# Multiply symbolic function by number or expression

I want to define a symbolic function in terms of other symbolic functions, like so:

function('psi psi_1 psi_2')
psi = 1/sqrt(2) * (psi_1 + psi_2 * i)


When running the code, I get the error:

TypeError: unsupported operand type(s) for *: 'NewSymbolicFunction' and 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_gaussian'


The same error appears when I replace i with a real number.

Is there any fundamental mistake I'm making? If so, what should I do instead? If not, is there a workaround?

The reason I am defining a function like this is because I need to find the derivative of the psi function in terms of derivatives of the latter two functions.

edit retag close merge delete

Sort by ยป oldest newest most voted

No need to include psi in your initial function declaration, as you then define psi in the next line.

Not sure how to explain the error you get, but here is something that works:

sage: psi1, psi2 = function('psi_1, psi_2')
sage: psi(t) = 1/sqrt(2) * (psi_1(t) + psi_2(t) * i)


That defines psi as a function. Observe the result:

sage: psi
t |--> 1/2*sqrt(2)*(psi_1(t) + I*psi_2(t))


That function can be differentiated:

sage: diff(psi)
t |--> 1/2*sqrt(2)*(diff(psi_1(t), t) + I*diff(psi_2(t), t))

sage: diff(psi(t), t)
1/2*sqrt(2)*(diff(psi_1(t), t) + I*diff(psi_2(t), t))

more

psi_1 and psi_2 are kind of not completely defined (in particular, they are not member of the symbolic ring, hence they can not benefit from the coercions between the symbolic ring and other rings), for example at this stage it is not clear how many symbolic variable do they use, see:

sage: parent(psi_1)
<class 'sage.symbolic.function_factory.function_factory.<locals>.NewSymbolicFunction'>

sage: psi_1(x)
psi_1(x)
sage: var('y')
y
sage: psi_1(x,y)
psi_1(x, y)

sage: parent(psi_1(x))
Symbolic Ring


If you decide that those are function of a single variable, it works:

sage: psi = 1/sqrt(2) * (psi_1(x) + psi_2(x) * i)
sage: psi
1/2*sqrt(2)*(psi_1(x) + I*psi_2(x))

more