acer

10 years, 330 days


These are answers submitted by acer

immutable

August 25 2016 acer 12610

Unlike the (indexed table reference) name X[k] the name X__k is not itself mutable (though of course its assigned value is, but that's not relevant here).

It just happens that both table reference X[k] and X__k both happen to print in 2D Output as subscripted.

Compare the results of attempting to substitute for k (or to evaluate at a particular value for k),

eval( X__k, k=3 );
                                                            X__k

eval( X[k], k=3 );
                                                            X[3]

An easy way to get the sequence of distinct names X__1 , X__2,... is to concatenate the base name X__ with the various values attained by your sequence index k. There are several syntax choices for doing that. If you choose to utilize the `||` operator then I suggest reading the help page so as to understand the argument evaluation difference between that and `cat`.

seq( cat(X__,k) , k=1..3 );
                                                      X__1, X__2, X__3

seq( X__||k , k=1..3 );    
                                                      X__1, X__2, X__3

acer

frontend

August 25 2016 acer 12610

While I would also agree that Kitonum's use of applyrule is the simpler and better (and more easily adjusted for some similar examples) , I just thought that I'd mention that this particular example can also be done with frontend.

e := g^((2*(-sigma+k+1))/(-1+sigma)) - tau^2:

factor(map(u->frontend(expand,[u],[{`*`,`^`},{}]), e));

A fun(?) example might be to obtain a graceful way to get ss from ee below.

ee := g^(-(2*(-sigma+k+1))/(-1+sigma))-tau^(-2):
ss := (g^(-(-sigma+k+1)/(-1+sigma)) -tau^(-1))*(g^(-(-sigma+k+1)/(-1+sigma))+tau^(-1)):

acer

Could you adjust this to get close to what you want, in Maple itself?

restart;

F := proc(sc,a,b)
       local c;
       uses Typesetting, plots;
       c := 2^(max(1, ceil(log[2](sc))));
       display( plot( sin(x/sc), x = a .. b,
                      view = [a .. b, "default"],
                      xtickmarks=[], filled ),
                seq( textplot( [ i*Pi/c*sc, -0.2, Typeset(EV(i*Pi/c)) ]),
                     i = a/Pi*c .. b/Pi*c) ):
     end proc:

#plots:-animate(F, [sc,-2*Pi,2*Pi], sc=1 .. 16, frames=12, title="");

plots:-display( [seq( F(sc,-2*Pi,2*Pi), sc=1 .. 16, ((16-1)/12.0) )],
                insequence=true, gridlines=false );

 


Download scanim.mw

acer

2-argument eval

August 23 2016 acer 12610

One common way to deal with this sort of thing is to not assign to x at all. Just make an equation for x instead, and then use 2-argument eval whenever you wish to evaluate an expression containing x so that its x attains the value from the equation.

For example,

restart:

mu:=c^(a-b)/x;                   

                                                              (a - b)
                                                             c
                                                       mu := --------
                                                                x

xeq := x = (t^(1-s)+s^(1-2*s))^a:

mu;

                                                           (a - b)
                                                          c
                                                          --------
                                                             x

eval(mu, xeq);

                                                           (a - b)
                                                          c
                                                  ------------------------
                                                    (1 - s)    (1 - 2 s) a
                                                  (t        + s         )

1+mu;

                                                             (a - b)
                                                            c
                                                        1 + --------
                                                               x

eval(1+mu, xeq);

                                                             (a - b)
                                                            c
                                                1 + ------------------------
                                                      (1 - s)    (1 - 2 s) a
                                                    (t        + s         )

Another way to get some of these effects is to make the assignment to x but then also to contol the evaluation level tightly upon further use. That works for the example at hand but I would stress that it will often become more complicated when you attempt to pass the assigned mu around (especially as argument to subsequent function calls). This approach is also difficult to manage if your name assignments are chained. I recommend you try the first approach above (2-argument eval, with no asignment to x) instead.

restart;

mu:=c^(a-b)/x;

                                                              (a - b)
                                                             c
                                                       mu := --------
                                                                x

x:=(t^(1-s)+s^(1-2*s))^a:

mu; # full evaluation
                                                           (a - b)
                                                          c
                                                  ------------------------
                                                    (1 - s)    (1 - 2 s) a
                                                  (t        + s         )

eval(mu, 1);

                                                           (a - b)
                                                          c
                                                          --------
                                                             x

eval(mu, 2);

                                                           (a - b)
                                                          c
                                                  ------------------------
                                                    (1 - s)    (1 - 2 s) a
                                                  (t        + s         )

eval(1+mu, 1);

                                                             (a - b)
                                                            c
                                                        1 + --------
                                                               x

eval(1+mu, 2);

                                                             (a - b)
                                                            c
                                                1 + ------------------------
                                                      (1 - s)    (1 - 2 s) a
                                                    (t        + s         )

acer

Palettes

July 28 2016 acer 12610

Regarding your first example, the list of three integers returned by the NameToRGB24 command does not contain information of which Palette might have been in the original string. Moreover the color may exist in more than one Palette. In light of all that I do not find the notion sensible that the particular Palette identity (before calling NameToRGB24) should always be uniquely recoverable.

restart;
with(ColorTools):

MyColor := "CSS Red":
NameToRGB24(MyColor);
                                                [255, 0, 0]

Regarding your second example, the documentation of an additional keyword option palette of the RGB24ToName command is missing from that command's help page. (I will submit a bug report.)

In particular, it is possible to force it to search a subset (or all) of the known Palettes. For example,

with(ColorTools):

MyColor := "Resene LaRioja":

NameToRGB24(MyColor);   
                                               [179, 193, 16]

RGB24ToName( %, palette=ColorTools:-PaletteNames() );
                                              "Resene LaRioja"

RGB24ToName( %, palette="Resene" );  
                                              "Resene LaRioja"

kernelopts(version);

                         Maple 2016.1, X86 64 LINUX, Apr 22 2016, Build ID 1133417

Now back to the first example. Perhaps the return value should be a sequence of all the Palette-specified strings that contain the color.

restart;                          
with(ColorTools):                 
MyColor := "CSS Red":             
foo:=NameToRGB24(MyColor);        
                                             foo := [255, 0, 0]

RGB24ToName( foo, palette="CSS" ); # should return "CSS Red"?
                                                  "Red"

RGB24ToName( foo, palette="CSS", new=false ); # same deal
                                                   "red"

RGB24ToName( foo, palette=ColorTools:-PaletteNames() ); # should return a sequence?
                                                  "Red"

acer

I believe it encodes univariate polynomials as if they were in the older internal format for such DAGs rather than the relatively new (couple of years) structure (ZPPOLY? ). The idea being that the Standard GUI only understands the older format.

acer

some ideas

July 21 2016 acer 12610

Just a couple of ideas... perhaps you can turn one into something useful for you.

 

G1 := V = Pi*(d/2)^2*h;

                                       1     2  
                             G1 := V = - Pi d  h
                                       4        

StringTools:-Substitute( latex( algsubs( d/2=`d/2`, G1 ),
                                output=string),
                         "`d/2`", "d/2" );

                      "V=\pi\,h{\mbox {{\tt d/2}}}^{2}"

StringTools:-Substitute( latex( eval( G1, d=2*`d/2` ),
                                output=string ),
                         "`d/2`", "d/2" );

                      "V=\pi\,h{\mbox {{\tt d/2}}}^{2}"

StringTools:-Substitute( latex( eval( G1, d=2*`d/2` ),
                                output=string ),
                         "`d/2`", "{\\frac {d}{2}}" );

                "V=\pi\,h{\mbox {{\tt {\frac {d}{2}}}}}^{2}"

G2 := InertForm:-Display(V = Pi*( `%/`(d,2) )^2*h, 'inert' = false):

latex(G2);

V =\pi ~\frac{d }{2}^{2}~h

 


Download latex_as.mw

acer

printlevel

July 20 2016 acer 12610

See the help page for printlevel. (Note that the printlevel command is mentioned in this very regard on the help pages for both if and do.)

restart;

printlevel; # default
                                                              1

for i from 1 to 2 do for j from 1 to 2 do 'j'=j; end do; 'i'=i; end do;

                                                            i = 1

                                                            i = 2

printlevel:=2:

for i from 1 to 2 do for j from 1 to 2 do 'j'=j; end do; 'i'=i; end do;

                                                            j = 1

                                                            j = 2

                                                            i = 1

                                                            j = 1

                                                            j = 2

                                                            i = 2

acer

something

July 08 2016 acer 12610

With a little effort you might make this more robust.

restart:

G:=proc(e::algebraic, x::name)
  local o,alt,cands;     
  alt := eval(subsindets( e, identical(x), ()->'`tools/genglobal`(o)' ));
  cands := indets(alt,name) minus indets(e,name) minus {x};
  subs([seq(o=x,o=cands)], [seq(isolate(alt,nm),nm=cands)]);
end proc:

G( 2*x-tan(x), x );

                                    [x = 1/2 tan(x), x = arctan(2 x)]

G( 2*x-tan(x*y), x );

                                                          arctan(2 x)
                                   [x = 1/2 tan(x y), x = -----------]
                                                               y

acer

not a bug

July 08 2016 acer 12610

It is not a bug. It is deliberate that procedure bodies are not evaluated at construction time. (For the most part procedure bodies are also not automatically simplified, but that's another matter...)

It would be less useful in general if the final statement in the following returned 3*x.

restart;

a:=3:

f:=x->a*x:

a:=5:

f(x);

                                                   5 x

Having said that, the following variant does do what you intended (without recourse to unapply).

restart;

seq(subs(a=aa, x->a*x), aa=1..3);

                                    x -> x, x -> 2 x, x -> 3 x

restart;

f:=x->a*x;

                                              f := x -> a x

seq(eval(subs(a=aa, eval(f))), aa=1..3);

                                       x -> x, x -> 2 x, x -> 3 x

acer

Typesetting:-Settings

July 07 2016 acer 12610

The Typesetting:-Settings command covers this.

 

restart;

interface(typesetting=extended):

Typesetting:-Settings(prime);

x

diff(f(x),x), diff(f(t1),t1);

diff(f(x), x), diff(f(t1), t1)

Typesetting:-Settings(prime=t1):

diff(f(x),x), diff(f(t1),t1);

diff(f(x), x), diff(f(t1), t1)

 

 

Download prime.mw

acer

purpose

July 07 2016 acer 12610

If you are trying to recreate an accented name that already appears elsewhere (outside a code-edit-region) in your Worksheet/Document then lprint it as Robert suggests.

If you want it to appear as the typeset accented name inside the code-edit-region then you are out of luck.

If you are trying to construct an accented name as non-typeset, plaintext Maple Notation code, then you can either do a Robert suggests (create it in a 2D Math input elsewhere, and lprint that) or you can experiment with constructing it with code. For example,

restart;

placehat:=proc(x::name,{italic::truefalse:=false})
            cat(`#mover(`,
                `if`(italic,"mi","mn"),
                `("`,
                x,
                `"),mo("ˆ"))`);
          end proc:

placehat(UU);

placehat(x);

lprint(%);

placehat(x, italic);
lprint(%);

Note that the above code is 1D Maple Notation plaintext code. You can paste it into a code-edit-region or an execution group as 1D code and it should work. If you mistakenly paste it into a paragraph or execution group in 2D Input mode then it won't properly show you the `ˆ` thing.

On my Linux it seems to me that the `∧` and `ˆ` and `&Hat'` identifiers all render the same. You could try each.

Using the `placehat` procedure above you can see the difference between mi and mn, in typesetting. The mn renders like the upright text that appears in the typeset rendering of a string.

I am not satisfied with how these accents get centered according to the bottom of an italic rendered name, rather than the top. To me the accent appears a little too far left, when over an italic symbol.

acer

typesetting level

July 06 2016 acer 12610

The display you see is one consequence of having the typesetting level be extended rather than standard, That can be set via the interface command, or via the Tools->Options->Display preferences (main menubar).


restart;

kernelopts(version);

`Maple 2016.1, X86 64 LINUX, Apr 22 2016, Build ID 1133417`

interface(typesetting=standard):
1. * Unit(m);

1.*Units:-Unit('m')

interface(typesetting=extended):
1. * Unit(m);

1.*Units:-Unit('m')


Download tsetunit.mw

acer

dividend

July 06 2016 acer 12610

This kind of manipulation comes up often enough that Alejandro Jakubi wrote a useful utility for it (and similar operations).

restart;

dividend:=proc(ex,f:=numer(ex),t:=[expand,expand])
  local n,d;
  n:=t[1](numer(ex)/f):
  d:=t[2](denom(ex)/f);
  n/d;
end proc:

e:= w^2/(w^4+2*w^2+1);

                                                      2
                                                     w
                                           e := -------------
                                                 4      2
                                                w  + 2 w  + 1

dividend(e, w^2);

                                                   1
                                             -------------
                                              2        1
                                            w  + 2 + ----
                                                        2
                                                       w

dividend(e, numer(e));

                                                   1
                                             -------------
                                              2        1
                                             w  + 2 + ----
                                                        2
                                                       w

The third argument defaults to [expand,expand] and designates the intermediate operations applied to numerator and denominator (before the final division). But it can also be useful when those intermediate operations are some other custom action.

That source definition of dividend can be put in an initialization file, or it can be assigned the name saved to a personal utility Library archive.

acer

two ways

July 05 2016 acer 12610

One way (g below) involves having the original procedure be literal in the body of g.

Another way (which may not always work if your `f` is not set up to act like you intend when called with names as arguments) is to call `f` to obtain an expression, and then to `unapply` that to get your new procedure (G below).

restart;

f:=(x,y)->x+y:

g:=subs(_dummy=eval(f), x->_dummy(x,1)):

g(2);
                                                    3

G:=unapply(f(x,1),x);

                                             G := x -> x + 1

G(2);

                                                    3

f:=(x,y)->x+2*y:

g(2);

                                                    3

G(2);

                                                    3

acer

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