Skip to content

Commit 4806e94

Browse files
authored
Merge pull request jwiegley#106 from jwiegley/johnw/cartesian
2 parents 2809341 + 22da641 commit 4806e94

File tree

10 files changed

+1429
-578
lines changed

10 files changed

+1429
-578
lines changed

Instance/Lambda/Sem.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Fixpoint SemTy (τ : Ty) : Type :=
1919
| TyArrow dom cod => SemTy dom → SemTy cod
2020
end.
2121

22-
Definition SemEnv Γ : Type := ilist SemTy Γ.
22+
Definition SemEnv Γ : Type := ilist (B:=SemTy) Γ.
2323

2424
Fixpoint SemVar `(v : Var Γ τ) : SemEnv Γ → SemTy τ :=
2525
match v with

Lib/IList.v

+56-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,69 @@ Import ListNotations.
1111
Section ilist.
1212

1313
Context {A : Type}.
14-
15-
Variable B : A → Type.
14+
Context {B : A → Type}.
1615

1716
Fixpoint ilist (l : list A) : Type :=
1817
match l with
1918
| [] => unit
2019
| x :: xs => B x * ilist xs
2120
end.
2221

22+
Definition icons
23+
(a : A)
24+
{l : list A}
25+
(b : B a)
26+
(il : ilist l) : ilist (a :: l) :=
27+
(b, il).
28+
29+
Definition inil : ilist [] := tt.
30+
31+
(* Get the car of an ilist. *)
32+
Definition ilist_hd {As : list A} (il : ilist As) :
33+
match As return ilist As → Type with
34+
| a :: As' => fun il => B a
35+
| [] => fun _ => unit
36+
end il :=
37+
match As return
38+
∀ (il : ilist As),
39+
match As return ilist As → Type with
40+
| a :: As' => fun il => B a
41+
| [] => fun _ => unit
42+
end il with
43+
| a :: As => fun il => fst il
44+
| [] => fun il => tt
45+
end il.
46+
47+
(* Get the cdr of an ilist. *)
48+
Definition ilist_tl {As : list A} (il : ilist As) :
49+
match As return ilist As → Type with
50+
| a :: As' => fun il => ilist As'
51+
| [] => fun _ => unit
52+
end il :=
53+
match As return
54+
∀ (il : ilist As),
55+
match As return ilist As → Type with
56+
| a :: As' => fun il => ilist As'
57+
| [] => fun _ => unit
58+
end il with
59+
| a :: As => fun il => snd il
60+
| [] => fun il => tt
61+
end il.
62+
63+
Definition ith (n : nat) {As : list A} (il : ilist As)
64+
{defA : A} (defB : B defA) : B (nth n As defA).
65+
Proof.
66+
generalize dependent As.
67+
induction n; intros.
68+
- destruct As; simpl.
69+
+ exact defB.
70+
+ exact (fst il).
71+
- destruct As; simpl.
72+
+ exact defB.
73+
+ apply IHn.
74+
exact (snd il).
75+
Defined.
76+
2377
Equations iapp `(xs : ilist l) `(ys : ilist l') : ilist (l ++ l') :=
2478
iapp (l:=[]) tt ys := ys;
2579
iapp (x, xs) ys := (x, iapp xs ys).

Lib/IListVec.v

-134
This file was deleted.

Solver.v

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
Require Export Category.Solver.Reify.
12
Require Export Category.Solver.Normal.
23
Require Export Category.Solver.Decide.

Solver/Decide.v

+48-65
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
From Equations Require Import Equations.
2-
Set Equations With UIP.
3-
41
Require Import Category.Lib.
52
Require Import Category.Theory.Category.
3+
Require Import Category.Structure.Cartesian.
64
Require Import Category.Solver.Expr.
75
Require Import Category.Solver.Denote.
86
Require Import Category.Solver.Reify.
@@ -12,7 +10,7 @@ Generalizable All Variables.
1210

1311
Section Decide.
1412

15-
Context `{Env}.
13+
Context `{Arrows}.
1614

1715
(** This code is from Certified Programming with Dependent Types (CPDT). *)
1816

@@ -34,89 +32,74 @@ Notation "'Reduce' v" := (if v then Yes else No) (at level 100) : partial_scope.
3432
Notation "x || y" := (if x then Yes else Reduce y) : partial_scope.
3533
Notation "x && y" := (if x then Reduce y else No) : partial_scope.
3634

37-
Program Fixpoint sexpr_forward (t : SExpr) (hyp : SExpr)
38-
(cont : [sexprD t]) :
39-
[sexprD hyp → sexprD t] :=
35+
Program Fixpoint expr_forward (t : Expr) (hyp : Expr)
36+
(cont : [exprD t]) :
37+
[exprD hyp → exprD t] :=
4038
match hyp with
41-
| STop => Reduce cont
42-
| SBottom => Yes
43-
| SEquiv x y f g => Reduce cont
44-
| SAnd p q => Reduce cont
45-
| SOr p q => if sexpr_forward t p cont
46-
then Reduce (sexpr_forward t q cont)
47-
else No
48-
| SImpl _ _ => Reduce cont
39+
| Top => Reduce cont
40+
| Bottom => Yes
41+
| Equiv x y f g => Reduce cont
42+
| And p q => Reduce cont
43+
| Or p q => if expr_forward t p cont
44+
then Reduce (expr_forward t q cont)
45+
else No
46+
| Impl _ _ => Reduce cont
4947
end.
5048
Next Obligation. tauto. Defined.
51-
Next Obligation. intuition. Defined.
5249

53-
Program Fixpoint sexpr_backward (t : SExpr) {measure t SExpr_subterm} :
54-
[sexprD t] :=
50+
#[local] Obligation Tactic := cat_simpl; intuition.
51+
52+
Program Fixpoint expr_backward (t : Expr) {measure t Expr_subterm} :
53+
[exprD t] :=
5554
match t with
56-
| STop => Yes
57-
| SBottom => No
58-
| SEquiv x y f g => _
59-
| SAnd p q =>
60-
match sexpr_backward p with
61-
| Proved _ _ => Reduce (sexpr_backward q)
62-
| Uncertain _ => No
63-
end
64-
| SOr p q =>
65-
match sexpr_backward p with
66-
| Proved _ _ => Yes
67-
| Uncertain _ => Reduce (sexpr_backward q)
68-
end
69-
| SImpl p q =>
70-
sexpr_forward q p (sexpr_backward q)
55+
| Top => Yes
56+
| Bottom => No
57+
| Equiv x y f g => _
58+
| And p q => expr_backward p && expr_backward q
59+
| Or p q => expr_backward p || expr_backward q
60+
| Impl p q => expr_forward q p (expr_backward q)
7161
end.
7262
Next Obligation.
73-
destruct (list_eqdec _ (sindices f) (sindices g)) eqn:?;
63+
destruct (morphism_eq_dec (to_morphism f) (to_morphism g)) eqn:?;
7464
[|apply Uncertain].
75-
destruct (Pos_to_fin _); [|apply Uncertain].
76-
destruct (Pos_to_fin _); [|apply Uncertain].
77-
destruct (stermD _ _ f) eqn:?; [|apply Uncertain].
78-
destruct (stermD _ _ g) eqn:?; [|apply Uncertain].
65+
destruct (termD _ _ f) eqn:?; [|apply Uncertain].
66+
destruct (termD _ _ g) eqn:?; [|apply Uncertain].
7967
apply Proved.
80-
apply unsindices_sindices_r in Heqo.
81-
apply unsindices_sindices_r in Heqo0.
68+
apply from_morphism_to_morphism_r in Heqo.
69+
apply from_morphism_to_morphism_r in Heqo0.
8270
rewrite e in Heqo.
8371
rewrite Heqo in Heqo0.
8472
now simpl in Heqo0.
8573
Defined.
86-
Next Obligation. intuition. Defined.
87-
Next Obligation. intuition. Defined.
88-
Next Obligation. intuition. Defined.
89-
Next Obligation. intuition. Defined.
90-
Next Obligation. intuition. Defined.
91-
Next Obligation. apply well_founded_SExpr_subterm. Defined.
74+
Next Obligation. apply well_founded_Expr_subterm. Defined.
9275

93-
Definition sexpr_tauto : ∀ t, [sexprD t].
94-
Proof. intros; refine (Reduce (sexpr_backward t)); auto. Defined.
76+
Definition expr_tauto : ∀ t, [exprD t].
77+
Proof. intros; refine (Reduce (expr_backward t)); auto. Defined.
9578

96-
Lemma sexpr_sound t :
97-
(if sexpr_tauto t then True else False) → sexprD t.
98-
Proof. unfold sexpr_tauto; destruct t, (sexpr_backward _); tauto. Qed.
79+
Lemma expr_sound t :
80+
(if expr_tauto t then True else False) → exprD t.
81+
Proof. unfold expr_tauto; destruct t, (expr_backward _); tauto. Qed.
9982

10083
End Decide.
10184

10285
Ltac categorical := reify_terms_and_then
10386
ltac:(fun env g =>
104-
change (@sexprD env g);
105-
apply sexpr_sound;
87+
change (@exprD env g);
88+
apply expr_sound;
10689
now vm_compute).
10790

108-
Example sample_1 :
109-
∀ (C : Category) (x y z w : C) (f : z ~> w) (g : y ~> z) (h : x ~> y) (i : x ~> z),
110-
g ∘ id ∘ id ∘ id ∘ h ≈ i ->
111-
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
112-
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
113-
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
114-
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
115-
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
116-
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
117-
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
118-
g ∘ h ≈ i ->
119-
f ∘ (id ∘ g ∘ h) ≈ (f ∘ g) ∘ h.
91+
Example ex_categorical (C : Category) `{@Cartesian C} (x y z w : C)
92+
(f : z ~> w) (g : y ~> z) (h : x ~> y) (i : x ~> z) :
93+
g ∘ id ∘ id ∘ id ∘ h ≈ i ->
94+
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
95+
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
96+
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
97+
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
98+
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
99+
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
100+
g ∘ id ∘ id ∘ id ∘ h ≈ g ∘ h ->
101+
g ∘ h ≈ i ->
102+
f ∘ (id ∘ g ∘ h) ≈ (f ∘ g) ∘ h.
120103
Proof.
121104
intros.
122105
now categorical.

0 commit comments

Comments
 (0)