1
- (* * Proofs and tactics . *)
1
+ (* * Proof state . *)
2
2
3
- open Lplib open Base open Extra
3
+ open Lplib open Base
4
4
open Timed
5
- open Core open Term open Print
5
+ open Core open Term
6
6
open Common open Pos
7
-
8
- (* * Type of goals. *)
9
- type goal_typ =
10
- { goal_meta : meta (* * Goal metavariable. *)
11
- ; goal_hyps : Env .t (* * Precomputed scoping environment. *)
12
- ; goal_type : term (* * Precomputed type. *) }
13
-
14
- type goal =
15
- | Typ of goal_typ (* * Typing goal. *)
16
- | Unif of constr (* * Unification goal. *)
17
-
18
- let is_typ : goal -> bool = function Typ _ -> true | Unif _ -> false
19
- let is_unif : goal -> bool = function Typ _ -> false | Unif _ -> true
20
-
21
- let get_constr : goal -> constr =
22
- function Unif c -> c | Typ _ -> invalid_arg (__FILE__ ^ " get_constr" )
23
-
24
- let get_names : goal -> int StrMap.t = function
25
- | Unif (c ,_ ,_ ) -> Ctxt. names c
26
- | Typ gt -> Env. names gt.goal_hyps
27
-
28
- module Goal = struct
29
-
30
- type t = goal
31
-
32
- (* * [ctxt g] returns the typing context of the goal [g]. *)
33
- let ctxt : goal -> ctxt = fun g ->
34
- match g with
35
- | Typ gt -> Env. to_ctxt gt.goal_hyps
36
- | Unif (c ,_ ,_ ) -> c
37
-
38
- (* * [env g] returns the scoping environment of the goal [g]. *)
39
- let env : goal -> Env.t = fun g ->
40
- match g with
41
- | Unif (c ,_ ,_ ) ->
42
- let t, n = Ctxt. to_prod c mk_Type in
43
- (try fst (Env. of_prod_nth c n t)
44
- with Invalid_argument _ -> assert false )
45
- | Typ gt -> gt.goal_hyps
46
-
47
- (* * [of_meta m] creates a goal from the meta [m]. *)
48
- let of_meta : meta -> goal = fun m ->
49
- let goal_hyps, goal_type =
50
- try Env. of_prod_nth [] m.meta_arity ! (m.meta_type)
51
- with Invalid_argument _ -> assert false
52
- in
53
- Typ {goal_meta = m; goal_hyps; goal_type }
54
-
55
- (* * [simpl_opt f g] tries to simplify the goal [g] with the function [f]. *)
56
- let simpl_opt : (ctxt -> term -> term option) -> goal -> goal option =
57
- fun f g ->
58
- match g with
59
- | Typ gt ->
60
- begin
61
- match f (Env. to_ctxt gt.goal_hyps) gt.goal_type with
62
- | None -> None
63
- | Some goal_type -> Some (Typ {gt with goal_type})
64
- end
65
- | Unif (c ,t ,u ) ->
66
- begin
67
- match f c t, f c u with
68
- | Some t , Some u -> Some (Unif (c,t,u))
69
- | _ -> None
70
- end
71
-
72
- (* * [simpl f g] simplifies the goal [g] with the function [f]. *)
73
- let simpl : (ctxt -> term -> term) -> goal -> goal = fun f g ->
74
- match g with
75
- | Typ gt ->
76
- Typ {gt with goal_type = f (Env. to_ctxt gt.goal_hyps) gt.goal_type}
77
- | Unif (c ,t ,u ) -> Unif (c, f c t, f c u)
78
-
79
- (* * [hyps ppf g] prints on [ppf] the beta-normal forms of the hypotheses of
80
- the goal [g]. *)
81
- let hyps : int StrMap.t -> goal pp =
82
- let hyps elt ppf l =
83
- if l <> [] then
84
- out ppf " %a---------------------------------------------\
85
- ---------------------------------\n "
86
- (List. pp (fun ppf -> out ppf " %a\n " elt) " " ) (List. rev l)
87
- in
88
- fun idmap ppf g ->
89
- let term = term_in idmap in
90
- match g with
91
- | Typ gt ->
92
- let elt ppf (s ,(_ ,ty ,def )) =
93
- match def with
94
- | None -> out ppf " %a: %a" uid s term (Eval. snf_beta ty)
95
- | Some u -> out ppf " %a ≔ %a" uid s term u
96
- in
97
- hyps elt ppf gt.goal_hyps
98
- | Unif (c ,_ ,_ ) ->
99
- let elt ppf (x ,a ,t ) =
100
- out ppf " %a: %a" var x term a;
101
- match t with
102
- | None -> ()
103
- | Some t -> out ppf " ≔ %a" term t
104
- in
105
- hyps elt ppf c
106
-
107
- (* * [concl ppf g] prints on [ppf] the beta-normal form of the conclusion of
108
- the goal [g]. *)
109
- let concl : int StrMap.t -> goal pp = fun idmap ppf g ->
110
- let term = term_in idmap in
111
- match g with
112
- | Typ gt ->
113
- out ppf " ?%d: %a" gt.goal_meta.meta_key
114
- term (Eval. snf_beta gt.goal_type)
115
- | Unif (_ , t , u ) -> out ppf " %a ≡ %a" term t term u
116
-
117
- (* * [pp ppf g] prints on [ppf] the beta-normal form of the goal [g] with its
118
- hypotheses. *)
119
- let pp ppf g =
120
- let idmap = get_names g in hyps idmap ppf g; concl idmap ppf g
121
-
122
- (* * [pp_no_hyp ppf g] prints on [ppf] the beta-normal form of the conclusion
123
- of the goal [g] without its hypotheses. *)
124
- let pp_no_hyp ppf g = concl (get_names g) ppf g
125
-
126
- end
127
-
128
- (* * [add_goals_of_problem p gs] extends the list of goals [gs] with the
129
- metavariables and constraints of [p]. *)
130
- let add_goals_of_problem : problem -> goal list -> goal list = fun p gs ->
131
- let gs = MetaSet. fold (fun m gs -> Goal. of_meta m :: gs) ! p.metas gs in
132
- let f gs c = Unif c :: gs in
133
- let gs = List. fold_left f gs ! p.to_solve in
134
- List. fold_left f gs ! p.unsolved
7
+ open Goal
135
8
136
9
(* * Representation of the proof state of a theorem. *)
137
10
type proof_state =
@@ -149,7 +22,7 @@ let goals : proof_state pp = fun ppf ps ->
149
22
match ps.proof_goals with
150
23
| [] -> out ppf " No goal."
151
24
| g ::gs ->
152
- let idmap = get_names g in
25
+ let idmap = Goal. get_names g in
153
26
out ppf " %a0. %a" (Goal. hyps idmap) g (Goal. concl idmap) g;
154
27
let goal ppf i g = out ppf " \n %d. %a" (i+ 1 ) Goal. pp_no_hyp g in
155
28
List. iteri (goal ppf) gs
0 commit comments