Question: Why does applying this rule inside a procedure not work?

Hi,

I want to apply a rule to simplify an expression. The applyrule command works, when used directly in the worksheet. When I try to use the command within a procedure, Maple throws an error I cannot decipher:

Error, (in PatternMatching:-AlgStruct:-InsertPattern) first operand of `::' must be a name

 

Here is a full demonstration worksheet:

restart:

anexp:=abs(x)^2;

abs(x)^2

(1)

simplify(anexp);

abs(x)^2

(2)

rmabssq := proc(inexp)
description "removes the abs^2 construct in an expression":
local ruleabssqared1,ruleabssqared2,outexp:
    ruleabssqared1:= abs(''a''::algebraic)^2= ''a''^2:
    ruleabssqared2:= abs('expand'(-''a'')::algebraic)^2= ''a'':
    outexp:= applyrule([ruleabssqared1,ruleabssqared2],inexp):
    return outexp:
end proc;
 

proc (inexp) local ruleabssqared1, ruleabssqared2, outexp; description "removes the abs^2 construct in an expression"; ruleabssqared1 := abs(''a''::algebraic)^2 = ''a''^2; ruleabssqared2 := abs((('expand')(-''a''))::algebraic)^2 = ''a''; outexp := applyrule([ruleabssqared1, ruleabssqared2], inexp); return outexp end proc

(3)

## does not work :(
rmabssq(anexp);

Error, (in PatternMatching:-AlgStruct:-InsertPattern) first operand of `::' must be a name

 

## works!
ruleabssqared1:= abs(''a''::algebraic)^2= ''a''^2:
ruleabssqared2:= abs('expand'(-''a'')::algebraic)^2= ''a'':
newexp:= applyrule([ruleabssqared1,ruleabssqared2],anexp);

x^2

(4)

 


 

Download applyrule_4.mw

Thanks for your help

Please Wait...