maple

How to substitute into function with dummy argument in Maple?


In maple, I define a function H(x,y) as below

H := U(x, y) + U(3*x, y);

And then I try to decompose U(x,y) to x*f(y) and then get the corresponding H(x,y), so I do the following

subs(U(x, y) = x*f(y), H);

Maple gives me xf(y) + U(3x, y) But what I expect is xf(y)+3xf(y) or 4x*f(y)

[enter image description here][1]:https://i.sstatic.net/eQb1a.jpg What should I do?

I expect Maple to do further substitution to give the final result.


Solution

  • Maple did what you instructed it; it literally substituted for U(x,y) in the expression assigned to H.

    Your described expectation does not match literal substitution for U(x,y). Rather, your description is that of getting the expression re-evaluated with some operator replacing U.

    H := U(x, y) + U(3*x, y);
    
         H := U(x, y) + U(3 x, y)
    
    eval(H, U = ((a,b)->a*f(b)));
    
                  4 x f(y)
    

    Note that does not guard against calls to U having less than the expected two arguments.

    G := U(x, y) + U(3*x, y) + U(z) + (Ua,b,c):
    
    eval(G, U = ((a,b)->a*f(b)));
    Error, invalid input: unknown uses a 2nd
    argument, b, which is missing
    

    Here is another way, that only acts on function calls to U which have exactly two arguments -- and leaves others alone.

    evalindets(H, And(specfunc(U),
                      satisfies(t -> nops(t)=2)),
               t -> op(1,t)*f(op(2,t)));
    
                  4 x f(y)
    
    evalindets(G, And(specfunc(U),
                      satisfies(t -> nops(t)=2)),
               t -> op(1,t)*f(op(2,t)));
    
          4 x f(y) + U(z) + (Ua, b, c)