text
stringlengths 0
3.34M
|
---|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.mv_polynomial.default
import Mathlib.field_theory.finite.basic
import Mathlib.PostPort
universes u_1 u_2 u_3
namespace Mathlib
/-!
# The Chevalley–Warning theorem
This file contains a proof of the Chevalley–Warning theorem.
Throughout most of this file, `K` denotes a finite field
and `q` is notation for the cardinality of `K`.
## Main results
1. Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`)
such that the total degree of `f` is less than `(q-1)` times the cardinality of `σ`.
Then the evaluation of `f` on all points of `σ → K` (aka `K^σ`) sums to `0`.
(`sum_mv_polynomial_eq_zero`)
2. The Chevalley–Warning theorem (`char_dvd_card_solutions`).
Let `f i` be a finite family of multivariate polynomials
in finitely many variables (`X s`, `s : σ`) such that
the sum of the total degrees of the `f i` is less than the cardinality of `σ`.
Then the number of common solutions of the `f i`
is divisible by the characteristic of `K`.
## Notation
- `K` is a finite field
- `q` is notation for the cardinality of `K`
- `σ` is the indexing type for the variables of a multivariate polynomial ring over `K`
-/
theorem mv_polynomial.sum_mv_polynomial_eq_zero {K : Type u_1} {σ : Type u_2} [fintype K] [field K]
[fintype σ] [DecidableEq σ] (f : mv_polynomial σ K)
(h : mv_polynomial.total_degree f < (fintype.card K - 1) * fintype.card σ) :
(finset.sum finset.univ fun (x : σ → K) => coe_fn (mv_polynomial.eval x) f) = 0 :=
sorry
/-- The Chevalley–Warning theorem.
Let `(f i)` be a finite family of multivariate polynomials
in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`.
Assume that the sum of the total degrees of the `f i` is less than the cardinality of `σ`.
Then the number of common solutions of the `f i` is divisible by `p`. -/
theorem char_dvd_card_solutions_family {K : Type u_1} {σ : Type u_2} [fintype K] [field K]
[fintype σ] [DecidableEq K] [DecidableEq σ] (p : ℕ) [char_p K p] {ι : Type u_3} {s : finset ι}
{f : ι → mv_polynomial σ K}
(h : (finset.sum s fun (i : ι) => mv_polynomial.total_degree (f i)) < fintype.card σ) :
p ∣
fintype.card
(Subtype fun (x : σ → K) => ∀ (i : ι), i ∈ s → coe_fn (mv_polynomial.eval x) (f i) = 0) :=
sorry
/-- The Chevalley–Warning theorem.
Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`)
over a finite field of characteristic `p`.
Assume that the total degree of `f` is less than the cardinality of `σ`.
Then the number of solutions of `f` is divisible by `p`.
See `char_dvd_card_solutions_family` for a version that takes a family of polynomials `f i`. -/
theorem char_dvd_card_solutions {K : Type u_1} {σ : Type u_2} [fintype K] [field K] [fintype σ]
[DecidableEq K] [DecidableEq σ] (p : ℕ) [char_p K p] {f : mv_polynomial σ K}
(h : mv_polynomial.total_degree f < fintype.card σ) :
p ∣ fintype.card (Subtype fun (x : σ → K) => coe_fn (mv_polynomial.eval x) f = 0) :=
sorry
end Mathlib |
/-
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import measure_theory.measurable_space
import measure_theory.measure_space
import measure_theory.outer_measure
import measure_theory.lebesgue_measure
import measure_theory.integration
import measure_theory.set_integral
import measure_theory.borel_space
import data.set.countable
import formal_ml.nnreal
import formal_ml.sum
import formal_ml.core
import formal_ml.measurable_space
import formal_ml.semiring
import formal_ml.real_measurable_space
import formal_ml.set
import formal_ml.filter_util
import topology.instances.ennreal
import formal_ml.int
import formal_ml.lattice
import formal_ml.rat
--import formal_ml.with_density_compose_eq_multiply_part_one
/-
The simple way to think about a continuous random variable is as a
continuous function (a density function). Formally, this is the Radon-Nikodym derivative.
Using the operation with_density, one can transform this Radon-Nikodym derivative into
a measure using measure_theory.with_density, which is provided in measure_theory.integration
in mathlib. Specifically, one can write:
μ.with_density f
where μ is normally the Lebesgue measure on the real number line, and generate a probability
measure for a continuous density function.
In this file,
measure_theory.with_density.compose_eq_multiply connects the integration (or expectation) of
a function with respect to the probability measure derived from the density function with the
integral using the original base measure. So, if μ is again the base measure, f is the density
function, and g is the function we want to take the expectation of, then:
(μ.with_density f).integral g = μ.integral (f * g)
This is the familiar connection that we use to integrate functions of real random variables on
a regular basis.
-/
------------------------Theorems of ennreal -------------------------------------------
--Unnecessary
lemma le_coe_ne_top {x:nnreal} {y:ennreal}:y≤(x:ennreal) → y≠ ⊤ :=
begin
intro A1,
have A2:(x:ennreal)< ⊤,
{
apply with_top.coe_lt_top,
},
have A3:y < ⊤,
{
apply lt_of_le_of_lt,
apply A1,
apply A2,
},
rw ← lt_top_iff_ne_top,
apply A3,
end
--Unnecessary
lemma upper_bounds_nnreal (s : set ennreal) {x:nnreal} {y:ennreal}:
(x:ennreal) ∈ upper_bounds s → (y∈ s) → y≠ ⊤:=
begin
intros A1 A2,
rw mem_upper_bounds at A1,
have A3 := A1 y A2,
apply le_coe_ne_top A3,
end
--Unnecessary
lemma upper_bounds_nnreal_fn {α:Type*} {f:α → ennreal} {x:nnreal}:
(x:ennreal) ∈ upper_bounds (set.range f) → (∃ g:α → nnreal,
f = (λ a:α, (g a:ennreal))) :=
begin
intro A1,
let g:α → nnreal := λ a:α, ((f a).to_nnreal),
begin
have A2:g = λ a:α, ((f a).to_nnreal) := rfl,
apply exists.intro g,
rw A2,
ext a,
split;intro A3,
{
simp,
simp at A3,
rw A3,
rw ennreal.to_nnreal_coe,
},
{
simp,
simp at A3,
rw ← A3,
symmetry,
apply ennreal.coe_to_nnreal,
apply upper_bounds_nnreal,
apply A1,
simp,
},
end
end
------ Measure theory --------------------------------------------------------------------------
--Used EVERYWHERE.
lemma measure.apply {Ω:Type*} [M:measurable_space Ω] (μ:measure_theory.measure Ω) (S:set Ω):
μ S = μ.to_outer_measure.measure_of S :=
begin
refl
end
--Use in hahn.lean
--TODO: Can this be replaced with measure_theory.lintegral_supr?
--Look more closely: this is using supr_apply, which means it is more
--than just measure_theory.lintegral_supr.
lemma measure_theory.lintegral_supr2 {α : Type*}
[N:measurable_space α]
{μ:measure_theory.measure α}
{f : ℕ → α → ennreal}:
(∀ (n : ℕ), measurable (f n)) →
monotone f →
((∫⁻ a:α, (⨆ (n : ℕ), f n) a ∂ μ) =
⨆ (n : ℕ), (∫⁻ a:α, (f n) a ∂ μ)) :=
begin
intros A1 A2,
have A3:(λ a, (⨆ (n : ℕ), f n a)) = (⨆ (n : ℕ), f n),
{
apply funext,
intro a,
rw supr_apply,
},
rw ← A3,
apply measure_theory.lintegral_supr,
apply A1,
apply A2,
end
--Used in hahn.lean
lemma supr_indicator {Ω:Type*} (g:ℕ → Ω → ennreal) (S:set Ω):
(set.indicator S (supr g)) =
(⨆ (n : ℕ), (set.indicator S (g n))) :=
begin
apply funext,
intro ω,
rw (@supr_apply Ω (λ ω:Ω, ennreal) ℕ _ (λ n:ℕ, set.indicator S (g n)) ),
have A0:(λ (i : ℕ), (λ (n : ℕ), set.indicator S (g n)) i ω) =
(λ (i : ℕ), set.indicator S (g i) ω),
{
apply funext,
intro i,
simp,
},
rw A0,
have A1:ω ∈ S ∨ ω ∉ S ,
{
apply classical.em,
},
cases A1,
{
rw set.indicator_of_mem A1,
have B1A:(λ (i : ℕ), set.indicator S (g i) ω) =
(λ (i : ℕ), g i ω),
{
apply funext,
intro i,
rw set.indicator_of_mem A1,
},
rw B1A,
rw supr_apply,
},
{
rw set.indicator_of_not_mem A1,
have B1A:(λ (i : ℕ), set.indicator S (g i) ω) = (λ (i:ℕ), 0),
{
apply funext,
intro i,
rw set.indicator_of_not_mem A1,
},
rw B1A,
rw @supr_const ennreal ℕ _ _ 0,
},
end
--Used all over.
--Prefer measure_theory.with_density_apply
lemma measure_theory.with_density_apply2' {Ω:Type*} [M:measurable_space Ω] (μ:measure_theory.measure Ω) (f:Ω → ennreal) (S:set Ω):(measurable_set S) →
(μ.with_density f) S = (∫⁻ a:Ω, (set.indicator S f) a ∂ μ) :=
begin
intro A1,
rw measure_theory.with_density_apply f A1,
rw measure_theory.lintegral_indicator,
apply A1,
end
--Move to Radon-Nikodym (?)
lemma with_density.zero {Ω:Type*} [M:measurable_space Ω] (μ:measure_theory.measure Ω):
(μ.with_density 0) = 0 :=
begin
apply measure_theory.measure.ext,
intros S A1,
rw measure_theory.with_density_apply2',
{
simp,
},
{
apply A1,
}
end
|
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module CGX.Prelude
( module X
#if __GLASGOW_HASKELL__ <= 800
, fromLeft
, fromRight
#endif
, mk
, ps
, psu
) where
import qualified Data.Text as Text
import qualified Prelude
import Prelude as X
( Bounded(..)
, Enum(..)
, iterate
, maxBound
)
import Control.Applicative as X
( Applicative(..)
, (<$)
, (<$>)
, (<*)
, (*>)
, pure
)
import Control.Monad as X
( Functor
, Monad
, forever
, fmap
, liftM
, return
, when
, (>>=)
, (=<<)
, (>>)
)
import Control.Monad.State as X
( State
, get
, put
, runState
)
import Control.Exception.Base as X
( SomeException(..)
, handle
)
import Control.Concurrent as X
import Debug.Trace as X
( trace
, traceIO
, traceShow
)
import Safe as X
( headMay
, abort
)
import Data.Eq as X
import Data.Ord as X
import Data.Monoid as X
import Data.Traversable as X
import Data.Foldable as X hiding
( foldr1
, foldl1
, maximum
, maximumBy
, minimum
, minimumBy
)
import Data.Int as X
import Data.Bits as X
import Data.Word as X
import Data.Bool as X hiding (bool)
import Data.Char as X (Char)
import Data.Maybe as X hiding (fromJust)
import Data.Either as X
--import Data.Complex as X
import Data.Function as X
( id
, const
, (.)
, ($)
, flip
, fix
, on
)
import Data.Tuple as X
import Data.List as X
( filter
, intersect
, iterate
, reverse
, take
, takeWhile
, (\\)
, (++)
)
import Data.Text as X
( Text
, pack
)
import qualified Data.Text.Lazy
import qualified Data.Text.IO
import Data.String.Conv as X
( toS
)
import Data.IntMap as X (IntMap)
import Data.Tagged as X
import GHC.IO as X (IO)
import GHC.Num as X
import GHC.Real as X
import GHC.Float as X
import GHC.Generics as X
import GHC.Show as X
import GHC.Exts as X
( Constraint
, Ptr
, FunPtr
, the
)
#if __GLASGOW_HASKELL__ <= 800
fromLeft :: a -> Either a b -> a
fromLeft _ (Left a) = a
fromLeft a _ = a
fromRight :: b -> Either a b -> b
fromRight _ (Right b) = b
fromRight b _ = b
#endif
mk :: a -> Tagged b a
mk = X.Tagged
psu :: Show a => Tagged b a -> Text
psu = Text.pack . show . X.untag
ps :: Show a => a -> Text
ps = Text.pack . show
|
[STATEMENT]
lemma exec_bind_SE_success''':
"\<sigma> \<Turnstile> ((s \<leftarrow> A ; M s)) \<Longrightarrow> \<exists> a. (A \<sigma>) = Some a \<and> (snd a \<Turnstile> M (fst a))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<sigma> \<Turnstile> bind\<^sub>S\<^sub>E A M \<Longrightarrow> \<exists>a. A \<sigma> = Some a \<and> (snd a \<Turnstile> M (fst a))
[PROOF STEP]
apply(auto simp: valid_SE_def unit_SE_def bind_SE_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>a b. \<lbrakk>a; (case A \<sigma> of None \<Rightarrow> None | Some (xa, xb) \<Rightarrow> M xa xb) = Some (True, b)\<rbrakk> \<Longrightarrow> \<exists>a b. A \<sigma> = Some (a, b) \<and> (\<exists>aa ba. M a b = Some (aa, ba)) \<and> fst (the (M a b))
[PROOF STEP]
apply(cases "A \<sigma>", simp_all)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>a b aa. \<lbrakk>a; (case aa of (x, xa) \<Rightarrow> M x xa) = Some (True, b); A \<sigma> = Some aa\<rbrakk> \<Longrightarrow> \<exists>a b. aa = (a, b) \<and> (\<exists>aa ba. M a b = Some (aa, ba)) \<and> fst (the (M a b))
[PROOF STEP]
apply(drule_tac x="A \<sigma>" and f=the in arg_cong, simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>a b aa. \<lbrakk>a; (case aa of (x, xa) \<Rightarrow> M x xa) = Some (True, b); the (A \<sigma>) = aa\<rbrakk> \<Longrightarrow> \<exists>a b. aa = (a, b) \<and> (\<exists>aa ba. M a b = Some (aa, ba)) \<and> fst (the (M a b))
[PROOF STEP]
apply(rule_tac x="fst aa" in exI)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<And>a b aa. \<lbrakk>a; (case aa of (x, xa) \<Rightarrow> M x xa) = Some (True, b); the (A \<sigma>) = aa\<rbrakk> \<Longrightarrow> \<exists>b. aa = (fst aa, b) \<and> (\<exists>a ba. M (fst aa) b = Some (a, ba)) \<and> fst (the (M (fst aa) b))
[PROOF STEP]
apply(rule_tac x="snd aa" in exI, auto)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
using Bokeh
plotfile("functions.html")
plot(sin) # this uses the default range of -10 to 10
plot(sin, 0:20) # supply the rante
plot(x -> x^3 - 2x^2 + 3x, -5, 5) # also supplies the range
# the three plots above won't be shown since we haven't set hold, see below
plot([sin, cos, tan, sinh, cosh, tanh], -1:1)
showplot() |
= = Recovery = =
|
lemma closed_UNIV [continuous_intros, intro, simp]: "closed UNIV" |
-- Issue #2814 reported by tomjack on 2017-10-18
{-# OPTIONS --cubical --rewriting --confluence-check #-}
-- prelude stolen from Saizan/cubical-demo
open import Agda.Primitive.Cubical public
open import Agda.Builtin.Cubical.Path
Path = _≡_
refl : ∀ {ℓ} {A : Set ℓ} {x : A} → x ≡ x
refl {x = x} = λ _ → x
postulate
Rewrite : ∀ {ℓ} {A : Set ℓ} → A → A → Set
{-# BUILTIN REWRITE Rewrite #-}
module Good where
postulate
Unit : Set
unit : Unit
module UnitElim (P : Unit → Set) (unit* : P unit) where
postulate
Unit-elim : (x : Unit) → P x
unit-β : Rewrite (Unit-elim unit) unit*
open UnitElim public
{-# REWRITE unit-β #-}
test₁ : {C : Set} {c₀ : C} → Path {A = C} (Unit-elim (λ _ → C) c₀ unit) c₀
test₁ = refl
test₂ : {C : Set} {c₀ : C} → Path {A = Path c₀ c₀} (λ j → Unit-elim (λ _ → C) c₀ unit) refl
test₂ = refl
-- same code, but with a dummy module parameter
module Bad (Dummy : Set) where
postulate
Unit : Set
unit : Unit
module UnitElim (P : Unit → Set) (unit* : P unit) where
postulate
Unit-elim : (x : Unit) → P x
unit-β : Rewrite (Unit-elim unit) unit*
open UnitElim public
{-# REWRITE unit-β #-}
test₁ : {C : Set} {c₀ : C} → Path {A = C} (Unit-elim (λ _ → C) c₀ unit) c₀
test₁ = refl
test₂ : {C : Set} {c₀ : C} → Path {A = Path c₀ c₀} (λ j → Unit-elim (λ _ → C) c₀ unit) refl
test₂ = refl
-- WAS:
-- Unit-elim (λ _ → .C) .c₀ unit != .c₀ of type .C
-- when checking that the expression refl has type
-- Path (λ j → Unit-elim (λ _ → .C) .c₀ unit) refl
-- SHOULD: succeed
|
# Active Suppression of QML
Instead of designing the laser for stable mode-locking, we want to investigate how we could apply state feedback to the pump power to stabilize it.
We start from [linearized laser-dynamics] [linearized]:
[linearized]: ./Passively%20Mode-Locked%20Laser%20-%20Steady-State%20Dynamics.ipynb
```
from IPython.display import display
import sympy as sym
sym.init_printing(use_latex='mathjax')
w0, zeta, rho, Toc = sym.symbols('omega_0 zeta rho T_{oc}', real=True)
x = sym.MatrixSymbol('x', 2, 1)
xdot = sym.MatrixSymbol('xdot', 2, 1)
u = sym.MatrixSymbol('u', 1, 1)
A = sym.Matrix([[-2 * w0 * zeta, -w0],
[w0, 0, ]])
B = sym.Matrix([[rho * w0],
[0]])
xdot_ = sym.Eq(xdot, A * x + B * u)
xdot_
```
$$\dot{x} = \left[\begin{matrix}\omega_{0} \rho\\0\end{matrix}\right] u + \left[\begin{matrix}- 2 \omega_{0} \zeta & - \omega_{0}\\\omega_{0} & 0\end{matrix}\right] x$$
where
$ \vec{x} = \left[ \begin{array}{ccc}
\delta \dot{P} / \omega_0 \\
\delta P
\end{array}\right] $ and $ u = \left[ \delta P_P \right] $. $\rho$ is the internal slope efficiency, $\omega_0$ is the natural frequency, and $\zeta$ is the damping ratio of the system.
The output equation is chosen such that it provides the normal output (i.e. $\delta P_{out}$) and additionally the full state:
```
y = sym.MatrixSymbol('y', 3, 1)
C = sym.Matrix([[0, Toc],
[1, 0],
[0, 1]])
y_ = sym.Eq(y, C * x)
y_
```
$$y = \left[\begin{matrix}0 & T_{{oc}}\\1 & 0\\0 & 1\end{matrix}\right] x$$
where $T_{oc}$ is the output-coupling ratio.
# Pole Placement
(figure from Åström & Murray, <a href="http://www.cds.caltech.edu/~murray/books/AM05/pdf/am08-complete_22Feb09.pdf">"Feedback Systems"</a>, figure 6.5)
Now we apply feedback (almost) as shown in the figure. This means that
$ u = k_r \cdot r - K \cdot \vec{y} $
where $r$ is the control signal, $k_r$ is a constant, and $K = \left[0, k_1, k_2 \right]$ is the feedback matrix. Inserting this into the state equations yields:
$ \dot{\vec{x}} = (A - B K C) \vec{x} + B k_r r $
which is a new system $\dot{\vec{x}} = A' \vec{x} + B' r$ with
$ \begin{align*}
A' &= A - B K C \\
B' &= B k_r
\end{align*} $
```
kr = sym.Symbol('k_r')
r = sym.MatrixSymbol('r', 1, 1)
Ap = sym.MatrixSymbol("A'", 2, 2)
Bp = sym.MatrixSymbol("B'", 2, 1)
k1, k2 = sym.symbols('k_1 k_2', real=True)
K = sym.Matrix([[0, k1, k2]])
Ap_ = sym.Eq(Ap, A - B * K * C)
Bp_ = sym.Eq(Bp, B * kr)
display(Ap_, Bp_)
```
$$A' = \left[\begin{matrix}- k_{1} \omega_{0} \rho - 2 \omega_{0} \zeta & - k_{2} \omega_{0} \rho - \omega_{0}\\\omega_{0} & 0\end{matrix}\right]$$
$$B' = \left[\begin{matrix}k_{r} \omega_{0} \rho\\0\end{matrix}\right]$$
Our goal is to to choose $K$ so as to obtain arbitrary poles in the new system. The eigenvalues of $A'$ are:
```
ev = Ap_.rhs.eigenvects()
vals = [v[0] for v in ev]
gamma = sym.Symbol("\gamma", real=True)
gamma_ = sym.Eq(gamma, k1 * rho / 2 + zeta)
nu = sym.Symbol('\\nu', real=True)
nu_ = sym.Eq(nu, (k1 * rho)**2 / 4 + rho * (k1 * zeta - k2) + zeta**2 - 1)
vals = [sym.simplify(v.subs([(k2, sym.solve(nu_, k2)[0]),
(zeta, sym.solve(gamma_, zeta)[0])]))
for v in vals]
display(*vals)
```
$$- \gamma \omega_{0} - \sqrt{\nu} \left\lvert{\omega_{0}}\right\rvert$$
$$- \gamma \omega_{0} + \sqrt{\nu} \left\lvert{\omega_{0}}\right\rvert$$
where
```
display(gamma_, nu_)
```
$$\gamma = \frac{k_{1} \rho}{2} + \zeta$$
$$\nu = \frac{k_{1}^{2} \rho^{2}}{4} + \rho \left(k_{1} \zeta - k_{2}\right) + \zeta^{2} - 1$$
To obtain the poles as advertised above, $K$ has to be chosen as follows:
```
k1_ = sym.Eq(k1, sym.solve(gamma_, k1)[0])
k2_ = sym.Eq(k2, sym.solve(nu_.subs(k1_.lhs, k1_.rhs), k2)[0])
sym.Eq(sym.MatrixSymbol('K', 1, 3),
K.subs(k1_.lhs, k1_.rhs).subs(k2_.lhs, k2_.rhs))
```
$$K = \left[\begin{matrix}0 & \frac{1}{\rho} \left(2 \gamma - 2 \zeta\right) & \frac{1}{\rho} \left(\gamma^{2} - \nu - 1\right)\end{matrix}\right]$$
Finally, we require that the unit-step response on $\delta P$ is $\rho$, i.e. the same as in the uncontrolled system. To achieve that, we choose $k_r$ as follows:
```
dPstep = sym.simplify(-Ap_.rhs**-1 * Bp_.rhs)[1]
dPstep = dPstep.subs(k2_.lhs, k2_.rhs)
kr_ = sym.Eq(kr, sym.solve(sym.Eq(rho, dPstep), kr)[0])
kr_
```
$$k_{r} = \gamma^{2} - \nu$$
|
import M4R.Algebra.Ring.ChainProperties
namespace M4R
open Semiring localisation Ideal QuotientRing
class LocalRing (α : Type _) extends Ring α where
loc : ∃ m : Ideal α, Ring.MaxSpec α = Set.singleton m
namespace LocalRing
open Classical
variable {α : Type _} [LocalRing α]
noncomputable def m : Ideal α := choose LocalRing.loc
theorem m_maxspec : Ring.MaxSpec α = Set.singleton m := choose_spec LocalRing.loc
theorem m_max : (m : Ideal α).is_maximal := (m_maxspec ▸ rfl : m ∈ Ring.MaxSpec α)
theorem m_proper : (m : Ideal α).proper_ideal := m_max.left
theorem maximal_is_m {I : Ideal α} (hI : I.is_maximal) : I = m :=
(m_maxspec ▸ hI : I ∈ Set.singleton m)
theorem units {a : α} : isUnit a ↔ a ∉ m :=
⟨fun h₁ h₂ => absurd (is_unit_ideal'.mpr ⟨a, h₁, h₂⟩) m_proper,
not_imp_symm fun ha =>
let ⟨I, haI, hI⟩ := exists_maximal_containing (unit_not_principal ha)
maximal_is_m hI ▸ haI (generator_in_principal a)⟩
theorem not_unit {a : α} : ¬isUnit a ↔ a ∈ m := (iff_not_comm.mp units).symm
theorem subset_m {I : Ideal α} (hI : I.proper_ideal) : I ⊆ m :=
fun x hx => byContradiction fun h =>
absurd (Ideal.is_unit_ideal'.mpr ⟨x, units.mpr h, hx⟩) hI
theorem nontrivial (α : Type _) [LocalRing α] : Ring.is_NonTrivial α :=
fun h => units.mp (isUnit_1 : isUnit (1 : α)) (h ▸ m.has_zero)
def residue_field (α : Type _) [LocalRing α] := QClass (m : Ideal α)
instance localisation_at [Ring α] {P : Ideal α} (hP : P.is_prime) : LocalRing (localisationₚ hP) where
loc := ⟨localiseₚ hP P, Set.singleton.ext.mpr (localisationₚ.is_max hP)⟩
theorem localisation_at.m_def [Ring α] {P : Ideal α} (hP : P.is_prime) : localiseₚ hP P = m :=
maximal_is_m ((localisationₚ.is_max hP _).mpr rfl)
theorem jacobson_radical_eq_m (α : Type _) [LocalRing α] : Ring.jacobson_radical α = m :=
Ideal.antisymm (Ring.maximal_subset_jacobson m_max)
fun x hx => Ideal.sIntersection.mem.mpr fun I hI => maximal_is_m hI ▸ hx
theorem proper_subset_jacobson_radical [LocalRing α] {I : Ideal α} (hI : I.proper_ideal) : I ⊆ Ring.jacobson_radical α :=
jacobson_radical_eq_m α ▸ subset_m hI
instance quotient_LocalRing [LocalRing α] {I : Ideal α} (hI : I.proper_ideal) : LocalRing (QClass I) where
loc := ⟨extension (QuotientRing.natural_hom I).hom m, Set.ext.mp fun x => ⟨fun hx =>
quotient_contraction_injective ((quotient_extension_contraction (subset_m hI)).symm ▸
maximal_is_m (quotient_contraction_maximal hx)),
fun hx => hx ▸ Ideal.quotient_extension_maximal m_max (subset_m hI)⟩⟩
theorem quotient_LocalRing.m_def [LocalRing α] {I : Ideal α} (hI : I.proper_ideal) :
extension (QuotientRing.natural_hom I).hom m = @m _ (quotient_LocalRing hI) :=
@maximal_is_m _ (quotient_LocalRing hI) _ (quotient_extension_maximal m_max (subset_m hI))
end LocalRing
open LocalRing localisation_at Monoid Group NCSemiring CommMonoid
class NoetherianLocalRing (α : Type _) extends LocalRing α, NoetherianRing α
namespace NoetherianLocalRing
instance localisation_NoetherianLocalRing [NoetherianRing α] {P : Ideal α} (hP : P.is_prime) :
NoetherianLocalRing (localisationₚ hP) where
noetherian := NoetherianRing.localisation_noetherian (PrimeComp hP)
instance quotient_NotherianLocalRing [NoetherianLocalRing α] {I : Ideal α} (hI : I.proper_ideal) :
NoetherianLocalRing (QClass I) where
toLocalRing := quotient_LocalRing hI
noetherian := NoetherianRing.quotient_noetherian I
protected theorem m_finitely_generated (α : Type _) [NoetherianLocalRing α] : (m : Ideal α).finitely_generated :=
NoetherianRing.ideal_finitely_generated m
theorem local_krull_principal_ideal_theorem [NoetherianLocalRing α] {a : α}
(hP : m.minimal_prime_ideal_of (principal a)) : (m : Ideal α).height_le 1 :=
let RaR := QClass (principal a)
have : Ring.Spec RaR ⊆ Ring.MaxSpec RaR := fun Q hQ => by
let Q' := contractionᵣ₁ (QuotientRing.natural_hom (principal a)) Q
have h₁ : principal a ⊆ Q' := fun x hx => (natural_hom.kernel.mpr hx ▸ Q.has_zero :
QuotientRing.natural_hom (principal a) x ∈ Q)
have h₂ : Q'.is_prime := Ideal.contraction_prime _ hQ
have := quotient_extension_maximal m_max (subset_m hP.right_proper)
rw [←hP.right.right h₂ h₁ (subset_m h₂.left)] at this
exact contraction_extension_eq_of_surjective (QuotientRing.natural_hom (principal a)).preserve_mul_right
(natural_hom.surjective (principal a)) Q ▸ this
have : ∀ Q Q' : Ideal α, Q.is_prime → Q'.is_prime → Q' ⊊ Q → Q ⊊ m → False := fun Q Q' hQ hQ' hQ'Q hQm => by
have haQ : a ∉ Q := fun h => absurd (hP.right.right hQ (principal_in h) hQm.left) (Ideal.subsetneq.mp hQm).right
let c : chain RaR := fun n => extension (QuotientRing.natural_hom (principal a)) (symbolic_power hQ n.succ)
have hc : c.descending := fun n => extension.subset _ (symbolic_power.descending hQ n.succ)
let ⟨N, hN⟩ := ArtinianRing.artinian_of_primes_maximal this c hc
have he := quotient_extension_injective (hN N.succ (Nat.le_succ N))
have : symbolic_power hQ N.succ = symbolic_power hQ N.succ.succ + principal a * symbolic_power hQ N.succ :=
Ideal.antisymm (fun x hx =>
let ⟨i, hi, j, ⟨c, hc⟩, hij⟩ : x ∈ symbolic_power hQ N.succ.succ + principal a := he ▸ add.subset (symbolic_power hQ N.succ) (principal a) hx
⟨i, hi, j,
have : x - i = c * a := mul_comm a c ▸ hc ▸ Group.sub_eq.mpr (add_comm i j ▸ hij.symm)
have : c * a ∈ symbolic_power hQ N.succ := this ▸ (symbolic_power hQ N.succ).sub_closed hx (symbolic_power.descending hQ N.succ hi)
have := ((symbolic_power.primary hQ N.succ_ne_zero).right c a this).resolve_right
fun ha => absurd (symbolic_power.rad_eq hQ N.succ_ne_zero ▸ ha) haQ
from_set.contains_mem ⟨a, generator_in_principal a, c, this, hc.symm⟩, hij⟩)
(add.subset_add (symbolic_power.descending hQ N.succ) (product.subset_right))
have h₁ : extension (QuotientRing.natural_hom (symbolic_power hQ N.succ.succ)).hom m ⊆ Ring.jacobson_radical _ :=
@proper_subset_jacobson_radical _ (LocalRing.quotient_LocalRing (symbolic_power.primary hQ (N.succ.succ_ne_zero)).left) _
(quotient_extension_proper (Subset.trans (symbolic_power.subset_base hQ N.succ.succ_ne_zero) hQm.left) m_proper)
have h₂ : extension (QuotientRing.natural_hom (symbolic_power hQ N.succ.succ)).hom (symbolic_power hQ N.succ) =
extension (QuotientRing.natural_hom (symbolic_power hQ N.succ.succ)).hom (m * symbolic_power hQ N.succ) :=
Ideal.antisymm (by
conv => lhs rw [this, QuotientRing.natural_hom.extension_add_I]
exact extension.subset _ (Ideal.product.mul_subset_mul hP.right.left (Subset.refl _)))
(extension_mul _ _ _ ▸ product.subset_right)
rw [extension_mul] at h₂
have := Ideal.antisymm (quotient_extension_zero.mp (Ring.nakayama (NoetherianRing.ideal_finitely_generated _) h₁ h₂)) (symbolic_power.descending hQ N.succ)
have h₁ : localiseₚ hQ Q ⊆ Ring.jacobson_radical _ := by
rw [jacobson_radical_eq_m, localisation_at.m_def]; exact Subset.refl m
have h₂ : localiseₚ hQ Q ^ N.succ = localiseₚ hQ Q ^ N.succ.succ :=
((extension_pow (natural_homₚ hQ).toRMulMap Q N.succ_ne_zero).symm.trans ((extension_contraction_extension
(natural_homₚ hQ).preserve_mul_right (Q ^ N.succ)).trans ((congrArg (localiseₚ hQ) this).trans (extension_contraction_extension
(natural_homₚ hQ).preserve_mul_right (Q ^ N.succ.succ)).symm))).trans (extension_pow (natural_homₚ hQ).toRMulMap Q N.succ.succ_ne_zero)
conv at h₂ => rhs rw [pow_nat_succ, mul_comm]
have := congrArg Ideal.radical (Ring.nakayama (NoetherianRing.ideal_finitely_generated _) h₁ h₂)
rw [radical_pow_of_prime (localisationₚ.prime hQ) N.succ N.succ_ne_zero, Ring.nil_radical.def] at this
have : delocaliseₚ hQ (localiseₚ hQ Q) ⊆ delocaliseₚ hQ (localiseₚ hQ Q') := contraction.subset
(natural_homₚ hQ).preserve_mul_right (this ▸ Ring.nil_radical.eq_prime_intersection (localisationₚ hQ)
▸ Ideal.sIntersection.contains (localise_ideal.prime hQ' (PrimeComp.disjoint_subset hQ hQ'Q.left)))
exact absurd (Ideal.antisymm hQ'Q.left (localise_ideal.prime_loc_deloc hQ (PrimeComp.disjoint_subset hQ (Subset.refl Q))
▸ localise_ideal.prime_loc_deloc hQ' (PrimeComp.disjoint_subset hQ hQ'Q.left) ▸ this)) (Ideal.subsetneq.mp hQ'Q).right
height_le_of_strict_lt (maximal_is_prime m_max) fun c hc h => Classical.byContradiction fun he =>
this (c 1) (c 2) (hc.right.right 1) (hc.right.right 2) (Ideal.subsetneq.mpr ⟨hc.right.left 1, Ne.symm he⟩)
(Ideal.subsetneq.mpr (hc.left ▸ ⟨hc.right.left 0, (h 0 Nat.zero_lt_one).symm⟩))
theorem local_krull_height_theorem {α : Type u} [NoetherianLocalRing α] (f : Finset α) (hP : m.minimal_prime_ideal_of (from_set f.toSet))
(ih : ∀ m, m < f.length → ∀ (α : Type u) [NoetherianRing α] (f : Finset α) (hfm : f.length = m) (P : Ideal α),
P.minimal_prime_ideal_of (from_set f.toSet) → P.height_le f.length) : (m : Ideal α).height_le f.length :=
(f.length.le_or_lt 0).elim
(fun hf0 => by
have hf0 := Nat.le_zero.mp hf0
rw [Finset.eq_empty_of_length_eq_zero hf0] at hP
exact hf0 ▸ Ideal.height_le_of_eq (Ideal.height_eq_zero.mpr (from_set.empty ▸ hP)))
fun hf0 =>
/-
• sufficient to show height Q ≤ f.length - 1 for any prime ideal Q such that Q ⊊ m with no prime Q' in between (NOT Q ⊊ Q' ⊊ m)
• from_set f ⊈ Q as m is minimal prime, so f must contain at least one generator g ∉ Q
• use artinian_of_primes_maximal on R/(Q + principal g) (primes in R/(Q + gR) correspond to primes P in R s.t.
Q + gR ⊊ P (i.e. only m, which is also maximal in the quotient))
• artinian → nilradical nilpotent, and nilradical = m / (Q + gR) (⋂₀ of primes = {m})
• (m/(Q + gR)) ^ n = 0 → m ^ n ⊆ Q + gR → all generators in x ∈ f (apart from g) satisfy x ^ n ∈ Q + principal g,
i.e. xᵢ ^ n = dᵢ + rᵢg, xᵢ ∈ f ∖ { g }, dᵢ ∈ Q, rᵢ ∈ R
• any prime ideal containing all the dᵢ's and g must contain all of f, and so must equal m. Thus, letting d = {d₁, ..., dᵢ} (of length f.length-1),
we have : M / (from_set d) is a minimal prime ideal of principal (natural_hom (from_set d) g) (or principal g / (from_set d)?).
• Using krull_principal_ideal_theorem (maybe even local version?) we have height (m / (from_set d)) ≤ 1, and so Q must be a minimal prime of from_set d,
otherwise if there exists a prime Q' s.t. from_set d ⊆ Q' ⊊ Q, we would have Q' / (from_set d) ⊊ Q / (from_set d) ⊊ m / (from_set d),
violating the height condition.
• As Q is a minimal prime of from_set d (with d.length + 1 = f.length), ih gives height Q ≤ n - 1
-/
have : ∀ Q : Ideal α, Q.is_prime → Q ⊊ m → (∀ Q' : Ideal α, Q'.is_prime → Q ⊆ Q' → Q' ⊊ m → Q' ⊆ Q) → Q.height_le f.length.pred := fun Q hQ hQm hQmax => by
let ⟨g, hgf, hgQ⟩ : ∃ g : α, g ∈ f ∧ g ∉ Q := Classical.byContradiction fun h =>
absurd ((hP.right.right hQ (from_set.ideal_contained fun x hx => of_not_not (not_and.mp
(not_exists.mp h x) hx)) hQm.left) ▸ Subset.refl _) (ProperSubset.toNotSubset hQm)
have hprimes_maximal : Ring.Spec (QClass (Q + principal g)) ⊆ Ring.MaxSpec (QClass (Q + principal g)) := fun Q' hQ' =>
have := contraction_prime (QuotientRing.natural_hom (Q + principal g)) hQ'
Classical.byContradiction fun h' => absurd (Subset.trans (quotient_contraction_contains Q')
(hQmax _ this (Subset.trans (add.subset Q (principal g)) (quotient_contraction_contains Q'))
(Ideal.subsetneq.mpr ⟨subset_m this.left, fun h => absurd (quotient_of_contraction_maximal
(h ▸ m_max)) h'⟩)) (add.subset' _ _ (generator_in_principal g))) hgQ
have : Ring.MaxSpec (QClass (Q + principal g)) = Set.singleton (extension (QuotientRing.natural_hom (Q + principal g)).hom m) :=
Set.ext.mp fun I => ⟨fun hI => contraction_extension_eq_of_surjective (QuotientRing.natural_hom (Q + principal g)).preserve_mul_right
(natural_hom.surjective (Q + principal g)) I ▸ congrArg (extension (QuotientRing.natural_hom (Q + principal g)).hom ·)
(maximal_is_m (quotient_contraction_maximal hI)), fun hI => hI ▸ quotient_extension_maximal m_max (add.subset_add hQm.left
(principal_in (hP.right.left (from_set.contains_mem hgf))))⟩
let ⟨n, hn, hnm⟩ := ArtinianRing.nilradical_nilpotent (ArtinianRing.artinian_of_primes_maximal hprimes_maximal)
rw [Ring.nil_radical.eq_prime_intersection, Set.subset.antisymm hprimes_maximal (fun _ => maximal_is_prime),
this, sIntersection.single, ←extension_pow _ _ hn, quotient_extension_zero] at hnm
have hxQg : ∀ x ∈ f, x ^ n ∈ Q + principal g := fun x hx =>
hnm (product.pow_contains n (hP.right.left (from_set.contains_mem hx)))
let d : Finset α := ((f.erase g).elems.pmap (fun x hx => Classical.choose (hxQg x hx))
(fun x hx => (Finset.mem_erase.mp hx).right)).to_finset
have hdQ : from_set d.toSet ⊆ Q := from_set.ideal_contained fun x hx =>
let ⟨a, ha, hx⟩ := UnorderedList.mem_pmap.mp (UnorderedList.mem_to_finset.mp hx)
hx ▸ (Classical.choose_spec (hxQg a (Finset.mem_erase.mp ha).right)).left
have hdproper := proper_ideal_subset hdQ hQ.left
have : (extension (QuotientRing.natural_hom (from_set d.toSet)).hom m).minimal_prime_ideal_of
(principal (QuotientRing.natural_hom (from_set d.toSet) g)) :=
⟨quotient_extension_prime (maximal_is_prime m_max) (Subset.trans hdQ hQm.left),
from_set.contains_principal ⟨g, hP.right.left (from_set.contains_mem hgf), rfl⟩,
by
intro J hJ hgJ hJm
have : f.toSet ⊆ (contractionᵣ₁ (QuotientRing.natural_hom (from_set d.toSet)) J).subset := fun x hxf => by
byCases hxg : x = g
{ rw [←extension_principal] at hgJ
apply contraction.subset (QuotientRing.natural_hom (from_set d.toSet)).preserve_mul_right hgJ;
rw [←natural_hom.extension_add_I, hxg]
exact extension_contraction _ _ (add.subset' (from_set d.toSet) (principal g) (generator_in_principal g)) }
{ have := Classical.choose_spec (Classical.choose_spec (hxQg x hxf)).right;
exact prime_radical (contraction_prime (QuotientRing.natural_hom (from_set d.toSet)) hJ) x n hn
(this.right ▸ (contractionᵣ₁ (QuotientRing.natural_hom (from_set d.toSet)) J).add_closed
(quotient_contraction_contains J (from_set.contains_mem (UnorderedList.mem_to_finset.mpr
(UnorderedList.mem_pmap.mpr ⟨x, Finset.mem_erase.mpr ⟨hxg, hxf⟩, rfl⟩))))
(Subset.trans (extension_principal _ g ▸ extension_contraction _ _) (contraction.subset (QuotientRing.natural_hom
(from_set d.toSet)).preserve_mul_right hgJ) this.left)) }
have := hP.right.right (contraction_prime _ hJ) (from_set.ideal_contained this) (quotient_extension_contraction
(Subset.trans hdQ hQm.left) ▸ contraction.subset (QuotientRing.natural_hom (from_set d.toSet)).preserve_mul_right hJm)
exact contraction_extension_eq_of_surjective _ (natural_hom.surjective _) J ▸
congrArg (extension (QuotientRing.natural_hom (from_set d.toSet)).hom ·) this⟩
rw [quotient_LocalRing.m_def hdproper] at this
have := @local_krull_principal_ideal_theorem _ (quotient_NotherianLocalRing hdproper) _ this
have : Q.minimal_prime_ideal_of (from_set d.toSet) := ⟨hQ, hdQ, by
intro J hJ hdJ hJQ
exact Classical.byContradiction fun hneJQ => absurd this (Ideal.height_gt_one (quotient_extension_prime hJ hdJ)
(quotient_extension_prime hQ hdQ) (maximal_is_prime (@m_max _ (quotient_LocalRing hdproper)))
(quotient_extension_subsetneq hdJ (Ideal.subsetneq.mpr ⟨hJQ, hneJQ⟩))
(quotient_LocalRing.m_def hdproper ▸ quotient_extension_subsetneq hdQ hQm))⟩
have hdf : d.length < f.length := by
apply Nat.lt_of_le_of_lt (UnorderedList.to_finset_length_le _)
rw [UnorderedList.pmap_length]
conv => rhs rw [f.erase_cons hgf, Finset.length_cons]
exact Nat.lt.base _
exact Q.height_le_trans (Nat.le_of_succ_le_succ (Nat.succ_pred_eq_of_pos hf0 ▸ hdf))
(ih d.length hdf α d rfl Q this)
Nat.succ_pred_eq_of_pos hf0 ▸ height_le_succ (maximal_is_prime m_max) fun Q hQ hQm =>
let ⟨P, ⟨hP, hPm, hQP⟩, hPmax⟩ := @NoetherianRing.exists_maximal _ _ {P : Ideal α | P.is_prime ∧ P ⊊ m ∧ Q ⊆ P} ⟨Q, hQ, hQm, Subset.refl Q⟩
have := this P hP hPm (fun Q' hQ' hPQ' hQm' => hPmax Q' ⟨hQ', hQm', Subset.trans hQP hPQ'⟩ hPQ' ▸ Subset.refl _)
height_le_subset hQ hQP this
end NoetherianLocalRing
namespace NoetherianRing
theorem krull_principal_ideal_theorem [NoetherianRing α] {a : α}
{P : Ideal α} (hP : P.minimal_prime_ideal_of (principal a)) : P.height_le 1 :=
have : m.minimal_prime_ideal_of (principal (natural_homₚ hP.left a)) :=
localise_ideal.principal _ a ▸ m_def hP.left ▸ minimal_prime_localisation
hP (PrimeComp.disjoint hP.left)
local_height_le hP.left (PrimeComp.disjoint hP.left) 1 (m_def hP.left ▸
NoetherianLocalRing.local_krull_principal_ideal_theorem this : height_le (localiseₚ hP.left P) 1)
theorem krull_height_theorem [NoetherianRing α] {f : Finset α} {P : Ideal α}
(hP : P.minimal_prime_ideal_of (from_set f.toSet)) : P.height_le f.length :=
Nat.strong_induction (fun n => ∀ (α : Type _) [NoetherianRing α] (f : Finset α) (hfn : f.length = n) (P : Ideal α),
P.minimal_prime_ideal_of (from_set f.toSet) → P.height_le f.length)
(fun n ih α hα f hfn P hP =>
let f' : Finset (localisationₚ hP.left) := (f.map (natural_homₚ hP.left)).to_finset
have hf' : f'.length ≤ f.length := f.length_map (natural_homₚ hP.left).hom ▸
(f.map (natural_homₚ hP.left).hom).to_finset_length_le
have : m.minimal_prime_ideal_of (from_set f'.toSet) := by
exact extension_from_finset (natural_homₚ hP.left).preserve_mul_right f ▸ m_def hP.left
▸ minimal_prime_localisation hP (PrimeComp.disjoint hP.left)
have := NoetherianLocalRing.local_krull_height_theorem f' this (fun m hm => ih m (hfn ▸ Nat.lt_of_lt_of_le hm hf'))
P.height_le_trans hf' (local_height_le hP.left (PrimeComp.disjoint hP.left) f'.length (m_def hP.left ▸ this :
height_le (localiseₚ hP.left P) f'.length))) f.length α f rfl P hP
end NoetherianRing
namespace NoetherianLocalRing
protected theorem has_krull_dim (α : Type _) [NoetherianLocalRing α] : Ring.krull_dim.has_krull_dim α :=
let ⟨f, hf⟩ := NoetherianLocalRing.m_finitely_generated α
Ring.krull_dim.has_krull_dim_of_maximal_height_le ⟨m, m_max⟩ f.length fun M hM =>
NoetherianRing.krull_height_theorem (maximal_is_m hM ▸ hf ▸ minimal_prime_of_prime (maximal_is_prime m_max))
end NoetherianLocalRing
class RegularLocalRing (α : Type _) extends NoetherianLocalRing α where
regular : (NoetherianLocalRing.m_finitely_generated α).minimal_generator_count =
Ring.krull_dim.dim (NoetherianLocalRing.has_krull_dim α)
end M4R
|
The MGB @-@ 314 replied in a coded response obtained from a German trawler boarded during the <unk> raid . A few bursts were fired from a shore battery and both Campbeltown and MGB @-@ 314 replied : " Ship being fired upon by friendly forces " . The deception gave them a little more time before every German gun in the bay opened fire . At 01 : 28 , with the convoy 1 mile ( 1 @.@ 6 km ) from the dock gates , Beattie ordered the German flag lowered and the White Ensign raised . The intensity of the German fire seemed to increase . The guard ship opened fire and was quickly silenced when the ships in the convoy responded , shooting into her as they passed .
|
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
s : Sphere P
⊢ { center := s.center, radius := s.radius } = s
[PROOFSTEP]
ext
[GOAL]
case center
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
s : Sphere P
⊢ { center := s.center, radius := s.radius }.center = s.center
[PROOFSTEP]
rfl
[GOAL]
case radius
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
s : Sphere P
⊢ { center := s.center, radius := s.radius }.radius = s.radius
[PROOFSTEP]
rfl
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
s₁ s₂ : Sphere P
⊢ s₁ ≠ s₂ ↔ s₁.center ≠ s₂.center ∨ s₁.radius ≠ s₂.radius
[PROOFSTEP]
rw [← not_and_or, ← Sphere.ext_iff]
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
s₁ s₂ : Sphere P
p : P
hs₁ : p ∈ s₁
hs₂ : p ∈ s₂
⊢ s₁.center = s₂.center ↔ s₁ = s₂
[PROOFSTEP]
refine' ⟨fun h => Sphere.ext _ _ h _, fun h => h ▸ rfl⟩
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
s₁ s₂ : Sphere P
p : P
hs₁ : p ∈ s₁
hs₂ : p ∈ s₂
h : s₁.center = s₂.center
⊢ s₁.radius = s₂.radius
[PROOFSTEP]
rw [mem_sphere] at hs₁ hs₂
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
s₁ s₂ : Sphere P
p : P
hs₁ : dist p s₁.center = s₁.radius
hs₂ : dist p s₂.center = s₂.radius
h : s₁.center = s₂.center
⊢ s₁.radius = s₂.radius
[PROOFSTEP]
rw [← hs₁, ← hs₂, h]
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
p₁ p₂ : P
s : Sphere P
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
⊢ dist p₁ s.center = dist p₂ s.center
[PROOFSTEP]
rw [mem_sphere.1 hp₁, mem_sphere.1 hp₂]
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
p₁ p₂ : P
s : Sphere P
hp₁ : p₁ ∈ s
hp₂ : p₂ ∈ s
⊢ dist s.center p₁ = dist s.center p₂
[PROOFSTEP]
rw [mem_sphere'.1 hp₁, mem_sphere'.1 hp₂]
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
ps : Set P
⊢ Cospherical ps ↔ ∃ s, ps ⊆ Metric.sphere s.center s.radius
[PROOFSTEP]
refine' ⟨fun h => _, fun h => _⟩
[GOAL]
case refine'_1
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
ps : Set P
h : Cospherical ps
⊢ ∃ s, ps ⊆ Metric.sphere s.center s.radius
[PROOFSTEP]
rcases h with ⟨c, r, h⟩
[GOAL]
case refine'_1.intro.intro
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
ps : Set P
c : P
r : ℝ
h : ∀ (p : P), p ∈ ps → dist p c = r
⊢ ∃ s, ps ⊆ Metric.sphere s.center s.radius
[PROOFSTEP]
exact ⟨⟨c, r⟩, h⟩
[GOAL]
case refine'_2
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
ps : Set P
h : ∃ s, ps ⊆ Metric.sphere s.center s.radius
⊢ Cospherical ps
[PROOFSTEP]
rcases h with ⟨s, h⟩
[GOAL]
case refine'_2.intro
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
ps : Set P
s : Sphere P
h : ps ⊆ Metric.sphere s.center s.radius
⊢ Cospherical ps
[PROOFSTEP]
exact ⟨s.center, s.radius, h⟩
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
ps₁ ps₂ : Set P
hs : ps₁ ⊆ ps₂
hc : Cospherical ps₂
⊢ Cospherical ps₁
[PROOFSTEP]
rcases hc with ⟨c, r, hcr⟩
[GOAL]
case intro.intro
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
ps₁ ps₂ : Set P
hs : ps₁ ⊆ ps₂
c : P
r : ℝ
hcr : ∀ (p : P), p ∈ ps₂ → dist p c = r
⊢ Cospherical ps₁
[PROOFSTEP]
exact ⟨c, r, fun p hp => hcr p (hs hp)⟩
[GOAL]
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
p : P
⊢ Cospherical {p}
[PROOFSTEP]
use p
[GOAL]
case h
V : Type u_1
P : Type u_2
inst✝ : MetricSpace P
p : P
⊢ ∃ radius, ∀ (p_1 : P), p_1 ∈ {p} → dist p_1 p = radius
[PROOFSTEP]
simp
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : NormedSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
p₁ p₂ : P
⊢ ∀ (p : P), p ∈ {p₁, p₂} → dist p (midpoint ℝ p₁ p₂) = ‖2‖⁻¹ * dist p₁ p₂
[PROOFSTEP]
rintro p (rfl | rfl | _)
[GOAL]
case inl
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : NormedSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
p₂ p : P
⊢ dist p (midpoint ℝ p p₂) = ‖2‖⁻¹ * dist p p₂
[PROOFSTEP]
rw [dist_comm, dist_midpoint_left (𝕜 := ℝ)]
[GOAL]
case inr.refl
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : NormedSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
p₁ p₂ : P
⊢ dist p₂ (midpoint ℝ p₁ p₂) = ‖2‖⁻¹ * dist p₁ p₂
[PROOFSTEP]
rw [dist_comm, dist_midpoint_right (𝕜 := ℝ)]
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
⊢ AffineIndependent ℝ p
[PROOFSTEP]
rw [affineIndependent_iff_not_collinear]
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
⊢ ¬Collinear ℝ (Set.range p)
[PROOFSTEP]
intro hc
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
hc : Collinear ℝ (Set.range p)
⊢ False
[PROOFSTEP]
rw [collinear_iff_of_mem (Set.mem_range_self (0 : Fin 3))] at hc
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
hc : ∃ v, ∀ (p_1 : P), p_1 ∈ Set.range p → ∃ r, p_1 = r • v +ᵥ p 0
⊢ False
[PROOFSTEP]
rcases hc with ⟨v, hv⟩
[GOAL]
case intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (p_1 : P), p_1 ∈ Set.range p → ∃ r, p_1 = r • v +ᵥ p 0
⊢ False
[PROOFSTEP]
rw [Set.forall_range_iff] at hv
[GOAL]
case intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
⊢ False
[PROOFSTEP]
have hv0 : v ≠ 0 := by
intro h
have he : p 1 = p 0 := by simpa [h] using hv 1
exact (by decide : (1 : Fin 3) ≠ 0) (hpi he)
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
⊢ v ≠ 0
[PROOFSTEP]
intro h
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
h : v = 0
⊢ False
[PROOFSTEP]
have he : p 1 = p 0 := by simpa [h] using hv 1
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
h : v = 0
⊢ p 1 = p 0
[PROOFSTEP]
simpa [h] using hv 1
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
h : v = 0
he : p 1 = p 0
⊢ False
[PROOFSTEP]
exact (by decide : (1 : Fin 3) ≠ 0) (hpi he)
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
h : v = 0
he : p 1 = p 0
⊢ 1 ≠ 0
[PROOFSTEP]
decide
[GOAL]
case intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
hv0 : v ≠ 0
⊢ False
[PROOFSTEP]
rcases hs with ⟨c, r, hs⟩
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
⊢ False
[PROOFSTEP]
have hs' := fun i => hs (p i) (Set.mem_of_mem_of_subset (Set.mem_range_self _) hps)
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv : ∀ (i : Fin 3), ∃ r, p i = r • v +ᵥ p 0
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
⊢ False
[PROOFSTEP]
choose f hf using hv
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
⊢ False
[PROOFSTEP]
have hsd : ∀ i, dist (f i • v +ᵥ p 0) c = r := by
intro i
rw [← hf]
exact hs' i
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
⊢ ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
[PROOFSTEP]
intro i
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
i : Fin 3
⊢ dist (f i • v +ᵥ p 0) c = r
[PROOFSTEP]
rw [← hf]
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
i : Fin 3
⊢ dist (p i) c = r
[PROOFSTEP]
exact hs' i
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
⊢ False
[PROOFSTEP]
have hf0 : f 0 = 0 := by
have hf0' := hf 0
rw [eq_comm, ← @vsub_eq_zero_iff_eq V, vadd_vsub, smul_eq_zero] at hf0'
simpa [hv0] using hf0'
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
⊢ f 0 = 0
[PROOFSTEP]
have hf0' := hf 0
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
hf0' : p 0 = f 0 • v +ᵥ p 0
⊢ f 0 = 0
[PROOFSTEP]
rw [eq_comm, ← @vsub_eq_zero_iff_eq V, vadd_vsub, smul_eq_zero] at hf0'
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
hf0' : f 0 = 0 ∨ v = 0
⊢ f 0 = 0
[PROOFSTEP]
simpa [hv0] using hf0'
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
hf0 : f 0 = 0
⊢ False
[PROOFSTEP]
have hfi : Function.Injective f := by
intro i j h
have hi := hf i
rw [h, ← hf j] at hi
exact hpi hi
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
hf0 : f 0 = 0
⊢ Function.Injective f
[PROOFSTEP]
intro i j h
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
hf0 : f 0 = 0
i j : Fin 3
h : f i = f j
⊢ i = j
[PROOFSTEP]
have hi := hf i
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
hf0 : f 0 = 0
i j : Fin 3
h : f i = f j
hi : p i = f i • v +ᵥ p 0
⊢ i = j
[PROOFSTEP]
rw [h, ← hf j] at hi
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
hf0 : f 0 = 0
i j : Fin 3
h : f i = f j
hi : p i = p j
⊢ i = j
[PROOFSTEP]
exact hpi hi
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hsd : ∀ (i : Fin 3), dist (f i • v +ᵥ p 0) c = r
hf0 : f 0 = 0
hfi : Function.Injective f
⊢ False
[PROOFSTEP]
simp_rw [← hsd 0, hf0, zero_smul, zero_vadd, dist_smul_vadd_eq_dist (p 0) c hv0] at hsd
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
⊢ False
[PROOFSTEP]
have hfn0 : ∀ i, i ≠ 0 → f i ≠ 0 := fun i => (hfi.ne_iff' hf0).2
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
⊢ False
[PROOFSTEP]
have hfn0' : ∀ i, i ≠ 0 → f i = -2 * ⟪v, p 0 -ᵥ c⟫ / ⟪v, v⟫ :=
by
intro i hi
have hsdi := hsd i
simpa [hfn0, hi] using hsdi
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
⊢ ∀ (i : Fin 3), i ≠ 0 → f i = -2 * inner v (p 0 -ᵥ c) / inner v v
[PROOFSTEP]
intro i hi
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
i : Fin 3
hi : i ≠ 0
⊢ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
[PROOFSTEP]
have hsdi := hsd i
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
i : Fin 3
hi : i ≠ 0
hsdi : f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
⊢ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
[PROOFSTEP]
simpa [hfn0, hi] using hsdi
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
hfn0' : ∀ (i : Fin 3), i ≠ 0 → f i = -2 * inner v (p 0 -ᵥ c) / inner v v
⊢ False
[PROOFSTEP]
have hf12 : f 1 = f 2 := by rw [hfn0' 1 (by decide), hfn0' 2 (by decide)]
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
hfn0' : ∀ (i : Fin 3), i ≠ 0 → f i = -2 * inner v (p 0 -ᵥ c) / inner v v
⊢ f 1 = f 2
[PROOFSTEP]
rw [hfn0' 1 (by decide), hfn0' 2 (by decide)]
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
hfn0' : ∀ (i : Fin 3), i ≠ 0 → f i = -2 * inner v (p 0 -ᵥ c) / inner v v
⊢ 1 ≠ 0
[PROOFSTEP]
decide
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
hfn0' : ∀ (i : Fin 3), i ≠ 0 → f i = -2 * inner v (p 0 -ᵥ c) / inner v v
⊢ 2 ≠ 0
[PROOFSTEP]
decide
[GOAL]
case intro.intro.intro
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
hfn0' : ∀ (i : Fin 3), i ≠ 0 → f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hf12 : f 1 = f 2
⊢ False
[PROOFSTEP]
exact (by decide : (1 : Fin 3) ≠ 2) (hfi hf12)
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
p : Fin 3 → P
hps : Set.range p ⊆ s
hpi : Function.Injective p
v : V
hv0 : v ≠ 0
c : P
r : ℝ
hs : ∀ (p : P), p ∈ s → dist p c = r
hs' : ∀ (i : Fin 3), dist (p i) c = r
f : Fin 3 → ℝ
hf : ∀ (i : Fin 3), p i = f i • v +ᵥ p 0
hf0 : f 0 = 0
hfi : Function.Injective f
hsd : ∀ (i : Fin 3), f i = 0 ∨ f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hfn0 : ∀ (i : Fin 3), i ≠ 0 → f i ≠ 0
hfn0' : ∀ (i : Fin 3), i ≠ 0 → f i = -2 * inner v (p 0 -ᵥ c) / inner v v
hf12 : f 1 = f 2
⊢ 1 ≠ 2
[PROOFSTEP]
decide
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p₁ p₂ p₃ : P
h₁ : p₁ ∈ s
h₂ : p₂ ∈ s
h₃ : p₃ ∈ s
h₁₂ : p₁ ≠ p₂
h₁₃ : p₁ ≠ p₃
h₂₃ : p₂ ≠ p₃
⊢ AffineIndependent ℝ ![p₁, p₂, p₃]
[PROOFSTEP]
refine' hs.affineIndependent _ _
[GOAL]
case refine'_1
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p₁ p₂ p₃ : P
h₁ : p₁ ∈ s
h₂ : p₂ ∈ s
h₃ : p₃ ∈ s
h₁₂ : p₁ ≠ p₂
h₁₃ : p₁ ≠ p₃
h₂₃ : p₂ ≠ p₃
⊢ Set.range ![p₁, p₂, p₃] ⊆ s
[PROOFSTEP]
simp [h₁, h₂, h₃, Set.insert_subset_iff]
[GOAL]
case refine'_2
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p₁ p₂ p₃ : P
h₁ : p₁ ∈ s
h₂ : p₂ ∈ s
h₃ : p₃ ∈ s
h₁₂ : p₁ ≠ p₂
h₁₃ : p₁ ≠ p₃
h₂₃ : p₂ ≠ p₃
⊢ Function.Injective ![p₁, p₂, p₃]
[PROOFSTEP]
erw [Fin.cons_injective_iff, Fin.cons_injective_iff]
[GOAL]
case refine'_2
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Set P
hs : Cospherical s
p₁ p₂ p₃ : P
h₁ : p₁ ∈ s
h₂ : p₂ ∈ s
h₃ : p₃ ∈ s
h₁₂ : p₁ ≠ p₂
h₁₃ : p₁ ≠ p₃
h₂₃ : p₂ ≠ p₃
⊢ ¬p₁ ∈ Set.range ![p₂, p₃] ∧ ¬p₂ ∈ Set.range ![p₃] ∧ Function.Injective ![p₃]
[PROOFSTEP]
simp [h₁₂, h₁₃, h₂₃, Function.Injective]
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center ≤ s.radius
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center) ∨ p₁ = p₂
[PROOFSTEP]
by_cases h : p₁ = p₂
[GOAL]
case pos
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center ≤ s.radius
h : p₁ = p₂
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center) ∨ p₁ = p₂
[PROOFSTEP]
exact Or.inr h
[GOAL]
case neg
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center) ∨ p₁ = p₂
[PROOFSTEP]
refine' Or.inl _
[GOAL]
case neg
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
[PROOFSTEP]
rw [mem_sphere] at hp₁
[GOAL]
case neg
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
[PROOFSTEP]
rw [← vsub_sub_vsub_cancel_right p₁ p₂ s.center, inner_sub_left, real_inner_self_eq_norm_mul_norm, sub_pos]
[GOAL]
case neg
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
⊢ inner (p₂ -ᵥ s.center) (p₁ -ᵥ s.center) < ‖p₁ -ᵥ s.center‖ * ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
refine' lt_of_le_of_ne ((real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right _ (norm_nonneg _))) _
[GOAL]
case neg.refine'_1
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
⊢ ‖p₂ -ᵥ s.center‖ ≤ ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
rwa [← dist_eq_norm_vsub, ← dist_eq_norm_vsub, hp₁]
[GOAL]
case neg.refine'_2
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
⊢ inner (p₂ -ᵥ s.center) (p₁ -ᵥ s.center) ≠ ‖p₁ -ᵥ s.center‖ * ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
rcases hp₂.lt_or_eq with (hp₂' | hp₂')
[GOAL]
case neg.refine'_2.inl
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
hp₂' : dist p₂ s.center < s.radius
⊢ inner (p₂ -ᵥ s.center) (p₁ -ᵥ s.center) ≠ ‖p₁ -ᵥ s.center‖ * ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
refine' ((real_inner_le_norm _ _).trans_lt (mul_lt_mul_of_pos_right _ _)).ne
[GOAL]
case neg.refine'_2.inl.refine'_1
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
hp₂' : dist p₂ s.center < s.radius
⊢ ‖p₂ -ᵥ s.center‖ < ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
rwa [← hp₁, @dist_eq_norm_vsub V, @dist_eq_norm_vsub V] at hp₂'
[GOAL]
case neg.refine'_2.inl.refine'_2
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
hp₂' : dist p₂ s.center < s.radius
⊢ 0 < ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
rw [norm_pos_iff, vsub_ne_zero]
[GOAL]
case neg.refine'_2.inl.refine'_2
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
hp₂' : dist p₂ s.center < s.radius
⊢ p₁ ≠ s.center
[PROOFSTEP]
rintro rfl
[GOAL]
case neg.refine'_2.inl.refine'_2
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₂ : P
hp₂ : dist p₂ s.center ≤ s.radius
hp₂' : dist p₂ s.center < s.radius
hp₁ : dist s.center s.center = s.radius
h : ¬s.center = p₂
⊢ False
[PROOFSTEP]
rw [← hp₁] at hp₂'
[GOAL]
case neg.refine'_2.inl.refine'_2
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₂ : P
hp₂ : dist p₂ s.center ≤ s.radius
hp₂' : dist p₂ s.center < dist s.center s.center
hp₁ : dist s.center s.center = s.radius
h : ¬s.center = p₂
⊢ False
[PROOFSTEP]
refine' (dist_nonneg.not_lt : ¬dist p₂ s.center < 0) _
[GOAL]
case neg.refine'_2.inl.refine'_2
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₂ : P
hp₂ : dist p₂ s.center ≤ s.radius
hp₂' : dist p₂ s.center < dist s.center s.center
hp₁ : dist s.center s.center = s.radius
h : ¬s.center = p₂
⊢ dist p₂ s.center < 0
[PROOFSTEP]
simpa using hp₂'
[GOAL]
case neg.refine'_2.inr
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
hp₂' : dist p₂ s.center = s.radius
⊢ inner (p₂ -ᵥ s.center) (p₁ -ᵥ s.center) ≠ ‖p₁ -ᵥ s.center‖ * ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
rw [← hp₁, @dist_eq_norm_vsub V, @dist_eq_norm_vsub V] at hp₂'
[GOAL]
case neg.refine'_2.inr
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
hp₂' : ‖p₂ -ᵥ s.center‖ = ‖p₁ -ᵥ s.center‖
⊢ inner (p₂ -ᵥ s.center) (p₁ -ᵥ s.center) ≠ ‖p₁ -ᵥ s.center‖ * ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
nth_rw 1 [← hp₂']
[GOAL]
case neg.refine'_2.inr
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
hp₂' : ‖p₂ -ᵥ s.center‖ = ‖p₁ -ᵥ s.center‖
⊢ inner (p₂ -ᵥ s.center) (p₁ -ᵥ s.center) ≠ ‖p₂ -ᵥ s.center‖ * ‖p₁ -ᵥ s.center‖
[PROOFSTEP]
rw [Ne.def, inner_eq_norm_mul_iff_real, hp₂', ← sub_eq_zero, ← smul_sub, vsub_sub_vsub_cancel_right, ← Ne.def,
smul_ne_zero_iff, vsub_ne_zero, and_iff_left (Ne.symm h), norm_ne_zero_iff, vsub_ne_zero]
[GOAL]
case neg.refine'_2.inr
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₁ s.center = s.radius
hp₂ : dist p₂ s.center ≤ s.radius
h : ¬p₁ = p₂
hp₂' : ‖p₂ -ᵥ s.center‖ = ‖p₁ -ᵥ s.center‖
⊢ p₁ ≠ s.center
[PROOFSTEP]
rintro rfl
[GOAL]
case neg.refine'_2.inr
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₂ : P
hp₂ : dist p₂ s.center ≤ s.radius
hp₁ : dist s.center s.center = s.radius
h : ¬s.center = p₂
hp₂' : ‖p₂ -ᵥ s.center‖ = ‖s.center -ᵥ s.center‖
⊢ False
[PROOFSTEP]
refine' h (Eq.symm _)
[GOAL]
case neg.refine'_2.inr
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₂ : P
hp₂ : dist p₂ s.center ≤ s.radius
hp₁ : dist s.center s.center = s.radius
h : ¬s.center = p₂
hp₂' : ‖p₂ -ᵥ s.center‖ = ‖s.center -ᵥ s.center‖
⊢ p₂ = s.center
[PROOFSTEP]
simpa using hp₂'
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center ≤ s.radius
⊢ 0 ≤ inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
[PROOFSTEP]
rcases inner_pos_or_eq_of_dist_le_radius hp₁ hp₂ with (h | rfl)
[GOAL]
case inl
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center ≤ s.radius
h : 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
⊢ 0 ≤ inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
[PROOFSTEP]
exact h.le
[GOAL]
case inr
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₁ s.center ≤ s.radius
⊢ 0 ≤ inner (p₁ -ᵥ p₁) (p₁ -ᵥ s.center)
[PROOFSTEP]
simp
[GOAL]
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center < s.radius
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
[PROOFSTEP]
by_cases h : p₁ = p₂
[GOAL]
case pos
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center < s.radius
h : p₁ = p₂
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
[PROOFSTEP]
rw [h, mem_sphere] at hp₁
[GOAL]
case pos
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : dist p₂ s.center = s.radius
hp₂ : dist p₂ s.center < s.radius
h : p₁ = p₂
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
[PROOFSTEP]
exact False.elim (hp₂.ne hp₁)
[GOAL]
case neg
V : Type u_1
P : Type u_2
inst✝³ : NormedAddCommGroup V
inst✝² : InnerProductSpace ℝ V
inst✝¹ : MetricSpace P
inst✝ : NormedAddTorsor V P
s : Sphere P
p₁ p₂ : P
hp₁ : p₁ ∈ s
hp₂ : dist p₂ s.center < s.radius
h : ¬p₁ = p₂
⊢ 0 < inner (p₁ -ᵥ p₂) (p₁ -ᵥ s.center)
[PROOFSTEP]
exact (inner_pos_or_eq_of_dist_le_radius hp₁ hp₂.le).resolve_right h
|
import Mathbin.Data.Nat.Basic
lemma Nat.le_eq_LessThanOrEqual : Nat.le = Nat.LessThanOrEqual := by
ext m n
constructor
· intro h
induction h with
| refl => apply Nat.LessThanOrEqual.refl
| step _ h => apply Nat.LessThanOrEqual.step h
· intro h
induction h with
| refl => apply Nat.le.refl
| step _ h => apply Nat.le.step h
lemma Nat.hasLt_eq_instLTNat : Nat.hasLt = instLTNat := by
simp only [Nat.le_eq_LessThanOrEqual, Nat.hasLt, instLTNat, Nat.lt]
|
The Protein Naming Utility
|
(************************************************************************)
(* v * The Coq Proof Assistant / The Coq Development Team *)
(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2011 *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
(* Evgeny Makarov, INRIA, 2007 *)
(************************************************************************)
(*i $Id: NBase.v 14641 2011-11-06 11:59:10Z herbelin $ i*)
Require Export Decidable.
Require Export NAxioms.
Require Import NZProperties.
Module NBasePropFunct (Import N : NAxiomsSig').
(** First, we import all known facts about both natural numbers and integers. *)
Include NZPropFunct N.
(** We prove that the successor of a number is not zero by defining a
function (by recursion) that maps 0 to false and the successor to true *)
Definition if_zero (A : Type) (a b : A) (n : N.t) : A :=
recursion a (fun _ _ => b) n.
Implicit Arguments if_zero [A].
Instance if_zero_wd (A : Type) :
Proper (Logic.eq ==> Logic.eq ==> N.eq ==> Logic.eq) (@if_zero A).
Proof.
intros; unfold if_zero.
repeat red; intros. apply recursion_wd; auto. repeat red; auto.
Qed.
Theorem if_zero_0 : forall (A : Type) (a b : A), if_zero a b 0 = a.
Proof.
unfold if_zero; intros; now rewrite recursion_0.
Qed.
Theorem if_zero_succ :
forall (A : Type) (a b : A) (n : N.t), if_zero a b (S n) = b.
Proof.
intros; unfold if_zero.
now rewrite recursion_succ.
Qed.
Theorem neq_succ_0 : forall n, S n ~= 0.
Proof.
intros n H.
generalize (Logic.eq_refl (if_zero false true 0)).
rewrite <- H at 1. rewrite if_zero_0, if_zero_succ; discriminate.
Qed.
Theorem neq_0_succ : forall n, 0 ~= S n.
Proof.
intro n; apply neq_sym; apply neq_succ_0.
Qed.
(** Next, we show that all numbers are nonnegative and recover regular
induction from the bidirectional induction on NZ *)
Theorem le_0_l : forall n, 0 <= n.
Proof.
nzinduct n.
now apply eq_le_incl.
intro n; split.
apply le_le_succ_r.
intro H; apply -> le_succ_r in H; destruct H as [H | H].
assumption.
symmetry in H; false_hyp H neq_succ_0.
Qed.
Theorem induction :
forall A : N.t -> Prop, Proper (N.eq==>iff) A ->
A 0 -> (forall n, A n -> A (S n)) -> forall n, A n.
Proof.
intros A A_wd A0 AS n; apply right_induction with 0; try assumption.
intros; auto; apply le_0_l. apply le_0_l.
Qed.
(** The theorems [bi_induction], [central_induction] and the tactic [nzinduct]
refer to bidirectional induction, which is not useful on natural
numbers. Therefore, we define a new induction tactic for natural numbers.
We do not have to call "Declare Left Step" and "Declare Right Step"
commands again, since the data for stepl and stepr tactics is inherited
from NZ. *)
Ltac induct n := induction_maker n ltac:(apply induction).
Theorem case_analysis :
forall A : N.t -> Prop, Proper (N.eq==>iff) A ->
A 0 -> (forall n, A (S n)) -> forall n, A n.
Proof.
intros; apply induction; auto.
Qed.
Ltac cases n := induction_maker n ltac:(apply case_analysis).
Theorem neq_0 : ~ forall n, n == 0.
Proof.
intro H; apply (neq_succ_0 0). apply H.
Qed.
Theorem neq_0_r : forall n, n ~= 0 <-> exists m, n == S m.
Proof.
cases n. split; intro H;
[now elim H | destruct H as [m H]; symmetry in H; false_hyp H neq_succ_0].
intro n; split; intro H; [now exists n | apply neq_succ_0].
Qed.
Theorem zero_or_succ : forall n, n == 0 \/ exists m, n == S m.
Proof.
cases n.
now left.
intro n; right; now exists n.
Qed.
Theorem eq_pred_0 : forall n, P n == 0 <-> n == 0 \/ n == 1.
Proof.
cases n.
rewrite pred_0. setoid_replace (0 == 1) with False using relation iff. tauto.
split; intro H; [symmetry in H; false_hyp H neq_succ_0 | elim H].
intro n. rewrite pred_succ.
setoid_replace (S n == 0) with False using relation iff by
(apply -> neg_false; apply neq_succ_0).
rewrite succ_inj_wd. tauto.
Qed.
Theorem succ_pred : forall n, n ~= 0 -> S (P n) == n.
Proof.
cases n.
intro H; exfalso; now apply H.
intros; now rewrite pred_succ.
Qed.
Theorem pred_inj : forall n m, n ~= 0 -> m ~= 0 -> P n == P m -> n == m.
Proof.
intros n m; cases n.
intros H; exfalso; now apply H.
intros n _; cases m.
intros H; exfalso; now apply H.
intros m H2 H3. do 2 rewrite pred_succ in H3. now rewrite H3.
Qed.
(** The following induction principle is useful for reasoning about, e.g.,
Fibonacci numbers *)
Section PairInduction.
Variable A : N.t -> Prop.
Hypothesis A_wd : Proper (N.eq==>iff) A.
Theorem pair_induction :
A 0 -> A 1 ->
(forall n, A n -> A (S n) -> A (S (S n))) -> forall n, A n.
Proof.
intros until 3.
assert (D : forall n, A n /\ A (S n)); [ |intro n; exact (proj1 (D n))].
induct n; [ | intros n [IH1 IH2]]; auto.
Qed.
End PairInduction.
(** The following is useful for reasoning about, e.g., Ackermann function *)
Section TwoDimensionalInduction.
Variable R : N.t -> N.t -> Prop.
Hypothesis R_wd : Proper (N.eq==>N.eq==>iff) R.
Theorem two_dim_induction :
R 0 0 ->
(forall n m, R n m -> R n (S m)) ->
(forall n, (forall m, R n m) -> R (S n) 0) -> forall n m, R n m.
Proof.
intros H1 H2 H3. induct n.
induct m.
exact H1. exact (H2 0).
intros n IH. induct m.
now apply H3. exact (H2 (S n)).
Qed.
End TwoDimensionalInduction.
Section DoubleInduction.
Variable R : N.t -> N.t -> Prop.
Hypothesis R_wd : Proper (N.eq==>N.eq==>iff) R.
Theorem double_induction :
(forall m, R 0 m) ->
(forall n, R (S n) 0) ->
(forall n m, R n m -> R (S n) (S m)) -> forall n m, R n m.
Proof.
intros H1 H2 H3; induct n; auto.
intros n H; cases m; auto.
Qed.
End DoubleInduction.
Ltac double_induct n m :=
try intros until n;
try intros until m;
pattern n, m; apply double_induction; clear n m;
[solve_relation_wd | | | ].
End NBasePropFunct.
|
/-
Copyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : María Inés de Frutos-Fernández
-/
import data.real.basic -- Importamos los números reales.
/-!
Algunos de estos ejemplos se han adaptado de la charla de estructuras y classes de LftCM 2022:
<https://icerm.brown.edu/video_archive/?play=2897>
-/
noncomputable theory
/-! # Clases
Referencia : Theorem Proving in Lean.
Cualquier estructura en Lean se puede marcar como una *clase de tipos*.
Podemos declarar *instancias* de una clase.
Cuando el elaborador está buscando un elemento de una clase, puede consultar una tabla con las
instancias declaradas para encontrar un elemento apropiado.
-/
/-! ## Variables -/
--En Lean, podemos usar distintos tipos de variables
variable (r : ℝ) -- variable explícita.
variable {n : ℕ} -- variable implícita. Para argumentos que se pueden inferir a partir de otros.
variable (G : Type*)
variable [group G] -- argumentos entre `[ ]` son inferidos por el mecanismo de inferencia de clases.
/- Las variables que acabamos de declarar estarán visibles hasta el final del fichero. No es posible
tener dos variables visibles con el mismo nombre.
Podemos modificar este comportamiento utilizando secciones:
-/
section ejemplo
variable (a : ℕ)
--variable (a : ℝ) -- da error
end ejemplo
variable (a : ℕ)
-- Ejemplos
lemma nat.add_pos (n m : ℕ) (hm : 0 < m) :
0 < n + m :=
sorry
lemma nat.add_pos' (n : ℕ) {m : ℕ} (hm : 0 < m) :
0 < n + m :=
sorry
example (n m : ℕ) (hm : 0 < m) :
0 < m + n :=
begin
rw add_comm, -- ¿por qué funciona esto?
sorry
--exact nat.add_pos n m hm,
--exact nat.add_pos n _ hm, -- Lean puede deducir m a partir de hm
--exact nat.add_pos' n hm -- con la segunda variante, la barra _ no es necesara.
end
/- ¿Por qué hemos podido utilizar `add_comm` en el ejemplo anterior?
`add_comm` es un teorema sobre semigrupos aditivos conmutativos.
Lean ha encontrado automáticamente la estructura de semigrupo de `ℕ`, mediante un proceso
llamado *inferencia de clases*. -/
/- Cualquier estructura en Lean se puede marcar como una *clase de tipos*. Por ejemplo,
`add_group` es la clase de grupos aditivos. -/
--#check add_group
/- Podemos declarar *instancias* de una clase. Por ejemplo, la estructura de grupo aditivo de `ℤ`
está registrada en la instancia `int.add_group`. -/
--#check int.add_group
/-Cuando el elaborador está buscando un elemento de una clase, puede consultar una tabla con las
instancias declaradas para encontrar un elemento apropiado. -/
--#check add_comm -- tiene un argumento [add_comm_semigroup G]
/- En Lean utilizamos clases para registrar estructuras algebraicas, topológicas, analíticas, ... -/
-- Ejemplo: Podemos crear una clase para indicar que un tipo es no vacío.
class no_vacio (A : Type) : Prop :=
(has_val : ∃ x : A, true)
instance : no_vacio ℤ :=
{ has_val := ⟨0, trivial⟩ }
instance {A B : Type} [ha : no_vacio A] [hb : no_vacio B] :
no_vacio (A × B) :=
begin
cases ha.has_val with a _,
cases hb.has_val with b _,
apply no_vacio.mk,
use (a, b)
end
-- Ejemplo
instance producto_de_grupos {G H : Type*} [group G] [group H] : group (G × H) := infer_instance
|
theory prop_54
imports Main
"$HIPSTER_HOME/IsaHipster"
begin
datatype Nat = Z | S "Nat"
fun plus :: "Nat => Nat => Nat" where
"plus (Z) y = y"
| "plus (S z) y = S (plus z y)"
fun minus :: "Nat => Nat => Nat" where
"minus (Z) y = Z"
| "minus (S z) (Z) = S z"
| "minus (S z) (S x2) = minus z x2"
(*hipster plus minus *)
(*hipster minus*)
lemma lemma_am [thy_expl]: "minus x2 x2 = Z"
apply (hipster_induct_schemes minus.simps)
done
lemma lemma_aam [thy_expl]: "minus x3 Z = x3"
by (hipster_induct_schemes minus.simps)
lemma lemma_abm [thy_expl]: "minus x2 (S x2) = Z"
by (hipster_induct_schemes)
lemma lemma_acm [thy_expl]: "minus (S x2) x2 = S Z"
by (hipster_induct_schemes)
lemma lemma_adm [thy_expl]: "minus (minus x3 y3) (minus y3 x3) = minus x3 y3"
by (hipster_induct_schemes minus.simps)
lemma lemma_aem [thy_expl]: "minus (minus x3 y3) (S Z) = minus x3 (S y3)"
by (hipster_induct_schemes minus.simps)
lemma lemma_afm [thy_expl]: "minus (minus x4 y4) x4 = Z"
by (hipster_induct_schemes minus.simps)
(*hipster plus*)
lemma lemma_a [thy_expl]: "plus x2 Z = x2"
by (hipster_induct_schemes plus.simps)
lemma lemma_aa [thy_expl]: "plus (plus x2 y2) z2 = plus x2 (plus y2 z2)"
by (hipster_induct_schemes plus.simps)
lemma lemma_ab [thy_expl]: "plus x2 (S y2) = S (plus x2 y2)"
by (hipster_induct_schemes plus.simps)
lemma lemma_ac [thy_expl]: "plus x1 (plus y1 x1) = plus y1 (plus x1 x1)"
by (hipster_induct_schemes plus.simps)
lemma lemma_ad [thy_expl]: "plus x2 (plus y2 y2) = plus y2 (plus y2 x2)"
by (hipster_induct_schemes plus.simps)
lemma lemma_ae [thy_expl]: "plus x2 (S y2) = S (plus y2 x2)"
by (hipster_induct_schemes plus.simps)
lemma lemma_af [thy_expl]: "plus (S x2) y2 = S (plus y2 x2)"
by (hipster_induct_schemes plus.simps)
lemma lemma_ag [thy_expl]: "plus (plus x2 y2) (plus x2 z2) = plus (plus x2 z2) (plus x2 y2)"
by (hipster_induct_schemes plus.simps Nat.exhaust)
lemma lemma_ah [thy_expl]: "plus (plus x2 y2) (plus z2 x2) = plus (plus z2 x2) (plus x2 y2)"
by (hipster_induct_schemes plus.simps)
lemma lemma_ai [thy_expl]: "plus x2 (plus y2 z2) = plus y2 (plus z2 x2)"
by (hipster_induct_schemes plus.simps)
theorem x0 :
"(minus (plus m n) n) = m"
by (hipster_induct_schemes plus.simps minus.simps)
(*
by (tactic {* Subgoal.FOCUS_PARAMS (K (Tactic_Data.hard_tac @{context})) @{context} 1 *})*)
end
|
`is_element/BW1` := eval(`is_element/prime_simplex`);
`is_equal/BW1` := eval(`is_equal/prime_simplex`);
`is_leq/BW1` := NULL;
`random_element/BW1` := eval(`random_element/prime_simplex`);
`list_elements/BW1` := NULL;
`count_elements/BW1` := NULL;
`phi/nonempty_subsets/BW1` := eval(`phi/nonempty_subsets/prime_simplex`);
|
#!/usr/bin/env python
#-*- encoding: utf-8 -*-
"""
"""
from __future__ import print_function
from __future__ import division
import numpy as np
import argparse
import sys
import os
root_dir = os.path.dirname(os.path.abspath(__file__))
if not root_dir in sys.path:
sys.path.append(root_dir)
import server
import client
from helper_functions import *
def setup_server():
pass
def setup_client():
pass
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-r","--root",action='store_true',
help="Call to create a root node")
parser.add_argument("-sr","--sub-root",action='store_true',
help="Call to create a root node")
parser.add_argument("-n","--node",action='store_true',
help="Call to create a root node")
args = parser.parse_args()
print(args)
if __name__ == "__main__":
main() |
import logic.basic
lemma or_iff_or {p p' q q' : Prop} :
(p ↔ p') → (q ↔ q') → ((p ∨ q) ↔ (p' ∨ q')) :=
begin
intros hp hq, rewrite hp, rewrite hq
end
lemma and_iff_and {p p' q q' : Prop} :
(p ↔ p') → (q ↔ q') → ((p ∧ q) ↔ (p' ∧ q')) :=
begin intros hp hq, rewrite hp, rewrite hq end
lemma iff_of_left_of_right {p q : Prop} :
p → q → (p ↔ q) :=
begin intros hp hq, constructor; intro h; assumption end
lemma iff_iff_and_or_not_and_not {p q : Prop} :
(p ↔ q) ↔ ((p ∧ q) ∨ (¬p ∧ ¬q)) :=
begin
constructor; intro h1,
{ apply @classical.by_cases p; intro h2,
{ left, rw ← h1, constructor; assumption },
{ right, rw ← h1, constructor; assumption } },
{ cases h1; cases h1 with hp hq,
{ constructor; intro _; assumption },
{ constructor; intro _; contradiction } }
end
lemma exists_iff_exists {α : Type} {p q : α → Prop} :
(∀ a, p a ↔ q a) → ((∃ a, p a) ↔ ∃ a, q a) :=
begin
intro h, constructor; intro h;
cases h with a ha; existsi a;
[{rw (h a).symm}, {rw h}]; assumption
end
lemma forall_iff_not_exists_not {α : Type} {p : α → Prop} :
(∀ a, p a) ↔ (¬ ∃ a, ¬ p a) :=
begin
rw [@not_exists_not α p (λ x, _)],
apply classical.dec
end
lemma forall_iff_forall {α : Type} {p q : α → Prop} :
(∀ a, p a ↔ q a) → ((∀ a, p a) ↔ ∀ a, q a) :=
begin
intro h1, constructor; intros h2 a;
[{rw (h1 a).symm}, {rw h1}]; apply h2
end
lemma not_not_iff {φ : Prop} : ¬¬φ ↔ φ :=
iff.intro (classical.by_contradiction) (not_not_intro)
lemma or_of_not_imp_right {p q} : (¬ q → p) → p ∨ q :=
begin
intro h, cases (classical.em q) with hq hq,
apply or.inr hq, apply or.inl (h hq)
end
variable {α : Type}
lemma exists_eq_and_iff {p : α → Prop} {a : α} :
(∃ x, (x = a ∧ p x)) ↔ p a :=
begin
constructor; intro h, cases h with a' ha',
cases ha' with ha1' ha2', subst ha1', assumption,
existsi a, constructor, refl, assumption
end
lemma exists_and_comm {p q : α → Prop} :
(∃ x, p x ∧ q x) ↔ (∃ x, q x ∧ p x) :=
begin apply exists_iff_exists, intro a, apply and.comm end
lemma ite.rec {p} [hd : decidable p] {q : α → Prop} {f g : α}
(hf : p → q f) (hg : ¬ p → q g) : q (@ite p hd α f g) :=
begin
unfold ite, tactic.unfreeze_local_instances,
cases hd with h h, simp, apply hg h, simp, apply hf h
end
def as_true' (c : Prop) (h : decidable c) : Prop :=
@ite _ h Prop true false
def of_as_true' {c : Prop} (h₁ : decidable c) (h₂ : as_true' c h₁) : c :=
match h₁, h₂ with
| (is_true h_c), h₂ := h_c
| (is_false h_c), h₂ := false.elim h₂
end
lemma eq.symm' {a1 a2 : α} :
a1 = a2 ↔ a2 = a1 :=
iff.intro eq.symm eq.symm
lemma eq_iff_eq_of_eq_of_eq {a1 a2 a3 a4 : α} :
a1 = a3 → a2 = a4 → (a1 = a2 ↔ a3 = a4) :=
begin intros h1 h2, rw [h1, h2] end
lemma lt_iff_lt_of_eq_of_eq [has_lt α] {a1 a2 a3 a4 : α} :
a1 = a3 → a2 = a4 → (a1 < a2 ↔ a3 < a4) :=
begin intros h1 h2, rw [h1, h2] end |
function [ a, info ] = spofa ( a, lda, n )
%*****************************************************************************80
%
%% SPOFA factors a real symmetric positive definite matrix.
%
% Discussion:
%
% SPOFA is usually called by SPOCO, but it can be called
% directly with a saving in time if RCOND is not needed.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 09 November 2006
%
% Author:
%
% MATLAB version by John Burkardt.
%
% Reference:
%
% Dongarra, Moler, Bunch and Stewart,
% LINPACK User's Guide,
% SIAM, (Society for Industrial and Applied Mathematics),
% 3600 University City Science Center,
% Philadelphia, PA, 19104-2688.
% ISBN 0-89871-172-X
%
% Parameters:
%
% Input, real A(LDA,N), the symmetric matrix to be factored. Only the
% diagonal and upper triangle are used.
%
% Input, integer LDA, the leading dimension of the array A.
%
% Input, integer N, the order of the matrix.
%
% Output, real A(LDA,N), an upper triangular matrix R so that A = R'*R
% where R' is the transpose. The strict lower triangle is unaltered.
% If INFO /= 0, the factorization is not complete.
%
% Output, integer INFO, error flag.
% 0, for normal return.
% K, signals an error condition. The leading minor of order K is not
% positive definite.
%
for j = 1 : n
s = 0.0;
for k = 1 : j-1
t = a(k,j) - sdot ( k-1, a(1:k-1,k), 1, a(1:k-1,j), 1 );
t = t / a(k,k);
a(k,j) = t;
s = s + t * t;
end
s = a(j,j) - s;
if ( s <= 0.0 )
info = j;
return
end
a(j,j) = sqrt ( s );
end
info = 0;
return
end
|
attribute [local simp] Nat.mul_comm Nat.mul_assoc Nat.mul_left_comm
attribute [local simp] Nat.add_assoc Nat.add_comm Nat.add_left_comm
example (w x y z : Nat) (p : Nat → Prop)
(h : p (x * y + z * w * x)) : p (x * w * z + y * x) := by
simp at *; assumption
example (x y z : Nat) (p : Nat → Prop)
(h₁ : p (1 * x + y)) (h₂ : p (x * z * 1))
: p (y + 0 + x) ∧ p (z * x) := by
simp at * <;> constructor <;> assumption
|
(***********************************************************************
* HiVe theory files
*
* Copyright (C) 2015 Commonwealth of Australia as represented by Defence Science and Technology
* Group (DST Group)
*
* All rights reserved.
*
* The HiVe theory files are free software: released for redistribution and use, and/or modification,
* under the BSD License, details of which can be found in the LICENSE file included in the
* distribution.
************************************************************************)
theory
Z_Bag
imports
Z_Sequence
Z_Bag_Chap
begin
section {* Ranged bags *}
text {*
Bags are collections that may be distinguished by the number of occurrrences
of a member.
This makes them essentially natural number valued functions.
Spivey~\cite[p. 124]{Spivey:ZRef} introduces bags as non-zero valued functions
from a specified range set to the natural numbers.
*}
type_synonym
'a bagT = "'a \<leftrightarrow> \<arithmos>"
definition
bag :: "'a set \<rightarrow> 'a bagT set"
where
bag_def: "bag X \<defs> X \<zpfun> \<nat>\<subone>"
notation (zed)
bag ("\<zbag>")
lemma in_bagI [mintro!(fspace)]:
assumes a1: "b \<in> X \<zpfun> \<nat>\<subone>"
shows "b \<in> \<zbag> X"
using a1
by (simp add: bag_def)
lemma in_bagE [melim!(fspace)]:
assumes a1: "b \<in> \<zbag> X" "b \<in> X \<zpfun> \<nat>\<subone> \<turnstile> R"
shows "R"
using a1
by (simp add: bag_def)
lemma bag_range:
assumes a1: "b \<in> \<zbag> X" and a2: "x \<in> \<zdom> b"
shows "b\<cdot>x \<in> \<nat>\<subone>"
proof -
from a1 have b1: "functional b"
by (msafe_no_assms(fspace))
from a1 functional_ran [OF b1 a2]
show "b\<cdot>x \<in> \<nat>\<subone>"
apply (mauto(fspace))
done
qed
lemma bag_ran:
assumes a1: "b \<in> \<zbag> X" and a2: "(x \<mapsto> y) \<in> b"
shows "y \<in> \<nat>\<subone>"
apply (rule in_bagE [OF a1])
apply (mauto(fspace))
using a1 a2
apply (auto simp add: Range_def Domain_def subset_def)
done
lemma in_bag_functional:
assumes a1: "b \<in> \<zbag> X"
shows "functional b"
using a1
by (mauto(fspace))
lemma in_bag_subset:
assumes a1: "X \<subseteq> Y" "b \<in> \<zbag> X"
shows "b \<in> \<zbag> Y"
using a1
by (mauto(fspace))
lemma in_bag_dom:
assumes a1: "b \<in> \<zbag> X"
shows "b \<in> \<zbag> (\<zdom> b)"
using a1
by (mauto(fspace))
section {* Bag count *}
text {*
The basic membership operator is the count operator which determines
the order of membership for a particular element.
*}
definition
bhash :: "['a bagT, 'a] \<rightarrow> \<arithmos>"
where
bhash_def: "bhash b \<defs> (\<^funK>{:0:})\<oporide>b"
notation (xsymbols)
bhash ("_\<sharp>_" [1000, 999] 999)
lemma Z_bhash_def:
"b\<sharp>x \<defs> ((\<olambda> x \<bullet> 0)\<oporide>b) x"
by (simp add: bhash_def funK_def)
lemma mem_bhash:
assumes
a1: "b \<in> \<zbag> X"
shows
"(x \<mapsto> y) \<in> b \<Leftrightarrow> y = b\<sharp>x \<and> b\<sharp>x \<in> \<nat>\<subone>"
using a1
apply (simp add: bhash_def op_oride_beta funK_def)
apply (msafe(inference))
apply (simp add: functional_beta in_bag_functional)
apply (simp add: bag_range [OF a1])
apply (simp add: functional_appl in_bag_functional)
apply (auto simp add: zNats1_def)
done
lemma Z_dom_bhash:
assumes a1: "b \<in> \<zbag> X"
shows "\<zdom> b = { x | b\<sharp>x \<in> \<nat>\<subone> }"
apply (rule set_eqI)
using a1
apply (auto simp add: mem_bhash)
done
lemma appl_bhash:
assumes a1: "b \<in> \<zbag> X" "b\<sharp>x \<in> \<nat>\<subone>"
shows "(x \<mapsto> b\<sharp>x) \<in> b"
using a1
by (auto simp add: mem_bhash)
lemma bhash_beta:
assumes a1: "b \<in> \<zbag> X" "(x \<mapsto> y) \<in> b"
shows "b\<sharp>x = y"
using a1
by (auto simp add: mem_bhash)
lemma bhash_range:
assumes a1: "b \<in> \<zbag> X"
shows "b\<sharp>x \<in> \<nat>"
apply (simp add: bhash_def op_oride_beta funK_def)
apply (msafe(inference))
apply (rule subsetD [OF _ bag_range [OF a1]])
apply (auto simp add: zNats1_def)
done
lemma bhash_range2:
assumes a1: "b \<in> \<zbag> X"
shows "0 \<le> b\<sharp>x"
apply (insert bhash_range [OF a1])
apply (simp add: zInts_zNats_nonneg)
done
lemma bhash_beta':
assumes a1: "b \<in> \<zbag> X"
shows "b\<sharp>x = \<if> x \<in> \<zdom> b \<then> b\<cdot>x \<else> 0 \<fi>"
using a1
by (simp add: bhash_def op_oride_beta funK_def)
lemma bag_eqI:
assumes
a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X" and
a3: "\<And> x \<bullet> b\<sharp>x = c\<sharp>x"
shows "b = c"
apply (rule functional_eqI)
apply (insert a1 a2)
apply (mauto(fspace))
proof -
from a3 show b0: "\<zdom> b = \<zdom> c"
by (auto simp add: Z_dom_bhash [OF a1] Z_dom_bhash [OF a2] set_eq_def)
fix x assume
b1: "x \<in> \<zdom> b"
with b0 have
b2: "x \<in> \<zdom> c"
by (simp)
from a3 [of x] b1 b2 a1 a2 show
"b\<cdot>x = c\<cdot>x"
by (simp add: bhash_beta')
qed
lemma bag_eqI':
assumes
a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X" and
a3: "\<And> x \<bullet> x \<in> X \<turnstile> b\<sharp>x = c\<sharp>x"
shows "b = c"
proof (rule bag_eqI [OF a1 a2])
fix x show "b\<sharp>x = c\<sharp>x"
proof (cases "x \<in> X")
assume c1: "x \<in> X"
then show "?thesis"
by (rule a3)
next
assume c1: "x \<notin> X"
with a1 a2 have "x \<notin> \<zdom> b" and "x \<notin> \<zdom> c"
apply (mauto(fspace))
done
then show ?thesis
by (simp add: bhash_beta' [OF a1] bhash_beta' [OF a2])
qed
qed
section {* Defining bag operators from bag count terms *}
text {*
The general approach taken by Spivey to defining bag operators is to
express axiomatically the count of the result in terms of the count of the arguments.
Axiomatic definitions can adressed in HOL with the definite articl operator.
In order to demonstrate that such definitions are always well-defined, we introduce
the @{term "bag_of"} operator which converts any given natural number function to a bag.
*}
definition
bag_of :: "('a \<leftrightarrow> \<arithmos>) \<rightarrow> 'a bagT"
where
bag_of_def: "bag_of f \<defs> f\<zrres>\<nat>\<subone>"
lemma bag_of_in_bagI:
assumes
a1: "f \<in> X \<zpfun> \<nat>"
shows
"bag_of f \<in> \<zbag> X"
using a1
apply (simp add: bag_of_def)
apply (mauto(fspace))
apply (auto simp add: rres_dom)
apply (auto simp add: rres_def)
done
lemma bag_of_glambda_in_bagI:
assumes
a1: "{ x | b x } \<subseteq> X" "{ x | b x \<bullet> t x } \<subseteq> \<nat>"
shows
"bag_of (\<glambda> x | b x \<bullet> t x) \<in> \<zbag> X"
apply (rule bag_of_in_bagI)
apply (mauto(fspace))
using a1
apply (auto dest!: subsetD simp add: Domain_def Range_def rsub_def glambda_mem zNats1_def)
done
lemma bag_of_beta:
assumes a1: "functional f" and a2: "x \<in> \<zdom> f" and a3: "f\<cdot>x \<in> \<nat>\<subone>"
shows "(bag_of f)\<cdot>x = f\<cdot>x"
apply (insert functional_appl [OF a1 a2] a1 a2 a3)
apply (simp add: bag_of_def)
apply (rule functional_beta)
apply (mauto(fspace))
apply (simp add: rres_def)
done
lemma bag_of_mem:
"(x \<mapsto> y) \<in> bag_of f \<Leftrightarrow> (x \<mapsto> y) \<in> f \<and> y \<in> \<nat>\<subone>"
by (auto simp add: bag_of_def rres_def)
lemma bag_of_dom:
"\<zdom> (bag_of f) = { x | (\<exists> y | y \<in> \<nat>\<subone> \<bullet> (x \<mapsto> y) \<in> f)}"
by (auto simp add: Domain_def bag_of_mem)
lemma bag_of_ran:
"\<zran> (bag_of f) = \<zran> f \<inter> \<nat>\<subone>"
by (auto simp add: bag_of_mem)
lemma bag_of_bhash:
assumes a1: "functional f" and a2: "\<zran> f \<subseteq> \<nat>"
shows "(bag_of f)\<sharp>x = \<if> x \<in> \<zdom> f \<then> f\<cdot>x \<else> 0 \<fi>"
apply (cases "x \<in> \<zdom> f")
apply (simp_all)
proof -
from a1 a2 have b1: "bag_of f \<in> \<zbag> \<univ>"
apply (intro bag_of_in_bagI)
apply (mauto(fspace))
done
{ assume b2: "x \<in> \<zdom> f"
show "(bag_of f)\<sharp>x = f\<cdot>x"
proof (cases "f\<cdot>x \<in> \<nat>\<subone>")
assume c1: "f\<cdot>x \<notin> \<nat>\<subone>"
with functional_unique [OF a1] have c3: "x \<notin> \<zdom> (bag_of f)"
by (simp add: bag_of_dom zNats1_def)
with a1 a2 [THEN subsetD, OF functional_ran [OF a1 b2]] functional_appl [OF a1 b2]
show "(bag_of f)\<sharp>x = f\<cdot>x"
apply (simp add: bhash_beta' [OF b1])
apply (auto simp add: bag_of_dom zNats1_def)
done
next
assume c1: "f\<cdot>x \<in> \<nat>\<subone>"
have c2: "x \<in> \<zdom> (bag_of f)"
apply (simp add: bag_of_mem Domain_iff)
apply (witness "f\<cdot>x")
apply (simp add: c1 functional_appl [OF a1 b2])
done
then show "(bag_of f)\<sharp>x = f\<cdot>x"
by (simp add: bhash_beta' [OF b1] bag_of_beta [OF a1 b2 c1])
qed
next
assume "x \<notin> \<zdom> f"
then have "x \<notin> \<zdom> (bag_of f)"
by (auto simp add: bag_of_mem)
then show "(bag_of f)\<sharp>x = 0"
by (simp add: bhash_beta' [OF b1]) }
qed
lemma bag_of_glambda_bhash:
assumes a1: "\<And> x \<bullet> b x \<turnstile> t x \<in> \<nat>"
shows "(bag_of (\<glambda> x | b x \<bullet> t x))\<sharp>x = \<if> b x \<then> t x \<else> 0 \<fi>"
proof -
from a1 have b1: "\<zran> (\<glambda> x | b x \<bullet> t x) \<subseteq> \<nat>"
by (auto simp add: glambda_ran)
with a1 show "?thesis"
by (auto simp add: bag_of_bhash [OF glambda_functional] glambda_dom glambda_beta)
qed
lemma bag_of_glambda_bhash':
"(bag_of (\<glambda> x | b x \<bullet> of_nat (t x)))\<sharp>x = \<if> b x \<then> of_nat (t x) \<else> 0 \<fi>"
apply (rule bag_of_glambda_bhash)
apply (auto simp add: zNats_def)
done
text {*
Now we make use of @{text "bag_of"} to demonstrate that all bag count style definitions
are well-defined.
*}
lemma bhash_def_wdef:
assumes a1: "(\<forall> x | x \<in> X \<bullet> t x \<in> \<nat>)"
shows "(\<exists>\<subone> b' \<bullet> b' \<in> \<zbag> X \<and> (\<forall> x | x \<in> X \<bullet> b'\<sharp>x = t x))"
apply (rule ex1I [of _ "bag_of (\<glambda> x | x \<in> X \<bullet> t x)"])
apply (msafe(inference))
proof -
show b1: "bag_of (\<glambda> x | x \<in> X \<bullet> t x) \<in> \<zbag> X"
apply (rule bag_of_glambda_in_bagI)
using a1
apply (auto)
done
{ fix x assume "x \<in> X"
with a1 show "(bag_of (\<glambda> x | x \<in> X \<bullet> t x))\<sharp>x = t x"
by (simp add: bag_of_glambda_bhash) } note b2 = this
{ fix b'
assume b3: "b' \<in> \<zbag> X" and b4: "(\<forall> x | x \<in> X \<bullet> b'\<sharp>x = t x)"
from b3 b1 show "b' = bag_of (\<glambda> x | x \<in> X \<bullet> t x)"
apply (rule bag_eqI')
apply (simp add: b2 b4)
done }
qed
section {* Bag extension *}
text {*
Extensional bag comprehension uses a comma-separated list similar to
that for sets and sequences, but with doubled bracket delimeters..
*}
definition
bempty :: "'a bagT"
where
bempty_def: "bempty \<defs> \<emptyset>"
definition
binsert :: "['a, 'a bagT] \<rightarrow> 'a bagT"
where
binsert_def: "binsert x b \<defs> b \<oplus> {(x \<mapsto> b\<sharp>x + 1)} "
notation (xsymbols)
bempty ("\<lbag> \<rbag>") and
bempty ("\<lbag> \<rbag>")
syntax (xsymbols)
"_Z_Bag\<ZZ>extbag" :: "args \<rightarrow> logic" ("\<lbag> _ \<rbag>")
translations
"\<lbag>x, xs\<rbag>" \<rightleftharpoons> "CONST Z_Bag.binsert x \<lbag>xs\<rbag>"
"\<lbag>x\<rbag>" \<rightleftharpoons> "CONST Z_Bag.binsert x \<lbag> \<rbag>"
lemma bempty_in_bagI:
"\<lbag> \<rbag> \<in> \<zbag> X"
apply (simp add: bempty_def)
apply (mauto(fspace) mintro: fin_pfunI)
done
lemma binsert_in_bagI:
assumes
a1: "b \<in> \<zbag> X" and
a2: "x \<in> X"
shows
"binsert x b \<in> \<zbag> X"
using a1 a2
apply (simp add: binsert_def)
apply (mauto(fspace))
apply (mauto(fspace) mintro!: fin_pfunI)
apply (simp add: Z_rel_oride_dom_dist fin_pfun_simp)
proof -
have "b\<sharp>x \<in> \<nat>"
by (rule bhash_range [OF a1])
then have b1: "b\<sharp>x + 1 \<in> \<nat>\<subone>"
by (auto simp add: zInts_zNats_nonneg zInts_zNats1_pos image_def)
with a1 show "\<zran> (b \<oplus> {(x \<mapsto> b\<sharp>x + 1)}) \<subseteq> \<nat>\<subone>"
apply (mauto(fspace))
apply (auto dest!: subsetD simp add: rel_oride_def dsub_def)
done
qed
lemma binsert_mem:
"(y \<mapsto> n) \<in> binsert x b \<Leftrightarrow> (\<if> y = x \<then> n = b\<sharp>x + 1 \<else> (y \<mapsto> n) \<in> b \<fi>)"
by (simp add: binsert_def rel_oride_mem fin_pfun_simp)
lemma bempty_mem:
"(y \<mapsto> n) \<notin> \<lbag> \<rbag>"
by (simp add: bempty_def)
lemmas bfin_mem = binsert_mem bempty_mem
lemma binsert_dom:
"\<zdom> (binsert x b) = insert x (\<zdom> b)"
by (auto simp add: binsert_mem Domain_def)
lemma bempty_dom:
"\<zdom> \<lbag> \<rbag> = \<emptyset>"
by (auto simp add: bempty_mem Domain_def)
lemmas bfin_dom = binsert_dom bempty_dom
lemma binsert_bhash:
"(binsert x b)\<sharp>y = \<if> y = x \<then> b\<sharp>x + 1 \<else> b\<sharp>y \<fi>"
by (simp add: bhash_def op_oride_beta binsert_def rel_oride_beta Z_rel_oride_dom_dist fin_pfun_simp fin_funappl)
lemma bempty_bhash:
"\<lbag> \<rbag>\<sharp>y = 0"
by (simp add: bhash_def op_oride_beta funK_def bempty_def rel_oride_beta glambda_beta)
lemmas bfin_bhash = binsert_bhash bempty_bhash
lemma binsertC [simp]: "binsert x (binsert y b) = binsert y (binsert x b)"
apply (rule rel_eqI)
apply (simp add: binsert_mem binsert_bhash)
done
lemma "\<lbag> 0::nat, 1, 1, 1, 2, 2, 3 \<rbag>\<sharp>1 = 3"
by (simp add: bfin_bhash)
lemma "\<zdom> \<lbag> 0::nat, 1, 1, 1, 2, 2, 3 \<rbag> = {0, 1, 2, 3}"
by (simp add: bfin_dom)
lemma "\<lbag> 0::nat, 1, 1, 1, 2, 2, 3 \<rbag> = \<lbag> 1, 2, 1, 0::nat, 1, 2, 3 \<rbag>"
by (simp)
section {* Bag scaling *}
text {*
Scalar bag multiplication increases the membership of the bag by an integer
factor.
*}
definition
bscale :: "[\<arithmos>, 'a bagT] \<rightarrow> 'a bagT"
where
bscale_def: "bscale n b \<defs> (\<mu> b' | b' \<in> \<zbag> (\<zdom> b) \<and> (\<forall> x | x \<in> \<zdom> b \<bullet> b'\<sharp>x = n * (b\<sharp>x)))"
notation (xsymbols)
bscale (infixr "\<otimes>" 100)
lemma bscale_in_zNats:
assumes a1: "b \<in> \<zbag> X" and a2: "n \<in> \<nat>"
shows "(\<forall> x | x \<in> X \<bullet> n * (b\<sharp>x) \<in> \<nat>)"
apply (msafe(inference))
apply (rule zNats_mult)
apply (rule a2)
apply (rule bhash_range [OF a1])
done
lemmas bscale_wdef =
bhash_def_wdef [
of "\<zdom> b" "\<olambda> x \<bullet> n * b\<sharp>x",
THEN theI',
OF bscale_in_zNats,
folded bscale_def,
standard]
lemma bscale_in_bagI:
assumes a1: "b \<in> \<zbag> X" and a2: "n \<in> \<nat>"
shows "n \<otimes> b \<in> \<zbag> X"
apply (insert bscale_wdef [OF a1 [THEN in_bag_dom] a2, THEN conjunct1] a1)
apply (mauto(fspace))
done
lemma bscale_bhash:
assumes a1: "b \<in> \<zbag> X" and a2: "n \<in> \<nat>"
shows "(n \<otimes> b)\<sharp>x = n * (b\<sharp>x)"
apply (cases "x \<in> \<zdom> b")
apply (rule bscale_wdef [OF a1 [THEN in_bag_dom] a2, THEN conjunct2, rule_format])
apply (assumption)
apply (insert a1 bscale_wdef [OF a1 [THEN in_bag_dom] a2, THEN conjunct1])
apply (simp add: bhash_beta')
apply (mauto(fspace))
apply (auto)
done
lemma Z_bscale_def:
assumes
a1: "b \<in> \<zbag> X" "n \<in> \<nat>"
shows
"(n \<otimes> b)\<sharp>x \<defs> n * (b\<sharp>x)"
using a1
by (simp add: bscale_bhash)
lemma bscale_mem:
assumes
a1: "b \<in> \<zbag> X" and
a2: "n \<in> \<nat>"
shows
"(x \<mapsto> y) \<in> n \<otimes> b \<Leftrightarrow> n \<noteq> 0 \<and> (\<exists> y' \<bullet> (x \<mapsto> y') \<in> b \<and> y = n * y')"
using a1 a2
by (auto simp add: mem_bhash [OF a1] mem_bhash [OF bscale_in_bagI [OF a1]] bscale_bhash zNats1_def bhash_range)
lemma bscale_dom:
assumes
a1: "b \<in> \<zbag> X" and
a2: "n \<in> \<nat>"
shows
"\<zdom> (n \<otimes> b) = \<if> n = 0 \<then> {} \<else> \<zdom> b \<fi>"
using a1 a2
by (auto simp add: Domain_def bscale_mem zNats1_def)
lemma bscale_dom2:
assumes
a1: "b \<in> \<zbag> X" and
a2: "n \<in> \<nat>"
shows
"\<zdom> (n \<otimes> b) = \<if> 0 < n \<then> \<zdom> b \<else> {} \<fi>"
using a1 a2
by (auto simp add: Domain_def bscale_mem zInts_zNats_nonneg zInts_zNats1_pos)
lemma bscale_beta:
assumes a1: "b \<in> \<zbag> X" and a2: "x \<in> \<zdom> b" and a3: "n \<in> \<nat>\<subone>"
shows "(n \<otimes> b)\<cdot>x = n*(b\<cdot>x)"
apply (insert bscale_in_bagI [OF a1 a3 [THEN zNats_zNats1]] a1 a2 a3)
apply (simp add: zNats1_def)
apply (mauto(fspace))
apply (rule functional_beta)
apply (assumption)
apply (simp add: bscale_mem [OF a1 a3 [THEN zNats_zNats1]])
apply (rule functional_appl)
apply (mauto(fspace))
done
lemma bempty_scale:
assumes a1: "n \<in> \<nat>"
shows "n \<otimes> \<lbag> \<rbag> = \<lbag> \<rbag>"
by (auto simp add: bscale_mem [OF bempty_in_bagI a1] bempty_mem)
lemma zero_scale:
assumes a1: "b \<in> \<zbag> X"
shows "0 \<otimes> b = \<lbag> \<rbag>"
by (auto simp add: bscale_mem [OF a1] bempty_mem)
lemma Z_bscale_bempty_zero:
assumes a1: "b \<in> \<zbag> X" and a2: "n \<in> \<nat>"
shows "\<lch> n \<otimes> \<lbag> \<rbag> \<chEq> 0 \<otimes> b \<chEq> \<lbag> \<rbag> \<rch>"
using a1 a2
by (simp add: zero_scale bempty_scale)
lemma Z_unit_scale:
assumes a1: "b \<in> \<zbag> X"
shows "1 \<otimes> b = b"
by (auto simp add: bscale_mem [OF a1])
lemma Z_dist_scale:
assumes a1: "b \<in> \<zbag> X" and a2: "n \<in> \<nat>" and a3: "m \<in> \<nat>"
shows "(n * m) \<otimes> b = n \<otimes> m \<otimes> b"
apply (insert a1 a2 a3 bscale_in_bagI [OF a1, of "m"])
apply (auto simp add: bscale_mem set_eq_def)
done
section {* Bag membership and sub-bags *}
text {*
An element is a member of a bag if it is in the domain of the bag function.
*}
definition
inbag :: "['a, 'a bagT] \<rightarrow> \<bool>"
where
inbag_def : "inbag x b \<defs> x \<in> \<zdom> b"
notation (xsymbols)
inbag (infixl "\<inbag>" 90)
lemma Z_inbag_def:
assumes "x \<in> X" "B \<in> \<zbag> X"
shows "x \<inbag> B \<defs> x \<in> \<zdom> B"
by (auto simp add: inbag_def Domain_def)
lemma Z_inbag_bhash:
assumes a1: "b \<in> \<zbag> X"
shows "x \<inbag> b \<Leftrightarrow> 0 < b\<sharp>x"
by (simp add: inbag_def Z_dom_bhash [OF a1] zNats1_pos bhash_range [OF a1])
text {*
The sub-bag relation can be defined as the pointwise order on bag counts.
*}
definition
bag_le :: "['a bagT, 'a bagT] \<rightarrow> \<bool>"
where
bag_le_def: "bag_le b_d_1 b_d_2 \<defs> (\<forall> x \<bullet> b_d_1\<sharp>x \<le> b_d_2\<sharp>x)"
notation (xsymbols)
bag_le ("_ \<subbag> _" [50, 51] 50)
lemma Z_bag_le_def:
assumes a1: "B \<in> \<zbag> X" "C \<in> \<zbag> X"
shows "B \<subbag> C \<defs> (\<forall> x | x \<in> X \<bullet> B\<sharp>x \<le> C\<sharp>x)"
apply (rule eq_reflection)
using a1
apply (auto simp add: bag_le_def)
proof -
fix x
assume b1: "(\<forall> x | x \<in> X \<bullet> B\<sharp>x \<le> C\<sharp>x)"
show "B\<sharp>x \<le> C\<sharp>x"
apply (cases "x \<in> X")
apply (simp add: b1)
proof -
assume c1: "x \<notin> X"
from a1 c1 have "x \<notin> \<zdom> B" "x \<notin> \<zdom> C"
apply (mauto(fspace))
done
with a1 show "B\<sharp>x \<le> C\<sharp>x"
by (simp add: bhash_beta')
qed
qed
lemma Z_bempty_bag_le:
assumes a1: "b \<in> \<zbag> X"
shows "\<lbag> \<rbag> \<subbag> b"
using a1
by (simp add: bag_le_def bempty_in_bagI bempty_bhash bhash_range2)
lemma Z_bag_self_le:
assumes a1: "b \<in> \<zbag> X"
shows "b \<subbag> b"
using a1
by (auto simp add: bag_le_def)
lemma bag_le_dom:
assumes
a1: "b_d_1 \<subbag> b_d_2" and
a2: "b_d_1 \<in> \<zbag> X" and
a3: "b_d_2 \<in> \<zbag> X"
shows
"\<zdom> b_d_1 \<subseteq> \<zdom> b_d_2"
using a1 a2 a3
apply (simp add: Z_dom_bhash)
apply (auto intro: order_less_le_trans)
apply (simp add: bag_le_def)
proof -
fix x
assume b0: "\<forall> r \<bullet> b_d_1\<sharp>r \<le> b_d_2\<sharp>r" and b1: "b_d_1\<sharp>x \<in> \<nat>\<subone>"
from b1 zNats1_def have b1': "b_d_1\<sharp>x \<in> zNats" and b1'': "b_d_1\<sharp>x \<noteq> 0" by auto
from b0 [rule_format] have b2: "b_d_1\<sharp>x \<le> b_d_2\<sharp>x" by auto
from a3 have
b3: "b_d_2\<sharp>x \<in> zNats"
by (rule bhash_range)
have "b_d_2\<sharp>x \<noteq> 0"
by (rule zNats_le_noteq_zero [OF b1' b3 b2 b1''] )
with b3 show "b_d_2\<sharp>x \<in> \<nat>\<subone>"
by (simp add: zNats1_def)
qed
lemma Z_bag_le_dom:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "b \<subbag> c \<Rightarrow> \<zdom> b \<subseteq> \<zdom> c"
apply (msafe(inference))
apply (intro bag_le_dom)
using a1 a2
apply (simp_all)
done
lemma Z_bag_le_eq:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "b \<subbag> c \<and> c \<subbag> b \<Rightarrow> b = c"
apply (simp add: bag_le_def)
apply (msafe(inference))
proof (rule bag_eqI [OF a1 a2])
fix x
assume b0: "\<forall> r \<bullet> b\<sharp>r \<le> c\<sharp>r" and b1: "\<forall> r \<bullet> c\<sharp>r \<le> b\<sharp>r"
from b0 [rule_format] have b0': "b\<sharp>x \<le> c\<sharp>x" by this
from b1 [rule_format] have b1': "c\<sharp>x \<le> b\<sharp>x" by this
from b0' b1' show "b\<sharp>x = c\<sharp>x" by auto
qed
lemma Z_bag_le_trans:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X" and a3: "d \<in> \<zbag> X"
shows "b \<subbag> c \<and> c \<subbag> d \<Rightarrow> b \<subbag> d"
apply (simp add: bag_le_def)
apply (msafe(inference))
proof -
fix x
assume b0: "\<forall> r \<bullet> b\<sharp>r \<le> c\<sharp>r" and b1: "\<forall> r \<bullet> c\<sharp>r \<le> d\<sharp>r"
from b0 [rule_format] have b0': "b\<sharp>x \<le> c\<sharp>x" by this
from b1 [rule_format] have b1': "c\<sharp>x \<le> d\<sharp>x" by this
from b0' b1' show "b\<sharp>x \<le> d\<sharp>x" by auto
qed
(*
interpretation bagpo: Order_Locale.partial_order ["bag X" "bag_le X"]
apply (simp_all add: carrier_def setrel_axioms_def reflexive_axioms_def transitive_axioms_def antisymmetric_axioms_def)
apply (msafe(inference))
proof -
from bempty_in_bagI [of X] show "\<zbag> X \<noteq> \<emptyset>"
by (auto)
next
show "\<oprel>(bag_le X) \<in> \<zbag> X \<zrel> \<zbag> X"
by (auto simp add: op2rel_def bag_le_def rel_def)
next
fix b assume "b \<in> \<zbag> X"
then show "b \<^ble>{:X:} b"
by (auto simp add: bag_le_def)
next
fix b_d_1 b_d_2 b_d_3
assume "b_d_1 \<in> \<zbag> X" and "b_d_2 \<in> \<zbag> X" and "b_d_3 \<in> \<zbag> X" and
"b_d_1 \<^ble>{:X:} b_d_2" and "b_d_2 \<^ble>{:X:} b_d_3"
then show "b_d_1 \<^ble>{:X:} b_d_3"
by (auto intro: order_trans simp add: bag_le_def)
next
fix b_d_1 b_d_2
assume "b_d_1 \<in> \<zbag> X" and "b_d_2 \<in> \<zbag> X" and
"b_d_1 \<^ble>{:X:} b_d_2" and "b_d_2 \<^ble>{:X:} b_d_1"
then show "b_d_1 = b_d_2"
apply (intro bag_eqI)
apply (auto intro: order_antisym simp add: bag_le_def)
done
qed
*)
section {* Bag union and difference *}
text {*
Bag union and bag difference can be defined in terms of arithmetic on the counts.
*}
definition
bunion :: "['a bagT, 'a bagT] \<rightarrow> 'a bagT"
where
bunion_def : "bunion b c \<defs> (\<mu> b' | b' \<in> \<zbag> (\<zdom> b \<union> \<zdom> c) \<and> (\<forall> x | x \<in> (\<zdom> b \<union> \<zdom> c) \<bullet> b'\<sharp>x = b\<sharp>x + c\<sharp>x))"
definition
bdiff :: "['a bagT, 'a bagT] \<rightarrow> 'a bagT"
where
bdiff_def : "bdiff b c \<defs> (\<mu> b' | b' \<in> \<zbag> (\<zdom> b \<union> \<zdom> c) \<and> (\<forall> x | x \<in> (\<zdom> b \<union> \<zdom> c) \<bullet> b'\<sharp>x = \<if> c\<sharp>x \<le> b\<sharp>x \<then> b\<sharp>x - c\<sharp>x \<else> 0 \<fi>))"
notation (xsymbols)
bunion (infixl "\<bunion>" 100) and
bdiff (infixl "\<bdiff>" 100)
lemma bunion_in_zNats:
assumes
a1: "b \<in> \<zbag> X" "c \<in> \<zbag> X"
shows
"(\<forall> x \<bullet> x \<in> Domain b \<union> Domain c \<Rightarrow> b\<sharp>x + c\<sharp>x \<in> \<nat>)"
using a1
by (auto intro!: zNats_add simp add: bhash_range)
lemmas bunion_wdef =
bhash_def_wdef [
of "\<zdom> b \<union> \<zdom> c" "\<olambda> x \<bullet> b\<sharp>x + c\<sharp>x",
THEN theI',
folded bunion_def,
OF bunion_in_zNats,
standard]
lemma bdiff_in_zNats:
assumes
a1: "b \<in> \<zbag> X" "c \<in> \<zbag> X"
shows
"(\<forall> x \<bullet> x \<in> Domain b \<union> Domain c \<Rightarrow> \<if> c\<sharp>x \<le> b\<sharp>x \<then> b\<sharp>x - c\<sharp>x \<else> 0 \<fi> \<in> \<nat>)"
using a1
by (auto intro!: zNats_diff simp add: bhash_range)
lemmas bdiff_wdef =
bhash_def_wdef [
of "\<zdom> b \<union> \<zdom> c" "\<olambda> x \<bullet> \<if> c\<sharp>x \<le> b\<sharp>x \<then> b\<sharp>x - c\<sharp>x \<else> 0 \<fi>",
THEN theI',
folded bdiff_def,
OF bdiff_in_zNats,
standard]
lemma bunion_in_bagI:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "b \<bunion> c \<in> \<zbag> X"
apply (insert a1 a2 bunion_wdef [OF a1 a2])
apply (msafe(inference))
apply (mauto(fspace))
(*J XXX why need this now? *)
apply (rule order_trans, assumption)
apply auto
done
lemma bdiff_in_bagI:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "b \<bdiff> c \<in> \<zbag> X"
apply (insert a1 a2 bdiff_wdef [OF a1 a2])
apply (msafe(inference))
apply (mauto(fspace))
(*J XXX why need this now? *)
apply (rule order_trans, assumption)
apply auto
done
lemma bunion_bhash:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "(b \<bunion> c)\<sharp>x = (b\<sharp>x) + (c\<sharp>x)"
apply (cases "x \<in> \<zdom> b \<union> \<zdom> c")
apply (simp add: bunion_wdef [OF a1 a2, THEN conjunct2, rule_format])
apply (insert a1 a2 bunion_wdef [OF a1 a2, THEN conjunct1])
apply (simp add: bhash_beta')
apply (mauto(fspace))
apply (auto)
done
lemma Z_bunion_def:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "(b \<bunion> c)\<sharp>x \<defs> (b\<sharp>x) + (c\<sharp>x)"
using a1 a2
by (simp add: bunion_bhash)
lemma bdiff_bhash:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "(b \<bdiff> c)\<sharp>x = \<if> c\<sharp>x \<le> b\<sharp>x \<then> b\<sharp>x - c\<sharp>x \<else> 0 \<fi>"
apply (cases "x \<in> \<zdom> b \<union> \<zdom> c")
apply (simp add: bdiff_wdef [OF a1 a2, THEN conjunct2, rule_format])
apply (insert a1 a2 bdiff_wdef [OF a1 a2, THEN conjunct1])
apply (simp add: bhash_beta')
apply (mauto(fspace))
apply (auto)
done
lemma Z_bdiff_def:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "(b \<bdiff> c)\<sharp>x \<defs> \<if> c\<sharp>x \<le> b\<sharp>x \<then> b\<sharp>x - c\<sharp>x \<else> 0 \<fi>"
using a1 a2
by (simp add: bdiff_bhash)
lemma Z_bunion_dom:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "\<zdom> (b \<bunion> c) = (\<zdom> b) \<union> (\<zdom> c)"
apply (insert bunion_wdef [OF a1 a2, THEN conjunct1])
apply (mauto(fspace))
apply (rule order_antisym)
apply (assumption)
apply (rule subsetI)
apply (insert bhash_range [OF a1] bhash_range [OF a2])
apply (simp add: Z_dom_bhash [OF a1] Z_dom_bhash [OF a2] Z_dom_bhash [OF bunion_in_bagI [OF a1 a2]]
bunion_bhash [OF a1 a2] zNats1_def nat_of_norm)
done
lemma bunion_empty:
assumes a1: "b \<in> \<zbag> X"
shows "\<lbag> \<rbag> \<bunion> b = b" "b \<bunion> \<lbag> \<rbag> = b"
apply (rule bag_eqI')
apply (rule bunion_in_bagI [OF bempty_in_bagI a1])
apply (rule a1)
apply (simp add: bunion_bhash [OF bempty_in_bagI a1] bempty_bhash)
apply (rule bag_eqI')
apply (rule bunion_in_bagI [OF a1 bempty_in_bagI])
apply (rule a1)
apply (simp add: bunion_bhash [OF a1 bempty_in_bagI] bempty_bhash)
done
lemma Z_bunion_empty:
assumes a1: "b \<in> \<zbag> X"
shows "\<lch> \<lbag> \<rbag> \<bunion> b \<chEq> b \<bunion> \<lbag> \<rbag> \<chEq> b \<rch>"
apply (insert bunion_empty [OF a1])
apply auto
done
lemma Z_bunion_commute:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X"
shows "b \<bunion> c = c \<bunion> b"
apply (rule bag_eqI')
apply (rule bunion_in_bagI [OF a1 a2])
apply (rule bunion_in_bagI [OF a2 a1])
apply (simp add: bunion_bhash [OF a1 a2] bunion_bhash [OF a2 a1])
done
lemma Z_bunion_assoc:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X" and a3: "d \<in> \<zbag> X"
shows "(b \<bunion> c) \<bunion> d = b \<bunion> (c \<bunion> d)"
apply (rule bag_eqI')
apply (rule bunion_in_bagI [OF bunion_in_bagI [OF a1 a2] a3])
apply (rule bunion_in_bagI [OF a1 bunion_in_bagI [OF a2 a3]])
apply (simp add:
bunion_bhash [OF bunion_in_bagI [OF a1 a2] a3] bunion_bhash [OF a1 bunion_in_bagI [OF a2 a3]]
bunion_bhash [OF a1 a2] bunion_bhash [OF a2 a3])
done
lemma bunion_left_commute:
assumes a1: "b \<in> \<zbag> X" and a2: "c \<in> \<zbag> X" and a3: "d \<in> \<zbag> X"
shows "b \<bunion> (c \<bunion> d) = c \<bunion> (b \<bunion> d)"
by (simp add: Z_bunion_assoc [OF a1 a2 a3, symmetric] Z_bunion_assoc [OF a2 a1 a3, symmetric]
Z_bunion_commute [OF a1 a2])
lemmas bunion_AC = Z_bunion_commute Z_bunion_assoc bunion_left_commute
lemma Z_bdiff_empty:
assumes a1: "b \<in> \<zbag> X"
shows "\<lbag> \<rbag> \<bdiff> b = \<lbag> \<rbag> \<and> b \<bdiff> \<lbag> \<rbag> = b"
apply (rule conjI)
apply (rule bag_eqI')
apply (rule bdiff_in_bagI [OF bempty_in_bagI a1])
apply (rule bempty_in_bagI)
using a1
apply (simp add: bdiff_bhash [OF bempty_in_bagI a1] bempty_bhash bhash_range zNats_le_0_eq)
apply (rule bag_eqI')
apply (rule bdiff_in_bagI [OF a1 bempty_in_bagI])
apply (rule a1)
using a1
apply (simp add: bdiff_bhash [OF a1 bempty_in_bagI] bempty_bhash bhash_range zNats_le0)
done
lemma Z_bunion_inverse:
assumes
a1: "b \<in> \<zbag> X" and
a2: "c \<in> \<zbag> X"
shows
"(b \<bunion> c) \<bdiff> c = b"
apply (rule bag_eqI')
apply (rule bdiff_in_bagI [OF bunion_in_bagI [OF a1 a2] a2])
apply (rule a1)
using a1 a2
apply (simp add: bunion_bhash [OF a1 a2] bdiff_bhash [OF bunion_in_bagI [OF a1 a2] a2]
bhash_range zNats_le0)
done
lemma Z_bscale_union:
assumes
a1: "b \<in> \<zbag> X" and
a2: "n \<in> \<nat>" and
a3: "m \<in> \<nat>"
shows "(n + m) \<otimes> b = (n \<otimes> b) \<bunion> (m \<otimes> b)"
apply (rule bag_eqI')
apply (rule bscale_in_bagI [OF a1 zNats_add [OF a2 a3]])
apply (rule bunion_in_bagI [OF bscale_in_bagI [OF a1 a2] bscale_in_bagI [OF a1 a3]])
using a1 a2 a3
apply (simp add: bunion_bhash [OF bscale_in_bagI [OF a1] bscale_in_bagI [OF a1]]
bscale_bhash [OF a1] bhash_range distrib_right)
done
lemma bscale_diff:
assumes
a1: "b \<in> \<zbag> X" and
a2: "n \<in> \<nat>" and
a3: "m \<in> \<nat>" and
a4: "m \<le> n"
shows
"(n - m) \<otimes> b = (n \<otimes> b) \<bdiff> (m \<otimes> b)"
apply (rule bag_eqI')
apply (rule bscale_in_bagI [OF a1])
using a1 a2 a3 a4
apply (simp)
apply (rule bdiff_in_bagI [OF bscale_in_bagI [OF a1] bscale_in_bagI [OF a1]])
using a1 a2 a3 a4
apply (auto simp add: bdiff_bhash [OF bscale_in_bagI [OF a1] bscale_in_bagI [OF a1]]
bscale_bhash [OF a1] left_diff_distrib mult_right_mono bhash_range nat_of_norm)
done
lemma Z_bscale_diff:
assumes
a1: "b \<in> \<zbag> X" and
a2: "n \<in> \<nat>" and
a3: "m \<in> \<nat>"
shows
"m \<le> n \<Rightarrow> (n - m) \<otimes> b = (n \<otimes> b) \<bdiff> (m \<otimes> b)"
apply (msafe(inference))
apply (intro bscale_diff)
using a1 a2 a3
apply (simp_all)
done
lemma Z_bunion_distr:
assumes
a1: "b \<in> \<zbag> X" and
a2: "c \<in> \<zbag> X" and
a3: "n \<in> \<nat>"
shows
"n \<otimes> (b \<bunion> c) = (n \<otimes> b) \<bunion> (n \<otimes> c)"
apply (rule bag_eqI')
apply (rule bscale_in_bagI [OF bunion_in_bagI [OF a1 a2] a3])
apply (rule bunion_in_bagI [OF bscale_in_bagI [OF a1 a3] bscale_in_bagI [OF a2 a3]])
using a1 a2 a3
apply (simp add: bunion_bhash [OF bscale_in_bagI [OF a1 a3] bscale_in_bagI [OF a2 a3]]
bscale_bhash [OF bunion_in_bagI [OF a1 a2] a3] bunion_bhash [OF a1 a2]
bscale_bhash [OF a1 a3] bscale_bhash [OF a2 a3] distrib_left bhash_range)
done
lemma Z_bdiff_distr:
assumes
a1: "b \<in> \<zbag> X" and
a2: "c \<in> \<zbag> X" and
a3: "n \<in> \<nat>"
shows
"n \<otimes> (b \<bdiff> c) = (n \<otimes> b) \<bdiff> (n \<otimes> c)"
apply (rule bag_eqI')
apply (rule bscale_in_bagI [OF bdiff_in_bagI [OF a1 a2] a3])
apply (rule bdiff_in_bagI [OF bscale_in_bagI [OF a1 a3] bscale_in_bagI [OF a2 a3]])
apply (insert bhash_range [OF a1] bhash_range [OF a2] a1 a2 a3)
apply (auto simp add: bdiff_bhash [OF bscale_in_bagI [OF a1 a3] bscale_in_bagI [OF a2 a3]]
bscale_bhash [OF bdiff_in_bagI [OF a1 a2] a3] bdiff_bhash [OF a1 a2]
bscale_bhash [OF a1 a3] bscale_bhash [OF a2 a3] right_diff_distrib bhash_range
mult_left_mono nat_of_norm diff_mult_distrib2)
done
(*
lemma Z_bunion_bdiff_defs:
"\<forall> B C x | B \<in> \<zbag> X \<and> C \<in> \<zbag> X \<and> x \<in> X \<bullet>
((B \<bunion> C)\<sharp>x = (B\<sharp>x) + (C\<sharp>x)) \<and>
((B \<bdiff> C)\<sharp>x = zmax\<cdot>{B\<sharp>x - C\<sharp>x, (0::\<arithmos>)})"
apply (auto simp add: bunion_bhash)
apply (simp add: bdiff_bhash)
*)
section {* Bags from sequences *}
text {*
A bag can be constructed by counting the occurrances of the elements of a list.
*}
definition
bitems :: "'a seqT \<rightarrow> 'a bagT"
where
bitems_def : "bitems s \<defs> (\<mu> b' | b' \<in> \<zbag> (\<zran> s) \<and> (\<forall> x | x \<in> \<zran> s \<bullet> b'\<sharp>x = \<zcard>{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x }))"
notation (xsymbols)
bitems ("\<bitems>")
lemma bitems_in_ZNats:
"\<forall> x | x \<in> \<zran> s \<bullet> \<zcard>{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x } \<in> \<nat>"
by (simp add: zcard_def zNats_def)
lemmas bitems_wdef =
bhash_def_wdef [
of "\<zran> (s::'a seqT)" "\<olambda> x \<bullet> \<zcard>{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x }",
THEN theI',
folded bitems_def,
OF bitems_in_ZNats,
standard]
lemma bitems_in_bagI:
assumes a1: "s \<in> \<zseq> X"
shows "\<bitems> s \<in> \<zbag> X"
apply (insert bitems_wdef [of s, THEN conjunct1] a1)
apply (mauto(fspace))
done
lemma bitems_in_bagI':
"bitems s \<in> \<zbag> \<univ>"
apply (insert bitems_wdef [of s, THEN conjunct1])
apply (rule in_bag_subset)
apply (auto)
done
lemma zcard_pre_seq_zero:
assumes a1: "s \<in> \<zseq> X" and a2: "x \<notin> \<zran> s"
shows "\<zcard>{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x } = 0"
proof -
from a1 have b1: "functional s"
by (mauto(fspace))
from b1 have "{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x } = { i | (i \<mapsto> x) \<in> s }"
by (mauto(wind) msimp add: functional_unique functional_beta)
(*
apply (mauto(wind))
apply (msafe(inference))
apply (simp add: functional_unique)
apply (fast)
apply (simp add: functional_beta)
done
*)
also from a2 have "{ i | (i \<mapsto> x) \<in> s } = \<emptyset>"
by (auto)
finally have b2: "{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x } = \<emptyset>"
by (this)
show "?thesis"
by (simp add: b2 zcard_def)
qed
lemma zcard_pre_image:
assumes a1: "s \<in> \<zseq> X"
shows "\<zcard>{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x } = \<zcard>{ i | (i \<mapsto> x) \<in> s \<bullet> (i \<mapsto> x)}"
proof -
from a1 have b1: "{ i | (i \<mapsto> x) \<in> s \<bullet> (i \<mapsto> x)} = (\<olambda> i \<bullet> (i \<mapsto> x))\<lparr>{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x }\<rparr>"
apply (auto)
apply (mauto(fspace))
apply (auto intro: functional_appl functional_beta simp add: image_def)
done
then show "?thesis"
apply (simp add: zcard_def)
apply (rule sym)
apply (rule card_image)
apply (rule inj_onI)
apply (auto)
done
qed
lemma bitems_bhash:
assumes a1: "s \<in> \<zseq> X"
shows "(\<bitems> s)\<sharp>x = \<zcard>{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x }"
apply (cases "x \<in> \<zran> s")
apply (insert bitems_wdef [of s, THEN conjunct2])
apply (simp)
apply (insert bitems_wdef [of s, THEN conjunct1])
apply (simp add: bhash_beta' [OF bitems_wdef [of s, THEN conjunct1]])
apply (mauto(fspace))
apply (auto simp add: zcard_pre_seq_zero [OF a1])
done
lemma Z_bitems_def:
assumes a1: "s \<in> \<zseq> X" "x \<in> X"
shows "(\<bitems> s)\<sharp>x \<defs> \<zcard>{ i | i \<in> \<zdom> s \<and> s\<cdot>i = x }"
using a1
by (simp add: bitems_bhash)
lemma Z_bitems_dom:
assumes a1: "s \<in> \<zseq> X"
shows "\<zdom> (\<bitems> s) = \<zran> s"
apply (rule set_eqI)
apply (simp add: Z_dom_bhash [OF bitems_in_bagI [OF a1]] bitems_bhash [OF a1]
zcard_pre_image [OF a1] zNats1_pos [OF zcard_range])
proof -
fix x
from a1 have "{ i | (i \<mapsto> x) \<in> s \<bullet> (i \<mapsto> x) } \<subseteq> s" "finite s"
by (auto intro: seq_finite)
then have b2: "finite { i | (i \<mapsto> x) \<in> s \<bullet> (i \<mapsto> x) }"
by (rule finite_subset)
have "0 < \<zcard>{ i | (i \<mapsto> x) \<in> s \<bullet> (i \<mapsto> x) } \<Leftrightarrow> { i | (i \<mapsto> x) \<in> s \<bullet> (i \<mapsto> x) } \<noteq> \<emptyset>"
apply (subst zcard_nempty_conv [OF b2])
apply (fast)
done
also have "\<dots> \<Leftrightarrow> x \<in> \<zran> s"
apply (subst nempty_conv)
apply (auto)
done
finally show "0 < \<zcard>{ i | (i \<mapsto> x) \<in> s \<bullet> (i \<mapsto> x) } \<Leftrightarrow> x \<in> \<zran> s"
by (this)
qed
lemma zcard_pre_sinsert:
assumes a1: "s \<in> \<zseq> X" and a2: "x \<in> X" and a3: "y \<in> X"
shows "\<zcard>{i | (i, x) \<in> sinsert y s \<bullet> (i \<mapsto> x)}
= \<if> y = x
\<then> \<zcard>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)} + 1
\<else> \<zcard>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)}
\<fi>"
proof (auto)
have "\<zcard>{i | (i, x) \<in> sinsert x s \<bullet> (i \<mapsto> x)}
= \<zcard>{i | (i, x) \<in> insert (1 \<mapsto> x) (stranslate s 1) \<bullet> (i \<mapsto> x)}"
by (simp add: sinsert_redef [OF a1 a2])
also have "{i | (i, x) \<in> insert (1 \<mapsto> x) (stranslate s 1) \<bullet> (i \<mapsto> x)}
= (insert (1 \<mapsto> x) {i | (i, x) \<in> (stranslate s 1) \<bullet> (i \<mapsto> x)})"
by (auto)
also have "\<zcard>(insert (1 \<mapsto> x) {i | (i, x) \<in> (stranslate s 1) \<bullet> (i \<mapsto> x)})
= (\<zcard>{i | (i, x) \<in> (stranslate s 1) \<bullet> (i \<mapsto> x)}) + 1"
apply (rule zcard_insert_disjoint)
apply (rule finite_subset [OF _ stranslate_finite [of s 1]])
apply (simp add: eind_def subset_def)
apply (rule seq_finite [OF a1])
apply (simp add: stranslate_def)
apply (rule contrapos_nn)
defer 1
apply (rule DomainI)
apply (assumption)
apply (simp add: seq_dom [OF a1])
done
also have "\<zcard>{i | (i, x) \<in> (stranslate s 1) \<bullet> (i \<mapsto> x)}
= \<zcard>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)}"
proof -
let ?f = "\<olambda>(n::\<arithmos>, x::'b) \<bullet> (n + 1, x)"
have c1: "{i | (i, x) \<in> (stranslate s 1) \<bullet> (i \<mapsto> x)} = ?f\<lparr>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)}\<rparr>"
by (auto simp add: stranslate_def eind_def)
show "?thesis"
apply (subst c1)
apply (rule zcard_image)
apply (rule inj_onI)
apply (auto)
done
qed
finally show "\<zcard>{i | (i, x) \<in> sinsert x s \<bullet> (i \<mapsto> x)}
= (\<zcard>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)}) + 1"
by (this)
next
assume b1: "y \<noteq> x"
have "\<zcard>{i | (i, x) \<in> sinsert y s \<bullet> (i \<mapsto> x)}
= \<zcard>{i | (i, x) \<in> insert (1 \<mapsto> y) (stranslate s 1) \<bullet> (i \<mapsto> x)}"
by (simp add: sinsert_redef [OF a1 a3])
also from b1 have "{i | (i, x) \<in> insert (1 \<mapsto> y) (stranslate s 1) \<bullet> (i \<mapsto> x)}
= {i | (i, x) \<in> (stranslate s 1) \<bullet> (i \<mapsto> x)}"
by (auto)
also have "\<zcard>{i | (i, x) \<in> (stranslate s 1) \<bullet> (i \<mapsto> x)}
= \<zcard>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)}"
proof -
let ?f = "\<olambda>(n::\<arithmos>, x::'b) \<bullet> (n + 1, x)"
have c1: "{i | (i, x) \<in> (stranslate s 1) \<bullet> (i \<mapsto> x)} = ?f\<lparr>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)}\<rparr>"
by (auto simp add: stranslate_def eind_def)
show "?thesis"
apply (subst c1)
apply (rule zcard_image)
apply (rule inj_onI)
apply (auto)
done
qed
finally show "\<zcard>{i | (i, x) \<in> sinsert y s \<bullet> (i \<mapsto> x)}
= \<zcard>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)}"
by (this)
qed
lemma Z_bitems_concat:
assumes a1: "s \<in> \<zseq> X" and a2: "t \<in> \<zseq> X"
shows "\<bitems> (s \<zcat> t) = \<bitems> s \<bunion> \<bitems> t"
apply (rule bag_eqI')
apply (rule bitems_in_bagI [OF sconcat_closed [OF a1 a2]])
apply (rule bunion_in_bagI [OF bitems_in_bagI [OF a1] bitems_in_bagI [OF a2]])
apply (simp add: bitems_bhash [OF sconcat_closed [OF a1 a2]]
bunion_bhash [OF bitems_in_bagI [OF a1] bitems_in_bagI [OF a2]] bitems_bhash [OF a1]
bitems_bhash [OF a2] zcard_pre_image [OF sconcat_closed [OF a1 a2]]
zcard_pre_image [OF a1] zcard_pre_image [OF a2])
proof -
fix x
assume b1: "x \<in> X"
show "\<zcard>{i | (i, x) \<in> s \<zcat> t \<bullet> (i \<mapsto> x)} = \<zcard>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)} + \<zcard>{i | (i, x) \<in> t \<bullet> (i \<mapsto> x)}"
apply (induct s rule: seq_induct_insert)
apply (rule a1)
proof -
show "\<zcard>{i | (i, x) \<in> \<sempty> \<zcat> t \<bullet> (i \<mapsto> x)} = \<zcard>{i | (i, x) \<in> \<sempty> \<bullet> (i \<mapsto> x)} + \<zcard>{i | (i, x) \<in> t \<bullet> (i \<mapsto> x)}"
apply (simp add: Z_sconcat_sempty [OF a2])
apply (simp add: sempty_def eind_def)
done
next
fix s y
assume c1: "s \<in> \<zseq> X" and c2: "y \<in> X" and
c3: "\<zcard>{i | (i, x) \<in> s \<zcat> t \<bullet> (i \<mapsto> x)} = \<zcard>{i | (i, x) \<in> s \<bullet> (i \<mapsto> x)} + \<zcard>{i | (i, x) \<in> t \<bullet> (i \<mapsto> x)}"
have "\<zcard>{i | (i, x) \<in> sinsert y (s \<zcat> t) \<bullet> (i \<mapsto> x)} = \<zcard>{i | (i, x) \<in> sinsert y s \<bullet> (i \<mapsto> x)} + \<zcard>{i | (i, x) \<in> t \<bullet> (i \<mapsto> x)}"
by (simp add: zcard_pre_sinsert [OF c1 b1 c2] zcard_pre_sinsert [OF sconcat_closed [OF c1 a2] b1 c2] c3)
also from c1 c2 a2 sconcat_closed [OF c1 a2] sinsert_closed [OF sempty_seq c2]
have "sinsert y (s \<zcat> t) = (sinsert y s) \<zcat> t"
by (simp add: sinsert_sconcat Z_sconcat_assoc)
finally show "\<zcard>{i | (i, x) \<in> (sinsert y s) \<zcat> t \<bullet> (i \<mapsto> x)} = \<zcard>{i | (i, x) \<in> sinsert y s \<bullet> (i \<mapsto> x)} + \<zcard>{i | (i, x) \<in> t \<bullet> (i \<mapsto> x)}"
by (this)
qed
qed
lemma bitems_sempty:
"bitems \<sempty> = \<lbag> \<rbag>"
apply (rule bag_eqI)
apply (rule bitems_in_bagI)
apply (rule sempty_seq)
apply (rule bempty_in_bagI)
apply (simp add: bitems_bhash [OF sempty_seq])
apply (simp add: sempty_def bempty_bhash)
done
lemma Z_bitems_sinsert:
assumes a1: "s \<in> \<zseq> X" and a2: "x \<in> X"
shows "bitems (sinsert x s) = binsert x (bitems s)"
apply (rule bag_eqI')
apply (rule bitems_in_bagI)
apply (rule sinsert_closed [OF a1 a2])
apply (rule binsert_in_bagI [OF bitems_in_bagI [OF a1] a2])
apply (simp add: bitems_bhash [OF sinsert_closed [OF a1 a2]] binsert_bhash
bitems_bhash [OF a1] zcard_pre_image [OF a1] zcard_pre_image [OF sinsert_closed [OF a1 a2]]
zcard_pre_sinsert [OF a1 a2 a2] zcard_pre_sinsert [OF a1 _ a2])
done
lemmas fin_bitems = bitems_sempty Z_bitems_sinsert
lemma Z_bitems_permutations:
assumes a1: "s \<in> \<zseq> X" and a2: "t \<in> \<zseq> X"
shows "\<bitems> s = \<bitems> t \<Leftrightarrow> (\<exists> f | f \<in> \<zdom> s \<zbij> \<zdom> t \<bullet> s = t \<zbcomp> f)"
proof (rule iffI)
assume b1: "\<bitems> s = \<bitems> t"
then have "\<zdom> (\<bitems> s) = \<zdom> (\<bitems> t)"
by (simp)
then have b2: "\<zran> s = \<zran> t"
by (simp add: Z_bitems_dom [OF a1] Z_bitems_dom [OF a2])
from b1 have
b3: "\<forall> x | x \<in> \<zran> s \<bullet>
(\<exists> f \<bullet> f \<in> { i | i \<in> \<zdom> s \<and> s\<cdot>i = x } \<zbij> { i | i \<in> \<zdom> t \<and> t\<cdot>i = x })"
apply (msafe(inference))
apply (rule zcard_eq_bij [where ?'c = "arithmos"])
apply (rule finite_subset [OF _ seq_finite_dom [OF a1]])
apply (fast)
apply (rule finite_subset [OF _ seq_finite_dom [OF a2]])
apply (fast)
using a1 a2
apply (simp add: bitems_bhash [symmetric])
done
then obtain F where
b4: "(\<forall> x | x \<in> \<zran> s \<bullet> F x \<in> { i | i \<in> \<zdom> s \<and> s\<cdot>i = x } \<zbij> { i | i \<in> \<zdom> t \<and> t\<cdot>i = x })"
by (auto simp add: qual_ax_choice_eq)
let ?f = "\<Union> x | x \<in> \<zran> s \<bullet> F x"
have
b5: "(\<forall> x | x \<in> \<zran> s \<bullet>
functional (F x) \<and> functional ((F x)\<^sup>\<sim>) \<and>
\<zdom> (F x) = { i | i \<in> \<zdom> s \<and> s\<cdot>i = x } \<and>
\<zran> (F x) = { i | i \<in> \<zdom> t \<and> t\<cdot>i = x })"
apply (rule mp [OF _ b4])
apply (msafe(wind))
apply (msafe(inference))
apply (mauto(fspace))
done
have
b5': "(\<forall> x | x \<in> \<zran> s \<bullet>
functional (F x) \<and> functional ((F x)\<^sup>\<sim>) \<and>
\<zdom> (F x) = { i | (i \<mapsto> x) \<in> s} \<and>
\<zran> (F x) = { i | (i \<mapsto> x) \<in> t})"
proof (msafe(inference))
fix x assume c1: "x \<in> \<zran> s"
from b5 [rule_format, OF c1] show "functional (F x)" "functional ((F x)\<^sup>\<sim>)"
by (auto)
from b5 [rule_format, OF c1] show "\<zdom> (F x) = { i | (i \<mapsto> x) \<in> s}"
by (auto simp add: functional_beta [OF seq_functional [OF a1]])
from b5 [rule_format, OF c1] show "\<zran> (F x) = { i | (i \<mapsto> x) \<in> t}"
by (auto simp add: functional_beta [OF seq_functional [OF a2]])
qed
have b6: "?f \<in> \<zdom> s \<zbij> \<zdom> t"
proof (mauto(fspace))
show "functional (\<Union> x | x \<in> Range s \<bullet> F x)"
apply (rule rel_Union_functional')
apply (simp add: b5 [rule_format])
proof -
fix x y
assume d1: "x \<in> \<zran> s" and d2: "y \<in> \<zran> s"
show "\<zdom> (F y) \<zdres> F x = \<zdom> (F x) \<zdres> F y"
apply (cases "x = y")
apply (simp)
proof -
assume e1: "x \<noteq> y"
with d1 d2 have "\<zdom> (F x) \<inter> \<zdom> (F y) = \<emptyset>"
apply (simp add: b5 [rule_format])
apply (auto)
done
then show "?thesis"
by (auto simp add: dres_def eind_def)
qed
qed
show "functional ((\<Union> x | x \<in> Range s \<bullet> F x)\<^sup>\<sim>)"
apply (simp add: converse_Union eind_norm [of "Collect"])
apply (rule rel_Union_functional')
apply (simp add: b5 [rule_format])
proof -
fix x y
assume d1: "x \<in> \<zran> s" and d2: "y \<in> \<zran> s"
show "\<zdom> ((F y)\<^sup>\<sim>) \<zdres> (F x)\<^sup>\<sim> = \<zdom> ((F x)\<^sup>\<sim>) \<zdres> (F y)\<^sup>\<sim>"
apply (cases "x = y")
apply (simp)
proof -
assume e1: "x \<noteq> y"
with d1 d2 have "\<zdom> ((F x)\<^sup>\<sim>) \<inter> \<zdom> ((F y)\<^sup>\<sim>) = \<emptyset>"
apply (simp add: b5 [rule_format] Z_inverse_dom)
apply (auto)
done
then show "?thesis"
by (auto simp add: dres_def Range_iff set_eq_def)
qed
qed
have "\<zdom> (\<Union> x | x \<in> \<zran> s \<bullet> F x) = (\<Union> x | x \<in> \<zran> s \<bullet> \<zdom> (F x))"
by (simp add: rel_Union_dom eind_def eind_comp)
also have "\<dots> = (\<Union> x | x \<in> Range s \<bullet> { i | i \<in> \<zdom> s \<and> s\<cdot>i = x })"
by (mauto(wind) msimp add: b5 [rule_format])
also have "\<dots> = \<zdom> s"
apply (auto)
apply (rule seq_in_ran1 [OF a1])
apply (auto)
done
finally show "\<zdom> (\<Union> x | x \<in> Range s \<bullet> F x) = \<zdom> s"
by (this)
have "\<zran> (\<Union> x | x \<in> Range s \<bullet> F x) = (\<Union> x | x \<in> Range s \<bullet> \<zran> (F x))"
by (simp add: rel_Union_ran eind_def eind_comp)
also have "\<dots> = (\<Union> x | x \<in> Range s \<bullet> { i | i \<in> \<zdom> t \<and> t\<cdot>i = x })"
by (mauto(wind) msimp add: b5 [rule_format])
also have "\<dots> = \<zdom> t"
apply (auto simp add: b2)
apply (rule seq_in_ran1 [OF a2])
apply (auto)
done
finally show "\<zran> (\<Union> x | x \<in> Range s \<bullet> F x) = \<zdom> t"
by (this)
qed
from b6 have b6': "functional ?f"
by (mauto(fspace))
have b7: "s = t \<zbcomp> ?f"
proof (rule rel_eqI)
fix i x
show "(i \<mapsto> x) \<in> s \<Leftrightarrow> (i \<mapsto> x) \<in> t \<zbcomp> ?f"
apply (auto simp add: rel_bcomp_def)
apply (witness "(F x)\<cdot>i")
apply (msafe(inference))
apply (witness "x")
apply (msafe(inference))
proof -
assume d1: "(i \<mapsto> x) \<in> s"
then show d2: "x \<in> \<zran> s"
by (auto)
from d1 b5' [rule_format, OF d2] show "(i \<mapsto> (F x)\<cdot>i) \<in> F x"
by (auto intro!: functional_appl)
with d1 b5' [rule_format, OF d2] show "((F x)\<cdot>i \<mapsto> x) \<in> t"
by (auto)
next
fix k j y
assume d1: "(k \<mapsto> x) \<in> t" and d2: "(i \<mapsto> k) \<in> F y" and d3: "(j \<mapsto> y) \<in> s"
from d3 have d4: "y \<in> \<zran> s"
by (auto)
from b5' [rule_format, OF d4] d2 have d5: "(k \<mapsto> y) \<in> t"
by (auto)
from seq_functional [OF a2] d1 d5 have d6: "x = y"
by (rule functionalD)
from b5' [rule_format, OF d4] d2 d6
show "(i \<mapsto> x) \<in> s"
by (auto)
qed
qed
from b6 b7 show "(\<exists> f | f \<in> \<zdom> s \<zbij> \<zdom> t \<bullet> s = t \<zbcomp> f)"
apply (witness "?f")
apply (auto)
done
next
apply_end (msafe_no_assms(inference))
fix f
assume b1: "f \<in> \<zdom> s \<zbij> \<zdom> t" and b2: "s = t \<zbcomp> f"
from b1 have b3: "functional f"
by (mauto(fspace))
from b1 have b4: "functional (f\<^sup>\<sim>)"
by (mauto(fspace))
from b1 have b5: "\<zdom> s = \<zdom> f"
by (mauto(fspace))
from b1 have b6: "\<zdom> t = \<zran> f"
by (mauto(fspace))
from b1 a2 have b7: "(\<forall> i j | (i \<mapsto> j) \<in> f \<bullet> s\<cdot>i = t\<cdot>j)"
apply (msafe(inference))
apply (simp add: b2)
apply (rule trans)
apply (rule bcomp_beta)
apply (mauto(fspace))
apply (auto simp add: functional_beta)
done
show "\<bitems> s = \<bitems> t"
apply (rule bag_eqI)
apply (rule bitems_in_bagI [OF a1])
apply (rule bitems_in_bagI [OF a2])
apply (auto simp add: bitems_bhash [OF a1] bitems_bhash [OF a2])
proof -
fix x
from b1 have
c1: "{i | i \<in> Domain s \<and> s\<cdot>i = x} \<zdres> f
\<in> {i | i \<in> Domain s \<and> s\<cdot>i = x} \<zbij> {i | i \<in> Domain t \<and> t\<cdot>i = x}"
proof (mauto(fspace))
show "\<zdom> ({i | i \<in> Domain s \<and> s\<cdot>i = x} \<zdres> f) = {i | i \<in> Domain s \<and> s\<cdot>i = x}"
by (auto simp add: Z_dres_dom b5)
from b7 [rule_format]
show "\<zran> ({i | i \<in> Domain s \<and> s\<cdot>i = x} \<zdres> f) = {i | i \<in> Domain t \<and> t\<cdot>i = x}"
apply (auto simp add: dres_def b5 b6 ran_eind Domain_iff)
apply (auto intro!: exI)
proof -
fix i j k
assume d1: "(i \<mapsto> j) \<in> f" and d2: "(i \<mapsto> k) \<in> f"
show "t\<cdot>j = t\<cdot>k"
by (simp add: functionalD [OF b3 d1 d2])
qed
qed
show "\<zcard>{i | i \<in> Domain s \<and> s\<cdot>i = x} = \<zcard>{i | i \<in> Domain t \<and> t\<cdot>i = x}"
by (rule zcard_Image [where ?'c = "arithmos", OF c1, symmetric])
qed
qed
end
|
Formal statement is: lemma locally_path_connected_UNIV: "locally path_connected (UNIV::'a :: real_normed_vector set)" Informal statement is: The real vector space $\mathbb{R}^n$ is locally path-connected. |
find_thumbnails {
*thb_list = list()
*err = errormsg(get_list_of_thumbnails(*src_obj_path, *thb_list), *msg)
if(0 != *err) {
writeLine( "stdout", "FAIL: [*err] [*msg]")
}
foreach( *t in *thb_list ) {
writeLine("stdout", "thumbnail [*t]")
}
}
INPUT *src_obj_path="/tempZone/home/rods/stickers.jpg"
OUTPUT ruleExecOut
|
State Before: n m : ℕ
⊢ lxor' (lxor' m n) n = m State After: no goals Tactic: rw [lxor'_assoc, lxor'_self, lxor'_zero] |
inductive TreeNode :=
| mkLeaf (name : String) : TreeNode
| mkNode (name : String) (children : List TreeNode) : TreeNode
def treeToList (t : TreeNode) : List String :=
match t with
| .mkLeaf name => [name]
| .mkNode name children => Id.run do
let mut r := [name]
for h : child in children do
-- We will not this the following `have` in the future
have : sizeOf child < 1 + sizeOf name + sizeOf children := Nat.lt_trans (List.sizeOf_lt_of_mem h) (by simp_arith)
r := r ++ treeToList child
return r
@[simp] theorem treeToList_eq (name : String) (children : List TreeNode) : treeToList (.mkNode name children) = name :: List.join (children.map treeToList) := by
simp [treeToList, Id.run, forIn, List.forIn]
have : ∀ acc, (Id.run do List.forIn.loop (fun a b => ForInStep.yield (b ++ treeToList a)) children acc) = acc ++ List.join (List.map treeToList children) := by
intro acc
induction children generalizing acc with simp [List.forIn.loop, List.map, List.join, Id.run]
| cons c cs ih => simp [Id.run] at ih; simp [ih, List.append_assoc]
apply this
mutual
def numNames : TreeNode → Nat
| .mkLeaf _ => 1
| .mkNode _ cs => 1 + numNamesLst cs
def numNamesLst : List TreeNode → Nat
| [] => 0
| a :: as => numNames a + numNamesLst as
end
theorem length_treeToList_eq_numNames (t : TreeNode) : (treeToList t).length = numNames t := by
match t with
| .mkLeaf .. => simp [treeToList, numNames]
| .mkNode _ cs => simp_arith [numNames, helper cs]
where
helper (cs : List TreeNode) : (cs.map treeToList).join.length = numNamesLst cs := by
match cs with
| [] => rfl
| c::cs' => simp [List.join, List.map, numNamesLst, length_treeToList_eq_numNames c, helper cs']
|
import for_mathlib.category_theory.localization.derived_functor_shift
import for_mathlib.category_theory.triangulated.is_triangulated_subcategory
open category_theory category_theory.category category_theory.limits
noncomputable theory
namespace category_theory
namespace right_derivability_structure
variables {C₀ C H D : Type*} [category C₀] [category C] [category D] [category H]
{W₀ : morphism_property C₀} {W : morphism_property C} {Φ : localizor_morphism W₀ W}
[localizor_morphism.is_localization_equivalence Φ]
[morphism_property.multiplicative W₀] [morphism_property.multiplicative W]
(β : right_derivability_structure.basic Φ)
(F : C ⥤ D) (L : C ⥤ H)
(hF : W₀.is_inverted_by (Φ.functor ⋙ F))
[has_shift C₀ ℤ] [has_shift C ℤ] [has_shift H ℤ] [has_shift D ℤ]
[F.has_comm_shift ℤ] [L.has_comm_shift ℤ] [Φ.functor.has_comm_shift ℤ]
[preadditive C₀] [preadditive C] [preadditive H] [preadditive D]
[has_zero_object C₀] [has_zero_object C] [has_zero_object H] [has_zero_object D]
[∀ (n : ℤ ), (shift_functor C₀ n).additive]
[∀ (n : ℤ ), (shift_functor C n).additive]
[∀ (n : ℤ ), (shift_functor H n).additive]
[∀ (n : ℤ ), (shift_functor D n).additive]
[L.is_localization W]
[pretriangulated C₀] [pretriangulated C] [pretriangulated H] [pretriangulated D]
[functor.is_triangulated F] [functor.is_triangulated Φ.functor]
namespace basic
include β
lemma Φ_functor_comp_L_ess_surj_on_dist_triang [L.ess_surj_on_dist_triang] [L.is_triangulated]:
(Φ.functor ⋙ L).ess_surj_on_dist_triang :=
⟨λ T hT, begin
obtain ⟨T', hT', ⟨e⟩⟩ := functor.ess_surj_on_dist_triang.condition L T hT,
obtain ⟨X₁, X₂, f', fac⟩ := β.nonempty_arrow_right_resolution T'.mor₁,
obtain ⟨X₃, g, h, mem⟩ := pretriangulated.distinguished_cocone_triangle _ _ f',
haveI : is_iso (L.map X₁.hom.f) := localization.inverts L W _ X₁.hom.hf,
haveI : is_iso (L.map X₂.hom.f) := localization.inverts L W _ X₂.hom.hf,
refine ⟨_, mem, ⟨iso.symm _ ≪≫ e⟩⟩,
refine pretriangulated.iso_triangle_of_distinguished_of_is_iso₁₂ _ _
(L.map_distinguished _ hT') ((Φ.functor ⋙ L).map_distinguished _ mem)
(as_iso (L.map X₁.hom.f)) (as_iso (L.map X₂.hom.f))
(by { dsimp, simp only [← L.map_comp, fac]}),
end⟩
variable [functor.ess_surj_on_dist_triang (Φ.functor ⋙ L)]
include hF
lemma derived_functor_is_triangulated' [F.has_right_derived_functor W] :
(F.right_derived_functor L W).is_triangulated :=
⟨λ T hT, begin
obtain ⟨T', hT', ⟨e⟩⟩ := functor.ess_surj_on_dist_triang.condition (Φ.functor ⋙ L) T hT,
have E' := (functor.map_triangle_comp (Φ.functor ⋙ L) (F.right_derived_functor L W)).symm.app T',
let τ : Φ.functor ⋙ F ⟶ (Φ.functor ⋙ L) ⋙ F.right_derived_functor L W :=
whisker_left Φ.functor (F.right_derived_functor_α L W) ≫ (functor.associator _ _ _).inv,
haveI : ∀ (X₀ : C₀), is_iso (τ.app X₀) := λ X₀, begin
dsimp [τ],
rw [comp_id],
apply β.is_iso_app L F hF,
end,
haveI := nat_iso.is_iso_of_is_iso_app τ,
haveI : (as_iso τ).hom.respects_comm_shift ℤ := by { dsimp [as_iso], apply_instance, },
exact pretriangulated.isomorphic_distinguished _ (functor.map_distinguished _ _ hT') _
((F.right_derived_functor L W).map_triangle.map_iso e.symm ≪≫
(functor.map_triangle_comp (Φ.functor ⋙ L) (F.right_derived_functor L W)).symm.app T' ≪≫
(functor.map_triangle_nat_iso (as_iso τ)).symm.app T'),
end⟩
lemma derived_functor_is_triangulated (RF : H ⥤ D) (α : F ⟶ L ⋙ RF)
[RF.is_right_derived_functor α] [RF.has_comm_shift ℤ] [α.respects_comm_shift ℤ] :
RF.is_triangulated :=
begin
haveI := functor.is_right_derived_functor.has_right_derived_functor F RF L α W,
haveI := β.derived_functor_is_triangulated' F L hF,
let e := nat_iso.right_derived (iso.refl F) (F.right_derived_functor_α L W) α,
haveI : e.hom.respects_comm_shift ℤ,
{ refine ⟨λ n, _⟩,
apply functor.is_right_derived_functor_to_ext
(shift_functor H n ⋙ F.right_derived_functor L W)
(functor.has_comm_shift.right_derived_shift_α F L W n),
ext X,
simp only [nat_trans.comp_app, whisker_left_app, whisker_right_app],
erw functor.has_comm_shift.right_derived_comm_shift_comm_assoc,
simp only [nat_iso.right_derived_hom, iso.refl_hom,
functor.has_comm_shift.right_derived_α_shift_app, ← functor.map_comp,
nat_trans.right_derived_app (𝟙 F) (F.right_derived_functor_α L W) α X,
nat_trans.id_app, id_comp,
functor.has_comm_shift.right_derived_shift_α_app,
assoc, nat_trans.naturality_assoc, nat_trans.right_derived_app_assoc,
nat_trans.respects_comm_shift.comm_app α n X,
functor.has_comm_shift.comp_hom_app], },
exact functor.is_triangulated.of_iso e,
end
end basic
end right_derivability_structure
end category_theory
|
------------------------------------------------------------------------
-- Subject reduction for typing in Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
-- This module proves a variant of subject reduction (aka the
-- "preservation" theorem) for term reduction in Fω with interval
-- kinds. The subject reduction property proved here is weaker than
-- the one typically found in the literature on other variants of Fω:
-- subject reduction does not hold in arbitrary typing contexts in Fω
-- with interval types because type variables of interval kind can be
-- used to introduce arbitrary typing (in)equalities into the
-- subtyping relation. In other words, subject reduction does not
-- hold for full β-reduction as reductions under type abstractions are
-- not safe in general. Note, however, that subject reduction does
-- hold for arbitrary β-reductions in *types* (see `pres-Tp∈-→β*' in
-- the Kinding.Declarative.Validity module for a proof).
--
-- NOTE. Here we use the CBV evaluation strategy, but this is
-- unnecessarily restrictive. Other evaluation strategies work so
-- long as they do not allow reductions under type abstractions.
--
-- Together with the "progress" theorem from Typing.Progress, subject
-- reduction ensures type safety. For details, see e.g.
--
-- * B. C. Pierce, TAPL (2002), pp. 95.
--
-- * A. Wright and M. Felleisen, "A Syntactic Approach to Type
-- Soundness" (1994).
module FOmegaInt.Typing.Preservation where
open import Data.Product using (_,_)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_)
open import Relation.Binary.PropositionalEquality using (subst)
open import Relation.Nullary.Negation using (contradiction)
open import FOmegaInt.Syntax
open import FOmegaInt.Typing
open import FOmegaInt.Typing.Inversion
open import FOmegaInt.Reduction.Cbv
open import FOmegaInt.Reduction.Full
open Syntax
open TermCtx
open Substitution using (_[_]; weaken-sub)
open Typing
open TypedSubstitution using (Tm∈-[]; <:-[])
-- Types of closed terms are preserved under single-step reduction.
pres : ∀ {a b c} → [] ⊢Tm a ∈ c → a →v b → [] ⊢Tm b ∈ c
pres (∈-var () _ _)
pres (∈-∀-i k-kd a∈b) ()
pres (∈-→-i a∈* b∈c c∈*) ()
pres (∈-∀-e Λja∈Πkc b∈k) (cont-⊡ j a b) with Tm∈-gen Λja∈Πkc
... | ∈-∀-i j-kd a∈d Πjd<:Πkc =
let k<∷j , d<:c = <:-∀-inv Πjd<:Πkc
in ∈-⇑ (Tm∈-[] a∈d (∈-tp (∈-⇑ b∈k k<∷j))) (<:-[] d<:c (∈-tp b∈k))
pres (∈-∀-e a∈Πcd b∈c) (a→e ⊡ b) = ∈-∀-e (pres a∈Πcd a→e) b∈c
pres (∈-→-e ƛea∈c⇒d v∈c) (cont-· e a v) with Tm∈-gen ƛea∈c⇒d
... | ∈-→-i e∈* a∈f e⇒f<:c⇒d =
let c<:e , f<:d = <:-→-inv e⇒f<:c⇒d
in ∈-⇑ (subst (_ ⊢Tm _ ∈_) (weaken-sub _) (Tm∈-[] a∈f (∈-tm (∈-⇑ v∈c c<:e))))
f<:d
pres (∈-→-e a∈c⇒d b∈c) (a→e ·₁ b) = ∈-→-e (pres a∈c⇒d a→e) b∈c
pres (∈-→-e a∈c⇒d b∈c) (v ·₂ b→e) = ∈-→-e a∈c⇒d (pres b∈c b→e)
pres (∈-⇑ a∈c c<:d) a→b = ∈-⇑ (pres a∈c a→b) c<:d
-- Weak preservation (aka subject reduction): types of closed terms
-- are preserved under reduction.
pres* : ∀ {a b c} → [] ⊢Tm a ∈ c → a →v* b → [] ⊢Tm b ∈ c
pres* a∈c ε = a∈c
pres* a∈d (a→b ◅ b→*c) = pres* (pres a∈d a→b) b→*c
|
The lemma swap_apply(2) is now called swap_apply2. |
[GOAL]
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
⊢ Projective R P ↔ ∃ s, comp (Finsupp.total P P R id) s = LinearMap.id
[PROOFSTEP]
simp_rw [projective_def, FunLike.ext_iff, Function.LeftInverse, comp_apply, id_apply]
[GOAL]
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
⊢ ∃ h, comp f h = g
[PROOFSTEP]
let φ : (P →₀ R) →ₗ[R] M :=
Finsupp.total _ _ _ fun p =>
Function.surjInv hf
(g p)
-- By projectivity we have a map `P →ₗ (P →₀ R)`;
[GOAL]
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
φ : (P →₀ R) →ₗ[R] M := Finsupp.total P M R fun p => Function.surjInv hf (↑g p)
⊢ ∃ h, comp f h = g
[PROOFSTEP]
cases' h.out with s hs
[GOAL]
case intro
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
φ : (P →₀ R) →ₗ[R] M := Finsupp.total P M R fun p => Function.surjInv hf (↑g p)
s : P →ₗ[R] P →₀ R
hs : Function.LeftInverse ↑(Finsupp.total P P R id) ↑s
⊢ ∃ h, comp f h = g
[PROOFSTEP]
use φ.comp s
[GOAL]
case h
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
φ : (P →₀ R) →ₗ[R] M := Finsupp.total P M R fun p => Function.surjInv hf (↑g p)
s : P →ₗ[R] P →₀ R
hs : Function.LeftInverse ↑(Finsupp.total P P R id) ↑s
⊢ comp f (comp φ s) = g
[PROOFSTEP]
ext p
[GOAL]
case h.h
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
φ : (P →₀ R) →ₗ[R] M := Finsupp.total P M R fun p => Function.surjInv hf (↑g p)
s : P →ₗ[R] P →₀ R
hs : Function.LeftInverse ↑(Finsupp.total P P R id) ↑s
p : P
⊢ ↑(comp f (comp φ s)) p = ↑g p
[PROOFSTEP]
conv_rhs => rw [← hs p]
[GOAL]
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
φ : (P →₀ R) →ₗ[R] M := Finsupp.total P M R fun p => Function.surjInv hf (↑g p)
s : P →ₗ[R] P →₀ R
hs : Function.LeftInverse ↑(Finsupp.total P P R id) ↑s
p : P
| ↑g p
[PROOFSTEP]
rw [← hs p]
[GOAL]
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
φ : (P →₀ R) →ₗ[R] M := Finsupp.total P M R fun p => Function.surjInv hf (↑g p)
s : P →ₗ[R] P →₀ R
hs : Function.LeftInverse ↑(Finsupp.total P P R id) ↑s
p : P
| ↑g p
[PROOFSTEP]
rw [← hs p]
[GOAL]
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
φ : (P →₀ R) →ₗ[R] M := Finsupp.total P M R fun p => Function.surjInv hf (↑g p)
s : P →ₗ[R] P →₀ R
hs : Function.LeftInverse ↑(Finsupp.total P P R id) ↑s
p : P
| ↑g p
[PROOFSTEP]
rw [← hs p]
[GOAL]
case h.h
R : Type u_1
inst✝⁶ : Semiring R
P : Type u_2
inst✝⁵ : AddCommMonoid P
inst✝⁴ : Module R P
M : Type u_3
inst✝³ : AddCommMonoid M
inst✝² : Module R M
N : Type u_4
inst✝¹ : AddCommMonoid N
inst✝ : Module R N
h : Projective R P
f : M →ₗ[R] N
g : P →ₗ[R] N
hf : Function.Surjective ↑f
φ : (P →₀ R) →ₗ[R] M := Finsupp.total P M R fun p => Function.surjInv hf (↑g p)
s : P →ₗ[R] P →₀ R
hs : Function.LeftInverse ↑(Finsupp.total P P R id) ↑s
p : P
⊢ ↑(comp f (comp φ s)) p = ↑g (↑(Finsupp.total P P R id) (↑s p))
[PROOFSTEP]
simp [Finsupp.total_apply, Function.surjInv_eq hf]
[GOAL]
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
inst✝¹ : Projective R P
inst✝ : Projective R Q
⊢ Projective R (P × Q)
[PROOFSTEP]
refine .of_lifting_property'' fun f hf ↦ ?_
[GOAL]
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
inst✝¹ : Projective R P
inst✝ : Projective R Q
f : (P × Q →₀ R) →ₗ[R] P × Q
hf : Function.Surjective ↑f
⊢ ∃ h, comp f h = LinearMap.id
[PROOFSTEP]
rcases projective_lifting_property f (.inl _ _ _) hf with ⟨g₁, hg₁⟩
[GOAL]
case intro
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
inst✝¹ : Projective R P
inst✝ : Projective R Q
f : (P × Q →₀ R) →ₗ[R] P × Q
hf : Function.Surjective ↑f
g₁ : P →ₗ[R] P × Q →₀ R
hg₁ : comp f g₁ = inl R P Q
⊢ ∃ h, comp f h = LinearMap.id
[PROOFSTEP]
rcases projective_lifting_property f (.inr _ _ _) hf with ⟨g₂, hg₂⟩
[GOAL]
case intro.intro
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
inst✝¹ : Projective R P
inst✝ : Projective R Q
f : (P × Q →₀ R) →ₗ[R] P × Q
hf : Function.Surjective ↑f
g₁ : P →ₗ[R] P × Q →₀ R
hg₁ : comp f g₁ = inl R P Q
g₂ : Q →ₗ[R] P × Q →₀ R
hg₂ : comp f g₂ = inr R P Q
⊢ ∃ h, comp f h = LinearMap.id
[PROOFSTEP]
refine ⟨coprod g₁ g₂, ?_⟩
[GOAL]
case intro.intro
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
inst✝¹ : Projective R P
inst✝ : Projective R Q
f : (P × Q →₀ R) →ₗ[R] P × Q
hf : Function.Surjective ↑f
g₁ : P →ₗ[R] P × Q →₀ R
hg₁ : comp f g₁ = inl R P Q
g₂ : Q →ₗ[R] P × Q →₀ R
hg₂ : comp f g₂ = inr R P Q
⊢ comp f (coprod g₁ g₂) = LinearMap.id
[PROOFSTEP]
rw [LinearMap.comp_coprod, hg₁, hg₂, LinearMap.coprod_inl_inr]
[GOAL]
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
ι : Type u_6
A : ι → Type u_7
inst✝¹ : (i : ι) → AddCommMonoid (A i)
inst✝ : (i : ι) → Module R (A i)
h : ∀ (i : ι), Projective R (A i)
f : ((Π₀ (i : ι), A i) →₀ R) →ₗ[R] Π₀ (i : ι), A i
hf : Function.Surjective ↑f
⊢ ∃ h, comp f h = LinearMap.id
[PROOFSTEP]
classical
choose g hg using fun i ↦ projective_lifting_property f (DFinsupp.lsingle i) hf
replace hg : ∀ i x, f (g i x) = DFinsupp.single i x := fun i ↦ FunLike.congr_fun (hg i)
refine ⟨DFinsupp.coprodMap g, ?_⟩
ext i x j
simp only [comp_apply, id_apply, DFinsupp.lsingle_apply, DFinsupp.coprodMap_apply_single, hg]
[GOAL]
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
ι : Type u_6
A : ι → Type u_7
inst✝¹ : (i : ι) → AddCommMonoid (A i)
inst✝ : (i : ι) → Module R (A i)
h : ∀ (i : ι), Projective R (A i)
f : ((Π₀ (i : ι), A i) →₀ R) →ₗ[R] Π₀ (i : ι), A i
hf : Function.Surjective ↑f
⊢ ∃ h, comp f h = LinearMap.id
[PROOFSTEP]
choose g hg using fun i ↦ projective_lifting_property f (DFinsupp.lsingle i) hf
[GOAL]
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
ι : Type u_6
A : ι → Type u_7
inst✝¹ : (i : ι) → AddCommMonoid (A i)
inst✝ : (i : ι) → Module R (A i)
h : ∀ (i : ι), Projective R (A i)
f : ((Π₀ (i : ι), A i) →₀ R) →ₗ[R] Π₀ (i : ι), A i
hf : Function.Surjective ↑f
g : (i : ι) → A i →ₗ[R] (Π₀ (i : ι), A i) →₀ R
hg : ∀ (i : ι), comp f (g i) = DFinsupp.lsingle i
⊢ ∃ h, comp f h = LinearMap.id
[PROOFSTEP]
replace hg : ∀ i x, f (g i x) = DFinsupp.single i x := fun i ↦ FunLike.congr_fun (hg i)
[GOAL]
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
ι : Type u_6
A : ι → Type u_7
inst✝¹ : (i : ι) → AddCommMonoid (A i)
inst✝ : (i : ι) → Module R (A i)
h : ∀ (i : ι), Projective R (A i)
f : ((Π₀ (i : ι), A i) →₀ R) →ₗ[R] Π₀ (i : ι), A i
hf : Function.Surjective ↑f
g : (i : ι) → A i →ₗ[R] (Π₀ (i : ι), A i) →₀ R
hg : ∀ (i : ι) (x : A i), ↑f (↑(g i) x) = DFinsupp.single i x
⊢ ∃ h, comp f h = LinearMap.id
[PROOFSTEP]
refine ⟨DFinsupp.coprodMap g, ?_⟩
[GOAL]
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
ι : Type u_6
A : ι → Type u_7
inst✝¹ : (i : ι) → AddCommMonoid (A i)
inst✝ : (i : ι) → Module R (A i)
h : ∀ (i : ι), Projective R (A i)
f : ((Π₀ (i : ι), A i) →₀ R) →ₗ[R] Π₀ (i : ι), A i
hf : Function.Surjective ↑f
g : (i : ι) → A i →ₗ[R] (Π₀ (i : ι), A i) →₀ R
hg : ∀ (i : ι) (x : A i), ↑f (↑(g i) x) = DFinsupp.single i x
⊢ comp f (DFinsupp.coprodMap g) = LinearMap.id
[PROOFSTEP]
ext i x j
[GOAL]
case h.h.h
R : Type u_1
inst✝¹⁰ : Semiring R
P : Type u_2
inst✝⁹ : AddCommMonoid P
inst✝⁸ : Module R P
M : Type u_3
inst✝⁷ : AddCommMonoid M
inst✝⁶ : Module R M
N : Type u_4
inst✝⁵ : AddCommMonoid N
inst✝⁴ : Module R N
Q : Type u_5
inst✝³ : AddCommMonoid Q
inst✝² : Module R Q
ι : Type u_6
A : ι → Type u_7
inst✝¹ : (i : ι) → AddCommMonoid (A i)
inst✝ : (i : ι) → Module R (A i)
h : ∀ (i : ι), Projective R (A i)
f : ((Π₀ (i : ι), A i) →₀ R) →ₗ[R] Π₀ (i : ι), A i
hf : Function.Surjective ↑f
g : (i : ι) → A i →ₗ[R] (Π₀ (i : ι), A i) →₀ R
hg : ∀ (i : ι) (x : A i), ↑f (↑(g i) x) = DFinsupp.single i x
i : ι
x : A i
j : ι
⊢ ↑(↑(comp (comp f (DFinsupp.coprodMap g)) (DFinsupp.lsingle i)) x) j = ↑(↑(comp LinearMap.id (DFinsupp.lsingle i)) x) j
[PROOFSTEP]
simp only [comp_apply, id_apply, DFinsupp.lsingle_apply, DFinsupp.coprodMap_apply_single, hg]
[GOAL]
R : Type u_1
inst✝² : Ring R
P : Type u_2
inst✝¹ : AddCommGroup P
inst✝ : Module R P
ι : Type u_3
b : Basis ι R P
⊢ Projective R P
[PROOFSTEP]
use b.constr ℕ fun i => Finsupp.single (b i) (1 : R)
[GOAL]
case h
R : Type u_1
inst✝² : Ring R
P : Type u_2
inst✝¹ : AddCommGroup P
inst✝ : Module R P
ι : Type u_3
b : Basis ι R P
⊢ Function.LeftInverse ↑(Finsupp.total P P R id) ↑(↑(Basis.constr b ℕ) fun i => Finsupp.single (↑b i) 1)
[PROOFSTEP]
intro m
[GOAL]
case h
R : Type u_1
inst✝² : Ring R
P : Type u_2
inst✝¹ : AddCommGroup P
inst✝ : Module R P
ι : Type u_3
b : Basis ι R P
m : P
⊢ ↑(Finsupp.total P P R id) (↑(↑(Basis.constr b ℕ) fun i => Finsupp.single (↑b i) 1) m) = m
[PROOFSTEP]
simp only [b.constr_apply, mul_one, id.def, Finsupp.smul_single', Finsupp.total_single, LinearMap.map_finsupp_sum]
[GOAL]
case h
R : Type u_1
inst✝² : Ring R
P : Type u_2
inst✝¹ : AddCommGroup P
inst✝ : Module R P
ι : Type u_3
b : Basis ι R P
m : P
⊢ (sum (↑b.repr m) fun i d => d • ↑b i) = m
[PROOFSTEP]
exact b.total_repr m
|
! =====================================================================
! function FACTORIAL
!
! factorial is an function that recursively computes the value of the
! factorial of integer n.
! ---------------------------------------------------------------------
INTEGER RECURSIVE FUNCTION factorial ( n ) RESULT ( nFactorial )
IMPLICIT NONE
INTEGER, INTENT ( IN ) :: n
nFactorial = 0
IF ( n == 0 ) THEN
nFactorial = 1
ELSE IF ( n >= 1 .AND. n <= 12 ) THEN
nFactorial = n * factorial ( n - 1 )
ELSE
nFactorial = -1
WRITE ( UNIT = 6 , FMT = * ) 'math : factorial :: &
& ERROR - n must be an integer greater than or equal to 0, &
& but less than or equal to 12 because KIND ( n ) may be a &
& 32-bit integer.'
STOP
END IF
RETURN
END FUNCTION
! =====================================================================
|
(* From sflib Require Import sflib. *)
(* From Paco Require Import paco. *)
(* From PromisingLib Require Import Basic. *)
(* Require Import Event. *)
(* From PromisingLib Require Import Language. *)
(* Require Import View. *)
(* Require Import Cell. *)
(* Require Import Memory. *)
(* Require Import TView. *)
(* Require Import Thread. *)
(* Require Import Configuration. *)
(* Set Implicit Arguments. *)
(* (* NOTE: We currently consider only finite behaviors of program: we *)
(* * ignore non-terminating executions. This simplification affects two *)
(* * aspects of the development: *)
(* * *)
(* * - Liveness. In our definition, the liveness matters only for *)
(* * non-terminating execution. *)
(* * *)
(* * - Simulation. We do not introduce simulation index for inftau *)
(* * behaviors (i.e. infinite loop without system call interactions). *)
(* * *)
(* * We will consider infinite behaviors in the future work. *)
(* *) *)
(* (* NOTE: We serialize all the events within a behavior, but it may not *)
(* * be the case. The *NIX kernels are re-entrant: system calls may *)
(* * race. *)
(* *) *)
(* Inductive pf_behaviors: forall (conf:Configuration.t) (b:list Event.t), Prop := *)
(* | behaviors_nil *)
(* c *)
(* (TERMINAL: Configuration.is_terminal c): *)
(* behaviors c nil *)
(* | behaviors_event *)
(* e tid c1 c2 beh *)
(* (STEP: Configuration.step (Some e) tid c1 c2) *)
(* (NEXT: behaviors c2 beh): *)
(* behaviors c1 (e::beh) *)
(* | behaviors_tau *)
(* c1 c2 beh *)
(* (STEP: Configuration.tau_step c1 c2) *)
(* (NEXT: behaviors c2 beh): *)
(* behaviors c1 beh *)
(* . *)
|
{-# OPTIONS_GHC -Wall #-}
{-|
Module : AutoBench.Internal.Analysis
Description : Coordinates the analysis of runtime measurements.
Copyright : (c) 2018 Martin Handley
License : BSD-style
Maintainer : [email protected]
Stability : Experimental
Portability : GHC
This module is responsible for coordinating the statistical analysis of
runtime measurements. Raw measurements are subject to regression analysis
(ridge regression) and linear models are fitted sets of (input size, runtime)
coordinates. Regression models are then ranked according to fitting statistics
generated by e.g., cross-validation (see 'Stats'). The equations of best
fitting models are used to approximate the time complexity of test programs.
* 'quickAnalysis' is for analysing the results of QuickBenching;
* 'analyse' and 'analyseWith' are for analysing the results of AutoBenching.
Note that 'analyse' and 'analyseWith' will be moved to a user exposed module
when 'TestReport's can be saved to/loaded from file.
-}
{-
----------------------------------------------------------------------------
<TO-DO>:
----------------------------------------------------------------------------
- Address the cleansing of input sizes to remove 0;
-
-}
module AutoBench.Internal.Analysis
(
-- * QuickBench.
quickAnalyseWith -- Analyse the given @[QuickReport]@, i.e., test results using the given 'AnalOpts'.
-- * AutoBench.
, analyse -- Analyse the given 'TestReport', i.e., test results using the default 'AnalOpts'.
, analyseWith -- Analyse the given 'TestReport', i.e., test results using the given 'AnalOpts'
) where
import Control.Arrow ((&&&))
import Criterion.Types (OutlierEffect(..))
import Data.Default (def)
import Data.List (genericLength, sort, sortBy)
import Data.Maybe (catMaybes)
import qualified Data.Vector.Storable as V
import Numeric.LinearAlgebra (Vector, norm_1, norm_2)
import System.IO.Unsafe (unsafePerformIO)
import System.Random (randomRIO)
import AutoBench.Internal.AbstractSyntax (Id)
import AutoBench.Internal.Configuration (maximumModelPredictors)
import AutoBench.Internal.UserIO (outputAnalysisReport, outputQuickAnalysis)
import AutoBench.Internal.Regression (generateLinearCandidate, fitRidgeRegress)
import AutoBench.Internal.UserInputChecks (validateAnalOpts, validateTestReport)
import AutoBench.Internal.Utils (notNull, uniqPairs)
import AutoBench.Internal.Types
( AnalOpts(..)
, AnalysisReport(..)
, BenchReport(..)
, Coord
, Coord3
, CVStats(..)
, Improvement
, InputError(..)
, LinearCandidate(..)
, LinearFit(..)
, SimpleReport(..)
, SimpleResults(..)
, Stats(..)
, TestReport(..)
, QuickAnalysis(..)
, QuickReport(..)
, QuickResults(..)
, numPredictors
, simpleReportsToCoords
)
-- * QuickBench Top-level
-- | Analyse the given @[QuickReport]@, i.e., test results using the
-- given 'AnalOpts'. Analysis results are output to the console and file
-- depending on the 'AnalOpts'. The boolean parameter is whether the
-- test programs have the same results according to QuickCheck testing.
-- Note: this function is not exposed to users.
quickAnalyseWith :: AnalOpts -> Bool -> [QuickReport] -> IO ()
quickAnalyseWith _ _ [] = print $ QuickBenchErr "No results to analyse."
quickAnalyseWith aOpts eql qrs = outputQuickAnalysis aOpts eql $
quickAnalysis aOpts qrs
-- * AutoBench Top-level
-- | Analyse the given 'TestReport', i.e., test results using the
-- default 'AnalOpts'.
analyse :: TestReport -> IO ()
analyse = analyseWith def
-- | Analyse the given 'TestReport', i.e., test results using the
-- given 'AnalOpts'. Analysis results are output to the console and file
-- depending on the 'AnalOpts'.
analyseWith :: AnalOpts -> TestReport -> IO ()
analyseWith aOpts tr
| notNull (aOptsErrs ++ trErrs) = do
putStrLn "Cannot analyse results due to one or more errors:"
mapM_ print (aOptsErrs ++ trErrs)
-- Just output the results of statistical analysis.
| otherwise = outputAnalysisReport aOpts tr $ calculateAnalysisReport aOpts tr
where
-- Validate the 'AnalOpts'.
aOptsErrs = validateAnalOpts aOpts
-- Validate the 'TestReport'
trErrs = validateTestReport tr
-- * QuickBench Analysis
-- | Perform statistical analysis on the benchmarking results (i.e., runtime
-- measurements of test programs) in the given @[QuickReport]@ and produce a
-- 'QuickAnalysis' report to summarise the system's analysis phase.
quickAnalysis :: AnalOpts -> [QuickReport] -> QuickAnalysis
quickAnalysis aOpts qrs =
QuickAnalysis
{
_qAnlys = quickResults aOpts qrs -- A set of quick results ('QuickResults') for each test program.
, _qImps = catMaybes $ fmap (uncurry $ calculateImprovements -- A set of improvements.
(_improv aOpts)) (uniqPairs $ zip names coords)
}
where
-- Names of test programs
names = fmap _qName qrs
-- (Input size(s), runtime) coordinates.
coords = fmap _qRuntimes qrs
-- | Perform statistical analysis on the benchmarking results (i.e., runtime
-- measurements of test programs) in the given @[QuickReport]@ and produce an
-- analysis report ('QuickResults') /for each test program/.
quickResults :: AnalOpts -> [QuickReport] -> [QuickResults]
quickResults aOpts = fmap quickResult
where
quickResult :: QuickReport -> QuickResults
quickResult qr =
QuickResults
{
_qrIdt = _qName qr
-- Raw measurements.
, _qrRaws = coords
-- Fit all models in the 'AnalOpts' to the raw measurements.
, _qrFits = fitCoords aOpts coords
}
where coords = _qRuntimes qr
-- * AutoBench Analysis
-- | Perform statistical analysis on the benchmarking results (i.e., runtime
-- measurements of test programs) in the given 'TestReport' and produce an
-- 'AnalysisReport' to summarise the system's overall analysis phase.
calculateAnalysisReport :: AnalOpts -> TestReport -> AnalysisReport
calculateAnalysisReport aOpts tr =
AnalysisReport
{
_anlys = anlys -- A set of simple results ('SimpleResults') for each test program.
, _imps = catMaybes $ fmap (uncurry $ calculateImprovements -- A set of improvements.
-- Compare every set of measurements against every other set.
(_improv aOpts)) (uniqPairs $ zip srNames srCoords)
, _blAn = blAn -- Analysis of baseline measurements, if applicable.
}
where
-- 'SimpleResults' for test programs and baseline measurements, if applicable.
(anlys, blAn) = calculateSimpleResults aOpts tr
-- For generating improvements: compare all results from test programs
-- against eachother using 'uniqPairs'.
-- SimpleReports.
srs = _reports (_br tr)
-- Names of test programs from 'SimpleReport's.
srNames = fmap (_name . head) srs
-- (Input size(s), runtime) coordinates.
srCoords = zipWith simpleReportsToCoords srNames srs
-- | Perform statistical analysis on the benchmarking results (i.e., runtime
-- measurements of test programs) in the given 'TestReport' and produce an
-- analysis report ('SimpleResults') /for each test program/.
-- If baseline measurements have been taken then also produce a 'SimpleReport'
-- for these results.
calculateSimpleResults
:: AnalOpts
-> TestReport
-> ([SimpleResults], Maybe SimpleResults) -- Maybe is for baseline measurements.
calculateSimpleResults aOpts tr = (progResults, blResults)
where
-- Analysis for test programs.
progResults = zipWith calculateSimpleResult (_tProgs tr) (_reports $ _br tr)
-- Analysis for baseline measurements.
blResults = case _baselines $ _br tr of
[] -> Nothing
bls -> Just $ calculateSimpleResult "Baseline measurements" bls -- <TO-DO>: This shouldn't be a string.
-- For a set of 'SimpleReport's (i.e., test cases) relating to a
-- given test program, perform statistical analysis and generate
-- 'SimpleResults'.
calculateSimpleResult
:: Id -- Name of test program.
-> [SimpleReport] -- Benchmarking measurements for each test case.
-> SimpleResults
calculateSimpleResult idt srs =
SimpleResults
{
_srIdt = idt
-- Raw measurements.
, _srRaws = coords
-- Cumulative statistics for /all/ test cases, taken from Criterion's 'Report'.
, _srStdDev = stdDev
, _srAvgOutVarEff = avgOutVarEff
, _srAvgPutVarFrac = avgOutVarFrac
-- Fit all models in the 'AnalOpts' to the raw measurements.
, _srFits = fitCoords aOpts coords
}
where
coords = simpleReportsToCoords idt srs
(stdDev, avgOutVarFrac, avgOutVarEff) = simpleReportSummary srs
-- Provide an summary of the simple statistics taken from
-- Criterion's 'Report's relating to the /same/ test program:
--
-- * Standard deviation of all test cases;
-- * Average effect of outliers on variance (percentage);
-- * Average effect of outliers on variance ('OutlierEffect').
simpleReportSummary
:: [SimpleReport]
-> (Double, Double, OutlierEffect)
simpleReportSummary [] = (0, 0, Unaffected) -- <TO-DO> What is this error handling?
simpleReportSummary srs = (stdDev srs, avgOutVarFrac, avgOutVarEff)
where
-- Standard deviation for all test cases: sqrt (SUM variance_i/samples_i).
stdDev = sqrt . sum . fmap (uncurry (/) . ((** 2) .
_stdDev &&& fromIntegral . _samples))
-- Average effect of outliers on variance.
avgOutVarFrac = sum (fmap _outVarFrac srs) / genericLength srs
avgOutVarEff
| avgOutVarFrac < 0.01 = Unaffected -- Same as Criterion.
| avgOutVarFrac < 0.1 = Slight
| avgOutVarFrac < 0.5 = Moderate
| otherwise = Severe
-- * Linear fitting
-- | Fit a 'LinearCandidate' model to a data set, generating a 'LinearFit'
-- that can be used to asses the model's goodness of fit.
candidateFit
:: ([Coord] -> LinearCandidate -> Vector Double) -- Fitting function.
-> Double -- Cross-validation train/validate data split.
-> Int -- Cross-validation iterations.
-> [Coord] -- Data set.
-> LinearCandidate -- Model to fit.
-> Maybe LinearFit
candidateFit ff split iters coords c
| length cleansedCoords < maximumModelPredictors + 1 = Nothing -- Need a minimum of (maximumModelPredictors + 1) coordinates.
| V.null coeffs = Nothing -- If coefficients are null, can't use model.
| otherwise = Just
LinearFit
{
_lft = _lct c
, _cfs = coeffs
, _ex = _fex c coeffs
, _yhat = _fyhat c coeffs
, _sts = sts
}
where
-- Model coefficients when fit to /entire/ data set.
-- This is for e.g., R^2, Adj. R^2, BIC, AIC CP.
coeffs = ff cleansedCoords c -- <TO-DO>: can 'ff' fail?
-- Statistics from cross-validation, e.g., PRESS, PMAE, PMSE.
cvSts = cvCandidateFit ff split iters cleansedCoords c
-- Combine statistics from each cross-validation iteration and also compute
-- other goodness of fit measures.
sts = stats c cleansedCoords coeffs cvSts
-- Cleanse in case transformation produces infinite values. -- <TO-DO> *** This needs addressing. ***
-- /This happens when for size 0 only, LogBase _ 0 = -Infinity/.
-- Remove the @(0, _)@ coordinate.
-- ** Only cleanse runtimes predicted by models. **
cleansedCoords = cleanse coords
cleanse :: [Coord] -> [Coord]
cleanse = filter (\(x, _) -> x /= 0)
-- ** Linear fitting cross-validation
-- | Fit a 'LinearCandidate' to a data set using Monte Carlo cross-validation.
-- Return the fitting statistics ('CVStats') from each iteration of
-- cross-validation.
cvCandidateFit
:: ([Coord] -> LinearCandidate -> Vector Double) -- Fitting function (ridge regression in practice).
-> Double -- Train/evaluate data split.
-> Int -- Number of iterations.
-> [Coord] -- Full data set.
-> LinearCandidate -- Model to fit.
-> [CVStats]
cvCandidateFit ff split iters coords c =
fmap (uncurry trainAndValidate) splits
where
splits = fmap (splitRand split) (replicate iters coords)
-- Train the model on the training data and evaluate it on the validation
-- data: calculating the cross-validation statistics ('CVStats').
trainAndValidate :: [Coord] -> [Coord] -> CVStats
trainAndValidate train valid = cvStats c valid (ff train c)
-- ** Linear fitting statistics
-- | Fitting statistics generated from a /single/ iteration of cross-validation.
-- See 'stats' for cumulative fitting statistics.
cvStats
:: LinearCandidate -- The model.
-> [Coord] -- The /evaluation/ set of this iteration of cross-validation.
-> Vector Double -- The coefficients of the model calculated using the /training/ set.
-> CVStats -- The model's fitting statistics for this iteration of cross-validation.
cvStats c coords coeffs =
CVStats
{
_cv_mse = mse
, _cv_mae = mae
, _cv_ss_tot = ss_tot
, _cv_ss_res = ss_res
}
where
---------------------------------------------------------------------------
(xs, ys) = unzip coords
_X = V.fromList xs -- X. ** don't transform using fxs **
_Y = V.fromList ys -- Y.
n = length coords
n' = fromIntegral n -- n data points.
---------------------------------------------------------------------------
yhat = _fyhat c coeffs _X -- Model y-coords.
ybar = V.sum _Y / n' -- Average of data y-coords.
ybars = V.replicate n ybar
---------------------------------------------------------------------------
mse = ss_res / n' -- Mean squared error ss_res / n
mae = (norm_1 $ V.zipWith (-) _Y yhat) / n' -- Mean absolute error: (SUM |y_i - f(y_i)|) / n
ss_tot = (norm_2 $ V.zipWith (-) _Y ybars) ** 2.0 -- Total sum of squares: SUM (y_i - avg(y))^2
ss_res = (norm_2 $ V.zipWith (-) _Y yhat) ** 2.0 -- Residual sum of squares: SUM (y_i - f(y_i))^2
-- | Overall fitting statics for a model and a given data set. Some statistics
-- are cumulative fitting stats, generated by cross-validation (PMSE, PMAE,
-- PRESS, SST, Pred. R^2); others are generated by using the whole data set as
-- training data (R^2, Adj. R^2, AIC, BIC, Mallow's CP).
stats
:: LinearCandidate -- The model.
-> [Coord] -- The data set
-> Vector Double -- The coefficients of the model calculated using the /entire/ set.
-> [CVStats] -- The statistics from each iteration of cross-validation.
-> Stats -- The cumulative fitting statistics.
stats c coords coeffs cvSts = _sts
where
-- Statistics calculated below.
_sts = Stats
{
_p_mse = p_mse
, _p_mae = p_mae
, _ss_tot = cv_ss_tot
, _p_ss_res = p_ss_res
, _r2 = r2
, _a_r2 = a_r2
, _p_r2 = p_r2
, _bic = bic
, _aic = aic
, _cp = cp
}
---------------------------------------------------------------------------
-- Statistics for /complete/ data set:
---------------------------------------------------------------------------
(xs, ys) = unzip coords
_X = V.fromList xs -- X. ** do not transform using fxs **
_Y = V.fromList ys -- Y.
n = length coords
n' = fromIntegral n -- n data points.
k' = fromIntegral (numPredictors $ _lct c) -- k predictors.
---------------------------------------------------------------------------
yhat = _fyhat c coeffs _X -- Model y-coords.
ybar = V.sum _Y / n' -- Average of data y-coords.
ybars = V.replicate n ybar
---------------------------------------------------------------------------
_mse = _ss_res / n' -- Mean squared error: ss_res / n
_ss_tot = (norm_2 $ V.zipWith (-) _Y ybars) ** 2.0 -- Total sum of squares: SUM (y_i - avg(y))^2
_ss_res = (norm_2 $ V.zipWith (-) _Y yhat) ** 2.0 -- Residual sum of squares: SUM (y_i - f(y_i))^2
r2 = 1.0 - (_ss_res / _ss_tot) -- Coefficient of Determination: 1 - ss_res/ss_tot
a_r2 = 1.0 - ((1.0 - r2) * (n' - 1.0) / (n' - k' - 1.0)) -- Adjusted Coefficient of Determination: 1 - ((1 - r^2)(n - 1)/(n - k - 1))
---------------------------------------------------------------------------
-- http://www.stat.wisc.edu/courses/st333-larget/aic.pdf (implementations from R).
---------------------------------------------------------------------------
aic = (n' * log (_ss_res / n')) + (2 * k') -- Akaike’s Information Criterion: n * ln(ss_res/n) + 2k
bic = (n' * log (_ss_res / n')) + (k' * log n') -- Bayesian Information Criterion: n * ln(ss_res/n) + k * ln(n)
cp = (_ss_res / _mse) - (n' - (2 * k')) -- Mallows' Cp Statistic: (ss_res/_mse) - (n - 2k)
---------------------------------------------------------------------------
-- Cross-validated statistics:
---------------------------------------------------------------------------
cv_n = genericLength cvSts
p_mse = (sum $ fmap _cv_mse cvSts) / cv_n -- 1/n * SUM mse_k for each iteration k
p_mae = (sum $ fmap _cv_mae cvSts) / cv_n -- 1/n * SUM mae_k for each iteration k
cv_ss_tot = (sum $ fmap _cv_ss_tot cvSts) / cv_n -- 1/n * SUM ss_tot_k for each iteration k
p_ss_res = (sum $ fmap _cv_ss_res cvSts) / cv_n -- 1/n * SUM ss_res_k for each iteration k
p_r2 = 1.0 - (p_ss_res / cv_ss_tot) -- 1 - p_ss_res/cv_ss_tot
-- * Helpers
-- | Split a list into two random sublists of specified sizes.
-- Warning: uses 'unsafePerformIO' for randomness.
splitRand :: Double -> [a] -> ([a], [a]) -- <TO-DO>: Does this need to be more sophisticated?
splitRand split xs = (take len shuffled, drop len shuffled)
where
len = ceiling (genericLength xs * split)
shuffled = unsafePerformIO (shuffle xs) -- <TO-DO> 'unsafePerformIO'
-- | Naive-ish way to shuffle a list.
shuffle :: [a] -> IO [a] -- <TO-DO>: Could shuffle in the top-level functions to avoid using unsafePerformIO?
shuffle x = -- <TO-DO>: Does this need to be more sophisticated?
if length x < 2
then return x
else do
i <- randomRIO (0, length x - 1)
r <- shuffle (take i x ++ drop (i + 1) x)
return (x !! i : r)
-- | Compare the runtimes of two test programs, given as a list of
-- xy-coordinates, pointwise to generate improvement results. Only compare
-- results relating to test programs of the same airty. (Note: this should
-- always be the case when used in practice).
calculateImprovements
:: ([(Double, Double)] -> Maybe (Ordering, Double)) -- '_improv' function from 'AnalOpts'.
-> (Id, Either [Coord] [Coord3]) -- Runtimes of test program 1.
-> (Id, Either [Coord] [Coord3]) -- Runtimes of test program 2.
-> Maybe Improvement
calculateImprovements improv (idt1, Left cs1) (idt2, Left cs2) -- Unary against unary.
-- If all coordinates didn't match, then can't generate improvements.
| length toCompare < length cs1 = Nothing
| otherwise = case improv toCompare of
Nothing -> Nothing
Just (ord, d) -> Just (idt1, ord, idt2, d)
where toCompare = matchCoords (sort cs1) (sort cs2)
calculateImprovements improv (idt1, Right cs1) (idt2, Right cs2) -- Binary against binary.
-- If all coordinates didn't match, then can't generate improvements.
| length toCompare < length cs1 = Nothing
| otherwise = case improv toCompare of
Nothing -> Nothing
Just (ord, d) -> Just (idt1, ord, idt2, d)
where toCompare = matchCoords3 (sort cs1) (sort cs2)
calculateImprovements _ _ _ = Nothing -- Shouldn't happen.
-- | Make sure coordinates to compare when generating improvement results have
-- the same size information. (Note: this should always be the case because of
-- how they are generated, but better to check.). For 'Coord'.
matchCoords :: [Coord] -> [Coord] -> [(Double, Double)]
matchCoords [] _ = []
matchCoords _ [] = []
matchCoords ((s1, t1) : cs1) ((s1', t2) : cs2)
| s1 == s1' = (t1, t2) : matchCoords cs1 cs2
| otherwise = matchCoords cs1 cs2
-- | Make sure coordinates to compare when generating improvement results have
-- the same size information. (Note: this should always be the case because of
-- how they are generated, but better to check.). For 'Coord3'
matchCoords3 :: [Coord3] -> [Coord3] -> [(Double, Double)]
matchCoords3 [] _ = []
matchCoords3 _ [] = []
matchCoords3 ((s1, s2, t1) : cs1) ((s1', s2', t2) : cs2)
| s1 == s1' && s2 == s2' = (t1, t2) : matchCoords3 cs1 cs2
| otherwise = matchCoords3 cs1 cs2
-- | Fit the '_linearModels' in a given 'AnalOpts' to a data set to generate
-- 'LinearFit's (i.e., models with their missing parameters/coefficients
-- approximated). Currently this only works for 'Coord's, i.e., runtime
-- measurements from /unary/ test programs. Models are fitted to data
-- sets using ridge regression.
--
-- Note 'AnalOpts' is required here because it contains other settings needed
-- for fitting, i.e., cross-validation parameters: '_cvTrain', '_cvIters'.
--
-- Also sorts and filters the resulting models using '_statsSort' and
-- '_statsFilt' from 'AnalOpts', respectively.
fitCoords :: AnalOpts -> Either [Coord] [Coord3] -> [LinearFit]
fitCoords _ Right{} = [] -- <TO-DO>: Analyse 3D coords?
fitCoords aOpts (Left coords) = take (_topModels aOpts)
$ sortBy (\lf1 lf2 -> (_statsSort aOpts) (_sts lf1) (_sts lf2)) -- SORT: '_statsSort'
$ filter (\lf -> (_statsFilt aOpts) (_sts lf)) -- FILTER: '_statsFilt'
$ catMaybes -- The fitting process may fail in some cases, exactly when? -- <TO-DO>: When does fitting fail.. When not enough coords only!
$ fmap ( ( candidateFit
fitRidgeRegress -- Use ridge regression to fit.
(_cvTrain aOpts) -- Train/evaluate data split.
(_cvIters aOpts) -- Number of cross-validation iterations.
coords -- Data set.
) . generateLinearCandidate -- 'LinearType' -> 'LinearCandidate'.
) (_linearModels aOpts) -- Fit all models in 'AnalOpts'. |
The “Santosham Pongattum Offer” (“Offer”) is provided by Samsung India Electronics Private Limited.
The Offer is valid in State of Tamil Nadu from 1st January to 31st January 2018 (both days inclusive) (“Offer Period”).
Free HTS HT-J5100 worth Rs 17,990 with purchase of 55M6300, 49MU6470, 65MU6470, 49MU7000, 55MU7000, 55LS003 and 65LS003.
Free HW-K20 Speaker worth Rs. 5000/- with purchase of 49M5100, 49K5300, 49M6300, 49M5570, 55M5570, 50MU6100 and 55MU6470.
Free Samsung Scoop wireless BT speaker worth Rs 2799 with purchase of 43M5100, 43K5300 and 43M5570.
The 2 months DTH offer is applicable on all TV models of M5570 and MU6470 Series with Airtel Digital TV, Dish TV and SunDirect.
Free DTH offer is provided by Airtel Digital TV, Dish TV, Tata Sky and SunDirect at their sole discretion and is subject to the terms and conditions of the DTH provider. Samsung disclaims any and all claims in respect of the same.
Installation @ Rs. 499/- is applicable on purchase of all Samsung Split Air Conditioners.
Cash Back will be credited after 90 days of transaction. |
(*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*)
theory Strengthen_Demo
imports "Strengthen"
begin
text \<open>Here's a complicated predicate transformer. You don't need
to understand this, it just makes it easy to set up some complicated
example goals below.\<close>
definition
"predt f g h P x y = (\<exists>x'. (\<exists>y' \<in> f y. x' \<in> g y' ` h y) \<and> P x x')"
text \<open>Strengthen performs the same kinds of steps as
intro/elim rules, but it can perform them within complex
conclusions. Here's an example where we replace Q with P
(strengthening the goal) deep within some quantifiers.\<close>
lemma predt_double_mono:
assumes PQ: "\<And>x y. P x y \<longrightarrow> Q x y"
assumes P: "predt f g h (predt f g h' P) x y"
shows "predt f g h (predt f g h' Q) x y"
using P
apply (simp add: predt_def)
apply (strengthen PQ)
apply assumption
done
text \<open>Here's a more conventional monotonicity proof.
Once the clarsimp has finished, the goal becomes a bit
difficult to prove. Let's use some fancy strengthen
features to address this. The rest of this demo will
explain what the attribute and fancy features are doing,
and thus how this proof works.\<close>
lemma predt_double_mono2:
assumes PQ: "\<And>x y. P x y \<longrightarrow> Q x y"
assumes P: "predt f g h (predt f g' h P) x y"
shows "predt f g h (predt f g' h Q) x y"
using P
apply (clarsimp simp: predt_def)
apply (strengthen bexI[mk_strg I _ A])
apply (strengthen image_eqI[mk_strg I _ A])
apply simp
apply (strengthen bexI[mk_strg I _ O], assumption)
apply (strengthen image_eqI[mk_strg I _ E])
apply simp
apply (simp add: PQ)
done
text \<open>The @{attribute mk_strg} controls the way that
strengthen applies a rule. By default, strengthen will
use a rule as an introduction rule, trying to replace
the rule's conclusion with its premises.
Once the @{attribute mk_strg} attribute has applied, the
rule is formatted showing how strengthen will try to
transform components of a goal. The syntax of the
second theorem is reversed, showing that strengthen will
attempt to replace instances of the subset predicate
with instances of the proper subset predicate.
\<close>
thm psubset_imp_subset psubset_imp_subset[mk_strg]
text \<open>Rules can have any number of premises, or none,
and still be used as strengthen rules.\<close>
thm subset_UNIV subset_UNIV[mk_strg]
equalityI equalityI[mk_strg]
text \<open>Rules which would introduce schematics are
adjusted by @{attribute mk_strg} to introduce quantifiers
instead. The argument I to mk_strg prevents this step.
\<close>
thm subsetD subsetD[mk_strg I] subsetD[mk_strg]
text \<open>The first argument to mk_strg controls the way
the rule will be applied.
I: use rule in introduction style, matching its conclusion.
D: use rule in destruction (forward) style, matching its first premise.
I': like I, replace new schematics with existential quantifiers.
D': like D, replace new schematics with universal quantifiers.
The default is I'.
\<close>
thm subsetD subsetD[mk_strg I] subsetD[mk_strg I']
subsetD[mk_strg D] subsetD[mk_strg D']
text \<open>Note that I and D rules will be applicable at different
sites.\<close>
lemma
assumes PQ: "P \<Longrightarrow> Q"
shows "{x. Suc 0 < x \<and> P} \<subseteq> {x. Suc 0 < x \<and> Q}"
(* adjust Q into P on rhs *)
apply (strengthen PQ[mk_strg I])
(* adjust P into Q on lhs *)
apply (strengthen PQ[mk_strg D])
(* oops, overdid it *)
oops
text \<open>Subsequent arguments to mk_strg capture premises for
special treatment. The 'A' argument (synonym 'E') specifies that
a premise should be solved by assumption. Our fancy proof above
used a strengthen rule bexI[mk_strg I _ A], which tells strengthen
to do approximately the same thing as
\<open>apply (rule bexI) prefer 2 apply assumption\<close>
This is a useful way to apply a rule, picking the premise which
will cause unknowns to be instantiated correctly.
\<close>
thm eq_mem_trans eq_mem_trans[mk_strg I _ _] eq_mem_trans[mk_strg I A _]
eq_mem_trans[mk_strg I _ A] eq_mem_trans[mk_strg I A A]
text \<open>The 'O' argument ("obligation") picks out premises of
a rule for immediate attention as new subgoals.
The step
\<open>apply (strengthen bexI[mk_strg I _ O], assumption)\<close>
in our proof above had the same effect as strengthening with
@{thm bexI[mk_strg I _ A]}.
This option suits special cases where a particular premise is best
handled by a specialised method.
\<close>
thm eq_mem_trans eq_mem_trans[mk_strg I _ _] eq_mem_trans[mk_strg I O _]
eq_mem_trans[mk_strg I _ O] eq_mem_trans[mk_strg I O O]
end
|
subroutine token(x,y,mrk,fz,n,h,th)
call tmf(x,y,xf,yf)
call move(xf,yf,0)
call marker(mrk)
call number(xf,yf,h,fz,n,th)
return
end
|
[STATEMENT]
lemma multisets_UNIV [simp]: "multisets UNIV = UNIV"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. multisets UNIV = UNIV
[PROOF STEP]
by (metis image_mset_lists lists_UNIV surj_mset) |
------------------------------------------------------------------------------
-- Conversion rules for the Collatz function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.Collatz.ConversionRulesATP where
open import FOT.FOTC.Program.Collatz.CollatzConditionals
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Program.Collatz.Data.Nat
------------------------------------------------------------------------------
-- Conversion rules for the Collatz function.
postulate
collatz-0 : collatz 0' ≡ 1'
collatz-1 : collatz 1' ≡ 1'
collatz-even : ∀ {n} → Even (succ₁ (succ₁ n)) →
collatz (succ₁ (succ₁ n)) ≡
collatz (div (succ₁ (succ₁ n)) 2')
collatz-noteven : ∀ {n} → NotEven (succ₁ (succ₁ n)) →
collatz (succ₁ (succ₁ n)) ≡
collatz (3' * (succ₁ (succ₁ n)) + 1')
{-# ATP prove collatz-0 #-}
{-# ATP prove collatz-1 #-}
{-# ATP prove collatz-even #-}
{-# ATP prove collatz-noteven #-}
|
// CONSTANTIN MIHAI - 336CA
// TEMA 2 ASC
#include <cblas.h>
#include "utils.h"
double* copy(int N, double *A) {
int i, j;
double *B = malloc(N * N * sizeof(double));
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
B[i * N + j] = A[i * N + j];
}
}
return B;
}
double* add_matrix(int N, double *A, double *B) {
int i, j;
double *C = calloc(N * N, sizeof(double));
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
C[i * N + j] = A[i * N + j] + B[i * N + j];
}
}
return C;
}
double* my_solver(int N, double *A, double *B) {
/*
A - matrice superior triunghiulara
B - matrice normala
Vrem C = B * A^t + A^2 * B
*/
/*
CblasRowMajor - matrice stocata pe o singura linie
CblasRight - facem B * A^t
CblasUpper - matrice superior triunghiulara
CblasTrans - folosim A^t
CblasNoTrans - folosim A, nu A^t
CblasNonUnit - A nu e matrice unitara
*/
// B2 <- B2 * A^t
double *B2 = copy(N, B);
cblas_dtrmm(CblasRowMajor, CblasRight, CblasUpper, CblasTrans, CblasNonUnit, N, N, 1.0, A, N, B2, N);
// A2 <- A2 * A
double *A2 = copy(N, A);
cblas_dtrmm(CblasRowMajor, CblasRight, CblasUpper, CblasNoTrans, CblasNonUnit, N, N, 1.0, A, N, A2, N);
// B <- A2 * B
cblas_dtrmm(CblasRowMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, N, N, 1.0, A2, N, B, N);
// result <- B2 + B
double *result = add_matrix(N, B2, B);
return result;
}
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Haitao Zhang
The propositional connectives. See also init.datatypes and init.logic.
-/
open eq.ops
variables {a b c d : Prop}
/- implies -/
definition imp (a b : Prop) : Prop := a → b
theorem imp.id (H : a) : a := H
theorem imp.intro (H : a) (H₂ : b) : a := H
theorem imp.mp (H : a) (H₂ : a → b) : b :=
H₂ H
theorem imp.syl (H : a → b) (H₂ : c → a) (Hc : c) : b :=
H (H₂ Hc)
theorem imp.left (H : a → b) (H₂ : b → c) (Ha : a) : c :=
H₂ (H Ha)
theorem imp_true (a : Prop) : (a → true) ↔ true :=
iff_true_intro (imp.intro trivial)
theorem true_imp (a : Prop) : (true → a) ↔ a :=
iff.intro (assume H, H trivial) imp.intro
theorem imp_false (a : Prop) : (a → false) ↔ ¬ a := iff.rfl
theorem false_imp (a : Prop) : (false → a) ↔ true :=
iff_true_intro false.elim
/- not -/
theorem not.elim {A : Type} (H1 : ¬a) (H2 : a) : A := absurd H2 H1
theorem not.mto {a b : Prop} : (a → b) → ¬b → ¬a := imp.left
theorem not_imp_not_of_imp {a b : Prop} : (a → b) → ¬b → ¬a := not.mto
theorem not_not_of_not_implies : ¬(a → b) → ¬¬a :=
not.mto not.elim
theorem not_of_not_implies : ¬(a → b) → ¬b :=
not.mto imp.intro
theorem not_not_em : ¬¬(a ∨ ¬a) :=
assume not_em : ¬(a ∨ ¬a),
not_em (or.inr (not.mto or.inl not_em))
theorem not_iff_not (H : a ↔ b) : ¬a ↔ ¬b :=
iff.intro (not.mto (iff.mpr H)) (not.mto (iff.mp H))
/- and -/
definition not_and_of_not_left (b : Prop) : ¬a → ¬(a ∧ b) :=
not.mto and.left
definition not_and_of_not_right (a : Prop) {b : Prop} : ¬b → ¬(a ∧ b) :=
not.mto and.right
theorem and.imp_left (H : a → b) : a ∧ c → b ∧ c :=
and.imp H imp.id
theorem and.imp_right (H : a → b) : c ∧ a → c ∧ b :=
and.imp imp.id H
theorem and_of_and_of_imp_of_imp (H₁ : a ∧ b) (H₂ : a → c) (H₃ : b → d) : c ∧ d :=
and.imp H₂ H₃ H₁
theorem and_of_and_of_imp_left (H₁ : a ∧ c) (H : a → b) : b ∧ c :=
and.imp_left H H₁
theorem and_of_and_of_imp_right (H₁ : c ∧ a) (H : a → b) : c ∧ b :=
and.imp_right H H₁
theorem and_imp_iff (a b c : Prop) : (a ∧ b → c) ↔ (a → b → c) :=
iff.intro (λH a b, H (and.intro a b)) and.rec
theorem and_imp_eq (a b c : Prop) : (a ∧ b → c) = (a → b → c) :=
propext !and_imp_iff
/- or -/
definition not_or : ¬a → ¬b → ¬(a ∨ b) := or.rec
theorem or_of_or_of_imp_of_imp (H₁ : a ∨ b) (H₂ : a → c) (H₃ : b → d) : c ∨ d :=
or.imp H₂ H₃ H₁
theorem or_of_or_of_imp_left (H₁ : a ∨ c) (H : a → b) : b ∨ c :=
or.imp_left H H₁
theorem or_of_or_of_imp_right (H₁ : c ∨ a) (H : a → b) : c ∨ b :=
or.imp_right H H₁
theorem or.elim3 (H : a ∨ b ∨ c) (Ha : a → d) (Hb : b → d) (Hc : c → d) : d :=
or.elim H Ha (assume H₂, or.elim H₂ Hb Hc)
theorem or_resolve_right (H₁ : a ∨ b) (H₂ : ¬a) : b :=
or.elim H₁ (not.elim H₂) imp.id
theorem or_resolve_left (H₁ : a ∨ b) : ¬b → a :=
or_resolve_right (or.swap H₁)
theorem or.imp_distrib : ((a ∨ b) → c) ↔ ((a → c) ∧ (b → c)) :=
iff.intro
(λH, and.intro (imp.syl H or.inl) (imp.syl H or.inr))
(and.rec or.rec)
theorem or_iff_right_of_imp {a b : Prop} (Ha : a → b) : (a ∨ b) ↔ b :=
iff.intro (or.rec Ha imp.id) or.inr
theorem or_iff_left_of_imp {a b : Prop} (Hb : b → a) : (a ∨ b) ↔ a :=
iff.intro (or.rec imp.id Hb) or.inl
theorem or_iff_or (H1 : a ↔ c) (H2 : b ↔ d) : (a ∨ b) ↔ (c ∨ d) :=
iff.intro (or.imp (iff.mp H1) (iff.mp H2)) (or.imp (iff.mpr H1) (iff.mpr H2))
/- distributivity -/
theorem and.left_distrib (a b c : Prop) : a ∧ (b ∨ c) ↔ (a ∧ b) ∨ (a ∧ c) :=
iff.intro
(and.rec (λH, or.imp (and.intro H) (and.intro H)))
(or.rec (and.imp_right or.inl) (and.imp_right or.inr))
theorem and.right_distrib (a b c : Prop) : (a ∨ b) ∧ c ↔ (a ∧ c) ∨ (b ∧ c) :=
iff.trans (iff.trans !and.comm !and.left_distrib) (or_iff_or !and.comm !and.comm)
theorem or.left_distrib (a b c : Prop) : a ∨ (b ∧ c) ↔ (a ∨ b) ∧ (a ∨ c) :=
iff.intro
(or.rec (λH, and.intro (or.inl H) (or.inl H)) (and.imp or.inr or.inr))
(and.rec (or.rec (imp.syl imp.intro or.inl) (imp.syl or.imp_right and.intro)))
theorem or.right_distrib (a b c : Prop) : (a ∧ b) ∨ c ↔ (a ∨ c) ∧ (b ∨ c) :=
iff.trans (iff.trans !or.comm !or.left_distrib) (and_congr !or.comm !or.comm)
/- iff -/
definition iff.def : (a ↔ b) = ((a → b) ∧ (b → a)) := rfl
theorem forall_imp_forall {A : Type} {P Q : A → Prop} (H : ∀a, (P a → Q a)) (p : ∀a, P a) (a : A)
: Q a :=
(H a) (p a)
theorem forall_iff_forall {A : Type} {P Q : A → Prop} (H : ∀a, (P a ↔ Q a))
: (∀a, P a) ↔ (∀a, Q a) :=
iff.intro (λp a, iff.elim_left (H a) (p a)) (λq a, iff.elim_right (H a) (q a))
theorem imp_iff {P : Prop} (Q : Prop) (p : P) : (P → Q) ↔ Q :=
iff.intro (λf, f p) imp.intro
|
(* 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>\<open>\<open>pp.~18-30\<close> in "schutz1997"\<close>, 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>\<open>\<open> p.~27\<close> in "schutz1997"\<close>.\<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 |
{-# OPTIONS --safe #-}
module Cubical.HITs.SetCoequalizer where
open import Cubical.HITs.SetCoequalizer.Base public
open import Cubical.HITs.SetCoequalizer.Properties public
|
{-
-- an ≃ equivalence of types can be lifted to a ≃S equivalence
-- (over their ≡-Setoids)
-- NOT NEEDED
lift≃ : ∀ {ℓ} → {A B : Set ℓ} → A ≃ B → (≡-Setoid A) ≃S (≡-Setoid B)
lift≃ {_} {A} {B} (f , mkqinv g α β) = equiv AS BS α' β'
where
module AA = Setoid (≡-Setoid A)
module BB = Setoid (≡-Setoid B)
AS : ≡-Setoid A ⟶ ≡-Setoid B
AS = →to⟶ f
BS : ≡-Setoid B ⟶ ≡-Setoid A
BS = →to⟶ g
α' : {x y : B} → P._≡_ x y → P._≡_ (f (g x)) y
α' = λ {x} {y} p → BB.trans (α x) p
β' : {x y : A} → P._≡_ x y → P._≡_ (g (f x)) y
β' = λ {x} {y} p → AA.trans (β x) p
-}
|
function mandel_calc(a)
z = 0
for i in 1:100
z = z^2 + a
end
return z
end
function mandelbrot()
"starting mandelbrot"
for i in 0:30
y = 0.066666*i - 1
s = ""
for j in 0:78
x = 0.0315*j - 2
if abs(mandel_calc((x, y))) < 2 then
s = s + "*"
else
s = s + " "
end
end
s
end
end
mandelbrot()
|
module Gen.Plict
public export
data Plict = Expl | Impl
export
Eq Plict.Plict where
Expl == Expl = True
Impl == Impl = True
_ == _ = False
export
Show Plict.Plict where
show Expl = "<Explicit>"
show Impl = "<Implicit>"
|
[STATEMENT]
theorem p52: "\<exists>z w. \<forall>x y. F(x,y) \<longleftrightarrow> x = z \<and> y = w \<Longrightarrow>
\<exists>w. \<forall>y. (\<exists>z. \<forall>x. F(x,y) \<longleftrightarrow> x = z) \<longleftrightarrow> y = w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>z w. \<forall>x y. F (x, y) = (x = z \<and> y = w) \<Longrightarrow> \<exists>w. \<forall>y. (\<exists>z. \<forall>x. F (x, y) = (x = z)) = (y = w)
[PROOF STEP]
@proof
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>z w. \<forall>x y. F (x, y) = (x = z \<and> y = w) \<Longrightarrow> \<exists>w. \<forall>y. (\<exists>z. \<forall>x. F (x, y) = (x = z)) = (y = w)
[PROOF STEP]
@obtain z w where "\<forall>x y. F(x,y) \<longleftrightarrow> x = z \<and> y = w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>z w. \<forall>x y. F (x, y) = (x = z \<and> y = w) \<Longrightarrow> \<exists>w. \<forall>y. (\<exists>z. \<forall>x. F (x, y) = (x = z)) = (y = w)
[PROOF STEP]
@have"\<forall>y. (\<exists>z. \<forall>x. F(x,y) \<longleftrightarrow> x = z) \<longleftrightarrow> y = w" @with
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>z w. \<forall>x y. F (x, y) = (x = z \<and> y = w) \<Longrightarrow> \<exists>w. \<forall>y. (\<exists>z. \<forall>x. F (x, y) = (x = z)) = (y = w)
[PROOF STEP]
@case "y = w" @with
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>z w. \<forall>x y. F (x, y) = (x = z \<and> y = w) \<Longrightarrow> \<exists>w. \<forall>y. (\<exists>z. \<forall>x. F (x, y) = (x = z)) = (y = w)
[PROOF STEP]
@have "\<forall>x. F(x,y) \<longleftrightarrow> x = z"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>z w. \<forall>x y. F (x, y) = (x = z \<and> y = w) \<Longrightarrow> \<exists>w. \<forall>y. (\<exists>z. \<forall>x. F (x, y) = (x = z)) = (y = w)
[PROOF STEP]
@end
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>z w. \<forall>x y. F (x, y) = (x = z \<and> y = w) \<Longrightarrow> \<exists>w. \<forall>y. (\<exists>z. \<forall>x. F (x, y) = (x = z)) = (y = w)
[PROOF STEP]
@end
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. \<exists>z w. \<forall>x y. F (x, y) = (x = z \<and> y = w) \<Longrightarrow> \<exists>w. \<forall>y. (\<exists>z. \<forall>x. F (x, y) = (x = z)) = (y = w)
[PROOF STEP]
@qed |
/-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.Array.Basic
import Init.Data.Nat.Linear
import Init.NotationExtra
theorem Array.of_push_eq_push {as bs : Array α} (h : as.push a = bs.push b) : as = bs ∧ a = b := by
simp [push] at h
have ⟨h₁, h₂⟩ := List.of_concat_eq_concat h
cases as; cases bs
simp_all
private theorem List.size_toArrayAux (as : List α) (bs : Array α) : (as.toArrayAux bs).size = as.length + bs.size := by
induction as generalizing bs with
| nil => simp [toArrayAux]
| cons a as ih => simp_arith [toArrayAux, *]
private theorem List.of_toArrayAux_eq_toArrayAux {as bs : List α} {cs ds : Array α} (h : as.toArrayAux cs = bs.toArrayAux ds) (hlen : cs.size = ds.size) : as = bs ∧ cs = ds := by
match as, bs with
| [], [] => simp [toArrayAux] at h; simp [h]
| a::as, [] => simp [toArrayAux] at h; rw [← h] at hlen; simp_arith [size_toArrayAux] at hlen
| [], b::bs => simp [toArrayAux] at h; rw [h] at hlen; simp_arith [size_toArrayAux] at hlen
| a::as, b::bs =>
simp [toArrayAux] at h
have : (cs.push a).size = (ds.push b).size := by simp [*]
have ⟨ih₁, ih₂⟩ := of_toArrayAux_eq_toArrayAux h this
simp [ih₁]
have := Array.of_push_eq_push ih₂
simp [this]
@[simp] theorem List.toArray_eq_toArray_eq (as bs : List α) : (as.toArray = bs.toArray) = (as = bs) := by
apply propext; apply Iff.intro
· intro h; simp [toArray] at h; have := of_toArrayAux_eq_toArrayAux h rfl; exact this.1
· intro h; rw [h]
def Array.mapM' [Monad m] (f : α → m β) (as : Array α) : m { bs : Array β // bs.size = as.size } :=
go 0 ⟨mkEmpty as.size, rfl⟩ (by simp_arith)
where
go (i : Nat) (acc : { bs : Array β // bs.size = i }) (hle : i ≤ as.size) : m { bs : Array β // bs.size = as.size } := do
if h : i = as.size then
return h ▸ acc
else
have hlt : i < as.size := Nat.lt_of_le_of_ne hle h
let b ← f as[i]
go (i+1) ⟨acc.val.push b, by simp [acc.property]⟩ hlt
termination_by go i _ _ => as.size - i
@[inline] private unsafe def mapMonoMImp [Monad m] (as : Array α) (f : α → m α) : m (Array α) :=
go 0 as
where
@[specialize] go (i : Nat) (as : Array α) : m (Array α) := do
if h : i < as.size then
let a := as[i]
let b ← f a
if ptrEq a b then
go (i+1) as
else
go (i+1) (as.set ⟨i, h⟩ b)
else
return as
/--
Monomorphic `Array.mapM`. The internal implementation uses pointer equality, and does not allocate a new array
if the result of each `f a` is a pointer equal value `a`.
-/
@[implemented_by mapMonoMImp] def Array.mapMonoM [Monad m] (as : Array α) (f : α → m α) : m (Array α) :=
as.mapM f
@[inline] def Array.mapMono (as : Array α) (f : α → α) : Array α :=
Id.run <| as.mapMonoM f
|
open import Signature
-- | One signature for terms and one for predicates.
module Logic (Σ Δ : Sig) (V : Set) where
open import Data.Empty renaming (⊥ to Ø)
open import Data.Unit
open import Data.Sum
open import Data.Product renaming (Σ to ∐)
open import Data.Nat
open import Data.Fin
FinSet : Set → Set
FinSet X = ∃ λ n → (Fin n → X)
dom : ∀{X} → FinSet X → Set
dom (n , _) = Fin n
get : ∀{X} (F : FinSet X) → dom F → X
get (_ , f) k = f k
drop : ∀{X} (F : FinSet
domEmpty : ∀{X} → FinSet X → Set
domEmpty (zero , _) = ⊤
domEmpty (suc _ , _) = Ø
open import Terms Σ
Term : Set
Term = T V
-- | An atom is either a predicate on terms or bottom.
Atom : Set
Atom = ⟪ Δ ⟫ Term -- ⊎ ⊤
{-
⊥ : Atom
⊥ = inj₂ tt
-}
Formula : Set
Formula = Atom
Sentence : Set
Sentence = FinSet Formula
data Parity : Set where
ind : Parity
coind : Parity
record Clause : Set where
constructor _⊢[_]_
field
head : Sentence
par : Parity
concl : Formula
open Clause public
Program : Set
Program = FinSet Clause
indClauses : Program → Program
indClauses (zero , P) = zero , λ ()
indClauses (suc n , P) = {!!}
|
/-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import field_theory.primitive_element
import linear_algebra.determinant
import linear_algebra.finite_dimensional
import linear_algebra.matrix.charpoly.minpoly
import linear_algebra.matrix.to_linear_equiv
import field_theory.is_alg_closed.algebraic_closure
import field_theory.galois
/-!
# Norm for (finite) ring extensions
Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`,
the determinant of the linear map given by multiplying by `s` gives information
about the roots of the minimal polynomial of `s` over `R`.
## Implementation notes
Typically, the norm is defined specifically for finite field extensions.
The current definition is as general as possible and the assumption that we have
fields or that the extension is finite is added to the lemmas as needed.
We only define the norm for left multiplication (`algebra.left_mul_matrix`,
i.e. `algebra.lmul_left`).
For now, the definitions assume `S` is commutative, so the choice doesn't
matter anyway.
See also `algebra.trace`, which is defined similarly as the trace of
`algebra.left_mul_matrix`.
## References
* https://en.wikipedia.org/wiki/Field_norm
-/
universes u v w
variables {R S T : Type*} [comm_ring R] [comm_ring S]
variables [algebra R S]
variables {K L F : Type*} [field K] [field L] [field F]
variables [algebra K L] [algebra K F]
variables {ι : Type w} [fintype ι]
open finite_dimensional
open linear_map
open matrix polynomial
open_locale big_operators
open_locale matrix
namespace algebra
variables (R)
/-- The norm of an element `s` of an `R`-algebra is the determinant of `(*) s`. -/
noncomputable def norm : S →* R :=
linear_map.det.comp (lmul R S).to_ring_hom.to_monoid_hom
lemma norm_apply (x : S) : norm R x = linear_map.det (lmul R S x) := rfl
lemma norm_eq_one_of_not_exists_basis
(h : ¬ ∃ (s : finset S), nonempty (basis s R S)) (x : S) : norm R x = 1 :=
by { rw [norm_apply, linear_map.det], split_ifs with h, refl }
variables {R}
-- Can't be a `simp` lemma because it depends on a choice of basis
lemma norm_eq_matrix_det [decidable_eq ι] (b : basis ι R S) (s : S) :
norm R s = matrix.det (algebra.left_mul_matrix b s) :=
by rw [norm_apply, ← linear_map.det_to_matrix b, to_matrix_lmul_eq]
/-- If `x` is in the base field `K`, then the norm is `x ^ [L : K]`. -/
lemma norm_algebra_map_of_basis (b : basis ι R S) (x : R) :
norm R (algebra_map R S x) = x ^ fintype.card ι :=
begin
haveI := classical.dec_eq ι,
rw [norm_apply, ← det_to_matrix b, lmul_algebra_map],
convert @det_diagonal _ _ _ _ _ (λ (i : ι), x),
{ ext i j, rw [to_matrix_lsmul, matrix.diagonal] },
{ rw [finset.prod_const, finset.card_univ] }
end
/-- If `x` is in the base field `K`, then the norm is `x ^ [L : K]`.
(If `L` is not finite-dimensional over `K`, then `norm = 1 = x ^ 0 = x ^ (finrank L K)`.)
-/
@[simp]
protected lemma norm_algebra_map (x : K) : norm K (algebra_map K L x) = x ^ finrank K L :=
begin
by_cases H : ∃ (s : finset L), nonempty (basis s K L),
{ rw [norm_algebra_map_of_basis H.some_spec.some, finrank_eq_card_basis H.some_spec.some] },
{ rw [norm_eq_one_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis, pow_zero],
rintros ⟨s, ⟨b⟩⟩,
exact H ⟨s, ⟨b⟩⟩ },
end
section eq_prod_roots
/-- Given `pb : power_basis K S`, then the norm of `pb.gen` is
`(-1) ^ pb.dim * coeff (minpoly K pb.gen) 0`. -/
lemma power_basis.norm_gen_eq_coeff_zero_minpoly [algebra K S] (pb : power_basis K S) :
norm K pb.gen = (-1) ^ pb.dim * coeff (minpoly K pb.gen) 0 :=
begin
rw [norm_eq_matrix_det pb.basis, det_eq_sign_charpoly_coeff, charpoly_left_mul_matrix,
fintype.card_fin]
end
/-- Given `pb : power_basis K S`, then the norm of `pb.gen` is
`((minpoly K pb.gen).map (algebra_map K F)).roots.prod`. -/
lemma power_basis.norm_gen_eq_prod_roots [algebra K S] (pb : power_basis K S)
(hf : (minpoly K pb.gen).splits (algebra_map K F)) :
algebra_map K F (norm K pb.gen) =
((minpoly K pb.gen).map (algebra_map K F)).roots.prod :=
begin
rw [power_basis.norm_gen_eq_coeff_zero_minpoly, ← pb.nat_degree_minpoly, ring_hom.map_mul,
← coeff_map, prod_roots_eq_coeff_zero_of_monic_of_split
((minpoly.monic (power_basis.is_integral_gen _)).map _)
((splits_id_iff_splits _).2 hf), nat_degree_map, map_pow, ← mul_assoc, ← mul_pow],
simp
end
end eq_prod_roots
section eq_zero_iff
lemma norm_eq_zero_iff_of_basis [is_domain R] [is_domain S] (b : basis ι R S) {x : S} :
algebra.norm R x = 0 ↔ x = 0 :=
begin
have hι : nonempty ι := b.index_nonempty,
letI := classical.dec_eq ι,
rw algebra.norm_eq_matrix_det b,
split,
{ rw ← matrix.exists_mul_vec_eq_zero_iff,
rintros ⟨v, v_ne, hv⟩,
rw [← b.equiv_fun.apply_symm_apply v, b.equiv_fun_symm_apply, b.equiv_fun_apply,
algebra.left_mul_matrix_mul_vec_repr] at hv,
refine (mul_eq_zero.mp (b.ext_elem $ λ i, _)).resolve_right (show ∑ i, v i • b i ≠ 0, from _),
{ simpa only [linear_equiv.map_zero, pi.zero_apply] using congr_fun hv i },
{ contrapose! v_ne with sum_eq,
apply b.equiv_fun.symm.injective,
rw [b.equiv_fun_symm_apply, sum_eq, linear_equiv.map_zero] } },
{ rintro rfl,
rw [alg_hom.map_zero, matrix.det_zero hι] },
end
lemma norm_ne_zero_iff_of_basis [is_domain R] [is_domain S] (b : basis ι R S) {x : S} :
algebra.norm R x ≠ 0 ↔ x ≠ 0 :=
not_iff_not.mpr (algebra.norm_eq_zero_iff_of_basis b)
/-- See also `algebra.norm_eq_zero_iff'` if you already have rewritten with `algebra.norm_apply`. -/
@[simp]
lemma norm_eq_zero_iff [finite_dimensional K L] {x : L} :
algebra.norm K x = 0 ↔ x = 0 :=
algebra.norm_eq_zero_iff_of_basis (basis.of_vector_space K L)
/-- This is `algebra.norm_eq_zero_iff` composed with `algebra.norm_apply`. -/
@[simp]
lemma norm_eq_zero_iff' [finite_dimensional K L] {x : L} :
linear_map.det (algebra.lmul K L x) = 0 ↔ x = 0 :=
algebra.norm_eq_zero_iff_of_basis (basis.of_vector_space K L)
end eq_zero_iff
open intermediate_field
variable (K)
lemma norm_eq_norm_adjoin [finite_dimensional K L] [is_separable K L] (x : L) :
norm K x = norm K (adjoin_simple.gen K x) ^ finrank K⟮x⟯ L :=
begin
letI := is_separable_tower_top_of_is_separable K K⟮x⟯ L,
let pbL := field.power_basis_of_finite_of_separable K⟮x⟯ L,
let pbx := intermediate_field.adjoin.power_basis (is_separable.is_integral K x),
rw [← adjoin_simple.algebra_map_gen K x, norm_eq_matrix_det (pbx.basis.smul pbL.basis) _,
smul_left_mul_matrix_algebra_map, det_block_diagonal, norm_eq_matrix_det pbx.basis],
simp only [finset.card_fin, finset.prod_const],
congr,
rw [← power_basis.finrank, adjoin_simple.algebra_map_gen K x]
end
variable {K}
section intermediate_field
lemma _root_.intermediate_field.adjoin_simple.norm_gen_eq_one {x : L}
(hx : ¬_root_.is_integral K x) : norm K (adjoin_simple.gen K x) = 1 :=
begin
rw [norm_eq_one_of_not_exists_basis],
contrapose! hx,
obtain ⟨s, ⟨b⟩⟩ := hx,
refine is_integral_of_mem_of_fg (K⟮x⟯).to_subalgebra _ x _,
{ exact (submodule.fg_iff_finite_dimensional _).mpr (of_finset_basis b) },
{ exact intermediate_field.subset_adjoin K _ (set.mem_singleton x) }
end
lemma _root_.intermediate_field.adjoin_simple.norm_gen_eq_prod_roots (x : L)
(hf : (minpoly K x).splits (algebra_map K F)) :
(algebra_map K F) (norm K (adjoin_simple.gen K x)) =
((minpoly K x).map (algebra_map K F)).roots.prod :=
begin
have injKxL := (algebra_map K⟮x⟯ L).injective,
by_cases hx : _root_.is_integral K x, swap,
{ simp [minpoly.eq_zero hx, intermediate_field.adjoin_simple.norm_gen_eq_one hx] },
have hx' : _root_.is_integral K (adjoin_simple.gen K x),
{ rwa [← is_integral_algebra_map_iff injKxL, adjoin_simple.algebra_map_gen],
apply_instance },
rw [← adjoin.power_basis_gen hx, power_basis.norm_gen_eq_prod_roots];
rw [adjoin.power_basis_gen hx, minpoly.eq_of_algebra_map_eq injKxL hx'];
try { simp only [adjoin_simple.algebra_map_gen _ _] },
exact hf
end
end intermediate_field
section eq_prod_embeddings
open intermediate_field intermediate_field.adjoin_simple polynomial
variables (E : Type*) [field E] [algebra K E]
lemma norm_eq_prod_embeddings_gen
(pb : power_basis K L)
(hE : (minpoly K pb.gen).splits (algebra_map K E)) (hfx : (minpoly K pb.gen).separable) :
algebra_map K E (norm K pb.gen) =
(@@finset.univ (power_basis.alg_hom.fintype pb)).prod (λ σ, σ pb.gen) :=
begin
letI := classical.dec_eq E,
rw [power_basis.norm_gen_eq_prod_roots pb hE, fintype.prod_equiv pb.lift_equiv',
finset.prod_mem_multiset, finset.prod_eq_multiset_prod, multiset.to_finset_val,
multiset.dedup_eq_self.mpr, multiset.map_id],
{ exact nodup_roots ((separable_map _).mpr hfx) },
{ intro x, refl },
{ intro σ, rw [power_basis.lift_equiv'_apply_coe, id.def] }
end
lemma norm_eq_prod_roots [is_separable K L] [finite_dimensional K L]
{x : L} (hF : (minpoly K x).splits (algebra_map K F)) :
algebra_map K F (norm K x) = ((minpoly K x).map (algebra_map K F)).roots.prod ^ finrank K⟮x⟯ L :=
by rw [norm_eq_norm_adjoin K x, map_pow,
intermediate_field.adjoin_simple.norm_gen_eq_prod_roots _ hF]
variable (F)
lemma prod_embeddings_eq_finrank_pow [algebra L F] [is_scalar_tower K L F][is_alg_closed E]
[is_separable K F] [finite_dimensional K F] (pb : power_basis K L) :
∏ σ : F →ₐ[K] E, σ (algebra_map L F pb.gen) =
((@@finset.univ (power_basis.alg_hom.fintype pb)).prod
(λ σ : L →ₐ[K] E, σ pb.gen)) ^ finrank L F :=
begin
haveI : finite_dimensional L F := finite_dimensional.right K L F,
haveI : is_separable L F := is_separable_tower_top_of_is_separable K L F,
letI : fintype (L →ₐ[K] E) := power_basis.alg_hom.fintype pb,
letI : ∀ (f : L →ₐ[K] E), fintype (@@alg_hom L F E _ _ _ _ f.to_ring_hom.to_algebra) := _,
rw [fintype.prod_equiv alg_hom_equiv_sigma (λ (σ : F →ₐ[K] E), _) (λ σ, σ.1 pb.gen),
← finset.univ_sigma_univ, finset.prod_sigma, ← finset.prod_pow],
refine finset.prod_congr rfl (λ σ _, _),
{ letI : algebra L E := σ.to_ring_hom.to_algebra,
simp only [finset.prod_const, finset.card_univ],
congr,
rw alg_hom.card L F E },
{ intros σ,
simp only [alg_hom_equiv_sigma, equiv.coe_fn_mk, alg_hom.restrict_domain, alg_hom.comp_apply,
is_scalar_tower.coe_to_alg_hom'] }
end
variable (K)
/-- For `L/K` a finite separable extension of fields and `E` an algebraically closed extension
of `K`, the norm (down to `K`) of an element `x` of `L` is equal to the product of the images
of `x` over all the `K`-embeddings `σ` of `L` into `E`. -/
lemma norm_eq_prod_embeddings [finite_dimensional K L] [is_separable K L] [is_alg_closed E]
{x : L} : algebra_map K E (norm K x) = ∏ σ : L →ₐ[K] E, σ x :=
begin
have hx := is_separable.is_integral K x,
rw [norm_eq_norm_adjoin K x, ring_hom.map_pow, ← adjoin.power_basis_gen hx,
norm_eq_prod_embeddings_gen E (adjoin.power_basis hx) (is_alg_closed.splits_codomain _)],
{ exact (prod_embeddings_eq_finrank_pow L E (adjoin.power_basis hx)).symm },
{ haveI := is_separable_tower_bot_of_is_separable K K⟮x⟯ L,
exact is_separable.separable K _ }
end
lemma norm_eq_prod_automorphisms [finite_dimensional K L] [is_galois K L] {x : L}:
algebra_map K L (norm K x) = ∏ (σ : L ≃ₐ[K] L), σ x :=
begin
apply no_zero_smul_divisors.algebra_map_injective L (algebraic_closure L),
rw map_prod (algebra_map L (algebraic_closure L)),
rw ← fintype.prod_equiv (normal.alg_hom_equiv_aut K (algebraic_closure L) L),
{ rw ← norm_eq_prod_embeddings,
simp only [algebra_map_eq_smul_one, smul_one_smul] },
{ intro σ,
simp only [normal.alg_hom_equiv_aut, alg_hom.restrict_normal', equiv.coe_fn_mk,
alg_equiv.coe_of_bijective, alg_hom.restrict_normal_commutes, id.map_eq_id,
ring_hom.id_apply] },
end
lemma is_integral_norm [algebra S L] [algebra S K] [is_scalar_tower S K L]
[is_separable K L] [finite_dimensional K L] {x : L} (hx : _root_.is_integral S x) :
_root_.is_integral S (norm K x) :=
begin
have hx' : _root_.is_integral K x := is_integral_of_is_scalar_tower _ hx,
rw [← is_integral_algebra_map_iff (algebra_map K (algebraic_closure L)).injective,
norm_eq_prod_roots],
{ refine (is_integral.multiset_prod (λ y hy, _)).pow _,
rw mem_roots_map (minpoly.ne_zero hx') at hy,
use [minpoly S x, minpoly.monic hx],
rw ← aeval_def at ⊢ hy,
exact minpoly.aeval_of_is_scalar_tower S x y hy },
{ apply is_alg_closed.splits_codomain },
{ apply_instance }
end
end eq_prod_embeddings
end algebra
|
/-
Copyright (c) 2022 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import data.finsupp.defs
import data.finset.pairwise
/-!
# Sums of collections of finsupp, and their support
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file provides results about the `finsupp.support` of sums of collections of `finsupp`,
including sums of `list`, `multiset`, and `finset`.
The support of the sum is a subset of the union of the supports:
* `list.support_sum_subset`
* `multiset.support_sum_subset`
* `finset.support_sum_subset`
The support of the sum of pairwise disjoint finsupps is equal to the union of the supports
* `list.support_sum_eq`
* `multiset.support_sum_eq`
* `finset.support_sum_eq`
Member in the support of the indexed union over a collection iff
it is a member of the support of a member of the collection:
* `list.mem_foldr_sup_support_iff`
* `multiset.mem_sup_map_support_iff`
* `finset.mem_sup_support_iff`
-/
variables {ι M : Type*} [decidable_eq ι]
lemma list.support_sum_subset [add_monoid M] (l : list (ι →₀ M)) :
l.sum.support ⊆ l.foldr ((⊔) ∘ finsupp.support) ∅ :=
begin
induction l with hd tl IH,
{ simp },
{ simp only [list.sum_cons, finset.union_comm],
refine finsupp.support_add.trans (finset.union_subset_union _ IH),
refl }
end
lemma multiset.support_sum_subset [add_comm_monoid M] (s : multiset (ι →₀ M)) :
s.sum.support ⊆ (s.map (finsupp.support)).sup :=
begin
induction s using quot.induction_on,
simpa using list.support_sum_subset _
end
lemma finset.support_sum_subset [add_comm_monoid M] (s : finset (ι →₀ M)) :
(s.sum id).support ⊆ finset.sup s finsupp.support :=
by { classical, convert multiset.support_sum_subset s.1; simp }
lemma list.mem_foldr_sup_support_iff [has_zero M] {l : list (ι →₀ M)} {x : ι} :
x ∈ l.foldr ((⊔) ∘ finsupp.support) ∅ ↔ ∃ (f : ι →₀ M) (hf : f ∈ l), x ∈ f.support :=
begin
simp only [finset.sup_eq_union, list.foldr_map, finsupp.mem_support_iff, exists_prop],
induction l with hd tl IH,
{ simp },
{ simp only [IH, list.foldr_cons, finset.mem_union, finsupp.mem_support_iff, list.mem_cons_iff],
split,
{ rintro (h|h),
{ exact ⟨hd, or.inl rfl, h⟩ },
{ exact h.imp (λ f hf, hf.imp_left or.inr) } },
{ rintro ⟨f, rfl|hf, h⟩,
{ exact or.inl h },
{ exact or.inr ⟨f, hf, h⟩ } } }
end
lemma multiset.mem_sup_map_support_iff [has_zero M] {s : multiset (ι →₀ M)} {x : ι} :
x ∈ (s.map (finsupp.support)).sup ↔ ∃ (f : ι →₀ M) (hf : f ∈ s), x ∈ f.support :=
quot.induction_on s $ λ _, by simpa using list.mem_foldr_sup_support_iff
lemma finset.mem_sup_support_iff [has_zero M] {s : finset (ι →₀ M)} {x : ι} :
x ∈ s.sup finsupp.support ↔ ∃ (f : ι →₀ M) (hf : f ∈ s), x ∈ f.support :=
multiset.mem_sup_map_support_iff
lemma list.support_sum_eq [add_monoid M] (l : list (ι →₀ M))
(hl : l.pairwise (disjoint on finsupp.support)) :
l.sum.support = l.foldr ((⊔) ∘ finsupp.support) ∅ :=
begin
induction l with hd tl IH,
{ simp },
{ simp only [list.pairwise_cons] at hl,
simp only [list.sum_cons, list.foldr_cons, function.comp_app],
rw [finsupp.support_add_eq, IH hl.right, finset.sup_eq_union],
suffices : disjoint hd.support (tl.foldr ((⊔) ∘ finsupp.support) ∅),
{ exact finset.disjoint_of_subset_right (list.support_sum_subset _) this },
{ rw [←list.foldr_map, ←finset.bot_eq_empty, list.foldr_sup_eq_sup_to_finset],
rw finset.disjoint_sup_right,
intros f hf,
simp only [list.mem_to_finset, list.mem_map] at hf,
obtain ⟨f, hf, rfl⟩ := hf,
exact hl.left _ hf } }
end
lemma multiset.support_sum_eq [add_comm_monoid M] (s : multiset (ι →₀ M))
(hs : s.pairwise (disjoint on finsupp.support)) :
s.sum.support = (s.map finsupp.support).sup :=
begin
induction s using quot.induction_on,
obtain ⟨l, hl, hd⟩ := hs,
convert list.support_sum_eq _ _,
{ simp },
{ simp },
{ simp only [multiset.quot_mk_to_coe'', multiset.coe_map, multiset.coe_eq_coe] at hl,
exact hl.symm.pairwise hd (λ _ _ h, disjoint.symm h) }
end
lemma finset.support_sum_eq [add_comm_monoid M] (s : finset (ι →₀ M))
(hs : (s : set (ι →₀ M)).pairwise_disjoint finsupp.support) :
(s.sum id).support = finset.sup s finsupp.support :=
begin
classical,
convert multiset.support_sum_eq s.1 _,
{ exact (finset.sum_val _).symm },
{ obtain ⟨l, hl, hn⟩ : ∃ (l : list (ι →₀ M)), l.to_finset = s ∧ l.nodup,
{ refine ⟨s.to_list, _, finset.nodup_to_list _⟩,
simp },
subst hl,
rwa [list.to_finset_val, list.dedup_eq_self.mpr hn,
multiset.pairwise_coe_iff_pairwise,
←list.pairwise_disjoint_iff_coe_to_finset_pairwise_disjoint hn],
intros x y hxy,
exact symmetric_disjoint hxy }
end
|
(* http://gallium.inria.fr/~scherer/gagallium/coq-eval/index.html *)
Definition nat_eq (x y: nat) : {x=y} + {x<>y}.
Proof.
decide equality.
Qed.
Compute (nat_eq 2 2).
Definition nat_eq2 (x y: nat) : {x=y} + {x<>y}.
Proof.
decide equality.
Defined.
Compute (nat_eq2 2 2).
(*vm_compute
native_compute *)
Require Import Coq.Program.Tactics.
Require Import Coq.ZArith.ZArith.
(*Require Export Coq.ZArith.Zcompare.
Require Export Coq.ZArith.Znat.*)
Require Import Coq.QArith.QArith.
Definition a := Z.of_nat 2 # Pos.of_nat 3.
Check Z.le.
Open Scope Z_scope. (* good *)
Definition t := { n : Z | n > 1 }.
Program Definition two : t := 2.
Next Obligation.
omega.
Show Proof.
Qed.
Program Definition succ (n: t) : t := n + 1.
Next Obligation. destruct n; simpl; omega. Qed.
(*!*)
Goal (1 # 1 <> 2 # 2).
congruence.
Show Proof.
Qed.
|
DGERQF Example Program Results
Minimum-norm solution
0.2371 -0.4575 -0.0085 -0.5192 0.0239 -0.0543
|
The lemma swap_apply(1) is now called swap_apply1. |
State Before: x : ℂ
n : ℕ
⊢ x ^ ↑↑n = x ^ ↑n State After: no goals Tactic: simp State Before: x : ℂ
n : ℕ
⊢ x ^ ↑-[n+1] = x ^ -[n+1] State After: x : ℂ
n : ℕ
⊢ x ^ ↑-[n+1] = (x ^ (n + 1))⁻¹ Tactic: rw [zpow_negSucc] State Before: x : ℂ
n : ℕ
⊢ x ^ ↑-[n+1] = (x ^ (n + 1))⁻¹ State After: no goals Tactic: simp only [Int.negSucc_coe, Int.cast_neg, Complex.cpow_neg, inv_eq_one_div, Int.cast_ofNat,
cpow_nat_cast] |
-- § 4.7
section
variables A B C D : Prop
example : A ∧ (A → B) → B := λ ⟨a, f⟩, f a
example : A → ¬(¬A ∧ B) := λ a ⟨f, b⟩, f a
example : ¬ (A ∧ B) → (A → ¬B) := λ f a b, f ⟨a, b⟩
example (h₁ : A ∨ B) (h₂ : A → C) (h₃ : B → D) : C ∨ D := h₁.cases_on (or.inl ∘ h₂) (or.inr ∘ h₃)
example (h : ¬A ∧ ¬B) : ¬(A ∨ B) := let ⟨f, g⟩ := h in λ ab, ab.cases_on f g
lemma t : ¬ (A ↔ ¬A) := λ ⟨f, g⟩, let a := g (λ a, f a a) in f a a
end
-- § 5.3
section
variables {A B C D : Prop}
example : (A ∨ ¬A) → (¬¬A → A) := λ d f, d.cases_on id (false.rec _ ∘ f)
variable em : ∀ {p : Prop}, p ∨ ¬p
variable by_contradiction : ∀ {p : Prop}, ¬¬p → p
example : ¬A ∨ ¬B → ¬(A ∧ B) := λ d ⟨a, b⟩, d.cases_on (λ f, f a) (λ f, f b)
example : ¬(A ∧ B) → ¬A ∨ ¬B := λ f, em.cases_on (λ a, or.inr (λ b, f ⟨a, b⟩)) (λ f, or.inl (λ a, f a))
example : (A → B) → ¬A ∨ B := λ f, em.cases_on (or.inr ∘ f) or.inl
lemma step1 (h₁ : ¬(A ∧ B)) (h₂ : A) : ¬A ∨ ¬B :=
have ¬B, from λ b, h₁ ⟨h₂, b⟩,
show ¬A ∨ ¬B, from or.inr this
lemma step2 (h₁ : ¬(A ∧ B)) (h₂ : ¬(¬A ∨ ¬B)) : false :=
have ¬A, from
assume : A,
have ¬A ∨ ¬B, from (step1 h₁ ‹A›),
show false, from h₂ this,
show false, from h₂ (or.inl ‹¬A›)
theorem step3 (h : ¬(A ∧ B)) : ¬A ∨ ¬B :=
by_contradiction
(assume h' : ¬(¬A ∨ ¬B),
show false, from step2 h h')
example (h : ¬B → ¬A) : A → B := λ a, by_contradiction (λ f, h f a)
example (h : A → B) : ¬A ∨ B := em.cases_on (or.inr ∘ h) or.inl
end
-- § 8.6
section
variables {T : Type} {A B C : T → Prop} {even odd : T → Prop} {s : T → T}
example : (∀ x, A x → B x) → ((∀ x, A x) → (∀ x, B x)) := λ f g x, f x (g x)
example : (∀ x, A x ∨ B x) → (∀ y, ¬(A y)) → (∀ x, B x) := λ f g x, (f x).cases_on (false.rec _ ∘ g x) id
example (h₁ : ∀ x, even x ∨ odd x) (h₂ : ∀ x, odd x → even (s x)) : ∀ x, even x ∨ even (s x) :=
λ x, (h₁ x).cases_on or.inl (or.inr ∘ h₂ x)
example : (∃ x, A x) ∨ (∃ x, B x) → ∃ x, (A x ∨ B x) :=
λ d, d.cases_on (λ ⟨x, p⟩, (⟨x, or.inl p⟩ : ∃ x, (A x ∨ B x))) (λ ⟨x, p⟩, ⟨x, or.inr p⟩)
example (h₁ : ∃ x, A x ∧ B x) (h₂ : ∀ x, A x ∧ B x → C x) : (∃ x, A x ∧ C x) :=
let ⟨x, ⟨a, b⟩⟩ := h₁ in ⟨x, ⟨a, h₂ x ⟨a, b⟩⟩⟩
variables {politician : T → Prop} {trusts : T → T → Prop}
example : (∀ x y, politician x → ¬(trusts y x)) ↔ (∀ x y, trusts y x → ¬(politician x)) :=
⟨λ f x y t p, f x y p t, λ f x y p t, f x y t p⟩
variables {person : Type} {young healthy likes_baseball active : person → Prop}
example
(h₁ : ∀ p, young p ∧ healthy p → likes_baseball p)
(h₂ : ∀ p, active p → healthy p)
(h₃ : ∃ p, young p ∧ active p)
: ∃ p, likes_baseball p :=
let ⟨p, ⟨y, a⟩⟩ := h₃ in ⟨p, h₁ p ⟨y, h₂ p a⟩⟩
end
section
variables {T : Type} {f : T → T} {P : T → Prop}
variable {refl : ∀ {t : T}, t = t}
variable {symm : ∀ {s t : T}, s = t → t = s}
variable {trans : ∀ {r s t : T}, r = s → s = t → r = t}
variable {congr : ∀ {s t : T}, s = t → f s = f t}
variable {subst : ∀ {s t : T}, s = t → P s → P t}
example : ∀ {x y z : T}, x = z → y = z → x = y :=
λ x y z xz yz, trans xz (symm yz)
end
section
variables {T : Type}
example
(h₁ : ∀ (x : T), x = x)
(h₂ : ∀ (u v w : T), u = w → v = w → u = v)
: ∀ x y, (x = y → y = x) :=
λ x y xy, h₂ _ _ _ (h₁ y) xy
end
section
variables {T: Type} {x : T} {A B : T → Prop}
example : ¬(∃x, A x ∧ B x) ↔ (∀x, A x → ¬(B x)) := ⟨λ f x a b, (f ⟨x, ⟨a, b⟩⟩).elim, λ f ⟨x, ⟨a, b⟩⟩, f x a b⟩
open classical
example : ¬(∀x, A x) → ∃x, ¬(A x) :=
λ f, by_contradiction (λ g, f (λ x, by_contradiction (λ h, g ⟨x, h⟩)))
example : ¬(∀x, A x → B x) ↔ (∃x, A x ∧ ¬(B x)) :=
⟨λ f, by_contradiction (λ g, f (λ x a, (by_contradiction (λ h, g ⟨x, ⟨a, h⟩⟩) : B x))),
λ ⟨x, ⟨a, f⟩⟩ g, (f (g x a)).elim⟩
variables {f : T → T} {P : T → Prop}
variable {refl : ∀ {t : T}, t = t}
variable {symm : ∀ {s t : T}, s = t → t = s}
variable {trans : ∀ {r s t : T}, r = s → s = t → r = t}
variable {congr : ∀ {s t : T}, s = t → f s = f t}
variable {subst : ∀ {s t : T}, s = t → P s → P t}
def L (P : T → Prop) := ∃ (x : T), P x ∧ ∀ y, P y → y = x
def R (P : T → Prop) := ∃ (x : T), P x ∧ ∀ y y', P y ∧ P y' → y = y'
example : L A → R A :=
λ ⟨x, ax, f⟩, ⟨x, ax, (λ y y' ⟨ay, ay'⟩, trans (f y ay) (symm (f y' ay')))⟩
example : R A → L A :=
λ ⟨x, ax, f⟩, ⟨x, ax, λ y ay, f y x ⟨ay, ax⟩⟩
end
-- § 9.5
section
variable A : Type
variable f : A → A
variable P : A → Prop
variable h : ∀ x, P x → P (f x)
example : ∀ y, P y → P (f (f y)) :=
λ _ py, h _ (h _ py).
end
section
variable U : Type
variables A B : U → Prop
example : (∀ x, A x ∧ B x) → ∀ x, A x :=
λ f x, (f x).elim_left
end
section
variable U : Type
variables A B C : U → Prop
variable h1 : ∀ x, A x ∨ B x
variable h2 : ∀ x, A x → C x
variable h3 : ∀ x, B x → C x
example : ∀ x, C x :=
λ x, (h1 x).elim (h2 x) (h3 x)
end
section
variable not_iff_not_self (P : Prop) : ¬ (P ↔ ¬ P)
variable Person : Type
variable shaves : Person → Person → Prop
variable barber : Person
variable h : ∀ x, shaves barber x ↔ ¬ shaves x x
example : false :=
not_iff_not_self _ (h barber)
end
section
variable U : Type
variables A B : U → Prop
example : (∃ x, A x) → ∃ x, A x ∨ B x :=
λ ⟨x, a⟩, ⟨x, or.inl a⟩
end
section
variable U : Type
variables A B : U → Prop
variable h1 : ∀ x, A x → B x
variable h2 : ∃ x, A x
example : ∃ x, B x :=
let ⟨x, a⟩ := h2 in ⟨x, h1 x a⟩
end
section
variable U : Type
variables A B C : U → Prop
example (h1 : ∃ x, A x ∧ B x) (h2 : ∀ x, B x → C x) : ∃ x, A x ∧ C x :=
let ⟨x, a, b⟩ := h1 in ⟨x, a, h2 x b⟩
end
section
variable U : Type
variables A B C : U → Prop
example : (¬ ∃ x, A x) → ∀ x, ¬ A x :=
λ f x a, f ⟨x, a⟩
example : (∀ x, ¬ A x) → ¬ ∃ x, A x :=
λ f ⟨x, a⟩, f x a
end
section
variable U : Type
variables R : U → U → Prop
example : (∃ x, ∀ y, R x y) → ∀ y, ∃ x, R x y :=
λ ⟨x, f⟩ y, ⟨x, f y⟩
end
section
theorem foo {A : Type} {a b c : A} : a = b → c = b → a = c :=
λ h₁ h₂, eq.symm h₂ ▸ h₁
section
variable {A : Type}
variables {a b c : A}
-- replace the sorry with a proof, using foo and rfl, without using eq.symm.
theorem my_symm (h : b = a) : a = b := foo rfl h
-- now use foo, rfl, and my_symm to prove transitivity
theorem my_trans (h1 : a = b) (h2 : b = c) : a = c := foo h1 (my_symm h2)
end
end
-- § 10.6
section
variables {T : Type} (R : T → T → Prop)
def has_min := ∃x, ∀y, R x y
def has_max := ∃y, ∀x, R x y
def has_between := ∀ x y, R x y ∧ x ≠ y → ∃ z, R x z ∧ R z y ∧ x ≠ z ∧ y ≠ z
#print nat.less_than_or_equal
lemma not_succ_le {x : ℕ} : ¬(nat.succ x ≤ x) :=
λ le, begin
induction x,
{ cases le },
{ exact x_ih (nat.pred_le_pred le) }
end
#check nat.less_than_or_equal.rec_on
universe u
def double : ℕ → ℕ := nat.rec 0 (λ (n m : ℕ), nat.succ (nat.succ m))
#reduce double 7
lemma nat_le_rec_on
{a b : ℕ} {T : Type} {P : ℕ → Prop} (le : a ≤ b) (x : T) :
(T → P a) → (T → ∀ ⦃b : ℕ⦄, nat.less_than_or_equal a b → P b → P (nat.succ b)) → P b :=
λ h₁ h₂, nat.less_than_or_equal.rec_on le (h₁ x) (h₂ x)
lemma not_succ_le' {x : ℕ} : ¬(nat.succ x ≤ x) :=
λ le, nat_le_rec_on le x (λ x, _) (λ b le' x, _)
example : has_min nat.le := ⟨0, λ x, x.rec_on (nat.less_than_or_equal.refl _) (λ n h, nat.less_than_or_equal.step h)⟩
example : ¬has_max nat.le := λ ⟨y, f⟩, not_succ_le (f (nat.succ y))
end
|
[GOAL]
n : ℕ
x : ℕ × ℕ
⊢ x ∈ antidiagonal n ↔ x.fst + x.snd = n
[PROOFSTEP]
rw [antidiagonal, mem_map]
[GOAL]
n : ℕ
x : ℕ × ℕ
⊢ (∃ a, a ∈ range (n + 1) ∧ (a, n - a) = x) ↔ x.fst + x.snd = n
[PROOFSTEP]
constructor
[GOAL]
case mp
n : ℕ
x : ℕ × ℕ
⊢ (∃ a, a ∈ range (n + 1) ∧ (a, n - a) = x) → x.fst + x.snd = n
[PROOFSTEP]
rintro ⟨i, hi, rfl⟩
[GOAL]
case mp.intro.intro
n i : ℕ
hi : i ∈ range (n + 1)
⊢ (i, n - i).fst + (i, n - i).snd = n
[PROOFSTEP]
rw [mem_range, lt_succ_iff] at hi
[GOAL]
case mp.intro.intro
n i : ℕ
hi : i ≤ n
⊢ (i, n - i).fst + (i, n - i).snd = n
[PROOFSTEP]
exact add_tsub_cancel_of_le hi
[GOAL]
case mpr
n : ℕ
x : ℕ × ℕ
⊢ x.fst + x.snd = n → ∃ a, a ∈ range (n + 1) ∧ (a, n - a) = x
[PROOFSTEP]
rintro rfl
[GOAL]
case mpr
x : ℕ × ℕ
⊢ ∃ a, a ∈ range (x.fst + x.snd + 1) ∧ (a, x.fst + x.snd - a) = x
[PROOFSTEP]
refine' ⟨x.fst, _, _⟩
[GOAL]
case mpr.refine'_1
x : ℕ × ℕ
⊢ x.fst ∈ range (x.fst + x.snd + 1)
[PROOFSTEP]
rw [mem_range, add_assoc, lt_add_iff_pos_right]
[GOAL]
case mpr.refine'_1
x : ℕ × ℕ
⊢ 0 < x.snd + 1
[PROOFSTEP]
exact zero_lt_succ _
[GOAL]
case mpr.refine'_2
x : ℕ × ℕ
⊢ (x.fst, x.fst + x.snd - x.fst) = x
[PROOFSTEP]
exact Prod.ext rfl (by simp only [add_tsub_cancel_left])
[GOAL]
x : ℕ × ℕ
⊢ (x.fst, x.fst + x.snd - x.fst).snd = x.snd
[PROOFSTEP]
simp only [add_tsub_cancel_left]
[GOAL]
n : ℕ
⊢ length (antidiagonal n) = n + 1
[PROOFSTEP]
rw [antidiagonal, length_map, length_range]
[GOAL]
n : ℕ
⊢ antidiagonal (n + 1) = (0, n + 1) :: map (Prod.map succ id) (antidiagonal n)
[PROOFSTEP]
simp only [antidiagonal, range_succ_eq_map, map_cons, true_and_iff, Nat.add_succ_sub_one, add_zero, id.def,
eq_self_iff_true, tsub_zero, map_map, Prod.map_mk]
[GOAL]
n : ℕ
⊢ (0, n + 1) :: (succ 0, n) :: map ((fun i => (i, n + 1 - i)) ∘ succ ∘ succ) (range n) =
(0, n + 1) :: (succ 0, n) :: map (Prod.map succ id ∘ (fun i => (i, n - i)) ∘ succ) (range n)
[PROOFSTEP]
apply congr rfl (congr rfl _)
[GOAL]
n : ℕ
⊢ map ((fun i => (i, n + 1 - i)) ∘ succ ∘ succ) (range n) =
map (Prod.map succ id ∘ (fun i => (i, n - i)) ∘ succ) (range n)
[PROOFSTEP]
ext
[GOAL]
case a.a
n n✝ : ℕ
a✝ : ℕ × ℕ
⊢ a✝ ∈ get? (map ((fun i => (i, n + 1 - i)) ∘ succ ∘ succ) (range n)) n✝ ↔
a✝ ∈ get? (map (Prod.map succ id ∘ (fun i => (i, n - i)) ∘ succ) (range n)) n✝
[PROOFSTEP]
simp
[GOAL]
n : ℕ
⊢ antidiagonal (n + 1) = map (Prod.map id succ) (antidiagonal n) ++ [(n + 1, 0)]
[PROOFSTEP]
simp only [antidiagonal, range_succ, add_tsub_cancel_left, map_append, append_assoc, tsub_self, singleton_append,
map_map, map]
[GOAL]
n : ℕ
⊢ map (fun i => (i, n + 1 - i)) (range n) ++ [(n, 1), (n + 1, 0)] =
map (Prod.map id succ ∘ fun i => (i, n - i)) (range n) ++ [Prod.map id succ (n, 0), (n + 1, 0)]
[PROOFSTEP]
congr 1
[GOAL]
case e_a
n : ℕ
⊢ map (fun i => (i, n + 1 - i)) (range n) = map (Prod.map id succ ∘ fun i => (i, n - i)) (range n)
[PROOFSTEP]
apply map_congr
[GOAL]
case e_a.a
n : ℕ
⊢ ∀ (x : ℕ), x ∈ range n → (x, n + 1 - x) = (Prod.map id succ ∘ fun i => (i, n - i)) x
[PROOFSTEP]
simp (config := { contextual := true }) [le_of_lt, Nat.succ_eq_add_one, Nat.sub_add_comm]
[GOAL]
n : ℕ
⊢ antidiagonal (n + 2) = (0, n + 2) :: map (Prod.map succ succ) (antidiagonal n) ++ [(n + 2, 0)]
[PROOFSTEP]
rw [antidiagonal_succ']
[GOAL]
n : ℕ
⊢ map (Prod.map id succ) (antidiagonal (n + 1)) ++ [(n + 1 + 1, 0)] =
(0, n + 2) :: map (Prod.map succ succ) (antidiagonal n) ++ [(n + 2, 0)]
[PROOFSTEP]
simp
[GOAL]
n : ℕ
⊢ map (Prod.map id succ ∘ Prod.map succ id) (antidiagonal n) = map (Prod.map succ succ) (antidiagonal n)
[PROOFSTEP]
ext
[GOAL]
case a.a
n n✝ : ℕ
a✝ : ℕ × ℕ
⊢ a✝ ∈ get? (map (Prod.map id succ ∘ Prod.map succ id) (antidiagonal n)) n✝ ↔
a✝ ∈ get? (map (Prod.map succ succ) (antidiagonal n)) n✝
[PROOFSTEP]
simp
[GOAL]
n : ℕ
⊢ map Prod.swap (antidiagonal n) = reverse (antidiagonal n)
[PROOFSTEP]
rw [antidiagonal, map_map, ← List.map_reverse, range_eq_range', reverse_range', ← range_eq_range', map_map]
[GOAL]
n : ℕ
⊢ map (Prod.swap ∘ fun i => (i, n - i)) (range (n + 1)) =
map ((fun i => (i, n - i)) ∘ fun x => 0 + (n + 1) - 1 - x) (range (n + 1))
[PROOFSTEP]
apply map_congr
[GOAL]
case a
n : ℕ
⊢ ∀ (x : ℕ),
x ∈ range (n + 1) → (Prod.swap ∘ fun i => (i, n - i)) x = ((fun i => (i, n - i)) ∘ fun x => 0 + (n + 1) - 1 - x) x
[PROOFSTEP]
simp (config := { contextual := true }) [Nat.sub_sub_self, lt_succ_iff]
|
Inductive IND2 (A:Type) (T:=fun _ : Type->Type => A) := CONS2 : IND2 A -> IND2 (T IND2).
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of interleaving using propositional equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Ternary.Interleaving.Propositional.Properties
{a} {A : Set a} where
import Data.List.Relation.Ternary.Interleaving.Setoid.Properties
as SetoidProperties
open import Relation.Binary.PropositionalEquality using (setoid)
------------------------------------------------------------------------
-- Re-exporting existing properties
open SetoidProperties (setoid A) public
|
%................................................................
function outputDisplacements...
(displacements,numberNodes,GDof)
% output of displacements in tabular form
disp('Displacements')
jj=1:numberNodes; format
f=[jj; displacements(1:2:GDof)'; displacements(2:2:GDof)'];
fprintf('Node UX UY\n')
fprintf('%4d %10.4e %10.4e\n',f) |
Formal statement is: lemma closed_substandard: "closed {x::'a::euclidean_space. \<forall>i\<in>Basis. P i \<longrightarrow> x\<bullet>i = 0}" (is "closed ?A") Informal statement is: The set of points in $\mathbb{R}^n$ that are zero in all coordinates where $P$ is true is closed. |
[GOAL]
G : Type u
inst✝ : Group G
⊢ commutator G = Subgroup.closure (commutatorSet G)
[PROOFSTEP]
simp [commutator, Subgroup.commutator_def, commutatorSet]
[GOAL]
G : Type u
inst✝ : Group G
⊢ commutator G = Subgroup.normalClosure (commutatorSet G)
[PROOFSTEP]
simp [commutator, Subgroup.commutator_def', commutatorSet]
[GOAL]
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Group.FG { x // x ∈ commutator G }
[PROOFSTEP]
rw [commutator_eq_closure]
[GOAL]
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Group.FG { x // x ∈ Subgroup.closure (commutatorSet G) }
[PROOFSTEP]
apply Group.closure_finite_fg
[GOAL]
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Group.rank { x // x ∈ commutator G } ≤ Nat.card ↑(commutatorSet G)
[PROOFSTEP]
rw [Subgroup.rank_congr (commutator_eq_closure G)]
[GOAL]
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Group.rank { x // x ∈ Subgroup.closure (commutatorSet G) } ≤ Nat.card ↑(commutatorSet G)
[PROOFSTEP]
apply Subgroup.rank_closure_finite_le_nat_card
[GOAL]
G : Type u
inst✝ : Group G
⊢ ⁅centralizer ↑(commutator G), centralizer ↑(commutator G)⁆ ≤ Subgroup.center G
[PROOFSTEP]
rw [← Subgroup.centralizer_univ, ← Subgroup.coe_top, ← Subgroup.commutator_eq_bot_iff_le_centralizer]
[GOAL]
G : Type u
inst✝ : Group G
⊢ ⁅⁅centralizer ↑(commutator G), centralizer ↑(commutator G)⁆, ⊤⁆ = ⊥
[PROOFSTEP]
suffices ⁅⁅⊤, centralizer (commutator G : Set G)⁆, centralizer (commutator G : Set G)⁆ = ⊥
by
refine' Subgroup.commutator_commutator_eq_bot_of_rotate _ this
rwa [Subgroup.commutator_comm (centralizer (commutator G : Set G))]
[GOAL]
G : Type u
inst✝ : Group G
this : ⁅⁅⊤, centralizer ↑(commutator G)⁆, centralizer ↑(commutator G)⁆ = ⊥
⊢ ⁅⁅centralizer ↑(commutator G), centralizer ↑(commutator G)⁆, ⊤⁆ = ⊥
[PROOFSTEP]
refine' Subgroup.commutator_commutator_eq_bot_of_rotate _ this
[GOAL]
G : Type u
inst✝ : Group G
this : ⁅⁅⊤, centralizer ↑(commutator G)⁆, centralizer ↑(commutator G)⁆ = ⊥
⊢ ⁅⁅centralizer ↑(commutator G), ⊤⁆, centralizer ↑(commutator G)⁆ = ⊥
[PROOFSTEP]
rwa [Subgroup.commutator_comm (centralizer (commutator G : Set G))]
[GOAL]
G : Type u
inst✝ : Group G
⊢ ⁅⁅⊤, centralizer ↑(commutator G)⁆, centralizer ↑(commutator G)⁆ = ⊥
[PROOFSTEP]
rw [Subgroup.commutator_comm, Subgroup.commutator_eq_bot_iff_le_centralizer]
[GOAL]
G : Type u
inst✝ : Group G
⊢ centralizer ↑(commutator G) ≤ centralizer ↑⁅⊤, centralizer ↑(commutator G)⁆
[PROOFSTEP]
exact Set.centralizer_subset (Subgroup.commutator_mono le_top le_top)
[GOAL]
G : Type u
inst✝ : Group G
src✝ : Group (G ⧸ commutator G) := QuotientGroup.Quotient.group (commutator G)
x y : Abelianization G
a b : G
⊢ ⁅b⁻¹, a⁻¹⁆ = ((fun x x_1 => x * x_1) a b)⁻¹ * (fun x x_1 => x * x_1) b a
[PROOFSTEP]
group
[GOAL]
G : Type u
inst✝¹ : Group G
A : Type v
inst✝ : CommGroup A
f : G →* A
⊢ commutator G ≤ MonoidHom.ker f
[PROOFSTEP]
rw [commutator_eq_closure, Subgroup.closure_le]
[GOAL]
G : Type u
inst✝¹ : Group G
A : Type v
inst✝ : CommGroup A
f : G →* A
⊢ commutatorSet G ⊆ ↑(MonoidHom.ker f)
[PROOFSTEP]
rintro x ⟨p, q, rfl⟩
[GOAL]
case intro.intro
G : Type u
inst✝¹ : Group G
A : Type v
inst✝ : CommGroup A
f : G →* A
p q : G
⊢ ⁅p, q⁆ ∈ ↑(MonoidHom.ker f)
[PROOFSTEP]
simp [MonoidHom.mem_ker, mul_right_comm (f p) (f q), commutatorElement_def]
[GOAL]
G : Type u
inst✝² inst✝¹ : Group G
H : Type v
inst✝ : Group H
e : G ≃* H
⊢ Function.LeftInverse ↑(Abelianization.map (toMonoidHom (symm e))) ↑(Abelianization.map (toMonoidHom e))
[PROOFSTEP]
rintro ⟨a⟩
[GOAL]
case mk
G : Type u
inst✝² inst✝¹ : Group G
H : Type v
inst✝ : Group H
e : G ≃* H
x✝ : Abelianization G
a : G
⊢ ↑(Abelianization.map (toMonoidHom (symm e))) (↑(Abelianization.map (toMonoidHom e)) (Quot.mk Setoid.r a)) =
Quot.mk Setoid.r a
[PROOFSTEP]
simp
[GOAL]
G : Type u
inst✝² inst✝¹ : Group G
H : Type v
inst✝ : Group H
e : G ≃* H
⊢ Function.RightInverse ↑(Abelianization.map (toMonoidHom (symm e))) ↑(Abelianization.map (toMonoidHom e))
[PROOFSTEP]
rintro ⟨a⟩
[GOAL]
case mk
G : Type u
inst✝² inst✝¹ : Group G
H : Type v
inst✝ : Group H
e : G ≃* H
x✝ : Abelianization H
a : H
⊢ ↑(Abelianization.map (toMonoidHom e)) (↑(Abelianization.map (toMonoidHom (symm e))) (Quot.mk Setoid.r a)) =
Quot.mk Setoid.r a
[PROOFSTEP]
simp
[GOAL]
G : Type u
inst✝¹ : Group G
H : Type u_1
inst✝ : CommGroup H
src✝ : H →* Abelianization H := of
⊢ Function.RightInverse ↑(↑lift (MonoidHom.id H)) ↑of
[PROOFSTEP]
rintro ⟨a⟩
[GOAL]
case mk
G : Type u
inst✝¹ : Group G
H : Type u_1
inst✝ : CommGroup H
src✝ : H →* Abelianization H := of
x✝ : Abelianization H
a : H
⊢ ↑of (↑(↑lift (MonoidHom.id H)) (Quot.mk Setoid.r a)) = Quot.mk Setoid.r a
[PROOFSTEP]
rfl
[GOAL]
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Group.rank { x // x ∈ closureCommutatorRepresentatives G } ≤ 2 * Nat.card ↑(commutatorSet G)
[PROOFSTEP]
rw [two_mul]
[GOAL]
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Group.rank { x // x ∈ closureCommutatorRepresentatives G } ≤ Nat.card ↑(commutatorSet G) + Nat.card ↑(commutatorSet G)
[PROOFSTEP]
exact
(Subgroup.rank_closure_finite_le_nat_card _).trans
((Set.card_union_le _ _).trans
(add_le_add ((Finite.card_image_le _).trans (Finite.card_range_le _))
((Finite.card_image_le _).trans (Finite.card_range_le _))))
[GOAL]
G : Type u
inst✝ : Group G
⊢ ↑(Subgroup.subtype (closureCommutatorRepresentatives G)) ''
commutatorSet { x // x ∈ closureCommutatorRepresentatives G } =
commutatorSet G
[PROOFSTEP]
apply Set.Subset.antisymm
[GOAL]
case h₁
G : Type u
inst✝ : Group G
⊢ ↑(Subgroup.subtype (closureCommutatorRepresentatives G)) ''
commutatorSet { x // x ∈ closureCommutatorRepresentatives G } ⊆
commutatorSet G
[PROOFSTEP]
rintro - ⟨-, ⟨g₁, g₂, rfl⟩, rfl⟩
[GOAL]
case h₁.intro.intro.intro.intro
G : Type u
inst✝ : Group G
g₁ g₂ : { x // x ∈ closureCommutatorRepresentatives G }
⊢ ↑(Subgroup.subtype (closureCommutatorRepresentatives G)) ⁅g₁, g₂⁆ ∈ commutatorSet G
[PROOFSTEP]
exact ⟨g₁, g₂, rfl⟩
[GOAL]
case h₂
G : Type u
inst✝ : Group G
⊢ commutatorSet G ⊆
↑(Subgroup.subtype (closureCommutatorRepresentatives G)) ''
commutatorSet { x // x ∈ closureCommutatorRepresentatives G }
[PROOFSTEP]
exact fun g hg =>
⟨_,
⟨⟨_, subset_closure (Or.inl ⟨_, ⟨⟨g, hg⟩, rfl⟩, rfl⟩)⟩, ⟨_, subset_closure (Or.inr ⟨_, ⟨⟨g, hg⟩, rfl⟩, rfl⟩)⟩, rfl⟩,
hg.choose_spec.choose_spec⟩
[GOAL]
G : Type u
inst✝ : Group G
⊢ Nat.card ↑(commutatorSet { x // x ∈ closureCommutatorRepresentatives G }) = Nat.card ↑(commutatorSet G)
[PROOFSTEP]
rw [← image_commutatorSet_closureCommutatorRepresentatives G]
[GOAL]
G : Type u
inst✝ : Group G
⊢ Nat.card ↑(commutatorSet { x // x ∈ closureCommutatorRepresentatives G }) =
Nat.card
↑(↑(Subgroup.subtype (closureCommutatorRepresentatives G)) ''
commutatorSet { x // x ∈ closureCommutatorRepresentatives G })
[PROOFSTEP]
exact Nat.card_congr (Equiv.Set.image _ _ (subtype_injective _))
[GOAL]
G : Type u
inst✝ : Group G
⊢ Nat.card { x // x ∈ _root_.commutator { x // x ∈ closureCommutatorRepresentatives G } } =
Nat.card { x // x ∈ _root_.commutator G }
[PROOFSTEP]
rw [commutator_eq_closure G, ← image_commutatorSet_closureCommutatorRepresentatives, ← MonoidHom.map_closure, ←
commutator_eq_closure]
[GOAL]
G : Type u
inst✝ : Group G
⊢ Nat.card { x // x ∈ _root_.commutator { x // x ∈ closureCommutatorRepresentatives G } } =
Nat.card
{ x //
x ∈
map (Subgroup.subtype (closureCommutatorRepresentatives G))
(_root_.commutator { x // x ∈ closureCommutatorRepresentatives G }) }
[PROOFSTEP]
exact Nat.card_congr (Equiv.Set.image _ _ (subtype_injective _))
[GOAL]
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Finite ↑(commutatorSet { x // x ∈ closureCommutatorRepresentatives G })
[PROOFSTEP]
apply Nat.finite_of_card_ne_zero
[GOAL]
case h
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Nat.card ↑(commutatorSet { x // x ∈ closureCommutatorRepresentatives G }) ≠ 0
[PROOFSTEP]
rw [card_commutatorSet_closureCommutatorRepresentatives]
[GOAL]
case h
G : Type u
inst✝¹ : Group G
inst✝ : Finite ↑(commutatorSet G)
⊢ Nat.card ↑(commutatorSet G) ≠ 0
[PROOFSTEP]
exact Finite.card_pos.ne'
|
/-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
! This file was ported from Lean 3 source module category_theory.abelian.generator
! leanprover-community/mathlib commit 09f981f72d43749f1fa072deade828d9c1e185bb
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.CategoryTheory.Abelian.Subobject
import Mathbin.CategoryTheory.Limits.EssentiallySmall
import Mathbin.CategoryTheory.Preadditive.Injective
import Mathbin.CategoryTheory.Preadditive.Generator
import Mathbin.CategoryTheory.Preadditive.Yoneda.Limits
/-!
# A complete abelian category with enough injectives and a separator has an injective coseparator
## Future work
* Once we know that Grothendieck categories have enough injectives, we can use this to conclude
that Grothendieck categories have an injective coseparator.
## References
* [Peter J Freyd, *Abelian Categories* (Theorem 3.37)][freyd1964abelian]
-/
open CategoryTheory CategoryTheory.Limits Opposite
universe v u
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C] [Abelian C]
theorem has_injective_coseparator [HasLimits C] [EnoughInjectives C] (G : C) (hG : IsSeparator G) :
∃ G : C, Injective G ∧ IsCoseparator G :=
by
haveI : well_powered C := well_powered_of_is_detector G hG.is_detector
haveI : has_products_of_shape (subobject (op G)) C := has_products_of_shape_of_small _ _
let T : C := injective.under (pi_obj fun P : subobject (op G) => unop P)
refine' ⟨T, inferInstance, (preadditive.is_coseparator_iff _).2 fun X Y f hf => _⟩
refine' (preadditive.is_separator_iff _).1 hG _ fun h => _
suffices hh : factor_thru_image (h ≫ f) = 0
· rw [← limits.image.fac (h ≫ f), hh, zero_comp]
let R := subobject.mk (factor_thru_image (h ≫ f)).op
let q₁ : image (h ≫ f) ⟶ unop R :=
(subobject.underlying_iso (factor_thru_image (h ≫ f)).op).unop.Hom
let q₂ : unop (R : Cᵒᵖ) ⟶ pi_obj fun P : subobject (op G) => unop P :=
section_ (pi.π (fun P : subobject (op G) => unop P) R)
let q : image (h ≫ f) ⟶ T := q₁ ≫ q₂ ≫ injective.ι _
exact
zero_of_comp_mono q
(by
rw [← injective.comp_factor_thru q (limits.image.ι (h ≫ f)), limits.image.fac_assoc,
category.assoc, hf, comp_zero])
#align category_theory.abelian.has_injective_coseparator CategoryTheory.Abelian.has_injective_coseparator
theorem has_projective_separator [HasColimits C] [EnoughProjectives C] (G : C)
(hG : IsCoseparator G) : ∃ G : C, Projective G ∧ IsSeparator G :=
by
obtain ⟨T, hT₁, hT₂⟩ := has_injective_coseparator (op G) ((is_separator_op_iff _).2 hG)
exact ⟨unop T, inferInstance, (is_separator_unop_iff _).2 hT₂⟩
#align category_theory.abelian.has_projective_separator CategoryTheory.Abelian.has_projective_separator
end CategoryTheory.Abelian
|
/-
Copyright (c) 2020 Shing Tak Lam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam
! This file was ported from Lean 3 source module group_theory.specific_groups.dihedral
! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Data.Zmod.Basic
import Mathbin.GroupTheory.Exponent
/-!
# Dihedral Groups
We define the dihedral groups `dihedral_group n`, with elements `r i` and `sr i` for `i : zmod n`.
For `n ≠ 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon. `r i`
represents the rotations of the `n`-gon by `2πi/n`, and `sr i` represents the reflections of the
`n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.
-/
/-- For `n ≠ 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon.
`r i` represents the rotations of the `n`-gon by `2πi/n`, and `sr i` represents the reflections of
the `n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.
-/
inductive DihedralGroup (n : ℕ) : Type
| r : ZMod n → DihedralGroup
| sr : ZMod n → DihedralGroup
deriving DecidableEq
#align dihedral_group DihedralGroup
namespace DihedralGroup
variable {n : ℕ}
/-- Multiplication of the dihedral group.
-/
private def mul : DihedralGroup n → DihedralGroup n → DihedralGroup n
| r i, r j => r (i + j)
| r i, sr j => sr (j - i)
| sr i, r j => sr (i + j)
| sr i, sr j => r (j - i)
#align dihedral_group.mul dihedral_group.mul
/-- The identity `1` is the rotation by `0`.
-/
private def one : DihedralGroup n :=
r 0
#align dihedral_group.one dihedral_group.one
instance : Inhabited (DihedralGroup n) :=
⟨one⟩
/-- The inverse of a an element of the dihedral group.
-/
private def inv : DihedralGroup n → DihedralGroup n
| r i => r (-i)
| sr i => sr i
#align dihedral_group.inv dihedral_group.inv
/-- The group structure on `dihedral_group n`.
-/
instance : Group (DihedralGroup n) where
mul := mul
mul_assoc := by rintro (a | a) (b | b) (c | c) <;> simp only [mul] <;> ring
one := one
one_mul := by
rintro (a | a)
exact congr_arg r (zero_add a)
exact congr_arg sr (sub_zero a)
mul_one := by
rintro (a | a)
exact congr_arg r (add_zero a)
exact congr_arg sr (add_zero a)
inv := inv
mul_left_inv := by
rintro (a | a)
exact congr_arg r (neg_add_self a)
exact congr_arg r (sub_self a)
@[simp]
theorem r_mul_r (i j : ZMod n) : r i * r j = r (i + j) :=
rfl
#align dihedral_group.r_mul_r DihedralGroup.r_mul_r
@[simp]
theorem r_mul_sr (i j : ZMod n) : r i * sr j = sr (j - i) :=
rfl
#align dihedral_group.r_mul_sr DihedralGroup.r_mul_sr
@[simp]
theorem sr_mul_r (i j : ZMod n) : sr i * r j = sr (i + j) :=
rfl
#align dihedral_group.sr_mul_r DihedralGroup.sr_mul_r
@[simp]
theorem sr_mul_sr (i j : ZMod n) : sr i * sr j = r (j - i) :=
rfl
#align dihedral_group.sr_mul_sr DihedralGroup.sr_mul_sr
theorem one_def : (1 : DihedralGroup n) = r 0 :=
rfl
#align dihedral_group.one_def DihedralGroup.one_def
private def fintype_helper : Sum (ZMod n) (ZMod n) ≃ DihedralGroup n
where
invFun i :=
match i with
| r j => Sum.inl j
| sr j => Sum.inr j
toFun i :=
match i with
| Sum.inl j => r j
| Sum.inr j => sr j
left_inv := by rintro (x | x) <;> rfl
right_inv := by rintro (x | x) <;> rfl
#align dihedral_group.fintype_helper dihedral_group.fintype_helper
/-- If `0 < n`, then `dihedral_group n` is a finite group.
-/
instance [NeZero n] : Fintype (DihedralGroup n) :=
Fintype.ofEquiv _ fintypeHelper
instance : Nontrivial (DihedralGroup n) :=
⟨⟨r 0, sr 0, by decide⟩⟩
/-- If `0 < n`, then `dihedral_group n` has `2n` elements.
-/
theorem card [NeZero n] : Fintype.card (DihedralGroup n) = 2 * n := by
rw [← fintype.card_eq.mpr ⟨fintype_helper⟩, Fintype.card_sum, ZMod.card, two_mul]
#align dihedral_group.card DihedralGroup.card
@[simp]
theorem r_one_pow (k : ℕ) : (r 1 : DihedralGroup n) ^ k = r k :=
by
induction' k with k IH
· rw [Nat.cast_zero]
rfl
· rw [pow_succ, IH, r_mul_r]
congr 1
norm_cast
rw [Nat.one_add]
#align dihedral_group.r_one_pow DihedralGroup.r_one_pow
@[simp]
theorem r_one_pow_n : r (1 : ZMod n) ^ n = 1 :=
by
rw [r_one_pow, one_def]
congr 1
exact ZMod.nat_cast_self _
#align dihedral_group.r_one_pow_n DihedralGroup.r_one_pow_n
@[simp]
theorem sr_mul_self (i : ZMod n) : sr i * sr i = 1 := by rw [sr_mul_sr, sub_self, one_def]
#align dihedral_group.sr_mul_self DihedralGroup.sr_mul_self
/-- If `0 < n`, then `sr i` has order 2.
-/
@[simp]
theorem orderOf_sr (i : ZMod n) : orderOf (sr i) = 2 :=
by
rw [orderOf_eq_prime _ _]
· exact ⟨Nat.prime_two⟩
rw [sq, sr_mul_self]
decide
#align dihedral_group.order_of_sr DihedralGroup.orderOf_sr
/-- If `0 < n`, then `r 1` has order `n`.
-/
@[simp]
theorem orderOf_r_one : orderOf (r 1 : DihedralGroup n) = n :=
by
rcases eq_zero_or_neZero n with (rfl | hn)
· rw [orderOf_eq_zero_iff']
intro n hn
rw [r_one_pow, one_def]
apply mt r.inj
simpa using hn.ne'
· skip
apply
(Nat.le_of_dvd (NeZero.pos n) <|
orderOf_dvd_of_pow_eq_one <| @r_one_pow_n n).lt_or_eq.resolve_left
intro h
have h1 : (r 1 : DihedralGroup n) ^ orderOf (r 1) = 1 := pow_orderOf_eq_one _
rw [r_one_pow] at h1
injection h1 with h2
rw [← ZMod.val_eq_zero, ZMod.val_nat_cast, Nat.mod_eq_of_lt h] at h2
exact absurd h2.symm (orderOf_pos _).Ne
#align dihedral_group.order_of_r_one DihedralGroup.orderOf_r_one
/-- If `0 < n`, then `i : zmod n` has order `n / gcd n i`.
-/
theorem orderOf_r [NeZero n] (i : ZMod n) : orderOf (r i) = n / Nat.gcd n i.val :=
by
conv_lhs => rw [← ZMod.nat_cast_zmod_val i]
rw [← r_one_pow, orderOf_pow, order_of_r_one]
#align dihedral_group.order_of_r DihedralGroup.orderOf_r
theorem exponent : Monoid.exponent (DihedralGroup n) = lcm n 2 :=
by
rcases eq_zero_or_neZero n with (rfl | hn)
· exact Monoid.exponent_eq_zero_of_order_zero order_of_r_one
skip
apply Nat.dvd_antisymm
· apply Monoid.exponent_dvd_of_forall_pow_eq_one
rintro (m | m)
· rw [← orderOf_dvd_iff_pow_eq_one, order_of_r]
refine' Nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2)
· exact (Nat.div_mul_cancel (Nat.gcd_dvd_left n m.val)).symm
· rw [← orderOf_dvd_iff_pow_eq_one, order_of_sr]
exact dvd_lcm_right n 2
· apply lcm_dvd
· convert Monoid.order_dvd_exponent (r 1)
exact order_of_r_one.symm
· convert Monoid.order_dvd_exponent (sr 0)
exact (order_of_sr 0).symm
#align dihedral_group.exponent DihedralGroup.exponent
end DihedralGroup
|
lemma coeffs_shift_poly [code abstract]: "coeffs (poly_shift n p) = drop n (coeffs p)" |
subroutine PARAMS_HDR( plon, plonl, plat, plev, &
phtcnt, rxntot, &
adv_cnt, nadv_cnt, histout_cnt, &
chemistry, diffusion, convection, arch_type, &
filespec )
!-----------------------------------------------------------------------
! ... Make the params.h file
!-----------------------------------------------------------------------
use IO, only : lout
implicit none
!-----------------------------------------------------------------------
! ... Dummy args
!-----------------------------------------------------------------------
integer, intent(in) :: plon, plonl, plat, plev
integer, intent(in) :: phtcnt, rxntot
integer, intent(in) :: adv_cnt, nadv_cnt
integer, intent(in) :: histout_cnt(20,2)
logical, intent(in) :: chemistry, diffusion, convection
character(len=16), intent(in) :: arch_type
character(len=*), intent(in) :: filespec
!-----------------------------------------------------------------------
! ... The local variables
!-----------------------------------------------------------------------
integer :: ios
logical :: lexist
INQUIRE( file = TRIM(filespec), exist = lexist )
if( lexist ) then
call SYSTEM( 'rm '//TRIM(filespec) )
end if
OPEN( unit = 30, file = TRIM(filespec), iostat=ios )
if( ios /= 0 ) then
write(lout,*) 'PARAMS_HDR: Failed to open simulation datafile ',TRIM(filespec),' ;error = ',ios
stop
end if
write(30,'(a)') '# ifndef PARAMS_H'
write(30,'(a)') '# define PARAMS_H'
write(30,'('' '')')
write(30,'(a)') '# define CALC_ETADOT'
if( diffusion ) then
write(30,'(a)') '# define DI_VDIFF'
else
write(30,'(a)') '# define AR_VDIFF'
end if
if( convection ) then
write(30,'(a)') '# define DI_CONV_CCM'
else
write(30,'(a)') '# define AR_CONV_CCM'
end if
write(30,'(a)') '# define DI_CLOUD_PHYS'
if( chemistry ) then
write(30,'(a)') '# define TROP_CHEM'
end if
write(30,'('' '')')
write(30,'(a)') '# endif'
end subroutine PARAMS_HDR
|
# Decision Lens API
#
# No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
#
# OpenAPI spec version: 1.0
#
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#' AddUsersRequest Class
#'
#' @field emailIds
#' @field message
#' @field doNotNotify
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
AddUsersRequest <- R6::R6Class(
'AddUsersRequest',
public = list(
`emailIds` = NULL,
`message` = NULL,
`doNotNotify` = NULL,
initialize = function(`emailIds`, `message`, `doNotNotify`){
if (!missing(`emailIds`)) {
stopifnot(is.list(`emailIds`), length(`emailIds`) != 0)
lapply(`emailIds`, function(x) stopifnot(is.character(x)))
self$`emailIds` <- `emailIds`
}
if (!missing(`message`)) {
stopifnot(is.character(`message`), length(`message`) == 1)
self$`message` <- `message`
}
if (!missing(`doNotNotify`)) {
self$`doNotNotify` <- `doNotNotify`
}
},
toJSON = function() {
AddUsersRequestObject <- list()
if (!is.null(self$`emailIds`)) {
AddUsersRequestObject[['emailIds']] <- self$`emailIds`
}
if (!is.null(self$`message`)) {
AddUsersRequestObject[['message']] <- self$`message`
}
if (!is.null(self$`doNotNotify`)) {
AddUsersRequestObject[['doNotNotify']] <- self$`doNotNotify`
}
AddUsersRequestObject
},
fromJSON = function(AddUsersRequestJson) {
AddUsersRequestObject <- dlensFromJSON(AddUsersRequestJson)
if (!is.null(AddUsersRequestObject$`emailIds`)) {
self$`emailIds` <- AddUsersRequestObject$`emailIds`
}
if (!is.null(AddUsersRequestObject$`message`)) {
self$`message` <- AddUsersRequestObject$`message`
}
if (!is.null(AddUsersRequestObject$`doNotNotify`)) {
self$`doNotNotify` <- AddUsersRequestObject$`doNotNotify`
}
},
toJSONString = function() {
sprintf(
'{
"emailIds": [%s],
"message": %s,
"doNotNotify": %s
}',
lapply(self$`emailIds`, function(x) paste(paste0('"', x, '"'), sep=",")),
self$`message`,
self$`doNotNotify`
)
},
fromJSONString = function(AddUsersRequestJson) {
AddUsersRequestObject <- dlensFromJSON(AddUsersRequestJson)
self$`emailIds` <- AddUsersRequestObject$`emailIds`
self$`message` <- AddUsersRequestObject$`message`
self$`doNotNotify` <- AddUsersRequestObject$`doNotNotify`
}
)
)
|
module Logic where
data True : Set where
tt : True
infix 10 _/\_
data _/\_ (P Q : Set) : Set where
<_,_> : P -> Q -> P /\ Q
|
lemma connected_component_eq_empty [simp]: "connected_component_set S x = {} \<longleftrightarrow> x \<notin> S" |
With both the Canadian and New Zealand Divisions finding progress difficult , it was decided to bring the Indian 21st Infantry Brigade into the attack with orders to seize <unk> . With no river crossing available , the Indian engineers rushed to build a bridge across the Moro which was completed on 9 December and allowed infantry and supporting armour to cross and expand the bridgehead on the far bank . The bridge was named the " Impossible Bridge " because the local geography required for it to be built backwards from the enemy bank of the river .
|
header {* Lasso Finding Algorithm for Generalized B\"uchi Graphs \label{sec:gbg}*}
theory Gabow_GBG
imports
Gabow_Skeleton
"../CAVA_Automata/Lasso"
Find_Path
begin
text {*
We implement an algorithm that computes witnesses for the
non-emptiness of Generalized B\"uchi Graphs (GBG).
*}
section {* Specification *}
context igb_graph
begin
definition ce_correct
-- "Specifies a correct counter-example"
where
"ce_correct Vr Vl \<equiv> (\<exists>pr pl.
Vr \<subseteq> E\<^sup>*``V0 \<and> Vl \<subseteq> E\<^sup>*``V0 (* Only reachable nodes are covered *)
\<and> set pr\<subseteq>Vr \<and> set pl\<subseteq>Vl (* The paths are inside the specified sets *)
\<and> Vl\<times>Vl \<subseteq> (E \<inter> Vl\<times>Vl)\<^sup>* (* Vl is mutually connected *)
\<and> Vl\<times>Vl \<inter> E \<noteq> {} (* Vl is non-trivial *)
\<and> is_lasso_prpl (pr,pl)) (* Paths form a lasso *)
"
definition find_ce_spec :: "('Q set \<times> 'Q set) option nres" where
"find_ce_spec \<equiv> SPEC (\<lambda>r. case r of
None \<Rightarrow> (\<forall>prpl. \<not>is_lasso_prpl prpl)
| Some (Vr,Vl) \<Rightarrow> ce_correct Vr Vl
)"
definition find_lasso_spec :: "('Q list \<times> 'Q list) option nres" where
"find_lasso_spec \<equiv> SPEC (\<lambda>r. case r of
None \<Rightarrow> (\<forall>prpl. \<not>is_lasso_prpl prpl)
| Some prpl \<Rightarrow> is_lasso_prpl prpl
)"
end
section {* Invariant Extension *}
text {* Extension of the outer invariant: *}
context igb_graph
begin
definition no_acc_over
-- "Specifies that there is no accepting cycle touching a set of nodes"
where
"no_acc_over D \<equiv> \<not>(\<exists>v\<in>D. \<exists>pl. pl\<noteq>[] \<and> path E v pl v \<and>
(\<forall>i<num_acc. \<exists>q\<in>set pl. i\<in>acc q))"
definition "fgl_outer_invar_ext \<equiv> \<lambda>it (brk,D).
case brk of None \<Rightarrow> no_acc_over D | Some (Vr,Vl) \<Rightarrow> ce_correct Vr Vl"
definition "fgl_outer_invar \<equiv> \<lambda>it (brk,D). case brk of
None \<Rightarrow> outer_invar it D \<and> no_acc_over D
| Some (Vr,Vl) \<Rightarrow> ce_correct Vr Vl"
end
text {* Extension of the inner invariant: *}
locale fgl_invar_loc =
invar_loc G v0 D0 p D pE
+ igb_graph G
for G :: "('Q, 'more) igb_graph_rec_scheme"
and v0 D0 and brk :: "('Q set \<times> 'Q set) option" and p D pE +
assumes no_acc: "brk=None \<Longrightarrow> \<not>(\<exists>v pl. pl\<noteq>[] \<and> path lvE v pl v \<and>
(\<forall>i<num_acc. \<exists>q\<in>set pl. i\<in>acc q))" -- "No accepting cycle over
visited edges"
assumes acc: "brk=Some (Vr,Vl) \<Longrightarrow> ce_correct Vr Vl"
begin
lemma locale_this: "fgl_invar_loc G v0 D0 brk p D pE"
by unfold_locales
lemma invar_loc_this: "invar_loc G v0 D0 p D pE" by unfold_locales
lemma eas_gba_graph_this: "igb_graph G" by unfold_locales
end
definition (in igb_graph) "fgl_invar v0 D0 \<equiv>
\<lambda>(brk, p, D, pE). fgl_invar_loc G v0 D0 brk p D pE"
section {* Definition of the Lasso-Finding Algorithm*}
context igb_graph
begin
definition find_ce :: "('Q set \<times> 'Q set) option nres" where
"find_ce \<equiv> do {
let D = {};
(brk,_)\<leftarrow>FOREACHci fgl_outer_invar V0
(\<lambda>(brk,_). brk=None)
(\<lambda>v0 (brk,D0). do {
if v0\<notin>D0 then do {
let s = (None,initial v0 D0);
(brk,p,D,pE) \<leftarrow> WHILEIT (fgl_invar v0 D0)
(\<lambda>(brk,p,D,pE). brk=None \<and> p \<noteq> []) (\<lambda>(_,p,D,pE).
do {
(* Select edge from end of path *)
(vo,(p,D,pE)) \<leftarrow> select_edge (p,D,pE);
ASSERT (p\<noteq>[]);
case vo of
Some v \<Rightarrow> do {
if v \<in> \<Union>set p then do {
(* Collapse *)
let (p,D,pE) = collapse v (p,D,pE);
ASSERT (p\<noteq>[]);
if \<forall>i<num_acc. \<exists>q\<in>last p. i\<in>acc q then
RETURN (Some (\<Union>set (butlast p),last p),p,D,pE)
else
RETURN (None,p,D,pE)
} else if v\<notin>D then do {
(* Edge to new node. Append to path *)
RETURN (None,push v (p,D,pE))
} else RETURN (None,p,D,pE)
}
| None \<Rightarrow> do {
(* No more outgoing edges from current node on path *)
ASSERT (pE \<inter> last p \<times> UNIV = {});
RETURN (None,pop (p,D,pE))
}
}) s;
ASSERT (brk=None \<longrightarrow> (p=[] \<and> pE={}));
RETURN (brk,D)
} else
RETURN (brk,D0)
}) (None,D);
RETURN brk
}"
end
section {* Invariant Preservation *}
context igb_graph
begin
definition "fgl_invar_part \<equiv> \<lambda>(brk, p, D, pE).
fgl_invar_loc_axioms G brk p D pE"
lemma fgl_outer_invarI[intro?]:
"\<lbrakk>
brk=None \<Longrightarrow> outer_invar it D;
\<lbrakk>brk=None \<Longrightarrow> outer_invar it D\<rbrakk> \<Longrightarrow> fgl_outer_invar_ext it (brk,D)\<rbrakk>
\<Longrightarrow> fgl_outer_invar it (brk,D)"
unfolding outer_invar_def fgl_outer_invar_ext_def fgl_outer_invar_def
apply (auto split: prod.splits option.splits)
done
lemma fgl_invarI[intro?]:
"\<lbrakk> invar v0 D0 PDPE;
invar v0 D0 PDPE \<Longrightarrow> fgl_invar_part (B,PDPE)\<rbrakk>
\<Longrightarrow> fgl_invar v0 D0 (B,PDPE)"
unfolding invar_def fgl_invar_part_def fgl_invar_def
apply (simp split: prod.split_asm)
apply intro_locales
apply (simp add: invar_loc_def)
apply assumption
done
lemma fgl_invar_initial:
assumes OINV: "fgl_outer_invar it (None,D0)"
assumes A: "v0\<in>it" "v0\<notin>D0"
shows "fgl_invar_part (None, initial v0 D0)"
proof -
from OINV interpret outer_invar_loc G it D0
by (simp add: fgl_outer_invar_def outer_invar_def)
from OINV have no_acc: "no_acc_over D0"
by (simp add: fgl_outer_invar_def fgl_outer_invar_ext_def)
{
fix v pl
assume "pl \<noteq> []" and P: "path (vE [{v0}] D0 (E \<inter> {v0} \<times> UNIV)) v pl v"
hence 1: "v\<in>D0"
by (cases pl) (auto simp: path_cons_conv vE_def touched_def)
have 2: "path E v pl v" using path_mono[OF vE_ss_E P] .
note 1 2
} note AUX1=this
show ?thesis
unfolding fgl_invar_part_def
apply (simp split: prod.splits add: initial_def)
apply unfold_locales
using `v0\<notin>D0`
using AUX1 no_acc unfolding no_acc_over_def apply blast
by simp
qed
lemma fgl_invar_pop:
assumes INV: "fgl_invar v0 D0 (None,p,D,pE)"
assumes INV': "invar v0 D0 (pop (p,D,pE))"
assumes NE[simp]: "p\<noteq>[]"
assumes NO': "pE \<inter> last p \<times> UNIV = {}"
shows "fgl_invar_part (None, pop (p,D,pE))"
proof -
from INV interpret fgl_invar_loc G v0 D0 None p D pE
by (simp add: fgl_invar_def)
show ?thesis
apply (unfold fgl_invar_part_def pop_def)
apply (simp split: prod.splits)
apply unfold_locales
unfolding vE_pop[OF NE]
using no_acc apply auto []
apply simp
done
qed
lemma fgl_invar_collapse_ce_aux:
assumes INV: "invar v0 D0 (p, D, pE)"
assumes NE[simp]: "p\<noteq>[]"
assumes NONTRIV: "vE p D pE \<inter> (last p \<times> last p) \<noteq> {}"
assumes ACC: "\<forall>i<num_acc. \<exists>q\<in>last p. i\<in>acc q"
shows "fgl_invar_part (Some (\<Union>set (butlast p), last p), p, D, pE)"
proof -
from INV interpret invar_loc G v0 D0 p D pE by (simp add: invar_def)
txt {* The last collapsed node on the path contains states from all
accepting sets.
As it is strongly connected and reachable, we get a counter-example.
Here, we explicitely construct the lasso. *}
let ?Er = "E \<inter> (\<Union>set (butlast p) \<times> UNIV)"
txt {* We choose a node in the last Cnode, that is reachable only using
former Cnodes. *}
obtain w where "(v0,w)\<in>?Er\<^sup>*" "w\<in>last p"
proof cases
assume "length p = 1"
hence "v0\<in>last p"
using root_v0
by (cases p) auto
thus thesis by (auto intro: that)
next
assume "length p\<noteq>1"
hence "length p > 1" by (cases p) auto
hence "Suc (length p - 2) < length p" by auto
from p_connected'[OF this] obtain u v where
UIP: "u\<in>p!(length p - 2)" and VIP: "v\<in>p!(length p - 1)" and "(u,v)\<in>lvE"
using `length p > 1` by auto
from root_v0 have V0IP: "v0\<in>p!0" by (cases p) auto
from VIP have "v\<in>last p" by (cases p rule: rev_cases) auto
from pathI[OF V0IP UIP] `length p > 1` have
"(v0,u)\<in>(lvE \<inter> (\<Union>set (butlast p)) \<times> (\<Union>set (butlast p)))\<^sup>*"
(is "_ \<in> \<dots>\<^sup>*")
by (simp add: path_seg_butlast)
also have "\<dots> \<subseteq> ?Er" using lvE_ss_E by auto
finally (rtrancl_mono_mp[rotated]) have "(v0,u)\<in>?Er\<^sup>*" .
also note `(u,v)\<in>lvE` UIP hence "(u,v)\<in>?Er" using lvE_ss_E `length p > 1`
apply (auto simp: Bex_def in_set_conv_nth)
by (metis One_nat_def Suc_lessE `Suc (length p - 2) < length p`
diff_Suc_1 length_butlast nth_butlast)
finally show ?thesis by (rule that) fact
qed
then obtain "pr" where
P_REACH: "path E v0 pr w" and
R_SS: "set pr \<subseteq> \<Union>set (butlast p)"
apply -
apply (erule rtrancl_is_path)
apply (frule path_nodes_edges)
apply (auto
dest!: order_trans[OF _ image_Int_subset]
dest: path_mono[of _ E, rotated])
done
have [simp]: "last p = p!(length p - 1)" by (cases p rule: rev_cases) auto
txt {* From that node, we construct a lasso by inductively appending a path
for each accepting set *}
{
fix na
assume na_def: "na = num_acc"
have "\<exists>pl. pl\<noteq>[]
\<and> path (lvE \<inter> last p\<times>last p) w pl w
\<and> (\<forall>i<num_acc. \<exists>q\<in>set pl. i\<in>acc q)"
using ACC
unfolding na_def[symmetric]
proof (induction na)
case 0
from NONTRIV obtain u v
where "(u,v)\<in>lvE \<inter> last p \<times> last p" "u\<in>last p" "v\<in>last p"
by auto
from cnode_connectedI `w\<in>last p` `u\<in>last p`
have "(w,u)\<in>(lvE \<inter> last p \<times> last p)\<^sup>*"
by auto
also note `(u,v)\<in>lvE \<inter> last p \<times> last p`
also (rtrancl_into_trancl1) from cnode_connectedI `v\<in>last p` `w\<in>last p`
have "(v,w)\<in>(lvE \<inter> last p \<times> last p)\<^sup>*"
by auto
finally obtain pl where "pl\<noteq>[]" "path (lvE \<inter> last p \<times> last p) w pl w"
by (rule trancl_is_path)
thus ?case by auto
next
case (Suc n)
from Suc.prems have "\<forall>i<n. \<exists>q\<in>last p. i\<in>acc q" by auto
with Suc.IH obtain pl where IH:
"pl\<noteq>[]"
"path (lvE \<inter> last p \<times> last p) w pl w"
"\<forall>i<n. \<exists>q\<in>set pl. i\<in>acc q"
by blast
from Suc.prems obtain v where "v\<in>last p" and "n\<in>acc v" by auto
from cnode_connectedI `w\<in>last p` `v\<in>last p`
have "(w,v)\<in>(lvE \<inter> last p \<times> last p)\<^sup>*" by auto
then obtain pl1 where P1: "path (lvE \<inter> last p \<times> last p) w pl1 v"
by (rule rtrancl_is_path)
also from cnode_connectedI `w\<in>last p` `v\<in>last p`
have "(v,w)\<in>(lvE \<inter> last p \<times> last p)\<^sup>*" by auto
then obtain pl2 where P2: "path (lvE \<inter> last p \<times> last p) v pl2 w"
by (rule rtrancl_is_path)
also (path_conc) note IH(2)
finally (path_conc) have
P: "path (lvE \<inter> last p \<times> last p) w (pl1@pl2@pl) w"
by simp
moreover from IH(1) have "pl1@pl2@pl \<noteq> []" by simp
moreover have "\<forall>i'<n. \<exists>q\<in>set (pl1@pl2@pl). i'\<in>acc q" using IH(3) by auto
moreover have "v\<in>set (pl1@pl2@pl)" using P1 P2 P IH(1)
apply (cases pl2, simp_all add: path_cons_conv path_conc_conv)
apply (cases pl, simp_all add: path_cons_conv)
apply (cases pl1, simp_all add: path_cons_conv)
done
with `n\<in>acc v` have "\<exists>q\<in>set (pl1@pl2@pl). n\<in>acc q" by auto
ultimately show ?case
apply (intro exI conjI)
apply assumption+
apply (auto elim: less_SucE)
done
qed
}
then obtain pl where "pl\<noteq>[]" "path (lvE \<inter> last p\<times>last p) w pl w"
"\<forall>i<num_acc. \<exists>q\<in>set pl. i\<in>acc q" by blast
hence "path E w pl w" and L_SS: "set pl \<subseteq> last p"
apply -
apply (frule path_mono[of _ E, rotated])
using lvE_ss_E
apply auto [2]
apply (drule path_nodes_edges)
apply (drule order_trans[OF _ image_Int_subset])
apply auto []
done
have LASSO: "is_lasso_prpl (pr,pl)"
unfolding is_lasso_prpl_def is_lasso_prpl_pre_def
by (simp,intro exI conjI) fact+
from p_sc have "last p \<times> last p \<subseteq> (lvE \<inter> last p \<times> last p)\<^sup>*" by auto
with lvE_ss_E have VL_CLOSED: "last p \<times> last p \<subseteq> (E \<inter> last p \<times> last p)\<^sup>*"
apply (erule_tac order_trans)
apply (rule rtrancl_mono)
by blast
have NONTRIV': "last p \<times> last p \<inter> E \<noteq> {}"
by (metis Int_commute NONTRIV disjoint_mono lvE_ss_E subset_refl)
from order_trans[OF path_touched touched_reachable]
have LP_REACH: "last p \<subseteq> E\<^sup>*``V0"
and BLP_REACH: "\<Union>set (butlast p) \<subseteq> E\<^sup>*``V0"
apply -
apply (cases p rule: rev_cases)
apply simp
apply auto []
apply (cases p rule: rev_cases)
apply simp
apply auto []
done
show ?thesis
apply (simp add: fgl_invar_part_def)
apply unfold_locales
apply simp
using LASSO R_SS L_SS VL_CLOSED NONTRIV' LP_REACH BLP_REACH
unfolding ce_correct_def
apply simp
apply blast
done
qed
lemma fgl_invar_collapse_ce:
fixes u v
assumes INV: "fgl_invar v0 D0 (None,p,D,pE)"
defines "pE' \<equiv> pE - {(u,v)}"
assumes CFMT: "(p',D',pE'') = collapse v (p,D,pE')"
assumes INV': "invar v0 D0 (p',D',pE'')"
assumes NE[simp]: "p\<noteq>[]"
assumes E: "(u,v)\<in>pE" and "u\<in>last p"
assumes BACK: "v\<in>\<Union>set p"
assumes ACC: "\<forall>i<num_acc. \<exists>q\<in>last p'. i\<in>acc q"
defines i_def: "i \<equiv> idx_of p v"
shows "fgl_invar_part (
Some (\<Union>set (butlast p'), last p'),
collapse v (p,D,pE'))"
proof -
from CFMT have p'_def: "p' = collapse_aux p i" and [simp]: "D'=D" "pE''=pE'"
by (simp_all add: collapse_def i_def)
from INV interpret fgl_invar_loc G v0 D0 None p D pE
by (simp add: fgl_invar_def)
from idx_of_props[OF BACK] have "i<length p" and "v\<in>p!i"
by (simp_all add: i_def)
have "u\<in>last p'"
using `u\<in>last p` `i<length p`
unfolding p'_def collapse_aux_def
apply (simp add: last_drop last_snoc)
by (metis Misc.last_in_set drop_eq_Nil last_drop not_le)
moreover have "v\<in>last p'"
using `v\<in>p!i` `i<length p`
unfolding p'_def collapse_aux_def
by (metis UnionI append_Nil Cons_nth_drop_Suc in_set_conv_decomp last_snoc)
ultimately have "vE p' D pE' \<inter> last p' \<times> last p' \<noteq> {}"
unfolding p'_def pE'_def by (auto simp: E)
have "p'\<noteq>[]" by (simp add: p'_def collapse_aux_def)
have [simp]: "collapse v (p,D,pE') = (p',D,pE')"
unfolding collapse_def p'_def i_def
by simp
show ?thesis
apply simp
apply (rule fgl_invar_collapse_ce_aux)
using INV' apply simp
apply fact+
done
qed
lemma fgl_invar_collapse_nce:
fixes u v
assumes INV: "fgl_invar v0 D0 (None,p,D,pE)"
defines "pE' \<equiv> pE - {(u,v)}"
assumes CFMT: "(p',D',pE'') = collapse v (p,D,pE')"
assumes INV': "invar v0 D0 (p',D',pE'')"
assumes NE[simp]: "p\<noteq>[]"
assumes E: "(u,v)\<in>pE" and "u\<in>last p"
assumes BACK: "v\<in>\<Union>set p"
assumes NACC: "j<num_acc" "\<forall>q\<in>last p'. j\<notin>acc q"
defines "i \<equiv> idx_of p v"
shows "fgl_invar_part (None, collapse v (p,D,pE'))"
proof -
from CFMT have p'_def: "p' = collapse_aux p i" and [simp]: "D'=D" "pE''=pE'"
by (simp_all add: collapse_def i_def)
have [simp]: "collapse v (p,D,pE') = (p',D,pE')"
by (simp add: collapse_def p'_def i_def)
from INV interpret fgl_invar_loc G v0 D0 None p D pE
by (simp add: fgl_invar_def)
from INV' interpret inv': invar_loc G v0 D0 p' D pE' by (simp add: invar_def)
def vE' \<equiv> "vE p' D pE'"
have vE'_alt: "vE' = insert (u,v) lvE"
by (simp add: vE'_def p'_def pE'_def E)
from idx_of_props[OF BACK] have "i<length p" and "v\<in>p!i"
by (simp_all add: i_def)
have "u\<in>last p'"
using `u\<in>last p` `i<length p`
unfolding p'_def collapse_aux_def
apply (simp add: last_drop last_snoc)
by (metis Misc.last_in_set drop_eq_Nil last_drop leD)
moreover have "v\<in>last p'"
using `v\<in>p!i` `i<length p`
unfolding p'_def collapse_aux_def
by (metis UnionI append_Nil Cons_nth_drop_Suc in_set_conv_decomp last_snoc)
ultimately have "vE' \<inter> last p' \<times> last p' \<noteq> {}"
unfolding vE'_alt by (auto)
have "p'\<noteq>[]" by (simp add: p'_def collapse_aux_def)
{
txt {*
We show that no visited strongly connected component contains states
from all acceptance sets. *}
fix w pl
txt {* For this, we chose a non-trivial loop inside the visited edges *}
assume P: "path vE' w pl w" and NT: "pl\<noteq>[]"
txt {* And show that there is one acceptance set disjoint with the nodes
of the loop *}
have "\<exists>i<num_acc. \<forall>q\<in>set pl. i\<notin>acc q"
proof cases
assume "set pl \<inter> last p' = {}"
-- "Case: The loop is outside the last Cnode"
with path_restrict[OF P] `u\<in>last p'` `v\<in>last p'` have "path lvE w pl w"
apply -
apply (drule path_mono[of _ lvE, rotated])
unfolding vE'_alt
by auto
with no_acc NT show ?thesis by auto
next
assume "set pl \<inter> last p' \<noteq> {}"
-- "Case: The loop touches the last Cnode"
txt {* Then, the loop must be completely inside the last CNode *}
from inv'.loop_in_lastnode[folded vE'_def, OF P `p'\<noteq>[]` this]
have "w\<in>last p'" "set pl \<subseteq> last p'" .
with NACC show ?thesis by blast
qed
} note AUX_no_acc = this
show ?thesis
apply (simp add: fgl_invar_part_def)
apply unfold_locales
using AUX_no_acc[unfolded vE'_def] apply auto []
apply simp
done
qed
lemma collapse_ne: "([],D',pE') \<noteq> collapse v (p,D,pE)"
by (simp add: collapse_def collapse_aux_def Let_def)
lemma fgl_invar_push:
assumes INV: "fgl_invar v0 D0 (None,p,D,pE)"
assumes BRK[simp]: "brk=None"
assumes NE[simp]: "p\<noteq>[]"
assumes E: "(u,v)\<in>pE" and UIL: "u\<in>last p"
assumes VNE: "v\<notin>\<Union>set p" "v\<notin>D"
assumes INV': "invar v0 D0 (push v (p,D,pE - {(u,v)}))"
shows "fgl_invar_part (None, push v (p,D,pE - {(u,v)}))"
proof -
from INV interpret fgl_invar_loc G v0 D0 None p D pE
by (simp add: fgl_invar_def)
def pE'\<equiv>"(pE - {(u,v)} \<union> E\<inter>{v}\<times>UNIV)"
have [simp]: "push v (p,D,pE - {(u,v)}) = (p@[{v}],D,pE')"
by (simp add: push_def pE'_def)
from INV' interpret inv': invar_loc G v0 D0 "(p@[{v}])" D "pE'"
by (simp add: invar_def)
note defs_fold = vE_push[OF E UIL VNE, folded pE'_def]
{
txt {* We show that there still is no loop that contains all accepting
nodes. For this, we choose some loop. *}
fix w pl
assume P: "path (insert (u,v) lvE) w pl w" and [simp]: "pl\<noteq>[]"
have "\<exists>i<num_acc. \<forall>q\<in>set pl. i\<notin>acc q"
proof cases
assume "v\<in>set pl" -- "Case: The newly pushed last cnode is on the loop"
txt {* Then the loop is entirely on the last cnode*}
with inv'.loop_in_lastnode[unfolded defs_fold, OF P]
have [simp]: "w=v" and SPL: "set pl = {v}" by auto
txt {* However, we then either have that the last cnode is contained in
the last but one cnode, or that there is a visited edge inside the
last cnode.*}
from P SPL have "u=v \<or> (v,v)\<in>lvE"
apply (cases pl) apply (auto simp: path_cons_conv)
apply (case_tac list)
apply (auto simp: path_cons_conv)
done
txt {* Both leads to a contradiction *}
hence False proof
assume "u=v" -- {* This is impossible, as @{text "u"} was on the
original path, but @{text "v"} was not*}
with UIL VNE show False by auto
next
assume "(v,v)\<in>lvE" -- {* This is impossible, as all visited edges are
from touched nodes, but @{text "v"} was untouched *}
with vE_touched VNE show False unfolding touched_def by auto
qed
thus ?thesis ..
next
assume A: "v\<notin>set pl"
-- "Case: The newly pushed last cnode is not on the loop"
txt {* Then, the path lays inside the old visited edges *}
have "path lvE w pl w"
proof -
have "w\<in>set pl" using P by (cases pl) (auto simp: path_cons_conv)
with A show ?thesis using path_restrict[OF P]
apply -
apply (drule path_mono[of _ lvE, rotated])
apply (cases pl, auto) []
apply assumption
done
qed
txt {* And thus, the proposition follows from the invariant on the old
state *}
with no_acc show ?thesis
apply simp
using `pl\<noteq>[]`
by blast
qed
} note AUX_no_acc = this
show ?thesis
unfolding fgl_invar_part_def
apply simp
apply unfold_locales
unfolding defs_fold
using AUX_no_acc apply auto []
apply simp
done
qed
lemma fgl_invar_skip:
assumes INV: "fgl_invar v0 D0 (None,p,D,pE)"
assumes BRK[simp]: "brk=None"
assumes NE[simp]: "p\<noteq>[]"
assumes E: "(u,v)\<in>pE" and UIL: "u\<in>last p"
assumes VID: "v\<in>D"
assumes INV': "invar v0 D0 (p, D, (pE - {(u,v)}))"
shows "fgl_invar_part (None, p, D, (pE - {(u,v)}))"
proof -
from INV interpret fgl_invar_loc G v0 D0 None p D pE
by (simp add: fgl_invar_def)
from INV' interpret inv': invar_loc G v0 D0 p D "(pE - {(u,v)})"
by (simp add: invar_def)
{
txt {* We show that there still is no loop that contains all accepting
nodes. For this, we choose some loop. *}
fix w pl
assume P: "path (insert (u,v) lvE) w pl w" and [simp]: "pl\<noteq>[]"
from P have "\<exists>i<num_acc. \<forall>q\<in>set pl. i\<notin>acc q"
proof (cases rule: path_edge_rev_cases)
case no_use -- "Case: The loop does not use the new edge"
txt {* The proposition follows from the invariant for the old state *}
with no_acc show ?thesis
apply simp
using `pl\<noteq>[]`
by blast
next
case (split p1 p2) -- "Case: The loop uses the new edge"
txt {* As done is closed under transitions, the nodes of the edge have
already been visited *}
from split(2) D_closed_vE_rtrancl
have WID: "w\<in>D"
using VID by (auto dest!: path_is_rtrancl)
from split(1) WID D_closed_vE_rtrancl have "u\<in>D"
apply (cases rule: path_edge_cases)
apply (auto dest!: path_is_rtrancl)
done
txt {* Which is a contradition to the assumptions *}
with UIL p_not_D have False by (cases p rule: rev_cases) auto
thus ?thesis ..
qed
} note AUX_no_acc = this
show ?thesis
apply (simp add: fgl_invar_part_def)
apply unfold_locales
unfolding vE_remove[OF NE E]
using AUX_no_acc apply auto []
apply simp
done
qed
lemma fgl_outer_invar_initial:
"outer_invar V0 {} \<Longrightarrow> fgl_outer_invar_ext V0 (None, {})"
unfolding fgl_outer_invar_ext_def
apply (simp add: no_acc_over_def)
done
lemma fgl_outer_invar_brk:
assumes INV: "fgl_invar v0 D0 (Some (Vr,Vl),p,D,pE)"
shows "fgl_outer_invar_ext anyIt (Some (Vr,Vl), anyD)"
proof -
from INV interpret fgl_invar_loc G v0 D0 "Some (Vr,Vl)" p D pE
by (simp add: fgl_invar_def)
from acc show ?thesis by (simp add: fgl_outer_invar_ext_def)
qed
lemma fgl_outer_invar_newnode_nobrk:
assumes A: "v0\<notin>D0" "v0\<in>it"
assumes OINV: "fgl_outer_invar it (None,D0)"
assumes INV: "fgl_invar v0 D0 (None,[],D',pE)"
shows "fgl_outer_invar_ext (it-{v0}) (None,D')"
proof -
from OINV interpret outer_invar_loc G it D0
unfolding fgl_outer_invar_def outer_invar_def by simp
from INV interpret inv!: fgl_invar_loc G v0 D0 None "[]" D' pE
unfolding fgl_invar_def by simp
from inv.pE_fin have [simp]: "pE = {}" by simp
{ fix v pl
assume A: "v\<in>D'" "path E v pl v"
have "path (E \<inter> D' \<times> UNIV) v pl v"
apply (rule path_mono[OF _ path_restrict_closed[OF inv.D_closed A]])
by auto
} note AUX1=this
show ?thesis
unfolding fgl_outer_invar_ext_def
apply simp
using inv.no_acc AUX1
apply (auto simp add: vE_def touched_def no_acc_over_def) []
done
qed
lemma fgl_outer_invar_newnode:
assumes A: "v0\<notin>D0" "v0\<in>it"
assumes OINV: "fgl_outer_invar it (None,D0)"
assumes INV: "fgl_invar v0 D0 (brk,p,D',pE)"
assumes CASES: "(\<exists>Vr Vl. brk = Some (Vr, Vl)) \<or> p = []"
shows "fgl_outer_invar_ext (it-{v0}) (brk,D')"
using CASES
apply (elim disjE1)
using fgl_outer_invar_brk[of v0 D0 _ _ p D' pE] INV
apply -
apply (auto, assumption) []
using fgl_outer_invar_newnode_nobrk[OF A] OINV INV apply auto []
done
lemma fgl_outer_invar_Dnode:
assumes "fgl_outer_invar it (None, D)" "v\<in>D"
shows "fgl_outer_invar_ext (it - {v}) (None, D)"
using assms
by (auto simp: fgl_outer_invar_def fgl_outer_invar_ext_def)
lemma fgl_fin_no_lasso:
assumes A: "fgl_outer_invar {} (None, D)"
assumes B: "is_lasso_prpl prpl"
shows "False"
proof -
obtain "pr" pl where [simp]: "prpl = (pr,pl)" by (cases prpl)
from A have NA: "no_acc_over D"
by (simp add: fgl_outer_invar_def fgl_outer_invar_ext_def)
from A have "outer_invar {} D" by (simp add: fgl_outer_invar_def)
with fin_outer_D_is_reachable have [simp]: "D=E\<^sup>*``V0" by simp
from NA B show False
apply (simp add: no_acc_over_def is_lasso_prpl_def is_lasso_prpl_pre_def)
apply clarsimp
apply (blast dest: path_is_rtrancl)
done
qed
lemma fgl_fin_lasso:
assumes A: "fgl_outer_invar it (Some (Vr,Vl), D)"
shows "ce_correct Vr Vl"
using A by (simp add: fgl_outer_invar_def fgl_outer_invar_ext_def)
lemmas fgl_invar_preserve =
fgl_invar_initial fgl_invar_push fgl_invar_pop
fgl_invar_collapse_ce fgl_invar_collapse_nce fgl_invar_skip
fgl_outer_invar_newnode fgl_outer_invar_Dnode
invar_initial outer_invar_initial fgl_invar_initial fgl_outer_invar_initial
fgl_fin_no_lasso fgl_fin_lasso
end
section {* Main Correctness Proof *}
context igb_graph
begin
lemma outer_invar_from_fgl_invarI:
"fgl_outer_invar it (None,D) \<Longrightarrow> outer_invar it D"
unfolding fgl_outer_invar_def outer_invar_def
by (simp split: prod.splits)
lemma invar_from_fgl_invarI: "fgl_invar v0 D0 (B,PDPE) \<Longrightarrow> invar v0 D0 PDPE"
unfolding fgl_invar_def invar_def
apply (simp split: prod.splits)
unfolding fgl_invar_loc_def by simp
theorem find_ce_correct: "find_ce \<le> find_ce_spec"
proof -
note [simp del] = Union_iff
show ?thesis
unfolding find_ce_def find_ce_spec_def select_edge_def select_def
apply (refine_rcg
WHILEIT_rule[where R="inv_image (abs_wf_rel v0) snd" for v0]
refine_vcg
)
using [[goals_limit = 5]]
apply (vc_solve
rec: fgl_invarI fgl_outer_invarI
intro: invar_from_fgl_invarI outer_invar_from_fgl_invarI
dest!: sym[of "collapse a b" for a b]
simp: collapse_ne
simp: pE_fin'[OF invar_from_fgl_invarI]
solve: invar_preserve
solve: fgl_invar_preserve)
done
qed
end
section "Emptiness Check"
text {* Using the lasso-finding algorithm, we can define an emptiness check *}
context igb_graph
begin
definition "abs_is_empty \<equiv> do {
ce \<leftarrow> find_ce;
RETURN (ce = None)
}"
theorem abs_is_empty_correct:
"abs_is_empty \<le> SPEC (\<lambda>res. res \<longleftrightarrow> (\<forall>r. \<not>is_acc_run r))"
unfolding abs_is_empty_def
apply (refine_rcg refine_vcg
order_trans[OF find_ce_correct, unfolded find_ce_spec_def])
unfolding ce_correct_def
using lasso_accepted accepted_lasso
apply (clarsimp split: option.splits)
apply (metis is_lasso_prpl_of_lasso surj_pair)
by (metis is_lasso_prpl_conv)
definition "abs_is_empty_ce \<equiv> do {
ce \<leftarrow> find_ce;
case ce of
None \<Rightarrow> RETURN None
| Some (Vr,Vl) \<Rightarrow> do {
ASSERT (\<exists>pr pl. set pr \<subseteq> Vr \<and> set pl \<subseteq> Vl \<and> Vl \<times> Vl \<subseteq> (E \<inter> Vl\<times>Vl)\<^sup>*
\<and> is_lasso_prpl (pr,pl));
(pr,pl) \<leftarrow> SPEC (\<lambda>(pr,pl).
set pr \<subseteq> Vr
\<and> set pl \<subseteq> Vl
\<and> Vl \<times> Vl \<subseteq> (E \<inter> Vl\<times>Vl)\<^sup>*
\<and> is_lasso_prpl (pr,pl));
RETURN (Some (pr,pl))
}
}"
theorem abs_is_empty_ce_correct: "abs_is_empty_ce \<le> SPEC (\<lambda>res. case res of
None \<Rightarrow> (\<forall>r. \<not>is_acc_run r)
| Some (pr,pl) \<Rightarrow> is_acc_run (pr\<frown>pl\<^sup>\<omega>)
)"
unfolding abs_is_empty_ce_def
apply (refine_rcg refine_vcg
order_trans[OF find_ce_correct, unfolded find_ce_spec_def])
apply (clarsimp_all simp: ce_correct_def)
using accepted_lasso apply (metis is_lasso_prpl_of_lasso surj_pair)
apply blast
apply (simp add: lasso_prpl_acc_run)
done
end
section {* Refinement *}
text {*
In this section, we refine the lasso finding algorithm to use efficient
data structures. First, we explicitely keep track of the set of acceptance
classes for every c-node on the path. Second, we use Gabow's data structure
to represent the path.
*}
subsection {* Addition of Explicit Accepting Sets *}
text {* In a first step, we explicitely keep track of the current set of
acceptance classes for every c-node on the path. *}
type_synonym 'a abs_gstate = "nat set list \<times> 'a abs_state"
type_synonym 'a ce = "('a set \<times> 'a set) option"
type_synonym 'a abs_gostate = "'a ce \<times> 'a set"
context igb_graph
begin
definition gstate_invar :: "'Q abs_gstate \<Rightarrow> bool" where
"gstate_invar \<equiv> \<lambda>(a,p,D,pE). a = map (\<lambda>V. \<Union>(acc`V)) p"
definition "gstate_rel \<equiv> br snd gstate_invar"
lemma gstate_rel_sv[relator_props,simp,intro!]: "single_valued gstate_rel"
by (simp add: gstate_rel_def)
definition (in -) gcollapse_aux
:: "nat set list \<Rightarrow> 'a set list \<Rightarrow> nat \<Rightarrow> nat set list \<times> 'a set list"
where "gcollapse_aux a p i \<equiv>
(take i a @ [\<Union>set (drop i a)],take i p @ [\<Union>set (drop i p)])"
definition (in -) gcollapse :: "'a \<Rightarrow> 'a abs_gstate \<Rightarrow> 'a abs_gstate"
where "gcollapse v APDPE \<equiv>
let
(a,p,D,pE)=APDPE;
i=idx_of p v;
(a,p) = gcollapse_aux a p i
in (a,p,D,pE)"
definition "gpush v s \<equiv>
let
(a,s) = s
in
(a@[acc v],push v s)"
definition "gpop s \<equiv>
let (a,s) = s in (butlast a,pop s)"
definition ginitial :: "'Q \<Rightarrow> 'Q abs_gostate \<Rightarrow> 'Q abs_gstate"
where "ginitial v0 s0 \<equiv> ([acc v0], initial v0 (snd s0))"
definition goinitial :: "'Q abs_gostate" where "goinitial \<equiv> (None,{})"
definition go_is_no_brk :: "'Q abs_gostate \<Rightarrow> bool"
where "go_is_no_brk s \<equiv> fst s = None"
definition goD :: "'Q abs_gostate \<Rightarrow> 'Q set" where "goD s \<equiv> snd s"
definition goBrk :: "'Q abs_gostate \<Rightarrow> 'Q ce" where "goBrk s \<equiv> fst s"
definition gto_outer :: "'Q ce \<Rightarrow> 'Q abs_gstate \<Rightarrow> 'Q abs_gostate"
where "gto_outer brk s \<equiv> let (A,p,D,pE)=s in (brk,D)"
definition "gselect_edge s \<equiv> do {
let (a,s)=s;
(r,s)\<leftarrow>select_edge s;
RETURN (r,a,s)
}"
definition gfind_ce :: "('Q set \<times> 'Q set) option nres" where
"gfind_ce \<equiv> do {
let os = goinitial;
os\<leftarrow>FOREACHci fgl_outer_invar V0 (go_is_no_brk) (\<lambda>v0 s0. do {
if v0\<notin>goD s0 then do {
let s = (None,ginitial v0 s0);
(brk,a,p,D,pE) \<leftarrow> WHILEIT (\<lambda>(brk,a,s). fgl_invar v0 (goD s0) (brk,s))
(\<lambda>(brk,a,p,D,pE). brk=None \<and> p \<noteq> []) (\<lambda>(_,a,p,D,pE).
do {
(* Select edge from end of path *)
(vo,(a,p,D,pE)) \<leftarrow> gselect_edge (a,p,D,pE);
ASSERT (p\<noteq>[]);
case vo of
Some v \<Rightarrow> do {
if v \<in> \<Union>set p then do {
(* Collapse *)
let (a,p,D,pE) = gcollapse v (a,p,D,pE);
ASSERT (p\<noteq>[]);
ASSERT (a\<noteq>[]);
if last a = {0..<num_acc} then
RETURN (Some (\<Union>set (butlast p),last p),a,p,D,pE)
else
RETURN (None,a,p,D,pE)
} else if v\<notin>D then do {
(* Edge to new node. Append to path *)
RETURN (None,gpush v (a,p,D,pE))
} else RETURN (None,a,p,D,pE)
}
| None \<Rightarrow> do {
(* No more outgoing edges from current node on path *)
ASSERT (pE \<inter> last p \<times> UNIV = {});
RETURN (None,gpop (a,p,D,pE))
}
}) s;
ASSERT (brk=None \<longrightarrow> (p=[] \<and> pE={}));
RETURN (gto_outer brk (a,p,D,pE))
} else RETURN s0
}) os;
RETURN (goBrk os)
}"
lemma gcollapse_refine:
"\<lbrakk>(v',v)\<in>Id; (s',s)\<in>gstate_rel\<rbrakk>
\<Longrightarrow> (gcollapse v' s',collapse v s)\<in>gstate_rel"
unfolding gcollapse_def collapse_def collapse_aux_def gcollapse_aux_def
apply (simp add: gstate_rel_def br_def Let_def)
unfolding gstate_invar_def[abs_def]
apply (auto split: prod.splits simp: take_map drop_map)
done
lemma gpop_refine:
"\<lbrakk>(s',s)\<in>gstate_rel\<rbrakk> \<Longrightarrow> (gpop s',pop s)\<in>gstate_rel"
unfolding gpop_def pop_def
apply (simp add: gstate_rel_def br_def)
unfolding gstate_invar_def[abs_def]
apply (auto split: prod.splits simp: map_butlast)
done
lemma ginitial_refine:
"(ginitial x (None, b), initial x b) \<in> gstate_rel"
unfolding ginitial_def gstate_rel_def br_def gstate_invar_def initial_def
by auto
lemma oinitial_b_refine: "((None,{}),(None,{}))\<in>Id\<times>\<^sub>rId" by simp
lemma gselect_edge_refine: "\<lbrakk>(s',s)\<in>gstate_rel\<rbrakk> \<Longrightarrow> gselect_edge s'
\<le>\<Down>(\<langle>Id\<rangle>option_rel \<times>\<^sub>r gstate_rel) (select_edge s)"
unfolding gselect_edge_def select_edge_def
apply (simp add: pw_le_iff refine_pw_simps prod_rel_sv
split: prod.splits option.splits)
apply (auto simp: gstate_rel_def br_def gstate_invar_def)
done
lemma last_acc_impl:
assumes "p\<noteq>[]"
assumes "((a',p',D',pE'),(p,D,pE))\<in>gstate_rel"
shows "(last a' = {0..<num_acc}) = (\<forall>i<num_acc. \<exists>q\<in>last p. i\<in>acc q)"
using assms acc_bound unfolding gstate_rel_def br_def gstate_invar_def
by (auto simp: last_map)
lemma fglr_aux1:
assumes V: "(v',v)\<in>Id" and S: "(s',s)\<in>gstate_rel"
and P: "\<And>a' p' D' pE' p D pE. ((a',p',D',pE'),(p,D,pE))\<in>gstate_rel
\<Longrightarrow> f' a' p' D' pE' \<le>\<Down>R (f p D pE)"
shows "(let (a',p',D',pE') = gcollapse v' s' in f' a' p' D' pE')
\<le> \<Down>R (let (p,D,pE) = collapse v s in f p D pE)"
apply (auto split: prod.splits)
apply (rule P)
using gcollapse_refine[OF V S]
apply simp
done
lemma gstate_invar_empty:
"gstate_invar (a,[],D,pE) \<Longrightarrow> a=[]"
"gstate_invar ([],p,D,pE) \<Longrightarrow> p=[]"
by (auto simp add: gstate_invar_def)
lemma find_ce_refine: "gfind_ce \<le>\<Down>Id find_ce"
unfolding gfind_ce_def find_ce_def
unfolding goinitial_def go_is_no_brk_def[abs_def] goD_def goBrk_def
gto_outer_def
using [[goals_limit = 1]]
apply (refine_rcg
gselect_edge_refine prod_relI[OF IdI gpop_refine]
prod_relI[OF IdI gpush_refine]
fglr_aux1 last_acc_impl oinitial_b_refine
inj_on_id
)
apply (simp_all add: ginitial_refine)
apply (vc_solve (nopre)
solve: asm_rl
simp: gstate_rel_def br_def gstate_invar_empty)
done
end
subsection {* Refinement to Gabow's Data Structure *}
subsubsection {* Preliminaries *}
definition Un_set_drop_impl :: "nat \<Rightarrow> 'a set list \<Rightarrow> 'a set nres"
-- {* Executable version of @{text "\<Union>set (drop i A)"}, using indexing to
access @{text "A"} *}
where "Un_set_drop_impl i A \<equiv>
do {
(_,res) \<leftarrow> WHILET (\<lambda>(i,res). i < length A) (\<lambda>(i,res). do {
ASSERT (i<length A);
let res = A!i \<union> res;
let i = i + 1;
RETURN (i,res)
}) (i,{});
RETURN res
}"
lemma Un_set_drop_impl_correct:
"Un_set_drop_impl i A \<le> SPEC (\<lambda>r. r=\<Union>set (drop i A))"
unfolding Un_set_drop_impl_def
apply (refine_rcg
WHILET_rule[where I="\<lambda>(i',res). res=\<Union>set ((drop i (take i' A))) \<and> i\<le>i'"
and R="measure (\<lambda>(i',_). length A - i')"]
refine_vcg)
apply (auto simp: take_Suc_conv_app_nth)
done
schematic_lemma Un_set_drop_code_aux:
assumes [relator_props]: "single_valued R"
assumes [relator_props]: "single_valued (\<langle>R\<rangle>Rs)"
assumes [autoref_rules]: "(es_impl,{})\<in>\<langle>R\<rangle>Rs"
assumes [autoref_rules]: "(un_impl,op \<union>)\<in>\<langle>R\<rangle>Rs\<rightarrow>\<langle>R\<rangle>Rs\<rightarrow>\<langle>R\<rangle>Rs"
shows "(?c,Un_set_drop_impl)\<in>nat_rel \<rightarrow> \<langle>\<langle>R\<rangle>Rs\<rangle>as_rel \<rightarrow> \<langle>\<langle>R\<rangle>Rs\<rangle>nres_rel"
unfolding Un_set_drop_impl_def[abs_def]
apply (autoref (trace, keep_goal))
done
concrete_definition Un_set_drop_code uses Un_set_drop_code_aux
schematic_lemma Un_set_drop_tr_aux:
"RETURN ?c \<le> Un_set_drop_code es_impl un_impl i A"
unfolding Un_set_drop_code_def
by refine_transfer
concrete_definition Un_set_drop_tr for es_impl un_impl i A
uses Un_set_drop_tr_aux
lemma Un_set_drop_autoref[autoref_rules]:
assumes "GEN_OP es_impl {} (\<langle>R\<rangle>Rs)"
assumes "GEN_OP un_impl op \<union> (\<langle>R\<rangle>Rs\<rightarrow>\<langle>R\<rangle>Rs\<rightarrow>\<langle>R\<rangle>Rs)"
assumes "PREFER single_valued R"
assumes "PREFER single_valued (\<langle>R\<rangle>Rs)"
shows "(\<lambda>i A. RETURN (Un_set_drop_tr es_impl un_impl i A),Un_set_drop_impl)
\<in>nat_rel \<rightarrow> \<langle>\<langle>R\<rangle>Rs\<rangle>as_rel \<rightarrow> \<langle>\<langle>R\<rangle>Rs\<rangle>nres_rel"
apply (intro fun_relI nres_relI)
apply (rule order_trans[OF Un_set_drop_tr.refine])
thm Un_set_drop_code.refine
using Un_set_drop_code.refine[of R Rs es_impl un_impl,
param_fo, THEN nres_relD]
using assms
by simp
subsubsection {* Actual Refinement *}
type_synonym 'Q gGS = "nat set list \<times> 'Q GS"
type_synonym 'Q goGS = "'Q ce \<times> 'Q oGS"
context igb_graph
begin
definition gGS_invar :: "'Q gGS \<Rightarrow> bool"
where "gGS_invar s \<equiv>
let (a,S,B,I,P) = s in
GS_invar (S,B,I,P)
\<and> length a = length B
\<and> \<Union>set a \<subseteq> {0..<num_acc}
"
definition gGS_\<alpha> :: "'Q gGS \<Rightarrow> 'Q abs_gstate"
where "gGS_\<alpha> s \<equiv> let (a,s)=s in (a,GS.\<alpha> s)"
definition "gGS_rel \<equiv> br gGS_\<alpha> gGS_invar"
lemma gGS_rel_sv[relator_props,intro!,simp]: "single_valued gGS_rel"
unfolding gGS_rel_def by auto
definition goGS_invar :: "'Q goGS \<Rightarrow> bool" where
"goGS_invar s \<equiv> let (brk,ogs)=s in brk=None \<longrightarrow> oGS_invar ogs"
definition "goGS_\<alpha> s \<equiv> let (brk,ogs)=s in (brk,oGS_\<alpha> ogs)"
definition "goGS_rel \<equiv> br goGS_\<alpha> goGS_invar"
lemma goGS_rel_sv[relator_props,intro!,simp]: "single_valued goGS_rel"
unfolding goGS_rel_def by auto
end
context igb_graph
begin
lemma gGS_relE:
assumes "(s',(a,p,D,pE))\<in>gGS_rel"
obtains S' B' I' P' where "s'=(a,S',B',I',P')"
and "((S',B',I',P'),(p,D,pE))\<in>GS_rel"
and "length a = length B'"
and "\<Union>set a \<subseteq> {0..<num_acc}"
using assms
apply (cases s')
apply (simp add: gGS_rel_def br_def gGS_\<alpha>_def GS.\<alpha>_def)
apply (rule that)
apply (simp only:)
apply (auto simp: GS_rel_def br_def gGS_invar_def GS.\<alpha>_def)
done
definition goinitial_impl :: "'Q goGS"
where "goinitial_impl \<equiv> (None,Map.empty)"
lemma goinitial_impl_refine: "(goinitial_impl,goinitial)\<in>goGS_rel"
by (auto
simp: goinitial_impl_def goinitial_def goGS_rel_def br_def
simp: goGS_\<alpha>_def goGS_invar_def oGS_\<alpha>_def oGS_invar_def)
definition gto_outer_impl :: "'Q ce \<Rightarrow> 'Q gGS \<Rightarrow> 'Q goGS"
where "gto_outer_impl brk s \<equiv> let (A,S,B,I,P)=s in (brk,I)"
lemma gto_outer_refine:
assumes A: "brk = None \<longrightarrow> (p=[] \<and> pE={})"
assumes B: "(s, (A,p, D, pE)) \<in> gGS_rel"
assumes C: "(brk',brk)\<in>Id"
shows "(gto_outer_impl brk' s,gto_outer brk (A,p,D,pE))\<in>goGS_rel"
proof (cases s)
fix A S B I P
assume [simp]: "s=(A,S,B,I,P)"
show ?thesis
using C
apply (cases brk)
using assms I_to_outer[of S B I P D]
apply (auto
simp: goGS_rel_def br_def goGS_\<alpha>_def gto_outer_def
gto_outer_impl_def goGS_invar_def
simp: gGS_rel_def oGS_rel_def GS_rel_def gGS_\<alpha>_def gGS_invar_def
GS.\<alpha>_def) []
using B apply (auto
simp: gto_outer_def gto_outer_impl_def
simp: br_def goGS_rel_def goGS_invar_def goGS_\<alpha>_def oGS_\<alpha>_def
simp: gGS_rel_def gGS_\<alpha>_def GS.\<alpha>_def GS.D_\<alpha>_def
)
done
qed
definition "gpush_impl v s \<equiv> let (a,s)=s in (a@[acc v], push_impl v s)"
lemma gpush_impl_refine:
assumes B: "(s',(a,p,D,pE))\<in>gGS_rel"
assumes A: "(v',v)\<in>Id"
assumes PRE: "v' \<notin> \<Union>set p" "v' \<notin> D"
shows "(gpush_impl v' s', gpush v (a,p,D,pE))\<in>gGS_rel"
proof -
from B obtain S' B' I' P' where [simp]: "s'=(a,S',B',I',P')"
and OSR: "((S',B',I',P'),(p,D,pE))\<in>GS_rel" and L: "length a = length B'"
and R: "\<Union>set a \<subseteq> {0..<num_acc}"
by (rule gGS_relE)
{
fix S B I P S' B' I' P'
assume "push_impl v (S, B, I, P) = (S', B', I', P')"
hence "length B' = Suc (length B)"
by (auto simp add: push_impl_def GS.push_impl_def Let_def)
} note AUX1=this
from push_refine[OF OSR A PRE] A L acc_bound R show ?thesis
unfolding gpush_impl_def gpush_def
gGS_rel_def gGS_invar_def gGS_\<alpha>_def GS_rel_def br_def
apply (auto dest: AUX1)
done
qed
definition gpop_impl :: "'Q gGS \<Rightarrow> 'Q gGS nres"
where "gpop_impl s \<equiv> do {
let (a,s)=s;
s\<leftarrow>pop_impl s;
ASSERT (a\<noteq>[]);
let a = butlast a;
RETURN (a,s)
}"
lemma gpop_impl_refine:
assumes A: "(s',(a,p,D,pE))\<in>gGS_rel"
assumes PRE: "p \<noteq> []" "pE \<inter> last p \<times> UNIV = {}"
shows "gpop_impl s' \<le> \<Down>gGS_rel (RETURN (gpop (a,p,D,pE)))"
proof -
from A obtain S' B' I' P' where [simp]: "s'=(a,S',B',I',P')"
and OSR: "((S',B',I',P'),(p,D,pE))\<in>GS_rel" and L: "length a = length B'"
and R: "\<Union>set a \<subseteq> {0..<num_acc}"
by (rule gGS_relE)
from PRE OSR have [simp]: "a\<noteq>[]" using L
by (auto simp add: GS_rel_def br_def GS.\<alpha>_def GS.p_\<alpha>_def)
{
fix S B I P S' B' I' P'
assume "nofail (pop_impl ((S, B, I, P)::'a GS))"
"inres (pop_impl ((S, B, I, P)::'a GS)) (S', B', I', P')"
hence "length B' = length B - Suc 0"
apply (simp add: pop_impl_def GS.pop_impl_def Let_def
refine_pw_simps)
apply auto
done
} note AUX1=this
from A L show ?thesis
unfolding gpop_impl_def gpop_def gGS_rel_def gGS_\<alpha>_def br_def
apply (simp add: Let_def)
using pop_refine[OF OSR PRE]
apply (simp add: pw_le_iff refine_pw_simps split: prod.splits)
unfolding gGS_rel_def gGS_invar_def gGS_\<alpha>_def GS_rel_def GS.\<alpha>_def br_def
apply (auto dest!: AUX1 in_set_butlastD iff: Sup_le_iff)
done
qed
definition gselect_edge_impl :: "'Q gGS \<Rightarrow> ('Q option \<times> 'Q gGS) nres"
where "gselect_edge_impl s \<equiv>
do {
let (a,s)=s;
(vo,s)\<leftarrow>select_edge_impl s;
RETURN (vo,a,s)
}"
thm select_edge_refine
lemma gselect_edge_impl_refine:
assumes A: "(s', a, p, D, pE) \<in> gGS_rel"
assumes PRE: "p \<noteq> []"
shows "gselect_edge_impl s' \<le> \<Down>(Id \<times>\<^sub>r gGS_rel) (gselect_edge (a, p, D, pE))"
proof -
from A obtain S' B' I' P' where [simp]: "s'=(a,S',B',I',P')"
and OSR: "((S',B',I',P'),(p,D,pE))\<in>GS_rel" and L: "length a = length B'"
and R: "\<Union>set a \<subseteq> {0..<num_acc}"
by (rule gGS_relE)
{
fix S B I P S' B' I' P' vo
assume "nofail (select_edge_impl ((S, B, I, P)::'a GS))"
"inres (select_edge_impl ((S, B, I, P)::'a GS)) (vo, (S', B', I', P'))"
hence "length B' = length B"
apply (simp add: select_edge_impl_def GS.sel_rem_last_def refine_pw_simps
split: split_if_asm prod.splits)
apply auto
done
} note AUX1=this
show ?thesis
using select_edge_refine[OF OSR PRE]
unfolding gselect_edge_impl_def gselect_edge_def
apply (simp add: refine_pw_simps pw_le_iff prod_rel_sv)
unfolding gGS_rel_def br_def gGS_\<alpha>_def gGS_invar_def GS_rel_def GS.\<alpha>_def
apply (simp split: prod.splits)
apply clarsimp
using R
apply (auto simp: L dest: AUX1)
done
qed
term GS.idx_of_impl
thm GS_invar.idx_of_correct
definition gcollapse_impl_aux :: "'Q \<Rightarrow> 'Q gGS \<Rightarrow> 'Q gGS nres" where
"gcollapse_impl_aux v s \<equiv>
do {
let (A,s)=s;
(*ASSERT (v\<in>\<Union>set (GS.p_\<alpha> s));*)
i \<leftarrow> GS.idx_of_impl s v;
s \<leftarrow> collapse_impl v s;
ASSERT (i < length A);
us \<leftarrow> Un_set_drop_impl i A;
let A = take i A @ [us];
RETURN (A,s)
}"
term collapse
lemma gcollapse_alt:
"gcollapse v APDPE = (
let
(a,p,D,pE)=APDPE;
i=idx_of p v;
s=collapse v (p,D,pE);
us=\<Union>set (drop i a);
a = take i a @ [us]
in (a,s))"
unfolding gcollapse_def gcollapse_aux_def collapse_def collapse_aux_def
by auto
thm collapse_refine
lemma gcollapse_impl_aux_refine:
assumes A: "(s', a, p, D, pE) \<in> gGS_rel"
assumes B: "(v',v)\<in>Id"
assumes PRE: "v\<in>\<Union>set p"
shows "gcollapse_impl_aux v' s'
\<le> \<Down> gGS_rel (RETURN (gcollapse v (a, p, D, pE)))"
proof -
note [simp] = Let_def
from A obtain S' B' I' P' where [simp]: "s'=(a,S',B',I',P')"
and OSR: "((S',B',I',P'),(p,D,pE))\<in>GS_rel" and L: "length a = length B'"
and R: "\<Union>set a \<subseteq> {0..<num_acc}"
by (rule gGS_relE)
from B have [simp]: "v'=v" by simp
from OSR have [simp]: "GS.p_\<alpha> (S',B',I',P') = p"
by (simp add: GS_rel_def br_def GS.\<alpha>_def)
from OSR PRE have PRE': "v \<in> \<Union>set (GS.p_\<alpha> (S',B',I',P'))"
by (simp add: GS_rel_def br_def GS.\<alpha>_def)
from OSR have GS_invar: "GS_invar (S',B',I',P')"
by (simp add: GS_rel_def br_def)
term GS.B
{
fix s
assume "collapse v (p, D, pE) = (GS.p_\<alpha> s, GS.D_\<alpha> s, GS.pE_\<alpha> s)"
hence "length (GS.B s) = Suc (idx_of p v)"
unfolding collapse_def collapse_aux_def Let_def
apply (cases s)
apply (auto simp: GS.p_\<alpha>_def)
apply (drule arg_cong[where f=length])
using GS_invar.p_\<alpha>_disjoint_sym[OF GS_invar]
and PRE `GS.p_\<alpha> (S', B', I', P') = p` idx_of_props(1)[of p v]
by simp
} note AUX1 = this
show ?thesis
unfolding gcollapse_alt gcollapse_impl_aux_def
apply simp
apply (rule RETURN_as_SPEC_refine_sv, tagged_solver)
apply (refine_rcg
order_trans[OF GS_invar.idx_of_correct[OF GS_invar PRE']]
order_trans[OF collapse_refine[OF OSR B PRE, simplified]]
refine_vcg
)
using PRE' apply simp
apply (simp add: L)
using Un_set_drop_impl_correct acc_bound R
apply (simp add: refine_pw_simps pw_le_iff)
unfolding gGS_rel_def GS_rel_def GS.\<alpha>_def br_def gGS_\<alpha>_def gGS_invar_def
apply (clarsimp simp: L dest!: AUX1)
apply (auto dest!: AUX1 simp: L)
apply (force dest!: in_set_dropD) []
apply (force dest!: in_set_takeD) []
done
qed
definition gcollapse_impl :: "'Q \<Rightarrow> 'Q gGS \<Rightarrow> 'Q gGS nres"
where "gcollapse_impl v s \<equiv>
do {
let (A,S,B,I,P)=s;
i \<leftarrow> GS.idx_of_impl (S,B,I,P) v;
ASSERT (i+1 \<le> length B);
let B = take (i+1) B;
ASSERT (i < length A);
us\<leftarrow>Un_set_drop_impl i A;
let A = take i A @ [us];
RETURN (A,S,B,I,P)
}"
lemma gcollapse_impl_aux_opt_refine:
"gcollapse_impl v s \<le> gcollapse_impl_aux v s"
unfolding gcollapse_impl_def gcollapse_impl_aux_def collapse_impl_def
GS.collapse_impl_def
apply (simp add: refine_pw_simps pw_le_iff split: prod.splits)
apply blast
done
lemma gcollapse_impl_refine:
assumes A: "(s', a, p, D, pE) \<in> gGS_rel"
assumes B: "(v',v)\<in>Id"
assumes PRE: "v\<in>\<Union>set p"
shows "gcollapse_impl v' s'
\<le> \<Down> gGS_rel (RETURN (gcollapse v (a, p, D, pE)))"
using order_trans[OF
gcollapse_impl_aux_opt_refine
gcollapse_impl_aux_refine[OF assms]]
.
definition ginitial_impl :: "'Q \<Rightarrow> 'Q goGS \<Rightarrow> 'Q gGS"
where "ginitial_impl v0 s0 \<equiv> ([acc v0],initial_impl v0 (snd s0))"
lemma ginitial_impl_refine:
assumes A: "v0\<notin>goD s0" "go_is_no_brk s0"
assumes REL: "(s0i,s0)\<in>goGS_rel" "(v0i,v0)\<in>Id"
shows "(ginitial_impl v0i s0i,ginitial v0 s0)\<in>gGS_rel"
unfolding ginitial_impl_def ginitial_def
using REL initial_refine[OF A(1) _ REL(2), of "snd s0i"] A(2)
apply (auto
simp: gGS_rel_def br_def gGS_\<alpha>_def gGS_invar_def goGS_rel_def goGS_\<alpha>_def
simp: go_is_no_brk_def goD_def oGS_rel_def GS_rel_def goGS_invar_def
split: prod.splits
)
using acc_bound
apply (fastforce simp: initial_impl_def GS_initial_impl_def)+
done
definition gpath_is_empty_impl :: "'Q gGS \<Rightarrow> bool"
where "gpath_is_empty_impl s = path_is_empty_impl (snd s)"
lemma gpath_is_empty_refine:
"(s,(a,p,D,pE))\<in>gGS_rel \<Longrightarrow> gpath_is_empty_impl s \<longleftrightarrow> p=[]"
unfolding gpath_is_empty_impl_def
using path_is_empty_refine
by (fastforce simp: gGS_rel_def br_def gGS_invar_def gGS_\<alpha>_def GS.\<alpha>_def)
definition gis_on_stack_impl :: "'Q \<Rightarrow> 'Q gGS \<Rightarrow> bool"
where "gis_on_stack_impl v s = is_on_stack_impl v (snd s)"
lemma gis_on_stack_refine:
"\<lbrakk>(s,(a,p,D,pE))\<in>gGS_rel\<rbrakk> \<Longrightarrow> gis_on_stack_impl v s \<longleftrightarrow> v\<in>\<Union>set p"
unfolding gis_on_stack_impl_def
using is_on_stack_refine
by (fastforce simp: gGS_rel_def br_def gGS_invar_def gGS_\<alpha>_def GS.\<alpha>_def)
definition gis_done_impl :: "'Q \<Rightarrow> 'Q gGS \<Rightarrow> bool"
where "gis_done_impl v s \<equiv> is_done_impl v (snd s)"
thm is_done_refine
lemma gis_done_refine: "(s,(a,p,D,pE))\<in>gGS_rel
\<Longrightarrow> gis_done_impl v s \<longleftrightarrow> (v \<in> D)"
using is_done_refine[of "(snd s)" v]
by (auto
simp: gGS_rel_def br_def gGS_\<alpha>_def gGS_invar_def GS.\<alpha>_def
gis_done_impl_def)
definition (in -) "on_stack_less I u v \<equiv>
case I v of
Some (STACK j) \<Rightarrow> j<u
| _ \<Rightarrow> False"
definition (in -) "on_stack_ge I l v \<equiv>
case I v of
Some (STACK j) \<Rightarrow> l\<le>j
| _ \<Rightarrow> False"
lemma (in GS_invar) set_butlast_p_refine:
assumes PRE: "p_\<alpha>\<noteq>[]"
shows "Collect (on_stack_less I (last B)) = \<Union>set (butlast p_\<alpha>)" (is "?L=?R")
proof (intro equalityI subsetI)
from PRE have [simp]: "B\<noteq>[]" by (auto simp: p_\<alpha>_def)
have [simp]: "S\<noteq>[]"
by (simp add: empty_eq)
{
fix v
assume "v\<in>?L"
then obtain j where [simp]: "I v = Some (STACK j)" and "j<last B"
by (auto simp: on_stack_less_def split: option.splits node_state.splits)
from I_consistent[of v j] have [simp]: "j<length S" "v=S!j" by auto
from B0 have "B!0=0" by simp
from `j<last B` have "j<B!(length B - 1)" by (simp add: last_conv_nth)
from find_seg_bounds[OF `j<length S`] find_seg_correct[OF `j<length S`]
have "v\<in>seg (find_seg j)" "find_seg j < length B" by auto
moreover with `j<B!(length B - 1)` have "find_seg j < length B - 1"
(* What follows is an unreadable, auto-generated structured proof
that replaces the following smt-call:
by (smt GS.seg_start_def `seg_start (find_seg j) \<le> j`)*)
proof -
have f1: "\<And>x\<^sub>1 x. \<not> (x\<^sub>1\<Colon>nat) < x\<^sub>1 - x"
using less_imp_diff_less by blast
have "j \<le> last B"
by (metis `j < last B` sup.semilattice_strict_iff_order)
hence f2: "\<And>x\<^sub>1. \<not> last B < x\<^sub>1 \<or> \<not> x\<^sub>1 \<le> j"
using f1 by (metis diff_diff_cancel le_trans)
have "\<And>x\<^sub>1. seg_end x\<^sub>1 \<le> j \<or> \<not> x\<^sub>1 < find_seg j"
by (metis `seg_start (find_seg j) \<le> j` calculation(2)
le_trans seg_end_less_start)
thus "find_seg j < length B - 1"
using f1 f2
by (metis GS.seg_start_def `B \<noteq> []` `j < B ! (length B - 1)`
`seg_start (find_seg j) \<le> j` calculation(2) diff_diff_cancel
last_conv_nth nat_neq_iff seg_start_less_end)
qed
ultimately show "v\<in>?R"
by (auto simp: p_\<alpha>_def map_butlast[symmetric] butlast_upt)
}
{
fix v
assume "v\<in>?R"
then obtain i where "i<length B - 1" and "v\<in>seg i"
by (auto simp: p_\<alpha>_def map_butlast[symmetric] butlast_upt)
then obtain j where "j < seg_end i" and "v=S!j"
by (auto simp: seg_def)
hence "j<B!(i+1)" and "i+1 \<le> length B - 1" using `i<length B - 1`
by (auto simp: seg_end_def last_conv_nth split: split_if_asm)
with sorted_nth_mono[OF B_sorted `i+1 \<le> length B - 1`] have "j<last B"
by (auto simp: last_conv_nth)
moreover from `j < seg_end i` have "j<length S"
by (metis GS.seg_end_def Nat.add_diff_inverse `i + 1 \<le> length B - 1`
add_lessD1 less_imp_diff_less less_le_not_le nat_neq_iff
seg_end_bound)
(*by (smt `i < length B - 1` seg_end_bound)*)
with I_consistent `v=S!j` have "I v = Some (STACK j)" by auto
ultimately show "v\<in>?L"
by (auto simp: on_stack_less_def)
}
qed
lemma (in GS_invar) set_last_p_refine:
assumes PRE: "p_\<alpha>\<noteq>[]"
shows "Collect (on_stack_ge I (last B)) = last p_\<alpha>" (is "?L=?R")
proof (intro equalityI subsetI)
from PRE have [simp]: "B\<noteq>[]" by (auto simp: p_\<alpha>_def)
have [simp]: "S\<noteq>[]" by (simp add: empty_eq)
{
fix v
assume "v\<in>?L"
then obtain j where [simp]: "I v = Some (STACK j)" and "j\<ge>last B"
by (auto simp: on_stack_ge_def split: option.splits node_state.splits)
from I_consistent[of v j] have [simp]: "j<length S" "v=S!j" by auto
hence "v\<in>seg (length B - 1)" using `j\<ge>last B`
by (auto simp: seg_def last_conv_nth seg_start_def seg_end_def)
thus "v\<in>last p_\<alpha>" by (auto simp: p_\<alpha>_def last_map)
}
{
fix v
assume "v\<in>?R"
hence "v\<in>seg (length B - 1)"
by (auto simp: p_\<alpha>_def last_map)
then obtain j where "v=S!j" "j\<ge>last B" "j<length S"
by (auto simp: seg_def last_conv_nth seg_start_def seg_end_def)
with I_consistent have "I v = Some (STACK j)" by simp
with `j\<ge>last B` show "v\<in>?L" by (auto simp: on_stack_ge_def)
}
qed
definition ce_impl :: "'Q gGS \<Rightarrow> (('Q set \<times> 'Q set) option \<times> 'Q gGS) nres"
where "ce_impl s \<equiv>
do {
let (a,S,B,I,P) = s;
ASSERT (B\<noteq>[]);
let bls = Collect (on_stack_less I (last B));
let ls = Collect (on_stack_ge I (last B));
RETURN (Some (bls, ls),a,S,B,I,P)
}"
lemma ce_impl_refine:
assumes A: "(s,(a,p,D,pE))\<in>gGS_rel"
assumes PRE: "p\<noteq>[]"
shows "ce_impl s \<le> \<Down>(Id\<times>\<^sub>rgGS_rel)
(RETURN (Some (\<Union>set (butlast p),last p),a,p,D,pE))"
proof -
from A obtain S' B' I' P' where [simp]: "s=(a,S',B',I',P')"
and OSR: "((S',B',I',P'),(p,D,pE))\<in>GS_rel" and L: "length a = length B'"
by (rule gGS_relE)
from OSR have [simp]: "GS.p_\<alpha> (S',B',I',P') = p"
by (simp add: GS_rel_def br_def GS.\<alpha>_def)
from PRE have NE': "GS.p_\<alpha> (S', B', I', P') \<noteq> []" by simp
hence BNE[simp]: "B'\<noteq>[]" by (simp add: GS.p_\<alpha>_def)
from OSR have GS_invar: "GS_invar (S',B',I',P')"
by (simp add: GS_rel_def br_def)
show ?thesis
using GS_invar.set_butlast_p_refine[OF GS_invar NE']
using GS_invar.set_last_p_refine[OF GS_invar NE']
unfolding ce_impl_def
apply (simp)
apply (rule RETURN_refine_sv, tagged_solver)
using A
by auto
qed
definition "last_is_acc_impl s \<equiv>
do {
let (a,_)=s;
ASSERT (a\<noteq>[]);
RETURN (\<forall>i<num_acc. i\<in>last a)
}"
lemma last_is_acc_impl_refine:
assumes A: "(s,(a,p,D,pE))\<in>gGS_rel"
assumes PRE: "a\<noteq>[]"
shows "last_is_acc_impl s \<le> RETURN (last a = {0..<num_acc})"
proof -
from A PRE have "last a \<subseteq> {0..<num_acc}"
unfolding gGS_rel_def gGS_invar_def br_def gGS_\<alpha>_def by auto
hence C: "(\<forall>i<num_acc. i\<in>last a) \<longleftrightarrow> (last a = {0..<num_acc})"
by auto
from A obtain gs where [simp]: "s=(a,gs)"
by (auto simp: gGS_rel_def gGS_\<alpha>_def br_def split: prod.splits)
show ?thesis
unfolding last_is_acc_impl_def
by (auto simp: gGS_rel_def br_def gGS_\<alpha>_def C PRE split: prod.splits)
qed
definition go_is_no_brk_impl :: "'Q goGS \<Rightarrow> bool"
where "go_is_no_brk_impl s \<equiv> fst s = None"
lemma go_is_no_brk_refine:
"(s,s')\<in>goGS_rel \<Longrightarrow> go_is_no_brk_impl s \<longleftrightarrow> go_is_no_brk s'"
unfolding go_is_no_brk_def go_is_no_brk_impl_def
by (auto simp: goGS_rel_def br_def goGS_\<alpha>_def split: prod.splits)
definition goD_impl :: "'Q goGS \<Rightarrow> 'Q oGS" where "goD_impl s \<equiv> snd s"
lemma goD_refine:
"go_is_no_brk s' \<Longrightarrow> (s,s')\<in>goGS_rel \<Longrightarrow> (goD_impl s, goD s')\<in>oGS_rel"
unfolding goD_impl_def goD_def
by (auto
simp: goGS_rel_def br_def goGS_\<alpha>_def goGS_invar_def oGS_rel_def
go_is_no_brk_def)
definition go_is_done_impl :: "'Q \<Rightarrow> 'Q goGS \<Rightarrow> bool"
where "go_is_done_impl v s \<equiv> is_done_oimpl v (snd s)"
thm is_done_orefine
lemma go_is_done_impl_refine: "\<lbrakk>go_is_no_brk s'; (s,s')\<in>goGS_rel; (v,v')\<in>Id\<rbrakk>
\<Longrightarrow> go_is_done_impl v s \<longleftrightarrow> (v'\<in>goD s')"
using is_done_orefine
unfolding go_is_done_impl_def goD_def go_is_no_brk_def
apply (fastforce simp: goGS_rel_def br_def goGS_invar_def goGS_\<alpha>_def)
done
definition goBrk_impl :: "'Q goGS \<Rightarrow> 'Q ce" where "goBrk_impl \<equiv> fst"
definition find_ce_impl :: "('Q set \<times> 'Q set) option nres" where
"find_ce_impl \<equiv> do {
stat_start_nres;
let os=goinitial_impl;
os\<leftarrow>FOREACHci (\<lambda>it os. fgl_outer_invar it (goGS_\<alpha> os)) V0
(go_is_no_brk_impl) (\<lambda>v0 s0.
do {
if \<not>go_is_done_impl v0 s0 then do {
let s = (None,ginitial_impl v0 s0);
(brk,s)\<leftarrow>WHILEIT
(\<lambda>(brk,s). fgl_invar v0 (oGS_\<alpha> (goD_impl s0)) (brk,snd (gGS_\<alpha> s)))
(\<lambda>(brk,s). brk=None \<and> \<not>gpath_is_empty_impl s) (\<lambda>(l,s).
do {
(* Select edge from end of path *)
(vo,s) \<leftarrow> gselect_edge_impl s;
case vo of
Some v \<Rightarrow> do {
if gis_on_stack_impl v s then do {
s\<leftarrow>gcollapse_impl v s;
b\<leftarrow>last_is_acc_impl s;
if b then
ce_impl s
else
RETURN (None,s)
} else if \<not>gis_done_impl v s then do {
(* Edge to new node. Append to path *)
RETURN (None,gpush_impl v s)
} else do {
(* Edge to done node. Skip *)
RETURN (None,s)
}
}
| None \<Rightarrow> do {
(* No more outgoing edges from current node on path *)
s\<leftarrow>gpop_impl s;
RETURN (None,s)
}
}) (s);
RETURN (gto_outer_impl brk s)
} else RETURN s0
}) os;
stat_stop_nres;
RETURN (goBrk_impl os)
}"
lemma find_ce_impl_refine: "find_ce_impl \<le> \<Down>Id gfind_ce"
proof -
note [refine2] = prod_relI[OF IdI[of None] ginitial_impl_refine]
have [refine]: "\<And>s a p D pE. \<lbrakk>
(s,(a,p,D,pE))\<in>gGS_rel;
p \<noteq> []; pE \<inter> last p \<times> UNIV = {}
\<rbrakk> \<Longrightarrow>
gpop_impl s \<guillemotright>= (\<lambda>s. RETURN (None, s))
\<le> SPEC (\<lambda>c. (c, None, gpop (a,p,D,pE)) \<in> Id \<times>\<^sub>r gGS_rel)"
apply (drule (2) gpop_impl_refine)
apply (fastforce simp add: pw_le_iff refine_pw_simps)
done
note [[goals_limit = 1]]
note FOREACHci_refine_rcg'[refine del]
show ?thesis
unfolding find_ce_impl_def gfind_ce_def
apply (refine_rcg
bind_refine'
prod_relI IdI
inj_on_id
gselect_edge_impl_refine gpush_impl_refine
oinitial_refine ginitial_impl_refine
bind_Let_refine2[OF gcollapse_impl_refine]
if_bind_cond_refine[OF last_is_acc_impl_refine]
ce_impl_refine
goinitial_impl_refine
gto_outer_refine
goBrk_refine
FOREACHci_refine_rcg'[where R=goGS_rel, OF inj_on_id]
)
apply (simp_all add: go_is_no_brk_refine go_is_done_impl_refine)
apply (auto simp: goGS_rel_def br_def) []
apply (auto simp: goGS_rel_def br_def goGS_\<alpha>_def gGS_\<alpha>_def gGS_rel_def
goD_def goD_impl_def) []
apply (auto dest: gpath_is_empty_refine ) []
apply (auto dest: gis_on_stack_refine) []
apply (auto dest: gis_done_refine) []
done
qed
end
section {* Constructing a Lasso from Counterexample *}
subsection {* Lassos in GBAs *}
context igb_graph begin
definition reconstruct_reach :: "'Q set \<Rightarrow> 'Q set \<Rightarrow> ('Q list \<times> 'Q) nres"
-- "Reconstruct the reaching path of a lasso"
where "reconstruct_reach Vr Vl \<equiv> do {
res \<leftarrow> find_path (E\<inter>Vr\<times>UNIV) V0 (\<lambda>v. v\<in>Vl);
ASSERT (res \<noteq> None);
RETURN (the res)
}"
lemma (in igb_graph) reconstruct_reach_correct:
assumes CEC: "ce_correct Vr Vl"
shows "reconstruct_reach Vr Vl
\<le> SPEC (\<lambda>(pr,va). \<exists>v0\<in>V0. path E v0 pr va \<and> va\<in>Vl)"
proof -
have FIN_aux: "finite ((E \<inter> Vr \<times> UNIV)\<^sup>* `` V0)"
by (metis finite_reachableE_V0 finite_subset inf_sup_ord(1) inf_sup_ord(2)
inf_top.left_neutral reachable_mono)
{
fix u p v
assume P: "path E u p v" and SS: "set p \<subseteq> Vr"
have "path (E \<inter> Vr\<times>UNIV) u p v"
apply (rule path_mono[OF _ path_restrict[OF P]])
using SS by auto
} note P_CONV=this
from CEC obtain v0 "pr" va where "v0\<in>V0" "set pr \<subseteq> Vr" "va\<in>Vl"
"path (E \<inter> Vr\<times>UNIV) v0 pr va"
unfolding ce_correct_def is_lasso_prpl_def is_lasso_prpl_pre_def
by (force simp: neq_Nil_conv path_simps dest: P_CONV)
hence 1: "va \<in> (E \<inter> Vr \<times> UNIV)\<^sup>* `` V0"
by (auto dest: path_is_rtrancl)
show ?thesis
using assms unfolding reconstruct_reach_def
apply (refine_rcg refine_vcg order_trans[OF find_path_ex_rule])
apply (clarsimp_all simp: FIN_aux)
using `va\<in>Vl` 1 apply auto []
apply (auto dest: path_mono[of "E \<inter> Vr \<times> UNIV" E, simplified]) []
done
qed
definition "rec_loop_invar Vl va s \<equiv> let (v,p,cS) = s in
va \<in> E\<^sup>*``V0 \<and>
path E va p v \<and>
cS = acc v \<union> (\<Union>(acc`set p)) \<and>
va \<in> Vl \<and> v \<in> Vl \<and> set p \<subseteq> Vl"
definition reconstruct_lasso :: "'Q set \<Rightarrow> 'Q set \<Rightarrow> ('Q list \<times> 'Q list) nres"
-- "Reconstruct lasso"
where "reconstruct_lasso Vr Vl \<equiv> do {
(pr,va) \<leftarrow> reconstruct_reach Vr Vl;
let cS_full = {0..<num_acc};
let E = E \<inter> UNIV\<times>Vl;
(vd,p,_) \<leftarrow> WHILEIT (rec_loop_invar Vl va)
(\<lambda>(_,_,cS). cS \<noteq> cS_full)
(\<lambda>(v,p,cS). do {
ASSERT (\<exists>v'. (v,v')\<in>E\<^sup>* \<and> \<not> (acc v' \<subseteq> cS));
sr \<leftarrow> find_path E {v} (\<lambda>v. \<not> (acc v \<subseteq> cS));
ASSERT (sr \<noteq> None);
let (p_seg,v) = the sr;
RETURN (v,p@p_seg,cS \<union> acc v)
}) (va,[],acc va);
p_close_r \<leftarrow> (if p=[] then
find_path1 E vd (op = va)
else
find_path E {vd} (op = va));
ASSERT (p_close_r \<noteq> None);
let (p_close,_) = the p_close_r;
RETURN (pr, p@p_close)
}"
lemma (in igb_graph) reconstruct_lasso_correct:
assumes CEC: "ce_correct Vr Vl"
shows "reconstruct_lasso Vr Vl \<le> SPEC (is_lasso_prpl)"
proof -
let ?E = "E \<inter> UNIV \<times> Vl"
have E_SS: "E \<inter> Vl \<times> Vl \<subseteq> ?E" by auto
from CEC have
REACH: "Vl \<subseteq> E\<^sup>*``V0"
and CONN: "Vl\<times>Vl \<subseteq> (E \<inter> Vl\<times>Vl)\<^sup>*"
and NONTRIV: "Vl\<times>Vl \<inter> E \<noteq> {}"
and NES[simp]: "Vl\<noteq>{}"
and ALL: "\<Union>(acc`Vl) = {0..<num_acc}"
unfolding ce_correct_def is_lasso_prpl_def
apply clarsimp_all
apply auto []
apply force
done
def term_rel
\<equiv> "(inv_image (finite_psupset {0..<num_acc}) (\<lambda>(_::'Q,_::'Q list,cS). cS))"
hence WF: "wf term_rel" by simp
{ fix va
assume "va \<in> Vl"
hence "rec_loop_invar Vl va (va, [], acc va)"
unfolding rec_loop_invar_def using REACH by auto
} note INVAR_INITIAL = this
{
fix v p cS va
assume "rec_loop_invar Vl va (v, p, cS)"
hence "finite ((?E)\<^sup>* `` {v})"
apply -
apply (rule finite_subset[where B="E\<^sup>*``V0"])
unfolding rec_loop_invar_def
using REACH
apply (clarsimp_all dest!: path_is_rtrancl)
apply (drule rtrancl_mono_mp[where U="?E" and V=E, rotated], (auto) [])
by (metis rev_ImageI rtrancl_trans)
} note FIN1 = this
{
fix va v :: 'Q and p cS
assume INV: "rec_loop_invar Vl va (v,p,cS)"
and NC: "cS \<noteq> {0..<num_acc}"
from NC INV obtain i where "i<num_acc" "i\<notin>cS"
unfolding rec_loop_invar_def by force
with ALL obtain v' where "v'\<in>Vl" "\<not> acc v' \<subseteq> cS"
by fastforce
moreover with CONN INV have "(v,v')\<in>(E \<inter> Vl \<times> Vl)\<^sup>*"
unfolding rec_loop_invar_def by auto
hence "(v,v')\<in>?E\<^sup>*" using rtrancl_mono_mp[OF E_SS] by blast
ultimately have "\<exists>v'. (v,v')\<in>(?E)\<^sup>* \<and> \<not> acc v' \<subseteq> cS" by auto
} note ASSERT1 = this
{
fix va v p cS v' p'
assume "rec_loop_invar Vl va (v, p, cS)"
and "path (?E) v p' v'"
and "\<not> (acc v' \<subseteq> cS)"
and "\<forall>v\<in>set p'. acc v \<subseteq> cS"
hence "rec_loop_invar Vl va (v', p@p', cS \<union> acc v')"
unfolding rec_loop_invar_def
apply simp
apply (intro conjI)
apply (auto simp: path_simps dest: path_mono[of "?E" E, simplified]) []
apply (cases p')
apply (auto simp: path_simps) [2]
apply (cases p' rule: rev_cases)
apply (auto simp: path_simps) [2]
apply (erule path_set_induct)
apply auto [2]
done
} note INV_PRES = this
{
fix va v p cS v' p'
assume "rec_loop_invar Vl va (v, p, cS)"
and "path ?E v p' v'"
and "\<not> (acc v' \<subseteq> cS)"
and "\<forall>v\<in>set p'. acc v \<subseteq> cS"
hence "((v', p@p', cS \<union> acc v'), (v,p,cS)) \<in> term_rel"
unfolding term_rel_def rec_loop_invar_def
by (auto simp: finite_psupset_def)
} note VAR = this
have CONN1: "Vl \<times> Vl \<subseteq> (?E)\<^sup>+"
proof clarify
fix a b
assume "a\<in>Vl" "b\<in>Vl"
from NONTRIV obtain u v where E: "(u,v)\<in>(E \<inter> Vl\<times>Vl)" by auto
from CONN `a\<in>Vl` E have "(a,u)\<in>(E\<inter>Vl\<times>Vl)\<^sup>*" by auto
also note E
also (rtrancl_into_trancl1) from CONN `b\<in>Vl` E have "(v,b)\<in>(E\<inter>Vl\<times>Vl)\<^sup>*"
by auto
finally show "(a,b)\<in>(?E)\<^sup>+" using trancl_mono[OF _ E_SS] by auto
qed
{
fix va v p cS
assume "rec_loop_invar Vl va (v, p, cS)"
hence "(v,va) \<in> (?E)\<^sup>+"
unfolding rec_loop_invar_def
using CONN1
by auto
} note CLOSE1 = this
{
fix va v p cS
assume "rec_loop_invar Vl va (v, p, cS)"
hence "(v,va) \<in> (?E)\<^sup>*"
unfolding rec_loop_invar_def
using CONN rtrancl_mono[OF E_SS]
by auto
} note CLOSE2 = this
{
fix "pr" vd pl va v0
assume "rec_loop_invar Vl va (vd, [], {0..<num_acc})" "va \<in> Vl" "v0 \<in> V0"
"path E v0 pr va" "pl \<noteq> []" "path ?E vd pl va"
hence "is_lasso_prpl (pr, pl)"
unfolding is_lasso_prpl_def is_lasso_prpl_pre_def rec_loop_invar_def
by (auto simp: neq_Nil_conv path_simps
dest!: path_mono[of "?E" E, simplified]) []
} note INV_POST1 = this
{
fix va v p p' "pr" v0
assume INV: "rec_loop_invar Vl va (v,p,{0..<num_acc})"
and 1: "p\<noteq>[]" "path ?E v p' va"
and PR: "v0\<in>V0" "path E v0 pr va"
from INV have "\<forall>i<num_acc. \<exists>q\<in>insert v (set p). i \<in> acc q"
unfolding rec_loop_invar_def
by auto
moreover from INV 1 have "insert v (set p) \<subseteq> set p \<union> set p'"
unfolding rec_loop_invar_def
apply (cases p, simp)
apply (cases p')
apply (auto simp: path_simps)
done
ultimately have ACC: "\<forall>i<num_acc. \<exists>q\<in>set p \<union> set p'. i \<in> acc q" by blast
from INV 1 have PL: "path E va (p @ p') va"
by (auto simp: rec_loop_invar_def path_simps
dest!: path_mono[of "?E" E, simplified]) []
have "is_lasso_prpl (pr,p@p')"
unfolding is_lasso_prpl_def is_lasso_prpl_pre_def
apply (clarsimp simp: ACC)
using PR PL `p\<noteq>[]` by auto
} note INV_POST2 = this
show ?thesis
unfolding reconstruct_lasso_def
apply (refine_rcg
WF
order_trans[OF reconstruct_reach_correct]
order_trans[OF find_path_ex_rule]
order_trans[OF find_path1_ex_rule]
refine_vcg
)
apply (vc_solve
del: subsetI
solve: ASSERT1 INV_PRES asm_rl VAR CLOSE1 CLOSE2 INV_POST1 INV_POST2
simp: INVAR_INITIAL FIN1 CEC)
done
qed
definition find_lasso where "find_lasso \<equiv> do {
ce \<leftarrow> find_ce_spec;
case ce of
None \<Rightarrow> RETURN None
| Some (Vr,Vl) \<Rightarrow> do {
l \<leftarrow> reconstruct_lasso Vr Vl;
RETURN (Some l)
}
}"
lemma (in igb_graph) find_lasso_correct: "find_lasso \<le> find_lasso_spec"
unfolding find_lasso_spec_def find_lasso_def find_ce_spec_def
apply (refine_rcg refine_vcg order_trans[OF reconstruct_lasso_correct])
apply auto
done
end
end
|
import analysis.calculus.affine_map
/-!
# Lemmas about interaction of `ball` and `homothety`
TODO Generalise these lemmas appropriately.
-/
open set function metric affine_map
variables {F : Type*} [normed_add_comm_group F] [normed_space ℝ F]
-- Unused
@[simp] lemma range_affine_equiv_ball {p c : F} {s r : ℝ} (hr : 0 < r) :
range (λ (x : ball p s), c +ᵥ homothety p r (x : F)) = ball (c + p) (r * s) :=
begin
ext,
simp only [homothety_apply, dist_eq_norm, vsub_eq_sub, vadd_eq_add, mem_range,
set_coe.exists, mem_ball, subtype.coe_mk, exists_prop],
refine ⟨_, λ h, ⟨p + r⁻¹ • (x - (c + p)), _, _⟩⟩,
{ rintros ⟨y, h, rfl⟩,
simpa [norm_smul, abs_eq_self.mpr hr.le] using (mul_lt_mul_left hr).mpr h, },
{ simpa [norm_smul, abs_eq_self.mpr hr.le] using (inv_mul_lt_iff hr).mpr h, },
{ simp [← smul_assoc, hr.ne.symm.is_unit.mul_inv_cancel], abel, },
end
@[simp] lemma norm_coe_ball_lt (r : ℝ) (x : ball (0 : F) r) : ‖(x : F)‖ < r :=
by { cases x with x hx, simpa using hx, }
lemma maps_to_homothety_ball (c : F) {r : ℝ} (hr : 0 < r) :
maps_to (λ y, homothety c r⁻¹ y -ᵥ c) (ball c r) (ball 0 1) :=
begin
intros y hy,
replace hy : r⁻¹ * ‖y - c‖ < 1,
{ rw [← mul_lt_mul_left hr, ← mul_assoc, mul_inv_cancel hr.ne.symm, mul_one, one_mul],
simpa [dist_eq_norm] using hy, },
simp only [homothety_apply, vsub_eq_sub, vadd_eq_add, add_sub_cancel, mem_ball_zero_iff,
norm_smul, real.norm_eq_abs, abs_eq_self.2 (inv_pos.mpr hr).le, hy],
end
lemma cont_diff_homothety {n : ℕ∞} (c : F) (r : ℝ) : cont_diff ℝ n (homothety c r) :=
(⟨homothety c r, homothety_continuous c r⟩ : F →A[ℝ] F).cont_diff
|
Human Protein Atlas
|
/-
Copyright (c) 2019 Jan-David Salchow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo
! This file was ported from Lean 3 source module analysis.normed_space.operator_norm
! leanprover-community/mathlib commit 91862a6001a8b6ae3f261cdd8eea42f6ac596886
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Algebra.Algebra.Tower
import Mathbin.Analysis.Asymptotics.Asymptotics
import Mathbin.Analysis.NormedSpace.ContinuousLinearMap
import Mathbin.Analysis.NormedSpace.LinearIsometry
import Mathbin.Topology.Algebra.Module.StrongTopology
/-!
# Operator norm on the space of continuous linear maps
Define the operator norm on the space of continuous (semi)linear maps between normed spaces, and
prove its basic properties. In particular, show that this space is itself a normed space.
Since a lot of elementary properties don't require `‖x‖ = 0 → x = 0` we start setting up the
theory for `seminormed_add_comm_group` and we specialize to `normed_add_comm_group` at the end.
Note that most of statements that apply to semilinear maps only hold when the ring homomorphism
is isometric, as expressed by the typeclass `[ring_hom_isometric σ]`.
-/
noncomputable section
open Classical NNReal Topology
-- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps
variable {𝕜 𝕜₂ 𝕜₃ E Eₗ F Fₗ G Gₗ 𝓕 : Type _}
section SemiNormed
open Metric ContinuousLinearMap
variable [SeminormedAddCommGroup E] [SeminormedAddCommGroup Eₗ] [SeminormedAddCommGroup F]
[SeminormedAddCommGroup Fₗ] [SeminormedAddCommGroup G] [SeminormedAddCommGroup Gₗ]
variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃]
[NormedSpace 𝕜 E] [NormedSpace 𝕜 Eₗ] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜 Fₗ] [NormedSpace 𝕜₃ G]
[NormedSpace 𝕜 Gₗ] {σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃} {σ₁₃ : 𝕜 →+* 𝕜₃}
[RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
/-- If `‖x‖ = 0` and `f` is continuous then `‖f x‖ = 0`. -/
theorem norm_image_of_norm_zero [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕) (hf : Continuous f) {x : E}
(hx : ‖x‖ = 0) : ‖f x‖ = 0 :=
by
refine' le_antisymm (le_of_forall_pos_le_add fun ε hε => _) (norm_nonneg (f x))
rcases NormedAddCommGroup.tendsto_nhds_nhds.1 (hf.tendsto 0) ε hε with ⟨δ, δ_pos, hδ⟩
replace hδ := hδ x
rw [sub_zero, hx] at hδ
replace hδ := le_of_lt (hδ δ_pos)
rw [map_zero, sub_zero] at hδ
rwa [zero_add]
#align norm_image_of_norm_zero norm_image_of_norm_zero
section
variable [RingHomIsometric σ₁₂] [RingHomIsometric σ₂₃]
theorem SemilinearMapClass.bound_of_shell_semi_normed [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕)
{ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ‖c‖)
(hf : ∀ x, ε / ‖c‖ ≤ ‖x‖ → ‖x‖ < ε → ‖f x‖ ≤ C * ‖x‖) {x : E} (hx : ‖x‖ ≠ 0) :
‖f x‖ ≤ C * ‖x‖ :=
by
rcases rescale_to_shell_semi_normed hc ε_pos hx with ⟨δ, hδ, δxle, leδx, δinv⟩
have := hf (δ • x) leδx δxle
simpa only [map_smulₛₗ, norm_smul, mul_left_comm C, mul_le_mul_left (norm_pos_iff.2 hδ),
RingHomIsometric.is_iso] using hf (δ • x) leδx δxle
#align semilinear_map_class.bound_of_shell_semi_normed SemilinearMapClass.bound_of_shell_semi_normed
/-- A continuous linear map between seminormed spaces is bounded when the field is nontrivially
normed. The continuity ensures boundedness on a ball of some radius `ε`. The nontriviality of the
norm is then used to rescale any element into an element of norm in `[ε/C, ε]`, whose image has a
controlled norm. The norm control for the original element follows by rescaling. -/
theorem SemilinearMapClass.bound_of_continuous [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕)
(hf : Continuous f) : ∃ C, 0 < C ∧ ∀ x : E, ‖f x‖ ≤ C * ‖x‖ :=
by
rcases NormedAddCommGroup.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one with ⟨ε, ε_pos, hε⟩
simp only [sub_zero, map_zero] at hε
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
have : 0 < ‖c‖ / ε := div_pos (zero_lt_one.trans hc) ε_pos
refine' ⟨‖c‖ / ε, this, fun x => _⟩
by_cases hx : ‖x‖ = 0
· rw [hx, MulZeroClass.mul_zero]
exact le_of_eq (norm_image_of_norm_zero f hf hx)
refine' SemilinearMapClass.bound_of_shell_semi_normed f ε_pos hc (fun x hle hlt => _) hx
refine' (hε _ hlt).le.trans _
rwa [← div_le_iff' this, one_div_div]
#align semilinear_map_class.bound_of_continuous SemilinearMapClass.bound_of_continuous
end
namespace ContinuousLinearMap
theorem bound [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) : ∃ C, 0 < C ∧ ∀ x : E, ‖f x‖ ≤ C * ‖x‖ :=
SemilinearMapClass.bound_of_continuous f f.2
#align continuous_linear_map.bound ContinuousLinearMap.bound
section
open Filter
variable (𝕜 E)
/-- Given a unit-length element `x` of a normed space `E` over a field `𝕜`, the natural linear
isometry map from `𝕜` to `E` by taking multiples of `x`.-/
def LinearIsometry.toSpanSingleton {v : E} (hv : ‖v‖ = 1) : 𝕜 →ₗᵢ[𝕜] E :=
{ LinearMap.toSpanSingleton 𝕜 E v with norm_map' := fun x => by simp [norm_smul, hv] }
#align linear_isometry.to_span_singleton LinearIsometry.toSpanSingleton
variable {𝕜 E}
@[simp]
theorem LinearIsometry.toSpanSingleton_apply {v : E} (hv : ‖v‖ = 1) (a : 𝕜) :
LinearIsometry.toSpanSingleton 𝕜 E hv a = a • v :=
rfl
#align linear_isometry.to_span_singleton_apply LinearIsometry.toSpanSingleton_apply
@[simp]
theorem LinearIsometry.coe_toSpanSingleton {v : E} (hv : ‖v‖ = 1) :
(LinearIsometry.toSpanSingleton 𝕜 E hv).toLinearMap = LinearMap.toSpanSingleton 𝕜 E v :=
rfl
#align linear_isometry.coe_to_span_singleton LinearIsometry.coe_toSpanSingleton
end
section OpNorm
open Set Real
/-- The operator norm of a continuous linear map is the inf of all its bounds. -/
def opNorm (f : E →SL[σ₁₂] F) :=
infₛ { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ }
#align continuous_linear_map.op_norm ContinuousLinearMap.opNorm
instance hasOpNorm : Norm (E →SL[σ₁₂] F) :=
⟨opNorm⟩
#align continuous_linear_map.has_op_norm ContinuousLinearMap.hasOpNorm
theorem norm_def (f : E →SL[σ₁₂] F) : ‖f‖ = infₛ { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
rfl
#align continuous_linear_map.norm_def ContinuousLinearMap.norm_def
-- So that invocations of `le_cInf` make sense: we show that the set of
-- bounds is nonempty and bounded below.
theorem bounds_nonempty [RingHomIsometric σ₁₂] {f : E →SL[σ₁₂] F} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
let ⟨M, hMp, hMb⟩ := f.bound
⟨M, le_of_lt hMp, hMb⟩
#align continuous_linear_map.bounds_nonempty ContinuousLinearMap.bounds_nonempty
theorem bounds_bddBelow {f : E →SL[σ₁₂] F} : BddBelow { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
⟨0, fun _ ⟨hn, _⟩ => hn⟩
#align continuous_linear_map.bounds_bdd_below ContinuousLinearMap.bounds_bddBelow
/-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/
theorem op_norm_le_bound (f : E →SL[σ₁₂] F) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ x, ‖f x‖ ≤ M * ‖x‖) :
‖f‖ ≤ M :=
cinfₛ_le bounds_bddBelow ⟨hMp, hM⟩
#align continuous_linear_map.op_norm_le_bound ContinuousLinearMap.op_norm_le_bound
/-- If one controls the norm of every `A x`, `‖x‖ ≠ 0`, then one controls the norm of `A`. -/
theorem op_norm_le_bound' (f : E →SL[σ₁₂] F) {M : ℝ} (hMp : 0 ≤ M)
(hM : ∀ x, ‖x‖ ≠ 0 → ‖f x‖ ≤ M * ‖x‖) : ‖f‖ ≤ M :=
op_norm_le_bound f hMp fun x =>
(ne_or_eq ‖x‖ 0).elim (hM x) fun h => by
simp only [h, MulZeroClass.mul_zero, norm_image_of_norm_zero f f.2 h]
#align continuous_linear_map.op_norm_le_bound' ContinuousLinearMap.op_norm_le_bound'
theorem op_norm_le_of_lipschitz {f : E →SL[σ₁₂] F} {K : ℝ≥0} (hf : LipschitzWith K f) : ‖f‖ ≤ K :=
f.op_norm_le_bound K.2 fun x => by
simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0
#align continuous_linear_map.op_norm_le_of_lipschitz ContinuousLinearMap.op_norm_le_of_lipschitz
theorem op_norm_eq_of_bounds {φ : E →SL[σ₁₂] F} {M : ℝ} (M_nonneg : 0 ≤ M)
(h_above : ∀ x, ‖φ x‖ ≤ M * ‖x‖) (h_below : ∀ N ≥ 0, (∀ x, ‖φ x‖ ≤ N * ‖x‖) → M ≤ N) :
‖φ‖ = M :=
le_antisymm (φ.op_norm_le_bound M_nonneg h_above)
((le_cinfₛ_iff ContinuousLinearMap.bounds_bddBelow ⟨M, M_nonneg, h_above⟩).mpr
fun N ⟨N_nonneg, hN⟩ => h_below N N_nonneg hN)
#align continuous_linear_map.op_norm_eq_of_bounds ContinuousLinearMap.op_norm_eq_of_bounds
theorem op_norm_neg (f : E →SL[σ₁₂] F) : ‖-f‖ = ‖f‖ := by simp only [norm_def, neg_apply, norm_neg]
#align continuous_linear_map.op_norm_neg ContinuousLinearMap.op_norm_neg
section
variable [RingHomIsometric σ₁₂] [RingHomIsometric σ₂₃] (f g : E →SL[σ₁₂] F) (h : F →SL[σ₂₃] G)
(x : E)
theorem op_norm_nonneg : 0 ≤ ‖f‖ :=
le_cinfₛ bounds_nonempty fun _ ⟨hx, _⟩ => hx
#align continuous_linear_map.op_norm_nonneg ContinuousLinearMap.op_norm_nonneg
/-- The fundamental property of the operator norm: `‖f x‖ ≤ ‖f‖ * ‖x‖`. -/
theorem le_op_norm : ‖f x‖ ≤ ‖f‖ * ‖x‖ :=
by
obtain ⟨C, Cpos, hC⟩ := f.bound
replace hC := hC x
by_cases h : ‖x‖ = 0
· rwa [h, MulZeroClass.mul_zero] at hC⊢
have hlt : 0 < ‖x‖ := lt_of_le_of_ne (norm_nonneg x) (Ne.symm h)
exact
(div_le_iff hlt).mp
(le_cinfₛ bounds_nonempty fun c ⟨_, hc⟩ => (div_le_iff hlt).mpr <| by apply hc)
#align continuous_linear_map.le_op_norm ContinuousLinearMap.le_op_norm
theorem dist_le_op_norm (x y : E) : dist (f x) (f y) ≤ ‖f‖ * dist x y := by
simp_rw [dist_eq_norm, ← map_sub, f.le_op_norm]
#align continuous_linear_map.dist_le_op_norm ContinuousLinearMap.dist_le_op_norm
theorem le_op_norm_of_le {c : ℝ} {x} (h : ‖x‖ ≤ c) : ‖f x‖ ≤ ‖f‖ * c :=
le_trans (f.le_op_norm x) (mul_le_mul_of_nonneg_left h f.op_norm_nonneg)
#align continuous_linear_map.le_op_norm_of_le ContinuousLinearMap.le_op_norm_of_le
theorem le_of_op_norm_le {c : ℝ} (h : ‖f‖ ≤ c) (x : E) : ‖f x‖ ≤ c * ‖x‖ :=
(f.le_op_norm x).trans (mul_le_mul_of_nonneg_right h (norm_nonneg x))
#align continuous_linear_map.le_of_op_norm_le ContinuousLinearMap.le_of_op_norm_le
theorem ratio_le_op_norm : ‖f x‖ / ‖x‖ ≤ ‖f‖ :=
div_le_of_nonneg_of_le_mul (norm_nonneg _) f.op_norm_nonneg (le_op_norm _ _)
#align continuous_linear_map.ratio_le_op_norm ContinuousLinearMap.ratio_le_op_norm
/-- The image of the unit ball under a continuous linear map is bounded. -/
theorem unit_le_op_norm : ‖x‖ ≤ 1 → ‖f x‖ ≤ ‖f‖ :=
mul_one ‖f‖ ▸ f.le_op_norm_of_le
#align continuous_linear_map.unit_le_op_norm ContinuousLinearMap.unit_le_op_norm
theorem op_norm_le_of_shell {f : E →SL[σ₁₂] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜}
(hc : 1 < ‖c‖) (hf : ∀ x, ε / ‖c‖ ≤ ‖x‖ → ‖x‖ < ε → ‖f x‖ ≤ C * ‖x‖) : ‖f‖ ≤ C :=
f.op_norm_le_bound' hC fun x hx => SemilinearMapClass.bound_of_shell_semi_normed f ε_pos hc hf hx
#align continuous_linear_map.op_norm_le_of_shell ContinuousLinearMap.op_norm_le_of_shell
theorem op_norm_le_of_ball {f : E →SL[σ₁₂] F} {ε : ℝ} {C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C)
(hf : ∀ x ∈ ball (0 : E) ε, ‖f x‖ ≤ C * ‖x‖) : ‖f‖ ≤ C :=
by
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
refine' op_norm_le_of_shell ε_pos hC hc fun x _ hx => hf x _
rwa [ball_zero_eq]
#align continuous_linear_map.op_norm_le_of_ball ContinuousLinearMap.op_norm_le_of_ball
theorem op_norm_le_of_nhds_zero {f : E →SL[σ₁₂] F} {C : ℝ} (hC : 0 ≤ C)
(hf : ∀ᶠ x in 𝓝 (0 : E), ‖f x‖ ≤ C * ‖x‖) : ‖f‖ ≤ C :=
let ⟨ε, ε0, hε⟩ := Metric.eventually_nhds_iff_ball.1 hf
op_norm_le_of_ball ε0 hC hε
#align continuous_linear_map.op_norm_le_of_nhds_zero ContinuousLinearMap.op_norm_le_of_nhds_zero
theorem op_norm_le_of_shell' {f : E →SL[σ₁₂] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜}
(hc : ‖c‖ < 1) (hf : ∀ x, ε * ‖c‖ ≤ ‖x‖ → ‖x‖ < ε → ‖f x‖ ≤ C * ‖x‖) : ‖f‖ ≤ C :=
by
by_cases h0 : c = 0
· refine' op_norm_le_of_ball ε_pos hC fun x hx => hf x _ _
· simp [h0]
· rwa [ball_zero_eq] at hx
· rw [← inv_inv c, norm_inv, inv_lt_one_iff_of_pos (norm_pos_iff.2 <| inv_ne_zero h0)] at hc
refine' op_norm_le_of_shell ε_pos hC hc _
rwa [norm_inv, div_eq_mul_inv, inv_inv]
#align continuous_linear_map.op_norm_le_of_shell' ContinuousLinearMap.op_norm_le_of_shell'
/-- For a continuous real linear map `f`, if one controls the norm of every `f x`, `‖x‖ = 1`, then
one controls the norm of `f`. -/
theorem op_norm_le_of_unit_norm [NormedSpace ℝ E] [NormedSpace ℝ F] {f : E →L[ℝ] F} {C : ℝ}
(hC : 0 ≤ C) (hf : ∀ x, ‖x‖ = 1 → ‖f x‖ ≤ C) : ‖f‖ ≤ C :=
by
refine' op_norm_le_bound' f hC fun x hx => _
have H₁ : ‖‖x‖⁻¹ • x‖ = 1 := by rw [norm_smul, norm_inv, norm_norm, inv_mul_cancel hx]
have H₂ := hf _ H₁
rwa [map_smul, norm_smul, norm_inv, norm_norm, ← div_eq_inv_mul, div_le_iff] at H₂
exact (norm_nonneg x).lt_of_ne' hx
#align continuous_linear_map.op_norm_le_of_unit_norm ContinuousLinearMap.op_norm_le_of_unit_norm
/-- The operator norm satisfies the triangle inequality. -/
theorem op_norm_add_le : ‖f + g‖ ≤ ‖f‖ + ‖g‖ :=
(f + g).op_norm_le_bound (add_nonneg f.op_norm_nonneg g.op_norm_nonneg) fun x =>
(norm_add_le_of_le (f.le_op_norm x) (g.le_op_norm x)).trans_eq (add_mul _ _ _).symm
#align continuous_linear_map.op_norm_add_le ContinuousLinearMap.op_norm_add_le
/-- The norm of the `0` operator is `0`. -/
theorem op_norm_zero : ‖(0 : E →SL[σ₁₂] F)‖ = 0 :=
le_antisymm
(cinfₛ_le bounds_bddBelow
⟨le_rfl, fun _ =>
le_of_eq
(by
rw [MulZeroClass.zero_mul]
exact norm_zero)⟩)
(op_norm_nonneg _)
#align continuous_linear_map.op_norm_zero ContinuousLinearMap.op_norm_zero
/-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial
where it is `0`. It means that one can not do better than an inequality in general. -/
theorem norm_id_le : ‖id 𝕜 E‖ ≤ 1 :=
op_norm_le_bound _ zero_le_one fun x => by simp
#align continuous_linear_map.norm_id_le ContinuousLinearMap.norm_id_le
/-- If there is an element with norm different from `0`, then the norm of the identity equals `1`.
(Since we are working with seminorms supposing that the space is non-trivial is not enough.) -/
theorem norm_id_of_nontrivial_seminorm (h : ∃ x : E, ‖x‖ ≠ 0) : ‖id 𝕜 E‖ = 1 :=
le_antisymm norm_id_le <| by
let ⟨x, hx⟩ := h
have := (id 𝕜 E).ratio_le_op_norm x
rwa [id_apply, div_self hx] at this
#align continuous_linear_map.norm_id_of_nontrivial_seminorm ContinuousLinearMap.norm_id_of_nontrivial_seminorm
theorem op_norm_smul_le {𝕜' : Type _} [NormedField 𝕜'] [NormedSpace 𝕜' F] [SMulCommClass 𝕜₂ 𝕜' F]
(c : 𝕜') (f : E →SL[σ₁₂] F) : ‖c • f‖ ≤ ‖c‖ * ‖f‖ :=
(c • f).op_norm_le_bound (mul_nonneg (norm_nonneg _) (op_norm_nonneg _)) fun _ =>
by
erw [norm_smul, mul_assoc]
exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _)
#align continuous_linear_map.op_norm_smul_le ContinuousLinearMap.op_norm_smul_le
/-- Continuous linear maps themselves form a seminormed space with respect to
the operator norm. This is only a temporary definition because we want to replace the topology
with `continuous_linear_map.topological_space` to avoid diamond issues.
See Note [forgetful inheritance] -/
protected def tmpSeminormedAddCommGroup : SeminormedAddCommGroup (E →SL[σ₁₂] F) :=
AddGroupSeminorm.toSeminormedAddCommGroup
{ toFun := norm
map_zero' := op_norm_zero
add_le' := op_norm_add_le
neg' := op_norm_neg }
#align continuous_linear_map.tmp_seminormed_add_comm_group ContinuousLinearMap.tmpSeminormedAddCommGroup
/-- The `pseudo_metric_space` structure on `E →SL[σ₁₂] F` coming from
`continuous_linear_map.tmp_seminormed_add_comm_group`.
See Note [forgetful inheritance] -/
protected def tmpPseudoMetricSpace : PseudoMetricSpace (E →SL[σ₁₂] F) :=
ContinuousLinearMap.tmpSeminormedAddCommGroup.toPseudoMetricSpace
#align continuous_linear_map.tmp_pseudo_metric_space ContinuousLinearMap.tmpPseudoMetricSpace
/-- The `uniform_space` structure on `E →SL[σ₁₂] F` coming from
`continuous_linear_map.tmp_seminormed_add_comm_group`.
See Note [forgetful inheritance] -/
protected def tmpUniformSpace : UniformSpace (E →SL[σ₁₂] F) :=
ContinuousLinearMap.tmpPseudoMetricSpace.toUniformSpace
#align continuous_linear_map.tmp_uniform_space ContinuousLinearMap.tmpUniformSpace
/-- The `topological_space` structure on `E →SL[σ₁₂] F` coming from
`continuous_linear_map.tmp_seminormed_add_comm_group`.
See Note [forgetful inheritance] -/
protected def tmpTopologicalSpace : TopologicalSpace (E →SL[σ₁₂] F) :=
ContinuousLinearMap.tmpUniformSpace.toTopologicalSpace
#align continuous_linear_map.tmp_topological_space ContinuousLinearMap.tmpTopologicalSpace
section Tmp
attribute [-instance] ContinuousLinearMap.topologicalSpace
attribute [-instance] ContinuousLinearMap.uniformSpace
attribute [local instance] ContinuousLinearMap.tmpSeminormedAddCommGroup
protected theorem tmp_topologicalAddGroup : TopologicalAddGroup (E →SL[σ₁₂] F) :=
inferInstance
#align continuous_linear_map.tmp_topological_add_group ContinuousLinearMap.tmp_topologicalAddGroup
protected theorem tmp_closedBall_div_subset {a b : ℝ} (ha : 0 < a) (hb : 0 < b) :
closedBall (0 : E →SL[σ₁₂] F) (a / b) ⊆
{ f | ∀ x ∈ closedBall (0 : E) b, f x ∈ closedBall (0 : F) a } :=
by
intro f hf x hx
rw [mem_closedBall_zero_iff] at hf hx⊢
calc
‖f x‖ ≤ ‖f‖ * ‖x‖ := le_op_norm _ _
_ ≤ a / b * b := (mul_le_mul hf hx (norm_nonneg _) (div_pos ha hb).le)
_ = a := div_mul_cancel a hb.ne.symm
#align continuous_linear_map.tmp_closed_ball_div_subset ContinuousLinearMap.tmp_closedBall_div_subset
end Tmp
protected theorem tmp_topology_eq :
(ContinuousLinearMap.tmpTopologicalSpace : TopologicalSpace (E →SL[σ₁₂] F)) =
ContinuousLinearMap.topologicalSpace :=
by
refine'
continuous_linear_map.tmp_topological_add_group.ext inferInstance
((@Metric.nhds_basis_closedBall _ ContinuousLinearMap.tmpPseudoMetricSpace 0).ext
(ContinuousLinearMap.hasBasis_nhds_zero_of_basis Metric.nhds_basis_closedBall) _ _)
· rcases NormedField.exists_norm_lt_one 𝕜 with ⟨c, hc₀, hc₁⟩
refine' fun ε hε =>
⟨⟨closed_ball 0 (1 / ‖c‖), ε⟩, ⟨NormedSpace.isVonNBounded_closedBall _ _ _, hε⟩, fun f hf =>
_⟩
change ∀ x, _ at hf
simp_rw [mem_closedBall_zero_iff] at hf
rw [@mem_closedBall_zero_iff _ SeminormedAddCommGroup.toSeminormedAddGroup]
refine' op_norm_le_of_shell' (div_pos one_pos hc₀) hε.le hc₁ fun x hx₁ hxc => _
rw [div_mul_cancel 1 hc₀.ne.symm] at hx₁
exact (hf x hxc.le).trans (le_mul_of_one_le_right hε.le hx₁)
· rintro ⟨S, ε⟩ ⟨hS, hε⟩
rw [NormedSpace.isVonNBounded_iff, ← bounded_iff_is_bounded] at hS
rcases hS.subset_ball_lt 0 0 with ⟨δ, hδ, hSδ⟩
exact
⟨ε / δ, div_pos hε hδ,
(ContinuousLinearMap.tmp_closedBall_div_subset hε hδ).trans fun f hf x hx => hf x <| hSδ hx⟩
#align continuous_linear_map.tmp_topology_eq ContinuousLinearMap.tmp_topology_eq
protected theorem tmpUniformSpace_eq :
(ContinuousLinearMap.tmpUniformSpace : UniformSpace (E →SL[σ₁₂] F)) =
ContinuousLinearMap.uniformSpace :=
by
rw [← @UniformAddGroup.toUniformSpace_eq _ ContinuousLinearMap.tmpUniformSpace, ←
@UniformAddGroup.toUniformSpace_eq _ ContinuousLinearMap.uniformSpace]
congr 1
exact ContinuousLinearMap.tmp_topology_eq
#align continuous_linear_map.tmp_uniform_space_eq ContinuousLinearMap.tmpUniformSpace_eq
instance toPseudoMetricSpace : PseudoMetricSpace (E →SL[σ₁₂] F) :=
ContinuousLinearMap.tmpPseudoMetricSpace.replaceUniformity
(congr_arg _ ContinuousLinearMap.tmpUniformSpace_eq.symm)
#align continuous_linear_map.to_pseudo_metric_space ContinuousLinearMap.toPseudoMetricSpace
/-- Continuous linear maps themselves form a seminormed space with respect to
the operator norm. -/
instance toSeminormedAddCommGroup : SeminormedAddCommGroup (E →SL[σ₁₂] F)
where dist_eq := ContinuousLinearMap.tmpSeminormedAddCommGroup.dist_eq
#align continuous_linear_map.to_seminormed_add_comm_group ContinuousLinearMap.toSeminormedAddCommGroup
theorem nnnorm_def (f : E →SL[σ₁₂] F) : ‖f‖₊ = infₛ { c | ∀ x, ‖f x‖₊ ≤ c * ‖x‖₊ } :=
by
ext
rw [NNReal.coe_infₛ, coe_nnnorm, norm_def, NNReal.coe_image]
simp_rw [← NNReal.coe_le_coe, NNReal.coe_mul, coe_nnnorm, mem_set_of_eq, Subtype.coe_mk,
exists_prop]
#align continuous_linear_map.nnnorm_def ContinuousLinearMap.nnnorm_def
/-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/
theorem op_nnnorm_le_bound (f : E →SL[σ₁₂] F) (M : ℝ≥0) (hM : ∀ x, ‖f x‖₊ ≤ M * ‖x‖₊) : ‖f‖₊ ≤ M :=
op_norm_le_bound f (zero_le M) hM
#align continuous_linear_map.op_nnnorm_le_bound ContinuousLinearMap.op_nnnorm_le_bound
/-- If one controls the norm of every `A x`, `‖x‖₊ ≠ 0`, then one controls the norm of `A`. -/
theorem op_nnnorm_le_bound' (f : E →SL[σ₁₂] F) (M : ℝ≥0) (hM : ∀ x, ‖x‖₊ ≠ 0 → ‖f x‖₊ ≤ M * ‖x‖₊) :
‖f‖₊ ≤ M :=
op_norm_le_bound' f (zero_le M) fun x hx => hM x <| by rwa [← NNReal.coe_ne_zero]
#align continuous_linear_map.op_nnnorm_le_bound' ContinuousLinearMap.op_nnnorm_le_bound'
/-- For a continuous real linear map `f`, if one controls the norm of every `f x`, `‖x‖₊ = 1`, then
one controls the norm of `f`. -/
theorem op_nnnorm_le_of_unit_nnnorm [NormedSpace ℝ E] [NormedSpace ℝ F] {f : E →L[ℝ] F} {C : ℝ≥0}
(hf : ∀ x, ‖x‖₊ = 1 → ‖f x‖₊ ≤ C) : ‖f‖₊ ≤ C :=
op_norm_le_of_unit_norm C.coe_nonneg fun x hx => hf x <| by rwa [← NNReal.coe_eq_one]
#align continuous_linear_map.op_nnnorm_le_of_unit_nnnorm ContinuousLinearMap.op_nnnorm_le_of_unit_nnnorm
theorem op_nnnorm_le_of_lipschitz {f : E →SL[σ₁₂] F} {K : ℝ≥0} (hf : LipschitzWith K f) :
‖f‖₊ ≤ K :=
op_norm_le_of_lipschitz hf
#align continuous_linear_map.op_nnnorm_le_of_lipschitz ContinuousLinearMap.op_nnnorm_le_of_lipschitz
theorem op_nnnorm_eq_of_bounds {φ : E →SL[σ₁₂] F} (M : ℝ≥0) (h_above : ∀ x, ‖φ x‖ ≤ M * ‖x‖)
(h_below : ∀ N, (∀ x, ‖φ x‖₊ ≤ N * ‖x‖₊) → M ≤ N) : ‖φ‖₊ = M :=
Subtype.ext <| op_norm_eq_of_bounds (zero_le M) h_above <| Subtype.forall'.mpr h_below
#align continuous_linear_map.op_nnnorm_eq_of_bounds ContinuousLinearMap.op_nnnorm_eq_of_bounds
instance toNormedSpace {𝕜' : Type _} [NormedField 𝕜'] [NormedSpace 𝕜' F] [SMulCommClass 𝕜₂ 𝕜' F] :
NormedSpace 𝕜' (E →SL[σ₁₂] F) :=
⟨op_norm_smul_le⟩
#align continuous_linear_map.to_normed_space ContinuousLinearMap.toNormedSpace
include σ₁₃
/-- The operator norm is submultiplicative. -/
theorem op_norm_comp_le (f : E →SL[σ₁₂] F) : ‖h.comp f‖ ≤ ‖h‖ * ‖f‖ :=
cinfₛ_le bounds_bddBelow
⟨mul_nonneg (op_norm_nonneg _) (op_norm_nonneg _), fun x =>
by
rw [mul_assoc]
exact h.le_op_norm_of_le (f.le_op_norm x)⟩
#align continuous_linear_map.op_norm_comp_le ContinuousLinearMap.op_norm_comp_le
theorem op_nnnorm_comp_le [RingHomIsometric σ₁₃] (f : E →SL[σ₁₂] F) : ‖h.comp f‖₊ ≤ ‖h‖₊ * ‖f‖₊ :=
op_norm_comp_le h f
#align continuous_linear_map.op_nnnorm_comp_le ContinuousLinearMap.op_nnnorm_comp_le
omit σ₁₃
/-- Continuous linear maps form a seminormed ring with respect to the operator norm. -/
instance toSemiNormedRing : SeminormedRing (E →L[𝕜] E) :=
{ ContinuousLinearMap.toSeminormedAddCommGroup, ContinuousLinearMap.ring with
norm_mul := fun f g => op_norm_comp_le f g }
#align continuous_linear_map.to_semi_normed_ring ContinuousLinearMap.toSemiNormedRing
/-- For a normed space `E`, continuous linear endomorphisms form a normed algebra with
respect to the operator norm. -/
instance toNormedAlgebra : NormedAlgebra 𝕜 (E →L[𝕜] E) :=
{ ContinuousLinearMap.toNormedSpace, ContinuousLinearMap.algebra with }
#align continuous_linear_map.to_normed_algebra ContinuousLinearMap.toNormedAlgebra
theorem le_op_nnnorm : ‖f x‖₊ ≤ ‖f‖₊ * ‖x‖₊ :=
f.le_op_norm x
#align continuous_linear_map.le_op_nnnorm ContinuousLinearMap.le_op_nnnorm
theorem nndist_le_op_nnnorm (x y : E) : nndist (f x) (f y) ≤ ‖f‖₊ * nndist x y :=
dist_le_op_norm f x y
#align continuous_linear_map.nndist_le_op_nnnorm ContinuousLinearMap.nndist_le_op_nnnorm
/-- continuous linear maps are Lipschitz continuous. -/
theorem lipschitz : LipschitzWith ‖f‖₊ f :=
AddMonoidHomClass.lipschitz_of_bound_nnnorm f _ f.le_op_nnnorm
#align continuous_linear_map.lipschitz ContinuousLinearMap.lipschitz
/-- Evaluation of a continuous linear map `f` at a point is Lipschitz continuous in `f`. -/
theorem lipschitz_apply (x : E) : LipschitzWith ‖x‖₊ fun f : E →SL[σ₁₂] F => f x :=
lipschitzWith_iff_norm_sub_le.2 fun f g => ((f - g).le_op_norm x).trans_eq (mul_comm _ _)
#align continuous_linear_map.lipschitz_apply ContinuousLinearMap.lipschitz_apply
end
section Sup
variable [RingHomIsometric σ₁₂]
theorem exists_mul_lt_apply_of_lt_op_nnnorm (f : E →SL[σ₁₂] F) {r : ℝ≥0} (hr : r < ‖f‖₊) :
∃ x, r * ‖x‖₊ < ‖f x‖₊ := by
simpa only [not_forall, not_le, Set.mem_setOf] using
not_mem_of_lt_cinfₛ (nnnorm_def f ▸ hr : r < Inf { c : ℝ≥0 | ∀ x, ‖f x‖₊ ≤ c * ‖x‖₊ })
(OrderBot.bddBelow _)
#align continuous_linear_map.exists_mul_lt_apply_of_lt_op_nnnorm ContinuousLinearMap.exists_mul_lt_apply_of_lt_op_nnnorm
theorem exists_mul_lt_of_lt_op_norm (f : E →SL[σ₁₂] F) {r : ℝ} (hr₀ : 0 ≤ r) (hr : r < ‖f‖) :
∃ x, r * ‖x‖ < ‖f x‖ := by
lift r to ℝ≥0 using hr₀
exact f.exists_mul_lt_apply_of_lt_op_nnnorm hr
#align continuous_linear_map.exists_mul_lt_of_lt_op_norm ContinuousLinearMap.exists_mul_lt_of_lt_op_norm
theorem exists_lt_apply_of_lt_op_nnnorm {𝕜 𝕜₂ E F : Type _} [NormedAddCommGroup E]
[SeminormedAddCommGroup F] [DenselyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] {σ₁₂ : 𝕜 →+* 𝕜₂}
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) {r : ℝ≥0}
(hr : r < ‖f‖₊) : ∃ x : E, ‖x‖₊ < 1 ∧ r < ‖f x‖₊ :=
by
obtain ⟨y, hy⟩ := f.exists_mul_lt_apply_of_lt_op_nnnorm hr
have hy' : ‖y‖₊ ≠ 0 :=
nnnorm_ne_zero_iff.2 fun heq => by
simpa only [HEq, nnnorm_zero, map_zero, not_lt_zero'] using hy
have hfy : ‖f y‖₊ ≠ 0 := (zero_le'.trans_lt hy).ne'
rw [← inv_inv ‖f y‖₊, NNReal.lt_inv_iff_mul_lt (inv_ne_zero hfy), mul_assoc, mul_comm ‖y‖₊, ←
mul_assoc, ← NNReal.lt_inv_iff_mul_lt hy'] at hy
obtain ⟨k, hk₁, hk₂⟩ := NormedField.exists_lt_nnnorm_lt 𝕜 hy
refine' ⟨k • y, (nnnorm_smul k y).symm ▸ (NNReal.lt_inv_iff_mul_lt hy').1 hk₂, _⟩
have : ‖σ₁₂ k‖₊ = ‖k‖₊ := Subtype.ext RingHomIsometric.is_iso
rwa [map_smulₛₗ f, nnnorm_smul, ← NNReal.div_lt_iff hfy, div_eq_mul_inv, this]
#align continuous_linear_map.exists_lt_apply_of_lt_op_nnnorm ContinuousLinearMap.exists_lt_apply_of_lt_op_nnnorm
theorem exists_lt_apply_of_lt_op_norm {𝕜 𝕜₂ E F : Type _} [NormedAddCommGroup E]
[SeminormedAddCommGroup F] [DenselyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] {σ₁₂ : 𝕜 →+* 𝕜₂}
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) {r : ℝ}
(hr : r < ‖f‖) : ∃ x : E, ‖x‖ < 1 ∧ r < ‖f x‖ :=
by
by_cases hr₀ : r < 0
· exact ⟨0, by simpa using hr₀⟩
· lift r to ℝ≥0 using not_lt.1 hr₀
exact f.exists_lt_apply_of_lt_op_nnnorm hr
#align continuous_linear_map.exists_lt_apply_of_lt_op_norm ContinuousLinearMap.exists_lt_apply_of_lt_op_norm
theorem supₛ_unit_ball_eq_nnnorm {𝕜 𝕜₂ E F : Type _} [NormedAddCommGroup E]
[SeminormedAddCommGroup F] [DenselyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] {σ₁₂ : 𝕜 →+* 𝕜₂}
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) :
supₛ ((fun x => ‖f x‖₊) '' ball 0 1) = ‖f‖₊ :=
by
refine'
csupₛ_eq_of_forall_le_of_forall_lt_exists_gt ((nonempty_ball.mpr zero_lt_one).image _) _
fun ub hub => _
· rintro - ⟨x, hx, rfl⟩
simpa only [mul_one] using f.le_op_norm_of_le (mem_ball_zero_iff.1 hx).le
· obtain ⟨x, hx, hxf⟩ := f.exists_lt_apply_of_lt_op_nnnorm hub
exact ⟨_, ⟨x, mem_ball_zero_iff.2 hx, rfl⟩, hxf⟩
#align continuous_linear_map.Sup_unit_ball_eq_nnnorm ContinuousLinearMap.supₛ_unit_ball_eq_nnnorm
theorem supₛ_unit_ball_eq_norm {𝕜 𝕜₂ E F : Type _} [NormedAddCommGroup E] [SeminormedAddCommGroup F]
[DenselyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] {σ₁₂ : 𝕜 →+* 𝕜₂} [NormedSpace 𝕜 E]
[NormedSpace 𝕜₂ F] [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) :
supₛ ((fun x => ‖f x‖) '' ball 0 1) = ‖f‖ := by
simpa only [NNReal.coe_supₛ, Set.image_image] using NNReal.coe_eq.2 f.Sup_unit_ball_eq_nnnorm
#align continuous_linear_map.Sup_unit_ball_eq_norm ContinuousLinearMap.supₛ_unit_ball_eq_norm
theorem supₛ_closed_unit_ball_eq_nnnorm {𝕜 𝕜₂ E F : Type _} [NormedAddCommGroup E]
[SeminormedAddCommGroup F] [DenselyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] {σ₁₂ : 𝕜 →+* 𝕜₂}
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) :
supₛ ((fun x => ‖f x‖₊) '' closedBall 0 1) = ‖f‖₊ :=
by
have hbdd : ∀ y ∈ (fun x => ‖f x‖₊) '' closed_ball 0 1, y ≤ ‖f‖₊ :=
by
rintro - ⟨x, hx, rfl⟩
exact f.unit_le_op_norm x (mem_closedBall_zero_iff.1 hx)
refine' le_antisymm (csupₛ_le ((nonempty_closed_ball.mpr zero_le_one).image _) hbdd) _
rw [← Sup_unit_ball_eq_nnnorm]
exact
csupₛ_le_csupₛ ⟨‖f‖₊, hbdd⟩ ((nonempty_ball.2 zero_lt_one).image _)
(Set.image_subset _ ball_subset_closed_ball)
#align continuous_linear_map.Sup_closed_unit_ball_eq_nnnorm ContinuousLinearMap.supₛ_closed_unit_ball_eq_nnnorm
theorem supₛ_closed_unit_ball_eq_norm {𝕜 𝕜₂ E F : Type _} [NormedAddCommGroup E]
[SeminormedAddCommGroup F] [DenselyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] {σ₁₂ : 𝕜 →+* 𝕜₂}
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) :
supₛ ((fun x => ‖f x‖) '' closedBall 0 1) = ‖f‖ := by
simpa only [NNReal.coe_supₛ, Set.image_image] using
NNReal.coe_eq.2 f.Sup_closed_unit_ball_eq_nnnorm
#align continuous_linear_map.Sup_closed_unit_ball_eq_norm ContinuousLinearMap.supₛ_closed_unit_ball_eq_norm
end Sup
section
theorem op_norm_ext [RingHomIsometric σ₁₃] (f : E →SL[σ₁₂] F) (g : E →SL[σ₁₃] G)
(h : ∀ x, ‖f x‖ = ‖g x‖) : ‖f‖ = ‖g‖ :=
op_norm_eq_of_bounds (norm_nonneg _)
(fun x => by
rw [h x]
exact le_op_norm _ _)
fun c hc h₂ =>
op_norm_le_bound _ hc fun z => by
rw [← h z]
exact h₂ z
#align continuous_linear_map.op_norm_ext ContinuousLinearMap.op_norm_ext
variable [RingHomIsometric σ₂₃]
theorem op_norm_le_bound₂ (f : E →SL[σ₁₃] F →SL[σ₂₃] G) {C : ℝ} (h0 : 0 ≤ C)
(hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) : ‖f‖ ≤ C :=
f.op_norm_le_bound h0 fun x => (f x).op_norm_le_bound (mul_nonneg h0 (norm_nonneg _)) <| hC x
#align continuous_linear_map.op_norm_le_bound₂ ContinuousLinearMap.op_norm_le_bound₂
theorem le_op_norm₂ [RingHomIsometric σ₁₃] (f : E →SL[σ₁₃] F →SL[σ₂₃] G) (x : E) (y : F) :
‖f x y‖ ≤ ‖f‖ * ‖x‖ * ‖y‖ :=
(f x).le_of_op_norm_le (f.le_op_norm x) y
#align continuous_linear_map.le_op_norm₂ ContinuousLinearMap.le_op_norm₂
end
@[simp]
theorem op_norm_prod (f : E →L[𝕜] Fₗ) (g : E →L[𝕜] Gₗ) : ‖f.Prod g‖ = ‖(f, g)‖ :=
le_antisymm
(op_norm_le_bound _ (norm_nonneg _) fun x => by
simpa only [prod_apply, Prod.norm_def, max_mul_of_nonneg, norm_nonneg] using
max_le_max (le_op_norm f x) (le_op_norm g x)) <|
max_le
(op_norm_le_bound _ (norm_nonneg _) fun x =>
(le_max_left _ _).trans ((f.Prod g).le_op_norm x))
(op_norm_le_bound _ (norm_nonneg _) fun x =>
(le_max_right _ _).trans ((f.Prod g).le_op_norm x))
#align continuous_linear_map.op_norm_prod ContinuousLinearMap.op_norm_prod
@[simp]
theorem op_nnnorm_prod (f : E →L[𝕜] Fₗ) (g : E →L[𝕜] Gₗ) : ‖f.Prod g‖₊ = ‖(f, g)‖₊ :=
Subtype.ext <| op_norm_prod f g
#align continuous_linear_map.op_nnnorm_prod ContinuousLinearMap.op_nnnorm_prod
/-- `continuous_linear_map.prod` as a `linear_isometry_equiv`. -/
def prodₗᵢ (R : Type _) [Semiring R] [Module R Fₗ] [Module R Gₗ] [ContinuousConstSMul R Fₗ]
[ContinuousConstSMul R Gₗ] [SMulCommClass 𝕜 R Fₗ] [SMulCommClass 𝕜 R Gₗ] :
(E →L[𝕜] Fₗ) × (E →L[𝕜] Gₗ) ≃ₗᵢ[R] E →L[𝕜] Fₗ × Gₗ :=
⟨prodₗ R, fun ⟨f, g⟩ => op_norm_prod f g⟩
#align continuous_linear_map.prodₗᵢ ContinuousLinearMap.prodₗᵢ
variable [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F)
@[simp, nontriviality]
theorem op_norm_subsingleton [Subsingleton E] : ‖f‖ = 0 :=
by
refine' le_antisymm _ (norm_nonneg _)
apply op_norm_le_bound _ rfl.ge
intro x
simp [Subsingleton.elim x 0]
#align continuous_linear_map.op_norm_subsingleton ContinuousLinearMap.op_norm_subsingleton
end OpNorm
section IsO
variable [RingHomIsometric σ₁₂] (c : 𝕜) (f g : E →SL[σ₁₂] F) (h : F →SL[σ₂₃] G) (x y z : E)
open Asymptotics
theorem isOWith_id (l : Filter E) : IsOWith ‖f‖ l f fun x => x :=
isOWith_of_le' _ f.le_op_norm
#align continuous_linear_map.is_O_with_id ContinuousLinearMap.isOWith_id
theorem isO_id (l : Filter E) : f =O[l] fun x => x :=
(f.isOWith_id l).IsO
#align continuous_linear_map.is_O_id ContinuousLinearMap.isO_id
theorem isOWith_comp [RingHomIsometric σ₂₃] {α : Type _} (g : F →SL[σ₂₃] G) (f : α → F)
(l : Filter α) : IsOWith ‖g‖ l (fun x' => g (f x')) f :=
(g.isOWith_id ⊤).comp_tendsto le_top
#align continuous_linear_map.is_O_with_comp ContinuousLinearMap.isOWith_comp
theorem isO_comp [RingHomIsometric σ₂₃] {α : Type _} (g : F →SL[σ₂₃] G) (f : α → F) (l : Filter α) :
(fun x' => g (f x')) =O[l] f :=
(g.isOWith_comp f l).IsO
#align continuous_linear_map.is_O_comp ContinuousLinearMap.isO_comp
theorem isOWith_sub (f : E →SL[σ₁₂] F) (l : Filter E) (x : E) :
IsOWith ‖f‖ l (fun x' => f (x' - x)) fun x' => x' - x :=
f.isOWith_comp _ l
#align continuous_linear_map.is_O_with_sub ContinuousLinearMap.isOWith_sub
theorem isO_sub (f : E →SL[σ₁₂] F) (l : Filter E) (x : E) :
(fun x' => f (x' - x)) =O[l] fun x' => x' - x :=
f.isO_comp _ l
#align continuous_linear_map.is_O_sub ContinuousLinearMap.isO_sub
end IsO
end ContinuousLinearMap
namespace LinearIsometry
theorem norm_toContinuousLinearMap_le (f : E →ₛₗᵢ[σ₁₂] F) : ‖f.toContinuousLinearMap‖ ≤ 1 :=
f.toContinuousLinearMap.op_norm_le_bound zero_le_one fun x => by simp
#align linear_isometry.norm_to_continuous_linear_map_le LinearIsometry.norm_toContinuousLinearMap_le
end LinearIsometry
namespace LinearMap
/-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`,
then its norm is bounded by the bound given to the constructor if it is nonnegative. -/
theorem mkContinuous_norm_le (f : E →ₛₗ[σ₁₂] F) {C : ℝ} (hC : 0 ≤ C) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) :
‖f.mkContinuous C h‖ ≤ C :=
ContinuousLinearMap.op_norm_le_bound _ hC h
#align linear_map.mk_continuous_norm_le LinearMap.mkContinuous_norm_le
/-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`,
then its norm is bounded by the bound or zero if bound is negative. -/
theorem mkContinuous_norm_le' (f : E →ₛₗ[σ₁₂] F) {C : ℝ} (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) :
‖f.mkContinuous C h‖ ≤ max C 0 :=
ContinuousLinearMap.op_norm_le_bound _ (le_max_right _ _) fun x =>
(h x).trans <| mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg x)
#align linear_map.mk_continuous_norm_le' LinearMap.mkContinuous_norm_le'
variable [RingHomIsometric σ₂₃]
/-- Create a bilinear map (represented as a map `E →L[𝕜] F →L[𝕜] G`) from the corresponding linear
map and a bound on the norm of the image. The linear map can be constructed using
`linear_map.mk₂`. -/
def mkContinuous₂ (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) (C : ℝ) (hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) :
E →SL[σ₁₃] F →SL[σ₂₃] G :=
LinearMap.mkContinuous
{ toFun := fun x => (f x).mkContinuous (C * ‖x‖) (hC x)
map_add' := fun x y => by
ext z
rw [ContinuousLinearMap.add_apply, mk_continuous_apply, mk_continuous_apply,
mk_continuous_apply, map_add, add_apply]
map_smul' := fun c x => by
ext z
rw [ContinuousLinearMap.smul_apply, mk_continuous_apply, mk_continuous_apply, map_smulₛₗ,
smul_apply] }
(max C 0) fun x =>
(mkContinuous_norm_le' _ _).trans_eq <| by
rw [max_mul_of_nonneg _ _ (norm_nonneg x), MulZeroClass.zero_mul]
#align linear_map.mk_continuous₂ LinearMap.mkContinuous₂
@[simp]
theorem mkContinuous₂_apply (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) {C : ℝ}
(hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) (x : E) (y : F) : f.mkContinuous₂ C hC x y = f x y :=
rfl
#align linear_map.mk_continuous₂_apply LinearMap.mkContinuous₂_apply
theorem mkContinuous₂_norm_le' (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) {C : ℝ}
(hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) : ‖f.mkContinuous₂ C hC‖ ≤ max C 0 :=
mkContinuous_norm_le _ (le_max_iff.2 <| Or.inr le_rfl) _
#align linear_map.mk_continuous₂_norm_le' LinearMap.mkContinuous₂_norm_le'
theorem mkContinuous₂_norm_le (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) {C : ℝ} (h0 : 0 ≤ C)
(hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) : ‖f.mkContinuous₂ C hC‖ ≤ C :=
(f.mkContinuous₂_norm_le' hC).trans_eq <| max_eq_left h0
#align linear_map.mk_continuous₂_norm_le LinearMap.mkContinuous₂_norm_le
end LinearMap
namespace ContinuousLinearMap
variable [RingHomIsometric σ₂₃] [RingHomIsometric σ₁₃]
/-- Flip the order of arguments of a continuous bilinear map.
For a version bundled as `linear_isometry_equiv`, see
`continuous_linear_map.flipL`. -/
def flip (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : F →SL[σ₂₃] E →SL[σ₁₃] G :=
LinearMap.mkContinuous₂
(LinearMap.mk₂'ₛₗ σ₂₃ σ₁₃ (fun y x => f x y) (fun x y z => (f z).map_add x y)
(fun c y x => (f x).map_smulₛₗ c y) (fun z x y => by rw [f.map_add, add_apply]) fun c y x =>
by rw [f.map_smulₛₗ, smul_apply])
‖f‖ fun y x => (f.le_op_norm₂ x y).trans_eq <| by rw [mul_right_comm]
#align continuous_linear_map.flip ContinuousLinearMap.flip
private theorem le_norm_flip (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : ‖f‖ ≤ ‖flip f‖ :=
f.op_norm_le_bound₂ (norm_nonneg _) fun x y =>
by
rw [mul_right_comm]
exact (flip f).le_op_norm₂ y x
#align continuous_linear_map.le_norm_flip continuous_linear_map.le_norm_flip
@[simp]
theorem flip_apply (f : E →SL[σ₁₃] F →SL[σ₂₃] G) (x : E) (y : F) : f.flip y x = f x y :=
rfl
#align continuous_linear_map.flip_apply ContinuousLinearMap.flip_apply
@[simp]
theorem flip_flip (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : f.flip.flip = f :=
by
ext
rfl
#align continuous_linear_map.flip_flip ContinuousLinearMap.flip_flip
@[simp]
theorem op_norm_flip (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : ‖f.flip‖ = ‖f‖ :=
le_antisymm (by simpa only [flip_flip] using le_norm_flip f.flip) (le_norm_flip f)
#align continuous_linear_map.op_norm_flip ContinuousLinearMap.op_norm_flip
@[simp]
theorem flip_add (f g : E →SL[σ₁₃] F →SL[σ₂₃] G) : (f + g).flip = f.flip + g.flip :=
rfl
#align continuous_linear_map.flip_add ContinuousLinearMap.flip_add
@[simp]
theorem flip_smul (c : 𝕜₃) (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : (c • f).flip = c • f.flip :=
rfl
#align continuous_linear_map.flip_smul ContinuousLinearMap.flip_smul
variable (E F G σ₁₃ σ₂₃)
/-- Flip the order of arguments of a continuous bilinear map.
This is a version bundled as a `linear_isometry_equiv`.
For an unbundled version see `continuous_linear_map.flip`. -/
def flipₗᵢ' : (E →SL[σ₁₃] F →SL[σ₂₃] G) ≃ₗᵢ[𝕜₃] F →SL[σ₂₃] E →SL[σ₁₃] G
where
toFun := flip
invFun := flip
map_add' := flip_add
map_smul' := flip_smul
left_inv := flip_flip
right_inv := flip_flip
norm_map' := op_norm_flip
#align continuous_linear_map.flipₗᵢ' ContinuousLinearMap.flipₗᵢ'
variable {E F G σ₁₃ σ₂₃}
@[simp]
theorem flipₗᵢ'_symm : (flipₗᵢ' E F G σ₂₃ σ₁₃).symm = flipₗᵢ' F E G σ₁₃ σ₂₃ :=
rfl
#align continuous_linear_map.flipₗᵢ'_symm ContinuousLinearMap.flipₗᵢ'_symm
@[simp]
theorem coe_flipₗᵢ' : ⇑(flipₗᵢ' E F G σ₂₃ σ₁₃) = flip :=
rfl
#align continuous_linear_map.coe_flipₗᵢ' ContinuousLinearMap.coe_flipₗᵢ'
variable (𝕜 E Fₗ Gₗ)
/-- Flip the order of arguments of a continuous bilinear map.
This is a version bundled as a `linear_isometry_equiv`.
For an unbundled version see `continuous_linear_map.flip`. -/
def flipₗᵢ : (E →L[𝕜] Fₗ →L[𝕜] Gₗ) ≃ₗᵢ[𝕜] Fₗ →L[𝕜] E →L[𝕜] Gₗ
where
toFun := flip
invFun := flip
map_add' := flip_add
map_smul' := flip_smul
left_inv := flip_flip
right_inv := flip_flip
norm_map' := op_norm_flip
#align continuous_linear_map.flipₗᵢ ContinuousLinearMap.flipₗᵢ
variable {𝕜 E Fₗ Gₗ}
@[simp]
theorem flipₗᵢ_symm : (flipₗᵢ 𝕜 E Fₗ Gₗ).symm = flipₗᵢ 𝕜 Fₗ E Gₗ :=
rfl
#align continuous_linear_map.flipₗᵢ_symm ContinuousLinearMap.flipₗᵢ_symm
@[simp]
theorem coe_flipₗᵢ : ⇑(flipₗᵢ 𝕜 E Fₗ Gₗ) = flip :=
rfl
#align continuous_linear_map.coe_flipₗᵢ ContinuousLinearMap.coe_flipₗᵢ
variable (F σ₁₂) [RingHomIsometric σ₁₂]
/-- The continuous semilinear map obtained by applying a continuous semilinear map at a given
vector.
This is the continuous version of `linear_map.applyₗ`. -/
def apply' : E →SL[σ₁₂] (E →SL[σ₁₂] F) →L[𝕜₂] F :=
flip (id 𝕜₂ (E →SL[σ₁₂] F))
#align continuous_linear_map.apply' ContinuousLinearMap.apply'
variable {F σ₁₂}
@[simp]
theorem apply_apply' (v : E) (f : E →SL[σ₁₂] F) : apply' F σ₁₂ v f = f v :=
rfl
#align continuous_linear_map.apply_apply' ContinuousLinearMap.apply_apply'
variable (𝕜 Fₗ)
/-- The continuous semilinear map obtained by applying a continuous semilinear map at a given
vector.
This is the continuous version of `linear_map.applyₗ`. -/
def apply : E →L[𝕜] (E →L[𝕜] Fₗ) →L[𝕜] Fₗ :=
flip (id 𝕜 (E →L[𝕜] Fₗ))
#align continuous_linear_map.apply ContinuousLinearMap.apply
variable {𝕜 Fₗ}
@[simp]
theorem apply_apply (v : E) (f : E →L[𝕜] Fₗ) : apply 𝕜 Fₗ v f = f v :=
rfl
#align continuous_linear_map.apply_apply ContinuousLinearMap.apply_apply
variable (σ₁₂ σ₂₃ E F G)
/-- Composition of continuous semilinear maps as a continuous semibilinear map. -/
def compSL : (F →SL[σ₂₃] G) →L[𝕜₃] (E →SL[σ₁₂] F) →SL[σ₂₃] E →SL[σ₁₃] G :=
LinearMap.mkContinuous₂
(LinearMap.mk₂'ₛₗ (RingHom.id 𝕜₃) σ₂₃ comp add_comp smul_comp comp_add fun c f g =>
by
ext
simp only [ContinuousLinearMap.map_smulₛₗ, coe_smul', coe_comp', Function.comp_apply,
Pi.smul_apply])
1 fun f g => by simpa only [one_mul] using op_norm_comp_le f g
#align continuous_linear_map.compSL ContinuousLinearMap.compSL
include σ₁₃
theorem norm_compSL_le : ‖compSL E F G σ₁₂ σ₂₃‖ ≤ 1 :=
LinearMap.mkContinuous₂_norm_le _ zero_le_one _
#align continuous_linear_map.norm_compSL_le ContinuousLinearMap.norm_compSL_le
variable {𝕜 σ₁₂ σ₂₃ E F G}
@[simp]
theorem compSL_apply (f : F →SL[σ₂₃] G) (g : E →SL[σ₁₂] F) : compSL E F G σ₁₂ σ₂₃ f g = f.comp g :=
rfl
#align continuous_linear_map.compSL_apply ContinuousLinearMap.compSL_apply
theorem Continuous.const_clm_comp {X} [TopologicalSpace X] {f : X → E →SL[σ₁₂] F}
(hf : Continuous f) (g : F →SL[σ₂₃] G) :
Continuous (fun x => g.comp (f x) : X → E →SL[σ₁₃] G) :=
(compSL E F G σ₁₂ σ₂₃ g).Continuous.comp hf
#align continuous.const_clm_comp Continuous.const_clm_comp
-- Giving the implicit argument speeds up elaboration significantly
theorem Continuous.clm_comp_const {X} [TopologicalSpace X] {g : X → F →SL[σ₂₃] G}
(hg : Continuous g) (f : E →SL[σ₁₂] F) :
Continuous (fun x => (g x).comp f : X → E →SL[σ₁₃] G) :=
(@ContinuousLinearMap.flip _ _ _ _ _ (E →SL[σ₁₃] G) _ _ _ _ _ _ _ _ _ _ _ _ _
(compSL E F G σ₁₂ σ₂₃) f).Continuous.comp
hg
#align continuous.clm_comp_const Continuous.clm_comp_const
omit σ₁₃
variable (𝕜 σ₁₂ σ₂₃ E Fₗ Gₗ)
/-- Composition of continuous linear maps as a continuous bilinear map. -/
def compL : (Fₗ →L[𝕜] Gₗ) →L[𝕜] (E →L[𝕜] Fₗ) →L[𝕜] E →L[𝕜] Gₗ :=
compSL E Fₗ Gₗ (RingHom.id 𝕜) (RingHom.id 𝕜)
#align continuous_linear_map.compL ContinuousLinearMap.compL
theorem norm_compL_le : ‖compL 𝕜 E Fₗ Gₗ‖ ≤ 1 :=
norm_compSL_le _ _ _ _ _
#align continuous_linear_map.norm_compL_le ContinuousLinearMap.norm_compL_le
@[simp]
theorem compL_apply (f : Fₗ →L[𝕜] Gₗ) (g : E →L[𝕜] Fₗ) : compL 𝕜 E Fₗ Gₗ f g = f.comp g :=
rfl
#align continuous_linear_map.compL_apply ContinuousLinearMap.compL_apply
variable (Eₗ) {𝕜 E Fₗ Gₗ}
/-- Apply `L(x,-)` pointwise to bilinear maps, as a continuous bilinear map -/
@[simps apply]
def precompR (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : E →L[𝕜] (Eₗ →L[𝕜] Fₗ) →L[𝕜] Eₗ →L[𝕜] Gₗ :=
(compL 𝕜 Eₗ Fₗ Gₗ).comp L
#align continuous_linear_map.precompR ContinuousLinearMap.precompR
/-- Apply `L(-,y)` pointwise to bilinear maps, as a continuous bilinear map -/
def precompL (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : (Eₗ →L[𝕜] E) →L[𝕜] Fₗ →L[𝕜] Eₗ →L[𝕜] Gₗ :=
(precompR Eₗ (flip L)).flip
#align continuous_linear_map.precompL ContinuousLinearMap.precompL
theorem norm_precompR_le (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : ‖precompR Eₗ L‖ ≤ ‖L‖ :=
calc
‖precompR Eₗ L‖ ≤ ‖compL 𝕜 Eₗ Fₗ Gₗ‖ * ‖L‖ := op_norm_comp_le _ _
_ ≤ 1 * ‖L‖ := (mul_le_mul_of_nonneg_right (norm_compL_le _ _ _ _) (norm_nonneg _))
_ = ‖L‖ := by rw [one_mul]
#align continuous_linear_map.norm_precompR_le ContinuousLinearMap.norm_precompR_le
theorem norm_precompL_le (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : ‖precompL Eₗ L‖ ≤ ‖L‖ :=
by
rw [precompL, op_norm_flip, ← op_norm_flip L]
exact norm_precompR_le _ L.flip
#align continuous_linear_map.norm_precompL_le ContinuousLinearMap.norm_precompL_le
section Prod
universe u₁ u₂ u₃ u₄
variable (M₁ : Type u₁) [SeminormedAddCommGroup M₁] [NormedSpace 𝕜 M₁] (M₂ : Type u₂)
[SeminormedAddCommGroup M₂] [NormedSpace 𝕜 M₂] (M₃ : Type u₃) [SeminormedAddCommGroup M₃]
[NormedSpace 𝕜 M₃] (M₄ : Type u₄) [SeminormedAddCommGroup M₄] [NormedSpace 𝕜 M₄]
variable {Eₗ} (𝕜)
/-- `continuous_linear_map.prod_map` as a continuous linear map. -/
def prodMapL : (M₁ →L[𝕜] M₂) × (M₃ →L[𝕜] M₄) →L[𝕜] M₁ × M₃ →L[𝕜] M₂ × M₄ :=
ContinuousLinearMap.copy
(have Φ₁ : (M₁ →L[𝕜] M₂) →L[𝕜] M₁ →L[𝕜] M₂ × M₄ :=
ContinuousLinearMap.compL 𝕜 M₁ M₂ (M₂ × M₄) (ContinuousLinearMap.inl 𝕜 M₂ M₄)
have Φ₂ : (M₃ →L[𝕜] M₄) →L[𝕜] M₃ →L[𝕜] M₂ × M₄ :=
ContinuousLinearMap.compL 𝕜 M₃ M₄ (M₂ × M₄) (ContinuousLinearMap.inr 𝕜 M₂ M₄)
have Φ₁' :=
(ContinuousLinearMap.compL 𝕜 (M₁ × M₃) M₁ (M₂ × M₄)).flip (ContinuousLinearMap.fst 𝕜 M₁ M₃)
have Φ₂' :=
(ContinuousLinearMap.compL 𝕜 (M₁ × M₃) M₃ (M₂ × M₄)).flip (ContinuousLinearMap.snd 𝕜 M₁ M₃)
have Ψ₁ : (M₁ →L[𝕜] M₂) × (M₃ →L[𝕜] M₄) →L[𝕜] M₁ →L[𝕜] M₂ :=
ContinuousLinearMap.fst 𝕜 (M₁ →L[𝕜] M₂) (M₃ →L[𝕜] M₄)
have Ψ₂ : (M₁ →L[𝕜] M₂) × (M₃ →L[𝕜] M₄) →L[𝕜] M₃ →L[𝕜] M₄ :=
ContinuousLinearMap.snd 𝕜 (M₁ →L[𝕜] M₂) (M₃ →L[𝕜] M₄)
Φ₁' ∘L Φ₁ ∘L Ψ₁ + Φ₂' ∘L Φ₂ ∘L Ψ₂)
(fun p : (M₁ →L[𝕜] M₂) × (M₃ →L[𝕜] M₄) => p.1.Prod_map p.2)
(by
apply funext
rintro ⟨φ, ψ⟩
apply ContinuousLinearMap.ext fun x => _
simp only [add_apply, coe_comp', coe_fst', Function.comp_apply, compL_apply, flip_apply,
coe_snd', inl_apply, inr_apply, Prod.mk_add_mk, add_zero, zero_add, coe_prod_map', Prod_map,
Prod.mk.inj_iff, eq_self_iff_true, and_self_iff]
rfl)
#align continuous_linear_map.prod_mapL ContinuousLinearMap.prodMapL
variable {M₁ M₂ M₃ M₄}
@[simp]
theorem prodMapL_apply (p : (M₁ →L[𝕜] M₂) × (M₃ →L[𝕜] M₄)) :
ContinuousLinearMap.prodMapL 𝕜 M₁ M₂ M₃ M₄ p = p.1.Prod_map p.2 :=
rfl
#align continuous_linear_map.prod_mapL_apply ContinuousLinearMap.prodMapL_apply
variable {X : Type _} [TopologicalSpace X]
theorem Continuous.prod_mapL {f : X → M₁ →L[𝕜] M₂} {g : X → M₃ →L[𝕜] M₄} (hf : Continuous f)
(hg : Continuous g) : Continuous fun x => (f x).Prod_map (g x) :=
(prodMapL 𝕜 M₁ M₂ M₃ M₄).Continuous.comp (hf.prod_mk hg)
#align continuous.prod_mapL Continuous.prod_mapL
theorem Continuous.prod_map_equivL {f : X → M₁ ≃L[𝕜] M₂} {g : X → M₃ ≃L[𝕜] M₄}
(hf : Continuous fun x => (f x : M₁ →L[𝕜] M₂)) (hg : Continuous fun x => (g x : M₃ →L[𝕜] M₄)) :
Continuous fun x => ((f x).Prod (g x) : M₁ × M₃ →L[𝕜] M₂ × M₄) :=
(prodMapL 𝕜 M₁ M₂ M₃ M₄).Continuous.comp (hf.prod_mk hg)
#align continuous.prod_map_equivL Continuous.prod_map_equivL
theorem ContinuousOn.prod_mapL {f : X → M₁ →L[𝕜] M₂} {g : X → M₃ →L[𝕜] M₄} {s : Set X}
(hf : ContinuousOn f s) (hg : ContinuousOn g s) :
ContinuousOn (fun x => (f x).Prod_map (g x)) s :=
((prodMapL 𝕜 M₁ M₂ M₃ M₄).Continuous.comp_continuousOn (hf.Prod hg) : _)
#align continuous_on.prod_mapL ContinuousOn.prod_mapL
theorem ContinuousOn.prod_map_equivL {f : X → M₁ ≃L[𝕜] M₂} {g : X → M₃ ≃L[𝕜] M₄} {s : Set X}
(hf : ContinuousOn (fun x => (f x : M₁ →L[𝕜] M₂)) s)
(hg : ContinuousOn (fun x => (g x : M₃ →L[𝕜] M₄)) s) :
ContinuousOn (fun x => ((f x).Prod (g x) : M₁ × M₃ →L[𝕜] M₂ × M₄)) s :=
(prodMapL 𝕜 M₁ M₂ M₃ M₄).Continuous.comp_continuousOn (hf.Prod hg)
#align continuous_on.prod_map_equivL ContinuousOn.prod_map_equivL
end Prod
variable {𝕜 E Fₗ Gₗ}
section MultiplicationLinear
section NonUnital
variable (𝕜) (𝕜' : Type _) [NonUnitalSeminormedRing 𝕜'] [NormedSpace 𝕜 𝕜'] [IsScalarTower 𝕜 𝕜' 𝕜']
[SMulCommClass 𝕜 𝕜' 𝕜']
/-- Multiplication in a non-unital normed algebra as a continuous bilinear map. -/
def mul : 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' :=
(LinearMap.mul 𝕜 𝕜').mkContinuous₂ 1 fun x y => by simpa using norm_mul_le x y
#align continuous_linear_map.mul ContinuousLinearMap.mul
@[simp]
theorem mul_apply' (x y : 𝕜') : mul 𝕜 𝕜' x y = x * y :=
rfl
#align continuous_linear_map.mul_apply' ContinuousLinearMap.mul_apply'
@[simp]
theorem op_norm_mul_apply_le (x : 𝕜') : ‖mul 𝕜 𝕜' x‖ ≤ ‖x‖ :=
op_norm_le_bound _ (norm_nonneg x) (norm_mul_le x)
#align continuous_linear_map.op_norm_mul_apply_le ContinuousLinearMap.op_norm_mul_apply_le
theorem op_norm_mul_le : ‖mul 𝕜 𝕜'‖ ≤ 1 :=
LinearMap.mkContinuous₂_norm_le _ zero_le_one _
#align continuous_linear_map.op_norm_mul_le ContinuousLinearMap.op_norm_mul_le
/-- Simultaneous left- and right-multiplication in a non-unital normed algebra, considered as a
continuous trilinear map. This is akin to its non-continuous version `linear_map.mul_left_right`,
but there is a minor difference: `linear_map.mul_left_right` is uncurried. -/
def mulLeftRight : 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' :=
((compL 𝕜 𝕜' 𝕜' 𝕜').comp (mul 𝕜 𝕜').flip).flip.comp (mul 𝕜 𝕜')
#align continuous_linear_map.mul_left_right ContinuousLinearMap.mulLeftRight
@[simp]
theorem mulLeftRight_apply (x y z : 𝕜') : mulLeftRight 𝕜 𝕜' x y z = x * z * y :=
rfl
#align continuous_linear_map.mul_left_right_apply ContinuousLinearMap.mulLeftRight_apply
theorem op_norm_mulLeftRight_apply_apply_le (x y : 𝕜') : ‖mulLeftRight 𝕜 𝕜' x y‖ ≤ ‖x‖ * ‖y‖ :=
(op_norm_comp_le _ _).trans <|
(mul_comm _ _).trans_le <|
mul_le_mul (op_norm_mul_apply_le _ _ _)
(op_norm_le_bound _ (norm_nonneg _) fun _ => (norm_mul_le _ _).trans_eq (mul_comm _ _))
(norm_nonneg _) (norm_nonneg _)
#align continuous_linear_map.op_norm_mul_left_right_apply_apply_le ContinuousLinearMap.op_norm_mulLeftRight_apply_apply_le
theorem op_norm_mulLeftRight_apply_le (x : 𝕜') : ‖mulLeftRight 𝕜 𝕜' x‖ ≤ ‖x‖ :=
op_norm_le_bound _ (norm_nonneg x) (op_norm_mulLeftRight_apply_apply_le 𝕜 𝕜' x)
#align continuous_linear_map.op_norm_mul_left_right_apply_le ContinuousLinearMap.op_norm_mulLeftRight_apply_le
theorem op_norm_mulLeftRight_le : ‖mulLeftRight 𝕜 𝕜'‖ ≤ 1 :=
op_norm_le_bound _ zero_le_one fun x => (one_mul ‖x‖).symm ▸ op_norm_mulLeftRight_apply_le 𝕜 𝕜' x
#align continuous_linear_map.op_norm_mul_left_right_le ContinuousLinearMap.op_norm_mulLeftRight_le
end NonUnital
section Unital
variable (𝕜) (𝕜' : Type _) [SeminormedRing 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormOneClass 𝕜']
/-- Multiplication in a normed algebra as a linear isometry to the space of
continuous linear maps. -/
def mulₗᵢ : 𝕜' →ₗᵢ[𝕜] 𝕜' →L[𝕜] 𝕜' where
toLinearMap := mul 𝕜 𝕜'
norm_map' x :=
le_antisymm (op_norm_mul_apply_le _ _ _)
(by
convert ratio_le_op_norm _ (1 : 𝕜')
simp [norm_one]
infer_instance)
#align continuous_linear_map.mulₗᵢ ContinuousLinearMap.mulₗᵢ
@[simp]
theorem coe_mulₗᵢ : ⇑(mulₗᵢ 𝕜 𝕜') = mul 𝕜 𝕜' :=
rfl
#align continuous_linear_map.coe_mulₗᵢ ContinuousLinearMap.coe_mulₗᵢ
@[simp]
theorem op_norm_mul_apply (x : 𝕜') : ‖mul 𝕜 𝕜' x‖ = ‖x‖ :=
(mulₗᵢ 𝕜 𝕜').norm_map x
#align continuous_linear_map.op_norm_mul_apply ContinuousLinearMap.op_norm_mul_apply
end Unital
end MultiplicationLinear
section SmulLinear
variable (𝕜) (𝕜' : Type _) [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' E]
[IsScalarTower 𝕜 𝕜' E]
/-- Scalar multiplication as a continuous bilinear map. -/
def lsmul : 𝕜' →L[𝕜] E →L[𝕜] E :=
((Algebra.lsmul 𝕜 E).toLinearMap : 𝕜' →ₗ[𝕜] E →ₗ[𝕜] E).mkContinuous₂ 1 fun c x => by
simpa only [one_mul] using norm_smul_le c x
#align continuous_linear_map.lsmul ContinuousLinearMap.lsmul
@[simp]
theorem lsmul_apply (c : 𝕜') (x : E) : lsmul 𝕜 𝕜' c x = c • x :=
rfl
#align continuous_linear_map.lsmul_apply ContinuousLinearMap.lsmul_apply
variable {𝕜'}
theorem norm_toSpanSingleton (x : E) : ‖toSpanSingleton 𝕜 x‖ = ‖x‖ :=
by
refine' op_norm_eq_of_bounds (norm_nonneg _) (fun x => _) fun N hN_nonneg h => _
· rw [to_span_singleton_apply, norm_smul, mul_comm]
· specialize h 1
rw [to_span_singleton_apply, norm_smul, mul_comm] at h
exact (mul_le_mul_right (by simp)).mp h
#align continuous_linear_map.norm_to_span_singleton ContinuousLinearMap.norm_toSpanSingleton
variable {𝕜}
theorem op_norm_lsmul_apply_le (x : 𝕜') : ‖(lsmul 𝕜 𝕜' x : E →L[𝕜] E)‖ ≤ ‖x‖ :=
ContinuousLinearMap.op_norm_le_bound _ (norm_nonneg x) fun y => norm_smul_le x y
#align continuous_linear_map.op_norm_lsmul_apply_le ContinuousLinearMap.op_norm_lsmul_apply_le
/-- The norm of `lsmul` is at most 1 in any semi-normed group. -/
theorem op_norm_lsmul_le : ‖(lsmul 𝕜 𝕜' : 𝕜' →L[𝕜] E →L[𝕜] E)‖ ≤ 1 :=
by
refine' ContinuousLinearMap.op_norm_le_bound _ zero_le_one fun x => _
simp_rw [one_mul]
exact op_norm_lsmul_apply_le _
#align continuous_linear_map.op_norm_lsmul_le ContinuousLinearMap.op_norm_lsmul_le
end SmulLinear
section RestrictScalars
variable {𝕜' : Type _} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜' 𝕜]
variable [NormedSpace 𝕜' E] [IsScalarTower 𝕜' 𝕜 E]
variable [NormedSpace 𝕜' Fₗ] [IsScalarTower 𝕜' 𝕜 Fₗ]
@[simp]
theorem norm_restrictScalars (f : E →L[𝕜] Fₗ) : ‖f.restrictScalars 𝕜'‖ = ‖f‖ :=
le_antisymm (op_norm_le_bound _ (norm_nonneg _) fun x => f.le_op_norm x)
(op_norm_le_bound _ (norm_nonneg _) fun x => f.le_op_norm x)
#align continuous_linear_map.norm_restrict_scalars ContinuousLinearMap.norm_restrictScalars
variable (𝕜 E Fₗ 𝕜') (𝕜'' : Type _) [Ring 𝕜''] [Module 𝕜'' Fₗ] [ContinuousConstSMul 𝕜'' Fₗ]
[SMulCommClass 𝕜 𝕜'' Fₗ] [SMulCommClass 𝕜' 𝕜'' Fₗ]
/-- `continuous_linear_map.restrict_scalars` as a `linear_isometry`. -/
def restrictScalarsIsometry : (E →L[𝕜] Fₗ) →ₗᵢ[𝕜''] E →L[𝕜'] Fₗ :=
⟨restrictScalarsₗ 𝕜 E Fₗ 𝕜' 𝕜'', norm_restrictScalars⟩
#align continuous_linear_map.restrict_scalars_isometry ContinuousLinearMap.restrictScalarsIsometry
variable {𝕜 E Fₗ 𝕜' 𝕜''}
@[simp]
theorem coe_restrictScalarsIsometry :
⇑(restrictScalarsIsometry 𝕜 E Fₗ 𝕜' 𝕜'') = restrictScalars 𝕜' :=
rfl
#align continuous_linear_map.coe_restrict_scalars_isometry ContinuousLinearMap.coe_restrictScalarsIsometry
@[simp]
theorem restrictScalarsIsometry_toLinearMap :
(restrictScalarsIsometry 𝕜 E Fₗ 𝕜' 𝕜'').toLinearMap = restrictScalarsₗ 𝕜 E Fₗ 𝕜' 𝕜'' :=
rfl
#align continuous_linear_map.restrict_scalars_isometry_to_linear_map ContinuousLinearMap.restrictScalarsIsometry_toLinearMap
variable (𝕜 E Fₗ 𝕜' 𝕜'')
/-- `continuous_linear_map.restrict_scalars` as a `continuous_linear_map`. -/
def restrictScalarsL : (E →L[𝕜] Fₗ) →L[𝕜''] E →L[𝕜'] Fₗ :=
(restrictScalarsIsometry 𝕜 E Fₗ 𝕜' 𝕜'').toContinuousLinearMap
#align continuous_linear_map.restrict_scalarsL ContinuousLinearMap.restrictScalarsL
variable {𝕜 E Fₗ 𝕜' 𝕜''}
@[simp]
theorem coe_restrictScalarsL :
(restrictScalarsL 𝕜 E Fₗ 𝕜' 𝕜'' : (E →L[𝕜] Fₗ) →ₗ[𝕜''] E →L[𝕜'] Fₗ) =
restrictScalarsₗ 𝕜 E Fₗ 𝕜' 𝕜'' :=
rfl
#align continuous_linear_map.coe_restrict_scalarsL ContinuousLinearMap.coe_restrictScalarsL
@[simp]
theorem coe_restrict_scalarsL' : ⇑(restrictScalarsL 𝕜 E Fₗ 𝕜' 𝕜'') = restrictScalars 𝕜' :=
rfl
#align continuous_linear_map.coe_restrict_scalarsL' ContinuousLinearMap.coe_restrict_scalarsL'
end RestrictScalars
end ContinuousLinearMap
namespace Submodule
theorem norm_subtypeL_le (K : Submodule 𝕜 E) : ‖K.subtypeL‖ ≤ 1 :=
K.subtypeₗᵢ.norm_toContinuousLinearMap_le
#align submodule.norm_subtypeL_le Submodule.norm_subtypeL_le
end Submodule
namespace ContinuousLinearEquiv
section
variable {σ₂₁ : 𝕜₂ →+* 𝕜} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] [RingHomIsometric σ₁₂]
variable (e : E ≃SL[σ₁₂] F)
include σ₂₁
protected theorem lipschitz : LipschitzWith ‖(e : E →SL[σ₁₂] F)‖₊ e :=
(e : E →SL[σ₁₂] F).lipschitz
#align continuous_linear_equiv.lipschitz ContinuousLinearEquiv.lipschitz
theorem isO_comp {α : Type _} (f : α → E) (l : Filter α) : (fun x' => e (f x')) =O[l] f :=
(e : E →SL[σ₁₂] F).isO_comp f l
#align continuous_linear_equiv.is_O_comp ContinuousLinearEquiv.isO_comp
theorem isO_sub (l : Filter E) (x : E) : (fun x' => e (x' - x)) =O[l] fun x' => x' - x :=
(e : E →SL[σ₁₂] F).isO_sub l x
#align continuous_linear_equiv.is_O_sub ContinuousLinearEquiv.isO_sub
end
variable {σ₂₁ : 𝕜₂ →+* 𝕜} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
variable [RingHomIsometric σ₂₁] (e : E ≃SL[σ₁₂] F)
include σ₂₁
theorem isO_comp_rev {α : Type _} (f : α → E) (l : Filter α) : f =O[l] fun x' => e (f x') :=
(e.symm.isO_comp _ l).congr_left fun _ => e.symm_apply_apply _
#align continuous_linear_equiv.is_O_comp_rev ContinuousLinearEquiv.isO_comp_rev
theorem isO_sub_rev (l : Filter E) (x : E) : (fun x' => x' - x) =O[l] fun x' => e (x' - x) :=
e.isO_comp_rev _ _
#align continuous_linear_equiv.is_O_sub_rev ContinuousLinearEquiv.isO_sub_rev
end ContinuousLinearEquiv
variable {σ₂₁ : 𝕜₂ →+* 𝕜} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
namespace ContinuousLinearMap
variable {E' F' : Type _} [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F']
variable {𝕜₁' : Type _} {𝕜₂' : Type _} [NontriviallyNormedField 𝕜₁'] [NontriviallyNormedField 𝕜₂']
[NormedSpace 𝕜₁' E'] [NormedSpace 𝕜₂' F'] {σ₁' : 𝕜₁' →+* 𝕜} {σ₁₃' : 𝕜₁' →+* 𝕜₃} {σ₂' : 𝕜₂' →+* 𝕜₂}
{σ₂₃' : 𝕜₂' →+* 𝕜₃} [RingHomCompTriple σ₁' σ₁₃ σ₁₃'] [RingHomCompTriple σ₂' σ₂₃ σ₂₃']
[RingHomIsometric σ₂₃] [RingHomIsometric σ₁₃'] [RingHomIsometric σ₂₃']
/-- Compose a bilinear map `E →SL[σ₁₃] F →SL[σ₂₃] G` with two linear maps
`E' →SL[σ₁'] E` and `F' →SL[σ₂'] F`. -/
def bilinearComp (f : E →SL[σ₁₃] F →SL[σ₂₃] G) (gE : E' →SL[σ₁'] E) (gF : F' →SL[σ₂'] F) :
E' →SL[σ₁₃'] F' →SL[σ₂₃'] G :=
((f.comp gE).flip.comp gF).flip
#align continuous_linear_map.bilinear_comp ContinuousLinearMap.bilinearComp
include σ₁₃' σ₂₃'
@[simp]
theorem bilinearComp_apply (f : E →SL[σ₁₃] F →SL[σ₂₃] G) (gE : E' →SL[σ₁'] E) (gF : F' →SL[σ₂'] F)
(x : E') (y : F') : f.bilinearComp gE gF x y = f (gE x) (gF y) :=
rfl
#align continuous_linear_map.bilinear_comp_apply ContinuousLinearMap.bilinearComp_apply
omit σ₁₃' σ₂₃'
variable [RingHomIsometric σ₁₃] [RingHomIsometric σ₁'] [RingHomIsometric σ₂']
/-- Derivative of a continuous bilinear map `f : E →L[𝕜] F →L[𝕜] G` interpreted as a map `E × F → G`
at point `p : E × F` evaluated at `q : E × F`, as a continuous bilinear map. -/
def deriv₂ (f : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : E × Fₗ →L[𝕜] E × Fₗ →L[𝕜] Gₗ :=
f.bilinearComp (fst _ _ _) (snd _ _ _) + f.flip.bilinearComp (snd _ _ _) (fst _ _ _)
#align continuous_linear_map.deriv₂ ContinuousLinearMap.deriv₂
@[simp]
theorem coe_deriv₂ (f : E →L[𝕜] Fₗ →L[𝕜] Gₗ) (p : E × Fₗ) :
⇑(f.deriv₂ p) = fun q : E × Fₗ => f p.1 q.2 + f q.1 p.2 :=
rfl
#align continuous_linear_map.coe_deriv₂ ContinuousLinearMap.coe_deriv₂
theorem map_add_add (f : E →L[𝕜] Fₗ →L[𝕜] Gₗ) (x x' : E) (y y' : Fₗ) :
f (x + x') (y + y') = f x y + f.deriv₂ (x, y) (x', y') + f x' y' := by
simp only [map_add, add_apply, coe_deriv₂, add_assoc]
#align continuous_linear_map.map_add_add ContinuousLinearMap.map_add_add
end ContinuousLinearMap
end SemiNormed
section Normed
variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G]
[NormedAddCommGroup Fₗ]
open Metric ContinuousLinearMap
section
variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃]
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜₃ G] [NormedSpace 𝕜 Fₗ] (c : 𝕜)
{σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃} (f g : E →SL[σ₁₂] F) (x y z : E)
namespace LinearMap
theorem bound_of_shell [RingHomIsometric σ₁₂] (f : E →ₛₗ[σ₁₂] F) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜}
(hc : 1 < ‖c‖) (hf : ∀ x, ε / ‖c‖ ≤ ‖x‖ → ‖x‖ < ε → ‖f x‖ ≤ C * ‖x‖) (x : E) :
‖f x‖ ≤ C * ‖x‖ := by
by_cases hx : x = 0; · simp [hx]
exact
SemilinearMapClass.bound_of_shell_semi_normed f ε_pos hc hf (ne_of_lt (norm_pos_iff.2 hx)).symm
#align linear_map.bound_of_shell LinearMap.bound_of_shell
/-- `linear_map.bound_of_ball_bound'` is a version of this lemma over a field satisfying `is_R_or_C`
that produces a concrete bound.
-/
theorem bound_of_ball_bound {r : ℝ} (r_pos : 0 < r) (c : ℝ) (f : E →ₗ[𝕜] Fₗ)
(h : ∀ z ∈ Metric.ball (0 : E) r, ‖f z‖ ≤ c) : ∃ C, ∀ z : E, ‖f z‖ ≤ C * ‖z‖ :=
by
cases' @NontriviallyNormedField.non_trivial 𝕜 _ with k hk
use c * (‖k‖ / r)
intro z
refine' bound_of_shell _ r_pos hk (fun x hko hxo => _) _
calc
‖f x‖ ≤ c := h _ (mem_ball_zero_iff.mpr hxo)
_ ≤ c * (‖x‖ * ‖k‖ / r) := (le_mul_of_one_le_right _ _)
_ = _ := by ring
· exact le_trans (norm_nonneg _) (h 0 (by simp [r_pos]))
· rw [div_le_iff (zero_lt_one.trans hk)] at hko
exact (one_le_div r_pos).mpr hko
#align linear_map.bound_of_ball_bound LinearMap.bound_of_ball_bound
theorem antilipschitz_of_comap_nhds_le [h : RingHomIsometric σ₁₂] (f : E →ₛₗ[σ₁₂] F)
(hf : (𝓝 0).comap f ≤ 𝓝 0) : ∃ K, AntilipschitzWith K f :=
by
rcases((nhds_basis_ball.comap _).le_basis_iffₓ nhds_basis_ball).1 hf 1 one_pos with ⟨ε, ε0, hε⟩
simp only [Set.subset_def, Set.mem_preimage, mem_ball_zero_iff] at hε
lift ε to ℝ≥0 using ε0.le
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
refine' ⟨ε⁻¹ * ‖c‖₊, AddMonoidHomClass.antilipschitz_of_bound f fun x => _⟩
by_cases hx : f x = 0
· rw [← hx] at hf
obtain rfl : x = 0 :=
Specializes.eq
(specializes_iff_pure.2 <|
((Filter.tendsto_pure_pure _ _).mono_right (pure_le_nhds _)).le_comap.trans hf)
exact norm_zero.trans_le (mul_nonneg (NNReal.coe_nonneg _) (norm_nonneg _))
have hc₀ : c ≠ 0 := norm_pos_iff.1 (one_pos.trans hc)
rw [← h.1] at hc
rcases rescale_to_shell_zpow hc ε0 hx with ⟨n, -, hlt, -, hle⟩
simp only [← map_zpow₀, h.1, ← map_smulₛₗ] at hlt hle
calc
‖x‖ = ‖c ^ n‖⁻¹ * ‖c ^ n • x‖ := by
rwa [← norm_inv, ← norm_smul, inv_smul_smul₀ (zpow_ne_zero _ _)]
_ ≤ ‖c ^ n‖⁻¹ * 1 := (mul_le_mul_of_nonneg_left (hε _ hlt).le (inv_nonneg.2 (norm_nonneg _)))
_ ≤ ε⁻¹ * ‖c‖ * ‖f x‖ := by rwa [mul_one]
#align linear_map.antilipschitz_of_comap_nhds_le LinearMap.antilipschitz_of_comap_nhds_le
end LinearMap
namespace ContinuousLinearMap
section OpNorm
open Set Real
/-- An operator is zero iff its norm vanishes. -/
theorem op_norm_zero_iff [RingHomIsometric σ₁₂] : ‖f‖ = 0 ↔ f = 0 :=
Iff.intro
(fun hn =>
ContinuousLinearMap.ext fun x =>
norm_le_zero_iff.1
(calc
_ ≤ ‖f‖ * ‖x‖ := le_op_norm _ _
_ = _ := by rw [hn, MulZeroClass.zero_mul]
))
(by
rintro rfl
exact op_norm_zero)
#align continuous_linear_map.op_norm_zero_iff ContinuousLinearMap.op_norm_zero_iff
/-- If a normed space is non-trivial, then the norm of the identity equals `1`. -/
@[simp]
theorem norm_id [Nontrivial E] : ‖id 𝕜 E‖ = 1 :=
by
refine' norm_id_of_nontrivial_seminorm _
obtain ⟨x, hx⟩ := exists_ne (0 : E)
exact ⟨x, ne_of_gt (norm_pos_iff.2 hx)⟩
#align continuous_linear_map.norm_id ContinuousLinearMap.norm_id
instance normOneClass [Nontrivial E] : NormOneClass (E →L[𝕜] E) :=
⟨norm_id⟩
#align continuous_linear_map.norm_one_class ContinuousLinearMap.normOneClass
/-- Continuous linear maps themselves form a normed space with respect to
the operator norm. -/
instance toNormedAddCommGroup [RingHomIsometric σ₁₂] : NormedAddCommGroup (E →SL[σ₁₂] F) :=
NormedAddCommGroup.ofSeparation fun f => (op_norm_zero_iff f).mp
#align continuous_linear_map.to_normed_add_comm_group ContinuousLinearMap.toNormedAddCommGroup
/-- Continuous linear maps form a normed ring with respect to the operator norm. -/
instance toNormedRing : NormedRing (E →L[𝕜] E) :=
{ ContinuousLinearMap.toNormedAddCommGroup, ContinuousLinearMap.toSemiNormedRing with }
#align continuous_linear_map.to_normed_ring ContinuousLinearMap.toNormedRing
variable {f}
theorem homothety_norm [RingHomIsometric σ₁₂] [Nontrivial E] (f : E →SL[σ₁₂] F) {a : ℝ}
(hf : ∀ x, ‖f x‖ = a * ‖x‖) : ‖f‖ = a :=
by
obtain ⟨x, hx⟩ : ∃ x : E, x ≠ 0 := exists_ne 0
rw [← norm_pos_iff] at hx
have ha : 0 ≤ a := by simpa only [hf, hx, zero_le_mul_right] using norm_nonneg (f x)
apply le_antisymm (f.op_norm_le_bound ha fun y => le_of_eq (hf y))
simpa only [hf, hx, mul_le_mul_right] using f.le_op_norm x
#align continuous_linear_map.homothety_norm ContinuousLinearMap.homothety_norm
variable (f)
/-- If a continuous linear map is a topology embedding, then it is expands the distances
by a positive factor.-/
theorem antilipschitz_of_embedding (f : E →L[𝕜] Fₗ) (hf : Embedding f) :
∃ K, AntilipschitzWith K f :=
f.toLinearMap.antilipschitz_of_comap_nhds_le <| map_zero f ▸ (hf.nhds_eq_comap 0).ge
#align continuous_linear_map.antilipschitz_of_embedding ContinuousLinearMap.antilipschitz_of_embedding
section Completeness
open Topology
open Filter
variable {E' : Type _} [SeminormedAddCommGroup E'] [NormedSpace 𝕜 E'] [RingHomIsometric σ₁₂]
/-- Construct a bundled continuous (semi)linear map from a map `f : E → F` and a proof of the fact
that it belongs to the closure of the image of a bounded set `s : set (E →SL[σ₁₂] F)` under coercion
to function. Coercion to function of the result is definitionally equal to `f`. -/
@[simps (config := { fullyApplied := false }) apply]
def ofMemClosureImageCoeBounded (f : E' → F) {s : Set (E' →SL[σ₁₂] F)} (hs : Bounded s)
(hf : f ∈ closure ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' s)) : E' →SL[σ₁₂] F :=
by
-- `f` is a linear map due to `linear_map_of_mem_closure_range_coe`
refine' (linearMapOfMemClosureRangeCoe f _).mkContinuousOfExistsBound _
· refine' closure_mono (image_subset_iff.2 fun g hg => _) hf
exact ⟨g, rfl⟩
· -- We need to show that `f` has bounded norm. Choose `C` such that `‖g‖ ≤ C` for all `g ∈ s`.
rcases bounded_iff_forall_norm_le.1 hs with ⟨C, hC⟩
-- Then `‖g x‖ ≤ C * ‖x‖` for all `g ∈ s`, `x : E`, hence `‖f x‖ ≤ C * ‖x‖` for all `x`.
have : ∀ x, IsClosed { g : E' → F | ‖g x‖ ≤ C * ‖x‖ } := fun x =>
is_closed_Iic.preimage (@continuous_apply E' (fun _ => F) _ x).norm
refine' ⟨C, fun x => (this x).closure_subset_iff.2 (image_subset_iff.2 fun g hg => _) hf⟩
exact g.le_of_op_norm_le (hC _ hg) _
#align continuous_linear_map.of_mem_closure_image_coe_bounded ContinuousLinearMap.ofMemClosureImageCoeBounded
/-- Let `f : E → F` be a map, let `g : α → E →SL[σ₁₂] F` be a family of continuous (semi)linear maps
that takes values in a bounded set and converges to `f` pointwise along a nontrivial filter. Then
`f` is a continuous (semi)linear map. -/
@[simps (config := { fullyApplied := false }) apply]
def ofTendstoOfBoundedRange {α : Type _} {l : Filter α} [l.ne_bot] (f : E' → F)
(g : α → E' →SL[σ₁₂] F) (hf : Tendsto (fun a x => g a x) l (𝓝 f)) (hg : Bounded (Set.range g)) :
E' →SL[σ₁₂] F :=
ofMemClosureImageCoeBounded f hg <|
mem_closure_of_tendsto hf <|
eventually_of_forall fun a => mem_image_of_mem _ <| Set.mem_range_self _
#align continuous_linear_map.of_tendsto_of_bounded_range ContinuousLinearMap.ofTendstoOfBoundedRange
/-- If a Cauchy sequence of continuous linear map converges to a continuous linear map pointwise,
then it converges to the same map in norm. This lemma is used to prove that the space of continuous
linear maps is complete provided that the codomain is a complete space. -/
theorem tendsto_of_tendsto_pointwise_of_cauchySeq {f : ℕ → E' →SL[σ₁₂] F} {g : E' →SL[σ₁₂] F}
(hg : Tendsto (fun n x => f n x) atTop (𝓝 g)) (hf : CauchySeq f) : Tendsto f atTop (𝓝 g) :=
by
/- Since `f` is a Cauchy sequence, there exists `b → 0` such that `‖f n - f m‖ ≤ b N` for any
`m, n ≥ N`. -/
rcases cauchySeq_iff_le_tendsto_0.1 hf with ⟨b, hb₀, hfb, hb_lim⟩
-- Since `b → 0`, it suffices to show that `‖f n x - g x‖ ≤ b n * ‖x‖` for all `n` and `x`.
suffices : ∀ n x, ‖f n x - g x‖ ≤ b n * ‖x‖
exact
tendsto_iff_norm_tendsto_zero.2
(squeeze_zero (fun n => norm_nonneg _) (fun n => op_norm_le_bound _ (hb₀ n) (this n)) hb_lim)
intro n x
-- Note that `f m x → g x`, hence `‖f n x - f m x‖ → ‖f n x - g x‖` as `m → ∞`
have : tendsto (fun m => ‖f n x - f m x‖) at_top (𝓝 ‖f n x - g x‖) :=
(tendsto_const_nhds.sub <| tendsto_pi_nhds.1 hg _).norm
-- Thus it suffices to verify `‖f n x - f m x‖ ≤ b n * ‖x‖` for `m ≥ n`.
refine' le_of_tendsto this (eventually_at_top.2 ⟨n, fun m hm => _⟩)
-- This inequality follows from `‖f n - f m‖ ≤ b n`.
exact (f n - f m).le_of_op_norm_le (hfb _ _ _ le_rfl hm) _
#align continuous_linear_map.tendsto_of_tendsto_pointwise_of_cauchy_seq ContinuousLinearMap.tendsto_of_tendsto_pointwise_of_cauchySeq
/-- If the target space is complete, the space of continuous linear maps with its norm is also
complete. This works also if the source space is seminormed. -/
instance [CompleteSpace F] : CompleteSpace (E' →SL[σ₁₂] F) :=
by
-- We show that every Cauchy sequence converges.
refine' Metric.complete_of_cauchySeq_tendsto fun f hf => _
-- The evaluation at any point `v : E` is Cauchy.
have cau : ∀ v, CauchySeq fun n => f n v := fun v => hf.map (lipschitz_apply v).UniformContinuous
-- We assemble the limits points of those Cauchy sequences
-- (which exist as `F` is complete)
-- into a function which we call `G`.
choose G hG using fun v => cauchySeq_tendsto_of_complete (cau v)
-- Next, we show that this `G` is a continuous linear map.
-- This is done in `continuous_linear_map.of_tendsto_of_bounded_range`.
set Glin : E' →SL[σ₁₂] F :=
of_tendsto_of_bounded_range _ _ (tendsto_pi_nhds.mpr hG) hf.bounded_range
-- Finally, `f n` converges to `Glin` in norm because of
-- `continuous_linear_map.tendsto_of_tendsto_pointwise_of_cauchy_seq`
exact ⟨Glin, tendsto_of_tendsto_pointwise_of_cauchy_seq (tendsto_pi_nhds.2 hG) hf⟩
/-- Let `s` be a bounded set in the space of continuous (semi)linear maps `E →SL[σ] F` taking values
in a proper space. Then `s` interpreted as a set in the space of maps `E → F` with topology of
pointwise convergence is precompact: its closure is a compact set. -/
theorem isCompact_closure_image_coe_of_bounded [ProperSpace F] {s : Set (E' →SL[σ₁₂] F)}
(hb : Bounded s) : IsCompact (closure ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' s)) :=
have : ∀ x, IsCompact (closure (apply' F σ₁₂ x '' s)) := fun x =>
((apply' F σ₁₂ x).lipschitz.bounded_image hb).isCompact_closure
isCompact_closure_of_subset_compact (isCompact_pi_infinite this)
(image_subset_iff.2 fun g hg x => subset_closure <| mem_image_of_mem _ hg)
#align continuous_linear_map.is_compact_closure_image_coe_of_bounded ContinuousLinearMap.isCompact_closure_image_coe_of_bounded
/-- Let `s` be a bounded set in the space of continuous (semi)linear maps `E →SL[σ] F` taking values
in a proper space. If `s` interpreted as a set in the space of maps `E → F` with topology of
pointwise convergence is closed, then it is compact.
TODO: reformulate this in terms of a type synonym with the right topology. -/
theorem isCompact_image_coe_of_bounded_of_closed_image [ProperSpace F] {s : Set (E' →SL[σ₁₂] F)}
(hb : Bounded s) (hc : IsClosed ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' s)) :
IsCompact ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' s) :=
hc.closure_eq ▸ isCompact_closure_image_coe_of_bounded hb
#align continuous_linear_map.is_compact_image_coe_of_bounded_of_closed_image ContinuousLinearMap.isCompact_image_coe_of_bounded_of_closed_image
/-- If a set `s` of semilinear functions is bounded and is closed in the weak-* topology, then its
image under coercion to functions `E → F` is a closed set. We don't have a name for `E →SL[σ] F`
with weak-* topology in `mathlib`, so we use an equivalent condition (see `is_closed_induced_iff'`).
TODO: reformulate this in terms of a type synonym with the right topology. -/
theorem isClosed_image_coe_of_bounded_of_weak_closed {s : Set (E' →SL[σ₁₂] F)} (hb : Bounded s)
(hc : ∀ f, (⇑f : E' → F) ∈ closure ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' s) → f ∈ s) :
IsClosed ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' s) :=
isClosed_of_closure_subset fun f hf =>
⟨ofMemClosureImageCoeBounded f hb hf, hc (ofMemClosureImageCoeBounded f hb hf) hf, rfl⟩
#align continuous_linear_map.is_closed_image_coe_of_bounded_of_weak_closed ContinuousLinearMap.isClosed_image_coe_of_bounded_of_weak_closed
/-- If a set `s` of semilinear functions is bounded and is closed in the weak-* topology, then its
image under coercion to functions `E → F` is a compact set. We don't have a name for `E →SL[σ] F`
with weak-* topology in `mathlib`, so we use an equivalent condition (see `is_closed_induced_iff'`).
-/
theorem isCompact_image_coe_of_bounded_of_weak_closed [ProperSpace F] {s : Set (E' →SL[σ₁₂] F)}
(hb : Bounded s)
(hc : ∀ f, (⇑f : E' → F) ∈ closure ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' s) → f ∈ s) :
IsCompact ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' s) :=
isCompact_image_coe_of_bounded_of_closed_image hb <|
isClosed_image_coe_of_bounded_of_weak_closed hb hc
#align continuous_linear_map.is_compact_image_coe_of_bounded_of_weak_closed ContinuousLinearMap.isCompact_image_coe_of_bounded_of_weak_closed
/-- A closed ball is closed in the weak-* topology. We don't have a name for `E →SL[σ] F` with
weak-* topology in `mathlib`, so we use an equivalent condition (see `is_closed_induced_iff'`). -/
theorem is_weak_closed_closedBall (f₀ : E' →SL[σ₁₂] F) (r : ℝ) ⦃f : E' →SL[σ₁₂] F⦄
(hf : ⇑f ∈ closure ((coeFn : (E' →SL[σ₁₂] F) → E' → F) '' closedBall f₀ r)) :
f ∈ closedBall f₀ r :=
by
have hr : 0 ≤ r := nonempty_closed_ball.1 (nonempty_image_iff.1 (closure_nonempty_iff.1 ⟨_, hf⟩))
refine' mem_closedBall_iff_norm.2 (op_norm_le_bound _ hr fun x => _)
have : IsClosed { g : E' → F | ‖g x - f₀ x‖ ≤ r * ‖x‖ } :=
is_closed_Iic.preimage ((@continuous_apply E' (fun _ => F) _ x).sub continuous_const).norm
refine' this.closure_subset_iff.2 (image_subset_iff.2 fun g hg => _) hf
exact (g - f₀).le_of_op_norm_le (mem_closedBall_iff_norm.1 hg) _
#align continuous_linear_map.is_weak_closed_closed_ball ContinuousLinearMap.is_weak_closed_closedBall
/-- The set of functions `f : E → F` that represent continuous linear maps `f : E →SL[σ₁₂] F`
at distance `≤ r` from `f₀ : E →SL[σ₁₂] F` is closed in the topology of pointwise convergence.
This is one of the key steps in the proof of the **Banach-Alaoglu** theorem. -/
theorem isClosed_image_coe_closedBall (f₀ : E →SL[σ₁₂] F) (r : ℝ) :
IsClosed ((coeFn : (E →SL[σ₁₂] F) → E → F) '' closedBall f₀ r) :=
isClosed_image_coe_of_bounded_of_weak_closed bounded_closedBall (is_weak_closed_closedBall f₀ r)
#align continuous_linear_map.is_closed_image_coe_closed_ball ContinuousLinearMap.isClosed_image_coe_closedBall
/-- **Banach-Alaoglu** theorem. The set of functions `f : E → F` that represent continuous linear
maps `f : E →SL[σ₁₂] F` at distance `≤ r` from `f₀ : E →SL[σ₁₂] F` is compact in the topology of
pointwise convergence. Other versions of this theorem can be found in
`analysis.normed_space.weak_dual`. -/
theorem isCompact_image_coe_closedBall [ProperSpace F] (f₀ : E →SL[σ₁₂] F) (r : ℝ) :
IsCompact ((coeFn : (E →SL[σ₁₂] F) → E → F) '' closedBall f₀ r) :=
isCompact_image_coe_of_bounded_of_weak_closed bounded_closedBall <| is_weak_closed_closedBall f₀ r
#align continuous_linear_map.is_compact_image_coe_closed_ball ContinuousLinearMap.isCompact_image_coe_closedBall
end Completeness
section UniformlyExtend
variable [CompleteSpace F] (e : E →L[𝕜] Fₗ) (h_dense : DenseRange e)
section
variable (h_e : UniformInducing e)
/-- Extension of a continuous linear map `f : E →SL[σ₁₂] F`, with `E` a normed space and `F` a
complete normed space, along a uniform and dense embedding `e : E →L[𝕜] Fₗ`. -/
def extend : Fₗ →SL[σ₁₂] F :=
have cont :=
(-- extension of `f` is continuous
uniformContinuous_uniformly_extend
h_e h_dense f.UniformContinuous).Continuous
-- extension of `f` agrees with `f` on the domain of the embedding `e`
have eq := uniformly_extend_of_ind h_e h_dense f.UniformContinuous
{ toFun := (h_e.DenseInducing h_dense).extend f
map_add' := by
refine' h_dense.induction_on₂ _ _
·
exact
isClosed_eq (cont.comp continuous_add)
((cont.comp continuous_fst).add (cont.comp continuous_snd))
· intro x y
simp only [Eq, ← e.map_add]
exact f.map_add _ _
map_smul' := fun k => by
refine' fun b => h_dense.induction_on b _ _
·
exact
isClosed_eq (cont.comp (continuous_const_smul _)) ((continuous_const_smul _).comp cont)
· intro x
rw [← map_smul]
simp only [Eq]
exact ContinuousLinearMap.map_smulₛₗ _ _ _
cont }
#align continuous_linear_map.extend ContinuousLinearMap.extend
@[simp]
theorem extend_eq (x : E) : extend f e h_dense h_e (e x) = f x :=
DenseInducing.extend_eq _ f.cont _
#align continuous_linear_map.extend_eq ContinuousLinearMap.extend_eq
theorem extend_unique (g : Fₗ →SL[σ₁₂] F) (H : g.comp e = f) : extend f e h_dense h_e = g :=
ContinuousLinearMap.coeFn_injective <|
uniformly_extend_unique h_e h_dense (ContinuousLinearMap.ext_iff.1 H) g.Continuous
#align continuous_linear_map.extend_unique ContinuousLinearMap.extend_unique
@[simp]
theorem extend_zero : extend (0 : E →SL[σ₁₂] F) e h_dense h_e = 0 :=
extend_unique _ _ _ _ _ (zero_comp _)
#align continuous_linear_map.extend_zero ContinuousLinearMap.extend_zero
end
section
variable {N : ℝ≥0} (h_e : ∀ x, ‖x‖ ≤ N * ‖e x‖) [RingHomIsometric σ₁₂]
-- mathport name: exprψ
local notation "ψ" => f.extend e h_dense (uniformEmbedding_of_bound _ h_e).to_uniformInducing
/-- If a dense embedding `e : E →L[𝕜] G` expands the norm by a constant factor `N⁻¹`, then the
norm of the extension of `f` along `e` is bounded by `N * ‖f‖`. -/
theorem op_norm_extend_le : ‖ψ‖ ≤ N * ‖f‖ :=
by
have uni : UniformInducing e := (uniform_embedding_of_bound _ h_e).to_uniformInducing
have eq : ∀ x, ψ (e x) = f x := uniformly_extend_of_ind uni h_dense f.uniform_continuous
by_cases N0 : 0 ≤ N
· refine' op_norm_le_bound ψ _ (isClosed_property h_dense (isClosed_le _ _) _)
· exact mul_nonneg N0 (norm_nonneg _)
· exact continuous_norm.comp (cont ψ)
· exact continuous_const.mul continuous_norm
· intro x
rw [Eq]
calc
‖f x‖ ≤ ‖f‖ * ‖x‖ := le_op_norm _ _
_ ≤ ‖f‖ * (N * ‖e x‖) := (mul_le_mul_of_nonneg_left (h_e x) (norm_nonneg _))
_ ≤ N * ‖f‖ * ‖e x‖ := by rw [mul_comm ↑N ‖f‖, mul_assoc]
· have he : ∀ x : E, x = 0 := by
intro x
have N0 : N ≤ 0 := le_of_lt (lt_of_not_ge N0)
rw [← norm_le_zero_iff]
exact le_trans (h_e x) (mul_nonpos_of_nonpos_of_nonneg N0 (norm_nonneg _))
have hf : f = 0 := by
ext
simp only [he x, zero_apply, map_zero]
have hψ : ψ = 0 := by
rw [hf]
apply extend_zero
rw [hψ, hf, norm_zero, norm_zero, MulZeroClass.mul_zero]
#align continuous_linear_map.op_norm_extend_le ContinuousLinearMap.op_norm_extend_le
end
end UniformlyExtend
end OpNorm
end ContinuousLinearMap
namespace LinearIsometry
@[simp]
theorem norm_toContinuousLinearMap [Nontrivial E] [RingHomIsometric σ₁₂] (f : E →ₛₗᵢ[σ₁₂] F) :
‖f.toContinuousLinearMap‖ = 1 :=
f.toContinuousLinearMap.homothety_norm <| by simp
#align linear_isometry.norm_to_continuous_linear_map LinearIsometry.norm_toContinuousLinearMap
variable {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
include σ₁₃
/-- Postcomposition of a continuous linear map with a linear isometry preserves
the operator norm. -/
theorem norm_toContinuousLinearMap_comp [RingHomIsometric σ₁₂] (f : F →ₛₗᵢ[σ₂₃] G)
{g : E →SL[σ₁₂] F} : ‖f.toContinuousLinearMap.comp g‖ = ‖g‖ :=
op_norm_ext (f.toContinuousLinearMap.comp g) g fun x => by
simp only [norm_map, coe_to_continuous_linear_map, coe_comp']
#align linear_isometry.norm_to_continuous_linear_map_comp LinearIsometry.norm_toContinuousLinearMap_comp
omit σ₁₃
end LinearIsometry
end
namespace ContinuousLinearMap
variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃]
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜₃ G] [NormedSpace 𝕜 Fₗ] (c : 𝕜)
{σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃}
variable {𝕜₂' : Type _} [NontriviallyNormedField 𝕜₂'] {F' : Type _} [NormedAddCommGroup F']
[NormedSpace 𝕜₂' F'] {σ₂' : 𝕜₂' →+* 𝕜₂} {σ₂'' : 𝕜₂ →+* 𝕜₂'} {σ₂₃' : 𝕜₂' →+* 𝕜₃}
[RingHomInvPair σ₂' σ₂''] [RingHomInvPair σ₂'' σ₂'] [RingHomCompTriple σ₂' σ₂₃ σ₂₃']
[RingHomCompTriple σ₂'' σ₂₃' σ₂₃] [RingHomIsometric σ₂₃] [RingHomIsometric σ₂']
[RingHomIsometric σ₂''] [RingHomIsometric σ₂₃']
include σ₂'' σ₂₃'
/-- Precomposition with a linear isometry preserves the operator norm. -/
theorem op_norm_comp_linearIsometryEquiv (f : F →SL[σ₂₃] G) (g : F' ≃ₛₗᵢ[σ₂'] F) :
‖f.comp g.toLinearIsometry.toContinuousLinearMap‖ = ‖f‖ :=
by
cases subsingleton_or_nontrivial F'
· haveI := g.symm.to_linear_equiv.to_equiv.subsingleton
simp
refine' le_antisymm _ _
· convert f.op_norm_comp_le g.to_linear_isometry.to_continuous_linear_map
simp [g.to_linear_isometry.norm_to_continuous_linear_map]
· convert(f.comp g.to_linear_isometry.to_continuous_linear_map).op_norm_comp_le
g.symm.to_linear_isometry.to_continuous_linear_map
· ext
simp
haveI := g.symm.surjective.nontrivial
simp [g.symm.to_linear_isometry.norm_to_continuous_linear_map]
#align continuous_linear_map.op_norm_comp_linear_isometry_equiv ContinuousLinearMap.op_norm_comp_linearIsometryEquiv
omit σ₂'' σ₂₃'
/-- The norm of the tensor product of a scalar linear map and of an element of a normed space
is the product of the norms. -/
@[simp]
theorem norm_smulRight_apply (c : E →L[𝕜] 𝕜) (f : Fₗ) : ‖smulRight c f‖ = ‖c‖ * ‖f‖ :=
by
refine' le_antisymm _ _
· apply op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) fun x => _
calc
‖c x • f‖ = ‖c x‖ * ‖f‖ := norm_smul _ _
_ ≤ ‖c‖ * ‖x‖ * ‖f‖ := (mul_le_mul_of_nonneg_right (le_op_norm _ _) (norm_nonneg _))
_ = ‖c‖ * ‖f‖ * ‖x‖ := by ring
· by_cases h : f = 0
· simp [h]
· have : 0 < ‖f‖ := norm_pos_iff.2 h
rw [← le_div_iff this]
apply op_norm_le_bound _ (div_nonneg (norm_nonneg _) (norm_nonneg f)) fun x => _
rw [div_mul_eq_mul_div, le_div_iff this]
calc
‖c x‖ * ‖f‖ = ‖c x • f‖ := (norm_smul _ _).symm
_ = ‖smul_right c f x‖ := rfl
_ ≤ ‖smul_right c f‖ * ‖x‖ := le_op_norm _ _
#align continuous_linear_map.norm_smul_right_apply ContinuousLinearMap.norm_smulRight_apply
/-- The non-negative norm of the tensor product of a scalar linear map and of an element of a normed
space is the product of the non-negative norms. -/
@[simp]
theorem nnnorm_smulRight_apply (c : E →L[𝕜] 𝕜) (f : Fₗ) : ‖smulRight c f‖₊ = ‖c‖₊ * ‖f‖₊ :=
NNReal.eq <| c.norm_smulRight_apply f
#align continuous_linear_map.nnnorm_smul_right_apply ContinuousLinearMap.nnnorm_smulRight_apply
variable (𝕜 E Fₗ)
/-- `continuous_linear_map.smul_right` as a continuous trilinear map:
`smul_rightL (c : E →L[𝕜] 𝕜) (f : F) (x : E) = c x • f`. -/
def smulRightL : (E →L[𝕜] 𝕜) →L[𝕜] Fₗ →L[𝕜] E →L[𝕜] Fₗ :=
LinearMap.mkContinuous₂
{ toFun := smulRightₗ
map_add' := fun c₁ c₂ => by
ext x
simp only [add_smul, coe_smul_rightₗ, add_apply, smul_right_apply, LinearMap.add_apply]
map_smul' := fun m c => by
ext x
simp only [smul_smul, coe_smul_rightₗ, Algebra.id.smul_eq_mul, coe_smul', smul_right_apply,
LinearMap.smul_apply, RingHom.id_apply, Pi.smul_apply] }
1 fun c x => by simp only [coe_smul_rightₗ, one_mul, norm_smul_right_apply, LinearMap.coe_mk]
#align continuous_linear_map.smul_rightL ContinuousLinearMap.smulRightL
variable {𝕜 E Fₗ}
@[simp]
theorem norm_smulRightL_apply (c : E →L[𝕜] 𝕜) (f : Fₗ) : ‖smulRightL 𝕜 E Fₗ c f‖ = ‖c‖ * ‖f‖ :=
norm_smulRight_apply c f
#align continuous_linear_map.norm_smul_rightL_apply ContinuousLinearMap.norm_smulRightL_apply
@[simp]
theorem norm_smulRightL (c : E →L[𝕜] 𝕜) [Nontrivial Fₗ] : ‖smulRightL 𝕜 E Fₗ c‖ = ‖c‖ :=
ContinuousLinearMap.homothety_norm _ c.norm_smulRight_apply
#align continuous_linear_map.norm_smul_rightL ContinuousLinearMap.norm_smulRightL
variable (𝕜) (𝕜' : Type _)
section
variable [NormedRing 𝕜'] [NormedAlgebra 𝕜 𝕜']
@[simp]
theorem op_norm_mul [NormOneClass 𝕜'] : ‖mul 𝕜 𝕜'‖ = 1 :=
haveI := NormOneClass.nontrivial 𝕜'
(mulₗᵢ 𝕜 𝕜').norm_toContinuousLinearMap
#align continuous_linear_map.op_norm_mul ContinuousLinearMap.op_norm_mul
end
/-- The norm of `lsmul` equals 1 in any nontrivial normed group.
This is `continuous_linear_map.op_norm_lsmul_le` as an equality. -/
@[simp]
theorem op_norm_lsmul [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' E]
[IsScalarTower 𝕜 𝕜' E] [Nontrivial E] : ‖(lsmul 𝕜 𝕜' : 𝕜' →L[𝕜] E →L[𝕜] E)‖ = 1 :=
by
refine' ContinuousLinearMap.op_norm_eq_of_bounds zero_le_one (fun x => _) fun N hN h => _
· rw [one_mul]
exact op_norm_lsmul_apply_le _
obtain ⟨y, hy⟩ := exists_ne (0 : E)
have := le_of_op_norm_le _ (h 1) y
simp_rw [lsmul_apply, one_smul, norm_one, mul_one] at this
refine' le_of_mul_le_mul_right _ (norm_pos_iff.mpr hy)
simp_rw [one_mul, this]
#align continuous_linear_map.op_norm_lsmul ContinuousLinearMap.op_norm_lsmul
end ContinuousLinearMap
namespace Submodule
variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃]
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] {σ₁₂ : 𝕜 →+* 𝕜₂}
theorem norm_subtypeL (K : Submodule 𝕜 E) [Nontrivial K] : ‖K.subtypeL‖ = 1 :=
K.subtypeₗᵢ.norm_toContinuousLinearMap
#align submodule.norm_subtypeL Submodule.norm_subtypeL
end Submodule
namespace ContinuousLinearEquiv
variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃]
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] {σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₁ : 𝕜₂ →+* 𝕜} [RingHomInvPair σ₁₂ σ₂₁]
[RingHomInvPair σ₂₁ σ₁₂]
section
variable [RingHomIsometric σ₂₁]
protected theorem antilipschitz (e : E ≃SL[σ₁₂] F) :
AntilipschitzWith ‖(e.symm : F →SL[σ₂₁] E)‖₊ e :=
e.symm.lipschitz.to_rightInverse e.left_inv
#align continuous_linear_equiv.antilipschitz ContinuousLinearEquiv.antilipschitz
theorem one_le_norm_mul_norm_symm [RingHomIsometric σ₁₂] [Nontrivial E] (e : E ≃SL[σ₁₂] F) :
1 ≤ ‖(e : E →SL[σ₁₂] F)‖ * ‖(e.symm : F →SL[σ₂₁] E)‖ :=
by
rw [mul_comm]
convert(e.symm : F →SL[σ₂₁] E).op_norm_comp_le (e : E →SL[σ₁₂] F)
rw [e.coe_symm_comp_coe, ContinuousLinearMap.norm_id]
#align continuous_linear_equiv.one_le_norm_mul_norm_symm ContinuousLinearEquiv.one_le_norm_mul_norm_symm
include σ₂₁
theorem norm_pos [RingHomIsometric σ₁₂] [Nontrivial E] (e : E ≃SL[σ₁₂] F) :
0 < ‖(e : E →SL[σ₁₂] F)‖ :=
pos_of_mul_pos_left (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _)
#align continuous_linear_equiv.norm_pos ContinuousLinearEquiv.norm_pos
omit σ₂₁
theorem norm_symm_pos [RingHomIsometric σ₁₂] [Nontrivial E] (e : E ≃SL[σ₁₂] F) :
0 < ‖(e.symm : F →SL[σ₂₁] E)‖ :=
pos_of_mul_pos_right (zero_lt_one.trans_le e.one_le_norm_mul_norm_symm) (norm_nonneg _)
#align continuous_linear_equiv.norm_symm_pos ContinuousLinearEquiv.norm_symm_pos
theorem nnnorm_symm_pos [RingHomIsometric σ₁₂] [Nontrivial E] (e : E ≃SL[σ₁₂] F) :
0 < ‖(e.symm : F →SL[σ₂₁] E)‖₊ :=
e.norm_symm_pos
#align continuous_linear_equiv.nnnorm_symm_pos ContinuousLinearEquiv.nnnorm_symm_pos
theorem subsingleton_or_norm_symm_pos [RingHomIsometric σ₁₂] (e : E ≃SL[σ₁₂] F) :
Subsingleton E ∨ 0 < ‖(e.symm : F →SL[σ₂₁] E)‖ :=
by
rcases subsingleton_or_nontrivial E with (_i | _i) <;> skip
· left
infer_instance
· right
exact e.norm_symm_pos
#align continuous_linear_equiv.subsingleton_or_norm_symm_pos ContinuousLinearEquiv.subsingleton_or_norm_symm_pos
theorem subsingleton_or_nnnorm_symm_pos [RingHomIsometric σ₁₂] (e : E ≃SL[σ₁₂] F) :
Subsingleton E ∨ 0 < ‖(e.symm : F →SL[σ₂₁] E)‖₊ :=
subsingleton_or_norm_symm_pos e
#align continuous_linear_equiv.subsingleton_or_nnnorm_symm_pos ContinuousLinearEquiv.subsingleton_or_nnnorm_symm_pos
variable (𝕜)
@[simp]
theorem coord_norm (x : E) (h : x ≠ 0) : ‖coord 𝕜 x h‖ = ‖x‖⁻¹ :=
by
have hx : 0 < ‖x‖ := norm_pos_iff.mpr h
haveI : Nontrivial (𝕜 ∙ x) := Submodule.nontrivial_span_singleton h
exact
ContinuousLinearMap.homothety_norm _ fun y =>
homothety_inverse _ hx _ (to_span_nonzero_singleton_homothety 𝕜 x h) _
#align continuous_linear_equiv.coord_norm ContinuousLinearEquiv.coord_norm
variable {𝕜} {𝕜₄ : Type _} [NontriviallyNormedField 𝕜₄]
variable {H : Type _} [NormedAddCommGroup H] [NormedSpace 𝕜₄ H] [NormedSpace 𝕜₃ G]
variable {σ₂₃ : 𝕜₂ →+* 𝕜₃} {σ₁₃ : 𝕜 →+* 𝕜₃}
variable {σ₃₄ : 𝕜₃ →+* 𝕜₄} {σ₄₃ : 𝕜₄ →+* 𝕜₃}
variable {σ₂₄ : 𝕜₂ →+* 𝕜₄} {σ₁₄ : 𝕜 →+* 𝕜₄}
variable [RingHomInvPair σ₃₄ σ₄₃] [RingHomInvPair σ₄₃ σ₃₄]
variable [RingHomCompTriple σ₂₁ σ₁₄ σ₂₄] [RingHomCompTriple σ₂₄ σ₄₃ σ₂₃]
variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₁₃ σ₃₄ σ₁₄]
variable [RingHomIsometric σ₁₄] [RingHomIsometric σ₂₃]
variable [RingHomIsometric σ₄₃] [RingHomIsometric σ₂₄]
variable [RingHomIsometric σ₁₃] [RingHomIsometric σ₁₂]
variable [RingHomIsometric σ₃₄]
include σ₂₁ σ₃₄ σ₁₃ σ₂₄
/-- A pair of continuous (semi)linear equivalences generates an continuous (semi)linear equivalence
between the spaces of continuous (semi)linear maps. -/
@[simps apply symm_apply]
def arrowCongrSL (e₁₂ : E ≃SL[σ₁₂] F) (e₄₃ : H ≃SL[σ₄₃] G) : (E →SL[σ₁₄] H) ≃SL[σ₄₃] F →SL[σ₂₃] G :=
{-- given explicitly to help `simps`
-- given explicitly to help `simps`
e₁₂.arrowCongrEquiv
e₄₃ with
toFun := fun L => (e₄₃ : H →SL[σ₄₃] G).comp (L.comp (e₁₂.symm : F →SL[σ₂₁] E))
invFun := fun L => (e₄₃.symm : G →SL[σ₃₄] H).comp (L.comp (e₁₂ : E →SL[σ₁₂] F))
map_add' := fun f g => by rw [add_comp, comp_add]
map_smul' := fun t f => by rw [smul_comp, comp_smulₛₗ]
continuous_toFun := (continuous_id.clm_comp_const _).const_clm_comp _
continuous_invFun := (continuous_id.clm_comp_const _).const_clm_comp _ }
#align continuous_linear_equiv.arrow_congrSL ContinuousLinearEquiv.arrowCongrSL
omit σ₂₁ σ₃₄ σ₁₃ σ₂₄
/-- A pair of continuous linear equivalences generates an continuous linear equivalence between
the spaces of continuous linear maps. -/
def arrowCongr {F H : Type _} [NormedAddCommGroup F] [NormedAddCommGroup H] [NormedSpace 𝕜 F]
[NormedSpace 𝕜 G] [NormedSpace 𝕜 H] (e₁ : E ≃L[𝕜] F) (e₂ : H ≃L[𝕜] G) :
(E →L[𝕜] H) ≃L[𝕜] F →L[𝕜] G :=
arrowCongrSL e₁ e₂
#align continuous_linear_equiv.arrow_congr ContinuousLinearEquiv.arrowCongr
end
end ContinuousLinearEquiv
end Normed
/-- A bounded bilinear form `B` in a real normed space is *coercive*
if there is some positive constant C such that `C * ‖u‖ * ‖u‖ ≤ B u u`.
-/
def IsCoercive [NormedAddCommGroup E] [NormedSpace ℝ E] (B : E →L[ℝ] E →L[ℝ] ℝ) : Prop :=
∃ C, 0 < C ∧ ∀ u, C * ‖u‖ * ‖u‖ ≤ B u u
#align is_coercive IsCoercive
|
{-# LANGUAGE ScopedTypeVariables, UndecidableInstances #-}
{-|
Array access, including cell arrays and structures.
Functions here are primarily thin wrappers to the underlying Matlab functions, and the same memory-management semantics hold.
In particular, created arrays must be freed, 'copyMXArray' and 'freeMXArray' are deep operations, other set operations do not make copies.
-}
module Foreign.Matlab.Array (
-- * Array manipulation
anyMXArray,
MNullArray, castMNull,
mxArrayClass,
mxArrayIsComplex,
mxArraySize,
mxArraySetSize,
mxArrayLength,
freeMXArray,
copyMXArray,
mIndexOffset,
-- * Array element access
MXArrayComponent (mxArrayGetOffset, mxArraySetOffset
, mxArrayGetOffsetList, mxArraySetOffsetList
, mxScalarGet, isMXScalar
, createMXArray, createMXScalar
, createColVector, createRowVector),
castMXArray,
-- | array element access
mxArrayGet, mxArraySet,
-- | array list access
mxArrayGetList, mxArraySetList,
mxArrayGetAll, mxArraySetAll,
mxArrayGetOffsetSafe, mxArrayGetFirst, mxArrayGetLast,
-- mxArrayGetSafe, --TODO--
fromListIO, cellFromListsIO,
isMNull,
-- * Struct access
-- |Structs in Matlab are always arrays, and so can be accessed using most array accessors.
-- |However, the modification functions such as 'mxArraySet' are not implemented because they could disrupt field data in the entire struct array, and so some specialized functions are necessary.
MStructArray,
createStruct,
mStructFields,
mStructGet, mStructSet,
mStructSetFields,
mStructAddField, mStructRemoveField,
mxCellGetAllOfType, mxCellGetArraysOfType,
-- ** Object access
-- |Some structs are also validated (blessed) user objects.
mObjectGetClass, mObjectSetClass
) where
import Control.Monad
import Data.Foldable (toList)
import Foreign
import Foreign.C.String
import Foreign.C.Types
import Data.Complex
import qualified Data.Map.Strict as DM
import Data.Maybe (catMaybes)
import Foreign.Matlab.Util
import Foreign.Matlab.Internal
import Foreign.Matlab.Types
#include <matrix.h>
-- |(Un)cast an array to a generic type.
anyMXArray :: MXArray a -> MAnyArray
anyMXArray a = unsafeCastMXArray a
-- |A NULL (empty) array
type MNullArray = MXArray MNull
-- |Safely cast a generic array to a NULL array, or return Nothing if the array is not NULL
castMNull :: MAnyArray -> MIO (Maybe MNullArray)
castMNull a
| isMNull a = pure $ Just (unsafeCastMXArray a)
| otherwise = pure Nothing
foreign import ccall unsafe mxGetClassID :: MXArrayPtr -> IO MXClassID
-- |Return the representation of the type of the elements of an array
mxArrayClass :: MXArray a -> IO MXClass
mxArrayClass a
| isMNull a = pure $ MXClassNull
| otherwise = withMXArray a mxGetClassID >.= mx2hs
ndims :: MWSize -> Ptr MWSize -> IO MSize
ndims n s = map ii =.< peekArray (ii n) s
--nsubs = ndims
withNSubs :: With MSubs (MWSize, Ptr MWSize) (IO a)
withNSubs l f = withArrayLen (map ii l) (\l a -> f (ii l, a))
withNDims :: With MSize (MWSize, Ptr MWSize) (IO a)
withNDims = withNSubs . realMSize
foreign import ccall unsafe mxGetNumberOfDimensions :: MXArrayPtr -> IO MWSize
foreign import ccall unsafe mxGetDimensions :: MXArrayPtr -> IO (Ptr MWSize)
-- |Get the size (dimensions) of an array
mxArraySize :: MXArray a -> MIO MSize
mxArraySize a = withMXArray a $ \a -> do
n <- mxGetNumberOfDimensions a
s <- mxGetDimensions a
ndims n s
foreign import ccall unsafe mxSetDimensions :: MXArrayPtr -> Ptr MWSize -> MWSize -> IO CInt
-- |Set dimension array and number of dimensions
mxArraySetSize :: MXArray a -> MSize -> IO ()
mxArraySetSize a s = do
r <- withMXArray a (\a -> withNDims s (\(nd,d) -> mxSetDimensions a d nd))
when (r /= 0) $ fail "mxArraySetSize"
foreign import ccall unsafe mxGetNumberOfElements :: MXArrayPtr -> IO CSize
-- |Like `numel` in MATLAB.
mxArrayLength :: MXArray a -> MIO Int
mxArrayLength a = ii =.< withMXArray a mxGetNumberOfElements
foreign import ccall unsafe mxCalcSingleSubscript :: MXArrayPtr -> MWSize -> Ptr MWIndex -> IO MWIndex
-- |Convert an array subscript into an offset
mIndexOffset :: MXArray a -> MIndex -> MIO Int
mIndexOffset _ (MSubs []) = pure 0
mIndexOffset _ (MSubs [i]) = pure i
mIndexOffset a (MSubs i) = ii =.< withMXArray a (withNSubs i . uncurry . mxCalcSingleSubscript)
foreign import ccall unsafe mxDuplicateArray :: MXArrayPtr -> IO MXArrayPtr
-- |Make a deep copy of an array
copyMXArray :: MXArray a -> MIO (MXArray a)
copyMXArray a = withMXArray a mxDuplicateArray >>= mkMXArray
foreign import ccall unsafe mxDestroyArray :: MXArrayPtr -> IO ()
-- |Destroy an array and all of its contents.
freeMXArray :: MXArray a -> MIO ()
freeMXArray a = do
withMXArray a mxDestroyArray
mxArraySetSize a [0, 0]
-- | Create and populate an MXArray in one go. Named without 'mx' due to possible
-- | conformity to a typeclass function.
fromListIO :: (Foldable t, MXArrayComponent a) => t a -> MIO (MXArray a)
fromListIO xs = do
arr <- createMXArray [length xs]
mxArraySetAll arr xsList
pure arr
where
xsList = toList xs
-- | Like fromListIO but wraps elements in a cell. Most useful for converting a list of strings
-- | to a MATLAB cell array of strings. Named in conjunction with `fromListIO`, which is used
-- | as part of the implementation.
cellFromListsIO :: (Traversable s, Foldable t, MXArrayComponent a) => s (t a) -> MIO (MXArray MCell)
cellFromListsIO xss = do
listOfStructArrays <- sequence $ fromListIO <$> xss
arr <- createMXArray [length xss]
mxArraySetAll arr (toList $ (MCell . anyMXArray) <$> listOfStructArrays)
pure arr
-- |The class of standardly typeable array elements
class MXArrayComponent a where
-- |Determine whether the given array is of the correct type
isMXArray :: MXArray a -> MIO Bool
-- |Create an array and initialize all its data elements to some default value, usually 0 or []
createMXArray :: MSize -> MIO (MXArray a)
-- |Determine if an array is singleton. Equivalent to
--
-- > liftM (all (1 ==)) . mxArraySize
isMXScalar :: MXArray a -> MIO Bool
mxArrayGetOffset :: MXArray a -> Int -> MIO a
mxArraySetOffset :: MXArray a -> Int -> a -> MIO ()
mxArrayGetOffsetList :: MXArray a -> Int -> Int -> MIO [a]
mxArraySetOffsetList :: MXArray a -> Int -> [a] -> MIO ()
-- |Get the value of the first data element in an array or, more specifically, the value that the array will be interpreted as in scalar context
mxScalarGet :: MXArray a -> MIO a
-- |Create a singleton (scalar) array having the specified value
createMXScalar :: a -> MIO (MXArray a)
-- |Create a column vector from the given list.
createColVector :: [a] -> MIO (MXArray a)
-- |Create a row vector from the given list.
createRowVector :: [a] -> MIO (MXArray a)
isMXArray _ = pure False
isMXScalar a = liftM2 (&&) (isMXArray a) (all (1 ==) =.< mxArraySize a)
mxArrayGetOffsetList a o n = mapM (mxArrayGetOffset a) [o..o+n-1]
mxArraySetOffsetList a o = zipWithM_ (mxArraySetOffset a . (o+)) [0..]
mxScalarGet a = mxArrayGetOffset a 0
createMXScalar x = do
a <- createMXArray [1]
mxArraySetOffset a 0 x
pure a
createRowVector l = do
a <- createMXArray [1,length l]
mxArraySetOffsetList a 0 l
pure a
createColVector l = do
a <- createMXArray [length l]
mxArraySetOffsetList a 0 l
pure a
-- |Get the value of the specified array element. Does not check bounds.
mxArrayGet :: MXArrayComponent a => MXArray a -> MIndex -> MIO a
mxArrayGet a i = mIndexOffset a i >>= mxArrayGetOffset a
-- |Set an element in an array to the specified value. Does not check bounds.
mxArraySet :: MXArrayComponent a => MXArray a -> MIndex -> a -> MIO ()
mxArraySet a i v = do
o <- mIndexOffset a i
mxArraySetOffset a o v
-- |@'mxArrayGetList' a i n@ gets the sequential list of @n@ items from array @a@ starting at index @i@. Does not check bounds.
mxArrayGetList :: MXArrayComponent a => MXArray a -> MIndex -> Int -> MIO [a]
mxArrayGetList a i n = do
o <- mIndexOffset a i
n <- if n == -1 then subtract o =.< mxArrayLength a else pure n
mxArrayGetOffsetList a o n
-- |@'mxArraySetList' a i l@ sets the sequential items in array @a@ starting at index @i@ to @l@. Does not check bounds.
mxArraySetList :: MXArrayComponent a => MXArray a -> MIndex -> [a] -> MIO ()
mxArraySetList a i l = do
o <- mIndexOffset a i
mxArraySetOffsetList a o l
-- |Get a flat list of all elements in the array.
mxArrayGetAll :: MXArrayComponent a => MXArray a -> IO [a]
mxArrayGetAll a = mxArrayGetList a mStart (-1)
-- |Set a flat list of all elements in the array.
mxArraySetAll :: MXArrayComponent a => MXArray a -> [a] -> IO ()
mxArraySetAll a = mxArraySetList a mStart
mxArrayGetFirst :: MXArrayComponent a => MXArray a -> MIO (Either String a)
mxArrayGetFirst arr = mxArrayGetOffsetSafe arr 0
mxArrayGetLast :: MXArrayComponent a => MXArray a -> MIO (Either String a)
mxArrayGetLast arr = do
arrLen <- mxArrayLength arr
mxArrayGetOffsetSafe arr (arrLen - 1)
-- |Like mxArrayGetOffset but safe.
mxArrayGetOffsetSafe :: forall a. MXArrayComponent a => MXArray a -> Int -> MIO (Either String a)
mxArrayGetOffsetSafe arr ix
| isMNull arr = pure $ Left "Couldn't get element of null array"
| otherwise = do
arrLen <- mxArrayLength arr
safeGetElem arrLen ix
where
safeGetElem :: Int -> Int -> MIO (Either String a)
safeGetElem aLen aIx
| aIx < aLen = Right <$> mxArrayGetOffset arr aIx
| otherwise = pure $ Left $ "Couldn't get element at index "
<> (show aIx) <> " of " <> (show aLen) <> "-length array"
-- |Safely cast a generic array to a type, or return Nothing if the array does not have the proper type
castMXArray :: forall a. MXArrayComponent a => MAnyArray -> MIO (Maybe (MXArray a))
castMXArray a
| isMNull a = pure Nothing
| otherwise = do
y <- isMXArray b
pure $ if y then Just b else Nothing
where
b :: MXArray a
b = unsafeCastMXArray a
-- | Extract all arrays of a given type from a Cell Array.
mxCellGetArraysOfType :: MXArrayComponent a => MXArray MCell -> MIO ([MXArray a])
mxCellGetArraysOfType ca = do
cellVals <- (fmap . fmap) mCell (mxArrayGetAll ca)
mxaMays :: [Maybe (MXArray a)] <- sequence $ castMXArray <$> cellVals
pure $ catMaybes mxaMays
-- | A convenience function to extract all arrays of a given type from a Cell Array;
-- | may have larger dimensions than the original Cell Array due to flattening.
mxCellGetAllOfType :: MXArrayComponent a => MXArray MCell -> MIO [a]
mxCellGetAllOfType ca = do
as <- mxCellGetArraysOfType ca
join <$> (sequence $ mxArrayGetAll <$> as)
foreign import ccall unsafe mxGetData :: MXArrayPtr -> IO (Ptr a)
class (MXArrayComponent a, MType mx a, Storable mx) => MXArrayData mx a where
withArrayData :: MXArray a -> (Ptr mx -> IO b) -> IO b
withArrayDataOff :: MXArray a -> Int -> (Ptr mx -> IO b) -> IO b
arrayDataGet :: MXArray a -> Int -> IO a
arrayDataSet :: MXArray a -> Int -> a -> IO ()
arrayDataGetList :: MXArray a -> Int -> Int -> IO [a]
arrayDataSetList :: MXArray a -> Int -> [a] -> IO ()
withArrayData a f = withMXArray a (mxGetData >=> f)
withArrayDataOff a o f = withArrayData a (\p -> f (advancePtr p o))
arrayDataGet a o = withArrayDataOff a o (mx2hs .=< peek)
arrayDataSet a o v = withArrayDataOff a o (\p -> poke p (hs2mx v))
arrayDataGetList a o n = withArrayDataOff a o (map mx2hs .=< peekArray n)
arrayDataSetList a o l = withArrayDataOff a o (\p -> pokeArray p (map hs2mx l))
#let arrayDataComponent = "\
mxArrayGetOffset = arrayDataGet ;\
mxArraySetOffset = arrayDataSet ;\
mxArrayGetOffsetList = arrayDataGetList ;\
mxArraySetOffsetList = arrayDataSetList\
"
--"
foreign import ccall unsafe mxIsLogical :: MXArrayPtr -> IO CBool
foreign import ccall unsafe mxCreateLogicalArray :: MWSize -> Ptr MWSize -> IO MXArrayPtr
foreign import ccall unsafe mxGetLogicals :: MXArrayPtr -> IO (Ptr MXLogical)
foreign import ccall unsafe mxCreateLogicalScalar :: CBool -> IO MXArrayPtr
foreign import ccall unsafe mxIsLogicalScalar :: MXArrayPtr -> IO CBool
foreign import ccall unsafe mxIsLogicalScalarTrue :: MXArrayPtr -> IO CBool
instance MXArrayComponent MLogical where
isMXArray a = boolC =.< withMXArray a mxIsLogical
createMXArray s = withNDims s (uncurry mxCreateLogicalArray) >>= mkMXArray
createMXScalar = mxCreateLogicalScalar . cBool >=> mkMXArray
isMXScalar a = boolC =.< withMXArray a mxIsLogicalScalar
mxScalarGet a = boolC =.< withMXArray a mxIsLogicalScalarTrue
#arrayDataComponent
instance MXArrayData MXLogical MLogical where
withArrayData a f = withMXArray a (mxGetLogicals >=> f)
foreign import ccall unsafe mxIsChar :: MXArrayPtr -> IO CBool
foreign import ccall unsafe mxCreateCharArray :: MWSize -> Ptr MWSize -> IO MXArrayPtr
foreign import ccall unsafe mxGetChars :: MXArrayPtr -> IO (Ptr MXChar)
foreign import ccall unsafe mxCreateStringFromNChars :: CString -> MWSize -> IO MXArrayPtr
instance MXArrayComponent MChar where
isMXArray a = boolC =.< withMXArray a mxIsChar
createMXArray s = withNDims s (uncurry mxCreateCharArray) >>= mkMXArray
createRowVector s =
mkMXArray =<< withCStringLen s (\(s,n) -> mxCreateStringFromNChars s (ii n))
#arrayDataComponent
instance MXArrayData MXChar MChar where
withArrayData a f = withMXArray a (mxGetChars >=> f)
foreign import ccall unsafe mxCreateNumericArray :: MWSize -> Ptr MWSize -> MXClassID -> (#type mxComplexity) -> IO MXArrayPtr
createNumericArray :: MXClass -> Bool -> MWSize -> Ptr MWSize -> IO MXArrayPtr
createNumericArray t c n s = mxCreateNumericArray n s (hs2mx t) (if c then (#const mxCOMPLEX) else (#const mxREAL))
#let numarray t = "\
foreign import ccall unsafe mxIs%s :: MXArrayPtr -> IO CBool\n\
instance MXArrayComponent M%s where\n\
isMXArray a = boolC =.< withMXArray a mxIs%s\n\
createMXArray s = withNDims s (uncurry $ createNumericArray (mxClassOf (undefined :: M%s)) False) >>= mkMXArray\n\
\
mxArrayGetOffset = arrayDataGet ;\
mxArraySetOffset = arrayDataSet ;\
mxArrayGetOffsetList = arrayDataGetList ;\
mxArraySetOffsetList = arrayDataSetList\
\n\
instance MXArrayData MX%s M%s\
", #t, #t, #t, #t, #t, #t
foreign import ccall unsafe mxIsDouble :: MXArrayPtr -> IO CBool
foreign import ccall unsafe mxCreateDoubleScalar :: MXDouble -> IO MXArrayPtr
foreign import ccall unsafe mxGetScalar :: MXArrayPtr -> IO MXDouble
instance MXArrayComponent MDouble where
isMXArray a = boolC =.< withMXArray a mxIsDouble
createMXScalar = mxCreateDoubleScalar . hs2mx >=> mkMXArray
mxScalarGet a = withMXArray a mxGetScalar
createMXArray s = withNDims s (uncurry $ createNumericArray (mxClassOf (undefined :: Double)) False) >>= mkMXArray
#arrayDataComponent
instance MXArrayData MXDouble MDouble
#numarray Single
#numarray Int8
#numarray Int16
#numarray Int32
#numarray Int64
#numarray Uint8
#numarray Uint16
#numarray Uint32
#numarray Uint64
foreign import ccall unsafe mxIsCell :: MXArrayPtr -> IO CBool
foreign import ccall unsafe mxCreateCellArray :: MWSize -> Ptr MWSize -> IO MXArrayPtr
foreign import ccall unsafe mxGetCell :: MXArrayPtr -> MWIndex -> IO MXArrayPtr
foreign import ccall unsafe mxSetCell :: MXArrayPtr -> MWIndex -> MXArrayPtr -> IO ()
instance MXArrayComponent MCell where
isMXArray a = boolC =.< withMXArray a mxIsCell
createMXArray s = withNDims s (uncurry mxCreateCellArray) >>= mkMXArray
-- Get a the specified cell element (not a copy).
mxArrayGetOffset a o = withMXArray a (\a -> mxGetCell a (ii o) >>= mkMXArray >.= MCell)
-- Set an element in a cell array to the specified value. The cell takes ownership of the array: and no copy is made. Any existing value should be freed first.
mxArraySetOffset a o (MCell v) = withMXArray a (\a -> withMXArray v (mxSetCell a (ii o)))
-- |A (array of) structs
type MStructArray = MXArray MStruct
foreign import ccall unsafe mxIsStruct :: MXArrayPtr -> IO CBool
foreign import ccall unsafe mxIsObject :: MXArrayPtr -> IO CBool
foreign import ccall unsafe mxCreateStructArray :: MWSize -> Ptr MWSize -> CInt -> Ptr CString -> IO MXArrayPtr
-- |Create an N-Dimensional structure array having the specified fields; initialize all values to 'MNullArray'
createStruct :: MSize -> [String] -> MIO MStructArray
createStruct s f =
withNDims s (\(nd,d) ->
mapWithArrayLen withCString f (\(f,nf) ->
mxCreateStructArray nd d (ii nf) f))
>>= mkMXArray
foreign import ccall unsafe mxGetNumberOfFields :: MXArrayPtr -> IO CInt
foreign import ccall unsafe mxGetFieldNameByNumber :: MXArrayPtr -> CInt -> IO CString
foreign import ccall unsafe mxGetFieldNumber :: MXArrayPtr -> CString -> IO CInt
-- |Get the names of the fields
mStructFields :: MStructArray -> MIO [String]
mStructFields a = withMXArray a $ \a -> do
n <- mxGetNumberOfFields a
forM [0..pred n] (mxGetFieldNameByNumber a >=> peekCString)
foreign import ccall unsafe mxGetField :: MXArrayPtr -> MWIndex -> CString -> IO MXArrayPtr
foreign import ccall unsafe mxSetField :: MXArrayPtr -> MWIndex -> CString -> MXArrayPtr -> IO ()
foreign import ccall unsafe mxGetFieldByNumber :: MXArrayPtr -> MWIndex -> CInt -> IO MXArrayPtr
foreign import ccall unsafe mxSetFieldByNumber :: MXArrayPtr -> MWIndex -> CInt -> MXArrayPtr -> IO ()
-- |Return the contents of the named field for the given element.
-- |Returns 'MNullArray' on no such field or if the field itself is NULL
mStructGet :: MStructArray -> MIndex -> String -> MIO MAnyArray
-- |Sets the contents of the named field for the given element. The input is stored in the array -- no copy is made.
mStructSet :: MStructArray -> MIndex -> String -> MXArray a -> MIO ()
mStructGet a i f = do
o <- mIndexOffset a i
withMXArray a (\a -> withCString f (mxGetField a (ii o) >=> mkMXArray))
mStructSet a i f v = do
o <- mIndexOffset a i
withMXArray a (\a -> withCString f (withMXArray v . mxSetField a (ii o)))
foreign import ccall unsafe mxAddField :: MXArrayPtr -> CString -> IO CInt
foreign import ccall unsafe mxRemoveField :: MXArrayPtr -> CInt -> IO ()
-- |Add a field to a structure array.
mStructAddField :: MStructArray -> String -> MIO ()
-- |Remove a field from a structure array. Does nothing if no such field exists.
mStructRemoveField :: MStructArray -> String -> MIO ()
mStructAddField a f = do
i <- withMXArray a (withCString f . mxAddField)
when (i < 0) $ fail "mxAddField"
mStructRemoveField a f = withMXArray a $ \a -> do
i <- withCString f (mxGetFieldNumber a)
if i < 0
then fail "mxRemoveField"
else mxRemoveField a i
structGetOffsetFields :: MStructArray -> [String] -> Int -> IO MStruct
structGetOffsetFields a f o =
MStruct =.< withMXArray a (\a -> DM.fromList <$>
(zipWithM (\f -> ((,) f) .=< (mxGetFieldByNumber a (ii o) >=> mkMXArray)) f [0..]))
-- |Set the fields of a struct index to the given value list. The list corresponds to the field list and must match in size.
mStructSetFields :: MStructArray -> MIndex -> [MXArray a] -> MIO ()
mStructSetFields a i v = do
o <- mIndexOffset a i
withMXArray a (\a -> zipWithM_ (\v -> withMXArray v . mxSetFieldByNumber a (ii o)) v [0..])
instance MXArrayComponent MStruct where
isMXArray a = liftM2 (||) (boolC =.< withMXArray a mxIsStruct) (boolC =.< withMXArray a mxIsObject)
createMXArray s = createStruct s []
mxArrayGetOffset a o = do
f <- mStructFields a
structGetOffsetFields a f o
mxArraySetOffset = error "mxArraySet undefined for MStruct: use mStructSet"
mxArrayGetOffsetList a o n = do
f <- mStructFields a
mapM (structGetOffsetFields a f) [o..o+n-1]
createMXScalar (MStruct fv) = do
a <- createStruct [1] f
withMXArray a $ \a -> zipWithM_ (\i v -> withMXArray v (mxSetFieldByNumber a 0 i)) [0..] v
pure a
where
(f,v) = unzip $ DM.toList fv
foreign import ccall unsafe mxGetClassName :: MXArrayPtr -> IO CString
-- |Determine if a struct array is a user defined object, and return its class name, if any.
mObjectGetClass :: MStructArray -> IO (Maybe String)
mObjectGetClass a = do
b <- boolC =.< withMXArray a mxIsObject
if b
then Just =.< withMXArray a (mxGetClassName >=> peekCString)
else pure Nothing
foreign import ccall unsafe mxSetClassName :: MXArrayPtr -> CString -> IO CInt
-- |Set classname of an unvalidated object array. It is illegal to call this function on a previously validated object array.
mObjectSetClass :: MStructArray -> String -> IO ()
mObjectSetClass a c = do
r <- withMXArray a (withCString c . mxSetClassName)
when (r /= 0) $ fail "mObjectSetClass"
castReal :: MXArray (Complex a) -> MXArray a
castReal = unsafeCastMXArray
foreign import ccall unsafe mxGetImagData :: MXArrayPtr -> IO (Ptr a)
withRealDataOff :: MXArrayData mx a => MXArray (Complex a) -> Int -> (Ptr mx -> IO b) -> IO b
withRealDataOff = withArrayDataOff . castReal
withImagDataOff :: MXArrayData mx a => MXArray (Complex a) -> Int -> (Ptr mx -> IO b) -> IO b
withImagDataOff a o f = withMXArray a (mxGetImagData >=> \p -> f (advancePtr p o))
foreign import ccall unsafe mxIsComplex :: MXArrayPtr -> IO CBool
mxArrayIsComplex :: MXArray a -> IO Bool
mxArrayIsComplex a = boolC =.< withMXArray a mxIsComplex
-- |Complex array access.
instance (RealFloat a, MNumeric a, MXArrayData mx a) => MXArrayComponent (MComplex a) where
isMXArray a = liftM2 (&&) (isMXArray (castReal a)) (mxArrayIsComplex a)
createMXArray s = withNDims s (uncurry $ createNumericArray (mxClassOf (undefined :: a)) True) >>= mkMXArray
mxArrayGetOffset a o = do
r <- withRealDataOff a o (mx2hs .=< peek)
c <- withImagDataOff a o (mx2hs .=< peek)
pure $ r :+ c
mxArraySetOffset a o (r :+ c) = do
withRealDataOff a o (\p -> poke p (hs2mx r))
withImagDataOff a o (\p -> poke p (hs2mx c))
mxArrayGetOffsetList a o n = do
r <- withRealDataOff a o (map mx2hs .=< peekArray n)
c <- withImagDataOff a o (map mx2hs .=< peekArray n)
pure $ zipWith (:+) r c
mxArraySetOffsetList a o v = do
withRealDataOff a o (\p -> pokeArray p (map hs2mx r))
withImagDataOff a o (\p -> pokeArray p (map hs2mx c))
where (r,c) = unzip $ map (\(r:+c) -> (r,c)) v
|
integer Pdd,Ndmax
parameter(Pdd=16)
parameter(Ndmax=100)
|
import Cat.Fam.Comp
/-! # Equivalence for category arrows in terms of the corresponding setoid -/
namespace Cat
/-- A proof that `f` is equivalent to `g` (`≋`, `\~~~`). -/
inductive Fam.Cat.Hom.Equiv
{ℂ : Cat}
{α β : ℂ.Obj}
(f : α ↠ β)
: {γ δ : ℂ.Obj}
→ (γ ↠ δ)
→ Prop
where
| proof :
(g : α ↠ β)
→ f ≈ g
→ Equiv f g
/-- Predicate for *"`f` and `g` are equivalent"* (`≋`, `\~~~`). -/
abbrev Fam.Cat.Hom.Equiv.equiv
{ℂ : Cat}
{α β γ δ : ℂ.Obj}
(f : α ↠ β)
(g : γ ↠ δ)
: Prop :=
@Equiv ℂ α β f γ δ g
infix:30 " ≋ " =>
Fam.Cat.Hom.Equiv.equiv
theorem Fam.Cat.Hom.Equiv.domEq
{ℂ : Cat}
{α β γ δ : ℂ.Obj}
{f : α ↠ β}
{g : γ ↠ δ}
(h : f ≋ g)
: α = γ :=
by
cases h with
| proof _ _ =>
rfl
theorem Fam.Cat.Hom.Equiv.codEq
{ℂ : Cat}
{α β γ δ : ℂ.Obj}
{f : α ↠ β}
{g : γ ↠ δ}
(h : f ≋ g)
: β = δ :=
by
cases h with
| proof _ _ =>
rfl
/-- Rewrites a `Equiv.proof` unifying (co)domains. -/
theorem Fam.Cat.Hom.Equiv.unify
{ℂ : Cat}
{α β γ δ : ℂ.Obj}
{f : α ↠ β}
{g : γ ↠ δ}
(h : f ≋ g)
: (
@Equiv ℂ α β f α β (
let h_dom := domEq h
let h_cod := codEq h
by
rw [h_dom, h_cod]
exact g
)
) :=
by
cases h with
| proof g eq =>
apply proof g eq
theorem Fam.Cat.Hom.Equiv.toEq
{ℂ : Cat}
{α β : ℂ.Obj}
{f : α ↠ β}
{g : α ↠ β}
(h : f ≋ g)
: (f ≈ g) :=
match h with
| proof _ eq =>
eq
/-! ## `Fam.Cat.Hom.Equiv` is an equivalence relation
We cannot build an `Equivalence` though, as it takes a `r : α → α → Prop`. `Equiv`'s arguments do
not have the same type in general `:/`.
We can still prove that `Equiv` is reflexive, symmetric and transitive so let's just do that.
-/
namespace Fam.Cat.Hom.Equiv
theorem refl
{ℂ : Cat}
{α β : ℂ.Obj}
(f : α ↠ β)
: f ≋ f :=
let eq_f :=
ℂ.Hom α β |>.refl f
proof f eq_f
theorem symm
{ℂ : Cat}
{α₁ β₁ α₂ β₂ : ℂ.Obj}
(f₁ : α₁ ↠ β₁)
(f₂ : α₂ ↠ β₂)
: f₁ ≋ f₂ → f₂ ≋ f₁ :=
by
intro h
cases h
apply proof
apply ℂ.Hom α₁ β₁ |>.symm
assumption
theorem trans
{ℂ : Cat}
{α₁ β₁ α₂ β₂ α₃ β₃ : ℂ.Obj}
{f₁ : α₁ ↠ β₁}
{f₂ : α₂ ↠ β₂}
{f₃ : α₃ ↠ β₃}
: f₁ ≋ f₂ → f₂ ≋ f₃ → f₁ ≋ f₃ :=
by
intro h₁₂ h₂₃
cases h₁₂ ; cases h₂₃
apply proof
apply ℂ.Hom α₁ β₁ |>.trans
<;> assumption
end Fam.Cat.Hom.Equiv
instance instTransHomEq
{ℂ : Fam.Cat}
{α₁ β₁ α₂ β₂ α₃ β₃ : ℂ.Obj}
: Trans
(@Fam.Cat.Hom.Equiv.equiv ℂ α₁ β₁ α₂ β₂)
(@Fam.Cat.Hom.Equiv.equiv ℂ α₂ β₂ α₃ β₃)
(@Fam.Cat.Hom.Equiv.equiv ℂ α₁ β₁ α₃ β₃)
where
trans :=
Fam.Cat.Hom.Equiv.trans
|
Formal statement is: corollary fps_coeff_residues_bigo: fixes f :: "complex \<Rightarrow> complex" and r :: real assumes "open A" "connected A" "cball 0 r \<subseteq> A" "r > 0" assumes "f holomorphic_on A - S" "S \<subseteq> ball 0 r" "finite S" "0 \<notin> S" assumes g: "eventually (\<lambda>n. g n = -(\<Sum>z\<in>S. residue (\<lambda>z. f z / z ^ Suc n) z)) sequentially" (is "eventually (\<lambda>n. _ = -?g' n) _") shows "(\<lambda>n. (deriv ^^ n) f 0 / fact n - g n) \<in> O(\<lambda>n. 1 / r ^ n)" (is "(\<lambda>n. ?c n - _) \<in> O(_)") Informal statement is: Suppose $f$ is a holomorphic function on a connected open set $A$ containing the closed ball of radius $r$ centered at the origin, and $S$ is a finite set of points in the open ball of radius $r$ centered at the origin. Suppose that $0$ is not in $S$. Then the sequence of coefficients of the Taylor series of $f$ centered at $0$ is asymptotically equal to the sequence of residues of $f$ at the points in $S$. |
Require Import ZArith ROmega.
(* Submitted by Yegor Bryukhov (#922) *)
Open Scope Z_scope.
(* First a simplified version used during debug of romega on Test46 *)
Lemma Test46_simplified :
forall v1 v2 v5 : Z,
0 = v2 + v5 ->
0 < v5 ->
0 < v2 ->
4*v2 <> 5*v1.
intros.
romega.
Qed.
(* The complete problem *)
Lemma Test46 :
forall v1 v2 v3 v4 v5 : Z,
((2 * v4) + (5)) + (8 * v2) <= ((4 * v4) + (3 * v4)) + (5 * v4) ->
9 * v4 > (1 * v4) + ((2 * v1) + (0 * v2)) ->
((9 * v3) + (2 * v5)) + (5 * v2) = 3 * v4 ->
0 > 6 * v1 ->
(0 * v3) + (6 * v2) <> 2 ->
(0 * v3) + (5 * v5) <> ((4 * v2) + (8 * v2)) + (2 * v5) ->
7 * v3 > 5 * v5 ->
0 * v4 >= ((5 * v1) + (4 * v1)) + ((6 * v5) + (3 * v5)) ->
7 * v2 = ((3 * v2) + (6 * v5)) + (7 * v2) ->
0 * v3 > 7 * v1 ->
9 * v2 < 9 * v5 ->
(2 * v3) + (8 * v1) <= 5 * v4 ->
5 * v2 = ((5 * v1) + (0 * v5)) + (1 * v2) ->
0 * v5 <= 9 * v2 ->
((7 * v1) + (1 * v3)) + ((2 * v3) + (1 * v3)) >= ((6 * v5) + (4)) + ((1) + (9))
-> False.
intros.
romega.
Qed.
|
Unset Strict Universe Declaration.
(* -*- coq-prog-args: ("-nois") -*- *)
(* File reduced by coq-bug-finder from original input, then from 830 lines to 47 lines, then from 25 lines to 11 lines *)
(* coqc version 8.5beta1 (March 2015) compiled on Mar 11 2015 18:51:36 with OCaml 4.01.0
coqtop version cagnode15:/afs/csail.mit.edu/u/j/jgross/coq-8.5,v8.5 (8dbfee5c5f897af8186cb1bdfb04fd4f88eca677) *)
Declare ML Module "ltac_plugin".
Set Universe Polymorphism.
Class Contr_internal (A : Type) := BuildContr { center : A }.
Arguments center A {_}.
Class Contr (A : Type) : Type := Contr_is_trunc : Contr_internal A.
Hint Extern 0 => progress change Contr_internal with Contr in * : typeclass_instances.
Definition contr_paths_contr0 {A} `{Contr A} : Contr A := {| center := center A |}.
Instance contr_paths_contr1 {A} `{Contr A} : Contr A := {| center := center A |}.
Check @contr_paths_contr0@{i}.
Check @contr_paths_contr1@{i}. (* Error: Universe instance should have length 2 *)
(** It should have length 1, just like contr_paths_contr0 *)
|
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
module Pinwheel.Transform where
import Control.DeepSeq
import Data.Array.IArray as IA
import Data.Complex
import Data.List as L
import Data.Vector.Generic as VG
import Data.Vector.Unboxed as VU
import FokkerPlanck.FourierSeries (getHarmonics)
import FokkerPlanck.Histogram
import Pinwheel.List
import Sparse.Vector as SV
import Utils.List
import Utils.Parallel hiding (dot)
data PinwheelTransformData a b =
PinwheelTransformData a
a
b
instance (NFData a, NFData b) => NFData (PinwheelTransformData a b) where
rnf (PinwheelTransformData x y z) = x `seq` y `seq` z `seq` ()
{-# INLINE projectVec #-}
projectVec ::
( VG.Vector vector e
, VG.Vector vector (Complex e)
, VG.Vector vector Int
, Num e
, RealFloat e
)
=> Int
-> Int
-> e
-> vector (Complex e)
-> PinwheelTransformData e (SparseVector vector (Complex e))
-> Complex e
projectVec angularFreq radialFreq sigma pinwheel (PinwheelTransformData logR theta sparseVec) =
((exp ((sigma - 1) * logR)) :+ 0) *
(cis $
(-1) * (theta * fromIntegral angularFreq + logR * fromIntegral radialFreq)) *
(sparseVec `dot` pinwheel)
{-# INLINE pinwheelTransform #-}
pinwheelTransform ::
( VG.Vector vector e
, VG.Vector vector (Complex e)
, VG.Vector vector Int
, NFData e
, RealFloat e
, Unbox e
)
=> Int
-> Int
-> Int
-> Int
-> Int
-> e
-> IA.Array (Int, Int) (vector (Complex e))
-> [PinwheelTransformData e (SparseVector vector (Complex e))]
-> Histogram (Complex e)
pinwheelTransform numThread maxPhiFreq maxRhoFreq maxThetaFreq maxRFreq sigma pinwheelArr xs =
let coef =
parMapChunk
(ParallelParams numThread undefined)
rdeepseq
(\(rFreq, thetaFreq, rhoFreq, phiFreq) ->
let pinwheel =
getHarmonics
pinwheelArr
(fromIntegral phiFreq)
(fromIntegral rhoFreq)
(fromIntegral thetaFreq)
(fromIntegral rFreq)
in L.foldl'
(\s x -> s + projectVec thetaFreq rFreq sigma pinwheel x)
0
xs) $
[ (rFreq, thetaFreq, rhoFreq, phiFreq)
| rFreq <- [-maxRFreq .. maxRFreq]
, thetaFreq <- [-maxThetaFreq .. maxThetaFreq]
, rhoFreq <- [-maxRhoFreq .. maxRhoFreq]
, phiFreq <- [-maxPhiFreq .. maxPhiFreq]
]
in Histogram
[ 2 * maxPhiFreq + 1
, 2 * maxRhoFreq + 1
, 2 * maxThetaFreq + 1
, 2 * maxRFreq + 1
]
1 .
VU.fromList $
coef
|
--
-- The Falso HyperProver in Lean. Why bother with another axiom system?
-- (c) Copyright 2018 Michael Jendrusch
--
-- For details about the copyright, see the file
-- LICENSE, included in this distribution.
--
import falso.hyperprover
-- As a small example of the immense reasoning power of
-- the Falso (TM) system, we shall prove Fermat's theorem.
def fermat_true (n : ℕ) : Prop :=
n > 2 → ¬(
∃ x y z : ℕ,
x > 0 ∧
y > 0 ∧
z > 0 ∧
x^n + y^n = z^n
)
-- And that's it for the proof.
theorem Fermat (n : ℕ) : fermat_true n :=
by falso.hyperprove
-- Equivalent:
-- falso.prove (fermat_true n)
-- QED. |
lemma compact_lemma: fixes f :: "nat \<Rightarrow> 'a::euclidean_space" assumes "bounded (range f)" shows "\<forall>d\<subseteq>Basis. \<exists>l::'a. \<exists> r. strict_mono r \<and> (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially)" |
[STATEMENT]
lemma null_is_zero [simp]:
shows "OP null t = null" and "OP t null = null"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. OP null t = null &&& OP t null = null
[PROOF STEP]
using null_def ex_un_null theI' [of "\<lambda>n. \<forall>t. OP n t = n \<and> OP t n = n"]
[PROOF STATE]
proof (prove)
using this:
null = (THE n. \<forall>t. OP n t = n \<and> OP t n = n)
\<exists>!n. \<forall>t. OP n t = n \<and> OP t n = n
\<exists>!x. \<forall>t. OP x t = x \<and> OP t x = x \<Longrightarrow> \<forall>t. OP (THE x. \<forall>t. OP x t = x \<and> OP t x = x) t = (THE x. \<forall>t. OP x t = x \<and> OP t x = x) \<and> OP t (THE x. \<forall>t. OP x t = x \<and> OP t x = x) = (THE x. \<forall>t. OP x t = x \<and> OP t x = x)
goal (1 subgoal):
1. OP null t = null &&& OP t null = null
[PROOF STEP]
by auto |
record Four a b c d where
constructor MkFour
x : a
y : b
z : c
w : d
firstTwo : Four a b c d -> (a, b)
firstTwo $ MkFour {x, y, _} = (x, y)
record X where
constructor MkX
x : Int
y : Nat
z : Integer
SomeX : Monad m => m X
SomeX = pure $ MkX {x=5} {y=3} {z=10}
analyzeX : Monad m => m Integer
analyzeX = do
MkX {y, z, _} <- SomeX
pure $ z + natToInteger y
|
State Before: a b c : ℕ
⊢ Ico a (a + 1) = {a} State After: no goals Tactic: rw [Ico_succ_right, Icc_self] |
import LMT
variable {I} [Nonempty I] {E} [Nonempty E] [Nonempty (A I E)]
example {a1 a2 a3 : A I E} :
((a3).write i1 (v3)) = (a3) → ((a3).read i1) ≠ (v3) → False := by
arr
|
module Core.Variable
import Gen.Common
-- 0 0 o8o 8YYYo Y8Y o8o 8888. 0 8YYYY
-- ____ ____ 0 0 8 8 8___P 0 8 8 8___Y 0 8___
-- """" """" "o o" 8YYY8 8""Yo 0 8YYY8 8"""o 0 8"""
-- "8" 0 0 0 0 o8o 0 0 8ooo" 8ooo 8oooo
public export
data Variable = Name String | Generated String Int
export
implementation Interfaces.Eq Variable where
(Name x) == (Name y) = x == y
(Generated _ i) == (Generated _ j) = i == j
_ == _ = False
export
implementation Show Variable where
show (Name x) = x
show (Generated x _) = x
-- 8YYYY 0 0 0 0 8o 0 o8o 8_ _8 8YYYY
-- 8___ 0 0 0 0 8Yo 8 8 8 8"o_o"8 8___
-- 8""" 0 0 0 0 8 Yo8 8YYY8 0 8 0 8"""
-- 0 "ooo" 8ooo 8ooo 0 8 0 0 0 0 8oooo
public export
FullName : Type
FullName = Pair String String
|
[STATEMENT]
lemma in_open_segment_rotD:
"x \<in> {a<--<b} \<Longrightarrow> (x - a) \<bullet> rot (b - a) = 0 \<and> x \<bullet> (b - a) \<in> {a\<bullet>(b - a) <..< b \<bullet> (b - a)}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. x \<in> {a<--<b} \<Longrightarrow> (x - a) \<bullet> rot (b - a) = 0 \<and> x \<bullet> (b - a) \<in> {a \<bullet> (b - a)<..<b \<bullet> (b - a)}
[PROOF STEP]
by (subst in_open_segment_iff_rot[symmetric]) auto |
C * * * * * * * * * * * * * * *
C --- DRIVER FOR RADAR5
C * * * * * * * * * * * * * * *
C Use make command (relevant to Makefile)
IMPLICIT REAL*8 (A-H,O-Z)
INTEGER, PARAMETER :: DP=kind(1D0)
C ---> PARAMETERS FOR RADAR5 (FULL JACOBIAN) <---
INTEGER, PARAMETER :: ND=4
INTEGER, PARAMETER :: NRDENS=1
INTEGER, PARAMETER :: NGRID=11
INTEGER, PARAMETER :: NLAGS=1
INTEGER, PARAMETER :: NJACL=2
INTEGER, PARAMETER :: MXST=1000
INTEGER, PARAMETER :: LWORK=30
INTEGER, PARAMETER :: LIWORK=30
INTEGER, PARAMETER :: NPAR=2
REAL(kind=DP), dimension(ND) :: Y
REAL(kind=DP), dimension(NGRID+1) :: GRID
REAL(kind=DP), dimension(LWORK) :: WORK
INTEGER, dimension(LIWORK) :: IWORK
INTEGER, dimension(NRDENS+1) :: IPAST
REAL(kind=DP), dimension(NPAR) :: RPAR
INTEGER, dimension(22) :: ISTAT
EXTERNAL FCN,PHI,ARGLAG,JFCN,JACLAG,SOLOUT
C ------ FILE TO OPEN ----------
OPEN(9,FILE='sol.out')
OPEN(10,FILE='cont.out')
REWIND 9
REWIND 10
C --- PARAMETERS IN THE DIFFERENTIAL EQUATION
C --- Tau
RPAR(1)= 4.0D0
C --- K1
RPAR(2)= 0.0005D0
C -----------------------------------------------------------------------
C
C --- DIMENSION OF THE SYSTEM
N=ND
C --- COMPUTE THE JACOBIAN ANALYTICALLY
IJAC=1
C --- JACOBIAN IS A FULL MATRIX
MLJAC=N
C --- DIFFERENTIAL EQUATION IS IN EXLPICIT FORM
IMAS=0
MLMAS=N
C --- OUTPUT ROUTINE IS USED DURING INTEGRATION
IOUT=1
C --- INITIAL VALUES
X=0.0D0
Y(1)=6.0D1
Y(2)=1.0D1
Y(3)=1.0D1
Y(4)=2.0D1
C Consistent with initial function
C --- ENDPOINT OF INTEGRATION
XEND=160.0D0
C --- REQUIRED (RELATIVE AND ABSOLUTE) TOLERANCE
ITOL=0
RTOL=1.D-6
ATOL=RTOL*1.0D0
C --- INITIAL STEP SIZE
H=1.0D-6
C --- DEFAULT VALUES FOR PARAMETERS
DO 10 I=1,20
IWORK(I)=0
10 WORK(I)=0.0D0
C --- WORKSPACE FOR PAST
IWORK(12)=MXST
C --- THE FOURTH COMPONENT USES RETARDED ARGUMENTS
IWORK(15)=NRDENS
IPAST(1)=4
C --- SET THE PRESCRIBED GRID-POINTS
DO I=1,NGRID
GRID(I)=RPAR(1)*I
END DO
C --- WORKSPACE FOR GRID
IWORK(13)=NGRID
C _____________________________________________________________________
C --- CALL OF THE SUBROUTINE RADAR5
CALL RADAR5(N,FCN,PHI,ARGLAG,X,Y,XEND,H,
& RTOL,ATOL,ITOL,
& JFCN,IJAC,MLJAC,MUJAC,
& JACLAG,NLAGS,NJACL,
& IMAS,SOLOUT,IOUT,
& WORK,IWORK,RPAR,IPAR,IDID,
& GRID,IPAST,DUMMY,MLMAS,MUMAS)
C --- PRINT FINAL SOLUTION SOLUTION
WRITE (6,90) X,Y(1),Y(2),Y(3),Y(4)
C --- PRINT STATISTICS
DO J=14,20
ISTAT(J)=IWORK(J)
END DO
WRITE(6,*)' ***** TOL=',RTOL,' ****'
WRITE (6,91) (ISTAT(J),J=14,20)
90 FORMAT(1X,'X =',F8.2,' Y =',4E18.10)
91 FORMAT(' fcn=',I7,' jac=',I6,' step=',I6,
& ' accpt=',I6,' rejct=',I6,' dec=',I6,
& ' sol=',I7)
WRITE(6,*) 'SOLUTION IS TABULATED IN FILES: sol.out & cont.out'
STOP
END
C
SUBROUTINE SOLOUT (NR,XOLD,X,HSOL,Y,CONT,LRC,N,
& RPAR,IPAR,IRTRN)
C ----- PRINTS THE DISCRETE OUTPUT AND THE CONTINUOUS OUTPUT
C AT EQUIDISTANT OUTPUT-POINTS
IMPLICIT REAL*8 (A-H,O-Z)
INTEGER, PARAMETER :: DP=kind(1D0)
REAL(kind=DP), PARAMETER :: XSTEP=0.01D0
REAL(kind=DP), dimension(N) :: Y
REAL(kind=DP), dimension(LRC) :: CONT
REAL(kind=DP), dimension(1) :: RPAR
EXTERNAL PHI
C XOUT IS USED FOR THE DENSE OUTPUT
COMMON /INTERN/XOUT
WRITE (9,99) X,Y(1),Y(2),Y(3),Y(4)
C
IF (NR.EQ.1) THEN
WRITE (10,99) X,Y(1),Y(2),Y(3),Y(4)
XOUT=XSTEP
ELSE
10 CONTINUE
IF (X.GE.XOUT) THEN
WRITE (10,99) XOUT,CONTR5(1,N,XOUT,CONT,X,HSOL),
& CONTR5(2,N,XOUT,CONT,X,HSOL),
& CONTR5(3,N,XOUT,CONT,X,HSOL),
& CONTR5(4,N,XOUT,CONT,X,HSOL)
XOUT=XOUT+XSTEP
GOTO 10
END IF
END IF
99 FORMAT(1X,'X =',F12.8,' Y =',4E18.10)
RETURN
END
C
FUNCTION ARGLAG(IL,X,Y,RPAR,IPAR,PHI,PAST,IPAST,NRDS)
IMPLICIT REAL*8 (A-H,O-Z)
INTEGER, PARAMETER :: DP=kind(1D0)
REAL(kind=DP), dimension(1) :: Y
REAL(kind=DP), dimension(1) :: PAST
INTEGER, dimension(1) :: IPAST
REAL(kind=DP), dimension(1) :: RPAR
ARGLAG=X-RPAR(1)
RETURN
END
SUBROUTINE FCN(N,X,Y,F,ARGLAG,PHI,RPAR,IPAR,
& PAST,IPAST,NRDS)
IMPLICIT REAL*8 (A-H,K,O-Z)
INTEGER, PARAMETER :: DP=kind(1D0)
REAL(kind=DP), dimension(N) :: Y
REAL(kind=DP), dimension(N) :: F
REAL(kind=DP), dimension(1) :: PAST
INTEGER, dimension(1) :: IPAST
REAL(kind=DP), dimension(1) :: RPAR
EXTERNAL PHI,ARGLAG
C FIRST DELAY
CALL LAGR5(1,X,Y,ARGLAG,PAST,ALPHA1,IPOS1,RPAR,IPAR,
& PHI,IPAST,NRDS)
Y4L1=YLAGR5(4,ALPHA1,IPOS1,PHI,RPAR,IPAR,
& PAST,IPAST,NRDS)
U=1.D0/(1.D0 + RPAR(2)*Y4L1**3)
F(1)= 10.5D0 - Y(1)*U
F(2)= Y(1)*U - Y(2)
F(3)= Y(2) - Y(3)
F(4)= Y(3) - 0.5D0*Y(4)
RETURN
END
C
SUBROUTINE JFCN(N,X,Y,DFY,LDFY,ARGLAG,PHI,RPAR,IPAR,
& PAST,IPAST,NRDS)
C ----- STANDARD JACOBIAN OF THE EQUATION
IMPLICIT REAL*8 (A-H,K,O-Z)
INTEGER, PARAMETER :: DP=kind(1D0)
REAL(kind=DP), dimension(N) :: Y
REAL(kind=DP), dimension(LDFY,N) :: DFY
REAL(kind=DP), dimension(1) :: PAST
INTEGER, dimension(1) :: IPAST
REAL(kind=DP), dimension(1) :: RPAR
EXTERNAL PHI,ARGLAG
C FIRST DELAY
CALL LAGR5(1,X,Y,ARGLAG,PAST,ALPHA1,IPOS1,RPAR,IPAR,
& PHI,IPAST,NRDS)
Y4L1=YLAGR5(4,ALPHA1,IPOS1,PHI,RPAR,IPAR,
& PAST,IPAST,NRDS)
U=1.D0/(1.D0 + RPAR(2)*Y4L1**3)
C STANDARD JACOBIAN MATRIX 4x4
DFY(1,1)=-U
DFY(1,2)= 0.D0
DFY(1,3)= 0.D0
DFY(1,4)= 0.D0
DFY(2,1)= U
DFY(2,2)=-1.D0
DFY(2,3)= 0.D0
DFY(2,4)= 0.D0
DFY(3,1)= 0.D0
DFY(3,2)= 1.D0
DFY(3,3)=-1.D0
DFY(3,4)= 0.D0
DFY(4,1)= 0.D0
DFY(4,2)= 0.D0
DFY(4,3)= 1.D0
DFY(4,4)=-0.5D0
RETURN
END
C
SUBROUTINE JACLAG(N,X,Y,DFYL,ARGLAG,PHI,IVE,IVC,IVL,
& RPAR,IPAR,PAST,IPAST,NRDS)
C ----- JACOBIAN OF DELAY TERMS IN THE EQUATION
IMPLICIT REAL*8 (A-H,O-Z)
INTEGER, PARAMETER :: DP=kind(1D0)
REAL(kind=DP), dimension(N) :: Y
REAL(kind=DP), dimension(1) :: DFYL
REAL(kind=DP), dimension(1) :: PAST
INTEGER, dimension(1) :: IPAST
REAL(kind=DP), dimension(1) :: RPAR
INTEGER, dimension(1) :: IVE,IVC,IVL
EXTERNAL PHI
C FIRST DELAY
CALL LAGR5(1,X,Y,ARGLAG,PAST,ALPHA1,IPOS1,RPAR,IPAR,
& PHI,IPAT,NRDS)
Y4L1=YLAGR5(4,ALPHA1,IPOS1,PHI,RPAR,IPAR,
& PAST,IPAST,NRDS)
UD=(3.D0*RPAR(2)*Y(1)*Y4L1**2)/((1.D0+RPAR(2)*Y4L1**3)**2)
IVL(1)=1
IVE(1)=1
IVC(1)=4
IVL(2)=1
IVE(2)=2
IVC(2)=4
DFYL(1)= UD
DFYL(2)=-UD
RETURN
END
C
FUNCTION PHI(I,X,RPAR,IPAR)
IMPLICIT REAL*8 (A-H,O-Z)
INTEGER, PARAMETER :: DP=kind(1D0)
REAL(kind=DP), dimension(1) :: RPAR
SELECT CASE (I)
CASE (1)
PHI=6.0D1
CASE (2)
PHI=1.0D1
CASE (3)
PHI=1.0D1
CASE (4)
PHI=2.0D1
END SELECT
RETURN
END
|
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Numeric.Loss.MeanSquaredError where
import Numeric.Loss
import Dependent.Size
import qualified Numeric.Vector.Sized as Sized
import Numeric.Vector.Sized(SizedVector',SizedVector)
import Data.Proxy
import GHC.TypeLits(KnownNat,Nat,natVal)
newtype MeanSquaredError (n :: Nat) = MeanSquaredError ()
instance forall n. KnownNat n => Loss (ZZ ::. n) (MeanSquaredError n) where
-- forward (MeanSquaredError targets) x
-- = (err, x)
-- where
-- err = (normalize . Sized.foldAll (+) 0 . Sized.map square) (Sized.zipWith (-) x (Sized.use targets))
-- square x = x ^2
-- n = fromInteger $ natVal (Proxy :: Proxy (n :: Nat))
-- normalize total = Sized.map (\t -> t / n) total
lossDerivative _ x targets = dx
where
dx = normalize (Sized.zipWith (-) x targets)
n = fromInteger $ natVal (Proxy :: Proxy (n :: Nat))
normalize zs = Sized.map (\z -> 2/n * z) zs
|
lemma norm_le_zero_iff [simp]: "norm x \<le> 0 \<longleftrightarrow> x = 0" |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
! This file was ported from Lean 3 source module topology.instances.sign
! leanprover-community/mathlib commit 4c19a16e4b705bf135cf9a80ac18fcc99c438514
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Sign
import Mathlib.Topology.Order.Basic
/-!
# Topology on `SignType`
This file gives `SignType` the discrete topology, and proves continuity results for `SignType.sign`
in an `OrderTopology`.
-/
instance : TopologicalSpace SignType :=
⊥
instance : DiscreteTopology SignType :=
⟨rfl⟩
variable {α : Type _} [Zero α] [TopologicalSpace α]
section PartialOrder
variable [PartialOrder α] [DecidableRel ((· < ·) : α → α → Prop)] [OrderTopology α]
theorem continuousAt_sign_of_pos {a : α} (h : 0 < a) : ContinuousAt SignType.sign a := by
refine' (continuousAt_const : ContinuousAt (fun _ => (1 : SignType)) a).congr _
rw [Filter.EventuallyEq, eventually_nhds_iff]
exact ⟨{ x | 0 < x }, fun x hx => (sign_pos hx).symm, isOpen_lt' 0, h⟩
#align continuous_at_sign_of_pos continuousAt_sign_of_pos
theorem continuousAt_sign_of_neg {a : α} (h : a < 0) : ContinuousAt SignType.sign a := by
refine' (continuousAt_const : ContinuousAt (fun x => (-1 : SignType)) a).congr _
rw [Filter.EventuallyEq, eventually_nhds_iff]
exact ⟨{ x | x < 0 }, fun x hx => (sign_neg hx).symm, isOpen_gt' 0, h⟩
#align continuous_at_sign_of_neg continuousAt_sign_of_neg
end PartialOrder
section LinearOrder
variable [LinearOrder α] [OrderTopology α]
theorem continuousAt_sign_of_ne_zero {a : α} (h : a ≠ 0) : ContinuousAt SignType.sign a := by
rcases h.lt_or_lt with (h_neg | h_pos)
· exact continuousAt_sign_of_neg h_neg
· exact continuousAt_sign_of_pos h_pos
#align continuous_at_sign_of_ne_zero continuousAt_sign_of_ne_zero
end LinearOrder
|
% simple wrapper for softmax function
function [y] = softmax(x)
logZ = logsum(x, 2);
y = exp(bsxfun(@minus, x, logZ));
|
open import Oscar.Prelude
open import Oscar.Class.[ExtensibleType]
open import Oscar.Data.Proposequality
module Oscar.Class.[ExtensibleType].Proposequality where
instance
[ExtensibleType]Proposequality : ∀ {a} {b} {A : Set a} {B : A → Set b} → [ExtensibleType] (λ {w} → Proposequality⟦ B w ⟧)
[ExtensibleType]Proposequality = ∁
|
/-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
-/
import .basic
import logic.cast
open function
open category eq eq.ops heq
structure functor (C D : Category) : Type :=
(object : C → D)
(morphism : Π⦃a b : C⦄, hom a b → hom (object a) (object b))
(respect_id : Π (a : C), morphism (ID a) = ID (object a))
(respect_comp : Π ⦃a b c : C⦄ (g : hom b c) (f : hom a b),
morphism (g ∘ f) = morphism g ∘ morphism f)
infixl `⇒`:25 := functor
namespace functor
attribute object [coercion]
attribute morphism [coercion]
attribute respect_id [irreducible]
attribute respect_comp [irreducible]
variables {A B C D : Category}
protected definition compose [reducible] (G : functor B C) (F : functor A B) : functor A C :=
functor.mk
(λx, G (F x))
(λ a b f, G (F f))
(λ a, proof calc
G (F (ID a)) = G id : {respect_id F a}
--not giving the braces explicitly makes the elaborator compute a couple more seconds
... = id : respect_id G (F a) qed)
(λ a b c g f, proof calc
G (F (g ∘ f)) = G (F g ∘ F f) : respect_comp F g f
... = G (F g) ∘ G (F f) : respect_comp G (F g) (F f) qed)
infixr `∘f`:60 := functor.compose
protected theorem assoc (H : functor C D) (G : functor B C) (F : functor A B) :
H ∘f (G ∘f F) = (H ∘f G) ∘f F :=
rfl
protected definition id [reducible] {C : Category} : functor C C :=
mk (λa, a) (λ a b f, f) (λ a, rfl) (λ a b c f g, rfl)
protected definition ID [reducible] (C : Category) : functor C C := @functor.id C
protected theorem id_left (F : functor C D) : (@functor.id D) ∘f F = F :=
functor.rec (λ obF homF idF compF, dcongr_arg4 mk rfl rfl !proof_irrel !proof_irrel) F
protected theorem id_right (F : functor C D) : F ∘f (@functor.id C) = F :=
functor.rec (λ obF homF idF compF, dcongr_arg4 mk rfl rfl !proof_irrel !proof_irrel) F
end functor
namespace category
open functor
definition category_of_categories [reducible] : category Category :=
mk (λ a b, functor a b)
(λ a b c g f, functor.compose g f)
(λ a, functor.id)
(λ a b c d h g f, !functor.assoc)
(λ a b f, !functor.id_left)
(λ a b f, !functor.id_right)
definition Category_of_categories [reducible] := Mk category_of_categories
namespace ops
notation `Cat`:max := Category_of_categories
attribute category_of_categories [instance]
end ops
end category
namespace functor
variables {C D : Category}
theorem mk_heq {obF obG : C → D} {homF homG idF idG compF compG} (Hob : ∀x, obF x = obG x)
(Hmor : ∀(a b : C) (f : a ⟶ b), homF a b f == homG a b f)
: mk obF homF idF compF = mk obG homG idG compG :=
hddcongr_arg4 mk
(funext Hob)
(hfunext (λ a, hfunext (λ b, hfunext (λ f, !Hmor))))
!proof_irrel
!proof_irrel
protected theorem hequal {F G : C ⇒ D} : Π (Hob : ∀x, F x = G x)
(Hmor : ∀a b (f : a ⟶ b), F f == G f), F = G :=
functor.rec
(λ obF homF idF compF,
functor.rec
(λ obG homG idG compG Hob Hmor, mk_heq Hob Hmor)
G)
F
-- theorem mk_eq {obF obG : C → D} {homF homG idF idG compF compG} (Hob : ∀x, obF x = obG x)
-- (Hmor : ∀(a b : C) (f : a ⟶ b), cast (congr_arg (λ x, x a ⟶ x b) (funext Hob)) (homF a b f)
-- = homG a b f)
-- : mk obF homF idF compF = mk obG homG idG compG :=
-- dcongr_arg4 mk
-- (funext Hob)
-- (funext (λ a, funext (λ b, funext (λ f, sorry ⬝ Hmor a b f))))
-- -- to fill this sorry use (a generalization of) cast_pull
-- !proof_irrel
-- !proof_irrel
-- protected theorem equal {F G : C ⇒ D} : Π (Hob : ∀x, F x = G x)
-- (Hmor : ∀a b (f : a ⟶ b), cast (congr_arg (λ x, x a ⟶ x b) (funext Hob)) (F f) = G f), F = G :=
-- functor.rec
-- (λ obF homF idF compF,
-- functor.rec
-- (λ obG homG idG compG Hob Hmor, mk_eq Hob Hmor)
-- G)
-- F
end functor
|
c attempts to remove observations that are either too large or too small
c
c specify input time series
c
c compute a running median (not running mean)
c after specifying the period
c
c examine the residuals about the median
c
c identify observations greater or less than a threshold around the median
c eliminate those observations
c
c difference between bust_2 and bust_3 is that new verision allows for 2 different
c date formats
c
c Bust_4 uses more efficient algorithms to take medians and/or sort data
c
c Modified bust_4 (now _5) to:
c 1) remove sorting routines from Press et al Numerical recipes; substituting
c routines written by John Burkardt; https://people.sc.fsu.edu/~jburkardt/f77_src/i4lib/i4lib.f
c 2) Provide more variety in data formats
c 3) Get time subroutines from time.f
c
character*20 ifile,ofile
character*80 string
character*3 net
dimension d(9000000),e(9000000),dsrt(9000000),r(9000000)
integer year(9000000)
double precision fjul,fday,tsam_day,time0,time,day(9000000),
& dec_timed
fmiss=9999999.
nmax=9000000
do 1 i=1,nmax
r(i)=fmiss
1 d(i)=fmiss
print*,' Input the data format'
print*,' otr=data'
print*,' otr format of year day_of_year obs err'
print*,' otd format of YearMnDa obs err'
print*,' otx format of year mo da obs err'
print*,' mjd Modified Julian day, obs, err'
print*,'For all of the above, the da and doy are ',
& 'double precision'
print*,' which allows decimal days to accomodate seconds'
print*,' '
print*,' gmt GMT format for time'
print*,' year-mo-daThr:mn:secs.x obs err'
read(5,*)net
105 format(a3)
if (net .eq. '1') net='otr'
print*,'net is ', net
print*,' Input file to examine'
print*,' input format is year, julian day, data, data_error'
read(5,100)ifile
100 format(a20)
open(1,file=ifile)
print*,' Input name of output file'
read(5,100)ofile
open(4,file=ofile)
open(3,file="reject.out")
print*,' Input sampling interval in days'
print*,' 1--hour = ',1./24.d+0
print*,' 10--minutes =',10./(24.d+0 * 60.0d+0)
print*,' 1--minute = ',1.0/(24.d+0 * 60.0d+0)
print*,' 1--second =', 1.0/(24.d+0 * 3600.0d+0)
read(5,*)tsam_day
n=0
ic=0
2 continue
read(1,106,end=3) string
106 format(a80)
call GetData(net,string,time,obs,err)
if (n .eq. 0) time0=time
c if (n .eq. 0) then
c print*,yr,fjul,time
c end if
n=int(((time-time0)/tsam_day)+0.5)+1
ic=ic+1
day(n)=time
if (n .gt. nmax) then
print*,' Number of observation exceeds dimensions'
print*,' n=',n,' nmax= ',nmax
print*,' time0=',time0
print*,' last record read is',yr,fjul,obs
print*,' time=', time
stop
end if
c print*,n,n+1,year(n+1),fjul,day(n+1)
c write(2,*)n,time(n)
d(n)=obs
dsrt(ic)=obs
e(n)=err
c write(10,*)n,yr,fjul,obs,time,year(n),day(n),d(n)
c print*,year,fjul,time,ic,n,time-time0,(time-time0)/tsam_day
if (n .ge. nmax) then
print*,' Number of observations exceed dimensions'
print*,' nmax=',nmax,' n=',n
print*,' time0=', time0
print*,n,yr,fjul,obs,time,year(n),day(n),d(n)
stop
end if
go to 2
3 continue
print*,' number of data',ic
print*,' Total number of days ',n*tsam_day
c remove median and a secular rate
if (ic .gt. 0 ) then
call i4vec_median (ic, dsrt, xmed )
else
xmed=0.0
end if
print*,' the median is: ', xmed
do 12 i=1,n
if (d(i) .ne. fmiss) r(i)=d(i)-xmed
12 continue
tstart=0
print*,' Input the window length in days to compute running ',
& 'median'
read(5,*)per
nwind=int(per/tsam_day)
print*,' Number of points in window', nwind
n_tot_wind=int(n/nwind)
print*,' Total number of windows is', n_tot_wind+1
c
c compute medians of windows of data with length perio
c
c istart=1
c istop=istart+nwind-1
do 20 k=1,n_tot_wind
istart=k*nwind-nwind+1
istop=k*nwind
ix=0
do 21 i=istart,istop
if (r(i) .ne. fmiss) then
ix=ix+1
dsrt(ix)=r(i)
end if
21 continue
c xmed=fmedian(ix,dsrt)
c print*,istart,istop,ix
if (ix .gt. 0) then
call i4vec_median (ix, dsrt, xmed )
else
xmed=0.0
end if
print*,istart,istop,ix,xmed
c remove running median
do 22 i=istart,istop
if (r(i) .ne. fmiss) r(i)=r(i)-xmed
22 continue
20 continue
c same as above but for the last window
istart=istop+1
istop=n
ix=0
do 23 i=istart,istop
if (r(i) .ne. fmiss) then
ix=ix+1
dsrt(ix)=r(i)
end if
23 continue
c xmed=fmedian(ix,dsrt)
if (ix .gt. 0) then
call i4vec_median (ix, dsrt, xmed )
else
xmed=0.0
end if
print*,istart,istop,ix,xmed
do 24 i=istart,istop
if (r(i) .ne. fmiss) r(i)=r(i)-xmed
24 continue
c
c sort the data to get statistics on data
c
sum=0.0
ix=0
do 30 i=1,n
if (r(i) .ne. fmiss) then
ix=ix+1
dsrt(ix)=r(i)
sum=sum+r(i)**2
c write(98,*)ix,dsrt(ix)
end if
30 continue
print*," Number of missing observations is ",n-ix
c call i4vec_heap_a ( ix, dsrt )
c if (ix .gt. 0 ) then
c call i4vec_sort_heap_d ( ix, dsrt )
c end if
c do 301 i=1,ix
c write(99,*)i,dsrt(i)
c301 continue
c call hpsort(ix,dsrt)
c print*," Minimum value ",1,dsrt(1)
c print*," Maximum value ",ix,dsrt(ix)
print*, 'Standard deviation of filtered data is ',
& sqrt(sum/float(ix))
call i4vec_frac ( ix, dsrt, 1, xx1 )
call i4vec_frac ( ix, dsrt, ix, xx2 )
print*," Extreme values ",xx1,xx2,
& " distance = ",xx2-xx1
n75=int(0.125*ix)
n25=ix-n75+1
call i4vec_frac ( ix, dsrt, n75, xx1)
call i4vec_frac ( ix, dsrt, n25, xx2)
print*," 75% interval",xx1, xx2,
& " distance= ",xx2-xx1
thres0=xx2-xx1
n90=int(0.05*ix)
n10=ix-n90+1
call i4vec_frac ( ix, dsrt, n90, xx1)
call i4vec_frac ( ix, dsrt, n10, xx2)
print*," 90% interval",xx1,xx2,
& " distance= ",xx2-xx1
n95=int(0.025*ix)
n05=ix-n95+1
if (n95 .lt. 1) n95=1
if (n05 .gt. ix) n05=ix
call i4vec_frac ( ix, dsrt, n95, xx1)
call i4vec_frac ( ix, dsrt, n05, xx2)
print*," 95% interval",xx1,xx2,
& " distance= ",xx2-xx1
n99=int(0.005*ix)
n01=ix-n99+1
if (n99 .lt. 1) n99=1
if (n01 .gt. ix) n01=ix
call i4vec_frac ( ix, dsrt, n99, xx1)
call i4vec_frac ( ix, dsrt, n01, xx2)
print*," 99% interval",xx1,xx2,
& " distance= ",xx2-xx1
n999=int(0.0005*ix)
n001=ix-n999+1
if (n999 .lt. 1) n999=1
if (n001 .gt. ix) n001=ix
call i4vec_frac ( ix, dsrt, n999, xx1)
call i4vec_frac ( ix, dsrt, n001, xx2)
print*," 99.9% interval",xx1,xx2,
& " distance= ",xx2-xx1
print*, " Input the threshold used to reject data"
print*,' use units of IQR'
read(5,*)thres
thres=thres*thres0/2.0
print*,' The threshold is ',thres
nbust=0
do 40 i=1,n
if (d(i) .ne. fmiss) then
time=day(i)
itime=int(time)
dec_timed=(time)-int(time)
if (abs(r(i)) .lt. thres) then
if (net .eq. 'otr' ) then
call inv_jul_time(itime,nyr,jul)
write(4,6501)nyr,float(jul)+dec_timed,d(i),e(i)
end if
if (net .eq. 'otx' ) then
call invcal(itime,nyr,mn,idate)
write(4,6502)nyr,mn,idate+dec_timed,d(i),e(i)
end if
if (net .eq. 'otd' ) then
call invcal(itime,nyr,mn,idate)
write(4,6503)nyr,mn,idate,dec_timed,d(i),e(i)
end if
if (net .eq. 'gmt' ) then
call invcal(itime,nyr,mn,idate)
ihr1=int(24.0*dec_timed)
imn1=int(24.0*60.0*(dec_timed-dble(ihr1)/24.0))
sec1=dec_timed-dble(ihr1)/24.0-dble(imn1)/(24.0*60.0)
sec1=sec1*3600.0*24.0
isec1=int(sec1)
write(4,6504)nyr,mn,idate,ihr1,imn1,isec1,sec1,d(i),e(i)
end if
if (net .eq. 'mjd' ) then
write(4,6505)dble(itime)+dec_timed+36933.d+0,d(i),e(i)
end if
else
c output rejected data
if (net .eq. 'otr' ) then
call inv_jul_time(itime,nyr,jul)
write(3,65013)nyr,float(jul)+dec_timed,r(i),d(i),e(i)
end if
if (net .eq. 'otx' ) then
call invcal(itime,nyr,mn,idate)
write(3,65023)nyr,mn,idate+dec_timed,r(i),d(i),e(i)
end if
if (net .eq. 'otd' ) then
call invcal(itime,nyr,mn,idate)
write(3,65033)nyr,mn,idate,dec_timed,r(i),d(i),e(i)
end if
if (net .eq. 'gmt' ) then
call invcal(itime,nyr,mn,idate)
ihr1=int(24.0*dec_timed)
imn1=int(24.0*60.0*(dec_timed-dble(ihr1)/24.0))
sec1=dec_timed-dble(ihr1)/24.0-dble(imn1)/(24.0*60.0)
sec1=sec1*3600.0*24.0
isec1=int(sec1)
write(3,65043)nyr,mn,idate,ihr1,imn1,isec1,sec1,r(i)
& ,d(i),e(i)
end if
if (net .eq. 'mjd' ) then
write(3,65053)dble(itime)+dec_timed+36933.d+0,r(i)
& ,d(i),e(i)
end if
c write(3,*)i,day(i),r(i),d(i),e(i)
nbust=nbust+1
end if
end if
40 continue
6501 format(1x,i5,1x, f15.9, 1x, f15.2,1x,f8.2)
6502 format(1x,2i5,f15.9, 1x,f15.2, 1x,f8.2)
6503 format(1x,i4,i2.2,i2.2,f10.9, 1x,f15.2,1x,f8.2)
6504 format(1x,i4,'-',i2.2,'-',i2.2,'T',
& i2.2,':',i2.2,':',i2.2,f2.1, 1x,f15.2,1x,f8.2)
6505 format(1x,f18.9, 1x,f15.2,1x,f8.2)
65013 format(1x,i5,1x, f15.9, 1x, f15.2,1x,f8.2,1x,f8.2)
65023 format(1x,2i5,f15.9, 1x,f15.2, 1x,f8.2,1x,f8.2)
65033 format(1x,i4,i2.2,i2.2,f10.9, 1x,f15.2,1x,f8.2,1x,f8.2)
65043 format(1x,i4,'-',i2.2,'-',i2.2,'T',
& i2.2,':',i2.2,':',i2.2,f2.1, 1x,f15.2,1x,f8.2,1x,f8.2)
65053 format(1x,f18.9, 1x,f15.2,1x,f8.2,1x,f8.2)
print*," Number of data rejected is ", nbust
c istart=istop+nwind
print*," Clean data in ", ofile
print*," Outlyers in file reject.out"
close (1)
close (2)
close (3)
close (4)
stop
end
c Note --- only i4vec_median and i4vec_frac are used
c the remaining subroutines below (i4...) aren't needed
subroutine i4vec_median ( n, a, median )
c*********************************************************************72
c
cc I4VEC_MEDIAN returns the median of an unsorted I4VEC.
c
c Discussion:
c
c An I4VEC is a vector of I4's.
c
c Hoare's algorithm is used. The values of the vector are
c rearranged by this routine.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 06 July 2009
c
c Author:
c
c John Burkardt
c
c Parameters:
c
c Input, integer N, the number of elements of A.
c
c Input/output, integer A(N), the array to search. On output,
c the order of the elements of A has been somewhat changed.
c
c Output, integer MEDIAN, the value of the median of A.
c
c MODIFIED BY JL for real MEDIAN and real A
implicit none
integer n,i
real a(n)
integer k
real median
k = ( n + 1 ) / 2
c print*,n,k,(a(i),i=1,5)
if (n .ne. 0 ) then
c BUG FIX BY JOL.... crashes when n=0
call i4vec_frac ( n, a, k, median )
else
median=0
end if
return
end
subroutine i4vec_frac ( n, a, k, frac )
c*********************************************************************72
c
cc I4VEC_FRAC searches for the K-th smallest element in an I4VEC.
c
c Discussion:
c
c An I4VEC is a vector of I4's.
c
c Hoare's algorithm is used.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 18 July 2010
c
c Author:
c
c John Burkardt
c
c Parameters:
c
c Input, integer N, the number of elements of A.
c
c Input/output, integer A(N), array to search. On output,
c the elements of A have been somewhat rearranged.
c
c Input, integer K, the fractile to be sought. If K = 1, the
c minimum entry is sought. If K = N, the maximum is sought.
c Other values of K search for the entry which is K-th in size.
c K must be at least 1, and no greater than N.
c
c Output, integer FRAC, the value of the K-th fractile of A.
c
implicit none
integer n
real a(n)
real frac,ix,t
integer i
integer iryt
c integer ix
integer j
integer k
integer left
c integer t
c Changed by JOL when n = 0
if (n .eq. 0 ) then
frac=0
return
end if
if ( n .le. 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'I4VEC_FRAC - Fatal error!'
write ( *, '(a,i8)' ) ' Illegal nonpositive value of N = ', n
stop 1
end if
if ( k .le. 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'I4VEC_FRAC - Fatal error!'
write ( *, '(a,i8)' ) ' Illegal nonpositive value of K = ', k
stop 1
end if
if ( n .lt. k ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'I4VEC_FRAC - Fatal error!'
write ( *, '(a,i8)' ) ' Illegal N < K, K = ', k
stop 1
end if
left = 1
iryt = n
10 continue
if ( iryt .le. left ) then
frac = a(k)
go to 60
end if
ix = a(k)
i = left
j = iryt
20 continue
if ( j .lt. i ) then
if ( j .lt. k ) then
left = i
end if
if ( k .lt. i ) then
iryt = j
end if
go to 50
end if
c
c Find I so that IX <= A(I).
c
30 continue
if ( a(i) .lt. ix ) then
i = i + 1
go to 30
end if
c
c Find J so that A(J) <= IX.
c
40 continue
if ( ix .lt. a(j) ) then
j = j - 1
go to 40
end if
if ( i .le. j ) then
t = a(i)
a(i) = a(j)
a(j) = t
i = i + 1
j = j - 1
end if
go to 20
50 continue
go to 10
60 continue
return
end
subroutine i4vec_heap_a ( n, a )
c*********************************************************************72
c
cc I4VEC_HEAP_A reorders an I4VEC into an ascending heap.
c
c Discussion:
c
c An I4VEC is a vector of I4's.
c
c An ascending heap is an array A with the property that, for every index J,
c A(J) <= A(2*J) and A(J) <= A(2*J+1), (as long as the indices
c 2*J and 2*J+1 are legal).
c
c A(1)
c / \
c A(2) A(3)
c / \ / \
c A(4) A(5) A(6) A(7)
c / \ / \
c A(8) A(9) A(10) A(11)
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 18 July 2010
c
c Author:
c
c John Burkardt
c
c Reference:
c
c Albert Nijenhuis, Herbert Wilf,
c Combinatorial Algorithms for Computers and Calculators,
c Academic Press, 1978,
c ISBN: 0-12-519260-6,
c LC: QA164.N54.
c
c Parameters:
c
c Input, integer N, the size of the input array.
c
c Input/output, integer A(N).
c On input, an unsorted array.
c On output, the array has been reordered into a heap.
c
c MODIFIED by JL to take Real values
implicit none
integer n
real a(n)
integer i
integer ifree
real key
integer m
c
c Only nodes N/2 down to 1 can be "parent" nodes.
c
do i = n / 2, 1, -1
c
c Copy the value out of the parent node.
c Position IFREE is now "open".
c
key = a(i)
ifree = i
10 continue
c
c Positions 2*IFREE and 2*IFREE + 1 are the descendants of position
c IFREE. (One or both may not exist because they exceed N.)
c
m = 2 * ifree
c
c Does the first position exist?
c
if ( n .lt. m ) then
go to 20
end if
c
c Does the second position exist?
c
if ( m + 1 .le. n ) then
c
c If both positions exist, take the smaller of the two values,
c and update M if necessary.
c
if ( a(m+1) .lt. a(m) ) then
m = m + 1
end if
end if
c
c If the small descendant is smaller than KEY, move it up,
c and update IFREE, the location of the free position, and
c consider the descendants of THIS position.
c
if ( key .le. a(m) ) then
go to 20
end if
a(ifree) = a(m)
ifree = m
go to 10
c
c Once there is no more shifting to do, KEY moves into the free spot.
c
20 continue
a(ifree) = key
end do
return
end
subroutine i4vec_sort_heap_d ( n, a )
c*********************************************************************72
c
cc I4VEC_SORT_HEAP_D descending sorts an I4VEC using heap sort.
c
c Discussion:
c
c An I4VEC is a vector of I4's.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 31 August 2008
c
c Author:
c
c John Burkardt
c
c Reference:
c
c Albert Nijenhuis, Herbert Wilf,
c Combinatorial Algorithms for Computers and Calculators,
c Academic Press, 1978,
c ISBN: 0-12-519260-6,
c LC: QA164.N54.
c
c Parameters:
c
c Input, integer N, the number of entries in the array.
c
c Input/output, integer A(N).
c On input, the array to be sorted;
c On output, the array has been sorted.
c
c Modified by JL for real data, not integers
c
implicit none
integer n
real a(n)
integer n1
if ( n .le. 1 ) then
return
end if
c
c 1: Put A into ascending heap form.
c
call i4vec_heap_a ( n, a )
c
c 2: Sort A.
c
c The smallest object in the heap is in A(1).
c Move it to position A(N).
c
call i4_swap ( a(1), a(n) )
c
c Consider the diminished heap of size N1.
c
do n1 = n - 1, 2, -1
c
c Restore the heap structure of A(1) through A(N1).
c
call i4vec_heap_a ( n1, a )
c
c Take the smallest object from A(1) and move it to A(N1).
c
call i4_swap ( a(1), a(n1) )
end do
return
end
subroutine i4_swap ( i, j )
c*********************************************************************72
c
cc I4_SWAP switches two I4's.
c
c Licensing:
c
c This code is distributed under the GNU LGPL license.
c
c Modified:
c
c 06 January 2006
c
c Author:
c
c John Burkardt
c
c Parameters:
c
c Input/output, integer I, J. On output, the values of I and
c J have been interchanged.
c
implicit none
real i
real j
real k
k = i
i = j
j = k
return
end
|
{-# LANGUAGE ViewPatterns #-}
-- | Tests for Statistics.Math
module Tests.SpecFunctions (
tests
) where
import qualified Data.Vector as V
import Data.Vector ((!))
import Test.QuickCheck hiding (choose)
import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Tests.Helpers
import Tests.SpecFunctions.Tables
import Numeric.SpecFunctions
tests :: Test
tests = testGroup "Special functions"
[ testProperty "Gamma(x+1) = x*Gamma(x) [logGamma]" $ gammaReccurence logGamma 3e-8
, testProperty "Gamma(x+1) = x*Gamma(x) [logGammaL]" $ gammaReccurence logGammaL 2e-13
, testProperty "gamma(1,x) = 1 - exp(-x)" $ incompleteGammaAt1Check
, testProperty "0 <= gamma <= 1" $ incompleteGammaInRange
, testProperty "gamma - increases" $
\s x y -> s > 0 && x > 0 && y > 0 ==> monotonicallyIncreases (incompleteGamma s) x y
, testProperty "invIncompleteGamma = gamma^-1" $ invIGammaIsInverse
, testProperty "0 <= I[B] <= 1" $ incompleteBetaInRange
, testProperty "invIncompleteBeta = B^-1" $ invIBetaIsInverse
, testProperty "invErfc = erfc^-1" $ invErfcIsInverse
, testProperty "invErf = erf^-1" $ invErfIsInverse
-- Unit tests
, testAssertion "Factorial is expected to be precise at 1e-15 level"
$ and [ eq 1e-15 (factorial (fromIntegral n))
(fromIntegral (factorial' n))
|n <- [0..170]]
, testAssertion "Log factorial is expected to be precise at 1e-15 level"
$ and [ eq 1e-15 (logFactorial (fromIntegral n))
(log $ fromIntegral $ factorial' n)
| n <- [2..170]]
, testAssertion "logGamma is expected to be precise at 1e-9 level [integer points]"
$ and [ eq 1e-9 (logGamma (fromIntegral n))
(logFactorial (n-1))
| n <- [3..10000]]
, testAssertion "logGamma is expected to be precise at 1e-9 level [fractional points]"
$ and [ eq 1e-9 (logGamma x) lg | (x,lg) <- tableLogGamma ]
, testAssertion "logGammaL is expected to be precise at 1e-15 level"
$ and [ eq 1e-15 (logGammaL (fromIntegral n))
(logFactorial (n-1))
| n <- [3..10000]]
-- FIXME: Too low!
, testAssertion "logGammaL is expected to be precise at 1e-10 level [fractional points]"
$ and [ eq 1e-10 (logGammaL x) lg | (x,lg) <- tableLogGamma ]
-- FIXME: loss of precision when logBeta p q ≈ 0.
-- Relative error doesn't work properly in this case.
, testAssertion "logBeta is expected to be precise at 1e-6 level"
$ and [ eq 1e-6 (logBeta p q)
(logGammaL p + logGammaL q - logGammaL (p+q))
| p <- [0.1,0.2 .. 0.9] ++ [2 .. 20]
, q <- [0.1,0.2 .. 0.9] ++ [2 .. 20]
]
, testAssertion "digamma is expected to be precise at 1e-14 [integers]"
$ digammaTestIntegers 1e-14
-- Relative precision is lost when digamma(x) ≈ 0
, testAssertion "digamma is expected to be precise at 1e-12"
$ and [ eq 1e-12 r (digamma x) | (x,r) <- tableDigamma ]
-- FIXME: Why 1e-8? Is it due to poor precision of logBeta?
, testAssertion "incompleteBeta is expected to be precise at 1e-8 level"
$ and [ eq 1e-8 (incompleteBeta p q x) ib | (p,q,x,ib) <- tableIncompleteBeta ]
, testAssertion "incompleteBeta with p > 3000 and q > 3000"
$ and [ eq 1e-11 (incompleteBeta p q x) ib | (x,p,q,ib) <-
[ (0.495, 3001, 3001, 0.2192546757957825068677527085659175689142653854877723)
, (0.501, 3001, 3001, 0.5615652382981522803424365187631195161665429270531389)
, (0.531, 3500, 3200, 0.9209758089734407825580172472327758548870610822321278)
, (0.501, 13500, 13200, 0.0656209987264794057358373443387716674955276089622780)
]
]
, testAssertion "choose is expected to precise at 1e-12 level"
$ and [ eq 1e-12 (choose (fromIntegral n) (fromIntegral k)) (fromIntegral $ choose' n k)
| n <- [0..300], k <- [0..n]]
----------------------------------------------------------------
-- Self tests
, testProperty "Self-test: 0 <= range01 <= 1" $ \x -> let f = range01 x in f <= 1 && f >= 0
]
----------------------------------------------------------------
-- QC tests
----------------------------------------------------------------
-- Γ(x+1) = x·Γ(x)
gammaReccurence :: (Double -> Double) -> Double -> Double -> Property
gammaReccurence logG ε x =
(x > 0 && x < 100) ==> (abs (g2 - g1 - log x) < ε)
where
g1 = logG x
g2 = logG (x+1)
-- γ(s,x) is in [0,1] range
incompleteGammaInRange :: Double -> Double -> Property
incompleteGammaInRange (abs -> s) (abs -> x) =
x >= 0 && s > 0 ==> let i = incompleteGamma s x in i >= 0 && i <= 1
-- γ(1,x) = 1 - exp(-x)
-- Since Γ(1) = 1 normalization doesn't make any difference
incompleteGammaAt1Check :: Double -> Property
incompleteGammaAt1Check (abs -> x) =
x > 0 ==> (incompleteGamma 1 x + exp(-x)) ≈ 1
where
(≈) = eq 1e-13
-- invIncompleteGamma is inverse of incompleteGamma
invIGammaIsInverse :: Double -> Double -> Property
invIGammaIsInverse (abs -> a) (range01 -> p) =
a > 0 && p > 0 && p < 1 ==> ( printTestCase ("a = " ++ show a )
$ printTestCase ("p = " ++ show p )
$ printTestCase ("x = " ++ show x )
$ printTestCase ("p' = " ++ show p')
$ printTestCase ("Δp = " ++ show (p - p'))
$ abs (p - p') <= 1e-12
)
where
x = invIncompleteGamma a p
p' = incompleteGamma a x
-- invErfc is inverse of erfc
invErfcIsInverse :: Double -> Property
invErfcIsInverse ((*2) . range01 -> p)
= printTestCase ("p = " ++ show p )
$ printTestCase ("x = " ++ show x )
$ printTestCase ("p' = " ++ show p')
$ abs (p - p') <= 1e-14
where
x = invErfc p
p' = erfc x
-- invErf is inverse of erf
invErfIsInverse :: Double -> Property
invErfIsInverse a
= printTestCase ("p = " ++ show p )
$ printTestCase ("x = " ++ show x )
$ printTestCase ("p' = " ++ show p')
$ abs (p - p') <= 1e-14
where
x = invErf p
p' = erf x
p | a < 0 = - range01 a
| otherwise = range01 a
-- B(s,x) is in [0,1] range
incompleteBetaInRange :: Double -> Double -> Double -> Property
incompleteBetaInRange (abs -> p) (abs -> q) (range01 -> x) =
p > 0 && q > 0 ==> let i = incompleteBeta p q x in i >= 0 && i <= 1
-- invIncompleteBeta is inverse of incompleteBeta
invIBetaIsInverse :: Double -> Double -> Double -> Property
invIBetaIsInverse (abs -> p) (abs -> q) (abs . snd . properFraction -> x) =
p > 0 && q > 0 ==> ( printTestCase ("p = " ++ show p )
$ printTestCase ("q = " ++ show q )
$ printTestCase ("x = " ++ show x )
$ printTestCase ("x' = " ++ show x')
$ printTestCase ("a = " ++ show a)
$ printTestCase ("err = " ++ (show $ abs $ (x - x') / x))
$ abs (x - x') <= 1e-12
)
where
x' = incompleteBeta p q a
a = invIncompleteBeta p q x
-- Table for digamma function:
--
-- Uses equality ψ(n) = H_{n-1} - γ where
-- H_{n} = Σ 1/k, k = [1 .. n] - harmonic number
-- γ = 0.57721566490153286060 - Euler-Mascheroni number
digammaTestIntegers :: Double -> Bool
digammaTestIntegers eps
= all (uncurry $ eq eps) $ take 3000 digammaInt
where
ok approx exact = approx
-- Harmonic numbers starting from 0
harmN = scanl (\a n -> a + 1/n) 0 [1::Rational .. ]
gam = 0.57721566490153286060
-- Digamma values
digammaInt = zipWith (\i h -> (digamma i, realToFrac h - gam)) [1..] harmN
----------------------------------------------------------------
-- Unit tests
----------------------------------------------------------------
-- Lookup table for fact factorial calculation. It has fixed size
-- which is bad but it's OK for this particular case
factorial_table :: V.Vector Integer
factorial_table = V.generate 2000 (\n -> product [1..fromIntegral n])
-- Exact implementation of factorial
factorial' :: Integer -> Integer
factorial' n = factorial_table ! fromIntegral n
-- Exact albeit slow implementation of choose
choose' :: Integer -> Integer -> Integer
choose' n k = factorial' n `div` (factorial' k * factorial' (n-k))
-- Truncate double to [0,1]
range01 :: Double -> Double
range01 = abs . snd . properFraction
|
module _ where
postulate
C : Set → Set
A : Set
i : C A
foo : {X : Set} {{_ : C X}} → X
bar : A
bar = let instance z = i in foo
|
From sflib Require Import sflib.
From Paco Require Import paco.
From PromisingLib Require Import Axioms.
From PromisingLib Require Import Basic.
From PromisingLib Require Import DataStructure.
From PromisingLib Require Import DenseOrder.
From PromisingLib Require Import Loc.
From PromisingLib Require Import Language.
Require Import Event.
Require Import Time.
Require Import View.
Require Import Cell.
Require Import Memory.
Require Import TView.
Require Import Local.
Require Import Thread.
Require Import PromiseConsistent.
Require Import ReorderPromises.
Set Implicit Arguments.
Definition pf_consistent lang (e:Thread.t lang): Prop :=
forall mem1 sc1
(CAP: Memory.cap (Thread.memory e) mem1)
(SC_MAX: Memory.max_concrete_timemap mem1 sc1),
exists e2,
(<<STEPS: rtc (tau (Thread.step true)) (Thread.mk _ (Thread.state e) (Thread.local e) sc1 mem1) e2>>) /\
((<<FAILURE: exists e3, Thread.step true ThreadEvent.failure e2 e3 >>) \/
(<<PROMISES: (Local.promises (Thread.local e2)) = Memory.bot>>)).
Lemma rtc_union_step_nonpf_failure
lang e1 e2 e2'
(STEP: rtc (union (@Thread.step lang false)) e1 e2)
(FAILURE: Thread.step true ThreadEvent.failure e2 e2')
:
exists e1',
Thread.step true ThreadEvent.failure e1 e1'.
Proof.
ginduction STEP; eauto.
i. exploit IHSTEP; eauto. i. des.
exists (Thread.mk _ (Thread.state e1') (Thread.local x) (Thread.sc x) (Thread.memory x)).
inv x0; inv STEP0. inv LOCAL. inv LOCAL0.
inv H. inv USTEP. inv STEP0.
econs 2; eauto. econs; eauto. econs; eauto. econs; eauto.
ss. eapply promise_step_promise_consistent; eauto.
Qed.
Lemma consistent_pf_consistent lang (e:Thread.t lang)
(WF: Local.wf (Thread.local e) (Thread.memory e))
(MEM: Memory.closed (Thread.memory e))
(CONSISTENT: Thread.consistent e)
:
pf_consistent e.
Proof.
ii. exploit CONSISTENT; eauto. i. des.
- inv FAILURE. des.
hexploit tau_steps_pf_tau_steps; eauto; ss.
{ inv FAILURE; inv STEP. inv LOCAL. inv LOCAL0.
hexploit rtc_tau_step_promise_consistent; eauto; ss.
{ eapply Local.cap_wf; eauto. }
{ eapply Memory.max_concrete_timemap_closed; eauto. }
{ eapply Memory.cap_closed; eauto. }
}
{ eapply Local.cap_wf; eauto. }
{ eapply Memory.max_concrete_timemap_closed; eauto. }
{ eapply Memory.cap_closed; eauto. }
i. des.
exploit rtc_union_step_nonpf_failure.
{ eapply rtc_implies; [|eauto]. apply tau_union. }
{ eauto. }
i. des.
esplits; eauto.
- exploit tau_steps_pf_tau_steps; eauto; ss.
{ ii. rewrite PROMISES, Memory.bot_get in *. congr. }
{ eapply Local.cap_wf; eauto. }
{ eapply Memory.max_concrete_timemap_closed; eauto. }
{ eapply Memory.cap_closed; eauto. }
i. des.
exploit rtc_union_step_nonpf_bot; [|eauto|].
{ eapply rtc_implies; [|eauto]. apply tau_union. }
i. subst. esplits; eauto.
Qed.
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.