logical-foundations/Rel.v

76 lines
1.8 KiB
Coq

From Coq Require Import Arith.Arith.
From Coq Require Import Bool.Bool.
From Coq Require Import Logic.FunctionalExtensionality.
From Coq Require Import Lists.List.
From Coq Require Import Strings.String.
Import ListNotations.
Set Default Goal Selector "!".
Definition relation (X: Type) := X -> X -> Prop.
Definition partial_function {X: Type} (R: relation X) :=
forall x y1 y2 : X, R x y1 -> R x y2 -> y1 = y2.
Inductive next_nat : nat -> nat -> Prop :=
| nn n : next_nat n (S n).
Check next_nat : relation nat.
Theorem next_nat_partial_function: partial_function next_nat.
Proof.
unfold partial_function.
intros x y1 y2 H1 H2.
inversion H1.
inversion H2.
reflexivity.
Qed.
Theorem le_not_a_partial_function :
~ (partial_function le).
Proof.
unfold not.
unfold partial_function.
intros Hc.
assert (0 = 1) as Nonsense. {
apply Hc with (x := 0).
- apply le_n.
- apply le_S. apply le_n.
}
discriminate Nonsense.
Qed.
Inductive total_relation : nat -> nat -> Prop :=
| rel_0 (n : nat) : total_relation 0 n
| rel_Sn_m (n m : nat) (H : total_relation n m) : total_relation (S n) m.
Theorem total_relation_not_partial_function :
~ (partial_function total_relation).
Proof.
unfold partial_function.
intros Hc.
assert (0 = 1) as Nonsense. {
apply Hc with (x := 1) ; apply rel_Sn_m ; apply rel_0.
}
discriminate.
Qed.
Inductive empty_relation : nat -> nat -> Prop :=
| rel_contra (n m : nat) (H : S n = 0) : empty_relation n m.
Theorem empty_relation_partial_function :
partial_function empty_relation.
Proof.
unfold partial_function.
intros x y1 y2 H1 H2.
exfalso.
inversion H1.
discriminate.
Qed.
Definition reflexive {X: Type} (R: relation X) :=
forall a: X, R a a.
Theorem le_reflexive : reflexive le.
Proof.
exact le_n.
Qed.