Debian Codegraph @

src/Util/PointedProp.v

raw
1 (** * Propositions with a distinguished point representing true *)
2 (** This allows for something between [bool] and [Prop], where we can
3 computationally reduce things like [True /\ True], but can still
4 express equality of types. *)
5 From Coq Require Import Setoid.
6 Require Import Crypto.Util.Notations.
7
8 Declare Scope pointed_prop_scope.
9 Declare Scope option_pointed_prop_scope.
10 Delimit Scope pointed_prop_scope with pointed_prop.
11 Delimit Scope option_pointed_prop_scope with option_pointed_prop.
12 Inductive pointed_Prop := trivial | inject (_ : Prop).
13 Bind Scope pointed_prop_scope with pointed_Prop.
14
15 Definition to_prop (x : pointed_Prop) : Prop
16 := match x with
17 | trivial => True
18 | inject p => p
19 end.
20
21 Coercion option_pointed_Prop_of_bool (x : bool) : option pointed_Prop
22 := if x then Some trivial else None.
23 Coercion option_pointed_Prop_of_pointed_Prop (x : pointed_Prop) : option pointed_Prop
24 := Some x.
25
26 Definition prop_of_option (x : option pointed_Prop) : Prop
27 := match x with
28 | Some p => to_prop p
29 | None => False
30 end.
31
32 Definition and_pointed_Prop (x y : pointed_Prop) : pointed_Prop
33 := match x, y with
34 | trivial, y => y
35 | x, trivial => x
36 | inject p, inject q => inject (p /\ q)
37 end.
38
39 Definition or_pointed_Prop (x y : pointed_Prop) : pointed_Prop
40 := match x, y with
41 | trivial, _ => trivial
42 | _, trivial => trivial
43 | inject p, inject q => inject (p \/ q)
44 end.
45
46 Definition impl_pointed_Prop (x y : pointed_Prop) : pointed_Prop
47 := match x, y with
48 | trivial, y => y
49 | _, trivial => trivial
50 | inject p, inject q => inject (p -> q)
51 end.
52
53 Definition not_option_pointed_Prop (x : option pointed_Prop) : option pointed_Prop
54 := match x with
55 | Some trivial => None
56 | None => Some trivial
57 | Some (inject p) => Some (inject (~p))
58 end.
59 Arguments not_option_pointed_Prop _%option_pointed_prop.
60
61 Definition and_option_pointed_Prop (x y : option pointed_Prop) : option pointed_Prop
62 := match x, y with
63 | Some x, Some y => Some (and_pointed_Prop x y)
64 | _, _ => None
65 end.
66 Arguments and_option_pointed_Prop (_ _)%option_pointed_prop.
67
68 Definition or_option_pointed_Prop (x y : option pointed_Prop) : option pointed_Prop
69 := match x, y with
70 | Some x, Some y => Some (or_pointed_Prop x y)
71 | Some x, None => Some x
72 | None, Some y => Some y
73 | None, None => None
74 end.
75 Arguments or_option_pointed_Prop (_ _)%option_pointed_prop.
76
77 Definition impl_option_pointed_Prop (x y : option pointed_Prop) : option pointed_Prop
78 := match x, y with
79 | None, _ => Some trivial
80 | Some x, Some y => Some (impl_pointed_Prop x y)
81 | Some p, None => not_option_pointed_Prop p
82 end.
83 Arguments impl_option_pointed_Prop (_ _)%option_pointed_prop.
84
85 Infix "/\" := and_pointed_Prop : pointed_prop_scope.
86 Infix "\/" := or_pointed_Prop : pointed_prop_scope.
87 Infix "->" := impl_pointed_Prop : pointed_prop_scope.
88 Infix "/\" := and_option_pointed_Prop : option_pointed_prop_scope.
89 Infix "\/" := or_option_pointed_Prop : option_pointed_prop_scope.
90 Infix "->" := impl_option_pointed_Prop : option_pointed_prop_scope.
91 Notation "~ P" := (not_option_pointed_Prop P) : option_pointed_prop_scope.
92
93 Ltac inversion_pointed_Prop_step :=
94 match goal with
95 | [ H : inject _ = inject _ |- _ ] => progress (inversion H; clear H)
96 end.
97 Ltac inversion_pointed_Prop := repeat inversion_pointed_Prop_step.
98
99 Create HintDb push_prop_of_option discriminated.
100 Create HintDb push_to_prop discriminated.
101 Create HintDb push_eq_trivial discriminated.
102 Create HintDb push_eq_Some_trivial discriminated.
103 Global Hint Extern 1 => progress autorewrite with push_prop_of_option in * : push_prop_of_option.
104 Global Hint Extern 1 => progress autorewrite with push_to_prop in * : push_to_prop.
105 Global Hint Extern 1 => progress autorewrite with push_eq_trivial in * : push_eq_trivial.
106 Global Hint Extern 1 => progress autorewrite with push_eq_Some_trivial in * : push_eq_Some_trivial.
107
108 Lemma to_prop_and P Q : to_prop (P /\ Q)%pointed_prop
109 <-> (to_prop P /\ to_prop Q).
110 Proof. destruct P, Q; simpl; tauto. Qed.
111 #[global]
112 Hint Rewrite to_prop_and : push_to_prop.
113
114 Lemma to_prop_or P Q : to_prop (P \/ Q)%pointed_prop
115 <-> (to_prop P \/ to_prop Q).
116 Proof. destruct P, Q; simpl; tauto. Qed.
117 #[global]
118 Hint Rewrite to_prop_or : push_to_prop.
119
120 Lemma to_prop_impl P Q : to_prop (impl_pointed_Prop P Q)%pointed_prop
121 <-> (to_prop P -> to_prop Q).
122 Proof. destruct P, Q; simpl; tauto. Qed.
123 #[global]
124 Hint Rewrite to_prop_impl : push_to_prop.
125
126 Lemma prop_of_option_and P Q : prop_of_option (P /\ Q)%option_pointed_prop
127 <-> (prop_of_option P /\ prop_of_option Q).
128 Proof. destruct P, Q; simpl; autorewrite with push_to_prop; tauto. Qed.
129 #[global]
130 Hint Rewrite prop_of_option_and : push_prop_of_option.
131
132 Lemma prop_of_option_or P Q : prop_of_option (P \/ Q)%option_pointed_prop
133 <-> (prop_of_option P \/ prop_of_option Q).
134 Proof. destruct P, Q; simpl; autorewrite with push_to_prop; tauto. Qed.
135 #[global]
136 Hint Rewrite prop_of_option_or : push_prop_of_option.
137
138 Lemma prop_of_option_impl P Q : prop_of_option (impl_option_pointed_Prop P Q)%option_pointed_prop
139 <-> (prop_of_option P -> prop_of_option Q).
140 Proof. destruct P as [ [|P] |], Q as [ [|Q] |]; simpl; tauto. Qed.
141 #[global]
142 Hint Rewrite prop_of_option_impl : push_prop_of_option.
143
144 Lemma prop_of_option_not P : prop_of_option (~P)%option_pointed_prop
145 <-> (~prop_of_option P).
146 Proof. destruct P as [ [|] | ]; simpl; tauto. Qed.
147 #[global]
148 Hint Rewrite prop_of_option_not : push_prop_of_option.
149
150 Lemma eq_trivial_and P Q : (P /\ Q)%pointed_prop = trivial
151 <-> (P = trivial /\ Q = trivial).
152 Proof. destruct P, Q; simpl; intuition congruence. Qed.
153 #[global]
154 Hint Rewrite eq_trivial_and : push_eq_trivial.
155
156 Lemma eq_trivial_or P Q : (P \/ Q)%pointed_prop = trivial
157 <-> (P = trivial \/ Q = trivial).
158 Proof. destruct P, Q; simpl; intuition congruence. Qed.
159 #[global]
160 Hint Rewrite eq_trivial_or : push_eq_trivial.
161
162 Lemma eq_trivial_impl P Q : (impl_pointed_Prop P Q)%pointed_prop = trivial
163 <-> Q = trivial.
164 Proof. destruct P, Q; simpl; intuition congruence. Qed.
165 #[global]
166 Hint Rewrite eq_trivial_impl : push_eq_trivial.
167
168 Lemma eq_Some_trivial_and P Q : (P /\ Q)%option_pointed_prop = Some trivial
169 <-> (P = Some trivial /\ Q = Some trivial).
170 Proof. destruct P as [ []|], Q as [ []|]; simpl; intuition congruence. Qed.
171 #[global]
172 Hint Rewrite eq_Some_trivial_and : push_eq_Some_trivial.
173
174 Lemma eq_Some_trivial_or P Q : (P \/ Q)%option_pointed_prop = Some trivial
175 <-> (P = Some trivial \/ Q = Some trivial).
176 Proof. destruct P as [ []|], Q as [ []|]; simpl; intuition congruence. Qed.
177 #[global]
178 Hint Rewrite eq_Some_trivial_or : push_eq_Some_trivial.
179
180 Lemma eq_Some_trivial_impl P Q : (impl_option_pointed_Prop P Q)%option_pointed_prop = Some trivial
181 <-> (P = None \/ Q = Some trivial).
182 Proof. destruct P as [ [|P] |], Q as [ [|Q] |]; simpl; intuition congruence. Qed.
183 #[global]
184 Hint Rewrite eq_Some_trivial_impl : push_eq_Some_trivial.
185
186 Lemma eq_Some_trivial_not P : (~P)%option_pointed_prop = Some trivial
187 <-> P = None.
188 Proof. destruct P as [ [|] | ]; simpl; intuition congruence. Qed.
189 #[global]
190 Hint Rewrite eq_Some_trivial_not : push_eq_Some_trivial.