library colibrilib.stda — module A_intfThe real algebraic numbers, implemented by StdA. One name per notion, no program operator; the specifications are on the real value. A number has several representations at most for its value: the equality of the numbers is equal, not the logical equality. Only add, sub, mul and mod_e are logic functions on t (polynome.mlw needs their terms).
module A_intf12use real.RealInfix13use int.Int14use real.FromInt15use real.Abs16use real.Square17use real.Truncate18use mach.int.Int6319use colibrilib.q.Ord as Ord20use colibrilib.q.Real as Real21use colibrilib.dv.Dv22use colibrilib.stdq.StdQ as Q23use real.PowerInt2425type t2627function real (x:t) : real2829meta coercion function real30
The rational numbers among the algebraic ones
predicate rational (a:t) = Q.is_rat (real a)33Valid (25ms) (colibri2)34val equal (a b:t) : bool35ensures { result <-> real a = real b }36Valid (22ms) (colibri2)37val le (a b:t) : bool38ensures { result <-> real a <=. real b }39Valid (22ms) (colibri2)40val lt (a b:t) : bool41ensures { result <-> real a <. real b }42Valid (28ms) (colibri2)43val abs (a:t) : t44ensures { real result = abs (real a) }45Valid (24ms) (colibri2)46val compare (a b:t) : Ord.t47ensures { match result with48| Ord.Eq -> real a = real b49| Ord.Lt -> real a <. real b50| Ord.Gt -> real b <. real a51end }52Valid (17ms) (colibri2)53val function add (a b:t) : t54ensures { real result = real a +. real b }55Valid (26ms) (colibri2)56val function sub (a b:t) : t57ensures { real result = real a -. real b }58Valid (31ms) (colibri2)59val function mul (a b:t) : t60ensures { real result = real a *. real b }61
A function, for the closures given to the maps (polynome.Lin.nz)
Valid (51ms) (colibri2)val function is_zero (a:t) : bool64ensures { result <-> real a = 0. }65Valid (30ms) (colibri2)66val div (a b:t) : t67requires { real b <> 0. }68ensures { real result = real a /. real b }69Valid (35ms) (colibri2)70val neg (a:t) : t71ensures { real result = -. real a }72Valid (34ms) (colibri2)73val of_int (a:int63) : t74ensures { real result = from_int a }75Valid (28ms) (colibri2)76val of_bigint (a:int) : t77ensures { real result = from_int a }78Valid (28ms) (colibri2)79val truncate_z (a:t) : int80ensures { result = truncate (real a) }81Valid (29ms) (colibri2)82val floor_z (a:t) : int83ensures { result = floor (real a) }84Valid (24ms) (colibri2)85val ceil_z (a:t) : int86ensures { result = ceil (real a) }87Valid (42ms) (colibri2)88val is_integer (a:t) : bool89ensures { result <-> Real.is_integer (real a) }90Valid (32ms) (colibri2)91val div_e (a b:t) : t92requires { real b <> 0. }93ensures { real result = from_int (Real.div_e (real a) (real b)) }94
The Euclidean remainder, as a term: polynome.mlw reduces coefficients
Valid (37ms) (colibri2)val function mod_e (a b:t) : t97requires { real b <> 0. }98ensures { real result = Real.mod_e (real a) (real b) }99Valid (26ms) (colibri2)100val div_t (a b:t) : t101requires { real b <> 0. }102ensures { real result = from_int (Real.div_t (real a) (real b)) }103Valid (29ms) (colibri2)104val mod_t (a b:t) : t105requires { real b <> 0. }106ensures { real result = Real.mod_t (real a) (real b) }107Valid (23ms) (colibri2)108val div_f (a b:t) : t109requires { real b <> 0. }110ensures { real result = from_int (Real.div_f (real a) (real b)) }111Valid (29ms) (colibri2)112val mod_f (a b:t) : t113requires { real b <> 0. }114ensures { real result = Real.mod_f (real a) (real b) }115Valid (33ms) (colibri2)116val sqrt (a:t) : t117requires { 0. <=. real a }118ensures { real result = sqrt (real a) }119
The two cases of the representation: Irr is a number that is not a rational (the invariant of StdA.irr, proved from Flint's to_q)
type view = Rat Q.t | Irr123Valid (34ms) (colibri2)124val view (a:t) : view125ensures { match result with126| Rat q -> real a = Q.real q127| Irr -> forall q:Q.t. real a <> Q.real q128end }129Valid (28ms) (colibri2)130val of_q (q:Q.t) : t131ensures { real result = Q.real q }132
The value of an integer
Valid (29ms) (colibri2)val to_z (a:t) : int135requires { Real.is_integer (real a) }136ensures { from_int result = real a }137
The largest multiple of m (positive) below a, and the smallest above
Valid (24ms) (colibri2)val round_down_to (a:t) (m:Q.t) : Q.t140requires { 0.0 <. Q.real m }141ensures { dv (Q.real result) (Q.real m) }142ensures { Q.real result <=. real a <. Q.real result +. Q.real m }143Valid (38ms) (colibri2)144val round_up_to (a:t) (m:Q.t) : Q.t145requires { 0.0 <. Q.real m }146ensures { dv (Q.real result) (Q.real m) }147ensures { Q.real result -. Q.real m <. real a <=. Q.real result }148
a^e, the non negative root: for a fraction n/d equal to e, the d–th power of the result is the n–th power of a. The power of the reals is left out of this interface: colibrilib.product.APow derives it.
Valid (242ms) (colibri2)val positive_pow (a:t) (e:Q.t) : t154requires { 0. <. real a \/ (real a = 0. /\ 0. <. Q.real e) }155ensures { 0. <=. real result }156ensures { exists n d:int. 0 < d /\ Q.real e = from_int n /. from_int d /\157(0 <= n -> power (real result) d = power (real a) n) /\158(n < 0 -> power (real result) d *. power (real a) (- n) = 1.) }159end160