"""Build a Scalar profile with exact rational arithmetic and prove literal domains."""
from apn_mojo import Integer, Rational
from judgment_core import LiteralValue
from judgment_shell import literal_at
from scalar import ProfileLevel, build_scalar, literal_facts, session
from std.testing import assert_equal, assert_true
from termbank import Budget


def main() raises:
    var budget = Budget(100_000_000)
    var profile = build_scalar(budget, ProfileLevel.EXACT_ARITHMETIC)
    var s = session(profile, work=10_000_000)
    var root = s.base()
    var kind = profile.literal_kind(s)
    var half = literal_at(s, root, kind, LiteralValue(Rational(Integer(1), Integer(2))), budget)
    var third = literal_at(s, root, kind, LiteralValue(Rational(Integer(1), Integer(3))), budget)
    var expected = literal_at(s, root, kind, LiteralValue(Rational(Integer(5), Integer(6))), budget)
    var plus = profile.constant(s, "plus")
    assert_true(plus(half, third).same_as(expected))
    var facts = literal_facts(s, profile, Rational(Integer(1), Integer(2)), budget)
    assert_equal(len(facts), 4)
    print("Exact arithmetic: 1/2 + 1/3 = 5/6; 4 checked domain facts for 1/2")
