text
stringlengths 0
3.34M
|
---|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Heather Macbeth
-/
import topology.continuous_function.weierstrass
import analysis.complex.basic
/-!
# The Stone-Weierstrass theorem
If a subalgebra `A` of `C(X, ℝ)`, where `X` is a compact topological space,
separates points, then it is dense.
We argue as follows.
* In any subalgebra `A` of `C(X, ℝ)`, if `f ∈ A`, then `abs f ∈ A.topological_closure`.
This follows from the Weierstrass approximation theorem on `[-∥f∥, ∥f∥]` by
approximating `abs` uniformly thereon by polynomials.
* This ensures that `A.topological_closure` is actually a sublattice:
if it contains `f` and `g`, then it contains the pointwise supremum `f ⊔ g`
and the pointwise infimum `f ⊓ g`.
* Any nonempty sublattice `L` of `C(X, ℝ)` which separates points is dense,
by a nice argument approximating a given `f` above and below using separating functions.
For each `x y : X`, we pick a function `g x y ∈ L` so `g x y x = f x` and `g x y y = f y`.
By continuity these functions remain close to `f` on small patches around `x` and `y`.
We use compactness to identify a certain finitely indexed infimum of finitely indexed supremums
which is then close to `f` everywhere, obtaining the desired approximation.
* Finally we put these pieces together. `L = A.topological_closure` is a nonempty sublattice
which separates points since `A` does, and so is dense (in fact equal to `⊤`).
We then prove the complex version for self-adjoint subalgebras `A`, by separately approximating
the real and imaginary parts using the real subalgebra of real-valued functions in `A`
(which still separates points, by taking the norm-square of a separating function).
## Future work
Extend to cover the case of subalgebras of the continuous functions vanishing at infinity,
on non-compact spaces.
-/
noncomputable theory
namespace continuous_map
variables {X : Type*} [topological_space X] [compact_space X]
/--
Turn a function `f : C(X, ℝ)` into a continuous map into `set.Icc (-∥f∥) (∥f∥)`,
thereby explicitly attaching bounds.
-/
def attach_bound (f : C(X, ℝ)) : C(X, set.Icc (-∥f∥) (∥f∥)) :=
{ to_fun := λ x, ⟨f x, ⟨neg_norm_le_apply f x, apply_le_norm f x⟩⟩ }
@[simp] lemma attach_bound_apply_coe (f : C(X, ℝ)) (x : X) : ((attach_bound f) x : ℝ) = f x := rfl
lemma polynomial_comp_attach_bound (A : subalgebra ℝ C(X, ℝ)) (f : A) (g : polynomial ℝ) :
(g.to_continuous_map_on (set.Icc (-∥f∥) ∥f∥)).comp (f : C(X, ℝ)).attach_bound =
polynomial.aeval f g :=
begin
ext,
simp only [continuous_map.comp_coe, function.comp_app,
continuous_map.attach_bound_apply_coe,
polynomial.to_continuous_map_on_to_fun,
polynomial.aeval_subalgebra_coe,
polynomial.aeval_continuous_map_apply,
polynomial.to_continuous_map_to_fun],
end
/--
Given a continuous function `f` in a subalgebra of `C(X, ℝ)`, postcomposing by a polynomial
gives another function in `A`.
This lemma proves something slightly more subtle than this:
we take `f`, and think of it as a function into the restricted target `set.Icc (-∥f∥) ∥f∥)`,
and then postcompose with a polynomial function on that interval.
This is in fact the same situation as above, and so also gives a function in `A`.
-/
lemma polynomial_comp_attach_bound_mem (A : subalgebra ℝ C(X, ℝ)) (f : A) (g : polynomial ℝ) :
(g.to_continuous_map_on (set.Icc (-∥f∥) ∥f∥)).comp (f : C(X, ℝ)).attach_bound ∈ A :=
begin
rw polynomial_comp_attach_bound,
apply set_like.coe_mem,
end
theorem comp_attach_bound_mem_closure
(A : subalgebra ℝ C(X, ℝ)) (f : A) (p : C(set.Icc (-∥f∥) (∥f∥), ℝ)) :
p.comp (attach_bound f) ∈ A.topological_closure :=
begin
-- `p` itself is in the closure of polynomials, by the Weierstrass theorem,
have mem_closure : p ∈ (polynomial_functions (set.Icc (-∥f∥) (∥f∥))).topological_closure :=
continuous_map_mem_polynomial_functions_closure _ _ p,
-- and so there are polynomials arbitrarily close.
have frequently_mem_polynomials := mem_closure_iff_frequently.mp mem_closure,
-- To prove `p.comp (attached_bound f)` is in the closure of `A`,
-- we show there are elements of `A` arbitrarily close.
apply mem_closure_iff_frequently.mpr,
-- To show that, we pull back the polynomials close to `p`,
refine ((comp_right_continuous_map ℝ (attach_bound (f : C(X, ℝ)))).continuous_at p).tendsto
.frequently_map _ _ frequently_mem_polynomials,
-- but need to show that those pullbacks are actually in `A`.
rintros _ ⟨g, ⟨-,rfl⟩⟩,
simp only [set_like.mem_coe, alg_hom.coe_to_ring_hom, comp_right_continuous_map_apply,
polynomial.to_continuous_map_on_alg_hom_apply],
apply polynomial_comp_attach_bound_mem,
end
theorem abs_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f : A) :
(f : C(X, ℝ)).abs ∈ A.topological_closure :=
begin
let M := ∥f∥,
let f' := attach_bound (f : C(X, ℝ)),
let abs : C(set.Icc (-∥f∥) (∥f∥), ℝ) :=
{ to_fun := λ x : set.Icc (-∥f∥) (∥f∥), |(x : ℝ)| },
change (abs.comp f') ∈ A.topological_closure,
apply comp_attach_bound_mem_closure,
end
theorem inf_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f g : A) :
(f : C(X, ℝ)) ⊓ (g : C(X, ℝ)) ∈ A.topological_closure :=
begin
rw inf_eq,
refine A.topological_closure.smul_mem
(A.topological_closure.sub_mem
(A.topological_closure.add_mem (A.subalgebra_topological_closure f.property)
(A.subalgebra_topological_closure g.property)) _) _,
exact_mod_cast abs_mem_subalgebra_closure A _,
end
theorem inf_mem_closed_subalgebra (A : subalgebra ℝ C(X, ℝ)) (h : is_closed (A : set C(X, ℝ)))
(f g : A) : (f : C(X, ℝ)) ⊓ (g : C(X, ℝ)) ∈ A :=
begin
convert inf_mem_subalgebra_closure A f g,
apply set_like.ext',
symmetry,
erw closure_eq_iff_is_closed,
exact h,
end
theorem sup_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f g : A) :
(f : C(X, ℝ)) ⊔ (g : C(X, ℝ)) ∈ A.topological_closure :=
begin
rw sup_eq,
refine A.topological_closure.smul_mem
(A.topological_closure.add_mem
(A.topological_closure.add_mem (A.subalgebra_topological_closure f.property)
(A.subalgebra_topological_closure g.property)) _) _,
exact_mod_cast abs_mem_subalgebra_closure A _,
end
theorem sup_mem_closed_subalgebra (A : subalgebra ℝ C(X, ℝ)) (h : is_closed (A : set C(X, ℝ)))
(f g : A) : (f : C(X, ℝ)) ⊔ (g : C(X, ℝ)) ∈ A :=
begin
convert sup_mem_subalgebra_closure A f g,
apply set_like.ext',
symmetry,
erw closure_eq_iff_is_closed,
exact h,
end
open_locale topological_space
-- Here's the fun part of Stone-Weierstrass!
theorem sublattice_closure_eq_top
(L : set C(X, ℝ)) (nA : L.nonempty)
(inf_mem : ∀ f g ∈ L, f ⊓ g ∈ L) (sup_mem : ∀ f g ∈ L, f ⊔ g ∈ L)
(sep : L.separates_points_strongly) :
closure L = ⊤ :=
begin
-- We start by boiling down to a statement about close approximation.
apply eq_top_iff.mpr,
rintros f -,
refine filter.frequently.mem_closure
((filter.has_basis.frequently_iff metric.nhds_basis_ball).mpr (λ ε pos, _)),
simp only [exists_prop, metric.mem_ball],
-- It will be helpful to assume `X` is nonempty later,
-- so we get that out of the way here.
by_cases nX : nonempty X,
swap,
exact ⟨nA.some, (dist_lt_iff pos).mpr (λ x, false.elim (nX ⟨x⟩)), nA.some_spec⟩,
/-
The strategy now is to pick a family of continuous functions `g x y` in `A`
with the property that `g x y x = f x` and `g x y y = f y`
(this is immediate from `h : separates_points_strongly`)
then use continuity to see that `g x y` is close to `f` near both `x` and `y`,
and finally using compactness to produce the desired function `h`
as a maximum over finitely many `x` of a minimum over finitely many `y` of the `g x y`.
-/
dsimp [set.separates_points_strongly] at sep,
let g : X → X → L := λ x y, (sep f x y).some,
have w₁ : ∀ x y, g x y x = f x := λ x y, (sep f x y).some_spec.1,
have w₂ : ∀ x y, g x y y = f y := λ x y, (sep f x y).some_spec.2,
-- For each `x y`, we define `U x y` to be `{z | f z - ε < g x y z}`,
-- and observe this is a neighbourhood of `y`.
let U : X → X → set X := λ x y, {z | f z - ε < g x y z},
have U_nhd_y : ∀ x y, U x y ∈ 𝓝 y,
{ intros x y,
refine is_open.mem_nhds _ _,
{ apply is_open_lt; continuity, },
{ rw [set.mem_set_of_eq, w₂],
exact sub_lt_self _ pos, }, },
-- Fixing `x` for a moment, we have a family of functions `λ y, g x y`
-- which on different patches (the `U x y`) are greater than `f z - ε`.
-- Taking the supremum of these functions
-- indexed by a finite collection of patches which cover `X`
-- will give us an element of `A` that is globally greater than `f z - ε`
-- and still equal to `f x` at `x`.
-- Since `X` is compact, for every `x` there is some finset `ys t`
-- so the union of the `U x y` for `y ∈ ys x` still covers everything.
let ys : Π x, finset X := λ x, (compact_space.elim_nhds_subcover (U x) (U_nhd_y x)).some,
let ys_w : ∀ x, (⋃ y ∈ ys x, U x y) = ⊤ :=
λ x, (compact_space.elim_nhds_subcover (U x) (U_nhd_y x)).some_spec,
have ys_nonempty : ∀ x, (ys x).nonempty :=
λ x, set.nonempty_of_union_eq_top_of_nonempty _ _ nX (ys_w x),
-- Thus for each `x` we have the desired `h x : A` so `f z - ε < h x z` everywhere
-- and `h x x = f x`.
let h : Π x, L := λ x,
⟨(ys x).sup' (ys_nonempty x) (λ y, (g x y : C(X, ℝ))),
finset.sup'_mem _ sup_mem _ _ _ (λ y _, (g x y).2)⟩,
have lt_h : ∀ x z, f z - ε < h x z,
{ intros x z,
obtain ⟨y, ym, zm⟩ := set.exists_set_mem_of_union_eq_top _ _ (ys_w x) z,
dsimp [h],
simp only [coe_fn_coe_base', subtype.coe_mk, sup'_coe, finset.sup'_apply, finset.lt_sup'_iff],
exact ⟨y, ym, zm⟩ },
have h_eq : ∀ x, h x x = f x,
{ intro x, simp only [coe_fn_coe_base'] at w₁, simp [coe_fn_coe_base', w₁], },
-- For each `x`, we define `W x` to be `{z | h x z < f z + ε}`,
let W : Π x, set X := λ x, {z | h x z < f z + ε},
-- This is still a neighbourhood of `x`.
have W_nhd : ∀ x, W x ∈ 𝓝 x,
{ intros x,
refine is_open.mem_nhds _ _,
{ apply is_open_lt; continuity, },
{ dsimp only [W, set.mem_set_of_eq],
rw h_eq,
exact lt_add_of_pos_right _ pos}, },
-- Since `X` is compact, there is some finset `ys t`
-- so the union of the `W x` for `x ∈ xs` still covers everything.
let xs : finset X := (compact_space.elim_nhds_subcover W W_nhd).some,
let xs_w : (⋃ x ∈ xs, W x) = ⊤ :=
(compact_space.elim_nhds_subcover W W_nhd).some_spec,
have xs_nonempty : xs.nonempty := set.nonempty_of_union_eq_top_of_nonempty _ _ nX xs_w,
-- Finally our candidate function is the infimum over `x ∈ xs` of the `h x`.
-- This function is then globally less than `f z + ε`.
let k : (L : Type*) :=
⟨xs.inf' xs_nonempty (λ x, (h x : C(X, ℝ))),
finset.inf'_mem _ inf_mem _ _ _ (λ x _, (h x).2)⟩,
refine ⟨k.1, _, k.2⟩,
-- We just need to verify the bound, which we do pointwise.
rw dist_lt_iff pos,
intro z,
-- We rewrite into this particular form,
-- so that simp lemmas about inequalities involving `finset.inf'` can fire.
rw [(show ∀ a b ε : ℝ, dist a b < ε ↔ a < b + ε ∧ b - ε < a,
by { intros, simp only [← metric.mem_ball, real.ball_eq_Ioo, set.mem_Ioo, and_comm], })],
fsplit,
{ dsimp [k],
simp only [finset.inf'_lt_iff, continuous_map.inf'_apply],
exact set.exists_set_mem_of_union_eq_top _ _ xs_w z, },
{ dsimp [k],
simp only [finset.lt_inf'_iff, continuous_map.inf'_apply],
intros x xm,
apply lt_h, },
end
/--
The **Stone-Weierstrass Approximation Theorem**,
that a subalgebra `A` of `C(X, ℝ)`, where `X` is a compact topological space,
is dense if it separates points.
-/
theorem subalgebra_topological_closure_eq_top_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points) :
A.topological_closure = ⊤ :=
begin
-- The closure of `A` is closed under taking `sup` and `inf`,
-- and separates points strongly (since `A` does),
-- so we can apply `sublattice_closure_eq_top`.
apply set_like.ext',
let L := A.topological_closure,
have n : set.nonempty (L : set C(X, ℝ)) :=
⟨(1 : C(X, ℝ)), A.subalgebra_topological_closure A.one_mem⟩,
convert sublattice_closure_eq_top
(L : set C(X, ℝ)) n
(λ f g fm gm, inf_mem_closed_subalgebra L A.is_closed_topological_closure ⟨f, fm⟩ ⟨g, gm⟩)
(λ f g fm gm, sup_mem_closed_subalgebra L A.is_closed_topological_closure ⟨f, fm⟩ ⟨g, gm⟩)
(subalgebra.separates_points.strongly
(subalgebra.separates_points_monotone (A.subalgebra_topological_closure) w)),
{ simp, },
end
/--
An alternative statement of the Stone-Weierstrass theorem.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is a uniform limit of elements of `A`.
-/
theorem continuous_map_mem_subalgebra_closure_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : C(X, ℝ)) :
f ∈ A.topological_closure :=
begin
rw subalgebra_topological_closure_eq_top_of_separates_points A w,
simp,
end
/--
An alternative statement of the Stone-Weierstrass theorem,
for those who like their epsilons.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A`.
-/
theorem exists_mem_subalgebra_near_continuous_map_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : C(X, ℝ)) (ε : ℝ) (pos : 0 < ε) :
∃ (g : A), ∥(g : C(X, ℝ)) - f∥ < ε :=
begin
have w := mem_closure_iff_frequently.mp
(continuous_map_mem_subalgebra_closure_of_separates_points A w f),
rw metric.nhds_basis_ball.frequently_iff at w,
obtain ⟨g, H, m⟩ := w ε pos,
rw [metric.mem_ball, dist_eq_norm] at H,
exact ⟨⟨g, m⟩, H⟩,
end
/--
An alternative statement of the Stone-Weierstrass theorem,
for those who like their epsilons and don't like bundled continuous functions.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A`.
-/
theorem exists_mem_subalgebra_near_continuous_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : X → ℝ) (c : continuous f) (ε : ℝ) (pos : 0 < ε) :
∃ (g : A), ∀ x, ∥g x - f x∥ < ε :=
begin
obtain ⟨g, b⟩ := exists_mem_subalgebra_near_continuous_map_of_separates_points A w ⟨f, c⟩ ε pos,
use g,
rwa norm_lt_iff _ pos at b,
end
end continuous_map
section complex
open complex
-- Redefine `X`, since for the next few lemmas it need not be compact
variables {X : Type*} [topological_space X]
namespace continuous_map
/-- A real subalgebra of `C(X, ℂ)` is `conj_invariant`, if it contains all its conjugates. -/
def conj_invariant_subalgebra (A : subalgebra ℝ C(X, ℂ)) : Prop :=
A.map (conj_ae.to_alg_hom.comp_left_continuous ℝ conj_cle.continuous) ≤ A
lemma mem_conj_invariant_subalgebra {A : subalgebra ℝ C(X, ℂ)} (hA : conj_invariant_subalgebra A)
{f : C(X, ℂ)} (hf : f ∈ A) :
(conj_ae.to_alg_hom.comp_left_continuous ℝ conj_cle.continuous) f ∈ A :=
hA ⟨f, hf, rfl⟩
end continuous_map
open continuous_map
/-- If a conjugation-invariant subalgebra of `C(X, ℂ)` separates points, then the real subalgebra
of its purely real-valued elements also separates points. -/
lemma subalgebra.separates_points.complex_to_real {A : subalgebra ℂ C(X, ℂ)}
(hA : A.separates_points) (hA' : conj_invariant_subalgebra (A.restrict_scalars ℝ)) :
((A.restrict_scalars ℝ).comap'
(of_real_am.comp_left_continuous ℝ continuous_of_real)).separates_points :=
begin
intros x₁ x₂ hx,
-- Let `f` in the subalgebra `A` separate the points `x₁`, `x₂`
obtain ⟨_, ⟨f, hfA, rfl⟩, hf⟩ := hA hx,
let F : C(X, ℂ) := f - const (f x₂),
-- Subtract the constant `f x₂` from `f`; this is still an element of the subalgebra
have hFA : F ∈ A,
{ refine A.sub_mem hfA _,
convert A.smul_mem A.one_mem (f x₂),
ext1,
simp },
-- Consider now the function `λ x, |f x - f x₂| ^ 2`
refine ⟨_, ⟨(⟨complex.norm_sq, continuous_norm_sq⟩ : C(ℂ, ℝ)).comp F, _, rfl⟩, _⟩,
{ -- This is also an element of the subalgebra, and takes only real values
rw [set_like.mem_coe, subalgebra.mem_comap],
convert (A.restrict_scalars ℝ).mul_mem (mem_conj_invariant_subalgebra hA' hFA) hFA,
ext1,
exact complex.norm_sq_eq_conj_mul_self },
{ -- And it also separates the points `x₁`, `x₂`
have : f x₁ - f x₂ ≠ 0 := sub_ne_zero.mpr hf,
simpa using this },
end
variables [compact_space X]
/--
The Stone-Weierstrass approximation theorem, complex version,
that a subalgebra `A` of `C(X, ℂ)`, where `X` is a compact topological space,
is dense if it is conjugation-invariant and separates points.
-/
theorem continuous_map.subalgebra_complex_topological_closure_eq_top_of_separates_points
(A : subalgebra ℂ C(X, ℂ)) (hA : A.separates_points)
(hA' : conj_invariant_subalgebra (A.restrict_scalars ℝ)) :
A.topological_closure = ⊤ :=
begin
rw algebra.eq_top_iff,
-- Let `I` be the natural inclusion of `C(X, ℝ)` into `C(X, ℂ)`
let I : C(X, ℝ) →ₗ[ℝ] C(X, ℂ) := of_real_clm.comp_left_continuous ℝ X,
-- The main point of the proof is that its range (i.e., every real-valued function) is contained
-- in the closure of `A`
have key : I.range ≤ (A.to_submodule.restrict_scalars ℝ).topological_closure,
{ -- Let `A₀` be the subalgebra of `C(X, ℝ)` consisting of `A`'s purely real elements; it is the
-- preimage of `A` under `I`. In this argument we only need its submodule structure.
let A₀ : submodule ℝ C(X, ℝ) := (A.to_submodule.restrict_scalars ℝ).comap I,
-- By `subalgebra.separates_points.complex_to_real`, this subalgebra also separates points, so
-- we may apply the real Stone-Weierstrass result to it.
have SW : A₀.topological_closure = ⊤,
{ have := subalgebra_topological_closure_eq_top_of_separates_points _ (hA.complex_to_real hA'),
exact congr_arg subalgebra.to_submodule this },
rw [← submodule.map_top, ← SW],
-- So it suffices to prove that the image under `I` of the closure of `A₀` is contained in the
-- closure of `A`, which follows by abstract nonsense
have h₁ := A₀.topological_closure_map (of_real_clm.comp_left_continuous_compact X),
have h₂ := (A.to_submodule.restrict_scalars ℝ).map_comap_le I,
exact h₁.trans (submodule.topological_closure_mono h₂) },
-- In particular, for a function `f` in `C(X, ℂ)`, the real and imaginary parts of `f` are in the
-- closure of `A`
intros f,
let f_re : C(X, ℝ) := (⟨complex.re, complex.re_clm.continuous⟩ : C(ℂ, ℝ)).comp f,
let f_im : C(X, ℝ) := (⟨complex.im, complex.im_clm.continuous⟩ : C(ℂ, ℝ)).comp f,
have h_f_re : I f_re ∈ A.topological_closure := key ⟨f_re, rfl⟩,
have h_f_im : I f_im ∈ A.topological_closure := key ⟨f_im, rfl⟩,
-- So `f_re + complex.I • f_im` is in the closure of `A`
convert A.topological_closure.add_mem h_f_re (A.topological_closure.smul_mem h_f_im complex.I),
-- And this, of course, is just `f`
ext; simp [I]
end
end complex
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import algebra.homology.image_to_kernel
/-!
# Exact sequences
In a category with zero morphisms, images, and equalizers we say that `f : A ⟶ B` and `g : B ⟶ C`
are exact if `f ≫ g = 0` and the natural map `image f ⟶ kernel g` is an epimorphism.
In any preadditive category this is equivalent to the homology at `B` vanishing.
However in general it is weaker than other reasonable definitions of exactness,
particularly that
1. the inclusion map `image.ι f` is a kernel of `g` or
2. `image f ⟶ kernel g` is an isomorphism or
3. `image_subobject f = kernel_subobject f`.
However when the category is abelian, these all become equivalent;
these results are found in `category_theory/abelian/exact.lean`.
# Main results
* Suppose that cokernels exist and that `f` and `g` are exact.
If `s` is any kernel fork over `g` and `t` is any cokernel cofork over `f`,
then `fork.ι s ≫ cofork.π t = 0`.
* Precomposing the first morphism with an epimorphism retains exactness.
Postcomposing the second morphism with a monomorphism retains exactness.
* If `f` and `g` are exact and `i` is an isomorphism,
then `f ≫ i.hom` and `i.inv ≫ g` are also exact.
# Future work
* Short exact sequences, split exact sequences, the splitting lemma (maybe only for abelian
categories?)
* Two adjacent maps in a chain complex are exact iff the homology vanishes
-/
universes v v₂ u u₂
open category_theory
open category_theory.limits
variables {V : Type u} [category.{v} V]
variables [has_images V]
namespace category_theory
/--
Two morphisms `f : A ⟶ B`, `g : B ⟶ C` are called exact if `w : f ≫ g = 0` and the natural map
`image_to_kernel f g w : image_subobject f ⟶ kernel_subobject g` is an epimorphism.
In any preadditive category, this is equivalent to `w : f ≫ g = 0` and `homology f g w ≅ 0`.
In an abelian category, this is equivalent to `image_to_kernel f g w` being an isomorphism,
and hence equivalent to the usual definition,
`image_subobject f = kernel_subobject g`.
-/
-- One nice feature of this definition is that we have
-- `epi f → exact g h → exact (f ≫ g) h` and `exact f g → mono h → exact f (g ≫ h)`,
-- which do not necessarily hold in a non-abelian category with the usual definition of `exact`.
structure exact [has_zero_morphisms V] [has_kernels V] {A B C : V} (f : A ⟶ B) (g : B ⟶ C) : Prop :=
(w : f ≫ g = 0)
(epi : epi (image_to_kernel f g w))
-- This works as an instance even though `exact` itself is not a class, as long as the goal is
-- literally of the form `epi (image_to_kernel f g h.w)` (where `h : exact f g`). If the proof of
-- `f ≫ g = 0` looks different, we are out of luck and have to add the instance by hand.
attribute [instance] exact.epi
attribute [reassoc] exact.w
section
variables [has_zero_object V] [preadditive V] [has_kernels V] [has_cokernels V]
open_locale zero_object
/--
In any preadditive category,
composable morphisms `f g` are exact iff they compose to zero and the homology vanishes.
-/
lemma preadditive.exact_iff_homology_zero {A B C : V} (f : A ⟶ B) (g : B ⟶ C) :
exact f g ↔ ∃ w : f ≫ g = 0, nonempty (homology f g w ≅ 0) :=
⟨λ h, ⟨h.w, ⟨cokernel.of_epi _⟩⟩,
λ h, begin
obtain ⟨w, ⟨i⟩⟩ := h,
exact ⟨w, preadditive.epi_of_cokernel_zero ((cancel_mono i.hom).mp (by ext))⟩,
end⟩
lemma preadditive.exact_of_iso_of_exact {A₁ B₁ C₁ A₂ B₂ C₂ : V}
(f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂)
(α : arrow.mk f₁ ≅ arrow.mk f₂) (β : arrow.mk g₁ ≅ arrow.mk g₂) (p : α.hom.right = β.hom.left)
(h : exact f₁ g₁) :
exact f₂ g₂ :=
begin
rw preadditive.exact_iff_homology_zero at h ⊢,
rcases h with ⟨w₁, ⟨i⟩⟩,
suffices w₂ : f₂ ≫ g₂ = 0, from ⟨w₂, ⟨(homology.map_iso w₁ w₂ α β p).symm.trans i⟩⟩,
rw [← cancel_epi α.hom.left, ← cancel_mono β.inv.right, comp_zero, zero_comp, ← w₁],
simp only [← arrow.mk_hom f₁, ← arrow.left_hom_inv_right α.hom,
← arrow.mk_hom g₁, ← arrow.left_hom_inv_right β.hom, p],
simp only [arrow.mk_hom, is_iso.inv_hom_id_assoc, category.assoc, ← arrow.inv_right,
is_iso.iso.inv_hom]
end
/-- A reformulation of `preadditive.exact_of_iso_of_exact` that does not involve the arrow
category. -/
lemma preadditive.exact_of_iso_of_exact' {A₁ B₁ C₁ A₂ B₂ C₂ : V}
(f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂)
(α : A₁ ≅ A₂) (β : B₁ ≅ B₂) (γ : C₁ ≅ C₂) (hsq₁ : α.hom ≫ f₂ = f₁ ≫ β.hom)
(hsq₂ : β.hom ≫ g₂ = g₁ ≫ γ.hom)
(h : exact f₁ g₁) :
exact f₂ g₂ :=
preadditive.exact_of_iso_of_exact f₁ g₁ f₂ g₂ (arrow.iso_mk α β hsq₁) (arrow.iso_mk β γ hsq₂) rfl h
lemma preadditive.exact_iff_exact_of_iso {A₁ B₁ C₁ A₂ B₂ C₂ : V}
(f₁ : A₁ ⟶ B₁) (g₁ : B₁ ⟶ C₁) (f₂ : A₂ ⟶ B₂) (g₂ : B₂ ⟶ C₂)
(α : arrow.mk f₁ ≅ arrow.mk f₂) (β : arrow.mk g₁ ≅ arrow.mk g₂) (p : α.hom.right = β.hom.left) :
exact f₁ g₁ ↔ exact f₂ g₂ :=
⟨preadditive.exact_of_iso_of_exact _ _ _ _ _ _ p,
preadditive.exact_of_iso_of_exact _ _ _ _ α.symm β.symm
begin
rw ← cancel_mono α.hom.right,
simp only [iso.symm_hom, ← comma.comp_right, α.inv_hom_id],
simp only [p, ←comma.comp_left, arrow.id_right, arrow.id_left, iso.inv_hom_id],
refl
end⟩
end
section
variables [has_zero_morphisms V] [has_kernels V]
lemma comp_eq_zero_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C)
(p : image_subobject f = kernel_subobject g) : f ≫ g = 0 :=
begin
rw [←image_subobject_arrow_comp f, category.assoc],
convert comp_zero,
rw p,
simp,
end
lemma image_to_kernel_is_iso_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C)
(p : image_subobject f = kernel_subobject g) :
is_iso (image_to_kernel f g (comp_eq_zero_of_image_eq_kernel f g p)) :=
begin
refine ⟨⟨subobject.of_le _ _ p.ge, _⟩⟩,
dsimp [image_to_kernel],
simp only [subobject.of_le_comp_of_le, subobject.of_le_refl],
simp,
end
-- We'll prove the converse later, when `V` is abelian.
lemma exact_of_image_eq_kernel {A B C : V} (f : A ⟶ B) (g : B ⟶ C)
(p : image_subobject f = kernel_subobject g) : exact f g :=
{ w := comp_eq_zero_of_image_eq_kernel f g p,
epi := begin
haveI := image_to_kernel_is_iso_of_image_eq_kernel f g p,
apply_instance,
end }
end
variables {A B C D : V} {f : A ⟶ B} {g : B ⟶ C} {h : C ⟶ D}
local attribute [instance] epi_comp
section
variables [has_zero_morphisms V] [has_equalizers V]
lemma exact_comp_hom_inv_comp (i : B ≅ D) (h : exact f g) : exact (f ≫ i.hom) (i.inv ≫ g) :=
begin
refine ⟨by simp [h.w], _⟩,
rw image_to_kernel_comp_hom_inv_comp,
haveI := h.epi,
apply_instance,
end
lemma exact_comp_inv_hom_comp (i : D ≅ B) (h : exact f g) : exact (f ≫ i.inv) (i.hom ≫ g) :=
exact_comp_hom_inv_comp i.symm h
lemma exact_comp_hom_inv_comp_iff (i : B ≅ D) : exact (f ≫ i.hom) (i.inv ≫ g) ↔ exact f g :=
⟨λ h, by simpa using exact_comp_inv_hom_comp i h, exact_comp_hom_inv_comp i⟩
lemma exact_epi_comp (hgh : exact g h) [epi f] : exact (f ≫ g) h :=
begin
refine ⟨by simp [hgh.w], _⟩,
rw image_to_kernel_comp_left,
apply_instance,
end
@[simp]
lemma exact_iso_comp [is_iso f] : exact (f ≫ g) h ↔ exact g h :=
⟨λ w, by { rw ←is_iso.inv_hom_id_assoc f g, exact exact_epi_comp w }, λ w, exact_epi_comp w⟩
lemma exact_comp_mono (hfg : exact f g) [mono h] : exact f (g ≫ h) :=
begin
refine ⟨by simp [hfg.w_assoc], _⟩,
rw image_to_kernel_comp_right f g h hfg.w,
apply_instance,
end
/-- The dual of this lemma is only true when `V` is abelian, see `abelian.exact_epi_comp_iff`. -/
lemma exact_comp_mono_iff [mono h] : exact f (g ≫ h) ↔ exact f g :=
begin
refine ⟨λ hfg, ⟨zero_of_comp_mono h (by rw [category.assoc, hfg.1]), _⟩, λ h, exact_comp_mono h⟩,
rw ← (iso.eq_comp_inv _).1 (image_to_kernel_comp_mono _ _ h hfg.1),
haveI := hfg.2, apply_instance
end
@[simp]
lemma exact_kernel_subobject_arrow : exact (kernel_subobject f).arrow f :=
begin
refine ⟨by simp, _⟩,
apply @is_iso.epi_of_iso _ _ _ _ _ _,
exact ⟨⟨factor_thru_image_subobject _, by { ext, simp, }, by { ext, simp, }⟩⟩,
end
lemma exact_kernel_ι : exact (kernel.ι f) f :=
by { rw [←kernel_subobject_arrow', exact_iso_comp], exact exact_kernel_subobject_arrow }
instance (h : exact f g) : epi (factor_thru_kernel_subobject g f h.w) :=
begin
rw ←factor_thru_image_subobject_comp_image_to_kernel,
apply epi_comp,
end
instance (h : exact f g) : epi (kernel.lift g f h.w) :=
begin
rw ←factor_thru_kernel_subobject_comp_kernel_subobject_iso,
apply epi_comp
end
variables (A)
lemma kernel_subobject_arrow_eq_zero_of_exact_zero_left (h : exact (0 : A ⟶ B) g) :
(kernel_subobject g).arrow = 0 :=
begin
rw [←cancel_epi (image_to_kernel (0 : A ⟶ B) g h.w),
←cancel_epi (factor_thru_image_subobject (0 : A ⟶ B))],
simp
end
lemma kernel_ι_eq_zero_of_exact_zero_left (h : exact (0 : A ⟶ B) g) :
kernel.ι g = 0 :=
by { rw ←kernel_subobject_arrow', simp [kernel_subobject_arrow_eq_zero_of_exact_zero_left A h], }
lemma exact_zero_left_of_mono [has_zero_object V] [mono g] : exact (0 : A ⟶ B) g :=
⟨by simp, image_to_kernel_epi_of_zero_of_mono _⟩
end
section has_cokernels
variables [has_zero_morphisms V] [has_equalizers V] [has_cokernels V] (f g)
@[simp, reassoc] lemma kernel_comp_cokernel (h : exact f g) : kernel.ι g ≫ cokernel.π f = 0 :=
begin
rw [←kernel_subobject_arrow', category.assoc],
convert comp_zero,
apply zero_of_epi_comp (image_to_kernel f g h.w) _,
rw [image_to_kernel_arrow_assoc, ←image_subobject_arrow, category.assoc, ←iso.eq_inv_comp],
ext,
simp,
end
lemma comp_eq_zero_of_exact (h : exact f g) {X Y : V} {ι : X ⟶ B} (hι : ι ≫ g = 0) {π : B ⟶ Y}
(hπ : f ≫ π = 0) : ι ≫ π = 0 :=
by rw [←kernel.lift_ι _ _ hι, ←cokernel.π_desc _ _ hπ, category.assoc,
kernel_comp_cokernel_assoc _ _ h, zero_comp, comp_zero]
@[simp, reassoc] lemma fork_ι_comp_cofork_π (h : exact f g) (s : kernel_fork g)
(t : cokernel_cofork f) : fork.ι s ≫ cofork.π t = 0 :=
comp_eq_zero_of_exact f g h (kernel_fork.condition s) (cokernel_cofork.condition t)
end has_cokernels
section
variables [has_zero_object V]
open_locale zero_object
section
variables [has_zero_morphisms V] [has_kernels V]
lemma exact_of_zero {A C : V} (f : A ⟶ 0) (g : 0 ⟶ C) : exact f g :=
begin
obtain rfl : f = 0 := by ext,
obtain rfl : g = 0 := by ext,
fsplit,
{ simp, },
{ exact image_to_kernel_epi_of_zero_of_mono 0, },
end
lemma exact_zero_mono {B C : V} (f : B ⟶ C) [mono f] : exact (0 : (0 ⟶ B)) f :=
⟨by simp, infer_instance⟩
lemma exact_epi_zero {A B : V} (f : A ⟶ B) [epi f] : exact f (0 : (B ⟶ 0)) :=
⟨by simp, infer_instance⟩
end
section
variables [preadditive V]
lemma mono_iff_exact_zero_left [has_kernels V] {B C : V} (f : B ⟶ C) :
mono f ↔ exact (0 : (0 ⟶ B)) f :=
⟨λ h, by exactI exact_zero_mono _,
λ h, preadditive.mono_of_kernel_iso_zero
((kernel_subobject_iso f).symm ≪≫ iso_zero_of_epi_zero (by simpa using h.epi))⟩
lemma epi_iff_exact_zero_right [has_equalizers V] {A B : V} (f : A ⟶ B) :
epi f ↔ exact f (0 : (B ⟶ 0)) :=
⟨λ h, by exactI exact_epi_zero _,
λ h, begin
have e₁ := h.epi,
rw image_to_kernel_zero_right at e₁,
have e₂ : epi (((image_subobject f).arrow ≫ inv (kernel_subobject 0).arrow) ≫
(kernel_subobject 0).arrow) := @epi_comp _ _ _ _ _ _ e₁ _ _,
rw [category.assoc, is_iso.inv_hom_id, category.comp_id] at e₂,
rw [←image_subobject_arrow] at e₂,
resetI,
haveI : epi (image.ι f) := epi_of_epi (image_subobject_iso f).hom (image.ι f),
apply epi_of_epi_image,
end⟩
end
end
namespace functor
variables [has_zero_morphisms V] [has_kernels V] {W : Type u₂} [category.{v₂} W]
variables [has_images W] [has_zero_morphisms W] [has_kernels W]
/-- A functor reflects exact sequences if any composable pair of morphisms that is mapped to an
exact pair is itself exact. -/
class reflects_exact_sequences (F : V ⥤ W) :=
(reflects : ∀ {A B C : V} (f : A ⟶ B) (g : B ⟶ C), exact (F.map f) (F.map g) → exact f g)
lemma exact_of_exact_map (F : V ⥤ W) [reflects_exact_sequences F] {A B C : V} {f : A ⟶ B}
{g : B ⟶ C} (hfg : exact (F.map f) (F.map g)) : exact f g :=
reflects_exact_sequences.reflects f g hfg
end functor
end category_theory
|
Rachel is considered to be Aniston 's breakout role , credited with making her the show 's most famous cast member and for spawning her successful film career . Praised for her performance as Rachel , Aniston won both an Emmy Award for Outstanding Lead Actress in a Comedy Series and a Golden Globe Award for Best Performance by an Actress In A Television Series – Comedy Or Musical .
|
If $g$ is $o(f)$, then $L(f) \subseteq L(\lambda x. f(x) + g(x))$. |
module Haskell.Prim.List where
open import Agda.Builtin.List public
open import Agda.Builtin.Nat
open import Haskell.Prim
open import Haskell.Prim.Tuple
open import Haskell.Prim.Bool
open import Haskell.Prim.Int
--------------------------------------------------
-- List
map : (a → b) → List a → List b
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
infixr 5 _++_
_++_ : ∀ {ℓ} {a : Set ℓ} → List a → List a → List a
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ xs ++ ys
filter : (a → Bool) → List a → List a
filter p [] = []
filter p (x ∷ xs) = if p x then x ∷ filter p xs else filter p xs
scanl : (b → a → b) → b → List a → List b
scanl f z [] = z ∷ []
scanl f z (x ∷ xs) = z ∷ scanl f (f z x) xs
scanr : (a → b → b) → b → List a → List b
scanr f z [] = z ∷ []
scanr f z (x ∷ xs) =
case scanr f z xs of λ where
[] → [] -- impossible
qs@(q ∷ _) → f x q ∷ qs
scanl1 : (a → a → a) → List a → List a
scanl1 f [] = []
scanl1 f (x ∷ xs) = scanl f x xs
scanr1 : (a → a → a) → List a → List a
scanr1 f [] = []
scanr1 f (x ∷ []) = x ∷ []
scanr1 f (x ∷ xs) =
case scanr1 f xs of λ where
[] → [] -- impossible
qs@(q ∷ _) → f x q ∷ qs
takeWhile : (a → Bool) → List a → List a
takeWhile p [] = []
takeWhile p (x ∷ xs) = if p x then x ∷ takeWhile p xs else []
dropWhile : (a → Bool) → List a → List a
dropWhile p [] = []
dropWhile p (x ∷ xs) = if p x then dropWhile p xs else x ∷ xs
span : (a → Bool) → List a → List a × List a
span p [] = [] , []
span p (x ∷ xs) = if p x then first (x ∷_) (span p xs)
else ([] , x ∷ xs)
break : (a → Bool) → List a → List a × List a
break p = span (not ∘ p)
zipWith : (a → b → c) → List a → List b → List c
zipWith f [] _ = []
zipWith f _ [] = []
zipWith f (x ∷ xs) (y ∷ ys) = f x y ∷ zipWith f xs ys
zip : List a → List b → List (a × b)
zip = zipWith _,_
zipWith3 : (a → b → c → d) → List a → List b → List c → List d
zipWith3 f [] _ _ = []
zipWith3 f _ [] _ = []
zipWith3 f _ _ [] = []
zipWith3 f (x ∷ xs) (y ∷ ys) (z ∷ zs) = f x y z ∷ zipWith3 f xs ys zs
zip3 : List a → List b → List c → List (a × b × c)
zip3 = zipWith3 _,_,_
unzip : List (a × b) → List a × List b
unzip [] = [] , []
unzip ((x , y) ∷ xys) = (x ∷_) *** (y ∷_) $ unzip xys
unzip3 : List (a × b × c) → List a × List b × List c
unzip3 [] = [] , [] , []
unzip3 ((x , y , z) ∷ xyzs) =
case unzip3 xyzs of λ where
(xs , ys , zs) → x ∷ xs , y ∷ ys , z ∷ zs
takeNat : Nat → List a → List a
takeNat n [] = []
takeNat zero xs = []
takeNat (suc n) (x ∷ xs) = x ∷ takeNat n xs
take : (n : Int) → ⦃ IsNonNegativeInt n ⦄ → List a → List a
take n xs = takeNat (intToNat n) xs
dropNat : Nat → List a → List a
dropNat n [] = []
dropNat zero xs = xs
dropNat (suc n) (_ ∷ xs) = dropNat n xs
drop : (n : Int) → ⦃ IsNonNegativeInt n ⦄ → List a → List a
drop n xs = dropNat (intToNat n) xs
splitAtNat : (n : Nat) → List a → List a × List a
splitAtNat _ [] = [] , []
splitAtNat 0 xs = [] , xs
splitAtNat (suc n) (x ∷ xs) = first (x ∷_) (splitAtNat n xs)
splitAt : (n : Int) → ⦃ IsNonNegativeInt n ⦄ → List a → List a × List a
splitAt n xs = splitAtNat (intToNat n) xs
head : (xs : List a) → ⦃ NonEmpty xs ⦄ → a
head (x ∷ _) = x
tail : (xs : List a) → ⦃ NonEmpty xs ⦄ → List a
tail (_ ∷ xs) = xs
last : (xs : List a) → ⦃ NonEmpty xs ⦄ → a
last (x ∷ []) = x
last (_ ∷ xs@(_ ∷ _)) = last xs
init : (xs : List a) → ⦃ NonEmpty xs ⦄ → List a
init (x ∷ []) = []
init (x ∷ xs@(_ ∷ _)) = x ∷ init xs
|
[STATEMENT]
lemma unit_prod:
assumes "finite S"
shows "is_unit (prod (\<lambda>i. U $ i $ i) S) = (\<forall>i\<in>S. is_unit (U $ i $ i))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. is_unit (\<Prod>i\<in>S. U $ i $ i) = (\<forall>i\<in>S. is_unit (U $ i $ i))
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
finite S
goal (1 subgoal):
1. is_unit (\<Prod>i\<in>S. U $ i $ i) = (\<forall>i\<in>S. is_unit (U $ i $ i))
[PROOF STEP]
proof (induct)
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. is_unit (\<Prod>i\<in>{}. U $ i $ i) = (\<forall>i\<in>{}. is_unit (U $ i $ i))
2. \<And>x F. \<lbrakk>finite F; x \<notin> F; is_unit (\<Prod>i\<in>F. U $ i $ i) = (\<forall>i\<in>F. is_unit (U $ i $ i))\<rbrakk> \<Longrightarrow> is_unit (\<Prod>i\<in>insert x F. U $ i $ i) = (\<forall>i\<in>insert x F. is_unit (U $ i $ i))
[PROOF STEP]
case empty
[PROOF STATE]
proof (state)
this:
goal (2 subgoals):
1. is_unit (\<Prod>i\<in>{}. U $ i $ i) = (\<forall>i\<in>{}. is_unit (U $ i $ i))
2. \<And>x F. \<lbrakk>finite F; x \<notin> F; is_unit (\<Prod>i\<in>F. U $ i $ i) = (\<forall>i\<in>F. is_unit (U $ i $ i))\<rbrakk> \<Longrightarrow> is_unit (\<Prod>i\<in>insert x F. U $ i $ i) = (\<forall>i\<in>insert x F. is_unit (U $ i $ i))
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. is_unit (\<Prod>i\<in>{}. U $ i $ i) = (\<forall>i\<in>{}. is_unit (U $ i $ i))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
is_unit (\<Prod>i\<in>{}. U $ i $ i) = (\<forall>i\<in>{}. is_unit (U $ i $ i))
goal (1 subgoal):
1. \<And>x F. \<lbrakk>finite F; x \<notin> F; is_unit (\<Prod>i\<in>F. U $ i $ i) = (\<forall>i\<in>F. is_unit (U $ i $ i))\<rbrakk> \<Longrightarrow> is_unit (\<Prod>i\<in>insert x F. U $ i $ i) = (\<forall>i\<in>insert x F. is_unit (U $ i $ i))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<And>x F. \<lbrakk>finite F; x \<notin> F; is_unit (\<Prod>i\<in>F. U $ i $ i) = (\<forall>i\<in>F. is_unit (U $ i $ i))\<rbrakk> \<Longrightarrow> is_unit (\<Prod>i\<in>insert x F. U $ i $ i) = (\<forall>i\<in>insert x F. is_unit (U $ i $ i))
[PROOF STEP]
case (insert a S)
[PROOF STATE]
proof (state)
this:
finite S
a \<notin> S
is_unit (\<Prod>i\<in>S. U $ i $ i) = (\<forall>i\<in>S. is_unit (U $ i $ i))
goal (1 subgoal):
1. \<And>x F. \<lbrakk>finite F; x \<notin> F; is_unit (\<Prod>i\<in>F. U $ i $ i) = (\<forall>i\<in>F. is_unit (U $ i $ i))\<rbrakk> \<Longrightarrow> is_unit (\<Prod>i\<in>insert x F. U $ i $ i) = (\<forall>i\<in>insert x F. is_unit (U $ i $ i))
[PROOF STEP]
have "prod (\<lambda>i. U $ i $ i) (insert a S) = U $ a $ a * prod (\<lambda>i. U $ i $ i) S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<Prod>i\<in>insert a S. U $ i $ i) = U $ a $ a * (\<Prod>i\<in>S. U $ i $ i)
[PROOF STEP]
by (simp add: insert.hyps(2))
[PROOF STATE]
proof (state)
this:
(\<Prod>i\<in>insert a S. U $ i $ i) = U $ a $ a * (\<Prod>i\<in>S. U $ i $ i)
goal (1 subgoal):
1. \<And>x F. \<lbrakk>finite F; x \<notin> F; is_unit (\<Prod>i\<in>F. U $ i $ i) = (\<forall>i\<in>F. is_unit (U $ i $ i))\<rbrakk> \<Longrightarrow> is_unit (\<Prod>i\<in>insert x F. U $ i $ i) = (\<forall>i\<in>insert x F. is_unit (U $ i $ i))
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
using this:
(\<Prod>i\<in>insert a S. U $ i $ i) = U $ a $ a * (\<Prod>i\<in>S. U $ i $ i)
goal (1 subgoal):
1. is_unit (\<Prod>i\<in>insert a S. U $ i $ i) = (\<forall>i\<in>insert a S. is_unit (U $ i $ i))
[PROOF STEP]
using is_unit_mult_iff insert.hyps
[PROOF STATE]
proof (prove)
using this:
(\<Prod>i\<in>insert a S. U $ i $ i) = U $ a $ a * (\<Prod>i\<in>S. U $ i $ i)
is_unit (?a * ?b) = (is_unit ?a \<and> is_unit ?b)
finite S
a \<notin> S
is_unit (\<Prod>i\<in>S. U $ i $ i) = (\<forall>i\<in>S. is_unit (U $ i $ i))
goal (1 subgoal):
1. is_unit (\<Prod>i\<in>insert a S. U $ i $ i) = (\<forall>i\<in>insert a S. is_unit (U $ i $ i))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
is_unit (\<Prod>i\<in>insert a S. U $ i $ i) = (\<forall>i\<in>insert a S. is_unit (U $ i $ i))
goal:
No subgoals!
[PROOF STEP]
qed |
lemma continuous_on_prod' [continuous_intros]: fixes f :: "'a \<Rightarrow> 'b::topological_space \<Rightarrow> 'c::topological_comm_monoid_mult" shows "(\<And>i. i \<in> I \<Longrightarrow> continuous_on S (f i)) \<Longrightarrow> continuous_on S (\<lambda>x. \<Prod>i\<in>I. f i x)" |
(*****************************************************************************
* ESPL --- an embedded security protocol logic
* http://people.inf.ethz.ch/meiersi/espl/
*
* Copyright (c) 2009-2011, Simon Meier, ETH Zurich, Switzerland
*
* All rights reserved. See file LICENCE for more information.
******************************************************************************)
(* Extensions to the standard HOL library *)
theory HOL_ext
imports
Main
begin
section{* Maps *}
lemma dom_upd [simp]:
"dom (\<lambda> a. if a = x then Some y else m a) = insert x (dom m)"
by(fastforce simp: dom_if)
lemma map_leD: "\<lbrakk> m \<subseteq>\<^sub>m m'; m x = Some y \<rbrakk> \<Longrightarrow> m' x = Some y"
by(force simp: map_le_def)
lemma rev_map_leD: "\<lbrakk> m x = Some y; m \<subseteq>\<^sub>m m' \<rbrakk> \<Longrightarrow> m' x = Some y"
by(force simp: map_le_def)
lemma map_leI:
"\<lbrakk> \<And> x y. m x = Some y \<Longrightarrow> m' x = Some y \<rbrakk> \<Longrightarrow> m \<subseteq>\<^sub>m m'"
by(force simp: map_le_def)
section{* Option *}
fun opt_map2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a option \<Rightarrow> 'b option \<Rightarrow> 'c option"
where
"opt_map2 f (Some x) (Some y) = Some (f x y)"
| "opt_map2 f _ _ = None"
lemma Some_opt_map2 [simp]:
"(Some x = opt_map2 f a b) =
(\<exists> y z. x = f y z \<and> Some y = a \<and> Some z = b)"
"(opt_map2 f a b = Some x) =
(\<exists> y z. x = f y z \<and> Some y = a \<and> Some z = b)"
by (cases a, simp, cases b, simp_all add: eq_commute)+
lemma Some_if_pushL [simp]:
"(Some x = (if b then Some y else None)) = (b \<and> x = y)"
"((if b then Some y else None) = Some x) = (b \<and> x = y)"
by (auto split: if_splits)
lemma Some_if_pushR [simp]:
"(Some x = (if b then None else Some y)) = (\<not>b \<and> x = y)"
"((if b then None else Some y) = Some x) = (\<not>b \<and> x = y)"
by (auto split: if_splits)
lemma Some_Option_map [simp]:
"(Some x = map_option f a) = (\<exists>y. x = f y \<and> Some y = a)"
"(map_option f a = Some x) = (\<exists>y. x = f y \<and> Some y = a)"
by (cases a, auto)+
section{* Variadic Functions *}
datatype ('a, 'b) varfun = Val 'b | Fun "'a \<Rightarrow> ('a, 'b) varfun"
primrec var_map :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a, 'b) varfun \<Rightarrow> ('a, 'c) varfun"
where
"var_map f (Val x) = Val (f x)"
| "var_map f (Fun g) = Fun (\<lambda>x. var_map f (g x))"
primrec var_apply :: "('a, 'b \<Rightarrow> 'c) varfun \<Rightarrow> ('a, 'b) varfun \<Rightarrow> ('a, 'c) varfun"
where
"var_apply (Val f) v = var_map f v"
| "var_apply (Fun g) v = Fun (\<lambda>x. var_apply (g x) v)"
abbreviation var_lift2 :: "('b \<Rightarrow> 'c \<Rightarrow> 'd) \<Rightarrow> ('a, 'b) varfun \<Rightarrow> ('a, 'c) varfun \<Rightarrow> ('a, 'd) varfun"
where "var_lift2 f v1 v2 \<equiv> var_apply (var_map f v1) v2"
primrec var_fold :: "(('a \<Rightarrow> 'b) \<Rightarrow> 'b) \<Rightarrow> ('a, 'b) varfun \<Rightarrow> 'b"
where
"var_fold f (Val x) = x"
| "var_fold f (Fun g) = f (\<lambda>x. var_fold f (g x))"
lemma var_map_map [simp]: "var_map f (var_map g v) = var_map (f o g) v"
by (induct v) (auto)
lemma var_fold_not_all: "(\<not> var_fold All v) = var_fold Ex (var_map Not v)"
by (induct v) (auto)
lemma var_fold_not_ex: "(\<not> var_fold Ex v) = var_fold All (var_map Not v)"
by (induct v) (auto)
section{* Finite Sets *}
text{*
Automating the simplification of differences of finite sets.
*}
lemma eq_conj_neq:
"y \<noteq> z \<Longrightarrow> (x = y \<and> x \<noteq> z) = (x = y)"
"y \<noteq> z \<Longrightarrow> (x = y \<and> (x \<noteq> z \<and> P)) = ((x = y) \<and> P)"
"y \<noteq> z \<Longrightarrow> (x = y \<and> (P \<and> x \<noteq> z)) = ((x = y) \<and> P)"
"y \<noteq> z \<Longrightarrow> (x \<noteq> z \<and> x = y) = (x = y)"
"y \<noteq> z \<Longrightarrow> ((x \<noteq> z \<and> P) \<and> x = y) = ((x = y) \<and> P)"
"y \<noteq> z \<Longrightarrow> ((P \<and> x \<noteq> z) \<and> x = y) = ((x = y) \<and> P)"
by(auto)
lemmas finite_setdiff_compute =
conj_disj_distribL
conj_disj_distribR
ex_disj_distrib
eq_conj_neq
disj_ac
subsection{* Extensions to ML infrastructure for HOL *}
lemma HOL_concl_revcut_rl:
"\<lbrakk> PROP V; PROP V \<Longrightarrow> W \<rbrakk> \<Longrightarrow> W"
by simp
ML{*
signature HOL_EXT =
sig
(* Gather bound variables *)
val add_bound_list : term -> int list -> int list
(* Permutations of all quantifiers *)
val invert_perm : int list -> int list
val forall_permute : Proof.context -> int list -> cterm -> thm
val forall_permute_conv : Proof.context -> int list -> cterm -> thm
(* Theorem modifications *)
val beta_norm_thm : thm -> thm
val make_HOL_elim : thm -> thm
val protect_concl : thm -> thm
val lift_ground_thm_mod
: Proof.context -> (Proof.context -> thm -> thm) -> thm -> thm
(* Applying tactics to theorems *)
val rule_by_tactic
: Proof.context -> (Proof.context -> thm -> thm Seq.seq) -> thm -> thm
val refine_rule
: Proof.context -> (Proof.context -> thm -> thm Seq.seq) -> thm -> thm
val track_HOL_term
: Proof.context -> term -> (thm * (thm -> thm)) * Proof.context
end;
*}
ML{*
structure HOL_Ext: HOL_EXT =
struct
(* gather a list of bound variables *)
val add_bound_list =
(fn f => rev o f) o fold_aterms (fn Bound i => (fn is => i::is) | _ => I);
(* invert a permutation *)
fun invert_perm p =
p ~~ (0 upto (length p - 1))
|> sort (int_ord o pairself fst)
|> map snd
(* Prove the permutation of the outermost all quantifiers:
!!x0 .. x(n-1). A |- !!x[p0] .. x[p(n-1)]. A
PRE: No meta-variables in the given cterm.
*)
fun forall_permute ctxt p ct =
let
val cert = Thm.cterm_of (Proof_Context.theory_of ctxt);
fun mk_cv (_, ty) n = cert (Free (n, ty));
val string_of_perm = commas o map string_of_int;
fun err msg = raise CTERM
( "forall_permute: " ^ msg ^ " [" ^ string_of_perm p ^ "]"
, [ct] );
val t = Thm.term_of ct;
val n = length p;
val vs = t |> Term.strip_all_vars |> #1 o chop n;
val () = if n <> length vs
then err "too many variables referenced"
else ();
val (vns', _) = Variable.variant_fixes (map fst vs) ctxt;
val cvs' = map2 mk_cv vs vns';
val cpvs' =
map (nth cvs') p
handle Subscript => err "wrong subscript in permutation";
in
ct
|> Thm.assume
|> forall_elim_list cvs'
|> forall_intr_list cpvs'
end
(* Prove the conversion permuting the variables:
(!!x0 .. x(n-1). A) == (!!x[p0] .. x[p(n-1)]. A)
*)
fun forall_permute_conv ctxt p ct =
let
val lr = forall_permute ctxt p ct;
val ct' = Thm.cprop_of lr;
val rl = forall_permute ctxt (invert_perm p) ct';
in
Thm.equal_intr (Thm.implies_intr ct lr)
(Thm.implies_intr ct' rl)
end;
(* Beta-normal form of a theorem *)
fun beta_norm_thm th =
Thm.equal_elim (Thm.beta_conversion true (Thm.cprop_of th)) th
(* make an elim rule with a "Trueprop ?R" concluion *)
fun make_HOL_elim rl =
zero_var_indexes (rl RS @{thm HOL_concl_revcut_rl})
(*
A ==> ... ==> C
---------------- (protect_concl)
A ==> ... ==> #C
*)
fun protect_concl th =
Drule.comp_no_flatten (th, Thm.nprems_of th) 1 Drule.protectI;
(* Modify a theorem using a function thm -> thm that requires the theorem
to contain no schematic variables.
*)
fun lift_ground_thm_mod ctxt f th =
let
val ((_, [th']), ctxt') = Variable.import true [th] ctxt;
in
f ctxt' th'
|> singleton (Variable.export ctxt' ctxt)
|> zero_var_indexes
end;
(*Makes a rule by applying a tactic to an existing rule.
Copied from 'tactic.ML' and fixed such that the current context
is taken as an argument to avoid clashes with free variables referenced
by facts used by the tactic.
*)
fun rule_by_tactic ctxt tac rl =
lift_ground_thm_mod ctxt
(fn ctxt' => fn st =>
case Seq.pull (tac ctxt' st) of
NONE => raise THM ("rule_by_tactic", 0, [rl])
| SOME (st', _) => st')
rl;
(* Apply a tactic to the premises of an elim rule *)
fun refine_rule ctxt tac =
Goal.conclude o rule_by_tactic ctxt tac o protect_concl
(* Returns a theorem of the for "Q x |- Q x" together with
a removal function that can be used to eliminate the "Q x"
assumption by replacing it with (\y. x = y). The given
theorem can be used to track the conversions of "x" that
happen when using automatic tools. Just insert the given
theorem.
*)
fun track_HOL_term ctxt x_t =
let
val thy = Proof_Context.theory_of ctxt;
val cert = Thm.cterm_of thy;
val x_ty = Term.fastype_of x_t;
val ([Q_n],ctxt') = Variable.variant_fixes ["Q"] ctxt;
val Q_ty = x_ty --> HOLogic.boolT;
val Q_t = Free (Q_n, Q_ty);
val Q_ct = cert Q_t;
val Qx_ct = cert (HOLogic.mk_Trueprop (Q_t $ x_t));
val eq_x_ct = cert
(Abs ("y", x_ty,
Const (@{const_name "HOL.eq"}, x_ty --> x_ty --> HOLogic.boolT)
$ x_t $ Bound 0));
fun remove_tracking th' =
th'
|> Thm.implies_intr Qx_ct
|> Thm.forall_intr Q_ct
|> Thm.forall_elim eq_x_ct
|> curry (op RS) @{thm refl}
|> beta_norm_thm
in
((Thm.assume Qx_ct, remove_tracking), ctxt')
end;
end;
*}
end
|
Set Warnings "-notation-overridden,-parsing,-deprecated-hint-without-locality".
From LF Require Export IndProp.
(* a playground module that helps me to recall the refined reflection *)
Module Silly.
Inductive reflect (P : Prop) : bool -> Set :=
| ReflectT : P -> reflect P true
| ReflectF : ~ P -> reflect P false.
Theorem eqb_natP : forall a b : nat, reflect (a = b) (a =? b).
Proof.
intros a b. destruct (a =? b) eqn:E.
- apply ReflectT. apply eqb_true. apply E.
- apply ReflectF. intro contra. rewrite contra in E.
rewrite eqb_refl in E. discriminate E. Qed.
Theorem silly_refl : forall n : nat, n =? n = true.
Proof.
intros n. Show Proof. destruct (eqb_natP n n). Show Proof.
- reflexivity. Show Proof.
- exfalso. Show Proof.
apply n0. Show Proof. reflexivity. Show Proof. Qed.
End Silly.
Theorem ev_4'' : ev 4.
Proof.
Show Proof. apply ev_SS.
Show Proof. apply ev_SS.
Show Proof. apply ev_0.
Show Proof. Qed.
Theorem ev_8 : ev 8.
Proof.
apply ev_SS. apply ev_SS. apply ev_SS. apply ev_SS. apply ev_0.
Qed.
Definition ev_8' : ev 8 := (ev_SS 6 (ev_SS 4 (ev_SS 2 (ev_SS 0 ev_0)))).
Theorem ev_plus4 : forall n, ev n -> ev (4 + n).
Proof.
intros n H. apply ev_SS. apply ev_SS.
apply H. Show Proof. Qed.
Definition ev_plus4' : forall n, ev n -> ev (4 + n) :=
fun (n : nat) (H : ev n) => (ev_SS (S (S n)) (ev_SS n H)).
Definition add1 : nat -> nat.
intro n. Show Proof.
apply S. Show Proof.
apply n. Show Proof.
Defined.
Print add1.
Module Props.
Module And.
Inductive and (P Q : Prop) : Prop :=
| conj : P -> Q -> and P Q.
Arguments conj [P] [Q].
Notation "P /\ Q" := (and P Q) : type_scope.
Theorem proj1' : forall P Q, P /\ Q -> P.
Proof.
intros P Q H. destruct H as [HP HQ]. apply HP.
Show Proof. Qed.
Lemma and_comm : forall P Q, P /\ Q <-> Q /\ P.
Proof.
intros P Q. Show Proof. split. Show Proof.
- intro H. Show Proof. destruct H as [HP HQ]. Show Proof.
split. Show Proof.
+ apply HQ. Show Proof.
+ apply HP. Show Proof.
- intros [HQ HP]. split.
+ apply HP.
+ apply HQ. Show Proof. Qed.
End And.
Definition and_comm'_aux (P Q : Prop) (H : P /\ Q) : Q /\ P :=
match H with
| conj HP HQ => conj HQ HP
end.
Check and_comm'_aux.
Definition and_comm' : forall (P Q : Prop), P /\ Q <-> Q /\ P.
split.
- intro H. apply (and_comm'_aux P Q). apply H.
- intro H. apply (and_comm'_aux Q P). apply H. Defined.
Definition and_comm'' : forall (P Q : Prop), P /\ Q <-> Q /\ P :=
fun (P Q : Prop) => conj (fun H : P /\ Q => and_comm'_aux P Q H)
(fun H : Q /\ P => and_comm'_aux Q P H).
(* Currying is brilliant! *)
Definition and_comm''' (P Q : Prop) : P /\ Q <-> Q /\ P :=
conj (and_comm'_aux P Q) (and_comm'_aux Q P).
Definition conj_fact : forall P Q R, P /\ Q -> Q /\ R -> P /\ R :=
fun P Q R => (fun HPQ : P /\ Q =>
match HPQ with
| conj HP _ =>
(fun HQR : Q /\ R =>
match HQR with
| conj _ HR => conj HP HR
end)
end).
Module Or.
Inductive or (P Q : Prop) : Prop :=
| or_introl : P -> or P Q
| or_intror : Q -> or P Q.
Arguments or_introl [P] [Q].
Arguments or_intror [P] [Q].
Notation "P \/ Q" := (or P Q) : type_scope.
Definition inj_l : forall P Q : Prop, P -> P \/ Q :=
fun P Q : Prop => fun HP : P => or_introl HP.
Theorem inj_j' : forall P Q : Prop, P -> P \/ Q.
Proof.
intros P Q HP. Show Proof. left. (* selects the `or_introl` constructor *)
Show Proof. apply HP. Qed.
Definition or_elim : forall (P Q R : Prop), P \/ Q -> (P -> R) -> (Q -> R) -> R :=
fun P Q R (H : P \/ Q) (HPR : P -> R) (HQR : Q -> R) =>
match H with
| or_introl HP => HPR HP
| or_intror HQ => HQR HQ
end.
End Or.
Definition or_commut' : forall P Q, P \/ Q -> Q \/ P :=
fun P Q (H : P \/ Q) =>
match H with
| or_introl HP => (@or_intror Q P) HP
| or_intror HQ => (@or_introl Q P) HQ
end.
Module Ex.
(* ex: "Show me a witness of the Prop, and I'll know there
exists something that witnesses the Prop..." *)
Inductive ex {A : Type} (P : A -> Prop) : Prop :=
| ex_intro (x : A) : P x -> ex P.
Notation "'exists' x , p" :=
(ex (fun x => p)) (at level 200, right associativity) : type_scope.
End Ex.
Check @ex.
Check @ex_intro.
Check ex (fun n => ev n) : Prop.
Definition some_nat_is_even : exists n, ev n :=
ex_intro ev 0 ev_0.
Definition ex_ev_Sn : ex (fun n => ev (S n)) :=
ex_intro (fun n => ev (S n)) 1 (ev_SS 0 ev_0).
Inductive True : Prop :=
| I : True.
Definition p_implies_true : forall P : Prop, P -> True :=
fun P (_ : P) => I.
Inductive False : Prop :=.
Definition ex_falso_quodlibet' : forall P, False -> P :=
fun P (contra : False) =>
match contra with end.
End Props.
Module MyEquality.
Inductive eq {X : Type} : X -> X -> Prop :=
| eq_refl : forall (x : X), eq x x.
Notation "x == y" := (eq x y) (at level 70, no associativity).
Definition singleton : forall (X : Type) (x : X), [] ++ [x] == x :: [] :=
fun X x => eq_refl [x].
Lemma equality__leibniz_equality : forall (X : Type) (x y : X),
x == y -> forall (P : X -> Prop), P x -> P y.
Proof.
intros X x y [x_y] P HPx. apply HPx. Qed.
Lemma leibniz_equality__equality : forall (X : Type) (x y : X),
(forall P : X -> Prop, P x -> P y) -> x == y.
Proof.
intros X x y Leib. apply (Leib (eq x)).
apply (eq_refl x). Qed.
Theorem try_leibniz_refl : forall (X : Type) (x y : X),
(forall P : X -> Prop, P x -> P y) -> (forall P : X -> Prop, P y -> P x).
Proof.
intros X x y Hxy P.
apply (Hxy (fun t : X => P t -> P x)).
intro H. apply H.
Qed.
End MyEquality.
|
Formal statement is: lemma ball_trivial [simp]: "ball x 0 = {}" Informal statement is: The ball of radius $0$ around any point is empty. |
Formal statement is: lemma sigma_sets_vimage_commute: assumes X: "X \<in> \<Omega> \<rightarrow> \<Omega>'" shows "{X -` A \<inter> \<Omega> |A. A \<in> sigma_sets \<Omega>' M'} = sigma_sets \<Omega> {X -` A \<inter> \<Omega> |A. A \<in> M'}" (is "?L = ?R") Informal statement is: If $X$ is a measurable function from $\Omega$ to $\Omega'$, then the preimage of a $\sigma$-algebra on $\Omega'$ is a $\sigma$-algebra on $\Omega$. |
% IM = mkSine(SIZE, PERIOD, DIRECTION, AMPLITUDE, PHASE, ORIGIN)
% or
% IM = mkSine(SIZE, FREQ, AMPLITUDE, PHASE, ORIGIN)
%
% Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar)
% containing samples of a 2D sinusoid, with given PERIOD (in pixels),
% DIRECTION (radians, CW from X-axis, default = 0), AMPLITUDE (default
% = 1), and PHASE (radians, relative to ORIGIN, default = 0). ORIGIN
% defaults to the center of the image.
%
% In the second form, FREQ is a 2-vector of frequencies (radians/pixel).
% Eero Simoncelli, 6/96.
function [res] = mkSine(sz, per_freq, dir_amp, amp_phase, phase_orig, orig)
%------------------------------------------------------------
%% OPTIONAL ARGS:
if (prod(size(per_freq)) == 2)
frequency = norm(per_freq);
direction = atan2(per_freq(1),per_freq(2));
if (exist('dir_amp') == 1)
amplitude = dir_amp;
else
amplitude = 1;
end
if (exist('amp_phase') == 1)
phase = amp_phase;
else
phase = 0;
end
if (exist('phase_orig') == 1)
origin = phase_orig;
end
if (exist('orig') == 1)
error('Too many arguments for (second form) of mkSine');
end
else
frequency = 2*pi/per_freq;
if (exist('dir_amp') == 1)
direction = dir_amp;
else
direction = 0;
end
if (exist('amp_phase') == 1)
amplitude = amp_phase;
else
amplitude = 1;
end
if (exist('phase_orig') == 1)
phase = phase_orig;
else
phase = 0;
end
if (exist('orig') == 1)
origin = orig;
end
end
%------------------------------------------------------------
if (exist('origin') == 1)
res = amplitude*sin(mkRamp(sz, direction, frequency, phase, origin));
else
res = amplitude*sin(mkRamp(sz, direction, frequency, phase));
end
|
# using Statistics, StatsBase
# using PyCall
# xr = pyimport("xarray")
# using PyPlot
#
# path = "/Users/milan/cams"
# allvars = ["no2","go3","so2","aermr04","aermr05","aermr06","ch4","co"]
#
# M = Array{Float32,3}(undef,length(allvars),6,137)
#
# for (i,vari) in enumerate(allvars)
# filelist = filter(x->endswith(x,vari*".grib"),readdir(path))
# X = xr.open_dataset(joinpath(path,filelist[1]),engine="cfgrib")[vari].data
#
# M[i,1,:] = mean(X,dims=2)[:,1]
# M[i,2,:] = median(X,dims=2)[:,1]
# M[i,3,:] = minimum(X,dims=2)[:,1]
# M[i,4,:] = maximum(X,dims=2)[:,1]
# M[i,5,:] = [percentile(vec(X[i,:]),10) for i in level]
# M[i,6,:] = [percentile(vec(X[i,:]),90) for i in level]
# end
# plotting
level = 1:137
alphabet = ["a","b","c","d","e","f","g","h","i","j"]
fig,axs = subplots(2,4,figsize=(10,8),sharey=true)
axs[1,1].invert_yaxis()
for (i,ax) in enumerate(axs)
ax.semilogx(M[i,1,:],level,"C0",lw=3,label="mean")
ax.plot(M[i,2,:],level,"C0",lw=1.5,label="median")
ax.fill_betweenx(level,M[i,3,:],M[i,4,:],color="C0",alpha=0.2,label="Min-max range")
ax.fill_betweenx(level,M[i,5,:],M[i,6,:],color="C0",alpha=0.5,label="10-90% range")
ax.set_title(allvars[i],loc="left")
ax.set_title(alphabet[i],loc="right",fontweight="bold")
end
axs[2,1].legend(loc=2)
axs[1,1].set_ylim(137,1)
axs[1,1].set_ylabel("model level")
axs[2,1].set_ylabel("model level")
axs[2,1].set_xlabel("values")
axs[2,2].set_xlabel("values")
axs[2,3].set_xlabel("values")
axs[2,4].set_xlabel("values")
tight_layout()
|
module Erlang.Types.Atom
import Language.Reflection
%default total
||| Generate atom functions from a list of strings.
|||
||| Usage:
||| ```
||| import Erlang
||| import Language.Reflection
|||
||| %language ElabReflection
|||
||| %runElab generateAtomHelpers ["ok", "error"]
||| ```
|||
||| Will generate the following functions:
||| ```
||| private %inline
||| A_ok : ErlAtom
||| A_ok = MkAtom "ok"
|||
||| private %inline
||| A_error : ErlAtom
||| A_error = MkAtom "error"
||| ```
export
generateAtomHelpers : List String -> Elab ()
generateAtomHelpers atoms =
declare (atoms >>= atomToDecls)
where
atomToDecls : String -> List Decl
atomToDecls atom =
let fnName = UN (Basic ("A_" ++ atom))
in
[ IClaim EmptyFC MW Private [Inline] (MkTy EmptyFC EmptyFC fnName `(ErlAtom))
, IDef EmptyFC fnName
[ PatClause EmptyFC
(IVar EmptyFC fnName)
`(MkAtom ~(IPrimVal EmptyFC (Str atom)))
]
]
|
> module Functor.tests.Main
> import Control.Monad.Identity
> import Functor.Operations
> import Identity.Properties
> %default total
> %auto_implicits off
> b : Bool
> b = elem Z (Id Z)
> B : Type
> B = Elem (S Z) (Id Z)
> b' : Bool
> b' = decAsBool (decElem (S Z) (Id Z))
> main : IO ()
> main = do putStrLn ("b = " ++ show b)
> putStrLn ("b' = " ++ show b')
|
(*************************************************************************
* Copyright (C)
* 2019 The University of Exeter
* 2018-2019 The University of Paris-Saclay
* 2018 The University of Sheffield
*
* License:
* This program can be redistributed and/or modified under the terms
* of the 2-clause BSD-style license.
*
* SPDX-License-Identifier: BSD-2-Clause
*************************************************************************)
(*<*)
theory IsaDofApplications
imports "Isabelle_DOF.scholarly_paper"
begin
use_template "lncs"
use_ontology "Isabelle_DOF.scholarly_paper"
open_monitor*[this::article]
declare[[strict_monitor_checking=false]]
define_shortcut* isadof \<rightleftharpoons> \<open>\isadof\<close>
LaTeX \<rightleftharpoons> \<open>\LaTeX{}\<close>
dots \<rightleftharpoons> \<open>\ldots\<close>
isabelle \<rightleftharpoons> \<open>Isabelle/HOL\<close>
Protege \<rightleftharpoons> \<open>Prot{\'e}g{\'e}\<close>
(* slanted text in contrast to italics *)
define_macro* slanted_text \<rightleftharpoons> \<open>\textsl{\<close> _ \<open>}\<close>
(*>*)
title*[tit::title] \<open>Using the Isabelle Ontology Framework\<close>
subtitle*[stit::subtitle]\<open>Linking the Formal with the Informal\<close>
author*[adb,
email ="''[email protected]''",
orcid ="''0000-0002-6355-1200''",
affiliation ="''The University of Sheffield, Sheffield, UK''"]\<open>Achim D. Brucker\<close>
author*[idir,
email = "''[email protected]''",
affiliation = "''CentraleSupelec, Paris, France''"]\<open>Idir Ait-Sadoune\<close>
author*[paolo,
email = "''[email protected]''",
affiliation = "''IRT-SystemX, Paris, France''"]\<open>Paolo Crisafulli\<close>
author*[bu,
email = "\<open>[email protected]\<close>",
affiliation = "\<open>Université Paris-Saclay, Paris, France\<close>"]\<open>Burkhart Wolff\<close>
abstract*[abs::abstract, keywordlist="[''Ontology'',''Ontological Modeling'',''Isabelle/DOF'']"]\<open>
While Isabelle is mostly known as part of \<^isabelle> (an interactive
theorem prover), it actually provides a framework for developing a wide
spectrum of applications. A particular strength
of the Isabelle framework is the combination of text editing, formal verification,
and code generation.
Up to now, Isabelle's document preparation system lacks a mechanism
for ensuring the structure of different document types (as, e.g.,
required in certification processes) in general and, in particular,
mechanism for linking informal and formal parts of a document.
In this paper, we present \<^isadof>, a novel Document Ontology Framework
on top of Isabelle. \<^isadof> allows for conventional typesetting
\<^emph>\<open>as well\<close> as formal development. We show how to model document
ontologies inside \<^isadof>, how to use the resulting meta-information
for enforcing a certain document structure, and discuss ontology-specific
IDE support.
%% If you consider citing this paper, please refer to
%% @{cite "brucker.ea:isabelle-ontologies:2018"}.
\<close>
section*[intro::introduction]\<open> Introduction \<close>
text*[introtext::introduction, level = "Some 1"]\<open>
The linking of the \<^emph>\<open>formal\<close> to the \<^emph>\<open>informal\<close> is perhaps the
most pervasive challenge in the digitization of knowledge and its
propagation. This challenge incites numerous research efforts
summarized under the labels ``semantic web'', ``data mining'', or any
form of advanced ``semantic'' text processing. A key role in
structuring this linking play \<^emph>\<open>document ontologies\<close> (also called
\<^emph>\<open>vocabulary\<close> in the semantic web community~@{cite "w3c:ontologies:2015"}),
\<^ie>, a machine-readable form of the structure of documents as well as
the document discourse.
Such ontologies can be used for the scientific discourse within scholarly
articles, mathematical libraries, and in the engineering discourse
of standardized software certification
documents~@{cite "boulanger:cenelec-50128:2015" and "cc:cc-part3:2006"}.
Further applications are the domain-specific discourse in juridical texts or medical reports.
In general, an ontology is a formal explicit description of \<^emph>\<open>concepts\<close>
in a domain of discourse (called \<^emph>\<open>classes\<close>), properties of each concept
describing \<^emph>\<open>attributes\<close> of the concept, as well as \<^emph>\<open>links\<close> between
them. A particular link between concepts is the \<^emph>\<open>is-a\<close> relation declaring
the instances of a subclass to be instances of the super-class.
The main objective of this paper is to present \<^isadof>, a novel
framework to \<^emph>\<open>model\<close> typed ontologies and to \<^emph>\<open>enforce\<close> them during
document evolution. Based on Isabelle infrastructures, ontologies may refer to
types, terms, proven theorems, code, or established assertions.
Based on a novel adaption of the Isabelle IDE, a document is checked to be
\<^emph>\<open>conform\<close> to a particular ontology---\<^isadof> is designed to give fast user-feedback
\<^emph>\<open>during the capture of content\<close>. This is particularly valuable in case of document
changes, where the \<^emph>\<open>coherence\<close> between the formal and the informal parts of the
content can be mechanically checked.
To avoid any misunderstanding: \<^isadof> is \<^emph>\<open>not a theory in HOL\<close>
on ontologies and operations to track and trace links in texts,
it is an \<^emph>\<open>environment to write structured text\<close> which \<^emph>\<open>may contain\<close>
\<^isabelle> definitions and proofs like mathematical articles, tech-reports and
scientific papers---as the present one, which is written in \<^isadof>
itself. \<^isadof> is a plugin into the Isabelle/Isar
framework in the style of~@{cite "wenzel.ea:building:2007"}.
\<close>
(* declaring the forward references used in the subsequent section *)
(*<*)
declare_reference*[bgrnd::text_section]
declare_reference*[isadof::text_section]
declare_reference*[ontomod::text_section]
declare_reference*[ontopide::text_section]
declare_reference*[conclusion::text_section]
(*>*)
text*[plan::introduction, level="Some 1"]\<open> The plan of the paper is follows: we start by introducing the underlying
Isabelle system (@{text_section (unchecked) \<open>bgrnd\<close>}) followed by presenting the
essentials of \<^isadof> and its ontology language (@{text_section (unchecked) \<open>isadof\<close>}).
It follows @{text_section (unchecked) \<open>ontomod\<close>}, where we present three application
scenarios from the point of view of the ontology modeling. In @{text_section (unchecked) \<open>ontopide\<close>}
we discuss the user-interaction generated from the ontological definitions. Finally, we draw
conclusions and discuss related work in @{text_section (unchecked) \<open>conclusion\<close>}. \<close>
section*[bgrnd::text_section,main_author="Some(@{docitem ''bu''}::author)"]
\<open> Background: The Isabelle System \<close>
text*[background::introduction, level="Some 1"]\<open>
While Isabelle is widely perceived as an interactive theorem prover
for HOL (Higher-order Logic)~@{cite "nipkow.ea:isabelle:2002"}, we
would like to emphasize the view that Isabelle is far more than that:
it is the \<^emph>\<open>Eclipse of Formal Methods Tools\<close>. This refers to the
``\<^slanted_text>\<open>generic system framework of Isabelle/Isar underlying recent
versions of Isabelle. Among other things, Isar provides an
infrastructure for Isabelle plug-ins, comprising extensible state
components and extensible syntax that can be bound to ML
programs. Thus, the Isabelle/Isar architecture may be understood as
an extension and refinement of the traditional `LCF approach', with
explicit infrastructure for building derivative
\<^emph>\<open>systems\<close>.\<close>''~@{cite "wenzel.ea:building:2007"}
The current system framework offers moreover the following features:
\<^item> a build management grouping components into to pre-compiled sessions,
\<^item> a prover IDE (PIDE) framework~@{cite "wenzel:asynchronous:2014"} with various front-ends
\<^item> documentation - and code generators,
\<^item> an extensible front-end language Isabelle/Isar, and,
\<^item> last but not least, an LCF style, generic theorem prover kernel as
the most prominent and deeply integrated system component.
\<close>
figure*[architecture::figure,relative_width="100",src="''figures/isabelle-architecture''"]\<open>
The system architecture of Isabelle (left-hand side) and the
asynchronous communication between the Isabelle system and
the IDE (right-hand side). \<close>
text*[blug::introduction, level="Some 1"]\<open> The Isabelle system architecture shown in @{figure \<open>architecture\<close>}
comes with many layers, with Standard ML (SML) at the bottom layer as implementation
language. The architecture actually foresees a \<^emph>\<open>Nano-Kernel\<close> (our terminology) which
resides in the SML structure \<^ML_structure>\<open>Context\<close>. This structure provides a kind of container called
\<^emph>\<open>context\<close> providing an identity, an ancestor-list as well as typed, user-defined state
for components (plugins) such as \<^isadof>. On top of the latter, the LCF-Kernel, tactics,
automated proof procedures as well as specific support for higher specification constructs
were built. \<close>
text\<open> We would like to detail the documentation generation of the architecture,
which is based on literate specification commands such as \inlineisar+section+ \<^dots>,
\inlineisar+subsection+ \<^dots>, \inlineisar+text+ \<^dots>, etc.
Thus, a user can add a simple text:
\begin{isar}
text\<Open>This is a description.\<Close>
\end{isar}
These text-commands can be arbitrarily mixed with other commands stating definitions, proofs, code, etc.,
and will result in the corresponding output in generated \<^LaTeX> or HTML documents.
Now, \<^emph>\<open>inside\<close> the textual content, it is possible to embed a \<^emph>\<open>text-antiquotation\<close>:
\begin{isar}
text\<Open>According to the reflexivity axiom \at{thm refl}, we obtain in \<Gamma>
for \at{term "fac 5"} the result \at{value "fac 5"}.\<Close>
\end{isar}
which is represented in the generated output by:
\begin{out}
According to the reflexivity axiom $x = x$, we obtain in $\Gamma$ for $\operatorname{fac} 5$ the result $120$.
\end{out}
where \inlineisar+refl+ is actually the reference to the axiom of reflexivity in HOL.
For the antiquotation \inlineisar+\at{value "fac 5"}+ we assume the usual definition for
\inlineisar+fac+ in HOL.
\<close>
text*[anti::introduction, level = "Some 1"]\<open> Thus, antiquotations can refer to formal content, can be type-checked before being
displayed and can be used for calculations before actually being typeset. When editing,
Isabelle's PIDE offers auto-completion and error-messages while typing the above
\<^emph>\<open>semi-formal\<close> content. \<close>
section*[isadof::technical,main_author="Some(@{docitem ''adb''}::author)"]\<open> \<^isadof> \<close>
text\<open> An \<^isadof> document consists of three components:
\<^item> the \<^emph>\<open>ontology definition\<close> which is an Isabelle theory file with definitions
for document-classes and all auxiliary datatypes.
\<^item> the \<^emph>\<open>core\<close> of the document itself which is an Isabelle theory
importing the ontology definition. \<^isadof> provides an own family of text-element
commands such as \inlineisar+title*+, \inlineisar+section*+, \inlineisar+text*+, etc.,
which can be annotated with meta-information defined in the underlying ontology definition.
\<^item> the \<^emph>\<open>layout definition\<close> for the given ontology exploiting this meta-information.
\<close>
text\<open>\<^isadof> is a novel Isabelle system component providing specific support for all these
three parts. Note that the document core \<^emph>\<open>may\<close>, but \<^emph>\<open>must\<close> not
use Isabelle definitions or proofs for checking the formal content---the
present paper is actually an example of a document not containing any proof.
The document generation process of \<^isadof> is currently restricted to \LaTeX, which means
that the layout is defined by a set of \<^LaTeX> style files. Several layout
definitions for one ontology are possible and pave the way that different \<^emph>\<open>views\<close> for
the same central document were generated, addressing the needs of different purposes `
and/or target readers.
While the ontology and the layout definition will have to be developed by an expert
with knowledge over Isabelle and \<^isadof> and the back end technology depending on the layout
definition, the core is intended to require only minimal knowledge of these two. The situation
is similar to \<^LaTeX>-users, who usually have minimal knowledge about the content in
style-files (\<^verbatim>\<open>.sty\<close>-files). In the document core authors \<^emph>\<open>can\<close> use \<^LaTeX> commands in
their source, but this limits the possibility of using different representation technologies,
\<^eg>, HTML, and increases the risk of arcane error-messages in generated \<^LaTeX>.
The \<^isadof> ontology specification language consists basically on a notation for
document classes, where the attributes were typed with HOL-types and can be instantiated
by terms HOL-terms, \<^ie>, the actual parsers and type-checkers of the Isabelle system were reused.
This has the particular advantage that \<^isadof> commands can be arbitrarily mixed with
Isabelle/HOL commands providing the machinery for type declarations and term specifications such
as enumerations. In particular, document class definitions provide:
\<^item> a HOL-type for each document class as well as inheritance,
\<^item> support for attributes with HOL-types and optional default values,
\<^item> support for overriding of attribute defaults but not overloading, and
\<^item> text-elements annotated with document classes; they are mutable
instances of document classes.
\<close>
text\<open>
Attributes referring to other ontological concepts are called \<^emph>\<open>links\<close>.
The HOL-types inside the document specification language support built-in types for Isabelle/HOL
\inlineisar+typ+'s, \inlineisar+term+'s, and \inlineisar+thm+'s reflecting internal Isabelle's
internal types for these entities; when denoted in HOL-terms to instantiate an attribute, for
example, there is a specific syntax (called \<^emph>\<open>inner syntax antiquotations\<close>) that is checked by
\<^isadof> for consistency.
Document classes can have a \inlineisar+where+ clause containing a regular
expression over class names. Classes with such a \inlineisar+where+ were called \<^emph>\<open>monitor classes\<close>.
While document classes and their inheritance relation structure meta-data of text-elements
in an object-oriented manner, monitor classes enforce structural organization
of documents via the language specified by the regular expression
enforcing a sequence of text-elements that must belong to the corresponding classes.
To start using \<^isadof>, one creates an Isabelle project (with the name
\inlinebash{IsaDofApplications}):
\begin{bash}
isabelle dof_mkroot -o scholarly_paper -t lncs IsaDofApplications
\end{bash}
where the \inlinebash{-o scholarly_paper} specifies the ontology for writing scientific articles and
\inlinebash{-t lncs} specifies the use of Springer's \LaTeX-configuration for the Lecture Notes in
Computer Science series. The project can be formally checked, including the generation of the
article in PDF using the following command:
\begin{bash}
isabelle build -d . IsaDofApplications
\end{bash}
\<close>
section*[ontomod::text_section]\<open> Modeling Ontologies in \<^isadof> \<close>
text\<open> In this section, we will use the \<^isadof> document ontology language
for three different application scenarios: for scholarly papers, for mathematical
exam sheets as well as standardization documents where the concepts of the
standard are captured in the ontology. For space reasons, we will concentrate in all three
cases on aspects of the modeling due to space limitations.\<close>
subsection*[scholar_onto::example]\<open> The Scholar Paper Scenario: Eating One's Own Dog Food. \<close>
text\<open> The following ontology is a simple ontology modeling scientific papers. In this
\<^isadof> application scenario, we deliberately refrain from integrating references to
(Isabelle) formal content in order demonstrate that \<^isadof> is not a framework from
Isabelle users to Isabelle users only.
Of course, such references can be added easily and represent a particular strength
of \<^isadof>.
\begin{figure}
\begin{isar}
doc_class title =
short_title :: "string option" <= None
doc_class subtitle =
abbrev :: "string option" <= None
doc_class author =
affiliation :: "string"
doc_class abstract =
keyword_list :: "string list" <= None
doc_class text_section =
main_author :: "author option" <= None
todo_list :: "string list" <= "[]"
\end{isar}
\caption{The core of the ontology definition for writing scholarly papers.}
\label{fig:paper-onto-core}
\end{figure}
The first part of the ontology \inlineisar+scholarly_paper+ (see \autoref{fig:paper-onto-core})
contains the document class definitions
with the usual text-elements of a scientific paper. The attributes \inlineisar+short_title+,
\inlineisar+abbrev+ etc are introduced with their types as well as their default values.
Our model prescribes an optional \inlineisar+main_author+ and a todo-list attached to an arbitrary
text section; since instances of this class are mutable (meta)-objects of text-elements, they
can be modified arbitrarily through subsequent text and of course globally during text evolution.
Since \inlineisar+author+ is a HOL-type internally generated by \<^isadof> framework and can therefore
appear in the \inlineisar+main_author+ attribute of the \inlineisar+text_section+ class;
semantic links between concepts can be modeled this way.
The translation of its content to, \<^eg>, Springer's \<^LaTeX> setup for the Lecture Notes in Computer
Science Series, as required by many scientific conferences, is mostly straight-forward. \<close>
figure*[fig1::figure,spawn_columns=False,relative_width="95",src="''figures/Dogfood-Intro''"]
\<open> Ouroboros I: This paper from inside \<^dots> \<close>
text\<open> @{figure \<open>fig1\<close>} shows the corresponding view in the Isabelle/PIDE of thqqe present paper.
Note that the text uses \<^isadof>'s own text-commands containing the meta-information provided by
the underlying ontology.
We proceed by a definition of \inlineisar+introduction+'s, which we define as the extension of
\inlineisar+text_section+ which is intended to capture common infrastructure:
\begin{isar}
doc_class introduction = text_section +
comment :: string
\end{isar}
As a consequence of the definition as extension, the \inlineisar+introduction+ class
inherits the attributes \inlineisar+main_author+ and \inlineisar+todo_list+ together with
the corresponding default values.
As a variant of the introduction, we could add here an attribute that contains the formal
claims of the article --- either here, or, for example, in the keyword list of the abstract.
As type, one could use either the built-in type \inlineisar+term+ (for syntactically correct,
but not necessarily proven entity) or \inlineisar+thm+ (for formally proven entities). It suffices
to add the line:
\begin{isar}
claims :: "thm list"
\end{isar}
and to extent the \LaTeX-style accordingly to handle the additional field.
Note that \inlineisar+term+ and \inlineisar+thm+ are types reflecting the core-types of the
Isabelle kernel. In a corresponding conclusion section, one could model analogously an
achievement section; by programming a specific compliance check in SML, the implementation
of automated forms of validation check for specific categories of papers is envisageable.
Since this requires deeper knowledge in Isabelle programming, however, we consider this out
of the scope of this paper.
We proceed more or less conventionally by the subsequent sections (\autoref{fig:paper-onto-sections})
\begin{figure}
\begin{isar}
doc_class technical = text_section +
definition_list :: "string list" <= "[]"
doc_class example = text_section +
comment :: string
doc_class conclusion = text_section +
main_author :: "author option" <= None
doc_class related_work = conclusion +
main_author :: "author option" <= None
doc_class bibliography =
style :: "string option" <= "''LNCS''"
\end{isar}
\caption{Various types of sections of a scholarly papers.}
\label{fig:paper-onto-sections}
\end{figure}
and finish with a monitor class definition that enforces a textual ordering
in the document core by a regular expression (\autoref{fig:paper-onto-monitor}).
\begin{figure}
\begin{isar}
doc_class article =
trace :: "(title + subtitle + author+ abstract +
introduction + technical + example +
conclusion + bibliography) list"
where "(title ~~ \<lbrakk>subtitle\<rbrakk> ~~ \<lbrace>author\<rbrace>$^+$+ ~~ abstract ~~
introduction ~~ \<lbrace>technical || example\<rbrace>$^+$ ~~ conclusion ~~
bibliography)"
\end{isar}
\caption{A monitor for the scholarly paper ontology.}
\label{fig:paper-onto-monitor}
\end{figure}
\<close>
text\<open> We might wish to add a component into our ontology that models figures to be included into
the document. This boils down to the exercise of modeling structured data in the style of a
functional programming language in HOL and to reuse the implicit HOL-type inside a suitable document
class \inlineisar+figure+:
\begin{isar}
datatype placement = h | t | b | ht | hb
doc_class figure = text_section +
relative_width :: "int" (* percent of textwidth *)
src :: "string"
placement :: placement
spawn_columns :: bool <= True
\end{isar}
\<close>
text\<open> Alternatively, by including the HOL-libraries for rationals, it is possible to
use fractions or even mathematical reals. This must be counterbalanced by syntactic
and semantic convenience. Choosing the mathematical reals, \<^eg>, would have the drawback that
attribute evaluation could be substantially more complicated.\<close>
figure*[fig_figures::figure,spawn_columns=False,relative_width="85",src="''figures/Dogfood-figures''"]
\<open> Ouroboros II: figures \<^dots> \<close>
text\<open> The document class \inlineisar+figure+ --- supported by the \<^isadof> text command
\inlineisar+figure*+ --- makes it possible to express the pictures and diagrams in this paper
such as @{figure \<open>fig_figures\<close>}.
\<close>
subsection*[math_exam::example]\<open> The Math-Exam Scenario \<close>
text\<open> The Math-Exam Scenario is an application with mixed formal and
semi-formal content. It addresses applications where the author of the exam is not present
during the exam and the preparation requires a very rigorous process, as the french
\<^emph>\<open>baccaleaureat\<close> and exams at The University of Sheffield.
We assume that the content has four different types of addressees, which have a different
\<^emph>\<open>view\<close> on the integrated document:
\<^item> the \<^emph>\<open>setter\<close>, \<^ie>, the author of the exam,
\<^item> the \<^emph>\<open>checker\<close>, \<^ie>, an internal person that checks
the exam for feasibility and non-ambiguity,
\<^item> the \<^emph>\<open>external examiner\<close>, \<^ie>, an external person that checks
the exam for feasibility and non-ambiguity, and
\<^item> the \<^emph>\<open>student\<close>, \<^ie>, the addressee of the exam.
\<close>
text\<open> The latter quality assurance mechanism is used in many universities,
where for organizational reasons the execution of an exam takes place in facilities
where the author of the exam is not expected to be physically present.
Furthermore, we assume a simple grade system (thus, some calculation is required).
\begin{figure}
\begin{isar}
doc_class Author = ...
datatype Subject = algebra | geometry | statistical
datatype Grade = A1 | A2 | A3
doc_class Header = examTitle :: string
examSubject :: Subject
date :: string
timeAllowed :: int -- minutes
datatype ContentClass = setter
| checker
| external_examiner
| student
doc_class Exam_item =
concerns :: "ContentClass set"
doc_class Exam_item =
concerns :: "ContentClass set"
type_synonym SubQuestion = string
\end{isar}
\caption{The core of the ontology modeling math exams.}
\label{fig:onto-exam}
\end{figure}
The heart of this ontology (see \autoref{fig:onto-exam}) is an alternation of questions and answers,
where the answers can consist of simple yes-no answers (QCM style check-boxes) or lists of formulas.
Since we do not
assume familiarity of the students with Isabelle (\inlineisar+term+ would assume that this is a
parse-able and type-checkable entity), we basically model a derivation as a sequence of strings
(see \autoref{fig:onto-questions}).
\begin{figure}
\begin{isar}
doc_class Answer_Formal_Step = Exam_item +
justification :: string
"term" :: "string"
doc_class Answer_YesNo = Exam_item +
step_label :: string
yes_no :: bool -- \<open>for checkboxes\<close>
datatype Question_Type =
formal | informal | mixed
doc_class Task = Exam_item +
level :: Level
type :: Question_Type
subitems :: "(SubQuestion *
(Answer_Formal_Step list + Answer_YesNo) list) list"
concerns :: "ContentClass set" <= "UNIV"
mark :: int
doc_class Exercise = Exam_item +
type :: Question_Type
content :: "(Task) list"
concerns :: "ContentClass set" <= "UNIV"
mark :: int
\end{isar}
\caption{An exam can contain different types of questions.}
\label{fig:onto-questions}
\end{figure}
In many institutions, it makes sense to have a rigorous process of validation
for exam subjects: is the initial question correct? Is a proof in the sense of the
question possible? We model the possibility that the @{term examiner} validates a
question by a sample proof validated by Isabelle (see \autoref{fig:onto-exam-monitor}).
In our scenario this sample proofs are completely \<^emph>\<open>intern\<close>, \<^ie>, not exposed to the
students but just additional material for the internal review process of the exam.
\begin{figure}
\begin{isar}
doc_class Validation =
tests :: "term list" <="[]"
proofs :: "thm list" <="[]"
doc_class Solution = Exam_item +
content :: "Exercise list"
valids :: "Validation list"
concerns :: "ContentClass set" <= "{setter,checker,external_examiner}"
doc_class MathExam=
content :: "(Header + Author + Exercise) list"
global_grade :: Grade
where "\<lbrace>Author\<rbrace>$^+$ ~~ Header ~~ \<lbrace>Exercise ~~ Solution\<rbrace>$^+$ "
\end{isar}
\caption{Validating exams.}
\label{fig:onto-exam-monitor}
\end{figure}
\<close>
declare_reference*["fig_qcm"::figure]
text\<open> Using the \<^LaTeX> package hyperref, it is possible to conceive an interactive
exam-sheets with multiple-choice and/or free-response elements
(see @{figure (unchecked) \<open>fig_qcm\<close>}). With the
help of the latter, it is possible that students write in a browser a formal mathematical
derivation---as part of an algebra exercise, for example---which is submitted to the examiners
electronically. \<close>
figure*[fig_qcm::figure,spawn_columns=False,
relative_width="90",src="''figures/InteractiveMathSheet''"]
\<open> A Generated QCM Fragment \<^dots> \<close>
subsection*[cenelec_onto::example]\<open> The Certification Scenario following CENELEC \<close>
text\<open> Documents to be provided in formal certifications (such as CENELEC
50126/50128, the DO-178B/C, or Common Criteria) can much profit from the control of ontological consistency:
a lot of an evaluators work consists in tracing down the links from requirements over
assumptions down to elements of evidence, be it in the models, the code, or the tests.
In a certification process, traceability becomes a major concern; and providing
mechanisms to ensure complete traceability already at the development of the
global document will clearly increase speed and reduce risk and cost of a
certification process. Making the link-structure machine-checkable, be it between requirements,
assumptions, their implementation and their discharge by evidence (be it tests, proofs, or
authoritative arguments), is therefore natural and has the potential to decrease the cost
of developments targeting certifications. Continuously checking the links between the formal
and the semi-formal parts of such documents is particularly valuable during the (usually
collaborative) development effort.
As in many other cases, formal certification documents come with an own terminology and
pragmatics of what has to be demonstrated and where, and how the trace-ability of requirements through
design-models over code to system environment assumptions has to be assured.
\<close>
text\<open> In the sequel, we present a simplified version of an ontological model used in a
case-study~ @{cite "bezzecchi.ea:making:2018"}. We start with an introduction of the concept of requirement
(see \autoref{fig:conceptual}).
\begin{figure}
\begin{isar}
doc_class requirement = long_name :: "string option"
doc_class requirement_analysis = no :: "nat"
where "requirement_item +"
doc_class hypothesis = requirement +
hyp_type :: hyp_type <= physical (* default *)
datatype ass_kind = informal | semiformal | formal
doc_class assumption = requirement +
assumption_kind :: ass_kind <= informal
\end{isar}
\caption{Modeling requirements.}
\label{fig:conceptual}
\end{figure}
Such ontologies can be enriched by larger explanations and examples, which may help
the team of engineers substantially when developing the central document for a certification,
like an explication what is precisely the difference between an \<^emph>\<open>hypothesis\<close> and an
\<^emph>\<open>assumption\<close> in the context of the evaluation standard. Since the PIDE makes for each
document class its definition available by a simple mouse-click, this kind on meta-knowledge
can be made far more accessible during the document evolution.
For example, the term of category \<^emph>\<open>assumption\<close> is used for domain-specific assumptions.
It has formal, semi-formal and informal sub-categories. They have to be
tracked and discharged by appropriate validation procedures within a
certification process, by it by test or proof. It is different from a hypothesis, which is
globally assumed and accepted.
In the sequel, the category \<^emph>\<open>exported constraint\<close> (or \<^emph>\<open>ec\<close> for short)
is used for formal assumptions, that arise during the analysis,
design or implementation and have to be tracked till the final
evaluation target, and discharged by appropriate validation procedures
within the certification process, by it by test or proof. A particular class of interest
is the category \<^emph>\<open>safety related application condition\<close> (or \<^emph>\<open>srac\<close>
for short) which is used for \<^emph>\<open>ec\<close>'s that establish safety properties
of the evaluation target. Their track-ability throughout the certification
is therefore particularly critical. This is naturally modeled as follows:
\begin{isar}
doc_class ec = assumption +
assumption_kind :: ass_kind <= (*default *) formal
doc_class srac = ec +
assumption_kind :: ass_kind <= (*default *) formal
\end{isar}
\<close>
section*[ontopide::technical]\<open> Ontology-based IDE support \<close>
text\<open> We present a selection of interaction scenarios @{example \<open>scholar_onto\<close>}
and @{example \<open>cenelec_onto\<close>} with Isabelle/PIDE instrumented by \<^isadof>. \<close>
subsection*[scholar_pide::example]\<open> A Scholarly Paper \<close>
text\<open> In \autoref{fig-Dogfood-II-bgnd1} and \autoref{fig-bgnd-text_section} we show how
hovering over links permits to explore its meta-information.
Clicking on a document class identifier permits to hyperlink into the corresponding
class definition (\autoref{fig:Dogfood-IV-jumpInDocCLass}); hovering over an attribute-definition
(which is qualified in order to disambiguate; \autoref{fig:Dogfood-V-attribute}).
\<close>
side_by_side_figure*["text-elements"::side_by_side_figure,anchor="''fig-Dogfood-II-bgnd1''",
caption="''Exploring a Reference of a Text-Element.''",relative_width="48",
src="''figures/Dogfood-II-bgnd1''",anchor2="''fig-bgnd-text_section''",
caption2="''Exploring the class of a text element.''",relative_width2="47",
src2="''figures/Dogfood-III-bgnd-text_section''"]\<open> Exploring text elements. \<close>
side_by_side_figure*["hyperlinks"::side_by_side_figure,anchor="''fig:Dogfood-IV-jumpInDocCLass''",
caption="''Hyperlink to Class-Definition.''",relative_width="48",
src="''figures/Dogfood-IV-jumpInDocCLass''",anchor2="''fig:Dogfood-V-attribute''",
caption2="''Exploring an attribute.''",relative_width2="47",
src2="''figures/Dogfood-III-bgnd-text_section''"]\<open> Hyperlinks.\<close>
declare_reference*["figDogfoodVIlinkappl"::figure]
text\<open> An ontological reference application in \autoref{figDogfoodVIlinkappl}: the ontology-dependant
antiquotation \inlineisar|@ {example ...}| refers to the corresponding text-elements. Hovering allows
for inspection, clicking for jumping to the definition. If the link does not exist or has a
non-compatible type, the text is not validated. \<close>
figure*[figDogfoodVIlinkappl::figure,relative_width="80",src="''figures/Dogfood-V-attribute''"]
\<open> Exploring an attribute (hyperlinked to the class). \<close>
subsection*[cenelec_pide::example]\<open> CENELEC \<close>
declare_reference*[figfig3::figure]
text\<open> The corresponding view in @{docitem (unchecked) \<open>figfig3\<close>} shows core part of a document,
coherent to the @{example \<open>cenelec_onto\<close>}. The first sample shows standard Isabelle antiquotations
@{cite "wenzel:isabelle-isar:2017"} into formal entities of a theory. This way, the informal parts
of a document get ``formal content'' and become more robust under change.\<close>
figure*[figfig3::figure,relative_width="80",src="''figures/antiquotations-PIDE''"]
\<open> Standard antiquotations referring to theory elements.\<close>
declare_reference*[figfig5::figure]
text\<open> The subsequent sample in @{figure (unchecked) \<open>figfig5\<close>} shows the definition of an
\<^emph>\<open>safety-related application condition\<close>, a side-condition of a theorem which
has the consequence that a certain calculation must be executed sufficiently fast on an embedded
device. This condition can not be established inside the formal theory but has to be
checked by system integration tests.\<close>
figure*[figfig5::figure, relative_width="80", src="''figures/srac-definition''"]
\<open> Defining a SRAC reference \<^dots> \<close>
figure*[figfig7::figure, relative_width="80", src="''figures/srac-as-es-application''"]
\<open> Using a SRAC as EC document reference. \<close>
text\<open> Now we reference in @{figure (unchecked) \<open>figfig7\<close>} this safety-related condition;
however, this happens in a context where general \<^emph>\<open>exported constraints\<close> are listed.
\<^isadof>'s checks establish that this is legal in the given ontology.
This example shows that ontological modeling is indeed adequate for large technical,
collaboratively developed documentations, where modifications can lead easily to incoherence.
The current checks help to systematically avoid this type of incoherence between formal and
informal parts. \<close>
section*[onto_future::technical]\<open> Monitor Classes \<close>
text\<open> Besides sub-typing, there is another relation between
document classes: a class can be a \<^emph>\<open>monitor\<close> to other ones,
which is expressed by the occurrence of a \inlineisar+where+ clause
in the document class definition containing a regular
expression (see @{example \<open>scholar_onto\<close>}).
While class-extension refers to data-inheritance of attributes,
a monitor imposes structural constraints -- the order --
in which instances of monitored classes may occur. \<close>
text\<open>
The control of monitors is done by the commands:
\<^item> \inlineisar+open_monitor* + <doc-class>
\<^item> \inlineisar+close_monitor* + <doc-class>
\<close>
text\<open>
where the automaton of the monitor class is expected to be in a final state. In the final state,
user-defined SML Monitors can be nested, so it is possible to "overlay" one or more monitoring
classes and imposing different sets of structural constraints in a Classes which are neither
directly nor indirectly (via inheritance) mentioned in the monitor are \<^emph>\<open>independent\<close> from a
monitor; instances of independent test elements may occur freely. \<close>
section*[conclusion::conclusion]\<open> Conclusion and Related Work\<close>
text\<open> We have demonstrated the use of \<^isadof>, a novel ontology modeling and enforcement
IDE deeply integrated into the Isabelle/Isar Framework. The two most distinguishing features are
\<^item> \<^isadof> and its ontology language are a strongly typed language that allows
for referring (albeit not reasoning) to entities of \<^isabelle>, most notably types, terms,
and (formally proven) theorems, and
\<^item> \<^isadof> is supported by the Isabelle/PIDE framework; thus, the advantages of an IDE for
text-exploration (which is the type of this link? To which text element does this link refer?
Which are the syntactic alternatives here?) were available during editing
instead of a post-hoc validation process.
\<close>
text\<open> Of course, a conventional batch-process also exists which can be used
for the validation of large document bases in a conventional continuous build process.
This combination of formal and semi-informal elements, as well as a systematic enforcement
of the coherence to a document ontology of the latter, is, as we believe, novel and offers
a unique potential for the semantic treatment of scientific texts and technical documentations. \<close>
text\<open>
To our knowledge, this is the first ontology-driven framework for
editing mathematical and technical documents that focuses particularly
on documents mixing formal and informal content---a type of documents
that is very common in technical certification processes. We see
mainly one area of related works: IDEs and text editors that support
editing and checking of documents based on an ontology. There is a
large group of ontology editors (\<^eg>, \<^Protege>~@{cite "protege"},
Fluent Editor~@{cite "cognitum"}, NeOn~@{cite "neon"}, or
OWLGrEd~@{cite "owlgred"}). With them, we share the support for defining
ontologies as well as auto-completion when editing documents based on
an ontology. While our ontology definitions are currently based on a
textual definition, widely used ontology editors (\<^eg>,
OWLGrEd~@{cite "owlgred"}) also support graphical notations. This could
be added to \<^isadof> in the future. A unique feature of \<^isadof> is the
deep integration of formal and informal text parts. The only other
work in this area we are aware of is rOntorium~@{cite "rontorium"}, a plugin
for \<^Protege> that integrates R~@{cite "adler:r:2010"} into an
ontology environment. Here, the main motivation behind this
integration is to allow for statistically analyze ontological
documents. Thus, this is complementary to our work.
\<close>
text\<open> \<^isadof> in its present form has a number of technical short-comings as well
as potentials not yet explored. On the long list of the short-comings is the
fact that strings inside HOL-terms do not support, for example, Unicode.
For the moment, \<^isadof> is conceived as an
add-on for \<^isabelle>; a much deeper integration of \<^isadof> into Isabelle
could increase both performance and uniformity. Finally, different target
presentation (such as HTML) would be highly desirable in particular for the
math exam scenarios. And last but not least, it would be desirable that PIDE
itself is ``ontology-aware'' and can, for example, use meta-information
to control read- and write accesses of \<^emph>\<open>parts\<close> of documents.
\<close>
paragraph\<open> Availability. \<close>
text\<open> The implementation of the framework, the discussed ontology definitions,
and examples are available at
\url{\dofurl}.\<close>
paragraph\<open> Acknowledgement. \<close>
text\<open> This work was partly supported by the framework of IRT SystemX, Paris-Saclay, France,
and therefore granted with public funds within the scope of the Program ``Investissements d’Avenir''.\<close>
(*<*)
section*[bib::bibliography]\<open>References\<close>
close_monitor*[this]
end
(*>*)
|
module contactForceLaw_2_boxes_Prismatic
using Modia3D
using Modia3D.StaticArrays
import Modia3D.ModiaMath
vmat1 = Modia3D.Material(color="LightBlue" , transparency=0.5) # material of SolidFileMesh
vmat2 = deepcopy(vmat1) # material of convex decomposition of SolidFileMesh
vmat2.transparency = 0.7
cmat = "Steel"
@assembly TwoBoxes begin
world = Modia3D.Object3D(visualizeFrame=true)
boxMoving = Modia3D.Object3D(Modia3D.Solid(Modia3D.SolidBox(0.5,0.5,0.5) , "Steel", vmat1; contactMaterial = cmat) )
helpFrame1 = Modia3D.Object3D(visualizeFrame=false)
helpFrame2 = Modia3D.Object3D(visualizeFrame=false)
prisX = Modia3D.Prismatic(world, helpFrame1; axis=1, v_start=-6.0, s_start=0.0, canCollide=true)
prisY = Modia3D.Prismatic(helpFrame1, helpFrame2, axis=2, v_start=2.0, s_start=0.0, canCollide=true)
prisZ = Modia3D.Prismatic(helpFrame2, boxMoving, axis=3, v_start=4.0, s_start=0.0, canCollide=true)
box = Modia3D.Object3D(world, Modia3D.Solid(Modia3D.SolidBox(3.0,2.0,5.0) , "Steel", vmat1; contactMaterial = cmat); r=[-3.0, 0.0, 1.5], fixed=true) # R=ModiaMath.rot2(-pi/3),
end
gravField = Modia3D.UniformGravityField(g=9.81, n=[-1,0,0])
threeD = TwoBoxes(sceneOptions=Modia3D.SceneOptions(gravityField=gravField,visualizeFrames=true, defaultFrameLength=0.7,nz_max = 100, enableContactDetection=true, visualizeContactPoints=true, visualizeSupportPoints=true))
# Modia3D.visualizeAssembly!( threeD )
model = Modia3D.SimulationModel( threeD )
ModiaMath.print_ModelVariables(model)
result = ModiaMath.simulate!(model; stopTime=5.0, tolerance=1e-6,interval=0.001, log=false)
ModiaMath.plot(result, ["prisX.r","prisX.v"])
println("... success of contactForceLaw_2_boxes_Prismatic.jl!")
end
|
acCreateUserF1 {
# this should only be executed within the core.re file
msiCreateUser ::: msiRollback;
acCreateDefaultCollections ::: msiRollback;
msiAddUserToGroup("public") ::: msiRollback;
msiCommit;
}
|
This article discusses the Microsoft SQL Server Analysis Services formats that are supported by cube formulas in Excel Services in SharePoint Server 2007.
If a cell in a workbook has no defined number format, the number format is set to the Analysis Services format. This is true if the Analysis Services format is supported. If a cell in a workbook has a defined number format, the cell number format takes precedence over the Analysis Services format. This is true if the Analysis Services format is supported. The cell number format is applied, and the Analysis Services format is disregarded.
Note If no specific number formats have been applied to the cell, the general number format will be applied. The workbook author can still use a specific number format, date format, or percentage format on the cells that contain cube formulas to override these format selections. |
For each modeling standard, you will complete a Modeling Project Form. Find the appropriate standard/version on the Suggested Exercises site, then complete the version assigned to you below.
Completed projects should be uploaded to Gradescope. |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.specific_limits
import order.filter.countable_Inter
import topology.G_delta
/-!
# Baire theorem
In a complete metric space, a countable intersection of dense open subsets is dense.
The good concept underlying the theorem is that of a Gδ set, i.e., a countable intersection
of open sets. Then Baire theorem can also be formulated as the fact that a countable
intersection of dense Gδ sets is a dense Gδ set. We prove Baire theorem, giving several different
formulations that can be handy. We also prove the important consequence that, if the space is
covered by a countable union of closed sets, then the union of their interiors is dense.
The names of the theorems do not contain the string "Baire", but are instead built from the form of
the statement. "Baire" is however in the docstring of all the theorems, to facilitate grep searches.
We also define the filter `residual α` generated by dense `Gδ` sets and prove that this filter
has the countable intersection property.
-/
noncomputable theory
open_locale classical topological_space filter ennreal
open filter encodable set
variables {α : Type*} {β : Type*} {γ : Type*} {ι : Type*}
section Baire_theorem
open emetric ennreal
variables [pseudo_emetric_space α] [complete_space α]
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here when
the source space is ℕ (and subsumed below by `dense_Inter_of_open` working with any
encodable source space). -/
theorem dense_Inter_of_open_nat {f : ℕ → set α} (ho : ∀n, is_open (f n))
(hd : ∀n, dense (f n)) : dense (⋂n, f n) :=
begin
let B : ℕ → ℝ≥0∞ := λn, 1/2^n,
have Bpos : ∀n, 0 < B n,
{ intro n,
simp only [B, one_div, one_mul, ennreal.inv_pos],
exact pow_ne_top two_ne_top },
/- Translate the density assumption into two functions `center` and `radius` associating
to any n, x, δ, δpos a center and a positive radius such that
`closed_ball center radius` is included both in `f n` and in `closed_ball x δ`.
We can also require `radius ≤ (1/2)^(n+1)`, to ensure we get a Cauchy sequence later. -/
have : ∀n x δ, δ ≠ 0 → ∃y r, 0 < r ∧ r ≤ B (n+1) ∧ closed_ball y r ⊆ (closed_ball x δ) ∩ f n,
{ assume n x δ δpos,
have : x ∈ closure (f n) := hd n x,
rcases emetric.mem_closure_iff.1 this (δ/2) (ennreal.half_pos δpos) with ⟨y, ys, xy⟩,
rw edist_comm at xy,
obtain ⟨r, rpos, hr⟩ : ∃ r > 0, closed_ball y r ⊆ f n :=
nhds_basis_closed_eball.mem_iff.1 (is_open_iff_mem_nhds.1 (ho n) y ys),
refine ⟨y, min (min (δ/2) r) (B (n+1)), _, _, λz hz, ⟨_, _⟩⟩,
show 0 < min (min (δ / 2) r) (B (n+1)),
from lt_min (lt_min (ennreal.half_pos δpos) rpos) (Bpos (n+1)),
show min (min (δ / 2) r) (B (n+1)) ≤ B (n+1), from min_le_right _ _,
show z ∈ closed_ball x δ, from calc
edist z x ≤ edist z y + edist y x : edist_triangle _ _ _
... ≤ (min (min (δ / 2) r) (B (n+1))) + (δ/2) : add_le_add hz (le_of_lt xy)
... ≤ δ/2 + δ/2 : add_le_add (le_trans (min_le_left _ _) (min_le_left _ _)) le_rfl
... = δ : ennreal.add_halves δ,
show z ∈ f n, from hr (calc
edist z y ≤ min (min (δ / 2) r) (B (n+1)) : hz
... ≤ r : le_trans (min_le_left _ _) (min_le_right _ _)) },
choose! center radius Hpos HB Hball using this,
refine λ x, (mem_closure_iff_nhds_basis nhds_basis_closed_eball).2 (λ ε εpos, _),
/- `ε` is positive. We have to find a point in the ball of radius `ε` around `x` belonging to all
`f n`. For this, we construct inductively a sequence `F n = (c n, r n)` such that the closed ball
`closed_ball (c n) (r n)` is included in the previous ball and in `f n`, and such that
`r n` is small enough to ensure that `c n` is a Cauchy sequence. Then `c n` converges to a
limit which belongs to all the `f n`. -/
let F : ℕ → (α × ℝ≥0∞) := λn, nat.rec_on n (prod.mk x (min ε (B 0)))
(λn p, prod.mk (center n p.1 p.2) (radius n p.1 p.2)),
let c : ℕ → α := λn, (F n).1,
let r : ℕ → ℝ≥0∞ := λn, (F n).2,
have rpos : ∀ n, 0 < r n,
{ assume n,
induction n with n hn,
exact lt_min εpos (Bpos 0),
exact Hpos n (c n) (r n) hn.ne' },
have r0 : ∀ n, r n ≠ 0 := λ n, (rpos n).ne',
have rB : ∀n, r n ≤ B n,
{ assume n,
induction n with n hn,
exact min_le_right _ _,
exact HB n (c n) (r n) (r0 n) },
have incl : ∀n, closed_ball (c (n+1)) (r (n+1)) ⊆ (closed_ball (c n) (r n)) ∩ (f n) :=
λ n, Hball n (c n) (r n) (r0 n),
have cdist : ∀n, edist (c n) (c (n+1)) ≤ B n,
{ assume n,
rw edist_comm,
have A : c (n+1) ∈ closed_ball (c (n+1)) (r (n+1)) := mem_closed_ball_self,
have I := calc
closed_ball (c (n+1)) (r (n+1)) ⊆ closed_ball (c n) (r n) :
subset.trans (incl n) (inter_subset_left _ _)
... ⊆ closed_ball (c n) (B n) : closed_ball_subset_closed_ball (rB n),
exact I A },
have : cauchy_seq c :=
cauchy_seq_of_edist_le_geometric_two _ one_ne_top cdist,
-- as the sequence `c n` is Cauchy in a complete space, it converges to a limit `y`.
rcases cauchy_seq_tendsto_of_complete this with ⟨y, ylim⟩,
-- this point `y` will be the desired point. We will check that it belongs to all
-- `f n` and to `ball x ε`.
use y,
simp only [exists_prop, set.mem_Inter],
have I : ∀n, ∀m ≥ n, closed_ball (c m) (r m) ⊆ closed_ball (c n) (r n),
{ assume n,
refine nat.le_induction _ (λm hnm h, _),
{ exact subset.refl _ },
{ exact subset.trans (incl m) (subset.trans (inter_subset_left _ _) h) }},
have yball : ∀n, y ∈ closed_ball (c n) (r n),
{ assume n,
refine is_closed_ball.mem_of_tendsto ylim _,
refine (filter.eventually_ge_at_top n).mono (λ m hm, _),
exact I n m hm mem_closed_ball_self },
split,
show ∀n, y ∈ f n,
{ assume n,
have : closed_ball (c (n+1)) (r (n+1)) ⊆ f n := subset.trans (incl n) (inter_subset_right _ _),
exact this (yball (n+1)) },
show edist y x ≤ ε, from le_trans (yball 0) (min_le_left _ _),
end
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with ⋂₀. -/
theorem dense_sInter_of_open {S : set (set α)} (ho : ∀s∈S, is_open s) (hS : countable S)
(hd : ∀s∈S, dense s) : dense (⋂₀S) :=
begin
cases S.eq_empty_or_nonempty with h h,
{ simp [h] },
{ rcases hS.exists_surjective h with ⟨f, hf⟩,
have F : ∀n, f n ∈ S := λn, by rw hf; exact mem_range_self _,
rw [hf, sInter_range],
exact dense_Inter_of_open_nat (λn, ho _ (F n)) (λn, hd _ (F n)) }
end
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with
an index set which is a countable set in any type. -/
theorem dense_bInter_of_open {S : set β} {f : β → set α} (ho : ∀s∈S, is_open (f s))
(hS : countable S) (hd : ∀s∈S, dense (f s)) : dense (⋂s∈S, f s) :=
begin
rw ← sInter_image,
apply dense_sInter_of_open,
{ rwa ball_image_iff },
{ exact hS.image _ },
{ rwa ball_image_iff }
end
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with
an index set which is an encodable type. -/
theorem dense_Inter_of_open [encodable β] {f : β → set α} (ho : ∀s, is_open (f s))
(hd : ∀s, dense (f s)) : dense (⋂s, f s) :=
begin
rw ← sInter_range,
apply dense_sInter_of_open,
{ rwa forall_range_iff },
{ exact countable_range _ },
{ rwa forall_range_iff }
end
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with ⋂₀. -/
theorem dense_sInter_of_Gδ {S : set (set α)} (ho : ∀s∈S, is_Gδ s) (hS : countable S)
(hd : ∀s∈S, dense s) : dense (⋂₀S) :=
begin
-- the result follows from the result for a countable intersection of dense open sets,
-- by rewriting each set as a countable intersection of open sets, which are of course dense.
choose T hTo hTc hsT using ho,
have : ⋂₀ S = ⋂₀ (⋃ s ∈ S, T s ‹_›), -- := (sInter_bUnion (λs hs, (hT s hs).2.2)).symm,
by simp only [sInter_Union, (hsT _ _).symm, ← sInter_eq_bInter],
rw this,
refine dense_sInter_of_open _ (hS.bUnion hTc) _;
simp only [mem_Union]; rintro t ⟨s, hs, tTs⟩,
show is_open t, from hTo s hs t tTs,
show dense t,
{ intro x,
have := hd s hs x,
rw hsT s hs at this,
exact closure_mono (sInter_subset_of_mem tTs) this }
end
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with
an index set which is an encodable type. -/
theorem dense_Inter_of_Gδ [encodable β] {f : β → set α} (ho : ∀s, is_Gδ (f s))
(hd : ∀s, dense (f s)) : dense (⋂s, f s) :=
begin
rw ← sInter_range,
exact dense_sInter_of_Gδ (forall_range_iff.2 ‹_›) (countable_range _) (forall_range_iff.2 ‹_›)
end
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with
an index set which is a countable set in any type. -/
theorem dense_bInter_of_Gδ {S : set β} {f : Π x ∈ S, set α} (ho : ∀s∈S, is_Gδ (f s ‹_›))
(hS : countable S) (hd : ∀s∈S, dense (f s ‹_›)) : dense (⋂s∈S, f s ‹_›) :=
begin
rw bInter_eq_Inter,
haveI := hS.to_encodable,
exact dense_Inter_of_Gδ (λ s, ho s s.2) (λ s, hd s s.2)
end
/-- Baire theorem: the intersection of two dense Gδ sets is dense. -/
theorem dense.inter_of_Gδ {s t : set α} (hs : is_Gδ s) (ht : is_Gδ t) (hsc : dense s)
(htc : dense t) :
dense (s ∩ t) :=
begin
rw [inter_eq_Inter],
apply dense_Inter_of_Gδ; simp [bool.forall_bool, *]
end
/-- A property holds on a residual (comeagre) set if and only if it holds on some dense `Gδ` set. -/
lemma eventually_residual {p : α → Prop} :
(∀ᶠ x in residual α, p x) ↔ ∃ (t : set α), is_Gδ t ∧ dense t ∧ ∀ x ∈ t, p x :=
calc (∀ᶠ x in residual α, p x) ↔
∀ᶠ x in ⨅ (t : set α) (ht : is_Gδ t ∧ dense t), 𝓟 t, p x :
by simp only [residual, infi_and]
... ↔ ∃ (t : set α) (ht : is_Gδ t ∧ dense t), ∀ᶠ x in 𝓟 t, p x : mem_binfi_of_directed
(λ t₁ h₁ t₂ h₂, ⟨t₁ ∩ t₂, ⟨h₁.1.inter h₂.1, dense.inter_of_Gδ h₁.1 h₂.1 h₁.2 h₂.2⟩, by simp⟩)
⟨univ, is_Gδ_univ, dense_univ⟩
... ↔ _ : by simp [and_assoc]
/-- A set is residual (comeagre) if and only if it includes a dense `Gδ` set. -/
lemma mem_residual {s : set α} : s ∈ residual α ↔ ∃ t ⊆ s, is_Gδ t ∧ dense t :=
(@eventually_residual α _ _ (λ x, x ∈ s)).trans $ exists_congr $
λ t, by rw [exists_prop, and_comm (t ⊆ s), subset_def, and_assoc]
lemma dense_of_mem_residual {s : set α} (hs : s ∈ residual α) : dense s :=
let ⟨t, hts, _, hd⟩ := mem_residual.1 hs in hd.mono hts
instance : countable_Inter_filter (residual α) :=
⟨begin
intros S hSc hS,
simp only [mem_residual] at *,
choose T hTs hT using hS,
refine ⟨⋂ s ∈ S, T s ‹_›, _, _, _⟩,
{ rw [sInter_eq_bInter],
exact Inter₂_mono hTs },
{ exact is_Gδ_bInter hSc (λ s hs, (hT s hs).1) },
{ exact dense_bInter_of_Gδ (λ s hs, (hT s hs).1) hSc (λ s hs, (hT s hs).2) }
end⟩
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with an index set which is a countable set in any type. -/
theorem dense_bUnion_interior_of_closed {S : set β} {f : β → set α} (hc : ∀s∈S, is_closed (f s))
(hS : countable S) (hU : (⋃s∈S, f s) = univ) : dense (⋃s∈S, interior (f s)) :=
begin
let g := λs, (frontier (f s))ᶜ,
have : dense (⋂s∈S, g s),
{ refine dense_bInter_of_open (λs hs, _) hS (λs hs, _),
show is_open (g s), from is_open_compl_iff.2 is_closed_frontier,
show dense (g s),
{ intro x,
simp [interior_frontier (hc s hs)] }},
refine this.mono _,
show (⋂s∈S, g s) ⊆ (⋃s∈S, interior (f s)),
assume x hx,
have : x ∈ ⋃s∈S, f s, { have := mem_univ x, rwa ← hU at this },
rcases mem_Union₂.1 this with ⟨s, hs, xs⟩,
have : x ∈ g s := mem_Inter₂.1 hx s hs,
have : x ∈ interior (f s),
{ have : x ∈ f s \ (frontier (f s)) := mem_inter xs this,
simpa [frontier, xs, (hc s hs).closure_eq] using this },
exact mem_Union₂.2 ⟨s, ⟨hs, this⟩⟩
end
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with `⋃₀`. -/
theorem dense_sUnion_interior_of_closed {S : set (set α)} (hc : ∀s∈S, is_closed s)
(hS : countable S) (hU : (⋃₀ S) = univ) : dense (⋃s∈S, interior s) :=
by rw sUnion_eq_bUnion at hU; exact dense_bUnion_interior_of_closed hc hS hU
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with an index set which is an encodable type. -/
theorem dense_Union_interior_of_closed [encodable β] {f : β → set α} (hc : ∀s, is_closed (f s))
(hU : (⋃s, f s) = univ) : dense (⋃s, interior (f s)) :=
begin
rw ← bUnion_univ,
apply dense_bUnion_interior_of_closed,
{ simp [hc] },
{ apply countable_encodable },
{ rwa ← bUnion_univ at hU }
end
/-- One of the most useful consequences of Baire theorem: if a countable union of closed sets
covers the space, then one of the sets has nonempty interior. -/
theorem nonempty_interior_of_Union_of_closed [nonempty α] [encodable β] {f : β → set α}
(hc : ∀s, is_closed (f s)) (hU : (⋃s, f s) = univ) :
∃s, (interior $ f s).nonempty :=
begin
by_contradiction h,
simp only [not_exists, not_nonempty_iff_eq_empty] at h,
have := calc ∅ = closure (⋃s, interior (f s)) : by simp [h]
... = univ : (dense_Union_interior_of_closed hc hU).closure_eq,
exact univ_nonempty.ne_empty this.symm
end
end Baire_theorem
|
[STATEMENT]
lemma pmf_geometric[simp]: "pmf geometric_pmf n = (1 - p)^n * p"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. pmf local.geometric_pmf n = (1 - p) ^ n * p
[PROOF STEP]
by transfer rule |
import order.conditionally_complete_lattice
open set
-- TODO: Move: conditionally_complete_lattice
private lemma le_csupr_iff.mpr
{α : Type*} {ι : Sort*} [conditionally_complete_lattice α]
{s : ι → α} {a : α} (hs : bdd_above (range s)) (h : ∀ (b : α), (∀ (i : ι), s i ≤ b) → a ≤ b)
: a ≤ supr s :=
h (supr s) (λ i, le_csupr hs i)
|
function stroud_test052 ( )
%*****************************************************************************80
%
%% TEST052 tests BALL_VOLUME_3D.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 06 April 2009
%
% Author:
%
% John Burkardt
%
n = 3;
fprintf ( 1, '\n' );
fprintf ( 1, 'TEST052\n' );
fprintf ( 1, ' In 3 dimensions:\n' );
fprintf ( 1, ' BALL_VOLUME_3D computes the volume of a unit ball.\n' );
fprintf ( 1, ' BALL_VOLUME_ND will be called for comparison.\n' );
fprintf ( 1, '\n' );
fprintf ( 1, ' N R Volume Method\n' );
fprintf ( 1, '\n' );
r = 1.0;
for i = 1 : 3
fprintf ( 1, ' %1d %12f %12f %s\n', ...
n, r, ball_volume_3d ( r ), 'BALL_VOLUME_3D' );
fprintf ( 1, ' %1d %12f %12f %s\n', ...
n, r, ball_volume_nd ( n, r ), 'BALL_VOLUME_ND' );
r = r * 2.0;
end
return
end
|
import logic
import set_theory.zfc
namespace Set
-- We have ext axiom. (Set.ext)
-- Set.eq_empty proves there is only one empty set (using extensionality).
-- We have pairing axiom. (Set.mem_pair)
theorem pair_commutative {x y : Set} : ({x, y} : Set) = {y, x} :=
begin
apply Set.ext,
intro z,
simp [Set.mem_pair] at *,
exact or.comm,
end
theorem singleton_of_pair_self {x : Set} : ({x, x} : Set) = {x} :=
begin
apply Set.ext,
intro z,
simp [Set.mem_pair] at *,
end
def from_list : list Set → Set
| [] := ∅
| (hd :: tl) := {hd} ∪ from_list tl
theorem mem_from_list {l : list Set} (z : Set) : z ∈ from_list l ↔ z ∈ l :=
begin
induction l with hd tl ih,
simp only [list.mem_nil_iff, iff_false, from_list], exact Set.mem_empty _,
simp only [from_list, list.mem_cons_iff, Set.mem_union, Set.mem_singleton],
rw ih,
end
theorem empty_is_subset (x : Set) : ∅ ⊆ x :=
begin
intros z h,
exfalso, exact (Set.mem_empty _) h,
end
theorem p2a : (∅ : Set) ≠ {∅} :=
begin
intro he,
have h : ∅ ∈ {∅} := Set.mem_singleton.mpr rfl,
rw ←he at h,
exact Set.mem_empty _ h,
end
theorem p2b : ({∅} : Set) ≠ {{∅}} :=
begin
intro he,
have h : {∅} ∈ {{∅}} := Set.mem_singleton.mpr rfl,
rw ←he at h,
rw Set.mem_singleton at h,
exact p2a h.symm,
end
theorem p2c : (∅ : Set) ≠ {{∅}} :=
begin
intro he,
have h : {∅} ∈ {{∅}} := Set.mem_singleton.mpr rfl,
rw ←he at h,
exact Set.mem_empty _ h,
end
-- powerset axiom enabled by Set.powerset and Set.mem_powerset
theorem p4 {x y B : Set} (h : {x, y} ⊆ B) : x.pair y ∈ B.powerset.powerset :=
begin
simp only [Set.mem_powerset, Set.pair],
intros z hm,
simp only [Set.mem_pair] at hm,
simp only [Set.mem_powerset],
cases hm,
{ rw hm,
intros s he,
rw Set.mem_singleton at he,
rw he,
apply h,
simp only [Set.mem_pair],
left, refl, },
{ rw hm,
exact h, },
end
def finite_hierarchy : ℕ → Set
| 0 := ∅
| (n + 1) := let V := finite_hierarchy n in V ∪ V.powerset
theorem subset_union_of_subset {x y z : Set} (h : x ⊆ z) : x ⊆ z ∪ y :=
begin
intros c hm,
specialize h hm,
simp only [Set.mem_union],
left, exact h,
end
theorem subset_finite_hierarchy_of_mem {n : ℕ} {x : Set} : x ∈ finite_hierarchy n → x ⊆ finite_hierarchy n :=
begin
induction n with m ih,
{ simp only [finite_hierarchy],
intro h,
exfalso,
exact Set.mem_empty _ h, },
{ simp only [finite_hierarchy, Set.mem_union],
intros h,
cases h,
exact subset_union_of_subset (ih h),
exact subset_union_of_subset (Set.mem_powerset.mp h), },
end
theorem finite_hierarchy_succ (n : ℕ) : finite_hierarchy (n + 1) = (finite_hierarchy n).powerset :=
begin
simp only [finite_hierarchy],
apply Set.ext,
simp only [Set.mem_union],
intro z,
split; intro h,
{ cases h,
simp only [Set.mem_powerset],
exact subset_finite_hierarchy_of_mem h,
exact h, },
{ right, exact h, },
end
lemma singleton_eq {x y : Set} : ({x} : Set) = {y} ↔ x = y :=
begin
rw ←Set.ext_iff, simp only [Set.mem_singleton], exact eq_iff_eq_cancel_left,
end
end Set |
------------------------------------------------------------------------
-- A map function for the substitutions
------------------------------------------------------------------------
open import Data.Universe.Indexed
module deBruijn.Substitution.Function.Map
{i u e} {Uni : IndexedUniverse i u e} where
import Axiom.Extensionality.Propositional as E
import deBruijn.Context; open deBruijn.Context Uni
open import deBruijn.Substitution.Function.Basics
open import Function using (_$_)
open import Level using (_⊔_)
import Relation.Binary.PropositionalEquality as P
private
module Dummy
{t₁} {T₁ : Term-like t₁}
{t₂} {T₂ : Term-like t₂}
where
open Term-like T₁ using ()
renaming (_⊢_ to _⊢₁_; _≅-⊢_ to _≅-⊢₁_; [_] to [_]₁)
open Term-like T₂ using () renaming (_≅-⊢_ to _≅-⊢₂_)
-- Map.
map : ∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} →
[ T₁ ⟶ T₂ ] ρ̂₂ → (ρ₁ : Sub T₁ ρ̂₁) → Sub T₂ (ρ̂₁ ∘̂ ρ̂₂)
map f ρ₁ = f [∘] ρ₁
abstract
-- An unfolding lemma.
map-▻ :
E.Extensionality (i ⊔ u ⊔ e) (i ⊔ u ⊔ e ⊔ t₂) →
∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} {σ}
(f : [ T₁ ⟶ T₂ ] ρ̂₂) (ρ : Sub T₁ ρ̂₁) t →
map f (ρ ▻⇨[ σ ] t) ≅-⇨ map f ρ ▻⇨[ σ ] f · t
map-▻ ext {Γ} {σ = σ} f ρ t = extensionality ext P.refl lemma
where
lemma : ∀ {τ} (x : Γ ▻ σ ∋ τ) →
f · (x /∋ (ρ ▻⇨ t)) ≅-⊢₂ x /∋ (map f ρ ▻⇨ f · t)
lemma zero = P.refl
lemma (suc x) = P.refl
-- A congruence lemma.
map-cong : ∀ {Γ₁ Δ₁ Ε₁} {ρ̂₁₁ : Γ₁ ⇨̂ Δ₁} {ρ̂₂₁ : Δ₁ ⇨̂ Ε₁}
{f₁ : [ T₁ ⟶ T₂ ] ρ̂₂₁} {ρ₁ : Sub T₁ ρ̂₁₁}
{Γ₂ Δ₂ Ε₂} {ρ̂₁₂ : Γ₂ ⇨̂ Δ₂} {ρ̂₂₂ : Δ₂ ⇨̂ Ε₂}
{f₂ : [ T₁ ⟶ T₂ ] ρ̂₂₂} {ρ₂ : Sub T₁ ρ̂₁₂} →
f₁ ≅-⟶ f₂ → ρ₁ ≅-⇨ ρ₂ → map f₁ ρ₁ ≅-⇨ map f₂ ρ₂
map-cong {f₁ = _ , _} {ρ₁ = _ , _} {f₂ = ._ , _} {ρ₂ = ._ , _}
[ P.refl ] [ P.refl ] = [ P.refl ]
abstract
-- Variants which only require that the functions are
-- extensionally equal.
map-cong-ext₁ : E.Extensionality (i ⊔ u ⊔ e) (i ⊔ u ⊔ e ⊔ t₂) →
∀ {Γ₁ Δ Ε₁} {ρ̂₁₁ : Γ₁ ⇨̂ Δ} {ρ̂₂₁ : Δ ⇨̂ Ε₁}
{f₁ : [ T₁ ⟶ T₂ ] ρ̂₂₁} {ρ₁ : Sub T₁ ρ̂₁₁}
{Γ₂ Ε₂} {ρ̂₁₂ : Γ₂ ⇨̂ Δ} {ρ̂₂₂ : Δ ⇨̂ Ε₂}
{f₂ : [ T₁ ⟶ T₂ ] ρ̂₂₂} {ρ₂ : Sub T₁ ρ̂₁₂} →
Ε₁ ≅-Ctxt Ε₂ →
(∀ {σ} (t : Δ ⊢₁ σ) → f₁ · t ≅-⊢₂ f₂ · t) →
ρ₁ ≅-⇨ ρ₂ → map f₁ ρ₁ ≅-⇨ map f₂ ρ₂
map-cong-ext₁ ext {ρ₁ = ρ} {ρ₂ = ._ , _} Ε₁≅Ε₂ f₁≅f₂ [ P.refl ] =
extensionality ext Ε₁≅Ε₂ (λ x → f₁≅f₂ (x /∋ ρ))
map-cong-ext₂ : E.Extensionality (i ⊔ u ⊔ e) (i ⊔ u ⊔ e ⊔ t₂) →
∀ {Γ₁ Δ₁ Ε₁} {ρ̂₁₁ : Γ₁ ⇨̂ Δ₁} {ρ̂₂₁ : Δ₁ ⇨̂ Ε₁}
{f₁ : [ T₁ ⟶ T₂ ] ρ̂₂₁} {ρ₁ : Sub T₁ ρ̂₁₁}
{Γ₂ Δ₂ Ε₂} {ρ̂₁₂ : Γ₂ ⇨̂ Δ₂} {ρ̂₂₂ : Δ₂ ⇨̂ Ε₂}
{f₂ : [ T₁ ⟶ T₂ ] ρ̂₂₂} {ρ₂ : Sub T₁ ρ̂₁₂} →
Δ₁ ≅-Ctxt Δ₂ → Ε₁ ≅-Ctxt Ε₂ →
(∀ {σ₁ σ₂} {t₁ : Δ₁ ⊢₁ σ₁} {t₂ : Δ₂ ⊢₁ σ₂} →
t₁ ≅-⊢₁ t₂ → f₁ · t₁ ≅-⊢₂ f₂ · t₂) →
ρ₁ ≅-⇨ ρ₂ → map f₁ ρ₁ ≅-⇨ map f₂ ρ₂
map-cong-ext₂ ext P.refl Ε₁≅Ε₂ f₁≅f₂ ρ₁≅ρ₂ =
map-cong-ext₁ ext Ε₁≅Ε₂ (λ t → f₁≅f₂ (P.refl {x = [ t ]₁})) ρ₁≅ρ₂
-- Some sort of naturality statement for _/∋_. (Note that this lemma
-- holds definitionally. This is not the case for the corresponding
-- lemma in deBruijn.Substitution.Data.Map.)
/∋-map : ∀ {Γ Δ Ε σ} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} →
(x : Γ ∋ σ) (f : [ T₁ ⟶ T₂ ] ρ̂₂) (ρ : Sub T₁ ρ̂₁) →
x /∋ map f ρ ≅-⊢₂ f · (x /∋ ρ)
/∋-map x f ρ = P.refl
open Dummy public
-- Map is functorial.
map-[id] : ∀ {t} {T : Term-like t} {Γ Δ} {ρ̂ : Γ ⇨̂ Δ}
(ρ : Sub T ρ̂) →
map ([id] {T = T}) ρ ≅-⇨ ρ
map-[id] = [id]-[∘]
map-[∘] :
∀ {t₁} {T₁ : Term-like t₁}
{t₂} {T₂ : Term-like t₂}
{t₃} {T₃ : Term-like t₃}
{Γ Δ Ε Ζ} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} {ρ̂₃ : Ε ⇨̂ Ζ}
(f₂ : [ T₂ ⟶ T₃ ] ρ̂₃) (f₁ : [ T₁ ⟶ T₂ ] ρ̂₂)
(ρ : Sub T₁ ρ̂₁) →
map (f₂ [∘] f₁) ρ ≅-⇨ map f₂ (map f₁ ρ)
map-[∘] f₂ f₁ ρ = sym-⟶ $ [∘]-[∘] f₂ f₁ ρ
|
[STATEMENT]
lemma one_not_le_zero_ereal[simp]: "\<not> (1 \<le> (0::ereal))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<not> 1 \<le> 0
[PROOF STEP]
by (simp add: one_ereal_def zero_ereal_def) |
## develop the preprocess
import pandas as pd
import os
import matplotlib.pyplot as plt
import numpy as np
strProjectFolder="datasets/R3-Yahoo/"
DataTest = pd.read_csv(os.path.join(strProjectFolder, "ydata-ymusic-rating-study-v1_0-test.txt"),sep="\\t",header=None)
DataTest.columns=["UserID", "ItemID", "Rating"]
DataTrain = pd.read_csv(os.path.join(strProjectFolder, "ydata-ymusic-rating-study-v1_0-train.txt"),sep="\\t",header=None)
DataTrain.columns=["UserID", "ItemID", "Rating"]
preprocess_dir="datasets/preprocessed/"
os.makedirs(preprocess_dir, exist_ok=True)
DataTest.to_csv(preprocess_dir+"train.csv")
# split the original test to 3 parts, auxlliary, validation, test
auxilliary_ratio=0.1
valid_ratio=0.1
UserID=DataTest.UserID.unique()
UserID.sort()
n_User=len(UserID)
aux_end=int(auxilliary_ratio*n_User)
vali_end=aux_end+int(valid_ratio*n_User)
auxilliary=UserID[:aux_end]
Data_aux=DataTest[DataTest.UserID.isin(auxilliary)]
Data_aux.to_csv(preprocess_dir+"aux.csv")
validation=UserID[aux_end:vali_end]
Data_vali=DataTest[DataTest.UserID.isin(validation)]
Data_vali.to_csv(preprocess_dir+"vali.csv")
test=UserID[vali_end:]
Data_test=DataTest[DataTest.UserID.isin(test)]
Data_test.to_csv(preprocess_dir+"test.csv") |
import implementation.model.predicate
import implementation.model.sys_state
import implementation.spec.main
variables {pid_t : Type} [linear_order pid_t] [fintype pid_t] {value_t : Type}
{is_quorum : finset pid_t → Prop} [decidable_pred is_quorum]
[quorum_assumption is_quorum] {vals : pid_t → value_t}
-- For each process, the current ballot will never decrease when taking a step.
lemma ballot_nondecreasing
{u v : sys_state pid_t (server pid_t value_t is_quorum vals) (message pid_t value_t)}
(p : pid_t) : u.possible_next v → (u.procs p).curr ≤ (v.procs p).curr :=
begin
rintros ⟨receiver, sender, e, he, deliverable, proc_change, ntwk_change, procs_same, ntwks_same⟩,
cases decidable.em (p = receiver),
swap,
{ rw procs_same p h },
rw h, clear h p procs_same ntwks_same ntwk_change,
rw proc_change,
have key := state_change receiver (u.procs receiver) e.msg sender,
cases key,
{ rw key },
cases e.msg,
case p1a : b {
rw key.right, exact le_of_lt key.left
},
case p1b : b p_or {
cases key,
{ rw key.right, exact le_of_lt key.left },
cases key,
{ rw key.right.right.right.right },
rw key.right.right.right.right.right
},
case p2a : pr {
rw key.right, exact key.left
},
case p2b : b accepted {
rw key.right, exact le_of_lt key.left
},
case preempt : {
rw key.right,
exact le_of_lt (ballot.next_larger receiver (u.procs receiver).curr)
}
end
|
State Before: ι : Type u_1
M : Type ?u.25531
n : ℕ
I J : Box ι
i : ι
x : ℝ
⊢ J ∈ split I i x ↔ ↑J = ↑I ∩ {y | y i ≤ x} ∨ ↑J = ↑I ∩ {y | x < y i} State After: no goals Tactic: simp [mem_split_iff, ← Box.withBotCoe_inj] |
###### Knowledge Discovery and Data Mining (CS 513) ######
# (Final Exam)
# Course : CS 513 - A
# First Name : PARAS
# Last Name : GARG
# Id : 10414982
# Purpose : Final Exam - IRIS Dataset
###### ******************************************** ######
### Develop the following program in R
# a. Load the IRIS dataset into memory
iris_dataset <- data.frame(iris);
View(iris_dataset);
# b. Create a test dataset by extracting every third (3rd) row of the data, starting with the second row.
extract_range <- seq(from = 2, to = nrow(iris_dataset), by = 3);
test_dataset <- iris_dataset[extract_range, ];
View(test_dataset);
# c. Create a training dataset by excluding the test data from the IRIS dataset
train_dataset <- iris_dataset[-extract_range, ];
View(train_dataset);
### clearing environment
rm(list = ls()) |
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LogicalFramework.AdequacyTheorems where
module Example5 where
-- First-order logic with equality.
open import Common.FOL.FOL-Eq public
postulate
A B C : Set
f₁ : A → C
f₂ : B → C
g : (A → C) → (B → C) → A ∨ B → C
g f₁ f₂ (inj₁ a) = f₁ a
g f₁ f₂ (inj₂ b) = f₂ b
g' : (A → C) → (B → C) → A ∨ B → C
g' f₁ f₂ x = case f₁ f₂ x
module Example7 where
-- First-order logic with equality.
open import Common.FOL.FOL-Eq public
postulate
C : D → D → Set
d : ∀ {a} → C a a
g : ∀ {a b} → a ≡ b → C a b
g refl = d
g' : ∀ {a b} → a ≡ b → C a b
g' {a} h = subst (C a) h d
module Example10 where
-- First-order logic with equality.
open import Common.FOL.FOL-Eq public
postulate
A B C : Set
f₁ : A → C
f₂ : B → C
f : A ∨ B → C
f (inj₁ a) = f₁ a
f (inj₂ b) = f₂ b
f' : A ∨ B → C
f' = case f₁ f₂
module Example20 where
-- First-order logic with equality.
open import Common.FOL.FOL-Eq public
f : {A : D → Set}{t t' : D} → t ≡ t' → A t → A t'
f {A} {t} {.t} refl At = d At
where
postulate d : A t → A t
f' : {A : D → Set}{t t' : D} → t ≡ t' → A t → A t'
f' {A} h At = subst A h At
module Example30 where
-- First-order logic with equality.
open import Common.FOL.FOL-Eq public
postulate
A B C E : Set
f₁ : A → E
f₂ : B → E
f₃ : C → E
g : (A ∨ B) ∨ C → E
g (inj₁ (inj₁ a)) = f₁ a
g (inj₁ (inj₂ b)) = f₂ b
g (inj₂ c) = f₃ c
g' : (A ∨ B) ∨ C → E
g' = case (case f₁ f₂) f₃
module Example40 where
infixl 9 _+_ _+'_
infix 7 _≡_
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
ℕ-ind : (A : ℕ → Set) → A zero → (∀ n → A n → A (succ n)) → ∀ n → A n
ℕ-ind A A0 h zero = A0
ℕ-ind A A0 h (succ n) = h n (ℕ-ind A A0 h n)
data _≡_ (x : ℕ) : ℕ → Set where
refl : x ≡ x
subst : (A : ℕ → Set) → ∀ {x y} → x ≡ y → A x → A y
subst A refl Ax = Ax
_+_ : ℕ → ℕ → ℕ
zero + n = n
succ m + n = succ (m + n)
_+'_ : ℕ → ℕ → ℕ
m +' n = ℕ-ind (λ _ → ℕ) n (λ x y → succ y) m
-- Properties using pattern matching.
succCong : ∀ {m n} → m ≡ n → succ m ≡ succ n
succCong refl = refl
+-rightIdentity : ∀ n → n + zero ≡ n
+-rightIdentity zero = refl
+-rightIdentity (succ n) = succCong (+-rightIdentity n)
-- Properties using the basic inductive constants.
succCong' : ∀ {m n} → m ≡ n → succ m ≡ succ n
succCong' {m} h = subst (λ x → succ m ≡ succ x) h refl
+'-leftIdentity : ∀ n → zero +' n ≡ n
+'-leftIdentity n = refl
+'-rightIdentity : ∀ n → n +' zero ≡ n
+'-rightIdentity = ℕ-ind A A0 is
where
A : ℕ → Set
A n = n +' zero ≡ n
A0 : A zero
A0 = refl
is : ∀ n → A n → A (succ n)
is n ih = succCong' ih
module Example50 where
infixl 10 _*_
infixl 9 _+_
infix 7 _≡_
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
ℕ-ind : (A : ℕ → Set) → A zero → (∀ n → A n → A (succ n)) → ∀ n → A n
ℕ-ind A A0 h zero = A0
ℕ-ind A A0 h (succ n) = h n (ℕ-ind A A0 h n)
data _≡_ (x : ℕ) : ℕ → Set where
refl : x ≡ x
ℕ-rec : {A : Set} → A → (ℕ → A → A) → ℕ → A
ℕ-rec {A} = ℕ-ind (λ _ → A)
_+_ : ℕ → ℕ → ℕ
m + n = ℕ-rec n (λ _ x → succ x) m
+-0x : ∀ n → zero + n ≡ n
+-0x n = refl
+-Sx : ∀ m n → succ m + n ≡ succ (m + n)
+-Sx m n = refl
_*_ : ℕ → ℕ → ℕ
m * n = ℕ-rec zero (λ _ x → n + x) m
*-0x : ∀ n → zero * n ≡ zero
*-0x n = refl
*-Sx : ∀ m n → succ m * n ≡ n + m * n
*-Sx m n = refl
|
module Selective.Examples.TestCall where
open import Selective.Libraries.Call
open import Prelude
AddReplyMessage : MessageType
AddReplyMessage = ValueType UniqueTag ∷ [ ValueType ℕ ]ˡ
AddReply : InboxShape
AddReply = [ AddReplyMessage ]ˡ
AddMessage : MessageType
AddMessage = ValueType UniqueTag ∷ ReferenceType AddReply ∷ ValueType ℕ ∷ [ ValueType ℕ ]ˡ
Calculator : InboxShape
Calculator = [ AddMessage ]ˡ
calculatorActor : ∀ {i} → ∞ActorM (↑ i) Calculator (Lift (lsuc lzero) ⊤) [] (λ _ → [])
calculatorActor .force = receive ∞>>= λ {
(Msg Z (tag ∷ _ ∷ n ∷ m ∷ [])) .force →
(Z ![t: Z ] (lift tag ∷ [ lift (n + m) ]ᵃ)) ∞>> (do
strengthen []
calculatorActor)
; (Msg (S ()) _)
}
TestBox : InboxShape
TestBox = AddReply
calltestActor : ∀{i} → ∞ActorM i TestBox (Lift (lsuc lzero) ℕ) [] (λ _ → [])
calltestActor .force = spawn∞ calculatorActor ∞>> do
x ← call Z Z 0
((lift 10) ∷ [ lift 32 ]ᵃ)
⊆-refl Z
strengthen []
return-result x
where
return-result : SelectedMessage {TestBox} (call-select 0 [ Z ]ᵐ Z) →
∀ {i} → ∞ActorM i TestBox (Lift (lsuc lzero) ℕ) [] (λ _ → [])
return-result record { msg = (Msg Z (tag ∷ n ∷ [])) } = return n
return-result record { msg = (Msg (S x) x₁) ; msg-ok = () } |
The 5-piece Apothecary round waterfall pendant chandelier features five blown glass pendants (two short, one regular, two tall - see below) suspended from a round canopy. Science meets art in this sleek modern collection showcasing crisp, crystal-clear glass shades subtly reminiscent of 19th century apothecary jars. Available in four glass colors and four hardware finish options.
Accepts 5 lightbulbs with E26 Base, 40 Watts, A19 (dimmable, not included). |
If $f(x) \in o(g(x))$ for all $x \in A$, then $\sum_{y \in A} f(y, x) \in o(g(x))$. |
Module M0.
Inductive foo (A : Type) := Foo {
foo0 : option (bar A);
foo1 : nat;
foo2 := foo1 = 0;
foo3 : foo2;
}
with bar (A : Type) := Bar {
bar0 : A;
bar1 := 0;
bar2 : bar1 = 0;
bar3 : nat -> foo A;
}.
End M0.
Module M1.
Set Primitive Projections.
Inductive foo (A : Type) := Foo {
foo0 : option (bar A);
foo1 : nat;
foo2 := foo1 = 0;
foo3 : foo2;
}
with bar (A : Type) := Bar {
bar0 : A;
bar1 := 0;
bar2 : bar1 = 0;
bar3 : nat -> foo A;
}.
End M1.
Module M2.
Set Primitive Projections.
CoInductive foo (A : Type) := Foo {
foo0 : option (bar A);
foo1 : nat;
foo2 := foo1 = 0;
foo3 : foo2;
}
with bar (A : Type) := Bar {
bar0 : A;
bar1 := 0;
bar2 : bar1 = 0;
bar3 : nat -> foo A;
}.
End M2.
|
From Coq Require Import
Morphisms
Setoid
RelationClasses
Arith
Lia
List.
From ExtLib Require Import
Monad
Traversable
Data.List.
From ITree Require Import
ITree
ITreeFacts
Traces.
Import ListNotations.
Import ITreeNotations.
Import MonadNotation.
Open Scope monad_scope.
(* * Idea * *)
(* An environment is an transition system over state space and action space. An deterministic environment has type "State * Action -> State" and an agent policy has type "State -> Action". Now represent an environment as an itree and agent policy as effect. *)
(* * Example * *)
(* One-demension road with cliff. State space has type "nat" and there is a cliff at position "4". Action space is "{Left, Right}". If the car reach position "4" it will crash. A safe environment should not let this happen while any decision the agent makes. *)
Definition StateT := nat.
Inductive ActionT : Type :=
| Left
| Right.
(* There are only three effects. Read current state, read the action generated by agent with current state, update current state. Each step an agent goes in an environment will cause these three effects. *)
Inductive rlE : Type -> Type :=
| InputA : rlE ActionT
| InputS: rlE StateT
| OutputS : StateT -> rlE unit.
(* An enviornment has type "itree rlE unit", which says it can cause all effects in rlE and return nothing(the only output of an environment is exported by "OutputS"). It should first read current state and the action maked by agent, then write a new state. *)
Definition trigger_inr1 {D E : Type -> Type} : E ~> itree (D +' E)
:= fun _ e => ITree.trigger (inr1 e).
Arguments trigger_inr1 {D E} [T].
Definition unsafe_env : itree rlE unit :=
(rec-fix env_ _ :=
state <- trigger_inr1 InputS ;; (* read current state *)
action <- ITree.trigger (inr1 InputA) ;; (* read action from agent *)
match (state, action) with
| (0, Left) => ITree.trigger (inr1 (OutputS 0)) ;; env_ tt
| (S s, Left) => ITree.trigger (inr1 (OutputS s)) ;; env_ tt
| (s, Right) => ITree.trigger (inr1 (OutputS (S s))) ;; env_ tt
end
) tt.
Definition safe_env_body : StateT -> ActionT -> StateT :=
fun state action =>
match state with
| 0 =>
match action with
| Left => 0
| Right => S state
end
| S (2 as s) =>
match action with
| Left => 2
| Right => 3
end
| S s =>
match action with
| Left => s
| Right => S state
end
end.
(* A trace of a reinforcement environment looks like "{s <- InputS ;; a <- InputA ;; tt <- OutputS s'}*": "s" represents the current state, "a" represents the action generated by the agent, "s'" indicates the next state, which is the output of an environment. A RL trace has to follow the consistency requirement: the adjacent "s'" and "s" should be equal. i.e. in "s1 <- InputS ;; a1 <- InputA ;; tt <- OutputS s1' ;; a2 <- InputS ;; a2 <- InputA ;; tt <- OutputS s2'...", "s1' = s2". *)
Notation "[ e , a ] t" := (TEventResponse e a t) (at level 80, right associativity).
Notation "[< e >]" := (TEventEnd e) (at level 80, right associativity).
Definition StepRecord : Type := StateT * ActionT * StateT.
Definition ret_rl_trace (x : StepRecord) : @trace rlE unit :=
match x with
(s, a, s') => [InputS, s] [InputA, a] [< OutputS s'>]
end.
Definition bind_rl_trace (x : StepRecord) (tr: @trace rlE unit) : @trace rlE unit :=
match x with
(s, a, s') => [InputS, s] [InputA, a] [OutputS s', tt] tr
end.
Definition step_adjacent (x1 x2: StepRecord) : Prop :=
match x1, x2 with
(s1, a1, s1'), (s2, a2, s2') => s1' = s2
end.
Inductive is_rltrace : @trace rlE unit -> Prop :=
| ret_is_rltrace : forall x, is_rltrace (ret_rl_trace x)
| bind_ret_is_rltrace: forall x1 x2,
step_adjacent x1 x2 ->
is_rltrace (bind_rl_trace x1 (ret_rl_trace x2))
| bind_bind_is_rltrace: forall x1 x2 tr,
step_adjacent x1 x2 ->
is_rltrace (bind_rl_trace x2 tr) ->
is_rltrace (bind_rl_trace x1 (bind_rl_trace x2 tr)).
(* An inductive invariant of an environment says: within one step "(s,a,s')", if "s" <= 3, forall "a", "s'" <=3. *)
Print Eqdep.EqdepTheory.inj_pair2.
Ltac inj_event_pair :=
match goal with
| [H : existT _ _ _ = existT _ _ _ |- _] => (apply (Eqdep.EqdepTheory.inj_pair2 Type) in H; subst)
end.
Ltac clear_id :=
match goal with
| [H : ?a = ?a |- _] => clear H
end.
Section Proper.
Local Open Scope signature_scope.
Global Instance proper_is_trace {E R} : Proper ((@eutt E R R eq) ==> eq ==> iff) is_trace.
Proof.
intros t t' Ht tr tr' Htr. subst tr'.
apply trace_eq_iff_eutt in Ht.
unfold trace_eq in Ht.
intuition.
Qed.
End Proper.
Ltac inj_event_pair_all := repeat (try inj_event_pair; idtac).
Ltac auto_is_trace_H H := unfold observe in H; cbn in H.
Ltac inv_is_trace H := auto_is_trace_H H; inversion H; try inj_event_pair_all; try clear_id; try clear H.
Lemma inv_vis_inputS : forall k s (tr: @trace rlE unit), is_trace (Vis InputS k) ([InputS, s] tr) -> is_trace (k s) tr.
Proof. intros. inv_is_trace H. auto. Qed.
Lemma inv_vis_inputA : forall k a (tr: @trace rlE unit), is_trace (Vis InputA k) ([InputA, a] tr) -> is_trace (k a) tr.
Proof. intros. inv_is_trace H. auto. Qed.
Lemma inv_vis_outputS : forall k s s' (tr: @trace rlE unit), is_trace (Vis (OutputS s) k) ([OutputS s', tt] tr) ->
s = s' ->
is_trace (k tt) tr.
Proof. intros. inv_is_trace H. auto. Qed.
Lemma inv_vis_outputS_2 : forall (k: unit -> itree rlE unit) s s' , is_trace (Vis (OutputS s) k) ([<OutputS s'>]) ->
s = s'.
Proof. intros. inv_is_trace H. inversion H2. auto. Qed.
Lemma inv_vis_triggerS : forall k s (tr: @trace rlE unit), is_trace (ITree.bind (ITree.trigger InputS) k) ([InputS, s] tr) <-> is_trace (k s) tr.
Proof.
split; intros.
- repeat setoid_rewrite bind_trigger in H. inv_is_trace H. auto.
- unfold is_trace, observe. cbn. constructor. auto.
Qed.
Lemma inv_vis_triggerA : forall k a (tr: @trace rlE unit), is_trace (ITree.bind (ITree.trigger InputA) k) ([InputA, a] tr) <-> is_trace (k a) tr.
Proof.
split; intros.
- repeat setoid_rewrite bind_trigger in H. inv_is_trace H. auto.
- unfold is_trace, observe. cbn. constructor. auto.
Qed.
Lemma inv_vis_triggerSoutputS : forall k s s' (tr: @trace rlE unit),
is_trace (ITree.trigger (OutputS s);; k tt) ([OutputS s', tt] tr) <-> s = s' /\ is_trace (k tt) tr.
Proof.
split; intros.
- repeat setoid_rewrite bind_trigger in H. inv_is_trace H. split; auto. inversion H2; auto.
- destruct H. unfold is_trace, observe. cbn. rewrite H. constructor. auto.
Qed.
Lemma inv_vis_triggerSoutputSEnd : forall (t : itree rlE unit) s s',
is_trace (ITree.trigger (OutputS s);; t) ([<OutputS s'>]) <-> s = s'.
Proof.
split; intros.
- repeat setoid_rewrite bind_trigger in H. inv_is_trace H. inversion H2; auto.
- destruct H. unfold is_trace, observe. cbn. constructor.
Qed.
Definition env_generator (f: StateT -> ActionT -> StateT) : itree rlE unit :=
(rec-fix env_ _ :=
state <- trigger_inr1 InputS ;; (* read current state *)
action <- trigger_inr1 InputA ;; (* read action from agent *)
trigger_inr1 (OutputS (f state action)) ;; (* write new state *)
env_ tt
) tt.
Definition step_generator (f: StateT -> ActionT -> StateT) : itree rlE unit :=
state <- ITree.trigger InputS ;; (* read current state *)
action <- ITree.trigger InputA ;; (* read action from agent *)
ITree.trigger (OutputS (f state action)) ;; (* write new state *)
Ret tt.
Lemma is_trace_bodyf : forall (s s': StateT) (a: ActionT) bodyf,
is_trace (step_generator bodyf) (ret_rl_trace (s, a, s')) <->
bodyf s a = s'.
Proof.
split; intros.
- unfold step_generator in H. cbn in H.
rewrite inv_vis_triggerS in H.
rewrite inv_vis_triggerA in H.
rewrite inv_vis_triggerSoutputSEnd in H.
auto.
- unfold step_generator. cbn.
rewrite inv_vis_triggerS.
rewrite inv_vis_triggerA.
rewrite inv_vis_triggerSoutputSEnd.
auto.
Qed.
Lemma is_trace_rec_nil : forall (s s': StateT) (a: ActionT) bodyf,
is_trace (env_generator bodyf) (ret_rl_trace (s, a, s')) <->
is_trace (step_generator bodyf) (ret_rl_trace (s, a, s')).
Proof.
split; intros.
- setoid_rewrite rec_as_interp in H.
match goal with
| H: context [recursive ?b] |- _ => remember b as body in H
end.
repeat setoid_rewrite interp_bind in H.
repeat setoid_rewrite interp_trigger in H.
cbn in H.
rewrite inv_vis_triggerS in H.
rewrite inv_vis_triggerA in H.
rewrite inv_vis_triggerSoutputSEnd in H.
rewrite is_trace_bodyf. auto.
- rewrite is_trace_bodyf in H.
unfold env_generator. cbn.
setoid_rewrite rec_as_interp.
match goal with
| H: _ |- context [recursive ?b] => remember b as body in H
end.
repeat setoid_rewrite interp_bind.
repeat setoid_rewrite interp_trigger.
cbn.
rewrite inv_vis_triggerS.
rewrite inv_vis_triggerA.
rewrite inv_vis_triggerSoutputSEnd.
auto.
Qed.
Definition safe_env : itree rlE unit := env_generator safe_env_body.
Lemma safe_inductive_invariant : forall (s s': StateT) (a: ActionT),
safe_env_body s a = s' -> s <= 3 -> s' <= 3.
Proof.
unfold safe_env_body.
intros.
repeat match goal with
| H : context [match s with _ => _ end] |- _ => destruct s
| H : context [match a with _ => _ end] |- _ => destruct a
| _ => subst; auto; lia
end.
Qed.
Lemma is_trace_rl_split: forall s a s' tr bodyf,
is_trace (env_generator bodyf) (bind_rl_trace (s, a, s') tr) ->
(is_trace (env_generator bodyf) tr) /\
is_trace (env_generator bodyf) (ret_rl_trace (s, a, s')).
Proof.
intros. cbn in H. unfold env_generator in H.
setoid_rewrite rec_as_interp in H.
match goal with
| H: context [recursive ?b] |- _ => remember b as body in H
end.
repeat setoid_rewrite interp_bind in H.
repeat setoid_rewrite interp_trigger in H.
cbn in H.
rewrite inv_vis_triggerS in H.
rewrite inv_vis_triggerA in H.
rewrite inv_vis_triggerSoutputS in H.
destruct H. split.
- unfold safe_env. unfold env_generator.
unfold rec_fix.
rewrite <- Heqbody.
auto.
- unfold safe_env.
rewrite is_trace_rec_nil.
rewrite is_trace_bodyf.
auto.
Qed.
(* We can say, if an agent start form position less equal than 3, and the environment satisfies the inductive invariant, the trace of environment will not reach the position 4. *)
Inductive trace_init : (StateT -> Prop) -> @trace rlE unit -> Prop :=
| ret_trace_init :
forall (s s': StateT) (a: ActionT) (phi: StateT -> Prop),
phi s -> trace_init phi (ret_rl_trace (s, a, s'))
| bind_trace_init :
forall (s s': StateT) (a: ActionT) (phi: StateT -> Prop) tr,
phi s -> trace_init phi (bind_rl_trace (s, a, s') tr).
Inductive trace_end : (StateT -> Prop) -> @trace rlE unit -> Prop :=
| ret_trace_end :
forall (s s': StateT) (a: ActionT) (phi: StateT -> Prop),
phi s' -> trace_end phi (ret_rl_trace (s, a, s'))
| bind_trace_end :
forall (s s': StateT) (a: ActionT) (phi: StateT -> Prop) tr,
trace_end phi tr -> trace_end phi (bind_rl_trace (s, a, s') tr).
Lemma inv_trace_init_ret : forall phi s a s',
trace_init phi (ret_rl_trace (s, a, s')) <-> phi s.
Proof.
split; intros.
- inv_is_trace H. auto.
- constructor. auto.
Qed.
Lemma inv_trace_end_ret : forall phi s a s',
trace_end phi (ret_rl_trace (s, a, s')) <-> phi s'.
Proof.
split; intros.
- inv_is_trace H. auto.
- constructor. auto.
Qed.
Lemma inv_trace_init_bind : forall phi s a s' tr,
trace_init phi (bind_rl_trace (s, a, s') tr) <->
phi s.
Proof.
split; intros.
- inv_is_trace H. auto.
- constructor. auto.
Qed.
Lemma inv_trace_end_bind : forall phi s a s' tr,
trace_end phi (bind_rl_trace (s, a, s') tr) <->
trace_end phi tr.
Proof.
split; intros.
- inv_is_trace H. auto.
- constructor. auto.
Qed.
(* The following safe lemma can be proved by the inductive invariant. *)
Lemma safe: forall (tr: @trace rlE unit),
is_rltrace tr ->
trace_init (fun s => s <= 3) tr ->
trace_end (fun s' => s' = 4) tr ->
not (is_trace safe_env tr).
Proof.
unfold not.
intros. cbn in H0. unfold safe_env in H2.
induction H.
- destruct x, p.
rewrite is_trace_rec_nil in H2.
rewrite is_trace_bodyf in H2.
rewrite inv_trace_init_ret in H0.
rewrite inv_trace_end_ret in H1.
apply safe_inductive_invariant in H2; auto.
subst. lia.
- destruct x1, x2, p, p0.
rewrite inv_trace_init_bind in H0.
rewrite inv_trace_end_bind in H1.
rewrite inv_trace_end_ret in H1.
inversion H. clear H.
apply is_trace_rl_split in H2.
destruct H2.
rewrite is_trace_rec_nil in H.
rewrite is_trace_rec_nil in H2.
rewrite is_trace_bodyf in H.
rewrite is_trace_bodyf in H2.
apply safe_inductive_invariant in H2; auto. subst.
apply safe_inductive_invariant in H; auto. lia.
- destruct x1, x2, p, p0.
rewrite inv_trace_init_bind in H0.
rewrite inv_trace_end_bind in H1.
rewrite inv_trace_end_bind in H1.
inversion H. clear H. subst.
apply is_trace_rl_split in H2.
rewrite is_trace_rec_nil in H2.
rewrite is_trace_bodyf in H2.
destruct H2.
apply IHis_rltrace; clear IHis_rltrace; auto.
* rewrite inv_trace_init_bind. apply safe_inductive_invariant in H2; auto.
* rewrite inv_trace_end_bind. auto.
Qed.
|
[STATEMENT]
lemma less_list_code [code]:
"list_less xs [] \<longleftrightarrow> False"
"list_less [] (x # xs) \<longleftrightarrow> True"
"list_less (x # xs) (y # ys) \<longleftrightarrow> x < y \<or> x = y \<and> list_less xs ys"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. list_less xs [] = False &&& list_less [] (x # xs) = True &&& list_less (x # xs) (y # ys) = (x < y \<or> x = y \<and> list_less xs ys)
[PROOF STEP]
by simp_all |
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import data.equiv.encodable.basic
import data.finset.basic
import data.set.pairwise
/-!
# Lattice operations on encodable types
Lemmas about lattice and set operations on encodable types
## Implementation Notes
This is a separate file, to avoid unnecessary imports in basic files.
Previously some of these results were in the `measure_theory` folder.
-/
open set
namespace encodable
variables {α : Type*} {β : Type*} [encodable β]
lemma supr_decode₂ [complete_lattice α] (f : β → α) :
(⨆ (i : ℕ) (b ∈ decode₂ β i), f b) = (⨆ b, f b) :=
by { rw [supr_comm], simp [mem_decode₂] }
lemma Union_decode₂ (f : β → set α) : (⋃ (i : ℕ) (b ∈ decode₂ β i), f b) = (⋃ b, f b) :=
supr_decode₂ f
@[elab_as_eliminator] lemma Union_decode₂_cases
{f : β → set α} {C : set α → Prop}
(H0 : C ∅) (H1 : ∀ b, C (f b)) {n} :
C (⋃ b ∈ decode₂ β n, f b) :=
match decode₂ β n with
| none := by { simp, apply H0 }
| (some b) := by { convert H1 b, simp [ext_iff] }
end
theorem Union_decode₂_disjoint_on {f : β → set α} (hd : pairwise (disjoint on f)) :
pairwise (disjoint on λ i, ⋃ b ∈ decode₂ β i, f b) :=
begin
rintro i j ij x,
suffices : ∀ a, encode a = i → x ∈ f a → ∀ b, encode b = j → x ∉ f b, by simpa [decode₂_eq_some],
rintro a rfl ha b rfl hb,
exact hd a b (mt (congr_arg encode) ij) ⟨ha, hb⟩
end
end encodable
namespace finset
lemma nonempty_encodable {α} (t : finset α) : nonempty $ encodable {i // i ∈ t} :=
begin
classical, induction t using finset.induction with x t hx ih,
{ refine ⟨⟨λ _, 0, λ _, none, λ ⟨x,y⟩, y.rec _⟩⟩ },
{ cases ih with ih, exactI ⟨encodable.of_equiv _ (finset.subtype_insert_equiv_option hx)⟩ }
end
end finset
|
Formal statement is: lemma closed_insert [continuous_intros, simp]: assumes "closed S" shows "closed (insert a S)" Informal statement is: If $S$ is a closed set, then $S \cup \{a\}$ is closed. |
{-# OPTIONS --without-K --safe --no-universe-polymorphism
--no-sized-types --no-guardedness --no-subtyping #-}
module Agda.Builtin.Unit where
record ⊤ : Set where
instance constructor tt
{-# BUILTIN UNIT ⊤ #-}
{-# COMPILE GHC ⊤ = data () (()) #-}
|
[STATEMENT]
lemma pp_dist_inf [simp]:
"--(x \<sqinter> y) = --x \<sqinter> --y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. - - (x \<sqinter> y) = - - x \<sqinter> - - y
[PROOF STEP]
by (metis p_dist_sup p_inf_pp_pp ppp) |
chapter \<open>Code Snippets\<close>
theory Snippets
imports "lib/VTcomp"
begin
section \<open>Find Element in Array (Arrays)\<close>
definition "find_elem (x::int) xs \<equiv> doN {
WHILEIT (\<lambda>i. i\<le>length xs \<and> x\<notin>set (take i xs)) (\<lambda>i. i<length xs \<and> xs!i\<noteq>x) (\<lambda>i. RETURN (i+1)) 0
}"
lemma find_elem_correct: "find_elem x xs \<le> SPEC (\<lambda>i. i\<le>length xs \<and> (i<length xs \<longrightarrow> xs!i = x))"
unfolding find_elem_def
apply refine_vcg
apply (rule wf_measure[of "\<lambda>i. length xs - i"])
apply (auto simp: in_set_conv_nth)
(*sledgehammer*)
using less_Suc_eq by blast
sepref_definition find_elem_impl is "uncurry find_elem" :: "int_assn\<^sup>k *\<^sub>a (array_assn int_assn)\<^sup>k \<rightarrow>\<^sub>a nat_assn"
unfolding find_elem_def short_circuit_conv
by sepref
export_code find_elem_impl in Haskell module_name test
subsection \<open>Combined Correctness Theorem\<close>
lemma find_elem_r1: "(find_elem, \<lambda> x xs. SPEC (\<lambda>i. i\<le>length xs \<and> (i<length xs \<longrightarrow> xs!i = x))) \<in> Id \<rightarrow> Id \<rightarrow> \<langle>Id\<rangle>nres_rel"
using find_elem_correct by (auto intro: nres_relI)
thm find_elem_impl.refine[FCOMP find_elem_r1]
section \<open>Check Prefix (Arrays, Exceptions: Check)\<close>
definition "check_prefix xs ys \<equiv> doE {
CHECK (length xs \<le> length ys) ();
EWHILEIT (\<lambda>i. i\<le>length xs \<and> take i xs = take i ys) (\<lambda>i. i<length xs) (\<lambda>i. doE {
EASSERT (i<length xs \<and> i<length ys);
CHECK (xs!i = ys!i) ();
ERETURN (i+1)
} ) 0;
ERETURN ()
}"
(* ESPEC Exc Normal ! *)
lemma check_prefix_correct: "check_prefix xs ys \<le> ESPEC (\<lambda>_. xs \<noteq> take (length xs) ys) (\<lambda>_. xs = take (length xs) ys)"
unfolding check_prefix_def
apply (refine_vcg EWHILEIT_rule[where R="measure (\<lambda>i. length xs - i)"])
apply auto []
apply auto []
apply auto []
apply auto []
apply auto []
apply auto []
subgoal
by (simp add: take_Suc_conv_app_nth)
apply auto []
apply auto []
subgoal
by (metis nth_take)
subgoal
by force
apply auto []
done
synth_definition check_prefix_bd is [enres_unfolds]: "check_prefix xs ys = \<hole>"
apply (rule CNV_eqD)
unfolding check_prefix_def
apply opt_enres_unfold
apply (rule CNV_I)
done
sepref_definition check_prefix_impl is "uncurry check_prefix_bd"
:: "(array_assn int_assn)\<^sup>k *\<^sub>a (array_assn int_assn)\<^sup>k \<rightarrow>\<^sub>a (unit_assn +\<^sub>a unit_assn)"
unfolding check_prefix_bd_def
by sepref
export_code check_prefix_impl checking SML_imp
subsection \<open>Modularity\<close>
lemmas [refine_vcg] = check_prefix_correct[THEN ESPEC_trans]
thm SPEC_trans (* for plain nres-monad without exceptions *)
(* TODO: I remember to have automated the order_trans transformation, but cannot find it right now. *)
definition "is_prefix' xs ys \<equiv> CATCH (doE {check_prefix xs ys; ERETURN True }) (\<lambda>_. ERETURN False)"
lemma is_prefix'_correct: "is_prefix' xs ys \<le> ESPEC (\<lambda>_. False) (\<lambda>r. r \<longleftrightarrow> xs = take (length xs) ys)"
unfolding is_prefix'_def
apply refine_vcg
by auto
lemmas [sepref_fr_rules] = check_prefix_impl.refine
sepref_register check_prefix_bd :: "'a list \<Rightarrow> 'a list \<Rightarrow> (unit+unit) nres"
(* Optional interface type. Required if interfaces used that do not match Isabelle types, e.g. i_map, i_mtx, \<dots>*)
synth_definition is_prefix_bd' is [enres_unfolds]: "is_prefix' xs ys = \<hole>"
apply (rule CNV_eqD)
unfolding is_prefix'_def
apply opt_enres_unfold
apply (rule CNV_I)
done
sepref_definition is_prefix_impl' is "uncurry is_prefix_bd'"
:: "(array_assn int_assn)\<^sup>k *\<^sub>a (array_assn int_assn)\<^sup>k \<rightarrow>\<^sub>a (unit_assn +\<^sub>a bool_assn)"
unfolding is_prefix_bd'_def
by sepref
export_code is_prefix_impl' checking SML_imp
section \<open>Is Prefix (Arrays, Exceptions: Catch)\<close>
definition "is_prefix xs ys \<equiv> CATCH (doE {
CHECK (length xs \<le> length ys) False;
EWHILEIT (\<lambda>i. i\<le>length xs \<and> take i xs = take i ys) (\<lambda>i. i<length xs) (\<lambda>i. doE {
EASSERT (i<length xs \<and> i<length ys);
CHECK (xs!i = ys!i) False;
ERETURN (i+1)
} ) 0;
THROW True
}) (ERETURN)"
(* ESPEC Exc Normal ! *)
lemma "is_prefix xs ys \<le> ESPEC (\<lambda>_. False) (\<lambda>r. r \<longleftrightarrow> xs = take (length xs) ys)"
unfolding is_prefix_def
apply (refine_vcg EWHILEIT_rule[where R="measure (\<lambda>i. length xs - i)"])
apply auto []
apply auto []
apply auto []
apply auto []
apply auto []
apply auto []
subgoal
by (simp add: take_Suc_conv_app_nth)
apply auto []
apply auto []
subgoal
by (metis nth_take)
subgoal
by force
apply auto []
done
synth_definition is_prefix_bd is [enres_unfolds]: "is_prefix xs ys = \<hole>"
apply (rule CNV_eqD)
unfolding is_prefix_def
apply opt_enres_unfold
apply (rule CNV_I)
done
sepref_definition is_prefix_impl is "uncurry is_prefix_bd"
:: "(array_assn int_assn)\<^sup>k *\<^sub>a (array_assn int_assn)\<^sup>k \<rightarrow>\<^sub>a (unit_assn +\<^sub>a bool_assn)"
unfolding is_prefix_bd_def
by sepref
export_code is_prefix_impl checking SML_imp
section \<open>Copy Array (Arrays, For i=l..u)\<close>
definition "cp_array xs \<equiv> doN {
let ys = op_array_replicate (length xs) 0; \<comment> \<open>Use proper constructors\<close>
ys \<leftarrow> nfoldli [0..<length xs] (\<lambda>_. True) (\<lambda>i ys. doN { \<comment> \<open>Ensure linearity! \<open>ys\<leftarrow>\<dots>\<close>\<close>
ASSERT (i<length xs \<and> i<length ys);
RETURN (ys[i:=xs!i])
}) ys;
RETURN ys
}"
lemma "cp_array xs \<le> SPEC (\<lambda>ys. ys=xs)"
unfolding cp_array_def
supply nfoldli_rule nfoldli_rule[where I="\<lambda>l1 l2 ys. length ys = length xs \<and> (\<forall>i\<in>set l1. ys!i = xs!i)", refine_vcg]
apply refine_vcg
apply auto
subgoal
using upt_eq_lel_conv by blast
subgoal
using upt_eq_lel_conv by blast
subgoal
by (simp add: nth_list_update)
subgoal
by (simp add: nth_equalityI)
done
term arl_assn
subsection \<open>Proof with \<open>nfoldli_upt_rule\<close>\<close>
lemma "cp_array xs \<le> SPEC (\<lambda>ys. ys=xs)"
unfolding cp_array_def
supply nfoldli_upt_rule nfoldli_upt_rule[where I="\<lambda>i ys. length ys = length xs \<and> (\<forall>j<i. ys!j = xs!j)", refine_vcg]
apply refine_vcg
apply auto
subgoal
using less_Suc_eq by auto
subgoal
by (simp add: nth_equalityI)
done
sepref_definition cp_array_impl is cp_array :: "(array_assn nat_assn)\<^sup>k \<rightarrow>\<^sub>a array_assn nat_assn"
unfolding cp_array_def
by sepref
end
|
module Depling.Elevate
import Depling
import Utils
import Data.Fin
import Data.Vect
total
export
elevate : {auto gte : GTE m n} -> DAST n -> DAST m
elevate (ʌ v) = ʌ $ finE v
elevate {gte} (λ at b) = λ (elevate at) (elevate {gte=LTESucc gte} b)
elevate {gte} (λT at rt) = λT (elevate at) (elevate {gte=LTESucc gte} rt)
elevate (f =!= a) = elevate f =!= elevate a
elevate 𝕋 = 𝕋
elevate {gte} (𝔽 at rt b) = 𝔽 (elevate at) (elevate rt) (elevate {gte=LTESucc$ LTESucc$ gte} b)
elevate (𝕌 n t) = 𝕌 n (elevate t)
elevate (ℂ cn as) = assert_total $ ℂ cn (map elevate as)
elevate {n} {m} {gte} (ℙ v cn t f) = ℙ (elevate v) cn (elevate {gte = ltePlus gte} t) (elevate f)
elevate (𝔹 t) = 𝔹 (elevate t)
total
export
elevateRC : {auto gte : GTE m n} -> DRCtx a n -> DRCtx a m
elevateRC [] = []
elevateRC {gte} (h :: t) = elevate h :: elevateRC {gte = LTESucc gte} t
|
% --------------------------- %
% BalancerText Start
% --------------------------- %
\section{\textbf{Balancer Test}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Particular Case}
\par
The problem we are dealing with in this experiment is that of creating a
balancer class.
\par
As stated in the text book, a \textit{Balancer} is a simple switch with two
input wires and two output wires (top and bottom wires). The token arrives to
the input lines and the balancer must output the input one at a time.
\par
A balancer has two states: \textit{up} and \textit{down}. If the state is
\textit{up}, the next token exits on the top of the wire. Otherwise, it exits
on the bottom wire.
\par
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Solution}
\par
The following is a simple implementation of a Balancer
class. As described above, the balancer consists of a
toggle.
\par
\hfill
\begin{lstlisting}[style=numbers]
public synchronized int traverse(int input) {
try {
if (toggle) {
return 0;
} else {
return 1;
}
} finally {
toggle = !toggle;
}
}
\end{lstlisting}
\hfill
\par
As we can observe, the traverse method simply switches the state of the toggle
and outputs either $0$ or $1$.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Experiment Description}
\par
The balancer class described above is used in one test case. The test case
consists of a 2-slot array. Each slot keeps track of how many times the
balancer has output a signal on the \textit{up} wire and how many on the
\textit{down} wire.
\par
So, the test activates the balancer exactly $256$ times. The final result must be that each slot has the number $128$. If that is the case, we declare the test as passed, otherwise it failed.
\par
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Sample Results and Interpretation}
\par
Here is the result of the execution. It passed every time:
\par
\hfill
\begin{verbatim}
[oraadm@gdlaa008 Counting]$ junit counting.BalancerTest
.
Time: 0.002
OK (1 test)
\end{verbatim}
\hfill
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --------------------------- %
% BalancerText End
% --------------------------- %
|
(* Title: HOL/Library/Code_Real_Approx_By_Float.thy
Author: Florian Haftmann
Author: Johannes Hölzl
Author: Tobias Nipkow
*)
theory Code_Real_Approx_By_Float
imports Complex_MainRLT Code_Target_Int
begin
text\<open>
\<^bold>\<open>WARNING!\<close> This theory implements mathematical reals by machine reals
(floats). This is inconsistent. See the proof of False at the end of the
theory, where an equality on mathematical reals is (incorrectly) disproved
by mapping it to machine reals.
The \<^theory_text>\<open>value\<close> command cannot display real results yet.
The only legitimate use of this theory is as a tool for code generation
purposes.
\<close>
code_printing
type_constructor real \<rightharpoonup>
(SML) "real"
and (OCaml) "float"
code_printing
constant Ratreal \<rightharpoonup>
(SML) "error/ \"Bad constant: Ratreal\""
code_printing
constant "0 :: real" \<rightharpoonup>
(SML) "0.0"
and (OCaml) "0.0"
code_printing
constant "1 :: real" \<rightharpoonup>
(SML) "1.0"
and (OCaml) "1.0"
code_printing
constant "HOL.equal :: real \<Rightarrow> real \<Rightarrow> bool" \<rightharpoonup>
(SML) "Real.== ((_), (_))"
and (OCaml) "Pervasives.(=)"
code_printing
constant "Orderings.less_eq :: real \<Rightarrow> real \<Rightarrow> bool" \<rightharpoonup>
(SML) "Real.<= ((_), (_))"
and (OCaml) "Pervasives.(<=)"
code_printing
constant "Orderings.less :: real \<Rightarrow> real \<Rightarrow> bool" \<rightharpoonup>
(SML) "Real.< ((_), (_))"
and (OCaml) "Pervasives.(<)"
code_printing
constant "(+) :: real \<Rightarrow> real \<Rightarrow> real" \<rightharpoonup>
(SML) "Real.+ ((_), (_))"
and (OCaml) "Pervasives.( +. )"
code_printing
constant "(*) :: real \<Rightarrow> real \<Rightarrow> real" \<rightharpoonup>
(SML) "Real.* ((_), (_))"
and (OCaml) "Pervasives.( *. )"
code_printing
constant "(-) :: real \<Rightarrow> real \<Rightarrow> real" \<rightharpoonup>
(SML) "Real.- ((_), (_))"
and (OCaml) "Pervasives.( -. )"
code_printing
constant "uminus :: real \<Rightarrow> real" \<rightharpoonup>
(SML) "Real.~"
and (OCaml) "Pervasives.( ~-. )"
code_printing
constant "(/) :: real \<Rightarrow> real \<Rightarrow> real" \<rightharpoonup>
(SML) "Real.'/ ((_), (_))"
and (OCaml) "Pervasives.( '/. )"
code_printing
constant "HOL.equal :: real \<Rightarrow> real \<Rightarrow> bool" \<rightharpoonup>
(SML) "Real.== ((_:real), (_))"
code_printing
constant "sqrt :: real \<Rightarrow> real" \<rightharpoonup>
(SML) "Math.sqrt"
and (OCaml) "Pervasives.sqrt"
declare sqrt_def[code del]
context
begin
qualified definition real_exp :: "real \<Rightarrow> real"
where "real_exp = exp"
lemma exp_eq_real_exp [code_unfold]: "exp = real_exp"
unfolding real_exp_def ..
end
code_printing
constant Code_Real_Approx_By_Float.real_exp \<rightharpoonup>
(SML) "Math.exp"
and (OCaml) "Pervasives.exp"
declare Code_Real_Approx_By_Float.real_exp_def[code del]
declare exp_def[code del]
code_printing
constant ln \<rightharpoonup>
(SML) "Math.ln"
and (OCaml) "Pervasives.ln"
declare ln_real_def[code del]
code_printing
constant cos \<rightharpoonup>
(SML) "Math.cos"
and (OCaml) "Pervasives.cos"
declare cos_def[code del]
code_printing
constant sin \<rightharpoonup>
(SML) "Math.sin"
and (OCaml) "Pervasives.sin"
declare sin_def[code del]
code_printing
constant pi \<rightharpoonup>
(SML) "Math.pi"
and (OCaml) "Pervasives.pi"
declare pi_def[code del]
code_printing
constant arctan \<rightharpoonup>
(SML) "Math.atan"
and (OCaml) "Pervasives.atan"
declare arctan_def[code del]
code_printing
constant arccos \<rightharpoonup>
(SML) "Math.scos"
and (OCaml) "Pervasives.acos"
declare arccos_def[code del]
code_printing
constant arcsin \<rightharpoonup>
(SML) "Math.asin"
and (OCaml) "Pervasives.asin"
declare arcsin_def[code del]
definition real_of_integer :: "integer \<Rightarrow> real"
where "real_of_integer = of_int \<circ> int_of_integer"
code_printing
constant real_of_integer \<rightharpoonup>
(SML) "Real.fromInt"
and (OCaml) "Pervasives.float/ (Big'_int.to'_int (_))"
context
begin
qualified definition real_of_int :: "int \<Rightarrow> real"
where [code_abbrev]: "real_of_int = of_int"
lemma [code_unfold del]: "0 \<equiv> (of_rat 0 :: real)"
by simp
lemma [code_unfold del]: "1 \<equiv> (of_rat 1 :: real)"
by simp
lemma [code_unfold del]: "numeral k \<equiv> (of_rat (numeral k) :: real)"
by simp
lemma [code_unfold del]: "- numeral k \<equiv> (of_rat (- numeral k) :: real)"
by simp
end
code_printing
constant Ratreal \<rightharpoonup> (SML)
definition Realfract :: "int \<Rightarrow> int \<Rightarrow> real"
where "Realfract p q = of_int p / of_int q"
code_datatype Realfract
code_printing
constant Realfract \<rightharpoonup> (SML) "Real.fromInt _/ '// Real.fromInt _"
lemma [code]: "Ratreal r = case_prod Realfract (quotient_of r)"
by (cases r) (simp add: Realfract_def quotient_of_Fract of_rat_rat)
declare [[code drop: "HOL.equal :: real \<Rightarrow> real \<Rightarrow> bool"
"plus :: real \<Rightarrow> real \<Rightarrow> real"
"uminus :: real \<Rightarrow> real"
"minus :: real \<Rightarrow> real \<Rightarrow> real"
"times :: real \<Rightarrow> real \<Rightarrow> real"
"divide :: real \<Rightarrow> real \<Rightarrow> real"
"(<) :: real \<Rightarrow> real \<Rightarrow> bool"
"(\<le>) :: real \<Rightarrow> real \<Rightarrow> bool"]]
lemma [code]: "inverse r = 1 / r" for r :: real
by (fact inverse_eq_divide)
notepad
begin
have "cos (pi/2) = 0" by (rule cos_pi_half)
moreover have "cos (pi/2) \<noteq> 0" by eval
ultimately have False by blast
end
end
|
[STATEMENT]
lemma R2_imp_P2 [simp, elim]: "f \<in> \<R>\<^sup>2 \<Longrightarrow> f \<in> \<P>\<^sup>2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. f \<in> \<R>\<^sup>2 \<Longrightarrow> f \<in> \<P>\<^sup>2
[PROOF STEP]
using R2_def P2_def
[PROOF STATE]
proof (prove)
using this:
\<R>\<^sup>2 \<equiv> {\<lambda>x y. eval r [x, y] |r. recfn 2 r \<and> Partial_Recursive.total r}
\<P>\<^sup>2 \<equiv> {\<lambda>x y. eval r [x, y] |r. recfn 2 r}
goal (1 subgoal):
1. f \<in> \<R>\<^sup>2 \<Longrightarrow> f \<in> \<P>\<^sup>2
[PROOF STEP]
by auto |
import data.nat.basic
namespace nat
lemma max_succ_succ {m n} :
max (succ m) (succ n) = succ (max m n) :=
begin
by_cases h1 : m ≤ n,
rw [max_eq_right h1, max_eq_right (succ_le_succ h1)],
{ rw not_le at h1, have h2 := le_of_lt h1,
rw [max_eq_left h2, max_eq_left (succ_le_succ h2)] }
end
end nat |
[STATEMENT]
lemma R9 [simp]: "pmf (sds R9) b = 0" "pmf (sds R9) d = 0" "pmf (sds R14) a = pmf (sds R35) a" "pmf (sds R9) c = 1 - pmf (sds R35) a"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (pmf (sds R9) b = 0 &&& pmf (sds R9) d = 0) &&& pmf (sds R14) a = pmf (sds R35) a &&& pmf (sds R9) c = 1 - pmf (sds R35) a
[PROOF STEP]
using R12_R14 R14_R9.strategyproofness(1) lottery_conditions[OF R9.wf] R9.support
[PROOF STATE]
proof (prove)
using this:
pmf (sds R14) a \<le> pmf (sds R12) a
(pmf (sds R9) a < pmf (sds R14) a \<or> pmf (sds R9) a + pmf (sds R9) d < pmf (sds R14) a + pmf (sds R14) d \<or> pmf (sds R9) a + (pmf (sds R9) d + pmf (sds R9) c) < pmf (sds R14) a + (pmf (sds R14) d + pmf (sds R14) c)) \<or> pmf (sds R9) a = pmf (sds R14) a \<and> pmf (sds R9) a + pmf (sds R9) d = pmf (sds R14) a + pmf (sds R14) d \<and> pmf (sds R9) a + (pmf (sds R9) d + pmf (sds R9) c) = pmf (sds R14) a + (pmf (sds R14) d + pmf (sds R14) c)
0 \<le> pmf (sds R9) a
0 \<le> pmf (sds R9) b
0 \<le> pmf (sds R9) c
0 \<le> pmf (sds R9) d
pmf (sds R9) a + pmf (sds R9) b + pmf (sds R9) c + pmf (sds R9) d = 1
pmf (sds R9) b = 0
goal (1 subgoal):
1. (pmf (sds R9) b = 0 &&& pmf (sds R9) d = 0) &&& pmf (sds R14) a = pmf (sds R35) a &&& pmf (sds R9) c = 1 - pmf (sds R35) a
[PROOF STEP]
by auto |
= = Responses = =
|
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import data.equiv.encodable.basic
import data.finset.basic
import data.set.pairwise
/-!
# Lattice operations on encodable types
Lemmas about lattice and set operations on encodable types
## Implementation Notes
This is a separate file, to avoid unnecessary imports in basic files.
Previously some of these results were in the `measure_theory` folder.
-/
open set
namespace encodable
variables {α : Type*} {β : Type*} [encodable β]
lemma supr_decode₂ [complete_lattice α] (f : β → α) :
(⨆ (i : ℕ) (b ∈ decode₂ β i), f b) = (⨆ b, f b) :=
by { rw [supr_comm], simp [mem_decode₂] }
lemma Union_decode₂ (f : β → set α) : (⋃ (i : ℕ) (b ∈ decode₂ β i), f b) = (⋃ b, f b) :=
supr_decode₂ f
@[elab_as_eliminator] lemma Union_decode₂_cases
{f : β → set α} {C : set α → Prop}
(H0 : C ∅) (H1 : ∀ b, C (f b)) {n} :
C (⋃ b ∈ decode₂ β n, f b) :=
match decode₂ β n with
| none := by { simp, apply H0 }
| (some b) := by { convert H1 b, simp [ext_iff] }
end
theorem Union_decode₂_disjoint_on {f : β → set α} (hd : pairwise (disjoint on f)) :
pairwise (disjoint on λ i, ⋃ b ∈ decode₂ β i, f b) :=
begin
rintro i j ij x ⟨h₁, h₂⟩,
revert h₁ h₂,
simp, intros b₁ e₁ h₁ b₂ e₂ h₂,
refine hd _ _ _ ⟨h₁, h₂⟩,
cases encodable.mem_decode₂.1 e₁,
cases encodable.mem_decode₂.1 e₂,
exact mt (congr_arg _) ij
end
end encodable
namespace finset
lemma nonempty_encodable {α} (t : finset α) : nonempty $ encodable {i // i ∈ t} :=
begin
classical, induction t using finset.induction with x t hx ih,
{ refine ⟨⟨λ _, 0, λ _, none, λ ⟨x,y⟩, y.rec _⟩⟩ },
{ cases ih with ih, exactI ⟨encodable.of_equiv _ (finset.subtype_insert_equiv_option hx)⟩ }
end
end finset
|
/-
Copyright (c) 2019 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Yaël Dillies
-/
import analysis.convex.basic
import data.complex.module
/-!
# Convexity of half spaces in ℂ
The open and closed half-spaces in ℂ given by an inequality on either the real or imaginary part
are all convex over ℝ.
-/
lemma convex_halfspace_re_lt (r : ℝ) : convex ℝ {c : ℂ | c.re < r} :=
convex_halfspace_lt (is_linear_map.mk complex.add_re complex.smul_re) _
lemma convex_halfspace_re_le (r : ℝ) : convex ℝ {c : ℂ | c.re ≤ r} :=
convex_halfspace_le (is_linear_map.mk complex.add_re complex.smul_re) _
lemma convex_halfspace_re_gt (r : ℝ) : convex ℝ {c : ℂ | r < c.re } :=
convex_halfspace_gt (is_linear_map.mk complex.add_re complex.smul_re) _
lemma convex_halfspace_re_ge (r : ℝ) : convex ℝ {c : ℂ | r ≤ c.re} :=
convex_halfspace_ge (is_linear_map.mk complex.add_re complex.smul_re) _
lemma convex_halfspace_im_lt (r : ℝ) : convex ℝ {c : ℂ | c.im < r} :=
convex_halfspace_lt (is_linear_map.mk complex.add_im complex.smul_im) _
lemma convex_halfspace_im_le (r : ℝ) : convex ℝ {c : ℂ | c.im ≤ r} :=
convex_halfspace_le (is_linear_map.mk complex.add_im complex.smul_im) _
lemma convex_halfspace_im_gt (r : ℝ) : convex ℝ {c : ℂ | r < c.im} :=
convex_halfspace_gt (is_linear_map.mk complex.add_im complex.smul_im) _
lemma convex_halfspace_im_ge (r : ℝ) : convex ℝ {c : ℂ | r ≤ c.im} :=
convex_halfspace_ge (is_linear_map.mk complex.add_im complex.smul_im) _
|
From Coq Require Export
ssreflect
ssrfun
ssrbool.
Lemma and_swap : forall x y z, [&& x, y & z] = [&& y, x & z].
Proof. by case; case; case. Qed.
Definition decide {T : Type} (H : bool)
(kt : (H = true) -> T)
(kf : (H = false) -> T) : T :=
(fun (if_true : (fun b : bool => protect_term (H = b) -> T) true)
(if_false : (fun b : bool => protect_term (H = b) -> T) false) =>
if H as b return ((fun b0 : bool => protect_term (H = b0) -> T) b)
then if_true
else if_false)
(fun (E : H = true) => kt E)
(fun (E : H = false) => kf E)
(erefl H).
Arguments decide {T} H kt kf.
Definition prop (b : bool) : option (is_true b) :=
if b then Some is_true_true else None.
|
C CODE FROM THE PAPER "ARRAY PRIVATIZATION FOR PARALLEL
C EXECUTION OF LOOPS" FROM Z. LI, ICS'92.
SUBROUTINE LI921(A,N)
INTEGER N, A(N), M
A(1) = 0
DO I = 1,N
DO J = 1,N
DO K = 2,N
A(K) = 0
M = A(K-1)
ENDDO
ENDDO
ENDDO
PRINT *, I, J, K, M
END
|
test : Not (Nat = String)
test eq impossible
test2 : Not (Char = String)
test2 eq impossible
test3 : Not (Type = String)
test3 eq impossible
test4 : Not (Type = Nat)
test4 eq impossible
test5 : Not (List Nat = Type)
test5 eq impossible
test6 : Not (Bits64 = Type)
test6 eq impossible
test7 : Not ('a' = 'b')
test7 eq impossible
-- The following ones are actually possible
test8 : Not (a = Type)
test8 eq impossible
test9 : Not (a = 'a')
test9 eq impossible
test10 : Not (a = Nat)
test10 eq impossible
test11 : Not (3 = a)
test11 eq impossible
|
[STATEMENT]
lemma conj_distrib1: "c \<iinter> (d\<^sub>0 \<iinter> d\<^sub>1) = (c \<iinter> d\<^sub>0) \<iinter> (c \<iinter> d\<^sub>1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. c \<iinter> (d\<^sub>0 \<iinter> d\<^sub>1) = c \<iinter> d\<^sub>0 \<iinter> (c \<iinter> d\<^sub>1)
variables:
c, d\<^sub>0, d\<^sub>1 :: 'a
(\<iinter>) :: 'a \<Rightarrow> 'a \<Rightarrow> 'a
type variables:
'a :: refinement_lattice
[PROOF STEP]
by (metis conj_assoc conj_commute conj_idem) |
[STATEMENT]
lemma cqt_basic_6[PLM]:
"[(\<^bold>\<forall>\<alpha>. (\<^bold>\<forall>\<alpha>. \<phi> \<alpha>)) \<^bold>\<equiv> (\<^bold>\<forall>\<alpha>. \<phi> \<alpha>) in v]"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. [(\<^bold>\<forall>\<alpha> \<alpha>'. \<phi> \<alpha>') \<^bold>\<equiv> (\<^bold>\<forall>\<alpha>. \<phi> \<alpha>) in v]
[PROOF STEP]
by PLM_solver |
\documentclass[12pt]{article}
\input{physics1}
\begin{document}
\noindent
Name: \rule[-1ex]{0.55\textwidth}{0.1pt}
NetID: \rule[-1ex]{0.2\textwidth}{0.1pt}
\section*{NYU Physics I---Term Exam 3}
\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from lecture 2018-10-16)
Remember this free-body diagram for the light table? We obtained an expression
for the net torque on the table when we put the reference point at the location
at which the force $N_B$ acts.
What would we have obtained for the net torque if we had put the reference point
at the location at which the force $N_A$ acts?
Keep the same sign convention (counter-clockwise is positive torque).\\
\includegraphics[width=3in]{../jpg/light_table.jpg}
\vfill
\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from lecture 2018-10-18)
Without using a calculator, estimate the sine of the angle $1.2~\deg$.
Use the small-angle approximation! (\emph{Hint:} Degrees aren't radians.)
\vfill
\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from bouncing worksheet)
An elastic ball of mass $m$ heads at speed $v$ towards a huge wall.
Its initial velocity is at an angle of $\theta$ to the normal.
Imagine that the collision is perfectly elastic and the
wall is perfectly frictionless, so the ``angle of incidence equals the
angle of reflection''. What is the magnitude of the momentum change of the ball (final
minus initial)?
Give your answer in terms of the symbols in the diagram.
\marginpar{\includegraphics[width=1in]{../jpg/ballwall.jpg}}
\vfill
~
\clearpage
\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from oscillations worksheet)
The $x$-axis position $x$ of a particle as a function of time is
$$
x(t) = A\,\cos(\omega t) \quad .
$$
What is the maximum $x$-direction velocity $v_{\mathrm{max}}$ that the
particle obtains in this motion, and what is the period $T$ of the
velocity oscillation? Give your answers in terms of $A$ and $\omega$.
\vfill
\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from Problem Set 5)
A student of mass $m_\mathrm{student}=80\,\kg$ stands at rest next to
a block of ice of mass $m_\mathrm{ice}=320\,\kg$, also at rest, on a
frictionless frozen lake. The student pushes on the block. After the
push is completed, the block is moving in the positive $x$ direction at $1\,\mps$
relative to the frozen lake.
What is the student's velocity (relative to the lake) after the push?
\vfill
\paragraph{\problemname~\theproblem:}\refstepcounter{problem}%
(from Problem Set 6)
If a block of mass $M$ is dragged a distance $h$ across a horizontal floor,
how much heat $Q$ is generated? Assume that the acceleration due to
gravity is $g$, that the friction is kinetic with
coefficient $\mu$, and that the force pulling the block is purely
horizontal.
\vfill
~
\end{document}
|
State Before: α : Type u_1
β : Type ?u.1901
γ : Type ?u.1904
x y z w : α
⊢ Rel α (x, y) (z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z State After: no goals Tactic: aesop (rule_sets [Sym2]) |
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
m : (s : Set α) → MeasurableSet s → ℝ≥0∞
m0 : m ∅ (_ : MeasurableSet ∅) = 0
mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
m (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) = ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i))
src✝ : OuterMeasure α := inducedOuterMeasure m (_ : MeasurableSet ∅) m0
f : ℕ → Set α
hf : ∀ (i : ℕ), MeasurableSet (f i)
hd : Pairwise (Disjoint on f)
⊢ ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) (iUnion f) =
∑' (i : ℕ), ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) (f i)
[PROOFSTEP]
rw [inducedOuterMeasure_eq m0 mU, mU hf hd]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
m : (s : Set α) → MeasurableSet s → ℝ≥0∞
m0 : m ∅ (_ : MeasurableSet ∅) = 0
mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
m (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) = ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i))
src✝ : OuterMeasure α := inducedOuterMeasure m (_ : MeasurableSet ∅) m0
f : ℕ → Set α
hf : ∀ (i : ℕ), MeasurableSet (f i)
hd : Pairwise (Disjoint on f)
⊢ ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i)) = ∑' (i : ℕ), ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) (f i)
[PROOFSTEP]
congr
[GOAL]
case e_f
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
m : (s : Set α) → MeasurableSet s → ℝ≥0∞
m0 : m ∅ (_ : MeasurableSet ∅) = 0
mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
m (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) = ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i))
src✝ : OuterMeasure α := inducedOuterMeasure m (_ : MeasurableSet ∅) m0
f : ℕ → Set α
hf : ∀ (i : ℕ), MeasurableSet (f i)
hd : Pairwise (Disjoint on f)
⊢ (fun i => m (f i) (_ : MeasurableSet (f i))) = fun i => ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) (f i)
[PROOFSTEP]
funext n
[GOAL]
case e_f.h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
m : (s : Set α) → MeasurableSet s → ℝ≥0∞
m0 : m ∅ (_ : MeasurableSet ∅) = 0
mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
m (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) = ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i))
src✝ : OuterMeasure α := inducedOuterMeasure m (_ : MeasurableSet ∅) m0
f : ℕ → Set α
hf : ∀ (i : ℕ), MeasurableSet (f i)
hd : Pairwise (Disjoint on f)
n : ℕ
⊢ m (f n) (_ : MeasurableSet (f n)) = ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) (f n)
[PROOFSTEP]
rw [inducedOuterMeasure_eq m0 mU]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
m : (s : Set α) → MeasurableSet s → ℝ≥0∞
m0 : m ∅ (_ : MeasurableSet ∅) = 0
mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
m (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) = ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i))
src✝ : OuterMeasure α := inducedOuterMeasure m (_ : MeasurableSet ∅) m0
⊢ OuterMeasure.trim (inducedOuterMeasure m (_ : MeasurableSet ∅) m0) = inducedOuterMeasure m (_ : MeasurableSet ∅) m0
[PROOFSTEP]
unfold OuterMeasure.trim
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
m : (s : Set α) → MeasurableSet s → ℝ≥0∞
m0 : m ∅ (_ : MeasurableSet ∅) = 0
mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
m (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) = ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i))
src✝ : OuterMeasure α := inducedOuterMeasure m (_ : MeasurableSet ∅) m0
⊢ inducedOuterMeasure (fun s x => ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) s) (_ : MeasurableSet ∅)
(_ : ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) ∅ = 0) =
inducedOuterMeasure m (_ : MeasurableSet ∅) m0
[PROOFSTEP]
congr
[GOAL]
case e_m
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
m : (s : Set α) → MeasurableSet s → ℝ≥0∞
m0 : m ∅ (_ : MeasurableSet ∅) = 0
mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
m (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) = ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i))
src✝ : OuterMeasure α := inducedOuterMeasure m (_ : MeasurableSet ∅) m0
⊢ (fun s x => ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) s) = m
[PROOFSTEP]
funext s hs
[GOAL]
case e_m.h.h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
m : (s : Set α) → MeasurableSet s → ℝ≥0∞
m0 : m ∅ (_ : MeasurableSet ∅) = 0
mU :
∀ ⦃f : ℕ → Set α⦄ (h : ∀ (i : ℕ), MeasurableSet (f i)),
Pairwise (Disjoint on f) →
m (⋃ (i : ℕ), f i) (_ : MeasurableSet (⋃ (b : ℕ), f b)) = ∑' (i : ℕ), m (f i) (_ : MeasurableSet (f i))
src✝ : OuterMeasure α := inducedOuterMeasure m (_ : MeasurableSet ∅) m0
s : Set α
hs : MeasurableSet s
⊢ ↑(inducedOuterMeasure m (_ : MeasurableSet ∅) m0) s = m s hs
[PROOFSTEP]
exact inducedOuterMeasure_eq m0 mU hs
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
x✝¹ x✝ : Measure α
m₁ : OuterMeasure α
u₁ :
∀ ⦃f : ℕ → Set α⦄,
(∀ (i : ℕ), MeasurableSet (f i)) → Pairwise (Disjoint on f) → ↑m₁ (⋃ (i : ℕ), f i) = ∑' (i : ℕ), ↑m₁ (f i)
h₁ : OuterMeasure.trim m₁ = m₁
m₂ : OuterMeasure α
_u₂ :
∀ ⦃f : ℕ → Set α⦄,
(∀ (i : ℕ), MeasurableSet (f i)) → Pairwise (Disjoint on f) → ↑m₂ (⋃ (i : ℕ), f i) = ∑' (i : ℕ), ↑m₂ (f i)
_h₂ : OuterMeasure.trim m₂ = m₂
_h :
↑{ toOuterMeasure := m₁, m_iUnion := u₁, trimmed := h₁ } = ↑{ toOuterMeasure := m₂, m_iUnion := _u₂, trimmed := _h₂ }
⊢ { toOuterMeasure := m₁, m_iUnion := u₁, trimmed := h₁ } = { toOuterMeasure := m₂, m_iUnion := _u₂, trimmed := _h₂ }
[PROOFSTEP]
congr
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : ∀ (s : Set α), MeasurableSet s → ↑↑μ₁ s = ↑↑μ₂ s
⊢ ↑μ₁ = ↑μ₂
[PROOFSTEP]
rw [← trimmed, OuterMeasure.trim_congr (h _), trimmed]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ μ₁ = μ₂ → ∀ (s : Set α), MeasurableSet s → ↑↑μ₁ s = ↑↑μ₂ s
[PROOFSTEP]
rintro rfl s _hs
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ : Measure α
s✝ s₁ s₂ t s : Set α
_hs : MeasurableSet s
⊢ ↑↑μ₁ s = ↑↑μ₁ s
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t s : Set α
⊢ ↑↑μ s = ↑(OuterMeasure.trim ↑μ) s
[PROOFSTEP]
rw [μ.trimmed]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t s : Set α
⊢ ↑↑μ s = ⨅ (t : Set α) (_ : s ⊆ t) (_ : MeasurableSet t), ↑↑μ t
[PROOFSTEP]
rw [measure_eq_trim, OuterMeasure.trim_eq_iInf]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
⊢ ↑↑μ s = ⨅ (t : { t // s ⊆ t ∧ MeasurableSet t }), ↑↑μ ↑t
[PROOFSTEP]
simp_rw [iInf_subtype, iInf_and, ← measure_eq_iInf]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
hs : MeasurableSet s
⊢ ↑↑μ s = extend (fun t _ht => ↑↑μ t) s
[PROOFSTEP]
rw [extend_eq]
[GOAL]
case h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
hs : MeasurableSet s
⊢ MeasurableSet s
[PROOFSTEP]
exact hs
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
⊢ ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ↑↑μ t = ↑↑μ s
[PROOFSTEP]
simpa only [← measure_eq_trim] using μ.toOuterMeasure.exists_measurable_superset_eq_trim s
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι✝ : Type u_5
inst✝¹ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
ι : Sort u_6
inst✝ : Countable ι
μ : ι → Measure α
s : Set α
⊢ ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ∀ (i : ι), ↑↑(μ i) t = ↑↑(μ i) s
[PROOFSTEP]
simpa only [← measure_eq_trim] using
OuterMeasure.exists_measurable_superset_forall_eq_trim (fun i => (μ i).toOuterMeasure) s
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ ν : Measure α
s : Set α
⊢ ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ↑↑μ t = ↑↑μ s ∧ ↑↑ν t = ↑↑ν s
[PROOFSTEP]
simpa only [Bool.forall_bool.trans and_comm] using exists_measurable_superset_forall_eq (fun b => cond b μ ν) s
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Set β
hs : Set.Countable s
f : β → Set α
⊢ ↑↑μ (⋃ (b : β) (_ : b ∈ s), f b) ≤ ∑' (p : ↑s), ↑↑μ (f ↑p)
[PROOFSTEP]
haveI := hs.to_subtype
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Set β
hs : Set.Countable s
f : β → Set α
this : Countable ↑s
⊢ ↑↑μ (⋃ (b : β) (_ : b ∈ s), f b) ≤ ∑' (p : ↑s), ↑↑μ (f ↑p)
[PROOFSTEP]
rw [biUnion_eq_iUnion]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Set β
hs : Set.Countable s
f : β → Set α
this : Countable ↑s
⊢ ↑↑μ (⋃ (x : ↑s), f ↑x) ≤ ∑' (p : ↑s), ↑↑μ (f ↑p)
[PROOFSTEP]
apply measure_iUnion_le
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Finset β
f : β → Set α
⊢ ↑↑μ (⋃ (b : β) (_ : b ∈ s), f b) ≤ ∑ p in s, ↑↑μ (f p)
[PROOFSTEP]
rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Finset β
f : β → Set α
⊢ ↑↑μ (⋃ (b : β) (_ : b ∈ s), f b) ≤ ∑' (b : { x // x ∈ s }), ↑↑μ (f ↑b)
[PROOFSTEP]
exact measure_biUnion_le s.countable_toSet f
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝¹ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
inst✝ : Fintype β
f : β → Set α
⊢ ↑↑μ (⋃ (b : β), f b) ≤ ∑ p : β, ↑↑μ (f p)
[PROOFSTEP]
convert measure_biUnion_finset_le Finset.univ f
[GOAL]
case h.e'_3.h.e'_3.h.e'_3.h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝¹ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
inst✝ : Fintype β
f : β → Set α
x✝ : β
⊢ f x✝ = ⋃ (_ : x✝ ∈ Finset.univ), f x✝
[PROOFSTEP]
simp
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Set β
f : β → Set α
hs : Set.Finite s
hfin : ∀ (i : β), i ∈ s → ↑↑μ (f i) ≠ ⊤
⊢ ↑↑μ (⋃ (i : β) (_ : i ∈ s), f i) < ⊤
[PROOFSTEP]
convert (measure_biUnion_finset_le hs.toFinset f).trans_lt _ using 3
[GOAL]
case h.e'_3.h.e'_3.h.e'_3
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Set β
f : β → Set α
hs : Set.Finite s
hfin : ∀ (i : β), i ∈ s → ↑↑μ (f i) ≠ ⊤
⊢ (fun i => ⋃ (_ : i ∈ s), f i) = fun b => ⋃ (_ : b ∈ Finite.toFinset hs), f b
[PROOFSTEP]
ext
[GOAL]
case h.e'_3.h.e'_3.h.e'_3.h.h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Set β
f : β → Set α
hs : Set.Finite s
hfin : ∀ (i : β), i ∈ s → ↑↑μ (f i) ≠ ⊤
x✝¹ : β
x✝ : α
⊢ x✝ ∈ ⋃ (_ : x✝¹ ∈ s), f x✝¹ ↔ x✝ ∈ ⋃ (_ : x✝¹ ∈ Finite.toFinset hs), f x✝¹
[PROOFSTEP]
rw [Finite.mem_toFinset]
[GOAL]
case convert_3
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Set β
f : β → Set α
hs : Set.Finite s
hfin : ∀ (i : β), i ∈ s → ↑↑μ (f i) ≠ ⊤
⊢ ∑ p in Finite.toFinset hs, ↑↑μ (f p) < ⊤
[PROOFSTEP]
apply ENNReal.sum_lt_top
[GOAL]
case convert_3.h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
s : Set β
f : β → Set α
hs : Set.Finite s
hfin : ∀ (i : β), i ∈ s → ↑↑μ (f i) ≠ ⊤
⊢ ∀ (a : β), a ∈ Finite.toFinset hs → ↑↑μ (f a) ≠ ⊤
[PROOFSTEP]
simpa only [Finite.mem_toFinset]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ ↑↑μ (s ∪ t) < ⊤ ↔ ↑↑μ s < ⊤ ∧ ↑↑μ t < ⊤
[PROOFSTEP]
refine' ⟨fun h => ⟨_, _⟩, fun h => measure_union_lt_top h.1 h.2⟩
[GOAL]
case refine'_1
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : ↑↑μ (s ∪ t) < ⊤
⊢ ↑↑μ s < ⊤
[PROOFSTEP]
exact (measure_mono (Set.subset_union_left s t)).trans_lt h
[GOAL]
case refine'_2
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : ↑↑μ (s ∪ t) < ⊤
⊢ ↑↑μ t < ⊤
[PROOFSTEP]
exact (measure_mono (Set.subset_union_right s t)).trans_lt h
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ ¬↑↑μ (s ∪ t) = ⊤ ↔ ¬(↑↑μ s = ⊤ ∨ ↑↑μ t = ⊤)
[PROOFSTEP]
simp only [← lt_top_iff_ne_top, ← Ne.def, not_or, measure_union_lt_top_iff]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝¹ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
inst✝ : Countable β
s : β → Set α
hs : ↑↑μ (⋃ (n : β), s n) ≠ 0
⊢ ∃ n, 0 < ↑↑μ (s n)
[PROOFSTEP]
contrapose! hs
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝¹ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
inst✝ : Countable β
s : β → Set α
hs : ∀ (n : β), ↑↑μ (s n) ≤ 0
⊢ ↑↑μ (⋃ (n : β), s n) = 0
[PROOFSTEP]
exact measure_iUnion_null fun n => nonpos_iff_eq_zero.1 (hs n)
[GOAL]
α✝ : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α✝
μ✝ μ₁ μ₂ : Measure α✝
s s₁ s₂ t : Set α✝
α : Type ?u.37668
m : MeasurableSpace α
μ : Measure α
⊢ univ ∈ {s | ↑↑μ sᶜ = 0}
[PROOFSTEP]
simp
[GOAL]
α✝ : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α✝
μ✝ μ₁ μ₂ : Measure α✝
s s₁ s₂ t : Set α✝
α : Type ?u.37668
m : MeasurableSpace α
μ : Measure α
x✝ y✝ : Set α
hs : x✝ ∈ {s | ↑↑μ sᶜ = 0}
ht : y✝ ∈ {s | ↑↑μ sᶜ = 0}
⊢ x✝ ∩ y✝ ∈ {s | ↑↑μ sᶜ = 0}
[PROOFSTEP]
simp only [compl_inter, mem_setOf_eq]
[GOAL]
α✝ : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α✝
μ✝ μ₁ μ₂ : Measure α✝
s s₁ s₂ t : Set α✝
α : Type ?u.37668
m : MeasurableSpace α
μ : Measure α
x✝ y✝ : Set α
hs : x✝ ∈ {s | ↑↑μ sᶜ = 0}
ht : y✝ ∈ {s | ↑↑μ sᶜ = 0}
⊢ ↑↑μ (x✝ᶜ ∪ y✝ᶜ) = 0
[PROOFSTEP]
exact measure_union_null hs ht
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t s : Set α
⊢ sᶜ ∈ Measure.ae μ ↔ ↑↑μ s = 0
[PROOFSTEP]
simp only [mem_ae_iff, compl_compl]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ ∀ (S : Set (Set α)), Set.Countable S → (∀ (s : Set α), s ∈ S → s ∈ Measure.ae μ) → ⋂₀ S ∈ Measure.ae μ
[PROOFSTEP]
intro S hSc hS
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
S : Set (Set α)
hSc : Set.Countable S
hS : ∀ (s : Set α), s ∈ S → s ∈ Measure.ae μ
⊢ ⋂₀ S ∈ Measure.ae μ
[PROOFSTEP]
rw [mem_ae_iff, compl_sInter, sUnion_image]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
S : Set (Set α)
hSc : Set.Countable S
hS : ∀ (s : Set α), s ∈ S → s ∈ Measure.ae μ
⊢ ↑↑μ (⋃ (x : Set α) (_ : x ∈ S), xᶜ) = 0
[PROOFSTEP]
exact (measure_biUnion_null_iff hSc).2 hS
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
f g : α → ℝ≥0∞
h : ∀ᵐ (x : α) ∂μ, f x < g x
⊢ f ≤ᵐ[μ] g
[PROOFSTEP]
rw [Filter.EventuallyLE, ae_iff]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
f g : α → ℝ≥0∞
h : ∀ᵐ (x : α) ∂μ, f x < g x
⊢ ↑↑μ {a | ¬f a ≤ g a} = 0
[PROOFSTEP]
rw [ae_iff] at h
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
f g : α → ℝ≥0∞
h : ↑↑μ {a | ¬f a < g a} = 0
⊢ ↑↑μ {a | ¬f a ≤ g a} = 0
[PROOFSTEP]
refine' measure_mono_null (fun x hx => _) h
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
f g : α → ℝ≥0∞
h : ↑↑μ {a | ¬f a < g a} = 0
x : α
hx : x ∈ {a | ¬f a ≤ g a}
⊢ x ∈ {a | ¬f a < g a}
[PROOFSTEP]
exact not_lt.2 (le_of_lt (not_le.1 hx))
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ (∀ᵐ (x : α) ∂μ, ¬x ∈ s) ↔ ↑↑μ s = 0
[PROOFSTEP]
simp only [ae_iff, Classical.not_not, setOf_mem_eq]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ (∀ᵐ (x : α) ∂μ, x ∈ s → x ∈ t) ↔ ↑↑μ (s \ t) = 0
[PROOFSTEP]
simp [ae_iff]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ ↑↑μ {a | a ∈ s ∧ ¬a ∈ t} = 0 ↔ ↑↑μ (s \ t) = 0
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ s ∪ t =ᵐ[μ] t ↔ ↑↑μ (s \ t) = 0
[PROOFSTEP]
simp [eventuallyLE_antisymm_iff, ae_le_set, union_diff_right, diff_eq_empty.2 (Set.subset_union_right _ _)]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
⊢ s \ t =ᵐ[μ] s ↔ ↑↑μ (s ∩ t) = 0
[PROOFSTEP]
simp [eventuallyLE_antisymm_iff, ae_le_set, diff_diff_right, diff_diff, diff_eq_empty.2 (Set.subset_union_right _ _)]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t✝ s t : Set α
⊢ s =ᵐ[μ] t ↔ ↑↑μ (s \ t) = 0 ∧ ↑↑μ (t \ s) = 0
[PROOFSTEP]
simp [eventuallyLE_antisymm_iff, ae_le_set]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t✝ s t : Set α
⊢ ↑↑μ (s ∆ t) = 0 ↔ s =ᵐ[μ] t
[PROOFSTEP]
simp [ae_eq_set, symmDiff_def]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t✝ s t : Set α
⊢ sᶜ =ᵐ[μ] tᶜ ↔ s =ᵐ[μ] t
[PROOFSTEP]
simp only [← measure_symmDiff_eq_zero_iff, compl_symmDiff_compl]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t✝ s t : Set α
⊢ sᶜ =ᵐ[μ] t ↔ s =ᵐ[μ] tᶜ
[PROOFSTEP]
rw [← ae_eq_set_compl_compl, compl_compl]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : s =ᵐ[μ] univ
⊢ s ∪ t =ᵐ[μ] univ
[PROOFSTEP]
convert ae_eq_set_union h (ae_eq_refl t)
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : s =ᵐ[μ] univ
⊢ univ = univ ∪ t
[PROOFSTEP]
rw [univ_union]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : t =ᵐ[μ] univ
⊢ s ∪ t =ᵐ[μ] univ
[PROOFSTEP]
convert ae_eq_set_union (ae_eq_refl s) h
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : t =ᵐ[μ] univ
⊢ univ = s ∪ univ
[PROOFSTEP]
rw [union_univ]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : s =ᵐ[μ] ∅
⊢ s ∪ t =ᵐ[μ] t
[PROOFSTEP]
convert ae_eq_set_union h (ae_eq_refl t)
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : s =ᵐ[μ] ∅
⊢ t = ∅ ∪ t
[PROOFSTEP]
rw [empty_union]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : t =ᵐ[μ] ∅
⊢ s ∪ t =ᵐ[μ] s
[PROOFSTEP]
convert ae_eq_set_union (ae_eq_refl s) h
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : t =ᵐ[μ] ∅
⊢ s = s ∪ ∅
[PROOFSTEP]
rw [union_empty]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : s =ᵐ[μ] univ
⊢ s ∩ t =ᵐ[μ] t
[PROOFSTEP]
convert ae_eq_set_inter h (ae_eq_refl t)
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : s =ᵐ[μ] univ
⊢ t = univ ∩ t
[PROOFSTEP]
rw [univ_inter]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : t =ᵐ[μ] univ
⊢ s ∩ t =ᵐ[μ] s
[PROOFSTEP]
convert ae_eq_set_inter (ae_eq_refl s) h
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : t =ᵐ[μ] univ
⊢ s = s ∩ univ
[PROOFSTEP]
rw [inter_univ]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : s =ᵐ[μ] ∅
⊢ s ∩ t =ᵐ[μ] ∅
[PROOFSTEP]
convert ae_eq_set_inter h (ae_eq_refl t)
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : s =ᵐ[μ] ∅
⊢ ∅ = ∅ ∩ t
[PROOFSTEP]
rw [empty_inter]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : t =ᵐ[μ] ∅
⊢ s ∩ t =ᵐ[μ] ∅
[PROOFSTEP]
convert ae_eq_set_inter (ae_eq_refl s) h
[GOAL]
case h.e'_5
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
h : t =ᵐ[μ] ∅
⊢ ∅ = s ∩ ∅
[PROOFSTEP]
rw [inter_empty]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝¹ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
M : Type u_6
inst✝ : One M
f : α → M
s : Set α
⊢ mulIndicator s f =ᵐ[μ] 1 ↔ ↑↑μ (s ∩ mulSupport f) = 0
[PROOFSTEP]
simp [EventuallyEq, eventually_iff, Measure.ae, compl_setOf]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝¹ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
M : Type u_6
inst✝ : One M
f : α → M
s : Set α
⊢ ↑↑μ {a | a ∈ s ∧ ¬f a = 1} = 0 ↔ ↑↑μ (s ∩ mulSupport f) = 0
[PROOFSTEP]
rfl
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
H : s ≤ᵐ[μ] t
⊢ ↑↑μ (s ∪ t) = ↑↑μ (t ∪ s \ t)
[PROOFSTEP]
rw [union_diff_self, Set.union_comm]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s s₁ s₂ t : Set α
H : s ≤ᵐ[μ] t
⊢ ↑↑μ t + ↑↑μ (s \ t) = ↑↑μ t
[PROOFSTEP]
rw [ae_le_set.1 H, add_zero]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
⊢ s ⊆ toMeasurable μ s
[PROOFSTEP]
rw [toMeasurable_def]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
⊢ s ⊆
if h : ∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s then Exists.choose h
else
if h' : ∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u) then Exists.choose h'
else Exists.choose (_ : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ↑↑μ t = ↑↑μ s)
[PROOFSTEP]
split_ifs with hs h's
[GOAL]
case pos
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
hs : ∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
⊢ s ⊆ Exists.choose hs
case pos
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
hs : ¬∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
h's : ∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u)
⊢ s ⊆ Exists.choose h's
case neg
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
hs : ¬∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
h's : ¬∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u)
⊢ s ⊆ Exists.choose (_ : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ↑↑μ t = ↑↑μ s)
[PROOFSTEP]
exacts [hs.choose_spec.fst, h's.choose_spec.fst, (exists_measurable_superset μ s).choose_spec.1]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
⊢ MeasurableSet (toMeasurable μ s)
[PROOFSTEP]
rw [toMeasurable_def]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
⊢ MeasurableSet
(if h : ∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s then Exists.choose h
else
if h' : ∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u) then Exists.choose h'
else Exists.choose (_ : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ↑↑μ t = ↑↑μ s))
[PROOFSTEP]
split_ifs with hs h's
[GOAL]
case pos
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
hs : ∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
⊢ MeasurableSet (Exists.choose hs)
case pos
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
hs : ¬∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
h's : ∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u)
⊢ MeasurableSet (Exists.choose h's)
case neg
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ✝ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t : Set α
μ : Measure α
s : Set α
hs : ¬∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
h's : ¬∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u)
⊢ MeasurableSet (Exists.choose (_ : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ↑↑μ t = ↑↑μ s))
[PROOFSTEP]
exacts [hs.choose_spec.snd.1, h's.choose_spec.snd.1, (exists_measurable_superset μ s).choose_spec.2.1]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t s : Set α
⊢ ↑↑μ (toMeasurable μ s) = ↑↑μ s
[PROOFSTEP]
rw [toMeasurable_def]
[GOAL]
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t s : Set α
⊢ ↑↑μ
(if h : ∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s then Exists.choose h
else
if h' : ∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u) then
Exists.choose h'
else Exists.choose (_ : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ↑↑μ t = ↑↑μ s)) =
↑↑μ s
[PROOFSTEP]
split_ifs with hs h's
[GOAL]
case pos
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t s : Set α
hs : ∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
⊢ ↑↑μ (Exists.choose hs) = ↑↑μ s
[PROOFSTEP]
exact measure_congr hs.choose_spec.snd.2
[GOAL]
case pos
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t s : Set α
hs : ¬∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
h's : ∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u)
⊢ ↑↑μ (Exists.choose h's) = ↑↑μ s
[PROOFSTEP]
simpa only [inter_univ] using h's.choose_spec.snd.2 univ MeasurableSet.univ
[GOAL]
case neg
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
ι : Type u_5
inst✝ : MeasurableSpace α
μ μ₁ μ₂ : Measure α
s✝ s₁ s₂ t s : Set α
hs : ¬∃ t x, MeasurableSet t ∧ t =ᵐ[μ] s
h's : ¬∃ t x, MeasurableSet t ∧ ∀ (u : Set α), MeasurableSet u → ↑↑μ (t ∩ u) = ↑↑μ (s ∩ u)
⊢ ↑↑μ (Exists.choose (_ : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ↑↑μ t = ↑↑μ s)) = ↑↑μ s
[PROOFSTEP]
exact (exists_measurable_superset μ s).choose_spec.2.2
|
Ethanol extracts of the fruit body are high in antioxidant activity , and have been shown in laboratory tests to have anti @-@ inflammatory activity comparable to the drug diclofenac . Studies with mouse models have also demonstrated <unk> ( liver @-@ protecting ) ability , possibly by restoring diminished levels of the antioxidant enzymes superoxide dismutase and catalase caused by experimental exposure to the liver @-@ damaging chemical carbon tetrachloride .
|
From Paco Require Import paco.
Require Import sflib.
Require Import SysSem.
Require Import PALSSystem.
Require console ctrl dev.
Require Import AcStSystem.
Require Import SpecConsole SpecController SpecDevice.
Require Import VerifConsole VerifController VerifDevice.
Require Import ZArith List Lia.
Local Opaque Z.of_nat Z.to_nat.
Program Definition active_standby_system
: PALSSys.t :=
{| (* PALSSys.RNWSParamsObj := _ ; *)
(* PALSSys.SystemEnvObj := _ ; *)
(* PALSSys.sysE := ActiveStandby.sysE; *)
(* PALSSys.CProgSysEventObj := _; *)
PALSSys.tasks := [task_con; task_ctrl1; task_ctrl2;
task_dev1; task_dev2; task_dev3] ;
|}.
Next Obligation.
ss.
Qed.
Next Obligation.
repeat (econs; ss).
Qed.
(* Lemma active_standby_system_refinement1 *)
(* tm_init *)
(* (TM_INIT: Z.to_nat ActiveStandby.period <= tm_init) *)
(* : DSys.behav_sys (PALSSys.dsys_nc *)
(* active_standby_system tm_init) <1= *)
(* DSys.behav_sys (PALSSys.dsys_exec *)
(* active_standby_system tm_init). *)
(* Proof. *)
(* apply impl_spec_refinement1. *)
(* ss. *)
(* Qed. *)
Theorem active_standby_system_refinement
tm_init
(TM_INIT: Z.to_nat ActiveStandby.period <= tm_init)
: DSys.behav_sys2 _ (PALSSys.dsys_nc
active_standby_system tm_init) <1=
DSys.behav_sys2 _ (PALSSys.dsys_exec
active_standby_system tm_init).
Proof.
apply impl_spec_refinement.
ss.
Qed.
|
State Before: α : Type u
n : ℕ
⊢ finRange (Nat.succ n) = 0 :: map Fin.succ (finRange n) State After: case a
α : Type u
n : ℕ
⊢ map Fin.val (finRange (Nat.succ n)) = map Fin.val (0 :: map Fin.succ (finRange n)) Tactic: apply map_injective_iff.mpr Fin.val_injective State Before: case a
α : Type u
n : ℕ
⊢ map Fin.val (finRange (Nat.succ n)) = map Fin.val (0 :: map Fin.succ (finRange n)) State After: case a
α : Type u
n : ℕ
⊢ 0 :: map (Nat.succ ∘ Fin.val) (finRange n) = 0 :: map (Fin.val ∘ Fin.succ) (finRange n) Tactic: rw [map_cons, map_coe_finRange, range_succ_eq_map, Fin.val_zero, ← map_coe_finRange, map_map,
map_map] State Before: case a
α : Type u
n : ℕ
⊢ 0 :: map (Nat.succ ∘ Fin.val) (finRange n) = 0 :: map (Fin.val ∘ Fin.succ) (finRange n) State After: no goals Tactic: simp only [Function.comp, Fin.val_succ] |
function [H W] = createHashTable(K,b,t)
%% function [H W] = createHashTable(K,b,t)
% Create a hash table for kernelized LSH.
%
% Inputs: K (kernel matrix)
% b (number of bits)
% t (number of Gaussian approximation elements)
%
% Outputs: H (hash table over elements of K, size p x b)
% W (weight matrix for computing hash keys over queries, size p x b)
%%
[p,p] = size(K);
%center the kernel matrix
K = K - (1/p)*(K*ones(p,1))*ones(1,p) - (1/p)*ones(p,1)*(ones(1,p)*K) + (1/p^2)*sum(sum(K));
if nargin < 3
t = min(floor(p/4), 30);
end
[V_K,D_K] = eig(K);
d_k = diag(D_K);
ind_k = find(d_k > 1e-8);
d_k(ind_k) = d_k(ind_k).^(-1/2);
K_half = V_K*diag(d_k)*V_K';
%create indices for the t random points for each hash bit
%then form weight matrix
for i = 1:b
rp = randperm(p);
I_s(i,:) = rp(1:t);
e_s = zeros(p,1);
e_s(I_s(i,:)) = 1;
W(:,i) = sqrt((p-1)/t)*K_half*e_s;
end
H = (K*W)>0;
W = real(W); |
function result = analyzeHardStop(debug, ground_truth, tFailure_s, PerformanceSpec)
% Author: Alexander Wischnewski Date: 24-02-2019
%
% Description:
% scans the debug data and ground truth whether a hard stop
% was performed within the given specifications
%
% Input:
% debug: Debug structure of the vehicle
% ground_truth: Physical ground truth data from simulation
% tFailure_s: Timestamp where the failure occured
% PerformanceSpec Structure with fields:
% AccxMin_mps2 Minimum mean negative acceleration applied until vehicle
% stops
% tDetectionMax_s Maximum time to detect the hard stop
%
% Outputs:
% result: 1 if a valid emergency stop was detected, 0 otherwise
result = 1;
disp(' ');
disp('------------------------------');
disp('Check Hard Stop: ');
disp('------------------------------');
% find timestamp where vehicle has gone to hard stop
idxDetect = find(uint16(debug.debug_mloc_statemachine_debug_TUMVehicleState.Data) == 60, 1);
if isempty(idxDetect)
disp('The vehicle did not detect the hard stop');
result = 0;
return
else
tFailuredDetected_s = debug.debug_mloc_statemachine_debug_TUMVehicleState.Time(idxDetect);
disp(['The vehicle took ' num2str(tFailuredDetected_s - tFailure_s) ' s to detect the failure.']);
end
% check if fault detection time was within spec
if(tFailuredDetected_s <= 0 && tFailuredDetected_s >= PerformanceSpec.tDetectionMax_s)
disp('The vehicle did not detect the emergency within the specified time');
result = 0;
return
end
% find point where failure was detected
idxDetect_gt = find(ground_truth.SimRealState_ax_mps2.Time > tFailuredDetected_s, 1);
% find timestamp where velocity has gone to new stopped
% for very low velocites, the stop controller does not behave precisly in
% sim, therefore its tested against roughly 5kph.
idxStop = find(ground_truth.SimRealState_vx_mps.Data(idxDetect_gt:end) < 2, 1) + idxDetect_gt;
if isempty(idxStop)
disp('The vehicle did not stop.');
result = 0;
return
else
tStop_s = ground_truth.SimRealState_vx_mps.Time(idxStop);
disp(['The vehicle took ' num2str(tStop_s - tFailure_s) ' s to stop.']);
end
% check if control performance was ok
meanAccX = mean(ground_truth.SimRealState_ax_mps2.Data(idxDetect_gt:idxStop));
disp(['The mean longitudinal accleeration was: ' num2str(meanAccX)]);
if(meanAccX > PerformanceSpec.AccxMin_mps2)
disp('The vehicle did not stay within the specified deceleration bounds.');
result = 0;
return
end
disp(' ');
disp('All checks passed.'); |
function [maxVal] = maxIdx(a, idx)
%
% Copyright Aditya Khosla http://mit.edu/khosla
%
% Please cite this paper if you use this code in your publication:
% A. Khosla, J. Xiao, A. Torralba, A. Oliva
% Memorability of Image Regions
% Advances in Neural Information Processing Systems (NIPS) 2012
%
maxVal = max(a(idx, :), [], 1);
|
Rebol [
Title: "Amazon S3 Protocol"
Author: "Christopher Ross-Gill"
Date: 30-Aug-2011
File: %s3.r
Version: 0.2.1
Purpose: {Basic retrieve and upload protocol for Amazon S3.}
Rights: http://opensource.org/licenses/Apache-2.0
Example: [
do/args http://reb4.me/r/s3 [args (see settings)]
write s3://<bucket>/file/foo.txt "Foo"
read s3://<bucket>/file/foo.txt
]
History: [
23-Nov-2008 ["Graham Chiu" "Maarten Koopmans" "Gregg Irwin"]
]
Settings: [
AWSAccessKeyId: <AWSAccessKeyId>
AWSSecretAccessKey: <AWSSecretAccessKey>
Secure: true ; optional
]
]
do http://reb4.me/r/http-custom
make object! bind [
port-flags: system/standard/port-flags/pass-thru
init: use [chars url] [
chars: charset [
"-_!+%.,"
#"0" - #"9"
#"a" - #"z" #"A" - #"Z"
]
url: [
"s3://" [
copy user some chars
#":"
copy pass some chars
#"@"
|
(
user: none
pass: none
)
]
copy host some chars
#"/"
copy path any [
some chars
#"/"
]
copy target any chars
end
(
path: if path [
to file! path
]
target: if target [
to file! target
]
user: any [
user
settings/awsaccesskeyid
]
pass: any [
pass
settings/awssecretaccesskey
]
url: rejoin [
s3:// host "/"
any [path ""]
any [target ""]
]
)
]
func [port spec] [
if not all [
url? spec
parse/all spec bind url port
][
make error! "Invalid S3 Spec"
]
spec: rejoin [
either settings/secure [
https://
][
http://
]
port/host ".s3.amazonaws.com/"
any [
all [
port/target
port/path
]
""
]
any [
port/target
""
]
]
port/sub-port: make port! spec
]
]
open: use [options] [
options: make object! [
options:
modes:
type:
md5:
access:
prefix: _
]
func [port] [
port/state/flags: port/state/flags or port-flags
port/locals: make options [
modes: make block! 3
if port/state/flags and 1 > 0 [
append modes 'read
]
if port/state/flags and 2 > 0 [
append modes 'write
]
if port/state/flags and 32 > 0 [
append modes 'binary
]
options: any [
port/state/custom
make block! 0
]
if all [
port/path
not port/target
][
repend options [
'prefix port/path
]
]
parse options [
any [
'md5
set md5 string!
|
'type
set type path!
(type: form type)
|
'read
(access: "public-read")
|
'write
(access: "public-read-write")
|
'prefix
set prefix [
string! | file!
]
(
if not port/target [
port/sub-port/path: join "?prefix=" prefix
]
)
|
skip
]
]
]
]
]
copy: func [port] [
send "GET" port _
]
insert: func [port data] [
if not port/target [
make error! "Not a valid S3 key"
]
case [
none? data [
send "DELETE" port _
]
any [
string? data
binary? data
][
send "PUT" port data
]
data [
send "PUT" port form data
]
]
]
close: does []
query: func [port] [
port/locals: [
modes [read]
]
send "HEAD" port _
port/size: attempt [
to integer! port/sub-port/locals/headers/content-length
]
port/date: port/sub-port/date
port/status: either port/target [
'file
][
'directory
]
]
if not in system/schemes 's3 [
system/schemes: make system/schemes [
s3: _
]
]
system/schemes/s3: make system/standard/port compose [
scheme: 's3
port-id: 0
handler: (self)
passive: _
cache-size: 5
proxy: make object! [
host:
port-id:
user:
pass:
type:
bypass: _
]
]
]
make object! [
_: none
settings: make context [
awsaccesskeyid:
awssecretaccesskey: ""
secure: true
] any [
system/script/args
system/script/header/settings
]
get-http-response: func [port] [
reform next parse do bind [response-line] last second get in port/handler 'open none
]
send: use [timestamp detect-mime sign compose-request] [
timestamp: func [/for date [date!]] [
date: any [
date
now
]
date/time: date/time - date/zone
rejoin [
copy/part pick system/locale/days date/weekday 3
", "
next form 100 + date/day
" "
copy/part pick system/locale/months date/month 3
" "
date/year
" "
next form 100 + date/time/hour
":"
next form 100 + date/time/minute
":"
next form 100 + to integer! date/time/second
" GMT"
]
]
detect-mime: use [types] [
types: [
application/octet-stream
text/html %.html %.htm
image/jpeg %.jpg %.jpeg
image/png %.png
image/tiff %.tif %.tiff
application/pdf %.pdf
text/plain %.txt %.r
application/xml %.xml
video/mpeg %.mpg %.mpeg
video/x-m4v %.m4v
]
func [
file [file! url! none!]
][
if file [
file: any [
find types suffix? file
next types
]
form first find/reverse file path!
]
]
]
sign: func [
verb [string!]
port [port!]
request [object!]
][
rejoin [
"AWS " port/user ":"
enbase/base checksum/secure/key rejoin [
form verb
newline
newline ; any [port/locals/md5 ""] newline
any [
request/type ""
]
newline
timestamp
newline
either request/auth [
rejoin [
"x-amz-acl:" request/auth "^/"
]
][
""
]
"/" port/host
"/" any [
all [
port/target
port/path
] ""
]
any [
port/target ""
]
] port/pass 64
]
]
compose-request: func [
verb [string!]
port [port!]
data [series! none!]
][
data: make object! [
body: any [
data ""
]
size: all [
data
length? data
]
type: all [
data any [
port/locals/type
detect-mime port/target
]
]
auth: all [
data
port/locals/access
]
]
reduce [
to-word verb data/body
foreach [header value] [
"Date" [timestamp]
"Content-Type" [data/type]
"Content-Length" [data/size]
"Authorization" [sign verb port data]
"x-amz-acl" [data/auth]
"Pragma" ["no-cache"]
"Cache-Control" ["no-cache"]
][
if value: all :value [
repend [] [
to-set-word header
form value
]
]
]
]
]
send: func [
[catch]
method [string!]
port [port!]
data [any-type!]
][
either error? data: try [
open/mode/custom port/sub-port port/locals/modes compose-request method port data
][
net-error rejoin [
"Target url " port/url " could not be retrieved "
"(" get-http-response port/sub-port ")."
]
][
data: copy port/sub-port
either port/target [
data
][
unless method = "HEAD" [
data: load/markup data
parse data [
copy data any [
data:
<key>
(
remove data
change data to-file data/1
)
|
skip
(
remove data
)
:data
]
]
data
]
]
]
]
]
]
|
function fx2 = p08_fx2 ( x )
%*****************************************************************************80
%
%% P08_FX2 evaluates the second derivative of the function for problem 8.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 07 May 2011
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, real X, the abscissa.
%
% Output, real FX2, the second derivative of the function at X.
%
fx2 = - cos ( x );
return
end
|
Class(OpenMP_POWERUnparser, paradigms.smp.OpenMP_UnparseMixin, packages.powerisa.power9.p9macro.POWER9Unparser);
Class(OpenMP_POWERUnparser_ParFor, paradigms.smp.OpenMP_UnparseMixin_ParFor, packages.powerisa.power9.p9macro.POWER9Unparser);
|
lemma poly_0 [simp]: "poly 0 x = 0" |
#############################################################################
#
# Mark Cembrowski, Janelia Farm, January 29 2014
#
# This is a helper function that checks to make sure a list of sample names
# provided are all contained within the samples in the dataset.
#
# Search, as currently implement, is EXACT. e.g., if the samples are
# c('ca3_mpp3','ca3_grp'), then providedNames='ca3' will be stopped, but
# 'providedNames='ca3_mpp3' will not be stopped.
#
# fpkmMat can be supplied if the full fpkmMatrix (or repFpkmMatrix) should
# not be used, or should not be regenerated (saves time for large
# matrices, especially when dealing with replicates).
#
# It halts execution if at least one sample is not found.
#
# INPUTS:
# providedNames: character. List of samples to check for.
#
# OPTIONAL ARGUMENTS:
# replicates=F: logical. Use replicates in analysis.
# fpkmMat=matrix(): matrix. Can supply a specific matrix for analysis.
#############################################################################
.screenSamples <- function(providedNames,replicates=F,fpkmMat=matrix()){
if(prod(dim(fpkmMat))>1.1){
theMat <- fpkmMat
if(!replicates){
namesInDb <- colnames(theMat)
}else{
namesInDb <- substr(colnames(theMat),1,nchar(colnames(theMat))-2)
}
}else{
if(!replicates){
theMat <- fpkmMatrix(genes(cuff_data))
namesInDb <- colnames(theMat)
}else{
theMat <- repFpkmMatrix(genes(cuff_data))
namesInDb <- colnames(theMat)
# Remove replicate identifiers from the end of
# column names; e.g., turn 'ca3_mpp3_0' into
# 'ca3_mpp3'
namesInDb <- substr(namesInDb,1,nchar(namesInDb)-2)
namesInDb <- unique(namesInDb)
}
}
allInDb <- prod(providedNames%in%namesInDb)
if(allInDb<0.1){
stop('At least one provided name not in database.')
}
# Invisibly return full matrix, if going to be used by a downstream
# script (e.g., masking).
invisible(theMat)
}
|
module test where
|
import data.real.irrational
import topology.basic
import algebra.order.floor
--OUTPUT 1
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
have h1 : ∀ (i j : ℤ), i ≠ j → int.fract (α * ↑i) ≠ int.fract (α * ↑j),
from by auto [int.fract_eq_iff, hα_irrat, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_iff, int.fract_eq_
end --Needs more than 2000 tokens!
/- FEW SHOT PROMPTS TO CODEX(START)
/--`theorem`
Power Set is Closed under Intersection
Let $S$ be a set.
Let $\powerset S$ be the power set of $S$.
Then:
:$\forall A, B \in \powerset S: A \cap B \in \powerset S$
`proof`
Let $A, B \in \powerset S$.
Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$.
From Intersection is Subset we have that $A \cap B \subseteq A$.
It follows from Subset Relation is Transitive that $A \cap B \subseteq S$.
Thus $A \cap B \in \powerset S$ and closure is proved.
{{qed}}
-/
theorem power_set_intersection_closed {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S :=
begin
assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),
have h1 : (A ⊆ S) ∧ (B ⊆ S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],
have h2 : (A ∩ B) ⊆ A, from by auto [set.inter_subset_left],
have h3 : (A ∩ B) ⊆ S, from by auto [set.subset.trans],
show (A ∩ B) ∈ 𝒫 S, from by auto [set.mem_powerset],
end
/--`theorem`
Square of Sum
:$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$
`proof`
Follows from the distribution of multiplication over addition:
{{begin-eqn}}
{{eqn | l = \left({x + y}\right)^2
| r = \left({x + y}\right) \cdot \left({x + y}\right)
}}
{{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right)
| c = Real Multiplication Distributes over Addition
}}
{{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y
| c = Real Multiplication Distributes over Addition
}}
{{eqn | r = x^2 + 2xy + y^2
| c =
}}
{{end-eqn}}
{{qed}}
-/
theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) :=
begin
calc (x + y)^2 = (x+y)*(x+y) : by auto [sq]
... = x*(x+y) + y*(x+y) : by auto [add_mul]
... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring]
... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring]
end
/--`theorem`
Identity of Group is Unique
Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$.
`proof`
From Group has Latin Square Property, there exists a unique $x \in G$ such that:
:$a x = b$
and there exists a unique $y \in G$ such that:
:$y a = b$
Setting $b = a$, this becomes:
There exists a unique $x \in G$ such that:
:$a x = a$
and there exists a unique $y \in G$ such that:
:$y a = a$
These $x$ and $y$ are both $e$, by definition of identity element.
{{qed}}
-/
theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a :=
begin
have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by auto using [use (a⁻¹ * b)],
have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by auto using [use b * a⁻¹],
have h3 : ∀ a : G, ∃! x : G, a * x = a, from by auto [h1],
have h4 : ∀ a : G, ∃! y : G, y * a = a, from by auto [h2],
have h5 : ∀ a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one],
have h6 : ∀ a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul],
show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)],
end
/--`theorem`
Squeeze Theorem for Real Numbers
Let $\sequence {x_n}$, $\sequence {y_n}$ and $\sequence {z_n}$ be sequences in $\R$.
Let $\sequence {y_n}$ and $\sequence {z_n}$ both be convergent to the following limit:
:$\ds \lim_{n \mathop \to \infty} y_n = l, \lim_{n \mathop \to \infty} z_n = l$
Suppose that:
:$\forall n \in \N: y_n \le x_n \le z_n$
Then:
:$x_n \to l$ as $n \to \infty$
that is:
:$\ds \lim_{n \mathop \to \infty} x_n = l$
`proof`
From Negative of Absolute Value:
:$\size {x - l} < \epsilon \iff l - \epsilon < x < l + \epsilon$
Let $\epsilon > 0$.
We need to prove that:
:$\exists N: \forall n > N: \size {x_n - l} < \epsilon$
As $\ds \lim_{n \mathop \to \infty} y_n = l$ we know that:
:$\exists N_1: \forall n > N_1: \size {y_n - l} < \epsilon$
As $\ds \lim_{n \mathop \to \infty} z_n = l$ we know that:
:$\exists N_2: \forall n > N_2: \size {z_n - l} < \epsilon$
Let $N = \max \set {N_1, N_2}$.
Then if $n > N$, it follows that $n > N_1$ and $n > N_2$.
So:
:$\forall n > N: l - \epsilon < y_n < l + \epsilon$
:$\forall n > N: l - \epsilon < z_n < l + \epsilon$
But:
:$\forall n \in \N: y_n \le x_n \le z_n$
So:
:$\forall n > N: l - \epsilon < y_n \le x_n \le z_n < l + \epsilon$
and so:
:$\forall n > N: l - \epsilon < x_n < l + \epsilon$
So:
:$\forall n > N: \size {x_n - l} < \epsilon$
Hence the result.
{{qed}}
-/
theorem squeeze_theorem_real_numbers (x y z : ℕ → ℝ) (l : ℝ) :
let seq_limit : (ℕ → ℝ) → ℝ → Prop := λ (u : ℕ → ℝ) (l : ℝ), ∀ ε > 0, ∃ N, ∀ n > N, |u n - l| < ε in
seq_limit y l → seq_limit z l → (∀ n : ℕ, (y n) ≤ (x n) ∧ (x n) ≤ (z n)) → seq_limit x l :=
begin
assume seq_limit (h2 : seq_limit y l) (h3 : seq_limit z l) (h4 : ∀ (n : ℕ), y n ≤ x n ∧ x n ≤ z n) (ε),
have h5 : ∀ x, |x - l| < ε ↔ (((l - ε) < x) ∧ (x < (l + ε))),
from by auto [abs_sub_lt_iff] using [linarith],
assume (h7 : ε > 0),
cases h2 ε h7 with N1 h8,
cases h3 ε h7 with N2 h9,
let N := max N1 N2,
use N,
have h10 : ∀ n > N, n > N1 ∧ n > N2 := by auto [lt_of_le_of_lt, le_max_left, le_max_right],
have h11 : ∀ n > N, (((l - ε) < (y n)) ∧ ((y n) ≤ (x n))) ∧ (((x n) ≤ (z n)) ∧ ((z n) < l+ε)),
from by auto [h8, h10, h5, h9],
have h15 : ∀ n > N, ((l - ε) < (x n)) ∧ ((x n) < (l+ε)),
from by auto [h11] using [linarith],
show ∀ (n : ℕ), n > N → |x n - l| < ε,
from by auto [h5, h15],
end
/--`theorem`
Density of irrational orbit
The fractional parts of the integer multiples of an irrational number form a dense subset of the unit interval
`proof`
Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then
$$
i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor,
$$
which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. Hence,
$$
S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}
$$
is an infinite subset of $\left[0,1\right]$.
By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$.
To show that $S$ is dense in $[0, 1]$, consider $y \in[0,1]$, and $\epsilon>0$. Then by selecting $x \in S$ such that $\{x\}<\epsilon$ (which exists as $0$ is a limit point), and $N$ such that $N \cdot\{x\} \leq y<(N+1) \cdot\{x\}$, we get: $|y-\{N x\}|<\epsilon$.
QED
-/
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
FEW SHOT PROMPTS TO CODEX(END)-/
|
theory Lang_Simplifier
imports Tools Lang_Typed Hoare_Typed RHL_Typed
begin
named_theorems lang_simp_start
named_theorems lang_simp
named_theorems lang_cong
lemma lang_simp_start_denotation [lang_simp_start]:
"fun_equiv denotation c c' \<Longrightarrow> denotation c == denotation c'"
unfolding fun_equiv_def by simp
lemma lang_simp_start_hoare [lang_simp_start]:
"fun_equiv denotation c c' \<Longrightarrow> Hoare_Typed.hoare P c Q == Hoare_Typed.hoare P c' Q"
unfolding fun_equiv_def hoare_def by simp
lemma lang_simp_start_rhoare [lang_simp_start]:
"fun_equiv denotation c c' \<Longrightarrow> fun_equiv denotation d d' \<Longrightarrow> rhoare P c d Q == rhoare P c' d' Q"
unfolding fun_equiv_def rhoare_def by simp
simproc_setup hoare_simproc ("denotation c" | "Hoare_Typed.hoare P c Q" | "rhoare P' c d Q'") = {*
Tools.fun_equiv_simproc_named
@{named_theorems lang_simp_start}
@{named_theorems lang_cong}
@{named_theorems lang_simp}
*}
(* lemma lang_cong_program [lang_cong]: "fun_equiv denotation x y \<Longrightarrow> fun_equiv denotation (program x) (program y)"
unfolding program_def . *)
lemma lang_cong_while [lang_cong]: "fun_equiv denotation x y \<Longrightarrow> fun_equiv denotation (Lang_Typed.while e x) (Lang_Typed.while e y)"
unfolding fun_equiv_def denotation_def Rep_while unfolding denotation_untyped_While[THEN ext] by simp
lemma lang_cong_seq [lang_cong]: "fun_equiv denotation x y \<Longrightarrow> fun_equiv denotation x' y' \<Longrightarrow> fun_equiv denotation (seq x x') (seq y y')"
unfolding fun_equiv_def denotation_seq[THEN ext] by simp
lemma lang_cong_ifte [lang_cong]: "fun_equiv denotation x y \<Longrightarrow> fun_equiv denotation x' y' \<Longrightarrow> fun_equiv denotation (ifte e x x') (ifte e y y')"
unfolding fun_equiv_def denotation_def Rep_ifte unfolding denotation_untyped_IfTE[THEN ext] by auto
lemma lang_simp_seq_assoc [lang_simp]: "fun_equiv denotation (seq x (seq y z)) (seq (seq x y) z)"
unfolding fun_equiv_def by (fact denotation_seq_assoc[symmetric])
lemma lang_simp_skip_Seq [lang_simp]: "fun_equiv denotation (seq Lang_Typed.skip x) x"
unfolding fun_equiv_def by (fact denotation_seq_skip)
lemma lang_simp_seq_skip [lang_simp]: "fun_equiv denotation (seq x Lang_Typed.skip) x"
unfolding fun_equiv_def by (fact denotation_skip_seq)
lemma lang_simp_iftrue [lang_simp]: "(\<And>m. e_fun e m) \<Longrightarrow> fun_equiv denotation (ifte e c d) c"
unfolding fun_equiv_def by (subst denotation_ifte[THEN ext], simp)
lemma lang_simp_iffalse [lang_simp]: "(\<And>m. \<not> e_fun e m) \<Longrightarrow> fun_equiv denotation (ifte e c d) d"
unfolding fun_equiv_def by (subst denotation_ifte[THEN ext], simp)
lemma lang_simp_whilefalse [lang_simp]: "(\<And>m. \<not> e_fun e m) \<Longrightarrow> fun_equiv denotation (Lang_Typed.while e c) Lang_Typed.skip"
using lang_simp_iffalse unfolding fun_equiv_def while_unfold by simp
lemma lang_simp_ifsame [lang_simp]: "fun_equiv denotation c d \<Longrightarrow> fun_equiv denotation (ifte e c d) c"
unfolding fun_equiv_def by (subst denotation_ifte[THEN ext], auto)
lemma lang_simp_selfassign [lang_simp]: "(\<And>m. e_fun e m = memory_lookup m x) \<Longrightarrow> fun_equiv denotation (assign (variable_pattern x) e) Lang_Typed.skip"
unfolding fun_equiv_def denotation_assign[THEN ext] denotation_skip[THEN ext] apply auto
by (subst memory_update_lookup, simp)
(*
experiment begin
lemma "denotation PROGRAM[\<guillemotleft>x\<guillemotright>; {\<guillemotleft>y\<guillemotright>; \<guillemotleft>z\<guillemotright>}; \<guillemotleft>x\<guillemotright>] = denotation (foldr seq [x,y,z,x] Lang_Typed.skip)"
apply simp unfolding program_def ..
lemma "denotation PROGRAM[if ($x+1=$x+2-(1::int)) x:=x+1 else x:=x-1] = denotation PROGRAM[x:=x+1]"
by simp
lemma "denotation PROGRAM[if ($x=1) { while ($x=$x+(1::int)) { x:=x+1 } }; x:=x+1+2-3] = point_distr"
by (simp add: program_def denotation_skip[THEN ext])
(* lemma "LOCAL (x::int variable). hoare {True} x:=0; if ($x\<noteq>$x) { \<guillemotleft>c\<guillemotright> }; x:=x; x:=x+1 {$x=1}"
by (simp, wp, skip, auto) *)
end
*)
end
|
import pandas as pd
import os
import numpy as np
from learntools.core import *
class Evaluation(CodingProblem):
show_solution_on_correct = False
_vars = ["data_path", "results"]
_hints = [
"""Checking your solution requires that the file 'test_labels.csv' be available at `data_path`."""
]
def check(self, *args):
data_path = args[0]
results = args[1]
data_file = 'test_labels.csv'
assert_file_exists(os.path.join(data_path, data_file))
test_df = pd.read_csv(os.path.join(data_path, data_file), index_col=0, header=None)
y_true = test_df.iloc[:, 0]
if not set(y_true.index).issubset(set(results.keys())):
missing = set(y_true.index).difference(set(results.keys()))
print(f"Es gibt noch keine Vorhersage für die folgenden `id`s")
for missing_id in missing:
print(missing_id)
assert False
if not set(results.keys()).issubset(set(y_true.index)):
additional = set(results.keys()).difference(set(y_true.index))
print("Es gibt Vorhersagen für nicht vorhandene `id`s. Diese sind")
for additional_id in additional:
print(additional_id)
assert False
correct = 0
for id_, y_pred in results.items():
correct += y_true.loc[id_] == y_pred
accuracy = correct / len(y_true)
print(f"Die Genauigkeit der Vorhersage ist {accuracy}")
assert True
qvars = bind_exercises(globals(), [
Evaluation
],
)
__all__ = list(qvars)
|
import data.set.function
import data.fintype.basic
import data.finset.basic
import data.fin
import tactic
open finset function
@[derive fintype, derive decidable_eq]
structure cell := (r : fin 9) (c : fin 9)
def row (i : fin 9) : finset cell := filter (λ a, a.r = i) univ
def col (i : fin 9) : finset cell := filter (λ a, a.c = i) univ
def box (i : fin 9) : finset cell := filter (λ a, a.r / 3 = i / 3 ∧ a.c / 3 = i % 3) univ
lemma mem_row (a : cell) (i : fin 9) : a ∈ row i ↔ a.r = i := by simp [row]
lemma mem_col (a : cell) (i : fin 9) : a ∈ col i ↔ a.c = i := by simp [col]
lemma mem_box (a : cell) (i j : fin 3) :
a ∈ box i ↔ a.r / 3 = i / 3 ∧ a.c / 3 = i % 3 := by simp [box]
def same_row (a : cell) (b : cell) := a.r = b.r
def same_col (a : cell) (b : cell) := a.c = b.c
def same_box (a : cell) (b : cell) := (a.r / 3) = (b.r / 3) ∧ (a.c / 3) = (b.c / 3)
def cell_row (a : cell) : finset cell := row (a.r)
def cell_col (a : cell) : finset cell := col (a.c)
def cell_box (a : cell) : finset cell := box (3*(a.r / 3) + a.c / 3)
@[derive fintype, derive decidable_eq]
def sudoku := cell → fin 9
def row_axiom (s : sudoku) : Prop := ∀ a b : cell, same_row a b → s a = s b → a = b
def col_axiom (s : sudoku) : Prop := ∀ a b : cell, same_col a b → s a = s b → a = b
def box_axiom (s : sudoku) : Prop := ∀ a b : cell, same_box a b → s a = s b → a = b
def normal_sudoku_rules (s : sudoku) : Prop := row_axiom s ∧ col_axiom s ∧ box_axiom s
@[simp] lemma card_row : ∀ (i : fin 9), finset.card (row i) = 9 := dec_trivial
@[simp] lemma card_col : ∀ (i : fin 9), finset.card (col i) = 9 := dec_trivial
@[simp] lemma card_box : ∀ (i : fin 9), finset.card (box i) = 9 := dec_trivial
lemma row_injective (s : sudoku) (h_row : row_axiom s) (i : fin 9) :
∀ a b ∈ row i, s a = s b → a = b :=
begin
intros a b ha hb h_eq,
have h_srow : same_row a b,
{ rw mem_row at ha hb,
rw ← hb at ha,
exact ha
},
apply h_row _ _ h_srow h_eq
end
lemma row_surjective (s : sudoku) (h_row : row_axiom s) (i v : fin 9) :
∃ c ∈ (row i), v = s c :=
finset.surj_on_of_inj_on_of_card_le
(λ c (hc : c ∈ row i), s c)
(λ _ _, finset.mem_univ _)
(row_injective s h_row i)
(by simp) _
(mem_univ _)
#exit
import ring_theory.polynomial.homogeneous
variables {σ R : Type*} [comm_semiring R]
namespace mv_polynomial
lemma homogeneous_submodule_eq_span_monomial (i : ℕ) :
homogeneous_submodule σ R i =
submodule.span R ((λ d, monomial d 1) '' { d : σ →₀ ℕ | d.sum (λ _, id) = i }) :=
begin
rw [homogenous_submodule_eq_finsupp_supported, finsupp.supported_eq_span_single],
refl,
end
#print submodule.span_induction
@[elab_as_eliminator, elab_strategy]
theorem submodule.span_induction {R : Type*} {M : Type*} [_inst_1 : semiring R]
[_inst_2 : add_comm_monoid M] [_inst_5 : module R M] {x : M}
{s : set M} {p : M → Prop}
(hx : x ∈ submodule.span R s)
(h0 : p 0)
(hadd : ∀ (a : R) (x y : M), x ∈ s → y ∈ submodule.span R s → p y → p (a • x + y)) : p x :=
sorry
lemma is_homogeneous.induction_on'
{p : mv_polynomial σ R → Prop}
(hmonomial : ∀ d r, p (monomial d r))
(hadd : ∀ j (a b : mv_polynomial σ R),
a.is_homogeneous j → b.is_homogeneous j → p a → p b → p (a + b))
{x : mv_polynomial σ R} {i : ℕ} (hx : x.is_homogeneous i)
: p x :=
begin
let p_submonoid : add_submonoid (mv_polynomial σ R) :=
{ carrier := { x | x.is_homogeneous i ∧ p x },
add_mem' := λ a b ⟨ha, pa⟩ ⟨hb, pb⟩, ⟨ha.add hb, hadd i a b ha hb pa pb⟩,
zero_mem' := ⟨is_homogeneous_zero _ _ _, by simpa using hmonomial 0 0⟩ },
suffices : x ∈ p_submonoid, { exact and.right this },
rw ←finsupp.sum_single x,
apply add_submonoid.finsupp_sum_mem,
intros d hd,
exact ⟨is_homogeneous_monomial _ _ _ (hx hd), hmonomial _ _⟩,
end
#print submodule.span_induction
/-- To prove a property `p` on all homogenous polynomials, it suffices to prove it for monomials
and their summations. -/
lemma is_homogeneous.induction_on'
{p : mv_polynomial σ R → Prop}
(hmonomial : ∀ d r, p (monomial d r))
(hadd : ∀ j (a b : mv_polynomial σ R), a.is_homogeneous j → b.is_homogeneous j → p a → p b → p (a + b))
{x : mv_polynomial σ R} {i : ℕ} (hx : x.is_homogeneous i)
: p x :=
begin
rw [←mem_homogeneous_submodule, homogeneous_submodule_eq_span_monomial] at hx,
suffices : p x ∧ x.is_homogeneous i,
{ exact this.1 },
apply submodule.span_induction hx,
{ rintros xi ⟨d, hd, rfl⟩,
admit },
{ admit },
sorry, --oops
sorry, --oops
end
end mv_polynomial
end mv_polynomial
#exit
eval main
import order.complete_lattice
import data.set.intervals.basic
import data.fin
open set
example {X : Type*} [partial_order X] (x y : X) :
(Ico y x = {y}) ↔ (∀ z, y < z ↔ x ≤ z) :=
begin
simp only [set.eq_singleton_iff_unique_mem,
set.mem_Ico, le_refl, true_and, and_imp],
split,
{ assume h z,
split,
{ assume hyz,
have := h.2 z (le_of_lt hyz),
admit
},
{ assume hxz,
refine lt_of_le_of_ne _ _,
{ } }
}
end
universe u
open set
variables (X : Type u) [complete_lattice X]
structure composition_series : Type u :=
(length : ℕ)
(series : fin length.succ → X)
-- (zero : series 0 = ⊥)
-- (last : series (fin.last length) = ⊤)
(step : ∀ i : fin length, Ico (series i.cast_succ) (series i.succ) = {series i.cast_succ})
-- /- Make composition series a list on an interval -/
-- #print list.chain'
-- structure composition_series' : Type u :=
-- (l : list X)
-- ()
namespace composition_series
instance : has_coe_to_fun (composition_series X) :=
{ F := _, coe := composition_series.series }
variables {X}
theorem lt_succ (s : composition_series X) (i : fin s.length) :
s i.cast_succ < s i.succ :=
(mem_Ico.1 (eq_singleton_iff_unique_mem.1 (s.step i)).1).2
protected theorem strict_mono (s : composition_series X) : strict_mono s :=
fin.strict_mono_iff_lt_succ.2 (λ i h, s.lt_succ ⟨i, nat.lt_of_succ_lt_succ h⟩)
protected theorem injective (s : composition_series X) : function.injective s :=
s.strict_mono.injective
@[simp] protected theorem eq_iff (s : composition_series X) {i j : fin s.length.succ} :
s i = s j ↔ i = j :=
s.injective.eq_iff
@[simps] def erase_top (s : composition_series X) : composition_series X :=
{ length := s.length - 1,
series := λ i, s ⟨i, lt_of_lt_of_le i.2 (nat.succ_le_succ (nat.sub_le_self _ _))⟩,
step := λ i, begin
have := s.step ⟨i, lt_of_lt_of_le i.2 (nat.sub_le_self _ _)⟩,
cases i,
exact this
end }
def fin.cast_add_right {}
@[simps] def append (s₁ s₂ : composition_series X)
(h : s₁ (fin.last _) = s₂ 0) : composition_series X :=
{ length := s₁.length + s₂.length,
series := fin.append (nat.add_succ _ _).symm (s₁ ∘ fin.cast_succ) s₂,
step := λ i, begin
end }
lemma last_erase_top (s : composition_series X) :
s.erase_top (fin.last _) = s (fin.cast_succ (fin.last (s.length - 1))) :=
show s _ = s _, from congr_arg s
begin
ext,
simp only [erase_top_length, fin.coe_last, fin.coe_cast_succ, fin.coe_of_nat_eq_mod,
fin.coe_mk, coe_coe],
rw [nat.mod_eq_of_lt (lt_of_le_of_lt (nat.sub_le_self _ _) (nat.lt_succ_self _))],
end
-- theorem subsingleton_iff_length_eq_zero (s : composition_series X) :
-- subsingleton X ↔ s.length = 0 :=
-- begin
-- erw [← subsingleton_iff_bot_eq_top, ← s.zero, ← s.last, s.eq_iff, fin.ext_iff],
-- simp [eq_comm]
-- end
variables (r : (X × X) → (X × X) → Prop)
def equivalence (s₁ s₂ : composition_series X) : Type* :=
{ f : fin s₁.length ≃ fin s₂.length //
∀ i : fin s₁.length, r (s₁ i, s₁ i.succ) (s₂ (f i), s₂ (f i).succ) }
namespace equivalence
variables [is_equiv _ r]
@[refl] def refl (s : composition_series X) : equivalence r s s :=
⟨equiv.refl _, λ _, is_refl.reflexive _⟩
@[symm] def symm {s₁ s₂ : composition_series X} (h : equivalence r s₁ s₂) :
equivalence r s₂ s₁ :=
⟨h.1.symm, λ i, is_symm.symm _ _ (by simpa using h.2 (h.1.symm i))⟩
@[trans] def trans {s₁ s₂ s₃ : composition_series X}
(h₁ : equivalence r s₁ s₂)
(h₂ : equivalence r s₂ s₃) :
equivalence r s₁ s₃ :=
⟨h₁.1.trans h₂.1, λ i, is_trans.trans _ _ _ (h₁.2 i) (h₂.2 (h₁.1 i))⟩
lemma append
end equivalence
@[elab_as_eliminator, elab_strategy]
def fin.last_cases {n : ℕ} {C : fin n.succ → Sort*}
(hlast : C (fin.last n)) (hcast : (Π (i : fin n), C i.cast_succ)) (i : fin n.succ) : C i :=
if hi : i = fin.last _
then cast (by rw hi) hlast
else have hi : i = fin.cast_succ ⟨i, lt_of_le_of_ne (nat.le_of_lt_succ i.2)
(λ h, hi (fin.ext h))⟩, from fin.ext rfl,
cast (by rw hi) (hcast _)
@[simp] lemma fin.last_cases_last {n : ℕ} {C : fin n.succ → Sort*}
(hlast : C (fin.last n)) (hcast : (Π (i : fin n), C i.cast_succ)) :
(fin.last_cases hlast hcast (fin.last n): C (fin.last n)) = hlast :=
by simp [fin.last_cases]
@[simp] lemma fin.last_cases_cast_succ {n : ℕ} {C : fin n.succ → Sort*}
(hlast : C (fin.last n)) (hcast : (Π (i : fin n), C i.cast_succ)) (i : fin n) :
(fin.last_cases hlast hcast (fin.cast_succ i): C (fin.cast_succ i)) = hcast i :=
begin
simp only [fin.last_cases, dif_neg (ne_of_lt (fin.cast_succ_lt_last i)), cast_eq],
congr,
simp,
end
lemma equivalent_of_erase_top_equivalent {s₁ s₂ : composition_series X}
(h0₁ : 0 < s₁.length) (h0₂ : 0 < s₂.length)
(htop : s₁ (fin.last _) = s₂ (fin.last _))
(h : equivalence r s₁.erase_top s₂.erase_top)
(htop_erase_top : s₁.erase_top (fin.last _) = s₂.erase_top (fin.last _)) :
equivalence r s₁ s₂ :=
let f : fin (s₁.length - 1) ≃ fin (s₂.length - 1) :=
⟨_,
begin
intros i j hij,
refine fin.last_cases _ _ j,
end⟩
theorem jordan_hoelder (s₁ s₂ : composition_series X)
(h0 : s₁ 0 = s₂ 0) (hl : s₁ (fin.last _) = s₂ (fin.last _))
: equivalent r s₁ s₂ :=
begin
induction hl : s₁.length with n ih generalizing s₁ s₂,
{ admit
-- haveI hs : subsingleton X,
-- { rw [subsingleton_iff_length_eq_zero, hl] },
-- have : s₁.length = s₂.length,
-- { rw [hl, eq_comm, ← subsingleton_iff_length_eq_zero,
-- s₁.subsingleton_iff_length_eq_zero, hl] },
-- use this,
-- intros i j hij,
-- have : ∀ x : X, x = s₁ i, from λ _, subsingleton.elim _ _,
-- rw [this (s₁ j), this (s₂ _), this (s₂ _)],
-- exact is_refl.reflexive _
},
{ let H := s₁.erase_top (fin.last _),
let K := s₂.erase_top (fin.last _),
by_cases hHK : H = K,
{ }
}
end
-- (second_iso : ∀ h k, r (h ⊔ k, k) (h, h ⊓ k))
-- (hIco : ∀ g h k : X, Ico h g = {h} → Ico k g = {k} → Ico (h ⊓ k) h = {h ⊓ k})
#exit
import algebra.char_p.basic
import tactic.ring
variables {R : Type} [comm_ring R] [char_p R 7]
@[simp] lemma ring_char_eq : ring_char R = 7 :=
eq.symm $ ring_char.eq _ (by assumption)
@[simp] lemma seven_eq_zero : (7 : R) = 0 :=
calc (7 : R) = (7 : ℕ) : by simp
... = 0 : char_p.cast_eq_zero _ _
@[simp] lemma bit0bit0bit0 (n : R) : (bit0 $ bit0 $ bit0 n) = n :=
calc (bit0 $ bit0 $ bit0 n) = 7 * n + n : by delta bit0; ring
... = n : by simp
@[simp] lemma bit0bit0bit1 (n : R) : (bit0 $ bit0 $ bit1 n) = n + 4 :=
calc (bit0 $ bit0 $ bit1 n) = 7 * n + n + 4 : by delta bit0 bit1; ring
... = _ : by simp
@[simp] lemma bit0bit1bit0 (n : R) : (bit0 $ bit1 $ bit0 n) = n + 2 :=
calc (bit0 $ bit1 $ bit0 n) = 7 * n + n + 2 : by delta bit0 bit1; ring
... = _ : by simp
@[simp] lemma bit0bit1bit1 (n : R) : (bit0 $ bit1 $ bit1 n) = n + 6 :=
calc (bit0 $ bit1 $ bit1 n) = 7 * n + n + 6 : by delta bit0 bit1; ring
... = _ : by simp
@[simp] lemma bit1bit0bit0 (n : R) : (bit1 $ bit0 $ bit0 n) = n + 1 :=
calc (bit1 $ bit0 $ bit0 n) = 7 * n + n + 1 : by delta bit0 bit1; ring
... = _ : by simp
@[simp] lemma bit1bit0bit1 (n : R) : (bit1 $ bit0 $ bit1 n) = n + 5 :=
calc (bit1 $ bit0 $ bit1 n) = 7 * n + n + 5 : by delta bit0 bit1; ring
... = _ : by simp
@[simp] lemma bit1bit1bit0 (n : R) : (bit1 $ bit1 $ bit0 n) = n + 3 :=
calc (bit1 $ bit1 $ bit0 n) = 7 * n + n + 3 : by delta bit0 bit1; ring
... = _ : by simp
@[simp] lemma bit1bit1bit1 (n : R) : (bit1 $ bit1 $ bit1 n) = n :=
calc (bit1 $ bit1 $ bit1 n) = 7 * n + n + 7: by delta bit0 bit1; ring
... = _ : by simp
@[simp] lemma bit0_add_bit0 (n m : R) : bit0 n + bit0 m = bit0 (n + m) :=
by delta bit0 bit1; ring
@[simp] lemma bit0_add_bit1 (n m : R) : bit0 n + bit1 m = bit1 (n + m) :=
by delta bit0 bit1; ring
@[simp] lemma bit1_add_bit0 (n m : R) : bit1 n + bit0 m = bit1 (n + m) :=
by delta bit0 bit1; ring
@[simp] lemma bit1_add_bit1 (n m : R) : bit1 n + bit1 m = bit1 (n + m) + 1 :=
by delta bit0 bit1; ring
@[simp] lemma bit0_add_one (n : R) : bit0 n + 1 = bit1 n :=
by delta bit0 bit1; ring
@[simp] lemma three_add_one : (3 : R) + 1 = 4 :=
by delta bit0 bit1; ring
@[simp] lemma one_add_one : (1 : R) + 1 = 2 :=
by delta bit0 bit1; ring
@[simp] lemma bit1bit0_add_one (n : R) : bit1 (bit0 n) + 1 = bit0 (bit1 n) :=
by delta bit0 bit1; ring
@[simp] lemma bit1bit1_add_one (n : R) : bit1 (bit1 n) + 1 = bit0 (bit0 (n + 1)) :=
by delta bit0 bit1; ring
@[simp] lemma one_add_bit0 (n : R) : 1 + bit0 n = bit1 n :=
by delta bit0 bit1; ring
@[simp] lemma one_add_bit1bit0 (n : R) : 1 + bit1 (bit0 n) = bit0 (bit1 n) :=
by delta bit0 bit1; ring
@[simp] lemma one_add_bit1bit1 (n : R) : 1 + bit1 (bit1 n) = bit0 (bit0 (n + 1)) :=
by delta bit0 bit1; ring
@[simp] lemma one_add_three : (1 : R) + 3 = 4 :=
by delta bit0 bit1; ring
set_option trace.simplify.rewrite true
example : (145903 : R) = 2 :=
begin
simp,
end
#exit
import group_theory.perm.cycles
open string equiv.perm tactic equiv
run_cmd
do
"c[1, 4, 3, 2]" ← pure (repr (1 : ℕ)),
pure ()
variables {A : Type*} [add_comm_group A] (n m k : ℤ) (a b c : A)
example : (n + m) • a = n • a + m • a :=
by abel -- fails
example : (5 : ℤ) • a + a = (6 : ℤ) • a :=
by abel -- works
example : (5 : ℤ) • a + a = (6 : ℕ) • a :=
by abel -- fails
example : (5 + 4 : ℤ) • a + a = (10 : ℤ) • a :=
by abel -- works
example : (5 + 3 + 1 : ℤ) • a + a = (10 : ℤ) • a :=
by abel -- works
#print norm_num.eval_field
#exit
import data.list.basic
variables {A : Type} (op : A → A → A)
#reduce
let x : ℕ := (list.range 10000).nth_le 0 sorry in
1
#exit
import group_theory.subgroup
import group_theory.free_group
universes u v
def fintype' : Type* → Type* := id
def fintype'.card {α : Type u} [fintype' α] : Type u := α
set_option pp.universes true
variables {G : Type u} [group G]
def X : has_coe_to_sort (subgroup G) := by apply_instance
#print set_like.has_coe_to_sort
@[simp, to_additive] lemma card_bot {h : fintype' (⊤ : subgroup G)} : ℕ :=
0
#exit
import data.nat.totient
import data.zmod.basic
import group_theory.order_of_element
lemma pow_eq_pow_mod_card {G : Type*} [group G] [fintype G] (a : G) (n : ℕ) :
a ^ n = a ^ (n % fintype.card G) :=
by rw [pow_eq_mod_order_of, @pow_eq_mod_order_of _ _ _ (_ % fintype.card G),
nat.mod_mod_of_dvd _ order_of_dvd_card_univ]
lemma pow_eq_pow_mod_totient {n : ℕ} (a : units (zmod n)) (k : ℕ) :
a ^ k = a ^ (k % nat.totient n) :=
if hn0 : n = 0
then by simp [hn0]
else by { haveI : fact (0 < n) := fact.mk (nat.pos_of_ne_zero hn0),
rw [pow_eq_pow_mod_card a k, zmod.card_units_eq_totient] }
lemma pow_mod_eq_pow_mod_totient {n : ℕ} (a k : ℕ) (han : nat.coprime a n) :
(a ^ k) % n = (a ^ (k % nat.totient n)) % n :=
(zmod.eq_iff_modeq_nat n).1 begin
rw [nat.cast_pow, nat.cast_pow, ← zmod.coe_unit_of_coprime a han,
← units.coe_pow, ← units.coe_pow, pow_eq_pow_mod_totient],
end
lemma nat.totient_eq_list_range (n : ℕ) :
nat.totient n = ((list.range n).filter (nat.coprime n)).length :=
begin
rw [nat.totient, ← list.erase_dup_eq_self.2 (list.nodup_filter _ (list.nodup_range n)),
← list.card_to_finset],
refine congr_arg finset.card _,
ext,
simp,
end
def prod_zmod_one_equiv (R : Type*) [semiring R] : R ≃+* R × zmod 1 :=
{ to_fun := λ x, (x, 0),
inv_fun := prod.fst,
map_add' := by intros; ext; simp; congr,
map_mul' := by intros; ext; simp; congr,
left_inv := λ x, rfl,
right_inv := λ x, by apply prod.ext; simp; congr }
def zmod_one_prod_equiv (R : Type*) [semiring R] : R ≃+* zmod 1 × R :=
{ to_fun := λ x, (0, x),
inv_fun := prod.snd,
map_add' := by intros; ext; simp; congr,
map_mul' := by intros; ext; simp; congr,
left_inv := λ x, rfl,
right_inv := λ x, by apply prod.ext; simp; congr }
local attribute [instance] zmod.char_p
def chinese_remainder (m n : ℕ) (h : m.coprime n) :
zmod (m * n) ≃+* zmod m × zmod n :=
if hmn0 : m * n = 0
then if hm1 : m = 1
then begin
rw [hm1, one_mul],
exact zmod_one_prod_equiv _
end
else have hn1 : n = 1,
begin
rw [nat.mul_eq_zero] at hmn0,
rcases hmn0 with ⟨rfl, rfl⟩;
simp [*, fact_iff] at *,
end,
begin
rw [hn1, mul_one],
exact prod_zmod_one_equiv _
end
else
by haveI : fact (0 < (m * n)) := fact.mk (nat.pos_of_ne_zero hmn0);
haveI : fact (0 < m) := fact.mk (nat.pos_of_ne_zero $ λ h, by simp [fact_iff, *] at *);
haveI : fact (0 < n) := fact.mk (nat.pos_of_ne_zero $ λ h, by simp [fact_iff, *] at *);
exact
{ to_fun := λ x, (zmod.cast_hom (dvd_mul_right _ _) _ x, zmod.cast_hom (dvd_mul_left _ _) _ x),
inv_fun := λ x, nat.modeq.chinese_remainder h x.1.val x.2.val,
map_mul' := λ _ _, by ext; simp only [ring_hom.map_mul]; refl,
map_add' := λ _ _, by ext; simp only [ring_hom.map_add]; refl,
left_inv := λ x, begin
conv_rhs { rw ← zmod.nat_cast_zmod_val x },
dsimp,
rw [zmod.eq_iff_modeq_nat, ← nat.modeq.modeq_and_modeq_iff_modeq_mul h],
refine
⟨(subtype.property (nat.modeq.chinese_remainder h (x : zmod m).val (x : zmod n).val)).1.trans _,
(subtype.property (nat.modeq.chinese_remainder h (x : zmod m).val (x : zmod n).val)).2.trans _⟩,
rw [← zmod.eq_iff_modeq_nat, zmod.nat_cast_zmod_val, zmod.nat_cast_val],
rw [← zmod.eq_iff_modeq_nat, zmod.nat_cast_zmod_val, zmod.nat_cast_val],
end,
right_inv := λ x,
begin
haveI : fact (0 < (m * n)) := fact.mk (nat.pos_of_ne_zero hmn0),
haveI : fact (0 < m) := fact.mk (nat.pos_of_ne_zero $ λ h, by simp [fact_iff, *] at *),
haveI : fact (0 < n) := fact.mk (nat.pos_of_ne_zero $ λ h, by simp [fact_iff, *] at *),
ext,
{ conv_rhs { rw ← zmod.nat_cast_zmod_val x.1 },
dsimp,
rw [@zmod.cast_nat_cast _ (zmod m) _ _ _ (dvd_mul_right _ _)],
rw [zmod.eq_iff_modeq_nat],
exact (nat.modeq.chinese_remainder h _ _).2.1,
apply_instance },
{ conv_rhs { rw ← zmod.nat_cast_zmod_val x.2 },
dsimp,
rw [@zmod.cast_nat_cast _ (zmod n) _ _ _ (dvd_mul_left _ _)],
rw [zmod.eq_iff_modeq_nat],
exact (nat.modeq.chinese_remainder h _ _).2.2,
apply_instance }
end }
lemma totient_mul (m n : ℕ) (h : m.coprime n) : nat.totient (m * n) =
nat.totient m * nat.totient n :=
if hmn0 : m * n = 0
then by finish
else
begin
haveI : fact (0 < m * n) := fact.mk (nat.pos_of_ne_zero hmn0),
haveI : fact (0 < m) := fact.mk (nat.pos_of_ne_zero $ λ h, by simp [fact_iff, *] at *),
haveI : fact (0 < n) := fact.mk (nat.pos_of_ne_zero $ λ h, by simp [fact_iff, *] at *),
rw [← zmod.card_units_eq_totient, ← zmod.card_units_eq_totient,
← zmod.card_units_eq_totient],
rw [fintype.card_congr (units.map_equiv (chinese_remainder _ _ h).to_mul_equiv).to_equiv],
rw [fintype.card_congr (@mul_equiv.prod_units (zmod m) (zmod n) _ _).to_equiv],
rw [fintype.card_prod]
end
lemma nat.coprime_pow_left_iff (a b : ℕ) {n : ℕ} (hn : 0 < n) :
nat.coprime (a ^ n) b ↔ nat.coprime a b :=
begin
cases n with n,
{ exact (lt_irrefl _ hn).elim },
{ rw [pow_succ, nat.coprime_mul_iff_left],
exact iff.intro and.left (λ hab, ⟨hab, nat.coprime.pow_left _ hab⟩) }
end
lemma totient_prime_pow {p : ℕ} (hp : p.prime) (n : ℕ) :
nat.totient (p ^ (n + 1)) = p ^ n * (p - 1) :=
calc nat.totient (p ^ (n + 1))
= ((finset.range (p ^ (n + 1))).filter (nat.coprime (p ^ (n + 1)))).card : rfl
... = (finset.range (p ^ (n + 1)) \ ((finset.range (p ^ n)).image (* p))).card :
congr_arg finset.card begin
rw [finset.sdiff_eq_filter],
apply finset.filter_congr,
simp only [finset.mem_range, finset.mem_filter, nat.coprime_pow_left_iff _ _ (nat.succ_pos n),
finset.mem_image, not_exists, hp.coprime_iff_not_dvd],
intros a ha,
split,
{ rintros hap b _ rfl,
exact hap (dvd_mul_left _ _) },
{ rintros h ⟨b, rfl⟩,
rw [pow_succ] at ha,
exact h b (lt_of_mul_lt_mul_left ha (nat.zero_le _)) (mul_comm _ _) }
end
... = _ :
have h1 : set.inj_on (* p) (finset.range (p ^ n)),
from λ x _ y _, (nat.mul_left_inj hp.pos).1,
have h2 : (finset.range (p ^ n)).image (* p) ⊆ finset.range (p ^ (n + 1)),
from λ a, begin
simp only [finset.mem_image, finset.mem_range, exists_imp_distrib],
rintros b h rfl,
rw [pow_succ'],
exact (mul_lt_mul_right hp.pos).2 h
end,
begin
rw [finset.card_sdiff h2, finset.card_image_of_inj_on h1, finset.card_range,
finset.card_range, ← one_mul (p ^ n), pow_succ, ← nat.mul_sub_right_distrib,
one_mul, mul_comm]
end
lemma totient_prime {p : ℕ} (hp : p.prime) : nat.totient p = p - 1 :=
by conv_lhs { rw [← pow_one p, totient_prime_pow hp, pow_zero, one_mul] }
namespace tactic.interactive
meta def totient_tac : tactic unit :=
`[simp only [nat.totient_eq_list_range],
delta nat.coprime,
dsimp only [list.range, list.range_core],
dsimp only [list.filter],
norm_num]
end tactic.interactive
lemma totient_1000000 : nat.totient 1000000 = 400000 :=
calc nat.totient 1000000 = nat.totient (5 ^ 6 * 2 ^ 6) :
congr_arg nat.totient (by norm_num)
... = 400000 : begin
rw [totient_mul, totient_prime_pow, totient_prime_pow];
try {delta nat.coprime}; norm_num
end
lemma totient_400000 : nat.totient 400000 = 160000 :=
calc nat.totient 400000 = nat.totient (2 ^ 7 * 5 ^ 5) :
congr_arg nat.totient (by norm_num)
... = 160000 : begin
rw [totient_mul, totient_prime_pow, totient_prime_pow];
try {delta nat.coprime}; norm_num
end
lemma totient_160000 : nat.totient 160000 = 64000 :=
calc nat.totient 160000 = nat.totient (2 ^ 8 * 5 ^ 4) :
congr_arg nat.totient (by norm_num)
... = 64000 : begin
rw [totient_mul, totient_prime_pow, totient_prime_pow];
try {delta nat.coprime}; norm_num,
end
lemma totient_64000 : nat.totient 64000 = 25600 :=
calc nat.totient 64000 = nat.totient (2 ^ 9 * 5 ^ 3) :
congr_arg nat.totient (by norm_num)
... = 25600 :
begin
rw [totient_mul, totient_prime_pow, totient_prime_pow];
try {delta nat.coprime}; norm_num,
end
lemma totient_25600 : nat.totient 25600 = 10240 :=
calc nat.totient 25600 = nat.totient (2 ^ 10 * 5 ^ 2) :
congr_arg nat.totient (by norm_num)
... = 10240 :
begin
rw [totient_mul, totient_prime_pow, totient_prime_pow];
try {delta nat.coprime}; norm_num,
end
lemma totient_10240 : nat.totient 10240 = 4096 :=
calc nat.totient 10240 = nat.totient (2 ^ 11 * 5) :
congr_arg nat.totient (by norm_num)
... = 4096 :
begin
rw [totient_mul, totient_prime_pow, totient_prime];
try {delta nat.coprime}; norm_num,
end
def pow_mod (a b c : ℕ) : ℕ := (a ^ b) % c
lemma pow_mod_bit0 (a b c : ℕ) :
pow_mod a (bit0 b) c = pow_mod a b c ^ 2 % c :=
by rw [pow_mod, pow_mod, pow_two, bit0, pow_add, nat.mul_mod],
lemma pow_mod_bit1 (a b c : ℕ) :
pow_mod a (bit1 b) c = (pow_mod a b c ^ 2 % c * a % c) % c :=
begin
rw [bit1, bit0, pow_mod, pow_add, ← pow_mod, nat.mul_mod, ← pow_mod,
← bit0, pow_mod_bit0, pow_one, nat.mod_mod, pow_mod, pow_mod],
conv_rhs { rw nat.mul_mod },
rw [nat.mod_mod]
end
lemma pow_mod_one (a c : ℕ) :
pow_mod a 1 c = a % c :=
by simp [pow_mod]
def seven_sevens_mod : (7 ^ 7 ^ 7 ^ 7 ^ 7 ^ 7 ^ 7) % 1000000 = 172343 :=
begin
rw [pow_mod_eq_pow_mod_totient, totient_1000000,
@pow_mod_eq_pow_mod_totient 400000, totient_400000,
@pow_mod_eq_pow_mod_totient 160000, totient_160000,
@pow_mod_eq_pow_mod_totient 64000, totient_64000,
@pow_mod_eq_pow_mod_totient 25600, totient_25600,
@pow_mod_eq_pow_mod_totient 10240, totient_10240],
repeat { rw [← pow_mod] },
norm_num [pow_mod_bit0, pow_mod_bit1, pow_mod_one],
all_goals { delta nat.coprime, norm_num }
end
#print axioms seven_sevens_mod
#exit
import data.nat.fib
import data.real.sqrt
import tactic
open nat real
lemma fib_formula : ∀ n : ℕ,
(((1 + real.sqrt 5) / 2) ^ n - ((1 - sqrt 5) / 2) ^ n) / sqrt 5 = fib n
| 0 := by simp
| 1 := begin
have hs : real.sqrt 5 ≠ 0, by norm_num,
field_simp [hs],
ring,
end
| (n+2) := begin
have hs : real.sqrt 5 ≠ 0, { norm_num },
have hsq : real.sqrt 5 ^ 2 = 5, { norm_num },
have hsq3 : real.sqrt 5 ^ 3 = real.sqrt 5 * 5, { rw [pow_succ, hsq] },
have hsq4 : real.sqrt 5 ^ 4 = 1 + 24 - 1 + 5 - 4, { rw [pow_bit0, hsq], norm_num },
rw [fib_succ_succ, nat.cast_add, ← fib_formula, ← fib_formula],
field_simp [hs],
ring_exp,
rw [hsq, hsq3, hsq4],
ring
end
#exit
import data.int.basic
inductive poly
| C : ℤ → poly
| X : poly
| add : poly → poly → poly
| mul : poly → poly → poly
open poly
instance : has_add poly := ⟨poly.add⟩
instance : has_mul poly := ⟨poly.mul⟩
instance : has_one poly := ⟨C 1⟩
instance : has_zero poly := ⟨C 0⟩
instance : has_coe ℤ poly := ⟨C⟩
instance : has_pow poly ℕ := ⟨λ p n, nat.rec_on n 1 (λ n q, nat.cases_on n p (λ m, p * q))⟩
/-- Remove leading zeroes from a list -/
def erase_zeroes : list ℤ → list ℤ
| [] := []
| m@(a :: l) := if a = 0 then erase_zeroes l else m
-- add_list_aux l₁ l₂ r returns ((reverse l₁ + reverse l₂) ++ r)
def add_list_aux :
list ℤ →
list ℤ →
list ℤ →
list ℤ
| [] [] r := r
| (a::l) [] r := add_list_aux l [] (a::r)
| [] (a::l) r := add_list_aux [] l (a::r)
| (a::l₁) (b::l₂) r := add_list_aux l₁ l₂ ((a + b) :: r)
def add_list (l₁ l₂ : list ℤ) :=
erase_zeroes (add_list_aux l₁.reverse l₂.reverse [])
def mul_list : list ℤ → list ℤ → list ℤ
| [] l := []
| (a::l₁) l₂ :=
add_list (l₂.map (*a) ++ list.repeat 0 l₁.length) (mul_list l₁ l₂)
def poly_to_list : poly → list ℤ
| (C n) := if n = 0 then [] else [n]
| X := [1, 0]
| (add p q) := add_list (poly_to_list p) (poly_to_list q)
| (mul p q) := mul_list (poly_to_list p) (poly_to_list q)
instance : has_repr poly := ⟨repr ∘ poly_to_list⟩
/- Multiples of (X - a) form an ideal -/
def mults_is_ideal_zero (a : ℤ) : poly × poly := (0, 0)
def mults_is_ideal_add (a : ℤ) (f fdiv g gdiv : poly) : poly × poly :=
(f + g, fdiv + gdiv)
def mults_is_ideal_smul (a : ℤ) (f g gdiv : poly) : poly × poly :=
(f * g, f * gdiv)
def ring_hom_well_defined_on_quotient
(I : poly → Type) (I0 : I 0)
(Iadd : Π p q, I p → I q → I (p + q))
(Ismul : Π p q, I q → I (p * q))
def mod_div (a : ℤ) : poly → ℤ × poly
| (C n) := (n, 0)
| X := (a, 1)
| (add p q) :=
let (np, Pp) := mod_div p in
let (nq, Pq) := mod_div q in
-- p = Pp * (X - a) + np
-- q = Pq * (X - a) + nq
-- So p + q = (Pp + Pq) * (X - a) + (np + nq)
(np + nq, Pp + Pq)
| (mul p q) :=
let (np, Pp) := mod_div p in
let (nq, Pq) := mod_div q in
-- p = Pp * (X - a) + np
-- q = Pq * (X - a) + nq
-- p * q = (Pp * Pq * (X - a) + np * Pq + nq * Pp) * (X - a) + (np + nq)
(np + nq, Pp * Pq * (X + C (-a)) + np * Pq + nq * Pp)
#eval mod_div (-1) (X * X + 2 * X + 1)
#exit
import data.list.perm
variables {α : Type*} [decidable_eq α] {l₁ l₂ : list α}
#eval list.permutations [1,2,3,0]
lemma X {α : Type} (a : α) (l : list α) : list.permutations (l ++ [a]) =
l.permutations.bind (λ l, (list.range l.length.succ).map (λ n, l.insert_nth n a)) := sorry
#print list.permutations_aux2
lemma permutations_cons {α : Type} (a : α) (l : list α) :
list.permutations (a :: l) ~ l.permutations.bind
(λ l, (list.range l.length.succ).map (λ n, l.insert_nth n a)) :=
begin
unfold list.permutations,
end
#eval let l := [1,2,3] in let a := 0 in
(list.permutations (l ++ [a]) =
l.permutations.bind (λ l, (list.range l.length.succ).map (λ n, l.insert_nth n a)) : bool)
#exit
ariables (P : Prop) (R : P → P → Prop) (α : Type) (f : P → α)
(H : ∀ x y, R x y → f x = f y) (q : quot R) (h : P)
example : q = quot.mk R h := rfl
#print task
#print task.
local attribute [semireducible] reflected
run_cmd tactic.add_decl (declaration.thm `exmpl []
`(∀ (P : Prop) (R : P → P → Prop) (α : Type) (f : P → α)
(H : ∀ x y, R x y → f x = f y) (q : quot R) (h : P),
quot.lift f H q = quot.lift f H (quot.mk R h))
(task.pure `(λ (P : Prop) (R : P → P → Prop) (α : Type) (f : P → α)
(H : ∀ x y, R x y → f x = f y) (q : quot R) (h : P),
eq.refl (quot.lift f H q))))
example : quot.lift f H q = quot.lift f H (quot.mk R h) := rfl
#exit
import data.polynomial.field_division
import data.real.liouville
lemma roots_derivative : ∀ (f : polynomial ℝ),
f.roots.to_finset.card = f.derivative.roots.to_finset.card + 1
| f :=
if hfe : f.roots.to_finset = ∅
then by simp [hfe]
else begin
cases finset.nonempty_of_ne_empty hfe with a ha,
have hf0 : f ≠ 0, from λ hf0, by simp * at *,
rw [multiset.mem_to_finset, mem_roots hf0, ← dvd_iff_is_root] at ha,
rcases ha with ⟨g, rfl⟩,
rw [derivative_mul, derivative_sub, derivative_X, derivative_C,
sub_zero, one_mul, roots_mul hf0, roots_X_sub_C, multiset.to_finset_add],
simp,
end
def f (n : ℕ) (h : acc (>) n) : unit :=
acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n)) h
-- notation `t1 ` := f 0 a
-- def t2 (a : acc (>) 0) : unit := acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n)) a
-- def t3 (a : acc (>) 0) : unit := acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n))
-- (acc.inv a (nat.lt_succ_self 0))
example (a : acc (>) 0) :
f 0 a
= (acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n)) a : unit) :=
rfl
example (a : acc (>) 0) :
(acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n))
(acc.intro 0 (λ y hy, acc.inv a hy)) : unit)
= acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n))
(acc.inv a (nat.lt_succ_self 0)) :=
rfl
example (a : acc (>) 0) :
f 0 a
= acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n))
(acc.inv a (nat.lt_succ_self 0)) := rfl
inductive X (a : acc (>) 0) : unit → Type
| mk (u : unit) : X u
example (a : acc (>) 0) :
X a (f 0 a)
= X a (acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n)) a : unit) :=
rfl
#check λ a : acc (>) 0, @id
(X a (acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n))
(acc.intro 0 (λ y hy, acc.inv a hy))))
(X.mk (acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n))
(acc.inv a (nat.lt_succ_self 0))))
#check λ a : acc (>) 0,
-- @id (X a (f 0 a))
(@id (X a ((acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n)) a)))
(X.mk (acc.rec (λ n _ g, g (n + 1) (nat.lt_succ_self n))
(acc.inv a (nat.lt_succ_self 0)))))
variables {A : Type}
def T (A : Type) : A → A → Prop := λ _ _, true
inductive B : quot (T A) → Type
| mk : Π a : A, B (quot.mk (T A) a)
#print funext
def f (a : quot (T A)) : B a :=
quot.lift (λ x, _) _ a
#exit
import data.complex.basic
open complex
lemma X : (2 : ℂ).im = 0 :=
begin
simp,
end
#print X
inductive term (L : signature) : ℕ → Type
| Var (v : L.Variables) : term 0
| Fun {n : ℕ} (f : L.funcs n) : term n
| App {n : ℕ} : term (n+1) → term 0 → term n
open subgroup
variables {G : Type*} {H : Type*} [group G] [group H]
example (p q : Prop) : (p → q) → (¬¬p → ¬¬q) :=
λ h hnp hq, hnp (λ hp, hq $ h hp)
example (p q r : Prop)
(h : ¬ ((p → q) ↔ r) ↔ (p → (q ↔ r))) : ¬p :=
begin
by_cases hp : p,
{ simp [hp] at h,
exact h.elim },
{ assumption }
end
example (p q r : Prop)
(h : ¬ ((p → q) ↔ r) ↔ (p → (q ↔ r))) : ¬r :=
begin
by_cases hr : r,
{ by_cases hp : p;
simp [hp, hr] at h;
contradiction },
{ assumption }
end
example (p q r : Prop) :
(¬(((p → q) ↔ r) ↔ (p → (q ↔ r)))) ↔ ¬p ∧ ¬r :=
⟨λ h, ⟨λ hp, h ⟨λ h _, ⟨λ hq, h.1 (λ _, hq), λ hr, h.2 hr hp⟩,
λ h2, ⟨λ hpq, (h2 hp).1 (hpq hp), λ hr _, (h2 hp).2 hr⟩⟩,
λ hr, h ⟨λ h2 hp, ⟨λ _, hr, λ _, h2.2 hr hp⟩,
λ h2, ⟨λ _, hr, λ _ hp, (h2 hp).2 hr⟩⟩⟩,
λ h h2, h.2 $ (h2.2 (λ hp, (h.1 hp).elim)).1 (λ hp, (h.1 hp).elim)⟩
lemma Z (h : ∀ (p q r : Prop),
(((p → q) ↔ r) ↔ (p → (q ↔ r))) ↔ p ∨ r) (p : Prop) : p ∨ ¬p :=
(h p true (¬ p)).1
⟨λ h hp, ⟨λ _, h.1 (λ _, trivial), λ _, trivial⟩,
λ h, ⟨λ _ hp, (h hp).1 trivial hp, λ _ _, trivial⟩⟩
lemma Z1 (h : ∀ (p q r : Prop),
(((p → q) ↔ r) ↔ (p → (q ↔ r))) ↔ p ∨ r) (p : Prop) : p ∨ ¬p :=
begin
have := h (¬ p) false p,
simp only [true_implies_iff, true_iff, true_or, iff_true, false_iff,
false_implies_iff, iff_false, false_or, imp_false] at this,
end
#print axioms Z
example : ¬ ((false → true) ↔ false) ↔ (false → (true ↔ false)) :=
begin
simp,
end
#exit
lemma commutative_of_cyclic_center_quotient [is_cyclic H] (f : G →* H)
(hf : f.ker ≤ center G) (a b : G) : a * b = b * a :=
begin
rcases is_cyclic.exists_generator f.range with ⟨⟨x, y, rfl⟩, hx⟩,
rcases hx ⟨f a, a, rfl⟩ with ⟨m, hm⟩,
rcases hx ⟨f b, b, rfl⟩ with ⟨n, hn⟩,
have hm : f y ^ m = f a, by simpa [subtype.ext_iff] using hm,
have hn : f y ^ n = f b, by simpa [subtype.ext_iff] using hn,
have ha : y ^ (-m) * a ∈ center G, from hf (f.mem_ker.2 (by group_rel [hm])),
have hb : y ^ (-n) * b ∈ center G, from hf (f.mem_ker.2 (by group_rel [hn])),
have this := mem_center_iff.1 ha (y ^ n),
have that := mem_center_iff.1 hb a,
group_rel [this, that],
end
#print commutative_of_cyclic_center_quotient
def comm_group_of_cycle_center_quotient [is_cyclic H] (f : G →* H)
(hf : f.ker ≤ center G) : comm_group G :=
{ mul_comm := commutative_of_cyclic_center_quotient f hf,
..show group G, by apply_instance }
#exit
import logic.function.iterate
import tactic
example {G : Type} [group G] (a b : G) :
(a * b * a⁻¹) * (a * b * a * b^2)⁻¹ * (a * b * a⁻¹)⁻¹ *
(b⁻¹ * a⁻¹) * (a * b * a * b^2) * (b⁻¹ * a⁻¹)⁻¹ = a * b * a⁻¹ * b⁻¹ :=
begin
simp [mul_assoc, pow_succ],
end
lemma F {G : Type} [group G] (a b c : G) (ha : a^2 = 1) (hb : b^3 = 1)
(hr : c * a * c⁻¹ = b) : a = 1 :=
begin
subst hr,
simp [pow_succ, mul_assoc] at *,
end
def h : (ℕ → bool) → bool × (ℕ → bool) :=
λ s, (s 0, s ∘ nat.succ)
variables {X : Type} (f : X → bool × X)
def UMP (x : X) (n : ℕ) : bool :=
(f ((prod.snd ∘ f)^[n] x)).1
lemma commutes : h ∘ UMP f = λ x, ((f x).1, (UMP f (f x).2)) :=
begin
ext,
{ simp [h, UMP] },
{ simp [h, UMP] }
end
lemma uniqueness (W : X → (ℕ → bool)) (hW : ∀ x, h (W x) = ((f x).1, (W (f x).2))) :
W = UMP f :=
begin
ext x n,
unfold UMP h at *,
simp only [prod.ext_iff, function.funext_iff, function.comp_apply] at hW,
induction n with n ih generalizing x,
{ simp [(hW x).1] },
{ simp [(hW x).2, ih] }
end
#exit
import data.list.basic
variables {α : Type*}
inductive count_at_least (a : α) : ℕ → list α → Prop
| nil : count_at_least 0 []
| cons_self {n l} : count_at_least n l → count_at_least (n + 1) (a :: l)
| cons {b n l} : count_at_least n l → count_at_least n (b :: l)
inductive duplicate (a : α) : list α → Prop
| cons_mem {l} : a ∈ l → duplicate (a :: l)
| cons_duplicate {b l} : duplicate l → duplicate (b :: l)
#exit
open nat
example (a b : ℕ) (h : succ a = succ b) : a = b :=
show a = @nat.rec (λ n, ℕ) 0 (λ n _, n) (succ b),
from h ▸ rfl
variables
(formula : Type)
(T_proves : formula → Prop)
(is_true : formula → formula)
(implies : formula → formula → formula)
(himplies : ∀ {φ ψ}, T_proves (implies φ ψ) → T_proves φ → T_proves ψ)
(and : formula → formula → formula)
(handl : ∀ {φ ψ}, T_proves (and φ ψ) → T_proves φ)
(handr : ∀ {φ ψ}, T_proves (and φ ψ) → T_proves ψ)
(false : formula)
(hcons : ¬ T_proves false)
(h1 : ∀ {φ}, T_proves φ → T_proves (is_true φ))
(h3 : ∀ {φ}, T_proves (is_true φ) → T_proves φ) -- Need Rosser's trick
(ρ : formula)
(hρ : T_proves (and (implies ρ (implies (is_true ρ) false))
(implies (implies ρ false) (is_true ρ))))
include formula T_proves is_true implies and false h1 h3 ρ hρ
lemma rho_not_is_true : ¬ T_proves ρ :=
assume h : T_proves ρ,
have T_proves_not_is_true_ρ : T_proves (implies (is_true ρ) false),
from himplies (handl hρ) h,
have T_proves_is_true_ρ : T_proves (is_true ρ),
from h1 h,
have T_proves_false : T_proves false,
from himplies T_proves_not_is_true_ρ T_proves_is_true_ρ,
hcons T_proves_false
lemma not_rho_not_is_true : ¬ T_proves (implies ρ false) :=
assume h : T_proves (implies ρ false),
have T_proves_is_true_ρ : T_proves (is_true ρ),
from himplies (handr hρ) h,
have T_proves_ρ : T_proves ρ,
from h3 T_proves_is_true_ρ,
have T_proves_false : T_proves false,
from himplies h T_proves_ρ,
hcons T_proves_false
#reduce not_rho_not_is_true
#exit
#eval quot.unquot ((finset.univ : finset (zmod 3 × zmod 3 × zmod 3)).filter
(λ x: (zmod 3 × zmod 3 × zmod 3), 5 * x.1^2 - 7 * x.2.1^2 + x.2.2 ^ 2 = 0)).1
#exit
#eval let c : ℚ := 1 in let d : ℚ := -2 in
c * d * (c + d)
example (a b c d : ℝ) (h : 0 < c * d * (c + d)) :
(a + b)^2 / (c + d) ≤ a^2 / c + b^2 / d :=
sub_nonneg.1 $
calc 0 ≤ (a * d - b * c) ^ 2 / (c * d * (c + d)) :
div_nonneg (pow_two_nonneg _) (le_of_lt h)
... = _ : begin
have hc0 : c ≠ 0, from λ h, by simp [*, lt_irrefl] at *,
have hd0 : d ≠ 0, from λ h, by simp [*, lt_irrefl] at *,
have hcd0 : c + d ≠ 0, from λ h, by simp [*, lt_irrefl] at *,
field_simp [hc0, hd0, hcd0],
ring
end
#exit
import group_theory.perm.basic
import group_theory.subgroup
open equiv
example (p : Prop) : ¬(¬p ∧ ¬¬p) :=
λ h, h.2 h.1
example (x y z : perm bool)
(a : subgroup.closure ({(x * y * z)} : set (perm bool)))
(b : subgroup.closure ({(x * (y * z))} : set (perm bool))) :
a * a = b * b :=
begin
end
example {G : Type} [group G] (x y z : G)
(a : subgroup.closure ({(x * y * z)} : set G))
(b : subgroup.closure ({(x * (y * z))} : set G)) :
a * a = b * b :=
begin
end
example {A : Type*} (f : set A → A) (h : function.injective f) : false :=
let s := f '' {y | f y ∉ y} in
have h1 : f s ∉ s, from
λ hs, Exists.rec (λ t ht, ht.1 (eq.rec hs (h ht.2).symm)) hs,
have h2 : f s ∈ s, from ⟨s, h1, eq.refl _⟩,
h1 h2
#print X
#exit
inductive myheq {α : Type} : ∀ {β : Type}, α → β → Type
| refl (a : α) : myheq a a
lemma heq_refl {α} {a b : α} (h : myheq a b) : myheq (myheq.refl a) h :=
@myheq.rec α (λ α' a a' h', myheq (myheq.refl a) h') (λ a, myheq.refl (myheq.refl a)) α a b h
def myeq {α : Type} (a b : α) : Type := myheq a b
lemma eq_irrel {α} {a b : α} (h₁ h₂ : myeq a b) : myeq h₁ h₂ :=
@myheq.rec α (λ α a b h₁, ∀ h₂, myeq h₁ h₂) (λ a h₂, heq_refl h₂) α a b h₁ h₂
#exit
import data.list.chain
section monoids
-- given a family of monoids, where both the monoids and the indexing set have decidable equality.
variables {ι : Type*} (G : Π i : ι, Type*) [Π i, monoid (G i)]
[decidable_eq ι] [∀ i, decidable_eq (G i)]
-- The coproduct of our monoids.
@[derive decidable_eq]
def coprod : Type* := { l : list (Σ i, { g : G i // g ≠ 1 }) // (l.map sigma.fst).chain' (≠) }
variable {G}
-- `w.head_isn't i` says that `i` is not the head of `w`.
def coprod.head_isn't (w : coprod G) (i : ι) : Prop := ∀ p ∈ (w.val.map sigma.fst).head', i ≠ p
section cases
-- here we define a custom eliminator for `coprod`. The idea is we have an index `i`, and
-- want to say that every `w : coprod G` either (1) doesn't have `i` as its head, or (2) is `g * w'`
-- for some `g : G i`, where `w'` doesn't have `i` as its head.
variables {i : ι} {C : coprod G → Sort*}
(d1 : Π w : coprod G, w.head_isn't i → C w)
(d2 : Π (w : coprod G) (h : w.head_isn't i) (g), C ⟨⟨i, g⟩ :: w.val, w.property.cons' h⟩)
include d1 d2
def coprod_cases : Π w : coprod G, C w
| w@⟨[], _⟩ := d1 w $ by rintro _ ⟨⟩
| w@⟨⟨j, g⟩ :: ls, h⟩ := if ij : i = j then by { cases ij, exact d2 ⟨ls, h.tail⟩ h.rel_head' g }
else d1 w $ by { rintro _ ⟨⟩ ⟨⟩, exact ij rfl }
variables {d1 d2}
-- computation rule for the first case of our eliminator
lemma beta1 : ∀ (w : coprod G) h, (coprod_cases d1 d2 w : C w) = d1 w h
| ⟨[], _⟩ h := rfl
| ⟨⟨j, g⟩ :: ls, hl⟩ h := by { rw [coprod_cases, dif_neg], exact h j rfl }
-- computation rule for the second case of our eliminator
lemma beta2 (w : coprod G) (h : w.head_isn't i) (g) {x} :
(coprod_cases d1 d2 ⟨⟨i, g⟩ :: w.val, x⟩ : C ⟨⟨i, g⟩ :: w.val, x⟩) = d2 w h g :=
by { rw [coprod_cases, dif_pos rfl], cases w, refl }
end cases
-- prepend `g : G i` to `w`, assuming `i` is not the head of `w`.
def rcons' {i : ι} (g : G i) (w : coprod G) (h : w.head_isn't i) : coprod G :=
if g_one : g = 1 then w else ⟨⟨i, g, g_one⟩ :: w.val, w.property.cons' h⟩
-- prepend `g : G i` to `w`. NB this is defined in terms of `rcons'`: this will be a recurring theme.
def rcons {i : ι} (g : G i) : coprod G → coprod G :=
coprod_cases (rcons' g) (λ w h g', rcons' (g * ↑g') w h)
-- computation rules for `rcons`
lemma rcons_def1 {i : ι} {g : G i} {w : coprod G} (h) : rcons g w = rcons' g w h := beta1 _ _
lemma rcons_def2 {i : ι} {g : G i} {w : coprod G} (h) (g') {x} :
rcons g ⟨⟨i, g'⟩ :: w.val, x⟩ = rcons' (g * ↑g') w h := beta2 _ _ _
-- prepending one doesn't change our word
lemma rcons_one {i : ι} : ∀ w : coprod G, rcons (1 : G i) w = w :=
begin
apply coprod_cases,
{ intros w h, rw [rcons_def1 h, rcons', dif_pos rfl], },
{ rintros w h ⟨g, hg⟩, rw [rcons_def2 h, one_mul, rcons', dif_neg], refl, }
end
-- preliminary for `rcons_mul`
private lemma rcons_mul' {i : ι} {g g' : G i} {w : coprod G} (h : w.head_isn't i) :
rcons (g * g') w = rcons g (rcons g' w) :=
begin
rw [rcons_def1 h, rcons_def1 h, rcons', rcons'],
split_ifs,
{ rw [h_2, mul_one] at h_1, rw [h_1, rcons_one], },
{ rw [rcons_def2 h, rcons', dif_pos], exact h_1, },
{ rw [rcons_def1 h, rcons', dif_neg], { congr, rw [h_2, mul_one], }, simpa [h_2] using h_1, },
{ rw [rcons_def2 h, rcons', dif_neg], refl, },
end
-- we can prepend `g * g'` one element at a time.
lemma rcons_mul {i : ι} (g : G i) (g' : G i) : ∀ w, rcons (g * g') w = rcons g (rcons g' w) :=
begin
apply coprod_cases,
{ apply rcons_mul', },
{ intros w h g'', rw [rcons_def2 h, rcons_def2 h, mul_assoc,
←rcons_def1, rcons_mul' h, ←rcons_def1] }
end
-- Every `G i` thus acts on the coproduct.
@[simps] instance bar (i) : mul_action (G i) (coprod G) :=
{ smul := rcons, one_smul := rcons_one, mul_smul := rcons_mul }
-- Prepending a letter to a word means acting on that word. This will be useful for proofs by
-- induction on words.
lemma cons_as_smul {i} {g} (ls) (hl) :
(⟨⟨i, g⟩ :: ls, hl⟩ : coprod G) = (g.val • ⟨ls, hl.tail⟩ : coprod G) :=
begin
rw [bar_to_has_scalar_smul, rcons_def1, rcons', dif_neg g.property],
{ congr, ext, refl, }, { exact hl.rel_head', },
end
section action
-- Given actions of `G i` on `X`, the coproduct also has a scalar action on `X`. We'll use this
-- both to define multiplication in the coproduct, and to get its universal property.
variables {X : Type*} [∀ i, mul_action (G i) X]
instance foo : has_scalar (coprod G) X := ⟨λ g x, g.val.foldr (λ l y, l.snd.val • y) x⟩
-- preliminary for `foobar`.
private lemma foobar' {i} {g : G i} {x : X} {w : coprod G} (h : w.head_isn't i) :
(rcons g w) • x = g • (w • x) :=
by { rw [rcons_def1 h, rcons'], split_ifs, { rw [h_1, one_smul], }, { refl, }, }
-- (I'm not sure it's worth it to use these typeclasses, since Lean gets a bit confused by them...)
instance foobar (i) : is_scalar_tower (G i) (coprod G) X :=
⟨begin
intros g' w x, revert w,
apply coprod_cases,
{ apply foobar', },
{ intros w h g, rw [bar_to_has_scalar_smul, rcons_def2 h, ←rcons_def1 h,
foobar' h, mul_smul], refl, }
end⟩
end action
instance coprod_monoid : monoid (coprod G) :=
{ mul := λ x y, x • y,
mul_assoc := begin
rintros ⟨ls, hl⟩ b c,
change (_ • _) • _ = _ • (_ • _),
induction ls with p ls ih,
{ refl, },
cases p with i g,
rw [cons_as_smul, smul_assoc g.val _ b, smul_assoc, ih, smul_assoc],
apply_instance, -- ??
end,
one := ⟨[], list.chain'_nil⟩,
one_mul := λ _, rfl,
mul_one := begin
rintro ⟨ls, hl⟩,
change _ • _ = _,
induction ls with p ls ih,
{ refl },
cases p with i g,
rw [cons_as_smul, smul_assoc, ih],
end }
def of {i} : G i →* coprod G :=
{ to_fun := λ g, g • 1,
map_one' := rcons_one _,
map_mul' := by { intros, change rcons _ _ = _ • _, rw [rcons_mul, smul_assoc], refl } }
lemma cons_as_mul {i} {g} (ls) (h) :
(⟨⟨i, g⟩ :: ls, h⟩ : coprod G) = (of g.val * ⟨ls, h.tail⟩ : coprod G) :=
by { convert cons_as_smul ls h, change (_ • _) • _ = _, rw smul_assoc g.val, congr, apply_instance }
def ump (X : Type*) [monoid X] :
(Π {i}, G i →* X) ≃ (coprod G →* X) :=
{ to_fun := λ fi, begin
letI : ∀ i, mul_action (G i) X := λ i, mul_action.comp_hom _ fi,
refine { to_fun := λ g, g • 1, map_one' := rfl, map_mul' := _ },
rintros ⟨ls, hl⟩ b,
change (_ • _) • _ = _,
induction ls with p ls ih,
{ exact (one_mul _).symm },
cases p with i g,
rw [cons_as_smul, smul_assoc g.val _ b, smul_assoc, ih, smul_assoc],
{ symmetry, apply mul_assoc, },
{ apply_instance },
end,
inv_fun := λ f i, f.comp of,
left_inv := begin
intro fi, letI : ∀ i, mul_action (G i) X := λ i, mul_action.comp_hom _ fi,
ext i g, change (g • (1 : coprod G)) • (1 : X) = fi g,
rw smul_assoc, apply mul_one,
end,
right_inv := begin
intro f,
ext w,
cases w with ls hl,
change _ • 1 = f ⟨ls, hl⟩,
induction ls with p ls ih,
{ exact f.map_one.symm },
cases p with i g,
conv_rhs { rw [cons_as_mul, f.map_mul] },
letI : ∀ i, mul_action (G i) X := λ i, mul_action.comp_hom _ (f.comp of),
rw [cons_as_smul, smul_assoc, ih], refl
end }
lemma prod_eq_self (w : coprod G) : list.prod (w.val.map (λ l, of l.snd.val)) = w :=
begin
cases w with ls hl, induction ls with p ls ih,
{ refl, }, { cases p, rw [list.map_cons, list.prod_cons, ih hl.tail, cons_as_mul], },
end
end monoids
-- we now do the case of groups.
variables {ι : Type*} {G : Π i : ι, Type*} [Π i, group (G i)]
[decidable_eq ι] [∀ i, decidable_eq (G i)]
@[simps]
instance coprod_inv : has_inv (coprod G) :=
⟨λ w, ⟨list.reverse (w.val.map $ λ l, ⟨l.fst, l.snd.val⁻¹, inv_ne_one.mpr l.snd.property⟩),
begin
rw [list.map_reverse, list.chain'_reverse, list.map_map, function.comp],
convert w.property, ext, exact ne_comm,
end⟩⟩
instance : group (coprod G) :=
{ mul_left_inv := begin
intro w, -- possibly this should all be deduced from some more general result
conv_lhs { congr, rw ←prod_eq_self w⁻¹, skip, rw ←prod_eq_self w },
cases w with ls _,
rw [subtype.val_eq_coe, coprod_inv_inv_coe, list.map_reverse, list.map_map],
dsimp only,
induction ls with p ls ih,
{ apply mul_one, },
rw [list.map_cons, list.reverse_cons, list.prod_append, list.map_cons, list.prod_cons,
list.prod_nil, mul_one, function.comp_apply, mul_assoc, list.prod_cons,
←mul_assoc _ (of p.snd.val), ←of.map_mul, mul_left_inv, of.map_one, one_mul, ih],
end,
..coprod_inv,
..coprod_monoid }
#exit
import group_theory.semidirect_product
import group_theory.free_group
open free_group multiplicative semidirect_product
universes u v
def free_group_hom_ext {α G : Type*} [group G] {f g : free_group α →* G}
(h : ∀ a : α, f (of a) = g (of a)) (w : free_group α) : f w = g w :=
free_group.induction_on w (by simp) h (by simp) (by simp {contextual := tt})
def free_group_equiv {α β : Type*} (h : α ≃ β) : free_group α ≃* free_group β :=
{ to_fun := free_group.map h,
inv_fun := free_group.map h.symm,
left_inv := λ w, begin rw [← monoid_hom.comp_apply],
conv_rhs {rw ← monoid_hom.id_apply (free_group α) w},
exact free_group_hom_ext (by simp) _ end,
right_inv := λ w, begin rw [← monoid_hom.comp_apply],
conv_rhs {rw ← monoid_hom.id_apply (free_group β) w},
exact free_group_hom_ext (by simp) _ end,
map_mul' := by simp }
def free_group_perm {α : Type u} : equiv.perm α →* mul_aut (free_group α) :=
{ to_fun := free_group_equiv,
map_one' := by ext; simp [free_group_equiv],
map_mul' := by intros; ext; simp [free_group_equiv, ← free_group.map.comp] }
def phi : multiplicative ℤ →* mul_aut (free_group (multiplicative ℤ)) :=
(@free_group_perm (multiplicative ℤ)).comp
(mul_action.to_perm (multiplicative ℤ) (multiplicative ℤ))
example : free_group bool ≃* free_group (multiplicative ℤ) ⋊[phi] multiplicative ℤ :=
{ to_fun := free_group.lift (λ b, cond b (inl (of (of_add (0 : ℤ)))) (inr (of_add (1 : ℤ)))),
inv_fun := semidirect_product.lift
(free_group.lift (λ a, of ff ^ (to_add a) * of tt * of ff ^ (-to_add a)))
(gpowers_hom _ (of ff))
begin
assume g,
ext,
apply free_group_hom_ext,
assume b,
simp only [mul_equiv.coe_to_monoid_hom,
gpow_neg, function.comp_app, monoid_hom.coe_comp, gpowers_hom_apply,
mul_equiv.map_inv, lift.of, mul_equiv.map_mul, mul_aut.conj_apply, phi,
free_group_perm, free_group_equiv, mul_action.to_perm,
units.smul_perm_hom, units.smul_perm],
dsimp [free_group_equiv, units.smul_perm],
simp [to_units, mul_assoc, gpow_add]
end,
left_inv := λ w, begin
conv_rhs { rw ← monoid_hom.id_apply _ w },
rw [← monoid_hom.comp_apply],
apply free_group_hom_ext,
intro a,
cases a; refl,
end,
right_inv := λ s, begin
conv_rhs { rw ← monoid_hom.id_apply _ s },
rw [← monoid_hom.comp_apply],
refine congr_fun (congr_arg _ _) _,
apply semidirect_product.hom_ext,
{ ext,
{ simp only [right_inl, mul_aut.apply_inv_self, mul_right,
mul_one, monoid_hom.map_mul, gpow_neg, lift_inl,
mul_left, function.comp_app, left_inl, cond, monoid_hom.map_inv,
monoid_hom.coe_comp, monoid_hom.id_comp, of_add_zero,
inv_left, lift.of, phi, free_group_perm, free_group_equiv,
mul_action.to_perm, units.smul_perm_hom, units.smul_perm],
dsimp [free_group_equiv, units.smul_perm],
simp,
simp only [← monoid_hom.map_gpow],
simp [- monoid_hom.map_gpow],
rw [← int.of_add_mul, one_mul],
simp [to_units] },
{ simp } },
{ apply monoid_hom.ext_mint,
refl }
end,
map_mul' := by simp }
#exit
open equiv set nat
variables {S : set ℕ} (π : perm S) (x : S)
set_option trace.simplify.rewrite true
lemma set_S_wf {α : Type*} [group α] (a b c : α) (hab : c * a⁻¹ = c * b⁻¹) : a = b :=
by simp * at *
#print set_S_wf
#exit
import tactic.rcases
universes u
inductive word₀
| blank : word₀
| concat : word₀ → word₀ → word₀
open word₀
infixr ` □ `:80 := concat
@[simp] lemma ne_concat_self_left : ∀ u v, u ≠ u □ v
| blank v h := word₀.no_confusion h
| (u □ u') v h := ne_concat_self_left u u' (by injection h)
@[simp] lemma ne_concat_self_right : ∀ u v, v ≠ u □ v
| u blank h := word₀.no_confusion h
| u (v □ v') h := ne_concat_self_right v v' (by injection h)
@[simp] lemma concat_ne_self_right (u v : word₀) : u □ v ≠ v :=
(ne_concat_self_right _ _).symm
@[simp] lemma concat_ne_self_left (u v : word₀) : u □ v ≠ u :=
(ne_concat_self_left _ _).symm
inductive hom₀ : word₀ → word₀ → Sort*
| α_hom : ∀ (u v w : word₀), hom₀ ((u □ v) □ w) (u □ (v □ w))
| α_inv : ∀ (u v w : word₀), hom₀ (u □ (v □ w)) ((u □ v) □ w)
| tensor_id : ∀ {u v} (w), hom₀ u v → hom₀ (u □ w) (v □ w)
| id_tensor : ∀ (u) {v w}, hom₀ v w → hom₀ (u □ v) (u □ w)
inductive hom₀.is_directed : ∀ {v w}, hom₀ v w → Prop
| α : ∀ {u v w}, hom₀.is_directed (hom₀.α_hom u v w)
| tensor_id : ∀ (u) {v w} (s : hom₀ v w), hom₀.is_directed s →
hom₀.is_directed (hom₀.tensor_id u s)
| id_tensor : ∀ {u v} (w) (s : hom₀ u v), hom₀.is_directed s →
hom₀.is_directed (hom₀.id_tensor w s)
lemma hom₀.ne {u v} (s : hom₀ u v) : u ≠ v :=
by induction s; simp *
lemma hom₀.subsingleton_aux :
∀ {u v u' v'} (hu : u = u') (hv : v = v')
(s : hom₀ u v) (s' : hom₀ u' v'), s.is_directed →
s'.is_directed → s == s' :=
begin
assume u v u' v' hu hv s s' hs hs',
induction hs generalizing u' v',
{ cases hs',
{ simp only at hu hv,
rcases hu with ⟨⟨rfl, rfl⟩, rfl⟩,
refl },
{ simp only at hu hv,
rcases hu with ⟨rfl, rfl⟩,
simp * at * },
{ simp only at hu hv,
rcases hu with ⟨rfl, rfl⟩,
simp * at * } },
{ cases hs',
{ simp only at hu hv,
rcases hu with ⟨⟨rfl, rfl⟩, rfl⟩,
simp * at * },
{ simp only at hu hv,
rcases hu with ⟨rfl, rfl⟩,
rcases hv with ⟨rfl, _⟩,
simp only [heq_iff_eq],
rw [← heq_iff_eq],
exact hs_ih rfl rfl _ (by assumption) },
{ simp only at hu hv,
rcases hu with ⟨rfl, rfl⟩,
rcases hv with ⟨rfl, rfl⟩,
exact (hom₀.ne hs'_s rfl).elim } },
{ cases hs',
{ simp only at hu hv,
rcases hu with ⟨⟨rfl, rfl⟩, rfl⟩,
simp * at * },
{ simp only at hu hv,
rcases hu with ⟨rfl, rfl⟩,
rcases hv with ⟨rfl, rfl⟩,
exact (hom₀.ne hs'_s rfl).elim },
{ simp only at hu hv,
rcases hu with ⟨rfl, rfl⟩,
rcases hv with ⟨_, rfl⟩,
simp only [heq_iff_eq],
rw [← heq_iff_eq],
exact hs_ih rfl rfl _ (by assumption) } }
end
lemma hom₀.subsingleton {u v}
(s s' : hom₀ u v) (hs : s.is_directed)
(hs' : s'.is_directed) : s = s' :=
eq_of_heq (hom₀.subsingleton_aux rfl rfl _ _ hs hs')
#exit
import order.conditionally_complete_lattice
import order.lattice_intervals
lemma Z {X : Type} [conditionally_complete_lattice X] [densely_ordered X]
(a b : X) (h : a < b) : Inf (set.Ioc a b) = a :=
le_antisymm
begin
by_contra h1,
set s := (Inf (set.Ioc a b)) ⊔ a,
have has : a < s, from lt_iff_le_not_le.2
⟨le_sup_right, λ hsa, h1 (le_trans le_sup_left hsa)⟩,
rcases densely_ordered.dense _ _ has with ⟨c, hac, hcs⟩,
have hIb : Inf (set.Ioc a b) ≤ b, from cInf_le bdd_below_Ioc (set.mem_Ioc.2 ⟨h, le_refl _⟩),
have hsb : s ≤ b, from sup_le hIb (le_of_lt h),
have hIc : Inf (set.Ioc a b) ≤ c, from cInf_le bdd_below_Ioc
(set.mem_Ioc.2 ⟨hac, le_of_lt (lt_of_lt_of_le hcs hsb)⟩),
have hsc : s ≤ c, from sup_le hIc (le_of_lt hac),
exact not_le_of_gt hcs hsc,
end
(le_cInf ⟨b, set.mem_Ioc.2 ⟨h, le_refl _⟩⟩
(λ c hc, le_of_lt (set.mem_Ioc.1 hc).1))
#print Z
#exit
class group (set : Type) :=
(add: set → set → set)
structure group_obj :=
(set : Type)
(group : group set)
instance coe_to_sort : has_coe_to_sort group_obj :=
{ S := Type,
coe := group_obj.set }
instance group_obj_group (G : group_obj) : group G := G.group
infix `+` := group.add
structure group_morphism (G H : group_obj) :=
(f: G → H)
(additive: ∀ g h : G.set, f(g + h) = (f g) + (f h))
#exit
import algebra.field
import tactic
example {R : Type} [linear_ordered_field R] (d : R) : d * (d + 3) / 2 = (d + 2) * (d + 1) / 2 - 1 :=
begin
ring,
end
theorem thm (a b : ℤ) : a * (1 + b) - a = a * b :=
(mul_add a 1 b).symm ▸ (mul_one a).symm ▸ add_sub_cancel' a (a * b)
example : ∀ p q : Prop, p ∧ q → q ∧ p :=
λ (p q : Prop) (h : p ∧ q), and.intro (and.right h) (and.left h)
import algebra.ring algebra.group_power
import tactic
example {R : Type} [comm_ring R] (x : R) (hx : x^2 + x + 1 = 0) :
x^4 = x :=
calc x^4 = x ^ 4 + x * (x ^ 2 + x + 1) : by rw hx; ring
... = x * (x ^ 2 + 1) * (x + 1) : by ring
... = _ : _
lemma lem1 {R : Type} [semiring R] {T : R} (hT : T = T^2 + 1) (n : ℕ) :
T^n.succ = T^n.succ.succ + T^n :=
calc T ^ n.succ = T ^ n * (T ^ 2 + 1) : by rw [← hT, pow_succ']
... = _ : by simp only [pow_succ', pow_zero, one_mul, mul_assoc, mul_add, mul_one]
lemma lem2 {R : Type} [semiring R] {T : R} (hT : T = T^2 + 1) (k : ℕ) :
T^(k + 3) + T ^ k + T = T :=
begin
induction k with k ih,
{ conv_rhs { rw [hT, pow_two], congr, congr, rw hT },
simp [pow_succ, mul_assoc, add_assoc, add_mul, add_comm, add_left_comm] },
{ calc T ^ (k + 4) + T ^ (k + 1) + T
= T ^ (k + 4) + T ^ (k + 1) + (T ^ 2 + 1) : by rw [← hT]
... = (T ^ (k + 3) + T ^ k + T) * T + 1 :
by simp only [pow_succ', one_mul, pow_zero, mul_assoc, add_mul, mul_one,
add_assoc]
... = T^2 + 1 : by rw ih; simp only [pow_succ', one_mul, pow_zero, mul_assoc, add_mul, mul_one,
add_assoc]
... = T : hT.symm }
end
lemma lem3 {R : Type} [semiring R] {T : R} (hT : T = T^2 + 1) (n k : ℕ) :
T^(k + 3) + T ^ k + T ^ (n + 1) = T ^ (n + 1) :=
begin
induction n with n ih,
{ rw [zero_add, pow_one, lem2 hT] },
{ rw [lem1 hT n.succ, add_comm _ (T ^ n.succ), ← add_assoc, ih] }
end
lemma lem4 {R : Type} [semiring R] {T : R} (hT : T = T^2 + 1) : T^7 = T :=
calc T ^ 7 = T ^ 7 + T ^ 4 + T ^ 1 :
by conv_lhs { rw [← lem3 hT 6 1] };
simp only [pow_succ', one_mul, pow_zero, mul_assoc, add_mul, mul_one, add_assoc, add_comm]
... = _ : by rw lem3 hT 0 4; simp
example {R : Type} [comm_ring R] (T : R) (hT : T = T^2 + 1) : T^7 = T :=
calc T ^ 7 = (T ^ 8 + T ^ 7 + (T ^ 6 + T ^ 4) + (T ^ 5 + T ^ 3) + T ^ 2 + 1) : begin
conv_lhs { rw [lem1 hT 6, lem1 hT 5, lem1 hT 4, lem1 hT 3, lem1 hT 2, lem1 hT 1, lem1 hT 0] },
ring_exp,
end
... = T^8 + (T ^ 7 + T ^ 5) + T ^ 4 + T ^ 3 + T + 1 : begin
rw [← lem1 hT 3, ← lem1 hT 4, lem1 hT 1],
ring_exp,
end
... = (T ^ 8 + T ^ 6) + T ^ 4 + T ^ 3 + T + 1 :
begin
rw [← lem1 hT 5],
end
... = T ^ 7 + T ^ 4 + T ^ 3 + T + 1 :
begin
rw [← lem1 hT 6],
end
example {R : Type} [comm_semiring R] (T : R) (hT : T = T^2 + 1) : T^7 = T :=
calc T^7 = T^6 * T : by ring
... = T^6 * (T^2 + 1) :
example {R : Type} [comm_ring R] (T : R) (hT : T = T^2 + 1) :
T^7 = T :=
calc T ^ 7 = T * ((T^2 + 1)^2 - T^2) * (T + 1) * (T - 1) + T : by ring
... = 1 : begin
rw ← hT, ring
end
example {R : Type} [comm_ring R] (T : R) (hT : T = T^2 + 1) :
T^7 = T :=
calc T ^ 7 = T * (T^2 + T + 1) * (T^2 - T + 1) * (T + 1) * (T - 1) + T : by ring
... = _ : sorry
example {R : Type} [comm_semiring R] (T : R) (hT : T = T^2 + 1) :
T^7 = T :=
calc T ^ 7 = T ^ 3 * T ^ 3 : by simp[pow_succ, mul_assoc]
... = (T ^ 2 + 1)^3 * T^3 : by rw ← hT
... = _ : begin
ring_exp,
end
#exit
import logic.basic
def type_of {α : Sort*} (a : α) := α
#reduce type_of $ type_of $ type_of @flip
#reduce type_of $ type_of $ @flip (type_of @flip) (type_of @flip) (type_of @flip)
#exit
import data.real.nnreal
import algebra.big_operators
import topology.algebra.infinite_sum
import tactic
import order.lexicographic
open_locale nnreal big_operators
def mask_fun (f : ℕ → ℝ≥0) (mask : ℕ → Prop) [∀ n, decidable (mask n)] : ℕ → ℝ≥0 :=
λ n, if mask n then f n else 0
lemma exists_smul_le_sum {α M : Type*} [linear_ordered_cancel_add_comm_monoid M] (s : finset α)
(hs : s.nonempty) (f : α → M) : ∃ a ∈ s, finset.card s •ℕ f a ≤ ∑ x in s, f x :=
begin
classical,
induction s using finset.induction_on with a s has ih,
{ cases hs with a ha,
exact ⟨a, by simp *⟩ },
{ simp only [finset.card_insert_of_not_mem has, finset.sum_insert has, succ_nsmul],
by_cases hs : s.nonempty,
{ rcases ih hs with ⟨b, hbs, hs⟩,
by_cases f a ≤ f b,
{ use [a, by simp],
exact add_le_add (le_refl _) (le_trans (nsmul_le_nsmul_of_le_right h _) hs) },
{ use [b, finset.mem_insert_of_mem hbs],
exact add_le_add (le_of_not_le h) hs } },
{ use a,
simp [(finset.eq_empty_or_nonempty s).resolve_right hs] } },
end
lemma exists_partition (N : ℕ) (hN : 0 < N) (f : ℕ → ℝ≥0) (hf : ∀ n, f n ≤ 1) :
∃ (m : ℕ), f m ≤ (∑' n, f n) / N + 1 :=
begin
split,
{ rintros ⟨mask, _, h₁, h₂⟩,
cases h₁ 0 with m hm,
use m, dsimp at *,
}
end
#exit
import data.real.nnreal
import algebra.big_operators
import data.list.min_max
import tactic
open_locale nnreal
open_locale big_operators
#exit
instance (n : ℕ) (h : 0 < n) : denumerable (fin n × ℕ) :=
@denumerable.of_encodable_of_infinite _ _
(infinite.of_injective (λ i : nat, (fin.mk 0 h, i))
(λ _ _, by simp))
#exit
import tactic
set_option profiler true
example {R : Type} [comm_ring R] (α β γ : R)
(h : α + β + γ = 0):
(α - β)^2 * (α - γ)^2 * (β - γ)^2 =
-4 * (α * β + β * γ + α * γ) ^3- 27 * (α * β * γ)^2 :=
begin
rw [add_assoc, add_eq_zero_iff_eq_neg] at h,
subst h,
ring,
end
#print buffer
def fast_choose (n k : ℕ) : ℕ :=
n.factorial / ((n - k).factorial * k.factorial)
def C : ℕ → buffer ℕ
| 0 := buffer.nil.push_back 1
| 1 := (C 0).push_back 1
| n@(x+1) :=
let n2 := (n * x) / 2 in
let C := C x in
let b : ℕ:= 2^n2 - ((list.fin_range x).map
(λ m : fin x, have h : m.val < x, from m.2,
let nx : ℕ := x - m in
fast_choose x m * C.read' (m + 1) * 2^
(((nx - 1) * nx) / 2))).sum in
C.push_back b
def list_digits_to_string : list ℕ → string :=
λ l, l.foldl (λ s n, repr n ++ s) ""
#eval let n :=9 in (nat.digits (n) ((C n).read' n)).reverse
#exit
import logic.basic
import logic.function.basic
-- term `n` is a function with `n` arguments
inductive term (α : Type) (arity : α → ℕ) : ℕ → Type
| func : Π a, term (arity a)
| var : ℕ → term 0
| app : Π {n : ℕ}, term n.succ → term 0 → term n
variables {α : Type} (arity : α → ℕ)
open term
meta def lt [has_lt α] [decidable_rel (@has_lt.lt α _)] :
Π {n m}, term α arity n → term α arity m → bool
| _ _ (func a) (func b) := a < b
| _ _ (func a) (var _) := ff
| n m (func a) (app _ _) := n < m
| n m (var _) (func _) := if n < m then tt else ff
| _ _ (var i) (var j) := i < j
| _ _ (var i) (app _ _) := tt
| n m (app _ _) (func _) := n < m
| _ _ (app _ _) (var _) := ff
| n m (app f x) (app g y) :=
cond (lt f g)
tt
(cond (lt g f)
ff
(lt x y))
instance (n : ℕ) : has_coe_to_fun (term α arity n.succ) :=
{ F := λ _, term α arity 0 → term α arity n,
coe := term.app }
def subst (n : ℕ) : term α arity 0 → term α arity 0 →
#exit
import algebra.group
@[derive decidable_eq, derive has_reflect] inductive gterm : Type
| X : ℕ → gterm
| one : gterm
| mul : gterm → gterm → gterm
| inv : gterm → gterm
meta instance : has_repr gterm := ⟨λ g, (`(%%(reflect g) : gterm)).to_string⟩
instance : has_mul gterm := ⟨gterm.mul⟩
instance : has_one gterm := ⟨gterm.one⟩
instance : has_inv gterm := ⟨gterm.inv⟩
open gterm
inductive geq : gterm → gterm → Type
| X : ∀ n, geq (X n) (X n)
| one : geq 1 1
| mul : ∀ {a b c d}, geq a b → geq c d → geq (a * c) (b * d)
| inv : ∀ {a b}, geq a b → geq (a⁻¹) (b⁻¹)
| mul_assoc : ∀ {a b c}, geq (a * b * c) (a * (b * c))
| one_mul : ∀ a, geq (1 * a) a
| inv_mul : ∀ a, geq (a⁻¹ * a) 1
| refl : ∀ (a), geq a a
| symm : ∀ {a b}, geq a b → geq b a
| trans : ∀ {a b c}, geq a b → geq b c → geq a c
meta def to_expr (a b : gterm) (h : geq a b) : expr :=
begin
induction h,
{ exact expr.app (expr.const `geq.refl []) (reflect h) },
{ exact expr.const `geq.one [] },
{ exact expr.app (expr.app (expr.app (expr.app (expr.app (expr.app (expr.const `geq.mul []) (reflect h_a)) (reflect h_b))
(reflect h_c)) (reflect h_d)) h_ih_ᾰ) h_ih_ᾰ_1 },
{ exact expr.app (expr.app (expr.app (expr.const `geq.inv []) (reflect h_a)) (reflect h_b)) h_ih },
{ exact expr.app (expr.app (expr.app (expr.const `geq.mul_assoc []) (reflect h_a))
(reflect h_b)) (reflect h_c) },
{ exact expr.app (expr.const `geq.one_mul []) (reflect h) },
{ exact expr.app (expr.const `geq.inv_mul []) (reflect h) },
{ exact expr.app (expr.const `geq.refl []) (reflect h) },
{ exact expr.app (expr.app (expr.app (expr.const `geq.symm []) (reflect h_a)) (reflect h_b)) h_ih },
{ exact expr.app (expr.app (expr.app (expr.app (expr.app (expr.const `geq.trans []) (reflect h_a))
(reflect h_b)) (reflect h_c)) h_ih_ᾰ) h_ih_ᾰ_1 }
end
meta instance (a b : gterm): has_repr (geq a b) :=
⟨λ g, (to_expr _ _ g).to_string⟩
attribute [refl] geq.refl
attribute [symm] geq.symm
attribute [trans] geq.trans
/-- `subst a b t` replaces occurences of `a` in `t` with `b` -/
def subst (a b : gterm) : gterm → gterm
| (mul x y) :=
if a = x
then if a = y
then b * b
else b * subst y
else if a = y
then subst x * b
else subst x * subst y
| (inv x) :=
if a = x
then b⁻¹
else (subst x)⁻¹
| (X n) := if a = X n then b else X n
| 1 := if a = 1 then b else 1
def geq_subst (a b : gterm) (h : geq a b) :
∀ t : gterm, geq t (subst a b t)
| (mul x y) :=
begin
dunfold subst,
split_ifs;
apply geq.mul;
try { rw ← h_1 };
try { rw ← h_2 };
try { exact h };
try { exact geq_subst _ }
end
| (inv x) :=
begin
dunfold subst,
split_ifs;
apply geq.inv;
try { rw ← h_1 };
try { exact h };
try { exact geq_subst _ }
end
| (X n) :=
begin
dunfold subst,
split_ifs,
{ rw ← h_1, assumption },
{ refl }
end
| 1 :=
begin
dunfold subst,
split_ifs,
{ rw ← h_1, assumption },
{ refl }
end
infixl ` ≡ ` := geq
def geq.mul_inv (x) : geq (x * x⁻¹) 1 :=
calc x * x⁻¹ ≡ 1 * (x * x⁻¹) : (geq.one_mul _).symm
... ≡ ((x * x⁻¹)⁻¹ * (x * x⁻¹)) * (x * x⁻¹) :
geq.mul (geq.inv_mul _).symm (geq.refl _)
... ≡ (x * x⁻¹)⁻¹ * ((x * x⁻¹) * (x * x⁻¹)) : geq.mul_assoc
... ≡ (x * x⁻¹)⁻¹ * (x * x⁻¹) :
geq.mul (geq.refl _)
(calc (x * x⁻¹) * (x * x⁻¹) ≡ x * (x⁻¹ * (x * x⁻¹)) : geq.mul_assoc
... ≡ x * x⁻¹ : geq.mul (geq.refl _)
(geq.mul_assoc.symm.trans ((geq.mul (geq.inv_mul _) (geq.refl _)).trans (geq.one_mul _))))
... ≡ 1 : (geq.inv_mul _)
def geq.mul_one (x : gterm) : x * 1 ≡ x :=
calc x * 1 ≡ x * (x⁻¹ * x) : geq.mul (geq.refl _) (geq.inv_mul _).symm
... ≡ x * x⁻¹ * x : geq.mul_assoc.symm
... ≡ 1 * x : geq.mul (geq.mul_inv _) (geq.refl _)
... ≡ x : (geq.one_mul _)
def find_inv_mul : Π {a b : gterm}, geq a b → list gterm
| _ _ (geq.mul h₁ h₂) := find_inv_mul h₁ ∪ find_inv_mul h₂
| _ _ (geq.inv h) := find_inv_mul h
| _ _ (geq.inv_mul x) := [x]
| _ _ (geq.symm h) := find_inv_mul h
| _ _ (geq.trans h₁ h₂) := find_inv_mul h₁ ∪ find_inv_mul h₂
| _ _ (geq.X _) := []
| _ _ (geq.one) := []
| _ _ (geq.mul_assoc) := []
| _ _ (geq.one_mul _) := []
| _ _ (geq.refl _) := []
#eval find_inv_mul (geq.mul_inv (X 0))
#exit
import data.fin
universes u v
/-- A value which wraps a type. -/
inductive typeinfo (α : Type u) : Type
| of [] : typeinfo
/-- Get the type of the domain of a function type. -/
abbreviation typeinfo.domain {α : Type u} {β : α → Type v}
(a : typeinfo (Π (i : α), β i)) : Type u := α
/-- Get the type of the codomain of a function type. -/
abbreviation typeinfo.codomain {α : Type v} {β : Type u}
(a : typeinfo (α → β)) : Type u := β
/-- Get the type of the codomain of a dependent function type. -/
abbreviation typeinfo.pi_codomain {α : Type v} {β : α → Type u}
(a : typeinfo (Π (i : α), β i)) : α → Type u := β
variables {M' : Type u} {ι : Type v}
#check (ι → M')
#check typeinfo (ι → M')
#check typeinfo.of (ι → M')
#check typeinfo.domain (typeinfo.of (ι → M'))
#check (fin 2 → M')
#check typeinfo (fin 2 → M')
#check typeinfo.of (fin 2 → M')
#check typeinfo.domain (typeinfo.of (fin 2 → M') : _) -- fail, everything else works
#exit
import data.zmod.basic
import data.list
#eval quot.unquot ((finset.univ : finset (fin 4 × fin 4 × fin 4)).filter
(λ q : fin 4 × fin 4 × fin 4,
let a := 2 * q.1.val + 1,
b := 2 * q.2.1.val + 1,
c := 2 * q.2.2.val in
¬ (8 ∣ a + b) ∧
¬ (8 ∣ a + b + c) ∧
∃ x ∈ [1,4,9,16],∃ y ∈ [1,4,9,16], ∃ z ∈ [1,4,9,16],
32 ∣ a * x + b * y + c * z)).1
example {X Y Z : Type} (f g : X → Y × Z)
(h₁ : prod.fst ∘ f = prod.fst ∘ g)
(h₂ : prod.snd ∘ f = prod.snd ∘ g) :
f = g :=
calc f = (λ x, ((prod.fst ∘ f) x, (prod.snd ∘ f) x)) : begin
dsimp,
end
... = _
open nat
attribute [elab_as_eliminator] binary_rec
example {a b c : ℕ+} (h' : ({a, b, c} : finset ℕ+).card = 3) :
a ≠ b ∧ b ≠ c ∧ c ≠ a :=
begin
sorry
end
#exit
import data.nat.basic
import tactic
def Delta (f : int → int) := λ x, f (x + 1) - f x
example : Delta ∘ Delta ∘ Delta ∘ Delta = sorry :=
begin
funext,
dsimp [function.comp, Delta],
abel,
end
#exit
import data.list
import algebra.big_operators
#print finset.sum_
def blah_core {α : Type} (f : α → α) : list α → list α → list (list α)
| l₁ [] := sorry
| l₁ (a::l₂) := l₁ ++ f a :: l₂
def partitions {α : Type} : list α → list (list (list α))
| [] := [[]]
| (a::l) := let P := partitions l in
P.bind (λ p, ([a] :: p) :: p.bind (λ l, [p.replace]))
def tree_number : Π n : ℕ, array n ℕ
| n := let s : list (list ℕ) :=
#exit
import data.list order.pilex
#print list.lex
variables {α : Type*} (r : α → α → Prop) (wf : well_founded r)
def to_pilex : list α → Σ' n : ℕ, fin n → α
| [] := ⟨0, fin.elim0⟩
| (a::l) := ⟨(to_pilex l).fst.succ, fin.cons a (to_pilex l).snd⟩
lemma list.lex_wf : well_founded (list.lex r) :=
subrelation.wf
_
(inv_image.wf to_pilex (psigma.lex_wf nat.lt_wf (λ n, pi.lex_wf)))
#exit
#exit
import data.zmod.basic
lemma lemma1 (n : ℕ) {G : Type*} [group G] (a b : G) (h : a * b = b * a) :
a^n * b = b * a^n :=
begin
induction n with n ih,
{ rw [pow_zero, one_mul, mul_one] },
{ rw [pow_succ, mul_assoc, ih, ← mul_assoc, h, mul_assoc] }
end
example {G : Type*} [group G] (a b : G) (h : a * b = b * a) : a^2 * b = b * a^2 :=
lemma1 2 a b h
def compute_mod (p : nat.primes) (r : ℤ) : ∀ m : nat, zmod (p ^ m)
| 0 := 1
| 1 := by convert fintype.choose (λ x : zmod p, x^2 = r) sorry; simp
| (n + )
#eval (4⁻¹ : zmod 169)
#eval (-3 + 4 * 13 : int)
#eval (55 ^ 2 : zmod 169)
#eval (127^2 + 4) / 169
#eval (-4 * 95⁻¹ : zmod(13^ 3))
#eval ((95 + 13^2 * 740)^2 : zmod (13^3)) + 4
#eval 13^3
instance : fact (0 < (5 ^ 3)) := sorry
#eval ((finset.univ : finset (zmod (5 ^ 3)))).filter (λ x, x^2 = (-10 : zmod _))
#eval padic_norm 5 (1 / 4 + 156)
open native
meta def x : ℕ → rb_set ℕ × rb_set ℕ
| 0 := (mk_rb_map, mk_rb_map)
| (n+1) := let r := x n in
let h := r.1.insert (n + 1) in
let i := r.1.insert n in
if n % 2 = 0
then (h, r.2.insert n)
else (i, r.2.insert n)
meta def y : ℕ → rb_set ℕ
| 0 := mk_rb_map
| (n+1) := (y n).insert n
set_option profiler true
#eval (x 100000).1.contains 0
#eval (y 200000).contains 0
#exit
@[reducible] def V := {s : finset (fin 5) // s.card = 3}
open sum
def edge : V → V → bool
| (inl x) (inl y) := x = y + 1 ∨ y = x + 1
| (inr x) (inr y) := x = y + 2 ∨ y = x + 2
| (inl x) (inr y) := x = y
| (inr x) (inl y) := x = y
@[derive decidable_pred] def is_isom (f : V ≃ V) : Prop :=
∀ x y, edge x y = edge (f x) (f y)
-- #eval fintype.card (V ≃ V)
-- #eval fintype.card {f : V ≃ V // is_isom f}
#exit
import all
open tactic
def foo : nat → Prop
| 0 := true
| (n+1) := (foo n) ∧ (foo n)
meta def mk_foo_expr : nat → expr
| 0 := `(trivial)
| (n+1) :=
expr.app
(expr.app
(reflected.to_expr `(@and.intro (foo n) (foo n)))
(mk_foo_expr n))
(mk_foo_expr n)
open tactic
meta def show_foo : tactic unit :=
do `(foo %%nx) ← target,
n ← eval_expr nat nx,
exact (mk_foo_expr n)
set_option profiler true
lemma foo_200 : foo 200 :=
by show_foo
#print foo_200
run_cmd do env ← get_env,
dec ← env.get `foo_200,
trace (dec.value.fold 0 (fun _ _ n, n + 1) : nat)
lemma X : true :=
by cc
#print level
run_cmd do env ← get_env,
l ← env.fold (return ([] : list name))
(λ dec l, do l' ← l,
let b : bool := expr.occurs
`((17 : ℕ))
dec.type,
return (cond b (dec.to_name :: l') l')),
trace l.length
#print X
def X : list ℕ → list (ℕ × ℕ)
| [] := []
| (a::l) := X l ++ l.map (prod.mk a)
#eval X [1, 2, 3, 4, 5]
open tactic
#print tactic.set_goals
run_cmd trace_state
#print unify
#exit
import algebra.ring
universe u
variables (X : Type*) [ring X]
-- a contrived example to test recursive and non-recursive constructors
inductive foo : X → X → Prop
| of_mul {a} : foo a (a*a)
| add_two {a b} : foo a b → foo a (b + 2)
inductive foo_eqv : X → X → Prop
| refl (a) : foo_eqv a a
| symm {a b} : foo_eqv a b → foo_eqv b a
| trans {a b c} : foo_eqv a b → foo_eqv b c → foo_eqv a c
| of_mul {a} : foo_eqv a (a*a)
| add_two {a b} : foo_eqv a b → foo_eqv a (b + 2)
variable {α : Type u}
variable (r : α → α → Prop)
inductive eqv_gen' : α → α → Type u
| rel : Π x y, r x y → eqv_gen' x y
| refl : Π x, eqv_gen' x x
| symm : Π x y, eqv_gen' x y → eqv_gen' y x
| trans : Π x y z, eqv_gen' x y → eqv_gen' y z → eqv_gen' x z
def foo_eqv.of_eqv_gen : ∀ {x y}, eqv_gen' (foo X) x y → foo_eqv X x y
| _ _ (eqv_gen'.refl _) := foo_eqv.refl _
| _ _ (eqv_gen'.symm _ _ h) := (foo_eqv.of_eqv_gen h).symm
| _ _ (eqv_gen'.trans a b c hab hbc) := (foo_eqv.of_eqv_gen hab).trans (foo_eqv.of_eqv_gen hbc)
| _ _ (eqv_gen'.rel a b (foo.of_mul)) := foo_eqv.of_mul
| _ _ (eqv_gen'.rel a b (foo.add_two h)) := foo_eqv.add_two (foo_eqv.of_eqv_gen $ eqv_gen'.rel _ _ h)
using_well_founded
{ rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ p, sizeof p.snd.snd)⟩],
dec_tac := `[simp [measure, inv_image]; apply nat.lt_succ_self _] }
#exit
import tactic.abel
variables {A : Type*} [ring A]
attribute [reducible] id
#eval expr.lex_lt `(id id (1 : nat)) `((2 : nat))
#check `(add_comm_group.to_add_comm_monoid ℤ)
meta def x : expr := `(add_comm_group.to_add_comm_monoid ℤ)
meta def y : expr := `(show add_comm_monoid ℤ, from infer_instance)
#eval (x = y : bool)
def f {A : Type} [add_comm_monoid A] : A → A := id
example (a b c : ℤ) :
@f ℤ (by tactic.exact y) a + b = b + @f ℤ (by tactic.exact x) a :=
begin
abel,
end
#exit
open complex
open_locale real
example : (1 : ℂ) ^ (- I * log 2 / (2 * π)) = 2 :=
begin
rw one_cpow,
end
#exit
import tactic data.nat.basic
import data.nat.prime
import data.fintype
open tactic
#print list.take
meta def test : tactic unit :=
do t ← target,
(lhs, rhs) ← expr.is_eq t,
s ← mk_simp_set tt [] [simp_arg_type.expr ``(mul_one)],
(e₁, e₂) ← tactic.simplify s.1 [] lhs,
tactic.exact e₂
run_cmd do n ← mk_fresh_name, trace n
-- example : 2021 = 5 + nat.choose (4 ^ 3) (nat.choose 2 1) :=
-- begin
-- rw [nat.choose_eq_factorial_div_factorial, nat.choose_eq_factorial_div_factorial];
-- norm_num,
-- end
#exit
import order.order_iso_nat
import order.preorder_hom
namespace partial_order
variables (α : Type*)
/-- For partial orders, one of the many equivalent forms of well-foundedness is the following
flavour of "ascending chain condition". -/
class satisfies_acc [preorder α] : Prop :=
(acc : ∀ (a : ℕ →ₘ α), ∃ n, ∀ m, n ≤ m → a n = a m)
run_cmd tactic.mk_iff_of_inductive_prop ``satisfies_acc `partial_order.satisfies_acc_iff
variables [partial_order α]
lemma wf_iff_satisfies_acc :
well_founded ((>) : α → α → Prop) ↔ satisfies_acc α :=
begin
rw [rel_embedding.well_founded_iff_no_descending_seq,
satisfies_acc_iff, not_nonempty_iff_imp_false],
end
#print native.float
#eval native.float.exp native.float.pi - 23.1407 + 3.8147 * 0.000001
#eval native.float.exp 1
def thing (a b : nat) : nat :=
(a + b).choose a
#exit
import analysis.special_functions.trigonometric
universes u v
#check (Type u -> Type v : Type (max u v + 1)
open real
noncomputable theory
#print real.arcsin
lemma cosh_def (x : ℝ) : cosh x = (exp x + exp (-x)) / 2 :=
by simp only [cosh, complex.cosh, complex.div_re, complex.exp_of_real_re, complex.one_re,
bit0_zero, add_zero, complex.add_re, euclidean_domain.zero_div, complex.bit0_re,
complex.one_im, complex.bit0_im, mul_zero, ← complex.of_real_neg, complex.norm_sq];
ring
lemma sinh_def (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 :=
by simp only [sinh, complex.sinh, complex.div_re, complex.exp_of_real_re, complex.one_re,
bit0_zero, add_zero, complex.sub_re, euclidean_domain.zero_div, complex.bit0_re,
complex.one_im, complex.bit0_im, mul_zero, ← complex.of_real_neg, complex.norm_sq];
ring
lemma cosh_pos (x : ℝ) : 0 < real.cosh x :=
(cosh_def x).symm ▸ half_pos (add_pos (exp_pos x) (exp_pos (-x)))
lemma sinh_strict_mono : strict_mono sinh :=
strict_mono_of_deriv_pos differentiable_sinh (by rw [real.deriv_sinh]; exact cosh_pos)
lemma sinh_arcsinh (x : ℝ) : sinh (arcsinh x) = x :=
have h₂ : 0 ≤ x^2 + 1, from add_nonneg (pow_two_nonneg _) zero_le_one,
have h₁ : 0 < x + sqrt (x^2 + 1),
from suffices - x < sqrt (x^2 + 1), by linarith,
lt_of_pow_lt_pow 2 (sqrt_nonneg _)
begin
rw [sqr_sqrt h₂, pow_two, pow_two, neg_mul_neg],
exact lt_add_one _
end,
begin
rw [sinh_def, arcsinh, exp_neg, exp_log h₁],
field_simp [ne_of_gt h₁],
rw [add_mul, mul_add, mul_add, ← pow_two (sqrt _), sqr_sqrt h₂],
gen''eralize hy : sqrt (x^2 + 1) = y,
rw [← sub_eq_zero],
ring
end
lemma arcsinh_sinh (x : ℝ) : arcsinh (sinh x) = x :=
function.right_inverse_of_injective_of_left_inverse
sinh_strict_mono.injective sinh_arcsinh _
#exit
import group_theory.sylow
open_locale classical
/-
theorem has_fixed_point {G : Type} [group G] [fintype G] (hG65 : fintype.card G = 65)
{M : Type} [fintype M] (hM27 : fintype.card M = 27) [mul_action G M] :
∃ m : M, ∀ g : G, g • m = m :=
have horbit : ∀
-- begin
-- rcases @incidence.I₃ _ _ incident_with _ with ⟨A, B, C, hAB, hBC, hAC, hABC⟩,
-- have : P ≠ B ∧ P ≠ C ∨ P ≠ A ∧ P ≠ C ∨ P ≠ A ∧ P ≠ B, { finish },
-- wlog hP : P ≠ B ∧ P ≠ C := this using [B C, A C, A B],
-- { }
-- end
end
#exit
theorem fib_fast_correct : ∀ n, fib_fast n = fib n :=
#exit
import data.equiv.denumerable
open function
structure iso (A : Type) (B : Type) :=
(a_to_b : A → B)
(b_to_a : B → A)
(a_b_a : ∀ a, b_to_a (a_to_b a) = a)
(b_a_b : ∀ b, a_to_b (b_to_a b) = b)
inductive nat_plus_1 : Type
| null : nat_plus_1
| is_nat (n : ℕ) : nat_plus_1
inductive nat_plus_nat : Type
| left (n : ℕ) : nat_plus_nat
| right (n : ℕ) : nat_plus_nat
-- Task 0
-- Find a bijection between bool and bit. (provided for you as an example)
inductive bit : Type
| b0 : bit
| b1 : bit
open bit
def bool_to_bit : bool → bit
| tt := b1
| ff := b0
def bit_to_bool : bit → bool
| b0 := ff
| b1 := tt
def bool_iso_bit : iso bool bit :=
{
a_to_b := bool_to_bit,
b_to_a := bit_to_bool,
a_b_a := λ a, bool.cases_on a rfl rfl,
b_a_b := λ b, bit.cases_on b rfl rfl,
}
-- Task 1
-- General properties of iso
-- Task 1-1 : Prove that any set has the same cardinality as itself
def iso_rfl {A : Type} : iso A A := ⟨id, id, eq.refl, eq.refl⟩
-- Task 1-2 : Prove that iso is symmetric
def iso_symm {A B : Type} (i : iso A B) : iso B A :=
⟨i.2, i.1, i.4, i.3⟩
-- Task 1-3 : Prove that iso is transitive
def iso_trans {A B C : Type} (ab : iso A B) (bc : iso B C) : iso A C :=
⟨bc.1 ∘ ab.1, ab.2 ∘ bc.2, λ _, by simp [function.comp, bc.3, ab.3],
by simp [function.comp, bc.4, ab.4]⟩
-- Task 1-4 : Prove the following statement:
-- Given two functions A->B and B->A, if A->B->A is satisfied and B->A is injective, A <=> B
def bijection_alt {A B : Type} (ab : A → B) (ba : B → A)
(h : ∀ a, ba (ab a) = a) (hba: injective ba) : iso A B :=
⟨ab, ba, h, λ b, hba $ by rw h⟩
-- Task 2
-- iso relations between nat and various supersets of nat
-- nat_plus_1 : a set having one more element than nat. (provided in preloaded)
open nat_plus_1
def nat_iso_nat_plus_1 : iso ℕ nat_plus_1 :=
⟨fun n, nat.cases_on n null is_nat,
fun n, nat_plus_1.cases_on n 0 nat.succ,
λ n, by cases n; refl,
fun n, by cases n; refl⟩
-- nat_plus_nat : a set having size(nat) more elements than nat. (provided in preloaded)
open nat_plus_nat
instance : denumerable nat_plus_nat :=
denumerable.of_equiv (ℕ ⊕ ℕ)
⟨λ n, nat_plus_nat.cases_on n sum.inl sum.inr,
fun n, sum.cases_on n left right,
fun n, by cases n; refl,
fun n, by cases n; refl⟩
def nat_iso_nat_plus_nat : iso ℕ nat_plus_nat :=
let e := denumerable.equiv₂ ℕ nat_plus_nat in
⟨e.1, e.2, e.3, e.4⟩
#exit
import data.finset
open finset
variable {α : Type*}
lemma list.take_sublist : ∀ (n : ℕ) (l : list α), l.take n <+ l
| 0 l := list.nil_sublist _
| (n+1) [] := list.nil_sublist _
| (n+1) (a::l) := list.cons_sublist_cons _ (list.take_sublist _ _)
lemma list.take_subset (n : ℕ) (l : list α) : l.take n ⊆ l :=
list.subset_of_sublist (list.take_sublist _ _)
#print list.mem_diff_iff_of_nop
lemma exists_intermediate_set {A B : finset α} (i : ℕ)
(h₁ : i + card B ≤ card A) (h₂ : B ⊆ A) :
∃ (C : finset α), B ⊆ C ∧ C ⊆ A ∧ card C = i + card B :=
begin
cases A with A hA, cases B with B hB,
induction A using quotient.induction_on with A,
induction B using quotient.induction_on with B,
classical,
refine ⟨⟨⟦((B.diff A).take i) ++ A⟧,
list.nodup_append.2 ⟨list.nodup_of_sublist (list.take_sublist _ _)
(list.nodup_diff hB), hA, list.disjoint_left.2 (λ a ha h, _)⟩⟩, _⟩,
have := list.take_subset _ _ ha, finish [list.mem_diff_iff_of_nodup hB],
dsimp, simp [finset.subset_iff],
end
#exit
import data.rat.order data.equiv.denumerable data.rat.denumerable
structure rat_iso_rat_without_zero : Type :=
(to_fun : ℚ → ℚ)
(map_ne_zero : ∀ x, to_fun x ≠ 0)
(exists_map_of_ne_zero : ∀ y ≠ 0, ∃ x, to_fun x = y)
(injective : ∀ x y, to_fun x = to_fun y → x = y)
(map_le_map : ∀ x y, x ≤ y → to_fun x ≤ to_fun y)
def denumerable_rat : ℕ → ℕ × list ℚ
| 0 := ⟨1, [0]⟩
| (n+1) :=
let ⟨i, l⟩ := denumerable_rat n in
have h : ∃ m : ℕ, let p := denumerable.equiv₂ ℕ (ℤ × ℕ+) (m + i) in
nat.coprime p.1.nat_abs p.2,
from sorry,
let m := nat.find h in
let p := denumerable.equiv₂ ℕ (ℤ × ℕ+) (m + i) in
⟨m + i + 1, ⟨p.1, p.2, p.2.2, nat.find_spec h⟩ :: l⟩
def denumerable_rat' : ℕ → list ℚ
| 0 := []
| (n+1) :=
let p := denumerable.equiv₂ ℕ (ℤ × ℕ+) n in
if h : p.1.nat_abs.coprime p.2.1
then ⟨p.1, p.2.1, p.2.2, h⟩ :: denumerable_rat' n
else denumerable_rat' n
#eval denumerable_rat' 10000
def blah : ℕ → list {x : ℚ // x ≠ 0} × list {x : ℚ // x ≠ 0}
| 0 := ⟨[], [⟨-1, dec_trivial⟩]⟩
| (n+1) :=
let ⟨i, lq, ln, lq0⟩ := blah n in
have h : ∃ m : ℕ, let p := denumerable.equiv₂ ℕ (ℤ × ℕ+) (m + i) in
nat.coprime p.1.nat_abs p.2,
from sorry,
let m := nat.find h in
let p := denumerable.equiv₂ ℕ (ℤ × ℕ+) (m + i) in
⟨m + i + 1, ⟨p.1, p.2, p.2.2, nat.find_spec h⟩ :: lq,
_, _⟩
-- set_option profiler true
-- #eval ((denumerable_rat 100)).2
-- #eval (((list.range 100).map (denumerable.equiv₂ ℕ ℚ))).reverse
-- -- instance denumerable_rat_without_zero :
-- -- denumerable {x : ℚ // x ≠ 0} :=
-- #eval denumerable.equiv₂ ℚ ℕ 0
-- def inbetween (a b : {x : ℚ // x ≠ 0}) : {x : ℚ // x ≠ 0} :=
-- if h : (a : ℚ) + b = 0
-- then ⟨((2 : ℚ) * a + b)/ 3,
-- div_ne_zero (by rw [two_mul, add_assoc, h, add_zero]; exact a.2) (by norm_num)⟩
-- else ⟨(a + b) / 2, div_ne_zero h (by norm_num)⟩
-- attribute [priority 10000] denumerable_rat_without_zero
-- def rat_iso_rat_without_zero_aux : ℕ → list {x : ℚ // x ≠ 0}
-- | 0 := [denumerable.equiv₂ ℕ {x : ℚ // x ≠ 0} 0]
-- | (n+1) :=
-- let q := denumerable.equiv₂ ℕ ℚ (n+1) in
-- let l := rat_iso_rat_without_zero_aux n in
-- option.cases_on (l.filter (λ x : {x : ℚ // x ≠ 0}, x.1 ≤ q)).maximum
-- (option.cases_on (l.filter (λ x : {x : ℚ // x ≠ 0}, q ≤ x.1)).minimum
-- [] (λ x, _))
-- _
theorem nonempty_rat_iso_rat_without_zero :
nonempty rat_iso_rat_without_zero :=
open nat
def fsum : (ℕ → ℕ) → ℕ → ℕ :=
λ f n, nat.rec_on n (f 0) (λ n' ihn', f (nat.succ n') + ihn')
open nat
theorem fsum_zero (f) : fsum f 0 = f 0 := rfl
theorem fsum_succ (n f) : fsum f (succ n) = f (succ n) + fsum f n := rfl
def sq : ℕ → ℕ := λ n, n ^ 2
def cb : ℕ → ℕ := λ n, n ^ 3
lemma fsum_id_eq (n) : 2 * fsum id n = n * (n + 1) :=
begin
induction n with n ih,
{ refl },
{ rw [fsum_succ, mul_add, ih, succ_eq_add_one, id.def],
ring }
end
lemma fsum_cb_eq (n) : 4 * fsum cb n = (n * (n + 1)) * (n * (n + 1)) :=
begin
induction n with n ih,
{ refl },
{ rw [fsum_succ, mul_add, ih, succ_eq_add_one, cb],
simp [mul_add, add_mul, nat.pow_succ, bit0, bit1, mul_assoc,
mul_comm, mul_left_comm, add_comm, add_assoc, add_left_comm] }
end
theorem nicomachus (n) : sq (fsum id n) = fsum cb n :=
(nat.mul_left_inj (show 0 < 4, from dec_trivial)).1
(calc 4 * sq (fsum id n) = (2 * fsum id n) * (2 * fsum id n) :
by simp only [sq, ← nat.pow_eq_pow]; ring
... = (n * (n + 1)) * (n * (n + 1)) : by rw [fsum_id_eq]
... = _ : by rw [fsum_cb_eq])
#exit
lemma pow_sqr_aux_succ (gas b e : ℕ) :
pow_sqr_aux (succ gas) b e =
prod.cases_on (bodd_div2 e)
(λ r e', bool.cases_on r
(pow_sqr_aux gas (b * b) e')
(b * pow_sqr_aux gas (b * b) e')) := rfl
def pow_sqr (b e : ℕ) : ℕ := pow_sqr_aux e b e
lemma bodd_eq_ff : ∀ n, bodd n = ff ↔ even n
| 0 := by simp
| (n+1) := by rw [bodd_succ, even_add, ← bodd_eq_ff]; simp
lemma pow_eq_aux (gas b e : ℕ) (h : e ≤ gas) : pow_sqr_aux gas b e = b ^ e :=
begin
induction gas with gas ih generalizing e b,
{ rw [nat.eq_zero_of_le_zero h], refl },
{ rw [pow_sqr_aux_succ],
cases e with e,
{ dsimp [bodd_div2],
rw [ih _ _ (nat.zero_le _), nat.pow_zero] },
{ rw [bodd_div2_eq],
have : div2 (succ e) < succ gas,
from lt_of_lt_of_le
(by rw [div2_val]; exact nat.div_lt_self (nat.succ_pos _) dec_trivial)
h,
rcases hb : bodd (succ e) with tt | ff,
{ dsimp,
have heven : even (succ e), by rwa bodd_eq_ff at hb,
rw [ih _ _ (nat.le_of_lt_succ this), div2_val, ← nat.pow_two,
← nat.pow_mul, nat.mul_div_cancel' heven] },
{ dsimp,
have hodd : succ e % 2 = 1, { rw [← not_even_iff, ← bodd_eq_ff, hb], simp },
rw [ih _ _ (nat.le_of_lt_succ this), div2_val, ← nat.pow_two,
← nat.pow_mul, mul_comm, ← nat.pow_succ, nat.succ_eq_add_one,
add_comm],
suffices : b ^ (succ e % 2 + 2 * (succ e / 2)) = b ^ succ e, rwa hodd at this,
rw [nat.mod_add_div] } } }
end
theorem pow_eq (b e : ℕ) : pow_sqr b e = b ^ e :=
pow_eq_aux _ _ _ (le_refl _)
#exit
import data.fintype.basic
open finset
lemma mul_comm_of_card_eq_four (G : Type u) [fintype G] [group G]
(hG4 : fintype.card G = 4) (g h : G) : G, g * h = h * g :=
example {G : Type*} [fintype G] [group G] (h4 : fintype.card G ≤ 4) :
∀ x y : G, x * y = y * x :=
λ g h, classical.by_contradiction $ λ H, begin
have hn : multiset.nodup [x * y, y * x, x, y, 1],
{ finish [mul_right_eq_self, mul_left_eq_self, mul_eq_one_iff_eq_inv] },
exact absurd (le_trans (card_le_of_subset (subset_univ ⟨_, hn⟩)) hG4) dec_trivial
end
#exit
import topology.metric_space.closeds
open nat
def strong_rec_on_aux {P : ℕ → Sort*}
(h : Π n : ℕ, (Π m < n, P m) → P n) :
Π n m, m < n → P m :=
λ n, nat.rec_on n (λ m h₁, absurd h₁ (not_lt_zero _))
(λ n ih m h₁, or.by_cases (lt_or_eq_of_le (le_of_lt_succ h₁))
(ih _)
(λ h₁, by subst m; exact h _ ih))
lemma strong_rec_on_aux_succ {P : ℕ → Sort*}
(h : Π n : ℕ, (Π m < n, P m) → P n) (n m h₁):
strong_rec_on_aux h (succ n) m h₁ =
or.by_cases (lt_or_eq_of_le (le_of_lt_succ h₁))
(λ hmn, strong_rec_on_aux h _ _ hmn)
(λ h₁, by subst m; exact h _ (strong_rec_on_aux h _)) := rfl
theorem nat.strong_rec_on_beta_aux {P : ℕ → Sort*} {h} {n : ℕ} :
(nat.strong_rec_on n h : P n) =
(strong_rec_on_aux h (succ n) n (lt_succ_self _)) := rfl
theorem nat.strong_rec_on_beta {P : ℕ → Sort*} {h} {n : ℕ} :
(nat.strong_rec_on n h : P n) =
h n (λ m hmn, (nat.strong_rec_on m h : P m)) :=
begin
simp only [nat.strong_rec_on_beta_aux,
strong_rec_on_aux_succ, or.by_cases, dif_pos, not_lt, dif_neg],
congr, funext m h₁,
induction n with n ih,
{ exact (not_lt_zero _ h₁).elim },
{ cases (lt_or_eq_of_le (le_of_lt_succ h₁)) with hmn hmn,
{ simp [← ih hmn, strong_rec_on_aux_succ, or.by_cases, hmn] },
{ subst m, simp [strong_rec_on_aux_succ, or.by_cases] } }
end
def strong_rec' {P : ℕ → Sort*} (h : ∀ n, (∀ m, m < n → P m) → P n) : ∀ (n : ℕ), P n
| n := h n (λ m hm, strong_rec' m)
set_option profiler true
#reduce strong_rec'
(λ n, show (∀ m, m < n → ℕ) → ℕ, from nat.cases_on n 0 (λ n h, h 0 (succ_pos _)))
500
#reduce nat.strong_rec_on
500
(λ n, show (∀ m, m < n → ℕ) → ℕ, from nat.cases_on n 0 (λ n h, h 0 (succ_pos _)))
#eval strong_rec'
(λ n, show (∀ m, m < n → ℕ) → ℕ, from nat.cases_on n 0 (λ n h, h 0 (succ_pos _)))
10000000
#eval nat.strong_rec_on
10000000
(λ n, show (∀ m, m < n → ℕ) → ℕ, from nat.cases_on n 0 (λ n h, h 0 (succ_pos _)))
#exit
constant layout : Type → Type
--constant edge_sequence : Type → Type
--inductive T : Π {b : bool}, cond b (layout G) (Σ L : layout G, )
mutual inductive edge_sequence, add_edge_sequence
with edge_sequence : layout G → Type
| single {L : layout G} {e : G.edges} (h : e ∈ L.remaining_edges) : edge_sequence L
| cons {L : layout G} (S : edge_sequence L) {e : G.edges}
(h : e ∈ (add_edge_sequence S).1.remaining_edges) : edge_sequence L
with add_edge_sequence : Π {L : layout G}, edge_sequence L → layout G × finset G.boxes
| L (single h) := L.add_edge h
| L (cons S h) := let ⟨L', B⟩ := L.add_edge_sequence S in let ⟨L'', B'⟩ := L.1.add_edge h in ⟨L'', B ∪ B'⟩
import topology.basic topology.metric_space.closeds
#print closeds
lemma closure_inter_subset_inter_closure' {X Y : set ℝ} :
closure (X ∩ Y) ⊆ closure X ∩ closure Y :=
galois_connection.u_inf
begin show galois_connection (closure : set ℝ → closeds ℝ) (subtype.val), end
#exit
import data.fintype.basic
open finset
set_option class.instance_max_depth 1000
#eval (((univ : finset (vector (fin 10) 3)).filter
(λ v : vector (fin 10) 3, (v.nth 0 = 6 ∨ v.nth 1 = 8 ∨ v.nth 2 = 2)
∧ (7 : fin 10) ∉ v.1 ∧ (3 : fin 10) ∉ v.1 ∧ (8 : fin 10) ∉ v.1
∧ ((v.nth 1 = 6 ∨ v.nth 2 = 6) ∨ (v.nth 0 = 1 ∨ v.nth 2 = 1) ∨
(v.nth 0 = 4 ∨ v.nth 1 = 4))
∧ ((v.nth 1 = 7 ∨ v.nth 2 = 7) ∨ (v.nth 0 = 8 ∨ v.nth 2 = 8) ∨
(v.nth 0 = 0 ∨ v.nth 1 = 0))
)).map
⟨vector.to_list, subtype.val_injective⟩)
universes u v
def map_copy_aux {α : Type u} {β : Type v} {n m : ℕ} (f : α → β) :
ℕ → array n α → array m β → array m β
| r x y := if h : r < n ∧ r < m then
let fn : fin n := ⟨r, and.elim_left h⟩ in
let fm : fin m := ⟨r, and.elim_right h⟩ in
have wf : m - (r + 1) < m - r,
from nat.lt_of_succ_le $ by rw [← nat.succ_sub h.2, nat.succ_sub_succ],
map_copy_aux (r + 1) x $ y.write fm (f $ x.read fn)
else y
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ a, m - a.1)⟩]}
#exit
import data.zmod.basic
#eval fintype.choose _
(show ∃! f : zmod 4 → zmod 4, ∀ x y, f (x * y) = f x * f y
∧ ∀ x, f x = 1 ↔ x = 1 ∧ f ≠ id, from sorry) 3
example (n : ℕ) (hn : n ≤ 4) : false :=
begin
classical,
interval_cases n,
repeat {sorry}
end
theorem zagier (R : Type) [comm_ring R]
[fintype (units R)] : card (units R) ≠ 5 :=
if h : (-1 : R) = 1
then _
else _
#exit
import data.finset
#print no_zero_divisors
open nat
lemma mul_add (t a b : nat) : t * (a + b) = t * a + t * b :=
begin
induction b with B hB,
-- b base case
rw add_zero a,
rw mul_zero t,
rw add_zero (t*a),
refl,
-- joint inductive step
rw add_succ a B,
rw mul_succ t (a + B),
rw hB,
rw add_assoc (t*a) (t*B) t,
rw <- mul_succ t B,
end
#exit
import data.finset
import tactic
/-!
Test
-/
#print auto.split_hyps
open_locale classical
namespace tactic.interactive
meta def split_hyps := auto.split_hyps
end tactic.interactive
lemma Z (X : Type*) (a b c d e f : X) (h : ({a,b,c} : set X) = {d,e,f}) :
a = d ∧ b = e ∧ c = f ∨ a = d ∧ b = f ∧ c = e ∨ a = e ∧ b = d ∧ c = f
∨ a = e ∧ b = f ∧ c = d ∨ a = f ∧ b = d ∧ c = e ∨ a = f ∧ b = e ∧ c = d :=
begin sorry
-- simp [set.ext_iff] at h,
-- have := h a, have := h b, have := h c, have := h d, have := h e, have := h f,
-- by_cases a = d; by_cases a = e; by_cases a = f;
-- by_cases b = d; by_cases b = e; by_cases b = f;
-- by_cases c = d; by_cases c = e; by_cases c = f;
-- simp [*, eq_comm] at *; simp * at *; simp * at *,
-- finish using [h a, h b, h c, h d, h e, h f]
end
example : false :=
begin
have := Z ℕ 0 1 1 0 0 1,
simpa using this,
end
example (X : Type*) (a b c d : X) :
(a = c ∧ b = d) ∨ (a = d ∧ b = c) ↔
∀ x : X, (x = a ∨ x = b) ↔ (x = c ∨ x = d) :=
⟨λ h x, by rcases h with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩; simp [or_comm],
λ h, begin
have := h a, have := h b, have := h c, have := h d,
by_cases a = c; by_cases a = d;
simp [*, eq_comm] at *; simp * at *; simp * at *
end⟩
#exit
import data.finset
lemma X (X : Type) [decidable_eq X] (x y : X) : ({x, y} : finset X) = {y, x} :=
begin
simp [finset.ext, or_comm]
end
lemma Y (X : Type) [decidable_eq X] (x y : X) : ({x, y} : finset X) = {y, x} :=
begin
finish [finset.ext],
end
#print X
#print Y
#exit
import all
def fact (n : ℕ) : ℕ :=
let f : ℕ → ℕ := λ n, nat.rec_on n 1 (λ n fact, (n + 1) * fact) in
f n
def fact' (n : ℕ) : ℕ :=
let f : ℕ → ℕ := λ n, well_founded.fix nat.lt_wf
(λ n fact, show ℕ, from nat.cases_on n (λ _, 1)
(λ n fact, (n + 1) * fact n n.lt_succ_self) fact)
n in
f n
#eval fact' 5
#exit
import data.fintype.basic algebra.big_operators
open finset
open_locale classical
lemma prod_add {α R : Type*} [comm_semiring R] (f g : α → R) (s : finset α) :
s.prod (λ a, f a + g a) =
s.powerset.sum (λ t : finset α, t.prod f * (s.filter (∉ t)).prod g) :=
calc s.prod (λ a, f a + g a)
= s.prod (λ a, ({false, true} : finset Prop).sum
(λ p : Prop, if p then f a else g a)) : by simp
... = (s.pi (λ _, {false, true})).sum (λ p : Π a ∈ s, Prop,
s.attach.prod (λ a : {a // a ∈ s}, if p a.1 a.2 then f a.1 else g a.1)) : prod_sum
... = s.powerset.sum (λ (t : finset α), t.prod f * (s.filter (∉ t)).prod g) : begin
refine eq.symm (sum_bij (λ t _ a _, a ∈ t) _ _ _ _),
{ simp [subset_iff]; tauto },
{ intros t ht,
erw [prod_ite (λ a : {a // a ∈ s}, f a.1) (λ a : {a // a ∈ s}, g a.1) (λ x, x)],
refine congr_arg2 _
(prod_bij (λ (a : α) (ha : a ∈ t), ⟨a, mem_powerset.1 ht ha⟩)
_ _ _
(λ b hb, ⟨b, by cases b; finish⟩))
(prod_bij (λ (a : α) (ha : a ∈ s.filter (∉ t)), ⟨a, by simp * at *⟩)
_ _ _
(λ b hb, ⟨b, by cases b; finish⟩));
intros; simp * at *; simp * at * },
{ finish [function.funext_iff, finset.ext, subset_iff] },
{ assume f hf,
exact ⟨s.filter (λ a : α, ∃ h : a ∈ s, f a h),
by simp, by funext; intros; simp *⟩ }
end
lemma card_sub_card {α : Type*} {s t : finset α} (hst : t ⊆ s) :
card s - card t = (s.filter (∉ t)).card :=
begin
rw [nat.sub_eq_iff_eq_add (card_le_of_subset hst), ← card_disjoint_union],
exact congr_arg card (finset.ext.2 $ λ _, by split; finish [subset_iff]),
finish [disjoint_left]
end
lemma sum_pow_mul_eq_add_pow
{α R : Type*} [comm_semiring R] (a b : R) (s : finset α) :
s.powerset.sum (λ t : finset α, a ^ t.card * b ^ (s.card - t.card)) =
(a + b) ^ s.card :=
begin
rw [← prod_const, prod_add],
refine finset.sum_congr rfl (λ t ht, _),
rw [prod_const, prod_const, card_sub_card (mem_powerset.1 ht)]
end
#exit
import topology.metric_space.basic
noncomputable theory
variables {X : Type*} [metric_space X]
variables {Y : Type*} [metric_space Y]
#reduce 200 - 10
/- The metric of any two elements of a metric space is non-negative -/
theorem metric_nonneg : ∀ x y : X, 0 ≤ dist x y := λ x y,
begin
suffices : 0 ≤ dist y x + dist x y - dist y y,
rw [dist_self, dist_comm, sub_zero] at this,
linarith,
linarith [dist_triangle y x y]
end
/- The product of two metric spaces is also a metric space -/
instance : metric_space (X × Y) :=
{ dist := λ ⟨x₀, y₀⟩ ⟨x₁, y₁⟩, dist x₀ x₁ + dist y₀ y₁,
dist_self := λ ⟨x, y⟩, show dist x x + dist y y = 0, by simp,
eq_of_dist_eq_zero := -- Why can't I use λ ⟨x₀, y₀⟩ ⟨x₁, y₁⟩ here?
λ ⟨x₀, y₀⟩ ⟨x₁, y₁⟩, begin
--rintros ⟨x₀, y₀⟩ ⟨x₁, y₁⟩,
-- show dist x₀ x₁ + dist y₀ y₁ = 0 → (x₀, y₀) = (x₁, y₁), intro h,
-- suffices : dist x₀ x₁ = 0 ∧ dist y₀ y₁ = 0,
-- rwa [eq_of_dist_eq_zero this.left, eq_of_dist_eq_zero this.right],
-- split,
-- all_goals {linarith [metric_nonneg x₀ x₁, metric_nonneg y₀ y₁, h]}
end,
dist_comm := λ ⟨x₀, y₀⟩ ⟨x₁, y₁⟩,
show dist x₀ x₁ + dist y₀ y₁ = dist x₁ x₀ + dist y₁ y₀, by simp [dist_comm],
dist_triangle := λ ⟨x₀, y₀⟩ ⟨x₁, y₁⟩ ⟨x₂, y₂⟩,
show dist x₀ x₂ + dist y₀ y₂ ≤ dist x₀ x₁ + dist y₀ y₁ + (dist x₁ x₂ + dist y₁ y₂),
by linarith
#exit
def definitely_not_false : bool := tt
attribute [irreducible] definitely_not_false
example (f : bool → bool) (h : f definitely_not_false = ff) : f tt = ff := by rw h
example (h : definitely_not_false = ff) : tt = ff := by rw h
attribute [semireducible] definitely_not_false
example (f : bool → bool) (h : f definitely_not_false = ff) : f tt = ff := by rw h
example (h : definitely_not_false = ff) : tt = ff := by rw h
attribute [reducible] definitely_not_false
example (f : bool → bool) (h : f definitely_not_false = ff) : f tt = ff := by rw h -- only one that works
example (h : definitely_not_false = ff) : tt = ff := by rw h
#exit
import data.fintype
#print classical.dec_eq
#print subtype.decidable_eq
#exit
import logic.basic
def X : Type := empty → ℕ
lemma hx : X = (empty → X) :=
calc X = Π i : empty, (λ h : empty, ℕ) i : rfl
... = Π i : empty, (λ h : empty, X) i :
have (λ h : empty, ℕ) = (λ h : empty, X),
from funext empty.elim,
this ▸ rfl
example : X = ℕ :=
begin
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
rw hx,
end
#exit
prelude
inductive eq {α : Sort*} (a : α) : α → Sort
| refl : eq a
infix ` = `:50 := eq
constant nat : Type
constant nat.zero : nat
constant nat.succ : nat → nat
constant cast {α : Sort*} (zero : α) (succ : α → α) : nat → α
constant cast_zero {α : Sort*} (zero : α) (succ : α → α) : cast zero succ nat.zero = zero
constant cast_succ {α : Sort*} (zero : α) (succ : α → α) (n : nat) :
cast zero succ (nat.succ n) = succ (cast zero succ n)
constant cast_unique {α : Sort*} (zero : α) (succ : α → α)
(f : nat → α) (hzero : f nat.zero = zero)
(hsucc : ∀ n, f (nat.succ n) = succ (f n)) :
∀ n, f n = cast zero succ n
lemma nat.rec_on {C : nat → Sort*} (n : nat)
(hzero : C nat.zero)
(hsucc : Π (a : nat), C a → C (nat.succ a)) :
C n :=
cast _ _ _
#exit
import category_theory.functor_category
open category_theory
open category_theory.category
universes v₁ v₂ u₁ u₂
namespace tactic.interactive
meta def poor_mans_rewrite_search : tactic unit :=
`[ iterate 5
{ repeat {rw assoc},
try {rw nat_trans.naturality},
try {simp},
repeat {rw ←assoc},
try {rw nat_trans.naturality},
try {simp}
}]
end tactic.interactive
variables {C : Type u₁} [𝒞 : category.{v₁} C] {D : Type u₂} [𝒟 : category.{v₂} D]
include 𝒞 𝒟
variables (X Y U V: C)
variables (f : X ⟶ Y) (g : V ⟶ U)(h : Y ⟶ V)
variables (F G : C ⥤ D)
variables (α : F ⟶ G)
/- The diagram coming from g and α
F(f) F(h) F(g)
F X ---> F Y ---> F V ----> F U
| | | |
|α(X) |α(Y) | α (v) | α (U)
v v v v
G X ---> G Y ----> G(V) ---- G(U)
G(f) G(h) G(g)
commutes.
-/
example :
F.map f ≫ α.app Y ≫ G.map h ≫ G.map g =
F.map f ≫ F.map h ≫ α.app V ≫ G.map g :=
begin
poor_mans_rewrite_search,
end
#exit
import data.equiv.basic
#
axiom univalence {α β : Sort*} : α ≃ β → α = β
#exit
--import tactic.suggest
import data.nat.basic algebra.group_power tactic.ring
lemma X1 (a b : ℤ) : a + (a + (a + b)) = a * 3 + b := by ring
--lemma X2 (a b : ℤ) : (a * (a * (a * (a * b))))
example (a b c x : ℤ) (hx : x^3 = -3) :
(a * x^2 + b * x + c)^3 =
- 9 * a^2 * b * x^2
+ 3 * a * c^2 * x^2 +
3 * b^2 * c * x^2
+
3 * b * c^2 * x
- 9 * a * b^2 * x
- 9 * a^2 * c * x
+ 9 * a ^ 3
-3 * b^3
- 18 * a * b * c
+ c^3 :=
begin
simp [pow_succ, mul_add, add_mul, mul_assoc, mul_comm,
mul_left_comm] at *,
simp only [← mul_assoc, ← add_assoc],
have : ∀ y, x * (x * (x * y)) = -3 * y, { intro, rw [← hx], ring },
simp [hx, this],
ring,
end
local attribute [simp] nat.succ_pos'
set_option trace.simplify.rewrite true
def ack : ℕ → ℕ → ℕ
| 0 y := y+1
| (x+1) 0 := ack x 1
| (x+1) (y+1) := ack x (ack (x+1) y)
using_well_founded {rel_tac := λ _ _, `[exact ⟨λ _ _, true, sorry⟩],
dec_tac := `[trivial]}
#eval ack 3 5
#exit
import category_theory.monoidal.types
#reduce terminal Type
#exit
import data.zmod.basic data.nat.totient group_theory.order_of_element
local notation `φ` := nat.totient
open fintype finset
instance {n : ℕ+} : fintype (units (zmod n)) :=
fintype.of_equiv _ zmod.units_equiv_coprime.symm
lemma card_units_eq_totient (n : ℕ+) :
card (units (zmod n)) = φ n :=
calc card (units (zmod n)) = card {x : zmod n // x.1.coprime n} :
fintype.card_congr zmod.units_equiv_coprime
... = φ n : finset.card_congr
(λ a _, a.1.1)
(λ a, by simp [a.1.2, a.2.symm] {contextual := tt})
(λ _ _ h, by simp [subtype.val_injective.eq_iff, (fin.eq_iff_veq _ _).symm])
(λ b hb, ⟨⟨⟨b, by finish⟩, nat.coprime.symm (by simp at hb; tauto)⟩, mem_univ _, rfl⟩)
lemma pow_totient {n : ℕ+} (x : units (zmod n)) : x ^ φ n = 1 :=
by rw [← card_units_eq_totient, pow_card_eq_one]
@[simp] lemma totient_zero : φ 0 = 0 := rfl
def coprime.to_units {n : ℕ+} {p : ℕ} (h : nat.coprime p n) : units (zmod n) :=
lemma pow_totient' {n : ℕ+} {p : ℕ} (h : nat.coprime p n) : p ^ φ n ≡ 1 [MOD n] :=
begin
cases n, { simp },
{ erw [← @zmod.eq_iff_modeq_nat ⟨n.succ, nat.succ_pos _⟩, nat.cast_pow],
let x := zmod.units_equiv_coprime.symm.to_fun
⟨(p : zmod ⟨n.succ, nat.succ_pos _⟩), by simpa using h⟩, }
end
#exit
import tactic.ring linear_algebra.basic linear_algebra.dual
variables {R : Type*} [field R]
open finset
example {R : Type*} [ring R] (x₁ x₂ y₁ y₂ : R) :
Σ' z₁ z₂ : R, z₁ ^ 2 + z₂ ^ 2 = (x₁ ^ 2 + x₂ ^ 2) * (y₁ ^ 2 + y₂ ^ 2) :=
⟨x₁ * y₁ + x₂ * y₂, x₁ * y₂ - x₂ * y₁, begin
simp only [mul_add, add_mul, add_comm, add_right_comm, pow_two,
sub_eq_add_neg],
simp only [(add_assoc _ _ _).symm],
end⟩
example {n : ℕ}
(hn : ∀ x₁ x₂ : fin (2 ^ n) → R, ∃ y : fin (2 ^ n) → R,
univ.sum (λ i, y i ^2) = univ.sum (λ i, x₁ i ^ 2) * univ.sum (λ i, x₂ i ^ 2)) :
#exit
import data.polynomial
open polynomial
#print is_unit
example (A B : Type) [comm_ring A] [comm_ring B] (f : A →+* B)
(p : polynomial A) (hp : monic p) (hip : irreducible (p.map f)) :
irreducible p :=
classical.by_contradiction $ λ h,
begin
dsimp [irreducible] at h,
push_neg at h,
cases h,
{ sorry },
{ rcases h with ⟨q, r, hpqr, hq, hr⟩,
have := hip.2 (q.map f) (r.map f) (by rw [← map_mul, hpqr]),
}
end
#exit
inductive eq2 {α : Type} (a : α) : α → Type
| refl : eq2 a
lemma X {α : Type} (a b : α) (h₁ h₂ : eq2 a b) : eq2 h₁ h₂ :=
begin
cases h₁, cases h₂, exact eq2.refl _,
end
set_option pp.proofs true
#print X
inductive X : Type
| mk : X → X
example : ∀ x : X, false :=
begin
assume x,
induction x,
end
instance : fintype X := ⟨∅, λ x, X.rec_on x (λ _, id)⟩
#print X.rec
inductive Embedding (b a:Sort u) : Sort u
| Embed : forall (j:b -> a), (forall (x y:b), j x = j y -> x = y) -> Embedding
#print Embedding.rec
def restrict {a b:Sort u} (r:a -> a -> Prop) (e:Embedding b a) (x y: b) : Prop :=
begin
destruct e, -- error
end
#print Embedding
#exit
def injective {X : Type} {Y : Type} (f : X → Y) : Prop :=
∀ a b : X, f a = f b → a = b
theorem injective_comp3 {X Y Z : Type} (f : X → Y) (g : Y → Z) :
injective f → injective g → injective (g ∘ f) :=
λ hf hg _ _, (hf _ _ ∘ hg _ _)
-- dunfold injective,
-- intros hf hg a b,
-- end
#exit
import data.list data.equiv.basic data.fintype
noncomputable theory
open_locale classical
universe u
variables (α β : Type u)
open finset list
@[simp] lemma list.nth_le_pmap {l : list α} {p : α → Prop}
(f : Π (a : α), p a → β) (h : ∀ a, a ∈ l → p a) (n : ℕ)
(hn : n < l.length) :
(l.pmap f h).nth_le n (by simpa using hn) = f (l.nth_le n hn)
(h _ (nth_le_mem _ _ _)) :=
by simp [pmap_eq_map_attach]
@[simp] lemma list.nth_le_fin_range {n i : ℕ} (h : i < n) :
(fin_range n).nth_le i (by simpa using h) = ⟨i, h⟩ :=
by simp only [fin_range]; rw [list.nth_le_pmap]; simp *
lemma fin_range_map_nth_le {l : list α} :
(list.fin_range l.length).map (λ x, l.nth_le x.1 x.2) = l :=
list.ext_le (by simp) (λ _ _ _, by rw [nth_le_map, list.nth_le_fin_range])
lemma length_filter_eq_card_fin {l : list α} (p : α → Prop) :
list.length (list.filter p l) =
(univ.filter (λ x : fin l.length, p (l.nth_le x.1 x.2))).card :=
calc list.length (list.filter p l)
= (((list.fin_range l.length).map (λ x : fin l.length, l.nth_le x.1 x.2)).filter p).length :
by rw [fin_range_map_nth_le]
... = ((list.fin_range l.length).filter (λ x : fin l.length, p (l.nth_le x.1 x.2))).length :
by rw [filter_of_map, length_map]
... = (finset.mk
((list.fin_range l.length).filter (λ x : fin l.length, p (l.nth_le x.1 x.2)))
(list.nodup_filter _ (nodup_fin_range _))).card : rfl
... = _ : congr_arg card (finset.ext.2 (by simp))
lemma card_filter_univ [fintype α] (p : α → Prop) :
card (univ.filter p) = fintype.card (subtype p) :=
begin
refine (finset.card_congr (λ a _, ↑a) _ _ _).symm,
{ rintros ⟨_, h⟩ _; simp * },
{ rintros ⟨_, _⟩ ⟨_, _⟩; simp },
{ intros b hb,
refine ⟨⟨b, (finset.mem_filter.1 hb).2⟩, by simp⟩, }
end
#print classical.axiom_of_choice
example {α : Sort*} {β : α → Sort*} :
(∀ a, nonempty (β a)) ↔ nonempty (Π a, β a) :=
by library_search
example {l₁ l₂ : list β} {r : α → β → Prop}
(nodup : ∀ (x y : α) (b : β), x ≠ y → ¬ (r x b ∧ r y b))
(h : ∀ a : α, l₁.countp (r a) = l₂.countp (r a)) :
l₁.countp (λ b, ∃ a, r a b) = l₂.countp (λ b, ∃ a, r a b) :=
begin
simp only [countp_eq_length_filter, length_filter_eq_card_fin,
card_filter_univ, fintype.card_eq, skolem_nonempty] at *,
cases h with f,
split,
exact ⟨λ x, ⟨f x, _⟩, _, _, _⟩
end
#exit
prelude
import init.logic
set_option old_structure_cmd true
universe u
class comm_semigroup (α : Type u) extends has_mul α
class monoid (α : Type u) extends has_mul α, has_one α :=
(one_mul : ∀ a : α, 1 * a = a)
class comm_monoid (α : Type u) extends comm_semigroup α, has_one α :=
(one_mul : ∀ a : α, 1 * a = a)
set_option pp.all true
class X (α : Type u) extends monoid α, comm_monoid α
#exit
--import data.real.basic
def injective (f : ℤ → ℤ ) := ∀ x x', f x = f x' → x = x'
example (f g : ℤ → ℤ) :
injective f → injective g → injective (g ∘ f) :=
begin
intros hf hg x x' gof,
rw hf x,
rw hg (f x),
exact gof,
end
open finset
open_locale classical
example {α β : Type} {x : α} {v : β → α} [comm_monoid α] [fintype β] :
finset.univ.prod (λ (i : option β), i.elim x v) = x * finset.univ.prod v :=
calc univ.prod (λ (i : option β), i.elim x v)
= x * (univ.erase (none)).prod (λ (i : option β), i.elim x v) :
begin
conv_lhs { rw [← insert_erase (mem_univ (none : option β))] },
rw [prod_insert (not_mem_erase _ _)], refl
end
... = x * finset.univ.prod v :
begin
refine congr_arg2 _ rfl (prod_bij (λ a _, some a) _ _ _ _).symm,
{ simp },
{ intros, refl },
{ simp },
{ assume b,
cases b with b,
{ simp },
{ intro, use b, simp } }
end
import data.zmod.quadratic_reciprocity
open finset
def Fib : ℕ → ℕ
| 0 := 0
| 1 := 1
| (n + 2) := Fib n + Fib (n + 1)
theorem sum_Fib (n : ℕ) : 1 + (range n).sum Fib = Fib (n + 1) :=
by induction n; simp [sum_range_succ, Fib, *]
#print sum_Fib
#exit
import algebra.group_power tactic.ring
example (x y : ℤ) : y^4 + 9 * y^2 + 20 ≠ x^3 :=
suffices (y^2 + 5) * (y^2 + 4) ≠ x^3,
by ring at *; assumption,
assume h : (y^2 + 5) * (y^2 + 4) = x^3,
#exit
import data.finset
set_option profiler true
#eval (finset.range 200).filter (λ x, x % 2 = 0)
def has_min_element {A : Type} (R : A → A → Prop) : Prop :=
∃ x, ∀ y, R x y
axiom ax1 {n m: ℕ} : (n ≤ m) ↔ (∃ l : ℕ, n + l = m)
axiom ax2 {m n x y: ℕ} (h1 : x + n = y) (h2 : y + m = x): x = y ∧ (m = 0) ∧ (n = 0)
axiom ax3 {m n x y z : ℕ} (h1 : x + n = y) (h2 : y + m = z) : x + (n + m) = z
axiom ax4 : 1 ≠ 2
axiom ax5 (m n : ℕ) : ∃ l : ℕ, m + l = n ∨ n + l = m
axiom ax6 (n : ℕ) : 0 + n = n
theorem le_not_symmetric : ¬ (symmetric nat.less_than_or_equal) :=
λ h, absurd (@h 0 1 dec_trivial) dec_trivial
example : ¬ (equivalence nat.less_than_or_equal) :=
λ h, le_not_symmetric h.2.1
variables (U : Type) (P R: U → Prop)(Q : Prop)
example (h1a : ∃ x, P x) (h1b : ∃ x, R x) (h2 : ∀ x y, P x → R y → Q) : Q :=
begin
cases h1a with x hPx,
cases h1b with y hRy,
end
#eval (finset.range 10000).filter
(λ y, ∃ x ∈ finset.range (nat.sqrt y), y^2 + 9 * y + 20 = x)
-- #eval let n : ℕ+ := 511 in (finset.univ).filter
-- (λ y : zmod n, ∃ x, y^4 + 9 * y ^ 2 + 20 = x)
example (a b s : ℚ) (hs : s * s = -35):
(a + b * (1 + s)/ 2)^3 =
a^3 + 3 * a^2 * b / 2 - 51 * a * b^2 / 2 - 13 * b ^ 3
+ (3 * a^2 * b /2+ 3 * a * b ^ 2 /2- 4 * b^3) * s:=
begin
simp [pow_succ, mul_add, add_mul, mul_comm s, mul_assoc,
mul_left_comm s, hs, div_eq_mul_inv],
ring,
-- simp [bit0, bit1, mul_add, add_mul, add_assoc, add_comm,
-- add_left_comm, mul_assoc, mul_comm, mul_left_comm],
end
#eval (finset.univ : finset (zmod 24 × zmod 24)).image
(λ x : zmod 24 × zmod 24, x.1^2 + 6 * x.2^2 )
#exit
import data.list
noncomputable theory
open_locale classical
universe u
variables {α : Type u} (a : α) (l : list α)
theorem count_eq_countp {h : decidable_pred (λ x, a = x)} :
l.count a = l.countp (λ x, a = x) := sorry
theorem count_eq_countp' : l.count a = l.countp (λ x, x = a) :=
begin
conv in (_ = a) { rw eq_comm, },
convert (count_eq_countp a l), -- error here
end
#exit
import data.nat.parity
open nat
example {x y : ℕ} : even (x^2 + y^2) ↔ even (x + y) :=
by simp [show 2 ≠ 0, from λ h, nat.no_confusion h] with parity_simps
#exit
import ring_theory.ideals algebra.associated
open ideal
local infix ` ≈ᵤ `: 50 := associated
variables {R : Type*} [integral_domain R]
(wf : well_founded (λ x y : R, span {y} < span ({x} : set R)))
(hex : ∀ p q : R, irreducible p → irreducible q → ¬ p ≈ᵤ q →
∃ x : R, x ∈ span ({p, q} : set R) ∧ x ≠ 0 ∧ x ≠ p ∧ x ≠ q ∧
(span {p} < span ({x} : set R) ∨ span {q} < span ({x} : set R)))
lemma exists_irreducible_factor {a : R} (hau : ¬ is_unit a) :
∃ p, irreducible p ∧ p ∣ a := sorry
include hex
example (a b : R) : ∀ (p q : R) (hp : irreducible p) (hq : irreducible q) (hpq : ¬ p ≈ᵤ q)
(hpa : p * b = q * a), p ∣ a :=
have ¬ is_unit a, from sorry,
well_founded.fix wf
begin
assume a ih p q hp hq hpq hpa,
cases exists_irreducible_factor this with r hr,
cases hex p q hp hq hpq with x hx,
have : span ({a} : set R) < span {x},
from hx.2.2.2.2.elim
(lt_of_le_of_lt sorry)
(lt_of_le_of_lt _),
end a
#exit
import data.nat.prime
open nat
theorem sqrt_two_irrational_V1 {a b : ℕ} (co : gcd a b = 1) : a^2 ≠ 2 * b^2 :=
assume h : a^2 = 2 * b^2,
have 2 ∣ a^2,
by simp [h],
have ha : 2 ∣ a,
from prime.dvd_of_dvd_pow prime_two this,
-- this line below is wrong
match ha with | ⟨c, aeq⟩ :=
have 2 * (2 * c^2) = 2 * b^2,
by simp [eq.symm h, aeq];
simp [nat.pow_succ, mul_comm, mul_assoc, mul_left_comm],
have 2 * c^2 = b^2,
from eq_of_mul_eq_mul_left dec_trivial this,
have 2 ∣ b^2,
by simp [eq.symm this],
have hb : 2 ∣ b,
from prime.dvd_of_dvd_pow prime_two this,
have 2 ∣ gcd a b,
from dvd_gcd ha hb,
have habs : 2 ∣ (1:ℕ),
by simp * at *,
show false, from absurd habs dec_trivial
end
#print sqrt_two_irrational_V1
#exit
example (A B : Prop) : A → (A ∧ B) ∨ (A ∧ ¬ B) :=
assume a : A,
classical.by_contradiction
(assume h : ¬((A ∧ B) ∨ (A ∧ ¬ B)),
have nb : ¬ B, from
assume b : B,
h (or.inl ⟨a, b⟩),
h (or.inr ⟨a, nb⟩))
#exit
import logic.basic
#print eq.drec_on
axiom choice (X : Type) : X ⊕ (X → empty)
def choice2 {α : Type} {β : α → Type*} (h : ∀ x, nonempty (β x)) :
nonempty (Π x, β x) :=
⟨λ x, sum.cases_on (choice (β x)) id
(λ f, false.elim (nonempty.elim (h x) (λ y, empty.elim (f y))))⟩
#exit
import data.sum linear_algebra.basic
example {α α' β β' : Type} (f : α → α') (g : β → β') :
α ⊕ β → α' ⊕ β'
| (sum.inl a) := sum.inl (f a)
| (sum.inr b) := sum.inr (g b)
example {A A' B B' : Type} [add_comm_group A]
[add_comm_group A'] [add_comm_group B] [add_comm_group B']
(f : A →+ A') (g : B →+ B') :
A × A' → B × B'
lemma inv_unique {x y z : M}
(hy : x * y = 1) (hz : z * x = 1) : y = z :=
by rw [← one_mul y, ← hz, mul_assoc, hy, mul_one]
#exit
import data.pfun
import data.list.defs
namespace tactic
meta def match_goals (ls : list (ℕ × ℕ)) : tactic unit := do
gs ← get_goals,
ls.mmap' $ λ ⟨a, b⟩, unify (gs.inth a) (gs.inth b),
set_goals gs
#print tactic.interactive.induction
meta def interactive.cases_symmetric
(a b : interactive.parse (lean.parser.pexpr std.prec.max)) : tactic unit := do
a ← to_expr a,
b ← to_expr b,
env ← get_env,
ty ← infer_type a,
let n := (env.constructors_of ty.get_app_fn.const_name).length,
(() <$ cases_core a [`a]); (() <$ cases_core b [`a]),
match_goals $ do
a ← list.range n,
b ← list.range n,
guard (b < a),
return (n * a + b, n * b + a)
end tactic
inductive weekday
| sun | mon | tue | wed | thu | fri | sat
example : weekday → weekday → nat :=
begin
intros a b,
cases_symmetric a b,
end
import init.data.nat.basic
import init.algebra.ring
import data.nat.parity
import init.algebra.norm_num
import data.equiv.list
import tactic.omega
import data.W
#print int.sizeof
#print subtype.range_val
#print W
def N : Type := W (λ b : bool, bool.cases_on b empty unit)
def F : N → ℕ := λ n, W.rec_on n
(λ b, bool.cases_on b (λ _ _, 0) (λ _ f, nat.succ (f ())))
def G : ℕ → N := λ n, nat.rec_on n
(W.mk ff empty.elim)
(λ _ ih, W.mk tt (λ _, ih))
lemma FG (n : ℕ) : F (G n) = n :=
nat.rec_on n rfl
(begin
dsimp [F, G],
assume n h,
rw h,
end)
lemma GF (n : N) : G (F n) = n :=
W.rec_on n
(λ b, bool.cases_on b
(λ b _, begin
have h : b = (λ x, empty.elim x), from funext (λ x, empty.elim x),
simp [G, F, h], refl,
end)
(λ f, begin
dsimp [F, G],
assume ih,
rw ih (),
congr, funext, congr,
end))
open finset
example {s : finset ℕ} (x : ℕ) (h : x ∈ s) : s \ {x} ⊂ s :=
finset.ssubset_iff.2 ⟨x, by simp,
λ y hy, (mem_insert.1 hy).elim (λ hxy, hxy.symm ▸ h) (by simp {contextual := tt})⟩
#eval denumerable.equiv₂ ℕ (ℕ × ℕ × ℕ × ℕ × ℕ) 15
3192
#eval 2^12
--Alice only sees r and Bob only sees c. The strategy isn't (r,c) → (...) but two maps, r→(r1 r2 r3) and c → (c1 c2 c3)
--I'm using 0 and 1 instead of Green and Red as the two options to fill squares. This makes checking parity of strategies easier
open nat
def checkStrategyrc (r c : ℕ) (strategy : ((ℕ → ℕ × ℕ × ℕ) × (ℕ → ℕ × ℕ × ℕ))) : Prop :=
--functionalize this with lists.
let r1 := (strategy.1 r).1,
r2 := (strategy.1 r).2.1,
r3 := (strategy.1 r).2.2,
c1 := (strategy.2 c).1,
c2 := (strategy.2 c).2.1,
c3 := (strategy.2 c).2.2
in even (r1 + r2 + r3) ∧ ¬ even (c1 + c2 + c3) ∧
((r = 1 ∧ c = 1 ∧ r1 = c1) ∨ (r = 1 ∧ c = 2 ∧ r2 = c1) ∨ (r = 1 ∧ c = 3 ∧ r3 = c1)
∨(r = 2 ∧ c = 1 ∧ r1 = c2) ∨ (r = 2 ∧ c = 2 ∧ r2 = c2) ∨ (r = 2 ∧ c = 3 ∧ r3 = c2)
∨(r = 3 ∧ c = 1 ∧ r1 = c3) ∨ (r = 3 ∧ c = 2 ∧ r2 = c3) ∨ (r = 3 ∧ c = 3 ∧ r3 = c3))
--checks all three conditions are met for the strategy
def checkStrategy (strategy : ((ℕ → ℕ × ℕ × ℕ) × (ℕ → ℕ × ℕ × ℕ))) : Prop :=
(checkStrategyrc 1 1 strategy) ∧ (checkStrategyrc 1 2 strategy) ∧ (checkStrategyrc 1 3 strategy) ∧
(checkStrategyrc 2 1 strategy) ∧ (checkStrategyrc 2 2 strategy) ∧ (checkStrategyrc 2 3 strategy) ∧
(checkStrategyrc 3 1 strategy) ∧ (checkStrategyrc 3 2 strategy) ∧ (checkStrategyrc 3 3 strategy)
instance : decidable_pred checkStrategy :=
λ _, by dunfold checkStrategy checkStrategyrc even; apply_instance
-- theorem notnoStrategy : ∃ (strategy : ((ℕ → ℕ × ℕ × ℕ) × (ℕ → ℕ × ℕ × ℕ))),
-- (checkStrategy (strategy)) :=
-- ⟨(λ _, (0, 0, 0), λ _, (0, 0, 0)), dec_trivial⟩
-- --someone on Zulip said to try putting this not directly after the import statements. This seems to have helped
-- open_locale classical
-- --given a strategy, we can't have it satisfy all the conditions
theorem noStrategy2 (strategy : ((ℕ → ℕ × ℕ × ℕ) × (ℕ → ℕ × ℕ × ℕ))) : ¬ (checkStrategy (strategy)) :=
begin
dsimp [checkStrategy, checkStrategyrc],
simp only [eq_self_iff_true, true_and,
(show (1 : ℕ) ≠ 2, from dec_trivial),
(show (1 : ℕ) ≠ 3, from dec_trivial),
false_and, false_or, or_false,
(show (3 : ℕ) ≠ 1, from dec_trivial),
(show (3 : ℕ) ≠ 2, from dec_trivial),
(show (2 : ℕ) ≠ 1, from dec_trivial),
(show (2 : ℕ) ≠ 3, from dec_trivial)],
generalize h : strategy.1 0 = x₁,
generalize h : strategy.1 1 = x₂,
generalize h : strategy.1 2 = x₃,
generalize h : strategy.1 3 = x₄,
generalize h : strategy.2 0 = y₁,
generalize h : strategy.2 1 = y₂,
generalize h : strategy.2 2 = y₃,
generalize h : strategy.2 3 = y₄,
clear h h h h h h h h strategy,
rcases x₁ with ⟨_, _, _⟩,
rcases x₂ with ⟨_, _, _⟩,
rcases x₃ with ⟨_, _, _⟩,
rcases x₄ with ⟨_, _, _⟩,
rcases y₁ with ⟨_, _, _⟩,
rcases y₂ with ⟨_, _, _⟩,
rcases y₃ with ⟨_, _, _⟩,
rcases y₄ with ⟨_, _, _⟩,
simp with parity_simps,
simp only [iff_iff_implies_and_implies],
finish,
end
example : true := trivial
#eval (∃ f : (vector (fin 2 × fin 2 × fin 2) 3 × vector (fin 2 × fin 2 × fin 2) 3),
(checkStrategy (λ n, ((f.1.nth (n - 1)).map fin.val) (prod.map fin.val fin.val),
λ n, ((f.2.nth (n - 1)).map fin.val) (prod.map fin.val fin.val))) : bool)
#exit
import algebra.pointwise
import ring_theory.algebra
local attribute [instance] set.smul_set_action
variables (R : Type*) [comm_ring R]
variables (A : Type*) [ring A] [algebra R A]
set_option class.instance_max_depth 26
example : mul_action R (set A) :=
by apply_instance -- works
variables (B : Type*) [comm_ring B] [algebra R B]
set_option trace.class_instances true
set_option class.instance_max_depth 34
example : mul_action R (set B) :=
by apply_instance -- fails
import data.finset data.int.sqrt data.nat.parity data.complex.exponential
example : finset ℤ := by library_search
example (n : ℕ) : finset ℤ := finset.map ⟨int.of_nat, @int.of_nat.inj⟩
(finset.range n)
#exit
import data.quot data.setoid
meta def quotient_choice {α β : Type} [s : setoid β]
(f : α → quotient s) : quotient (@pi_setoid _ _ (λ a : α, s)) :=
quotient.mk (λ a : α, quot.unquot (f a))
--applying choice to the identity map
def decidable_true
(quotient_choice : Π {α β : Type} [s : setoid β]
(f : α → quotient s), quotient (@pi_setoid _ _ (λ a : α, s))) :
decidable true :=
-- ⊤ is the always true relation
by letI : setoid bool := ⊤; exact
quot.rec_on_subsingleton (@quotient_choice (@quotient bool ⊤) bool ⊤ id)
(λ f, decidable_of_iff (f ⟦ff⟧ = f ⟦tt⟧)
(iff_true_intro (congr_arg f (quotient.sound trivial))))
#eval decidable_true @quotient_choice
#exit
import data.quot
variables {A : Type} {B : A → Type}
example (f : Π a : A, trunc (sigma B)) :
trunc (Π a : A, sigma B) :=
#exit
import data.set.basic data.set.lattice
example {s t : set ℕ} : s < t ↔ s ⊂ t := iff.rfl
example {s t : set ℕ} : s ≤ t ↔ -s ≤ -t := by library_search
set_option class.instance_max_depth 1000
local attribute
def decidable_true (choice : Π {α : Type*} {β : α → Type*}
(f : Π a, @quotient (β a) ⊤), @quotient (Π a, β a) ⊤) : decidable true :=
quot.rec_on_subsingleton (choice (id : @quotient bool ⊤ → @quotient bool ⊤))
(λ f, decidable_of_iff (f (quotient.mk' ff) = f (quotient.mk' tt))
(iff_true_intro (congr_arg f (quotient.sound' (by constructor))))
example : @quotient.choice (@quotient bool ⊤) (λ _, @quotient bool ⊤)
()
#exit
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import data.nat.basic data.fintype
import tactic
/-!
# Strong recursion
A strong recursion principle based on `fin`.
The benefit of `(Π (m:fin n), X m)` over `Π (m:ℕ) (h:m < n), X m`
is that with `fin` the bound on `m` is bundled,
and this can be used in later proofs and constructions.
## Example
For example, one can use this to give a definition of the Bernoulli numbers
that closely follows the recursive definition found at
https://en.wikipedia.org/wiki/Bernoulli_number#Recursive_definition
It is:
$$ B_n = 1 - \sum_{k < n} \binom{n}{k} \frac{B_k}{n - k + 1} $$
```
example : ℕ → ℚ :=
strong_recursion $ λ n bernoulli,
1 - finset.univ.sum (λ k : fin n, (n.choose k) * bernoulli k / (n - k + 1))
```
This example shows the benefit of using `fin n` in the implementation,
because it allows us to use `finset.univ.sum` which enables the recursive call `bernoulli k`.
If, on the other hand, we had used `Π (m:ℕ) (h:m < n), X m` and `(finset.range n).sum`,
then the recursive call to `bernoulli k` would get stuck,
because it would come with a proof obligation `k < n`
which isn't provided by `(finset.range n).sum`.
-/
namespace nat
universe variable u
variables {X : ℕ → Sort u} (f : Π n, (Π (m:fin n), X m) → X n)
/-- A strong recursion principle for the natural numbers.
It allows one to recursively define a function on ℕ
by showing how to extend a function on `fin n := {k // k < n}` to `n`. -/
def strong_recursion : Π n : ℕ, X n
| n := f _ (λ k : fin n, have wf : ↑k < n, from k.2, strong_recursion ↑k)
lemma strong_recursion_apply (n : ℕ) :
strong_recursion f n = f n (λ i, strong_recursion f i) :=
by rw strong_recursion
-- Example: Fibonacci
example : ℕ → ℚ :=
strong_recursion $ λ n fib,
match n, fib with
| 0 := λ _, 0
| 1 := λ _, 1
| (k+2) := λ fib, fib k + fib (k+1)
end
-- Example: Bernoulli
def bernoulli₁ : ℕ → ℚ :=
strong_recursion $ λ n bernoulli,
1 - finset.univ.sum (λ k : fin n, (n.choose k) * bernoulli k / (n - k + 1))
def bernoulli (n : ℕ) : ℚ :=
well_founded.fix nat.lt_wf
(λ n bernoulli, 1 - finset.univ.sum
(λ k : fin n, (n.choose k) * bernoulli k k.2 / (n - k + 1))) n
#eval (λ k, bernoulli₂ k - bernoulli₁ k) 8
end nat
#exit
import logic.basic
open classical
variables (α : Type) (p q : α → Prop)
variable a : α
#print classical.not_forall
local attribute [instance] classical.prop_decidable
theorem T08R [∀ x, decidable (p x)] (h : (¬ ∀ x, p x) → (∃ x, ¬ p x)) :
(∃ x, ¬ p x) ∨ ¬ (∃ x, ¬ p x) :=
begin
end
#exit
import data.nat.basic
open nat
lemma choose_mul_succ_eq (n k : ℕ) :
(n.choose k) * (n + 1) = ((n+1).choose k) * (n + 1 - k) :=
begin
by_cases hkn : k ≤ n,
{ have pos : 0 < fact k * fact (n - k), from mul_pos (fact_pos _) (fact_pos _),
rw [← nat.mul_left_inj pos],
suffices : choose n k * fact k * fact (n - k) * (n + 1) =
choose (n + 1) k * fact k * ((n + 1 - k) * fact (n - k)),
{ simpa [mul_comm, mul_assoc, mul_left_comm] },
rw [choose_mul_fact_mul_fact hkn, nat.succ_sub hkn, ← fact_succ,
← nat.succ_sub hkn, choose_mul_fact_mul_fact (le_succ_of_le hkn), fact_succ,
mul_comm] },
simp [choose_eq_zero_of_lt (lt_of_not_ge hkn), nat.sub_eq_zero_iff_le.2 (lt_of_not_ge hkn)],
end
open classical
variables {α : Type} {p : α → Prop}
theorem T06_1 : ¬ (∀ x, ¬ p x) → (∃ x, p x) :=
(assume hnAxnpx : ¬ (∀ x, ¬ p x),
by_contradiction
(λ hnExpx : ¬ (∃ x, p x),
(hnAxnpx
(λ x, (λ hpx,
hnExpx (exists.intro x hpx))))))
#check T06_1
-- it appears this is needed in tactic mode
local attribute [instance] classical.prop_decidable
theorem T06_2 : ¬ (∀ x, ¬ p x) → (∃ x, p x) :=
begin
intro hnAxnpx,
by_contradiction,
end
#exit
import topology.separation data.set.finite algebra.associated data.equiv.basic tactic.ring
example {α : Type} {p : α → Prop} (r : Prop): (∀ x, p x ∨ r) → ∀ x, p x ∨ r :=
assume h : ∀ x, p x ∨ r, assume a: α,
or.elim (h a)
(assume hl: p a,
show p a ∨ r, from
or.inl hl)
(assume hr: r,
show p a ∨ r, from or.inr hr)
example {M : Type} [monoid M] {a b c : M} (h : a * b = 1) (h2 : c * a = 1) : b = c :=
by rw [← one_mul b, ← h2, mul_assoc, h, mul_one]
open set
universes u v
variables {X : Type u} [topological_space X] [normal_space X] {α : Type v}
#print function.swap
def T (s : set X) (u : α → set X) : Type (max u v) :=
Σ (i : set α), {v : α → set X // s ⊆ Union v ∧ (∀ a, is_open (v a)) ∧
(∀ a ∈ i, closure (v a) ⊆ u a) ∧ (∀ a ∉ i, v a = u a)}
def le_aux (s : set X) (u : α → set X) : T s u → T s u → Prop :=
λ t t', t.1 ⊆ t'.1 ∧ ∀ a ∈ t.1, t.2.1 a = t'.2.1 a
instance (s : set X) (u : α → set X) : preorder (T s u) :=
{ le := le_aux s u,
le_trans := λ ⟨u₁, v₁, hv₁⟩ ⟨u₂, v₂, hv₂⟩ ⟨u₃, v₃, hv₃⟩ ⟨hu₁₂, hv₁₂⟩ ⟨hu₂₃, hv₂₃⟩,
⟨set.subset.trans hu₁₂ hu₂₃, λ a ha, (hv₁₂ a ha).symm ▸ hv₂₃ _ (hu₁₂ ha)⟩,
le_refl := λ t, ⟨set.subset.refl _, λ _ _, rfl⟩ }
open_locale classical
example (s : set X) (u : α → set X)
(su : s ⊆ Union u) (uo : ∀ a, is_open (u a)) :=
@zorn.exists_maximal_of_chains_bounded (T s u) (≤)
(λ c hc,
⟨⟨⋃ (t : T s u) (ht : t ∈ c), t.1,
λ a, ⋂ (t : T s u) (ht : t ∈ c), t.2.1 a,
⟨begin
assume x hx,
simp only [set.mem_Union, set.mem_Inter],
cases set.mem_Union.1 (su hx) with a ha,
refine ⟨a, λ t ht, _⟩,
rwa t.2.2.2.2.2,
end,
λ a, is_open_Union (λ t, is_open_Union (λ ht, t.2.2.2.1 _)),
λ a ha, begin
simp only [set.mem_Union] at ha,
rcases ha with ⟨t, htc, ha⟩,
have := t.2.2.2.2.1 a ha,
assume x hx, sorry
end,
begin
assume a ha,
ext,
simp only [set.mem_Union, not_exists] at *,
split,
{ rintro ⟨t, htc, ht⟩,
rwa ← t.2.2.2.2.2 a (ha _ htc) },
{ assume hau,
cases hcn with t htc,
use [t, htc],
rwa t.2.2.2.2.2 _ (ha _ htc) }
end⟩⟩,
λ t htc, ⟨λ x hx, set.mem_Union.2 ⟨t, by simp *⟩,
λ a, begin
end⟩⟩
)
(λ _ _ _, le_trans)
lemma shrinking_lemma
{s : set X} (hs : is_closed s) (u : α → set X) (uo : ∀ a, is_open (u a))
(uf : ∀ x, finite {a | x ∈ u a}) (su : s ⊆ Union u) :
∃ v : α → set X, s ⊆ Union v ∧ ∀ a, is_open (v a) ∧ closure (v a) ⊆ u a :=
#exit
import data.equiv.encodable
#eval @encodable.choose (ℕ × ℕ) (λ x, x.1 ^2 - 26 * x.2 ^2 = 1 ∧ x.2 ≠ 0) _ _ sorry
#exit
import data.mv_polynomial
def eval_list :
#exit
import data.set.basic
#print set.image_preimage_eq
inductive heq' {α : Type} (a : α) : Π {β : Type}, β → Type
| refl : heq' a
inductive eq' {α : Type} (a : α) : α → Type
| refl : eq' a
lemma eq_of_heq' {α : Type} (a b : α) : heq' a b → eq' a b :=
begin
assume h,
cases h,
constructor,
end
#print eq_of_heq'
#exit
import topology.instances.real
example : continuous (λ x : { x : ℝ × ℝ // x ≠ (0, 0) },
(x.1.1 * x.1.2) / (x.1.1^2 + x.1.2^2)) :=
continuous.mul
(continuous.mul
(continuous_fst.comp continuous_subtype_val)
(continuous_snd.comp continuous_subtype_val))
(real.continuous.inv
(begin
rintros ⟨⟨x₁, x₂⟩, hx⟩, dsimp,
rw [ne.def, prod.mk.inj_iff, not_and] at hx,
dsimp, clear hx,
refine ne_of_gt _,
simp at *,
rcases classical.em (x₁ = 0) with rfl | hx₁,
{ rcases classical.em (x₂ = 0) with rfl | hx₂,
{ exact (hx rfl).elim },
{ exact add_pos_of_nonneg_of_pos (pow_two_nonneg _)
(by rw pow_two; exact mul_self_pos hx₂) } },
{ exact add_pos_of_pos_of_nonneg
(by rw pow_two; exact mul_self_pos hx₁)
(pow_two_nonneg _) }
end)
(continuous.add
((continuous_pow 2).comp
(continuous_fst.comp continuous_subtype_val))
((continuous_pow 2).comp
(continuous_snd.comp continuous_subtype_val)) ))
example : continuous_on (λ x, x⁻¹ : ℝ → ℝ)
(≠ 0) := by library_search
#print real.continuous_inv
example : continuous_on (λ x : ℝ × ℝ,
(x.1 * x.2) / (x.1^2 + x.2^2)) (≠ (0, 0)):=
continuous_on.mul
(continuous_on.mul
real.continuous_on
_)
(continuous_on.inv)
#exit
example (A B : Prop) : (¬ A ∧ ¬ B) ∨ (A ∧ B) ↔ (A ∨ B) ∧ ()
#exit
import set_theory.ordinal algebra.euclidean_domain
universe u
variables {α : Type u} (r : α → α → Prop) (wf : well_founded r)
lemma psigma.lex.is_well_order {α : Type*} {β : α → Type*}
(r : α → α → Prop) (s : Π a, β a → β a → Prop) [is_well_order α r]
[∀ a, is_well_order (β a) (s a)] :
is_well_order (psigma β) (psigma.lex r s) :=
{ }
noncomputable def rank : α → ordinal.{u}
| a := ordinal.sup.{u u} (λ b : {b : α // r b a},
have wf : r b.1 a, from b.2, ordinal.succ.{u} (rank b.1))
using_well_founded {rel_tac := λ _ _, `[exact ⟨r, wf⟩],
dec_tac := tactic.assumption}
lemma mono : ∀ {a b : α}, r a b → rank r wf a < rank r wf b
| a := λ b hab, begin
rw [rank, rank],
refine lt_of_not_ge _,
assume hle,
rw [ge, ordinal.sup_le] at hle,
have := hle ⟨_, hab⟩,
rw [ordinal.succ_le, ← not_le, ordinal.sup_le, classical.not_forall] at this,
rcases this with ⟨c, hc⟩,
rw [ordinal.succ_le, not_lt] at hc,
exact have wf : _ := c.2, not_le_of_gt (mono c.2) hc
end
using_well_founded {rel_tac := λ _ _, `[exact ⟨r, wf⟩], dec_tac := tactic.assumption}
def well_order : Π a b : Σ' a : α, {b // rank r wf b = rank r wf a}, Prop :=
psigma.lex well_ordering_rel (λ _, rank r wf ∘ subtype.val ⁻¹'o (<))
#print psigma.lex
#exit
import order.bounded_lattice
instance : partial_order ℕ := linear_order.to_partial_order ℕ
lemma exampl : well_founded ((<) : with_top ℕ → with_top ℕ → Prop) :=
with_top.well_founded_lt nat.lt_wf
#print axioms exampl
#exit
import data.zmod.basic data.matrix.basic order.filter
variables {p : ℕ → Prop} [decidable_pred p]
def rel' (p : ℕ → Prop) : ℕ → ℕ → Prop :=
λ a b, ∀ n, p n → (∀ m, p m → n ≤ m) → a ≤ n ∧ b < a
def exists_least_of_exists {n : ℕ} (h : p n) : ∃ m, p m ∧ ∀ k, p k → m ≤ k :=
begin
resetI,
induction n with n ih generalizing p,
{ exact ⟨0, h, λ _ _, nat.zero_le _⟩ },
{ cases @ih (p ∘ nat.succ) _ h with m hm,
by_cases hp0 : p 0,
{ exact ⟨0, hp0, λ _ _, nat.zero_le _⟩ },
{ use [m.succ, hm.1],
assume k hpk,
cases k with k,
{ contradiction },
exact nat.succ_le_succ (hm.2 k hpk) } }
end
#print axioms with_top.well_founded_lt
lemma rel'_wf (h : ∃ n, p n) : well_founded (rel' p) :=
begin
cases h with n hn,
cases exists_least_of_exists hn with m hm,
clear hn n,
refine @subrelation.wf _ (measure (λ a, m - a)) _ _ (measure_wf _),
assume a b hab,
rcases hab m hm.1 hm.2 with ⟨ham, hba⟩,
clear hm hab,
show m - a < m - b,
induction ham with z,
rw nat.sub_self,
exact nat.sub_pos_of_lt hba,
rw [nat.succ_sub ham_a, nat.succ_sub],
exact nat.succ_lt_succ ham_ih,
exact le_trans(le_of_lt hba) ham_a,
end
attribute [elab_as_eliminator] well_founded.fix
#print axioms le_of_not_gt
lemma nat.lt_of_le_of_ne {a b : ℕ} (hle : a ≤ b) (hne : a ≠ b) : a < b :=
begin
induction hle,
{ exact (hne rfl).elim },
exact nat.lt_succ_of_le hle_a
end
def find (h : ∃ n, p n) : {n // p n ∧ ∀ m, p m → n ≤ m} :=
well_founded.fix (rel'_wf h)
(λ n ih hn, if hpn : p n then ⟨n, hpn, hn⟩
else ih n.succ (λ k hk h, ⟨nat.succ_le_of_lt (nat.lt_of_le_of_ne (hn _ hk)
(by rintro rfl; exact (hpn hk).elim)), nat.lt_succ_self _⟩)
(λ m hm, nat.succ_le_of_lt (nat.lt_of_le_of_ne (hn _ hm)
(by rintro rfl; exact (hpn hm).elim)))) 0
(show ∀ m, p m → 0 ≤ m, from λ _ _, nat.zero_le _)
set_option profiler true
#eval @find (> 1000000) _ sorry
#eval @nat.find (> 1000000) _ sorry
#print axioms find
#eval (6/10 : zmodp 5 (by norm_num))
#exit
import set_theory.ordinal tactic
lemma exampl {α β : Type} (f : α → β) (hf : function.surjective f) : function.injective (set.preimage f) :=
λ s t, begin
simp only [set.ext_iff],
assume h x,
rcases hf x with ⟨y, rfl⟩,
exact h y
end
#print rfl
#reduce exampl
#exit
import data.nat.gcd data.equiv.basic
#print equiv.set.univ
#exit
import data.set.basic data.fintype.basic data.equiv.encodable
variables {R A : Type} (P : R → A → bool)
def 𝕍_ (S : set R) : set A :=
{x : A | ∀ f ∈ S, P f x}
notation `𝕍`:max := 𝕍_ (by exact P)
def 𝕀_ (X : set A) : set R :=
{f : R | ∀ x ∈ X, P f x}
notation `𝕀`:max := 𝕀_ (by exact P)
set_option class.instance_max_depth 200
#eval let s := @fintype.choose (Σ' (P : finset (unit × unit)) (Y J : finset (unit)),
(∀ (x : unit), (∀ (x_1 : unit), x_1 ∈ Y → ((x, x_1) ∈ P)) → x ∈ J) ∧ ¬
∀ (x : unit), (∀ (f : unit), f ∈ J → ((f, x) ∈ P)) → x ∈ Y) _ _ (λ _, true) _ sorry in
(s.1, s.2.1, s.2.2.1)
lemma Galois_connection : ¬
∀ (P : unit→ unit→ bool) {Y : finset (unit)} {J : finset (unit)},
𝕀 (↑Y: set (unit)) ⊆ ↑J ↔ 𝕍 (↑J : set (unit)) ⊆ ↑Y :=
begin
dsimp [𝕀_, 𝕍_, set.subset_def],
simp,
exact dec_trivial,
end
#exit
import order.filter.basic
#print filter.cofinite
open filter set
variables {α : Type*}
@[simp] lemma mem_cofinite {s : set α} : s ∈ (@cofinite α) ↔ finite (-s) := iff.rfl
example : @cofinite ℕ = at_top :=
begin
ext s,
simp only [mem_cofinite, mem_at_top_sets],
end
#exit
import data.mv_polynomial data.fintype
open polynomial
variables {R : Type*} {σ : Type*} [integral_domain R] [infinite R]
open_locale classical
lemma eval_eq_zero (f : polynomial R) : (∀ x, f.eval x = 0) ↔ f = 0 :=
⟨λ h, let ⟨x, hx⟩ := infinite.exists_not_mem_finset (roots f) in
by_contradiction (mt mem_roots (λ hiff, hx (hiff.2 (h x)))),
by rintro rfl; simp⟩
#print mv_polynomial.comm_ring
lemma mv_polynomial.eval_eq_zero (f : mv_polynomial σ R) : (∀ x, f.eval x = 0) ↔ f = 0 :=
finsupp
#exit
import data.set.lattice
variables p q r : Prop
open set
example (R : Type*) (A : Type*) (P : R → A → Prop)
(ι : Type*) (S : ι → set R) (x : A) :
(∀ (f : R), (f ∈ ⋃ (i : ι), S i) → P f x) ↔
∀ (i : ι) (f : R), f ∈ S i → P f x :=
begin
simp, tauto,
end
theorem T2R : ((p ∨ q) → r) → (p → r) ∧ (q → r) :=
begin
intros porqr,
split,
{ assume hp : p,
apply porqr,
left,
exact hp },
{ assume hq : q,
apply porqr,
right,
exact hq },
end
noncomputable theory
open_locale classical
def foo : Π (X : Type), X → X :=
λ X, if h : X = ℕ then by {subst h; exact nat.succ } else id
example (claim : (Π X : Type, X → X) ≃ unit) : false :=
let foo : Π (X : Type), X → X :=
λ X, if h : X = ℕ then by {subst h; exact nat.succ } else id in
by simpa [foo] using congr_fun (congr_fun (claim.injective
(subsingleton.elim (claim @id) (claim foo))) ℕ) 0
#exit
import linear_algebra.basic
theorem Distr_or_L (p q r : Prop) : (p ∨ q) ∧ (p ∨ r) → p ∨ (q ∧ r) :=
begin
intros pqpr,
have porq : p ∨ q, from pqpr.left,
have porr : p ∨ r, from pqpr.right,
{ cases porq with hp hq,
{ exact or.inl hp },
{ cases porr with hp hr,
{ exact or.inl hp },
{ exact or.inr ⟨hq, hr⟩ } } }
end
#print linear_map
example : Σ
#exit
import topology.compact_open topology.separation
open function
example {X Y : Type} [topological_space X] [topological_space Y] (f : X → Y) [compact_space X]
[t2_space Y] (hf : continuous f) (hfs : surjective f) (U : set Y) (hU : is_open (f ⁻¹' U)) :
is_open U :=
have h : is_closed (f '' (f⁻¹' -U)), from _,
begin
end
#exit
import data.rat.denumerable
#eval denumerable.equiv₂ ℕ ℚ 20
#eval denumerable.equiv₂ ℚ ℕ ((denumerable.equiv₂ ℕ ℚ 3) + (denumerable.equiv₂ ℕ ℚ 1))
#eval (denumerable.equiv₂ (Σ n : ℕ, fin n) ℕ) (8,3)
constant fintype (α : Type) : Type
attribute [class] fintype
def card (α : Type) [fintype α]: ℕ := sorry
constant fintype_subset {α : Type} [fintype α] {p : set α} : fintype ↥p
attribute [instance] fintype_subset
instance {α β : Type} [fintype β] (f : β → α) : fintype (set.range f) := sorry
lemma subset_lemma {α : Type} [fintype α] {p : set α} : card p = card p := sorry
example {α β : Type} [fintype α] [fintype β] (f : β → α) :
card (set.range f) = card (set.range f):=
begin
rw [subset_lemma], --fails
end
#exit
import data.setoid
def M : Type := (classical.choice ⟨sigma.mk ℕ nat.monoid⟩).1
noncomputable instance : monoid M := (classical.choice ⟨sigma.mk ℕ nat.monoid⟩).2
inductive monoid_expr (α : Type) : Type
| of (a : α) : monoid_expr
| one {} : monoid_expr
| mul : monoid_expr → monoid_expr → monoid_expr
open monoid_expr
def eval {α β : Type} [has_mul β] [has_one β] (f : α → β) : monoid_expr α → β
| (of x) := f x
| one := 1
| (mul x y) := eval x * eval y
instance : setoid (monoid_expr M) :=
{ r := λ x y, eval id x = eval id y,
iseqv := ⟨λ _, rfl, λ _ _, eq.symm, λ _ _ _, eq.trans⟩ }
def M' : Type := @quotient (monoid_expr M) monoid_expr.setoid
instance : monoid M' :=
{ mul := λ x y,
quotient.lift_on₂' x y (λ x y, ⟦mul x y⟧)
(λ a₁ a₂ b₁ b₂ (h₁ : _ = _) (h₂ : _ = _),
quotient.sound $ show _ = _,
by simp [eval, *]),
mul_assoc := λ a b c, quotient.induction_on₃ a b c
(λ a b c, quotient.sound (mul_assoc (eval id a) _ _)),
one := ⟦one⟧,
one_mul := λ a, quotient.induction_on a
(λ a, quotient.sound (one_mul (eval id a))),
mul_one := λ a, quotient.induction_on a
(λ a, quotient.sound (mul_one (eval id a))) }
#exit
import data.fintype.basic tactic.fin_cases
variables p q : Prop
open classical
example : ¬(p → q) → p ∧ ¬q :=
λ h,
have notq : ¬q, from (λ hq', (h (λ hp, hq'))),
and.intro
(or.elim (em p)
id
(
(λ hnp, _)))
notq
instance decidable_eq_endofunctions {qq : Type} [fintype qq] [decidable_eq qq] :
decidable_eq (qq → qq) := by apply_instance
inductive nand_expr (n : ℕ) : Type
| false {} : nand_expr
| var (i : fin n) : nand_expr
| nand : nand_expr → nand_expr → nand_expr
{x : A × B | ∃ a : A, X = (a, f a)}
namespace nand_expr
def eval {n : ℕ} : nand_expr n → (fin n → bool) → bool
| false x := ff
| (var i) x := x i
| (nand a b) x := !((eval a x) && (eval b x))
lemma surjective_eval : Π {n : ℕ} (f : (fin n → bool) → bool),
{e : nand_expr n // e.eval = f }
| 0 := λ f, if hf : f fin.elim0 = ff
then ⟨false, funext $ λ x, hf.symm.trans sorry⟩
else ⟨nand false false, sorry⟩
| (n+1) := λ f, _
end nand_expr
#exit
import data.set.basic
inductive mynat
| zero : mynat
| succ : mynat → mynat
namespace mynat
def one : mynat := succ zero
def two : mynat := succ one
def add (a b : mynat) : mynat :=
mynat.rec b (λ _, succ) a
lemma one_add_one : add one one = two := eq.refl two
lemma one_add_one' : 1 + 1 = 2 := eq.refl 2
set_option pp.all true
#print one_add_one
set_option pp.all true
#print exampl
import system.io
def main : io nat :=
do io.put_str "Hello world", return 1
#exit
import tactic.ring data.complex.basic
example (a b c : ℂ) :
(a + b + c)^2 + (a + b - c)^2 + (a + c - b)^2 + (b + c - a)^2 =
(2 * a)^2 + (2 * b)^2 + (2 * c)^2 := by ring
#exit
import logic.basic data.fintype.basic tactic.tauto
def xo (a b : Prop) := ¬(a ↔ b)
lemma xo_assoc_aux1 (a b c : Prop) (h : xo (xo a b) c) : xo a (xo b c) :=
λ h₁,
have h : ¬(¬(¬(b ↔ c) ↔ b) ↔ c),
from λ h₂,
h ⟨λ hab, h₂.mp (λ h₃, hab (h₁.trans h₃)),
λ hc hab, h₂.mpr hc (h₁.symm.trans hab)⟩,
have hnc : ¬ c,
from λ hc, h ⟨λ _, hc, λ hc hbcb,
have hnb : ¬ b, from λ hb, hbcb.mpr hb (iff_of_true hb hc),
hnb (hbcb.mp (λ hbc, hnb (hbc.mpr hc)))⟩,
have h : ¬(¬(b ↔ c) ↔ b),
from (not_not_not_iff _).1 (λ h₁, h ⟨λ h₂, (h₁ h₂).elim, λ hc, (hnc hc).elim⟩),
have h : ¬ (¬ ¬ b ↔ b),
from λ hb,
h ⟨λ h, hb.mp (λ hnb, h (iff_of_false hnb hnc)), λ hb hbc, hnc (hbc.mp hb)⟩,
have hnb : ¬ b,
from λ hb, h (iff_of_true (λ hnb, hnb hb) hb),
h ⟨λ hnnb, (hnnb hnb).elim, λ hb, (hnb hb).elim⟩
#reduce xo_assoc_aux1
lemma xo_assoc_aux2 (a b c : Prop) : xo (xo a b) c → xo a (xo b c) :=
begin
dsimp [xo],
assume h h₁,
replace h : ¬(¬(¬(b ↔ c) ↔ b) ↔ c),
{ assume h₂,
apply h,
split,
{ assume hab : ¬ (a ↔ b),
apply h₂.mp,
assume h₃,
apply hab,
apply h₁.trans,
exact h₃ },
{ assume hc : c,
assume hab : a ↔ b,
apply h₂.mpr hc,
apply h₁.symm.trans,
exact hab } },
clear h₁ a,
have hnc : ¬ c,
{ assume hc : c,
apply h,
split,
{ exact λ _, hc },
{ assume hc hbcb,
have hnb : ¬ b,
{ assume hb : b,
apply hbcb.mpr hb,
exact iff_of_true hb hc },
{ apply hnb,
apply hbcb.mp,
assume hbc,
apply hnb,
apply hbc.mpr,
exact hc } } },
replace h : ¬(¬¬(¬(b ↔ c) ↔ b)),
{ assume h₁,
apply h,
split,
{ assume h₂,
exact (h₁ h₂).elim },
{ assume hc, exact (hnc hc).elim } },
replace h := (not_not_not_iff _).1 h,
replace h : ¬ (¬ ¬ b ↔ b),
{ assume hb,
apply h,
split,
{ assume h,
apply hb.mp,
assume hnb,
apply h,
exact iff_of_false hnb hnc },
{ assume hb hbc,
apply hnc,
apply hbc.mp hb } },
clear hnc c,
have hnb : ¬ b,
{ assume hb,
apply h,
exact iff_of_true (λ hnb, hnb hb) hb },
apply h,
exact ⟨λ hnnb, (hnnb hnb).elim, λ hb, (hnb hb).elim⟩
end
#reduce xo_assoc_aux
#print ring
set_option class.instance_max_depth 200
instance : fintype (ring bool) :=
fintype.of_equiv
(Σ' (add : bool → bool → bool)
(add_assoc : ∀ a b c, add (add a b) c = add a (add b c))
(zero : bool)
(zero_add : ∀ a, add zero a = a)
(add_zero : ∀ a, add a zero = a)
(neg : bool → bool)
(add_left_neg : ∀ a, add (neg a) a = zero)
(add_comm : ∀ a b, add a b = add b a)
(mul : bool → bool → bool)
(mul_assoc : ∀ a b c, mul (mul a b) c = mul a (mul b c))
(one : bool)
(one_mul : ∀ a, mul one a = a)
(mul_one : ∀ a, mul a one = a)
(left_distrib : ∀ a b c, mul a (add b c) = add (mul a b) (mul a c)),
∀ b c a, mul (add b c) a = add (mul b a) (mul c a) )
{ to_fun := λ ⟨x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15⟩,
⟨x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15⟩,
inv_fun := λ ⟨x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15⟩,
⟨x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15⟩,
left_inv := λ ⟨x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15⟩, rfl,
right_inv := λ a, by cases a; refl }
#eval fintype.card {op : bool → bool → bool //
∀ a b c, op (op a b) c = op a (op b c)}
example : fintype.card (ring bool) = 2 := rfl
local attribute [instance, priority 0] classical.prop_decidable
lemma iff.assoc {a b c : Prop} : ((a ↔ b) ↔ c) ↔ (a ↔ (b ↔ c)) :=
if h : a then by simp [h] else by simp [h, not_iff]
lemma or_iff_distrib_left {a b c : Prop} : (a ∨ (b ↔ c)) ↔ ((a ∨ b) ↔ (a ∨ c)) :=
⟨λ h, by cases h; simp [h], λ h, by by_cases a; simp * at *⟩
lemma or_iff_distrib_right {a b c : Prop} : ((a ↔ b) ∨ c) ↔ ((a ∨ c) ↔ (b ∨ c)) :=
by rw [or_comm, or_iff_distrib_left, or_comm, or_comm c]
instance : discrete_field Prop :=
{ add := (↔),
mul := (∨),
add_assoc := λ _ _ _, propext $ iff.assoc,
zero := true,
zero_add := λ _, propext $ true_iff _,
add_zero := λ _, propext $ iff_true _,
neg := id,
add_left_neg := λ _, propext $ iff_true_intro iff.rfl,
add_comm := λ _ _, propext iff.comm,
mul_assoc := λ _ _ _, propext $ or.assoc,
one := false,
one_mul := λ _, propext $ false_or _,
mul_one := λ _, propext $ or_false _,
left_distrib := λ _ _ _, propext $ or_iff_distrib_left,
right_distrib := λ _ _ _, propext $ or_iff_distrib_right,
mul_comm := λ _ _, propext $ or.comm,
inv := id,
zero_ne_one := true_ne_false,
mul_inv_cancel := λ a ha0, if ha : a
then (ha0 (eq_true_intro ha)).elim
else eq_false_intro (λ h, h.elim ha ha),
inv_mul_cancel := λ a ha0, if ha : a
then (ha0 (eq_true_intro ha)).elim
else eq_false_intro (λ h, h.elim ha ha),
has_decidable_eq := classical.dec_eq _,
inv_zero := rfl }
variable V : Type
structure toto := (val : list V)
inductive shorter : toto V -> toto V -> Prop
| step : ∀ (z : V) (l : list V), shorter ⟨l⟩ ⟨z::l⟩
lemma shorter_wf : well_founded (shorter V)
:= by { apply well_founded.intro, intro l, cases l with xs,
induction xs with y ys; apply acc.intro; intros; cases a,
apply xs_ih }
instance : has_well_founded (toto V) := ⟨shorter V, shorter_wf V⟩
#print int.comm_semiring
def fold : toto V -> Prop
| ⟨[]⟩ := true
| ⟨x::xs⟩ := have h : shorter V ⟨xs⟩ ⟨x::xs⟩ := shorter.step x xs,
fold ⟨xs⟩
using_well_founded { rel_tac := λ _ _, `[exact ⟨_, shorter_wf V⟩],
dec_tac := `[exact h] }
#exit
import set_theory.ordinal
universe u
noncomputable theory
#print axioms int.comm_ring
example : ((<) : cardinal.{u} → cardinal.{u} → Prop)
≼o ((<) : ordinal.{u} → ordinal.{u} → Prop) :=
cardinal.ord.order_embedding
def ordinal.to_cardinal : ordinal.{u} → cardinal.{u}
| o := begin
have :=
end
example : ((<) : ordinal.{u} → ordinal.{u} → Prop)
≼o ((<) : cardinal.{u} → cardinal.{u} → Prop) :=
⟨⟨λ o : ordinal.{u}, well_founded.fix ordinal.wf.{u} begin end o, _⟩, _⟩
#exit
import linear_algebra.basic
set_option pp.implicit true
lemma X {p q : Prop} : (p ↔ ¬q) ↔ ¬(p ↔ q) :=
sorry
#print not_false
example {p : Prop} : p ∨ ¬p :=
((@X (p ∨ ¬p) false).mpr (λ h, h.mp (or.inr (λ hp, h.mp (or.inl hp))))).mpr (λb,b)
example := by library_search
example {α : Type} (s : set α) : s = s ⁻¹' {true} :=
set.ext $ λ x, ⟨λ h, or.inl (eq_true_intro h),
λ h, h.elim (λ h, h.mpr trivial) false.elim⟩
example {ι : Type} (i : ι) (f : Π (j : subtype (≠ i)), M₁ j.val)
import topology.opens
open topological_space
lemma opens.supr_val {X γ : Type*} [topological_space X] (ι : γ → opens X) :
(⨆ i, ι i).val = ⨆ i, (ι i).val :=
@galois_connection.l_supr (opens X) (set X) _ _ _ (subtype.val : opens X → set X)
opens.interior opens.gc _
lemma what_is_this_called {X Y : Type*} [topological_space X] [topological_space Y] {f : X → Y}
(hf : continuous f) {γ : Type*} (ι : γ → opens Y) :
(⨆ (j : γ), hf.comap (ι j)).val = ⋃ (j : γ), f ⁻¹' (ι j).val :=
opens.supr_val _
#exit
import algebra.pi_instances
universes u v w
class SemiModule (β : Type v) [add_comm_monoid β]
abbreviation Module (β : Type v) [add_comm_group β] :=
SemiModule β
instance piSemiModule (I : Type w) (f : I → Type u)
[∀ i, add_comm_monoid $ f i] [∀ i, SemiModule (f i)] :
SemiModule (Π i : I, f i) := by constructor
set_option pp.implicit true
-- instance piSemiModule' (I : Type w) (f : I → Type u)
-- [∀ i, add_comm_group $ f i] [∀ i, SemiModule (f i)] :
-- SemiModule (Π i : I, f i) := begin
-- apply_instance
-- end
example (I : Type w) (f : I → Type u) [∀ i, add_comm_group $ f i] :
@pi.add_comm_monoid I f _ = @add_comm_group.to_add_comm_monoid _ _ := rfl
set_option trace.class_instances true
#check piSemiModule _ _
instance piModule (I : Type w) (f : I → Type u)
[∀ i, add_comm_group $ f i] [∀ i, SemiModule (f i)] : -- changed from Module
Module (Π i : I, f i) := begin
delta Module,
-- ⊢ SemiModule (Π (i : I), f i)
-- apply piSemiModule I f, -- works
apply_instance -- still fails
end
/-
@SemiModule (Π (i : I), f i)
(@pi.add_comm_monoid I (λ (i : I), f i) (λ (i : I), _inst_1 i))
-/
#exit
import ring_theory.integral_closure set_theory.schroeder_bernstein
#print function.embedding.trans
example {R A : Type} [comm_ring A] [comm_ring R] [algebra R A] (S : subalgebra R A)
{x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S := by library_search
open_locale classical
example {α β ι : Type*} [hι : nonempty ι] {S : ι → set α} (f : α → β)
(hf : function.injective f) : (⨅ i, f '' S i) = f '' (⨅ i, S i) :=
by resetI; rcases hι with ⟨i⟩; exact
set.ext (λ x, ⟨λ h, by rcases set.mem_Inter.1 h i with ⟨y, hy, rfl⟩;
exact ⟨y, set.mem_Inter.2 (λ j, by rcases set.mem_Inter.1 h j with ⟨z, hz⟩;
exact (hf hz.2 ▸ hz.1)), rfl⟩,
by rintros ⟨y, hy, rfl⟩; exact set.mem_Inter.2 (λ i, set.mem_image_of_mem _
(set.mem_Inter.1 hy _))⟩)
/-
structure functor (C : Type u₁) [category.{v₁} C] (D : Type u₂) [category.{v₂} D] :
Type (max v₁ v₂ u₁ u₂) :=
(obj : C → D)
(map : Π {X Y : C}, (X ⟶ Y) → ((obj X) ⟶ (obj Y)))
(map_id' : ∀ (X : C), map (𝟙 X) = 𝟙 (obj X) . obviously)
(map_comp' : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z), map (f ≫ g) = (map f) ≫ (map g) . obviously)
infixr ` ⥤ `:26 := functor -- type as \func --
-/
variables {X : Type*} [topological_space X]
open topological_space
def res_functor {Y₁ Y₂ : set X} (hY : Y₂ ⊆ Y₁) :
{V : opens X // Y₁ ⊆ V} ⥤ {V : opens X // Y₂ ⊆ V} :=
{ obj := λ V, ⟨V.1, set.subset.trans hY V.2⟩,
map := λ _ _, id}
example (Y : set X) : res_functor (set.subset.refl Y) = 𝟭 _ :=
begin
apply category_theory.functor.mk.inj_eq.mpr,
simp, refl,
end
#exit
import data.nat.prime data.zsqrtd.gaussian_int
inductive W {α : Type*} (β : α → Type*)
| mk (a : α) (b : β a → W) : W
def blah {α : Type*} (β : α → Type*) [Π a, fintype (β a)] : W β → ℕ
| mk a b := begin
end
local notation `ℤ[i]` := gaussian_int
#eval let s := (finset.Ico 20 10000).filter nat.prime in
((s.sigma (λ n, (finset.Ico 20 n).filter nat.prime)).filter
(λ n : Σ n, ℕ, nat.sqrt (n.1^2 - n.2^2) ^ 2 = n.1^2 - n.2^2)).image
(λ n : Σ n, ℕ, (n.1, n.2, (n.1^2 - n.2^2).factors))
#eval nat.factors (71^2 + 31^2)
#eval (nat.prime 31 : bool)
#eval nat.sqrt(181^2 - 19^2)
#eval nat.factors 180
#eval (180^2 + 19^2 = 181^2 : bool)
#eval (nat.prime 181 : bool)
import tactic.split_ifs
open nat
inductive tree : Type
| lf : tree
| nd : tree -> nat -> tree -> tree
open tree
def fusion : tree -> tree -> tree
| lf t2 := t2
| (nd l1 x1 r1) lf := (nd l1 x1 r1)
| (nd l1 x1 r1) (nd l2 x2 r2) :=
if x1 <= x2
then nd (fusion r1 (nd l2 x2 r2)) x1 l1
else nd (fusion (nd l1 x1 r1) r2) x2 l2
def occ : nat -> tree -> nat
| _ lf := 0
| y (nd g x d) := (occ y g) + (occ y d) + (if x = y then 1 else 0)
theorem q5 : ∀ (x : ℕ) (t1 t2 : tree),
(occ x (fusion t1 t2)) = (occ x t1) + (occ x t2) :=
begin
intros x t1 t2,
induction t1 with g1 x1 d1 _ ih1,
simp [fusion, occ],
induction t2 with g2 x2 d2 _ ih2,
simp [fusion, occ],
by_cases x1 <= x2,
simp [fusion, h, occ],
rw ih1,
simp [occ, fusion, h],
simp [occ, fusion, h],
rw ih2,
simp [occ, fusion],
end
∀ t2
theorem q5 : ∀ (x : ℕ) (t1 t2 : tree),
(occ x (fusion t1 t2)) = (occ x t1) + (occ x t2) :=
begin
intros x t1,
induction t1 with g1 x1 d1 _ ih1,
{ simp [fusion, occ] },
{ assume t2,
induction t2 with g2 x2 d2 _ ih2,
simp [fusion, occ],
by_cases x1 <= x2,
{ simp [fusion, h, occ, ih1] },
{ simp [occ, fusion, h, ih2] }, },
end
theorem q5 (x : ℕ) : ∀ (t1 t2 : tree),
(occ x (fusion t1 t2)) = (occ x t1) + (occ x t2)
| lf t2 := by simp [fusion, occ]
| (nd l1 x1 r1) lf := by simp [fusion, occ]
| (nd l1 x1 r1) (nd l2 x2 r2) :=
begin
simp only [fusion, occ],
by_cases hx12 : x1 ≤ x2,
{ rw [if_pos hx12],
simp only [fusion, occ],
rw q5,
simp [occ] },
{ rw if_neg hx12,
simp only [fusion, occ],
rw q5,
simp [occ] }
end
#exit
import ring_theory.algebra
example {R : Type*} [comm_ring R] :
(algebra.to_module : module ℤ R) = add_comm_group.module :=
variable {n : ℕ}
open function nat finset
#print test_bit
def binary (A : finset ℕ) : ℕ := A.sum (λ x, pow 2 x)
def ith_bit (n i : ℕ) := n / 2 ^ i % 2
-- lemma ith_bit_binary (A : finset ℕ) : ∀ i,
-- i ∈ A ↔ ¬ even (binary A / 2 ^ i) :=
-- finset.induction_on A
-- (by simp [binary, ith_bit])
-- (λ a s has ih i,
-- begin
-- dsimp [binary, ith_bit] at *,
-- rw [sum_insert has, mem_insert],
-- have hnm : ∀ {n m}, n < m → 2^n / 2^m = 0,
-- from λ n m h, div_eq_of_lt ((pow_lt_iff_lt_right (le_refl _)).2 h),
-- have hnm' : ∀ {n m : ℕ}, n < m → 2^m % 2^n = 0, from sorry,
-- have h2p : ∀ {n : ℕ}, 0 < 2^n, from sorry,
-- rcases lt_trichotomy i a with hia|rfl|hai,
-- { have : even (2^a / 2^i),
-- { rw [even_div, mod_mul_left_div_self, ← dvd_iff_mod_eq_zero],
-- apply dvd_div_of_mul_dvd,
-- rw [← nat.pow_succ],
-- exact pow_dvd_pow _ hia }, sorry,
-- -- rw [hnm' hia, zero_add, if_neg (not_le_of_gt (mod_lt _ h2p))],
-- -- simp [*, ne_of_lt hia, ih, hnm' hia] with parity_simps
-- }, { sorry },
-- -- { rw [mod_self, zero_add, if_neg (not_le_of_gt (mod_lt _ h2p))],
-- -- simp [nat.div_self (nat.pow_pos h2p _), nat.mod_self] with parity_simps,
-- -- finish },--finish },
-- {
-- -- have : 2 ^ a + sum s (pow 2) % 2 ^ i = (2 ^ a + sum s (pow 2)) % 2 ^ i,
-- -- from begin
-- -- rw [add_mod]
-- -- end,
-- -- rw [hnm hai, mod_eq_of_lt ((pow_lt_iff_lt_right (le_refl _)).2 hai)],
-- rw [even_div],
-- simp [ne_of_gt hai, hnm hai, ih] with parity_simps, },
-- end)
lemma ith_bit_binary (A : finset ℕ) : ∀ i,
i ∈ A ↔ ¬ even (binary A / 2 ^ i) :=
finset.induction_on A
(by simp [binary, ith_bit])
(λ a s has ih i,
begin
dsimp [binary, ith_bit] at *,
rw [sum_insert has, mem_insert,
nat.add_div (nat.pow_pos (show 0 < 2, from dec_trivial) _)],
have hnm : ∀ {n m}, n < m → 2^n / 2^m = 0,
from λ n m h, div_eq_of_lt ((pow_lt_iff_lt_right (le_refl _)).2 h),
have hnm' : ∀ {n m : ℕ}, n < m → 2^m % 2^n = 0, from sorry,
have h2p : ∀ {n : ℕ}, 0 < 2^n, from sorry,
rcases lt_trichotomy i a with hia|rfl|hai,
{ have : even (2^a / 2^i),
{ rw [even_div, mod_mul_left_div_self, ← dvd_iff_mod_eq_zero],
apply dvd_div_of_mul_dvd,
rw [← nat.pow_succ],
exact pow_dvd_pow _ hia },
rw [hnm' hia, zero_add, if_neg (not_le_of_gt (mod_lt _ h2p))],
simp [*, ne_of_lt hia, ih, hnm' hia] with parity_simps },
{ rw [mod_self, zero_add, if_neg (not_le_of_gt (mod_lt _ h2p))],
simp [nat.div_self (nat.pow_pos h2p _), nat.mod_self] with parity_simps,
finish },--finish },
{ have : (2 ^ a + sum s (pow 2)) % 2 ^ i < 2 ^ a + sum s (pow 2) % 2 ^ i,
from _,
rw [hnm hai, mod_eq_of_lt ((pow_lt_iff_lt_right (le_refl _)).2 hai)],
simp [ne_of_gt hai, hnm hai, ih] with parity_simps, },
end)
lemma ith_bit_binary (A : finset ℕ) : ∀ i,
i ∈ A ↔ ith_bit (binary A) i = 1 :=
finset.induction_on A
(by simp [binary, ith_bit])
(λ a s has ih i, begin
dsimp [binary, ith_bit] at *,
rw [sum_insert has, mem_insert, nat.add_div],
rcases lt_trichotomy i a with hia|rfl|hai,
{
rw [if_neg, add_zero],
}
end)
example : function.injective (binary) :=
function.injective_of_has_left_inverse
⟨λ n, (range n).filter (λ i, n / 2^i ≠ n / 2^(i+1)),
λ s, finset.induction_on s
(by simp [binary]) $
λ a s has ih, begin
conv_rhs { rw ← ih },
ext i,
simp only [binary, sum_insert has, mem_filter, mem_range,
mem_insert],
split,
{ assume h,
}
end⟩
-- λ s, finset.induction_on s
-- (λ t h, begin simp [binary] at *, end) $
-- λ a s has ih t h,
-- have hat : binary t = binary (insert a (t.erase a)),
-- from h ▸ congr_arg binary (by finish [finset.ext]),
-- begin
-- rw [erase_in]
-- end
example (m : nat) : 0 * m = 0 :=
begin
induction m with m ih,
rw mul_zero,
rw [nat.mul_succ],
end
lemma z (a b c : ℝ) : a^3 + b^3 + c^3 - 3 * a * b * c =
1/2 * (a + b + c) * ((a - b)^2 + (b - c)^2 + (c - a)^2) := by ring
#print z
#exit
import data.set.basic
example {X : Type} (A B : set X) : A ∩ B = A ∪ B ↔ A = B :=
⟨λ h, set.ext $ λ x,
⟨λ hA, set.mem_of_subset_of_mem (set.inter_subset_right A B) (h.symm ▸ or.inl hA),
λ hB, set.mem_of_subset_of_mem (set.inter_subset_left A B) (h.symm ▸ or.inr hB)⟩,
by simp {contextual := tt}⟩
#exit
import data.int.basic
#print nat_abs
inductive cool : ℕ → Prop
| cool_2 : cool 2
| cool_5 : cool 5
| cool_sum : ∀ (x y : ℕ), cool x → cool y → cool (x + y)
| cool_prod : ∀ (x y : ℕ), cool x → cool y → cool (x*y)
example : 7 = sorry :=
begin
dsimp only [bit0, bit1],
end
example : cool 7 := (cool.cool_sum 2 5 cool.cool_2 cool.cool_5 : _)
#exit
import data.polynomial
variables {R : Type*} [comm_ring R]
open polynomial
lemma zzzz {u r : R} {n : ℕ} (hr : r^n = 0) (hu : is_unit u) : is_unit (u + r) :=
have hnegr : (-r)^n = 0, by rw [neg_eq_neg_one_mul, mul_pow, hr, mul_zero],
have (X - C (-r)) ∣ X ^ n, from dvd_iff_is_root.2 (by simp [is_root, hnegr]),
is_unit_of_dvd_unit
(let ⟨p, hp⟩ := this in ⟨p.eval u, by simpa using congr_arg (eval u) hp⟩)
(is_unit_pow n hu)
#print acc.intro
#exit
import data.zmod.quadratic_reciprocity
@[simp] lemma list.lex_nil_right (l)
#eval @nat.modeq.chinese_remainder 5 8 rfl 4 7
#eval zmodp.legendre_sym 10 71 (by norm_num)
#eval zmodp.legendre_sym 2 71 (by norm_num)
#eval zmodp.legendre_sym 5 71 (by norm_num)
#eval zmodp.legendre_sym 71 5 (by norm_num)
example {α : Type} [nonempty α] (F G : α → Prop)
(h : (∃ x, F x) → ∃ x, G x) : ∃ x, F x → G x :=
begin
resetI,
classical,
cases _inst_1 with a,
rcases classical.em (∃ x, G x) with ⟨x, hx⟩ | hx,
{ exact ⟨x, λ _, hx⟩ },
{ exact ⟨a, λ hF, (not_exists.1 (not_imp_not.2 h hx) a hF).elim ⟩ }
end
def sum' (f : ℕ → ℕ) : ℕ → ℕ
| 0 := 0
| (n+1) := sum' n + f n
#exit
import data.equiv.basic group_theory.perm.sign
#eval nat.choose 8 3
#eval (finset.range (721)).filter (λ x, x ∣ 720 ∧ x % 7 = 1)
#eval ((finset.Ico 1 31).powerset.filter
(λ s : finset ℕ, s.card = 8 ∧
((s.filter (λ s : finset ℕ, s.card = 4)).1.map
(λ s : finset ℕ, s.1.sum)).nodup)
open equiv equiv.perm
variable {α : Type}
open_locale classical
example (f : perm α) (a b : α) :
f * swap a b * f⁻¹ = sorry :=
begin
rw [mul_assoc, swap_mul_eq_mul_swap, inv_inv],
simp,
end
#exit
inductive tree : Type
| lf : tree
| nd : tree -> nat -> tree -> tree
open tree
def fusion : tree -> tree -> tree
| lf t2 := t2
| t1 lf := t1
| (nd l1 x1 r1) (nd l2 x2 r2) :=
if x1 ≤ x2
then nd (fusion r1 (nd l2 x2 r2)) x1 l1
else nd (fusion (nd l1 x1 r1) r2) x2 l2
-- using_well_founded { rel_tac := λ _ _,
-- `[exact ⟨_, measure_wf (λ t, tree.sizeof t.1 + tree.sizeof t.2)⟩] }
#print fusion._main._pack.equations._eqn_1
theorem fusion_lf : ∀ (t : tree), fusion lf lf = lf :=
λ _, rfl
example (t : tree) : fusion t lf = lf :=
by cases t; refl
#exit
import data.real.nnreal
#print xor
example : (∀ p q r, xor (xor p q) r ↔ xor p (xor q r)) → ∀ p, p ∨ ¬p :=
λ h p,
((h p p true).1
(or.inr ⟨trivial, λ h, h.elim (λ h, h.2 h.1) (λ h, h.2 h.1)⟩)).elim
(λ h, or.inl h.1)
(λ h, or.inr h.2)
example : (∀ p q, xor p q ↔ (p ∨ q) ∧ ¬(p ∧ q)) :=
λ p q, ⟨λ h, h.elim (λ h, ⟨or.inl h.1, λ h1, h.2 h1.2⟩)
(λ h, ⟨or.inr h.1, λ h1, h.2 h1.1⟩),
(λ h, h.1.elim
(λ hp, or.inl ⟨hp, λ hq, h.2 ⟨hp, hq⟩⟩)
(λ hq, or.inr ⟨hq, λ hp, h.2 ⟨hp, hq⟩⟩))⟩
example : (∀ p q r, ((p ↔ q) ↔ r) ↔ (p ↔ (q ↔ r))) → ∀ p, p ∨ ¬p :=
λ h p,
((h (p ∨ ¬p) false false).1
⟨λ h, h.1 (or.inr (λ hp, h.1 (or.inl hp))), false.elim⟩).2
iff.rfl
inductive pre_free_group (α : Type) : Type
| atom : α → pre_free_group
| one : pre_free_group
| mul : pre_free_group → pre_free_group → pre_free_group
| inv : pre_free_group → pre_free_group
namespace pre_free_group
variable {α : Type}
instance : has_one (pre_free_group α) := ⟨pre_free_group.one _⟩
instance : has_mul (pre_free_group α) := ⟨pre_free_group.mul⟩
instance : has_inv (pre_free_group α) := ⟨pre_free_group.inv⟩
lemma mul_def : (*) = @pre_free_group.mul α := rfl
lemma one_def : 1 = @pre_free_group.one α := rfl
lemma inv_def : has_inv.inv = @pre_free_group.inv α := rfl
inductive rel : Π (a b : pre_free_group α), Prop
| mul_assoc : ∀ a b c, rel ((a * b) * c) (a * (b * c))
| one_mul : ∀ a, rel (1 * a) a
| mul_one : ∀ a, rel (a * 1) a
| mul_left_inv : ∀ a, rel (a⁻¹ * a) 1
| mul_lift : ∀ a b c d, rel a b → rel c d → rel (a * c) (b * d)
| inv_lift : ∀ a b, rel a b → rel (a⁻¹) (b⁻¹)
| refl : ∀ a, rel a a
| symm : ∀ a b, rel a b → rel b a
| trans : ∀ a b c, rel a b → rel b c → rel a c
instance (α : Type) : setoid (pre_free_group α) :=
{ r := rel,
iseqv := ⟨rel.refl, rel.symm, rel.trans⟩ }
end pre_free_group
def free_group (α : Type) := quotient (pre_free_group.setoid α)
namespace free_group
open pre_free_group
variable {α : Type}
instance : group (free_group α) :=
{ one := ⟦1⟧,
mul := λ a b, quotient.lift_on₂ a b (λ a b, ⟦a * b⟧)
(λ a b c d h₁ h₂, quotient.sound (rel.mul_lift _ _ _ _ h₁ h₂)),
inv := λ a, quotient.lift_on a (λ a, ⟦a⁻¹⟧)
(λ a b h, quotient.sound (rel.inv_lift _ _ h)),
mul_assoc := λ a b c, quotient.induction_on₃ a b c
(λ a b c, quotient.sound (rel.mul_assoc _ _ _)),
one_mul := λ a, quotient.induction_on a
(λ a, quotient.sound (rel.one_mul a)),
mul_one := λ a, quotient.induction_on a
(λ a, quotient.sound (rel.mul_one a)),
mul_left_inv := λ a, quotient.induction_on a
(λ a, quotient.sound (rel.mul_left_inv _)) }
def atom (a : α) : free_group α := ⟦pre_free_group.atom a⟧
variables {G : Type} [group G]
def lift (G : Type) [group G] (f : α → G) : free_group α →* G :=
{ to_fun := λ a, quotient.lift_on a
(λ a, show G, from pre_free_group.rec_on a f 1 (λ _ _, (*)) (λ _ g, g⁻¹))
(λ a b h, begin
dsimp,
induction h;
try { dsimp [mul_def, inv_def, one_def] };
simp [mul_assoc, *] at *,
end),
map_one' := rfl,
map_mul' := λ a b, quotient.induction_on₂ a b (λ _ _, rfl) }
lemma one_def : (1 : free_group α) = ⟦pre_free_group.one α⟧ := rfl
lemma mul_def {a b : pre_free_group α} :
@eq (free_group α) ⟦pre_free_group.mul a b⟧ (⟦a⟧ * ⟦b⟧) := rfl
lemma inv_def {a : pre_free_group α} :
@eq (free_group α) ⟦pre_free_group.inv a⟧ (⟦a⟧⁻¹) := rfl
@[simp] lemma mk_apply {α β : Type*} [monoid α] [monoid β] (f : α → β) (h₁ h₂) (a : α) :
monoid_hom.mk f h₁ h₂ a = f a := rfl
@[simp] lemma lift_atom (f : α → G) (a : α) : lift G f (atom a) = f a := rfl
lemma lift_unique (f : α → G) (φ : free_group α →* G) (h : ∀ a, φ (atom a) = f a)
(g : free_group α) : φ g = lift G f g :=
quotient.induction_on g
(λ a, begin
dsimp [atom, lift] at *,
induction a;
simp [*, one_def.symm, mul_def, inv_def] at *;
refl,
end)
end free_group
#exit
import algebra.free
universe u
inductive pre_free_ring (α : Type u) : Type u
| atom : α → pre_free_ring
| zero : pre_free_ring
| one : pre_free_ring
| neg : pre_free_ring → pre_free_ring
| mul : pre_free_ring → pre_free_ring → pre_free_ring
| add : pre_free_ring → pre_free_ring → pre_free_ring
namespace pre_free_ring
variable {α : Type u}
instance : has_zero (pre_free_ring α) := ⟨pre_free_ring.zero _⟩
instance : has_one (pre_free_ring α) := ⟨pre_free_ring.one _⟩
instance : has_neg (pre_free_ring α) := ⟨pre_free_ring.neg⟩
instance : has_mul (pre_free_ring α) := ⟨pre_free_ring.mul⟩
instance : has_add (pre_free_ring α) := ⟨pre_free_ring.add⟩
inductive rel : Π (a b : pre_free_ring α), Prop
| add_assoc : ∀ a b c, rel (a + b + c) (a + (b + c))
| zero_add : ∀ a, rel (0 + a) a
| add_zero : ∀ a, rel (a + 0) a
| add_left_neg : ∀ a, rel (-a + a) 0
| add_comm : ∀ a b, rel (a + b) (b + a)
| mul_assoc : ∀ a b c, rel (a * b * c) (a * (b * c))
| one_mul : ∀ a, rel (1 * a) a
| mul_one : ∀ a, rel (a * 1) a
| left_distrib : ∀ a b c, rel (a * (b + c)) (a * b + a * c)
| right_distrib : ∀ a b c, rel ((a + b) * c) (a * c + b * c)
| add_lift : ∀ a b c d, rel a b → rel c d → rel (a + c) (b + d)
| mul_lift : ∀ a b c d, rel a b → rel c d → rel (a * c) (b * d)
| neg_lift : ∀ a b, rel a b → rel (-a) (-b)
| refl : ∀ a, rel a a
| symm : ∀ a b, rel a b → rel b a
| trans : ∀ a b c, rel a b → rel b c → rel a c
instance (α : Type u) : setoid (pre_free_ring α) :=
{ r := rel,
iseqv := ⟨rel.refl, rel.symm, rel.trans⟩ }
end pre_free_ring
variable {α : Type u}
def free_ring (α : Type u) := quotient (pre_free_ring.setoid α)
namespace free_ring
open pre_free_ring
instance : ring (free_ring α) :=
{ zero := quotient.mk' 0,
one := quotient.mk' 1,
add := λ a b, quotient.lift_on₂ a b (λ a b, quotient.mk (a + b))
(λ a b c d h₁ h₂, quot.sound (rel.add_lift _ _ _ _ h₁ h₂)),
mul := λ a b, quotient.lift_on₂ a b (λ a b, quotient.mk (a * b))
(λ a b c d h₁ h₂, quot.sound (rel.mul_lift _ _ _ _ h₁ h₂)),
add_assoc := λ a b c, quotient.induction_on₃ a b c
(λ a b c, quot.sound (rel.add_assoc _ _ _)),
mul_assoc := λ a b c, quotient.induction_on₃ a b c
(λ a b c, quot.sound (rel.mul_assoc _ _ _)),
zero_add := λ a, quotient.induction_on a (λ a, quot.sound (rel.zero_add a)),
add_zero := λ a, quotient.induction_on a (λ a, quot.sound (rel.add_zero a)),
neg := λ a, quotient.lift_on a (λ a, quotient.mk (-a))
(λ a b h, quot.sound (rel.neg_lift _ _ h)),
add_left_neg := λ a, quotient.induction_on a
(λ a, quot.sound (rel.add_left_neg _)),
add_comm := λ a b, quotient.induction_on₂ a b
(λ a b, quotient.sound (rel.add_comm _ _)),
one_mul := λ a, quotient.induction_on a (λ a, quot.sound (rel.one_mul a)),
mul_one := λ a, quotient.induction_on a (λ a, quot.sound (rel.mul_one a)),
left_distrib := λ a b c, quotient.induction_on₃ a b c
(λ a b c, quot.sound (rel.left_distrib _ _ _)),
right_distrib := λ a b c, quotient.induction_on₃ a b c
(λ a b c, quot.sound (rel.right_distrib _ _ _)) }
def atom : α → free_ring α := λ a, ⟦atom a⟧
#print linear_ordered_ring
#print
inductive le : free_ring bool → free_ring bool → Prop
| atom : le (atom ff) (atom tt)
| refl : ∀ x, le x x
| trans : ∀ a b c, le a b → le b c → le a c
| add_le_add_left :
#exit
import group_theory.subgroup algebra.commute
lemma X {α : Type} {φ : α → Prop}: (¬ ∃ v, φ v) ↔ (∀ v, ¬ φ v) :=
⟨λ ex v hv, ex ⟨v, hv⟩, Exists.rec⟩
#exit
open equiv
variables {G : Type*} [group G]
#print equiv.ext
def L (g : G) : perm G := ⟨λ h, g * h, λ h, g⁻¹ * h, λ _, by simp, λ _, by simp⟩
def R (g : G) : perm G := ⟨λ h, h * g⁻¹, λ h, h * g, λ _, by simp, λ _, by simp⟩
lemma perm.ext_iff {f g : perm G} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, by rw h, equiv.perm.ext _ _⟩
lemma forall_mem_range {α β : Type*} {p : β → Prop} {f : α → β} :
(∀ x ∈ set.range f, p x) ↔ (∀ x, p (f x)) :=
⟨λ h x, h _ (set.mem_range_self _), by rintros h x ⟨y, rfl⟩; exact h _⟩
lemma question_4 : set.centralizer (set.range L : set (perm G)) = set.range R :=
calc set.centralizer (set.range L) = { σ : perm G | ∀ g g₁, σ (g * g₁) = g * σ g₁ } :
by simp only [set.ext_iff, commute, semiconj_by, set.centralizer, forall_mem_range, perm.ext_iff];
tauto
... = set.range R : set.ext $ λ f,
⟨λ h, ⟨(f 1)⁻¹, perm.ext_iff.2 $ λ x, by dsimp [R]; rw [inv_inv, ← h, mul_one]⟩,
by rintros ⟨g, rfl⟩; simp [R, mul_assoc]⟩
#print Z
-- set.subset.antisymm
-- (λ f h, ⟨(f 1)⁻¹, perm.ext_iff.2 $ λ x, begin
-- have := h (L (f 1)) (set.mem_range_self _) ,
-- simp [commute, semiconj_by, L, R, perm.ext_iff] at *,
-- end⟩ )
-- (λ f, by rintros ⟨g, rfl⟩ f ⟨h, rfl⟩;
-- simp [set.centralizer, L, R, perm.ext_iff, commute, semiconj_by, mul_assoc])
instance : is_subgroup
#exit
import data.complex.basic tactic.norm_num tactic.ring
lemma X (a b : ℤ) (n : ℕ) : (a + b)^(n + 2) =
(a^2 + 2 * a * b + b^2) * (a + b)^n :=
by simp only [pow_add]; ring
#print X
example (n : nat) (m : int) : 2^(n+1) * m = 2 * 2^n * m :=
by simp only [pow_add]; ring
#eval ((∘) ∘ (∘)) (+) (*) 13 11 20
#eval (∘) ((∘) (+)) (*) 13 11 20
#eval (((∘) (+)) ∘ (*)) 13 11 20
#eval ((∘) (+)) (* 13) 11 20
#eval ((+) ∘ (* 13)) 11 20
#eval (+) (11 * 13) 20
#eval (11 * 13) + 20
example {X Y : Type*} : Π [nonempty X] [nonempty Y], nonempty (X × Y)
| ⟨x⟩ ⟨y⟩ := ⟨(x, y)⟩
#exit
import data.real.basic order.conditionally_complete_lattice
instance : lattice.conditionally_complete_linear_order_bot (with_bot ℝ) :=
by apply_instance
import data.zsqrtd.gaussian_int
#eval ((finset.range 200).filter
(λ x, ∃ a b : fin (x + 1), a.1^2 + b.1^2 = x)).sort (≤)
₄
notation `ℤ[i]` := gaussian_int
open euclidean_domain
#eval nat.factors (8 * 74 + 2)
#eval gcd (⟨557, 55⟩ : ℤ[i]) 12049
#eval 32 ^ 2 + 105 ^ 2
#exit
import tactic.omega data.nat.modeq
inductive C : Type
| c1 : C
| c2 : C
inductive D : Type
| d1 : D
| d2 : D
def thing1 (c : C) (d : D) : D :=
c.rec
(_) -- correct "don't know how to synthesize placeholder -- here's a helpful context"
(_) -- correct
def thing2 (c : C) (d : D) : D :=
C.rec_on c
(D.rec_on d _ _ )
(_)
open nat
example (n : fin 70) : n % 7 = (n / 10 + 5 * (n % 10)) % 7 :=
begin
revert n,
exact dec_trivial,
end
example (n : ℤ) (d : ℕ) (h : (2 : ℚ) * (d * d : ℤ) = ((n * n : ℤ) : ℚ)) :
2 * ((d : ℤ) * (d : ℤ)) = n * n :=
begin
rw [← @int.cast_inj ℚ],
end
#exit
import analysis.normed_space.basic
open metric
variables
{V : Type*} [normed_group V] [complete_space V] [normed_space ℝ V]
def B' : set V := closed_ball 0 1
example : B' ⊆ ⋃ (a : V) (H : a ∈ (B' : set V)), ball a 0.5 :=
begin
sorry
end
#exit
theorem add_comm (a b : ℕ) : begin
apply eq,
apply ((+) : ℕ → ℕ → ℕ),
apply a,
apply b,
apply ((+) : ℕ → ℕ → ℕ),
apply b,
apply a,
end
#exit
import data.fintype
#eval (@finset.univ (fin 100 × fin 100 × fin 100) _).filter
(λ k : fin 100 × fin 100 × fin 100, (k.1.1 ^ k.2.1.1 + 1) ∣ (k.1.1 + 1 : ℕ)^k.2.2.1
∧ k.1.1 > 1 ∧ k.2.1.1 > 1 ∧ k.2.2.1 > 1)
--import data.zmod.basic data.zmod.quadratic_reciprocity
example {k : ℕ+} (h : (3 ^ (2 ^ ((k - 1) : ℕ) : ℕ) :
zmod (2 ^ (2 ^ (k : ℕ)) + 1)) = -1) : nat.prime (2 ^ (2 ^ (k : ℕ)) + 1) :=
let n : ℕ+ := ⟨3 ^ (2 ^ ((k - 1) : ℕ) : ℕ) + 1, nat.succ_pos _⟩ in
have p3 : nat.prime 3, by norm_num,
have cp3n : nat.coprime 3 n,
begin
dsimp [n, nat.coprime],
erw [nat.gcd_rec, ← zmodp.val_cast_nat p3 (3 ^ 2 ^ (k - 1 : ℕ) + 1)],
simp [zero_pow (nat.pow_pos (show 0 < 2, from dec_trivial) _)]
end,
let u3 : units (zmod n) := (@zmod.units_equiv_coprime n).symm ⟨3, sorry⟩ in
have h3 : u3 ^ (n : ℕ) = 1, from _,
begin
end
import data.fintype
variable {α : Type*}
open finset
theorem fintype.card_subtype_lt [fintype α] (p : α → Prop) [decidable_pred p]
{x : α} (hx : ¬ p x) : fintype.card {x // p x} < fintype.card α :=
by rw [fintype.subtype_card]; exact finset.card_lt_card
⟨subset_univ _, classical.not_forall.2 ⟨x, by simp [*, set.mem_def]⟩⟩
#exit
import data.zmod.basic data.polynomial
open polynomial
inductive T : ℕ → Type
| mk : Π (n m : ℕ) (t : T m) (f : Π {n : ℕ}, T n), T n
#print T.rec
set_option trace.simplify.rewrite true
#print X
import data.nat.prime
open nat
lemma min_fac_le_div {n : ℕ} (pos : 0 < n) (np : ¬ prime n) : min_fac n ≤ n / min_fac n :=
match min_fac_dvd n with
| ⟨0, h0⟩ := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial
| ⟨1, h1⟩ := begin
rw mul_one at h1,
rw [prime_def_min_fac, not_and_distrib, ← h1, eq_self_iff_true, not_true, or_false, not_le] at np,
rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]
end
| ⟨(x+2), hx⟩ := begin
conv_rhs { congr, rw hx },
rw [nat.mul_div_cancel_left _ (min_fac_pos _)],
exact min_fac_le_of_dvd dec_trivial ⟨min_fac n, by rwa mul_comm⟩
end
#exit
import tactic.finish
lemma X (p : Prop): ¬(p ↔ ¬ p) := by ifinish
#print X
open multiset function
lemma eq_zero_iff_forall_not_mem {α : Type*} {s : multiset α} : s = 0 ↔ ∀ a, a ∉ s :=
⟨λ h, h.symm ▸ λ _, not_false, eq_zero_of_forall_not_mem⟩
lemma map_eq_map {α β γ : Type*} (f : α → γ) (g : β → γ) {s : multiset α}
(hs : s.nodup) {t : multiset β} (ht : t.nodup) (i : Πa∈s, β)
(hi : ∀a ha, i a ha ∈ t) (h : ∀a ha, f a = g (i a ha))
(i_inj : ∀a₁ a₂ ha₁ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀b∈t, ∃a ha, b = i a ha) :
s.map f = t.map g :=
have t = s.attach.map (λ x, i x.1 x.2),
from (nodup_ext ht (nodup_map
(show injective (λ x : {x // x ∈ s}, i x.1 x.2), from λ x y hxy,
subtype.eq (i_inj x.1 y.1 x.2 y.2 hxy))
(nodup_attach.2 hs))).2
(λ x, by simp only [mem_map, true_and, subtype.exists, eq_comm, mem_attach];
exact ⟨i_surj _, λ ⟨y, hy⟩, hy.snd.symm ▸ hi _ _⟩),
calc s.map f = s.pmap (λ x _, f x) (λ _, id) : by rw [pmap_eq_map]
... = s.attach.map (λ x, f x.1) : by rw [pmap_eq_map_attach]
... = t.map g : by rw [this, multiset.map_map]; exact map_congr (λ x _, h _ _)
#exit
import tactic.ring
example (p : ℕ) : p / 2 * (p / 2) + p / 2 * (p / 2) + p % 2 * (p % 2) +
(2 * (p / 2 * (p / 2)) + 4 * (p / 2) * (p % 2)) =
(p % 2 + 2 * (p / 2)) * (p % 2 + 2 * (p / 2)) :=
begin
ring,
end
example (n : ℕ) : n + n = 2 * n := by ring
import data.nat.prime
inductive option' (α : Sort*) : Sort*
| none {} : option'
| some : α → option'
def zmod (n : ℕ) (h : option' n.prime := option'.none) : Type := fin n
#exit
import data.zmod.basic algebra.euclidean_domain
def remainder_aux (a b : ℤ) : ℤ :=
if hb : b = 0 then a
else (a : zmod ⟨b.nat_abs, int.nat_abs_pos_of_ne_zero hb⟩).val_min_abs
def X : euclidean_domain ℤ :=
{ remainder := remainder_aux,
quotient := λ a b, (a - remainder_aux a b) / b,
quotient_zero := by simp [remainder_aux],
quotient_mul_add_remainder_eq := λ a b,
begin
rw [remainder_aux, int.mul_div_cancel', sub_add_cancel],
split_ifs with hb,
{ simp },
{ erw [← int.nat_abs_dvd,
← @zmod.eq_zero_iff_dvd_int ⟨b.nat_abs, int.nat_abs_pos_of_ne_zero hb⟩],
simp }
end,
r := λ x y, x.nat_abs < y.nat_abs,
r_well_founded := measure_wf _,
remainder_lt := λ a b hb0,
by rw [remainder_aux, dif_neg hb0];
exact lt_of_le_of_lt (zmod.nat_abs_val_min_abs_le _) (nat.div_lt_self
(int.nat_abs_pos_of_ne_zero hb0) dec_trivial),
mul_left_not_lt := λ a b hb0, not_lt_of_le $
by rw [int.nat_abs_mul];
exact le_mul_of_one_le_right' (nat.zero_le _) (int.nat_abs_pos_of_ne_zero hb0) }
#exit
import algebra.field data.rat.basic data.nat.choose
#print axioms add_pow
#print inv_inv'
set_option trace.simplify.rewrite true
example (x : ℚ) : x⁻¹⁻¹ = x := by simp
@[simp] lemma sol_set_simplex (T : tableau m n) (hT : feasible T) (w : tableau m n → bool)
(obj : fin m) : (T.simplex w obj hT).1.sol_set = T.sol_set :=
by simp [sol_set_eq_res_set_inter_dead_set]
import algebra.group_power
example (n : ℕ) (a b : ℤ) : (a * b) ^ n = a ^ n * b ^ n :=
begin
induction n with n ih,
end
#exit
import data.equiv.basic data.int.basic data.set.intervals
def int.Ico_fin_equiv (a b : ℤ) : set.Ico a b ≃ fin (int.to_nat $ b - a) :=
calc set.Ico a b ≃ set.Ico 0 (b - a) :
⟨λ x, ⟨x.1 - a, sub_nonneg.2 x.2.1, add_lt_add_right x.2.2 _⟩,
λ x, ⟨x.1 + a, le_add_of_nonneg_left x.2.1, lt_sub_iff_add_lt.1 x.2.2⟩,
λ _, by simp, λ _, by simp⟩
... ≃ fin (int.to_nat $ b - a) :
⟨λ x, ⟨x.1.to_nat, int.coe_nat_lt.1 $
by rw [int.to_nat_of_nonneg x.2.1, int.to_nat_of_nonneg (le_trans x.2.1 (le_of_lt x.2.2))];
exact x.2.2⟩,
λ x, ⟨x.1, int.coe_nat_nonneg _, begin
have := int.coe_nat_lt.2 x.2,
rwa [int.to_nat_of_nonneg] at this,
cases b - a;
simp only [int.to_nat, int.coe_nat_lt, nat.not_lt_zero, *] at *
end⟩,
λ x, by simp [int.to_nat_of_nonneg x.2.1],
λ x, by simp⟩
def int.Ioo_fin_equiv (a b : ℤ) : set.Ioo a b ≃ fin (int.to_nat $ b - (a + 1)) :=
calc set.Ioo a b ≃ set.Ico (a + 1) b : equiv.set.of_eq (by simp [set.ext_iff, int.add_one_le_iff])
... ≃ _ : int.Ico_fin_equiv _ _
def int.Ioc_fin_equiv (a b : ℤ) : set.Ioc a b ≃ fin (int.to_nat $ b - a) :=
calc set.Ioc a b ≃ set.Ioo a (b + 1) : equiv.set.of_eq (by simp [set.ext_iff, int.lt_add_one_iff])
... ≃ fin (int.to_nat $ (b + 1) - (a + 1)) : int.Ioo_fin_equiv _ _
... ≃ fin (int.to_nat $ b - a) : ⟨fin.cast (by simp), fin.cast (by simp),
λ _, fin.eq_of_veq rfl, λ _, fin.eq_of_veq rfl⟩
def int.Icc_fin_equiv (a b : ℤ) : set.Icc a b ≃ fin (int.to_nat $ b + 1 - a) :=
calc set.Icc a b ≃ set.Ico a (b + 1) : equiv.set.of_eq (by simp [set.ext_iff, int.lt_add_one_iff])
... ≃ fin (int.to_nat $ b + 1 - a) : int.Ico_fin_equiv _ _
class good (n : ℕ).
instance good4 : good 4 := good.mk _
local attribute [-pattern] nat.add has_add.add
local attribute [irreducible] has_add.add
local attribute [reducible] nat.mul
example : good (2 + 2) := infer_instance
example : good (2 * 2) := infer_instance
example : good (0 + 4) := infer_instance
#print has_add.add
#print nat.add
#print has_mul.mul
#print nat.mul
#exit
import tactic
inductive next_to : ℤ → ℤ → Prop
| left : ∀ x, next_to x (x + 1)
| right : ∀ x, next_to (x + 1) x
def next_to (a b : ℤ) := ∃ d ∈ ([-1, 1] : list ℤ), a + d = b
lemma next_to.symm {a b : ℤ} (hab : next_to a b) : next_to b a :=
by rcases hab with ⟨x, hx₁, hx₂⟩;
exact ⟨-x, by simpa [eq_neg_iff_eq_neg, eq_comm, or_comm] using hx₁, by rw ← hx₂; simp⟩
#exit
#print tc
inductive tc' {α : Type*} (r : α → α → Prop) : α → α → Prop
| base : ∀ {x y}, r x y → tc' x y
| base_trans : ∀ {x y z}, r x y → tc' y z → tc' x z
lemma tc'.trans {α : Type*} (r : α → α → Prop) {x y z}
(hxy : tc' r x y) : tc' r y z → tc' r x z :=
tc'.rec_on hxy (λ _ _, tc'.base_trans)
(λ x y b hxy hyb ih hbz, tc'.base_trans hxy (ih hbz))
#print tc
#exit
example : (1 : ℕ) = 1 + @has_zero.zero ℕ ⟨1⟩ :=
begin
rw add_zero,
end
#exit
import data.list.basic
inductive unit2 : Type
| star : unit2
instance : has_repr unit2 := ⟨λ x, "9"⟩
@[instance, priority 10000] def x : has_repr unit := ⟨λ x, punit.rec_on x "1"⟩
set_option profiler true
#eval if (list.range 1000000).sum = 999999 * 500000 then unit2.star else unit2.star
#eval if (list.range 1000000).sum = 999999 * 500000 then () else ()
#exit
import data.list
open list
lemma filter_false' {α : Type*} (l : list α) : l.filter (λ _, false) = [] := filter_false _
example (xs : list ℕ) : xs.filter (λ x, ¬true) = [] :=
by simp only [not_true]; convert filter_false' xs
example (xs : list ℕ) : xs.filter (λ x, ¬true) = [] :=
by simp only [not_true]; rw ← filter_false' xs; congr
#exit
import algebra.big_operators tactic.ring
def ssquares : ℕ → ℕ
| 0 := 0
| (n+1) := (n+1)*(n+1) + (ssquares n)
theorem ssquares_formula (n : ℕ) : 6*(ssquares n) = n*(n+1)*(2*n+1) :=
nat.rec_on n rfl -- trivial base case
(
assume k,
assume h : 6*(ssquares k) = k*(k+1)*(2*k+1),
show 6*(ssquares (k+1)) = (k+1)*((k+1)+1)*(2*(k+1)+1), from
calc
6*(ssquares (k+1)) = 6*((k+1)*(k+1) + (ssquares k)) : rfl
... = 6*((k+1)*(k+1)) + k*(k+1)*(2*k+1) : by rw [left_distrib, h]
... = _ : by ring)
#exit
import group_theory.abelianization
#print axioms
#print quotient_group._to_additive
open tactic expr
meta def get_macro : expr → list name
| (mvar _ _ e) := get_macro e
| (local_const _ _ _ e) := get_macro e
| (app e₁ e₂) := get_macro e₁ ++ get_macro e₂
| (lam _ _ e₁ e₂) := get_macro e₁ ++ get_macro e₂
| (pi _ _ e₁ e₂) := get_macro e₁ ++ get_macro e₂
| (elet _ e₁ e₂ e₃) := get_macro e₁ ++ get_macro e₂ ++ get_macro e₃
| (macro m l) := macro_def_name m :: l.bind get_macro
| _ := []
-- #eval get_macro `()
-- #print declaration.type
-- run_cmd do e ← get_env, let l : list name := environment.fold e []
-- (λ d l, let t := d.type in cond (expr.occurs `(macro_def) t) (d.to_name :: l) l),
-- trace l, return ()
def repr_aux : name → string
| name.anonymous := "anonymous"
| (name.mk_string s n) := "mk_string " ++ s ++ " (" ++ repr_aux n ++ ")"
| (name.mk_numeral i n) := "mk_numeral " ++ repr i ++ repr_aux n
run_cmd tactic.add_decl (declaration.defn `sorry [] `(nat) `(0)
(reducibility_hints.opaque) tt)
def X : false := sorry
lemma Y : false := X
#print axioms
#eval (is_sorry `(X)).is_some
run_cmd do d ← get_decl `sorry, trace d.value, return ()
run_cmd do d ← get_decl `X, trace ((get_macro d.value).map repr_aux)
#print macro_def
def X := by tactic.exact $ macro prod.fst [var 0]
#print tactic.exact
#print expr
#exit
import tactic.norm_num
example : ∃ a b c : ℤ, a^3 + b^3 + c^3 = 42 :=
⟨-80538738812075974, 80435758145817515, 12602123297335631, by norm_num⟩
#exit
inductive T : Type
| foo : T → T
def X : T → T := T.foo
set_option trace.compiler.optimize_bytecode true
#eval X
#exit
import data.zsqrtd.gaussian_int data.list.basic
set_option profiler true
#eval (((((list.range 100).product (list.range 10)).product
((list.range 10).product (list.range 10))).map
(λ a : (nat × nat) × (nat × nat),
(zsqrtd.mk (int.of_nat a.1.1) (int.of_nat a.1.2) : gaussian_int) /
⟨int.of_nat a.2.1, int.of_nat a.2.2⟩)).sum
--5.18 seconds to 1.62 ms
#eval euclidean_domain.gcd
(⟨35,2⟩ : gaussian_int) 15
#exit
import algebra.big_operators
@[inline] def ack : nat → nat → nat
| 0 y := y+1
| (x+1) 0 := ack x 1
| (x+1) (y+1) := ack x (ack (x+1) y)
def P : ℕ → Prop := λ n, n < 2
instance : decidable_pred P := λ _, nat.decidable_lt _ _
def X (n : ℕ) : ℕ := if P n then 0 else ack 100 100
set_option trace.compiler.code_gen true
#eval if P 0 then 0 else ack 100 100
#exit
import category_theory.category
open category_theory
variables {obj : Type*} [category obj] (X : obj)
#print nat.add
#exit
import data.zmod.basic
theorem test_ind (n : nat) : (3^n -1) % 2 = 0 :=
have (3 : zmod 2) ^ n - 1 = 0, by simp [show (3 : zmod 2) = 1, from rfl],
have h12 : 1 ≤ 3 ^ n, from by rw ← nat.pow_eq_pow; exact one_le_pow_of_one_le dec_trivial _,
(@zmod.eq_iff_modeq_nat 2 (3 ^ n - 1) 0).1 $ by rw [nat.cast_sub]; simpa
theorem test_ind' (n : nat) : (3^n -1) % 2 = 0 :=
nat.rec_on n rfl
(λ n ih,
let ⟨a, ha⟩ := (nat.dvd_iff_mod_eq_zero _ _).2 ih in
_)
#exit
import data.equiv.basic
#print environment.mk_std
#print acc
universe u
variables {α : Type u} (r : α → α → Prop)
inductive acc2 : α → Type u
| intro (x : α) (h : ∀ y, r y x → acc2 y) : acc2 x
def acc_of_acc2 (a : α) : acc2 r a → acc r a :=
λ h, begin
induction h,
refine acc.intro _ (λ _ _, _),
apply h_ih,
assumption
end
def acc2_of_acc (a : α) : acc r a → acc2 r a :=
λ h, begin
induction h,
refine acc2.intro _ (λ _ _, _),
apply h_ih,
assumption
end
set_option pp.proofs true
def acc2_equiv_acc (a : α) : acc2 r a ≃ acc r a :=
{ to_fun := acc_of_acc2 _ _,
inv_fun := acc2_of_acc _ _,
left_inv := λ h, begin
induction acc_of_acc2 _ _ h,
dsimp [acc2_of_acc] at *,
induction h_1,
simp,
simp [ih] at *, end,
right_inv := λ _, rfl
end }
#print acc2.rec
#exit
open tactic
run_cmd
do let e := environment.mk_std 0,
tactic.trace (repr (environment.is_inductive e `nat))
run_cmd
do let e := environment.mk_std 0,
let t := e.fold 0 (λ _, nat.succ) in
trace (repr t)
run_cmd
do e ← tactic.get_env,
tactic.trace (repr (environment.is_inductive e `nat))
#print environment
#print nat
import init.data.nat
#eval 1 + 1
#exit
import data.nat
import algebra.ordered_group
#print nat
open tactic expr declaration lean reducibility_hints
#print unify
def n_id : ℕ → ℕ
| 0 := 0
| (k+1) := k+1
set_option pp.all true
#print n_id -- n_id._main
#print declaration
def reducibility_hints.to_string : Π (h : reducibility_hints), string
| opaque := "opaque"
| abbrev := "abbrev"
| (regular n b) := "regular " ++ repr n ++ " " ++ repr b
meta def get_reducibility_hints : Π (d : declaration), string
| (defn _ _ _ _ h _) := h.to_string
| _ := "none"
def n_id2 := n_id._main
example : n_id = n_id2 := rfl -- succeeds
example : n_id = λ n, n_id n := rfl -- fails
run_cmd tactic.add_decl $ declaration.defn `n_id3 [] `(ℕ → ℕ) `(n_id._main) (regular 5 ff) tt
example : n_id = λ n, n_id3 n := rfl
#eval do t ← get_decl `n_id2, trace $ get_reducibility_hints t
example : n_id = λ n, n_id n := by {dsimp, refl} -- succeeds
-- proof term:
-- @id.{0} (@eq.{1} (nat → nat) n_id (λ (n : nat), n_id n)) (@eq.refl.{1} (nat → nat) n_id)
example : n_id = λ n, n_id n := -- fails
@id.{0} (@eq.{1} (nat → nat) n_id (λ (n : nat), n_id n)) (@eq.refl.{1} (nat → nat) n_id)
example : n_id2 = λ n, n_id2 n := rfl -- succeeds
example : n_id = λ n, n_id2 n := rfl -- succeeds
def nat2 := nat
instance : has_one nat2 := ⟨(0 : ℕ)⟩
example : (0 : ℕ) = (1 : nat2) := rfl
run_cmd do
let trace_unify (e1 e2 : expr) : tactic unit := (do
trace $ "try to unify " ++ to_string e1 ++ " with " ++ to_string e2,
unify e1 e2 transparency.all tt,
trace $ "unify successful between " ++ to_string e1 ++ " with " ++ to_string e2),
let c1 : expr tt := const `nat.pred [],
let c2 : expr tt := const `nat.pred._main [],
trace_unify c1 c2, -- success
trace "",
let eta_nat t := lam `n binder_info.default (const `nat []) $ mk_app t [var 0],
-- trace_unify (eta_nat c1) (eta_nat c2), -- failure!
trace_unify `(@has_one.one nat2 _) `(@has_zero.zero ℕ _)
run_cmd tactic.add_decl $ declaration.thm `blah []
`(@has_one.one nat2 _ = (0 : ℕ)) (pure `(eq.refl (0 : ℕ)))
#print unify
run_cmd tactic.add_decl $ declaration.thm `prod.fst_def []
`(∀ α β : Type, ∀ x : α × β, x.fst = prod.rec (λ a b, a) x)
(pure `(λ α β : Type, λ x : α × β, eq.refl x.fst))
#print blah
attribute [_refl_lemma] prod.fst_def
#print prod.fst_def
#print nat.pred
#print nat.pred._main
#print nat.pred.equations._eqn_1
def f : ℕ → ℕ := nat.pred._main
def g : ℕ → ℕ := f
local attribute [reducible] nat.pred
run_cmd tactic.add_decl $ declaration.thm `nat.pred_eq_pred_main []
`((λ n, nat.pred n) = λ n, nat.pred._main n) (pure `(@rfl _ nat.pred))
example : (λ n, nat.pred n) = (λ n, nat.pred._main n) := eq.refl nat.pred
#exit
import algebra.ordered_ring
#print nonneg_of_mul_nonneg_left
#print nonneg_of_mul_nonneg_right
#print nonpos_of_mul_nonpos_left
#print nonpos_of_mul_nonpos_right
#print pos_of_mul_pos_left
#print pos_of_mul_pos_right
#print neg_of_mul_neg_left
#print neg_of_mul_neg_right
#print declaration
#eval do d ← tactic.get_decl `nat.rec, tactic.trace d.type.to_raw_fmt.to_string, return ()
variables {α : Type*} [linear_ordered_semiring α] {a b c : α}
#print mul_pos_of_neg_of_neg
lemma neg_of_mul_pos_left (h : 0 < a * b) (hb : b ≤ 0) : a < 0 :=
lt_of_not_ge (λ ha, absurd h (not_lt_of_ge (mul_nonpos_of_nonneg_of_nonpos ha hb)))
lemma neg_of_mul_pos_right (h : 0 < a * b) (ha : a ≤ 0) : b < 0 :=
lt_of_not_ge (λ hb, absurd h (not_lt_of_ge (mul_nonpos_of_nonpos_of_nonneg ha hb)))
lemma pos_of_mul_neg_left (h : a * b < 0) (hb : 0 ≤ b) : 0 < a :=
lt_of_not_ge (λ ha, absurd h (not_lt_of_ge (mul_nonneg_of_nonpos_of_nonpos _ _)))
lemma nonneg_of_mul_nonpos_left (h : a * b ≤ 0) (hb : b < 0) : 0 ≤ a :=
le_of_not_gt (λ ha, absurd h (not_le_of_gt (mul_pos_of_neg_of_neg _ _)))
#exit
import data.nat.basic
local attribute [instance] classical.dec
lemma Q6 (a b : ℕ) (hab : (a * b + 1) ∣ a ^ 2 + b ^ 2) :
¬ ∀ k : ℕ, k^2 * (a * b + 1) ≠ a ^ 2 + b ^ 2:=
λ hk,
have h : ∃ a b, (∀ k : ℕ, k^2 * (a * b + 1) ≠ a ^ 2 + b ^ 2) ∧ (a * b + 1) ∣ a ^ 2 + b ^ 2,
from ⟨a, b, hk, hab⟩,
let i := nat.find h in
let ⟨j, hj⟩ := nat.find_spec h in
let ⟨n, hn⟩ := hj.2 in
let i' := n * j - i in
have hi' : i' < i, from sorry,
nat.find_min h hi' ⟨(j^2 - n) / i, begin
end⟩
#exit
import data.rat.basic
@[simp] lemma int.square_zero {n : ℤ} : n^2 = 0 ↔ n = 0 :=
begin
rw pow_two,
split,
{ contrapose!, intro h,
rcases lt_trichotomy n 0 with H|rfl|H,
{ apply ne_of_gt, exact mul_pos_of_neg_of_neg H H },
{ contradiction },
{ apply ne_of_gt, exact mul_pos H H } },
{ rintro rfl, simp },
end
lemma int.square_pos {n : ℤ} : n^2 > 0 ↔ n ≠ 0 :=
begin
rw ←not_iff_not, push_neg,
split,
{ rw ←int.square_zero, intro h, apply le_antisymm h, exact pow_two_nonneg n },
{ rintro rfl, simp [pow_two] }
end
variables {a b : ℤ} (h : a*b + 1 ∣ a^2 + b^2)
include h
lemma nz : a*b + 1 ≠ 0 :=
begin
cases h with c h,
contrapose! h,
simp [h],
rw [add_eq_zero_iff' (pow_two_nonneg _) (pow_two_nonneg _)],
rw [int.square_zero, int.square_zero],
rintro ⟨rfl, rfl⟩,
simpa using h,
end
lemma q6_aux (a b : ℤ) (n : ℕ) (hn : a^2 + b^2 = n * (a * b + 1)),
∃ k : ℤ, a^2 + b^2 = k^2 * (a * b + 1) :=
begin
end
lemma q6 (a b : ℤ) (h : a*b + 1 ∣ a^2 + b^2) :
∃ q : ℚ, q^2 = (a^2 + b^2)/(a*b + 1) :=
begin
cases q6_aux a b h with k hk,
use k,
rw_mod_cast hk, rw rat.mk_eq_div,
simp,
rw mul_div_cancel,
norm_cast,
simpa using nz h,
end
#exit
import data.fintype
instance psigma.fintype {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] :
fintype (Σ' a, β a) :=
fintype.of_equiv _ (equiv.psigma_equiv_sigma _).symm
instance psigma.fintype_prop_left {α : Prop} {β : α → Type*} [∀ a, fintype (β a)] [decidable α] :
fintype (Σ' a, β a) :=
if h : α then fintype.of_equiv (β h) ⟨λ x, ⟨h, x⟩, psigma.snd, λ _, rfl, λ ⟨_, _⟩, rfl⟩
else ⟨∅, λ x, h x.1⟩
instance psigma.fintype_prop_right {α : Type*} {β : α → Prop} [∀ a, decidable (β a)] [fintype α] :
fintype (Σ' a, β a) :=
fintype.of_equiv {a // β a} ⟨λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, rfl, λ ⟨x, y⟩, rfl⟩
instance psigma.fintype_prop_prop {α : Prop} {β : α → Prop} [∀ a, decidable (β a)] [decidable α] :
fintype (Σ' a, β a) :=
if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, λ ⟨_, _⟩, by simp⟩ else ⟨∅, λ ⟨x, y⟩, h ⟨x, y⟩⟩
#exit
import order.conditionally_complete_lattice
import data.real.basic
open classical set lattice
variables (Inf_one : real.Inf {(1:ℝ)} = 1)
(Inf_zero_one : real.Inf {(0:ℝ), (1:ℝ)} = 0)
include Inf_one Inf_zero_one
lemma foo {K : set ℕ} (h : K = {0}) : (⨅ w : ℕ, (⨅ H : w ∈ K, (1:ℝ))) = 0 :=
have Inf_one : real.Inf {(1 : ℝ)} = 1, from
le_antisymm (real.Inf_le _ ⟨1, by simp {contextual := tt}⟩ (by simp))
((real.le_Inf _ ⟨1, set.mem_singleton (1 : ℝ)⟩ ⟨1, by simp {contextual := tt}⟩).2
(by simp {contextual := tt})),
show real.Inf (range (λ w, real.Inf (range (λ (H : w ∈ K), (1:ℝ))))) = (0:ℝ), from
have h_range : range (λ w, real.Inf (range (λ (H : w ∈ K), (1:ℝ)))) = {(0:ℝ), (1:ℝ)},
begin
ext, rw mem_range, split,
rintros ⟨n, rfl⟩,
by_cases h₂ : n = (0:ℕ),
have : n ∈ K, finish,
have : range (λ (H : n ∈ K), (1:ℝ)) = {(1:ℝ)}, ext, finish,
rw [this, Inf_one], finish,
have : n ∉ K, finish,
have : range (λ (H : n ∈ K), (1:ℝ)) = (∅:set ℝ), ext, finish,
rw this, show lattice.Inf ∅ ∈ {(0:ℝ), (1:ℝ)}, rw real.Inf_empty, finish,
simp only [mem_singleton_iff, mem_insert_iff, set.insert_of_has_insert],
intro h, cases h with h h,
use 0,
have : range (λ (H : 0 ∈ K), (1:ℝ)) = {1}, ext, finish,
rw [this, Inf_one], finish,
use 1,
have : range (λ (H : 1 ∈ K), (1:ℝ)) = ∅, ext, finish,
rw this, show lattice.Inf ∅ = x, rw real.Inf_empty, finish
end,
begin
rw h_range, exact Inf_zero_one
end
lemma foo' {K : set ℕ} (h : K = {0}) : (⨅ w ∈ K, (1:ℝ)) = 1 :=
show lattice.Inf (range (λ w, lattice.Inf (range (λ (H : w ∈ K), (1:ℝ))))) = (1:ℝ),
from
have ∀ w : ℕ, (range (λ (H : w ∈ K), (1:ℝ)))
have (range (λ w, lattice.Inf (range (λ (H : w ∈ K), (1:ℝ))))) = {(1 : ℝ)},
from begin simp [h, set.ext_iff], end,
begin
end
#exit
import ring_theory.noetherian ring_theory.principal_ideal_domain
example {K : Type*} [discrete_field K] : is_noetherian_ring K := by apply_instance --works
example {K : Type*} [discrete_field K] : is_noetherian K K := by apply_instance
#exit
import algebra.ordered_Ring
lemma int.succ_ne_self (x : ℤ) : x + 1 ≠ x :=
(ne_of_lt (lt_add_one x)).symm
#exit
import algebra.ordered_ring algebra.group_power tactic.ring
variables {R : Type*} [discrete_linear_ordered_field R]
lemma discriminant_le_zero {a b c : R} (h : ∀ x : R, 0 ≤ a*x*x + b*x + c) :
b*b - 4*a*c ≤ 0 :=
have complete_square : ∀ x, (a * x * x + b * x + c) * 4 * a =
(2 * a * x + b) ^ 2 - (b * b - 4 * a * c) :=
λ x, by ring,
begin
rw [sub_nonpos],
have := h 0,
simp at this,
end
#exit
set_option old_structure_cmd true
class has_coe_to_fun' (Γ dom cod : Type) :=
( to_fun : Γ → dom → cod )
instance has_coe_to_fun'.has_coe_to_fun (Γ α β : Type) [has_coe_to_fun' Γ α β] :
has_coe_to_fun Γ := ⟨_, @has_coe_to_fun'.to_fun _ α β _⟩
structure add_group_hom (α β : Type) [add_group α] [add_group β] :=
( to_fun : α → β )
( map_add : ∀ (a b), to_fun (a + b) = to_fun a + to_fun b )
instance add_group_hom.coe_to_fun (α β : Type) [add_group α] [add_group β] :
has_coe_to_fun' (add_group_hom α β) α β := ⟨add_group_hom.to_fun⟩
structure ring_hom (α β : Type) [ring α] [ring β] extends add_group_hom α β :=
( map_mul : ∀ (a b), to_fun (a * b) = to_fun a * to_fun b )
( map_one : to_fun 1 = 1 )
instance ring_hom.coe_to_fun (α β : Type*) [ring α] [ring β] :
has_coe_to_fun' (ring_hom α β) α β := ⟨ring_hom.to_fun⟩
class has_map_add (Γ α β : Type) [has_coe_to_fun' Γ α β] [add_group α]
[add_group β] :=
( map_add : ∀ (f : Γ) (a b : α), f (a + b) = f a + f b )
instance add_group_hom.has_map_add (α β : Type) [add_group α] [add_group β] :
has_map_add (add_group_hom α β) α β :=
⟨add_group_hom.map_add⟩
instance ring_hom.has_map_add (α β : Type) [ring α] [ring β] : has_map_add (ring_hom α β) α β :=
⟨ring_hom.map_add⟩
attribute [simp] has_map_add.map_add
example (f : ring_hom ℤ ℤ) (a b : ℤ) : f a + f b = f (a + b) :=
begin
rw has_map_add.map_add ℤ f,
end
#exit
import ring_theory.noetherian ring_theory.principal_ideal_domain
example {K : Type*} [discrete_field K] : is_noetherian_ring K := by apply_instance --works
example {K : Type*} [discrete_field K] : is_noetherian K K := by apply_instance --fails
def S {X Y : Type} (f : X → Y) : X → X → Prop := λ x₁ x₂, f x₁ = f x₂
example {X Y : Type} (f : X → Y) : reflexive (S f) := λ x, rfl -- works
example {X Y : Type} (f : X → Y) : reflexive (S f) := λ x, begin
refl, end -- fails!
#exit
example {R : Type*} [monoid R] {a b c : R} (hab : a * b = 1) (hca : c * a = 1) : b = c :=
by rw [← one_mul b, ← hca, mul_assoc, hab, mul_one]
#exit
import data.real.cardinality group_theory.quotient_group set_theory.ordinal
#print real.topological_space
open cardinal
instance rat_cast_is_add_group_hom : is_add_group_hom (coe : ℚ → ℝ) :=
{ to_is_add_hom := { map_add := by simp } }
instance : is_add_subgroup (set.range (coe : ℚ → ℝ)) :=
is_add_group_hom.range_add_subgroup _
lemma rat_lt_real : mk ℚ < mk ℝ :=
calc mk ℚ = mk ℕ : quotient.sound ⟨denumerable.equiv₂ _ _⟩
... = omega : mk_nat
... < 2 ^ omega.{0} : cantor _
... = mk ℝ : mk_real.symm
lemma omega_eq_set_range_coe : omega.{0} = mk (set.range (coe : ℚ → ℝ)) :=
by rw [← mk_rat]; exact quotient.sound ⟨equiv.set.range _ rat.cast_injective⟩
lemma ne_zero_of_nonempty {α : Type*} [hn : nonempty α] : mk α ≠ 0 :=
λ f, nonempty.elim hn (λ a, pempty.elim (classical.choice (quotient.exact f) a))
noncomputable lemma real_equiv_real_mod_rat : ℝ ≃ quotient_add_group.quotient
(set.range (coe : ℚ → ℝ)) :=
have ℝ ≃ quotient_add_group.quotient (set.range (coe : ℚ → ℝ)) ×
(set.range (coe : ℚ → ℝ)) := is_add_subgroup.add_group_equiv_quotient_times_subgroup _,
calc ℝ ≃ quotient_add_group.quotient (set.range (coe : ℚ → ℝ)) ×
(set.range (coe : ℚ → ℝ)) : is_add_subgroup.add_group_equiv_quotient_times_subgroup _
... ≃ quotient_add_group.quotient (set.range (coe : ℚ → ℝ)) : classical.choice $
quotient.exact $ show mk _ * mk _ = mk _,
begin
have hR : cardinal.mk _ = cardinal.mk _ * cardinal.mk _ := quotient.sound ⟨this⟩,
have hQ : cardinal.mk ℚ = cardinal.mk (set.range (coe : ℚ → ℝ)),
from quotient.sound ⟨equiv.set.range _ (λ _, by simp)⟩,
have : cardinal.mk (set.range (coe : ℚ → ℝ)) <
cardinal.mk (quotient_add_group.quotient (set.range (coe : ℚ → ℝ))) :=
begin
refine lt_of_not_ge _,
assume h,
rw [mul_comm, mul_eq_max_of_omega_le_left (le_of_eq omega_eq_set_range_coe)
(@ne_zero_of_nonempty _ ⟨(0 : quotient_add_group.quotient _)⟩),
max_eq_left h, ← hQ] at hR,
exact absurd rat_lt_real (by rw hR; exact lt_irrefl _), apply_instance
end,
rw [mul_comm, mul_eq_max_of_omega_le_left (le_of_eq omega_eq_set_range_coe),
max_eq_right (le_of_lt this)],
exact (@ne_zero_of_nonempty _ ⟨(0 : quotient_add_group.quotient _)⟩)
end
noncomputable def f : ℝ → ℝ := real_equiv_real_mod_rat.symm ∘ quotient_add_group.mk
lemma thingy_aux (s : set ℝ) (hs : is_open s) (hsn : s ≠ ∅)
(x : quotient_add_group.quotient (set.range (coe : ℚ → ℝ))) :
∃ y ∈ s, quotient_add_group.mk y = x :=
let ⟨a, ha⟩ := set.exists_mem_of_ne_empty hsn in
let ⟨b, hb⟩ := @quotient.exists_rep _ (id _) x in
let ⟨q, hq⟩ := set.exists_mem_of_ne_empty (mem_closure_iff.1
(dense_inducing.dense dense_embedding_of_rat.to_dense_inducing a) s hs ha) in
let ⟨r, hr⟩ := set.exists_mem_of_ne_empty (mem_closure_iff.1
(dense_inducing.dense dense_embedding_of_rat.to_dense_inducing (-b))
((λ x, b + (x + q)) ⁻¹' s)
(continuous_add continuous_const
(continuous_add continuous_id continuous_const) s hs)
(by rw [set.mem_preimage, add_neg_cancel_left]; exact hq.1)) in
⟨_, hr.1, begin
rw [← hb],
refine quotient.sound' _,
show _ ∈ set.range (coe : ℚ → ℝ),
simp [-set.mem_range],
exact is_add_submonoid.add_mem (is_add_subgroup.neg_mem hq.2)
(is_add_subgroup.neg_mem hr.2)
end⟩
lemma thingy (s : set ℝ) (hs : is_open s) (hsn : s ≠ ∅) (x : ℝ) : ∃ y ∈ s, f y = x :=
let ⟨y, hy⟩ := thingy_aux s hs hsn (real_equiv_real_mod_rat x) in
⟨y, hy.fst, by rw [f, function.comp_app, hy.snd, equiv.symm_apply_apply]⟩
#exit
import data.fintype.basic data.zmod.basic
open finset equiv
example : ∀ {n : ℕ} (g : fin (n + 1) → fin n),
∃ (f₁ f₂ : perm (fin (n + 1))), ∀ x, (f₁ x : ℕ) + f₂ x ≡ x [MOD (n+1)]
| 0 g := ⟨1, 1, by simp [nat.modeq]⟩
| (n+1) g := begin
end
#exit
import data.quot logic.basic
meta def choice {α : Sort*} {β : α → Sort*} : (Π a, trunc (β a)) → trunc (Π a, β a) :=
λ f, trunc.mk (λ a, quot.unquot (f a))
def decidable_true (choice : Π {α : Sort*} {β : α → Sort*}
(f : Π a, trunc (β a)), trunc (Π a, β a)) : decidable true :=
trunc.rec_on_subsingleton (choice (id : trunc bool → trunc bool))
(λ f, decidable_of_iff (f (trunc.mk tt) = f (trunc.mk ff))
(by rw [subsingleton.elim (trunc.mk tt) (trunc.mk ff)]; exact eq_self_iff_true _))
#eval decidable_true @choice --ff
def bool_dec_eq_of_choice (choice : Π {α : Sort*} {β : α → Sort*} (f : Π a, trunc (β a)),
trunc (Π a, β a)) : decidable_eq bool :=
trunc.rec_on_subsingleton (choice (id : trunc bool → trunc bool))
(λ f a b, decidable_of_iff (f (trunc.mk a) = f (trunc.mk b))
⟨_, _⟩)
def choice_computes {α : Sort*} {β : α → Sort*} (f : Π a, trunc (β a)) :
∀ a : α, trunc.lift_on (f a) (λ b, trunc.lift_on (choice f) (λ f, f a = b)
sorry) sorry
example : false :=
begin
have := choice_computes (id : trunc bool → trunc bool) (trunc.mk tt),
dsimp [trunc.lift_on, trunc.lift, trunc.mk] at this,
end
section
parameter (p : Prop)
def r : setoid bool :=
{ r := λ x y : bool, p ∨ x = y,
iseqv := ⟨λ _, or.inr rfl,
λ x y hxy, hxy.elim or.inl (or.inr ∘ eq.symm),
λ x y z hxy hyz, hxy.elim or.inl
(λ hxy, hyz.elim or.inl (λ hyz, or.inr $ by rw [hxy, hyz]))⟩ }
def suspension : Type := quotient r
noncomputable lemma g : trunc (Π s : suspension, {b : bool // @quotient.mk _ r b = s}) :=
choice (λ s, @quotient.rec_on_subsingleton _ (id _)
(λ t, t = s → trunc {b : bool // @quotient.mk _ r b = s}) _ s
(λ b hb, trunc.mk ⟨b, hb⟩) rfl)
noncomputable lemma prop_decidable : decidable p :=
trunc.rec_on_subsingleton g
(λ g', let g := λ s, (g' s).val in
have quot_mk_g : ∀ s, quotient.mk' (g s) = s, from λ s, (g' s).2,
have g_injective : function.injective g, from
function.injective_of_has_left_inverse ⟨_, quot_mk_g⟩,
have p_iff_g_tt_eq_g_ff : p ↔ g (quotient.mk' tt) = g (quotient.mk' ff),
from ⟨λ hp, congr_arg _ (quotient.sound' (or.inl hp)),
λ h, (@quotient.exact _ (id _) _ _ (g_injective h)).elim
id
(λ h, bool.no_confusion h)⟩,
decidable_of_iff _ p_iff_g_tt_eq_g_ff.symm)
#exit
import data.finsupp order.complete_lattice algebra.ordered_group data.mv_polynomial
import algebra.order_functions
namespace multiset
variables {α : Type*} [decidable_eq α]
def to_finsupp (s : multiset α) : α →₀ ℕ :=
{ support := s.to_finset,
to_fun := λ a, s.count a,
mem_support_to_fun := λ a,
begin
rw mem_to_finset,
convert not_iff_not_of_iff (count_eq_zero.symm),
rw not_not
end }
@[simp] lemma to_finsupp_support (s : multiset α) :
s.to_finsupp.support = s.to_finset := rfl
@[simp] lemma to_finsupp_apply (s : multiset α) (a : α) :
s.to_finsupp a = s.count a := rfl
@[simp] lemma to_finsupp_zero :
to_finsupp (0 : multiset α) = 0 :=
finsupp.ext $ λ a, count_zero a
@[simp] lemma to_finsupp_add (s t : multiset α) :
to_finsupp (s + t) = to_finsupp s + to_finsupp t :=
finsupp.ext $ λ a, count_add a s t
namespace to_finsupp
instance : is_add_monoid_hom (to_finsupp : multiset α → α →₀ ℕ) :=
{ map_zero := to_finsupp_zero,
map_add := to_finsupp_add }
end to_finsupp
@[simp] lemma to_finsupp_to_multiset (s : multiset α) :
s.to_finsupp.to_multiset = s :=
ext.2 $ λ a, by rw [finsupp.count_to_multiset, to_finsupp_apply]
end multiset
namespace finsupp
variables {σ : Type*} {α : Type*} [decidable_eq σ]
instance [preorder α] [has_zero α] : preorder (σ →₀ α) :=
{ le := λ f g, ∀ s, f s ≤ g s,
le_refl := λ f s, le_refl _,
le_trans := λ f g h Hfg Hgh s, le_trans (Hfg s) (Hgh s) }
instance [partial_order α] [has_zero α] : partial_order (σ →₀ α) :=
{ le_antisymm := λ f g hfg hgf, finsupp.ext $ λ s, le_antisymm (hfg s) (hgf s),
.. finsupp.preorder }
instance [ordered_cancel_comm_monoid α] [decidable_eq α] :
add_left_cancel_semigroup (σ →₀ α) :=
{ add_left_cancel := λ a b c h, finsupp.ext $ λ s,
by { rw finsupp.ext_iff at h, exact add_left_cancel (h s) },
.. finsupp.add_monoid }
instance [ordered_cancel_comm_monoid α] [decidable_eq α] :
add_right_cancel_semigroup (σ →₀ α) :=
{ add_right_cancel := λ a b c h, finsupp.ext $ λ s,
by { rw finsupp.ext_iff at h, exact add_right_cancel (h s) },
.. finsupp.add_monoid }
instance [ordered_cancel_comm_monoid α] [decidable_eq α] :
ordered_cancel_comm_monoid (σ →₀ α) :=
{ add_le_add_left := λ a b h c s, add_le_add_left (h s) (c s),
le_of_add_le_add_left := λ a b c h s, le_of_add_le_add_left (h s),
.. finsupp.add_comm_monoid, .. finsupp.partial_order,
.. finsupp.add_left_cancel_semigroup, .. finsupp.add_right_cancel_semigroup }
attribute [simp] to_multiset_zero to_multiset_add
@[simp] lemma to_multiset_to_finsupp (f : σ →₀ ℕ) :
f.to_multiset.to_finsupp = f :=
ext $ λ s, by rw [multiset.to_finsupp_apply, count_to_multiset]
def diagonal (f : σ →₀ ℕ) : finset ((σ →₀ ℕ) × (σ →₀ ℕ)) :=
((multiset.diagonal f.to_multiset).map (prod.map multiset.to_finsupp multiset.to_finsupp)).to_finset
lemma mem_diagonal {f : σ →₀ ℕ} {p : (σ →₀ ℕ) × (σ →₀ ℕ)} :
p ∈ diagonal f ↔ p.1 + p.2 = f :=
begin
erw [multiset.mem_to_finset, multiset.mem_map],
split,
{ rintros ⟨⟨a, b⟩, h, rfl⟩,
rw multiset.mem_diagonal at h,
simpa using congr_arg multiset.to_finsupp h },
{ intro h,
refine ⟨⟨p.1.to_multiset, p.2.to_multiset⟩, _, _⟩,
{ simpa using congr_arg to_multiset h },
{ rw [prod.map, to_multiset_to_finsupp, to_multiset_to_finsupp, prod.mk.eta] } }
end
lemma swap_mem_diagonal {n : σ →₀ ℕ} {f} (hf : f ∈ diagonal n) : f.swap ∈ diagonal n :=
by simpa [mem_diagonal, add_comm] using hf
@[simp] lemma diagonal_zero : diagonal (0 : σ →₀ ℕ) = {(0,0)} := rfl
lemma to_multiset_strict_mono : strict_mono (@to_multiset σ _) :=
λ m n h,
begin
rw lt_iff_le_and_ne at h ⊢, cases h with h₁ h₂,
split,
{ rw multiset.le_iff_count, intro s, rw [count_to_multiset, count_to_multiset], exact h₁ s },
{ intro H, apply h₂, replace H := congr_arg multiset.to_finsupp H, simpa using H }
end
lemma sum_lt_of_lt (m n : σ →₀ ℕ) (h : m < n) :
m.sum (λ _, id) < n.sum (λ _, id) :=
begin
rw [← card_to_multiset, ← card_to_multiset],
apply multiset.card_lt_of_lt,
exact to_multiset_strict_mono _ _ h
end
variable (σ)
def lt_wf : well_founded (@has_lt.lt (σ →₀ ℕ) _) :=
subrelation.wf (sum_lt_of_lt) $ inv_image.wf _ nat.lt_wf
-- instance : has_well_founded (σ →₀ ℕ) :=
-- { r := (<),
-- wf := lt_wf σ }
end finsupp
/-- Multivariate power series, where `σ` is the index set of the variables
and `α` is the coefficient ring.-/
def mv_power_series (σ : Type*) (α : Type*) := (σ →₀ ℕ) → α
namespace mv_power_series
open finsupp
variables {σ : Type*} {α : Type*} [decidable_eq σ]
def coeff (n : σ →₀ ℕ) (φ : mv_power_series σ α) := φ n
@[extensionality] lemma ext {φ ψ : mv_power_series σ α} (h : ∀ n, coeff n φ = coeff n ψ) : φ = ψ :=
funext h
lemma ext_iff {φ ψ : mv_power_series σ α} : φ = ψ ↔ (∀ n, coeff n φ = coeff n ψ) :=
⟨λ h n, congr_arg (coeff n) h, ext⟩
variables [comm_semiring α]
def monomial (n : σ →₀ ℕ) (a : α) : mv_power_series σ α := λ m, if m = n then a else 0
lemma coeff_monomial (m n : σ →₀ ℕ) (a : α) :
coeff m (monomial n a) = if m = n then a else 0 := rfl
@[simp] lemma coeff_monomial' (n : σ →₀ ℕ) (a : α) :
coeff n (monomial n a) = a := if_pos rfl
def C (a : α) : mv_power_series σ α := monomial 0 a
lemma coeff_C (n : σ →₀ ℕ) (a : α) :
coeff n (C a : mv_power_series σ α) = if n = 0 then a else 0 := rfl
@[simp] lemma coeff_C_zero (a : α) : coeff 0 (C a : mv_power_series σ α) = a :=
coeff_monomial' 0 a
@[simp] lemma monomial_zero (a : α) : (monomial 0 a : mv_power_series σ α) = C a := rfl
def X (s : σ) : mv_power_series σ α := monomial (single s 1) 1
lemma coeff_X (n : σ →₀ ℕ) (s : σ) :
coeff n (X s : mv_power_series σ α) = if n = (single s 1) then 1 else 0 := rfl
lemma coeff_X' (s t : σ) :
coeff (single t 1) (X s : mv_power_series σ α) = if t = s then 1 else 0 :=
if h : t = s then by simp [h, coeff_X] else
begin
rw [coeff_X, if_neg h],
split_ifs with H,
{ have := @finsupp.single_apply σ ℕ _ _ _ t s 1,
rw [if_neg h, H, finsupp.single_apply, if_pos rfl] at this,
exfalso, exact one_ne_zero this, },
{ refl }
end
@[simp] lemma coeff_X'' (s : σ) :
coeff (single s 1) (X s : mv_power_series σ α) = 1 :=
by rw [coeff_X', if_pos rfl]
section ring
variables (σ) (α) (n : σ →₀ ℕ) (φ ψ : mv_power_series σ α)
def zero : mv_power_series σ α := λ n, 0
instance : has_zero (mv_power_series σ α) := ⟨zero σ α⟩
@[simp] lemma coeff_zero : coeff n (0 : mv_power_series σ α) = 0 := rfl
@[simp] lemma C_zero : (C 0 : mv_power_series σ α) = 0 :=
ext $ λ n, if h : n = 0 then by simp [h] else by rw [coeff_C, if_neg h, coeff_zero]
def one : mv_power_series σ α := C 1
instance : has_one (mv_power_series σ α) := ⟨one σ α⟩
@[simp] lemma coeff_one :
coeff n (1 : mv_power_series σ α) = if n = 0 then 1 else 0 := rfl
@[simp] lemma coeff_one_zero : coeff 0 (1 : mv_power_series σ α) = 1 :=
coeff_C_zero 1
@[simp] lemma C_one : (C 1 : mv_power_series σ α) = 1 := rfl
def add (φ ψ : mv_power_series σ α) : mv_power_series σ α :=
λ n, coeff n φ + coeff n ψ
instance : has_add (mv_power_series σ α) := ⟨add σ α⟩
variables {σ α}
@[simp] lemma coeff_add : coeff n (φ + ψ) = coeff n φ + coeff n ψ := rfl
@[simp] lemma zero_add : (0 : mv_power_series σ α) + φ = φ := ext $ λ n, zero_add _
@[simp] lemma add_zero : φ + 0 = φ := ext $ λ n, add_zero _
lemma add_comm : φ + ψ = ψ + φ := ext $ λ n, add_comm _ _
lemma add_assoc (φ₁ φ₂ φ₃ : mv_power_series σ α) :
(φ₁ + φ₂) + φ₃ = φ₁ + (φ₂ + φ₃) :=
ext $ λ n, by simp
@[simp] lemma monomial_add (n : σ →₀ ℕ) (a b : α) :
(monomial n (a + b) : mv_power_series σ α) = monomial n a + monomial n b :=
ext $ λ m, if h : m = n then by simp [h] else by simp [coeff_monomial, if_neg h]
@[simp] lemma C_add (a b : α) : (C (a + b) : mv_power_series σ α) = C a + C b :=
monomial_add 0 a b
variables (σ α)
def mul (φ ψ : mv_power_series σ α) : mv_power_series σ α :=
λ n, (finsupp.diagonal n).sum (λ p, coeff p.1 φ * coeff p.2 ψ)
instance : has_mul (mv_power_series σ α) := ⟨mul σ α⟩
variables {σ α}
lemma coeff_mul :
coeff n (φ * ψ) = (finsupp.diagonal n).sum (λ p, coeff p.1 φ * coeff p.2 ψ) := rfl
@[simp] lemma C_mul (a b : α) : (C (a * b) : mv_power_series σ α) = C a * C b :=
ext $ λ n,
begin
rw [coeff_C, coeff_mul],
split_ifs,
{ subst n, erw [diagonal_zero, finset.sum_singleton, coeff_C_zero, coeff_C_zero] },
{ rw finset.sum_eq_zero,
rintros ⟨i,j⟩ hij,
rw mem_diagonal at hij, rw [coeff_C, coeff_C],
split_ifs; try {simp * at *; done} }
end
@[simp] lemma zero_mul : (0 : mv_power_series σ α) * φ = 0 :=
ext $ λ n, by simp [coeff_mul]
@[simp] lemma mul_zero : φ * 0 = 0 :=
ext $ λ n, by simp [coeff_mul]
lemma mul_comm : φ * ψ = ψ * φ :=
ext $ λ n, finset.sum_bij (λ p hp, p.swap)
(λ p hp, swap_mem_diagonal hp)
(λ p hp, mul_comm _ _)
(λ p q hp hq H, by simpa using congr_arg prod.swap H)
(λ p hp, ⟨p.swap, swap_mem_diagonal hp, p.swap_swap.symm⟩)
@[simp] lemma one_mul : (1 : mv_power_series σ α) * φ = φ :=
ext $ λ n,
begin
have H : ((0 : σ →₀ ℕ), n) ∈ (diagonal n) := by simp [mem_diagonal],
rw [coeff_mul, ← finset.insert_erase H, finset.sum_insert (finset.not_mem_erase _ _),
coeff_one_zero, one_mul, finset.sum_eq_zero, _root_.add_zero],
rintros ⟨i,j⟩ hij,
rw [finset.mem_erase, mem_diagonal] at hij,
rw [coeff_one, if_neg, _root_.zero_mul],
intro H, apply hij.1, simp * at *
end
@[simp] lemma mul_one : φ * 1 = φ :=
by rw [mul_comm, one_mul]
lemma mul_add (φ₁ φ₂ φ₃ : mv_power_series σ α) :
φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ :=
ext $ λ n, by simp only [coeff_mul, coeff_add, mul_add, finset.sum_add_distrib]
lemma add_mul (φ₁ φ₂ φ₃ : mv_power_series σ α) :
(φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ :=
ext $ λ n, by simp only [coeff_mul, coeff_add, add_mul, finset.sum_add_distrib]
lemma mul_assoc (φ₁ φ₂ φ₃ : mv_power_series σ α) :
(φ₁ * φ₂) * φ₃ = φ₁ * (φ₂ * φ₃) :=
ext $ λ n,
begin
simp only [coeff_mul],
have := @finset.sum_sigma ((σ →₀ ℕ) × (σ →₀ ℕ)) α _ _ (diagonal n)
(λ p, diagonal (p.1)) (λ x, coeff x.2.1 φ₁ * coeff x.2.2 φ₂ * coeff x.1.2 φ₃),
convert this.symm using 1; clear this,
{ apply finset.sum_congr rfl,
intros p hp, exact finset.sum_mul },
have := @finset.sum_sigma ((σ →₀ ℕ) × (σ →₀ ℕ)) α _ _ (diagonal n)
(λ p, diagonal (p.2)) (λ x, coeff x.1.1 φ₁ * (coeff x.2.1 φ₂ * coeff x.2.2 φ₃)),
convert this.symm using 1; clear this,
{ apply finset.sum_congr rfl, intros p hp, rw finset.mul_sum },
apply finset.sum_bij,
swap 5,
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, exact ⟨(k, l+j), (l, j)⟩ },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, simp only [finset.mem_sigma, mem_diagonal] at H ⊢, finish },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, rw mul_assoc },
{ rintros ⟨⟨a,b⟩, ⟨c,d⟩⟩ ⟨⟨i,j⟩, ⟨k,l⟩⟩ H₁ H₂,
simp only [finset.mem_sigma, mem_diagonal,
and_imp, prod.mk.inj_iff, add_comm, heq_iff_eq] at H₁ H₂ ⊢,
finish },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, refine ⟨⟨(i+k, l), (i, k)⟩, _, _⟩;
{ simp only [finset.mem_sigma, mem_diagonal] at H ⊢, finish } }
end
instance : comm_semiring (mv_power_series σ α) :=
{ mul_one := mul_one,
one_mul := one_mul,
add_assoc := add_assoc,
zero_add := zero_add,
add_zero := add_zero,
add_comm := add_comm,
mul_assoc := mul_assoc,
mul_zero := mul_zero,
zero_mul := zero_mul,
mul_comm := mul_comm,
left_distrib := mul_add,
right_distrib := add_mul,
.. mv_power_series.has_zero σ α,
.. mv_power_series.has_one σ α,
.. mv_power_series.has_add σ α,
.. mv_power_series.has_mul σ α }
instance C.is_semiring_hom : is_semiring_hom (C : α → mv_power_series σ α) :=
{ map_zero := C_zero _ _,
map_one := C_one _ _,
map_add := C_add,
map_mul := C_mul }
instance coeff.is_add_monoid_hom : is_add_monoid_hom (coeff n : mv_power_series σ α → α) :=
{ map_zero := coeff_zero _ _ _,
map_add := coeff_add n }
instance : semimodule α (mv_power_series σ α) :=
{ smul := λ a φ, C a * φ,
one_smul := λ φ, one_mul _,
mul_smul := λ a b φ, by simp only [C_mul, mul_assoc],
smul_add := λ a φ ψ, mul_add _ _ _,
smul_zero := λ a, mul_zero _,
add_smul := λ a b φ, by simp only [C_add, add_mul],
zero_smul := λ φ, by simp only [zero_mul, C_zero] }
end ring
-- TODO(jmc): once adic topology lands, show that this is complete
end mv_power_series
namespace mv_power_series
variables {σ : Type*} {α : Type*} [decidable_eq σ] [comm_ring α]
protected def neg (φ : mv_power_series σ α) : mv_power_series σ α := λ n, - coeff n φ
instance : has_neg (mv_power_series σ α) := ⟨mv_power_series.neg⟩
@[simp] lemma coeff_neg (φ : mv_power_series σ α) (n) : coeff n (- φ) = - coeff n φ := rfl
lemma add_left_neg (φ : mv_power_series σ α) : (-φ) + φ = 0 :=
ext $ λ n, by rw [coeff_add, coeff_zero, coeff_neg, add_left_neg]
instance : comm_ring (mv_power_series σ α) :=
{ add_left_neg := add_left_neg,
.. mv_power_series.has_neg, .. mv_power_series.comm_semiring }
instance C.is_ring_hom : is_ring_hom (C : α → mv_power_series σ α) :=
{ map_one := C_one _ _,
map_add := C_add,
map_mul := C_mul }
instance coeff.is_add_group_hom (n : σ →₀ ℕ) :
is_add_group_hom (coeff n : mv_power_series σ α → α) :=
{ map_add := coeff_add n }
instance : module α (mv_power_series σ α) :=
{ ..mv_power_series.semimodule }
local attribute [instance, priority 0] classical.dec
noncomputable def inv_of_unit (φ : mv_power_series σ α) (u : units α) (h : coeff 0 φ = u) : mv_power_series σ α
| n := if n = 0 then ↑u⁻¹ else
- ↑u⁻¹ * finset.sum (n.diagonal) (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if h : x.1 < n then inv_of_unit x.1 * coeff x.2 φ else 0)
using_well_founded { rel_tac := λ _ _, `[exact ⟨_, finsupp.lt_wf σ⟩],
dec_tac := tactic.assumption }
end mv_power_series
#exit
import algebra.associated data.finsupp
variables {α : Type*} {σ : Type*} [ring α]
@[reducible] def mv_power_series (σ : Type*) (α : Type*) := (σ →₀ ℕ) → α
instance : has_zero $ mv_power_series σ α := ⟨λ _, 0⟩
def coeff (x : (σ →₀ ℕ)) (a : (σ →₀ ℕ) → α):= a x
local attribute [instance] classical.dec
def inv_of_unit (φ : mv_power_series σ α) (u : units α) (h : coeff 0 φ = u) : mv_power_series σ α
| n := if n = 0 then ↑u⁻¹ else
- ↑u⁻¹ * finset.sum (n.diagonal) (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if h : x.1 < n then inv_of_unit x.1 * coeff x.2 φ else 0)
using_well_founded { rel_tac := λ _ _, `[exact ⟨_, finsupp.lt_wf σ⟩] }
#exit
import data.finsupp
variables {σ : Type}
instance : preorder (σ →₀ ℕ) :=
{ le := λ f g, ∀ s, f s ≤ g s,
le_refl := λ f s, le_refl _,
le_trans := λ f g h Hfg Hgh s, le_trans (Hfg s) (Hgh s) }
#print finset.sum_le
lemma sum_lt_sum_of_lt (f g : σ →₀ ℕ) : f < g → f.sum (λ _, id) < g.sum (λ _, id) :=
begin
assume hfg,
cases classical.not_forall.1 hfg.2 with i hi,
rw finsupp.sum,
end
#exit
import set_theory.schroeder_bernstein
universe u
structure B := (C : Type u)
lemma eq.mpr_injective {α β : Sort u} (h : α = β) :
function.injective (eq.mpr h) := λ _ _, by cases h; exact id
instance : inhabited B := ⟨⟨pempty⟩⟩
open function
example {α : Type u} (f : B.{u} ↪ α) : false :=
let g := B.C ∘ inv_fun f in
have hg : surjective g, from
surjective_comp (λ x, ⟨B.mk x, rfl⟩) (inv_fun_surjective f.2),
let X : Type u := sigma g in
let a : α := classical.some (hg (X → Prop)) in
have ha : g a = (X → Prop), from classical.some_spec (hg (set X)),
cantor_injective (show set X → X, from λ s, ⟨a, by rw ha; exact s⟩)
(λ x y h, by simp at *; exact eq.mpr_injective _ h)
#exit
import ring_theory.ideal_operations
universe u
variables {R : Type u} [comm_ring R]
def ar : lattice.complete_lattice (ideal R) := by apply_instance
#print lattice.lt
instance : ordered_comm_monoid (ideal R) :=
{ le := (≤),
add_le_add_left := λ a b hab c, lattice.sup_le_sup (le_refl _) hab,
lt_of_add_lt_add_left := λ a b c h, begin
refine not_lt
end,
--add_left_cancel := _,
..ideal.comm_semiring,
..submodule.lattice.complete_lattice
--show lattice.complete_lattice (ideal R), by apply_instance
}
#exit
import data.multiset data.finsupp
import category_theory.natural_isomorphism category_theory.types category_theory.opposites category_theory.concrete_category
universe u
open category_theory
namespace category_theory.instances
@[reducible] def DecEq := bundled decidable_eq
instance (x : DecEq) : decidable_eq x := x.str
instance DecEq_category : category DecEq :=
{ hom := λ x y, x → y,
id := λ x, id,
comp := λ x y z f g, g ∘ f }
end category_theory.instances
open category_theory.instances
@[reducible] def Multiset : DecEq.{u} ⥤ Type u :=
{ obj := λ α, multiset α,
map := λ α β, multiset.map,
map_id' := λ α, funext multiset.map_id,
map_comp' := λ α β γ f g, funext $ λ s, (multiset.map_map g f s).symm }
@[reducible] def Finsupp_nat : DecEq.{u} ⥤ Type u :=
{ obj := λ α, α →₀ ℕ,
map := λ α β, finsupp.map_domain,
map_id' := λ α, funext $ λ s, finsupp.map_domain_id,
map_comp' := λ α β γ f g, funext $ λ s, finsupp.map_domain_comp }
theorem multiset.map_repeat {α : Type u} {β : Type*} (f : α → β) (x : α) (n : ℕ) :
multiset.map f (multiset.repeat x n) = multiset.repeat (f x) n :=
nat.rec_on n rfl $ λ n ih, by rw [multiset.repeat_succ, multiset.map_cons, ih, multiset.repeat_succ]
theorem multiset.repeat_add {α : Type u} (x : α) (m n : ℕ) :
multiset.repeat x (m + n) = multiset.repeat x m + multiset.repeat x n :=
nat.rec_on n (by rw [multiset.repeat_zero, add_zero, add_zero]) $ λ n ih,
by rw [multiset.repeat_succ, nat.add_succ, multiset.repeat_succ, multiset.add_cons, ih]
-- ⟨s.to_finset, λ x, s.count x, λ x, multiset.mem_to_finset.trans $ multiset.count_pos.symm.trans $ nat.pos_iff_ne_zero⟩
-- faster but less idiomatic
def Multiset_Finsupp_nat : Multiset.{u} ≅ Finsupp_nat.{u} :=
{ hom :=
{ app := λ α s, { to_fun := λ a, s.count a,
support := s.to_finset,
mem_support_to_fun := by simp [multiset.count_eq_zero] },
naturality' := λ X Y f, begin
dsimp, simp [function.funext_iff, finsupp.ext_iff],
unfold_coes,
dsimp [finsupp.map_domain],
end },
inv :=
{ app := λ α s, s.sum multiset.repeat,
naturality' := λ α β f, funext $ λ s,
show (s.map_domain f).sum multiset.repeat = (s.sum multiset.repeat).map f,
from finsupp.induction s rfl $ λ x n s hsx hn ih, begin
rw [finsupp.map_domain_add, finsupp.sum_add_index, finsupp.map_domain_single, finsupp.sum_single_index,
finsupp.sum_add_index, finsupp.sum_single_index, multiset.map_add, multiset.map_repeat, ih],
{ refl }, { intros, refl }, { intros, rw multiset.repeat_add },
{ refl }, { intros, refl }, { intros, rw multiset.repeat_add }
end },
hom_inv_id' := nat_trans.ext $ λ α, funext $ λ s,
show (s.map $ λ x, finsupp.single x 1).sum.sum multiset.repeat = s,
from multiset.induction_on s rfl $ λ a s ih, begin
rw [multiset.map_cons, multiset.sum_cons, finsupp.sum_add_index, finsupp.sum_single_index, multiset.repeat_one, ih, multiset.cons_add, zero_add],
{ refl }, { intros, refl }, { intros, rw multiset.repeat_add }
end,
inv_hom_id' := nat_trans.ext $ λ α, funext $ λ s,
show ((s.sum multiset.repeat).map $ λ x, finsupp.single x 1).sum = s,
from finsupp.induction s rfl $ λ y n s hsy hn ih, begin
rw [finsupp.sum_add_index, finsupp.sum_single_index, multiset.map_add, multiset.sum_add, ih, multiset.map_repeat],
{ congr' 1, clear hn, induction n with n ih,
{ rw [finsupp.single_zero, multiset.repeat_zero, multiset.sum_zero] },
{ rw [multiset.repeat_succ, multiset.sum_cons, ih, ← nat.one_add, finsupp.single_add] } },
{ refl }, { intros, refl }, { intros, rw multiset.repeat_add }
end }
#exit
import data.num.basic
set_option profiler true
namespace nat
def fib : ℕ → ℕ
| 0 := 1
| 1 := 1
| (n+2) := fib n + fib (n+1)
def fib2 : ℕ → ℕ × ℕ
| 0 := (1, 0)
| (n+1) := let x := fib2 n in (x.1 + x.2, x.1)
def fib3 : ℕ → ℕ × ℕ
| 0 := (1, 0)
| (n+1) := ((fib3 n).1 + (fib3 n).2, (fib3 n).1)
def fib4 : ℕ → ℕ × ℕ
| 0 := (1, 0)
| (n+1) :=
match fib4 n with
| (x, y) := (x + y, x)
end
#eval fib3 10
#eval fib4 100000
#eval fib2 100000
end nat
namespace num
def fib : ℕ → num
| 0 := 1
| 1 := 1
| (n+2) := fib n + fib (n+1)
def fib2 : ℕ → num × num
| 0 := (1, 0)
| (n+1) := let x := fib2 n in
(x.1 + x.2, x.1)
def fib3 : ℕ → num × num
| 0 := (1, 0)
| (n+1) := ((fib3 n).1 + (fib3 n).2, (fib3 n).1)
def fib4 : ℕ → num × num
| 0 := (1, 0)
| (n+1) :=
match fib4 n with
| (x, y) := (x + y, x)
end
--#reduce fib2 30
#reduce fib2 20
#reduce fib3 20
#reduce fib4 22
end num
set_option profiler true
-- #reduce fib 40
#eval fib3 100000
#exit
import data.nat.basic
open nat
theorem even_ne_odd {n m} : 2 * n ≠ 2 * m + 1 :=
mt (congr_arg (%2)) (by rw [add_comm, add_mul_mod_self_left, mul_mod_right]; exact dec_trivial)
#print even_ne_odd
#exit
import logic.function tactic
open monad
section
inductive p : Prop
| mk : p → p
example : ¬ p := λ h, by induction h; assumption
parameters {m : Type → Type} [monad m] [is_lawful_monad m]
inductive mem : Π {α : Type}, α → m α → Prop
| pure : ∀ {α : Type} (a : α), mem a (pure a)
| join : ∀ {α : Type} (a : α) (b : m α) (c : m (m α)), mem a b → mem b c →
mem a (monad.join c)
parameters (mem2 : Π {α : Type}, α → m α → Prop)
(mem2_pure : ∀ {α : Type} (a b : α), mem2 a (pure b) ↔ a = b)
(mem2_bind : Π {α : Type} (a : α) (c : m (m α)),
mem2 a (join c) ↔ ∃ b : m α, mem2 a b ∧ mem2 b c)
example (mem2 : Π {α : Type}, α → m α → Prop)
(mem2_pure : ∀ {α : Type} {a b : α}, mem2 a (pure b) ↔ a = b)
(mem2_join : Π {α : Type} (a : α) (c : m (m α)),
mem2 a (join c) ↔ ∃ b : m α, mem2 a b ∧ mem2 b c)
{α : Type} {a : α} (b : m α) (h : mem a b) : mem2 a b :=
by induction h; simp *; tauto
end
section
parameters {m : Type → Type} [monad m] [is_lawful_monad m]
inductive mem : Π {α : Type}, α → m α → Prop
| pure : ∀ {α : Type} (a : α), mem a (pure a)
| join : ∀ {α : Type} (a : α) (b : m α) (c : m (m α)), mem a b → mem b c →
mem a (monad.join c)
parameters (mem2 : Π {α : Type}, α → m α → Prop)
(mem2_pure : ∀ {α : Type} (a b : α), mem2 a (pure b) ↔ a = b)
(mem2_bind : Π {α : Type} (a : α) (c : m (m α)),
mem2 a (join c) ↔ ∃ b : m α, mem2 a b ∧ mem2 b c)
example (mem2 : Π {α : Type}, α → m α → Prop)
(mem2_pure : ∀ {α : Type} {a b : α}, mem2 a (pure b) ↔ a = b)
(mem2_join : Π {α : Type} (a : α) (c : m (m α)),
mem2 a (join c) ↔ ∃ b : m α, mem2 a b ∧ mem2 b c)
{α : Type} {a : α} (b : m α) (h : mem a b) : mem2 a b :=
by induction h; simp *; tauto
end
#exit
import data.matrix data.equiv.algebra
def one_by_one_equiv (one R : Type*) [unique one] [ring R] : matrix one one R ≃ R :=
{ to_fun := λ M, M (default _) (default _),
inv_fun := λ x _ _, x,
left_inv := λ _, matrix.ext
(λ i j, by rw [unique.eq_default i, unique.eq_default j]),
right_inv := λ _, rfl }
lemma one_by_one_equiv.is_ring_hom (one R : Type*) [unique one] [ring R] :
is_ring_hom (one_by_one_equiv one R) :=
{ map_one := rfl,
map_add := λ _ _, rfl,
map_mul := λ _ _, by dsimp [one_by_one_equiv, matrix.mul]; simp }
def one_by_one_ring_equiv (one R : Type*) [unique one] [ring R] : matrix one one R ≃r R :=
{ hom := one_by_one_equiv.is_ring_hom one R,
..one_by_one_equiv one R }
import data.finset
#check @finset.sup
#exit
import measure_theory.giry_monad
universe u
variables {α : Type u} {β : Type u}
open nat
example {n : ℕ} : n ≤ n * n :=
begin
induction n_eq : n with m IH,
all_goals {
have : 0 ≤ n, from n.zero_le
},
{ simp },
{ sorry }
end
lemma rubbish (n m : ℕ) (h : n = m) (hm : m ≠ 1) : n = 0 ∨ n > m :=
begin
induction n,
{ left, refl },
{ -- case nat.succ
-- m : ℕ,
-- hm : m ≠ 1,
-- n_n : ℕ,
-- n_ih : n_n = m → n_n = 0 ∨ n_n > m,
-- h : succ n_n = m
-- ⊢ succ n_n = 0 ∨ succ n_n > m
have : n_n = 0 ∨ n_n > m, from sorry,
cases this,
subst this, exfalso,
exact hm h.symm,
exact or.inr (lt_succ_of_lt this) }
end
example : false := absurd (rubbish 2 2) dec_trivial
open measure_theory measure_theory.measure
lemma inl_measurable_bind_ret [measurable_space α] [measurable_space β] (ν : measure β) :
measurable (λ (x : α), bind ν (λ y, dirac (x, y))) :=
begin
end
#print measure.join
lemma inl_measurable_bind_ret' [measurable_space α] [measurable_space β] (w : measure β) :
measurable (λ (x : α), bind w (λ y, dirac (x, y))) :=
have ∀ x : α, measurable (@prod.mk α β x),
from λ x, measurable_prod_mk measurable_const measurable_id,
begin
dsimp [measure.bind],
conv in (map _ _) { rw [← measure.map_map measurable_dirac (this x)] },
refine measurable_join.comp _,
refine measurable.comp _ _,
{ refine measurable_map _ measurable_dirac },
{ sorry }
end
#exit
import data.equiv.encodable data.fintype
def f : bool → bool → bool
| tt tt := ff
| _ _ := tt
#print as_true
local notation `dec_trivial'` := of_as_true trivial
example : (∀ x y, f x y = f y x) ∧
¬(∀ x y z, f x (f y z) = f (f x y) z) := dec_trivial'
#eval ((finset.univ : finset (bool → bool → bool)).filter
(λ f : bool → bool → bool, (∀ x y, f x y = f y x) ∧
¬(∀ x y z, f x (f y z) = f (f x y) z))).1.unquot.nth_le 0
sorry ff ff
#exit
import data.finsupp order.complete_lattice algebra.ordered_group
namespace finsupp
open lattice
variables {σ : Type*} {α : Type*} [decidable_eq σ]
instance [preorder α] [has_zero α] : preorder (σ →₀ α) :=
{ le := λ f g, ∀ s, f s ≤ g s,
le_refl := λ f s, le_refl _,
le_trans := λ f g h Hfg Hgh s, le_trans (Hfg s) (Hgh s) }
instance [partial_order α] [has_zero α] : partial_order (σ →₀ α) :=
{ le_antisymm := λ f g hfg hgf, finsupp.ext $ λ s, le_antisymm (hfg s) (hgf s),
.. finsupp.preorder }
instance [canonically_ordered_monoid α] : order_bot (σ →₀ α) :=
{ bot := 0,
bot_le := λ f s, zero_le _,
.. finsupp.partial_order }
def finsupp.of_pfun {α β : Type*} [has_zero β] [decidable_eq α] [decidable_eq β]
(s : finset α) (f : Πa ∈ s, β) : α →₀ β :=
{ to_fun := λ a, if h : a ∈ s then f a h else 0,
support := s.filter (λ a, ∃ h : a ∈ s, f a h ≠ 0),
mem_support_to_fun := begin intros,
simp only [finset.mem_def.symm, finset.mem_filter],
split_ifs;
split; {tauto <|> finish}
end, }
def downset [preorder α] (a : α) := {x | x ≤ a}
#print finsupp
lemma nat_downset (f : σ →₀ ℕ) : finset (σ →₀ ℕ) :=
(f.support.pi (λ s, finset.range (f s))).map
⟨_, _⟩
lemma nat_downset_eq_downset (f : σ →₀ ℕ) :
(↑(nat_downset f) : set (σ →₀ ℕ)) = downset f := sorry
end finsupp
#exit
def r : ℕ → ℕ → Prop := classical.some (show ∃ r : ℕ → ℕ → Prop,
equivalence r ∧ ∀ a c b d,
r a b → r c d → r (a + c) (b + d), from ⟨(=), ⟨eq.refl, λ _ _, eq.symm, λ _ _ _, eq.trans⟩,
by intros; simp *⟩)
instance X_setoid : setoid ℕ := ⟨r, (classical.some_spec r._proof_1).1⟩
def X : Type := quotient ⟨r, (classical.some_spec r._proof_1).1⟩
--computable
def add : X → X → X := λ a b, quotient.lift_on₂ a b
(λ a b, ⟦a + b⟧)
(λ a b c d hab hcd,
quotient.sound $ (classical.some_spec r._proof_1).2 _ _ _ _ hab hcd)
#exit
import logic.basic tactic data.finset data.complex.basic data.polynomial
#print option.bind
lemma Z : has_sizeof (ℕ → ℕ) := by apply_instance
#eval sizeof ([] : list Type)
#eval sizeof (0 : polynomial (polynomial ℚ))
set_option pp.all true
#print Z
#print (infer_instance : )
#eval list.sizeof [@id ℕ]
#reduce λ α : Type, has_sizeof.sizeof α
inductive list2 : Type
| nil : list2
| cons : ℕ → ℕ → list2 → list2
#eval sizeof list2.nil
example {α: ℕ → Type u} (x y: ℕ) (a: α (x+y)) (b: α (y+x)) (h: a == b): true := begin
-- i want (h: a = b)
-- rw [nat.add_comm] at a, -- h still depends on old (a: α (x+y)) :<
-- have h: a = b := eq_of_heq h, -- fail
rw [nat.add_comm] at a,
intros a b h,
have h: a = b := eq_of_heq h, -- good
trivial,
end
example (X Y : Type) (f : X → Y) (hf : function.bijective f) : ∃ g : Y → X, true :=
⟨λ y, hf _, trivial⟩
#exit
import data.polynomial
#print finset.prod_sum
set_option pp.proofs true
#print eq.drec
open polynomial
#eval ((finset.range 9).sum (λ n, (X : polynomial ℕ) ^ n)) ^ 5
#eval let k := 2 in ((k + 1) * (k + 2) * (k + 3) * (k + 4)) / nat.fact 4
#eval nat.choose 3 4
#exit
import algebra.char_p
#print classical.em
#print rel.comp
set_option pp.implicit true
set_option pp.notation false
lemma X : (⟨bool, tt⟩ : Σ α : Type, α) ≠ ⟨bool, ff⟩ :=
λ h, by cases h
#print X
#exit
import topology.opens
open topological_space continuous
def opens.what_is_this_called {X : Type*} [topological_space X]
{U V : opens X} : opens V :=
U.comap
def well_ordering_rel {α : Type*} : α → α → Prop :=
classical.some well_ordering_thm
instance {α : Type*} : is_well_order α well_ordering_rel :=
classical.some_spec well_ordering_thm
local attribute [instance] classical.dec
noncomputable example {M : Type u → Type u} [monad M]
{α β : Type u} (f : β → M α) : M (β → α) :=
let g : β → M (β → α) := λ i : β, (do x ← f i, return (λ _, x)) in
if h : nonempty β then g (classical.choice h) else return (λ i : β, false.elim (h ⟨i⟩))
example {M : Type u → Type u} [monad M] {α β : Type u} : (β → M α) → M (β → α) :=
let r := @well_ordering_rel β in
have h : Π a : β, ({x // r x a} → M α) → M ({x // r x a} → α),
from well_founded.fix (show well_founded r, from sorry)
(λ a ih f, do g ← ih a _ _, _),
begin
end
#print monad
#print is_lawful_monad
#print vector.traverse
import data.nat.basic tactic.ring
lemma silly (n d : ℕ) : 2 * (2 ^ n * d + 2 ^ n * 1) - 2 * 1 + 1 =
2 ^ n * 2 * 1 + 2 ^ n * 2 * d - 1 :=
begin
rw [mul_one 2, bit0, ← nat.sub_sub, nat.sub_add_cancel];
ring,
end
#exit
noncomputable theory
open set function continuous
section homotopy
variables {X : Type*} [topological_space X]
variables {Y : Type*} [topological_space Y]
variables {Z : Type*} [topological_space Z]
lemma Union_inter_subset {α ι : Type*} {s t : ι → set α} :
(⋃ i, (s i ∩ t i)) ⊆ (⋃ i, s i) ∩ (⋃ i, t i) :=
by finish [set.subset_def]
lemma Inter_union_subset {α ι : Type*} {s t : ι → set α} :
(⋂ i, s i) ∪ (⋂ i, t i) ⊆ (⋂ i, (s i ∪ t i)) :=
by finish [set.subset_def]
local attribute [instance]classical.dec
/- pasting or gluing lemma: if a continuous function is continuous on finitely many
closed subsets, it is continuous on the Union -/
theorem continuous_on_Union_of_closed {ι : Type*} [fintype ι]
{s : ι → set X} (hs : ∀ i, is_closed (s i)) {f : X → Y}
(h : ∀ i, continuous_on f (s i)) : continuous_on f (⋃ i, s i) :=
begin
simp only [continuous_on_iff, mem_Union, exists_imp_distrib] at *,
assume x i hi t ht hfxt,
have h' : ∃ v : Π i, x ∈ s i → set X, ∀ i hi,
is_open (v i hi) ∧ x ∈ v i hi ∧ v i hi ∩ s i ⊆ f ⁻¹' t,
{ simpa only [classical.skolem] using λ i hi, h i x hi t ht hfxt },
cases h' with v hv,
use ⋂ (i : ι), (⋂ (hi : x ∈ s i), v i hi) ∩ (⋂ (hi : x ∉ s i), -s i),
refine ⟨is_open_Inter (λ j, is_open_inter
(is_open_Inter_prop (λ _, (hv _ _).1))
(is_open_Inter_prop (λ _, hs _))),
mem_Inter.2 (λ j, mem_inter (mem_Inter.2 (λ _, (hv _ _).2.1)) (mem_Inter.2 id)),
_⟩,
assume y hy,
simp only [mem_Inter, mem_inter_eq] at hy,
cases mem_Union.1 hy.2 with j hyj,
have hxj : x ∈ s j, from classical.by_contradiction (λ hxj, (hy.1 j).2 hxj hyj),
exact (hv j hxj).2.2 ⟨(hy.1 j).1 _, hyj⟩
end
theorem continuous_on_Union_of_open {ι : Sort*}
{s : ι → set X} (hs : ∀ i, is_open (s i)) {f : X → Y}
(h : ∀ i, continuous_on f (s i)) : continuous_on f (⋃ i, s i) :=
begin
simp only [continuous_on_iff, mem_Union, exists_imp_distrib] at *,
assume x i hi t ht hfxt,
have h' : ∃ v : Π i, x ∈ s i → set X, ∀ i hi,
is_open (v i hi) ∧ x ∈ v i hi ∧ v i hi ∩ s i ⊆ f ⁻¹' t,
{ simpa only [classical.skolem] using λ i hi, h i x hi t ht hfxt },
cases h' with v hv,
use v i hi ∩ s i,
use is_open_inter (hv _ _).1 (hs i),
use mem_inter (hv _ _).2.1 hi,
use subset.trans (inter_subset_left _ _) (hv i hi).2.2
end
lemma Inter_cond {α : Type*} {s t : set α} : (⋂ (i : bool), cond i t s) = s ∩ t :=
@Union_cond
lemma continuous_on_union_of_closed {s t : set X} (hsc : is_closed s)
(htc : is_closed t) {f : X → Y} (hsf : continuous_on f s)
(htf : continuous_on f t) : continuous_on f (s ∪ t) :=
by rw [← Union_cond]; exact continuous_on_Union_of_closed
(λ i, bool.cases_on i hsc htc) (λ i, bool.cases_on i hsf htf)
lemma continuous_on_union_of_open {s t : set X} (hsc : is_open s)
(htc : is_open t) {f : X → Y} (hsf : continuous_on f s)
(htf : continuous_on f t) : continuous_on f (s ∪ t) :=
by rw [← Union_cond]; exact continuous_on_Union_of_open
(λ i, bool.cases_on i hsc htc) (λ i, bool.cases_on i hsf htf)
#exit
import data.rat.denumerable
open encodable function lattice
namespace nat.subtype
variables {s : set ℕ} [decidable_pred s] [infinite s]
lemma exists_succ (x : s) : ∃ n, x.1 + n + 1 ∈ s :=
classical.by_contradiction $ λ h,
have ∀ (a : ℕ) (ha : a ∈ s), a < x.val.succ,
from λ a ha, lt_of_not_ge (λ hax, h ⟨a - (x.1 + 1),
by rwa [add_right_comm, nat.add_sub_cancel' hax]⟩),
infinite.not_fintype
⟨(((multiset.range x.1.succ).filter (∈ s)).pmap
(λ (y : ℕ) (hy : y ∈ s), subtype.mk y hy)
(by simp [-multiset.range_succ])).to_finset,
by simpa [subtype.ext, multiset.mem_filter, -multiset.range_succ]⟩
def succ (x : s) : s :=
have h : ∃ m, x.1 + m + 1 ∈ s, from exists_succ x,
⟨x.1 + nat.find h + 1, nat.find_spec h⟩
lemma succ_le_of_lt {x y : s} (h : y < x) : succ y ≤ x :=
have hx : ∃ m, y.1 + m + 1 ∈ s, from exists_succ _,
let ⟨k, hk⟩ := nat.exists_eq_add_of_lt h in
have nat.find hx ≤ k, from nat.find_min' _ (hk ▸ x.2),
show y.1 + nat.find hx + 1 ≤ x.1,
by rw hk; exact add_le_add_right (add_le_add_left this _) _
lemma le_succ_of_forall_lt_le {x y : s} (h : ∀ z < x, z ≤ y) : x ≤ succ y :=
have hx : ∃ m, y.1 + m + 1 ∈ s, from exists_succ _,
show x.1 ≤ y.1 + nat.find hx + 1,
from le_of_not_gt $ λ hxy,
have y.1 + nat.find hx + 1 ≤ y.1 := h ⟨_, nat.find_spec hx⟩ hxy,
not_lt_of_le this $
calc y.1 ≤ y.1 + nat.find hx : le_add_of_nonneg_right (nat.zero_le _)
... < y.1 + nat.find hx + 1 : nat.lt_succ_self _
lemma lt_succ_self (x : s) : x < succ x :=
calc x.1 ≤ x.1 + _ : le_add_right (le_refl _)
... < succ x : nat.lt_succ_self (x.1 + _)
def of_nat (s : set ℕ) [decidable_pred s] [infinite s] : ℕ → s
| 0 := ⊥
| (n+1) := succ (of_nat n)
lemma of_nat_strict_mono : strict_mono (of_nat s) :=
nat.strict_mono_of_lt_succ (λ a, by rw of_nat; exact lt_succ_self _)
open list
lemma of_nat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, of_nat s n = ⟨x, hx⟩
| x := λ hx, let t : list s := ((list.range x).filter (λ y, y ∈ s)).pmap
(λ (y : ℕ) (hy : y ∈ s), ⟨y, hy⟩) (by simp) in
have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩,
by simp [list.mem_filter, subtype.ext, t]; intros; refl,
if ht : t = [] then ⟨0, le_antisymm (@bot_le s _ _)
(le_of_not_gt (λ h, list.not_mem_nil ⊥ $
by rw [← ht, hmt]; exact h))⟩
else by letI : inhabited s := ⟨⊥⟩;
exact have wf : (maximum t).1 < x, by simpa [hmt] using list.mem_maximum ht,
let ⟨a, ha⟩ := of_nat_surjective_aux (list.maximum t).2 in
⟨a + 1, le_antisymm
(by rw of_nat; exact succ_le_of_lt (by rw ha; exact wf)) $
by rw of_nat; exact le_succ_of_forall_lt_le
(λ z hz, by rw ha; exact list.le_maximum_of_mem (hmt.2 hz))⟩
lemma of_nat_surjective : surjective (of_nat s) :=
λ ⟨x, hx⟩, of_nat_surjective_aux hx
def denumerable (s : set ℕ) [decidable_pred s] [infinite s] : denumerable s :=
have li : left_inverse (of_nat s) (λ x : s, nat.find (of_nat_surjective x)),
from λ x, nat.find_spec (of_nat_surjective x),
denumerable.of_equiv ℕ
{ to_fun := λ x, nat.find (of_nat_surjective x),
inv_fun := of_nat s,
left_inv := li,
right_inv := right_inverse_of_injective_of_left_inverse
(strict_mono.injective of_nat_strict_mono) li }
end nat.subtype
variables {α : Type*} [encodable α] [decidable_eq α]
def decidable_range_encode : decidable_pred (set.range (@encode α _)) :=
λ x, decidable_of_iff (option.is_some (decode2 α x))
⟨λ h, ⟨option.get h, by rw [← decode2_is_partial_inv (option.get h), option.some_get]⟩,
λ ⟨n, hn⟩, by rw [← hn, encodek2]; exact rfl⟩
variable [infinite α]
def demumerable_of_encodable_of_infinite : denumerable α :=
by letI := @decidable_range_encode α _ _;
letI : infinite (set.range (@encode α _)) :=
infinite.of_injective _ (equiv.set.range _ encode_injective).injective;
letI := nat.subtype.denumerable (set.range (@encode α _)); exact
denumerable.of_equiv (set.range (@encode α _))
{ to_fun := _ }
#exit
import topology.instances.real
lemma bool_ne_nat : bool ≠ nat :=
begin
end
#print set.image_preimage_eq
instance z : topological_space Prop := by apply_instance
#print sierpinski_space
#print topological_space.generate_from
#print continuous_generated_from
example {α : Type*} [topological_space α] : continuous (eq : α → α → Prop) :=
continuous_pi (λ x, _)
example {α : Type*} [topological_space α] {s : α → Prop} :
continuous s ↔ is_open s :=
⟨λ h, by convert h {true} (by simp); simp [eq_true, set.preimage, set_of],
λ _, continuous_generated_from $ by simpa [set.preimage, eq_true, set_of]⟩
def foo : nat → Prop
| 0 := true
| (n+1) := (foo n) ∧ (foo n)
meta def mk_foo_expr : nat → expr
| 0 := `(trivial)
| (n+1) :=
expr.app
(expr.app
(reflected.to_expr `(@and.intro (foo n) (foo n)))
(mk_foo_expr n))
(mk_foo_expr n)
open tactic
meta def show_foo : tactic unit :=
do `(foo %%nx) ← target,
n ← eval_expr nat nx,
exact (mk_foo_expr n)
set_option profiler true
lemma foo_200 : foo 500 :=
by show_foo
#print foo_200
#exit
import tactic category_theory.limits.types
def colimit_cocone {J Y : Type} {X : J → Type} (t : Π j : J, X j → Y)
(h : ∀ {α : Type} (f g : Y → α), (∀ j x, f (t j x) = g (t j x)) → f = g) :
∀ y : Y, ∃ j x, t j x = y :=
@eq.rec _ _ (λ P : Y → Prop, ∀ y, P y)
(λ _, true.intro) _
(@h Prop (λ _, true)
(λ y, ∃ j x, t j x = y)
(λ j x, propext ⟨λ _, ⟨j, x, eq.refl _⟩,
λ _, true.intro⟩))
#print category_theory.functor.id
open category_theory
def fin_functor : functor ℕ Type :=
{ obj := fin,
map := λ a b ⟨⟨h⟩⟩ i, ⟨i.1, lt_of_lt_of_le i.2 h⟩ }
#print functor.obj
def type_of {α : Sort*} (x : α) : Sort* := α
#reduce type_of (limits.types.colimit.{0} fin_functor).ι.app
example : sorry :=
begin
have := @colimit_cocone ℕ _ _
((limits.types.colimit.{0} fin_functor).ι.app) begin
end,
end
#print colimit_cocone
#reduce colimit_cocone
#reduce propext
#exit
import data.vector2
inductive expression : Type
| a {dim : ℕ} (v : fin dim → expression) /- omitted constraints on dim -/ : expression
| b : expression
open expression
#print expression.sizeof
#print vector.of_fn
def f (e : expression) : ℕ :=
expression.rec_on e
(λ n idx f, 1 + (vector.of_fn f).1.sum)
1
def f : expression -> ℕ
| (a idx) := 1 + ((vector.of_fn (λ x, idx x)).map f).1.sum
--using_well_founded {rel_tac := λ_ _, `[exact ⟨_, measure_wf (λ e, expression_size e)⟩] }
#exit
import data.rat.basic algebra.archimedean
lemma lt_of_mul_lt_mul_left' {α : Type*} [ordered_ring α]
{a b c : α} (hc : c ≥ 0) (h : c * a < c * b) : a < b := sorry
lemma div_le_div {a b : ℤ} : ((a / b : ℤ) : ℚ) ≤ a / b :=
if hb : b = 0 then by simp [hb]
else
have hb0 : 0 < (b : ℚ), from nat.cast_pos.2 _,
le_of_mul_le_mul_left (@le_of_add_le_add_left ℚ _ (a % b : ℤ) _ _
begin
rw [← int.cast_mul, ← int.cast_add, int.mod_add_div,
mul_div_cancel', add_comm],
exact le_add_of_le_of_nonneg (le_refl _)
(int.cast_nonneg.2 (int.mod_nonneg _ hb)),
end)
hb0
lemma div_eq_rat_floor (n : ℤ) (d : ℕ) : n / d = ⌊(n : ℚ) / d⌋ :=
if h : d = 0 then by simp [h]
else
have hd0 : (d : ℚ) ≠ 0, by simpa,
have hd0' : 0 < (d : ℚ), from sorry,
le_antisymm
(le_floor.2 _)
(int.le_of_lt_add_one $ floor_lt.2 (lt_of_mul_lt_mul_left'
(show (0 : ℚ) ≤ d, from nat.cast_nonneg _)
(begin
rw [mul_div_cancel' _ hd0, int.cast_add, add_comm, mul_add,
int.cast_one, mul_one],
conv {to_lhs, rw ← int.mod_add_div n d},
simp,
rw [← int.cast_coe_nat d, int.cast_lt],
convert int.mod_lt _ (int.coe_nat_ne_zero.2 h),
simp
end)))
open nat
inductive le' (a : ℕ) : ℕ → Prop
| refl : le' a
| succ : ∀ b, le' b → le' (succ b)
infix ` ≤' `: 50 := le'
lemma le'_trans {a b c : ℕ} (hab : a ≤' b) (hbc : b ≤' c) : a ≤' c :=
le'.rec_on hbc hab (λ _ _, le'.succ _)
def lt' (a b : ℕ) : Prop :=
succ a ≤' b
infix ` <' `:50 := lt'
lemma le_of_lt' {a b : ℕ} (h : a <' b) : a ≤' b :=
le'.rec_on h (le'.succ _ (le'.refl _)) (λ _ _, le'.succ _)
lemma b (a b c : ℕ) (hab : a <' b) (hbc : b <' c) : a <' c :=
le'_trans hab (le_of_lt' hbc)
#reduce b 3 4 5 (le'.refl _) (le'.refl _)
#exit
import algebra.module
import group_theory.group_action
import linear_algebra.basic -- this import breaks the commented lines at the end of the file
class group_module (G M : Type) [monoid G] [add_comm_group M]
extends mul_action G M :=
(smul_add : ∀ (g : G) (m₁ m₂ : M), g • (m₁ + m₂) = g • m₁ + g • m₂)
attribute [simp] group_module.smul_add
namespace fixed_points
open mul_action
variables {G M : Type}
variables [monoid G] [add_comm_group M]
variable [group_module G M]
lemma add_mem (x y : M) (hx : x ∈ fixed_points G M) (hy : y ∈ fixed_points G M) :
x + y ∈ fixed_points G M :=
begin
intro g,
simp only [mem_stabilizer_iff, group_module.smul_add, mem_fixed_points] at *,
rw [hx, hy],
end
end fixed_points
class representation (G R M : Type) [monoid G] [ring R] [add_comm_group M] [module R M]
extends group_module G M :=
(smul_comm : ∀ (g : G) (r : R) (m : M), g • (r • m) = r • (g • m))
--namespace representation
--open mul_action linear_map
variables {G R M : Type}
variables [group G] [ring R] [ring M] [module R M] [representation G R M]
set_option trace.class_instances true
--set_option class_
lemma smul_mem_fixed_points (r : R) (m : M) (hm : m ∈ mul_action.fixed_points G M) :
(r • m : M) = sorry :=
begin
simp only [mem_fixed_points] at *,
intro g,
rw [smul_comm, hm],
end
end representation
import data.equiv.basic order.zorn
open function set zorn
variables {α : Type*} {β : Type*} [nonempty β]
instance m : partial_order (α → β) :=
{ le := λ x y, range x ⊆ range y ∧ ∀ a, y a ∈ range x → y a = x a,
le_trans := λ x y z hxy hyz, ⟨subset.trans hxy.1 hyz.1,
λ a ha, begin
rw [hyz.2 a (hxy.1 ha), hxy.2 a],
rwa [← hyz.2 a (hxy.1 ha)]
end⟩,
le_refl := λ _, ⟨subset.refl _, λ _ _, rfl⟩,
le_antisymm := λ x y hxy hyx,
by simp only [subset.antisymm hxy.1 hyx.1] at *;
exact funext (λ a, (hxy.2 _ ⟨a, rfl⟩).symm) }
example : ∃ f : α → β, ∀ g, f ≤ g → g ≤ f :=
zorn _
(λ _ _ _, le_trans)
example {α β : Type*} [nonempty β] : {f : α → β // injective f ∨ surjective f} :=
let r :
begin
end
#exit
import data.list.basic
#print has_to
#print galois_insterion
@[derive decidable_eq] inductive fml
| atom (i : ℕ)
| imp (a b : fml)
| not (a : fml)
open fml
infixr ` →' `:50 := imp -- right associative
prefix `¬' `:51 := fml.not
inductive prf : fml → Type
| axk {p q} : prf (p →' q →' p)
| axs {p q r} : prf $ (p →' q →' r) →' (p →' q) →' (p →' r)
| axX {p q} : prf $ ((¬' q) →' (¬' p)) →' p →' q
| mp {p q} : prf p → prf (p →' q) → prf q
instance (p): has_sizeof (prf p) := by apply_instance
open prf
meta def length {f : fml} (t : prf f) : ℕ :=
prf.rec_on t (λ _ _, 1) (λ _ _ _, 1) (λ _ _, 1) (λ _ _ _ _, (+))
instance (p q : fml) : has_coe_to_fun (prf (p →' q)) :=
{ F := λ x, prf p → prf q,
coe := λ x y, mp y x }
lemma imp_self' (p : fml) : prf (p →' p) :=
mp (@axk p p) (mp axk axs)
lemma imp_comm {p q r : fml} (h : prf (p →' q →' r)) : prf (q →' p →' r) :=
mp axk (mp (mp (mp h axs) axk) (@axs _ (p →' q) _))
lemma imp_of_true (p : fml) {q : fml} (h : prf q) : prf (p →' q) :=
mp h axk
namespace prf
prefix `⊢ `:30 := prf
def mp' {p q} (h1 : ⊢ p →' q) (h2 : ⊢ p) : ⊢ q := mp h2 h1
def a1i {p q} : ⊢ p → ⊢ q →' p := mp' axk
def a2i {p q r} : ⊢ p →' q →' r → ⊢ (p →' q) →' p →' r := mp' axs
def con4i {p q} : ⊢ ¬' p →' ¬' q → ⊢ q →' p := mp' axX
def mpd {p q r} (h : ⊢ p →' q →' r) : ⊢ p →' q → ⊢ p →' r := mp' (a2i h)
def syl {p q r} (h1 : ⊢ p →' q) (h2 : ⊢ q →' r) : ⊢ p →' r := mpd (a1i h2) h1
def id {p} : ⊢ p →' p := mpd axk (@axk p p)
def a1d {p q r} (h : ⊢ p →' q) : ⊢ p →' r →' q := syl h axk
def com12 {p q r} (h : ⊢ p →' q →' r) : ⊢ q →' p →' r := syl (a1d id) (a2i h)
def con4d {p q r} (h : ⊢ p →' ¬' q →' ¬' r) : ⊢ p →' r →' q := syl h axX
def absurd {p q} : ⊢ ¬' p →' p →' q := con4d axk
def imidm {p q} (h : ⊢ p →' p →' q) : ⊢ p →' q := mpd h id
def contra {p} : ⊢ (¬' p →' p) →' p := imidm (con4d (a2i absurd))
def notnot2 {p} : ⊢ ¬' ¬' p →' p := syl absurd contra
def mpdd {p q r s} (h : ⊢ p →' q →' r →' s) : ⊢ p →' q →' r → ⊢ p →' q →' s := mpd (syl h axs)
def syld {p q r s} (h1 : ⊢ p →' q →' r) (h2 : ⊢ p →' r →' s) : ⊢ p →' q →' s := mpdd (a1d h2) h1
def con2d {p q r} (h1 : ⊢ p →' q →' ¬' r) : ⊢ p →' r →' ¬' q := con4d (syld (a1i notnot2) h1)
def con2i {p q} (h1 : ⊢ p →' ¬' q) : ⊢ q →' ¬' p := con4i (syl notnot2 h1)
def notnot1 {p} : ��� p →' ¬' ¬' p := con2i id
#reduce notnot2
infixr ` →' `:50 := imp -- right associative
prefix `¬' `:51 := fml.not
def p_of_p (p : fml) : prf (p →' p) :=
mp (@axk p p) (mp axk axs)
inductive consequence (G : list fml) : fml → Type
| axk (p q) : consequence (p →' q →' p)
| axs (p q r) : consequence $ (p →' q →' r) →' (p →' q) →' (p →' r)
| axn (p q) : consequence $ ((¬'q) →' (¬'p)) ���' p →' q
| mp (p q) : consequence p → consequence (p →' q) → consequence q
| of_G (g ∈ G) : consequence g
def consequence_of_thm (f : fml) (H : prf f) (G : list fml) : consequence G f :=
begin
induction H,
exact consequence.axk G H_p H_q,
exact consequence.axs G H_p H_q H_r,
exact consequence.axn G H_p H_q,
exact consequence.mp H_p H_q H_ih_a H_ih_a_1,
end
def thm_of_consequence_null (f : fml) (H : consequence [] f) : prf f :=
begin
induction H,
exact @axk H_p H_q,
exact @axs H_p H_q H_r,
exact @axX H_p H_q,
exact mp H_ih_a H_ih_a_1,
exact false.elim (list.not_mem_nil H_g H_H),
end
def deduction (G : list fml) (p q : fml) (H : consequence (p :: G) q) : consequence G (p →' q) :=
begin
induction H,
have H1 := consequence.axk G H_p H_q,
have H2 := consequence.axk G (H_p →' H_q →' H_p) p,
exact consequence.mp _ _ H1 H2,
have H6 := consequence.axs G H_p H_q H_r,
have H7 := consequence.axk G ((H_p →' H_q →' H_r) →' (H_p →' H_q) →' H_p →' H_r) p,
exact consequence.mp _ _ H6 H7,
have H8 := consequence.axn G H_p H_q,
have H9 := consequence.axk G (((¬' H_q) →' ¬' H_p) →' H_p →' H_q) p,
exact consequence.mp _ _ H8 H9,
have H3 := consequence.axs G p H_p H_q,
have H4 := consequence.mp _ _ H_ih_a_1 H3,
exact consequence.mp _ _ H_ih_a H4,
rw list.mem_cons_iff at H_H,
exact if h : H_g ∈ G then
begin
have H51 := consequence.of_G H_g h,
have H52 := consequence.axk G H_g p,
exact consequence.mp _ _ H51 H52,
end else
begin
have h := H_H.resolve_right h,
rw h,
exact consequence_of_thm _ (p_of_p p) G,
end
end
def part1 (p : fml) : consequence [¬' (¬' p)] p :=
begin
have H1 := consequence.axk [¬' (¬' p)] p p,
have H2 := consequence.axk [¬' (¬' p)] (¬' (¬' p)) (¬' (¬' (p →' p →' p))),
have H3 := consequence.of_G (¬' (¬' p)) (list.mem_singleton.2 rfl),
have H4 := consequence.mp _ _ H3 H2,
have H5 := consequence.axn [¬' (¬' p)] (¬' p) (¬' (p →' p →' p)),
have H6 := consequence.mp _ _ H4 H5,
have H7 := consequence.axn [¬' (¬' p)] (p →' p →' p) p,
have H8 := consequence.mp _ _ H6 H7,
exact consequence.mp _ _ H1 H8,
end
def p_of_not_not_p (p : fml) : prf ((¬' (¬' p)) →' p) :=
begin
have H1 := deduction [] (¬' (¬' p)) p,
have H2 := H1 (part1 p),
exact thm_of_consequence_null ((¬' (¬' p)) →' p) H2,
end
#reduce p_of_not_not_p
#reduce @notnot2
theorem not_not_p_of_p (p : fml) : prf (p →' (¬' (¬' p))) :=
begin
have H1 := prf.axs p (¬' (¬' p)),
have H2 := p_of_not_not_p (¬' p),
exact thm.mp H2 H1,
end
set_option pp.implicit true
#reduce not_not_p_of_p
#exit
@[derive decidable_eq] inductive fml
| atom (i : ℕ)
| imp (a b : fml)
| not (a : fml)
open fml
infixr ` →' `:50 := imp -- right associative
prefix `¬' `:40 := fml.not
inductive prf : fml → Type
| axk (p q) : prf (p →' q →' p)
| axs (p q r) : prf $ (p →' q →' r) →' (p →' q) →' (p →' r)
| axX (p q) : prf $ ((¬' q) →' (¬' p)) →' p →' q
| mp {p q} : prf p → prf (p →' q) → prf q
#print prf.rec
open prf
/-
-- example usage:
lemma p_of_p_of_p_of_q (p q : fml) : prf $ (p →' q) →' (p →' p) :=
begin
apply mp (p →' q →' p) ((p →' q) →' p →' p) (axk p q),
exact axs p q p
end
-/
def is_not : fml → Prop :=
λ f, ∃ g : fml, f = ¬' g
#print prf.rec_on
theorem Q6b (f : fml) (p : prf f) : is_not f → false :=
begin
induction p,
{admit},
{admit},
{admit},
{
clear p_ih_a_1,
}
end
#print Q6b
theorem Q6b : ∀ p : fml, ¬(prf $ p →' ¬' ¬' p) :=
begin
cases p,
end
#exit
import data.fintype
section
@[derive decidable_eq] inductive cbool
| t : cbool
| f : cbool
| neither : cbool
open cbool
instance : fintype cbool := ⟨{t,f,neither}, λ x, by cases x; simp⟩
variables (imp : cbool → cbool → cbool) (n : cbool → cbool)
(a1 : ∀ p q, imp p (imp q p) = t)
(a2 : ∀ p q, imp (imp (n q) (n p)) (imp p q) = t)
(a3 : ∀ p q r, imp (imp p (imp q r)) (imp (imp p q) (imp p r)) = t)
include a1 a2 a3
set_option class.instance_max_depth 50
-- example : ∀ p, imp p (n (n p)) = t :=
-- by revert imp n; exact dec_trivial
#exit
import measure_theory.measure_space topology.metric_space.emetric_space
noncomputable lemma F {α β : Sort*} : ((α → β) → α) → α :=
classical.choice $ (classical.em (nonempty α)).elim
(λ ⟨a⟩, ⟨λ _, a⟩)
(λ h, ⟨λ f, false.elim (h ⟨f (λ a, false.elim (h ⟨a⟩))⟩)⟩)
#reduce F
def X {α : Type*} [add_monoid α] {p : α → Prop} [is_add_submonoid p]: add_monoid (subtype p) :=
subtype.add_monoid
instance add_monoid_integrable' [is_add_submonoid (ball (0 : ℝ) ⊤)]:
add_monoid (subtype (ball (0 : ℝ) ⊤)) := X
#exit
import measure_theory.measurable_space
example {α : Type*} [add_monoid α] (p : set α): add_monoid (subtype p) := by apply_instance
#print topological_add_group
#eval ((univ : finset (perm (fin 7))).filter (λ x, sign x = 1 ∧ order_of x = 6)).card
import data.polynomial tactic.omega
open polynomial
set_option trace.simplify.rewrite true
example (x : ℤ) : x ^ 2 + x = x + x * x :=
by ring
example (a b c d e f : ℤ) (ha : a ≤ 2) (hb : c ≥ b - e) (hf : 5 * f - 2 * c = 9 * b - 7 * e)
(hd : d + 3 ≤ 7 + e) : d + 3 ≤ 7 + e := by omega
open mv_polynomial
set_option trace.simplify.rewrite true
lemma z : (X () : mv_polynomial unit ℤ) ^ 2 = X () * X () :=
begin
ring,
end
#print z
#exit
import tactic.omega
example (a b c : ℕ) (hab : 20 * a + 2 * b = 10 * b + c + 10 * c + a)
(ha : a < 10) (hb : b < 10) (hc : c < 10) : a = b ∧ b = c :=
by omega
example : ∀ {a : ℕ} (ha : a < 10) {b : ℕ} (hb : b < 10) {c : ℕ} (hc : c < 10)
(hab : 20 * a + 2 * b = 10 * b + c + 10 * c + a), a = b ∧ b = c :=
by omega
#exit
import data.equiv.algebra
variables {α : Type*} {β : Type*} [add_monoid β] (e : α ≃ β)
instance foo : add_monoid α := equiv.add_monoid e
--import tactic.omega
#exit
example (p q : ℕ → Prop) (h : p = q) (x : subtype p) :
(eq.rec_on h x : subtype q) = ⟨x.1, h ▸ x.2⟩ :=
begin
cases x, subst h,
end
def X : Type := ℤ
set_option trace.class_instances true
instance : comm_ring X := by apply_instance
lemma whatever (a b : ℕ) : a + b = 1 ↔ (a = 1 ∧ b = 0) ∨ (b = 1 ∧ a = 0) := by omega
#print whatever
example : 1000000 * 1000000 = 1000000000000 := by norm_num
lemma h (a b n : ℤ) : a + b - b + n = a + n := by simp
example : (1 : ℤ) + 2 - 2 + 3 = 1 + 3 := h 1 2 3
example : default Prop := trivial
inductive nat2
| zero : nat2
| succ : nat2 → nat2
#print nat2.zero
#print nat2.succ
#print nat2.rec
def add (a b : nat2) : nat2 :=
nat2.rec a (λ c, nat2.succ) b
example : ∀ (b : ℕ), b = b := by omega
example : ∃ (a : ℕ), a = 0 := by omega
example :
#print z
example : (∀ p q r : Prop, ((p ↔ q) ↔ r) ↔ (p ↔ (q ↔ r))) → ∀ p, p ∨ ¬p :=
λ h p, ((h (p ∨ ¬p) false false).mp
⟨λ h, h.mp (or.inr (λ hp, h.mp (or.inl hp))), false.elim⟩).mpr iff.rfl
noncomputable def step_fun : ℝ → ℝ := λ x, if x ≤ ξ then 1 else 0
lemma discont_at_step : ¬ (continuous_at step_fun ξ) :=
begin
unfold continuous_at,
-- our goal:
-- ⊢ ¬filter.tendsto step_fun (nhds ξ) (nhds (step_fun ξ))
rw metric.tendsto_nhds_nhds,
push_neg,
-- goal
-- ∃ (ε : ℝ), ε > 0 ∧ ∀ (δ : ℝ), δ > 0 → (∃ {x : ℝ},
-- dist x ξ < δ ∧ ε ≤ dist (step_fun x) (step_fun ξ))
use 1,
refine ⟨by norm_num, _⟩,
assume δ δ0,
use ξ + δ / 2,
split,
{ simp [real.dist_eq, abs_of_nonneg (le_of_lt (half_pos δ0)), half_lt_self δ0] },
{ have : ¬ ξ + δ / 2 ≤ ξ, from not_le_of_gt ((lt_add_iff_pos_right _).2 (half_pos δ0)),
simp [real.dist_eq, step_fun, le_refl, this] }
end
#exit
import data.set.basic data.finset
variables {α : Type*} {A B : set α}
theorem Q8: (A \ B) ∪ (B \ A) = (A ∪ B) \ (A ∩ B) :=
set.ext $ λ x, ⟨λ h, h.elim (λ h, ⟨or.inl h.1, mt and.right h.2⟩)
(λ h, ⟨or.inr h.1, mt and.left h.2⟩),
λ h, h.1.elim (λ hA, or.inl ⟨hA, λ hB, h.2 ⟨hA, hB⟩⟩)
(λ hB, or.inr ⟨hB, λ hA, h.2 ⟨hA, hB⟩⟩)⟩
lemma f : has_sub (set α) := by apply_instance
#print f
#print axioms Q8
#print axioms
#exit
import set_theory.cardinal tactic.norm_num
def list_to_nat : list bool → nat
| [] := 0
| (ff :: l) := 3 ^ (list_to_nat l) + 1
| (tt :: l) := 3 ^ (list_to_nat l) + 2
lemma list_to_nat_injective : function.injective list_to_nat
| [] [] h := rfl
| (a::l) [] h := by cases a; exact nat.no_confusion h
| [] (a::l) h := by cases a; exact nat.no_confusion h
| (a::l₁) (b::l₂) h := begin
cases a; cases b;
dunfold list_to_nat at h,
simp [pow_left_inj] at h,
end
noncomputable def list_unit_equiv_list_bool : list unit ≃ list bool :=
classical.choice $ quotient.exact $
show cardinal.mk (list unit) = cardinal.mk (list bool),
begin
rw [cardinal.mk_list_eq_sum_pow, cardinal.mk_list_eq_sum_pow],
apply le_antisymm,
{ refine cardinal.sum_le_sum _ _ (λ _, cardinal.power_le_power_right $
⟨⟨λ _, tt, λ _ _ _, subsingleton.elim _ _⟩⟩), },
{ simp, }
end
#print nat.to_digits
#print nat.to_digi
def bool_to_unit : l :=
lemma injective_unit_to_bool : function.injective unit_to_bool
| [] [] h := rfl
| (x::l) [] h := by cases x; exact absurd h (list.cons_ne_nil _ _)
| [] (x::l) h := by cases x; exact absurd h (λ h, list.cons_ne_nil _ _ h.symm)
| (tt::l₁) (tt::l₂) h := begin
unfold unit_to_bool at h,
simp at h,
rw injective_unit_to_bool h
end
| (ff::l₁) (ff::l₂) h := begin
unfold unit_to_bool at h,
simp at h,
rw injective_unit_to_bool h
end
| (tt::l₁) (ff::l₂) h := begin
unfold unit_to_bool at h,
simp at h,
rw ← unit_to_bool at h,
have := injective_unit_to_bool h,
end
example : list unit ≃ list bool :=
#exit
import data.fintype
--set_option pp.all true
lemma fin_injective {n m : ℕ} (h : fin n = fin m) : n = m :=
have e : fin n ≃ fin m, by rw h,
by rw [← fintype.card_fin n, fintype.card_congr e, fintype.card_fin]
lemma h : ∀ n, su
#print (show ∀ n, (subsingleton (fin n)), by apply_instance)
instance gjh (α : Type*) : subsingleton (fintype α) :=
⟨λ ⟨s₁, h₁⟩ ⟨s₂, h₂⟩, by congr⟩
#print fin_injective
#print axioms fintype.card_fin
#print axioms fin_injective
#exit
import data.real.basic data.set.intervals topology.basic analysis.complex.exponential
local attribute [instance] classical.prop_decidable
open real
noncomputable def fake_abs (x : ℝ) : ℝ := if x ≤ 0 then -x else x
noncomputable def fake_abs' : ℝ → ℝ := λ x, if x ≤ 0 then -x else x
#print prefix fake_abs.equations._eqn_1
#print prefix fake_abs'.equations._eqn_1
#exit
import set_theory.ordinal
universe u
open function lattice
theorem schroeder_bernstein {α β : Type*} {f : α → β} {g : β → α}
(hf : injective f) (hg : injective g) : ∃h:α→β, bijective h :=
let s : set α := lfp $ λs, - (g '' - (f '' s)) in
have hs : s = - (g '' - (f '' s)) :=
begin
dsimp [s, lfp, lattice.Inf, has_Inf.Inf,
complete_lattice.Inf, set.mem_set_of_eq,
set.image, set.compl, has_le.le,
preorder.le, partial_order.le, order_bot.le,
bounded_lattice.le, complete_lattice.le, has_neg.neg,
boolean_algebra.neg, complete_boolean_algebra.neg,
set.subset_def],
simp only [not_exists, classical.not_forall, not_and, set.ext_iff,
set.mem_set_of_eq], intro,
split; finish
--simp at hs,
end, sorry
open function
lemma injective_of_increasing {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) [is_trichotomous α r]
[is_irrefl β s] (f : α → β) (hf : ∀{x y}, r x y → s (f x) (f y)) : injective f :=
begin
intros x y hxy,
rcases trichotomous_of r x y with h | h | h,
have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this,
exact h,
have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this
end
def well_order {α : Type*} : α → α → Prop := classical.some (@well_ordering_thm α)
def wf {α : Type*} : has_well_founded α :=
⟨well_order, (classical.some_spec (@well_ordering_thm α)).2⟩
open cardinal
local attribute [instance] wf
variable {α : Type u}
local infix ` ≺ `:50 := well_order
instance is_well_order_wf : is_well_order _ ((≺) : α → α → Prop) :=
classical.some_spec (@well_ordering_thm α)
noncomputable def to_cardinal {α : Type u} : α → cardinal.{u}
| a := cardinal.succ (@cardinal.sup.{u u} {y : α // y ≺ a}
(λ y, have y.1 ≺ a, from y.2, to_cardinal y.1))
using_well_founded {dec_tac := tactic.assumption }
local attribute [instance] classical.dec
#print cardinal
lemma to_cardinal_increasing : ∀ {x y : α} (h : x ≺ y), to_cardinal x < to_cardinal y
| a b hab :=
have ha' : a = (show subtype (≺ b), from ⟨a, hab⟩).1, by simp,
begin
conv {to_rhs, rw [to_cardinal], congr, congr, funext, rw to_cardinal },
rw [to_cardinal, cardinal.lt_succ],
have ha' : a = (show subtype (≺ b), from ⟨a, hab⟩).1, by simp,
rw ha',
exact le_sup _ _
end
lemma to_cardinal_injective : function.injective (@to_cardinal α) :=
injective_of_increasing (≺) (<) _ (λ _ _, to_cardinal_increasing)
def to_Type : α → Type u :=
quotient.out ∘ to_cardinal
#print to_Type
lemma injective_to_Type : function.injective (@to_Type α) :=
function.injective_comp (λ x y h, by convert congr_arg cardinal.mk h; simp)
to_cardinal_injective
lemma Type_gt : (Type u ↪ α) → false :=
λ ⟨f, h⟩, cantor_injective (f ∘ @to_Type (set α))
(function.injective_comp h injective_to_Type)
lemma universe_strict_mono : (Type (u+1) ↪ Type u) → false := Type_gt
lemma universe_strict_mono' : Type u ↪ Type (u+1) :=
⟨_, injective_to_Type⟩
--#print embedding.trans
example : cardinal.lift.{(u+1) (u+2)} (cardinal.mk (Type u)) <
cardinal.mk (Type (u+1)) :=
lt_of_not_ge (λ ⟨f⟩, universe_strict_mono
(f.trans ⟨ulift.down, λ ⟨_⟩ ⟨_⟩ h, congr_arg _ h⟩))
-- lemma injective_of_increasing {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) [is_trichotomous α r]
-- [is_irrefl β s] (f : α → β) (hf : ∀{x y}, r x y → s (f x) (f y)) : injective f :=
-- begin
-- intros x y hxy,
-- rcases trichotomous_of r x y with h | h | h,
-- have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this,
-- exact h,
-- have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this
-- end
-- def well_order {α : Type*} : α → α → Prop := classical.some (@well_ordering_thm α)
-- def wf {α : Type*} : has_well_founded α :=
-- ⟨well_order, (classical.some_spec (@well_ordering_thm α)).2⟩
-- open cardinal
-- local attribute [instance] wf
-- variable {α : Type u}
-- local infix ` ≺ `:50 := well_order
-- instance is_well_order_wf : is_well_order _ ((≺) : α → α → Prop) :=
-- classical.some_spec (@well_ordering_thm α)
-- noncomputable def to_cardinal {α : Type u} : α → cardinal.{u}
-- | a := cardinal.succ (@cardinal.sup.{u u} {y : α // y ≺ a}
-- (λ y, have y.1 ≺ a, from y.2, to_cardinal y.1))
-- using_well_founded {dec_tac := tactic.assumption }
-- local attribute [instance] classical.dec
-- lemma to_cardinal_increasing : ∀ {x y : α} (h : x ≺ y), to_cardinal x < to_cardinal y
-- | a b hab :=
-- have ha' : a = (show subtype (≺ b), from ⟨a, hab⟩).1, by simp,
-- begin
-- conv {to_rhs, rw [to_cardinal], congr, congr, funext, rw to_cardinal },
-- rw [to_cardinal, cardinal.lt_succ],
-- have ha' : a = (show subtype (≺ b), from ⟨a, hab⟩).1, by simp,
-- rw ha',
-- exact le_sup _ _
-- end
-- lemma to_cardinal_injective : function.injective (@to_cardinal α) :=
-- injective_of_increasing (≺) (<) _ (λ _ _, to_cardinal_increasing)
-- def to_Type : α → Type u :=
-- quotient.out ∘ to_cardinal
-- lemma injective_to_Type : function.injective (@to_Type α) :=
-- function.injective_comp (λ x y h, by convert congr_arg cardinal.mk h; simp)
-- to_cardinal_injective
-- lemma Type_gt : (Type u ↪ α) → false :=
-- λ ⟨f, h⟩, cantor_injective (f ∘ @to_Type (set α))
-- (function.injective_comp h injective_to_Type)
-- lemma universe_strict_mono : (Type (u+1) ↪ Type u) → false := Type_gt
#exit
inductive foo: ℕ → ℕ → Type
def foo_fn (n m: ℕ): Type := foo n m → foo n m
inductive is_foo_fn
: Π {n m: ℕ}, foo_fn n m → Type
| IsFooEta:
Π {n m: ℕ} {f: foo_fn n m},
is_foo_fn f
→ is_foo_fn (λ M, f M)
open is_foo_fn
def ext: -- equation compiler failed to prove equation lemma (
-- workaround: disable lemma generation using `set_option eqn_compiler.lemmas false`)
Π {n m: ℕ}
{f: foo_fn n m},
is_foo_fn f
→ Σ f': foo_fn n m, is_foo_fn f'
| _ _ _ (IsFooEta f) :=
⟨_, IsFooEta (ext f).snd⟩
set_option trace.simp_lemmas
def ext2: -- equation compiler failed to prove equation lemma
--(workaround: disable lemma generation using `set_option eqn_compiler.lemmas false`)
Π {m n : ℕ}
{f: foo_fn n m},
is_foo_fn f
→ Σ f': foo_fn n m, is_foo_fn f'
| _ _ _ (IsFooEta f) :=
⟨_, IsFooEta (ext2 f).snd⟩
#print ext2._main
example : ∀ (n m : ℕ) (z : foo_fn n m) (f : is_foo_fn z),
ext2 (IsFooEta f) = ⟨λ (M : foo n m), (ext2 f).fst M, IsFooEta ((ext2 f).snd)⟩ :=
λ _ _ _ _, rfl
#print ext.equations._eqn_1
#exit
import data.finset data.fintype
variables {α : Type*} {β : Type*}
@[instance] lemma nat.cast_coe : has_coe nat string := sorry
local attribute [-instance] nat.cast_coe
def embeddings [decidable_eq α] [decidable_eq β] :
Π (l : list α), list β → list (Π a : α, a ∈ l → β)
| [] l := [λ _ h, false.elim h]
| (a::l) [] := []
| (a::l₁) l₂ := (embeddings l₁ l₂).bind
(λ f, (l₂.filter (λ b, ∀ a h, f a h ≠ b)).map
(λ b a' ha', if h : a' = a then b else _))
#eval (embeddings [1,2,3,4,5] [1,2,3,4,5]).length
#eval 5^5
lemma card_embeddings :
#exit
import tactic
#print prod.lex
example {α : Type*} [preorder α] {x y : α × α}: prod.lex ((<) : α → α → Prop) (≤) x y
↔ x.1 < y.1 ∨ (x.1 = y.1 ∧ x.2 ≤ y.2) :=
begin
split,
{ assume h,
{ induction h;simp * at * } },
{ assume h,
cases x, cases y,
cases h,
refine prod.lex.left _ _ _ h,
dsimp at h,
rw h.1,
refine prod.lex.right _ _ h.2 }
end
example {α : Type*} {β : α → Type*} [preorder α] [Π a : α, preorder (β a)]
{x y : psigma β} : psigma.lex (<) (λ a : α, @has_le.le (β a) _) x y
↔ x.1 < y.1 ∨ ∃ p : x.1 = y.1, x.2 ≤ by convert y.2 :=
begin
split,
{ assume h,
induction h; simp [*, eq.mpr] at * },
{ assume h, cases x, cases y,
cases h,
refine psigma.lex.left _ _ _ h,
cases h,
dsimp at h_w,
subst h_w,
refine psigma.lex.right _ _ h_h }
end
#exit
import tactic.interactive
def f {α : Type*} [decidable_eq α] (x y : α) : bool := x = y
local attribute [instance, priority 0] classical.prop_decidable
example {α : Type*} {P : Prop} {x y : α} (hxy : f x y = tt)
(hP : f x y = tt → P) : P :=
by tauto!
#exit
import topology.metric_space.basic
def inclusion {α : Type*} {s t : set α} (h : s ⊆ t) : s → t :=
λ x : s, (⟨x, h x.2⟩ : t)
@[simp] lemma inclusion_self {α : Type*} {s : set α} (h : s ⊆ s) (x : s) :
inclusion h x = x := by cases x; refl
@[simp] lemma inclusion_inclusion {α : Type*} {s t u : set α} (hst : s ⊆ t) (htu : t ⊆ u)
(x : s) : inclusion htu (inclusion hst x) = inclusion (set.subset.trans hst htu) x :=
by cases x; refl
lemma inclusion_injective {α : Type*} {s t : set α} (h : s ⊆ t) :
function.injective (inclusion h)
| ⟨_, _⟩ ⟨_, _⟩ := subtype.ext.2 ∘ subtype.ext.1
example {α : Type*} [topological_space α] (s t : set α) (h : s ⊆ t) :
continuous (inclusion h) :=
continuous_subtype_mk
#exit
import algebra.associated
#print irreducible
]
end⟩
#print prime
#exit
example : ∃ h : 1 = 1, true := dec_trivial
#exit
import topology.basic data.set.intervals analysis.exponential
open real set
-- Give a handle on the set [0,1] ⊂ ℝ
def unit_interval := (Icc (0:ℝ) 1)
-- Define an identity function on the subtype corresponding to this set
def restricted_id := function.restrict (λ (x:ℝ), x) unit_interval
-- show that restricted_id is continuous
lemma cont_restricted_id : continuous restricted_id :=
begin
intro,
intro,
apply continuous_subtype_val _,
exact a,
end
-- main idea: "getting the value of the subtype" unifies with "restricted_id"
-- now show that the identity function (on ℝ) is continuous on the unit interval
lemma continuous_on_unit_interval_id : continuous_on (λ (x:ℝ), x) unit_interval :=
begin
rw [continuous_on_iff_continuous_restrict],
exact cont_restricted_id,
end
-- This breaks for 1/x, obviously.
-- First of all, we can't just use subtype.val, since that won't unify.
-- To get some hope that it will go through thing, let's start over with the interval (0,1].
def ounit_interval := (Ioc (0:ℝ) 1)
noncomputable def restricted_inv := function.restrict (λ (x:ℝ), 1/x) ounit_interval
lemma cont_restricted_inv : continuous restricted_inv :=
begin
unfold restricted_inv function.restrict,
simp only [one_div_eq_inv],
exact continuous_inv (λ a, (ne_of_lt a.2.1).symm) continuous_subtype_val,
end
#print real.uniform_continuous_inv
#exit
open nat
#eval gcd (gcd (61 ^ 610 + 1) (61 ^ 671 - 1) ^ 671 + 1)
(gcd (61 ^ 610 + 1) (61 ^ 671 - 1) ^ 610 - 1) % 10
example : gcd (gcd (61 ^ 610 + 1) (61 ^ 671 - 1) ^ 671 + 1)
(gcd (61 ^ 610 + 1) (61 ^ 671 - 1) ^ 610 - 1) % 10 = 3 :=
begin
end
#exit
import tactic.ring data.real.basic algebra.module
example (x : ℝ) : x=2 → 2+x=x+2 := begin intro h, ring, end -- works
example (x : ℝ) : x=2 → 2*x=x*2 := begin intro h, ring, end -- works
example (x y : ℝ) : (x - y) ^ 3 = x^3 - 3 * x^2 * y + 3 * x * y^2 - y^3 := by ring
#print semimodule
constant r : ℕ → ℕ → Prop
notation a ` ♥ `:50 b :50:= r b a
infix ` ♠ ` : 50 := r
#print notation ♥
example (a b : ℕ) : a ♥ b :=
begin
/-
1 goal
a b : ℕ
⊢ b ♠ a
-/
end
#exit
import tactic.norm_num data.zmod.basic
#print X
example : ∀ (x y z : zmod 9), x^3 + y^3 + z^3 ≠ 4 := dec_trivial
#exit
import analysis.normed_space.basic
variable {Β : Type*}
namespace hidden
@[simp] lemma norm_mul [normed_field-eq B] (a b : Β) : ∥a * b∥ = ∥a∥ * ∥b∥ :=
normed_field.norm_mul a b
instance normed_field.is_monoid_hom_norm [normed_field α] : is_monoid_hom (norm : α → ℝ) :=
⟨norm_one, norm_mul⟩
@[simp] lemma norm_pow [normed_field α] : ∀ (a : α) (n : ℕ), ∥a^n∥ = ∥a∥^n :=
is_monoid_hom.map_pow norm
end hidden
#exit
import tactic.norm_num
def FP_step : ℕ × ℕ → ℕ × ℕ :=
λ ⟨a,b⟩, ⟨b,(a + b) % 89⟩
def FP : ℕ → ℕ × ℕ
| 0 := ⟨0,1⟩
| (n + 1) := FP_step (FP n)
def F (n : ℕ) : ℕ := (FP n).fst
lemma FP_succ {n a b c : ℕ}
(h : FP n = (a, b)) (h2 : (a + b) % 89 = c) : FP (nat.succ n) = (b, c) :=
by rw [← h2, FP, h]; refl
set_option pp.max_steps 1000000000
set_option pp.max_depth 1000000000
lemma L : F 44 = 0 := begin
have : FP 0 = (0, 1) := rfl,
iterate 44 { replace := FP_succ this (by norm_num; refl) },
exact congr_arg prod.fst this
end
lemma zero_eq_one : 0 = @has_zero.zero ℕ ⟨1⟩ :=
begin
refl,
end
#print L
#exit
--import data.zmod.basic
lemma double_neg_em : (∀ p, ¬¬p → p) ↔ (∀ p, p ∨ ¬p) :=
⟨λ dneg p, dneg (p ∨ ¬ p) (λ h, h (or.inr (h ∘ or.inl))),
λ em p hneg, (em p).elim id (λ h, (hneg h).elim)⟩
#print or.assoc
lemma z : (∀ {α : Type} {p : α → Prop}, (∀ x, p x) ↔ ∄ x, ¬ p x) → ∀ (P : Prop), P ∨ ¬ P :=
λ h P, (@h unit (λ _, P ∨ ¬ P)).2 (λ ⟨_, h⟩, h (or.inr (h ∘ or.inl))) ()
#print axioms z
lemma y : (7 + 8) + 5 = 7 + (8 + 5) :=
add_assoc 7 8 5
#print axioms nat.mul_assoc
#reduce y
example : 0 = @has_zero.zero ℕ ⟨1⟩ :=
begin
refl,
end
example : (⊥ : ℕ) = @lattice.has_bot.bot ℕ ⟨1⟩ :=
begin
refl,
end
lemma b {m n : ℕ} : (m * n) % n = 0 :=
nat.mul_mod_left _ _
lemma iff_assoc {p q r : Prop} : p ↔ (q ↔ r) ↔ (p ↔ q ↔ r) := by tauto!
#print iff_assoc
lemma eq_assoc {p q r : Prop} : p = (q = r) = (p = q = r) :=
by simpa [iff_iff_eq] using iff.assoc
#print iff_assoc
#reduce iff.assoc
example {p q : Prop} : (p ↔ p ∧ q) ↔ (p → q) :=
by split; intros; simp * at *
#exit
import data.real.basic
example : (2 : ℝ) ≤ ((((2 - (157 / 50 / 2 ^ (4 + 1)) ^ 2) ^ 2 - 2) ^ 2 - 2) ^ 2 - 2) ^ 2 :=
begin
rw (show 4 + 1 = 5, from rfl),
rw (show (2 : ℝ) ^ 5 = 32, by norm_num),
rw (show (157 : ℝ) / 50 / 32 = 157 / 1600, by norm_num),
rw (show ((157 : ℝ) / 1600) ^ 2 = 24649 / 2560000, by norm_num),
rw (show (2 : ℝ) - 24649 / 2560000 = 5095351/2560000, by norm_num),
rw (show ((5095351 : ℝ) /2560000) ^ 2 = 25962601813201/6553600000000, by norm_num),
-- let's try skipping steps
rw (show ((((25962601813201 : ℝ) / 6553600000000 - 2) ^ 2 - 2) ^ 2 - 2) ^ 2 =
6806775565993596917798714352237438749189222725565123913061124308255143227446400872965401873904861225601/3402823669209384634633746074317682114560000000000000000000000000000000000000000000000000000000000000000,
by norm_num),
-- worked!
-- ⊢ 2 ≤
-- 6806775565993596917798714352237438749189222725565123913061124308255143227446400872965401873904861225601 /
-- 3402823669209384634633746074317682114560000000000000000000000000000000000000000000000000000000000000000
rw le_div_iff,
{ norm_num },
{ norm_num }
-- ⊢ 0 < 3402823669209384634633746074317682114560000000000000000000000000000000000000000000000000000000000000000
end
import algebra.big_operators data.int.basic
open finset nat
variables {α : Type*} [semiring α]
--set_option trace.simplify.rewrite true
lemma nat.sub_right_inj {a b c : ℕ} (h₁ : c ≤ a) (h₂ : c ≤ b) : a - c = b - c ↔ a = b :=
by rw [nat.sub_eq_iff_eq_add h₁, nat.sub_add_cancel h₂]
lemma lemma1 {x y z : ℕ → α} (n : ℕ) : (range (n + 1)).sum
(λ i, (range (i + 1)).sum (λ j, x j * y (i - j)) * z (n - i)) =
(range (n + 1)).sum (λ i, x i * (range (n - i + 1)).sum (λ j, y j * z (n - i - j))) :=
begin
induction n,
{ simp [mul_assoc] },
{ simp [*, mul_assoc, @range_succ (succ n_n)] at * }
end
#print imp_congr_ctx
#print lemma1
#exit
import algebra.group data.equiv.basic
variables {α : Type*} {β : Type*}
structure monoid_equiv (α β : Type*) [monoid α] [monoid β] extends α ≃ β :=
(mul_hom : ∀ x y, to_fun (x * y) = to_fun x * to_fun y)
infix ` ≃ₘ ` : 50 := monoid_equiv
instance sfklkj [monoid α] [monoid β] (f : α ≃ₘ β) : is_monoid_hom f.to_fun :=
{ map_mul := f.mul_hom,
map_one := calc f.to_equiv.to_fun 1
= f.to_equiv.to_fun 1 * f.to_equiv.to_fun (f.to_equiv.inv_fun 1) :
by rw [f.to_equiv.right_inv, mul_one]
... = 1 : by rw [← f.mul_hom, one_mul, f.to_equiv.right_inv] }
#exit
import data.multiset
open nat
def S : multiset ℕ := quot.mk _ [1,2]
def T : multiset ℕ := quot.mk _ [2,1]
lemma S_eq_T : S = T := quot.sound (list.perm.swap _ _ _)
def X (m : multiset ℕ) : Type := {n : ℕ // n ∈ m}
def n : X S := ⟨1, dec_trivial⟩
def n' : X T := eq.rec_on S_eq_T n
set_option pp.proofs true
#reduce n'
def id' (n : ℕ) : ℕ := pred (1 + n)
lemma id'_eq_id : id' = id := funext $ λ _, by rw [id', add_comm]; refl
def Y (f : ℕ → ℕ) : Type := {n : ℕ // f n = n}
def m : Y id := ⟨0, rfl⟩
def m' : Y id' := eq.rec_on id'_eq_id.symm m
set_option pp.proofs true
#reduce m'
import topology.metric_space.basic tactic.find
open filter
universes u v
variables {ι : Type u} {α : ι → Type v} [fintype ι] [∀ i, metric_space (α i)]
#print function.inv_fun
lemma g : lattice.complete_lattice Prop := by apply_instance
#print lattice.complete_lattice_Prop
lemma h :
(⨅ (ε : ℝ) (h : ε > 0), principal {p : (Π i, α i) × (Π i, α i) | dist p.1 p.2 < ε} =
⨅ i : ι, filter.comap (λ a : (Π i, α i)×(Π i, α i), (a.1 i, a.2 i)) uniformity)
=
∀ (ε : ℝ) (h : ε > 0), principal {p : (Π i, α i) × (Π i, α i) | dist p.1 p.2 < ε} =
⨅ i : ι, filter.comap (λ a : (Π i, α i)×(Π i, α i), (a.1 i, a.2 i)) uniformity :=
by simp [lattice.infi_Prop_eq]
#exit
--local attribute [semireducible] reflected
#print char.to_nat
#print string.to_nat
#eval "∅".front.to_nat
#eval (⟨11, dec_trivial⟩ : char)
#eval "∅".front.to_nat - "/".front.to_nat
#eval 8662 - 8192 - 256 - 128 - 64 - 16 - 4 - 2
#eval "/".front.to_nat
meta def f (n : ℕ) (e : expr): expr :=
`(nat.add %%e %%`(n))
def g : ℕ := by tactic.exact (f 5 `(1))
#print int
#eval g
def foo : bool → nat → bool
| tt 0 := ff
| tt m := tt
| ff 0 := ff
| ff (m+1) := foo ff m
#print prefix foo
#print reflect
#eval foo tt 1
#exit
import topology.metric_space.basic
open nat
structure aux : Type 1 :=
(space : Type)
(metric : metric_space space)
set_option eqn_compiler.zeta true
noncomputable def my_def (X : ℕ → Type) [m : ∀n, metric_space (X n)] : ∀n:ℕ, aux
| 0 :=
{ space := X 0,
metric := by apply_instance }
| (succ n) :=
{ space := prod (my_def n).space (X n.succ),
metric := @prod.metric_space_max _ _ (my_def n).metric _ }
#print prefix my_def
set_option pp.all true
#print my_def._main
example : ∀ (X : nat → Type) [m : Π (n : nat), metric_space.{0} (X n)] (n : nat),
@eq.{2} aux (@my_def._main X m (nat.succ n))
{space := prod.{0 0} ((@my_def._main X m n).space) (X (nat.succ n)),
metric := @prod.metric_space_max.{0 0} ((@my_def._main X m n).space) (X (nat.succ n))
((@my_def._main X m n).metric)
(m (nat.succ n))} :=
λ _ _ _, by tactic.reflexivity tactic.transparency.all
example : ∀ (X : nat → Type) [m : Π (n : nat), metric_space.{0} (X n)] (n : nat),
@eq.{2} aux {space := prod.{0 0} ((@my_def._main X m n).space) (X (nat.succ n)),
metric := @prod.metric_space_max.{0 0} ((@my_def._main X m n).space) (X (nat.succ n))
((@my_def._main X m n).metric)
(m (nat.succ n))}
{space := prod.{0 0} ((@my_def X m n).space) (X (nat.succ n)),
metric := @prod.metric_space_max.{0 0} ((@my_def X m n).space) (X (nat.succ n))
((@my_def X m n).metric)
(m (nat.succ n))} := λ _ _ _, rfl
example : my_def = my_def._main := rfl
lemma b : ∀ (X : nat → Type) [m : Π (n : nat), metric_space.{0} (X n)] (n : nat),
@eq.{2} aux
{space := prod.{0 0} ((@my_def X m n).space) (X (nat.succ n)),
metric := @prod.metric_space_max.{0 0} ((@my_def X m n).space) (X (nat.succ n))
((@my_def X m n).metric)
(m (nat.succ n))}
(@my_def X m (nat.succ n))
:= λ _ _ _, by tactic.reflexivity tactic.transparency.all
example (X : ℕ → Type) [m : ∀n, metric_space (X n)] (n : ℕ) :
my_def X (n+1) = ⟨(my_def X n).space × (X n.succ),
@prod.metric_space_max.{0 0} _ _ (my_def X n).metric _⟩ :=
by refl
#print my_def._main
#exit
import tactic
class A (α : Type*) :=
(a : α)
class B (α : Type*) extends A α :=
(b : α)
class C (α : Type*) :=
(a : α)
(t : true)
instance C.to_A (α : Type*) [C α] : A α :=
{ ..show C α, by apply_instance }
instance B.to_C {α : Type*} [B α] : C α :=
{ t := trivial, .. show B α, by apply_instance }
def B.to_A' (α : Type*) [n : B α] : A α :=
A.mk (B.to_A α).a
def a' {α : Type*} [A α] := A.a α
example {α : Type*} [n : B α] (x : α) (h : @a' _ (B.to_A α) = x) : @a' _ (C.to_A α) = x :=
by rw h
namespace foo
open classical
local attribute [instance] classical.prop_decidable
@[derive decidable_eq] inductive value : Type
@[derive decidable_eq] structure foo :=
(bar : ℕ)
end foo
#exit
example {p : Prop} : (∀ q, (p → q) → q) → p :=
λ h, classical.by_contradiction (h false)
import logic.function data.quot data.set.basic
universe u
inductive tree_aux (α : Type u) : bool → Type u
| nil : tree_aux ff
| cons : α → tree_aux ff → tree_aux ff
| mk_tree : α → tree_aux ff → tree_aux tt
variables (α : Type*) (β : Type*) (γ : Type*) (δ : Type*)
open function
example {p q : Prop} (h : p → q) : ¬q → ¬p := (∘ h)
#check ((∘) ∘ (∘)) not eq
#reduce (λ (x : α → β) (y : δ → γ → α) (z : δ) (w : γ), ((∘) ∘ (∘)) x y z w)
def fun_setoid {α β} (f : α → β) : setoid α :=
{ r := (∘ f) ∘ eq ∘ f,
iseqv := ⟨λ _, rfl, λ _ _, eq.symm, λ _ _ _, eq.trans⟩ }
#reduce (λ f : α → β, ((∘ f) ∘ eq ∘ f))
structure quotient_map (α β : Type*) :=
(to_fun : α → β)
(inv_fun : β → quotient (fun_setoid to_fun))
(right_inverse : right_inverse inv_fun
(λ a : quotient (fun_setoid to_fun), quotient.lift_on' a to_fun (λ _ _, id)))
example {α : Type*} [s : setoid α] : quotient_map α (quotient s) :=
{ to_fun := quotient.mk,
inv_fun := λ a, quotient.lift_on a (λ a, (quotient.mk' a : quotient (fun_setoid quotient.mk)))
(λ a b h, quotient.sound' (quotient.sound h)),
right_inverse := λ x, quotient.induction_on x (λ _, rfl) }
#exit
import topology.metric_space.isometry
variables {X : Type*} {Y : Type*} [metric_space X] [metric_space Y] (i : X ≃ᵢ Y)
open metric
def jaih : bool := true
#print jaih
#print to_bool
#print (true : bool)
#exit
import logic.function
universes u v
axiom choice : Π (α : Sort u), nonempty (nonempty α → α)
∈
example : nonempty (Π {α : Sort u}, nonempty α → α) :=
let ⟨x⟩ := choice (Σ' α : Sort u, nonempty α) in
have _ := x _,
⟨_⟩
#reduce function.cantor_surjective
#exit
import topology.continuity
open set
variables {X : Type*} {Y : Type*} [topological_space X] [topological_space Y]
#print prod.topological_space
#print topological_space.generate_open
#reduce (@prod.topological_space X Y _ _).is_open
def prod_topology : topological_space (X × Y) :=
{ is_open := λ R, ∃ S : set (set (X × Y)), R = ⋃₀ S ∧
∀ s ∈ S, ∃ (U : set X) (hU : is_open U) (V : set Y) (hV : is_open V), s = set.prod U V,
is_open_univ := sorry,
is_open_inter := sorry,
is_open_sUnion := sorry }
example : @prod_topology X Y _ _ = prod.topological_space := rfl
attribute [instance, priority 1000] prod_topology
example (U : set X) (V : set Y) : set.prod U V = prod.fst ⁻¹' U ∩ prod.snd ⁻¹' V := rfl
#print topolog
example {Z : Type*}[topological_space Z]
(f : Z → X × Y) (hX : continuous (prod.fst ∘ f)) (hY : continuous (prod.snd ∘ f)) :
continuous f :=
λ S ⟨T, hT⟩, begin
rw [hT.1, preimage_sUnion],
refine is_open_Union (λ s, is_open_Union (λ hs, _)),
rcases hT.2 s hs with ⟨U, hU, V, hV, hUV⟩,
rw hUV,
show is_open (((prod.fst ∘ f)⁻¹' U) ∩ (prod.snd ∘ f)⁻¹' V),
exact is_open_inter (hX _ hU) (hY _ hV)
end
example {X Y: Type*} [topological_space X] [topological_space Y]
(f : X → Y) (hf : continuous f) (V : set Y) : is_closed V → is_closed (f ⁻¹' V) :=
hf _
#print set.prod
#print has_seq
example {X Y Z : Type*} [topological_space X] [topological_space Y] [topological_space Z]
(f : Z → X × Y) (hX : continuous (prod.fst ∘ f)) (hY : continuous (prod.snd ∘ f)) :
continuous f :=
λ S hS, begin
rw is_open_prod_iff at hS,
end
#print g
#exit
import data.complex.exponential analysis.exponential algebra.field topology.algebra.topological_structures
open real
theorem continuous_cos_x_plus_x : continuous (λ x, cos x + x) :=
continuous_add real.continuous_cos continuous_id
theorem continuous_cos_x_plus_x' : continuous (λ x, cos x + x) :=
begin
refine continuous_add _ _,
exact continuous_cos,
exact continuous_id,
end
namespace nzreal
def nzreal := {r : ℝ // r ≠ 0}
notation `ℝ*` := nzreal
constants nzc nzd : nzreal
-- one_ne_zero is zero_ne_one backwards
instance nzreal.one : has_one nzreal := ⟨⟨(1:ℝ), one_ne_zero⟩⟩
noncomputable instance nzreal.div : has_div nzreal :=
⟨λ q r, ⟨q.val / r.val, div_ne_zero q.property r.property⟩⟩
def nzreal_to_real (z : nzreal) : ℝ := subtype.val z
instance : has_lift nzreal real := ⟨nzreal_to_real⟩
class real.nzreal (r : ℝ) :=
(p : ℝ*)
(pf : r = ↑p)
-- idea is copied from data.real.nnreal
instance : has_coe ℝ* ℝ := ⟨subtype.val⟩
-- copy from Kevin Buzzard post on "computable division by non-zero real"
noncomputable instance : topological_space ℝ* := by unfold nzreal; apply_instance
end nzreal
-- almost the same as the proof for continuity of tangent
theorem continuous_1_over_x : continuous (λ (x : ℝ*), 1/x) :=
continuous_subtype_mk _ $ continuous_mul
(continuous_subtype_val.comp continuous_const)
(continuous_inv subtype.property
(continuous_subtype_val.comp continuous_id))
#exit
import data.complex.basic
example {z : ℂ} :
#exit
import ring_theory.unique_factorization_domain
namespace hidden
constant α : Type
@[instance] constant I : integral_domain α
@[elab_as_eliminator] axiom induction_on_prime {P : α → Prop}
(a : α) (h₁ : P 0) (h₂ : ∀ x : α, is_unit x → P x)
(h₃ : ∀ a p : α, a ≠ 0 → prime p → P a → P (p * a)) : P a
local infix ` ~ᵤ ` : 50 := associated
#print associated
lemma factors_aux (a : α) : a ≠ 0 → ∃ s : multiset α, a ~ᵤ s.prod ∧ ∀ x ∈ s, irreducible x :=
induction_on_prime a (by simp)
(λ x hx hx0, ⟨0, by simpa [associated_one_iff_is_unit]⟩)
(λ a p ha0 hp ih hpa0, let ⟨s, hs₁, hs₂⟩ := ih ha0 in
⟨p :: s, by rw multiset.prod_cons;
exact associated_mul_mul (associated.refl p) hs₁,
λ x hx, (multiset.mem_cons.1 hx).elim (λ hxp, hxp.symm ▸ irreducible_of_prime hp) (hs₂ _)⟩)
@[simp] lemma mul_unit_dvd_iff {a b : α} {u : units α} : a * u ∣ b ↔ a ∣ b :=
⟨λ ⟨d, hd⟩, by simp [hd, mul_assoc], λ ⟨d, hd⟩, ⟨(u⁻¹ : units α) * d, by simp [mul_assoc, hd]⟩⟩
lemma dvd_iff_dvd_of_rel_left {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c :=
let ⟨u, hu⟩ := h in hu ▸ mul_unit_dvd_iff.symm
@[simp] lemma dvd_mul_unit_iff {a b : α} {u : units α} : a ∣ b * u ↔ a ∣ b :=
⟨λ ⟨d, hd⟩, ⟨d * (u⁻¹ : units α), by simp [(mul_assoc _ _ _).symm, hd.symm]⟩,
λ h, dvd.trans h (by simp)⟩
lemma dvd_iff_dvd_of_rel_right {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c :=
let ⟨u, hu⟩ := h in hu ▸ dvd_mul_unit_iff.symm
lemma ne_zero_iff_of_associated {a b : α} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 :=
⟨λ ha, let ⟨u, hu⟩ := h in hu ▸ mul_ne_zero ha (units.ne_zero _),
λ hb, let ⟨u, hu⟩ := h.symm in hu ▸ mul_ne_zero hb (units.ne_zero _)⟩
lemma irreducible_of_associated {p q : α} (h : irreducible p) :
p ~ᵤ q → irreducible q :=
λ ⟨u, hu⟩, ⟨_, _⟩
lemma prime_of_irreducible {p : α} : irreducible p → prime p :=
induction_on_prime p (by simp) (λ p hp h, (h.1 hp).elim)
(λ a p ha0 hp ih hpa, (hpa.2 p a rfl).elim (λ h, (hp.2.1 h).elim)
(λ ⟨u, hu⟩, prime_of_associated hp ⟨u, hu ▸ rfl⟩))
#print multiset.prod
local attribute [instance] classical.dec
lemma multiset.dvd_prod {a : α} {s : multiset α} : a ∈ s → a ∣ s.prod :=
quotient.induction_on s (λ l a h, by simpa using list.dvd_prod h) a
lemma exists_associated_mem_of_dvd_prod {p : α} (hp : prime p) {s : multiset α} :
(∀ r ∈ s, prime r) → p ∣ s.prod → ∃ q ∈ s, p ~ᵤ q :=
multiset.induction_on s (by simp [mt is_unit_iff_dvd_one.2 hp.2.1])
(λ a s ih hs hps, begin
rw [multiset.prod_cons] at hps,
cases hp.2.2 _ _ hps with h h,
{ use [a, by simp],
cases h with u hu,
cases ((irreducible_of_prime (hs a (multiset.mem_cons.2
(or.inl rfl)))).2 p u hu).resolve_left hp.2.1 with v hv,
exact ⟨v, by simp [hu, hv]⟩ },
{ rcases ih (λ r hr, hs _ (multiset.mem_cons.2 (or.inr hr))) h with ⟨q, hq₁, hq₂⟩,
exact ⟨q, multiset.mem_cons.2 (or.inr hq₁), hq₂⟩ }
end)
lemma associated_mul_left_cancel {a b c d : α} (h : a * b ~ᵤ c * d) (h₁ : a ~ᵤ c)
(ha : a ≠ 0) : b ~ᵤ d :=
let ⟨u, hu⟩ := h in let ⟨v, hv⟩ := associated.symm h₁ in
⟨u * (v : units α), (domain.mul_left_inj ha).1
begin
rw [← hv, mul_assoc c (v : α) d, mul_left_comm c, ← hu],
simp [hv.symm, mul_assoc, mul_comm, mul_left_comm]
end⟩
noncomputable instance : unique_factorization_domain α :=
{ factors := λ a, if ha : a = 0 then 0 else classical.some (factors_aux a ha),
factors_prod := λ a ha, by rw dif_neg ha;
exact associated.symm (classical.some_spec (factors_aux a ha)).1,
irreducible_factors := λ a ha, by rw dif_neg ha;
exact (classical.some_spec (factors_aux a ha)).2,
unique := λ f, multiset.induction_on f
(λ g _ hg h,
multiset.rel_zero_left.2 $
multiset.eq_zero_of_forall_not_mem (λ x hx,
have is_unit g.prod, by simpa [associated_one_iff_is_unit] using h.symm,
(hg x hx).1 (is_unit_iff_dvd_one.2 (dvd.trans (multiset.dvd_prod hx)
(is_unit_iff_dvd_one.1 this)))))
(λ p f ih g hf hg hfg,
let ⟨b, hbg, hb⟩ := exists_associated_mem_of_dvd_prod
(prime_of_irreducible (hf p (by simp)))
(λ q hq, prime_of_irreducible (hg _ hq)) $
(dvd_iff_dvd_of_rel_right hfg).1
(show p ∣ (p :: f).prod, by simp) in
begin
rw ← multiset.cons_erase hbg,
exact multiset.rel.cons hb (ih (λ q hq, hf _ (by simp [hq]))
(λ q (hq : q ∈ g.erase b), hg q (multiset.mem_of_mem_erase hq))
(associated_mul_left_cancel
(by rwa [← multiset.prod_cons, ← multiset.prod_cons, multiset.cons_erase hbg]) hb
(nonzero_of_irreducible (hf p (by simp)))))
end),
..I }
end hidden
#exit
/-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Cast of characters:
`P` : a polynomial functor
`W` : its W-type
`M` : its M-type
`F` : a functor
`q` : `qpf` data, representing `F` as a quotient of `P`
The main goal is to construct:
`fix` : the initial algebra with structure map `F fix → fix`.
`cofix` : the final coalgebra with structure map `cofix → F cofix`
We also show that the composition of qpfs is a qpf, and that the quotient of a qpf
is a qpf.
-/
import tactic.interactive data.multiset
universe u
/-
Facts about the general quotient needed to construct final coalgebras.
-/
namespace quot
def factor {α : Type*} (r s: α → α → Prop) (h : ∀ x y, r x y → s x y) :
quot r → quot s :=
quot.lift (quot.mk s) (λ x y rxy, quot.sound (h x y rxy))
def factor_mk_eq {α : Type*} (r s: α → α → Prop) (h : ∀ x y, r x y → s x y) :
factor r s h ∘ quot.mk _= quot.mk _ := rfl
end quot
/-
A polynomial functor `P` is given by a type `A` and a family `B` of types over `A`. `P` maps
any type `α` to a new type `P.apply α`.
An element of `P.apply α` is a pair `⟨a, f⟩`, where `a` is an element of a type `A` and
`f : B a → α`. Think of `a` as the shape of the object and `f` as an index to the relevant
elements of `α`.
-/
structure pfunctor :=
(A : Type u) (B : A → Type u)
namespace pfunctor
variables (P : pfunctor) {α β : Type u}
-- TODO: generalize to psigma?
def apply (α : Type*) := Σ x : P.A, P.B x → α
def map {α β : Type*} (f : α → β) : P.apply α → P.apply β :=
λ ⟨a, g⟩, ⟨a, f ∘ g⟩
instance : functor P.apply := {map := @map P}
theorem map_eq {α β : Type*} (f : α → β) (a : P.A) (g : P.B a → α) :
@functor.map P.apply _ _ _ f ⟨a, g⟩ = ⟨a, f ∘ g⟩ :=
rfl
theorem id_map {α : Type*} : ∀ x : P.apply α, id <$> x = id x :=
λ ⟨a, b⟩, rfl
theorem comp_map {α β γ : Type*} (f : α → β) (g : β → γ) :
∀ x : P.apply α, (g ∘ f) <$> x = g <$> (f <$> x) :=
λ ⟨a, b⟩, rfl
instance : is_lawful_functor P.apply :=
{id_map := @id_map P, comp_map := @comp_map P}
inductive W
| mk (a : P.A) (f : P.B a → W) : W
def W_dest : W P → P.apply (W P)
| ⟨a, f⟩ := ⟨a, f⟩
def W_mk : P.apply (W P) → W P
| ⟨a, f⟩ := ⟨a, f⟩
@[simp] theorem W_dest_W_mk (p : P.apply (W P)) : P.W_dest (P.W_mk p) = p :=
by cases p; reflexivity
@[simp] theorem W_mk_W_dest (p : W P) : P.W_mk (P.W_dest p) = p :=
by cases p; reflexivity
end pfunctor
/-
Quotients of polynomial functors.
Roughly speaking, saying that `F` is a quotient of a polynomial functor means that for each `α`,
elements of `F α` are represented by pairs `⟨a, f⟩`, where `a` is the shape of the object and
`f` indexes the relevant elements of `α`, in a suitably natural manner.
-/
class qpf (F : Type u → Type u) [functor F] :=
(P : pfunctor.{u})
(abs : Π {α}, P.apply α → F α)
(repr : Π {α}, F α → P.apply α)
(abs_repr : ∀ {α} (x : F α), abs (repr x) = x)
(abs_map : ∀ {α β} (f : α → β) (p : P.apply α), abs (f <$> p) = f <$> abs p)
namespace qpf
variables {F : Type u → Type u} [functor F] [q : qpf F]
include q
attribute [simp] abs_repr
/-
Show that every qpf is a lawful functor.
Note: every functor has a field, map_comp, and is_lawful_functor has the defining
characterization. We can only propagate the assumption.
-/
theorem id_map {α : Type*} (x : F α) : id <$> x = x :=
by { rw ←abs_repr x, cases repr x with a f, rw [←abs_map], reflexivity }
theorem comp_map {α β γ : Type*} (f : α → β) (g : β → γ) (x : F α) :
(g ∘ f) <$> x = g <$> f <$> x :=
by { rw ←abs_repr x, cases repr x with a f, rw [←abs_map, ←abs_map, ←abs_map], reflexivity }
theorem is_lawful_functor
(h : ∀ α β : Type u, @functor.map_const F _ α _ = functor.map ∘ function.const β) : is_lawful_functor F :=
{ map_const_eq := h,
id_map := @id_map F _ _,
comp_map := @comp_map F _ _ }
/-
Think of trees in the `W` type corresponding to `P` as representatives of elements of the
least fixed point of `F`, and assign a canonical representative to each equivalence class
of trees.
-/
/-- does recursion on `q.P.W` using `g : F α → α` rather than `g : P α → α` -/
def recF {α : Type*} (g : F α → α) : q.P.W → α
| ⟨a, f⟩ := g (abs ⟨a, λ x, recF (f x)⟩)
theorem recF_eq {α : Type*} (g : F α → α) (x : q.P.W) :
recF g x = g (abs (recF g <$> q.P.W_dest x)) :=
by cases x; reflexivity
theorem recF_eq' {α : Type*} (g : F α → α) (a : q.P.A) (f : q.P.B a → q.P.W) :
recF g ⟨a, f⟩ = g (abs (recF g <$> ⟨a, f⟩)) :=
rfl
/-- two trees are equivalent if their F-abstractions are -/
inductive Wequiv : q.P.W → q.P.W → Prop
| ind (a : q.P.A) (f f' : q.P.B a → q.P.W) :
(∀ x, Wequiv (f x) (f' x)) → Wequiv ⟨a, f⟩ ⟨a, f'⟩
| abs (a : q.P.A) (f : q.P.B a → q.P.W) (a' : q.P.A) (f' : q.P.B a' → q.P.W) :
abs ⟨a, f⟩ = abs ⟨a', f'⟩ → Wequiv ⟨a, f⟩ ⟨a', f'⟩
| trans (u v w : q.P.W) : Wequiv u v → Wequiv v w → Wequiv u w
/-- recF is insensitive to the representation -/
theorem recF_eq_of_Wequiv {α : Type u} (u : F α → α) (x y : q.P.W) :
Wequiv x y → recF u x = recF u y :=
begin
cases x with a f, cases y with b g,
intro h, induction h,
case qpf.Wequiv.ind : a f f' h ih
{ simp only [recF_eq', pfunctor.map_eq, function.comp, ih] },
case qpf.Wequiv.abs : a f a' f' h ih
{ simp only [recF_eq', abs_map, h] },
case qpf.Wequiv.trans : x y z e₁ e₂ ih₁ ih₂
{ exact eq.trans ih₁ ih₂ }
end
theorem Wequiv.abs' (x y : q.P.W) (h : abs (q.P.W_dest x) = abs (q.P.W_dest y)) :
Wequiv x y :=
by { cases x, cases y, apply Wequiv.abs, apply h }
theorem Wequiv.refl (x : q.P.W) : Wequiv x x :=
by cases x with a f; exact Wequiv.abs a f a f rfl
theorem Wequiv.symm (x y : q.P.W) : Wequiv x y → Wequiv y x :=
begin
cases x with a f, cases y with b g,
intro h, induction h,
case qpf.Wequiv.ind : a f f' h ih
{ exact Wequiv.ind _ _ _ ih },
case qpf.Wequiv.abs : a f a' f' h ih
{ exact Wequiv.abs _ _ _ _ h.symm },
case qpf.Wequiv.trans : x y z e₁ e₂ ih₁ ih₂
{ exact qpf.Wequiv.trans _ _ _ ih₂ ih₁}
end
/-- maps every element of the W type to a canonical representative -/
def Wrepr : q.P.W → q.P.W := recF (q.P.W_mk ∘ repr)
theorem Wrepr_equiv (x : q.P.W) : Wequiv (Wrepr x) x :=
begin
induction x with a f ih,
apply Wequiv.trans,
{ change Wequiv (Wrepr ⟨a, f⟩) (q.P.W_mk (Wrepr <$> ⟨a, f⟩)),
apply Wequiv.abs',
have : Wrepr ⟨a, f⟩ = q.P.W_mk (repr (abs (Wrepr <$> ⟨a, f⟩))) := rfl,
rw [this, pfunctor.W_dest_W_mk, abs_repr],
reflexivity },
apply Wequiv.ind, exact ih
end
/-
Define the fixed point as the quotient of trees under the equivalence relation.
-/
def W_setoid : setoid q.P.W :=
⟨Wequiv, @Wequiv.refl _ _ _, @Wequiv.symm _ _ _, @Wequiv.trans _ _ _⟩
local attribute [instance] W_setoid
def fix (F : Type u → Type u) [functor F] [q : qpf F]:= quotient (W_setoid : setoid q.P.W)
def fix.rec {α : Type*} (g : F α → α) : fix F → α :=
quot.lift (recF g) (recF_eq_of_Wequiv g)
def fix_to_W : fix F → q.P.W :=
quotient.lift Wrepr (recF_eq_of_Wequiv (λ x, q.P.W_mk (repr x)))
def fix.mk (x : F (fix F)) : fix F := quot.mk _ (q.P.W_mk (fix_to_W <$> repr x))
def fix.dest : fix F → F (fix F) := fix.rec (functor.map fix.mk)
theorem fix.rec_eq {α : Type*} (g : F α → α) (x : F (fix F)) :
fix.rec g (fix.mk x) = g (fix.rec g <$> x) :=
have recF g ∘ fix_to_W = fix.rec g,
by { apply funext, apply quotient.ind, intro x, apply recF_eq_of_Wequiv,
apply Wrepr_equiv },
begin
conv { to_lhs, rw [fix.rec, fix.mk], dsimp },
cases h : repr x with a f,
rw [pfunctor.map_eq, recF_eq, ←pfunctor.map_eq, pfunctor.W_dest_W_mk, ←pfunctor.comp_map,
abs_map, ←h, abs_repr, this]
end
theorem fix.ind_aux (a : q.P.A) (f : q.P.B a → q.P.W) :
fix.mk (abs ⟨a, λ x, ⟦f x⟧⟩) = ⟦⟨a, f⟩⟧ :=
have fix.mk (abs ⟨a, λ x, ⟦f x⟧⟩) = ⟦Wrepr ⟨a, f⟩⟧,
begin
apply quot.sound, apply Wequiv.abs',
rw [pfunctor.W_dest_W_mk, abs_map, abs_repr, ←abs_map, pfunctor.map_eq],
conv { to_rhs, simp only [Wrepr, recF_eq, pfunctor.W_dest_W_mk, abs_repr] },
reflexivity
end,
by { rw this, apply quot.sound, apply Wrepr_equiv }
theorem fix.ind {α : Type*} (g₁ g₂ : fix F → α)
(h : ∀ x : F (fix F), g₁ <$> x = g₂ <$> x → g₁ (fix.mk x) = g₂ (fix.mk x)) :
∀ x, g₁ x = g₂ x :=
begin
apply quot.ind,
intro x,
induction x with a f ih,
change g₁ ⟦⟨a, f⟩⟧ = g₂ ⟦⟨a, f⟩⟧,
rw [←fix.ind_aux a f], apply h,
rw [←abs_map, ←abs_map, pfunctor.map_eq, pfunctor.map_eq],
dsimp [function.comp],
congr, ext x, apply ih
end
theorem fix.rec_unique {α : Type*} (g : F α → α) (h : fix F → α)
(hyp : ∀ x, h (fix.mk x) = g (h <$> x)) :
fix.rec g = h :=
begin
ext x,
apply fix.ind,
intros x hyp',
rw [hyp, ←hyp', fix.rec_eq]
end
theorem fix.mk_dest (x : fix F) : fix.mk (fix.dest x) = x :=
begin
change (fix.mk ∘ fix.dest) x = id x,
apply fix.ind,
intro x, dsimp,
rw [fix.dest, fix.rec_eq, id_map, comp_map],
intro h, rw h
end
theorem fix.dest_mk (x : F (fix F)) : fix.dest (fix.mk x) = x :=
begin
unfold fix.dest, rw [fix.rec_eq, ←fix.dest, ←comp_map],
conv { to_rhs, rw ←(id_map x) },
congr, ext x, apply fix.mk_dest
end
end qpf
/- Axiomatize the M construction for now -/
-- TODO: needed only because we axiomatize M
noncomputable theory
namespace pfunctor
axiom M (P : pfunctor.{u}) : Type u
-- TODO: are the universe ascriptions correct?
variables {P : pfunctor.{u}} {α : Type u}
axiom M_dest : M P → P.apply (M P)
axiom M_corec : (α → P.apply α) → (α → M P)
axiom M_dest_corec (g : α → P.apply α) (x : α) :
M_dest (M_corec g x) = M_corec g <$> g x
axiom M_bisim {α : Type*} (R : M P → M P → Prop)
(h : ∀ x y, R x y → ∃ a f f',
M_dest x = ⟨a, f⟩ ∧
M_dest y = ⟨a, f'⟩ ∧
∀ i, R (f i) (f' i)) :
∀ x y, R x y → x = y
theorem M_bisim' {α : Type*} (Q : α → Prop) (u v : α → M P)
(h : ∀ x, Q x → ∃ a f f',
M_dest (u x) = ⟨a, f⟩ ∧
M_dest (v x) = ⟨a, f'⟩ ∧
∀ i, ∃ x', Q x' ∧ f i = u x' ∧ f' i = v x') :
∀ x, Q x → u x = v x :=
λ x Qx,
let R := λ w z : M P, ∃ x', Q x' ∧ w = u x' ∧ z = v x' in
@M_bisim P (M P) R
(λ x y ⟨x', Qx', xeq, yeq⟩,
let ⟨a, f, f', ux'eq, vx'eq, h'⟩ := h x' Qx' in
⟨a, f, f', xeq.symm ▸ ux'eq, yeq.symm ▸ vx'eq, h'⟩)
_ _ ⟨x, Qx, rfl, rfl⟩
-- for the record, show M_bisim follows from M_bisim'
theorem M_bisim_equiv (R : M P → M P → Prop)
(h : ∀ x y, R x y → ∃ a f f',
M_dest x = ⟨a, f⟩ ∧
M_dest y = ⟨a, f'⟩ ∧
∀ i, R (f i) (f' i)) :
∀ x y, R x y → x = y :=
λ x y Rxy,
let Q : M P × M P → Prop := λ p, R p.fst p.snd in
M_bisim' Q prod.fst prod.snd
(λ p Qp,
let ⟨a, f, f', hx, hy, h'⟩ := h p.fst p.snd Qp in
⟨a, f, f', hx, hy, λ i, ⟨⟨f i, f' i⟩, h' i, rfl, rfl⟩⟩)
⟨x, y⟩ Rxy
theorem M_corec_unique (g : α → P.apply α) (f : α → M P)
(hyp : ∀ x, M_dest (f x) = f <$> (g x)) :
f = M_corec g :=
begin
ext x,
apply M_bisim' (λ x, true) _ _ _ _ trivial,
clear x,
intros x _,
cases gxeq : g x with a f',
have h₀ : M_dest (f x) = ⟨a, f ∘ f'⟩,
{ rw [hyp, gxeq, pfunctor.map_eq] },
have h₁ : M_dest (M_corec g x) = ⟨a, M_corec g ∘ f'⟩,
{ rw [M_dest_corec, gxeq, pfunctor.map_eq], },
refine ⟨_, _, _, h₀, h₁, _⟩,
intro i,
exact ⟨f' i, trivial, rfl, rfl⟩
end
def M_mk : P.apply (M P) → M P := M_corec (λ x, M_dest <$> x)
theorem M_mk_M_dest (x : M P) : M_mk (M_dest x) = x :=
begin
apply M_bisim' (λ x, true) (M_mk ∘ M_dest) _ _ _ trivial,
clear x,
intros x _,
cases Mxeq : M_dest x with a f',
have : M_dest (M_mk (M_dest x)) = ⟨a, _⟩,
{ rw [M_mk, M_dest_corec, Mxeq, pfunctor.map_eq, pfunctor.map_eq] },
refine ⟨_, _, _, this, rfl, _⟩,
intro i,
exact ⟨f' i, trivial, rfl, rfl⟩
end
theorem M_dest_M_mk (x : P.apply (M P)) : M_dest (M_mk x) = x :=
begin
have : M_mk ∘ M_dest = id := funext M_mk_M_dest,
rw [M_mk, M_dest_corec, ←comp_map, ←M_mk, this, id_map, id]
end
end pfunctor
/-
Construct the final coalebra to a qpf.
-/
namespace qpf
variables {F : Type u → Type u} [functor F] [q : qpf F]
include q
/-- does recursion on `q.P.M` using `g : α → F α` rather than `g : α → P α` -/
def corecF {α : Type*} (g : α → F α) : α → q.P.M :=
pfunctor.M_corec (λ x, repr (g x))
theorem corecF_eq {α : Type*} (g : α → F α) (x : α) :
pfunctor.M_dest (corecF g x) = corecF g <$> repr (g x) :=
by rw [corecF, pfunctor.M_dest_corec]
/- Equivalence -/
/- A pre-congruence on q.P.M *viewed as an F-coalgebra*. Not necessarily symmetric. -/
def is_precongr (r : q.P.M → q.P.M → Prop) : Prop :=
∀ ⦃x y⦄, r x y →
abs (quot.mk r <$> pfunctor.M_dest x) = abs (quot.mk r <$> pfunctor.M_dest y)
/- The maximal congruence on q.P.M -/
def Mcongr : q.P.M → q.P.M → Prop :=
λ x y, ∃ r, is_precongr r ∧ r x y
def cofix (F : Type u → Type u) [functor F] [q : qpf F]:= quot (@Mcongr F _ q)
def cofix.corec {α : Type*} (g : α → F α) : α → cofix F :=
λ x, quot.mk _ (corecF g x)
def cofix.dest : cofix F → F (cofix F) :=
quot.lift
(λ x, quot.mk Mcongr <$> (abs (pfunctor.M_dest x)))
begin
rintros x y ⟨r, pr, rxy⟩, dsimp,
have : ∀ x y, r x y → Mcongr x y,
{ intros x y h, exact ⟨r, pr, h⟩ },
rw [←quot.factor_mk_eq _ _ this], dsimp,
conv { to_lhs, rw [comp_map, ←abs_map, pr rxy, abs_map, ←comp_map] }
end
theorem cofix.dest_corec {α : Type u} (g : α → F α) (x : α) :
cofix.dest (cofix.corec g x) = cofix.corec g <$> g x :=
begin
conv { to_lhs, rw [cofix.dest, cofix.corec] }, dsimp,
rw [corecF_eq, abs_map, abs_repr, ←comp_map], reflexivity
end
private theorem cofix.bisim_aux
(r : cofix F → cofix F → Prop)
(h' : ∀ x, r x x)
(h : ∀ x y, r x y → quot.mk r <$> cofix.dest x = quot.mk r <$> cofix.dest y) :
∀ x y, r x y → x = y :=
begin
intro x, apply quot.induction_on x, clear x,
intros x y, apply quot.induction_on y, clear y,
intros y rxy,
apply quot.sound,
let r' := λ x y, r (quot.mk _ x) (quot.mk _ y),
have : is_precongr r',
{ intros a b r'ab,
have h₀: quot.mk r <$> quot.mk Mcongr <$> abs (pfunctor.M_dest a) =
quot.mk r <$> quot.mk Mcongr <$> abs (pfunctor.M_dest b) := h _ _ r'ab,
have h₁ : ∀ u v : q.P.M, Mcongr u v → quot.mk r' u = quot.mk r' v,
{ intros u v cuv, apply quot.sound, dsimp [r'], rw quot.sound cuv, apply h' },
let f : quot r → quot r' := quot.lift (quot.lift (quot.mk r') h₁)
begin
intro c, apply quot.induction_on c, clear c,
intros c d, apply quot.induction_on d, clear d,
intros d rcd, apply quot.sound, apply rcd
end,
have : f ∘ quot.mk r ∘ quot.mk Mcongr = quot.mk r' := rfl,
rw [←this, pfunctor.comp_map _ _ f, pfunctor.comp_map _ _ (quot.mk r),
abs_map, abs_map, abs_map, h₀],
rw [pfunctor.comp_map _ _ f, pfunctor.comp_map _ _ (quot.mk r),
abs_map, abs_map, abs_map] },
refine ⟨r', this, rxy⟩
end
theorem cofix.bisim
(r : cofix F → cofix F → Prop)
(h : ∀ x y, r x y → quot.mk r <$> cofix.dest x = quot.mk r <$> cofix.dest y) :
∀ x y, r x y → x = y :=
let r' x y := x = y ∨ r x y in
begin
intros x y rxy,
apply cofix.bisim_aux r',
{ intro x, left, reflexivity },
{ intros x y r'xy,
cases r'xy, { rw r'xy },
have : ∀ x y, r x y → r' x y := λ x y h, or.inr h,
rw ←quot.factor_mk_eq _ _ this, dsimp,
rw [@comp_map _ _ q _ _ _ (quot.mk r), @comp_map _ _ q _ _ _ (quot.mk r)],
rw h _ _ r'xy },
right, exact rxy
end
/-
TODO:
- define other two versions of relation lifting (via subtypes, via P)
- derive other bisimulation principles.
- define mk and prove identities.
-/
end qpf
/-
Composition of qpfs.
-/
namespace pfunctor
/-
def comp : pfunctor.{u} → pfunctor.{u} → pfunctor.{u}
| ⟨A₂, B₂⟩ ⟨A₁, B₁⟩ := ⟨Σ a₂ : A₂, B₂ a₂ → A₁, λ ⟨a₂, a₁⟩, Σ u : B₂ a₂, B₁ (a₁ u)⟩
-/
def comp (P₂ P₁ : pfunctor.{u}) : pfunctor.{u} :=
⟨ Σ a₂ : P₂.1, P₂.2 a₂ → P₁.1,
λ a₂a₁, Σ u : P₂.2 a₂a₁.1, P₁.2 (a₂a₁.2 u) ⟩
end pfunctor
namespace qpf
variables {F₂ : Type u → Type u} [functor F₂] [q₂ : qpf F₂]
variables {F₁ : Type u → Type u} [functor F₁] [q₁ : qpf F₁]
include q₂ q₁
def comp : qpf (functor.comp F₂ F₁) :=
{ P := pfunctor.comp (q₂.P) (q₁.P),
abs := λ α,
begin
dsimp [functor.comp],
intro p,
exact abs ⟨p.1.1, λ x, abs ⟨p.1.2 x, λ y, p.2 ⟨x, y⟩⟩⟩
end,
repr := λ α,
begin
dsimp [functor.comp],
intro y,
refine ⟨⟨(repr y).1, λ u, (repr ((repr y).2 u)).1⟩, _⟩,
dsimp [pfunctor.comp],
intro x,
exact (repr ((repr y).2 x.1)).snd x.2
end,
abs_repr := λ α,
begin
abstract {
dsimp [functor.comp],
intro x,
conv { to_rhs, rw ←abs_repr x},
cases h : repr x with a f,
dsimp,
congr,
ext x,
cases h' : repr (f x) with b g,
dsimp, rw [←h', abs_repr] }
end,
abs_map := λ α β f,
begin
abstract {
dsimp [functor.comp, pfunctor.comp],
intro p,
cases p with a g, dsimp,
cases a with b h, dsimp,
symmetry,
transitivity,
symmetry,
apply abs_map,
congr,
rw pfunctor.map_eq,
dsimp [function.comp],
simp [abs_map],
split,
reflexivity,
ext x,
rw ←abs_map,
reflexivity }
end
}
end qpf
/-
Quotients.
We show that if `F` is a qpf and `G` is a suitable quotient of `F`, then `G` is a qpf.
-/
namespace qpf
variables {F : Type u → Type u} [functor F] [q : qpf F]
variables {G : Type u → Type u} [functor G]
variable {FG_abs : Π {α}, F α → G α}
variable {FG_repr : Π {α}, G α → F α}
def quotient_qpf
(FG_abs_repr : Π {α} (x : G α), FG_abs (FG_repr x) = x)
(FG_abs_map : ∀ {α β} (f : α → β) (x : F α), FG_abs (f <$> x) = f <$> FG_abs x) :
qpf G :=
{ P := q.P,
abs := λ {α} p, FG_abs (abs p),
repr := λ {α} x, repr (FG_repr x),
abs_repr := λ {α} x, by rw [abs_repr, FG_abs_repr],
abs_map := λ {α β} f x, by { rw [abs_map, FG_abs_map] } }
end qpf
#exit
import group_theory.subgroup group_theory.perm
universe u
open finset equiv equiv.perm
class simple_group {G : Type*} [group G] :=
(simple : ∀ (H : set G) [normal_subgroup H], H = set.univ ∨ H = is_subgroup.trivial G)
variables {G : Type*} [group G] [fintype G] [decidable_eq G]
def conjugacy_class (a : G) : finset G :=
(@univ G _).image (λ x, x * a * x⁻¹)
@[simp] lemma mem_conjugacy_class {a b : G} : b ∈ conjugacy_class a ↔ is_conj a b :=
by simp [conjugacy_class, mem_image, is_conj, eq_comm]
def subgroup_closure (s : finset G) : finset G :=
insert 1 ((s.product s).image (λ a, a.1 * a.2⁻¹))
instance subgroup_closure.is_subgroup (s : finset G) :
is_subgroup (↑(subgroup_closure s) : set G) :=
{ one_mem := by simp [subgroup_closure],
mul_mem := sorry,
inv_mem := sorry }
def alternating (α : Type u) [fintype α] [decidable_eq α] : Type u :=
is_group_hom.ker (sign : perm α → units ℤ)
instance (α : Type u) [fintype α] [decidable_eq α] : group (alternating α) :=
by unfold alternating; apply_instance
instance (α : Type u) [fintype α] [decidable_eq α] :
fintype (alternating α) :=
by simp [alternating, is_group_hom.ker];
exact subtype.fintype _
#eval conjugacy_class (show alternating (fin 5),
from ⟨swap 1 2 * swap 2 3, by simp [is_group_hom.ker]; refl⟩)
#exit
def next_aux (N : nat) : list nat -> nat
| [] := 0
| (hd :: tl) := if hd < N then 0 else next_aux tl + 1
def next (m : nat) : list nat -> list nat
| [] := []
| (0 :: tl) := tl
| ((n+1) :: tl) := let index := next_aux (n+1) tl,
B := n :: list.take index tl,
G := list.drop index tl in
((++ B)^[m+1] B) ++ G
-- Beklemishev's worms
def worm_step (initial : nat) : Π step : nat, list nat
| 0 := [initial]
| (m+1) := next m (worm_step m)
#eval (list.range 10).map (worm_step 3)
-- It will terminate
theorem worm_principle : ∀ n, ∃ s, worm_step n s = []
| 0 := ⟨1, rfl⟩
| (n+1) := begin
end
-- def Fin : nat → Type
-- | 0 := empty
-- | (n+1) := option (Fin n)
inductive Fin : nat → Type
| mk {n : ℕ} : option (Fin n) → Fin (n + 1)
#exit
import analysis.topology.continuity
#print axioms continuous
local attribute [instance] classical.prop_decidable
import analysis.topology.continuity
lemma continuous_of_const {α : Type*} {β : Type*} [topological_space α]
[topological_space β] {f : α → β} (h : ∀a b, f a = f b) : continuous f :=
λ s hs, _
#exit
example {α : Type*} (r : α → α → Prop)
(h : ∀ f : ℕ → α, ∃ n, ¬r (f (n + 1)) (f n)) :
well_founded r :=
let f : Π a : α, �� acc r a → {b : α // ¬ acc r b ∧ r b a} :=
λ a ha, classical.indefinite_description _
(classical.by_contradiction
(λ hc, ha $ acc.intro _ (λ y hy,
classical.by_contradiction (λ hy1, hc ⟨y, hy1, hy⟩)))) in
well_founded.intro
(λ a, classical.by_contradiction
(λ ha, let g : Π n : ℕ, {b : α // ¬ acc r b} := λ n, nat.rec_on n ⟨a, ha⟩
(λ n b, ⟨f b.1 b.2, (f b.1 b.2).2.1⟩ ) in
have hg : ∀ n, r (g (n + 1)) (g n),
from λ n, nat.rec_on n (f _ _).2.2
(λ n hn, (f _ _).2.2),
exists.elim (h (subtype.val ∘ g)) (λ n hn, hn (hg _))))
example {α : Type*} (r : α → α → Prop)
(h : well_founded r) (f : ℕ → α) :
∃ n, ¬r (f (n + 1)) (f n) :=
classical.by_contradiction (λ hr,
@well_founded.fix α (λ a, ∀ n, a ≠ f n) r h
(λ a ih n hn, ih (f (n + 1)) (classical.by_contradiction (hn.symm ▸ λ h, hr ⟨_, h⟩)) (n + 1) rfl)
(f 0) 0 rfl )
lemma well_founded_iff_descending_chain {α : Type*} (r : α → α → Prop) :
well_founded r ↔ ∀ f : ℕ → α, ∃ n, ¬ r (f (n + 1)) (f n) :=
⟨λ h f, classical.by_contradiction (λ hr,
@well_founded.fix α (λ a, ∀ n, a ≠ f n) r h
(λ a ih n hn, ih (f (n + 1))
(classical.by_contradiction (hn.symm ▸ λ h, hr ⟨_, h⟩)) (n + 1) rfl)
(f 0) 0 rfl),
λ h, let f : Π a : α, ¬ acc r a → {b : α // ¬ acc r b ∧ r b a} :=
λ a ha, classical.indefinite_description _
(classical.by_contradiction
(λ hc, ha $ acc.intro _ (λ y hy,
classical.by_contradiction (λ hy1, hc ⟨y, hy1, hy⟩)))) in
well_founded.intro
(λ a, classical.by_contradiction
(λ ha,
let g : Π n : ℕ, {b : α // ¬ acc r b} :=
λ n, nat.rec_on n ⟨a, ha⟩
(λ n b, ���f b.1 b.2, (f b.1 b.2).2.1⟩) in
have hg : ∀ n, r (g (n + 1)) (g n),
from λ n, nat.rec_on n (f _ _).2.2
(λ n hn, (f _ _).2.2),
exists.elim (h (subtype.val ∘ g)) (λ n hn, hn (hg _))))⟩
#exit
import data.set.lattice order.order_iso data.quot
universes u v
noncomputable theory
axiom choice2_aux {α : Sort u} : { choice : α → α // ∀ (a b : α), choice a = choice b }
def choice2 : Π {α : Sort u}, α → α := λ _, choice2_aux.1
lemma choice2_spec : ∀ {α : Sort u} (a b : α), choice2 a = choice2 b := λ _, choice2_aux.2
axiom univalence : ∀ {α β : Sort u}, α ≃ β → α = β
lemma trunc.out2 {α : Sort u} (a : trunc α) : α := trunc.lift_on a choice2 choice2_spec
section diaconescu
variable p : Sort u
include p
private def U (x : Sort u) := trunc (psum (trunc x) p)
private def V (x : Sort u) := trunc (psum (x → false) p)
private lemma exU : trunc (Σ' x : Sort u, U p x) :=
trunc.mk ⟨punit, trunc.mk (psum.inl (trunc.mk punit.star))⟩
private lemma exV : trunc (Σ' x : Sort u, V p x) :=
trunc.mk ⟨pempty, trunc.mk (psum.inl (λ h, pempty.rec_on _ h))⟩
/- TODO(Leo): check why the code generator is not ignoring (some exU)
when we mark u as def. -/
private def u : Sort u := psigma.fst (choice2 (trunc.out2 (exU p)))
private def v : Sort u := psigma.fst (choice2 (trunc.out2 (exV p)))
set_option type_context.unfold_lemmas true
private lemma u_def : U p (u p) := psigma.snd (choice2 (trunc.out2 (exU p)))
private lemma v_def : V p (v p) := psigma.snd (choice2 (trunc.out2 (exV p)))
private lemma not_uv_or_p : psum ((u p) ≠ (v p)) p :=
psum.cases_on (trunc.out2 (u_def p))
(assume hut : trunc (u p),
psum.cases_on (trunc.out2 (v_def p))
(assume hvf : v p → false,
psum.inl (λ h, hvf (eq.rec_on h (trunc.out2 hut))))
psum.inr)
psum.inr
private lemma p_implies_uv (hp : p) : u p = v p :=
have hpred : U p = V p, from
funext (assume x : Sort u,
univalence
{ to_fun := λ _, trunc.mk (psum.inr hp),
inv_fun := λ _, trunc.mk (psum.inr hp),
left_inv := λ x, show trunc.mk _ = _, from subsingleton.elim _ _,
right_inv := λ x, show trunc.mk _ = _, from subsingleton.elim _ _ }),
show (choice2 (trunc.out2 (exU p))).fst = (choice2 (trunc.out2 (exV p))).fst,
from @eq.drec_on _ (U p)
(λ α (h : (U p) = α),
(choice2 (trunc.out2 (exU p))).fst =
(@choice2 (Σ' x : Sort u, α x) (trunc.out2
(eq.rec_on (show V p = α, from hpred.symm.trans h) (exV p)))).fst)
(V p) hpred (by congr)
#print axioms p_implies_uv
theorem em : psum p (p → false) :=
psum.rec_on (not_uv_or_p p)
(assume hne : u p ≠ v p, psum.inr (λ hp, hne (p_implies_uv p hp)))
psum.inl
end diaconescu
def old_choice {α : Sort u} : nonempty α → α :=
psum.rec_on (em α) (λ a _, a)
(function.swap (((∘) ∘ (∘)) false.elim nonempty.elim))
#print axioms old_choice
open tactic declaration
#eval do d ← get_decl `old_choice,
match d with
| defn _ _ _ v _ _ := do e ← tactic.whnf v
tactic.transparency.all tt, trace e, skip
| _ := skip
end
#exit
open set
section chain
parameters {α : Type u} (r : α → α → Prop)
local infix ` ≺ `:50 := r
/-- A chain is a subset `c` satisfying
`x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ c`. -/
def chain (c : set α) := pairwise_on c (λx y, x ≺ y ∨ y ≺ x)
parameters {r}
theorem chain.total_of_refl [is_refl α r]
{c} (H : chain c) {x y} (hx : x ∈ c) (hy : y ∈ c) :
x ≺ y ∨ y ≺ x :=
if e : x = y then or.inl (e ▸ refl _) else H _ hx _ hy e
theorem chain.directed [is_refl α r]
{c} (H : chain c) {x y} (hx : x ∈ c) (hy : y ∈ c) :
∃ z, z ∈ c ∧ x ≺ z ∧ y ≺ z :=
match H.total_of_refl hx hy with
| or.inl h := ⟨y, hy, h, refl _⟩
| or.inr h := ⟨x, hx, refl _, h⟩
end
theorem chain.mono {c c'} : c' ⊆ c → chain c → chain c' :=
pairwise_on.mono
theorem chain.directed_on [is_refl α r] {c} (H : chain c) : directed_on (≺) c :=
λ x xc y yc, let ⟨z, hz, h⟩ := H.directed xc yc in ⟨z, hz, h⟩
theorem chain_insert {c : set α} {a : α} (hc : chain c) (ha : ∀b∈c, b ≠ a → a ≺ b ∨ b ≺ a) :
chain (insert a c) :=
forall_insert_of_forall
(assume x hx, forall_insert_of_forall (hc x hx) (assume hneq, (ha x hx hneq).symm))
(forall_insert_of_forall (assume x hx hneq, ha x hx $ assume h', hneq h'.symm) (assume h, (h rfl).rec _))
def super_chain (c₁ c₂ : set α) := chain c₂ ∧ c₁ ⊂ c₂
def is_max_chain (c : set α) := chain c ∧ ¬ (∃c', super_chain c c')
def succ_chain (c : set α) : set α :=
psum.rec_on (em2 {c' : set α // chain c ∧ super_chain c c'}) subtype.val (λ _, c)
theorem succ_spec {c : set α} (h : {c' // chain c ∧ super_chain c c'}) :
super_chain c (succ_chain c) :=
let ⟨c', hc'⟩ := h in
have chain c ∧ super_chain c (some h),
from @some_spec _ (λc', chain c ∧ super_chain c c') _,
by simp [succ_chain, dif_pos, h, this.right]
theorem chain_succ {c : set α} (hc : chain c) : chain (succ_chain c) :=
if h : ∃c', chain c ∧ super_chain c c' then
(succ_spec h).left
else
by simp [succ_chain, dif_neg, h]; exact hc
theorem super_of_not_max {c : set α} (hc₁ : chain c) (hc₂ : ¬ is_max_chain c) :
super_chain c (succ_chain c) :=
begin
simp [is_max_chain, not_and_distrib, not_forall_not] at hc₂,
cases hc₂.neg_resolve_left hc₁ with c' hc',
exact succ_spec ⟨c', hc₁, hc'⟩
end
theorem succ_increasing {c : set α} : c ⊆ succ_chain c :=
if h : ∃c', chain c ∧ super_chain c c' then
have super_chain c (succ_chain c), from succ_spec h,
this.right.left
else by simp [succ_chain, dif_neg, h, subset.refl]
inductive chain_closure : set α → Prop
| succ : ∀{s}, chain_closure s → chain_closure (succ_chain s)
| union : ∀{s}, (∀a∈s, chain_closure a) → chain_closure (⋃₀ s)
theorem chain_closure_empty : chain_closure ∅ :=
have chain_closure (⋃₀ ∅),
from chain_closure.union $ assume a h, h.rec _,
by simp at this; assumption
theorem chain_closure_closure : chain_closure (⋃₀ chain_closure) :=
chain_closure.union $ assume s hs, hs
variables {c c₁ c₂ c₃ : set α}
private lemma chain_closure_succ_total_aux (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
(h : ∀{c₃}, chain_closure c₃ → c₃ ⊆ c₂ → c₂ = c₃ ∨ succ_chain c₃ ⊆ c₂) :
c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁ :=
begin
induction hc₁,
case _root_.zorn.chain_closure.succ : c₃ hc₃ ih {
cases ih with ih ih,
{ have h := h hc₃ ih,
cases h with h h,
{ exact or.inr (h ▸ subset.refl _) },
{ exact or.inl h } },
{ exact or.inr (subset.trans ih succ_increasing) } },
case _root_.zorn.chain_closure.union : s hs ih {
refine (classical.or_iff_not_imp_right.2 $ λ hn, sUnion_subset $ λ a ha, _),
apply (ih a ha).resolve_right,
apply mt (λ h, _) hn,
exact subset.trans h (subset_sUnion_of_mem ha) }
end
private lemma chain_closure_succ_total (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂) (h : c₁ ⊆ c₂) :
c₂ = c₁ ∨ succ_chain c₁ ⊆ c₂ :=
begin
induction hc₂ generalizing c₁ hc₁ h,
case _root_.zorn.chain_closure.succ : c₂ hc₂ ih {
have h₁ : c₁ ⊆ c₂ ∨ @succ_chain α r c₂ ⊆ c₁ :=
(chain_closure_succ_total_aux hc₁ hc₂ $ assume c₁, ih),
cases h₁ with h₁ h₁,
{ have h₂ := ih hc₁ h₁,
cases h₂ with h₂ h₂,
{ exact (or.inr $ h₂ ▸ subset.refl _) },
{ exact (or.inr $ subset.trans h₂ succ_increasing) } },
{ exact (or.inl $ subset.antisymm h₁ h) } },
case _root_.zorn.chain_closure.union : s hs ih {
apply or.imp_left (assume h', subset.antisymm h' h),
apply classical.by_contradiction,
simp [not_or_distrib, sUnion_subset_iff, classical.not_forall],
intros c₃ hc₃ h₁ h₂,
have h := chain_closure_succ_total_aux hc₁ (hs c₃ hc₃) (assume c₄, ih _ hc₃),
cases h with h h,
{ have h' := ih c₃ hc₃ hc₁ h,
cases h' with h' h',
{ exact (h₁ $ h' ▸ subset.refl _) },
{ exact (h₂ $ subset.trans h' $ subset_sUnion_of_mem hc₃) } },
{ exact (h₁ $ subset.trans succ_increasing h) } }
end
theorem chain_closure_total (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂) : c₁ ⊆ c₂ ∨ c₂ ⊆ c₁ :=
have c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁,
from chain_closure_succ_total_aux hc₁ hc₂ $ assume c₃ hc₃, chain_closure_succ_total hc₃ hc₂,
or.imp_right (assume : succ_chain c₂ ⊆ c₁, subset.trans succ_increasing this) this
theorem chain_closure_succ_fixpoint (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
(h_eq : succ_chain c₂ = c₂) : c₁ ⊆ c₂ :=
begin
induction hc₁,
case _root_.zorn.chain_closure.succ : c₁ hc₁ h {
exact or.elim (chain_closure_succ_total hc₁ hc₂ h)
(assume h, h ▸ h_eq.symm ▸ subset.refl c₂) id },
case _root_.zorn.chain_closure.union : s hs ih {
exact (sUnion_subset $ assume c₁ hc₁, ih c₁ hc₁) }
end
theorem chain_closure_succ_fixpoint_iff (hc : chain_closure c) :
succ_chain c = c ↔ c = ⋃₀ chain_closure :=
⟨assume h, subset.antisymm
(subset_sUnion_of_mem hc)
(chain_closure_succ_fixpoint chain_closure_closure hc h),
assume : c = ⋃₀{c : set α | chain_closure c},
subset.antisymm
(calc succ_chain c ⊆ ⋃₀{c : set α | chain_closure c} :
subset_sUnion_of_mem $ chain_closure.succ hc
... = c : this.symm)
succ_increasing⟩
theorem chain_chain_closure (hc : chain_closure c) : chain c :=
begin
induction hc,
case _root_.zorn.chain_closure.succ : c hc h {
exact chain_succ h },
case _root_.zorn.chain_closure.union : s hs h {
have h : ∀c∈s, zorn.chain c := h,
exact assume c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq,
have t₁ ⊆ t₂ ∨ t₂ ⊆ t₁, from chain_closure_total (hs _ ht₁) (hs _ ht₂),
or.elim this
(assume : t₁ ⊆ t₂, h t₂ ht₂ c₁ (this hc₁) c₂ hc₂ hneq)
(assume : t₂ ⊆ t₁, h t₁ ht₁ c₁ hc₁ c₂ (this hc₂) hneq) }
end
def max_chain := ⋃₀ chain_closure
/-- Hausdorff's maximality principle
There exists a maximal totally ordered subset of `α`.
Note that we do not require `α` to be partially ordered by `r`. -/
theorem max_chain_spec : is_max_chain max_chain :=
classical.by_contradiction $
assume : ¬ is_max_chain (⋃₀ chain_closure),
have super_chain (⋃₀ chain_closure) (succ_chain (⋃₀ chain_closure)),
from super_of_not_max (chain_chain_closure chain_closure_closure) this,
let ⟨h₁, h₂, (h₃ : (⋃₀ chain_closure) ≠ succ_chain (⋃₀ chain_closure))⟩ := this in
have succ_chain (⋃₀ chain_closure) = (⋃₀ chain_closure),
from (chain_closure_succ_fixpoint_iff chain_closure_closure).mpr rfl,
h₃ this.symm
/-- Zorn's lemma
If every chain has an upper bound, then there is a maximal element -/
theorem zorn (h : ∀c, chain c → ∃ub, ∀a∈c, a ≺ ub) (trans : ∀{a b c}, a ≺ b → b ≺ c → a ≺ c) :
∃m, ∀a, m ≺ a → a ≺ m :=
have ∃ub, ∀a∈max_chain, a ≺ ub,
from h _ $ max_chain_spec.left,
let ⟨ub, (hub : ∀a∈max_chain, a ≺ ub)⟩ := this in
⟨ub, assume a ha,
have chain (insert a max_chain),
from chain_insert max_chain_spec.left $ assume b hb _, or.inr $ trans (hub b hb) ha,
have a ∈ max_chain, from
classical.by_contradiction $ assume h : a ∉ max_chain,
max_chain_spec.right $ ⟨insert a max_chain, this, ssubset_insert h⟩,
hub a this⟩
end
#exit
import analysis.exponential group_theory.quotient_group
axiom R_iso_C : {f : ℝ ≃ ℂ // is_add_group_hom f}
open quotient_group
def R_mod_Z_iso_units_C : quotient_add_group.quotient (gmultiples (1 : ℝ))
≃ units ℂ :=
calc units ℂ ≃
#exit
import data.real.basic tactic.norm_num
#print expr
--set_option pp.all true
lemma crazy (k l : ℕ) (h : l ≤ k): ((2:real)⁻¹)^k ≤ (2⁻¹)^l :=
begin
apply pow_le_pow_of_le_one _ _ h,
norm_num,
norm_num1, norm_num1, simp,
show (2 : ℝ)⁻¹ ≤ 1,
norm_num1,
end
example {α : Type*} (h : α ≃ unit → false) {x : α} : α
import tactic.norm_num
set_option profiler true
lemma facebook_puzzle :
let a := 154476802108746166441951315019919837485664325669565431700026634898253202035277999 in
let b := 36875131794129999827197811565225474825492979968971970996283137471637224634055579 in
let c := 4373612677928697257861252602371390152816537558161613618621437993378423467772036 in
(a : ℚ) / (b + c) + b / (a + c) + c / (a + b) = 4 := by norm_num
#print facebook_puzzle
#print axioms facebook_puzzle
#exit
import data.complex.basic
lemma
import data.quot
section
variables {α : Sort*} {β : α → Sort*} {γ : Sort*} [s : ∀ a : α, setoid (β a)]
include s
instance pi.setoid : setoid (Π a : α, β a) :=
{ r := λ x y, ∀ a : α, x a ≈ y a,
iseqv := ⟨λ x a, setoid.refl _,
λ x y h a, setoid.symm (h a),
λ x y z hxy hyz a, setoid.trans (hxy a) (hyz a)⟩ }
meta def setoid_to_setoid (x : Π a : α, quotient (s a)) :
quotient (@pi.setoid α β _) :=
quotient.mk (λ a, quot.unquot (x a))
axiom quotient.lift_onₙ (x : Π a : α, quotient (s a))
(f : (Π a : α, β a) → γ) (h : ∀ x₁ x₂ : Π a, β a,
(∀ a, x₁ a ≈ x₂ a) → f x₁ = f x₂) : γ
end
#print classical.axiom_of_choice
lemma choice {α : Sort*} {β : α → Sort*} {r : Π (x : α), β x → Prop}
(h : ∀ (x : α), ∃ (y : β x), r x y) :
∃ (f : Π (x : α), β x), ∀ (x : α), r x (f x) :=
begin
end
lemma quotient.lift_on
#exit
import tactic.ring data.complex.basic
lemma h (x : ℝ) : x / 3 + x / -2 = x / 6 := by ring
set_option pp.all true
#print h
example (x : ℂ) : x / 3 + x / 2 = 5 * x / 6 := by ring
#exit
import tactic.interactive
-- private meta def collect_proofs_in :
-- expr → list expr → list name × list expr → tactic (list name × list expr)
-- | e ctx (ns, hs) :=
-- let go (tac : list name × list expr → tactic (list name × list expr)) :
-- tactic (list name × list expr) :=
-- (do t ← infer_type e,
-- mcond (is_prop t) (do
-- first (hs.map $ λ h, do
-- t' ← infer_type h,
-- is_def_eq t t',
-- g ← target,
-- change $ g.replace (λ a n, if a = e then some h else none),
-- return (ns, hs)) <|>
-- (let (n, ns) := (match ns with
-- | [] := (`_x, [])
-- | (n :: ns) := (n, ns)
-- end : name × list name) in
-- do generalize e n,
-- h ← intro n,
-- return (ns, h::hs)) <|> return (ns, hs)) (tac (ns, hs))) <|> return ([], []) in
-- match e with
-- | (expr.const _ _) := go return
-- | (expr.local_const _ _ _ t) := collect_proofs_in t ctx (ns, hs)
-- | (expr.mvar _ _ t) := collect_proofs_in t ctx (ns, hs)
-- | (expr.app f x) :=
-- go (λ nh, collect_proofs_in f ctx nh >>= collect_proofs_in x ctx)
-- | (expr.lam n b d e) :=
-- go (λ nh, do
-- nh ← collect_proofs_in d ctx nh,
-- var ← mk_local' n b d,
-- collect_proofs_in (expr.instantiate_var e var) (var::ctx) nh)
-- | (expr.pi n b d e) := do
-- nh ← collect_proofs_in d ctx (ns, hs),
-- var ← mk_local' n b d,
-- collect_proofs_in (expr.instantiate_var e var) (var::ctx) nh
-- | (expr.elet n t d e) :=
-- go (λ nh, do
-- nh ← collect_proofs_in t ctx nh,
-- nh ← collect_proofs_in d ctx nh,
-- collect_proofs_in (expr.instantiate_var e d) ctx nh)
-- | (expr.macro m l) :=
-- go (λ nh, mfoldl (λ x e, collect_proofs_in e ctx x) nh l)
-- | _ := return (ns, hs)
-- end
example {α : Type*} [ring α] (f : Π a : α, a ≠ 0 → α) (a b : α) (hb : b ≠ a) :
f (b - a) (mt sub_eq_zero_iff_eq.1 hb) = 0 :=
begin
generalize_proofs,
end
example {α : Type*} [ring α] (f : Π a : α, a ≠ 0 → α) (b : α ) (hb : b ≠ 0) :
f b hb = 0 :=
begin
generalize_proofs,
end
#exit
import data.set.basic data.set.lattice
import data.equiv.basic
structure partition (α : Type) :=
(C : set (set α))
(non_empty : ∀ c ∈ C, ∃ a : α, a ∈ c)
(disjoint : ∀ c d ∈ C, (∃ x, x ∈ c ∩ d) → c = d)
(all : ⋃₀ C = set.univ)
variable {α : Type}
definition partitions_equiv_relns :
{r : α → α → Prop | equivalence r} ≃ partition α :=
{ to_fun := λ r, ⟨⋃ a : α, {{b : α | r.1 a b}},
λ c ⟨s, ⟨a, ha⟩, m⟩, ⟨a,
by simp only [ha.symm, set.mem_singleton_iff] at m;
rw m; exact r.2.1 a⟩,
λ u v ⟨s, ⟨a, ha⟩, m⟩ ⟨t, ⟨b, hb⟩, n⟩ ⟨c, hc⟩, begin
clear _fun_match _x _fun_match _x _fun_match _x,
simp [hb.symm, ha.symm] at *,
simp [m, n] at *,
have := r.2.2.2 hc.1 (r.2.2.1 hc.2),
exact set.ext (λ x, ⟨r.2.2.2 (r.2.2.1 this), r.2.2.2 this⟩),
end,
set.eq_univ_of_forall $ λ a, ⟨{b : α | r.val a b}, set.mem_Union.2 ⟨a, by simp⟩, r.2.1 a⟩⟩,
inv_fun := λ p, ⟨λ a b, ∃ s ∈ p.1, a ∈ s ∧ b ∈ s,
⟨λ a, let ⟨s, hs⟩ := set.eq_univ_iff_forall.1 p.4 a in
⟨s, by tauto⟩,
λ a b, by simp only [and.comm, imp_self],
λ a b c ⟨s, hs₁, hs₂⟩ ⟨t, ht₁, ht₂⟩,
⟨s, hs₁, hs₂.1, have t = s, from p.3 _ _ ht₁ hs₁ ⟨b, ht₂.1, hs₂.2⟩, this ▸ ht₂.2⟩⟩⟩,
left_inv := λ ⟨r, hr⟩, subtype.eq begin
ext x y,
exact ⟨λ ⟨s, ⟨a, ⟨b, hb⟩, m⟩, t, ht⟩, begin simp [hb.symm] at *, simp [m] at *,
exact hr.2.2 (hr.2.1 t) ht, end,
λ h, ⟨{b : α | r x b}, set.mem_Union.2 ⟨x, by simp⟩,
by simp [*, hr.1 x] at *⟩⟩
end,
right_inv := λ ⟨C, hc₁, hc₂, hc₃⟩, partition.mk.inj_eq.mpr $
set.ext $ λ s, begin
end }
#exit
import analysis.topology.topological_space
open filter
variables {α : Type*} [topological_space α]
def X : filter α := generate {s | compact (-s)}
lemma tendsto_X_right {α β : Type*} [topological_space β] (f : filter α) (m : α → β) :
tendsto m f X ↔ ∀ s, compact (-s) → m ⁻¹' s ∈ f.sets :=
by simp [X, tendsto, sets_iff_generate, map, set.subset_def]
lemma mem_generate_iff {s : set (set α)} (hs : ∀ u v, u ∈ s → v ∈ s → u ∩ v ∈ s) {t : set α} :
t ∈ (generate s).sets ↔ ∃ u ∈ s, s ⊆ u :=
begin
end
lemma tendsto_X_left {α β : Type*} [topological_space α]
[topological_space β] (m : α → β) : tendsto m X X :=
begin
rw [tendsto_X_right, X],
end
#exit
instance : preorder ℂ :=
{ le := λ x y, x.abs ≤ y.abs,
le_refl := λ x, le_refl x.abs,
le_trans := λ x y z, @le_trans ℝ _ _ _ _ }
#print filter
example (f : ℂ → ℂ) : tendsto f at_top at_top ↔
∀ x : ℝ, ∃ r, ∀ z : ℂ, r < z.abs → x < (f z).abs
#exit
import data.zmod.basic
def dihedral (n : ℕ+) := units ℤ × zmod n
variable (n : ℕ+)
def mul : Π (x y : dihedral n), dihedral n
| ⟨ff, x⟩ ⟨ff, y⟩ :=
#exit
import tactic.interactive -- to get simpa
namespace random
open nat
set_option trace.simplify.rewrite true
@[semireducible] theorem add_right_cancel (n m k : nat) : n + k = m + k → n = m :=
begin
induction k with k ih,
{ -- base case
exact id, -- n = n + 0 is true by definition
},
{ -- inductive step
show succ (n + k) = succ (m + k) → _, -- again true by definition
intro H,
apply ih,
injection H,
}
end
#print axioms add_right_cancel
end random
#exit
universe u
@[derive decidable_eq] inductive poly_aux : Type
| zero : poly_aux
| X : poly_aux
| C : poly_aux
inductive polynomial_aux {α : Type u} [comm_semiring α] : poly_aux → Type u
| zero : polynomial_aux poly_aux.zero
| X : polynomial_aux poly_aux.X ⊕ polynomial_aux poly_aux.C → polynomial_aux poly_aux.X
| C {a : α} (h : a ≠ 0) : polynomial_aux poly_aux.zero ⊕ polynomial_aux poly_aux.X →
polynomial_aux poly_aux.C
#exit
import analysis.metric_space
open set
set_option trace.simplify.rewrite true
lemma closed_ball_Icc {x r : ℝ} : closed_ball x r = Icc (x-r) (x+r) :=
by simp only [closed_ball, Icc, dist, abs_sub_le_iff,
sub_le_iff_le_add', and.comm, add_comm]
#print closed_ball_Icc
#exit
import ring_theory.determinant data.polynomial
open polynomial
def M : matrix (unit) (unit) (polynomial ℤ) :=
λ r c, if r = 0 then if c = 1 then 1 else -1
else if c = 0 then 0
else if c = 1 then if r = 1 then -4 else -3
else if r = 2 then 5 else 6
#exit
import algebra.archimedean
import data.real.basic
definition completeness_axiom (k : Type*) [preorder k] : Prop :=
∀ (S : set k), (∃ x, x ∈ S) → (∃ x, ∀ y ∈ S, y ≤ x) →
∃ x, ∀ y, x ≤ y ↔ ∀ z ∈ S, z ≤ y
lemma reals_complete : completeness_axiom ℝ :=
λ S hS₁ hS₂, ⟨real.Sup S, λ y, ⟨λ h z hz, le_trans (real.le_Sup S hS₂ hz) h,
λ h, (real.Sup_le _ hS₁ hS₂).2 h⟩⟩
open function
section
parameters {K : Type*} {L : Type*} [discrete_linear_ordered_field K] [archimedean K]
[discrete_linear_ordered_field L] [archimedean L] (hL : completeness_axiom L)
lemma f_exists (k : K) :
∃ x, ∀ y, x ≤ y ↔ ∀ z ∈ (rat.cast '' {q : ℚ | (q : K) ≤ k} : set L), z ≤ y :=
(hL (rat.cast '' {q : ℚ | (q : K) ≤ k})
(let ⟨q, hq⟩ := exists_rat_lt k in ⟨q, ⟨q, ⟨le_of_lt hq, rfl⟩⟩⟩)
(let ⟨q, hq⟩ := exists_rat_gt k in ⟨q, λ y ⟨g, hg⟩, hg.2 ▸ rat.cast_le.2 $
(@rat.cast_le K _ _ _).1 (le_trans hg.1 (le_of_lt hq))⟩))
noncomputable def f (k : K) : L :=
classical.some (f_exists k)
lemma f_le_iff {q : ℚ} {k : K} : f k ≤ q ↔ k ≤ q :=
have ∀ (y : L), f k ≤ y ↔ ∀ (z : L), z ∈ rat.cast '' {q : ℚ | ↑q ≤ k} → z ≤ y,
from classical.some_spec (f_exists k),
by rw this q; exact
⟨λ h, le_of_not_gt (λ h1, let ⟨r, hr⟩ := exists_rat_btwn h1 in
not_le_of_gt hr.1 (rat.cast_le.2 (rat.cast_le.1 (h _ ⟨r, ⟨le_of_lt hr.2, rfl⟩⟩)))),
λ h z ⟨g, hg⟩, hg.2 ▸ rat.cast_le.2 (rat.cast_le.1 (le_trans hg.1 h))⟩
lemma lt_f_iff {q : ℚ} {k : K} : (q : L) < f k ↔ (q : K) < k :=
by rw [← not_le, ← not_le, f_le_iff]
lemma le_f_iff {q : ℚ} {k : K} : (q : L) ≤ f k ↔ (q : K) ≤ k :=
⟨λ h, le_of_not_gt $ λ hk,
let ⟨r, hr⟩ := exists_rat_btwn hk in
not_lt_of_ge (f_le_iff.2 (le_of_lt hk))
(lt_of_le_of_ne h (λ hq,
by rw [rat.cast_lt, ← @rat.cast_lt L, hq, lt_f_iff] at hr;
exact not_lt_of_gt hr.1 hr.2)),
λ h, le_of_not_gt $ λ hk,
let ⟨r, hr⟩ := exists_rat_btwn hk in
not_lt_of_ge h $ lt_of_le_of_lt (f_le_iff.1 (le_of_lt hr.1))
(rat.cast_lt.2 (rat.cast_lt.1 hr.2))⟩
lemma f_lt_iff {q : ℚ} {k : K} : f k < q ↔ k < q :=
by rw [← not_le, ← not_le, le_f_iff]
@[simp] lemma f_rat_cast (q : ℚ) : f q = q :=
le_antisymm (by rw f_le_iff) (by rw le_f_iff)
lemma f_injective : function.injective f :=
λ x y hxy, match lt_trichotomy x y with
| (or.inl h) := let ⟨q, hq⟩ := exists_rat_btwn h in
by rw [← lt_f_iff, ← f_lt_iff] at hq;
exact absurd hxy (ne_of_lt (lt_trans hq.1 hq.2))
| (or.inr (or.inl h)) := h
| (or.inr (or.inr h)) := let ⟨q, hq⟩ := exists_rat_btwn h in
by rw [← lt_f_iff, ← f_lt_iff] at hq;
exact absurd hxy.symm (ne_of_lt (lt_trans hq.1 hq.2))
end
lemma f_is_ring_hom : is_ring_hom f :=
⟨by rw [← rat.cast_one, f_rat_cast, rat.cast_one],
λ x y, le_antisymm _ _,
λ x y, le_antisymm
(f_le_iff.2 _)
_⟩
theorem characterisation_of_reals :
∃ f : K → ℝ, is_ring_hom f ∧ bijective f ∧ ∀ x y : K, x < y → f x < f y :=
end
#exit
import data.fintype
theorem Q0505 :
¬ (∃ a b c : ℕ, 6 * a + 9 * b + 20 * c = 43)
∧ ∀ m, m > 43 → ∃ a b c : ℕ, 6 * a + 9 * b + 20 * c = m :=
#exit
import data.nat.choose
open finset nat
theorem Q0403 : ∀ n : ℕ, finset.sum (finset.range n.succ)
(λ i, (-1 : ℤ) ^ i * choose (2 * n) (2 * i)) = -2 ^ n
| 0 := rfl
| (n+1) := begin
rw [sum_range_succ', function.comp],
conv in (choose (2 * (n + 1)) (2 * succ _))
{ rw [mul_add, mul_succ, mul_zero, zero_add, mul_succ,
choose_succ_succ, choose_succ_succ, choose_succ_succ], },
simp [sum_add_distrib, mul_add, *, -range_succ]
end
theorem Q0403 : finset.sum (finset.range 51)
(λ i, (-1 : ℤ) ^ i * choose 100 (2 * i)) = 0 := sorry
def Fin : nat → Type
| 0 := empty
| (n+1) := option (Fin n)
inductive tm : nat -> Type
| var_tm : Π {ntm : nat}, Fin ntm -> tm ntm
| app : Π {ntm : nat}, tm ntm -> tm ntm -> tm ntm
| lam : Π {ntm : nat}, tm (nat.succ ntm) -> tm ntm
open tm
inductive type : Type
| tint : type
| tarrow : type → type → type
definition empty_ctx : Fin 0 → type.
local infix `⤏`:20 := type.tarrow
inductive types : Π{m : ℕ}, (Fin m → type) → tm m → type → Prop
| tvar {m} Γ (x : Fin m) : types Γ (var_tm x) (Γ x)
| tapp {m} Γ (e₁ : tm m) e₂ (A B) : types Γ e₁ (A ⤏ B) → types Γ e₂ A → types Γ (app e₁ e₂) B
-- | tlam {m} Γ (e : tm (nat.succ m)) (A B) : types (@scons _ m A Γ) e B → types Γ (lam e) (A ⤏ B) requires some more definitions
def step {n} (t t' : tm n) := tt. --(..)
#print types.drec_on
lemma preservation (A : type) {n} (ctx : Fin n → type) (e₁ : tm 0) :
types empty_ctx e₁ A →
forall e₂, step e₁ e₂ → types empty_ctx e₂ A :=
λ H₁ e H₂,
begin
destruct H₁, dsimp,
exact sorry, exact sorry,
end
#print preservation
set_option trace.check true
lemma preservation (A : type) {n} (ctx : Fin n → type) (e₁ : tm 0) :
types empty_ctx e₁ A →
forall e₂, step e₁ e₂ → types empty_ctx e₂ A :=
λ H₁, @types.rec_on
(λ m ctx e₁ t, m = 0 → ctx == empty_ctx → ∀ e₂ : tm m, step e₁ e₂ → types ctx e₂ A) 0 empty_ctx e₁ A H₁
begin
intros m Γ _ hm hΓ,
subst hm,
have := eq_of_heq hΓ,
subst this,
end sorry rfl (heq.refl _)
set_option trace.check true
lemma preservation1 (A : type) {n} (ctx : Fin n → type) (e₁ : tm 0) :
types empty_ctx e₁ A →
forall e₂, step e₁ e₂ → types empty_ctx e₂ A :=
begin
intros H₁,
induction H₁,
end
#print empty_ctx
def f : ℕ+ → ℕ+
| ⟨1, h⟩ :=
example (x y : ℕ ): (x + y) * 2 = sorry :=
begin
simp [mul_comm],
end
example : real.partial_order = (@semilattice_inf.to_partial_order ℝ
(@lattice.to_semilattice_inf ℝ
(@conditionally_complete_lattice.to_lattice ℝ
(@conditionally_complete_linear_order.to_conditionally_complete_lattice ℝ
real.lattice.conditionally_complete_linear_order)))) := rfl
#print orderable_topology
#eval let n := 3 in let r := 2 in
(fintype.card {f : fin r → fin n // function.injective f},
fintype.card {f : fin n → fin r // function.surjective f})
#eval 93 / 3
#eval 2 ^ 5 - 2 * (1 ^ 5)
#eval 3 ^ 5 - 3 * (2 ^ 5 - (1 ^ 5))
#eval
#eval choose 5 2
#exit
import data.set.basic
class has_heart (α : Type*) := (heart : α → α → Prop)
notation a ` ♥ ` b := has_heart.heart a b
variables {α : Type*} [has_heart α]
def upper_bounds (s : set α) : set α := { x | ∀a ∈ s, a ♥ x }
def lower_bounds (s : set α) : set α := { x | ∀a ∈ s, x ♥ a }
def is_least (s : set α) (a : α) : Prop := a ∈ s ∧ a ∈ lower_bounds s
def is_greatest (s : set α) (a : α) : Prop := a ∈ s ∧ a ∈ upper_bounds s
def is_lub (s : set α) : α → Prop := is_least (upper_bounds s)
def is_glb (s : set α) : α → Prop := is_greatest (lower_bounds s)
theorem warm_up (S : Type) [has_heart S] :
(∀ E : set S, (∃ a, a ∈ E) ∧ (∃ b, b ∈ upper_bounds E) → ∃ s : S, is_lub E s) →
(∀ E : set S, (∃ a, a ∈ E) ∧ (∃ b, b ∈ lower_bounds E) → ∃ s : S, is_glb E s) :=
λ h E ⟨⟨e, he⟩, ⟨b, hb⟩⟩, let ⟨s, hs⟩ := h (lower_bounds E) ⟨⟨b, hb⟩, ⟨e, λ a ha, ha e he⟩⟩ in
⟨s, ⟨λ a ha, hs.2 _ (λ c hc, hc _ ha), hs.1⟩⟩
#print warm_up
#exit
import data.real.basic
structure complex : Type :=
(re : ℝ) (im : ℝ)
notation `ℂ` := complex
namespace complex
protected definition add : ℂ → ℂ → ℂ
| ⟨a, b⟩ ⟨c, d⟩ := ⟨a + c, b + d⟩
#print tactic.simp_config
notation a `+` b := complex.add a b
set_option trace.simplify.rewrite true
protected lemma add_assoc' (z1 z2 z3 : ℂ) : z1 + z2 + z3 = z1 + (z2 + z3) :=
begin
cases z1 with x1 y1, cases z2 with x2 y2, cases z3 with x3 y3,
simp only [complex.add, add_assoc],
exact ⟨rfl, rfl⟩
end
#print complex.add_assoc'
end complex
#exit
import data.fintype.basic group_theory.order_of_element algebra.pi_instances
variables {α : Type*} [fintype α] [decidable_eq α]
instance [group α] : decidable (∃ a : α, ∀ b : α, b ∈ gpowers a) :=
@fintype.decidable_exists_fintype α _ (λ a, ∀ b, b ∈ gpowers a)
(λ a, @fintype.decidable_forall_fintype α _ (λ b, b ∈ gpowers a)
(decidable_gpowers))
instance [group α] : decidable (is_cyclic α) :=
#exit
import data.rat.basic
inductive real : bool → Type
| of_rat : ℚ → real tt
| limit (x : Π q : ℚ, 0 < q → real tt) (∀ δ ε : ℚ, 0 < δ → 0 < ε → real ff ) :
mutual inductive A, B
with A : Type
| mk : B → A
with B : Type
| mk : A → B
def A.to_sort (l : Sort*) : A → l
| (A.mk (B.mk x)) := A.to_sort x
#print A.rec
def AB.reca : Π {Ca : A → Sort*}
(ha : Π a : A, Ca a → Cb (B.mk a))
(a : A), Ca a := λ _ _ _ _ a, A.to_sort _ a
def A.to_false (a : A) : false :=
AB.reca _ _ _
#print A.to_sort._main._pack
#exit
import data.finset analysis.metric_space
#print tactic.interactive.dsimp
example {α : Type*} (s : finset α) : s.card = 1 → {a : α // s = finset.singleton a} :=
finset.rec_on s (λ s, @quotient.rec_on_subsingleton _ _
(λ t : multiset α, Π (nodup : multiset.nodup t),
finset.card {val := t, nodup := nodup} = 1 → {a // finset.mk t nodup = finset.singleton a})
(λ l, ⟨λ a b, funext (λ x, funext (λ y, subtype.eq $ finset.singleton_inj.1 $
by rw [← (a x y).2, ← (b x y).2]))⟩) s
(λ l, list.rec_on l (λ _ h, nat.no_confusion h)
(λ a l _ _ h, have l.length = 0, from nat.succ_inj h,
⟨a, finset.eq_of_veq $ by dsimp; rw [list.length_eq_zero.1 this]; refl⟩)) )
#eval g ({1} : finset ℕ) rfl
#print metric_space
mutual inductive A, B
with A : Type
| mk : B → A
with B : Type
| mk : A → B
def size : A ⊕ B → ℕ
|
inductive AB : bool → Type
| mk_0 : AB ff → AB tt
| mk_1 : AB tt → AB ff
example (b : bool) (x : AB b) : false :=
AB.rec_on x (λ _, id) (λ _, id)
lemma A_mut_false(x : psum unit unit) (a : A._mut_ x) : false :=
A._mut_.rec_on a (λ _, id) (λ _, id)
lemma h : A ⊕ B → false
| (sum.inl (A.mk b)) := h (sum.inr b)
| (sum.inr (B.mk a)) := h (sum.inl a)
example : A → false := h ∘ sum.inl
example : B → false := h ∘ sum.inr
#print prefix A
#print B
#print A._mut_
#exit
import analysis.exponential
#print quot.rec_on
universes u v
variable {α : Sort u}
variable {r : α → α → Prop}
variable {β : quot r → Sort v}
open quot
local notation `⟦`:max a `⟧` := quot.mk r a
attribute [simp] mul_comm
inductive Id {α : Type} (a : α) : α → Type
| refl : Id a
inductive Id2 {α : Type} : α → α → Type
| refl : Π a : α, Id2 a a
inductive eq2 {α : Type} : α → α → Prop
| refl : ∀ a : α, eq2 a a
lemma eq2_iff_eq {α : Type} (a b : α) : eq2 a b ↔ a = b :=
⟨λ h, eq2.rec (λ _, rfl) h, λ h, eq.rec (eq2.refl _) h⟩
universe l
example : Π {α : Type} {a b : α} {C : Id a b → Sort l},
C (Id.refl a) → Π {a_1 : α} (n : Id a a_1), C a_1 n
#print Id.rec
#print eq.rec
#print Id2.rec
#print eq2.rec
local attribute [instance] classical.prop_decidable
example (α β : Type*) : ((α → β) → α) → α :=
if h : nonempty α then λ _, classical.choice h
else (λ f, f (λ a, (h ⟨a⟩).elim))
noncomputable example (α : Type*) : α ⊕ (α → empty) :=
if h : nonempty α then sum.inl (classical.choice h)
else sum.inr (λ a, (h ⟨a⟩).elim)
#print quot.ind
#print quot.rec
#print quot.lift
example : ∀ {α : Sort u} {r : α → α → Prop} {β : quot r → Prop},
(∀ (a : α), β (mk r a)) → ∀ (q : quot r), β q :=
λ α r β f q, quot.rec f (λ _ _ _, rfl) q
set_option pp.proofs true
example : Π {α : Sort u} {r : α → α → Prop} {β : Sort v} (f : α → β),
(∀ (a b : α), r a b → f a = f b) → quot r → β := λ α r β f h q,
@quot.rec α r (λ _, β) f
(λ a b hab, eq_of_heq (eq_rec_heq _ begin end))
protected lemma lift_indep_pr1
(f : Π a, β ⟦a⟧) (h : ∀ (a b : α) (p : r a b), (eq.rec (f a) (sound p) : β ⟦b⟧) = f b)
(q : quot r) : (lift (quot.indep f) (quot.indep_coherent f h) q).1 = q :=
quot.ind (by)
#exit
import analysis.topology.continuity data.zmod.basic
universe u
class t2_space1 (α : Type u) [topological_space α] : Prop :=
(t2 : ∀x y, x ≠ y → ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅)
class t2_space2 (α : Type u) [topological_space α] : Prop :=
(t2 : ∀x y, (∀u v : set α, is_open u → is_open v → x ∈ u → y ∈ v → ∃ r, r ∈ u ∩ v) → x = y)
import data.fintype
open equiv
instance thing {α β : Type*} [group α] [group β] [fintype α] [decidable_eq β] :
decidable_pred (@is_group_hom α β _ _) :=
λ f, decidable_of_iff (∀ x y, f (x * y) = f x * f y)
⟨λ h, ⟨h⟩, λ ⟨h⟩, h⟩
lemma h : ¬is_group_hom ((^3) : perm (fin 4) → perm (fin 4)) := dec_trivial
#print fintype.equiv_fin
#eval list.find (λ x : perm (fin 4) × perm (fin 4),
x.1 ^ 3 * x.2 ^ 3 ≠ (x.1 * x.2) ^ 3) (quot.unquot
(finset.univ : finset (perm (fin 4) × perm (fin 4))).1)
#print h
#exit
class is_rat (x : ℝ) :=
(val : ℚ)
(val_eq : (val : ℝ) = x)
variables (x y : ℝ) [is_rat x] [is_rat y]
noncomputable theory
instance : is_rat (x + y) := ⟨is_rat.val x + is_rat.val y, by simp [is_rat.val_eq]⟩
instance : is_rat (x * y) := ⟨is_rat.val x * is_rat.val y, by simp [is_rat.val_eq]⟩
instance : is_rat (-x) := ⟨-is_rat.val x, by simp [is_rat.val_eq]⟩
instance : is_rat (x - y) := ⟨is_rat.val x - is_rat.val y, by simp [is_rat.val_eq]⟩
instance : is_rat (x / y) := ⟨is_rat.val x / is_rat.val y, by simp [is_rat.val_eq]⟩
instance : is_rat (x⁻¹) := ⟨(is_rat.val x)⁻¹, by simp [is_rat.val_eq]⟩
instance zero_is_rat : is_rat 0 := ⟨0, by simp [rat.cast_zero]⟩
instance one_is_rat : is_rat 1 := ⟨1, by simp⟩
instance : is_rat (bit0 x) := by unfold bit0; apply_instance
instance : is_rat (bit1 x) := by unfold bit1; apply_instance
instance i2 : decidable (x = y) :=
by rw [← is_rat.val_eq x, ← is_rat.val_eq y, rat.cast_inj]; apply_instance
instance i3 : decidable (x ≤ y) :=
by rw [← is_rat.val_eq x, ← is_rat.val_eq y, rat.cast_le]; apply_instance
instance i4 : decidable (x < y) :=
by rw [← is_rat.val_eq x, ← is_rat.val_eq y, rat.cast_lt]; apply_instance
lemma is_rat.val_inj {x y : ℝ} [is_rat x] [is_rat y] (h : is_rat.val x = is_rat.val y) : x = y :=
(is_rat.val_eq x).symm.trans (eq.trans (rat.cast_inj.2 h) (is_rat.val_eq y))
a ^ 2 + 3 * a - 1 = 0 ↔ (X ^ 2 + 3 * X - 1).eval a = 0
set_option profiler true
set_option class.instance_max_depth 100
instance i5 : is_rat ((5 : ℝ) / 4) := by apply_instance
#print as_true
#eval ( (5 : ℝ) * 4 = 10 * 2 : bool)
example : (5 : ℚ) / 2 = 10 / 4 := rfl
lemma l1 : (5 : ℝ) / 2 = 10 / 4 := is_rat.val_inj rfl
#print l1
#print l2
#exit
#exit
#print expr
open expr level
#print level
meta def level.repr : level → string
| zero := "0"
| (succ l) := level.repr l ++ "+1"
| (max a b) := "max " ++ a.repr ++ " " ++ b.repr
| (imax a b) := "imax " ++ a.repr ++ " " ++ b.repr
| (param a) := "param " ++ a.to_string
| (mvar a) := "mvar " ++ a.to_string
meta instance : has_repr level := ⟨level.repr⟩
meta def expr.to_string' : expr → string
| (var a) := "var (" ++ repr a ++")"
| (sort a) := "sort (" ++ repr a ++")"
| (const a b) := "const (" ++ a.to_string ++ ") (" ++ repr b ++")"
| (expr.mvar a b c) := "mvar (" ++ a.to_string ++ ") (" ++ b.to_string ++ ")"
| (local_const a b c d) := "local_const (" ++ a.to_string ++ ") (" ++ b.to_string ++ ") (" ++
expr.to_string' d ++")"
| (pi a b c d) := "pi (" ++ a.to_string ++") (" ++ expr.to_string' c ++") (" ++ expr.to_string' d ++")"
| (lam a b c d) := "lam (" ++ a.to_string ++ ") (" ++ expr.to_string' c ++ ") (" ++ expr.to_string' d ++")"
| (app a b) := "app (" ++ expr.to_string' a ++ ") (" ++ expr.to_string b ++ ")"
| _ := "aargh"
def list.nil' : Π (α : Type), list α := @list.nil
def f : ℕ → ℕ := id
meta def x : tactic unit :=
do t ← tactic.infer_type `(f),
tactic.trace (expr.to_string' t), tactic.skip
#eval (format.compose (format.of_string "a") (format.of_string "b")).to_string
#print expr.to_raw_fmt
#eval (`(fin) : expr).to_raw_fmt.to_string
#eval expr.to_string' `(fin)
#exit
import data.equiv.encodable algebra.group_power
#print encodable
-- #eval encodable.choose (show ∃ x : (ℤ × ℕ), x.1 ^ 2 + 615 = 2 ^ x.2, from ⟨(59, 12), rfl⟩)
#print tactic.interactive.rw
#print tactic.transparency
example : 2 = 1 + 1 := by tactic.reflexivity tactic.transparency.none
#print tactic.interactive.refl
example : 2 = list.sum [2] := by tactic.reflexivity tactic.transparency.semireducible
#exit
import data.polynomial
open polynomial
#eval (X ^ 2 + 3 * X - 4 : polynomial ℤ).comp (X ^ 3 - X)
example : (@with_top.add_monoid ℕ _) = (@add_comm_monoid.to_add_monoid (with_top ℕ) _) := rfl
variables {α β γ δ : Type} {f : α → β}
#check function.comp (@function.comp ℕ _ _) (@function.comp ℕ ℕ (ℕ → ℕ))
#check
#print infer_instance
@[derive decidable_eq] inductive fml
| atom (i : ℕ)
| imp (a b : fml)
| not (a : fml)
open fml
infixr ` →' `:50 := imp -- right associative
prefix `¬' `:51 := fml.not
inductive prf : fml → Type
| axk {p q} : prf (p →' q →' p)
| axs {p q r} : prf $ (p →' q →' r) →' (p →' q) →' (p →' r)
| axX {p q} : prf $ ((¬' q) →' (¬' p)) →' p →' q
| mp {p q} : prf p → prf (p →' q) → prf q
instance (p): has_sizeof (prf p) := by apply_instance
open prf
meta def length {f : fml} (t : prf f) : ℕ :=
prf.rec_on t (λ _ _, 1) (λ _ _ _, 1) (λ _ _, 1) (λ _ _ _ _, (+))
instance (p q : fml) : has_coe_to_fun (prf (p →' q)) :=
{ F := λ x, prf p → prf q,
coe := λ x y, mp y x }
lemma imp_self' (p : fml) : prf (p →' p) :=
mp (@axk p p) (mp axk axs)
lemma imp_comm {p q r : fml} (h : prf (p →' q →' r)) : prf (q →' p →' r) :=
mp axk (mp (mp (mp h axs) axk) (@axs _ (p →' q) _))
lemma imp_of_true (p : fml) {q : fml} (h : prf q) : prf (p →' q) :=
mp h axk
namespace prf
prefix `⊢ `:30 := prf
def mp' {p q} (h1 : ⊢ p →' q) (h2 : ⊢ p) : ⊢ q := mp h2 h1
def a1i {p q} : ⊢ p → ⊢ q →' p := mp' axk
def a2i {p q r} : ⊢ p →' q →' r → ⊢ (p →' q) →' p →' r := mp' axs
def con4i {p q} : ⊢ ¬' p →' ¬' q → ⊢ q →' p := mp' axX
def mpd {p q r} (h : ⊢ p →' q →' r) : ⊢ p →' q → ⊢ p →' r := mp' (a2i h)
def syl {p q r} (h1 : ⊢ p →' q) (h2 : ⊢ q →' r) : ⊢ p →' r := mpd (a1i h2) h1
def id {p} : ⊢ p →' p := mpd axk (@axk p p)
def a1d {p q r} (h : ⊢ p →' q) : ⊢ p →' r →' q := syl h axk
def com12 {p q r} (h : ⊢ p →' q →' r) : ⊢ q →' p →' r := syl (a1d id) (a2i h)
def con4d {p q r} (h : ⊢ p →' ¬' q →' ¬' r) : ⊢ p →' r →' q := syl h axX
def absurd {p q} : ⊢ ¬' p →' p →' q := con4d axk
def imidm {p q} (h : ⊢ p →' p →' q) : ⊢ p →' q := mpd h id
def contra {p} : ⊢ (¬' p →' p) →' p := imidm (con4d (a2i absurd))
def notnot2 {p} : ⊢ ¬' ¬' p →' p := syl absurd contra
def mpdd {p q r s} (h : ⊢ p →' q →' r →' s) : ⊢ p →' q →' r → ⊢ p →' q →' s := mpd (syl h axs)
def syld {p q r s} (h1 : ⊢ p →' q →' r) (h2 : ⊢ p →' r →' s) : ⊢ p →' q →' s := mpdd (a1d h2) h1
def con2d {p q r} (h1 : ⊢ p →' q →' ¬' r) : ⊢ p →' r →' ¬' q := con4d (syld (a1i notnot2) h1)
def con2i {p q} (h1 : ⊢ p →' ¬' q) : ⊢ q →' ¬' p := con4i (syl notnot2 h1)
def notnot1 {p} : ⊢ p →' ¬' ¬' p := con2i id
#eval length (@notnot1 (atom 0))
lemma notnot1' {p} : ⊢ p →' ¬' ¬' p :=
mp (mp (mp (mp axk (mp (mp axX axk) axs))
(mp (mp (mp (mp axk (mp axk axs))
(mp (mp (mp (mp axk (mp (mp axX axk) axs)) axs) (mp (mp axX axk) axs)) axs)) axk) axs))
(mp (mp (mp axk (mp axk axs)) axk) axs)) axX
-- @mp ((¬' ¬' ¬' p) →' ¬' p) (p →' ¬' ¬' p)
-- (@mp ((¬' ¬' ¬' p) →' (¬' p) →' (¬' p) →' ¬' p) ((¬' ¬' ¬' p) →' ¬' p)
-- (@mp ((¬' p) →' (¬' p) →' ¬' p) ((¬' ¬' ¬' p) →' (¬' p) →' (¬' p) →' ¬' p)
-- (@axk (¬' p) (¬' p))
-- (@axk ((¬' p) →' (¬' p) →' ¬' p) (¬' ¬' ¬' p)))
-- (@mp ((¬' ¬' ¬' p) →' ((¬' p) →' (¬' p) →' ¬' p) →' ¬' p)
-- (((¬' ¬' ¬' p) →' (¬' p) →' (¬' p) →' ¬' p) →' (¬' ¬' ¬' p) →' ¬' p)
-- (@mp ((¬' ¬' ¬' p) →' (¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p)
-- ((¬' ¬' ¬' p) →' ((¬' p) →' (¬' p) →' ¬' p) →' ¬' p)
-- (@mp ((¬' ¬' ¬' p) →' (¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p)
-- ((¬' ¬' ¬' p) →' (¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p)
-- (@mp ((¬' ¬' ¬' p) →' ¬' ¬' ¬' p)
-- ((¬' ¬' ¬' p) →' (¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p)
-- (@mp ((¬' ¬' ¬' p) →' (¬' ¬' ¬' p) →' ¬' ¬' ¬' p) ((¬' ¬' ¬' p) →' ¬' ¬' ¬' p)
-- (@axk (¬' ¬' ¬' p) (¬' ¬' ¬' p))
-- (@mp ((¬' ¬' ¬' p) →' ((¬' ¬' ¬' p) →' ¬' ¬' ¬' p) →' ¬' ¬' ¬' p)
-- (((¬' ¬' ¬' p) →' (¬' ¬' ¬' p) →' ¬' ¬' ¬' p) →'
-- (¬' ¬' ¬' p) →' ¬' ¬' ¬' p)
-- (@axk (¬' ¬' ¬' p) ((¬' ¬' ¬' p) →' ¬' ¬' ¬' p))
-- (@axs (¬' ¬' ¬' p) ((¬' ¬' ¬' p) →' ¬' ¬' ¬' p) (¬' ¬' ¬' p))))
-- (@mp
-- ((¬' ¬' ¬' p) →'
-- (¬' ¬' ¬' p) →' (¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p)
-- (((¬' ¬' ¬' p) →' ¬' ¬' ¬' p) →'
-- (¬' ¬' ¬' p) →' (¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p)
-- (@mp ((¬' ¬' ¬' p) →' (¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p)
-- ((¬' ¬' ¬' p) →'
-- (¬' ¬' ¬' p) →' (¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p)
-- (@axk (¬' ¬' ¬' p) (¬' ¬' (¬' p) →' (¬' p) →' ¬' p))
-- (@axk ((¬' ¬' ¬' p) →' (¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p)
-- (¬' ¬' ¬' p)))
-- (@axs (¬' ¬' ¬' p) (¬' ¬' ¬' p)
-- ((¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p))))
-- (@mp
-- ((¬' ¬' ¬' p) →'
-- ((¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p) →'
-- (¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p)
-- (((¬' ¬' ¬' p) →' (¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p) →'
-- (¬' ¬' ¬' p) →' (¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p)
-- (@mp
-- (((¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p) →'
-- (¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p)
-- ((¬' ¬' ¬' p) →'
-- ((¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p) →'
-- (¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p)
-- (@axX (¬' ¬' p) (¬' (¬' p) →' (¬' p) →' ¬' p))
-- (@axk
-- (((¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p) →'
-- (¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p)
-- (¬' ¬' ¬' p)))
-- (@axs (¬' ¬' ¬' p) ((¬' ¬' (¬' p) →' (¬' p) →' ¬' p) →' ¬' ¬' ¬' p)
-- ((¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p))))
-- (@mp
-- ((¬' ¬' ¬' p) →'
-- ((¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p) →'
-- ((¬' p) →' (¬' p) →' ¬' p) →' ¬' p)
-- (((¬' ¬' ¬' p) →' (¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p) →'
-- (¬' ¬' ¬' p) →' ((¬' p) →' (¬' p) →' ¬' p) →' ¬' p)
-- (@mp
-- (((¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p) →'
-- ((¬' p) →' (¬' p) →' ¬' p) →' ¬' p)
-- ((¬' ¬' ¬' p) →'
-- ((¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p) →'
-- ((¬' p) →' (¬' p) →' ¬' p) →' ¬' p)
-- (@axX ((¬' p) →' (¬' p) →' ¬' p) (¬' p))
-- (@axk
-- (((¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p) →'
-- ((¬' p) →' (¬' p) →' ¬' p) →' ¬' p)
-- (¬' ¬' ¬' p)))
-- (@axs (¬' ¬' ¬' p) ((¬' ¬' p) →' ¬' (¬' p) →' (¬' p) →' ¬' p)
-- (((¬' p) →' (¬' p) →' ¬' p) →' ¬' p))))
-- (@axs (¬' ¬' ¬' p) ((¬' p) →' (¬' p) →' ¬' p) (¬' p))))
-- (@axX p (¬' ¬' p))
-- set_option pp.implicit true
#print not_not_p_of_p
-- /-
-- example usage:
-- lemma p_of_p_of_p_of_q (p q : fml) : prf $ (p →' q) →' (p →' p) :=
-- begin
-- apply mp (p →' q →' p) ((p →' q) →' p →' p) (axk p q),
-- exact axs p q p
-- end
-- -/
-- theorem Q6b (p : fml) : prf $ p →' ¬' ¬' p := sorry
namespace prop_logic
-- infixr ` →' `:50 := imp
-- local notation ` ¬' ` := fml.not
infixr ` →' `:50 := imp -- right associative
prefix `¬' `:51 := fml.not
--CAN I MAKE THIS A FUNCTION INTO PROP INSTEAD OF TYPE????
-- inductive thm : fml → Type
-- | axk (p q) : thm (p →' q →' p)
-- | axs (p q r) : thm $ (p →' q →' r) →' (p →' q) →' (p →' r)
-- | axn (p q) : thm $ ((¬' q) →' (¬' p)) →' p →' q
-- | mp {p q} : thm p → thm (p →' q) → thm q
-- open thm
lemma p_of_p (p : fml) : prf (p →' p) :=
mp (@axk p p) (mp axk axs)
inductive consequence (G : list fml) : fml → Type
| axk (p q) : consequence (p →' q →' p)
| axs (p q r) : consequence $ (p →' q →' r) →' (p →' q) →' (p →' r)
| axn (p q) : consequence $ ((¬'q) →' (¬'p)) →' p →' q
| mp (p q) : consequence p → consequence (p →' q) → consequence q
| of_G (g ∈ G) : consequence g
lemma consequence_of_thm (f : fml) (H : prf f) (G : list fml) : consequence G f :=
begin
induction H,
exact consequence.axk G H_p H_q,
exact consequence.axs G H_p H_q H_r,
exact consequence.axn G H_p H_q,
exact consequence.mp H_p H_q H_ih_a H_ih_a_1,
end
lemma thm_of_consequence_null (f : fml) (H : consequence [] f) : prf f :=
begin
induction H,
exact @axk H_p H_q,
exact @axs H_p H_q H_r,
exact @axX H_p H_q,
exact mp H_ih_a H_ih_a_1,
exact false.elim (list.not_mem_nil H_g H_H),
end
theorem deduction (G : list fml) (p q : fml) (H : consequence (p :: G) q) : consequence G (p →' q) :=
begin
induction H,
have H1 := consequence.axk G H_p H_q,
have H2 := consequence.axk G (H_p →' H_q →' H_p) p,
exact consequence.mp _ _ H1 H2,
have H6 := consequence.axs G H_p H_q H_r,
have H7 := consequence.axk G ((H_p →' H_q →' H_r) →' (H_p →' H_q) →' H_p →' H_r) p,
exact consequence.mp _ _ H6 H7,
have H8 := consequence.axn G H_p H_q,
have H9 := consequence.axk G (((¬' H_q) →' ¬' H_p) →' H_p →' H_q) p,
exact consequence.mp _ _ H8 H9,
have H3 := consequence.axs G p H_p H_q,
have H4 := consequence.mp _ _ H_ih_a_1 H3,
exact consequence.mp _ _ H_ih_a H4,
rw list.mem_cons_iff at H_H,
exact if h : H_g ∈ G then
begin
have H51 := consequence.of_G H_g h,
have H52 := consequence.axk G H_g p,
exact consequence.mp _ _ H51 H52,
end else
begin
have h := H_H.resolve_right h,
rw h,
exact consequence_of_thm _ (p_of_p p) G,
end
end
lemma part1 (p : fml) : consequence [¬' (¬' p)] p :=
begin
have H1 := consequence.axk [¬' (¬' p)] p p,
have H2 := consequence.axk [¬' (¬' p)] (¬' (¬' p)) (¬' (¬' (p →' p →' p))),
have H3 := consequence.of_G (¬' (¬' p)) (list.mem_singleton.2 rfl),
have H4 := consequence.mp _ _ H3 H2,
have H5 := consequence.axn [¬' (¬' p)] (¬' p) (¬' (p →' p →' p)),
have H6 := consequence.mp _ _ H4 H5,
have H7 := consequence.axn [¬' (¬' p)] (p →' p →' p) p,
have H8 := consequence.mp _ _ H6 H7,
exact consequence.mp _ _ H1 H8,
end
lemma part1' (p : fml) : prf (¬' ¬' p →' p) :=
begin
have H1 := @axk p p,
have H2 := @axk (¬' ¬' p) (¬' ¬' (p →' p →' p)),
have H3 := imp_self' (¬' ¬' p),
have H4 := mp H3 H2,
end
lemma p_of_not_not_p (p : fml) : thm ((¬' (¬' p)) →' p) :=
begin
have H1 := deduction [] (¬' (¬' p)) p,
have H2 := H1 (part1 p),
exact thm_of_consequence_null ((¬' (¬' p)) →' p) H2,
end
theorem not_not_p_of_p (p : fml) : thm (p →' (¬' (¬' p))) :=
begin
have H1 := thm.axn p (¬' (¬' p)),
have H2 := p_of_not_not_p (¬' p),
exact thm.mp H2 H1,
end
set_option pp.implicit true
#reduce not_not_p_of_p
theorem not_not_p_of_p' (p : fml) : thm (p →' (¬' (¬' p))) :=
thm.mp
(thm.mp (thm.mp (thm.axk (¬' p) (¬' p)) (thm.axk (¬' p →' ¬' p →' ¬' p) (¬' (¬' (¬' p)))))
(thm.mp
(thm.mp
(thm.mp
(thm.mp
(thm.mp (thm.axk (¬' (¬' (¬' p))) (¬' (¬' (¬' p))))
(thm.mp (thm.axk (¬' (¬' (¬' p))) (¬' (¬' (¬' p)) →' ¬' (¬' (¬' p))))
(thm.axs (¬' (¬' (¬' p))) (¬' (¬' (¬' p)) →' ¬' (¬' (¬' p))) (¬' (¬' (¬' p))))))
(thm.mp
(thm.mp (thm.axk (¬' (¬' (¬' p))) (¬' (¬' (¬' p →' ¬' p →' ¬' p))))
(thm.axk
(¬' (¬' (¬' p)) →' ¬' (¬' (¬' p →' ¬' p →' ¬' p)) →' ¬' (¬' (¬' p)))
(¬' (¬' (¬' p)))))
(thm.axs (¬' (¬' (¬' p))) (¬' (¬' (¬' p)))
(¬' (¬' (¬' p →' ¬' p →' ¬' p)) →' ¬' (¬' (¬' p))))))
(thm.mp
(thm.mp (thm.axn (¬' (¬' p)) (¬' (¬' p →' ¬' p →' ¬' p)))
(thm.axk
((¬' (¬' (¬' p →' ¬' p →' ¬' p)) →' ¬' (¬' (¬' p))) →'
¬' (¬' p) →' ¬' (¬' p →' ¬' p →' ¬' p))
(¬' (¬' (¬' p)))))
(thm.axs (¬' (¬' (¬' p))) (¬' (¬' (¬' p →' ¬' p →' ¬' p)) →' ¬' (¬' (¬' p)))
(¬' (¬' p) →' ¬' (¬' p →' ¬' p →' ¬' p)))))
(thm.mp
(thm.mp (thm.axn (¬' p →' ¬' p →' ¬' p) (¬' p))
(thm.axk
((¬' (¬' p) →' ¬' (¬' p →' ¬' p →' ¬' p)) →'
(¬' p →' ¬' p →' ¬' p) →' ¬' p)
(¬' (¬' (¬' p)))))
(thm.axs (¬' (¬' (¬' p))) (¬' (¬' p) →' ¬' (¬' p →' ¬' p →' ¬' p))
((¬' p →' ¬' p →' ¬' p) →' ¬' p))))
(thm.axs (¬' (¬' (¬' p))) (¬' p →' ¬' p →' ¬' p) (¬' p))))
(thm.axn p (¬' (¬' p)))
#exit
@[derive decidable_eq] inductive fml
| atom (i : ℕ)
| imp (a b : fml)
| not (a : fml)
open fml
infixr ` →' `:50 := imp -- right associative
prefix `¬' `:40 := fml.not
inductive prf : fml → Type
| axk (p q) : prf (p →' q →' p)
| axs (p q r) : prf $ (p →' q →' r) →' (p →' q) →' (p →' r)
| axX (p q) : prf $ ((¬' q) →' (¬' p)) →' p →' q
| mp {p q} : prf p → prf (p →' q) → prf q
#print prf.rec
open prf
/-
-- example usage:
lemma p_of_p_of_p_of_q (p q : fml) : prf $ (p →' q) →' (p →' p) :=
begin
apply mp (p →' q →' p) ((p →' q) →' p →' p) (axk p q),
exact axs p q p
end
-/
def is_not : fml → Prop :=
λ f, ∃ g : fml, f = ¬' g
#print prf.rec_on
theorem Q6b (f : fml) (p : prf f) : is_not f → false :=
begin
induction p,
{admit},
{admit},
{admit},
{
clear p_ih_a_1,
}
end
#print Q6b
theorem Q6b : ∀ p : fml, ¬(prf $ p →' ¬' ¬' p) :=
begin
cases p,
end
#exit
import data.fintype
section
@[derive decidable_eq] inductive cbool
| t : cbool
| f : cbool
| neither : cbool
open cbool
instance : fintype cbool := ⟨{t,f,neither}, λ x, by cases x; simp⟩
variables (imp : cbool → cbool → cbool) (n : cbool → cbool)
(a1 : ∀ p q, imp p (imp q p) = t)
(a2 : ∀ p q, imp (imp (n q) (n p)) (imp p q) = t)
(a3 : ∀ p q r, imp (imp p (imp q r)) (imp (imp p q) (imp p r)) = t)
include a1 a2 a3
set_option class.instance_max_depth 50
-- example : ∀ p, imp p (n (n p)) = t :=
-- by revert imp n; exact dec_trivial
end
open finset
instance inst1 : has_repr (bool → bool) :=
⟨λ f, "(tt ↦ " ++ repr (f tt) ++ ", ff ↦ " ++ repr (f ff) ++")"⟩
instance inst2 : has_repr (bool → bool → bool) :=
⟨λ f, "(tt ↦ " ++ repr (f tt) ++ ", ff ↦ " ++ repr (f ff)++")"⟩
#eval band
#eval (((univ : finset ((bool → bool → bool) × (bool → bool))).filter
(λ x : (bool → bool → bool) × (bool → bool),
(∀ p q, x.1 p (x.1 q p) = tt) ∧
(∀ p q, x.1 (x.1 (x.2 q) (x.2 p)) (x.1 p q) = tt) ∧
(∀ p q r, x.1 (x.1 p (x.1 q r)) (x.1 (x.1 p q) (x.1 p r)) = tt)))
#exit
import ring_theory.ideals
variables {p : Prop} {α : Type*} [comm_ring α]
instance : is_ideal {x : α | x = 0 ∨ p} :=
{ to_is_submodule :=
⟨or.inl rfl,
λ x y hx hy, hx.elim (λ hx0, by rw [hx0, zero_add]; exact hy) or.inr,
λ c x hx, hx.elim (λ hx0, by rw [hx0, smul_eq_mul, mul_zero]; exact or.inl rfl) or.inr⟩ }
def h : is_ideal {x : ℤ | x = 0 ∨ p} := by apply_instance
set_option pp.implicit true
#print axioms set_of.is_ideal
#print axioms nonzero_comm_ring.to_comm_ring
#exit
import algebra.pi_instances
variables {G₁ G₂ G₃ : Type} [group G₁] [group G₂] [group G₃]
def isom : {f : (G₁ × (G₂ × G₃)) ≃ ((G₁ × G₂) × G₃) // is_group_hom f} :=
⟨⟨λ ⟨a, ⟨b, c⟩⟩, ⟨⟨a, b⟩, c⟩, λ ⟨⟨a, b⟩, c⟩, ⟨a, b, c⟩, λ ⟨_, _, _⟩, rfl, λ ⟨⟨_, _⟩, _⟩, rfl⟩, ⟨λ ⟨_, _, _⟩ ⟨_, _, _⟩, rfl⟩⟩
#exit
import data.equiv.denumerable
open denumerable
#eval of_nat (ℤ × ℤ) 145903
#exit
import data.polynomial ring_theory.ideals
open polynomial euclidean_domain
def gaussian_integers := @quotient_ring.quotient (polynomial ℤ) _
(span ({(X : polynomial ℤ) ^ 2 + 1} : set (polynomial ℤ)))
(is_ideal.span ({X ^ 2 + 1} : set (polynomial ℤ)))
instance : decidable_eq gaussian_integers :=
λ x y, begin end
#eval gcd_a (-5 : ℤ) (-11)
local notation `f` := ((X : polynomial ℚ) ^ 2 * C (53/96) - 22 * X - 141)
local notation `g` := (23 * (X : polynomial ℚ) ^ 3 - 44 * X^2 + 3 * X - 2)
#eval (5 / 4 : ℚ)
#eval gcd_a f g * C (coeff (gcd f g) 0)⁻¹
#eval gcd f g
#eval (f * (gcd_a f g * C (coeff (gcd f g) 0)⁻¹) - 1) % g
#exit
import data.nat.choose data.nat.prime
open nat
lemma prime_dvd_fact_iff : ∀ {n p : ℕ} (hp : prime p), p ∣ n.fact ↔ p ≤ n
| 0 p hp := by simp [nat.pos_iff_ne_zero.1 hp.pos, ne.symm (ne_of_lt hp.gt_one)]
| (n+1) p hp := begin
rw [fact_succ, hp.dvd_mul, prime_dvd_fact_iff hp],
exact ⟨λ h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,
λ h, (lt_or_eq_of_le h).elim (or.inr ∘ le_of_lt_succ) (λ h, by simp [h])⟩
end
example {p k : ℕ} (hk : 0 < k) (hkp : k < p) (hp : prime p) : p ∣ choose p k :=
(hp.dvd_mul.1 (show p ∣ choose p k * (fact k * fact (p - k)),
by rw [← mul_assoc, choose_mul_fact_mul_fact (le_of_lt hkp)];
exact dvd_fact hp.pos (le_refl _))).resolve_right
(by rw [hp.dvd_mul, prime_dvd_fact_iff hp,
prime_dvd_fact_iff hp, not_or_distrib, not_le, not_le];
exact ⟨hkp, nat.sub_lt_self hp.pos hk⟩)
#exit
#print eq
inductive Id {α : Type} (x : α) : α → Type
| refl : Id x
lemma T1 {α : Type} (x y : α) (i j : Id x y) : i = j :=
by cases i; cases j; refl
#print T1
#reduce T1
lemma T2 {α : Type} (x y : α) (i j : Id x y) : Id i j :=
begin cases i; cases j; constructor end
#print T2
#exit
import group_theory.quotient_group analysis.topology.topological structures
instance {α : Type*} [topological_group α] (S : set α) [normal_subgroup S] :
topological_space (quotient_group.quotient S) := by apply_instance
#exit
import analysis.real tactic.linarith
open real filter
lemma IVT {f : ℝ → ℝ} {a b : ℝ} (hf : ∀ x, a ≤ x → x ≤ b → tendsto f (nhds x) (nhds (f x)))
(ha : f a ≤ 0) (hb : 0 ≤ f b) (hab : a ≤ b) : ∃ x : ℝ, a ≤ x ∧ x ≤ b ∧ f x = 0 :=
let x := Sup {x | f x ≤ 0 ∧ a ≤ x ∧ x ≤ b} in
have hx₁ : ∃ y, ∀ g ∈ {x | f x ≤ 0 ∧ a ≤ x ∧ x ≤ b}, g ≤ y := ⟨b, λ _ h, h.2.2⟩,
have hx₂ : ∃ y, y ∈ {x | f x ≤ 0 ∧ a ≤ x ∧ x ≤ b} := ⟨a, ha, le_refl _, hab⟩,
have hax : a ≤ x, from le_Sup _ hx₁ ⟨ha, le_refl _, hab⟩,
have hxb : x ≤ b, from (Sup_le _ hx₂ hx₁).2 (λ _ h, h.2.2),
⟨x, hax, hxb,
eq_of_forall_dist_le $ λ ε ε0,
let ⟨δ, hδ0, hδ⟩ := tendsto_nhds_of_metric.1 (hf _ hax hxb) ε ε0 in
(le_total 0 (f x)).elim
(λ h, le_of_not_gt $ λ hfε, begin
rw [dist_0_eq_abs, abs_of_nonneg h] at hfε,
refine mt (Sup_le {x | f x ≤ 0 ∧ a ≤ x ∧ x ≤ b} hx₂ hx₁).2
(not_le_of_gt (sub_lt_self x (half_pos hδ0)))
(λ g hg, le_of_not_gt
(λ hgδ, not_lt_of_ge hg.1
(lt_trans (sub_pos_of_lt hfε) (sub_lt_of_sub_lt
(lt_of_le_of_lt (le_abs_self _) _))))),
rw abs_sub,
exact hδ (abs_sub_lt_iff.2 ⟨lt_of_le_of_lt (sub_nonpos.2 (le_Sup _ hx₁ hg)) hδ0,
by simp only [x] at *; linarith⟩)
end)
(λ h, le_of_not_gt $ λ hfε, begin
rw [dist_0_eq_abs, abs_of_nonpos h] at hfε,
exact mt (le_Sup {x | f x ≤ 0 ∧ a ≤ x ∧ x ≤ b})
(λ h : ∀ k, k ∈ {x | f x ≤ 0 ∧ a ≤ x ∧ x ≤ b} → k ≤ x,
not_le_of_gt ((lt_add_iff_pos_left x).2 (half_pos hδ0))
(h _ ⟨le_trans (le_sub_iff_add_le.2 (le_trans (le_abs_self _)
(le_of_lt (hδ $ by rw [dist_eq, add_sub_cancel, abs_of_nonneg (le_of_lt (half_pos hδ0))];
exact half_lt_self hδ0))))
(le_of_lt (sub_neg_of_lt hfε)),
le_trans hax (le_of_lt ((lt_add_iff_pos_left _).2 (half_pos hδ0))),
le_of_not_gt (λ hδy, not_lt_of_ge hb (lt_of_le_of_lt (show f b ≤ f b - f x - ε, by linarith)
(sub_neg_of_lt (lt_of_le_of_lt (le_abs_self _)
(@hδ b (abs_sub_lt_iff.2 ⟨by simp only [x] at *; linarith,
by linarith⟩))))))⟩))
hx₁
end)⟩
#print IVT
#exit
import tactic.norm_num tactic.ring tactic.linarith
lemma h (x y z : ℤ) (h₁ : 0 ≤ x) (h₂ : y + x ≤ z) : y ≤ z :=
by linarith
#print h
open nat
lemma prime_seven : prime 7 := by norm_num
#print prime_seven
lemma ring_thing (x y z : ℤ) : x ^ 2 - x * (y - z) - z * x = x * (x - y) := by ring
#print ring_thing
example (x : ℤ) (h : ∃ y, x = y ∧ x ^ 2 = 2) :
open nat zmodp
lemma p7 : prime 7 := by norm_num
theorem foo (x y : zmodp 7 p7) (h : x ≠ y) : (x - y) ^ 6 = 1 :=
fermat_little p7 (sub_ne_zero.2 h)
#exit
import data.polynomial
import linear_algebra.multivariate_polynomial
import ring_theory.associated
universe u
namespace algebraic_closure
variables (k : Type u) [field k] [decidable_eq k]
def irred : set (polynomial k) :=
{ p | irreducible p }
def big_ring : Type u :=
mv_polynomial (irred k) k
instance : comm_ring (big_ring k) :=
mv_polynomial.comm_ring
instance : module (big_ring k) (big_ring k) := by apply_instance
instance : decidable_eq (big_ring k) := by apply_instance
instance foo : decidable_eq (irred k) := by apply_instance
set_option profiler true
def big_ideal : set (big_ring k) :=
span (⋃ p : irred k, { polynomial.eval₂ (@mv_polynomial.C k (irred k) _ _ _)
(@mv_polynomial.X k (irred k) _ _ _ p) p.1 })
#exit
import data.nat.basic
#print dlist
@[simp] lemma nat.strong_rec_on_beta {p : nat → Sort*} : ∀ (n : nat) (h : ∀ n, (∀ m, m < n → p m) → p n),
(nat.strong_rec_on n h : p n) = h n (λ m H, nat.strong_rec_on m h)
| 0 h := begin simp [nat.strong_rec_on, or.by_cases], congr, funext,
exact (nat.not_lt_zero _ h₁).elim, intros, end
#exit
meta def foo (n : ℕ) : option ℕ :=
do let m : ℕ :=
match n with
| 0 := 1
| (n+1) := by exact _match n + _match n
end,
return m
#print foo
#eval foo 4 -- some 16
-- begin
-- let m : ℕ :=
-- match n with
-- | 0 := 1
-- | (n+1) := _match n + _match n
-- end,
-- have h : m = 2 ^ n, by induction n;
-- simp [nat.mul_succ, nat.succ_mul, *, m, _example._match_1, nat.pow_succ] at *,
-- end
import set_theory.cardinal
#print list.zip_with
open cardinal
example (α : Type*) (S T : set α)
(HS : set.finite S) (HT : set.finite T)
(H : finset.card (set.finite.to_finset HS) ≤ finset.card (set.finite.to_finset HT)) :
cardinal.mk S ≤ cardinal.mk T :=
begin
haveI := classical.choice HS,
haveI := classical.choice HT,
rwa [fintype_card S, fintype_card T, nat_cast_le,
set.card_fintype_of_finset' (set.finite.to_finset HS),
set.card_fintype_of_finset' (set.finite.to_finset HT)];
simp
end
example (f g : ℕ → ℕ) : (∀ x : ℕ, f x = g x) → f ≈ g := id
#print funext
#exit
import data.nat.modeq tactic.find
example (p : ℕ) (nine : 2 ∣ p / 2) (thing11 : 3 + 4 * (p / 4) = p) : false :=
begin
rw [nat.dvd_iff_mod_eq_zero, ← nat.mod_mul_right_div_self,
← thing11, show 2 * 2 = 4, from rfl, nat.add_mul_mod_self_left] at nine,
contradiction
end
#exit
import data.list.sort data.string
meta def list_constant (e : expr) : rbtree name :=
e.fold (mk_rbtree name) $ λ e _ cs,
let n := e.const_name in
if e.is_constant
then cs.insert n
else cs
open declaration tactic
meta def const_in_def (n : name) : tactic (list name) :=
do d ← get_decl n,
match d with
| thm _ _ t v := return (list_constant v.get ∪ list_constant t)
| defn _ _ t v _ _ := return (list_constant v ∪ list_constant t)
| cnst _ _ t _ := return (list_constant t)
| ax _ _ t := return (list_constant t)
end
meta def const_in_def_trans_aux : list name × list (name × list name) →
tactic (list name × list (name × list name))
| ([], l₂) := pure ([], l₂)
| (l₁, l₂) :=
do l' ← l₁.mmap (λ n, do l ← const_in_def n, return (n, l)),
let l2 := l' ++ l₂,
const_in_def_trans_aux ((l'.map prod.snd).join.erase_dup.diff (l2.map prod.fst), l2)
meta def const_in_def_trans (n : name) : tactic unit :=
do l ← const_in_def_trans_aux ([n], []),
trace l.2.length,
trace (list.insertion_sort (≤) (l.2.map to_string)),
return ()
meta def list_all_consts : tactic (list name) :=
do e ← get_env,
let l : list name := environment.fold e []
(λ d l, match d with
| thm n _ _ _ := n :: l
| defn n _ _ _ _ _ := n :: l
| cnst n _ _ _ := n :: l
| ax n _ _ := n :: l end),
trace l,
trace l.length,
return l
meta def trans_def_all_aux : list name → rbmap name (rbtree name)
→ rbmap name (rbtree name) → option (rbmap name (rbtree name))
| [] m₁ m₂ := pure m₂
| (n::l₁) m₁ m₂ :=
do l₁ ← m₁.find n,
l₂ ← l₁.mmap m₁.find,
let l₃ := l₂.join,
if l₃ = l₁ then trans_def_all_aux l₁ (m₁.erase n)
else sorry
meta def trans_def_list (l : list name) : tactic unit :=
do
map ← l.mmap (λ n, do l' ← const_in_def n, return (n, l)),
m ← trans_def_all_aux [`prod.swap] (pure (rbmap.from_list map)),
let result := m.to_list,
trace (result.map (λ n, (n.1, n.2.length))),
return ()
meta def trans_def_list_all : tactic unit :=
do l ← list_all_consts,
trans_def_list l,
return ()
#eval const_in_def_trans `prod.swap
-- #eval trans_def_list_all
#exit
#print list.union
meta def const_in_def_trans_aux : Π (n : name), tactic (list name)
| n := do d ← get_decl n,
match d with
| thm _ _ t v := do
let v := v.get,
let l := list_constant v,
-- do m ← l.mmap const_in_def_trans_aux,
return (l).erase_dup
| defn _ _ t v _ _ := do
let l := list_constant v,
do m ← l.mmap const_in_def_trans_aux,
return (l).erase_dup
| d := pure []
end
meta def const_in_def_depth_aux : ℕ → name → list name → tactic (list name)
| 0 n p := pure []
| (m+1) n p :=
do d ← get_decl n,
match d with
| thm _ _ t v := do
let v := v.get,
let l := (list_constant v).diff p,
let q := p ++ l,
l' ← l.mmap (λ n, const_in_def_depth_aux m n q),
return (l ++ l'.bind id).erase_dup
| defn _ _ t v _ _ := do
let l := (list_constant v).diff p,
let q := p ++ l,
l' ← l.mmap (λ n, const_in_def_depth_aux m n q),
return (l ++ l'.bind id).erase_dup
| d := pure []
end
meta def const_in_def_depth_aux' : ℕ → Π n : name, tactic (list name)
| 0 n := pure []
| (m+1) n :=
do d ← get_decl n,
match d with
| thm _ _ t v := do
let v := v.get,
let l := list_constant v,
l' ← l.mmap (const_in_def_depth_aux' m),
return (l'.bind id ++ l).erase_dup
| defn _ _ t v _ _ := do
let l := list_constant v,
l' ← l.mmap (const_in_def_depth_aux' m),
return (l'.bind id ++ l).erase_dup
| d := pure []
end
meta def const_in_def_depth (m : ℕ) (n : name) : tactic unit :=
do l ← const_in_def_depth_aux m n [],
trace l.length,
trace l,
return ()
meta def const_in_def_depth' (m : ℕ) (n : name) : tactic unit :=
do l ← const_in_def_depth_aux' m n,
trace l.length,
trace l,
return ()
meta def const_in_def_trans (n : name) : tactic unit :=
do l ← const_in_def_trans_aux n,
trace l.length,
trace l,
return ()
set_option profiler true
-- #eval const_in_def_depth' 3 `polynomial.euclidean_domain
-- #eval const_in_def_depth 5 `polynomial.euclidean_domain
-- meta def const_in_def₂ (n : name) : tactic (list name) :=
-- do l ← const_in_def n,
-- m ← l.mmap const_in_def,
-- trace m,
-- return l
#print simp_config
#exit
data.zmod.basic data.polynomial tactic.norm_num data.rat.basic
instance h {p : ℕ} (hp : nat.prime p) : has_repr (zmodp p hp) := fin.has_repr _
open polynomial
#eval (11 * X ^ 20 + 7 * X ^ 9 + 12 * X + 11 :
polynomial ℚ) / (22 * X ^ 2 - 1)
#exit
import algebra.big_operators
open finset
lemma prod_involution (s : finset β) {f : β → α} :
∀ (g : Π a ∈ s, β)
(h₁ : ∀ a ha, f a * f (g a ha) = 1)
(h₂ : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
(h₃ : ∀ a ha, g a ha ∈ s)
(h₄ : ∀ a ha, g (g a ha) (h₃ a ha) = a),
s.prod f = 1 :=
by haveI := classical.dec_eq β;
haveI := classical.dec_eq α; exact
finset.strong_induction_on s
(λ s ih g h₁ h₂ h₃ h₄,
if hs : s = ∅ then hs.symm ▸ rfl
else let ⟨x, hx⟩ := exists_mem_of_ne_empty hs in
have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s,
from λ y hy, (mem_of_mem_erase (mem_of_mem_erase hy)),
have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y,
from λ x hx y hy h, by rw [← h₄ x hx, ← h₄ y hy]; simp [h],
have ih': (erase (erase s x) (g x hx)).prod f = (1 : α) :=
ih ((s.erase x).erase (g x hx))
⟨subset.trans (erase_subset _ _) (erase_subset _ _),
λ h, not_mem_erase (g x hx) (s.erase x) (h (h₃ x hx))⟩
(λ y hy, g y (hmem y hy))
(λ y hy, h₁ y (hmem y hy))
(λ y hy, h₂ y (hmem y hy))
(λ y hy, mem_erase.2 ⟨λ (h : g y _ = g x hx), by simpa [g_inj h] using hy,
mem_erase.2 ⟨λ (h : g y _ = x),
have y = g x hx, from h₄ y (hmem y hy) ▸ by simp [h],
by simpa [this] using hy, h₃ y (hmem y hy)⟩⟩)
(λ y hy, h₄ y (hmem y hy)),
if hx1 : f x = 1
then ih' ▸ eq.symm (prod_subset hmem
(λ y hy hy₁,
have y = x ∨ y = g x hx, by simp [hy] at hy₁; tauto,
this.elim (λ h, h.symm ▸ hx1)
(λ h, h₁ x hx ▸ h ▸ hx1.symm ▸ (one_mul _).symm)))
else by rw [← insert_erase hx, prod_insert (not_mem_erase _ _),
← insert_erase (mem_erase.2 ⟨h₂ x hx hx1, h₃ x hx⟩),
prod_insert (not_mem_erase _ _), ih', mul_one, h₁ x hx])
lemma prod_univ_units_finite_field {α : Type*} [fintype α] [field α] [decidable_eq α] : univ.prod (λ x, x) = (-1 : units α) :=
have h₁ : ∀ x : units α, x ∈ (univ.erase (-1 : units α)).erase 1 → x⁻¹ ∈ (univ.erase (-1 : units α)).erase 1,
from λ x, by rw [mem_erase, mem_erase, mem_erase, mem_erase, ne.def, ne.def, ne.def,
ne.def, inv_eq_iff_inv_eq, one_inv, inv_eq_iff_inv_eq]; simp; cc,
have h₂ : ∀ x : units α, x ∈ (univ.erase (-1 : units α)).erase 1 → x⁻¹ ≠ x,
from λ x, by rw [ne.def, units.inv_eq_self_iff]; finish,
calc univ.prod (λ x, x) = (insert (1 : units α) (insert (-1 : units α) ((univ.erase (-1 : units α)).erase 1))).prod (λ x, x) :
by congr; simp [finset.ext]; tauto
... = -((univ.erase (-1 : units α)).erase 1).prod (λ x, x) :
if h : (1 : units α) = -1
then by rw [insert_eq_of_mem, prod_insert]; simp *; cc
else by rw [prod_insert, prod_insert]; simp *
... = -1 : by rw [prod_finset_distinct_inv h₁ h₂]
#exit
import data.equiv.basic
variables {α : Type*} {β : Type*} [preorder α] [preorder β]
example (f : α ≃ β) (hf : ∀ a b, a ≤ b → f a ≤ f b)
(hf' : ∀ a b, a ≤ b → f.symm a ≤ f.symm b) : ∀ a b, a < b ↔ f a < f b :=
have ∀ a b, a ≤ b ↔ f a ≤ f b, from λ a b,
⟨hf a b, λ h, by rw [← equiv.inverse_apply_apply f a, ← equiv.inverse_apply_apply f b];
exact hf' (f a) (f b) h⟩,
λ a b, by simp [lt_iff_le_not_le, this]
#exit
import analysis.real
def g : topological_space ℝ := by apply_instance
theorem nonethm {t} : (none <|> none)=@none t := rfl
#exit
import data.nat.basic data.fintype.basic algebra.group_power
instance nat.decidable_bexists_lt (n : ℕ) (P : Π k < n, Prop)
[∀ k h, decidable (P k h)] : decidable (∃ k h, P k h) :=
decidable_of_iff (¬ ∀ k h, ¬ P k h) $ by simp [classical.not_forall]
instance nat.decidable_bexists_le (n : ℕ) (P : Π k ≤ n, Prop)
[∀ k h, decidable (P k h)] : decidable (∃ k h, P k h) :=
decidable_of_iff (∃ (k) (h : k < n.succ), P k (nat.le_of_lt_succ h))
⟨λ ⟨k, hk, h⟩, ⟨k, nat.le_of_lt_succ hk, h⟩,
λ ⟨k, hk, h⟩, ⟨k, nat.lt_succ_of_le hk, h⟩⟩
instance decidable_mul_self_nat (n : ℕ) : decidable (∃ k, k * k = n) :=
decidable_of_iff (∃ k ≤ n, k * k = n)
⟨λ ⟨k, h1, h2⟩, ⟨k, h2⟩, λ ⟨k, h1⟩, ⟨k, h1 ▸ nat.le_mul_self k, h1⟩⟩
instance decidable_sqr_nat (n : ℕ) : decidable (∃ k, k^2 = n) :=
decidable_of_iff (∃ k, k * k = n)
⟨λ ⟨k, h⟩, ⟨k, by rwa [nat.pow_two]⟩, λ ⟨k, h⟩, ⟨k, by rwa [nat.pow_two] at h⟩⟩
instance decidable_mul_self_int : Π (n : ℤ), decidable (∃ k, k * k = n)
| (int.of_nat n) := decidable_of_iff (∃ k, k * k = n)
⟨λ ⟨k, hk⟩, ⟨k, by rw [← int.coe_nat_mul, hk]; refl⟩,
λ ⟨k, hk⟩, ⟨int.nat_abs k, by rw [← int.nat_abs_mul, hk]; refl⟩⟩
| -[1+ n] := is_false $ λ ⟨k, h1⟩, not_lt_of_ge (mul_self_nonneg k) $
h1.symm ▸ int.neg_succ_of_nat_lt_zero n
instance decidable_sqr_int (n : ℤ) : decidable (∃ k, k^2 = n) :=
decidable_of_iff (∃ k, k * k = n)
⟨λ ⟨k, h⟩, ⟨k, by rwa [pow_two]⟩, λ ⟨k, h⟩, ⟨k, by rwa [pow_two] at h⟩⟩
theorem what_i_need: ¬ (∃ n : ℤ , n ^ 2 = 2 ) := dec_trivial
#exit
import data.polynomial data.rat.basic tactic.ring
open polynomial nat
def gcd' : ℕ → ℕ → ℕ
| 0 y := y
| (succ x) y := have y % succ x < succ x, from classical.choice ⟨mod_lt _ $ succ_pos _⟩,
gcd (y % succ x) (succ x)
set_option pp.proofs true
#reduce (classical.choice (show nonempty true, from ⟨trivial⟩))
#print list.foldr
#print char
#eval (X ^ 17 + 2 * X + 1 : polynomial ℚ) / (17 * X ^ 9 + - 21/17 * X ^ 14 - 5 * X ^ 4 * 5)
example : (-17/21 * X ^ 3 : polynomial ℚ) = sorry
#eval ((1/17 * X ^ 8 + -25/289 * X ^ 3 : polynomial ℚ) =
(C (1/17) * X ^ 8 + C (-25/289) * X ^ 3 : polynomial ℚ) : bool)
example : (1/17 * X ^ 8 + -25/289 * X ^ 3 : polynomial ℚ) =
(C (1/17) * X ^ 8 + C -25 X ^ 3 : polynomial ℚ) := begin
ℤ
end
example : (X ^ 2 + 2 * X + 1 : polynomial ℤ) %ₘ (X + 1) = 0 :=
(dvd_iff_mod_by_monic_eq_zero dec_trivial).2 ⟨X + 1, by ring⟩
#exit
import data.zmod
instance h (m : ℤ) : decidable (∃ n : ℤ, n ^ 2 = m) :=
decidable_of_iff (0 ≤ m ∧ m.nat_abs.sqrt ^ 2 = m.nat_abs)
⟨λ h, ⟨nat.sqrt m.nat_abs, by rw [← int.coe_nat_pow, h.2, int.nat_abs_of_nonneg h.1]⟩,
λ ⟨s, hs⟩, ⟨hs ▸ (pow_two_nonneg _), by rw [← hs, pow_two, int.nat_abs_mul, nat.sqrt_eq, nat.pow_two]⟩⟩
#eval (∄ n : ℤ, n ^ 2 = 2 : bool)
#print nat.gcd._main._pack
example : nat.gcd 4 5 = 1 := rfl
lemma two_not_square : ∄ n : ℤ, n ^ 2 = 2 := dec_trivial
example : ∄ n : ℤ, n ^ 2 = 2 :=
λ ⟨n, hn⟩, have h : ∀ n : zmod 3, n ^ 2 ≠ (2 : ℤ), from dec_trivial,
by have := h n; rw ← hn at this; simpa
example (d : ℤ) : d * d ≡ 0 [ZMOD 8] ∨ d * d ≡ 1 [ZMOD 8] ∨ d * d ≡ 4 [ZMOD 8] :=
have ∀ d : zmod 8, d * d = (0 : ℤ) ∨ d * d = (1 : ℤ) ∨ d * d = (4 : ℤ), from dec_trivial,
by have := this d;
rwa [← int.cast_mul, zmod.eq_iff_modeq_int, zmod.eq_iff_modeq_int, zmod.eq_iff_modeq_int] at this
example (a b : ℤ) (h : a ≡ b [ZMOD 8]) : a ^ 2 ≡ b ^ 2 [ZMOD 8] :=
by rw [pow_two, pow_two]; exact int.modeq.modeq_mul h h
example : ∀ a b : zmod 8, a = b → a ^ 2 = b ^ 2 := dec_trivial
open finset
def thing : ℕ → Type := λ n : ℕ,
well_founded.fix nat.lt_wf (λ (x) (ih : Π (y : ℕ), nat.lt y x → Type),
Π (m : fin x), ih m.1 m.2) n
lemma thing_eq : thing =
(λ n, (Π m : fin n, thing m.1)) :=
begin
funext,
rw [thing],
dsimp,
rw [well_founded.fix_eq]
end
instance : ∀ n : ℕ, fintype (thing n)
| 0 := ⟨finset.singleton (begin rw thing_eq, exact λ ⟨m, hm⟩, (nat.not_lt_zero _ hm).elim end),
λ x, mem_singleton.2 (funext $ λ ⟨m, hm⟩, (nat.not_lt_zero _ hm).elim)⟩
| (n+1) := begin
haveI : ∀ m : fin (n + 1), fintype (thing m.1) :=
λ m, have m.1 < n + 1, from m.2, thing.fintype m.1,
rw thing_eq,
apply_instance
end
#eval fintype.card (thing 4)
example (n : nat) : thing n = sorry :=
begin
rw thing_eq, rw thing_eq, rw thing_eq, rw thing_eq, rw thing_eq, rw thing_eq,
dsimp,
end
import data.int.basic
#print int.nat_abs_ne
#exit
class principal_ideal_domain (α : Type*) extends comm_ring α :=
(principal : ∀ (S : set α) [is_ideal S], ∃ a, S = {x | a ∣ x})
lemma prime_factors (n : ℕ) : ∃ l : list ℕ, (∀ p, p ∈ l → nat.prime p) ∧ l.prod = n :=
begin
end
#exit
class has_group_notation (G : Type) extends has_mul G, has_one G, has_inv G
class group' (G : Type) extends has_group_notation G :=
(mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c))
(one_mul : ∀ (a : G), 1 * a = a)
(mul_left_inv : ∀ (a : G), a⁻¹ * a = 1)
-- Lean 3.4.1 also uses mul_one : ∀ (a : G), a * 1 = a , but we'll see we can deduce it!
-- Note : this doesn't matter at all :-)
variables {G : Type} [group' G]
namespace group'
lemma mul_left_cancel : ∀ (a b c : G), a * b = a * c → b = c :=
λ (a b c : G) (Habac : a * b = a * c), -- got to deduce b = c.
calc b = 1 * b : by rw one_mul
... = (a⁻¹ * a) * b : by rw mul_left_inv
... = a⁻¹ * (a * b) : by rw mul_assoc
... = a⁻¹ * (a * c) : by rw Habac
... = (a⁻¹ * a) * c : by rw mul_assoc
... = 1 * c : by rw mul_left_inv
... = c : by rw one_mul
-- now the main theorem
theorem mul_one : ∀ (a : G), a * 1 = a :=
begin
intro a, -- goal is a * 1 = a
apply mul_left_cancel a⁻¹, -- goal now a⁻¹ * (a * 1) = a⁻¹ * a
exact calc a⁻¹ * (a * 1) = (a⁻¹ * a) * 1 : by rw mul_assoc
... = 1 * 1 : by rw mul_left_inv
... = 1 : by rw one_mul
... = a⁻¹ * a : by rw ← mul_left_inv
end
#print mul_one
#exit
import data.nat.basic
#print nat.nat.find_greatest
def nat.find_greatest (P : ℕ → Prop) [decidable_pred P] : ℕ → ℕ
| 0 := 0
| (n+1) := if h : P (n + 1) then n + 1 else nat.find_greatest n
lemma n (α : Type) (n : ℕ) (Hn : cardinal.mk α = n) :
∃ l : list α, l.nodup ∧ l.length = n :=
have fintype α, from classical.choice (cardinal.lt_omega_iff_fintype.1
(Hn.symm ▸ cardinal.nat_lt_omega _)),
let ⟨l, hl⟩ := quotient.exists_rep (@finset.univ α this).1 in
⟨l, show multiset.nodup ⟦l⟧, from hl.symm ▸ (@finset.univ α this).2,
begin end⟩
lemma three (α : Type) (Hthree : cardinal.mk α = 3) :
∃ a b c : α, a ≠ b ∧ b ≠ c ∧ c ≠ a ∧ ∀ d : α, d = a ∨ d = b ∨ d = c :=
by simp
ₘ
example (s : finset ℕ) : Type := (↑s : set ℕ)
def thing (n : ℕ) := n.factors.erase_dup.length
#eval thing 217094830932814709123840973089487098175
example : f(g*h) = f(g) * f(h) := sorry
def A : set ℝ := {x | x^2 < 3}
def B : set ℝ := {x | x^2 < 3 ∧ ∃ y : ℤ, x = y}
lemma foo : (1 / 2 : ℝ) ∈ A ∩ B :=
begin
split,
rw [A, set.mem_set_of_eq],
{norm_num},
end
example : (1 / 2 : ℝ)^2 < 3 := by norm_num
import data.zmod
lemma gcd_one_of_unit {n : ℕ+} (u : units (zmod n)) :
nat.gcd (u.val.val) n = 1 :=
begin
let abar := u.val, let bbar := u.inv, -- in zmod n
let a := abar.val, let b := bbar.val, -- in ℕ
have H : (a b) % n = 1 % n,
show (abar.val bbar.val) % n = 1 % n,
rw ←mul_val,
rw u.val_inv,
refl,
let d := nat.gcd a n,
show d = 1,
rw ←nat.dvd_one,
rw ←dvd_mod_iff (gcd_dvd_right a n),
rw ←H,
rw dvd_mod_iff (gcd_dvd_right a n),
apply dvd_mul_of_dvd_left,
exact gcd_dvd_left a n
end
lemma hintq3a : ∀ (a b c : zmod 4), 0 = a^2 + b^2 + c^2 → (2 ∣ a ∧ 2 ∣ b ∧ 2 ∣ c) := dec_trivial
lemma zmod.cast_nat_dvd {n : ℕ+} {a b : ℕ} (h : a ∣ n) : (a : zmod n) ∣ b ↔ a ∣ b := sorry
#exit
import data.set.basic tactic.interactive
variables {α : Type*} [ring α] (S T : set α)
instance : has_mul (set α) := ⟨λ S T, {x | ∃ s ∈ S, ∃ t ∈ T, x = s * t}⟩
lemma mul_def : S * T = {x | ∃ s ∈ S, ∃ t ∈ T, x = s * t} := rfl
instance : has_add (set α) := ⟨λ S T, {x | ∃ s ∈ S, ∃ t ∈ T, x = s + t}⟩
lemma add_def : S + T = {x | ∃ s ∈ S, ∃ t ∈ T, x = s + t} := rfl
instance : has_one (set α) := ⟨{1}⟩
instance : has_zero (set α) := ⟨{0}⟩
instance {α : Type*} [ring α] : semiring (set α) :=
{ one_mul := λ a, set.ext $ by simp,
mul_one := λ a, set.ext $ by simp,
add_assoc := λ s t u, set.ext $ λ x, ⟨λ h,begin rcases? h, end, sorry⟩,
..set.has_mul,
..set.has_add,
..set.has_one,
..set.has_zero }
#exit
import data.fintype
example : ∀ (f : fin 2 → fin 2 → fin 2),
(∀ x y z, f (f x y) z = f x (f y z)) → (∀ x, f x 0 = x) →
(∀ x, ∃ y, f x y = 0) → (∀ x y, f x y = f y x) := dec_trivial
#exit
import data.vector2
lemma vector.ext {α : Type*} {n : ℕ} : ∀ {v w : vector α n}
(h : ∀ m : fin n, vector.nth v m = vector.nth w m), v = w :=
λ ⟨v, hv⟩ ⟨w, hw⟩ h, subtype.eq (list.ext_le (by rw [hv, hw])
(λ m hm hn, h ⟨m, hv ▸ hm⟩))
lemma vector.nth_of_fn {α : Type*} {n : ℕ} : ∀ (f : fin n → α),
vector.nth (vector.of_fn f) = f :=
#print opt_param
inductive nested : Type
| nest : list nested → nested
#print has_inv.inv
open nested
#print nested.rec
#print prefix nested
#print vector.of_fn
def nested.rec_on (C : nested → Sort*) (x : nested) (h0 : C (nest [])) :
Π (h : Π (l : list nested), (Π a ∈ l, C a) → C (nest l)), C x :=
nested.cases_on _ x (
begin
assume l,
induction l with a l ih,
{ exact λ _, h0 },
{ assume h,
refine h _ (λ b h, _),
}
end
)
instance : has_well_founded nested :=
⟨λ a b, nested.rec (λ _, Prop) (λ l, a ∈ l) b,
⟨λ a, acc.intro _ (λ b, nested.cases_on _ a (begin
assume l hb,
simp at hb,
end))⟩⟩
def nested_dec_eq : ∀ a b : nested, decidable (a = b)
| (nest []) (nest []) := is_true rfl
| (nest []) (nest (a :: l)) := is_false (mt nest.inj (λ h, list.no_confusion h))
| (nest (a :: l)) (nest []) := is_false (mt nest.inj (λ h, list.no_confusion h))
| (nest (a :: l)) (nest (b :: m)) :=
end
#exit
import data.equiv.basic data.fintype
universes u v w
set_option trace.simplify.rewrite true
lemma thing {α : Type*} (p q : Prop) : (∃ hp : p, q) ↔ p ∧ q :=
begin
simp,
end
#print exists_prop
#exit
#print equiv.coe_fn_mk
#print has_coe_to_fun
theorem coe_fn_mk {α : Sort u} {β : Sort v} (f : α → β) (g : β → α) (l : function.left_inverse g f)
(r : function.right_inverse g f) : (equiv.mk f g l r : has_coe_to_fun.F (equiv.mk f g l r)) = f := rfl
example {α : Sort*} {β : Sort*} (f : α ≃ β) (a : ℕ) : (equiv.mk (λ a, ite (a = 5) (4 : ℕ) 5)
sorry sorry sorry : ℕ → ℕ) = sorry :=
begin
cases f, simp,
simp only [coe_fn_mk],
end
#exit
import data.real.basic
lemma silly_function : ∃ f : ℝ → ℝ, ∀ x y a : ℝ, x < y → ∃ z : ℝ, x < z ∧ z < y ∧ f z = a := sorry
#print well_founded.fix
#exit
import logic.function
example (x y : ℕ) (h : x ≠ y) (f : ℕ → ℕ) (h₂ : function.injective f) :
f x ≠ f y := mt (@h₂ x y) h
lemma em_of_iff_assoc : (∀ p q r : Prop, ((p ↔ q) ↔ r) ↔ (p ↔ (q ↔ r))) → ∀ p, p ∨ ¬p :=
λ h p, ((h (p ∨ ¬p) false false).1
⟨λ h, h.1 (or.inr (λ hp, h.1 (or.inl hp))), λ h, h.elim⟩).2 iff.rfl
#print axioms em_of_iff_assoc
#exit
import data.fintype.basic algebra.big_operators linear_algebra.linear_map_module
#print finset.smul
instance {α : Type*} [monoid α] [fintype α] : fintype (units α) :=
fintype.of_equiv {a : α // ∃ }
#exit
import data.nat.prime
import data.nat.modeq
import data.int.modeq
import algebra.group_power
namespace nat
definition quadratic_res (a n: ℕ) := ∃ x: ℕ, a ≡ x^2 [MOD n]
local attribute [instance] classical.prop_decidable
noncomputable definition legendre_sym (a: ℕ) (p:ℕ) : ℤ :=
if quadratic_res a p ∧ ¬ p ∣ a then 1 else
if ¬ quadratic_res a p then -1
else 0
theorem law_of_quadratic_reciprocity (p q : ℕ)(H1: prime p ∧ ¬ p=2)(H2: prime q ∧ ¬ q=2) :
(legendre_sym p q)*(legendre_sym q p) =(-1)^(((p-1)/2)*((q-1)/2)) := sorry
theorem euler_criterion (p : ℕ) (a: ℕ) (hp : prime p ∧ ¬ p=2) (ha : ¬ p ∣ a) :
a^((p - 1) / 2) ≡ legendre_sym a p [MOD p] := sorry
#exit
def phi (n : nat) := ((finset.range n).filter (nat.coprime n)).card
local notation φ: = phi
lemma phi_n (n : ℕ) : phi n = fintype.card (units (Zmod n)) := sorry
lemma phi_p (p : ℕ) (hp: nat.prime p) : phi p = p-1 :=
calc phi p = p-1
#exit
import data.nat.modeq data.nat.prime data.finset data.complex.basic
#print mul_le_mul_left
definition quadratic_res (a n : ℕ) : Prop := ∃ x : ℕ, a ≡ x^2 [MOD n]
instance : decidable_rel quadratic_res :=
λ a n, if hn : n = 0 then decidable_of_iff (∃ x ∈ finset.range a, a = x^2)
⟨λ ⟨x, _, hx⟩, ⟨x, by rw hx⟩, λ ⟨x, hx⟩, ⟨x, finset.mem_range.2 begin end, begin end⟩⟩
else decidable_of_iff (∃ x ∈ finset.range n, a ≡ x^2 [MOD n])
⟨λ ⟨x, _, hx⟩, ⟨x, hx⟩, λ ⟨x, hx⟩, ⟨x % n, finset.mem_range.2 (begin end), sorry⟩ ⟩
-- definition legendre_sym (a : ℤ) (p : ℕ) :=
-- if quadratic_res a p ∧ ¬ p ∣ a then 1 else
-- if ¬ quadratic_res a p then -1
-- else 0
#exit
import algebra.group_power data.finset data.nat.gcd data.nat.prime
def phi (n : nat) := ((finset.range n).filter n.coprime).card
def phi2 (n : nat) := (n.factors.map nat.pred).prod
#eval phi 1000
#eval phi2 1000
def thing (m n : ℤ) (h : n * n < n * m) : n ^ 2 < n * m := (pow_two n).symm ▸ h
example : 2 + 3 = 5 := add_comm 0 5 ▸ rfl
lemma two_add_three2 : 2 + 3 = 5 := rfl
#exit
import data.int.basic
example (a b : ℤ) : (-3 : ℤ).nat_abs / (-5 : ℤ).nat_abs
≠ ((-3 : ℤ) / (- 5 : ℤ)).nat_abs :=
dec_trivial
#print tactic.interactive.induction
set_option trace.simplify.rewrite true
lemma h (α β γ : Type) (f : α → β) (g : β → α) (H : ∀ b : β, f (g b) = b)
(j : γ → option β) (x : γ) :
(do y ← (j x), return (f (g y))) = j x :=
by simp [H]
#print h
#exit
import analysis.real
theorem infinite_cover {a b : ℝ} {c : set (set ℝ)} (n : ℕ) :
∃ k : ℕ, 1 ≤ k ≤ n ∧ ∀ c' ⊆ c, {r : ℝ | a+(k-1)*(a+b)/n ≤ r ∧
r ≤ a+k*(a+b)/n} ⊆ ⋃₀ c' → ¬ set.finite c' := sorry
example : ∃! x, x = 2 := ⟨2, rfl, λ y, id⟩
#print exists_unique
#exit
#print array
def f : ℕ → ℕ → ℕ → ℕ → Prop
notation a `≡` b := f a b
set_option pp.implicit true
lemma h : ¬ (2 ∣ 5) := dec_trivial
#print nat.decidable_dvd
example : ¬ (2 | 5) := dec_trivial
open vector_space
variables {α β γ : Type}
[field α] [vector_space α β] [vector_space α γ]
inductive T : Type
| mk : (ℕ → T) → T
#print T
#exit
import tactic.finish
variables (p q : Prop) (hp : p) (hq : q)
lemma easy : p ↔ p := iff.rfl
theorem not_a_constructivist : (¬(p ∨ q)) ↔ ((¬ p) ∧ (¬ q)) :=
by finish
#print not_a_constructivist
#exit
import logic.function
open function
def f : (thunk ℕ) → ℕ := λ _, 0
def g : ℕ → ℕ := λ _, 0
#print thunk
#eval f ((99 : ℕ) ^ 99 ^ 99)
#eval g (99 ^ 99 ^ 99 ^ 99 ^ 99)
#check Σ α : Type, set α
structure g :=
(α : Type)
(f : α → bool)
#print tactic.exact
def gafd (p q : Prop) [decidable p] [decidable q] :
decidable (p → q) := by apply_instance
#print forall_prop_decidable
def h {α : Sort*} (f : α → α → ℕ) : ¬ surjective f :=
λ h, let ⟨a, ha⟩ := h (λ a, nat.succ (f a a)) in begin
have : f a a = nat.succ (f a a) := congr_fun ha _,
exact nat.succ_ne_self _ this.symm,
end
#print h
#exit
import data.multiset
def value_aux' (N_min : multiset ℕ → ℕ) : multiset ℕ → multiset ℕ → ℕ
| C L := N_min (multiset.pmap
(λ a (h : a ∈ C),
have multiset.card (C.erase a) < multiset.card C,
from multiset.card_lt_of_lt (multiset.erase_lt.2 h),
a - 2 + int.nat_abs (2 - value_aux' (C.erase a) L))
C (λ _,id) + multiset.pmap
(λ a (h : a ∈ L),
have multiset.card (L.erase a) < multiset.card L,
from multiset.card_lt_of_lt (multiset.erase_lt.2 h),
a - 4 +int.nat_abs (4 - value_aux' C (L.erase a)))
L (λ _,id))
using_well_founded {rel_tac := λ _ _,
`[exact ⟨_, measure_wf (λ CL, multiset.card CL.fst + multiset.card CL.snd)⟩]}
set_option pp.proofs true
#print value_aux'._main._pack
#exit
example (C : multiset ℕ) : decidable (∃ a : ℕ, a ≥ 4 ∧ a ∈ C) :=
suffices this : decidable (∃ a ∈ C, a ≥ 4),
by { resetI, apply @decidable_of_iff _ _ _ this, apply exists_congr, intro, tauto },
by { apply_instance }
set_option pp.implicit true
instance decidable_exists_multiset {α : Type*} (s : multiset α) (p : α → Prop) [decidable_pred p] :
decidable (∃ x ∈ s, p x) :=
quotient.rec_on s list.decidable_exists_mem (λ a b h, subsingleton.elim _ _)
example (C : multiset ℕ) : decidable (∃ a : ℕ, a ≥ 4 ∧ a ∈ C) :=
decidable_of_iff (∃ a ∈ quotient.out C, a ≥ 4) (⟨λ ⟨x, hx₁, hx₂⟩, ⟨x, hx₂, begin
rw ← quotient.out_eq C,
exact hx₁,
end⟩, λ ⟨x, hx₁, hx₂⟩, ⟨x, begin
rw ← quotient.out_eq C at hx₂,
exact ⟨ hx₂, hx₁⟩
end⟩⟩)
#exit
import data.num.basic import tactic.basic data.num.lemmas data.list.basic data.complex.basic
open tactic
namespace ring_tac
open tactic
-- We start by modelling polynomials as lists of integers. Note that znum
-- is basically the same as int, but optimised for computations.
-- The list [a0,a1,...,an] represents a0 + a1*x + a2*x^2 + ... +an*x^n
def poly := list znum
-- We now make basic definitions and prove basic lemmas about addition of polynomials,
-- multiplication of a polynomial by a scalar, and multiplication of polynomials.
def poly.add : poly → poly → poly
| [] g := g
| f [] := f
| (a :: f') (b :: g') := (a + b) :: poly.add f' g'
@[simp] lemma poly.zero_add (p : poly) : poly.add [] p = p := by cases p; refl
def poly.smul : znum → poly → poly
| _ [] := []
| z (a :: f') := (z * a) :: poly.smul z f'
def poly.mul : poly → poly → poly
| [] _ := []
| (a :: f') g := poly.add (poly.smul a g) (0 :: poly.mul f' g)
def poly.const : znum → poly := λ z, [z]
def poly.X : poly := [0,1]
-- One problem with our implementation is that the lists [1,2,3] and [1,2,3,0] are different
-- list, but represent the same polynomial. So we define an "is_equal" predicate.
def poly.is_eq_aux : list znum -> list znum -> bool
| [] [] := tt
| [] (h₂ :: t₂) := if (h₂ = 0) then poly.is_eq_aux [] t₂ else ff
| (h₁ :: t₁) [] := if (h₁ = 0) then poly.is_eq_aux t₁ [] else ff
| (h₁ :: t₁) (h₂ :: t₂) := if (h₁ = h₂) then poly.is_eq_aux t₁ t₂ else ff
def poly.is_eq : poly → poly → bool := poly.is_eq_aux
-- evaluation of a polynomial at some element of a commutative ring.
def poly.eval {α} [comm_ring α] (X : α) : poly → α
| [] := 0
| (n::l) := n + X * poly.eval l
-- Lemmas saying that evaluation plays well with addition, multiplication, polynomial equality etc
@[simp] lemma poly.eval_zero {α} [comm_ring α] (X : α) : poly.eval X [] = 0 := rfl
@[simp] theorem poly.eval_add {α} [comm_ring α] (X : α) : ∀ p₁ p₂ : poly,
(p₁.add p₂).eval X = p₁.eval X + p₂.eval X :=
begin
intro p₁,
induction p₁ with h₁ t₁ H,
-- base case
intros,simp [poly.eval],
-- inductive step
intro p₂,
cases p₂ with h₂ t₂,
simp [poly.add],
unfold poly.eval poly.add,
rw (H t₂),
simp [mul_add]
end
@[simp] lemma poly.eval_mul_zero {α} [comm_ring α] (f : poly) (X : α) :
poly.eval X (poly.mul f []) = 0 :=
begin
induction f with h t H,
refl,
unfold poly.mul poly.smul poly.add poly.mul poly.eval,
rw H,simp
end
@[simp] lemma poly.eval_smul {α} [comm_ring α] (X : α) (z : znum) (f : poly) :
poly.eval X (poly.smul z f) = z * poly.eval X f :=
begin
induction f with h t H, simp [poly.smul,poly.eval,mul_zero],
unfold poly.smul poly.eval,
rw H,
simp [mul_add,znum.cast_mul,mul_assoc,mul_comm]
end
@[simp] theorem poly.eval_mul {α} [comm_ring α] (X : α) : ∀ p₁ p₂ : poly,
(p₁.mul p₂).eval X = p₁.eval X * p₂.eval X :=
begin
intro p₁,induction p₁ with h₁ t₁ H,
simp [poly.mul],
intro p₂,
unfold poly.mul,
rw poly.eval_add,
unfold poly.eval,
rw [H p₂,znum.cast_zero,zero_add,add_mul,poly.eval_smul,mul_assoc]
end
@[simp] theorem poly.eval_const {α} [comm_ring α] (X : α) : ∀ n : znum,
(poly.const n).eval X = n :=
begin
intro n,
unfold poly.const poly.eval,simp
end
@[simp] theorem poly.eval_X {α} [comm_ring α] (X : α) : poly.X.eval X = X :=
begin
unfold poly.X poly.eval,simp
end
-- Different list representing the same polynomials evaluate to the same thing
theorem poly.eval_is_eq {α} [comm_ring α] (X : α) {p₁ p₂ : poly} :
poly.is_eq p₁ p₂ → p₁.eval X = p₂.eval X :=
begin
revert p₂,
induction p₁ with h₁ t₁ H₁,
{ intros p₂ H,
induction p₂ with h₁ t₁ H₂,refl,
unfold poly.eval,
unfold poly.is_eq poly.is_eq_aux at H,
split_ifs at H,swap,cases H,
rw [h,←H₂ H],
simp },
{ intros p₂ H,
induction p₂ with h₂ t₂ H₂,
{ unfold poly.eval,
unfold poly.is_eq poly.is_eq_aux at H,
split_ifs at H,swap,cases H,
rw [h,H₁ H],
simp },
{ unfold poly.eval,
unfold poly.is_eq poly.is_eq_aux at H,
split_ifs at H,swap,cases H,
unfold poly.is_eq at H₂,
rw [h,H₁ H] } }
end
-- That's the end of the poly interface. We now prepare for the reflection.
-- First an abstract version of polynomials (where equality is harder to test, and we won't
-- need to test it). We'll construct a term of this type from (x+1)*(x+1)*(x+1)
-- fancy attribute because we will be using reflection in meta-land
@[derive has_reflect]
inductive ring_expr : Type
| add : ring_expr → ring_expr → ring_expr
| mul : ring_expr → ring_expr → ring_expr
| const : znum → ring_expr
| X : ring_expr
-- Now a "reflection" of this abstract type which the VM can play with.
meta def reflect_expr (X : expr) : expr → option ring_expr
| `(%%e₁ + %%e₂) := do
p₁ ← reflect_expr e₁,
p₂ ← reflect_expr e₂,
return (ring_expr.add p₁ p₂)
| `(%%e₁ * %%e₂) := do
p₁ ← reflect_expr e₁,
p₂ ← reflect_expr e₂,
return (ring_expr.mul p₁ p₂)
| e := if e = X then return ring_expr.X else
do n ← expr.to_int e,
return (ring_expr.const (znum.of_int' n))
-- turning the abstract poly into a concrete list of coefficients.
def to_poly : ring_expr → poly
| (ring_expr.add e₁ e₂) := (to_poly e₁).add (to_poly e₂)
| (ring_expr.mul e₁ e₂) := (to_poly e₁).mul (to_poly e₂)
| (ring_expr.const z) := poly.const z
| ring_expr.X := poly.X
-- evaluating the abstract poly
def ring_expr.eval {α} [comm_ring α] (X : α) : ring_expr → α
| (ring_expr.add e₁ e₂) := e₁.eval + e₂.eval
| (ring_expr.mul e₁ e₂) := e₁.eval * e₂.eval
| (ring_expr.const z) := z
| ring_expr.X := X
-- evaluating the abstract and the concrete polynomial gives the same answer
theorem to_poly_eval {α} [comm_ring α] (X : α) (e) : (to_poly e).eval X = e.eval X :=
by induction e; simp [to_poly, ring_expr.eval, *]
-- The big theorem! If the concrete polys are equal then the abstract ones evaluate
-- to the same value.
theorem main_thm {α} [comm_ring α] (X : α) (e₁ e₂) {x₁ x₂}
(H : poly.is_eq (to_poly e₁) (to_poly e₂)) (R1 : e₁.eval X = x₁) (R2 : e₂.eval X = x₂) : x₁ = x₂ :=
by rw [← R1, ← R2, ← to_poly_eval,poly.eval_is_eq X H, to_poly_eval]
-- Now here's the tactic! It takes as input the unknown but concrete variable x
-- and an expression f(x)=g(x),
-- creates abstract polys f(X) and g(X), proves they're equal using rfl,
-- and then applies the main theorem to deduce f(x)=g(x).
meta def ring_tac (X : pexpr) : tactic unit := do
X ← to_expr X,
`(%%x₁ = %%x₂) ← target,
r₁ ← reflect_expr X x₁,
r₂ ← reflect_expr X x₂,
let e₁ : expr := reflect r₁,
let e₂ : expr := reflect r₂,
`[refine main_thm %%X %%e₁ %%e₂ rfl _ _],
all_goals `[simp only [ring_expr.eval,
znum.cast_pos, znum.cast_neg, znum.cast_zero',
pos_num.cast_bit0, pos_num.cast_bit1,
pos_num.cast_one']]
example (x : ℤ) : (x + 1) * (x + 1) = x*x+2*x+1 := by do ring_tac ```(x)
example (x : ℤ) : (x + 1) * (x + 1) * (x + 1) = x*x*x+3*x*x+3*x+1 := by do ring_tac ```(x)
example (x : ℤ) : (x + 1) + ((-1)*x + 1) = 2 := by do ring_tac ```(x)
end ring_tac
def poly := list znum
def poly.add : poly → poly → poly
| [] g := g
| f [] := f
| (a :: f') (b :: g') := (a + b) :: poly.add f' g'
def poly.eval {α} [comm_ring α] (X : α) : poly → α
| [] := 0
| (n::l) := n + X * poly.eval l
#exit
open expr tactic classical
section logical_equivalences
local attribute [instance] prop_decidable
variables {a b : Prop}
theorem not_not_iff (a : Prop) : ¬¬a ↔ a :=
iff.intro classical.by_contradiction not_not_intro
theorem implies_iff_not_or (a b : Prop) : (a → b) ↔ (¬ a ∨ b) :=
iff.intro
(λ h, if ha : a then or.inr (h ha) else or.inl ha)
(λ h, or.elim h (λ hna ha, absurd ha hna) (λ hb ha, hb))
theorem not_and_of_not_or_not (h : ¬ a ∨ ¬ b) : ¬ (a ∧ b) :=
assume ⟨ha, hb⟩, or.elim h (assume hna, hna ha) (assume hnb, hnb hb)
theorem not_or_not_of_not_and (h : ¬ (a ∧ b)) : ¬ a ∨ ¬ b :=
if ha : a then
or.inr (show ¬ b, from assume hb, h ⟨ha, hb⟩)
else
or.inl ha
theorem not_and_iff (a b : Prop) : ¬ (a ∧ b) ↔ ¬a ∨ ¬b :=
iff.intro not_or_not_of_not_and not_and_of_not_or_not
theorem not_or_of_not_and_not (h : ¬ a ∧ ¬ b) : ¬ (a ∨ b) :=
assume h1, or.elim h1 (assume ha, h^.left ha) (assume hb, h^.right hb)
theorem not_and_not_of_not_or (h : ¬ (a ∨ b)) : ¬ a ∧ ¬ b :=
and.intro (assume ha, h (or.inl ha)) (assume hb, h (or.inr hb))
theorem not_or_iff (a b : Prop) : ¬ (a ∨ b) ↔ ¬ a ∧ ¬ b :=
iff.intro not_and_not_of_not_or not_or_of_not_and_not
end logical_equivalences
meta def normalize_hyp (lemmas : list expr) (hyp : expr) : tactic unit :=
do try (simp_at hyp lemmas)
meta def normalize_hyps : tactic unit :=
do hyps ← local_context,
lemmas ← monad.mapm mk_const [``iff_iff_implies_and_implies,
``implies_iff_not_or, ``not_and_iff, ``not_or_iff, ``not_not_iff,
``not_true_iff, ``not_false_iff],
monad.for' hyps (normalize_hyp lemmas)
#exit
def bind_option {X : Type} {Y : Type} :
option X → (X → option Y) → option Y
| option.none f := @option.none Y
| (option.some x) f := f x
#print option.bind
lemma pierce_em : (∀ p q : Prop, ((p → q) → p) → p) ↔ (∀ p, p ∨ ¬p) :=
⟨λ pierce p, pierce (p ∨ ¬p) (¬p) (λ h, or.inr (λ hp, h (or.inl hp) hp)),
λ em p q, (em p).elim (λ hp _, hp)
(λ h h₁, h₁ $ (em q).elim (λ hq _, hq) (λ h₂ hp, (h hp).elim))⟩
#print axioms pierce_em
lemma double_neg_em : (∀ p, ¬¬p → p) ↔ (∀ p, p ∨ ¬p) :=
⟨λ dneg p, dneg () (λ h, h (or.inr (h ∘ or.inl))),
λ em p hneg, (em p).elim id (λ h, (hneg h).elim)⟩
#print axioms double_neg_em
lemma demorgan_em : (∀ p q, ¬ (¬p ∧ ¬q) → p ∨ q) ↔ (∀ p, p ∨ ¬p) :=
⟨λ h p, h p (¬p) (λ h, h.2 h.1),
λ em p q h, (em p).elim or.inl $ λ not_p, (em q).elim or.inr
(λ not_q, (h ⟨not_p, not_q⟩).elim)⟩
#print axioms demorgan_em
lemma implies_to_or_em : (∀ p q, (p → q) → (¬p ∨ q)) ↔ (∀ p, p ∨ ¬p) :=
⟨λ h p, or.symm $ h p p id,
λ em p q hpq, (em p).elim (or.inr ∘ hpq) or.inl⟩
#print axioms implies_to_or_em
#exit
import logic.function data.equiv.basic
open function
universe u
axiom exists_inv_of_bijection {α β : Sort*} {f : α → β}
(hf : bijective f) : ∃ g : β → α, left_inverse f g ∧ right_inverse f g
axiom em2 (p : Prop) : p ∨ ¬p
lemma choice2 {α : Sort*} : nonempty (nonempty α → α) :=
(em2 (nonempty α)).elim
(λ ⟨a⟩, ⟨λ _, a⟩) (λ h, ⟨false.elim ∘ h⟩)
lemma choice3 : nonempty (Π {α : Sort u}, nonempty α → α) :=
(em2 (nonempty (Π {α : Sort u}, nonempty α → α))).elim id
(λ h, begin
end)
lemma choice_equiv :
(∀ {α : Sort*}, nonempty (nonempty α → α)) → (nonempty)
lemma exists_inv_of_bijection {α β : Sort*} {f : α → β}
(hf : bijective f) : ∃ g : β → α, left_inverse f g ∧ right_inverse f g :=
have hchoice : ∀ b : β, nonempty (nonempty {a : α // f a = b} → {a : α // f a = b}) :=
λ b, choice2,
let choice : Π b : β, nonempty {a : α // f a = b} → {a : α // f a = b} :=
λ b, begin end in
let f : Π b : β, {a : α // f a = b} := λ b, begin end,
begin
cases hf,
end
example {α : Sort*} : nonempty (nonempty α → α) :=
begin
end
lemma em2 {p : Prop} : p ∨ ¬p :=
let U : Prop → Prop := λ q, q = true ∨ p in
let V : Prop → Prop := λ q, q = false ∨ p in
have u : subtype U := ⟨true, or.inl rfl⟩,
have v : subtype V := ⟨false, or.inl rfl⟩,
have not_uv_or_p : u.1 ≠ v.1 ∨ p :=
u.2.elim (v.2.elim (λ h₁ h₂, h₁.symm ▸ h₂.symm ▸ or.inl (λ htf, htf ▸ ⟨⟩))
(λ hp _, or.inr hp)) or.inr,
have p_implies_uv : p → u.1 = v.1 := λ hp,
have U = V := funext (assume x : Prop,
have hl : (x = true ∨ p) → (x = false ∨ p), from
assume a, or.inr hp,
have hr : (x = false ∨ p) → (x = true ∨ p), from
assume a, or.inr hp,
show (x = true ∨ p) = (x = false ∨ p), from
propext (iff.intro hl hr)),
begin
end,
begin
end,
not_uv_or_p.elim
(λ h, or.inr $ mt p_implies_uv h)
or.inl
#exit
import tactic.interactive
namespace tactic
run_cmd mk_simp_attr `norm_num2
lemma two_add_three : 2 + 3 = 4 := sorry
attribute [norm_num2] two_add_three
meta def norm_num2 : tactic unit :=
do simp_all
meta def generalize_proofs (ns : list name) : tactic unit :=
do intros_dep,
hs ← local_context >>= mfilter is_proof,
t ← target,
collect_proofs_in t [] (ns, hs) >> skip
theorem not_not_iff (a : Prop) : ¬¬a ↔ a :=
iff.intro classical.by_contradiction not_not_intro
theorem implies_iff_not_or (a b : Prop) : (a → b) ↔ (¬ a ∨ b) :=
iff.intro
(λ h, if ha : a then or.inr (h ha) else or.inl ha)
(λ h, or.elim h (λ hna ha, absurd ha hna) (λ hb ha, hb))
theorem not_and_of_not_or_not (h : ¬ a ∨ ¬ b) : ¬ (a ∧ b) :=
assume ⟨ha, hb⟩, or.elim h (assume hna, hna ha) (assume hnb, hnb hb)
theorem not_or_not_of_not_and (h : ¬ (a ∧ b)) : ¬ a ∨ ¬ b :=
if ha : a then
or.inr (show ¬ b, from assume hb, h ⟨ha, hb⟩)
else
or.inl ha
theorem not_and_iff (a b : Prop) : ¬ (a ∧ b) ↔ ¬a ∨ ¬b :=
iff.intro not_or_not_of_not_and not_and_of_not_or_not
theorem not_or_of_not_and_not (h : ¬ a ∧ ¬ b) : ¬ (a ∨ b) :=
assume h1, or.elim h1 (assume ha, h^.left ha) (assume hb, h^.right hb)
theorem not_and_not_of_not_or (h : ¬ (a ∨ b)) : ¬ a ∧ ¬ b :=
and.intro (assume ha, h (or.inl ha)) (assume hb, h (or.inr hb))
theorem not_or_iff (a b : Prop) : ¬ (a ∨ b) ↔ ¬ a ∧ ¬ b :=
iff.intro not_and_not_of_not_or not_or_of_not_and_not
end logical_equivalences
meta def normalize_hyp (lemmas : simp_lemmas) (lemmas2 : list name) (hyp : expr) : tactic unit :=
do try (simp_hyp lemmas lemmas2 hyp)
meta def normalize_hyps : tactic unit :=
do hyps ← local_context,
lemmas ← monad.mapm mk_const [``iff_iff_implies_and_implies,
``implies_iff_not_or, ``not_and_iff, ``not_not_iff,
``not_true_iff, ``not_false_iff],
hyps (normalize_hyp lemmas)
open tactic
universe u
meta def find_same_type : expr → list expr → tactic expr
| e [] := failed
| e (h :: hs) :=
do t ← infer_type h,
(unify e t >> return h) <|> find_same_type e hs
meta def assumption : tactic unit :=
do ctx ← local_context,
t ← target,
h ← tactic.find_same_type t ctx,
exact h
<|> fail "assumption tactic failed"
#print assumption
#print nonempty
#print eq_of_heq
variables (real : Type) [ordered_ring real]
variables (log exp : real → real)
variable log_exp_eq : ∀ x, log (exp x) = x
variable exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x
variable exp_pos : ∀ x, exp x > 0
variable exp_add : ∀ x y, exp (x + y) = exp x * exp y
-- this ensures the assumptions are available in tactic proofs
include log_exp_eq exp_log_eq exp_pos exp_add
example (x y z : real) :
exp (x + y + z) = exp x * exp y * exp z :=
by rw [exp_add, exp_add]
example (y : real) (h : y > 0) : exp (log y) = y :=
exp_log_eq h
theorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :
log (x * y) = log x + log y :=
calc
log (x * y) = log (exp (log x) * exp(log y)) : by rw [← exp_log_eq hx, ← exp_log_eq hy]
... = log (exp (log x + log y)) : by rw [← exp_add (log x) (log y)]
... = log x + log y : by rw [log_exp_eq (log x + log y)]
example : ∀ {α : Sort u} {a a' : α}, a == a' → a = a' :=
λ α a a' h, @heq.rec_on α a (λ β b, begin end) h begin
end
example (a b : Prop) (h : a ∧ b) : b ∧ a :=
by do split,
eh ← get_local `h,
mk_const ``and.right >>= apply,
exact eh,
mk_const ``and.left >>= apply,
exact eh
namespace foo
theorem bar : true := trivial
meta def my_tac : tactic unit :=
mk_const ``bar >>= exact
example : true := by my_tac
end foo
#print apply_instance
lemma h : a → b → a ∧ b :=
by do eh1 ← intro `h1,
eh2 ← intro `h2,
applyc ``and.intro,
exact eh1,
exact eh2
#print h
universes u v
open io
#eval put_str "hello " >> put_str "world! " >> put_str (to_string (27 * 39))
#eval (some 2) <|> (some 1)
#print axioms put_str
#check @put_str
#check @get_line
namespace la
structure registers : Type := (x : ℕ) (y : ℕ) (z : ℕ)
def init_reg : registers := registers.mk 0 0 0
def state (S : Type u) (α : Type v) : Type (max u v) := S → α × S
instance (S : Type u) : monad (state S) :=
{ pure := λ α a r, (a, r),
bind := λ α β sa b s, b (sa s).1 (sa s).2 }
def read {S : Type} : state S S :=
λ s, (s, s)
def write {S : Type} : S → state S unit :=
λ s0 s, ((), s0)
@[reducible] def reg_state := state registers
def read_x : reg_state ℕ :=
do s ← read, return (registers.x s)
def read_y : reg_state ℕ :=
do s ← read, return (registers.y s)
def read_z : reg_state ℕ :=
do s ← read, return (registers.z s)
def write_x (n : ℕ) : reg_state unit :=
do s ← read,
write (registers.mk n (registers.y s) (registers.z s))
def write_y (n : ℕ) : reg_state unit :=
do s ← read,
write(registers.mk (registers.x s) n (registers.z s))
def write_z (n : ℕ) : reg_state unit :=
do s ← read,
write (registers.mk (registers.x s) (registers.y s) n)
def foo : reg_state ℕ :=
do write_x 5,
write_y 7,
x ← read_x,
write_z (x + 3),
y ← read_y,
z ← read_z,
write_y (y + z),
y ← read_y,
return (y ^ 3)
#print foo
end la
#exit
universe u
variables {α β γ δ : Type.{u}} (la : list α)
variables (f : α → list β) (g : α → β → list γ)
(h : α → β → γ → list δ)
inductive option2 (α : Type u) : Type u
| none : option2
| some : α → option2
instance : monad option2 :=
begin
refine {..},
refine λ α β, _,
end
#print applicative
#print option.monad
example : list δ :=
do a ← la,
b ← f a,
c ← g a b,
#exit
import data.multiset data.finset order.bounded_lattice
@[derive decidable_eq] structure sle :=
(three_chains : ℕ) -- number of three-chains
(four_loops : ℕ)
(six_loops : ℕ)
(long_chains : multiset ℕ)
(long_chains_are_long : ∀ x ∈ long_chains, x ≥ 4)
(long_loops : multiset ℕ)
(long_loops_are_long : ∀ x ∈ long_loops, x ≥ 8)
(long_loops_are_even : ∀ x ∈ long_loops, 2 ∣ x)
def size (e : sle) : ℕ := sorry
def legal_moves (e : sle) : finset {f : sle // size f < size e} := sorry
def val : sle → with_top ℕ
| e := (legal_moves e).inf
(λ f, have size f.1 < size e := f.2, (val f.1 : with_top ℕ))
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf size⟩]}
def val2 : Π e : sle, legal_moves e ≠ ∅ → ℕ
| e := (legal_moves e).inf
(λ f, have size f.1 < size e := f.2, (val f.1 : with_top ℕ))
#exit
variables {α β γ δ : Type.{u}} (oa : option α)
variables (f : α → option β) (g : α → β → option γ)
(h : α → β → γ → option δ)
definition test (m : Type → Type) [monad m]
(α : Type) (s : m α) (β : Type) (t : m β) (γ : Type) (f : α → β → m γ)
(g : α → β → m γ)
:=
do a ← s,
b ← t,
return (g a b)
def x : option β :=
do a ← oa,
b ← f a,
return b
#print x
example : option δ :=
do a ← oa,
b ← f a,
c ← g a b,
h a b c
#print option.return
@[elab_as_eliminator, elab_strategy] def multiset.strong_induction_on2 {α : Type*} {p : multiset α → Sort*} :
∀ (s : multiset α), (∀ s, (∀t < s, p t) → p s) → p s :=
well_founded.fix (measure_wf multiset.card) (λ s ih h, h s (λ t ht, ih t (multiset.card_lt_of_lt ht) h))
#print multiset.strong_induction_on2
definition f (s : multiset ℕ) : ℕ :=
multiset.strong_induction_on2 s (λ s' H, 0)
#eval f ({1,2,3} : multiset ℕ)
def bar : ℕ → ℕ
| 0 := 0
| (n+1) := list.length
(list.pmap (λ m (hm : m < n + 1), bar m) [n, n, n]
(by simp [nat.lt_succ_self]))
set_option pp.proofs true
#print bar._main._pack
def map_rec_on {C : ℕ → Sort*} (f : ℕ → list ℕ) :
Π (n : ℕ) (h : ∀ m, ∀ k ∈ f m, k < m)
(c0 : C 0) (ih : (Π n, list ℕ → C (n + 1))), C n
| 0 := λ h c0 ih, c0
| (n+1) := λ h c0 ih, begin have := ih n,
have := this ((f (n + 1)).map (λ m, map_rec_on,
end
#eval bar 1
def bar_aux : ℕ → (ℕ → list ℕ) → list ℕ
| 0 _ := []
| (n+1) f := list.repeat 3 $
list.length (bar_aux n f)
#eval bar_aux 2 (λ n, [n, n, n])
instance subtype.has_decidable_eq (α : Prop) [h : decidable_eq α]
(p : α → Prop) : decidable_eq (subtype p)
| ⟨_, _⟩ ⟨_, _⟩ := is_true rfl
#print decidable
lemma h (p : Prop) : ¬(p ↔ ¬p) :=
λ h : p ↔ ¬p,
have not_p : ¬p := λ hp : p, h.1 hp hp,
not_p (h.2 not_p)
#print h
def subfunc_to_option {α β: Type} {c: α → Prop} [decidable_pred c]
(f: {x:α // c x} → β) : α → option β :=
λ y: α, if h : c y then some (f (subtype.mk y h)) else none
def option_to_subfunc {α β: Type} (f: α → (option β)) :
{x : α // option.is_some (f x)} → β | ⟨x, h⟩ := option.get h
theorem inv1 {α β: Type} {c: α → Prop} (f: {x:α // c x} → β) [decidable_pred c] :
∀ y : {x // c x}, option_to_subfunc (@subfunc_to_option α β c _ f) ⟨y.1, sorry⟩ = f y := sorry
#print roption
def option_to_subfunc {α β: Type} (f: α → (option β)) :
{x : α // f x ≠ none} → β :=
λ y: {x:α // f x ≠ none},
match f y, y.2 with
| some x, hfy := x
| none , hfy := (hfy rfl).elim
end
def subfunc_to_option {α β: Type} {c: α → Prop} [decidable_pred c]
(f: {x:α // c x} → β) : α → option β :=
λ y: α, if h : c y then some (f (subtype.mk y h)) else none
open lattice
variable {α : Type*}
lemma sup_eq_max [decidable_linear_order α] (a b : with_bot α) : a ⊔ b = max a b :=
le_antisymm (sup_le (le_max_left _ _) (le_max_right _ _)) (max_le le_sup_left le_sup_right)
lemma inf_eq_min [decidable_linear_order α] (a b : with_top α) : a ⊓ b = min a b :=
le_antisymm (le_min inf_le_left inf_le_right) (le_inf (min_le_left _ _) (min_le_right _ _))
#print subtype.eq
#print subtype.eq
lemma well_founded_lt_with_bot {α : Type*} [partial_order α] (h : well_founded ((<) : α → α → Prop)) :
well_founded ((<) : with_bot α → with_bot α → Prop) :=
have acc_bot : acc ((<) : with_bot α → with_bot α → Prop) ⊥ :=
acc.intro _ (λ a ha, (not_le_of_gt ha bot_le).elim),
⟨λ a, option.rec_on a acc_bot (λ a, acc.intro _ (λ b, option.rec_on b (λ _, acc_bot)
(λ b, well_founded.induction h b
(show ∀ b : α, (∀ c, c < b → (c : with_bot α) < a →
acc ((<) : with_bot α → with_bot α → Prop) c) → (b : with_bot α) < a →
acc ((<) : with_bot α → with_bot α → Prop) b,
from λ b ih hba, acc.intro _ (λ c, option.rec_on c (λ _, acc_bot)
(λ c hc, ih _ (with_bot.some_lt_some.1 hc) (lt_trans hc hba)))))))⟩
lemma well_founded_lt_with_top {α : Type*} [partial_order α] (h : well_founded ((<) : α → α → Prop)) :
well_founded ((<) : with_top α → with_top α → Prop) :=
have acc_some : ∀ a : α, acc ((<) : with_top α → with_top α → Prop) (some a) :=
λ a, acc.intro _ (well_founded.induction h a
(show ∀ b, (∀ c, c < b → ∀ d : with_top α, d < some c → acc (<) d) →
∀ y : with_top α, y < some b → acc (<) y,
from λ b ih c, option.rec_on c (λ hc, (not_lt_of_ge lattice.le_top hc).elim)
(λ c hc, acc.intro _ (ih _ (with_top.some_lt_some.1 hc))))),
⟨λ a, option.rec_on a (acc.intro _ (λ y, option.rec_on y (λ h, (lt_irrefl _ h).elim)
(λ _ _, acc_some _))) acc_some⟩
#exit
variables {α : Type}
def preimage (f : α → ℕ) (u : ℕ) : set α := λ x, f x=u
instance [fintype α] [decidable_eq α] (f : α → ℕ) (u : ℕ) : fintype (preimage f u) :=
by unfold preimage; apply_instance
def card_image [fintype α] [decidable_eq α] (f : α → ℕ) (u : ℕ) : ℕ :=
fintype.card (preimage f u)
#exit
variables {α β γ : Type}
-- function f is continuous at point x
axiom continuous_at (x : α) (f : α → β) : Prop
def continuous (f : α → β) : Prop := ∀ x, continuous_at x f
lemma continuous_comp (f : α → β) (g : β → γ) :
continuous f → continuous g → continuous (g ∘ f) :=
begin
assume cf cg x,
unfold continuous at *,
have := cg (f x)
end
#exit
import data.fintype.basic data.num.lemmas tactic.norm_num data.real.basic
#print prefix subsingleton
@[elab_with_expected_type] lemma subsingleton_thing {α : Type*} [subsingleton α] {P : α → Prop} (a : α)
(h : P a) (b : α) : P b :=
by rwa subsingleton.elim b a
example {α : Type*} [f₁ : fintype α] (h : fintype.card α = 0) (f₂ : fintype α) :
@fintype.card α f₂ = 0 :=
@subsingleton_thing (fintype α) _ _ f₁ h _
#print finset.product
lemma e : (2 : ℝ) + 2 = 4 := rfl
#print e
#exit
import data.equiv
def is_valuation {R : Type} [comm_ring R] {α : Type} [linear_order α] (f : R → α) : Prop := true
structure valuations (R : Type) [comm_ring R] :=
(α : Type) [Hα : linear_order α] (f : R → α) (Hf : is_valuation f)
instance to_make_next_line_work (R : Type) [comm_ring R] (v : valuations R) : linear_order v.α := v.Hα
instance valuations.setoid (R : Type) [comm_ring R] : setoid (valuations R) := {
r := λ v w, ∀ r s : R, valuations.f v r ≤ v.f s ↔ w.f r ≤ w.f s,
iseqv := ⟨λ v r s,iff.rfl,λ v w H r s,(H r s).symm,λ v w x H1 H2 r s,iff.trans (H1 r s) (H2 r s)⟩
}
def Spv1 (R : Type) [comm_ring R] := quotient (valuations.setoid R)
def Spv2 (R : Type) [comm_ring R] :=
{ineq : R → R → Prop // ∃ v : valuations R, ∀ r s : R, ineq r s ↔ v.f r ≤ v.f s}
#check Spv1 _ -- Type 1
#check Spv2 _ -- Type
def to_fun (R : Type) [comm_ring R] : Spv1 R → Spv2 R :=
quotient.lift (λ v, (⟨λ r s, valuations.f v r ≤ v.f s, ⟨v,λ r s,iff.rfl⟩⟩ : Spv2 R))
(λ v w H,begin dsimp,congr,funext,exact propext (H r s) end)
open function
noncomputable definition they_are_the_same (R : Type) [comm_ring R] : equiv (Spv1 R) (Spv2 R) :=
equiv.of_bijective $ show bijective (to_fun R),
from ⟨λ x y, quotient.induction_on₂ x y $ λ x y h,
quotient.sound $ λ r s, iff_of_eq $ congr_fun (congr_fun (subtype.mk.inj h) r) s,
λ ⟨x, ⟨v, hv⟩⟩, ⟨⟦v⟧, subtype.eq $ funext $ λ r, funext $ λ s, propext (hv r s).symm⟩⟩
noncomputable definition they_are_the_same (R : Type) [comm_ring R] : equiv (Spv1 R) (Spv2 R) :=
{ to_fun := to_fun R,
inv_fun := inv_fun R,
left_inv := λ vs, quotient.induction_on vs begin
assume vs,
apply quotient.sound,
intros r s,
have := (to_fun R ⟦vs⟧).property,
have H := classical.some_spec (to_fun R ⟦vs⟧).property r s,
refine H.symm.trans _,
refl,
end,
right_inv := λ s2,begin
cases s2 with rel Hrel,
apply subtype.eq,
dsimp,
unfold inv_fun,
funext r s,
sorry
end
}
#exit
import logic.function data.set.basic set_theory.cardinal
universes u v w x
open function
lemma eq.rec_thing {α : Sort*} (a : α) (h : a = a) (C : α → Sort*) (b : C a) : (eq.rec b h : C a) = b := rfl
def T : Type 1 := Σ α : Type, set α
set_option trace.simplify.rewrite true
lemma Type_1_bigger {α : Type} {f : T → α} : ¬injective f :=
λ h, cantor_injective (f ∘ sigma.mk α) $ injective_comp h (by simp [injective])
theorem forall_2_true_iff2 {α : Sort u} {β : α → Sort v} : (∀ (a b : α), true) ↔ true :=
by rw [forall_true_iff, forall_true_iff]
theorem forall_2_true_iff3 {α : Sort u} {β : α → Sort v} : (∀ (a b : α), true) ↔ true :=
by simp only [forall_true_iff, forall_true_iff]
example {α : Type} {f : α → T} : ¬ surjective f :=
λ h, Type_1_bigger (injective_surj_inv h)
#exit
constant a : ℕ
lemma empty_implies_false (f : empty → empty) : f = id :=
funext $ λ x, by cases x
#print has_equiv
structure thing {R : Type} [ring R]
{ type : Type }
( )
instance : has_repr pnat := subtype.has_repr
#eval ((@function.comp ℕ ℕ ℕ) ∘ (∘))
#print quotient.lift_on
noncomputable example (f : α → β) :
quotient (fun_rel f) ≃ set.range f :=
@equiv.of_bijective _ _ (λ a, @quotient.lift_on _ _ (fun_rel f) a
(λ a, show set.range f, from ⟨f a, set.mem_range_self _⟩)
(λ a b h, subtype.eq h))
⟨λ a b, @quotient.induction_on₂ _ _ (fun_rel f) (fun_rel f) _ a b begin
assume a b h,
exact quot.sound (subtype.mk.inj h),
end, λ ⟨a, ⟨x, ha⟩⟩, ⟨@quotient.mk _ (fun_rel f) x, by simp * ⟩⟩
noncomputable example {G H : Type*} [group G] [group H] (f : G → H) [is_group_hom f] :
{x : left_cosets (ker f) ≃ set.range f // is_group_hom x} :=
⟨@equiv.of_bijective _ _ (λ a, @quotient.lift_on _ _ (left_rel (ker f)) a
(λ a, show set.range f, from ⟨f a, set.mem_range_self _⟩)
(λ a b h, subtype.eq begin
show f a = f b,
rw [← one_mul b, ← mul_inv_self a, mul_assoc, is_group_hom.mul f, mem_trivial.1 h, mul_one],
end)) ⟨λ a b, @quotient.induction_on₂ _ _(left_rel (ker f)) (left_rel (ker f)) _ a b
(begin
assume a b h,
have : f a = f b := subtype.mk.inj h,
refine quot.sound (mem_trivial.2 _),
rw [mul f, ← this, ← mul f, inv_mul_self, one f]
end),
λ ⟨a, ha⟩,
let ⟨x, hx⟩ := set.mem_range.1 ha in
⟨@quotient.mk _ (left_rel (ker f)) x, subtype.eq hx⟩⟩,
⟨λ a b, @quotient.induction_on₂ _ _(left_rel (ker f)) (left_rel (ker f)) _ a b begin
assume a b,
rw equiv.of_bijective_to_fun,
exact subtype.eq (mul f _ _),
end⟩⟩
#print has_repr
instance : has_repr (finset α) :=
#exit
universes u v
axiom choice {α : Type u} (β : α → Type v)
(h : ∀ a : α, nonempty (β a)) : Π a, β a
example {α : Type u} : nonempty α → α :=
λ h, @choice unit (λ _, α) (λ _, h) ()
#print classical.axiom_of_choice
variable (α : Type)
def foo : semigroup α :=
begin
refine_struct { .. },
end
variables {a b c : ℕ}
#print empty.elim
lemma empty_implies_false (f : empty → empty) : f = id :=
#print empty_implies_false
#eval list.foldr ((∘) : (ℕ → ℕ) → (ℕ → ℕ) → ℕ → ℕ) id [nat.succ, nat.pred] 0
example (x : ℕ) (l : list ℕ) : list.prod (x :: l) = l.prod * x := rfl
example : list.prod [a, b, c] = sorry := begin
unfold list.prod list.foldl,
end
#print list.prod
open set
local attribute [instance] classical.prop_decidable
example (a b : Prop) : ((a → b) → (a ↔ b)) ↔ (b → a) :=
⟨λ h, begin
by_cases A : b,
simp [A, *] at *,
simp [A, *] at *,
end,
begin
intros; split; assumption
end⟩
-- so my goal is to define graphs
-- I find the best way to implement them is as a structure with a set of vertices and a binary relation on those vertices
-- I like the coercion from sets to subtypes, but it looks like it makes things a little complicated with the little experience I have (see below)
constants {V : Type} (vertices : set V) (edge : vertices → vertices → Prop)
-- this is an extra convenient definition to allow the creation of "set edges" below
def edges : set (vertices × vertices) := λ ⟨v₁,v₂⟩, edge v₁ v₂
-- I would like to reason on the edge binary relation rather than on the set of edges, that's why I suppose edge is a decidable rel
instance [H : decidable_rel edge] : decidable_pred edges := λ⟨v₁,v₂⟩, H v₁ v₂
-- set of edges whose tip is v ∈ vertices
-- used to define the "in-degree" of vertex v
-- in_edges has type "set edges" because I find it convenient, maybe it's not the best to do (too many coercions ?)
def in_edges (v : vertices) : set edges := let ⟨v,hv⟩ := v in λ⟨⟨_,⟨b,hb⟩⟩, _⟩, b = v
-- I need to use noncomputable because in_edges is a set whose base type is a subtype and
-- I only assume decidable_eq on V
-- but there exists subtype.decidable_eq...
#check subtype.decidable_eq
noncomputable instance [H : decidable_eq V] {v : vertices} : decidable_pred (in_edges v) := let ⟨v,hv⟩ := v in λ⟨⟨⟨a, ha⟩,⟨b,hb⟩⟩, _⟩, H b v
noncomputable instance {v : vertices} [fintype vertices] [decidable_rel edge] [decidable_eq V] : fintype (in_edges v) := @set_fintype _ (set_fintype _) _ _
variables [fintype vertices] [decidable_eq V] [decidable_rel edge]
-- now I want to define some stuff on finite graphs and prove some lemmas
-- for instance, the sum of the in_degrees of all the vertices is equal to fintype.card edges
-- which I did prove, but with another unpleasant setup
noncomputable def in_degree (v : vertices) := finset.card (in_edges v).to_finset
-- this doesn't work without the extra instances above
-- I would like instances to be inferred out-of-the-box but I didn't succeed
#exit
instance : fintype bool2 := bool.fintype
lemma card_bool1 : fintype.card bool2 = 2 :=
begin
refl,
end
def bool2_fintype : fintype bool2 := ⟨{tt, ff}, λ x, by cases x; simp⟩
def bool2_fintype3 : fintype bool2 := ⟨{ff, tt}, λ x, by cases x; simp⟩
lemma card_bool2 : @fintype.card bool2 bool2_fintype = 2 :=
card_bool1 -- They are defeq
lemma card_bool3 : @fintype.card bool2 bool2_fintype = 2 :=
begin
rw card_bool1, --doesn't work
end
lemma card_bool4 : @fintype.card bool2 bool2_fintype3 = 2 := card_bool1
#exit
#print rat.has_mul
def poly := list znum
def poly.is_eq_aux : list znum -> list znum -> bool
| [] [] := tt
| [] (h₂ :: t₂) := if (h₂ = 0) then poly.is_eq_aux [] t₂ else ff
| (h₁ :: t₁) [] := if (h₁ = 0) then poly.is_eq_aux t₁ [] else ff
| (h₁ :: t₁) (h₂ :: t₂) := if (h₁ = h₂) then poly.is_eq_aux t₁ t₂ else ff
def poly.is_eq : poly → poly → bool
| [] [] := tt
| [] (h₂ :: t₂) := if (h₂ = 0) then poly.is_eq [] t₂ else ff
| (h₁ :: t₁) [] := if (h₁ = 0) then poly.is_eq t₁ [] else ff
| (h₁ :: t₁) (h₂ :: t₂) := if (h₁ = h₂) then poly.is_eq t₁ t₂ else ff
#print default.sizeof
example (n : ℕ) : n ^ (n + 1) = sorry :=
begin
simp [nat.pow_succ],
end
def normalizer (H : set G) : set G :=
{ g : G | ∀ n, n ∈ H ↔ g * n * g⁻¹ ∈ H }
instance (H : set G) [is_subgroup H] : is_subgroup (normalizer H) :=
{ one_mem := show ∀ n : G, n ∈ H ↔ 1 * n * 1⁻¹ ∈ H, by simp,
mul_mem := λ a b (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H)
(hb : ∀ n, n ∈ H ↔ b * n * b⁻¹ ∈ H) n,
by rw [mul_inv_rev, ← mul_assoc, mul_assoc a, mul_assoc a, ← ha, hb],
inv_mem := λ a (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) n,
by rw [ha (a⁻¹ * n * a⁻¹⁻¹)];
simp [mul_assoc] }
lemma subset_normalizer (H : set G) [is_subgroup H] : H ⊆ normalizer H :=
λ g hg n, by rw [is_subgroup.mul_mem_cancel_left _ ((is_subgroup.inv_mem_iff _).2 hg),
is_subgroup.mul_mem_cancel_right _ hg]
instance (H : set G) [is_subgroup H] : normal_subgroup {x : normalizer H | ↑x ∈ H} :=
{ one_mem := show (1 : G) ∈ H, from is_submonoid.one_mem _,
mul_mem := λ a b ha hb, show (a * b : G) ∈ H, from is_submonoid.mul_mem ha hb,
inv_mem := λ a ha, show (a⁻¹ : G) ∈ H, from is_subgroup.inv_mem ha,
normal := λ a ha ⟨m, hm⟩, (hm a).1 ha }
local attribute [instance] left_rel normal_subgroup.to_is_subgroup
instance : group (left_cosets H) :=
{ one := ⟦1⟧,
mul := λ a b, quotient.lift_on₂ a b
(λ a b, ⟦a * b⟧)
(λ a₁ a₂ b₁ b₂ (hab₁ : a₁⁻¹ * b₁ ∈ H) (hab₂ : a₂⁻¹ * b₂ ∈ H),
quotient.sound
((is_subgroup.mul_mem_cancel_left H (is_subgroup.inv_mem hab₂)).1
(by rw [mul_inv_rev, mul_inv_rev, ← mul_assoc (a₂⁻¹ * a₁⁻¹),
mul_assoc _ b₂, ← mul_assoc b₂, mul_inv_self, one_mul, mul_assoc (a₂⁻¹)];
exact normal_subgroup.normal _ hab₁ _))),
mul_assoc := λ a b c, quotient.induction_on₃
a b c (λ a b c, show ⟦_⟧ = ⟦_⟧, by rw mul_assoc),
one_mul := λ a, quotient.induction_on a
(λ a, show ⟦_⟧ = ⟦_⟧, by rw one_mul),
mul_one := λ a, quotient.induction_on a
(λ a, show ⟦_⟧ = ⟦_⟧, by rw mul_one),
inv := λ a, quotient.lift_on a (λ a, ⟦a⁻¹⟧)
(λ a b hab, quotient.sound begin
show a⁻¹⁻¹ * b⁻¹ ∈ H,
rw ← mul_inv_rev,
exact is_subgroup.inv_mem (is_subgroup.mem_norm_comm hab)
end),
mul_left_inv := λ a, quotient.induction_on a
(λ a, show ⟦_⟧ = ⟦_⟧, by rw inv_mul_self) }
variables {I : Type*} (f : I → Type*)
open real
example : (sqrt 2 + sqrt 3) ^ 2 = 5 + 2 * sqrt 6 :=
begin
rw [pow_two, mul_add, add_mul, add_mul, ← pow_two, ← pow_two, sqr_sqrt, sqr_sqrt,
← sqrt_mul, ← sqrt_mul],
ring,
end
lemma g : 0.71 + 0.8 = 0.51 := rfl
#print g
example : (ℕ → fin 0) → false := λ f, nat.not_lt_zero (f 0).1 (f 0).2
instance semigroup1 [∀ i, semigroup $ f i] : semigroup (Π i : I, f i) :=
{ mul := begin intros, admit end,
mul_assoc := sorry
}
variables {α : Type*} {β : Type*}
noncomputable theory
namespace finset
lemma image_const [decidable_eq β] {s : finset α} (h : s ≠ ∅) (b : β) : s.image (λa, b) = singleton b :=
ext.2 $ assume b', by simp [exists_mem_of_ne_empty h, eq_comm]
@[simp] theorem max_singleton' [decidable_linear_order α] {a : α} : finset.max (singleton a) = some a :=
max_singleton
section Max
open option
variables [decidable_linear_order β] [inhabited β] {s : finset α} {f : α → β}
def maxi [decidable_linear_order β] [inhabited β] (s : finset α) (f : α → β) : β :=
(s.image f).max.iget
@[simp] lemma maxi_empty : (∅ : finset α).maxi f = default β := rfl
lemma maxi_mem (f : α → β) (h : s ≠ ∅) : s.maxi f ∈ s.image f :=
let ⟨a, ha⟩ := exists_mem_of_ne_empty h in
mem_of_max $ (iget_mem $ is_some_iff_exists.2 $ max_of_mem (mem_image_of_mem f ha))
lemma maxi_le {b : β} (hf : ∀a∈s, f a ≤ b) (hd : s = ∅ → default β ≤ b) : s.maxi f ≤ b :=
classical.by_cases
(assume h : s = ∅, by simp * at * )
(assume h : s ≠ ∅,
let ⟨a, ha, eq⟩ := mem_image.1 $ maxi_mem f h in
eq ▸ hf a ha)
lemma le_maxi {a : α} (h : a ∈ s) : f a ≤ s.maxi f :=
le_max_of_mem (mem_image_of_mem f h) (iget_mem $ is_some_iff_exists.2 $ max_of_mem (mem_image_of_mem f h))
lemma le_maxi_of_forall {b : β} (hb : ∀a∈s, b ≤ f a) (hd : s = ∅ → b ≤ default β) : b ≤ s.maxi f :=
classical.by_cases
(assume h : s = ∅, by simp * at * )
(assume h : s ≠ ∅,
let ⟨a, ha, eq⟩ := mem_image.1 $ maxi_mem f h in
eq ▸ hb a ha)
@[simp] lemma maxi_const {b : β} (h : s = ∅ → b = default β) : s.maxi (λa, b) = b :=
classical.by_cases
(assume h : s = ∅, by simp * at * )
(assume h, by simp [maxi, image_const h])
end Max
end finset
@[simp] lemma real.default_eq : default ℝ = 0 :=
rfl
namespace metric_space
open finset
instance fintype_function {α : β → Type*} [fintype β] [∀b, metric_space (α b)] :
metric_space (Πb, α b) :=
{ dist := λf g, maxi univ (λb, _root_.dist (f b) (g b)),
dist_self := assume f, by simp,
dist_comm := assume f g, by congr; funext b; exact dist_comm _ _,
dist_triangle := assume f g h, maxi_le
(assume b hb,
calc dist (f b) (h b) ≤ dist (f b) (g b) + dist (g b) (h b) : dist_triangle _ _ _
... ≤ maxi univ (λb, _root_.dist (f b) (g b)) + maxi univ (λb, _root_.dist (g b) (h b)) :
add_le_add (le_maxi hb) (le_maxi hb))
(by simp [le_refl] {contextual := tt}),
eq_of_dist_eq_zero := assume f g eq0, funext $ assume b, dist_le_zero.1 $ eq0 ▸
show dist (f b) (g b) ≤ maxi univ (λb, dist (f b) (g b)), from le_maxi (mem_univ b) }
#print axioms metric_space.fintype_function
end metric_space
#check (cardinal.{0})
#eval (∅ : finset ℕ).sup nat.succ
lemma h {α : Type*} (U : set α) : id '' U = U := by finish [set.image]
#print h
open nat int
lemma nat.mul_pow (a b n : ℕ) : (a * b) ^ n = a ^ n * b ^ n :=
by induction n; simp [*, nat.pow_succ, mul_comm, mul_assoc, mul_left_comm]
lemma nat.dvd_of_pow_dvd_pow : ∀ {a b n : ℕ}, 0 < n → a ^ n ∣ b ^ n → a ∣ b
| a 0 := λ n hn h, dvd_zero _
| a (b+1) := λ n hn h,
let d := nat.gcd a (b + 1) in
have hd : nat.gcd a (b + 1) = d := rfl,
match d, hd with
| 0 := λ hd, (eq_zero_of_gcd_eq_zero_right hd).symm ▸ dvd_zero _
| 1 := λ hd,
begin
have h₁ : a ^ n = 1 := coprime.eq_one_of_dvd (coprime.pow n n hd) h,
have := pow_dvd_pow a hn,
rw [nat.pow_one, h₁] at this,
exact dvd.trans this (one_dvd _),
end
| (d+2) := λ hd,
have (b+1) / (d+2) < (b+1) := div_lt_self dec_trivial dec_trivial,
have ha : a = (d+2) * (a / (d+2)) :=
by rw [← hd, nat.mul_div_cancel' (gcd_dvd_left _ _)],
have hb : (b+1) = (d+2) * ((b+1) / (d+2)) :=
by rw [← hd, nat.mul_div_cancel' (gcd_dvd_right _ _)],
have a / (d+2) ∣ (b+1) / (d+2) := nat.dvd_of_pow_dvd_pow hn $ dvd_of_mul_dvd_mul_left
(show (d + 2) ^ n > 0, from pos_pow_of_pos _ (dec_trivial))
(by rwa [← nat.mul_pow, ← nat.mul_pow, ← ha, ← hb]),
by rw [ha, hb];
exact mul_dvd_mul_left _ this
end
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf psigma.snd⟩]}
lemma int.nat_abs_pow (a : ℤ) (n : ℕ) : a.nat_abs ^ n = (a ^ n).nat_abs :=
by induction n; simp [*, nat.pow_succ, _root_.pow_succ, nat_abs_mul, mul_comm]
lemma int.dvd_of_pow_dvd_pow {a b : ℤ} {n : ℕ} (hn : 0 < n) (h : a ^ n ∣ b ^ n) : a ∣ b :=
begin
rw [← nat_abs_dvd, ← dvd_nat_abs, ← int.nat_abs_pow, ← int.nat_abs_pow, int.coe_nat_dvd] at h,
rw [← nat_abs_dvd, ← dvd_nat_abs, int.coe_nat_dvd],
exact nat.dvd_of_pow_dvd_pow hn h
end
lemma int.cast_pow {α : Type*} [ring α] (a : ℤ) (n : ℕ) : ((a ^ n : ℤ) : α) = (a : α) ^ n :=
by induction n; simp [*, _root_.pow_succ]
def nth_root_irrational {x : ℤ} {a : ℚ} {n : ℕ} (hn : 0 < n) (h : a ^ n = x) : {a' : ℤ // a = a'} :=
have had : ((a.denom : ℤ) : ℚ) ≠ 0 := int.cast_ne_zero.2 (ne_of_lt (int.coe_nat_lt.2 a.3)).symm,
⟨a.num,
begin
rw [rat.num_denom a, rat.mk_eq_div, div_pow _ had, div_eq_iff_mul_eq (pow_ne_zero _ had),
← int.cast_pow, ← int.cast_mul, ← int.cast_pow, int.cast_inj] at h,
have := int.coe_nat_dvd.1 (dvd_nat_abs.2 (int.dvd_of_pow_dvd_pow hn (dvd_of_mul_left_eq _ h))),
have := coprime.eq_one_of_dvd a.4.symm this,
rw [rat.num_denom a, rat.mk_eq_div, this],
simp,
end⟩
instance : euclidean_domain ℤ :=
{ quotient := (/),
remainder := (%),
quotient_mul_add_remainder_eq := λ a b,
by rw [mul_comm, add_comm, int.mod_add_div],
valuation := int.nat_abs,
valuation_remainder_lt := λ a b hb, int.coe_nat_lt.1
(by rw [← abs_eq_nat_abs b, nat_abs_of_nonneg (mod_nonneg _ hb)]; exact int.mod_lt a hb),
le_valuation_mul := λ a b hb, by rw nat_abs_mul;
exact le_mul_of_ge_one_right' (nat.zero_le _)
(nat.pos_of_ne_zero (λ h, hb (eq_zero_of_nat_abs_eq_zero h))) }
#exit
def is_isom (G H : Σ α : Type*, group α) := nonempty (isom G H)
def lift_from {α β γ : Type*} (e : α ≃ β) (f : α → γ) (b : β) : γ := f (e.inv_fun b)
def lift_to {α β γ : Type*} (e : α ≃ β) (f : γ → α) (g : γ) : β := e (f g)
def lift_to_from {α β γ : Type*} (e : α ≃ β) (f : α → α) (b : β) : β := lift_from
class isom
def ring_of_ring_of_equiv (α β : Type*) [ring α] (e : α ≃ β) : ring β :=
{ mul := λ a b, e (e.inv_fun a * e.inv_fun b),
mul_assoc := λ a b c, begin unfold_coes, rw [e.left_inv, e.left_inv, mul_assoc], end
}
theorem canonical_iso_is_canonical_hom {R : Type u} [comm_ring R] {f g : R} (H : Spec.D' g ⊆ Spec.D' f) :
let gbar := of_comm_ring R (powers f) g in
let sα : R → loc (away f) (powers gbar) :=
of_comm_ring (away f) (powers gbar) ∘ of_comm_ring R (powers f) in
let sγ := (of_comm_ring R (non_zero_on_U (Spec.D' g))) in
by letI H2 := (canonical_iso H).is_ring_hom;
letI H3 : is_ring_hom sα := by apply_instance;
letI H4 : is_ring_hom sγ := by apply_instance; exact
@is_unique_R_alg_hom _ _ _ _ _ _ sγ sα (canonical_iso H).to_fun H4 H3 H2 :=
def disjoint {α β : Type*} [has_mem α β] (s t : β) := ∀ ⦃a : α⦄, a ∈ s → a ∈ t → false
def disjoint1 {α β : Type*} [has_mem α β] (s t : β) := ∀ ⦃a : α⦄, a ∈ s → a ∈ t → false
def add (n m : ℕ) : ℕ := nat.rec n (λ n, nat.succ) m
#eval add 34 3
example (X : Type) (R : Type) (D : R → set X) (γ : Type) (f : γ → R) :
⋃₀(D '' set.range f) = ⋃ (i : γ), D (f i) := set.ext (λ x, begin
rw set.sUnion_image, simp,
end)
theorem mk_eq : ∀ {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0),
a /. b = c /. d ↔ a * d = c * b :=
suffices ∀ a b c d hb hd, mk_pnat a ⟨b, hb⟩ = mk_pnat c ⟨d, hd⟩ ↔ a * d = c * b,
[...]
example {p q t : ℕ+} {xp xq : ℤ} {m n : ℕ} (hm : (t : ℕ) = ↑p * m) (hn : (t : ℕ) = ↑q * n)
(hpqt : xp * m = xq * n) : xp * q = xq * p :=
have hm0 : (m : ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ h, lt_irrefl (0 : ℕ) (trans_rel_left
(<) t.2 (by rwa [h, mul_zero] at hm))),
have hm' : (t : ℤ) = p * m := show ((t : ℕ) : ℤ) = p * m, from hm.symm ▸ by simp,
have hn' : (t : ℤ) = q * n := show ((t : ℕ) : ℤ) = q * n, from hn.symm ▸ by simp,
(domain.mul_right_inj hm0).1
(by rw [mul_assoc xq, ← hm', hn', mul_left_comm, ← hpqt, mul_left_comm, mul_assoc])
inductive natε : Type
| ofnat : ℕ → natε
| addε : ℕ → natε
open natε
def add : natε → natε → natε
| (ofnat a) (ofnat b) := ofnat (a + b)
| (ofnat a) (addε b) := addε (a + b)
| (addε a) (ofnat b) := addε (a + b)
| (addε a) (addε b) := addε (a + b)
instance : has_add (natε) := ⟨add⟩
instance : add_comm_monoid natε :=
{ add := (+),
zero := ofnat 0,
add_assoc := λ a b c, by cases a; cases b; cases c; begin unfold has_add.add add,simp, end
}
example : α ≃ set α → false :=
λ f, function.cantor_surjective f f.bijective.2
lemma infinite_real : ¬ nonempty (fintype ℝ) := λ ⟨h⟩, set.infinite_univ_nat
(set.finite_of_finite_image
(show function.injective (@nat.cast ℝ _ _ _), from λ x y, nat.cast_inj.1)
⟨@set_fintype ℝ h _ (classical.dec_pred _)⟩)
lemma omega_le_real : cardinal.omega ≤ ⟦ℝ⟧ :=
le_of_not_gt (λ h, infinite_real (cardinal.lt_omega_iff_fintype.1 h))
noncomputable def real_equiv_complex : ℝ ≃ ℂ :=
equiv.trans
(classical.choice (quotient.exact (cardinal.mul_eq_self omega_le_real).symm))
⟨λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨_, _⟩, rfl, λ ⟨_, _⟩, rfl⟩
attribute [instance] classical.prop_decidable
theorem cantor_surjective (f : α → α → Prop) : ¬ function.surjective f | h :=
let ⟨D, e⟩ := h (λ a, ¬ f a a) in
(iff_not_self (f D D)).1 (iff_of_eq (congr_fun e D))
#print cantor_surjective
lemma em1 (p : Prop) : p ∨ ¬ p :=
have h : xor (xor true p) p :=
begin
unfold xor,
end,
sorry⟩
#print eq.refl
def real_equiv_real_squared : ℝ ≃ (ℝ × ℝ) :=
{ to_fun :=
}
lemma red.trans {L₁ L₂ L₃ : list (α × bool)} (H12 : red L₁ L₂) (H23 : red L₂ L₃) : red L₁ L₃ :=
begin
induction H23 with L1 L1 L2 L3 x b H ih generalizing L₁,
case red.refl
{ assumption },
case red.trans_bnot
{ exact red.trans_bnot (ih H12) }
end
lemma church_rosser {L₁ L₂ L₃ : list (α × bool)} (H12 : red L₁ L₂) (H13: red L₁ L₃) :
∃ L₄, red L₂ L₄ ∧ red L₃ L₄ :=
begin
induction H12 with L1 L1 L2 L3 x1 b1 H1 ih1 generalizing L₃,
case red.refl
{ exact ⟨L₃, H13, red.refl⟩ },
case red.trans_bnot
{ specialize ih1 H13,
rcases ih1 with ⟨L₄, H24, H34⟩,
revert H24,
generalize HL23 : L2 ++ (x1, b1) :: (x1, bnot b1) :: L3 = L23,
intro H24,
induction H24 with L4 L4 L5 L6 x2 b2 H2 ih2,
case red.refl
{ subst HL23,
exact ⟨_, red.refl, red.trans_bnot H34⟩ },
case red.trans_bnot
{ subst HL23,
admit } }
end
open equiv
variables {α : Type*}
#print not_iff
lemma mul_apply (a b : perm α) (x : α) : (a * b) x = (a (b x)) := rfl
@[simp] lemma one_apply (x : α) : (1 : perm α) x = x := rfl
def support (a : perm α) : set α := {x : α | a x ≠ x}
set_option pp.implicit true
set_option pp.notation false
example (a b n : ℕ) : (a * b)^n = a^n * b^n := begin have end
example (f g : perm α) : support (g * f * g⁻¹) = g '' support f :=
set.ext $ λ y, ⟨λ h : _ ≠ _, ⟨g⁻¹ y, λ h₁, by
rw [mul_apply, mul_apply, h₁, ← mul_apply, mul_inv_self] at h;
exact h rfl,
show (g * g⁻¹) y = y, by rw mul_inv_self; refl⟩,
λ ⟨x, (hx : _ ≠ _ ∧ _)⟩, show _ ≠ _,
begin
rw [mul_apply, ← hx.2, ← mul_apply, ← mul_apply, mul_assoc, inv_mul_self, mul_one, mul_apply],
assume h,
rw (equiv.bijective g).1 h at hx,
exact hx.1 rfl
end⟩
example (f g : perm α) : {x : X | conj g f x ≠ x} = {b : X | f (g⁻¹ b) ≠ g⁻¹ b}
universes u v l
variables {α : Type u} {β : Type v} {γ : Type*}
example (n : ℕ) (summand : ℕ → ℕ) : finset.sum finset.univ (λ (x : fin (succ n)), summand (x.val)) =
summand n + finset.sum finset.univ (λ (x : fin n), summand (x.val)) := begin
rw [← insert_erase (mem_univ (⟨n, lt_succ_self n⟩: fin (succ n))), sum_insert (not_mem_erase _ _)],
refine congr_arg _ _,
exact sum_bij (λ ⟨i, hi⟩ h, ⟨i, lt_of_le_of_ne (le_of_lt_succ hi) (fin.vne_of_ne (mem_erase.1 h).1)⟩) (λ _ _, mem_univ _)
(λ ⟨_, _⟩ _, rfl) (λ ⟨a, _⟩ ⟨b, _⟩ _ _ (h : _), fin.eq_of_veq (show a = b, from fin.veq_of_eq h))
(λ ⟨b, hb⟩ _, ⟨⟨b, lt_succ_of_lt hb⟩, ⟨mem_erase.2 ⟨fin.ne_of_vne (ne_of_lt hb), mem_univ _⟩, rfl⟩⟩)
end
#print num
example : (λ n : ℕ, 0) = (λ n, 0) := begin funext, end
example (n : ℕ) : (range n).sum (λ i, 2 * i + 1) = n * n :=
begin
induction n with n hi,
refl,
rw [range_succ, sum_insert (λ h, lt_irrefl _ (mem_range.1 h)), hi, ← add_one],
ring,
end
theorem meh {i : ℕ} {n : ℕ} : i < n → i < nat.succ n := λ H, lt.trans H $ nat.lt_succ_self _
#print sum_attach
theorem miracle (f : ℕ → ℕ)
(d : ℕ)
(Hd :
∀ (g : fin d → ℕ),
(∀ (i : fin d), f (i.val) = g i) →
finset.sum (finset.range d) f = finset.sum finset.univ g)
(g : fin (nat.succ d) → ℕ)
(h : ∀ (i : fin (nat.succ d)), f (i.val) = g i)
: finset.sum (finset.range d) f = finset.sum finset.univ (λ (i : fin d), g ⟨i.val, meh i.is_lt⟩)
:=
let gres : fin d → ℕ := λ (i : fin d), g ⟨i.val, meh i.is_lt⟩ in
by rw Hd gres (λ i, h ⟨i.val, _⟩)
#print miracle
example (n : ℕ) (f : ℕ → ℕ) (g : fin n → ℕ) (h : ∀ i : fin n, f i.1 = g i) :
(range n).sum f = univ.sum g :=
sum_bij (λ i h, ⟨i, mem_range.1 h⟩) (λ _ _, mem_univ _) (λ a ha, h ⟨a, mem_range.1 ha⟩)
(λ _ _ _ _, fin.veq_of_eq) (λ ⟨b, hb⟩ _, ⟨b, mem_range.2 hb, rfl⟩)
lemma fin_sum (n : ℕ) (f : ℕ → ℕ) : (range n).sum f = univ.sum (f ∘ @fin.val n) :=
sum_bij (λ i h, fin.mk i (mem_range.1 h)) (λ _ _, mem_univ _) (λ _ _, rfl) (λ _ _ _ _, fin.veq_of_eq)
(λ ⟨b, hb⟩ _, ⟨b, mem_range.2 hb, rfl⟩)
#print fin_sum
#print fin_sum
#check multiset.pmap_eq_map
example (f : β → α) (g : γ → α) (s : finset γ)
lemma wilson (p : ℕ) (hp : prime p) : fact (p - 1) ≡ p - 1 [MOD p] :=
begin
end
inductive ev : nat → Prop
| ev_0 : ev 0
| ev_SS : ∀ n : nat, ev n → ev (n+2)
open ev
lemma ev_one : ¬ ev 1 := λ h, by cases h
#print ev_one
def double (n : ℕ) := n + n
lemma ev_double (n : ℕ) : ev (double n) :=
nat.rec ev_0 (λ n h, show ev (_ + _), from (succ_add (succ n) n).symm ▸ ev_SS _ h) n
example {α : Sort*} {f : perm α} : ∃ g h : perm α, g ∘ g = id ∧ h ∘ h = id ∧ f.1 = g ∘ h := begin
end
inductive P : ℕ → Prop
| intro (n : ℕ) : P n
#print ulift
inductive P1 (n : ℕ) : Prop
| intro : P1
#print P1.rec
#print P.rec
inductive eq2 : α → α → Prop
| refl : ∀ a, eq2 a a
#print eq2.rec
#print nat.div
inductive mystery : Sort u
| A : mystery
| B : mystery
#print mystery.rec
def f (n : ℕ) : P n → ℕ := @P.rec (λ n, ℕ) id n
def bla5d (n : ℕ) : ℕ := P.rec id (P.intro n)
lemma zero_one : P 0 = P 1 := propext ⟨λ _, P.intro 1, λ _, P.intro 0⟩
example : f 0 (P.intro 0) = f 1 (P.intro 1)
#print subtype
#check ℕ → ℤ
lemma succ_inj2 (n m : ℕ) : succ n = succ m → n = m :=
λ h, show natnc (succ n) = natnc (succ m), from eq.rec (eq.refl _) h
lemma succ_addax : ∀ b a : ℕ, succ a + b = succ (a + b) :=
λ a, nat.rec (λ a, eq.refl _) (λ a hi b,
show succ (succ b + a) = succ (succ (b + a)),
from eq.rec (eq.refl _) (hi b)) a
lemma zero_addax : ∀ a : ℕ, 0 + a = a :=
λ b, nat.rec (eq.refl zero)
(λ c (hc : 0 + c = c), show succ (0 + c) = succ c,
from @eq.rec _ _ (λ d, succ (0 + c) = succ d)
(show succ (0 + c) = succ (0 + c), from eq.refl _) _ hc) b
lemma add_commax : ∀ a b : ℕ, a + b = b + a := λ a,
nat.rec (λ b, zero_addax b)
(λ b hi c, show succ b + c = succ (c + b),
from eq.rec (eq.rec (succ_addax c b) (hi c)) (succ_addax c b)) a
#print nat.rec
inductive T : Prop
| mk : T → T
#print nat.strong_rec_on
lemma not_T : ¬T := λ h, T.rec_on h (λ _, id)
#print unit.rec
#print eq.rec
lemma f (n m : ℕ) : n = m → n = m :=
λ h, eq.rec rfl h
#print f
inductive T2
| mk : T2 → T2
example : T2 → false := λ t, T2.rec_on t (λ _, id)
inductive xnat
| zero : xnat
| succ : xnat → xnat
inductive prod2 (α β : Type*)
| mk (fst : α) (snd : β) : prod2
inductive prod3 (α β : Type*)
| mk (fst : α) (snd : β) : prod3
def prod2.fst (α β : Type*) (x : prod2 α β) : α :=
prod2.rec (λ a _, a) x
#print sum
inductive pint
| one : pint
| d : pint → pint
| da : pint → pint
inductive xnat1
| succ : xnat1 → xnat1
| zero : xnat1
| blah : xnat1 → xnat1
#print xnat1.rec
open pint
#print pint.rec_on
def padd_one : pint → pint
| one := d one
| (d m) := da m
| (da m) := d (padd_one m)
def padd : pint → pint → pint
| one m := padd_one m
| n one := padd_one n
| (d n) (d m) := d (padd n m)
| (d n) (da m) := da (padd n m)
| (da n) (d m) := da (padd n m)
| (da n) (da m) := d (padd_one (padd n m))
inductive rel : pint → pint → Prop
| oned : ∀ n : pint, rel one (d n)
| oneda : ∀ n : pint, rel one (da n)
def pintwf : has_well_founded Σ' pint, pint :=
{ r := rel,
wf := well_founded.intro sorry
}
lemma sizeof_pos : ∀ n : pint, 0 < pint.sizeof n
| one := dec_trivial
| (d m) := by unfold pint.sizeof; rw add_comm; exact succ_pos _
| (da m) := by unfold pint.sizeof; rw add_comm; exact succ_pos _
def padd2 : pint → pint → pint
| one one := d one
| one (d m) := da m
| one (da m) := d (padd2 one m)
| (d n) one := da n
| (d n) (d m) := d (padd2 n m)
| (d n) (da m) := da (padd2 n m)
| (da n) one := d (padd2 n one)
| (da n) (d m) := da (padd2 n m)
| (da n) (da m) := have h : 0 < pint.sizeof n, from sizeof_pos _,
d (padd2 one (padd2 n m))
#print nat.below
inductive eq2 (a : ℕ) : ℤ → Prop
| refl : eq2 2
inductive eq3 : Π {α : Sort u}, α → α → Prop
| refl : ∀ {α : Sort u} (a : α), eq3 a a
inductive bla3 (a : ℕ) : ℤ → Prop
| one : ∀ i : ℤ, bla3 (i + a)
| two : bla3 2
| three : ∀ i : ℤ, i < a → bla3 i
inductive bla4 (a : ℕ) : ℕ → Type
| one : Π n : ℕ, bla4 (a + n)
inductive bla5 : ℕ → Prop
| intro (n : ℕ) : bla5 n
#print bla5.rec
def fb (n : ℕ) : bla5 n → ℕ := @bla5.rec (λ n, ℕ) id n
def bla5d (n : ℕ) : ℕ := bla5.rec id (bla5.intro n)
#eval bla5d 5
#reduce bla5d 5
lemma zero_one : bla5 0 = bla5 1 := propext ⟨λ _, bla5.intro 1, λ _, bla5.intro 0⟩
example : @bla5.rec (λ n, ℕ) id (bla5.intro 0) : ℕ) = bla5.rec id (bla5.intro 1) :=
@eq.drec_on Prop (bla5 1) (λ a b, begin end) (bla5 2) zero_one rfl
axiom bla4.rec2 : ∀ {a : ℕ} {C : ℕ → Sort l}, (∀ (n : ℕ), C (a + n)) →
∀ {b : ℕ}, bla4 a b → C b
#print bla4.rec
axiom bla4_iota {a : ℕ} {C : ℕ → Sort l} (f : Π n, C (a + n)) {b : ℕ}
: @bla4.rec a C f b (bla4.one b) =
#print bla4.rec
#print acc.rec
#print eq
#print eq3
#print eq.rec
#print bla3.rec
#print list.perm.rec
#print psum.rec
lemma bla3.rec2 {a : ℕ} {C : ℤ → Sort l} : (Π i : ℤ, C (i + a)) → C 2 →
(Π i : ℤ, i < a → C i) → Π i : ℤ, bla3 a i → C i := @bla3.rec a C
#print eq2.rec
universe l
#print nat.no_confusion_type
#print nat.no_confusion
#print nat.succ.inj
#print int.cases_on
#print int.rec_on
lemma no_confusion1 : Π {P : Sort l} {v1 v2 : ℕ}, v1 = v2 → nat.no_confusion_type P v1 v2 :=
assume P v1 v2 h,begin
rw h,
induction v2,
exact id,
assume h,
exact h rfl,
end
lemma preod {α β : Type*} (p : α × β) : p = prod.mk p.fst p.snd :=
prod.rec (λ f s, rfl) p
#print sigma.rec
lemma bla (P Q R : Prop) : (P ∧ Q → R) ↔ (P → (Q → R)) :=
iff.intro (λ h hp hq, h (and.intro hp hq)) (λ h hpq, h (and.left hpq) (and.right hpq))
#print bla
lemma succ_inj {n m : ℕ} : nat.succ m = nat.succ n → m = n :=
λ h, nat.no_confusion h id
lemma succ_ne_zero (n : ℕ) : nat.succ n ≠ nat.zero :=
@nat.no_confusion _ (nat.succ n) nat.zero
lemma succ_ne (n : ℕ) : nat.succ n ≠ n :=
nat.rec (succ_ne_zero nat.zero) (λ n h hi, h $ succ_inj hi) n
#print prod
def bool.no_confusion_type1 : Sort l → bool → bool → Sort l :=
λ P v1 v2, bool.rec (bool.rec (P → P) P v2)
(bool.rec P (P → P) v2) v1
lemma prod.mk_inj {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: (x₁, y₁) = (x₂, y₂) → and (x₁ = x₂) (y₁ = y₂) :=
λ h, ⟨show (x₁, y₁).fst = (x₂, y₂).fst, from eq.rec (eq.refl _) h,
show (x₁, y₁).snd = (x₂, y₂).snd, from eq.rec (eq.refl _) h⟩
set_option pp.implicit true
example : @bool.no_confusion_type1 = @bool.no_confusion_type := rfl
def f : xnat → bool := λ n, xnat.rec ff (λ n h, bnot h) n
lemma bool.no_confusion1 {v1 v2 : bool} : v1 = v2 → bool.no_confusion_type1 false v1 v2 :=
λ h, eq.rec (bool.rec id id v1) h
example : tt ≠ ff := bool.no_confusion1
example (n : xnat) : succ n ≠ n := xnat.rec n begin end sorry
axiom em2 (p : Prop) : p ∨ ¬p
lemma choice2 {α : Sort*} : nonempty (nonempty α → α) :=
begin
have := em2 (nonempty α),
cases this,
cases this,
exact ⟨λ h, this⟩,
exact ⟨λ h, false.elim (this h)⟩
end
inductive acc2 {α : Sort u} (r : α → α → Prop) : α → Prop
| intro (x : α) (h : ∀ y, r y x → acc2 y) : acc2 x
#print prefix acc2
axiom em3 (p : Prop) : decidable p
|
State Before: a b c : ℕ
⊢ Fintype.card ↑(Set.Ioo a b) = b - a - 1 State After: no goals Tactic: rw [Fintype.card_ofFinset, card_Ioo] |
module AND where
import Numeric.LinearAlgebra
import AI.HNN.FF.Network
samples :: Samples Double
samples = [ (fromList [0,0], fromList [1,0])
, (fromList [0,1], fromList [1,0])
, (fromList [1,0], fromList [1,0])
, (fromList [1,1], fromList [0,1]) ]
run :: IO ()
run = do
n <- createNetwork 2 [2] 2
mapM_ (print . output n tanh . fst) samples
putStrLn "----------------"
let n' = trainNTimes 1000 0.8 tanh tanh' n samples
mapM_ (print . output n' tanh . fst) samples
|
import NewEden.Natural
import NewEden.Implementations.Int64
{- Int64
At present, this is pretty much completely worthless, as Idris doesn't have
unboxed primitives, which means you're not gaining any practically significant
performance by using this over GMP integers.
But hopefully in the future they'll be available. Along with unboxed arrays.
-}
x : Natural Int64
x = 1024
y : Natural Int64
y = 12345
z : Natural Int64
z = x * y + y * x
|
import data.nat.basic
example (a b : ℕ) (h : a ≠ b) : b ≠ a :=
begin
symmetry,
exact h,
end
|
From cgraphs.locks.lambdalockpp Require Export langdef.
(* The definition of the set of barrier references in an expression. *)
Fixpoint expr_refs e :=
match e with
| Val v => val_refs v
| Var x => ∅
| Fun x e => expr_refs e
| App e1 e2 => expr_refs e1 ∪ expr_refs e2
| Unit => ∅
| Pair e1 e2 => expr_refs e1 ∪ expr_refs e2
| LetPair e1 e2 => expr_refs e1 ∪ expr_refs e2
| Sum i e => expr_refs e
| MatchSum n e es => expr_refs e ∪ fin_union n (expr_refs ∘ es)
| ForkBarrier e => expr_refs e
| NewLock i e => expr_refs e
| DropLock i e => expr_refs e
| ForkLock e1 e2 => expr_refs e1 ∪ expr_refs e2
| Acquire i e => expr_refs e
| Release i e1 e2 => expr_refs e1 ∪ expr_refs e2
| Wait i e => expr_refs e
| NewGroup => ∅
| DropGroup e => expr_refs e
end
with val_refs v :=
match v with
| FunV x e => expr_refs e
| UnitV => ∅
| PairV v1 v2 => val_refs v1 ∪ val_refs v2
| SumV i v => val_refs v
| BarrierV i => {[ i ]}
| LockGV i ls => {[ i ]}
end.
Definition gmap_union `{Countable K} {V} `{Countable R} (f : V -> gset R) (xs : gmap K V) : gset R :=
map_fold (λ k a s, s ∪ f a) ∅ xs.
Definition obj_refs x :=
match x with
| Thread e => expr_refs e
| Barrier => ∅
| LockG refcnt xs => gmap_union (from_option val_refs ∅ ∘ snd) xs
end.
Inductive expr_head_waiting : expr -> nat -> Prop :=
| Barrier_waiting j v :
expr_head_waiting (App (Val $ BarrierV j) (Val v)) j
| ForkLock_waiting j v ls :
expr_head_waiting (ForkLock (Val $ LockGV j ls) (Val v)) j
| Acquire_waiting j ls i :
expr_head_waiting (Acquire i (Val $ LockGV j ls)) j
| Release_waiting j v ls i :
expr_head_waiting (Release i (Val $ LockGV j ls) (Val v)) j
| Wait_waiting j ls i :
expr_head_waiting (Wait i (Val $ LockGV j ls)) j
| NewLock_waiting j ls i :
expr_head_waiting (NewLock i (Val $ LockGV j ls)) j
| DropLock_waiting j ls i :
expr_head_waiting (DropLock i (Val $ LockGV j ls)) j
| DropGroup_waiting j ls :
expr_head_waiting (DropGroup (Val $ LockGV j ls)) j.
(* Paper definition 2 *)
Definition expr_waiting e j :=
∃ k e', ctx k ∧ e = k e' ∧ expr_head_waiting e' j.
Definition waiting (ρ : cfg) (i j : nat) :=
(∃ e, ρ !! i = Some (Thread e) ∧ expr_waiting e j) ∨
(∃ y, ρ !! j = Some y ∧ i ∈ obj_refs y ∧ ∀ e, y = Thread e -> ¬ expr_waiting e i).
(* These definitions are not explicitly given in the paper, but we factor them out in Coq *)
Definition can_step (ρ : cfg) (i : nat) := ∃ ρ', step i ρ ρ'.
Definition inactive (ρ : cfg) (i : nat) := ρ !! i = None.
(* Paper definition 3 *)
Record deadlock (ρ : cfg) (s : nat -> Prop) := {
dl_nostep i : s i -> ¬ can_step ρ i;
dl_waiting i j : waiting ρ i j -> s i -> s j;
}.
(* Paper definition 4 *)
Definition deadlock_free (ρ : cfg) :=
∀ s, deadlock ρ s -> ∀ i, s i -> inactive ρ i.
(* Paper definition 5 *)
Inductive reachable (ρ : cfg) : nat -> Prop :=
| Can_step_reachable i :
can_step ρ i -> reachable ρ i
| Waiting_reachable i j :
waiting ρ i j -> reachable ρ j -> reachable ρ i.
(* Paper definition 6 *)
Definition fully_reachable (ρ : cfg) :=
∀ i, inactive ρ i ∨ reachable ρ i.
(* Paper definition 8 *)
Definition global_progress (ρ : cfg) :=
(∀ i, inactive ρ i) ∨ (∃ i, can_step ρ i).
(* Paper definition 9 *)
Definition type_safety (ρ : cfg) :=
∀ i, inactive ρ i ∨ can_step ρ i ∨ ∃ j, waiting ρ i j.
|
= = Poem = =
|
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Test.Grenade.Layers.Add where
import Data.Constraint
import Data.Maybe (fromJust)
import Data.Proxy
import Unsafe.Coerce
import GHC.TypeLits
import Grenade.Core
import Grenade.Layers.Add
import Numeric.LinearAlgebra hiding (R, konst, randomVector,
uniformSample, (===), reshape)
import qualified Numeric.LinearAlgebra.Data as D
import Numeric.LinearAlgebra.Static (L, R)
import qualified Numeric.LinearAlgebra.Static as H
import Hedgehog
import Test.Hedgehog.Compat
import Test.Hedgehog.Hmatrix
prop_add_zero_does_nothing = property $ do
height :: Int <- forAll $ choose 2 100
width :: Int <- forAll $ choose 2 100
channels :: Int <- forAll $ choose 2 100
case (someNatVal (fromIntegral height), someNatVal (fromIntegral width), someNatVal (fromIntegral channels)) of
(Just (SomeNat (Proxy :: Proxy h)), Just (SomeNat (Proxy :: Proxy w)), Just (SomeNat (Proxy :: Proxy c))) -> do
input :: S ('D3 h w c) <- forAll genOfShape
let layer = initAdd :: Add c 1 1
S3D out = snd $ runForwards layer input :: S ('D3 h w c)
S3D inp' = input :: S ('D3 h w c)
H.extract inp' === H.extract out
prop_add_per_channel_words_as_expected = property $ do
height :: Int <- forAll $ choose 2 100
width :: Int <- forAll $ choose 2 100
case (someNatVal (fromIntegral height), someNatVal (fromIntegral width)) of
(Just (SomeNat (Proxy :: Proxy h)), Just (SomeNat (Proxy :: Proxy w))) ->
case ( unsafeCoerce (Dict :: Dict ()) :: Dict ( (h * 3) ~ (h + h + h) ) ) of
Dict -> do
channel_one :: R (h * w) <- forAll randomVector
channel_two :: R (h * w) <- forAll randomVector
channel_three :: R (h * w) <- forAll randomVector
bias :: R 3 <- forAll randomVector
let reshape = fromJust . H.create . (D.reshape width) . H.extract
c1 = reshape channel_one :: L h w
c2 = reshape channel_two :: L h w
c3 = reshape channel_three :: L h w
bias' = H.extract bias
o1 = H.dmmap (\a -> a + bias' ! 0) c1 :: L h w
o2 = H.dmmap (\a -> a + bias' ! 1) c2 :: L h w
o3 = H.dmmap (\a -> a + bias' ! 2) c3 :: L h w
out = o1 H.=== o2 H.=== o3 :: L (h * 3) w
inp = c1 H.=== c2 H.=== c3 :: L (h * 3) w
layer = Add bias :: Add 3 1 1
inp' = S3D inp :: S ('D3 h w 3)
S3D out' = snd $ runForwards layer inp' :: S ('D3 h w 3)
H.extract out === H.extract out'
tests :: IO Bool
tests = checkParallel $$(discover)
|
Formal statement is: lemma nullhomotopic_from_contractible_space: assumes f: "continuous_map X Y f" and X: "contractible_space X" obtains c where "homotopic_with (\<lambda>h. True) X Y f (\<lambda>x. c)" Informal statement is: If $X$ is a contractible space and $f: X \to Y$ is a continuous map, then $f$ is nullhomotopic. |
lemma span_Basis [simp]: "span Basis = UNIV" |
While the true origins of the rhyme are unknown there are several theories . As is common with nursery rhyme exegesis , complicated metaphors are often said to exist within the lyrics of Jack and Jill . Most explanations post @-@ date the first publication of the rhyme and have no corroborating evidence . These include the suggestion by S. Baring @-@ Gould in the 19th century that the events were a version of the story told in the 13th @-@ century Prose Edda Gylfaginning written by Icelandic historian Snorri Sturluson , who stated that in Norse mythology , Hjúki and Bil , brother and sister ( respectively ) , were taken up from the earth by the moon ( personified as the god Máni ) as they were fetching water from the well called <unk> , bearing on their shoulders the cask called <unk> and the pole called <unk> . Around 1835 John Bellenden Ker suggested that Jack and Jill were two priests , and this was enlarged by Katherine Elwes in 1930 to indicate that Jack represented Cardinal Wolsey ( <unk> – 1530 ) ; and Jill was Bishop Tarbes , who negotiated the marriage of Mary Tudor to the French king in 1514 .
|
[STATEMENT]
lemma has_fps_expansion_divide [fps_expansion_intros]:
fixes F G :: "'a :: {banach, real_normed_field} fps"
assumes "f has_fps_expansion F" and "g has_fps_expansion G" and
"subdegree G \<le> subdegree F" "G \<noteq> 0"
"c = fps_nth F (subdegree G) / fps_nth G (subdegree G)"
shows "(\<lambda>x. if x = 0 then c else f x / g x) has_fps_expansion (F / G)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
define n where "n = subdegree G"
[PROOF STATE]
proof (state)
this:
n = subdegree G
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
define F' and G' where "F' = fps_shift n F" and "G' = fps_shift n G"
[PROOF STATE]
proof (state)
this:
F' = fps_shift n F
G' = fps_shift n G
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
have "F = F' * fps_X ^ n" "G = G' * fps_X ^ n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. F = F' * fps_X ^ n &&& G = G' * fps_X ^ n
[PROOF STEP]
unfolding F'_def G'_def n_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. F = fps_shift (subdegree G) F * fps_X ^ subdegree G &&& G = fps_shift (subdegree G) G * fps_X ^ subdegree G
[PROOF STEP]
by (rule fps_shift_times_fps_X_power [symmetric] le_refl | fact)+
[PROOF STATE]
proof (state)
this:
F = F' * fps_X ^ n
G = G' * fps_X ^ n
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
F = F' * fps_X ^ n
G = G' * fps_X ^ n
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
from assms
[PROOF STATE]
proof (chain)
picking this:
f has_fps_expansion F
g has_fps_expansion G
subdegree G \<le> subdegree F
G \<noteq> 0
c = fps_nth F (subdegree G) / fps_nth G (subdegree G)
[PROOF STEP]
have "fps_nth G' 0 \<noteq> 0"
[PROOF STATE]
proof (prove)
using this:
f has_fps_expansion F
g has_fps_expansion G
subdegree G \<le> subdegree F
G \<noteq> 0
c = fps_nth F (subdegree G) / fps_nth G (subdegree G)
goal (1 subgoal):
1. fps_nth G' 0 \<noteq> (0::'a)
[PROOF STEP]
by (simp add: G'_def n_def)
[PROOF STATE]
proof (state)
this:
fps_nth G' 0 \<noteq> (0::'a)
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
F = F' * fps_X ^ n
G = G' * fps_X ^ n
fps_nth G' 0 \<noteq> (0::'a)
[PROOF STEP]
have FG: "F / G = F' * inverse G'"
[PROOF STATE]
proof (prove)
using this:
F = F' * fps_X ^ n
G = G' * fps_X ^ n
fps_nth G' 0 \<noteq> (0::'a)
goal (1 subgoal):
1. F / G = F' * inverse G'
[PROOF STEP]
by (simp add: fps_divide_unit)
[PROOF STATE]
proof (state)
this:
F / G = F' * inverse G'
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
have "(\<lambda>x. (if x = 0 then fps_nth F n else f x / x ^ n) *
inverse (if x = 0 then fps_nth G n else g x / x ^ n)) has_fps_expansion F / G"
(is "?h has_fps_expansion _")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<lambda>x. (if x = (0::'a) then fps_nth F n else f x / x ^ n) * inverse (if x = (0::'a) then fps_nth G n else g x / x ^ n)) has_fps_expansion F / G
[PROOF STEP]
unfolding FG F'_def G'_def n_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<lambda>x. (if x = (0::'a) then fps_nth F (subdegree G) else f x / x ^ subdegree G) * inverse (if x = (0::'a) then fps_nth G (subdegree G) else g x / x ^ subdegree G)) has_fps_expansion fps_shift (subdegree G) F * inverse (fps_shift (subdegree G) G)
[PROOF STEP]
using \<open>G \<noteq> 0\<close>
[PROOF STATE]
proof (prove)
using this:
G \<noteq> 0
goal (1 subgoal):
1. (\<lambda>x. (if x = (0::'a) then fps_nth F (subdegree G) else f x / x ^ subdegree G) * inverse (if x = (0::'a) then fps_nth G (subdegree G) else g x / x ^ subdegree G)) has_fps_expansion fps_shift (subdegree G) F * inverse (fps_shift (subdegree G) G)
[PROOF STEP]
by (intro has_fps_expansion_mult has_fps_expansion_inverse
has_fps_expansion_shift assms) auto
[PROOF STATE]
proof (state)
this:
(\<lambda>x. (if x = (0::'a) then fps_nth F n else f x / x ^ n) * inverse (if x = (0::'a) then fps_nth G n else g x / x ^ n)) has_fps_expansion F / G
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<lambda>x. (if x = (0::'a) then fps_nth F n else f x / x ^ n) * inverse (if x = (0::'a) then fps_nth G n else g x / x ^ n)) has_fps_expansion F / G
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
have "?h = (\<lambda>x. if x = 0 then c else f x / g x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (\<lambda>x. (if x = (0::'a) then fps_nth F n else f x / x ^ n) * inverse (if x = (0::'a) then fps_nth G n else g x / x ^ n)) = (\<lambda>x. if x = (0::'a) then c else f x / g x)
[PROOF STEP]
using assms(5)
[PROOF STATE]
proof (prove)
using this:
c = fps_nth F (subdegree G) / fps_nth G (subdegree G)
goal (1 subgoal):
1. (\<lambda>x. (if x = (0::'a) then fps_nth F n else f x / x ^ n) * inverse (if x = (0::'a) then fps_nth G n else g x / x ^ n)) = (\<lambda>x. if x = (0::'a) then c else f x / g x)
[PROOF STEP]
unfolding n_def
[PROOF STATE]
proof (prove)
using this:
c = fps_nth F (subdegree G) / fps_nth G (subdegree G)
goal (1 subgoal):
1. (\<lambda>x. (if x = (0::'a) then fps_nth F (subdegree G) else f x / x ^ subdegree G) * inverse (if x = (0::'a) then fps_nth G (subdegree G) else g x / x ^ subdegree G)) = (\<lambda>x. if x = (0::'a) then c else f x / g x)
[PROOF STEP]
by (intro ext) (auto split: if_splits simp: field_simps)
[PROOF STATE]
proof (state)
this:
(\<lambda>x. (if x = (0::'a) then fps_nth F n else f x / x ^ n) * inverse (if x = (0::'a) then fps_nth G n else g x / x ^ n)) = (\<lambda>x. if x = (0::'a) then c else f x / g x)
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
goal (1 subgoal):
1. (\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
(\<lambda>x. if x = (0::'a) then c else f x / g x) has_fps_expansion F / G
goal:
No subgoals!
[PROOF STEP]
qed |
(* seplog (c) AIST 2005-2013. R. Affeldt, N. Marti, et al. GNU GPLv3. *)
(* seplog (c) AIST 2014-2018. R. Affeldt et al. GNU GPLv3. *)
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq.
From mathcomp Require Import div path tuple.
Require Import Init_ext ssrZ ZArith_ext String_ext Max_ext.
Require Import machine_int seq_ext ssrnat_ext tuple_ext path_ext.
Require order finmap.
Import MachineInt.
Require Import C_types C_types_fp C_value C_expr C_expr_equiv.
Local Close Scope Z_scope.
Local Open Scope C_types_scope.
Local Open Scope C_value_scope.
Local Open Scope C_expr_scope.
Local Open Scope machine_int_scope.
(** ground arithmetic expressions *)
Lemma cat_nil {A: Type}: forall (l1: seq A) l2, l1 ++ l2 = nil -> l1 = nil /\ l2 = nil.
elim => //=.
Defined.
Definition ground_exp {g} {sigma : g.-env} {t : g.-typ} :
forall (e : exp sigma t) (H: vars e = nil), t.-phy.
induction e; simpl.
- done.
- move => H; exact p.
- move => /cat_nil [] H1 H2.
exact ([ bop_n _ t b ([ IHe1 H1 ]c) ([ IHe2 H2 ]c) ]_ (store0 sigma)).
- move => H.
exact (eval (store0 sigma) (bopk_n _ t b [IHe H ]c n)).
- move => /cat_nil [] H1 H2.
exact (eval (store0 sigma) (bop_r _ t b ([ IHe1 H1 ]c) ([ IHe2 H2 ]c))).
- move => /cat_nil [] H1 H2.
exact (eval (store0 sigma) ([ IHe1 H1 ]c \+ [ IHe2 H2 ]c)).
- move => H.
exact (eval (store0 sigma) (safe_cast _ t t' [IHe H ]c i)).
- move => H.
exact (eval (store0 sigma) (unsafe_cast _ t t' [IHe H ]c i)).
- move => H'.
exact (eval (store0 sigma) (fldp _ f [IHe H' ]c H e0)).
- move => /cat_nil [] H1 H2.
exact (eval (store0 sigma) ([ IHe1 H1 ]c \= [ IHe2 H2 ]c)).
- move => /cat_nil [] H1 / cat_nil [] H2 H3.
exact (eval (store0 sigma) (ifte_e _ t ([ IHe1 H1 ]c) ([ IHe2 H2 ]c) ([ IHe3 H3 ]c))).
Defined.
Global Opaque ground_exp.
Notation "'[' e ']ge'" := (@ground_exp _ _ _ e (Logic.eq_refl _)) (at level 9, only parsing) : C_expr_scope.
Notation "'[' e ']ge'" := (ground_exp e _) (at level 9, format "'[' [ e ]ge ']'"): C_expr_scope.
Lemma ground_exp_sem {g} {ts : g.-env} (s : store ts) {ty : g.-typ} :
forall (e : exp ts ty) (H : vars e = nil), [ e ]_s = ground_exp e H.
Transparent ground_exp.
induction e => //=.
- move/cat_nil => [] H1 H2.
by rewrite -(IHe1 H1) -(IHe2 H2).
- move => H; by rewrite -(IHe H).
- move/cat_nil => [] H1 H2.
by rewrite -(IHe1 H1) -(IHe2 H2).
- move/cat_nil => [] H1 H2.
by rewrite -(IHe1 H1) -(IHe2 H2).
- move => H; by rewrite -(IHe H).
- move => H; by rewrite -(IHe H).
- move => H'; by rewrite -(IHe H').
- move/cat_nil => [] H1 H2.
by rewrite -(IHe1 H1) -(IHe2 H2).
- move/cat_nil => [] H1 /cat_nil [] H2 H3.
by rewrite -(IHe1 H1) -(IHe2 H2) -(IHe3 H3).
Opaque ground_exp.
Qed.
Lemma ground_exp_c_inj {g} {sigma : g.-env} {t} (pv1 pv2 : t.-phy) H1 H2 :
ground_exp ([ pv1 ]c : exp sigma t) H1 = ground_exp ([ pv2 ]c : exp sigma t) H2 ->
pv1 = pv2.
Proof. done. Qed.
Lemma ge_cast_sint_cst_8c g (sigma : g.-env) (a : int 8) H :
ground_exp ((int) ([ a ]pc : exp sigma (g.-ityp: uchar)) ) H = [ zext 24 a ]p.
Proof.
Transparent eval beval.
rewrite /si32_of_phy /=.
by apply mkPhy_irrelevance.
Opaque eval beval.
Qed.
Lemma ge_cast_sint_cst_sint g (sigma : g.-env) (pv : (g.-ityp: sint).-phy) H :
ground_exp ((int) ([ pv ]c : exp sigma (g.-ityp: sint))) H = pv.
Proof. done. Qed.
(* similar to ge_cst_e but in ge_cst_e c is a phyval *)
Lemma sequiv_ge {g} {ts : g.-env} ty (e : exp ts ty) (H : vars e = nil) :
[ ground_exp e H ]c =s e.
Proof.
Transparent eval.
move=> s /=.
by rewrite ground_exp_sem.
Opaque eval.
Qed.
Lemma ge_cst_e {g sigma} {ty : g.-typ} (pv : ty.-phy) H : @ground_exp _ sigma _ [ pv ]c H = pv.
Proof. done. Qed.
Lemma i32_ge_s_cst_e {g} {sigma : g.-env} n H :
si32<=phy (ground_exp ([ n ]sc : exp sigma _) H) = Z2s 32 n.
Proof. by rewrite ge_cst_e (si32_of_phy_sc _ _ (store0 sigma)). Qed.
Lemma i8_ge_8_cst_e {g} sigma z H :
i8<=phy (@ground_exp g sigma _ [ z ]pc H) = z.
Proof. by rewrite ge_cst_e phy_of_ui8K. Qed.
Local Open Scope zarith_ext_scope.
Lemma sequiv_s2Z_si32_of_phy {g} {ts : g.-env} e H :
([s2Z (si32<=phy (ground_exp e H) )]sc : exp ts _ ) =s e.
Proof.
move=> s.
rewrite (ground_exp_sem _ e H).
set X := ground_exp e H.
destruct X.
unfold si32_of_phy; simpl.
move: (oi32_of_i8_Some _ Hphy) => [] x Hx.
rewrite Hx /= /phy_of_si32.
apply mkPhy_irrelevance => /=.
rewrite -(oi32_of_i8_bij _ _ Hx).
Transparent eval.
by rewrite /= Z2s_s2Z.
Opaque eval.
Qed.
Lemma s2Z_ge_s_cst_e {g sigma} z H : (- 2 ^^ 31 <= z < 2 ^^ 31)%Z ->
s2Z (si32<=phy (@ground_exp g sigma _ [ z ]sc H)) = z.
Proof. move=> Hz. by rewrite i32_ge_s_cst_e Z2sK. Qed.
Lemma u2Z_ge_s_cst_e {g sigma} z H : (0 <= z < 2 ^^ 31)%Z ->
u2Z (si32<=phy (@ground_exp g sigma _ [ z ]sc H)) = z.
Proof.
case=> Hz0 Hz1.
rewrite i32_ge_s_cst_e-s2Z_u2Z_pos.
rewrite Z2sK //; split => //; exact: (@leZ_trans Z0).
rewrite Z2sK //; split => //; exact: (@leZ_trans Z0).
Qed.
Lemma si32_of_phy_gb_add_e {g} {sigma : g.-env} (a b : exp sigma _) H Ha Hb :
si32<=phy (ground_exp (a \+ b) H) =
si32<=phy (ground_exp a Ha) `+ si32<=phy (ground_exp b Hb).
Proof.
by rewrite -(ground_exp_sem (store0 sigma)) si32_of_phy_binop_ne 2!(ground_exp_sem (store0 sigma)).
Qed.
Lemma si32_of_phy_gb_or_e {g} {sigma : g.-env} (a b : exp sigma _) H Ha Hb :
si32<=phy (ground_exp (a \| b) H) =
si32<=phy (ground_exp a Ha) `|` si32<=phy (ground_exp b Hb).
Proof.
by rewrite -(ground_exp_sem (store0 sigma)) si32_of_phy_binop_ne 2!(ground_exp_sem (store0 sigma)).
Qed.
(* NB: generaliser? *)
Lemma sint_shl_e_to_i32_ge g (sigma : g.-env) (a : int 8) H :
si32<=phy (ground_exp ((int) ([ a ]pc : exp sigma (g.-ityp: uchar)) \<< [ 8 ]sc : exp sigma _) H) =
zext 16 a `|| Z2u 8 0.
Proof.
Transparent eval beval.
rewrite /si32_of_phy /= i8_of_i32Ko /= !i8_of_i32K /= Z2s_Z2u_k // Z2uK //.
apply u2Z_inj.
rewrite (@u2Z_shl _ _ _ 8) //.
- by rewrite (u2Z_concat (zext 16 a)) Z2uK // !u2Z_zext addZ0 (u2Z_zext (8 * (4 - 1)) a).
- rewrite (u2Z_zext (8 * (4 - 1)) a).
by apply max_u2Z.
Opaque eval beval.
Qed.
Local Open Scope Z_scope.
Lemma i8_of_phy_ifte {g sigma} (a b c d : _) H :
i8<=phy (@ground_exp g sigma _ ([ a ]c \<= [ b ]c \? [ c ]c \: [ d ]c) H) =
if Z<=u (i8<=phy a) <=? Z<=u (i8<=phy b) then i8<=phy c else i8<=phy d.
Proof.
Transparent eval.
rewrite -(ground_exp_sem (store0 sigma)) /=.
destruct a as [a Ha] => //=.
have Ha' : size a = 1%nat by rewrite Ha sizeof_ityp.
have Ha'Ha : Ha' = Ha by apply eq_irrelevance.
subst Ha.
destruct a as [|a []] => //=.
destruct b as [b Hb] => //=.
have Hb' : size b = 1%nat by rewrite Hb sizeof_ityp.
have Hb'Hb : Hb' = Hb by apply eq_irrelevance.
subst Hb.
destruct b as [|b []] => //=.
set a1 := Z<=u _.
set b1 := Z<=u _.
case: ifP.
rewrite /is_zero.
case: ifP => // _ /eqP.
case.
move/int_break_inj => abs.
exfalso.
lapply abs => //.
by apply Z2u_dis.
case: ifP => // _.
by rewrite is_zero_0.
Opaque eval.
Qed.
Local Close Scope Z_scope.
(** ground boolean expressions *)
Lemma ground_bexp_helper1 {g} {sigma : g.-env} (e : exp sigma (ityp: uint)) : bvars (exp2bexp sigma e) = nil -> vars e = nil.
Proof. done. Qed.
Lemma ground_bexp_helper2 {g} {sigma : g.-env} (b : bexp sigma) : bvars (bneg sigma b) = nil -> bvars b = nil.
Proof. done. Qed.
Fixpoint ground_bexp {g} {sigma : g.-env} (b : bexp sigma) : bvars b = nil -> bool :=
match b as b0 return bvars b0 = nil -> bool with
| exp2bexp e => fun H => ~~ is_zero (ground_exp e (ground_bexp_helper1 e H))
| bneg b' => fun H => ~~ ground_bexp b' (ground_bexp_helper2 b' H)
end.
Global Opaque ground_bexp.
Lemma gb_bneg {g} {sigma: g.-env} (b : bexp sigma) H : ground_bexp (\~b b) H = ~~ ground_bexp b H.
Proof.
congr (~~ _ _ _ _ _).
by apply eq_irrelevance.
Qed.
Lemma ground_bexp_sem {g} {sigma : g.-env} (s : store sigma) :
forall (b : bexp sigma) (H : bvars b = nil), [ b ]b_ s = ground_bexp b H.
Proof.
Transparent beval.
induction b => //=.
- move => H.
rewrite ground_exp_sem /=.
congr (~~ _ [ _ ]ge).
by apply eq_irrelevance.
- move => H; by rewrite IHb gb_bneg.
Opaque beval.
Qed.
Notation "'[' e ']gb'" := (@ground_bexp _ _ e erefl) (at level 9, only parsing) : C_expr_scope.
Notation "'[' e ']gb'" := (ground_bexp e _) (at level 9): C_expr_scope.
Section ground_bexp_prop.
Variables (g : wfctxt) (sigma : g.-env).
Lemma bneg_0uc H : @ground_bexp _ sigma (\~b \b [ 0 ]uc) H.
Proof.
Transparent beval.
by rewrite -(ground_bexp_sem (store0 sigma)) /= is_zero_0.
Opaque beval.
Qed.
Lemma oneuc H : @ground_bexp _ sigma ( \b [ 1 ]uc ) H.
Proof.
Transparent beval.
by rewrite -(ground_bexp_sem (store0 sigma)) /= not_is_zero_1.
Opaque beval.
Qed.
Lemma gb_eq_p {t} (a b : exp sigma (:* t)) H H1 H2 :
ground_bexp ( \b a \= b ) H = (ground_exp a H1 == ground_exp b H2).
Proof.
by rewrite -(ground_bexp_sem (store0 sigma) _ H) beval_eq_p_eq -!(ground_exp_sem (store0 _)).
Qed.
Lemma and_gb (e1 e2 : exp sigma (ityp: uint)) H H1 H2 :
ground_bexp (\b e1 \&& e2) H = ground_bexp (\b e1) H1 && ground_bexp (\b e2) H2.
Proof.
Transparent eval beval.
rewrite -!(ground_bexp_sem (store0 sigma)) /=.
move He1 : ( [ e1 ]_(store0 _) ) => [he1 Hhe1].
move He2 : ( [ e2 ]_(store0 _) ) => [he2 Hhe2].
set tmp1 := eq_ind_r _ _ _. rewrite (_ : tmp1 = Hhe1); last by apply eq_irrelevance.
set tmp2 := eq_ind_r _ _ _. rewrite (_ : tmp2 = Hhe2); last by apply eq_irrelevance.
case: ifP => [Hcase | /negbT].
rewrite is_zero_0; symmetry; apply/negbTE.
rewrite negb_and 2!negbK /is_zero /=.
apply/orP.
case/orP : Hcase => /eqP Hcase; [left | right].
apply/eqP.
apply mkPhy_irrelevance => /=.
symmetry; apply i32_of_i8_bij with Hhe1.
apply u2Z_inj.
by rewrite Hcase Z2uK.
apply/eqP.
apply mkPhy_irrelevance => /=.
symmetry; apply i32_of_i8_bij with Hhe2.
apply u2Z_inj; by rewrite Hcase Z2uK.
rewrite not_is_zero_1 negb_or; case/andP => Ha Hb.
symmetry; apply/andP; split.
move: Ha; apply contra.
rewrite /is_zero; case/eqP => ?; subst he1.
by rewrite i8_of_i32K Z2uK.
move: Hb; apply contra.
rewrite /is_zero; case/eqP => ?; subst he2.
by rewrite i8_of_i32K Z2uK.
Opaque eval beval.
Qed.
Lemma and_8c (a b : int 8) H :
ground_exp ([ a ]pc \& [ b ]pc : exp sigma (g.-ityp: uchar)) H =
ground_exp ([ a `& b ]pc : exp sigma _) H.
Proof. by []. Qed.
End ground_bexp_prop.
Section ground_bexp_eq.
Variables (g : wfctxt) (sigma : g.-env) (t : integral) (a b : exp sigma (ityp: t)).
Hypotheses (Ha : vars a = nil) (Hb : vars b = nil).
Lemma gb_eq_e H : ground_bexp (\b a \= b) H = (ground_exp a Ha == ground_exp b Hb).
Proof. by rewrite -(ground_bexp_sem (store0 _) _ H) beval_eq_e_eq -!(ground_exp_sem (store0 _)). Qed.
Lemma gb_neq H H' : ground_bexp (\b a \!= b) H = ~~ ground_bexp (\b a \= b) H'.
Proof. by rewrite -!(ground_bexp_sem (store0 sigma)) beval_neq_not_eq beval_eq_e_eq. Qed.
Lemma gb_bneg_bop_r_lt H H' : ground_bexp (\~b \b a \< b) H = ground_bexp (\b a \>= b) H'.
Proof. by rewrite -!(ground_bexp_sem (store0 sigma)) CgeqNlt. Qed.
Lemma gb_bneg_bop_r_ge H H' : ground_bexp (\~b \b a \>= b) H = ground_bexp (\b a \< b) H'.
Proof. by rewrite -!(ground_bexp_sem (store0 sigma)) CgeqNlt bnegK. Qed.
Lemma gb_bneg_bop_r_gt H H' : ground_bexp (\~b \b a \> b) H = ground_bexp (\b a \<= b) H'.
Proof. by rewrite -!(ground_bexp_sem (store0 sigma)) -CleqNgt. Qed.
Lemma gb_ge_lt H H' : ground_bexp (\b a \>= b) H = ground_bexp (\b b \<= a) H'.
Proof. by rewrite -!(ground_bexp_sem (store0 sigma)) sequiv_ge_sym. Qed.
End ground_bexp_eq.
Local Open Scope zarith_ext_scope.
Local Open Scope Z_scope.
Section ground_bexp_Zlt_Zle.
Variables (g : wfctxt) (sigma : g.-env) (e1 e2 : exp sigma (ityp: sint)).
Hypotheses (H1 : vars e1 = nil) (H2 : vars e2 = nil).
(* NB: lower bounds could be generalized to - 2 ^^ 31 *)
Lemma le_n_gb H : 0 <= Z<=s (si32<=phy (ground_exp e1 H1)) < 2 ^^ 31 ->
0 <= Z<=s (si32<=phy (ground_exp e2 H2)) < 2 ^^ 31 ->
ground_bexp (\b e1 \<= e2) H -> si32<=phy (ground_exp e1 H1) `<= si32<=phy (ground_exp e2 H2).
Proof.
move=> K1 K2.
rewrite -!(ground_bexp_sem (store0 sigma)) -!(ground_exp_sem (store0 sigma)).
move/bop_re_le_Zle => K.
apply Zle2le_n.
case: K1; move/s2Z_u2Z_pos => K1 _.
rewrite -!(ground_exp_sem (store0 sigma)) in K1.
case: K2; move/s2Z_u2Z_pos => K2 _.
rewrite -!(ground_exp_sem (store0 sigma)) in K2.
congruence.
Qed.
Lemma lt_n_gb H : 0 <= Z<=s (si32<=phy (ground_exp e1 H1)) < 2 ^^ 31 ->
0 <= Z<=s (si32<=phy (ground_exp e2 H2)) < 2 ^^ 31 ->
ground_bexp (\b e1 \< e2) H -> si32<=phy (ground_exp e1 H1) `< si32<=phy (ground_exp e2 H2).
Proof.
move=> K1 K2.
rewrite -!(ground_bexp_sem (store0 sigma)) -!(ground_exp_sem (store0 sigma)).
move/bop_re_lt_Zlt => K.
apply Zlt2lt_n.
case: K1; move/s2Z_u2Z_pos => K1 _.
rewrite -!(ground_exp_sem (store0 sigma)) in K1.
case: K2; move/s2Z_u2Z_pos => K2 _.
rewrite -!(ground_exp_sem (store0 sigma)) in K2.
congruence.
Qed.
Lemma Zlt_gb H : ground_bexp (\b e1 \< e2) H ->
0 <= Z<=s (si32<=phy (ground_exp e1 H1)) < 2 ^^ 31 ->
0 <= Z<=s (si32<=phy (ground_exp e2 H2)) < 2 ^^ 31 ->
Z<=s (si32<=phy (ground_exp e1 H1)) < Z<=s (si32<=phy (ground_exp e2 H2)).
Proof.
move=> K K1 K2.
rewrite -1!(ground_bexp_sem (store0 sigma)) in K.
rewrite -2!(ground_exp_sem (store0 sigma)).
by apply bop_re_lt_Zlt.
Qed.
Lemma Zle_gb H : ground_bexp (\b e1 \<= e2) H ->
s2Z (si32<=phy (ground_exp e1 H1)) <= s2Z (si32<=phy (ground_exp e2 H2)).
Proof.
move=> H'.
rewrite -2!(ground_exp_sem (store0 sigma)).
apply bop_re_le_Zle.
by rewrite -(ground_bexp_sem (store0 sigma)) in H'.
Qed.
Lemma Zle_gb_inv H :
Z<=s (si32<=phy (ground_exp e1 H1)) <= Z<=s (si32<=phy (ground_exp e2 H2)) ->
ground_bexp (\b e1 \<= e2) H.
Proof.
Transparent eval beval.
rewrite -(ground_bexp_sem (store0 sigma)) -2!(ground_exp_sem (store0 sigma)) /=.
move He1 : ( [ e1 ]_ _) => [e1s0 He1s0].
move He2 : ( [ e2 ]_ _) => [e2s0 He2s0] K.
case: ifP; first by rewrite not_is_zero_1.
rewrite /si32_of_phy /= in K.
have He1s0' : size e1s0 = 4%nat by rewrite He1s0 sizeof_ityp.
case/oi32_of_i8_Some : He1s0' => x Hx.
rewrite Hx /= in K.
have He2s0' : size e2s0 = 4%nat by rewrite He2s0 sizeof_ityp.
case/oi32_of_i8_Some : He2s0' => y Hy.
rewrite Hy /= in K.
rewrite (i32_of_i8_bij3 _ _ _ Hx) (i32_of_i8_bij3 _ _ _ Hy).
move/leZP => abs; contradiction.
Opaque eval beval.
Qed.
(* almost the same proof as Zle_gb_inv *)
Lemma Zlt_gb_inv H :
Z<=s (si32<=phy (ground_exp e1 H1)) < Z<=s (si32<=phy (ground_exp e2 H2)) ->
ground_bexp (\b e1 \< e2) H.
Proof.
Transparent eval beval.
rewrite -(ground_bexp_sem (store0 sigma)) -2!(ground_exp_sem (store0 sigma)) /=.
move He1 : ( [ e1 ]_ _) => [e1s0 He1s0].
move He2 : ( [ e2 ]_ _) => [e2s0 He2s0] => K.
case: ifP; first by rewrite not_is_zero_1.
rewrite /si32_of_phy /= in K.
have He1s0' : size e1s0 = 4%nat by rewrite He1s0 sizeof_ityp.
case/oi32_of_i8_Some : He1s0' => x Hx.
rewrite Hx /= in K.
have He2s0' : size e2s0 = 4%nat by rewrite He2s0 sizeof_ityp.
case/oi32_of_i8_Some : He2s0' => y Hy.
rewrite Hy /= in K.
rewrite (i32_of_i8_bij3 _ _ _ Hx) (i32_of_i8_bij3 _ _ _ Hy).
move/ltZP => abs; contradiction.
Opaque eval beval.
Qed.
Lemma ground_bexp_lt0n H :
0 < Z<=s (si32<=phy (ground_exp e1 H1)) -> ground_bexp (\b [ 0 ]sc \< e1) H.
Proof.
move=> H0.
Transparent beval eval.
rewrite -(ground_bexp_sem (store0 sigma) (\b [ 0 ]sc \< e1)) /=.
move He1 : ([ e1 ]_ _) => [l1 Hl1].
rewrite i8_of_i32K Z2sK //.
case: ifP; first by rewrite not_is_zero_1.
rewrite -(ground_exp_sem (store0 sigma)) He1 /= in H0.
set lhs := si32<=phy _ in H0.
set rhs := i32<=i8 _ _.
suff: lhs = rhs by move=> <- /ltZP.
rewrite /lhs /rhs {lhs rhs H0} /si32_of_phy /oi32_of_i8.
have : List.length l1 = 4%nat.
clear He1; by rewrite sizeof_ityp /= in Hl1.
case/(int_flat_Some erefl) => x Hx.
rewrite Hx /= /i32_of_i8.
by symmetry; apply int_flat_int_flat_ok.
Opaque beval eval.
Qed.
Lemma ground_bexp_le0n H :
0 <= Z<=s (si32<=phy (ground_exp e1 H1)) -> ground_bexp (\b [ 0 ]sc \<= e1) H.
Proof.
move=> H0.
Transparent beval eval.
rewrite -(ground_bexp_sem (store0 sigma) (\b [ 0 ]sc \<= e1)) /=.
move He1 : ([ e1 ]_ _) => [l1 Hl1].
rewrite i8_of_i32K Z2sK //.
case: ifP; first by rewrite not_is_zero_1.
rewrite -(ground_exp_sem (store0 sigma)) He1 /= in H0.
set lhs := si32<=phy _ in H0.
set rhs := i32<=i8 _ _.
suff: lhs = rhs by move=> <- /leZP.
rewrite /lhs /rhs {lhs rhs H0} /si32_of_phy /oi32_of_i8.
have : List.length l1 = 4%nat.
clear He1; by rewrite sizeof_ityp /= in Hl1.
case/(int_flat_Some erefl) => x Hx.
rewrite Hx /= /i32_of_i8.
by symmetry; apply int_flat_int_flat_ok.
Opaque beval eval.
Qed.
End ground_bexp_Zlt_Zle.
Definition ground_bexp_relation {g} {sigma : g.-env} :
Relations.Relation_Definitions.relation (forall (b : bexp sigma) (Hb : bvars b = nil), Prop).
red.
apply Morphisms.respectful_hetero.
exact bequiv.
move=> x y.
apply Morphisms.respectful_hetero.
exact (fun _ _ => True).
move=> Hx Hy.
exact iff.
Defined.
Instance ground_bexp_morphism {g} {sigma : g.-env} :
Morphisms.Proper ground_bexp_relation (@ground_bexp _ sigma).
move=> b1 b2 Hb /= Hb1 Hb2 _ /=.
by rewrite -(ground_bexp_sem (store0 _)) -(ground_bexp_sem (store0 _)) Hb.
Qed.
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2010 *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
Require Import Arith.
Require Import List.
(**** A few tests for the extraction mechanism ****)
(* Ideally, we should monitor the extracted output
for changes, but this is painful. For the moment,
we just check for failures of this script. *)
(*** STANDARD EXAMPLES *)
(** Functions. *)
Definition idnat (x:nat) := x.
Extraction idnat.
(* let idnat x = x *)
Definition id (X:Type) (x:X) := x.
Extraction id. (* let id x = x *)
Definition id' := id Set nat.
Extraction id'. (* type id' = nat *)
Definition test2 (f:nat -> nat) (x:nat) := f x.
Extraction test2.
(* let test2 f x = f x *)
Definition test3 (f:nat -> Set -> nat) (x:nat) := f x nat.
Extraction test3.
(* let test3 f x = f x __ *)
Definition test4 (f:(nat -> nat) -> nat) (x:nat) (g:nat -> nat) := f g.
Extraction test4.
(* let test4 f x g = f g *)
Definition test5 := (1, 0).
Extraction test5.
(* let test5 = Pair ((S O), O) *)
Definition cf (x:nat) (_:x <= 0) := S x.
Extraction NoInline cf.
Definition test6 := cf 0 (le_n 0).
Extraction test6.
(* let test6 = cf O *)
Definition test7 := (fun (X:Set) (x:X) => x) nat.
Extraction test7.
(* let test7 x = x *)
Definition d (X:Type) := X.
Extraction d. (* type 'x d = 'x *)
Definition d2 := d Set.
Extraction d2. (* type d2 = __ d *)
Definition d3 (x:d Set) := 0.
Extraction d3. (* let d3 _ = O *)
Definition d4 := d nat.
Extraction d4. (* type d4 = nat d *)
Definition d5 := (fun x:d Type => 0) Type.
Extraction d5. (* let d5 = O *)
Definition d6 (x:d Type) := x.
Extraction d6. (* type 'x d6 = 'x *)
Definition test8 := (fun (X:Type) (x:X) => x) Set nat.
Extraction test8. (* type test8 = nat *)
Definition test9 := let t := nat in id Set t.
Extraction test9. (* type test9 = nat *)
Definition test10 := (fun (X:Type) (x:X) => 0) Type Type.
Extraction test10. (* let test10 = O *)
Definition test11 := let n := 0 in let p := S n in S p.
Extraction test11. (* let test11 = S (S O) *)
Definition test12 := forall x:forall X:Type, X -> X, x Type Type.
Extraction test12.
(* type test12 = (__ -> __ -> __) -> __ *)
Definition test13 := match @left True True I with
| left x => 1
| right x => 0
end.
Extraction test13. (* let test13 = S O *)
(** example with more arguments that given by the type *)
Definition test19 :=
nat_rec (fun n:nat => nat -> nat) (fun n:nat => 0)
(fun (n:nat) (f:nat -> nat) => f) 0 0.
Extraction test19.
(* let test19 =
let rec f = function
| O -> (fun n0 -> O)
| S n0 -> f n0
in f O O
*)
(** casts *)
Definition test20 := True:Type.
Extraction test20.
(* type test20 = __ *)
(** Simple inductive type and recursor. *)
Extraction nat.
(*
type nat =
| O
| S of nat
*)
Extraction sumbool_rect.
(*
let sumbool_rect f f0 = function
| Left -> f __
| Right -> f0 __
*)
(** Less simple inductive type. *)
Inductive c (x:nat) : nat -> Set :=
| refl : c x x
| trans : forall y z:nat, c x y -> y <= z -> c x z.
Extraction c.
(*
type c =
| Refl
| Trans of nat * nat * c
*)
Definition Ensemble (U:Type) := U -> Prop.
Definition Empty_set (U:Type) (x:U) := False.
Definition Add (U:Type) (A:Ensemble U) (x y:U) := A y \/ x = y.
Inductive Finite (U:Type) : Ensemble U -> Type :=
| Empty_is_finite : Finite U (Empty_set U)
| Union_is_finite :
forall A:Ensemble U,
Finite U A -> forall x:U, ~ A x -> Finite U (Add U A x).
Extraction Finite.
(*
type 'u finite =
| Empty_is_finite
| Union_is_finite of 'u finite * 'u
*)
(** Mutual Inductive *)
Inductive tree : Set :=
Node : nat -> forest -> tree
with forest : Set :=
| Leaf : nat -> forest
| Cons : tree -> forest -> forest.
Extraction tree.
(*
type tree =
| Node of nat * forest
and forest =
| Leaf of nat
| Cons of tree * forest
*)
Fixpoint tree_size (t:tree) : nat :=
match t with
| Node a f => S (forest_size f)
end
with forest_size (f:forest) : nat :=
match f with
| Leaf b => 1
| Cons t f' => tree_size t + forest_size f'
end.
Extraction tree_size.
(*
let rec tree_size = function
| Node (a, f) -> S (forest_size f)
and forest_size = function
| Leaf b -> S O
| Cons (t, f') -> plus (tree_size t) (forest_size f')
*)
(** Eta-expansions of inductive constructor *)
Inductive titi : Set :=
tata : nat -> nat -> nat -> nat -> titi.
Definition test14 := tata 0.
Extraction test14.
(* let test14 x x0 x1 = Tata (O, x, x0, x1) *)
Definition test15 := tata 0 1.
Extraction test15.
(* let test15 x x0 = Tata (O, (S O), x, x0) *)
Inductive eta : Type :=
eta_c : nat -> Prop -> nat -> Prop -> eta.
Extraction eta_c.
(*
type eta =
| Eta_c of nat * nat
*)
Definition test16 := eta_c 0.
Extraction test16.
(* let test16 x = Eta_c (O, x) *)
Definition test17 := eta_c 0 True.
Extraction test17.
(* let test17 x = Eta_c (O, x) *)
Definition test18 := eta_c 0 True 0.
Extraction test18.
(* let test18 _ = Eta_c (O, O) *)
(** Example of singleton inductive type *)
Inductive bidon (A:Prop) (B:Type) : Type :=
tb : forall (x:A) (y:B), bidon A B.
Definition fbidon (A B:Type) (f:A -> B -> bidon True nat)
(x:A) (y:B) := f x y.
Extraction bidon.
(* type 'b bidon = 'b *)
Extraction tb.
(* tb : singleton inductive constructor *)
Extraction fbidon.
(* let fbidon f x y =
f x y
*)
Definition fbidon2 := fbidon True nat (tb True nat).
Extraction fbidon2. (* let fbidon2 y = y *)
Extraction NoInline fbidon.
Extraction fbidon2.
(* let fbidon2 y = fbidon (fun _ x -> x) __ y *)
(* NB: first argument of fbidon2 has type [True], so it disappears. *)
(** mutual inductive on many sorts *)
Inductive test_0 : Prop :=
ctest0 : test_0
with test_1 : Set :=
ctest1 : test_0 -> test_1.
Extraction test_0.
(* test0 : logical inductive *)
Extraction test_1.
(*
type test1 =
| Ctest1
*)
(** logical singleton *)
Extraction eq.
(* eq : logical inductive *)
Extraction eq_rect.
(* let eq_rect x f y =
f
*)
(** No more propagation of type parameters. Obj.t instead. *)
Inductive tp1 : Type :=
T : forall (C:Set) (c:C), tp2 -> tp1
with tp2 : Type :=
T' : tp1 -> tp2.
Extraction tp1.
(*
type tp1 =
| T of __ * tp2
and tp2 =
| T' of tp1
*)
Inductive tp1bis : Type :=
Tbis : tp2bis -> tp1bis
with tp2bis : Type :=
T'bis : forall (C:Set) (c:C), tp1bis -> tp2bis.
Extraction tp1bis.
(*
type tp1bis =
| Tbis of tp2bis
and tp2bis =
| T'bis of __ * tp1bis
*)
(** Strange inductive type. *)
Inductive Truc : Set -> Type :=
| chose : forall A:Set, Truc A
| machin : forall A:Set, A -> Truc bool -> Truc A.
Extraction Truc.
(*
type 'x truc =
| Chose
| Machin of 'x * bool truc
*)
(** Dependant type over Type *)
Definition test24 := sigT (fun a:Set => option a).
Extraction test24.
(* type test24 = (__, __ option) sigT *)
(** Coq term non strongly-normalizable after extraction *)
Require Import Gt.
Definition loop (Ax:Acc gt 0) :=
(fix F (a:nat) (b:Acc gt a) {struct b} : nat :=
F (S a) (Acc_inv b (S a) (gt_Sn_n a))) 0 Ax.
Extraction loop.
(* let loop _ =
let rec f a =
f (S a)
in f O
*)
(*** EXAMPLES NEEDING OBJ.MAGIC *)
(** False conversion of type: *)
Lemma oups : forall H:nat = list nat, nat -> nat.
intros.
generalize H0; intros.
rewrite H in H1.
case H1.
exact H0.
intros.
exact n.
Qed.
Extraction oups.
(*
let oups h0 =
match Obj.magic h0 with
| Nil -> h0
| Cons0 (n, l) -> n
*)
(** hybrids *)
Definition horibilis (b:bool) :=
if b as b return (if b then Type else nat) then Set else 0.
Extraction horibilis.
(*
let horibilis = function
| True -> Obj.magic __
| False -> Obj.magic O
*)
Definition PropSet (b:bool) := if b then Prop else Set.
Extraction PropSet. (* type propSet = __ *)
Definition natbool (b:bool) := if b then nat else bool.
Extraction natbool. (* type natbool = __ *)
Definition zerotrue (b:bool) := if b as x return natbool x then 0 else true.
Extraction zerotrue.
(*
let zerotrue = function
| True -> Obj.magic O
| False -> Obj.magic True
*)
Definition natProp (b:bool) := if b return Type then nat else Prop.
Definition natTrue (b:bool) := if b return Type then nat else True.
Definition zeroTrue (b:bool) := if b as x return natProp x then 0 else True.
Extraction zeroTrue.
(*
let zeroTrue = function
| True -> Obj.magic O
| False -> Obj.magic __
*)
Definition natTrue2 (b:bool) := if b return Type then nat else True.
Definition zeroprop (b:bool) := if b as x return natTrue x then 0 else I.
Extraction zeroprop.
(*
let zeroprop = function
| True -> Obj.magic O
| False -> Obj.magic __
*)
(** polymorphic f applied several times *)
Definition test21 := (id nat 0, id bool true).
Extraction test21.
(* let test21 = Pair ((id O), (id True)) *)
(** ok *)
Definition test22 :=
(fun f:forall X:Type, X -> X => (f nat 0, f bool true))
(fun (X:Type) (x:X) => x).
Extraction test22.
(* let test22 =
let f = fun x -> x in Pair ((f O), (f True)) *)
(* still ok via optim beta -> let *)
Definition test23 (f:forall X:Type, X -> X) := (f nat 0, f bool true).
Extraction test23.
(* let test23 f = Pair ((Obj.magic f __ O), (Obj.magic f __ True)) *)
(* problem: fun f -> (f 0, f true) not legal in ocaml *)
(* solution: magic ... *)
(** Dummy constant __ can be applied.... *)
Definition f (X:Type) (x:nat -> X) (y:X -> bool) : bool := y (x 0).
Extraction f.
(* let f x y =
y (x O)
*)
Definition f_prop := f (0 = 0) (fun _ => refl_equal 0) (fun _ => true).
Extraction NoInline f.
Extraction f_prop.
(* let f_prop =
f (Obj.magic __) (fun _ -> True)
*)
Definition f_arity := f Set (fun _:nat => nat) (fun _:Set => true).
Extraction f_arity.
(* let f_arity =
f (Obj.magic __) (fun _ -> True)
*)
Definition f_normal :=
f nat (fun x => x) (fun x => match x with
| O => true
| _ => false
end).
Extraction f_normal.
(* let f_normal =
f (fun x -> x) (fun x -> match x with
| O -> True
| S n -> False)
*)
(* inductive with magic needed *)
Inductive Boite : Set :=
boite : forall b:bool, (if b then nat else (nat * nat)%type) -> Boite.
Extraction Boite.
(*
type boite =
| Boite of bool * __
*)
Definition boite1 := boite true 0.
Extraction boite1.
(* let boite1 = Boite (True, (Obj.magic O)) *)
Definition boite2 := boite false (0, 0).
Extraction boite2.
(* let boite2 = Boite (False, (Obj.magic (Pair (O, O)))) *)
Definition test_boite (B:Boite) :=
match B return nat with
| boite true n => n
| boite false n => fst n + snd n
end.
Extraction test_boite.
(*
let test_boite = function
| Boite (b0, n) ->
(match b0 with
| True -> Obj.magic n
| False -> plus (fst (Obj.magic n)) (snd (Obj.magic n)))
*)
(* singleton inductive with magic needed *)
Inductive Box : Type :=
box : forall A:Set, A -> Box.
Extraction Box.
(* type box = __ *)
Definition box1 := box nat 0.
Extraction box1. (* let box1 = Obj.magic O *)
(* applied constant, magic needed *)
Definition idzarb (b:bool) (x:if b then nat else bool) := x.
Definition zarb := idzarb true 0.
Extraction NoInline idzarb.
Extraction zarb.
(* let zarb = Obj.magic idzarb True (Obj.magic O) *)
(** function of variable arity. *)
(** Fun n = nat -> nat -> ... -> nat *)
Fixpoint Fun (n:nat) : Set :=
match n with
| O => nat
| S n => nat -> Fun n
end.
Fixpoint Const (k n:nat) {struct n} : Fun n :=
match n as x return Fun x with
| O => k
| S n => fun p:nat => Const k n
end.
Fixpoint proj (k n:nat) {struct n} : Fun n :=
match n as x return Fun x with
| O => 0 (* ou assert false ....*)
| S n =>
match k with
| O => fun x => Const x n
| S k => fun x => proj k n
end
end.
Definition test_proj := proj 2 4 0 1 2 3.
Eval compute in test_proj.
Recursive Extraction test_proj.
(*** TO SUM UP: ***)
(* Was previously producing a "test_extraction.ml" *)
Recursive Extraction
idnat id id' test2 test3 test4 test5 test6 test7 d d2
d3 d4 d5 d6 test8 id id' test9 test10 test11 test12
test13 test19 test20 nat sumbool_rect c Finite tree
tree_size test14 test15 eta_c test16 test17 test18 bidon
tb fbidon fbidon2 fbidon2 test_0 test_1 eq eq_rect tp1
tp1bis Truc oups test24 loop horibilis PropSet natbool
zerotrue zeroTrue zeroprop test21 test22 test23 f f_prop
f_arity f_normal Boite boite1 boite2 test_boite Box box1
zarb test_proj.
Extraction Language Haskell.
(* Was previously producing a "Test_extraction.hs" *)
Recursive Extraction
idnat id id' test2 test3 test4 test5 test6 test7 d d2
d3 d4 d5 d6 test8 id id' test9 test10 test11 test12
test13 test19 test20 nat sumbool_rect c Finite tree
tree_size test14 test15 eta_c test16 test17 test18 bidon
tb fbidon fbidon2 fbidon2 test_0 test_1 eq eq_rect tp1
tp1bis Truc oups test24 loop horibilis PropSet natbool
zerotrue zeroTrue zeroprop test21 test22 test23 f f_prop
f_arity f_normal Boite boite1 boite2 test_boite Box box1
zarb test_proj.
Extraction Language Scheme.
(* Was previously producing a "test_extraction.scm" *)
Recursive Extraction
idnat id id' test2 test3 test4 test5 test6 test7 d d2
d3 d4 d5 d6 test8 id id' test9 test10 test11 test12
test13 test19 test20 nat sumbool_rect c Finite tree
tree_size test14 test15 eta_c test16 test17 test18 bidon
tb fbidon fbidon2 fbidon2 test_0 test_1 eq eq_rect tp1
tp1bis Truc oups test24 loop horibilis PropSet natbool
zerotrue zeroTrue zeroprop test21 test22 test23 f f_prop
f_arity f_normal Boite boite1 boite2 test_boite Box box1
zarb test_proj.
(*** Finally, a test more focused on everyday's life situations ***)
Require Import ZArith.
Recursive Extraction two_or_two_plus_one Zdiv_eucl_exist.
|
(* Title: Schutz_Spacetime/TemporalOrderOnPath.thy
Authors: Richard Schmoetten, Jake Palmer and Jacques D. Fleuriot
University of Edinburgh, 2021
*)
theory TemporalOrderOnPath
imports Minkowski "HOL-Library.Disjoint_Sets"
begin
text \<open>
In Schutz \cite[pp.~18-30]{schutz1997}, this is ``Chapter 3: Temporal order on a path''.
All theorems are from Schutz, all lemmas are either parts of the Schutz proofs extracted, or
additional lemmas which needed to be added, with the exception of the three transitivity lemmas
leading to Theorem 9, which are given by Schutz as well.
Much of what we'd like to prove about chains with respect to injectivity, surjectivity,
bijectivity, is proved in \<open>TernaryOrdering.thy\<close>.
Some more things are proved in interlude sections.
\<close>
section "Preliminary Results for Primitives"
text \<open>
First some proofs that belong in this section but aren't proved in the book or are covered but
in a different form or off-handed remark.
\<close>
context MinkowskiPrimitive begin
lemma cross_once_notin:
assumes "Q \<in> \<P>"
and "R \<in> \<P>"
and "a \<in> Q"
and "b \<in> Q"
and "b \<in> R"
and "a \<noteq> b"
and "Q \<noteq> R"
shows "a \<notin> R"
using assms paths_cross_once eq_paths by meson
lemma paths_cross_at:
assumes path_Q: "Q \<in> \<P>" and path_R: "R \<in> \<P>"
and Q_neq_R: "Q \<noteq> R"
and QR_nonempty: "Q \<inter> R \<noteq> {}"
and x_inQ: "x \<in> Q" and x_inR: "x \<in> R"
shows "Q \<inter> R = {x}"
proof (rule equalityI)
show "Q \<inter> R \<subseteq> {x}"
proof (rule subsetI, rule ccontr)
fix y
assume y_in_QR: "y \<in> Q \<inter> R"
and y_not_in_just_x: "y \<notin> {x}"
then have y_neq_x: "y \<noteq> x" by simp
then have "\<not> (\<exists>z. Q \<inter> R = {z})"
by (meson Q_neq_R path_Q path_R x_inQ x_inR y_in_QR cross_once_notin IntD1 IntD2)
thus False using paths_cross_once by (meson QR_nonempty Q_neq_R path_Q path_R)
qed
show "{x} \<subseteq> Q \<inter> R" using x_inQ x_inR by simp
qed
lemma events_distinct_paths:
assumes a_event: "a \<in> \<E>"
and b_event: "b \<in> \<E>"
and a_neq_b: "a \<noteq> b"
shows "\<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> b \<in> S \<and> (R \<noteq> S \<longrightarrow> (\<exists>!c\<in>\<E>. R \<inter> S = {c}))"
by (metis events_paths assms paths_cross_once)
end (* context MinkowskiPrimitive *)
context MinkowskiBetweenness begin
lemma assumes "[a;b;c]" shows "\<exists>f. local_long_ch_by_ord f {a,b,c}"
using abc_abc_neq[OF assms] unfolding chain_defs
by (simp add: assms ord_ordered_loc)
lemma between_chain: "[a;b;c] \<Longrightarrow> ch {a,b,c}"
proof -
assume "[a;b;c]"
hence "\<exists>f. local_ordering f betw {a,b,c}"
by (simp add: abc_abc_neq ord_ordered_loc)
hence "\<exists>f. local_long_ch_by_ord f {a,b,c}"
using \<open>[a;b;c]\<close> abc_abc_neq local_long_ch_by_ord_def by auto
thus ?thesis
by (simp add: chain_defs)
qed
end (* context MinkowskiBetweenness *)
section "3.1 Order on a finite chain"
context MinkowskiBetweenness begin
subsection \<open>Theorem 1\<close>
text \<open>
See \<open>Minkowski.abc_only_cba\<close>.
Proving it again here to show it can be done following the prose in Schutz.
\<close>
theorem theorem1 [no_atp]:
assumes abc: "[a;b;c]"
shows "[c;b;a] \<and> \<not> [b;c;a] \<and> \<not> [c;a;b]"
proof -
(* (i) *)
have part_i: "[c;b;a]" using abc abc_sym by simp
(* (ii) *)
have part_ii: "\<not> [b;c;a]"
proof (rule notI)
assume "[b;c;a]"
then have "[a;b;a]" using abc abc_bcd_abd by blast
thus False using abc_ac_neq by blast
qed
(* (iii) *)
have part_iii: "\<not> [c;a;b]"
proof (rule notI)
assume "[c;a;b]"
then have "[c;a;c]" using abc abc_bcd_abd by blast
thus False using abc_ac_neq by blast
qed
thus ?thesis using part_i part_ii part_iii by auto
qed
subsection \<open>Theorem 2\<close>
text \<open>
The lemma \<open>abc_bcd_acd\<close>, equal to the start of Schutz's proof, is given in \<open>Minkowski\<close> in order
to prove some equivalences.
We're splitting up Theorem 2 into two named results:
\begin{itemize}
\item[\<open>order_finite_chain\<close>] there is a betweenness relation for each triple of adjacent events, and
\item[\<open>index_injective\<close>] all events of a chain are distinct.
\end{itemize}
We will be following Schutz' proof for both.
Distinctness of chain events is interpreted as injectivity of the indexing function
(see \<open>index_injective\<close>): we assume that this corresponds to what Schutz means by distinctness
of elements in a sequence.
\<close>
text \<open>
For the case of two-element chains: the elements are distinct by definition,
and the statement on \<^term>\<open>local_ordering\<close> is void (respectively, \<^term>\<open>False \<Longrightarrow> P\<close> for any \<^term>\<open>P\<close>).
We exclude this case from our proof of \<open>order_finite_chain\<close>. Two helper lemmas are provided,
each capturing one of the proofs by induction in Schutz' writing.
\<close>
lemma thm2_ind1:
assumes chX: "local_long_ch_by_ord f X"
and finiteX: "finite X"
shows "\<forall>j i. ((i::nat) < j \<and> j < card X - 1) \<longrightarrow> [f i; f j; f (j + 1)]"
proof (rule allI)+
let ?P = "\<lambda> i j. [f i; f j; f (j+1)]"
fix i j
show "(i<j \<and> j<card X -1) \<longrightarrow> ?P i j"
proof (induct j)
case 0 (* this assumption is False, so easy *)
show ?case by blast
next
case (Suc j)
show ?case
proof (clarify)
assume asm: "i<Suc j" "Suc j<card X -1"
have pj: "?P j (Suc j)"
using asm(2) chX less_diff_conv local_long_ch_by_ord_def local_ordering_def
by (metis Suc_eq_plus1)
have "i<j \<or> i=j" using asm(1)
by linarith
thus "?P i (Suc j)"
proof
assume "i=j"
hence "Suc i = Suc j \<and> Suc (Suc j) = Suc (Suc j)"
by simp
thus "?P i (Suc j)"
using pj by auto
next
assume "i<j"
have "j < card X - 1"
using asm(2) by linarith
thus "?P i (Suc j)"
using \<open>i<j\<close> Suc.hyps asm(1) asm(2) chX finiteX Suc_eq_plus1 abc_bcd_acd pj
by presburger
qed
qed
qed
qed
lemma thm2_ind2:
assumes chX: "local_long_ch_by_ord f X"
and finiteX: "finite X"
shows "\<forall>m l. (0<(l-m) \<and> (l-m) < l \<and> l < card X) \<longrightarrow> [f (l-m-1); f (l-m); (f l)]"
proof (rule allI)+
fix l m
let ?P = "\<lambda> k l. [f (k-1); f k; f l]"
let ?n = "card X"
let ?k = "(l::nat)-m"
show "0 < ?k \<and> ?k < l \<and> l < ?n \<longrightarrow> ?P ?k l"
proof (induct m)
case 0 (* yet again, this assumption is False, so easy *)
show ?case by simp
next
case (Suc m)
show ?case
proof (clarify)
assume asm: "0 < l - Suc m" "l - Suc m < l" "l < ?n"
have "Suc m = 1 \<or> Suc m > 1" by linarith
thus "[f (l - Suc m - 1); f (l - Suc m); f l]" (is ?goal)
proof
assume "Suc m = 1"
show ?goal
proof -
have "l - Suc m < card X"
using asm(2) asm(3) less_trans by blast
then show ?thesis
using \<open>Suc m = 1\<close> asm finiteX thm2_ind1 chX
using Suc_eq_plus1 add_diff_inverse_nat diff_Suc_less
gr_implies_not_zero less_one plus_1_eq_Suc
by (smt local_long_ch_by_ord_def ordering_ord_ijk_loc)
qed
next
assume "Suc m > 1"
show ?goal
apply (rule_tac a="f l" and c="f(l - Suc m - 1)" in abc_sym)
apply (rule_tac a="f l" and c="f(l-Suc m)" and d="f(l-Suc m-1)" and b="f(l-m)" in abc_bcd_acd)
proof -
have "[f(l-m-1); f(l-m); f l]"
using Suc.hyps \<open>1 < Suc m\<close> asm(1,3) by force
thus "[f l; f(l - m); f(l - Suc m)]"
using abc_sym One_nat_def diff_zero minus_nat.simps(2)
by metis
have "Suc(l - Suc m - 1) = l - Suc m" "Suc(l - Suc m) = l-m"
using Suc_pred asm(1) by presburger+
hence "[f(l - Suc m - 1); f(l - Suc m); f(l - m)]"
using chX unfolding local_long_ch_by_ord_def local_ordering_def
by (metis asm(2,3) less_trans_Suc)
thus "[f(l - m); f(l - Suc m); f(l - Suc m - 1)]"
using abc_sym by blast
qed
qed
qed
qed
qed
lemma thm2_ind2b:
assumes chX: "local_long_ch_by_ord f X"
and finiteX: "finite X"
and ordered_nats: "0<k \<and> k<l \<and> l < card X"
shows "[f (k-1); f k; f l]"
using thm2_ind2 finiteX chX ordered_nats
by (metis diff_diff_cancel less_imp_le)
text \<open>
This is Theorem 2 properly speaking, except for the "chain elements are distinct" part
(which is proved as injectivity of the index later). Follows Schutz fairly well!
The statement Schutz proves under (i) is given in \<open>MinkowskiBetweenness.abc_bcd_acd\<close> instead.
\<close>
theorem (*2*) order_finite_chain:
assumes chX: "local_long_ch_by_ord f X"
and finiteX: "finite X"
and ordered_nats: "0 \<le> (i::nat) \<and> i < j \<and> j < l \<and> l < card X"
shows "[f i; f j; f l]"
proof -
let ?n = "card X - 1"
have ord1: "0\<le>i \<and> i<j \<and> j<?n"
using ordered_nats by linarith
have e2: "[f i; f j; f (j+1)]" using thm2_ind1
using Suc_eq_plus1 chX finiteX ord1
by presburger
have e3: "\<forall>k. 0<k \<and> k<l \<longrightarrow> [f (k-1); f k; f l]"
using thm2_ind2b chX finiteX ordered_nats
by blast
have "j<l-1 \<or> j=l-1"
using ordered_nats by linarith
thus ?thesis
proof
assume "j<l-1"
have "[f j; f (j+1); f l]"
using e3 abc_abc_neq ordered_nats
using \<open>j < l - 1\<close> less_diff_conv by auto
thus ?thesis
using e2 abc_bcd_abd
by blast
next
assume "j=l-1"
thus ?thesis using e2
using ordered_nats by auto
qed
qed
corollary (*2*) order_finite_chain2:
assumes chX: "[f\<leadsto>X]"
and finiteX: "finite X"
and ordered_nats: "0 \<le> (i::nat) \<and> i < j \<and> j < l \<and> l < card X"
shows "[f i; f j; f l]"
proof -
have "card X > 2" using ordered_nats by (simp add: eval_nat_numeral)
thus ?thesis using order_finite_chain chain_defs short_ch_card(1) by (metis assms nat_neq_iff)
qed
theorem (*2ii*) index_injective:
fixes i::nat and j::nat
assumes chX: "local_long_ch_by_ord f X"
and finiteX: "finite X"
and indices: "i<j" "j<card X"
shows "f i \<noteq> f j"
proof (cases)
assume "Suc i < j"
then have "[f i; f (Suc(i)); f j]"
using order_finite_chain chX finiteX indices(2) by blast
then show ?thesis
using abc_abc_neq by blast
next
assume "\<not>Suc i < j"
hence "Suc i = j"
using Suc_lessI indices(1) by blast
show ?thesis
proof (cases)
assume "Suc j = card X"
then have "0<i"
proof -
have "card X \<ge> 3"
using assms(1) finiteX long_chain_card_geq by blast
thus ?thesis
using \<open>Suc i = j\<close> \<open>Suc j = card X\<close> by linarith
qed
then have "[f 0; f i; f j]"
using assms order_finite_chain by blast
thus ?thesis
using abc_abc_neq by blast
next
assume "\<not>Suc j = card X"
then have "Suc j < card X"
using Suc_lessI indices(2) by blast
then have "[f i; f j; f(Suc j)]"
using chX finiteX indices(1) order_finite_chain by blast
thus ?thesis
using abc_abc_neq by blast
qed
qed
theorem (*2ii*) index_injective2:
fixes i::nat and j::nat
assumes chX: "[f\<leadsto>X]"
and finiteX: "finite X"
and indices: "i<j" "j<card X"
shows "f i \<noteq> f j"
using assms(1) unfolding ch_by_ord_def
proof (rule disjE)
assume asm: "short_ch_by_ord f X"
hence "card X = 2" using short_ch_card(1) by simp
hence "j=1" "i=0" using indices plus_1_eq_Suc by auto
thus ?thesis using asm unfolding chain_defs by force
next
assume "local_long_ch_by_ord f X" thus ?thesis using index_injective assms by presburger
qed
text \<open>
Surjectivity of the index function is easily derived from the definition of \<open>local_ordering\<close>,
so we obtain bijectivity as an easy corollary to the second part of Theorem 2.
\<close>
corollary index_bij_betw:
assumes chX: "local_long_ch_by_ord f X"
and finiteX: "finite X"
shows "bij_betw f {0..<card X} X"
proof (unfold bij_betw_def, (rule conjI))
show "inj_on f {0..<card X}"
using index_injective[OF assms] by (metis (mono_tags) atLeastLessThan_iff inj_onI nat_neq_iff)
{
fix n assume "n \<in> {0..<card X}"
then have "f n \<in> X"
using assms unfolding chain_defs local_ordering_def by auto
} moreover {
fix x assume "x \<in> X"
then have "\<exists>n \<in> {0..<card X}. f n = x"
using assms unfolding chain_defs local_ordering_def
using atLeastLessThan_iff bot_nat_0.extremum by blast
} ultimately show "f ` {0..<card X} = X" by blast
qed
corollary index_bij_betw2:
assumes chX: "[f\<leadsto>X]"
and finiteX: "finite X"
shows "bij_betw f {0..<card X} X"
using assms(1) unfolding ch_by_ord_def
proof (rule disjE)
assume "local_long_ch_by_ord f X"
thus "bij_betw f {0..<card X} X" using index_bij_betw assms by presburger
next
assume asm: "short_ch_by_ord f X"
show "bij_betw f {0..<card X} X"
proof (unfold bij_betw_def, (rule conjI))
show "inj_on f {0..<card X}"
using index_injective2[OF assms] by (metis (mono_tags) atLeastLessThan_iff inj_onI nat_neq_iff)
{
fix n assume asm2: "n \<in> {0..<card X}"
have "f n \<in> X"
using asm asm2 short_ch_card(1) apply (simp add: eval_nat_numeral)
by (metis One_nat_def less_Suc0 less_antisym short_ch_ord_in)
} moreover {
fix x assume asm2: "x \<in> X"
have "\<exists>n \<in> {0..<card X}. f n = x"
using short_ch_card(1) short_ch_by_ord_def asm asm2 atLeast0_lessThan_Suc by (auto simp: eval_nat_numeral)[1]
} ultimately show "f ` {0..<card X} = X" by blast
qed
qed
subsection "Additional lemmas about chains"
lemma first_neq_last:
assumes "[f\<leadsto>Q|x..z]"
shows "x\<noteq>z"
apply (cases rule: finite_chain_with_cases[OF assms])
using chain_defs apply (metis Suc_1 card_2_iff diff_Suc_1)
using index_injective[of f Q 0 "card Q - 1"]
by (metis card.infinite diff_is_0_eq diff_less gr0I le_trans less_imp_le_nat
less_numeral_extra(1) numeral_le_one_iff semiring_norm(70))
lemma index_middle_element:
assumes "[f\<leadsto>X|a..b..c]"
shows "\<exists>n. 0<n \<and> n<(card X - 1) \<and> f n = b"
proof -
obtain n where n_def: "n < card X" "f n = b"
using local_ordering_def assms chain_defs by (metis two_ordered_loc)
have "0<n \<and> n<(card X - 1) \<and> f n = b"
using assms chain_defs n_def
by (metis (no_types, lifting) Suc_pred' gr_implies_not0 less_SucE not_gr_zero)
thus ?thesis by blast
qed
text \<open>
Another corollary to Theorem 2, without mentioning indices.
\<close>
corollary fin_ch_betw: "[f\<leadsto>X|a..b..c] \<Longrightarrow> [a;b;c]"
using order_finite_chain2 index_middle_element
using finite_chain_def finite_chain_with_def finite_long_chain_with_def
by (metis (no_types, lifting) card_gt_0_iff diff_less empty_iff le_eq_less_or_eq less_one)
lemma long_chain_2_imp_3: "\<lbrakk>[f\<leadsto>X|a..c]; card X > 2\<rbrakk> \<Longrightarrow> \<exists>b. [f\<leadsto>X|a..b..c]"
using points_in_chain first_neq_last finite_long_chain_with_def
by (metis card_2_iff' numeral_less_iff semiring_norm(75,78))
lemma finite_chain2_betw: "\<lbrakk>[f\<leadsto>X|a..c]; card X > 2\<rbrakk> \<Longrightarrow> \<exists>b. [a;b;c]"
using fin_ch_betw long_chain_2_imp_3 by metis
lemma finite_long_chain_with_alt [chain_alts]: "[f\<leadsto>Q|x..y..z] \<longleftrightarrow> [f\<leadsto>Q|x..z] \<and> [x;y;z] \<and> y\<in>Q"
proof
{
assume "[f\<leadsto>Q|x .. z] \<and> [x;y;z] \<and> y\<in>Q"
thus "[f\<leadsto>Q|x..y..z]"
using abc_abc_neq finite_long_chain_with_def by blast
} {
assume asm: "[f\<leadsto>Q|x..y..z]"
show "[f\<leadsto>Q|x .. z] \<and> [x;y;z] \<and> y\<in>Q"
using asm fin_ch_betw finite_long_chain_with_def by blast
}
qed
lemma finite_long_chain_with_card: "[f\<leadsto>Q|x..y..z] \<Longrightarrow> card Q \<ge> 3"
unfolding chain_defs numeral_3_eq_3 by fastforce
lemma finite_long_chain_with_alt2:
assumes "finite Q" "local_long_ch_by_ord f Q" "f 0 = x" "f (card Q - 1) = z" "[x;y;z] \<and> y\<in>Q"
shows "[f\<leadsto>Q|x..y..z]"
using assms finite_chain_alt finite_chain_with_def finite_long_chain_with_alt by blast
lemma finite_long_chain_with_alt3:
assumes "finite Q" "local_long_ch_by_ord f Q" "f 0 = x" "f (card Q - 1) = z" "y\<noteq>x \<and> y\<noteq>z \<and> y\<in>Q"
shows "[f\<leadsto>Q|x..y..z]"
using assms finite_chain_alt finite_chain_with_def finite_long_chain_with_def by auto
lemma chain_sym_obtain:
assumes "[f\<leadsto>X|a..b..c]"
obtains g where "[g\<leadsto>X|c..b..a]" and "g=(\<lambda>n. f (card X - 1 - n))"
using ordering_sym_loc[of betw X f] abc_sym assms unfolding chain_defs
using first_neq_last points_in_long_chain(3)
by (metis assms diff_self_eq_0 empty_iff finite_long_chain_with_def insert_iff minus_nat.diff_0)
lemma chain_sym:
assumes "[f\<leadsto>X|a..b..c]"
shows "[\<lambda>n. f (card X - 1 - n)\<leadsto>X|c..b..a]"
using chain_sym_obtain [where f=f and a=a and b=b and c=c and X=X]
using assms(1) by blast
lemma chain_sym2:
assumes "[f\<leadsto>X|a..c]"
shows "[\<lambda>n. f (card X - 1 - n)\<leadsto>X|c..a]"
proof -
{
assume asm: "a = f 0" "c = f (card X - 1)"
and asm_short: "short_ch_by_ord f X"
hence cardX: "card X = 2"
using short_ch_card(1) by auto
hence ac: "f 0 = a" "f 1 = c"
by (simp add: asm)+
have "n=1 \<or> n=0" if "n<card X" for n
using cardX that by linarith
hence fn_eq: "(\<lambda>n. if n = 0 then f 1 else f 0) = (\<lambda>n. f (card X - Suc n))" if "n<card X" for n
by (metis One_nat_def Zero_not_Suc ac(2) asm(2) not_gr_zero old.nat.inject zero_less_diff)
have "c = f (card X - 1 - 0)" and "a = f (card X - 1 - (card X - 1))"
and "short_ch_by_ord (\<lambda>n. f (card X - 1 - n)) X"
apply (simp add: asm)+
using short_ch_sym[OF asm_short] fn_eq \<open>f 1 = c\<close> asm(2) short_ch_by_ord_def by fastforce
}
consider "short_ch_by_ord f X"|"\<exists>b. [f\<leadsto>X|a..b..c]"
using assms long_chain_2_imp_3 finite_chain_with_alt by fastforce
thus ?thesis
apply cases
using \<open>\<lbrakk>a=f 0; c=f (card X-1); short_ch_by_ord f X\<rbrakk> \<Longrightarrow> short_ch_by_ord (\<lambda>n. f (card X -1-n)) X\<close>
assms finite_chain_alt finite_chain_with_def apply auto[1]
using chain_sym finite_long_chain_with_alt by blast
qed
lemma chain_sym_obtain2:
assumes "[f\<leadsto>X|a..c]"
obtains g where "[g\<leadsto>X|c..a]" and "g=(\<lambda>n. f (card X - 1 - n))"
using assms chain_sym2 by auto
end (* context MinkowskiBetweenness *)
section "Preliminary Results for Kinematic Triangles and Paths/Betweenness"
text \<open>
Theorem 3 (collinearity)
First we prove some lemmas that will be very helpful.
\<close>
context MinkowskiPrimitive begin
lemma triangle_permutes [no_atp]:
assumes "\<triangle> a b c"
shows "\<triangle> a c b" "\<triangle> b a c" "\<triangle> b c a" "\<triangle> c a b" "\<triangle> c b a"
using assms by (auto simp add: kinematic_triangle_def)+
lemma triangle_paths [no_atp]:
assumes tri_abc: "\<triangle> a b c"
shows "path_ex a b" "path_ex a c" "path_ex b c"
using tri_abc by (auto simp add: kinematic_triangle_def)+
lemma triangle_paths_unique:
assumes tri_abc: "\<triangle> a b c"
shows "\<exists>!ab. path ab a b"
using path_unique tri_abc triangle_paths(1) by auto
text \<open>
The definition of the kinematic triangle says that there exist paths that $a$ and $b$ pass through,
and $a$ and $c$ pass through etc that are not equal. But we can show there is a \emph{unique} $ab$ that $a$
and $b$ pass through, and assuming there is a path $abc$ that $a, b, c$ pass through, it must be
unique. Therefore \<open>ab = abc\<close> and \<open>ac = abc\<close>, but \<open>ab \<noteq> ac\<close>, therefore \<open>False\<close>.
Lemma \<open>tri_three_paths\<close> is not in the books but might simplify some path obtaining.
\<close>
lemma triangle_diff_paths:
assumes tri_abc: "\<triangle> a b c"
shows "\<not> (\<exists>Q\<in>\<P>. a \<in> Q \<and> b \<in> Q \<and> c \<in> Q)"
proof (rule notI)
assume not_thesis: "\<exists>Q\<in>\<P>. a \<in> Q \<and> b \<in> Q \<and> c \<in> Q"
(* First show [abc] or similar so I can show the path through abc is unique. *)
then obtain abc where path_abc: "abc \<in> \<P> \<and> a \<in> abc \<and> b \<in> abc \<and> c \<in> abc" by auto
have abc_neq: "a \<noteq> b \<and> a \<noteq> c \<and> b \<noteq> c" using tri_abc kinematic_triangle_def by simp
(* Now extract some information from \<triangle> a b c. *)
have "\<exists>ab\<in>\<P>. \<exists>ac\<in>\<P>. ab \<noteq> ac \<and> a \<in> ab \<and> b \<in> ab \<and> a \<in> ac \<and> c \<in> ac"
using tri_abc kinematic_triangle_def by metis
then obtain ab ac where ab_ac_relate: "ab \<in> \<P> \<and> ac \<in> \<P> \<and> ab \<noteq> ac \<and> {a,b} \<subseteq> ab \<and> {a,c} \<subseteq> ac"
by blast
have "\<exists>!ab\<in>\<P>. a \<in> ab \<and> b \<in> ab" using tri_abc triangle_paths_unique by blast
then have ab_eq_abc: "ab = abc" using path_abc ab_ac_relate by auto
have "\<exists>!ac\<in>\<P>. a \<in> ac \<and> b \<in> ac" using tri_abc triangle_paths_unique by blast
then have ac_eq_abc: "ac = abc" using path_abc ab_ac_relate eq_paths abc_neq by auto
have "ab = ac" using ab_eq_abc ac_eq_abc by simp
thus False using ab_ac_relate by simp
qed
lemma tri_three_paths [elim]:
assumes tri_abc: "\<triangle> a b c"
shows "\<exists>ab bc ca. path ab a b \<and> path bc b c \<and> path ca c a \<and> ab \<noteq> bc \<and> ab \<noteq> ca \<and> bc \<noteq> ca"
using tri_abc triangle_diff_paths triangle_paths(2,3) triangle_paths_unique
by fastforce
lemma triangle_paths_neq:
assumes tri_abc: "\<triangle> a b c"
and path_ab: "path ab a b"
and path_ac: "path ac a c"
shows "ab \<noteq> ac"
using assms triangle_diff_paths by blast
end (*context MinkowskiPrimitive*)
context MinkowskiBetweenness begin
lemma abc_ex_path_unique:
assumes abc: "[a;b;c]"
shows "\<exists>!Q\<in>\<P>. a \<in> Q \<and> b \<in> Q \<and> c \<in> Q"
proof -
have a_neq_c: "a \<noteq> c" using abc_ac_neq abc by simp
have "\<exists>Q\<in>\<P>. a \<in> Q \<and> b \<in> Q \<and> c \<in> Q" using abc_ex_path abc by simp
then obtain P Q where path_P: "P \<in> \<P>" and abc_inP: "a \<in> P \<and> b \<in> P \<and> c \<in> P"
and path_Q: "Q \<in> \<P>" and abc_in_Q: "a \<in> Q \<and> b \<in> Q \<and> c \<in> Q" by auto
then have "P = Q" using a_neq_c eq_paths by blast
thus ?thesis using eq_paths a_neq_c using abc_inP path_P by auto
qed
lemma betw_c_in_path:
assumes abc: "[a;b;c]"
and path_ab: "path ab a b"
shows "c \<in> ab"
(* By abc_ex_path, there is a path through a b c. By eq_paths there can be only one, which must be ab. *)
using eq_paths abc_ex_path assms by blast
lemma betw_b_in_path:
assumes abc: "[a;b;c]"
and path_ab: "path ac a c"
shows "b \<in> ac"
using assms abc_ex_path_unique path_unique by blast
lemma betw_a_in_path:
assumes abc: "[a;b;c]"
and path_ab: "path bc b c"
shows "a \<in> bc"
using assms abc_ex_path_unique path_unique by blast
lemma triangle_not_betw_abc:
assumes tri_abc: "\<triangle> a b c"
shows "\<not> [a;b;c]"
using tri_abc abc_ex_path triangle_diff_paths by blast
lemma triangle_not_betw_acb:
assumes tri_abc: "\<triangle> a b c"
shows "\<not> [a;c;b]"
by (simp add: tri_abc triangle_not_betw_abc triangle_permutes(1))
lemma triangle_not_betw_bac:
assumes tri_abc: "\<triangle> a b c"
shows "\<not> [b;a;c]"
by (simp add: tri_abc triangle_not_betw_abc triangle_permutes(2))
lemma triangle_not_betw_any:
assumes tri_abc: "\<triangle> a b c"
shows "\<not> (\<exists>d\<in>{a,b,c}. \<exists>e\<in>{a,b,c}. \<exists>f\<in>{a,b,c}. [d;e;f])"
by (metis abc_ex_path abc_abc_neq empty_iff insertE tri_abc triangle_diff_paths)
end (*context MinkowskiBetweenness*)
section "3.2 First collinearity theorem"
theorem (*3*) (in MinkowskiChain) collinearity_alt2:
assumes tri_abc: "\<triangle> a b c"
and path_de: "path de d e"
(* This follows immediately from tri_abc without it as an assumption, but we need ab in scope
to refer to it in the conclusion. *)
and path_ab: "path ab a b"
and bcd: "[b;c;d]"
and cea: "[c;e;a]"
shows "\<exists>f\<in>de\<inter>ab. [a;f;b]"
proof -
have "\<exists>f\<in>ab \<inter> de. \<exists>X ord. [ord\<leadsto>X|a..f..b]"
proof -
have "path_ex a c" using tri_abc triangle_paths(2) by auto
then obtain ac where path_ac: "path ac a c" by auto
have "path_ex b c" using tri_abc triangle_paths(3) by auto
then obtain bc where path_bc: "path bc b c" by auto
have ab_neq_ac: "ab \<noteq> ac" using triangle_paths_neq path_ab path_ac tri_abc by fastforce
have ab_neq_bc: "ab \<noteq> bc" using eq_paths ab_neq_ac path_ab path_ac path_bc by blast
have ac_neq_bc: "ac \<noteq> bc" using eq_paths ab_neq_bc path_ab path_ac path_bc by blast
have d_in_bc: "d \<in> bc" using bcd betw_c_in_path path_bc by blast
have e_in_ac: "e \<in> ac" using betw_b_in_path cea path_ac by blast
show ?thesis
using O6_old [where Q = ab and R = ac and S = bc and T = de and a = a and b = b and c = c]
ab_neq_ac ab_neq_bc ac_neq_bc path_ab path_bc path_ac path_de bcd cea d_in_bc e_in_ac
by auto
qed
thus ?thesis using fin_ch_betw by blast
qed
theorem (*3*) (in MinkowskiChain) collinearity_alt:
assumes tri_abc: "\<triangle> a b c"
and path_de: "path de d e"
and bcd: "[b;c;d]"
and cea: "[c;e;a]"
shows "\<exists>ab. path ab a b \<and> (\<exists>f\<in>de\<inter>ab. [a;f;b])"
proof -
have ex_path_ab: "path_ex a b"
using tri_abc triangle_paths_unique by blast
then obtain ab where path_ab: "path ab a b"
by blast
have "\<exists>f\<in>ab \<inter> de. \<exists>X g. [g\<leadsto>X|a..f..b]"
proof -
have "path_ex a c" using tri_abc triangle_paths(2) by auto
then obtain ac where path_ac: "path ac a c" by auto
have "path_ex b c" using tri_abc triangle_paths(3) by auto
then obtain bc where path_bc: "path bc b c" by auto
have ab_neq_ac: "ab \<noteq> ac" using triangle_paths_neq path_ab path_ac tri_abc by fastforce
have ab_neq_bc: "ab \<noteq> bc" using eq_paths ab_neq_ac path_ab path_ac path_bc by blast
have ac_neq_bc: "ac \<noteq> bc" using eq_paths ab_neq_bc path_ab path_ac path_bc by blast
have d_in_bc: "d \<in> bc" using bcd betw_c_in_path path_bc by blast
have e_in_ac: "e \<in> ac" using betw_b_in_path cea path_ac by blast
show ?thesis
using O6_old [where Q = ab and R = ac and S = bc and T = de and a = a and b = b and c = c]
ab_neq_ac ab_neq_bc ac_neq_bc path_ab path_bc path_ac path_de bcd cea d_in_bc e_in_ac
by auto
qed
thus ?thesis using fin_ch_betw path_ab by fastforce
qed
theorem (*3*) (in MinkowskiChain) collinearity:
assumes tri_abc: "\<triangle> a b c"
and path_de: "path de d e"
and bcd: "[b;c;d]"
and cea: "[c;e;a]"
shows "(\<exists>f\<in>de\<inter>(path_of a b). [a;f;b])"
proof -
let ?ab = "path_of a b"
have path_ab: "path ?ab a b"
using tri_abc theI' [OF triangle_paths_unique] by blast
have "\<exists>f\<in>?ab \<inter> de. \<exists>X ord. [ord\<leadsto>X|a..f..b]"
proof -
have "path_ex a c" using tri_abc triangle_paths(2) by auto
then obtain ac where path_ac: "path ac a c" by auto
have "path_ex b c" using tri_abc triangle_paths(3) by auto
then obtain bc where path_bc: "path bc b c" by auto
have ab_neq_ac: "?ab \<noteq> ac" using triangle_paths_neq path_ab path_ac tri_abc by fastforce
have ab_neq_bc: "?ab \<noteq> bc" using eq_paths ab_neq_ac path_ab path_ac path_bc by blast
have ac_neq_bc: "ac \<noteq> bc" using eq_paths ab_neq_bc path_ab path_ac path_bc by blast
have d_in_bc: "d \<in> bc" using bcd betw_c_in_path path_bc by blast
have e_in_ac: "e \<in> ac" using betw_b_in_path cea path_ac by blast
show ?thesis
using O6_old [where Q = ?ab and R = ac and S = bc and T = de and a = a and b = b and c = c]
ab_neq_ac ab_neq_bc ac_neq_bc path_ab path_bc path_ac path_de bcd cea d_in_bc e_in_ac
IntI Int_commute
by (metis (no_types, lifting))
qed
thus ?thesis using fin_ch_betw by blast
qed
section "Additional results for Paths and Unreachables"
context MinkowskiPrimitive begin
text \<open>The degenerate case.\<close>
lemma big_bang:
assumes no_paths: "\<P> = {}"
shows "\<exists>a. \<E> = {a}"
proof -
have "\<exists>a. a \<in> \<E>" using nonempty_events by blast
then obtain a where a_event: "a \<in> \<E>" by auto
have "\<not> (\<exists>b\<in>\<E>. b \<noteq> a)"
proof (rule notI)
assume "\<exists>b\<in>\<E>. b \<noteq> a"
then have "\<exists>Q. Q \<in> \<P>" using events_paths a_event by auto
thus False using no_paths by simp
qed
then have "\<forall>b\<in>\<E>. b = a" by simp
thus ?thesis using a_event by auto
qed
lemma two_events_then_path:
assumes two_events: "\<exists>a\<in>\<E>. \<exists>b\<in>\<E>. a \<noteq> b"
shows "\<exists>Q. Q \<in> \<P>"
proof -
have "(\<forall>a. \<E> \<noteq> {a}) \<longrightarrow> \<P> \<noteq> {}" using big_bang by blast
then have "\<P> \<noteq> {}" using two_events by blast
thus ?thesis by blast
qed
lemma paths_are_events: "\<forall>Q\<in>\<P>. \<forall>a\<in>Q. a \<in> \<E>"
by simp
lemma same_empty_unreach:
"\<lbrakk>Q \<in> \<P>; a \<in> Q\<rbrakk> \<Longrightarrow> unreach-on Q from a = {}"
apply (unfold unreachable_subset_def)
by simp
lemma same_path_reachable:
"\<lbrakk>Q \<in> \<P>; a \<in> Q; b \<in> Q\<rbrakk> \<Longrightarrow> a \<in> Q - unreach-on Q from b"
by (simp add: same_empty_unreach)
text \<open>
If we have two paths crossing and $a$ is on the crossing point, and $b$ is on one of the paths,
then $a$ is in the reachable part of the path $b$ is on.
\<close>
lemma same_path_reachable2:
"\<lbrakk>Q \<in> \<P>; R \<in> \<P>; a \<in> Q; a \<in> R; b \<in> Q\<rbrakk> \<Longrightarrow> a \<in> R - unreach-on R from b"
unfolding unreachable_subset_def by blast
(* This will never be used without R \<in> \<P> but we might as well leave it off as the proof doesn't
need it. *)
lemma cross_in_reachable:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
and b_inQ: "b \<in> Q"
and b_inR: "b \<in> R"
shows "b \<in> R - unreach-on R from a"
unfolding unreachable_subset_def using a_inQ b_inQ b_inR path_Q by auto
lemma reachable_path:
assumes path_Q: "Q \<in> \<P>"
and b_event: "b \<in> \<E>"
and a_reachable: "a \<in> Q - unreach-on Q from b"
shows "\<exists>R\<in>\<P>. a \<in> R \<and> b \<in> R"
proof -
have a_inQ: "a \<in> Q" using a_reachable by simp
have "Q \<notin> \<P> \<or> b \<notin> \<E> \<or> b \<in> Q \<or> (\<exists>R\<in>\<P>. b \<in> R \<and> a \<in> R)"
using a_reachable unreachable_subset_def by auto
then have "b \<in> Q \<or> (\<exists>R\<in>\<P>. b \<in> R \<and> a \<in> R)" using path_Q b_event by simp
thus ?thesis
proof (rule disjE)
assume "b \<in> Q"
thus ?thesis using a_inQ path_Q by auto
next
assume "\<exists>R\<in>\<P>. b \<in> R \<and> a \<in> R"
thus ?thesis using conj_commute by simp
qed
qed
end (* context MinkowskiPrimitive *)
context MinkowskiBetweenness begin
lemma ord_path_of:
assumes "[a;b;c]"
shows "a \<in> path_of b c" "b \<in> path_of a c" "c \<in> path_of a b"
and "path_of a b = path_of a c" "path_of a b = path_of b c"
proof -
show "a \<in> path_of b c"
using betw_a_in_path[of a b c "path_of b c"] path_of_ex abc_ex_path_unique abc_abc_neq assms
by (smt (z3) betw_a_in_path the1_equality)
show "b \<in> path_of a c"
using betw_b_in_path[of a b c "path_of a c"] path_of_ex abc_ex_path_unique abc_abc_neq assms
by (smt (z3) betw_b_in_path the1_equality)
show "c \<in> path_of a b"
using betw_c_in_path[of a b c "path_of a b"] path_of_ex abc_ex_path_unique abc_abc_neq assms
by (smt (z3) betw_c_in_path the1_equality)
show "path_of a b = path_of a c"
by (metis (mono_tags) abc_ac_neq assms betw_b_in_path betw_c_in_path ends_notin_segment seg_betw)
show "path_of a b = path_of b c"
by (metis (mono_tags) assms betw_a_in_path betw_c_in_path ends_notin_segment seg_betw)
qed
text \<open>
Schutz defines chains as subsets of paths. The result below proves that even though we do not
include this fact in our definition, it still holds, at least for finite chains.
\<close>
text \<open>
Notice that this whole proof would be unnecessary if including path-belongingness in the
definition, as Schutz does. This would also keep path-belongingness independent of axiom O1 and O4,
thus enabling an independent statement of axiom O6, which perhaps we now lose. In exchange,
our definition is slightly weaker (for \<open>card X \<ge> 3\<close> and \<open>infinite X\<close>).
\<close>
lemma obtain_index_fin_chain:
assumes "[f\<leadsto>X]" "x\<in>X" "finite X"
obtains i where "f i = x" "i<card X"
proof -
have "\<exists>i<card X. f i = x"
using assms(1) unfolding ch_by_ord_def
proof (rule disjE)
assume asm: "short_ch_by_ord f X"
hence "card X = 2"
using short_ch_card(1) by auto
thus "\<exists>i<card X. f i = x"
using asm assms(2) unfolding chain_defs by force
next
assume asm: "local_long_ch_by_ord f X"
thus "\<exists>i<card X. f i = x"
using asm assms(2,3) unfolding chain_defs local_ordering_def by blast
qed
thus ?thesis using that by blast
qed
lemma obtain_index_inf_chain:
assumes "[f\<leadsto>X]" "x\<in>X" "infinite X"
obtains i where "f i = x"
using assms unfolding chain_defs local_ordering_def by blast
lemma fin_chain_on_path2:
assumes "[f\<leadsto>X]" "finite X"
shows "\<exists>P\<in>\<P>. X\<subseteq>P"
using assms(1) unfolding ch_by_ord_def
proof (rule disjE)
assume "short_ch_by_ord f X"
thus ?thesis
using short_ch_by_ord_def by auto
next
assume asm: "local_long_ch_by_ord f X"
have "[f 0;f 1;f 2]"
using order_finite_chain asm assms(2) local_long_ch_by_ord_def by auto
then obtain P where "P\<in>\<P>" "{f 0,f 1,f 2} \<subseteq> P"
by (meson abc_ex_path empty_subsetI insert_subset)
then have "path P (f 0) (f 1)"
using \<open>[f 0;f 1;f 2]\<close> by (simp add: abc_abc_neq)
{
fix x assume "x\<in>X"
then obtain i where i: "f i = x" "i<card X"
using obtain_index_fin_chain assms by blast
consider "i=0\<or>i=1"|"i>1" by linarith
hence "x\<in>P"
proof (cases)
case 1 thus ?thesis
using i(1) \<open>{f 0, f 1, f 2} \<subseteq> P\<close> by auto
next
case 2
hence "[f 0;f 1;f i]"
using assms i(2) order_finite_chain2 by auto
hence "{f 0,f 1,f i}\<subseteq>P"
using \<open>path P (f 0) (f 1)\<close> betw_c_in_path by blast
thus ?thesis by (simp add: i(1))
qed
}
thus ?thesis
using \<open>P\<in>\<P>\<close> by auto
qed
lemma fin_chain_on_path:
assumes "[f\<leadsto>X]" "finite X"
shows "\<exists>!P\<in>\<P>. X\<subseteq>P"
proof -
obtain P where P: "P\<in>\<P>" "X\<subseteq>P"
using fin_chain_on_path2[OF assms] by auto
obtain a b where ab: "a\<in>X" "b\<in>X" "a\<noteq>b"
using assms(1) unfolding chain_defs by (metis assms(2) insertCI three_in_set3)
thus ?thesis using P ab by (meson eq_paths in_mono)
qed
lemma fin_chain_on_path3:
assumes "[f\<leadsto>X]" "finite X" "a\<in>X" "b\<in>X" "a\<noteq>b"
shows "X \<subseteq> path_of a b"
proof -
let ?ab = "path_of a b"
obtain P where P: "P\<in>\<P>" "X\<subseteq>P" using fin_chain_on_path2[OF assms(1,2)] by auto
have "path P a b" using P assms(3-5) by auto
then have "path ?ab a b" using path_of_ex by blast
hence "?ab = P" using eq_paths \<open>path P a b\<close> by auto
thus "X \<subseteq> path_of a b" using P by simp
qed
end (* context MinkowskiBetweenness *)
context MinkowskiUnreachable begin
text \<open>
First some basic facts about the primitive notions, which seem to belong here.
I don't think any/all of these are explicitly proved in Schutz.
\<close>
lemma no_empty_paths [simp]:
assumes "Q\<in>\<P>"
shows "Q\<noteq>{}"
(*using assms nonempty_events two_in_unreach unreachable_subset_def by blast*)
proof -
obtain a where "a\<in>\<E>" using nonempty_events by blast
have "a\<in>Q \<or> a\<notin>Q" by auto
thus ?thesis
proof
assume "a\<in>Q"
thus ?thesis by blast
next
assume "a\<notin>Q"
then obtain b where "b\<in>unreach-on Q from a"
using two_in_unreach \<open>a \<in> \<E>\<close> assms
by blast
thus ?thesis
using unreachable_subset_def by auto
qed
qed
lemma events_ex_path:
assumes ge1_path: "\<P> \<noteq> {}"
shows "\<forall>x\<in>\<E>. \<exists>Q\<in>\<P>. x \<in> Q"
(*using ex_in_conv no_empty_paths in_path_event assms events_paths
by metis*)
proof
fix x
assume x_event: "x \<in> \<E>"
have "\<exists>Q. Q \<in> \<P>" using ge1_path using ex_in_conv by blast
then obtain Q where path_Q: "Q \<in> \<P>" by auto
then have "\<exists>y. y \<in> Q" using no_empty_paths by blast
then obtain y where y_inQ: "y \<in> Q" by auto
then have y_event: "y \<in> \<E>" using in_path_event path_Q by simp
have "\<exists>P\<in>\<P>. x \<in> P"
proof cases
assume "x = y"
thus ?thesis using y_inQ path_Q by auto
next
assume "x \<noteq> y"
thus ?thesis using events_paths x_event y_event by auto
qed
thus "\<exists>Q\<in>\<P>. x \<in> Q" by simp
qed
lemma unreach_ge2_then_ge2:
assumes "\<exists>x\<in>unreach-on Q from b. \<exists>y\<in>unreach-on Q from b. x \<noteq> y"
shows "\<exists>x\<in>Q. \<exists>y\<in>Q. x \<noteq> y"
using assms unreachable_subset_def by auto
text \<open>
This lemma just proves that the chain obtained to bound the unreachable set of a path
is indeed on that path. Extends I6; requires Theorem 2; used in Theorem 13.
Seems to be assumed in Schutz' chain notation in I6.
\<close>
lemma chain_on_path_I6:
assumes path_Q: "Q\<in>\<P>"
and event_b: "b\<notin>Q" "b\<in>\<E>"
and unreach: "Q\<^sub>x \<in> unreach-on Q from b" "Q\<^sub>z \<in> unreach-on Q from b" "Q\<^sub>x \<noteq> Q\<^sub>z"
and X_def: "[f\<leadsto>X|Q\<^sub>x..Q\<^sub>z]"
"(\<forall>i\<in>{1 .. card X - 1}. (f i) \<in> unreach-on Q from b \<and> (\<forall>Q\<^sub>y\<in>\<E>. [(f(i-1)); Q\<^sub>y; f i] \<longrightarrow> Q\<^sub>y \<in> unreach-on Q from b))"
shows "X\<subseteq>Q"
proof -
have 1: "path Q Q\<^sub>x Q\<^sub>z" using unreachable_subset_def unreach path_Q by simp
then have 2: "Q = path_of Q\<^sub>x Q\<^sub>z" using path_of_ex[of Q\<^sub>x Q\<^sub>z] by (meson eq_paths)
have "X\<subseteq>path_of Q\<^sub>x Q\<^sub>z"
proof (rule fin_chain_on_path3[of f])
from unreach(3) show "Q\<^sub>x \<noteq> Q\<^sub>z" by simp
from X_def chain_defs show "[f\<leadsto>X]" "finite X" by metis+
from assms(7) points_in_chain show "Q\<^sub>x \<in> X" "Q\<^sub>z \<in> X" by auto
qed
thus ?thesis using 2 by simp
qed
end (* context MinkowskiUnreachable *)
section "Results about Paths as Sets"
text \<open>
Note several of the following don't need MinkowskiPrimitive, they are just Set lemmas;
nevertheless I'm naming them and writing them this way for clarity.
\<close>
context MinkowskiPrimitive begin
lemma distinct_paths:
assumes "Q \<in> \<P>"
and "R \<in> \<P>"
and "d \<notin> Q"
and "d \<in> R"
shows "R \<noteq> Q"
using assms by auto
lemma distinct_paths2:
assumes "Q \<in> \<P>"
and "R \<in> \<P>"
and "\<exists>d. d \<notin> Q \<and> d \<in> R"
shows "R \<noteq> Q"
using assms by auto
lemma external_events_neq:
"\<lbrakk>Q \<in> \<P>; a \<in> Q; b \<in> \<E>; b \<notin> Q\<rbrakk> \<Longrightarrow> a \<noteq> b"
by auto
lemma notin_cross_events_neq:
"\<lbrakk>Q \<in> \<P>; R \<in> \<P>; Q \<noteq> R; a \<in> Q; b \<in> R; a \<notin> R\<inter>Q\<rbrakk> \<Longrightarrow> a \<noteq> b"
by blast
lemma nocross_events_neq:
"\<lbrakk>Q \<in> \<P>; R \<in> \<P>; a \<in> Q; b \<in> R; R\<inter>Q = {}\<rbrakk> \<Longrightarrow> a \<noteq> b"
by auto
text \<open>
Given a nonempty path $Q$, and an external point $d$, we can find another path
$R$ passing through $d$ (by I2 aka \<open>events_paths\<close>). This path is distinct
from $Q$, as it passes through a point external to it.
\<close>
lemma external_path:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
and d_notinQ: "d \<notin> Q"
and d_event: "d \<in> \<E>"
shows "\<exists>R\<in>\<P>. d \<in> R"
proof -
have a_neq_d: "a \<noteq> d" using a_inQ d_notinQ by auto
thus "\<exists>R\<in>\<P>. d \<in> R" using events_paths by (meson a_inQ d_event in_path_event path_Q)
qed
lemma distinct_path:
assumes "Q \<in> \<P>"
and "a \<in> Q"
and "d \<notin> Q"
and "d \<in> \<E>"
shows "\<exists>R\<in>\<P>. R \<noteq> Q"
using assms external_path by metis
lemma external_distinct_path:
assumes "Q \<in> \<P>"
and "a \<in> Q"
and "d \<notin> Q"
and "d \<in> \<E>"
shows "\<exists>R\<in>\<P>. R \<noteq> Q \<and> d \<in> R"
using assms external_path by fastforce
end (* context MinkowskiPrimitive *)
section "3.3 Boundedness of the unreachable set"
subsection \<open>Theorem 4 (boundedness of the unreachable set)\<close>
text \<open>
The same assumptions as I7, different conclusion.
This doesn't just give us boundedness, it gives us another event outside of the unreachable
set, as long as we have one already.
I7 conclusion: \<open>\<exists>g X Qn. [g\<leadsto>X|Qx..Qy..Qn] \<and> Qn \<in> Q - unreach-on Q from b\<close>
\<close>
theorem (*4*) (in MinkowskiUnreachable) unreachable_set_bounded:
assumes path_Q: "Q \<in> \<P>"
and b_nin_Q: "b \<notin> Q"
and b_event: "b \<in> \<E>"
and Qx_reachable: "Qx \<in> Q - unreach-on Q from b"
and Qy_unreachable: "Qy \<in> unreach-on Q from b"
shows "\<exists>Qz\<in>Q - unreach-on Q from b. [Qx;Qy;Qz] \<and> Qx \<noteq> Qz"
using assms I7_old finite_long_chain_with_def fin_ch_betw
by (metis first_neq_last)
subsection \<open>Theorem 5 (first existence theorem)\<close>
text \<open>
The lemma below is used in the contradiction in \<open>external_event\<close>,
which is the essential part to Theorem 5(i).
\<close>
lemma (in MinkowskiUnreachable) only_one_path:
assumes path_Q: "Q \<in> \<P>"
and all_inQ: "\<forall>a\<in>\<E>. a \<in> Q"
and path_R: "R \<in> \<P>"
shows "R = Q"
proof (rule ccontr)
assume "\<not> R = Q"
then have R_neq_Q: "R \<noteq> Q" by simp
have "\<E> = Q"
by (simp add: all_inQ antisym path_Q path_sub_events subsetI)
hence "R\<subset>Q"
using R_neq_Q path_R path_sub_events by auto
obtain c where "c\<notin>R" "c\<in>Q"
using \<open>R \<subset> Q\<close> by blast
then obtain a b where "path R a b"
using \<open>\<E> = Q\<close> path_R two_in_unreach unreach_ge2_then_ge2 by blast
have "a\<in>Q" "b\<in>Q"
using \<open>\<E> = Q\<close> \<open>path R a b\<close> in_path_event by blast+
thus False using eq_paths
using R_neq_Q \<open>path R a b\<close> path_Q by blast
qed
context MinkowskiSpacetime begin
text \<open>Unfortunately, we cannot assume that a path exists without the axiom of dimension.\<close>
lemma external_event:
assumes path_Q: "Q \<in> \<P>"
shows "\<exists>d\<in>\<E>. d \<notin> Q"
proof (rule ccontr)
assume "\<not> (\<exists>d\<in>\<E>. d \<notin> Q)"
then have all_inQ: "\<forall>d\<in>\<E>. d \<in> Q" by simp
then have only_one_path: "\<forall>P\<in>\<P>. P = Q" by (simp add: only_one_path path_Q)
thus False using ex_3SPRAY three_SPRAY_ge4 four_paths by auto
qed
text \<open>
Now we can prove the first part of the theorem's conjunction.
This follows pretty much exactly the same pattern as the book, except it relies on more
intermediate lemmas.
\<close>
theorem (*5i*) ge2_events:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
shows "\<exists>b\<in>Q. b \<noteq> a"
proof -
have d_notinQ: "\<exists>d\<in>\<E>. d \<notin> Q" using path_Q external_event by blast
then obtain d where "d \<in> \<E>" and "d \<notin> Q" by auto
thus ?thesis using two_in_unreach [where Q = Q and b = d] path_Q unreach_ge2_then_ge2 by metis
qed
text \<open>
Simple corollary which is easier to use when we don't have one event on a path yet.
Anything which uses this implicitly used \<open>no_empty_paths\<close> on top of \<open>ge2_events\<close>.
\<close>
lemma ge2_events_lax:
assumes path_Q: "Q \<in> \<P>"
shows "\<exists>a\<in>Q. \<exists>b\<in>Q. a \<noteq> b"
proof -
have "\<exists>a\<in>\<E>. a \<in> Q" using path_Q no_empty_paths by (meson ex_in_conv in_path_event)
thus ?thesis using path_Q ge2_events by blast
qed
lemma ex_crossing_path:
assumes path_Q: "Q \<in> \<P>"
shows "\<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>c. c \<in> R \<and> c \<in> Q)"
proof -
obtain a where a_inQ: "a \<in> Q" using ge2_events_lax path_Q by blast
obtain d where d_event: "d \<in> \<E>"
and d_notinQ: "d \<notin> Q" using external_event path_Q by auto
then have "a \<noteq> d" using a_inQ by auto
then have ex_through_d: "\<exists>R\<in>\<P>. \<exists>S\<in>\<P>. a \<in> R \<and> d \<in> S \<and> R \<inter> S \<noteq> {}"
using events_paths [where a = a and b = d]
path_Q a_inQ in_path_event d_event by simp
then obtain R S where path_R: "R \<in> \<P>"
and path_S: "S \<in> \<P>"
and a_inR: "a \<in> R"
and d_inS: "d \<in> S"
and R_crosses_S: "R \<inter> S \<noteq> {}" by auto
have S_neq_Q: "S \<noteq> Q" using d_notinQ d_inS by auto
show ?thesis
proof cases
assume "R = Q"
then have "Q \<inter> S \<noteq> {}" using R_crosses_S by simp
thus ?thesis using S_neq_Q path_S by blast
next
assume "R \<noteq> Q"
thus ?thesis using a_inQ a_inR path_R by blast
qed
qed
text \<open>
If we have two paths $Q$ and $R$ with $a$ on $Q$ and $b$ at the intersection of $Q$ and $R$, then by
\<open>two_in_unreach\<close> (I5) and Theorem 4 (boundedness of the unreachable set), there is an unreachable
set from $a$ on one side of $b$ on $R$, and on the other side of that there is an event which is
reachable from $a$ by some path, which is the path we want.
\<close>
lemma path_past_unreach:
assumes path_Q: "Q \<in> \<P>"
and path_R: "R \<in> \<P>"
and a_inQ: "a \<in> Q"
and b_inQ: "b \<in> Q"
and b_inR: "b \<in> R"
and Q_neq_R: "Q \<noteq> R"
and a_neq_b: "a \<noteq> b"
shows "\<exists>S\<in>\<P>. S \<noteq> Q \<and> a \<in> S \<and> (\<exists>c. c \<in> S \<and> c \<in> R)"
proof -
obtain d where d_event: "d \<in> \<E>"
and d_notinR: "d \<notin> R" using external_event path_R by blast
have b_reachable: "b \<in> R - unreach-on R from a" using cross_in_reachable path_R a_inQ b_inQ b_inR path_Q by simp
have a_notinR: "a \<notin> R" using cross_once_notin
Q_neq_R a_inQ a_neq_b b_inQ b_inR path_Q path_R by blast
then obtain u where "u \<in> unreach-on R from a"
using two_in_unreach a_inQ in_path_event path_Q path_R by blast
then obtain c where c_reachable: "c \<in> R - unreach-on R from a"
and c_neq_b: "b \<noteq> c" using unreachable_set_bounded
[where Q = R and Qx = b and b = a and Qy = u]
path_R d_event d_notinR
using a_inQ a_notinR b_reachable in_path_event path_Q by blast
then obtain S where S_facts: "S \<in> \<P> \<and> a \<in> S \<and> (c \<in> S \<and> c \<in> R)" using reachable_path
by (metis Diff_iff a_inQ in_path_event path_Q path_R)
then have "S \<noteq> Q" using Q_neq_R b_inQ b_inR c_neq_b eq_paths path_R by blast
thus ?thesis using S_facts by auto
qed
theorem (*5ii*) ex_crossing_at:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
shows "\<exists>ac\<in>\<P>. ac \<noteq> Q \<and> (\<exists>c. c \<notin> Q \<and> a \<in> ac \<and> c \<in> ac)"
proof -
obtain b where b_inQ: "b \<in> Q"
and a_neq_b: "a \<noteq> b" using a_inQ ge2_events path_Q by blast
have "\<exists>R\<in>\<P>. R \<noteq> Q \<and> (\<exists>e. e \<in> R \<and> e \<in> Q)" by (simp add: ex_crossing_path path_Q)
then obtain R e where path_R: "R \<in> \<P>"
and R_neq_Q: "R \<noteq> Q"
and e_inR: "e \<in> R"
and e_inQ: "e \<in> Q" by auto
thus ?thesis
proof cases
assume e_eq_a: "e = a"
then have "\<exists>c. c \<in> unreach-on R from b" using R_neq_Q a_inQ a_neq_b b_inQ e_inR path_Q path_R
two_in_unreach path_unique in_path_event by metis
thus ?thesis using R_neq_Q e_eq_a e_inR path_Q path_R
eq_paths ge2_events_lax by metis
next
assume e_neq_a: "e \<noteq> a"
(* We know the whole of R isn't unreachable from a because e is on R and both a and e are on Q.
We also know there is some point after e, and after the unreachable set, which is reachable
from a (because there are at least two events in the unreachable set, and it is bounded). *)
(* This does follow Schutz, if you unfold the proof for path_past_unreach here, though it's a
little trickier than Schutz made it seem. *)
then have "\<exists>S\<in>\<P>. S \<noteq> Q \<and> a \<in> S \<and> (\<exists>c. c \<in> S \<and> c \<in> R)"
using path_past_unreach
R_neq_Q a_inQ e_inQ e_inR path_Q path_R by auto
thus ?thesis by (metis R_neq_Q e_inR e_neq_a eq_paths path_Q path_R)
qed
qed
(* Alternative formulation using the path function *)
lemma (*5ii_alt*) ex_crossing_at_alt:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
shows "\<exists>ac. \<exists>c. path ac a c \<and> ac \<noteq> Q \<and> c \<notin> Q"
using ex_crossing_at assms by fastforce
end (* context MinkowskiSpacetime *)
section "3.4 Prolongation"
context MinkowskiSpacetime begin
lemma (in MinkowskiPrimitive) unreach_on_path:
"a \<in> unreach-on Q from b \<Longrightarrow> a \<in> Q"
using unreachable_subset_def by simp
lemma (in MinkowskiUnreachable) unreach_equiv:
"\<lbrakk>Q \<in> \<P>; R \<in> \<P>; a \<in> Q; b \<in> R; a \<in> unreach-on Q from b\<rbrakk> \<Longrightarrow> b \<in> unreach-on R from a"
unfolding unreachable_subset_def by auto
theorem (*6i*) prolong_betw:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
and b_inQ: "b \<in> Q"
and ab_neq: "a \<noteq> b"
shows "\<exists>c\<in>\<E>. [a;b;c]"
proof -
obtain e ae where e_event: "e \<in> \<E>"
and e_notinQ: "e \<notin> Q"
and path_ae: "path ae a e"
using ex_crossing_at a_inQ path_Q in_path_event by blast
have "b \<notin> ae" using a_inQ ab_neq b_inQ e_notinQ eq_paths path_Q path_ae by blast
then obtain f where f_unreachable: "f \<in> unreach-on ae from b"
using two_in_unreach b_inQ in_path_event path_Q path_ae by blast
then have b_unreachable: "b \<in> unreach-on Q from f" using unreach_equiv
by (metis (mono_tags, lifting) CollectD b_inQ path_Q unreachable_subset_def)
have a_reachable: "a \<in> Q - unreach-on Q from f"
using same_path_reachable2 [where Q = ae and R = Q and a = a and b = f]
path_ae a_inQ path_Q f_unreachable unreach_on_path by blast
thus ?thesis
using unreachable_set_bounded [where Qy = b and Q = Q and b = f and Qx = a]
b_unreachable unreachable_subset_def by auto
qed
lemma (in MinkowskiSpacetime) prolong_betw2:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
and b_inQ: "b \<in> Q"
and ab_neq: "a \<noteq> b"
shows "\<exists>c\<in>Q. [a;b;c]"
by (metis assms betw_c_in_path prolong_betw)
lemma (in MinkowskiSpacetime) prolong_betw3:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
and b_inQ: "b \<in> Q"
and ab_neq: "a \<noteq> b"
shows "\<exists>c\<in>Q. \<exists>d\<in>Q. [a;b;c] \<and> [a;b;d] \<and> c\<noteq>d"
by (metis (full_types) abc_abc_neq abc_bcd_abd a_inQ ab_neq b_inQ path_Q prolong_betw2)
lemma finite_path_has_ends:
assumes "Q \<in> \<P>"
and "X \<subseteq> Q"
and "finite X"
and "card X \<ge> 3"
shows "\<exists>a\<in>X. \<exists>b\<in>X. a \<noteq> b \<and> (\<forall>c\<in>X. a \<noteq> c \<and> b \<noteq> c \<longrightarrow> [a;c;b])"
using assms
proof (induct "card X - 3" arbitrary: X)
case 0
then have "card X = 3"
by linarith
then obtain a b c where X_eq: "X = {a, b, c}"
by (metis card_Suc_eq numeral_3_eq_3)
then have abc_neq: "a \<noteq> b" "a \<noteq> c" "b \<noteq> c"
by (metis \<open>card X = 3\<close> empty_iff insert_iff order_refl three_in_set3)+
then consider "[a;b;c]" | "[b;c;a]" | "[c;a;b]"
using some_betw [of Q a b c] "0.prems"(1) "0.prems"(2) X_eq by auto
thus ?case
proof (cases)
assume "[a;b;c]"
thus ?thesis \<comment> \<open>All d not equal to a or c is just d = b, so it immediately follows.\<close>
using X_eq abc_neq(2) by blast
next
assume "[b;c;a]"
thus ?thesis
by (simp add: X_eq abc_neq(1))
next
assume "[c;a;b]"
thus ?thesis
using X_eq abc_neq(3) by blast
qed
next
case IH: (Suc n)
obtain Y x where X_eq: "X = insert x Y" and "x \<notin> Y"
by (meson IH.prems(4) Set.set_insert three_in_set3)
then have "card Y - 3 = n" "card Y \<ge> 3"
using IH.hyps(2) IH.prems(3) X_eq \<open>x \<notin> Y\<close> by auto
then obtain a b where ab_Y: "a \<in> Y" "b \<in> Y" "a \<noteq> b"
and Y_ends: "\<forall>c\<in>Y. (a \<noteq> c \<and> b \<noteq> c) \<longrightarrow> [a;c;b]"
using IH(1) [of Y] IH.prems(1-3) X_eq by auto
consider "[a;x;b]" | "[x;b;a]" | "[b;a;x]"
using some_betw [of Q a x b] ab_Y IH.prems(1,2) X_eq \<open>x \<notin> Y\<close> by auto
thus ?case
proof (cases)
assume "[a;x;b]"
thus ?thesis
using Y_ends X_eq ab_Y by auto
next
assume "[x;b;a]"
{ fix c
assume "c \<in> X" "x \<noteq> c" "a \<noteq> c"
then have "[x;c;a]"
by (smt IH.prems(2) X_eq Y_ends \<open>[x;b;a]\<close> ab_Y(1) abc_abc_neq abc_bcd_abd abc_only_cba(3) abc_sym \<open>Q \<in> \<P>\<close> betw_b_in_path insert_iff some_betw subsetD)
}
thus ?thesis
using X_eq \<open>[x;b;a]\<close> ab_Y(1) abc_abc_neq insert_iff by force
next
assume "[b;a;x]"
{ fix c
assume "c \<in> X" "b \<noteq> c" "x \<noteq> c"
then have "[b;c;x]"
by (smt IH.prems(2) X_eq Y_ends \<open>[b;a;x]\<close> ab_Y(1) abc_abc_neq abc_bcd_acd abc_only_cba(1)
abc_sym \<open>Q \<in> \<P>\<close> betw_a_in_path insert_iff some_betw subsetD)
}
thus ?thesis
using X_eq \<open>x \<notin> Y\<close> ab_Y(2) by fastforce
qed
qed
lemma obtain_fin_path_ends:
assumes path_X: "X\<in>\<P>"
and fin_Q: "finite Q"
and card_Q: "card Q \<ge> 3"
and events_Q: "Q\<subseteq>X"
obtains a b where "a\<noteq>b" and "a\<in>Q" and "b\<in>Q" and "\<forall>c\<in>Q. (a\<noteq>c \<and> b\<noteq>c) \<longrightarrow> [a;c;b]"
proof -
obtain n where "n\<ge>0" and "card Q = n+3"
using card_Q nat_le_iff_add
by auto
then obtain a b where "a\<noteq>b" and "a\<in>Q" and "b\<in>Q" and "\<forall>c\<in>Q. (a\<noteq>c \<and> b\<noteq>c) \<longrightarrow> [a;c;b]"
using finite_path_has_ends assms \<open>n\<ge>0\<close>
by metis
thus ?thesis
using that by auto
qed
lemma path_card_nil:
assumes "Q\<in>\<P>"
shows "card Q = 0"
proof (rule ccontr)
assume "card Q \<noteq> 0"
obtain n where "n = card Q"
by auto
hence "n\<ge>1"
using \<open>card Q \<noteq> 0\<close> by linarith
then consider (n1) "n=1" | (n2) "n=2" | (n3) "n\<ge>3"
by linarith
thus False
proof (cases)
case n1
thus ?thesis
using One_nat_def card_Suc_eq ge2_events_lax singletonD assms(1)
by (metis \<open>n = card Q\<close>)
next
case n2
then obtain a b where "a\<noteq>b" and "a\<in>Q" and "b\<in>Q"
using ge2_events_lax assms(1) by blast
then obtain c where "c\<in>Q" and "c\<noteq>a" and "c\<noteq>b"
using prolong_betw2 by (metis abc_abc_neq assms(1))
hence "card Q \<noteq> 2"
by (metis \<open>a \<in> Q\<close> \<open>a \<noteq> b\<close> \<open>b \<in> Q\<close> card_2_iff')
thus False
using \<open>n = card Q\<close> \<open>n = 2\<close> by blast
next
case n3
have fin_Q: "finite Q"
proof -
have "(0::nat) \<noteq> 1"
by simp
then show ?thesis
by (meson \<open>card Q \<noteq> 0\<close> card.infinite)
qed
have card_Q: "card Q \<ge> 3"
using \<open>n = card Q\<close> n3 by blast
have "Q\<subseteq>Q" by simp
then obtain a b where "a\<in>Q" and "b\<in>Q" and "a\<noteq>b"
and acb: "\<forall>c\<in>Q. (c\<noteq>a \<and> c\<noteq>b) \<longrightarrow> [a;c;b]"
using obtain_fin_path_ends card_Q fin_Q assms(1)
by metis
then obtain x where "[a;b;x]" and "x\<in>Q"
using prolong_betw2 assms(1) by blast
thus False
by (metis acb abc_abc_neq abc_only_cba(2))
qed
qed
theorem (*6ii*) infinite_paths:
assumes "P\<in>\<P>"
shows "infinite P"
proof
assume fin_P: "finite P"
have "P\<noteq>{}"
by (simp add: assms)
hence "card P \<noteq> 0"
by (simp add: fin_P)
moreover have "\<not>(card P \<ge> 1)"
using path_card_nil
by (simp add: assms)
ultimately show False
by simp
qed
end (* contex MinkowskiSpacetime *)
section "3.5 Second collinearity theorem"
text \<open>We start with a useful betweenness lemma.\<close>
lemma (in MinkowskiBetweenness) some_betw2:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
and b_inQ: "b \<in> Q"
and c_inQ: "c \<in> Q"
shows "a = b \<or> a = c \<or> b = c \<or> [a;b;c] \<or> [b;c;a] \<or> [c;a;b]"
using a_inQ b_inQ c_inQ path_Q some_betw by blast
lemma (in MinkowskiPrimitive) paths_tri:
assumes path_ab: "path ab a b"
and path_bc: "path bc b c"
and path_ca: "path ca c a"
and a_notin_bc: "a \<notin> bc"
shows "\<triangle> a b c"
proof -
have abc_events: "a \<in> \<E> \<and> b \<in> \<E> \<and> c \<in> \<E>"
using path_ab path_bc path_ca in_path_event by auto
have abc_neq: "a \<noteq> b \<and> a \<noteq> c \<and> b \<noteq> c"
using path_ab path_bc path_ca by auto
have paths_neq: "ab \<noteq> bc \<and> ab \<noteq> ca \<and> bc \<noteq> ca"
using a_notin_bc cross_once_notin path_ab path_bc path_ca by blast
show ?thesis
unfolding kinematic_triangle_def
using abc_events abc_neq paths_neq path_ab path_bc path_ca
by auto
qed
lemma (in MinkowskiPrimitive) paths_tri2:
assumes path_ab: "path ab a b"
and path_bc: "path bc b c"
and path_ca: "path ca c a"
and ab_neq_bc: "ab \<noteq> bc"
shows "\<triangle> a b c"
by (meson ab_neq_bc cross_once_notin path_ab path_bc path_ca paths_tri)
text \<open>
Schutz states it more like
\<open>\<lbrakk>tri_abc; bcd; cea\<rbrakk> \<Longrightarrow> (path de d e \<longrightarrow> \<exists>f\<in>de. [a;f;b]\<and>[d;e;f])\<close>.
Equivalent up to usage of \<open>impI\<close>.
\<close>
theorem (*7*) (in MinkowskiChain) collinearity2:
assumes tri_abc: "\<triangle> a b c"
and bcd: "[b;c;d]"
and cea: "[c;e;a]"
and path_de: "path de d e"
shows "\<exists>f. [a;f;b] \<and> [d;e;f]"
proof -
obtain ab where path_ab: "path ab a b" using tri_abc triangle_paths_unique by blast
then obtain f where afb: "[a;f;b]"
and f_in_de: "f \<in> de" using collinearity tri_abc path_de path_ab bcd cea by blast
(* af will be used a few times, so obtain it here. *)
obtain af where path_af: "path af a f" using abc_abc_neq afb betw_b_in_path path_ab by blast
have "[d;e;f]"
proof -
have def_in_de: "d \<in> de \<and> e \<in> de \<and> f \<in> de" using path_de f_in_de by simp
then have five_poss:"f = d \<or> f = e \<or> [e;f;d] \<or> [f;d;e] \<or> [d;e;f]"
using path_de some_betw2 by blast
have "f = d \<or> f = e \<longrightarrow> (\<exists>Q\<in>\<P>. a \<in> Q \<and> b \<in> Q \<and> c \<in> Q)"
by (metis abc_abc_neq afb bcd betw_a_in_path betw_b_in_path cea path_ab)
then have f_neq_d_e: "f \<noteq> d \<and> f \<noteq> e" using tri_abc
using triangle_diff_paths by simp
then consider "[e;f;d]" | "[f;d;e]" | "[d;e;f]" using five_poss by linarith
thus ?thesis
proof (cases)
assume efd: "[e;f;d]"
obtain dc where path_dc: "path dc d c" using abc_abc_neq abc_ex_path bcd by blast
obtain ce where path_ce: "path ce c e" using abc_abc_neq abc_ex_path cea by blast
have "dc\<noteq>ce"
using bcd betw_a_in_path betw_c_in_path cea path_ce path_dc tri_abc triangle_diff_paths
by blast
hence "\<triangle> d c e"
using paths_tri2 path_ce path_dc path_de by blast
then obtain x where x_in_af: "x \<in> af"
and dxc: "[d;x;c]"
using collinearity
[where a = d and b = c and c = e and d = a and e = f and de = af]
cea efd path_dc path_af by blast
then have x_in_dc: "x \<in> dc" using betw_b_in_path path_dc by blast
then have "x = b" using eq_paths by (metis path_af path_dc afb bcd tri_abc x_in_af
betw_a_in_path betw_c_in_path triangle_diff_paths)
then have "[d;b;c]" using dxc by simp
then have "False" using bcd abc_only_cba [where a = b and b = c and c = d] by simp
thus ?thesis by simp
next
assume fde: "[f;d;e]"
obtain bd where path_bd: "path bd b d" using abc_abc_neq abc_ex_path bcd by blast
obtain ea where path_ea: "path ea e a" using abc_abc_neq abc_ex_path_unique cea by blast
obtain fe where path_fe: "path fe f e" using f_in_de f_neq_d_e path_de by blast
have "fe\<noteq>ea"
using tri_abc afb cea path_ea path_fe
by (metis abc_abc_neq betw_a_in_path betw_c_in_path triangle_paths_neq)
hence "\<triangle> e a f"
by (metis path_unique path_af path_ea path_fe paths_tri2)
then obtain y where y_in_bd: "y \<in> bd"
and eya: "[e;y;a]" thm collinearity
using collinearity
[where a = e and b = a and c = f and d = b and e = d and de = bd]
afb fde path_bd path_ea by blast
then have "y = c" by (metis (mono_tags, lifting)
afb bcd cea path_bd tri_abc
abc_ac_neq betw_b_in_path path_unique triangle_paths(2)
triangle_paths_neq)
then have "[e;c;a]" using eya by simp
then have "False" using cea abc_only_cba [where a = c and b = e and c = a] by simp
thus ?thesis by simp
next
assume "[d;e;f]"
thus ?thesis by assumption
qed
qed
thus ?thesis using afb f_in_de by blast
qed
section "3.6 Order on a path - Theorems 8 and 9"
context MinkowskiSpacetime begin
subsection \<open>Theorem 8 (as in Veblen (1911) Theorem 6)\<close>
text \<open>
Note \<open>a'b'c'\<close> don't necessarily form a triangle, as there still needs to be paths between them.
\<close>
theorem (*8*) (in MinkowskiChain) tri_betw_no_path:
assumes tri_abc: "\<triangle> a b c"
and ab'c: "[a; b'; c]"
and bc'a: "[b; c'; a]"
and ca'b: "[c; a'; b]"
shows "\<not> (\<exists>Q\<in>\<P>. a' \<in> Q \<and> b' \<in> Q \<and> c' \<in> Q)"
proof -
have abc_a'b'c'_neq: "a \<noteq> a' \<and> a \<noteq> b' \<and> a \<noteq> c'
\<and> b \<noteq> a' \<and> b \<noteq> b' \<and> b \<noteq> c'
\<and> c \<noteq> a' \<and> c \<noteq> b' \<and> c \<noteq> c'"
using abc_ac_neq
by (metis ab'c abc_abc_neq bc'a ca'b tri_abc triangle_not_betw_abc triangle_permutes(4))
have tri_betw_no_path_single_case: False
if a'b'c': "[a'; b'; c']" and tri_abc: "\<triangle> a b c"
and ab'c: "[a; b'; c]" and bc'a: "[b; c'; a]" and ca'b: "[c; a'; b]"
for a b c a' b' c'
proof -
have abc_a'b'c'_neq: "a \<noteq> a' \<and> a \<noteq> b' \<and> a \<noteq> c'
\<and> b \<noteq> a' \<and> b \<noteq> b' \<and> b \<noteq> c'
\<and> c \<noteq> a' \<and> c \<noteq> b' \<and> c \<noteq> c'"
using abc_abc_neq that by (metis triangle_not_betw_abc triangle_permutes(4))
have c'b'a': "[c'; b'; a']" using abc_sym a'b'c' by simp
have nopath_a'c'b: "\<not> (\<exists>Q\<in>\<P>. a' \<in> Q \<and> c' \<in> Q \<and> b \<in> Q)"
proof (rule notI)
assume "\<exists>Q\<in>\<P>. a' \<in> Q \<and> c' \<in> Q \<and> b \<in> Q"
then obtain Q where path_Q: "Q \<in> \<P>"
and a'_inQ: "a' \<in> Q"
and c'_inQ: "c' \<in> Q"
and b_inQ: "b \<in> Q" by blast
then have ac_inQ: "a \<in> Q \<and> c \<in> Q" using eq_paths
by (metis abc_a'b'c'_neq ca'b bc'a betw_a_in_path betw_c_in_path)
thus False using b_inQ path_Q tri_abc triangle_diff_paths by blast
qed
then have tri_a'bc': "\<triangle> a' b c'"
by (smt bc'a ca'b a'b'c' paths_tri abc_ex_path_unique)
obtain ab' where path_ab': "path ab' a b'" using ab'c abc_a'b'c'_neq abc_ex_path by blast
obtain a'b where path_a'b: "path a'b a' b" using tri_a'bc' triangle_paths(1) by blast
then have "\<exists>x\<in>a'b. [a'; x; b] \<and> [a; b'; x]"
using collinearity2 [where a = a' and b = b and c = c' and e = b' and d = a and de = ab']
bc'a betw_b_in_path c'b'a' path_ab' tri_a'bc' by blast
then obtain x where x_in_a'b: "x \<in> a'b"
and a'xb: "[a'; x; b]"
and ab'x: "[a; b'; x]" by blast
(* ab' \<inter> a'b = {c} doesn't follow as immediately as in Schutz. *)
have c_in_ab': "c \<in> ab'" using ab'c betw_c_in_path path_ab' by auto
have c_in_a'b: "c \<in> a'b" using ca'b betw_a_in_path path_a'b by auto
have ab'_a'b_distinct: "ab' \<noteq> a'b"
using c_in_a'b path_a'b path_ab' tri_abc triangle_diff_paths by blast
have "ab' \<inter> a'b = {c}"
using paths_cross_at ab'_a'b_distinct c_in_a'b c_in_ab' path_a'b path_ab' by auto
then have "x = c" using ab'x path_ab' x_in_a'b betw_c_in_path by auto
then have "[a'; c; b]" using a'xb by auto
thus ?thesis using ca'b abc_only_cba by blast
qed
show ?thesis
proof (rule notI)
assume path_a'b'c': "\<exists>Q\<in>\<P>. a' \<in> Q \<and> b' \<in> Q \<and> c' \<in> Q"
consider "[a'; b'; c']" | "[b'; c'; a']" | "[c'; a'; b']" using some_betw
by (smt abc_a'b'c'_neq path_a'b'c' bc'a ca'b ab'c tri_abc
abc_ex_path cross_once_notin triangle_diff_paths)
thus False
apply (cases)
using tri_betw_no_path_single_case[of a' b' c'] ab'c bc'a ca'b tri_abc apply blast
using tri_betw_no_path_single_case ab'c bc'a ca'b tri_abc triangle_permutes abc_sym by blast+
qed
qed
subsection \<open>Theorem 9\<close>
text \<open>
We now begin working on the transitivity lemmas needed to prove Theorem 9.
Multiple lemmas below obtain primed variables (e.g. \<open>d'\<close>). These are starred in Schutz (e.g. \<open>d*\<close>),
but that notation is already reserved in Isabelle.
\<close>
lemma unreachable_bounded_path_only:
assumes d'_def: "d'\<notin> unreach-on ab from e" "d'\<in>ab" "d'\<noteq>e"
and e_event: "e \<in> \<E>"
and path_ab: "ab \<in> \<P>"
and e_notin_S: "e \<notin> ab"
shows "\<exists>d'e. path d'e d' e"
proof (rule ccontr)
assume "\<not>(\<exists>d'e. path d'e d' e)"
hence "\<not>(\<exists>R\<in>\<P>. d'\<in>R \<and> e\<in>R \<and> d'\<noteq>e)"
by blast
hence "\<not>(\<exists>R\<in>\<P>. e\<in>R \<and> d'\<in>R)"
using d'_def(3) by blast
moreover have "ab\<in>\<P> \<and> e\<in>\<E> \<and> e\<notin>ab"
by (simp add: e_event e_notin_S path_ab)
ultimately have "d'\<in> unreach-on ab from e"
unfolding unreachable_subset_def using d'_def(2)
by blast
thus False
using d'_def(1) by auto
qed
lemma unreachable_bounded_path:
assumes S_neq_ab: "S \<noteq> ab"
and a_inS: "a \<in> S"
and e_inS: "e \<in> S"
and e_neq_a: "e \<noteq> a"
and path_S: "S \<in> \<P>"
and path_ab: "path ab a b"
and path_be: "path be b e"
and no_de: "\<not>(\<exists>de. path de d e)"
and abd:"[a;b;d]"
obtains d' d'e where "d'\<in>ab \<and> path d'e d' e \<and> [b; d; d']"
proof -
have e_event: "e\<in>\<E>"
using e_inS path_S by auto
have "e\<notin>ab"
using S_neq_ab a_inS e_inS e_neq_a eq_paths path_S path_ab by auto
have "ab\<in>\<P> \<and> e\<notin>ab"
using S_neq_ab a_inS e_inS e_neq_a eq_paths path_S path_ab
by auto
have "b \<in> ab - unreach-on ab from e"
using cross_in_reachable path_ab path_be
by blast
have "d \<in> unreach-on ab from e"
using no_de abd path_ab e_event \<open>e\<notin>ab\<close>
betw_c_in_path unreachable_bounded_path_only
by blast
have "\<exists>d' d'e. d'\<in>ab \<and> path d'e d' e \<and> [b; d; d']"
proof -
obtain d' where "[b; d; d']" "d'\<in>ab" "d'\<notin> unreach-on ab from e" "b\<noteq>d'" "e\<noteq>d'"
using unreachable_set_bounded \<open>b \<in> ab - unreach-on ab from e\<close> \<open>d \<in> unreach-on ab from e\<close> e_event \<open>e\<notin>ab\<close> path_ab
by (metis DiffE)
then obtain d'e where "path d'e d' e"
using unreachable_bounded_path_only e_event \<open>e\<notin>ab\<close> path_ab
by blast
thus ?thesis
using \<open>[b; d; d']\<close> \<open>d' \<in> ab\<close>
by blast
qed
thus ?thesis
using that by blast
qed
text \<open>
This lemma collects the first three paragraphs of Schutz' proof of Theorem 9 - Lemma 1.
Several case splits need to be considered, but have no further importance outside of this lemma:
thus we parcel them away from the main proof.\<close>
lemma exist_c'd'_alt:
assumes abc: "[a;b;c]"
and abd: "[a;b;d]"
and dbc: "[d;b;c]" (* the assumption that makes this False for ccontr! *)
and c_neq_d: "c \<noteq> d"
and path_ab: "path ab a b"
and path_S: "S \<in> \<P>"
and a_inS: "a \<in> S"
and e_inS: "e \<in> S"
and e_neq_a: "e \<noteq> a"
and S_neq_ab: "S \<noteq> ab"
and path_be: "path be b e"
shows "\<exists>c' d'. \<exists>d'e c'e. c'\<in>ab \<and> d'\<in>ab
\<and> [a; b; d'] \<and> [c'; b; a] \<and> [c'; b; d']
\<and> path d'e d' e \<and> path c'e c' e"
proof (cases)
assume "\<exists>de. path de d e"
then obtain de where "path de d e"
by blast
hence "[a;b;d] \<and> d\<in>ab"
using abd betw_c_in_path path_ab by blast
thus ?thesis
proof (cases)
assume "\<exists>ce. path ce c e"
then obtain ce where "path ce c e" by blast
have "c \<in> ab"
using abc betw_c_in_path path_ab by blast
thus ?thesis
using \<open>[a;b;d] \<and> d \<in> ab\<close> \<open>\<exists>ce. path ce c e\<close> \<open>c \<in> ab\<close> \<open>path de d e\<close> abc abc_sym dbc
by blast
next
assume "\<not>(\<exists>ce. path ce c e)"
obtain c' c'e where "c'\<in>ab \<and> path c'e c' e \<and> [b; c; c']"
using unreachable_bounded_path [where ab=ab and e=e and b=b and d=c and a=a and S=S and be=be]
S_neq_ab \<open>\<not>(\<exists>ce. path ce c e)\<close> a_inS abc e_inS e_neq_a path_S path_ab path_be
by (metis (mono_tags, lifting))
hence "[a; b; c'] \<and> [d; b; c']"
using abc dbc by blast
hence "[c'; b; a] \<and> [c'; b; d]"
using theorem1 by blast
thus ?thesis
using \<open>[a;b;d] \<and> d \<in> ab\<close> \<open>c' \<in> ab \<and> path c'e c' e \<and> [b; c; c']\<close> \<open>path de d e\<close>
by blast
qed
next
assume "\<not> (\<exists>de. path de d e)"
obtain d' d'e where d'_in_ab: "d' \<in> ab"
and bdd': "[b; d; d']"
and "path d'e d' e"
using unreachable_bounded_path [where ab=ab and e=e and b=b and d=d and a=a and S=S and be=be]
S_neq_ab \<open>\<nexists>de. path de d e\<close> a_inS abd e_inS e_neq_a path_S path_ab path_be
by (metis (mono_tags, lifting))
hence "[a; b; d']" using abd by blast
thus ?thesis
proof (cases)
assume "\<exists>ce. path ce c e"
then obtain ce where "path ce c e" by blast
have "c \<in> ab"
using abc betw_c_in_path path_ab by blast
thus ?thesis
using \<open>[a; b; d']\<close> \<open>d' \<in> ab\<close> \<open>path ce c e\<close> \<open>c \<in> ab\<close> \<open>path d'e d' e\<close> abc abc_sym dbc
by (meson abc_bcd_acd bdd')
next
assume "\<not>(\<exists>ce. path ce c e)"
obtain c' c'e where "c'\<in>ab \<and> path c'e c' e \<and> [b; c; c']"
using unreachable_bounded_path [where ab=ab and e=e and b=b and d=c and a=a and S=S and be=be]
S_neq_ab \<open>\<not>(\<exists>ce. path ce c e)\<close> a_inS abc e_inS e_neq_a path_S path_ab path_be
by (metis (mono_tags, lifting))
hence "[a; b; c'] \<and> [d; b; c']"
using abc dbc by blast
hence "[c'; b; a] \<and> [c'; b; d]"
using theorem1 by blast
thus ?thesis
using \<open>[a; b; d']\<close> \<open>c' \<in> ab \<and> path c'e c' e \<and> [b; c; c']\<close> \<open>path d'e d' e\<close> bdd' d'_in_ab
by blast
qed
qed
lemma exist_c'd':
assumes abc: "[a;b;c]"
and abd: "[a;b;d]"
and dbc: "[d;b;c]" (* the assumption that makes this False for ccontr! *)
and path_S: "path S a e"
and path_be: "path be b e"
and S_neq_ab: "S \<noteq> path_of a b"
shows "\<exists>c' d'. [a; b; d'] \<and> [c'; b; a] \<and> [c'; b; d'] \<and>
path_ex d' e \<and> path_ex c' e"
proof (cases "path_ex d e")
let ?ab = "path_of a b"
have "path_ex a b"
using abc abc_abc_neq abc_ex_path by blast
hence path_ab: "path ?ab a b" using path_of_ex by simp
have "c\<noteq>d" using abc_ac_neq dbc by blast
{
case True
then obtain de where "path de d e"
by blast
hence "[a;b;d] \<and> d\<in>?ab"
using abd betw_c_in_path path_ab by blast
thus ?thesis
proof (cases "path_ex c e")
case True
then obtain ce where "path ce c e" by blast
have "c \<in> ?ab"
using abc betw_c_in_path path_ab by blast
thus ?thesis
using \<open>[a;b;d] \<and> d \<in> ?ab\<close> \<open>\<exists>ce. path ce c e\<close> \<open>c \<in> ?ab\<close> \<open>path de d e\<close> abc abc_sym dbc
by blast
next
case False
obtain c' c'e where "c'\<in>?ab \<and> path c'e c' e \<and> [b; c; c']"
using unreachable_bounded_path [where ab="?ab" and e=e and b=b and d=c and a=a and S=S and be=be]
S_neq_ab \<open>\<not>(\<exists>ce. path ce c e)\<close> abc path_S path_ab path_be
by (metis (mono_tags, lifting))
hence "[a; b; c'] \<and> [d; b; c']"
using abc dbc by blast
hence "[c'; b; a] \<and> [c'; b; d]"
using theorem1 by blast
thus ?thesis
using \<open>[a;b;d] \<and> d \<in> ?ab\<close> \<open>c' \<in> ?ab \<and> path c'e c' e \<and> [b; c; c']\<close> \<open>path de d e\<close>
by blast
qed
} {
case False
obtain d' d'e where d'_in_ab: "d' \<in> ?ab"
and bdd': "[b; d; d']"
and "path d'e d' e"
using unreachable_bounded_path [where ab="?ab" and e=e and b=b and d=d and a=a and S=S and be=be]
S_neq_ab \<open>\<not>path_ex d e\<close> abd path_S path_ab path_be
by (metis (mono_tags, lifting))
hence "[a; b; d']" using abd by blast
thus ?thesis
proof (cases "path_ex c e")
case True
then obtain ce where "path ce c e" by blast
have "c \<in> ?ab"
using abc betw_c_in_path path_ab by blast
thus ?thesis
using \<open>[a; b; d']\<close> \<open>d' \<in> ?ab\<close> \<open>path ce c e\<close> \<open>c \<in> ?ab\<close> \<open>path d'e d' e\<close> abc abc_sym dbc
by (meson abc_bcd_acd bdd')
next
case False
obtain c' c'e where "c'\<in>?ab \<and> path c'e c' e \<and> [b; c; c']"
using unreachable_bounded_path [where ab="?ab" and e=e and b=b and d=c and a=a and S=S and be=be]
S_neq_ab \<open>\<not>(path_ex c e)\<close> abc path_S path_ab path_be
by (metis (mono_tags, lifting))
hence "[a; b; c'] \<and> [d; b; c']"
using abc dbc by blast
hence "[c'; b; a] \<and> [c'; b; d]"
using theorem1 by blast
thus ?thesis
using \<open>[a; b; d']\<close> \<open>c' \<in> ?ab \<and> path c'e c' e \<and> [b; c; c']\<close> \<open>path d'e d' e\<close> bdd' d'_in_ab
by blast
qed
}
qed
lemma exist_f'_alt:
assumes path_ab: "path ab a b"
and path_S: "S \<in> \<P>"
and a_inS: "a \<in> S"
and e_inS: "e \<in> S"
and e_neq_a: "e \<noteq> a"
and f_def: "[e; c'; f]" "f\<in>c'e"
and S_neq_ab: "S \<noteq> ab"
and c'd'_def: "c'\<in>ab \<and> d'\<in>ab
\<and> [a; b; d'] \<and> [c'; b; a] \<and> [c'; b; d']
\<and> path d'e d' e \<and> path c'e c' e"
shows "\<exists>f'. \<exists>f'b. [e; c'; f'] \<and> path f'b f' b"
proof (cases)
assume "\<exists>bf. path bf b f"
thus ?thesis
using \<open>[e; c'; f]\<close> by blast
next
assume "\<not>(\<exists>bf. path bf b f)"
hence "f \<in> unreach-on c'e from b"
using assms(1-5,7-9) abc_abc_neq betw_events eq_paths unreachable_bounded_path_only
by metis
moreover have "c' \<in> c'e - unreach-on c'e from b"
using c'd'_def cross_in_reachable path_ab by blast
moreover have "b\<in>\<E> \<and> b\<notin>c'e"
using \<open>f \<in> unreach-on c'e from b\<close> betw_events c'd'_def same_empty_unreach by auto
ultimately obtain f' where f'_def: "[c'; f; f']" "f'\<in>c'e" "f'\<notin> unreach-on c'e from b" "c'\<noteq>f'" "b\<noteq>f'"
using unreachable_set_bounded c'd'_def
by (metis DiffE)
hence "[e; c'; f']"
using \<open>[e; c'; f]\<close> by blast
moreover obtain f'b where "path f'b f' b"
using \<open>b \<in> \<E> \<and> b \<notin> c'e\<close> c'd'_def f'_def(2,3) unreachable_bounded_path_only
by blast
ultimately show ?thesis by blast
qed
lemma exist_f':
assumes path_ab: "path ab a b"
and path_S: "path S a e"
and f_def: "[e; c'; f]"
and S_neq_ab: "S \<noteq> ab"
and c'd'_def: "[a; b; d']" "[c'; b; a]" "[c'; b; d']"
"path d'e d' e" "path c'e c' e"
shows "\<exists>f'. [e; c'; f'] \<and> path_ex f' b"
proof (cases)
assume "path_ex b f"
thus ?thesis
using f_def by blast
next
assume no_path: "\<not>(path_ex b f)"
have path_S_2: "S \<in> \<P>" "a \<in> S" "e \<in> S" "e \<noteq> a"
using path_S by auto
have "f\<in>c'e"
using betw_c_in_path f_def c'd'_def(5) by blast
have "c'\<in> ab" "d'\<in> ab"
using betw_a_in_path betw_c_in_path c'd'_def(1,2) path_ab by blast+
have "f \<in> unreach-on c'e from b"
using no_path assms(1,4-9) path_S_2 \<open>f\<in>c'e\<close> \<open>c'\<in>ab\<close> \<open>d'\<in>ab\<close>
abc_abc_neq betw_events eq_paths unreachable_bounded_path_only
by metis
moreover have "c' \<in> c'e - unreach-on c'e from b"
using c'd'_def cross_in_reachable path_ab \<open>c' \<in> ab\<close> by blast
moreover have "b\<in>\<E> \<and> b\<notin>c'e"
using \<open>f \<in> unreach-on c'e from b\<close> betw_events c'd'_def same_empty_unreach by auto
ultimately obtain f' where f'_def: "[c'; f; f']" "f'\<in>c'e" "f'\<notin> unreach-on c'e from b" "c'\<noteq>f'" "b\<noteq>f'"
using unreachable_set_bounded c'd'_def
by (metis DiffE)
hence "[e; c'; f']"
using \<open>[e; c'; f]\<close> by blast
moreover obtain f'b where "path f'b f' b"
using \<open>b \<in> \<E> \<and> b \<notin> c'e\<close> c'd'_def f'_def(2,3) unreachable_bounded_path_only
by blast
ultimately show ?thesis by blast
qed
lemma abc_abd_bcdbdc:
assumes abc: "[a;b;c]"
and abd: "[a;b;d]"
and c_neq_d: "c \<noteq> d"
shows "[b;c;d] \<or> [b;d;c]"
proof -
have "\<not> [d;b;c]"
proof (rule notI)
assume dbc: "[d;b;c]"
obtain ab where path_ab: "path ab a b"
using abc_abc_neq abc_ex_path_unique abc by blast
obtain S where path_S: "S \<in> \<P>"
and S_neq_ab: "S \<noteq> ab"
and a_inS: "a \<in> S"
using ex_crossing_at path_ab
by auto
(* This is not as immediate as Schutz presents it. *)
have "\<exists>e\<in>S. e \<noteq> a \<and> (\<exists>be\<in>\<P>. path be b e)"
proof -
have b_notinS: "b \<notin> S" using S_neq_ab a_inS path_S path_ab path_unique by blast
then obtain x y z where x_in_unreach: "x \<in> unreach-on S from b"
and y_in_unreach: "y \<in> unreach-on S from b"
and x_neq_y: "x \<noteq> y"
and z_in_reach: "z \<in> S - unreach-on S from b"
using two_in_unreach [where Q = S and b = b]
in_path_event path_S path_ab a_inS cross_in_reachable
by blast
then obtain w where w_in_reach: "w \<in> S - unreach-on S from b"
and w_neq_z: "w \<noteq> z"
using unreachable_set_bounded [where Q = S and b = b and Qx = z and Qy = x]
b_notinS in_path_event path_S path_ab by blast
thus ?thesis by (metis DiffD1 b_notinS in_path_event path_S path_ab reachable_path z_in_reach)
qed
then obtain e be where e_inS: "e \<in> S"
and e_neq_a: "e \<noteq> a"
and path_be: "path be b e"
by blast
have path_ae: "path S a e"
using a_inS e_inS e_neq_a path_S by auto
have S_neq_ab_2: "S \<noteq> path_of a b"
using S_neq_ab cross_once_notin path_ab path_of_ex by blast
(* Obtain c' and d' as in Schutz (there called c* and d* ) *)
have "\<exists>c' d'.
c'\<in>ab \<and> d'\<in>ab
\<and> [a; b; d'] \<and> [c'; b; a] \<and> [c'; b; d']
\<and> path_ex d' e \<and> path_ex c' e"
using exist_c'd' [where a=a and b=b and c=c and d=d and e=e and be=be and S=S]
using assms(1-2) dbc e_neq_a path_ae path_be S_neq_ab_2
using abc_sym betw_a_in_path path_ab by blast
then obtain c' d' d'e c'e
where c'd'_def: "c'\<in>ab \<and> d'\<in>ab
\<and> [a; b; d'] \<and> [c'; b; a] \<and> [c'; b; d']
\<and> path d'e d' e \<and> path c'e c' e"
by blast
(* Now obtain f' (called f* in Schutz) *)
obtain f where f_def: "f\<in>c'e" "[e; c'; f]"
using c'd'_def prolong_betw2 by blast
then obtain f' f'b where f'_def: "[e; c'; f'] \<and> path f'b f' b"
using exist_f'
[where e=e and c'=c' and b=b and f=f and S=S and ab=ab and d'=d' and a=a and c'e=c'e]
using path_ab path_S a_inS e_inS e_neq_a f_def S_neq_ab c'd'_def
by blast
(* Now we follow Schutz, who follows Veblen. *)
obtain ae where path_ae: "path ae a e" using a_inS e_inS e_neq_a path_S by blast
have tri_aec: "\<triangle> a e c'"
by (smt cross_once_notin S_neq_ab a_inS abc abc_abc_neq abc_ex_path
e_inS e_neq_a path_S path_ab c'd'_def paths_tri)
(* The second collinearity theorem doesn't explicitly capture the fact that it meets at
ae, so Schutz misspoke, but maybe that's an issue with the statement of the theorem. *)
then obtain h where h_in_f'b: "h \<in> f'b"
and ahe: "[a;h;e]"
and f'bh: "[f'; b; h]"
using collinearity2 [where a = a and b = e and c = c' and d = f' and e = b and de = f'b]
f'_def c'd'_def f'_def betw_c_in_path by blast
have tri_dec: "\<triangle> d' e c'"
using cross_once_notin S_neq_ab a_inS abc abc_abc_neq abc_ex_path
e_inS e_neq_a path_S path_ab c'd'_def paths_tri by smt
then obtain g where g_in_f'b: "g \<in> f'b"
and d'ge: "[d'; g; e]"
and f'bg: "[f'; b; g]"
using collinearity2 [where a = d' and b = e and c = c' and d = f' and e = b and de = f'b]
f'_def c'd'_def betw_c_in_path by blast
have "\<triangle> e a d'" by (smt betw_c_in_path paths_tri2 S_neq_ab a_inS abc_ac_neq
abd e_inS e_neq_a c'd'_def path_S path_ab)
thus False
using tri_betw_no_path [where a = e and b = a and c = d' and b' = g and a' = b and c' = h]
f'_def c'd'_def h_in_f'b g_in_f'b abd d'ge ahe abc_sym
by blast
qed
thus ?thesis
by (smt abc abc_abc_neq abc_ex_path abc_sym abd c_neq_d cross_once_notin some_betw)
qed
(* Lemma 2-3.6. *)
lemma abc_abd_acdadc:
assumes abc: "[a;b;c]"
and abd: "[a;b;d]"
and c_neq_d: "c \<noteq> d"
shows "[a;c;d] \<or> [a;d;c]"
proof -
have cba: "[c;b;a]" using abc_sym abc by simp
have dba: "[d;b;a]" using abc_sym abd by simp
have dcb_over_cba: "[d;c;b] \<and> [c;b;a] \<Longrightarrow> [d;c;a]" by auto
have cdb_over_dba: "[c;d;b] \<and> [d;b;a] \<Longrightarrow> [c;d;a]" by auto
have bcdbdc: "[b;c;d] \<or> [b;d;c]" using abc abc_abd_bcdbdc abd c_neq_d by auto
then have dcb_or_cdb: "[d;c;b] \<or> [c;d;b]" using abc_sym by blast
then have "[d;c;a] \<or> [c;d;a]" using abc_only_cba dcb_over_cba cdb_over_dba cba dba by blast
thus ?thesis using abc_sym by auto
qed
(* Lemma 3-3.6. *)
lemma abc_acd_bcd:
assumes abc: "[a;b;c]"
and acd: "[a;c;d]"
shows "[b;c;d]"
proof -
have path_abc: "\<exists>Q\<in>\<P>. a \<in> Q \<and> b \<in> Q \<and> c \<in> Q" using abc by (simp add: abc_ex_path)
have path_acd: "\<exists>Q\<in>\<P>. a \<in> Q \<and> c \<in> Q \<and> d \<in> Q" using acd by (simp add: abc_ex_path)
then have "\<exists>Q\<in>\<P>. b \<in> Q \<and> c \<in> Q \<and> d \<in> Q" using path_abc abc_abc_neq acd cross_once_notin by metis
then have bcd3: "[b;c;d] \<or> [b;d;c] \<or> [c;b;d]" by (metis abc abc_only_cba(1,2) acd some_betw2)
show ?thesis
proof (rule ccontr)
assume "\<not> [b;c;d]"
then have "[b;d;c] \<or> [c;b;d]" using bcd3 by simp
thus False
proof (rule disjE)
assume "[b;d;c]"
then have "[c;d;b]" using abc_sym by simp
then have "[a;c;b]" using acd abc_bcd_abd by blast
thus False using abc abc_only_cba by blast
next
assume cbd: "[c;b;d]"
have cba: "[c;b;a]" using abc abc_sym by blast
have a_neq_d: "a \<noteq> d" using abc_ac_neq acd by auto
then have "[c;a;d] \<or> [c;d;a]" using abc_abd_acdadc cbd cba by simp
thus False using abc_only_cba acd by blast
qed
qed
qed
text \<open>
A few lemmas that don't seem to be proved by Schutz, but can be proven now, after Lemma 3.
These sometimes avoid us having to construct a chain explicitly.
\<close>
lemma abd_bcd_abc:
assumes abd: "[a;b;d]"
and bcd: "[b;c;d]"
shows "[a;b;c]"
proof -
have dcb: "[d;c;b]" using abc_sym bcd by simp
have dba: "[d;b;a]" using abc_sym abd by simp
have "[c;b;a]" using abc_acd_bcd dcb dba by blast
thus ?thesis using abc_sym by simp
qed
lemma abc_acd_abd:
assumes abc: "[a;b;c]"
and acd: "[a;c;d]"
shows "[a;b;d]"
using abc abc_acd_bcd acd by blast
lemma abd_acd_abcacb:
assumes abd: "[a;b;d]"
and acd: "[a;c;d]"
and bc: "b\<noteq>c"
shows "[a;b;c] \<or> [a;c;b]"
proof -
obtain P where P_def: "P\<in>\<P>" "a\<in>P" "b\<in>P" "d\<in>P"
using abd abc_ex_path by blast
hence "c\<in>P"
using acd abc_abc_neq betw_b_in_path by blast
have "\<not>[b;a;c]"
using abc_only_cba abd acd by blast
thus ?thesis
by (metis P_def(1-3) \<open>c \<in> P\<close> abc_abc_neq abc_sym abd acd bc some_betw)
qed
lemma abe_ade_bcd_ace:
assumes abe: "[a;b;e]"
and ade: "[a;d;e]"
and bcd: "[b;c;d]"
shows "[a;c;e]"
proof -
have abdadb: "[a;b;d] \<or> [a;d;b]"
using abc_ac_neq abd_acd_abcacb abe ade bcd by auto
thus ?thesis
proof
assume "[a;b;d]" thus ?thesis
by (meson abc_acd_abd abc_sym ade bcd)
next assume "[a;d;b]" thus ?thesis
by (meson abc_acd_abd abc_sym abe bcd)
qed
qed
text \<open>Now we start on Theorem 9. Based on Veblen (1904) Lemma 2 p357.\<close>
lemma (in MinkowskiBetweenness) chain3:
assumes path_Q: "Q \<in> \<P>"
and a_inQ: "a \<in> Q"
and b_inQ: "b \<in> Q"
and c_inQ: "c \<in> Q"
and abc_neq: "a \<noteq> b \<and> a \<noteq> c \<and> b \<noteq> c"
shows "ch {a,b,c}"
proof -
have abc_betw: "[a;b;c] \<or> [a;c;b] \<or> [b;a;c]"
using assms by (meson in_path_event abc_sym some_betw insert_subset)
have ch1: "[a;b;c] \<longrightarrow> ch {a,b,c}"
using abc_abc_neq ch_by_ord_def ch_def ord_ordered_loc between_chain by auto
have ch2: "[a;c;b] \<longrightarrow> ch {a,c,b}"
using abc_abc_neq ch_by_ord_def ch_def ord_ordered_loc between_chain by auto
have ch3: "[b;a;c] \<longrightarrow> ch {b,a,c}"
using abc_abc_neq ch_by_ord_def ch_def ord_ordered_loc between_chain by auto
show ?thesis
using abc_betw ch1 ch2 ch3 by (metis insert_commute)
qed
lemma overlap_chain: "\<lbrakk>[a;b;c]; [b;c;d]\<rbrakk> \<Longrightarrow> ch {a,b,c,d}"
proof -
assume "[a;b;c]" and "[b;c;d]"
have "\<exists>f. local_ordering f betw {a,b,c,d}"
proof -
have f1: "[a;b;d]"
using \<open>[a;b;c]\<close> \<open>[b;c;d]\<close> by blast
have "[a;c;d]"
using \<open>[a;b;c]\<close> \<open>[b;c;d]\<close> abc_bcd_acd by blast
then show ?thesis
using f1 by (metis (no_types) \<open>[a;b;c]\<close> \<open>[b;c;d]\<close> abc_abc_neq overlap_ordering_loc)
qed
hence "\<exists>f. local_long_ch_by_ord f {a,b,c,d}"
apply (simp add: chain_defs eval_nat_numeral)
using \<open>[a;b;c]\<close> abc_abc_neq
by (smt (z3) \<open>[b;c;d]\<close> card.empty card_insert_disjoint card_insert_le finite.emptyI
finite.insertI insertE insert_absorb insert_not_empty)
thus ?thesis
by (simp add: chain_defs)
qed
text \<open>
The book introduces Theorem 9 before the above three lemmas but can only complete the proof
once they are proven.
This doesn't exactly say it the same way as the book, as the book gives the
\<^term>\<open>local_ordering\<close> (abcd) explicitly (for arbitrarly named events), but is equivalent.
\<close>
theorem (*9*) chain4:
assumes path_Q: "Q \<in> \<P>"
and inQ: "a \<in> Q" "b \<in> Q" "c \<in> Q" "d \<in> Q"
and abcd_neq: "a \<noteq> b \<and> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<and> c \<noteq> d"
shows "ch {a,b,c,d}"
proof -
obtain a' b' c' where a'_pick: "a' \<in> {a,b,c,d}"
and b'_pick: "b' \<in> {a,b,c,d}"
and c'_pick: "c' \<in> {a,b,c,d}"
and a'b'c': "[a'; b'; c']"
using some_betw by (metis inQ(1,2,4) abcd_neq insert_iff path_Q)
then obtain d' where d'_neq: "d' \<noteq> a' \<and> d' \<noteq> b' \<and> d' \<noteq> c'"
and d'_pick: "d' \<in> {a,b,c,d}"
using insert_iff abcd_neq by metis
have all_picked_on_path: "a'\<in>Q" "b'\<in>Q" "c'\<in>Q" "d'\<in>Q"
using a'_pick b'_pick c'_pick d'_pick inQ by blast+
consider "[d'; a'; b']" | "[a'; d'; b']" | "[a'; b'; d']"
using some_betw abc_only_cba all_picked_on_path(1,2,4)
by (metis a'b'c' d'_neq path_Q)
then have picked_chain: "ch {a',b',c',d'}"
proof (cases)
assume "[d'; a'; b']"
thus ?thesis using a'b'c' overlap_chain by (metis (full_types) insert_commute)
next
assume a'd'b': "[a'; d'; b']"
then have "[d'; b'; c']" using abc_acd_bcd a'b'c' by blast
thus ?thesis using a'd'b' overlap_chain by (metis (full_types) insert_commute)
next
assume a'b'd': "[a'; b'; d']"
then have two_cases: "[b'; c'; d'] \<or> [b'; d'; c']" using abc_abd_bcdbdc a'b'c' d'_neq by blast
(* Doing it this way avoids SMT. *)
have case1: "[b'; c'; d'] \<Longrightarrow> ?thesis" using a'b'c' overlap_chain by blast
have case2: "[b'; d'; c'] \<Longrightarrow> ?thesis"
using abc_only_cba abc_acd_bcd a'b'd' overlap_chain
by (metis (full_types) insert_commute)
show ?thesis using two_cases case1 case2 by blast
qed
have "{a',b',c',d'} = {a,b,c,d}"
proof (rule Set.set_eqI, rule iffI)
fix x
assume "x \<in> {a',b',c',d'}"
thus "x \<in> {a,b,c,d}" using a'_pick b'_pick c'_pick d'_pick by auto
next
fix x
assume x_pick: "x \<in> {a,b,c,d}"
have "a' \<noteq> b' \<and> a' \<noteq> c' \<and> a' \<noteq> d' \<and> b' \<noteq> c' \<and> c' \<noteq> d'"
using a'b'c' abc_abc_neq d'_neq by blast
thus "x \<in> {a',b',c',d'}"
using a'_pick b'_pick c'_pick d'_pick x_pick d'_neq by auto
qed
thus ?thesis using picked_chain by simp
qed
theorem (*9*) chain4_alt:
assumes path_Q: "Q \<in> \<P>"
and abcd_inQ: "{a,b,c,d} \<subseteq> Q"
and abcd_distinct: "card {a,b,c,d} = 4"
shows "ch {a,b,c,d}"
proof -
have abcd_neq: "a \<noteq> b \<and> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<and> c \<noteq> d"
using abcd_distinct numeral_3_eq_3
by (smt (z3) card_1_singleton_iff card_2_iff card_3_dist insert_absorb2 insert_commute numeral_1_eq_Suc_0 numeral_eq_iff semiring_norm(85) semiring_norm(88) verit_eq_simplify(8))
have inQ: "a \<in> Q" "b \<in> Q" "c \<in> Q" "d \<in> Q"
using abcd_inQ by auto
show ?thesis using chain4[OF assms(1) inQ] abcd_neq by simp
qed
end (* context MinkowskiSpacetime *)
section "Interlude - Chains, segments, rays"
context MinkowskiBetweenness begin
subsection "General results for chains"
lemma inf_chain_is_long:
assumes "[f\<leadsto>X|x..]"
shows "local_long_ch_by_ord f X \<and> f 0 = x \<and> infinite X"
using chain_defs by (metis assms infinite_chain_alt)
text \<open>A reassurance that the starting point $x$ is implied.\<close>
lemma long_inf_chain_is_semifin:
assumes "local_long_ch_by_ord f X \<and> infinite X"
shows "\<exists> x. [f\<leadsto>X|x..]"
using assms infinite_chain_with_def chain_alts by auto
lemma endpoint_in_semifin:
assumes "[f\<leadsto>X|x..]"
shows "x\<in>X"
using zero_into_ordering_loc by (metis assms empty_iff inf_chain_is_long local_long_ch_by_ord_alt)
text \<open>
Yet another corollary to Theorem 2, without indices, for arbitrary events on the chain.
\<close>
corollary all_aligned_on_fin_chain:
assumes "[f\<leadsto>X]" "finite X"
and x: "x\<in>X" and y: "y\<in>X" and z:"z\<in>X" and xy: "x\<noteq>y" and xz: "x\<noteq>z" and yz: "y\<noteq>z"
shows "[x;y;z] \<or> [x;z;y] \<or> [y;x;z]"
proof -
have "card X \<ge> 3" using assms(2-5) three_subset[OF xy xz yz] by blast
hence 1: "local_long_ch_by_ord f X"
using assms(1,3-) chain_defs by (metis short_ch_alt(1) short_ch_card(1) short_ch_card_2)
obtain i j k where ijk: "x=f i" "i<card X" "y=f j" "j<card X" "z=f k" "k<card X"
using obtain_index_fin_chain assms(1-5) by metis
have 2: "[f i;f j;f k]" if "i<j \<and> j<k" "k<card X" for i j k
using assms order_finite_chain2 that(1,2) by auto
consider "i<j \<and> j<k"|"i<k \<and> k<j"|"j<i \<and> i<k"|"i>j \<and> j>k"|"i>k \<and> k>j"|"j>i \<and> i>k"
using xy xz yz ijk(1,3,5) by (metis linorder_neqE_nat)
thus ?thesis
apply cases using 2 abc_sym ijk by presburger+
qed
lemma (in MinkowskiPrimitive) card2_either_elt1_or_elt2:
assumes "card X = 2" and "x\<in>X" and "y\<in>X" and "x\<noteq>y"
and "z\<in>X" and "z\<noteq>x"
shows "z=y"
by (metis assms card_2_iff')
(* potential misnomer: Schutz defines bounds only for infinite chains. *)
lemma get_fin_long_ch_bounds:
assumes "local_long_ch_by_ord f X"
and "finite X"
shows "\<exists>x\<in>X. \<exists>y\<in>X. \<exists>z\<in>X. [f\<leadsto>X|x..y..z]"
proof (rule bexI)+
show 1:"[f\<leadsto>X|f 0..f 1..f (card X - 1)]"
using assms unfolding finite_long_chain_with_def using index_injective
by (auto simp: finite_chain_with_alt local_long_ch_by_ord_def local_ordering_def)
show "f (card X - 1) \<in> X"
using 1 points_in_long_chain(3) by auto
show "f 0 \<in> X" "f 1 \<in> X"
using "1" points_in_long_chain by auto
qed
lemma get_fin_long_ch_bounds2:
assumes "local_long_ch_by_ord f X"
and "finite X"
obtains x y z n\<^sub>x n\<^sub>y n\<^sub>z
where "x\<in>X" "y\<in>X" "z\<in>X" "[f\<leadsto>X|x..y..z]" "f n\<^sub>x = x" "f n\<^sub>y = y" "f n\<^sub>z = z"
using get_fin_long_ch_bounds assms
by (meson finite_chain_with_def finite_long_chain_with_alt index_middle_element)
lemma long_ch_card_ge3:
assumes "ch_by_ord f X" "finite X"
shows "local_long_ch_by_ord f X \<longleftrightarrow> card X \<ge> 3"
using assms ch_by_ord_def local_long_ch_by_ord_def short_ch_card(1) by auto
lemma fin_ch_betw2:
assumes "[f\<leadsto>X|a..c]" and "b\<in>X"
obtains "b=a"|"b=c"|"[a;b;c]"
by (metis assms finite_long_chain_with_alt finite_long_chain_with_def)
lemma chain_bounds_unique:
assumes "[f\<leadsto>X|a..c]" "[g\<leadsto>X|x..z]"
shows "(a=x \<and> c=z) \<or> (a=z \<and> c=x)"
using assms points_in_chain abc_abc_neq abc_bcd_acd abc_sym
by (metis (full_types) fin_ch_betw2 )
end (* context MinkowskiBetweenness *)
subsection "Results for segments, rays and (sub)chains"
context MinkowskiBetweenness begin
lemma inside_not_bound:
assumes "[f\<leadsto>X|a..c]"
and "j<card X"
shows "j>0 \<Longrightarrow> f j \<noteq> a" "j<card X - 1 \<Longrightarrow> f j \<noteq> c"
using index_injective2 assms finite_chain_def finite_chain_with_def apply metis
using index_injective2 assms finite_chain_def finite_chain_with_def by auto
text \<open>Converse to Theorem 2(i).\<close>
lemma (in MinkowskiBetweenness) order_finite_chain_indices:
assumes chX: "local_long_ch_by_ord f X" "finite X"
and abc: "[a;b;c]"
and ijk: "f i = a" "f j = b" "f k = c" "i<card X" "j<card X" "k<card X"
shows "i<j \<and> j<k \<or> k<j \<and> j<i"
by (metis abc_abc_neq abc_only_cba(1,2,3) assms bot_nat_0.extremum linorder_neqE_nat order_finite_chain)
lemma order_finite_chain_indices2:
assumes "[f\<leadsto>X|a..c]"
and "f j = b" "j<card X"
obtains "0<j \<and> j<(card X - 1)"|"j=(card X - 1) \<and> b=c"|"j=0 \<and> b=a"
proof -
have finX: "finite X"
using assms(3) card.infinite gr_implies_not0 by blast
have "b\<in>X"
using assms unfolding chain_defs local_ordering_def
by (metis One_nat_def card_2_iff insertI1 insert_commute less_2_cases)
have a: "f 0 = a" and c: "f (card X - 1) = c"
using assms(1) finite_chain_with_def by auto
have "0<j \<and> j<(card X - 1) \<or> j=(card X - 1) \<and> b=c \<or> j=0 \<and> b=a"
proof (cases "short_ch_by_ord f X")
case True
hence "X={a,c}"
using a assms(1) first_neq_last points_in_chain short_ch_by_ord_def by fastforce
then consider "b=a"|"b=c"
using \<open>b\<in>X\<close> by fastforce
thus ?thesis
apply cases using assms(2,3) a c le_less by fastforce+
next
case False
hence chX: "local_long_ch_by_ord f X"
using assms(1) unfolding finite_chain_with_alt using chain_defs by meson
consider "[a;b;c]"|"b=a"|"b=c"
using \<open>b\<in>X\<close> assms(1) fin_ch_betw2 by blast
thus ?thesis apply cases
using \<open>f 0 = a\<close> chX finX assms(2,3) a c order_finite_chain_indices apply fastforce
using \<open>f 0 = a\<close> chX finX assms(2,3) index_injective apply blast
using a c assms chX finX index_injective linorder_neqE_nat inside_not_bound(2) by metis
qed
thus ?thesis using that by blast
qed
lemma index_bij_betw_subset:
assumes chX: "[f\<leadsto>X|a..b..c]" "f i = b" "card X > i"
shows "bij_betw f {0<..<i} {e\<in>X. [a;e;b]}"
proof (unfold bij_betw_def, intro conjI)
have chX2: "local_long_ch_by_ord f X" "finite X"
using assms unfolding chain_defs apply (metis chX(1)
abc_ac_neq fin_ch_betw points_in_long_chain(1,3) short_ch_alt(1) short_ch_path)
using assms unfolding chain_defs by simp
from index_bij_betw[OF this] have 1: "bij_betw f {0..<card X} X" .
have "{0<..<i} \<subset> {0..<card X}"
using assms(1,3) unfolding chain_defs by fastforce
show "inj_on f {0<..<i}"
using 1 assms(3) unfolding bij_betw_def
by (smt (z3) atLeastLessThan_empty_iff2 atLeastLessThan_iff empty_iff greaterThanLessThan_iff
inj_on_def less_or_eq_imp_le)
show "f ` {0<..<i} = {e \<in> X. [a;e;b]}"
proof
show "f ` {0<..<i} \<subseteq> {e \<in> X. [a;e;b]}"
proof (auto simp add: image_subset_iff conjI)
fix j assume asm: "j>0" "j<i"
hence "j < card X" using chX(3) less_trans by blast
thus "f j \<in> X" "[a;f j;b]"
using chX(1) asm(1) unfolding chain_defs local_ordering_def
apply (metis chX2(1) chX(1) fin_chain_card_geq_2 short_ch_card_2 short_xor_long(2)
le_antisym set_le_two finite_chain_def finite_chain_with_def finite_long_chain_with_alt)
using chX asm chX2(1) order_finite_chain unfolding chain_defs local_ordering_def by force
qed
show "{e \<in> X. [a;e;b]} \<subseteq> f ` {0<..<i}"
proof (auto)
fix e assume e: "e \<in> X" "[a;e;b]"
obtain j where "f j = e" "j<card X"
using e chX2 unfolding chain_defs local_ordering_def by blast
show "e \<in> f ` {0<..<i}"
proof
have "0<j\<and>j<i \<or> i<j\<and>j<0"
using order_finite_chain_indices chX chain_defs
by (smt (z3) \<open>f j = e\<close> \<open>j < card X\<close> chX2(1) e(2) gr_implies_not_zero linorder_neqE_nat)
hence "j<i" by simp
thus "j\<in>{0<..<i}" "e = f j"
using \<open>0 < j \<and> j < i \<or> i < j \<and> j < 0\<close> greaterThanLessThan_iff
by (blast,(simp add: \<open>f j = e\<close>))
qed
qed
qed
qed
lemma bij_betw_extend:
assumes "bij_betw f A B"
and "f a = b" "a\<notin>A" "b\<notin>B"
shows "bij_betw f (insert a A) (insert b B)"
by (smt (verit, ccfv_SIG) assms(1) assms(2) assms(4) bij_betwI' bij_betw_iff_bijections insert_iff)
lemma insert_iff2:
assumes "a\<in>X" shows "insert a {x\<in>X. P x} = {x\<in>X. P x \<or> x=a}"
using insert_iff assms by blast
lemma index_bij_betw_subset2:
assumes chX: "[f\<leadsto>X|a..b..c]" "f i = b" "card X > i"
shows "bij_betw f {0..i} {e\<in>X. [a;e;b]\<or>a=e\<or>b=e}"
proof -
have "bij_betw f {0<..<i} {e\<in>X. [a;e;b]}" using index_bij_betw_subset[OF assms] .
moreover have "0\<notin>{0<..<i}" "i\<notin>{0<..<i}" by simp+
moreover have "a\<notin>{e\<in>X. [a;e;b]}" "b\<notin>{e\<in>X. [a;e;b]}" using abc_abc_neq by auto+
moreover have "f 0 = a" "f i = b" using assms unfolding chain_defs by simp+
moreover have "(insert b (insert a {e\<in>X. [a;e;b]})) = {e\<in>X. [a;e;b]\<or>a=e\<or>b=e}"
proof -
have 1: "(insert a {e\<in>X. [a;e;b]}) = {e\<in>X. [a;e;b]\<or>a=e}"
using insert_iff2[OF points_in_long_chain(1)[OF chX(1)]] by auto
have "b\<notin>{e\<in>X. [a;e;b]\<or>a=e}"
using abc_abc_neq chX(1) fin_ch_betw by fastforce
thus "(insert b (insert a {e\<in>X. [a;e;b]})) = {e\<in>X. [a;e;b]\<or>a=e\<or>b=e}"
using 1 insert_iff2 points_in_long_chain(2)[OF chX(1)] by auto
qed
moreover have "(insert i (insert 0 {0<..<i})) = {0..i}" using image_Suc_lessThan by auto
ultimately show ?thesis using bij_betw_extend[of f]
by (metis (no_types, lifting) chX(1) finite_long_chain_with_def insert_iff)
qed
lemma chain_shortening:
assumes "[f\<leadsto>X|a..b..c]"
shows "[f \<leadsto> {e\<in>X. [a;e;b] \<or> e=a \<or> e=b} |a..b]"
proof (unfold finite_chain_with_def finite_chain_def, (intro conjI))
text \<open>Different forms of assumptions for compatibility with needed antecedents later.\<close>
show "f 0 = a" using assms unfolding chain_defs by simp
have chX: "local_long_ch_by_ord f X"
using assms first_neq_last points_in_long_chain(1,3) short_ch_card(1) chain_defs
by (metis card2_either_elt1_or_elt2)
have finX: "finite X"
by (meson assms chain_defs)
text \<open>General facts about the shortened set, which we will call Y.\<close>
let ?Y = "{e\<in>X. [a;e;b] \<or> e=a \<or> e=b}"
show finY: "finite ?Y"
using assms finite_chain_def finite_chain_with_def finite_long_chain_with_alt by auto
have "a\<noteq>b" "a\<in>?Y" "b\<in>?Y" "c\<notin>?Y"
using assms finite_long_chain_with_def apply simp
using assms points_in_long_chain(1,2) apply auto[1]
using assms points_in_long_chain(2) apply auto[1]
using abc_ac_neq abc_only_cba(2) assms fin_ch_betw by fastforce
from this(1-3) finY have cardY: "card ?Y \<ge> 2"
by (metis (no_types, lifting) card_le_Suc0_iff_eq not_less_eq_eq numeral_2_eq_2)
text \<open>Obtain index for \<open>b\<close> (\<open>a\<close> is at index \<open>0\<close>): this index \<open>i\<close> is \<open>card ?Y - 1\<close>.\<close>
obtain i where i: "i<card X" "f i=b"
using assms unfolding chain_defs local_ordering_def using Suc_leI diff_le_self by force
hence "i<card X - 1"
using assms unfolding chain_defs
by (metis Suc_lessI diff_Suc_Suc diff_Suc_eq_diff_pred minus_nat.diff_0 zero_less_diff)
have card01: "i+1 = card {0..i}" by simp
have bb: "bij_betw f {0..i} ?Y" using index_bij_betw_subset2[OF assms i(2,1)] Collect_cong by smt
hence i_eq: "i = card ?Y - 1" using bij_betw_same_card by force
thus "f (card ?Y - 1) = b" using i(2) by simp
text \<open>The path \<open>P\<close> on which \<open>X\<close> lies. If \<open>?Y\<close> has two arguments, \<open>P\<close> makes it a short chain.\<close>
obtain P where P_def: "P\<in>\<P>" "X\<subseteq>P" "\<And>Q. Q\<in>\<P> \<and> X\<subseteq>Q \<Longrightarrow> Q=P"
using fin_chain_on_path[of f X] assms unfolding chain_defs by force
have "a\<in>P" "b\<in>P" using P_def by (meson assms in_mono points_in_long_chain)+
consider (eq_1)"i=1"|(gt_1)"i>1" using \<open>a \<noteq> b\<close> \<open>f 0 = a\<close> i(2) less_linear by blast
thus "[f\<leadsto>?Y]"
proof (cases)
case eq_1
hence "{0..i}={0,1}" by auto
hence "bij_betw f {0,1} ?Y" using bb by auto
from bij_betw_imp_surj_on[OF this] show ?thesis
unfolding chain_defs using P_def eq_1 \<open>a \<noteq> b\<close> \<open>f 0 = a\<close> i(2) by blast
next
case gt_1
have 1: "3\<le>card ?Y" using gt_1 cardY i_eq by linarith
{
fix n assume "n < card ?Y"
hence "n<card X"
using \<open>i<card X - 1\<close> add_diff_inverse_nat i_eq nat_diff_split_asm by linarith
have "f n \<in> ?Y"
proof (simp, intro conjI)
show "f n \<in> X"
using \<open>n<card X\<close> assms chX chain_defs local_ordering_def by metis
consider "0<n \<and> n<card ?Y - 1"|"n=card ?Y - 1"|"n=0"
using \<open>n<card ?Y\<close> nat_less_le zero_less_diff by linarith
thus "[a;f n;b] \<or> f n = a \<or> f n = b"
using i i_eq \<open>f 0 = a\<close> chX finX le_numeral_extra(3) order_finite_chain by fastforce
qed
} moreover {
fix x assume "x\<in>?Y" hence "x\<in>X" by simp
obtain i\<^sub>x where i\<^sub>x: "i\<^sub>x < card X" "f i\<^sub>x = x"
using assms obtain_index_fin_chain chain_defs \<open>x\<in>X\<close> by metis
have "i\<^sub>x < card ?Y"
proof -
consider "[a;x;b]"|"x=a"|"x=b" using \<open>x\<in>?Y\<close> by auto
hence "(i\<^sub>x<i \<or> i\<^sub>x<0) \<or> i\<^sub>x=0 \<or> i\<^sub>x=i"
apply cases
apply (metis \<open>f 0=a\<close> chX finX i i\<^sub>x less_nat_zero_code neq0_conv order_finite_chain_indices)
using \<open>f 0 = a\<close> chX finX i\<^sub>x index_injective apply blast
by (metis chX finX i(2) i\<^sub>x index_injective linorder_neqE_nat)
thus ?thesis using gt_1 i_eq by linarith
qed
hence "\<exists>n. n < card ?Y \<and> f n = x" using i\<^sub>x(2) by blast
} moreover {
fix n assume "Suc (Suc n) < card ?Y"
hence "Suc (Suc n) < card X"
using i(1) i_eq by linarith
hence "[f n; f (Suc n); f (Suc (Suc n))]"
using assms unfolding chain_defs local_ordering_def by auto
}
ultimately have 2: "local_ordering f betw ?Y"
by (simp add: local_ordering_def finY)
show ?thesis using 1 2 chain_defs by blast
qed
qed
corollary ord_fin_ch_right:
assumes "[f\<leadsto>X|a..f i..c]" "j\<ge>i" "j<card X"
shows "[f i;f j;c] \<or> j = card X - 1 \<or> j = i"
proof -
consider (inter)"j>i \<and> j<card X - 1"|(left)"j=i"|(right)"j=card X - 1"
using assms(3,2) by linarith
thus ?thesis
apply cases
using assms(1) chain_defs order_finite_chain2 apply force
by simp+
qed
lemma f_img_is_subset:
assumes "[f\<leadsto>X|(f 0) ..]" "i\<ge>0" "j>i" "Y=f`{i..j}"
shows "Y\<subseteq>X"
proof
fix x assume "x\<in>Y"
then obtain n where "n\<in>{i..j}" "f n = x"
using assms(4) by blast
hence "f n \<in> X"
by (metis local_ordering_def assms(1) inf_chain_is_long local_long_ch_by_ord_def)
thus "x\<in>X"
using \<open>f n = x\<close> by blast
qed
lemma i_le_j_events_neq:
assumes "[f\<leadsto>X|a..b..c]"
and "i<j" "j<card X"
shows "f i \<noteq> f j"
using chain_defs by (meson assms index_injective2)
lemma indices_neq_imp_events_neq:
assumes "[f\<leadsto>X|a..b..c]"
and "i\<noteq>j" "j<card X" "i<card X"
shows "f i \<noteq> f j"
by (metis assms i_le_j_events_neq less_linear)
end (* context MinkowskiChain *)
context MinkowskiSpacetime begin
lemma bound_on_path:
assumes "Q\<in>\<P>" "[f\<leadsto>X|(f 0)..]" "X\<subseteq>Q" "is_bound_f b X f"
shows "b\<in>Q"
proof -
obtain a c where "a\<in>X" "c\<in>X" "[a;c;b]"
using assms(4)
by (metis local_ordering_def inf_chain_is_long is_bound_f_def local_long_ch_by_ord_def zero_less_one)
thus ?thesis
using abc_abc_neq assms(1) assms(3) betw_c_in_path by blast
qed
lemma pro_basis_change:
assumes "[a;b;c]"
shows "prolongation a c = prolongation b c" (is "?ac=?bc")
proof
show "?ac \<subseteq> ?bc"
proof
fix x assume "x\<in>?ac"
hence "[a;c;x]"
by (simp add: pro_betw)
hence "[b;c;x]"
using assms abc_acd_bcd by blast
thus "x\<in>?bc"
using abc_abc_neq pro_betw by blast
qed
show "?bc \<subseteq> ?ac"
proof
fix x assume "x\<in>?bc"
hence "[b;c;x]"
by (simp add: pro_betw)
hence "[a;c;x]"
using assms abc_bcd_acd by blast
thus "x\<in>?ac"
using abc_abc_neq pro_betw by blast
qed
qed
lemma adjoining_segs_exclusive:
assumes "[a;b;c]"
shows "segment a b \<inter> segment b c = {}"
proof (cases)
assume "segment a b = {}" thus ?thesis by blast
next
assume "segment a b \<noteq> {}"
have "x\<in>segment a b \<longrightarrow> x\<notin>segment b c" for x
proof
fix x assume "x\<in>segment a b"
hence "[a;x;b]" by (simp add: seg_betw)
have "\<not>[a;b;x]" by (meson \<open>[a;x;b]\<close> abc_only_cba)
have "\<not>[b;x;c]"
using \<open>\<not> [a;b;x]\<close> abd_bcd_abc assms by blast
thus "x\<notin>segment b c"
by (simp add: seg_betw)
qed
thus ?thesis by blast
qed
end (* context MinkowskiSpacetime *)
section "3.6 Order on a path - Theorems 10 and 11"
context MinkowskiSpacetime begin
subsection \<open>Theorem 10 (based on Veblen (1904) theorem 10).\<close>
lemma (in MinkowskiBetweenness) two_event_chain:
assumes finiteX: "finite X"
and path_Q: "Q \<in> \<P>"
and events_X: "X \<subseteq> Q"
and card_X: "card X = 2"
shows "ch X"
proof -
obtain a b where X_is: "X={a,b}"
using card_le_Suc_iff numeral_2_eq_2
by (meson card_2_iff card_X)
have no_c: "\<not>(\<exists>c\<in>{a,b}. c\<noteq>a \<and> c\<noteq>b)"
by blast
have "a\<noteq>b \<and> a\<in>Q & b\<in>Q"
using X_is card_X events_X by force
hence "short_ch {a,b}"
using path_Q no_c by (meson short_ch_intros(2))
thus ?thesis
by (simp add: X_is chain_defs)
qed
lemma (in MinkowskiBetweenness) three_event_chain:
assumes finiteX: "finite X"
and path_Q: "Q \<in> \<P>"
and events_X: "X \<subseteq> Q"
and card_X: "card X = 3"
shows "ch X"
proof -
obtain a b c where X_is: "X={a,b,c}"
using numeral_3_eq_3 card_X by (metis card_Suc_eq)
then have all_neq: "a\<noteq>b \<and> a\<noteq>c \<and> b\<noteq>c"
using card_X numeral_2_eq_2 numeral_3_eq_3
by (metis Suc_n_not_le_n insert_absorb2 insert_commute set_le_two)
have in_path: "a\<in>Q \<and> b\<in>Q \<and> c\<in>Q"
using X_is events_X by blast
hence "[a;b;c] \<or> [b;c;a] \<or> [c;a;b]"
using some_betw all_neq path_Q by auto
thus "ch X"
using between_chain X_is all_neq chain3 in_path path_Q by auto
qed
text \<open>This is case (i) of the induction in Theorem 10.\<close>
lemma (*for 10*) chain_append_at_left_edge:
assumes long_ch_Y: "[f\<leadsto>Y|a\<^sub>1..a..a\<^sub>n]"
and bY: "[b; a\<^sub>1; a\<^sub>n]"
fixes g defines g_def: "g \<equiv> (\<lambda>j::nat. if j\<ge>1 then f (j-1) else b)"
shows "[g\<leadsto>(insert b Y)|b .. a\<^sub>1 .. a\<^sub>n]"
proof -
let ?X = "insert b Y"
have ord_fY: "local_ordering f betw Y" using long_ch_Y finite_long_chain_with_card chain_defs
by (meson long_ch_card_ge3)
have "b\<notin>Y"
using abc_ac_neq abc_only_cba(1) assms by (metis fin_ch_betw2 finite_long_chain_with_alt)
have bound_indices: "f 0 = a\<^sub>1 \<and> f (card Y - 1) = a\<^sub>n"
using long_ch_Y by (simp add: chain_defs)
have fin_Y: "card Y \<ge> 3"
using finite_long_chain_with_def long_ch_Y numeral_2_eq_2 points_in_long_chain
by (metis abc_abc_neq bY card2_either_elt1_or_elt2 fin_chain_card_geq_2 leI le_less_Suc_eq numeral_3_eq_3)
hence num_ord: "0 \<le> (0::nat) \<and> 0<(1::nat) \<and> 1 < card Y - 1 \<and> card Y - 1 < card Y"
by linarith
hence "[a\<^sub>1; f 1; a\<^sub>n]"
using order_finite_chain chain_defs long_ch_Y
by auto
text \<open>Schutz has a step here that says $[b a_1 a_2 a_n]$ is a chain (using Theorem 9).
We have no easy way (yet) of denoting an ordered 4-element chain, so we skip this step
using a \<^term>\<open>local_ordering\<close> lemma from our script for 3.6, which Schutz doesn't list.\<close>
hence "[b; a\<^sub>1; f 1]"
using bY abd_bcd_abc by blast
have "local_ordering g betw ?X"
proof -
{
fix n assume "finite ?X \<longrightarrow> n<card ?X"
have "g n \<in> ?X"
apply (cases "n\<ge>1")
prefer 2 apply (simp add: g_def)
proof
assume "1\<le>n" "g n \<notin> Y"
hence "g n = f(n-1)" unfolding g_def by auto
hence "g n \<in> Y"
proof (cases "n = card ?X - 1")
case True
thus ?thesis
using \<open>b\<notin>Y\<close> card.insert diff_Suc_1 long_ch_Y points_in_long_chain chain_defs
by (metis \<open>g n = f (n - 1)\<close>)
next
case False
hence "n < card Y"
using points_in_long_chain \<open>finite ?X \<longrightarrow> n < card ?X\<close> \<open>g n = f (n - 1)\<close> \<open>g n \<notin> Y\<close> \<open>b\<notin>Y\<close> chain_defs
by (metis card.insert finite_insert long_ch_Y not_less_simps(1))
hence "n-1 < card Y - 1"
using \<open>1 \<le> n\<close> diff_less_mono by blast
hence "f(n-1)\<in>Y"
using long_ch_Y fin_Y unfolding chain_defs local_ordering_def
by (metis Suc_le_D card_3_dist diff_Suc_1 insert_absorb2 le_antisym less_SucI numeral_3_eq_3 set_le_three)
thus ?thesis
using \<open>g n = f (n - 1)\<close> by presburger
qed
hence False using \<open>g n \<notin> Y\<close> by auto
thus "g n = b" by simp
qed
} moreover {
fix n assume "(finite ?X \<longrightarrow> Suc(Suc n) < card ?X)"
hence "[g n; g (Suc n); g (Suc(Suc n))]"
apply (cases "n\<ge>1")
using \<open>b\<notin>Y\<close> \<open>[b; a\<^sub>1; f 1]\<close> g_def ordering_ord_ijk_loc[OF ord_fY] fin_Y
apply (metis Suc_diff_le card_insert_disjoint diff_Suc_1 finite_insert le_Suc_eq not_less_eq)
by (metis One_nat_def Suc_leI \<open>[b;a\<^sub>1;f 1]\<close> bound_indices diff_Suc_1 g_def
not_less_less_Suc_eq zero_less_Suc)
} moreover {
fix x assume "x\<in>?X" "x=b"
have "(finite ?X \<longrightarrow> 0 < card ?X) \<and> g 0 = x"
by (simp add: \<open>b\<notin>Y\<close> \<open>x = b\<close> g_def)
} moreover {
fix x assume "x\<in>?X" "x\<noteq>b"
hence "\<exists>n. (finite ?X \<longrightarrow> n < card ?X) \<and> g n = x"
proof -
obtain n where "f n = x" "n < card Y"
using \<open>x\<in>?X\<close> \<open>x\<noteq>b\<close> local_ordering_def insert_iff long_ch_Y chain_defs by (metis ord_fY)
have "(finite ?X \<longrightarrow> n+1 < card ?X)" "g(n+1) = x"
apply (simp add: \<open>b\<notin>Y\<close> \<open>n < card Y\<close>)
by (simp add: \<open>f n = x\<close> g_def)
thus ?thesis by auto
qed
}
ultimately show ?thesis
unfolding local_ordering_def
by smt
qed
hence "local_long_ch_by_ord g ?X"
unfolding local_long_ch_by_ord_def
using fin_Y \<open>b\<notin>Y\<close>
by (meson card_insert_le finite_insert le_trans)
show ?thesis
proof (intro finite_long_chain_with_alt2)
show "local_long_ch_by_ord g ?X" using \<open>local_long_ch_by_ord g ?X\<close> by simp
show "[b;a\<^sub>1;a\<^sub>n] \<and> a\<^sub>1 \<in> ?X" using bY long_ch_Y points_in_long_chain(1) by auto
show "g 0 = b" using g_def by simp
show "finite ?X"
using fin_Y \<open>b\<notin>Y\<close> eval_nat_numeral by (metis card.infinite finite.insertI not_numeral_le_zero)
show "g (card ?X - 1) = a\<^sub>n"
using g_def \<open>b\<notin>Y\<close> bound_indices eval_nat_numeral
by (metis One_nat_def card.infinite card_insert_disjoint diff_Suc_Suc
diff_is_0_eq' less_nat_zero_code minus_nat.diff_0 nat_le_linear num_ord)
qed
qed
text \<open>
This is case (iii) of the induction in Theorem 10.
Schutz says merely ``The proof for this case is similar to that for Case (i).''
Thus I feel free to use a result on symmetry, rather than going through
the pain of Case (i) (\<open>chain_append_at_left_edge\<close>) again.
\<close>
lemma (*for 10*) chain_append_at_right_edge:
assumes long_ch_Y: "[f\<leadsto>Y|a\<^sub>1..a..a\<^sub>n]"
and Yb: "[a\<^sub>1; a\<^sub>n; b]"
fixes g defines g_def: "g \<equiv> (\<lambda>j::nat. if j \<le> (card Y - 1) then f j else b)"
shows "[g\<leadsto>(insert b Y)|a\<^sub>1 .. a\<^sub>n .. b]"
proof -
let ?X = "insert b Y"
have "b\<notin>Y"
using Yb abc_abc_neq abc_only_cba(2) long_ch_Y
by (metis fin_ch_betw2 finite_long_chain_with_def)
have fin_Y: "card Y \<ge> 3"
using finite_long_chain_with_card long_ch_Y by auto
hence fin_X: "finite ?X"
by (metis card.infinite finite.insertI not_numeral_le_zero)
have "a\<^sub>1\<in>Y \<and> a\<^sub>n\<in>Y \<and> a\<in>Y"
using long_ch_Y points_in_long_chain by meson
have "a\<^sub>1\<noteq>a \<and> a\<noteq> a\<^sub>n \<and> a\<^sub>1\<noteq>a\<^sub>n"
using Yb abc_abc_neq finite_long_chain_with_def long_ch_Y by auto
have "Suc (card Y) = card ?X"
using \<open>b\<notin>Y\<close> fin_X finite_long_chain_with_def long_ch_Y by auto
obtain f2 where f2_def: "[f2\<leadsto>Y|a\<^sub>n..a..a\<^sub>1]" "f2=(\<lambda>n. f (card Y - 1 - n))"
using chain_sym long_ch_Y by blast
obtain g2 where g2_def: "g2 = (\<lambda>j::nat. if j\<ge>1 then f2 (j-1) else b)"
by simp
have "[b; a\<^sub>n; a\<^sub>1]"
using abc_sym Yb by blast
hence g2_ord_X: "[g2\<leadsto>?X|b .. a\<^sub>n .. a\<^sub>1]"
using chain_append_at_left_edge [where a\<^sub>1="a\<^sub>n" and a\<^sub>n="a\<^sub>1" and f="f2"]
fin_X \<open>b\<notin>Y\<close> f2_def g2_def
by blast
then obtain g1 where g1_def: "[g1\<leadsto>?X|a\<^sub>1..a\<^sub>n..b]" "g1=(\<lambda>n. g2 (card ?X - 1 - n))"
using chain_sym by blast
have sYX: "(card Y) = (card ?X) - 1"
using assms(2,3) finite_long_chain_with_def long_ch_Y \<open>Suc (card Y) = card ?X\<close> by linarith
have "g1=g"
unfolding g1_def g2_def f2_def g_def
proof
fix n
show "(
if 1 \<le> card ?X - 1 - n then
f (card Y - 1 - (card ?X - 1 - n - 1))
else b
) = (
if n \<le> card Y - 1 then
f n
else b
)" (is "?lhs=?rhs")
proof (cases)
assume "n \<le> card ?X - 2"
show "?lhs=?rhs"
using \<open>n \<le> card ?X - 2\<close> finite_long_chain_with_def long_ch_Y sYX \<open>Suc (card Y) = card ?X\<close>
by (metis (mono_tags, opaque_lifting) Suc_1 Suc_leD diff_Suc_Suc diff_commute diff_diff_cancel
diff_le_mono2 fin_chain_card_geq_2)
next
assume "\<not> n \<le> card ?X - 2"
thus "?lhs=?rhs"
by (metis \<open>Suc (card Y) = card ?X\<close> Suc_1 diff_Suc_1 diff_Suc_eq_diff_pred diff_diff_cancel
diff_is_0_eq' nat_le_linear not_less_eq_eq)
qed
qed
thus ?thesis
using g1_def(1) by blast
qed
lemma S_is_dense:
assumes long_ch_Y: "[f\<leadsto>Y|a\<^sub>1..a..a\<^sub>n]"
and S_def: "S = {k::nat. [a\<^sub>1; f k; b] \<and> k < card Y}"
and k_def: "S\<noteq>{}" "k = Max S"
and k'_def: "k'>0" "k'<k"
shows "k' \<in> S"
proof -
text \<open>
We will prove this by contradiction. We can obtain the path that \<open>Y\<close> lies on, and show \<open>b\<close> is
on it too. Then since \<open>f`S\<close> must be on this path, there must be an ordering involving \<open>b\<close>, \<open>f k\<close>
and \<open>f k'\<close> that leads to contradiction with the definition of \<open>S\<close> and \<open>k\<notin>S\<close>.
Notice we need no knowledge about \<open>b\<close> except how it relates to \<open>S\<close>.
\<close>
have "[f\<leadsto>Y]" using long_ch_Y chain_defs by meson
have "card Y \<ge> 3" using finite_long_chain_with_card long_ch_Y by blast
hence "finite Y" by (metis card.infinite not_numeral_le_zero)
have "k\<in>S" using k_def Max_in S_def by (metis finite_Collect_conjI finite_Collect_less_nat)
hence "k<card Y" using S_def by auto
have "k'<card Y" using S_def k'_def \<open>k\<in>S\<close> by auto
show "k' \<in> S"
proof (rule ccontr)
assume asm: "\<not>k'\<in>S"
have 1: "[f 0;f k;f k']"
proof -
have "[a\<^sub>1; b; f k']"
using order_finite_chain2 long_ch_Y \<open>k \<in> S\<close> \<open>k' < card Y\<close> chain_defs
by (smt (z3) abc_acd_abd asm le_numeral_extra(3) assms mem_Collect_eq)
have "[a\<^sub>1; f k; b]"
using S_def \<open>k \<in> S\<close> by blast
have "[f k; b; f k']"
using abc_acd_bcd \<open>[a\<^sub>1; b; f k']\<close> \<open>[a\<^sub>1; f k; b]\<close> by blast
thus ?thesis
using \<open>[a\<^sub>1;f k;b]\<close> long_ch_Y unfolding finite_long_chain_with_def finite_chain_with_def
by blast
qed
have 2: "[f 0;f k';f k]"
apply (intro order_finite_chain2[OF \<open>[f\<leadsto>Y]\<close> \<open>finite Y\<close>]) by (simp add: \<open>k < card Y\<close> k'_def)
show False using 1 2 abc_only_cba(2) by blast
qed
qed
lemma (*for 10*) smallest_k_ex:
assumes long_ch_Y: "[f\<leadsto>Y|a\<^sub>1..a..a\<^sub>n]"
and Y_def: "b\<notin>Y"
and Yb: "[a\<^sub>1; b; a\<^sub>n]"
shows "\<exists>k>0. [a\<^sub>1; b; f k] \<and> k < card Y \<and> \<not>(\<exists>k'<k. [a\<^sub>1; b; f k'])"
proof -
(* the usual suspects first, they'll come in useful I'm sure *)
have bound_indices: "f 0 = a\<^sub>1 \<and> f (card Y - 1) = a\<^sub>n"
using chain_defs long_ch_Y by auto
have fin_Y: "finite Y"
using chain_defs long_ch_Y by presburger
have card_Y: "card Y \<ge> 3"
using long_ch_Y points_in_long_chain finite_long_chain_with_card by blast
text \<open>We consider all indices of chain elements between \<open>a\<^sub>1\<close> and \<open>b\<close>, and find the maximal one.\<close>
let ?S = "{k::nat. [a\<^sub>1; f k; b] \<and> k < card Y}"
obtain S where S_def: "S=?S"
by simp
have "S\<subseteq>{0..card Y}"
using S_def by auto
hence "finite S"
using finite_subset by blast
show ?thesis
proof (cases)
assume "S={}"
show ?thesis
proof
show "(0::nat)<1 \<and> [a\<^sub>1; b; f 1] \<and> 1 < card Y \<and> \<not> (\<exists>k'::nat. k' < 1 \<and> [a\<^sub>1; b; f k'])"
proof (intro conjI)
show "(0::nat)<1" by simp
show "1 < card Y"
using Yb abc_ac_neq bound_indices not_le by fastforce
show "\<not> (\<exists>k'::nat. k' < 1 \<and> [a\<^sub>1; b; f k'])"
using abc_abc_neq bound_indices
by blast
show "[a\<^sub>1; b; f 1]"
proof -
have "f 1 \<in> Y"
using long_ch_Y chain_defs local_ordering_def by (metis \<open>1 < card Y\<close> short_ch_ord_in(2))
hence "[a\<^sub>1; f 1; a\<^sub>n]"
using bound_indices long_ch_Y chain_defs local_ordering_def card_Y
by (smt (z3) Nat.lessE One_nat_def Suc_le_lessD Suc_lessD diff_Suc_1 diff_Suc_less
fin_ch_betw2 i_le_j_events_neq less_numeral_extra(1) numeral_3_eq_3)
hence "[a\<^sub>1; b; f 1] \<or> [a\<^sub>1; f 1; b] \<or> [b; a\<^sub>1; f 1]"
using abc_ex_path_unique some_betw abc_sym
by (smt Y_def Yb \<open>f 1 \<in> Y\<close> abc_abc_neq cross_once_notin)
thus "[a\<^sub>1; b; f 1]"
proof -
have "\<forall>n. \<not> ([a\<^sub>1; f n; b] \<and> n < card Y)"
using S_def \<open>S = {}\<close>
by blast
then have "[a\<^sub>1; b; f 1] \<or> \<not> [a\<^sub>n; f 1; b] \<and> \<not> [a\<^sub>1; f 1; b]"
using bound_indices abc_sym abd_bcd_abc Yb
by (metis (no_types) diff_is_0_eq' nat_le_linear nat_less_le)
then show ?thesis
using abc_bcd_abd abc_sym
by (meson \<open>[a\<^sub>1; b; f 1] \<or> [a\<^sub>1; f 1; b] \<or> [b; a\<^sub>1; f 1]\<close> \<open>[a\<^sub>1; f 1; a\<^sub>n]\<close>)
qed
qed
qed
qed
next assume "\<not>S={}"
obtain k where "k = Max S"
by simp
hence "k \<in> S" using Max_in
by (simp add: \<open>S \<noteq> {}\<close> \<open>finite S\<close>)
have "k\<ge>1"
proof (rule ccontr)
assume "\<not> 1 \<le> k"
hence "k=0" by simp
have "[a\<^sub>1; f k; b]"
using \<open>k\<in>S\<close> S_def
by blast
thus False
using bound_indices \<open>k = 0\<close> abc_abc_neq
by blast
qed
show ?thesis
proof
let ?k = "k+1"
show "0<?k \<and> [a\<^sub>1; b; f ?k] \<and> ?k < card Y \<and> \<not> (\<exists>k'::nat. k' < ?k \<and> [a\<^sub>1; b; f k'])"
proof (intro conjI)
show "(0::nat)<?k" by simp
show "?k < card Y"
by (metis (no_types, lifting) S_def Yb \<open>k \<in> S\<close> abc_only_cba(2) add.commute
add_diff_cancel_right' bound_indices less_SucE mem_Collect_eq nat_add_left_cancel_less
plus_1_eq_Suc)
show "[a\<^sub>1; b; f ?k]"
proof -
have "f ?k \<in> Y"
using \<open>k + 1 < card Y\<close> long_ch_Y card_Y unfolding local_ordering_def chain_defs
by (metis One_nat_def Suc_numeral not_less_eq_eq numeral_3_eq_3 numerals(1) semiring_norm(2) set_le_two)
have "[a\<^sub>1; f ?k; a\<^sub>n] \<or> f ?k = a\<^sub>n"
using fin_ch_betw2 inside_not_bound(1) long_ch_Y chain_defs
by (metis \<open>0 < k + 1\<close> \<open>k + 1 < card Y\<close> \<open>f (k + 1) \<in> Y\<close>)
thus "[a\<^sub>1; b; f ?k]"
proof (rule disjE)
assume "[a\<^sub>1; f ?k; a\<^sub>n]"
hence "f ?k \<noteq> a\<^sub>n"
by (simp add: abc_abc_neq)
hence "[a\<^sub>1; b; f ?k] \<or> [a\<^sub>1; f ?k; b] \<or> [b; a\<^sub>1; f ?k]"
using abc_ex_path_unique some_betw abc_sym \<open>[a\<^sub>1; f ?k; a\<^sub>n]\<close>
\<open>f ?k \<in> Y\<close> Yb abc_abc_neq assms(3) cross_once_notin
by (smt Y_def)
moreover have "\<not> [a\<^sub>1; f ?k; b]"
proof
assume "[a\<^sub>1; f ?k; b]"
hence "?k \<in> S"
using S_def \<open>[a\<^sub>1; f ?k; b]\<close> \<open>k + 1 < card Y\<close> by blast
hence "?k \<le> k"
by (simp add: \<open>finite S\<close> \<open>k = Max S\<close>)
thus False
by linarith
qed
moreover have "\<not> [b; a\<^sub>1; f ?k]"
using Yb \<open>[a\<^sub>1; f ?k; a\<^sub>n]\<close> abc_only_cba
by blast
ultimately show "[a\<^sub>1; b; f ?k]"
by blast
next assume "f ?k = a\<^sub>n"
show ?thesis
using Yb \<open>f (k + 1) = a\<^sub>n\<close> by blast
qed
qed
show "\<not>(\<exists>k'::nat. k' < k + 1 \<and> [a\<^sub>1; b; f k'])"
proof
assume "\<exists>k'::nat. k' < k + 1 \<and> [a\<^sub>1; b; f k']"
then obtain k' where k'_def: "k'>0" "k' < k + 1" "[a\<^sub>1; b; f k']"
using abc_ac_neq bound_indices neq0_conv
by blast
hence "k'<k"
using S_def \<open>k \<in> S\<close> abc_only_cba(2) less_SucE by fastforce
hence "k'\<in>S"
using S_is_dense long_ch_Y S_def \<open>\<not>S={}\<close> \<open>k = Max S\<close> \<open>k'>0\<close>
by blast
thus False
using S_def abc_only_cba(2) k'_def(3) by blast
qed
qed
qed
qed
qed
(* TODO: there's definitely a way of doing this using chain_sym and smallest_k_ex. *)
lemma greatest_k_ex:
assumes long_ch_Y: "[f\<leadsto>Y|a\<^sub>1..a..a\<^sub>n]"
and Y_def: "b\<notin>Y"
and Yb: "[a\<^sub>1; b; a\<^sub>n]"
shows "\<exists>k. [f k; b; a\<^sub>n] \<and> k < card Y - 1 \<and> \<not>(\<exists>k'<card Y. k'>k \<and> [f k'; b; a\<^sub>n])"
proof -
have bound_indices: "f 0 = a\<^sub>1 \<and> f (card Y - 1) = a\<^sub>n"
using chain_defs long_ch_Y by simp
have fin_Y: "finite Y"
using chain_defs long_ch_Y by presburger
have card_Y: "card Y \<ge> 3"
using long_ch_Y points_in_long_chain finite_long_chain_with_card by blast
have chY2: "local_long_ch_by_ord f Y"
using long_ch_Y chain_defs by (meson card_Y long_ch_card_ge3)
text \<open>Again we consider all indices of chain elements between \<open>a\<^sub>1\<close> and \<open>b\<close>.\<close>
let ?S = "{k::nat. [a\<^sub>n; f k; b] \<and> k < card Y}"
obtain S where S_def: "S=?S"
by simp
have "S\<subseteq>{0..card Y}"
using S_def by auto
hence "finite S"
using finite_subset by blast
show ?thesis
proof (cases)
assume "S={}"
show ?thesis
proof
let ?n = "card Y - 2"
show "[f ?n; b; a\<^sub>n] \<and> ?n < card Y - 1 \<and> \<not>(\<exists>k'<card Y. k'>?n \<and> [f k'; b; a\<^sub>n])"
proof (intro conjI)
show "?n < card Y - 1"
using Yb abc_ac_neq bound_indices not_le by fastforce
next show "\<not>(\<exists>k'<card Y. k'>?n \<and> [f k'; b; a\<^sub>n])"
using abc_abc_neq bound_indices
by (metis One_nat_def Suc_diff_le Suc_leD Suc_lessI card_Y diff_Suc_1 diff_Suc_Suc
not_less_eq numeral_2_eq_2 numeral_3_eq_3)
next show "[f ?n; b; a\<^sub>n]"
proof -
have "[f 0;f ?n; f (card Y - 1)]"
apply (intro order_finite_chain[of f Y], (simp_all add: chY2 fin_Y))
using card_Y by linarith
hence "[a\<^sub>1; f ?n; a\<^sub>n]"
using long_ch_Y unfolding chain_defs by simp
have "f ?n \<in> Y"
using long_ch_Y eval_nat_numeral unfolding local_ordering_def chain_defs
by (metis card_1_singleton_iff card_Suc_eq card_gt_0_iff diff_Suc_less diff_self_eq_0 insert_iff numeral_2_eq_2)
hence "[a\<^sub>n; b; f ?n] \<or> [a\<^sub>n; f ?n; b] \<or> [b; a\<^sub>n; f ?n]"
using abc_ex_path_unique some_betw abc_sym \<open>[a\<^sub>1; f ?n; a\<^sub>n]\<close>
by (smt Y_def Yb \<open>f ?n \<in> Y\<close> abc_abc_neq cross_once_notin)
thus "[f ?n; b; a\<^sub>n]"
proof -
have "\<forall>n. \<not> ([a\<^sub>n; f n; b] \<and> n < card Y)"
using S_def \<open>S = {}\<close>
by blast
then have "[a\<^sub>n; b; f ?n] \<or> \<not> [a\<^sub>1; f ?n; b] \<and> \<not> [a\<^sub>n; f ?n; b]"
using bound_indices abc_sym abd_bcd_abc Yb
by (metis (no_types, lifting) \<open>f (card Y - 2) \<in> Y\<close> card_gt_0_iff diff_less empty_iff fin_Y zero_less_numeral)
then show ?thesis
using abc_bcd_abd abc_sym
by (meson \<open>[a\<^sub>n; b; f ?n] \<or> [a\<^sub>n; f ?n; b] \<or> [b; a\<^sub>n; f ?n]\<close> \<open>[a\<^sub>1; f ?n; a\<^sub>n]\<close>)
qed
qed
qed
qed
next assume "\<not>S={}"
obtain k where "k = Min S"
by simp
hence "k \<in> S"
by (simp add: \<open>S \<noteq> {}\<close> \<open>finite S\<close>)
show ?thesis
proof
let ?k = "k-1"
show "[f ?k; b; a\<^sub>n] \<and> ?k < card Y - 1 \<and> \<not> (\<exists>k'<card Y. ?k < k' \<and> [f k'; b; a\<^sub>n])"
proof (intro conjI)
show "?k < card Y - 1"
using S_def \<open>k \<in> S\<close> less_imp_diff_less card_Y
by (metis (no_types, lifting) One_nat_def diff_is_0_eq' diff_less_mono lessI less_le_trans
mem_Collect_eq nat_le_linear numeral_3_eq_3 zero_less_diff)
show "[f ?k; b; a\<^sub>n]"
proof -
have "f ?k \<in> Y"
using \<open>k - 1 < card Y - 1\<close> long_ch_Y card_Y eval_nat_numeral unfolding local_ordering_def chain_defs
by (metis Suc_pred' less_Suc_eq less_nat_zero_code not_less_eq not_less_eq_eq set_le_two)
have "[a\<^sub>1; f ?k; a\<^sub>n] \<or> f ?k = a\<^sub>1"
using bound_indices long_ch_Y \<open>k - 1 < card Y - 1\<close> chain_defs
unfolding finite_long_chain_with_alt
by (metis \<open>f (k - 1) \<in> Y\<close> card_Diff1_less card_Diff_singleton_if chY2 index_injective)
thus "[f ?k; b; a\<^sub>n]"
proof (rule disjE)
assume "[a\<^sub>1; f ?k; a\<^sub>n]"
hence "f ?k \<noteq> a\<^sub>1"
using abc_abc_neq by blast
hence "[a\<^sub>n; b; f ?k] \<or> [a\<^sub>n; f ?k; b] \<or> [b; a\<^sub>n; f ?k]"
using abc_ex_path_unique some_betw abc_sym \<open>[a\<^sub>1; f ?k; a\<^sub>n]\<close>
\<open>f ?k \<in> Y\<close> Yb abc_abc_neq assms(3) cross_once_notin
by (smt Y_def)
moreover have "\<not> [a\<^sub>n; f ?k; b]"
proof
assume "[a\<^sub>n; f ?k; b]"
hence "?k \<in> S"
using S_def \<open>[a\<^sub>n; f ?k; b]\<close> \<open>k - 1 < card Y - 1\<close>
by simp
hence "?k \<ge> k"
by (simp add: \<open>finite S\<close> \<open>k = Min S\<close>)
thus False
using \<open>f (k - 1) \<noteq> a\<^sub>1\<close> chain_defs long_ch_Y
by auto
qed
moreover have "\<not> [b; a\<^sub>n; f ?k]"
using Yb \<open>[a\<^sub>1; f ?k; a\<^sub>n]\<close> abc_only_cba(2) abc_bcd_acd
by blast
ultimately show "[f ?k; b; a\<^sub>n]"
using abc_sym by auto
next assume "f ?k = a\<^sub>1"
show ?thesis
using Yb \<open>f (k - 1) = a\<^sub>1\<close> by blast
qed
qed
show "\<not>(\<exists>k'<card Y. k-1 < k' \<and> [f k'; b; a\<^sub>n])"
proof
assume "\<exists>k'<card Y. k-1 < k' \<and> [f k'; b; a\<^sub>n]"
then obtain k' where k'_def: "k'<card Y -1" "k' > k - 1" "[a\<^sub>n; b; f k']"
using abc_ac_neq bound_indices neq0_conv
by (metis Suc_diff_1 abc_sym gr_implies_not0 less_SucE)
hence "k'>k"
using S_def \<open>k \<in> S\<close> abc_only_cba(2) less_SucE
by (metis (no_types, lifting) add_diff_inverse_nat less_one mem_Collect_eq
not_less_eq plus_1_eq_Suc)thm S_is_dense
hence "k'\<in>S"
apply (intro S_is_dense[of f Y a\<^sub>1 a a\<^sub>n _ b "Max S"])
apply (simp add: long_ch_Y)
apply (smt (verit, ccfv_SIG) S_def \<open>k \<in> S\<close> abc_acd_abd abc_only_cba(4)
add_diff_inverse_nat bound_indices chY2 diff_add_zero diff_is_0_eq fin_Y k'_def(1,3)
less_add_one less_diff_conv2 less_nat_zero_code mem_Collect_eq nat_diff_split order_finite_chain)
apply (simp add: \<open>S \<noteq> {}\<close>, simp, simp)
using k'_def S_def
by (smt (verit, ccfv_SIG) \<open>k \<in> S\<close> abc_acd_abd abc_only_cba(4) add_diff_cancel_right'
add_diff_inverse_nat bound_indices chY2 fin_Y le_eq_less_or_eq less_nat_zero_code
mem_Collect_eq nat_diff_split nat_neq_iff order_finite_chain zero_less_diff zero_less_one)
thus False
using S_def abc_only_cba(2) k'_def(3)
by blast
qed
qed
qed
qed
qed
lemma get_closest_chain_events:
assumes long_ch_Y: "[f\<leadsto>Y|a\<^sub>0..a..a\<^sub>n]"
and x_def: "x\<notin>Y" "[a\<^sub>0; x; a\<^sub>n]"
obtains n\<^sub>b n\<^sub>c b c
where "b=f n\<^sub>b" "c=f n\<^sub>c" "[b;x;c]" "b\<in>Y" "c\<in>Y" "n\<^sub>b = n\<^sub>c - 1" "n\<^sub>c<card Y" "n\<^sub>c>0"
"\<not>(\<exists>k < card Y. [f k; x; a\<^sub>n] \<and> k>n\<^sub>b)" "\<not>(\<exists>k<n\<^sub>c. [a\<^sub>0; x; f k])"
proof -
have "\<exists> n\<^sub>b n\<^sub>c b c. b=f n\<^sub>b \<and> c=f n\<^sub>c \<and> [b;x;c] \<and> b\<in>Y \<and> c\<in>Y \<and> n\<^sub>b = n\<^sub>c - 1 \<and> n\<^sub>c<card Y \<and> n\<^sub>c>0
\<and> \<not>(\<exists>k < card Y. [f k; x; a\<^sub>n] \<and> k>n\<^sub>b) \<and> \<not>(\<exists>k < n\<^sub>c. [a\<^sub>0; x; f k])"
proof -
have bound_indices: "f 0 = a\<^sub>0 \<and> f (card Y - 1) = a\<^sub>n"
using chain_defs long_ch_Y by simp
have fin_Y: "finite Y"
using chain_defs long_ch_Y by presburger
have card_Y: "card Y \<ge> 3"
using long_ch_Y points_in_long_chain finite_long_chain_with_card by blast
have chY2: "local_long_ch_by_ord f Y"
using long_ch_Y chain_defs by (meson card_Y long_ch_card_ge3)
obtain P where P_def: "P\<in>\<P>" "Y\<subseteq>P"
using fin_chain_on_path long_ch_Y fin_Y chain_defs by meson
hence "x\<in>P"
using betw_b_in_path x_def(2) long_ch_Y points_in_long_chain
by (metis abc_abc_neq in_mono)
obtain n\<^sub>c where nc_def: "\<not>(\<exists>k. [a\<^sub>0; x; f k] \<and> k<n\<^sub>c)" "[a\<^sub>0; x; f n\<^sub>c]" "n\<^sub>c<card Y" "n\<^sub>c>0"
using smallest_k_ex [where a\<^sub>1=a\<^sub>0 and a=a and a\<^sub>n=a\<^sub>n and b=x and f=f and Y=Y]
long_ch_Y x_def
by blast
then obtain c where c_def: "c=f n\<^sub>c" "c\<in>Y"
using chain_defs local_ordering_def by (metis chY2)
have c_goal: "c=f n\<^sub>c \<and> c\<in>Y \<and> n\<^sub>c<card Y \<and> n\<^sub>c>0 \<and> \<not>(\<exists>k < card Y. [a\<^sub>0; x; f k] \<and> k<n\<^sub>c)"
using c_def nc_def(1,3,4) by blast
obtain n\<^sub>b where nb_def: "\<not>(\<exists>k < card Y. [f k; x; a\<^sub>n] \<and> k>n\<^sub>b)" "[f n\<^sub>b; x; a\<^sub>n]" "n\<^sub>b<card Y-1"
using greatest_k_ex [where a\<^sub>1=a\<^sub>0 and a=a and a\<^sub>n=a\<^sub>n and b=x and f=f and Y=Y]
long_ch_Y x_def
by blast
hence "n\<^sub>b<card Y"
by linarith
then obtain b where b_def: "b=f n\<^sub>b" "b\<in>Y"
using nb_def chY2 local_ordering_def by (metis local_long_ch_by_ord_alt)
have "[b;x;c]"
proof -
have "[b; x; a\<^sub>n]"
using b_def(1) nb_def(2) by blast
have "[a\<^sub>0; x; c]"
using c_def(1) nc_def(2) by blast
moreover have "\<forall>a. [a;x;b] \<or> \<not> [a; a\<^sub>n; x]"
using \<open>[b; x; a\<^sub>n]\<close> abc_bcd_acd
by (metis (full_types) abc_sym)
moreover have "\<forall>a. [a;x;b] \<or> \<not> [a\<^sub>n; a; x]"
using \<open>[b; x; a\<^sub>n]\<close> by (meson abc_acd_bcd abc_sym)
moreover have "a\<^sub>n = c \<longrightarrow> [b;x;c]"
using \<open>[b; x; a\<^sub>n]\<close> by meson
ultimately show ?thesis
using abc_abd_bcdbdc abc_sym x_def(2)
by meson
qed
have "n\<^sub>b<n\<^sub>c"
using \<open>[b;x;c]\<close> \<open>n\<^sub>c<card Y\<close> \<open>n\<^sub>b<card Y\<close> \<open>c = f n\<^sub>c\<close> \<open>b = f n\<^sub>b\<close>
by (smt (z3) abc_abd_bcdbdc abc_ac_neq abc_acd_abd abc_only_cba(4) abc_sym bot_nat_0.extremum
bound_indices chY2 fin_Y nat_neq_iff nc_def(2) nc_def(4) order_finite_chain)
have "n\<^sub>b = n\<^sub>c - 1"
proof (rule ccontr)
assume "n\<^sub>b \<noteq> n\<^sub>c - 1"
have "n\<^sub>b<n\<^sub>c-1"
using \<open>n\<^sub>b \<noteq> n\<^sub>c - 1\<close> \<open>n\<^sub>b<n\<^sub>c\<close> by linarith
hence "[f n\<^sub>b; (f(n\<^sub>c-1)); f n\<^sub>c]"
using \<open>n\<^sub>b \<noteq> n\<^sub>c - 1\<close> long_ch_Y nc_def(3) order_finite_chain chain_defs
by auto
have "\<not>[a\<^sub>0; x; (f(n\<^sub>c-1))]"
using nc_def(1,4) diff_less less_numeral_extra(1)
by blast
have "n\<^sub>c-1\<noteq>0"
using \<open>n\<^sub>b < n\<^sub>c\<close> \<open>n\<^sub>b \<noteq> n\<^sub>c - 1\<close> by linarith
hence "f(n\<^sub>c-1)\<noteq>a\<^sub>0 \<and> a\<^sub>0\<noteq>x"
using bound_indices \<open>n\<^sub>b < n\<^sub>c - 1\<close> abc_abc_neq less_imp_diff_less nb_def(1) nc_def(3) x_def(2)
by blast
have "x\<noteq>f(n\<^sub>c-1)"
using x_def(1) nc_def(3) chY2 unfolding chain_defs local_ordering_def
by (metis One_nat_def Suc_pred less_Suc_eq nc_def(4) not_less_eq)
hence "[a\<^sub>0; f (n\<^sub>c-1); x]"
using long_ch_Y nc_def c_def chain_defs
by (metis \<open>[f n\<^sub>b;f (n\<^sub>c - 1);f n\<^sub>c]\<close> \<open>\<not> [a\<^sub>0;x;f (n\<^sub>c - 1)]\<close> abc_ac_neq abc_acd_abd abc_bcd_acd
abd_acd_abcacb abd_bcd_abc b_def(1) b_def(2) fin_ch_betw2 nb_def(2))
hence "[(f(n\<^sub>c-1)); x; a\<^sub>n]"
using abc_acd_bcd x_def(2) by blast
thus False using nb_def(1)
using \<open>n\<^sub>b < n\<^sub>c - 1\<close> less_imp_diff_less nc_def(3)
by blast
qed
have b_goal: "b=f n\<^sub>b \<and> b\<in>Y \<and> n\<^sub>b=n\<^sub>c-1 \<and> \<not>(\<exists>k < card Y. [f k; x; a\<^sub>n] \<and> k>n\<^sub>b)"
using b_def nb_def(1) nb_def(3) \<open>n\<^sub>b=n\<^sub>c-1\<close> by blast
thus ?thesis
using \<open>[b;x;c]\<close> c_goal
using \<open>n\<^sub>b < card Y\<close> nc_def(1) by auto
qed
thus ?thesis
using that by auto
qed
text \<open>This is case (ii) of the induction in Theorem 10.\<close>
lemma (*for 10*) chain_append_inside:
assumes long_ch_Y: "[f\<leadsto>Y|a\<^sub>1..a..a\<^sub>n]"
and Y_def: "b\<notin>Y"
and Yb: "[a\<^sub>1; b; a\<^sub>n]"
and k_def: "[a\<^sub>1; b; f k]" "k < card Y" "\<not>(\<exists>k'. (0::nat)<k' \<and> k'<k \<and> [a\<^sub>1; b; f k'])"
fixes g
defines g_def: "g \<equiv> (\<lambda>j::nat. if (j\<le>k-1) then f j else (if (j=k) then b else f (j-1)))"
shows "[g\<leadsto>insert b Y|a\<^sub>1 .. b .. a\<^sub>n]"
proof -
let ?X = "insert b Y"
have fin_X: "finite ?X"
by (meson chain_defs finite.insertI long_ch_Y)
have bound_indices: "f 0 = a\<^sub>1 \<and> f (card Y - 1) = a\<^sub>n"
using chain_defs long_ch_Y
by auto
have fin_Y: "finite Y"
using chain_defs long_ch_Y by presburger
have f_def: "local_long_ch_by_ord f Y"
using chain_defs long_ch_Y by (meson finite_long_chain_with_card long_ch_card_ge3)
have \<open>a\<^sub>1 \<noteq> a\<^sub>n \<and> a\<^sub>1 \<noteq> b \<and> b \<noteq> a\<^sub>n\<close>
using Yb abc_abc_neq by blast
have "k \<noteq> 0"
using abc_abc_neq bound_indices k_def
by metis
have b_middle: "[f(k-1); b; f k]"
proof (cases)
assume "k=1" show "[f(k-1); b; f k]"
using \<open>[a\<^sub>1; b; f k]\<close> \<open>k = 1\<close> bound_indices by auto
next assume "k\<noteq>1" show "[f(k-1); b; f k]"
proof -
have a1k: "[a\<^sub>1; f (k-1); f k]" using bound_indices
using \<open>k < card Y\<close> \<open>k \<noteq> 0\<close> \<open>k \<noteq> 1\<close> long_ch_Y fin_Y order_finite_chain
unfolding chain_defs by auto
text \<open>In fact, the comprehension below gives the order of elements too.
Our notation and Theorem 9 are too weak to say that just now.\<close>
have ch_with_b: "ch {a\<^sub>1, (f (k-1)), b, (f k)}" using chain4
using k_def(1) abc_ex_path_unique between_chain cross_once_notin
by (smt \<open>[a\<^sub>1; f (k-1); f k]\<close> abc_abc_neq insert_absorb2)
have "f (k-1) \<noteq> b \<and> (f k) \<noteq> (f (k-1)) \<and> b \<noteq> (f k)"
using abc_abc_neq f_def k_def(2) Y_def
by (metis local_ordering_def \<open>[a\<^sub>1; f (k-1); f k]\<close> less_imp_diff_less local_long_ch_by_ord_def)
hence some_ord_bk: "[f(k-1); b; f k] \<or> [b; f (k-1); f k] \<or> [f (k-1); f k; b]"
using fin_chain_on_path ch_with_b some_betw Y_def chain_defs
by (metis a1k abc_acd_bcd abd_acd_abcacb k_def(1))
thus "[f(k-1); b; f k]"
proof -
have "\<not> [a\<^sub>1; f k; b]"
by (simp add: \<open>[a\<^sub>1; b; f k]\<close> abc_only_cba(2))
thus ?thesis
using some_ord_bk k_def abc_bcd_acd abd_bcd_abc bound_indices
by (metis diff_is_0_eq' diff_less less_imp_diff_less less_irrefl_nat not_less
zero_less_diff zero_less_one \<open>[a\<^sub>1; b; f k]\<close> a1k)
qed
qed
qed
(* not xor but it works anyway *)
let "?case1 \<or> ?case2" = "k-2 \<ge> 0 \<or> k+1 \<le> card Y -1"
have b_right: "[f (k-2); f (k-1); b]" if "k \<ge> 2"
proof -
have "k-1 < (k::nat)"
using \<open>k \<noteq> 0\<close> diff_less zero_less_one by blast
hence "k-2 < k-1"
using \<open>2 \<le> k\<close> by linarith
have "[f (k-2); f (k-1); b]"
using abd_bcd_abc b_middle f_def k_def(2) fin_Y \<open>k-2 < k-1\<close> \<open>k-1 < k\<close> thm2_ind2 chain_defs
by (metis Suc_1 Suc_le_lessD diff_Suc_eq_diff_pred that zero_less_diff)
thus "[f (k-2); f (k-1); b]"
using \<open>[f(k - 1); b; f k]\<close> abd_bcd_abc
by blast
qed
have b_left: "[b; f k; f (k+1)]" if "k+1 \<le> card Y -1"
proof -
have "[f (k-1); f k; f (k+1)]"
using \<open>k \<noteq> 0\<close> f_def fin_Y order_finite_chain that
by auto
thus "[b; f k; f (k+1)]"
using \<open>[f (k - 1); b; f k]\<close> abc_acd_bcd
by blast
qed
have "local_ordering g betw ?X"
proof -
have "\<forall>n. (finite ?X \<longrightarrow> n < card ?X) \<longrightarrow> g n \<in> ?X"
proof (clarify)
fix n assume "finite ?X \<longrightarrow> n < card ?X" "g n \<notin> Y"
consider "n\<le>k-1" | "n\<ge>k+1" | "n=k"
by linarith
thus "g n = b"
proof (cases)
assume "n \<le> k - 1"
thus "g n = b"
using f_def k_def(2) Y_def(1) chain_defs local_ordering_def g_def
by (metis \<open>g n \<notin> Y\<close> \<open>k \<noteq> 0\<close> diff_less le_less less_one less_trans not_le)
next
assume "k + 1 \<le> n"
show "g n = b"
proof -
have "f n \<in> Y \<or> \<not>(n < card Y)" for n
using chain_defs by (metis local_ordering_def f_def)
then show "g n = b"
using \<open>finite ?X \<longrightarrow> n < card ?X\<close> fin_Y g_def Y_def \<open>g n \<notin> Y\<close> \<open>k + 1 \<le> n\<close>
not_less not_less_simps(1) not_one_le_zero
by fastforce
qed
next
assume "n=k"
thus "g n = b"
using Y_def \<open>k \<noteq> 0\<close> g_def
by auto
qed
qed
moreover have "\<forall>x\<in>?X. \<exists>n. (finite ?X \<longrightarrow> n < card ?X) \<and> g n = x"
proof
fix x assume "x\<in>?X"
show "\<exists>n. (finite ?X \<longrightarrow> n < card ?X) \<and> g n = x"
proof (cases)
assume "x\<in>Y"
show ?thesis
proof -
obtain ix where "f ix = x" "ix < card Y"
using \<open>x \<in> Y\<close> f_def fin_Y
unfolding chain_defs local_ordering_def
by auto
have "ix\<le>k-1 \<or> ix\<ge>k"
by linarith
thus ?thesis
proof
assume "ix\<le>k-1"
hence "g ix = x"
using \<open>f ix = x\<close> g_def by auto
moreover have "finite ?X \<longrightarrow> ix < card ?X"
using Y_def \<open>ix < card Y\<close> by auto
ultimately show ?thesis by metis
next assume "ix\<ge>k"
hence "g (ix+1) = x"
using \<open>f ix = x\<close> g_def by auto
moreover have "finite ?X \<longrightarrow> ix+1 < card ?X"
using Y_def \<open>ix < card Y\<close> by auto
ultimately show ?thesis by metis
qed
qed
next assume "x\<notin>Y"
hence "x=b"
using Y_def \<open>x \<in> ?X\<close> by blast
thus ?thesis
using Y_def \<open>k \<noteq> 0\<close> k_def(2) ordered_cancel_comm_monoid_diff_class.le_diff_conv2 g_def
by auto
qed
qed
moreover have "\<forall>n n' n''. (finite ?X \<longrightarrow> n'' < card ?X) \<and> Suc n = n' \<and> Suc n' = n''
\<longrightarrow> [g n; g (Suc n); g (Suc (Suc n))]"
proof (clarify)
fix n n' n'' assume a: "(finite ?X \<longrightarrow> (Suc (Suc n)) < card ?X)"
text \<open>Introduce the two-case splits used later.\<close>
have cases_sn: "Suc n\<le>k-1 \<or> Suc n=k" if "n\<le>k-1"
using \<open>k \<noteq> 0\<close> that by linarith
have cases_ssn: "Suc(Suc n)\<le>k-1 \<or> Suc(Suc n)=k" if "n\<le>k-1" "Suc n\<le>k-1"
using that(2) by linarith
consider "n\<le>k-1" | "n\<ge>k+1" | "n=k"
by linarith
then show "[g n; g (Suc n); g (Suc (Suc n))]"
proof (cases)
assume "n\<le>k-1" show ?thesis
using cases_sn
proof (rule disjE)
assume "Suc n \<le> k - 1"
show ?thesis using cases_ssn
proof (rule disjE)
show "n \<le> k - 1" using \<open>n \<le> k - 1\<close> by blast
show \<open>Suc n \<le> k - 1\<close> using \<open>Suc n \<le> k - 1\<close> by blast
next
assume "Suc (Suc n) \<le> k - 1"
thus ?thesis
using \<open>Suc n \<le> k - 1\<close> \<open>k \<noteq> 0\<close> \<open>n \<le> k - 1\<close> ordering_ord_ijk_loc f_def g_def k_def(2)
by (metis (no_types, lifting) add_diff_inverse_nat less_Suc_eq_le
less_imp_le_nat less_le_trans less_one local_long_ch_by_ord_def plus_1_eq_Suc)
next
assume "Suc (Suc n) = k"
thus ?thesis
using b_right g_def by force
qed
next
assume "Suc n = k"
show ?thesis
using b_middle \<open>Suc n = k\<close> \<open>n \<le> k - 1\<close> g_def
by auto
next show "n \<le> k-1" using \<open>n \<le> k - 1\<close> by blast
qed
next assume "n\<ge>k+1" show ?thesis
proof -
have "g n = f (n-1)"
using \<open>k + 1 \<le> n\<close> less_imp_diff_less g_def
by auto
moreover have "g (Suc n) = f (n)"
using \<open>k + 1 \<le> n\<close> g_def by auto
moreover have "g (Suc (Suc n)) = f (Suc n)"
using \<open>k + 1 \<le> n\<close> g_def by auto
moreover have "n-1<n \<and> n<Suc n"
using \<open>k + 1 \<le> n\<close> by auto
moreover have "finite Y \<longrightarrow> Suc n < card Y"
using Y_def a by auto
ultimately show ?thesis
using f_def unfolding chain_defs local_ordering_def
by (metis \<open>k + 1 \<le> n\<close> add_leD2 le_add_diff_inverse plus_1_eq_Suc)
qed
next assume "n=k"
show ?thesis
using \<open>k \<noteq> 0\<close> \<open>n = k\<close> b_left g_def Y_def(1) a assms(3) fin_Y
by auto
qed
qed
ultimately show "local_ordering g betw ?X"
unfolding local_ordering_def
by presburger
qed
hence "local_long_ch_by_ord g ?X"
using Y_def f_def local_long_ch_by_ord_def local_long_ch_by_ord_def
by auto
thus "[g\<leadsto>?X|a\<^sub>1..b..a\<^sub>n]"
using fin_X \<open>a\<^sub>1 \<noteq> a\<^sub>n \<and> a\<^sub>1 \<noteq> b \<and> b \<noteq> a\<^sub>n\<close> bound_indices k_def(2) Y_def g_def chain_defs
by simp
qed
lemma card4_eq:
assumes "card X = 4"
shows "\<exists>a b c d. a \<noteq> b \<and> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<and> c \<noteq> d \<and> X = {a, b, c, d}"
proof -
obtain a X' where "X = insert a X'" and "a \<notin> X'"
by (metis Suc_eq_numeral assms card_Suc_eq)
then have "card X' = 3"
by (metis add_2_eq_Suc' assms card_eq_0_iff card_insert_if diff_Suc_1 finite_insert numeral_3_eq_3 numeral_Bit0 plus_nat.add_0 zero_neq_numeral)
then obtain b X'' where "X' = insert b X''" and "b \<notin> X''"
by (metis card_Suc_eq numeral_3_eq_3)
then have "card X'' = 2"
by (metis Suc_eq_numeral \<open>card X' = 3\<close> card.infinite card_insert_if finite_insert pred_numeral_simps(3) zero_neq_numeral)
then have "\<exists>c d. c \<noteq> d \<and> X'' = {c, d}"
by (meson card_2_iff)
thus ?thesis
using \<open>X = insert a X'\<close> \<open>X' = insert b X''\<close> \<open>a \<notin> X'\<close> \<open>b \<notin> X''\<close> by blast
qed
theorem (*10*) path_finsubset_chain:
assumes "Q \<in> \<P>"
and "X \<subseteq> Q"
and "card X \<ge> 2"
shows "ch X"
proof -
have "finite X"
using assms(3) not_numeral_le_zero by fastforce
consider "card X = 2" | "card X = 3" | "card X \<ge> 4"
using \<open>card X \<ge> 2\<close> by linarith
thus ?thesis
proof (cases)
assume "card X = 2"
thus ?thesis
using \<open>finite X\<close> assms two_event_chain by blast
next
assume "card X = 3"
thus ?thesis
using \<open>finite X\<close> assms three_event_chain by blast
next
assume "card X \<ge> 4"
thus ?thesis
using assms(1,2) \<open>finite X\<close>
proof (induct "card X - 4" arbitrary: X)
case 0
then have "card X = 4"
by auto
then have "\<exists>a b c d. a \<noteq> b \<and> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<and> c \<noteq> d \<and> X = {a, b, c, d}"
using card4_eq by fastforce
thus ?case
using "0.prems"(3) assms(1) chain4 by auto
next
case IH: (Suc n)
then obtain Y b where X_eq: "X = insert b Y" and "b \<notin> Y"
by (metis Diff_iff card_eq_0_iff finite.cases insertI1 insert_Diff_single not_numeral_le_zero)
have "card Y \<ge> 4" "n = card Y - 4"
using IH.hyps(2) IH.prems(4) X_eq \<open>b \<notin> Y\<close> by auto
then have "ch Y"
using IH(1) [of Y] IH.prems(3,4) X_eq assms(1) by auto
then obtain f where f_ords: "local_long_ch_by_ord f Y"
using \<open>4 \<le> card Y\<close> ch_alt short_ch_card(2) by auto
then obtain a\<^sub>1 a a\<^sub>n where long_ch_Y: "[f\<leadsto>Y|a\<^sub>1..a..a\<^sub>n]"
using \<open>4 \<le> card Y\<close> get_fin_long_ch_bounds by fastforce
hence bound_indices: "f 0 = a\<^sub>1 \<and> f (card Y - 1) = a\<^sub>n"
by (simp add: chain_defs)
have "a\<^sub>1 \<noteq> a\<^sub>n \<and> a\<^sub>1 \<noteq> b \<and> b \<noteq> a\<^sub>n"
using \<open>b \<notin> Y\<close> abc_abc_neq fin_ch_betw long_ch_Y points_in_long_chain by metis
moreover have "a\<^sub>1 \<in> Q \<and> a\<^sub>n \<in> Q \<and> b \<in> Q"
using IH.prems(3) X_eq long_ch_Y points_in_long_chain by auto
ultimately consider "[b; a\<^sub>1; a\<^sub>n]" | "[a\<^sub>1; a\<^sub>n; b]" | "[a\<^sub>n; b; a\<^sub>1]"
using some_betw [of Q b a\<^sub>1 a\<^sub>n] \<open>Q \<in> \<P>\<close> by blast
thus "ch X"
proof (cases)
(* case (i) *)
assume "[b; a\<^sub>1; a\<^sub>n]"
have X_eq': "X = Y \<union> {b}"
using X_eq by auto
let ?g = "\<lambda>j. if j \<ge> 1 then f (j - 1) else b"
have "[?g\<leadsto>X|b..a\<^sub>1..a\<^sub>n]"
using chain_append_at_left_edge IH.prems(4) X_eq' \<open>[b; a\<^sub>1; a\<^sub>n]\<close> \<open>b \<notin> Y\<close> long_ch_Y X_eq
by presburger
thus "ch X"
using chain_defs by auto
next
(* case (ii) *)
assume "[a\<^sub>1; a\<^sub>n; b]"
let ?g = "\<lambda>j. if j \<le> (card X - 2) then f j else b"
have "[?g\<leadsto>X|a\<^sub>1..a\<^sub>n..b]"
using chain_append_at_right_edge IH.prems(4) X_eq \<open>[a\<^sub>1; a\<^sub>n; b]\<close> \<open>b \<notin> Y\<close> long_ch_Y
by auto
thus "ch X" using chain_defs by (meson ch_def)
next
(* case (iii) *)
assume "[a\<^sub>n; b; a\<^sub>1]"
then have "[a\<^sub>1; b; a\<^sub>n]"
by (simp add: abc_sym)
obtain k where
k_def: "[a\<^sub>1; b; f k]" "k < card Y" "\<not> (\<exists>k'. 0 < k' \<and> k' < k \<and> [a\<^sub>1; b; f k'])"
using \<open>[a\<^sub>1; b; a\<^sub>n]\<close> \<open>b \<notin> Y\<close> long_ch_Y smallest_k_ex by blast
obtain g where "g = (\<lambda>j::nat. if j \<le> k - 1
then f j
else if j = k
then b else f (j - 1))"
by simp
hence "[g\<leadsto>X|a\<^sub>1..b..a\<^sub>n]"
using chain_append_inside [of f Y a\<^sub>1 a a\<^sub>n b k] IH.prems(4) X_eq
\<open>[a\<^sub>1; b; a\<^sub>n]\<close> \<open>b \<notin> Y\<close> k_def long_ch_Y
by auto
thus "ch X"
using chain_defs ch_def by auto
qed
qed
qed
qed
lemma path_finsubset_chain2:
assumes "Q \<in> \<P>" and "X \<subseteq> Q" and "card X \<ge> 2"
obtains f a b where "[f\<leadsto>X|a..b]"
proof -
have finX: "finite X"
by (metis assms(3) card.infinite rel_simps(28))
have ch_X: "ch X"
using path_finsubset_chain[OF assms] by blast
obtain f a b where f_def: "[f\<leadsto>X|a..b]" "a\<in>X \<and> b\<in>X"
using assms finX ch_X get_fin_long_ch_bounds chain_defs
by (metis ch_def points_in_chain)
thus ?thesis
using that by auto
qed
subsection \<open>Theorem 11\<close>
text \<open>
Notice this case is so simple, it doesn't even require the path density larger sets of segments
rely on for fixing their cardinality.
\<close>
lemma (*for 11*) segmentation_ex_N2:
assumes path_P: "P\<in>\<P>"
and Q_def: "finite (Q::'a set)" "card Q = N" "Q\<subseteq>P" "N=2"
and f_def: "[f\<leadsto>Q|a..b]"
and S_def: "S = {segment a b}"
and P1_def: "P1 = prolongation b a"
and P2_def: "P2 = prolongation a b"
shows "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q) \<and>
card S = (N-1) \<and> (\<forall>x\<in>S. is_segment x) \<and>
P1\<inter>P2={} \<and> (\<forall>x\<in>S. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>S. x\<noteq>y \<longrightarrow> x\<inter>y={})))"
proof -
have "a\<in>Q \<and> b\<in>Q \<and> a\<noteq>b"
using chain_defs f_def points_in_chain first_neq_last
by (metis)
hence "Q={a,b}"
using assms(3,5)
by (smt card_2_iff insert_absorb insert_commute insert_iff singleton_insert_inj_eq)
have "a\<in>P \<and> b\<in>P"
using \<open>Q={a,b}\<close> assms(4) by auto
have "a\<noteq>b" using \<open>Q={a,b}\<close>
using \<open>N = 2\<close> assms(3) by force
obtain s where s_def: "s = segment a b" by simp
let ?S = "{s}"
have "P = ((\<Union>{s}) \<union> P1 \<union> P2 \<union> Q) \<and>
card {s} = (N-1) \<and> (\<forall>x\<in>{s}. is_segment x) \<and>
P1\<inter>P2={} \<and> (\<forall>x\<in>{s}. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>{s}. x\<noteq>y \<longrightarrow> x\<inter>y={})))"
proof (rule conjI)
{ fix x assume "x\<in>P"
have "[a;x;b] \<or> [b;a;x] \<or> [a;b;x] \<or> x=a \<or> x=b"
using \<open>a\<in>P \<and> b\<in>P\<close> some_betw path_P \<open>a\<noteq>b\<close>
by (meson \<open>x \<in> P\<close> abc_sym)
then have "x\<in>s \<or> x\<in>P1 \<or> x\<in>P2 \<or> x=a \<or> x=b"
using pro_betw seg_betw P1_def P2_def s_def \<open>Q = {a, b}\<close>
by auto
hence "x \<in> (\<Union>{s}) \<union> P1 \<union> P2 \<union> Q"
using \<open>Q = {a, b}\<close> by auto
} moreover {
fix x assume "x \<in> (\<Union>{s}) \<union> P1 \<union> P2 \<union> Q"
hence "x\<in>s \<or> x\<in>P1 \<or> x\<in>P2 \<or> x=a \<or> x=b"
using \<open>Q = {a, b}\<close> by blast
hence "[a;x;b] \<or> [b;a;x] \<or> [a;b;x] \<or> x=a \<or> x=b"
using s_def P1_def P2_def
unfolding segment_def prolongation_def
by auto
hence "x\<in>P"
using \<open>a \<in> P \<and> b \<in> P\<close> \<open>a \<noteq> b\<close> betw_b_in_path betw_c_in_path path_P
by blast
}
ultimately show union_P: "P = ((\<Union>{s}) \<union> P1 \<union> P2 \<union> Q)"
by blast
show "card {s} = (N-1) \<and> (\<forall>x\<in>{s}. is_segment x) \<and> P1\<inter>P2={} \<and>
(\<forall>x\<in>{s}. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>{s}. x\<noteq>y \<longrightarrow> x\<inter>y={})))"
proof (safe)
show "card {s} = N - 1"
using \<open>Q = {a, b}\<close> \<open>a \<noteq> b\<close> assms(3) by auto
show "is_segment s"
using s_def by blast
show "\<And>x. x \<in> P1 \<Longrightarrow> x \<in> P2 \<Longrightarrow> x \<in> {}"
proof -
fix x assume "x\<in>P1" "x\<in>P2"
show "x\<in>{}"
using P1_def P2_def \<open>x \<in> P1\<close> \<open>x \<in> P2\<close> abc_only_cba pro_betw
by metis
qed
show "\<And>x xa. xa \<in> s \<Longrightarrow> xa \<in> P1 \<Longrightarrow> xa \<in> {}"
proof -
fix x xa assume "xa\<in>s" "xa\<in>P1"
show "xa\<in>{}"
using abc_only_cba seg_betw pro_betw P1_def \<open>xa \<in> P1\<close> \<open>xa \<in> s\<close> s_def
by (metis)
qed
show "\<And>x xa. xa \<in> s \<Longrightarrow> xa \<in> P2 \<Longrightarrow> xa \<in> {}"
proof -
fix x xa assume "xa\<in>s" "xa\<in>P2"
show "xa\<in>{}"
using abc_only_cba seg_betw pro_betw
by (metis P2_def \<open>xa \<in> P2\<close> \<open>xa \<in> s\<close> s_def)
qed
qed
qed
thus ?thesis
by (simp add: S_def s_def)
qed
lemma int_split_to_segs:
assumes f_def: "[f\<leadsto>Q|a..b..c]"
fixes S defines S_def: "S \<equiv> {segment (f i) (f(i+1)) | i. i<card Q-1}"
shows "interval a c = (\<Union>S) \<union> Q"
proof
let ?N = "card Q"
have f_def_2: "a\<in>Q \<and> b\<in>Q \<and> c\<in>Q"
using f_def points_in_long_chain by blast
hence "?N \<ge> 3"
using f_def long_ch_card_ge3 chain_defs
by (meson finite_long_chain_with_card)
have bound_indices: "f 0 = a \<and> f (card Q - 1) = c"
using f_def chain_defs by auto
let "?i = ?u" = "interval a c = (\<Union>S) \<union> Q"
show "?i\<subseteq>?u"
proof
fix p assume "p \<in> ?i"
show "p\<in>?u"
proof (cases)
assume "p\<in>Q" thus ?thesis by blast
next assume "p\<notin>Q"
hence "p\<noteq>a \<and> p\<noteq>c"
using f_def f_def_2 by blast
hence "[a;p;c]"
using seg_betw \<open>p \<in> interval a c\<close> interval_def
by auto
then obtain n\<^sub>y n\<^sub>z y z
where yz_def: "y=f n\<^sub>y" "z=f n\<^sub>z" "[y;p;z]" "y\<in>Q" "z\<in>Q" "n\<^sub>y=n\<^sub>z-1" "n\<^sub>z<card Q"
"\<not>(\<exists>k < card Q. [f k; p; c] \<and> k>n\<^sub>y)" "\<not>(\<exists>k<n\<^sub>z. [a; p; f k])"
using get_closest_chain_events [where f=f and x=p and Y=Q and a\<^sub>n=c and a\<^sub>0=a and a=b]
f_def \<open>p\<notin>Q\<close>
by metis
have "n\<^sub>y<card Q-1"
using yz_def(6,7) f_def index_middle_element
by fastforce
let ?s = "segment (f n\<^sub>y) (f n\<^sub>z)"
have "p\<in>?s"
using \<open>[y;p;z]\<close> abc_abc_neq seg_betw yz_def(1,2)
by blast
have "n\<^sub>z = n\<^sub>y + 1"
using yz_def(6)
by (metis abc_abc_neq add.commute add_diff_inverse_nat less_one yz_def(1,2,3) zero_diff)
hence "?s\<in>S"
using S_def \<open>n\<^sub>y<card Q-1\<close> assms(2)
by blast
hence "p\<in>\<Union>S"
using \<open>p \<in> ?s\<close> by blast
thus ?thesis by blast
qed
qed
show "?u\<subseteq>?i"
proof
fix p assume "p \<in> ?u"
hence "p\<in>\<Union>S \<or> p\<in>Q" by blast
thus "p\<in>?i"
proof
assume "p\<in>Q"
then consider "p=a"|"p=c"|"[a;p;c]"
using f_def by (meson fin_ch_betw2 finite_long_chain_with_alt)
thus ?thesis
proof (cases)
assume "p=a"
thus ?thesis by (simp add: interval_def)
next assume "p=c"
thus ?thesis by (simp add: interval_def)
next assume "[a;p;c]"
thus ?thesis using interval_def seg_betw by auto
qed
next assume "p\<in>\<Union>S"
then obtain s where "p\<in>s" "s\<in>S"
by blast
then obtain y where "s = segment (f y) (f (y+1))" "y<?N-1"
using S_def by blast
hence "y+1<?N" by (simp add: assms(2))
hence fy_in_Q: "(f y)\<in>Q \<and> f (y+1) \<in> Q"
using f_def add_lessD1 unfolding chain_defs local_ordering_def
by (metis One_nat_def Suc_eq_plus1 Zero_not_Suc \<open>3\<le>card Q\<close> card_1_singleton_iff card_gt_0_iff
card_insert_if diff_add_inverse2 diff_is_0_eq' less_numeral_extra(1) numeral_3_eq_3 plus_1_eq_Suc)
have "[a; f y; c] \<or> y=0"
using \<open>y <?N - 1\<close> assms(2) f_def chain_defs order_finite_chain by auto
moreover have "[a; f (y+1); c] \<or> y = ?N-2"
using \<open>y+1 < card Q\<close> assms(2) f_def chain_defs order_finite_chain i_le_j_events_neq
using indices_neq_imp_events_neq fin_ch_betw2 fy_in_Q
by (smt (z3) Nat.add_0_right Nat.add_diff_assoc add_gr_0 card_Diff1_less card_Diff_singleton_if
diff_diff_left diff_is_0_eq' le_numeral_extra(4) less_numeral_extra(1) nat_1_add_1)
ultimately consider "y=0"|"y=?N-2"|"([a; f y; c] \<and> [a; f (y+1); c])"
by linarith
hence "[a;p;c]"
proof (cases)
assume "y=0"
hence "f y = a"
by (simp add: bound_indices)
hence "[a; p; (f(y+1))]"
using \<open>p \<in> s\<close> \<open>s = segment (f y) (f (y + 1))\<close> seg_betw
by auto
moreover have "[a; (f(y+1)); c]"
using \<open>[a; (f(y+1)); c] \<or> y = ?N - 2\<close> \<open>y = 0\<close> \<open>?N\<ge>3\<close>
by linarith
ultimately show "[a;p;c]"
using abc_acd_abd by blast
next
assume "y=?N-2"
hence "f (y+1) = c"
using bound_indices \<open>?N\<ge>3\<close> numeral_2_eq_2 numeral_3_eq_3
by (metis One_nat_def Suc_diff_le add.commute add_leD2 diff_Suc_Suc plus_1_eq_Suc)
hence "[f y; p; c]"
using \<open>p \<in> s\<close> \<open>s = segment (f y) (f (y + 1))\<close> seg_betw
by auto
moreover have "[a; f y; c]"
using \<open>[a; f y; c] \<or> y = 0\<close> \<open>y = ?N - 2\<close> \<open>?N\<ge>3\<close>
by linarith
ultimately show "[a;p;c]"
by (meson abc_acd_abd abc_sym)
next
assume "[a; f y; c] \<and> [a; (f(y+1)); c]"
thus "[a;p;c]"
using abe_ade_bcd_ace [where a=a and b="f y" and d="f (y+1)" and e=c and c=p]
using \<open>p \<in> s\<close> \<open>s = segment (f y) (f(y+1))\<close> seg_betw
by auto
qed
thus ?thesis
using interval_def seg_betw by auto
qed
qed
qed
lemma (*for 11*) path_is_union:
assumes path_P: "P\<in>\<P>"
and Q_def: "finite (Q::'a set)" "card Q = N" "Q\<subseteq>P" "N\<ge>3"
and f_def: "a\<in>Q \<and> b\<in>Q \<and> c\<in>Q" "[f\<leadsto>Q|a..b..c]"
and S_def: "S = {s. \<exists>i<(N-1). s = segment (f i) (f (i+1))}"
and P1_def: "P1 = prolongation b a"
and P2_def: "P2 = prolongation b c"
shows "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)"
proof -
(* For future use, as always *)
have in_P: "a\<in>P \<and> b\<in>P \<and> c\<in>P"
using assms(4) f_def by blast
have bound_indices: "f 0 = a \<and> f (card Q - 1) = c"
using f_def chain_defs by auto
have points_neq: "a\<noteq>b \<and> b\<noteq>c \<and> a\<noteq>c"
using f_def chain_defs by (metis first_neq_last)
text \<open>The proof in two parts: subset inclusion one way, then the other.\<close>
{ fix x assume "x\<in>P"
have "[a;x;c] \<or> [b;a;x] \<or> [b;c;x] \<or> x=a \<or> x=c"
using in_P some_betw path_P points_neq \<open>x \<in> P\<close> abc_sym
by (metis (full_types) abc_acd_bcd fin_ch_betw f_def(2))
then have "(\<exists>s\<in>S. x\<in>s) \<or> x\<in>P1 \<or> x\<in>P2 \<or> x\<in>Q"
proof (cases)
assume "[a;x;c]"
hence only_axc: "\<not>([b;a;x] \<or> [b;c;x] \<or> x=a \<or> x=c)"
using abc_only_cba
by (meson abc_bcd_abd abc_sym f_def fin_ch_betw)
have "x \<in> interval a c"
using \<open>[a;x;c]\<close> interval_def seg_betw by auto
hence "x\<in>Q \<or> x\<in>\<Union>S"
using int_split_to_segs S_def assms(2,3,5) f_def
by blast
thus ?thesis by blast
next assume "\<not>[a;x;c]"
hence "[b;a;x] \<or> [b;c;x] \<or> x=a \<or> x=c"
using \<open>[a;x;c] \<or> [b;a;x] \<or> [b;c;x] \<or> x = a \<or> x = c\<close> by blast
hence " x\<in>P1 \<or> x\<in>P2 \<or> x\<in>Q"
using P1_def P2_def f_def pro_betw by auto
thus ?thesis by blast
qed
hence "x \<in> (\<Union>S) \<union> P1 \<union> P2 \<union> Q" by blast
} moreover {
fix x assume "x \<in> (\<Union>S) \<union> P1 \<union> P2 \<union> Q"
hence "(\<exists>s\<in>S. x\<in>s) \<or> x\<in>P1 \<or> x\<in>P2 \<or> x\<in>Q"
by blast
hence "x\<in>\<Union>S \<or> [b;a;x] \<or> [b;c;x] \<or> x\<in>Q"
using S_def P1_def P2_def
unfolding segment_def prolongation_def
by auto
hence "x\<in>P"
proof (cases)
assume "x\<in>\<Union>S"
have "S = {segment (f i) (f(i+1)) | i. i<N-1}"
using S_def by blast
hence "x\<in>interval a c"
using int_split_to_segs [OF f_def(2)] assms \<open>x\<in>\<Union>S\<close>
by (simp add: UnCI)
hence "[a;x;c] \<or> x=a \<or> x=c"
using interval_def seg_betw by auto
thus ?thesis
proof (rule disjE)
assume "x=a \<or> x=c"
thus ?thesis
using in_P by blast
next
assume "[a;x;c]"
thus ?thesis
using betw_b_in_path in_P path_P points_neq by blast
qed
next assume "x\<notin>\<Union>S"
hence "[b;a;x] \<or> [b;c;x] \<or> x\<in>Q"
using \<open>x \<in> \<Union> S \<or> [b;a;x] \<or> [b;c;x] \<or> x \<in> Q\<close>
by blast
thus ?thesis
using assms(4) betw_c_in_path in_P path_P points_neq
by blast
qed
}
ultimately show "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)"
by blast
qed
lemma (*for 11*) inseg_axc:
assumes path_P: "P\<in>\<P>"
and Q_def: "finite (Q::'a set)" "card Q = N" "Q\<subseteq>P" "N\<ge>3"
and f_def: "a\<in>Q \<and> b\<in>Q \<and> c\<in>Q" "[f\<leadsto>Q|a..b..c]"
and S_def: "S = {s. \<exists>i<(N-1). s = segment (f i) (f (i+1))}"
and x_def: "x\<in>s" "s\<in>S"
shows "[a;x;c]"
proof -
have fQ: "local_long_ch_by_ord f Q"
using f_def Q_def chain_defs by (metis ch_long_if_card_geq3 path_P short_ch_card(1) short_xor_long(2))
have inseg_neq_ac: "x\<noteq>a \<and> x\<noteq>c" if "x\<in>s" "s\<in>S" for x s
proof
show "x\<noteq>a"
proof (rule notI)
assume "x=a"
obtain n where s_def: "s = segment (f n) (f (n+1))" "n<N-1"
using S_def \<open>s \<in> S\<close> by blast
hence "n<card Q" using assms(3) by linarith
hence "f n \<in> Q"
using fQ unfolding chain_defs local_ordering_def by blast
hence "[a; f n; c]"
using f_def finite_long_chain_with_def assms(3) order_finite_chain seg_betw that(1)
using \<open>n < N - 1\<close> \<open>s = segment (f n) (f (n + 1))\<close> \<open>x = a\<close>
by (metis abc_abc_neq add_lessD1 fin_ch_betw inside_not_bound(2) less_diff_conv)
moreover have "[(f(n)); x; (f(n+1))]"
using \<open>x\<in>s\<close> seg_betw s_def(1) by simp
ultimately show False
using \<open>x=a\<close> abc_only_cba(1) assms(3) fQ chain_defs s_def(2)
by (smt (z3) \<open>n < card Q\<close> f_def(2) order_finite_chain_indices2 thm2_ind1)
qed
show "x\<noteq>c"
proof (rule notI)
assume "x=c"
obtain n where s_def: "s = segment (f n) (f (n+1))" "n<N-1"
using S_def \<open>s \<in> S\<close> by blast
hence "n+1<N" by simp
have "[(f(n)); x; (f(n+1))]"
using \<open>x\<in>s\<close> seg_betw s_def(1) by simp
have "f (n) \<in> Q"
using fQ \<open>n+1 < N\<close> chain_defs local_ordering_def
by (metis add_lessD1 assms(3))
have "f (n+1) \<in> Q"
using \<open>n+1 < N\<close> fQ chain_defs local_ordering_def
by (metis assms(3))
have "f(n+1) \<noteq> c"
using \<open>x=c\<close> \<open>[(f(n)); x; (f(n+1))]\<close> abc_abc_neq
by blast
hence "[a; (f(n+1)); c]"
using f_def finite_long_chain_with_def assms(3) order_finite_chain seg_betw that(1)
abc_abc_neq abc_only_cba fin_ch_betw
by (metis \<open>[f n; x; f (n + 1)]\<close> \<open>f (n + 1) \<in> Q\<close> \<open>f n \<in> Q\<close> \<open>x = c\<close>)
thus False
using \<open>x=c\<close> \<open>[(f(n)); x; (f(n+1))]\<close> assms(3) f_def s_def(2)
abc_only_cba(1) finite_long_chain_with_def order_finite_chain
by (metis \<open>f n \<in> Q\<close> abc_bcd_acd abc_only_cba(1,2) fin_ch_betw)
qed
qed
show "[a;x;c]"
proof -
have "x\<in>interval a c"
using int_split_to_segs [OF f_def(2)] S_def assms(2,3,5) x_def
by blast
have "x\<noteq>a \<and> x\<noteq>c" using inseg_neq_ac
using x_def by auto
thus ?thesis
using seg_betw \<open>x \<in> interval a c\<close> interval_def
by auto
qed
qed
lemma disjoint_segmentation:
assumes path_P: "P\<in>\<P>"
and Q_def: "finite (Q::'a set)" "card Q = N" "Q\<subseteq>P" "N\<ge>3"
and f_def: "a\<in>Q \<and> b\<in>Q \<and> c\<in>Q" "[f\<leadsto>Q|a..b..c]"
and S_def: "S = {s. \<exists>i<(N-1). s = segment (f i) (f (i+1))}"
and P1_def: "P1 = prolongation b a"
and P2_def: "P2 = prolongation b c"
shows "P1\<inter>P2={} \<and> (\<forall>x\<in>S. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>S. x\<noteq>y \<longrightarrow> x\<inter>y={})))"
proof (rule conjI)
have fQ: "local_long_ch_by_ord f Q"
using f_def Q_def chain_defs by (metis ch_long_if_card_geq3 path_P short_ch_card(1) short_xor_long(2))
show "P1 \<inter> P2 = {}"
proof (safe)
fix x assume "x\<in>P1" "x\<in>P2"
show "x\<in>{}"
using abc_only_cba pro_betw P1_def P2_def
by (metis \<open>x \<in> P1\<close> \<open>x \<in> P2\<close> abc_bcd_abd f_def(2) fin_ch_betw)
qed
show "\<forall>x\<in>S. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>S. x\<noteq>y \<longrightarrow> x\<inter>y={}))"
proof (rule ballI)
fix s assume "s\<in>S"
show "s \<inter> P1 = {} \<and> s \<inter> P2 = {} \<and> (\<forall>y\<in>S. s \<noteq> y \<longrightarrow> s \<inter> y = {})"
proof (intro conjI ballI impI)
show "s\<inter>P1={}"
proof (safe)
fix x assume "x\<in>s" "x\<in>P1"
hence "[a;x;c]"
using inseg_axc \<open>s \<in> S\<close> assms by blast
thus "x\<in>{}"
by (metis P1_def \<open>x \<in> P1\<close> abc_bcd_abd abc_only_cba(1) f_def(2) fin_ch_betw pro_betw)
qed
show "s\<inter>P2={}"
proof (safe)
fix x assume "x\<in>s" "x\<in>P2"
hence "[a;x;c]"
using inseg_axc \<open>s \<in> S\<close> assms by blast
thus "x\<in>{}"
by (metis P2_def \<open>x \<in> P2\<close> abc_bcd_acd abc_only_cba(2) f_def(2) fin_ch_betw pro_betw)
qed
fix r assume "r\<in>S" "s\<noteq>r"
show "s\<inter>r={}"
proof (safe)
fix y assume "y \<in> r" "y \<in> s"
obtain n m where rs_def: "r = segment (f n) (f(n+1))" "s = segment (f m) (f(m+1))"
"n\<noteq>m" "n<N-1" "m<N-1"
using S_def \<open>r \<in> S\<close> \<open>s \<noteq> r\<close> \<open>s \<in> S\<close> by blast
have y_betw: "[f n; y; (f(n+1))] \<and> [f m; y; (f(m+1))]"
using seg_betw \<open>y\<in>r\<close> \<open>y\<in>s\<close> rs_def(1,2) by simp
have False
proof (cases)
assume "n<m"
have "[f n; f m; (f(m+1))]"
using \<open>n < m\<close> assms(3) fQ chain_defs order_finite_chain rs_def(5) by (metis assms(2) thm2_ind1)
have "n+1<m"
using \<open>[f n; f m; f(m + 1)]\<close> \<open>n < m\<close> abc_only_cba(2) abd_bcd_abc y_betw
by (metis Suc_eq_plus1 Suc_leI le_eq_less_or_eq)
hence "[f n; (f(n+1)); f m]"
using fQ assms(3) rs_def(5) unfolding chain_defs local_ordering_def
by (metis (full_types) \<open>[f n;f m;f (m + 1)]\<close> abc_only_cba(1) abc_sym abd_bcd_abc assms(2) fQ thm2_ind1 y_betw)
hence "[f n; (f(n+1)); y]"
using \<open>[f n; f m; f(m + 1)]\<close> abc_acd_abd abd_bcd_abc y_betw
by blast
thus ?thesis
using abc_only_cba y_betw by blast
next
assume "\<not>n<m"
hence "n>m" using nat_neq_iff rs_def(3) by blast
have "[f m; f n; (f(n+1))]"
using \<open>n > m\<close> assms(3) fQ chain_defs rs_def(4) by (metis assms(2) thm2_ind1)
hence "m+1<n"
using \<open>n > m\<close> abc_only_cba(2) abd_bcd_abc y_betw
by (metis Suc_eq_plus1 Suc_leI le_eq_less_or_eq)
hence "[f m; (f(m+1)); f n]"
using fQ assms(2,3) rs_def(4) unfolding chain_defs local_ordering_def
by (metis (no_types, lifting) \<open>[f m;f n;f (n + 1)]\<close> abc_only_cba(1) abc_sym abd_bcd_abc fQ thm2_ind1 y_betw)
hence "[f m; (f(m+1)); y]"
using \<open>[f m; f n; f(n + 1)]\<close> abc_acd_abd abd_bcd_abc y_betw
by blast
thus ?thesis
using abc_only_cba y_betw by blast
qed
thus "y\<in>{}" by blast
qed
qed
qed
qed
lemma (*for 11*) segmentation_ex_Nge3:
assumes path_P: "P\<in>\<P>"
and Q_def: "finite (Q::'a set)" "card Q = N" "Q\<subseteq>P" "N\<ge>3"
and f_def: "a\<in>Q \<and> b\<in>Q \<and> c\<in>Q" "[f\<leadsto>Q|a..b..c]"
and S_def: "S = {s. \<exists>i<(N-1). s = segment (f i) (f (i+1))}"
and P1_def: "P1 = prolongation b a"
and P2_def: "P2 = prolongation b c"
shows "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q) \<and>
(\<forall>x\<in>S. is_segment x) \<and>
P1\<inter>P2={} \<and> (\<forall>x\<in>S. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>S. x\<noteq>y \<longrightarrow> x\<inter>y={})))"
proof (intro disjoint_segmentation conjI)
show "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)"
using path_is_union assms
by blast
show "\<forall>x\<in>S. is_segment x"
proof
fix s assume "s\<in>S"
thus "is_segment s" using S_def by auto
qed
qed (use assms disjoint_segmentation in auto)
text \<open>Some unfolding of the definition for a finite chain that happens to be short.\<close>
lemma finite_chain_with_card_2:
assumes f_def: "[f\<leadsto>Q|a..b]"
and card_Q: "card Q = 2"
shows "finite Q" "f 0 = a" "f (card Q - 1) = b" "Q = {f 0, f 1}" "\<exists>Q. path Q (f 0) (f 1)"
using assms unfolding chain_defs by auto
text \<open>
Schutz says "As in the proof of the previous theorem [...]" - does he mean to imply that this
should really be proved as induction? I can see that quite easily, induct on $N$, and add a segment
by either splitting up a segment or taking a piece out of a prolongation.
But I think that might be too much trouble.
\<close>
theorem (*11*) show_segmentation:
assumes path_P: "P\<in>\<P>"
and Q_def: "Q\<subseteq>P"
and f_def: "[f\<leadsto>Q|a..b]"
fixes P1 defines P1_def: "P1 \<equiv> prolongation b a"
fixes P2 defines P2_def: "P2 \<equiv> prolongation a b"
fixes S defines S_def: "S \<equiv> {segment (f i) (f (i+1)) | i. i<card Q-1}"
shows "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)" "(\<forall>x\<in>S. is_segment x)"
"disjoint (S\<union>{P1,P2})" "P1\<noteq>P2" "P1\<notin>S" "P2\<notin>S"
proof -
have card_Q: "card Q \<ge> 2"
using fin_chain_card_geq_2 f_def by blast
have "finite Q"
by (metis card.infinite card_Q rel_simps(28))
have f_def_2: "a\<in>Q \<and> b\<in>Q"
using f_def points_in_chain finite_chain_with_def by auto
have "a\<noteq>b"
using f_def chain_defs by (metis first_neq_last)
{
assume "card Q = 2"
hence "card Q - 1 = Suc 0" by simp
have "Q = {f 0, f 1}" "\<exists>Q. path Q (f 0) (f 1)" "f 0 = a" "f (card Q - 1) = b"
using \<open>card Q = 2\<close> finite_chain_with_card_2 f_def by auto
hence "S={segment a b}"
unfolding S_def using \<open>card Q - 1 = Suc 0\<close> by (simp add: eval_nat_numeral)
hence "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)" "(\<forall>x\<in>S. is_segment x)" "P1\<inter>P2={}"
"(\<forall>x\<in>S. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>S. x\<noteq>y \<longrightarrow> x\<inter>y={})))"
using assms f_def \<open>finite Q\<close> segmentation_ex_N2
[where P=P and Q=Q and N="card Q"]
by (metis (no_types, lifting) \<open>card Q = 2\<close>)+
} moreover {
assume "card Q \<noteq> 2"
hence "card Q \<ge> 3"
using card_Q by auto
then obtain c where c_def: "[f\<leadsto>Q|a..c..b]"
using assms(3,5) \<open>a\<noteq>b\<close> chain_defs
by (metis f_def three_in_set3)
have pro_equiv: "P1 = prolongation c a \<and> P2 = prolongation c b"
using pro_basis_change
using P1_def P2_def abc_sym c_def fin_ch_betw by auto
have S_def2: "S = {s. \<exists>i<(card Q-1). s = segment (f i) (f (i+1))}"
using S_def \<open>card Q \<ge> 3\<close> by auto
have "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)" "(\<forall>x\<in>S. is_segment x)" "P1\<inter>P2={}"
"(\<forall>x\<in>S. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>S. x\<noteq>y \<longrightarrow> x\<inter>y={})))"
using f_def_2 assms f_def \<open>card Q \<ge> 3\<close> c_def pro_equiv
segmentation_ex_Nge3 [where P=P and Q=Q and N="card Q" and S=S and a=a and b=c and c=b and f=f]
using points_in_long_chain \<open>finite Q\<close> S_def2 by metis+
}
ultimately have old_thesis: "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)" "(\<forall>x\<in>S. is_segment x)" "P1\<inter>P2={}"
"(\<forall>x\<in>S. (x\<inter>P1={} \<and> x\<inter>P2={} \<and> (\<forall>y\<in>S. x\<noteq>y \<longrightarrow> x\<inter>y={})))" by meson+
thus "disjoint (S\<union>{P1,P2})" "P1\<noteq>P2" "P1\<notin>S" "P2\<notin>S"
"P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)" "(\<forall>x\<in>S. is_segment x)"
unfolding disjoint_def apply (simp add: Int_commute)
apply (metis P2_def Un_iff old_thesis(1,3) \<open>a \<noteq> b\<close> disjoint_iff f_def_2 path_P pro_betw prolong_betw2)
apply (metis P1_def Un_iff old_thesis(1,4) \<open>a \<noteq> b\<close> disjoint_iff f_def_2 path_P pro_betw prolong_betw3)
apply (metis P2_def Un_iff old_thesis(1,4) \<open>a \<noteq> b\<close> disjoint_iff f_def_2 path_P pro_betw prolong_betw)
using old_thesis(1,2) by linarith+
qed
theorem (*11*) segmentation:
assumes path_P: "P\<in>\<P>"
and Q_def: "card Q\<ge>2" "Q\<subseteq>P"
shows "\<exists>S P1 P2. P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q) \<and>
disjoint (S\<union>{P1,P2}) \<and> P1\<noteq>P2 \<and> P1\<notin>S \<and> P2\<notin>S \<and>
(\<forall>x\<in>S. is_segment x) \<and> is_prolongation P1 \<and> is_prolongation P2"
proof -
let ?N = "card Q"
(* Hooray for theorem 10! Without it, we couldn't so brazenly go from a set of events
to an ordered chain of events. *)
obtain f a b where f_def: "[f\<leadsto>Q|a..b]"
using path_finsubset_chain2[OF path_P Q_def(2,1)]
by metis
let ?S = "{segment (f i) (f (i+1)) | i. i<card Q-1}"
let ?P1 = "prolongation b a"
let ?P2 = "prolongation a b"
have from_seg: "P = ((\<Union>?S) \<union> ?P1 \<union> ?P2 \<union> Q)" "(\<forall>x\<in>?S. is_segment x)"
"disjoint (?S\<union>{?P1,?P2})" "?P1\<noteq>?P2" "?P1\<notin>?S" "?P2\<notin>?S"
using show_segmentation[OF path_P Q_def(2) \<open>[f\<leadsto>Q|a..b]\<close>]
by force+
thus ?thesis
by blast
qed
end (* context MinkowskiSpacetime *)
section "Chains are unique up to reversal"
context MinkowskiSpacetime begin
lemma chain_remove_at_right_edge:
assumes "[f\<leadsto>X|a..c]" "f (card X - 2) = p" "3 \<le> card X" "X = insert c Y" "c\<notin>Y"
shows "[f\<leadsto>Y|a..p]"
proof -
have lch_X: "local_long_ch_by_ord f X"
using assms(1,3) chain_defs short_ch_card_2
by fastforce
have "p\<in>X"
by (metis local_ordering_def assms(2) card.empty card_gt_0_iff diff_less lch_X
local_long_ch_by_ord_def not_numeral_le_zero zero_less_numeral)
have bound_ind: "f 0 = a \<and> f (card X - 1) = c"
using lch_X assms(1,3) unfolding finite_chain_with_def finite_long_chain_with_def
by metis
have "[a;p;c]"
proof -
have "card X - 2 < card X - 1"
using \<open>3 \<le> card X\<close> by auto
moreover have "card X - 2 > 0"
using \<open>3 \<le> card X\<close> by linarith
ultimately show ?thesis
using order_finite_chain[OF lch_X] \<open>3 \<le> card X\<close> assms(2) bound_ind
by (metis card.infinite diff_less le_numeral_extra(3) less_numeral_extra(1) not_gr_zero not_numeral_le_zero)
qed
have "[f\<leadsto>X|a..p..c]"
unfolding finite_long_chain_with_alt by (simp add: assms(1) \<open>[a;p;c]\<close> \<open>p\<in>X\<close>)
have 1: "x = a" if "x \<in> Y" "\<not> [a;x;p]" "x \<noteq> p" for x
proof -
have "x\<in>X"
using that(1) assms(4) by simp
hence 01: "x=a \<or> [a;p;x]"
by (metis that(2,3) \<open>[a;p;c]\<close> abd_acd_abcacb assms(1) fin_ch_betw2)
have 02: "x=c" if "[a;p;x]"
proof -
obtain i where i_def: "f i = x" "i<card X"
using \<open>x\<in>X\<close> chain_defs by (meson assms(1) obtain_index_fin_chain)
have "f 0 = a"
by (simp add: bound_ind)
have "card X - 2 < i"
using order_finite_chain_indices[OF lch_X _ that \<open>f 0 = a\<close> assms(2) i_def(1) _ _ i_def(2)]
by (metis card_eq_0_iff card_gt_0_iff diff_less i_def(2) less_nat_zero_code zero_less_numeral)
hence "i = card X - 1" using i_def(2) by linarith
thus ?thesis using bound_ind i_def(1) by blast
qed
show ?thesis using 01 02 assms(5) that(1) by auto
qed
have "Y = {e \<in> X. [a;e;p] \<or> e = a \<or> e = p}"
apply (safe, simp_all add: assms(4) 1)
using \<open>[a;p;c]\<close> abc_only_cba(2) abc_abc_neq assms(4) by blast+
thus ?thesis using chain_shortening[OF \<open>[f\<leadsto>X|a..p..c]\<close>] by simp
qed
lemma (in MinkowskiChain) fin_long_ch_imp_fin_ch:
assumes "[f\<leadsto>X|a..b..c]"
shows "[f\<leadsto>X|a..c]"
using assms by (simp add: finite_long_chain_with_alt)
text \<open>
If we ever want to have chains less strongly identified by endpoints,
this result should generalise - $a,c,x,z$ are only used to identify reversal/no-reversal cases.
\<close>
lemma chain_unique_induction_ax:
assumes "card X \<ge> 3"
and "i < card X"
and "[f\<leadsto>X|a..c]"
and "[g\<leadsto>X|x..z]"
and "a = x \<or> c = z"
shows "f i = g i"
using assms
proof (induct "card X - 3" arbitrary: X a c x z)
case Nil: 0
have "card X = 3"
using Nil.hyps Nil.prems(1) by auto
obtain b where f_ch: "[f\<leadsto>X|a..b..c]"
using chain_defs by (metis Nil.prems(1,3) three_in_set3)
obtain y where g_ch: "[g\<leadsto>X|x..y..z]"
using Nil.prems chain_defs by (metis three_in_set3)
have "i=1 \<or> i=0 \<or> i=2"
using \<open>card X = 3\<close> Nil.prems(2) by linarith
thus ?case
proof (rule disjE)
assume "i=1"
hence "f i = b \<and> g i = y"
using index_middle_element f_ch g_ch \<open>card X = 3\<close> numeral_3_eq_3
by (metis One_nat_def add_diff_cancel_left' less_SucE not_less_eq plus_1_eq_Suc)
have "f i = g i"
proof (rule ccontr)
assume "f i \<noteq> g i"
hence "g i \<noteq> b"
by (simp add: \<open>f i = b \<and> g i = y\<close>)
have "g i \<in> X"
using \<open>f i = b \<and> g i = y\<close> g_ch points_in_long_chain by blast
have "X = {a,b,c}"
using f_ch unfolding finite_long_chain_with_alt
using \<open>card X = 3\<close> points_in_long_chain[OF f_ch] abc_abc_neq[of a b c]
by (simp add: card_3_eq'(2))
hence "(g i = a \<or> g i = c)"
using \<open>g i \<noteq> b\<close> \<open>g i \<in> X\<close> by blast
hence "\<not> [a; g i; c]"
using abc_abc_neq by blast
hence "g i \<notin> X"
using \<open>f i=b \<and> g i=y\<close> \<open>g i=a \<or> g i=c\<close> f_ch g_ch chain_bounds_unique finite_long_chain_with_def
by blast
thus False
by (simp add: \<open>g i \<in> X\<close>)
qed
thus ?thesis
by (simp add: \<open>card X = 3\<close> \<open>i = 1\<close>)
next
assume "i = 0 \<or> i = 2"
show ?thesis
using Nil.prems(5) \<open>card X = 3\<close> \<open>i = 0 \<or> i = 2\<close> chain_bounds_unique f_ch g_ch chain_defs
by (metis diff_Suc_1 numeral_2_eq_2 numeral_3_eq_3)
qed
next
case IH: (Suc n)
have lch_fX: "local_long_ch_by_ord f X"
using chain_defs long_ch_card_ge3 IH(3,5)
by fastforce
have lch_gX: "local_long_ch_by_ord g X"
using IH(3,6) chain_defs long_ch_card_ge3
by fastforce
have fin_X: "finite X"
using IH(4) le_0_eq by fastforce
have "ch_by_ord f X"
using lch_fX unfolding ch_by_ord_def by blast
have "card X \<ge> 4"
using IH.hyps(2) by linarith
obtain b where f_ch: "[f\<leadsto>X|a..b..c]"
using IH(3,5) chain_defs by (metis three_in_set3)
obtain y where g_ch: "[g\<leadsto>X|x..y..z]"
using IH.prems(1,4) chain_defs by (metis three_in_set3)
obtain p where p_def: "p = f (card X - 2)" by simp
have "[a;p;c]"
proof -
have "card X - 2 < card X - 1"
using \<open>4 \<le> card X\<close> by auto
moreover have "card X - 2 > 0"
using \<open>3 \<le> card X\<close> by linarith
ultimately show ?thesis
using f_ch p_def chain_defs \<open>[f\<leadsto>X]\<close> order_finite_chain2 by force
qed
hence "p\<noteq>c \<and> p\<noteq>a"
using abc_abc_neq by blast
obtain Y where Y_def: "X = insert c Y" "c\<notin>Y"
using f_ch points_in_long_chain
by (meson mk_disjoint_insert)
hence fin_Y: "finite Y"
using f_ch chain_defs by auto
hence "n = card Y - 3"
using \<open>Suc n = card X - 3\<close> \<open>X = insert c Y\<close> \<open>c\<notin>Y\<close> card_insert_if
by auto
hence card_Y: "card Y = n + 3"
using Y_def(1) Y_def(2) fin_Y IH.hyps(2) by fastforce
have "card Y = card X - 1"
using Y_def(1,2) fin_X by auto
have "p\<in>Y"
using \<open>X = insert c Y\<close> \<open>[a;p;c]\<close> abc_abc_neq lch_fX p_def IH.prems(1,3) Y_def(2)
by (metis chain_remove_at_right_edge points_in_chain)
have "[f\<leadsto>Y|a..p]"
using chain_remove_at_right_edge [where f=f and a=a and c=c and X=X and p=p and Y=Y]
using fin_long_ch_imp_fin_ch [where f=f and a=a and c=c and b=b and X=X]
using f_ch p_def \<open>card X \<ge> 3\<close> Y_def
by blast
hence ch_fY: "local_long_ch_by_ord f Y"
using card_Y fin_Y chain_defs long_ch_card_ge3
by force
have p_closest: "\<not> (\<exists>q\<in>X. [p;q;c])"
proof
assume "(\<exists>q\<in>X. [p;q;c])"
then obtain q where "q\<in>X" "[p;q;c]" by blast
then obtain j where "j < card X" "f j = q"
using lch_fX lch_gX fin_X points_in_chain \<open>p\<noteq>c \<and> p\<noteq>a\<close> chain_defs
by (metis local_ordering_def)
have "j > card X - 2 \<and> j < card X - 1"
proof -
have "j > card X - 2 \<and> j < card X - 1 \<or> j > card X - 1 \<and> j < card X - 2"
apply (intro order_finite_chain_indices[OF lch_fX \<open>finite X\<close> \<open>[p;q;c]\<close>])
using p_def \<open>f j = q\<close> IH.prems(3) finite_chain_with_def \<open>j < card X\<close> by auto
thus ?thesis by linarith
qed
thus False by linarith
qed
have "g (card X - 2) = p"
proof (rule ccontr)
assume asm_false: "g (card X - 2) \<noteq> p"
obtain j where "g j = p" "j < card X - 1" "j>0"
using \<open>X = insert c Y\<close> \<open>p\<in>Y\<close> points_in_chain \<open>p\<noteq>c \<and> p\<noteq>a\<close>
by (metis (no_types) chain_bounds_unique f_ch
finite_long_chain_with_def g_ch index_middle_element insert_iff)
hence "j < card X - 2"
using asm_false le_eq_less_or_eq by fastforce
hence "j < card Y - 1"
by (simp add: Y_def(1,2) fin_Y)
obtain d where "d = g (card X - 2)" by simp
have "[p;d;z]"
proof -
have "card X - 1 > card X - 2"
using \<open>j < card X - 1\<close> by linarith
thus ?thesis
using lch_gX \<open>j < card Y - 1\<close> \<open>card Y = card X - 1\<close> \<open>d = g (card X - 2)\<close> \<open>g j = p\<close>
order_finite_chain[OF lch_gX] chain_defs local_ordering_def
by (smt (z3) IH.prems(3-5) asm_false chain_bounds_unique chain_remove_at_right_edge p_def
\<open>\<And>thesis. (\<And>Y. \<lbrakk>X = insert c Y; c \<notin> Y\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close>)
qed
moreover have "d\<in>X"
using lch_gX \<open>d = g (card X - 2)\<close> unfolding local_long_ch_by_ord_def local_ordering_def
by auto
ultimately show False
using p_closest abc_sym IH.prems(3-5) chain_bounds_unique f_ch g_ch
by blast
qed
hence ch_gY: "local_long_ch_by_ord g Y"
using IH.prems(1,4,5) g_ch f_ch ch_fY card_Y chain_remove_at_right_edge fin_Y chain_defs
by (metis Y_def chain_bounds_unique long_ch_card_ge3)
have "f i \<in> Y \<or> f i = c"
by (metis local_ordering_def \<open>X = insert c Y\<close> \<open>i < card X\<close> lch_fX insert_iff local_long_ch_by_ord_def)
thus "f i = g i"
proof (rule disjE)
assume "f i \<in> Y"
hence "f i \<noteq> c"
using \<open>c \<notin> Y\<close> by blast
hence "i < card Y"
using \<open>X = insert c Y\<close> \<open>c\<notin>Y\<close> IH(3,4) f_ch fin_Y chain_defs not_less_less_Suc_eq
by (metis \<open>card Y = card X - 1\<close> card_insert_disjoint)
hence "3 \<le> card Y"
using card_Y le_add2 by presburger
show "f i = g i"
using IH(1) [of Y]
using \<open>n = card Y - 3\<close> \<open>3 \<le> card Y\<close> \<open>i < card Y\<close>
using Y_def card_Y chain_remove_at_right_edge le_add2
by (metis IH.prems(1,3,4,5) chain_bounds_unique)
next
assume "f i = c"
show ?thesis
using IH.prems(2,5) \<open>f i = c\<close> chain_bounds_unique f_ch g_ch indices_neq_imp_events_neq chain_defs
by (metis \<open>card Y = card X - 1\<close> Y_def card_insert_disjoint fin_Y lessI)
qed
qed
text \<open>I'm really impressed \<open>sledgehammer\<close>/\<open>smt\<close> can solve this if I just tell them "Use symmetry!".\<close>
lemma chain_unique_induction_cx:
assumes "card X \<ge> 3"
and "i < card X"
and "[f\<leadsto>X|a..c]"
and "[g\<leadsto>X|x..z]"
and "c = x \<or> a = z"
shows "f i = g (card X - i - 1)"
using chain_sym_obtain2 chain_unique_induction_ax assms diff_right_commute by smt
text \<open>
This lemma has to exclude two-element chains again, because no order exists within them.
Alternatively, the result is trivial: any function that assigns one element to index 0 and
the other to 1 can be replaced with the (unique) other assignment, without destroying any
(trivial, since ternary) \<^term>\<open>local_ordering\<close> of the chain.
This could be made generic over the \<^term>\<open>local_ordering\<close>
similar to @{thm chain_sym} relying on @{thm ordering_sym_loc}.
\<close>
lemma chain_unique_upto_rev_cases:
assumes ch_f: "[f\<leadsto>X|a..c]"
and ch_g: "[g\<leadsto>X|x..z]"
and card_X: "card X \<ge> 3"
and valid_index: "i < card X"
shows "((a=x \<or> c=z) \<longrightarrow> (f i = g i))" "((a=z \<or> c=x) \<longrightarrow> (f i = g (card X - i - 1)))"
proof -
obtain n where n_def: "n = card X - 3"
by blast
hence valid_index_2: "i < n + 3"
by (simp add: card_X valid_index)
show "((a=x \<or> c=z) \<longrightarrow> (f i = g i))"
using card_X ch_f ch_g chain_unique_induction_ax valid_index by blast
show "((a=z \<or> c=x) \<longrightarrow> (f i = g (card X - i - 1)))"
using assms(3) ch_f ch_g chain_unique_induction_cx valid_index by blast
qed
lemma chain_unique_upto_rev:
assumes "[f\<leadsto>X|a..c]" "[g\<leadsto>X|x..z]" "card X \<ge> 3" "i < card X"
shows "f i = g i \<or> f i = g (card X - i - 1)" "a=x\<and>c=z \<or> c=x\<and>a=z"
proof -
have "(a=x \<or> c=z) \<or> (a=z \<or> c=x)"
using chain_bounds_unique by (metis assms(1,2))
thus "f i = g i \<or> f i = g (card X - i - 1)"
using assms(3) \<open>i < card X\<close> assms chain_unique_upto_rev_cases by blast
thus "(a=x\<and>c=z) \<or> (c=x\<and>a=z)"
by (meson assms(1-3) chain_bounds_unique)
qed
end (* context MinkowskiSpacetime *)
section "Interlude: betw4 and WLOG"
subsection "betw4 - strict and non-strict, basic lemmas"
context MinkowskiBetweenness begin
text \<open>Define additional notation for non-strict \<^term>\<open>local_ordering\<close> -
cf Schutz' monograph \cite[ p.~27]{schutz1997}.\<close>
abbreviation nonstrict_betw_right :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" ("[_;_;_\<rbrakk>") where
"nonstrict_betw_right a b c \<equiv> [a;b;c] \<or> b = c"
abbreviation nonstrict_betw_left :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" ("\<lbrakk>_;_;_]") where
"nonstrict_betw_left a b c \<equiv> [a;b;c] \<or> b = a"
abbreviation nonstrict_betw_both :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" (* ("[(_ _ _)]") *) where
"nonstrict_betw_both a b c \<equiv> nonstrict_betw_left a b c \<or> nonstrict_betw_right a b c"
abbreviation betw4 :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" ("[_;_;_;_]") where
"betw4 a b c d \<equiv> [a;b;c] \<and> [b;c;d]"
abbreviation nonstrict_betw_right4 :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" ("[_;_;_;_\<rbrakk>") where
"nonstrict_betw_right4 a b c d \<equiv> betw4 a b c d \<or> c = d"
abbreviation nonstrict_betw_left4 :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" ("\<lbrakk>_;_;_;_]") where
"nonstrict_betw_left4 a b c d \<equiv> betw4 a b c d \<or> a = b"
abbreviation nonstrict_betw_both4 :: "'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" (* ("[(_ _ _ _)]") *) where
"nonstrict_betw_both4 a b c d \<equiv> nonstrict_betw_left4 a b c d \<or> nonstrict_betw_right4 a b c d"
lemma betw4_strong:
assumes "betw4 a b c d"
shows "[a;b;d] \<and> [a;c;d]"
using abc_bcd_acd assms by blast
lemma betw4_imp_neq:
assumes "betw4 a b c d"
shows "a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d"
using abc_only_cba assms by blast
end (* context MinkowskiBetweenness *)
context MinkowskiSpacetime begin
lemma betw4_weak:
fixes a b c d :: 'a
assumes "[a;b;c] \<and> [a;c;d]
\<or> [a;b;c] \<and> [b;c;d]
\<or> [a;b;d] \<and> [b;c;d]
\<or> [a;b;d] \<and> [b;c;d]"
shows "betw4 a b c d"
using abc_acd_bcd abd_bcd_abc assms by blast
lemma betw4_sym:
fixes a::'a and b::'a and c::'a and d::'a
shows "betw4 a b c d \<longleftrightarrow> betw4 d c b a"
using abc_sym by blast
lemma abcd_dcba_only:
fixes a::'a and b::'a and c::'a and d::'a
assumes "[a;b;c;d]"
shows "\<not>[a;b;d;c]" "\<not>[a;c;b;d]" "\<not>[a;c;d;b]" "\<not>[a;d;b;c]" "\<not>[a;d;c;b]"
"\<not>[b;a;c;d]" "\<not>[b;a;d;c]" "\<not>[b;c;a;d]" "\<not>[b;c;d;a]" "\<not>[b;d;c;a]" "\<not>[b;d;a;c]"
"\<not>[c;a;b;d]" "\<not>[c;a;d;b]" "\<not>[c;b;a;d]" "\<not>[c;b;d;a]" "\<not>[c;d;a;b]" "\<not>[c;d;b;a]"
"\<not>[d;a;b;c]" "\<not>[d;a;c;b]" "\<not>[d;b;a;c]" "\<not>[d;b;c;a]" "\<not>[d;c;a;b]"
using abc_only_cba assms by blast+
lemma some_betw4a:
fixes a::'a and b::'a and c::'a and d::'a and P
assumes "P\<in>\<P>" "a\<in>P" "b\<in>P" "c\<in>P" "d\<in>P" "a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d"
and "\<not>([a;b;c;d] \<or> [a;b;d;c] \<or> [a;c;b;d] \<or> [a;c;d;b] \<or> [a;d;b;c] \<or> [a;d;c;b])"
shows "[b;a;c;d] \<or> [b;a;d;c] \<or> [b;c;a;d] \<or> [b;d;a;c] \<or> [c;a;b;d] \<or> [c;b;a;d]"
by (smt abc_bcd_acd abc_sym abd_bcd_abc assms some_betw_xor)
lemma some_betw4b:
fixes a::'a and b::'a and c::'a and d::'a and P
assumes "P\<in>\<P>" "a\<in>P" "b\<in>P" "c\<in>P" "d\<in>P" "a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d"
and "\<not>([b;a;c;d] \<or> [b;a;d;c] \<or> [b;c;a;d] \<or> [b;d;a;c] \<or> [c;a;b;d] \<or> [c;b;a;d])"
shows "[a;b;c;d] \<or> [a;b;d;c] \<or> [a;c;b;d] \<or> [a;c;d;b] \<or> [a;d;b;c] \<or> [a;d;c;b]"
by (smt abc_bcd_acd abc_sym abd_bcd_abc assms some_betw_xor)
lemma abd_acd_abcdacbd:
fixes a::'a and b::'a and c::'a and d::'a
assumes abd: "[a;b;d]" and acd: "[a;c;d]" and "b\<noteq>c"
shows "[a;b;c;d] \<or> [a;c;b;d]"
proof -
obtain P where "P\<in>\<P>" "a\<in>P" "b\<in>P" "d\<in>P"
using abc_ex_path abd by blast
have "c\<in>P"
using \<open>P \<in> \<P>\<close> \<open>a \<in> P\<close> \<open>d \<in> P\<close> abc_abc_neq acd betw_b_in_path by blast
have "\<not>[b;d;c]"
using abc_sym abcd_dcba_only(5) abd acd by blast
hence "[b;c;d] \<or> [c;b;d]"
using abc_abc_neq abc_sym abd acd assms(3) some_betw
by (metis \<open>P \<in> \<P>\<close> \<open>b \<in> P\<close> \<open>c \<in> P\<close> \<open>d \<in> P\<close>)
thus ?thesis
using abd acd betw4_weak by blast
qed
end (*context MinkowskiSpacetime*)
subsection "WLOG for two general symmetric relations of two elements on a single path"
context MinkowskiBetweenness begin
text \<open>
This first one is really just trying to get a hang of how to write these things.
If you have a relation that does not care which way round the ``endpoints'' (if $Q$ is the
interval-relation) go, then anything you want to prove about both undistinguished endpoints,
follows from a proof involving a single endpoint.
\<close>
lemma wlog_sym_element:
assumes symmetric_rel: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and one_endpoint: "\<And>a b x I. \<lbrakk>Q I a b; x=a\<rbrakk> \<Longrightarrow> P x I"
shows other_endpoint: "\<And>a b x I. \<lbrakk>Q I a b; x=b\<rbrakk> \<Longrightarrow> P x I"
using assms by fastforce
text \<open>
This one gives the most pertinent case split: a proof involving e.g. an element of an interval
must consider the edge case and the inside case.
\<close>
lemma wlog_element:
assumes symmetric_rel: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and one_endpoint: "\<And>a b x I. \<lbrakk>Q I a b; x=a\<rbrakk> \<Longrightarrow> P x I"
and neither_endpoint: "\<And>a b x I. \<lbrakk>Q I a b; x\<in>I; (x\<noteq>a \<and> x\<noteq>b)\<rbrakk> \<Longrightarrow> P x I"
shows any_element: "\<And>x I. \<lbrakk>x\<in>I; (\<exists>a b. Q I a b)\<rbrakk> \<Longrightarrow> P x I"
by (metis assms)
text \<open>
Summary of the two above. Use for early case splitting in proofs.
Doesn't need $P$ to be symmetric - the context in the conclusion is explicitly symmetric.
\<close>
lemma wlog_two_sets_element:
assumes symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and case_split: "\<And>a b c d x I J. \<lbrakk>Q I a b; Q J c d\<rbrakk> \<Longrightarrow>
(x=a \<or> x=c \<longrightarrow> P x I J) \<and> (\<not>(x=a \<or> x=b \<or> x=c \<or> x=d) \<longrightarrow> P x I J)"
shows "\<And>x I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>a b. Q J a b\<rbrakk> \<Longrightarrow> P x I J"
by (smt case_split symmetric_Q)
text \<open>
Now we start on the actual result of interest. First we assume the events are all distinct,
and we deal with the degenerate possibilities after.
\<close>
lemma wlog_endpoints_distinct1:
assumes symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; [a;b;c;d]\<rbrakk> \<Longrightarrow> P I J"
shows "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d;
[b;a;c;d] \<or> [a;b;d;c] \<or> [b;a;d;c] \<or> [d;c;b;a]\<rbrakk> \<Longrightarrow> P I J"
by (meson abc_sym assms(2) symmetric_Q)
lemma wlog_endpoints_distinct2:
assumes symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; [a;c;b;d]\<rbrakk> \<Longrightarrow> P I J"
shows "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d;
[b;c;a;d] \<or> [a;d;b;c] \<or> [b;d;a;c] \<or> [d;b;c;a]\<rbrakk> \<Longrightarrow> P I J"
by (meson abc_sym assms(2) symmetric_Q)
lemma wlog_endpoints_distinct3:
assumes symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and symmetric_P: "\<And>I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>a b. Q J a b; P I J\<rbrakk> \<Longrightarrow> P J I"
and "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; [a;c;d;b]\<rbrakk> \<Longrightarrow> P I J"
shows "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d;
[a;d;c;b] \<or> [b;c;d;a] \<or> [b;d;c;a] \<or> [c;a;b;d]\<rbrakk> \<Longrightarrow> P I J"
by (meson assms)
lemma (in MinkowskiSpacetime) wlog_endpoints_distinct4:
fixes Q:: "('a set) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" (* cf \<open>I = interval a b\<close> *)
and P:: "('a set) \<Rightarrow> ('a set) \<Rightarrow> bool"
and A:: "('a set)" (* the path that takes the role of the real line *)
assumes path_A: "A\<in>\<P>"
and symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and Q_implies_path: "\<And>a b I. \<lbrakk>I\<subseteq>A; Q I a b\<rbrakk> \<Longrightarrow> b\<in>A \<and> a\<in>A"
and symmetric_P: "\<And>I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>a b. Q J a b; P I J\<rbrakk> \<Longrightarrow> P J I"
and "\<And>I J a b c d.
\<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A; [a;b;c;d] \<or> [a;c;b;d] \<or> [a;c;d;b]\<rbrakk> \<Longrightarrow> P I J"
shows "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A;
a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d\<rbrakk> \<Longrightarrow> P I J"
proof -
fix I J a b c d
assume asm: "Q I a b" "Q J c d" "I \<subseteq> A" "J \<subseteq> A"
"a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d"
have endpoints_on_path: "a\<in>A" "b\<in>A" "c\<in>A" "d\<in>A"
using Q_implies_path asm by blast+
show "P I J"
proof (cases) (* have to split like this, because the full \<open>some_betw\<close> is too large for Isabelle *)
assume "[b;a;c;d] \<or> [b;a;d;c] \<or> [b;c;a;d] \<or>
[b;d;a;c] \<or> [c;a;b;d] \<or> [c;b;a;d]"
then consider "[b;a;c;d]"|"[b;a;d;c]"|"[b;c;a;d]"|
"[b;d;a;c]"|"[c;a;b;d]"|"[c;b;a;d]"
by linarith
thus "P I J"
apply (cases)
apply (metis(mono_tags) asm(1-4) assms(5) symmetric_Q)+
apply (metis asm(1-4) assms(4,5))
by (metis asm(1-4) assms(2,4,5) symmetric_Q)
next
assume "\<not>([b;a;c;d] \<or> [b;a;d;c] \<or> [b;c;a;d] \<or>
[b;d;a;c] \<or> [c;a;b;d] \<or> [c;b;a;d])"
hence "[a;b;c;d] \<or> [a;b;d;c] \<or> [a;c;b;d] \<or>
[a;c;d;b] \<or> [a;d;b;c] \<or> [a;d;c;b]"
using some_betw4b [where P=A and a=a and b=b and c=c and d=d]
using endpoints_on_path asm path_A by simp
then consider "[a;b;c;d]"|"[a;b;d;c]"|"[a;c;b;d]"|
"[a;c;d;b]"|"[a;d;b;c]"|"[a;d;c;b]"
by linarith
thus "P I J"
apply (cases)
by (metis asm(1-4) assms(5) symmetric_Q)+
qed
qed
lemma (in MinkowskiSpacetime) wlog_endpoints_distinct':
assumes "A \<in> \<P>"
and "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and "\<And>a b I. \<lbrakk>I \<subseteq> A; Q I a b\<rbrakk> \<Longrightarrow> a \<in> A"
and "\<And>I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>a b. Q J a b; P I J\<rbrakk> \<Longrightarrow> P J I"
and "\<And>I J a b c d.
\<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A; betw4 a b c d \<or> betw4 a c b d \<or> betw4 a c d b\<rbrakk> \<Longrightarrow> P I J"
and "Q I a b"
and "Q J c d"
and "I \<subseteq> A"
and "J \<subseteq> A"
and "a \<noteq> b" "a \<noteq> c" "a \<noteq> d" "b \<noteq> c" "b \<noteq> d" "c \<noteq> d"
shows "P I J"
proof -
{
let ?R = "(\<lambda>I. (\<exists>a b. Q I a b))"
have "\<And>I J. \<lbrakk>?R I; ?R J; P I J\<rbrakk> \<Longrightarrow> P J I"
using assms(4) by blast
}
thus ?thesis
using wlog_endpoints_distinct4
[where P=P and Q=Q and A=A and I=I and J=J and a=a and b=b and c=c and d=d]
by (smt assms(1-3,5-))
qed
lemma (in MinkowskiSpacetime) wlog_endpoints_distinct:
assumes path_A: "A\<in>\<P>"
and symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and Q_implies_path: "\<And>a b I. \<lbrakk>I\<subseteq>A; Q I a b\<rbrakk> \<Longrightarrow> b\<in>A \<and> a\<in>A"
and symmetric_P: "\<And>I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>a b. Q J a b; P I J\<rbrakk> \<Longrightarrow> P J I"
and "\<And>I J a b c d.
\<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A; [a;b;c;d] \<or> [a;c;b;d] \<or> [a;c;d;b]\<rbrakk> \<Longrightarrow> P I J"
shows "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A;
a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d\<rbrakk> \<Longrightarrow> P I J"
by (smt (verit, ccfv_SIG) assms some_betw4b)
lemma wlog_endpoints_degenerate1:
assumes symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and symmetric_P: "\<And>I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>a b. Q I a b; P I J\<rbrakk> \<Longrightarrow> P J I"
(* two singleton intervals *)
and two: "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d;
(a=b \<and> b=c \<and> c=d) \<or> (a=b \<and> b\<noteq>c \<and> c=d)\<rbrakk> \<Longrightarrow> P I J"
(* one singleton interval *)
and one: "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d;
(a=b \<and> b=c \<and> c\<noteq>d) \<or> (a=b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d)\<rbrakk> \<Longrightarrow> P I J"
(* no singleton interval - the all-distinct case is a separate theorem *)
and no: "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d;
(a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a=d) \<or> (a\<noteq>b \<and> b=c \<and> c\<noteq>d \<and> a=d)\<rbrakk> \<Longrightarrow> P I J"
shows "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; \<not>(a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d \<and> a\<noteq>c \<and> b\<noteq>d)\<rbrakk> \<Longrightarrow> P I J"
by (metis assms)
lemma wlog_endpoints_degenerate2:
assumes symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and Q_implies_path: "\<And>a b I A. \<lbrakk>I\<subseteq>A; A\<in>\<P>; Q I a b\<rbrakk> \<Longrightarrow> b\<in>A \<and> a\<in>A"
and symmetric_P: "\<And>I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>a b. Q J a b; P I J\<rbrakk> \<Longrightarrow> P J I"
and "\<And>I J a b c d A. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A; A\<in>\<P>;
[a;b;c] \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
and "\<And>I J a b c d A. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A; A\<in>\<P>;
[b;a;c] \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
shows "\<And>I J a b c d A. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A; A\<in>\<P>;
a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
proof -
have last_case: "\<And>I J a b c d A. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A; A\<in>\<P>;
[b;c;a] \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
using assms(1,3-5) by (metis abc_sym)
thus "\<And>I J a b c d A. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A; A\<in>\<P>;
a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
by (smt (z3) abc_sym assms(2,4,5) some_betw)
qed
lemma wlog_endpoints_degenerate:
assumes path_A: "A\<in>\<P>"
and symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and Q_implies_path: "\<And>a b I. \<lbrakk>I\<subseteq>A; Q I a b\<rbrakk> \<Longrightarrow> b\<in>A \<and> a\<in>A"
and symmetric_P: "\<And>I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>a b. Q J a b; P I J\<rbrakk> \<Longrightarrow> P J I"
and "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A\<rbrakk>
\<Longrightarrow> ((a=b \<and> b=c \<and> c=d) \<longrightarrow> P I J) \<and> ((a=b \<and> b\<noteq>c \<and> c=d) \<longrightarrow> P I J)
\<and> ((a=b \<and> b=c \<and> c\<noteq>d) \<longrightarrow> P I J) \<and> ((a=b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d) \<longrightarrow> P I J)
\<and> ((a\<noteq>b \<and> b=c \<and> c\<noteq>d \<and> a=d) \<longrightarrow> P I J)
\<and> (([a;b;c] \<and> a=d) \<longrightarrow> P I J) \<and> (([b;a;c] \<and> a=d) \<longrightarrow> P I J)"
shows "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A;
\<not>(a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d \<and> a\<noteq>c \<and> b\<noteq>d)\<rbrakk> \<Longrightarrow> P I J"
proof -
text \<open>We first extract some of the assumptions of this lemma into the form
of other WLOG lemmas' assumptions.\<close>
have ord1: "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A;
[a;b;c] \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
using assms(5) by auto
have ord2: "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A;
[b;a;c] \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
using assms(5) by auto
have last_case: "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A;
a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
using ord1 ord2 wlog_endpoints_degenerate2 symmetric_P symmetric_Q Q_implies_path path_A
by (metis abc_sym some_betw)
show "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A;
\<not>(a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d \<and> a\<noteq>c \<and> b\<noteq>d)\<rbrakk> \<Longrightarrow> P I J"
proof -
text \<open>Fix the sets on the path, and obtain the assumptions of \<open>wlog_endpoints_degenerate1\<close>.\<close>
fix I J
assume asm1: "I\<subseteq>A" "J\<subseteq>A"
have two: "\<And>a b c d. \<lbrakk>Q I a b; Q J c d; a=b \<and> b=c \<and> c=d\<rbrakk> \<Longrightarrow> P I J"
"\<And>a b c d. \<lbrakk>Q I a b; Q J c d; a=b \<and> b\<noteq>c \<and> c=d\<rbrakk> \<Longrightarrow> P I J"
using \<open>J \<subseteq> A\<close> \<open>I \<subseteq> A\<close> path_A assms(5) by blast+
have one: "\<And> a b c d. \<lbrakk>Q I a b; Q J c d; a=b \<and> b=c \<and> c\<noteq>d\<rbrakk> \<Longrightarrow> P I J"
"\<And> a b c d. \<lbrakk>Q I a b; Q J c d; a=b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d\<rbrakk> \<Longrightarrow> P I J"
using \<open>I \<subseteq> A\<close> \<open>J \<subseteq> A\<close> path_A assms(5) by blast+
have no: "\<And> a b c d. \<lbrakk>Q I a b; Q J c d; a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
"\<And> a b c d. \<lbrakk>Q I a b; Q J c d; a\<noteq>b \<and> b=c \<and> c\<noteq>d \<and> a=d\<rbrakk> \<Longrightarrow> P I J"
using \<open>I \<subseteq> A\<close> \<open>J \<subseteq> A\<close> path_A last_case apply blast
using \<open>I \<subseteq> A\<close> \<open>J \<subseteq> A\<close> path_A assms(5) by auto
text \<open>Now unwrap the remaining object logic and finish the proof.\<close>
fix a b c d
assume asm2: "Q I a b" "Q J c d" "\<not>(a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d \<and> a\<noteq>c \<and> b\<noteq>d)"
show "P I J"
using two [where a=a and b=b and c=c and d=d]
using one [where a=a and b=b and c=c and d=d]
using no [where a=a and b=b and c=c and d=d]
using wlog_endpoints_degenerate1
[where I=I and J=J and a=a and b=b and c=c and d=d and P=P and Q=Q]
using asm1 asm2 symmetric_P last_case assms(5) symmetric_Q
by smt
qed
qed
lemma (in MinkowskiSpacetime) wlog_intro:
assumes path_A: "A\<in>\<P>"
and symmetric_Q: "\<And>a b I. Q I a b \<Longrightarrow> Q I b a"
and Q_implies_path: "\<And>a b I. \<lbrakk>I\<subseteq>A; Q I a b\<rbrakk> \<Longrightarrow> b\<in>A \<and> a\<in>A"
and symmetric_P: "\<And>I J. \<lbrakk>\<exists>a b. Q I a b; \<exists>c d. Q J c d; P I J\<rbrakk> \<Longrightarrow> P J I"
and essential_cases: "\<And>I J a b c d. \<lbrakk>Q I a b; Q J c d; I\<subseteq>A; J\<subseteq>A\<rbrakk>
\<Longrightarrow> ((a=b \<and> b=c \<and> c=d) \<longrightarrow> P I J)
\<and> ((a=b \<and> b\<noteq>c \<and> c=d) \<longrightarrow> P I J)
\<and> ((a=b \<and> b=c \<and> c\<noteq>d) \<longrightarrow> P I J)
\<and> ((a=b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d) \<longrightarrow> P I J)
\<and> ((a\<noteq>b \<and> b=c \<and> c\<noteq>d \<and> a=d) \<longrightarrow> P I J)
\<and> (([a;b;c] \<and> a=d) \<longrightarrow> P I J)
\<and> (([b;a;c] \<and> a=d) \<longrightarrow> P I J)
\<and> ([a;b;c;d] \<longrightarrow> P I J)
\<and> ([a;c;b;d] \<longrightarrow> P I J)
\<and> ([a;c;d;b] \<longrightarrow> P I J)"
and antecedants: "Q I a b" "Q J c d" "I\<subseteq>A" "J\<subseteq>A"
shows "P I J"
using essential_cases antecedants
and wlog_endpoints_degenerate[OF path_A symmetric_Q Q_implies_path symmetric_P]
and wlog_endpoints_distinct[OF path_A symmetric_Q Q_implies_path symmetric_P]
by (smt (z3) Q_implies_path path_A symmetric_P symmetric_Q some_betw2 some_betw4b abc_only_cba(1))
end (*context MinkowskiSpacetime*)
subsection "WLOG for two intervals"
context MinkowskiBetweenness begin
text \<open>
This section just specifies the results for a generic relation $Q$
in the previous section to the interval relation.
\<close>
lemma wlog_two_interval_element:
assumes "\<And>x I J. \<lbrakk>is_interval I; is_interval J; P x J I\<rbrakk> \<Longrightarrow> P x I J"
and "\<And>a b c d x I J. \<lbrakk>I = interval a b; J = interval c d\<rbrakk> \<Longrightarrow>
(x=a \<or> x=c \<longrightarrow> P x I J) \<and> (\<not>(x=a \<or> x=b \<or> x=c \<or> x=d) \<longrightarrow> P x I J)"
shows "\<And>x I J. \<lbrakk>is_interval I; is_interval J\<rbrakk> \<Longrightarrow> P x I J"
by (metis assms(2) int_sym)
lemma (in MinkowskiSpacetime) wlog_interval_endpoints_distinct:
assumes "\<And>I J. \<lbrakk>is_interval I; is_interval J; P I J\<rbrakk> \<Longrightarrow> P J I" (*P does not distinguish between intervals*)
"\<And>I J a b c d. \<lbrakk>I = interval a b; J = interval c d\<rbrakk>
\<Longrightarrow> ([a;b;c;d] \<longrightarrow> P I J) \<and> ([a;c;b;d] \<longrightarrow> P I J) \<and> ([a;c;d;b] \<longrightarrow> P I J)"
shows "\<And>I J Q a b c d. \<lbrakk>I = interval a b; J = interval c d; I\<subseteq>Q; J\<subseteq>Q; Q\<in>\<P>;
a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d\<rbrakk> \<Longrightarrow> P I J"
proof -
let ?Q = "\<lambda> I a b. I = interval a b"
fix I J A a b c d
assume asm: "?Q I a b" "?Q J c d" "I\<subseteq>A" "J\<subseteq>A" "A\<in>\<P>" "a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d"
show "P I J"
proof (rule wlog_endpoints_distinct)
show "\<And>a b I. ?Q I a b \<Longrightarrow> ?Q I b a"
by (simp add: int_sym)
show "\<And>a b I. I \<subseteq> A \<Longrightarrow> ?Q I a b \<Longrightarrow> b \<in> A \<and> a \<in> A"
by (simp add: ends_in_int subset_iff)
show "\<And>I J. is_interval I \<Longrightarrow> is_interval J \<Longrightarrow> P I J \<Longrightarrow> P J I"
using assms(1) by blast
show "\<And>I J a b c d. \<lbrakk>?Q I a b; ?Q J c d; [a;b;c;d] \<or> [a;c;b;d] \<or> [a;c;d;b]\<rbrakk>
\<Longrightarrow> P I J"
by (meson assms(2))
show "I = interval a b" "J = interval c d" "I\<subseteq>A" "J\<subseteq>A" "A\<in>\<P>"
"a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d"
using asm by simp+
qed
qed
lemma wlog_interval_endpoints_degenerate:
assumes symmetry: "\<And>I J. \<lbrakk>is_interval I; is_interval J; P I J\<rbrakk> \<Longrightarrow> P J I"
and "\<And>I J a b c d Q. \<lbrakk>I = interval a b; J = interval c d; I\<subseteq>Q; J\<subseteq>Q; Q\<in>\<P>\<rbrakk>
\<Longrightarrow> ((a=b \<and> b=c \<and> c=d) \<longrightarrow> P I J) \<and> ((a=b \<and> b\<noteq>c \<and> c=d) \<longrightarrow> P I J)
\<and> ((a=b \<and> b=c \<and> c\<noteq>d) \<longrightarrow> P I J) \<and> ((a=b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d) \<longrightarrow> P I J)
\<and> ((a\<noteq>b \<and> b=c \<and> c\<noteq>d \<and> a=d) \<longrightarrow> P I J)
\<and> (([a;b;c] \<and> a=d) \<longrightarrow> P I J) \<and> (([b;a;c] \<and> a=d) \<longrightarrow> P I J)"
shows "\<And>I J a b c d Q. \<lbrakk>I = interval a b; J = interval c d; I\<subseteq>Q; J\<subseteq>Q; Q\<in>\<P>;
\<not>(a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d \<and> a\<noteq>c \<and> b\<noteq>d)\<rbrakk> \<Longrightarrow> P I J"
proof -
let ?Q = "\<lambda> I a b. I = interval a b"
fix I J a b c d A
assume asm: "?Q I a b" "?Q J c d" "I\<subseteq>A" "J\<subseteq>A" "A\<in>\<P>" "\<not>(a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d \<and> a\<noteq>c \<and> b\<noteq>d)"
show "P I J"
proof (rule wlog_endpoints_degenerate)
show "\<And>a b I. ?Q I a b \<Longrightarrow> ?Q I b a"
by (simp add: int_sym)
show "\<And>a b I. I \<subseteq> A \<Longrightarrow> ?Q I a b \<Longrightarrow> b \<in> A \<and> a \<in> A"
by (simp add: ends_in_int subset_iff)
show "\<And>I J. is_interval I \<Longrightarrow> is_interval J \<Longrightarrow> P I J \<Longrightarrow> P J I"
using symmetry by blast
show "I = interval a b" "J = interval c d" "I\<subseteq>A" "J\<subseteq>A" "A\<in>\<P>"
"\<not> (a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d \<and> a\<noteq>c \<and> b\<noteq>d)"
using asm by auto+
show "\<And>I J a b c d. \<lbrakk>?Q I a b; ?Q J c d; I \<subseteq> A; J \<subseteq> A\<rbrakk> \<Longrightarrow>
(a = b \<and> b = c \<and> c = d \<longrightarrow> P I J) \<and>
(a = b \<and> b \<noteq> c \<and> c = d \<longrightarrow> P I J) \<and>
(a = b \<and> b = c \<and> c \<noteq> d \<longrightarrow> P I J) \<and>
(a = b \<and> b \<noteq> c \<and> c \<noteq> d \<and> a \<noteq> d \<longrightarrow> P I J) \<and>
(a \<noteq> b \<and> b = c \<and> c \<noteq> d \<and> a = d \<longrightarrow> P I J) \<and>
([a;b;c] \<and> a = d \<longrightarrow> P I J) \<and> ([b;a;c] \<and> a = d \<longrightarrow> P I J)"
using assms(2) \<open>A\<in>\<P>\<close> by auto
qed
qed
end (* context MinkowskiBetweenness *)
section "Interlude: Intervals, Segments, Connectedness"
context MinkowskiSpacetime begin
text \<open>
In this secion, we apply the WLOG lemmas from the previous section in order to reduce the
number of cases we need to consider when thinking about two arbitrary intervals on a path.
This is used to prove that the (countable) intersection of intervals is an interval.
These results cannot be found in Schutz, but he does use them (without justification)
in his proof of Theorem 12 (even for uncountable intersections).
\<close>
lemma int_of_ints_is_interval_neq: (* Proof using WLOG *)
assumes "I1 = interval a b" "I2 = interval c d" "I1\<subseteq>P" "I2\<subseteq>P" "P\<in>\<P>" "I1\<inter>I2 \<noteq> {}"
and events_neq: "a\<noteq>b" "a\<noteq>c" "a\<noteq>d" "b\<noteq>c" "b\<noteq>d" "c\<noteq>d"
shows "is_interval (I1 \<inter> I2)"
proof -
have on_path: "a\<in>P \<and> b\<in>P \<and> c\<in>P \<and> d\<in>P"
using assms(1-4) interval_def by auto
let ?prop = "\<lambda> I J. is_interval (I\<inter>J) \<or> (I\<inter>J) = {}" (* The empty intersection is excluded in assms. *)
have symmetry: "(\<And>I J. is_interval I \<Longrightarrow> is_interval J \<Longrightarrow> ?prop I J \<Longrightarrow> ?prop J I)"
by (simp add: Int_commute)
{
fix I J a b c d
assume "I = interval a b" "J = interval c d"
have "([a;b;c;d] \<longrightarrow> ?prop I J)"
"([a;c;b;d] \<longrightarrow> ?prop I J)"
"([a;c;d;b] \<longrightarrow> ?prop I J)"
proof (rule_tac [!] impI)
assume "betw4 a b c d"
have "I\<inter>J = {}"
proof (rule ccontr)
assume "I\<inter>J\<noteq>{}"
then obtain x where "x\<in>I\<inter>J"
by blast
show False
proof (cases)
assume "x\<noteq>a \<and> x\<noteq>b \<and> x\<noteq>c \<and> x\<noteq>d"
hence "[a;x;b]" "[c;x;d]"
using \<open>I=interval a b\<close> \<open>x\<in>I\<inter>J\<close> \<open>J=interval c d\<close> \<open>x\<in>I\<inter>J\<close>
by (simp add: interval_def seg_betw)+
thus False
by (meson \<open>betw4 a b c d\<close> abc_only_cba(3) abc_sym abd_bcd_abc)
next
assume "\<not>(x\<noteq>a \<and> x\<noteq>b \<and> x\<noteq>c \<and> x\<noteq>d)"
thus False
using interval_def seg_betw \<open>I = interval a b\<close> \<open>J = interval c d\<close> abcd_dcba_only(21)
\<open>x \<in> I \<inter> J\<close> \<open>betw4 a b c d\<close> abc_bcd_abd abc_bcd_acd abc_only_cba(1,2)
by (metis (full_types) insert_iff Int_iff)
qed
qed
thus "?prop I J" by simp
next
assume "[a;c;b;d]"
then have "a \<noteq> b \<and> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<and> c \<noteq> d"
using betw4_imp_neq by blast
have "I\<inter>J = interval c b"
proof (safe)
fix x
assume "x \<in> interval c b"
{
assume "x=b \<or> x=c"
hence "x\<in>I"
using \<open>[a;c;b;d]\<close> \<open>I = interval a b\<close> interval_def seg_betw by auto
have "x\<in>J"
using \<open>x=b \<or> x=c\<close>
using \<open>[a;c;b;d]\<close> \<open>J = interval c d\<close> interval_def seg_betw by auto
hence "x\<in>I \<and> x\<in>J" using \<open>x \<in> I\<close> by blast
} moreover {
assume "\<not>(x=b \<or> x=c)"
hence "[c;x;b]"
using \<open>x\<in>interval c b\<close> unfolding interval_def segment_def by simp
hence "[a;x;b]"
by (meson \<open>[a;c;b;d]\<close> abc_acd_abd abc_sym)
have "[c;x;d]"
using \<open>[a;c;b;d]\<close> \<open>[c;x;b]\<close> abc_acd_abd by blast
have "x\<in>I" "x\<in>J"
using \<open>I = interval a b\<close> \<open>[a;x;b]\<close> \<open>J = interval c d\<close> \<open>[c;x;d]\<close>
interval_def seg_betw by auto
}
ultimately show "x\<in>I" "x\<in>J" by blast+
next
fix x
assume "x\<in>I" "x\<in>J"
show "x \<in> interval c b"
proof (cases)
assume not_eq: "x\<noteq>a \<and> x\<noteq>b \<and> x\<noteq>c \<and> x\<noteq>d"
have "[a;x;b]" "[c;x;d]"
using \<open>x\<in>I\<close> \<open>I = interval a b\<close> \<open>x\<in>J\<close> \<open>J = interval c d\<close>
not_eq unfolding interval_def segment_def by blast+
hence "[c;x;b]"
by (meson \<open>[a;c;b;d]\<close> abc_bcd_acd betw4_weak)
thus ?thesis
unfolding interval_def segment_def using seg_betw segment_def by auto
next
assume not_not_eq: "\<not>(x\<noteq>a \<and> x\<noteq>b \<and> x\<noteq>c \<and> x\<noteq>d)"
{
assume "x=a"
have "\<not>[d;a;c]"
using \<open>[a;c;b;d]\<close> abcd_dcba_only(9) by blast
hence "a \<notin> interval c d" unfolding interval_def segment_def
using abc_sym \<open>a \<noteq> b \<and> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<and> c \<noteq> d\<close> by blast
hence "False" using \<open>x\<in>J\<close> \<open>J = interval c d\<close> \<open>x=a\<close> by blast
} moreover {
assume "x=d"
have "\<not>[a;d;b]" using \<open>betw4 a c b d\<close> abc_sym abcd_dcba_only(9) by blast
hence "d\<notin>interval a b" unfolding interval_def segment_def
using \<open>a \<noteq> b \<and> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<and> c \<noteq> d\<close> by blast
hence "False" using \<open>x\<in>I\<close> \<open>x=d\<close> \<open>I = interval a b\<close> by blast
}
ultimately show ?thesis
using interval_def not_not_eq by auto
qed
qed
thus "?prop I J" by auto
next
assume "[a;c;d;b]"
have "I\<inter>J = interval c d"
proof (safe)
fix x
assume "x \<in> interval c d"
{
assume "x\<noteq>c \<and> x\<noteq>d"
have "x \<in> J"
by (simp add: \<open>J = interval c d\<close> \<open>x \<in> interval c d\<close>)
have "[c;x;d]"
using \<open>x \<in> interval c d\<close> \<open>x \<noteq> c \<and> x \<noteq> d\<close> interval_def seg_betw by auto
have "[a;x;b]"
by (meson \<open>betw4 a c d b\<close> \<open>[c;x;d]\<close> abc_bcd_abd abc_sym abe_ade_bcd_ace)
have "x \<in> I"
using \<open>I = interval a b\<close> \<open>[a;x;b]\<close> interval_def seg_betw by auto
hence "x\<in>I \<and> x\<in>J" by (simp add: \<open>x \<in> J\<close>)
} moreover {
assume "\<not> (x\<noteq>c \<and> x\<noteq>d)"
hence "x\<in>I \<and> x\<in>J"
by (metis \<open>I = interval a b\<close> \<open>J = interval c d\<close> \<open>[a;c;d;b]\<close> \<open>x \<in> interval c d\<close>
abc_bcd_abd abc_bcd_acd insertI2 interval_def seg_betw)
}
ultimately show "x\<in>I" "x\<in>J" by blast+
next
fix x
assume "x\<in>I" "x\<in>J"
show "x \<in> interval c d"
using \<open>J = interval c d\<close> \<open>x \<in> J\<close> by auto
qed
thus "?prop I J" by auto
qed
}
then show "is_interval (I1\<inter>I2)"
using wlog_interval_endpoints_distinct
[where P="?prop" and I=I1 and J=I2 and Q=P and a=a and b=b and c=c and d=d]
using symmetry assms by simp
qed
lemma int_of_ints_is_interval_deg: (* Proof using WLOG *)
assumes "I = interval a b" "J = interval c d" "I\<inter>J \<noteq> {}" "I\<subseteq>P" "J\<subseteq>P" "P\<in>\<P>"
and events_deg: "\<not>(a\<noteq>b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d \<and> a\<noteq>c \<and> b\<noteq>d)"
shows "is_interval (I \<inter> J)"
proof -
let ?p = "\<lambda> I J. (is_interval (I \<inter> J) \<or> I\<inter>J = {})"
have symmetry: "\<And>I J. \<lbrakk>is_interval I; is_interval J; ?p I J\<rbrakk> \<Longrightarrow> ?p J I"
by (simp add: inf_commute)
have degen_cases: "\<And>I J a b c d Q. \<lbrakk>I = interval a b; J = interval c d; I\<subseteq>Q; J\<subseteq>Q; Q\<in>\<P>\<rbrakk>
\<Longrightarrow> ((a=b \<and> b=c \<and> c=d) \<longrightarrow> ?p I J) \<and> ((a=b \<and> b\<noteq>c \<and> c=d) \<longrightarrow> ?p I J)
\<and> ((a=b \<and> b=c \<and> c\<noteq>d) \<longrightarrow> ?p I J) \<and> ((a=b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d) \<longrightarrow> ?p I J)
\<and> ((a\<noteq>b \<and> b=c \<and> c\<noteq>d \<and> a=d) \<longrightarrow> ?p I J)
\<and> (([a;b;c] \<and> a=d) \<longrightarrow> ?p I J) \<and> (([b;a;c] \<and> a=d) \<longrightarrow> ?p I J)"
proof -
fix I J a b c d Q
assume "I = interval a b" "J = interval c d" "I\<subseteq>Q" "J\<subseteq>Q" "Q\<in>\<P>"
show "((a=b \<and> b=c \<and> c=d) \<longrightarrow> ?p I J) \<and> ((a=b \<and> b\<noteq>c \<and> c=d) \<longrightarrow> ?p I J)
\<and> ((a=b \<and> b=c \<and> c\<noteq>d) \<longrightarrow> ?p I J) \<and> ((a=b \<and> b\<noteq>c \<and> c\<noteq>d \<and> a\<noteq>d) \<longrightarrow> ?p I J)
\<and> ((a\<noteq>b \<and> b=c \<and> c\<noteq>d \<and> a=d) \<longrightarrow> ?p I J)
\<and> (([a;b;c] \<and> a=d) \<longrightarrow> ?p I J) \<and> (([b;a;c] \<and> a=d) \<longrightarrow> ?p I J)"
proof (intro conjI impI)
assume "a = b \<and> b = c \<and> c = d" thus "?p I J"
using \<open>I = interval a b\<close> \<open>J = interval c d\<close> by auto
next
assume "a = b \<and> b \<noteq> c \<and> c = d" thus "?p I J"
using \<open>J = interval c d\<close> empty_segment interval_def by auto
next
assume "a = b \<and> b = c \<and> c \<noteq> d" thus "?p I J"
using \<open>I = interval a b\<close> empty_segment interval_def by auto
next
assume "a = b \<and> b \<noteq> c \<and> c \<noteq> d \<and> a \<noteq> d" thus "?p I J"
using \<open>I = interval a b\<close> empty_segment interval_def by auto
next
assume "a \<noteq> b \<and> b = c \<and> c \<noteq> d \<and> a = d" thus "?p I J"
using \<open>I = interval a b\<close> \<open>J = interval c d\<close> int_sym by auto
next
assume "[a;b;c] \<and> a = d" show "?p I J"
proof (cases)
assume "I\<inter>J = {}" thus ?thesis by simp
next
assume "I\<inter>J \<noteq> {}"
have "I\<inter>J = interval a b"
proof (safe)
fix x assume "x\<in>I" "x\<in>J"
thus "x\<in>interval a b"
using \<open>I = interval a b\<close> by blast
next
fix x assume "x\<in>interval a b"
show "x\<in>I"
by (simp add: \<open>I = interval a b\<close> \<open>x \<in> interval a b\<close>)
have "[d;b;c]"
using \<open>[a;b;c] \<and> a = d\<close> by blast
have "[a;x;b] \<or> x=a \<or> x=b"
using \<open>I = interval a b\<close> \<open>x \<in> I\<close> interval_def seg_betw by auto
consider "[d;x;c]"|"x=a \<or> x=b"
using \<open>[a;b;c] \<and> a = d\<close> \<open>[a;x;b] \<or> x = a \<or> x = b\<close> abc_acd_abd by blast
thus "x\<in>J"
proof (cases)
case 1
then show ?thesis
by (simp add: \<open>J = interval c d\<close> abc_abc_neq abc_sym interval_def seg_betw)
next
case 2
then have "x \<in> interval c d"
using \<open>[a;b;c] \<and> a = d\<close> int_sym interval_def seg_betw
by force
then show ?thesis
using \<open>J = interval c d\<close> by blast
qed
qed
thus "?p I J" by blast
qed
next
assume "[b;a;c] \<and> a = d" show "?p I J"
proof (cases)
assume "I\<inter>J = {}" thus ?thesis by simp
next
assume "I\<inter>J \<noteq> {}"
have "I\<inter>J = {a}"
proof (safe)
fix x assume "x\<in>I" "x\<in>J" "x\<notin>{}"
have cxd: "[c;x;d] \<or> x=c \<or> x=d"
using \<open>J = interval c d\<close> \<open>x \<in> J\<close> interval_def seg_betw by auto
consider "[a;x;b]"|"x=a"|"x=b"
using \<open>I = interval a b\<close> \<open>x \<in> I\<close> interval_def seg_betw by auto
then show "x=a"
proof (cases)
assume "[a;x;b]"
hence "[b;x;d;c]"
using \<open>[b;a;c] \<and> a = d\<close> abc_acd_bcd abc_sym by meson
hence False
using cxd abc_abc_neq by blast
thus ?thesis by simp
next
assume "x=b"
hence "[b;d;c]"
using \<open>[b;a;c] \<and> a = d\<close> by blast
hence False
using cxd \<open>x = b\<close> abc_abc_neq by blast
thus ?thesis
by simp
next
assume "x=a" thus "x=a" by simp
qed
next
show "a\<in>I"
by (simp add: \<open>I = interval a b\<close> ends_in_int)
show "a\<in>J"
by (simp add: \<open>J = interval c d\<close> \<open>[b;a;c] \<and> a = d\<close> ends_in_int)
qed
thus "?p I J"
by (simp add: empty_segment interval_def)
qed
qed
qed
have "?p I J"
using wlog_interval_endpoints_degenerate
[where P="?p" and I=I and J=J and a=a and b=b and c=c and d=d and Q=P]
using degen_cases
using symmetry assms
by smt
thus ?thesis
using assms(3) by blast
qed
lemma int_of_ints_is_interval:
assumes "is_interval I" "is_interval J" "I\<subseteq>P" "J\<subseteq>P" "P\<in>\<P>" "I\<inter>J \<noteq> {}"
shows "is_interval (I \<inter> J)"
using int_of_ints_is_interval_neq int_of_ints_is_interval_deg
by (meson assms)
lemma int_of_ints_is_interval2:
assumes "\<forall>x\<in>S. (is_interval x \<and> x\<subseteq>P)" "P\<in>\<P>" "\<Inter>S \<noteq> {}" "finite S" "S\<noteq>{}"
shows "is_interval (\<Inter>S)"
proof -
obtain n where "n = card S"
by simp
consider "n=0"|"n=1"|"n\<ge>2"
by linarith
thus ?thesis
proof (cases)
assume "n=0"
then have False
using \<open>n = card S\<close> assms(4,5) by simp
thus ?thesis
by simp
next
assume "n=1"
then obtain I where "S = {I}"
using \<open>n = card S\<close> card_1_singletonE by auto
then have "\<Inter>S = I"
by simp
moreover have "is_interval I"
by (simp add: \<open>S = {I}\<close> assms(1))
ultimately show ?thesis
by blast
next
assume "2\<le>n"
obtain m where "m+2=n"
using \<open>2 \<le> n\<close> le_add_diff_inverse2 by blast
have ind: "\<And>S. \<lbrakk>\<forall>x\<in>S. (is_interval x \<and> x\<subseteq>P); P\<in>\<P>; \<Inter>S \<noteq> {}; finite S; S\<noteq>{}; m+2=card S\<rbrakk>
\<Longrightarrow> is_interval (\<Inter>S)"
proof (induct m)
case 0
then have "card S = 2"
by auto
then obtain I J where "S={I,J}" "I\<noteq>J"
by (meson card_2_iff)
then have "I\<in>S" "J\<in>S"
by blast+
then have "is_interval I" "is_interval J" "I\<subseteq>P" "J\<subseteq>P"
by (simp add: "0.prems"(1))+
also have "I\<inter>J \<noteq> {}"
using \<open>S={I,J}\<close> "0.prems"(3) by force
then have "is_interval(I\<inter>J)"
using assms(2) calculation int_of_ints_is_interval[where I=I and J=J and P=P]
by fastforce
then show ?case
by (simp add: \<open>S = {I, J}\<close>)
next
case (Suc m)
obtain S' I where "I\<in>S" "S = insert I S'" "I\<notin>S'"
using Suc.prems(4,5) by (metis Set.set_insert finite.simps insertI1)
then have "is_interval (\<Inter>S')"
proof -
have "m+2 = card S'"
using Suc.prems(4,6) \<open>S = insert I S'\<close> \<open>I\<notin>S'\<close> by auto
moreover have "\<forall>x\<in>S'. is_interval x \<and> x \<subseteq> P"
by (simp add: Suc.prems(1) \<open>S = insert I S'\<close>)
moreover have "\<Inter> S' \<noteq> {}"
using Suc.prems(3) \<open>S = insert I S'\<close> by auto
moreover have "finite S'"
using Suc.prems(4) \<open>S = insert I S'\<close> by auto
ultimately show ?thesis
using assms(2) Suc(1) [where S=S'] by fastforce
qed
then have "is_interval ((\<Inter>S')\<inter>I)"
proof (rule int_of_ints_is_interval)
show "is_interval I"
by (simp add: Suc.prems(1) \<open>I \<in> S\<close>)
show "\<Inter>S' \<subseteq> P"
using \<open>I \<notin> S'\<close> \<open>S = insert I S'\<close> Suc.prems(1,4,6) Inter_subset
by (metis Suc_n_not_le_n card.empty card_insert_disjoint finite_insert
le_add2 numeral_2_eq_2 subset_eq subset_insertI)
show "I \<subseteq> P"
by (simp add: Suc.prems(1) \<open>I \<in> S\<close>)
show "P \<in> \<P>"
using assms(2) by auto
show "\<Inter>S' \<inter> I \<noteq> {}"
using Suc.prems(3) \<open>S = insert I S'\<close> by auto
qed
thus ?case
using \<open>S = insert I S'\<close> by (simp add: inf.commute)
qed
then show ?thesis
using \<open>m + 2 = n\<close> \<open>n = card S\<close> assms by blast
qed
qed
end (*context MinkowskiSpacetime*)
section "3.7 Continuity and the monotonic sequence property"
context MinkowskiSpacetime begin
text \<open>
This section only includes a proof of the first part of Theorem 12, as well as some results
that would be useful in proving part (ii).
\<close>
theorem (*12(i)*) two_rays:
assumes path_Q: "Q\<in>\<P>"
and event_a: "a\<in>Q"
shows "\<exists>R L. (is_ray_on R Q \<and> is_ray_on L Q
\<and> Q-{a} \<subseteq> (R \<union> L) \<^cancel>\<open>events of Q excl. a belong to two rays\<close>
\<and> (\<forall>r\<in>R. \<forall>l\<in>L. [l;a;r]) \<^cancel>\<open>a is betw any 'a of one ray and any 'a of the other\<close>
\<and> (\<forall>x\<in>R. \<forall>y\<in>R. \<not> [x;a;y]) \<^cancel>\<open>but a is not betw any two events \<dots>\<close>
\<and> (\<forall>x\<in>L. \<forall>y\<in>L. \<not> [x;a;y]))" \<^cancel>\<open>\<dots> of the same ray\<close>
proof -
text \<open>Schutz here uses Theorem 6, but we don't need it.\<close>
obtain b where "b\<in>\<E>" and "b\<in>Q" and "b\<noteq>a"
using event_a ge2_events in_path_event path_Q by blast
let ?L = "{x. [x;a;b]}"
let ?R = "{y. [a;y;b] \<or> [a;b;y\<rbrakk>}"
have "Q = ?L \<union> {a} \<union> ?R"
proof -
have inQ: "\<forall>x\<in>Q. [x;a;b] \<or> x=a \<or> [a;x;b] \<or> [a;b;x\<rbrakk>"
by (meson \<open>b \<in> Q\<close> \<open>b \<noteq> a\<close> abc_sym event_a path_Q some_betw)
show ?thesis
proof (safe)
fix x
assume "x \<in> Q" "x \<noteq> a" "\<not> [x;a;b]" "\<not> [a;x;b]" "b \<noteq> x"
then show "[a;b;x]"
using inQ by blast
next
fix x
assume "[x;a;b]"
then show "x \<in> Q"
by (simp add: \<open>b \<in> Q\<close> abc_abc_neq betw_a_in_path event_a path_Q)
next
show "a \<in> Q"
by (simp add: event_a)
next
fix x
assume "[a;x;b]"
then show "x \<in> Q"
by (simp add: \<open>b \<in> Q\<close> abc_abc_neq betw_b_in_path event_a path_Q)
next
fix x
assume "[a;b;x]"
then show "x \<in> Q"
by (simp add: \<open>b \<in> Q\<close> abc_abc_neq betw_c_in_path event_a path_Q)
next
show "b \<in> Q" using \<open>b \<in> Q\<close> .
qed
qed
have disjointLR: "?L \<inter> ?R = {}"
using abc_abc_neq abc_only_cba by blast
have wxyz_ord: "[x;a;y;b\<rbrakk> \<or> [x;a;b;y\<rbrakk>
\<and> (([w;x;a] \<and> [x;a;y]) \<or> ([x;w;a] \<and> [w;a;y]))
\<and> (([x;a;y] \<and> [a;y;z]) \<or> ([x;a;z] \<and> [a;z;y]))"
if "x\<in>?L" "w\<in>?L" "y\<in>?R" "z\<in>?R" "w\<noteq>x" "y\<noteq>z" for x w y z
using path_finsubset_chain order_finite_chain (* Schutz says: implied by thm 10 & 2 *)
by (smt abc_abd_bcdbdc abc_bcd_abd abc_sym abd_bcd_abc mem_Collect_eq that) (* impressive, sledgehammer! *)
obtain x y where "x\<in>?L" "y\<in>?R"
by (metis (mono_tags) \<open>b \<in> Q\<close> \<open>b \<noteq> a\<close> abc_sym event_a mem_Collect_eq path_Q prolong_betw2)
obtain w where "w\<in>?L" "w\<noteq>x"
by (metis \<open>b \<in> Q\<close> \<open>b \<noteq> a\<close> abc_sym event_a mem_Collect_eq path_Q prolong_betw3)
obtain z where "z\<in>?R" "y\<noteq>z"
by (metis (mono_tags) \<open>b \<in> Q\<close> \<open>b \<noteq> a\<close> event_a mem_Collect_eq path_Q prolong_betw3)
have "is_ray_on ?R Q \<and>
is_ray_on ?L Q \<and>
Q - {a} \<subseteq> ?R \<union> ?L \<and>
(\<forall>r\<in>?R. \<forall>l\<in>?L. [l;a;r]) \<and>
(\<forall>x\<in>?R. \<forall>y\<in>?R. \<not> [x;a;y]) \<and>
(\<forall>x\<in>?L. \<forall>y\<in>?L. \<not> [x;a;y])"
proof (intro conjI)
show "is_ray_on ?L Q"
proof (unfold is_ray_on_def, safe)
show "Q \<in> \<P>"
by (simp add: path_Q)
next
fix x
assume "[x;a;b]"
then show "x \<in> Q"
using \<open>b \<in> Q\<close> \<open>b \<noteq> a\<close> betw_a_in_path event_a path_Q by blast
next
show "is_ray {x. [x;a;b]}"
proof -
have "[x;a;b]"
using \<open>x\<in>?L\<close> by simp
have "?L = ray a x"
proof
show "ray a x \<subseteq> ?L"
proof
fix e assume "e\<in>ray a x"
show "e\<in>?L"
using wxyz_ord ray_cases abc_bcd_abd abd_bcd_abc abc_sym
by (metis \<open>[x;a;b]\<close> \<open>e \<in> ray a x\<close> mem_Collect_eq)
qed
show "?L \<subseteq> ray a x"
proof
fix e assume "e\<in>?L"
hence "[e;a;b]"
by simp
show "e\<in>ray a x"
proof (cases)
assume "e=x"
thus ?thesis
by (simp add: ray_def)
next
assume "e\<noteq>x"
hence "[e;x;a] \<or> [x;e;a]" using wxyz_ord
by (meson \<open>[e;a;b]\<close> \<open>[x;a;b]\<close> abc_abd_bcdbdc abc_sym)
thus "e\<in>ray a x"
by (metis Un_iff abc_sym insertCI pro_betw ray_def seg_betw)
qed
qed
qed
thus "is_ray ?L" by auto
qed
qed
show "is_ray_on ?R Q"
proof (unfold is_ray_on_def, safe)
show "Q \<in> \<P>"
by (simp add: path_Q)
next
fix x
assume "[a;x;b]"
then show "x \<in> Q"
by (simp add: \<open>b \<in> Q\<close> abc_abc_neq betw_b_in_path event_a path_Q)
next
fix x
assume "[a;b;x]"
then show "x \<in> Q"
by (simp add: \<open>b \<in> Q\<close> abc_abc_neq betw_c_in_path event_a path_Q)
next
show "b \<in> Q" using \<open>b \<in> Q\<close> .
next
show "is_ray {y. [a;y;b] \<or> [a;b;y\<rbrakk>}"
proof -
have "[a;y;b] \<or> [a;b;y] \<or> y=b"
using \<open>y\<in>?R\<close> by blast
have "?R = ray a y"
proof
show "ray a y \<subseteq> ?R"
proof
fix e assume "e\<in>ray a y"
hence "[a;e;y] \<or> [a;y;e] \<or> y=e"
using ray_cases by auto
show "e\<in>?R"
proof -
{ assume "e \<noteq> b"
have "(e \<noteq> y \<and> e \<noteq> b) \<and> [w;a;y] \<or> [a;e;b] \<or> [a;b;e\<rbrakk>"
using \<open>[a;y;b] \<or> [a;b;y] \<or> y = b\<close> \<open>w \<in> {x. [x;a;b]}\<close> abd_bcd_abc by blast
hence "[a;e;b] \<or> [a;b;e\<rbrakk>"
using abc_abd_bcdbdc abc_bcd_abd abd_bcd_abc
by (metis \<open>[a;e;y] \<or> [a;y;e\<rbrakk>\<close> \<open>w \<in> ?L\<close> mem_Collect_eq)
}
thus ?thesis
by blast
qed
qed
show "?R \<subseteq> ray a y"
proof
fix e assume "e\<in>?R"
hence aeb_cases: "[a;e;b] \<or> [a;b;e] \<or> e=b"
by blast
hence aey_cases: "[a;e;y] \<or> [a;y;e] \<or> e=y"
using abc_abd_bcdbdc abc_bcd_abd abd_bcd_abc
by (metis \<open>[a;y;b] \<or> [a;b;y] \<or> y = b\<close> \<open>x \<in> {x. [x;a;b]}\<close> mem_Collect_eq)
show "e\<in>ray a y"
proof -
{
assume "e=b"
hence ?thesis
using \<open>[a;y;b] \<or> [a;b;y] \<or> y = b\<close> \<open>b \<noteq> a\<close> pro_betw ray_def seg_betw by auto
} moreover {
assume "[a;e;b] \<or> [a;b;e]"
assume "y\<noteq>e"
hence "[a;e;y] \<or> [a;y;e]"
using aey_cases by auto
hence "e\<in>ray a y"
unfolding ray_def using abc_abc_neq pro_betw seg_betw by auto
} moreover {
assume "[a;e;b] \<or> [a;b;e]"
assume "y=e"
have "e\<in>ray a y"
unfolding ray_def by (simp add: \<open>y = e\<close>)
}
ultimately show ?thesis
using aeb_cases by blast
qed
qed
qed
thus "is_ray ?R" by auto
qed
qed
show "(\<forall>r\<in>?R. \<forall>l\<in>?L. [l;a;r])"
using abd_bcd_abc by blast
show "\<forall>x\<in>?R. \<forall>y\<in>?R. \<not> [x;a;y]"
by (smt abc_ac_neq abc_bcd_abd abd_bcd_abc mem_Collect_eq)
show "\<forall>x\<in>?L. \<forall>y\<in>?L. \<not> [x;a;y]"
using abc_abc_neq abc_abd_bcdbdc abc_only_cba by blast
show "Q-{a} \<subseteq> ?R \<union> ?L"
using \<open>Q = {x. [x;a;b]} \<union> {a} \<union> {y. [a;y;b] \<or> [a;b;y\<rbrakk>}\<close> by blast
qed
thus ?thesis
by (metis (mono_tags, lifting))
qed
text \<open>
The definition \<open>closest_to\<close> in prose:
Pick any $r \in R$. The closest event $c$ is such that there is no closer event in $L$,
i.e. all other events of $L$ are further away from $r$.
Thus in $L$, $c$ is the element closest to $R$.
\<close>
definition closest_to :: "('a set) \<Rightarrow> 'a \<Rightarrow> ('a set) \<Rightarrow> bool"
where "closest_to L c R \<equiv> c\<in>L \<and> (\<forall>r\<in>R. \<forall>l\<in>L-{c}. [l;c;r])"
lemma int_on_path:
assumes "l\<in>L" "r\<in>R" "Q\<in>\<P>"
and partition: "L\<subseteq>Q" "L\<noteq>{}" "R\<subseteq>Q" "R\<noteq>{}" "L\<union>R=Q"
shows "interval l r \<subseteq> Q"
proof
fix x assume "x\<in>interval l r"
thus "x\<in>Q"
unfolding interval_def segment_def
using betw_b_in_path partition(5) \<open>Q\<in>\<P>\<close> seg_betw \<open>l \<in> L\<close> \<open>r \<in> R\<close>
by blast
qed
lemma ray_of_bounds1:
assumes "Q\<in>\<P>" "[f\<leadsto>X|(f 0)..]" "X\<subseteq>Q" "closest_bound c X" "is_bound_f b X f" "b\<noteq>c"
assumes "is_bound_f x X f"
shows "x=b \<or> x=c \<or> [c;x;b] \<or> [c;b;x]"
proof -
have "x\<in>Q"
using bound_on_path assms(1,3,7) unfolding all_bounds_def is_bound_def is_bound_f_def
by auto
{
assume "x=b"
hence ?thesis by blast
} moreover {
assume "x=c"
hence ?thesis by blast
} moreover {
assume "x\<noteq>b" "x\<noteq>c"
hence ?thesis
by (meson abc_abd_bcdbdc assms(4,5,6,7) closest_bound_def is_bound_def)
}
ultimately show ?thesis by blast
qed
lemma ray_of_bounds2:
assumes "Q\<in>\<P>" "[f\<leadsto>X|(f 0)..]" "X\<subseteq>Q" "closest_bound_f c X f" "is_bound_f b X f" "b\<noteq>c"
assumes "x=b \<or> x=c \<or> [c;x;b] \<or> [c;b;x]"
shows "is_bound_f x X f"
proof -
have "x\<in>Q"
using assms(1,3,4,5,6,7) betw_b_in_path betw_c_in_path bound_on_path
using closest_bound_f_def is_bound_f_def by metis
{
assume "x=b"
hence ?thesis
by (simp add: assms(5))
} moreover {
assume "x=c"
hence ?thesis using assms(4)
by (simp add: closest_bound_f_def)
} moreover {
assume "[c;x;b]"
hence ?thesis unfolding is_bound_f_def
proof (safe)
fix i j::nat
show "[f\<leadsto>X|f 0..]"
by (simp add: assms(2))
assume "i<j"
hence "[f i; f j; b]"
using assms(5) is_bound_f_def by blast
hence "[f j; b; c] \<or> [f j; c; b]"
using \<open>i < j\<close> abc_abd_bcdbdc assms(4,6) closest_bound_f_def is_bound_f_def by auto
thus "[f i; f j; x]"
by (meson \<open>[c;x;b]\<close> \<open>[f i; f j; b]\<close> abc_bcd_acd abc_sym abd_bcd_abc)
qed
} moreover {
assume "[c;b;x]"
hence ?thesis unfolding is_bound_f_def
proof (safe)
fix i j::nat
show "[f\<leadsto>X|f 0..]"
by (simp add: assms(2))
assume "i<j"
hence "[f i; f j; b]"
using assms(5) is_bound_f_def by blast
hence "[f j; b; c] \<or> [f j; c; b]"
using \<open>i < j\<close> abc_abd_bcdbdc assms(4,6) closest_bound_f_def is_bound_f_def by auto
thus "[f i; f j; x]"
proof -
have "(c = b) \<or> [f 0; c; b]"
using assms(4,5) closest_bound_f_def is_bound_def by auto
hence "[f j; b; c] \<longrightarrow> [x; f j; f i]"
by (metis abc_bcd_acd abc_only_cba(2) assms(5) is_bound_f_def neq0_conv)
thus ?thesis
using \<open>[c;b;x]\<close> \<open>[f i; f j; b]\<close> \<open>[f j; b; c] \<or> [f j; c; b]\<close> abc_bcd_acd abc_sym
by blast
qed
qed
}
ultimately show ?thesis using assms(7) by blast
qed
lemma ray_of_bounds3:
assumes "Q\<in>\<P>" "[f\<leadsto>X|(f 0)..]" "X\<subseteq>Q" "closest_bound_f c X f" "is_bound_f b X f" "b\<noteq>c"
shows "all_bounds X = insert c (ray c b)"
proof
let ?B = "all_bounds X"
let ?C = "insert c (ray c b)"
show "?B \<subseteq> ?C"
proof
fix x assume "x\<in>?B"
hence "is_bound x X"
by (simp add: all_bounds_def)
hence "x=b \<or> x=c \<or> [c;x;b] \<or> [c;b;x]"
using ray_of_bounds1 abc_abd_bcdbdc assms(4,5,6)
by (meson closest_bound_f_def is_bound_def)
thus "x\<in>?C"
using pro_betw ray_def seg_betw by auto
qed
show "?C \<subseteq> ?B"
proof
fix x assume "x\<in>?C"
hence "x=b \<or> x=c \<or> [c;x;b] \<or> [c;b;x]"
using pro_betw ray_def seg_betw by auto
hence "is_bound x X"
unfolding is_bound_def using ray_of_bounds2 assms
by blast
thus "x\<in>?B"
by (simp add: all_bounds_def)
qed
qed
lemma int_in_closed_ray:
assumes "path ab a b"
shows "interval a b \<subset> insert a (ray a b)"
proof
let ?i = "interval a b"
show "interval a b \<noteq> insert a (ray a b)"
proof -
obtain c where "[a;b;c]" using prolong_betw2
using assms by blast
hence "c\<in>ray a b"
using abc_abc_neq pro_betw ray_def by auto
have "c\<notin>interval a b"
using \<open>[a;b;c]\<close> abc_abc_neq abc_only_cba(2) interval_def seg_betw by auto
thus ?thesis
using \<open>c \<in> ray a b\<close> by blast
qed
show "interval a b \<subseteq> insert a (ray a b)"
using interval_def ray_def by auto
qed
end (* context MinkowskiSpacetime *)
section "3.8 Connectedness of the unreachable set"
context MinkowskiSpacetime begin
subsection \<open>Theorem 13 (Connectedness of the Unreachable Set)\<close>
theorem (*13*) unreach_connected:
assumes path_Q: "Q\<in>\<P>"
and event_b: "b\<notin>Q" "b\<in>\<E>"
and unreach: "Q\<^sub>x \<in> unreach-on Q from b" "Q\<^sub>z \<in> unreach-on Q from b"
and xyz: "[Q\<^sub>x; Q\<^sub>y; Q\<^sub>z]"
shows "Q\<^sub>y \<in> unreach-on Q from b"
proof -
have xz: "Q\<^sub>x \<noteq> Q\<^sub>z" using abc_ac_neq xyz by blast
text \<open>First we obtain the chain from @{thm I6}.\<close>
have in_Q: "Q\<^sub>x\<in>Q \<and> Q\<^sub>y\<in>Q \<and> Q\<^sub>z\<in>Q"
using betw_b_in_path path_Q unreach(1,2) xz unreach_on_path xyz by blast
hence event_y: "Q\<^sub>y\<in>\<E>"
using in_path_event path_Q by blast
text\<open>legacy: @{thm I6_old} instead of @{thm I6}\<close>
obtain X f where X_def: "ch_by_ord f X" "f 0 = Q\<^sub>x" "f (card X - 1) = Q\<^sub>z"
"(\<forall>i\<in>{1 .. card X - 1}. (f i) \<in> unreach-on Q from b \<and> (\<forall>Qy\<in>\<E>. [f (i - 1); Qy; f i] \<longrightarrow> Qy \<in> unreach-on Q from b))"
"short_ch X \<longrightarrow> Q\<^sub>x \<in> X \<and> Q\<^sub>z \<in> X \<and> (\<forall>Q\<^sub>y\<in>\<E>. [Q\<^sub>x; Q\<^sub>y; Q\<^sub>z] \<longrightarrow> Q\<^sub>y \<in> unreach-on Q from b)"
using I6_old [OF assms(1-5) xz] by blast
hence fin_X: "finite X"
using xz not_less by fastforce
obtain N where "N=card X" "N\<ge>2"
using X_def(2,3) xz by fastforce
text \<open>
Then we have to manually show the bounds, defined via indices only, are in the obtained chain.
\<close>
let ?a = "f 0"
let ?d = "f (card X - 1)"
{
assume "card X = 2"
hence "short_ch X" "?a \<in> X \<and> ?d \<in> X" "?a \<noteq> ?d"
using X_def \<open>card X = 2\<close> short_ch_card_2 xz by blast+
}
hence "[f\<leadsto>X|Q\<^sub>x..Q\<^sub>z]"
using chain_defs by (metis X_def(1-3) fin_X)
text \<open>
Further on, we split the proof into two cases, namely the split Schutz absorbs into his
non-strict \<^term>\<open>local_ordering\<close>. Just below is the statement we use @{thm disjE} with.\<close>
have y_cases: "Q\<^sub>y\<in>X \<or> Q\<^sub>y\<notin>X" by blast
have y_int: "Q\<^sub>y\<in>interval Q\<^sub>x Q\<^sub>z"
using interval_def seg_betw xyz by auto
have X_in_Q: "X\<subseteq>Q"
using chain_on_path_I6 [where Q=Q and X=X] X_def event_b path_Q unreach xz \<open>[f\<leadsto>X|Q\<^sub>x .. Q\<^sub>z]\<close> by blast
show ?thesis
proof (cases)
text \<open>We treat short chains separately.
(Legacy: they used to have a separate clause in @{thm I6}, now @{thm I6_old})\<close>
assume "N=2"
thus ?thesis
using X_def(1,5) xyz \<open>N = card X\<close> event_y short_ch_card_2 by auto
next
text \<open>
This is where Schutz obtains the chain from Theorem 11. We instead use the chain we already have
with only a part of Theorem 11, namely @{thm int_split_to_segs}.
\<open>?S\<close> is defined like in @{thm segmentation}.\<close>
assume "N\<noteq>2"
hence "N\<ge>3" using \<open>2 \<le> N\<close> by auto
have "2\<le>card X" using \<open>2 \<le> N\<close> \<open>N = card X\<close> by blast
show ?thesis using y_cases
proof (rule disjE)
assume "Q\<^sub>y\<in>X"
then obtain i where i_def: "i<card X" "Q\<^sub>y = f i"
using X_def(1) by (metis fin_X obtain_index_fin_chain)
have "i\<noteq>0 \<and> i\<noteq>card X - 1"
using X_def(2,3)
by (metis abc_abc_neq i_def(2) xyz)
hence "i\<in>{1..card X -1}"
using i_def(1) by fastforce
thus ?thesis using X_def(4) i_def(2) by metis
next
assume "Q\<^sub>y\<notin>X"
let ?S = "if card X = 2 then {segment ?a ?d} else {segment (f i) (f(i+1)) | i. i<card X - 1}"
have "Q\<^sub>y\<in>\<Union>?S"
proof -
obtain c where "[f\<leadsto>X|Q\<^sub>x..c..Q\<^sub>z]"
using X_def(1) \<open>N = card X\<close> \<open>N\<noteq>2\<close> \<open>[f\<leadsto>X|Q\<^sub>x..Q\<^sub>z]\<close> short_ch_card_2
by (metis \<open>2 \<le> N\<close> le_neq_implies_less long_chain_2_imp_3)
have "interval Q\<^sub>x Q\<^sub>z = \<Union>?S \<union> X"
using int_split_to_segs [OF \<open>[f\<leadsto>X|Q\<^sub>x..c..Q\<^sub>z]\<close>] by auto
thus ?thesis
using \<open>Q\<^sub>y\<notin>X\<close> y_int by blast
qed
then obtain s where "s\<in>?S" "Q\<^sub>y\<in>s" by blast
have "\<exists>i. i\<in>{1..(card X)-1} \<and> [(f(i-1)); Q\<^sub>y; f i]"
proof -
obtain i' where i'_def: "i' < N-1" "s = segment (f i') (f (i' + 1))"
using \<open>Q\<^sub>y\<in>s\<close> \<open>s\<in>?S\<close> \<open>N=card X\<close>
by (smt \<open>2 \<le> N\<close> \<open>N \<noteq> 2\<close> le_antisym mem_Collect_eq not_less)
show ?thesis
proof (rule exI, rule conjI)
show "(i'+1) \<in> {1..card X - 1}"
using i'_def(1)
by (simp add: \<open>N = card X\<close>)
show "[f((i'+1) - 1); Q\<^sub>y; f(i'+1)]"
using i'_def(2) \<open>Q\<^sub>y\<in>s\<close> seg_betw by simp
qed
qed
then obtain i where i_def: "i\<in>{1..(card X)-1}" "[(f(i-1)); Q\<^sub>y; f i]"
by blast
show ?thesis
by (meson X_def(4) i_def event_y)
qed
qed
qed
subsection \<open>Theorem 14 (Second Existence Theorem)\<close>
lemma (*for 14i*) union_of_bounded_sets_is_bounded:
assumes "\<forall>x\<in>A. [a;x;b]" "\<forall>x\<in>B. [c;x;d]" "A\<subseteq>Q" "B\<subseteq>Q" "Q\<in>\<P>"
"card A > 1 \<or> infinite A" "card B > 1 \<or> infinite B"
shows "\<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>A\<union>B. [l;x;u]"
proof -
let ?P = "\<lambda> A B. \<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>A\<union>B. [l;x;u]"
let ?I = "\<lambda> A a b. (card A > 1 \<or> infinite A) \<and> (\<forall>x\<in>A. [a;x;b])"
let ?R = "\<lambda>A. \<exists>a b. ?I A a b"
have on_path: "\<And>a b A. A \<subseteq> Q \<Longrightarrow> ?I A a b \<Longrightarrow> b \<in> Q \<and> a \<in> Q"
proof -
fix a b A assume "A\<subseteq>Q" "?I A a b"
show "b\<in>Q\<and>a\<in>Q"
proof (cases)
assume "card A \<le> 1 \<and> finite A"
thus ?thesis
using \<open>?I A a b\<close> by auto
next
assume "\<not> (card A \<le> 1 \<and> finite A)"
hence asmA: "card A > 1 \<or> infinite A"
by linarith
then obtain x y where "x\<in>A" "y\<in>A" "x\<noteq>y"
proof
assume "1 < card A" "\<And>x y. \<lbrakk>x \<in> A; y \<in> A; x \<noteq> y\<rbrakk> \<Longrightarrow> thesis"
then show ?thesis
by (metis One_nat_def Suc_le_eq card_le_Suc_iff insert_iff)
next
assume "infinite A" "\<And>x y. \<lbrakk>x \<in> A; y \<in> A; x \<noteq> y\<rbrakk> \<Longrightarrow> thesis"
then show ?thesis
using infinite_imp_nonempty by (metis finite_insert finite_subset singletonI subsetI)
qed
have "x\<in>Q" "y\<in>Q"
using \<open>A \<subseteq> Q\<close> \<open>x \<in> A\<close> \<open>y \<in> A\<close> by auto
have "[a;x;b]" "[a;y;b]"
by (simp add: \<open>(1 < card A \<or> infinite A) \<and> (\<forall>x\<in>A. [a;x;b])\<close> \<open>x \<in> A\<close> \<open>y \<in> A\<close>)+
hence "betw4 a x y b \<or> betw4 a y x b"
using \<open>x \<noteq> y\<close> abd_acd_abcdacbd by blast
hence "a\<in>Q \<and> b\<in>Q"
using \<open>Q\<in>\<P>\<close> \<open>x\<in>Q\<close> \<open>x\<noteq>y\<close> \<open>x\<in>Q\<close> \<open>y\<in>Q\<close> betw_a_in_path betw_c_in_path by blast
thus ?thesis by simp
qed
qed
show ?thesis
proof (cases)
assume "a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d"
show "?P A B"
proof (rule_tac P="?P" and A=Q in wlog_endpoints_distinct)
text \<open>First, some technicalities: the relations $P, I, R$ have the symmetry required.\<close>
show "\<And>a b I. ?I I a b \<Longrightarrow> ?I I b a" using abc_sym by blast
show "\<And>a b A. A \<subseteq> Q \<Longrightarrow> ?I A a b \<Longrightarrow> b \<in> Q \<and> a \<in> Q" using on_path assms(5) by blast
show "\<And>I J. ?R I \<Longrightarrow> ?R J \<Longrightarrow> ?P I J \<Longrightarrow> ?P J I" by (simp add: Un_commute)
text \<open>Next, the lemma/case assumptions have to be repeated for Isabelle.\<close>
show "?I A a b" "?I B c d" "A\<subseteq>Q" "B\<subseteq>Q" "Q\<in>\<P>"
using assms by simp+
show "a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d"
using \<open>a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d\<close> by simp
text \<open>Finally, the important bit: proofs for the necessary cases of betweenness.\<close>
show "?P I J"
if "?I I a b" "?I J c d" "I\<subseteq>Q" "J\<subseteq>Q"
and "[a;b;c;d] \<or> [a;c;b;d] \<or> [a;c;d;b]"
for I J a b c d
proof -
consider "[a;b;c;d]"|"[a;c;b;d]"|"[a;c;d;b]"
using \<open>[a;b;c;d] \<or> [a;c;b;d] \<or> [a;c;d;b]\<close> by fastforce
thus ?thesis
proof (cases)
assume asm: "[a;b;c;d]" show "?P I J"
proof -
have "\<forall>x\<in> I\<union>J. [a;x;d]"
by (metis Un_iff asm betw4_strong betw4_weak that(1) that(2))
moreover have "a\<in>Q" "d\<in>Q"
using assms(5) on_path that(1-4) by blast+
ultimately show ?thesis by blast
qed
next
assume "[a;c;b;d]" show "?P I J"
proof -
have "\<forall>x\<in> I\<union>J. [a;x;d]"
by (metis Un_iff \<open>betw4 a c b d\<close> abc_bcd_abd abc_bcd_acd betw4_weak that(1,2))
moreover have "a\<in>Q" "d\<in>Q"
using assms(5) on_path that(1-4) by blast+
ultimately show ?thesis by blast
qed
next
assume "[a;c;d;b]" show "?P I J"
proof -
have "\<forall>x\<in> I\<union>J. [a;x;b]"
using \<open>betw4 a c d b\<close> abc_bcd_abd abc_bcd_acd abe_ade_bcd_ace
by (meson UnE that(1,2))
moreover have "a\<in>Q" "b\<in>Q"
using assms(5) on_path that(1-4) by blast+
ultimately show ?thesis by blast
qed
qed
qed
qed
next
assume "\<not>(a\<noteq>b \<and> a\<noteq>c \<and> a\<noteq>d \<and> b\<noteq>c \<and> b\<noteq>d \<and> c\<noteq>d)"
show "?P A B"
proof (rule_tac P="?P" and A=Q in wlog_endpoints_degenerate)
text \<open>
This case follows the same pattern as above: the next five \<open>show\<close> statements
are effectively bookkeeping.\<close>
show "\<And>a b I. ?I I a b \<Longrightarrow> ?I I b a" using abc_sym by blast
show "\<And>a b A. A \<subseteq> Q \<Longrightarrow> ?I A a b \<Longrightarrow> b \<in> Q \<and> a \<in> Q" using on_path \<open>Q\<in>\<P>\<close> by blast
show "\<And>I J. ?R I \<Longrightarrow> ?R J \<Longrightarrow> ?P I J \<Longrightarrow> ?P J I" by (simp add: Un_commute)
show "?I A a b" "?I B c d" "A\<subseteq>Q" "B\<subseteq>Q" "Q\<in>\<P>"
using assms by simp+
show "\<not> (a \<noteq> b \<and> b \<noteq> c \<and> c \<noteq> d \<and> a \<noteq> d \<and> a \<noteq> c \<and> b \<noteq> d)"
using \<open>\<not> (a \<noteq> b \<and> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<and> c \<noteq> d)\<close> by blast
text \<open>Again, this is the important bit: proofs for the necessary cases of degeneracy.\<close>
show "(a = b \<and> b = c \<and> c = d \<longrightarrow> ?P I J) \<and> (a = b \<and> b \<noteq> c \<and> c = d \<longrightarrow> ?P I J) \<and>
(a = b \<and> b = c \<and> c \<noteq> d \<longrightarrow> ?P I J) \<and> (a = b \<and> b \<noteq> c \<and> c \<noteq> d \<and> a \<noteq> d \<longrightarrow> ?P I J) \<and>
(a \<noteq> b \<and> b = c \<and> c \<noteq> d \<and> a = d \<longrightarrow> ?P I J) \<and>
([a;b;c] \<and> a = d \<longrightarrow> ?P I J) \<and> ([b;a;c] \<and> a = d \<longrightarrow> ?P I J)"
if "?I I a b" "?I J c d" "I \<subseteq> Q" "J \<subseteq> Q"
for I J a b c d
proof (intro conjI impI)
assume "a = b \<and> b = c \<and> c = d"
show "\<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>I \<union> J. [l;x;u]"
using \<open>a = b \<and> b = c \<and> c = d\<close> abc_ac_neq assms(5) ex_crossing_path that(1,2)
by fastforce
next
assume "a = b \<and> b \<noteq> c \<and> c = d"
show "\<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>I \<union> J. [l;x;u]"
using \<open>a = b \<and> b \<noteq> c \<and> c = d\<close> abc_ac_neq assms(5) ex_crossing_path that(1,2)
by (metis Un_iff)
next
assume "a = b \<and> b = c \<and> c \<noteq> d"
hence "\<forall>x\<in> I\<union>J. [c;x;d]"
using abc_abc_neq that(1,2) by fastforce
moreover have "c\<in>Q" "d\<in>Q"
using on_path \<open>a = b \<and> b = c \<and> c \<noteq> d\<close> that(1,3) abc_abc_neq by metis+
ultimately show "\<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>I \<union> J. [l;x;u]" by blast
next
assume "a = b \<and> b \<noteq> c \<and> c \<noteq> d \<and> a \<noteq> d"
hence "\<forall>x\<in> I\<union>J. [c;x;d]"
using abc_abc_neq that(1,2) by fastforce
moreover have "c\<in>Q" "d\<in>Q"
using on_path \<open>a = b \<and> b \<noteq> c \<and> c \<noteq> d \<and> a \<noteq> d\<close> that(1,3) abc_abc_neq by metis+
ultimately show "\<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>I \<union> J. [l;x;u]" by blast
next
assume "a \<noteq> b \<and> b = c \<and> c \<noteq> d \<and> a = d"
hence "\<forall>x\<in> I\<union>J. [c;x;d]"
using abc_sym that(1,2) by auto
moreover have "c\<in>Q" "d\<in>Q"
using on_path \<open>a \<noteq> b \<and> b = c \<and> c \<noteq> d \<and> a = d\<close> that(1,3) abc_abc_neq by metis+
ultimately show "\<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>I \<union> J. [l;x;u]" by blast
next
assume "[a;b;c] \<and> a = d"
hence "\<forall>x\<in> I\<union>J. [c;x;d]"
by (metis UnE abc_acd_abd abc_sym that(1,2))
moreover have "c\<in>Q" "d\<in>Q"
using on_path that(2,4) by blast+
ultimately show "\<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>I \<union> J. [l;x;u]" by blast
next
assume "[b;a;c] \<and> a = d"
hence "\<forall>x\<in> I\<union>J. [c;x;b]"
using abc_sym abd_bcd_abc betw4_strong that(1,2) by (metis Un_iff)
moreover have "c\<in>Q" "b\<in>Q"
using on_path that by blast+
ultimately show "\<exists>l\<in>Q. \<exists>u\<in>Q. \<forall>x\<in>I \<union> J. [l;x;u]" by blast
qed
qed
qed
qed
lemma (*for 14i*) union_of_bounded_sets_is_bounded2:
assumes "\<forall>x\<in>A. [a;x;b]" "\<forall>x\<in>B. [c;x;d]" "A\<subseteq>Q" "B\<subseteq>Q" "Q\<in>\<P>"
"1<card A \<or> infinite A" "1<card B \<or> infinite B"
shows "\<exists>l\<in>Q-(A\<union>B). \<exists>u\<in>Q-(A\<union>B). \<forall>x\<in>A\<union>B. [l;x;u]"
using assms union_of_bounded_sets_is_bounded
[where A=A and a=a and b=b and B=B and c=c and d=d and Q=Q]
by (metis Diff_iff abc_abc_neq)
text \<open>
Schutz proves a mildly stronger version of this theorem than he states. Namely, he gives an
additional condition that has to be fulfilled by the bounds $y,z$ in the proof (\<open>y,z\<notin>unreach-on Q from ab\<close>).
This condition is trivial given \<open>abc_abc_neq\<close>. His stating it in the proof makes me wonder
whether his (strictly speaking) undefined notion of bounded set is somehow weaker than the
version using strict betweenness in his theorem statement and used here in Isabelle.
This would make sense, given the obvious analogy with sets on the real line.
\<close>
theorem (*14i*) second_existence_thm_1:
assumes path_Q: "Q\<in>\<P>"
and events: "a\<notin>Q" "b\<notin>Q"
and reachable: "path_ex a q1" "path_ex b q2" "q1\<in>Q" "q2\<in>Q"
shows "\<exists>y\<in>Q. \<exists>z\<in>Q. (\<forall>x\<in>unreach-on Q from a. [y;x;z]) \<and> (\<forall>x\<in>unreach-on Q from b. [y;x;z])"
proof -
text \<open>Slightly annoying: Schutz implicitly extends \<open>bounded\<close> to sets, so his statements are neater.\<close>
(* alternative way of saying reachable *)
have "\<exists>q\<in>Q. q\<notin>(unreach-on Q from a)" "\<exists>q\<in>Q. q\<notin>(unreach-on Q from b)"
using cross_in_reachable reachable by blast+
text \<open>This is a helper statement for obtaining bounds in both directions of both unreachable sets.
Notice this needs Theorem 13 right now, Schutz claims only Theorem 4. I think this is necessary?\<close>
have get_bds: "\<exists>la\<in>Q. \<exists>ua\<in>Q. la\<notin>unreach-on Q from a \<and> ua\<notin>unreach-on Q from a \<and> (\<forall>x\<in>unreach-on Q from a. [la;x;ua])"
if asm: "a\<notin>Q" "path_ex a q" "q\<in>Q"
for a q
proof -
obtain Qy where "Qy\<in>unreach-on Q from a"
using asm(2) \<open>a \<notin> Q\<close> in_path_event path_Q two_in_unreach by blast
then obtain la where "la \<in> Q - unreach-on Q from a"
using asm(2,3) cross_in_reachable by blast
then obtain ua where "ua \<in> Q - unreach-on Q from a" "[la;Qy;ua]" "la \<noteq> ua"
using unreachable_set_bounded [where Q=Q and b=a and Qx=la and Qy=Qy]
using \<open>Qy \<in> unreach-on Q from a\<close> asm in_path_event path_Q by blast
have "la \<notin> unreach-on Q from a \<and> ua \<notin> unreach-on Q from a \<and> (\<forall>x\<in>unreach-on Q from a. (x\<noteq>la \<and> x\<noteq>ua) \<longrightarrow> [la;x;ua])"
proof (intro conjI)
show "la \<notin> unreach-on Q from a"
using \<open>la \<in> Q - unreach-on Q from a\<close> by force
next
show "ua \<notin> unreach-on Q from a"
using \<open>ua \<in> Q - unreach-on Q from a\<close> by force
next show "\<forall>x\<in>unreach-on Q from a. x \<noteq> la \<and> x \<noteq> ua \<longrightarrow> [la;x;ua]"
proof (safe)
fix x assume "x\<in>unreach-on Q from a" "x\<noteq>la" "x\<noteq>ua"
{
assume "x=Qy" hence "[la;x;ua]" by (simp add: \<open>[la;Qy;ua]\<close>)
} moreover {
assume "x\<noteq>Qy"
have "[Qy;x;la] \<or> [la;Qy;x]"
proof -
{ assume "[x;la;Qy]"
hence "la\<in>unreach-on Q from a"
using unreach_connected \<open>Qy\<in>unreach-on Q from a\<close>\<open>x\<in>unreach-on Q from a\<close>\<open>x\<noteq>Qy\<close> in_path_event path_Q that by blast
hence False
using \<open>la \<in> Q - unreach-on Q from a\<close> by blast }
thus "[Qy;x;la] \<or> [la;Qy;x]"
using some_betw [where Q=Q and a=x and b=la and c=Qy] path_Q unreach_on_path
using \<open>Qy \<in> unreach-on Q from a\<close> \<open>la \<in> Q - unreach-on Q from a\<close> \<open>x \<in> unreach-on Q from a\<close> \<open>x \<noteq> Qy\<close> \<open>x \<noteq> la\<close> by force
qed
hence "[la;x;ua]"
proof
assume "[Qy;x;la]"
thus ?thesis using \<open>[la;Qy;ua]\<close> abc_acd_abd abc_sym by blast
next
assume "[la;Qy;x]"
hence "[la;x;ua] \<or> [la;ua;x]"
using \<open>[la;Qy;ua]\<close> \<open>x \<noteq> ua\<close> abc_abd_acdadc by auto
have "\<not>[la;ua;x]"
using unreach_connected that abc_abc_neq abc_acd_bcd in_path_event path_Q
by (metis DiffD2 \<open>Qy \<in> unreach-on Q from a\<close> \<open>[la;Qy;ua]\<close> \<open>ua \<in> Q - unreach-on Q from a\<close> \<open>x \<in> unreach-on Q from a\<close>)
show ?thesis
using \<open>[la;x;ua] \<or> [la;ua;x]\<close> \<open>\<not> [la;ua;x]\<close> by linarith
qed
}
ultimately show "[la;x;ua]" by blast
qed
qed
thus ?thesis using \<open>la \<in> Q - unreach-on Q from a\<close> \<open>ua \<in> Q - unreach-on Q from a\<close> by force
qed
have "\<exists>y\<in>Q. \<exists>z\<in>Q. (\<forall>x\<in>(unreach-on Q from a)\<union>(unreach-on Q from b). [y;x;z])"
proof -
obtain la ua where "\<forall>x\<in>unreach-on Q from a. [la;x;ua]"
using events(1) get_bds reachable(1,3) by blast
obtain lb ub where "\<forall>x\<in>unreach-on Q from b. [lb;x;ub]"
using events(2) get_bds reachable(2,4) by blast
have "unreach-on Q from a \<subseteq> Q" "unreach-on Q from b \<subseteq> Q"
by (simp add: subsetI unreach_on_path)+
moreover have "1 < card (unreach-on Q from a) \<or> infinite (unreach-on Q from a)"
using two_in_unreach events(1) in_path_event path_Q reachable(1)
by (metis One_nat_def card_le_Suc0_iff_eq not_less)
moreover have "1 < card (unreach-on Q from b) \<or> infinite (unreach-on Q from b)"
using two_in_unreach events(2) in_path_event path_Q reachable(2)
by (metis One_nat_def card_le_Suc0_iff_eq not_less)
ultimately show ?thesis
using union_of_bounded_sets_is_bounded [where Q=Q and A="unreach-on Q from a" and B="unreach-on Q from b"]
using get_bds assms \<open>\<forall>x\<in>unreach-on Q from a. [la;x;ua]\<close> \<open>\<forall>x\<in>unreach-on Q from b. [lb;x;ub]\<close>
by blast
qed
then obtain y z where "y\<in>Q" "z\<in>Q" "(\<forall>x\<in>(unreach-on Q from a)\<union>(unreach-on Q from b). [y;x;z])"
by blast
show ?thesis
proof (rule bexI)+
show "y\<in>Q" by (simp add: \<open>y \<in> Q\<close>)
show "z\<in>Q" by (simp add: \<open>z \<in> Q\<close>)
show "(\<forall>x\<in>unreach-on Q from a. [z;x;y]) \<and> (\<forall>x\<in>unreach-on Q from b. [z;x;y])"
by (simp add: \<open>\<forall>x\<in>unreach-on Q from a \<union> unreach-on Q from b. [y;x;z]\<close> abc_sym)
qed
qed
theorem (*14*) second_existence_thm_2:
assumes path_Q: "Q\<in>\<P>"
and events: "a\<notin>Q" "b\<notin>Q" "c\<in>Q" "d\<in>Q" "c\<noteq>d"
and reachable: "\<exists>P\<in>\<P>. \<exists>q\<in>Q. path P a q" "\<exists>P\<in>\<P>. \<exists>q\<in>Q. path P b q"
shows "\<exists>e\<in>Q. \<exists>ae\<in>\<P>. \<exists>be\<in>\<P>. path ae a e \<and> path be b e \<and> [c;d;e]"
proof -
obtain y z where bounds_yz: "(\<forall>x\<in>unreach-on Q from a. [z;x;y]) \<and> (\<forall>x\<in>unreach-on Q from b. [z;x;y])"
and yz_inQ: "y\<in>Q" "z\<in>Q"
using second_existence_thm_1 [where Q=Q and a=a and b=b]
using path_Q events(1,2) reachable by blast
have "y\<notin>(unreach-on Q from a)\<union>(unreach-on Q from b)" "z\<notin>(unreach-on Q from a)\<union>(unreach-on Q from b)"
by (meson Un_iff \<open>(\<forall>x\<in>unreach-on Q from a. [z;x;y]) \<and> (\<forall>x\<in>unreach-on Q from b. [z;x;y])\<close> abc_abc_neq)+
let ?P = "\<lambda>e ae be. (e\<in>Q \<and> path ae a e \<and> path be b e \<and> [c;d;e])"
have exist_ay: "\<exists>ay. path ay a y"
if "a\<notin>Q" "\<exists>P\<in>\<P>. \<exists>q\<in>Q. path P a q" "y\<notin>(unreach-on Q from a)" "y\<in>Q"
for a y
using in_path_event path_Q that unreachable_bounded_path_only
by blast
have "[c;d;y] \<or> \<lbrakk>y;c;d] \<or> [c;y;d\<rbrakk>"
by (meson \<open>y \<in> Q\<close> abc_sym events(3-5) path_Q some_betw)
moreover have "[c;d;z] \<or> \<lbrakk>z;c;d] \<or> [c;z;d\<rbrakk>"
by (meson \<open>z \<in> Q\<close> abc_sym events(3-5) path_Q some_betw)
ultimately consider "[c;d;y]" | "[c;d;z]" |
"((\<lbrakk>y;c;d] \<or> [c;y;d\<rbrakk>) \<and> (\<lbrakk>z;c;d] \<or> [c;z;d\<rbrakk>))"
by auto
thus ?thesis
proof (cases)
assume "[c;d;y]"
have "y\<notin>(unreach-on Q from a)" "y\<notin>(unreach-on Q from b)"
using \<open>y \<notin> unreach-on Q from a \<union> unreach-on Q from b\<close> by blast+
then obtain ay yb where "path ay a y" "path yb b y"
using \<open>y\<in>Q\<close> exist_ay events(1,2) reachable(1,2) by blast
have "?P y ay yb"
using \<open>[c;d;y]\<close> \<open>path ay a y\<close> \<open>path yb b y\<close> \<open>y \<in> Q\<close> by blast
thus ?thesis by blast
next
assume "[c;d;z]"
have "z\<notin>(unreach-on Q from a)" "z\<notin>(unreach-on Q from b)"
using \<open>z \<notin> unreach-on Q from a \<union> unreach-on Q from b\<close> by blast+
then obtain az bz where "path az a z" "path bz b z"
using \<open>z\<in>Q\<close> exist_ay events(1,2) reachable(1,2) by blast
have "?P z az bz"
using \<open>[c;d;z]\<close> \<open>path az a z\<close> \<open>path bz b z\<close> \<open>z \<in> Q\<close> by blast
thus ?thesis by blast
next
assume "(\<lbrakk>y;c;d] \<or> [c;y;d\<rbrakk>) \<and> (\<lbrakk>z;c;d] \<or> [c;z;d\<rbrakk>)"
have "\<exists>e. [c;d;e]"
using prolong_betw (* works as Schutz says! *)
using events(3-5) path_Q by blast
then obtain e where "[c;d;e]" by auto
have "\<not>[y;e;z]"
proof (rule notI)
text \<open>Notice Theorem 10 is not needed for this proof, and does not seem to help \<open>sledgehammer\<close>.
I think this is because it cannot be easily/automatically reconciled with non-strict
notation.\<close>
assume "[y;e;z]"
moreover consider "(\<lbrakk>y;c;d] \<and> \<lbrakk>z;c;d])" | "(\<lbrakk>y;c;d] \<and> [c;z;d\<rbrakk>)" |
"([c;y;d\<rbrakk> \<and> \<lbrakk>z;c;d])" | "([c;y;d\<rbrakk> \<and> [c;z;d\<rbrakk>)"
using \<open>(\<lbrakk>y;c;d] \<or> [c;y;d\<rbrakk>) \<and> (\<lbrakk>z;c;d] \<or> [c;z;d\<rbrakk>)\<close> by linarith
ultimately show False
by (smt \<open>[c;d;e]\<close> abc_ac_neq betw4_strong betw4_weak)
qed
have "e\<in>Q"
using \<open>[c;d;e]\<close> betw_c_in_path events(3-5) path_Q by blast
have "e\<notin> unreach-on Q from a" "e\<notin> unreach-on Q from b"
using bounds_yz \<open>\<not> [y;e;z]\<close> abc_sym by blast+
hence ex_aebe: "\<exists>ae be. path ae a e \<and> path be b e"
using \<open>e \<in> Q\<close> events(1,2) in_path_event path_Q reachable(1,2) unreachable_bounded_path_only
by metis
thus ?thesis
using \<open>[c;d;e]\<close> \<open>e \<in> Q\<close> by blast
qed
qed
text \<open>
The assumption \<open>Q\<noteq>R\<close> in Theorem 14(iii) is somewhat implicit in Schutz.
If \<open>Q=R\<close>, \<open>unreach-on Q from a\<close> is empty, so the third conjunct of the conclusion is meaningless.
\<close>
theorem (*14*) second_existence_thm_3:
assumes paths: "Q\<in>\<P>" "R\<in>\<P>" "Q\<noteq>R"
and events: "x\<in>Q" "x\<in>R" "a\<in>R" "a\<noteq>x" "b\<notin>Q"
and reachable: "\<exists>P\<in>\<P>. \<exists>q\<in>Q. path P b q"
shows "\<exists>e\<in>\<E>. \<exists>ae\<in>\<P>. \<exists>be\<in>\<P>. path ae a e \<and> path be b e \<and> (\<forall>y\<in>unreach-on Q from a. [x;y;e])"
proof -
have "a\<notin>Q"
using events(1-4) paths eq_paths by blast
hence "unreach-on Q from a \<noteq> {}"
by (metis events(3) ex_in_conv in_path_event paths(1,2) two_in_unreach)
then obtain d where "d\<in> unreach-on Q from a" (*as in Schutz*)
by blast
have "x\<noteq>d"
using \<open>d \<in> unreach-on Q from a\<close> cross_in_reachable events(1) events(2) events(3) paths(2) by auto
have "d\<in>Q"
using \<open>d \<in> unreach-on Q from a\<close> unreach_on_path by blast
have "\<exists>e\<in>Q. \<exists>ae be. [x;d;e] \<and> path ae a e \<and> path be b e"
using second_existence_thm_2 [where c=x and Q=Q and a=a and b=b and d=d] (*as in Schutz*)
using \<open>a \<notin> Q\<close> \<open>d \<in> Q\<close> \<open>x \<noteq> d\<close> events(1-3,5) paths(1,2) reachable by blast
then obtain e ae be where conds: "[x;d;e] \<and> path ae a e \<and> path be b e" by blast
have "\<forall>y\<in>(unreach-on Q from a). [x;y;e]"
proof
fix y assume "y\<in>(unreach-on Q from a)"
hence "y\<in>Q"
using unreach_on_path by blast
show "[x;y;e]"
proof (rule ccontr)
assume "\<not>[x;y;e]"
then consider "y=x" | "y=e" | "[y;x;e]" | "[x;e;y]"
by (metis \<open>d\<in>Q\<close> \<open>y\<in>Q\<close> abc_abc_neq abc_sym betw_c_in_path conds events(1) paths(1) some_betw)
thus False
proof (cases)
assume "y=x" thus False
using \<open>y \<in> unreach-on Q from a\<close> events(2,3) paths(1,2) same_empty_unreach unreach_equiv unreach_on_path
by blast
next
assume "y=e" thus False
by (metis \<open>y\<in>Q\<close> assms(1) conds empty_iff same_empty_unreach unreach_equiv \<open>y \<in> unreach-on Q from a\<close>)
next
assume "[y;x;e]"
hence "[y;x;d]"
using abd_bcd_abc conds by blast
hence "x\<in>(unreach-on Q from a)"
using unreach_connected [where Q=Q and Q\<^sub>x=y and Q\<^sub>y=x and Q\<^sub>z=d and b=a]
using \<open>\<not>[x;y;e]\<close> \<open>a\<notin>Q\<close> \<open>d\<in>unreach-on Q from a\<close> \<open>y\<in>unreach-on Q from a\<close> conds in_path_event paths(1) by blast
thus False
using empty_iff events(2,3) paths(1,2) same_empty_unreach unreach_equiv unreach_on_path
by metis
next
assume "[x;e;y]"
hence "[d;e;y]"
using abc_acd_bcd conds by blast
hence "e\<in>(unreach-on Q from a)"
using unreach_connected [where Q=Q and Q\<^sub>x=y and Q\<^sub>y=e and Q\<^sub>z=d and b=a]
using \<open>a \<notin> Q\<close> \<open>d \<in> unreach-on Q from a\<close> \<open>y \<in> unreach-on Q from a\<close>
abc_abc_neq abc_sym events(3) in_path_event paths(1,2)
by blast
thus False
by (metis conds empty_iff paths(1) same_empty_unreach unreach_equiv unreach_on_path)
qed
qed
qed
thus ?thesis
using conds in_path_event by blast
qed
end (* context MinkowskiSpacetime *)
section "Theorem 11 - with path density assumed"
locale MinkowskiDense = MinkowskiSpacetime +
assumes path_dense: "path ab a b \<Longrightarrow> \<exists>x. [a;x;b]"
begin
text \<open>
Path density: if $a$ and $b$ are connected by a path, then the segment between them is nonempty.
Since Schutz insists on the number of segments in his segmentation (Theorem 11), we prove it here,
showcasing where his missing assumption of path density fits in (it is used three times
in \<open>number_of_segments\<close>, once in each separate meaningful \<^term>\<open>local_ordering\<close> case).
\<close>
lemma segment_nonempty:
assumes "path ab a b"
obtains x where "x \<in> segment a b"
using path_dense by (metis seg_betw assms)
lemma (*for 11*) number_of_segments:
assumes path_P: "P\<in>\<P>"
and Q_def: "Q\<subseteq>P"
and f_def: "[f\<leadsto>Q|a..b..c]"
shows "card {segment (f i) (f (i+1)) | i. i<(card Q-1)} = card Q - 1"
proof -
let ?S = "{segment (f i) (f (i+1)) | i. i<(card Q-1)}"
let ?N = "card Q"
let ?g = "\<lambda> i. segment (f i) (f (i+1))"
have "?N \<ge> 3" using chain_defs f_def by (meson finite_long_chain_with_card)
have "?g ` {0..?N-2} = ?S"
proof (safe)
fix i assume "i\<in>{(0::nat)..?N-2}"
show "\<exists>ia. segment (f i) (f (i+1)) = segment (f ia) (f (ia+1)) \<and> ia<card Q - 1"
proof
have "i<?N-1"
using assms \<open>i\<in>{(0::nat)..?N-2}\<close> \<open>?N\<ge>3\<close>
by (metis One_nat_def Suc_diff_Suc atLeastAtMost_iff le_less_trans lessI less_le_trans
less_trans numeral_2_eq_2 numeral_3_eq_3)
then show "segment (f i) (f (i + 1)) = segment (f i) (f (i + 1)) \<and> i<?N-1"
by blast
qed
next
fix x i assume "i < card Q - 1"
let ?s = "segment (f i) (f (i + 1))"
show "?s \<in> ?g ` {0..?N - 2}"
proof -
have "i\<in>{0..?N-2}"
using \<open>i < card Q - 1\<close> by force
thus ?thesis by blast
qed
qed
moreover have "inj_on ?g {0..?N-2}"
proof
fix i j assume asm: "i\<in>{0..?N-2}" "j\<in>{0..?N-2}" "?g i = ?g j"
show "i=j"
proof (rule ccontr)
assume "i\<noteq>j"
hence "f i \<noteq> f j"
using asm(1,2) f_def assms(3) indices_neq_imp_events_neq
[where X=Q and f=f and a=a and b=b and c=c and i=i and j=j]
by auto
show False
proof (cases)
assume "j=i+1" hence "j=Suc i" by linarith
have "Suc(Suc i) < ?N" using asm(1,2) eval_nat_numeral \<open>j = Suc i\<close> by auto
hence "[f i; f (Suc i); f (Suc (Suc i))]"
using assms short_ch_card \<open>?N\<ge>3\<close> chain_defs local_ordering_def
by (metis short_ch_alt(1) three_in_set3)
hence "[f i; f j; f (j+1)]" by (simp add: \<open>j = i + 1\<close>)
obtain e where "e\<in>?g j" using segment_nonempty abc_ex_path asm(3)
by (metis \<open>[f i; f j; f (j+1)]\<close> \<open>f i \<noteq> f j\<close> \<open>j = i + 1\<close>)
hence "e\<in>?g i"
using asm(3) by blast
have "[f i; f j; e]"
using abd_bcd_abc \<open>[f i; f j; f (j+1)]\<close>
by (meson \<open>e \<in> segment (f j) (f (j + 1))\<close> seg_betw)
thus False
using \<open>e \<in> segment (f i) (f (i + 1))\<close> \<open>j = i + 1\<close> abc_only_cba(2) seg_betw
by auto
next assume "j\<noteq>i+1"
have "i < card Q \<and> j < card Q \<and> (i+1) < card Q"
using add_mono_thms_linordered_field(3) asm(1,2) assms \<open>?N\<ge>3\<close> by auto
hence "f i \<in> Q \<and> f j \<in> Q \<and> f (i+1) \<in> Q"
using f_def unfolding chain_defs local_ordering_def
by (metis One_nat_def Suc_diff_le Suc_eq_plus1 \<open>3 \<le> card Q\<close> add_Suc card_1_singleton_iff
card_gt_0_iff card_insert_if diff_Suc_1 diff_Suc_Suc less_natE less_numeral_extra(1)
nat.discI numeral_3_eq_3)
hence "f i \<in> P \<and> f j \<in> P \<and> f (i+1) \<in> P"
using path_is_union assms
by (simp add: subset_iff)
then consider "[f i; (f(i+1)); f j]" | "[f i; f j; (f(i+1))]" |
"[(f(i+1)); f i; f j]"
using some_betw path_P f_def indices_neq_imp_events_neq
\<open>f i \<noteq> f j\<close> \<open>i < card Q \<and> j < card Q \<and> i + 1 < card Q\<close> \<open>j \<noteq> i + 1\<close>
by (metis abc_sym less_add_one less_irrefl_nat)
thus False
proof (cases)
assume "[(f(i+1)); f i; f j]"
then obtain e where "e\<in>?g i" using segment_nonempty
by (metis \<open>f i \<in> P \<and> f j \<in> P \<and> f (i + 1) \<in> P\<close> abc_abc_neq path_P)
hence "[e; f j; (f(j+1))]"
using \<open>[(f(i+1)); f i; f j]\<close>
by (smt abc_acd_abd abc_acd_bcd abc_only_cba abc_sym asm(3) seg_betw)
moreover have "e\<in>?g j"
using \<open>e \<in> ?g i\<close> asm(3) by blast
ultimately show False
by (simp add: abc_only_cba(1) seg_betw)
next
assume "[f i; f j; (f(i+1))]"
thus False
using abc_abc_neq [where b="f j" and a="f i" and c="f(i+1)"] asm(3) seg_betw [where x="f j"]
using ends_notin_segment by blast
next
assume "[f i; (f(i+1)); f j]"
then obtain e where "e\<in>?g i" using segment_nonempty
by (metis \<open>f i \<in> P \<and> f j \<in> P \<and> f (i + 1) \<in> P\<close> abc_abc_neq path_P)
hence "[e; f j; (f(j+1))]"
proof -
have "f (i+1) \<noteq> f j"
using \<open>[f i; (f(i+1)); f j]\<close> abc_abc_neq by presburger
then show ?thesis
using \<open>e \<in> segment (f i) (f (i+1))\<close> \<open>[f i; (f(i+1)); f j]\<close> asm(3) seg_betw
by (metis (no_types) abc_abc_neq abc_acd_abd abc_acd_bcd abc_sym)
qed
moreover have "e\<in>?g j"
using \<open>e \<in> ?g i\<close> asm(3) by blast
ultimately show False
by (simp add: abc_only_cba(1) seg_betw)
qed
qed
qed
qed
ultimately have "bij_betw ?g {0..?N-2} ?S"
using inj_on_imp_bij_betw by fastforce
thus ?thesis
using assms(2) bij_betw_same_card numeral_2_eq_2 numeral_3_eq_3 \<open>?N\<ge>3\<close>
by (metis (no_types, lifting) One_nat_def Suc_diff_Suc card_atLeastAtMost le_less_trans
less_Suc_eq_le minus_nat.diff_0 not_less not_numeral_le_zero)
qed
theorem (*11*) segmentation_card:
assumes path_P: "P\<in>\<P>"
and Q_def: "Q\<subseteq>P"
and f_def: "[f\<leadsto>Q|a..b]" (* This always exists given card Q > 2 *)
fixes P1 defines P1_def: "P1 \<equiv> prolongation b a"
fixes P2 defines P2_def: "P2 \<equiv> prolongation a b"
fixes S defines S_def: "S \<equiv> {segment (f i) (f (i+1)) | i. i<card Q-1}"
shows "P = ((\<Union>S) \<union> P1 \<union> P2 \<union> Q)"
(* The union of these segments and prolongations with the separating points is the path. *)
"card S = (card Q-1) \<and> (\<forall>x\<in>S. is_segment x)"
(* There are N-1 segments. *)
(* There are two prolongations. *)
"disjoint (S\<union>{P1,P2})" "P1\<noteq>P2" "P1\<notin>S" "P2\<notin>S"
(* The prolongations and all the segments are disjoint. *)
proof -
let ?N = "card Q"
have "2 \<le> card Q"
using f_def fin_chain_card_geq_2 by blast
have seg_facts: "P = (\<Union>S \<union> P1 \<union> P2 \<union> Q)" "(\<forall>x\<in>S. is_segment x)"
"disjoint (S\<union>{P1,P2})" "P1\<noteq>P2" "P1\<notin>S" "P2\<notin>S"
using show_segmentation [OF path_P Q_def f_def]
using P1_def P2_def S_def by fastforce+
show "P = \<Union>S \<union> P1 \<union> P2 \<union> Q" by (simp add: seg_facts(1))
show "disjoint (S\<union>{P1,P2})" "P1\<noteq>P2" "P1\<notin>S" "P2\<notin>S"
using seg_facts(3-6) by blast+
have "card S = (?N-1)"
proof (cases)
assume "?N=2"
hence "card S = 1"
by (simp add: S_def)
thus ?thesis
by (simp add: \<open>?N = 2\<close>)
next
assume "?N\<noteq>2"
hence "?N\<ge>3"
using \<open>2 \<le> card Q\<close> by linarith
then obtain c where "[f\<leadsto>Q|a..c..b]"
using assms chain_defs short_ch_card_2 \<open>2 \<le> card Q\<close> \<open>card Q \<noteq> 2\<close>
by (metis three_in_set3)
show ?thesis
using number_of_segments [OF assms(1,2) \<open>[f\<leadsto>Q|a..c..b]\<close>]
using S_def \<open>card Q \<noteq> 2\<close> by presburger
qed
thus "card S = card Q - 1 \<and> Ball S is_segment"
using seg_facts(2) by blast
qed
end (* context MinkowskiDense *)
(*
context MinkowskiSpacetime begin
interpretation is_dense: MinkowskiDense apply unfold_locales oops
end
*)
end |
module Trainer where
import Numeric.LinearAlgebra
import Models
import Layer
import Optimization
import Data.Foldable
import Control.Monad.IO.Class
import Utils
data TrainConfig = TrainConfig {
trainConfigRowNum :: Int,
trainConfigColNum :: Int,
trainConfigLearningRate :: Double,
trainConfigMomentum :: Double,
trainConfigDecay :: Double,
trainConfigEpsilon :: Double,
trainConfigBatchSize :: Double,
trainConfigOptimization:: String
}
trainSingleData :: Model VLayer -> TrainConfig -> Matrix R -> IO ()
trainSingleData (Model []) _ _ = print "No models !" >> return ()
trainSingleData neuModel trainConfig inputData =
let r = trainConfigRowNum trainConfig
c = trainConfigColNum trainConfig
paramsList = genParamsList neuModel
gparamsList = genGParamsList neuModel
accGradList = accMatrixInit paramsList
accDeltaList = accMatrixInit paramsList
optimize = Adadelta {
adaDecay = trainConfigDecay trainConfig,
adaEpsilon = trainConfigEpsilon trainConfig,
adaBatchSize = (trainConfigBatchSize trainConfig),
adaParams = paramsList,
adaGparams = gparamsList,
adaAccGrad = accGradList,
adaAccDelta = accDeltaList
} in
-- begin to train
forM_ [1..10000] $ \idx -> do
--print idx
let output = forward inputData neuModel in
--print "backpropagate the model" >>
let neuModel = backward "mse" output inputData neuModel in
--print "neumodel" >>
let gparamsList = updateGParamsList neuModel gparamsList in
--print "continue" >>
if mod idx 100 == 0 && idx >= 100 then
-- update the params in optimize
-- update the params in model
let optimize = paramUpdate optimize
paramsList = adaParams optimize
neuModel = updateModelParams neuModel paramsList in
print (getAverageMat output) >>
return()
else return()
|
library(ffrmv)
test_that("make_filename works", expect_that(make_filename('2014'), equals("accident_2014.csv.bz2"))) |
[STATEMENT]
lemma comp_fun_commute_maybe_and: "comp_fun_commute maybe_and"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. comp_fun_commute (\<and>?)
[PROOF STEP]
apply standard
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>y x. (\<and>?) y \<circ> (\<and>?) x = (\<and>?) x \<circ> (\<and>?) y
[PROOF STEP]
apply (simp add: comp_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>y x. (\<lambda>xa. y \<and>? (x \<and>? xa)) = (\<lambda>xa. x \<and>? (y \<and>? xa))
[PROOF STEP]
apply (rule ext)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>y x xa. y \<and>? (x \<and>? xa) = x \<and>? (y \<and>? xa)
[PROOF STEP]
by (metis add.left_commute de_morgans_2 maybe_not_eq) |
From iris.algebra Require Export cmra.
From iris.algebra Require Import proofmode_classes.
From iris.prelude Require Import options.
Require Import cpdt.CpdtTactics.
From stdpp Require Import gmap.
From stdpp Require Import mapset.
From stdpp Require Import sets.
From stdpp Require Import list.
Require Import Burrow.gmap_utils.
Require Import Burrow.trees.
Require Import Burrow.indexing.
Require Import Burrow.locations.
Require Import Burrow.tactics.
Require Import coq_tricks.Deex.
Section ExchangeProof.
Context {M} `{!EqDecision M} `{!TPCM M}.
Context {RI} `{!EqDecision RI, !Countable RI, !RefinementIndex M RI}.
Definition specific_exchange_cond (ref: Refinement M M) (p m f h s m' f' h' s' : M) :=
∃ j l l' ,
rel_defined M M ref (dot f p) ->
m_valid (dot m (rel M M ref (dot f p))) ->
dot j s' = f' /\ m = dot l h /\ m' = dot l' h' /\
rel_defined M M ref (dot (dot j s) p) /\
mov (dot l (rel M M ref (dot f p))) (dot l' (rel M M ref (dot (dot j s) p))).
Definition specific_flow_cond p i (t t': Branch M) (active: Lifetime) (down up : PathLoc -> M) :=
let q := (p, i) in
let r := (p, S i) in
let s := (p ++ [i], 0) in
specific_exchange_cond (refinement_of_nat M RI i)
(node_total_minus_live (refinement_of_nat M RI) (node_of_pl t q) active)
(down q) (node_live (node_of_pl t q))
(down r) (down s)
(up q) (node_live (node_of_pl t' q))
(up r) (up s).
Lemma dot_kjha k j a : (dot (dot a k) j) = (dot (dot j a) k).
Proof. rewrite tpcm_comm. rewrite tpcm_assoc. trivial. Qed.
Lemma valid_reduce m k a :
m_valid (dot (dot m k) a) -> m_valid (dot m a).
Proof. intro. apply valid_monotonic with (y := k).
rewrite dot_comm_right2. trivial. Qed.
Lemma dot_aklh a k l h
: (dot (dot a k) (dot l h)) = dot (dot l a) (dot k h).
Proof.
rewrite tpcm_assoc. rewrite tpcm_assoc. f_equal.
apply dot_kjha. Qed.
Lemma dot_aklh2 a k l h
: (dot (dot (dot l h) k) a) = (dot (dot l a) (dot k h)).
Proof.
rewrite <- tpcm_assoc. rewrite <- tpcm_assoc. rewrite <- tpcm_assoc. f_equal.
rewrite tpcm_assoc. rewrite tpcm_assoc. rewrite dot_kjha.
rewrite dot_comm_right2. trivial. Qed.
Lemma dot_jszr (j s z r : M)
: dot (dot j s) (dot z r) = dot (dot r s) (dot j z).
Proof.
replace (dot j s) with (dot s j) by (apply tpcm_comm).
replace (dot r s) with (dot s r) by (apply tpcm_comm).
rewrite <- tpcm_assoc. rewrite <- tpcm_assoc. f_equal.
replace (dot z r) with (dot r z) by (apply tpcm_comm).
rewrite tpcm_assoc. rewrite tpcm_assoc. f_equal. apply tpcm_comm. Qed.
Lemma dot_jszr2 (j s z r : M)
: (dot (dot (dot j s) z) r) = dot (dot r s) (dot j z).
Proof.
rewrite <- tpcm_assoc.
apply dot_jszr. Qed.
Lemma dot_qklh (q k l h : M)
: dot (dot q k) (dot l h) = dot (dot k h) (dot q l).
Proof.
replace (dot k h) with (dot h k) by (apply tpcm_comm).
apply dot_jszr.
Qed.
Lemma all_the_movs (z m f h s r k m' f' h' s' r' k' : M) i
(mo: mov (dot r s) (dot r' s'))
(mo2: mov (dot k h) (dot k' h'))
(inr: in_refinement_domain (refinement_of_nat M RI) i (dot f (dot z r)))
(myflow : specific_exchange_cond (refinement_of_nat M RI i) (dot z r) m f h s m' f' h' s')
(val : m_valid (dot (dot m k) (project (refinement_of_nat M RI) i (dot (dot f z) r))))
: mov (dot (dot (project (refinement_of_nat M RI) i (dot (dot f z) r)) k) m)
(dot (dot (project (refinement_of_nat M RI) i (dot (dot f' z) r')) k') m').
Proof.
unfold specific_exchange_cond in myflow. deex.
unfold in_refinement_domain in inr.
unfold project in *.
assert ((dot (dot f z) r) = (dot f (dot z r))) as A by (rewrite tpcm_assoc; trivial).
rewrite A in val. rewrite A. clear A.
(*destruct (rel M M (refinement_of_nat M RI i) (dot f (dot z r))) eqn:fzr.
- rename m0 into a.*)
have myf := myflow inr (valid_reduce m k _ val). clear myflow.
destruct_ands.
subst m.
subst m'. subst f'.
set a := (rel M M (refinement_of_nat M RI i) (dot f (dot z r))).
set a' := (rel M M (refinement_of_nat M RI i) ((dot (dot j s) (dot z r)))).
assert (m_valid (dot (dot a' k) (dot l' h)) /\
(mov (dot (dot a k) (dot l h)) (dot (dot a' k) (dot l' h)))).
* assert (dot (dot a k) (dot l h) = dot (dot l a) (dot k h)) as r1 by (apply dot_aklh).
assert (dot (dot a' k) (dot l' h) = dot (dot l' a') (dot k h)) as r2 by (apply dot_aklh).
rewrite r1.
rewrite r2.
subst a. subst a'.
apply mov_monotonic; trivial.
rewrite <- dot_aklh2. trivial.
* destruct_ands.
apply trans with (y := dot (dot a' k) (dot l' h)); trivial.
subst a. subst a'.
rewrite dot_jszr in H2.
rewrite dot_jszr in H3.
rewrite dot_jszr2.
assert (m_valid (dot (dot r s) (dot j z))) as m_valid_srjz
by ( apply (rel_valid_left M M (refinement_of_nat M RI i) (dot (dot r s) (dot j z))); trivial).
assert (mov (dot (dot r s) (dot j z)) (dot (dot r' s') (dot j z))) as mov_rsjz
by (apply mov_monotonic; trivial).
have movr := mov_refines M M (refinement_of_nat M RI i)
(dot (dot r s) (dot j z)) (dot (dot r' s') (dot j z)) mov_rsjz H2.
deex. destruct_ands.
assert (m_valid (dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot r' s') (dot j z))) k) (dot l' h)) /\
(mov (dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r))) k) (dot l' h)) (dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot r' s') (dot j z))) k) (dot l' h)))).
-- replace
((dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r))) k) (dot l' h))) with
((dot ((rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r)))) (dot k (dot l' h)))) by (apply tpcm_assoc).
replace
((dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r))) k) (dot l' h))) with
((dot ((rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r)))) (dot k (dot l' h)))) in H by (apply tpcm_assoc).
replace
((dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot r' s') (dot j z))) k) (dot l' h))) with
((dot ((rel M M (refinement_of_nat M RI i) (dot (dot r' s') (dot j z)))) (dot k (dot l' h)))) by (apply tpcm_assoc).
rewrite <- dot_jszr in H4.
apply mov_monotonic; trivial.
-- destruct_ands.
apply trans with (y := (dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot r' s') (dot j z))) k) (dot l' h))); trivial.
rewrite dot_qklh.
rewrite dot_qklh in H5.
assert (dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot r' s') (dot j z))) k') (dot l' h') = dot (dot k' h') (dot (rel M M (refinement_of_nat M RI i) (dot (dot r' s') (dot j z))) l'))
by (apply dot_qklh).
rewrite H7.
apply mov_monotonic; trivial.
Qed.
Lemma all_the_movs_ird (z m f h s r k m' f' h' s' r' k' : M) i
(mo: mov (dot r s) (dot r' s'))
(mo2: mov (dot k h) (dot k' h'))
(inr: in_refinement_domain (refinement_of_nat M RI) i (dot f (dot z r)))
(myflow : specific_exchange_cond (refinement_of_nat M RI i) (dot z r) m f h s m' f' h' s')
(val : m_valid (dot (dot m k) (project (refinement_of_nat M RI) i (dot (dot f z) r))))
: in_refinement_domain (refinement_of_nat M RI) i (dot (dot f' z) r').
Proof.
unfold specific_exchange_cond in myflow. deex.
unfold in_refinement_domain in inr.
unfold project in *.
assert ((dot (dot f z) r) = (dot f (dot z r))) as A by (rewrite tpcm_assoc; trivial).
rewrite A in val. clear A.
have myf := myflow inr (valid_reduce m k _ val). clear myflow.
destruct_ands.
subst m.
subst m'.
subst f'.
assert (m_valid (dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r))) k) (dot l' h)) /\
(mov (dot (dot (rel M M (refinement_of_nat M RI i) (dot f (dot z r))) k) (dot l h)) (dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r))) k) (dot l' h)))).
* assert (dot (dot (rel M M (refinement_of_nat M RI i) (dot f (dot z r))) k) (dot l h) = dot (dot l (rel M M (refinement_of_nat M RI i) (dot f (dot z r)))) (dot k h)) as r1 by (apply dot_aklh).
assert (dot (dot (rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r))) k) (dot l' h) = dot (dot l' (rel M M (refinement_of_nat M RI i) (dot (dot j s) (dot z r)))) (dot k h)) as r2 by (apply dot_aklh).
rewrite r1.
rewrite r2.
apply mov_monotonic; trivial.
rewrite <- dot_aklh2. trivial.
* destruct_ands.
(*rewrite dot_jszr in jszr.
rewrite dot_jszr2.*)
rewrite dot_jszr in H2.
rewrite dot_jszr in H3.
rewrite dot_jszr2.
assert (m_valid (dot (dot r s) (dot j z))) as m_valid_srjz
by (apply (rel_valid_left M M (refinement_of_nat M RI i) (dot (dot r s) (dot j z)) ); trivial).
assert (mov (dot (dot r s) (dot j z)) (dot (dot r' s') (dot j z))) as mov_rsjz
by (apply mov_monotonic; trivial).
have movr := mov_refines M M (refinement_of_nat M RI i)
(dot (dot r s) (dot j z)) (dot (dot r' s') (dot j z)) mov_rsjz H2.
deex. destruct_ands.
unfold in_refinement_domain.
trivial.
Qed.
Lemma m_valid_ca a b c
: m_valid (dot (dot a b) c) -> m_valid (dot c a).
Proof.
intro. apply valid_monotonic with (y := b).
rewrite dot_kjha in H. trivial.
Qed.
Lemma m_valid_bd (a b c d : M)
: m_valid (dot (dot a b) (dot c d)) -> m_valid (dot b d).
Proof.
intro. apply valid_monotonic with (y := dot a c).
rewrite dot_aklh. replace (dot d c) with (dot c d) by (apply tpcm_comm). trivial. Qed.
Lemma m_valid_db (a b c d : M)
: m_valid (dot (dot a b) (dot c d)) -> m_valid (dot d b).
Proof.
intro. apply valid_monotonic with (y := dot a c).
rewrite <- dot_aklh.
replace (dot b a) with (dot a b) by (apply tpcm_comm).
replace (dot d c) with (dot c d) by (apply tpcm_comm). trivial.
Qed.
Lemma rec_m_valid_branch
(t t' : Branch M)
(active : Lifetime)
(branch : Branch M) p i
(down up : PathLoc -> M)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(branch_is : branch ≡ branch_of_pl t (p, i))
(amval : m_valid (dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i))))
(batird : branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch active i)
: m_valid (dot
(branch_total (refinement_of_nat M RI) (branch_of_pl t (p, S i)) active
(S i)) (down (p, S i))).
Proof.
setoid_rewrite branch_is in amval.
setoid_rewrite branchcons_pl in amval.
rewrite branch_total_unfold in amval.
have fl := flow_update p i.
unfold specific_flow_cond in fl.
unfold specific_exchange_cond in fl. deex.
setoid_rewrite branch_is in batird.
setoid_rewrite branchcons_pl in batird.
rewrite branch_all_total_in_refinement_domain_unfold in batird.
destruct_ands. clear H0. rename H into natird.
setoid_rewrite cellnode_pl in natird.
rewrite node_all_total_in_refinement_domain_unfold in natird.
destruct_ands. rename H into Y. clear H0.
unfold in_refinement_domain in Y.
assert ((node_total (refinement_of_nat M RI)
(CellNode (cell_of_pl t (p, i)) (branch_of_pl t (p ++ [i], 0))) active)
= node_total (refinement_of_nat M RI) (node_of_pl t (p, i)) active).
- setoid_rewrite cellnode_pl. trivial.
- rewrite H in Y.
rewrite <- node_live_plus_node_total_minus_live in Y.
rewrite <- node_live_plus_node_total_minus_live in amval.
unfold project in amval.
full_generalize (rel M M (refinement_of_nat M RI i)
(dot (node_live (node_of_pl t (p, i)))
(node_total_minus_live (refinement_of_nat M RI) (node_of_pl t (p, i)) active))) as x.
+ have fl' := fl Y (m_valid_ca _ _ _ amval).
destruct_ands.
rewrite H1 in amval.
have am := m_valid_bd _ _ _ _ amval.
trivial.
Qed.
Lemma rec_m_valid_node
(t t' : Branch M)
(active : Lifetime)
(branch : Branch M) p i
(down up : PathLoc -> M)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(branch_is : branch ≡ branch_of_pl t (p, i))
(amval : m_valid (dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i))))
(batird : branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch active i)
: m_valid
(dot
(branch_total (refinement_of_nat M RI) (branch_of_node (node_of_pl t (p, i)))
active 0) (down (p ++ [i], 0))).
Proof.
(*setoid_rewrite branch_is in amval.
setoid_rewrite branchcons_pl in amval.
rewrite branch_total_unfold in amval.
setoid_rewrite cellnode_pl in amval.
rewrite node_total_unfold in amval.*)
setoid_rewrite branch_is in amval.
setoid_rewrite branchcons_pl in amval.
rewrite branch_total_unfold in amval.
have fl := flow_update p i.
unfold specific_flow_cond in fl.
unfold specific_exchange_cond in fl. deex.
setoid_rewrite branch_is in batird.
setoid_rewrite branchcons_pl in batird.
rewrite branch_all_total_in_refinement_domain_unfold in batird.
destruct_ands. clear H0. rename H into natird.
setoid_rewrite cellnode_pl in natird.
rewrite node_all_total_in_refinement_domain_unfold in natird.
destruct_ands. rename H into Y. clear H0.
unfold in_refinement_domain in Y.
assert ((node_total (refinement_of_nat M RI)
(CellNode (cell_of_pl t (p, i)) (branch_of_pl t (p ++ [i], 0))) active)
= node_total (refinement_of_nat M RI) (node_of_pl t (p, i)) active).
- setoid_rewrite cellnode_pl. trivial.
- rewrite H in Y.
rewrite <- node_live_plus_node_total_minus_live in Y.
rewrite <- node_live_plus_node_total_minus_live in amval.
unfold project in amval.
full_generalize (rel M M (refinement_of_nat M RI i)
(dot (node_live (node_of_pl t (p, i)))
(node_total_minus_live (refinement_of_nat M RI) (node_of_pl t (p, i)) active))) as x.
+ have fl' := fl Y (m_valid_ca _ _ _ amval).
destruct_ands.
(*destruct (rel M M (refinement_of_nat M RI i)
(dot (dot j (down (p ++ [i], 0)))
(node_total_minus_live (refinement_of_nat M RI) (node_of_pl t (p, i)) active))) eqn:de.*)
* have rvl := rel_valid_left M M (refinement_of_nat M RI i) ((dot (dot j (down (p ++ [i], 0))) (node_total_minus_live (refinement_of_nat M RI) (node_of_pl t (p, i)) active))) H3.
setoid_rewrite cellnode_pl in rvl.
unfold node_total_minus_live in rvl.
have q := m_valid_db _ _ _ _ rvl .
setoid_rewrite branch_of_node_node_of_pl.
trivial.
Qed.
Lemma dot_cba a b c
: (dot (dot a b) c) = (dot (dot c b) a).
Proof.
rewrite dot_kjha. rewrite <- tpcm_assoc. rewrite <- tpcm_assoc. f_equal.
apply tpcm_comm. Qed.
Lemma listset_max_fn (se : gset PathLoc) (fn: PathLoc -> nat)
: ∃ lmax , ∀ pl , pl ∈ se -> fn pl ≤ lmax.
Proof. exists (set_fold (λ r k, k `max` fn r) 1 se).
intros.
replace (se) with ((se ∖ {[ pl ]}) ∪ {[ pl ]}).
- rewrite set_fold_add_1_element.
+ lia.
+ set_solver.
+ intros. lia.
- apply set_eq. intros. rewrite elem_of_union.
rewrite elem_of_difference. rewrite elem_of_singleton. intuition.
+ subst. trivial.
+ have h : Decision (x = pl) by solve_decision. destruct h; intuition.
Qed.
Lemma listset_max_len (se : gset PathLoc)
: ∃ lmax , ∀ p i , (p, i) ∈ se -> length p ≤ lmax.
Proof. have h := listset_max_fn se (λ pl , match pl with (p, i) => length p end).
deex. exists lmax. intros. have q := h (p, i). apply q. trivial.
Qed.
Lemma listset_max_i (se : gset PathLoc)
: ∃ imax , ∀ p i , (p, i) ∈ se -> i ≤ imax.
Proof. have h := listset_max_fn se (λ pl , match pl with (p, i) => i end).
deex. exists lmax. intros. have q := h (p, i). apply q. trivial.
Qed.
Lemma batird_BranchNil active idx:
branch_all_total_in_refinement_domain (refinement_of_nat M RI) BranchNil active idx.
Proof. unfold branch_all_total_in_refinement_domain. trivial. Qed.
Lemma branch_total_is_unit active i
: branch_total (refinement_of_nat M RI) BranchNil active i = unit.
Proof. unfold branch_total. trivial. Qed.
Lemma resolve_trivial branch branch' active i
(bt : branch_trivial branch)
(bt' : branch_trivial branch')
: branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch' active i
∧ mov (dot (branch_total (refinement_of_nat M RI) branch active i) unit)
(dot (branch_total (refinement_of_nat M RI) branch' active i) unit).
Proof.
assert (branch ≡ BranchNil) as bn
by (apply branch_equiv_of_trivial; trivial; unfold branch_trivial; trivial).
assert (branch' ≡ BranchNil) as bn'
by (apply branch_equiv_of_trivial; trivial; unfold branch_trivial; trivial).
split.
- setoid_rewrite bn'.
apply batird_BranchNil.
- setoid_rewrite bn.
setoid_rewrite bn'.
rewrite branch_total_is_unit.
apply reflex.
Qed.
Lemma do_trivial_movs (m h s m' h' s': M) i
(mov1 : mov h h')
(mov2 : mov s s')
(is_valid_m: m_valid m)
(fl : specific_exchange_cond (refinement_of_nat M RI i) unit m unit h s m' unit h' s')
: mov m m'.
Proof.
have t : mov (dot (dot (project (refinement_of_nat M RI) i (dot (dot unit unit) unit)) unit) m) (dot (dot (project (refinement_of_nat M RI) i (dot (dot unit unit) unit)) unit) m').
- apply all_the_movs with (h := h) (s := s) (h' := h') (s' := s').
+ rewrite unit_dot_left. rewrite unit_dot_left. trivial.
+ rewrite unit_dot_left. rewrite unit_dot_left. trivial.
+ rewrite unit_dot_left. rewrite unit_dot_left.
unfold in_refinement_domain. apply rel_defined_unit.
+ rewrite unit_dot_left. trivial.
+ repeat (rewrite unit_dot_left).
repeat (rewrite unit_dot).
unfold project. rewrite rel_unit.
repeat (rewrite unit_dot).
trivial.
- unfold project in t.
repeat (rewrite unit_dot_left in t).
repeat (rewrite unit_dot in t).
rewrite rel_unit in t.
repeat (rewrite unit_dot_left in t).
trivial.
Qed.
Lemma specexc_branch_tt_ind (t t': Branch M) (active: Lifetime) (se: gset PathLoc) : ∀ len_add i_add p i
branch branch'
(indl: ∀ p0 i0 , (p0, i0) ∈ se -> length p0 < len_add + length p)
(indi: ∀ p0 i0 , (p0, i0) ∈ se -> i0 < i_add + i)
(down up : PathLoc -> M)
(flow_se : ∀ p i , (p, i) ∉ se -> up (p, i) = unit /\ down (p, i) = unit)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(branch_is : branch ≡ branch_of_pl t (p, i))
(branch'_is : branch' ≡ branch_of_pl t' (p, i))
(reserved_untouched : ∀ pl, cell_total_minus_live (cell_of_pl t pl) active = cell_total_minus_live (cell_of_pl t' pl) active)
(amval : m_valid (dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i))))
(branch_is_trivial : branch_trivial branch)
(branch'_is_trivial : branch_trivial branch')
(batird : branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch active i)
,
branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch' active i
/\ mov
(dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i)))
(dot (branch_total (refinement_of_nat M RI) branch' active i) (up (p, i))).
induction len_add as [len_add IHnLen] using lt_wf_ind.
induction i_add as [i_add IHnI] using lt_wf_ind.
Proof.
intros.
destruct len_add.
- assert ((p, i) ∉ se).
+ intro. have indl_a := indl p i H. lia.
+ have d := flow_se p i H. destruct_ands. rewrite H0. rewrite H1.
apply resolve_trivial; trivial.
- destruct i_add.
+ assert ((p, i) ∉ se).
* intro. have indi_a := indi p i H. lia.
* have d := flow_se p i H. destruct_ands. rewrite H0. rewrite H1.
apply resolve_trivial; trivial.
+
assert (len_add < S len_add) as len_add_lt_S by lia.
assert (∀ (p0 : list nat) (i0 : nat),
(p0, i0) ∈ se → length p0 < len_add + length (p ++ [i])) as afl
by (intros; have indla := indl p0 i0 H; rewrite app_length; simpl; lia).
assert ((∀ (p0 : list nat) (i0 : nat), (p0, i0) ∈ se → i0 < S i_add + i + 0)) as ifl
by (intros; have india := indi p0 i0 H; lia).
assert (BranchNil ≡ branch_of_pl t (p ++ [i], 0)) as branch_nil_n_child
by (apply branch_nil_of_n_child; setoid_rewrite branch_is in branch_is_trivial;
trivial).
assert (BranchNil ≡ branch_of_pl t' (p ++ [i], 0)) as branch_nil_n_child'
by (apply branch_nil_of_n_child; setoid_rewrite branch'_is in branch'_is_trivial;
trivial).
assert (BranchNil ≡ branch_of_pl t (p, S i)) as branch_nil_b_child
by (apply branch_nil_of_b_child; setoid_rewrite branch_is in branch_is_trivial;
trivial).
assert (BranchNil ≡ branch_of_pl t' (p, S i)) as branch_nil_b_child'
by (apply branch_nil_of_b_child; setoid_rewrite branch'_is in branch'_is_trivial;
trivial).
have mval_b := rec_m_valid_branch t t' active branch p i down up flow_update branch_is
amval batird.
setoid_rewrite <- branch_nil_b_child in mval_b.
have mval_n := rec_m_valid_node t t' active branch p i down up flow_update branch_is
amval batird.
setoid_rewrite branch_of_node_node_of_pl in mval_n.
setoid_rewrite <- branch_nil_n_child in mval_n.
assert (branch_trivial BranchNil) as bt_bn by (unfold branch_trivial; trivial).
have Ih1 := IHnLen len_add len_add_lt_S (S i_add + i) (p ++ [i]) 0
BranchNil BranchNil afl ifl down up flow_se flow_update branch_nil_n_child
branch_nil_n_child' reserved_untouched mval_n bt_bn bt_bn
(batird_BranchNil active 0).
assert (i_add < S i_add) as i_add_lt_S by lia.
assert (∀ (p0 : list nat) (i0 : nat), (p0, i0) ∈ se → length p0 < S len_add + length p)
as merf by (intros; have q := indl p0 i0 H; lia).
assert (∀ (p0 : list nat) (i0 : nat), (p0, i0) ∈ se → i0 < i_add + S i)
as gerf by (intros; have q := indi p0 i0 H; lia).
have Ih2 := IHnI i_add i_add_lt_S p (S i) BranchNil BranchNil merf gerf
down up flow_se flow_update branch_nil_b_child
branch_nil_b_child' reserved_untouched mval_b bt_bn bt_bn
(batird_BranchNil active (S i)).
clear IHnLen. clear IHnI.
destruct_ands. rename H0 into mov1. rename H2 into mov2.
assert (branch ≡ BranchNil) as b_bn by (apply branch_equiv_of_trivial; trivial).
assert (branch' ≡ BranchNil) as b'_bn by (apply branch_equiv_of_trivial; trivial).
split.
* setoid_rewrite b'_bn. apply batird_BranchNil.
* setoid_rewrite b'_bn. setoid_rewrite b_bn.
rewrite branch_total_is_unit.
rewrite branch_total_is_unit in mov1.
rewrite branch_total_is_unit in mov2.
setoid_rewrite b_bn in amval.
rewrite branch_total_is_unit in amval.
rewrite unit_dot_left.
rewrite unit_dot_left.
rewrite unit_dot_left in mov1.
rewrite unit_dot_left in mov1.
rewrite unit_dot_left in mov2.
rewrite unit_dot_left in mov2.
have fl := flow_update p i.
unfold specific_flow_cond in fl.
assert (node_of_pl t (p, i) ≡ triv_node) as is_triv_node
by (apply node_triv_of_triv_branch; setoid_rewrite branch_is in branch_is_trivial;
trivial).
assert (node_of_pl t' (p, i) ≡ triv_node) as is_triv_node'
by (apply node_triv_of_triv_branch; setoid_rewrite branch'_is in branch'_is_trivial;
trivial).
setoid_rewrite is_triv_node in fl.
setoid_rewrite is_triv_node' in fl.
rewrite node_total_minus_live_triv in fl.
unfold node_live, triv_node, cell_live, triv_cell in fl.
full_generalize (down (p, S i)) as h.
full_generalize (up (p, S i)) as h'.
full_generalize (down (p, i)) as m.
full_generalize (up (p, i)) as m'.
full_generalize ((down (p ++ [i], 0))) as s.
full_generalize ((up(p ++ [i], 0))) as s'.
apply do_trivial_movs with (h:=h) (s:=s) (h':=h') (s':=s') (i:=i); trivial.
rewrite unit_dot_left in amval. trivial.
Qed.
Lemma specexc_branch_tt (t t': Branch M) (active: Lifetime) (se: gset PathLoc) p i
branch branch'
(down up : PathLoc -> M)
(flow_se : ∀ p i , (p, i) ∉ se -> up (p, i) = unit /\ down (p, i) = unit)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(branch_is : branch ≡ branch_of_pl t (p, i))
(branch'_is : branch' ≡ branch_of_pl t' (p, i))
(reserved_untouched : ∀ pl, cell_total_minus_live (cell_of_pl t pl) active = cell_total_minus_live (cell_of_pl t' pl) active)
(amval : m_valid (dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i))))
(branch_is_trivial : branch_trivial branch)
(branch'_is_trivial : branch_trivial branch')
(batird : branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch active i)
: branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch' active i
/\ mov
(dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i)))
(dot (branch_total (refinement_of_nat M RI) branch' active i) (up (p, i))).
Proof.
have lmax_h := listset_max_len se.
have imax_h := listset_max_i se. deex.
assert ( ∀ (p0 : list nat) (i0 : nat), (p0, i0) ∈ se → length p0 < (lmax+1) + length p).
- intros. have g := lmax_h p0 i0 H. lia.
- assert (∀ (p0 : list nat) (i0 : nat), (p0, i0) ∈ se → i0 < imax + 1 + i).
+ intros. have g := imax_h p0 i0 H0. lia.
+ eapply (specexc_branch_tt_ind t t' active se (lmax+1) (imax+1) p i branch branch' H H0 down up flow_se flow_update branch_is
branch'_is reserved_untouched amval branch_is_trivial branch'_is_trivial batird).
Qed.
Lemma specexc_branch_t (t t': Branch M) (active: Lifetime) (branch branch': Branch M) (se: gset PathLoc) p i
(down up : PathLoc -> M)
(flow_se : ∀ p i , (p, i) ∉ se -> up (p, i) = unit /\ down (p, i) = unit)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(branch_is : branch ≡ branch_of_pl t (p, i))
(branch'_is : branch' ≡ branch_of_pl t' (p, i))
(reserved_untouched : ∀ pl, cell_total_minus_live (cell_of_pl t pl) active = cell_total_minus_live (cell_of_pl t' pl) active)
(amval : m_valid (dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i))))
(branch'_is_trivial : branch_trivial branch')
(batird : branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch active i)
: branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch' active i
/\ mov
(dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i)))
(dot (branch_total (refinement_of_nat M RI) branch' active i) (up (p, i)))
with specexc_node_t (t t': Branch M) (active: Lifetime) (node node': Node M) (se: gset PathLoc) p i
(down up : PathLoc -> M)
(flow_se : ∀ p i , (p, i) ∉ se -> up (p, i) = unit /\ down (p, i) = unit)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(node_is : node ≡ node_of_pl t (p, i))
(node'_is : node' ≡ node_of_pl t' (p, i))
(reserved_untouched : ∀ pl, cell_total_minus_live (cell_of_pl t pl) active = cell_total_minus_live (cell_of_pl t' pl) active)
(amval : m_valid (dot (branch_total (refinement_of_nat M RI) (branch_of_node node) active 0) (down (p++[i], 0))))
(node'_is_trivial : node_trivial node')
(batird : node_all_total_in_refinement_domain (refinement_of_nat M RI) node active i)
: branch_all_total_in_refinement_domain (refinement_of_nat M RI) (branch_of_node node') active 0
/\ mov
(dot (branch_total (refinement_of_nat M RI) (branch_of_node node) active 0) (down (p++[i], 0)))
(dot (branch_total (refinement_of_nat M RI) (branch_of_node node') active 0) (up (p++[i], 0))).
Proof.
-
have mval_b := rec_m_valid_branch t t' active branch p i down up flow_update branch_is
amval batird.
have mval_n := rec_m_valid_node t t' active branch p i down up flow_update branch_is
amval batird.
destruct branch.
+ have branch_destruct := branchcons_pl t p i.
have triv_equiv : (branch_of_pl t' (p, S i) ≡ branch_of_pl t' (p, S i)) by trivial.
have triv_equiv2 : (node_of_pl t' (p, i) ≡ node_of_pl t' (p, i)) by trivial.
have b_equiv : branch ≡ branch_of_pl t (p, S i)
by (apply branchcons_pl_inv_b with (n0 := n); symmetry; trivial).
have n_equiv : n ≡ node_of_pl t (p, i)
by (apply branchcons_pl_inv_n with (b := branch); symmetry; trivial).
setoid_rewrite branch'_is in branch'_is_trivial.
assert (branch_trivial (branch_of_pl t' (p, S i))) as rec_bt by
(apply rec_branch_branch_triv; trivial).
assert (node_trivial (node_of_pl t' (p, i))) as rec_nt by
(apply rec_branch_node_triv; trivial).
setoid_rewrite <- b_equiv in mval_b.
have IHbranch := specexc_branch_t t t' active branch (branch_of_pl t' (p, S i)) se p (S i)
down up flow_se flow_update b_equiv triv_equiv reserved_untouched mval_b rec_bt.
clear specexc_branch_t.
setoid_rewrite <- n_equiv in mval_n.
have IHnode := specexc_node_t t t' active n (node_of_pl t' (p, i)) se p i
down up flow_se flow_update n_equiv triv_equiv2 reserved_untouched mval_n rec_nt.
clear specexc_node_t.
setoid_rewrite branch_is in batird.
setoid_rewrite branch_destruct in batird.
rewrite branch_all_total_in_refinement_domain_unfold in batird.
destruct_ands.
rename H into natird.
rename H0 into batird.
setoid_rewrite <- n_equiv in natird.
setoid_rewrite <- b_equiv in batird.
have IHbranch' := IHbranch batird. clear IHbranch.
have IHnode' := IHnode natird. clear IHnode.
destruct_ands. rename H1 into Q1. rename H2 into Q2.
rename H into Q3. rename H0 into Q4.
setoid_rewrite branch_is. setoid_rewrite branch_destruct.
rewrite branch_total_unfold.
have myflow := flow_update p i.
unfold specific_flow_cond in myflow.
setoid_rewrite cellnode_pl.
setoid_rewrite cellnode_pl in myflow.
unfold node_total_minus_live in myflow.
unfold node_live in myflow.
setoid_rewrite branchcons_pl in Q1.
(*setoid_rewrite branchcons_pl in Q2.*)
setoid_rewrite b_equiv in Q2.
setoid_rewrite n_equiv in natird.
setoid_rewrite cellnode_pl in natird.
rewrite node_all_total_in_refinement_domain_unfold in natird.
rewrite node_total_unfold in natird.
rewrite cell_total_split in natird.
destruct_ands. rename H into ird.
assert ((cell_total_minus_live (cell_of_pl t (p, i)) active)
= (cell_total_minus_live (cell_of_pl t' (p, i)) active)) as ctml_pres
by (apply reserved_untouched).
setoid_rewrite branch_is in amval.
setoid_rewrite branchcons_pl in amval.
rewrite branch_total_unfold in amval.
setoid_rewrite cellnode_pl in amval.
rewrite node_total_unfold in amval.
rewrite cell_total_split in amval.
rewrite ctml_pres in amval.
setoid_rewrite branch_of_node_node_of_pl in Q4.
setoid_rewrite n_equiv in Q4.
setoid_rewrite branch_of_node_node_of_pl in Q4.
rewrite ctml_pres in myflow.
rewrite ctml_pres in ird.
rewrite <- tpcm_assoc in ird.
(*rewrite (branch_total_unfold (refinement_of_nat M RI) (BranchCons n' branch')).*)
split.
* setoid_rewrite branch'_is.
setoid_rewrite branchcons_pl.
rewrite branch_all_total_in_refinement_domain_unfold.
split.
-- setoid_rewrite cellnode_pl.
rewrite node_all_total_in_refinement_domain_unfold.
rewrite node_total_unfold.
split.
(* ++ setoid_rewrite cellnode_pl in Q3.
rewrite branch_all_total_in_refinement_domain_unfold in Q3.
unfold branch_of_node in Q3.
destruct (branch_of_pl t' (p ++ [i], 0)) eqn:ye.
** destruct Q3.
rewrite ye in H.*)
++ rewrite cell_total_split.
full_generalize
(branch_total (refinement_of_nat M RI) (branch_of_pl t (p, S i)) active (S i))
as k.
full_generalize
(branch_total (refinement_of_nat M RI) (branch_of_pl t' (p, S i)) active (S i))
as k'.
full_generalize (cell_live (cell_of_pl t (p, i))) as f.
full_generalize (cell_live (cell_of_pl t' (p, i))) as f'.
(*full_generalize (cell_total_minus_live (cell_of_pl t (p, i)) active) as z.*)
full_generalize (cell_total_minus_live (cell_of_pl t' (p, i)) active) as z.
full_generalize (branch_total (refinement_of_nat M RI) (branch_of_pl t (p ++ [i], 0)) active 0) as r.
full_generalize (branch_total (refinement_of_nat M RI) (branch_of_pl t' (p ++ [i], 0)) active 0) as r'.
full_generalize (down (p, S i)) as h.
full_generalize (up (p, S i)) as h'.
full_generalize (down (p, i)) as m.
full_generalize (up (p, i)) as m'.
full_generalize ((down (p ++ [i], 0))) as s.
full_generalize ((up(p ++ [i], 0))) as s'.
apply all_the_movs_ird
with (m:=m) (f:=f) (h:=h) (s:=s) (r:=r) (k:=k) (m':=m') (h':=h') (s':=s') (k':=k');
trivial.
** rewrite dot_cba. trivial.
++ setoid_rewrite cellnode_pl in Q3. unfold branch_of_node in Q3. trivial.
-- setoid_rewrite <- branchcons_pl in Q1. trivial.
*
(*
(*setoid_rewrite n_equiv.*)
rewrite branch_total_unfold.
(*setoid_rewrite b_equiv.*)
rewrite cell_total_split.
(*rewrite cell_total_split.*)
*)
setoid_rewrite branch'_is.
rewrite node_total_unfold.
setoid_rewrite (branchcons_pl t' p i).
rewrite (branch_total_unfold _ (BranchCons (node_of_pl t' (p, i)) (branch_of_pl t' (p, S i)))).
setoid_rewrite (cellnode_pl t' p i).
rewrite node_total_unfold.
rewrite cell_total_split.
rewrite cell_total_split.
rewrite ctml_pres.
full_generalize
(branch_total (refinement_of_nat M RI) (branch_of_pl t (p, S i)) active (S i))
as k.
full_generalize
(branch_total (refinement_of_nat M RI) (branch_of_pl t' (p, S i)) active (S i))
as k'.
full_generalize (cell_live (cell_of_pl t (p, i))) as f.
full_generalize (cell_live (cell_of_pl t' (p, i))) as f'.
(*full_generalize (cell_total_minus_live (cell_of_pl t (p, i)) active) as z.*)
full_generalize (cell_total_minus_live (cell_of_pl t' (p, i)) active) as z.
full_generalize (branch_total (refinement_of_nat M RI) (branch_of_pl t (p ++ [i], 0)) active 0) as r.
full_generalize (branch_total (refinement_of_nat M RI) (branch_of_pl t' (p ++ [i], 0)) active 0) as r'.
full_generalize (down (p, S i)) as h.
full_generalize (up (p, S i)) as h'.
full_generalize (down (p, i)) as m.
full_generalize (up (p, i)) as m'.
full_generalize ((down (p ++ [i], 0))) as s.
full_generalize ((up(p ++ [i], 0))) as s'.
apply all_the_movs with (h := h) (s := s) (h' := h') (s' := s'); trivial.
rewrite dot_cba. trivial.
+ eapply specexc_branch_tt with (t := t) (t' := t') (se:=se); trivial.
- clear specexc_node_t.
assert (branch_trivial (branch_of_pl t' (p ++ [i], 0))) as rec_bt
by (apply rec_node_branch_triv; setoid_rewrite <- node'_is; trivial).
destruct node, node'. rename b into branch. rename b0 into branch'.
assert (branch ≡ branch_of_pl t (p ++ [i], 0)) as branch1_equiv
by (apply cellnode_pl_inv_b with (c1 := c); symmetry; trivial).
assert (branch' ≡ branch_of_pl t' (p ++ [i], 0)) as branch2_equiv
by (apply cellnode_pl_inv_b with (c1 := c0); symmetry; trivial).
unfold branch_of_node in amval.
rewrite node_all_total_in_refinement_domain_unfold in batird.
destruct_ands. rename H into ird. rename H0 into batird.
setoid_rewrite <- branch2_equiv in rec_bt.
have Ihb := specexc_branch_t t t' active branch branch' se (p++[i]) 0 down up flow_se flow_update
branch1_equiv branch2_equiv reserved_untouched amval rec_bt batird.
destruct_ands.
repeat split; trivial.
Qed.
Lemma specexc_branch (t t': Branch M) (active: Lifetime) (branch branch': Branch M) (se: gset PathLoc) p i
(down up : PathLoc -> M)
(flow_se : ∀ p i , (p, i) ∉ se -> up (p, i) = unit /\ down (p, i) = unit)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(branch_is : branch ≡ branch_of_pl t (p, i))
(branch'_is : branch' ≡ branch_of_pl t' (p, i))
(reserved_untouched : ∀ pl, cell_total_minus_live (cell_of_pl t pl) active = cell_total_minus_live (cell_of_pl t' pl) active)
(amval : m_valid (dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i))))
(batird : branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch active i)
: branch_all_total_in_refinement_domain (refinement_of_nat M RI) branch' active i
/\ mov
(dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i)))
(dot (branch_total (refinement_of_nat M RI) branch' active i) (up (p, i)))
with specexc_node (t t': Branch M) (active: Lifetime) (node node': Node M) (se: gset PathLoc) p i
(down up : PathLoc -> M)
(flow_se : ∀ p i , (p, i) ∉ se -> up (p, i) = unit /\ down (p, i) = unit)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(node_is : node ≡ node_of_pl t (p, i))
(node'_is : node' ≡ node_of_pl t' (p, i))
(reserved_untouched : ∀ pl, cell_total_minus_live (cell_of_pl t pl) active = cell_total_minus_live (cell_of_pl t' pl) active)
(amval : m_valid (dot (branch_total (refinement_of_nat M RI) (branch_of_node node) active 0) (down (p++[i], 0))))
(batird : node_all_total_in_refinement_domain (refinement_of_nat M RI) node active i)
: branch_all_total_in_refinement_domain (refinement_of_nat M RI) (branch_of_node node') active 0
/\ mov
(dot (branch_total (refinement_of_nat M RI) (branch_of_node node) active 0) (down (p++[i], 0)))
(dot (branch_total (refinement_of_nat M RI) (branch_of_node node') active 0) (up (p++[i], 0))).
Proof.
- destruct branch'.
+ rename n into n'.
have branch_destruct := branchcons_pl t p i.
have triv_equiv : (branch_of_pl t (p, S i) ≡ branch_of_pl t (p, S i)) by trivial.
have triv_equiv2 : (node_of_pl t (p, i) ≡ node_of_pl t (p, i)) by trivial.
have b_equiv : branch' ≡ branch_of_pl t' (p, S i)
by (apply branchcons_pl_inv_b with (n := n'); symmetry; trivial).
have n_equiv : n' ≡ node_of_pl t' (p, i)
by (apply branchcons_pl_inv_n with (b := branch'); symmetry; trivial).
have mval_b := rec_m_valid_branch t t' active branch p i down up flow_update branch_is
amval batird.
have mval_n := rec_m_valid_node t t' active branch p i down up flow_update branch_is
amval batird.
have IHbranch := specexc_branch t t' active (branch_of_pl t (p, S i)) branch' se p (S i)
down up flow_se flow_update triv_equiv b_equiv reserved_untouched mval_b.
clear specexc_branch.
have IHnode := specexc_node t t' active (node_of_pl t (p, i)) n' se p i
down up flow_se flow_update triv_equiv2 n_equiv reserved_untouched mval_n.
clear specexc_node.
setoid_rewrite branch_is in batird.
setoid_rewrite branch_destruct in batird.
rewrite branch_all_total_in_refinement_domain_unfold in batird.
destruct_ands.
rename H into natird.
rename H0 into batird.
have IHbranch' := IHbranch batird. clear IHbranch.
have IHnode' := IHnode natird. clear IHnode.
destruct_ands. rename H1 into Q1. rename H2 into Q2.
rename H into Q3. rename H0 into Q4.
rewrite branch_all_total_in_refinement_domain_unfold.
enough (
(node_all_total_in_refinement_domain (refinement_of_nat M RI) n' active i)
∧ mov (dot (branch_total (refinement_of_nat M RI) branch active i) (down (p, i)))
(dot (branch_total (refinement_of_nat M RI) (BranchCons n' branch') active i)
(up (p, i))))
by (destruct_ands; repeat split; trivial).
setoid_rewrite branch_is. setoid_rewrite branch_destruct.
rewrite branch_total_unfold.
have myflow := flow_update p i.
unfold specific_flow_cond in myflow.
setoid_rewrite cellnode_pl.
setoid_rewrite cellnode_pl in myflow.
unfold node_total_minus_live in myflow.
rewrite (branch_total_unfold (refinement_of_nat M RI) (BranchCons n' branch')).
(*assert (node_all_total_in_refinement_domain (refinement_of_nat M RI) (node_of_pl t' (p, i)) active i <->
node_all_total_in_refinement_domain (refinement_of_nat M RI) n' active i) by (split; setoid_rewrite n_equiv; trivial).
rewrite <- H.*)
unfold node_live in myflow.
setoid_rewrite b_equiv in Q1.
setoid_rewrite b_equiv in Q2.
setoid_rewrite cellnode_pl in natird.
rewrite node_all_total_in_refinement_domain_unfold in natird.
rewrite node_total_unfold in natird.
rewrite cell_total_split in natird.
destruct_ands. rename H into ird.
assert ((cell_total_minus_live (cell_of_pl t (p, i)) active)
= (cell_total_minus_live (cell_of_pl t' (p, i)) active)) as ctml_pres
by (apply reserved_untouched).
setoid_rewrite branch_is in amval.
setoid_rewrite branchcons_pl in amval.
rewrite branch_total_unfold in amval.
setoid_rewrite cellnode_pl in amval.
rewrite node_total_unfold in amval.
rewrite cell_total_split in amval.
rewrite ctml_pres in amval.
setoid_rewrite branch_of_node_node_of_pl in Q4.
setoid_rewrite n_equiv in Q4.
setoid_rewrite branch_of_node_node_of_pl in Q4.
rewrite ctml_pres in myflow.
rewrite ctml_pres in ird.
rewrite <- tpcm_assoc in ird.
split.
* setoid_rewrite n_equiv.
setoid_rewrite cellnode_pl.
rewrite node_all_total_in_refinement_domain_unfold.
rewrite node_total_unfold.
split; trivial.
-- rewrite cell_total_split.
full_generalize
(branch_total (refinement_of_nat M RI) (branch_of_pl t (p, S i)) active (S i))
as k.
full_generalize
(branch_total (refinement_of_nat M RI) (branch_of_pl t' (p, S i)) active (S i))
as k'.
full_generalize (cell_live (cell_of_pl t (p, i))) as f.
full_generalize (cell_live (cell_of_pl t' (p, i))) as f'.
(*full_generalize (cell_total_minus_live (cell_of_pl t (p, i)) active) as z.*)
full_generalize (cell_total_minus_live (cell_of_pl t' (p, i)) active) as z.
full_generalize (branch_total (refinement_of_nat M RI) (branch_of_pl t (p ++ [i], 0)) active 0) as r.
full_generalize (branch_total (refinement_of_nat M RI) (branch_of_pl t' (p ++ [i], 0)) active 0) as r'.
full_generalize (down (p, S i)) as h.
full_generalize (up (p, S i)) as h'.
full_generalize (down (p, i)) as m.
full_generalize (up (p, i)) as m'.
full_generalize ((down (p ++ [i], 0))) as s.
full_generalize ((up(p ++ [i], 0))) as s'.
apply all_the_movs_ird
with (m:=m) (f:=f) (h:=h) (s:=s) (r:=r) (k:=k) (m':=m') (h':=h') (s':=s') (k':=k');
trivial.
rewrite dot_cba. trivial.
-- setoid_rewrite n_equiv in Q3.
setoid_rewrite cellnode_pl in Q3. trivial.
*
setoid_rewrite n_equiv.
rewrite node_total_unfold.
setoid_rewrite (cellnode_pl t' p i).
rewrite node_total_unfold.
setoid_rewrite b_equiv.
rewrite cell_total_split.
rewrite cell_total_split.
rewrite ctml_pres.
full_generalize
(branch_total (refinement_of_nat M RI) (branch_of_pl t (p, S i)) active (S i))
as k.
full_generalize
(branch_total (refinement_of_nat M RI) (branch_of_pl t' (p, S i)) active (S i))
as k'.
full_generalize (cell_live (cell_of_pl t (p, i))) as f.
full_generalize (cell_live (cell_of_pl t' (p, i))) as f'.
(*full_generalize (cell_total_minus_live (cell_of_pl t (p, i)) active) as z.*)
full_generalize (cell_total_minus_live (cell_of_pl t' (p, i)) active) as z.
full_generalize (branch_total (refinement_of_nat M RI) (branch_of_pl t (p ++ [i], 0)) active 0) as r.
full_generalize (branch_total (refinement_of_nat M RI) (branch_of_pl t' (p ++ [i], 0)) active 0) as r'.
full_generalize (down (p, S i)) as h.
full_generalize (up (p, S i)) as h'.
full_generalize (down (p, i)) as m.
full_generalize (up (p, i)) as m'.
full_generalize ((down (p ++ [i], 0))) as s.
full_generalize ((up(p ++ [i], 0))) as s'.
unfold specific_exchange_cond in myflow.
apply all_the_movs with (h := h) (s := s) (h' := h') (s' := s'); trivial.
rewrite dot_cba. trivial.
+ eapply specexc_branch_t with (t := t) (t' := t') (se := se); trivial.
unfold branch_trivial. trivial.
- clear specexc_node.
destruct node, node'. rename b into branch. rename b0 into branch'.
assert (branch ≡ branch_of_pl t (p ++ [i], 0)) as branch1_equiv
by (apply cellnode_pl_inv_b with (c1 := c); symmetry; trivial).
assert (branch' ≡ branch_of_pl t' (p ++ [i], 0)) as branch2_equiv
by (apply cellnode_pl_inv_b with (c1 := c0); symmetry; trivial).
unfold branch_of_node in amval.
rewrite node_all_total_in_refinement_domain_unfold in batird.
destruct_ands. rename H into ird. rename H0 into batird.
have Ihb := specexc_branch t t' active branch branch' se (p++[i]) 0 down up flow_se flow_update
branch1_equiv branch2_equiv reserved_untouched amval batird.
destruct_ands.
repeat split; trivial.
Qed.
Lemma valid_of_mov (x y : M) : m_valid x -> mov x y -> m_valid y.
Proof.
intros.
have h := mov_monotonic x y unit.
have j := h EqDecision0 TPCM0 EqDecision0 TPCM0.
rewrite unit_dot in j.
rewrite unit_dot in j.
have l := j H0 H. destruct_ands. trivial.
Qed.
Lemma specific_flows_preserve_branch_all_total_in_refinement_domain
(t t': Branch M) (active: Lifetime)
(se: gset PathLoc)
(down up : PathLoc -> M)
(flow_se : ∀ p i , (p, i) ∉ se -> up (p, i) = unit /\ down (p, i) = unit)
(flow_update : ∀ p i , specific_flow_cond p i t t' active down up)
(down_0 : down ([], 0) = unit)
(up_0 : up ([], 0) = unit)
(reserved_untouched : ∀ pl, cell_reserved (cell_of_pl t pl) ≡ cell_reserved (cell_of_pl t' pl))
(vts : valid_totals (refinement_of_nat M RI) t active)
: valid_totals (refinement_of_nat M RI) t' active.
Proof.
unfold valid_totals in *. destruct_ands.
assert ((∀ pl : PathLoc,
cell_total_minus_live (cell_of_pl t pl) active =
cell_total_minus_live (cell_of_pl t' pl) active)) as ru2.
- intros. have ru := reserved_untouched pl.
unfold cell_reserved in ru.
unfold cell_total_minus_live.
destruct (cell_of_pl t pl).
destruct (cell_of_pl t' pl).
setoid_rewrite ru.
trivial.
-
assert (t ≡ branch_of_pl t ([], 0)) as tb0 by (rewrite <- branch_of_pl_zero; trivial).
assert (t' ≡ branch_of_pl t' ([], 0)) as tb1 by (rewrite <- branch_of_pl_zero; trivial).
have h := specexc_branch t t' active t t' se [] 0 down up flow_se flow_update
tb0 tb1 ru2 _ _.
rewrite down_0 in h.
rewrite up_0 in h.
rewrite unit_dot in h.
rewrite unit_dot in h.
have j := h H0 H.
destruct_ands.
split; trivial.
apply valid_of_mov with (x := (branch_total (refinement_of_nat M RI) t active 0)); trivial.
Qed.
End ExchangeProof.
|
module residuo_interface
interface
subroutine residuo(a, b, u, r)
real(8), dimension(:,:), intent(in) :: a
real(8), dimension(:), intent(in) :: b
real(8), dimension(:), intent(in) :: u
real(8), dimension(:), intent(inout) :: r
end subroutine
end interface
end module
|
module MNIST.DataSet where
import MNIST.Prelude
import qualified Codec.Compression.GZip as GZip
import qualified Data.ByteString.Lazy as L
import qualified Data.Vector.Generic as G
import qualified Numeric.LinearAlgebra as HM
import qualified Numeric.LinearAlgebra.Static as SM
rows :: Int
rows = 28
cols :: Int
cols = 28
nPixels :: Int
nPixels = cols * rows
nLabels :: Int
nLabels = 10
_loadMNIST
:: FilePath
-> FilePath
-> IO [(Int, UVector Int)]
_loadMNIST dataPath labelPath =
runMaybeT (do
i <- MaybeT . fmap (decodeIDX . GZip.decompress) . L.readFile $ dataPath
l <- MaybeT . fmap (decodeIDXLabels . GZip.decompress) . L.readFile $ labelPath
d <- MaybeT . pure $ labeledIntData l i
return d)
>>= \case
Just mnist -> return mnist
Nothing -> throwString $
"couldn't read gzipped MNIST at data file " <> dataPath
<> " and label file " <> labelPath
loadMNISTTf :: FilePath -> FilePath -> IO [(Int, Vector Int)]
loadMNISTTf dp lp = _loadMNIST dp lp
>>= pure . fmap (identity *** G.convert)
trainingDataTf :: IO [(Int, Vector Int)]
trainingDataTf =
loadMNISTTf
"data/train-images-idx3-ubyte.gz"
"data/train-labels-idx1-ubyte.gz"
testDataTf :: IO [(Int, Vector Int)]
testDataTf =
loadMNISTTf
"data/t10k-images-idx3-ubyte.gz"
"data/t10k-labels-idx1-ubyte.gz"
-- ========================================================================= --
loadMNISTBp
:: FilePath
-> FilePath
-> IO [(R 784, R 9)]
loadMNISTBp dp lp = _loadMNIST dp lp
>>= pure . fmap ((fromJust . mkImage *** fromJust . mkLabel) . swap)
where
mkImage :: UVector Int -> Maybe (R 784)
mkImage u = SM.create . G.convert . G.map (\i -> fromIntegral i / 255) $ u
mkLabel :: Int -> Maybe (R 9)
mkLabel n = SM.create $ HM.build 9 (fromIntegral . fromEnum . (== n) . round)
trainingDataBp :: IO [(R 784, R 9)]
trainingDataBp =
loadMNISTBp
"data/train-images-idx3-ubyte.gz"
"data/train-labels-idx1-ubyte.gz"
testDataBp :: IO [(R 784, R 9)]
testDataBp =
loadMNISTBp
"data/t10k-images-idx3-ubyte.gz"
"data/t10k-labels-idx1-ubyte.gz"
|
example : ∃ n : Nat, n = n := by
refine ⟨?n, ?h⟩
case h => exact Eq.refl 3
example : ∃ n : Nat, n = n := by
refine ⟨?n, ?h⟩
case h => exact rfl
case n => exact 3
example : ∃ n : Nat, n = n := by
refine ⟨?n, by rfl⟩
case n => exact 3
example : ∃ n : Nat, n = n := by
refine ⟨?n, ?h⟩
case h =>
refine rfl
case n => exact 3
|
theory Exercises2_02
imports Main
begin
(*---------------- Exercise 2.2----------------*)
(* add function *)
fun add :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
"add m 0 = m" |
"add m (Suc n) = Suc(add m n)"
(* prove associativity of add *)
theorem add_associative : "add x (add y z) = add (add x y) z"
apply(induction z)
apply(auto)
done
(* prove commutativity of add *)
(* lemma 1*)
lemma add2zero : "add 0 x = x"
apply(induction x)
apply(auto)
done
(* lemma 2 *)
lemma suc_add : "Suc (add y x) = add (Suc y) x"
apply(induction x)
apply(auto)
done
theorem add_commutative : "add x y = add y x"
apply(induction y)
apply(auto)
apply(simp add: add2zero)
apply(simp add: suc_add)
done
(* double function *)
fun double :: "nat \<Rightarrow> nat" where
"double 0 = 0" |
"double (Suc m) = 2 + (double m)"
theorem double_add : "double m = add m m"
apply(induction m)
apply(auto)
apply(simp add: add_commutative)
done
end |
import set_theory.surreal
open pgame
namespace pgame
universe u
/-- An explicit description of the moves for Left in `x * y`. -/
def left_moves_mul {x y : pgame} : (x * y).left_moves
≃ x.left_moves × y.left_moves ⊕ x.right_moves × y.right_moves :=
by { cases x, cases y, refl, }
/-- An explicit description of the moves for Right in `x * y`. -/
def right_moves_mul {x y : pgame} : (x * y).right_moves
≃ x.left_moves × y.right_moves ⊕ x.right_moves × y.left_moves :=
by { cases x, cases y, refl, }
@[simp] lemma mk_mul_move_left_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).move_left (sum.inl (i,j))
= xL i * (mk yl yr yL yR) + (mk xl xr xL xR) * yL j - xL i * yL j
:= rfl
@[simp] lemma mul_move_left_inl {x y : pgame} {i j} :
(x * y).move_left ((@left_moves_mul x y).symm (sum.inl (i,j)))
= x.move_left i * y + x * y.move_left j - x.move_left i * y.move_left j
:= by {cases x, cases y, refl}
@[simp] lemma mk_mul_move_left_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).move_left (sum.inr (i,j))
= xR i * (mk yl yr yL yR) + (mk xl xr xL xR) * yR j - xR i * yR j
:= rfl
@[simp] lemma mul_move_left_inr {x y : pgame} {i j} :
(x * y).move_left ((@left_moves_mul x y).symm (sum.inr (i,j)))
= x.move_right i * y + x * y.move_right j - x.move_right i * y.move_right j
:= by {cases x, cases y, refl}
@[simp] lemma mk_mul_move_right_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).move_right (sum.inl (i,j))
= xL i * (mk yl yr yL yR) + (mk xl xr xL xR) * yR j - xL i * yR j
:= rfl
@[simp] lemma mul_move_right_inl {x y : pgame} {i j} :
(x * y).move_right ((@right_moves_mul x y).symm (sum.inr (i, j)))
= x.move_right i * y + x * y.move_left j - x.move_right i * y.move_left j
:= by {cases x, cases y, refl}
@[simp] lemma mk_mul_move_right_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).move_right (sum.inr (i,j))
= xR i * (mk yl yr yL yR) + (mk xl xr xL xR) * yL j - xR i * yL j
:= rfl
@[simp] lemma mul_move_right_inr {x y : pgame} {i j} :
(x * y).move_right ((@right_moves_mul x y).symm (sum.inr (i,j)))
= x.move_right i * y + x * y.move_left j - x.move_right i * y.move_left j
:= by {cases x, cases y, refl}
local infix ` ~ ` := relabelling
/-- `x * 0` has exactly the same moves as `0`. -/
theorem mul_zero_relabelling : Π (x : pgame), relabelling (x * 0) 0
| (mk xl xr xL xR) :=
⟨by fsplit; rintro (⟨_, ⟨⟩⟩ | ⟨_, ⟨⟩⟩),
by fsplit; rintro (⟨_, ⟨⟩⟩ | ⟨_, ⟨⟩⟩),
by rintro (⟨_, ⟨⟩⟩ | ⟨_, ⟨⟩⟩),
by rintro ⟨⟩⟩
/-- `x * 0` is equivalent to `0`. -/
lemma mul_zero_equiv (x : pgame) : (x * 0).equiv 0 :=
equiv_of_relabelling (mul_zero_relabelling x)
/-- `0 * x` has exactly the same moves as `0`. -/
theorem zero_mul_relabelling : Π (x : pgame), relabelling (0 * x) 0
| (mk xl xr xL xR) :=
⟨by fsplit; rintro (⟨⟨⟩, _⟩ | ⟨⟨⟩, _⟩),
by fsplit; rintro (⟨⟨⟩, _⟩ | ⟨⟨⟩, _⟩),
by rintro (⟨⟨⟩,_⟩ | ⟨⟨⟩,_⟩),
by rintro ⟨⟩⟩
/-- `0 * x` is equivalent to `0`. -/
lemma zero_mul_equiv (x : pgame) : (0 * x).equiv 0 :=
equiv_of_relabelling (zero_mul_relabelling x)
theorem sub_congr_relabelling {w x y z : pgame}
(h₁ : w.relabelling x) (h₂ : y.relabelling z) : (w - y).relabelling (x - z) :=
sorry
#check equiv.refl
def mul_one_relabelling : Π {x : pgame.{u}}, relabelling (x * 1) x
| (mk xl xr xL xR) :=
begin
refine ⟨_,_,_,_⟩,
calc
(mk xl xr xL xR * 1).left_moves
≃ xl × punit ⊕ xr × pempty : by refl
... ≃ xl × punit ⊕ pempty : equiv.sum_congr (equiv.refl _) (equiv.prod_pempty _)
... ≃ xl × punit : equiv.sum_pempty _
... ≃ xl : equiv.prod_punit _,
calc
(mk xl xr xL xR * 1).right_moves
≃ xl × pempty ⊕ xr × punit : by refl
... ≃ pempty ⊕ xr × punit : equiv.sum_congr (equiv.prod_pempty _) (equiv.refl _)
... ≃ xr × punit : equiv.pempty_sum _
... ≃ xr : equiv.prod_punit _,
rintros (⟨i, ⟨⟩⟩|⟨i, ⟨⟩⟩),
calc
xL i * 1 + mk xl xr xL xR * 0 - xL i * 0
~ xL i * 1 + mk xl xr xL xR * 0 - 0 : sub_congr_relabelling (relabelling.refl _) (mul_zero_relabelling _)
... ~ xL i * 1 + mk xl xr xL xR * 0 + (-0) : by refl
... ~ xL i * 1 + (mk xl xr xL xR * 0 + 0) : sorry
... ~ xL i * 1 + mk xl xr xL xR * 0 : sorry
... ~ xL i * 1 + 0 : sorry
... ~ xL i * 1 : sorry
... ~ xL i : mul_one_relabelling,
intro j,
calc
xR j * 1 + mk xl xr xL xR * 0 - xR j * 0
~ xR j * 1 + (mk xl xr xL xR * 0 - xR j * 0) : sorry
... ~ xR j * 1 + (mk xl xr xL xR * 0 - xR j * 0) : sorry
... ~ xR j * 1 + (mk xl xr xL xR - xR j) * 0 : sorry
... ~ xR j * 1 + 0 : sorry
... ~ xR j * 1 : by { refine add_zero_relabelling _ }
... ~ xR j : mul_one_relabelling,
end
using_well_founded { dec_tac := pgame_wf_tac }
example : ∀ (a b c : nat), a + b + c = a + ( b + c )
:= add_assoc
end pgame
example (a b c : Type) : a × (b ⊕ c) ≃ (a × b) ⊕ (a × c) :=
equiv.prod_sum_distrib a b c
|
[STATEMENT]
lemma no_ofail_wp_comb2 [wp_comb]:
"\<lbrakk> no_ofail P f; no_ofail P' f \<rbrakk> \<Longrightarrow> no_ofail (\<lambda>s. P s \<and> P' s) f"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<lbrakk>no_ofail P f; no_ofail P' f\<rbrakk> \<Longrightarrow> no_ofail (\<lambda>s. P s \<and> P' s) f
[PROOF STEP]
by (simp add: no_ofail_def) |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.