Mac Dude

1521 Reputation

17 Badges

10 years, 293 days

MaplePrimes Activity

These are answers submitted by Mac Dude

Your examples can be done with map:

T := [[1, 2], [3, 4]];
                        [{1, 2}, {3, 4}]
                        {{1, 2}, {3, 4}}

This also works for your situation with choose(). If your nesting is deeper you may need more levels.


There is no generally valid answer to your question (other than:. You need to analyse your applications and where the bottlenecks are.

  • Are you running primarily multithreaded or singe-threaded tasks? If single-threaded, then the raw power of each core will dominate your results, else having more cores will help.
  • Are you memory starved? Occasionally Maple processes can become memory hogs gobbling up significant amounts of memory. If the machine starts swapping it will slow down by a lot.
  • Do you know where your cycles go? Maple has facilities to profile usage of routines that can help identifying routines the system spends most of its time in.
  • Are you producing a lot of output into the worksheet? While the worksheet runs in a separate process, the necessary synchronization does slow things down.
  • And many more…

If you really want to soecifically speed up certain worksheets, profile them. If you have an itch to buy a new computer I'd suggest get the fastest single-core performance you reasonably can. Check the memory use on your machine and note that on macOS the actual use tends to be twice what Maple reports at the bottom of the worksheet.

Don't expect miracles from new hardware. If you look for a large factor speed-up, you will need to revisit the algorithm you use and its implementation.


In your sheet IntPlaneX and IntPlaneZ are really the same planes, just expressed differently.

In your proc p, the test asks if a point is below or above this plane and changes the return value accordingly.

The plot shows the result. If you look at it along the plane you see that the red figure above and below is different, so it is not just a simple sphere.

What did you expect?


It appears your Mma program does not use Mma packages and has a relatively simple structure, which at least opens up a chance to translate it with acceptable effort. I once translated an Mma program, but I used an editor to change some of the more routine things (like [] to () for functions, and I think the ";" in Mma suppresses output) before manually converting the rest.

Maple has the MmaTranslator package that may be helpful. However, don't expect to run the whole thing through it, it won't do you any good. Doing it statement-by-statement may have a chance to at least speed up the conversion. I have no experience with MmaTranslator, however.

Ultimately it depends how badly you want it.

It will be very helpful if you have access to Mma so you can check correctness of your conversion.


@lcz For me, collect and simplify,size come close:

                     (n + 6 - 2 b) k + 2 a
                     (n + 6 - 2 b) k + 2 a

Your specific desired form seems difficult to get without fairly cumbersome casting of operations to specific parts of the expression, with no generality under any changes of the expression.


Try kernelopts(opaquemodules=false);


While I don't consider Maple a true OO language, I often use the following construct which at least mimics the method overloading you are looking for:

# define the module ("class") 
   export data1,move,dog;

     print("In Animal class. moving ....");
   end proc; 


     return module()

       export move:=proc(_self,$)
         print("In dog class. moving ....");
       end proc;  

    end module;

  end proc;
end module;
# Use the module
A:=Animal;# Can only have one class!
Buster:=A:-dog():# this instantiates dog, can have multiples of this.
                  "In dog class. moving ...."
                 "In Animal class. moving ...."

This is actually quite powerful & I use it in many packages. You can have a whole hierarchy of subclasses . Procedure dog is an example of a "Module Factory" and comes straight out of the Programming  Guide. Note that this programming model has been available since Maple 15 (much older than 2015 where the "object" option was introduced).

I hope this helps,


@janhardo So what is it you are actually asking for? Is it how to program a procedure in Maple, or is it how to program the Sieve?

There is a number of articles on the web on how to program the Sieve in Maple. A random one is (which provides a Maple worksheet).

If you are really after learning how to write procedures in Maple, there is no better resource than the Programming Guide. Sections 1.4 and 6 are relevant here. I do not understand your assertion that questions have no answers, maybe because I do not know your questions.

Study these materials and post here specific questions when you get stuck.


It is not clear what your expression sequence is supposed to achieve, but interval arithmetic is done with evalr and INTERVAL:



Note that the x from the second element of the sequence does not get substituted in the first element; you have to do that using substitute. (I just put it into the cosine to demonstrate what Maple does in his case.) Look up evalr() and subs() in the Help pages.


Edit: Now reading your next question it looks like you may want a sequence of values. That can be achieved using the seq() function:


which gives a cosine table with 200 entries.

It has to do with the fractional exponent. The last sentence in help/series reads like this:

Usually, the result of the series function is represented in the form of a series data structure. For an explanation of the data structure, see the type/series help page. However, the result of the series function will be represented in ordinary sum-of-products form, rather than in a series data structure if it is a generalized series requiring fractional exponents.

So it seems to work as designed.



PS: In my experience, convert will accept pretty much anything & try to convert to the desired form.

Well, you may be able to convince your teacher with an explicit solution, and yourself that such a situation is perfectly normal:

You have two values for an integral of an unknown function f(x), namely from 1 to 4 and from 1 to 6. If you give f(x) two parameters (call them a and b) and can find the integral for the two intervals given, then you can determine f(x) and hence do the integral from 4 to 6. The trick is to find a simple enough function f(x) so this can actually be done. The simplest case I can come up with is a straight line: f(x)=a*x+b.

Then the calculation goes like this:

f:=(x) -> a*x+b;
x -> a x + b
                    1   / 2    \            
                    - a \X  - 1/ + b (X - 1)
                      [[    -23      37]]
                      [[a = ---, b = --]]
                      [[    15       6 ]]
                            23     37
                          - -- x + --
                            15     6 

confirming your assertion. The plot looks like this:

I hasten to add that f(x) is not uniquely defined by the integral values; there will be infinitely many different ones with the same integrals. But since the integrals are additive (rule # 4 in your book), the result is in fact general and not dependent on the details of f(x).

I hope this helps,


You really don't give enough details, but what about the following:

You can get the set of parameters using indets(array,'name'). If you have other indeterminates besides your parameters then they will show up, too, so you may have to filter the list. You get the number of parameters from numelems(indets(array,'name')) or using the filtered list.

Presumably you have a list of values you want to assign to the parameters. You can do this using eval(array,[seq(indets(array)[ii]=values[ii],ii=1..numelems(indets(array,'name')))]). Somehow you have to know the list of your values, obviously, and it is not clear to me how you do that when you do not know the number of parameters, but that seems to be a separate problem.

Here is a code snippet:

                       Array(1 .. 3, {1 = f(x1), 2 = f(x2), 3 = f(x3)})
X:=indets(A,'name'); # these are your parameters
                          {x1, x2, x3}
                           [1, 2, 3]
                         Array(1 .. 3, {1 = f(1), 2 = f(2), 3 = f(3)})

This will scale to any length of A and X.

Let us know if this addresses your problem or is off the mark.


If it is a specific Maple command that takes a longtime: not easily. You can observe the memory and time indicators in the bottom status line of the window: if memory usage goes up and up you likely have expression swell (or a memory leak) that causes things to slow to a crawl or hang; if the time stops updating, the kernel (or the interface process) may be hung.

If it is a loop, you can put a print statement to follow through the iterations. For a nicer way, put something like a gauge into your sheet & update it each iteration. I do this for calculations I know take a long time.

If you can, start with a simpler case that works (e.g. smaller matrices) & add complexity or whatever slows things down (e.g. size of Matrices). As a general rule, if you observe growth in calculation time with the size of your problem much faster than linear or quadratic you are in trouble with larger problem size.

Beyond these generalities you need to shows us a worksheet that exhibits the prroblem you are trying to address.


Attached is an example of mine called Filters. The library is a module that contains all the functions you want in there.

You then need to save it where Maple can find it. As you can see, I pre-pended (in my maple.init file) my library directory to the others in libname; Maple will look in my own directory first before looking in its general directory (thus I can overlay my own definitions if I so chose). then you use LibraryTools:-Save to put the .mla file in there.

After that, with(Filters) (in my case) will find it.

I do agree with SGJanssens suggestion, but this example may get you going faster.


I think the closest to structs are records. They are related to modules but are more geared towards data structures, although you can store procedures as well. You can access members of a record using :- notation.


Struct := Record(c=2*Pi*rho,a=Pi*rho^2);

     2 π rho
    π rho^2

Members can be Vectors, Arrays, you name it.

As for speed, Maple can be ok if you spend time programming it right. Naive implementation can lead to constant reallocation of memory, which gets costly. I am no expert on this although I have certainly run into unexpected super-linear growth of execution time with the number of cases. Declaring datatype=float (as opposed to "anything") in Vectors can help.

Look up the Maple Programming guide; a treasure trove of good practices.

I hope this helps,

Mac Dude

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