: reflect P b <-> (if b then P else ~ P). Proof. split. - intros H. (* -> *) case H. (* H : reflect P b *) + intros HP. (* P -> P *) apply HP. + intros HnP. (* ~ P -> ~ P *) apply HnP. - case b. (* <- *) + intro HP. (* P -> reflect P true *) apply ReflectT. apply HP. + intro HnP. (* ~ P -> reflect P false *) apply ReflectF. apply HnP. Qed.
:= EqMixin { op : T -> T -> bool; (* boolࣜɹ*) a : forall x y :ɹT, (* ূ໌ɹ*) reflect (x = y) (op x y) }. Record eqType := EqType { sort : Type; m : mixin_of sort }.
: forall {P : Prop}{b : bool}, reflect P b -> b -> P. • elimT eqP : x == y -> x = y ᶄ Leibnizಉཱ͕ؔ͢ΔͳΒɺboolཱ͕ࣜ͢Δɻ Lemma introT : forall {P : Prop}{b : bool}, reflect P b -> P -> b. • introT eqP : x = y -> x == y ᶅ introTFɺelimTFɺequivPif
updown) : reflect (x = y) (eqUD x y). Proof. apply (iffP idP). - case x; case y; auto. (* eqUD x y -> x = y *) - case x; case y; auto. (* x = y -> eqUD x y *) Qed. ɾ updown_eqPΛͬͯɺeqTypeܕ͔Βɺupdown_eqTypeܕΛ࡞Δɻ Definition updown_eqMixin := @EqMixin updown eqUD updown_eqP. Definition updown_eqType := @EqType updown updown_eqMixin. ɾ͔͠͠ɾɾɾ Fail Check eq_op up up. Fail Check up == up.
updown H : (ུ) ============== x = y apply (elimT eqP). x : updown y : updown H : (ུ) ============== x == y ΰʔϧʢલʣ λΫςΟΫ ΰʔϧʢޙʣ x : updown y : updown H : (ུ) ============== x == y apply (introT eqP). x : updown y : updown H : (ུ) ============== x = y
== y) = (y == x). Proof. apply (introTF eqP). apply (equivPif eqP); auto. Qed. ࠷ॳͷΰʔϧͷʮ=ʯͷ྆ลboolͰ͋Δɻ ͜ΕΛʮ<->ʯʹม͢Δɻಉ࣌ʹʮ==ʯΛʮ=ʯʹม͢Δɻ • ;ͨͭΊͷapplyͷ͋ͱͰΰʔϧɺ • x = y -> y = x • y = x -> x = y • SSReflectͷ߹ɺViewώϯτ͕͑ΔͷͰɺ1ߦͰࡁΉɻ apply/eqP/eqP; auto.
bool). Variables (x y : updown). Check equivPif : reflect P b -> (Q -> P) -> (P -> Q) -> (if b then Q else ~ Q). Check equivPif eqP : (x = y -> y = x) -> (y = x -> x = y) -> (if y == x then x = y else x <> y). Check introTF : reflect P b -> (if c then P else ~ P) -> b = c. Check introTF eqP : (if y == x then x = y else x <> y) -> (x == y) = (y == x).
Small Scale Reflection Extension for the Coq system”, Nr.6455, INRIA Microsoft Research SSReflectͷΞοϓσʔτຖʹվఆ͞ΕɺϦϑΝϨϯεϚχϡΞϧͱͯ͑͠Δɻ 6. Georges Gonthier, St ́phane Le Roux, “An Ssreflect Tutorial”, Nr.367, INIRA Microsoft Research 7. Georges Gonthier, Assia Mahboubi, “An introduction to small scale reflection in Coq”, Nr.7392, INIRA Microsoft Research
Type} (x : A) : A -> Prop := eq_refl : eq A x x. Notation "a = b" := (eq a b). • Leibnizಉؔ Definition leibnitz_eq (A : Type)(a b : A) : Prop := forall (P : A -> Prop), P a -> P b. • Coqͷʮ=ʯͱLeibnizಉؔɺͰ͋Δɻ Lemma eq_leibnitz_eq : forall (A : Type) (a b : A), leibnitz_eq A a b <-> a = b.
c reflect P b introTF if c then P else ~P if c then P else ~P reflect Q c equivPif • P -> Q • Q -> P apply/V1; apply/V2. ɺ apply/V1/V2. ͱॻ͚Δɻ apply/V1/V2
m == p + n) = (m == n). Proof. induction p; auto. Qed. Goal forall (p m n: nat), (p + m = p + n) -> (m = n). Proof. intros p m n H. apply (introT eqP) in H. (* H : p + m == p + n *) apply (elimT eqP). (* Goal : m == n *) rewrite <- (eqn_add2l p m n). auto. Qed.
eqn_add2l p m n : (p + m == p + n) = (m == n). Proof. by elim: p. Qed. Goal forall p m n, (p + m = p + n) -> (m = n). Proof. move=> p m n. move/eqP => H. (* H : p + m == p + n *) apply/eqP. (* Goal : m == n *) by rewrite -(eqn_add2l p m n). Qed.