nm

4376 Reputation

17 Badges

8 years, 102 days

MaplePrimes Activity


These are questions asked by nm

I needed to make symbolic vector, as in  

my_vector:=Vector([v__1,v__2,v__3])

The problem is that, the proc called, has to create this vector on the fly, since the dimension changes on each call. So I used seq command to generate it. But seq did not work. I tried

my_vector:=Vector([seq('v__i',i=1..3)])

 

After looking more at it, It seems to have nothing to do with evaluation. If the subscript index is variable, it does not work.

 

f:=proc(v::symbol,i::posint)  
  print("i=",i);
  print("v__i=",v__i); 
  return (v__i);
end proc;

f(v,2)

One way is to use v[i] instead of v__i, and now it works:

[seq('v[i]',i=1..3)]

But since subscripted variable are supposed to be safer than indexed variable, I wanted to use v__i and not v[i].

 

Why it does not work? And is there a workaround this?  

ps. I could always do this 

V:=[seq(:-parse(cat("v__",convert(i,string))),i=1..3)]
lprint(V[1])

But this seems like a hack to me and I do not know why it should be needed.

ps. any one knows where help on "__" is in Maple? I can't find it. doing ?__ turns out nothing. I do not know under what name help on double subscript is in maple.

Maple 2020.1

When Maple converts sin(x)^n to Latex, the result remain  sin(x)^n.  But in Mathematical typesetting, this is normally written as sin^n(x).   Ofcourse this is only for Latex. In Maple code this not valid.

Is it possible to change Maple's Latex to make it do this automatically? Mathematica does this automatically. Here is an example

restart;
expr:=sin(x)^3+cos(3*x)^5;              
Physics:-Latex(expr)
 
            \sin \left(x \right)^{3}+\cos \left(3 x \right)^{5}

Which when compiled gives

Compare to Latex generated by Mathematica

Which compiles to 

Which is more standard in books and papers, that Maple's version.

Both Maple's Physics:-Latex and latex() command do the same thing.

Is there a way to make it generate the improved version for latex?

Maple 2020.1

 

 

sometimes I get intermediate expressions generated from other operations that contain terms such as exp(x)^n in them. As an example, exp(x)^3.  In Mathematica, it automatically replaces these by exp(3*x). But in Maple I need to force this change.

For purposes of Latex only, I like to change these terms to exp(3*x) before converting the whole expression to Latex, as it is looks much better that way.

expr:=exp(x)^3;
Physics:-Latex(expr)

                \left({\rm e}^{x}\right)^{3}

expr:=exp(3*x);
Physics:-Latex(expr)

                {\rm e}^{3 x}


I found that doing simplify(expr,exp)  does the trick. It changes exp(x)^n to exp(n*x). But I am worried about applying this whole simplification command to the whole expression, which can be very large, and do not want to change it all yet.

I just want to change any occurance of exp() there, and nothing more.

I tried using subsindent to do that, but it does not work on terms in denominator

restart;
expr:=exp(x)^3*sin(x)+3/(exp(x)^n);
subsindets(expr,'exp(anything)^anything',f->simplify(f,exp))

I tried

subsindets(expr,'1/exp(anything)^anything',f->simplify(f,exp))

and it did not work.

I am still not good at subsindent. How to make it change all exp(x)^n to exp(n*x) everywhere?

These are 4 equations in 4 unknowns. the equations are kinda long. But the issue is that PDEtools:-Solve hangs, while solve finishes instantly.

I have though before that  PDEtools:-Solve is a higher level API which ends up using solve? So why does it hang on this?

restart;

eqs:=[2 = c1+c2+c4-1, 0 = ((c2+c4-2)*(108+12*59^(1/2)*3^(1/2))^(1/3)+(1/12*c3*3^(1/2)+1/12*c2-1/6*c4)*(108+12*59^(1/2)*3^(1/2))^(2/3)+2*c3*3^(1/2)-2*c2+4*c4)/(108+12*59^(1/2)*3^(1/2))^(1/3), -1 = -1/6/(108+12*59^(1/2)*3^(1/2))^(2/3)*((((c2-2*c4)*3^(1/2)-3*c3)*59^(1/2)-33*c3*3^(1/2)+33*c2-66*c4)*(108+12*59^(1/2)*3^(1/2))^(1/3)+(2*c2+2*c4+12)*(108+12*59^(1/2)*3^(1/2))^(2/3)+((-12*c2+24*c4)*3^(1/2)-36*c3)*59^(1/2)-60*c3*3^(1/2)-60*c2+120*c4), -5 = ((((2*c2-4*c4)*3^(1/2)+6*c3)*59^(1/2)-30*c3*3^(1/2)-30*c2+60*c4)*(108+12*59^(1/2)*3^(1/2))^(1/3)+(((-c2+2*c4)*3^(1/2)+3*c3)*59^(1/2)+13*c3*3^(1/2)-13*c2+26*c4)*(108+12*59^(1/2)*3^(1/2))^(2/3)-96*(59^(1/2)*3^(1/2)+9)*(c2+c4))/(24*59^(1/2)*3^(1/2)+216)];

unknowns:=[c1, c2, c3, c4];

#han to put a timelimit, else it will never finish. I waited 20 minutes before.
timelimit(30,PDEtools:-Solve(eqs,unknowns));

#this completes right away
solve(eqs,unknowns);

 

Is this a known issue and to be expected sometimes?
 

restart;

interface(version);

`Standard Worksheet Interface, Maple 2020.1, Windows 10, July 30 2020 Build ID 1482634`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 851. The version installed in this computer is 847 created 2020, October 17, 17:3 hours Pacific Time, found in the directory C:\Users\me\maple\toolbox\2020\Physics Updates\lib\`

eqs:=[2 = c1+c2+c4-1, 0 = ((c2+c4-2)*(108+12*59^(1/2)*3^(1/2))^(1/3)+(1/12*c3*3^(1/2)+1/12*c2-1/6*c4)*(108+12*59^(1/2)*3^(1/2))^(2/3)+2*c3*3^(1/2)-2*c2+4*c4)/(108+12*59^(1/2)*3^(1/2))^(1/3), -1 = -1/6/(108+12*59^(1/2)*3^(1/2))^(2/3)*((((c2-2*c4)*3^(1/2)-3*c3)*59^(1/2)-33*c3*3^(1/2)+33*c2-66*c4)*(108+12*59^(1/2)*3^(1/2))^(1/3)+(2*c2+2*c4+12)*(108+12*59^(1/2)*3^(1/2))^(2/3)+((-12*c2+24*c4)*3^(1/2)-36*c3)*59^(1/2)-60*c3*3^(1/2)-60*c2+120*c4), -5 = ((((2*c2-4*c4)*3^(1/2)+6*c3)*59^(1/2)-30*c3*3^(1/2)-30*c2+60*c4)*(108+12*59^(1/2)*3^(1/2))^(1/3)+(((-c2+2*c4)*3^(1/2)+3*c3)*59^(1/2)+13*c3*3^(1/2)-13*c2+26*c4)*(108+12*59^(1/2)*3^(1/2))^(2/3)-96*(59^(1/2)*3^(1/2)+9)*(c2+c4))/(24*59^(1/2)*3^(1/2)+216)];
unknowns:=[c1, c2, c3, c4];

[2 = c1+c2+c4-1, 0 = ((c2+c4-2)*(108+12*59^(1/2)*3^(1/2))^(1/3)+((1/12)*c3*3^(1/2)+(1/12)*c2-(1/6)*c4)*(108+12*59^(1/2)*3^(1/2))^(2/3)+2*c3*3^(1/2)-2*c2+4*c4)/(108+12*59^(1/2)*3^(1/2))^(1/3), -1 = -(1/6)*((((c2-2*c4)*3^(1/2)-3*c3)*59^(1/2)-33*c3*3^(1/2)+33*c2-66*c4)*(108+12*59^(1/2)*3^(1/2))^(1/3)+(2*c2+2*c4+12)*(108+12*59^(1/2)*3^(1/2))^(2/3)+((-12*c2+24*c4)*3^(1/2)-36*c3)*59^(1/2)-60*c3*3^(1/2)-60*c2+120*c4)/(108+12*59^(1/2)*3^(1/2))^(2/3), -5 = ((((2*c2-4*c4)*3^(1/2)+6*c3)*59^(1/2)-30*c3*3^(1/2)-30*c2+60*c4)*(108+12*59^(1/2)*3^(1/2))^(1/3)+(((-c2+2*c4)*3^(1/2)+3*c3)*59^(1/2)+13*c3*3^(1/2)-13*c2+26*c4)*(108+12*59^(1/2)*3^(1/2))^(2/3)-96*(59^(1/2)*3^(1/2)+9)*(c2+c4))/(24*59^(1/2)*3^(1/2)+216)]

[c1, c2, c3, c4]

timelimit(30,PDEtools:-Solve(eqs,unknowns))

Error, (in expand/bigprod) time expired

solve(eqs,unknowns):

 


 

Download PDEtools_solve_issue_oct_23_2020.mw

What is the best way to handle this?  Many times one wants to return an expression from inside a proc, which uses local symbls, back to the user (global context).

The problem is, if one tries to simplify this returned expression, adding assumptions on some of the symbols in the expression, it does not work. Since the symbol used in the assuming is global, while the symbol inside the returned expression was local to the proc.

Even though the symbols look the same on the screen, they are actually different symbols, so the simplify does not work as expected.

Here is a simple example

restart;
foo:=proc()
local x;
  return exp(2*sqrt(1/x^2)*x*ln(x)) + exp(sqrt(1/x^2)*x*ln(x)) ;
end proc;

sol:=foo();

simplify(sol) assuming x>0

The above does not work. Since the "x" in assuming x>0 is global, while the "x" in the expression was local to the proc. So even though they look same, they are different symbols.

The standard way to handle this, is to pass the "x" to be used to build the solution, from the user to the proc(), so that when the expression is returned, the "x" used will be the global one. Like this

restart;
foo:=proc(x)
  return exp(2*sqrt(1/x^2)*x*ln(x)) + exp(sqrt(1/x^2)*x*ln(x)) ;
end proc;

sol:=foo(x);

simplify(sol) assuming x>0

Now it works:

But this method is not practical all the time. Suppose the local proc wants to generate an expression with other symbols in it, that the user does not know about. Say alpha, beta, z, eta, and so on. The user does not care about having to pass every possible symbol down on each call.  

Is there a way to tell assuming, that the symbols in assumptions command, are to be taken from the expression itself, and not to be global ones?    i.e. when doing 

simplify(sol) assuming x>0

I want Maple to take that "x" in assuming to be the "x" inside the expression only, and not a global "x".  

This will make life much simpler.  I remember seeing other use of assuming where this could be done, but I can't find it yet.

edit:

This is  just one example, where returning expression with new symbol from local proc can be required sometimes.

This is similar to using constant of integrations _C1 by dsolve when it returns a solution.

But those _C1 are all predefined as system/global symbols. But there can be cases where one needs to use new symbols. 

An example is where int() timesout or it does not produce result.

In this case, instead of leaving it as is (since I need to use the result and do not want Maple to keep evaluating it in the expression it is in), so  I replace int(integrand,x) with Int( new_integrand , alpha=0...x) where new_integrand is the same as integrand but with each in it, is replaced by new symbol alpha

This symbol alpha has to be local to the proc (it was not passed down by user). 

Maple uses _Z sometimes for such a cases, which I do not like. (it looks bad in Latex)

Here is an example

foo:=proc(x)
local int_result,alpha;
local integrand:=1/ln(x^2+1);

int_result:= int(integrand,x);
if has(int_result,'int') then  #did not integrate
   int_result:=Int(subs(x=alpha,integrand),alpha=0..x);
fi;

  return int_result;
end proc:

int_result:=foo(x)

The expression returned contains symbol alpha, which is local to the proc.  Only way around this, is to have the user pass in alpha as well as x, just in case it is needed, which is not practical to do.

This is just one example of many. Another example is when doing some transformation internally (change of variables) to convert the ode from one form to another, and I need to return those intermediate results back to caller. These substitutions use local symbols.

As I said, I could have used _Z or some other system/global known symbol for this. But I do not like how this looks in Latex. And if I need another symbol for another case, I have to look for another one.  Instead, I just make my own local symbols and use them in the expression. (Except for constant of integrations, I use those _C1,_C2, etc....

 

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