Skip to content

Commit e553ce9

Browse files
committed
Simple tactics in proof-terms.
Simple tactics (//, //#, /#) can now been used in proof-terms.
1 parent 18c8fd1 commit e553ce9

13 files changed

Lines changed: 173 additions & 79 deletions

src/ecCoreGoal.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ type proofterm =
4848
| PTQuant of binding * proofterm
4949

5050
and pt_head =
51-
| PTCut of EcFol.form
51+
| PTCut of EcFol.form * cutsolve option
5252
| PTHandle of handle
5353
| PTLocal of EcIdent.t
5454
| PTGlobal of EcPath.path * (ty list)
5555
| PTTerm of proofterm
5656

57+
and cutsolve = [`Done | `Smt | `DoneSmt]
58+
5759
and pt_arg =
5860
| PAFormula of EcFol.form
5961
| PAMemory of EcMemory.memory
@@ -88,8 +90,8 @@ let ptlocal ?(args = []) x =
8890
let pthandle ?(args = []) x =
8991
PTApply { pt_head = PTHandle x; pt_args = args; }
9092

91-
let ptcut ?(args = []) f =
92-
PTApply { pt_head = PTCut f; pt_args = args; }
93+
let ptcut ?(args = []) ?(cutsolve : cutsolve option) f =
94+
PTApply { pt_head = PTCut (f, cutsolve); pt_args = args; }
9395

9496
(* -------------------------------------------------------------------- *)
9597
let paglobal ?args ~tys p =

src/ecCoreGoal.mli

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ type proofterm =
5050
| PTQuant of binding * proofterm
5151

5252
and pt_head =
53-
| PTCut of EcFol.form
53+
| PTCut of EcFol.form * cutsolve option
5454
| PTHandle of handle
5555
| PTLocal of EcIdent.t
5656
| PTGlobal of EcPath.path * (ty list)
5757
| PTTerm of proofterm
5858

59+
and cutsolve = [`Done | `Smt | `DoneSmt]
60+
5961
and pt_arg =
6062
| PAFormula of EcFol.form
6163
| PAMemory of EcMemory.memory
@@ -88,7 +90,7 @@ val pahandle : ?args:pt_arg list -> handle -> pt_arg
8890
val ptglobal : ?args:pt_arg list -> tys:ty list -> EcPath.path -> proofterm
8991
val ptlocal : ?args:pt_arg list -> EcIdent.t -> proofterm
9092
val pthandle : ?args:pt_arg list -> handle -> proofterm
91-
val ptcut : ?args:pt_arg list -> EcFol.form -> proofterm
93+
val ptcut : ?args:pt_arg list -> ?cutsolve:cutsolve -> EcFol.form -> proofterm
9294

9395
(* -------------------------------------------------------------------- *)
9496
val ptapply : proofterm -> pt_arg list -> proofterm

src/ecHiGoal.ml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module LG = EcCoreLib.CI_Logic
2828

2929
(* -------------------------------------------------------------------- *)
3030
type ttenv = {
31-
tt_provers : EcParsetree.pprover_infos -> EcProvers.prover_infos;
31+
tt_provers : EcParsetree.pprover_infos option -> EcProvers.prover_infos;
3232
tt_smtmode : [`Admit | `Strict | `Sloppy | `Report];
3333
tt_implicits : bool;
3434
tt_oldip : bool;
@@ -150,7 +150,7 @@ let process_smt ?loc (ttenv : ttenv) pi (tc : tcenv1) =
150150
(* -------------------------------------------------------------------- *)
151151

152152
let process_coq ~loc ~name (ttenv : ttenv) coqmode pi (tc : tcenv1) =
153-
let pi = ttenv.tt_provers pi in
153+
let pi = ttenv.tt_provers (Some pi) in
154154

155155
match ttenv.tt_smtmode with
156156
| `Admit ->
@@ -841,7 +841,7 @@ let process_rewrite1_r ttenv ?target ri tc =
841841
ptenv.pte_ev := MEV.add x `Form !(ptenv.pte_ev)
842842
);
843843

844-
let pt = PTApply { pt_head = PTCut f; pt_args = []; } in
844+
let pt = PTApply { pt_head = PTCut (f, None); pt_args = []; } in
845845
let pt = { ptev_env = ptenv; ptev_pt = pt; ptev_ax = f; } in
846846

847847
process_rewrite1_core ~mode ?target (theside, prw, o) pt tc
@@ -872,10 +872,10 @@ let process_rewrite1_r ttenv ?target ri tc =
872872
end
873873

874874
| RWSmt (false, info) ->
875-
process_smt ~loc:ri.pl_loc ttenv info tc
875+
process_smt ~loc:ri.pl_loc ttenv (Some info) tc
876876

877877
| RWSmt (true, info) ->
878-
t_or process_done (process_smt ~loc:ri.pl_loc ttenv info) tc
878+
t_or process_done (process_smt ~loc:ri.pl_loc ttenv (Some info)) tc
879879

880880
| RWApp fp -> begin
881881
let implicits = ttenv.tt_implicits in
@@ -1404,10 +1404,10 @@ let rec process_mintros_1 ?(cf = true) ttenv pis gs =
14041404
| None -> process_trivial
14051405
in t tc
14061406

1407-
and intro1_smt (_ : ST.state) ((dn, pi) : _ * pprover_infos) (tc : tcenv1) =
1407+
and intro1_smt (_ : ST.state) (dn : bool) (pi : pprover_infos) (tc : tcenv1) =
14081408
if dn then
1409-
t_or process_done (process_smt ttenv pi) tc
1410-
else process_smt ttenv pi tc
1409+
t_or process_done (process_smt ttenv (Some pi)) tc
1410+
else process_smt ttenv (Some pi) tc
14111411

14121412
and intro1_simplify (_ : ST.state) logic tc =
14131413
t_simplify_lg ~delta:`IfApplied (ttenv, logic) tc
@@ -1575,8 +1575,8 @@ let rec process_mintros_1 ?(cf = true) ttenv pis gs =
15751575
| `Done b ->
15761576
(nointro, rl (t_onall (intro1_done st b)) gs)
15771577

1578-
| `Smt pi ->
1579-
(nointro, rl (t_onall (intro1_smt st pi)) gs)
1578+
| `Smt (b, pi) ->
1579+
(nointro, rl (t_onall (intro1_smt st b pi)) gs)
15801580

15811581
| `Simpl b ->
15821582
(nointro, rl (t_onall (intro1_simplify st b)) gs)
@@ -1938,6 +1938,9 @@ let process_cut ?(mode = `Have) engine ttenv ((ip, phi, t) : cut_t) tc =
19381938
(* -------------------------------------------------------------------- *)
19391939
type cutdef_t = intropattern * pcutdef
19401940

1941+
let cutsolver (ttenv : ttenv) =
1942+
{ smt = process_smt ttenv None; done_ = process_trivial; }
1943+
19411944
let process_cutdef ttenv (ip, pt) (tc : tcenv1) =
19421945
let pt = {
19431946
fp_mode = `Implicit;
@@ -1953,7 +1956,7 @@ let process_cutdef ttenv (ip, pt) (tc : tcenv1) =
19531956
let pt, ax = PT.concretize pt in
19541957

19551958
FApi.t_sub
1956-
[EcLowGoal.t_apply pt; process_intros_1 ttenv ip]
1959+
[EcLowGoal.t_apply ~cutsolver:(cutsolver ttenv) pt; process_intros_1 ttenv ip]
19571960
(t_cut ax tc)
19581961

19591962
(* -------------------------------------------------------------------- *)

src/ecHiGoal.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ open EcProofTerm
99

1010
(* -------------------------------------------------------------------- *)
1111
type ttenv = {
12-
tt_provers : EcParsetree.pprover_infos -> EcProvers.prover_infos;
12+
tt_provers : EcParsetree.pprover_infos option -> EcProvers.prover_infos;
1313
tt_smtmode : [`Admit | `Strict | `Sloppy | `Report];
1414
tt_implicits : bool;
1515
tt_oldip : bool;
@@ -72,7 +72,7 @@ val process_genintros : ?cf:bool -> ttenv -> introgenpattern list -> backward
7272
val process_generalize : ?doeq:bool -> genpattern list -> backward
7373
val process_move : ?doeq:bool -> ppterm list -> prevert -> backward
7474
val process_clear : psymbol list -> backward
75-
val process_smt : ?loc:EcLocation.t -> ttenv -> pprover_infos -> backward
75+
val process_smt : ?loc:EcLocation.t -> ttenv -> pprover_infos option -> backward
7676
val process_coq : loc:EcLocation.t -> name:string -> ttenv -> EcProvers.coq_mode option -> pprover_infos -> backward
7777
val process_apply : implicits:bool -> apply_t * prevert option -> backward
7878
val process_delta : und_delta:bool -> ?target:psymbol -> (rwside * rwocc * pformula) -> backward

src/ecHiTacticals.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ and process1_logic (ttenv : ttenv) (t : logtactic located) (tc : tcenv1) =
128128
match unloc t with
129129
| Preflexivity -> process_reflexivity
130130
| Passumption -> process_assumption
131-
| Psmt pi -> process_smt ~loc:(loc t) ttenv pi
131+
| Psmt pi -> process_smt ~loc:(loc t) ttenv (Some pi)
132132
| Psplit -> process_split
133133
| Pfield st -> process_algebra `Solve `Field st
134134
| Pring st -> process_algebra `Solve `Ring st

src/ecLowGoal.ml

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(* -------------------------------------------------------------------- *)
22
open EcUtils
3+
open EcMaps
34
open EcLocation
45
open EcIdent
56
open EcSymbols
@@ -99,17 +100,21 @@ module LowApply = struct
99100
in List.for_all h_eqs ld1.h_local
100101

101102
(* ------------------------------------------------------------------ *)
102-
let rec check_pthead (pt : pt_head) (tc : ckenv) =
103+
let rec check_pthead (pt : pt_head) (subgoals : _) (tc : ckenv) =
103104
let hyps = hyps_of_ckenv tc in
104105

105106
match pt with
106-
| PTCut f -> begin
107+
| PTCut (f, cutsolve) -> begin
107108
match tc with
108-
| `Hyps ( _, _) -> (PTCut f, f)
109+
| `Hyps ( _, _) -> (PTCut (f, None), f, subgoals) (* FIXME *)
109110
| `Tc (tc, _) ->
110111
(* cut - create a dedicated subgoal *)
111112
let handle = RApi.newgoal tc ~hyps f in
112-
(PTHandle handle, f)
113+
let subgoals =
114+
ofold
115+
(fun cutsolve subgoals -> DMap.add handle cutsolve subgoals)
116+
subgoals cutsolve
117+
in (PTHandle handle, f, subgoals)
113118
end
114119

115120
| PTHandle hd -> begin
@@ -121,38 +126,38 @@ module LowApply = struct
121126
(* proof reuse - fetch corresponding subgoal*)
122127
if not (sub_hyps subgoal.g_hyps (hyps_of_ckenv tc)) then
123128
raise InvalidProofTerm;
124-
(pt, subgoal.g_concl)
129+
(pt, subgoal.g_concl, subgoals)
125130
end
126131

127132
| PTLocal x -> begin
128133
let hyps = hyps_of_ckenv tc in
129-
try (pt, LDecl.hyp_by_id x hyps)
134+
try (pt, LDecl.hyp_by_id x hyps, subgoals)
130135
with LDecl.LdeclError _ -> raise InvalidProofTerm
131136
end
132137

133138
| PTGlobal (p, tys) ->
134139
(* FIXME: poor API ==> poor error recovery *)
135140
let env = LDecl.toenv (hyps_of_ckenv tc) in
136-
(pt, EcEnv.Ax.instanciate p tys env)
141+
(pt, EcEnv.Ax.instanciate p tys env, subgoals)
137142

138143
| PTTerm pt ->
139-
let pt, ax = check `Elim pt tc in
140-
(PTTerm pt, ax)
144+
let pt, ax, subgoals = check_ `Elim pt subgoals tc in
145+
(PTTerm pt, ax, subgoals)
141146

142147
(* ------------------------------------------------------------------ *)
143-
and check (mode : [`Intro | `Elim]) (pt : proofterm) (tc : ckenv) =
148+
and check_ (mode : [`Intro | `Elim]) (pt : proofterm) (subgoals : _) (tc : ckenv) =
144149
let hyps = hyps_of_ckenv tc in
145150
let env = LDecl.toenv hyps in
146151

147-
let rec check_args (sbt, ax, nargs) args =
152+
let rec check_args (sbt, ax, nargs) subgoals args =
148153
match args with
149-
| [] -> (Fsubst.f_subst sbt ax, List.rev nargs)
154+
| [] -> (Fsubst.f_subst sbt ax, List.rev nargs, subgoals)
150155

151156
| arg :: args ->
152-
let ((sbt, ax), narg) = check_arg (sbt, ax) arg in
153-
check_args (sbt, ax, narg :: nargs) args
157+
let ((sbt, ax), narg, subgoals) = check_arg (sbt, ax) subgoals arg in
158+
check_args (sbt, ax, narg :: nargs) subgoals args
154159

155-
and check_arg (sbt, ax) arg =
160+
and check_arg (sbt, ax) subgoals arg =
156161
let check_binder (x, xty) f =
157162
let xty = Fsubst.gty_subst sbt xty in
158163

@@ -186,43 +191,53 @@ module LowApply = struct
186191
| None -> EcCoreGoal.ptcut f1
187192
| Some subpt -> subpt
188193
in
189-
let subpt, subax = check mode subpt tc in
194+
let subpt, subax, subgoals = check_ mode subpt subgoals tc in
190195
if not (EcReduction.is_conv hyps f1 subax) then
191196
raise InvalidProofTerm;
192-
((sbt, f2), PASub (Some subpt))
197+
((sbt, f2), PASub (Some subpt), subgoals)
193198

194199
| Some (`Forall (x, xty, f)), _ ->
195-
(check_binder (x, xty) f, arg)
200+
(check_binder (x, xty) f, arg, subgoals)
196201

197202
| _, _ ->
198203
if Fsubst.is_subst_id sbt then
199204
raise InvalidProofTerm;
200-
check_arg (Fsubst.f_subst_id, Fsubst.f_subst sbt ax) arg
205+
check_arg (Fsubst.f_subst_id, Fsubst.f_subst sbt ax) subgoals arg
201206
end
202207

203208
| `Intro -> begin
204209
match TTC.destruct_exists hyps ax with
205-
| Some (`Exists (x, xty, f)) -> (check_binder (x, xty) f, arg)
210+
| Some (`Exists (x, xty, f)) ->
211+
(check_binder (x, xty) f, arg, subgoals)
206212
| None ->
207213
if Fsubst.is_subst_id sbt then
208214
raise InvalidProofTerm;
209-
check_arg (Fsubst.f_subst_id, Fsubst.f_subst sbt ax) arg
215+
check_arg (Fsubst.f_subst_id, Fsubst.f_subst sbt ax) subgoals arg
210216
end
211217
in
212218

213219
match pt with
214220
| PTApply pt ->
215-
let (nhd, ax) = check_pthead pt.pt_head tc in
216-
let ax, nargs = check_args (Fsubst.f_subst_id, ax, []) pt.pt_args in
217-
(PTApply { pt_head = nhd; pt_args = nargs }, ax)
221+
let (nhd, ax, subgoals) = check_pthead pt.pt_head subgoals tc in
222+
let ax, nargs, subgoals =
223+
check_args (Fsubst.f_subst_id, ax, []) subgoals pt.pt_args in
224+
(PTApply { pt_head = nhd; pt_args = nargs }, ax, subgoals)
218225

219226
| PTQuant (bd, pt) -> begin
220227
match mode with
221228
| `Intro -> raise InvalidProofTerm
222229
| `Elim ->
223-
let pt, ax = check `Elim pt tc in
224-
(PTQuant (bd, pt), f_forall [bd] ax)
230+
let pt, ax, subgoals = check_ `Elim pt subgoals tc in
231+
(PTQuant (bd, pt), f_forall [bd] ax, subgoals)
225232
end
233+
234+
let check_with_cutsolve (mode : [`Intro | `Elim]) (pt : proofterm) (tc : ckenv) =
235+
check_ mode pt DMap.empty tc
236+
237+
let check (mode : [`Intro | `Elim]) (pt : proofterm) (tc : ckenv) =
238+
let pt, f, subgoals = check_ mode pt DMap.empty tc in
239+
assert (DMap.is_empty subgoals);
240+
(pt, f)
226241
end
227242

228243
(* -------------------------------------------------------------------- *)
@@ -619,10 +634,16 @@ let t_intro_sx_seq id tt tc =
619634
FApi.t_focus (tt id) tc
620635

621636
(* -------------------------------------------------------------------- *)
622-
let tt_apply (pt : proofterm) (tc : tcenv) =
637+
type cutsolver = {
638+
smt : FApi.backward;
639+
done_ : FApi.backward;
640+
}
641+
642+
(* -------------------------------------------------------------------- *)
643+
let tt_apply ?(cutsolver : cutsolver option) (pt : proofterm) (tc : tcenv) =
623644
let (hyps, concl) = FApi.tc_flat tc in
624-
let tc, (pt, ax) =
625-
RApi.to_pure (fun tc -> LowApply.check `Elim pt (`Tc (tc, None))) tc in
645+
let tc, (pt, ax, subgoals) =
646+
RApi.to_pure (fun tc -> LowApply.check_with_cutsolve `Elim pt (`Tc (tc, None))) tc in
626647

627648
if not (EcReduction.is_conv hyps ax concl) then begin
628649
(*
@@ -636,7 +657,25 @@ let tt_apply (pt : proofterm) (tc : tcenv) =
636657
raise InvalidGoalShape
637658
end;
638659

639-
FApi.close tc (VApply pt)
660+
let tc = FApi.close tc (VApply pt) in
661+
662+
match cutsolver with
663+
| None ->
664+
assert (DMap.is_empty subgoals);
665+
tc
666+
667+
| Some cutsolver -> begin
668+
Format.eprintf "%d@." (DMap.cardinal subgoals);
669+
FApi.t_onall (fun tc ->
670+
let tactic =
671+
match DMap.find_opt (FApi.tc1_handle tc) subgoals with
672+
| Some `Smt -> cutsolver.smt
673+
| Some `Done -> cutsolver.done_
674+
| Some `DoneSmt -> FApi.t_seq cutsolver.done_ cutsolver.smt
675+
| None -> t_id in
676+
tactic tc
677+
) tc
678+
end
640679

641680
(* -------------------------------------------------------------------- *)
642681
let tt_apply_hyp (x : EcIdent.t) ?(args = []) ?(sk = 0) tc =
@@ -663,8 +702,8 @@ let tt_apply_hd (hd : handle) ?(args = []) ?(sk = 0) tc =
663702
tt_apply pt tc
664703

665704
(* -------------------------------------------------------------------- *)
666-
let t_apply (pt : proofterm) (tc : tcenv1) =
667-
tt_apply pt (FApi.tcenv_of_tcenv1 tc)
705+
let t_apply ?(cutsolver : cutsolver option) (pt : proofterm) (tc : tcenv1) =
706+
tt_apply ?cutsolver pt (FApi.tcenv_of_tcenv1 tc)
668707

669708
(* -------------------------------------------------------------------- *)
670709
let t_apply_hyp (x : EcIdent.t) ?args ?sk tc =

0 commit comments

Comments
 (0)