acer

32358 Reputation

29 Badges

19 years, 331 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

It works fine in Maple 14.01 on Windows.

I suspect either a problem with the installation, or an initialization file is setting something, or assigned values from an errant .mla archive are being pickled up.

acer

I doubt that the interpreted, Library level code of  evalf(Int(...)) is thread-safe. So perhaps you got lucky at first, and that Library code might still go wrong running under Threads:-Seq.

Also, the last I checked the Maple Library level define_external call for NAG d01amc was not being done with an option that designates it as thread-safe (the end result being that those particular external calls are blocking -- only one can run at a time). Ie, in Maple 16, I see no THREAD_SAFE option passed here to define_external(),

showstat(`evalf/int/NAGInt`::d01ajc,16);

`evalf/int/NAGInt`:-d01ajc := proc(func, xx, Left, Right, Eps, MaxNumSubInt)
local epsabs, epsrel, f, ret, NAGd01ajcM, max_num_subint, abserr, fun_count, num_subint, HFDigits, intfunc;
       ...
  16     NAGd01ajcM := ExternalCalling:-DefineExternal('hw_d01ajc',ExternalCalling:-ExternalLibraryName("int",'HWFloat'))
       ...
end proc

On the other hand, can you pull the rangeexp(amp,depth/4,t0[128]) right out of your Int() call, as a multiplicative constant? If so, then would there just be one numeric integral to be computed, which doesn't depend upon `depth`? Or have I read it wrongly?

acer

What form of printing is wanted? As a string, or line-printing, or...?

What printing mechanisms are allowed, if not explicit calls to the `print` command?

Perhaps one of these is closer to what you're after.

p:=proc () convert(eval('procname'),string) end proc:
p();

p:=proc () printf("%s",convert(eval('procname'),string)) end proc:
p();

p:=proc () iolib(9,':-default',"%s",convert(eval('procname'),string)); iolib(23,':-default') end proc:
p();

Those can also be anonymous, in recent Maple versions where `thisproc` is available, as follows,

proc () convert(eval('thisproc'),string) end proc:
%();

and so on.

Is this for 2D Math, or is it for 1D Maple notation input?

acer

@GPekov I find it quite difficult to give anything but vague and general advice if you don't post code or describe the code in much more detail. Sorry.

You haven't said whether you used Maple 16, or an older version. In some cases the new garbage collector of Maple 16 can do much better than the older "mark and sweep" collector of previous versions.

If you see some speedup for your code when you increase gcfreq then it may mean that your code speeds up a bit by virtue of the collector running less often (as the expense of more allocation, probably). But it doesn't follow from that that the collector is wasting its time walking structures unnecessarily (and which you seem to want to avoid forcibly). It might instead be that the collector is actually usefully collecting things, and keeping memory allocation down (which in turn might be helping keep your code faster than it might otherwise be). Or not. Hard to tell, code unseen.

What is inside this large Array (of Arrays?). Do the inner Arrays have hardware datatype? If not, and if their contents are numeric, then why not? Are there very many Arrays inside the outer Array? Could you use just a large flat Array instead of all of them (with code revised, but that's just bookkeeping) and give it a hardware datatype. Are you using lists somewhere, of Arrays of integers that are not datatype=integer[4], instead of hardware datatype Arrays? Lots of possibilities, with code unseen, sorry.

You might have a look at Maple's profiling tools, here, here, or here.

It sounds like you are on the right track for efficiency, judging by your other thread and Axel's sound advice: hardware datatypes, inplace operation on Array arguments for both input and output of Compilable procedures, etc. If you can keep garbage production (by the code) down, with zero being the goal, then the collector will almost never run and likely you can avoid it as a bottleneck.

One small thing, if your are coming from a compiled C/Fortran/other environment: Maple procedure calls are relatively quite a bit more expensive, so it can sometimes help to refactor code which just happens to be written to perform many function calls.

I don't see the justification for your last step, where you make the outer Sum have its index be just "q" (as opposed to "q-s" say). (I guess I must be missing something?)

> F := Sum(f(h)*exp(i*h*x),h=-infinity..infinity):

> G := Sum(g(s)*exp(i*s*x),s=-infinity..infinity):

> simplify(combine(combine(F*G)));                

             infinity    /  infinity                              \
               -----     |    -----                               |
                \        |     \                                  |
                 )       |      )       f(h) g(s) exp(i x (h + s))|
                /        |     /                                  |
               -----     |    -----                               |
           h = -infinity \s = -infinity   
                        /

> student[changevar](h=q-s,%,q);

              infinity    /  infinity                            \
                -----     |    -----                             |
                 \        |     \                                |
                  )       |      )       f(q - s) g(s) exp(i x q)|
                 /        |     /                                |
                -----     |    -----                             |
            q = -infinity \s = -infinity                         /

acer

with(Logic):

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

Tautology( T );

                              true

acer

The select command picks off operands of the expression which satisfy the predicate. And what one might imagine to be "some terms" may not be the same as the operands of the expression.

op(y+3*x(t));
                           y, 3 x(t)

select(has, y+3*x(t), x);
                             3 x(t)

op(3*x(t));
                            3, x(t)

select(has, 3*x(t), x);
                              x(t)

op(x(t));
                               t

select(has, x(t), x);
                              x()

You might have intended "some terms" to mean terms in a sum, but neither a product nor a function call is a sum of terms.

Sometimes people will write a procedure which handles expressions by case. Ie, whether it is of type `+`, or type `*`, or neither. Or just to handle type `+` or not, according to need. The predicate gets mapped across a sum, but is applied directly otherwise. For example, as a simple operator,

H:=(e,x)->`if`(type(e,`+`),select(has,e,x),`if`(has(e,x),e,NULL)):

H( y+3*x(t), x );
                             3 x(t)

H( 3*x(t), x );
                             3 x(t)

H( x(t), x );
                              x(t)

H( x(t), y ); # returns NULL

nb. You may or may not want to distinguish between `has` and `depends`.

acer

Maple will use less memory (often, for the kind of operations you describe) if the Matrices,Vectors, or Arrays have a "hardware" datatype. That means that the datatype=value option is float[8] or integer[4], etc.

There is more support for datatype=float[8], which matches the double precision type for floating-point data that would be used by Matlab or `double` in the C language, etc. That support is accessible using most commands from LinearAlgebra, arithmetic operations such as `+`, `.`, etc, as well as elementwise operations such as (several commands prefixed by) `~` or `zip`.

3000x1000 is not very large, if programmed as above. For datatype=float[8] that is only about 24 MB of memory.

restart:

m:=CodeTools:-Usage( LinearAlgebra:-RandomMatrix(3000,1000,
                               outputoptions=[datatype=float[8]]) );

memory used=22.96MiB, alloc change=23.00MiB, cpu time=93.00ms, real time=97.00ms
                             [ 3000 x 1000 Matrix   ]
                             [ Data Type: float[8]  ]
                        m := [ Storage: rectangular ]
                             [ Order: Fortran_order ]

CodeTools:-Usage( m + m ):
memory used=22.89MiB, alloc change=23.00MiB, cpu time=16.00ms, real time=15.00ms

From your brief description I would imagine that yout task would involve a lot of floating-point computations, and that the float[8] datatype would be adequate for most (if not all) of the Arrays.

acer

I'm not sure what precisely you might mean by, "...the parameters in a record do get updated..."?

> restart:
> r:=Record(p1=parm1,p2=parm2):
> parm2:=0:
> r:-p2;
                                       0

> eval(r:-p2,1);
                                     parm2

> n:=eval(r):
> eval(n:-p2,1);
                                     parm2

> s:=copy(r):
> eval(s:-p2,1);
                                     parm2

> s:=copy(eval(r)):
> eval(s:-p2,1);   
                                     parm2

> f:=proc(t) t:-p2, eval(t:-p2,2), eval(t:-p2,1), eval(t); end proc:
> f(r);                                                             
                  0, 0, parm2, Record(p1 = parm1, p2 = parm2)

The printing of a Record might not be showing the value of `parm2` that you do get upon programmatic access of the value of export `p2`, but that's just a detail of the printing mechanism. In contrast, the `print/rtable` routine is what makes the assigned value of `z` appear visibly in the displayed output below.

> restart:
> m:=Matrix([[a]]):
> a:=z:
> m;
                                      [z]

> eval(m[1,1],1);
                                       a

acer

The first link might allow you an easier way to vary the coloring, if you are trying to match or get close to that image, by use of a graphical application where coloring is controlled by sliders.

http://www.mapleprimes.com/posts/134419-Faster-Fractals

 

http://www.maplesoft.com/applications/view.aspx?SID=32594

 

http://www.maplesoft.com/applications/view.aspx?SID=6853

 

If you just need something simple, to get started, you could modify the last example (Julia set) of the help-page of the densityplot command. You would need to understand the difference in the formula, of course.

acer

Maple has pretty good coverage. One area where it stands out is Ordinarty Differential Equations (ODEs), at which it is strong in both the exact symbolic and also the numerical solving areas.

acer

Can you not simply solve for omega_1 once, up front, and then create R a simple, explicit expression in `a`, and then plot in the usual way?

omega:=solve(eval((10000*Pr^2*(Pr^2*(Pr-1)*(1+a^2/Pi^2)^2
                  +10*Pr^2*(Pr+Pr[m])+Pr[m]^2*omega_1*(Pr-1))
                  /((1+a^2/Pi^2)*(omega_1*(1+a^2/Pi^2)^2*(Pr+Pr*Pr[m])^2
                  +(Pr^2*(1+a^2/Pi^2)^2-Pr[m]*omega_1+10*Pr^2)^2))
                  +10*Pr^2*(Pr-Pr[m])/(Pr[m]^2*omega_1+Pr^2
                  *(1+a^2/Pi^2)^2)+(1+Pr)),[Pr[m]= 0]),omega_1):

R:=eval(((1+a^2/Pi^2)*Pi^2*((1+a^2/Pi^2)^2-omega/Pr+10*(omega*Pr*Pr[m]
        +Pr^2*(1+a^2/Pi^2)^2)/(Pr[m]^2*omega+Pr^2*(1+a^2/Pi^2)^2)
        +10000*Pr*((Pr^2*(1+a^2/Pi^2)^2-Pr[m]*omega+10*Pr^2)
        *(Pr*(1+a^2/Pi^2)^2-Pr[m]*omega)+omega*(1+a^2/Pi^2)^2
        *(Pr+Pr[m])*(Pr+Pr*Pr[m]))/((1+a^2/Pi^2)*(omega*(1+a^2/Pi^2)^2
        *(Pr+Pr*Pr[m])^2+(Pr^2*(1+a^2/Pi^2)^2-Pr[m]
        *omega+10*Pr^2)^2)))/a^2*Pi^4), [Pr[m] = 0]):

R:=eval(simplify(R,size),[Pr = 0.025]);

plot(R,a=4.56..7.56);

plot(R,a=4.56..7.56,adaptive=false,numpoints=10,style=point);

If you really want to built a list of lists, so as to call plots:-pointplot, then better to get in the habit of using `seq` to do it than by repeatedly augmenting a list (which is inefficient for large lists).

L:=[seq([A,evalf[15](eval(R,a=A))], A=4.56..7.56, 0.5)];

plots:-pointplot(L);

acer

Perhaps it is a grammatical slip, and that line in the help-page for last_name_eval was instead supposed to read, "...a name assigned a value that is one of the special types, such as procedures, modules and tables (hence, matrices, vectors and arrays, but not rtables), is not fully evaluated during normal evaluation." Would that make sense?

Since (now-deprecated) things such as matrix, vector, and array are all of type table then they too are of type `last_name_eval`. A list or a set is not of type `last_name_eval`, and neither are any of the rtable subtypes Matrix, Vector, or Array.

A Record (of type `record`) is a kind of module. And Records are thus of type `last_name_eval`, since modules are.

> r := Record( 'a', 'b' ):

> type(r,record);
                                     true

> type(r,`module`);
                                     true

> type(r,last_name_eval);
                                     true

> subtype(record,`module`);
                                     true

> subtype(record,last_name_eval);
                                     true

[edited] In conversation I've been informed that the issue of whether things of type object are also of type `last_name_eval` is messy. If I create Obj a named module with option `object` in Maple 16.01 then type(Obj, last_name_eval) returns true. But this might be a coding oversight in `type`, and it would be interesting to test whether it actually behaves that way under evaluation. (It may be a bug that the command subtype(object,`module`) returns FAIL in Maple 16, while the command type(Obj,`module`) returns true for Obj created as a named Object. I'm not at all sure, but this may be on purpose, as an implementation detail.)

It appears that `last_name_eval` is a super-type of `module`, `procedure`, and `table` (and hence also of all their subtypes). The exception to this rule is  `object`, as mentioned.

You also asked whether Matrices and Vectors (ie. rtables) evaluate fully. The mutable data structures are tricky. When the Help writes of "...under normal evaluation" it's often describing the situation of passing arguments to a procedure. When a mutable structure (table, rtable, but not list or set) is passed as an argument in a procedure call it is desirable to have it be passed as if "by reference". The rationale is that it's desirable to be able to act on its entries "in-place", and to avoid inefficient copying of data. So having the procedure get the name of the thing, rather than a copy of the thing, is desirable. The crazy-brilliant way that old (lowercase, deprecated) matrices, vectors, and arrays attained this was by being of type `last_name_eval`, so that only the assigned name got received by the procedure after normal up-front evaluation of the arguments. The way that Matrices, Vectors, and Arrays attain the same kind of behaviour is by (de facto) not evaluating fully under normal evaluation. That behaviour of rtables works pretty well, but there are some corner cases of usage which gave rise the rtable_eval command.

acer

If your expression is assigned to the name `e`, for example, then you should be able to pull out that a[0] term with the command,

'collect(e, a[0])'

acer

There are various ways to produce the sorting list [2,3,1] which you want to use to sort the rows of Matrix A. Once you have that list there are also several ways to construct the new sorted Matrix.

A := Matrix(3, 3, [1, 3, 4, 2, 3, 1, 2, 4, 1]);

                                    [1  3  4]
                                    [       ]
                               A := [2  3  1]
                                    [       ]
                                    [2  4  1]

B := Array([8, 6, 7]);

                               B := [8, 6, 7]

Bhat:=[seq(r[2], r in sort([seq([B[i],i],i=1..3)],(a,b)->b[1]>a[1]))];

                              Bhat := [2, 3, 1]

# one way
Anew:=Matrix([seq([A[r,1..-1]],r=Bhat)]);

                                      [2  3  1]
                                      [       ]
                              Anew := [2  4  1]
                                      [       ]
                                      [1  3  4]

# another way
Anew:=Matrix(3,3):
for i from 1 to 3 do
  Anew[i,1..-1]:=A[Bhat[i]];
end do:

Anew;

                                  [2  3  1]
                                  [       ]
                                  [2  4  1]
                                  [       ]
                                  [1  3  4]

I've made no effort to make the above especially efficient. It's likely that there are ways which are much faster if you have to do it many times, or do it for a much larger size Matrix.

acer

First 262 263 264 265 266 267 268 Last Page 264 of 336