| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
open Ccalgo |
| 15 |
open Pp |
| 16 |
|
| 17 |
type rule= |
| 18 |
Ax of axiom |
| 19 |
| SymAx of axiom |
| 20 |
| Refl of ATerm.t |
| 21 |
| Trans of proof*proof |
| 22 |
| Congr of proof*proof |
| 23 |
| Inject of proof*Constr.pconstructor*int*int |
| 24 |
and proof = |
| 25 |
{p_lhs:ATerm.t;p_rhs:ATerm.t;p_rule:rule} |
| 26 |
|
| 27 |
let prefl t = {p_lhs=t;p_rhs=t;p_rule=Refl t} |
| 28 |
|
| 29 |
let pcongr p1 p2 = |
| 30 |
match p1.p_rule,p2.p_rule with |
| 31 |
Refl t1, Refl t2 -> prefl (ATerm.mkAppli (t1, t2)) |
| 32 |
| _, _ -> |
| 33 |
{p_lhs=ATerm.mkAppli (p1.p_lhs, p2.p_lhs); |
| 34 |
p_rhs=ATerm.mkAppli (p1.p_rhs, p2.p_rhs); |
| 35 |
p_rule=Congr (p1,p2)} |
| 36 |
|
| 37 |
let rec ptrans p1 p3= |
| 38 |
match p1.p_rule,p3.p_rule with |
| 39 |
Refl _, _ ->p3 |
| 40 |
| _, Refl _ ->p1 |
| 41 |
| Trans(p1,p2), _ ->ptrans p1 (ptrans p2 p3) |
| 42 |
| Congr(p1,p2), Congr(p3,p4) -> |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
u) |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
pcongr (ptrans p1 p3) (ptrans p2 p4) |
| 52 |
| Congr(p1,p2), Trans({p_rule=Congr(p3,p4)},p5) -> |
| 53 |
|
| 54 |
ptrans (pcongr (ptrans p1 p3) (ptrans p2 p4)) p5 |
| 55 |
| _, _ -> |
| 56 |
{p_lhs=p1.p_lhs; |
| 57 |
p_rhs=p3.p_rhs; |
| 58 |
p_rule=Trans (p1,p3)} |
| 59 |
|
| 60 |
let rec psym p = |
| 61 |
match p.p_rule with |
| 62 |
Refl _ -> p |
| 63 |
| SymAx s -> |
| 64 |
{p_lhs=p.p_rhs; |
| 65 |
p_rhs=p.p_lhs; |
| 66 |
p_rule=Ax s} |
| 67 |
| Ax s-> |
| 68 |
{p_lhs=p.p_rhs; |
| 69 |
p_rhs=p.p_lhs; |
| 70 |
p_rule=SymAx s} |
| 71 |
| Inject (p0,c,n,a)-> |
| 72 |
{p_lhs=p.p_rhs; |
| 73 |
p_rhs=p.p_lhs; |
| 74 |
p_rule=Inject (psym p0,c,n,a)} |
| 75 |
| Trans (p1,p2)-> ptrans (psym p2) (psym p1) |
| 76 |
| Congr (p1,p2)-> pcongr (psym p1) (psym p2) |
| 77 |
|
| 78 |
let pax uf s = |
| 79 |
let l,r = Ccalgo.axioms uf s in |
| 80 |
{p_lhs=l; |
| 81 |
p_rhs=r; |
| 82 |
p_rule=Ax s} |
| 83 |
|
| 84 |
let psymax uf s = |
| 85 |
let l,r = Ccalgo.axioms uf s in |
| 86 |
{p_lhs=r; |
| 87 |
p_rhs=l; |
| 88 |
p_rule=SymAx s} |
| 89 |
|
| 90 |
let pinject p c n a = |
| 91 |
{p_lhs=ATerm.nth_arg p.p_lhs (n-a); |
| 92 |
p_rhs=ATerm.nth_arg p.p_rhs (n-a); |
| 93 |
p_rule=Inject(p,c,n,a)} |
| 94 |
|
| 95 |
let rec equal_proof env sigma uf i j= |
| 96 |
debug_congruence (fun () -> str "equal_proof " ++ pr_idx_term env sigma uf i ++ brk (1,20) ++ pr_idx_term env sigma uf j); |
| 97 |
if i=j then prefl (aterm uf i) else |
| 98 |
let (li,lj)=join_path uf i j in |
| 99 |
ptrans (path_proof env sigma uf i li) (psym (path_proof env sigma uf j lj)) |
| 100 |
|
| 101 |
and edge_proof env sigma uf ((i,j),eq)= |
| 102 |
debug_congruence (fun () -> str "edge_proof " ++ pr_idx_term env sigma uf i ++ brk (1,20) ++ pr_idx_term env sigma uf j); |
| 103 |
let pi=equal_proof env sigma uf i eq.lhs in |
| 104 |
let pj=psym (equal_proof env sigma uf j eq.rhs) in |
| 105 |
let pij= |
| 106 |
match eq.rule with |
| 107 |
Axiom (s,reversed)-> |
| 108 |
if reversed then psymax uf s |
| 109 |
else pax uf s |
| 110 |
| Congruence ->congr_proof env sigma uf eq.lhs eq.rhs |
| 111 |
| Injection (ti,ipac,tj,jpac,k) -> |
| 112 |
let p=ind_proof env sigma uf ti ipac tj jpac in |
| 113 |
let cinfo= get_constructor_info uf ipac.cnode in |
| 114 |
let cstr = match cinfo.ci_constr with |
| 115 |
| Construct c -> c |
| 116 |
| Int _ | Float _ | String _ -> assert false |
| 117 |
in |
| 118 |
pinject p cstr cinfo.ci_nhyps k in |
| 119 |
ptrans (ptrans pi pij) pj |
| 120 |
|
| 121 |
and constr_proof env sigma uf i ipac= |
| 122 |
debug_congruence (fun () -> str "constr_proof " ++ pr_idx_term env sigma uf i ++ brk (1,20)); |
| 123 |
let t=find_oldest_pac uf i ipac in |
| 124 |
let eq_it=equal_proof env sigma uf i t in |
| 125 |
if ipac.args=[] then |
| 126 |
eq_it |
| 127 |
else |
| 128 |
let fipac=tail_pac ipac in |
| 129 |
let (fi,arg)=subterms uf t in |
| 130 |
let targ=aterm uf arg in |
| 131 |
let p=constr_proof env sigma uf fi fipac in |
| 132 |
ptrans eq_it (pcongr p (prefl targ)) |
| 133 |
|
| 134 |
and path_proof env sigma uf i l= |
| 135 |
debug_congruence (fun () -> str "path_proof " ++ pr_idx_term env sigma uf i ++ brk (1,20) ++ str "{" ++ |
| 136 |
(prlist_with_sep (fun () -> str ",") (fun ((_,j),_) -> int j) l) ++ str "}"); |
| 137 |
match l with |
| 138 |
| [] -> prefl (aterm uf i) |
| 139 |
| x::q->ptrans (path_proof env sigma uf (snd (fst x)) q) (edge_proof env sigma uf x) |
| 140 |
|
| 141 |
and congr_proof env sigma uf i j= |
| 142 |
debug_congruence (fun () -> str "congr_proof " ++ pr_idx_term env sigma uf i ++ brk (1,20) ++ pr_idx_term env sigma uf j); |
| 143 |
let (i1,i2) = subterms uf i |
| 144 |
and (j1,j2) = subterms uf j in |
| 145 |
pcongr (equal_proof env sigma uf i1 j1) (equal_proof env sigma uf i2 j2) |
| 146 |
|
| 147 |
and ind_proof env sigma uf i ipac j jpac= |
| 148 |
debug_congruence (fun () -> str "ind_proof " ++ pr_idx_term env sigma uf i ++ brk (1,20) ++ pr_idx_term env sigma uf j); |
| 149 |
let p=equal_proof env sigma uf i j |
| 150 |
and p1=constr_proof env sigma uf i ipac |
| 151 |
and p2=constr_proof env sigma uf j jpac in |
| 152 |
ptrans (psym p1) (ptrans p p2) |
| 153 |
|
| 154 |
let build_proof env sigma uf= |
| 155 |
function |
| 156 |
| `Prove (i,j) -> equal_proof env sigma uf i j |
| 157 |
| `Discr (i,ci,j,cj)-> ind_proof env sigma uf i ci j cj |