## `Dom::Rational` -- the field of rational numbers

#### Introduction

`Dom::Rational` is the field of rational numbers represented by elements of the domains `DOM_INT` or `DOM_RAT`.

#### Creating Elements

`Dom::Rational(x)`

#### Parameters

`x` | - | an integer or a rational number

#### Categories

`Cat::QuotientField(`Dom::Integer

), `Cat::DifferentialRing`, `Cat::OrderedSet`

#### Related Domains

`Dom::Complex`, `Dom::Float`, `Dom::Numerical`, `Dom::Rational`, `Dom::Real`

#### Details

- `Dom::Rational` is the domain of rational numbers represented by expressions of type `DOM_INT` or `DOM_RAT`.
- Elements of `Dom::Rational` are usually not created explicitly. However, if one creates elements using the usual syntax, it is checked wether the input is of type `DOM_INT` or `DOM_RAT`. This means `Dom::Rational` is a faēcade domain which creates elements of domain type `DOM_INT` or `DOM_RAT`.
- Viewed as a differential ring `Dom::Rational` is trivial, it contains constants only.
- `Dom::Rational` has the domain `Dom::Numerical` as its super domain, i.e., it inherits each method which is defined by `Dom::Numerical` and not re-implemented by `Dom::Rational`. Methods described below are re-implemented by `Dom::Rational`.

#### Method denom: denominator of a rational number

- `denom(dom x)`
- - This method returns the denominator of the rational number `x`.
  - This method overloads `denom`.

#### Method diff: differentiates

- `diff(dom z, <, any x...> )`
- - This method returns `z` if it is called with only one argument. Otherwise it returns 0.
  - This method overloads `diff`.

#### Method numer: numerator of the rational number

- `numer(dom x)`
- - This method returns the numerator of the rational number `x`.
  - This method overloads `numer`.

#### Method random: random number generation

- `random()`
- - This methods returns a rational number `a/b` where `a` and `b` are integers between -999 and 999.

#### Method retract: retract to an integer element

- `retract(dom x)`
- - This method returns `x` if it is an integer and `FAIL` otherwise.

#### Method convert: conversion of objects

- `convert(any x)`
- - This method tries to convert `x` to a number of type `Dom::Rational`. This is only possible if `x` is of type `DOM_INT` or `DOM_RAT`. If the conversion fails, `FAIL` is returned.

#### Method convert_to: conversion to other domains

- `convert_to(dom x, any T)`
- - This method tries to convert the number `x` to an element of type `T`, or, if `T` is not a domain, to the domain type of `T`. If the conversion fails, `FAIL` is returned.
  - The following domains are allowed for `T`: `DOM_INT`, `Dom::Integer`, `Dom::Rational`, `DOM_RAT`, `DOM_FLOAT`, `Dom::Float` and `Dom::Numerical`.

#### Method testtype: type checking

- `testtype(any x, dom T)`
- - This method checks whether it can convert `x` to the domain `Dom::Rational`. This is the case if `x` is of type `DOM_INT` or `DOM_RAT`. It returns `TRUE` if it can perform the conversion. Otherwise `FAIL` is returned.
  - In general this method is called from the function `testtype` and not directly by the user. Example 2 demonstrates this behaviour.

#### Example 1

Creating some rational numbers using `Dom::Rational`. This example also shows that `Dom::Rational` is a faēcade domain.

    >> Dom::Rational(2/3) ; domtype(%)

                                        2/3

                                      DOM_RAT

    >> Dom::Rational(2.0)

          Error: illegal arguments [Dom::Rational::new]

#### Example 2

By tracing the method `Dom::Rational::testtype` we can see the interaction between `testtype` and `Dom::Rational::testtype`.

    >> prog::trace(Dom::Rational::testtype):
       delete x:
       testtype(x, Dom::Rational);
       testtype(3/4, Dom::Rational);
       prog::untrace(Dom::Rational::testtype):

          enter 'Dom::Rational::testtype'        with args   : x, Dom::Rational
          leave 'Dom::Rational::testtype'        with result : FAIL

                                       FALSE
          enter 'Dom::Rational::testtype'        with args   : 3/4, Dom::Rational
          leave 'Dom::Rational::testtype'        with result : TRUE

                                       TRUE

#### Super-Domain

`Dom::Numerical`

#### Axioms

`Ax::canonicalRep`

, `Ax::systemRep`, `Ax::canonicalOrder`, `Ax::efficientOperation("_divide")`, `Ax::efficientOperation("_mult")`, `Ax::efficientOperation("_invert")`

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000