acer

32622 Reputation

29 Badges

20 years, 43 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Yes, there is something akin to automatic simplification that can take place with the infix form of and yet not with its prefix form. Actually it's more of a premature evaluation under evalb (see below).

[ edit: removed confusing poor comparison with automatic simplification of f()+f() vs `+`(f(),f()). ]

The help page for and mentions evaluation of strict equality under evalb. That also affects `<>` by which I mean unequal. For the infix form of and the evalb evaluation causes instances of infix `=` and `<>` to prematurely become just true or false. (It's not an exact analog to f()+f() since that cannot be prevented from simplifying automatically to 2*f() prior to evaluation of f() through use of single left quotes aka uneval quotes. But as you've seen there are similarities, I think.) This affects mixtures like say,

   u>0 and x<>y

which becomes just u>0 via u>0 and true . For the prefix form the evaluation of the `<>` part doesn't happen right away.

T:=`and`(u>0, x<>y);
                    T := 0 < u and x <> y

lprint(eval(T,1));
  0 < u and x <> y

T; # causing another evaluation
                            0 < u

Notice that the first result in the group above has the infix form as output. The effect here is that eventually (with enough evaluations) the x<>y will become true (because of the and). If it weren't for the wrapping and then the x<>y would not get hit by evalb and thence evaluate to true.

R:=x<>y;
                         R := x <> y

R;
                           x <> y

evalb(R);
                            true

One way to deal with this kind of thing is to use the prefix operator And instead of and.

Some of your other difficulties seem due to confusion between types and properties. For example is and assume deal with properties. They know of a real property. But there is no type real, so type evaluation (of double-colon, under evalb, under and)  produces the error message to that effect.

Your very last example does look like a weakness in Re.

I've heavily edited my Answer, trying to make my terminology more precise.

Using convert(...,base,2) ,
 

restart;
# Don't do something silly like assigning to the global name :-`2`.

p:=proc(x::realcons, ex::identical(:-exact):=NULL)
  local Ln,Ld,r;
  r:=convert(evalf(x),rational, ex);
  Ln:=convert(numer(r),':-base',2);
  Ld:=convert(denom(r),':-base',2);
  add(Ln[i]*`2`^(i-1), i=1..nops(Ln))
    /add(Ld[i]*`2`^(i-1), i=1..nops(Ld));
end proc:

p(2.142857143);
eval(%,`2`=2);
evalf(%);

(1+`2`+`2`^2+`2`^3)/(1+`2`+`2`^2)

 

15/7

 

2.142857143

(1)

p(-13.55555555);
eval(%,`2`=2);
evalf(%);

(-`2`-`2`^3-`2`^4-`2`^5-`2`^6)/(1+`2`^3)

 

-122/9

 

-13.55555556

(2)

p(-13.55555555, ':-exact');
eval(%,`2`=2);
evalf(%);

(-1-`2`-`2`^2-`2`^6-`2`^7-`2`^8-`2`^9-`2`^12-`2`^14-`2`^15-`2`^19-`2`^21-`2`^28)/(`2`^8+`2`^10+`2`^11+`2`^13+`2`^16+`2`^20+`2`^21+`2`^24)

 

-271111111/20000000

 

-13.55555555

(3)

Digits:=12;
evalf(Pi);
p(%);
eval(%,`2`=2);
evalf(%);
Digits:=10:

12

 

3.14159265359

 

(1+`2`^4+`2`^5+`2`^6+`2`^8+`2`^10+`2`^14+`2`^15+`2`^18)/(`2`^2+`2`^3+`2`^6+`2`^7+`2`^10+`2`^15+`2`^16)

 

312689/99532

 

3.14159265362

(4)

Digits:=12;
evalf(Pi);
p(%, ':-exact');
eval(%,`2`=2);
evalf(%);
Digits:=10:

12

 

3.14159265359

 

(1+`2`+`2`^2+`2`^3+`2`^6+`2`^9+`2`^10+`2`^12+`2`^13+`2`^14+`2`^15+`2`^16+`2`^19+`2`^20+`2`^22+`2`^24+`2`^26+`2`^29+`2`^32+`2`^35+`2`^38)/(`2`^11+`2`^13+`2`^14+`2`^15+`2`^17+`2`^18+`2`^20+`2`^21+`2`^22+`2`^27+`2`^30+`2`^32+`2`^33+`2`^34+`2`^36)

 

314159265359/100000000000

 

3.14159265359

(5)

 


 

Download b2.mw

You forgot the colon when trying to assign to `eq`.

You used only = instead of := and so you created an equation instead making an assignment.

Your original question was not clear about whether you wanted to pick off names according to the prefix or the subscript.

My Answer gets the names with a particular prefix. And of course you could use select instead of indets if your actual goal is to obtain the subexpressions in poly rather than just the suffixed names.

But if your actual goal is to get the names/subexpressions that have a particular "subscript" then see Carl's Answer.

restart;

poly:=a__b+b__a+a__b^2;

                                   2
                       poly := a__b  + a__b + b__a

indets(poly, 'suffixed(a__)');

                                  {a__b}

indets(poly, 'suffixed(b__)');

                                  {b__a}

another:=a__b+b__a+a__b^2+a__4^3*a__c;

                         3            2
          another := a__4  a__c + a__b  + a__b + b__a

indets(another, 'suffixed(a__)');

                       {a__4, a__b, a__c}

indets(another, 'suffixed(a__, integer)');

                             {a__4}

indets(another, 'suffixed(a__, name)');

                          {a__b, a__c}

indets(another, 'suffixed(a__, identical(c))');

                             {a__c}

With the values for some variables set as in special below, then is it not clear that there are infinitely many solutions for the remaning variables, if r22 is taken between -1 and 1?
 

restart;

eq1:=r11^2+r21^2+r31^2 = 1:
eq2:=r12^2+r22^2+r32^2 = 1:
eq3:=r13^2+r23^2+r33^2 = 1:
eq4:=r11*r12+r21*r22+r31*r32 = 0:
eq5:=r11*r13+r21*r23+r31*r33 = 0:
eq6:=r12*r13+r22*r23+r32*r33 = 0:
eq7:=-30*r13-.79382581863774e-1*s1*r11-.95259098236529e-1*s1*r12
     +.992282273297173*s1*r13 = -.83717247687439e-1*t1:
eq8:=-30*r13+.79382581863774e-1*s2*r11+.95259098236529e-1*s2*r12
     +.992282273297173*s2*r13 = .76364294519742e-1*t2:
eq9:=-30*r13-.86165283952334e-1*s3*r11+.103398340742801*s3*r12
     +.990900765451843*s3*r13 = -.81460429387834e-1*t3:
eq10:=-30*r23-.79382581863774e-1*s1*r21-.95259098236529e-1*s1*r22
     +.992282273297173*s1*r23 = -.107930827800543*t1:
eq11:=-30*r23+.79382581863774e-1*s2*r21+.95259098236529e-1*s2*r22
      +.992282273297173*s2*r23 = .60269029165473e-1*t2:
eq12:=-30*r23-.86165283952334e-1*s3*r21+.103398340742801*s3*r22
      +.990900765451843*s3*r23 = .105021268850622*t3:
eq13:=-30*r33-.79382581863774e-1*s1*r31-.95259098236529e-1*s1*r32
      +.992282273297173*s1*r33 = .990627255252918*t1-30:
eq14:=-30*r33+.79382581863774e-1*s2*r31+.95259098236529e-1*s2*r32
      +.992282273297173*s2*r33 = .995256820446840*t2-30:
eq15:=-30*r33-.86165283952334e-1*s3*r31+.103398340742801*s3*r32
      +.990900765451843*s3*r33 = .991128009660183*t3-30:

sys:=[eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,
      eq11,eq12,eq13,eq14,eq15]:
vars:=indets(sys, And(name,Non(constant)));

{r11, r12, r13, r21, r22, r23, r31, r32, r33, s1, s2, s3, t1, t2, t3}

special:=[r13=0, r23=0, r31=0, r32=0, r33=1,
          s1=0, s2=0, s3=0, t1=0, t2=0, t3=0]:

simpler:=remove(s->(lhs-rhs)(s)=0, {eval(sys, special)[]});

{r11^2+r21^2 = 1, r12^2+r22^2 = 1, r11*r12+r21*r22 = 0}

manysols:=solve(simpler, [r11,r12,r21], AllSolutions, Explicit):

map(print, manysols):

[r11 = r22, r12 = (-r22^2+1)^(1/2), r21 = -(-r22^2+1)^(1/2)]

[r11 = r22, r12 = -(-r22^2+1)^(1/2), r21 = (-r22^2+1)^(1/2)]

[r11 = -r22, r12 = (-r22^2+1)^(1/2), r21 = (-r22^2+1)^(1/2)]

[r11 = -r22, r12 = -(-r22^2+1)^(1/2), r21 = -(-r22^2+1)^(1/2)]

eval( eval(map(rhs-lhs,sys),special), manysols[1] );

[0, 0, 0, 0, 0, 0, 0., 0., 0., 0., 0., 0., 0., 0., 0.]

 


Download polysys2.mw

First, a few comments:

A few years (Maple major releases) ago the style of Help pages was changed so that Execution Group Boundaries were hidden from view in most Help pages Examples. The default setting for non-Help Documents and Worksheets is that Execution Group Boundaries are shown, however. That's the reason you see the mismatch between what appears in the Help page and what happens when you type the example into a fresh Document or Worksheet.

As Samir mentions, you can toggle the setting yourself, obtaining the non-default display that matches the current/modern Help pages.

nb. If, from the Help browser, you open the help page as a Document in the main Maple window then it retains its setting w.r.t. display/hiding of Markers like Execution Group Boundaries. So with default settings for File->New Documents/Worksheets (that show such Markers) you'll also see a mismatch between a fresh New Document and a Help page opened as Document.

Now, a suggestion:

I notice that your attachment is a Document, rather than a Worksheet. The more common unit for input/output in a Document is the Document-Block (which wraps around some Execution-Group) rather than the bare Execution-Group. An Execution-Group contained in a Document-Block does not get its Execution Group Boundaries shown. And so it seems to me that a Document-Block would provide an alternative, natural mechanism to get the effect you seem to want (of a Document's style) in your Document.

nb. The main menubar's View->Markers checkbox controls whether Document-Block boundaries are shown. Note that -- when shown -- those appear in a thin column to the left and outside of the actual sheet, whereas boundaries of bare Execution Groups are shown as black brackets within the actual sheet.

Here's an attachment where I have left the View->Show/Hide Contents...->Markers->Execution Group Boundaries toggled on. 

Download displayDocBlock.mw

You can apply the commands lhs and rhs to a range such as 1490.90920124091 .. 1497.18170785000 in order to extract the end-points.

expr := 1490.90920124091 .. 1497.18170785000:

lhs(expr);
                   1490.90920124091

rhs(expr);
                   1497.18170785000

I can reproduce the problem in Maple 17.02 on a 64bit OS X host as well as on a 64bit Linux host.

The problem seems (at least in part) to be in the `combine/ln` procedure, but I have not really dug down into that.

restart; kernelopts(printbytes=false):                                                         

kernelopts(version);

            Maple 17.02, APPLE UNIVERSAL OSX, Sep 5 2013, Build ID 872941

`combine/ln`:=u->u: # extraordinary measure

ans:=CodeTools:-Usage( int(3628800/(y*(1/2+y)^11)
                           -3628800/(y*(39/2+y)^11), y=39/2..infinity) ):
  memory used=13.75MiB, alloc change=32.00MiB,
  cpu time=218.00ms, real time=321.00ms

lprint(ans);                                                                                   

 87385605194015325709926400/3919454781758919*ln(2)-7431782400*ln(3)
 -7431782400*ln(13)-53097887349433051488808628851346857/
 282200744286642168000000000+7431782400*ln(5)

And now, after restart,

restart;
ans:=87385605194015325709926400/3919454781758919*ln(2)-7431782400*ln(3)
 -7431782400*ln(13)-53097887349433051488808628851346857/
  282200744286642168000000000+7431782400*ln(5):

combine(ans);
memory used=49975.3MB, alloc=2666.1MB, time=189.08
memory used=51387.2MB, alloc=4078.1MB, time=189.75
memory used=52093.2MB, alloc=4784.1MB, time=189.77
memory used=52097.7MB, alloc=4784.1MB, time=189.84
memory used=52099.3MB, alloc=4785.4MB, time=189.85
Interrupted

Another workaround for the given example is to force the ftocms method of the int command.

restart; kernelopts(printbytes=false):

ans:=CodeTools:-Usage( int(3628800/(y*(1/2+y)^11)-3628800/(y*(39/2+y)^11),
                           y=39/2..infinity, method=ftocms) ):
memory used=15.56MiB, alloc change=24.00MiB, cpu time=210.00ms, real time=314.00ms

lprint(ans);
 -53097887349433051488808628851346857/282200744286642168000000000
 +7431782400*ln(40)-29128535064671775175475200/
 3919454781758919*ln(39)-91750400/3919454781758919*ln(78)

oldans:=87385605194015325709926400/3919454781758919*ln(2)-7431782400*ln(3)
  -7431782400*ln(13)-53097887349433051488808628851346857/
  282200744286642168000000000+7431782400*ln(5):

simplify(ans - oldans);

                                     0

Here is a simpler instance of trouble within `combine/ln` . In Maple 

restart;                                                        
kernelopts(version);

        Maple 17.02, APPLE UNIVERSAL OSX, Sep 5 2013, Build ID 872941

expr:=87385605194015325709926400/3919454781758919*ln(2)-ln(3):

combine(expr);
memory used=195798.0MB, alloc=2666.1MB, time=25.01
memory used=198455.8MB, alloc=5324.0MB, time=26.77
memory used=201156.1MB, alloc=8024.2MB, time=29.39
Interrupted

Now, you wouldn't want `combine/ln` to never do anything, as in my crudest workaround at top.

I might be able to figure out how to patch your Maple 17.02 `combine/ln` (say as a "hotfix" with ToInert/FromInert to avoid copyright issues). If I do I'll let you know. (It might be related to the elif d = 1 then clause shown around line 92 under showstat(`combine/ln`) in your version. A preliminary attempt shows your example succeeding after that... but it'd require more examination. Such a change would, I suspect, return the shorter, simpler example above unchanged by combine.)

That link you gave indicates that within Matlab you can issue a command of the form

maple( ' ... ' )

and have the statement enclosed in single right-quotes be dispatched to the Maple symbolic engine. Is that correct?

If that is the case then (as I mentioned to you on stackexchange) you could use the Maple command zip to obtain a Matrix of equations from two given Matrix exp1 and exp2.  Did you try,

maple('zip(`=`,exp1,exp2)')

where the symbol `=`  is enclosed in single left-quotes?

Each of the commands evala , rationalize , and radnormal succeed in getting that form in Maple 17.02.

Using the avoid option of fsolve seems to be another way to get two distinct solutions.

Using 64bit Maple 2017.2 for Linux this worked for me at default Digits=10, without having to restrict the ranges narrower than the given 0<=beta,delta<=1 .

restart;

focdeltapioptS2Tbeta_eg := 2.*delta*(-8.016120437*10^13*beta-5.599041156*10^11*beta^4-9.950892840*10^12*beta^3+4.172202042*10^9*beta^2*delta^6-3.593992717*10^11*beta^5*delta^2-5.153172141*10^12*beta^4*delta^2+1.100201852*10^9*beta^4*delta^8+3.667339507*10^8*beta^6*delta^8-3.667339507*10^8*beta^3*delta^8-1.100201852*10^9*beta^5*delta^8+2.670209307*10^9*beta^4*delta^4+1.032944471*10^10*beta^3*delta^4+2.114848520*10^13*beta^2*delta^2-1.562440115*10^13*beta^3*delta^2-6.630411895*10^9*beta^3*delta^6-1.582188745*10^10*beta*delta^4+1.713992189*10^9*beta^5*delta^6+7.442176619*10^8*beta^4*delta^6+2.822233434*10^9*beta^2*delta^4+2.464874192*10^10*beta*delta^2+2.000000000*10^10*delta^2-5.383607038*10^13*beta^2)/(-2636.981242*beta^2*delta^2+2636.981242*beta*delta^2-4108.123654*beta-10000.)^3:

focbetapioptS2Tbeta_eg := (.8333333333*(1.784795533*10^13*beta^4*delta^6-1.780394727*10^13*beta^5*delta^6-5.910514827*10^13*beta^2*delta^4-5.501009263*10^10*beta^8*delta^6+1.701903476*10^14*beta*delta^2+1.100201852*10^10*beta^9*delta^6+1.100201852*10^11*beta^7*delta^6+5.842965601*10^12*beta^6*delta^6-3.878841795*10^13*beta+2.205824535*10^11*beta^5+1.735006720*10^11*beta^4+4.159889289*10^10*beta^6+7.379516540*10^12*beta^3-6.234247772*10^11*beta^6*delta^4+5.141976568*10^10*beta^8*delta^4-1.126878340*10^12*beta^5*delta^2-3.757524927*10^13*beta^4*delta^4+1.556869544*10^13*beta^5*delta^4-8.051300147*10^10*beta^7*delta^4+1.496707827*10^11*beta^6*delta^2+8.010627926*10^10*beta^7*delta^2+1.459035087*10^13-9.619344526*10^13*delta^2+2.590921095*10^11*beta^2-5.952985789*10^12*beta^3*delta^6+2.536603101*10^13*beta*delta^4+1.142130779*10^13*beta^4*delta^2-3.282217618*10^13*beta^2*delta^2-5.169893249*10^13*beta^3*delta^2+5.639818880*10^13*beta^3*delta^4))/((-1.+beta)^2*(-2636.981242*beta^2*delta^2+2636.981242*beta*delta^2-4108.123654*beta-10000.)^3):

fsolve({focdeltapioptS2Tbeta_eg, focbetapioptS2Tbeta_eg},
             {beta=0..1, delta=0..1}):
op(0,eval(%,1));
sol1:=%%;

set

{beta = .3884692297, delta = 0.}

fsolve({focdeltapioptS2Tbeta_eg, focbetapioptS2Tbeta_eg},
             {beta=0..1, delta=0..1}, avoid={sol1}):
op(0,eval(%,1));
sol2:=%%;

set

{beta = 0.3784251243e-4, delta = .3894512919}

fsolve({focdeltapioptS2Tbeta_eg, focbetapioptS2Tbeta_eg},
             {beta=0..1, delta=0..1}, avoid={sol1, sol2}):
op(0,eval(%,1));
# fsolve has returned unevaluated, ie. no other solution found.

fsolve

# We can automate the above process, attempting
# (avoiding) fsolve calls until it returns unevaluated.

foundsols:={}:
sol:=fsolve({focdeltapioptS2Tbeta_eg, focbetapioptS2Tbeta_eg},
             {beta=0..1, delta=0..1}, avoid=foundsols);
while type(eval(sol,1),specfunc(fsolve)) <> true do
  foundsols := foundsols union {sol};
   sol:=fsolve({focdeltapioptS2Tbeta_eg, focbetapioptS2Tbeta_eg},
             {beta=0..1, delta=0..1}, avoid=foundsols);
end do:
foundsols;

{beta = .3884692297, delta = 0.}

{{beta = 0.3784251243e-4, delta = .3894512919}, {beta = .3884692297, delta = 0.}}

kernelopts(version);

`Maple 2017.2, X86 64 LINUX, Jul 19 2017, Build ID 1247392`

 


Download bivar.mw

An earlier post of yours was marked as Product: Maple 18 , which would explain why you are not always getting the same results from other members here, using just the simplify command.

If that guess is true then please mark all your Mapleprimes Questions as Maple 18 for the Product.

In the attached worksheet I show how you can get simpler results using Maple 18.02.

Download simp18.mw

Use time[real]() instead of time() to compare wall-clock timing.

(...and make sure that your machine is not otherwise loaded.)

You could also wrap the call with CodeTools:-Usage . Note the "cpu time" shows the addition from all threads (concurrent or otherwise), which is why you need to compare real-time instead. Eg,

restart;
N:=1000000: with(Threads): CodeTools:-Usage( Seq(sqrt(i),i=1. .. N) ):
memory used=1.21GiB, alloc change=302.20MiB, cpu time=11.41s, real time=2.99s, gc time=3.23s

restart;
N:=1000000: CodeTools:-Usage( seq(sqrt(i),i=1. .. N) ):
memory used=1.21GiB, alloc change=247.64MiB, cpu time=9.14s, real time=6.47s, gc time=4.34s

To emulate the general effect of Matlab's parfor you could look at Threads:-Seq (if the statements are thread-safe) or Grid:-Seq.

Since the syntax for parfor is like a that of a do-loop you might have to use a procedure in the Seq call, if you're trying to get the effect of multiple statements.

One can compare also with:

restart;
solve({x^3+x*a+2 > 0}, x, parametric);

{            3
{ [[RootOf(_Z  + _Z a + 2, index = real[3]) < x],
              3
    [RootOf(_Z  + _Z a + 2, index = real[1]) < x,
                  3
     x < RootOf(_Z  + _Z a + 2, index = real[2])]] , a < -3

    [[1 < x], [-2 < x, x < 1]] , a = -3
               3
    [[RootOf(_Z  + _Z a + 2, index = real[1]) < x]] , -3 < a
However...
restart; solve({x^3+x*a+2 > 0, a>-3}, x);

                             1/3              1/3
                           %1        a      %1        a
                      {x < ----- - -----}, {----- - ----- < x}
                             3       1/3      3       1/3
                                   %1               %1

                                              3      1/2
                            %1 := -27 + 3 (3 a  + 81)

restart; solve({x^3+x*a+2 > 0, a<-3}, x);

                             1/3              1/3
                           %1        a      %1        a
                      {x < ----- - -----}, {----- - ----- < x}
                             3       1/3      3       1/3
                                   %1               %1

                                              3      1/2
                            %1 := -27 + 3 (3 a  + 81)
First 195 196 197 198 199 200 201 Last Page 197 of 339