Package sage :: Package rings :: Module rational_field :: Class RationalField
[show private | hide private]
[frames | no frames]

Type RationalField

      Ring --+
             |
object --+   |
         |   |
     _uniq --+
             |
            RationalField


The field of rational numbers.

EXAMPLES: We create the rational numbers and call a few functions:
>>> Q = RationalField(); Q
Rational Field

>>> Q.characteristic()
0

>>> Q.is_field()
True

>>> Q.zeta()
-1
We illustrate arithmetic in Q.
>>> Q('49/7')
7

>>> type(Q('49/7'))
<type '_rational.Rational'>

>>> a = Q('19/374'); b = frac(17, 371); print a, b
19/374 17/371

>>> a + b
13407/138754

>>> b + a
13407/138754

>>> a * b
19/8162

>>> b * a
19/8162

>>> a - b
691/138754

>>> b - a
-691/138754

>>> a / b
7049/6358

>>> b / a
6358/7049

>>> b < a
True

>>> a < b
False
Next we illustrate arithmetic with automatic coercion. The types that coerce are: str, int, long, Integer.
>>> a + '17/371'
13407/138754

>>> a * 374
19

>>> 374 * a
19

>>> a/19
1/374

>>> a + 1
393/374

Method Summary
  __call__(self, x)
Coerce x into the ring.
  __cmp__(self, other)
  __contains__(self, x)
  __repr__(self)
  characteristic(self)
  gen(self)
  is_atomic_repr(self)
True if the elements have atomic string representations, in the sense that they print if they print at s, then -s means the negative of s.
  is_field(self)
  name(self)
  ngens(self)
  random(self, num_bound, den_bound)
  zeta(self)
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)
    Inherited from Ring
  type(self)

Instance Method Details

__call__(self, x)
(Call operator)

Coerce x into the ring.
Overrides:
sage.rings.ring.Ring.__call__ (inherited documentation)

is_atomic_repr(self)

True if the elements have atomic string representations, in the sense that they print if they print at s, then -s means the negative of s. For example, integers are atomic but polynomials are not.
Overrides:
sage.rings.ring.Ring.is_atomic_repr (inherited documentation)

Generated by Epydoc 2.1 on Mon May 9 17:57:02 2005 http://epydoc.sf.net