1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(*i $Id: QSig.v 11207 2008-07-04 16:50:32Z letouzey $ i*)
11
Require Import QArith Qpower.
17
(** Interface of a rich structure about rational numbers.
18
Specifications are written via translation to Q.
25
Parameter to_Q : t -> Q.
26
Notation "[ x ]" := (to_Q x).
28
Definition eq x y := [x] == [y].
30
Parameter of_Q : Q -> t.
31
Parameter spec_of_Q: forall x, to_Q (of_Q x) == x.
35
Parameter minus_one : t.
37
Parameter spec_0: [zero] == 0.
38
Parameter spec_1: [one] == 1.
39
Parameter spec_m1: [minus_one] == -(1).
41
Parameter compare : t -> t -> comparison.
43
Parameter spec_compare : forall x y, compare x y = ([x] ?= [y]).
45
Definition lt n m := compare n m = Lt.
46
Definition le n m := compare n m <> Gt.
47
Definition min n m := match compare n m with Gt => m | _ => n end.
48
Definition max n m := match compare n m with Lt => m | _ => n end.
50
Parameter eq_bool : t -> t -> bool.
52
Parameter spec_eq_bool : forall x y,
53
if eq_bool x y then [x]==[y] else ~([x]==[y]).
55
Parameter red : t -> t.
57
Parameter spec_red : forall x, [red x] == [x].
58
Parameter strong_spec_red : forall x, [red x] = Qred [x].
60
Parameter add : t -> t -> t.
62
Parameter spec_add: forall x y, [add x y] == [x] + [y].
64
Parameter sub : t -> t -> t.
66
Parameter spec_sub: forall x y, [sub x y] == [x] - [y].
68
Parameter opp : t -> t.
70
Parameter spec_opp: forall x, [opp x] == - [x].
72
Parameter mul : t -> t -> t.
74
Parameter spec_mul: forall x y, [mul x y] == [x] * [y].
76
Parameter square : t -> t.
78
Parameter spec_square: forall x, [square x] == [x] ^ 2.
80
Parameter inv : t -> t.
82
Parameter spec_inv : forall x, [inv x] == / [x].
84
Parameter div : t -> t -> t.
86
Parameter spec_div: forall x y, [div x y] == [x] / [y].
88
Parameter power : t -> Z -> t.
90
Parameter spec_power: forall x z, [power x z] == [x] ^ z.
94
(** NB: several of the above functions come with [..._norm] variants
95
that expect reduced arguments and return reduced results. *)
97
(** TODO : also speak of specifications via Qcanon ... *)