## Why does applying this rule inside a procedure not...

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:

Here is a full demonstration worksheet:

 > restart:
 > anexp:=abs(x)^2;
 (1)
 > simplify(anexp);
 (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;
 (3)
 > ## does not work :( rmabssq(anexp);
 > ## works! ruleabssqared1:= abs(''a''::algebraic)^2= ''a''^2: ruleabssqared2:= abs('expand'(-''a'')::algebraic)^2= ''a'': newexp:= applyrule([ruleabssqared1,ruleabssqared2],anexp);
 (4)
 >

## Problem with applyrule...

Hi,

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:

 > restart;
 > rule:=abs(''a''::algebraic)^2=''a''^2;
 (1)
 >
 (2)
 > applyrule(rule,myexp);
 (3)
 > rule
 (4)
 >

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

 > restart;
 > rule:=abs(''a''::algebraic)^2=''a''^2;
 (1)
 > applyrule(rule,abs(x)^2)
 (2)
 > rule
 (3)
 >
 >

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?

Thanks!

Honigmelone

## Recognize specific algebraic forms...

Hi,

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)

poly2:=(A*B+A*X+B*X)*(Y+X)/((A+B)*X*(2*Y+X))

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

(A*B/(A+B)+X)/(X+Y*X/(Y+X))

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.)

Thanks.

## algsubs or applyrule ? with powers and sqrt...

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

http://www.mapleprimes.com/questions/200835-Algsubs-With-Subscripts-And-Powers

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.

example.mw

Thanks a lot for your help.

## Changing limits in integrals...

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)

## How do I preform a particular substitution?...

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.

 (1)

 (2)

 (3)

 (4)

 (5)

 (6)

 (7)

 (8)

 (9)

 (10)

 (11)

 (12)

## difference between algsubs and applyrule...

Dear people in Mapleprimes,

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

Then,

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.

But,

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

taro

## How to factor out an integer?...

 > restart: tmp:=Vector( [ 1+(-s[2]-s[4]+2*w[1]/(1+1/exp(mu[p]))^2+(2*(-w[1]+1))/(1+1/(exp(mu[p])*exp(eta[p2])))^2)*s[1]^3+(-s[2]+s[3])*s[1]^2-s[2]*s[1], (s[2]+s[4]-2*w[1]/(1+1/exp(mu[p]))^2-(2*(-w[1]+1))/(1+1/(exp(mu[p])*exp(eta[p2])))^2)*s[1]^3 ] );
 (1)
 > rule3:=w[1]/(1+1/exp(mu[p]))^2+(-w[1]+1)/(1+1/(exp(mu[p])*exp(eta[p2])))^2 = s[3];
 (2)
 > applyrule(rule3,tmp[1]);
 (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];
>rule3:=2*rule3;

> 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.

Thanks,

casper

## How to use applyrule...

Hello people in Mapleprimes,

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

applyrule(2*F(K,L)=F(2*K,2*L),2*F(K,L));

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

applyrule(n*F(K,L)=F(n*K,n*L),2*F(K,L));

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.

Taro

## applyrule,subs,algsubs...

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?

## Simplifiying exponential expression (susb,algsubs,...

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

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

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?

Thanks!

## How do I apply an inverse distributive law...

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:

collectf:=proc(f)
A::algebraic*f(a::algebraic)+B::algebraic*f(b::algebraic)\
+C::algebraic*f(c::algebraic)+D::algebraic*f(d::algebraic)=f(A*a+B*b+C*c+D*d);
end proc:

and then

applyrule(collectf(Sum),%);

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?

TIA,

Mac Dude

## subs, algsubs, solve, simplify, applyrule: nothing...

Greetings,

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:

Hi,

I have an expression which contains terms like cos(3*x)*cos(x) + sin(3*x)*sin(x). In this expression, I replace the prevous terms by using applyrule as:

applyrule([cos(3*x)*cos(x)=1/2*(cos(2*x)+cos(4*x)), sin(3*x)*sin(x)=1/2(cos(2*x)-cos(4*x))],expr);

Is there a way to generalize this so that I may replace all forms of sin(n*x)*sin(m*x) = 1/2(cos((n-m)*x)-cos((n+m)*x))?

## applyrule and half-angle relations...

Following an earlier thread (Collect-And-Sqrt) where a solution using applyrule was proposed (and that solution works), I tried to use applyrule to implement some of the trig half-angle relationships. Immediately I ran into trouble:

Say I want to use the rule

r:=cos(th::algebraic)=2*cos(th/2)^2-1;

so I say

applyrule(r,cos(alpha));

and Maple promptly goes into an...

 1 2 Page 1 of 2
﻿