Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Rational[a,b] vs Rational[1,2]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116770] Re: Rational[a,b] vs Rational[1,2]
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 26 Feb 2011 06:10:12 -0500 (EST)

On 25 Feb 2011, at 12:34, Jack L Goldberg 1 wrote:

> I am a bit puzzled.  In view of the on-going debate, when ought one 
> use Rational[a,b].  Put a bit differently, is there a snippet of code 
> in which one would prefer Rational[a,b] to a/b?
>

Well, first of all, when you want to match something like 2/3 you need to use Rational[x_,y_]; e.g.

2/3 /. Rational[x_, y_] -> x - y

 -1

so you need to be able to use Rational with symbolic arguments when you use patterns. As for Rational[a,b] when a and b are not patterns, I can't think of any obvious situation when it would be necessary, although when writing a global rule (function)  with Rational[x_,y_] on the LHS you might prefer to have Rational[x,y] also on the right rather than just x/y, simply because it will be probably easier to see what is going on in the program (and it would be slightly more direct since x/y will be converted to Rational[x,y] when integers are substituted for x and y.

Andrzej Kozlowski


  • Prev by Date: Re: Formatting a Cell Programmatically
  • Next by Date: Re: Formatting a Cell Programmatically
  • Previous by thread: Re: Rational[a,b] vs Rational[1,2]
  • Next by thread: Solved: Factor/Simplify set of complex expressions