Re: Simplfying inside Sqrt
- To: mathgroup at smc.vnet.net
- Subject: [mg55115] Re: [mg55106] Simplfying inside Sqrt
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 13 Mar 2005 04:57:34 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On 12 Mar 2005, at 08:36, billkavanagh at gmail.com wrote: > Hi > > I'm wondering how to tell mathematica that I want terms like > Sqrt[x^2+x^4] to be x*Sqrt[1+x^2]. I have an expression with a few > terms like this in it so manually inserting a > PowerExpand[Sqrt[Expand[x^2+x^4]] is no good to me. > > I've tried a general PowerExpand and Simplify with a Im[x]==0 around > the whole expression but with no luck. > > Does anybody know how to do this? > > Thanks, > Bill > > -- > William R. Kavanagh > http://www.physics.mun.ca/~wkavanag > > > Your problem is that by most commonly used measures of complexity you are trying to replace a simper expressions by a more complex one. For example, the expression you want has the same LeafCount as the one you get but a higher Depth. So you need a carefully designed complexity function, that will treat such factored forms as simpler than unfactored ones but will not, as a side effect, produce "simplifications" (actually "complexifications") that you do not want. One possibility is to define a complexity function that penalises the presence of high powers, for example: f[expr_] := With[{a = Cases[expr, Power[_, n_?NumericQ] -> Abs[n], Infinity]}, If[a == {}, 0, Max[a]]] + LeafCount[expr] I added LeafCount because we also want to keep this to minimum. With this complexity function we get the desired simplification: Simplify[Sqrt[x^2 + x^4], x >= 0, ComplexityFunction -> f] x*Sqrt[x^2 + 1] and also Simplify[Sqrt[x^(-2) + x^(-4)], x >= 0, ComplexityFunction -> f] Sqrt[x^2 + 1]/x^2 Of course you need the assumption that x>0! Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/andrzej/index.html http://www.mimuw.edu.pl/~akoz/