Problem Statement
Let's say we have a set of $n\times n$ matrices $X=\{M_1,\ldots,M_r\}$ and weights of these matrices $\{w_1,\ldots,w_r\}$ along with a set of "initial vectors" $\{v_1,\ldots,v_s\}$. We then define the weight of a vector $u\in\mathbb{R}^n$ by
$$w(u)=\min\{x:\big(\exists i_1,\ldots,i_k,j:x=w_{i_1}+\cdots+w_{i_k},u=M_{i_1}\cdots M_{i_k}v_j \big)\}\textrm{ or }w(u)=\infty\textrm{ if this set is empty}$$
Finally, we introduce a function $f:\mathbb{R}^n\to\mathbb{R}$ which we wish to maximize. We can then ask questions like "what is the maximum value of $f$ over all vectors of weight at most some $y$?", or "given $x$, what is the minimum weight of a vector $u$ satisfying $f(u)\geq x$?". We can also ask for the most efficient algorithm to answer these questions, or if a closed form exists.
I am very curious if this general question has been studied at all. Are there any known results in this area? Any references or pointers would be greatly appreciated.
Motivation
An example of a problem which can be formulated as above is the $UwU$ problem. In this problem, Alice wants to send Bob as many $UwU$'s as possible. She starts by manually typing "$UwU$" and afterwards has two options at each step: copy everything she has already written (which takes $kp$ seconds for $p>0,k>1$) or paste the last thing she copied (which takes $p$ seconds). This can be formulated using the matrix set $COPY=\big(\begin{smallmatrix} 1 & 0\\ 1 & 0 \end{smallmatrix}\big)$ and $PASTE=\big(\begin{smallmatrix} 1 & 1\\ 0 & 1 \end{smallmatrix}\big)$ and $w_1=pk$ and $w_2=p$ and a set of initial vectors consisting just of $v_1=\big(\begin{smallmatrix} 1\\ 0 \end{smallmatrix}\big)$. We then want to maximize the first coordinate of a vector by multiplying by $COPY$ and $PASTE$ while keeping the cost/sum of weights low.
By generalizing this problem to the format above, I am hoping to see if anyone has studied this class of problems, and to uncover any research that may have already been done in this area.