Joe Riel

9660 Reputation

23 Badges

20 years, 3 days

MaplePrimes Activity


These are replies submitted by Joe Riel

I'm not sure why your example fails. Consider the following:
subsindets((a+b)*(c+d),Not(integer),Q);
                       Q(Q(Q(a) + Q(b)) Q(Q(c) + Q(d)))
subs(Q=1,%);
                       1(1(1(a) + 1(b)) 1(1(c) + 1(d)))
eval(%);
                                       1
I'll have to look at subsindets a bit closer.
Your icoeff4 looks like the way to go. I was afraid that something like that might occur with subsindets (more precisely, the Not(integer)), but couldn't come up with a failing case. Thanks for finding that. I'm calling it a night...
Your icoeff4 looks like the way to go. I was afraid that something like that might occur with subsindets (more precisely, the Not(integer)), but couldn't come up with a failing case. Thanks for finding that. I'm calling it a night...
I had already done that, but out of necessity because I already had an icoeff4.
I had already done that, but out of necessity because I already had an icoeff4.
On review, the flat option fails (as does the "inline" version). This because
indets(4*a,Not(integer));
         {a, 4*a}
so 4*a gets replaced by 1.
On review, the flat option fails (as does the "inline" version). This because
indets(4*a,Not(integer));
         {a, 4*a}
so 4*a gets replaced by 1.
It nicely handles complex values and is certainly easier to understand, if less compact.
It nicely handles complex values and is certainly easier to understand, if less compact.
Thanks for the reminder. Someday maybe that will make it into the help page 8-). Of course, for a bit more speed I could just inline subsindets[flat]:
icoeff5 := t-> `if`(t::{integer,`*`},subs(map(x->x=1, indets(t,Not(integer))),t),1);
That is about twice as fast as using the call to subsindets[flat], which is twice as fast as not using the flat option, which is a couple orders of magnitude faster than using patmatch. If the arguments were mainly integers it would be slightly faster to handle them separately, but at this point speed is not an issue.
Thanks for the reminder. Someday maybe that will make it into the help page 8-). Of course, for a bit more speed I could just inline subsindets[flat]:
icoeff5 := t-> `if`(t::{integer,`*`},subs(map(x->x=1, indets(t,Not(integer))),t),1);
That is about twice as fast as using the call to subsindets[flat], which is twice as fast as not using the flat option, which is a couple orders of magnitude faster than using patmatch. If the arguments were mainly integers it would be slightly faster to handle them separately, but at this point speed is not an issue.
How about,
icoeff3 := t-> `if`(t::{integer,`*`},subsindets(t,Not(integer),1),1);
That it fails (safely) with 3*I (as do the other approaches) isn't a concern in the particular application. By safely, I mean that returning 1 is always acceptable (though not ideal). I'm looking for a common integer factor among various terms; failing to find one is not critical, finding one that doesn't exist is.
How about,
icoeff3 := t-> `if`(t::{integer,`*`},subsindets(t,Not(integer),1),1);
That it fails (safely) with 3*I (as do the other approaches) isn't a concern in the particular application. By safely, I mean that returning 1 is always acceptable (though not ideal). I'm looking for a common integer factor among various terms; failing to find one is not critical, finding one that doesn't exist is.
Using subsindets is clever, thanks. To make it robust, I can do the following:
icoeff2 := t-> `if`(t::`*`,subsindets(t,Not(integer),1),1);
That eliminates the errors with sums. It's not immediately clear how subsindets does the job. To see it, do
subsindets(x^2,Not(integer),Q);
                       Q(Q(x)^2)
Because integers, when used as functions, return themselves, using 1 instead of Q returns 1.
Using subsindets is clever, thanks. To make it robust, I can do the following:
icoeff2 := t-> `if`(t::`*`,subsindets(t,Not(integer),1),1);
That eliminates the errors with sums. It's not immediately clear how subsindets does the job. To see it, do
subsindets(x^2,Not(integer),Q);
                       Q(Q(x)^2)
Because integers, when used as functions, return themselves, using 1 instead of Q returns 1.
First 187 188 189 190 191 192 193 Page 189 of 195