1434 Reputation

19 Badges

14 years, 354 days

Social Networks and Content at

Maple Application Center
I am the manager of the Mathematical Software Group, working mostly on the Maple library. I have been working at Maplesoft since 2007, mostly on the Statistics and Units packages and on contract work with industry users. My background is in abstract algebra, in which I completed a PhD at Eindhoven University of Technology. During my studies I was always searching for interesting questions at the crossroads of math and computer science. When I came to Canada in 2007, I had nothing but a work permit, some contacts at Maplesoft (whom I had met at a computer algebra conference a year earlier), and a plan to travel around beautiful Canada for a few months. Since Maplesoft is a company that solves more interesting math and computer science related questions than just about anywhere else, I was quite eager to join them, and after about three months, I could start.

MaplePrimes Activity

These are replies submitted by epostma

This is unfortunately not something we can support, because of the way that operator overloading works.

Here's what happens in detail. First of all, Maple's parser parses B - A as B + (-A). Then the Units:-Simple package's minus operator is evaluated on the result of evaluating A, that is, 1, 2, 3. Here we run into the first problem: we can't distinguish this call from a user calling `-`(1, 2, 3): we get the same argument sequence, there is no difference between the two. For the top level minus operator, this last call would be interpreted as 1 - 2 - 3, which evaluates to -4. So Units:-Simple's minus operator returns the same.

Now the plus operator gets called, with as its arguments the results of evaluating B and the earlier result that came out of the minus operator. B evaluates to 4, 5, 6, and the minus operator evaluated to -4. It is the nature of expression sequences in Maple that they automatically concatenate into a single, flat, expression sequence, so the kernel now passes this as the argument sequence 4, 5, 6, -4 to the plus operator. Again, we cannot distinguish this from a user calling `+`(4, 5, 6, -4). As the top level plus operator would return 4 + 5 + 6 + (-4) = 11 from that, so does the Units:-Simple package's plus operator.

Generally, arithmetic with expression sequences in Maple is extremely fragile. It is impossible for any overloaded package to replicate the top level operators exactly, and I don't believe there are documented rules for how the top level operators interpret expression sequences. Moreover, replacing the operator form with the functional form (that is, replacing something like A + B with something like `+`(A, B)) must also fail, because the expression sequence A, B immediately loses the information of where the split between the two was. This is the same issue we saw above: packages can really only provide the functional form of these operators.

I would strongly recommend against using expression sequences for arithmetic. Using lists or Vectors is much more reliable.

Erik Postma (he/him)
Manager, mathematical software group

One thing I immediately noticed about the second listing is that, while correct, it is unnecessarily inefficient because it grows the list of primes one element at a time. That is quadratic in memory and time in Maple, because every new version of the list needs to be created from scratch. Instead it's better to use rtables (Arrays or Vectors) which can grow in-place. You can append with ArrayTools:-Append or the ",=" operator.

I wonder what ChatGPT would say to that...

@Carl Love @Angelo Melino  Thank you for finding this! I just submitted a fix for the main development version of Maple; it should make it into the next major version (which might be released next spring).

Erik Postma
Manager, mathematical software group

@Anthrazit The 'eval' should be done when reading from the data table; when you write it, the unit expressions will hopefully be valid -- otherwise you would get errors at that point, anyway, whenever you do anything with them -- so then the eval is not necessary.

@vv Thank you for this request for high performance, high precision evaluation of the Zeta function. That'll help us prioritize where we focus our efforts. If we hear this from more people, that would be a strong indicator to help redirect effort to this project.

Erik Postma
Manager, mathematical software group.

@Axel Vogt - one doesn't, in this case. It was me who suggested this to the support team, and I thought the `in` operator was defined in the PolynomialIdeals[Operator] subpackage, but it's actually in the PolynomialIdeals package itself.

Yes, that works for the Bootstrap command, thanks for pointing that out!

The focus of the user's question was on generating samples, so I answered that question initially. I believe they wanted to roll their own bootstrap-like mechanism. For just generating (large) samples, EmpiricalDistribution works well enough, and efficiently.

I figured I could show that you can use Maple's Bootstrap command, too, and because I had already constructed the EmpiricalDistribution object, that's where my mind went, and I didn't think about the fact that Bootstrap accepts the plain data sample, too.

By the way -- I think we can probably speed Bootstrap up a lot by having it sample into a larger buffer. It currently just uses the sample size for the buffer, so it fills a size-4 buffer 10000 times. It would be much more efficient to fill a size-10000 buffer 4 times, and then slice it into 2500 samples with ArrayTools:-Alias. I expect you would get performance very close to the calling sequence  you show in that case.

Thanks Robert, I enjoyed reading this account.

Two notes, one mathematical and one Maple-related. First the mathematical one: I think you would expect 3 degrees of freedom, right? There are 10 equations, but there is a dependency between them: all four row-sums must needs sum to the same as all four column-sums. So there are really only 9 independent equations.

The Maple point is that the combinatorial question you raise is solved by the Iterator package, in particular the BoundedComposition command. You supply it with a k-tuple of bounds (b1, ..., bk), and a sum s, all nonnegative integers. It then finds all k-tuples (a1, ..., ak) of nonnegative integers with ai <= bi that sum to s. This raises one problem: we want integers from 1-9, and  BoundedComposition will also give us zeroes -- but that's easily dealt with: we just use integers from 0-8 instead, adjust the requested sum (by subtracting k=4), and presto. For example:

k := 4;
B := BoundedComposition([8 $ k], 25-k):
Number(B); # result: 324
Print(B, 'showrank');

tells us that there are 324 such tuples with sum 25, and will print all of them. To do a computation with them, you would use:

for b in BoundedComposition([8 $ k], 25 - k) do
  tup := b +~ 1;
  # Now use the tuple, tup, which will contain suitable integers 1-9. (It's an Array.)
end do;

Of course, if one number is given already, you could generate 3-tuples.

@C_R If this is what you want, the best option is probably to use convert/system to convert every unit to one consistent system, and then use Carl's solution below:

expr := sin(t * Unit(1/min)) * Unit(mm);
to_SI := evalindets(expr, specfunc(Units:-Unit), e -> convert(e, 'system', 'SI'));
result := eval(to_SI, Units:-Unit = 1);
# result is now sin(t/60) / 1000

@C_R For what it's worth, here is another teaser screenshot...

Hi everyone,

I think Tom and Carl have already answered the actual question, so I won't add an answer... but I will add a little teaser image of what the current in-development version of Maple looks like when applied to this worksheet:

If everything goes as expected, you can expect this to work without any tinkering being necessary, in the next major release of Maple.

@mike7944 You're welcome!

Hi Mike,

I should have mentioned explicitly - this was written to work in Maple 2021. Over the last couple of years we've made some additions to the Maple syntax. One of them is allowing full if statements (including arbitrary substatements) inside expressions; it looks like that's what you're running into. If you need to use this code in an older version, you can replace this fragment:

 local result := add(nonconst) + (
    if is(const = 0) then
      const := evalf(const);
      if type(const, ':-float') then
        frem(const, 2.*Pi);
        frem(Re(const), 2.*Pi) + I*Im(const);
      end if;
    end if);

with the following:

 local result := add(nonconst);
    if is(const <> 0) then
      const := evalf(const);
      if type(const, ':-float') then
        result := result + frem(const, 2.*Pi);
        result := result + frem(Re(const), 2.*Pi) + I*Im(const);
      end if;
    end if;

You may also need to move all local declarations to the top of the procedure and module; for example, the module would start with a line saying local ModuleApply, process_trig; and the word local would be removed from the lines assigning to ModuleApply and process_trig.

Please let me know if you're still having trouble -- I don't have Maple 2017 handy so I can't easily check right now, but I'll dig it out if needed.

@Carl Love Yeah, the change should be in 2020.0 and later.


@vs140580 Another option would be to use the command Iterator:-CartesianProduct. If you want to deal with the results one by one, you can use it like this:

m := 4; # or more
S := {0, 1, 2}; # or something else
for v in Iterator:-CartesianProduct(S $ m) do
  print(v); # v will be an Array with one result
end do;

Note that the Array in v will be reused between iterations; only its contents will change.

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