library colibrilib.flint — module CAThe exact real numbers of Flint (Flint.CA, with the context of colibri2). Trusted: each operation is exact.
Flint can fail to decide a comparison, even on algebraic numbers: then flint_ca.ml prints a message and exits, so that the comparisons, floor, ceil and truncate return only exact results.
Known false assumption, see agents/journal/soundness–review–2026–11–05.md (finding F1): the OCaml check_is_rational is for now a stand–in that never answers None, and answers Some false when to_q fails.
module CA18use int.Int19use real.RealInfix20use real.FromInt21use real.Abs22use real.Square23use real.Truncate24use mach.int.Int6325use option.Option26use colibrilib.zarith.Q as Q27use colibrilib.q.Real as Real2829type t3031function real t : real323334val function of_q (q:Q.t) : t35ensures { real result = Q.real q }36
The rational value when Flint finds one (ca_get_fmpq). None proves nothing: Flint also fails on some rationals.
val function to_q (a:t) : option Q.t40ensures { match result with41| Some q -> Q.real q = real a42| None -> true43end }44
Is the number rational (ca_check_is_rational)? None when Flint did not finish.
val function check_is_rational (a:t) : option bool48ensures { match result with49| Some b -> b <-> exists q:Q.t. Q.real q = real a50| None -> true51end }52
Prints a message and stops the program: it never returns. For a case where Flint did not finish.
val give_up (_a:t) : 'a56returns { _ -> false }57
There are irrational numbers (sqrt 2)
axiom irrational: exists c:t. forall q:Q.t. Q.real q <> real c60
The comparisons answer -1, 0 or 1
val function compare (a b:t) : int6363ensures { result = if real a >. real b then 1 else if real a <. real b then -1 else 0 }6465val function compare_q (a:t) (q:Q.t) : int6366ensures { result = if real a >. Q.real q then 1 else if real a <. Q.real q then -1 else 0 }6768val function sign (a:t) : int6369ensures { result = if real a >. 0. then 1 else if real a <. 0. then -1 else 0 }7071val function floor (a:t) : int72ensures { result = Truncate.floor (real a) }7374val function ceil (a:t) : int75ensures { result = Truncate.ceil (real a) }7677val function truncate (a:t) : int78ensures { result = Truncate.truncate (real a) }7980val function add (a b:t) : t81ensures { real result = real a +. real b }8283val function sub (a b:t) : t84ensures { real result = real a -. real b }8586val function mul (a b:t) : t87ensures { real result = real a *. real b }8889val function div (a b:t) : t90requires { real b <> 0. }91ensures { real result = real a /. real b }9293val function neg (a:t) : t94ensures { real result = -. real a }9596val function inv (a:t) : t97requires { real a <> 0. }98ensures { real result = 1. /. real a }99100val function abs (a:t) : t101ensures { real result = Abs.abs (real a) }102103val function sqrt (a:t) : t104requires { 0. <=. real a }105ensures { real result = Square.sqrt (real a) }106107val function div_e (a b:t) : int108requires { real b <> 0. }109ensures { result = Real.div_e (real a) (real b) }110111val function div_t (a b:t) : int112requires { real b <> 0. }113ensures { result = Real.div_t (real a) (real b) }114115val function div_f (a b:t) : int116requires { real b <> 0. }117ensures { result = Real.div_f (real a) (real b) }118119val function mod_e (a b:t) : t120requires { real b <> 0. }121ensures { real result = Real.mod_e (real a) (real b) }122123val function mod_t (a b:t) : t124requires { real b <> 0. }125ensures { real result = Real.mod_t (real a) (real b) }126127val function mod_f (a b:t) : t128requires { real b <> 0. }129ensures { real result = Real.mod_f (real a) (real b) }130131use real.PowerInt as RP132133val function of_z (z:int) : t134ensures { real result = from_int z }135
a^n (Flint.CA.pow_int)
val function pow_int (a:t) (n:int63) : t138requires { 0 <= n \/ real a <> 0. }139ensures { real result = if 0 <= n then RP.power (real a) n140else 1. /. RP.power (real a) (- n) }141
a^e for a rational exponent e = num/den (Flint.CA.pow, the non negative root): r^den = a^num
val function pow (a:t) (e:Q.t) : t145requires { 0. <. real a \/ (real a = 0. /\ 0 < e.Q.num) }146ensures { 0. <=. real result }147ensures { 0 <= e.Q.num ->148RP.power (real result) e.Q.den = RP.power (real a) e.Q.num }149ensures { e.Q.num < 0 ->150RP.power (real result) e.Q.den *. RP.power (real a) (- e.Q.num) = 1. }151
The length of the printed number, a measure of its size (no specification)
val function size (a:t) : int63155end156