Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Maple 10: collect and sqrt

38 views
Skip to first unread message

Jerome BENOIT

unread,
Apr 24, 2006, 10:34:28 PM4/24/06
to
Hello Group,

how can we collect square root within Maple 10 ?

I am asking because

collect(<some formula>,[sqrt])

seems not to work.

Thanks in advance,
Jerome
*** Posted via a free Usenet account from http://www.teranews.com ***

Carl Love

unread,
Apr 24, 2006, 11:36:03 PM4/24/06
to
Jerome BENOIT wrote:
> how can we collect square root within Maple 10 ?
> collect(<some formula>,[sqrt])
> seems not to work.

If all of the square roots that you want to collect have the same
argument, say x, then do
collect(e, sqrt(x))
where e is the expression to be collected.

Otherwise, the problem is that sqrt(x) evaluates to x^(1/2) and is
stored thus rather than being stored as an unevaluated function call to
sqrt. To get around this, we can encapsulate all subexpressions of the
form anything^(1/2) as some dummy function, collect with respect to
that function, then remove the function. Like this:

eval(collect(subsindets(e, anything^(1/2), ``), ``), ``= eval);

Jerome BENOIT

unread,
Apr 24, 2006, 11:55:41 PM4/24/06
to
Hello,

thanks for the reply.

Carl Love wrote:
> Jerome BENOIT wrote:
>
>>how can we collect square root within Maple 10 ?
>>collect(<some formula>,[sqrt])
>>seems not to work.
>
>
> If all of the square roots that you want to collect have the same
> argument, say x, then do
> collect(e, sqrt(x))
> where e is the expression to be collected.

as a matter of fact my `x' is large.

>
> Otherwise, the problem is that sqrt(x) evaluates to x^(1/2) and is
> stored thus rather than being stored as an unevaluated function call to
> sqrt. To get around this, we can encapsulate all subexpressions of the
> form anything^(1/2) as some dummy function, collect with respect to
> that function, then remove the function. Like this:
>
> eval(collect(subsindets(e, anything^(1/2), ``), ``), ``= eval);
>

I am doing this, but I though this was rather an ad hoc solution:
this story sound odd to me, as I expected something less heavy.

Carl Love

unread,
Apr 25, 2006, 1:07:12 AM4/25/06
to
Jerome BENOIT wrote:

> Carl Love wrote:
> > eval(collect(subsindets(e, anything^(1/2), ``), ``), ``= eval);
>
> I am doing this, but I though this was rather an ad hoc solution:
> this story sound odd to me, as I expected something less heavy.

Okay, here's a less heavy solution:

collect(e, indets(e, sqrt(anything)));

Jerome BENOIT

unread,
Apr 25, 2006, 1:25:19 AM4/25/06
to
Thanks,
Jerome

Roman

unread,
Apr 25, 2006, 6:35:30 PM4/25/06
to
collect(e, indets(e, sqrt(anything)));

This solution doesn´t work !

Carl Love

unread,
Apr 25, 2006, 11:22:27 PM4/25/06
to
Roman wrote:
> collect(e, indets(e, sqrt(anything)));

Please give an example on which it does not work, and the version of
Maple that you used, so that I can correct it. Using Maple 10, I get

> restart;
> e:= a*sqrt(x)+b*sqrt(y)+c*sqrt(y)+d*sqrt(x)+5;

e := a*x^(1/2)+b*y^(1/2)+c*y^(1/2)+d*x^(1/2)+5

> collect(e, indets(e, sqrt(anything)));

(d+a)*x^(1/2)+5+(b+c)*y^(1/2)

Roman

unread,
Apr 26, 2006, 9:57:08 AM4/26/06
to
e:=sqrt(x^3)+a*sqrt(x^3)+b*sqrt(x^3);

3 1/2 3 1/2 3 1/2
e := (x ) + a (x ) + b (x )

I think, I unstand what you ment.
Your solution is perfekt, but I thought it would work for the following
problem as well.
No exists a simpler solution?

> eval(collect(subsindets(e, anything^(1/2), ``), ``), ``= eval);
>

3 1/2
(1 + a + b) (x )

> collect(e, indets(e, sqrt(anything)));
>
Error, (in collect) cannot collect (x^3)^(1/2)
Roman

Jerome BENOIT

unread,
Apr 26, 2006, 10:40:00 AM4/26/06
to
Hello,

a few minutes ago I tried

collect(e,indets(e,sqrt(anything)));

where e contains a sqrt of polynomial,
and I got the reported error message.

As a matter of fact, I used to do
convert(e,sqrt) with a former version of Maple:
unfortunately I cannot tell since which version
I have got troubles.

Jerome

C W

unread,
Apr 27, 2006, 10:51:49 AM4/27/06
to

Use this instead :
collectt:=proc(e,t)
frontend(collect,[e,select(type,frontend(indets,[e]),t)],[{`+`,`*`,set},{}])
end;
collectt(e,radical);


Chris

C W

unread,
Apr 27, 2006, 12:02:12 PM4/27/06
to
Another code :

collectt:=proc(e,t)
local T;
frontend(proc(e,T) collect(e,[op(T)],distributed);
end,[e,select(type,T(op(frontend(indets,[e]))),t)],[{`+`,`*`},{T}]);
end;
e :=
a*x^(1/2)+b*y^(1/2)+c*y^(1/2)+d*x^(1/2)+5+a*2^(1/2)+b*2^(1/2)+((1+x^(1/2)+Pi^(1/3))^(1/2)+1)^6;
E:=(map2)(proc(e,t) [collectt(e,t),t]; end
,expand(e),[radical,Non({Non(radfunext),Non(radnumext)}),Non({radnumext,Non(radfunext)})]);
map2(nops@op,1,E);


Chris

Carl Love

unread,
Apr 27, 2006, 1:15:11 PM4/27/06
to
Jerome BENOIT wrote:
> collect(e,indets(e,sqrt(anything)));
> where e contains a sqrt of polynomial,
> and I got the reported error message.

My original intuition that the sqrt's needed to be encapsulated with a
dummy function was correct, as in my first solution:

eval(collect(subsindets(e, sqrt(anything), ``), ``), ``= eval)

We see in procedure `collect/filter` that the subexpression with
respect to which the collection is done must be of type
{function^rational, name^rational, function, name}.
A sqrt of a polynomial is not any of these types.

> As a matter of fact, I used to do
> convert(e,sqrt) with a former version of Maple:
> unfortunately I cannot tell since which version
> I have got troubles.

sqrt's may have been stored as unevaluated function calls in earlier
Maple.

0 new messages