Items tagged with applyrule



can you please help me with the usage of applyrule? I have the following problem that I cannot isolate. I have a rule that I want to apply, but instead of applying the rule to the expression, the rule seems to be applied to itself. In an isolated worksheet everything is fine:



abs('a'::algebraic)^2 = 'a'^2










abs(a::algebraic)^2 = a^2




What happens when I try to use this rule in my script is this:


#read "some_long_script.mpl":


abs('a'::algebraic)^2 = 'a'^2






a::algebraic^2 = a^2




I want to clarify, that the script that is read before applying those rules does not apply a similar rule. Also the variables rule and x were free. Can you please help me to locate the problem?




Wondered if anyone could help with the query below.

Consider f(x,y) defined as:
f := proc (x, y) options operator, arrow; x*y/(x+y) end proc


Then f(A, B); becomes:
(A * B )/(A + B)


now consider the polynomial:(poly2)



This polynomial is just the expansion of the polynomial below (lets call it poly1) which MAPLE does not recognize.


Here you can see that A,B on top and X,Y on the bottom are clearly of the form f(x,y).


Is there a way you can get MAPLE to recognize certain algebraic forms such that the polynomial poly2 could be written either as poly1 (already shown above) or as poly3 below:

poly3:=(f(A, B)+X)/(X+f(Y, X))


I have tried using simplify in the following form but not much luck. It doesn't seem to recognize anything other than the obvious.

simplify(poly2, {A*B/(A+B) = F1}, tdeg(A, B))


(I am still a bit new to the MAPLE syntax and procedures so apologies if I have missed something obvious function that can do this.)




Hello, I have a similary issue with the following post :

In a constraint equation (in mechanics), I need to make these algebraic substitutions :

--> sqrt(xA1² + yA1²) =rF1 
--> arctan(abs(yA1)/abs(xA1)) = aF1
--> sqrt(xC1^2+yC1^2) = rBTP
--> arctan(abs(yC1)/abs(xC1))=a1

I try to do it with this code :

ListAlgsubs:={sqrt(xA1^2+yA1^2)=rF1,sqrt(xA2^2+yA2^2)=rF2,sqrt(xA3^2+yA3^2)=rF3, sqrt(xA4^2+yA4^2)=rF4,arctan(abs(yA1)/abs(xA1))=aF1,-arctan(abs(yA2)/abs(xA2))=aF2,pi+arctan(abs(yA3)/abs(xA3))=aF3,pi-arctan(abs(yA4)/abs(xA4))=aF4,sqrt(xC1^2+yC1^2)=rBTP,arctan(abs(yC1)/abs(xC1))=a1};
for i from 1 to nops(ListAlgsubs)
do Branch1Cons:=applyrule(op(i,ListAlgsubs),Branch1Cons)
end do:
Branch1Cons:= simplify(Branch1Cons);

I have tried with algsubs or applyrule but it wasn't successfull in both cases.

Do you have an idea how can I do to simplify my expressions ? and namely conduct a good use of applyrule function

I join an extract of my code in order to facilitate the troubleshooting.

Thanks a lot for your help.

Hello everyone,


I am working on a program in Maple and got stuck in exchanging limits for integrals. For example, if I have an expression of following type.

Eq:=4*Int(f(x), x=0..1/3)+Int(x*f(x), x=0..2/3);

I want to convert it in to an expression of form

4*Int(f(x),x=0..x)-4*Int(y,x=1/3..x)+ Int(x*f(x), x=0..x)- Int(x*f(x), x=2/3..x)

In short, I want to split both the integral at x but flip in limits in the second integral. I tried as follows which did not work

applyrule(Int(f::anything,y=c::numeric..d::numeric)=Int(f,y=c..x)-Int(f,y=c..x), Eq)

Please, help me!

Thank you for your time.

I am trying to do a substitution as shown in the attached document. I know variants of this question have been asked before but dont quiet get what to do. It is problem with algsubs and how it handles denominators I think. Can get substiturion to work for simple fractions but more complicated ones fail. Would appreciate any guidance here.




CR := proc (a, b, c, d) options operator, arrow; (a-c)*(b-d)/((a-d)*(b-c)) end proc

proc (a, b, c, d) options operator, arrow; (a-c)*(b-d)/((a-d)*(b-c)) end proc


eqns := CR(a, b, c, d)



e1 := CR(b, a, c, d)



simplify(e1, {(a-c)*(b-d)/((a-d)*(b-c)) = lambda})










applyrule((a-c)*(b-d)/((a-d)*(b-c)) = lambda, e1)



alias(lambda = (a-c)*(b-d)/((a-d)*(b-c)))









f := a/b




f := algsubs(a/b = alpha, f)






algsubs((a-c)*(b-d)/((a-d)*(b-c)) = lambda, e1)

Error, (in algsubs) cannot compute degree of pattern in a





Hi everyone,


I have a question regarding the use of the applyrule function. I have an expression that contains a polynomial. The expression looks something like:


Y := (a0 + a_1*x + a_2*x^2 + ... a_n*x^n)*f(y) + b_0 + b_1*x + b_2*x^2 + ... b_n*x^n)*g(y):


I would like to express this as y(x) = P_1*f(y) + P_2*g(y).


So far I have tried applyrule([a0 + a_1*x + a_2*x^2 + ... a_n*x^n = P_1, b_0 + b_1*x + b_2*x^2 + ... b_n*x^n) = P_2],Y):


This doesn't seem to work. Any suggestions?





Dear people in Mapleprimes,


alpha-gamma*q[k]-eta*(int(q[i], i = 0 .. M__n))-eta*q[k] = p[k];



algsubs(-eta*(int(q[i], i = 0 .. M__n))-eta*q[k] = -eta*(int(q[i], i = 0 .. M__n)), alpha-gamma*q[k]-eta*(int(q[i], i = 0 .. M__n))-eta*q[k] = p[k]);


This works fine.



applyrule(-eta*(int(q[i], i = 0 .. M__n))-eta*q[k] = -eta*(int(q[i], i = 0 .. M__n)), alpha-gamma*q[k]-eta*(int(q[i], i = 0 .. M__n))-eta*q[k] = p[k]);


This doesn't bring an right replacement.


What difference is there between applyrule and algsubs?


Best wishes








tmp := Vector(2, {(1) = 1+(-s[2]-s[4]+2*w[1]/(1+1/exp(mu[p]))^2+(-2*w[1]+2)/(1+1/(exp(mu[p])*exp(eta[p2])))^2)*s[1]^3+(-s[2]+s[3])*s[1]^2-s[2]*s[1], (2) = (s[2]+s[4]-2*w[1]/(1+1/exp(mu[p]))^2-(-2*w[1]+2)/(1+1/(exp(mu[p])*exp(eta[p2])))^2)*s[1]^3})


rule3:=w[1]/(1+1/exp(mu[p]))^2+(-w[1]+1)/(1+1/(exp(mu[p])*exp(eta[p2])))^2 = s[3];

w[1]/(1+1/exp(mu[p]))^2+(-w[1]+1)/(1+1/(exp(mu[p])*exp(eta[p2])))^2 = s[3]










This is part of a large simplifcation where lots of terms are being substituted. In two of those terms, it did not simplify as we would expect.

I think the main thing is trying to find a way to factor out the "2".


I could do this

> rule3:=w[1]/(1+1/exp(mu[p]))^2+(-w[1]+1)/(1+1/(exp(mu[p])*exp(eta[p2])))^2 = s[3];

> rule3ne:=-(w[1]/(1+1/exp(mu[p]))^2+(-w[1]+1)/(1+1/(exp(mu[p])*exp(eta[p2])))^2) = -s[3];
> rule3ne:=2*rule3ne;

> applyrule(rule3,tmp[1]);
> applyrule(rule3ne,tmp[2]);

For this example, this works.

But I hope for a more generic approach.








Hello people in Mapleprimes,


I want to know how to use apply rule in the following problem.

Please tell me how to do about this.


returns F(2*K,2*L), which is right.

But, what I want to do is to apply the rule with holding n as general variable of real number.

But, what I can get through 


is only 2*F(K,L) not F(2*K,2*L).


What should I write additinally to the above to have Maple calcurate and produce the outcome as F(2*K,2*L), F(3*K,3*L) and so on?


Best wishes.





Hi Everyone,

I have an expression that contains a second order derivative: EXPR:=ay''(x) + bz'(x) + cf'(x)+... The variable y  obeys an ordinary differential equation, y''(x) = f(y,x). I would like to replace the second order deriavtive in my expression with f(y,x). So far I have tried applyrule([y''(x)=f(y,x)],EXPR), subs(y''(x)=f(y,x),EXPR) and algsubs(y''(x)=f(y,x),EXPR) and nothing seems to work. Any helpful suggestions?


kappa := Vector(7, [1,w[1]*(1-phi+phi*(1-1/(1+exp(-mu[p]-tau[p3]))))+(1-w[1])*

Download kappa.txt

Here is the expression, I am trying to simplify, given a set of rules.

I have tried different substitutions, using simplify with side rules, applyrule, eval, subs, algsubs.

But none seem to be working as the way I want them to be.


Is there a better way?



Hi everyone,

I have a maple program that generates a polynomial g(y)=(80y^8 + 68y^6 + 12y^4 -4y^2 -1). This polynomial has two real roots (irrational roots), call them +/- y*. My code does a sequential calculation, and often sI am left with a higher order polynomial in y that has the form h(y)= p(y)*g(y), where p(y) is also a polynomial in y. This polynomial h(y)=p(y)*g(y) is not in factored form (i.e. it would look like expand(p(y)*g(y)). Is there a way to instruct maple to recoginize that +/-y* is also a root h(y)=p(y)*g(y)? So far I've tried things like applyrule([g(y*)=0],h(y*)), but nothing seems to work (I suspect because Maple cannot recgonize that g(y) is a factor of h(y)). I am not interested in computing this numerically. I am just trying to find a way to instruct Maple to recognize symbolically that h(y*) =0.

Thanks a million for anyone who has any idea.




I am trying to make a substitution:

> restart;
> f1 := conjugate(z)^2*z^2;
> f2 := applyrule(z*conjugate(z) = x, f1);

however the result is

f2 := conjugate(z)^2*z^2

Do you have any ideas how to solve the problem? Thank you.

I have the following expression (obtained from an earlier calculation):

I want to collect all the terms under one summation. So I define a rule:

end proc:

and then


I get

Error, (in +) unable to identify A::algebraic

I used similar constructs before so I think the rule is constructed correctly. I should, however, mention that I use the Physics:-Vectors package and in fact the expression I start up with here reads, in 1-d Maple inputform:

Physics[Vectors][`+`](Physics[Vectors][`+`](Physics[Vectors][`+`](-y*(Sum((diff(a[n](r), r))/(exp(I*Pi*n/L))^2, n))/r, (2*I)*(Sum(a[n](r)/(exp(I*Pi*n/L))^2, n))*k0), y*(Sum(a[n](r)/(exp(I*Pi*n/L))^2, n))*k0^2), -y*(Sum((diff(a[n](r), r, r))/(exp(I*Pi*n/L))^2, n)))

Is my problem related to the use of Physics:-Vectors? If so, how can I get around that?


Mac Dude


I have a differential equation:

an the solution:

I want to substitute

ekf := omega = sqrt(c/m);

algsubs(ekf, sol);
but sol does not change.

This works a bit but does not substitute everything in a way that you would expedect

This is the result:

Thanks in advance

1 2 Page 1 of 2