nm

6928 Reputation

19 Badges

10 years, 74 days

MaplePrimes Activity


These are replies submitted by nm

@acer 

I meant exactly what select help page says

The select function selects the operands of the expression expr which satisfy the Boolean-valued procedure fcn,

may be I should not added more words myself. but I said clearly I am using select and has.

So for your examples

expr:= sin( f( diff(y(x),x) ) + Q );
select(has,expr,diff(y(x),x))

sin(f(diff(y(x), x)) + Q)

And

expr:= 3*diff(y(x),x);
select(has,expr,diff(y(x),x))

diff(y(x), x)

The only special case is when expr=diff(y(x),x) and this causes a problem. i.e. I expected that

select(has,diff(y(x),x),diff(y(x),x))

To return diff(y(x),x) and not diff(). but I know now why it does not because the way select works.

So I ended up just using an extra if, like this

expr:=diff(y(x),x);
if expr=diff(y(x),x) then
   print("nothing to select, expr is diff(y(x),x)");
else
   select(has,expr,diff(y(x),x));
fi;

And this solved the issue of the special case. Not a big deal, but was wondering if select has some option build in to handle this special case. I tried flatten and other options.

But I am ok now.

the problem in Maple is that there does not seem to be an overall guiding principle to help one figure which one of the 100's commands and comination of these are needed to simplify something.

On top of this, imagine doing this inside a program, i.e. without looking at the screen and not knowing what kind of expression one has each time.

So I find myself trying things until something work. 

Why did not simplify just work on its own? Why not with the size option? Why is combine needed in this case and not other cases?

Compare to Mathematica, where a one command Simplify is all what is needed for 95% of the cases. And if that does not work, there is another command called FullSimplify which will try even harder.

No need for the user to try 200 different commands and combinations of these each time to simplify something like with Maple.

I wish Maple would work on improving its simplification. Make new command called full_simplify() and hide all these things inside it so the user does not have to figure it out each time.

 

@nm 

 

"I still do not know why odetest verifies the solution one time but not the second time when this code is added. But that might be separate problem in odetest?"

I will make separate question on odetest as it is not related to this issue with this fix.

@Carl Love 

I found a big problem with the above.

If I just put the code you show at the top of the worksheet, then call odetest on some ode, it does not verify it. OK. But repeating the same odetest call, now it does verify the solution.

So odetest fails only first time, but not the second time.  This is all when I have your code added at the top.

If I remove your code, then now odetest fail to verify the ode each time I call it. No matter how many times.

It seems the code changes something internal in Maple. Why would odetest fail first time, but says the solution is correct the second time it is called without changing anything??

I found this when I was doing a test and found I am getting different result depending on when something is called.

Attached worksheet

interface(version);

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

restart;

#from https://www.mapleprimes.com/questions/230035-Error-in-SolveToolsCancelInverses
CI__orig:= eval(SolveTools:-CancelInverses):
unprotect(SolveTools:-CancelInverses):
SolveTools:-CancelInverses:= e->
local _A;
    eval(CI__orig(eval(e, _Z= _A), _rest), _A= _Z)
:
protect(SolveTools:-CancelInverses, CI__orig):
 

ode:= diff(y(x),x)-(2*x-y(x))/(2*x+y(x)) = 0;
ic:=y(2) = 2;
sol:=1/68*(-42*((-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(1/2*17^(1/2))*2^(-3/2*17^(1/2))*((-11/21*17^(1/2)-17/7)*x^(2*17^(1/2)+1)+y(x)*x^(2*17^(1/2))*(17^(1/2)+85/21))+4*(1/8*(-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(-1/2*17^(1/2))*((2*y(x)+3*x)*17^(1/2)+17*x))/(-5/4*x^(2*17^(1/2))*2^(-3/2*17^(1/2))*((-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(1/2*17^(1/2))*(17^(1/2)+21/5)+(1/8*(-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(-1/2*17^(1/2)))/x = 0;
 

diff(y(x), x)-(2*x-y(x))/(2*x+y(x)) = 0

y(2) = 2

(1/68)*(-42*((-2*x^2+3*x*y(x)+y(x)^2)/x^2)^((1/2)*17^(1/2))*2^(-(3/2)*17^(1/2))*((-(11/21)*17^(1/2)-17/7)*x^(2*17^(1/2)+1)+y(x)*x^(2*17^(1/2))*(17^(1/2)+85/21))+4*((1/8)*(-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(-(1/2)*17^(1/2))*((2*y(x)+3*x)*17^(1/2)+17*x))/((-(5/4)*x^(2*17^(1/2))*2^(-(3/2)*17^(1/2))*((-2*x^2+3*x*y(x)+y(x)^2)/x^2)^((1/2)*17^(1/2))*(17^(1/2)+21/5)+((1/8)*(-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(-(1/2)*17^(1/2)))*x) = 0

res:=odetest(sol,[ode, ic]) assuming x>0:
if res[1]=0 and res[2]=0 then
   print("verified");
else
   print("did not verify");
fi;

"did not verify"

res:=odetest(sol,[ode, ic]) assuming x>0:
if res[1]=0 and res[2]=0 then
   print("verified");
else
   print("did not verify");
fi;

"verified"

res:=odetest(sol,[ode, ic]) assuming x>0:
if res[1]=0 and res[2]=0 then
   print("verified");
else
   print("did not verify");
fi;

"verified"

res:=odetest(sol,[ode, ic]) assuming x>0:
if res[1]=0 and res[2]=0 then
   print("verified");
else
   print("did not verify");
fi;

"verified"

 

Download cancel_added_bug_in_odetest.mw

Now compare what happens when I do not use your code at all. Now each time odetest is called, it returns unverified. Not just the first time.

So now I am not sure what is the correct result. is it verified or not.

interface(version);

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

restart;

ode:= diff(y(x),x)-(2*x-y(x))/(2*x+y(x)) = 0;
ic:=y(2) = 2;
sol:=1/68*(-42*((-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(1/2*17^(1/2))*2^(-3/2*17^(1/2))*((-11/21*17^(1/2)-17/7)*x^(2*17^(1/2)+1)+y(x)*x^(2*17^(1/2))*(17^(1/2)+85/21))+4*(1/8*(-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(-1/2*17^(1/2))*((2*y(x)+3*x)*17^(1/2)+17*x))/(-5/4*x^(2*17^(1/2))*2^(-3/2*17^(1/2))*((-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(1/2*17^(1/2))*(17^(1/2)+21/5)+(1/8*(-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(-1/2*17^(1/2)))/x = 0;
 

diff(y(x), x)-(2*x-y(x))/(2*x+y(x)) = 0

y(2) = 2

(1/68)*(-42*((-2*x^2+3*x*y(x)+y(x)^2)/x^2)^((1/2)*17^(1/2))*2^(-(3/2)*17^(1/2))*((-(11/21)*17^(1/2)-17/7)*x^(2*17^(1/2)+1)+y(x)*x^(2*17^(1/2))*(17^(1/2)+85/21))+4*((1/8)*(-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(-(1/2)*17^(1/2))*((2*y(x)+3*x)*17^(1/2)+17*x))/((-(5/4)*x^(2*17^(1/2))*2^(-(3/2)*17^(1/2))*((-2*x^2+3*x*y(x)+y(x)^2)/x^2)^((1/2)*17^(1/2))*(17^(1/2)+21/5)+((1/8)*(-2*x^2+3*x*y(x)+y(x)^2)/x^2)^(-(1/2)*17^(1/2)))*x) = 0

res:=odetest(sol,[ode, ic]) assuming x>0:
if res[1]=0 and res[2]=0 then
   print("verified");
else
   print("did not verify");
fi;

"did not verify"

res:=odetest(sol,[ode, ic]) assuming x>0:
if res[1]=0 and res[2]=0 then
   print("verified");
else
   print("did not verify");
fi;

"did not verify"

res:=odetest(sol,[ode, ic]) assuming x>0:
if res[1]=0 and res[2]=0 then
   print("verified");
else
   print("did not verify");
fi;

"did not verify"

res:=odetest(sol,[ode, ic]) assuming x>0:
if res[1]=0 and res[2]=0 then
   print("verified");
else
   print("did not verify");
fi;

"did not verify"

 

Download cancel_added_bug_in_odetest_version_2.mw

But since the original reason for this code seem not to be needed any more, as in Maple 2022.1 this code does not generate an error any more

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
expr:=exp(x)*sin(y)-3*x^2+(exp(x)*cos(y)+1/3/y^(2/3))*Z = 0;
solve(expr,y);

So I think I will just remove all the code using SolveTools:-CancelInverses from the worksheet now.

I still do not know why odetest verifies the solution one time but not the second time when this code is added. But that might be separate problem in odetest?

@Carl Love 

thanks. yes, That fixed it. Now all tests pass.

@Carl Love 

I think what happens is this. DEtools:-odeadvisor(ode,y(x),[linear]) rewrites   (x+y)*y'=0 as two equations. one is (x+y)=0, which is algebraic and gives solution y=-x, and the other is y'=0, which is an ode which is linear with solution y=constant.

But if looking at the ode as is , then the ode is clearly not linear _before_ factoring it out. So the question is, should DEtools:-odeadvisor(ode,y(x),[linear]) look at the ode as is to decide if it is linear or not?

I think so. But clearly that is not what it is doing now.  When actually solving the ode, factoring it is the right approach. But not for the advisor. That is my point.  Because now, I can't use the advisor to check if the ode is linear in order to check before calling convertAlg

May be Maple needs a new build in method to check if an ode is linear or not?

@Carl Love 

I rewrote the question to make it more clear.

@Carl Love 

But that is what I said. But the code I have uses

DEtools:-odeadvisor(ode,y(x),[linear]);

To check if the ode is linear or not before calling convertAlg and this is how I found this error. 

So the problem is that DEtools:-odeadvisor(ode,y(x),[linear]); should not have returned _linear as result. Now I have to go back to using my own code to check if an ode is linear or not.

@Carl Love 

Fyi, I found a bug. Added it to the tests. (and corrected y to y(x) in two of the odes, that was a typo).

Attached is the complete worksheet. The last ode gives degree as 1, it should be 3.

Last ode is y(x)-x*diff(y(x),x)-1/2/diff(y(x),x)^2=0 which is the same as shown below, which is obtained using the command  PDEtools:-dpolyform(ode)


 

interface(version);

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

restart;

#code from https://www.mapleprimes.com/questions/227477-Finding-Order-And-Degree-Of-ODE-In-Maple#comment289059
ODEdegree:= (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(
                  evala@Norm,
                  [convert(`if`(e::`=`, lhs-rhs, x->x)(e), Diff)],
                  [
                     {
                         specfunc(Diff), `+`, `*`,
                         'satisfies'(e-> hastype(e, specfunc(Diff)))^rational
                     },
                     {}
                  ]
               ))
         )
   catch:
      FAIL
   end try
;

 Typesetting:-Settings(typesetprime=true):
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]
]:

for i from 1 to nops(tests) do
  deg:= ODEdegree(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:

"Passed on ", diff(y(x), x) = y(x)^(1/2), " .Expected degree ", 1, " got ", 1

"Passed on ", diff(diff(y(x), x), x)+(diff(y(x), x))^(1/2) = y(x), " .Expected degree ", 2, " got ", 2

"Passed on ", (1+(diff(y(x), x))^2)^(3/2) = diff(diff(y(x), x), x), " .Expected degree ", 2, " got ", 2

"Passed on ", 3*y(x)^2*(diff(y(x), x))^3-(diff(diff(y(x), x), x)) = sin(x^2), " .Expected degree ", 1, " got ", 1

"Passed on ", (1+(diff(y(x), x))^2)^(1/2) = y(x)*(diff(diff(diff(y(x), x), x), x)), " .Expected degree ", 2, " got ", 2

"Passed on ", (1+(diff(y(x), x))^2)^(1/2) = y(x)*(diff(diff(diff(y(x), x), x), x)), " .Expected degree ", 2, " got ", 2

"Passed on ", sin(diff(y(x), x))+diff(diff(y(x), x), x)+3*x, " .Expected degree ", FAIL, " got ", FAIL

"Passed on ", exp(diff(diff(y(x), x), x))+sin(x)*(diff(y(x), x)) = 1, " .Expected degree ", FAIL, " got ", FAIL

"Passed on ", k*(diff(diff(y(x), x), x))^2 = (1+(diff(diff(y(x), x), x))^2)^3, " .Expected degree ", 6, " got ", 6

"Passed on ", x*(diff(diff(y(x), x), x))^3*(diff(y(x), x))-5*exp(x)*(diff(diff(y(x), x), x))+y(x)*ln(y(x)), " .Expected degree ", 3, " got ", 3

"Passed on ", 2*ln(x)*(diff(y(x), x))^2+7*cos(x)*(diff(diff(y(x), x), x))^4*(diff(y(x), x))^7+x*y(x) = 0, " .Expected degree ", 4, " got ", 4

"Failed on ", y(x)-x*(diff(y(x), x))-(1/2)/(diff(y(x), x))^2 = 0, " .Expected degree ", 3, " got ", 1

 


 

Download different_degree_second_test.mw

 

 

@ecterrab 

Fyi, I found another example where de_degree returns different result depending on how the ode is written,

Please see attached worksheet

interface(version);

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

restart;

#code from https://www.mapleprimes.com/questions/227477-Finding-Order-And-Degree-Of-ODE-In-Maple
de_degree := proc(de, f::expects(unknown) := NULL)
local de_in_diff_notation, derivatives, diff_ord;

de_in_diff_notation := convert(`if`(de::`=`, (lhs-rhs)(de), de), diff);
derivatives := indets(de_in_diff_notation, specfunc(diff));
if f <> NULL then
    derivatives := select(has, derivatives, f);
fi;
if derivatives = {} then return(0) fi;
diff_ord := PDEtools:-difforder(derivatives);
derivatives := select(u -> PDEtools:-difforder(u) = diff_ord, derivatives);
max(map2(degree, de_in_diff_notation, derivatives));
end:

ode:=y(x)-x*diff(y(x),x)-1/2/diff(y(x),x)^2=0;

y(x)-x*(diff(y(x), x))-(1/2)/(diff(y(x), x))^2 = 0

odes:=[PDEtools:-dpolyform(ode)];

 

[[-2*x*(diff(y(x), x))^3+2*y(x)*(diff(y(x), x))^2-1 = 0], [(diff(y(x), x))^2 <> 0], []]

#this gives correct degree of 3, using the form from PDEtools:-dpolyform
de_degree(odes[1,1],y(x))

3

#this gives the wrong degree using the original ode form. THis should be 3, it gives 1
de_degree(ode,y(x))

1

 

Download different_degree.mw

@Carl Love 

The definition does not exclude the possibilities f=0 or g=0.

Are you saying that y(x) = g(p) can be dAlembert? for what conditions on g(p) ?

In this case, then y(x)=ln(diff(y(x),x)) and y(x)= tan(diff(y(x),x)) and so on all are now dAlembert. But clearly these are not. These are all quadrature.

But by adding an x to both the above examples, they now become dAlembert. y(x)=x*ln(diff(y(x),x)) and y(x)= x*tan(diff(y(x),x)) are dAlembert. (g=0 case is allowed)

So if y=g(p) can be dAlembert (i.e. f=0 is allowed), what are the conditions on g(p) for this to be the case? Otherwise, this is all fussy definitions.

In all the text books I looked at, I never seen an ode called dAlembert which had a missing x on the RHS (i.e. f=0 case) . But may be I did not look at enough examples.

try MmaTranslator  andFromMmaNotebook

But do not expect it to work on such large notebook with other non-mathematical functions in it. This translator is meant to be used to translate basic Mathematica math constructs.

Not to translate Full Mathematica code (otherwise, people will just use Maple to run Mathematic code for everything, which means Maplesoft will have to implement all of the Mathematica kernel in it, which is about 50 millions line of code or so). For example, do not expect the Plot commands to be translated to Maple.

My advice to translate this, is to do manually. Try to implement the algorithm itself in Maple directly, and do not translate line by line. I use this Maple translator to translate individual Mathematical expressions from Mathematica to Maple (which is very useful to have), but not to translate full functions and packages. Will not work for that.

 

 

@Christian Wolinski 

Thanks. It does fail on cases where the function shows up as argument to itself. But I do not think I have such cases, so this should not cause a problem.

restart;
C := proc(E, T)
   if type('E, T') then 1 elif hastype('E, T') then add(map(procname, [op]('E'), 'T')) else 0 fi;
end;
expr:=sin(sin(x));
C(expr,'specfunc(anything,sin)');  # gives 1
nops(indets(expr,'specfunc(anything,sin)'))  # gives 2

 

it would have been better if you attached such problem worksheet to use as an example. I do not see this problem you are talking about. But I do not use Maple to export pdf files much if any. I export what I want from the worksheet to Latex and compile the Latex to pdf. You get much better quality pdf this way.

But to change the font size in pdf, there are many external tools to use. Some are free, and some are not.

Adobe itself has an online service that does that Here is the link  https://www.adobe.com/acrobat/hub/how-to/change-font-size-in-pdf  

 

 

etc..

@Joe Riel 

This change was meant to be applied/used only within MmaTranslator:-FromMma package and not anywhere else in Maple. 

Since the expression x^y^z is a valid Mathematica expression and the Maple package is meant to be able to translate any valid Mathematica  Math expression to Maple, then it will be better if it can translate this to Maple, using a default internal setting  to generate x^(y^z) as translation to Maple.

Within Maple, it is no problem at all adding explicit () when needed.

That will something useful to have in Maple 2023 if possible. 

1 2 3 4 5 6 7 Last Page 1 of 60