nm

11353 Reputation

20 Badges

13 years, 13 days

MaplePrimes Activity


These are replies submitted by nm

@Carl Love 

 

" Your Mathematica example doesn't look so great to me! The spacing is awkward, and the 2 is not superscripted. "

Sorry I was not clear. The Mathematica Latex output still needs to be compiled by pdflatex, which I did not bother doing like I did with Maple as it was clear it is correct Latex, but here it is after compiling it in Latex

In[22]:= expr= y[x]^2;
TeXForm[expr]

Out[23]//TeXForm=
         y(x)^2

Which renders as (after compiling)

 

side by side

@Carl Love 

" There's no difference between sin(s)^2 and (sin(s))^2. The latter simply has superfluous parentheses (which I personally find to be a significant annoyance when I'm trying to read code). "

That is all true. That is why I hate it when Maple insists on adding the extra parentheses when converting to Latex.

expr:=y(x)^2:
latex(expr);

           \left( y \left( x \right)  \right) ^{2}

which renders as

Compare to Mathematica

Which renders as, well, as it shows above. No extra ugly () needed.

Maple Latex rendering of math is broke for many many years. Yet Maplesoft claims Maple is for Mathematicians.

 

@Carl Love 

 

"You don't need to return anything because the statement r:-b:= 5 inside foo has already changed the global r"

Ah. So Maple passed the Record variable by reference. That is why when I updated it inside the function, it updates the global one also. 

I thought at first it passes a copy of the Record variable, that is why after i modified it, I did explicit return. I had no idea it passed it by reference here.

This is a bit confusing.  How does one know when Maple passes parameters by Value and when it passes by reference? I thought Maple passes everything by Value like with Mathematica. Ok. I found that Maple pass rtables by reference. and Record is of this type. That is why.

How to force a copy to be passed for rtable based struct such as Matrix, Record, etc...?  I did foo(eval(r)): but it still passed it by reference. 

I want to pass by value "r", so changes inside the function do not update the global variable with same name. 

thanks

 

 

 

There are many ways to iterate over data. You have not explained what data structure your data is contained in. Better to make a MWE always.

 

Try looking up 'for' which is used for a loop. something like

for item in z do
     process(item)
od;

or

for n from 1 to nops(z) do
     process(z[n])
od;

etc...

@tomleslie 

yes I did. I always look at help. I did see the use of :: which I tried and did not work. The opaquemodules= false was burried deep inside a long page of writing and I must have missed it. Not that I even know what it means being a newbie in Maple.

I find Maple help pages the worst part abut Maple as they are very hard to read. The formatting and the way help page are organised makes them hard to read.  One has to read pages and pages of stuff looking for something.

Such things in Mathematica are put in special section called "possible issues" where it is easy to spot.

@Carl Love 

" The first is to replace :- with :: in the stopat command "

I tried

stopat(foo::foo1::foo2);
Error, ambiguous use of `::`, please use parentheses

stopat(foo::(foo1::foo2));
Error, (in stopat) procedure name expected

But this worked !

stopat((foo::foo1)::foo2);

Also your second solution seems to work.

      kernelopts(opaquemodules= false);
     stopat(foo:-foo1::foo2);

Thank you

 

Mathematica seems to be fast doing these. 10^12 takes 20 seconds.

Prime[n] gives the n^th prime number. The numbers in the first entry returned in the seconds used.

@vv 

"For example F(x,y) = x * ( y + x*sqrt(x*y) + sqrt(x^3*y) )
can be split only for x<0,
"

Yes, good point. So I guess I have to assume x>0 for all test cases. This is in the context of solving a first order ODE by separation. So suppose the ODE was

               y'(x) = F(x,y)

and F(x,y) was your function above. If one can separate it, then the ODE becomes easy to solve. But most HW problems normally do not say x>0, but I think it is safe to assume this. Unless otherwise stated. I need to worry about this.

btw, your F seems to give dsolve hard time.

@Kitonum 

I implemented this `` trick in what follows. It gets little tricky, since I have to watch out for op(1,op(1... all the times. Does this look ok for you? 

Given sqrt(1-y^2)/x; I want to write is as sqrt(|1-y^2|)/x; and then remove || to obtain the original expression back. Using subsindents. So I wrote

restart;
Y:=sqrt(1-y^2)/x;
Y:=subsindets(Y,anything^({1/2,-1/2}),ee->abs(``(op(1,ee)))^(op(2,ee)));     
Y:=subsindets(Y,abs(anything)^(1/2),ee -> op(1,op(1,op(1,ee)))^op(2,ee));

Which works. I am just getting little dizzy counting ops in op(1,op(1,op(1,ee)))^op(2,ee) to get it right.

I wish there was a simple way for Maple to just leave what is inside abs() the way it was and not muck it up.

 

@Carl Love 

fyi, I found some problems.

expr:=sqrt(1-y^2)/(2*sqrt(x));
r:=Separate(expr,[x,y]);

It should be  sqrt(1-y^2) and 1/(2*sqrt(x)). And

 

expr:=sqrt(1-y^2)/x;
r:=Separate(expr,[x,y],method=tryhard);

The result should be   sqrt(1-y^2) and 1/x

And

expr:=sqrt(1-y^2);
r:=Separate(expr,[x,y],method=tryhard);

It should be  1 * sqrt(1-y^2).

I think these all are from same "issue". Having complex numbers pop up like this, makes it hard to use. I will add these cases to the list of cases in my original post now.

I am sure there is a way to simplify the result obtained back to what it should be with assumptions and combine(...,radical). So the output is not wrong, but hard to use as is. A post-processing step is now needed.

thanks

 

 

@Carl Love 

very good. Now with tryharder option (I saw this in your code, but did not know I can pass it in), your function can do them all correctly. congratulations.

I did not say that "Maplesoft can achieve with a "build-in" function something better than we can make here " I simply said such a function ought to be build-in Maple. Maplesoft can take your function for example and use it.

There are two important and useful functionality missing now in Maple itself: They are finding additively separable functions 

f(x,y,...) = g1(x) + g2(y) + .....

And product separable functiuons

f(x,y,....) = g1(x) * g2(y) * ....

https://ieeexplore.ieee.org/document/1104018/

Neither Maple nor Mathematica as well, have support for finding such decomposition.

I will test your function now more with other functions I have, and will use tryharder option.

thanks

@Carl Love 

Nice. Your function works well. I only found it fails on the first one in my list of tests I posted above. This was the hardest one.

expr:=arcsin(x)/(sqrt(1-x^2)*y^2);

This is clearly separable. But your method does not seprate it

Separate(expr,[x,y]);

                         FAIL

It should be

Sometimes doing things by CAS is much harder than doing things by hand. By just looking at the expression one can see it is separable. Why can't computers do the same?  :)

what I have I am still testing, but it is based on this paper   https://arxiv.org/ftp/math/papers/0210/0210167.pdf

by C. P. Viazminsky. The method is basically covered in equations (2.1) to equation (2.8).

This is something that Maple itself should have as build-in function. This will be very useful to have in Maple.  May be someone inside Maplesoft can look into adding such a function to Maple.

 

 

@Kitonum 

thanks for all the answers. But I found a problem

Your method works for ln(x) when ln(x) is both in numerator and denominator.

But for sqrt(x), which I want to change to sqrt(abs(x)), it only works when sqrt() is in the numerator.  

expr:=sqrt(x);
applyrule(sqrt(t::anything)=sqrt(abs(t)), expr);

is OK. But not for:

expr:=1/sqrt(x);
applyrule(sqrt(t::anything)=sqrt(abs(t)), expr);

does not work. Since I do not know where the subexpresion will show up in the expression, this will be a problem. I do not know why applyrule works for both 1/ln(x) and ln(x), but only for sqrt(x) and not for 1/sqrt(x).

 

 

@vv 

Thanks. This looks better. But using these arbitray "a" and "b" makes it little hard to use.

I wrote a a Maple function based on paper "On Separation of Variables by C. P. Viazminsky". I am still debugging and testing it. But this is what I get using it. on the test functions I posted above

can not split arcsin(x)/(-x^2+1)^(1/2)/y^2
x*y = (x) * (y)
x^2*y+x^2 = (x^2) * (y+1)
2*x+1 = (2*x+1) * (1)
cos(2*x) = (cos(2*x)) * (1)
y = (1) * (y)
(x-1)/y = (x-1) * (1/y)
ln(y^2+1) = (1) * (ln(y^2+1))
can not split -x*y^2+y^2-x+1
can not split x^3*y+x^2
can not split 1/(x+y)
(1+x^(1/2))/(1+y^(1/2)) = (1+x^(1/2)) * (1/(1+y^(1/2)))
(-x^2*y^2-x^2+y^2+1)/x^2 = ((x^2-1)/x^2) * (-y^2-1)
3*x^2*y^2+2*x*y^2 = (3*x^2+2*x) * (y^2)
can not split 3*exp(2*x)+2*y
can not split (5*x^(1/2)-y)/x
can not split 2*x*y+3*x^2*exp(x^2)
can not split (y^2+x+1)^(1/2)
1 = (1) * (1)
can not split x*y+1
4*x^3*y-y = (4*x^3-1) * (y)
can not split exp(x^2)+2*x*y
can not split -(y-exp(x))/(x-2)
arcsin(x)/(-x^2+1)/y^2 = (arcsin(x)/(x^2-1)) * (-1/y^2)
can not split -(y-exp(x))/(x-2)
4*x^3*y-y = (4*x^3-1) * (y)
can not split (x^2*y+y)*y^3*exp(-x-y+1)*3^(-x-y)*(x^2*y-y)^(1/2)

The only problem is the last one. Based on the function is_separable(f,x,y) that I posted above, here is it again

is_separable:=proc(f,x,y)
  #checks if f(x,y) is separable to X(x)*Y(y) or not
  #but does not do the separation. The separation is done by
  #another function I have
  if diff(simplify(diff( simplify(ln(f)),x)),y) = 0 then
     return(true);
  else
     return(false);
  fi;
end proc:

The last function is supposed to be seperable.

is_separable((x^2*y+y)*y^3*exp(-x-y+1)*3^(-x-y)*sqrt(x^2*y-y),x,y);

true

Yet, the function I wrote does not separate it. my function also does not separate the first one, which is sqrt(x-1)*sqrt(x+1)/(sqrt(-x^2+1)*y^2); but your SplitX does. But since your use all these extra constants, it makes it hard for me to use now.

Thanks for all the help.

@John Fredsted 

hi. Your method also has same issue as I just mentioned below.

expr:=-y+4*x^3*y;
s,r := selectremove(z -> has(z,x) and has(z,y),expr):
``(simplify(select(has,r*expand(s),x)))*
``(simplify(remove(has,r*expand(s),x)));

It should be  y*(4x^3-1)

And

expr:=exp(x^2)+2*x*y;
s,r := selectremove(z -> has(z,x) and has(z,y),expr):
``(simplify(select(has,r*expand(s),x)))*
``(simplify(remove(has,r*expand(s),x)));

Which is also wrong.

Hard problem!

First 67 68 69 70 71 72 73 Last Page 69 of 91