RelProperties of Relations
Set Warnings "-notation-overridden,-parsing".
From LF Require Export IndProp.
From LF Require Export IndProp.
Relations
Definition relation (X: Type) := X → X → Prop.
Confusingly, the Coq standard library hijacks the generic term
"relation" for this specific instance of the idea. To maintain
consistency with the library, we will do the same. So, henceforth
the Coq identifier relation will always refer to a binary
relation between some set and itself, whereas the English word
"relation" can refer either to the specific Coq concept or the
more general concept of a relation between any number of possibly
different sets. The context of the discussion should always make
clear which is meant.
An example relation on nat is le, the less-than-or-equal-to
relation, which we usually write n1 ≤ n2.
Print le.
(* ====> Inductive le (n : nat) : nat -> Prop :=
le_n : n <= n
| le_S : forall m : nat, n <= m -> n <= S m *)
Check le : nat → nat → Prop.
Check le : relation nat.
(* ====> Inductive le (n : nat) : nat -> Prop :=
le_n : n <= n
| le_S : forall m : nat, n <= m -> n <= S m *)
Check le : nat → nat → Prop.
Check le : relation nat.
(Why did we write it this way instead of starting with Inductive
le : relation nat...? Because we wanted to put the first nat
to the left of the :, which makes Coq generate a somewhat nicer
induction principle for reasoning about ≤.)
Basic Properties
Partial Functions
Definition partial_function {X: Type} (R: relation X) :=
∀x y1 y2 : X, R x y1 → R x y2 → y1 = y2.
∀x y1 y2 : X, R x y1 → R x y2 → y1 = y2.
For example, the next_nat relation defined earlier is a partial
function.
Print next_nat.
(* ====> Inductive next_nat (n : nat) : nat -> Prop :=
nn : next_nat n (S n) *)
Check next_nat : relation nat.
Theorem next_nat_partial_function :
partial_function next_nat.
(* ====> Inductive next_nat (n : nat) : nat -> Prop :=
nn : next_nat n (S n) *)
Check next_nat : relation nat.
Theorem next_nat_partial_function :
partial_function next_nat.
However, the ≤ relation on numbers is not a partial
function. (Assume, for a contradiction, that ≤ is a partial
function. But then, since 0 ≤ 0 and 0 ≤ 1, it follows that
0 = 1. This is nonsense, so our assumption was
contradictory.)
Theorem le_not_a_partial_function :
¬(partial_function le).
¬(partial_function le).
Exercise: 2 stars, standard, optional (total_relation_not_partial)
Show that the total_relation defined in (an exercise in) IndProp is not a partial function.
(* FILL IN HERE *)
☐
Exercise: 2 stars, standard, optional (empty_relation_partial)
Show that the empty_relation defined in (an exercise in) IndProp is a partial function.
(* FILL IN HERE *)
☐
Reflexive Relations
Definition reflexive {X: Type} (R: relation X) :=
∀a : X, R a a.
Theorem le_reflexive :
reflexive le.
∀a : X, R a a.
Theorem le_reflexive :
reflexive le.
Definition transitive {X: Type} (R: relation X) :=
∀a b c : X, (R a b) → (R b c) → (R a c).
Theorem le_trans :
transitive le.
Theorem lt_trans:
transitive lt.
∀a b c : X, (R a b) → (R b c) → (R a c).
Theorem le_trans :
transitive le.
Theorem lt_trans:
transitive lt.
Exercise: 2 stars, standard, optional (le_trans_hard_way)
We can also prove lt_trans more laboriously by induction, without using le_trans. Do this.
Theorem lt_trans' :
transitive lt.
Proof.
(* Prove this by induction on evidence that m is less than o. *)
unfold lt. unfold transitive.
intros n m o Hnm Hmo.
induction Hmo as [| m' Hm'o].
(* FILL IN HERE *) Admitted.
☐
transitive lt.
Proof.
(* Prove this by induction on evidence that m is less than o. *)
unfold lt. unfold transitive.
intros n m o Hnm Hmo.
induction Hmo as [| m' Hm'o].
(* FILL IN HERE *) Admitted.
Theorem lt_trans'' :
transitive lt.
☐
transitive lt.
Theorem le_Sn_le : ∀n m, S n ≤ m → n ≤ m.
Theorem le_S_n : ∀n m,
(S n ≤ S m) → (n ≤ m).
Proof.
(* FILL IN HERE *) Admitted.
☐
(S n ≤ S m) → (n ≤ m).
Proof.
(* FILL IN HERE *) Admitted.
Exercise: 2 stars, standard, optional (le_Sn_n_inf)
Provide an informal proof of the following theorem:
(* FILL IN HERE *)
☐
Theorem le_Sn_n : ∀n,
¬(S n ≤ n).
Proof.
(* FILL IN HERE *) Admitted.
☐
¬(S n ≤ n).
Proof.
(* FILL IN HERE *) Admitted.
Symmetric and Antisymmetric Relations
Definition symmetric {X: Type} (R: relation X) :=
∀a b : X, (R a b) → (R b a).
∀a b : X, (R a b) → (R b a).
Theorem le_not_symmetric :
¬(symmetric le).
Proof.
(* FILL IN HERE *) Admitted.
☐
¬(symmetric le).
Proof.
(* FILL IN HERE *) Admitted.
Definition antisymmetric {X: Type} (R: relation X) :=
∀a b : X, (R a b) → (R b a) → a = b.
∀a b : X, (R a b) → (R b a) → a = b.
Theorem le_antisymmetric :
antisymmetric le.
Proof.
(* FILL IN HERE *) Admitted.
☐
antisymmetric le.
Proof.
(* FILL IN HERE *) Admitted.
Theorem le_step : ∀n m p,
n < m →
m ≤ S p →
n ≤ p.
Proof.
(* FILL IN HERE *) Admitted.
☐
n < m →
m ≤ S p →
n ≤ p.
Proof.
(* FILL IN HERE *) Admitted.
Definition equivalence {X:Type} (R: relation X) :=
(reflexive R) ∧ (symmetric R) ∧ (transitive R).
(reflexive R) ∧ (symmetric R) ∧ (transitive R).
Partial Orders and Preorders
Definition order {X:Type} (R: relation X) :=
(reflexive R) ∧ (antisymmetric R) ∧ (transitive R).
(reflexive R) ∧ (antisymmetric R) ∧ (transitive R).
A preorder is almost like a partial order, but doesn't have to be
antisymmetric.
Definition preorder {X:Type} (R: relation X) :=
(reflexive R) ∧ (transitive R).
Theorem le_order :
order le.
(reflexive R) ∧ (transitive R).
Theorem le_order :
order le.
Reflexive, Transitive Closure
Inductive clos_refl_trans {A: Type} (R: relation A) : relation A :=
| rt_step x y (H : R x y) : clos_refl_trans R x y
| rt_refl x : clos_refl_trans R x x
| rt_trans x y z
(Hxy : clos_refl_trans R x y)
(Hyz : clos_refl_trans R y z) :
clos_refl_trans R x z.
| rt_step x y (H : R x y) : clos_refl_trans R x y
| rt_refl x : clos_refl_trans R x x
| rt_trans x y z
(Hxy : clos_refl_trans R x y)
(Hyz : clos_refl_trans R y z) :
clos_refl_trans R x z.
For example, the reflexive and transitive closure of the
next_nat relation coincides with the le relation.
Theorem next_nat_closure_is_le : ∀n m,
(n ≤ m) ↔ ((clos_refl_trans next_nat) n m).
(n ≤ m) ↔ ((clos_refl_trans next_nat) n m).
The above definition of reflexive, transitive closure is natural:
it says, explicitly, that the reflexive and transitive closure of
R is the least relation that includes R and that is closed
under rules of reflexivity and transitivity. But it turns out
that this definition is not very convenient for doing proofs,
since the "nondeterminism" of the rt_trans rule can sometimes
lead to tricky inductions. Here is a more useful definition:
Inductive clos_refl_trans_1n {A : Type}
(R : relation A) (x : A)
: A → Prop :=
| rt1n_refl : clos_refl_trans_1n R x x
| rt1n_trans (y z : A)
(Hxy : R x y) (Hrest : clos_refl_trans_1n R y z) :
clos_refl_trans_1n R x z.
(R : relation A) (x : A)
: A → Prop :=
| rt1n_refl : clos_refl_trans_1n R x x
| rt1n_trans (y z : A)
(Hxy : R x y) (Hrest : clos_refl_trans_1n R y z) :
clos_refl_trans_1n R x z.
Our new definition of reflexive, transitive closure "bundles"
the rt_step and rt_trans rules into the single rule step.
The left-hand premise of this step is a single use of R,
leading to a much simpler induction principle.
Before we go on, we should check that the two definitions do
indeed define the same relation...
First, we prove two lemmas showing that clos_refl_trans_1n mimics
the behavior of the two "missing" clos_refl_trans
constructors.
Lemma rsc_R : ∀(X:Type) (R:relation X) (x y : X),
R x y → clos_refl_trans_1n R x y.
R x y → clos_refl_trans_1n R x y.
Lemma rsc_trans :
∀(X:Type) (R: relation X) (x y z : X),
clos_refl_trans_1n R x y →
clos_refl_trans_1n R y z →
clos_refl_trans_1n R x z.
Proof.
(* FILL IN HERE *) Admitted.
☐
∀(X:Type) (R: relation X) (x y z : X),
clos_refl_trans_1n R x y →
clos_refl_trans_1n R y z →
clos_refl_trans_1n R x z.
Proof.
(* FILL IN HERE *) Admitted.
Exercise: 3 stars, standard, optional (rtc_rsc_coincide)
Theorem rtc_rsc_coincide :
∀(X:Type) (R: relation X) (x y : X),
clos_refl_trans R x y ↔ clos_refl_trans_1n R x y.
Proof.
(* FILL IN HERE *) Admitted.
☐
∀(X:Type) (R: relation X) (x y : X),
clos_refl_trans R x y ↔ clos_refl_trans_1n R x y.
Proof.
(* FILL IN HERE *) Admitted.
(* Mon Mar 25 14:36:24 EDT 2019 *)