acer

32333 Reputation

29 Badges

19 years, 324 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

There's something goofy going on witheven the u[1] and u[0]. I can look later this evening.

The change from exp to sin,cos happens because of your evalc call. It's easy to amend that.

But the key will be to fix the appriach so that even the first a[1] comes out as you expect...

@salim-barzani Why didn't you show the expected result when you posted this Question thread!?

Or, were the additional details in one of your earlier Question threads that you've deleted?

@Geoff That's a regression in behaviour; Maple 2024.2 gets it in one call to simplify.

You can report bugs at this link, btw.

@emendes It returns the expression with the subexpression (addend) z*x becoming x*z, which is what you asked for if I'm not misunderstanding.

See the comments (after # symbols) in the latter code. See also the 3rd paragraph in my previous Reply. By sorting z*x into x*z anywhere -- including on its own -- it becomes thus sorted everywhere it appears structurally. Instances where it appears structurally merely point at the unique stored item. The sort command can actually change that stored item, in-place.

If the stored item is x*z and you type in, say, cos(z*x) then that automatically becomes cos(x*z) because z*x is uniquified (automatically simplified) to the stored x*z. And case of the opposite order being the one that happens to be store would also hold. For this example, it's one order of the product, or the other, that happens to be stored.

So the nature of the sole stored representation of the symbolic product of (only) x and z then rules over previously created as well as new expressions that contain it structurally. NB. p*x*z doesn't contain x*z structurally (even though it may, mathematically).

restart;

z*x;

z*x

T := cos(x*z);

cos(z*x)

sort(z*x, order=plex(x,z));

x*z

T;

cos(x*z)

L := [13*z*x, z*x];

[13*x*z, x*z]

f(z*x);

f(x*z)

sort(z*x, order=plex(z,x));

z*x

T;

cos(z*x)

L;

[13*z*x, z*x]

f(x*z);

f(z*x)

Download uniquification.mw

The mechanism for centrally storing items helps Maple performance. See also "The Simplification Table" in Appendix 1 of the Programming Guide.

The background knowledge and explanation is advanced Maple. But usage (like we're doing here) can be quite practical.

@nm I deleted the other Question thread.

If you are going to post multiple examples involving recursion errors during odetest (including while using Physics 'assumingusesAssume'=true), and if you also suspect that they might be related, and if you also are going to reference any of those from another in words, then they are closely related.

I have asked before, politely, to please either cross-reference such queries with links added manually, or to get such links automatically added by using the Branch button on a Question, or to simply group them together in the same Question thread. It's a reasonable request, because otherwise it's unjustifiably difficult for people to properly follow all what you are saying (especially at some future date) on this topic.

Ideally everyone here would be respectful, and honest, and helpful, whenever possible. In the absence of that, maybe I ought to stay away.

@rlewis You've changed the example I gave from using the plottools:-polygon command to using the plots:-polygonplot3d command, and kept all the other syntax corrections. The result is essentially the same, here.

It's good that you have it working.

@emendes Is this the kind of fix-up you're after? That is changing z*x back to x*z.

I added it as a late step in the Alt_monomialsGB procedure, but at the end of this worksheet I also show how you can apply it to an arbitrary list of expressions (of type polynom in your list of names). You could even make that a new small procedure.

The basic idea is that it simply forces re-ordering of the multiplicands in (only) the subexpressions of type `*`. Maple stores a single instance of such terms, in a special internal structure, and sort acts in-place on those; the sorted instance then appears (automatically) in any expression containing those terms.

restart;

Alt_monomialsGB := proc(p::algebraic, vars::list,
                        {ord::identical(plex,tdeg,grlex):=':-plex',
                         reverse::truefalse:=false})
local
     M, res,
     v:= indets(p, suffixed({vars[]})),
     C:= coeffs(expand(p), v, 'M'),
     P:= ord(ListTools:-Reverse([v[]])[]),
     S:= sort(`[]`~([C],[M]), (a,b)-> not Groebner:-TestOrder(a[2], b[2], P));
     S:= ifelse(reverse,ListTools:-Reverse(S),S);
     res:= (map2(op, 1, S), map2(op, 2, S));
     map(sort,indets([res],`*`),'order'=':-plex'(vars[]));
     return res;
end proc:

 

lorenz := [-sigma*x + sigma*y, rho*x - x*z - y, -beta*z + x*y,
           z^2+y*z+x*z+z+w*y^2+x*y+K*y+x^2+x+1];

[-sigma*x+sigma*y, rho*x-x*z-y, -beta*z+x*y, w*y^2+K*y+x^2+x*y+x*z+y*z+z^2+x+z+1]

vars := [x,y,z]:

 

map(w->Alt_monomialsGB(w,vars),lorenz);

[[sigma, -sigma], [y, x], [-1, -1, rho], [x*z, y, x], [-beta, 1], [z, x*y], [1, 1, 1, 1, w, 1, K, 1, 1, 1], [z^2, y*z, x*z, z, y^2, x*y, y, x^2, x, 1]]

map(w->Alt_monomialsGB(w,vars,ord=tdeg,reverse),lorenz);

[[-sigma, sigma], [x, y], [rho, -1, -1], [x, y, x*z], [-beta, 1], [z, x*y], [1, 1, K, 1, 1, 1, 1, w, 1, 1], [1, x, y, z, x^2, x*y, x*z, y^2, y*z, z^2]]

map(w->Alt_monomialsGB(w,vars,ord=tdeg),lorenz);

[[sigma, -sigma], [y, x], [-1, -1, rho], [x*z, y, x], [1, -beta], [x*y, z], [1, 1, w, 1, 1, 1, 1, K, 1, 1], [z^2, y*z, y^2, x*z, x*y, x^2, z, y, x, 1]]

map(w->Alt_monomialsGB(w,vars,ord=grlex),lorenz);

[[sigma, -sigma], [y, x], [-1, -1, rho], [x*z, y, x], [1, -beta], [x*y, z], [1, 1, 1, w, 1, 1, 1, K, 1, 1], [z^2, y*z, x*z, y^2, x*y, x^2, z, y, x, 1]]


You can do a similar fix-up, stand-alone. Eg,

foo := [z*y^2*x, z^4*y*x^3]; # only if created fresh in a session, out-of-order
map(sort,indets([foo],`*`),'order'=':-plex'(vars[])):
foo;

[z*y^2*x, z^4*y*x^3]

[x*y^2*z, x^3*y*z^4]

sort(z*x, order=plex(z,x)): # to forcibly get your problematic example
# Now this next example has the unwanted z*x subterm.
Q := [sigma*y, (-sigma - 1)*y + z*x, (rho - 1 - z)*beta - (x + y)*x];

[sigma*y, (-sigma-1)*y+z*x, (rho-1-z)*beta-(x+y)*x]

map(sort,indets([Q],`*`),'order'=':-plex'(x,y,z)):
Q;

[sigma*y, (-sigma-1)*y+x*z, (-z+rho-1)*beta-(x+y)*x]

fixup := proc(expr, vars)
  map(sort,indets([expr],`*`),'order'=':-plex'(vars[]));
  return expr;
end proc:

 

sort(z*x, order=plex(z,x)): # to forcibly get your problematic example
Q; # once again problematic

[sigma*y, (-sigma-1)*y+z*x, (-z+rho-1)*beta-(x+y)*x]

fixup(Q, vars); # using the order appearing in list vars

[sigma*y, (-sigma-1)*y+x*z, (-z+rho-1)*beta-(x+y)*x]

Download more_sort_fun2.mw

@emendes Yes, that's an artefact of some of the forced sorting orders.

As I mentioned in the initial text of my original Answer, that (somewhat cosmetic) effect can be adjusted by an additional `sort` applied separately to the individual terms. I can add that, maybe tonight.

Do you always want the individual product terms alwats to have their multiplicands in usual alphabetic/lexicographic order?

It is a bug; a regression introduced in Maple 2023.

The syntax a(1) and a[1] are only interchangeable for some flavours of rtable indexing.

@emendes Does this cover your flavours?

(Choices of ordering are plex,tdeg,grlex, with plex the default. And reverse=true/false, defaulting to false.)

tdeg, reversed, is what I did for your original examples in this Question.

restart;

lorenz := [-sigma*x + sigma*y, rho*x - x*z - y, -beta*z + x*y,
           z^2+y*z+x*z+z+w*y^2+x*y+K*y+x^2+x+1];

[-sigma*x+sigma*y, rho*x-x*z-y, -beta*z+x*y, w*y^2+K*y+x^2+x*y+x*z+y*z+z^2+x+z+1]

vars := [x,y,z]:

Alt_monomialsGB := proc(p::algebraic, vars::list,
                        {ord::identical(plex,tdeg,grlex):=':-plex',
                         reverse::truefalse:=false})
local
     M,
     v:= indets(p, suffixed({vars[]})),
     C:= coeffs(expand(p), v, 'M'),
     P:= ord(ListTools:-Reverse([v[]])[]),
     S:= sort(`[]`~([C],[M]), (a,b)-> not Groebner:-TestOrder(a[2], b[2], P));
     S:= ifelse(reverse,ListTools:-Reverse(S),S);
     (map2(op, 1, S), map2(op, 2, S));
end proc:

map(w->Alt_monomialsGB(w,vars),lorenz);

[[sigma, -sigma], [y, x], [-1, -1, rho], [x*z, y, x], [-beta, 1], [z, x*y], [1, 1, 1, 1, w, 1, K, 1, 1, 1], [z^2, y*z, x*z, z, y^2, x*y, y, x^2, x, 1]]

map(w->Alt_monomialsGB(w,vars,ord=tdeg,reverse),lorenz);

[[-sigma, sigma], [x, y], [rho, -1, -1], [x, y, x*z], [-beta, 1], [z, x*y], [1, 1, K, 1, 1, 1, 1, w, 1, 1], [1, x, y, z, x^2, x*y, x*z, y^2, y*z, z^2]]

map(w->Alt_monomialsGB(w,vars,ord=tdeg),lorenz);

[[sigma, -sigma], [y, x], [-1, -1, rho], [x*z, y, x], [1, -beta], [x*y, z], [1, 1, w, 1, 1, 1, 1, K, 1, 1], [z^2, y*z, y^2, x*z, x*y, x^2, z, y, x, 1]]

map(w->Alt_monomialsGB(w,vars,ord=grlex),lorenz);

[[sigma, -sigma], [y, x], [-1, -1, rho], [x*z, y, x], [1, -beta], [x*y, z], [1, 1, 1, w, 1, 1, 1, K, 1, 1], [z^2, y*z, x*z, y^2, x*y, x^2, z, y, x, 1]]


Download more_sort_fun.mw

@emendes Please give a brief but characteristic example of input and output for that procedure (which has Carl's "fist"), and a description of what it does, and how you want that changed.

@Andiguys I've updated my previous Reply, to cover your followup case involving
   c ≤ a and a ≤ b

I don't understand why you would wait so long to inform us that all the variables are positive. How does it help, to hold that back originally?

And now you've got some further, new variant example? Am I reading that rightly?

Is there some good reason that you couldn't give use all three different examples at the beginning?

@Andiguys The 2D Math display that looks like c ≤ a ≤ b is simply a conjunction of two inequalities, a ≤ b and c ≤ a . You might try dealing with those one at a time.

Does the following make sense,

restart

kernelopts(version)

`Maple 2019.2, X86 64 LINUX, Nov 26 2019, Build ID 1435526`

B := w+Ce; A := (1/3)*`ϕ`*(-beta*p1+a)-upsilon*Pu

ineq := -A/upsilon <= (B-A*(2*U*upsilon+1)/upsilon)/(2*(U*upsilon+1)) and (B-A*(2*U*upsilon+1)/upsilon)/(2*(U*upsilon+1)) <= (`&varphi;`*(-beta*p1+a)-A)/upsilon

 

You gave us the (new, updated) information that all variables
are positive. Literally, that means p1 as well (unless you now exclude it).

extra := indets(ineq,And(name,Not(constant))) >~ 0;

{0 < Ce, 0 < Pu, 0 < U, 0 < a, 0 < beta, 0 < p1, 0 < upsilon, 0 < varphi, 0 < w}

 

ineq1 := op(1,ineq):

R1 := op(solve({ineq1},p1)) assuming extra[];

p1 <= (3*Ce*upsilon-3*Pu*upsilon+a*varphi+3*upsilon*w)/(beta*varphi)

ineq2 := op(2,ineq):

R2 := op(solve({ineq2},p1) assuming extra[]);

p1 <= -(-6*U*a*upsilon*varphi+3*Ce*upsilon-3*Pu*upsilon-5*a*varphi+3*upsilon*w)/((6*U*upsilon+5)*beta*varphi)

Maybe this is all you are after...

`and`(R1, R2, p1>0);

p1 <= (3*Ce*upsilon-3*Pu*upsilon+a*varphi+3*upsilon*w)/(beta*varphi) and p1 <= -(-6*U*a*upsilon*varphi+3*Ce*upsilon-3*Pu*upsilon-5*a*varphi+3*upsilon*w)/((6*U*upsilon+5)*beta*varphi) and 0 < p1

Or maybe something like this...

p1>0 and p1 <= min(rhs(R1),rhs(R2));

0 < p1 and p1 <= min((3*Ce*upsilon-3*Pu*upsilon+a*varphi+3*upsilon*w)/(beta*varphi), -(-6*U*a*upsilon*varphi+3*Ce*upsilon-3*Pu*upsilon-5*a*varphi+3*upsilon*w)/((6*U*upsilon+5)*beta*varphi))

Or maybe something like this...
simplify(solve(`and`(R1, R2, p1>0), p1)) assuming extra[];

piecewise(`and`(Pu-w < Ce, Ce < ((6*U*a*`&varphi;`+3*Pu-3*w)*upsilon+5*a*`&varphi;`)/(3*upsilon)), [{p1 <= ((6*U*a*`&varphi;`-3*Ce+3*Pu-3*w)*upsilon+5*a*`&varphi;`)/((6*U*upsilon+5)*beta*`&varphi;`), 0 < p1}], `and`(((-3*w+3*Pu)*upsilon-a*`&varphi;`)/(3*upsilon) < Ce, Ce <= Pu-w), [{p1 <= ((3*w+3*Ce-3*Pu)*upsilon+a*`&varphi;`)/(beta*`&varphi;`), 0 < p1}], [])

Download Q_isolate_acc_2.mw

@emendes With repeats,

restart;

P := (LL::list, VV::list(name)) ->
       map(u->seq(sort(u/icontent(u),'order'=':-plex'(sort(VV)[])),icontent(u)),
           [op(sort(`+`(op(LL)),order=':-tdeg'(VV[]),':-ascending'))]):

 

V := [z,y,x]:

 

L1 := [z^2, y*z, x*z, z, y^2, x*y, y, x^2, x, 1]:

 

P(L1, V);

[1, x, y, z, x^2, x*y, x*z, y^2, y*z, z^2]

 

L2 := [z^2, y*z, y, x*z, y, z^2, y, x*z, z, y^2, x*y, y, x*z, x^2, x, 1, x]:

 

P(L2, V);

[1, x, x, y, y, y, y, z, x^2, x*y, x*z, x*z, x*z, y^2, y*z, z^2, z^2]

Download sort_lex_fun2.mw

Here I put the plex sorting (of multiplicands in each separate monomial) as an inside rather than outside job. That aspect might not even be of interest/use to you; and I can only guess at what order you might prefer for them.) Without that touch it can come out like this:

restart;

P := (LL::list, VV::list(name)) ->
       map(u->seq(u/icontent(u),icontent(u)),
           [op(sort(`+`(op(LL)),order=':-tdeg'(VV[]),':-ascending'))]):

V := [z,y,x]:

L1 := [z^2, y*z, x*z, z, y^2, x*y, y, x^2, x, 1]:

P(L1, V);

[1, x, y, z, x^2, y*x, z*x, y^2, z*y, z^2]

L2 := [z^2, y*z, y, x*z, y, z^2, y, x*z, z, y^2, x*y, y, x*z, x^2, x, 1, x]:

P(L2, V);

[1, x, x, y, y, y, y, z, x^2, y*x, z*x, z*x, z*x, y^2, z*y, z^2, z^2]

@emendes Would you rather see the original z,z,z,z in the output list, or 4*z? (both are easy to accomodate)

2 3 4 5 6 7 8 Last Page 4 of 591