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
(* $Id: ccproof.ml 9857 2007-05-24 14:21:08Z corbinea $ *)
11
(* This file uses the (non-compressed) union-find structure to generate *)
12
(* proof-trees that will be transformed into proof-terms in cctac.ml4 *)
23
| Trans of proof*proof
24
| Congr of proof*proof
25
| Inject of proof*constructor*int*int
27
{p_lhs:term;p_rhs:term;p_rule:rule}
29
let prefl t = {p_lhs=t;p_rhs=t;p_rule=Refl t}
32
match p1.p_rule,p2.p_rule with
33
Refl t1, Refl t2 -> prefl (Appli (t1,t2))
35
{p_lhs=Appli (p1.p_lhs,p2.p_lhs);
36
p_rhs=Appli (p1.p_rhs,p2.p_rhs);
40
match p1.p_rule,p3.p_rule with
43
| Trans(p1,p2), _ ->ptrans p1 (ptrans p2 p3)
44
| Congr(p1,p2), Congr(p3,p4) ->pcongr (ptrans p1 p3) (ptrans p2 p4)
45
| Congr(p1,p2), Trans({p_rule=Congr(p3,p4)},p5) ->
46
ptrans (pcongr (ptrans p1 p3) (ptrans p2 p4)) p5
48
if p1.p_rhs = p3.p_lhs then
52
else anomaly "invalid cc transitivity"
68
p_rule=Inject (psym p0,c,n,a)}
69
| Trans (p1,p2)-> ptrans (psym p2) (psym p1)
70
| Congr (p1,p2)-> pcongr (psym p1) (psym p2)
73
let l,r = Hashtbl.find axioms s in
79
let l,r = Hashtbl.find axioms s in
90
| _ -> anomaly "nth_arg: not enough args"
93
{p_lhs=nth_arg p.p_lhs (n-a);
94
p_rhs=nth_arg p.p_rhs (n-a);
95
p_rule=Inject(p,c,n,a)}
99
let axioms = axioms uf in
101
let rec equal_proof i j=
102
if i=j then prefl (term uf i) else
103
let (li,lj)=join_path uf i j in
104
ptrans (path_proof i li) (psym (path_proof j lj))
106
and edge_proof ((i,j),eq)=
107
let pi=equal_proof i eq.lhs in
108
let pj=psym (equal_proof j eq.rhs) in
112
if reversed then psymax axioms s
114
| Congruence ->congr_proof eq.lhs eq.rhs
115
| Injection (ti,ipac,tj,jpac,k) ->
116
let p=ind_proof ti ipac tj jpac in
117
let cinfo= get_constructor_info uf ipac.cnode in
118
pinject p cinfo.ci_constr cinfo.ci_nhyps k
119
in ptrans (ptrans pi pij) pj
121
and constr_proof i t ipac=
125
let npac=tail_pac ipac in
126
let (j,arg)=subterms uf t in
127
let targ=term uf arg in
129
let u=find_pac uf rj npac in
130
let p=constr_proof j u npac in
131
ptrans (equal_proof i t) (pcongr p (prefl targ))
133
and path_proof i=function
134
[] -> prefl (term uf i)
135
| x::q->ptrans (path_proof (snd (fst x)) q) (edge_proof x)
138
let (i1,i2) = subterms uf i
139
and (j1,j2) = subterms uf j in
140
pcongr (equal_proof i1 j1) (equal_proof i2 j2)
142
and ind_proof i ipac j jpac=
143
let p=equal_proof i j
144
and p1=constr_proof i i ipac
145
and p2=constr_proof j j jpac in
146
ptrans (psym p1) (ptrans p p2)
149
`Prove (i,j) -> equal_proof i j
150
| `Discr (i,ci,j,cj)-> ind_proof i ci j cj