If I have two plain formal functions, like
sage: var('q k')
sage: function('u')
sage: function('v')
it seems I can always get more 'involved' formal functions, like the following h(k,q), by symbolic operations
sage: h(k,q)=u(k)*v(q)
sage: h(17,sin(k))
u(17)*v(sin(k)) # OK.
My naive hope was, that this would straightforwardly apply also to matrix construction from formal functions, like so
sage: B(k,q) = matrix([[u(k),v(q)],[v(q),u(k)]])
# but
sage: B(17,sin(q))
[u(k) v(q)]
[v(q) u(k)] # :(
So, B(k,q) does not substitute the variables. After some attempts, it seems that this is a valid way to construct a callable symbolic matrix from formal functions
sage: B=matrix(CallableSymbolicExpressionRing((k,q)),[[u(k),v(q)],[v(q),u(k)]])
# at least
sage: B(x^2,cos(q))
[ u(x^2) v(cos(q))]
[v(cos(q)) u(x^2)] # OK.
My 1st question is, if there is not a 'less cryptic' way to construct B from u and v?
My 2nd question concerns doing matrix arithmetic with B. If I try to do something similar to that for the plain formal function arithmetic for h(k,q) with my formal matrix function B it 'does not work'. Eg.:
sage: H(k,q)=B(k,q)*B(q,q)
sage: H(sin(17),pi)
[ u(k)*u(q) + v(q)^2 u(k)*v(q) + u(q)*v(q)]
[u(k)*v(q) + u(q)*v(q) u(k)*u(q) + v(q)^2] # :(
I.e., again, upon matrix multiplication, the object B(k,q)*B(q,q) seems to not substitute the arguments into the formal functions anymore. However, if I do
sage: H=matrix(CallableSymbolicExpressionRing((k,q)),B(k,q)*B(q,q))
Then
sage: H(sin(17),pi)
[ u(pi)*u(sin(17)) + v(pi)^2 u(pi)*v(pi) + u(sin(17))*v(pi)]
[u(pi)*v(pi) + u(sin(17))*v(pi) u(pi)*u(sin(17)) + v(pi)^2] # OK.
But it seems awkward if one would have to do matrix arithmetic like that. So, how does one do proper matrix operations with matrices made from formal functions?