epostma

1579 Reputation

19 Badges

17 years, 49 days
Maplesoft

Social Networks and Content at Maplesoft.com

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

Whoops - fell for the old "if you paste an image into MaplePrimes, it becomes a link to your local filesystem" issue again. Should be fixed now.

@hirnyk : see the ?if help page.

@hirnyk : see the ?if help page.

@John May, @Robert Israel : interesting. I hadn't tested Robert's image yet, but I get the same result, and John's fix works for me too. Looks like I misunderstood the Sockets:-ReadBinary contract. At first I was confused - I thought that ?Sockets/ReadBinary would always block until it had read the specified number of bytes, or the socket was closed by the other party. But now that I read the ?Sockets/Peek documentation, I think I understand that at least some data gets read every time you call ReadBinary, if any is still coming, but not necessarily as much as you asked for. So John's fix should work for all cases.

@John May, @Robert Israel : interesting. I hadn't tested Robert's image yet, but I get the same result, and John's fix works for me too. Looks like I misunderstood the Sockets:-ReadBinary contract. At first I was confused - I thought that ?Sockets/ReadBinary would always block until it had read the specified number of bytes, or the socket was closed by the other party. But now that I read the ?Sockets/Peek documentation, I think I understand that at least some data gets read every time you call ReadBinary, if any is still coming, but not necessarily as much as you asked for. So John's fix should work for all cases.

@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.

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