acer

32313 Reputation

29 Badges

19 years, 313 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Carlos36r Hopefully this capture all the flavours in which you're interested...

Hopefully all readers of this will realize that this is an exercise in post-processing of solve results, and reformulating as equivalents. Naturally we could more easily pass the original arguments into one solve call, directly.

I duplicated a few steps, just for clarity's sake.

restart;

r1 := solve(x^2-1 > 0);

RealRange(-infinity, Open(-1)), RealRange(Open(1), infinity)

r1r := Or(`::`~(x,[r1])[]);

Or(x::(RealRange(-infinity, Open(-1))), x::(RealRange(Open(1), infinity)))

convert(r1r, relation);

Or(And(-infinity <= x, x < -1), And(1 < x, x <= infinity))

r2 := solve(x > 10);

RealRange(Open(10), infinity)

# For consistency, we could also use this
# as   r2r := Or(`::`~(x,[r2])[]);
r2r := x::r2;

x::(RealRange(Open(10), infinity))

convert(r2r, relation);

And(10 < x, x <= infinity)

allr := And(r1r,r2r);

And(Or(x::(RealRange(-infinity, Open(-1))), x::(RealRange(Open(1), infinity))), x::(RealRange(Open(10), infinity)))

convert(allr, relation);

And(Or(And(-infinity <= x, x < -1), And(1 < x, x <= infinity)), 10 < x, x <= infinity)

solve(convert(allr, relation));

RealRange(Open(10), infinity)

Now, another way (some parts trivial, of course).

The And@op is not needed for this example, but in general
there could be more that one inquality in each of several
alternative solutions returned by solve. So group those
solutions by And -- even if not necessary here.

restart;

s1 := solve(x^2-1 > 0, {x});

{x < -1}, {1 < x}

p1 := Or((And@op)~([s1])[]);

Or(And(x < -1), And(1 < x))

s2 := solve(x > 10, {x});

{10 < x}

p2 := Or((And@op)~([s2])[]);

Or(And(10 < x))

solve([p1,p2]);

{10 < x}

Download ineq_rel_Carlos.mw

@DEE_Engineering It's a preference.

Sometimes when I'm doing things similar to this I also want some additional effects, and when customizing & debugging I sometimes find aliases get in my way. I have a very low tolerance for any need for extra typing when probing, etc.

Here's a difference that may (or may not) matter for your tasks related to this: If you line-print (lprint) or convert to a string then the way I used will produce something with the actual words sin and cos. I often prefer that; you might not, here. Using that alias(s=sin,c=cos) then the line-printing will contain s and c.

note: this is not the reason that I don't use alias. But it's a possible reason that you might want it here, if you want the s/c effect in exported 1D formulas.

So, do you need to export your outputs as 1D plaintext formulas? (If you do, it would have been more useful to have mentioned that requirement at the outset...)

@sursumCorda Indeed, using evala, radnormal, or even rationalize to get the radical in the numerator will work here.

Surprisingly, even factoring the expression inside the radical (while keeping it in the denominator) works too.

I'll add all this to the bug report.

restart;

kernelopts(version);

`Maple 2023.0, X86 64 LINUX, Mar 06 2023, Build ID 1689885`

ee:=[1/(4*a + z^2 + (z^4 + 4*a*z^2)^(1/2)), -1/(z^2 - (z^4 + 4*a*z^2)^(1/2) + 4*a)];

[1/(4*a+z^2+(z^4+4*a*z^2)^(1/2)), -1/(z^2-(z^4+4*a*z^2)^(1/2)+4*a)]

factor(ee);
int~(%,z);

[1/(4*a+z^2+(z^2*(z^2+4*a))^(1/2)), 1/(-z^2+(z^2*(z^2+4*a))^(1/2)-4*a)]

[(1/4)*z/a-(1/4)*(z^4+4*a*z^2)^(1/2)/(a*z), -(1/4)*z/a-(1/4)*(z^4+4*a*z^2)^(1/2)/(a*z)]

simplify(ee);
int~(%, z);

[1/(4*a+z^2+(z^2*(z^2+4*a))^(1/2)), 1/(-z^2+(z^2*(z^2+4*a))^(1/2)-4*a)]

[(1/4)*z/a-(1/4)*(z^4+4*a*z^2)^(1/2)/(a*z), -(1/4)*z/a-(1/4)*(z^4+4*a*z^2)^(1/2)/(a*z)]

evala(ee);
int~(%, z);

[(1/4)*(z^2-(z^2*(z^2+4*a))^(1/2)+4*a)/(a*(z^2+4*a)), -(1/4)*(4*a+z^2+(z^2*(z^2+4*a))^(1/2))/(a*(z^2+4*a))]

[(1/4)*(z-(z^2*(z^2+4*a))^(1/2)/z)/a, -(1/4)*(z+(z^2*(z^2+4*a))^(1/2)/z)/a]

rationalize(ee);
int~(%, z);

[(1/4)*(z^2-(z^4+4*a*z^2)^(1/2)+4*a)/(a*(z^2+4*a)), -(1/4)*(4*a+z^2+(z^4+4*a*z^2)^(1/2))/(a*(z^2+4*a))]

[(1/4)*(z-(z^4+4*a*z^2)^(1/2)/z)/a, -(1/4)*(z+(z^4+4*a*z^2)^(1/2)/z)/a]

radnormal(ee);
int~(%, z);

[1/(4*a+z^2+(z^2*(z^2+4*a))^(1/2)), -1/(z^2-(z^2*(z^2+4*a))^(1/2)+4*a)]

[(1/4)*z/a-(1/4)*(z^4+4*a*z^2)^(1/2)/(a*z), -(1/4)*z/a-(1/4)*(z^4+4*a*z^2)^(1/2)/(a*z)]

Download gosh.mw

@NurinFYP As you've already been told (by two other people), actual code is key to diagnosing your difficulties.

That is especially true of 2D Input mode (which you are using) since there are some cases where different code renders very similarly, eg. beta__i versus beta[i] .

It's inconsiderate and unhelpful of you to continue showing only images of your followup difficulties, without actual code that can be used without having to retype it all based on an image.

You should upload and attach a link to your worksheet, using the green up-arrow in the Mapleprimes editor. You should do this each time you ask a followup query for some new difficulty.

@Christopher2222 My example -x^3-x^2+x-1 was not posed as a mere presentation challenge.

There are other ways that can handle mere presentation for both it and other flavours, in a more automatic and flexible manner, IMO.

But that was not my point. I mentioned it specifically because it's another class that cannot be transformed via sort into something that gets pretty-printed without a leading negative because of the way it's stored internally.

@Christopher2222 No, you are mistaken. Your suggestion to use subs would not work on the example I posed.

The most important thing about my example (which your response overlooks) is that if the original form has already been created in a session then the target form gets uniquified to that by the kernel's fundamental behavior of storing in memory only a single instance of a sum of terms. There are only a few mechanisms that can prevent that -- sort is one of them, and subs is not.

restart;

- (-K + a - a*sqrt(f))*b - b^2 + (-Q + a - a*sqrt(f))*b - 1

-(-K+a-a*f^(1/2))*b-b^2+(-Q+a-a*f^(1/2))*b-1

b*(a - Q - a*sqrt(f)) - b*(a - K - a*sqrt(f)) - b^2 - 1

-(-K+a-a*f^(1/2))*b-b^2+(-Q+a-a*f^(1/2))*b-1


It doesn't make any difference what usual mechanism you use (subs, or whatever) to create
   b*(a - Q - a*sqrt(f)) - b*(a - K - a*sqrt(f)) - b^2 - 1
because if the earlier form has already occupied the kernel's internal uniquification table for that session then this new reformed instance will merely get represented in the earlier manner (and not that desired manner).

So, for my more general example, you cannot reform the original (as an actual expression) unless you can replace it as the uniquified version stored in memory in that session. The sort command has that memory-in-place replacement power, but I don't see how sort can be used to make the whole reformulation in question.

That's a big reason why I chose that particular more general example -- because I suspect that sort (as outer call) cannot be used to do the required replacement. My point was that there are some examples which cannot be handled as easily as the OP's originals.

Here's another difficult flavour of example:
    - x^3 - x^2 + x - 1
Do you think that you could get that reformulated with the +x term as the leading summand?

And such examples are why I also hinted at merely printing the target form as a possible general alternative, using typesetting or other kludges.

@achreftabet 

You can use this list of eqautions to perform the reverse operation.

  invrepl := map(u -> u = u(t), [r, Z, U, V, W, S]);

  eval([seq(eq || i, i = 1 .. 6)], invrepl);

See attached document,

problem_1_ac.mw

You could change t to theta, if that's what you'd prefer.

problem_1_ac_theta.mw

Please don't put a followup query about doing the reverse of this in a wholly new and separate Question thread. Just mention it here, instead, if you need that.

@Anthrazit Yes, that's exactly what I meant, merging like,

   display(F, draw(B))

ps. Naturally, you don't have to use an embedded component 

@Anthrazit My Answer's title said geometry:-draw, and the URL link goes to that command's help page, and the two examples I showed used that command. Sorry if I misnamed it in one place in my text. I've corrected that.

My other point was that you can merge  results from geometry:-draw with other kinds of plots, by using plots:-display. In other words, the results are much like those of other, usual plotting commands 

Do you just need these two examples handled?

Or do you have some more general examples that you'd like to be handled programmatically?

In general it's tricky. For example I can make,

   - (-K + a - a*sqrt(f))*b - b^2 + (-Q + a - a*sqrt(f))*b - 1       

be rewritten as,

   - (a -sqrt(f)*a - K)*b - b^2 + (a - sqrt(f)*a - Q)*b - 1                  # sort(%,a)

but I have doubts about getting it rewritten as, say,

   (a - Q - a*sqrt(f))*b - (a - K - a*sqrt(f))*b - b^2 - 1

When I say rewritten I mean that the single instance of that expression stored in Maple's memory gets replaced -- without restart and in the same session in which the earlier form appeared.

On the other hand, it's tricky but not impossible to write a procedure which will show a 2D Output rendering of the beautified form. I don't know whether that'd be worthwhile for you.

@MaPal93 Your FOC_* are equations, their right-hand sides being zero. There's not much need for that (ie. solve doesn't require it).

You could pass lhs(FOC_*) to coeff, or simply not construct them as equations.

Why do you seem to think that `&+-` always means something particular in Maple, that might have that property?

@Carl Love That splits an Execution Group. But does it also split a Document Block?

@OliverB If I recall correctly, the undefined values were posing a difficulty for implicitplot, which is why I put in a fallback extreme numeric value.

First 73 74 75 76 77 78 79 Last Page 75 of 591