Library Common
Inverse functions.
Bijetive function. Existence of such a function implies that A and B are isomorphic.
Definition bijection (f: A → B) :=
∃ g: B → A, inverse f g.
Definition flip3 {A B C: Set}
(H: ∀ (a:A) (b:B) (c:C), Prop)
(c:C) (a:A) (b:B) := H a b c.
End Functions.
Implicit Arguments inverse [A B].
Implicit Arguments bijection [A B].
∃ g: B → A, inverse f g.
Definition flip3 {A B C: Set}
(H: ∀ (a:A) (b:B) (c:C), Prop)
(c:C) (a:A) (b:B) := H a b c.
End Functions.
Implicit Arguments inverse [A B].
Implicit Arguments bijection [A B].
Identity is an self-inverse function.
As the fact is trivial, the intuition tactic, with a little help from unfold,
is smart enough to prove it.
Identity is a bijection.
We give id as the inverse function for id and refer to lemma inverse_id.
Property P is decidable in Prop.
Property P is decidable in Set.
propDecS is stronger than propDec.
It derives from characteristic of inductive definitions over Set and Prop.
When we destruct propDecS, the goal can be proven automatically (here using tauto).
Equality in A is decidable in Prop.
Equality in A is decidable in Set.
eqDecS is stronger than eqDec.
We use lemma prop_decS_dec here.
unfold eqDec, eqDecS.
auto using PpropDecS_propDec.
Qed.
End EqDec.
Inductive TOneOrTwo (A: Set): Set :=
| One (elem: A)
| Two (elem1 elem2: A).
Arguments TOneOrTwo A.
Arguments One [A] elem.
Arguments Two [A] elem1 elem2.
Definition map_oneOrTwo (A B: Set) (f: A → B) (a12: TOneOrTwo A): TOneOrTwo B :=
match a12 with
| One a ⇒ One (f a)
| Two a1 a2 ⇒ Two (f a1) (f a2)
end.
Arguments map_oneOrTwo [A B] f a12.
Section Lists.
Require Import List.
Require Import BoolEq.
Variable K: Set.
Variable A: Type.
Hypothesis keyEqDec: eqDecS K.
Inductive ListPrefix: list A → list A → Prop :=
| ListPrefix_Nil: ∀ l, ListPrefix nil l
| ListPrefix_Rec: ∀ p l x, ListPrefix p l → ListPrefix (x::p) (x::l).
Lemma Pnth_error_length: ∀ (n: nat) (l: list A) (a: A),
nth_error l n = value a → n < length l.
Proof.
intros n.
induction n.
intros.
destruct l.
simpl in ×.
discriminate H.
simpl.
apply Lt.lt_0_Sn.
intros.
destruct l; simpl in ×.
discriminate H.
apply Lt.lt_n_S.
eapply IHn.
eassumption.
Qed.
Lemma Pnth_error_in: ∀ (n: nat) (l: list A) (a: A),
nth_error l n = value a → In a l.
Proof.
intros n.
induction n.
intros.
destruct l.
simpl in ×.
discriminate H.
simpl in ×.
injection H; intros.
left.
assumption.
intros.
destruct l; simpl in ×.
discriminate H.
right.
apply IHn.
assumption.
Qed.
Fixpoint findInListOfPairs (key: K) (l: list (K × A)) (default: A) {struct l}: A :=
match l with
| nil ⇒ default
| ((k,a)::tl) ⇒
if keyEqDec k key
then a
else findInListOfPairs key tl default
end.
End Lists.
Implicit Arguments ListPrefix [A].
Implicit Arguments Pnth_error_length [A].
Implicit Arguments findInListOfPairs [K A].
auto using PpropDecS_propDec.
Qed.
End EqDec.
Inductive TOneOrTwo (A: Set): Set :=
| One (elem: A)
| Two (elem1 elem2: A).
Arguments TOneOrTwo A.
Arguments One [A] elem.
Arguments Two [A] elem1 elem2.
Definition map_oneOrTwo (A B: Set) (f: A → B) (a12: TOneOrTwo A): TOneOrTwo B :=
match a12 with
| One a ⇒ One (f a)
| Two a1 a2 ⇒ Two (f a1) (f a2)
end.
Arguments map_oneOrTwo [A B] f a12.
Section Lists.
Require Import List.
Require Import BoolEq.
Variable K: Set.
Variable A: Type.
Hypothesis keyEqDec: eqDecS K.
Inductive ListPrefix: list A → list A → Prop :=
| ListPrefix_Nil: ∀ l, ListPrefix nil l
| ListPrefix_Rec: ∀ p l x, ListPrefix p l → ListPrefix (x::p) (x::l).
Lemma Pnth_error_length: ∀ (n: nat) (l: list A) (a: A),
nth_error l n = value a → n < length l.
Proof.
intros n.
induction n.
intros.
destruct l.
simpl in ×.
discriminate H.
simpl.
apply Lt.lt_0_Sn.
intros.
destruct l; simpl in ×.
discriminate H.
apply Lt.lt_n_S.
eapply IHn.
eassumption.
Qed.
Lemma Pnth_error_in: ∀ (n: nat) (l: list A) (a: A),
nth_error l n = value a → In a l.
Proof.
intros n.
induction n.
intros.
destruct l.
simpl in ×.
discriminate H.
simpl in ×.
injection H; intros.
left.
assumption.
intros.
destruct l; simpl in ×.
discriminate H.
right.
apply IHn.
assumption.
Qed.
Fixpoint findInListOfPairs (key: K) (l: list (K × A)) (default: A) {struct l}: A :=
match l with
| nil ⇒ default
| ((k,a)::tl) ⇒
if keyEqDec k key
then a
else findInListOfPairs key tl default
end.
End Lists.
Implicit Arguments ListPrefix [A].
Implicit Arguments Pnth_error_length [A].
Implicit Arguments findInListOfPairs [K A].