text
stringlengths 0
3.34M
|
---|
Formal statement is: lemma to_fract_uminus [simp]: "to_fract (-x) = -to_fract x" Informal statement is: The negation of a fraction is the negation of the numerator divided by the denominator. |
Inductive bool : Type :=
| true
| false.
Definition negb (b : bool) : bool :=
match b with
| true => false
| false => true
end.
Definition andb (b_1 : bool) (b_2 : bool) : bool :=
match b_1 with
| true => b_2
| false => false
end.
Definition orb (b_1 : bool) (b_2 : bool) : bool :=
match b_1 with
| true => true
| false => b_2
end.
Compute negb true.
Compute andb true false.
Example test_orb1: orb true false = true.
Proof. simpl. reflexivity. Qed.
Example test_orb2: orb false false = false.
Proof. simpl. reflexivity. Qed.
Example test_orb3: orb false true = true.
Proof. simpl. reflexivity. Qed.
Example test_orb4: orb true true = true.
Proof. simpl. reflexivity. Qed.
(* Notation "! x" := (negb x). *)
Notation "x && y" := (andb x y).
Notation "x || y" := (orb x y).
Compute true && false.
Definition andb3 (b_1 : bool) (b_2 : bool) (b_3 : bool) : bool :=
andb b_1 (andb b_2 b_3).
Example test_andb31: andb3 true true true = true.
Proof. simpl. reflexivity. Qed.
Example test_andb32: andb3 false true true = false.
Proof. simpl. reflexivity. Qed.
Example test_andb33: andb3 true false true = false.
Proof. simpl. reflexivity. Qed.
Example test_andb34: andb3 true true false = false.
Proof. simpl. reflexivity. Qed.
Check andb3.
Inductive rgb : Type :=
| red
| green
| blue.
Inductive color : Type :=
| black
| white
| primary (p : rgb).
Definition monochrome (c : color) : bool :=
match c with
| black => true
| white => true
| primary _ => false
end.
Compute monochrome (primary blue).
Inductive nat : Type :=
| O
| S (n : nat).
Check S.
Inductive bit : Type :=
| B_0
| B_1.
Inductive nybble : Type :=
| bits (b_0 b_1 b_2 b_3 : bit).
Check bits B_0 B_0 B_0 B_0.
Definition all_zero (bits : nybble) : bool :=
match bits with
| bits B_0 B_0 B_0 B_0 => true
| bits _ _ _ _ => false
end.
Compute all_zero (bits B_0 B_0 B_0 B_0).
Compute all_zero (bits B_0 B_0 B_0 B_1).
|
"""
nsolpde_test(n)
Test elliptic pde with nsol. Newton and Shamanskii. Query
convergence history, accuracy, agreement.
"""
function nsolpde_test(n)
h = 1 / (n + 1)
x = collect(h:h:1.0-h)
uexact = solexact(x)
ue = reshape(uexact, (n * n,))
houtn = NsolPDE(n)
histn = houtn.history
npass =
(length(histn) == 7) &&
(sum(houtn.stats.iarm) == 2) &&
(histn[7] / histn[1] < 1.e-13)
houts = NsolPDE(n; sham = Inf, resdec = 0.1)
hists = houts.history
spass =
(length(hists) == 8) &&
(sum(houts.stats.iarm) == 2) &&
(hists[8] / hists[1] < 1.e-7)
errn = norm(houtn.solution - ue, Inf)
errs = norm(houts.solution - ue, Inf)
delsol = norm(houts.solution - houtn.solution, Inf)
accpass = (errn < 1.e-3) && (errs < 1.e-3) && (delsol < 1.e-8)
return npass && accpass
end
|
Require Import
Coq.Program.Program
Coq.Program.Tactics
Coq.Lists.List
Coq.omega.Omega
Hask.Control.Monad.
Require Export
Member
Comp.
Import ListNotations.
Import EqNotations.
Generalizable All Variables.
Inductive Choice (A : Type) : Type :=
| Pick : forall (P : A -> Prop), Choice A.
Arguments Pick {A} P.
(* A Choice "effect" may be refined so long as every value computable from the
new choice was computable from the original choice. *)
Inductive refineChoice {a} : Choice a -> Choice a -> Prop :=
RefineChoice : forall old new, (forall v, new ↝ v -> old ↝ v) ->
refineChoice (Pick new) (Pick old).
Class Computes (s : Type) (eff : Type -> Type) := {
computes : forall a, s -> eff a -> s -> a -> Prop
}.
Arguments computes {s eff _ a} _ _ _ _.
(* Given an interpreter that can run any effect down to its denotation in
Gallina, we can interpret any action. *)
Inductive interpP {effs state a}
(interpE : forall v, effs v -> v -> state -> state -> Prop) :
Freer effs a -> a -> state -> state -> Prop :=
| interpP_Impure :
forall {t} (u : effs t) (r : t) (k : t -> Freer effs a)
val pre mid post,
interpE _ u r pre mid ->
interpP interpE (k r) val mid post ->
interpP interpE (Impure u k) val pre post
| interpP_Pure : forall val pre post,
interpP interpE (Pure val) val pre post.
Require Import
RWS.
(* This theorem present the meaning of state, interpreted as an "effect" on an
input state and resulting in a final value. *)
Theorem meaning_of_State {s v} (f : State s v) (x : v) (start : s) :
interpP
(fun v (st : State s v) (x : v) (pre : s) (post : s) =>
match st in State _ v' return v' = v -> _ with
| Get => fun H => post = pre /\ x = rew H in post
| Put p => fun H => post = p /\ x = rew H in tt
end eq_refl)
(sendF f)
(match f in State _ v' return v' = v -> _ with
| Get => fun H => start
| Put p => fun H => tt
end eq_refl)
start
(match f in State _ v' return v' = v -> _ with
| Get => fun H => start
| Put p => fun H => p
end eq_refl).
Proof.
unfold sendF.
induction f; simpl;
eapply interpP_Impure; eauto;
eapply interpP_Pure.
Qed.
Theorem final {a} {x : Eff [] a} {v state} {pre post : state} :
run x = v ->
interpP (fun _ u _ _ _ => False_rect _ (Union_empty _ u)) x v pre post.
Proof.
simpl; intros; subst.
induction x; simpl.
now apply interpP_Pure.
now inversion f.
Qed.
|
/-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import analysis.asymptotics.asymptotic_equivalent
import analysis.asymptotics.specific_asymptotics
import data.polynomial.erase_lead
/-!
# Limits related to polynomial and rational functions
This file proves basic facts about limits of polynomial and rationals functions.
The main result is `eval_is_equivalent_at_top_eval_lead`, which states that for
any polynomial `P` of degree `n` with leading coefficient `a`, the corresponding
polynomial function is equivalent to `a * x^n` as `x` goes to +∞.
We can then use this result to prove various limits for polynomial and rational
functions, depending on the degrees and leading coefficients of the considered
polynomials.
-/
open filter finset asymptotics
open_locale asymptotics topological_space
namespace polynomial
variables {𝕜 : Type*} [normed_linear_ordered_field 𝕜] (P Q : polynomial 𝕜)
lemma eventually_no_roots (hP : P ≠ 0) : ∀ᶠ x in filter.at_top, ¬ P.is_root x :=
begin
obtain ⟨x₀, hx₀⟩ := polynomial.exists_max_root P hP,
refine filter.eventually_at_top.mpr (⟨x₀ + 1, λ x hx h, _⟩),
exact absurd (hx₀ x h) (not_le.mpr (lt_of_lt_of_le (lt_add_one x₀) hx)),
end
variables [order_topology 𝕜]
lemma is_equivalent_at_top_lead :
(λ x, eval x P) ~[at_top] (λ x, P.leading_coeff * x ^ P.nat_degree) :=
begin
by_cases h : P = 0,
{ simp [h] },
{ conv_lhs
{ funext,
rw [polynomial.eval_eq_finset_sum, sum_range_succ] },
exact is_equivalent.refl.add_is_o (is_o.sum $ λ i hi, is_o.const_mul_left
(is_o.const_mul_right (λ hz, h $ leading_coeff_eq_zero.mp hz) $
is_o_pow_pow_at_top_of_lt (mem_range.mp hi)) _) }
end
lemma tendsto_at_top_of_leading_coeff_nonneg (hdeg : 1 ≤ P.degree) (hnng : 0 ≤ P.leading_coeff) :
tendsto (λ x, eval x P) at_top at_top :=
P.is_equivalent_at_top_lead.symm.tendsto_at_top
(tendsto_const_mul_pow_at_top (le_nat_degree_of_coe_le_degree hdeg)
(lt_of_le_of_ne hnng $ ne.symm $ mt leading_coeff_eq_zero.mp $ ne_zero_of_coe_le_degree hdeg))
lemma tendsto_at_bot_of_leading_coeff_nonpos (hdeg : 1 ≤ P.degree) (hnps : P.leading_coeff ≤ 0) :
tendsto (λ x, eval x P) at_top at_bot :=
P.is_equivalent_at_top_lead.symm.tendsto_at_bot
(tendsto_neg_const_mul_pow_at_top (le_nat_degree_of_coe_le_degree hdeg)
(lt_of_le_of_ne hnps $ mt leading_coeff_eq_zero.mp $ ne_zero_of_coe_le_degree hdeg))
lemma abs_tendsto_at_top (hdeg : 1 ≤ P.degree) :
tendsto (λ x, abs $ eval x P) at_top at_top :=
begin
by_cases hP : 0 ≤ P.leading_coeff,
{ exact tendsto_abs_at_top_at_top.comp (P.tendsto_at_top_of_leading_coeff_nonneg hdeg hP)},
{ push_neg at hP,
exact tendsto_abs_at_bot_at_top.comp (P.tendsto_at_bot_of_leading_coeff_nonpos hdeg hP.le)}
end
lemma is_equivalent_at_top_div :
(λ x, (eval x P)/(eval x Q)) ~[at_top]
λ x, P.leading_coeff/Q.leading_coeff * x^(P.nat_degree - Q.nat_degree : ℤ) :=
begin
by_cases hP : P = 0,
{ simp [hP] },
by_cases hQ : Q = 0,
{ simp [hQ] },
refine (P.is_equivalent_at_top_lead.symm.div
Q.is_equivalent_at_top_lead.symm).symm.trans
(eventually_eq.is_equivalent ((eventually_gt_at_top 0).mono $ λ x hx, _)),
simp [← div_mul_div, hP, hQ, fpow_sub hx.ne.symm]
end
lemma div_tendsto_zero_of_degree_lt (hdeg : P.degree < Q.degree) :
tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 0) :=
begin
by_cases hP : P = 0,
{ simp [hP, tendsto_const_nhds] },
rw ← nat_degree_lt_nat_degree_iff hP at hdeg,
refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,
rw ← mul_zero,
refine (tendsto_fpow_at_top_zero _).const_mul _,
linarith
end
lemma div_tendsto_leading_coeff_div_of_degree_eq (hdeg : P.degree = Q.degree) :
tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 $ P.leading_coeff / Q.leading_coeff) :=
begin
refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,
rw show (P.nat_degree : ℤ) = Q.nat_degree, by simp [hdeg, nat_degree],
simp [tendsto_const_nhds]
end
lemma div_tendsto_at_top_of_degree_gt' (hdeg : Q.degree < P.degree)
(hpos : 0 < P.leading_coeff/Q.leading_coeff) :
tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=
begin
have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hpos, linarith},
rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,
refine (is_equivalent_at_top_div P Q).symm.tendsto_at_top _,
apply tendsto.const_mul_at_top hpos,
apply tendsto_fpow_at_top_at_top,
linarith
end
lemma div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)
(hQ : Q ≠ 0) (hnng : 0 ≤ P.leading_coeff/Q.leading_coeff) :
tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=
have ratio_pos : 0 < P.leading_coeff/Q.leading_coeff,
from lt_of_le_of_ne hnng
(div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)
(λ h, hQ $ leading_coeff_eq_zero.mp h)).symm,
div_tendsto_at_top_of_degree_gt' P Q hdeg ratio_pos
lemma div_tendsto_at_bot_of_degree_gt' (hdeg : Q.degree < P.degree)
(hneg : P.leading_coeff/Q.leading_coeff < 0) :
tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=
begin
have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hneg, linarith},
rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,
refine (is_equivalent_at_top_div P Q).symm.tendsto_at_bot _,
apply tendsto.neg_const_mul_at_top hneg,
apply tendsto_fpow_at_top_at_top,
linarith
end
lemma div_tendsto_at_bot_of_degree_gt (hdeg : Q.degree < P.degree)
(hQ : Q ≠ 0) (hnps : P.leading_coeff/Q.leading_coeff ≤ 0) :
tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=
have ratio_neg : P.leading_coeff/Q.leading_coeff < 0,
from lt_of_le_of_ne hnps
(div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)
(λ h, hQ $ leading_coeff_eq_zero.mp h)),
div_tendsto_at_bot_of_degree_gt' P Q hdeg ratio_neg
lemma eval_div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)
(hQ : Q ≠ 0) :
tendsto (λ x, abs ((eval x P)/(eval x Q))) at_top at_top :=
begin
by_cases h : 0 ≤ P.leading_coeff/Q.leading_coeff,
{ exact tendsto_abs_at_top_at_top.comp (P.div_tendsto_at_top_of_degree_gt Q hdeg hQ h) },
{ push_neg at h,
exact tendsto_abs_at_bot_at_top.comp (P.div_tendsto_at_bot_of_degree_gt Q hdeg hQ h.le) }
end
theorem is_O_of_degree_le (h : P.degree ≤ Q.degree) :
is_O (λ x, eval x P) (λ x, eval x Q) filter.at_top :=
begin
by_cases hp : P = 0,
{ simpa [hp] using is_O_zero (λ x, eval x Q) filter.at_top },
{ have hq : Q ≠ 0 := ne_zero_of_degree_ge_degree h hp,
have hPQ : ∀ᶠ (x : 𝕜) in at_top, eval x Q = 0 → eval x P = 0 :=
filter.mem_sets_of_superset (polynomial.eventually_no_roots Q hq) (λ x h h', absurd h' h),
cases le_iff_lt_or_eq.mp h with h h,
{ exact is_O_of_div_tendsto_nhds hPQ 0 (div_tendsto_zero_of_degree_lt P Q h) },
{ exact is_O_of_div_tendsto_nhds hPQ _ (div_tendsto_leading_coeff_div_of_degree_eq P Q h) } }
end
end polynomial
|
data Nat : Set where
record Ord (A : Set) : Set where
field f : A → A
instance
OrdNat : Ord Nat
OrdNat = record { f = λ x → x }
postulate
T : Nat → Set
R : ∀ {A} {{_ : Ord A}} → A → Set
-- Before solving the type of m, instance search considers it to
-- be a potential candidate for Ord Nat. It then proceeds to check
-- uniqueness by comparing m and OrdNat. The problem was that this
-- left a constraint m == OrdNat that leaked into the state.
foo : Set
foo = ∀ (n : Nat) m → R n → T m
|
module map-Tree where
-- ツリー
data Tree (A B : Set) : Set where
leaf : A → Tree A B
node : Tree A B → B → Tree A B → Tree A B
-- ツリーのmap
map-Tree : ∀ {A B C D : Set} → (A → C) → (B → D) → Tree A B → Tree C D
map-Tree f g (leaf a) = leaf (f a)
map-Tree f g (node treeˡ b treeʳ) = node (map-Tree f g treeˡ) (g b) (map-Tree f g treeʳ)
|
function sphere_cubed_grid_points_display ( ns, xyz, filename )
%*****************************************************************************80
%
%% SPHERE_CUBED_GRID_POINTS_DISPLAY displays the points on a cubed sphere grid.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 09 May 2015
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, integer NS, the number of points.
%
% Output, real XYZ(NS,3), distinct points on the unit sphere
% generated by a cubed sphere grid.
%
figure ( )
clf
hold on
[ x, y, z ] = sphere ( 20 );
c = ones ( size ( z ) );
surf ( x, y, z, c );
plot3 ( xyz(:,1), xyz(:,2), xyz(:,3), 'b.', 'Markersize', 20 );
axis equal
grid on
view ( 3 )
xlabel ( '<--X-->' )
ylabel ( '<--Y-->' )
zlabel ( '<--Z-->' )
title_string = s_escape_tex ( filename )
title ( title_string, 'FontSize', 24 );
hold off
print ( '-dpng', filename );
fprintf ( 1, '\n' );
fprintf ( 1, ' Plot file saved to "%s".\n', filename );
return
end
|
lemmas continuous_on_scaleR [continuous_intros] = bounded_bilinear.continuous_on [OF bounded_bilinear_scaleR] |
lemma content_primitive_part [simp]: fixes p :: "'a :: {normalization_semidom_multiplicative, semiring_gcd} poly" assumes "p \<noteq> 0" shows "content (primitive_part p) = 1" |
%% Copyright (C) 2016 Utkarsh Gautam
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published
%% by the Free Software Foundation; either version 3 of the License,
%% or (at your option) any later version.
%%
%% This software is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty
%% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
%% the GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.
%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym besseljn (@var{alpha}, @var{x})
%% Symbolic Spherical Bessel function of the first kind.
%%
%% Example:
%% @example
%% @group
%% syms n x
%% A = besseljn(n, x)
%% @result{} A = (sym) jn(n, x)
%% diff(A)
%% @result{} ans = (sym)
%%
%% (n + 1)⋅jn(n, x)
%% jn(n - 1, x) - ────────────────
%% x
%% @end group
%% @end example
%%
%% @seealso{@@sym/besselyn, @@sym/besselj}
%% @end defmethod
function Y = besseljn(n, x)
if (nargin ~= 2)
print_usage ();
end
Y = elementwise_op ('jn', sym(n), sym(x));
end
%!test
%! % roundtrip
%! syms x
%! A = double(besseljn(sym(2), sym(9)));
%! q = besseljn(sym(2), x);
%! h = function_handle(q);
%! B = h(9);
%! assert (abs (A - B) <= eps)
%!error jn(sym('x'))
|
import .list
import algebra.geom_sum
import analysis.specific_limits
lemma geom_sum_of_sum_of_range_map {α} [semiring α] (x: α) (n: ℕ):
list.sum (list.map (pow x) (list.range n)) = geom_sum x n :=
begin
induction n with d hd,
{ simp only [list.sum_nil, geom_sum_zero, list.range_zero, list.map] },
{ simp [geom_sum, finset.range, list.range_succ, add_comm, hd] },
end
lemma geom_sum_of_sum_of_map_with_index {α} [semiring α] (x: α) (l: list α):
list.sum (l.map_with_index (λ i a, x ^ i)) = geom_sum x (l.length) :=
by simp [← geom_sum_of_sum_of_range_map x (l.length), list.map_with_index_eq_range_map (λ i a, x ^ i) (λ i, x ^ i)]
lemma real.finite_geom_sum_le_infinite_geom_sum_of_abs_lt_1
{x: ℝ} (n: ℕ) (x_nonneg: 0 ≤ x) (h: abs x < 1):
geom_sum x n ≤ ∑' k: ℕ, x ^ k :=
begin
apply sum_le_tsum,
simp,
intros m hm,
exact pow_nonneg x_nonneg m,
exact summable_geometric_of_abs_lt_1 h,
end
lemma real.finite_geom_sum_le_infinite_geom_sum_of_lt_1
{x: ℝ} (n: ℕ) (x_nonneg: 0 ≤ x) (h: x < 1):
geom_sum x n ≤ ∑' k: ℕ, x ^ k :=
begin
rw ← abs_eq_self.2 x_nonneg at h,
exact real.finite_geom_sum_le_infinite_geom_sum_of_abs_lt_1 n x_nonneg h,
end
-- can be generalized to 'semifield', but we do not have them.
lemma geom_sum_eq_factor_inv_geom_sum
{α} [field α]
{x: α} (n: ℕ) (hx_ne_0: x ≠ 0) (hx_ne_1: x ≠ 1):
geom_sum x (n + 1) = (x ^ n) * geom_sum (x⁻¹) (n + 1) :=
begin
rw [geom_sum_eq hx_ne_1, geom_sum_inv hx_ne_1 hx_ne_0],
rw [← mul_assoc, div_eq_mul_inv],
exact calc (x ^ (n + 1) - 1) * (x - 1)⁻¹ = (x - 1)⁻¹ * (x ^ (n + 1) - 1) : mul_comm _ _
... = (x - 1)⁻¹ * (x ^ n * x - 1) : by rw pow_succ' x n
... = (x - 1)⁻¹ * (x ^ n * x - x ^ (-n: ℤ) * x ^ (n: ℤ)) : by rw [fpow_neg_mul_fpow_self n hx_ne_0]
... = (x - 1)⁻¹ * (x ^ n * x - x ^ n * x ^ (-n: ℤ)) : by norm_cast; ring_nf
... = (x - 1)⁻¹ * x ^ n * (x - x⁻¹ ^ n) : by rw [← mul_sub_left_distrib _ _ _, ← mul_assoc]; simp [inv_fpow]
... = (x - 1)⁻¹ * x ^ n * (x - x⁻¹ ^ n * 1) : by rw mul_one (x⁻¹ ^ n)
... = (x - 1)⁻¹ * x ^ n * (x - x⁻¹ ^ n * (x⁻¹ * x)) : by rw inv_mul_cancel hx_ne_0
... = (x - 1)⁻¹ * x ^ n * (x - x⁻¹ ^ (n + 1) * x) : by rw [← mul_assoc, pow_succ' x⁻¹ n]
... = x ^ n * (x - 1)⁻¹ * (x - x⁻¹ ^ (n + 1) * x) : by ac_refl,
end |
lemma bigE_nonneg_real: assumes "f \<in> Lr F (g)" "eventually (\<lambda>x. f x \<ge> 0) F" obtains c where "c > 0" "eventually (\<lambda>x. R (f x) (c * \<bar>g x\<bar>)) F" |
From Coqprime Require Import PocklingtonRefl.
Local Open Scope positive_scope.
Lemma primo82:
prime 1659108721->
prime 4732254109989697.
Proof.
intro H.
apply (Pocklington_refl
(Ell_certif
4732254109989697
2852287
((1659108721,1)::nil)
0
1238519631397054
3549190582492305
4436488228116381)
((Proof_certif _ H) :: nil)).
native_cast_no_check (refl_equal true).
Time Qed.
|
(** Formal Reasoning About Programs <http://adam.chlipala.net/frap/>
* Chapter 2: Basic Program Syntax
* Author: Adam Chlipala
* License: https://creativecommons.org/licenses/by-nc-nd/4.0/ *)
Require Import Frap.
(* This [Import] command is for including a library of code, theorems, tactics, etc.
* Here we just include the standard library of the book.
* We won't distinguish carefully between built-in Coq features and those provided by that library. *)
(* As a first example, let's look at the syntax of simple arithmetic expressions.
* We use the Coq feature of modules, which let us group related definitions together.
* A key benefit is that names can be reused across modules,
* which is helpful to define several variants of a suite of functionality,
* within a single source file. *)
Module ArithWithConstants.
(* The following definition closely mirrors a standard BNF grammar for expressions.
* It defines abstract syntax trees of arithmetic expressions. *)
Inductive arith : Set :=
| Const (n : nat)
| Plus (e1 e2 : arith)
| Times (e1 e2 : arith).
(* Here are a few examples of specific expressions. *)
Example ex1 := Const 42.
Example ex2 := Plus (Const 1) (Times (Const 2) (Const 3)).
(* How many nodes appear in the tree for an expression?
* Unlike in many programming languages, in Coq,
* recursive functions must be marked as recursive explicitly.
* That marking comes with the [Fixpoint] command, as opposed to [Definition].
* Note also that Coq checks termination of each recursive definition.
* Intuitively, recursive calls must be on subterms of the original argument. *)
Fixpoint size (e : arith) : nat :=
match e with
| Const _ => 1
| Plus e1 e2 => 1 + size e1 + size e2
| Times e1 e2 => 1 + size e1 + size e2
end.
(* Here's how to run a program (evaluate a term) in Coq. *)
Compute size ex1.
Compute size ex2.
(* What's the longest path from the root of a syntax tree to a leaf? *)
Fixpoint depth (e : arith) : nat :=
match e with
| Const _ => 1
| Plus e1 e2 => 1 + max (depth e1) (depth e2)
| Times e1 e2 => 1 + max (depth e1) (depth e2)
end.
Compute depth ex1.
Compute depth ex2.
(* Our first proof!
* Size is an upper bound on depth. *)
Theorem depth_le_size : forall e, depth e <= size e.
Proof.
(* Within a proof, we apply commands called *tactics*.
* Here's our first one.
* Throughout the book's Coq code, we give a brief note documenting each tactic,
* after its first use.
* Keep in mind that the best way to understand what's going on
* is to run the proof script for yourself, inspecting intermediate states! *)
induct e.
(* [induct x]: where [x] is a variable in the theorem statement,
* structure the proof by induction on the structure of [x].
* You will get one generated subgoal per constructor in the
* inductive definition of [x]. (Indeed, it is required that
* [x]'s type was introduced with [Inductive].) *)
simplify.
(* [simplify]: simplify throughout the goal, applying the definitions of
* recursive functions directly. That is, when a subterm
* matches one of the [match] cases in a defining [Fixpoint],
* replace with the body of that case, then repeat. *)
linear_arithmetic.
(* [linear_arithmetic]: a complete decision procedure for linear arithmetic.
* Relevant formulas are essentially those built up from
* variables and constant natural numbers and integers
* using only addition, with equality and inequality
* comparisons on top. (Multiplication by constants
* is supported, as a shorthand for repeated addition.) *)
simplify.
linear_arithmetic.
simplify.
linear_arithmetic.
Qed.
Theorem depth_le_size_snazzy : forall e, depth e <= size e.
Proof.
induct e; simplify; linear_arithmetic.
(* Oo, look at that! Chaining tactics with semicolon, as in [t1; t2],
* asks to run [t1] on the goal, then run [t2] on *every*
* generated subgoal. This is an essential ingredient for automation. *)
Qed.
(* A silly recursive function: swap the operand orders of all binary operators. *)
Fixpoint commuter (e : arith) : arith :=
match e with
| Const _ => e
| Plus e1 e2 => Plus (commuter e2) (commuter e1)
| Times e1 e2 => Times (commuter e2) (commuter e1)
end.
Compute commuter ex1.
Compute commuter ex2.
(* [commuter] has all the appropriate interactions with other functions (and itself). *)
Theorem size_commuter : forall e, size (commuter e) = size e.
Proof.
induct e; simplify; linear_arithmetic.
Qed.
Theorem depth_commuter : forall e, depth (commuter e) = depth e.
Proof.
induct e; simplify; linear_arithmetic.
Qed.
Theorem commuter_inverse : forall e, commuter (commuter e) = e.
Proof.
induct e; simplify; equality.
(* [equality]: a complete decision procedure for the theory of equality
* and uninterpreted functions. That is, the goal must follow
* from only reflexivity, symmetry, transitivity, and congruence
* of equality, including that functions really do behave as functions. *)
Qed.
End ArithWithConstants.
(* Let's shake things up a bit by adding variables to expressions.
* Note that all of the automated proof scripts from before will keep working
* with no changes! That sort of "free" proof evolution is invaluable for
* theorems about real-world compilers, say. *)
Module ArithWithVariables.
Inductive arith : Set :=
| Const (n : nat)
| Var (x : var) (* <-- this is the new constructor! *)
| Plus (e1 e2 : arith)
| Times (e1 e2 : arith).
Example ex1 := Const 42.
Example ex2 := Plus (Const 1) (Times (Var "x") (Const 3)).
Fixpoint size (e : arith) : nat :=
match e with
| Const _ => 1
| Var _ => 1
| Plus e1 e2 => 1 + size e1 + size e2
| Times e1 e2 => 1 + size e1 + size e2
end.
Compute size ex1.
Compute size ex2.
Fixpoint depth (e : arith) : nat :=
match e with
| Const _ => 1
| Var _ => 1
| Plus e1 e2 => 1 + max (depth e1) (depth e2)
| Times e1 e2 => 1 + max (depth e1) (depth e2)
end.
Compute depth ex1.
Compute depth ex2.
Theorem depth_le_size : forall e, depth e <= size e.
Proof.
induct e; simplify; linear_arithmetic.
Qed.
Fixpoint commuter (e : arith) : arith :=
match e with
| Const _ => e
| Var _ => e
| Plus e1 e2 => Plus (commuter e2) (commuter e1)
| Times e1 e2 => Times (commuter e2) (commuter e1)
end.
Compute commuter ex1.
Compute commuter ex2.
Theorem size_commuter : forall e, size (commuter e) = size e.
Proof.
induct e; simplify; linear_arithmetic.
Qed.
Theorem depth_commuter : forall e, depth (commuter e) = depth e.
Proof.
induct e; simplify; linear_arithmetic.
Qed.
Theorem commuter_inverse : forall e, commuter (commuter e) = e.
Proof.
induct e; simplify; equality.
Qed.
(* Now that we have variables, we can consider new operations,
* like substituting an expression for a variable.
* We use an infix operator [==v] for equality tests on strings.
* It has a somewhat funny and very expressive type,
* whose details we will try to gloss over.
* (We later return to them in SubsetTypes.v.) *)
Fixpoint substitute (inThis : arith) (replaceThis : var) (withThis : arith) : arith :=
match inThis with
| Const _ => inThis
| Var x => if x ==v replaceThis then withThis else inThis
| Plus e1 e2 => Plus (substitute e1 replaceThis withThis) (substitute e2 replaceThis withThis)
| Times e1 e2 => Times (substitute e1 replaceThis withThis) (substitute e2 replaceThis withThis)
end.
(* An intuitive property about how much [substitute] might increase depth. *)
Theorem substitute_depth : forall replaceThis withThis inThis,
depth (substitute inThis replaceThis withThis) <= depth inThis + depth withThis.
Proof.
induct inThis.
simplify.
linear_arithmetic.
simplify.
cases (x ==v replaceThis).
(* [cases e]: break the proof into one case for each constructor that might have
* been used to build the value of expression [e]. In the special case where
* [e] essentially has a Boolean type, we consider whether [e] is true or false. *)
linear_arithmetic.
simplify.
linear_arithmetic.
simplify.
linear_arithmetic.
simplify.
linear_arithmetic.
Qed.
(* Let's get fancier about automation, using [match goal] to pattern-match the goal
* and decide what to do next!
* The [|-] syntax separates hypotheses and conclusion in a goal.
* The [context] syntax is for matching against *any subterm* of a term.
* The construct [try] is also useful, for attempting a tactic and rolling back
* the effect if any error is encountered. *)
Theorem substitute_depth_snazzy : forall replaceThis withThis inThis,
depth (substitute inThis replaceThis withThis) <= depth inThis + depth withThis.
Proof.
induct inThis; simplify;
try match goal with
| [ |- context[if ?a ==v ?b then _ else _] ] => cases (a ==v b); simplify
end; linear_arithmetic.
Qed.
(* A silly self-substitution has no effect. *)
Theorem substitute_self : forall replaceThis inThis,
substitute inThis replaceThis (Var replaceThis) = inThis.
Proof.
induct inThis; simplify;
try match goal with
| [ |- context[if ?a ==v ?b then _ else _] ] => cases (a ==v b); simplify
end; equality.
Qed.
(* We can do substitution and commuting in either order. *)
Theorem substitute_commuter : forall replaceThis withThis inThis,
commuter (substitute inThis replaceThis withThis)
= substitute (commuter inThis) replaceThis (commuter withThis).
Proof.
induct inThis; simplify;
try match goal with
| [ |- context[if ?a ==v ?b then _ else _] ] => cases (a ==v b); simplify
end; equality.
Qed.
(* *Constant folding* is one of the classic compiler optimizations.
* We repeatedly find opportunities to replace fancier expressions
* with known constant values. *)
Fixpoint constantFold (e : arith) : arith :=
match e with
| Const _ => e
| Var _ => e
| Plus e1 e2 =>
let e1' := constantFold e1 in
let e2' := constantFold e2 in
match e1', e2' with
| Const n1, Const n2 => Const (n1 + n2)
| Const 0, _ => e2'
| _, Const 0 => e1'
| _, _ => Plus e1' e2'
end
| Times e1 e2 =>
let e1' := constantFold e1 in
let e2' := constantFold e2 in
match e1', e2' with
| Const n1, Const n2 => Const (n1 * n2)
| Const 1, _ => e2'
| _, Const 1 => e1'
| Const 0, _ => Const 0
| _, Const 0 => Const 0
| _, _ => Times e1' e2'
end
end.
(* This is supposed to be an *optimization*, so it had better not *increase*
* the size of an expression!
* There are enough cases to consider here that we skip straight to
* the automation.
* A new scripting construct is [match] patterns with dummy bodies.
* Such a pattern matches *any* [match] in a goal, over any type! *)
Theorem size_constantFold : forall e, size (constantFold e) <= size e.
Proof.
induct e; simplify;
repeat match goal with
| [ |- context[match ?E with _ => _ end] ] => cases E; simplify
end; linear_arithmetic.
Qed.
(* Business as usual, with another commuting law *)
Theorem commuter_constantFold : forall e, commuter (constantFold e) = constantFold (commuter e).
Proof.
induct e; simplify;
repeat match goal with
| [ |- context[match ?E with _ => _ end] ] => cases E; simplify
| [ H : ?f _ = ?f _ |- _ ] => invert H
| [ |- ?f _ = ?f _ ] => f_equal
end; equality || linear_arithmetic || ring.
(* [f_equal]: when the goal is an equality between two applications of
* the same function, switch to proving that the function arguments are
* pairwise equal.
* [invert H]: replace hypothesis [H] with other facts that can be deduced
* from the structure of [H]'s statement. This is admittedly a fuzzy
* description for now; we'll learn much more about the logic shortly!
* Here, what matters is that, when the hypothesis is an equality between
* two applications of a constructor of an inductive type, we learn that
* the arguments to the constructor must be pairwise equal.
* [ring]: prove goals that are equalities over some registered ring or
* semiring, in the sense of algebra, where the goal follows solely from
* the axioms of that algebraic structure. *)
Qed.
(* To define a further transformation, we first write a roundabout way of
* testing whether an expression is a constant.
* This detour happens to be useful to avoid overhead in concert with
* pattern matching, since Coq internally elaborates wildcard [_] patterns
* into separate cases for all constructors not considered beforehand.
* That expansion can create serious code blow-ups, leading to serious
* proof blow-ups! *)
Definition isConst (e : arith) : option nat :=
match e with
| Const n => Some n
| _ => None
end.
(* Our next target is a function that finds multiplications by constants
* and pushes the multiplications to the leaves of syntax trees,
* ideally finding constants, which can be replaced by larger constants,
* not affecting the meanings of expressions.
* This helper function takes a coefficient [multiplyBy] that should be
* applied to an expression. *)
Fixpoint pushMultiplicationInside' (multiplyBy : nat) (e : arith) : arith :=
match e with
| Const n => Const (multiplyBy * n)
| Var _ => Times (Const multiplyBy) e
| Plus e1 e2 => Plus (pushMultiplicationInside' multiplyBy e1)
(pushMultiplicationInside' multiplyBy e2)
| Times e1 e2 =>
match isConst e1 with
| Some k => pushMultiplicationInside' (k * multiplyBy) e2
| None => Times (pushMultiplicationInside' multiplyBy e1) e2
end
end.
(* The overall transformation just fixes the initial coefficient as [1]. *)
Definition pushMultiplicationInside (e : arith) : arith :=
pushMultiplicationInside' 1 e.
(* Let's prove this boring arithmetic property, so that we may use it below. *)
Lemma n_times_0 : forall n, n * 0 = 0.
Proof.
linear_arithmetic.
Qed.
(* A fun fact about pushing multiplication inside:
* the coefficient has no effect on depth!
* Let's start by showing any coefficient is equivalent to coefficient 0. *)
Lemma depth_pushMultiplicationInside'_irrelevance0 : forall e multiplyBy,
depth (pushMultiplicationInside' multiplyBy e)
= depth (pushMultiplicationInside' 0 e).
Proof.
induct e; simplify.
linear_arithmetic.
linear_arithmetic.
rewrite IHe1.
(* [rewrite H]: where [H] is a hypothesis or previously proved theorem,
* establishing [forall x1 .. xN, e1 = e2], find a subterm of the goal
* that equals [e1], given the right choices of [xi] values, and replace
* that subterm with [e2]. *)
rewrite IHe2.
linear_arithmetic.
cases (isConst e1); simplify.
rewrite IHe2.
rewrite n_times_0.
linear_arithmetic.
rewrite IHe1.
linear_arithmetic.
Qed.
(* It can be remarkably hard to get Coq's automation to be dumb enough to
* help us demonstrate all of the primitive tactics. ;-)
* In particular, we can redo the proof in an automated way, without the
* explicit rewrites. *)
Lemma depth_pushMultiplicationInside'_irrelevance0_snazzy : forall e multiplyBy,
depth (pushMultiplicationInside' multiplyBy e)
= depth (pushMultiplicationInside' 0 e).
Proof.
induct e; simplify;
try match goal with
| [ |- context[match ?E with _ => _ end] ] => cases E; simplify
end; equality.
Qed.
(* Now the general corollary about irrelevance of coefficients for depth. *)
Lemma depth_pushMultiplicationInside'_irrelevance : forall e multiplyBy1 multiplyBy2,
depth (pushMultiplicationInside' multiplyBy1 e)
= depth (pushMultiplicationInside' multiplyBy2 e).
Proof.
simplify.
transitivity (depth (pushMultiplicationInside' 0 e)).
(* [transitivity X]: when proving [Y = Z], switch to proving [Y = X]
* and [X = Z]. *)
apply depth_pushMultiplicationInside'_irrelevance0.
(* [apply H]: for [H] a hypothesis or previously proved theorem,
* establishing some fact that matches the structure of the current
* conclusion, switch to proving [H]'s own hypotheses.
* This is *backwards reasoning* via a known fact. *)
symmetry.
(* [symmetry]: when proving [X = Y], switch to proving [Y = X]. *)
apply depth_pushMultiplicationInside'_irrelevance0.
Qed.
(* Let's prove that pushing-inside has only a small effect on depth,
* considering for now only coefficient 0. *)
Lemma depth_pushMultiplicationInside' : forall e,
depth (pushMultiplicationInside' 0 e) <= S (depth e).
Proof.
induct e; simplify.
linear_arithmetic.
linear_arithmetic.
linear_arithmetic.
cases (isConst e1); simplify.
rewrite n_times_0.
linear_arithmetic.
linear_arithmetic.
Qed.
Local Hint Rewrite n_times_0.
(* Registering rewrite hints will get [simplify] to apply them for us
* automatically! *)
Lemma depth_pushMultiplicationInside'_snazzy : forall e,
depth (pushMultiplicationInside' 0 e) <= S (depth e).
Proof.
induct e; simplify;
try match goal with
| [ |- context[match ?E with _ => _ end] ] => cases E; simplify
end; linear_arithmetic.
Qed.
Theorem depth_pushMultiplicationInside : forall e,
depth (pushMultiplicationInside e) <= S (depth e).
Proof.
simplify.
unfold pushMultiplicationInside.
(* [unfold X]: replace [X] by its definition. *)
rewrite depth_pushMultiplicationInside'_irrelevance0.
apply depth_pushMultiplicationInside'.
Qed.
End ArithWithVariables.
|
module Issue453 where
postulate
A : Set
fails : {x : _} → A
|
/**
*
* @generated d Tue Jan 7 11:45:26 2014
*
**/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cblas.h>
#include <lapacke.h>
#include <plasma.h>
#include <core_blas.h>
#include "auxiliary.h"
/*-------------------------------------------------------------------
* Check the orthogonality of Q
*/
int d_check_orthogonality(int M, int N, int LDQ, double *Q)
{
double alpha, beta;
double normQ;
int info_ortho;
int i;
int minMN = min(M, N);
double eps;
double *work = (double *)malloc(minMN*sizeof(double));
eps = LAPACKE_dlamch_work('e');
alpha = 1.0;
beta = -1.0;
/* Build the idendity matrix USE DLASET?*/
double *Id = (double *) malloc(minMN*minMN*sizeof(double));
memset((void*)Id, 0, minMN*minMN*sizeof(double));
for (i = 0; i < minMN; i++)
Id[i*minMN+i] = (double)1.0;
/* Perform Id - Q'Q */
if (M >= N)
cblas_dsyrk(CblasColMajor, CblasUpper, CblasTrans, N, M, alpha, Q, LDQ, beta, Id, N);
else
cblas_dsyrk(CblasColMajor, CblasUpper, CblasNoTrans, M, N, alpha, Q, LDQ, beta, Id, M);
normQ = LAPACKE_dlansy_work(LAPACK_COL_MAJOR, 'i', 'u', minMN, Id, minMN, work);
printf("============\n");
printf("Checking the orthogonality of Q \n");
printf("||Id-Q'*Q||_oo / (N*eps) = %e \n",normQ/(minMN*eps));
if ( isnan(normQ / (minMN * eps)) || (normQ / (minMN * eps) > 10.0) ) {
printf("-- Orthogonality is suspicious ! \n");
info_ortho=1;
}
else {
printf("-- Orthogonality is CORRECT ! \n");
info_ortho=0;
}
free(work); free(Id);
return info_ortho;
}
/*------------------------------------------------------------
* Check the factorization QR
*/
int d_check_QRfactorization(int M, int N, double *A1, double *A2, int LDA, double *Q)
{
double Anorm, Rnorm;
double alpha, beta;
int info_factorization;
int i,j;
double eps;
eps = LAPACKE_dlamch_work('e');
double *Ql = (double *)malloc(M*N*sizeof(double));
double *Residual = (double *)malloc(M*N*sizeof(double));
double *work = (double *)malloc(max(M,N)*sizeof(double));
alpha=1.0;
beta=0.0;
if (M >= N) {
/* Extract the R */
double *R = (double *)malloc(N*N*sizeof(double));
memset((void*)R, 0, N*N*sizeof(double));
LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,'u', M, N, A2, LDA, R, N);
/* Perform Ql=Q*R */
memset((void*)Ql, 0, M*N*sizeof(double));
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, N, (alpha), Q, LDA, R, N, (beta), Ql, M);
free(R);
}
else {
/* Extract the L */
double *L = (double *)malloc(M*M*sizeof(double));
memset((void*)L, 0, M*M*sizeof(double));
LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,'l', M, N, A2, LDA, L, M);
/* Perform Ql=LQ */
memset((void*)Ql, 0, M*N*sizeof(double));
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, M, (alpha), L, M, Q, LDA, (beta), Ql, M);
free(L);
}
/* Compute the Residual */
for (i = 0; i < M; i++)
for (j = 0 ; j < N; j++)
Residual[j*M+i] = A1[j*LDA+i]-Ql[j*M+i];
Rnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, N, Residual, M, work);
Anorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, N, A2, LDA, work);
if (M >= N) {
printf("============\n");
printf("Checking the QR Factorization \n");
printf("-- ||A-QR||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps));
}
else {
printf("============\n");
printf("Checking the LQ Factorization \n");
printf("-- ||A-LQ||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps));
}
if (isnan(Rnorm / (Anorm * N *eps)) || (Rnorm / (Anorm * N * eps) > 10.0) ) {
printf("-- Factorization is suspicious ! \n");
info_factorization = 1;
}
else {
printf("-- Factorization is CORRECT ! \n");
info_factorization = 0;
}
free(work); free(Ql); free(Residual);
return info_factorization;
}
/*------------------------------------------------------------------------
* Check the factorization of the matrix A2
*/
int d_check_LLTfactorization(int N, double *A1, double *A2, int LDA, int uplo)
{
double Anorm, Rnorm;
double alpha;
int info_factorization;
int i,j;
double eps;
eps = LAPACKE_dlamch_work('e');
double *Residual = (double *)malloc(N*N*sizeof(double));
double *L1 = (double *)malloc(N*N*sizeof(double));
double *L2 = (double *)malloc(N*N*sizeof(double));
double *work = (double *)malloc(N*sizeof(double));
memset((void*)L1, 0, N*N*sizeof(double));
memset((void*)L2, 0, N*N*sizeof(double));
alpha= 1.0;
LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,' ', N, N, A1, LDA, Residual, N);
/* Dealing with L'L or U'U */
if (uplo == PlasmaUpper){
LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,'u', N, N, A2, LDA, L1, N);
LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,'u', N, N, A2, LDA, L2, N);
cblas_dtrmm(CblasColMajor, CblasLeft, CblasUpper, CblasTrans, CblasNonUnit, N, N, (alpha), L1, N, L2, N);
}
else{
LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,'l', N, N, A2, LDA, L1, N);
LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,'l', N, N, A2, LDA, L2, N);
cblas_dtrmm(CblasColMajor, CblasRight, CblasLower, CblasTrans, CblasNonUnit, N, N, (alpha), L1, N, L2, N);
}
/* Compute the Residual || A -L'L|| */
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
Residual[j*N+i] = L2[j*N+i] - Residual[j*N+i];
Rnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', N, N, Residual, N, work);
Anorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', N, N, A1, LDA, work);
printf("============\n");
printf("Checking the Cholesky Factorization \n");
printf("-- ||L'L-A||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps));
if ( isnan(Rnorm/(Anorm*N*eps)) || (Rnorm/(Anorm*N*eps) > 10.0) ){
printf("-- Factorization is suspicious ! \n");
info_factorization = 1;
}
else{
printf("-- Factorization is CORRECT ! \n");
info_factorization = 0;
}
free(Residual); free(L1); free(L2); free(work);
return info_factorization;
}
/*--------------------------------------------------------------
* Check the gemm
*/
double d_check_gemm(PLASMA_enum transA, PLASMA_enum transB, int M, int N, int K,
double alpha, double *A, int LDA,
double *B, int LDB,
double beta, double *Cplasma,
double *Cref, int LDC,
double *Cinitnorm, double *Cplasmanorm, double *Clapacknorm )
{
double beta_const = -1.0;
double Rnorm;
double *work = (double *)malloc(max(K,max(M, N))* sizeof(double));
*Cinitnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work);
*Cplasmanorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, N, Cplasma, LDC, work);
cblas_dgemm(CblasColMajor, (CBLAS_TRANSPOSE)transA, (CBLAS_TRANSPOSE)transB, M, N, K,
(alpha), A, LDA, B, LDB, (beta), Cref, LDC);
*Clapacknorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work);
cblas_daxpy(LDC * N, (beta_const), Cplasma, 1, Cref, 1);
Rnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work);
free(work);
return Rnorm;
}
/*--------------------------------------------------------------
* Check the trsm
*/
double d_check_trsm(PLASMA_enum side, PLASMA_enum uplo, PLASMA_enum trans, PLASMA_enum diag,
int M, int NRHS, double alpha,
double *A, int LDA,
double *Bplasma, double *Bref, int LDB,
double *Binitnorm, double *Bplasmanorm, double *Blapacknorm )
{
double beta_const = -1.0;
double Rnorm;
double *work = (double *)malloc(max(M, NRHS)* sizeof(double));
/*double eps = LAPACKE_dlamch_work('e');*/
*Binitnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, NRHS, Bref, LDB, work);
*Bplasmanorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bplasma, LDB, work);
cblas_dtrsm(CblasColMajor, (CBLAS_SIDE)side, (CBLAS_UPLO)uplo,
(CBLAS_TRANSPOSE)trans, (CBLAS_DIAG)diag, M, NRHS,
(alpha), A, LDA, Bref, LDB);
*Blapacknorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bref, LDB, work);
cblas_daxpy(LDB * NRHS, (beta_const), Bplasma, 1, Bref, 1);
Rnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bref, LDB, work);
Rnorm = Rnorm / *Blapacknorm;
/* max(M,NRHS) * eps);*/
free(work);
return Rnorm;
}
/*--------------------------------------------------------------
* Check the solution
*/
double d_check_solution(int M, int N, int NRHS, double *A, int LDA,
double *B, double *X, int LDB,
double *anorm, double *bnorm, double *xnorm )
{
/* int info_solution; */
double Rnorm = -1.00;
double zone = 1.0;
double mzone = -1.0;
double *work = (double *)malloc(max(M, N)* sizeof(double));
*anorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, N, A, LDA, work);
*xnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', M, NRHS, X, LDB, work);
*bnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', N, NRHS, B, LDB, work);
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, NRHS, N, (zone), A, LDA, X, LDB, (mzone), B, LDB);
Rnorm = LAPACKE_dlange_work(LAPACK_COL_MAJOR, 'i', N, NRHS, B, LDB, work);
free(work);
return Rnorm;
}
|
Formal statement is: lemma (in algebra) sets_Collect_finite_All: assumes "\<And>i. i \<in> S \<Longrightarrow> {x\<in>\<Omega>. P i x} \<in> M" "finite S" shows "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} \<in> M" Informal statement is: If $S$ is a finite set and for each $i \in S$, the set $\{x \in \Omega \mid P_i(x)\}$ is in $M$, then the set $\{x \in \Omega \mid \forall i \in S, P_i(x)\}$ is in $M$. |
# Returns a partitioning of `range` into sub-ranges of length `partition_size`.
# If `range` is not divisible by `partition_size`, the last sub-range will be
# of length `range` mod `partition_size`.
function partition_range(range::UnitRange, partition_size::Int)
n_partitions = ceil(Int, last(range) / partition_size)
partitions = Vector{UnitRange{Int}}(undef, n_partitions)
for p in 1:n_partitions
l::Int = first(range) + (p-1) * partition_size
r::Int = min(l - 1 + partition_size, last(range))
partitions[p] = l:r
end
return partitions
end
function calculate_sample_weights(targets::T) where {T <: AbstractVector}
t = targets
N = length(t)
ψ₀ = sum(t .!= 1) / N
ψ₁ = sum(t .== 1) / N
ψ = [q == 1 ? ψ₁ : ψ₀ for q in t]
end
function gaussian_projection_matrix(::Type{T},
n_neurons::Int,
n_features::Int) where {T <: Number}
randn(T, n_neurons, n_features) ./ sqrt(n_features)
end
function project(samples::T₁,
weights::T₂,
activation_functions::Vector{T₃}) where {T₁ <: AbstractMatrix,
T₂ <: AbstractMatrix,
T₃ <: ActivationFunction}
X = samples
W = weights
fs = activation_functions
L = length(fs)
H = W * X
for l in 1:L
H[l,:] .= fs[l].(H[l,:])
end
H
end
|
import tactic
import tactic.induction
import .defs .lemmas
noncomputable theory
open_locale classical
theorem A_hws_iff_pw_ge_2 {pw : ℕ} :
A_hws pw ↔ 2 ≤ pw :=
begin
cases pw, simp [A_pw_0_not_hws],
cases pw, simp [A_pw_1_not_hws], simp [nat.succ_le_succ],
refine A_pw_ge_hws _ A_pw_2_hws, simp [nat.succ_le_succ],
end
theorem exi_pw_A_hws : ∃ (pw : ℕ), A_hws pw :=
⟨2, A_pw_2_hws⟩ |
/-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import algebra.big_operators.order
import algebra.big_operators.ring
import data.rat.cast
/-!
# The Oxford Invariants Puzzle Challenges - Summer 2021, Week 3, Problem 1
## Original statement
Let `n ≥ 3`, `a₁, ..., aₙ` be strictly positive integers such that `aᵢ ∣ aᵢ₋₁ + aᵢ₊₁` for
`i = 2, ..., n - 1`. Show that $\sum_{i=1}^{n-1}\dfrac{a_0a_n}{a_ia_{i+1}} ∈ \mathbb N$.
## Comments
Mathlib is based on type theory, so saying that a rational is a natural doesn't make sense. Instead,
we ask that there exists `b : ℕ` whose cast to `α` is the sum we want.
In mathlib, `ℕ` starts at `0`. To make the indexing cleaner, we use `a₀, ..., aₙ₋₁` instead of
`a₁, ..., aₙ`. Similarly, it's nicer to not use substraction of naturals, so we replace
`aᵢ ∣ aᵢ₋₁ + aᵢ₊₁` by `aᵢ₊₁ ∣ aᵢ + aᵢ₊₂`.
We don't actually have to work in `ℚ` or `ℝ`. We can be even more general by stating the result for
any linearly ordered field.
Instead of having `n` naturals, we use a function `a : ℕ → ℕ`.
In the proof itself, we replace `n : ℕ, 1 ≤ n` by `n + 1`.
The statement is actually true for `n = 0, 1` (`n = 1, 2` before the reindexing) as the sum is
simply `0` and `1` respectively. So the version we prove is slightly more general.
Overall, the indexing is a bit of a mess to understand. But, trust Lean, it works.
## Formalised statement
Let `n : ℕ`, `a : ℕ → ℕ`, `∀ i ≤ n, 0 < a i`, `∀ i, i + 2 ≤ n → aᵢ₊₁ ∣ aᵢ + aᵢ₊₂` (read `→` as
"implies"). Then there exists `b : ℕ` such that `b` as an element of any linearly ordered field
equals $\sum_{i=0}^{n-1} (a_0 a_n) / (a_i a_{i+1})$.
## Proof outline
The case `n = 0` is trivial.
For `n + 1`, we prove the result by induction but by adding `aₙ₊₁ ∣ aₙ * b - a₀` to the induction
hypothesis, where `b` is the previous sum, $\sum_{i=0}^{n-1} (a_0 a_n) / (a_i a_{i+1})$, as a
natural.
* Base case:
* $\sum_{i=0}^0 (a_0 a_{0+1}) / (a_0 a_{0+1})$ is a natural:
$\sum_{i=0}^0 (a_0 a_{0+1}) / (a_0 a_{0+1}) = (a_0 a_1) / (a_0 a_1) = 1$.
* Divisibility condition:
`a₀ * 1 - a₀ = 0` is clearly divisible by `a₁`.
* Induction step:
* $\sum_{i=0}^n (a_0 a_{n+1}) / (a_i a_{i+1})$ is a natural:
$$\sum_{i=0}^{n+1} (a_0 a_{n+2}) / (a_i a_{i+1})
= \sum_{i=0}^n\ (a_0 a_{n+2}) / (a_i a_{i+1}) + (a_0 a_{n+2}) / (a_{n+1} a_{n+2})
= a_{n+2} / a_{n+1} × \sum_{i=0}^n (a_0 a_{n+1}) / (a_i a_{i+1}) + a_0 / a_{n+1}
= a_{n+2} / a_{n+1} × b + a_0 / a_{n+1}
= (a_n + a_{n+2}) / a_{n+1} × b - (a_n b - a_0)(a_{n+1})$$
which is a natural because `(aₙ + aₙ₊₂)/aₙ₊₁`, `b` and `(aₙ * b - a₀)/aₙ₊₁` are (plus an
annoying inequality, or the fact that the original sum is positive because its terms are).
* Divisibility condition:
`aₙ₊₁ * ((aₙ + aₙ₊₂)/aₙ₊₁ * b - (aₙ * b - a₀)/aₙ₊₁) - a₀ = aₙ₊₁aₙ₊₂b` is divisible by `aₙ₊₂`.
-/
open_locale big_operators
variables {α : Type*} [linear_ordered_field α]
theorem week3_p1 (n : ℕ) (a : ℕ → ℕ) (a_pos : ∀ i ≤ n, 0 < a i)
(ha : ∀ i, i + 2 ≤ n → a (i + 1) ∣ a i + a (i + 2)) :
∃ b : ℕ, (b : α) = ∑ i in finset.range n, (a 0 * a n)/(a i * a (i + 1)) :=
begin
-- Treat separately `n = 0` and `n ≥ 1`
cases n,
/- Case `n = 0`
The sum is trivially equal to `0` -/
{ exact ⟨0, by rw [nat.cast_zero, finset.sum_range_zero]⟩ }, -- `⟨Claim it, Prove it⟩`
/- Case `n ≥ 1`. We replace `n` by `n + 1` everywhere to make this inequality explicit
Set up the stronger induction hypothesis -/
suffices h : ∃ b : ℕ, (b : α) = ∑ i in finset.range (n + 1), (a 0 * a (n + 1))/(a i * a (i + 1))
∧ a (n + 1) ∣ a n * b - a 0,
{ obtain ⟨b, hb, -⟩ := h,
exact ⟨b, hb⟩ },
simp_rw ←@nat.cast_pos α at a_pos,
/- Declare the induction
`ih` will be the induction hypothesis -/
induction n with n ih,
/- Base case
Claim that the sum equals `1`-/
{ refine ⟨1, _, _⟩,
-- Check that this indeed equals the sum
{ rw [nat.cast_one, finset.sum_range_one, div_self],
exact (mul_pos (a_pos 0 (nat.zero_le _)) (a_pos 1 (nat.zero_lt_succ _))).ne' },
-- Check the divisibility condition
{ rw [mul_one, tsub_self],
exact dvd_zero _ } },
/- Induction step
`b` is the value of the previous sum as a natural, `hb` is the proof that it is indeed the value,
and `han` is the divisibility condition -/
obtain ⟨b, hb, han⟩ := ih (λ i hi, ha i $ nat.le_succ_of_le hi)
(λ i hi, a_pos i $ nat.le_succ_of_le hi),
specialize ha n le_rfl,
have ha₀ : a 0 ≤ a n * b, -- Needing this is an artifact of `ℕ`-substraction.
{ rw [←@nat.cast_le α, nat.cast_mul, hb, ←div_le_iff' (a_pos _ $ n.le_succ.trans $ nat.le_succ _),
←mul_div_mul_right _ _ (a_pos _ $ nat.le_succ _).ne'],
suffices h : ∀ i, i ∈ finset.range (n + 1) → 0 ≤ (a 0 : α) * a (n + 1) / (a i * a (i + 1)),
{ exact finset.single_le_sum h (finset.self_mem_range_succ n) },
refine (λ i _, div_nonneg _ _); refine mul_nonneg _ _; exact nat.cast_nonneg _ },
-- Claim that the sum equals `(aₙ + aₙ₊₂)/aₙ₊₁ * b - (aₙ * b - a₀)/aₙ₊₁`
refine ⟨(a n + a (n + 2))/ a (n + 1) * b - (a n * b - a 0) / a (n + 1), _, _⟩,
-- Check that this indeed equals the sum
{ calc
(((a n + a (n + 2)) / a (n + 1) * b - (a n * b - a 0) / a (n + 1) : ℕ) : α)
= (a n + a (n + 2)) / a (n + 1) * b - (a n * b - a 0) / a (n + 1) : begin
norm_cast,
rw nat.cast_sub (nat.div_le_of_le_mul _),
rw [←mul_assoc, nat.mul_div_cancel' ha, add_mul],
exact tsub_le_self.trans (nat.le_add_right _ _),
end
... = a (n + 2) / a (n + 1) * b + (a 0 * a (n + 2)) / (a (n + 1) * a (n + 2))
: by rw [add_div, add_mul, sub_div, mul_div_right_comm, add_sub_sub_cancel,
mul_div_mul_right _ _ (a_pos _ le_rfl).ne']
... = ∑ (i : ℕ) in finset.range (n + 2), a 0 * a (n + 2) / (a i * a (i + 1))
: begin
rw [finset.sum_range_succ, hb, finset.mul_sum],
congr, ext i,
rw [←mul_div_assoc, ←mul_div_right_comm, mul_div_assoc, mul_div_cancel _
(a_pos _ $ nat.le_succ _).ne', mul_comm],
end },
-- Check the divisibility condition
{ rw [mul_tsub, ← mul_assoc, nat.mul_div_cancel' ha, add_mul,
nat.mul_div_cancel' han, add_tsub_tsub_cancel ha₀, add_tsub_cancel_right],
exact dvd_mul_right _ _ }
end
|
\appendix
\chapter{An appendix}\label{ch:appendix1}
Notice that the equation
\begin{equation}\label{eq:equation1}
H = \sum_{k}\epsilon_kc_k^\dagger c_k
\end{equation}
gets a ``A''.
\chapter{Another appendix}\label{ch:appendix2}
\begin{equation}
H = \sum_{k}\epsilon_kc_k^\dagger c_k
\end{equation}
Here, the equation gets a ``B''. |
/-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import analysis.normed_space.star.basic
import analysis.normed_space.spectrum
import algebra.star.module
import analysis.normed_space.star.exponential
/-! # Spectral properties in C⋆-algebras
In this file, we establish various propreties related to the spectrum of elements in C⋆-algebras.
-/
local postfix `⋆`:std.prec.max_plus := star
open_locale topological_space ennreal
open filter ennreal spectrum cstar_ring
section unitary_spectrum
variables
{𝕜 : Type*} [normed_field 𝕜]
{E : Type*} [normed_ring E] [star_ring E] [cstar_ring E]
[normed_algebra 𝕜 E] [complete_space E] [nontrivial E]
lemma unitary.spectrum_subset_circle (u : unitary E) :
spectrum 𝕜 (u : E) ⊆ metric.sphere 0 1 :=
begin
refine λ k hk, mem_sphere_zero_iff_norm.mpr (le_antisymm _ _),
{ simpa only [cstar_ring.norm_coe_unitary u] using norm_le_norm_of_mem hk },
{ rw ←unitary.coe_to_units_apply u at hk,
have hnk := ne_zero_of_mem_of_unit hk,
rw [←inv_inv (unitary.to_units u), ←spectrum.map_inv, set.mem_inv] at hk,
have : ∥k∥⁻¹ ≤ ∥↑((unitary.to_units u)⁻¹)∥, simpa only [norm_inv] using norm_le_norm_of_mem hk,
simpa using inv_le_of_inv_le (norm_pos_iff.mpr hnk) this }
end
lemma spectrum.subset_circle_of_unitary {u : E} (h : u ∈ unitary E) :
spectrum 𝕜 u ⊆ metric.sphere 0 1 :=
unitary.spectrum_subset_circle ⟨u, h⟩
end unitary_spectrum
section complex_scalars
open complex
variables {A : Type*}
[normed_ring A] [normed_algebra ℂ A] [complete_space A] [star_ring A] [cstar_ring A]
local notation `↑ₐ` := algebra_map ℂ A
lemma spectral_radius_eq_nnnorm_of_self_adjoint [norm_one_class A] {a : A}
(ha : a ∈ self_adjoint A) :
spectral_radius ℂ a = ∥a∥₊ :=
begin
have hconst : tendsto (λ n : ℕ, (∥a∥₊ : ℝ≥0∞)) at_top _ := tendsto_const_nhds,
refine tendsto_nhds_unique _ hconst,
convert (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a : A)).comp
(nat.tendsto_pow_at_top_at_top_of_one_lt (by linarith : 1 < 2)),
refine funext (λ n, _),
rw [function.comp_app, nnnorm_pow_two_pow_of_self_adjoint ha, ennreal.coe_pow, ←rpow_nat_cast,
←rpow_mul],
simp,
end
lemma spectral_radius_eq_nnnorm_of_star_normal [norm_one_class A] (a : A) [is_star_normal a] :
spectral_radius ℂ a = ∥a∥₊ :=
begin
refine (ennreal.pow_strict_mono two_ne_zero).injective _,
have ha : a⋆ * a ∈ self_adjoint A,
from self_adjoint.mem_iff.mpr (by simpa only [star_star] using (star_mul a⋆ a)),
have heq : (λ n : ℕ, ((∥(a⋆ * a) ^ n∥₊ ^ (1 / n : ℝ)) : ℝ≥0∞))
= (λ x, x ^ 2) ∘ (λ n : ℕ, ((∥a ^ n∥₊ ^ (1 / n : ℝ)) : ℝ≥0∞)),
{ funext,
rw [function.comp_apply, ←rpow_nat_cast, ←rpow_mul, mul_comm, rpow_mul, rpow_nat_cast,
←coe_pow, sq, ←nnnorm_star_mul_self, commute.mul_pow (star_comm_self' a), star_pow], },
have h₂ := ((ennreal.continuous_pow 2).tendsto (spectral_radius ℂ a)).comp
(spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius a),
rw ←heq at h₂,
convert tendsto_nhds_unique h₂ (pow_nnnorm_pow_one_div_tendsto_nhds_spectral_radius (a⋆ * a)),
rw [spectral_radius_eq_nnnorm_of_self_adjoint ha, sq, nnnorm_star_mul_self, coe_mul],
end
/-- Any element of the spectrum of a selfadjoint is real. -/
theorem self_adjoint.mem_spectrum_eq_re [star_module ℂ A] [nontrivial A] {a : A}
(ha : a ∈ self_adjoint A) {z : ℂ} (hz : z ∈ spectrum ℂ a) : z = z.re :=
begin
let Iu := units.mk0 I I_ne_zero,
have : exp ℂ (I • z) ∈ spectrum ℂ (exp ℂ (I • a)),
by simpa only [units.smul_def, units.coe_mk0]
using spectrum.exp_mem_exp (Iu • a) (smul_mem_smul_iff.mpr hz),
exact complex.ext (of_real_re _)
(by simpa only [←complex.exp_eq_exp_ℂ, mem_sphere_zero_iff_norm, norm_eq_abs, abs_exp,
real.exp_eq_one_iff, smul_eq_mul, I_mul, neg_eq_zero]
using spectrum.subset_circle_of_unitary (self_adjoint.exp_i_smul_unitary ha) this),
end
/-- Any element of the spectrum of a selfadjoint is real. -/
theorem self_adjoint.mem_spectrum_eq_re' [star_module ℂ A] [nontrivial A]
(a : self_adjoint A) {z : ℂ} (hz : z ∈ spectrum ℂ (a : A)) : z = z.re :=
self_adjoint.mem_spectrum_eq_re a.property hz
/-- The spectrum of a selfadjoint is real -/
theorem self_adjoint.coe_re_map_spectrum [star_module ℂ A] [nontrivial A] {a : A}
(ha : a ∈ self_adjoint A) : spectrum ℂ a = (coe ∘ re '' (spectrum ℂ a) : set ℂ) :=
le_antisymm (λ z hz, ⟨z, hz, (self_adjoint.mem_spectrum_eq_re ha hz).symm⟩) (λ z, by
{ rintros ⟨z, hz, rfl⟩,
simpa only [(self_adjoint.mem_spectrum_eq_re ha hz).symm, function.comp_app] using hz })
/-- The spectrum of a selfadjoint is real -/
theorem self_adjoint.coe_re_map_spectrum' [star_module ℂ A] [nontrivial A] (a : self_adjoint A) :
spectrum ℂ (a : A) = (coe ∘ re '' (spectrum ℂ (a : A)) : set ℂ) :=
self_adjoint.coe_re_map_spectrum a.property
end complex_scalars
|
kk : ∀ {ℓ} → Set ℓ
kk = {!∀ B → B!}
|
[STATEMENT]
lemma bounded_linear_blinfun_inner_right[bounded_linear]: "bounded_linear blinfun_inner_right"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. bounded_linear blinfun_inner_right
[PROOF STEP]
by transfer (rule bounded_bilinear_inner) |
State Before: G : Type u_1
G' : Type ?u.352996
inst✝² : Group G
inst✝¹ : Group G'
A : Type ?u.353005
inst✝ : AddGroup A
H K : Subgroup G
⊢ Characteristic H ↔ ∀ (ϕ : G ≃* G), map (MulEquiv.toMonoidHom ϕ) H ≤ H State After: G : Type u_1
G' : Type ?u.352996
inst✝² : Group G
inst✝¹ : Group G'
A : Type ?u.353005
inst✝ : AddGroup A
H K : Subgroup G
⊢ Characteristic H ↔ ∀ (ϕ : G ≃* G), comap (MulEquiv.toMonoidHom (MulEquiv.symm ϕ)) H ≤ H Tactic: simp_rw [map_equiv_eq_comap_symm] State Before: G : Type u_1
G' : Type ?u.352996
inst✝² : Group G
inst✝¹ : Group G'
A : Type ?u.353005
inst✝ : AddGroup A
H K : Subgroup G
⊢ Characteristic H ↔ ∀ (ϕ : G ≃* G), comap (MulEquiv.toMonoidHom (MulEquiv.symm ϕ)) H ≤ H State After: no goals Tactic: exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ |
State Before: E : Type u_1
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : FiniteDimensional ℝ E
⊢ multiplicity E ≤ 5 ^ finrank ℝ E State After: case h₁
E : Type u_1
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : FiniteDimensional ℝ E
⊢ Set.Nonempty
{N |
∃ s, Finset.card s = N ∧ (∀ (c : E), c ∈ s → ‖c‖ ≤ 2) ∧ ∀ (c : E), c ∈ s → ∀ (d : E), d ∈ s → c ≠ d → 1 ≤ ‖c - d‖}
case h₂
E : Type u_1
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : FiniteDimensional ℝ E
⊢ ∀ (b : ℕ),
b ∈
{N |
∃ s,
Finset.card s = N ∧
(∀ (c : E), c ∈ s → ‖c‖ ≤ 2) ∧ ∀ (c : E), c ∈ s → ∀ (d : E), d ∈ s → c ≠ d → 1 ≤ ‖c - d‖} →
b ≤ 5 ^ finrank ℝ E Tactic: apply csSup_le State Before: case h₁
E : Type u_1
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : FiniteDimensional ℝ E
⊢ Set.Nonempty
{N |
∃ s, Finset.card s = N ∧ (∀ (c : E), c ∈ s → ‖c‖ ≤ 2) ∧ ∀ (c : E), c ∈ s → ∀ (d : E), d ∈ s → c ≠ d → 1 ≤ ‖c - d‖} State After: no goals Tactic: refine' ⟨0, ⟨∅, by simp⟩⟩ State Before: E : Type u_1
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : FiniteDimensional ℝ E
⊢ Finset.card ∅ = 0 ∧ (∀ (c : E), c ∈ ∅ → ‖c‖ ≤ 2) ∧ ∀ (c : E), c ∈ ∅ → ∀ (d : E), d ∈ ∅ → c ≠ d → 1 ≤ ‖c - d‖ State After: no goals Tactic: simp State Before: case h₂
E : Type u_1
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : FiniteDimensional ℝ E
⊢ ∀ (b : ℕ),
b ∈
{N |
∃ s,
Finset.card s = N ∧
(∀ (c : E), c ∈ s → ‖c‖ ≤ 2) ∧ ∀ (c : E), c ∈ s → ∀ (d : E), d ∈ s → c ≠ d → 1 ≤ ‖c - d‖} →
b ≤ 5 ^ finrank ℝ E State After: case h₂.intro.intro
E : Type u_1
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : FiniteDimensional ℝ E
s : Finset E
h : (∀ (c : E), c ∈ s → ‖c‖ ≤ 2) ∧ ∀ (c : E), c ∈ s → ∀ (d : E), d ∈ s → c ≠ d → 1 ≤ ‖c - d‖
⊢ Finset.card s ≤ 5 ^ finrank ℝ E Tactic: rintro _ ⟨s, ⟨rfl, h⟩⟩ State Before: case h₂.intro.intro
E : Type u_1
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : FiniteDimensional ℝ E
s : Finset E
h : (∀ (c : E), c ∈ s → ‖c‖ ≤ 2) ∧ ∀ (c : E), c ∈ s → ∀ (d : E), d ∈ s → c ≠ d → 1 ≤ ‖c - d‖
⊢ Finset.card s ≤ 5 ^ finrank ℝ E State After: no goals Tactic: exact Besicovitch.card_le_of_separated s h.1 h.2 |
SUBROUTINE LS_GRPT( lenb, bulltn, jpos, lszrpt, lsfrpt, iret )
C************************************************************************
C* LS_GRPT *
C* *
C* This subroutine gets the next report in bulletin. The length of the *
C* report must be within the range limits; otherwise, the report is *
C* rejected. When there are no more reports in the bulletin, IRET will *
C* be set to 2. *
C* *
C* LS_GRPT ( LENB, BULLTN, JPOS, LSZRPT, LSFRPT, IRET ) *
C* *
C* Input parameters: *
C* LENB INTEGER Bulletin length *
C* BULLTN CHAR* Bulletin to decode *
C* *
C* Input and Output parameters: *
C* JPOS INTEGER Pointer to start of report *
C* *
C* Output parameters: *
C* LSZRPT INTEGER Report length *
C* LSFRPT CHAR* Raw report *
C* IRET INTEGER Return code *
C* 0 = normal return *
C* 1 = report rejected *
C* 2 = no more reports in bulletin*
C* 3 = found another AAXX group *
C* *
C** *
C* Log: *
C* R. Hollern/NCEP 4/96 *
C* R. Hollern/NCEP 10/96 Added logic to reject NIL reports *
C* R. Hollern/NCEP 1/98 Cleaned up and improved logging *
C* A. Hardy/GSC 1/98 Added GEMINC *
C* R. Hollern/NCEP 2/98 Redefined jsize *
C* D. Kidwell/NCEP 7/02 Added check for AAXX and return code 3 *
C************************************************************************
INCLUDE 'GEMPRM.PRM'
INCLUDE 'lscmn.cmn'
C*
CHARACTER*(*) bulltn, lsfrpt
C*
LOGICAL more
C------------------------------------------------------------------------
iret = 0
more = .true.
lsfrpt = ' '
C
DO WHILE ( more )
C
C* Remove any spaces before start of report.
C* Set pointer to start of report.
C
IF ( bulltn ( jpos:jpos ) .eq. ' ' ) THEN
jpos = jpos + 1
ELSE
more = .false.
END IF
C
C* Check for end of bulletin.
C
jsize = lenb - jpos + 1
C
IF ( jsize .lt. 18 ) THEN
iret = 2
RETURN
END IF
END DO
C
C* Check for another AAXX group.
C
IF ( bulltn ( jpos:jpos + 3 ) .eq. 'AAXX' ) THEN
jpos = jpos + 10
iret = 3
RETURN
END IF
C
lszrpt = 0
kst = jpos
more = .true.
C
DO WHILE ( more )
C
C* A report ends with the character '='.
C
IF ( bulltn ( jpos:jpos ) .eq. '=' ) THEN
jpos = jpos + 1
more = .false.
ELSE IF ( jpos .ge. lenb ) THEN
C
C* End of bulletin reached.
C
iret = 2
RETURN
ELSE
jpos = jpos + 1
lszrpt = lszrpt + 1
END IF
END DO
C
C* Check for and reject NIL report.
C
iipos = INDEX( bulltn ( kst:kst+10 ), 'NIL' )
IF ( iipos .gt. 0 ) THEN
iret = 1
RETURN
END IF
C
C* Check that the length of the report is not too long.
C
IF ( lszrpt .gt. 400 ) THEN
loglvl = 4
CALL DC_WLOG ( loglvl, 'LS', -1, bulltn(kst:kst+20), ierwl )
iret = 1
RETURN
END IF
C
C* Store report in lsfrpt.
C
lsfrpt ( 1:lszrpt ) = bulltn ( kst:jpos )
C*
RETURN
END
|
function nameList = makeNamesUnique(nameList, varargin)
% Identifies duplicate names in a list of names (cell array)
% and prompts the user to input new names.
% Called by `cleanTmodel`, `verifyModel`, `addSEEDInfo`, calls `countUnique`.
%
% USAGE:
%
% nameList = makeNamesUnique(nameList, [nameInfo])
%
% INPUTS:
% nameList: Cell array of entires that contains duplicates.
%
% OPTIONAL INPUTS:
% nameInfo: Cell array the same length as nameList that contains
% information pertaining to the matching entry in `nameList`. This
% array can help the renaming process.
%
% OUTPUTS:
% nameList: Version of nameList with all unique entires.
%
% Please cite:
% `Sauls, J. T., & Buescher, J. M. (2014). Assimilating genome-scale
% metabolic reconstructions with modelBorgifier. Bioinformatics
% (Oxford, England), 30(7), 1036?8`. http://doi.org/10.1093/bioinformatics/btt747
%
% ..
% Edit the above text to modify the response to help addMetInfo
% Last Modified by GUIDE v2.5 06-Dec-2013 14:19:28
% This file is published under Creative Commons BY-NC-SA.
%
% Correspondance:
% [email protected]
%
% Developed at:
% BRAIN Aktiengesellschaft
% Microbial Production Technologies Unit
% Quantitative Biology and Sequencing Platform
% Darmstaeter Str. 34-36
% 64673 Zwingenberg, Germany
% www.brain-biotech.de
if (nargin > 1) % Declare variables.
nameInfo = varargin{1} ;
end
% List of unique names, sorted.
uniqList = unique(nameList) ;
% Automatically rename entities?
[names, cnt] = countUnique(nameList);
nameInd = find(cnt > 1);
if ~isempty(nameInd)
fprintf('%d non-unique names. ', length(nameInd))
renameFlag = input(['Rename automatically?\n' ...
'Otherwise manual renaming will proceed. (y/n): '],...
's') ;
if strcmpi(renameFlag, 'y') || strcmpi(renameFlag, 'yes')
for i = 1:length(nameInd)
thisName = names{nameInd(i)} ;
fprintf('Renaming non-unique name %s (%d instances): ',...
thisName,cnt(nameInd(i)));
searchString = regexprep(thisName, '\[', '\\[') ;
searchString = regexprep(searchString,'\]', '\\]') ;
searchString = ['^' searchString '$'] ;
IDs = find(~cellfun(@isempty, regexp(nameList, searchString))) ;
for j = 1:length(IDs)
if regexp(nameList{IDs(j)}, '\[\w\]$')
nameList{IDs(j)} = [thisName(1:end - 3) '_' num2str(j) ...
thisName(end - 2:end)] ;
else
nameList{IDs(j)} = [thisName '_' num2str(j)] ;
end
fprintf('%s\t', nameList{IDs(j)}) ;
end
fprintf('\n')
end
end
end
%% Find duplicate names.
for iName = 1:length(uniqList)
dupPos = find(strcmp(uniqList{iName}, nameList)) ;
% If there are duplicates.
if length(dupPos) > 1
dupNo = length(dupPos) ;
% Duplicate name
dupName = uniqList{iName} ;
fprintf('%s has duplicates:\n', dupName)
% Go through each duplicate and print info.
for iDup = 1:dupNo
if exist('nameInfo','var')
string = [num2str(dupPos(iDup)), '\t', ...
nameInfo{dupPos(iDup)}, '\n'] ;
fprintf(string)
else
fprintf('%d\n', num2str(dupPos(iDup)))
end
end
% Ask for how names should be renamed.
for iDup = 1:dupNo
while 1
prompt = ['Rename ' num2str(dupPos(iDup)) ' as: '] ;
newName = input(prompt,'s') ;
alreadytherepos = strcmp(newName, nameList) ;
alreadytherepos(dupPos) = false ;
% Check to see if name is already taken
if sum(alreadytherepos) == 0
nameList{dupPos(iDup)} = newName ;
break
else
errorPrompt = 'Name already taken. Proceed (y/n)?: ' ;
proceed = input(errorPrompt, 's') ;
if strcmpi(proceed, 'y') || strcmpi(proceed, 'yes')
nameList{dupPos(iDup)} = newName ;
break
else
continue
end
end
end
end
end
end
%% Check to make sure it worked.
if length(unique(nameList)) ~= length(nameList)
fprintf('ERROR: Duplicate names still exist!\n')
end
|
module LetBinders
infix 1 :::
record List1 (a : Type) where
constructor (:::)
head : a
tail : List a
swap : List1 a -> List1 a
swap aas =
let (a ::: as) := aas in
let (b :: bs) = as
| [] => a ::: []
rest = a :: bs
in b ::: rest
identity : List (Nat, a) -> List (List a)
identity =
let
replicate : (n : Nat) -> a -> List a
replicate Z a = []
replicate (S n) a = a :: replicate n a
closure := uncurry replicate
in map closure
|
import smt2
import .test_tactics
lemma arith_simple :
forall (x y : int),
x < y →
x + 1 < y + 1000 :=
begin
intros, z3
end
lemma arith_wrong :
forall (x y : int),
x < y →
x + 1 < y :=
begin
intros, must_fail z3
end
lemma lt_trans_by_z3 :
forall (x y z : int),
x < y →
y < z →
x < z :=
begin
intros, z3
end
|
[STATEMENT]
theorem herbrand_evalt' [simp]:
\<open>evalt e HApp (term_of_hterm ht) = ht\<close>
\<open>evalts e HApp (terms_of_hterms hts) = hts\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. evalt e HApp (term_of_hterm ht) = ht &&& evalts e HApp (terms_of_hterms hts) = hts
[PROOF STEP]
by (induct ht and hts rule: term_of_hterm.induct terms_of_hterms.induct) simp_all |
State Before: α : Type u_1
m : Set α → ℝ≥0∞
s : Set α
⊢ ↑(boundedBy m) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' (n : ℕ), ⨆ (_ : Set.Nonempty (t n)), m (t n) State After: no goals Tactic: simp [boundedBy, ofFunction_apply] |
(*
Title: Dim_Formula.thy
Author: Jose Divasón <jose.divasonm at unirioja.es>
Author: Jesús Aransay <jesus-maria.aransay at unirioja.es>
Maintainer: Jose Divasón <jose.divasonm at unirioja.es>
*)
header "Rank Nullity Theorem of Linear Algebra"
theory Dim_Formula
imports Fundamental_Subspaces
begin
context vector_space
begin
subsection{*Previous results*}
text{*Linear dependency is a monotone property, based on the
monotonocity of linear independence:*}
lemma dependent_mono:
assumes d:"dependent A"
and A_in_B: "A \<subseteq> B"
shows "dependent B"
using independent_mono [OF _ A_in_B] d by auto
text{*Given a finite independent set, a linear combination of its
elements equal to zero is possible only if every coefficient is zero:*}
lemma scalars_zero_if_independent:
assumes fin_A: "finite A"
and ind: "independent A"
and sum: "(\<Sum>x\<in>A. scale (f x) x) = 0"
shows "\<forall>x \<in> A. f x = 0"
using assms unfolding independent_explicit by auto
end
context finite_dimensional_vector_space
begin
text{*In an finite dimensional vector space, every independent set is finite, and
thus @{thm [display ]scalars_zero_if_independent [no_vars]} holds:*}
corollary scalars_zero_if_independent_euclidean:
assumes ind: "independent A"
and sum: "(\<Sum>x\<in>A. scale (f x) x) = 0"
shows "\<forall>x \<in> A. f x = 0"
by (rule scalars_zero_if_independent,
rule conjunct1 [OF independent_bound [OF ind]])
(rule ind, rule sum)
end
text{*The following lemma states that every linear form is injective over the
elements which define the basis of the range of the linear form.
This property is applied later over the elements of an arbitrary
basis which are not in the basis of the nullifier or kernel set
(\emph{i.e.}, the candidates to be the basis of the range space
of the linear form).*}
text{*Thanks to this result, it can be concluded that the cardinal
of the elements of a basis which do not belong to the kernel
of a linear form @{term "f::'a => 'b"} is equal to the cardinal
of the set obtained when applying @{term "f::'a => 'b"} to such elements.*}
text{*The application of this lemma is not usually found in the pencil and paper
proofs of the ``rank nullity theorem'', but will be crucial to know that,
being @{term "f::'a => 'b"} a linear form from a finite dimensional
vector space @{term "V"} to a vector space @{term "V'"},
and given a basis @{term "B::'a set"} of @{term "ker f"},
when @{term "B"} is completed up to a basis of @{term "V::'a set"}
with a set @{term "W::'a set"}, the cardinal of this set is
equal to the cardinal of its range set:*}
context vector_space
begin
lemma inj_on_extended:
assumes lf: "linear scaleB scaleC f"
and f: "finite C"
and ind_C: "independent C"
and C_eq: "C = B \<union> W"
and disj_set: "B \<inter> W = {}"
and span_B: "{x. f x = 0} \<subseteq> span B"
shows "inj_on f W"
-- "The proof is carried out by reductio ad absurdum"
proof (unfold inj_on_def, rule+, rule ccontr)
interpret lf: linear scaleB scaleC f using lf by simp
-- "Some previous consequences of the premises that are used later:"
have fin_B: "finite B" using finite_subset [OF _ f] C_eq by simp
have ind_B: "independent B" and ind_W: "independent W"
using independent_mono[OF ind_C] C_eq by simp_all
-- "The proof starts here; we assume that there exist two different elements "
-- "with the same image:"
fix x::'b and y::'b
assume x: "x \<in> W" and y: "y \<in> W" and f_eq: "f x = f y" and x_not_y: "x \<noteq> y"
have fin_yB: "finite (insert y B)" using fin_B by simp
have "f (x - y) = 0" by (metis diff_self f_eq lf.linear_sub)
hence "x - y \<in> {x. f x = 0}" by simp
hence "\<exists>g. (\<Sum>v\<in>B. scale (g v) v) = (x - y)" using span_B
unfolding span_finite [OF fin_B] by auto
then obtain g where sum: "(\<Sum>v\<in>B. scale (g v) v) = (x - y)" by blast
-- "We define one of the elements as a linear combination of the second
element and the ones in $B$"
def h \<equiv> "(\<lambda>a. if a = y then (1::'a) else g a)"
have "x = y + (\<Sum>v\<in>B. scale (g v) v)" using sum by auto
also have "... = scale (h y) y + (\<Sum>v\<in>B. scale (g v) v)" unfolding h_def by simp
also have "... = scale (h y) y + (\<Sum>v\<in>B. scale (h v) v)"
apply (unfold add_left_cancel, rule setsum.cong)
using y h_def empty_iff disj_set by auto
also have "... = (\<Sum>v\<in>(insert y B). scale (h v) v)"
by (rule setsum.insert[symmetric], rule fin_B)
(metis (lifting) IntI disj_set empty_iff y)
finally have x_in_span_yB: "x \<in> span (insert y B)"
unfolding span_finite[OF fin_yB] by auto
-- "We have that a subset of elements of $C$ is linearly dependent"
have dep: "dependent (insert x (insert y B))"
by (unfold dependent_def, rule bexI [of _ x])
(metis Diff_insert_absorb Int_iff disj_set empty_iff insert_iff
x x_in_span_yB x_not_y, simp)
-- "Therefore, the set $C$ is also dependent:"
hence "dependent C" using C_eq x y
by (metis Un_commute Un_upper2 dependent_mono insert_absorb insert_subset)
-- "This yields the contradiction, since $C$ is independent:"
thus False using ind_C by contradiction
qed
end
subsection{*The proof*}
text{*Now the rank nullity theorem can be proved; given any linear form
@{term "f::'a => 'b"}, the sum of the dimensions of its kernel and
range subspaces is equal to the dimension of the source vector space.*}
text{*The statement of the ``rank nullity theorem for linear algebra'', as
well as its proof, follow the ones on~\cite{AX97}. The proof is the
traditional one found in the literature. The theorem is also named
``fundamental theorem of linear algebra'' in some texts (for instance,
in~\cite{GO10}).*}
context linear_first_finite_dimensional_vector_space
begin
theorem rank_nullity_theorem:
shows "B.dimension = B.dim {x. f x = 0} + C.dim (range f)"
proof -
have l: "linear scaleB scaleC f" by unfold_locales
-- "For convenience we define abbreviations for the universe set, $V$,
and the kernel of $f$"
def V == "UNIV::'b set"
def ker_f == "{x. f x = 0}"
-- "The kernel is a proper subspace:"
have sub_ker: "B.subspace {x. f x = 0}" using B.subspace_kernel[OF l] .
-- "The kernel has its proper basis, $B$:"
obtain B where B_in_ker: "B \<subseteq> {x. f x = 0}"
and independent_B: "B.independent B"
and ker_in_span:"{x. f x = 0} \<subseteq> B.span B"
and card_B: "card B = B.dim {x. f x = 0}" using B.basis_exists by blast
-- "The space $V$ has a (finite dimensional) basis, $C$:"
obtain C where B_in_C: "B \<subseteq> C" and C_in_V: "C \<subseteq> V"
and independent_C: "B.independent C"
and span_C: "V = B.span C"
using B.maximal_independent_subset_extend [OF _ independent_B, of V]
unfolding V_def by auto
-- "The basis of $V$, $C$, can be decomposed in the disjoint union of the
basis of the kernel, $B$, and its complementary set, $C - B$"
have C_eq: "C = B \<union> (C - B)" by (rule Diff_partition [OF B_in_C, symmetric])
have eq_fC: "f ` C = f ` B \<union> f ` (C - B)"
by (subst C_eq, unfold image_Un, simp)
-- "The basis $C$, and its image, are finite, since $V$ is finite-dimensional"
have finite_C: "finite C"
using B.independent_bound_general [OF independent_C] by fast
have finite_fC: "finite (f ` C)" by (rule finite_imageI [OF finite_C])
-- "The basis $B$ of the kernel of $f$, and its image, are also finite"
have finite_B: "finite B" by (rule rev_finite_subset [OF finite_C B_in_C])
have finite_fB: "finite (f ` B)" by (rule finite_imageI[OF finite_B])
-- "The set $C - B$ is also finite"
have finite_CB: "finite (C - B)" by (rule finite_Diff [OF finite_C, of B])
have dim_ker_le_dim_V:"B.dim (ker_f) \<le> B.dim V"
using B.dim_subset [of ker_f V] unfolding V_def by simp
-- "Here it starts the proof of the theorem: the sets $B$ and
$C - B$ must be proven to be bases, respectively, of the kernel
of $f$ and its range"
show ?thesis
proof -
have "B.dimension = B.dim V" unfolding V_def dim_UNIV dimension_def
by (metis B.basis_card_eq_dim B.dimension_def B.independent_Basis B.span_Basis top_greatest)
also have "B.dim V = B.dim C" unfolding span_C B.dim_span ..
also have "... = card C"
using B.basis_card_eq_dim [of C C, OF _ B.span_inc independent_C] by simp
also have "... = card (B \<union> (C - B))" using C_eq by simp
also have "... = card B + card (C-B)"
by (rule card_Un_disjoint[OF finite_B finite_CB], fast)
also have "... = B.dim ker_f + card (C-B)" unfolding ker_f_def card_B ..
-- "Now it has to be proved that the elements of $C - B$ are a basis of
the range of $f$"
also have "... = B.dim ker_f + C.dim (range f)"
proof (unfold add_left_cancel)
def W == "C - B"
have finite_W: "finite W" unfolding W_def using finite_CB .
have finite_fW: "finite (f ` W)" using finite_imageI[OF finite_W] .
have "card W = card (f ` W)"
by (rule card_image [symmetric], rule B.inj_on_extended[OF l, of C B], rule finite_C)
(rule independent_C,unfold W_def, subst C_eq, rule refl, simp, rule ker_in_span)
also have "... = C.dim (range f)"
unfolding C.dim_def
proof (rule someI2)
-- "1. The image set of $W$ generates the range of $f$:"
have range_in_span_fW: "range f \<subseteq> C.span (f ` W)"
proof (unfold l.C.span_finite [OF finite_fW], auto)
-- "Given any element $v$ in $V$, its image can be expressed as a
linear combination of elements of the image by $f$ of $C$:"
fix v :: 'b
have fV_span: "f ` V \<subseteq> C.span (f ` C)"
using B.spans_image [OF l] span_C by simp
have "\<exists>g. (\<Sum>x\<in>f`C. scaleC (g x) x) = f v"
using fV_span unfolding V_def
using l.C.span_finite[OF finite_fC] by auto
then obtain g where fv: "f v = (\<Sum>x\<in>f ` C. scaleC (g x) x)" by metis
-- "We recall that $C$ is equal to $B$ union $(C - B)$, and $B$
is the basis of the kernel; thus, the image of the elements of
$B$ will be equal to zero:"
have zero_fB: "(\<Sum>x\<in>f ` B. scaleC (g x) x) = 0"
using B_in_ker by (auto intro!: setsum.neutral)
have zero_inter: "(\<Sum>x\<in>(f ` B \<inter> f ` W). scaleC (g x) x) = 0"
using B_in_ker by (auto intro!: setsum.neutral)
have "f v = (\<Sum>x\<in>f ` C. scaleC (g x) x)" using fv .
also have "... = (\<Sum>x\<in>(f ` B \<union> f ` W). scaleC (g x) x)"
using eq_fC W_def by simp
also have "... =
(\<Sum>x\<in>f ` B. scaleC (g x) x) + (\<Sum>x\<in>f ` W. scaleC (g x) x)
- (\<Sum>x\<in>(f ` B \<inter> f ` W). scaleC (g x) x)"
using setsum_Un [OF finite_fB finite_fW] by simp
also have "... = (\<Sum>x\<in>f ` W. scaleC (g x) x)"
unfolding zero_fB zero_inter by simp
-- "We have proved that the image set of $W$ is a generating set
of the range of $f$"
finally show "\<exists>s. (\<Sum>x\<in>f ` W. scaleC (s x) x) = f v" by auto
qed
-- "2. The image set of $W$ is linearly independent:"
have independent_fW: "l.C.independent (f ` W)"
proof (rule l.C.independent_if_scalars_zero [OF finite_fW], rule+)
-- "Every linear combination (given by $g x$) of the elements of
the image set of $W$ equal to zero, requires every coefficient to
be zero:"
fix g :: "'c => 'a" and w :: 'c
assume sum: "(\<Sum>x\<in>f ` W. scaleC (g x) x) = 0" and w: "w \<in> f ` W"
have "0 = (\<Sum>x\<in>f ` W. scaleC (g x) x)" using sum by simp
also have "... = setsum ((\<lambda>x. scaleC (g x) x) \<circ> f) W"
by (rule setsum.reindex, rule B.inj_on_extended[OF l, of C B])
(unfold W_def, rule finite_C, rule independent_C, rule C_eq, simp,
rule ker_in_span)
also have "... = (\<Sum>x\<in>W. scaleC ((g \<circ> f) x) (f x))" unfolding o_def ..
also have "... = f (\<Sum>x\<in>W. scaleB ((g \<circ> f) x) x)"
using l.linear_setsum_mul [symmetric, OF finite_W] .
finally have f_sum_zero:"f (\<Sum>x\<in>W. scaleB ((g \<circ> f) x) x) = 0" by (rule sym)
hence "(\<Sum>x\<in>W. scaleB ((g \<circ> f) x) x) \<in> ker_f" unfolding ker_f_def by simp
hence "\<exists>h. (\<Sum>v\<in>B. scaleB (h v) v) = (\<Sum>x\<in>W. scaleB ((g \<circ> f) x) x)"
using B.span_finite[OF finite_B] using ker_in_span
unfolding ker_f_def by auto
then obtain h where
sum_h: "(\<Sum>v\<in>B. scaleB (h v) v) = (\<Sum>x\<in>W. scaleB ((g \<circ> f) x) x)" by blast
def t \<equiv> "(\<lambda>a. if a \<in> B then h a else - ((g \<circ> f) a))"
have "0 = (\<Sum>v\<in>B. scaleB (h v) v) + - (\<Sum>x\<in>W. scaleB ((g \<circ> f) x) x)"
using sum_h by simp
also have "... = (\<Sum>v\<in>B. scaleB (h v) v) + (\<Sum>x\<in>W. - (scaleB ((g \<circ> f) x) x))"
unfolding setsum_negf ..
also have "... = (\<Sum>v\<in>B. scaleB (t v) v) + (\<Sum>x\<in>W. -(scaleB((g \<circ> f) x) x))"
unfolding add_right_cancel unfolding t_def by simp
also have "... = (\<Sum>v\<in>B. scaleB (t v) v) + (\<Sum>x\<in>W. scaleB (t x) x)"
by (unfold add_left_cancel t_def W_def, rule setsum.cong) simp+
also have "... = (\<Sum>v\<in>B \<union> W. scaleB (t v) v)"
by (rule setsum.union_inter_neutral [symmetric], rule finite_B, rule finite_W)
(simp add: W_def)
finally have "(\<Sum>v\<in>B \<union> W. scaleB (t v) v) = 0" by simp
hence coef_zero: "\<forall>x\<in>B \<union> W. t x = 0"
using C_eq B.scalars_zero_if_independent [OF finite_C independent_C]
unfolding W_def by simp
obtain y where w_fy: "w = f y " and y_in_W: "y \<in> W" using w by fast
have "- g w = t y"
unfolding t_def w_fy using y_in_W unfolding W_def by simp
also have "... = 0" using coef_zero y_in_W unfolding W_def by simp
finally show "g w = 0" by simp
qed
-- "The image set of $W$ is independent and its span contains the range
of $f$, so it is a basis of the range:"
show " \<exists>B\<subseteq>range f. \<not> vector_space.dependent scaleC B
\<and> range f \<subseteq> vector_space.span scaleC B \<and> card B = card (f ` W)"
by (rule exI [of _"(f ` W)"],
simp add: range_in_span_fW independent_fW image_mono)
-- "Now, it has to be proved that any other basis of the subspace
range of $f$ has equal cardinality:"
show "\<And>n\<Colon>nat. \<exists>B\<subseteq>range f. l.C.independent B \<and> range f \<subseteq> l.C.span B \<and> card B = n
\<Longrightarrow> card (f ` W) = n"
proof (clarify)
fix S :: "'c set"
assume S_in_range: "S \<subseteq> range f" and independent_S: "vector_space.independent scaleC S"
and range_in_spanS: "range f \<subseteq> vector_space.span scaleC S"
have S_le: "finite S \<and> card S \<le> card (f ` W)"
by (rule l.C.independent_span_bound[OF finite_fW independent_S])
(rule subset_trans [OF S_in_range range_in_span_fW])
show "card (f ` W) = card S"
by (rule le_antisym, rule conjunct2, rule l.C.independent_span_bound)
(rule conjunct1 [OF S_le], rule independent_fW,
rule subset_trans [OF _ range_in_spanS], auto simp add: S_le)
qed
qed
finally show "card (C - B) = C.dim (range f)" unfolding W_def .
qed
finally show ?thesis unfolding V_def ker_f_def unfolding dim_UNIV .
qed
qed
end
subsection{*The rank nullity theorem for matrices*}
text{*The proof of the theorem for matrices
is direct, as a consequence of the ``rank nullity theorem''.*}
lemma rank_nullity_theorem_matrices:
fixes A::"'a::{field}^'cols::{finite, wellorder}^'rows"
shows "ncols A = vec.dim (null_space A) + vec.dim (col_space A)"
proof -
show ?thesis
apply (subst (1 2) matrix_of_matrix_vector_mul [of A, symmetric])
unfolding null_space_eq_ker[OF matrix_vector_mul_linear]
unfolding col_space_eq_range [OF matrix_vector_mul_linear]
using vec.rank_nullity_theorem
by (metis col_space_eq' ncols_def vec.dim_UNIV vec.dimension_def vec_dim_card)
qed
end
|
(*
Author: Norbert Schirmer
Maintainer: Norbert Schirmer, norbert.schirmer at web de
License: LGPL
*)
(* Title: Generalise.thy
Author: Norbert Schirmer, TU Muenchen
Copyright (C) 2005-2008 Norbert Schirmer
Some rights reserved, TU Muenchen
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*)
theory Generalise imports "~~/src/HOL/Statespace/DistinctTreeProver"
begin
lemma protectRefl: "PROP Pure.prop (PROP C) \<Longrightarrow> PROP Pure.prop (PROP C)"
by (simp add: prop_def)
lemma protectImp:
assumes i: "PROP Pure.prop (PROP P \<Longrightarrow> PROP Q)"
shows "PROP Pure.prop (PROP Pure.prop P \<Longrightarrow> PROP Pure.prop Q)"
proof -
{
assume P: "PROP Pure.prop P"
from i [unfolded prop_def, OF P [unfolded prop_def]]
have "PROP Pure.prop Q"
by (simp add: prop_def)
}
note i' = this
show "PROP ?thesis"
apply (rule protectI)
apply (rule i')
apply assumption
done
qed
lemma generaliseConj:
assumes i1: "PROP Pure.prop (PROP Pure.prop (Trueprop P) \<Longrightarrow> PROP Pure.prop (Trueprop Q))"
assumes i2: "PROP Pure.prop (PROP Pure.prop (Trueprop P') \<Longrightarrow> PROP Pure.prop (Trueprop Q'))"
shows "PROP Pure.prop (PROP Pure.prop (Trueprop (P \<and> P')) \<Longrightarrow> (PROP Pure.prop (Trueprop (Q \<and> Q'))))"
using i1 i2
by (auto simp add: prop_def)
lemma generaliseAll:
assumes i: "PROP Pure.prop (\<And>s. PROP Pure.prop (Trueprop (P s)) \<Longrightarrow> PROP Pure.prop (Trueprop (Q s)))"
shows "PROP Pure.prop (PROP Pure.prop (Trueprop (\<forall>s. P s)) \<Longrightarrow> PROP Pure.prop (Trueprop (\<forall>s. Q s)))"
using i
by (auto simp add: prop_def)
lemma generalise_all:
assumes i: "PROP Pure.prop (\<And>s. PROP Pure.prop (PROP P s) \<Longrightarrow> PROP Pure.prop (PROP Q s))"
shows "PROP Pure.prop ((PROP Pure.prop (\<And>s. PROP P s)) \<Longrightarrow> (PROP Pure.prop (\<And>s. PROP Q s)))"
using i
proof (unfold prop_def)
assume i1: "\<And>s. (PROP P s) \<Longrightarrow> (PROP Q s)"
assume i2: "\<And>s. PROP P s"
show "\<And>s. PROP Q s"
by (rule i1) (rule i2)
qed
lemma generaliseTrans:
assumes i1: "PROP Pure.prop (PROP P \<Longrightarrow> PROP Q)"
assumes i2: "PROP Pure.prop (PROP Q \<Longrightarrow> PROP R)"
shows "PROP Pure.prop (PROP P \<Longrightarrow> PROP R)"
using i1 i2
proof (unfold prop_def)
assume P_Q: "PROP P \<Longrightarrow> PROP Q"
assume Q_R: "PROP Q \<Longrightarrow> PROP R"
assume P: "PROP P"
show "PROP R"
by (rule Q_R [OF P_Q [OF P]])
qed
lemma meta_spec:
assumes "\<And>x. PROP P x"
shows "PROP P x" by fact
lemma meta_spec_protect:
assumes g: "\<And>x. PROP P x"
shows "PROP Pure.prop (PROP P x)"
using g
by (auto simp add: prop_def)
lemma generaliseImp:
assumes i: "PROP Pure.prop (PROP Pure.prop (Trueprop P) \<Longrightarrow> PROP Pure.prop (Trueprop Q))"
shows "PROP Pure.prop (PROP Pure.prop (Trueprop (X \<longrightarrow> P)) \<Longrightarrow> PROP Pure.prop (Trueprop (X \<longrightarrow> Q)))"
using i
by (auto simp add: prop_def)
lemma generaliseEx:
assumes i: "PROP Pure.prop (\<And>s. PROP Pure.prop (Trueprop (P s)) \<Longrightarrow> PROP Pure.prop (Trueprop (Q s)))"
shows "PROP Pure.prop (PROP Pure.prop (Trueprop (\<exists>s. P s)) \<Longrightarrow> PROP Pure.prop (Trueprop (\<exists>s. Q s)))"
using i
by (auto simp add: prop_def)
lemma generaliseRefl: "PROP Pure.prop (PROP Pure.prop (Trueprop P) \<Longrightarrow> PROP Pure.prop (Trueprop P))"
by (auto simp add: prop_def)
lemma generaliseRefl': "PROP Pure.prop (PROP P \<Longrightarrow> PROP P)"
by (auto simp add: prop_def)
lemma generaliseAllShift:
assumes i: "PROP Pure.prop (\<And>s. P \<Longrightarrow> Q s)"
shows "PROP Pure.prop (PROP Pure.prop (Trueprop P) \<Longrightarrow> PROP Pure.prop (Trueprop (\<forall>s. Q s)))"
using i
by (auto simp add: prop_def)
lemma generalise_allShift:
assumes i: "PROP Pure.prop (\<And>s. PROP P \<Longrightarrow> PROP Q s)"
shows "PROP Pure.prop (PROP Pure.prop (PROP P) \<Longrightarrow> PROP Pure.prop (\<And>s. PROP Q s))"
using i
proof (unfold prop_def)
assume P_Q: "\<And>s. PROP P \<Longrightarrow> PROP Q s"
assume P: "PROP P"
show "\<And>s. PROP Q s"
by (rule P_Q [OF P])
qed
lemma generaliseImpl:
assumes i: "PROP Pure.prop (PROP Pure.prop P \<Longrightarrow> PROP Pure.prop Q)"
shows "PROP Pure.prop ((PROP Pure.prop (PROP X \<Longrightarrow> PROP P)) \<Longrightarrow> (PROP Pure.prop (PROP X \<Longrightarrow> PROP Q)))"
using i
proof (unfold prop_def)
assume i1: "PROP P \<Longrightarrow> PROP Q"
assume i2: "PROP X \<Longrightarrow> PROP P"
assume X: "PROP X"
show "PROP Q"
by (rule i1 [OF i2 [OF X]])
qed
ML_file "generalise_state.ML"
end
|
import Mynat.Base
namespace mynat
def myadd (m n : mynat) : mynat :=
match n with
| 0 => m
| succ n' => succ (myadd m n')
instance : Add mynat where
add := myadd
theorem add_zero (m : mynat) : m + 0 = m := rfl
theorem add_succ (m n : mynat) : m + succ n = succ (m + n) := rfl
theorem zero_add (n : mynat) : 0 + n = n := by
cases n
. rfl
case succ m =>
have h := congrArg succ (zero_add m)
rw [←add_succ] at h
exact h
theorem add_assoc (a b c : mynat) : (a + b) + c = a + (b + c) := by
cases c
case zero =>
rw [mynat_zero_eq_zero]
repeat {rw [add_zero]}
rfl
case succ m =>
rw [add_succ]
rw [add_succ]
rw [add_succ]
rw [add_assoc a b m]
theorem succ_add (a b : mynat) : succ a + b = succ (a + b) := by
cases b
case zero =>
rw [mynat_zero_eq_zero]
repeat {rw [add_zero]}
rfl
case succ m =>
rw [add_succ]
rw [add_succ]
rw [succ_add a m]
theorem add_comm (a b : mynat) : a + b = b + a := by
cases b
case zero =>
rw [mynat_zero_eq_zero]
rw [add_zero]
rw [zero_add]
case succ m =>
rw [add_succ]
rw [succ_add]
rw [add_comm a m]
theorem succ_eq_add_one (n : mynat) : succ n = n + 1 := by
rw [one_eq_succ_zero]
rw [add_succ n 0]
rw [add_zero]
theorem add_right_comm (a b c : mynat) : a + b + c = a + c + b := by
rw [add_assoc]
rw [add_assoc]
rw [add_comm b c]
attribute [simp] add_assoc add_comm add_right_comm
end mynat |
\chapter{What is Sun} \label{chp2}
In this chapter, we investigate the discontinuity problem between |
These two boys belong to the same household. Decker (black) & Zeke (blue merle) are Aussie/Heeler crosses. I had the pleasure of meeting them. Both lovely gentlemen. This is my first double commission. Acrylics on 10×8″ on panel. |
lemma to_fract_add [simp]: "to_fract (x + y) = to_fract x + to_fract y" |
Formal statement is: lemma locally_connected_1: assumes "\<And>V x. \<lbrakk>openin (top_of_set S) V; x \<in> V\<rbrakk> \<Longrightarrow> \<exists>U. openin (top_of_set S) U \<and> connected U \<and> x \<in> U \<and> U \<subseteq> V" shows "locally connected S" Informal statement is: If every point in a topological space has a connected neighborhood, then the space is locally connected. |
data Maybe a = Nothing
| Just a
infixl 1 >>=
(>>=) : Maybe a -> (a -> Maybe b) -> Maybe b
(>>=) Nothing k = Nothing
(>>=) (Just x) k = k x
data Nat : Type where
Z : Nat
S : Nat -> Nat
plus : Nat -> Nat -> Nat
plus Z y = y
plus (S k) y = S (plus k y)
maybeAdd' : Maybe Nat -> Maybe Nat -> Maybe Nat
maybeAdd' x y
= x >>= \x' =>
y >>= \y' =>
Just (plus x' y')
maybeAdd : Maybe Nat -> Maybe Nat -> Maybe Nat
maybeAdd x y
= do x' <- x
y' <- y
Just (plus x' y')
data Either : Type -> Type -> Type where
Left : a -> Either a b
Right : b -> Either a b
mEmbed : Maybe a -> Maybe (Either String a)
mEmbed Nothing = Just (Left "FAIL")
mEmbed (Just x) = Just (Right x)
mPatBind : Maybe Nat -> Maybe Nat -> Maybe Nat
mPatBind x y
= do Right res <- mEmbed (maybeAdd x y)
| Left err => Just Z
Just res
mLetBind : Maybe Nat -> Maybe Nat -> Maybe Nat
mLetBind x y
= do let Just res = maybeAdd x y
| Nothing => Just Z
Just res
|
module ExtInterface.Data.Product where
-- TODO: Write to Agda team about the lack of compilability of Sigma.
-- I assumed that the builtin flag would allow to compile Σ into (,)
-- but it doesn't. That's why this microfile exists
infixr 4 ⟨_,_⟩
infixr 2 _×_
data _×_ (A B : Set) : Set where
⟨_,_⟩ : A → B → A × B
{-# COMPILE GHC _×_ = data (,) ((,)) #-} -- Yeah, kinda abstract
proj₁ : ∀ {A B : Set} → A × B → A
proj₁ ⟨ x , y ⟩ = x
proj₂ : ∀ {A B : Set} → A × B → B
proj₂ ⟨ x , y ⟩ = y
map : ∀ {A B C D : Set}
→ (A → C) → (B → D) → A × B → C × D
map f g ⟨ x , y ⟩ = ⟨ f x , g y ⟩
map₁ : ∀ {A B C : Set}
→ (A → C) → A × B → C × B
map₁ f = map f (λ x → x)
map₂ : ∀ {A B D : Set}
→ (B → D) → A × B → A × D
map₂ g = map (λ x → x) g
|
[STATEMENT]
lemma fincomp_0 [simp]:
"f \<in> {0::nat} \<rightarrow> M \<Longrightarrow> fincomp f {..0} = f 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. f \<in> {0} \<rightarrow> M \<Longrightarrow> fincomp f {..0} = f 0
[PROOF STEP]
by (simp add: Pi_def) |
module Spec_3_4_3 where
import Test.Hspec
import Numeric.LinearAlgebra
import Section_3_4_3 (initNetwork, forward)
spec :: Spec
spec = do
describe "forward" $ do
it "(1.0, 0.5) -> (0.326, 0.696)" $ do
let x = vector [1.0, 0.5]
answer = vector [0.31682708, 0.69627909]
prediction = forward initNetwork x
err = 0.0001
norm_2 (answer - prediction) < err `shouldBe` True
|
theory maximum
imports "~~/src/HOL/Hoare/Hoare_Logic"
"~~/src/HOL/Hoare/Arith2"
"~~/src/HOL/Hoare/List"
begin
(* ******************* *)
(* ******************* *)
(* ******************* *)
definition maximum :: "nat list \<Rightarrow> nat" where
"maximum l = foldr max l 0"
value "maximum [1,3,5,4,2]" (* 5 *)
value "maximum []" (* 0 *)
lemma max_hdtl_eq [simp] : "l \<noteq> [] \<Longrightarrow> max (hd l) (maximum (tl l)) = maximum l"
apply (induct l)
apply (auto)
apply (simp add: hd_def tl_def maximum_def)
done
(* ******* *)
(* ******* *)
(* ******* *)
lemma l1 : "max (maximum x) y = maximum l \<Longrightarrow>
x \<noteq> [] \<Longrightarrow> y \<le> hd x \<Longrightarrow> max (maximum (tl x)) (hd x) = maximum l"
by (metis max.assoc max.commute max_def max_hdtl_eq)
(*
proof -
fix x y l
assume 1 : "max (maximum x) y = maximum l" and
2 : "x \<noteq> []" and
3 : "y \<le> hd x"
show "max (maximum (tl x)) (hd x) = maximum l"
by (metis "1" "2" "3" max.assoc max.commute max_def max_hdtl_eq)
qed
*)
lemma l2 : "max (maximum x) y = maximum l \<Longrightarrow>
x \<noteq> [] \<Longrightarrow> \<not> y \<le> hd x \<Longrightarrow> max (maximum (tl x)) y = maximum l"
by (metis max.assoc max.commute max_def max_hdtl_eq)
(*
proof -
fix x y l
assume 1 : "max (maximum x) y = maximum l" and
2 : "x \<noteq> []" and
3 : "\<not> y \<le> hd x"
show "max (maximum (tl x)) y = maximum l"
by (metis "1" "2" "3" max.assoc max.commute max_def max_hdtl_eq)
qed
*)
lemma l3 : "max (maximum []) y = maximum l \<Longrightarrow> y = maximum l"
by (simp add: maximum_def)
(*
proof -
fix y l
assume "max (maximum []) y = maximum l"
thus "y = maximum l" using maximum_def by auto
qed
*)
(* ******* *)
(* ******* *)
(* ******* *)
theorem "TRUE
\<Longrightarrow>
VARS x y l
{x = l \<and> y = 0}
y := 0;
WHILE x \<noteq> []
INV {max (maximum x) y = maximum l}
DO
IF y \<le> hd x THEN
y := hd x
ELSE
SKIP
FI;
x := tl x
OD
{y = maximum l}"
apply vcg
apply auto
apply (simp_all add: l1 l2 l3)
done
end
(* END *) |
structure U (α : Type) where
a : α
theorem mk_inj (w : U.mk a = U.mk b) : a = b := by
injection w
|
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
! This file was ported from Lean 3 source module topology.metric_space.basic
! leanprover-community/mathlib commit 8631e2d5ea77f6c13054d9151d82b83069680cb1
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
-- import Mathbin.Tactic.Positivity
-- import Mathbin.Topology.Algebra.Order.Compact
-- import Mathbin.Topology.MetricSpace.EmetricSpace
-- import Mathbin.Topology.Bornology.Constructions
import Mathlib.Data.Real.Basic
import Hata.MathlibPort.Data.Real.Ennreal
import Hata.MathlibPort.Data.Real.Nnreal
/-!
# Metric spaces
This file defines metric spaces. Many definitions and theorems expected
on metric spaces are already introduced on uniform spaces and topological spaces.
For example: open and closed sets, compactness, completeness, continuity and uniform continuity
## Main definitions
* `has_dist α`: Endows a space `α` with a function `dist a b`.
* `pseudo_metric_space α`: A space endowed with a distance function, which can
be zero even if the two elements are non-equal.
* `metric.ball x ε`: The set of all points `y` with `dist y x < ε`.
* `metric.bounded s`: Whether a subset of a `pseudo_metric_space` is bounded.
* `metric_space α`: A `pseudo_metric_space` with the guarantee `dist x y = 0 → x = y`.
Additional useful definitions:
* `nndist a b`: `dist` as a function to the non-negative reals.
* `metric.closed_ball x ε`: The set of all points `y` with `dist y x ≤ ε`.
* `metric.sphere x ε`: The set of all points `y` with `dist y x = ε`.
* `proper_space α`: A `pseudo_metric_space` where all closed balls are compact.
* `metric.diam s` : The `supr` of the distances of members of `s`.
Defined in terms of `emetric.diam`, for better handling of the case when it should be infinite.
TODO (anyone): Add "Main results" section.
## Implementation notes
Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the
theory of `pseudo_metric_space`, where we don't require `dist x y = 0 → x = y` and we specialize
to `metric_space` at the end.
## Tags
metric, pseudo_metric, dist
-/
-- open Set Filter TopologicalSpace Bornology
-- open uniformity TopologicalSpace BigOperators Filter Nnreal Ennreal
open Nnreal Ennreal
universe u v w
variable {α : Type u} {β : Type v} {X ι : Type _}
/-- Construct a uniform structure core from a distance function and metric space axioms.
This is a technical construction that can be immediately used to construct a uniform structure
from a distance function and metric space axioms but is also useful when discussing
metrizable topologies, see `pseudo_metric_space.of_metrizable`. -/
-- def UniformSpace.coreOfDist {α : Type _} (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0)
-- (dist_comm : ∀ x y : α, dist x y = dist y x)
-- (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace.Core α := sorry
-- where
-- uniformity := ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε }
-- refl :=
-- le_infᵢ fun ε =>
-- le_infᵢ <| by
-- simp (config := { contextual := true }) [Set.subset_def, idRel, dist_self, (· > ·)]
-- comp :=
-- le_infᵢ fun ε =>
-- le_infᵢ fun h =>
-- lift'_le
-- (mem_infᵢ_of_mem (ε / 2) <| mem_infᵢ_of_mem (div_pos h zero_lt_two) (Subset.refl _)) <|
-- by
-- have : ∀ a b c : α, dist a c < ε / 2 → dist c b < ε / 2 → dist a b < ε :=
-- fun a b c hac hcb =>
-- calc
-- dist a b ≤ dist a c + dist c b := dist_triangle _ _ _
-- _ < ε / 2 + ε / 2 := add_lt_add hac hcb
-- _ = ε := by rw [div_add_div_same, add_self_div_two]
-- simpa [compRel]
-- symm :=
-- tendsto_infᵢ.2 fun ε =>
-- tendsto_infᵢ.2 fun h =>
-- tendsto_infᵢ' ε <| tendsto_infᵢ' h <| tendsto_principal_principal.2 <| by simp [dist_comm]
-- #align uniform_space.core_of_dist UniformSpace.coreOfDist
def ignore_me := ""
/-
/-- Construct a uniform structure from a distance function and metric space axioms -/
def uniformSpaceOfDist (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace α :=
UniformSpace.ofCore (UniformSpace.coreOfDist dist dist_self dist_comm dist_triangle)
#align uniform_space_of_dist uniformSpaceOfDist
/-- This is an internal lemma used to construct a bornology from a metric in `bornology.of_dist`. -/
private theorem bounded_iff_aux {α : Type _} (dist : α → α → ℝ)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) (s : Set α) (a : α) :
(∃ c, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ c) ↔ ∃ r, ∀ ⦃x⦄, x ∈ s → dist x a ≤ r :=
by
constructor <;> rintro ⟨C, hC⟩
· rcases s.eq_empty_or_nonempty with (rfl | ⟨x, hx⟩)
· exact ⟨0, by simp⟩
· exact ⟨C + dist x a, fun y hy => (dist_triangle y x a).trans (add_le_add_right (hC hy hx) _)⟩
·
exact
⟨C + C, fun x hx y hy =>
(dist_triangle x a y).trans
(add_le_add (hC hx)
(by
rw [dist_comm]
exact hC hy))⟩
#align bounded_iff_aux bounded_iff_aux
/-- Construct a bornology from a distance function and metric space axioms. -/
def Bornology.ofDist {α : Type _} (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : Bornology α :=
Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C }
⟨0, fun x hx y => hx.elim⟩ (fun s ⟨c, hc⟩ t h => ⟨c, fun x hx y hy => hc (h hx) (h hy)⟩)
(fun s hs t ht => by
rcases s.eq_empty_or_nonempty with (rfl | ⟨z, hz⟩)
· exact (empty_union t).symm ▸ ht
· simp only [fun u => bounded_iff_aux dist dist_comm dist_triangle u z] at hs ht⊢
rcases hs, ht with ⟨⟨r₁, hr₁⟩, ⟨r₂, hr₂⟩⟩
exact
⟨max r₁ r₂, fun x hx =>
Or.elim hx (fun hx' => (hr₁ hx').trans (le_max_left _ _)) fun hx' =>
(hr₂ hx').trans (le_max_right _ _)⟩)
fun z =>
⟨0, fun x hx y hy => by
rw [eq_of_mem_singleton hx, eq_of_mem_singleton hy]
exact (dist_self z).le⟩
#align bornology.of_dist Bornology.ofDist
-/
/-- The distance function (given an ambient metric space on `α`), which returns
a nonnegative real number `dist x y` given `x y : α`. -/
@[ext]
class HasDist (α : Type _) where
dist : α → α → ℝ
#align has_dist HasDist
export HasDist (dist)
-- the uniform structure and the emetric space structure are embedded in the metric space structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- This is an internal lemma used inside the default of `pseudo_metric_space.edist`. -/
private theorem PseudoMetricSpace.dist_nonneg' {α} {x y : α} (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : 0 ≤ dist x y :=
have : 2 * dist x y ≥ 0 :=
calc
2 * dist x y = dist x y + dist y x := by rw [dist_comm x y, two_mul]
_ ≥ 0 := by rw [← dist_self x] <;> apply dist_triangle
nonneg_of_mul_nonneg_right this zero_lt_two
-- #align pseudo_metric_space.dist_nonneg' PseudoMetricSpace.dist_nonneg'
/-
/- ./././Mathport/Syntax/Translate/Expr.lean:333:4: warning: unsupported (TODO): `[tacs] -/
/-- This tactic is used to populate `pseudo_metric_space.edist_dist` when the default `edist` is
used. -/
protected unsafe def pseudo_metric_space.edist_dist_tac : tactic Unit :=
tactic.intros >> sorry
#align pseudo_metric_space.edist_dist_tac pseudo_metric_space.edist_dist_tac
-/
/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:72:18: unsupported non-interactive tactic pseudo_metric_space.edist_dist_tac -/
/-- Pseudo metric and Metric spaces
A pseudo metric space is endowed with a distance for which the requirement `d(x,y)=0 → x = y` might
not hold. A metric space is a pseudo metric space such that `d(x,y)=0 → x = y`.
Each pseudo metric space induces a canonical `uniform_space` and hence a canonical
`topological_space` This is enforced in the type class definition, by extending the `uniform_space`
structure. When instantiating a `pseudo_metric_space` structure, the uniformity fields are not
necessary, they will be filled in by default. In the same way, each (pseudo) metric space induces a
(pseudo) emetric space structure. It is included in the structure, but filled in by default.
-/
class PseudoMetricSpace (α : Type u) extends HasDist α : Type u where
dist_self : ∀ x : α, dist x x = 0
dist_comm : ∀ x y : α, dist x y = dist y x
dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z
edist : α → α → ℝ≥0∞ := fun x y =>
@Coe.coe ℝ≥0 _ _ ⟨dist x y, PseudoMetricSpace.dist_nonneg' _ ‹_› ‹_› ‹_›⟩
edist_dist : ∀ x y : α, edist x y = Ennreal.ofReal (dist x y) := by simp
-- run_tac
-- pseudo_metric_space.edist_dist_tac
-- toUniformSpace : UniformSpace α := uniformSpaceOfDist dist dist_self dist_comm dist_triangle
-- uniformity_dist :
-- 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α |
-- dist p.1 p.2 < ε } := by
-- intros
-- rfl
-- toBornology : Bornology α := Bornology.ofDist dist dist_self dist_comm dist_triangle
-- cobounded_sets :
-- (Bornology.cobounded α).sets =
-- { s | ∃ C, ∀ ⦃x⦄, x ∈ sᶜ →
-- ∀ ⦃y⦄, y ∈ sᶜ → dist x y ≤ C } := by
-- intros
-- rfl
#align pseudo_metric_space PseudoMetricSpace
/-- Two pseudo metric space structures with the same distance function coincide. -/
@[ext]
theorem PseudoMetricSpace.ext {α : Type _} {m m' : PseudoMetricSpace α}
(h : m.toHasDist = m'.toHasDist) : m = m' :=
by
rcases m with ⟨⟩
rcases m' with ⟨⟩
dsimp at h
subst h
congr
· ext (x y) : 2
dsimp at m_edist_dist m'_edist_dist
simp [m_edist_dist, m'_edist_dist]
· dsimp at m_uniformity_dist m'_uniformity_dist
rw [← m'_uniformity_dist] at m_uniformity_dist
exact uniformSpace_eq m_uniformity_dist
· ext1
dsimp at m_cobounded_sets m'_cobounded_sets
rw [← m'_cobounded_sets] at m_cobounded_sets
exact filter_eq m_cobounded_sets
#align pseudo_metric_space.ext PseudoMetricSpace.ext
variable [PseudoMetricSpace α]
attribute [instance] PseudoMetricSpace.toUniformSpace
attribute [instance] PseudoMetricSpace.toBornology
/-
-- see Note [lower instance priority]
instance (priority := 200) PseudoMetricSpace.toHasEdist : HasEdist α :=
⟨PseudoMetricSpace.edist⟩
#align pseudo_metric_space.to_has_edist PseudoMetricSpace.toHasEdist
/-- Construct a pseudo-metric space structure whose underlying topological space structure
(definitionally) agrees which a pre-existing topology which is compatible with a given distance
function. -/
def PseudoMetricSpace.ofMetrizable {α : Type _} [TopologicalSpace α] (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) :
PseudoMetricSpace α :=
{ dist
dist_self
dist_comm
dist_triangle
toUniformSpace :=
{ UniformSpace.coreOfDist dist dist_self dist_comm dist_triangle with
is_open_uniformity := by
dsimp only [UniformSpace.coreOfDist]
intro s
change IsOpen s ↔ _
rw [H s]
refine' forall₂_congr fun x x_in => _
erw [(has_basis_binfi_principal _ nonempty_Ioi).mem_iff]
· refine' exists₂_congr fun ε ε_pos => _
simp only [Prod.forall, set_of_subset_set_of]
constructor
· rintro h _ y H rfl
exact h y H
· intro h y hxy
exact h _ _ hxy rfl
·
exact fun r (hr : 0 < r) p (hp : 0 < p) =>
⟨min r p, lt_min hr hp, fun x (hx : dist _ _ < _) =>
lt_of_lt_of_le hx (min_le_left r p), fun x (hx : dist _ _ < _) =>
lt_of_lt_of_le hx (min_le_right r p)⟩
· infer_instance }
uniformity_dist := rfl
toBornology := Bornology.ofDist dist dist_self dist_comm dist_triangle
cobounded_sets := rfl }
#align pseudo_metric_space.of_metrizable PseudoMetricSpace.ofMetrizable
@[simp]
theorem dist_self (x : α) : dist x x = 0 :=
PseudoMetricSpace.dist_self x
#align dist_self dist_self
theorem dist_comm (x y : α) : dist x y = dist y x :=
PseudoMetricSpace.dist_comm x y
#align dist_comm dist_comm
theorem edist_dist (x y : α) : edist x y = Ennreal.ofReal (dist x y) :=
PseudoMetricSpace.edist_dist x y
#align edist_dist edist_dist
theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
PseudoMetricSpace.dist_triangle x y z
#align dist_triangle dist_triangle
theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by
rw [dist_comm z] <;> apply dist_triangle
#align dist_triangle_left dist_triangle_left
theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z := by
rw [dist_comm y] <;> apply dist_triangle
#align dist_triangle_right dist_triangle_right
theorem dist_triangle4 (x y z w : α) : dist x w ≤ dist x y + dist y z + dist z w :=
calc
dist x w ≤ dist x z + dist z w := dist_triangle x z w
_ ≤ dist x y + dist y z + dist z w := add_le_add_right (dist_triangle x y z) _
#align dist_triangle4 dist_triangle4
theorem dist_triangle4_left (x₁ y₁ x₂ y₂ : α) :
dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) :=
by
rw [add_left_comm, dist_comm x₁, ← add_assoc]
apply dist_triangle4
#align dist_triangle4_left dist_triangle4_left
theorem dist_triangle4_right (x₁ y₁ x₂ y₂ : α) :
dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ :=
by
rw [add_right_comm, dist_comm y₁]
apply dist_triangle4
#align dist_triangle4_right dist_triangle4_right
/-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/
theorem dist_le_ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) :
dist (f m) (f n) ≤ ∑ i in Finset.ico m n, dist (f i) (f (i + 1)) :=
by
revert n
apply Nat.le_induction
· simp only [Finset.sum_empty, Finset.ico_self, dist_self]
· intro n hn hrec
calc
dist (f m) (f (n + 1)) ≤ dist (f m) (f n) + dist _ _ := dist_triangle _ _ _
_ ≤ (∑ i in Finset.ico m n, _) + _ := add_le_add hrec le_rfl
_ = ∑ i in Finset.ico m (n + 1), _ := by
rw [Nat.ico_succ_right_eq_insert_ico hn, Finset.sum_insert, add_comm] <;> simp
#align dist_le_Ico_sum_dist dist_le_ico_sum_dist
/-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/
theorem dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) :
dist (f 0) (f n) ≤ ∑ i in Finset.range n, dist (f i) (f (i + 1)) :=
Nat.ico_zero_eq_range ▸ dist_le_ico_sum_dist f (Nat.zero_le n)
#align dist_le_range_sum_dist dist_le_range_sum_dist
/-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
theorem dist_le_ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ}
(hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f m) (f n) ≤ ∑ i in Finset.ico m n, d i :=
le_trans (dist_le_ico_sum_dist f hmn) <|
Finset.sum_le_sum fun k hk => hd (Finset.mem_ico.1 hk).1 (Finset.mem_ico.1 hk).2
#align dist_le_Ico_sum_of_dist_le dist_le_ico_sum_of_dist_le
/-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
theorem dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ}
(hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f 0) (f n) ≤ ∑ i in Finset.range n, d i :=
Nat.ico_zero_eq_range ▸ dist_le_ico_sum_of_dist_le (zero_le n) fun _ _ => hd
#align dist_le_range_sum_of_dist_le dist_le_range_sum_of_dist_le
theorem swap_dist : Function.swap (@dist α _) = dist := by funext x y <;> exact dist_comm _ _
#align swap_dist swap_dist
theorem abs_dist_sub_le (x y z : α) : |dist x z - dist y z| ≤ dist x y :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add.2 (dist_triangle _ _ _), sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩
#align abs_dist_sub_le abs_dist_sub_le
theorem dist_nonneg {x y : α} : 0 ≤ dist x y :=
PseudoMetricSpace.dist_nonneg' dist dist_self dist_comm dist_triangle
#align dist_nonneg dist_nonneg
section
open Tactic Tactic.Positivity
/-- Extension for the `positivity` tactic: distances are nonnegative. -/
@[positivity]
unsafe def _root_.tactic.positivity_dist : expr → tactic strictness
| q(dist $(a) $(b)) => nonnegative <$> mk_app `` dist_nonneg [a, b]
| _ => failed
#align tactic.positivity_dist tactic.positivity_dist
end
@[simp]
theorem abs_dist {a b : α} : |dist a b| = dist a b :=
abs_of_nonneg dist_nonneg
#align abs_dist abs_dist
/-- A version of `has_dist` that takes value in `ℝ≥0`. -/
class HasNndist (α : Type _) where
nndist : α → α → ℝ≥0
#align has_nndist HasNndist
export HasNndist (nndist)
-- see Note [lower instance priority]
/-- Distance as a nonnegative real number. -/
instance (priority := 100) PseudoMetricSpace.toHasNndist : HasNndist α :=
⟨fun a b => ⟨dist a b, dist_nonneg⟩⟩
#align pseudo_metric_space.to_has_nndist PseudoMetricSpace.toHasNndist
/-- Express `nndist` in terms of `edist`-/
theorem nndist_edist (x y : α) : nndist x y = (edist x y).toNnreal := by
simp [nndist, edist_dist, Real.toNnreal, max_eq_left dist_nonneg, Ennreal.ofReal]
#align nndist_edist nndist_edist
/-- Express `edist` in terms of `nndist`-/
theorem edist_nndist (x y : α) : edist x y = ↑(nndist x y) := by
simpa only [edist_dist, Ennreal.ofReal_eq_coe_nnreal dist_nonneg]
#align edist_nndist edist_nndist
@[simp, norm_cast]
theorem coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y :=
(edist_nndist x y).symm
#align coe_nnreal_ennreal_nndist coe_nnreal_ennreal_nndist
@[simp, norm_cast]
theorem edist_lt_coe {x y : α} {c : ℝ≥0} : edist x y < c ↔ nndist x y < c := by
rw [edist_nndist, Ennreal.coe_lt_coe]
#align edist_lt_coe edist_lt_coe
@[simp, norm_cast]
theorem edist_le_coe {x y : α} {c : ℝ≥0} : edist x y ≤ c ↔ nndist x y ≤ c := by
rw [edist_nndist, Ennreal.coe_le_coe]
#align edist_le_coe edist_le_coe
/-- In a pseudometric space, the extended distance is always finite-/
theorem edist_lt_top {α : Type _} [PseudoMetricSpace α] (x y : α) : edist x y < ⊤ :=
(edist_dist x y).symm ▸ Ennreal.ofReal_lt_top
#align edist_lt_top edist_lt_top
/-- In a pseudometric space, the extended distance is always finite-/
theorem edist_ne_top (x y : α) : edist x y ≠ ⊤ :=
(edist_lt_top x y).Ne
#align edist_ne_top edist_ne_top
/-- `nndist x x` vanishes-/
@[simp]
theorem nndist_self (a : α) : nndist a a = 0 :=
(Nnreal.coe_eq_zero _).1 (dist_self a)
#align nndist_self nndist_self
/-- Express `dist` in terms of `nndist`-/
theorem dist_nndist (x y : α) : dist x y = ↑(nndist x y) :=
rfl
#align dist_nndist dist_nndist
@[simp, norm_cast]
theorem coe_nndist (x y : α) : ↑(nndist x y) = dist x y :=
(dist_nndist x y).symm
#align coe_nndist coe_nndist
@[simp, norm_cast]
theorem dist_lt_coe {x y : α} {c : ℝ≥0} : dist x y < c ↔ nndist x y < c :=
Iff.rfl
#align dist_lt_coe dist_lt_coe
@[simp, norm_cast]
theorem dist_le_coe {x y : α} {c : ℝ≥0} : dist x y ≤ c ↔ nndist x y ≤ c :=
Iff.rfl
#align dist_le_coe dist_le_coe
@[simp]
theorem edist_lt_ofReal {x y : α} {r : ℝ} : edist x y < Ennreal.ofReal r ↔ dist x y < r := by
rw [edist_dist, Ennreal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg]
#align edist_lt_of_real edist_lt_ofReal
@[simp]
theorem edist_le_ofReal {x y : α} {r : ℝ} (hr : 0 ≤ r) :
edist x y ≤ Ennreal.ofReal r ↔ dist x y ≤ r := by
rw [edist_dist, Ennreal.ofReal_le_ofReal_iff hr]
#align edist_le_of_real edist_le_ofReal
/-- Express `nndist` in terms of `dist`-/
theorem nndist_dist (x y : α) : nndist x y = Real.toNnreal (dist x y) := by
rw [dist_nndist, Real.toNnreal_coe]
#align nndist_dist nndist_dist
theorem nndist_comm (x y : α) : nndist x y = nndist y x := by
simpa only [dist_nndist, Nnreal.coe_eq] using dist_comm x y
#align nndist_comm nndist_comm
/-- Triangle inequality for the nonnegative distance-/
theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=
dist_triangle _ _ _
#align nndist_triangle nndist_triangle
theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=
dist_triangle_left _ _ _
#align nndist_triangle_left nndist_triangle_left
theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=
dist_triangle_right _ _ _
#align nndist_triangle_right nndist_triangle_right
/-- Express `dist` in terms of `edist`-/
theorem dist_edist (x y : α) : dist x y = (edist x y).toReal := by
rw [edist_dist, Ennreal.toReal_ofReal dist_nonneg]
#align dist_edist dist_edist
namespace Metric
-- instantiate pseudometric space as a topology
variable {x y z : α} {δ ε ε₁ ε₂ : ℝ} {s : Set α}
/-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/
def ball (x : α) (ε : ℝ) : Set α :=
{ y | dist y x < ε }
#align metric.ball Metric.ball
@[simp]
theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε :=
Iff.rfl
#align metric.mem_ball Metric.mem_ball
theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw [dist_comm, mem_ball]
#align metric.mem_ball' Metric.mem_ball'
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε :=
dist_nonneg.trans_lt hy
#align metric.pos_of_mem_ball Metric.pos_of_mem_ball
theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε :=
show dist x x < ε by rw [dist_self] <;> assumption
#align metric.mem_ball_self Metric.mem_ball_self
@[simp]
theorem nonempty_ball : (ball x ε).Nonempty ↔ 0 < ε :=
⟨fun ⟨x, hx⟩ => pos_of_mem_ball hx, fun h => ⟨x, mem_ball_self h⟩⟩
#align metric.nonempty_ball Metric.nonempty_ball
@[simp]
theorem ball_eq_empty : ball x ε = ∅ ↔ ε ≤ 0 := by
rw [← not_nonempty_iff_eq_empty, nonempty_ball, not_lt]
#align metric.ball_eq_empty Metric.ball_eq_empty
@[simp]
theorem ball_zero : ball x 0 = ∅ := by rw [ball_eq_empty]
#align metric.ball_zero Metric.ball_zero
/-- If a point belongs to an open ball, then there is a strictly smaller radius whose ball also
contains it.
See also `exists_lt_subset_ball`. -/
theorem exists_lt_mem_ball_of_mem_ball (h : x ∈ ball y ε) : ∃ ε' < ε, x ∈ ball y ε' :=
by
simp only [mem_ball] at h⊢
exact ⟨(ε + dist x y) / 2, by linarith, by linarith⟩
#align metric.exists_lt_mem_ball_of_mem_ball Metric.exists_lt_mem_ball_of_mem_ball
theorem ball_eq_ball (ε : ℝ) (x : α) :
UniformSpace.ball x { p | dist p.2 p.1 < ε } = Metric.ball x ε :=
rfl
#align metric.ball_eq_ball Metric.ball_eq_ball
theorem ball_eq_ball' (ε : ℝ) (x : α) :
UniformSpace.ball x { p | dist p.1 p.2 < ε } = Metric.ball x ε :=
by
ext
simp [dist_comm, UniformSpace.ball]
#align metric.ball_eq_ball' Metric.ball_eq_ball'
@[simp]
theorem unionᵢ_ball_nat (x : α) : (⋃ n : ℕ, ball x n) = univ :=
unionᵢ_eq_univ_iff.2 fun y => exists_nat_gt (dist y x)
#align metric.Union_ball_nat Metric.unionᵢ_ball_nat
@[simp]
theorem unionᵢ_ball_nat_succ (x : α) : (⋃ n : ℕ, ball x (n + 1)) = univ :=
unionᵢ_eq_univ_iff.2 fun y => (exists_nat_gt (dist y x)).imp fun n hn => hn.trans (lt_add_one _)
#align metric.Union_ball_nat_succ Metric.unionᵢ_ball_nat_succ
/-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/
def closedBall (x : α) (ε : ℝ) :=
{ y | dist y x ≤ ε }
#align metric.closed_ball Metric.closedBall
@[simp]
theorem mem_closedBall : y ∈ closedBall x ε ↔ dist y x ≤ ε :=
Iff.rfl
#align metric.mem_closed_ball Metric.mem_closedBall
theorem mem_closed_ball' : y ∈ closedBall x ε ↔ dist x y ≤ ε := by rw [dist_comm, mem_closed_ball]
#align metric.mem_closed_ball' Metric.mem_closed_ball'
/-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/
def sphere (x : α) (ε : ℝ) :=
{ y | dist y x = ε }
#align metric.sphere Metric.sphere
@[simp]
theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε :=
Iff.rfl
#align metric.mem_sphere Metric.mem_sphere
theorem mem_sphere' : y ∈ sphere x ε ↔ dist x y = ε := by rw [dist_comm, mem_sphere]
#align metric.mem_sphere' Metric.mem_sphere'
theorem ne_of_mem_sphere (h : y ∈ sphere x ε) (hε : ε ≠ 0) : y ≠ x :=
by
contrapose! hε
symm
simpa [hε] using h
#align metric.ne_of_mem_sphere Metric.ne_of_mem_sphere
theorem sphere_eq_empty_of_subsingleton [Subsingleton α] (hε : ε ≠ 0) : sphere x ε = ∅ :=
Set.eq_empty_iff_forall_not_mem.mpr fun y hy => ne_of_mem_sphere hy hε (Subsingleton.elim _ _)
#align metric.sphere_eq_empty_of_subsingleton Metric.sphere_eq_empty_of_subsingleton
theorem sphere_isEmpty_of_subsingleton [Subsingleton α] (hε : ε ≠ 0) : IsEmpty (sphere x ε) := by
simp only [sphere_eq_empty_of_subsingleton hε, Set.hasEmptyc.Emptyc.isEmpty α]
#align metric.sphere_is_empty_of_subsingleton Metric.sphere_isEmpty_of_subsingleton
theorem mem_closedBall_self (h : 0 ≤ ε) : x ∈ closedBall x ε :=
show dist x x ≤ ε by rw [dist_self] <;> assumption
#align metric.mem_closed_ball_self Metric.mem_closedBall_self
@[simp]
theorem nonempty_closedBall : (closedBall x ε).Nonempty ↔ 0 ≤ ε :=
⟨fun ⟨x, hx⟩ => dist_nonneg.trans hx, fun h => ⟨x, mem_closedBall_self h⟩⟩
#align metric.nonempty_closed_ball Metric.nonempty_closedBall
@[simp]
theorem closedBall_eq_empty : closedBall x ε = ∅ ↔ ε < 0 := by
rw [← not_nonempty_iff_eq_empty, nonempty_closed_ball, not_le]
#align metric.closed_ball_eq_empty Metric.closedBall_eq_empty
theorem ball_subset_closedBall : ball x ε ⊆ closedBall x ε := fun y (hy : _ < _) => le_of_lt hy
#align metric.ball_subset_closed_ball Metric.ball_subset_closedBall
theorem sphere_subset_closedBall : sphere x ε ⊆ closedBall x ε := fun y => le_of_eq
#align metric.sphere_subset_closed_ball Metric.sphere_subset_closedBall
theorem closedBall_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (closedBall x δ) (ball y ε) :=
Set.disjoint_left.mpr fun a ha1 ha2 =>
(h.trans <| dist_triangle_left _ _ _).not_lt <| add_lt_add_of_le_of_lt ha1 ha2
#align metric.closed_ball_disjoint_ball Metric.closedBall_disjoint_ball
theorem ball_disjoint_closedBall (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (closedBall y ε) :=
(closed_ball_disjoint_ball <| by rwa [add_comm, dist_comm]).symm
#align metric.ball_disjoint_closed_ball Metric.ball_disjoint_closedBall
theorem ball_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (ball y ε) :=
(closedBall_disjoint_ball h).mono_left ball_subset_closedBall
#align metric.ball_disjoint_ball Metric.ball_disjoint_ball
theorem closedBall_disjoint_closedBall (h : δ + ε < dist x y) :
Disjoint (closedBall x δ) (closedBall y ε) :=
Set.disjoint_left.mpr fun a ha1 ha2 =>
h.not_le <| (dist_triangle_left _ _ _).trans <| add_le_add ha1 ha2
#align metric.closed_ball_disjoint_closed_ball Metric.closedBall_disjoint_closedBall
theorem sphere_disjoint_ball : Disjoint (sphere x ε) (ball x ε) :=
Set.disjoint_left.mpr fun y hy₁ hy₂ => absurd hy₁ <| ne_of_lt hy₂
#align metric.sphere_disjoint_ball Metric.sphere_disjoint_ball
@[simp]
theorem ball_union_sphere : ball x ε ∪ sphere x ε = closedBall x ε :=
Set.ext fun y => (@le_iff_lt_or_eq ℝ _ _ _).symm
#align metric.ball_union_sphere Metric.ball_union_sphere
@[simp]
theorem sphere_union_ball : sphere x ε ∪ ball x ε = closedBall x ε := by
rw [union_comm, ball_union_sphere]
#align metric.sphere_union_ball Metric.sphere_union_ball
@[simp]
theorem closedBall_diff_sphere : closedBall x ε \ sphere x ε = ball x ε := by
rw [← ball_union_sphere, Set.union_diff_cancel_right sphere_disjoint_ball.symm.le_bot]
#align metric.closed_ball_diff_sphere Metric.closedBall_diff_sphere
@[simp]
theorem closedBall_diff_ball : closedBall x ε \ ball x ε = sphere x ε := by
rw [← ball_union_sphere, Set.union_diff_cancel_left sphere_disjoint_ball.symm.le_bot]
#align metric.closed_ball_diff_ball Metric.closedBall_diff_ball
theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε := by rw [mem_ball', mem_ball]
#align metric.mem_ball_comm Metric.mem_ball_comm
theorem mem_closedBall_comm : x ∈ closedBall y ε ↔ y ∈ closedBall x ε := by
rw [mem_closed_ball', mem_closed_ball]
#align metric.mem_closed_ball_comm Metric.mem_closedBall_comm
theorem mem_sphere_comm : x ∈ sphere y ε ↔ y ∈ sphere x ε := by rw [mem_sphere', mem_sphere]
#align metric.mem_sphere_comm Metric.mem_sphere_comm
theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ := fun y (yx : _ < ε₁) =>
lt_of_lt_of_le yx h
#align metric.ball_subset_ball Metric.ball_subset_ball
theorem closedBall_eq_bInter_ball : closedBall x ε = ⋂ δ > ε, ball x δ := by
ext y <;> rw [mem_closed_ball, ← forall_lt_iff_le', mem_Inter₂] <;> rfl
#align metric.closed_ball_eq_bInter_ball Metric.closedBall_eq_bInter_ball
theorem ball_subset_ball' (h : ε₁ + dist x y ≤ ε₂) : ball x ε₁ ⊆ ball y ε₂ := fun z hz =>
calc
dist z y ≤ dist z x + dist x y := dist_triangle _ _ _
_ < ε₁ + dist x y := add_lt_add_right hz _
_ ≤ ε₂ := h
#align metric.ball_subset_ball' Metric.ball_subset_ball'
theorem closedBall_subset_closedBall (h : ε₁ ≤ ε₂) : closedBall x ε₁ ⊆ closedBall x ε₂ :=
fun y (yx : _ ≤ ε₁) => le_trans yx h
#align metric.closed_ball_subset_closed_ball Metric.closedBall_subset_closedBall
theorem closedBall_subset_closed_ball' (h : ε₁ + dist x y ≤ ε₂) :
closedBall x ε₁ ⊆ closedBall y ε₂ := fun z hz =>
calc
dist z y ≤ dist z x + dist x y := dist_triangle _ _ _
_ ≤ ε₁ + dist x y := add_le_add_right hz _
_ ≤ ε₂ := h
#align metric.closed_ball_subset_closed_ball' Metric.closedBall_subset_closed_ball'
theorem closedBall_subset_ball (h : ε₁ < ε₂) : closedBall x ε₁ ⊆ ball x ε₂ :=
fun y (yh : dist y x ≤ ε₁) => lt_of_le_of_lt yh h
#align metric.closed_ball_subset_ball Metric.closedBall_subset_ball
theorem closedBall_subset_ball' (h : ε₁ + dist x y < ε₂) : closedBall x ε₁ ⊆ ball y ε₂ :=
fun z hz =>
calc
dist z y ≤ dist z x + dist x y := dist_triangle _ _ _
_ ≤ ε₁ + dist x y := add_le_add_right hz _
_ < ε₂ := h
#align metric.closed_ball_subset_ball' Metric.closedBall_subset_ball'
theorem dist_le_add_of_nonempty_closedBall_inter_closedBall
(h : (closedBall x ε₁ ∩ closedBall y ε₂).Nonempty) : dist x y ≤ ε₁ + ε₂ :=
let ⟨z, hz⟩ := h
calc
dist x y ≤ dist z x + dist z y := dist_triangle_left _ _ _
_ ≤ ε₁ + ε₂ := add_le_add hz.1 hz.2
#align metric.dist_le_add_of_nonempty_closed_ball_inter_closed_ball Metric.dist_le_add_of_nonempty_closedBall_inter_closedBall
theorem dist_lt_add_of_nonempty_closedBall_inter_ball (h : (closedBall x ε₁ ∩ ball y ε₂).Nonempty) :
dist x y < ε₁ + ε₂ :=
let ⟨z, hz⟩ := h
calc
dist x y ≤ dist z x + dist z y := dist_triangle_left _ _ _
_ < ε₁ + ε₂ := add_lt_add_of_le_of_lt hz.1 hz.2
#align metric.dist_lt_add_of_nonempty_closed_ball_inter_ball Metric.dist_lt_add_of_nonempty_closedBall_inter_ball
theorem dist_lt_add_of_nonempty_ball_inter_closedBall (h : (ball x ε₁ ∩ closedBall y ε₂).Nonempty) :
dist x y < ε₁ + ε₂ := by
rw [inter_comm] at h
rw [add_comm, dist_comm]
exact dist_lt_add_of_nonempty_closed_ball_inter_ball h
#align metric.dist_lt_add_of_nonempty_ball_inter_closed_ball Metric.dist_lt_add_of_nonempty_ball_inter_closedBall
theorem dist_lt_add_of_nonempty_ball_inter_ball (h : (ball x ε₁ ∩ ball y ε₂).Nonempty) :
dist x y < ε₁ + ε₂ :=
dist_lt_add_of_nonempty_closed_ball_inter_ball <|
h.mono (inter_subset_inter ball_subset_closedBall Subset.rfl)
#align metric.dist_lt_add_of_nonempty_ball_inter_ball Metric.dist_lt_add_of_nonempty_ball_inter_ball
@[simp]
theorem unionᵢ_closedBall_nat (x : α) : (⋃ n : ℕ, closedBall x n) = univ :=
unionᵢ_eq_univ_iff.2 fun y => exists_nat_ge (dist y x)
#align metric.Union_closed_ball_nat Metric.unionᵢ_closedBall_nat
theorem unionᵢ_inter_closedBall_nat (s : Set α) (x : α) : (⋃ n : ℕ, s ∩ closedBall x n) = s := by
rw [← inter_Union, Union_closed_ball_nat, inter_univ]
#align metric.Union_inter_closed_ball_nat Metric.unionᵢ_inter_closedBall_nat
theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ := fun z zx => by
rw [← add_sub_cancel'_right ε₁ ε₂] <;>
exact lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)
#align metric.ball_subset Metric.ball_subset
theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε :=
ball_subset <| by rw [sub_self_div_two] <;> exact le_of_lt h
#align metric.ball_half_subset Metric.ball_half_subset
theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=
⟨_, sub_pos.2 h, ball_subset <| by rw [sub_sub_self]⟩
#align metric.exists_ball_subset_ball Metric.exists_ball_subset_ball
/-- If a property holds for all points in closed balls of arbitrarily large radii, then it holds for
all points. -/
theorem forall_of_forall_mem_closedBall (p : α → Prop) (x : α)
(H : ∃ᶠ R : ℝ in at_top, ∀ y ∈ closedBall x R, p y) (y : α) : p y :=
by
obtain ⟨R, hR, h⟩ : ∃ (R : ℝ)(H : dist y x ≤ R), ∀ z : α, z ∈ closed_ball x R → p z :=
frequently_iff.1 H (Ici_mem_at_top (dist y x))
exact h _ hR
#align metric.forall_of_forall_mem_closed_ball Metric.forall_of_forall_mem_closedBall
/-- If a property holds for all points in balls of arbitrarily large radii, then it holds for all
points. -/
theorem forall_of_forall_mem_ball (p : α → Prop) (x : α)
(H : ∃ᶠ R : ℝ in at_top, ∀ y ∈ ball x R, p y) (y : α) : p y :=
by
obtain ⟨R, hR, h⟩ : ∃ (R : ℝ)(H : dist y x < R), ∀ z : α, z ∈ ball x R → p z :=
frequently_iff.1 H (Ioi_mem_at_top (dist y x))
exact h _ hR
#align metric.forall_of_forall_mem_ball Metric.forall_of_forall_mem_ball
theorem isBounded_iff {s : Set α} :
IsBounded s ↔ ∃ C : ℝ, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C := by
rw [is_bounded_def, ← Filter.mem_sets, (@PseudoMetricSpace.cobounded_sets α _).out, mem_set_of_eq,
compl_compl]
#align metric.is_bounded_iff Metric.isBounded_iff
theorem isBounded_iff_eventually {s : Set α} :
IsBounded s ↔ ∀ᶠ C in at_top, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C :=
isBounded_iff.trans
⟨fun ⟨C, h⟩ => eventually_atTop.2 ⟨C, fun C' hC' x hx y hy => (h hx hy).trans hC'⟩,
Eventually.exists⟩
#align metric.is_bounded_iff_eventually Metric.isBounded_iff_eventually
theorem isBounded_iff_exists_ge {s : Set α} (c : ℝ) :
IsBounded s ↔ ∃ C, c ≤ C ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C :=
⟨fun h => ((eventually_ge_atTop c).And (isBounded_iff_eventually.1 h)).exists, fun h =>
isBounded_iff.2 <| h.imp fun _ => And.right⟩
#align metric.is_bounded_iff_exists_ge Metric.isBounded_iff_exists_ge
theorem isBounded_iff_nndist {s : Set α} :
IsBounded s ↔ ∃ C : ℝ≥0, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → nndist x y ≤ C := by
simp only [is_bounded_iff_exists_ge 0, Nnreal.exists, ← Nnreal.coe_le_coe, ← dist_nndist,
Nnreal.coe_mk, exists_prop]
#align metric.is_bounded_iff_nndist Metric.isBounded_iff_nndist
theorem uniformity_basis_dist :
(𝓤 α).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : α × α | dist p.1 p.2 < ε } :=
by
rw [← pseudo_metric_space.uniformity_dist.symm]
refine' has_basis_binfi_principal _ nonempty_Ioi
exact fun r (hr : 0 < r) p (hp : 0 < p) =>
⟨min r p, lt_min hr hp, fun x (hx : dist _ _ < _) => lt_of_lt_of_le hx (min_le_left r p),
fun x (hx : dist _ _ < _) => lt_of_lt_of_le hx (min_le_right r p)⟩
#align metric.uniformity_basis_dist Metric.uniformity_basis_dist
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`.
For specific bases see `uniformity_basis_dist`, `uniformity_basis_dist_inv_nat_succ`,
and `uniformity_basis_dist_inv_nat_pos`. -/
protected theorem mk_uniformity_basis {β : Type _} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ i, p i → 0 < f i) (hf : ∀ ⦃ε⦄, 0 < ε → ∃ (i : _)(hi : p i), f i ≤ ε) :
(𝓤 α).HasBasis p fun i => { p : α × α | dist p.1 p.2 < f i } :=
by
refine' ⟨fun s => uniformity_basis_dist.mem_iff.trans _⟩
constructor
· rintro ⟨ε, ε₀, hε⟩
obtain ⟨i, hi, H⟩ : ∃ (i : _)(hi : p i), f i ≤ ε
exact hf ε₀
exact ⟨i, hi, fun x (hx : _ < _) => hε <| lt_of_lt_of_le hx H⟩
· exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, H⟩
#align metric.mk_uniformity_basis Metric.mk_uniformity_basis
theorem uniformity_basis_dist_inv_nat_succ :
(𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 < 1 / (↑n + 1) } :=
Metric.mk_uniformity_basis (fun n _ => div_pos zero_lt_one <| Nat.cast_add_one_pos n) fun ε ε0 =>
(exists_nat_one_div_lt ε0).imp fun n hn => ⟨trivial, le_of_lt hn⟩
#align metric.uniformity_basis_dist_inv_nat_succ Metric.uniformity_basis_dist_inv_nat_succ
theorem uniformity_basis_dist_inv_nat_pos :
(𝓤 α).HasBasis (fun n : ℕ => 0 < n) fun n : ℕ => { p : α × α | dist p.1 p.2 < 1 / ↑n } :=
Metric.mk_uniformity_basis (fun n hn => div_pos zero_lt_one <| Nat.cast_pos.2 hn) fun ε ε0 =>
let ⟨n, hn⟩ := exists_nat_one_div_lt ε0
⟨n + 1, Nat.succ_pos n, by exact_mod_cast hn.le⟩
#align metric.uniformity_basis_dist_inv_nat_pos Metric.uniformity_basis_dist_inv_nat_pos
theorem uniformity_basis_dist_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) :
(𝓤 α).HasBasis (fun n : ℕ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 < r ^ n } :=
Metric.mk_uniformity_basis (fun n hn => pow_pos h0 _) fun ε ε0 =>
let ⟨n, hn⟩ := exists_pow_lt_of_lt_one ε0 h1
⟨n, trivial, hn.le⟩
#align metric.uniformity_basis_dist_pow Metric.uniformity_basis_dist_pow
theorem uniformity_basis_dist_lt {R : ℝ} (hR : 0 < R) :
(𝓤 α).HasBasis (fun r : ℝ => 0 < r ∧ r < R) fun r => { p : α × α | dist p.1 p.2 < r } :=
Metric.mk_uniformity_basis (fun r => And.left) fun r hr =>
⟨min r (R / 2), ⟨lt_min hr (half_pos hR), min_lt_iff.2 <| Or.inr (half_lt_self hR)⟩,
min_le_left _ _⟩
#align metric.uniformity_basis_dist_lt Metric.uniformity_basis_dist_lt
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then closed neighborhoods of the diagonal of sizes `{f i | p i}`
form a basis of `𝓤 α`.
Currently we have only one specific basis `uniformity_basis_dist_le` based on this constructor.
More can be easily added if needed in the future. -/
protected theorem mk_uniformity_basis_le {β : Type _} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ (x : _)(hx : p x), f x ≤ ε) :
(𝓤 α).HasBasis p fun x => { p : α × α | dist p.1 p.2 ≤ f x } :=
by
refine' ⟨fun s => uniformity_basis_dist.mem_iff.trans _⟩
constructor
· rintro ⟨ε, ε₀, hε⟩
rcases exists_between ε₀ with ⟨ε', hε'⟩
rcases hf ε' hε'.1 with ⟨i, hi, H⟩
exact ⟨i, hi, fun x (hx : _ ≤ _) => hε <| lt_of_le_of_lt (le_trans hx H) hε'.2⟩
· exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, fun x (hx : _ < _) => H (le_of_lt hx)⟩
#align metric.mk_uniformity_basis_le Metric.mk_uniformity_basis_le
/-- Contant size closed neighborhoods of the diagonal form a basis
of the uniformity filter. -/
theorem uniformity_basis_dist_le :
(𝓤 α).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : α × α | dist p.1 p.2 ≤ ε } :=
Metric.mk_uniformity_basis_le (fun _ => id) fun ε ε₀ => ⟨ε, ε₀, le_refl ε⟩
#align metric.uniformity_basis_dist_le Metric.uniformity_basis_dist_le
theorem uniformity_basis_dist_le_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) :
(𝓤 α).HasBasis (fun n : ℕ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 ≤ r ^ n } :=
Metric.mk_uniformity_basis_le (fun n hn => pow_pos h0 _) fun ε ε0 =>
let ⟨n, hn⟩ := exists_pow_lt_of_lt_one ε0 h1
⟨n, trivial, hn.le⟩
#align metric.uniformity_basis_dist_le_pow Metric.uniformity_basis_dist_le_pow
theorem mem_uniformity_dist {s : Set (α × α)} :
s ∈ 𝓤 α ↔ ∃ ε > 0, ∀ {a b : α}, dist a b < ε → (a, b) ∈ s :=
uniformity_basis_dist.mem_uniformity_iff
#align metric.mem_uniformity_dist Metric.mem_uniformity_dist
/-- A constant size neighborhood of the diagonal is an entourage. -/
theorem dist_mem_uniformity {ε : ℝ} (ε0 : 0 < ε) : { p : α × α | dist p.1 p.2 < ε } ∈ 𝓤 α :=
mem_uniformity_dist.2 ⟨ε, ε0, fun a b => id⟩
#align metric.dist_mem_uniformity Metric.dist_mem_uniformity
theorem uniformContinuous_iff [PseudoMetricSpace β] {f : α → β} :
UniformContinuous f ↔ ∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε :=
uniformity_basis_dist.uniform_continuous_iff uniformity_basis_dist
#align metric.uniform_continuous_iff Metric.uniformContinuous_iff
/- ./././Mathport/Syntax/Translate/Basic.lean:632:2: warning: expanding binder collection (x y «expr ∈ » s) -/
theorem uniformContinuousOn_iff [PseudoMetricSpace β] {f : α → β} {s : Set α} :
UniformContinuousOn f s ↔
∀ ε > 0, ∃ δ > 0, ∀ (x) (_ : x ∈ s) (y) (_ : y ∈ s), dist x y < δ → dist (f x) (f y) < ε :=
Metric.uniformity_basis_dist.uniform_continuous_on_iff Metric.uniformity_basis_dist
#align metric.uniform_continuous_on_iff Metric.uniformContinuousOn_iff
/- ./././Mathport/Syntax/Translate/Basic.lean:632:2: warning: expanding binder collection (x y «expr ∈ » s) -/
theorem uniformContinuousOn_iff_le [PseudoMetricSpace β] {f : α → β} {s : Set α} :
UniformContinuousOn f s ↔
∀ ε > 0, ∃ δ > 0, ∀ (x) (_ : x ∈ s) (y) (_ : y ∈ s), dist x y ≤ δ → dist (f x) (f y) ≤ ε :=
Metric.uniformity_basis_dist_le.uniform_continuous_on_iff Metric.uniformity_basis_dist_le
#align metric.uniform_continuous_on_iff_le Metric.uniformContinuousOn_iff_le
theorem uniformEmbedding_iff [PseudoMetricSpace β] {f : α → β} :
UniformEmbedding f ↔
Function.Injective f ∧
UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=
uniformEmbedding_def'.trans <|
and_congr Iff.rfl <|
and_congr Iff.rfl
⟨fun H δ δ0 =>
let ⟨t, tu, ht⟩ := H _ (dist_mem_uniformity δ0)
let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 tu
⟨ε, ε0, fun a b h => ht _ _ (hε h)⟩,
fun H s su =>
let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 su
let ⟨ε, ε0, hε⟩ := H _ δ0
⟨_, dist_mem_uniformity ε0, fun a b h => hδ (hε h)⟩⟩
#align metric.uniform_embedding_iff Metric.uniformEmbedding_iff
/-- If a map between pseudometric spaces is a uniform embedding then the distance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y`. -/
theorem controlled_of_uniformEmbedding [PseudoMetricSpace β] {f : α → β} :
UniformEmbedding f →
(∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε) ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=
by
intro h
exact ⟨uniformContinuous_iff.1 (uniform_embedding_iff.1 h).2.1, (uniform_embedding_iff.1 h).2.2⟩
#align metric.controlled_of_uniform_embedding Metric.controlled_of_uniformEmbedding
theorem totallyBounded_iff {s : Set α} :
TotallyBounded s ↔ ∀ ε > 0, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, ball y ε :=
⟨fun H ε ε0 => H _ (dist_mem_uniformity ε0), fun H r ru =>
let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru
let ⟨t, ft, h⟩ := H ε ε0
⟨t, ft, h.trans <| Union₂_mono fun y yt z => hε⟩⟩
#align metric.totally_bounded_iff Metric.totallyBounded_iff
/-- A pseudometric space is totally bounded if one can reconstruct up to any ε>0 any element of the
space from finitely many data. -/
theorem totallyBounded_of_finite_discretization {s : Set α}
(H :
∀ ε > (0 : ℝ),
∃ (β : Type u)(_ : Fintype β)(F : s → β), ∀ x y, F x = F y → dist (x : α) y < ε) :
TotallyBounded s := by
cases' s.eq_empty_or_nonempty with hs hs
· rw [hs]
exact totallyBounded_empty
rcases hs with ⟨x0, hx0⟩
haveI : Inhabited s := ⟨⟨x0, hx0⟩⟩
refine' totally_bounded_iff.2 fun ε ε0 => _
rcases H ε ε0 with ⟨β, fβ, F, hF⟩
skip
let Finv := Function.invFun F
refine' ⟨range (Subtype.val ∘ Finv), finite_range _, fun x xs => _⟩
let x' := Finv (F ⟨x, xs⟩)
have : F x' = F ⟨x, xs⟩ := Function.invFun_eq ⟨⟨x, xs⟩, rfl⟩
simp only [Set.mem_unionᵢ, Set.mem_range]
exact ⟨_, ⟨F ⟨x, xs⟩, rfl⟩, hF _ _ this.symm⟩
#align metric.totally_bounded_of_finite_discretization Metric.totallyBounded_of_finite_discretization
/- ./././Mathport/Syntax/Translate/Basic.lean:632:2: warning: expanding binder collection (t «expr ⊆ » s) -/
theorem finite_approx_of_totallyBounded {s : Set α} (hs : TotallyBounded s) :
∀ ε > 0, ∃ (t : _)(_ : t ⊆ s), Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y ε :=
by
intro ε ε_pos
rw [totallyBounded_iff_subset] at hs
exact hs _ (dist_mem_uniformity ε_pos)
#align metric.finite_approx_of_totally_bounded Metric.finite_approx_of_totallyBounded
/-- Expressing uniform convergence using `dist` -/
theorem tendstoUniformlyOnFilter_iff {ι : Type _} {F : ι → β → α} {f : β → α} {p : Filter ι}
{p' : Filter β} :
TendstoUniformlyOnFilter F f p p' ↔
∀ ε > 0, ∀ᶠ n : ι × β in p ×ᶠ p', dist (f n.snd) (F n.fst n.snd) < ε :=
by
refine' ⟨fun H ε hε => H _ (dist_mem_uniformity hε), fun H u hu => _⟩
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩
refine' (H ε εpos).mono fun n hn => hε hn
#align metric.tendsto_uniformly_on_filter_iff Metric.tendstoUniformlyOnFilter_iff
/-- Expressing locally uniform convergence on a set using `dist`. -/
theorem tendstoLocallyUniformlyOn_iff {ι : Type _} [TopologicalSpace β] {F : ι → β → α} {f : β → α}
{p : Filter ι} {s : Set β} :
TendstoLocallyUniformlyOn F f p s ↔
∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε :=
by
refine' ⟨fun H ε hε => H _ (dist_mem_uniformity hε), fun H u hu x hx => _⟩
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩
rcases H ε εpos x hx with ⟨t, ht, Ht⟩
exact ⟨t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩
#align metric.tendsto_locally_uniformly_on_iff Metric.tendstoLocallyUniformlyOn_iff
/-- Expressing uniform convergence on a set using `dist`. -/
theorem tendstoUniformlyOn_iff {ι : Type _} {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} :
TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, dist (f x) (F n x) < ε :=
by
refine' ⟨fun H ε hε => H _ (dist_mem_uniformity hε), fun H u hu => _⟩
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩
exact (H ε εpos).mono fun n hs x hx => hε (hs x hx)
#align metric.tendsto_uniformly_on_iff Metric.tendstoUniformlyOn_iff
/-- Expressing locally uniform convergence using `dist`. -/
theorem tendstoLocallyUniformly_iff {ι : Type _} [TopologicalSpace β] {F : ι → β → α} {f : β → α}
{p : Filter ι} :
TendstoLocallyUniformly F f p ↔
∀ ε > 0, ∀ x : β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε :=
by
simp only [← tendstoLocallyUniformlyOn_univ, tendsto_locally_uniformly_on_iff, nhdsWithin_univ,
mem_univ, forall_const, exists_prop]
#align metric.tendsto_locally_uniformly_iff Metric.tendstoLocallyUniformly_iff
/-- Expressing uniform convergence using `dist`. -/
theorem tendstoUniformly_iff {ι : Type _} {F : ι → β → α} {f : β → α} {p : Filter ι} :
TendstoUniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, dist (f x) (F n x) < ε :=
by
rw [← tendstoUniformlyOn_univ, tendsto_uniformly_on_iff]
simp
#align metric.tendsto_uniformly_iff Metric.tendstoUniformly_iff
/- ./././Mathport/Syntax/Translate/Basic.lean:632:2: warning: expanding binder collection (x y «expr ∈ » t) -/
protected theorem cauchy_iff {f : Filter α} :
Cauchy f ↔ NeBot f ∧ ∀ ε > 0, ∃ t ∈ f, ∀ (x) (_ : x ∈ t) (y) (_ : y ∈ t), dist x y < ε :=
uniformity_basis_dist.cauchy_iff
#align metric.cauchy_iff Metric.cauchy_iff
theorem nhds_basis_ball : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) (ball x) :=
nhds_basis_uniformity uniformity_basis_dist
#align metric.nhds_basis_ball Metric.nhds_basis_ball
theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ ε > 0, ball x ε ⊆ s :=
nhds_basis_ball.mem_iff
#align metric.mem_nhds_iff Metric.mem_nhds_iff
theorem eventually_nhds_iff {p : α → Prop} :
(∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε > 0, ∀ ⦃y⦄, dist y x < ε → p y :=
mem_nhds_iff
#align metric.eventually_nhds_iff Metric.eventually_nhds_iff
theorem eventually_nhds_iff_ball {p : α → Prop} :
(∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε > 0, ∀ y ∈ ball x ε, p y :=
mem_nhds_iff
#align metric.eventually_nhds_iff_ball Metric.eventually_nhds_iff_ball
/-- A version of `filter.eventually_prod_iff` where the second filter consists of neighborhoods
in a pseudo-metric space.-/
theorem eventually_prod_nhds_iff {f : Filter ι} {x₀ : α} {p : ι × α → Prop} :
(∀ᶠ x in f ×ᶠ 𝓝 x₀, p x) ↔
∃ (pa : ι → Prop)(ha : ∀ᶠ i in f, pa i),
∃ ε > 0, ∀ {i}, pa i → ∀ {x}, dist x x₀ < ε → p (i, x) :=
by
simp_rw [eventually_prod_iff, Metric.eventually_nhds_iff]
refine' exists_congr fun q => exists_congr fun hq => _
constructor
· rintro ⟨r, ⟨ε, hε, hεr⟩, hp⟩
exact ⟨ε, hε, fun i hi x hx => hp hi <| hεr hx⟩
· rintro ⟨ε, hε, hp⟩
exact ⟨fun x => dist x x₀ < ε, ⟨ε, hε, fun y => id⟩, @hp⟩
#align metric.eventually_prod_nhds_iff Metric.eventually_prod_nhds_iff
/-- A version of `filter.eventually_prod_iff` where the first filter consists of neighborhoods
in a pseudo-metric space.-/
theorem eventually_nhds_prod_iff {ι α} [PseudoMetricSpace α] {f : Filter ι} {x₀ : α}
{p : α × ι → Prop} :
(∀ᶠ x in 𝓝 x₀ ×ᶠ f, p x) ↔
∃ ε > (0 : ℝ),
∃ (pa : ι → Prop)(ha : ∀ᶠ i in f, pa i), ∀ {x}, dist x x₀ < ε → ∀ {i}, pa i → p (x, i) :=
by
rw [eventually_swap_iff, Metric.eventually_prod_nhds_iff]
constructor <;>
· rintro ⟨a1, a2, a3, a4, a5⟩
refine' ⟨a3, a4, a1, a2, fun b1 b2 b3 b4 => a5 b4 b2⟩
#align metric.eventually_nhds_prod_iff Metric.eventually_nhds_prod_iff
theorem nhds_basis_closedBall : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) (closedBall x) :=
nhds_basis_uniformity uniformity_basis_dist_le
#align metric.nhds_basis_closed_ball Metric.nhds_basis_closedBall
theorem nhds_basis_ball_inv_nat_succ :
(𝓝 x).HasBasis (fun _ => True) fun n : ℕ => ball x (1 / (↑n + 1)) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_succ
#align metric.nhds_basis_ball_inv_nat_succ Metric.nhds_basis_ball_inv_nat_succ
theorem nhds_basis_ball_inv_nat_pos :
(𝓝 x).HasBasis (fun n => 0 < n) fun n : ℕ => ball x (1 / ↑n) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_pos
#align metric.nhds_basis_ball_inv_nat_pos Metric.nhds_basis_ball_inv_nat_pos
theorem nhds_basis_ball_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) :
(𝓝 x).HasBasis (fun n => True) fun n : ℕ => ball x (r ^ n) :=
nhds_basis_uniformity (uniformity_basis_dist_pow h0 h1)
#align metric.nhds_basis_ball_pow Metric.nhds_basis_ball_pow
theorem nhds_basis_closedBall_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) :
(𝓝 x).HasBasis (fun n => True) fun n : ℕ => closedBall x (r ^ n) :=
nhds_basis_uniformity (uniformity_basis_dist_le_pow h0 h1)
#align metric.nhds_basis_closed_ball_pow Metric.nhds_basis_closedBall_pow
theorem isOpen_iff : IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ball x ε ⊆ s := by
simp only [isOpen_iff_mem_nhds, mem_nhds_iff]
#align metric.is_open_iff Metric.isOpen_iff
theorem isOpen_ball : IsOpen (ball x ε) :=
isOpen_iff.2 fun y => exists_ball_subset_ball
#align metric.is_open_ball Metric.isOpen_ball
theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x :=
isOpen_ball.mem_nhds (mem_ball_self ε0)
#align metric.ball_mem_nhds Metric.ball_mem_nhds
theorem closedBall_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : closedBall x ε ∈ 𝓝 x :=
mem_of_superset (ball_mem_nhds x ε0) ball_subset_closedBall
#align metric.closed_ball_mem_nhds Metric.closedBall_mem_nhds
theorem closedBall_mem_nhds_of_mem {x c : α} {ε : ℝ} (h : x ∈ ball c ε) : closedBall c ε ∈ 𝓝 x :=
mem_of_superset (isOpen_ball.mem_nhds h) ball_subset_closedBall
#align metric.closed_ball_mem_nhds_of_mem Metric.closedBall_mem_nhds_of_mem
theorem nhdsWithin_basis_ball {s : Set α} :
(𝓝[s] x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => ball x ε ∩ s :=
nhdsWithin_hasBasis nhds_basis_ball s
#align metric.nhds_within_basis_ball Metric.nhdsWithin_basis_ball
theorem mem_nhdsWithin_iff {t : Set α} : s ∈ 𝓝[t] x ↔ ∃ ε > 0, ball x ε ∩ t ⊆ s :=
nhdsWithin_basis_ball.mem_iff
#align metric.mem_nhds_within_iff Metric.mem_nhdsWithin_iff
theorem tendsto_nhdsWithin_nhdsWithin [PseudoMetricSpace β] {t : Set β} {f : α → β} {a b} :
Tendsto f (𝓝[s] a) (𝓝[t] b) ↔
∀ ε > 0, ∃ δ > 0, ∀ {x : α}, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε :=
(nhdsWithin_basis_ball.tendsto_iff nhdsWithin_basis_ball).trans <|
forall₂_congr fun ε hε => exists₂_congr fun δ hδ => forall_congr' fun x => by simp <;> itauto
#align metric.tendsto_nhds_within_nhds_within Metric.tendsto_nhdsWithin_nhdsWithin
theorem tendsto_nhdsWithin_nhds [PseudoMetricSpace β] {f : α → β} {a b} :
Tendsto f (𝓝[s] a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀ {x : α}, x ∈ s → dist x a < δ → dist (f x) b < ε :=
by
rw [← nhdsWithin_univ b, tendsto_nhds_within_nhds_within]
simp only [mem_univ, true_and_iff]
#align metric.tendsto_nhds_within_nhds Metric.tendsto_nhdsWithin_nhds
theorem tendsto_nhds_nhds [PseudoMetricSpace β] {f : α → β} {a b} :
Tendsto f (𝓝 a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ {x : α}, dist x a < δ → dist (f x) b < ε :=
nhds_basis_ball.tendsto_iff nhds_basis_ball
#align metric.tendsto_nhds_nhds Metric.tendsto_nhds_nhds
theorem continuousAt_iff [PseudoMetricSpace β] {f : α → β} {a : α} :
ContinuousAt f a ↔ ∀ ε > 0, ∃ δ > 0, ∀ {x : α}, dist x a < δ → dist (f x) (f a) < ε := by
rw [ContinuousAt, tendsto_nhds_nhds]
#align metric.continuous_at_iff Metric.continuousAt_iff
theorem continuousWithinAt_iff [PseudoMetricSpace β] {f : α → β} {a : α} {s : Set α} :
ContinuousWithinAt f s a ↔
∀ ε > 0, ∃ δ > 0, ∀ {x : α}, x ∈ s → dist x a < δ → dist (f x) (f a) < ε :=
by rw [ContinuousWithinAt, tendsto_nhds_within_nhds]
#align metric.continuous_within_at_iff Metric.continuousWithinAt_iff
theorem continuousOn_iff [PseudoMetricSpace β] {f : α → β} {s : Set α} :
ContinuousOn f s ↔ ∀ b ∈ s, ∀ ε > 0, ∃ δ > 0, ∀ a ∈ s, dist a b < δ → dist (f a) (f b) < ε := by
simp [ContinuousOn, continuous_within_at_iff]
#align metric.continuous_on_iff Metric.continuousOn_iff
theorem continuous_iff [PseudoMetricSpace β] {f : α → β} :
Continuous f ↔ ∀ (b), ∀ ε > 0, ∃ δ > 0, ∀ a, dist a b < δ → dist (f a) (f b) < ε :=
continuous_iff_continuousAt.trans <| forall_congr' fun b => tendsto_nhds_nhds
#align metric.continuous_iff Metric.continuous_iff
theorem tendsto_nhds {f : Filter β} {u : β → α} {a : α} :
Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, dist (u x) a < ε :=
nhds_basis_ball.tendsto_right_iff
#align metric.tendsto_nhds Metric.tendsto_nhds
theorem continuousAt_iff' [TopologicalSpace β] {f : β → α} {b : β} :
ContinuousAt f b ↔ ∀ ε > 0, ∀ᶠ x in 𝓝 b, dist (f x) (f b) < ε := by
rw [ContinuousAt, tendsto_nhds]
#align metric.continuous_at_iff' Metric.continuousAt_iff'
theorem continuousWithinAt_iff' [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} :
ContinuousWithinAt f s b ↔ ∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε := by
rw [ContinuousWithinAt, tendsto_nhds]
#align metric.continuous_within_at_iff' Metric.continuousWithinAt_iff'
theorem continuousOn_iff' [TopologicalSpace β] {f : β → α} {s : Set β} :
ContinuousOn f s ↔ ∀ b ∈ s, ∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε := by
simp [ContinuousOn, continuous_within_at_iff']
#align metric.continuous_on_iff' Metric.continuousOn_iff'
theorem continuous_iff' [TopologicalSpace β] {f : β → α} :
Continuous f ↔ ∀ (a), ∀ ε > 0, ∀ᶠ x in 𝓝 a, dist (f x) (f a) < ε :=
continuous_iff_continuousAt.trans <| forall_congr' fun b => tendsto_nhds
#align metric.continuous_iff' Metric.continuous_iff'
theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {u : β → α} {a : α} :
Tendsto u atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, dist (u n) a < ε :=
(atTop_basis.tendsto_iff nhds_basis_ball).trans <|
by
simp only [exists_prop, true_and_iff]
rfl
#align metric.tendsto_at_top Metric.tendsto_atTop
/-- A variant of `tendsto_at_top` that
uses `∃ N, ∀ n > N, ...` rather than `∃ N, ∀ n ≥ N, ...`
-/
theorem tendsto_at_top' [Nonempty β] [SemilatticeSup β] [NoMaxOrder β] {u : β → α} {a : α} :
Tendsto u atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n > N, dist (u n) a < ε :=
(atTop_basis_ioi.tendsto_iff nhds_basis_ball).trans <|
by
simp only [exists_prop, true_and_iff]
rfl
#align metric.tendsto_at_top' Metric.tendsto_at_top'
theorem isOpen_singleton_iff {α : Type _} [PseudoMetricSpace α] {x : α} :
IsOpen ({x} : Set α) ↔ ∃ ε > 0, ∀ y, dist y x < ε → y = x := by
simp [is_open_iff, subset_singleton_iff, mem_ball]
#align metric.is_open_singleton_iff Metric.isOpen_singleton_iff
/-- Given a point `x` in a discrete subset `s` of a pseudometric space, there is an open ball
centered at `x` and intersecting `s` only at `x`. -/
theorem exists_ball_inter_eq_singleton_of_mem_discrete [DiscreteTopology s] {x : α} (hx : x ∈ s) :
∃ ε > 0, Metric.ball x ε ∩ s = {x} :=
nhds_basis_ball.exists_inter_eq_singleton_of_mem_discrete hx
#align metric.exists_ball_inter_eq_singleton_of_mem_discrete Metric.exists_ball_inter_eq_singleton_of_mem_discrete
/-- Given a point `x` in a discrete subset `s` of a pseudometric space, there is a closed ball
of positive radius centered at `x` and intersecting `s` only at `x`. -/
theorem exists_closedBall_inter_eq_singleton_of_discrete [DiscreteTopology s] {x : α} (hx : x ∈ s) :
∃ ε > 0, Metric.closedBall x ε ∩ s = {x} :=
nhds_basis_closedBall.exists_inter_eq_singleton_of_mem_discrete hx
#align metric.exists_closed_ball_inter_eq_singleton_of_discrete Metric.exists_closedBall_inter_eq_singleton_of_discrete
theorem Dense.exists_dist_lt {s : Set α} (hs : Dense s) (x : α) {ε : ℝ} (hε : 0 < ε) :
∃ y ∈ s, dist x y < ε :=
by
have : (ball x ε).Nonempty := by simp [hε]
simpa only [mem_ball'] using hs.exists_mem_open is_open_ball this
#align dense.exists_dist_lt Dense.exists_dist_lt
theorem DenseRange.exists_dist_lt {β : Type _} {f : β → α} (hf : DenseRange f) (x : α) {ε : ℝ}
(hε : 0 < ε) : ∃ y, dist x (f y) < ε :=
exists_range_iff.1 (hf.exists_dist_lt x hε)
#align dense_range.exists_dist_lt DenseRange.exists_dist_lt
end Metric
open Metric
/-Instantiate a pseudometric space as a pseudoemetric space. Before we can state the instance,
we need to show that the uniform structure coming from the edistance and the
distance coincide. -/
/-- Expressing the uniformity in terms of `edist` -/
protected theorem PseudoMetric.uniformity_basis_edist :
(𝓤 α).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => { p | edist p.1 p.2 < ε } :=
⟨by
intro t
refine' mem_uniformity_dist.trans ⟨_, _⟩ <;> rintro ⟨ε, ε0, Hε⟩
· use Ennreal.ofReal ε, Ennreal.ofReal_pos.2 ε0
rintro ⟨a, b⟩
simp only [edist_dist, Ennreal.ofReal_lt_ofReal_iff ε0]
exact Hε
· rcases Ennreal.lt_iff_exists_real_btwn.1 ε0 with ⟨ε', _, ε0', hε⟩
rw [Ennreal.ofReal_pos] at ε0'
refine' ⟨ε', ε0', fun a b h => Hε (lt_trans _ hε)⟩
rwa [edist_dist, Ennreal.ofReal_lt_ofReal_iff ε0']⟩
#align pseudo_metric.uniformity_basis_edist PseudoMetric.uniformity_basis_edist
theorem Metric.uniformity_edist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | edist p.1 p.2 < ε } :=
PseudoMetric.uniformity_basis_edist.eq_binfi
#align metric.uniformity_edist Metric.uniformity_edist
-- see Note [lower instance priority]
/-- A pseudometric space induces a pseudoemetric space -/
instance (priority := 100) PseudoMetricSpace.toPseudoEmetricSpace : PseudoEmetricSpace α :=
{ ‹PseudoMetricSpace α› with
edist := edist
edist_self := by simp [edist_dist]
edist_comm := by simp only [edist_dist, dist_comm] <;> simp
edist_triangle := fun x y z =>
by
simp only [edist_dist, ← Ennreal.ofReal_add, dist_nonneg]
rw [Ennreal.ofReal_le_ofReal_iff _]
· exact dist_triangle _ _ _
· simpa using add_le_add (dist_nonneg : 0 ≤ dist x y) dist_nonneg
uniformity_edist := Metric.uniformity_edist }
#align pseudo_metric_space.to_pseudo_emetric_space PseudoMetricSpace.toPseudoEmetricSpace
/-- In a pseudometric space, an open ball of infinite radius is the whole space -/
theorem Metric.eball_top_eq_univ (x : α) : Emetric.ball x ∞ = Set.univ :=
Set.eq_univ_iff_forall.mpr fun y => edist_lt_top y x
#align metric.eball_top_eq_univ Metric.eball_top_eq_univ
/-- Balls defined using the distance or the edistance coincide -/
@[simp]
theorem Metric.emetric_ball {x : α} {ε : ℝ} : Emetric.ball x (Ennreal.ofReal ε) = ball x ε :=
by
ext y
simp only [Emetric.mem_ball, mem_ball, edist_dist]
exact Ennreal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg
#align metric.emetric_ball Metric.emetric_ball
/-- Balls defined using the distance or the edistance coincide -/
@[simp]
theorem Metric.emetric_ball_nnreal {x : α} {ε : ℝ≥0} : Emetric.ball x ε = ball x ε :=
by
convert Metric.emetric_ball
simp
#align metric.emetric_ball_nnreal Metric.emetric_ball_nnreal
/-- Closed balls defined using the distance or the edistance coincide -/
theorem Metric.emetric_closedBall {x : α} {ε : ℝ} (h : 0 ≤ ε) :
Emetric.closedBall x (Ennreal.ofReal ε) = closedBall x ε := by
ext y <;> simp [edist_dist] <;> rw [Ennreal.ofReal_le_ofReal_iff h]
#align metric.emetric_closed_ball Metric.emetric_closedBall
/-- Closed balls defined using the distance or the edistance coincide -/
@[simp]
theorem Metric.emetric_closedBall_nnreal {x : α} {ε : ℝ≥0} :
Emetric.closedBall x ε = closedBall x ε :=
by
convert Metric.emetric_closedBall ε.2
simp
#align metric.emetric_closed_ball_nnreal Metric.emetric_closedBall_nnreal
@[simp]
theorem Metric.emetric_ball_top (x : α) : Emetric.ball x ⊤ = univ :=
eq_univ_of_forall fun y => edist_lt_top _ _
#align metric.emetric_ball_top Metric.emetric_ball_top
theorem Metric.inseparable_iff {x y : α} : Inseparable x y ↔ dist x y = 0 := by
rw [Emetric.inseparable_iff, edist_nndist, dist_nndist, Ennreal.coe_eq_zero, Nnreal.coe_eq_zero]
#align metric.inseparable_iff Metric.inseparable_iff
/-- Build a new pseudometric space from an old one where the bundled uniform structure is provably
(but typically non-definitionaly) equal to some given uniform structure.
See Note [forgetful inheritance].
-/
def PseudoMetricSpace.replaceUniformity {α} [U : UniformSpace α] (m : PseudoMetricSpace α)
(H : @uniformity _ U = @uniformity _ PseudoEmetricSpace.toUniformSpace) : PseudoMetricSpace α
where
dist := @dist _ m.toHasDist
dist_self := dist_self
dist_comm := dist_comm
dist_triangle := dist_triangle
edist := edist
edist_dist := edist_dist
toUniformSpace := U
uniformity_dist := H.trans PseudoMetricSpace.uniformity_dist
#align pseudo_metric_space.replace_uniformity PseudoMetricSpace.replaceUniformity
theorem PseudoMetricSpace.replaceUniformity_eq {α} [U : UniformSpace α] (m : PseudoMetricSpace α)
(H : @uniformity _ U = @uniformity _ PseudoEmetricSpace.toUniformSpace) :
m.replaceUniformity H = m := by
ext
rfl
#align pseudo_metric_space.replace_uniformity_eq PseudoMetricSpace.replaceUniformity_eq
/-- Build a new pseudo metric space from an old one where the bundled topological structure is
provably (but typically non-definitionaly) equal to some given topological structure.
See Note [forgetful inheritance].
-/
@[reducible]
def PseudoMetricSpace.replaceTopology {γ} [U : TopologicalSpace γ] (m : PseudoMetricSpace γ)
(H : U = m.toUniformSpace.toTopologicalSpace) : PseudoMetricSpace γ :=
@PseudoMetricSpace.replaceUniformity γ (m.toUniformSpace.replaceTopology H) m rfl
#align pseudo_metric_space.replace_topology PseudoMetricSpace.replaceTopology
theorem PseudoMetricSpace.replaceTopology_eq {γ} [U : TopologicalSpace γ] (m : PseudoMetricSpace γ)
(H : U = m.toUniformSpace.toTopologicalSpace) : m.replaceTopology H = m :=
by
ext
rfl
#align pseudo_metric_space.replace_topology_eq PseudoMetricSpace.replaceTopology_eq
/-- One gets a pseudometric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the pseudometric space and the pseudoemetric space. In this definition, the
distance is given separately, to be able to prescribe some expression which is not defeq to the
push-forward of the edistance to reals. -/
def PseudoEmetricSpace.toPseudoMetricSpaceOfDist {α : Type u} [e : PseudoEmetricSpace α]
(dist : α → α → ℝ) (edist_ne_top : ∀ x y : α, edist x y ≠ ⊤)
(h : ∀ x y, dist x y = Ennreal.toReal (edist x y)) : PseudoMetricSpace α :=
let m : PseudoMetricSpace α :=
{ dist
dist_self := fun x => by simp [h]
dist_comm := fun x y => by simp [h, PseudoEmetricSpace.edist_comm]
dist_triangle := fun x y z => by
simp only [h]
rw [← Ennreal.toReal_add (edist_ne_top _ _) (edist_ne_top _ _),
Ennreal.toReal_le_toReal (edist_ne_top _ _)]
· exact edist_triangle _ _ _
· simp [Ennreal.add_eq_top, edist_ne_top]
edist := edist
edist_dist := fun x y => by simp [h, Ennreal.ofReal_toReal, edist_ne_top] }
m.replaceUniformity <|
by
rw [uniformity_pseudoedist, Metric.uniformity_edist]
rfl
#align pseudo_emetric_space.to_pseudo_metric_space_of_dist PseudoEmetricSpace.toPseudoMetricSpaceOfDist
/-- One gets a pseudometric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the pseudometric space and the emetric space. -/
def PseudoEmetricSpace.toPseudoMetricSpace {α : Type u} [e : PseudoEmetricSpace α]
(h : ∀ x y : α, edist x y ≠ ⊤) : PseudoMetricSpace α :=
PseudoEmetricSpace.toPseudoMetricSpaceOfDist (fun x y => Ennreal.toReal (edist x y)) h fun x y =>
rfl
#align pseudo_emetric_space.to_pseudo_metric_space PseudoEmetricSpace.toPseudoMetricSpace
/-- Build a new pseudometric space from an old one where the bundled bornology structure is provably
(but typically non-definitionaly) equal to some given bornology structure.
See Note [forgetful inheritance].
-/
def PseudoMetricSpace.replaceBornology {α} [B : Bornology α] (m : PseudoMetricSpace α)
(H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) :
PseudoMetricSpace α :=
{ m with
toBornology := B
cobounded_sets :=
Set.ext <|
compl_surjective.forall.2 fun s =>
(H s).trans <| by rw [is_bounded_iff, mem_set_of_eq, compl_compl] }
#align pseudo_metric_space.replace_bornology PseudoMetricSpace.replaceBornology
theorem PseudoMetricSpace.replaceBornology_eq {α} [m : PseudoMetricSpace α] [B : Bornology α]
(H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) :
PseudoMetricSpace.replaceBornology _ H = m :=
by
ext
rfl
#align pseudo_metric_space.replace_bornology_eq PseudoMetricSpace.replaceBornology_eq
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem Metric.complete_of_convergent_controlled_sequences (B : ℕ → Real) (hB : ∀ n, 0 < B n)
(H :
∀ u : ℕ → α,
(∀ N n m : ℕ, N ≤ n → N ≤ m → dist (u n) (u m) < B N) → ∃ x, Tendsto u atTop (𝓝 x)) :
CompleteSpace α :=
UniformSpace.complete_of_convergent_controlled_sequences
(fun n => { p : α × α | dist p.1 p.2 < B n }) (fun n => dist_mem_uniformity <| hB n) H
#align metric.complete_of_convergent_controlled_sequences Metric.complete_of_convergent_controlled_sequences
theorem Metric.complete_of_cauchySeq_tendsto :
(∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α :=
Emetric.complete_of_cauchySeq_tendsto
#align metric.complete_of_cauchy_seq_tendsto Metric.complete_of_cauchySeq_tendsto
section Real
/-- Instantiate the reals as a pseudometric space. -/
instance Real.pseudoMetricSpace : PseudoMetricSpace ℝ
where
dist x y := |x - y|
dist_self := by simp [abs_zero]
dist_comm x y := abs_sub_comm _ _
dist_triangle x y z := abs_sub_le _ _ _
#align real.pseudo_metric_space Real.pseudoMetricSpace
theorem Real.dist_eq (x y : ℝ) : dist x y = |x - y| :=
rfl
#align real.dist_eq Real.dist_eq
theorem Real.nndist_eq (x y : ℝ) : nndist x y = Real.nnabs (x - y) :=
rfl
#align real.nndist_eq Real.nndist_eq
theorem Real.nndist_eq' (x y : ℝ) : nndist x y = Real.nnabs (y - x) :=
nndist_comm _ _
#align real.nndist_eq' Real.nndist_eq'
theorem Real.dist_0_eq_abs (x : ℝ) : dist x 0 = |x| := by simp [Real.dist_eq]
#align real.dist_0_eq_abs Real.dist_0_eq_abs
theorem Real.dist_left_le_of_mem_uIcc {x y z : ℝ} (h : y ∈ uIcc x z) : dist x y ≤ dist x z := by
simpa only [dist_comm x] using abs_sub_left_of_mem_uIcc h
#align real.dist_left_le_of_mem_uIcc Real.dist_left_le_of_mem_uIcc
theorem Real.dist_right_le_of_mem_uIcc {x y z : ℝ} (h : y ∈ uIcc x z) : dist y z ≤ dist x z := by
simpa only [dist_comm _ z] using abs_sub_right_of_mem_uIcc h
#align real.dist_right_le_of_mem_uIcc Real.dist_right_le_of_mem_uIcc
theorem Real.dist_le_of_mem_uIcc {x y x' y' : ℝ} (hx : x ∈ uIcc x' y') (hy : y ∈ uIcc x' y') :
dist x y ≤ dist x' y' :=
abs_sub_le_of_uIcc_subset_uIcc <| uIcc_subset_uIcc (by rwa [uIcc_comm]) (by rwa [uIcc_comm])
#align real.dist_le_of_mem_uIcc Real.dist_le_of_mem_uIcc
theorem Real.dist_le_of_mem_icc {x y x' y' : ℝ} (hx : x ∈ Icc x' y') (hy : y ∈ Icc x' y') :
dist x y ≤ y' - x' := by
simpa only [Real.dist_eq, abs_of_nonpos (sub_nonpos.2 <| hx.1.trans hx.2), neg_sub] using
Real.dist_le_of_mem_uIcc (Icc_subset_uIcc hx) (Icc_subset_uIcc hy)
#align real.dist_le_of_mem_Icc Real.dist_le_of_mem_icc
theorem Real.dist_le_of_mem_icc_01 {x y : ℝ} (hx : x ∈ Icc (0 : ℝ) 1) (hy : y ∈ Icc (0 : ℝ) 1) :
dist x y ≤ 1 := by simpa only [sub_zero] using Real.dist_le_of_mem_icc hx hy
#align real.dist_le_of_mem_Icc_01 Real.dist_le_of_mem_icc_01
instance : OrderTopology ℝ :=
orderTopology_of_nhds_abs fun x => by
simp only [nhds_basis_ball.eq_binfi, ball, Real.dist_eq, abs_sub_comm]
theorem Real.ball_eq_ioo (x r : ℝ) : ball x r = Ioo (x - r) (x + r) :=
Set.ext fun y => by
rw [mem_ball, dist_comm, Real.dist_eq, abs_sub_lt_iff, mem_Ioo, ← sub_lt_iff_lt_add',
sub_lt_comm]
#align real.ball_eq_Ioo Real.ball_eq_ioo
theorem Real.closedBall_eq_icc {x r : ℝ} : closedBall x r = Icc (x - r) (x + r) := by
ext y <;>
rw [mem_closed_ball, dist_comm, Real.dist_eq, abs_sub_le_iff, mem_Icc, ← sub_le_iff_le_add',
sub_le_comm]
#align real.closed_ball_eq_Icc Real.closedBall_eq_icc
theorem Real.ioo_eq_ball (x y : ℝ) : Ioo x y = ball ((x + y) / 2) ((y - x) / 2) := by
rw [Real.ball_eq_ioo, ← sub_div, add_comm, ← sub_add, add_sub_cancel', add_self_div_two, ←
add_div, add_assoc, add_sub_cancel'_right, add_self_div_two]
#align real.Ioo_eq_ball Real.ioo_eq_ball
theorem Real.icc_eq_closedBall (x y : ℝ) : Icc x y = closedBall ((x + y) / 2) ((y - x) / 2) := by
rw [Real.closedBall_eq_icc, ← sub_div, add_comm, ← sub_add, add_sub_cancel', add_self_div_two, ←
add_div, add_assoc, add_sub_cancel'_right, add_self_div_two]
#align real.Icc_eq_closed_ball Real.icc_eq_closedBall
section MetricOrdered
variable [Preorder α] [CompactIccSpace α]
theorem totallyBounded_icc (a b : α) : TotallyBounded (Icc a b) :=
isCompact_icc.TotallyBounded
#align totally_bounded_Icc totallyBounded_icc
theorem totallyBounded_ico (a b : α) : TotallyBounded (Ico a b) :=
totallyBounded_subset Ico_subset_Icc_self (totallyBounded_icc a b)
#align totally_bounded_Ico totallyBounded_ico
theorem totallyBounded_ioc (a b : α) : TotallyBounded (Ioc a b) :=
totallyBounded_subset Ioc_subset_Icc_self (totallyBounded_icc a b)
#align totally_bounded_Ioc totallyBounded_ioc
theorem totallyBounded_ioo (a b : α) : TotallyBounded (Ioo a b) :=
totallyBounded_subset Ioo_subset_Icc_self (totallyBounded_icc a b)
#align totally_bounded_Ioo totallyBounded_ioo
end MetricOrdered
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the
general case. -/
theorem squeeze_zero' {α} {f g : α → ℝ} {t₀ : Filter α} (hf : ∀ᶠ t in t₀, 0 ≤ f t)
(hft : ∀ᶠ t in t₀, f t ≤ g t) (g0 : Tendsto g t₀ (nhds 0)) : Tendsto f t₀ (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds g0 hf hft
#align squeeze_zero' squeeze_zero'
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le`
and `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/
theorem squeeze_zero {α} {f g : α → ℝ} {t₀ : Filter α} (hf : ∀ t, 0 ≤ f t) (hft : ∀ t, f t ≤ g t)
(g0 : Tendsto g t₀ (𝓝 0)) : Tendsto f t₀ (𝓝 0) :=
squeeze_zero' (eventually_of_forall hf) (eventually_of_forall hft) g0
#align squeeze_zero squeeze_zero
theorem Metric.uniformity_eq_comap_nhds_zero :
𝓤 α = comap (fun p : α × α => dist p.1 p.2) (𝓝 (0 : ℝ)) :=
by
ext s
simp [mem_uniformity_dist, (nhds_basis_ball.comap _).mem_iff, subset_def, Real.dist_0_eq_abs]
#align metric.uniformity_eq_comap_nhds_zero Metric.uniformity_eq_comap_nhds_zero
theorem cauchySeq_iff_tendsto_dist_atTop_0 [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ Tendsto (fun n : β × β => dist (u n.1) (u n.2)) atTop (𝓝 0) := by
rw [cauchySeq_iff_tendsto, Metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff, Prod.map_def]
#align cauchy_seq_iff_tendsto_dist_at_top_0 cauchySeq_iff_tendsto_dist_atTop_0
theorem tendsto_uniformity_iff_dist_tendsto_zero {ι : Type _} {f : ι → α × α} {p : Filter ι} :
Tendsto f p (𝓤 α) ↔ Tendsto (fun x => dist (f x).1 (f x).2) p (𝓝 0) := by
rw [Metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff]
#align tendsto_uniformity_iff_dist_tendsto_zero tendsto_uniformity_iff_dist_tendsto_zero
theorem Filter.Tendsto.congr_dist {ι : Type _} {f₁ f₂ : ι → α} {p : Filter ι} {a : α}
(h₁ : Tendsto f₁ p (𝓝 a)) (h : Tendsto (fun x => dist (f₁ x) (f₂ x)) p (𝓝 0)) :
Tendsto f₂ p (𝓝 a) :=
h₁.congr_uniformity <| tendsto_uniformity_iff_dist_tendsto_zero.2 h
#align filter.tendsto.congr_dist Filter.Tendsto.congr_dist
alias Filter.Tendsto.congr_dist ← tendsto_of_tendsto_of_dist
#align tendsto_of_tendsto_of_dist tendsto_of_tendsto_of_dist
theorem tendsto_iff_of_dist {ι : Type _} {f₁ f₂ : ι → α} {p : Filter ι} {a : α}
(h : Tendsto (fun x => dist (f₁ x) (f₂ x)) p (𝓝 0)) : Tendsto f₁ p (𝓝 a) ↔ Tendsto f₂ p (𝓝 a) :=
Uniform.tendsto_congr <| tendsto_uniformity_iff_dist_tendsto_zero.2 h
#align tendsto_iff_of_dist tendsto_iff_of_dist
/-- If `u` is a neighborhood of `x`, then for small enough `r`, the closed ball
`closed_ball x r` is contained in `u`. -/
theorem eventually_closedBall_subset {x : α} {u : Set α} (hu : u ∈ 𝓝 x) :
∀ᶠ r in 𝓝 (0 : ℝ), closedBall x r ⊆ u :=
by
obtain ⟨ε, εpos, hε⟩ : ∃ (ε : _)(hε : 0 < ε), closed_ball x ε ⊆ u :=
nhds_basis_closed_ball.mem_iff.1 hu
have : Iic ε ∈ 𝓝 (0 : ℝ) := iic_mem_nhds εpos
filter_upwards [this]with _ hr using subset.trans (closed_ball_subset_closed_ball hr) hε
#align eventually_closed_ball_subset eventually_closedBall_subset
end Real
section CauchySeq
variable [Nonempty β] [SemilatticeSup β]
/- ./././Mathport/Syntax/Translate/Basic.lean:632:2: warning: expanding binder collection (m n «expr ≥ » N) -/
-- see Note [nolint_ge]
/-- In a pseudometric space, Cauchy sequences are characterized by the fact that, eventually,
the distance between its elements is arbitrarily small -/
@[nolint ge_or_gt]
theorem Metric.cauchySeq_iff {u : β → α} :
CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ (m) (_ : m ≥ N) (n) (_ : n ≥ N), dist (u m) (u n) < ε :=
uniformity_basis_dist.cauchy_seq_iff
#align metric.cauchy_seq_iff Metric.cauchySeq_iff
/-- A variation around the pseudometric characterization of Cauchy sequences -/
theorem Metric.cauchySeq_iff' {u : β → α} :
CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, dist (u n) (u N) < ε :=
uniformity_basis_dist.cauchy_seq_iff'
#align metric.cauchy_seq_iff' Metric.cauchySeq_iff'
-- see Note [nolint_ge]
/-- In a pseudometric space, unifom Cauchy sequences are characterized by the fact that, eventually,
the distance between all its elements is uniformly, arbitrarily small -/
@[nolint ge_or_gt]
theorem Metric.uniformCauchySeqOn_iff {γ : Type _} {F : β → γ → α} {s : Set γ} :
UniformCauchySeqOn F atTop s ↔
∀ ε : ℝ,
ε > 0 →
∃ N : β, ∀ m : β, m ≥ N → ∀ n : β, n ≥ N → ∀ x : γ, x ∈ s → dist (F m x) (F n x) < ε :=
by
constructor
· intro h ε hε
let u := { a : α × α | dist a.fst a.snd < ε }
have hu : u ∈ 𝓤 α := metric.mem_uniformity_dist.mpr ⟨ε, hε, fun a b => by simp⟩
rw [←
@Filter.eventually_atTop_prod_self' _ _ _ fun m =>
∀ x : γ, x ∈ s → dist (F m.fst x) (F m.snd x) < ε]
specialize h u hu
rw [prod_at_top_at_top_eq] at h
exact h.mono fun n h x hx => set.mem_set_of_eq.mp (h x hx)
· intro h u hu
rcases metric.mem_uniformity_dist.mp hu with ⟨ε, hε, hab⟩
rcases h ε hε with ⟨N, hN⟩
rw [prod_at_top_at_top_eq, eventually_at_top]
use (N, N)
intro b hb x hx
rcases hb with ⟨hbl, hbr⟩
exact hab (hN b.fst hbl.ge b.snd hbr.ge x hx)
#align metric.uniform_cauchy_seq_on_iff Metric.uniformCauchySeqOn_iff
/-- If the distance between `s n` and `s m`, `n ≤ m` is bounded above by `b n`
and `b` converges to zero, then `s` is a Cauchy sequence. -/
theorem cauchySeq_of_le_tendsto_0' {s : β → α} (b : β → ℝ)
(h : ∀ n m : β, n ≤ m → dist (s n) (s m) ≤ b n) (h₀ : Tendsto b atTop (𝓝 0)) : CauchySeq s :=
Metric.cauchySeq_iff'.2 fun ε ε0 =>
(h₀.Eventually (gt_mem_nhds ε0)).exists.imp fun N hN n hn =>
calc
dist (s n) (s N) = dist (s N) (s n) := dist_comm _ _
_ ≤ b N := h _ _ hn
_ < ε := hN
#align cauchy_seq_of_le_tendsto_0' cauchySeq_of_le_tendsto_0'
/-- If the distance between `s n` and `s m`, `n, m ≥ N` is bounded above by `b N`
and `b` converges to zero, then `s` is a Cauchy sequence. -/
theorem cauchySeq_of_le_tendsto_0 {s : β → α} (b : β → ℝ)
(h : ∀ n m N : β, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) (h₀ : Tendsto b atTop (𝓝 0)) :
CauchySeq s :=
cauchySeq_of_le_tendsto_0' b (fun n m hnm => h _ _ _ le_rfl hnm) h₀
#align cauchy_seq_of_le_tendsto_0 cauchySeq_of_le_tendsto_0
/-- A Cauchy sequence on the natural numbers is bounded. -/
theorem cauchySeq_bdd {u : ℕ → α} (hu : CauchySeq u) : ∃ R > 0, ∀ m n, dist (u m) (u n) < R :=
by
rcases Metric.cauchySeq_iff'.1 hu 1 zero_lt_one with ⟨N, hN⟩
rsuffices ⟨R, R0, H⟩ : ∃ R > 0, ∀ n, dist (u n) (u N) < R
·
exact
⟨_, add_pos R0 R0, fun m n =>
lt_of_le_of_lt (dist_triangle_right _ _ _) (add_lt_add (H m) (H n))⟩
let R := Finset.sup (Finset.range N) fun n => nndist (u n) (u N)
refine' ⟨↑R + 1, add_pos_of_nonneg_of_pos R.2 zero_lt_one, fun n => _⟩
cases le_or_lt N n
· exact lt_of_lt_of_le (hN _ h) (le_add_of_nonneg_left R.2)
· have : _ ≤ R := Finset.le_sup (Finset.mem_range.2 h)
exact lt_of_le_of_lt this (lt_add_of_pos_right _ zero_lt_one)
#align cauchy_seq_bdd cauchySeq_bdd
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
theorem cauchySeq_iff_le_tendsto_0 {s : ℕ → α} :
CauchySeq s ↔
∃ b : ℕ → ℝ,
(∀ n, 0 ≤ b n) ∧
(∀ n m N : ℕ, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧ Tendsto b atTop (𝓝 0) :=
⟨fun hs =>
by
/- `s` is a Cauchy sequence. The sequence `b` will be constructed by taking
the supremum of the distances between `s n` and `s m` for `n m ≥ N`.
First, we prove that all these distances are bounded, as otherwise the Sup
would not make sense. -/
let S N := (fun p : ℕ × ℕ => dist (s p.1) (s p.2)) '' { p | p.1 ≥ N ∧ p.2 ≥ N }
have hS : ∀ N, ∃ x, ∀ y ∈ S N, y ≤ x :=
by
rcases cauchySeq_bdd hs with ⟨R, R0, hR⟩
refine' fun N => ⟨R, _⟩
rintro _ ⟨⟨m, n⟩, _, rfl⟩
exact le_of_lt (hR m n)
have bdd : BddAbove (range fun p : ℕ × ℕ => dist (s p.1) (s p.2)) :=
by
rcases cauchySeq_bdd hs with ⟨R, R0, hR⟩
use R
rintro _ ⟨⟨m, n⟩, rfl⟩
exact le_of_lt (hR m n)
-- Prove that it bounds the distances of points in the Cauchy sequence
have ub : ∀ m n N, N ≤ m → N ≤ n → dist (s m) (s n) ≤ Sup (S N) := fun m n N hm hn =>
le_csupₛ (hS N) ⟨⟨_, _⟩, ⟨hm, hn⟩, rfl⟩
have S0m : ∀ n, (0 : ℝ) ∈ S n := fun n => ⟨⟨n, n⟩, ⟨le_rfl, le_rfl⟩, dist_self _⟩
have S0 := fun n => le_csupₛ (hS n) (S0m n)
-- Prove that it tends to `0`, by using the Cauchy property of `s`
refine' ⟨fun N => Sup (S N), S0, ub, Metric.tendsto_atTop.2 fun ε ε0 => _⟩
refine' (Metric.cauchySeq_iff.1 hs (ε / 2) (half_pos ε0)).imp fun N hN n hn => _
rw [Real.dist_0_eq_abs, abs_of_nonneg (S0 n)]
refine' lt_of_le_of_lt (csupₛ_le ⟨_, S0m _⟩ _) (half_lt_self ε0)
rintro _ ⟨⟨m', n'⟩, ⟨hm', hn'⟩, rfl⟩
exact le_of_lt (hN _ (le_trans hn hm') _ (le_trans hn hn')), fun ⟨b, _, b_bound, b_lim⟩ =>
cauchySeq_of_le_tendsto_0 b b_bound b_lim⟩
#align cauchy_seq_iff_le_tendsto_0 cauchySeq_iff_le_tendsto_0
end CauchySeq
/-- Pseudometric space structure pulled back by a function. -/
def PseudoMetricSpace.induced {α β} (f : α → β) (m : PseudoMetricSpace β) : PseudoMetricSpace α
where
dist x y := dist (f x) (f y)
dist_self x := dist_self _
dist_comm x y := dist_comm _ _
dist_triangle x y z := dist_triangle _ _ _
edist x y := edist (f x) (f y)
edist_dist x y := edist_dist _ _
toUniformSpace := UniformSpace.comap f m.toUniformSpace
uniformity_dist :=
by
apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ fun x y => dist (f x) (f y)
refine' compl_surjective.forall.2 fun s => compl_mem_comap.trans <| mem_uniformity_dist.trans _
simp only [mem_compl_iff, @imp_not_comm _ (_ ∈ _), ← Prod.forall', Prod.mk.eta, ball_image_iff]
toBornology := Bornology.induced f
cobounded_sets :=
Set.ext <|
compl_surjective.forall.2 fun s => by
simp only [compl_mem_comap, Filter.mem_sets, ← is_bounded_def, mem_set_of_eq, compl_compl,
is_bounded_iff, ball_image_iff]
#align pseudo_metric_space.induced PseudoMetricSpace.induced
/-- Pull back a pseudometric space structure by an inducing map. This is a version of
`pseudo_metric_space.induced` useful in case if the domain already has a `topological_space`
structure. -/
def Inducing.comapPseudoMetricSpace {α β} [TopologicalSpace α] [PseudoMetricSpace β] {f : α → β}
(hf : Inducing f) : PseudoMetricSpace α :=
(PseudoMetricSpace.induced f ‹_›).replaceTopology hf.induced
#align inducing.comap_pseudo_metric_space Inducing.comapPseudoMetricSpace
/-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of
`pseudo_metric_space.induced` useful in case if the domain already has a `uniform_space`
structure. -/
def UniformInducing.comapPseudoMetricSpace {α β} [UniformSpace α] [PseudoMetricSpace β] (f : α → β)
(h : UniformInducing f) : PseudoMetricSpace α :=
(PseudoMetricSpace.induced f ‹_›).replaceUniformity h.comap_uniformity.symm
#align uniform_inducing.comap_pseudo_metric_space UniformInducing.comapPseudoMetricSpace
instance Subtype.pseudoMetricSpace {p : α → Prop} : PseudoMetricSpace (Subtype p) :=
PseudoMetricSpace.induced coe ‹_›
#align subtype.pseudo_metric_space Subtype.pseudoMetricSpace
theorem Subtype.dist_eq {p : α → Prop} (x y : Subtype p) : dist x y = dist (x : α) y :=
rfl
#align subtype.dist_eq Subtype.dist_eq
theorem Subtype.nndist_eq {p : α → Prop} (x y : Subtype p) : nndist x y = nndist (x : α) y :=
rfl
#align subtype.nndist_eq Subtype.nndist_eq
namespace MulOpposite
@[to_additive]
instance : PseudoMetricSpace αᵐᵒᵖ :=
PseudoMetricSpace.induced MulOpposite.unop ‹_›
@[simp, to_additive]
theorem dist_unop (x y : αᵐᵒᵖ) : dist (unop x) (unop y) = dist x y :=
rfl
#align mul_opposite.dist_unop MulOpposite.dist_unop
#align add_opposite.dist_unop AddOpposite.dist_unop
@[simp, to_additive]
theorem dist_op (x y : α) : dist (op x) (op y) = dist x y :=
rfl
#align mul_opposite.dist_op MulOpposite.dist_op
#align add_opposite.dist_op AddOpposite.dist_op
@[simp, to_additive]
theorem nndist_unop (x y : αᵐᵒᵖ) : nndist (unop x) (unop y) = nndist x y :=
rfl
#align mul_opposite.nndist_unop MulOpposite.nndist_unop
#align add_opposite.nndist_unop AddOpposite.nndist_unop
@[simp, to_additive]
theorem nndist_op (x y : α) : nndist (op x) (op y) = nndist x y :=
rfl
#align mul_opposite.nndist_op MulOpposite.nndist_op
#align add_opposite.nndist_op AddOpposite.nndist_op
end MulOpposite
section Nnreal
instance : PseudoMetricSpace ℝ≥0 :=
Subtype.pseudoMetricSpace
theorem Nnreal.dist_eq (a b : ℝ≥0) : dist a b = |(a : ℝ) - b| :=
rfl
#align nnreal.dist_eq Nnreal.dist_eq
theorem Nnreal.nndist_eq (a b : ℝ≥0) : nndist a b = max (a - b) (b - a) :=
by
/- WLOG, `b ≤ a`. `wlog h : b ≤ a` works too but it is much slower because Lean tries to prove one
case from the other and fails; `tactic.skip` tells Lean not to try. -/
wlog (discharger := tactic.skip) h : b ≤ a := le_total b a using a b, b a
·
rw [← Nnreal.coe_eq, ← dist_nndist, Nnreal.dist_eq, tsub_eq_zero_iff_le.2 h,
max_eq_left (zero_le <| a - b), ← Nnreal.coe_sub h, abs_of_nonneg (a - b).coe_nonneg]
· rwa [nndist_comm, max_comm]
#align nnreal.nndist_eq Nnreal.nndist_eq
@[simp]
theorem Nnreal.nndist_zero_eq_val (z : ℝ≥0) : nndist 0 z = z := by
simp only [Nnreal.nndist_eq, max_eq_right, tsub_zero, zero_tsub, zero_le']
#align nnreal.nndist_zero_eq_val Nnreal.nndist_zero_eq_val
@[simp]
theorem Nnreal.nndist_zero_eq_val' (z : ℝ≥0) : nndist z 0 = z :=
by
rw [nndist_comm]
exact Nnreal.nndist_zero_eq_val z
#align nnreal.nndist_zero_eq_val' Nnreal.nndist_zero_eq_val'
theorem Nnreal.le_add_nndist (a b : ℝ≥0) : a ≤ b + nndist a b :=
by
suffices (a : ℝ) ≤ (b : ℝ) + dist a b by exact nnreal.coe_le_coe.mp this
linarith [le_of_abs_le (by rfl : abs (a - b : ℝ) ≤ dist a b)]
#align nnreal.le_add_nndist Nnreal.le_add_nndist
end Nnreal
section ULift
variable [PseudoMetricSpace β]
instance : PseudoMetricSpace (ULift β) :=
PseudoMetricSpace.induced ULift.down ‹_›
theorem ULift.dist_eq (x y : ULift β) : dist x y = dist x.down y.down :=
rfl
#align ulift.dist_eq ULift.dist_eq
theorem ULift.nndist_eq (x y : ULift β) : nndist x y = nndist x.down y.down :=
rfl
#align ulift.nndist_eq ULift.nndist_eq
@[simp]
theorem ULift.dist_up_up (x y : β) : dist (ULift.up x) (ULift.up y) = dist x y :=
rfl
#align ulift.dist_up_up ULift.dist_up_up
@[simp]
theorem ULift.nndist_up_up (x y : β) : nndist (ULift.up x) (ULift.up y) = nndist x y :=
rfl
#align ulift.nndist_up_up ULift.nndist_up_up
end ULift
section Prod
variable [PseudoMetricSpace β]
instance Prod.pseudoMetricSpaceMax : PseudoMetricSpace (α × β) :=
(PseudoEmetricSpace.toPseudoMetricSpaceOfDist (fun x y : α × β => dist x.1 y.1 ⊔ dist x.2 y.2)
(fun x y => (max_lt (edist_lt_top _ _) (edist_lt_top _ _)).Ne) fun x y => by
simp only [sup_eq_max, dist_edist, ←
Ennreal.toReal_max (edist_ne_top _ _) (edist_ne_top _ _), Prod.edist_eq]).replaceBornology
fun s =>
by
simp only [← is_bounded_image_fst_and_snd, is_bounded_iff_eventually, ball_image_iff, ←
eventually_and, ← forall_and, ← max_le_iff]
rfl
#align prod.pseudo_metric_space_max Prod.pseudoMetricSpaceMax
theorem Prod.dist_eq {x y : α × β} : dist x y = max (dist x.1 y.1) (dist x.2 y.2) :=
rfl
#align prod.dist_eq Prod.dist_eq
@[simp]
theorem dist_prod_same_left {x : α} {y₁ y₂ : β} : dist (x, y₁) (x, y₂) = dist y₁ y₂ := by
simp [Prod.dist_eq, dist_nonneg]
#align dist_prod_same_left dist_prod_same_left
@[simp]
theorem dist_prod_same_right {x₁ x₂ : α} {y : β} : dist (x₁, y) (x₂, y) = dist x₁ x₂ := by
simp [Prod.dist_eq, dist_nonneg]
#align dist_prod_same_right dist_prod_same_right
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
theorem ball_prod_same (x : α) (y : β) (r : ℝ) : ball x r ×ˢ ball y r = ball (x, y) r :=
ext fun z => by simp [Prod.dist_eq]
#align ball_prod_same ball_prod_same
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
theorem closedBall_prod_same (x : α) (y : β) (r : ℝ) :
closedBall x r ×ˢ closedBall y r = closedBall (x, y) r :=
ext fun z => by simp [Prod.dist_eq]
#align closed_ball_prod_same closedBall_prod_same
end Prod
theorem uniformContinuous_dist : UniformContinuous fun p : α × α => dist p.1 p.2 :=
Metric.uniformContinuous_iff.2 fun ε ε0 =>
⟨ε / 2, half_pos ε0, by
suffices
· intro p q h
cases' p with p₁ p₂
cases' q with q₁ q₂
cases' max_lt_iff.1 h with h₁ h₂
clear h
dsimp at h₁ h₂⊢
rw [Real.dist_eq]
refine' abs_sub_lt_iff.2 ⟨_, _⟩
· revert p₁ p₂ q₁ q₂ h₁ h₂
exact this
· apply this <;> rwa [dist_comm]
intro p₁ p₂ q₁ q₂ h₁ h₂
have :=
add_lt_add (abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₁ q₁ p₂) h₁)).1
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₂ q₂ q₁) h₂)).1
rwa [add_halves, dist_comm p₂, sub_add_sub_cancel, dist_comm q₂] at this⟩
#align uniform_continuous_dist uniformContinuous_dist
theorem UniformContinuous.dist [UniformSpace β] {f g : β → α} (hf : UniformContinuous f)
(hg : UniformContinuous g) : UniformContinuous fun b => dist (f b) (g b) :=
uniformContinuous_dist.comp (hf.prod_mk hg)
#align uniform_continuous.dist UniformContinuous.dist
@[continuity]
theorem continuous_dist : Continuous fun p : α × α => dist p.1 p.2 :=
uniformContinuous_dist.Continuous
#align continuous_dist continuous_dist
@[continuity]
theorem Continuous.dist [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) :
Continuous fun b => dist (f b) (g b) :=
continuous_dist.comp (hf.prod_mk hg : _)
#align continuous.dist Continuous.dist
theorem Filter.Tendsto.dist {f g : β → α} {x : Filter β} {a b : α} (hf : Tendsto f x (𝓝 a))
(hg : Tendsto g x (𝓝 b)) : Tendsto (fun x => dist (f x) (g x)) x (𝓝 (dist a b)) :=
(continuous_dist.Tendsto (a, b)).comp (hf.prod_mk_nhds hg)
#align filter.tendsto.dist Filter.Tendsto.dist
theorem nhds_comap_dist (a : α) : ((𝓝 (0 : ℝ)).comap fun a' => dist a' a) = 𝓝 a := by
simp only [@nhds_eq_comap_uniformity α, Metric.uniformity_eq_comap_nhds_zero, comap_comap,
(· ∘ ·), dist_comm]
#align nhds_comap_dist nhds_comap_dist
theorem tendsto_iff_dist_tendsto_zero {f : β → α} {x : Filter β} {a : α} :
Tendsto f x (𝓝 a) ↔ Tendsto (fun b => dist (f b) a) x (𝓝 0) := by
rw [← nhds_comap_dist a, tendsto_comap_iff]
#align tendsto_iff_dist_tendsto_zero tendsto_iff_dist_tendsto_zero
theorem continuous_iff_continuous_dist [TopologicalSpace β] {f : β → α} :
Continuous f ↔ Continuous fun x : β × β => dist (f x.1) (f x.2) :=
⟨fun h => (h.comp continuous_fst).dist (h.comp continuous_snd), fun h =>
continuous_iff_continuousAt.2 fun x =>
tendsto_iff_dist_tendsto_zero.2 <|
(h.comp (continuous_id.prod_mk continuous_const)).tendsto' _ _ <| dist_self _⟩
#align continuous_iff_continuous_dist continuous_iff_continuous_dist
theorem uniformContinuous_nndist : UniformContinuous fun p : α × α => nndist p.1 p.2 :=
uniformContinuous_dist.subtype_mk _
#align uniform_continuous_nndist uniformContinuous_nndist
theorem UniformContinuous.nndist [UniformSpace β] {f g : β → α} (hf : UniformContinuous f)
(hg : UniformContinuous g) : UniformContinuous fun b => nndist (f b) (g b) :=
uniformContinuous_nndist.comp (hf.prod_mk hg)
#align uniform_continuous.nndist UniformContinuous.nndist
theorem continuous_nndist : Continuous fun p : α × α => nndist p.1 p.2 :=
uniformContinuous_nndist.Continuous
#align continuous_nndist continuous_nndist
theorem Continuous.nndist [TopologicalSpace β] {f g : β → α} (hf : Continuous f)
(hg : Continuous g) : Continuous fun b => nndist (f b) (g b) :=
continuous_nndist.comp (hf.prod_mk hg : _)
#align continuous.nndist Continuous.nndist
theorem Filter.Tendsto.nndist {f g : β → α} {x : Filter β} {a b : α} (hf : Tendsto f x (𝓝 a))
(hg : Tendsto g x (𝓝 b)) : Tendsto (fun x => nndist (f x) (g x)) x (𝓝 (nndist a b)) :=
(continuous_nndist.Tendsto (a, b)).comp (hf.prod_mk_nhds hg)
#align filter.tendsto.nndist Filter.Tendsto.nndist
namespace Metric
variable {x y z : α} {ε ε₁ ε₂ : ℝ} {s : Set α}
theorem isClosed_ball : IsClosed (closedBall x ε) :=
isClosed_le (continuous_id.dist continuous_const) continuous_const
#align metric.is_closed_ball Metric.isClosed_ball
theorem isClosed_sphere : IsClosed (sphere x ε) :=
isClosed_eq (continuous_id.dist continuous_const) continuous_const
#align metric.is_closed_sphere Metric.isClosed_sphere
@[simp]
theorem closure_closedBall : closure (closedBall x ε) = closedBall x ε :=
isClosed_ball.closure_eq
#align metric.closure_closed_ball Metric.closure_closedBall
theorem closure_ball_subset_closedBall : closure (ball x ε) ⊆ closedBall x ε :=
closure_minimal ball_subset_closedBall isClosed_ball
#align metric.closure_ball_subset_closed_ball Metric.closure_ball_subset_closedBall
theorem frontier_ball_subset_sphere : frontier (ball x ε) ⊆ sphere x ε :=
frontier_lt_subset_eq (continuous_id.dist continuous_const) continuous_const
#align metric.frontier_ball_subset_sphere Metric.frontier_ball_subset_sphere
theorem frontier_closedBall_subset_sphere : frontier (closedBall x ε) ⊆ sphere x ε :=
frontier_le_subset_eq (continuous_id.dist continuous_const) continuous_const
#align metric.frontier_closed_ball_subset_sphere Metric.frontier_closedBall_subset_sphere
theorem ball_subset_interior_closedBall : ball x ε ⊆ interior (closedBall x ε) :=
interior_maximal ball_subset_closedBall isOpen_ball
#align metric.ball_subset_interior_closed_ball Metric.ball_subset_interior_closedBall
/-- ε-characterization of the closure in pseudometric spaces-/
theorem mem_closure_iff {s : Set α} {a : α} : a ∈ closure s ↔ ∀ ε > 0, ∃ b ∈ s, dist a b < ε :=
(mem_closure_iff_nhds_basis nhds_basis_ball).trans <| by simp only [mem_ball, dist_comm]
#align metric.mem_closure_iff Metric.mem_closure_iff
theorem mem_closure_range_iff {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀ ε > 0, ∃ k : β, dist a (e k) < ε := by
simp only [mem_closure_iff, exists_range_iff]
#align metric.mem_closure_range_iff Metric.mem_closure_range_iff
theorem mem_closure_range_iff_nat {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀ n : ℕ, ∃ k : β, dist a (e k) < 1 / ((n : ℝ) + 1) :=
(mem_closure_iff_nhds_basis nhds_basis_ball_inv_nat_succ).trans <| by
simp only [mem_ball, dist_comm, exists_range_iff, forall_const]
#align metric.mem_closure_range_iff_nat Metric.mem_closure_range_iff_nat
theorem mem_of_closed' {s : Set α} (hs : IsClosed s) {a : α} :
a ∈ s ↔ ∀ ε > 0, ∃ b ∈ s, dist a b < ε := by
simpa only [hs.closure_eq] using @mem_closure_iff _ _ s a
#align metric.mem_of_closed' Metric.mem_of_closed'
theorem closedBall_zero' (x : α) : closedBall x 0 = closure {x} :=
Subset.antisymm
(fun y hy =>
mem_closure_iff.2 fun ε ε0 => ⟨x, mem_singleton x, (mem_closedBall.1 hy).trans_lt ε0⟩)
(closure_minimal (singleton_subset_iff.2 (dist_self x).le) isClosed_ball)
#align metric.closed_ball_zero' Metric.closedBall_zero'
theorem dense_iff {s : Set α} : Dense s ↔ ∀ x, ∀ r > 0, (ball x r ∩ s).Nonempty :=
forall_congr' fun x => by
simp only [mem_closure_iff, Set.Nonempty, exists_prop, mem_inter_iff, mem_ball', and_comm']
#align metric.dense_iff Metric.dense_iff
theorem denseRange_iff {f : β → α} : DenseRange f ↔ ∀ x, ∀ r > 0, ∃ y, dist x (f y) < r :=
forall_congr' fun x => by simp only [mem_closure_iff, exists_range_iff]
#align metric.dense_range_iff Metric.denseRange_iff
/-- If a set `s` is separable, then the corresponding subtype is separable in a metric space.
This is not obvious, as the countable set whose closure covers `s` does not need in general to
be contained in `s`. -/
theorem TopologicalSpace.IsSeparable.separableSpace {s : Set α} (hs : IsSeparable s) :
SeparableSpace s := by
classical
rcases eq_empty_or_nonempty s with (rfl | ⟨⟨x₀, x₀s⟩⟩)
· infer_instance
rcases hs with ⟨c, hc, h'c⟩
haveI : Encodable c := hc.to_encodable
obtain ⟨u, -, u_pos, u_lim⟩ :
∃ u : ℕ → ℝ, StrictAnti u ∧ (∀ n : ℕ, 0 < u n) ∧ tendsto u at_top (𝓝 0) :=
exists_seq_strictAnti_tendsto (0 : ℝ)
let f : c × ℕ → α := fun p =>
if h : (Metric.ball (p.1 : α) (u p.2) ∩ s).Nonempty then h.some else x₀
have fs : ∀ p, f p ∈ s := by
rintro ⟨y, n⟩
by_cases h : (ball (y : α) (u n) ∩ s).Nonempty
· simpa only [f, h, dif_pos] using h.some_spec.2
· simpa only [f, h, not_false_iff, dif_neg]
let g : c × ℕ → s := fun p => ⟨f p, fs p⟩
apply separable_space_of_dense_range g
apply Metric.denseRange_iff.2
rintro ⟨x, xs⟩ r (rpos : 0 < r)
obtain ⟨n, hn⟩ : ∃ n, u n < r / 2 := ((tendsto_order.1 u_lim).2 _ (half_pos rpos)).exists
obtain ⟨z, zc, hz⟩ : ∃ z ∈ c, dist x z < u n := Metric.mem_closure_iff.1 (h'c xs) _ (u_pos n)
refine' ⟨(⟨z, zc⟩, n), _⟩
change dist x (f (⟨z, zc⟩, n)) < r
have A : (Metric.ball z (u n) ∩ s).Nonempty := ⟨x, hz, xs⟩
dsimp [f]
simp only [A, dif_pos]
calc
dist x A.some ≤ dist x z + dist z A.some := dist_triangle _ _ _
_ < r / 2 + r / 2 := add_lt_add (hz.trans hn) ((Metric.mem_ball'.1 A.some_spec.1).trans hn)
_ = r := add_halves _
#align topological_space.is_separable.separable_space TopologicalSpace.IsSeparable.separableSpace
/-- The preimage of a separable set by an inducing map is separable. -/
protected theorem Inducing.isSeparable_preimage {f : β → α} [TopologicalSpace β] (hf : Inducing f)
{s : Set α} (hs : IsSeparable s) : IsSeparable (f ⁻¹' s) :=
by
have : second_countable_topology s :=
haveI : separable_space s := hs.separable_space
UniformSpace.second_countable_of_separable _
let g : f ⁻¹' s → s := cod_restrict (f ∘ coe) s fun x => x.2
have : Inducing g := (hf.comp inducing_coe).codRestrict _
haveI : second_countable_topology (f ⁻¹' s) := this.second_countable_topology
rw [show f ⁻¹' s = coe '' (univ : Set (f ⁻¹' s)) by
simpa only [image_univ, Subtype.range_coe_subtype] ]
exact (is_separable_of_separable_space _).image continuous_subtype_coe
#align inducing.is_separable_preimage Inducing.isSeparable_preimage
protected theorem Embedding.isSeparable_preimage {f : β → α} [TopologicalSpace β] (hf : Embedding f)
{s : Set α} (hs : IsSeparable s) : IsSeparable (f ⁻¹' s) :=
hf.to_inducing.is_separable_preimage hs
#align embedding.is_separable_preimage Embedding.isSeparable_preimage
/-- If a map is continuous on a separable set `s`, then the image of `s` is also separable. -/
theorem ContinuousOn.isSeparable_image [TopologicalSpace β] {f : α → β} {s : Set α}
(hf : ContinuousOn f s) (hs : IsSeparable s) : IsSeparable (f '' s) :=
by
rw [show f '' s = s.restrict f '' univ by ext <;> simp]
exact
(is_separable_univ_iff.2 hs.separable_space).image (continuousOn_iff_continuous_restrict.1 hf)
#align continuous_on.is_separable_image ContinuousOn.isSeparable_image
end Metric
section Pi
open Finset
variable {π : β → Type _} [Fintype β] [∀ b, PseudoMetricSpace (π b)]
/-- A finite product of pseudometric spaces is a pseudometric space, with the sup distance. -/
instance pseudoMetricSpacePi : PseudoMetricSpace (∀ b, π b) :=
by
/- we construct the instance from the pseudoemetric space instance to avoid checking again that
the uniformity is the same as the product uniformity, but we register nevertheless a nice formula
for the distance -/
refine'
(PseudoEmetricSpace.toPseudoMetricSpaceOfDist
(fun f g : ∀ b, π b => ((sup univ fun b => nndist (f b) (g b) : ℝ≥0) : ℝ)) (fun f g => _)
fun f g => _).replaceBornology
fun s => _
show edist f g ≠ ⊤
exact ne_of_lt ((Finset.sup_lt_iff bot_lt_top).2 fun b hb => edist_lt_top _ _)
show ↑(sup univ fun b => nndist (f b) (g b)) = (sup univ fun b => edist (f b) (g b)).toReal
· simp only [edist_nndist, ← Ennreal.coe_finset_sup, Ennreal.coe_toReal]
show @is_bounded _ Pi.bornology s ↔ @is_bounded _ PseudoMetricSpace.toBornology _
· simp only [← is_bounded_def, is_bounded_iff_eventually, ← forall_is_bounded_image_eval_iff,
ball_image_iff, ← eventually_all, Function.eval_apply, @dist_nndist (π _)]
refine' eventually_congr ((eventually_ge_at_top 0).mono fun C hC => _)
lift C to ℝ≥0 using hC
refine'
⟨fun H x hx y hy => Nnreal.coe_le_coe.2 <| Finset.sup_le fun b hb => H b x hx y hy,
fun H b x hx y hy => Nnreal.coe_le_coe.2 _⟩
simpa only using Finset.sup_le_iff.1 (Nnreal.coe_le_coe.1 <| H hx hy) b (Finset.mem_univ b)
#align pseudo_metric_space_pi pseudoMetricSpacePi
theorem nndist_pi_def (f g : ∀ b, π b) : nndist f g = sup univ fun b => nndist (f b) (g b) :=
Nnreal.eq rfl
#align nndist_pi_def nndist_pi_def
theorem dist_pi_def (f g : ∀ b, π b) : dist f g = (sup univ fun b => nndist (f b) (g b) : ℝ≥0) :=
rfl
#align dist_pi_def dist_pi_def
theorem nndist_pi_le_iff {f g : ∀ b, π b} {r : ℝ≥0} :
nndist f g ≤ r ↔ ∀ b, nndist (f b) (g b) ≤ r := by simp [nndist_pi_def]
#align nndist_pi_le_iff nndist_pi_le_iff
theorem dist_pi_lt_iff {f g : ∀ b, π b} {r : ℝ} (hr : 0 < r) :
dist f g < r ↔ ∀ b, dist (f b) (g b) < r :=
by
lift r to ℝ≥0 using hr.le
simp [dist_pi_def, Finset.sup_lt_iff (show ⊥ < r from hr)]
#align dist_pi_lt_iff dist_pi_lt_iff
theorem dist_pi_le_iff {f g : ∀ b, π b} {r : ℝ} (hr : 0 ≤ r) :
dist f g ≤ r ↔ ∀ b, dist (f b) (g b) ≤ r :=
by
lift r to ℝ≥0 using hr
exact nndist_pi_le_iff
#align dist_pi_le_iff dist_pi_le_iff
theorem dist_pi_le_iff' [Nonempty β] {f g : ∀ b, π b} {r : ℝ} :
dist f g ≤ r ↔ ∀ b, dist (f b) (g b) ≤ r :=
by
by_cases hr : 0 ≤ r
· exact dist_pi_le_iff hr
·
exact
iff_of_false (fun h => hr <| dist_nonneg.trans h) fun h =>
hr <| dist_nonneg.trans <| h <| Classical.arbitrary _
#align dist_pi_le_iff' dist_pi_le_iff'
theorem dist_pi_const_le (a b : α) : (dist (fun _ : β => a) fun _ => b) ≤ dist a b :=
(dist_pi_le_iff dist_nonneg).2 fun _ => le_rfl
#align dist_pi_const_le dist_pi_const_le
theorem nndist_pi_const_le (a b : α) : (nndist (fun _ : β => a) fun _ => b) ≤ nndist a b :=
nndist_pi_le_iff.2 fun _ => le_rfl
#align nndist_pi_const_le nndist_pi_const_le
@[simp]
theorem dist_pi_const [Nonempty β] (a b : α) : (dist (fun x : β => a) fun _ => b) = dist a b := by
simpa only [dist_edist] using congr_arg Ennreal.toReal (edist_pi_const a b)
#align dist_pi_const dist_pi_const
@[simp]
theorem nndist_pi_const [Nonempty β] (a b : α) :
(nndist (fun x : β => a) fun _ => b) = nndist a b :=
Nnreal.eq <| dist_pi_const a b
#align nndist_pi_const nndist_pi_const
theorem nndist_le_pi_nndist (f g : ∀ b, π b) (b : β) : nndist (f b) (g b) ≤ nndist f g :=
by
rw [nndist_pi_def]
exact Finset.le_sup (Finset.mem_univ b)
#align nndist_le_pi_nndist nndist_le_pi_nndist
theorem dist_le_pi_dist (f g : ∀ b, π b) (b : β) : dist (f b) (g b) ≤ dist f g := by
simp only [dist_nndist, Nnreal.coe_le_coe, nndist_le_pi_nndist f g b]
#align dist_le_pi_dist dist_le_pi_dist
/-- An open ball in a product space is a product of open balls. See also `metric.ball_pi'`
for a version assuming `nonempty β` instead of `0 < r`. -/
theorem ball_pi (x : ∀ b, π b) {r : ℝ} (hr : 0 < r) :
ball x r = Set.pi univ fun b => ball (x b) r :=
by
ext p
simp [dist_pi_lt_iff hr]
#align ball_pi ball_pi
/-- An open ball in a product space is a product of open balls. See also `metric.ball_pi`
for a version assuming `0 < r` instead of `nonempty β`. -/
theorem ball_pi' [Nonempty β] (x : ∀ b, π b) (r : ℝ) :
ball x r = Set.pi univ fun b => ball (x b) r :=
(lt_or_le 0 r).elim (ball_pi x) fun hr => by simp [ball_eq_empty.2 hr]
#align ball_pi' ball_pi'
/-- A closed ball in a product space is a product of closed balls. See also `metric.closed_ball_pi'`
for a version assuming `nonempty β` instead of `0 ≤ r`. -/
theorem closedBall_pi (x : ∀ b, π b) {r : ℝ} (hr : 0 ≤ r) :
closedBall x r = Set.pi univ fun b => closedBall (x b) r :=
by
ext p
simp [dist_pi_le_iff hr]
#align closed_ball_pi closedBall_pi
/-- A closed ball in a product space is a product of closed balls. See also `metric.closed_ball_pi`
for a version assuming `0 ≤ r` instead of `nonempty β`. -/
theorem closedBall_pi' [Nonempty β] (x : ∀ b, π b) (r : ℝ) :
closedBall x r = Set.pi univ fun b => closedBall (x b) r :=
(le_or_lt 0 r).elim (closedBall_pi x) fun hr => by simp [closed_ball_eq_empty.2 hr]
#align closed_ball_pi' closedBall_pi'
@[simp]
theorem Fin.nndist_insertNth_insertNth {n : ℕ} {α : Fin (n + 1) → Type _}
[∀ i, PseudoMetricSpace (α i)] (i : Fin (n + 1)) (x y : α i) (f g : ∀ j, α (i.succAbove j)) :
nndist (i.insertNth x f) (i.insertNth y g) = max (nndist x y) (nndist f g) :=
eq_of_forall_ge_iff fun c => by simp [nndist_pi_le_iff, i.forall_iff_succ_above]
#align fin.nndist_insert_nth_insert_nth Fin.nndist_insertNth_insertNth
@[simp]
theorem Fin.dist_insertNth_insertNth {n : ℕ} {α : Fin (n + 1) → Type _}
[∀ i, PseudoMetricSpace (α i)] (i : Fin (n + 1)) (x y : α i) (f g : ∀ j, α (i.succAbove j)) :
dist (i.insertNth x f) (i.insertNth y g) = max (dist x y) (dist f g) := by
simp only [dist_nndist, Fin.nndist_insertNth_insertNth, Nnreal.coe_max]
#align fin.dist_insert_nth_insert_nth Fin.dist_insertNth_insertNth
theorem Real.dist_le_of_mem_pi_icc {x y x' y' : β → ℝ} (hx : x ∈ icc x' y') (hy : y ∈ icc x' y') :
dist x y ≤ dist x' y' :=
by
refine'
(dist_pi_le_iff dist_nonneg).2 fun b =>
(Real.dist_le_of_mem_uIcc _ _).trans (dist_le_pi_dist _ _ b) <;>
refine' Icc_subset_uIcc _
exacts[⟨hx.1 _, hx.2 _⟩, ⟨hy.1 _, hy.2 _⟩]
#align real.dist_le_of_mem_pi_Icc Real.dist_le_of_mem_pi_icc
end Pi
section Compact
/- ./././Mathport/Syntax/Translate/Basic.lean:632:2: warning: expanding binder collection (t «expr ⊆ » s) -/
/-- Any compact set in a pseudometric space can be covered by finitely many balls of a given
positive radius -/
theorem finite_cover_balls_of_compact {α : Type u} [PseudoMetricSpace α] {s : Set α}
(hs : IsCompact s) {e : ℝ} (he : 0 < e) :
∃ (t : _)(_ : t ⊆ s), Set.Finite t ∧ s ⊆ ⋃ x ∈ t, ball x e :=
by
apply hs.elim_finite_subcover_image
· simp [is_open_ball]
· intro x xs
simp
exact ⟨x, ⟨xs, by simpa⟩⟩
#align finite_cover_balls_of_compact finite_cover_balls_of_compact
alias finite_cover_balls_of_compact ← IsCompact.finite_cover_balls
#align is_compact.finite_cover_balls IsCompact.finite_cover_balls
end Compact
section ProperSpace
open Metric
/-- A pseudometric space is proper if all closed balls are compact. -/
class ProperSpace (α : Type u) [PseudoMetricSpace α] : Prop where
is_compact_closed_ball : ∀ x : α, ∀ r, IsCompact (closedBall x r)
#align proper_space ProperSpace
export ProperSpace (is_compact_closed_ball)
/-- In a proper pseudometric space, all spheres are compact. -/
theorem isCompact_sphere {α : Type _} [PseudoMetricSpace α] [ProperSpace α] (x : α) (r : ℝ) :
IsCompact (sphere x r) :=
isCompact_of_isClosed_subset (isCompact_closedBall x r) isClosed_sphere sphere_subset_closedBall
#align is_compact_sphere isCompact_sphere
/-- In a proper pseudometric space, any sphere is a `compact_space` when considered as a subtype. -/
instance {α : Type _} [PseudoMetricSpace α] [ProperSpace α] (x : α) (r : ℝ) :
CompactSpace (sphere x r) :=
isCompact_iff_compactSpace.mp (isCompact_sphere _ _)
-- see Note [lower instance priority]
/-- A proper pseudo metric space is sigma compact, and therefore second countable. -/
instance (priority := 100) second_countable_of_proper [ProperSpace α] : SecondCountableTopology α :=
by
-- We already have `sigma_compact_space_of_locally_compact_second_countable`, so we don't
-- add an instance for `sigma_compact_space`.
suffices SigmaCompactSpace α by exact Emetric.second_countable_of_sigma_compact α
rcases em (Nonempty α) with (⟨⟨x⟩⟩ | hn)
· exact ⟨⟨fun n => closed_ball x n, fun n => is_compact_closed_ball _ _, Union_closed_ball_nat _⟩⟩
· exact ⟨⟨fun n => ∅, fun n => isCompact_empty, Union_eq_univ_iff.2 fun x => (hn ⟨x⟩).elim⟩⟩
#align second_countable_of_proper second_countable_of_proper
theorem tendsto_dist_right_cocompact_atTop [ProperSpace α] (x : α) :
Tendsto (fun y => dist y x) (cocompact α) atTop :=
(hasBasis_cocompact.tendsto_iff atTop_basis).2 fun r hr =>
⟨closedBall x r, isCompact_closedBall x r, fun y hy => (not_le.1 <| mt mem_closedBall.2 hy).le⟩
#align tendsto_dist_right_cocompact_at_top tendsto_dist_right_cocompact_atTop
theorem tendsto_dist_left_cocompact_atTop [ProperSpace α] (x : α) :
Tendsto (dist x) (cocompact α) atTop := by
simpa only [dist_comm] using tendsto_dist_right_cocompact_atTop x
#align tendsto_dist_left_cocompact_at_top tendsto_dist_left_cocompact_atTop
/-- If all closed balls of large enough radius are compact, then the space is proper. Especially
useful when the lower bound for the radius is 0. -/
theorem properSpace_of_compact_closedBall_of_le (R : ℝ)
(h : ∀ x : α, ∀ r, R ≤ r → IsCompact (closedBall x r)) : ProperSpace α :=
⟨by
intro x r
by_cases hr : R ≤ r
· exact h x r hr
· have : closed_ball x r = closed_ball x R ∩ closed_ball x r :=
by
symm
apply inter_eq_self_of_subset_right
exact closed_ball_subset_closed_ball (le_of_lt (not_le.1 hr))
rw [this]
exact (h x R le_rfl).inter_right is_closed_ball⟩
#align proper_space_of_compact_closed_ball_of_le properSpace_of_compact_closedBall_of_le
-- A compact pseudometric space is proper
-- see Note [lower instance priority]
instance (priority := 100) proper_of_compact [CompactSpace α] : ProperSpace α :=
⟨fun x r => isClosed_ball.IsCompact⟩
#align proper_of_compact proper_of_compact
-- see Note [lower instance priority]
/-- A proper space is locally compact -/
instance (priority := 100) locally_compact_of_proper [ProperSpace α] : LocallyCompactSpace α :=
locallyCompactSpace_of_hasBasis (fun x => nhds_basis_closedBall) fun x ε ε0 =>
isCompact_closedBall _ _
#align locally_compact_of_proper locally_compact_of_proper
/- ./././Mathport/Syntax/Translate/Basic.lean:632:2: warning: expanding binder collection (x y «expr ∈ » t) -/
-- see Note [lower instance priority]
/-- A proper space is complete -/
instance (priority := 100) complete_of_proper [ProperSpace α] : CompleteSpace α :=
⟨by
intro f hf
/- We want to show that the Cauchy filter `f` is converging. It suffices to find a closed
ball (therefore compact by properness) where it is nontrivial. -/
obtain ⟨t, t_fset, ht⟩ : ∃ t ∈ f, ∀ (x) (_ : x ∈ t) (y) (_ : y ∈ t), dist x y < 1 :=
(Metric.cauchy_iff.1 hf).2 1 zero_lt_one
rcases hf.1.nonempty_of_mem t_fset with ⟨x, xt⟩
have : closed_ball x 1 ∈ f := mem_of_superset t_fset fun y yt => (ht y yt x xt).le
rcases(isCompact_iff_totallyBounded_isComplete.1 (is_compact_closed_ball x 1)).2 f hf
(le_principal_iff.2 this) with
⟨y, -, hy⟩
exact ⟨y, hy⟩⟩
#align complete_of_proper complete_of_proper
/-- A finite product of proper spaces is proper. -/
instance pi_properSpace {π : β → Type _} [Fintype β] [∀ b, PseudoMetricSpace (π b)]
[h : ∀ b, ProperSpace (π b)] : ProperSpace (∀ b, π b) :=
by
refine' properSpace_of_compact_closedBall_of_le 0 fun x r hr => _
rw [closedBall_pi _ hr]
apply isCompact_univ_pi fun b => _
apply (h b).is_compact_closed_ball
#align pi_proper_space pi_properSpace
variable [ProperSpace α] {x : α} {r : ℝ} {s : Set α}
/-- If a nonempty ball in a proper space includes a closed set `s`, then there exists a nonempty
ball with the same center and a strictly smaller radius that includes `s`. -/
theorem exists_pos_lt_subset_ball (hr : 0 < r) (hs : IsClosed s) (h : s ⊆ ball x r) :
∃ r' ∈ Ioo 0 r, s ⊆ ball x r' :=
by
rcases eq_empty_or_nonempty s with (rfl | hne)
· exact ⟨r / 2, ⟨half_pos hr, half_lt_self hr⟩, empty_subset _⟩
have : IsCompact s :=
isCompact_of_isClosed_subset (is_compact_closed_ball x r) hs
(subset.trans h ball_subset_closed_ball)
obtain ⟨y, hys, hy⟩ : ∃ y ∈ s, s ⊆ closed_ball x (dist y x)
exact this.exists_forall_ge hne (continuous_id.dist continuous_const).ContinuousOn
have hyr : dist y x < r := h hys
rcases exists_between hyr with ⟨r', hyr', hrr'⟩
exact ⟨r', ⟨dist_nonneg.trans_lt hyr', hrr'⟩, subset.trans hy <| closed_ball_subset_ball hyr'⟩
#align exists_pos_lt_subset_ball exists_pos_lt_subset_ball
/-- If a ball in a proper space includes a closed set `s`, then there exists a ball with the same
center and a strictly smaller radius that includes `s`. -/
theorem exists_lt_subset_ball (hs : IsClosed s) (h : s ⊆ ball x r) : ∃ r' < r, s ⊆ ball x r' :=
by
cases' le_or_lt r 0 with hr hr
· rw [ball_eq_empty.2 hr, subset_empty_iff] at h
subst s
exact (exists_lt r).imp fun r' hr' => ⟨hr', empty_subset _⟩
· exact (exists_pos_lt_subset_ball hr hs h).imp fun r' hr' => ⟨hr'.fst.2, hr'.snd⟩
#align exists_lt_subset_ball exists_lt_subset_ball
end ProperSpace
theorem IsCompact.isSeparable {s : Set α} (hs : IsCompact s) : IsSeparable s :=
haveI : CompactSpace s := is_compact_iff_compact_space.mp hs
is_separable_of_separable_space_subtype s
#align is_compact.is_separable IsCompact.isSeparable
namespace Metric
section SecondCountable
open TopologicalSpace
/-- A pseudometric space is second countable if, for every `ε > 0`, there is a countable set which
is `ε`-dense. -/
theorem second_countable_of_almost_dense_set
(H : ∀ ε > (0 : ℝ), ∃ s : Set α, s.Countable ∧ ∀ x, ∃ y ∈ s, dist x y ≤ ε) :
SecondCountableTopology α :=
by
refine' Emetric.second_countable_of_almost_dense_set fun ε ε0 => _
rcases Ennreal.lt_iff_exists_nnreal_btwn.1 ε0 with ⟨ε', ε'0, ε'ε⟩
choose s hsc y hys hyx using H ε' (by exact_mod_cast ε'0)
refine' ⟨s, hsc, Union₂_eq_univ_iff.2 fun x => ⟨y x, hys _, le_trans _ ε'ε.le⟩⟩
exact_mod_cast hyx x
#align metric.second_countable_of_almost_dense_set Metric.second_countable_of_almost_dense_set
end SecondCountable
end Metric
theorem lebesgue_number_lemma_of_metric {s : Set α} {ι} {c : ι → Set α} (hs : IsCompact s)
(hc₁ : ∀ i, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i :=
let ⟨n, en, hn⟩ := lebesgue_number_lemma hs hc₁ hc₂
let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 en
⟨δ, δ0, fun x hx =>
let ⟨i, hi⟩ := hn x hx
⟨i, fun y hy => hi (hδ (mem_ball'.mp hy))⟩⟩
#align lebesgue_number_lemma_of_metric lebesgue_number_lemma_of_metric
theorem lebesgue_number_lemma_of_metric_unionₛ {s : Set α} {c : Set (Set α)} (hs : IsCompact s)
(hc₁ : ∀ t ∈ c, IsOpen t) (hc₂ : s ⊆ ⋃₀ c) : ∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t := by
rw [sUnion_eq_Union] at hc₂ <;> simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂
#align lebesgue_number_lemma_of_metric_sUnion lebesgue_number_lemma_of_metric_unionₛ
namespace Metric
/- ./././Mathport/Syntax/Translate/Basic.lean:632:2: warning: expanding binder collection (x y «expr ∈ » s) -/
/-- Boundedness of a subset of a pseudometric space. We formulate the definition to work
even in the empty space. -/
def Bounded (s : Set α) : Prop :=
∃ C, ∀ (x) (_ : x ∈ s) (y) (_ : y ∈ s), dist x y ≤ C
#align metric.bounded Metric.Bounded
section Bounded
variable {x : α} {s t : Set α} {r : ℝ}
theorem bounded_iff_isBounded (s : Set α) : Bounded s ↔ IsBounded s :=
by
change bounded s ↔ sᶜ ∈ (cobounded α).sets
simp [PseudoMetricSpace.cobounded_sets, Metric.Bounded]
#align metric.bounded_iff_is_bounded Metric.bounded_iff_isBounded
@[simp]
theorem bounded_empty : Bounded (∅ : Set α) :=
⟨0, by simp⟩
#align metric.bounded_empty Metric.bounded_empty
theorem bounded_iff_mem_bounded : Bounded s ↔ ∀ x ∈ s, Bounded s :=
⟨fun h _ _ => h, fun H =>
s.eq_empty_or_nonempty.elim (fun hs => hs.symm ▸ bounded_empty) fun ⟨x, hx⟩ => H x hx⟩
#align metric.bounded_iff_mem_bounded Metric.bounded_iff_mem_bounded
/-- Subsets of a bounded set are also bounded -/
theorem Bounded.mono (incl : s ⊆ t) : Bounded t → Bounded s :=
Exists.imp fun C hC x hx y hy => hC x (incl hx) y (incl hy)
#align metric.bounded.mono Metric.Bounded.mono
/-- Closed balls are bounded -/
theorem bounded_closedBall : Bounded (closedBall x r) :=
⟨r + r, fun y hy z hz => by
simp only [mem_closed_ball] at *
calc
dist y z ≤ dist y x + dist z x := dist_triangle_right _ _ _
_ ≤ r + r := add_le_add hy hz
⟩
#align metric.bounded_closed_ball Metric.bounded_closedBall
/-- Open balls are bounded -/
theorem bounded_ball : Bounded (ball x r) :=
bounded_closedBall.mono ball_subset_closedBall
#align metric.bounded_ball Metric.bounded_ball
/-- Spheres are bounded -/
theorem bounded_sphere : Bounded (sphere x r) :=
bounded_closedBall.mono sphere_subset_closedBall
#align metric.bounded_sphere Metric.bounded_sphere
/-- Given a point, a bounded subset is included in some ball around this point -/
theorem bounded_iff_subset_ball (c : α) : Bounded s ↔ ∃ r, s ⊆ closedBall c r :=
by
constructor <;> rintro ⟨C, hC⟩
· cases' s.eq_empty_or_nonempty with h h
· subst s
exact ⟨0, by simp⟩
· rcases h with ⟨x, hx⟩
exact
⟨C + dist x c, fun y hy =>
calc
dist y c ≤ dist y x + dist x c := dist_triangle _ _ _
_ ≤ C + dist x c := add_le_add_right (hC y hy x hx) _
⟩
· exact bounded_closed_ball.mono hC
#align metric.bounded_iff_subset_ball Metric.bounded_iff_subset_ball
theorem Bounded.subset_ball (h : Bounded s) (c : α) : ∃ r, s ⊆ closedBall c r :=
(bounded_iff_subset_ball c).1 h
#align metric.bounded.subset_ball Metric.Bounded.subset_ball
theorem Bounded.subset_ball_lt (h : Bounded s) (a : ℝ) (c : α) : ∃ r, a < r ∧ s ⊆ closedBall c r :=
by
rcases h.subset_ball c with ⟨r, hr⟩
refine' ⟨max r (a + 1), lt_of_lt_of_le (by linarith) (le_max_right _ _), _⟩
exact subset.trans hr (closed_ball_subset_closed_ball (le_max_left _ _))
#align metric.bounded.subset_ball_lt Metric.Bounded.subset_ball_lt
theorem bounded_closure_of_bounded (h : Bounded s) : Bounded (closure s) :=
let ⟨C, h⟩ := h
⟨C, fun a ha b hb => (isClosed_le' C).closure_subset <| map_mem_closure₂ continuous_dist ha hb h⟩
#align metric.bounded_closure_of_bounded Metric.bounded_closure_of_bounded
alias bounded_closure_of_bounded ← bounded.closure
#align metric.bounded.closure Metric.Bounded.closure
@[simp]
theorem bounded_closure_iff : Bounded (closure s) ↔ Bounded s :=
⟨fun h => h.mono subset_closure, fun h => h.closure⟩
#align metric.bounded_closure_iff Metric.bounded_closure_iff
/-- The union of two bounded sets is bounded. -/
theorem Bounded.union (hs : Bounded s) (ht : Bounded t) : Bounded (s ∪ t) :=
by
refine' bounded_iff_mem_bounded.2 fun x _ => _
rw [bounded_iff_subset_ball x] at hs ht⊢
rcases hs with ⟨Cs, hCs⟩; rcases ht with ⟨Ct, hCt⟩
exact
⟨max Cs Ct,
union_subset (subset.trans hCs <| closed_ball_subset_closed_ball <| le_max_left _ _)
(subset.trans hCt <| closed_ball_subset_closed_ball <| le_max_right _ _)⟩
#align metric.bounded.union Metric.Bounded.union
/-- The union of two sets is bounded iff each of the sets is bounded. -/
@[simp]
theorem bounded_union : Bounded (s ∪ t) ↔ Bounded s ∧ Bounded t :=
⟨fun h => ⟨h.mono (by simp), h.mono (by simp)⟩, fun h => h.1.union h.2⟩
#align metric.bounded_union Metric.bounded_union
/-- A finite union of bounded sets is bounded -/
theorem bounded_bUnion {I : Set β} {s : β → Set α} (H : I.Finite) :
Bounded (⋃ i ∈ I, s i) ↔ ∀ i ∈ I, Bounded (s i) :=
Finite.induction_on H (by simp) fun x I _ _ IH => by simp [or_imp, forall_and, IH]
#align metric.bounded_bUnion Metric.bounded_bUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
protected theorem Bounded.prod [PseudoMetricSpace β] {s : Set α} {t : Set β} (hs : Bounded s)
(ht : Bounded t) : Bounded (s ×ˢ t) :=
by
refine' bounded_iff_mem_bounded.mpr fun x hx => _
rcases hs.subset_ball x.1 with ⟨rs, hrs⟩
rcases ht.subset_ball x.2 with ⟨rt, hrt⟩
suffices : s ×ˢ t ⊆ closed_ball x (max rs rt)
exact bounded_closed_ball.mono this
rw [← @Prod.mk.eta _ _ x, ← closedBall_prod_same]
exact
prod_mono (hrs.trans <| closed_ball_subset_closed_ball <| le_max_left _ _)
(hrt.trans <| closed_ball_subset_closed_ball <| le_max_right _ _)
#align metric.bounded.prod Metric.Bounded.prod
/-- A totally bounded set is bounded -/
theorem TotallyBounded.bounded {s : Set α} (h : TotallyBounded s) : Bounded s :=
let-- We cover the totally bounded set by finitely many balls of radius 1,
-- and then argue that a finite union of bounded sets is bounded
⟨t, fint, subs⟩ :=
(totallyBounded_iff.mp h) 1 zero_lt_one
Bounded.mono subs <| (bounded_bUnion fint).2 fun i hi => bounded_ball
#align totally_bounded.bounded TotallyBounded.bounded
/-- A compact set is bounded -/
theorem IsCompact.bounded {s : Set α} (h : IsCompact s) : Bounded s :=
-- A compact set is totally bounded, thus bounded
h.TotallyBounded.Bounded
#align is_compact.bounded IsCompact.bounded
/-- A finite set is bounded -/
theorem bounded_of_finite {s : Set α} (h : s.Finite) : Bounded s :=
h.IsCompact.Bounded
#align metric.bounded_of_finite Metric.bounded_of_finite
alias bounded_of_finite ← _root_.set.finite.bounded
#align set.finite.bounded Set.Finite.bounded
/-- A singleton is bounded -/
theorem bounded_singleton {x : α} : Bounded ({x} : Set α) :=
bounded_of_finite <| finite_singleton _
#align metric.bounded_singleton Metric.bounded_singleton
/-- Characterization of the boundedness of the range of a function -/
theorem bounded_range_iff {f : β → α} : Bounded (range f) ↔ ∃ C, ∀ x y, dist (f x) (f y) ≤ C :=
exists_congr fun C =>
⟨fun H x y => H _ ⟨x, rfl⟩ _ ⟨y, rfl⟩, by rintro H _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ <;> exact H x y⟩
#align metric.bounded_range_iff Metric.bounded_range_iff
theorem bounded_range_of_tendsto_cofinite_uniformity {f : β → α}
(hf : Tendsto (Prod.map f f) (cofinite ×ᶠ cofinite) (𝓤 α)) : Bounded (range f) :=
by
rcases(has_basis_cofinite.prod_self.tendsto_iff uniformity_basis_dist).1 hf 1 zero_lt_one with
⟨s, hsf, hs1⟩
rw [← image_univ, ← union_compl_self s, image_union, bounded_union]
use (hsf.image f).Bounded, 1
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩
exact le_of_lt (hs1 (x, y) ⟨hx, hy⟩)
#align metric.bounded_range_of_tendsto_cofinite_uniformity Metric.bounded_range_of_tendsto_cofinite_uniformity
theorem bounded_range_of_cauchy_map_cofinite {f : β → α} (hf : Cauchy (map f cofinite)) :
Bounded (range f) :=
bounded_range_of_tendsto_cofinite_uniformity <| (cauchy_map_iff.1 hf).2
#align metric.bounded_range_of_cauchy_map_cofinite Metric.bounded_range_of_cauchy_map_cofinite
theorem CauchySeq.bounded_range {f : ℕ → α} (hf : CauchySeq f) : Bounded (range f) :=
bounded_range_of_cauchy_map_cofinite <| by rwa [Nat.cofinite_eq_atTop]
#align cauchy_seq.bounded_range CauchySeq.bounded_range
theorem bounded_range_of_tendsto_cofinite {f : β → α} {a : α} (hf : Tendsto f cofinite (𝓝 a)) :
Bounded (range f) :=
bounded_range_of_tendsto_cofinite_uniformity <|
(hf.prod_map hf).mono_right <| nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)
#align metric.bounded_range_of_tendsto_cofinite Metric.bounded_range_of_tendsto_cofinite
/-- In a compact space, all sets are bounded -/
theorem bounded_of_compactSpace [CompactSpace α] : Bounded s :=
isCompact_univ.Bounded.mono (subset_univ _)
#align metric.bounded_of_compact_space Metric.bounded_of_compactSpace
theorem bounded_range_of_tendsto (u : ℕ → α) {x : α} (hu : Tendsto u atTop (𝓝 x)) :
Bounded (range u) :=
hu.CauchySeq.bounded_range
#align metric.bounded_range_of_tendsto Metric.bounded_range_of_tendsto
/-- If a function is continuous within a set `s` at every point of a compact set `k`, then it is
bounded on some open neighborhood of `k` in `s`. -/
theorem exists_isOpen_bounded_image_inter_of_isCompact_of_forall_continuousWithinAt
[TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k)
(hf : ∀ x ∈ k, ContinuousWithinAt f s x) : ∃ t, k ⊆ t ∧ IsOpen t ∧ Bounded (f '' (t ∩ s)) :=
by
apply hk.induction_on
· exact ⟨∅, subset.refl _, isOpen_empty, by simp only [image_empty, bounded_empty, empty_inter]⟩
· rintro s s' hss' ⟨t, s't, t_open, t_bounded⟩
exact ⟨t, hss'.trans s't, t_open, t_bounded⟩
· rintro s s' ⟨t, st, t_open, t_bounded⟩ ⟨t', s't', t'_open, t'_bounded⟩
refine' ⟨t ∪ t', union_subset_union st s't', t_open.union t'_open, _⟩
rw [union_inter_distrib_right, image_union]
exact t_bounded.union t'_bounded
· intro x hx
have A : ball (f x) 1 ∈ 𝓝 (f x) := ball_mem_nhds _ zero_lt_one
have B : f ⁻¹' ball (f x) 1 ∈ 𝓝[s] x := hf x hx A
obtain ⟨u, u_open, xu, uf⟩ : ∃ u : Set β, IsOpen u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' ball (f x) 1
exact _root_.mem_nhds_within.1 B
refine' ⟨u, _, u, subset.refl _, u_open, _⟩
· apply nhdsWithin_le_nhds
exact u_open.mem_nhds xu
· apply bounded.mono (image_subset _ uf)
exact bounded_ball.mono (image_preimage_subset _ _)
#align metric.exists_is_open_bounded_image_inter_of_is_compact_of_forall_continuous_within_at Metric.exists_isOpen_bounded_image_inter_of_isCompact_of_forall_continuousWithinAt
/-- If a function is continuous at every point of a compact set `k`, then it is bounded on
some open neighborhood of `k`. -/
theorem exists_isOpen_bounded_image_of_isCompact_of_forall_continuousAt [TopologicalSpace β]
{k : Set β} {f : β → α} (hk : IsCompact k) (hf : ∀ x ∈ k, ContinuousAt f x) :
∃ t, k ⊆ t ∧ IsOpen t ∧ Bounded (f '' t) :=
by
simp_rw [← continuousWithinAt_univ] at hf
simpa only [inter_univ] using
exists_is_open_bounded_image_inter_of_is_compact_of_forall_continuous_within_at hk hf
#align metric.exists_is_open_bounded_image_of_is_compact_of_forall_continuous_at Metric.exists_isOpen_bounded_image_of_isCompact_of_forall_continuousAt
/-- If a function is continuous on a set `s` containing a compact set `k`, then it is bounded on
some open neighborhood of `k` in `s`. -/
theorem exists_isOpen_bounded_image_inter_of_isCompact_of_continuousOn [TopologicalSpace β]
{k s : Set β} {f : β → α} (hk : IsCompact k) (hks : k ⊆ s) (hf : ContinuousOn f s) :
∃ t, k ⊆ t ∧ IsOpen t ∧ Bounded (f '' (t ∩ s)) :=
exists_isOpen_bounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk fun x hx =>
hf x (hks hx)
#align metric.exists_is_open_bounded_image_inter_of_is_compact_of_continuous_on Metric.exists_isOpen_bounded_image_inter_of_isCompact_of_continuousOn
/-- If a function is continuous on a neighborhood of a compact set `k`, then it is bounded on
some open neighborhood of `k`. -/
theorem exists_isOpen_bounded_image_of_isCompact_of_continuousOn [TopologicalSpace β] {k s : Set β}
{f : β → α} (hk : IsCompact k) (hs : IsOpen s) (hks : k ⊆ s) (hf : ContinuousOn f s) :
∃ t, k ⊆ t ∧ IsOpen t ∧ Bounded (f '' t) :=
exists_isOpen_bounded_image_of_isCompact_of_forall_continuousAt hk fun x hx =>
hf.ContinuousAt (hs.mem_nhds (hks hx))
#align metric.exists_is_open_bounded_image_of_is_compact_of_continuous_on Metric.exists_isOpen_bounded_image_of_isCompact_of_continuousOn
/-- The **Heine–Borel theorem**: In a proper space, a closed bounded set is compact. -/
theorem isCompact_of_isClosed_bounded [ProperSpace α] (hc : IsClosed s) (hb : Bounded s) :
IsCompact s := by
rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩)
· exact isCompact_empty
· rcases hb.subset_ball x with ⟨r, hr⟩
exact isCompact_of_isClosed_subset (is_compact_closed_ball x r) hc hr
#align metric.is_compact_of_is_closed_bounded Metric.isCompact_of_isClosed_bounded
/-- The **Heine–Borel theorem**: In a proper space, the closure of a bounded set is compact. -/
theorem Bounded.isCompact_closure [ProperSpace α] (h : Bounded s) : IsCompact (closure s) :=
isCompact_of_isClosed_bounded isClosed_closure h.closure
#align metric.bounded.is_compact_closure Metric.Bounded.isCompact_closure
/-- The **Heine–Borel theorem**:
In a proper Hausdorff space, a set is compact if and only if it is closed and bounded. -/
theorem isCompact_iff_isClosed_bounded [T2Space α] [ProperSpace α] :
IsCompact s ↔ IsClosed s ∧ Bounded s :=
⟨fun h => ⟨h.IsClosed, h.Bounded⟩, fun h => isCompact_of_isClosed_bounded h.1 h.2⟩
#align metric.is_compact_iff_is_closed_bounded Metric.isCompact_iff_isClosed_bounded
theorem compactSpace_iff_bounded_univ [ProperSpace α] : CompactSpace α ↔ Bounded (univ : Set α) :=
⟨@bounded_of_compactSpace α _ _, fun hb => ⟨isCompact_of_isClosed_bounded isClosed_univ hb⟩⟩
#align metric.compact_space_iff_bounded_univ Metric.compactSpace_iff_bounded_univ
section ConditionallyCompleteLinearOrder
variable [Preorder α] [CompactIccSpace α]
theorem bounded_icc (a b : α) : Bounded (Icc a b) :=
(totallyBounded_icc a b).Bounded
#align metric.bounded_Icc Metric.bounded_icc
theorem bounded_ico (a b : α) : Bounded (Ico a b) :=
(totallyBounded_ico a b).Bounded
#align metric.bounded_Ico Metric.bounded_ico
theorem bounded_ioc (a b : α) : Bounded (Ioc a b) :=
(totallyBounded_ioc a b).Bounded
#align metric.bounded_Ioc Metric.bounded_ioc
theorem bounded_ioo (a b : α) : Bounded (Ioo a b) :=
(totallyBounded_ioo a b).Bounded
#align metric.bounded_Ioo Metric.bounded_ioo
/-- In a pseudo metric space with a conditionally complete linear order such that the order and the
metric structure give the same topology, any order-bounded set is metric-bounded. -/
theorem bounded_of_bddAbove_of_bddBelow {s : Set α} (h₁ : BddAbove s) (h₂ : BddBelow s) :
Bounded s :=
let ⟨u, hu⟩ := h₁
let ⟨l, hl⟩ := h₂
Bounded.mono (fun x hx => mem_Icc.mpr ⟨hl hx, hu hx⟩) (bounded_icc l u)
#align metric.bounded_of_bdd_above_of_bdd_below Metric.bounded_of_bddAbove_of_bddBelow
end ConditionallyCompleteLinearOrder
end Bounded
section Diam
variable {s : Set α} {x y z : α}
/-- The diameter of a set in a metric space. To get controllable behavior even when the diameter
should be infinite, we express it in terms of the emetric.diameter -/
noncomputable def diam (s : Set α) : ℝ :=
Ennreal.toReal (Emetric.diam s)
#align metric.diam Metric.diam
/-- The diameter of a set is always nonnegative -/
theorem diam_nonneg : 0 ≤ diam s :=
Ennreal.toReal_nonneg
#align metric.diam_nonneg Metric.diam_nonneg
theorem diam_subsingleton (hs : s.Subsingleton) : diam s = 0 := by
simp only [diam, Emetric.diam_subsingleton hs, Ennreal.zero_toReal]
#align metric.diam_subsingleton Metric.diam_subsingleton
/-- The empty set has zero diameter -/
@[simp]
theorem diam_empty : diam (∅ : Set α) = 0 :=
diam_subsingleton subsingleton_empty
#align metric.diam_empty Metric.diam_empty
/-- A singleton has zero diameter -/
@[simp]
theorem diam_singleton : diam ({x} : Set α) = 0 :=
diam_subsingleton subsingleton_singleton
#align metric.diam_singleton Metric.diam_singleton
-- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x})
theorem diam_pair : diam ({x, y} : Set α) = dist x y := by
simp only [diam, Emetric.diam_pair, dist_edist]
#align metric.diam_pair Metric.diam_pair
/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:75:38: in apply_rules #[["[", expr ne_of_lt, ",", expr edist_lt_top, ",", expr max_lt, "]"], []]: ./././Mathport/Syntax/Translate/Basic.lean:349:22: unsupported: parse error -/
-- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x}))
theorem diam_triple :
Metric.diam ({x, y, z} : Set α) = max (max (dist x y) (dist x z)) (dist y z) :=
by
simp only [Metric.diam, Emetric.diam_triple, dist_edist]
rw [Ennreal.toReal_max, Ennreal.toReal_max] <;>
trace
"./././Mathport/Syntax/Translate/Tactic/Builtin.lean:75:38: in apply_rules #[[\"[\", expr ne_of_lt, \",\", expr edist_lt_top, \",\", expr max_lt, \"]\"], []]: ./././Mathport/Syntax/Translate/Basic.lean:349:22: unsupported: parse error"
#align metric.diam_triple Metric.diam_triple
/-- If the distance between any two points in a set is bounded by some constant `C`,
then `ennreal.of_real C` bounds the emetric diameter of this set. -/
theorem ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) :
Emetric.diam s ≤ Ennreal.ofReal C :=
Emetric.diam_le fun x hx y hy => (edist_dist x y).symm ▸ Ennreal.ofReal_le_ofReal (h x hx y hy)
#align metric.ediam_le_of_forall_dist_le Metric.ediam_le_of_forall_dist_le
/-- If the distance between any two points in a set is bounded by some non-negative constant,
this constant bounds the diameter. -/
theorem diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) :
diam s ≤ C :=
Ennreal.toReal_le_of_le_ofReal h₀ (ediam_le_of_forall_dist_le h)
#align metric.diam_le_of_forall_dist_le Metric.diam_le_of_forall_dist_le
/-- If the distance between any two points in a nonempty set is bounded by some constant,
this constant bounds the diameter. -/
theorem diam_le_of_forall_dist_le_of_nonempty (hs : s.Nonempty) {C : ℝ}
(h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) : diam s ≤ C :=
have h₀ : 0 ≤ C :=
let ⟨x, hx⟩ := hs
le_trans dist_nonneg (h x hx x hx)
diam_le_of_forall_dist_le h₀ h
#align metric.diam_le_of_forall_dist_le_of_nonempty Metric.diam_le_of_forall_dist_le_of_nonempty
/-- The distance between two points in a set is controlled by the diameter of the set. -/
theorem dist_le_diam_of_mem' (h : Emetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) :
dist x y ≤ diam s := by
rw [diam, dist_edist]
rw [Ennreal.toReal_le_toReal (edist_ne_top _ _) h]
exact Emetric.edist_le_diam_of_mem hx hy
#align metric.dist_le_diam_of_mem' Metric.dist_le_diam_of_mem'
/-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/
theorem bounded_iff_ediam_ne_top : Bounded s ↔ Emetric.diam s ≠ ⊤ :=
Iff.intro
(fun ⟨C, hC⟩ => ne_top_of_le_ne_top Ennreal.ofReal_ne_top <| ediam_le_of_forall_dist_le hC)
fun h => ⟨diam s, fun x hx y hy => dist_le_diam_of_mem' h hx hy⟩
#align metric.bounded_iff_ediam_ne_top Metric.bounded_iff_ediam_ne_top
theorem Bounded.ediam_ne_top (h : Bounded s) : Emetric.diam s ≠ ⊤ :=
bounded_iff_ediam_ne_top.1 h
#align metric.bounded.ediam_ne_top Metric.Bounded.ediam_ne_top
theorem ediam_univ_eq_top_iff_noncompact [ProperSpace α] :
Emetric.diam (univ : Set α) = ∞ ↔ NoncompactSpace α := by
rw [← not_compactSpace_iff, compact_space_iff_bounded_univ, bounded_iff_ediam_ne_top, not_not]
#align metric.ediam_univ_eq_top_iff_noncompact Metric.ediam_univ_eq_top_iff_noncompact
@[simp]
theorem ediam_univ_of_noncompact [ProperSpace α] [NoncompactSpace α] :
Emetric.diam (univ : Set α) = ∞ :=
ediam_univ_eq_top_iff_noncompact.mpr ‹_›
#align metric.ediam_univ_of_noncompact Metric.ediam_univ_of_noncompact
@[simp]
theorem diam_univ_of_noncompact [ProperSpace α] [NoncompactSpace α] : diam (univ : Set α) = 0 := by
simp [diam]
#align metric.diam_univ_of_noncompact Metric.diam_univ_of_noncompact
/-- The distance between two points in a set is controlled by the diameter of the set. -/
theorem dist_le_diam_of_mem (h : Bounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s :=
dist_le_diam_of_mem' h.ediam_ne_top hx hy
#align metric.dist_le_diam_of_mem Metric.dist_le_diam_of_mem
theorem ediam_of_unbounded (h : ¬Bounded s) : Emetric.diam s = ∞ := by
rwa [bounded_iff_ediam_ne_top, not_not] at h
#align metric.ediam_of_unbounded Metric.ediam_of_unbounded
/-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `emetric.diam`.
This lemma makes it possible to avoid side conditions in some situations -/
theorem diam_eq_zero_of_unbounded (h : ¬Bounded s) : diam s = 0 := by
rw [diam, ediam_of_unbounded h, Ennreal.top_toReal]
#align metric.diam_eq_zero_of_unbounded Metric.diam_eq_zero_of_unbounded
/-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/
theorem diam_mono {s t : Set α} (h : s ⊆ t) (ht : Bounded t) : diam s ≤ diam t :=
by
unfold diam
rw [Ennreal.toReal_le_toReal (bounded.mono h ht).ediam_ne_top ht.ediam_ne_top]
exact Emetric.diam_mono h
#align metric.diam_mono Metric.diam_mono
/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:75:38: in apply_rules #[["[", expr add_nonneg, ",", expr diam_nonneg, ",", expr dist_nonneg, "]"], []]: ./././Mathport/Syntax/Translate/Basic.lean:349:22: unsupported: parse error -/
/-- The diameter of a union is controlled by the sum of the diameters, and the distance between
any two points in each of the sets. This lemma is true without any side condition, since it is
obviously true if `s ∪ t` is unbounded. -/
theorem diam_union {t : Set α} (xs : x ∈ s) (yt : y ∈ t) :
diam (s ∪ t) ≤ diam s + dist x y + diam t :=
by
by_cases H : bounded (s ∪ t)
· have hs : bounded s := H.mono (subset_union_left _ _)
have ht : bounded t := H.mono (subset_union_right _ _)
rw [bounded_iff_ediam_ne_top] at H hs ht
rw [dist_edist, diam, diam, diam, ← Ennreal.toReal_add, ← Ennreal.toReal_add,
Ennreal.toReal_le_toReal] <;>
repeat' apply Ennreal.add_ne_top.2 <;> constructor <;>
try assumption <;>
try apply edist_ne_top
exact Emetric.diam_union xs yt
· rw [diam_eq_zero_of_unbounded H]
trace
"./././Mathport/Syntax/Translate/Tactic/Builtin.lean:75:38: in apply_rules #[[\"[\", expr add_nonneg, \",\", expr diam_nonneg, \",\", expr dist_nonneg, \"]\"], []]: ./././Mathport/Syntax/Translate/Basic.lean:349:22: unsupported: parse error"
#align metric.diam_union Metric.diam_union
/-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/
theorem diam_union' {t : Set α} (h : (s ∩ t).Nonempty) : diam (s ∪ t) ≤ diam s + diam t :=
by
rcases h with ⟨x, ⟨xs, xt⟩⟩
simpa using diam_union xs xt
#align metric.diam_union' Metric.diam_union'
theorem diam_le_of_subset_closedBall {r : ℝ} (hr : 0 ≤ r) (h : s ⊆ closedBall x r) :
diam s ≤ 2 * r :=
diam_le_of_forall_dist_le (mul_nonneg zero_le_two hr) fun a ha b hb =>
calc
dist a b ≤ dist a x + dist b x := dist_triangle_right _ _ _
_ ≤ r + r := add_le_add (h ha) (h hb)
_ = 2 * r := by simp [mul_two, mul_comm]
#align metric.diam_le_of_subset_closed_ball Metric.diam_le_of_subset_closedBall
/-- The diameter of a closed ball of radius `r` is at most `2 r`. -/
theorem diam_closedBall {r : ℝ} (h : 0 ≤ r) : diam (closedBall x r) ≤ 2 * r :=
diam_le_of_subset_closedBall h Subset.rfl
#align metric.diam_closed_ball Metric.diam_closedBall
/-- The diameter of a ball of radius `r` is at most `2 r`. -/
theorem diam_ball {r : ℝ} (h : 0 ≤ r) : diam (ball x r) ≤ 2 * r :=
diam_le_of_subset_closedBall h ball_subset_closedBall
#align metric.diam_ball Metric.diam_ball
/-- If a family of complete sets with diameter tending to `0` is such that each finite intersection
is nonempty, then the total intersection is also nonempty. -/
theorem IsComplete.nonempty_interᵢ_of_nonempty_bInter {s : ℕ → Set α} (h0 : IsComplete (s 0))
(hs : ∀ n, IsClosed (s n)) (h's : ∀ n, Bounded (s n)) (h : ∀ N, (⋂ n ≤ N, s n).Nonempty)
(h' : Tendsto (fun n => diam (s n)) atTop (𝓝 0)) : (⋂ n, s n).Nonempty :=
by
let u N := (h N).some
have I : ∀ n N, n ≤ N → u N ∈ s n := by
intro n N hn
apply mem_of_subset_of_mem _ (h N).some_spec
intro x hx
simp only [mem_Inter] at hx
exact hx n hn
have : ∀ n, u n ∈ s 0 := fun n => I 0 n (zero_le _)
have : CauchySeq u := by
apply cauchySeq_of_le_tendsto_0 _ _ h'
intro m n N hm hn
exact dist_le_diam_of_mem (h's N) (I _ _ hm) (I _ _ hn)
obtain ⟨x, hx, xlim⟩ : ∃ (x : α)(H : x ∈ s 0), tendsto (fun n : ℕ => u n) at_top (𝓝 x) :=
cauchySeq_tendsto_of_isComplete h0 (fun n => I 0 n (zero_le _)) this
refine' ⟨x, mem_Inter.2 fun n => _⟩
apply (hs n).mem_of_tendsto xlim
filter_upwards [Ici_mem_at_top n]with p hp
exact I n p hp
#align is_complete.nonempty_Inter_of_nonempty_bInter IsComplete.nonempty_interᵢ_of_nonempty_bInter
/-- In a complete space, if a family of closed sets with diameter tending to `0` is such that each
finite intersection is nonempty, then the total intersection is also nonempty. -/
theorem nonempty_interᵢ_of_nonempty_bInter [CompleteSpace α] {s : ℕ → Set α}
(hs : ∀ n, IsClosed (s n)) (h's : ∀ n, Bounded (s n)) (h : ∀ N, (⋂ n ≤ N, s n).Nonempty)
(h' : Tendsto (fun n => diam (s n)) atTop (𝓝 0)) : (⋂ n, s n).Nonempty :=
(hs 0).IsComplete.nonempty_Inter_of_nonempty_bInter hs h's h h'
#align metric.nonempty_Inter_of_nonempty_bInter Metric.nonempty_interᵢ_of_nonempty_bInter
end Diam
theorem exists_local_min_mem_ball [ProperSpace α] [TopologicalSpace β]
[ConditionallyCompleteLinearOrder β] [OrderTopology β] {f : α → β} {a z : α} {r : ℝ}
(hf : ContinuousOn f (closedBall a r)) (hz : z ∈ closedBall a r)
(hf1 : ∀ z' ∈ sphere a r, f z < f z') : ∃ z ∈ ball a r, IsLocalMin f z :=
by
simp_rw [← closed_ball_diff_ball] at hf1
exact
(is_compact_closed_ball a r).exists_local_min_mem_open ball_subset_closed_ball hf hz hf1
is_open_ball
#align metric.exists_local_min_mem_ball Metric.exists_local_min_mem_ball
end Metric
namespace Tactic
open Positivity
/-- Extension for the `positivity` tactic: the diameter of a set is always nonnegative. -/
@[positivity]
unsafe def positivity_diam : expr → tactic strictness
| q(Metric.diam $(s)) => nonnegative <$> mk_app `` Metric.diam_nonneg [s]
| e => pp e >>= fail ∘ format.bracket "The expression " " is not of the form `metric.diam s`"
#align tactic.positivity_diam tactic.positivity_diam
end Tactic
theorem comap_dist_right_atTop_le_cocompact (x : α) :
comap (fun y => dist y x) atTop ≤ cocompact α :=
by
refine' filter.has_basis_cocompact.ge_iff.2 fun s hs => mem_comap.2 _
rcases hs.bounded.subset_ball x with ⟨r, hr⟩
exact ⟨Ioi r, Ioi_mem_at_top r, fun y hy hys => (mem_closed_ball.1 <| hr hys).not_lt hy⟩
#align comap_dist_right_at_top_le_cocompact comap_dist_right_atTop_le_cocompact
theorem comap_dist_left_atTop_le_cocompact (x : α) : comap (dist x) atTop ≤ cocompact α := by
simpa only [dist_comm _ x] using comap_dist_right_atTop_le_cocompact x
#align comap_dist_left_at_top_le_cocompact comap_dist_left_atTop_le_cocompact
theorem comap_dist_right_atTop_eq_cocompact [ProperSpace α] (x : α) :
comap (fun y => dist y x) atTop = cocompact α :=
(comap_dist_right_atTop_le_cocompact x).antisymm <|
(tendsto_dist_right_cocompact_atTop x).le_comap
#align comap_dist_right_at_top_eq_cocompact comap_dist_right_atTop_eq_cocompact
theorem comap_dist_left_atTop_eq_cocompact [ProperSpace α] (x : α) :
comap (dist x) atTop = cocompact α :=
(comap_dist_left_atTop_le_cocompact x).antisymm <| (tendsto_dist_left_cocompact_atTop x).le_comap
#align comap_dist_left_at_top_eq_cocompact comap_dist_left_atTop_eq_cocompact
theorem tendsto_cocompact_of_tendsto_dist_comp_atTop {f : β → α} {l : Filter β} (x : α)
(h : Tendsto (fun y => dist (f y) x) l atTop) : Tendsto f l (cocompact α) :=
by
refine' tendsto.mono_right _ (comap_dist_right_atTop_le_cocompact x)
rwa [tendsto_comap_iff]
#align tendsto_cocompact_of_tendsto_dist_comp_at_top tendsto_cocompact_of_tendsto_dist_comp_atTop
/-- We now define `metric_space`, extending `pseudo_metric_space`. -/
class MetricSpace (α : Type u) extends PseudoMetricSpace α : Type u where
eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y
#align metric_space MetricSpace
/-- Two metric space structures with the same distance coincide. -/
@[ext]
theorem MetricSpace.ext {α : Type _} {m m' : MetricSpace α} (h : m.toHasDist = m'.toHasDist) :
m = m' :=
by
have h' : m.to_pseudo_metric_space = m'.to_pseudo_metric_space := PseudoMetricSpace.ext h
rcases m with ⟨⟩
rcases m' with ⟨⟩
dsimp at h'
subst h'
#align metric_space.ext MetricSpace.ext
/-- Construct a metric space structure whose underlying topological space structure
(definitionally) agrees which a pre-existing topology which is compatible with a given distance
function. -/
def MetricSpace.ofMetrizable {α : Type _} [TopologicalSpace α] (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s)
(eq_of_dist_eq_zero : ∀ x y : α, dist x y = 0 → x = y) : MetricSpace α :=
{ PseudoMetricSpace.ofMetrizable dist dist_self dist_comm dist_triangle H with
eq_of_dist_eq_zero }
#align metric_space.of_metrizable MetricSpace.ofMetrizable
variable {γ : Type w} [MetricSpace γ]
theorem eq_of_dist_eq_zero {x y : γ} : dist x y = 0 → x = y :=
MetricSpace.eq_of_dist_eq_zero
#align eq_of_dist_eq_zero eq_of_dist_eq_zero
@[simp]
theorem dist_eq_zero {x y : γ} : dist x y = 0 ↔ x = y :=
Iff.intro eq_of_dist_eq_zero fun this : x = y => this ▸ dist_self _
#align dist_eq_zero dist_eq_zero
@[simp]
theorem zero_eq_dist {x y : γ} : 0 = dist x y ↔ x = y := by rw [eq_comm, dist_eq_zero]
#align zero_eq_dist zero_eq_dist
theorem dist_ne_zero {x y : γ} : dist x y ≠ 0 ↔ x ≠ y := by
simpa only [not_iff_not] using dist_eq_zero
#align dist_ne_zero dist_ne_zero
@[simp]
theorem dist_le_zero {x y : γ} : dist x y ≤ 0 ↔ x = y := by
simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y
#align dist_le_zero dist_le_zero
@[simp]
theorem dist_pos {x y : γ} : 0 < dist x y ↔ x ≠ y := by
simpa only [not_le] using not_congr dist_le_zero
#align dist_pos dist_pos
theorem eq_of_forall_dist_le {x y : γ} (h : ∀ ε > 0, dist x y ≤ ε) : x = y :=
eq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h)
#align eq_of_forall_dist_le eq_of_forall_dist_le
/-- Deduce the equality of points with the vanishing of the nonnegative distance-/
theorem eq_of_nndist_eq_zero {x y : γ} : nndist x y = 0 → x = y := by
simp only [← Nnreal.eq_iff, ← dist_nndist, imp_self, Nnreal.coe_zero, dist_eq_zero]
#align eq_of_nndist_eq_zero eq_of_nndist_eq_zero
/-- Characterize the equality of points with the vanishing of the nonnegative distance-/
@[simp]
theorem nndist_eq_zero {x y : γ} : nndist x y = 0 ↔ x = y := by
simp only [← Nnreal.eq_iff, ← dist_nndist, imp_self, Nnreal.coe_zero, dist_eq_zero]
#align nndist_eq_zero nndist_eq_zero
@[simp]
theorem zero_eq_nndist {x y : γ} : 0 = nndist x y ↔ x = y := by
simp only [← Nnreal.eq_iff, ← dist_nndist, imp_self, Nnreal.coe_zero, zero_eq_dist]
#align zero_eq_nndist zero_eq_nndist
namespace Metric
variable {x : γ} {s : Set γ}
@[simp]
theorem closedBall_zero : closedBall x 0 = {x} :=
Set.ext fun y => dist_le_zero
#align metric.closed_ball_zero Metric.closedBall_zero
@[simp]
theorem sphere_zero : sphere x 0 = {x} :=
Set.ext fun y => dist_eq_zero
#align metric.sphere_zero Metric.sphere_zero
theorem subsingleton_closedBall (x : γ) {r : ℝ} (hr : r ≤ 0) : (closedBall x r).Subsingleton :=
by
rcases hr.lt_or_eq with (hr | rfl)
· rw [closed_ball_eq_empty.2 hr]
exact subsingleton_empty
· rw [closed_ball_zero]
exact subsingleton_singleton
#align metric.subsingleton_closed_ball Metric.subsingleton_closedBall
theorem subsingleton_sphere (x : γ) {r : ℝ} (hr : r ≤ 0) : (sphere x r).Subsingleton :=
(subsingleton_closedBall x hr).anti sphere_subset_closedBall
#align metric.subsingleton_sphere Metric.subsingleton_sphere
/-- A map between metric spaces is a uniform embedding if and only if the distance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem uniformEmbedding_iff' [MetricSpace β] {f : γ → β} :
UniformEmbedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, dist a b < δ → dist (f a) (f b) < ε) ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, dist (f a) (f b) < ε → dist a b < δ :=
by
constructor
· intro h
exact ⟨uniformContinuous_iff.1 (uniform_embedding_iff.1 h).2.1, (uniform_embedding_iff.1 h).2.2⟩
· rintro ⟨h₁, h₂⟩
refine' uniform_embedding_iff.2 ⟨_, uniformContinuous_iff.2 h₁, h₂⟩
intro x y hxy
have : dist x y ≤ 0 := by
refine' le_of_forall_lt' fun δ δpos => _
rcases h₂ δ δpos with ⟨ε, εpos, hε⟩
have : dist (f x) (f y) < ε := by simpa [hxy]
exact hε this
simpa using this
#align metric.uniform_embedding_iff' Metric.uniformEmbedding_iff'
-- see Note [lower instance priority]
instance (priority := 100) MetricSpace.to_separated : SeparatedSpace γ :=
separated_def.2 fun x y h =>
eq_of_forall_dist_le fun ε ε0 => le_of_lt (h _ (dist_mem_uniformity ε0))
#align metric_space.to_separated MetricSpace.to_separated
/-- If a `pseudo_metric_space` is a T₀ space, then it is a `metric_space`. -/
def ofT0PseudoMetricSpace (α : Type _) [PseudoMetricSpace α] [T0Space α] : MetricSpace α :=
{ ‹PseudoMetricSpace α› with
eq_of_dist_eq_zero := fun x y hdist => Inseparable.eq <| Metric.inseparable_iff.2 hdist }
#align metric.of_t0_pseudo_metric_space Metric.ofT0PseudoMetricSpace
-- see Note [lower instance priority]
/-- A metric space induces an emetric space -/
instance (priority := 100) MetricSpace.toEmetricSpace : EmetricSpace γ :=
Emetric.ofT0PseudoEmetricSpace γ
#align metric.metric_space.to_emetric_space Metric.MetricSpace.toEmetricSpace
theorem isClosed_of_pairwise_le_dist {s : Set γ} {ε : ℝ} (hε : 0 < ε)
(hs : s.Pairwise fun x y => ε ≤ dist x y) : IsClosed s :=
isClosed_of_spaced_out (dist_mem_uniformity hε) <| by simpa using hs
#align metric.is_closed_of_pairwise_le_dist Metric.isClosed_of_pairwise_le_dist
theorem closedEmbedding_of_pairwise_le_dist {α : Type _} [TopologicalSpace α] [DiscreteTopology α]
{ε : ℝ} (hε : 0 < ε) {f : α → γ} (hf : Pairwise fun x y => ε ≤ dist (f x) (f y)) :
ClosedEmbedding f :=
closedEmbedding_of_spaced_out (dist_mem_uniformity hε) <| by simpa using hf
#align metric.closed_embedding_of_pairwise_le_dist Metric.closedEmbedding_of_pairwise_le_dist
/-- If `f : β → α` sends any two distinct points to points at distance at least `ε > 0`, then
`f` is a uniform embedding with respect to the discrete uniformity on `β`. -/
theorem uniformEmbedding_bot_of_pairwise_le_dist {β : Type _} {ε : ℝ} (hε : 0 < ε) {f : β → α}
(hf : Pairwise fun x y => ε ≤ dist (f x) (f y)) :
@UniformEmbedding _ _ ⊥ (by infer_instance) f :=
uniformEmbedding_of_spaced_out (dist_mem_uniformity hε) <| by simpa using hf
#align metric.uniform_embedding_bot_of_pairwise_le_dist Metric.uniformEmbedding_bot_of_pairwise_le_dist
end Metric
/-- Build a new metric space from an old one where the bundled uniform structure is provably
(but typically non-definitionaly) equal to some given uniform structure.
See Note [forgetful inheritance].
-/
def MetricSpace.replaceUniformity {γ} [U : UniformSpace γ] (m : MetricSpace γ)
(H : @uniformity _ U = @uniformity _ PseudoEmetricSpace.toUniformSpace) : MetricSpace γ :=
{ PseudoMetricSpace.replaceUniformity m.toPseudoMetricSpace H with
eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _ }
#align metric_space.replace_uniformity MetricSpace.replaceUniformity
theorem MetricSpace.replaceUniformity_eq {γ} [U : UniformSpace γ] (m : MetricSpace γ)
(H : @uniformity _ U = @uniformity _ PseudoEmetricSpace.toUniformSpace) :
m.replaceUniformity H = m := by
ext
rfl
#align metric_space.replace_uniformity_eq MetricSpace.replaceUniformity_eq
/-- Build a new metric space from an old one where the bundled topological structure is provably
(but typically non-definitionaly) equal to some given topological structure.
See Note [forgetful inheritance].
-/
@[reducible]
def MetricSpace.replaceTopology {γ} [U : TopologicalSpace γ] (m : MetricSpace γ)
(H : U = m.toPseudoMetricSpace.toUniformSpace.toTopologicalSpace) : MetricSpace γ :=
@MetricSpace.replaceUniformity γ (m.toUniformSpace.replaceTopology H) m rfl
#align metric_space.replace_topology MetricSpace.replaceTopology
theorem MetricSpace.replaceTopology_eq {γ} [U : TopologicalSpace γ] (m : MetricSpace γ)
(H : U = m.toPseudoMetricSpace.toUniformSpace.toTopologicalSpace) : m.replaceTopology H = m :=
by
ext
rfl
#align metric_space.replace_topology_eq MetricSpace.replaceTopology_eq
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. In this definition, the distance
is given separately, to be able to prescribe some expression which is not defeq to the push-forward
of the edistance to reals. -/
def EmetricSpace.toMetricSpaceOfDist {α : Type u} [e : EmetricSpace α] (dist : α → α → ℝ)
(edist_ne_top : ∀ x y : α, edist x y ≠ ⊤) (h : ∀ x y, dist x y = Ennreal.toReal (edist x y)) :
MetricSpace α :=
{
PseudoEmetricSpace.toPseudoMetricSpaceOfDist dist edist_ne_top
h with
dist
eq_of_dist_eq_zero := fun x y hxy => by
simpa [h, Ennreal.toReal_eq_zero_iff, edist_ne_top x y] using hxy }
#align emetric_space.to_metric_space_of_dist EmetricSpace.toMetricSpaceOfDist
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. -/
def EmetricSpace.toMetricSpace {α : Type u} [e : EmetricSpace α] (h : ∀ x y : α, edist x y ≠ ⊤) :
MetricSpace α :=
EmetricSpace.toMetricSpaceOfDist (fun x y => Ennreal.toReal (edist x y)) h fun x y => rfl
#align emetric_space.to_metric_space EmetricSpace.toMetricSpace
/-- Build a new metric space from an old one where the bundled bornology structure is provably
(but typically non-definitionaly) equal to some given bornology structure.
See Note [forgetful inheritance].
-/
def MetricSpace.replaceBornology {α} [B : Bornology α] (m : MetricSpace α)
(H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) : MetricSpace α :=
{ PseudoMetricSpace.replaceBornology _ H, m with toBornology := B }
#align metric_space.replace_bornology MetricSpace.replaceBornology
theorem MetricSpace.replaceBornology_eq {α} [m : MetricSpace α] [B : Bornology α]
(H : ∀ s, @IsBounded _ B s ↔ @IsBounded _ PseudoMetricSpace.toBornology s) :
MetricSpace.replaceBornology _ H = m := by
ext
rfl
#align metric_space.replace_bornology_eq MetricSpace.replaceBornology_eq
/-- Metric space structure pulled back by an injective function. Injectivity is necessary to
ensure that `dist x y = 0` only if `x = y`. -/
def MetricSpace.induced {γ β} (f : γ → β) (hf : Function.Injective f) (m : MetricSpace β) :
MetricSpace γ :=
{ PseudoMetricSpace.induced f m.toPseudoMetricSpace with
eq_of_dist_eq_zero := fun x y h => hf (dist_eq_zero.1 h) }
#align metric_space.induced MetricSpace.induced
/-- Pull back a metric space structure by a uniform embedding. This is a version of
`metric_space.induced` useful in case if the domain already has a `uniform_space` structure. -/
@[reducible]
def UniformEmbedding.comapMetricSpace {α β} [UniformSpace α] [MetricSpace β] (f : α → β)
(h : UniformEmbedding f) : MetricSpace α :=
(MetricSpace.induced f h.inj ‹_›).replaceUniformity h.comap_uniformity.symm
#align uniform_embedding.comap_metric_space UniformEmbedding.comapMetricSpace
/-- Pull back a metric space structure by an embedding. This is a version of
`metric_space.induced` useful in case if the domain already has a `topological_space` structure. -/
@[reducible]
def Embedding.comapMetricSpace {α β} [TopologicalSpace α] [MetricSpace β] (f : α → β)
(h : Embedding f) : MetricSpace α :=
letI : UniformSpace α := Embedding.comapUniformSpace f h
UniformEmbedding.comapMetricSpace f (h.to_uniform_embedding f)
#align embedding.comap_metric_space Embedding.comapMetricSpace
instance Subtype.metricSpace {α : Type _} {p : α → Prop} [MetricSpace α] :
MetricSpace (Subtype p) :=
MetricSpace.induced coe Subtype.coe_injective ‹_›
#align subtype.metric_space Subtype.metricSpace
@[to_additive]
instance {α : Type _} [MetricSpace α] : MetricSpace αᵐᵒᵖ :=
MetricSpace.induced MulOpposite.unop MulOpposite.unop_injective ‹_›
instance : MetricSpace Empty where
dist _ _ := 0
dist_self _ := rfl
dist_comm _ _ := rfl
eq_of_dist_eq_zero _ _ _ := Subsingleton.elim _ _
dist_triangle _ _ _ := show (0 : ℝ) ≤ 0 + 0 by rw [add_zero]
toUniformSpace := Empty.uniformSpace
uniformity_dist := Subsingleton.elim _ _
instance : MetricSpace PUnit.{u + 1} where
dist _ _ := 0
dist_self _ := rfl
dist_comm _ _ := rfl
eq_of_dist_eq_zero _ _ _ := Subsingleton.elim _ _
dist_triangle _ _ _ := show (0 : ℝ) ≤ 0 + 0 by rw [add_zero]
toUniformSpace := PUnit.uniformSpace
uniformity_dist := by
simp only
have : ne_bot (⨅ ε > (0 : ℝ), 𝓟 { p : PUnit.{u + 1} × PUnit.{u + 1} | 0 < ε }) :=
@uniformity.neBot _
(uniformSpaceOfDist (fun _ _ => 0) (fun _ => rfl) (fun _ _ => rfl) fun _ _ _ => by
rw [zero_add])
_
refine' (eq_top_of_ne_bot _).trans (eq_top_of_ne_bot _).symm
section Real
/-- Instantiate the reals as a metric space. -/
instance Real.metricSpace : MetricSpace ℝ :=
{ Real.pseudoMetricSpace with
eq_of_dist_eq_zero := fun x y h => by simpa [dist, sub_eq_zero] using h }
#align real.metric_space Real.metricSpace
end Real
section Nnreal
instance : MetricSpace ℝ≥0 :=
Subtype.metricSpace
end Nnreal
instance [MetricSpace β] : MetricSpace (ULift β) :=
MetricSpace.induced ULift.down ULift.down_injective ‹_›
section Prod
instance Prod.metricSpaceMax [MetricSpace β] : MetricSpace (γ × β) :=
{ Prod.pseudoMetricSpaceMax with
eq_of_dist_eq_zero := fun x y h =>
by
cases' max_le_iff.1 (le_of_eq h) with h₁ h₂
exact Prod.ext_iff.2 ⟨dist_le_zero.1 h₁, dist_le_zero.1 h₂⟩ }
#align prod.metric_space_max Prod.metricSpaceMax
end Prod
section Pi
open Finset
variable {π : β → Type _} [Fintype β] [∀ b, MetricSpace (π b)]
/-- A finite product of metric spaces is a metric space, with the sup distance. -/
instance metricSpacePi : MetricSpace (∀ b, π b) :=
{/- we construct the instance from the emetric space instance to avoid checking again that the
uniformity is the same as the product uniformity, but we register nevertheless a nice formula
for the distance -/
pseudoMetricSpacePi with
eq_of_dist_eq_zero := fun f g eq0 =>
by
have eq1 : edist f g = 0 := by simp only [edist_dist, eq0, Ennreal.ofReal_zero]
have eq2 : (sup univ fun b : β => edist (f b) (g b)) ≤ 0 := le_of_eq eq1
simp only [Finset.sup_le_iff] at eq2
exact funext fun b => edist_le_zero.1 <| eq2 b <| mem_univ b }
#align metric_space_pi metricSpacePi
end Pi
namespace Metric
section SecondCountable
open TopologicalSpace
/-- A metric space is second countable if one can reconstruct up to any `ε>0` any element of the
space from countably many data. -/
theorem second_countable_of_countable_discretization {α : Type u} [MetricSpace α]
(H :
∀ ε > (0 : ℝ), ∃ (β : Type _)(_ : Encodable β)(F : α → β), ∀ x y, F x = F y → dist x y ≤ ε) :
SecondCountableTopology α :=
by
cases' (univ : Set α).eq_empty_or_nonempty with hs hs
· haveI : CompactSpace α := ⟨by rw [hs] <;> exact isCompact_empty⟩
· infer_instance
rcases hs with ⟨x0, hx0⟩
letI : Inhabited α := ⟨x0⟩
refine' second_countable_of_almost_dense_set fun ε ε0 => _
rcases H ε ε0 with ⟨β, fβ, F, hF⟩
skip
let Finv := Function.invFun F
refine' ⟨range Finv, ⟨countable_range _, fun x => _⟩⟩
let x' := Finv (F x)
have : F x' = F x := Function.invFun_eq ⟨x, rfl⟩
exact ⟨x', mem_range_self _, hF _ _ this.symm⟩
#align metric.second_countable_of_countable_discretization Metric.second_countable_of_countable_discretization
end SecondCountable
end Metric
section EqRel
/-- The canonical equivalence relation on a pseudometric space. -/
def PseudoMetric.distSetoid (α : Type u) [PseudoMetricSpace α] : Setoid α :=
Setoid.mk (fun x y => dist x y = 0)
(by
unfold Equivalence
repeat' constructor
· exact PseudoMetricSpace.dist_self
· intro x y h
rwa [PseudoMetricSpace.dist_comm]
· intro x y z hxy hyz
refine' le_antisymm _ dist_nonneg
calc
dist x z ≤ dist x y + dist y z := PseudoMetricSpace.dist_triangle _ _ _
_ = 0 + 0 := by rw [hxy, hyz]
_ = 0 := by simp
)
#align pseudo_metric.dist_setoid PseudoMetric.distSetoid
attribute [local instance] PseudoMetric.distSetoid
/-- The canonical quotient of a pseudometric space, identifying points at distance `0`. -/
@[reducible]
def PseudoMetricQuot (α : Type u) [PseudoMetricSpace α] : Type _ :=
Quotient (PseudoMetric.distSetoid α)
#align pseudo_metric_quot PseudoMetricQuot
instance hasDistMetricQuot {α : Type u} [PseudoMetricSpace α] : HasDist (PseudoMetricQuot α)
where dist :=
Quotient.lift₂ (fun p q : α => dist p q)
(by
intro x y x' y' hxx' hyy'
have Hxx' : dist x x' = 0 := hxx'
have Hyy' : dist y y' = 0 := hyy'
have A : dist x y ≤ dist x' y' :=
calc
dist x y ≤ dist x x' + dist x' y := PseudoMetricSpace.dist_triangle _ _ _
_ = dist x' y := by simp [Hxx']
_ ≤ dist x' y' + dist y' y := PseudoMetricSpace.dist_triangle _ _ _
_ = dist x' y' := by simp [PseudoMetricSpace.dist_comm, Hyy']
have B : dist x' y' ≤ dist x y :=
calc
dist x' y' ≤ dist x' x + dist x y' := PseudoMetricSpace.dist_triangle _ _ _
_ = dist x y' := by simp [PseudoMetricSpace.dist_comm, Hxx']
_ ≤ dist x y + dist y y' := PseudoMetricSpace.dist_triangle _ _ _
_ = dist x y := by simp [Hyy']
exact le_antisymm A B)
#align has_dist_metric_quot hasDistMetricQuot
theorem pseudo_metric_quot_dist_eq {α : Type u} [PseudoMetricSpace α] (p q : α) :
dist ⟦p⟧ ⟦q⟧ = dist p q :=
rfl
#align pseudo_metric_quot_dist_eq pseudo_metric_quot_dist_eq
instance metricSpaceQuot {α : Type u} [PseudoMetricSpace α] : MetricSpace (PseudoMetricQuot α)
where
dist_self := by
refine' Quotient.ind fun y => _
exact PseudoMetricSpace.dist_self _
eq_of_dist_eq_zero xc yc := Quotient.induction_on₂ xc yc fun x y H => Quotient.sound H
dist_comm xc yc := Quotient.induction_on₂ xc yc fun x y => PseudoMetricSpace.dist_comm _ _
dist_triangle xc yc zc :=
Quotient.induction_on₃ xc yc zc fun x y z => PseudoMetricSpace.dist_triangle _ _ _
#align metric_space_quot metricSpaceQuot
end EqRel
/-!
### `additive`, `multiplicative`
The distance on those type synonyms is inherited without change.
-/
open Additive Multiplicative
section
variable [HasDist X]
instance : HasDist (Additive X) :=
‹HasDist X›
instance : HasDist (Multiplicative X) :=
‹HasDist X›
@[simp]
theorem dist_ofMul (a b : X) : dist (ofMul a) (ofMul b) = dist a b :=
rfl
#align dist_of_mul dist_ofMul
@[simp]
theorem dist_ofAdd (a b : X) : dist (ofAdd a) (ofAdd b) = dist a b :=
rfl
#align dist_of_add dist_ofAdd
@[simp]
theorem dist_toMul (a b : Additive X) : dist (toMul a) (toMul b) = dist a b :=
rfl
#align dist_to_mul dist_toMul
@[simp]
theorem dist_toAdd (a b : Multiplicative X) : dist (toAdd a) (toAdd b) = dist a b :=
rfl
#align dist_to_add dist_toAdd
end
section
variable [PseudoMetricSpace X]
instance : PseudoMetricSpace (Additive X) :=
‹PseudoMetricSpace X›
instance : PseudoMetricSpace (Multiplicative X) :=
‹PseudoMetricSpace X›
@[simp]
theorem nndist_ofMul (a b : X) : nndist (ofMul a) (ofMul b) = nndist a b :=
rfl
#align nndist_of_mul nndist_ofMul
@[simp]
theorem nndist_ofAdd (a b : X) : nndist (ofAdd a) (ofAdd b) = nndist a b :=
rfl
#align nndist_of_add nndist_ofAdd
@[simp]
theorem nndist_toMul (a b : Additive X) : nndist (toMul a) (toMul b) = nndist a b :=
rfl
#align nndist_to_mul nndist_toMul
@[simp]
theorem nndist_toAdd (a b : Multiplicative X) : nndist (toAdd a) (toAdd b) = nndist a b :=
rfl
#align nndist_to_add nndist_toAdd
end
instance [MetricSpace X] : MetricSpace (Additive X) :=
‹MetricSpace X›
instance [MetricSpace X] : MetricSpace (Multiplicative X) :=
‹MetricSpace X›
instance [PseudoMetricSpace X] [ProperSpace X] : ProperSpace (Additive X) :=
‹ProperSpace X›
instance [PseudoMetricSpace X] [ProperSpace X] : ProperSpace (Multiplicative X) :=
‹ProperSpace X›
/-!
### Order dual
The distance on this type synonym is inherited without change.
-/
open OrderDual
section
variable [HasDist X]
instance : HasDist Xᵒᵈ :=
‹HasDist X›
@[simp]
theorem dist_toDual (a b : X) : dist (toDual a) (toDual b) = dist a b :=
rfl
#align dist_to_dual dist_toDual
@[simp]
theorem dist_ofDual (a b : Xᵒᵈ) : dist (ofDual a) (ofDual b) = dist a b :=
rfl
#align dist_of_dual dist_ofDual
end
section
variable [PseudoMetricSpace X]
instance : PseudoMetricSpace Xᵒᵈ :=
‹PseudoMetricSpace X›
@[simp]
theorem nndist_toDual (a b : X) : nndist (toDual a) (toDual b) = nndist a b :=
rfl
#align nndist_to_dual nndist_toDual
@[simp]
theorem nndist_ofDual (a b : Xᵒᵈ) : nndist (ofDual a) (ofDual b) = nndist a b :=
rfl
#align nndist_of_dual nndist_ofDual
end
instance [MetricSpace X] : MetricSpace Xᵒᵈ :=
‹MetricSpace X›
instance [PseudoMetricSpace X] [ProperSpace X] : ProperSpace Xᵒᵈ :=
‹ProperSpace X›
-/
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
-/
import set_theory.cardinal_ordinal
/-!
# Cofinality
This file contains the definition of cofinality of a ordinal number and regular cardinals
## Main Definitions
* `ordinal.cof o` is the cofinality of the ordinal `o`.
If `o` is the order type of the relation `<` on `α`, then `o.cof` is the smallest cardinality of a
subset `s` of α that is *cofinal* in `α`, i.e. `∀ x : α, ∃ y ∈ s, ¬ y < x`.
* `cardinal.is_limit c` means that `c` is a (weak) limit cardinal: `c ≠ 0 ∧ ∀ x < c, succ x < c`.
* `cardinal.is_strong_limit c` means that `c` is a strong limit cardinal:
`c ≠ 0 ∧ ∀ x < c, 2 ^ x < c`.
* `cardinal.is_regular c` means that `c` is a regular cardinal: `ω ≤ c ∧ c.ord.cof = c`.
* `cardinal.is_inaccessible c` means that `c` is strongly inaccessible:
`ω < c ∧ is_regular c ∧ is_strong_limit c`.
## Main Statements
* `ordinal.infinite_pigeonhole_card`: the infinite pigeonhole principle
* `cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for
`c ≥ ω`
* `cardinal.univ_inaccessible`: The type of ordinals in `Type u` form an inaccessible cardinal
(in `Type v` with `v > u`). This shows (externally) that in `Type u` there are at least `u`
inaccessible cardinals.
## Implementation Notes
* The cofinality is defined for ordinals.
If `c` is a cardinal number, its cofinality is `c.ord.cof`.
## Tags
cofinality, regular cardinals, limits cardinals, inaccessible cardinals,
infinite pigeonhole principle
-/
noncomputable theory
open function cardinal set
open_locale classical cardinal
universes u v w
variables {α : Type*} {r : α → α → Prop}
namespace order
/-- Cofinality of a reflexive order `≼`. This is the smallest cardinality
of a subset `S : set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/
def cof (r : α → α → Prop) [is_refl α r] : cardinal :=
@cardinal.min {S : set α // ∀ a, ∃ b ∈ S, r a b}
⟨⟨set.univ, λ a, ⟨a, ⟨⟩, refl _⟩⟩⟩
(λ S, #S)
lemma cof_le (r : α → α → Prop) [is_refl α r] {S : set α} (h : ∀a, ∃(b ∈ S), r a b) :
order.cof r ≤ #S :=
le_trans (cardinal.min_le _ ⟨S, h⟩) (le_refl _)
lemma le_cof {r : α → α → Prop} [is_refl α r] (c : cardinal) :
c ≤ order.cof r ↔ ∀ {S : set α} (h : ∀a, ∃(b ∈ S), r a b) , c ≤ #S :=
by { rw [order.cof, cardinal.le_min], exact ⟨λ H S h, H ⟨S, h⟩, λ H ⟨S, h⟩, H h ⟩ }
end order
theorem rel_iso.cof.aux {α : Type u} {β : Type v} {r s}
[is_refl α r] [is_refl β s] (f : r ≃r s) :
cardinal.lift.{(max u v)} (order.cof r) ≤
cardinal.lift.{(max u v)} (order.cof s) :=
begin
rw [order.cof, order.cof, lift_min, lift_min, cardinal.le_min],
intro S, cases S with S H, simp only [comp, coe_sort_coe_base, subtype.coe_mk],
refine le_trans (min_le _ _) _,
{ exact ⟨f ⁻¹' S, λ a,
let ⟨b, bS, h⟩ := H (f a) in ⟨f.symm b, by simp [bS, ← f.map_rel_iff, h,
-coe_fn_coe_base, -coe_fn_coe_trans, principal_seg.coe_coe_fn', initial_seg.coe_coe_fn]⟩⟩ },
{ exact lift_mk_le.{u v (max u v)}.2
⟨⟨λ ⟨x, h⟩, ⟨f x, h⟩, λ ⟨x, h₁⟩ ⟨y, h₂⟩ h₃,
by congr; injection h₃ with h'; exact f.to_equiv.injective h'⟩⟩ }
end
theorem rel_iso.cof {α : Type u} {β : Type v} {r s}
[is_refl α r] [is_refl β s] (f : r ≃r s) :
cardinal.lift.{(max u v)} (order.cof r) =
cardinal.lift.{(max u v)} (order.cof s) :=
le_antisymm (rel_iso.cof.aux f) (rel_iso.cof.aux f.symm)
def strict_order.cof (r : α → α → Prop) [h : is_irrefl α r] : cardinal :=
@order.cof α (λ x y, ¬ r y x) ⟨h.1⟩
namespace ordinal
/-- Cofinality of an ordinal. This is the smallest cardinal of a
subset `S` of the ordinal which is unbounded, in the sense
`∀ a, ∃ b ∈ S, ¬(b > a)`. It is defined for all ordinals, but
`cof 0 = 0` and `cof (succ o) = 1`, so it is only really
interesting on limit ordinals (when it is an infinite cardinal). -/
def cof (o : ordinal.{u}) : cardinal.{u} :=
quot.lift_on o (λ ⟨α, r, _⟩, by exactI strict_order.cof r)
begin
rintros ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨⟨f, hf⟩⟩,
rw ← cardinal.lift_inj,
apply rel_iso.cof ⟨f, _⟩,
simp [hf]
end
lemma cof_type (r : α → α → Prop) [is_well_order α r] : (type r).cof = strict_order.cof r := rfl
theorem le_cof_type [is_well_order α r] {c} : c ≤ cof (type r) ↔
∀ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) → c ≤ #S :=
by dsimp [cof, strict_order.cof, order.cof, type, quotient.mk, quot.lift_on];
rw [cardinal.le_min, subtype.forall]; refl
theorem cof_type_le [is_well_order α r] (S : set α) (h : ∀ a, ∃ b ∈ S, ¬ r b a) :
cof (type r) ≤ #S :=
le_cof_type.1 (le_refl _) S h
theorem lt_cof_type [is_well_order α r] (S : set α) (hl : #S < cof (type r)) :
∃ a, ∀ b ∈ S, r b a :=
not_forall_not.1 $ λ h, not_le_of_lt hl $ cof_type_le S (λ a, not_ball.1 (h a))
theorem cof_eq (r : α → α → Prop) [is_well_order α r] :
∃ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) ∧ #S = cof (type r) :=
begin
have : ∃ i, cof (type r) = _,
{ dsimp [cof, order.cof, type, quotient.mk, quot.lift_on],
apply cardinal.min_eq },
exact let ⟨⟨S, hl⟩, e⟩ := this in ⟨S, hl, e.symm⟩,
end
theorem ord_cof_eq (r : α → α → Prop) [is_well_order α r] :
∃ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) ∧ type (subrel r S) = (cof (type r)).ord :=
let ⟨S, hS, e⟩ := cof_eq r, ⟨s, _, e'⟩ := cardinal.ord_eq S,
T : set α := {a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a} in
begin
resetI, suffices,
{ refine ⟨T, this,
le_antisymm _ (cardinal.ord_le.2 $ cof_type_le T this)⟩,
rw [← e, e'],
refine type_le'.2 ⟨rel_embedding.of_monotone
(λ a, ⟨a, let ⟨aS, _⟩ := a.2 in aS⟩) (λ a b h, _)⟩,
rcases a with ⟨a, aS, ha⟩, rcases b with ⟨b, bS, hb⟩,
change s ⟨a, _⟩ ⟨b, _⟩,
refine ((trichotomous_of s _ _).resolve_left (λ hn, _)).resolve_left _,
{ exact asymm h (ha _ hn) },
{ intro e, injection e with e, subst b,
exact irrefl _ h } },
{ intro a,
have : {b : S | ¬ r b a}.nonempty := let ⟨b, bS, ba⟩ := hS a in ⟨⟨b, bS⟩, ba⟩,
let b := (is_well_order.wf).min _ this,
have ba : ¬r b a := (is_well_order.wf).min_mem _ this,
refine ⟨b, ⟨b.2, λ c, not_imp_not.1 $ λ h, _⟩, ba⟩,
rw [show ∀b:S, (⟨b, b.2⟩:S) = b, by intro b; cases b; refl],
exact (is_well_order.wf).not_lt_min _ this
(is_order_connected.neg_trans h ba) }
end
theorem lift_cof (o) : (cof o).lift = cof o.lift :=
induction_on o $ begin introsI α r _,
cases lift_type r with _ e, rw e,
apply le_antisymm,
{ unfreezingI { refine le_cof_type.2 (λ S H, _) },
have : (#(ulift.up ⁻¹' S)).lift ≤ #S :=
⟨⟨λ ⟨⟨x, h⟩⟩, ⟨⟨x⟩, h⟩,
λ ⟨⟨x, h₁⟩⟩ ⟨⟨y, h₂⟩⟩ e, by simp at e; congr; injection e⟩⟩,
refine le_trans (cardinal.lift_le.2 $ cof_type_le _ _) this,
exact λ a, let ⟨⟨b⟩, bs, br⟩ := H ⟨a⟩ in ⟨b, bs, br⟩ },
{ rcases cof_eq r with ⟨S, H, e'⟩,
have : #(ulift.down ⁻¹' S) ≤ (#S).lift :=
⟨⟨λ ⟨⟨x⟩, h⟩, ⟨⟨x, h⟩⟩,
λ ⟨⟨x⟩, h₁⟩ ⟨⟨y⟩, h₂⟩ e, by simp at e; congr; injections⟩⟩,
rw e' at this,
unfreezingI { refine le_trans (cof_type_le _ _) this },
exact λ ⟨a⟩, let ⟨b, bs, br⟩ := H a in ⟨⟨b⟩, bs, br⟩ }
end
theorem cof_le_card (o) : cof o ≤ card o :=
induction_on o $ λ α r _, begin
resetI,
have : #(@set.univ α) = card (type r) :=
quotient.sound ⟨equiv.set.univ _⟩,
rw ← this, exact cof_type_le set.univ (λ a, ⟨a, ⟨⟩, irrefl a⟩)
end
theorem cof_ord_le (c : cardinal) : cof c.ord ≤ c :=
by simpa using cof_le_card c.ord
@[simp] theorem cof_zero : cof 0 = 0 :=
le_antisymm (by simpa using cof_le_card 0) (cardinal.zero_le _)
@[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 :=
⟨induction_on o $ λ α r _ z, by exactI
let ⟨S, hl, e⟩ := cof_eq r in type_eq_zero_iff_is_empty.2 $
⟨λ a, let ⟨b, h, _⟩ := hl a in
(mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩,
λ e, by simp [e]⟩
@[simp] theorem cof_succ (o) : cof (succ o) = 1 :=
begin
apply le_antisymm,
{ refine induction_on o (λ α r _, _),
change cof (type _) ≤ _,
rw [← (_ : #_ = 1)], apply cof_type_le,
{ refine λ a, ⟨sum.inr punit.star, set.mem_singleton _, _⟩,
rcases a with a|⟨⟨⟨⟩⟩⟩; simp [empty_relation] },
{ rw [cardinal.mk_fintype, set.card_singleton], simp } },
{ rw [← cardinal.succ_zero, cardinal.succ_le],
simpa [lt_iff_le_and_ne, cardinal.zero_le] using
λ h, succ_ne_zero o (cof_eq_zero.1 (eq.symm h)) }
end
@[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a :=
⟨induction_on o $ λ α r _ z, begin
resetI,
rcases cof_eq r with ⟨S, hl, e⟩, rw z at e,
cases mk_ne_zero_iff.1 (by rw e; exact one_ne_zero) with a,
refine ⟨typein r a, eq.symm $ quotient.sound
⟨rel_iso.of_surjective (rel_embedding.of_monotone _
(λ x y, _)) (λ x, _)⟩⟩,
{ apply sum.rec; [exact subtype.val, exact λ _, a] },
{ rcases x with x|⟨⟨⟨⟩⟩⟩; rcases y with y|⟨⟨⟨⟩⟩⟩;
simp [subrel, order.preimage, empty_relation],
exact x.2 },
{ suffices : r x a ∨ ∃ (b : punit), ↑a = x, {simpa},
rcases trichotomous_of r x a with h|h|h,
{ exact or.inl h },
{ exact or.inr ⟨punit.star, h.symm⟩ },
{ rcases hl x with ⟨a', aS, hn⟩,
rw (_ : ↑a = a') at h, {exact absurd h hn},
refine congr_arg subtype.val (_ : a = ⟨a', aS⟩),
haveI := le_one_iff_subsingleton.1 (le_of_eq e),
apply subsingleton.elim } }
end, λ ⟨a, e⟩, by simp [e]⟩
@[simp] theorem cof_add (a b : ordinal) : b ≠ 0 → cof (a + b) = cof b :=
induction_on a $ λ α r _, induction_on b $ λ β s _ b0, begin
resetI,
change cof (type _) = _,
refine eq_of_forall_le_iff (λ c, _),
rw [le_cof_type, le_cof_type],
split; intros H S hS,
{ refine le_trans (H {a | sum.rec_on a (∅:set α) S} (λ a, _)) ⟨⟨_, _⟩⟩,
{ cases a with a b,
{ cases type_ne_zero_iff_nonempty.1 b0 with b,
rcases hS b with ⟨b', bs, _⟩,
exact ⟨sum.inr b', bs, by simp⟩ },
{ rcases hS b with ⟨b', bs, h⟩,
exact ⟨sum.inr b', bs, by simp [h]⟩ } },
{ exact λ a, match a with ⟨sum.inr b, h⟩ := ⟨b, h⟩ end },
{ exact λ a b, match a, b with
⟨sum.inr a, h₁⟩, ⟨sum.inr b, h₂⟩, h := by congr; injection h
end } },
{ refine le_trans (H (sum.inr ⁻¹' S) (λ a, _)) ⟨⟨_, _⟩⟩,
{ rcases hS (sum.inr a) with ⟨a'|b', bs, h⟩; simp at h,
{ cases h }, { exact ⟨b', bs, h⟩ } },
{ exact λ ⟨a, h⟩, ⟨_, h⟩ },
{ exact λ ⟨a, h₁⟩ ⟨b, h₂⟩ h,
by injection h with h; congr; injection h } }
end
@[simp] theorem cof_cof (o : ordinal) : cof (cof o).ord= cof o :=
le_antisymm (le_trans (cof_le_card _) (by simp)) $
induction_on o $ λ α r _, by exactI
let ⟨S, hS, e₁⟩ := ord_cof_eq r,
⟨T, hT, e₂⟩ := cof_eq (subrel r S) in begin
rw e₁ at e₂, rw ← e₂,
refine le_trans (cof_type_le {a | ∃ h, (subtype.mk a h : S) ∈ T} (λ a, _)) ⟨⟨_, _⟩⟩,
{ rcases hS a with ⟨b, bS, br⟩,
rcases hT ⟨b, bS⟩ with ⟨⟨c, cS⟩, cT, cs⟩,
exact ⟨c, ⟨cS, cT⟩, is_order_connected.neg_trans cs br⟩ },
{ exact λ ⟨a, h⟩, ⟨⟨a, h.fst⟩, h.snd⟩ },
{ exact λ ⟨a, ha⟩ ⟨b, hb⟩ h,
by injection h with h; congr; injection h },
end
theorem omega_le_cof {o} : ω ≤ cof o ↔ is_limit o :=
begin
rcases zero_or_succ_or_limit o with rfl|⟨o,rfl⟩|l,
{ simp [not_zero_is_limit, cardinal.omega_ne_zero] },
{ simp [not_succ_is_limit, cardinal.one_lt_omega] },
{ simp [l], refine le_of_not_lt (λ h, _),
cases cardinal.lt_omega.1 h with n e,
have := cof_cof o,
rw [e, ord_nat] at this,
cases n,
{ simp at e, simpa [e, not_zero_is_limit] using l },
{ rw [← nat_cast_succ, cof_succ] at this,
rw [← this, cof_eq_one_iff_is_succ] at e,
rcases e with ⟨a, rfl⟩,
exact not_succ_is_limit _ l } }
end
@[simp] theorem cof_omega : cof omega = ω :=
le_antisymm
(by rw ← card_omega; apply cof_le_card)
(omega_le_cof.2 omega_is_limit)
theorem cof_eq' (r : α → α → Prop) [is_well_order α r] (h : is_limit (type r)) :
∃ S : set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = cof (type r) :=
let ⟨S, H, e⟩ := cof_eq r in
⟨S, λ a,
let a' := enum r _ (h.2 _ (typein_lt_type r a)) in
let ⟨b, h, ab⟩ := H a' in
⟨b, h, (is_order_connected.conn a b a' $ (typein_lt_typein r).1
(by rw typein_enum; apply ordinal.lt_succ_self)).resolve_right ab⟩,
e⟩
theorem cof_sup_le_lift {ι} (f : ι → ordinal) (H : ∀ i, f i < sup f) :
cof (sup f) ≤ (#ι).lift :=
begin
generalize e : sup f = o,
refine ordinal.induction_on o _ e, introsI α r _ e',
rw e' at H,
refine le_trans (cof_type_le (set.range (λ i, enum r _ (H i))) _)
⟨embedding.of_surjective _ _⟩,
{ intro a, by_contra h,
apply not_le_of_lt (typein_lt_type r a),
rw [← e', sup_le],
intro i,
have h : ∀ (x : ι), r (enum r (f x) _) a, { simpa using h },
simpa only [typein_enum] using le_of_lt ((typein_lt_typein r).2 (h i)) },
{ exact λ i, ⟨_, set.mem_range_self i.1⟩ },
{ intro a, rcases a with ⟨_, i, rfl⟩, exact ⟨⟨i⟩, by simp⟩ }
end
theorem cof_sup_le {ι} (f : ι → ordinal) (H : ∀ i, f i < sup.{u u} f) :
cof (sup.{u u} f) ≤ #ι :=
by simpa using cof_sup_le_lift.{u u} f H
theorem cof_bsup_le_lift {o : ordinal} : ∀ (f : Π a < o, ordinal), (∀ i h, f i h < bsup o f) →
cof (bsup o f) ≤ o.card.lift :=
induction_on o $ λ α r _ f H,
by rw bsup_type; refine cof_sup_le_lift _ _;
rw ← bsup_type; intro a; apply H
theorem cof_bsup_le {o : ordinal} : ∀ (f : Π a < o, ordinal), (∀ i h, f i h < bsup.{u u} o f) →
cof (bsup.{u u} o f) ≤ o.card :=
induction_on o $ λ α r _ f H,
by simpa using cof_bsup_le_lift.{u u} f H
@[simp] theorem cof_univ : cof univ.{u v} = cardinal.univ :=
le_antisymm (cof_le_card _) begin
refine le_of_forall_lt (λ c h, _),
rcases lt_univ'.1 h with ⟨c, rfl⟩,
rcases @cof_eq ordinal.{u} (<) _ with ⟨S, H, Se⟩,
rw [univ, ← lift_cof, ← cardinal.lift_lift, cardinal.lift_lt, ← Se],
refine lt_of_not_ge (λ h, _),
cases cardinal.lift_down h with a e,
refine quotient.induction_on a (λ α e, _) e,
cases quotient.exact e with f,
have f := equiv.ulift.symm.trans f,
let g := λ a, (f a).1,
let o := succ (sup.{u u} g),
rcases H o with ⟨b, h, l⟩,
refine l (lt_succ.2 _),
rw ← show g (f.symm ⟨b, h⟩) = b, by dsimp [g]; simp,
apply le_sup
end
theorem sup_lt_ord {ι} (f : ι → ordinal) {c : ordinal} (H1 : #ι < c.cof)
(H2 : ∀ i, f i < c) : sup.{u u} f < c :=
begin
apply lt_of_le_of_ne,
{ rw [sup_le], exact λ i, le_of_lt (H2 i) },
rintro h, apply not_le_of_lt H1,
simpa [sup_ord, H2, h] using cof_sup_le.{u} f
end
theorem sup_lt {ι} (f : ι → cardinal) {c : cardinal} (H1 : #ι < c.ord.cof)
(H2 : ∀ i, f i < c) : cardinal.sup.{u u} f < c :=
by { rw [←ord_lt_ord, ←sup_ord], apply sup_lt_ord _ H1, intro i, rw ord_lt_ord, apply H2 }
/-- If the union of s is unbounded and s is smaller than the cofinality,
then s has an unbounded member -/
theorem unbounded_of_unbounded_sUnion (r : α → α → Prop) [wo : is_well_order α r] {s : set (set α)}
(h₁ : unbounded r $ ⋃₀ s) (h₂ : #s < strict_order.cof r) : ∃(x ∈ s), unbounded r x :=
begin
by_contra h, simp only [not_exists, exists_prop, not_and, not_unbounded_iff] at h,
apply not_le_of_lt h₂,
let f : s → α := λ x : s, wo.wf.sup x (h x.1 x.2),
let t : set α := range f,
have : #t ≤ #s, exact mk_range_le, refine le_trans _ this,
have : unbounded r t,
{ intro x, rcases h₁ x with ⟨y, ⟨c, hc, hy⟩, hxy⟩,
refine ⟨f ⟨c, hc⟩, mem_range_self _, _⟩, intro hxz, apply hxy,
refine trans (wo.wf.lt_sup _ hy) hxz },
exact cardinal.min_le _ (subtype.mk t this)
end
/-- If the union of s is unbounded and s is smaller than the cofinality,
then s has an unbounded member -/
theorem unbounded_of_unbounded_Union {α β : Type u} (r : α → α → Prop) [wo : is_well_order α r]
(s : β → set α)
(h₁ : unbounded r $ ⋃x, s x) (h₂ : #β < strict_order.cof r) : ∃x : β, unbounded r (s x) :=
begin
rw [← sUnion_range] at h₁,
have : #(range (λ (i : β), s i)) < strict_order.cof r := lt_of_le_of_lt mk_range_le h₂,
rcases unbounded_of_unbounded_sUnion r h₁ this with ⟨_, ⟨x, rfl⟩, u⟩, exact ⟨x, u⟩
end
/-- The infinite pigeonhole principle -/
theorem infinite_pigeonhole {β α : Type u} (f : β → α) (h₁ : ω ≤ #β)
(h₂ : #α < (#β).ord.cof) : ∃a : α, #(f ⁻¹' {a}) = #β :=
begin
have : ¬∀a, #(f ⁻¹' {a}) < #β,
{ intro h,
apply not_lt_of_ge (ge_of_eq $ mk_univ),
rw [←@preimage_univ _ _ f, ←Union_of_singleton, preimage_Union],
apply lt_of_le_of_lt mk_Union_le_sum_mk,
apply lt_of_le_of_lt (sum_le_sup _),
apply mul_lt_of_lt h₁ (lt_of_lt_of_le h₂ $ cof_ord_le _),
exact sup_lt _ h₂ h },
rw [not_forall] at this, cases this with x h,
use x, apply le_antisymm _ (le_of_not_gt h),
rw [le_mk_iff_exists_set], exact ⟨_, rfl⟩
end
/-- pigeonhole principle for a cardinality below the cardinality of the domain -/
theorem infinite_pigeonhole_card {β α : Type u} (f : β → α) (θ : cardinal) (hθ : θ ≤ #β)
(h₁ : ω ≤ θ) (h₂ : #α < θ.ord.cof) : ∃a : α, θ ≤ #(f ⁻¹' {a}) :=
begin
rcases le_mk_iff_exists_set.1 hθ with ⟨s, rfl⟩,
cases infinite_pigeonhole (f ∘ subtype.val : s → α) h₁ h₂ with a ha,
use a, rw [←ha, @preimage_comp _ _ _ subtype.val f],
apply mk_preimage_of_injective _ _ subtype.val_injective
end
theorem infinite_pigeonhole_set {β α : Type u} {s : set β} (f : s → α) (θ : cardinal)
(hθ : θ ≤ #s) (h₁ : ω ≤ θ) (h₂ : #α < θ.ord.cof) :
∃(a : α) (t : set β) (h : t ⊆ s), θ ≤ #t ∧ ∀{{x}} (hx : x ∈ t), f ⟨x, h hx⟩ = a :=
begin
cases infinite_pigeonhole_card f θ hθ h₁ h₂ with a ha,
refine ⟨a, {x | ∃(h : x ∈ s), f ⟨x, h⟩ = a}, _, _, _⟩,
{ rintro x ⟨hx, hx'⟩, exact hx },
{ refine le_trans ha _, apply ge_of_eq, apply quotient.sound, constructor,
refine equiv.trans _ (equiv.subtype_subtype_equiv_subtype_exists _ _).symm,
simp only [set_coe_eq_subtype, mem_singleton_iff, mem_preimage, mem_set_of_eq] },
rintro x ⟨hx, hx'⟩, exact hx'
end
end ordinal
namespace cardinal
open ordinal
local infixr ^ := @pow cardinal.{u} cardinal cardinal.has_pow
/-- A cardinal is a limit if it is not zero or a successor
cardinal. Note that `ω` is a limit cardinal by this definition. -/
def is_limit (c : cardinal) : Prop :=
c ≠ 0 ∧ ∀ x < c, succ x < c
/-- A cardinal is a strong limit if it is not zero and it is
closed under powersets. Note that `ω` is a strong limit by this definition. -/
def is_strong_limit (c : cardinal) : Prop :=
c ≠ 0 ∧ ∀ x < c, 2 ^ x < c
theorem is_strong_limit.is_limit {c} (H : is_strong_limit c) : is_limit c :=
⟨H.1, λ x h, lt_of_le_of_lt (succ_le.2 $ cantor _) (H.2 _ h)⟩
/-- A cardinal is regular if it is infinite and it equals its own cofinality. -/
def is_regular (c : cardinal) : Prop :=
ω ≤ c ∧ c.ord.cof = c
lemma is_regular.pos {c : cardinal} (H : c.is_regular) : 0 < c :=
omega_pos.trans_le H.left
lemma is_regular.ord_pos {c : cardinal} (H : c.is_regular) : 0 < c.ord :=
by { rw cardinal.lt_ord, exact H.pos }
theorem cof_is_regular {o : ordinal} (h : o.is_limit) : is_regular o.cof :=
⟨omega_le_cof.2 h, cof_cof _⟩
theorem omega_is_regular : is_regular ω :=
⟨le_refl _, by simp⟩
theorem succ_is_regular {c : cardinal.{u}} (h : ω ≤ c) : is_regular (succ c) :=
⟨le_trans h (le_of_lt $ lt_succ_self _), begin
refine le_antisymm (cof_ord_le _) (succ_le.2 _),
cases quotient.exists_rep (succ c) with α αe, simp at αe,
rcases ord_eq α with ⟨r, wo, re⟩, resetI,
have := ord_is_limit (le_trans h $ le_of_lt $ lt_succ_self _),
rw [← αe, re] at this ⊢,
rcases cof_eq' r this with ⟨S, H, Se⟩,
rw [← Se],
apply lt_imp_lt_of_le_imp_le
(λ (h : #S ≤ c), mul_le_mul_right' h c),
rw [mul_eq_self h, ← succ_le, ← αe, ← sum_const'],
refine le_trans _ (sum_le_sum (λ x:S, card (typein r x)) _ _),
{ simp only [← card_typein, ← mk_sigma],
refine ⟨embedding.of_surjective _ _⟩,
{ exact λ x, x.2.1 },
{ exact λ a, let ⟨b, h, ab⟩ := H a in ⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩ } },
{ intro i,
rw [← lt_succ, ← lt_ord, ← αe, re],
apply typein_lt_type }
end⟩
/--
A function whose codomain's cardinality is infinite but strictly smaller than its domain's
has a fiber with cardinality strictly great than the codomain.
-/
theorem infinite_pigeonhole_card_lt {β α : Type u} (f : β → α)
(w : #α < #β) (w' : ω ≤ #α) :
∃ a : α, #α < #(f ⁻¹' {a}) :=
begin
simp_rw [← succ_le],
exact ordinal.infinite_pigeonhole_card f (#α).succ (succ_le.mpr w)
(w'.trans (lt_succ_self _).le)
((lt_succ_self _).trans_le (succ_is_regular w').2.ge),
end
/--
A function whose codomain's cardinality is infinite but strictly smaller than its domain's
has an infinite fiber.
-/
theorem exists_infinite_fiber {β α : Type*} (f : β → α)
(w : #α < #β) (w' : _root_.infinite α) :
∃ a : α, _root_.infinite (f ⁻¹' {a}) :=
begin
simp_rw [cardinal.infinite_iff] at ⊢ w',
cases infinite_pigeonhole_card_lt f w w' with a ha,
exact ⟨a, w'.trans ha.le⟩,
end
/--
If an infinite type `β` can be expressed as a union of finite sets,
then the cardinality of the collection of those finite sets
must be at least the cardinality of `β`.
-/
lemma le_range_of_union_finset_eq_top
{α β : Type*} [infinite β] (f : α → finset β) (w : (⋃ a, (f a : set β)) = ⊤) :
#β ≤ #(range f) :=
begin
have k : _root_.infinite (range f),
{ rw infinite_coe_iff,
apply mt (union_finset_finite_of_range_finite f),
rw w,
exact infinite_univ, },
by_contradiction h,
simp only [not_le] at h,
let u : Π b, ∃ a, b ∈ f a := λ b, by simpa using (w.ge : _) (set.mem_univ b),
let u' : β → range f := λ b, ⟨f (u b).some, by simp⟩,
have v' : ∀ a, u' ⁻¹' {⟨f a, by simp⟩} ≤ f a, begin rintros a p m,
simp at m,
rw ←m,
apply (λ b, (u b).some_spec),
end,
obtain ⟨⟨-, ⟨a, rfl⟩⟩, p⟩ := exists_infinite_fiber u' h k,
exact (@infinite.of_injective _ _ p (inclusion (v' a)) (inclusion_injective _)).false,
end
theorem sup_lt_ord_of_is_regular {ι} (f : ι → ordinal)
{c} (hc : is_regular c) (H1 : #ι < c)
(H2 : ∀ i, f i < c.ord) : ordinal.sup.{u u} f < c.ord :=
by { apply sup_lt_ord _ _ H2, rw [hc.2], exact H1 }
theorem sup_lt_of_is_regular {ι} (f : ι → cardinal)
{c} (hc : is_regular c) (H1 : #ι < c)
(H2 : ∀ i, f i < c) : sup.{u u} f < c :=
by { apply sup_lt _ _ H2, rwa [hc.2] }
theorem sum_lt_of_is_regular {ι} (f : ι → cardinal)
{c} (hc : is_regular c) (H1 : #ι < c)
(H2 : ∀ i, f i < c) : sum.{u u} f < c :=
lt_of_le_of_lt (sum_le_sup _) $ mul_lt_of_lt hc.1 H1 $
sup_lt_of_is_regular f hc H1 H2
/-- A cardinal is inaccessible if it is an uncountable regular strong limit cardinal. -/
def is_inaccessible (c : cardinal) :=
ω < c ∧ is_regular c ∧ is_strong_limit c
theorem is_inaccessible.mk {c}
(h₁ : ω < c) (h₂ : c ≤ c.ord.cof) (h₃ : ∀ x < c, 2 ^ x < c) :
is_inaccessible c :=
⟨h₁, ⟨le_of_lt h₁, le_antisymm (cof_ord_le _) h₂⟩,
ne_of_gt (lt_trans omega_pos h₁), h₃⟩
/- Lean's foundations prove the existence of ω many inaccessible cardinals -/
theorem univ_inaccessible : is_inaccessible (univ.{u v}) :=
is_inaccessible.mk
(by simpa using lift_lt_univ' ω)
(by simp)
(λ c h, begin
rcases lt_univ'.1 h with ⟨c, rfl⟩,
rw ← lift_two_power.{u (max (u+1) v)},
apply lift_lt_univ'
end)
theorem lt_power_cof {c : cardinal.{u}} : ω ≤ c → c < c ^ cof c.ord :=
quotient.induction_on c $ λ α h, begin
rcases ord_eq α with ⟨r, wo, re⟩, resetI,
have := ord_is_limit h,
rw [mk_def, re] at this ⊢,
rcases cof_eq' r this with ⟨S, H, Se⟩,
have := sum_lt_prod (λ a:S, #{x // r x a}) (λ _, #α) (λ i, _),
{ simp only [cardinal.prod_const, cardinal.lift_id, ← Se, ← mk_sigma, power_def] at this ⊢,
refine lt_of_le_of_lt _ this,
refine ⟨embedding.of_surjective _ _⟩,
{ exact λ x, x.2.1 },
{ exact λ a, let ⟨b, h, ab⟩ := H a in ⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩ } },
{ have := typein_lt_type r i,
rwa [← re, lt_ord] at this }
end
theorem lt_cof_power {a b : cardinal} (ha : ω ≤ a) (b1 : 1 < b) :
a < cof (b ^ a).ord :=
begin
have b0 : b ≠ 0 := ne_of_gt (lt_trans zero_lt_one b1),
apply lt_imp_lt_of_le_imp_le (power_le_power_left $ power_ne_zero a b0),
rw [← power_mul, mul_eq_self ha],
exact lt_power_cof (le_trans ha $ le_of_lt $ cantor' _ b1),
end
end cardinal
|
import LMT
variable {I} [Nonempty I] {E} [Nonempty E] [Nonempty (A I E)]
example {a1 a2 a3 : A I E} :
(v1) ≠ ((((a2).write i1 (v1)).write i3 (v1)).read i1) → False := by
arr
|
is.happy(2)
|
[STATEMENT]
lemma [named_ss vcg_bb]:
"UPD_STATE (s(x:=w)) x v = s(x:=v)"
"x\<noteq>y \<Longrightarrow> UPD_STATE (s(x:=w)) y v = (UPD_STATE s y v)(x:=w)"
"NO_MATCH (SS(XX:=VV)) s \<Longrightarrow> UPD_STATE s x v = s(x:=v)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. UPD_STATE (s(x := w)) x v = s(x := v) &&& (x \<noteq> y \<Longrightarrow> UPD_STATE (s(x := w)) y v = (UPD_STATE s y v)(x := w)) &&& (NO_MATCH (SS(XX := VV)) s \<Longrightarrow> UPD_STATE s x v = s(x := v))
[PROOF STEP]
by (auto simp: UPD_STATE_def) |
** Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
** See https://llvm.org/LICENSE.txt for license information.
** SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
* KANJI - NCHARACTER declarations, used in IMPLICIT, NLEN intrinsic.
implicit ncharacter*17 (i-k)
ncharacter a, b*2, c
ncharacter *171e, f*6
ncharacter*(16) g*3, h(10), i
ncharacter*10,j
integer i3, i6
integer expect(11), rslts(11)
data i3, i6 / 3, 6/
data expect / 1, 2, 1, 1000, -171,
+ 12, 3002, 16, 16, 34,
+ 4 /
rslts(1) = len(a)
rslts(2) = len(b)
rslts(3) = nlen(c)
rslts(4) = nlen(j) * 100
rslts(5) = -nlen(e)
rslts(6) = nlen(f // f)
rslts(7) = (1000 * nlen(g)) + nlen(g(2:3))
rslts(8) = len( h(nlen(b)) )
rslts(9) = max(len(i), -20)
rslts(10) = nlen(ii) + nlen(k)
rslts(11) = nlen( h(i3)(i3:i6) )
call check(rslts, expect, 11)
end
|
% ****** Start of file aipsamp.tex ******
%
% This file is part of the AIP files in the AIP distribution for REVTeX 4.
% Version 4.1 of REVTeX, October 2009
%
% Copyright (c) 2009 American Institute of Physics.
% Use this file as a source of example code for your aip document.
% Use the file aiptemplate.tex as a template for your document.
\documentclass[%
aip,
jmp,%
amsmath,amssymb,
%preprint,%
reprint,%
floatfix,
%author-year,%
%author-numerical,%
]{revtex4-1}
\usepackage{graphicx}% Include figure files
\usepackage{grffile}
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
%\usepackage[mathlines]{lineno}% Enable numbering of text and display math
%\linenumbers\relax % Commence numbering lines
\usepackage{multirow}
\usepackage{color} % for the notes
\usepackage{etex}
\reserveinserts{58}
%\usepackage{morefloats}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{amsmath}
\hypersetup{
colorlinks,
linkcolor={red!50!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}
%\usepackage{placeins}
\usepackage{xr}
\externaldocument{paper}
\usepackage[section] {placeins}
\newcommand{\beginsupplement}{%
\setcounter{table}{0}
\renewcommand{\thetable}{S\arabic{table}}%
\setcounter{figure}{0}
\renewcommand{\thefigure}{S\arabic{figure}}%
}
\beginsupplement
\begin{document}
\preprint{XXXXX (preprint)}
%\title[Evolution of interaction networks]{On the evolution of interaction networks: primitive typology of vertex, prominence of measures and activity statistics}% Force line breaks with \\
%\title[Evolution of interaction networks]{On the evolution of interaction networks: a primitive typology of vertex}% Force line breaks with \\
\title[Interaction networks stability: Supporting Information]{Time stability in human interaction networks, Supporting Information)}% Force line breaks with \\
\author{Renato Fabbri}%
\homepage{http://ifsc.usp.br/~fabbri/}
\email{[email protected]}
\affiliation{
S\~ao Carlos Institute of Physics, University of S\~ao Paulo (IFSC/USP)%\\This line break forced with \textbackslash\textbackslash
}
%\author{Vilson V. da Silva Jr.}
% \homepage{http://automata.cc/}
% \email{[email protected]}
% \altaffiliation[Also at ]{IFSC-USP}%Lines break automatically or can be forced with \\
%
%\author{Ricardo Fabbri}
% \homepage{http://www.lems.brown.edu/~rfabbri/}
% \email{[email protected]}
% \altaffiliation{
%Instituto Polit\'ecnico, Universidade Estadual do Rio de Janeiro (IPRJ)
%}%Lines break automatically or can be forced with \\
%
%\author{Deborah C. Antunes}
% \homepage{http://lattes.cnpq.br/1065956470701739}
% \email{[email protected]}
% \altaffiliation{
%Curso de Psicologia, Universidade Federal do Cer\'a (UFC)
%}%Lines break automatically or can be forced with \\
%
%\author{Marilia M. Pisani}
% \homepage{http://lattes.cnpq.br/6738980149860322}
% \email{[email protected]}
% \altaffiliation{
%Centro de Ci\^encias Naturais e Humanas, Universidade Federal do ABC (CCNH/UFABC)
%}%Lines break automatically or can be forced with \\
%
%%\author{Luciano da Fontoura Costa}
%% \homepage{http://cyvision.ifsc.usp.br/~luciano/}
%% \email{[email protected]}
% \altaffiliation[Also at ]{IFSC-USP}%Lines break automatically or can be forced with \\
%\author{Osvaldo N. Oliveira Jr.}
% \homepage{www.polimeros.ifsc.usp.br/professors/professor.php?id=4}
% \email{[email protected]}
% \altaffiliation[Also at ]{IFSC-USP}%Lines break automatically or can be forced with \\
\date{\today}% It is always \today, today,
% but any date may be explicitly specified
\maketitle
\section{Activity along time}\label{sec:time}
The activity along time obtained with circular statistics measurements is presented for the email lists.
\begin{table*}[!h]
\caption{LAU circular measurements}
\begin{center}
\begin{tabular}{ |l|| c|c|c|c|c||c|c| }
\hline
scale & $\theta_\mu'$ & $S(z)$ & $Var(z)$ & $\delta(z)$ & $\frac{max(incidence)}{min(incidence)}$ & $ \mu_{\frac{max(incidence')}{min(incidence')}} $ & $ \sigma_{\frac{max(incidence')}{min(incidence')} } $ \\ \hline\hline
\input{tables/tab2TimeLAU}
\end{tabular}
\end{center}
\label{tab:circLau}
\end{table*}
\begin{table*}[!h]
\caption{LAD circular measurements}
\begin{center}
\begin{tabular}{ |l|| c|c|c|c|c||c|c| }
\hline
scale & $\theta_\mu'$ & $S(z)$ & $Var(z)$ & $\delta(z)$ & $\frac{max(incidence)}{min(incidence)}$ & $ \mu_{\frac{max(incidence')}{min(incidence')}} $ & $ \sigma_{\frac{max(incidence')}{min(incidence')} } $ \\ \hline\hline
\input{tables/tab2TimeLAD}
\end{tabular}
\end{center}
\label{tab:circLad}
\end{table*}
\begin{table*}[!h]
\caption{MET circular measurements}
\begin{center}
\begin{tabular}{ |l|| c|c|c|c|c||c|c| }
\hline
scale & $\theta_\mu'$ & $S(z)$ & $Var(z)$ & $\delta(z)$ & $\frac{max(incidence)}{min(incidence)}$ & $ \mu_{\frac{max(incidence')}{min(incidence')}} $ & $ \sigma_{\frac{max(incidence')}{min(incidence')} } $ \\ \hline\hline
\input{tables/tab2TimeMET}
\end{tabular}
\end{center}
\label{tab:circMet}
\end{table*}
\begin{table*}[!h]
\caption{CPP circular measurements}
\begin{center}
\begin{tabular}{ |l|| c|c|c|c|c||c|c| }
\hline
scale & $\theta_\mu'$ & $S(z)$ & $Var(z)$ & $\delta(z)$ & $\frac{max(incidence)}{min(incidence)}$ & $ \mu_{\frac{max(incidence')}{min(incidence')}} $ & $ \sigma_{\frac{max(incidence')}{min(incidence')} } $ \\ \hline\hline
\input{tables/tab2TimeCPP}
\end{tabular}
\end{center}
\label{tab:circCPP}
\end{table*}
\begin{table}[!h]
\caption{LAU activity along the hours of the day}
\footnotesize
\input{tables/tabHoursLAU}
\end{table}
\begin{table}[!h]
\caption{LAD activity along the hours of the day}
\footnotesize
\input{tables/tabHoursLAD}
\end{table}
\begin{table}[!h]
\caption{MET activity along the hours of the day}
\footnotesize
\input{tables/tabHoursMET}
\end{table}
\begin{table}[!h]
\caption{CPP activity along the hours of the day}
\footnotesize
\input{tables/tabHoursCPP}
\end{table}
\begin{table}[!h]
\begin{center}
\begin{tabular}{ | l | c | c | c | c | c | c | c |}
\hline
& Mon & Tue & Wed & Thu & Fri & Sat & Sun \\ \hline
\input{tables/tabWeekdays}
\end{tabular}
\end{center}
\label{tab:win}
\end{table}
\begin{table}[!h]
\caption{LAU activity along the days of the month.}
\footnotesize
\input{tables/tabMonthdaysLAU}
\label{tab:min}
\end{table}
\begin{table}[!h]
\caption{LAD activity along the days of the month.}
\footnotesize
\input{tables/tabMonthdaysLAD}
\label{tab:min}
\end{table}
\begin{table}[!h]
\caption{MET activity along the days of the month.}
\footnotesize
\input{tables/tabMonthdaysMET}
\label{tab:min}
\end{table}
\begin{table}[!h]
\caption{CPP activity along the days of the month.}
\footnotesize
\input{tables/tabMonthdaysCPP}
\label{tab:min}
\end{table}
\begin{table}[!h]
\caption{LAU activity along the months of the year.}
\footnotesize
\input{tables/tabMonthsLAU}
\label{tab:min2}
\end{table}
\begin{table}[!h]
\caption{LAD activity along the months of the year.}
\footnotesize
\input{tables/tabMonthsLAD}
\label{tab:min2}
\end{table}
\begin{table}[!h]
\caption{MET activity along the months of the year.}
\footnotesize
\input{tables/tabMonthsMET}
\label{tab:min2}
\end{table}
\begin{table}[!h]
\caption{CPP activity along the months of the year.}
\footnotesize
\input{tables/tabMonthsCPP}
\label{tab:min2}
\end{table}
\section{Fraction of participants in each Erd\"os Sector along the timeline}\label{si:frac}
Here we present the fraction of participants in each Erd\"os sector with respect to each criterion defined in Section~\ref{sectioning}. Step sizes of 50, 100, 250, 500, 1000 and 5000 are shown below, first for CPP, than for the LAD list.
Each step size takes two pages of plot. On the first page, the criterion is based on each centrality metric observed separately: in, out and total degrees and strengths. In the first six plots, the code for the colors is as follows: red for hubs, green for the fraction of intermediary vertices and blue for the peripheral fraction. On the last plot, red is the center (maximum distance to another vertex is equal to radius), blue is periphery (maximum distance equals to diameter) of the greatest component. On the same graph, green represents the disconnected vertices.
On the second page we show the fractions of participants with respect to each compound criterion for the Erd\"os sectioning. In the first plot, the fraction of vertices with unique classification is plotted in black: $\frac{\text{number of nodes uniquely classified}}{\text{number of nodes}}$. On the second plot, black represents the exceeding classifications for the given vertices: $\frac{\text{number of classifications} - \text{number of nodes}}{\text{number of nodes}}$.
\subsection{CPP list}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-50/CPP-W50-S200}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-50/CPP-W50-S200_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-100/CPP-W100-S200}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-100/CPP-W100-S200_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-250/CPP-W250-S250}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-250/CPP-W250-S250_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-500/CPP-W500-S500}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-500/CPP-W500-S500_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-1000/CPP-W1000-S1000}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-1000/CPP-W1000-S1000_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-3300/CPP-W3300-S3300}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-3300/CPP-W3300-S3300_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-9900/CPP-W9900-S9900}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineCPP-9900/CPP-W9900-S9900_}
\end{figure*}
\FloatBarrier
\subsection{LAD list}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-50/LAD-W50-S200}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-50/LAD-W50-S200_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-100/LAD-W100-S200}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-100/LAD-W100-S200_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-250/LAD-W250-S250}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-250/LAD-W250-S250_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-500/LAD-W500-S500}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-500/LAD-W500-S500_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-1000/LAD-W1000-S1000}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-1000/LAD-W1000-S1000_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-3300/LAD-W3300-S3300}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-3300/LAD-W3300-S3300_}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-9900/LAD-W9900-S9900}
\end{figure*}
\begin{figure*}
\centering
\includegraphics[width=\textwidth]{evoTimelines/evoTimelineLAD-9900/LAD-W9900-S9900_}
\end{figure*}
\FloatBarrier
\section{PCA for the metrics along the timeline}\label{si:pcat}
Loadings for the 14 metrics into the principal components are given for all LAD, LAU, MET, CPP, lists, $ws=1000$ messages in 20 disjoint positioning. The clustering coefficient (cc) appears as the first metric in the Table, followed by 7 centrality metrics and 6 symmetry-related metrics. Note that the centrality metrics, including degrees, strength and betweenness centrality, are the most important contributors for the first principal component, while the second component is dominated by symmetry metrics. The clustering coefficient is only relevant for the third principal component, coupled with standard deviations of strengths and degrees. The three components have in average 80.36\% of the variance.
\subsection{Betweenness, clustering and degree}
\begin{table}[!h]
\caption{LAU principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA1LAU}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{LAD principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA1LAD}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{MET principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA1MET}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{CPP principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA1CPP}
\label{tab:pcain}
\end{table}
\FloatBarrier
\subsection{Betweenness, clustering, degrees and strengths}
\begin{table}[!h]
\caption{LAU principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA2LAU}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{LAD principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA2LAD}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{MET principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA2MET}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{CPP principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA2CPP}
\label{tab:pcain}
\end{table}
\FloatBarrier
\subsection{Betweenness, clustering, degrees, strengths and symmetry measures}
\begin{table}[!h]
\caption{LAU principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA3LAU}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{LAD principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA3LAD}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{MET principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA3MET}
\label{tab:pcain}
\end{table}
\begin{table}[!h]
\caption{CPP principal components formation and concentration of dispersion.}
\footnotesize
\input{tables/tabPCA3CPP}
\label{tab:pcain}
\end{table}
\section{Stability in other networks: Twitter, Facebook, Participa.br}\label{si:ext}
To further verify the hypothesis that such stability is a general property of human social networks,
we analyzed networks from Twitter, Facebook and Participa.br. Selected networks are summarized in
Table~\ref{tab:E}. Their Erd\"os sector relative sizes are given in Table~\ref{tab:secE}. PCA formations are given in
Tables~\ref{tab:pcaE1F},~\ref{tab:pcaE1I},~\ref{tab:pcaE2} and~\ref{tab:pcaE3}. The friendship networks considered are undirected and unweighted, therefore all measurements of strength, in- and out- centralities, asymmetry and disequilibrium have little or no meaning, which is why F1, F2, F3, F4 and F5 are only present in Table~\ref{tab:pcaE1F}.
The most important results from this analysis are:
\begin{itemize}
\item the stability reported for email interaction networks is also valid for a broader class of phenomena.
\item the stability in email interaction networks is higher than for the other networks, considering the same number of participants. This is especially important for benchmarking and probing general properties.
\end{itemize}
\begin{table*}[!h]
\caption{Overview of selected networks analyzed in addition to email interaction networks. Three social platforms were the sources of network structures: Facebook, Twitter and Participa.br. Both friendship and interaction networks were observed, yielding undirected and directed networks, respectively. The number of agents $N$ and the number of edges $z$ are given on the last columns. The acronyms, one for each network, are used throughout Tables~\ref{tab:secE},~\ref{tab:pcaE1I},~\ref{tab:pcaE1F},~\ref{tab:pcaE2} and~\ref{tab:pcaE3}. All the data were collected in 2013 and 2014.}
\begin{center}
\begin{tabular}{| l | c | c | c | c | c | c | }\hline
acronym & provenance & edge & directed & description & $N$ & $z$ \\ \hline\hline
\input{tables/tabExtra}
\hline
\end{tabular}
\end{center}
\label{tab:E}
\end{table*}
\begin{table*}[!h]
\caption{Percentage of agents in each Erd\"os sector in the friendship and interaction human networks of Table~\ref{tab:E}. The ratios found in email networks are preserved. I1 and I4 are outliers, probably because they should be better characterized as a superposition of networks, rather than one coherent network. The degree was used for establishing the sectors.}
\begin{center}
\begin{tabular}{| l | c | c | c |}\hline
& periphery & intermediary & hubs \\ \hline\hline
\input{tables/tabSectorsExtra}
\hline
\end{tabular}
\end{center}
\label{tab:secE}
\end{table*}
\begin{table*}[!h]
\caption{First three principal components and variance concentration for each of the five friendship networks of Table~\ref{tab:E} in the simplest case: dimensions correspond to degree, clustering coefficient and betweenness centrality. Participa.br yields the networks that most resemble the email networks. Overall, the general characteristic is preserved: first component is an average of degree and betweenness, while clustering is the most relevant for the second component. The friendship network of Renato Fabbri (F1) is the only network whose first component has more than 20\% of clustering coefficient and second component has more than 40\% of degree centrality.}
\footnotesize
\begin{center}
%\begin{tabular}{| l | c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c | c | c | c |}\hline
\begin{tabular}{| l || c |c |c |c |c || c | c | c | c | c || c |c |c |c |c | }\cline{2-16}
% & p. & i. & h. \\ \hline\hline
\multicolumn{1}{c|}{} & \multicolumn{5}{c||}{PC1} & \multicolumn{5}{c||}{PC2} & \multicolumn{5}{c|}{PC3} \\\cline{2-16}
\multicolumn{1}{c|}{} &
F1 & F2 & F3 & F4 & F5 &
F1 & F2 & F3 & F4 & F5 &
F1 & F2 & F3 & F4 & F5 \\\hline
\input{tables/tabPCA1ExtraF}
\hline
\end{tabular}
\end{center}
\label{tab:pcaE1F}
\end{table*}
\begin{table*}[!h]
\caption{First three principal components and variance concentration for each of the seven interaction networks of Table~\ref{tab:E} in the simplest case: dimensions correspond to degree, clustering coefficient and betweenness centrality. Twitter yields the networks that most resemble the email networks. Overall, the general characteristic is preserved: first component is an average of degree and betweenness, while clustering is the most relevant for the second component.}
\footnotesize
\begin{center}
%\begin{tabular}{| l | c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c | c | c | c |}\hline
\begin{tabular}{| l || c |c |c |c |c | c | c || c | c | c | c | c | c | c || c |c |c |c |c | c | c | }\cline{2-22}
% & p. & i. & h. \\ \hline\hline
\multicolumn{1}{c|}{} & \multicolumn{7}{c||}{PC1} & \multicolumn{7}{c||}{PC2} & \multicolumn{7}{c|}{PC3} \\\cline{2-22}
\multicolumn{1}{c|}{} &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 \\\hline
\input{tables/tabPCA1ExtraI}
\hline
\end{tabular}
\end{center}
\label{tab:pcaE1I}
\end{table*}
\begin{table*}[!h]
\caption{First three principal components and variance concentration for each of the seven interaction networks of Table~\ref{tab:E} considering dimensions of in- and out- degrees and strengths, clustering coefficient and betweenness centrality. Twitter yields the networks that most resemble email networks. The general characteristic is preserved: first component is an average of degree and betweenness, while clustering is the most relevant for the second component. Important differences are: - the clustering coefficient was only important to the third component for two of the networks ($I2$, $I3$) and does not contribute significantly to any of the first three principal components in $I5$; - in the first component, I5 exhibited less contribution from in-strength, in-degree and betweenness, I4 exhibited less contribution from out-degree.}
\footnotesize
\begin{center}
%\begin{tabular}{| l | c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c | c | c | c |}\hline
\begin{tabular}{| l || c |c |c |c |c | c | c || c | c | c | c | c | c | c || c |c |c |c |c | c | c | }\cline{2-22}
% & p. & i. & h. \\ \hline\hline
\multicolumn{1}{c|}{} & \multicolumn{7}{c||}{PC1} & \multicolumn{7}{c||}{PC2} & \multicolumn{7}{c|}{PC3} \\\cline{2-22}
\multicolumn{1}{c|}{} &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 \\\hline
\input{tables/tabPCA2Extra}
\hline
\end{tabular}
\end{center}
\label{tab:pcaE2}
\end{table*}
\begin{table*}[!h]
\caption{First three principal components and variance concentration for each of the seven interaction networks of Table~\ref{tab:E} considering dimensions of in- and out- degrees and strengths, clustering coefficient, betweenness centrality and symmetry related metrics (see Section~\ref{measures}). The characteristics found in email interaction networks are preserved: the first component is an average of degree and betweenness, the second component is mostly governed by symmetry related metrics, and clustering coefficient is mostly relevant for the third component. Standard deviation of asymmetry and disequilibrium metrics are again coupled to clustering coefficient in the third component. Important differences are: - the first component is a less regular average of centrality measures and has a greater contribution of symmetry metrics; - The first component of I5 is formed mostly from symmetry, not centrality, metrics.}
\footnotesize
\begin{center}
%\begin{tabular}{| l | c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c |c | c | c | c |}\hline
\begin{tabular}{| l || c |c |c |c |c | c | c || c | c | c | c | c | c | c || c |c |c |c |c | c | c | }\cline{2-22}
% & p. & i. & h. \\ \hline\hline
\multicolumn{1}{c|}{} & \multicolumn{7}{c||}{PC1} & \multicolumn{7}{c||}{PC2} & \multicolumn{7}{c|}{PC3} \\\cline{2-22}
\multicolumn{1}{c|}{} &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 &
I1 & I2 & I3 & I4 & I5 & TT1 & TT2 \\\hline
\input{tables/tabPCA3Extra}
\hline
\end{tabular}
\end{center}
\label{tab:pcaE3}
\end{table*}
%\begin{table}[!h]
% \caption{PCA2.}
% \footnotesize
% \input{tables/tabPCA2Extra}
%\label{tab:pcaE2}
%\end{table}
%\begin{table}[!h]
% \caption{PCA3.}
% \footnotesize
% \input{tables/tabPCA3Extra}
%\label{tab:pcaE3}
%\end{table}
%\newpage
%\pagebreak
\clearpage
\nocite{*}
\bibliography{supportingInformation}% Produces the bibliography via BibTeX.
\end{document}
%
% ****** End of file aipsamp.tex ******
|
text\<open> 8 October 2021: Exercise for Homework Assignment 06 in CS 511 \<close>
text\<open> Your task to remove the invocation of the pre-defined method blast,
by an equivalent sequence of 'apply' steps \<close>
text\<open> This is a continuation of the Isabelle exercise you did for
Homework Assignment 05, and inspired by the exercise on page 32
in Lecture Slides 11 "Quantified Propositional Logic" \<close>
theory HW06
imports Main
begin
(* The following is a theorem of QPL. Note that "=" means the same as "\<longleftrightarrow>" *)
theorem "(\<exists>y. (y = Phi) \<and> (y \<or> Psi1) \<and> (y \<or> Psi2)) \<longleftrightarrow> (Phi \<or> Psi1) \<and> (Phi \<or> Psi2)"
apply (rule simp_thms)
done
end |
/-
Copyright (c) 2021 OpenAI. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f
-/
import mathzoo.imports.miniF2F
open_locale nat rat real big_operators topological_space
theorem amc12b_2003_p9
(a b : ℝ)
(f : ℝ → ℝ)
(h₀ : ∀ x, f x = a * x + b)
(h₁ : f 6 - f 2 = 12) :
f 12 - f 2 = 30 :=
begin
simp [*] at *,
linarith,
end |
namespace Ex1
def f (x : Nat) : Nat := by
cases x with
| zero => exact 1
| succ x' =>
apply Nat.mul 2
exact f x'
#eval f 10
example : f x.succ = 2 * f x := rfl
end Ex1
namespace Ex2
inductive Foo where
| mk : List Foo → Foo
mutual
def g (x : Foo) : Nat := by
cases x with
| mk xs => exact gs xs
def gs (xs : List Foo) : Nat := by
cases xs with
| nil => exact 1
| cons x xs =>
apply Nat.add
exact g x
exact gs xs
end
end Ex2
namespace Ex3
inductive Foo where
| a | b | c
| pair: Foo × Foo → Foo
def Foo.deq (a b : Foo) : Decidable (a = b) := by
cases a <;> cases b
any_goals apply isFalse Foo.noConfusion
any_goals apply isTrue rfl
case pair a b =>
let (a₁, a₂) := a
let (b₁, b₂) := b
exact match deq a₁ b₁, deq a₂ b₂ with
| isTrue h₁, isTrue h₂ => isTrue (by rw [h₁,h₂])
| isFalse h₁, _ => isFalse (fun h => by cases h; cases (h₁ rfl))
| _, isFalse h₂ => isFalse (fun h => by cases h; cases (h₂ rfl))
end Ex3
|
(* Title: statecharts/DataSpace/Data.thy
Author: Steffen Helke, Software Engineering Group
Copyright 2010 Technische Universitaet Berlin
*)
header {* Data Space Assignments *}
theory Data
imports DataSpace
begin
subsection {* Total data space assignments *}
definition
Data :: "['d list, 'd dataspace]
=> bool" where
"Data L D = (((length L) = (PartNum D)) \<and>
(\<forall> i \<in> {n. n < (PartNum D)}. (L!i) \<in> (PartDom D i)))"
lemma Data_EmptySet:
"([@ t. True], Abs_dataspace [UNIV])\<in> { (L,D) | L D. Data L D }";
apply (unfold Data_def PartDom_def)
apply auto
apply (subst Abs_dataspace_inverse)
apply auto
done
definition
"data =
{ (L,D) |
(L::('d list))
(D::('d dataspace)).
Data L D }"
typedef 'd data = "data :: ('d list * 'd dataspace) set"
unfolding data_def
apply (rule exI)
apply (rule Data_EmptySet)
done
definition
DataValue :: "('d data) => ('d list)" where
"DataValue = fst o Rep_data"
definition
DataSpace :: "('d data) => ('d dataspace)" where
"DataSpace = snd o Rep_data"
definition
DataPart :: "['d data, nat] => 'd" ("(_ !P!/ _)" [10,11]10) where
"DataPart d n = (DataValue d) ! n"
lemma Rep_data_tuple:
"Rep_data D = (DataValue D, DataSpace D)";
by (unfold DataValue_def DataSpace_def, simp)
lemma Rep_data_select:
"(DataValue D, DataSpace D) \<in> data";
apply (subst Rep_data_tuple [THEN sym])
apply (rule Rep_data)
done
lemma Data_select:
"Data (DataValue D) (DataSpace D)"
apply (cut_tac D=D in Rep_data_select)
apply (unfold data_def)
apply auto
done
lemma length_DataValue_PartNum [simp]:
"length (DataValue D) = PartNum (Data.DataSpace D)"
apply (cut_tac D=D in Data_select)
apply (unfold Data_def)
apply auto
done
lemma DataValue_PartDom [simp]:
"i < PartNum (Data.DataSpace D) \<Longrightarrow>
DataValue D ! i \<in> PartDom (Data.DataSpace D) i";
apply (cut_tac D=D in Data_select)
apply (unfold Data_def)
apply auto
done
lemma DataPart_PartDom [simp]:
"i < PartNum (Data.DataSpace d) \<longrightarrow> (d !P! i) \<in> ((Data.DataSpace d) !D! i)";
apply (unfold DataPart_def)
apply auto
done
subsection {* Partial data space assignments *}
definition
PData :: "['d option list, 'd dataspace] => bool" where
"PData L D == ((length L) = (PartNum D)) \<and>
(\<forall> i \<in> {n. n < (PartNum D)}.
(L!i) \<noteq> None \<longrightarrow> the (L!i) \<in> (PartDom D i))"
lemma PData_EmptySet:
"([Some (@ t. True)], Abs_dataspace [UNIV]) \<in> { (L,D) | L D. PData L D }";
apply (unfold PData_def PartDom_def)
apply auto
apply (subst Abs_dataspace_inverse)
apply auto
done
definition
"pdata =
{ (L,D) |
(L::('d option list))
(D::('d dataspace)).
PData L D }"
typedef 'd pdata = "pdata :: ('d option list * 'd dataspace) set"
unfolding pdata_def
apply (rule exI)
apply (rule PData_EmptySet)
done
definition
PDataValue :: "('d pdata) => ('d option list)" where
"PDataValue = fst o Rep_pdata"
definition
PDataSpace :: "('d pdata) => ('d dataspace)" where
"PDataSpace = snd o Rep_pdata"
definition
Data2PData :: "('d data) => ('d pdata)" where
"Data2PData D = (let
(L,DP) = Rep_data D;
OL = map Some L
in
Abs_pdata (OL,DP))"
definition
PData2Data :: "('d pdata) => ('d data)" where
"PData2Data D = (let
(OL,DP) = Rep_pdata D;
L = map the OL
in
Abs_data (L,DP))"
definition
DefaultPData :: "('d dataspace) => ('d pdata)" where
"DefaultPData D = Abs_pdata (replicate (PartNum D) None, D)"
definition
OptionOverride :: "('d option * 'd) => 'd" where
"OptionOverride P = (if (fst P) = None then (snd P) else (the (fst P)))"
definition
DataOverride :: "['d pdata, 'd data] => 'd data" ("(_ [D+]/ _)" [10,11]10) where
"DataOverride D1 D2 =
(let
(L1,DP1) = Rep_pdata D1;
(L2,DP2) = Rep_data D2;
L = map OptionOverride (zip L1 L2)
in
Abs_data (L,DP2))"
lemma Rep_pdata_tuple:
"Rep_pdata D = (PDataValue D, PDataSpace D)"
apply (unfold PDataValue_def PDataSpace_def)
apply (simp)
done
lemma Rep_pdata_select:
"(PDataValue D, PDataSpace D) \<in> pdata";
apply (subst Rep_pdata_tuple [THEN sym])
apply (rule Rep_pdata)
done
lemma PData_select:
"PData (PDataValue D) (PDataSpace D)"
apply (cut_tac D=D in Rep_pdata_select)
apply (unfold pdata_def)
apply auto
done
subsubsection {* @{text "DefaultPData"} *}
lemma PData_DefaultPData [simp]:
"PData (replicate (PartNum D) None) D"
apply (unfold PData_def)
apply auto
done
lemma pdata_DefaultPData [simp]:
"(replicate (PartNum D) None, D) \<in> pdata "
apply (unfold pdata_def)
apply auto
done
lemma PDataSpace_DefaultPData [simp]:
"PDataSpace (DefaultPData D) = D"
apply (unfold DataSpace_def PDataSpace_def DefaultPData_def)
apply auto
apply (subst Abs_pdata_inverse)
apply auto
done
lemma length_PartNum_PData [simp]:
"length (PDataValue P) = PartNum (PDataSpace P)"
apply (cut_tac D=P in Rep_pdata_select)
apply (unfold pdata_def PData_def)
apply auto
done
subsubsection {* @{text "Data2PData"} *}
lemma PData_Data2PData [simp]:
"PData (map Some (DataValue D)) (Data.DataSpace D)";
apply (unfold PData_def)
apply auto
done
lemma pdata_Data2PData [simp]:
"(map Some (DataValue D), Data.DataSpace D) \<in> pdata";
apply (unfold pdata_def)
apply auto
done
lemma DataSpace_Data2PData [simp]:
"(PDataSpace (Data2PData D)) = (Data.DataSpace D)"
apply (unfold DataSpace_def PDataSpace_def Data2PData_def Let_def)
apply auto
apply (cut_tac D=D in Rep_data_tuple)
apply auto
apply (subst Abs_pdata_inverse)
apply auto
done
lemma PDataValue_Data2PData_DataValue [simp]:
"(map the (PDataValue (Data2PData D))) = DataValue D";
apply (unfold DataValue_def PDataValue_def Data2PData_def Let_def)
apply auto
apply (cut_tac D=D in Rep_data_tuple)
apply auto
apply (subst Abs_pdata_inverse)
apply simp
apply (simp del: map_map)
done
lemma DataSpace_PData2Data:
"Data (map the (PDataValue D)) (PDataSpace D) \<Longrightarrow>
(Data.DataSpace (PData2Data D) = (PDataSpace D))"
apply (unfold DataSpace_def PDataSpace_def PData2Data_def Let_def)
apply auto
apply (cut_tac D=D in Rep_pdata_tuple)
apply auto
apply (subst Abs_data_inverse)
apply (unfold data_def)
apply auto
done
lemma PartNum_PDataValue_PartDom [simp]:
"\<lbrakk> i < PartNum (PDataSpace Q);
PDataValue Q ! i = Some y \<rbrakk> \<Longrightarrow>
y \<in> PartDom (PDataSpace Q) i"
apply (cut_tac D=Q in Rep_pdata_select)
apply (unfold pdata_def PData_def)
apply auto
done
subsubsection {* @{text "DataOverride"} *}
lemma Data_DataOverride:
"((PDataSpace P) = (Data.DataSpace Q)) \<Longrightarrow>
Data (map OptionOverride (zip (PDataValue P) (Data.DataValue Q))) (Data.DataSpace Q)"
apply (unfold Data_def)
apply auto
apply (unfold OptionOverride_def)
apply auto
apply (rename_tac i D)
apply (case_tac "PDataValue P ! i = None")
apply auto
apply (drule sym)
apply auto
done
lemma data_DataOverride:
"((PDataSpace P) = (Data.DataSpace Q)) \<Longrightarrow>
(map OptionOverride (zip (PDataValue P) (Data.DataValue Q)), Data.DataSpace Q) \<in> data";
apply (unfold data_def)
apply auto
apply (rule Data_DataOverride)
apply fast
done
lemma DataSpace_DataOverride [simp]:
"((Data.DataSpace D) = (PDataSpace E)) \<Longrightarrow>
Data.DataSpace (E [D+] D) = (Data.DataSpace D)"
apply (unfold DataSpace_def DataOverride_def Let_def)
apply auto
apply (cut_tac D=D in Rep_data_tuple)
apply (cut_tac D=E in Rep_pdata_tuple)
apply auto
apply (subst Abs_data_inverse)
apply auto
apply (drule sym)
apply simp
apply (rule data_DataOverride)
apply auto
done
lemma DataValue_DataOverride [simp]:
"((PDataSpace P) = (Data.DataSpace Q)) \<Longrightarrow>
(DataValue (P [D+] Q)) = (map OptionOverride (zip (PDataValue P) (Data.DataValue Q)))"
apply (unfold DataValue_def DataOverride_def Let_def)
apply auto
apply (cut_tac D=P in Rep_pdata_tuple)
apply (cut_tac D=Q in Rep_data_tuple)
apply auto
apply (subst Abs_data_inverse)
apply auto
apply (rule data_DataOverride)
apply auto
done
subsubsection {* @{text "OptionOverride"} *}
lemma DataValue_OptionOverride_nth:
"\<lbrakk> ((PDataSpace P) = (DataSpace Q));
i < PartNum (DataSpace Q) \<rbrakk> \<Longrightarrow>
(DataValue (P [D+] Q) ! i) =
OptionOverride (PDataValue P ! i, DataValue Q ! i)"
apply auto
done
lemma None_OptionOverride [simp]:
"(fst P) = None \<Longrightarrow> OptionOverride P = (snd P)";
apply (unfold OptionOverride_def)
apply auto
done
lemma Some_OptionOverride [simp]:
"(fst P) \<noteq> None \<Longrightarrow> OptionOverride P = the (fst P)";
apply (unfold OptionOverride_def)
apply auto
done
end |
Require Export SystemFR.Judgments.
Require Export SystemFR.AnnotatedTactics.
Require Export SystemFR.ErasedSubtype.
Opaque reducible_values.
Lemma annotated_subtype_arrow:
forall Θ Γ A1 A2 B1 B2 x,
~(x ∈ fv_context Γ) ->
~(x ∈ fv A2) ->
~(x ∈ fv B2) ->
~(x ∈ fv B1) ->
~(x ∈ Θ) ->
is_annotated_type A2 ->
is_annotated_type B2 ->
[[ Θ; Γ ⊨ B1 <: A1 ]] ->
[[ Θ; (x,B1) :: Γ ⊨ open 0 A2 (fvar x term_var) <: open 0 B2 (fvar x term_var) ]] ->
[[ Θ; Γ ⊨ T_arrow A1 A2 <: T_arrow B1 B2 ]].
Proof.
unfold open_subtype;
repeat step.
apply reducible_arrow_subtype_subst with (erase_type A1) (erase_type A2) (erase_context Γ) x;
repeat step;
side_conditions.
unshelve epose proof (H7 ρ l0 _ _ _ v0 _);
repeat step || erase_open.
Qed.
Lemma annotated_subtype_arrow2:
forall Θ Γ T A B x f,
~(x ∈ fv_context Γ) ->
~(f ∈ fv_context Γ) ->
~(x = f) ->
~(x ∈ fv B) ->
~(f ∈ fv B) ->
~(x ∈ fv A) ->
~(f ∈ fv A) ->
~(x ∈ fv T) ->
~(f ∈ fv T) ->
~(x ∈ Θ) ->
~(f ∈ Θ) ->
is_annotated_type B ->
[[ Θ; (x,A) :: (f,T) :: Γ ⊨
app (fvar f term_var) (fvar x term_var) : open 0 B (fvar x term_var) ]] ->
[[ Θ; Γ ⊨ T <: T_arrow A B ]].
Proof.
unfold open_subtype;
repeat step.
apply subtype_arrow2 with (support ρ) x f (erase_context Γ) (erase_type T);
repeat step || erase_open;
side_conditions.
Qed.
|
function compute(x, y) result (z)
implicit none
double precision :: x, y, z
z = x + y
return
end function compute
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.algebra.basic
import Mathlib.algebra.star.basic
import Mathlib.PostPort
universes u v l
namespace Mathlib
/-!
# Star algebras
Introduces the notion of a star algebra over a star ring.
-/
/--
A star algebra `A` over a star ring `R` is an algebra which is a star ring,
and the two star structures are compatible in the sense
`star (r • a) = star r • star a`.
-/
-- Note that we take `star_ring A` as a typeclass argument, rather than extending it,
-- to avoid having multiple definitions of the star operation.
class star_algebra (R : Type u) (A : Type v) [comm_semiring R] [star_ring R] [semiring A]
[star_ring A] [algebra R A]
where
star_smul : ∀ (r : R) (a : A), star (r • a) = has_star.star r • star a
@[simp] theorem star_smul (R : Type u) (A : Type v) [comm_semiring R] [star_ring R] [semiring A]
[star_ring A] [algebra R A] [star_algebra R A] (r : R) (a : A) :
star (r • a) = star r • star a :=
star_algebra.star_smul r a
end Mathlib |
The Rhode Island Department of Transportation ( RIDOT ) has laid out long @-@ term plans for improvements to both the southern and northern termini of Route 4 . During the 1980s and 1990s , RIDOT announced plans to eliminate the three traffic lights along the southern end of the highway . The department planned to replace the existing signalized US 1 and Route 4 merge , converting it into a grade @-@ separated interchange with an extensive overpass . This would cut @-@ off access to three local roads that intersect US 1 near the signal . The plan also included the replacement of the two other signaled intersections at West Allenton Road and Oak Hill Road with overpasses ; the overpass for West Allenton Road is planned to be constructed as a new exit 4 . In the 1990s , the state purchased and demolished several houses in the region to allow for an expanded Route 4 right @-@ of @-@ way in the vicinity of West Allenton Road .
|
import algebra.module.basic
import algebra.module.linear_map
import linear_algebra.basic
import linear_algebra.prod
import linear_algebra.projection
import order.bounded_lattice
theorem cpge_reduction_7_a (R : Type*) (M : Type*)
[semiring R] [add_comm_monoid M] [module R M]
(E : submodule R M) (u : linear_map R M M):
u^3 + u = 0 -> (u '' E) ⊂ E := sorry |
I was watching TV with Devin the other day and we were watching some of the filler programing between shows on PBS. We don't have cable so the only kids shows the kids can watch outside of Saturday morning is on PBS and TVO. Rather than have commercials these networks show these short 2 minute filler … Continue reading Humanism on PBS? |
(** * Pushout of a Monic is Monic, Pullback of an Epi is Epi *)
(** Contents
- Pushout of a Monic is Monic
- Pushout of a Monic is Pullback
- Pullback of an Epi is Epi
- Pullback of an Epi is Pushout
*)
Require Import UniMath.Foundations.PartD.
Require Import UniMath.Foundations.Propositions.
Require Import UniMath.Foundations.Sets.
Require Import UniMath.CategoryTheory.limits.zero.
Require Import UniMath.CategoryTheory.limits.pushouts.
Require Import UniMath.CategoryTheory.limits.pullbacks.
Require Import UniMath.CategoryTheory.limits.equalizers.
Require Import UniMath.CategoryTheory.limits.coequalizers.
Require Import UniMath.CategoryTheory.limits.Opp.
Require Import UniMath.CategoryTheory.Core.Categories.
Require Import UniMath.CategoryTheory.opp_precat.
Local Open Scope cat.
Require Import UniMath.CategoryTheory.Monics.
Require Import UniMath.CategoryTheory.Epis.
Require Import UniMath.CategoryTheory.Morphisms.
Require Import UniMath.CategoryTheory.CategoriesWithBinOps.
Require Import UniMath.CategoryTheory.PrecategoriesWithAbgrops.
Require Import UniMath.CategoryTheory.PreAdditive.
Require Import UniMath.CategoryTheory.Additive.
Require Import UniMath.CategoryTheory.Abelian.
Require Import UniMath.CategoryTheory.AbelianToAdditive.
Require Import UniMath.CategoryTheory.limits.kernels.
Require Import UniMath.CategoryTheory.limits.cokernels.
Require Import UniMath.CategoryTheory.limits.BinDirectSums.
(** ** Introduction
We show that in abelian categories pushout of a Monic is a Monic and pullback of an Epi is an Epi.
Also, in this case the pushout diagram (resp. pullback diagram) is a pullback diagram (resp. pushout
diagram).
More precisely, let f : x --> y and g : x --> z be morphisms in an abelian category. Consider the
following pushout diagram
x ----g----> z
f | in2 |
y ---in1---> w
If f is a Monic, then in2 is a Monic, [AbelianPushoutMonic2]. If g is a Monic, then in1 is a Monic,
[AbelianPushoutMonic1]. In both of the cases the above diagram is a pullback diagram,
[AbelianPushoutMonicisPullback1], [AbelianPushoutMonicisPullback2].
Let f : x --> z and g : y --> z be morphisms in an abelian category. Consider the following pullback
diagram
w ---pr1---> x
pr2 | f |
y ----g----> z
If f is an Epi, then pr2 is an Epi, [AbelianPushoutEpi2], and if g is an Epi, then pr1 is an Epi,
[AbelianPushoutEpi1]. In both of the cases the above diagram is a pushout diagram,
[AbelianPullbackEpiisPushout1], [AbelianPullbackEpiisPushout2].
*)
Section pushout_monic_pullback_epi.
Context {A : AbelianPreCat}.
(* Let hs : has_homsets A := homset_property A. *)
Local Opaque Abelian.Equalizer.
Local Opaque Abelian.Coequalizer.
Local Opaque to_BinDirectSums.
Local Opaque to_binop to_inv.
(** ** Pushout of a Monic is Monic *)
Lemma AbelianPushoutMonic2 {x y z : A} (f : Monic A x y) (g : x --> z) (Po : Pushout f g) :
Monics.isMonic (PushoutIn2 Po).
Proof.
set (DS := to_BinDirectSums (AbelianToAdditive A) y z).
set (Po' := Pushout_from_Coequalizer_BinCoproduct
A _ _ _ f g (BinDirectSum_BinCoproduct _ DS)
(Abelian.Coequalizer
A
(f · (to_In1 DS))
(g · (to_In2 DS)))).
(* Transform the statement to a statement about other pushout *)
set (iso := z_iso_from_Pushout_to_Pushout Po Po').
apply (isMonic_postcomp
A _ (PushoutArrow Po Po' (PushoutIn1 Po') (PushoutIn2 Po')
(PushoutSqrCommutes Po'))).
rewrite (PushoutArrow_PushoutIn2
Po _ (PushoutIn1 Po') (PushoutIn2 Po')
(PushoutSqrCommutes Po')).
(* Prove that the arrow isMonic *)
set (CE := Coequalizer A (f · to_In1 (A:=AbelianToPreAdditive A) DS)
(g · to_In2 (A:=AbelianToPreAdditive A) DS)).
set (CK := AdditiveCoequalizerToCokernel (AbelianToAdditive A) _ _ CE).
set (M1 := @isMonic_to_binop_BinDirectSum1' (AbelianToAdditive A) x y z f g DS).
set (K := MonicToKernel' A (make_Monic _ _ M1) CK).
use (@to_isMonic (AbelianToAdditive A)).
intros z0 g0 H. cbn in H. rewrite assoc in H.
set (φ := KernelIn _ K z0 (g0 · to_In2 (A:=AbelianToPreAdditive A) DS) H).
set (KComm := KernelCommutes (to_Zero A) K z0 (g0 · to_In2 (A:=AbelianToPreAdditive A) DS) H).
fold φ in KComm.
(* The result follows from KComm and the fact that φ = ZeroArrow *)
assert (e1 : φ = ZeroArrow (to_Zero A) _ _).
{
use (MonicisMonic _ f).
rewrite ZeroArrow_comp_left. cbn in KComm.
assert (e2 : (MonicArrow _ f) =
(@to_binop (AbelianToAdditive A) _ _
(f · to_In1 (A:=AbelianToPreAdditive A) DS)
(@to_inv (AbelianToAdditive A) _ _
(g · to_In2 (A:=AbelianToPreAdditive A) DS)))
· to_Pr1 DS).
{
rewrite to_postmor_linear'. rewrite <- assoc.
rewrite PreAdditive_invlcomp. rewrite <- assoc.
set (tmp := to_IdIn1 DS). cbn in tmp. cbn. rewrite tmp. clear tmp.
set (tmp := to_Unel2' DS). cbn in tmp. rewrite tmp. clear tmp.
rewrite ZeroArrow_comp_right. rewrite id_right. apply pathsinv0.
set (tmp := @to_runax'' (AbelianToAdditive A) (to_Zero A) _ _ f). exact tmp.
}
rewrite e2. clear e2. rewrite assoc. cbn in KComm. cbn. rewrite KComm.
rewrite <- assoc. set (tmp := to_Unel2' DS). cbn in tmp. rewrite tmp. clear tmp.
apply ZeroArrow_comp_right.
}
use (to_In2_isMonic _ DS). cbn in KComm. use (pathscomp0 (! KComm)).
rewrite e1. rewrite ZeroArrow_comp_left. rewrite ZeroArrow_comp_left. apply idpath.
Qed.
Lemma AbelianPushoutMonic1 {x y z : A} (f : x --> y) (g : Monic A x z) (Po : Pushout f g) :
Monics.isMonic (PushoutIn1 Po).
Proof.
set (Po' := make_Pushout _ _ _ _ _ _ (is_symmetric_isPushout _ (isPushout_Pushout Po))).
use (AbelianPushoutMonic2 g f Po').
Qed.
(** ** Pushout of Monic is Pullback *)
Local Lemma AbelianPushoutMonicisPullback_eq {x y z : A} (f : Monic A x y) (g : x --> z)
{e : A} {h : A ⟦ e, y ⟧} {k : A ⟦ e, z ⟧}
(Hk : let DS := to_BinDirectSums (AbelianToAdditive A) y z in
let Po' := Pushout_from_Coequalizer_BinCoproduct
A _ _ _ f g (BinDirectSum_BinCoproduct _ DS)
(Abelian.Coequalizer A (f · (to_In1 DS)) (g · (to_In2 DS))) in
h · PushoutIn1 Po' = k · PushoutIn2 Po') :
let DS := to_BinDirectSums (AbelianToAdditive A) y z in
let Po' := Pushout_from_Coequalizer_BinCoproduct
A _ _ _ f g (BinDirectSum_BinCoproduct _ DS)
(Abelian.Coequalizer A (f · (to_In1 DS)) (g · (to_In2 DS))) in
h · CokernelArrow (Abelian.Cokernel f) = ZeroArrow (to_Zero A) e (Abelian.Cokernel f).
Proof.
intros DS Po'. cbn zeta in Hk. fold DS in Hk. fold Po' in Hk.
set (CK := Abelian.Cokernel f).
assert (e1 : f · CokernelArrow CK = g · ZeroArrow (to_Zero A) z CK).
{
rewrite CokernelCompZero. rewrite ZeroArrow_comp_right. apply idpath.
}
rewrite <- (PushoutArrow_PushoutIn1 Po' CK (CokernelArrow CK) (ZeroArrow (to_Zero A) _ _) e1).
rewrite assoc. rewrite Hk. clear Hk. rewrite <- assoc.
rewrite (PushoutArrow_PushoutIn2 Po' CK (CokernelArrow CK) (ZeroArrow (to_Zero A) _ _) e1).
apply ZeroArrow_comp_right.
Qed.
Lemma AbelianPushoutMonicisPullback1 {x y z : A} (f : Monic A x y) (g : x --> z)
(Po : Pushout f g) : isPullback (*(PushoutIn1 Po) (PushoutIn2 Po) f g*) (PushoutSqrCommutes Po).
Proof.
set (DS := to_BinDirectSums (AbelianToAdditive A) y z).
set (Po' := Pushout_from_Coequalizer_BinCoproduct
A _ _ _ f g (BinDirectSum_BinCoproduct _ DS)
(Abelian.Coequalizer
A
(f · (to_In1 DS))
(g · (to_In2 DS)))).
set (i := z_iso_from_Pushout_to_Pushout Po Po').
use isPullback_up_to_z_iso.
- exact Po'.
- exact i.
- use isPullback_mor_paths.
+ exact (PushoutIn1 Po').
+ exact (PushoutIn2 Po').
+ exact f.
+ exact g.
+ apply pathsinv0.
exact (PushoutArrow_PushoutIn1
Po Po' (PushoutIn1 Po') (PushoutIn2 Po') (PushoutSqrCommutes Po')).
+ apply pathsinv0.
exact (PushoutArrow_PushoutIn2
Po Po' (PushoutIn1 Po') (PushoutIn2 Po') (PushoutSqrCommutes Po')).
+ apply idpath.
+ apply idpath.
+ exact (PushoutSqrCommutes _ ).
+ set (K := MonicToKernel f).
set (CK := Abelian.Cokernel f). fold CK in K.
use make_isPullback.
intros e h k Hk.
use unique_exists.
* use (KernelIn (to_Zero A) K).
-- exact h.
-- exact (AbelianPushoutMonicisPullback_eq f g Hk).
* cbn. split.
-- use (KernelCommutes (to_Zero A) K).
-- assert (Hk' : h · PushoutIn1 Po' = k · PushoutIn2 Po') by apply Hk.
set (comm := KernelCommutes
(to_Zero A) K _ h (AbelianPushoutMonicisPullback_eq f g Hk)).
cbn in comm. rewrite <- comm in Hk'. clear comm.
apply (AbelianPushoutMonic2 f g Po'). rewrite <- Hk'.
cbn. rewrite <- assoc. rewrite <- assoc. apply cancel_precomposition.
rewrite assoc. rewrite assoc. apply pathsinv0.
use CoequalizerEqAr.
* intros y0. apply isapropdirprod; apply (homset_property A).
* intros y0 X. cbn in X.
use (KernelArrowisMonic (to_Zero A) K). rewrite KernelCommutes. exact (dirprod_pr1 X).
Qed.
Lemma AbelianPushoutMonicisPullback2 {x y z : A} (f : x --> y) (g : Monic A x z)
(Po : Pushout f g) : isPullback (*(PushoutIn1 Po) (PushoutIn2 Po) f g*) (PushoutSqrCommutes Po).
Proof.
set (Po' := make_Pushout _ _ _ _ _ _ (is_symmetric_isPushout _ (isPushout_Pushout Po))).
use is_symmetric_isPullback.
- exact (! (PushoutSqrCommutes _ )).
- exact (AbelianPushoutMonicisPullback1 g f Po').
Qed.
(** ** Pullback of an Epi is Epi *)
Lemma AbelianPullbackEpi2 {x y z : A} (f : Epi A x z) (g : y --> z) (Pb : Pullback f g) :
Epis.isEpi (PullbackPr2 Pb).
Proof.
set (DS := to_BinDirectSums (AbelianToAdditive A) x y).
set (Pb' := Pullback_from_Equalizer_BinProduct
A _ _ _ f g (BinDirectSum_BinProduct _ DS)
(Abelian.Equalizer
A
((to_Pr1 DS) · f)
((to_Pr2 DS) · g))).
(* Transform the statement to a statement about other pullback *)
set (iso := z_iso_from_Pullback_to_Pullback Pb Pb').
apply (isEpi_precomp
A (PullbackArrow Pb Pb' (PullbackPr1 Pb') (PullbackPr2 Pb')
(PullbackSqrCommutes Pb'))).
rewrite (PullbackArrow_PullbackPr2
Pb _ (PullbackPr1 Pb') (PullbackPr2 Pb')
(PullbackSqrCommutes Pb')).
(* Prove that the arrow isEpi *)
set (E := Equalizer A ((to_Pr1 DS) · f) ((to_Pr2 DS) · g)).
set (K := AdditiveEqualizerToKernel (AbelianToAdditive A) _ _ E).
set (E1 := @isEpi_to_binop_BinDirectSum1' (AbelianToAdditive A) x y z f g DS).
set (CK := EpiToCokernel' A (make_Epi _ _ E1) K).
use (@to_isEpi (AbelianToAdditive A)).
intros z0 g0 H. cbn in H. cbn. rewrite <- assoc in H.
set (φ := CokernelOut _ CK z0 (to_Pr2 DS · g0) H).
set (CKComm := CokernelCommutes (to_Zero A) CK z0 (to_Pr2 DS · g0) H).
fold φ in CKComm.
(* The result follows from CKComm and the fact that φ = ZeroArrow *)
assert (e1 : φ = ZeroArrow (to_Zero A) _ _).
{
use (EpiisEpi _ f).
rewrite ZeroArrow_comp_right. cbn in CKComm.
assert (e2 : (EpiArrow _ f) =
(to_In1 DS)
· (@to_binop (AbelianToAdditive A) _ _
(to_Pr1 DS · f)
(@to_inv (AbelianToAdditive A) _ _ (to_Pr2 DS · g)))).
{
rewrite to_premor_linear'. rewrite assoc.
rewrite PreAdditive_invrcomp. rewrite assoc.
set (tmp := to_IdIn1 DS). cbn in tmp. cbn. rewrite tmp. clear tmp.
set (tmp := to_Unel1' DS). cbn in tmp. rewrite tmp. clear tmp.
rewrite ZeroArrow_comp_left. rewrite id_left. apply pathsinv0.
set (tmp := @to_runax'' (AbelianToAdditive A) (to_Zero A) _ _ f). exact tmp.
}
rewrite e2. clear e2. rewrite <- assoc. cbn in CKComm. cbn. rewrite CKComm.
rewrite assoc. set (tmp := to_Unel1' DS). cbn in tmp. rewrite tmp. clear tmp.
apply ZeroArrow_comp_left.
}
use (to_Pr2_isEpi _ DS). cbn in CKComm. use (pathscomp0 (! CKComm)).
rewrite e1. rewrite ZeroArrow_comp_right. rewrite ZeroArrow_comp_right. apply idpath.
Qed.
Lemma AbelianPullbackEpi1 {x y z : A} (f : x --> z) (g : Epi A y z) (Pb : Pullback f g) :
Epis.isEpi (PullbackPr1 Pb).
Proof.
set (Pb' := make_Pullback _ (is_symmetric_isPullback _ (isPullback_Pullback Pb))).
use (AbelianPullbackEpi2 g f Pb').
Qed.
(** ** Pullback of Epi is Pushout *)
Local Lemma AbelianPullbackEpiisPushout1_eq {x y z : A} (f : Epi A x z) (g : y --> z)
{e : A} {h : A ⟦ x, e ⟧} {k : A ⟦ y, e ⟧}
(Hk : let DS := to_BinDirectSums (AbelianToAdditive A) x y in
let Pb' := Pullback_from_Equalizer_BinProduct
A _ _ _ f g (BinDirectSum_BinProduct _ DS)
(Abelian.Equalizer A ((to_Pr1 DS) · f) ((to_Pr2 DS) · g)) in
PullbackPr1 Pb' · h = PullbackPr2 Pb' · k) :
let DS := to_BinDirectSums (AbelianToAdditive A) x y in
let Pb' := Pullback_from_Equalizer_BinProduct
A _ _ _ f g (BinDirectSum_BinProduct _ DS)
(Abelian.Equalizer A ((to_Pr1 DS) · f) ((to_Pr2 DS) · g)) in
let K := Abelian.Kernel f in
KernelArrow K · h = ZeroArrow (to_Zero A) K e.
Proof.
intros DS Pb' K. cbn zeta in Hk. fold DS in Hk. fold Pb' in Hk.
assert (e1 : KernelArrow K · f = ZeroArrow (to_Zero A) _ _ · g).
{
rewrite KernelCompZero. rewrite ZeroArrow_comp_left. apply idpath.
}
rewrite <- (PullbackArrow_PullbackPr1 Pb' K (KernelArrow K) (ZeroArrow (to_Zero A) _ _) e1).
rewrite <- assoc. rewrite Hk. clear Hk. rewrite assoc.
rewrite (PullbackArrow_PullbackPr2 Pb' K (KernelArrow K) (ZeroArrow (to_Zero A) _ _) e1).
apply ZeroArrow_comp_left.
Qed.
Lemma AbelianPullbackEpiisPushout1 {x y z : A} (f : Epi A x z) (g : y --> z) (Pb : Pullback f g) :
isPushout (PullbackPr1 Pb) (PullbackPr2 Pb) f g (PullbackSqrCommutes Pb).
Proof.
set (DS := to_BinDirectSums (AbelianToAdditive A) x y).
set (Pb' := Pullback_from_Equalizer_BinProduct
A _ _ _ f g (BinDirectSum_BinProduct _ DS)
(Abelian.Equalizer A ((to_Pr1 DS) · f) ((to_Pr2 DS) · g))).
set (i := z_iso_from_Pullback_to_Pullback Pb' Pb).
use isPushout_up_to_z_iso.
- exact Pb'.
- exact i.
- use isPushout_mor_paths.
+ exact (PullbackPr1 Pb').
+ exact (PullbackPr2 Pb').
+ exact f.
+ exact g.
+ apply pathsinv0.
exact (PullbackArrow_PullbackPr1
Pb Pb' (PullbackPr1 Pb') (PullbackPr2 Pb') (PullbackSqrCommutes Pb')).
+ apply pathsinv0.
exact (PullbackArrow_PullbackPr2
Pb Pb' (PullbackPr1 Pb') (PullbackPr2 Pb') (PullbackSqrCommutes Pb')).
+ apply idpath.
+ apply idpath.
+ exact (PullbackSqrCommutes _ ).
+ set (CK := EpiToCokernel f).
set (K := Abelian.Kernel f). fold K in CK.
use make_isPushout.
intros e h k Hk.
use unique_exists.
* use (CokernelOut (to_Zero A) CK).
-- exact h.
-- exact (AbelianPullbackEpiisPushout1_eq f g Hk).
* cbn. split.
-- use (CokernelCommutes (to_Zero A) CK).
-- assert (Hk' : PullbackPr1 Pb' · h = PullbackPr2 Pb' · k) by apply Hk.
set (comm := CokernelCommutes
(to_Zero A) CK _ h (AbelianPullbackEpiisPushout1_eq f g Hk)).
cbn in comm. rewrite <- comm in Hk'. clear comm.
apply (AbelianPullbackEpi2 f g Pb'). rewrite <- Hk'.
cbn. rewrite assoc. rewrite assoc. apply cancel_postcomposition.
rewrite <- assoc. rewrite <- assoc. apply pathsinv0.
use EqualizerEqAr.
* intros y0. apply isapropdirprod; apply (homset_property A).
* intros y0 X. cbn in X.
use (CokernelArrowisEpi (to_Zero A) CK). rewrite CokernelCommutes. exact (dirprod_pr1 X).
Qed.
Lemma AbelianPullbackEpiisPushout2 {x y z : A} (f : x --> z) (g : Epi A y z) (Pb : Pullback f g) :
isPushout (PullbackPr1 Pb) (PullbackPr2 Pb) f g (PullbackSqrCommutes Pb).
Proof.
set (Pb' := make_Pullback _ (is_symmetric_isPullback _ (isPullback_Pullback Pb))).
use is_symmetric_isPushout.
- exact (! (PullbackSqrCommutes _ )).
- exact (AbelianPullbackEpiisPushout1 g f Pb').
Qed.
End pushout_monic_pullback_epi.
|
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.Reflection
pattern vArg x = arg (arg-info visible (modality relevant quantity-ω)) x
macro
macaroo : Term → TC ⊤
macaroo hole = unify hole (con (quote suc) (vArg unknown ∷ []))
test : Nat
test = macaroo
|
-- Untyped lambda calculus implemntation in Idris
data Term
= Var Nat -- A variable is represented by its de-bruijn index
| Abs Term -- An abstraction introduces a new function
| App Term Term -- One term applied to another
-- Variables are either free or bound
data VarType
= Free
| Bound
-- Turns the type into a function that can be used to determine
-- whether a variable with brujin index 'i' within 'n' abstractions
-- is Free/Bound. ('i' -> 'n' -> Bool)
varPred : VarType -> Nat -> Nat -> Bool
varPred Free = (>)
varPred Bound = (==)
-- Iterates through the AST of a Term, applying 'f' on
-- variables of type 'ty'.
termMap : VarType -> (Nat -> Nat -> Term) -> Term -> Term
termMap ty f = go 0 where
-- 'n' represents the number of abstractions the current term is
go : Nat -> Term -> Term
go n (Var i) with (varPred ty i n)
| True = f n i -- If the variable matches the desired type, apply f
| False = Var i -- Else leave it unchanged
go n (Abs body) = Abs $ go (succ n) body -- Recurse, incrementing n as we will be under another abstraction
go n (App t1 t2) = App (go n t1) (go n t2) -- Function application does not introduce an abstraction, so leave n unchanged
-- Apply a function to all of the indices of free variables
mapFreeIndices : (Nat -> Nat) -> Term -> Term
mapFreeIndices f t = termMap Free (const $ Var . f) t
-- Substitute 't1' into 't2' at the top level (replacing variables with index 0)
substitute : Term -> Term -> Term
substitute t1 t2 = termMap Bound (\n => const $ mapFreeIndices (+n) t1) t2
-- Perform a beta reduction (aka function application). First decrement all
-- free variable indices in the body, since function application removes the
-- top level abstraction. Then substitute the function argument into the body.
betaReduce : Term -> Term -> Term
betaReduce body arg = substitute arg $ mapFreeIndices Nat.pred body
-- Perform one reductive step. If no step could be applied, return Nothing
simplify : Term -> Maybe Term
simplify (App (Abs body) arg@(Abs _)) = Just $ betaReduce body arg -- Use function application if possible
simplify (App f@(Abs _) arg) = App f <$> simplify arg -- Simplify the argument, so function application can be used next
simplify (App f arg) = flip App arg <$> simplify f -- Simplify the function, so function application can be used next
simplify t = Nothing -- No simplification rules apply, so return Nothing
-- Evaluate a term down to it's normal form. This uses strict evaluation.
-- Note that this may not terminate: this a "feature" of untyped lc.
-- Here we keep simplifying until no more simplifying steps are available.
eval : Term -> Term
eval t = maybe t eval $ simplify t
|
import data.rat.basic tactic
-- prove one and delete the other
theorem some_reciprocal_is_zero : ∃ x : ℚ, 1 / x = 0 :=
begin
use 0,
refl -- cf. nat.inv
end
-- theorem no_reciprocal_is_zero : ¬ (∃ x : ℚ, 1 / x = 0) :=
-- begin
-- sorry
-- end
|
\documentclass{article}% standalone can be used after commenting /section lines
\usepackage[formats]{listings}
\lstdefineformat{C}
{
\{=\newline\string\newline\indent,%
\}=\newline\noindent\string\newline,%
;=[\ ]\string\space,%
}
\lstset{basicstyle=\ttfamily}
\usepackage{filecontents}
\begin{filecontents*}{sample.c}
#include<stdio.h>
void main()
{
printf("\n Hello World");
}
\end{filecontents*}
\begin{document}
\section*{``Raw'' listing}
\lstinputlisting{sample.c}
\section*{With automatic formatting}
\lstinputlisting[format=C]{sample.c}
\end{document}
|
Formal statement is: lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z" Informal statement is: The complex conjugate of the complex conjugate of $z$ is $z$. |
import data.nat
open nat
theorem mul_mod_eq_mod_mul_mod (m n k : nat) : (m * n) mod k = ((m mod k) * n) mod k :=
by_cases_zero_pos k
(by rewrite [*mod_zero])
(take k, assume H : k > 0,
(calc
(m * n) mod k = (((m div k) * k + m mod k) * n) mod k : eq_div_mul_add_mod
... = ((m mod k) * n) mod k :
by rewrite [mul.right_distrib, mul.right_comm, add.comm, add_mul_mod_self H]))
theorem eq_zero_or_eq_one_of_lt_two : ∀ {n : nat}, n < 2 → n = 0 ∨ n = 1 := dec_trivial
definition even (n : nat) : Prop := n mod 2 = 0
definition odd (n : nat) : Prop := n mod 2 = 1
theorem even_or_odd (n : nat) : even n ∨ odd n := eq_zero_or_eq_one_of_lt_two (mod_lt dec_trivial)
theorem even_of_exists_eq_two_mul {n : nat} (H : ∃ m, n = 2 * m) : even n :=
obtain m (H1 : n = 2 * m), from H,
calc
n mod 2 = 2*m mod 2 : H1
... = 0 : mul_mod_right
theorem exists_eq_two_mul_of_even {n : nat} (H : even n) : ∃ m, n = 2 * m :=
exists.intro (n div 2)
(calc
n = (n div 2) * 2 + n mod 2 : eq_div_mul_add_mod
... = 2*(n div 2) : by rewrite [↑even at H, H, add_zero, mul.comm])
theorem even_of_even_square {n : nat} (H : even (n * n)) : even n :=
or.elim (even_or_odd n) (assume H, H)
(assume H1 : n mod 2 = 1,
have H2 : 0 = 1, from calc
0 = n * n mod 2 : H
... = ((n mod 2) * n) mod 2 : mul_mod_eq_mod_mul_mod
... = 1 : by rewrite [H1, one_mul, H1],
absurd H2 dec_trivial)
theorem sqrt2_irrational (m : nat) : ∀ n : nat, n * n = 2 * m * m → m = 0 :=
nat.strong_induction_on m
(take m,
by_cases_zero_pos m (λ IH n H, rfl)
(take m,
assume (mpos : m > 0),
assume IH : ∀ {m'}, m' < m → (∀ {n}, n * n = 2 * m' * m' → m' = 0),
take n,
assume H : n * n = 2 * m * m,
have H1 : even (n * n),
from even_of_exists_eq_two_mul (exists.intro _ (eq.subst !mul.assoc H)),
have H2 : even n, from even_of_even_square H1,
obtain k (H3 : n = 2 * k), from exists_eq_two_mul_of_even H2,
have H4 : 2 * (m * m) = 2 * (2 * k * k),
by rewrite [-mul.assoc, -H, H3, *mul.assoc, mul.left_comm k],
assert H5 : m * m = 2 * k * k, from !eq_of_mul_eq_mul_left dec_trivial H4,
have H6 : k < m, from
lt_of_not_le
(assume H' : k ≥ m,
have H1' : k > 0, from lt_of_lt_of_le mpos H',
have H2' : k * k ≥ m * m, from mul_le_mul H' H',
assert H3' : 2 * (k * k) > 1 * (m * m),
from mul_lt_mul_of_lt_of_le (mul_pos H1' H1') dec_trivial H2',
have H4' : 2 * k * k > 2 * k * k,
by revert H3'; rewrite [H5, one_mul, mul.assoc]; intros; assumption,
absurd H4' !lt.irrefl),
assert H7 : k = 0, from IH H6 H5,
have H8 : m * m = 0, by rewrite [H5, H7, mul_zero],
show m = 0, from iff.mp !or_self (eq_zero_or_eq_zero_of_mul_eq_zero H8))) |
namespace graveyard
lemma closure_squeeze_term(X Y : set ℝ) (h₁ : X ⊆ Y) (h₂ : Y ⊆ closure(X))
: closure(X) = closure(Y) :=
-- Can either use set.eq_of_subset_of_subset or set.ext. The difference
-- being whether we are showing that two sets are subsets of each other or
-- whether we are showing that an object is an element of set X iff it is an
-- element of Y. Both are equivalent, but we need to choose which to use.
set.eq_of_subset_of_subset
(assume x, assume h₃ : x ∈ closure(X),
show x ∈ closure(Y), from
begin
intro ε,
intro h₄,
have h₅ : ∃ x' ∈ X, |x - x'| ≤ ε, from h₃ ε h₄,
show ∃ y ∈ Y, |x - y| ≤ ε, from exists.elim h₅ (
assume (x' : ℝ) (h: (∃hh₁ : (x' ∈ X), |x - x'| ≤ ε)),
exists.elim h (
assume (hhh₁ : x' ∈ X) (hhh₂ : |x - x'| ≤ ε),
have hhh₃ : x' ∈ Y, from h₁ hhh₁,
show ∃y ∈ Y, |x - y| ≤ ε, from
exists.intro x' (exists.intro hhh₃ hhh₂))),
end)
(assume y, assume h₃ : y ∈ closure(Y),
show y ∈ closure(X), from
assume ε,
assume h₄,
have h₅ : ∃δ : ℝ, δ = ε/3, from exists_eq,
have h₆ : ∃x ∈ X, |y - x| ≤ ε, from exists.elim h₅
(assume (δ : ℝ) (hh₁ : δ = ε/3),
have hh₃ : δ > 0, by linarith,
have hh₂ : ∃ y' ∈ Y, |y - y'| ≤ δ, from h₃ δ hh₃,
exists.elim hh₂
(assume (y' : ℝ) (hh₄ : ∃ hhh₁ : y' ∈ Y, | y - y'| ≤ δ),
exists.elim hh₄
(assume (h4₁ : y' ∈ Y) (h4₂ : |y - y'| ≤ δ),
have h4₃ : y' ∈ closure(X), from h₂ h4₁,
have h4₄ : ∃x ∈ X, |y' - x| ≤ δ, from h4₃ δ hh₃,
exists.elim h4₄
(assume (x : ℝ) (h4₅ : ∃ h5₁ : x ∈ X, |y' - x| ≤ δ),
exists.elim h4₅
(assume (h5₁ : x ∈ X) (h5₂ : |y' - x| ≤ δ),
--norm_add_le_of_le (by apply_instance) h4₂ h5₂
have h5₇ : |y - x| ≤ 2*δ, from sorry,
have h5₈ : |y - x| ≤ ε, by linarith,
have h5₉ : ∃x' ∈ X, |y - x'| ≤ ε, from
exists.intro x (exists.intro h5₁ h5₈),
h5₉))))),
h₆)
end graveyard |
import algebra.order.archimedean
import data.real.basic
import algebra.big_operators.basic
import analysis.specific_limits.basic
/-
Bulgarian Mathematical Olympiad 1998, Problem 3
Let ℝ⁺ be the set of positive real numbers. Prove that there does not exist a function
f: ℝ⁺ → ℝ⁺ such that
(f(x))² ≥ f(x + y) * (f(x) + y)
for every x,y ∈ ℝ⁺.
-/
open_locale big_operators
lemma geom_sum_bound (n:ℕ) : ∑(i : ℕ) in finset.range n, (1:ℝ) / (2^i) < 3 :=
calc ∑(i : ℕ) in finset.range n, (1:ℝ) / 2^i
= ∑(i : ℕ) in finset.range n, (1 / 2)^i : by {congr; simp [div_eq_mul_inv]}
... ≤ 2 : sum_geometric_two_le n
... < 3 : by norm_num
theorem bulgaria1998_q3
(f : ℝ → ℝ)
(hpos : ∀ x : ℝ, 0 < x → 0 < f x)
(hf : (∀ x y : ℝ, 0 < x → 0 < y → (f (x + y)) * (f x + y) ≤ (f x)^2)) :
false :=
begin
have f_decr : ∀ x y : ℝ, 0 < x → 0 < y → f (x + y) < f x,
{
intros x y hx hy,
have h1 := hf x y hx hy,
have h2 : 0 < f x + y := add_pos (hpos x hx) hy,
have h4 : f x < f x + y := lt_add_of_pos_right (f x) hy,
have h5 : f x / (f x + y) < 1 := by rwa [div_lt_iff h2, one_mul],
calc f (x + y) = f (x + y) * 1 : (mul_one (f (x + y))).symm
... = f (x + y) * ((f x + y) / (f x + y)) : by rw (div_self (ne.symm (ne_of_lt h2)))
... = (f (x + y) * (f x + y)) / (f x + y) : mul_div_assoc' _ _ _
... ≤ (f x)^2 / (f x + y) : (div_le_div_right h2).mpr h1
... = (f x) * (f x / (f x + y)) : by field_simp [pow_two]
... < f x : (mul_lt_iff_lt_one_right (hpos x hx)).mpr h5,
},
have f_half : ∀ x : ℝ, 0 < x → f (x + f x) ≤ f x / 2,
{
intros x hx,
have h0 := hpos x hx,
have h1 := hf x (f x) hx h0,
have h2 : 0 < f x + f x := add_pos h0 h0,
have h3 : 0 ≠ f x + f x := ne_of_lt h2,
have h5 := ne_of_lt h0,
have h6: 2 * f x ≠ 0 := by positivity,
have h7 : (f x/ (2 * f x)) = 1 / 2 := by { rw [div_eq_iff h6], ring },
calc f (x + f x) = f (x + f x) * 1 : (mul_one _).symm
... = f (x + f x) * ((f x + f x) / (f x + f x)) : by rw (div_self (ne.symm h3))
... = (f (x + f x) * (f x + f x)) / (f x + f x) : mul_div_assoc' _ _ _
... ≤ (f x)^2 / (f x + f x) : (div_le_div_right h2).mpr h1
... = (f x) * (f x / (f x + f x)) : by field_simp [pow_two]
... = (f x) * (f x/ (2 * f x)) : by rw [two_mul]
... = (f x) * (1 /2 ) : by rw [h7]
... = f x / 2 : by field_simp,
},
let x_seq : ℕ → ℝ := λ n : ℕ, 1 + ∑(i : ℕ) in finset.range n, (f 1) / (2^i),
have hz : x_seq 0 = 1 := by simp only [add_right_eq_self, finset.sum_empty, finset.range_zero],
have hf1 := hpos 1 zero_lt_one,
have x_seq_pos : ∀ n: ℕ, 0 < x_seq n,
{ intro n,
simp only [x_seq],
have sum_nonneg : 0 ≤ ∑ (i : ℕ) in finset.range n, f 1 / 2 ^ i,
{ apply finset.sum_nonneg,
intros i hi,
have h2 : (0:ℝ) < 2 ^ i := pow_pos (by norm_num) i,
exact le_of_lt (div_pos_iff.mpr (or.inl ⟨hf1, h2⟩)),
},
linarith
},
have f_x_seq: ∀ n:ℕ, f(x_seq n) ≤ f 1 / 2^n,
{ intro n,
induction n with pn hpn,
{ rw hz, simp only [div_one, pow_zero] },
have hpp: x_seq pn.succ = x_seq pn + f 1 / 2^pn,
{
simp only [x_seq],
have : ∑ (i : ℕ) in finset.range pn.succ, f 1 / 2 ^ i =
f 1 / 2 ^ pn + ∑ (i : ℕ) in finset.range pn, f 1 / 2 ^ i,
{ exact finset.sum_range_succ_comm (λ (x : ℕ), f 1 / 2 ^ x) pn },
rw this,
ring
},
have h1 : f (x_seq pn.succ) ≤ f (x_seq pn + f(x_seq pn)),
{
rw hpp,
obtain heq | hlt := eq_or_lt_of_le hpn,
{ rwa heq },
{ have := le_of_lt (f_decr (x_seq pn + f (x_seq pn)) (f 1 / 2 ^ pn - f (x_seq pn))
(add_pos (x_seq_pos pn) (hpos (x_seq pn) (x_seq_pos pn)))
(sub_pos.mpr hlt)),
rw[add_add_sub_cancel] at this,
exact this } },
calc f (x_seq pn.succ) ≤ f (x_seq pn + f(x_seq pn)) : h1
... ≤ f (x_seq pn) / 2 : f_half (x_seq pn) (x_seq_pos pn)
... ≤ (f 1 / 2 ^ pn) / 2 : by linarith
... = f 1 / 2 ^ pn.succ : by {field_simp[ne_of_gt hf1], ring_nf}
},
have h1: ∀ n: ℕ, x_seq n < 1 + 3 * f 1,
{ intro n,
norm_num,
calc ∑ (i : ℕ) in finset.range n, f 1 / 2 ^ i
= (∑ (i : ℕ) in finset.range n, 1 / 2 ^ i) * f 1 : by {rw [finset.sum_mul], field_simp }
... < 3 * f 1 : (mul_lt_mul_right hf1).mpr (geom_sum_bound n)
},
have h2 : ∀ n : ℕ, 0 < 1 + 3 * f 1 - x_seq n,
{ intro n, linarith [h1 n]},
have h3 : ∀ n:ℕ, f (1 + 3 * f 1) < f 1 / 2 ^ n,
{ intro n,
calc f (1 + 3 * f 1) = f (x_seq n + (1 + 3 * f 1 - x_seq n)) : by ring_nf
... < f (x_seq n) : f_decr (x_seq n) _ (x_seq_pos n) (h2 n)
... ≤ f 1 / 2^n : f_x_seq n,
},
have he : ∃n : ℕ, f 1 / 2^n < f (1 + 3 * f 1),
{ obtain ⟨N, hN⟩ := pow_unbounded_of_one_lt (f 1 / f (1 + 3 * f 1)) one_lt_two,
use N,
have hp : 0 < f (1 + 3 * f 1) :=
hpos (1 + 3 * f 1) (lt_trans (x_seq_pos 0) (h1 0)),
have h2N : (0:ℝ) < 2^N := pow_pos (by norm_num) N,
exact (div_lt_iff h2N).mpr ((div_lt_iff' hp).mp hN) },
obtain ⟨N, hN⟩ := he,
exact lt_irrefl _ (lt_trans (h3 N) hN),
end
|
/-
Copyright (c) 2021 OpenAI. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kunhao Zheng, Stanislas Polu, David Renshaw, OpenAI GPT-f
-/
import mathzoo.imports.miniF2F
open_locale nat rat real big_operators topological_space
theorem mathd_algebra_104
(x : ℝ)
(h₀ : 125 / 8 = x / 12) :
x = 375 / 2 :=
begin
linarith,
end |
using Test
# @time @testset "Debug" begin include("test_debug.jl") end
@time @testset "Miscellaneous" begin include("test_miscellaneous.jl") end
@time @testset "Acoustics" begin include("test_acoustics.jl") end
@time @testset "Heat diffusion" begin include("test_heat.jl") end
@time @testset "Linear deformation" begin include("test_linear_deformation.jl") end
@time @testset "Meshing" begin include("test_meshing.jl") end
@time @testset "Voxel box" begin include("test_voxel_box.jl") end
# @time @testset "Failing tests" begin include("test_failing.jl") end
true
|
lemma closed_empty [continuous_intros, intro, simp]: "closed {}" |
lemma (in finite_measure) finite_measure_mono: assumes "A \<subseteq> B" "B \<in> sets M" shows "measure M A \<le> measure M B" |
Like Percy Bysshe Shelley ’ s " To a Skylark " , Keats ’ s narrator listens to a bird song , but listening to the song within “ Ode to a Nightingale ” is almost painful and similar to death . The narrator seeks to be with the nightingale and abandons his sense of vision in order to embrace the sound in an attempt to share in the darkness with the bird . As the poem ends , the trance caused by the nightingale is broken and the narrator is left wondering if it was a real vision or just a dream . The poem reliance on the process of sleeping common to Keats 's poems , and " Ode to a Nightingale " shares many of the same themes as Keats 's Sleep and Poetry and Eve of St. Agnes . This further separates the image of the nightingale 's song from its closest comparative image , the urn as represented in " Ode on a Grecian Urn " . The nightingale is distant and mysterious , and even disappears at the end of the poem . The dream image emphasizes the <unk> and elusiveness of the poem . These elements make it impossible for there to be a complete self @-@ identification with the nightingale , but it also allows for self @-@ awareness to permeate throughout the poem , albeit in an altered state .
|
module Idris2Rust.Main
import Core.Context
import Compiler.Common
import Idris.Driver
import System
import System.Directory
import System.File
import System.Info
import Libraries.Data.NameMap
import Libraries.Data.Version
import Idris2Rust.CompileCfg
-- %default covering
compile : Profile
-> Ref Ctxt Defs
-> (tmpDir : String)
-> (outputDir : String)
-> ClosedTerm
-> (outfile : String)
-> Core (Maybe String)
compile profile defs tmpDir outputDir term file
= do coreLift $ putStrLn "I'd rather not."
pure $ Nothing
execute : Profile -> Ref Ctxt Defs -> (tmpDir : String) -> ClosedTerm -> Core ()
execute profile defs tmpDir term = do coreLift $ putStrLn "Maybe in an hour."
export
rustCodegen : Profile -> Codegen
rustCodegen profile = MkCG (compile profile) (execute profile) Nothing Nothing
main : IO ()
main = mainWithCodegens [
("rust-debug", rustCodegen Debug),
("rust-release", rustCodegen Release)
]
|
-----------------------------------------------------------------------------
-- |
-- Module : Data.Random.Distribution.Static.MultivariateNormal
-- Copyright : (c) 2016 FP Complete Corporation
-- License : MIT (see LICENSE)
-- Maintainer : [email protected]
--
-- Sample from the multivariate normal distribution with a given
-- vector-valued \(\mu\) and covariance matrix \(\Sigma\). For
-- example, the chart below shows samples from the bivariate normal
-- distribution. The dimension of the mean \(n\) is statically checked
-- to be compatible with the dimension of the covariance matrix \(n \times n\).
--
-- <<diagrams/src_Data_Random_Distribution_Static_MultivariateNormal_diagMS.svg#diagram=diagMS&height=600&width=500>>
--
-- Example code to generate the chart:
--
-- > {-# LANGUAGE DataKinds #-}
-- >
-- > import qualified Graphics.Rendering.Chart as C
-- > import Graphics.Rendering.Chart.Backend.Diagrams
-- >
-- > import Data.Random.Distribution.Static.MultivariateNormal
-- >
-- > import qualified Data.Random as R
-- > import Data.Random.Source.PureMT
-- > import Control.Monad.State
-- > import Numeric.LinearAlgebra.Static
-- >
-- > nSamples :: Int
-- > nSamples = 10000
-- >
-- > sigma1, sigma2, rho :: Double
-- > sigma1 = 3.0
-- > sigma2 = 1.0
-- > rho = 0.5
-- >
-- > singleSample :: R.RVarT (State PureMT) (R 2)
-- > singleSample = R.sample $ Normal (vector [0.0, 0.0])
-- > (sym $ matrix [ sigma1, rho * sigma1 * sigma2
-- > , rho * sigma1 * sigma2, sigma2])
-- >
-- > multiSamples :: [R 2]
-- > multiSamples = evalState (replicateM nSamples $ R.sample singleSample) (pureMT 3)
-- >
-- > pts = map f multiSamples
-- > where
-- > f z = (x, y)
-- > where
-- > (x, t) = headTail z
-- > (y, _) = headTail t
-- >
-- > chartPoint pointVals n = C.toRenderable layout
-- > where
-- >
-- > fitted = C.plot_points_values .~ pointVals
-- > $ C.plot_points_style . C.point_color .~ opaque red
-- > $ C.plot_points_title .~ "Sample"
-- > $ def
-- >
-- > layout = C.layout_title .~ "Sampling Bivariate Normal (" ++ (show n) ++ " samples)"
-- > $ C.layout_y_axis . C.laxis_generate .~ C.scaledAxis def (-3,3)
-- > $ C.layout_x_axis . C.laxis_generate .~ C.scaledAxis def (-3,3)
-- >
-- > $ C.layout_plots .~ [C.toPlot fitted]
-- > $ def
-- >
-- > diagMS = do
-- > denv <- defaultEnv C.vectorAlignmentFns 600 500
-- > return $ fst $ runBackend denv (C.render (chartPoint pts nSamples) (500, 500))
--
-----------------------------------------------------------------------------
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
module Data.Random.Distribution.Static.MultivariateNormal
( Normal(..)
) where
import Data.Random hiding ( StdNormal, Normal )
import qualified Data.Random as R
import Control.Monad.State ( replicateM )
import qualified Numeric.LinearAlgebra.HMatrix as H
import Numeric.LinearAlgebra.Static as S
( R, vector, extract, Sq, Sym, col,
tr, linSolve, uncol, chol, (<.>),
ℝ, (<>), diag, (#>), eigensystem
)
import GHC.TypeLits ( KnownNat, natVal )
import Data.Maybe ( fromJust )
normalMultivariate :: KnownNat n =>
R n -> Sym n -> RVarT m (R n)
normalMultivariate mu bigSigma = do
z <- replicateM (fromIntegral $ natVal mu) (rvarT R.StdNormal)
return $ mu + bigA #> (vector z)
where
(vals, bigU) = eigensystem bigSigma
lSqrt = diag $ mapVector sqrt vals
bigA = bigU S.<> lSqrt
mapVector :: KnownNat n => (ℝ -> ℝ) -> R n -> R n
mapVector f = vector . H.toList . H.cmap f . extract
sumVector :: KnownNat n => R n -> ℝ
sumVector x = x <.> 1
data family Normal k :: *
data instance Normal (R n) = Normal (R n) (Sym n)
instance KnownNat n => Distribution Normal (R n) where
rvar (Normal m s) = normalMultivariate m s
normalLogPdf :: KnownNat n =>
R n -> Sym n -> R n -> Double
normalLogPdf mu bigSigma x = - sumVector (mapVector log (diagonals dec))
- 0.5 * (fromIntegral $ natVal mu) * log (2 * pi)
- 0.5 * s
where
dec = chol bigSigma
t = uncol $ fromJust $ linSolve (tr dec) (col $ x - mu)
u = mapVector (\x -> x * x) t
s = sumVector u
normalPdf :: KnownNat n =>
R n -> Sym n -> R n -> Double
normalPdf mu sigma x = exp $ normalLogPdf mu sigma x
diagonals :: KnownNat n => Sq n -> R n
diagonals = vector . H.toList . H.takeDiag . extract
instance KnownNat n => PDF Normal (R n) where
pdf (Normal m s) = normalPdf m s
logPdf (Normal m s) = normalLogPdf m s
|
(*
* Copyright 2014, General Dynamics C4 Systems
*
* This software may be distributed and modified according to the terms of
* the GNU General Public License version 2. Note that NO WARRANTY is provided.
* See "LICENSE_GPLv2.txt" for details.
*
* @TAG(GD_GPL)
*)
theory SubMonad_AI
imports KHeap_AI
begin
(* SubMonadLib *)
lemma submonad_do_machine_op:
"submonad machine_state (machine_state_update \<circ> K) \<top> do_machine_op"
apply unfold_locales
apply (clarsimp simp: ext stateAssert_def do_machine_op_def o_def gets_def
get_def bind_def return_def submonad_fn_def)+
done
interpretation submonad_do_machine_op:
submonad machine_state "(machine_state_update \<circ> K)" \<top> do_machine_op
by (rule submonad_do_machine_op)
lemma submonad_args_pspace:
"submonad_args kheap (kheap_update o (\<lambda>x _. x)) \<top>"
by (simp add: submonad_args_def)
schematic_goal assert_get_tcb_pspace:
"gets_the (get_tcb t) = submonad_fn kheap (kheap_update o (\<lambda>x _. x)) \<top> ?f"
apply (unfold gets_the_def)
apply (rule submonad_bind_alt [OF submonad_args_pspace])
apply (rule gets_submonad [OF submonad_args_pspace _ refl])
apply (simp add: get_tcb_def)
apply (rule assert_opt_submonad [OF submonad_args_pspace])
apply simp
apply (rule empty_fail_assert_opt)
done
lemma assert_get_thread_do_machine_op_comm:
"empty_fail m' \<Longrightarrow>
do x \<leftarrow> gets_the (get_tcb t); y \<leftarrow> do_machine_op m'; n x y od =
do y \<leftarrow> do_machine_op m'; x \<leftarrow> gets_the (get_tcb t); n x y od"
apply (rule submonad_comm2 [OF _ _ submonad_do_machine_op])
apply (rule submonad_args_pspace)
apply (rule assert_get_tcb_pspace)
apply simp+
done
end
|
#
# Example R program
#
library("Rnlminb2")
# Feasible Start Solution:
start = c(10, 10)
# Objective Function: x^2 + y^2
fun <- function(x) sum(x^2)
# Bounds: -100 <= x,y <= 100
par.lower = c(-100, -100)
par.upper = c(100, 100)
# Equality Constraints: x*y = 2
eqFun <- list(
function(x) x[1]*x[2])
eqFun.bound = 2
# Solution: x = c(sqrt(2), sqrt(2)), f(x) = 4
result <- nlminb2NLP(
par = start,
fun = fun,
par.lower = par.lower,
par.upper = par.upper,
eqFun = eqFun,
eqFun.bound = eqFun.bound
)
print(result)
|
record R (a : Type) where
constructor MkR
x : a
rmap : (a -> b) -> R a -> R b
rmap f = { x $= f }
|
#!/usr/bin/env python3
import numpy as np
import tensorflow as tf
import timit_mfcc26_dataset
class Network:
def __init__(self, threads, seed=42):
# Create an empty graph and a session
graph = tf.Graph()
graph.seed = seed
self.session = tf.Session(graph = graph, config=tf.ConfigProto(inter_op_parallelism_threads=threads,
intra_op_parallelism_threads=threads))
def construct(self, args, num_phones, mfcc_dim):
with self.session.graph.as_default():
# Inputs
self.mfcc_lens = tf.placeholder(tf.int32, [None])
self.mfccs = tf.placeholder(tf.float32, [None, None, mfcc_dim])
self.phone_lens = tf.placeholder(tf.int32, [None])
self.phones = tf.placeholder(tf.int32, [None, None])
# Computation and training. The rest of the template assumes
# the following variables:
# - `losses`: vector of losses, with an element for each example in the batch
# - `edit_distances`: vector of edit distances, with an element for each batch example
targets = tf.contrib.layers.dense_to_sparse(self.phones)
num_hidden = 64
(output_fwd, output_bwd), _ = tf.nn.bidirectional_dynamic_rnn(
tf.nn.rnn_cell.LSTMCell(num_hidden),
tf.nn.rnn_cell.LSTMCell(num_hidden),
self.mfccs,
sequence_length=self.mfcc_lens,
dtype=tf.float32)
logits = tf.layers.dense(output_fwd + output_bwd, num_phones)
losses = tf.reduce_mean(tf.nn.ctc_loss(targets, logits, self.mfcc_lens, time_major=False))
# Evaluating
decoded, log_prob = tf.nn.ctc_greedy_decoder(tf.transpose(logits, perm=[1, 0, 2]), self.mfcc_lens)
edit_distances = tf.edit_distance(tf.cast(decoded[0], tf.int32), targets)
# Training
global_step = tf.train.create_global_step()
self.training = tf.train.AdamOptimizer().minimize(tf.reduce_mean(losses), global_step=global_step, name="training")
# Summaries
self.current_edit_distance, self.update_edit_distance = tf.metrics.mean(edit_distances)
self.current_loss, self.update_loss = tf.metrics.mean(losses)
self.reset_metrics = tf.variables_initializer(tf.get_collection(tf.GraphKeys.METRIC_VARIABLES))
summary_writer = tf.contrib.summary.create_file_writer(args.logdir, flush_millis=10 * 1000)
self.summaries = {}
with summary_writer.as_default(), tf.contrib.summary.record_summaries_every_n_global_steps(10):
self.summaries["train"] = [tf.contrib.summary.scalar("train/loss", self.update_loss),
tf.contrib.summary.scalar("train/edit_distance", self.update_edit_distance)]
with summary_writer.as_default(), tf.contrib.summary.always_record_summaries():
for dataset in ["dev", "test"]:
self.summaries[dataset] = [tf.contrib.summary.scalar(dataset + "/loss", self.current_loss),
tf.contrib.summary.scalar(dataset + "/edit_distance", self.current_edit_distance)]
# Initialize variables
self.session.run(tf.global_variables_initializer())
with summary_writer.as_default():
tf.contrib.summary.initialize(session=self.session, graph=self.session.graph)
def train_epoch(self, train, batch_size):
while not train.epoch_finished():
mfcc_lens, mfccs, phone_lens, phones = train.next_batch(batch_size)
self.session.run(self.reset_metrics)
self.session.run([self.training, self.summaries["train"]],
{self.mfcc_lens: mfcc_lens, self.mfccs: mfccs,
self.phone_lens: phone_lens, self.phones: phones})
def evaluate(self, dataset_name, dataset, batch_size):
self.session.run(self.reset_metrics)
while not dataset.epoch_finished():
mfcc_lens, mfccs, phone_lens, phones = dataset.next_batch(batch_size)
self.session.run([self.update_edit_distance, self.update_loss],
{self.mfcc_lens: mfcc_lens, self.mfccs: mfccs,
self.phone_lens: phone_lens, self.phones: phones})
return self.session.run([self.current_edit_distance, self.summaries[dataset_name]])[0]
def predict(self, dataset, batch_size):
# TODO: Predict phoneme sequences for the given dataset.
pass
if __name__ == "__main__":
import argparse
import datetime
import os
import re
# Fix random seed
np.random.seed(42)
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("--batch_size", default=64, type=int, help="Batch size.")
parser.add_argument("--epochs", default=100, type=int, help="Number of epochs.")
parser.add_argument("--threads", default=1, type=int, help="Maximum number of threads to use.")
args = parser.parse_args()
# Create logdir name
args.logdir = "logs/{}-{}-{}".format(
os.path.basename(__file__),
datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S"),
",".join(("{}={}".format(re.sub("(.)[^_]*_?", r"\1", key), value) for key, value in sorted(vars(args).items())))
)
if not os.path.exists("logs"): os.mkdir("logs") # TF 1.6 will do this by itself
# Load the data
timit = timit_mfcc26_dataset.TIMIT("timit-mfcc26.pickle")
# Construct the network
network = Network(threads=args.threads)
network.construct(args, len(timit.phones), timit.mfcc_dim)
# Train
for i in range(args.epochs):
network.train_epoch(timit.train, args.batch_size)
network.evaluate("dev", timit.dev, args.batch_size)
# Predict test data
with open("{}/speech_recognition_test.txt".format(args.logdir), "w") as test_file:
# TODO: Predict phonemes for test set using network.predict(timit.test, args.batch_size)
# and save them to `test_file`. Save the phonemes for each utterance on a single line,
# separating them by a single space. The phonemes should be printed as strings (use
# timit.phones to convert phoneme IDs to strings).
pass
|
(* Title: ZF/AC/AC15_WO6.thy
Author: Krzysztof Grabczewski
The proofs needed to state that AC10, ..., AC15 are equivalent to the rest.
We need the following:
WO1 ==> AC10(n) ==> AC11 ==> AC12 ==> AC15 ==> WO6
In order to add the formulations AC13 and AC14 we need:
AC10(succ(n)) ==> AC13(n) ==> AC14 ==> AC15
or
AC1 ==> AC13(1); AC13(m) ==> AC13(n) ==> AC14 ==> AC15 (m\<le>n)
So we don't have to prove all implications of both cases.
Moreover we don't need to prove AC13(1) ==> AC1 and AC11 ==> AC14 as
Rubin & Rubin do.
*)
theory AC15_WO6
imports HH Cardinal_aux
begin
(* ********************************************************************** *)
(* Lemmas used in the proofs in which the conclusion is AC13, AC14 *)
(* or AC15 *)
(* - cons_times_nat_not_Finite *)
(* - ex_fun_AC13_AC15 *)
(* ********************************************************************** *)
lemma lepoll_Sigma: "A\<noteq>0 ==> B \<lesssim> A*B"
apply (unfold lepoll_def)
apply (erule not_emptyE)
apply (rule_tac x = "\<lambda>z \<in> B. <x,z>" in exI)
apply (fast intro!: snd_conv lam_injective)
done
lemma cons_times_nat_not_Finite:
"0\<notin>A ==> \<forall>B \<in> {cons(0,x*nat). x \<in> A}. ~Finite(B)"
apply clarify
apply (rule nat_not_Finite [THEN notE] )
apply (subgoal_tac "x \<noteq> 0")
apply (blast intro: lepoll_Sigma [THEN lepoll_Finite])+
done
lemma lemma1: "[| \<Union>(C)=A; a \<in> A |] ==> \<exists>B \<in> C. a \<in> B & B \<subseteq> A"
by fast
lemma lemma2:
"[| pairwise_disjoint(A); B \<in> A; C \<in> A; a \<in> B; a \<in> C |] ==> B=C"
by (unfold pairwise_disjoint_def, blast)
lemma lemma3:
"\<forall>B \<in> {cons(0, x*nat). x \<in> A}. pairwise_disjoint(f`B) &
sets_of_size_between(f`B, 2, n) & \<Union>(f`B)=B
==> \<forall>B \<in> A. \<exists>! u. u \<in> f`cons(0, B*nat) & u \<subseteq> cons(0, B*nat) &
0 \<in> u & 2 \<lesssim> u & u \<lesssim> n"
apply (unfold sets_of_size_between_def)
apply (rule ballI)
apply (erule_tac x="cons(0, B*nat)" in ballE)
apply (blast dest: lemma1 intro!: lemma2, blast)
done
lemma lemma4: "[| A \<lesssim> i; Ord(i) |] ==> {P(a). a \<in> A} \<lesssim> i"
apply (unfold lepoll_def)
apply (erule exE)
apply (rule_tac x = "\<lambda>x \<in> RepFun(A,P). \<mu> j. \<exists>a\<in>A. x=P(a) & f`a=j"
in exI)
apply (rule_tac d = "%y. P (converse (f) `y) " in lam_injective)
apply (erule RepFunE)
apply (frule inj_is_fun [THEN apply_type], assumption)
apply (fast intro: LeastI2 elim!: Ord_in_Ord inj_is_fun [THEN apply_type])
apply (erule RepFunE)
apply (rule LeastI2)
apply fast
apply (fast elim!: Ord_in_Ord inj_is_fun [THEN apply_type])
apply (fast elim: sym left_inverse [THEN ssubst])
done
lemma lemma5_1:
"[| B \<in> A; 2 \<lesssim> u(B) |] ==> (\<lambda>x \<in> A. {fst(x). x \<in> u(x)-{0}})`B \<noteq> 0"
apply simp
apply (fast dest: lepoll_Diff_sing
elim: lepoll_trans [THEN succ_lepoll_natE] ssubst
intro!: lepoll_refl)
done
lemma lemma5_2:
"[| B \<in> A; u(B) \<subseteq> cons(0, B*nat) |]
==> (\<lambda>x \<in> A. {fst(x). x \<in> u(x)-{0}})`B \<subseteq> B"
apply auto
done
lemma lemma5_3:
"[| n \<in> nat; B \<in> A; 0 \<in> u(B); u(B) \<lesssim> succ(n) |]
==> (\<lambda>x \<in> A. {fst(x). x \<in> u(x)-{0}})`B \<lesssim> n"
apply simp
apply (fast elim!: Diff_lepoll [THEN lemma4 [OF _ nat_into_Ord]])
done
lemma ex_fun_AC13_AC15:
"[| \<forall>B \<in> {cons(0, x*nat). x \<in> A}.
pairwise_disjoint(f`B) &
sets_of_size_between(f`B, 2, succ(n)) & \<Union>(f`B)=B;
n \<in> nat |]
==> \<exists>f. \<forall>B \<in> A. f`B \<noteq> 0 & f`B \<subseteq> B & f`B \<lesssim> n"
by (fast del: subsetI notI
dest!: lemma3 theI intro!: lemma5_1 lemma5_2 lemma5_3)
(* ********************************************************************** *)
(* The target proofs *)
(* ********************************************************************** *)
(* ********************************************************************** *)
(* AC10(n) ==> AC11 *)
(* ********************************************************************** *)
theorem AC10_AC11: "[| n \<in> nat; 1\<le>n; AC10(n) |] ==> AC11"
by (unfold AC10_def AC11_def, blast)
(* ********************************************************************** *)
(* AC11 ==> AC12 *)
(* ********************************************************************** *)
theorem AC11_AC12: "AC11 ==> AC12"
by (unfold AC10_def AC11_def AC11_def AC12_def, blast)
(* ********************************************************************** *)
(* AC12 ==> AC15 *)
(* ********************************************************************** *)
theorem AC12_AC15: "AC12 ==> AC15"
apply (unfold AC12_def AC15_def)
apply (blast del: ballI
intro!: cons_times_nat_not_Finite ex_fun_AC13_AC15)
done
(* ********************************************************************** *)
(* AC15 ==> WO6 *)
(* ********************************************************************** *)
lemma OUN_eq_UN: "Ord(x) ==> (\<Union>a<x. F(a)) = (\<Union>a \<in> x. F(a))"
by (fast intro!: ltI dest!: ltD)
lemma AC15_WO6_aux1:
"\<forall>x \<in> Pow(A)-{0}. f`x\<noteq>0 & f`x \<subseteq> x & f`x \<lesssim> m
==> (\<Union>i<\<mu> x. HH(f,A,x)={A}. HH(f,A,i)) = A"
apply (simp add: Ord_Least [THEN OUN_eq_UN])
apply (rule equalityI)
apply (fast dest!: less_Least_subset_x)
apply (blast del: subsetI
intro!: f_subsets_imp_UN_HH_eq_x [THEN Diff_eq_0_iff [THEN iffD1]])
done
lemma AC15_WO6_aux2:
"\<forall>x \<in> Pow(A)-{0}. f`x\<noteq>0 & f`x \<subseteq> x & f`x \<lesssim> m
==> \<forall>x < (\<mu> x. HH(f,A,x)={A}). HH(f,A,x) \<lesssim> m"
apply (rule oallI)
apply (drule ltD [THEN less_Least_subset_x])
apply (frule HH_subset_imp_eq)
apply (erule ssubst)
apply (blast dest!: HH_subset_x_imp_subset_Diff_UN [THEN not_emptyI2])
(*but can't use del: DiffE despite the obvious conflict*)
done
theorem AC15_WO6: "AC15 ==> WO6"
apply (unfold AC15_def WO6_def)
apply (rule allI)
apply (erule_tac x = "Pow (A) -{0}" in allE)
apply (erule impE, fast)
apply (elim bexE conjE exE)
apply (rule bexI)
apply (rule conjI, assumption)
apply (rule_tac x = "\<mu> i. HH (f,A,i) ={A}" in exI)
apply (rule_tac x = "\<lambda>j \<in> (\<mu> i. HH (f,A,i) ={A}) . HH (f,A,j) " in exI)
apply (simp_all add: ltD)
apply (fast intro!: Ord_Least lam_type [THEN domain_of_fun]
elim!: less_Least_subset_x AC15_WO6_aux1 AC15_WO6_aux2)
done
(* ********************************************************************** *)
(* The proof needed in the first case, not in the second *)
(* ********************************************************************** *)
(* ********************************************************************** *)
(* AC10(n) ==> AC13(n-1) if 2\<le>n *)
(* *)
(* Because of the change to the formal definition of AC10(n) we prove *)
(* the following obviously equivalent theorem \<in> *)
(* AC10(n) implies AC13(n) for (1\<le>n) *)
(* ********************************************************************** *)
theorem AC10_AC13: "[| n \<in> nat; 1\<le>n; AC10(n) |] ==> AC13(n)"
apply (unfold AC10_def AC13_def, safe)
apply (erule allE)
apply (erule impE [OF _ cons_times_nat_not_Finite], assumption)
apply (fast elim!: impE [OF _ cons_times_nat_not_Finite]
dest!: ex_fun_AC13_AC15)
done
(* ********************************************************************** *)
(* The proofs needed in the second case, not in the first *)
(* ********************************************************************** *)
(* ********************************************************************** *)
(* AC1 ==> AC13(1) *)
(* ********************************************************************** *)
lemma AC1_AC13: "AC1 ==> AC13(1)"
apply (unfold AC1_def AC13_def)
apply (rule allI)
apply (erule allE)
apply (rule impI)
apply (drule mp, assumption)
apply (elim exE)
apply (rule_tac x = "\<lambda>x \<in> A. {f`x}" in exI)
apply (simp add: singleton_eqpoll_1 [THEN eqpoll_imp_lepoll])
done
(* ********************************************************************** *)
(* AC13(m) ==> AC13(n) for m \<subseteq> n *)
(* ********************************************************************** *)
lemma AC13_mono: "[| m\<le>n; AC13(m) |] ==> AC13(n)"
apply (unfold AC13_def)
apply (drule le_imp_lepoll)
apply (fast elim!: lepoll_trans)
done
(* ********************************************************************** *)
(* The proofs necessary for both cases *)
(* ********************************************************************** *)
(* ********************************************************************** *)
(* AC13(n) ==> AC14 if 1 \<subseteq> n *)
(* ********************************************************************** *)
theorem AC13_AC14: "[| n \<in> nat; 1\<le>n; AC13(n) |] ==> AC14"
by (unfold AC13_def AC14_def, auto)
(* ********************************************************************** *)
(* AC14 ==> AC15 *)
(* ********************************************************************** *)
theorem AC14_AC15: "AC14 ==> AC15"
by (unfold AC13_def AC14_def AC15_def, fast)
(* ********************************************************************** *)
(* The redundant proofs; however cited by Rubin & Rubin *)
(* ********************************************************************** *)
(* ********************************************************************** *)
(* AC13(1) ==> AC1 *)
(* ********************************************************************** *)
lemma lemma_aux: "[| A\<noteq>0; A \<lesssim> 1 |] ==> \<exists>a. A={a}"
by (fast elim!: not_emptyE lepoll_1_is_sing)
lemma AC13_AC1_lemma:
"\<forall>B \<in> A. f(B)\<noteq>0 & f(B)<=B & f(B) \<lesssim> 1
==> (\<lambda>x \<in> A. THE y. f(x)={y}) \<in> (\<Prod>X \<in> A. X)"
apply (rule lam_type)
apply (drule bspec, assumption)
apply (elim conjE)
apply (erule lemma_aux [THEN exE], assumption)
apply (simp add: the_equality)
done
theorem AC13_AC1: "AC13(1) ==> AC1"
apply (unfold AC13_def AC1_def)
apply (fast elim!: AC13_AC1_lemma)
done
(* ********************************************************************** *)
(* AC11 ==> AC14 *)
(* ********************************************************************** *)
theorem AC11_AC14: "AC11 ==> AC14"
apply (unfold AC11_def AC14_def)
apply (fast intro!: AC10_AC13)
done
end
|
theory prop_31
imports Main
"$HIPSTER_HOME/IsaHipster"
begin
datatype Nat = Z | S "Nat"
fun min2 :: "Nat => Nat => Nat" where
"min2 (Z) y = Z"
| "min2 (S z) (Z) = Z"
| "min2 (S z) (S y1) = S (min2 z y1)"
(*hipster min2 *)
lemma lemma_a [thy_expl]: "min2 x x = x"
by (hipster_induct_schemes min2.simps)
lemma lemma_aa [thy_expl]: "min2 x Z = Z"
by (hipster_induct_schemes min2.simps)
lemma lemma_ab [thy_expl]: "min2 x (min2 x y) = min2 x y"
by (hipster_induct_schemes min2.simps)
lemma lemma_ac [thy_expl]: "min2 x (min2 y x) = min2 y x"
by (hipster_induct_schemes min2.simps)
lemma lemma_ad [thy_expl]: "min2 (min2 x y) x = min2 x y"
by (hipster_induct_schemes min2.simps)
lemma lemma_ae []: "min2 (S x) y = min2 y (S x)"
by (hipster_induct_schemes min2.simps)
lemma lemma_af [thy_expl]: "min2 x y = min2 y x"
by (hipster_induct_schemes min2.simps)
theorem x0 :
"(min2 (min2 a b) c) = (min2 a (min2 b c))"
apply(induction a b arbitrary: c rule: min2.induct)
apply(simp_all)
apply(metis min2.simps Nat.exhaust)
by (metis min2.simps Nat.exhaust)
(*by (tactic {* Subgoal.FOCUS_PARAMS (K (Tactic_Data.hard_tac @{context})) @{context} 1 *})*)
end
|
More Information: Auxiliary contact type; cr463 series contactor used on; 1no-1nc contact configuration; left/right mounting location; with single pole. The 460XB1 Accessories is available brand new and refurbished, with a full 1-year replacement warranty.
WestCoastPower.com is your leading provider of General Electric 460XB1 Accessories. If you have questions about this product or need help identifying the part you need, give us a call. We also stock Accessories from General Electric that aren't listed on our website. If you don't see the specific General Electric Accessories you need listed, call us and we'll get it for you.
Due to the nature of the reconditioning process, we don't always get a chance to get all of our products represented in our online catalog - some are often sold before we get a chance to list them. If you don't see it listed, chances are, we likely have it in stock or can get it for you fast - and all of our reconditioned products carry the same 1-year warranty that come with our new products. And we offer price matching on all products - if you find it cheaper elsewhere, call us. Order typically ship the same business day the order was received. Let us get you the General Electric 460XB1 General Electric Lighting Contactor Accessories Accessories you need, quickly. |
/-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
! This file was ported from Lean 3 source module ring_theory.polynomial.dickson
! 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.Algebra.CharP.Invertible
import Mathbin.Data.Zmod.Basic
import Mathbin.RingTheory.Localization.FractionRing
import Mathbin.RingTheory.Polynomial.Chebyshev
import Mathbin.RingTheory.Ideal.LocalRing
/-!
# Dickson polynomials
The (generalised) Dickson polynomials are a family of polynomials indexed by `ℕ × ℕ`,
with coefficients in a commutative ring `R` depending on an element `a∈R`. More precisely, the
they satisfy the recursion `dickson k a (n + 2) = X * (dickson k a n + 1) - a * (dickson k a n)`
with starting values `dickson k a 0 = 3 - k` and `dickson k a 1 = X`. In the literature,
`dickson k a n` is called the `n`-th Dickson polynomial of the `k`-th kind associated to the
parameter `a : R`. They are closely related to the Chebyshev polynomials in the case that `a=1`.
When `a=0` they are just the family of monomials `X ^ n`.
## Main definition
* `polynomial.dickson`: the generalised Dickson polynomials.
## Main statements
* `polynomial.dickson_one_one_mul`, the `(m * n)`-th Dickson polynomial of the first kind for
parameter `1 : R` is the composition of the `m`-th and `n`-th Dickson polynomials of the first
kind for `1 : R`.
* `polynomial.dickson_one_one_char_p`, for a prime number `p`, the `p`-th Dickson polynomial of the
first kind associated to parameter `1 : R` is congruent to `X ^ p` modulo `p`.
## References
* [R. Lidl, G. L. Mullen and G. Turnwald, _Dickson polynomials_][MR1237403]
## TODO
* Redefine `dickson` in terms of `linear_recurrence`.
* Show that `dickson 2 1` is equal to the characteristic polynomial of the adjacency matrix of a
type A Dynkin diagram.
* Prove that the adjacency matrices of simply laced Dynkin diagrams are precisely the adjacency
matrices of simple connected graphs which annihilate `dickson 2 1`.
-/
noncomputable section
namespace Polynomial
open Polynomial
variable {R S : Type _} [CommRing R] [CommRing S] (k : ℕ) (a : R)
/-- `dickson` is the `n`the (generalised) Dickson polynomial of the `k`-th kind associated to the
element `a ∈ R`. -/
noncomputable def dickson : ℕ → R[X]
| 0 => 3 - k
| 1 => X
| n + 2 => X * dickson (n + 1) - C a * dickson n
#align polynomial.dickson Polynomial.dickson
@[simp]
theorem dickson_zero : dickson k a 0 = 3 - k :=
rfl
#align polynomial.dickson_zero Polynomial.dickson_zero
@[simp]
theorem dickson_one : dickson k a 1 = X :=
rfl
#align polynomial.dickson_one Polynomial.dickson_one
theorem dickson_two : dickson k a 2 = X ^ 2 - C a * (3 - k) := by simp only [dickson, sq]
#align polynomial.dickson_two Polynomial.dickson_two
@[simp]
theorem dickson_add_two (n : ℕ) :
dickson k a (n + 2) = X * dickson k a (n + 1) - C a * dickson k a n := by rw [dickson]
#align polynomial.dickson_add_two Polynomial.dickson_add_two
theorem dickson_of_two_le {n : ℕ} (h : 2 ≤ n) :
dickson k a n = X * dickson k a (n - 1) - C a * dickson k a (n - 2) :=
by
obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le h
rw [add_comm]
exact dickson_add_two k a n
#align polynomial.dickson_of_two_le Polynomial.dickson_of_two_le
variable {R S k a}
theorem map_dickson (f : R →+* S) : ∀ n : ℕ, map f (dickson k a n) = dickson k (f a) n
| 0 => by
simp only [dickson_zero, Polynomial.map_sub, Polynomial.map_nat_cast, bit1, bit0,
Polynomial.map_add, Polynomial.map_one]
| 1 => by simp only [dickson_one, map_X]
| n + 2 =>
by
simp only [dickson_add_two, Polynomial.map_sub, Polynomial.map_mul, map_X, map_C]
rw [map_dickson, map_dickson]
#align polynomial.map_dickson Polynomial.map_dickson
variable {R}
@[simp]
theorem dickson_two_zero : ∀ n : ℕ, dickson 2 (0 : R) n = X ^ n
| 0 => by
simp only [dickson_zero, pow_zero]
norm_num
| 1 => by simp only [dickson_one, pow_one]
| n + 2 => by
simp only [dickson_add_two, C_0, MulZeroClass.zero_mul, sub_zero]
rw [dickson_two_zero, pow_add X (n + 1) 1, mul_comm, pow_one]
#align polynomial.dickson_two_zero Polynomial.dickson_two_zero
section Dickson
/-!
### A Lambda structure on `ℤ[X]`
Mathlib doesn't currently know what a Lambda ring is.
But once it does, we can endow `ℤ[X]` with a Lambda structure
in terms of the `dickson 1 1` polynomials defined below.
There is exactly one other Lambda structure on `ℤ[X]` in terms of binomial polynomials.
-/
variable {R}
theorem dickson_one_one_eval_add_inv (x y : R) (h : x * y = 1) :
∀ n, (dickson 1 (1 : R) n).eval (x + y) = x ^ n + y ^ n
| 0 => by
simp only [bit0, eval_one, eval_add, pow_zero, dickson_zero]
norm_num
| 1 => by simp only [eval_X, dickson_one, pow_one]
| n + 2 =>
by
simp only [eval_sub, eval_mul, dickson_one_one_eval_add_inv, eval_X, dickson_add_two, C_1,
eval_one]
conv_lhs => simp only [pow_succ, add_mul, mul_add, h, ← mul_assoc, mul_comm y x, one_mul]
ring
#align polynomial.dickson_one_one_eval_add_inv Polynomial.dickson_one_one_eval_add_inv
variable (R)
theorem dickson_one_one_eq_chebyshev_t [Invertible (2 : R)] :
∀ n, dickson 1 (1 : R) n = 2 * (Chebyshev.T R n).comp (C (⅟ 2) * X)
| 0 => by
simp only [chebyshev.T_zero, mul_one, one_comp, dickson_zero]
norm_num
| 1 => by
rw [dickson_one, chebyshev.T_one, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul, mul_invOf_self,
C_1, one_mul]
| n + 2 =>
by
simp only [dickson_add_two, chebyshev.T_add_two, dickson_one_one_eq_chebyshev_T (n + 1),
dickson_one_one_eq_chebyshev_T n, sub_comp, mul_comp, add_comp, X_comp, bit0_comp, one_comp]
simp only [← C_1, ← C_bit0, ← mul_assoc, ← C_mul, mul_invOf_self]
rw [C_1, one_mul]
ring
#align polynomial.dickson_one_one_eq_chebyshev_T Polynomial.dickson_one_one_eq_chebyshev_t
theorem chebyshev_t_eq_dickson_one_one [Invertible (2 : R)] (n : ℕ) :
Chebyshev.T R n = C (⅟ 2) * (dickson 1 1 n).comp (2 * X) :=
by
rw [dickson_one_one_eq_chebyshev_T]
simp only [comp_assoc, mul_comp, C_comp, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul]
rw [invOf_mul_self, C_1, one_mul, one_mul, comp_X]
#align polynomial.chebyshev_T_eq_dickson_one_one Polynomial.chebyshev_t_eq_dickson_one_one
/-- The `(m * n)`-th Dickson polynomial of the first kind is the composition of the `m`-th and
`n`-th. -/
theorem dickson_one_one_mul (m n : ℕ) :
dickson 1 (1 : R) (m * n) = (dickson 1 1 m).comp (dickson 1 1 n) :=
by
have h : (1 : R) = Int.castRingHom R 1
simp only [eq_intCast, Int.cast_one]
rw [h]
simp only [← map_dickson (Int.castRingHom R), ← map_comp]
congr 1
apply map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [map_dickson, map_comp, eq_intCast, Int.cast_one, dickson_one_one_eq_chebyshev_T,
chebyshev.T_mul, two_mul, ← add_comp]
simp only [← two_mul, ← comp_assoc]
apply eval₂_congr rfl rfl
rw [comp_assoc]
apply eval₂_congr rfl _ rfl
rw [mul_comp, C_comp, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul, invOf_mul_self, C_1, one_mul]
#align polynomial.dickson_one_one_mul Polynomial.dickson_one_one_mul
theorem dickson_one_one_comp_comm (m n : ℕ) :
(dickson 1 (1 : R) m).comp (dickson 1 1 n) = (dickson 1 1 n).comp (dickson 1 1 m) := by
rw [← dickson_one_one_mul, mul_comm, dickson_one_one_mul]
#align polynomial.dickson_one_one_comp_comm Polynomial.dickson_one_one_comp_comm
theorem dickson_one_one_zMod_p (p : ℕ) [Fact p.Prime] : dickson 1 (1 : ZMod p) p = X ^ p :=
by
-- Recall that `dickson_eval_add_inv` characterises `dickson 1 1 p`
-- as a polynomial that maps `x + x⁻¹` to `x ^ p + (x⁻¹) ^ p`.
-- Since `X ^ p` also satisfies this property in characteristic `p`,
-- we can use a variant on `polynomial.funext` to conclude that these polynomials are equal.
-- For this argument, we need an arbitrary infinite field of characteristic `p`.
obtain ⟨K, _, _, H⟩ : ∃ (K : Type)(_ : Field K), ∃ _ : CharP K p, Infinite K :=
by
let K := FractionRing (Polynomial (ZMod p))
let f : ZMod p →+* K := (algebraMap _ (FractionRing _)).comp C
have : CharP K p := by
rw [← f.char_p_iff_char_p]
infer_instance
haveI : Infinite K :=
Infinite.of_injective (algebraMap (Polynomial (ZMod p)) (FractionRing (Polynomial (ZMod p))))
(IsFractionRing.injective _ _)
refine' ⟨K, _, _, _⟩ <;> infer_instance
skip
apply map_injective (ZMod.castHom (dvd_refl p) K) (RingHom.injective _)
rw [map_dickson, Polynomial.map_pow, map_X]
apply eq_of_infinite_eval_eq
-- The two polynomials agree on all `x` of the form `x = y + y⁻¹`.
apply @Set.Infinite.mono _ { x : K | ∃ y, x = y + y⁻¹ ∧ y ≠ 0 }
· rintro _ ⟨x, rfl, hx⟩
simp only [eval_X, eval_pow, Set.mem_setOf_eq, @add_pow_char K _ p,
dickson_one_one_eval_add_inv _ _ (mul_inv_cancel hx), inv_pow, ZMod.castHom_apply,
ZMod.cast_one']
-- Now we need to show that the set of such `x` is infinite.
-- If the set is finite, then we will show that `K` is also finite.
· intro h
rw [← Set.infinite_univ_iff] at H
apply H
-- To each `x` of the form `x = y + y⁻¹`
-- we `bind` the set of `y` that solve the equation `x = y + y⁻¹`.
-- For every `x`, that set is finite (since it is governed by a quadratic equation).
-- For the moment, we claim that all these sets together cover `K`.
suffices
(Set.univ : Set K) =
{ x : K | ∃ y : K, x = y + y⁻¹ ∧ y ≠ 0 } >>= fun x => { y | x = y + y⁻¹ ∨ y = 0 }
by
rw [this]
clear this
refine' h.bUnion fun x hx => _
-- The following quadratic polynomial has as solutions the `y` for which `x = y + y⁻¹`.
let φ : K[X] := X ^ 2 - C x * X + 1
have hφ : φ ≠ 0 := by
intro H
have : φ.eval 0 = 0 := by rw [H, eval_zero]
simpa [eval_X, eval_one, eval_pow, eval_sub, sub_zero, eval_add, eval_mul,
MulZeroClass.mul_zero, sq, zero_add, one_ne_zero]
classical
convert(φ.roots ∪ {0}).toFinset.finite_toSet using 1
ext1 y
simp only [Multiset.mem_toFinset, Set.mem_setOf_eq, Finset.mem_coe, Multiset.mem_union,
mem_roots hφ, is_root, eval_add, eval_sub, eval_pow, eval_mul, eval_X, eval_C, eval_one,
Multiset.mem_singleton]
by_cases hy : y = 0
· simp only [hy, eq_self_iff_true, or_true_iff]
apply or_congr _ Iff.rfl
rw [← mul_left_inj' hy, eq_comm, ← sub_eq_zero, add_mul, inv_mul_cancel hy]
apply eq_iff_eq_cancel_right.mpr
ring
-- Finally, we prove the claim that our finite union of finite sets covers all of `K`.
· apply (Set.eq_univ_of_forall _).symm
intro x
simp only [exists_prop, Set.mem_unionᵢ, Set.bind_def, Ne.def, Set.mem_setOf_eq]
by_cases hx : x = 0
· simp only [hx, and_true_iff, eq_self_iff_true, inv_zero, or_true_iff]
exact ⟨_, 1, rfl, one_ne_zero⟩
· simp only [hx, or_false_iff, exists_eq_right]
exact ⟨_, rfl, hx⟩
#align polynomial.dickson_one_one_zmod_p Polynomial.dickson_one_one_zMod_p
theorem dickson_one_one_charP (p : ℕ) [Fact p.Prime] [CharP R p] : dickson 1 (1 : R) p = X ^ p :=
by
have h : (1 : R) = ZMod.castHom (dvd_refl p) R 1
simp only [ZMod.castHom_apply, ZMod.cast_one']
rw [h, ← map_dickson (ZMod.castHom (dvd_refl p) R), dickson_one_one_zmod_p, Polynomial.map_pow,
map_X]
#align polynomial.dickson_one_one_char_p Polynomial.dickson_one_one_charP
end Dickson
end Polynomial
|
-- import picard_lindelof.definitions
-- open topological_space measure_theory metric
-- variable (μ : measure ℝ)
-- -- NOTE: This is meant to be ℝ^n.
-- variables {B : Type*} [normed_group B] [normed_space ℝ B] [measurable_space B]
-- [complete_space B] [second_countable_topology B] [borel_space B]
-- [linear_order B]
-- local infixr ` →ᵇ `:25 := bounded_continuous_function
-- lemma P.edist_eq_Inf (x y : ℝ →ᵇ B) (h : edist (P μ x) (P y) ≠ ⊤)
-- : edist (P x) (P y) = Inf {C | 0 ≤ C ∧ ∀ (a : ℝ), edist (P x a) (P y a) ≤ C} :=
-- begin
-- let S := {C : ℝ | 0 ≤ C ∧ ∀ (a : ℝ), dist (P x a) (P y a) ≤ C},
-- have hS : S.nonempty,
-- { use [supr (λ t, dist ((P x) t) ((P y) t))], split,
-- { eapply le_csupr_iff.mpr,
-- { rcases (P.dist_bdd_above x y) with ⟨C, hC⟩,
-- use C, rintros d ⟨a, hd⟩, rw ←hd, exact (hC a), },
-- { intros b h,
-- replace h := h (nonempty.some (by apply_instance)),
-- exact (le_trans dist_nonneg h), }, },
-- { apply le_csupr,
-- { rcases (P.dist_bdd_above x y) with ⟨C, hC⟩,
-- use C, rintros d ⟨a, hd⟩, rw ←hd, exact (hC a), }, }, },
-- have hSbdd : bdd_below S,
-- { use 0, intros x hx, exact hx.1, },
-- have h := map_cInf_of_continuous_at_of_monotone
-- (ennreal.continuous_at_of_real (Inf S)) ennreal.monotone_of_real hS hSbdd,
-- unfold edist, unfold metric_space.edist,
-- rw h, simp only [S, set.image], dsimp,
-- sorry,
-- -- Issue with C maybe being ⊤. But I believe that's because the sets won't
-- -- be the same, but the infimums will
-- -- congr, ext C, split,
-- -- { rintros ⟨c, ⟨⟨h0lec, hdist⟩, hC⟩⟩, split,
-- -- { rw ←hC, replace h0lec := ennreal.of_real_le_of_real h0lec,
-- -- rw ennreal.of_real_zero at h0lec, exact h0lec, },
-- -- { intros a, rw ←hC,
-- -- have hdista := hdist a,
-- -- erw metric_space.edist_dist,
-- -- exact (ennreal.of_real_le_of_real hdista), }, },
-- -- { rintros ⟨h0leC, hedist⟩, by_cases (C = ⊤),
-- -- { },
-- -- { use [ennreal.to_real C], split,
-- -- { split,
-- -- { exact ennreal.to_real_nonneg, },
-- -- { intros a, have hedista := hedist a,
-- -- erw metric_space.edist_dist at hedista, sorry, }, },
-- -- { sorry, }, }, },
-- end |
import analysis.normed_space.basic
import analysis.specific_limits
import for_mathlib.topology
open set metric function normed_field
lemma nondiscrete_normed_field.nondiscrete {k : Type*} [nondiscrete_normed_field k] :
¬ discrete_topology k :=
begin
intro h,
replace h := discrete_iff_open_singletons.mp h 0,
rw is_open_iff at h,
rcases h 0 (mem_singleton 0) with ⟨ε, ε_pos, hε⟩,
rcases exists_norm_lt_one k with ⟨x₀, x₀_ne, hx₀⟩,
obtain ⟨n, hn⟩ : ∃ n : ℕ, ∥x₀^n∥ < ε,
{ cases tendsto_at_top.mp (tendsto_pow_at_top_nhds_0_of_lt_1 (le_of_lt x₀_ne) hx₀) ε ε_pos with N hN,
use N,
simpa [norm_pow] using hN N (le_refl _) },
rw ball_0_eq at hε,
specialize hε hn,
rw [mem_singleton_iff, ← norm_eq_zero, norm_pow] at hε,
rw pow_eq_zero hε at x₀_ne,
exact lt_irrefl _ x₀_ne
end
|
module _ (A : Set) where
{-# POLARITY A #-}
|
[STATEMENT]
lemma PO_m3_inv7b_sesK_compr_non_trans [iff]:
"{m3_inv7b_sesK_compr_non \<inter> m3_inv6_ticket \<inter> m3_inv4_lkeysec}
trans m3
{> m3_inv7b_sesK_compr_non}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. {m3_inv7b_sesK_compr_non \<inter> m3_inv6_ticket \<inter> m3_inv4_lkeysec} TS.trans m3 {> m3_inv7b_sesK_compr_non}
[PROOF STEP]
by (auto simp add: m3_def m3_trans_def intro!: PO_m3_inv7b_sesK_compr_non_trans_lemmas)
(auto simp add: PO_hoare_defs m3_defs m3_inv7b_sesK_compr_non_simps
intro!: m3_inv7b_sesK_compr_nonI) |
Require Import Basic.
Inductive Result {A} := solution (a:A) | uninhabited.
Arguments Result _ : clear implicits.
Class Search `{Basic} := {
search {A} : Space A -> Result A;
searchSolution {A s} {a:A} : search s = solution a -> In ⟦ s ⟧ a;
searchUninhabited {A s} : search s = uninhabited -> ⟦ s ⟧ = Empty_set A
}.
|
A set $B$ is a topological basis if and only if every open set is a union of elements of $B$. |
-- let X, Y, Z be sets.
variables {X Y Z : Type}
-- a function f : X → Y is *injective* if f(a) = f(b) → a = b for all a,b in X.
def injective (f : X → Y) : Prop :=
∀ a b : X, f(a) = f(b) → a = b
-- challenge: the composite of two injective functions is injective
theorem challenge1
(f : X → Y) (hf : injective f)
(g : Y → Z) (hg : injective g) :
injective (g ∘ f) :=
begin
-- the *definition* of "injective" is "for all a and b...", so let
-- a and b be arbitrary elements of X.
intros a b,
-- Assume (g ∘ f) a = (g ∘ f) b
intro hab,
-- The goal is now ⊢ a = b .
-- By injectivity of f, it suffices to prove f(a)=f(b)
apply hf,
-- By injectivity of g, it suffices to prove g(f(a))=g(f(b))
apply hg,
-- but this is precisely our assumption.
exact hab,
-- "no goals" means we're done.
end
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.reverse
import algebra.associated
/-!
# Theory of monic polynomials
We give several tools for proving that polynomials are monic, e.g.
`monic_mul`, `monic_map`.
-/
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
open finset
open_locale big_operators
namespace polynomial
universes u v y
variables {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y}
section semiring
variables [semiring R] {p q r : polynomial R}
lemma monic.as_sum {p : polynomial R} (hp : p.monic) :
p = X^(p.nat_degree) + (∑ i in range p.nat_degree, C (p.coeff i) * X^i) :=
begin
conv_lhs { rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] },
suffices : C (p.coeff p.nat_degree) = 1,
{ rw [this, one_mul] },
exact congr_arg C hp
end
lemma ne_zero_of_monic_of_zero_ne_one (hp : monic p) (h : (0 : R) ≠ 1) :
p ≠ 0 := mt (congr_arg leading_coeff) $ by rw [monic.def.1 hp, leading_coeff_zero]; cc
lemma ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : monic q) : q ≠ 0 :=
begin
intro h, rw [h, monic.def, leading_coeff_zero] at hq,
rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp,
exact hp rfl
end
lemma monic_map [semiring S] (f : R →+* S) (hp : monic p) : monic (p.map f) :=
if h : (0 : S) = 1 then
by haveI := subsingleton_of_zero_eq_one h;
exact subsingleton.elim _ _
else
have f (leading_coeff p) ≠ 0,
by rwa [show _ = _, from hp, is_semiring_hom.map_one f, ne.def, eq_comm],
by
begin
rw [monic, leading_coeff, coeff_map],
suffices : p.coeff (map f p).nat_degree = 1, simp [this],
suffices : (map f p).nat_degree = p.nat_degree, rw this, exact hp,
rwa nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero _ _),
end
lemma monic_mul_C_of_leading_coeff_mul_eq_one [nontrivial R] {b : R}
(hp : p.leading_coeff * b = 1) : monic (p * C b) :=
by rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp]
theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : monic p :=
decidable.by_cases
(assume H : degree p < n, eq_of_zero_eq_one
(H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _)
(assume H : ¬degree p < n,
by rwa [monic, leading_coeff, nat_degree, (lt_or_eq_of_le H1).resolve_left H])
theorem monic_X_pow_add {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) + p) :=
have H1 : degree p < n+1, from lt_of_le_of_lt H (with_bot.coe_lt_coe.2 (nat.lt_succ_self n)),
monic_of_degree_le (n+1)
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero])
theorem monic_X_add_C (x : R) : monic (X + C x) :=
pow_one (X : polynomial R) ▸ monic_X_pow_add degree_C_le
lemma monic_mul (hp : monic p) (hq : monic q) : monic (p * q) :=
if h0 : (0 : R) = 1 then by haveI := subsingleton_of_zero_eq_one h0;
exact subsingleton.elim _ _
else
have leading_coeff p * leading_coeff q ≠ 0, by simp [monic.def.1 hp, monic.def.1 hq, ne.symm h0],
by rw [monic.def, leading_coeff_mul' this, monic.def.1 hp, monic.def.1 hq, one_mul]
lemma monic_pow (hp : monic p) : ∀ (n : ℕ), monic (p ^ n)
| 0 := monic_one
| (n+1) := by { rw pow_succ, exact monic_mul hp (monic_pow n) }
lemma monic_add_of_left {p q : polynomial R} (hp : monic p) (hpq : degree q < degree p) :
monic (p + q) :=
by rwa [monic, add_comm, leading_coeff_add_of_degree_lt hpq]
lemma monic_add_of_right {p q : polynomial R} (hq : monic q) (hpq : degree p < degree q) :
monic (p + q) :=
by rwa [monic, leading_coeff_add_of_degree_lt hpq]
namespace monic
@[simp]
lemma degree_eq_zero_iff_eq_one {p : polynomial R} (hp : p.monic) :
p.nat_degree = 0 ↔ p = 1 :=
begin
split; intro h,
swap, { rw h, exact nat_degree_one },
have : p = C (p.coeff 0),
{ rw ← polynomial.degree_le_zero_iff,
rwa polynomial.nat_degree_eq_zero_iff_degree_le_zero at h },
rw this, convert C_1, rw ← h, apply hp,
end
lemma nat_degree_mul {p q : polynomial R} (hp : p.monic) (hq : q.monic) :
(p * q).nat_degree = p.nat_degree + q.nat_degree :=
begin
nontriviality R,
apply nat_degree_mul',
simp [hp.leading_coeff, hq.leading_coeff]
end
lemma next_coeff_mul {p q : polynomial R} (hp : monic p) (hq : monic q) :
next_coeff (p * q) = next_coeff p + next_coeff q :=
begin
nontriviality,
simp only [← coeff_one_reverse],
rw reverse_mul;
simp [coeff_mul, nat.antidiagonal, hp.leading_coeff, hq.leading_coeff, add_comm]
end
end monic
end semiring
section comm_semiring
variables [comm_semiring R] {p : polynomial R}
lemma monic_multiset_prod_of_monic (t : multiset ι) (f : ι → polynomial R)
(ht : ∀ i ∈ t, monic (f i)) :
monic (t.map f).prod :=
begin
revert ht,
refine t.induction_on _ _, { simp },
intros a t ih ht,
rw [multiset.map_cons, multiset.prod_cons],
exact monic_mul
(ht _ (multiset.mem_cons_self _ _))
(ih (λ _ hi, ht _ (multiset.mem_cons_of_mem hi)))
end
lemma monic_prod_of_monic (s : finset ι) (f : ι → polynomial R) (hs : ∀ i ∈ s, monic (f i)) :
monic (∏ i in s, f i) :=
monic_multiset_prod_of_monic s.1 f hs
lemma is_unit_C {x : R} : is_unit (C x) ↔ is_unit x :=
begin
rw [is_unit_iff_dvd_one, is_unit_iff_dvd_one],
split,
{ rintros ⟨g, hg⟩,
replace hg := congr_arg (eval 0) hg,
rw [eval_one, eval_mul, eval_C] at hg,
exact ⟨g.eval 0, hg⟩ },
{ rintros ⟨y, hy⟩,
exact ⟨C y, by rw [← C_mul, ← hy, C_1]⟩ }
end
lemma eq_one_of_is_unit_of_monic (hm : monic p) (hpu : is_unit p) : p = 1 :=
have degree p ≤ 0,
from calc degree p ≤ degree (1 : polynomial R) :
let ⟨u, hu⟩ := is_unit_iff_dvd_one.1 hpu in
if hu0 : u = 0
then begin
rw [hu0, mul_zero] at hu,
rw [← mul_one p, hu, mul_zero],
simp
end
else have p.leading_coeff * u.leading_coeff ≠ 0,
by rw [hm.leading_coeff, one_mul, ne.def, leading_coeff_eq_zero];
exact hu0,
by rw [hu, degree_mul' this];
exact le_add_of_nonneg_right (degree_nonneg_iff_ne_zero.2 hu0)
... ≤ 0 : degree_one_le,
by rw [eq_C_of_degree_le_zero this, ← nat_degree_eq_zero_iff_degree_le_zero.2 this,
← leading_coeff, hm.leading_coeff, C_1]
lemma monic.next_coeff_multiset_prod (t : multiset ι) (f : ι → polynomial R)
(h : ∀ i ∈ t, monic (f i)) :
next_coeff (t.map f).prod = (t.map (λ i, next_coeff (f i))).sum :=
begin
revert h,
refine multiset.induction_on t _ (λ a t ih ht, _),
{ simp only [multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, multiset.map_zero,
multiset.prod_zero, multiset.sum_zero, not_false_iff, forall_true_iff],
rw ← C_1, rw next_coeff_C_eq_zero },
{ rw [multiset.map_cons, multiset.prod_cons, multiset.map_cons, multiset.sum_cons,
monic.next_coeff_mul, ih],
exacts [λ i hi, ht i (multiset.mem_cons_of_mem hi), ht a (multiset.mem_cons_self _ _),
monic_multiset_prod_of_monic _ _ (λ b bs, ht _ (multiset.mem_cons_of_mem bs))] }
end
lemma monic.next_coeff_prod (s : finset ι) (f : ι → polynomial R) (h : ∀ i ∈ s, monic (f i)) :
next_coeff (∏ i in s, f i) = ∑ i in s, next_coeff (f i) :=
monic.next_coeff_multiset_prod s.1 f h
end comm_semiring
section ring
variables [ring R] {p : polynomial R}
theorem monic_X_sub_C (x : R) : monic (X - C x) :=
by simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)
theorem monic_X_pow_sub {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) - p) :=
by simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) ≤ n, by rwa ←degree_neg p at H)
/-- `X ^ n - a` is monic. -/
lemma monic_X_pow_sub_C {R : Type u} [ring R] (a : R) {n : ℕ} (h : n ≠ 0) : (X ^ n - C a).monic :=
begin
obtain ⟨k, hk⟩ := nat.exists_eq_succ_of_ne_zero h,
convert monic_X_pow_sub _,
exact le_trans degree_C_le nat.with_bot.coe_nonneg,
end
lemma monic_sub_of_left {p q : polynomial R} (hp : monic p) (hpq : degree q < degree p) :
monic (p - q) :=
by { rw sub_eq_add_neg, apply monic_add_of_left hp, rwa degree_neg }
lemma monic_sub_of_right {p q : polynomial R}
(hq : q.leading_coeff = -1) (hpq : degree p < degree q) : monic (p - q) :=
have (-q).coeff (-q).nat_degree = 1 :=
by rw [nat_degree_neg, coeff_neg, show q.coeff q.nat_degree = -1, from hq, neg_neg],
by { rw sub_eq_add_neg, apply monic_add_of_right this, rwa degree_neg }
section injective
open function
variables [semiring S] {f : R →+* S} (hf : injective f)
include hf
lemma leading_coeff_of_injective (p : polynomial R) :
leading_coeff (p.map f) = f (leading_coeff p) :=
begin
delta leading_coeff,
rw [coeff_map f, nat_degree_map' hf p]
end
lemma monic_of_injective {p : polynomial R} (hp : (p.map f).monic) : p.monic :=
begin
apply hf,
rw [← leading_coeff_of_injective hf, hp.leading_coeff, is_semiring_hom.map_one f]
end
end injective
end ring
section nonzero_semiring
variables [semiring R] [nontrivial R] {p q : polynomial R}
@[simp] lemma not_monic_zero : ¬monic (0 : polynomial R) :=
by simpa only [monic, leading_coeff_zero] using (zero_ne_one : (0 : R) ≠ 1)
lemma ne_zero_of_monic (h : monic p) : p ≠ 0 :=
λ h₁, @not_monic_zero R _ _ (h₁ ▸ h)
end nonzero_semiring
end polynomial
|
[STATEMENT]
lemma RBT_lookup_empty [simp]: (*FIXME*)
"rbt_lookup t = Map.empty \<longleftrightarrow> t = RBT_Impl.Empty"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (rbt_lookup t = Map.empty) = (t = rbt.Empty)
[PROOF STEP]
by (cases t) (auto simp add: fun_eq_iff) |
[GOAL]
x y : ℍ
⊢ ↑(starRingEnd ℝ) (inner y x) = inner x y
[PROOFSTEP]
simp [inner_def, mul_comm]
[GOAL]
x y z : ℍ
⊢ inner (x + y) z = inner x z + inner y z
[PROOFSTEP]
simp only [inner_def, add_mul, add_re]
[GOAL]
x y : ℍ
r : ℝ
⊢ inner (r • x) y = ↑(starRingEnd ℝ) r * inner x y
[PROOFSTEP]
simp [inner_def]
[GOAL]
a : ℍ
⊢ ↑normSq a = ‖a‖ * ‖a‖
[PROOFSTEP]
rw [← inner_self, real_inner_self_eq_norm_mul_norm]
[GOAL]
⊢ ‖1‖ = 1
[PROOFSTEP]
rw [norm_eq_sqrt_real_inner, inner_self, normSq.map_one, Real.sqrt_one]
[GOAL]
a : ℝ
⊢ ‖↑a‖ = ‖a‖
[PROOFSTEP]
rw [norm_eq_sqrt_real_inner, inner_self, normSq_coe, Real.sqrt_sq_eq_abs, Real.norm_eq_abs]
[GOAL]
a : ℍ
⊢ ‖star a‖ = ‖a‖
[PROOFSTEP]
simp_rw [norm_eq_sqrt_real_inner, inner_self, normSq_star]
[GOAL]
a b : ℍ
⊢ ‖a * b‖ = ‖a‖ * ‖b‖
[PROOFSTEP]
simp only [norm_eq_sqrt_real_inner, inner_self, normSq.map_mul]
[GOAL]
a b : ℍ
⊢ Real.sqrt (↑normSq a * ↑normSq b) = Real.sqrt (↑normSq a) * Real.sqrt (↑normSq b)
[PROOFSTEP]
exact
Real.sqrt_mul normSq_nonneg
_
-- porting note: added `noncomputable`
[GOAL]
z w : ℂ
⊢ ↑(z + w) = ↑z + ↑w
[PROOFSTEP]
ext
[GOAL]
case a
z w : ℂ
⊢ (↑(z + w)).re = (↑z + ↑w).re
[PROOFSTEP]
simp
[GOAL]
case a
z w : ℂ
⊢ (↑(z + w)).imI = (↑z + ↑w).imI
[PROOFSTEP]
simp
[GOAL]
case a
z w : ℂ
⊢ (↑(z + w)).imJ = (↑z + ↑w).imJ
[PROOFSTEP]
simp
[GOAL]
case a
z w : ℂ
⊢ (↑(z + w)).imK = (↑z + ↑w).imK
[PROOFSTEP]
simp
[GOAL]
z w : ℂ
⊢ ↑(z * w) = ↑z * ↑w
[PROOFSTEP]
ext
[GOAL]
case a
z w : ℂ
⊢ (↑(z * w)).re = (↑z * ↑w).re
[PROOFSTEP]
simp
[GOAL]
case a
z w : ℂ
⊢ (↑(z * w)).imI = (↑z * ↑w).imI
[PROOFSTEP]
simp
[GOAL]
case a
z w : ℂ
⊢ (↑(z * w)).imJ = (↑z * ↑w).imJ
[PROOFSTEP]
simp
[GOAL]
case a
z w : ℂ
⊢ (↑(z * w)).imK = (↑z * ↑w).imK
[PROOFSTEP]
simp
[GOAL]
r : ℝ
z : ℂ
⊢ ↑(r • z) = ↑r * ↑z
[PROOFSTEP]
ext
[GOAL]
case a
r : ℝ
z : ℂ
⊢ (↑(r • z)).re = (↑r * ↑z).re
[PROOFSTEP]
simp
[GOAL]
case a
r : ℝ
z : ℂ
⊢ (↑(r • z)).imI = (↑r * ↑z).imI
[PROOFSTEP]
simp
[GOAL]
case a
r : ℝ
z : ℂ
⊢ (↑(r • z)).imJ = (↑r * ↑z).imJ
[PROOFSTEP]
simp
[GOAL]
case a
r : ℝ
z : ℂ
⊢ (↑(r • z)).imK = (↑r * ↑z).imK
[PROOFSTEP]
simp
[GOAL]
x : ℍ
⊢ ‖↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x)‖ = ‖x‖
[PROOFSTEP]
rw [norm_eq_sqrt_real_inner, norm_eq_sqrt_real_inner, inner_self, normSq_def', PiLp.inner_apply, Fin.sum_univ_four]
[GOAL]
x : ℍ
⊢ Real.sqrt
(inner (↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 0)
(↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 0) +
inner (↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 1)
(↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 1) +
inner (↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 2)
(↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 2) +
inner (↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 3)
(↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 3)) =
Real.sqrt (x.re ^ 2 + x.imI ^ 2 + x.imJ ^ 2 + x.imK ^ 2)
[PROOFSTEP]
simp_rw [IsROrC.inner_apply, starRingEnd_apply, star_trivial, ← sq]
[GOAL]
x : ℍ
⊢ Real.sqrt
(↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 0 ^ 2 +
↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 1 ^ 2 +
↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 2 ^ 2 +
↑(PiLp.equiv 2 fun x => ℝ).symm (↑(equivTuple ℝ) x) 3 ^ 2) =
Real.sqrt (x.re ^ 2 + x.imI ^ 2 + x.imJ ^ 2 + x.imK ^ 2)
[PROOFSTEP]
rfl
[GOAL]
⊢ Continuous ↑normSq
[PROOFSTEP]
simpa [← normSq_eq_norm_mul_self] using (continuous_norm.mul continuous_norm : Continuous fun q : ℍ => ‖q‖ * ‖q‖)
[GOAL]
⊢ Continuous fun q => im q
[PROOFSTEP]
simpa only [← sub_self_re] using continuous_id.sub (continuous_coe.comp continuous_re)
[GOAL]
this : UniformEmbedding ↑(LinearEquiv.toEquiv linearIsometryEquivTuple.toLinearEquiv).symm
⊢ CompleteSpace (EuclideanSpace ℝ (Fin 4))
[PROOFSTEP]
infer_instance
[GOAL]
α : Type u_1
f : α → ℝ
r : ℝ
h : HasSum (fun a => ↑(f a)) ↑r
⊢ HasSum f r
[PROOFSTEP]
simpa only using h.map (show ℍ →ₗ[ℝ] ℝ from QuaternionAlgebra.reₗ _ _) continuous_re
[GOAL]
α : Type u_1
f : α → ℝ
r : ℝ
h : HasSum f r
⊢ HasSum (fun a => ↑(f a)) ↑r
[PROOFSTEP]
simpa only using h.map (algebraMap ℝ ℍ) (continuous_algebraMap _ _)
[GOAL]
α : Type u_1
f : α → ℝ
⊢ (Summable fun a => ↑(f a)) ↔ Summable f
[PROOFSTEP]
simpa only using
Summable.map_iff_of_leftInverse (algebraMap ℝ ℍ) (show ℍ →ₗ[ℝ] ℝ from QuaternionAlgebra.reₗ _ _)
(continuous_algebraMap _ _) continuous_re coe_re
[GOAL]
α : Type u_1
f : α → ℝ
⊢ ∑' (a : α), ↑(f a) = ↑(∑' (a : α), f a)
[PROOFSTEP]
by_cases hf : Summable f
[GOAL]
case pos
α : Type u_1
f : α → ℝ
hf : Summable f
⊢ ∑' (a : α), ↑(f a) = ↑(∑' (a : α), f a)
[PROOFSTEP]
exact (hasSum_coe.mpr hf.hasSum).tsum_eq
[GOAL]
case neg
α : Type u_1
f : α → ℝ
hf : ¬Summable f
⊢ ∑' (a : α), ↑(f a) = ↑(∑' (a : α), f a)
[PROOFSTEP]
simp [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable (summable_coe.not.mpr hf)]
|
-- Math 52: Quiz 3
-- Open this file in a folder that contains 'utils'.
import utils.int_refl
definition is_even (n : ℤ) : Prop := ∃ (k : ℤ), n = 2 * k
definition is_odd (n : ℤ) : Prop := ∃ (k : ℤ), n = 2 * k + 1
axiom even_or_odd (n : ℤ) : is_even n ∨ is_odd n
theorem main : ∀ (n : ℤ), is_even (n * n + 3 * n + 2) :=
begin
intro n,
have H := even_or_odd n,
cases H,
{ unfold is_even at H,
unfold is_even,
cases H with i Hi,
existsi (2 * i * i + 3 * i + 1 : ℤ),
rw Hi,
int_refl [i],
},
{ unfold is_odd at H,
unfold is_even,
cases H with j Hj,
existsi (2 * j * j + 5 * j + 3 : ℤ),
rw Hj,
int_refl [j],
},
end
|
lemma coeffs_uminus [code abstract]: "coeffs (- p) = map uminus (coeffs p)" |
[STATEMENT]
theorem hbt_delete_auto:
"hbt t \<Longrightarrow> hbt(delete x t)"
"hbt t \<Longrightarrow> height t \<in> {height (delete x t), height (delete x t) + 1}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. (hbt t \<Longrightarrow> hbt (delete x t)) &&& (hbt t \<Longrightarrow> height t \<in> {height (delete x t), height (delete x t) + 1})
[PROOF STEP]
proof (induct t rule: tree2_induct)
[PROOF STATE]
proof (state)
goal (4 subgoals):
1. hbt \<langle>\<rangle> \<Longrightarrow> hbt (delete x \<langle>\<rangle>)
2. hbt \<langle>\<rangle> \<Longrightarrow> height \<langle>\<rangle> \<in> {height (delete x \<langle>\<rangle>), height (delete x \<langle>\<rangle>) + 1}
3. \<And>x1 a b x3. \<lbrakk>hbt x1 \<Longrightarrow> hbt (delete x x1); hbt x1 \<Longrightarrow> height x1 \<in> {height (delete x x1), height (delete x x1) + 1}; hbt x3 \<Longrightarrow> hbt (delete x x3); hbt x3 \<Longrightarrow> height x3 \<in> {height (delete x x3), height (delete x x3) + 1}; hbt \<langle>x1, (a, b), x3\<rangle>\<rbrakk> \<Longrightarrow> hbt (delete x \<langle>x1, (a, b), x3\<rangle>)
4. \<And>x1 a b x3. \<lbrakk>hbt x1 \<Longrightarrow> hbt (delete x x1); hbt x1 \<Longrightarrow> height x1 \<in> {height (delete x x1), height (delete x x1) + 1}; hbt x3 \<Longrightarrow> hbt (delete x x3); hbt x3 \<Longrightarrow> height x3 \<in> {height (delete x x3), height (delete x x3) + 1}; hbt \<langle>x1, (a, b), x3\<rangle>\<rbrakk> \<Longrightarrow> height \<langle>x1, (a, b), x3\<rangle> \<in> {height (delete x \<langle>x1, (a, b), x3\<rangle>), height (delete x \<langle>x1, (a, b), x3\<rangle>) + 1}
[PROOF STEP]
case (Node l a n r)
[PROOF STATE]
proof (state)
this:
hbt l \<Longrightarrow> hbt (delete x l)
hbt l \<Longrightarrow> height l \<in> {height (delete x l), height (delete x l) + 1}
hbt r \<Longrightarrow> hbt (delete x r)
hbt r \<Longrightarrow> height r \<in> {height (delete x r), height (delete x r) + 1}
goal (4 subgoals):
1. hbt \<langle>\<rangle> \<Longrightarrow> hbt (delete x \<langle>\<rangle>)
2. hbt \<langle>\<rangle> \<Longrightarrow> height \<langle>\<rangle> \<in> {height (delete x \<langle>\<rangle>), height (delete x \<langle>\<rangle>) + 1}
3. \<And>x1 a b x3. \<lbrakk>hbt x1 \<Longrightarrow> hbt (delete x x1); hbt x1 \<Longrightarrow> height x1 \<in> {height (delete x x1), height (delete x x1) + 1}; hbt x3 \<Longrightarrow> hbt (delete x x3); hbt x3 \<Longrightarrow> height x3 \<in> {height (delete x x3), height (delete x x3) + 1}; hbt \<langle>x1, (a, b), x3\<rangle>\<rbrakk> \<Longrightarrow> hbt (delete x \<langle>x1, (a, b), x3\<rangle>)
4. \<And>x1 a b x3. \<lbrakk>hbt x1 \<Longrightarrow> hbt (delete x x1); hbt x1 \<Longrightarrow> height x1 \<in> {height (delete x x1), height (delete x x1) + 1}; hbt x3 \<Longrightarrow> hbt (delete x x3); hbt x3 \<Longrightarrow> height x3 \<in> {height (delete x x3), height (delete x x3) + 1}; hbt \<langle>x1, (a, b), x3\<rangle>\<rbrakk> \<Longrightarrow> height \<langle>x1, (a, b), x3\<rangle> \<in> {height (delete x \<langle>x1, (a, b), x3\<rangle>), height (delete x \<langle>x1, (a, b), x3\<rangle>) + 1}
[PROOF STEP]
case 1
[PROOF STATE]
proof (state)
this:
hbt \<langle>l, (a, n), r\<rangle>
goal (4 subgoals):
1. hbt \<langle>\<rangle> \<Longrightarrow> hbt (delete x \<langle>\<rangle>)
2. hbt \<langle>\<rangle> \<Longrightarrow> height \<langle>\<rangle> \<in> {height (delete x \<langle>\<rangle>), height (delete x \<langle>\<rangle>) + 1}
3. \<And>x1 a b x3. \<lbrakk>hbt x1 \<Longrightarrow> hbt (delete x x1); hbt x1 \<Longrightarrow> height x1 \<in> {height (delete x x1), height (delete x x1) + 1}; hbt x3 \<Longrightarrow> hbt (delete x x3); hbt x3 \<Longrightarrow> height x3 \<in> {height (delete x x3), height (delete x x3) + 1}; hbt \<langle>x1, (a, b), x3\<rangle>\<rbrakk> \<Longrightarrow> hbt (delete x \<langle>x1, (a, b), x3\<rangle>)
4. \<And>x1 a b x3. \<lbrakk>hbt x1 \<Longrightarrow> hbt (delete x x1); hbt x1 \<Longrightarrow> height x1 \<in> {height (delete x x1), height (delete x x1) + 1}; hbt x3 \<Longrightarrow> hbt (delete x x3); hbt x3 \<Longrightarrow> height x3 \<in> {height (delete x x3), height (delete x x3) + 1}; hbt \<langle>x1, (a, b), x3\<rangle>\<rbrakk> \<Longrightarrow> height \<langle>x1, (a, b), x3\<rangle> \<in> {height (delete x \<langle>x1, (a, b), x3\<rangle>), height (delete x \<langle>x1, (a, b), x3\<rangle>) + 1}
[PROOF STEP]
thus ?case
[PROOF STATE]
proof (prove)
using this:
hbt \<langle>l, (a, n), r\<rangle>
goal (1 subgoal):
1. hbt (delete x \<langle>l, (a, n), r\<rangle>)
[PROOF STEP]
using Node hbt_split_max[of l]
[PROOF STATE]
proof (prove)
using this:
hbt \<langle>l, (a, n), r\<rangle>
hbt l \<Longrightarrow> hbt (delete x l)
hbt l \<Longrightarrow> height l \<in> {height (delete x l), height (delete x l) + 1}
hbt r \<Longrightarrow> hbt (delete x r)
hbt r \<Longrightarrow> height r \<in> {height (delete x r), height (delete x r) + 1}
\<lbrakk>hbt l; l \<noteq> \<langle>\<rangle>\<rbrakk> \<Longrightarrow> hbt (fst (split_max l)) \<and> height l \<in> {height (fst (split_max l)), height (fst (split_max l)) + 1}
goal (1 subgoal):
1. hbt (delete x \<langle>l, (a, n), r\<rangle>)
[PROOF STEP]
by (auto intro!: hbt_balL hbt_balR split: prod.split)
[PROOF STATE]
proof (state)
this:
hbt (delete x \<langle>l, (a, n), r\<rangle>)
goal (3 subgoals):
1. hbt \<langle>\<rangle> \<Longrightarrow> hbt (delete x \<langle>\<rangle>)
2. hbt \<langle>\<rangle> \<Longrightarrow> height \<langle>\<rangle> \<in> {height (delete x \<langle>\<rangle>), height (delete x \<langle>\<rangle>) + 1}
3. \<And>x1 a b x3. \<lbrakk>hbt x1 \<Longrightarrow> hbt (delete x x1); hbt x1 \<Longrightarrow> height x1 \<in> {height (delete x x1), height (delete x x1) + 1}; hbt x3 \<Longrightarrow> hbt (delete x x3); hbt x3 \<Longrightarrow> height x3 \<in> {height (delete x x3), height (delete x x3) + 1}; hbt \<langle>x1, (a, b), x3\<rangle>\<rbrakk> \<Longrightarrow> height \<langle>x1, (a, b), x3\<rangle> \<in> {height (delete x \<langle>x1, (a, b), x3\<rangle>), height (delete x \<langle>x1, (a, b), x3\<rangle>) + 1}
[PROOF STEP]
case 2
[PROOF STATE]
proof (state)
this:
hbt \<langle>l, (a, n), r\<rangle>
goal (3 subgoals):
1. hbt \<langle>\<rangle> \<Longrightarrow> hbt (delete x \<langle>\<rangle>)
2. hbt \<langle>\<rangle> \<Longrightarrow> height \<langle>\<rangle> \<in> {height (delete x \<langle>\<rangle>), height (delete x \<langle>\<rangle>) + 1}
3. \<And>x1 a b x3. \<lbrakk>hbt x1 \<Longrightarrow> hbt (delete x x1); hbt x1 \<Longrightarrow> height x1 \<in> {height (delete x x1), height (delete x x1) + 1}; hbt x3 \<Longrightarrow> hbt (delete x x3); hbt x3 \<Longrightarrow> height x3 \<in> {height (delete x x3), height (delete x x3) + 1}; hbt \<langle>x1, (a, b), x3\<rangle>\<rbrakk> \<Longrightarrow> height \<langle>x1, (a, b), x3\<rangle> \<in> {height (delete x \<langle>x1, (a, b), x3\<rangle>), height (delete x \<langle>x1, (a, b), x3\<rangle>) + 1}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
proof(cases "x = a")
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. x = a \<Longrightarrow> height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
2. x \<noteq> a \<Longrightarrow> height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
x = a
goal (2 subgoals):
1. x = a \<Longrightarrow> height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
2. x \<noteq> a \<Longrightarrow> height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
x = a
goal (1 subgoal):
1. height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
using 2 hbt_split_max[of l]
[PROOF STATE]
proof (prove)
using this:
x = a
hbt \<langle>l, (a, n), r\<rangle>
\<lbrakk>hbt l; l \<noteq> \<langle>\<rangle>\<rbrakk> \<Longrightarrow> hbt (fst (split_max l)) \<and> height l \<in> {height (fst (split_max l)), height (fst (split_max l)) + 1}
goal (1 subgoal):
1. height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
by(auto simp: balR_def max_absorb2 split!: if_splits prod.split tree.split)
[PROOF STATE]
proof (state)
this:
height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
goal (1 subgoal):
1. x \<noteq> a \<Longrightarrow> height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. x \<noteq> a \<Longrightarrow> height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
x \<noteq> a
goal (1 subgoal):
1. x \<noteq> a \<Longrightarrow> height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
x \<noteq> a
goal (1 subgoal):
1. height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
using height_balL[of l "delete x r" a] height_balR[of "delete x l" r a] 2 Node
[PROOF STATE]
proof (prove)
using this:
x \<noteq> a
\<lbrakk>hbt l; hbt (delete x r); height l = height (delete x r) + m + 1\<rbrakk> \<Longrightarrow> height (balL l a (delete x r)) \<in> {height (delete x r) + m + 1, height (delete x r) + m + 2}
\<lbrakk>hbt (delete x l); hbt r; height r = height (delete x l) + m + 1\<rbrakk> \<Longrightarrow> height (balR (delete x l) a r) \<in> {height (delete x l) + m + 1, height (delete x l) + m + 2}
hbt \<langle>l, (a, n), r\<rangle>
hbt l \<Longrightarrow> hbt (delete x l)
hbt l \<Longrightarrow> height l \<in> {height (delete x l), height (delete x l) + 1}
hbt r \<Longrightarrow> hbt (delete x r)
hbt r \<Longrightarrow> height r \<in> {height (delete x r), height (delete x r) + 1}
goal (1 subgoal):
1. height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
[PROOF STEP]
by(auto simp: balL_def balR_def split!: if_split)
[PROOF STATE]
proof (state)
this:
height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
height \<langle>l, (a, n), r\<rangle> \<in> {height (delete x \<langle>l, (a, n), r\<rangle>), height (delete x \<langle>l, (a, n), r\<rangle>) + 1}
goal (2 subgoals):
1. hbt \<langle>\<rangle> \<Longrightarrow> hbt (delete x \<langle>\<rangle>)
2. hbt \<langle>\<rangle> \<Longrightarrow> height \<langle>\<rangle> \<in> {height (delete x \<langle>\<rangle>), height (delete x \<langle>\<rangle>) + 1}
[PROOF STEP]
qed simp_all |
Subsets and Splits