Rational-Valued Functions

class murasyp.functions.Function(mapping={})[source]

Rational-valued functions

type mapping:Mapping (such as a dict) to a representation of Real

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()[source]

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'})
... )
range()[source]

Range of the function

returns:the range of the function, i.e., the set of all values returned by the function
rtype:frozenset
>>> assert (
...     Function({'a': 1, 'b': -1, 'c': 0}).range() ==
...     frozenset({Fraction(0, 1), Fraction(1, 1), Fraction(-1, 1)})
... )
support()[source]

Support of the function

returns:the support of the function, i.e., that part of the domain for which the function is nonzero
rtype:frozenset
>>> assert (
...     Function({'a': 1, 'b': -1, 'c': 0}).support() ==
...     frozenset({'a', 'b'})
... )

Previous topic

References

Next topic

Vectors & Polytopes

This Page