acer

32632 Reputation

29 Badges

20 years, 46 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Carl Love The cited error message, "Error, invalid 'if' statement" indicates that the OP was trying this in 2D Input mode.

It won't work in 2D Input, even in Maple 2023.

@digerdiga The context-menu conversion to Atomic Variable changes the input (in situ) into the kind of representation that I was building programatically in my Answer.

I had guessed (maybe wrongly) that you wanted to be able to programatically build such a thing, for multiple inputs.

Also, yes, non-executable math mode does't produce output. But you can mix it in with written text, for exposition.

@Carl Love But it appears that the OP wants the result to display in the a=b=c form (the first example in my Answer), rather than as some inert and form (the 2nd and 3rd examples in my Answer).

@digerdiga 

nprintf("#mrow(%a,mo(\"=\"),%a,mo(\"≤\"),%a)",
        Typesetting:-Typeset(P(X <= 5) = P(-5 <= -X)),
        Typesetting:-Typeset(P(E(X) - 5 <= E(X) - X)),
        Typesetting:-Typeset(P(E(X) - 5 <= abs(E(X) - X))));
 

`#mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mi("P"),Typesetting:-mo("&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi("X"),Typesetting:-mo("&le;"),Typesetting:-mn("5")))),Typesetting:-mo("&equals;"),Typesetting:-mrow(Typesetting:-mi("P"),Typesetting:-mo("&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mn("&uminus0;5"),Typesetting:-mo("&le;"),Typesetting:-mrow(Typesetting:-mo("&uminus0;"),Typesetting:-mi("X")))))),mo("&equals;"),Typesetting:-mrow(Typesetting:-mi("P"),Typesetting:-mo("&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mi("E"),Typesetting:-mo("&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mi("X"))),Typesetting:-mo("&minus;"),Typesetting:-mn("5")),Typesetting:-mo("&le;"),Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mi("E"),Typesetting:-mo("&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mi("X"))),Typesetting:-mo("&minus;"),Typesetting:-mi("X"))))),mo("&le;"),Typesetting:-mrow(Typesetting:-mi("P"),Typesetting:-mo("&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mi("E"),Typesetting:-mo("&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mi("X"))),Typesetting:-mo("&minus;"),Typesetting:-mn("5")),Typesetting:-mo("&le;"),Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mi("E"),Typesetting:-mo("&ApplyFunction;"),Typesetting:-mfenced(Typesetting:-mi("X"))),Typesetting:-mo("&minus;"),Typesetting:-mi("X")),open = "&verbar;",close = "&verbar;",Typesetting:-msemantics = "abs")))))`

Download ts_inert_ex2.mw

Some related entities are  &le;   &lt;   &ge;   &gt;
corresponding respectively to    <=    <    >=    >

In this nprintf call the three %a placeholders in the format string get replaced by the latter three arguments.  The first argument is the format string, and there most everything else (apart from the %a placeholders) are blobs of XML-style markup. The interior doublequotes in the format string are escaped \".

I used nprintf above to get a name-form of markup. The GUI also understands an operator-form. You can also build that up programmatically. For example,
   ts_inert_ex3.mw

@digerdiga Could you provide an example or what else you might want?

@Christian Wolinski It's not clear why you mention an "exact match".  It gives the same results as,

   A::'Matrix(4,4)' and LinearAlgebra:-Norm(A)=0;

with both methods accepting Matrices containing either exact or float zeroes.

ps. I like to do the dimension check first, so as (potentially) to fail out there before having to check all entries.

But reversing the order of the tests in just one of these approaches would make the approaches match (both throwing an error, or both not) in the case that A is not actually a Matrix. Alas, the OP did not really answer my query about whether the input would always be an actual Matrix.

@Jamie128 I'll mention that code would also produce A if used on a Matrix that contained floating-point zero, ie. 0.0 .  Reply if you'd want that not to happen.

Please put followup queries on this example (and related simplification or verification) as Replies/Comments here, instead of starting wholly separate new Question threads for such.

@mmcdara I wholeheartedly agree with the idea that it's often very beneficial to extend a solution and answer, past what a poster has written.

It was your sentence, "The key is to define the rewritting rules rel that will lead you to the desire result." that I found confusing.

The form that your rel rules reveal was not mentioned by the OP, and it's also not hands-down obviously superior, so why do you say that it's "the desire result" [emphasis mine]?

I didn't intend offence. It's the use of the definite article that surprised me. This might be just a translation thing.

@mmcdara I know how the Statistics package works, but thanks for your comment. I used rand and code in the OP's general form, only to try and keep it more consistent with his earlier style.

I already thought that it was clear (and obvious) that one could use a larger number of dice, to get the uniform distribution over the fixed (original) range. I used the same number n (20) in both spots only because the OP had.

The OP sometimes takes several messages before the true goal appears.

I often regret guessing, on this forum. I'll leave this thread now.

@mmcdara In the OP's original Question the stated target expressions appear (modulo rational coefficient rearrangements) as they do in your computed trigsol results.

The reformulation formed by your use of your rel equations is interesting, but not actually requested in the original Question. I'll note that one can also get it without having to write out those rel equations manually, ie.

   simplify(expand(trigsol),size)

@Gabriel Barcellos As you mention, this only affects the latter part, whose only purpose was to reformat the rational coefficients just as you wanted. The answer in the first part is already correct, and in trigh rather than exp calls.

I had shown 1D Maple Notation code. Not all such code can be simply copy&pasted in as 2D Input.

In particular I had used the infix form of an inert operator call, eg.
    foo %* bar

That infix syntax is not supported at present in 2D Input mode. But you can instead use the prefix form call in 2D Input mode, eg.
    `%*`(foo,bar)

V := exp(lambda*S) = S^4*a4 + S^3*a3 + S^2*a2 + S*a1 + a0:

raw := convert(combine(expand(solve({seq(V,S=[2,1,0,-1,-2])}))),trigh):

raw := remove(evalb, raw):

`~`[`@`(print, InertForm:-Display)](`~`[proc (u) options operator, arrow; `if`((rhs(u))::constant, rhs(u), `%*`(content(rhs(u)), rhs(u)/content(rhs(u)))) end proc](raw), 'inert' = false)

1

0, "%1 is not a command in the %2 package", _Hold, Typesetting

0, "%1 is not a command in the %2 package", _Hold, Typesetting

0, "%1 is not a command in the %2 package", _Hold, Typesetting

0, "%1 is not a command in the %2 package", _Hold, Typesetting

Download solve_trigh_2Dmath.mw

@Thomas Dean I'd prefer my second way, which works even in old Maple 16,

kernelopts(version);

`Maple 16.01, X86 64 LINUX, May 6 2012, Build ID 744592`

expr := 2*A*B/(A*m+m)+C^2+D^2;

2*A*B/(A*m+m)+C^2+D^2

Second way

divid := (u,F) -> expand(numer(u)/F)/expand(denom(u)/F):

 

map(divid, expr, A*m);

2*B/(m*(1+1/A))+C^2+D^2

Download ut_M16.mw

@srwarner 

You should provide at least one complete example, showing all all its programmatic input, and describing clearly all that you want to be able to accomplish programmatically. If it's only a toy example then you should describe the broader class you want to handle.

This is a long Question thread, but I haven't seen any such clear and comprehensive description here.

@srwarner 

restart;

interface(showassumed=0):

assume(m < 0, x <= y, 0 < x);

map(`*`,x <= y, m)

x*m <= y*m

is( % );

false

map(`*`,x <= y, -m)

-x*m <= -y*m

is( % );

true

Download inequality_basic.mw

First 61 62 63 64 65 66 67 Last Page 63 of 597