acer

32632 Reputation

29 Badges

20 years, 47 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@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.

@MaPal93 I didn't see anything in your example that made me worry about continuing to use subs.

@lcz I added an alternative in my Answer, which for me produces a tabbed space between the columns of the exported file.

The file ends up looking like this, for me,

{{1, 6}, {2, 7}, {2, 8}, {4, 5}, {4, 6}, {5, 6}, {5, 7}, {5, 8}, {7, 8}}        3       infinity                                                                                                                           
{{1, 2}, {1, 4}, {2, 5}, {3, 4}, {3, 5}, {3, 6}, {5, 7}, {6, 8}, {7, 8}}        5       4                                                                                                                                  
{{1, 2}, {1, 7}, {2, 3}, {2, 4}, {3, 4}, {3, 8}, {4, 5}, {6, 8}, {7, 8}}        3       4                                                                                                                                  
{{1, 6}, {1, 7}, {2, 3}, {2, 8}, {3, 7}, {4, 7}, {4, 8}, {5, 8}, {7, 8}}        3       4                                                                                                                                  
{{1, 3}, {2, 6}, {2, 8}, {3, 6}, {3, 7}, {4, 7}, {4, 8}, {5, 7}, {7, 8}}        3       3                                                                                                                                  
{{2, 4}, {2, 7}, {2, 8}, {3, 4}, {3, 5}, {4, 6}, {4, 7}, {6, 7}, {6, 8}}        3       infinity                                                                                                                           
{{1, 3}, {1, 4}, {1, 5}, {1, 8}, {2, 4}, {2, 6}, {3, 6}, {4, 5}, {4, 8}}        3       infinity                                                                                                                           
{{1, 2}, {1, 6}, {2, 4}, {2, 6}, {3, 4}, {3, 5}, {3, 6}, {3, 8}, {4, 8}}        3       infinity                                                                                                                           
{{1, 2}, {1, 7}, {2, 4}, {3, 5}, {3, 8}, {4, 5}, {4, 8}, {5, 6}, {6, 7}}        4       4                                                                                                                                  
{{1, 2}, {1, 4}, {1, 7}, {2, 3}, {3, 8}, {4, 8}, {5, 6}, {5, 7}, {6, 8}}        5       3

@MaPal93 I'm still thinking about the `solve`. I might be busy for a few days, though.

As far as your last indets query goes, you could also do,

   indets(Eqs,And(name,Not(constant),Not(RandomVariable)))

if you want to exclude the _R, _R0, etc.

I also remembered something that I forgot to mention earlier. In my Answer's attachment I used subs instead of 2-argument eval to substitute placeholder names, because at some point I had noticed the eval was generating duplicates of the _R,_R0,.. names. But now I wonder whether it was because what was actually being used was RealDomain:-eval which might be more buggy. In any event, any other instance of such oddness would likely need a correction.

Because I'd mentioned the possibility of using densityplot...

fff := proc(x, y) local res, r;
 if not [x, y]::list(numeric) then
   return 'procname'(_passed);
 end if;
 r := y^2 + x^2;
 if 169.5^2 < r or r < 10000 then
   return undefined;
 end if;
 res := f(x, y);
 if not res::numeric then undefined;
 else res; end if;
end proc:

NN := 301:
P := plots:-densityplot(fff, -200 .. 200, -200 .. 200, style = surface, grid = [NN, NN], colorscheme = ["zgradient", ["Blue", "Red"], colorspace = "HSV"]):

AA := op([2], indets(P, specfunc(COLOR))[1]):
AA[..,..,3] := Array(1..NN,1..NN,1.0):

Pnew := subsindets(P, specfunc(COLOR), () -> COLOR(HSV, AA)):

plots:-display(Pnew, Tubeout, Tubein, Coreout);

And merging that with your other parts,

GraphTest.zip

@MaPal93 If you read the Help page for the indets command then you should see a bullet point in the Description section, that goes something like this:

    The argument expr is viewed as a rational expression (an expression
    formed by applying only the operations +, -, *, / to its subexpressions).
    Therefore, expressions such as sin(x), f(x, y), and  sqrt(x) are treated
    as indeterminates.

The point is that your calling indets(Eqs) without any options is not going to return only the unassigned names. If you want only names then you could call it as, say, indets(Eqs,name). Or, even more targeted (avoiding names like Pi, etc),
   indets(Eqs,And(name,Not(constant)))

Which reminds me to ask: you've used the name gamma. Did you intend that as some free name, or did you intend it as Euler's constant as Maple does by default. If the former then you could declare it at the start of your worksheet,
   local gamma;

I would not use the RealDomain package in involved computation. It's not very useful or robust, IMO. Instead I either make my assumptions (real, positive, etc) up front with assume or (my preference) pass them with assuming. I sometimes assign a sequence of the relevant assumptions to some name, so that I can easily re-use it for multiple assuming calls.

Reducing intermediate expression swell can sometimes be quite beneficial, lessening the burder on some commands (eg, solve, sometimes).

First 79 80 81 82 83 84 85 Last Page 81 of 597