Skip to content

Project and reconstruct a residue class by the Chinese remainder theorem

Continuously checked

This is the exact source run by make test-examples and the ordinary Python test gate.

Domains: commalg

Source: examples/13_chinese_remainder_theorem.py

# SPDX-License-Identifier: MIT
# Copyright (c) 2026 Benjamin Antieau and Deven Manam
"""Project and reconstruct a residue class by the Chinese remainder theorem."""

from noether.commalg import ResidueRing


def main() -> None:
    ring = ResidueRing(360)
    decomposition = ring.crt()
    decomposition.verify()
    value = ring(347)
    components = decomposition.project(value)
    assert decomposition.reconstruct(components) == value
    print(f"347 mod 360 -> {[int(component) for component in components]}")


if __name__ == "__main__":
    main()

Run it

.venv/bin/python examples/13_chinese_remainder_theorem.py