Skip to content

Commit 12eccce

Browse files
committed
Setoid hell
1 parent cb119fa commit 12eccce

3 files changed

Lines changed: 337 additions & 71 deletions

File tree

theories/ListSelector.v

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,98 @@ Import ListNotations.
66
From Hammer Require Import
77
Tactics.
88

9+
Require Import Setoids.
10+
11+
Open Scope slot_scope.
12+
913
Section defn.
1014
Context {A : Type}.
1115

12-
Inductive Pick : list A -> A -> list A -> Prop :=
13-
| pick_this : forall a l,
14-
Pick (a :: l) a l
15-
| pick_next : forall a b l l',
16-
Pick l a l' ->
17-
Pick (b :: l) a (b :: l').
16+
Definition Pick (l : list A) a (l' : list A) : Prop :=
17+
Add a l' l.
18+
19+
(* Lemma permutation_split (a : A) l1 l2 : *)
20+
(* (a :: l1) =p= l2 -> *)
21+
(* exists l3 l4, *)
22+
(* l2 = (l3 ++ a :: l4). *)
23+
(* Admitted. *)
24+
25+
Lemma pick_equiv l1 l1' l2 a :
26+
l1 =p= l1' ->
27+
Pick l1 a l2 ->
28+
exists l2',
29+
Pick l1' a l2' /\ l2 =p= l2'.
30+
(* Proof. *)
31+
(* unfold Pick. intros Hl1 Hl2. *)
32+
(* generalize dependent l1'. *)
33+
34+
(* induction Hl2; intros l1' Hl1. *)
35+
(* - apply Permutation_in with (x := a) in Hl1 as Hl1'. *)
36+
(* + destruct (Add_inv a l1' Hl1') as [l2' Hl2']. *)
37+
(* exists l2'. split. *)
38+
(* * assumption. *)
39+
(* * apply Permutation_Add in Hl2'. *)
40+
(* rewrite <-Hl1 in Hl2'. *)
41+
(* now apply Permutation_cons_inv in Hl2'. *)
42+
(* + now constructor. *)
43+
(* - apply permutation_split in Hl1 as H. *)
44+
(* destruct H as [l3 [l4 Hl34]]. subst. *)
45+
(* rewrite <-Permutation_middle in Hl1. apply Permutation_cons_inv in Hl1. *)
46+
(* specialize (IHHl2 (l3 ++ l4) Hl1). *)
47+
(* destruct IHHl2 as [l5 [Hl5 Hll5]]. *)
48+
(* exists (x :: ). *)
49+
(* split. *)
50+
(* + *)
51+
(* exists (l3 ++ l4). *)
52+
53+
54+
55+
56+
57+
(* Search Permutation. *)
58+
(* induction Hl2. *)
59+
(* - apply Permutation_Add in Hl1. *)
60+
(* apply Permutation_Add in Hl2 as H. rewrite Hl1 in H. clear Hl1. *)
61+
62+
(* induction Hl1. *)
63+
(* 2:{ *)
64+
65+
66+
(* apply Add_split in Hl2. *)
67+
(* destruct Hl2 as [l3 [l4 [Hl3 Hl4]]]. subst. *)
68+
(* Check Permutation_Add. *)
69+
70+
(* induction l1'. *)
71+
(* - exfalso. inversion Hl1. *)
72+
(* now apply Permutation_sym, Permutation_nil_cons in Hl1. *)
73+
(* - *)
74+
(* Check Permutation_cons_app. *)
75+
76+
(* rewrite Permutation_middle in Hl1. *)
77+
(* Search Permutation. *)
78+
(* apply Permutation_cons_inv in H. *)
79+
80+
81+
(* replace (a :: l2) with ([] ++ a :: l2) in Hl1 by now rewrite <-app_nil_l. *)
82+
(* rewrite <-Permutation_middle in Hl1. *)
83+
(* Search Add. *)
84+
85+
(* (* intros Hl1 Hl2. *) *)
86+
(* apply pick_via_app in Hl2 as H. destruct H as [l3 [l4 Hl34]]. subst. *)
87+
(* rewrite <-Permutation_middle in Hl1. *)
88+
(* apply pick_via_permutation2 in Hl1 as Hl5. *)
89+
(* destruct Hl5 as [l5 Hl5]. *)
90+
(* exists l5. *)
91+
(* split. *)
92+
(* - assumption. *)
93+
(* - apply pick_via_permutation in Hl5. *)
94+
(* apply pick_via_permutation in Hl2. *)
95+
(* rewrite <-Permutation_middle in Hl2. *)
96+
(* apply Permutation_cons_inv in Hl2. *)
97+
(* rewrite Hl2. rewrite <-Hl1 in Hl5. *)
98+
(* now apply Permutation_cons_inv, Permutation_sym in Hl5. *)
99+
(* Qed. *)
100+
Admitted.
18101
End defn.
19102

20103
Section tests.

theories/Setoids.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ From Coq Require Import
88
From Hammer Require Import
99
Tactics.
1010

11+
From LibTx Require Import
12+
Storage.
13+
1114
Section pair.
1215
Context (A B : Type) `{Setoid A} `{Setoid B}.
1316

@@ -43,3 +46,6 @@ Section permutation.
4346
Global Program Instance setoid_permutation : Setoid (list T) | 10 :=
4447
{| equiv a b := Permutation a b |}.
4548
End permutation.
49+
50+
Infix "=p=" := (@equiv _ (setoid_permutation _)) (at level 50) : slot_scope.
51+
Infix "=s=" := (@equiv _ s_eq_setoid) (at level 50) : slot_scope.

0 commit comments

Comments
 (0)