Lean Lab ๐งช
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/- | |
Sina Hazratpour | |
Introduction to Proof | |
MATH 301, Johns Hopkins University, Spring 2022 | |
-/ | |
import tactic | |
/- We want to show that in order to establish a bijection between two sets (that is a function which is both an injection and a surjection ), it is enough to establish an isomorphism (i.e. a function which has a two-sided inverse.) | |
-/ | |
variables {A B : Type} | |
lemma inverse_of_left_inverse_and_right_inverse (f : A โ B) (g : B โ A) (h : B โ A) : | |
(f โ g = id) โ (h โ f = id) โ h = g := | |
begin | |
intros hp hq, | |
funext, | |
calc | |
h x = (h โ id) x : rfl | |
... = (h โ (f โ g)) x : by rw hp | |
... = (h โ f) (g x) : rfl -- this rfl is used to prove associativity of composition | |
... = id (g x) : by rw hq | |
... = g x : rfl, | |
end | |
@[simp] def isIso (f : A โ B) := โ g: B โ A, (g โ f = id) โง (f โ g = id ) | |
-- by using lemma `left_and_right_inverses_are_equal` | |
lemma iso_of_left_and_right_inverse (f : A โ B) (g : B โ A) (h : B โ A) : | |
(f โ g = id) โ (h โ f = id) โ isIso f:= | |
begin | |
intros hp hq, | |
have he : h = g, from inverse_of_left_inverse_and_right_inverse f g h hp hq, | |
use g, | |
split, | |
{rw โ he, exact hq}, | |
{exact hp}, | |
end | |
-- Recall | |
@[simp] def isInjective {X Y : Type} (f : X โ Y) : Prop := | |
โ โฆxโ xโโฆ, f xโ = f xโ โ xโ = xโ | |
@[simp] def isSurjective {X Y : Type} (f : X โ Y) : Prop := | |
โ y : Y, โ x : X, f x = y | |
def isBijection (f: A โ B) := isInjective f โง isSurjective f | |
theorem isos_are_bijections (f : A โ B) : isIso f โ isBijection f := | |
begin | |
intro hp, | |
simp at hp, | |
cases hp with g hpg, | |
split, | |
{ simp, | |
intros a b hq, | |
calc | |
a = id a : by refl | |
... = (g โ f) (a) : by rw โhpg.1 | |
... = g ( f (a)) : by refl | |
... = g (f b ) : by rw hq | |
... = (g โ f) b : by refl | |
... = id b : by rw hpg.1 | |
... = b : by refl, | |
}, | |
{simp, | |
intro y, | |
have u : (f โ g) y = id y, by rw hpg.2, | |
simp at u, | |
exact โจg y, u โฉ, | |
}, | |
end | |
/- | |
CHALLENGE: Can you prove the converse, that is every bijection is an isomorphism? | |
-/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/- | |
Sina Hazratpour, Johns Hopkins University | |
MATH301 Lecture for the section on Friday, Apr 1, 2022. | |
Key words: Retracts, Sections, Injections, Surjections | |
-/ | |
import tactic | |
import init.data.set | |
open nat | |
variables X Y Z U V W: Type | |
/- | |
A **retract** (aka **left inverse**) of a function f: A โ B is a function r: B โ A such that r โ f = id_A. In this situation we also say A is a retract of B. | |
-/ | |
def isRetract {X Y : Type} (r : X โ Y) : Prop := โ s : Y โ X, r โ s = id | |
-- pred : โ โ โ is a retract of succ: โ โ โ | |
lemma pred_of_succ : pred โ succ = id | |
:= | |
begin | |
funext, | |
refl, | |
end | |
-- challenge | |
example : succ โ pred โ id | |
:= | |
begin | |
intro h, | |
have e : (succ โ pred) 0 = id 0, by rw h, | |
simp at e, | |
exact e, | |
end | |
/- | |
A **section** (aka **right inverse**) of function f : A โ B is a function s: B โ A such that f โ s = id_B. | |
-/ | |
def isSection {X Y : Type} (s : X โ Y) : Prop := โ r : Y โ X, r โ s = id | |
/- From the example above we know that `succ` is a section of `pred`; we use `use` tactic, which is similar to `existsi`, to prove this. | |
-/ | |
theorem succ_is_section : isSection succ := | |
begin | |
use [pred, pred_of_succ], | |
end | |
/- | |
A function f: A โ B is **injective** (also called **one-to-one**) whenever the following sentence holds. | |
โ a, b :A, f(a) = f(b) โ a = b | |
An injective function is said to be an **injection**. | |
-/ | |
def isInjective {X Y : Type} (f : X โ Y) : Prop := | |
โ โฆxโ xโโฆ, f xโ = f xโ โ xโ = xโ | |
-- Let's prove the identity function is injective: | |
lemma injective_id : isInjective (id : X โ X) := | |
begin | |
intros xโ xโ, | |
intro hp, | |
dsimp at hp, | |
exact hp, | |
end | |
/- | |
Let's prove the following theorem from the lecture: | |
*Every section is injective.* | |
PROOF: | |
Suppose f: A โ B is a section with a retract r: B โ A. Therefore, r โ f = id_A. | |
For arbitrary elements a and a' of A, suppose f(a) = f(a'). It follows that | |
a = id (a) = r โ f (a) = r ( f(a) ) = r(f(a')) = r โ f (a') = id_A (a') = a'. | |
Hence, f is injective. | |
-/ | |
-- challenge: translate the proof above to Lean. | |
theorem injective_section (s : Y โ X ): isSection s โ isInjective s := | |
begin | |
sorry, | |
end | |
/- | |
There is an empty type in Lean: `empty`. This type has no element, but, for any type `A` it comes with a recursor function `empty.elim : empty โ A`. | |
-/ | |
#check empty | |
#check empty.elim | |
/- | |
First we show that for any type A there is a unique function from the empty type `empty` to A. Then we show this unique function is injective. | |
-/ | |
theorem fun_from_empty_unique {A : Type} (f g : empty โ A) : f = g := | |
begin | |
funext, | |
exact empty.elim x, | |
end | |
-- Therefore, any function `empty โ A` is necessarily equal to `empty.elim`. | |
theorem only_empty_elim {A : Type} (f : empty โ A) : f = empty.elim := | |
begin | |
apply fun_from_empty_unique f empty.elim, | |
end | |
theorem injective_empty (A : Type) : isInjective (empty.elim : empty โ A) := | |
begin | |
intros x x' h, | |
exact empty.elim x', | |
end | |
-- Injections are closed under composition. | |
lemma injective_comp (f : X โ Y) (g : Y โ Z) (inj_f : isInjective f) (inj_g : isInjective g): isInjective (g โ f) := | |
begin | |
intros x x' h, | |
simp at h, | |
have hโ : f x = f x', from inj_g h, | |
exact inj_f hโ, | |
end | |
def isSurjective {X Y : Type} (f : X โ Y) : Prop := | |
โ y : Y, โ x : X, f x = y | |
/- | |
challenge: Prove the following theorem in Lean: | |
*Theorem: Every retract is surjective.* | |
-/ | |
-- Surjections are closed under composition. | |
lemma surj_comp (f : X โ Y) (g : Y โ Z) (surj_f : isSurjective f) (surj_g : isSurjective g): isSurjective (g โ f) := | |
begin | |
intro z, | |
have hโ, from surj_g z, | |
cases hโ with y hโ, | |
have hโ, from surj_f y, | |
cases hโ with x hโ, | |
have hโ : g y = g (f (x)), by rw hโ, | |
have hโ : z = g (f (x)), by rw [โhโ, hโ ], | |
existsi x, | |
rw hโ, | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/- | |
Sina Hazratpour | |
Introduction to Proof | |
MATH 301, Johns Hopkins University, Spring 2022 | |
-/ | |
import init.classical | |
import init.data.set | |
import data.set | |
import data.set.basic | |
import data.real.basic | |
import tactic.ring | |
import analysis.special_functions.exp | |
import analysis.special_functions.trigonometric.basic | |
import data.set.intervals.infinite | |
/- ## Images -/ | |
open complex | |
noncomputable theory | |
#check real.sin | |
/- | |
The number ฯ = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from | |
which one can derive all its properties. For explicit bounds on ฯ, see `data.real.pi.bounds`. | |
protected noncomputable def pi : โ := 2 * classical.some exists_cos_eq_zero | |
-/ | |
#check real.sin real.pi | |
variables X Y Z U V W: Type | |
-- We must `open set` in order to use `image` and `preimage`; otherwise we have to use a more cumbersome notation like set.image which is less than ideal. | |
open set | |
open function | |
section image | |
variables A B S : set U | |
variable f : A โ B | |
variables g h : U โ V | |
#check A | |
#check B | |
#check f | |
/- | |
Coercion of sets into types: | |
A : U โ Prop | |
ฮน : Prop โ Type | |
โฅA is ฮน โ A : U โ Type gotten by the code of the comprhension type { x : U // A x } | |
Claim: { x : U | A x} is the same set as the truncation of ฮน โ A. | |
-/ | |
#check โฅA | |
#check g | |
#check image | |
#check image g | |
#check image g S | |
#check image h S | |
#check g '' S | |
-- if g is ฯ_1 : โ ร โ to โ and S is a subset of โ ร โ then images g S is a subset of โ. | |
-- recall that `image g S` is defined to be the set `{ y : V | โ x : U, x โ S โง g x = y }` | |
-- A hypothesis ``y โ g '' S`` decomposes to a triple ``โจx, hxS, eโฉ`` with ``x : U`` satisfying the hypotheses ``hxS : x โ S`` and ``e : g x = y``. | |
-- The information `y โ g ''S` is the same as a triple for some `x:U` where `hxS: x โ S` and `e : gx = y`. | |
--another notation of `image g S` is `g'' S`. | |
end image | |
namespace example_from_analysis | |
#check real.sin | |
def f (x : โ) : โ := real.sin x | |
#check f | |
#check f real.pi | |
/- The sine of `ฯ` is `0`. -/ | |
/- idea: how do we prove that sin ฯ is zero? | |
Well, ฯ is define as 2 * ฯ/2 where ฯ/2 is the root of cos : โ โ โ | |
between 1 and 2. | |
sin ฯ = sin (2 * ฯ/2 )= sin (ฯ + ฯ /2) = sin(ฯ/2 + ฯ/2) = sin (ฯ/2) cos(ฯ/2) + cos(ฯ_2) sin(ฯ_2) = sin (ฯ/2) * 0 + 0 * sin (ฯ/2) = 0 + 0 = 0. | |
-/ | |
@[simp] lemma sin_pi_is_zero : real.sin (real.pi) = 0 := | |
begin | |
rw [โ mul_div_cancel_left real.pi (@two_ne_zero โ _ _), two_mul, add_div, real.sin_add, real.cos_pi_div_two], | |
simp, | |
end | |
/-- The sine of `ฯ / 6` is `1 / 2`. -/ | |
@[simp] lemma sin_pi_div_six_is_half : real.sin (real.pi / 6) = 1 / 2 := | |
begin | |
rw [โ real.cos_pi_div_two_sub, โ real.cos_pi_div_three], | |
congr, | |
ring, | |
end | |
-- Find f({0, ฯ/6}), f([0, ฯ/6]), f([ฯ/6, ฯ/2]), f([0, ฯ/2]). | |
lemma image_i : real.sin '' ( {real.pi/6, real.pi} ) = {0, 1/2} := | |
begin | |
sorry, | |
end | |
#check Icc | |
-- `Icc 0 (real.pi/6)` is the closed interval [0, ฯ/6] | |
lemma image_ii : f '' Icc 0 (real.pi/6) = Icc 0 (1/2) := sorry | |
lemma image_iii : f '' Icc (real.pi/6) (real.pi/2) = Icc (1/2) 1 := sorry | |
lemma image_iv : f '' Icc 0 (real.pi/2) = Icc 0 1 := sorry | |
end example_from_analysis | |
/-! ## Preimages -/ | |
section preimage | |
variables A B : Type | |
variable f : A โ B | |
#check B | |
variable T : set V | |
variable g : U โ V | |
#check g | |
#check preimage g | |
variable y : V | |
#check preimage g T | |
#reduce preimage g T | |
-- Another notation for `preimage g T` is `g โปยน' T`. You can get by typing "g", "\", "^", "-1", and "'". | |
-- `preimage g T` is defined by the set `{ x : U | g x โ T } : set U` | |
#check preimage g {y} | |
end preimage | |
/-! ### Images and Preimages: Some Theorems -/ | |
/- | |
The subset relationship is respected by the image operation. | |
-/ | |
theorem image_increasing {U V : Type*} {f : U โ V} {S T : set U} {h : S โ T}: image f S โ image f T | |
:= | |
begin | |
rw subset_def, | |
intros y hy, | |
-- what was the definition of `f '' S` b/c we have to use hy. | |
-- { y : V | โ x : U, x โ S โง f x = y } | |
cases hy with x hxS, | |
have hxT : x โ T, from h hxS.1, | |
-- what is `f '' T`? acoording to its defn, it is { y : V | โ x : U, x โ T โง f x = y } | |
existsi x, | |
constructor, | |
exact hxT, | |
exact hxS.2, | |
end | |
theorem image_increasing_alt {U V : Type*} {f : U โ V} {S T : set U} {h : S โ T}: image f S โ image f T | |
:= | |
begin | |
rw subset_def, | |
intros y hy, | |
-- what was the definition of `f '' S` b/c we have to use hy. | |
-- { y : V | โ x : U, x โ S โง f x = y } | |
cases hy with x hxS, | |
have hxT : x โ T, from h hxS.1, | |
-- what is `f '' T`? acoording to its defn, it is { y : V | โ x : U, x โ T โง f x = y } | |
existsi x, | |
exact โจ hxT, hxS.2โฉ, | |
end | |
-- The subset relationship is also respected by the preimage operation. | |
lemma preimage_increasing {U V : Type*} {f : U โ V} {S T : set V} {h : S โ T}: preimage f S โ preimage f T | |
:= | |
begin | |
intro x, | |
simp, | |
apply h, | |
end | |
-- Preimage operation preserve the intersection of sets. | |
-- "meet" is another name for intersection. | |
lemma preimage_preserves_meets {U V : Type*} {f : U โ V} {S T : set V}: f โปยน' (S โฉ T) = f โปยน' S โฉ f โปยน' T := | |
by { ext, refl } | |
lemma image_of_meet {U V : Type*} {f : U โ V} {S T : set U}: f '' (S โฉ T) โ f '' S โฉ f '' T := | |
-- by {ext, refl } fails | |
begin | |
sorry, | |
end | |
/- However the reverse subset inclusion is not true: Consider the constant function | |
ฮป n, 1 : โ โ โ -/ | |
@[simp] def cons_at_zero : โ โ โ := ฮป n, 0 | |
#check cons_at_zero | |
/- | |
We write @[simp] at the beginning of a definition/lemma/theorem X to tell Lean that it can use `simp` tactic in other definition/lemma/theorem which use X. | |
-/ | |
@[simp] def Even : set โ := { n : โ | even n} | |
@[simp] def Odd : set โ := { n : โ | odd n} | |
lemma even_meet_odd : Even โฉ Odd = โ := | |
begin | |
ext n, | |
simp, | |
end | |
lemma zero_is_even : 0 โ Even := | |
by {simp} | |
lemma image_counterexampleโ : cons_at_zero '' Even = { 0 } | |
:= | |
begin | |
ext n, | |
split, | |
-- as we learned before `rintro` is for recursive introduction of conjunction and existential qunatifiers. | |
{ | |
rintro โจ m, hm, e โฉ , | |
dsimp at e, | |
simp at hm, | |
simp, | |
rw โe, | |
}, | |
{ | |
intro h, | |
simp at h, | |
rw h, | |
exact โจ 0, zero_is_even, rfl โฉ, | |
}, | |
end | |
lemma one_is_odd : 1 โ Odd := | |
by {simp} | |
lemma image_counterexampleโ : cons_at_zero '' Odd = { 0 } | |
:= | |
begin | |
ext n, | |
split, | |
-- as we learned before `rintro` is for recursive introduction of conjunction and existential qunatifiers. | |
{ | |
rintro โจ m, hm, e โฉ , | |
dsimp at e, | |
simp at hm, | |
simp, | |
rw โe, | |
}, | |
{ | |
intro h, | |
simp at h, | |
rw h, | |
exact โจ 1, one_is_odd, rfl โฉ, | |
}, | |
end | |
-- meet of images is not the image of meet. | |
example : | |
ยฌ (cons_at_zero '' Even) โฉ (cons_at_zero '' Odd) โ cons_at_zero '' (Even โฉ Odd) | |
:= | |
begin | |
rw even_meet_odd, | |
rw image_counterexampleโ, | |
rw image_counterexampleโ, | |
simp, | |
end | |
-- Image respects singletons | |
lemma image_preserves_singelton {U V : Type*} {f : U โ V} {u : U} : f '' { u } = { f u } := | |
begin | |
ext y, | |
split, | |
{ | |
rintros โจx, hx, eโฉ, | |
simp, | |
simp at hx, | |
rw [โe, hx] | |
}, | |
intro h, | |
simp, | |
simp at h, | |
exact h, | |
end | |
-- "join" is another name for union | |
lemma image_preserves_joinsโ {U V : Type*} {f : U โ V} {S T : set U}: f '' (S โช T) = f '' S โช f '' T := | |
begin | |
ext y, | |
simp, | |
split, | |
intros h, | |
cases h with x hx, | |
cases hx.1 with hxโ hxโ, | |
{ | |
apply or.inl, | |
existsi x, | |
sorry, | |
}, | |
{sorry}, | |
sorry, | |
end | |
/- | |
Here is a shorter proof relying on the fact that a hypothesis `y โ g '' S` decomposes to a triple `โจx, hxS, eโฉ` with `x : U` satisfying the hypotheses `hxS : x โ S` and `e : g x = y`. | |
-/ | |
lemma image_preserves_joinsโ {U V : Type*} {f : U โ V} {S T : set U}: f '' (S โช T) = f '' S โช f '' T := begin | |
ext y, | |
split, | |
rintros โจx, hxS | hxT, rflโฉ, | |
left, use [x, hxS], | |
right, use [x, hxT], | |
rintros ( โจx, hxS, rflโฉ | โจx, hxT, rflโฉ ), | |
use [x, or.inl hxS], | |
use [x, or.inr hxT], | |
end | |
-- A family (A_i | i โ I) of sets (in the universe M) is formalized as a function A : I โ set U of types. | |
example {M N: Type} {I : Type*} (A : I โ set M) (B : I โ set N) (f : M โ N) : f '' (โ i, A i) = โ i, f '' A i := | |
begin | |
ext y, | |
simp, | |
split, | |
{ rintros โจx, โจi, xAiโฉ, fxeqโฉ, | |
use [i, x, xAi, fxeq] }, | |
rintros โจi, x, xAi, fxeqโฉ, | |
exact โจx, โจi, xAiโฉ, fxeqโฉ, | |
end | |
theorem Frobenius_reciprocity {U V : Type*} {f : U โ V} {A : set U} {B : set V } : | |
B โฉ f '' A = f '' (f โปยน' B โฉ A ) | |
:= | |
begin | |
sorry, | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/- | |
Sina Hazratpour | |
Introduction to Proof | |
MATH 301, Johns Hopkins University, Spring 2022 | |
-/ | |
import init.data.set | |
import data.set | |
import data.set.basic | |
open set | |
open function | |
open nat | |
variables X Y Z U V W : Type | |
-- Recall | |
def isInjective {X Y : Type} (f : X โ Y) : Prop := | |
โ โฆxโ xโโฆ, f xโ = f xโ โ xโ = xโ | |
def isSurjective {X Y : Type} (f : X โ Y) : Prop := | |
โ y : Y, โ x : X, f x = y | |
/- ## Example 1 : Functions on Natural Numbers -/ | |
/- | |
- CHALLENGE 1: Define the subsets of even and odd numbers | |
-/ | |
@[simp] def my_even (n : โ) := โ k : โ, n = k + k | |
#check my_even | |
@[simp] def Even := { n : โ | my_even n} | |
#check Even | |
@[simp] def my_odd (n : โ) := โ k : โ, n = k + k + 1 | |
#check my_odd | |
@[simp] def Odd := { n : โ | my_odd n} | |
#check Odd | |
/- | |
- CHALLENGE 2: Prove that 0 is even and 1 is odd. | |
-/ | |
@[simp] lemma zero_is_even : 0 โ Even := | |
begin | |
use 0, | |
end | |
@[simp] lemma one_is_odd : 1 โ Odd := | |
begin | |
use 0, | |
end | |
/- | |
CHALLENGE 3: Prove that the odd numbers and even numbers do not meet, i.e. their intersection is the empty set. | |
-/ | |
#check add_left_cancel | |
lemma eq_zero_of_add_right_eq_self {m n : โ } : (m + n = m) โ (n = 0) := | |
begin | |
intro h, | |
rw โ add_zero m at h, | |
rw add_assoc m 0 n at h, | |
rw zero_add n at h, | |
rw add_left_cancel h, | |
end | |
lemma odd_meet_even : Even โฉ Odd = โ := | |
begin | |
ext, | |
rw inter_def, | |
simp, | |
intros k hk l, | |
intro h, | |
rw hk at h, | |
sorry, | |
end | |
/- CHALLENGE 4: Define the constant function at 0 from โ to โ. -/ | |
@[simp] def constant_at_zero : โ โ โ := ฮป n, 0 | |
/- CHALLENGE 5: Show that the image of the constant function at zero of the even numbers is the singleton containing zero. -/ | |
#check constant_at_zero '' | |
lemma image_of_constant_zero : constant_at_zero '' Even = { 0 } := | |
begin | |
ext y, | |
split, | |
{ intro hy, | |
cases hy with x hx, | |
simp, | |
simp at hx, | |
have hxr, from hx.2, | |
exact eq.symm hxr, | |
}, | |
{ | |
intro h, | |
simp, | |
use [0, 0, rfl], | |
simp at h, | |
exact eq.symm h, | |
}, | |
end | |
/- | |
CHALLENGE 6: Show that the image of the constant function at zero of the odd numbers is the singleton containing zero. | |
-/ | |
/- | |
In general we have: | |
-/ | |
lemma imagee_of_meet {f : X โ Y} (S T : set X) : f '' (S โฉ T) โ f '' S โฉ f '' T := | |
begin | |
rw subset_def, | |
intros y hy, | |
cases hy with x hx, | |
simp, | |
simp at hx, | |
exact โจ exists.intro x โจ hx.1.1, hx.2โฉ , exists.intro x โจ hx.1.2, hx.2โฉ โฉ, | |
end | |
/- | |
CHALLENGE 7 : Use 1-6 to prove that in general the meet of images is not the image of meet. | |
-/ | |
/- | |
CHALLENGE 8: Investigate under what conditions the the meet of images is the image of meet. | |
-/ | |
lemma image_of_injections_preserves_meets {X Y : Type} {f : X โ Y} {S T : set X}: isInjective f โ f '' (S โฉ T) = f '' S โฉ f '' T := | |
begin | |
sorry, | |
end | |
/- ## Examples 2: Image of finite sets -/ | |
/- | |
- CHALLENGE 1: Prove that the image of a singleton set is singelton. | |
-/ | |
lemma image_preserves_singelton {U V : Type*} {f : U โ V} {u : U} : f '' { u } = { f u } := | |
begin | |
sorry, | |
end | |
/- | |
- CHALLENGE 2: Prove that the image operation respects unions of sets. | |
-/ | |
lemma image_preserves_joins {U V : Type*} {f : U โ V} {S T : set U}: f '' (S โช T) = f '' S โช f '' T := | |
begin | |
sorry, | |
end | |
/- | |
- CHALLENGE 3: Use the previous two results to prove that for any function g : bool โ bool, we have g ''({tt,ff}) = {g tt, g ff} | |
-/ | |
/- | |
## Example 3: Subsingletons | |
-/ | |
/-- A set `S` is a `subsingleton`, if it has at most one element. -/ | |
def subsingle {X : Type} (S : set X) : Prop := | |
โ โฆx y : Xโฆ (hx : x โ S) (hy : y โ S), x = y | |
#check subsingle | |
/- | |
- CHALLENGE 1: Prove that a subsingleton T of a subsingleton S of X is a subsingleton of X. | |
-/ | |
lemma subsingle_of_subsingle {S T : set X} (hS : subsingle S) (hT : T โ S) : subsingle T := | |
begin | |
sorry, | |
end | |
/- | |
- CHALLENGE 2: Prove that the image of a subsingleton S of X under any function f: X โ Y is a subsingleton of Y. | |
-/ | |
lemma image_of_subsingle {f : X โ Y} {S : set X}(hS : subsingle S) : subsingle (f '' S) := | |
begin | |
sorry, | |
end | |
/- | |
- CHALLENGE 3: Any singelton is a subsingleton. | |
-/ | |
/- | |
- CHALLENGE 4: Any inhabited subsingleton is a singelton. | |
-/ | |
lemma inhabited_subsingleton_is_singelton {S : set X} (hS : subsingle S) {x : X} (hx : x โ S) : S = {x} := sorry | |
/-- | |
- CHALLENGE 5: A subset of a singleton set is a subsingleton. | |
--/ | |
/- | |
- CHALLENGE 6: The empty set is a subsingelton. | |
-/ | |
lemma empty_is_a_subsingleton : | |
subsingle (โ : set X) := sorry | |
/- | |
- CHALLENGE 7: Prove that the law of excluded middle implies that the only subsingletons are the empty and singeltons. How unbecoming! | |
-/ | |
/- | |
## Example 4: Restrict of the functions | |
-/ | |
/- | |
Suppose f: A โ B is a function and U โ A. We can restrict the function f to U, that is we restrict the action of f to those elements of A which are already present in U. | |
For instance if we restrict the absolute value function to the set of positive real numbers we obtain the identity function on the set of positive real numbers. | |
In Lean we prefer types to sets for defining functions. So if f : X โ Y and P : X โ Prop then we can restrict f to the type { x : X // P x }: | |
the restriction of f then takes a : { x : X // P x }to f a. | |
-/ | |
def restrict (f : X โ Y) (P : X โ Prop) : | |
{ x : X // P x } โ Y := ฮป โจ x, p โฉ, f x | |
/- | |
- CHALLENGE 1: Restrict the function ฮป n : โ, nยฒ to the odd numbers. | |
- CHALLENGE 2: Show that the image of the restricted function is a subset of odd numbers. | |
- CHALLENGE 3: Show that a restriction of a restriction is again a restriction. | |
-/ | |
/- | |
## Example 5 : The Galois Connection | |
-/ | |
theorem Galois_connection {X Y : Type} (f: X โ Y) (S : set X) (T : set Y) : f '' S โ T โ S โ f โปยน' T := | |
begin | |
split, | |
{ intros h x xS, | |
have fxS : f x โ f '' S, | |
from mem_image_of_mem _ xS, | |
exact h fxS }, | |
{ intros h y yS, | |
rcases yS with โจx, xS, fxeyโฉ, | |
rw โ fxey, | |
apply h xS }, | |
end | |
#check subset_refl | |
#check subset_rfl | |
/- | |
We use the Galois connection between the image and preimage operations to prove that every set is contained in the preimage of its image. | |
-/ | |
example (f : X โ Y) (S : set X) : S โ f โปยน' (f '' S) := | |
begin | |
have u, from Galois_connection f S (f '' S), | |
exact iff.elim_left u subset_rfl, | |
end | |
/- | |
Morover, if the function f is injective the subset inclusion above is in fact equality. | |
-/ | |
example {f : X โ Y} (inj_f : isInjective f) (S : set X) : S = f โปยน' (f '' S) := | |
begin | |
sorry, | |
end | |
/- | |
Does the condition S = f โปยน' (f '' S) for all subsets S : set X imply injectivity of f? | |
-/ | |
example {f : X โ Y} : โ (S : set X), S = f โปยน' (f '' S) โ isInjective f := | |
begin | |
sorry, | |
end |