| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
type vname = string |
| 13 |
|
| 14 |
open NumCompat |
| 15 |
|
| 16 |
type term = |
| 17 |
| Zero |
| 18 |
| Const of Q.t |
| 19 |
| Var of vname |
| 20 |
| Opp of term |
| 21 |
| Add of (term * term) |
| 22 |
| Sub of (term * term) |
| 23 |
| Mul of (term * term) |
| 24 |
| Pow of (term * int) |
| 25 |
|
| 26 |
let rec output_term o t = |
| 27 |
match t with |
| 28 |
| Zero -> output_string o "0" |
| 29 |
| Const n -> output_string o (Q.to_string n) |
| 30 |
| Var n -> Printf.fprintf o "v%s" n |
| 31 |
| Opp t -> Printf.fprintf o "- (%a)" output_term t |
| 32 |
| Add (t1, t2) -> Printf.fprintf o "(%a)+(%a)" output_term t1 output_term t2 |
| 33 |
| Sub (t1, t2) -> Printf.fprintf o "(%a)-(%a)" output_term t1 output_term t2 |
| 34 |
| Mul (t1, t2) -> Printf.fprintf o "(%a)*(%a)" output_term t1 output_term t2 |
| 35 |
| Pow (t1, i) -> Printf.fprintf o "(%a)^(%i)" output_term t1 i |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
type positivstellensatz = |
| 42 |
| Axiom_eq of int |
| 43 |
| Axiom_le of int |
| 44 |
| Axiom_lt of int |
| 45 |
| Rational_eq of Q.t |
| 46 |
| Rational_le of Q.t |
| 47 |
| Rational_lt of Q.t |
| 48 |
| Square of term |
| 49 |
| Monoid of int list |
| 50 |
| Eqmul of term * positivstellensatz |
| 51 |
| Sum of positivstellensatz * positivstellensatz |
| 52 |
| Product of positivstellensatz * positivstellensatz |
| 53 |
|
| 54 |
let rec output_psatz o = function |
| 55 |
| Axiom_eq i -> Printf.fprintf o "Aeq(%i)" i |
| 56 |
| Axiom_le i -> Printf.fprintf o "Ale(%i)" i |
| 57 |
| Axiom_lt i -> Printf.fprintf o "Alt(%i)" i |
| 58 |
| Rational_eq n -> Printf.fprintf o "eq(%s)" (Q.to_string n) |
| 59 |
| Rational_le n -> Printf.fprintf o "le(%s)" (Q.to_string n) |
| 60 |
| Rational_lt n -> Printf.fprintf o "lt(%s)" (Q.to_string n) |
| 61 |
| Square t -> Printf.fprintf o "(%a)^2" output_term t |
| 62 |
| Monoid l -> Printf.fprintf o "monoid" |
| 63 |
| Eqmul (t, ps) -> Printf.fprintf o "%a * %a" output_term t output_psatz ps |
| 64 |
| Sum (t1, t2) -> Printf.fprintf o "%a + %a" output_psatz t1 output_psatz t2 |
| 65 |
| Product (t1, t2) -> |
| 66 |
Printf.fprintf o "%a * %a" output_psatz t1 output_psatz t2 |