2014-07-30 17:43:47 +00:00
|
|
|
|
----------------------------------------------------------------------------------------------------
|
|
|
|
|
--- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
--- Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
--- Author: Jeremy Avigad
|
|
|
|
|
----------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2014-09-16 18:58:54 +00:00
|
|
|
|
import logic algebra.function
|
2014-09-05 01:41:06 +00:00
|
|
|
|
open eq
|
2014-09-03 23:00:38 +00:00
|
|
|
|
open function
|
2014-07-30 17:43:47 +00:00
|
|
|
|
|
|
|
|
|
namespace congruence
|
|
|
|
|
|
|
|
|
|
-- TODO: move this somewhere else
|
2014-09-29 15:18:10 +00:00
|
|
|
|
definition reflexive {T : Type} (R : T → T → Prop) : Prop := ∀x, R x x
|
2014-07-30 17:43:47 +00:00
|
|
|
|
|
|
|
|
|
-- Congruence classes for unary and binary functions
|
|
|
|
|
-- -------------------------------------------------
|
|
|
|
|
|
2014-10-08 01:02:15 +00:00
|
|
|
|
inductive congruence [class] {T1 : Type} {T2 : Type} (R1 : T1 → T1 → Prop) (R2 : T2 → T2 → Prop)
|
2014-07-30 17:43:47 +00:00
|
|
|
|
(f : T1 → T2) : Prop :=
|
2014-08-22 22:46:10 +00:00
|
|
|
|
mk : (∀x y : T1, R1 x y → R2 (f x) (f y)) → congruence R1 R2 f
|
2014-07-30 17:43:47 +00:00
|
|
|
|
|
|
|
|
|
-- to trigger class inference
|
|
|
|
|
theorem congr_app {T1 : Type} {T2 : Type} (R1 : T1 → T1 → Prop) (R2 : T2 → T2 → Prop)
|
|
|
|
|
(f : T1 → T2) {C : congruence R1 R2 f} {x y : T1} : R1 x y → R2 (f x) (f y) :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
congruence.rec id C x y
|
2014-07-30 17:43:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- General tools to build instances
|
|
|
|
|
-- --------------------------------
|
|
|
|
|
|
|
|
|
|
theorem congr_trivial [instance] {T : Type} (R : T → T → Prop) : congruence R R id :=
|
2014-09-04 23:36:06 +00:00
|
|
|
|
congruence.mk (take x y H, H)
|
2014-07-30 17:43:47 +00:00
|
|
|
|
|
|
|
|
|
theorem congr_const {T2 : Type} (R2 : T2 → T2 → Prop) (H : reflexive R2) :
|
|
|
|
|
∀(T1 : Type) (R1 : T1 → T1 → Prop) (c : T2), congruence R1 R2 (const T1 c) :=
|
2014-09-04 23:36:06 +00:00
|
|
|
|
take T1 R1 c, congruence.mk (take x y H1, H c)
|
2014-07-30 17:43:47 +00:00
|
|
|
|
|
|
|
|
|
-- congruences for logic
|
|
|
|
|
|
|
|
|
|
theorem congr_const_iff [instance] (T1 : Type) (R1 : T1 → T1 → Prop) (c : Prop) :
|
2014-09-05 04:25:21 +00:00
|
|
|
|
congruence R1 iff (const T1 c) := congr_const iff iff.refl T1 R1 c
|
2014-07-30 17:43:47 +00:00
|
|
|
|
|
|
|
|
|
theorem congr_or [instance] (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop)
|
2015-02-25 00:10:16 +00:00
|
|
|
|
[H1 : congruence R iff f1] [H2 : congruence R iff f2] :
|
2014-07-30 17:43:47 +00:00
|
|
|
|
congruence R iff (λx, f1 x ∨ f2 x) := sorry
|
|
|
|
|
|
|
|
|
|
theorem congr_implies [instance] (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop)
|
2015-02-25 00:10:16 +00:00
|
|
|
|
[H1 : congruence R iff f1] [H2 : congruence R iff f2] :
|
2014-07-30 17:43:47 +00:00
|
|
|
|
congruence R iff (λx, f1 x → f2 x) := sorry
|
|
|
|
|
|
|
|
|
|
theorem congr_iff [instance] (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop)
|
2015-02-25 00:10:16 +00:00
|
|
|
|
[H1 : congruence R iff f1] [H2 : congruence R iff f2] :
|
2014-07-30 17:43:47 +00:00
|
|
|
|
congruence R iff (λx, f1 x ↔ f2 x) := sorry
|
|
|
|
|
|
|
|
|
|
theorem congr_not [instance] (T : Type) (R : T → T → Prop) (f : T → Prop)
|
2015-02-25 00:10:16 +00:00
|
|
|
|
[H : congruence R iff f] :
|
2014-07-30 17:43:47 +00:00
|
|
|
|
congruence R iff (λx, ¬ f x) := sorry
|
|
|
|
|
|
2014-10-12 20:06:00 +00:00
|
|
|
|
theorem subst_iff {T : Type} {R : T → T → Prop} {P : T → Prop} [C : congruence R iff P]
|
2014-07-30 17:43:47 +00:00
|
|
|
|
{a b : T} (H : R a b) (H1 : P a) : P b :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
-- iff_mp_left (congruence.rec id C a b H) H1
|
2014-09-05 04:25:21 +00:00
|
|
|
|
iff.elim_left (@congr_app _ _ R iff P C a b H) H1
|
2014-07-30 17:43:47 +00:00
|
|
|
|
|
|
|
|
|
theorem test2 (a b c d e : Prop) (H1 : a ↔ b) (H2 : a ∨ c → ¬(d → a)) : b ∨ c → ¬(d → b) :=
|
|
|
|
|
subst_iff H1 H2
|
|
|
|
|
|
2014-09-03 23:00:38 +00:00
|
|
|
|
end congruence
|