This namespace contains an implementation of rational functions, or rational fractions; the data structure wraps a numerator u
and denominator v
where either or both are instances of [[p/Polynomial]]. (If both become non-polynomial, the functions in this namespace drop the [[RationalFunction]] instance down to whatever type is produced by (g/divide u v)
).
The [[RationalFunction]] type wraps up u
and v
, the arity
of the rational function (which must match the arity of u
and v
) and optional metadata m
.
The goal of this section is to implement +
, -
, *
and /
for rational function instances. The catch is that we want to hold to the contract that [[make]] provides - numerator and denominator should not acquire their own internal denominators! - without explicitly calling the expensive [[make]] each time.
The Rational arithmetic algorithms used below come from Knuth, vol 2, section 4.5.1.
The following functions act on full numerator, denominator pairs, and are suitable for use as the uv-op
argument to [[binary-combine]].
Armed with [[binary-combine]] and the functions above, we can now implement the full set of arithmetic functions for [[RationalFunction]] instances.
The following functions provide the ability to compose rational functions together without wrapping them in black-box functions.
This section defines functions that allow conversion back and forth between [[RationalFunction]] instances and symbolic expressions.
The operator-table
represents the operations that can be understood from the point of view of a rational function over some field.
[[polynomial/Polynomial]] gains a few more functions; inverting a polynomial, for example, results in a [[RationalFunction]] instance, so the generic installation of g/invert
and g/div
belong here.
TODO: g/quotient
, g/remainder
and g/lcm
feel like valid methods to install for [[RationalFunction]] instances. Close #365 when these are implemented.
v/=
is not implemented with [[defbinary]] because the variable order needs to change so that a [[RationalFunction]] is always on the left.