@@ -54,8 +54,8 @@ Definition asort_ty :=
5454 seq T -> (* input *)
5555 R. (* output *)
5656
57- Parametricity sort_ty.
58- Parametricity asort_ty.
57+ Elpi derive.param2 sort_ty.
58+ Elpi derive.param2 asort_ty.
5959
6060Structure function := Pack {
6161 (* the sort function *)
@@ -255,7 +255,7 @@ Definition sort (T R : Type) (leT : rel T)
255255 (merge merge' : R -> R -> R) (singleton : T -> R) (empty : R) :=
256256 foldr (fun x => merge (singleton x)) empty.
257257
258- Parametricity sort.
258+ Elpi derive.param2 sort.
259259
260260End Abstract.
261261
@@ -350,27 +350,34 @@ Fixpoint sort3rec (stack : seq (option R)) (xs : seq T) : R :=
350350Definition sort3 : seq T -> R := sort3rec [::].
351351
352352Fixpoint sortNrec (stack : seq (option R)) (x : T) (xs : seq T) : R :=
353- if xs is y :: xs then
354- sortNrec' (leT x y) stack y xs (singleton x) else pop (singleton x) stack
355- with sortNrec' (incr : bool) (stack : seq (option R))
356- (x : T) (xs : seq T) (accu : R) : R :=
353+ let fix sortNrec' (incr : bool) (stack : seq (option R))
354+ (x : T) (xs : seq T) (accu : R) : R :=
357355 let accu' := (if incr then merge' else merge) accu (singleton x) in
358356 if xs is y :: xs then
359357 if eqb incr (leT x y) then
360358 sortNrec' incr stack y xs accu' else sortNrec (push accu' stack) y xs
361359 else
362- pop accu' stack.
360+ pop accu' stack
361+ in
362+ if xs is y :: xs then
363+ sortNrec' (leT x y) stack y xs (singleton x) else pop (singleton x) stack.
363364
364365#[using ="All "]
365366Definition sortN (xs : seq T) : R :=
366367 if xs is x :: xs then sortNrec [::] x xs else empty.
367368
368369End Abstract.
369370
370- Parametricity sort1.
371- Parametricity sort2.
372- Parametricity sort3.
373- Parametricity sortN.
371+ Elpi derive.param2 pop.
372+ Elpi derive.param2 push.
373+ Elpi derive.param2 sort1rec.
374+ Elpi derive.param2 sort1.
375+ Elpi derive.param2 sort2rec.
376+ Elpi derive.param2 sort2.
377+ Elpi derive.param2 sort3rec.
378+ Elpi derive.param2 sort3.
379+ Elpi derive.param2 sortNrec.
380+ Elpi derive.param2 sortN.
374381
375382End Abstract.
376383
@@ -512,13 +519,10 @@ case=> // x xs; have [n] := ubnP (size xs).
512519rewrite /Abstract.sortN /sortN -[Nil (option _)]/(astack_of_stack [::]).
513520elim: n (Nil (seq _)) x xs => // n IHn stack x [|y xs /= /ltnSE Hxs].
514521 by rewrite [LHS]apop_mergeE.
515- rewrite /Abstract.sortNrec -/(Abstract.sortNrec' _ _ _ _).
516522have {1}->: [:: x] = condrev (leT x y) [:: x] by rewrite [RHS]if_same.
517523move: xs Hxs x y (RS in x :: RS) {-2}(leT x y) (erefl (leT x y)).
518524elim=> [_|z xs IHxs /= /ltnW Hxs] x y rs incr incrE.
519- by rewrite /Abstract.sortNrec' apop_mergeE /= incrE mergeEcons; case: ifP.
520- rewrite /Abstract.sortNrec'.
521- rewrite -/(Abstract.sortNrec' _ _ _ _) -/(Abstract.sortNrec _ _ _ _).
525+ by rewrite apop_mergeE /= incrE mergeEcons; case: ifP.
522526rewrite eqbE incrE mergeEcons apush_mergeE ?condrev_nilp // IHn //.
523527by have [/[dup] /IHxs -> // ->|] := eqVneq; do 2?case: ifP.
524528Qed .
@@ -564,12 +568,9 @@ case=> // x xs; have [n] := ubnP (size xs).
564568rewrite /Abstract.sortN -[RHS]/(flatten_stack (x :: xs) [::]).
565569elim: n x (Nil (option _)) xs => // n IHn x stack [|y xs /= /ltnSE Hxs];
566570 first by rewrite [LHS]apop_catE.
567- rewrite /Abstract.sortNrec -/(Abstract.sortNrec' _ _ _ _).
568571pose rs := Nil T; rewrite -[x :: y :: _]/(rs ++ _) -[[:: x]]/(rs ++ _).
569572elim: xs Hxs x y rs => [_|z xs IHxs /= /ltnW Hxs] x y rs.
570573 by rewrite [LHS]apop_catE if_same -catA.
571- rewrite /Abstract.sortNrec'.
572- rewrite -/(Abstract.sortNrec' _ _ _ _) -/(Abstract.sortNrec _ _ _ _).
573574move: (IHxs Hxs y z (rcons rs x)).
574575by rewrite eqbE if_same IHn // apush_catE -cats1 -!catA; case: eqVneq => // ->.
575576Qed .
@@ -678,29 +679,36 @@ Fixpoint sort3rec (stack : seq (option R)) (xs : seq T) : R :=
678679Definition sort3 : seq T -> R := sort3rec [::].
679680
680681Fixpoint sortNrec (stack : seq (option R)) (x : T) (xs : seq T) : R :=
681- if xs is y :: xs then
682- sortNrec' (leT x y) stack y xs (singleton x)
683- else
684- pop false (singleton x) stack
685- with sortNrec' (incr : bool) (stack : seq (option R))
686- (x : T) (xs : seq T) (accu : R) : R :=
682+ let fix sortNrec' (incr : bool) (stack : seq (option R))
683+ (x : T) (xs : seq T) (accu : R) : R :=
687684 let accu' := (if incr then merge' else merge) accu (singleton x) in
688685 if xs is y :: xs then
689686 if eqb incr (leT x y) then
690687 sortNrec' incr stack y xs accu' else sortNrec (push accu' stack) y xs
691688 else
692- pop false accu' stack.
689+ pop false accu' stack
690+ in
691+ if xs is y :: xs then
692+ sortNrec' (leT x y) stack y xs (singleton x)
693+ else
694+ pop false (singleton x) stack.
693695
694696#[using ="All "]
695697Definition sortN (xs : seq T) : R :=
696698 if xs is x :: xs then sortNrec [::] x xs else empty.
697699
698700End Abstract.
699701
700- Parametricity sort1.
701- Parametricity sort2.
702- Parametricity sort3.
703- Parametricity sortN.
702+ Elpi derive.param2 pop.
703+ Elpi derive.param2 push.
704+ Elpi derive.param2 sort1rec.
705+ Elpi derive.param2 sort1.
706+ Elpi derive.param2 sort2rec.
707+ Elpi derive.param2 sort2.
708+ Elpi derive.param2 sort3rec.
709+ Elpi derive.param2 sort3.
710+ Elpi derive.param2 sortNrec.
711+ Elpi derive.param2 sortN.
704712
705713End Abstract.
706714
@@ -864,13 +872,10 @@ case=> // x xs; have [n] := ubnP (size xs).
864872rewrite /Abstract.sortN /sortN -[Nil (option _)]/(astack_of_stack false [::]).
865873elim: n (Nil (seq _)) x xs => // n IHn stack x [|y xs /= /ltnSE Hxs].
866874 by rewrite [LHS]apop_mergeE.
867- rewrite /Abstract.sortNrec -/(Abstract.sortNrec' _ _ _ _).
868875have {1}->: [:: x] = condrev (leT x y) [:: x] by rewrite [RHS]if_same.
869876move: xs Hxs x y (RS in x :: RS) {-2}(leT x y) (erefl (leT x y)).
870877elim=> [_|z xs IHxs /= /ltnW Hxs] x y rs incr incrE.
871- by rewrite /Abstract.sortNrec' apop_mergeE /= incrE mergeEcons; case: ifP.
872- rewrite /Abstract.sortNrec'.
873- rewrite -/(Abstract.sortNrec' _ _ _ _) -/(Abstract.sortNrec _ _ _ _).
878+ by rewrite apop_mergeE /= incrE mergeEcons; case: ifP.
874879rewrite eqbE incrE mergeEcons apush_mergeE ?condrev_nilp // IHn //.
875880by have [/[dup] /IHxs -> // ->|] := eqVneq; do 2?case: ifP.
876881Qed .
@@ -923,12 +928,9 @@ case=> // x xs; have [n] := ubnP (size xs).
923928rewrite /Abstract.sortN -[RHS]/(flatten_stack (x :: xs) [::]).
924929elim: n x (Nil (option _)) xs => // n IHn x stack [|y xs /= /ltnSE Hxs];
925930 first by rewrite [LHS]apop_catE.
926- rewrite /Abstract.sortNrec -/(Abstract.sortNrec' _ _ _ _).
927931pose rs := Nil T; rewrite -[x :: y :: _]/(rs ++ _) -[[:: x]]/(rs ++ _).
928932elim: xs Hxs x y rs => [_|z xs IHxs /= /ltnW Hxs] x y rs.
929933 by rewrite [LHS]apop_catE if_same -catA.
930- rewrite /Abstract.sortNrec'.
931- rewrite -/(Abstract.sortNrec' _ _ _ _) -/(Abstract.sortNrec _ _ _ _).
932934move: (IHxs Hxs y z (rcons rs x)).
933935by rewrite eqbE if_same IHn // apush_catE -cats1 -!catA; case: eqVneq => // ->.
934936Qed .
0 commit comments