| 1 |
/* rocq-elpi: Coq terms as the object language of elpi */ |
| 2 |
/* license: GNU Lesser General Public License Version 2.1 or later */ |
| 3 |
/* ------------------------------------------------------------------------- */ |
| 4 |
|
| 5 |
namespace paramX { |
| 6 |
|
| 7 |
func mk-trivial-match int, term, list term, term -> term. |
| 8 |
mk-trivial-match Rno (prod N T P) Args F (fun N T B) :- Rno >= 0, !, std.do! [ |
| 9 |
Rno' is Rno - 1, |
| 10 |
(pi x\ decl x N T => mk-trivial-match Rno' (P x) [x|Args] F (B x)), |
| 11 |
]. |
| 12 |
|
| 13 |
mk-trivial-match Rno Prod Args F R :- Rno >= 0, whd1 Prod Prod1, !, |
| 14 |
mk-trivial-match Rno Prod1 Args F R. |
| 15 |
|
| 16 |
mk-trivial-match -1 P RArgs F Match :- std.do! [ |
| 17 |
RArgs = [RecArg|ROtherArgs], |
| 18 |
(decl RecArg _ T, unwind {whd T []} Twhd), % unneeded with elpi 1.13.7 |
| 19 |
coq.safe-dest-app Twhd (global (indt I)) IndArgs, |
| 20 |
coq.env.indt I _ Lno _ _ _ _, |
| 21 |
std.drop Lno IndArgs RIndArgs, |
| 22 |
coq.build-match RecArg T |
| 23 |
(mk-trivial-match.rty {std.append RIndArgs [RecArg]} P) |
| 24 |
(mk-trivial-match.branch Lno RIndArgs {std.rev ROtherArgs} F) Match, |
| 25 |
]. |
| 26 |
|
| 27 |
func mk-trivial-match.rty list term, term, term, list term, list term -> term. |
| 28 |
mk-trivial-match.rty Args P _ Vars _ R :- std.do! [ |
| 29 |
std.map2 Args Vars (x\y\r\ r = copy x y) Subst, |
| 30 |
Subst =!=> copy P R, |
| 31 |
]. |
| 32 |
|
| 33 |
func mk-trivial-match.branch int, list term, list term, term, term, term, list term, list term -> term. |
| 34 |
mk-trivial-match.branch Lno Args OtherArgs F K KTy Vars _ R1 :- std.do! [ |
| 35 |
coq.mk-app K Vars KArgs, |
| 36 |
coq.safe-dest-app KTy _ KTyArgs, |
| 37 |
std.drop Lno KTyArgs IdxVals, |
| 38 |
std.map2 Args IdxVals (x\y\r\ r = copy x y) Subst, |
| 39 |
(R = let `K` KTy KArgs x\ {coq.mk-app F {std.append OtherArgs [x]}}), |
| 40 |
Subst =!=> copy R R1, |
| 41 |
]. |
| 42 |
|
| 43 |
|
| 44 |
% prove H G P finds a P : H => G |
| 45 |
func prove term, term -> term. |
| 46 |
func cross term. |
| 47 |
|
| 48 |
% prove-arg AppliedHyp AppliedGoal Argument ProofAppliedHyp Proof. |
| 49 |
func prove-arg term, term, term, term -> term. |
| 50 |
|
| 51 |
prove-arg X X _ P P :- !. |
| 52 |
|
| 53 |
prove-arg (app [H|Hs]) (app[G|Gs]) X PHX PGX :- |
| 54 |
std.appendR HArgs [X] Hs, !, coq.mk-app H HArgs Hyp, |
| 55 |
std.appendR GArgs [X] Gs, !, coq.mk-app G GArgs Goal, |
| 56 |
prove Hyp Goal Proof, |
| 57 |
coq.mk-app Proof [X,PHX] PGX. |
| 58 |
|
| 59 |
prove-arg (prod _ X x\ prod _ (PX x) (H x)) (prod _ _ y\ prod _ (PX y) (G y)) A PA (fun `x` X x\ fun `px` (PX x) (Proof x)) :- |
| 60 |
pi x px\ |
| 61 |
prove-arg (H x px) (G x px) {coq.mk-app A [x]} {coq.mk-app PA [x,px]} (Proof x px). |
| 62 |
|
| 63 |
func prove-args list term, list term -> list term. |
| 64 |
prove-args [] [] []. |
| 65 |
prove-args [X,Pr|Args] [_,PX|ArgsT] [X,Proof|QArgs] :- |
| 66 |
coq.safe-dest-app PX HD _, cross HD, !, |
| 67 |
copy PX Goal, |
| 68 |
(prove-arg PX Goal X Pr Proof ; Proof = Pr), !, |
| 69 |
prove-args Args ArgsT QArgs. |
| 70 |
prove-args [X|Args] [PX|ArgsT] [ProofX|QArgs] :- |
| 71 |
copy PX Goal, |
| 72 |
prove PX Goal Proof, !, |
| 73 |
coq.mk-app Proof [X] ProofX, |
| 74 |
prove-args Args ArgsT QArgs. |
| 75 |
prove-args [X|Args] [_|ArgsT] [X|QArgs] :- |
| 76 |
prove-args Args ArgsT QArgs. |
| 77 |
|
| 78 |
} |