epostma

1494 Reputation

19 Badges

17 years, 110 days
Maplesoft

Social Networks and Content at Maplesoft.com

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

@Christopher2222 : looks like extending rtables was not as powerful in Maple 12 as it is today. As a stopgap measure, you can insert the line

s(n + p) := 1;

just before the line

s(n + 1 .. n + p) := a[1 .. p];

That should extend s to the required size. I checked it in Maple 12 as well, now, and it worked for me.

Hope this helps,

Erik Postma
Maplesoft.

@Christopher2222 : looks like extending rtables was not as powerful in Maple 12 as it is today. As a stopgap measure, you can insert the line

s(n + p) := 1;

just before the line

s(n + 1 .. n + p) := a[1 .. p];

That should extend s to the required size. I checked it in Maple 12 as well, now, and it worked for me.

Hope this helps,

Erik Postma
Maplesoft.

@herclau : yes, that's the best you can do, I think. As before, you can have the factors multiplied together again by applying value.

@herclau : yes, that's the best you can do, I think. As before, you can have the factors multiplied together again by applying value.

@Joe Riel : I had essentially your Ds4.

DsErik := proc(V::set, n::posint, t)                                         
local i, v, A, B;
    return {seq(subs(A = v, 'D(A)(t)'), v in V),
            seq(seq(subs(A = v, B = i, '`@@`(D,B)(A)(t)'), i=2..n), v in V)};
end proc;

Still, your version is about twice as fast and memory efficient, for sufficiently large V. Good idea to get one subs out of the inner seq, and an interesting idea to 'cache' the f(t) DAG.

Erik.

I got about a factor of 10 in cpu time and 5 in memory use improvement (relative to your Ds on my machine), but I would say it's not a very inspired optimization. Ah, and length(eval(Ds)) has increased by less than a factor of 2, which might be considered a good thing. Maybe I should hold off on posting my version as well?

Erik Postma
Maplesoft.

(Edit: I posted it now - see below.)

@herclau : I think there's not really any way you can get it returned as a 'true factorization'. The closest you can come is by using `%*`. To be more explicit, you could use this:

myFactorization3 := proc(v :: rtable, $)
local divisor;
  divisor := foldr(lcm, op(remove(`=`, convert(v, list), 0)));
  return `%*`(divisor, v / divisor);
end proc;

Another option would be to use the regular multiplication, `*`, but leave it unevaluated. However, this will evaluate to the vector you started with as soon as you touch it (at the top level; in a procedure it can stay unevaluated) :

myFactorization4 := proc(v :: rtable, $)
local divisor;
  divisor := foldr(lcm, op(remove(`=`, convert(v, list), 0)));
  return '`*`'(divisor, v / divisor);
end proc;

Hope this helps,

Erik Postma
Maplesoft.

@herclau : I think there's not really any way you can get it returned as a 'true factorization'. The closest you can come is by using `%*`. To be more explicit, you could use this:

myFactorization3 := proc(v :: rtable, $)
local divisor;
  divisor := foldr(lcm, op(remove(`=`, convert(v, list), 0)));
  return `%*`(divisor, v / divisor);
end proc;

Another option would be to use the regular multiplication, `*`, but leave it unevaluated. However, this will evaluate to the vector you started with as soon as you touch it (at the top level; in a procedure it can stay unevaluated) :

myFactorization4 := proc(v :: rtable, $)
local divisor;
  divisor := foldr(lcm, op(remove(`=`, convert(v, list), 0)));
  return '`*`'(divisor, v / divisor);
end proc;

Hope this helps,

Erik Postma
Maplesoft.

@pepa : I'd recommend going with pchin's solution, which is more reliable.

Just for people reading my comment above and wondering what's going on, a quick explanation. I'll repeat that this is not necessarily a reliable way to interact with plots; the data structure may change in future versions. That said, it may offer something useful to someone wanting to operate on other Maple data structures; the same basic functions are useful elsewhere, of course.

The easiest way to deal with these sorts of things is reading it starting from the inside. The innermost thing that makes sense by itself is

select(type, [op(P)], specfunc(anything, POLYGONS));

which returns the ordered list of all POLYGONS plot structures in P (see ?type and ?type/structure and ?select). Another subexpression on the same level is

map(lhs, T);

which returns all the left hand sides for the equations in T (see ?map and ?lhs). There should be equally many of each. We apply ?zip to those two lists, and the function with which we zip them is custom: it's

(pol, legend) -> pol = op(0, pol)(op(pol), LEGEND(legend));

which takes a POLYGONS plot structure and a legend argument (one from the first list constructed above, one from the second list) and creates from it an equation, where the left hand side is pol (the POLYGONS plot structure) and the right hand side is the same plot structure but with an extra argument: LEGEND(legend).

The resulting list of equations is fed to ?subs, so that it substitutes the version with the extra argument for the original version of each POLYGONS data structure, and that's it.

I'll finish by repeating my recommendation that you use pchin's idea of adding a couple empty polygons with a legend, for the question you originally asked.

HTH,

Erik Postma
Maplesoft.

@pepa : I'd recommend going with pchin's solution, which is more reliable.

Just for people reading my comment above and wondering what's going on, a quick explanation. I'll repeat that this is not necessarily a reliable way to interact with plots; the data structure may change in future versions. That said, it may offer something useful to someone wanting to operate on other Maple data structures; the same basic functions are useful elsewhere, of course.

The easiest way to deal with these sorts of things is reading it starting from the inside. The innermost thing that makes sense by itself is

select(type, [op(P)], specfunc(anything, POLYGONS));

which returns the ordered list of all POLYGONS plot structures in P (see ?type and ?type/structure and ?select). Another subexpression on the same level is

map(lhs, T);

which returns all the left hand sides for the equations in T (see ?map and ?lhs). There should be equally many of each. We apply ?zip to those two lists, and the function with which we zip them is custom: it's

(pol, legend) -> pol = op(0, pol)(op(pol), LEGEND(legend));

which takes a POLYGONS plot structure and a legend argument (one from the first list constructed above, one from the second list) and creates from it an equation, where the left hand side is pol (the POLYGONS plot structure) and the right hand side is the same plot structure but with an extra argument: LEGEND(legend).

The resulting list of equations is fed to ?subs, so that it substitutes the version with the extra argument for the original version of each POLYGONS data structure, and that's it.

I'll finish by repeating my recommendation that you use pchin's idea of adding a couple empty polygons with a legend, for the question you originally asked.

HTH,

Erik Postma
Maplesoft.

This is what I would do:

with(Statistics):
X := RandomVariable(Normal(mu, sigma)):
ExpectedValue(1-exp(-phi*X));

which returns:

(exp(mu*phi)-exp(1/2*phi^2*sigma^2))*exp(-mu*phi)

Agreed on the issue with the calling sequence with the second argument, acer; I'll have a look.

Erik Postma
Maplesoft.

This is what I would do:

with(Statistics):
X := RandomVariable(Normal(mu, sigma)):
ExpectedValue(1-exp(-phi*X));

which returns:

(exp(mu*phi)-exp(1/2*phi^2*sigma^2))*exp(-mu*phi)

Agreed on the issue with the calling sequence with the second argument, acer; I'll have a look.

Erik Postma
Maplesoft.

@sund0002 : At this stage, it bites you that you have Arrays instead of Vectors. You'll get the right plot if you replace your definition of pp with:

pp := pointplot(convert(V, Vector), convert(C, Vector), symbolsize=5, color=green);

There are a few alternatives that might be more appropriate in some circumstances. If you would do this repeatedly with huge data sets, you'd want to use ?ArrayTools/Alias for efficiency. If you need to fit the code in as few keystrokes as possible you'd just use Vector(V) instead of the convert calling sequence. You could convert Data to a Matrix instead. But from what we've seen so far, the above command may well be fine for your situation.

Hope this helps,

Erik Postma
Maplesoft.

@sund0002 : At this stage, it bites you that you have Arrays instead of Vectors. You'll get the right plot if you replace your definition of pp with:

pp := pointplot(convert(V, Vector), convert(C, Vector), symbolsize=5, color=green);

There are a few alternatives that might be more appropriate in some circumstances. If you would do this repeatedly with huge data sets, you'd want to use ?ArrayTools/Alias for efficiency. If you need to fit the code in as few keystrokes as possible you'd just use Vector(V) instead of the convert calling sequence. You could convert Data to a Matrix instead. But from what we've seen so far, the above command may well be fine for your situation.

Hope this helps,

Erik Postma
Maplesoft.

@sund0002: I took a look at the worksheet that you posted. This is somewhat tricky business; it looks like Maple has decided that the first line that it is complaining about consists of two separate halves, and the split between the two occurs in between "pp" and ":=". So Maple sees a line starting with ":=". It might be best to insert a new execution group there (using for example the ">" button on the toolbar, or hitting Ctrl-J or Ctrl-K) and retype that line.

The more difficult and more interesting question is how that split line came about. Do you have any theories?
I don't know too much about how the GUI works, but here's something that might help. In general, I think if you're working with "Maple Input" (the 1-D, "text-only", "red Maple" style of input, as opposed to the 2-D typeset input), it works most reliably if you insert new execution groups in one of the ways I describe above (with the ">" button, Ctrl-J, or Ctrl-K), and set Tools -> Options -> Display -> Input display to Maple notation.

I believe the new execution groups come about sort of automatically if you open a new "Worksheet"; if you create a "Document", you have to do it in one of the ways described above.

Hope this helps,

Erik Postma
Maplesoft.

First 9 10 11 12 13 14 15 Last Page 11 of 21