nm

8552 Reputation

19 Badges

12 years, 347 days

MaplePrimes Activity


These are replies submitted by nm

I located the bug, It is in the  inttrans:-invlaplace

it happens here. Compare

expr:=L*C*((L*C)^(1/2)*c[0]*s+(L*C)^(1/2)*c[1]+2*c[0])/(s^2*(L*C)^(1/2)*L*C+2*s*L*C+(L*C)^(1/2));
r1:=inttrans:-invlaplace(expr,s,x);

As a workaround, do partial fractions first, then it gives correct result because now invplace gives correct result on each simplified part of the partial fractions

expr_expanded := convert(expr,'fullparfrac',s);
r2:=map(X->inttrans:-invlaplace(X,s,x),expr_expanded );

We see the result is not the same

simplify(r1-r2)

 

@vs140580 

One way is

seq(`if`(L[i,1]="H",i,NULL),i=1..nops(L));
L_index:={%};
S:={{1,9},{1,20},{2,10},{3,4},{3,10},{3,14},{4,5},{4,6},
{5,7},{5,12},{6,8},{6,13},{7,9},{7,15},{8,9},{8,16},{10,11},
{11,17},{11,18},{11,19}}:

remove(has,S,L_index);

Lookup also select and selectremove

@Preben Alsholm 

Yes, wrapping it seems to be the key to making it work. So using nonunit and your wrapping trick seems to finally make it work. I still need to try more examples. This works

restart;
the_rule:=f(A::nonunit(anything))+f(B::nonunit(anything))=f(A)+1/2*f(B):
applyrule(the_rule,f(A)+f(B));
eval(%,f=(x->x)); 

But this hangs

restart;
the_rule:=A::nonunit(anything)+B::nonunit(anything)=A+1/2*B:
applyrule(the_rule,A+B);

So bottom line: use both nonunit and wrapping. but wrapping is not practical to use. Since the expression to be transformed is coming in without the terms having f() around them. So this will not really work in programming. It works for interactive usage where one can manually add f() around each symbol. 

So there is still problem with rules that does   A+B->A+1/2*B due to infinite applying of the rule. 

I looked at your ap function above, and I have no idea what your wrote. I see only 

ap:=proc (_rules, expr,count::nonnegint:=100)

But where is the body of the function?

So wrapping will not work for me to stop the infinite loop, and still need to figure how to your use your ap function, which so far, I do not know how as I do not see the definition of it,

 

@Carl Love 

Thanks. Using nonunit helps with applyrule. Yes. But I do not agree it is obvious. (else why no one mentioned its use before in this topic?)  In addition, patmatch works on this example without using nonunit 

Here is an example

restart;
the_rule:=A::nonunit(anything)+B::nonunit(anything)=A*B;
applyrule(the_rule,x+y);

              x*y

But nonunit is not needed for patmatch

restart;
the_rule:=A::anything+B::anything;
patmatch(x+y,the_rule,'la'); la

Successfull matching without nonunit

But from now on, will use nonunit with applyrule. This is good to know, and thanks for pointing this out, as I think applyrule is useful, if I can figure how to actualy use it correctly.

@Preben Alsholm 

applyrule is completely useless command. Consider this

rule0:=A::anything+B::anything=A+1/2*B;
applyrule(rule0,A+B)

It will loop forever.

Because applyrule computes the fix point, it applies the rules until no rule can be applied any more

And there is no way to tell it to applyrule only once. So it changes A+B to A+1/2B. Then since the result matches the rule, it will apply the rule again to give A+1/4*B, and it will keep doing this forever and ever. So I had to kill the session.

Compare to Mathematica

It will be good to have an option to tell it to apply the rule once. But no such option exists. May be in Maple 2032 we might get one. 

patmatch is much better,

rule0:=A::anything+B::anything;
patmatch(x+y,rule0,'la'); assign(la);
A+1/2*B

 

@Preben Alsholm 

"my conclusion is that applyrule is rather limited"

That is too bad. Because rule-based programming is very powerful in computer algebra (when it is done right).

Look at one of the answers given here https://mapleprimes.com/questions/235740-How-To-Emulate-This-Pattern-Operation-In-Maple- 

Where applyrule happend to work and how much shorter the solution became. 

But since it is very limited in Maple, it is not practical to use for many things where it would have been much more useful.

it can solve it without boundary conditions. Which is a hint that your BC could be inconsistent or such that it produces no solution. You might want to check the BC are correct.

      sol:=dsolve([OdeSys]);

solves it.

Maple 2022.2

@sursumCorda 

Thanks. Yes, you are right, applyrule seems the most direct way. It is also the closest to using Mathematica rule. I do not use applyrule and completely forgot about it. 

I wonder now why it is not used more vs. subsindets or patmatch since it seems from this example really easier. I will spend more time learning applyrule. I did use it before few times but for some reason I forgot now, I found it did not do what I wanted all the time. Need to visit it again.

restart;

expr1:=sin(x)+f(A)+f(B)+10*exp(x)/13+cos(x)+1/(f(C)+f(10*C))+g/(f(h)+f(n))+f(C);

sin(x)+f(A)+f(B)+(10/13)*exp(x)+cos(x)+1/(f(C)+f(10*C))+g/(f(h)+f(n))+f(C)

the_rule:=f(_A::anything)+f(_B::anything)=f(_A+_B);

f(_A::anything)+f(_B::anything) = f(_A+_B)

R := expr -> subsindets(expr,`+`,
       proc(ee)
         local u := selectremove(type,ee,specfunc(f));
         u[2] + `if`(u[1]=0,0,f(subsindets(u[1],specfunc(f),op)));
       end proc):

applyrule(the_rule,  expr1)

f(C+A+B)+1/f(11*C)+g/f(h+n)+(10/13)*exp(x)+cos(x)+sin(x)

R(expr1);

f(C+A+B)+1/f(11*C)+g/f(h+n)+(10/13)*exp(x)+cos(x)+sin(x)

 

Download apply_rule.mw

@acer 

thanks. It works. But debugging it, I am not able to figure how the recursive calls happen untill all terms f(a)+f(b) are exhausted in the input.

For example

expr:=sin(x)+f(A)+f(B)+10*exp(x)/13+cos(x)+1/(f(C)+f(10*C))+g/(f(h)+f(n));
R(expr)

In the debugger, first time u := selectremove(type,ee,specfunc(f)); is called, I see u[1]=f(C)+f(10*C), and u[2]=0. Then it does f(subsindets(u[1],specfunc(f),op) which returns f(11C) but now on the next step in the debugegr, I see it calling proc(ee) again and doing u := selectremove(type,ee,specfunc(f)); which now gives u[1]=f(h)+f(n), and u[2]=0 and it jeep doing this until it hits u[1]=0.

My question is, how is proc(ee) being called repeatedly like this? I do not see anywhere an explict recusive call.  

Is the original expr -> subsindets(expr,`+`, causing this to happen automatically ? 

It looks like magic to me how it is done. But it works very well. Just trying to understand how it works. i.e. how is causing the recursive calls to happen so I can extend it to other uses I wanted.

@Hullzie16 

What variable are you trying to solve for?

from help

If you do not specify the variables parameter, Maple solves for all the variables that appear in equations, that is, indets(equations, name).

Example

restart;
expr := exp(a)+b+c+3*d;
sol:=solve(expr = 0,  useassumptions,allsolutions) assuming nonnegative;


   sol := {b = -exp(a) - c - 3*d, 0 <= a, 0 <= c, 0 <= d}

I want to output to 1/6. it outputs to sqrt(9)/18 

That is not what I get. it gives 1/6 not sqrt(9)/18

restart;
expr:= (sqrt(1+x)-3)/(x-8);
limit(expr,x=8)

 

Maple 2022.2

@mz6687 

 'Error, cannot determine if this expression is true or false:'

that is a common error. see this page

I had no idea Maple had elseif  

I've only used elif for the compund if statement. Where is this documented? I searched help and did not find it.

However, in actual.mw I may have a bunch of data that I don't want to wipe out with a restart. 

If you have spend a lot of time to generate the data, why not save it to a file? This way you can do restart, and later read it and continue from there. see the save comand on how to save variables to disk.

@ecterrab 

thanks for the fix. 

Those unnecessary parentheses got removed from the typesetting of expressions

May be everyone sees it differently, but to my eyes, the way it was before looks more pleasing and more clear than the current way. i.e. I find 

better looking and more clear than

But may be it is just me. At least now it compiles OK and that is the important part.

First 6 7 8 9 10 11 12 Last Page 8 of 71