acer

31896 Reputation

29 Badges

19 years, 204 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Did you have a particular kind of f(x) in mind?

I don't mean so that we could just show a 2D plotting call, because I know that you know how to do that well. I mean so that we could check against any FunctionAdvisor attempt.

@NIMA112 You have non-function-call terms with omega, such as,

    omega * (x + xi)

and,

    omega * abs(x - xi)

as well as terms with function calls, such as,

    cos(omega(y + eta))

and,

    D(omega)(y + y__0)

What did you intend for all of those to mean, taken together?

Try attaching a renamed version of the worksheet .mw file, without the "&" character.

@jasser 

Do you want all possible sums >=  maxsum, or all the combinations whose sum = maxsum?

I only ask because you haven't commented on that aspect in what mmcdara has shown, checking against the strict equality (so that all the returned lists have sum=N).

Also, how many elements might be in your "longer lists"? And how fast do you need it?

Do you need the results separate, for the various odd q values? Or is it ok to do them all at once?

@C_R In the above, the Equation Label is acting similarly to the case where the input was written literally, as opposed to the case of being the value of an assigned name.

That might be the correct behavior of evaluation for the Equation Label's insertion. When I say "correct" I mean that having an inserted Eq.Label behave like an assigned name might have other kinds of problems. Certainly Eq.Labels have had evauation issues -- and tweaks/fixes -- over the years. I would believe it if a kernel expert told me that Equation Labels ought to act exactly like literal input.

The second and third add examples in my worksheet above both throw the same error if the sequence has four or more elements. In that case they both still don't work similarly to the case of an assigned variable. Using a list still handles that case fine. add_seq_ex2b.mw

So examples 2&3 don't act like examples 1&4, whether the sequence has three elements or more. That aspect, which was my main point, remains just the same as before.

I originally chose a sequence of three elements simply because the call to add using the literal sequence as arguments (third example above) happens to (kinda, sort of) match an esoteric add call with a skip/step value, and so produces no error message. The absence of an emitted error means that a user is less likely to notice the wrong&unintended result.

ps. I deliberately put in the Equation Label example because I know that you use such.

@C_R I'll make another comparison, if I may.

The last three calls below (ie. wrapping in a list) form an approach that works consistently, and has no unexpected "gotcha" pitfalls.

That approach, to pass in a list, also happens to guard against your case of a single scalar (product, say).

restart

S := 3, 5, 7

3, 5, 7

(1)


These next three produce mixed results.

The second and third will catch some people out,
unexpectedly. (The second looks like a bug.)

 

add(S)

15

(2)

add(3, 5, 7)

3

(3)

add(3, 5, 7)

3

(4)


These next three produce mixed results.

So, while none is wrong, it's not a syntax that
provides for a consistent approach.
Also, single-quotes tend to confuse people, and
they are ephemeral.

 

add('S')

S

(5)

add('3, 5, 7')

15

(6)

add('3, 5, 7')

15

(7)


These next three produce the same results, using
a consistent approach.
A list is a robust and easily understood structure.

 

add([S])

15

(8)

add([3, 5, 7])

15

(9)

add([3, 5, 7])

15

(10)


Download add_seq_ex2.mw

@C_R I'll split this response in a few parts:

1) In Section 3.1.1 of the Programming Guide there is some discussion of expression sequences. It shows a few things that can't be done with a vanilla procedure and passing expression sequences as arguments. And it also shows that (automatic simplification) flattening of expression sequences brings a few other, related limitations. Here are a few notes: seq_flat_ex01.mw

Difficulties in trying to pass expression sequences as arguments to procedure calls is a mistake on which some people stumble. (I have seen many, over the decades. Including some on this site, or elsewhere.)

2) There's another common issue with bare expression sequences, which is that one cannot normally construct an expression sequence of a single scalar and have it remain as an exprseq type/DAG/structure. You appear to have run afoul of this. And it's a common issue, as people learn and program in Maple. So, if your expression sequences might be constructed from just one element then you need to put in a check and handling for that case. Having `seq` or some constructor return a single scalar is thus a special case.

And very often one's code needs separate handling for the special case(s), and forgetting that can lead to unexpected errors or mistakes or wrong results. This is a fundamental issue with dealing with expression sequences.

3) Now, the Programming Guide doesn't moralize very much, or even provide much in the way of coding guidelines and notes on good programming practices. And there are things you can do in Maple that no Manual will inform you are in fact slightly dodgy.

And because of 1) and 2) handling and manipulating bare expression sequences is error prone. Those aspects can catch people off guard. In my not-so-humble opinion users are better off with lists than expression sequences in many situations.

4) It's very nice and convenient that Maple 2015 saw the new functionality to be able pass a list or Matrix/Vector to add and get the result without need for using an indexing variable. The single argument call add(M) is great, for list/set/rtable.

But the ability to call add(S) for S an expression sequence is dubious design. Users don't need more encouragement to pass expression sequences as arguments. Having a few more weird commands that allow it doesn't help, overall.

And since construction&deconstruction of list [S] from expression sequence S is decently efficient then there is no good reason for add to be able to work directly on expression sequences. And that functionality does contribute to functional ambiguity. It contributes to overall functional ambiguity. It contributes to functional inconsistency.

There are a few more bits that people ought not have to understand or muddle through. For example, in Maple 2015->2021 the second of these examples threw an error about an invalid second argument to add. In Maple 2022->2024 the result is just 3. Neither of those is easily comprehensible in light of the first example.

S:=3,4,5;
                                 S := 3, 4, 5

> add(S);
                                      12

> add(3,4,5);
                                      3

But lack of consistency and comprehensibility seem secondary, to me, relative to the earlier points against it; I don't see why it'd be a good idea altogether to have add act on an expression sequence.

I have no big objection to having add (and mul) act on the operands of a single scalar argument. What I don't care for is their functionality to accept expression sequences.

5) I don't recall your mentioning units before, in the context of this discussion. You haven't provided a full and explicit example, so I don't how it went awry.

@C_R 

The problem of expression sequences devolving into the special case of a scalar, and then unexpected behavior ensuing, is quite common. It is not rare. It is a basic level mistake, often encountered when people are relatively new to Maple. The problem is not at all restricted to add. It happens with lots of other code, and it happens often at a beginner level.

A much better solution is to adopt the general programming habit of not having bare expressions sequences floating around, or at least to get into the better habit of not passing them around in procedure calls. (There are a few exceptions, such as the prefix form of `*`(...), but those are relatively rare.)

I tried hard to convey an explanation earlier, but above you've just written the opposite conclusion and ascribed the earlier responses as justification of that misguided view.

Passing an expression sequence to add, and then being surprised when the scalar case is overlooked by the calling code, is user-error. It's an important case of user-error because left unchecked it will get the programmer into problems in many other situations not restricted to add.

The notion that add's functionality to act on operands of a scalar expression ought to be removed, just because you were caught off guard by uncareful use of expression sequences, is wrong.

The functionalities being discussed, for expression sequences and scalars, were introduced in the same release, just after Maple 18, IIRC. Yes, taken together those functionalities can lead to more mistakes. But if one of them had to be removed then it ought to be the handling of a bare expression sequence, because that is the one which mirrors suboptimal Maple programming more generally.

ps. I'm holding back above. Using bare expression sequences in one's code is an inferior Maple programming practice. Introducing the ensuing programming dangers, which are unnecessary and easily avoiding without large inefficiency, is a foolish approach.

ps. You've responded with, "After your comments, it seems even more likely that applying add to a scalar expression is dispensable and potentially `dangerous`." Now, three people responded so far to your Question, and all three of them suggested the call add([A]) instead of add(A), when A is an expression sequence. That's an endorsement for the idea of passing a list instead of a bare expression sequence. What's "dangerous" is the habit of passing expression sequences in procedure calls (they usually get flattened, which catches people off guard, and is easily avoidable, etc), rather than add's treatment of the operands of a scalar.

@jalal That was not clear to me from the original Question. Thanks.

You can apply handler procedure F to either the M or the Sol entries in your Tabulate calls. Below, I do it for both. It's your choice.

Systmes_Idea_ac2.mw

restart

L := [seq(S[i], i = 1 .. 12)]

sys_1 := [x+y = 2, x-y = 0]

sys_2 := [x+2*y = 3, x-3*y = -1]

sys_3 := [x+4*y = -3, x-3*y = -1]

sys_4 := [x+2*y = 3, x-3*y = 3]

sys_5 := [x-2*y = 3, x-3*y = -1]

sys_6 := [x+2*y = 7, x-3*y = -1]

sys_7 := [x+2*y = 8, x-3*y = -1]

sys_8 := [x+2*y = 9, x-3*y = -1]

sys_9 := [x+2*y = 10, x-3*y = -1]

sys_10 := [x+2*y = -3, x-3*y = -1]

sys_11 := [x+2*y = -4, x-3*y = -1]

sys_12 := [x+2*y = -5, x-3*y = -1]

M := [seq({(eval(cat(sys_, i)))[]}, i = 1 .. 12)]

[{x-y = 0, x+y = 2}, {x-3*y = -1, x+2*y = 3}, {x-3*y = -1, x+4*y = -3}, {x-3*y = 3, x+2*y = 3}, {x-3*y = -1, x-2*y = 3}, {x-3*y = -1, x+2*y = 7}, {x-3*y = -1, x+2*y = 8}, {x-3*y = -1, x+2*y = 9}, {x-3*y = -1, x+2*y = 10}, {x-3*y = -1, x+2*y = -3}, {x-3*y = -1, x+2*y = -4}, {x-3*y = -1, x+2*y = -5}]

F := proc (L::(({list, set})(equation))) local i; nprintf(`#%a;`, subs("\`\`" = "", convert(eval(('Typesetting:-Typeset')(('piecewise')(seq(op([``, L[i]]), i = 1 .. nops(L))))), `global`))) end proc

Sol := map(proc (sys) options operator, arrow; solve(sys, {x, y}) end proc, M)

[{x = 1, y = 1}, {x = 7/5, y = 4/5}, {x = -13/7, y = -2/7}, {x = 3, y = 0}, {x = 11, y = 4}, {x = 19/5, y = 8/5}, {x = 22/5, y = 9/5}, {x = 5, y = 2}, {x = 28/5, y = 11/5}, {x = -11/5, y = -2/5}, {x = -14/5, y = -3/5}, {x = -17/5, y = -4/5}]

DocumentTools:-InsertContent(DocumentTools:-Layout:-Worksheet(subs("centred" = "left", DocumentTools:-Tabulate(Matrix(4, 3, proc (i, j) options operator, arrow; `≡`(L[3*i-3+j], F(M[3*i-3+j])) end proc), width = 120, alignment = center, color = blue, fillcolor = "AliceBlue", output = XML))))

`≡`(S[1], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("0",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("2",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[2], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("3",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[3], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("4",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[4], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("3",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("3",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[5], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("3",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[6], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("7",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[7], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("8",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[8], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("9",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[9], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("10",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[10], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[11], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("4",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[12], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("3",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("+",mathcolor = "blue"),mn("2",mathcolor = "blue"),mo("⁢",mathcolor = "blue"),mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("−",mathcolor = "blue"),mn("5",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

 

Solutions

DocumentTools:-InsertContent(DocumentTools:-Layout:-Worksheet(subs("centred" = "left", DocumentTools:-Tabulate(Matrix(4, 3, proc (i, j) options operator, arrow; `≡`(L[3*i-3+j], F(Sol[3*i-3+j])) end proc), width = 120, alignment = center, color = blue, fillcolor = "LightYellow", output = XML))))

 

`≡`(S[1], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("1",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[2], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mfrac(mn("7",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mfrac(mn("4",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[3], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("&uminus0;",mathcolor = "blue"),mfrac(mn("13",mathcolor = "blue"),mn("7",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("&uminus0;",mathcolor = "blue"),mfrac(mn("2",mathcolor = "blue"),mn("7",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[4], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("3",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("0",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[5], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("11",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("4",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[6], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mfrac(mn("19",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mfrac(mn("8",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[7], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mfrac(mn("22",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mfrac(mn("9",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[8], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("5",mathcolor = "blue"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mn("2",mathcolor = "blue"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[9], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mfrac(mn("28",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mfrac(mn("11",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[10], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("&uminus0;",mathcolor = "blue"),mfrac(mn("11",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("&uminus0;",mathcolor = "blue"),mfrac(mn("2",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[11], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("&uminus0;",mathcolor = "blue"),mfrac(mn("14",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("&uminus0;",mathcolor = "blue"),mfrac(mn("3",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

`≡`(S[12], `#mfenced(mtable(mtr(mtd(mrow(mi("x",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("&uminus0;",mathcolor = "blue"),mfrac(mn("17",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none())),mtr(mtd(mrow(mi("y",mathcolor = "blue"),mo("=",mathcolor = "blue"),mo("&uminus0;",mathcolor = "blue"),mfrac(mn("4",mathcolor = "blue"),mn("5",mathcolor = "blue"),mathcolor = "blue",linethickness = "1"))),mtd(none()))),open = mo("{",mathcolor = "blue"),close = mo("",mathcolor = "blue"))`)

 

 

Systmes_Idea_ac2.mw

It's now a Post, rather than a Question. (I changed your link)

Your sentence, "The function “add” (a built-in function with special evaluation rules) is intended to be used on sequences" is charged with fuzzy inaccuracy.

It happens that add can work on an expression sequence. But it is not "intended" that such is any kind of preferred usage. Passing expression sequences as arguments to procedure calls is a more generally ruinous habit, and would lead to far more mistakes.

Don't get into the habit of invoking add(S) where S is an expression sequence, when you could instead use the sane add([S]) call. Much more of the time you'll run into trouble elsewhere when you mistakenly try and pass sequences to procedure calls and they get flattened.

nb. If S is an expression sequence then it is uniquified in Maple's stored memory, and construction of the list [S] only increases internal memory use of the thin wrapper of the list structure -- it does not double the memory use. So constructing [S] from S is not very memory-inefficient.

Thus there is no reason to pass a scalar to add by mistake, because you never have to pass it a bare expression sequence.

And the behavior of add to work on operands of a scalar should therefore not be problematic. It's only problematic if you follow the poor strategy of passing bare expression sequences to add.

Someone else might want the behaviour of add's adding operands of a scalar expression, and mistakes than ensue because someone else ill-advisedly passes bare expression sequences to add is not a decent justification for removing the former functionality.

That's my opinion, but I've supplied a rationale for it. I think that add's acceptance of bare expression sequences is more of a design mistake than is add's handling of scalar expression's operands.

@C_R I'm not sure that ::evaln procedure parameter spec would always act as you were expecting. There are a few Constants names that would require other handling; assuming that you are just trying to avoid having to always enter the single left-quotes and so manually form the actual names yourself.

convert(..,name) might be more along the lines of what you wanted. (The ::uneval is optional...)

restart;

GetDef := proc(x::evaln) uses ScientificConstants;
            ((evalf*GetUnit)@Constant)(x);
          end proc:

GetDef(E[h]);

0.4359744650e-17*Units:-Unit(J)

GetDef(mu[d]/mu[e]);

Error, illegal use of an object as a name

GetDef(A[r](e));

Error, (in ScientificConstants:-Constant) expecting a name for 1st argument, got A[r](e)

restart;

GetDef := proc(x::uneval) uses ScientificConstants;
            ((evalf*GetUnit)@Constant)(convert(x,name));
          end proc:

GetDef(E[h]);

0.4359744650e-17*Units:-Unit(J)

GetDef(mu[d]/mu[e]);

-0.4664345535e-3

GetDef(A[r](e));

0.5485799091e-3

A,E,r,e,d,mu := 1,1,1,1,1,1:

GetDef(E[h]);

0.4359744650e-17*Units:-Unit(J)

GetDef(mu[d]/mu[e]);

-0.4664345535e-3

GetDef(A[r](e));

0.5485799091e-3

Download getdef_ex.mw

@C_R I don't personally like Equation Labels (even more than I don't care for alias). But I'm glad that the system is flexible and allows for differing styles of programmatic flow.

Here below is an example of the zeal for replacing assignments with Equation Labels taken too far. It gets rid of the rhs calls. Please take it in the intended spirit of friendliness. (The world seems to need such, right now.) There's a balance somewhere, where a non-Maple reader can understand more of the presentation.

restart

with(Units:-Simple); with(ScientificConstants); Units:-UseUnit(W/m^2)

T__0 := `#msub(mi("T"),mn("0"));`

 

sigma = (evalf*GetUnit)(Constant(sigma))

sigma = 0.5670366658e-7*Units:-Unit(kg/(s^3*K^4))

(1)

T__0 = 293*Unit('K'), T = 500*Unit('K')

`#msub(mi("T"),mn("0"));` = 293*Units:-Unit(K), T = 500*Units:-Unit(K)

(2)

E = sigma*T^4

E = sigma*T^4

(3)

`ΔE` = eval(E, E = sigma*T^4)-(eval(E, eval(E = sigma*T^4, T = T__0)))

`ΔE` = T^4*sigma-sigma*`#msub(mi("T"),mn("0"));`^4

(4)

simplify(`ΔE` = T^4*sigma-sigma*`#msub(mi("T"),mn("0"));`^4)

`ΔE` = sigma*(T^4-`#msub(mi("T"),mn("0"));`^4)

(5)

eval(`ΔE` = sigma*(T^4-`#msub(mi("T"),mn("0"));`^4), [sigma = 0.5670366658e-7*Units:-Unit(kg/(s^3*K^4)), `#msub(mi("T"),mn("0"));` = 293*Units:-Unit(K), T = 500*Units:-Unit(K)])

`ΔE` = 3126.070258*Units:-Unit(W/m^2)

(6)

NULL

Download roman_in_subscript_example_ac2.mw

On a more serious note, I think that,
    (evalf*GetUnit)(Constant(sigma))
is somewhat nice, ie. without too many instance of "sigma". It's the only actual improvement I might have had for your example.

ps. I wish that the Mapleprimes inline worksheet renderer did a better job with Equation Labels, leaving them right-aligned as in the actual Maple GUI.

@C_R So, for this particular example an assignment can serve in lieu of alias. That's all I was trying to convey.

I made some other stylistic changes, not because I think it's better, but just for fun.
i) If one has Eq 2 E=sigma*T^4 at hand then it can be used for Eq 3.
ii) UseUnit makes the unit-combining on target, though you might not want it elsewhere.
iii) 2D Input of 2-argument eval is a choice.

restart

with(Units:-Simple); with(ScientificConstants); Units:-UseUnit(W/m^2)

T__0 := `#msub(mi("T"),mn("0"));`

 

sigma = (evalf*GetUnit)(Constant(sigma))

sigma = 0.5670366658e-7*Units:-Unit(kg/(s^3*K^4))

(1)

E = sigma*T^4

E = sigma*T^4

(2)

`ΔE` = simplify(rhs((E = sigma*T^4)-(eval(E = sigma*T^4, T = T__0))))

`ΔE` = sigma*(T^4-`#msub(mi("T"),mn("0"));`^4)

(3)

params := [sigma = 0.5670366658e-7*Units:-Unit(kg/(s^3*K^4)), T__0 = 293*Unit('K'), T = 500*Unit('K')]

eval(`ΔE` = sigma*(T^4-`#msub(mi("T"),mn("0"));`^4), params)

`ΔE` = 3126.070258*Units:-Unit(W/m^2)

(4)

``

Download roman_in_subscript_example_ac.mw

@Mapleliquid As I wrote before, you cannot be directly using RGB since that requires three layers, ie. here, three matrices or sets of data.

And you only have a single Matrix whose number of entries matches the number of grid points in the plot.

So (instead of RGB) I have used your single Matrix of data can be used to specify the HUE of an HSV colorspace.

Note that in my second example I used the HSVtoRGB command from the ColorTools package. That's why I scaled the 0.0..1.0 values (from FitIntensity) by 360, like degrees.

The GUI's plot renderer can attempt its own rescaling of data, but it does well/best with just the 0.0..1.0 range. But it gets into numeric difficulty if the data is scaled too far from that; I happened to use the 0..360 scaled data (which my second example needs) for both approaches, since the GUI could handle that.

So, you could the 0.0..1.0 range for the first method I showed, and the 0..0..360.0 range for only the second. Here that is:  Plot1_ac2.mw

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