acer

13156 Reputation

29 Badges

11 years, 210 days

On google groups. (comp.soft-sys.math.maple and sci.math.symbolic)

On stackoverflow.

On math.stackexchange.com.

MaplePrimes Activity


These are answers submitted by acer

Since Maple 2015 all platforms of Maple (Linux, OSX, Windows) have used BLAS and LAPACK functions from the Intel Math Kernel Library (MKL) for hardware floating-point linear algebra. That functionality can be utilized by computations other than just overt calls to LinearAlgebra commands.

The kernelopts(numcpus) setting will not affect the number of cores that may be used by those functions. But the OS enviroment variable OMP_NUM_THREADS will restrict that number of cores. As the system administrator you could set that variable in the two shell scripts maple and xmaple, both found in the bin directory of the Maple installation.

You can verify that it is functioning with the following code:

M:=LinearAlgebra:-RandomMatrix(5000,datatype=float[8]):

CodeTools:-Usage(LinearAlgebra:-Eigenvectors(M)):

The printout of that last command might look like the following on an otherwise unloaded 4-core 64bit Linux machine with that variable unset (or set to 4):

memory used=0.75GiB, alloc change=0.78GiB, cpu time=3.39m, real time=51.59s, gc time=32.00ms

The "cpu time" reported is the sum from all threads. Note that it is about 4 times greater than the "real time", which essentially means that four cores were in heavy use. The Linux utility `top` showed a load average of as high as about 3.40 while that was computing.

Now, with that environment variable set to 1 (in the maple shell script) the printout I see is like this:

memory used=0.75GiB, alloc change=0.78GiB, cpu time=68.50s, real time=68.56s, gc time=32.00ms

In that case top showed a load average no higher than about 1.05. And the "real time" matches the "cpu time" which is the sum for just the single thread.

The reason that the 4-thread case "real time" was not so very much faster than the single-thread case "real time" is that the nonsymmetric eigenvector algorithm is not so easily parallelized effectively throughout as is, say, matrix-matrix multiplication. But that's rather incidental to this illustration.

You can also check the value of a OS variable, within Maple, using the getenv command. Eg,

getenv("OMP_NUM_THREADS");

Regarding what Carl mentioned about kernelopts(numcpus=n) only working once, as an initial command. That's good news for your situation, since if you set it within a system-wide Maple initialization file then it could hold forcibly throughout your users' sessions.

for a from 1 to 20 do
  printf("%s\n",sprintf("%a",[op(numtheory:-divisors(a))])[2..-2]);
end do:

1
1, 2
1, 3
1, 2, 4
1, 5
1, 2, 3, 6
1, 7
1, 2, 4, 8
1, 3, 9
1, 2, 5, 10
1, 11
1, 2, 3, 4, 6, 12
1, 13
1, 2, 7, 14
1, 3, 5, 15
1, 2, 4, 8, 16
1, 17
1, 2, 3, 6, 9, 18
1, 19
1, 2, 4, 5, 10, 20

Or, if you don't want to reproduce it as a triangle,

seq(op(numtheory:-divisors(a)), a=1..20);

1, 1, 2, 1, 3, 1, 2, 4, 1, 5, 1, 2, 3, 6, 1, 7, 1, 2, 4, 8, 1, 3, 9, 1, 2, 5, 10, 1, 11, 1, 2, 3, 4, 6, 12, 1, 13, 1, 2, 7, 14, 1, 3, 5, 15, 1, 2, 4, 8, 16, 1, 17, 1, 2, 3, 6, 9, 18, 1, 19, 1, 2, 4, 5, 10, 20

The OP has written that, "The format of the input shouldn't matter."

But of course it can matter. Symbolic integration of expressions containing float-ing point approximations is not always a great idea. In this case alternatives include 1) floating-point numeric integration of the expression containing floats, 2) tricky, extra effort to get symbolic integration of the expression containing floats to behave better, and as mentioned 3) symbolic integration of the expression with exact rather than floating-point coefficients.

(This site doesn't render the worksheet below very nicely. Sorry.)
 

restart

with(VectorCalculus):

R := 1;

1

.6

.8

x := proc (t) options operator, arrow; (R+`-`(r))*cos(t)+d*cos((R+`-`(r))*(1/r)*t) end proc:

y := proc (t) options operator, arrow; VectorCalculus:-`+`(VectorCalculus:-`*`(VectorCalculus:-`+`(R, `-`(r)), sin(t)), `-`(VectorCalculus:-`*`(d, sin(VectorCalculus:-`*`(VectorCalculus:-`*`(VectorCalculus:-`+`(R, `-`(r)), 1/r), t))))) end proc:

 

The ArcLength command allows us to generate the result as an inert integral.

 

Q := ArcLength(`<,>`(x(t), y(t)), t = 0 .. VectorCalculus:-`*`(6, Pi), inert);

Int(((-.4*sin(t)-.5333333334*sin(.6666666668*t))^2+(.4*cos(t)-.5333333334*cos(.6666666668*t))^2)^(1/2), t = 0 .. 6*Pi)


We can force so-called numeric integration (ie. floating-point quadrature) by applying the evalf command to that inert integral.

 

evalf(VectorCalculus:-ArcLength(VectorCalculus:-`<,>`(x(t), y(t)), t = 0 .. VectorCalculus:-`*`(6, Pi), inert));

11.52567160

 

Another way to force numeric integration is to supply the end-points as floats (or, one a float and the other of type numeric).

 

VectorCalculus:-ArcLength(VectorCalculus:-`<,>`(x(t), y(t)), t = 0 .. evalf(VectorCalculus:-`*`(6, Pi)));

11.52567160

 

Let's have another look at that inert integral.

 

P := VectorCalculus:-ArcLength(VectorCalculus:-`<,>`(x(t), y(t)), t = 0 .. B, inert);

Int(((-.4*sin(t)-.5333333334*sin(.6666666668*t))^2+(.4*cos(t)-.5333333334*cos(.6666666668*t))^2)^(1/2), t = 0 .. B)

 

There is a particular symbolic integration method which can produce a viable result. But note that its subsequent symbolic result is subject to round-off error during subsequent floating-point evaluation. Other choice of method of symbolic integration can go awry in other ways (including severe use of resources even in the presence of assumptions on B)

 

PP := `assuming`([int(op(P), method = ftocms)], [B > 0, B <= 6*Pi])

piecewise(1. < .1326291193*B, 2.305134319*floor(.1326291193*B), 0.)+piecewise(0. < 4166666667.*B-0.1570796327e11, 2.305134319*floor(.1326291193*B-.5000000000)+2.305134319, 0.)+1.120000000*((-0.2133333334e20*cos(.8333333334*B)^2+0.2177777778e20)^(1/2)*EllipticE(cos(.8333333334*B), .9897433186)*cos(.8333333334*B)^2+1.029077821*sin(.8333333334*B)*(0.2133333334e20*cos(.8333333334*B)^4-0.4311111112e20*cos(.8333333334*B)^2+0.2177777778e20)^(1/2)-1.*EllipticE(cos(.8333333334*B), .9897433186)*(-0.2133333334e20*cos(.8333333334*B)^2+0.2177777778e20)^(1/2))/(sin(.8333333334*B)*(0.2133333334e20*cos(.8333333334*B)^4-0.4311111112e20*cos(.8333333334*B)^2+0.2177777778e20)^(1/2))

T := subs(B = 6*Pi, PP)

piecewise(1. < 2.500000001, 2.305134319*floor(2.500000001), 0.)+piecewise(0. < 0.6283185308e11, 2.305134319*floor(2.000000001)+2.305134319, 0.)+1.120000000*((-0.2133333334e20*cos(15.70796327)^2+0.2177777778e20)^(1/2)*EllipticE(cos(15.70796327), .9897433186)*cos(15.70796327)^2+1.029077821*sin(15.70796327)*(0.2133333334e20*cos(15.70796327)^4-0.4311111112e20*cos(15.70796327)^2+0.2177777778e20)^(1/2)-1.*EllipticE(cos(15.70796327), .9897433186)*(-0.2133333334e20*cos(15.70796327)^2+0.2177777778e20)^(1/2))/(sin(15.70796327)*(0.2133333334e20*cos(15.70796327)^4-0.4311111112e20*cos(15.70796327)^2+0.2177777778e20)^(1/2))

forget(evalf):

Float(undefined)+Float(undefined)*I

Float(-infinity)

11.564284298113954460

 

Reiterating that last point: even forcing a particular method for symbolic integration, the presence of floats can cause severe difficulties.

 

RR := Int(op(subs(B = VectorCalculus:-`*`(6, Pi), [op(P)])), method = ftocms);

Int(((-.4*sin(t)-.5333333334*sin(.6666666668*t))^2+(.4*cos(t)-.5333333334*cos(.6666666668*t))^2)^(1/2), t = 0 .. 6*Pi, method = ftocms)

Float(undefined)+Float(undefined)*I

Float(-infinity)

11.564284298113954460

 

Someone else mentioned that the symbolic integration works fine for this example if the floats in x(t), y(t) are turned into exact rationals.

 

VectorCalculus:-`<,>`(x(t), y(t));

map(combine, convert(%, rational));

Vector[column]([[.4*cos(t)+.8*cos(.6666666668*t)], [.4*sin(t)-.8*sin(.6666666668*t)]], ["x", "y"])

Vector[column]([[(2/5)*cos(t)+(4/5)*cos((2/3)*t)], [(2/5)*sin(t)-(4/5)*sin((2/3)*t)]], ["x", "y"])

(56/5)*EllipticE((4/7)*3^(1/2))

11.52567160

 


 

Download hypotrochoid_2.mw

Make your batch file print (whatever it thinks is) the PATH, when it runs successfully in a command shell.

Then adjust it to set PATH (for itself) explicitly to that very same thing.

[edit] If it relied on the current working directory (when functioning in cmd) then I suggest that 1) that is poor programming style, and 2) adjust the PATH anyway, but make it all fully qualified rather than relative.

Then try running it from Maple by escaping to a shell, using ssystem or system.

Below I give a procedure presubsuper which allows you to build the so-called atomic identifier (aka typeMK) for a pre-sub-superscripted name.

I also show that an unevaluated function call like, say, Iso(U,92,238) can be made to be automatically prettyprinted using that presubsuper procedure, by having its own so-called print-slash extension to the printing mechanism.

(This whole business could also be done, probably quite gracefully, using the more modern Maple object mechanism. I won't go there right now, but it would be fun to see how much physical chemistry or nuclear physics could be incorporated into static exports of such objects...).


 

restart;

presubsuper := proc(e,sub,super)
  nprintf("#mscripts(mi(%a),none(),none(),none(),none(),mn(%a),mn(%a))",
          convert(e,string),convert(sub,string),convert(super,string));
end proc:

Iso := proc(e,sub,super,$)
  return 'procname'(args);
end proc:

`print/Iso` := proc()
  presubsuper(args);
end proc:

presubsuper(U,92,238);

`#mscripts(mi("U"),none(),none(),none(),none(),mn("92"),mn("238"))`

Iso(U,92,238);

Iso(U, 92, 238)

op(Iso(U,92,238));

U, 92, 238

u := Iso(X,Z,A);

Iso(X, Z, A)

u;

Iso(X, Z, A)

A := foo: Z := bar: X := blah:

u;

Iso(blah, bar, foo)

A := 238: Z := 92: X := U:

u;

Iso(U, 92, 238)

he := Iso(He,2,4);

Iso(He, 2, 4)

th := Iso(Th,90,234);

Iso(Th, 90, 234)

Uranium := u implies th+he

Iso(U, 92, 238) implies Iso(Th, 90, 234)+Iso(He, 2, 4)

 


 

Download presubsuper.mw

The DocumentTools package can be used to programatically generate GUI Tables that are formatted like a report.

The DocumentTools:-Tabulate command provides an easy way to do that, though with ease-of-use comes less flexibility.

The subpackage DocumentTools:-Layout (and, less so here, DocumentTools:-Components) contains lower level commands with more flexibility. (It's what Tabulate uses). The results of the Layout commands can be saved to a new worksheet, opened in a new GUI tab, or embedded within the current worksheet (which you could also subsequently copy&paste).

The sticking point is your desire for LaTeX. The GUI's File->Export as... main menu item will produce LaTeX source for "the whole worksheet", as you probably know. It's a slight drawback that it requires use of one of Maple's own .sty files (bundled with the product). But the thorny bit is that support for such LaTeX export of GUI Tables is not good.

Let's call your AND(A->B, B->C) the statement P. And let's call your A->C the statement Q. It is the case that Q follows from P.

But you seem to be under the impression that Q is the only statement that follows from P. But it isn't. It's also not the case that P follows from Q, and so they are not equivalent. So what's your rationale for thinking that Q should be, say, the obvious or useful statement that follows from P?

It happens that Q does not contain a reference to B. Is that your reason want Q, because in that way it is simpler than P? I'm going to proceed along those grounds.

with(Logic):

p := (A &implies B) &and (B &implies C):

BooleanSimplify( eval(p, B=false) &or eval(p, B=true) );

                                  C &or &not(A)

# And you ought to be able to recognize the above as being
# equivalent to A->C

BooleanSimplify( A &implies C );

                                  C &or &not(A)

Your expression is a function call, rather than a multiplication (product) of the two bracketed terms.

Put either a space or an explicit multiplication symbol between the two bracketed terms. 

This is a common mistake (especially with users working in 2D Input mode since implicit multiplication fosters omission of the space).

n := 4:
L := [$1..n^2]:

A := Matrix(n,n,L);

rtable_redim(A,0..n-1,0..n-1);

Note that this changes A, in-place. You could also supply copy(A) as the first argument to rtable_redim. (I have sometimes relied on that in-place aspect, for efficiency.)

Matrix(1,4,(i,j)->j*x);

                       [x    2 x    3 x    4 x]

Matrix(1,4,(i,j)->unapply(j*x,x));

          [x -> x    x -> 2 x    x -> 3 x    x -> 4 x]

Matrix(1,4,(i,j)->subs(_J=j,x->_J*x));

          [x -> x    x -> 2 x    x -> 3 x    x -> 4 x]

I believe that the problem is due to over-agressive resampling of the data at the GUI rendering stage. That is to say, resampling when an Array within a CURVES substructure (of a PLOT structure) has many entries.

In my 64bit Maple 2015.2 for Linux there appears to be a threshold of 9999 for the rows of such CURVES Arrays, above which I see the more severe, reported clipping. By splitting such very tall m-by-2 Arrays into several smaller Arrays (all below the purported threshold) then the rendering behaviour improves considerably.

The following attachment was executed in that Maple 2015.2.

example_clipping_1.mw

There is still some resampling that occurs at the rendering stage, for more modest dimensions of CURVES Array. The above attachment also splits into yet a smaller size, exhibiting less beating patterning.

I expect that at least some level of resampling is needed at rendering, not only because the width in pixels of the target area may be smaller than the number of data points, but also for the goal of better GUI performance.

 

Is this what you want?

with(Statistics):

X:=Distribution(Normal(0,1)):

CDF(X, 0.7, numeric);

                       0.758036347776927

Quantile(X, %, numeric);

                       0.700000000000293

FWIW, using Maple 2016,

is( r^2 - r*s + s^2, positive ) assuming r>0, s>0, r<=s;

                            true

is( r^2 - r*s + s^2, positive ) assuming r>0, s>0, r>s;

                            true

So then I tried using an additional conjunction. Here's it failing even when I use a simple (new) name `T` with multiple properties inside an `Or`.

new := subs(s=T+r, r^2 - r*s + s^2):

is( new, positive ) assuming r>0, T+r>0, T<=0;

                                  true

is( new, positive ) assuming r>0, T+r>0, T>0;
                                  true

is( new, positive ) assuming r>0, T+r>0, Or(T<0, T>0, T=0);

                                  FAIL

is( new, positive ) assuming r>0, T+r>0, Or(T<=0, T>0);

                                  FAIL

If you are working in the Standard Java GUI, then you could try the following (I used Maple 2016.0).
 

restart;

twostep:=proc(expr::uneval)
  uses Typesetting;
  (Typeset(expr) =
   subsindets(expr,
     And(name,
         satisfies(t->type(eval(t),
           {constant,
            '`*`'({constant,
                   'specfunc'(anything,
                              Units:-Unit)})}))),
     z->Typeset(EV(z))))
   = combine(eval(expr),':-units');
end proc:

a := 1:
b := 3:
c := 5:

twostep(a + b*c);

(Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mi("b"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-mi("c")), Typesetting:-mo("&plus;"), Typesetting:-mi("a")) = Typesetting:-mn("3")*Typesetting:-mn("5")+Typesetting:-mn("1")) = 16

A := 70 * Unit(V):

B := 40 * Unit(ohm):

twostep(A/B);

(Typesetting:-mfrac(Typesetting:-mi("A"), Typesetting:-mi("B")) = Typesetting:-mrow(Typesetting:-mn("70"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-mfenced(Typesetting:-mi("V"), open = "&lobrk;", close = "&robrk;", Typesetting:-msemantics = "Unit"))/Typesetting:-mrow(Typesetting:-mn("40"), Typesetting:-mo("&InvisibleTimes;"), Typesetting:-mfenced(Typesetting:-mi("&Omega;"), open = "&lobrk;", close = "&robrk;", Typesetting:-msemantics = "Unit"))) = (7/4)*Units:-Unit('A')

 


 

Download units2step.mw


 

restart;

#
# I use prettyprint=1 below only because the %n labeling
# makes it easier to visualize the (desired) form of
# the result.
#

interface(prettyprint=1):

q := 20*x^3 + 10*x^2 + 4*x + 1;

Y:=[solve(q,x,explicit)]:

A,B:=selectremove(u->is(u,real),%):

#F:=u->simplify(radnormal(combine(u)),size):
#F:=u->simplify(simplify(u),size):
F:=u->simplify(evalc(u),size):

ans := `*`(map2(`-`,x,A)[])
       * collect(expand(`*`(map2(`-`,x,B)[])),x,F);

interface(prettyprint=3):
evalf(ans);

                                 3       2          
                        q := 20 x  + 10 x  + 4 x + 1

       /    1        7     1\ / 2   /1   1        7  \     1     1        49  
ans := |x + -- %1 - ---- + -| |x  + |- - -- %1 + ----| x + -- + --- %2 + -----
       \    30      6 %1   6/ \     \3   30      6 %1/     15   900      36 %2
                                                                              
       7      1    \                                                          
   + ----- - --- %1|                                                          
     36 %1   180   /                                                          
                                                                              
                                                                              
                         (1/3)                                                
      /            (1/2)\                                                     
%1 := \350 + 105 15     /                                                     
                         (2/3)                                                
      /            (1/2)\                                                     
%2 := \350 + 105 15     /                                                     

(x+.3423840949)*(x^2+.1576159051*x+.1460348210)

interface(prettyprint=1):

## Pick an example.
## I leave aside the special degree-4 case where A
## below is empty (in which case you may which to
## separate the two conjugate pairs in B).

#q := x^4 + x^3 + x - 1;
#q := x^4 + x - 1;
q := x^4 + x^2 + x - 1;

Y:=[solve(q,x,explicit)]:

A,B:=selectremove(u->is(u,real),%):

## You might experiment with various simpifiers
## which get applied to the coefficients of the
## expanded non-linear part, below.

#F:=u->simplify(radnormal(combine(u)),size):
#F:=u->simplify(simplify(u),size):
F:=u->simplify(evalc(u),size):

ans := `*`(map2(`-`,x,A)[])
       * collect(expand(`*`(map2(`-`,x,B)[])),x,F);

interface(prettyprint=3):
evalf(ans);

                                  4    2        
                            q := x  + x  + x - 1

               /    1       10    1\ / 2   /  2   1       10 \     2   1    
ans := (x + 1) |x - - %1 + ---- - -| |x  + |- - + - %1 - ----| x + - + -- %2
               \    6      3 %1   3/ \     \  3   6      3 %1/     3   36   
                                                                            
     100     10    1    \                                                   
   + ---- + ---- - -- %1|                                                   
     9 %2   9 %1   18   /                                                   
                                                                            
                                                                            
                       (1/3)                                                
      /          (1/2)\                                                     
%1 := \44 + 12 69     /                                                     
                       (2/3)                                                
      /          (1/2)\                                                     
%2 := \44 + 12 69     /                                                     

(x+1.)*(x-.5698402912)*(x^2-.4301597088*x+1.754877666)

 


 

Download realfactors.mw

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