nm

11413 Reputation

20 Badges

13 years, 71 days

MaplePrimes Activity


These are replies submitted by nm

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

@acer 

using x::numeric makes the function accept  1/2 as input.

So now NC(1, 1/2); returns 1. 

But  1/2 is 0.5 and the only digit is

NC(1, 0.5);  returns correctly.

That is why I used 

the_num::{integer,float}

@emendes 

In the example you sent my old mac had no problem to run the code: "Time out ok" in 120.736 (quite close to twice the estipulated time)

Could you please try with higher timeouts? try 200 seconds for example, then 300 seconds? Does it freez after that? As I mentioned the time could be different depending on the PC/memory and other factors.

I am using Maple 2022.2 on windows.

@dharr 

Thanks for trying. If I understand you right, you did get it to freeze, but at longer timeout. It depends on the PC and how fast it is to get solve or timelimit into the code path where it hangs. I have fast PC so with me 60 seconds was enough.

The issue with using task manager to kill the server is secondary. For me, I had to do that as (!) click did not do it. It does turn gray, but the server.exe remains running at high CPU. So (!) did not kill the server.

The main issue is that depending on what timelimit is used, it can cause a freeze. So it is all non-determinstic. It is not possible to do large scale development in Maple this way.

Note I am not talking about timelimit taking a little longer to timeout than asked. This is not the issue. It is actual freezing, or taking 10 hrs when the timeout is 30 seconds. This is the main problem that Maplesoft seems unable to fix for 30 years now.

@Carl Love 

You are correct., According to definition it should be degree 2. Corrected the tests so they all now pass

tests:=[[diff(y(x),x)=y(x)^(1/2),1],
[diff(y(x),x$2)+diff(y(x),x)^(1/2)=y(x),2],
[(1+diff(y(x),x)^2)^(3/2)=diff(y(x),x$2),2],
[3*y(x)^2*diff( y(x),x)^3- diff(y(x),x$2)=sin(x^2),1],
[sqrt(1+ diff(y(x),x)^2)=y(x)*diff(y(x),x$3),2],
[sqrt(1+ diff(y(x),x)^2)=y(x)*diff(y(x),x$3),2],
[sin(diff(y(x),x))+ diff(y(x),x$2)+3*x,FAIL],
[exp(diff(y(x),x$2))+sin(x)*diff(y(x),x)=1,FAIL],
[k*diff(y(x),x$2)^2=(1+ diff(y(x),x$2)^2)^3,6],
[x*diff(y(x),x$2)^3*diff(y(x),x)-5*exp(x)*diff(y(x),x$2)+y(x)*ln(y(x)),3],
[2*ln(x)*diff(y(x),x)^2+7*cos(x)*diff(y(x),x$2)^4*diff(y(x),x)^7+x*y(x)=0,4],
[y(x)-x*diff(y(x),x)-1/2/diff(y(x),x)^2=0,3],
[diff(y(x), x, x) - a*(c + b*x + y(x))*(diff(y(x), x)^2 + 1)^(3/2) = 0,2]]:

for i from 1 to nops(tests) do 
  deg := ODE_degree(tests[i,1]);
  if deg <> tests[i,2] then
     print("Failed on ",tests[i,1]," .Expected degree ",tests[i,2]," got ",deg);
  else
     print("Passed on ",tests[i,1]," .Expected degree ",tests[i,2]," got ",deg);
   fi;
od:

 

@Carl Love 

Hello. I found a bug. Added it to tests.

For the following ode

Which clearly has degree 1 by just looking at it, since the highest derivative has degree 1.  But ODE_degree gives 2. I think this happens because the ODE_degree tries to normalize all powers to integers, so it squares the ode, resulting in (y'')^2 ? 

 

#see https://www.mapleprimes.com/questions/227477-Finding-Order-And-Degree-Of-ODE-In-Maple
ODE_degree:=proc(e::{algebraic, `=`(algebraic)})
 try
      (e-> degree(
         e, 
         indets(
            e, 
            'typefunc'(
               (O-> `if`(O>1, 'typefunc'('`@@`'(identical(D),O)), specfunc(D)))
                  (PDEtools:-difforder(e))
            )
         )
      ))
         (
            ((e::satisfies(e-> degree(e, indets(e, specfunc(Diff)))::posint))-> 
               convert(e,D)
            ) 
               (frontend(
                  numer@evala@':-Norm',
                  [convert((numer@`if`(e::`=`, lhs-rhs, x->x))(e), Diff)], 
                  [
                     {
                         specfunc(Diff), `+`, `*`, 
                         'satisfies'(e-> hastype(e, specfunc(Diff)))^rational
                     }, 
                     {}
                  ]
               ))
         )
   catch:
     FAIL;
   end try;
end proc;   

And

ode:=diff(diff(y(x),x),x)-a*(c+b*x+y(x))*(diff(y(x),x)^2+1)^(3/2) = 0;
ODE_degree(ode)

                          2

 

Here is the updated tests

tests:=[[diff(y(x),x)=y(x)^(1/2),1],
[diff(y(x),x$2)+diff(y(x),x)^(1/2)=y(x),2],
[(1+diff(y(x),x)^2)^(3/2)=diff(y(x),x$2),2],
[3*y(x)^2*diff( y(x),x)^3- diff(y(x),x$2)=sin(x^2),1],
[sqrt(1+ diff(y(x),x)^2)=y(x)*diff(y(x),x$3),2],
[sqrt(1+ diff(y(x),x)^2)=y(x)*diff(y(x),x$3),2],
[sin(diff(y(x),x))+ diff(y(x),x$2)+3*x,FAIL],
[exp(diff(y(x),x$2))+sin(x)*diff(y(x),x)=1,FAIL],
[k*diff(y(x),x$2)^2=(1+ diff(y(x),x$2)^2)^3,6],
[x*diff(y(x),x$2)^3*diff(y(x),x)-5*exp(x)*diff(y(x),x$2)+y(x)*ln(y(x)),3],
[2*ln(x)*diff(y(x),x)^2+7*cos(x)*diff(y(x),x$2)^4*diff(y(x),x)^7+x*y(x)=0,4],
[y(x)-x*diff(y(x),x)-1/2/diff(y(x),x)^2=0,3],
[diff(y(x), x, x) - a*(c + b*x + y(x))*(diff(y(x), x)^2 + 1)^(3/2) = 0,1]]:

for i from 1 to nops(tests) do 
  deg := ODE_degree(tests[i,1]);
  if deg <> tests[i,2] then
     print("Failed on ",tests[i,1]," .Expected degree ",tests[i,2]," got ",deg);
  else
     print("Passed on ",tests[i,1]," .Expected degree ",tests[i,2]," got ",deg);
   fi;
od:

All pass except the last one.

First 27 28 29 30 31 32 33 Last Page 29 of 91