Rational-valued functions
Features:
Values may be specified as int, float, or Fraction, whose str-representation is then especially convenient.
>>> f = Function({'a': 11e-1, 'b': '-1/2','c': 0})
>>> assert f == Function({'a': '11/10', 'c': 0, 'b': '-1/2'})
>>> f['a']
Fraction(11, 10)
Note
No floats are ever really used; they are immediately converted to fractions and should be seen as just a convenient input representation for decimal numbers.
Scalar multiplication and division, as well as pointwise multiplication, addition, and subtraction (also with scalars) is possible.
>>> f = Function({'a': 1.1, 'b': '-1/2','c': 0})
>>> g = Function({'b': '.6', 'c': -2, 'd': 0.0})
>>> assert -1 + (.3 * f - g) / 2 == Function({'c': 0, 'b': '-11/8'})
>>> assert f * g == Function({'c': 0, 'b': '-3/10'})
Note
The domain of results of sums and differences is the intersection of the respective domains.
Domain of the function
returns: the domain of the function, i.e., those values for which the function is defined rtype: frozenset
>>> assert (
... Function({'a': 1, 'b': -1, 'c': 0}).domain() ==
... frozenset({'a', 'c', 'b'})
... )