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

Discussion in 'Mathematica' started by Richard Fateman, Feb 22, 2011.

  1. I find it potentially hazardous that Head[]
    does not distinguish the cases of Head[1/2]

    and Head[Rational[a,b]]

    Thus these both get transformed...

    1/2 /. Rational[r_,s_]-> foo[r,s]

    Rational[a,b] /. Rational[r_,s_] -> foo[r,s]

    but compare ...

    1/2 /. 2->4

    Rational[a,2] /. 2->4

    I'm not saying I'm surprised by this, of course.

    Perhaps Rational[a,b] should be converted to a/b unless both
    a and b are numbers.

    Oh, for some fun, try Rational[1/2,4].


    PS, I used version 7.
    Richard Fateman, Feb 22, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.