Functional Weave
Code in Python

math.rational@2.0.0

impl/python/subtract_rational.py

322 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .math_rational_rational import rational_from_wide, rational_parts  ← rational, another function of this group · built into the same file, even by a slim install
from .math_rational_types import Rational


def subtract_rational(a: Rational, b: Rational) -> Rational:
    """a - b, reduced."""
    an, ad = rational_parts(a)
    bn, bd = rational_parts(b)
    return rational_from_wide(an * bd - bn * ad, ad * bd)