) |
We create the rational numbers
, and call a few functions:
sage: Q = RationalField(); Q Rational Field sage: Q.characteristic() 0 sage: Q.is_field() True sage: Q.zeta() -1
We next illustrate arithmetic in
.
sage: Q('49/7') 7 sage: type(Q('49/7')) <type '_rational.Rational'> sage: a = Q('19/374'); b = frac(17, 371); print a, b 19/374 17/371 sage: a + b 13407/138754 sage: b + a 13407/138754 sage: a * b 19/8162 sage: b * a 19/8162 sage: a - b 691/138754 sage: b - a -691/138754 sage: a / b 7049/6358 sage: b / a 6358/7049 sage: b < a True sage: a < b False
Next finally illustrate arithmetic with automatic coercion.
The types that coerce into the rational field include
str, int, long, Integer
.
sage: a + '17/371' 13407/138754 sage: a * 374 19 sage: 374 * a 19 sage: a/19 1/374 sage: a + 1 393/374
characteristic,
gen,
is_atomic_repr,
is_field,
is_finite,
name,
ngens,
random,
zeta
Further documentation:
) |
Return 0, since the rational field has characteristic 0.
) |
Return True, since the rational field is a field.
) |
Return False, since the rational field is not finite.
Instances of class RationalField also have the following special functions:
__call__,
__cmp__,
__contains__
Further documentation:
x) |
Coerce x into the field of rational numbers.