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 ***
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);
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.
Okay, here's a less heavy solution:
collect(e, indets(e, sqrt(anything)));
This solution doesn´t work !
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)
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
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
Use this instead :
collectt:=proc(e,t)
frontend(collect,[e,select(type,frontend(indets,[e]),t)],[{`+`,`*`,set},{}])
end;
collectt(e,radical);
Chris
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
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.