MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: using rules for square roots

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110296] Re: using rules for square roots
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Sat, 12 Jun 2010 05:32:05 -0400 (EDT)
  • References: <hutb46$ltc$1@smc.vnet.net>

On 11/06/10 13:44, Kent Holing wrote:

>
> I still want to have feedback on my last question, i.e. how to return say expressions like e^5/2 as e^2 Sqrt[e]?
>
The fundamental problem is that some expressions undergo automatic 
simplification in the kernel. For example:

x+x
x*x
x^2 x^3

etc. This is normally very useful, and not a problem. However, if you 
want output to have a special structure - as in your case, you need to 
use a rule which protects part of the expression with HoldForm to 
prevent immediate re-evaluation. For example:

In[3]:= halfIntegerQ[x_?NumberQ] := (! IntegerQ[x]) && IntegerQ[2 x];

In[4]:= e^(5/2) /.
  a_^(b_?halfIntegerQ) -> a^(b - 1/2) HoldForm[Sqrt[a]]


This will print as you require, but if you copy the output into another 
input cell, you will have problems because the invisible HoldForm is 
still there (print in InputForm to see this). This can be removed with a 
rule such as:

  HoldForm -> Identity

David Bailey

www.dbaileyconsultancy.co.uk


  • Prev by Date: might be useful
  • Next by Date: Re: O'Reilly Ebook Deal of Day: Mathematica Cookbook
  • Previous by thread: Re: using rules for square roots
  • Next by thread: Re: using rules for square roots