text
stringlengths 0
3.34M
|
---|
lemma homeomorphism_ident: "homeomorphism T T (\<lambda>a. a) (\<lambda>a. a)" |
class(bat,mammal).
class(dog,mammal).
class(bat,mammal).
class(bat,mammal).
class(dog,mammal).
class(platypus,mammal).
class(eagle,nmammal).
class(eagle,nmammal).
class(ostrich,nmammal).
class(shark,nmammal).
class(crocodile,nmammal).
class(shark,nmammal).
class(penguin,nmammal).
class(shark,nmammal).
class(crocodile,nmammal).
class(crocodile,nmammal).
class(shark,nmammal).
class(snake,nmammal).
class(t_rex,nmammal).
class(crocodile,nmammal).
|
/* gsl_histogram2d_copy.c
* Copyright (C) 2000 Simone Piccardi
*
* This library 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 2 of the
* License, or (at your option) any later version.
*
* This program 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 library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/***************************************************************
*
* File gsl_histogram2d_copy.c:
* Routine to copy a 2D histogram.
* Need GSL library and header.
*
* Author: S. Piccardi
* Jan. 2000
*
***************************************************************/
#include <config.h>
#include <stdlib.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_histogram2d.h>
/*
* gsl_histogram2d_copy:
* copy the contents of an histogram into another
*/
int
gsl_histogram2d_memcpy (gsl_histogram2d * dest, const gsl_histogram2d * src)
{
size_t nx = src->nx;
size_t ny = src->ny;
size_t i;
if (dest->nx != src->nx || dest->ny != src->ny)
{
GSL_ERROR ("histograms have different sizes, cannot copy",
GSL_EINVAL);
}
for (i = 0; i <= nx; i++)
{
dest->xrange[i] = src->xrange[i];
}
for (i = 0; i <= ny; i++)
{
dest->yrange[i] = src->yrange[i];
}
for (i = 0; i < nx * ny; i++)
{
dest->bin[i] = src->bin[i];
}
return GSL_SUCCESS;
}
/*
* gsl_histogram2d_duplicate:
* duplicate an histogram creating
* an identical new one
*/
gsl_histogram2d *
gsl_histogram2d_clone (const gsl_histogram2d * src)
{
size_t nx = src->nx;
size_t ny = src->ny;
size_t i;
gsl_histogram2d *h;
h = gsl_histogram2d_calloc_range (nx, ny, src->xrange, src->yrange);
if (h == 0)
{
GSL_ERROR_VAL ("failed to allocate space for histogram struct",
GSL_ENOMEM, 0);
}
for (i = 0; i < nx * ny; i++)
{
h->bin[i] = src->bin[i];
}
return h;
}
|
{-# OPTIONS --rewriting #-}
--{-# OPTIONS -v rewriting:100 #-}
postulate
_↦_ : ∀ {i} {A : Set i} → A → A → Set i
{-# BUILTIN REWRITE _↦_ #-}
data _==_ {i} {A : Set i} (a : A) : A → Set i where
idp : a == a
ap : ∀ i j (A : Set i) (B : Set j) (f : A → B) (x y : A)
→ (x == y → f x == f y)
ap _ _ _ _ f _ ._ idp = idp
postulate
ap∘-rewr : ∀ {i j k} {A : Set i} {B : Set j} {C : Set k} (g : B → C) (f : A → B)
{x y : A} (p : x == y) →
ap j k B C g (f x) (f y) (ap i j A B f x y p) ↦ ap i k A C (λ x → g (f x)) x y p
{-# REWRITE ap∘-rewr #-}
-- This one works, rewriting the RHS to the LHS using the previous rewrite rule as expected
{-ap∘ : ∀ {i j k} {A : Set i} {B : Set j} {C : Set k} (g : B → C) (f : A → B)
{x y : A} (p : x == y) →
ap (λ x → g (f x)) p == ap g (ap f p)
ap∘ g f p = idp
-}
postulate P : ∀ i (A : Set i) (x y : A) (p : x == y) → Set
-- This one doesn’t work, although it should just have to rewrite [P (ap g (ap f p))] to [P (ap (λ x → g (f x)) p)]
test : ∀ {i j k} {A : Set i} {B : Set j} {C : Set k} (g : B → C) (f : A → B)
{x y : A} (p : x == y)
→ P k C (g (f x)) (g (f y)) (ap i k A C (λ x → g (f x)) x y p) → P k C (g (f x)) (g (f y)) (ap j k B C g (f x) (f y) (ap i j A B f x y p))
test g f p s = s
{-
.i != .j of type .Agda.Primitive.Level
when checking that the expression s has type P (ap g (ap f p))
-}
|
theory UniSWP_Common
imports Phi_Semantics.PhiSem_Int_ArbiPrec HOL.Real
Phi_Semantics.PhiSem_Real_Abst
Phi_Semantics.PhiSem_CF_Routine
begin
no_notation inter (infixl "Int" 70)
and union (infixl "Un" 65)
and Nats ("\<nat>")
and Ints ("\<int>")
type_synonym token = int
type_synonym fee = real
type_synonym address = int
type_synonym tick = int
type_synonym growth = \<open>fee \<times> fee \<times> int \<times> real \<times> int\<close>
type_synonym liquidity = \<open>tick \<Rightarrow> int\<close>
type_synonym growths = \<open>tick \<Rightarrow> growth\<close>
setup \<open>Sign.mandatory_path "growth"\<close>
definition \<open>fee0 (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> a)\<close>
definition \<open>map_fee0 f (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> ((f a,b,c,d,e) :: growth))\<close>
definition \<open>fee1 (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> b)\<close>
definition \<open>map_fee1 f (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> ((a,f b,c,d,e) :: growth))\<close>
lemma [simp]: \<open>growth.fee1 (a,b,c,d,e) = b\<close> unfolding growth.fee1_def by simp
lemma [simp]: \<open>growth.map_fee1 f (a,b,c,d,e) = (a,f b,c,d,e)\<close> unfolding growth.map_fee1_def by simp
definition \<open>tickCumulative (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> c)\<close>
definition \<open>map_tickCumulative f (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> ((a,b,f c,d,e) :: growth))\<close>
lemma [simp]: \<open>growth.tickCumulative (a,b,c,d,e) = c\<close> unfolding growth.tickCumulative_def by simp
lemma [simp]: \<open>growth.map_tickCumulative f (a,b,c,d,e) = (a,b,f c,d,e)\<close> unfolding growth.map_tickCumulative_def by simp
definition \<open>secondsPerLiquidity (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> d)\<close>
definition \<open>map_secondsPerLiquidity f (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> ((a,b,c,f d,e) :: growth))\<close>
lemma [simp]: \<open>growth.secondsPerLiquidity (a,b,c,d,e) = d\<close> unfolding growth.secondsPerLiquidity_def by simp
lemma [simp]: \<open>growth.map_secondsPerLiquidity f (a,b,c,d,e) = (a,b,c,f d,e)\<close> unfolding growth.map_secondsPerLiquidity_def by simp
definition \<open>seconds (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> e)\<close>
definition \<open>map_seconds f (x::growth) = (case x of (a,b,c,d,e) \<Rightarrow> ((a,b,c,d,f e) :: growth))\<close>
lemma [simp]: \<open>growth.seconds (a,b,c,d,e) = e\<close> unfolding growth.seconds_def by simp
lemma [simp]: \<open>growth.map_seconds f (a,b,c,d,e) = (a,b,c,d,f e)\<close> unfolding growth.map_seconds_def by simp
setup \<open>Sign.parent_path\<close>
lemma fee0_plus_homo[simp]:
\<open>growth.fee0 (a + b) = growth.fee0 a + growth.fee0 b\<close>
by (cases a; cases b; simp)
lemma fee0_sub_homo[simp]:
\<open>growth.fee0 (a - b) = growth.fee0 a - growth.fee0 b\<close>
by (cases a; cases b; simp)
lemma fee0_sum:
\<open>growth.fee0 (sum f S) = sum (growth.fee0 o f) S\<close>
by (metis add.right_neutral add_diff_cancel_left' fee0_plus_homo sum_comp_morphism)
lemma fee1_plus_homo[simp]:
\<open>growth.fee1 (a + b) = growth.fee1 a + growth.fee1 b\<close>
by (cases a; cases b; simp)
lemma fee1_sub_homo[simp]:
\<open>growth.fee1 (a - b) = growth.fee1 a - growth.fee1 b\<close>
by (cases a; cases b; simp)
lemma fee1_sum:
\<open>growth.fee1 (sum f S) = sum (growth.fee1 o f) S\<close>
by (metis add.right_neutral add_diff_cancel_left' fee1_plus_homo sum_comp_morphism)
datatype apos_info \<comment> \<open>abstract pos info\<close> = apos_info
(liquidity: token)
(revenue0: fee) \<comment> \<open>All time revenue, no matter whether is updated\<close>
(revenue1: fee)
(withdrawn0: fee) \<comment> \<open>the amount that the user has withdrawn\<close>
(withdrawn1: fee)
hide_const (open) liquidity revenue0 revenue1 withdrawn0 withdrawn1
text \<open>The implementation records a settled revenue and the timestamp of the last settling.
It will not calculate the actual revenue in time until an explicit update operation is invoked.
Here, we specify the system using the in-time actual revenue, intuitively reflecting the system behavior.
\<close>
definition Address :: \<open>(VAL, address) \<phi>\<close>
where [\<phi>defs]: \<open>Address a = (a \<Ztypecolon> \<int>)\<close>
lemma [\<phi>reason 1200]:
\<open> \<t>\<h>\<r>\<e>\<s>\<h>\<o>\<l>\<d> 1
\<Longrightarrow> \<p>\<r>\<e>\<m>\<i>\<s>\<e> i = j
\<Longrightarrow> i \<Ztypecolon> \<int> \<i>\<m>\<p>\<l>\<i>\<e>\<s> j \<Ztypecolon> Address\<close>
\<medium_left_bracket> construct\<phi> \<open>i \<Ztypecolon> Address\<close> \<medium_right_bracket>. .
lemma [\<phi>reason 1200]:
\<open> i \<Ztypecolon> \<int> \<i>\<m>\<p>\<l>\<i>\<e>\<s> i \<Ztypecolon> Address @action to Tick\<close> \<medium_left_bracket> \<medium_right_bracket>. .
lemma [\<phi>reason 1200]:
\<open> \<t>\<h>\<r>\<e>\<s>\<h>\<o>\<l>\<d> 1
\<Longrightarrow> \<p>\<r>\<e>\<m>\<i>\<s>\<e> i = j
\<Longrightarrow> i \<Ztypecolon> Address \<i>\<m>\<p>\<l>\<i>\<e>\<s> j \<Ztypecolon> \<int> \<close>
\<medium_left_bracket> destruct\<phi> _ \<medium_right_bracket>. .
lemma [\<phi>reason 1200, \<phi>inhabitance_rule]: \<open>i \<Ztypecolon> Address \<i>\<m>\<p>\<l>\<i>\<e>\<s> i \<Ztypecolon> \<int> @action to \<int>\<close> \<medium_left_bracket> \<medium_right_bracket>. .
lemma [\<phi>reason 1000]: "\<phi>Equal Address (\<lambda>x y. True) (=)" \<medium_left_bracket> to \<int> \<medium_right_bracket>. .
lemma [\<phi>reason 1000]: \<open>\<phi>SemType (x \<Ztypecolon> Address) aint\<close> \<medium_left_bracket> to \<int> \<medium_right_bracket>. .
lemma [\<phi>reason 1000]: "\<phi>Zero aint Address 0" \<medium_left_bracket> \<open>0 \<Ztypecolon> \<int>\<close> \<medium_right_bracket>. .
subsection \<open>Tick\<close>
definition \<open>MIN_TICK = (-887272::int)\<close>
definition \<open>MAX_TICK = ( 887272::int)\<close>
lemma MIN_TICK_LT_MAX_TICK[simp]:
\<open>MIN_TICK < MAX_TICK\<close>
unfolding MIN_TICK_def MAX_TICK_def by simp
lemma MM_TICK_LT_0[simp]:
\<open>MIN_TICK < 0\<close> \<open>0 < MAX_TICK\<close>
unfolding MIN_TICK_def MAX_TICK_def by simp_all
lemma MM_TICK_LE_0[simp]:
\<open>MIN_TICK \<le> 0\<close> \<open>0 \<le> MAX_TICK\<close>
unfolding MIN_TICK_def MAX_TICK_def by simp_all
definition Tick :: \<open>(VAL, tick) \<phi>\<close> where [\<phi>defs]: \<open>Tick i = (i \<Ztypecolon> \<int> \<s>\<u>\<b>\<j> i \<in> {MIN_TICK..MAX_TICK})\<close>
lemma [\<phi>reason 1200]:
\<open> \<t>\<h>\<r>\<e>\<s>\<h>\<o>\<l>\<d> 1
\<Longrightarrow> \<p>\<r>\<e>\<m>\<i>\<s>\<e> i = j \<and> j \<in> {MIN_TICK..MAX_TICK}
\<Longrightarrow> i \<Ztypecolon> \<int> \<i>\<m>\<p>\<l>\<i>\<e>\<s> j \<Ztypecolon> Tick\<close>
\<medium_left_bracket> construct\<phi> \<open>i \<Ztypecolon> Tick\<close> \<medium_right_bracket>. .
lemma [\<phi>reason 1200]:
\<open> \<p>\<r>\<e>\<m>\<i>\<s>\<e> i \<in> {MIN_TICK..MAX_TICK}
\<Longrightarrow> i \<Ztypecolon> \<int> \<i>\<m>\<p>\<l>\<i>\<e>\<s> i \<Ztypecolon> Tick @action to Tick\<close> \<medium_left_bracket> \<medium_right_bracket>. .
lemma [\<phi>reason 1200]:
\<open> \<t>\<h>\<r>\<e>\<s>\<h>\<o>\<l>\<d> 1
\<Longrightarrow> \<p>\<r>\<e>\<m>\<i>\<s>\<e> i = j
\<Longrightarrow> i \<Ztypecolon> Tick \<i>\<m>\<p>\<l>\<i>\<e>\<s> j \<Ztypecolon> \<int> \<a>\<n>\<d> i \<in> {MIN_TICK..MAX_TICK}\<close>
\<medium_left_bracket> destruct\<phi> _ \<medium_right_bracket>. .
lemma [\<phi>reason 1200, \<phi>inhabitance_rule]:
\<open>i \<Ztypecolon> Tick \<i>\<m>\<p>\<l>\<i>\<e>\<s> i \<Ztypecolon> \<int> \<a>\<n>\<d> i \<in> {MIN_TICK..MAX_TICK} @action to \<int>\<close> \<medium_left_bracket> \<medium_right_bracket>. .
lemma [\<phi>reason 1000]: "\<phi>Equal Tick (\<lambda>x y. True) (=)" \<medium_left_bracket> to \<int> \<medium_right_bracket>. .
lemma [\<phi>reason 1000]: \<open>\<phi>SemType (x \<Ztypecolon> Tick) aint\<close> \<medium_left_bracket> to \<int> \<medium_right_bracket>. .
lemma [\<phi>reason 1000]: "\<phi>Zero aint Tick 0" \<medium_left_bracket> \<open>0 \<Ztypecolon> \<int>\<close> \<medium_right_bracket>. .
end |
[STATEMENT]
lemma find_first_prefix:
assumes "find_first x xs = Some i" "i < n"
shows "find_first x (take n xs) = Some i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. find_first x (take n xs) = Some i
[PROOF STEP]
proof (rule find_first_first)
[PROOF STATE]
proof (state)
goal (3 subgoals):
1. i < length (take n xs)
2. x \<notin> set (take i (take n xs))
3. take n xs ! i = x
[PROOF STEP]
show "i < length (take n xs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. i < length (take n xs)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
find_first x xs = Some i
i < n
goal (1 subgoal):
1. i < length (take n xs)
[PROOF STEP]
by (simp add: find_first_correct)
[PROOF STATE]
proof (state)
this:
i < length (take n xs)
goal (2 subgoals):
1. x \<notin> set (take i (take n xs))
2. take n xs ! i = x
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. x \<notin> set (take i (take n xs))
2. take n xs ! i = x
[PROOF STEP]
have "x \<notin> set (take i xs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. x \<notin> set (take i xs)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
find_first x xs = Some i
i < n
goal (1 subgoal):
1. x \<notin> set (take i xs)
[PROOF STEP]
by (simp add: find_first_correct)
[PROOF STATE]
proof (state)
this:
x \<notin> set (take i xs)
goal (2 subgoals):
1. x \<notin> set (take i (take n xs))
2. take n xs ! i = x
[PROOF STEP]
with assms
[PROOF STATE]
proof (chain)
picking this:
find_first x xs = Some i
i < n
x \<notin> set (take i xs)
[PROOF STEP]
show "x \<notin> set (take i (take n xs))"
[PROOF STATE]
proof (prove)
using this:
find_first x xs = Some i
i < n
x \<notin> set (take i xs)
goal (1 subgoal):
1. x \<notin> set (take i (take n xs))
[PROOF STEP]
by (simp add: min.absorb1)
[PROOF STATE]
proof (state)
this:
x \<notin> set (take i (take n xs))
goal (1 subgoal):
1. take n xs ! i = x
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. take n xs ! i = x
[PROOF STEP]
show "take n xs ! i = x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. take n xs ! i = x
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
find_first x xs = Some i
i < n
goal (1 subgoal):
1. take n xs ! i = x
[PROOF STEP]
by (simp add: find_first_correct)
[PROOF STATE]
proof (state)
this:
take n xs ! i = x
goal:
No subgoals!
[PROOF STEP]
qed |
The Audi TT RS Coupé has never been this masculine. The completely redrawn front end and the striking rear end give it a dynamic appearance.
The quattro logo in a matt titanium-look is positioned in the lower section of the gloss black grill with its matt black Singleframe. The lateral air inlets, which have been enlarged once again, are each divided by vertical strips on the inside and outside. For cooling purposes there are additional radiators located behind the typical RS honeycomb grill. The lateral air inlets that extend almost all the way to the front wheel wells make the new TT RS appear extremely wide.
"The new TT RS is in absolute peak form," says Michael-Julius Renz, CEO of Audi Sport GmbH. "Like a well-trained athlete, it showcases even more prominently how much power lies beneath its muscular outer skin."
Five-cylinder, 294 kW (400 metric horsepower) output, 480 Nm (354.0 lb-ft) of torque, quattro all-wheel drive - the Audi TT RS impresses with inner values and offers an outstanding driving performance. The Coupé sprints from 0 to 100 km/h (0 to 62.1 mph) in only 3.7 seconds. Musical accompaniment is provided by the typical five-cylinder sound: 1-2-4-5-3. Due to this ignition sequence, ignition alternates between adjacent cylinders and those far apart from one another. This unique rhythm is music to the ears of many horsepower purists.
Last year, Audi Sport received the sought-after International Engine of the Year Award for the 2.5 TFSI engine for the ninth consecutive time. The turbo engine draws its power from an engine displacement of 2,480 cm3. The engine’s maximum torque of 480 Nm (354.0 lb-ft) is available between 1,950 and 5,850 rpm. The top speed is regulated at 250 km/h (155.3 mph) or an optional 280 km/h (174.0 mph). |
lemma poly_mod_minus_right [simp]: "x mod (- y) = x mod y" for x y :: "'a::field poly" |
/-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
! This file was ported from Lean 3 source module category_theory.idempotents.functor_extension
! leanprover-community/mathlib commit 5f68029a863bdf76029fa0f7a519e6163c14152e
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.CategoryTheory.Idempotents.Karoubi
/-!
# Extension of functors to the idempotent completion
In this file, we construct an extension `functor_extension₁`
of functors `C ⥤ karoubi D` to functors `karoubi C ⥤ karoubi D`. This results in an
equivalence `karoubi_universal₁ C D : (C ⥤ karoubi D) ≌ (karoubi C ⥤ karoubi D)`.
We also construct an extension `functor_extension₂` of functors
`(C ⥤ D) ⥤ (karoubi C ⥤ karoubi D)`. Moreover,
when `D` is idempotent complete, we get equivalences
`karoubi_universal₂ C D : C ⥤ D ≌ karoubi C ⥤ karoubi D`
and `karoubi_universal C D : C ⥤ D ≌ karoubi C ⥤ D`.
We occasionally state and use equalities of functors because it is
sometimes convenient to use rewrites when proving properties of
functors obtained using the constructions in this file. Users are
encouraged to use the corresponding natural isomorphism
whenever possible.
-/
open CategoryTheory.Category
open CategoryTheory.Idempotents.Karoubi
namespace CategoryTheory
namespace Idempotents
variable {C D E : Type _} [Category C] [Category D] [Category E]
/-- A natural transformation between functors `karoubi C ⥤ D` is determined
by its value on objects coming from `C`. -/
theorem nat_trans_eq {F G : Karoubi C ⥤ D} (φ : F ⟶ G) (P : Karoubi C) :
φ.app P = F.map (decompIdI P) ≫ φ.app P.pt ≫ G.map (decompIdP P) :=
by
rw [← φ.naturality, ← assoc, ← F.map_comp]
conv =>
lhs
rw [← id_comp (φ.app P), ← F.map_id]
congr
apply decomp_id
#align category_theory.idempotents.nat_trans_eq CategoryTheory.Idempotents.nat_trans_eq
namespace FunctorExtension₁
/-- The canonical extension of a functor `C ⥤ karoubi D` to a functor
`karoubi C ⥤ karoubi D` -/
@[simps]
def obj (F : C ⥤ Karoubi D) : Karoubi C ⥤ Karoubi D
where
obj P :=
⟨(F.obj P.pt).pt, (F.map P.p).f, by simpa only [F.map_comp, hom_ext] using F.congr_map P.idem⟩
map P Q f := ⟨(F.map f.f).f, by simpa only [F.map_comp, hom_ext] using F.congr_map f.comm⟩
#align category_theory.idempotents.functor_extension₁.obj CategoryTheory.Idempotents.FunctorExtension₁.obj
/-- Extension of a natural transformation `φ` between functors
`C ⥤ karoubi D` to a natural transformation between the
extension of these functors to `karoubi C ⥤ karoubi D` -/
@[simps]
def map {F G : C ⥤ Karoubi D} (φ : F ⟶ G) : obj F ⟶ obj G
where
app P :=
{ f := (F.map P.p).f ≫ (φ.app P.pt).f
comm := by
have h := φ.naturality P.p
have h' := F.congr_map P.idem
simp only [hom_ext, karoubi.comp_f, F.map_comp] at h h'
simp only [obj_obj_p, assoc, ← h]
slice_rhs 1 3 => rw [h', h'] }
naturality' P Q f := by
ext
dsimp [obj]
have h := φ.naturality f.f
have h' := F.congr_map (comp_p f)
have h'' := F.congr_map (p_comp f)
simp only [hom_ext, functor.map_comp, comp_f] at h h' h''⊢
slice_rhs 2 3 => rw [← h]
slice_lhs 1 2 => rw [h']
slice_rhs 1 2 => rw [h'']
#align category_theory.idempotents.functor_extension₁.map CategoryTheory.Idempotents.FunctorExtension₁.map
end FunctorExtension₁
variable (C D E)
/-- The canonical functor `(C ⥤ karoubi D) ⥤ (karoubi C ⥤ karoubi D)` -/
@[simps]
def functorExtension₁ : (C ⥤ Karoubi D) ⥤ Karoubi C ⥤ Karoubi D
where
obj := FunctorExtension₁.obj
map F G := FunctorExtension₁.map
map_id' F := by
ext P
exact comp_p (F.map P.p)
map_comp' F G H φ φ' := by
ext P
simp only [comp_f, functor_extension₁.map_app_f, nat_trans.comp_app, assoc]
have h := φ.naturality P.p
have h' := F.congr_map P.idem
simp only [hom_ext, comp_f, F.map_comp] at h h'
slice_rhs 2 3 => rw [← h]
slice_rhs 1 2 => rw [h']
simp only [assoc]
#align category_theory.idempotents.functor_extension₁ CategoryTheory.Idempotents.functorExtension₁
theorem functorExtension₁_comp_whiskeringLeft_toKaroubi :
functorExtension₁ C D ⋙ (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) = 𝟭 _ :=
by
refine' Functor.ext _ _
· intro F
refine' Functor.ext _ _
· intro X
ext
· dsimp
rw [id_comp, comp_id, F.map_id, id_eq]
· rfl
· intro X Y f
ext
dsimp
simp only [comp_id, eq_to_hom_f, eq_to_hom_refl, comp_p, functor_extension₁.obj_obj_p,
to_karoubi_obj_p, comp_f]
dsimp
simp only [Functor.map_id, id_eq, p_comp]
· intro F G φ
ext X
dsimp
simp only [eq_to_hom_app, F.map_id, comp_f, eq_to_hom_f, id_eq, p_comp, eq_to_hom_refl, comp_id,
comp_p, functor_extension₁.obj_obj_p, to_karoubi_obj_p, F.map_id X]
#align category_theory.idempotents.functor_extension₁_comp_whiskering_left_to_karoubi CategoryTheory.Idempotents.functorExtension₁_comp_whiskeringLeft_toKaroubi
/-- The natural isomorphism expressing that functors `karoubi C ⥤ karoubi D` obtained
using `functor_extension₁` actually extends the original functors `C ⥤ karoubi D`. -/
@[simps]
def functorExtension₁CompWhiskeringLeftToKaroubiIso :
functorExtension₁ C D ⋙ (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) ≅ 𝟭 _ :=
eqToIso (functorExtension₁_comp_whiskeringLeft_toKaroubi C D)
#align category_theory.idempotents.functor_extension₁_comp_whiskering_left_to_karoubi_iso CategoryTheory.Idempotents.functorExtension₁CompWhiskeringLeftToKaroubiIso
/-- The counit isomorphism of the equivalence `(C ⥤ karoubi D) ≌ (karoubi C ⥤ karoubi D)`. -/
@[simps]
def KaroubiUniversal₁.counitIso :
(whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) ⋙ functorExtension₁ C D ≅ 𝟭 _ :=
NatIso.ofComponents
(fun G =>
{ Hom :=
{ app := fun P =>
{ f := (G.map (decompIdP P)).f
comm := by
simpa only [hom_ext, G.map_comp, G.map_id] using
G.congr_map
(show P.decomp_id_p = (to_karoubi C).map P.p ≫ P.decomp_id_p ≫ 𝟙 _ by simp) }
naturality' := fun P Q f => by
simpa only [hom_ext, G.map_comp] using (G.congr_map (decomp_id_p_naturality f)).symm }
inv :=
{ app := fun P =>
{ f := (G.map (decompIdI P)).f
comm := by
simpa only [hom_ext, G.map_comp, G.map_id] using
G.congr_map
(show P.decomp_id_i = 𝟙 _ ≫ P.decomp_id_i ≫ (to_karoubi C).map P.p by simp) }
naturality' := fun P Q f => by
simpa only [hom_ext, G.map_comp] using G.congr_map (decomp_id_i_naturality f) }
hom_inv_id' := by
ext P
simpa only [hom_ext, G.map_comp, G.map_id] using G.congr_map P.decomp_p.symm
inv_hom_id' := by
ext P
simpa only [hom_ext, G.map_comp, G.map_id] using G.congr_map P.decomp_id.symm })
fun G₁ G₂ φ => by
ext P
dsimp
simpa only [nat_trans_eq φ P, comp_f, functor_extension₁.map_app_f, functor.comp_map,
whisker_left_app, assoc, P.decomp_p, G₁.map_comp]
#align category_theory.idempotents.karoubi_universal₁.counit_iso CategoryTheory.Idempotents.KaroubiUniversal₁.counitIso
/-- The equivalence of categories `(C ⥤ karoubi D) ≌ (karoubi C ⥤ karoubi D)`. -/
@[simps]
def karoubiUniversal₁ : C ⥤ Karoubi D ≌ Karoubi C ⥤ Karoubi D
where
Functor := functorExtension₁ C D
inverse := (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C)
unitIso := (functorExtension₁CompWhiskeringLeftToKaroubiIso C D).symm
counitIso := KaroubiUniversal₁.counitIso C D
functor_unitIso_comp' F := by
ext P
dsimp [functor_extension₁.map, karoubi_universal₁.counit_iso]
simpa only [comp_f, eq_to_hom_app, eq_to_hom_f, eq_to_hom_refl, comp_id, hom_ext, F.map_comp,
comp_p] using F.congr_map P.idem
#align category_theory.idempotents.karoubi_universal₁ CategoryTheory.Idempotents.karoubiUniversal₁
theorem functorExtension₁_comp (F : C ⥤ Karoubi D) (G : D ⥤ Karoubi E) :
(functorExtension₁ C E).obj (F ⋙ (functorExtension₁ D E).obj G) =
(functorExtension₁ C D).obj F ⋙ (functorExtension₁ D E).obj G :=
Functor.ext (by tidy) fun X Y f => by
dsimp
simpa only [id_comp, comp_id]
#align category_theory.idempotents.functor_extension₁_comp CategoryTheory.Idempotents.functorExtension₁_comp
/-- The canonical functor `(C ⥤ D) ⥤ (karoubi C ⥤ karoubi D)` -/
@[simps]
def functorExtension₂ : (C ⥤ D) ⥤ Karoubi C ⥤ Karoubi D :=
(whiskeringRight C D (Karoubi D)).obj (toKaroubi D) ⋙ functorExtension₁ C D
#align category_theory.idempotents.functor_extension₂ CategoryTheory.Idempotents.functorExtension₂
theorem functorExtension₂_comp_whiskeringLeft_toKaroubi :
functorExtension₂ C D ⋙ (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) =
(whiskeringRight C D (Karoubi D)).obj (toKaroubi D) :=
by
simp only [functor_extension₂, functor.assoc, functor_extension₁_comp_whiskering_left_to_karoubi,
functor.comp_id]
#align category_theory.idempotents.functor_extension₂_comp_whiskering_left_to_karoubi CategoryTheory.Idempotents.functorExtension₂_comp_whiskeringLeft_toKaroubi
/-- The natural isomorphism expressing that functors `karoubi C ⥤ karoubi D` obtained
using `functor_extension₂` actually extends the original functors `C ⥤ D`. -/
@[simps]
def functorExtension₂CompWhiskeringLeftToKaroubiIso :
functorExtension₂ C D ⋙ (whiskeringLeft C (Karoubi C) (Karoubi D)).obj (toKaroubi C) ≅
(whiskeringRight C D (Karoubi D)).obj (toKaroubi D) :=
eqToIso (functorExtension₂_comp_whiskeringLeft_toKaroubi C D)
#align category_theory.idempotents.functor_extension₂_comp_whiskering_left_to_karoubi_iso CategoryTheory.Idempotents.functorExtension₂CompWhiskeringLeftToKaroubiIso
section IsIdempotentComplete
variable [IsIdempotentComplete D]
noncomputable instance : IsEquivalence (toKaroubi D) :=
toKaroubiIsEquivalence D
/-- The equivalence of categories `(C ⥤ D) ≌ (karoubi C ⥤ karoubi D)` when `D`
is idempotent complete. -/
@[simps]
noncomputable def karoubiUniversal₂ : C ⥤ D ≌ Karoubi C ⥤ Karoubi D :=
(Equivalence.congrRight (toKaroubi D).asEquivalence).trans (karoubiUniversal₁ C D)
#align category_theory.idempotents.karoubi_universal₂ CategoryTheory.Idempotents.karoubiUniversal₂
theorem karoubiUniversal₂_functor_eq : (karoubiUniversal₂ C D).Functor = functorExtension₂ C D :=
rfl
#align category_theory.idempotents.karoubi_universal₂_functor_eq CategoryTheory.Idempotents.karoubiUniversal₂_functor_eq
noncomputable instance : IsEquivalence (functorExtension₂ C D) :=
by
rw [← karoubi_universal₂_functor_eq]
infer_instance
/-- The extension of functors functor `(C ⥤ D) ⥤ (karoubi C ⥤ D)`
when `D` is idempotent compltete. -/
@[simps]
noncomputable def functorExtension : (C ⥤ D) ⥤ Karoubi C ⥤ D :=
functorExtension₂ C D ⋙
(whiskeringRight (Karoubi C) (Karoubi D) D).obj (toKaroubiIsEquivalence D).inverse
#align category_theory.idempotents.functor_extension CategoryTheory.Idempotents.functorExtension
/-- The equivalence `(C ⥤ D) ≌ (karoubi C ⥤ D)` when `D` is idempotent complete. -/
@[simps]
noncomputable def karoubiUniversal : C ⥤ D ≌ Karoubi C ⥤ D :=
(karoubiUniversal₂ C D).trans (Equivalence.congrRight (toKaroubi D).asEquivalence.symm)
#align category_theory.idempotents.karoubi_universal CategoryTheory.Idempotents.karoubiUniversal
theorem karoubiUniversal_functor_eq : (karoubiUniversal C D).Functor = functorExtension C D :=
rfl
#align category_theory.idempotents.karoubi_universal_functor_eq CategoryTheory.Idempotents.karoubiUniversal_functor_eq
noncomputable instance : IsEquivalence (functorExtension C D) :=
by
rw [← karoubi_universal_functor_eq]
infer_instance
noncomputable instance : IsEquivalence ((whiskeringLeft C (Karoubi C) D).obj (toKaroubi C)) :=
IsEquivalence.cancelCompRight _
((whiskeringRight C _ _).obj (toKaroubi D) ⋙ (whiskeringRight C _ _).obj (toKaroubi D).inv)
(IsEquivalence.ofEquivalence
(@Equivalence.congrRight _ _ _ _ C _
((toKaroubi D).asEquivalence.trans (toKaroubi D).asEquivalence.symm)))
(by
change is_equivalence (karoubi_universal C D).inverse
infer_instance)
variable {C D}
theorem whiskeringLeft_obj_preimage_app {F G : Karoubi C ⥤ D}
(τ : toKaroubi _ ⋙ F ⟶ toKaroubi _ ⋙ G) (P : Karoubi C) :
(((whiskeringLeft _ _ _).obj (toKaroubi _)).preimage τ).app P =
F.map P.decompIdI ≫ τ.app P.pt ≫ G.map P.decompIdP :=
by
rw [nat_trans_eq]
congr 2
exact congr_app (((whiskering_left _ _ _).obj (to_karoubi _)).image_preimage τ) P.X
#align category_theory.idempotents.whiskering_left_obj_preimage_app CategoryTheory.Idempotents.whiskeringLeft_obj_preimage_app
end IsIdempotentComplete
end Idempotents
end CategoryTheory
|
# --------------
#Importing header files
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#Reading the file
data=pd.read_csv(path)
#Code starts here
# Step 1
#Reading the file
loan_status=data["Loan_Status"].value_counts()
print(loan_status)
loan_status.plot(kind='bar')
#Creating a new variable to store the value counts
#Plotting bar plot
# Step 2
#Plotting an unstacked bar plot
property_and_loan=data.groupby(['Property_Area','Loan_Status']).size().unstack()
property_and_loan.plot(kind='bar',stacked=True)
plt.xlabel('Property Area')
plt.xticks(rotation=45)
plt.ylabel('Loan Status')
print(property_and_loan['N'][1])
#Changing the x-axis label
#Changing the y-axis label
#Rotating the ticks of X-axis
# Step 3
#Plotting a stacked bar plot
education_and_loan=data.groupby(['Education','Loan_Status']).size().unstack()
education_and_loan.plot(kind='bar',stacked=True)
plt.xlabel('Education Status')
plt.ylabel('Loan Status')
plt.yticks(rotation=45)
#Changing the x-axis label
#Changing the y-axis label
#Rotating the ticks of X-axis
# Step 4
#Subsetting the dataframe based on 'Education' column
graduate=data[data['Education']=='Graduate']
not_graduate=data[data['Education']=='Not Graduate']
graduate['LoanAmount'].plot(kind='density',label="have fuck")
not_graduate['LoanAmount'].plot(kind='density',label="have fun")
#Subsetting the dataframe based on 'Education' column
#Plotting density plot for 'Graduate'
#Plotting density plot for 'Graduate'
#For automatic legend display
# Step 5
#Setting up the subplots
fig,(ax_1,ax_2,ax_3)=plt.subplots(3,1)
#Plotting scatter plot
ax_1.scatter(data['ApplicantIncome'],data['LoanAmount'])
ax_1.set_title('ApplicantIncome')
ax_2.scatter(data['CoapplicantIncome'],data['LoanAmount'])
ax_2.set_title('Coapplicant Income')
#Setting the subplot axis title
data['TotalIncome']=data['ApplicantIncome']+data['CoapplicantIncome']
ax_3.scatter(data['TotalIncome'],data['LoanAmount'])
ax_3.set_title('Total Income')
print(data['TotalIncome'])
#Plotting scatter plot
#Setting the subplot axis title
#Creating a new column 'TotalIncome'
#Plotting scatter plot
#Setting the subplot axis title
|
// (C) Copyright 2009-2011 Frederic Bron.
//
// Use, modification and distribution are subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt).
//
// See http://www.boost.org/libs/type_traits for most recent version including documentation.
#ifndef BOOST_TT_HAS_OPERATOR_HPP_INCLUDED
#define BOOST_TT_HAS_OPERATOR_HPP_INCLUDED
#include <boost/type_traits/has_bit_and.hpp>
#include <boost/type_traits/has_bit_and_assign.hpp>
#include <boost/type_traits/has_bit_or.hpp>
#include <boost/type_traits/has_bit_or_assign.hpp>
#include <boost/type_traits/has_bit_xor.hpp>
#include <boost/type_traits/has_bit_xor_assign.hpp>
#include <boost/type_traits/has_complement.hpp>
#include <boost/type_traits/has_dereference.hpp>
#include <boost/type_traits/has_divides.hpp>
#include <boost/type_traits/has_divides_assign.hpp>
#include <boost/type_traits/has_equal_to.hpp>
#include <boost/type_traits/has_greater.hpp>
#include <boost/type_traits/has_greater_equal.hpp>
#include <boost/type_traits/has_left_shift.hpp>
#include <boost/type_traits/has_left_shift_assign.hpp>
#include <boost/type_traits/has_less.hpp>
#include <boost/type_traits/has_less_equal.hpp>
#include <boost/type_traits/has_logical_and.hpp>
#include <boost/type_traits/has_logical_not.hpp>
#include <boost/type_traits/has_logical_or.hpp>
#include <boost/type_traits/has_minus.hpp>
#include <boost/type_traits/has_minus_assign.hpp>
#include <boost/type_traits/has_modulus.hpp>
#include <boost/type_traits/has_modulus_assign.hpp>
#include <boost/type_traits/has_multiplies.hpp>
#include <boost/type_traits/has_multiplies_assign.hpp>
#include <boost/type_traits/has_negate.hpp>
#include <boost/type_traits/has_not_equal_to.hpp>
#include <boost/type_traits/has_plus.hpp>
#include <boost/type_traits/has_plus_assign.hpp>
#include <boost/type_traits/has_post_decrement.hpp>
#include <boost/type_traits/has_post_increment.hpp>
#include <boost/type_traits/has_pre_decrement.hpp>
#include <boost/type_traits/has_pre_increment.hpp>
#include <boost/type_traits/has_right_shift.hpp>
#include <boost/type_traits/has_right_shift_assign.hpp>
#include <boost/type_traits/has_unary_minus.hpp>
#include <boost/type_traits/has_unary_plus.hpp>
#endif
|
lemma holomorphic_involution_point: assumes holfU: "f holomorphic_on UNIV" and non: "\<And>a. f \<noteq> (\<lambda>x. a + x)" obtains x where "f(f x) = x" |
/-
Copyright (c) 2020 Devon Tuma. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Devon Tuma
! This file was ported from Lean 3 source module ring_theory.jacobson_ideal
! leanprover-community/mathlib commit da420a8c6dd5bdfb85c4ced85c34388f633bc6ff
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.RingTheory.Ideal.Quotient
import Mathbin.RingTheory.Polynomial.Quotient
/-!
# Jacobson radical
The Jacobson radical of a ring `R` is defined to be the intersection of all maximal ideals of `R`.
This is similar to how the nilradical is equal to the intersection of all prime ideals of `R`.
We can extend the idea of the nilradical to ideals of `R`,
by letting the radical of an ideal `I` be the intersection of prime ideals containing `I`.
Under this extension, the original nilradical is the radical of the zero ideal `⊥`.
Here we define the Jacobson radical of an ideal `I` in a similar way,
as the intersection of maximal ideals containing `I`.
## Main definitions
Let `R` be a commutative ring, and `I` be an ideal of `R`
* `jacobson I` is the jacobson radical, i.e. the infimum of all maximal ideals containing I.
* `is_local I` is the proposition that the jacobson radical of `I` is itself a maximal ideal
## Main statements
* `mem_jacobson_iff` gives a characterization of members of the jacobson of I
* `is_local_of_is_maximal_radical`: if the radical of I is maximal then so is the jacobson radical
## Tags
Jacobson, Jacobson radical, Local Ideal
-/
universe u v
namespace Ideal
variable {R : Type u} {S : Type v}
open Polynomial
section Jacobson
section Ring
variable [Ring R] [Ring S] {I : Ideal R}
/-- The Jacobson radical of `I` is the infimum of all maximal (left) ideals containing `I`. -/
def jacobson (I : Ideal R) : Ideal R :=
infₛ { J : Ideal R | I ≤ J ∧ IsMaximal J }
#align ideal.jacobson Ideal.jacobson
theorem le_jacobson : I ≤ jacobson I := fun x hx => mem_infₛ.mpr fun J hJ => hJ.left hx
#align ideal.le_jacobson Ideal.le_jacobson
@[simp]
theorem jacobson_idem : jacobson (jacobson I) = jacobson I :=
le_antisymm (infₛ_le_infₛ fun J hJ => ⟨infₛ_le hJ, hJ.2⟩) le_jacobson
#align ideal.jacobson_idem Ideal.jacobson_idem
@[simp]
theorem jacobson_top : jacobson (⊤ : Ideal R) = ⊤ :=
eq_top_iff.2 le_jacobson
#align ideal.jacobson_top Ideal.jacobson_top
@[simp]
theorem jacobson_eq_top_iff : jacobson I = ⊤ ↔ I = ⊤ :=
⟨fun H =>
by_contradiction fun hi =>
let ⟨M, hm, him⟩ := exists_le_maximal I hi
lt_top_iff_ne_top.1
(lt_of_le_of_lt (show jacobson I ≤ M from infₛ_le ⟨him, hm⟩) <|
lt_top_iff_ne_top.2 hm.ne_top)
H,
fun H => eq_top_iff.2 <| le_infₛ fun J ⟨hij, hj⟩ => H ▸ hij⟩
#align ideal.jacobson_eq_top_iff Ideal.jacobson_eq_top_iff
theorem jacobson_eq_bot : jacobson I = ⊥ → I = ⊥ := fun h => eq_bot_iff.mpr (h ▸ le_jacobson)
#align ideal.jacobson_eq_bot Ideal.jacobson_eq_bot
theorem jacobson_eq_self_of_isMaximal [H : IsMaximal I] : I.jacobson = I :=
le_antisymm (infₛ_le ⟨le_of_eq rfl, H⟩) le_jacobson
#align ideal.jacobson_eq_self_of_is_maximal Ideal.jacobson_eq_self_of_isMaximal
instance (priority := 100) jacobson.isMaximal [H : IsMaximal I] : IsMaximal (jacobson I) :=
⟨⟨fun htop => H.1.1 (jacobson_eq_top_iff.1 htop), fun J hJ =>
H.1.2 _ (lt_of_le_of_lt le_jacobson hJ)⟩⟩
#align ideal.jacobson.is_maximal Ideal.jacobson.isMaximal
theorem mem_jacobson_iff {x : R} : x ∈ jacobson I ↔ ∀ y, ∃ z, z * y * x + z - 1 ∈ I :=
⟨fun hx y =>
by_cases
(fun hxy : I ⊔ span {y * x + 1} = ⊤ =>
let ⟨p, hpi, q, hq, hpq⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 hxy)
let ⟨r, hr⟩ := mem_span_singleton'.1 hq
⟨r, by
rw [mul_assoc, ← mul_add_one, hr, ← hpq, ← neg_sub, add_sub_cancel] <;>
exact I.neg_mem hpi⟩)
fun hxy : I ⊔ span {y * x + 1} ≠ ⊤ =>
let ⟨M, hm1, hm2⟩ := exists_le_maximal _ hxy
suffices x ∉ M from (this <| mem_infₛ.1 hx ⟨le_trans le_sup_left hm2, hm1⟩).elim
fun hxm =>
hm1.1.1 <|
(eq_top_iff_one _).2 <|
add_sub_cancel' (y * x) 1 ▸
M.sub_mem (le_sup_right.trans hm2 <| subset_span rfl) (M.mul_mem_left _ hxm),
fun hx =>
mem_infₛ.2 fun M ⟨him, hm⟩ =>
by_contradiction fun hxm =>
let ⟨y, i, hi, df⟩ := hm.exists_inv hxm
let ⟨z, hz⟩ := hx (-y)
hm.1.1 <|
(eq_top_iff_one _).2 <|
sub_sub_cancel (z * -y * x + z) 1 ▸
M.sub_mem
(by
rw [mul_assoc, ← mul_add_one, neg_mul, ← sub_eq_iff_eq_add.mpr df.symm, neg_sub,
sub_add_cancel]
exact M.mul_mem_left _ hi)
(him hz)⟩
#align ideal.mem_jacobson_iff Ideal.mem_jacobson_iff
theorem exists_mul_sub_mem_of_sub_one_mem_jacobson {I : Ideal R} (r : R) (h : r - 1 ∈ jacobson I) :
∃ s, s * r - 1 ∈ I := by
cases' mem_jacobson_iff.1 h 1 with s hs
use s
simpa [mul_sub] using hs
#align ideal.exists_mul_sub_mem_of_sub_one_mem_jacobson Ideal.exists_mul_sub_mem_of_sub_one_mem_jacobson
/-- An ideal equals its Jacobson radical iff it is the intersection of a set of maximal ideals.
Allowing the set to include ⊤ is equivalent, and is included only to simplify some proofs. -/
theorem eq_jacobson_iff_infₛ_maximal :
I.jacobson = I ↔ ∃ M : Set (Ideal R), (∀ J ∈ M, IsMaximal J ∨ J = ⊤) ∧ I = infₛ M :=
by
use fun hI => ⟨{ J : Ideal R | I ≤ J ∧ J.IsMaximal }, ⟨fun _ hJ => Or.inl hJ.right, hI.symm⟩⟩
rintro ⟨M, hM, hInf⟩
refine' le_antisymm (fun x hx => _) le_jacobson
rw [hInf, mem_Inf]
intro I hI
cases' hM I hI with is_max is_top
· exact (mem_Inf.1 hx) ⟨le_infₛ_iff.1 (le_of_eq hInf) I hI, IsMax⟩
· exact is_top.symm ▸ Submodule.mem_top
#align ideal.eq_jacobson_iff_Inf_maximal Ideal.eq_jacobson_iff_infₛ_maximal
theorem eq_jacobson_iff_infₛ_maximal' :
I.jacobson = I ↔ ∃ M : Set (Ideal R), (∀ J ∈ M, ∀ (K : Ideal R), J < K → K = ⊤) ∧ I = infₛ M :=
eq_jacobson_iff_infₛ_maximal.trans
⟨fun h =>
let ⟨M, hM⟩ := h
⟨M,
⟨fun J hJ K hK =>
Or.rec_on (hM.1 J hJ) (fun h => h.1.2 K hK) fun h => eq_top_iff.2 (le_of_lt (h ▸ hK)),
hM.2⟩⟩,
fun h =>
let ⟨M, hM⟩ := h
⟨M,
⟨fun J hJ =>
Or.rec_on (Classical.em (J = ⊤)) (fun h => Or.inr h) fun h => Or.inl ⟨⟨h, hM.1 J hJ⟩⟩,
hM.2⟩⟩⟩
#align ideal.eq_jacobson_iff_Inf_maximal' Ideal.eq_jacobson_iff_infₛ_maximal'
/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (x «expr ∉ » I) -/
/-- An ideal `I` equals its Jacobson radical if and only if every element outside `I`
also lies outside of a maximal ideal containing `I`. -/
theorem eq_jacobson_iff_not_mem :
I.jacobson = I ↔ ∀ (x) (_ : x ∉ I), ∃ M : Ideal R, (I ≤ M ∧ M.IsMaximal) ∧ x ∉ M :=
by
constructor
· intro h x hx
erw [← h, mem_Inf] at hx
push_neg at hx
exact hx
· refine' fun h => le_antisymm (fun x hx => _) le_jacobson
contrapose hx
erw [mem_Inf]
push_neg
exact h x hx
#align ideal.eq_jacobson_iff_not_mem Ideal.eq_jacobson_iff_not_mem
theorem map_jacobson_of_surjective {f : R →+* S} (hf : Function.Surjective f) :
RingHom.ker f ≤ I → map f I.jacobson = (map f I).jacobson :=
by
intro h
unfold Ideal.jacobson
have : ∀ J ∈ { J : Ideal R | I ≤ J ∧ J.IsMaximal }, f.ker ≤ J := fun J hJ => le_trans h hJ.left
refine' trans (map_Inf hf this) (le_antisymm _ _)
· refine'
infₛ_le_infₛ fun J hJ =>
⟨comap f J, ⟨⟨le_comap_of_map_le hJ.1, _⟩, map_comap_of_surjective f hf J⟩⟩
haveI : J.is_maximal := hJ.right
exact comap_is_maximal_of_surjective f hf
· refine' infₛ_le_infₛ_of_subset_insert_top fun j hj => hj.recOn fun J hJ => _
rw [← hJ.2]
cases' map_eq_top_or_is_maximal_of_surjective f hf hJ.left.right with htop hmax
· exact htop.symm ▸ Set.mem_insert ⊤ _
· exact Set.mem_insert_of_mem ⊤ ⟨map_mono hJ.1.1, hmax⟩
#align ideal.map_jacobson_of_surjective Ideal.map_jacobson_of_surjective
theorem map_jacobson_of_bijective {f : R →+* S} (hf : Function.Bijective f) :
map f I.jacobson = (map f I).jacobson :=
map_jacobson_of_surjective hf.right
(le_trans (le_of_eq (f.injective_iff_ker_eq_bot.1 hf.left)) bot_le)
#align ideal.map_jacobson_of_bijective Ideal.map_jacobson_of_bijective
theorem comap_jacobson {f : R →+* S} {K : Ideal S} :
comap f K.jacobson = infₛ (comap f '' { J : Ideal S | K ≤ J ∧ J.IsMaximal }) :=
trans (comap_Inf' f _) infₛ_eq_infᵢ.symm
#align ideal.comap_jacobson Ideal.comap_jacobson
theorem comap_jacobson_of_surjective {f : R →+* S} (hf : Function.Surjective f) {K : Ideal S} :
comap f K.jacobson = (comap f K).jacobson :=
by
unfold Ideal.jacobson
refine' le_antisymm _ _
· refine' le_trans (comap_mono (le_of_eq (trans top_inf_eq.symm Inf_insert.symm))) _
rw [comap_Inf', infₛ_eq_infᵢ]
refine' infᵢ_le_infᵢ_of_subset fun J hJ => _
have : comap f (map f J) = J :=
trans (comap_map_of_surjective f hf J)
(le_antisymm (sup_le_iff.2 ⟨le_of_eq rfl, le_trans (comap_mono bot_le) hJ.left⟩)
le_sup_left)
cases' map_eq_top_or_is_maximal_of_surjective _ hf hJ.right with htop hmax
· refine' ⟨⊤, ⟨Set.mem_insert ⊤ _, htop ▸ this⟩⟩
·
refine'
⟨map f J,
⟨Set.mem_insert_of_mem _ ⟨le_map_of_comap_le_of_surjective f hf hJ.1, hmax⟩, this⟩⟩
· rw [comap_Inf]
refine' le_infᵢ_iff.2 fun J => le_infᵢ_iff.2 fun hJ => _
haveI : J.is_maximal := hJ.right
refine' infₛ_le ⟨comap_mono hJ.left, comap_is_maximal_of_surjective _ hf⟩
#align ideal.comap_jacobson_of_surjective Ideal.comap_jacobson_of_surjective
@[mono]
theorem jacobson_mono {I J : Ideal R} : I ≤ J → I.jacobson ≤ J.jacobson :=
by
intro h x hx
erw [mem_Inf] at hx⊢
exact fun K ⟨hK, hK_max⟩ => hx ⟨trans h hK, hK_max⟩
#align ideal.jacobson_mono Ideal.jacobson_mono
end Ring
section CommRing
variable [CommRing R] [CommRing S] {I : Ideal R}
theorem radical_le_jacobson : radical I ≤ jacobson I :=
le_infₛ fun J hJ => (radical_eq_infₛ I).symm ▸ infₛ_le ⟨hJ.left, IsMaximal.isPrime hJ.right⟩
#align ideal.radical_le_jacobson Ideal.radical_le_jacobson
theorem isRadical_of_eq_jacobson (h : jacobson I = I) : I.IsRadical :=
radical_le_jacobson.trans h.le
#align ideal.is_radical_of_eq_jacobson Ideal.isRadical_of_eq_jacobson
theorem isUnit_of_sub_one_mem_jacobson_bot (r : R) (h : r - 1 ∈ jacobson (⊥ : Ideal R)) :
IsUnit r := by
cases' exists_mul_sub_mem_of_sub_one_mem_jacobson r h with s hs
rw [mem_bot, sub_eq_zero, mul_comm] at hs
exact isUnit_of_mul_eq_one _ _ hs
#align ideal.is_unit_of_sub_one_mem_jacobson_bot Ideal.isUnit_of_sub_one_mem_jacobson_bot
theorem mem_jacobson_bot {x : R} : x ∈ jacobson (⊥ : Ideal R) ↔ ∀ y, IsUnit (x * y + 1) :=
⟨fun hx y =>
let ⟨z, hz⟩ := (mem_jacobson_iff.1 hx) y
isUnit_iff_exists_inv.2
⟨z, by rwa [add_mul, one_mul, ← sub_eq_zero, mul_right_comm, mul_comm _ z, mul_right_comm]⟩,
fun h =>
mem_jacobson_iff.mpr fun y =>
let ⟨b, hb⟩ := isUnit_iff_exists_inv.1 (h y)
⟨b, (Submodule.mem_bot R).2 (hb ▸ by ring)⟩⟩
#align ideal.mem_jacobson_bot Ideal.mem_jacobson_bot
/-- An ideal `I` of `R` is equal to its Jacobson radical if and only if
the Jacobson radical of the quotient ring `R/I` is the zero ideal -/
theorem jacobson_eq_iff_jacobson_quotient_eq_bot :
I.jacobson = I ↔ jacobson (⊥ : Ideal (R ⧸ I)) = ⊥ :=
by
have hf : Function.Surjective (Quotient.mk' I) := Submodule.Quotient.mk_surjective I
constructor
· intro h
replace h := congr_arg (map (Quotient.mk' I)) h
rw [map_jacobson_of_surjective hf (le_of_eq mk_ker)] at h
simpa using h
· intro h
replace h := congr_arg (comap (Quotient.mk' I)) h
rw [comap_jacobson_of_surjective hf, ← (Quotient.mk' I).ker_eq_comap_bot] at h
simpa using h
#align ideal.jacobson_eq_iff_jacobson_quotient_eq_bot Ideal.jacobson_eq_iff_jacobson_quotient_eq_bot
/-- The standard radical and Jacobson radical of an ideal `I` of `R` are equal if and only if
the nilradical and Jacobson radical of the quotient ring `R/I` coincide -/
theorem radical_eq_jacobson_iff_radical_quotient_eq_jacobson_bot :
I.radical = I.jacobson ↔ radical (⊥ : Ideal (R ⧸ I)) = jacobson ⊥ :=
by
have hf : Function.Surjective (Quotient.mk' I) := Submodule.Quotient.mk_surjective I
constructor
· intro h
have := congr_arg (map (Quotient.mk' I)) h
rw [map_radical_of_surjective hf (le_of_eq mk_ker),
map_jacobson_of_surjective hf (le_of_eq mk_ker)] at this
simpa using this
· intro h
have := congr_arg (comap (Quotient.mk' I)) h
rw [comap_radical, comap_jacobson_of_surjective hf, ← (Quotient.mk' I).ker_eq_comap_bot] at this
simpa using this
#align ideal.radical_eq_jacobson_iff_radical_quotient_eq_jacobson_bot Ideal.radical_eq_jacobson_iff_radical_quotient_eq_jacobson_bot
theorem jacobson_radical_eq_jacobson : I.radical.jacobson = I.jacobson :=
le_antisymm
(le_trans (le_of_eq (congr_arg jacobson (radical_eq_infₛ I)))
(infₛ_le_infₛ fun J hJ => ⟨infₛ_le ⟨hJ.1, hJ.2.IsPrime⟩, hJ.2⟩))
(jacobson_mono le_radical)
#align ideal.jacobson_radical_eq_jacobson Ideal.jacobson_radical_eq_jacobson
end CommRing
end Jacobson
section Polynomial
open Polynomial
variable [CommRing R]
theorem jacobson_bot_polynomial_le_infₛ_map_maximal :
jacobson (⊥ : Ideal R[X]) ≤ infₛ (map (C : R →+* R[X]) '' { J : Ideal R | J.IsMaximal }) :=
by
refine' le_infₛ fun J => exists_imp.2 fun j hj => _
haveI : j.is_maximal := hj.1
refine' trans (jacobson_mono bot_le) (le_of_eq _ : J.jacobson ≤ J)
suffices (⊥ : Ideal (Polynomial (R ⧸ j))).jacobson = ⊥
by
rw [← hj.2, jacobson_eq_iff_jacobson_quotient_eq_bot]
replace this := congr_arg (map (polynomial_quotient_equiv_quotient_polynomial j).toRingHom) this
rwa [map_jacobson_of_bijective _, map_bot] at this
exact RingEquiv.bijective (polynomial_quotient_equiv_quotient_polynomial j)
refine' eq_bot_iff.2 fun f hf => _
simpa [(fun hX => by simpa using congr_arg (fun f => coeff f 1) hX : (X : (R ⧸ j)[X]) ≠ 0)] using
eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit ((mem_jacobson_bot.1 hf) X))
#align ideal.jacobson_bot_polynomial_le_Inf_map_maximal Ideal.jacobson_bot_polynomial_le_infₛ_map_maximal
theorem jacobson_bot_polynomial_of_jacobson_bot (h : jacobson (⊥ : Ideal R) = ⊥) :
jacobson (⊥ : Ideal R[X]) = ⊥ :=
by
refine' eq_bot_iff.2 (le_trans jacobson_bot_polynomial_le_Inf_map_maximal _)
refine' fun f hf => (Submodule.mem_bot _).2 (Polynomial.ext fun n => trans _ (coeff_zero n).symm)
suffices f.coeff n ∈ Ideal.jacobson ⊥ by rwa [h, Submodule.mem_bot] at this
exact mem_Inf.2 fun j hj => (mem_map_C_iff.1 ((mem_Inf.1 hf) ⟨j, ⟨hj.2, rfl⟩⟩)) n
#align ideal.jacobson_bot_polynomial_of_jacobson_bot Ideal.jacobson_bot_polynomial_of_jacobson_bot
end Polynomial
section IsLocal
variable [CommRing R]
/-- An ideal `I` is local iff its Jacobson radical is maximal. -/
class IsLocal (I : Ideal R) : Prop where
out : IsMaximal (jacobson I)
#align ideal.is_local Ideal.IsLocal
theorem isLocal_iff {I : Ideal R} : IsLocal I ↔ IsMaximal (jacobson I) :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
#align ideal.is_local_iff Ideal.isLocal_iff
theorem isLocal_of_isMaximal_radical {I : Ideal R} (hi : IsMaximal (radical I)) : IsLocal I :=
⟨have : radical I = jacobson I :=
le_antisymm (le_infₛ fun M ⟨him, hm⟩ => hm.IsPrime.radical_le_iff.2 him)
(infₛ_le ⟨le_radical, hi⟩)
show IsMaximal (jacobson I) from this ▸ hi⟩
#align ideal.is_local_of_is_maximal_radical Ideal.isLocal_of_isMaximal_radical
theorem IsLocal.le_jacobson {I J : Ideal R} (hi : IsLocal I) (hij : I ≤ J) (hj : J ≠ ⊤) :
J ≤ jacobson I :=
let ⟨M, hm, hjm⟩ := exists_le_maximal J hj
le_trans hjm <| le_of_eq <| Eq.symm <| hi.1.eq_of_le hm.1.1 <| infₛ_le ⟨le_trans hij hjm, hm⟩
#align ideal.is_local.le_jacobson Ideal.IsLocal.le_jacobson
theorem IsLocal.mem_jacobson_or_exists_inv {I : Ideal R} (hi : IsLocal I) (x : R) :
x ∈ jacobson I ∨ ∃ y, y * x - 1 ∈ I :=
by_cases
(fun h : I ⊔ span {x} = ⊤ =>
let ⟨p, hpi, q, hq, hpq⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h)
let ⟨r, hr⟩ := mem_span_singleton.1 hq
Or.inr ⟨r, by rw [← hpq, mul_comm, ← hr, ← neg_sub, add_sub_cancel] <;> exact I.neg_mem hpi⟩)
fun h : I ⊔ span {x} ≠ ⊤ =>
Or.inl <|
le_trans le_sup_right (hi.le_jacobson le_sup_left h) <| mem_span_singleton.2 <| dvd_refl x
#align ideal.is_local.mem_jacobson_or_exists_inv Ideal.IsLocal.mem_jacobson_or_exists_inv
end IsLocal
theorem isPrimary_of_isMaximal_radical [CommRing R] {I : Ideal R} (hi : IsMaximal (radical I)) :
IsPrimary I :=
have : radical I = jacobson I :=
le_antisymm (le_infₛ fun M ⟨him, hm⟩ => hm.IsPrime.radical_le_iff.2 him)
(infₛ_le ⟨le_radical, hi⟩)
⟨ne_top_of_lt <| lt_of_le_of_lt le_radical (lt_top_iff_ne_top.2 hi.1.1), fun x y hxy =>
((isLocal_of_isMaximal_radical hi).mem_jacobson_or_exists_inv y).symm.imp
(fun ⟨z, hz⟩ => by
rw [← mul_one x, ← sub_sub_cancel (z * y) 1, mul_sub, mul_left_comm] <;>
exact I.sub_mem (I.mul_mem_left _ hxy) (I.mul_mem_left _ hz))
(this ▸ id)⟩
#align ideal.is_primary_of_is_maximal_radical Ideal.isPrimary_of_isMaximal_radical
end Ideal
|
(*
* Copyright (c) 2021-2022 BedRock Systems, Inc.
* This software is distributed under the terms of the BedRock Open-Source License.
* See the LICENSE-BedRock file in the repository root for details.
*)
Require Import iris.bi.bi.
Module Type ERRORS.
Section with_bi.
Context {PROP : bi}.
Parameter ERROR : forall {T : Type}, T -> PROP.
Parameter UNSUPPORTED : forall {T : Type}, T -> PROP.
Parameter ERROR_elim : forall {T} (t : T), ERROR t ⊢ False.
Parameter UNSUPPORTED_elim : forall {T} (t : T), UNSUPPORTED t ⊢ False.
End with_bi.
End ERRORS.
Module Errors : ERRORS.
Section with_bi.
Context {PROP : bi}.
Definition ERROR : forall {T : Type}, T -> PROP :=
fun _ _ => False%I.
Definition UNSUPPORTED : forall {T : Type}, T -> PROP :=
fun _ _ => False%I.
Theorem ERROR_elim : forall {T} (t : T), ERROR t ⊢ False.
Proof. reflexivity. Qed.
Theorem UNSUPPORTED_elim : forall {T} (t : T), UNSUPPORTED t ⊢ False.
Proof. reflexivity. Qed.
End with_bi.
End Errors.
Export Errors.
|
module BasicIS4.Metatheory.Gentzen-BasicKripkeAlechina where
open import BasicIS4.Syntax.Gentzen public
open import BasicIS4.Semantics.BasicKripkeAlechina public
-- Soundness with respect to all models, or evaluation.
mutual
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam t) γ = λ ξ a → eval t (mono⊩⋆ ξ γ , a)
eval (app {A} {B} t u) γ = _⟪$⟫_ {A} {B} (eval t γ) (eval u γ)
eval (multibox ts u) γ = λ ξ ζ → eval u (thing ts γ ξ ζ)
eval (down {A} t) γ = ⟪↓⟫ {A} (eval t γ)
eval (pair t u) γ = eval t γ , eval u γ
eval (fst t) γ = π₁ (eval t γ)
eval (snd t) γ = π₂ (eval t γ)
eval unit γ = ∙
-- TODO: What is this?
thing : ∀ {{_ : Model}} {Δ Γ} {w : World}
→ Γ ⊢⋆ □⋆ Δ → w ⊩⋆ Γ → ∀ {w′} → w ≤ w′ → ∀ {v′} → w′ R v′ → v′ ⊩⋆ □⋆ Δ
thing {∅} ∙ γ ξ ζ = ∙
thing {Δ , B} (ts , t) γ ξ ζ = thing ts γ ξ ζ , λ ξ′ ζ′ →
let _ , (ξ″ , ζ″) = R⨾≤→≤⨾R (_ , (ζ , ξ′))
in eval t γ (trans≤ ξ ξ″) (transR ζ″ ζ′)
eval⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊨⋆ Ξ
eval⋆ {∅} ∙ γ = ∙
eval⋆ {Ξ , A} (ts , t) γ = eval⋆ ts γ , eval t γ
-- TODO: Correctness of evaluation with respect to conversion.
|
[STATEMENT]
lemma iMOD_cut_less: "
[r, mod m] \<down>< t = (
if t \<le> r then {}
else [r, mod m, (t - Suc r) div m])"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. [ r, mod m ] \<down>< t = (if t \<le> r then {} else [ r, mod m, (t - Suc r) div m ])
[PROOF STEP]
apply (case_tac "t = 0")
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. t = 0 \<Longrightarrow> [ r, mod m ] \<down>< t = (if t \<le> r then {} else [ r, mod m, (t - Suc r) div m ])
2. t \<noteq> 0 \<Longrightarrow> [ r, mod m ] \<down>< t = (if t \<le> r then {} else [ r, mod m, (t - Suc r) div m ])
[PROOF STEP]
apply (simp add: cut_less_0_empty)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. t \<noteq> 0 \<Longrightarrow> [ r, mod m ] \<down>< t = (if t \<le> r then {} else [ r, mod m, (t - Suc r) div m ])
[PROOF STEP]
apply (simp add: nat_cut_less_le_conv iMOD_cut_le)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. 0 < t \<Longrightarrow> (t - Suc 0 < r \<longrightarrow> \<not> t \<le> r \<longrightarrow> {} = [ r, mod m, 0 ]) \<and> (\<not> t - Suc 0 < r \<longrightarrow> t \<le> r \<longrightarrow> [ r, mod m, 0 ] = {})
[PROOF STEP]
apply fastforce
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
This auction is for parts from same 1969 VW Beetle and includes the frame, body, doors, engine in parts, etc. Body, frame, doors are very solid and in great condition. Body has been sandblasted, solid floor boards, door posts, and is primed. Not included is the interior (except for 2 front seats from a Porsche which needs to be redone), front windshield and transmission. Original 1500 German block engine needs to be rebuilt and reassembled. We have a lot of parts and some new as well, including a new 2” over-sized custom rear fiberglass fenders, new rear apron, etc. The body and frame are sitting on a big dolly on casters, which is easy to move around to work on and is included as well.
1967 white Beetle with many original parts. |
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-}
{-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-}
{-|
Module : Numeric.Proximal.Static
Description : Solve proximal problems using FISTA
Copyright : (c) Ryan Orendorff, 2020
License : BSD3
Stability : experimental
-}
module Numeric.Proximal.Static
( fista
, fistaCost
, indicatorBox
, l1Cost
, l1Prox
, lsqLipschitz
, proxIndicatorBox
, quadraticLipschitz
, residuals
)
where
import GHC.TypeLits
import Numeric.LinearAlgebra.Static
import Numeric.LinearAlgebra.Static.Util
import Data.Maybe
import Data.Tuple.HT ( fst3 )
------------------------------------------------------------------
-- Lipschitz calculations on actual matrixes by max eigenvalue --
------------------------------------------------------------------
-- TODO: Implement solution for extracting k largest eigenvalues directly.
-- Note that these are not particularly efficient as each eigenvalue must be extracted and then searched through to find the maximum.
-- | Find the Lipschitz constant for a least squares problem.
lsqLipschitz :: (KnownNat m, KnownNat n) => L m n -> Double
lsqLipschitz a = foldR1 max . eigenvalues $ mTm a
-- | Find the Lipschitz constant for a quadratic program.
quadraticLipschitz :: (KnownNat n) => Sym n -> Double
quadraticLipschitz = foldR1 max . eigenvalues
---------------------------------------------------------
-- Proximal Functions --
---------------------------------------------------------
-- | Returns the cost function for the box indicator function.
-- I(l, u) = {0 if l < xᵢ < u ∀ xᵢ ∈ x
-- ∞ otherwise}
indicatorBox :: Double -> Double -> (forall n . KnownNat n => R n -> Double)
indicatorBox l u =
foldR (\a b -> a + (if (b > u) || (b < l) then 1 / 0 else 0)) 0
-- | Proximal operator for the box indicator function
proxIndicatorBox :: Double -> Double -> (forall n . KnownNat n => R n -> R n)
proxIndicatorBox l u = dvmap bound
where
bound x = case (x < l, x > u) of
(True, _ ) -> l
(_ , True) -> u
_ -> x
-- | Fast Iterative Soft Thresholding Algorithm
-- Used to solve problems of the form F(x) = f(x) + g(x), where
-- f is a smooth convex function with grad F being L-Lipschitz continuous and
-- g is a (potentially non-smooth) convex function. Common problems solved
-- with FISTA include min ||Ax - b|| st. x \in C or min ||Ax - b|| + ||x||_1
fista
:: (KnownNat n)
=> (R n -> R n) -- ^ gradient of f
-> (R n -> R n) -- ^ proximal operator of g
-> Double -- ^ Lipschitz constant
-> Maybe (R n) -- ^ Initial guess at a solution
-> [R n] -- ^ Output cost function and optimal solution over time
fista grad_f prox_g lipschitz (fromMaybe (konst 0) -> x0) = map fst3
$ iterate go (x0, x0, 1)
where
-- Sometimes update is called p_L
gradient_step = \x -> x - konst (1 / lipschitz) * grad_f x
prox_step = prox_g
update = prox_step . gradient_step
-- Algorithm here
go (x, y, t) =
let
x_update = update y
t_update = (1 + sqrt (1 + 4 * t ^^ (2 :: Int))) / 2
y_update =
x_update + konst ((t - 1) / t_update) * (x_update - x)
in
(x_update, y_update, t_update)
-- | Residuals for a list of vectors.
residuals :: forall n . KnownNat n => [R n] -> [Double]
residuals x = zipWith (\y yn -> norm_2 (y - yn)) x (tail x)
-----------------------------------------------------------------
-- Cost Functions --
-----------------------------------------------------------------
-- | Takes the most smooth convex function \(f\) and the convex (potentially
-- non-smooth) function \(g\) and calculates the cost of a given input.
fistaCost :: (R n -> Double) -> (R n -> Double) -> R n -> Double
fistaCost f g x = f x + g x
-- | Cost function for an ℓ₁ term
l1Cost :: (KnownNat n) => Double -> R n -> Double
l1Cost lambda = (lambda *) . norm_1
-- | Proximal equation a the ℓ₁ term
l1Prox :: (KnownNat n) => Double -> R n -> R n
l1Prox lambda = dvmap f where f xi = signum xi * max (abs xi - lambda) 0
|
\documentclass{article}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage{varioref}
\usepackage{blindtext}
\begin{document}
\section{Figures}
\begin{figure}
\includegraphics{example-image}
\caption{An example figure}
\label{fig:example}
\end{figure}
\blindtext
\begin{figure}
\includegraphics{example-image}
\caption{Another example figure}
\label{fig:other}
\end{figure}
\newpage
Same reference code, different output:
\begin{verbatim}
See the \vpageref[above figure][figure]{fig:other} and
the \vpageref[above figure][figure]{fig:example}.
\end{verbatim}
See the \vpageref[above figure][figure]{fig:other} and
the \vpageref[above figure][figure]{fig:example}.
\end{document} |
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
⊢ ⁅g₁, g₂⁆ = 1 ↔ g₁ * g₂ = g₂ * g₁
[PROOFSTEP]
rw [commutatorElement_def, mul_inv_eq_one, mul_inv_eq_iff_eq_mul]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
⊢ ⁅g₁, g₂⁆⁻¹ = ⁅g₂, g₁⁆
[PROOFSTEP]
simp_rw [commutatorElement_def, mul_inv_rev, inv_inv, mul_assoc]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
⊢ ↑f ⁅g₁, g₂⁆ = ⁅↑f g₁, ↑f g₂⁆
[PROOFSTEP]
simp_rw [commutatorElement_def, map_mul f, map_inv f]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
⊢ ⁅H₁, H₂⁆ = ⊥ ↔ H₁ ≤ centralizer ↑H₂
[PROOFSTEP]
rw [eq_bot_iff, commutator_le]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
⊢ (∀ (g₁ : G), g₁ ∈ H₁ → ∀ (g₂ : G), g₂ ∈ H₂ → ⁅g₁, g₂⁆ ∈ ⊥) ↔ H₁ ≤ centralizer ↑H₂
[PROOFSTEP]
refine' forall_congr' fun p => forall_congr' fun _hp => forall_congr' fun q => forall_congr' fun hq => _
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
p : G
_hp : p ∈ H₁
q : G
hq : q ∈ H₂
⊢ ⁅p, q⁆ ∈ ⊥ ↔ q * p = p * q
[PROOFSTEP]
rw [mem_bot, commutatorElement_eq_one_iff_mul_comm, eq_comm]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h1 : ⁅⁅H₂, H₃⁆, H₁⁆ = ⊥
h2 : ⁅⁅H₃, H₁⁆, H₂⁆ = ⊥
⊢ ⁅⁅H₁, H₂⁆, H₃⁆ = ⊥
[PROOFSTEP]
simp_rw [commutator_eq_bot_iff_le_centralizer, commutator_le, mem_centralizer_iff_commutator_eq_one, ←
commutatorElement_def] at h1 h2 ⊢
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h1 : ∀ (g₁ : G), g₁ ∈ H₂ → ∀ (g₂ : G), g₂ ∈ H₃ → ∀ (h : G), h ∈ ↑H₁ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
h2 : ∀ (g₁ : G), g₁ ∈ H₃ → ∀ (g₂ : G), g₂ ∈ H₁ → ∀ (h : G), h ∈ ↑H₂ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
⊢ ∀ (g₁ : G), g₁ ∈ H₁ → ∀ (g₂ : G), g₂ ∈ H₂ → ∀ (h : G), h ∈ ↑H₃ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
[PROOFSTEP]
intro x hx y hy z hz
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h1 : ∀ (g₁ : G), g₁ ∈ H₂ → ∀ (g₂ : G), g₂ ∈ H₃ → ∀ (h : G), h ∈ ↑H₁ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
h2 : ∀ (g₁ : G), g₁ ∈ H₃ → ∀ (g₂ : G), g₂ ∈ H₁ → ∀ (h : G), h ∈ ↑H₂ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
x : G
hx : x ∈ H₁
y : G
hy : y ∈ H₂
z : G
hz : z ∈ ↑H₃
⊢ ⁅z, ⁅x, y⁆⁆ = 1
[PROOFSTEP]
trans x * z * ⁅y, ⁅z⁻¹, x⁻¹⁆⁆⁻¹ * z⁻¹ * y * ⁅x⁻¹, ⁅y⁻¹, z⁆⁆⁻¹ * y⁻¹ * x⁻¹
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h1 : ∀ (g₁ : G), g₁ ∈ H₂ → ∀ (g₂ : G), g₂ ∈ H₃ → ∀ (h : G), h ∈ ↑H₁ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
h2 : ∀ (g₁ : G), g₁ ∈ H₃ → ∀ (g₂ : G), g₂ ∈ H₁ → ∀ (h : G), h ∈ ↑H₂ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
x : G
hx : x ∈ H₁
y : G
hy : y ∈ H₂
z : G
hz : z ∈ ↑H₃
⊢ ⁅z, ⁅x, y⁆⁆ = x * z * ⁅y, ⁅z⁻¹, x⁻¹⁆⁆⁻¹ * z⁻¹ * y * ⁅x⁻¹, ⁅y⁻¹, z⁆⁆⁻¹ * y⁻¹ * x⁻¹
[PROOFSTEP]
group
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h1 : ∀ (g₁ : G), g₁ ∈ H₂ → ∀ (g₂ : G), g₂ ∈ H₃ → ∀ (h : G), h ∈ ↑H₁ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
h2 : ∀ (g₁ : G), g₁ ∈ H₃ → ∀ (g₂ : G), g₂ ∈ H₁ → ∀ (h : G), h ∈ ↑H₂ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
x : G
hx : x ∈ H₁
y : G
hy : y ∈ H₂
z : G
hz : z ∈ ↑H₃
⊢ x * z * ⁅y, ⁅z⁻¹, x⁻¹⁆⁆⁻¹ * z⁻¹ * y * ⁅x⁻¹, ⁅y⁻¹, z⁆⁆⁻¹ * y⁻¹ * x⁻¹ = 1
[PROOFSTEP]
rw [h1 _ (H₂.inv_mem hy) _ hz _ (H₁.inv_mem hx), h2 _ (H₃.inv_mem hz) _ (H₁.inv_mem hx) _ hy]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h1 : ∀ (g₁ : G), g₁ ∈ H₂ → ∀ (g₂ : G), g₂ ∈ H₃ → ∀ (h : G), h ∈ ↑H₁ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
h2 : ∀ (g₁ : G), g₁ ∈ H₃ → ∀ (g₂ : G), g₂ ∈ H₁ → ∀ (h : G), h ∈ ↑H₂ → ⁅h, ⁅g₁, g₂⁆⁆ = 1
x : G
hx : x ∈ H₁
y : G
hy : y ∈ H₂
z : G
hz : z ∈ ↑H₃
⊢ x * z * 1⁻¹ * z⁻¹ * y * 1⁻¹ * y⁻¹ * x⁻¹ = 1
[PROOFSTEP]
group
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
⊢ Normal ⁅H₁, H₂⁆
[PROOFSTEP]
let base : Set G := {x | ∃ g₁ ∈ H₁, ∃ g₂ ∈ H₂, ⁅g₁, g₂⁆ = x}
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
base : Set G := {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x}
⊢ Normal ⁅H₁, H₂⁆
[PROOFSTEP]
change (closure base).Normal
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
base : Set G := {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x}
⊢ Normal (closure base)
[PROOFSTEP]
suffices h_base : base = Group.conjugatesOfSet base
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
base : Set G := {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x}
h_base : base = Group.conjugatesOfSet base
⊢ Normal (closure base)
[PROOFSTEP]
rw [h_base]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
base : Set G := {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x}
h_base : base = Group.conjugatesOfSet base
⊢ Normal (closure (Group.conjugatesOfSet base))
[PROOFSTEP]
exact Subgroup.normalClosure_normal
[GOAL]
case h_base
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
base : Set G := {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x}
⊢ base = Group.conjugatesOfSet base
[PROOFSTEP]
refine' Set.Subset.antisymm Group.subset_conjugatesOfSet fun a h => _
[GOAL]
case h_base
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
base : Set G := {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x}
a : G
h : a ∈ Group.conjugatesOfSet base
⊢ a ∈ base
[PROOFSTEP]
simp_rw [Group.mem_conjugatesOfSet_iff, isConj_iff] at h
[GOAL]
case h_base
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
base : Set G := {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x}
a : G
h : ∃ a_1, a_1 ∈ {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x} ∧ ∃ c, c * a_1 * c⁻¹ = a
⊢ a ∈ base
[PROOFSTEP]
rcases h with ⟨b, ⟨c, hc, e, he, rfl⟩, d, rfl⟩
[GOAL]
case h_base.intro.intro.intro.intro.intro.intro.intro
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
h₁ : Normal H₁
h₂ : Normal H₂
base : Set G := {x | ∃ g₁, g₁ ∈ H₁ ∧ ∃ g₂, g₂ ∈ H₂ ∧ ⁅g₁, g₂⁆ = x}
c : G
hc : c ∈ H₁
e : G
he : e ∈ H₂
d : G
⊢ d * ⁅c, e⁆ * d⁻¹ ∈ base
[PROOFSTEP]
exact ⟨_, h₁.conj_mem c hc d, _, h₂.conj_mem e he d, (conjugate_commutatorElement c e d).symm⟩
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f✝ : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
f : G →* G'
⊢ map f ⁅H₁, H₂⁆ = ⁅map f H₁, map f H₂⁆
[PROOFSTEP]
simp_rw [le_antisymm_iff, map_le_iff_le_comap, commutator_le, mem_comap, map_commutatorElement]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f✝ : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
f : G →* G'
⊢ (∀ (g₁ : G), g₁ ∈ H₁ → ∀ (g₂ : G), g₂ ∈ H₂ → ⁅↑f g₁, ↑f g₂⁆ ∈ ⁅map f H₁, map f H₂⁆) ∧
∀ (g₁ : G'), g₁ ∈ map f H₁ → ∀ (g₂ : G'), g₂ ∈ map f H₂ → ⁅g₁, g₂⁆ ∈ map f ⁅H₁, H₂⁆
[PROOFSTEP]
constructor
[GOAL]
case left
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f✝ : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
f : G →* G'
⊢ ∀ (g₁ : G), g₁ ∈ H₁ → ∀ (g₂ : G), g₂ ∈ H₂ → ⁅↑f g₁, ↑f g₂⁆ ∈ ⁅map f H₁, map f H₂⁆
[PROOFSTEP]
intro p hp q hq
[GOAL]
case left
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f✝ : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
f : G →* G'
p : G
hp : p ∈ H₁
q : G
hq : q ∈ H₂
⊢ ⁅↑f p, ↑f q⁆ ∈ ⁅map f H₁, map f H₂⁆
[PROOFSTEP]
exact commutator_mem_commutator (mem_map_of_mem _ hp) (mem_map_of_mem _ hq)
[GOAL]
case right
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f✝ : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
f : G →* G'
⊢ ∀ (g₁ : G'), g₁ ∈ map f H₁ → ∀ (g₂ : G'), g₂ ∈ map f H₂ → ⁅g₁, g₂⁆ ∈ map f ⁅H₁, H₂⁆
[PROOFSTEP]
rintro _ ⟨p, hp, rfl⟩ _ ⟨q, hq, rfl⟩
[GOAL]
case right.intro.intro.intro.intro
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f✝ : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
f : G →* G'
p : G
hp : p ∈ ↑H₁
q : G
hq : q ∈ ↑H₂
⊢ ⁅↑f p, ↑f q⁆ ∈ map f ⁅H₁, H₂⁆
[PROOFSTEP]
rw [← map_commutatorElement]
[GOAL]
case right.intro.intro.intro.intro
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f✝ : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
f : G →* G'
p : G
hp : p ∈ ↑H₁
q : G
hq : q ∈ ↑H₂
⊢ ↑f ⁅p, q⁆ ∈ map f ⁅H₁, H₂⁆
[PROOFSTEP]
exact mem_map_of_mem _ (commutator_mem_commutator hp hq)
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ ⁅prod H₁ K₁, prod H₂ K₂⁆ = prod ⁅H₁, H₂⁆ ⁅K₁, K₂⁆
[PROOFSTEP]
apply le_antisymm
[GOAL]
case a
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ ⁅prod H₁ K₁, prod H₂ K₂⁆ ≤ prod ⁅H₁, H₂⁆ ⁅K₁, K₂⁆
[PROOFSTEP]
rw [commutator_le]
[GOAL]
case a
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ ∀ (g₁ : G × G'), g₁ ∈ prod H₁ K₁ → ∀ (g₂ : G × G'), g₂ ∈ prod H₂ K₂ → ⁅g₁, g₂⁆ ∈ prod ⁅H₁, H₂⁆ ⁅K₁, K₂⁆
[PROOFSTEP]
rintro ⟨p₁, p₂⟩ ⟨hp₁, hp₂⟩ ⟨q₁, q₂⟩ ⟨hq₁, hq₂⟩
[GOAL]
case a.mk.intro.mk.intro
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
p₁ : G
p₂ : G'
hp₁ : (p₁, p₂).fst ∈ ↑H₁.toSubmonoid
hp₂ : (p₁, p₂).snd ∈ ↑K₁.toSubmonoid
q₁ : G
q₂ : G'
hq₁ : (q₁, q₂).fst ∈ ↑H₂.toSubmonoid
hq₂ : (q₁, q₂).snd ∈ ↑K₂.toSubmonoid
⊢ ⁅(p₁, p₂), (q₁, q₂)⁆ ∈ prod ⁅H₁, H₂⁆ ⁅K₁, K₂⁆
[PROOFSTEP]
exact ⟨commutator_mem_commutator hp₁ hq₁, commutator_mem_commutator hp₂ hq₂⟩
[GOAL]
case a
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ prod ⁅H₁, H₂⁆ ⁅K₁, K₂⁆ ≤ ⁅prod H₁ K₁, prod H₂ K₂⁆
[PROOFSTEP]
rw [prod_le_iff]
[GOAL]
case a
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ map (MonoidHom.inl G G') ⁅H₁, H₂⁆ ≤ ⁅prod H₁ K₁, prod H₂ K₂⁆ ∧
map (MonoidHom.inr G G') ⁅K₁, K₂⁆ ≤ ⁅prod H₁ K₁, prod H₂ K₂⁆
[PROOFSTEP]
constructor
[GOAL]
case a.left
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ map (MonoidHom.inl G G') ⁅H₁, H₂⁆ ≤ ⁅prod H₁ K₁, prod H₂ K₂⁆
[PROOFSTEP]
rw [map_commutator]
[GOAL]
case a.left
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ ⁅map (MonoidHom.inl G G') H₁, map (MonoidHom.inl G G') H₂⁆ ≤ ⁅prod H₁ K₁, prod H₂ K₂⁆
[PROOFSTEP]
apply commutator_mono
[GOAL]
case a.left.h₁
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ map (MonoidHom.inl G G') H₁ ≤ prod H₁ K₁
[PROOFSTEP]
simp [le_prod_iff, map_map, MonoidHom.fst_comp_inl, MonoidHom.snd_comp_inl, MonoidHom.fst_comp_inr,
MonoidHom.snd_comp_inr]
[GOAL]
case a.left.h₂
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ map (MonoidHom.inl G G') H₂ ≤ prod H₂ K₂
[PROOFSTEP]
simp [le_prod_iff, map_map, MonoidHom.fst_comp_inl, MonoidHom.snd_comp_inl, MonoidHom.fst_comp_inr,
MonoidHom.snd_comp_inr]
[GOAL]
case a.right
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ map (MonoidHom.inr G G') ⁅K₁, K₂⁆ ≤ ⁅prod H₁ K₁, prod H₂ K₂⁆
[PROOFSTEP]
rw [map_commutator]
[GOAL]
case a.right
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ ⁅map (MonoidHom.inr G G') K₁, map (MonoidHom.inr G G') K₂⁆ ≤ ⁅prod H₁ K₁, prod H₂ K₂⁆
[PROOFSTEP]
apply commutator_mono
[GOAL]
case a.right.h₁
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ map (MonoidHom.inr G G') K₁ ≤ prod H₁ K₁
[PROOFSTEP]
simp [le_prod_iff, map_map, MonoidHom.fst_comp_inl, MonoidHom.snd_comp_inl, MonoidHom.fst_comp_inr,
MonoidHom.snd_comp_inr]
[GOAL]
case a.right.h₂
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝² : Group G
inst✝¹ : Group G'
inst✝ : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁✝ K₂✝ : Subgroup G
K₁ K₂ : Subgroup G'
⊢ map (MonoidHom.inr G G') K₂ ≤ prod H₂ K₂
[PROOFSTEP]
simp [le_prod_iff, map_map, MonoidHom.fst_comp_inl, MonoidHom.snd_comp_inl, MonoidHom.fst_comp_inr,
MonoidHom.snd_comp_inr]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
⊢ ⁅pi Set.univ H, pi Set.univ K⁆ = pi Set.univ fun i => ⁅H i, K i⁆
[PROOFSTEP]
classical
apply le_antisymm (commutator_pi_pi_le H K)
· rw [pi_le_iff]
intro i hi
rw [map_commutator]
apply commutator_mono <;>
· rw [le_pi_iff]
intro j _hj
rintro _ ⟨_, ⟨x, hx, rfl⟩, rfl⟩
by_cases h : j = i
· subst h
simpa using hx
· simp [h, one_mem]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
⊢ ⁅pi Set.univ H, pi Set.univ K⁆ = pi Set.univ fun i => ⁅H i, K i⁆
[PROOFSTEP]
apply le_antisymm (commutator_pi_pi_le H K)
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
⊢ (pi Set.univ fun i => ⁅H i, K i⁆) ≤ ⁅pi Set.univ H, pi Set.univ K⁆
[PROOFSTEP]
rw [pi_le_iff]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
⊢ ∀ (i : η), map (MonoidHom.single (fun i => Gs i) i) ⁅H i, K i⁆ ≤ ⁅pi Set.univ H, pi Set.univ K⁆
[PROOFSTEP]
intro i hi
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
⊢ hi ∈ map (MonoidHom.single (fun i => Gs i) i) ⁅H i, K i⁆ → hi ∈ ⁅pi Set.univ H, pi Set.univ K⁆
[PROOFSTEP]
rw [map_commutator]
[GOAL]
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
⊢ hi ∈ ⁅map (MonoidHom.single (fun i => Gs i) i) (H i), map (MonoidHom.single (fun i => Gs i) i) (K i)⁆ →
hi ∈ ⁅pi Set.univ H, pi Set.univ K⁆
[PROOFSTEP]
apply commutator_mono
[GOAL]
case h₁
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
⊢ map (MonoidHom.single (fun i => Gs i) i) (H i) ≤ pi Set.univ H
[PROOFSTEP]
rw [le_pi_iff]
[GOAL]
case h₁
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
⊢ ∀ (i_1 : η),
i_1 ∈ Set.univ → map (Pi.evalMonoidHom (fun i => Gs i) i_1) (map (MonoidHom.single (fun i => Gs i) i) (H i)) ≤ H i_1
[PROOFSTEP]
intro j _hj
[GOAL]
case h₁
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
⊢ map (Pi.evalMonoidHom (fun i => Gs i) j) (map (MonoidHom.single (fun i => Gs i) i) (H i)) ≤ H j
[PROOFSTEP]
rintro _ ⟨_, ⟨x, hx, rfl⟩, rfl⟩
[GOAL]
case h₁.intro.intro.intro.intro
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
x : Gs i
hx : x ∈ ↑(H i)
⊢ ↑(Pi.evalMonoidHom (fun i => Gs i) j) (↑(MonoidHom.single (fun i => Gs i) i) x) ∈ H j
[PROOFSTEP]
by_cases h : j = i
[GOAL]
case pos
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
x : Gs i
hx : x ∈ ↑(H i)
h : j = i
⊢ ↑(Pi.evalMonoidHom (fun i => Gs i) j) (↑(MonoidHom.single (fun i => Gs i) i) x) ∈ H j
[PROOFSTEP]
subst h
[GOAL]
case pos
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
x : Gs j
hx : x ∈ ↑(H j)
⊢ ↑(Pi.evalMonoidHom (fun i => Gs i) j) (↑(MonoidHom.single (fun i => Gs i) j) x) ∈ H j
[PROOFSTEP]
simpa using hx
[GOAL]
case neg
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
x : Gs i
hx : x ∈ ↑(H i)
h : ¬j = i
⊢ ↑(Pi.evalMonoidHom (fun i => Gs i) j) (↑(MonoidHom.single (fun i => Gs i) i) x) ∈ H j
[PROOFSTEP]
simp [h, one_mem]
[GOAL]
case h₂
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
⊢ map (MonoidHom.single (fun i => Gs i) i) (K i) ≤ pi Set.univ K
[PROOFSTEP]
rw [le_pi_iff]
[GOAL]
case h₂
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
⊢ ∀ (i_1 : η),
i_1 ∈ Set.univ → map (Pi.evalMonoidHom (fun i => Gs i) i_1) (map (MonoidHom.single (fun i => Gs i) i) (K i)) ≤ K i_1
[PROOFSTEP]
intro j _hj
[GOAL]
case h₂
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
⊢ map (Pi.evalMonoidHom (fun i => Gs i) j) (map (MonoidHom.single (fun i => Gs i) i) (K i)) ≤ K j
[PROOFSTEP]
rintro _ ⟨_, ⟨x, hx, rfl⟩, rfl⟩
[GOAL]
case h₂.intro.intro.intro.intro
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
x : Gs i
hx : x ∈ ↑(K i)
⊢ ↑(Pi.evalMonoidHom (fun i => Gs i) j) (↑(MonoidHom.single (fun i => Gs i) i) x) ∈ K j
[PROOFSTEP]
by_cases h : j = i
[GOAL]
case pos
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
x : Gs i
hx : x ∈ ↑(K i)
h : j = i
⊢ ↑(Pi.evalMonoidHom (fun i => Gs i) j) (↑(MonoidHom.single (fun i => Gs i) i) x) ∈ K j
[PROOFSTEP]
subst h
[GOAL]
case pos
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
x : Gs j
hx : x ∈ ↑(K j)
⊢ ↑(Pi.evalMonoidHom (fun i => Gs i) j) (↑(MonoidHom.single (fun i => Gs i) j) x) ∈ K j
[PROOFSTEP]
simpa using hx
[GOAL]
case neg
G : Type u_1
G' : Type u_2
F : Type u_3
inst✝⁴ : Group G
inst✝³ : Group G'
inst✝² : MonoidHomClass F G G'
f : F
g₁ g₂ g₃ g : G
H₁ H₂ H₃ K₁ K₂ : Subgroup G
η : Type u_4
inst✝¹ : Finite η
Gs : η → Type u_5
inst✝ : (i : η) → Group (Gs i)
H K : (i : η) → Subgroup (Gs i)
i : η
hi : (i : η) → Gs i
j : η
_hj : j ∈ Set.univ
x : Gs i
hx : x ∈ ↑(K i)
h : ¬j = i
⊢ ↑(Pi.evalMonoidHom (fun i => Gs i) j) (↑(MonoidHom.single (fun i => Gs i) i) x) ∈ K j
[PROOFSTEP]
simp [h, one_mem]
|
namespace Lean4Axiomatic
/-! # Handedness -/
/--
Handedness: either left-handed or right-handed.
Intended to be used as a more meaniningful `Bool` type in contexts where it
applies. One example is in selecting the left- or right-hand side of an ordered
pair. Another is in specifying which side of a binary operator an algebraic
property acts on; a common one is the concept of a left inverse (`a⁻¹ * a ≃ 1`)
vs. a right inverse (`a * a⁻¹ ≃ 1`).
-/
inductive Hand where
| /-- Left hand. -/ L
| /-- Right hand. -/ R
/--
Selects the left-hand or right-hand argument, according to the given `Hand`.
**Named parameters**
- `α`: The `Sort` of the items to select.
-/
abbrev Hand.pick {α : Sort u} : Hand → α → α → α
| L, x, _ => x
| R, _, y => y
end Lean4Axiomatic
|
State Before: K : Type u₁
V : Type u₂
inst✝² : Field K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
⊢ ker (eval K V) = ⊥ State After: no goals Tactic: classical exact (Basis.ofVectorSpace K V).eval_ker State Before: K : Type u₁
V : Type u₂
inst✝² : Field K
inst✝¹ : AddCommGroup V
inst✝ : Module K V
⊢ ker (eval K V) = ⊥ State After: no goals Tactic: exact (Basis.ofVectorSpace K V).eval_ker |
module TestHelpers
using Base.Test
using JuMP
using MathProgBase
using MIPVerify
using MIPVerify: find_adversarial_example
using MIPVerify: NeuralNet
using MIPVerify: PerturbationFamily
const TEST_DEFAULT_TIGHTENING_ALGORITHM = lp
if Pkg.installed("Gurobi") == nothing
using Cbc
main_solver = CbcSolver(logLevel=0)
tightening_solver = CbcSolver(logLevel=0, seconds=20)
else
using Gurobi
main_solver = GurobiSolver(Gurobi.Env())
tightening_solver = GurobiSolver(Gurobi.Env(), OutputFlag=0, TimeLimit=20)
end
function get_main_solver()::MathProgBase.SolverInterface.AbstractMathProgSolver
main_solver
end
function get_tightening_solver()::MathProgBase.SolverInterface.AbstractMathProgSolver
tightening_solver
end
function get_new_model()::Model
solver = get_main_solver()
MathProgBase.setparameters!(solver, Silent = true)
return Model(solver=solver)
end
"""
Tests the `find_adversarial_example` function.
- If `x0` is already classified in the target label, `expected_objective_value`
should be 0.
- If there is no adversarial example for the specified parameters,
`expected_objective_value` should be NaN.
- If there is an adversarial example, checks that the objective value is as expected,
and that the perturbed output for the target label exceeds the perturbed
output for all other labels by `tolerance`.
"""
function test_find_adversarial_example(
nn::NeuralNet,
x0::Array{<:Real, N},
target_selection::Union{Integer, Array{<:Integer, 1}},
pp::PerturbationFamily,
norm_order::Real,
tolerance::Real,
expected_objective_value::Real,
) where {N}
d = find_adversarial_example(
nn, x0, target_selection, get_main_solver(),
pp = pp, norm_order = norm_order, tolerance = tolerance, rebuild=false,
tightening_solver=get_tightening_solver(), tightening_algorithm=TEST_DEFAULT_TIGHTENING_ALGORITHM)
println(d[:SolveStatus])
if d[:SolveStatus] == :Infeasible || d[:SolveStatus] == :InfeasibleOrUnbounded
@test isnan(expected_objective_value)
else
actual_objective_value = getobjectivevalue(d[:Model])
if expected_objective_value == 0
@test isapprox(actual_objective_value, expected_objective_value; atol=1e-4)
else
@test isapprox(actual_objective_value, expected_objective_value; rtol=5e-5)
perturbed_output = getvalue(d[:PerturbedInput]) |> nn
perturbed_target_output = maximum(perturbed_output[Bool[i∈d[:TargetIndexes] for i = 1:length(d[:Output])]])
maximum_perturbed_other_output = maximum(perturbed_output[Bool[i∉d[:TargetIndexes] for i = 1:length(d[:Output])]])
@test perturbed_target_output/(maximum_perturbed_other_output+tolerance)≈1 atol=5e-5
end
end
end
"""
Runs tests on the neural net described by `nn` for input `x0` and the objective values
indicated in `expected objective values`.
# Arguments
- `expected_objective_values::Dict`:
d[(target_selection, perturbation_parameter, norm_order, tolerance)] = expected_objective_value
`expected_objective_value` is `NaN` if there is no perturbation that brings the image
into the target category.
"""
function batch_test_adversarial_example(
nn::NeuralNet,
x0::Array{<:Real, N},
expected_objective_values::Dict
) where {N}
for (test_params, expected_objective_value) in expected_objective_values
(target_selection, pp, norm_order, tolerance) = test_params
@testset "target label = $target_selection, $(string(pp)) perturbation, norm order = $norm_order, tolerance = $tolerance" begin
test_find_adversarial_example(
nn, x0,
target_selection, pp, norm_order, tolerance, expected_objective_value)
end
end
end
end |
[STATEMENT]
lemma nextl: "MN.nextl (init DFA) u = h (R `` {u})"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. MN.nextl (init DFA) u = h (R `` {u})
[PROOF STEP]
apply (induct u rule: List.rev_induct, auto)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
1. init DFA = h (R `` {[]})
2. \<And>x xs. MN.nextl (init DFA) xs = h (R `` {xs}) \<Longrightarrow> nxt DFA (h (R `` {xs})) x = h (R `` {xs @ [x]})
[PROOF STEP]
apply (simp_all add: DFA_def hinv_def injh quotientI UN_equiv_class [OF eqR resp])
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done |
%% DEBUG SIMULATION SETUP %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; close all;
% ADD THE PROGRAM PATHS
addpath('environment');
addpath('objects');
addpath('toolboxes');
addpath('scenarios');
% CODE DEBUG COMMANDS %
% profile on
% profile viewer
fprintf('[SETUP]\tInitialising example script.\n');
%% INITIALISE ANY TOOLBOXES
% IntLab(); % Load Intlab
% OMAS_objectDiagnostics()
%% SIMULATION PARAMETERS
[~, userdir] = system('echo %USERPROFILE%'); % Get desktop path
sim_outputPath = strcat(userdir,'\desktop\openmas-data');
sim_vebosity = 1;
sim_warningDistance = 2;
sim_maxDuration = 15;
sim_timeStep = 0.1; % Nominal (0.25s)
sim_idleTimeOut = 5*sim_timeStep;
sim_publishFigures = false;
% sim_publishFigures = true;
sim_figureSet = {'all'};
% sim_figureSet = {'events','plan','inputs','isometric','gif'};
% sim_figureSet = {'plan','inputs','isometric','gif'};
% sim_figureSet = {'isometric','gif'};
%% SCENARIO PARAMETERS
sim_agentNumber = 5;
sim_agentRadius = 0.5;
sim_agentOrbit = 5;
sim_agentVelocity = 2;
sim_adjacencyMatrix = double(~eye(sim_agentNumber));
sim_waypointOrbit = 10;
sim_waypointRadius = 0.1;
sim_offsetAngle = pi/4;
sim_obstacleNumber = 3;
sim_noiseSigma = 0.2;
sim_plotScenario = true;
%% INITIALISE AGENTS
fprintf('[SETUP]\tAssigning agent definitions:\n');
for index = 1:sim_agentNumber
% BASIC CLASSES
% agentIndex{index} = objectDefinition('radius',sim_agentRadius);
% agentIndex{index} = agent('radius',sim_agentRadius);
% agentIndex{index} = agent_test('radius',sim_agentRadius);
% agentIndex{index} = agent_2D();
% agentIndex{index} = agent_2D_test('radius',sim_agentRadius);
agentIndex{index} = agent_example('radius',sim_agentRadius);
% QUADCOPTER DYNAMICS
% agentIndex{index} = quadcopter_legacy();
% agentIndex{index} = quadcopter();
% agentIndex{index} = quadcopter_formation('adjacencyMatrix',sim_adjacencyMatrix);
% ARdrone DYNAMICS
% agentIndex{index} = ARdrone_prev();
% agentIndex{index} = ARdrone('radius',sim_agentRadius);
% agentIndex{index} = ARdrone_LQR();
% agentIndex{index} = ARdrone_MPC();
% agentIndex{index} = fixedWing();
% agentIndex{index} = globalHawk();
% agentIndex{index} = boeing737();
% agentIndex{index} = A10();
% agentIndex{index} = planetoid();
% agentIndex{index} = earth();
% agentIndex{index} = moon();
% agentIndex{index} = ISS();
% FORMATION CONTROL
% agentIndex{index} = agent_formation('adjacencyMatrix',sim_adjacencyMatrix);
% agentIndex{index} = agent_formation_boids();
% agentIndex{index} = agent_formation_VO();
% agentIndex{index} = agent_formation_RVO();
% agentIndex{index} = agent_formation_HRVO();
% agentIndex{index} = agent_2D_formation_VO('adjacencyMatrix',sim_adjacencyMatrix);
% agentIndex{index} = agent_2D_formation_RVO();
% agentIndex{index} = agent_2D_formation_HRVO();
% agentIndex{index} = agent_2D_formation_ORCA();
% VECTOR SHARING;
% agentIndex{index} = agent_vectorSharing('radius',sim_agentRadius,'detectionRadius',25);
% agentIndex{index} = agent_2D_vectorSharing('radius',sim_agentRadius);
% INTERVAL AVOIDANCE
% agentIndex{index} = agent_interval();
% agentIndex{index} = agent_IA('radius',sim_agentRadius);
% agentIndex{index} = agent_2D_IA('radius',sim_agentRadius);
% VELOCITY OBSTACLE METHODS
% agentIndex{index} = agent_VO('radius',sim_agentRadius);
% agentIndex{index} = agent_RVO('radius',sim_agentRadius);
% agentIndex{index} = agent_HRVO('radius',sim_agentRadius);
% agentIndex{index} = agent_2D_VO('radius',sim_agentRadius);
% agentIndex{index} = agent_2D_RVO('radius',sim_agentRadius);
% agentIndex{index} = agent_2D_HRVO('radius',sim_agentRadius);
% agentIndex{index} = agent_2D_ORCA('radius',sim_agentRadius);
% agentIndex{index} = agent_2D_VO_withComplex('radius',sim_agentRadius);
% OBSTACLES
% agentIndex{index} = obstacle();
% agentIndex{index} = obstacle_cuboid();
% agentIndex{index} = obstacle_spheroid();
end
for index = 1:sim_obstacleNumber
% OBSTACLES
% obstacleIndex{index} = obstacle();
% obstacleIndex{index} = obstacle_cuboid();
% obstacleIndex{index} = obstacle_spheroid();
end
%% PLACE AGENT OBJECTS IN PRE-DEFINED SCENARIO
% FORMATION CONTROL TESTS
% [ objectIndex ] = GetScenario_corridor('agents',agentIndex,'adjacencyMatrix',sim_adjacencyMatrix,'plot',sim_plotScenario);
% [ objectIndex ] = GetScenario_formation_split('agents',agentIndex,'agentSpacing',4,'adjacencyMatrix',sim_adjacencyMatrix,'plot',sim_plotScenario,'noiseFactor',sim_noiseSigma);
% [ objectIndex ] = GetScenario_formation_fourObstacles('agents',agentIndex,'obstacleRadius',2,'plot',sim_plotScenario);
% % OBSTACLE TESTS
% [ objectIndex ] = GetScenario_fourCuboidObstacles('agents',agentIndex,'plot',sim_plotScenario);
% [ objectIndex ] = GetScenario_obstacleTrack('agents',agentIndex,'obstacles',obstacleIndex,'plot',sim_plotScenario);
% % AGENT TESTS
% [ objectIndex ] = GetScenario_twoLines('agents',agentIndex,'agentVelocity',sim_agentVelocity,'padding',5,'agentSeparation',sim_agentOrbit,'waypointSeparation',sim_waypointOrbit,'agentVelocity',sim_agentVelocity,'plot',sim_plotScenario);
[ objectIndex ] = GetScenario_concentricRing('agents',agentIndex,'agentOrbit',sim_agentOrbit,'agentVelocity',sim_agentVelocity,'waypointOrbit',sim_waypointOrbit,'waypointRadius',sim_waypointRadius,'plot',sim_plotScenario,'noiseFactor',sim_noiseSigma);
% [ objectIndex ] = GetScenario_concentricRing('agents',agentIndex,'agentOrbit',sim_agentOrbit,'agentVelocity',sim_agentVelocity,'waypointOrbit',sim_waypointOrbit,'offsetAngle',pi/2,'plot',sim_plotScenario,'noiseFactor',sim_noiseSigma);
% [ objectIndex ] = GetScenario_concentricSphere('agents',agentIndex,'agentOrbit',sim_agentOrbit,'agentVelocity',sim_agentVelocity,'waypointOrbit',sim_waypointOrbit,'plot',sim_plotScenario);
% [ objectIndex ] = GetScenario_concentricAngle('agents',agentIndex,'agentOrbit',sim_agentOrbit,'agentVelocity',sim_agentVelocity,'waypointOrbit',sim_waypointOrbit,'angle',sim_offsetAngle,'plot',sim_plotScenario);
% RANDOM TESTS
% [ objectIndex ] = GetScenario_random('objects',agentIndex,'plot',sim_plotScenario);
% [ objectIndex ] = GetScenario_randomNormal('objects',agentIndex,'plot',sim_plotScenario);
% [ objectIndex ] = GetScenario_randomUniform('objects',agentIndex,'is3D',false,'plot',sim_plotScenario);
% WAYPOINT TESTS
% [ objectIndex ] = GetScenario_waypointCurve('agents',agentIndex,'agentVelocity',sim_agentVelocity,'plot',sim_plotScenario);
% [ objectIndex ] = GetScenario_waypoint_90Degrees('agents',agentIndex,'agentVelocity',sim_agentVelocity,'plot',sim_plotScenario);
% % RL TESTS
% [ objectIndex ] = GetScenario_earthOrbit('plot',sim_plotScenario);
%% %%%%%% INITIALISE THE SIMULATION WITH THE OBJECT INDEX %%%%%%%%%%%%%%%%%
[DATA,META] = OMAS_initialise('objects',objectIndex,...
'duration',sim_maxDuration,...
'dt',sim_timeStep,...
'idleTimeOut',sim_idleTimeOut,...
'figures',sim_figureSet,...
'warningDistance',sim_warningDistance,...
'verbosity',sim_vebosity,...
'outputPath',sim_outputPath,...
'publishMode',sim_publishFigures);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clearvars -except DATA META
load(strcat(META.outputPath,'META.mat'));
load(strcat(META.outputPath,'EVENTS.mat'));
load(strcat(META.outputPath,'OBJECTS.mat'));
%% EXTRA GRAPHS (DEBUG)
% objectDATA = DATA.objectIndex{1,1}.DATA;
% figure()
% grid on;
% plot(META.TIME.timeVector,objectDATA.inputs)
% xlabel('time (s)');
% legend('Location','southeast');
|
lemma prime_factors_characterization_int: "S = {p. 0 < f (p::int)} \<Longrightarrow> finite S \<Longrightarrow> \<forall>p\<in>S. prime p \<Longrightarrow> abs n = (\<Prod>p\<in>S. p ^ f p) \<Longrightarrow> prime_factors n = S" |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.ring_theory.polynomial.scale_roots
import Mathlib.ring_theory.localization
import Mathlib.PostPort
universes u_1 u_4 u_2
namespace Mathlib
/-!
# Rational root theorem and integral root theorem
This file contains the rational root theorem and integral root theorem.
The rational root theorem for a unique factorization domain `A`
with localization `S`, states that the roots of `p : polynomial A` in `A`'s
field of fractions are of the form `x / y` with `x y : A`, `x ∣ p.coeff 0` and
`y ∣ p.leading_coeff`.
The corollary is the integral root theorem `is_integer_of_is_root_of_monic`:
if `p` is monic, its roots must be integers.
Finally, we use this to show unique factorization domains are integrally closed.
## References
* https://en.wikipedia.org/wiki/Rational_root_theorem
-/
theorem scale_roots_aeval_eq_zero_of_aeval_mk'_eq_zero {A : Type u_1} {S : Type u_4} [integral_domain A] [comm_ring S] {M : submonoid A} {f : localization_map M S} {p : polynomial A} {r : A} {s : ↥M} (hr : coe_fn (polynomial.aeval (localization_map.mk' f r s)) p = 0) : coe_fn (polynomial.aeval (coe_fn (localization_map.to_map f) r)) (scale_roots p ↑s) = 0 := sorry
theorem num_is_root_scale_roots_of_aeval_eq_zero {A : Type u_1} {K : Type u_2} [integral_domain A] [field K] [unique_factorization_monoid A] (g : fraction_map A K) {p : polynomial A} {x : localization_map.codomain g} (hr : coe_fn (polynomial.aeval x) p = 0) : polynomial.is_root (scale_roots p ↑(fraction_map.denom g x)) (fraction_map.num g x) := sorry
/-- Rational root theorem part 1:
if `r : f.codomain` is a root of a polynomial over the ufd `A`,
then the numerator of `r` divides the constant coefficient -/
theorem num_dvd_of_is_root {A : Type u_1} {K : Type u_2} [integral_domain A] [unique_factorization_monoid A] [field K] {f : fraction_map A K} {p : polynomial A} {r : localization_map.codomain f} (hr : coe_fn (polynomial.aeval r) p = 0) : fraction_map.num f r ∣ polynomial.coeff p 0 := sorry
/-- Rational root theorem part 2:
if `r : f.codomain` is a root of a polynomial over the ufd `A`,
then the denominator of `r` divides the leading coefficient -/
theorem denom_dvd_of_is_root {A : Type u_1} {K : Type u_2} [integral_domain A] [unique_factorization_monoid A] [field K] {f : fraction_map A K} {p : polynomial A} {r : localization_map.codomain f} (hr : coe_fn (polynomial.aeval r) p = 0) : ↑(fraction_map.denom f r) ∣ polynomial.leading_coeff p := sorry
/-- Integral root theorem:
if `r : f.codomain` is a root of a monic polynomial over the ufd `A`,
then `r` is an integer -/
theorem is_integer_of_is_root_of_monic {A : Type u_1} {K : Type u_2} [integral_domain A] [unique_factorization_monoid A] [field K] {f : fraction_map A K} {p : polynomial A} (hp : polynomial.monic p) {r : localization_map.codomain f} (hr : coe_fn (polynomial.aeval r) p = 0) : localization_map.is_integer f r :=
fraction_map.is_integer_of_is_unit_denom f
(is_unit_of_dvd_one (↑(fraction_map.denom f r)) (hp ▸ denom_dvd_of_is_root hr))
namespace unique_factorization_monoid
theorem integer_of_integral {A : Type u_1} {K : Type u_2} [integral_domain A] [unique_factorization_monoid A] [field K] {f : fraction_map A K} {x : localization_map.codomain f} : is_integral A x → localization_map.is_integer f x := sorry
theorem integrally_closed {A : Type u_1} {K : Type u_2} [integral_domain A] [unique_factorization_monoid A] [field K] {f : fraction_map A K} : integral_closure A (localization_map.codomain f) = ⊥ :=
iff.mpr eq_bot_iff
fun (x : localization_map.codomain f) (hx : x ∈ ↑(integral_closure A (localization_map.codomain f))) =>
iff.mpr algebra.mem_bot (integer_of_integral hx)
|
State Before: C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
⊢ RespectsIso (MorphismProperty.diagonal P) State After: case left
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
⊢ ∀ {X Y Z : C} (e : X ≅ Y) (f : Y ⟶ Z), MorphismProperty.diagonal P f → MorphismProperty.diagonal P (e.hom ≫ f)
case right
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
⊢ ∀ {X Y Z : C} (e : Y ≅ Z) (f : X ⟶ Y), MorphismProperty.diagonal P f → MorphismProperty.diagonal P (f ≫ e.hom) Tactic: constructor State Before: case left
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
⊢ ∀ {X Y Z : C} (e : X ≅ Y) (f : Y ⟶ Z), MorphismProperty.diagonal P f → MorphismProperty.diagonal P (e.hom ≫ f) State After: case left
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
X Y Z : C
e : X ≅ Y
f : Y ⟶ Z
H : MorphismProperty.diagonal P f
⊢ MorphismProperty.diagonal P (e.hom ≫ f) Tactic: introv H State Before: case left
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
X Y Z : C
e : X ≅ Y
f : Y ⟶ Z
H : MorphismProperty.diagonal P f
⊢ MorphismProperty.diagonal P (e.hom ≫ f) State After: no goals Tactic: rwa [diagonal_iff, pullback.diagonal_comp, hP.cancel_left_isIso, hP.cancel_left_isIso,
← hP.cancel_right_isIso _
(pullback.map (e.hom ≫ f) (e.hom ≫ f) f f e.hom e.hom (𝟙 Z) (by simp) (by simp)),
← pullback.condition, hP.cancel_left_isIso] State Before: C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
X Y Z : C
e : X ≅ Y
f : Y ⟶ Z
H : MorphismProperty.diagonal P f
⊢ (e.hom ≫ f) ≫ 𝟙 Z = e.hom ≫ f State After: no goals Tactic: simp State Before: C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
X Y Z : C
e : X ≅ Y
f : Y ⟶ Z
H : MorphismProperty.diagonal P f
⊢ (e.hom ≫ f) ≫ 𝟙 Z = e.hom ≫ f State After: no goals Tactic: simp State Before: case right
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
⊢ ∀ {X Y Z : C} (e : Y ≅ Z) (f : X ⟶ Y), MorphismProperty.diagonal P f → MorphismProperty.diagonal P (f ≫ e.hom) State After: case right
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
X Y Z : C
e : Y ≅ Z
f : X ⟶ Y
H : MorphismProperty.diagonal P f
⊢ MorphismProperty.diagonal P (f ≫ e.hom) Tactic: introv H State Before: case right
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
X Y Z : C
e : Y ≅ Z
f : X ⟶ Y
H : MorphismProperty.diagonal P f
⊢ MorphismProperty.diagonal P (f ≫ e.hom) State After: case right
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
X Y Z : C
e : Y ≅ Z
f : X ⟶ Y
H : MorphismProperty.diagonal P f
⊢ P (pullback.diagonal (f ≫ e.hom)) Tactic: delta diagonal State Before: case right
C : Type u
inst✝² : Category C
D : Type ?u.69245
inst✝¹ : Category D
inst✝ : HasPullbacks C
P : MorphismProperty C
hP : RespectsIso P
X Y Z : C
e : Y ≅ Z
f : X ⟶ Y
H : MorphismProperty.diagonal P f
⊢ P (pullback.diagonal (f ≫ e.hom)) State After: no goals Tactic: rwa [pullback.diagonal_comp, hP.cancel_right_isIso] |
inductive vec : Nat → Type where
| nil : vec 0
| cons : Int → vec n → vec n.succ
def vec_len : vec n → Nat
| vec.nil => 0
| x@(vec.cons h t) => vec_len t + 1
def vec_len' : {n : Nat} → vec n → Nat
| _, vec.nil => 0
| _, x@(vec.cons h t) => vec_len' t + 1
def tst1 : vec (n+1) → Int × vec (n+1) × vec n
| x@(vec.cons h t) => (h, x, t)
def tst2 : vec n → Option (Int × vec n)
| x@(vec.cons h t) => some (h, x)
| _ => none
example (a : Int) (x : vec n) : tst2 (vec.cons a x) = some (a, vec.cons a x) :=
rfl
def vec_len_non_as : vec n → Nat
| vec.nil => 0
| vec.cons h t => vec_len_non_as t + 1
def list_len : List Int → Nat
| List.nil => 0
| x@(List.cons h t) => list_len t + 1
|
import data.real.irrational
import topology.basic
import algebra.order.floor
--OUTPUT 1
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
-- Let $α$ be an irrational number
assume α : ℝ,
assume hα_irrat : irrational α,
-- show the fractional parts of the integer multiples of $α$ form a dense subset of the unit interval
have Icc_subset : ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) ⊆ set.Icc 0 1, from --assume m : ℤ, by {rw int.fract_eq,
assume m : ℤ, by {rw int.fract_eq, simp [int.fract_bound_eq], },
have closure_subset_eq : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) ⊆ set.Icc 0 1, from by {rw ← Icc_subset, exact closure_subset _ _},
have h1 : ∀ x, x ∈ set.Icc 0 1 → x ∈ closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)), from begin
assume (x : ℝ),
assume : x ∈ set.Icc 0 1,
have h2 : ∀ n : ℤ, ∃ (m : ℤ), ∃ (M : ℤ), (M ≥ 0 ∧ M ≤ n) ∧
(int.fract (α * ↑m) - int.fract (α * ↑n)) < x ∧ int.fract (α * ↑m) ∈ set.Icc 0 1, from begin
assume n : ℤ,
have h3 : ∃ m : ℤ, int.fract (α * ↑m) < x, from begin
have exists_nat : ∃ n : ℕ, (n : ℝ) ≥ x, from exists_nat_ge x,
show ∃ m : ℤ, int.fract (α * ↑m) < x, from exists.elim exists_nat
(assume n, assume h4 : n ∈ ℕ, assume h5 : (↑n : ℝ) ≥ x,
exists.elim h5 (assume h6 : ↑n = x,
obtain (m : ℕ) (h7 : ↑n = ↑m * α)
(h8 : ↑n > (↑m : ℝ) * α → abs (↑n - ↑m * α) ≤ 1), from hα_irrat x,
have h9 : m ∈ ℤ, from exists.elim h8 (assume m : ℤ, assume h10 : ↑n = ↑m * α,
have h11 : ↑m ∈ ℕ, from (nat.of_int_eq_coe.mp h10).symm ▸ h4,
show m ∈ ℤ, from int.coe_nat_of_nat h11),
have h10 : ↑(nat.fract m) = x, from nat.fract_eq_of_eq h7,
have h11 : 1 ≥ 0, from trivial,
have h12 : int.fract ↑m = int.fract (α * ↑m), from begin
show int.fract ↑m = int.fract ↑m * α - int.fract ↑m + int.fract (α * ↑m), by ring,
end,
have h13 : int.fract ↑m = int.fract (α * ↑m), from by {rw nat.fract_eq (by {have h14 : ↑m ∈ ℤ, from exists.elim h8 (assume m : ℤ,
assume h15 : ↑n = ↑m * α, show ↑m ∈ ℤ, from int.coe_nat_of_nat h4), rw nat.fract_eq}), rw nat.fract_eq at h12,
rw h10 at h12, rw ← h12, simp [int.fract_bound_eq], assumption,},
have h14 : int.fract ↑m < x, from by {rw ← h10, rw int.fract_eq,
simp [int.fract_bound_eq], assumption,},
have h15 : int.fract (α * ↑m) = int.fract ↑m, from by rw [h13, mul_comm],
have h16 : int.fract (α * ↑m) < x, from by rw ← h15 at h14,
show _, from ⟨↑m, h9, h16⟩)),
have h7 : ∃ (m : ℤ), int.fract (α * ↑m) < x, from exists.elim h3 (assume m : ℤ,
assume h8 : int.fract (α * ↑m) < x, show _, from ⟨m, h8⟩),
show ∃ (m : ℤ), ∃ (M : ℤ), (M ≥ 0 ∧ M ≤ n) ∧
(int.fract (α * ↑m) - int.fract (α * ↑n)) < x ∧ int.fract (α * ↑m) ∈ set.Icc 0 1, from exists.elim h7 (assume m : ℤ,
assume h9 : int.fract (α * ↑m) < x, exists.elim h9 (assume h10 : int.fract (α * ↑m) < x,
exists.elim (le_iff_exists_add.mp (le_of_lt h10)) (assume M : ℤ, assume h11 : int.fract (α * ↑m) + (↑M : ℝ) = x,
exists.elim h11 (assume h12 : int.fract (α * ↑m) + ↑M = x,
exists.elim h12 (assume h13 : int.fract (α * ↑m) + ↑M = x,
show _, from ⟨int.of_nat (nat.fract m), by {have h14 : ↑m = ↑m * α, from mul_one_eq_of_irrational hα_irrat,
rw h14 at h13, rw mul_comm at h13, rw nat.fract_eq at h13, rw ← nat.fract_eq at h13, rw ← h13, rw mul_comm,
rw int.of_nat_eq_coe, simp}, h13 ▸ le_refl _, by {rw int.fract_eq at h13, rw mul_comm at h13, simp at h13, rw [← h13,int.fract_add], ring,},
by {have m_bound : ↑m ∈ ℤ, from nat.le.dest (nat.fract_le_nat h10) ▸ h9.1,
show int.fract (α * ↑m) ∈ set.Icc 0 1, from by {rw int.fract_eq, simp [int.fract_bound_eq],
have h14 : ↑m < ↑m + 1, from exists.elim h10 (assume h15 : α > 0, by linarith [h15]) ,
have h15 : (↑m : ℝ) ≥ 0, from nat.succ_le_iff.mp h14, rw [int.fract_eq, mul_comm] at h10,
have h16 : (α * ↑m) - ↑m < α, from
begin
have h17 : (α * ↑m) - ↑m < ↑m + 1 - ↑m, from ← h10,
have h18 : (α * ↑m) - ↑m < ↑m, from h17 ▸ nat.cast_succ_le_self h14,
have h19 : (α * ↑m) - ↑m + ↑m = ↑m * α, from by ring, rw ← h19 at h18,
have h20 : (α * ↑m) - ↑m + ↑m < ↑m * α, from h18, have h21 : (α * ↑m) - ↑
end --Needs more than 2000 tokens!
--OUTPUT 2
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
--Let $\alpha$ be an irrational number
assume hα_irrat : irrational α,
--Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$
have h1 : ∀ (i j : ℤ) (h_ij_distinct : i ≠ j), int.fract (α * ↑i) ≠ int.fract (α * ↑j), from assume (i j : ℤ) (h_ij_distinct : i ≠ j), by
{
have h1_1 : α * ↑i - (α * ↑i) ≠ α * ↑j - (α * ↑j), from
begin
rw int.fract,
rw int.fract,
assume h : α * ↑i - (α * ↑i) = α * ↑j - (α * ↑j),
rw [h,← int.cast_mul,← int.cast_mul i,← int.cast_mul j,← int.cast_mul (i-j),← int.cast_mul i] at h,
have h1_1_1 : rational (α * ↑j - (α * ↑j)), from by {rw ← h, apply rat_of_real_fract_of_real,},
have h1_1_2 : rational (α * ↑i - (α * ↑i)), by {apply rat_of_real_fract_of_real,},
have h1_1_3 : rational ((↑i-j) * (α * ↑i - (α * ↑i))), from rat.mul_self h1_1_2,
have h1_1_4 : (↑i-j) * (α * ↑i - (α * ↑i)) = (1 : ℝ), from by {rw ← int.cast_mul (i-j),rw ← h,rw ← int.cast_one,ring,},
have h1_1_5 : rational ((1 : ℝ)), from h1_1_3,
have h1_1_6 : ((1 : ℝ)) = (1 : ℚ), by {apply rat.eq_of_mul_self_eq_one h1_1_5,},
have h1_1_7 : ((1 : ℝ)) = rat.cast ((1 : ℚ)), by {rw h1_1_6,rw rat.cast_one,},
have h1_1_8 : ((1 : ℝ)) = 1, by {rw ← h1_1_7,apply rat.cast_injective,},
have h1_1_9 : 1 ≠ 0, from by {unfold has_zero.zero,rw h1_1_8,refl,},
have h1_1_10 : ↑i - j ≠ 0, from by {contradiction,},
rw [h1_1_4,← int.cast_mul (↑i-j),← int.cast_mul (↑i-j),← int.cast_mul (↑i-j),int.cast_one] at h1_1_1,
rw [← int.cast_mul (↑i-j)] at h1_1_3,
have h1_1_11 : (1 : ℚ) * ((↑i-j) * α) = (1 : ℚ), from by {rw ← int.cast_mul (↑i-j),rw ← rat.cast_one,rw ← h,rw ← rat.cast_mul,rw ← rat.cast_mul,ring,},
have h1_1_12 : (1 : ℚ) * ((↑i-j) * α) = (1 : ℚ), from by {rw ← rat.cast_one,rw ← h1_1_1,rw rat.cast_mul,rw rat.cast_mul,},
have h1_1_13 : (1 : ℚ) = rat.cast ((↑i-j) * α), from by {rw h1_1_12,rw h1_1_11,},
have h1_1_14 : (1 : ℝ) = (↑i-j) * α, from by {rw ← rat.cast_one,rw ← h1_1_13,apply rat.cast_injective,},
have h1_1_15 : (1 : ℝ) = ((↑i-j) : ℚ) * α, from by {rw ← int.cast_mul (i-j),rw h1_1_14,},
have h1_1_16 : (1 : ℝ) = ((↑i-j) : ℚ) * α, from by {rw ← rat.cast_one,rw ← h1_1_15,apply rat.cast_injective,},
have h1_1_17 : (1 : ℚ) = ((↑i-j) : ℚ) * α, from by ring at h1_1_16,
exact hα_irrat h1_1_17,
end,
exact ne_of_lt (abs_int_fract_lt_one (α * ↑i)) (abs_int_fract_lt_one (α * ↑j)) h1_1,
},
--If this were not true, then
--$$
--i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor,
--$$
--which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$.
have h2 : ∀ (i j : ℤ) (h_ij_distinct : i ≠ j), rat.cast (α) ≠ (((rat.cast (α * ↑i)) - (rat.cast (α * ↑j))) / (↑i - ↑j)), from
assume (i j : ℤ) (h_ij_distinct : i ≠ j),
begin
assume h : rat.cast (α) = (((rat.cast (α * ↑i)) - (rat.cast (α * ↑j))) / (↑i - ↑j)),
rw [rat.cast_mul,rat.cast_mul] at h,
have h1 : (rat.cast (α * ↑i)) - (rat.cast (α * ↑j)) = (rat.cast (α)) * (↑i - ↑j), from by {rw ← h,ring,},
have h2 : rat.cast (α * ↑i) - rat.cast (α * ↑j) = rat.cast (α) * (↑i - ↑j), from by rw [rat.cast_mul] at h1,
have h3 : rat.cast (α * ↑i) = rat.cast (α) * ↑i, from by {apply rat.mul_self,},
have h4 : rat.cast (α * ↑j) = rat.cast (α) * ↑j, from by {apply rat.mul_self,},
have h5 : rat.cast (α) = rat.cast (α) * ↑i, from by {apply rat.cast_injective,},
have h6 : rat.cast (α) = rat.cast (((↑i) : ℚ) * α), from by rw [← h5,← rat.cast_one,← rat.cast_mul,← rat.cast_mul],
have h7 : rat.cast (α) = rat.cast (((↑i) : ℚ) * α), from by ring at h3,
have h8 : rational (rat.cast (α)), from by {apply rat.cast_ne_zero,},
have h9 : rat.cast (((↑i) : ℚ) * α) ≠ rat.cast 0, from by {contradiction,},
have h10 : rat.cast (α) ≠ 0,
end --Needs more than 2000 tokens!
--OUTPUT 3
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
-- Let $\alpha$ be an irrational number. Then
assume hα_irrat : irrational α,
-- for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$.
have h2 : ∀ i j : ℤ, i ≠ j → (int.fract (α * ↑i)) ≠ (int.fract (α * ↑j)), from
assume (i j : ℤ) (hne : i ≠ j),
-- If this were not true, then $i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor$,
have h2a : (α * ↑i) - (int.to_nat (α * ↑i)) = (int.fract (α * ↑i)) := by {rw fract_eq_sub_floor,ring},
have h2b : (α * ↑j) - (int.to_nat (α * ↑j)) = (int.fract (α * ↑j)) := by {rw fract_eq_sub_floor,ring},
assume h2c : (int.fract (α * ↑i)) = (int.fract (α * ↑j)),
rw h2c at h2a h2b,
-- which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$.
have h2d : (α - int.fract α) + (int.fract α) = α := by ring,
have h2e : (int.fract α) = α - (α - int.fract α) := by ring,
have h2f : (α - int.fract α) = (α * ↑i) - (int.to_nat (α * ↑i)) := by rw h2a,
have h2g : (int.fract α) = (α * ↑j) - (int.to_nat (α * ↑j)) := by rw h2b,
have h2h : (α - int.fract α) = (α * ↑j) - (int.to_nat (α * ↑j)) := by rw h2e h2g,
have h2i : (α - int.fract α) - ((α * ↑j) - (int.to_nat (α * ↑j))) = 0 := by rw h2f h2h,
have h2j : (α * ↑i) - (int.to_nat (α * ↑i)) - ((α * ↑j) - (int.to_nat (α * ↑j))) = 0 := by rw ← nat.cast_sub h2i,
have h2k : (int.to_nat (α * ↑i)) - (int.to_nat (α * ↑j)) = 0 := by rw ← int.coe_nat_sub h2j,
have h2l : (int.to_nat (α * ↑i)) = (int.to_nat (α * ↑j)) := by rw nat.eq_zero_iff_zero_eq h2k,
have h2m : (α * ↑i) = (α * ↑j) := by {rw ← int.cast_mul,repeat {rw ← int.coe_nat_eq_coe_nat_iff},exact h2l},
have h2n : (α * (↑i - ↑j)) = 0 := by rw h2m,
have h2o : α = 0 := by rw int.cast_mul h2n,
have h2p : (α - int.fract α) + (int.fract α) = α := by ring,
have h2q : (int.fract α) = α - (α - int.fract α) := by ring,
have h2r : (α - int.fract α) = (α * ↑i) - (int.to_nat (α * ↑i)) := by rw h2a,
have h2s : (int.fract α) = (α * ↑j) - (int.to_nat (α * ↑j)) := by rw h2b,
have h2t : (α - int.fract α) = (α * ↑j) - (int.to_nat (α * ↑j)) := by rw h2q h2s,
have h2u : (α - int.fract α) - ((α * ↑j) - (int.to_nat (α * ↑j))) = 0 := by rw h2r h2t,
have h2v : (α * ↑i) - (int.to_nat (α * ↑i)) - ((α * ↑j) - (int.to_nat (α * ↑j))) = 0 := by rw ← nat.cast_sub h2u,
have h2w : (int.to_nat (α * ↑i)) - (int.to_nat (α * ↑j)) = 0 := by rw ← int.coe_nat_sub h2v,
have h2x : (int.to_nat (α * ↑i)) = (int.to_nat (α * ↑j)) := by rw nat.eq_zero_iff_zero_eq h2w,
have h2y : (α * ↑i) = (α * ↑j) := by {rw ← int.cast_mul,repeat {rw ← int.coe_nat_eq_coe_nat_iff},exact h2x},
have h2z : (α * (↑i - ↑j)) = 0 := by rw h2y,
have h2aa : α = 0 := by rw int.cast_mul h2z,
have h2ab : false := by {apply hα_irrat h2aa,},
exact absurd h2ab (show (int.fract (α * ↑i)) ≠ (int.fract (α * ↑j)), from h2ab),
-- Hence, $S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}$
have h3 : univ ⊆ (Π (m : ℤ), (int.fract (α * ↑m))), from by {
assume (n : ℤ),
existsi n, simp, },
-- is an infinite subset of $\left[0,1\right]$
have h4 : ∀ i j : ℤ, i ≠ j → (int.fract (α * ↑i)) ≠ (int.fract (α * ↑j)), from
assume (i j : ℤ) (hne : i ≠ j), h2 i j hne,
have h5 : ((λ m : ℤ, (int.fract (α * ↑m))) '' univ) = univ, from by rw set.eq_univ_of_forall h4,
-- By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$.
have h6 : closure ((λ m : ℤ, (int.fract (α * ↑m))) '' (@set.univ ℤ)) ⊆ set.Icc 0 1, from
by rw ← h5.symm; apply closure_subset,
-- To show that $S$ is dense in $[0, 1]$,
have h7 : ∀ y : ℝ, 0 ≤ y → y ≤ 1 → ∃ z : ℤ, 0 < (int.fract (α * ↑z)) ∧ (int.fract (α * ↑z)) ≤ y, from
by {
-- consider $y \in[0,1]$, and $\epsilon>0$.
assume (y : ℝ) (hy_pos : 0 ≤ y) (hy_le_one : y ≤ 1),
--
end --Needs more than 2000 tokens!
--OUTPUT 4
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
--let S := {x : ℝ | ∃ m : ℤ, x = α * (↑m)},
-- let $S := \{\{x\} \mid x \in \R \}$
let S : set ℝ := {int.fract x | x : ℝ},
-- S is an infinite subset of $[0,1]$, by the comment above
have hS_infinite : infinite S, from by
{ -- (the fractional parts of) the integer multiples of an irrational number form an infinite set
-- hence S is an infinite set, as required
exact @set.infinite_of_injective_to_univ ℝ _ ℤ (λ (x : ℝ), int.fract x)
(λ x y, int.fract_eq_fract) (λ (m : ℤ), int.fract (α * ↑m))
(mt (int.fract_eq_of_irrational_of_eq hα_irrat))
(λ m x, begin
{ assume hx : x = α * ↑m,
have h1 : (int.fract (α * ↑m)) = int.fract x, from by {rw hx, refl,},
apply @exists_of_mem ℝ _ _ _ _ _ h1, },
end)
(λ x, int.fract_ne_zero),
},
-- The set of integers is bounded
let Z : set ℤ := set.Icc (int.of_nat 0) (int.of_nat 0),
have hZ_bounded : is_bounded_above Z, from by {exact set.bounded_univ,},
-- The fractional parts of the integer multiples of an irrational number is a subset of the unit interval
have h1 : ((λ (m : ℤ), int.fract (α * ↑m) ) '' (@set.univ ℤ)) ⊆ S, from @set.subset.trans ((λ (m : ℤ), int.fract (α * ↑m)) '' Z) _ _ (set.image_subset_iff.mpr ⟨by obviously, by obviously⟩),
-- The fractional parts of the integer multiples of an irrational number is dense in the unit interval
have h2 : closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1, from
begin
have h3 : ∀ (x : ℝ) (hx : x ∈ closure (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)), ∃ (n : ℤ), n * (((int.fract (α * ↑n) : ℝ)) - x) > 0, from
begin
assume (x : ℝ) (hx : x ∈ closure (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)),
show ∃ (n : ℤ), n * (((int.fract (α * ↑n) : ℝ)) - x) > 0, from by
{ -- There exists a limit point of $S$ in $[0,1]$, by the Bolzano-Weierstrass theorem
-- Hence there exists an $x$ such that $(int.fract (α * ↑(int.of_nat 0)) : ℝ) < x < (int.fract (α * ↑(int.of_nat 1)) : ℝ)$
-- Hence there exists an $n$ such that $n * (((int.fract (α * ↑n) : ℝ)) - x) > 0$
have h4 : ∃ (n : ℤ), n * (((int.fract (α * ↑n) : ℝ)) - x) > 0, from by
{
have h5 : interval.is_open (set.Icc (int.fract (α * ↑(int.of_nat 0))) (int.fract (α * ↑(int.of_nat 1)))) :=
interval.is_open_Ioo (int.fract (α * ↑(int.of_nat 0))) (int.fract (α * ↑(int.of_nat 1))),
have h6 : x ∈ closure (λ (m : ℤ), int.fract (α * ↑m) ) '' (@set.univ ℤ), from hx,
have h7 : ∃ (n : ℤ), n * (((int.fract (α * ↑n) : ℝ)) - x) > 0, from @exists_nat_gt _ _
(λ (n : ℤ), (int.fract (α * ↑n) : ℝ) - x) 0
(mt (by {exact int.fract_lt_one (α * ↑(int.of_nat 1)),}) x) h4,
exact h7, },
exact h4, },
end,
show closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1, from
begin
have h5 : ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ⊆ set.Icc 0 1, from
begin
have h6 : (int.fract (α * ↑(int.of_nat 0)) : ℝ) = 0, from by
{
have h7 : (int.fract (α * ↑(int.of_nat 0)) : ℝ) = int.fract (int.of_nat 0), from by
{
have h8 : (int.fract (α * ↑(int.of_nat 0)) : ℝ) = int.fract (int.of_nat 0), from by
{
have h9 : ∀ (m : ℤ), int.fract (α * ↑m) = int.fract (int.of_nat (int.nat_abs m)), from
begin
have h10 : ∀ (m : ℤ), int.fract (α * ↑m) = int.fract (int.of_nat (int.nat_abs m)), from begin
assume (m : ℤ),
have h11 : int.fract (α * ↑m) ∈ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ), from
by apply @set.mem_image _ _ ℤ _ _ _ _ (int.fract (α * ↑m)) m,
have h12 : (int.fract (α * ↑m)) ∈ closure (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ), from h11,
have h13 : (int.fract (α * ↑m)) ∈ set.Icc 0 ((int.fract (α * ↑(int.of_nat 1))) : ℝ), from @mem_of_mem_closure ℝ _ _ (λ (m : ℤ), int.fract (α * ↑m)) h5
(int.fract (α * ↑m)) h12,
show int.fract (α * ↑m) = int.fract (int.of_nat (int.nat_abs m)), from begin
show int.fract (α * ↑m) = int.fract (int.of_nat (int.nat_abs m)), from by
{
have h14 : (int.fract (α * ↑m) : ℝ) < ((int.fract (α * ↑(int.of_nat 1)) : ℝ)), from by
{
exact @show (int.fract (α * ↑(int.of_nat 0))) < (int.fract (α * ↑(int.of_nat 1))), from
begin
have h15 : int.fract (int.of_nat (int.nat_abs (int.of_nat 1))) = int.fract (α * ↑(int.
end --Needs more than 2000 tokens!
--OUTPUT 5
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
-- don't know how to prove this yet, but it's true
obviously,
end
--OUTPUT 6
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
-- Lebesgue measure theory, one can show that the set (irrationals) has measure $1$.
have h1 : measure_theory.measure (set.Icc 0 1) = 1, from by {
rw [measure_theory.measure_Icc, measure_theory.measure_Icc_self],
norm_num, },
have h2 : measure_theory.is_measurable (closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ))), from by {
rw ← (measure_set_closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ))),
rw ← measure_theory.measure_univ, exact measure_theory.is_measurable_univ,
},
-- Then one can show that the closure of rationals has measure $1$.
have h3 : measure_theory.measure (closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ))) = 1, from by {
rw measure_set_closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)),
-- By the Axiom of Choice, the set of rationals is countable.
have h4 : fintype.card ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) ≤ ℕ, from by {
apply fintype.card_image_le,
have h5 : fintype.card (set.univ) ≤ ℕ, { exact fintype.card_le_nat (fintype.card_univ : fintype.card (set.univ) ≤ ℕ) },
rw ← fintype.card_fintype at h5, show fintype.card (λ (m : ℤ), int.fract (α * ↑m)) ≤ ℕ, from by {exact h5, },
},
rw ← ← card_set_closed_fract,
show fintype.card ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) ≤ fintype.card (set.univ), from by {
rw ← fintype.card_fintype, exact h4, },
norm_num, },
have h6 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) = set.Icc 0 1, from by {
show (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) = set.Icc (0 : ℝ) 1, from
eq.symm (eq_of_measure_eq_of_measurable h1 h2 h3), },
exact h6,
end
--OUTPUT 7
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
/-
The fractional parts of the integer multiples of an irrational number form a dense subset of the unit interval
-/
sorry
end
--OUTPUT 8
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
let α_set := (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ),
have h1 : (α_set : set ℝ) = (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ), from by {obviously},
-- Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then
have h2 : ∀ (i j : ℤ), i ≠ j → (int.fract (α * ↑i) ≠ int.fract (α * ↑j)), from assume (i j : ℤ) (hij : i ≠ j), by {
-- Then $i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor$,
have hij2 : int.fract (α * ↑i) = int.fract (α * ↑j), from int.fract_mul_cancel_left hij,
-- which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$.
have hα_rat : ℚ/1 = (α * ↑i - ↑i * int.fract (α * ↑i) - α * ↑j + ↑j * int.fract (α * ↑j)) / (↑i - ↑j), from by {rw [hij2, add_sub_cancel'],norm_cast, ring,},
have hα_rat2 : ℚ/1 = (α * ↑i - α * ↑j - ↑i * int.fract (α * ↑i) + ↑j * int.fract (α * ↑j)) / (↑i - ↑j), from by {ring,},
-- Then $i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor$, which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$.
have hα_rat3 : ℚ/1 = (α * ↑i - α * ↑j) / (↑i - ↑j), from by {ring,},
have hα_rat4 : ℚ/1 = α * (↑i - ↑j) / (↑i - ↑j), from by {ring,},
-- hence, we must have $\{i \alpha\} \neq\{j \alpha\}$
have hα_rat5 : α ≠ ℚ/1, from by {apply hα_irrat, rw ←hα_rat4,},
have hα_rat6 : int.fract (α * ↑i) ≠ int.fract (α * ↑j), from by {ring at hα_rat5,exact hα_rat5,},
show int.fract (α * ↑i) ≠ int.fract (α * ↑j) end,
-- Hence, $S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}$ is an infinite subset of $\left[0,1\right]$.
have h3 : α_set.finite = ff, from by {
have h3 : ∀ i : ℤ, (i : ℝ) ≠ 0, from assume i : ℤ, by {
assume h : (i : ℝ) = 0,
from show i ≠ 0, from dec_trivial,},
have h4 : ∀ i : ℤ, int.fract (α * ↑i) ≠ 0, from assume i : ℤ, by {
assume h : int.fract (α * ↑i) = 0,
have h5 : int.fract (α * ↑i) = int.fract (↑i * (α : ℤ)), from by {
rw ← int.fract_mul_cancel_left,norm_cast,ring,},
-- have h5 : int.fract (α * i) = 0, from by {rw ← int.fract_mul_cancel_left,norm_cast,ring,},
show int.fract (α * i) ≠ 0, from by {rw h5 at h, exact h3 i h,},},
have h5 : ∀ i : ℤ, (int.fract (α * ↑i) : ℝ) ≠ 0, from assume i : ℤ, by {
assume h : (int.fract (α * ↑i) : ℝ) = 0,
from show int.fract (α * ↑i) ≠ 0, from by { rw ← show (int.fract (α * ↑i) : ℝ) = ((int.fract (α * ↑i) : ℝ) * (1 : ℝ)) / (1 : ℝ), from by { norm_cast, ring }, },},
show α_set.finite = ff, from by {
unfold α_set,
rw ← set.finite_univ,
apply infinite.infinite_iff_fintype_nonempty,
apply by { existsi ℤ, split,apply fintype.of_injective_of_not_mem_empty (λ x y, by {
assume h : x ≠ y, exact h2 x y h}) h5, apply nonempty.intro (0 : ℤ),}
},},
have h4 : ∀ (j : ℤ), ∃! (i : ℤ), i ≠ j ∧ int.fract (α * ↑i) = int.fract (α * ↑j), from by {
assume j : ℤ,
-- By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$.
have h4 : ∃! (i : ℤ), (int.fract (α * ↑i) : ℝ) = 0, from by {
have h4 : ∀ (i : ℤ), (int.fract (α * ↑i) : ℝ) = 0 → i = 0, from by {
assume i : ℤ, assume h : (int.fract (α * ↑i) : ℝ) = 0,
have h5 : int.fract (α * ↑i) = 0, from by {
have h5 : (int.fract (α * ↑i) : ℝ) = 0, from by {rw ← show ((int.fract (α * ↑i) : ℝ) : ℤ) = (int.fract (α * ↑i) : ℤ), from by {norm_cast,},},
show int.fract (α * ↑i) = 0, from by {rw h5 at h, exact h,},},
show i = 0, from by {rw h5, ring,},},
have h5 : ∃ i : ℤ, (int.fract (α * ↑i) : ℝ) = 0, from by {
have h5 : ∀ i : ℤ, (i : ℤ) ≠ 0 → (int.fract (α * ↑i) : ℝ) ≠ 0, from by {
assume i : ℤ, assume hi : (i : ℤ) ≠ 0,
have hi2 : (int.fract (α * ↑i) : ℝ) ≠ 0, from by {
have hi2 : int.fract (α * ↑i) ≠ 0, from by {
have hi2 : int.fract (α * ↑i) ≠ 0, from by {
have hi2 : (i : ℝ) ≠ 0, from by {rw ← show (i : ℤ) ≠ (0 : ℤ), from hi,},
show
end --Needs more than 2000 tokens!
--OUTPUT 9
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
-- Consider $S$
let S : set ℝ := λ i : ℤ, has_fract.fract i α,
-- $S$ is an infinite subset of $\left[0,1\right]$
have h1 : S ⊆ Icc 0 1 ∧ infinite S, from by {
split,
have h2 : ∀ i : ℤ, (0 ≤ has_fract.fract i α) ∧ (has_fract.fract i α < 1), from by {
assume i : ℤ,
have l : 0 ≤ has_fract.fract i α, from by {
rw ← int.coe_nat_add, rw int.coe_nat_zero, rw int.fract_eq, ring,
from int.fract_nonneg},
have r : has_fract.fract i α < 1, from by {
rw int.fract_eq, ring, rw int.coe_nat_zero, rw int.coe_nat_one,ring,
from int.fract_lt_one},
show (0 ≤ has_fract.fract i α) ∧ (has_fract.fract i α < 1), from ⟨l, r⟩,
},
from set.subset.antisymm (λ i : ℤ, (h2 i).left) (λ i : ℤ, (h2 i).right),
have h3 : ∀ i j : ℤ, i ≠ j → has_fract.fract i α ≠ has_fract.fract j α, from by {
assume i j : ℤ, assume h : i ≠ j,
have h1 : i * α ≠ j * α, from by {
assume h2 : i * α = j * α,
have h3 : α = (i-j)*⁻¹*(i*α - j*α), from by {
rw [h2, int.neg_mul_eq_neg_mul_symm, sub_eq_neg_add], rw add_comm, rw add_mul, ring,
},
have h4 : (i-j)*⁻¹*(i*α - j*α) ∈ ℤ, from by {
rw h3, apply int.coe_nat_div_int, intros h4, exact h4.elim (λ h5 : j = 0, by {
calc
i = i*1 : by {rw mul_one}
... = i * (j+j) : by {rw h5, rw zero_add}
... = j* (i+i) : by {rw mul_comm, ring}
... = 0 : zero_mul,
apply h.symm,
}), intros h5, have h6 := h5.symm, have h7 : i - j ≠ 0, from h.symm,
apply int.ne_of_nat_ne_nat (int.coe_nat_ne_coe_nat_of_ne h7),
},
have h5 : irrational α, from hα_irrat,
show false, from h5 h4,
},
have h2 : i * α - j * α ≠ 0, from (int.ne_of_mul_ne_zero h1),
have h3 : (i-j)*⁻¹ ≠ 0, from by {
intros h4, exact absurd h4 ((int.coe_nat_ne_coe_nat_of_ne h).symm),
},
have h4 : (i * α - j * α) * (i-j)⁻¹ ≠ 0, from
by {rw ← inv_eq_iff_mul_eq_one, apply mul_ne_zero, exact h2, exact h3},
have h5 : i*α-j*α ≠ 0, from
by {rw ← mul_inv_cancel h4, rw mul_one},
have h6 : i * α - j * α ∈ ℤ, from by {
rw ← int.fract_eq, ring, exact int.fract_nonneg, exact int.fract_lt_one,
},
have h7 : int.fract (i * α) ≠ int.fract (j * α), from by {
rw int.fract_eq, ring, rw int.coe_nat_zero, rw int.coe_nat_zero, ring,
from h5,
},
show has_fract.fract i α ≠ has_fract.fract j α, from h7,
},
from ⟨infinite_int, h3⟩,
},
-- So, $S$ has a limit point in $[0, 1]$
have h2 : limit_point S (Icc 0 1), from by {
have h3 : limit_point S (closure (Icc 0 1)), from by {
rw ← closure_Icc,
rw ← closure_eq_of_is_closed (is_closed_Icc 0 1),
apply h1.right.limit_point,
},
show limit_point S (Icc 0 1), from by {
apply limit_point_of_limit_point_of_closed h3, from is_closed_Icc 0 1,
},
},
-- Show that $S$ is dense in $[0, 1]$
have h3 : dense S (Icc 0 1), from by {
assume y : ℝ, assume hi : y ∈ Icc 0 1, assume ε : ℝ, assume hε : 0 < ε,
have h4 : ∃ x : ℝ, x ∈ S ∧ x < ε, from h2.mem_of_lt_ne hi hε,
obtain (x : ℝ) (hx : x ∈ S ∧ x < ε), from h4,
have h5 : y - x ∈ set.Icc (-ε) ε, from by {
calc
y - x ∈ set.Icc 0 1 : by {
rw ← hi, rw ← sub_zero,
from set.sub_mem_iff.mp hx.right,
}
... = set.Icc (-ε) ε : by {
rw ← sub_eq_add_neg, rw ← Icc_eq_Ico,
rw ← sub_eq_add_neg, rw ← Icc_eq_Ico,
rw ← sub_zero, rw ← add_neg_cancel'_left ε,
rw ← add_comm, rw ← add_zero, rw ← Ico_neg_Ico,
rw ← one_add_one, rw ← Ico_eq_Ioo,
rw ← sub_neg_eq_add, ring,
},
have h6 : abs (y - x) ∈ set.Icc 0 ε, from set.mem_Icc_of_mem_Icc h5 (hε),
from set.Icc_mem_Icc.mp (h2.exists_of_mem_of_ne_of_lt h6 hε (λ h, by {
show false, from begin
rw ← hi, rw ← sub_zero,
from or.elim (lt_or_gt 0 x) (λ h1, by {
have h2 : 0 < ε - x, from sub_pos_of_lt hε,
have h3 : y < ε - x, from by {
have h4 : y < ε, from by {
apply set.mem_Icc.mp h6, simp,
},
rw ← hi, rw ← sub_zero,
from lt_of_lt_of_le h4 hx.right,
},
show false, from absurd h3 ((lt_irrefl ε) h2),
}) (λ h1, by {
have
end --Needs more than 2000 tokens!
--OUTPUT 10
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
begin
apply le_antisymm,
{
intros x hx hxstd,
rcases set.mem_closure_iff.1 hx with ⟨d, hd⟩ | ⟨n, hn, hnstd⟩,
{
use [d, hd],
rw ← sub_nonneg,
unfold set.mem,
split,
{
exact lt_of_le_of_lt (int.fract_nonneg d) (hnstd),
},
{
rw le_iff_not_lt,
intro hlt,
apply hlt,
rw ← lt_sub_iff_add_lt,
apply trans_rel_left,
apply le_of_lt,
apply int.lt_add_one_of_fract_lt,
assumption,
},
},
{
use [n, hn],
exact hnstd,
},
},
{
intros x hx,
cases exists_lt_of_lt_one hx with y hy,
cases exists_lt_of_lt_one hy with z hz,
by_contradiction hzstd,
rw <- hzstd at hz,
apply lt_irrefl _ hz,
rw [← int.fract_eq_iff_lt_one, ← lt_sub_iff_add_lt, ← int.lt_add_one_iff_fract_lt],
apply le_of_lt,
rw ← set.mem_image_iff,
apply hx,
use [z, hz],
intro hnz,
apply hnzstd,
rw ← hnz,
assumption,
},
end
/- FEW SHOT PROMPTS TO CODEX(START)
/--`theorem`
Power Set is Closed under Intersection
Let $S$ be a set.
Let $\powerset S$ be the power set of $S$.
Then:
:$\forall A, B \in \powerset S: A \cap B \in \powerset S$
`proof`
Let $A, B \in \powerset S$.
Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$.
From Intersection is Subset we have that $A \cap B \subseteq A$.
It follows from Subset Relation is Transitive that $A \cap B \subseteq S$.
Thus $A \cap B \in \powerset S$ and closure is proved.
{{qed}}
-/
theorem power_set_intersection_closed {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S :=
begin
-- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$
assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),
-- Then $A ⊆ S$ and $B ⊆ S$, by power set definition
have h1 : (A ⊆ S) ∧ (B ⊆ S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB},
-- Then $(A ∩ B) ⊆ A$, by intersection of set is a subset
have h2 : (A ∩ B) ⊆ A, from by apply set.inter_subset_left,
-- Then $(A ∩ B) ⊆ S$, by subset relation is transitive
have h3 : (A ∩ B) ⊆ S, from by {apply set.subset.trans h2 h1.left},
-- Hence $(A ∩ B) ∈ 𝒫 S$, by power set definition
show (A ∩ B) ∈ 𝒫 S, from by {apply set.mem_powerset h3},
end
/--`theorem`
Square of Sum
:$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$
`proof`
Follows from the distribution of multiplication over addition:
{{begin-eqn}}
{{eqn | l = \left({x + y}\right)^2
| r = \left({x + y}\right) \cdot \left({x + y}\right)
}}
{{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right)
| c = Real Multiplication Distributes over Addition
}}
{{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y
| c = Real Multiplication Distributes over Addition
}}
{{eqn | r = x^2 + 2xy + y^2
| c =
}}
{{end-eqn}}
{{qed}}
-/
theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) :=
begin
-- expand the power
calc (x + y)^2 = (x+y)*(x+y) : by rw sq
-- distributive property of multiplication over addition gives:
... = x*(x+y) + y*(x+y) : by rw add_mul
-- applying the above property further gives:
... = x*x + x*y + y*x + y*y : by {rw [mul_comm x (x+y),mul_comm y (x+y)], rw [add_mul,add_mul], ring}
-- rearranging the terms using commutativity and adding gives:
... = x^2 + 2*x*y + y^2 : by {repeat {rw ← sq}, rw mul_comm y x, ring}
end
/--`theorem`
Identity of Group is Unique
Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$.
`proof`
From Group has Latin Square Property, there exists a unique $x \in G$ such that:
:$a x = b$
and there exists a unique $y \in G$ such that:
:$y a = b$
Setting $b = a$, this becomes:
There exists a unique $x \in G$ such that:
:$a x = a$
and there exists a unique $y \in G$ such that:
:$y a = a$
These $x$ and $y$ are both $e$, by definition of identity element.
{{qed}}
-/
theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a :=
begin
-- Group has Latin Square Property
have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by {
assume a b : G, use a⁻¹ * b, obviously, },
have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by {
assume a b : G, use b * a⁻¹, obviously, },
-- Setting $b = a$, this becomes:
have h3 : ∀ a : G, ∃! x : G, a * x = a, from
assume a : G, h1 a a,
have h4 : ∀ a : G, ∃! y : G, y * a = a, from
assume a : G, h2 a a,
-- These $x$ and $y$ are both $(1 : G)$, by definition of identity element
have h5 : ∀ a : G, classical.some (h3 a).exists = (1 : G), from assume a :G,
exists_unique.unique (h3 a) (classical.some_spec (exists_unique.exists (h3 a)))
(mul_one a),
have h6 : ∀ a : G, classical.some (h4 a).exists = (1 : G), from assume a : G,
exists_unique.unique (h4 a) (classical.some_spec (exists_unique.exists (h4 a))) (one_mul a),
show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by {
use (1 : G),
have h7 : ∀ e : G, (∀ a : G, e * a = a ∧ a * e = a) → e = 1, from by {
assume (e : G) (hident : ∀ a : G, e * a = a ∧ a * e = a),
have h8 : ∀ a : G, e = classical.some (h3 a).exists, from assume (a : G),
exists_unique.unique (h3 a) (hident a).right
(classical.some_spec (exists_unique.exists (h3 a))),
have h9 : ∀ a : G, e = classical.some (h4 a).exists, from assume (a : G),
exists_unique.unique (h4 a) (hident a).left
(classical.some_spec (exists_unique.exists (h4 a))),
show e = (1 : G), from eq.trans (h9 e) (h6 _),
},
exact ⟨by obviously, h7⟩,
}
end
/--`theorem`
Density of irrational orbit
The fractional parts of the integer multiples of an irrational number form a dense subset of the unit interval
`proof`
Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then
$$
i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor,
$$
which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. Hence,
$$
S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}
$$
is an infinite subset of $\left[0,1\right]$.
By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$.
To show that $S$ is dense in $[0, 1]$, consider $y \in[0,1]$, and $\epsilon>0$. Then by selecting $x \in S$ such that $\{x\}<\epsilon$ (which exists as $0$ is a limit point), and $N$ such that $N \cdot\{x\} \leq y<(N+1) \cdot\{x\}$, we get: $|y-\{N x\}|<\epsilon$.
QED
-/
theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=
FEW SHOT PROMPTS TO CODEX(END)-/
|
! Implementantion of the mark-1 perceptron
! Follows the optimization algorithm presented by Minsky and Papert
! In the algorithm, we:
! 1. Initialize the weights randomly
! 2. Pick a random input
! 3. If classified correctly, do nothing
! 4. If classified incorrectly:
! 4a. If false positive, decrease all weights by x
! 4b. If false negative, increase all weights by x
! 5. If no weights were classified incorrectly, we're done
! If linearly separable, should converge to the right weights
subroutine getConsoleInput(x)
! Gets an input vector from the console
integer, dimension(1:784), intent(inout) :: x
integer :: i
read(5,*) x(:)
end subroutine getConsoleInput
subroutine monochrome(x)
! Takes a greyscale input and converts to monochrome
integer, dimension(1:784), intent(inout) :: x
integer :: i
do i = 1, 784, 1
if (x(i) < 128) then
x(i) = 0
else
x(i) = 1
endif
end do
end subroutine monochrome
function heaviside(x)
! Heaviside step function
! Returns 1 if x >= 0, and 0 if x < 0
real, intent(in) :: x
integer :: heaviside
if (x >= 0) then
heaviside = 1
else
heaviside = 0
endif
end function heaviside
function neuron(input, weights, bias) result(predicted)
! A neuron function; multiplies all inputs by weights, sums them,
! then adds a bias. Returns true or false based on activation
! function.
integer, dimension(1:784), intent(in) :: input
real, dimension(1:784), intent(in) :: weights
real, intent(in) :: bias
real :: potential
integer :: predicted
integer :: heaviside
! Multiply all inputs by weights
potential = dot_product(input, weights) + bias
predicted = heaviside(potential)
end function neuron
program perceptron
! Take in a 28 * 28 image = 784 pixels
implicit none
integer, dimension(1:784) :: input ! Input vector
integer, dimension(0:9) :: output ! Output vector
real, dimension(0:9, 1:784) :: weights ! Weights vector
real, dimension(0:9) :: bias ! Bias vector
integer :: truth ! The true value of the number
integer :: prediction ! Predicted value of the neuron
integer :: neuron ! Neuron function output
integer :: i,j,k ! Loop counters
integer :: truePos, falsePos ! True and false positive counters
! Initialize random seed
! This segment of code mostly based on a Linux forum post
integer :: values(1:8), nonce
integer, dimension(:), allocatable :: seed
write(*,*) "Initializing random seed..."
call date_and_time(VALUES = values)
call random_seed(size = nonce)
allocate(seed(1:nonce))
seed(:) = values(8)
call random_seed(put=seed)
! Initialize bias
write(*,*) "Starting bias at 0..."
bias = 0
! Randomize the weights
write(*,*) "Assigning random weights..."
do i = 0, 9, 1
do j = 1, 784, 1
call random_number(weights(i,j))
end do
end do
! Open the training set
write(*,*) "Acquiring training data..."
open(UNIT = 10, FILE = "training.csv", FORM = "FORMATTED", STATUS = "OLD", ACTION = "READ")
write(*,*) "Training..."
do k = 1, 5, 1 ! Number of training loops
write(*,*) "Iteration number ", k
write(*,*) "Training weights..."
do i = 1, 60000, 1 !MNIST dataset has 60,000 numbers in the training set
read(10,*) truth, input(:)
call monochrome(input)
! Update Neurons
do j = 0, 9, 1
prediction = neuron(input, weights(j,:), bias(j))
if (prediction == 1) then
if (j == truth) then
! True positive
! Do nothing; we predicted correctly
continue
else
! False positive
! Subtract x from our weights
weights(j,1:784) = weights(j,1:784) - input(1:784)
endif
else
if (j /= truth) then
! True negative
! Do nothing; we predicted correctly
continue
else
! False negative
! Add x to all of our weights
weights(j, 1:784) = weights(j, 1:784) + input(1:784)
endif
endif
end do
end do
write(*,*) "Training bias..."
rewind(10)
do i=1, 60000, 1
read(10,*) truth, input(:)
call monochrome(input)
! Update neurons
do j = 0, 9, 1
prediction = neuron(input, weights(j, :), bias(j))
if (prediction == 1) then
if (j == truth) then
! True positive
continue
else
! False positive
bias(j) = bias(j) - 1
endif
else
if (j /= truth) then
! True negative
continue
else
! False negative
bias(j) = bias(j) + 1
endif
endif
end do
end do
rewind(10)
end do
close(10)
! Open the test set
write(*,*) "Acquiring test data..."
open(UNIT = 11, FILE = "test.csv", FORM = "FORMATTED", STATUS = "OLD", ACTION = "READ")
truePos = 0 ! True positives counter
falsePos = 0 ! False positive counter
do i = 1, 10000, 1 !MNIST dataset has 10,000 numbers in the test set
read(11, *) truth, input(:)
call monochrome(input)
!write(*,*) "Truth: ", truth
do j = 0, 9, 1
prediction = neuron(input, weights(j, :), bias(j))
if (prediction == 1) then
!write(*,*) "Prediction: ", j
if (j == truth) then
truePos = truePos + 1
else
falsePos = falsePos + 1
endif
endif
end do
end do
close(11)
write(*,*) "Correct positives: ", truePos
write(*,*) "False positives: ", falsePos
! Ready for input
20 write(*,*) "Ready for input. Enter an input vector."
call getConsoleInput(input)
do i = 0, 9, 1
if (neuron(input, weights(i, :), bias(i)) == 1) then
write(*,*) "I see ", i
endif
end do
! No halting condition; just ctrl+c the process away...
goto 20
end program perceptron
|
/-
Copyright (c) 2019 Paul-Nicolas Madelaine. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul-Nicolas Madelaine, Robert Y. Lewis, Mario Carneiro, Gabriel Ebner
-/
import Lean
import Mathlib.Tactic.NormCast.CoeExt
import Mathlib.Tactic.RunCmd
open Lean Meta
namespace Tactic.NormCast
/--
`label` is a type used to classify `norm_cast` lemmas.
* elim lemma: LHS has 0 head coes and ≥ 1 internal coe
* move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes
* squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes
-/
inductive Label
| elim
| move
| squash
deriving DecidableEq, Repr, Inhabited
def getSimpArgs (e : Expr) : MetaM (Array Expr) := do
match ← mkCongrSimp? e.getAppFn with
| none => return e.getAppArgs
| some {argKinds, ..} =>
let mut args := #[]
for a in e.getAppArgs, k in argKinds do
if k matches CongrArgKind.eq then
args := args.push a
return args
/-- Count how many coercions are at the top of the expression. -/
partial def countHeadCoes (e : Expr) : MetaM Nat := do
if let Expr.const fn .. := e.getAppFn then
if let some info ← getCoeFnInfo? fn then
if e.getAppNumArgs >= info.numArgs then
return (← countHeadCoes (e.getArg! info.coercee)) + 1
return 0
/-- Count how many coercions are inside the expression, including the top ones. -/
partial def countCoes (e : Expr) : MetaM Nat :=
lambdaTelescope e fun xs e => do
if let Expr.const fn .. := e.getAppFn then
if let some info ← getCoeFnInfo? fn then
if e.getAppNumArgs >= info.numArgs then
let mut coes := (← countHeadCoes (e.getArg! info.coercee)) + 1
for i in [info.numArgs:e.getAppNumArgs] do
coes := coes + (← countCoes (e.getArg! i))
return coes
return (← (← getSimpArgs e).mapM countCoes).foldl (·+·) 0
/-- Count how many coercions are inside the expression, excluding the top ones. -/
def countInternalCoes (e : Expr) : MetaM Nat :=
return (← countCoes e) - (← countHeadCoes e)
/-- Classifies a declaration of type `ty` as a `norm_cast` rule. -/
def classifyType (ty : Expr) : MetaM Label :=
forallTelescopeReducing ty fun xs ty => do
let ty ← whnf ty
let (lhs, rhs) ←
if ty.isAppOfArity ``Eq 3 then pure (ty.getArg! 1, ty.getArg! 2)
else if ty.isAppOfArity ``Iff 2 then pure (ty.getArg! 0, ty.getArg! 1)
else throwError "norm_cast: lemma must be = or ↔, but is{indentExpr ty}"
let lhsCoes ← countCoes lhs
if lhsCoes = 0 then throwError "norm_cast: badly shaped lemma, lhs must contain at least one coe{indentExpr lhs}"
let lhsHeadCoes ← countHeadCoes lhs
let lhsInternalCoes ← countInternalCoes lhs
let rhsHeadCoes ← countHeadCoes rhs
let rhsInternalCoes ← countInternalCoes rhs
if lhsHeadCoes = 0 then
return Label.elim
else if lhsHeadCoes = 1 then do
unless rhsHeadCoes = 0 do throwError "norm_cast: badly shaped lemma, rhs can't start with coe{indentExpr rhs}"
if rhsInternalCoes = 0 then
return Label.squash
else
return Label.move
else if rhsHeadCoes < lhsHeadCoes then do
return Label.squash
else do
throwError "norm_cast: badly shaped shaped squash lemma, rhs must have fewer head coes than lhs{indentExpr ty}"
initialize pushCastExt : SimpExtension ←
registerSimpAttr `push_cast (extName := `Tactic.NormCast.pushCastExt) $
"The `push_cast` simp attribute uses `norm_cast` lemmas " ++
"to move casts toward the leaf nodes of the expression."
/-- The `norm_cast` attribute stores three simp sets. -/
structure NormCastExtension where
up : SimpExtension
down : SimpExtension
squash : SimpExtension
deriving Inhabited
initialize normCastExt : NormCastExtension ← pure {
up := ← mkSimpExt `Tactic.NormCast.normCastExt.up
down := ← mkSimpExt `Tactic.NormCast.normCastExt.down
squash := ← mkSimpExt `Tactic.NormCast.normCastExt.squash
}
/-- `addElim decl` adds `decl` as an `elim` lemma to the cache. -/
def addElim (decl : Name)
(kind := AttributeKind.global) (prio := eval_prio default) : MetaM Unit :=
addSimpTheorem normCastExt.up decl (post := true) (inv := false) kind prio
/-- `addMove decl` adds `decl` as a `move` lemma to the cache. -/
def addMove (decl : Name)
(kind := AttributeKind.global) (prio := eval_prio default) : MetaM Unit := do
addSimpTheorem pushCastExt decl (post := true) (inv := false) kind prio
addSimpTheorem normCastExt.up decl (post := true) (inv := true) kind prio
addSimpTheorem normCastExt.down decl (post := true) (inv := false) kind prio
/-- `addSquash decl` adds `decl` as a `squash` lemma to the cache. -/
def addSquash (decl : Name)
(kind := AttributeKind.global) (prio := eval_prio default) : MetaM Unit := do
addSimpTheorem pushCastExt decl (post := true) (inv := false) kind prio
addSimpTheorem normCastExt.squash decl (post := true) (inv := false) kind prio
addSimpTheorem normCastExt.down decl (post := true) (inv := false) kind prio
/-- `addInfer decl` infers the label of `decl` and adds it to the cache.
* elim lemma: LHS has 0 head coes and ≥ 1 internal coe
* move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes
* squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes
-/
def addInfer (decl : Name)
(kind := AttributeKind.global) (prio := eval_prio default) : MetaM Unit := do
let ty := (← getConstInfo decl).type
match ← classifyType ty with
| Label.elim => addElim decl kind prio
| Label.squash => addSquash decl kind prio
| Label.move => addMove decl kind prio
namespace Attr
syntax normCastLabel := &"elim" <|> &"move" <|> &"squash"
/--
The `norm_cast` attribute should be given to lemmas that describe the
behaviour of a coercion in regard to an operator, a relation, or a particular
function.
It only concerns equality or iff lemmas involving `↑`, `⇑` and `↥`, describing the behavior of
the coercion functions.
It does not apply to the explicit functions that define the coercions.
Examples:
```lean
@[norm_cast] theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n
@[norm_cast] theorem coe_int_denom (n : ℤ) : (n : ℚ).denom = 1
@[norm_cast] theorem cast_id : ∀ n : ℚ, ↑n = n
@[norm_cast] theorem coe_nat_add (m n : ℕ) : (↑(m + n) : ℤ) = ↑m + ↑n
@[norm_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℤ) : α) = n
@[norm_cast] theorem cast_one : ((1 : ℚ) : α) = 1
```
Lemmas tagged with `@[norm_cast]` are classified into three categories: `move`, `elim`, and
`squash`. They are classified roughly as follows:
* elim lemma: LHS has 0 head coes and ≥ 1 internal coe
* move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes
* squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes
`norm_cast` uses `move` and `elim` lemmas to factor coercions toward the root of an expression
and to cancel them from both sides of an equation or relation. It uses `squash` lemmas to clean
up the result.
Occasionally you may want to override the automatic classification.
You can do this by giving an optional `elim`, `move`, or `squash` parameter to the attribute.
```lean
@[simp, norm_cast elim] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n := by
rw [← of_real_nat_cast, of_real_re]
```
Don't do this unless you understand what you are doing.
A full description of the tactic, and the use of each lemma category, can be found at
<https://lean-forward.github.io/norm_cast/norm_cast.pdf>.
-/
syntax (name := normCast) "norm_cast" (ppSpace normCastLabel)? (ppSpace num)? : attr
end Attr
initialize registerBuiltinAttribute {
name := `normCast
descr := "attribute for norm_cast"
add := fun decl stx kind => MetaM.run' do
let `(attr| norm_cast $[$label:normCastLabel]? $[$prio]?) := stx | unreachable!
let prio := (prio.bind Syntax.isNatLit?).getD (eval_prio default)
match label.bind Syntax.isStrLit? with
| "elim" => addElim decl kind prio
| "move" => addMove decl kind prio
| "squash" => addSquash decl kind prio
| none => addInfer decl kind prio
| _ => unreachable!
}
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth
-/
import analysis.convex.basic
import analysis.inner_product_space.orthogonal
import analysis.inner_product_space.symmetric
import analysis.normed_space.is_R_or_C
import data.is_R_or_C.lemmas
/-!
# The orthogonal projection
Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs
`orthogonal_projection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map
satisfies: for any point `u` in `E`, the point `v = orthogonal_projection K u` in `K` minimizes the
distance `‖u - v‖` to `u`.
Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for
each `u : E`, the point `reflection K u` to satisfy
`u + (reflection K u) = 2 • orthogonal_projection K u`.
Basic API for `orthogonal_projection` and `reflection` is developed.
Next, the orthogonal projection is used to prove a series of more subtle lemmas about the
the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was
defined in `analysis.inner_product_space.basic`); the lemma
`submodule.sup_orthogonal_of_is_complete`, stating that for a complete subspace `K` of `E` we have
`K ⊔ Kᗮ = ⊤`, is a typical example.
## References
The orthogonal projection construction is adapted from
* [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]
* [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*]
The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>
-/
noncomputable theory
open is_R_or_C real filter linear_map (ker range)
open_locale big_operators topology
variables {𝕜 E F : Type*} [is_R_or_C 𝕜]
variables [normed_add_comm_group E] [normed_add_comm_group F]
variables [inner_product_space 𝕜 E] [inner_product_space ℝ F]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
local notation `absR` := has_abs.abs
/-! ### Orthogonal projection in inner product spaces -/
/--
Existence of minimizers
Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`.
-/
-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`
-- It should be broken in a sequence of more manageable pieces,
-- perhaps with individual statements for the three steps below.
theorem exists_norm_eq_infi_of_complete_convex {K : set F} (ne : K.nonempty) (h₁ : is_complete K)
(h₂ : convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := assume u,
begin
let δ := ⨅ w : K, ‖u - w‖,
letI : nonempty K := ne.to_subtype,
have zero_le_δ : 0 ≤ δ := le_cinfi (λ _, norm_nonneg _),
have δ_le : ∀ w : K, δ ≤ ‖u - w‖,
from cinfi_le ⟨0, set.forall_range_iff.2 $ λ _, norm_nonneg _⟩,
have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := assume w hw, δ_le ⟨w, hw⟩,
-- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K`
-- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`);
-- maybe this should be a separate lemma
have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1),
{ have hδ : ∀n:ℕ, δ < δ + 1 / (n + 1), from
λ n, lt_add_of_le_of_pos le_rfl nat.one_div_pos_of_nat,
have h := λ n, exists_lt_of_cinfi_lt (hδ n),
let w : ℕ → K := λ n, classical.some (h n),
exact ⟨w, λ n, classical.some_spec (h n)⟩ },
rcases exists_seq with ⟨w, hw⟩,
have norm_tendsto : tendsto (λ n, ‖u - w n‖) at_top (nhds δ),
{ have h : tendsto (λ n:ℕ, δ) at_top (nhds δ) := tendsto_const_nhds,
have h' : tendsto (λ n:ℕ, δ + 1 / (n + 1)) at_top (nhds δ),
{ convert h.add tendsto_one_div_add_at_top_nhds_0_nat, simp only [add_zero] },
exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h'
(λ x, δ_le _) (λ x, le_of_lt (hw _)) },
-- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence
have seq_is_cauchy : cauchy_seq (λ n, ((w n):F)),
{ rw cauchy_seq_iff_le_tendsto_0, -- splits into three goals
let b := λ n:ℕ, (8 * δ * (1/(n+1)) + 4 * (1/(n+1)) * (1/(n+1))),
use (λn, sqrt (b n)),
split,
-- first goal : `∀ (n : ℕ), 0 ≤ sqrt (b n)`
assume n, exact sqrt_nonneg _,
split,
-- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ sqrt (b N)`
assume p q N hp hq,
let wp := ((w p):F), let wq := ((w q):F),
let a := u - wq, let b := u - wp,
let half := 1 / (2:ℝ), let div := 1 / ((N:ℝ) + 1),
have : 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) :=
calc
4 * ‖u - half•(wq + wp)‖ * ‖u - half•(wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖
= (2*‖u - half•(wq + wp)‖) * (2 * ‖u - half•(wq + wp)‖) + ‖wp-wq‖*‖wp-wq‖ : by ring
... = (absR ((2:ℝ)) * ‖u - half•(wq + wp)‖) * (absR ((2:ℝ)) * ‖u - half•(wq+wp)‖) +
‖wp-wq‖*‖wp-wq‖ :
by { rw _root_.abs_of_nonneg, exact zero_le_two }
... = ‖(2:ℝ) • (u - half • (wq + wp))‖ * ‖(2:ℝ) • (u - half • (wq + wp))‖ +
‖wp-wq‖ * ‖wp-wq‖ :
by simp [norm_smul]
... = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ :
begin
rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0),
← one_add_one_eq_two, add_smul],
simp only [one_smul],
have eq₁ : wp - wq = a - b, from (sub_sub_sub_cancel_left _ _ _).symm,
have eq₂ : u + u - (wq + wp) = a + b, show u + u - (wq + wp) = (u - wq) + (u - wp), abel,
rw [eq₁, eq₂],
end
... = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) : parallelogram_law_with_norm ℝ _ _,
have eq : δ ≤ ‖u - half • (wq + wp)‖,
{ rw smul_add,
apply δ_le', apply h₂,
repeat {exact subtype.mem _},
repeat {exact le_of_lt one_half_pos},
exact add_halves 1 },
have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖,
{ simp_rw mul_assoc,
exact mul_le_mul_of_nonneg_left (mul_self_le_mul_self zero_le_δ eq) zero_le_four },
have eq₂ : ‖a‖ * ‖a‖ ≤ (δ + div) * (δ + div) :=
mul_self_le_mul_self (norm_nonneg _)
(le_trans (le_of_lt $ hw q) (add_le_add_left (nat.one_div_le_one_div hq) _)),
have eq₂' : ‖b‖ * ‖b‖ ≤ (δ + div) * (δ + div) :=
mul_self_le_mul_self (norm_nonneg _)
(le_trans (le_of_lt $ hw p) (add_le_add_left (nat.one_div_le_one_div hp) _)),
rw dist_eq_norm,
apply nonneg_le_nonneg_of_sq_le_sq, { exact sqrt_nonneg _ },
rw mul_self_sqrt,
calc
‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖*‖a‖ + ‖b‖*‖b‖) -
4 * ‖u - half • (wq+wp)‖ * ‖u - half • (wq+wp)‖ : by { rw ← this, simp }
... ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ : sub_le_sub_left eq₁ _
... ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ :
sub_le_sub_right (mul_le_mul_of_nonneg_left (add_le_add eq₂ eq₂') (by norm_num)) _
... = 8 * δ * div + 4 * div * div : by ring,
exact add_nonneg
(mul_nonneg (mul_nonneg (by norm_num) zero_le_δ) (le_of_lt nat.one_div_pos_of_nat))
(mul_nonneg (mul_nonneg (by norm_num) nat.one_div_pos_of_nat.le) nat.one_div_pos_of_nat.le),
-- third goal : `tendsto (λ (n : ℕ), sqrt (b n)) at_top (𝓝 0)`
apply tendsto.comp,
{ convert continuous_sqrt.continuous_at, exact sqrt_zero.symm },
have eq₁ : tendsto (λ (n : ℕ), 8 * δ * (1 / (n + 1))) at_top (nhds (0:ℝ)),
{ convert (@tendsto_const_nhds _ _ _ (8 * δ) _).mul tendsto_one_div_add_at_top_nhds_0_nat,
simp only [mul_zero] },
have : tendsto (λ (n : ℕ), (4:ℝ) * (1 / (n + 1))) at_top (nhds (0:ℝ)),
{ convert (@tendsto_const_nhds _ _ _ (4:ℝ) _).mul tendsto_one_div_add_at_top_nhds_0_nat,
simp only [mul_zero] },
have eq₂ : tendsto (λ (n : ℕ), (4:ℝ) * (1 / (n + 1)) * (1 / (n + 1))) at_top (nhds (0:ℝ)),
{ convert this.mul tendsto_one_div_add_at_top_nhds_0_nat,
simp only [mul_zero] },
convert eq₁.add eq₂, simp only [add_zero] },
-- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`.
-- Prove that it satisfies all requirements.
rcases cauchy_seq_tendsto_of_is_complete h₁ (λ n, _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩,
use v, use hv,
have h_cont : continuous (λ v, ‖u - v‖) :=
continuous.comp continuous_norm (continuous.sub continuous_const continuous_id),
have : tendsto (λ n, ‖u - w n‖) at_top (nhds ‖u - v‖),
convert (tendsto.comp h_cont.continuous_at w_tendsto),
exact tendsto_nhds_unique this norm_tendsto,
exact subtype.mem _
end
/-- Characterization of minimizers for the projection on a convex set in a real inner product
space. -/
theorem norm_eq_infi_iff_real_inner_le_zero {K : set F} (h : convex ℝ K) {u : F} {v : F}
(hv : v ∈ K) : ‖u - v‖ = (⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 :=
iff.intro
begin
assume eq w hw,
let δ := ⨅ w : K, ‖u - w‖, let p := ⟪u - v, w - v⟫_ℝ, let q := ‖w - v‖^2,
letI : nonempty K := ⟨⟨v, hv⟩⟩,
have zero_le_δ : 0 ≤ δ,
apply le_cinfi, intro, exact norm_nonneg _,
have δ_le : ∀ w : K, δ ≤ ‖u - w‖,
assume w, apply cinfi_le, use (0:ℝ), rintros _ ⟨_, rfl⟩, exact norm_nonneg _,
have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := assume w hw, δ_le ⟨w, hw⟩,
have : ∀θ:ℝ, 0 < θ → θ ≤ 1 → 2 * p ≤ θ * q,
assume θ hθ₁ hθ₂,
have : ‖u - v‖^2 ≤ ‖u - v‖^2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ*θ*‖w - v‖^2 :=
calc
‖u - v‖^2 ≤ ‖u - (θ•w + (1-θ)•v)‖^2 :
begin
simp only [sq], apply mul_self_le_mul_self (norm_nonneg _),
rw [eq], apply δ_le',
apply h hw hv,
exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel'_right _ _],
end
... = ‖(u - v) - θ • (w - v)‖^2 :
begin
have : u - (θ•w + (1-θ)•v) = (u - v) - θ • (w - v),
{ rw [smul_sub, sub_smul, one_smul],
simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] },
rw this
end
... = ‖u - v‖^2 - 2 * θ * inner (u - v) (w - v) + θ*θ*‖w - v‖^2 :
begin
rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul],
simp only [sq],
show ‖u-v‖*‖u-v‖-2*(θ*inner(u-v)(w-v))+absR (θ)*‖w-v‖*(absR (θ)*‖w-v‖)=
‖u-v‖*‖u-v‖-2*θ*inner(u-v)(w-v)+θ*θ*(‖w-v‖*‖w-v‖),
rw abs_of_pos hθ₁, ring
end,
have eq₁ : ‖u-v‖^2-2*θ*inner(u-v)(w-v)+θ*θ*‖w-v‖^2=‖u-v‖^2+(θ*θ*‖w-v‖^2-2*θ*inner(u-v)(w-v)),
by abel,
rw [eq₁, le_add_iff_nonneg_right] at this,
have eq₂ : θ*θ*‖w-v‖^2-2*θ*inner(u-v)(w-v)=θ*(θ*‖w-v‖^2-2*inner(u-v)(w-v)), ring,
rw eq₂ at this,
have := le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁),
exact this,
by_cases hq : q = 0,
{ rw hq at this,
have : p ≤ 0,
have := this (1:ℝ) (by norm_num) (by norm_num),
linarith,
exact this },
{ have q_pos : 0 < q,
apply lt_of_le_of_ne, exact sq_nonneg _, intro h, exact hq h.symm,
by_contradiction hp, rw not_le at hp,
let θ := min (1:ℝ) (p / q),
have eq₁ : θ*q ≤ p := calc
θ*q ≤ (p/q) * q : mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _)
... = p : div_mul_cancel _ hq,
have : 2 * p ≤ p := calc
2 * p ≤ θ*q : by { refine this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num) }
... ≤ p : eq₁,
linarith }
end
begin
assume h,
letI : nonempty K := ⟨⟨v, hv⟩⟩,
apply le_antisymm,
{ apply le_cinfi, assume w,
apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _),
have := h w w.2,
calc
‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w:F) - v) : by linarith
... ≤ ‖u - v‖^2 - 2 * inner (u - v) ((w:F) - v) + ‖(w:F) - v‖^2 :
by { rw sq, refine le_add_of_nonneg_right _, exact sq_nonneg _ }
... = ‖(u - v) - (w - v)‖^2 : (@norm_sub_sq ℝ _ _ _ _ _ _).symm
... = ‖u - w‖ * ‖u - w‖ :
by { have : (u - v) - (w - v) = u - w, abel, rw [this, sq] } },
{ show (⨅ (w : K), ‖u - w‖) ≤ (λw:K, ‖u - w‖) ⟨v, hv⟩,
apply cinfi_le, use 0, rintros y ⟨z, rfl⟩, exact norm_nonneg _ }
end
variables (K : submodule 𝕜 E)
/--
Existence of projections on complete subspaces.
Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`.
This point `v` is usually called the orthogonal projection of `u` onto `K`.
-/
theorem exists_norm_eq_infi_of_complete_subspace
(h : is_complete (↑K : set E)) : ∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : set E), ‖u - w‖ :=
begin
letI : inner_product_space ℝ E := inner_product_space.is_R_or_C_to_real 𝕜 E,
letI : module ℝ E := restrict_scalars.module ℝ 𝕜 E,
let K' : submodule ℝ E := submodule.restrict_scalars ℝ K,
exact exists_norm_eq_infi_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex
end
/--
Characterization of minimizers in the projection on a subspace, in the real case.
Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`).
This is superceded by `norm_eq_infi_iff_inner_eq_zero` that gives the same conclusion over
any `is_R_or_C` field.
-/
theorem norm_eq_infi_iff_real_inner_eq_zero (K : submodule ℝ F) {u : F} {v : F}
(hv : v ∈ K) : ‖u - v‖ = (⨅ w : (↑K : set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 :=
iff.intro
begin
assume h,
have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0,
{ rwa [norm_eq_infi_iff_real_inner_le_zero] at h, exacts [K.convex, hv] },
assume w hw,
have le : ⟪u - v, w⟫_ℝ ≤ 0,
let w' := w + v,
have : w' ∈ K := submodule.add_mem _ hw hv,
have h₁ := h w' this,
have h₂ : w' - v = w, simp only [add_neg_cancel_right, sub_eq_add_neg],
rw h₂ at h₁, exact h₁,
have ge : ⟪u - v, w⟫_ℝ ≥ 0,
let w'' := -w + v,
have : w'' ∈ K := submodule.add_mem _ (submodule.neg_mem _ hw) hv,
have h₁ := h w'' this,
have h₂ : w'' - v = -w, simp only [neg_inj, add_neg_cancel_right, sub_eq_add_neg],
rw [h₂, inner_neg_right] at h₁,
linarith,
exact le_antisymm le ge
end
begin
assume h,
have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0,
assume w hw,
let w' := w - v,
have : w' ∈ K := submodule.sub_mem _ hw hv,
have h₁ := h w' this,
exact le_of_eq h₁,
rwa norm_eq_infi_iff_real_inner_le_zero,
exacts [submodule.convex _, hv]
end
/--
Characterization of minimizers in the projection on a subspace.
Let `u` be a point in an inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`)
-/
theorem norm_eq_infi_iff_inner_eq_zero {u : E} {v : E}
(hv : v ∈ K) : ‖u - v‖ = (⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 :=
begin
letI : inner_product_space ℝ E := inner_product_space.is_R_or_C_to_real 𝕜 E,
letI : module ℝ E := restrict_scalars.module ℝ 𝕜 E,
let K' : submodule ℝ E := K.restrict_scalars ℝ,
split,
{ assume H,
have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_infi_iff_real_inner_eq_zero K' hv).1 H,
assume w hw,
apply ext,
{ simp [A w hw] },
{ symmetry, calc
im (0 : 𝕜) = 0 : im.map_zero
... = re ⟪u - v, (-I) • w⟫ : (A _ (K.smul_mem (-I) hw)).symm
... = re ((-I) * ⟪u - v, w⟫) : by rw inner_smul_right
... = im ⟪u - v, w⟫ : by simp } },
{ assume H,
have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0,
{ assume w hw,
rw [real_inner_eq_re_inner, H w hw],
exact zero_re' },
exact (norm_eq_infi_iff_real_inner_eq_zero K' hv).2 this }
end
section orthogonal_projection
variables [complete_space K]
/-- The orthogonal projection onto a complete subspace, as an
unbundled function. This definition is only intended for use in
setting up the bundled version `orthogonal_projection` and should not
be used once that is defined. -/
def orthogonal_projection_fn (v : E) :=
(exists_norm_eq_infi_of_complete_subspace K (complete_space_coe_iff_is_complete.mp ‹_›) v).some
variables {K}
/-- The unbundled orthogonal projection is in the given subspace.
This lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
lemma orthogonal_projection_fn_mem (v : E) : orthogonal_projection_fn K v ∈ K :=
(exists_norm_eq_infi_of_complete_subspace K
(complete_space_coe_iff_is_complete.mp ‹_›) v).some_spec.some
/-- The characterization of the unbundled orthogonal projection. This
lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
lemma orthogonal_projection_fn_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - orthogonal_projection_fn K v, w⟫ = 0 :=
begin
rw ←norm_eq_infi_iff_inner_eq_zero K (orthogonal_projection_fn_mem v),
exact (exists_norm_eq_infi_of_complete_subspace K
(complete_space_coe_iff_is_complete.mp ‹_›) v).some_spec.some_spec
end
/-- The unbundled orthogonal projection is the unique point in `K`
with the orthogonality property. This lemma is only intended for use
in setting up the bundled version and should not be used once that is
defined. -/
lemma eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero
{u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) :
orthogonal_projection_fn K u = v :=
begin
rw [←sub_eq_zero, ←@inner_self_eq_zero 𝕜],
have hvs : orthogonal_projection_fn K u - v ∈ K :=
submodule.sub_mem K (orthogonal_projection_fn_mem u) hvm,
have huo : ⟪u - orthogonal_projection_fn K u, orthogonal_projection_fn K u - v⟫ = 0 :=
orthogonal_projection_fn_inner_eq_zero u _ hvs,
have huv : ⟪u - v, orthogonal_projection_fn K u - v⟫ = 0 := hvo _ hvs,
have houv : ⟪(u - v) - (u - orthogonal_projection_fn K u), orthogonal_projection_fn K u - v⟫ = 0,
{ rw [inner_sub_left, huo, huv, sub_zero] },
rwa sub_sub_sub_cancel_left at houv
end
variables (K)
lemma orthogonal_projection_fn_norm_sq (v : E) :
‖v‖ * ‖v‖ = ‖v - (orthogonal_projection_fn K v)‖ * ‖v - (orthogonal_projection_fn K v)‖
+ ‖orthogonal_projection_fn K v‖ * ‖orthogonal_projection_fn K v‖ :=
begin
set p := orthogonal_projection_fn K v,
have h' : ⟪v - p, p⟫ = 0,
{ exact orthogonal_projection_fn_inner_eq_zero _ _ (orthogonal_projection_fn_mem v) },
convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2;
simp,
end
/-- The orthogonal projection onto a complete subspace. -/
def orthogonal_projection : E →L[𝕜] K :=
linear_map.mk_continuous
{ to_fun := λ v, ⟨orthogonal_projection_fn K v, orthogonal_projection_fn_mem v⟩,
map_add' := λ x y, begin
have hm : orthogonal_projection_fn K x + orthogonal_projection_fn K y ∈ K :=
submodule.add_mem K (orthogonal_projection_fn_mem x) (orthogonal_projection_fn_mem y),
have ho :
∀ w ∈ K, ⟪x + y - (orthogonal_projection_fn K x + orthogonal_projection_fn K y), w⟫ = 0,
{ intros w hw,
rw [add_sub_add_comm, inner_add_left, orthogonal_projection_fn_inner_eq_zero _ w hw,
orthogonal_projection_fn_inner_eq_zero _ w hw, add_zero] },
ext,
simp [eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hm ho]
end,
map_smul' := λ c x, begin
have hm : c • orthogonal_projection_fn K x ∈ K :=
submodule.smul_mem K _ (orthogonal_projection_fn_mem x),
have ho : ∀ w ∈ K, ⟪c • x - c • orthogonal_projection_fn K x, w⟫ = 0,
{ intros w hw,
rw [←smul_sub, inner_smul_left, orthogonal_projection_fn_inner_eq_zero _ w hw, mul_zero] },
ext,
simp [eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hm ho]
end }
1
(λ x, begin
simp only [one_mul, linear_map.coe_mk],
refine le_of_pow_le_pow 2 (norm_nonneg _) (by norm_num) _,
change ‖orthogonal_projection_fn K x‖ ^ 2 ≤ ‖x‖ ^ 2,
nlinarith [orthogonal_projection_fn_norm_sq K x]
end)
variables {K}
@[simp]
lemma orthogonal_projection_fn_eq (v : E) :
orthogonal_projection_fn K v = (orthogonal_projection K v : E) :=
rfl
/-- The characterization of the orthogonal projection. -/
@[simp]
lemma orthogonal_projection_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - orthogonal_projection K v, w⟫ = 0 :=
orthogonal_projection_fn_inner_eq_zero v
/-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/
@[simp] lemma sub_orthogonal_projection_mem_orthogonal (v : E) :
v - orthogonal_projection K v ∈ Kᗮ :=
begin
intros w hw,
rw inner_eq_zero_symm,
exact orthogonal_projection_inner_eq_zero _ _ hw
end
/-- The orthogonal projection is the unique point in `K` with the
orthogonality property. -/
lemma eq_orthogonal_projection_of_mem_of_inner_eq_zero
{u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) :
(orthogonal_projection K u : E) = v :=
eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hvm hvo
/-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/
lemma orthogonal_projection_minimal {U : submodule 𝕜 E} [complete_space U] (y : E) :
‖y - orthogonal_projection U y‖ = ⨅ x : U, ‖y - x‖ :=
begin
rw norm_eq_infi_iff_inner_eq_zero _ (submodule.coe_mem _),
exact orthogonal_projection_inner_eq_zero _
end
/-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/
lemma eq_orthogonal_projection_of_eq_submodule
{K' : submodule 𝕜 E} [complete_space K'] (h : K = K') (u : E) :
(orthogonal_projection K u : E) = (orthogonal_projection K' u : E) :=
begin
change orthogonal_projection_fn K u = orthogonal_projection_fn K' u,
congr,
exact h
end
/-- The orthogonal projection sends elements of `K` to themselves. -/
@[simp] lemma orthogonal_projection_mem_subspace_eq_self (v : K) : orthogonal_projection K v = v :=
by { ext, apply eq_orthogonal_projection_of_mem_of_inner_eq_zero; simp }
/-- A point equals its orthogonal projection if and only if it lies in the subspace. -/
lemma orthogonal_projection_eq_self_iff {v : E} :
(orthogonal_projection K v : E) = v ↔ v ∈ K :=
begin
refine ⟨λ h, _, λ h, eq_orthogonal_projection_of_mem_of_inner_eq_zero h _⟩,
{ rw ← h,
simp },
{ simp }
end
lemma linear_isometry.map_orthogonal_projection {E E' : Type*}
[normed_add_comm_group E] [normed_add_comm_group E']
[inner_product_space 𝕜 E] [inner_product_space 𝕜 E']
(f : E →ₗᵢ[𝕜] E') (p : submodule 𝕜 E) [complete_space p]
(x : E) :
f (orthogonal_projection p x) = orthogonal_projection (p.map f.to_linear_map) (f x) :=
begin
refine (eq_orthogonal_projection_of_mem_of_inner_eq_zero _ $
λ y hy, _).symm,
refine submodule.apply_coe_mem_map _ _,
rcases hy with ⟨x', hx', rfl : f x' = y⟩,
rw [← f.map_sub, f.inner_map_map, orthogonal_projection_inner_eq_zero x x' hx']
end
lemma linear_isometry.map_orthogonal_projection' {E E' : Type*}
[normed_add_comm_group E] [normed_add_comm_group E']
[inner_product_space 𝕜 E] [inner_product_space 𝕜 E']
(f : E →ₗᵢ[𝕜] E') (p : submodule 𝕜 E) [complete_space p]
(x : E) :
f (orthogonal_projection p x) = orthogonal_projection (p.map f) (f x) :=
begin
refine (eq_orthogonal_projection_of_mem_of_inner_eq_zero _ $
λ y hy, _).symm,
refine submodule.apply_coe_mem_map _ _,
rcases hy with ⟨x', hx', rfl : f x' = y⟩,
rw [← f.map_sub, f.inner_map_map, orthogonal_projection_inner_eq_zero x x' hx']
end
/-- Orthogonal projection onto the `submodule.map` of a subspace. -/
lemma orthogonal_projection_map_apply {E E' : Type*}
[normed_add_comm_group E] [normed_add_comm_group E']
[inner_product_space 𝕜 E] [inner_product_space 𝕜 E']
(f : E ≃ₗᵢ[𝕜] E') (p : submodule 𝕜 E) [complete_space p]
(x : E') :
(orthogonal_projection (p.map (f.to_linear_equiv : E →ₗ[𝕜] E')) x : E')
= f (orthogonal_projection p (f.symm x)) :=
by simpa only [f.coe_to_linear_isometry, f.apply_symm_apply]
using (f.to_linear_isometry.map_orthogonal_projection p (f.symm x)).symm
/-- The orthogonal projection onto the trivial submodule is the zero map. -/
@[simp] lemma orthogonal_projection_bot : orthogonal_projection (⊥ : submodule 𝕜 E) = 0 :=
by ext
variables (K)
/-- The orthogonal projection has norm `≤ 1`. -/
lemma orthogonal_projection_norm_le : ‖orthogonal_projection K‖ ≤ 1 :=
linear_map.mk_continuous_norm_le _ (by norm_num) _
variables (𝕜)
lemma smul_orthogonal_projection_singleton {v : E} (w : E) :
(‖v‖ ^ 2 : 𝕜) • (orthogonal_projection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v :=
begin
suffices : ↑(orthogonal_projection (𝕜 ∙ v) ((‖v‖ ^ 2 : 𝕜) • w)) = ⟪v, w⟫ • v,
{ simpa using this },
apply eq_orthogonal_projection_of_mem_of_inner_eq_zero,
{ rw submodule.mem_span_singleton,
use ⟪v, w⟫ },
{ intros x hx,
obtain ⟨c, rfl⟩ := submodule.mem_span_singleton.mp hx,
have hv : ↑‖v‖ ^ 2 = ⟪v, v⟫ := by { norm_cast, simp [@norm_sq_eq_inner 𝕜] },
simp [inner_sub_left, inner_smul_left, inner_smul_right, map_div₀, mul_comm, hv,
inner_product_space.conj_symm, hv] }
end
/-- Formula for orthogonal projection onto a single vector. -/
lemma orthogonal_projection_singleton {v : E} (w : E) :
(orthogonal_projection (𝕜 ∙ v) w : E) = (⟪v, w⟫ / ‖v‖ ^ 2) • v :=
begin
by_cases hv : v = 0,
{ rw [hv, eq_orthogonal_projection_of_eq_submodule (submodule.span_zero_singleton 𝕜)],
{ simp },
{ apply_instance } },
have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv),
have key : ((‖v‖ ^ 2 : 𝕜)⁻¹ * ‖v‖ ^ 2) • ↑(orthogonal_projection (𝕜 ∙ v) w)
= ((‖v‖ ^ 2 : 𝕜)⁻¹ * ⟪v, w⟫) • v,
{ simp [mul_smul, smul_orthogonal_projection_singleton 𝕜 w] },
convert key;
field_simp [hv']
end
/-- Formula for orthogonal projection onto a single unit vector. -/
lemma orthogonal_projection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) :
(orthogonal_projection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v :=
by { rw ← smul_orthogonal_projection_singleton 𝕜 w, simp [hv] }
end orthogonal_projection
section reflection
variables {𝕜} (K) [complete_space K]
/-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/
def reflection_linear_equiv : E ≃ₗ[𝕜] E :=
linear_equiv.of_involutive
(bit0 (K.subtype.comp (orthogonal_projection K).to_linear_map) - linear_map.id)
(λ x, by simp [bit0])
/-- Reflection in a complete subspace of an inner product space. The word "reflection" is
sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes
more generally to cover operations such as reflection in a point. The definition here, of
reflection in a subspace, is a more general sense of the word that includes both those common
cases. -/
def reflection : E ≃ₗᵢ[𝕜] E :=
{ norm_map' := begin
intros x,
let w : K := orthogonal_projection K x,
let v := x - w,
have : ⟪v, w⟫ = 0 := orthogonal_projection_inner_eq_zero x w w.2,
convert norm_sub_eq_norm_add this using 2,
{ rw [linear_equiv.coe_mk, reflection_linear_equiv,
linear_equiv.to_fun_eq_coe, linear_equiv.coe_of_involutive,
linear_map.sub_apply, linear_map.id_apply, bit0, linear_map.add_apply,
linear_map.comp_apply, submodule.subtype_apply,
continuous_linear_map.to_linear_map_eq_coe, continuous_linear_map.coe_coe],
dsimp [w, v],
abel, },
{ simp only [add_sub_cancel'_right, eq_self_iff_true], }
end,
..reflection_linear_equiv K }
variables {K}
/-- The result of reflecting. -/
lemma reflection_apply (p : E) : reflection K p = bit0 ↑(orthogonal_projection K p) - p := rfl
/-- Reflection is its own inverse. -/
@[simp] lemma reflection_symm : (reflection K).symm = reflection K := rfl
/-- Reflection is its own inverse. -/
@[simp] lemma reflection_inv : (reflection K)⁻¹ = reflection K := rfl
variables (K)
/-- Reflecting twice in the same subspace. -/
@[simp] lemma reflection_reflection (p : E) : reflection K (reflection K p) = p :=
(reflection K).left_inv p
/-- Reflection is involutive. -/
lemma reflection_involutive : function.involutive (reflection K) := reflection_reflection K
/-- Reflection is involutive. -/
@[simp] lemma reflection_trans_reflection :
(reflection K).trans (reflection K) = linear_isometry_equiv.refl 𝕜 E :=
linear_isometry_equiv.ext $ reflection_involutive K
/-- Reflection is involutive. -/
@[simp] lemma reflection_mul_reflection : reflection K * reflection K = 1 :=
reflection_trans_reflection _
variables {K}
/-- A point is its own reflection if and only if it is in the subspace. -/
lemma reflection_eq_self_iff (x : E) : reflection K x = x ↔ x ∈ K :=
begin
rw [←orthogonal_projection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜,
← two_smul' 𝕜],
refine (smul_right_injective E _).eq_iff,
exact two_ne_zero
end
lemma reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : reflection K x = x :=
(reflection_eq_self_iff x).mpr hx
/-- Reflection in the `submodule.map` of a subspace. -/
lemma reflection_map_apply {E E' : Type*}
[normed_add_comm_group E] [normed_add_comm_group E']
[inner_product_space 𝕜 E] [inner_product_space 𝕜 E']
(f : E ≃ₗᵢ[𝕜] E') (K : submodule 𝕜 E) [complete_space K] (x : E') :
reflection (K.map (f.to_linear_equiv : E →ₗ[𝕜] E')) x = f (reflection K (f.symm x)) :=
by simp [bit0, reflection_apply, orthogonal_projection_map_apply f K x]
/-- Reflection in the `submodule.map` of a subspace. -/
lemma reflection_map {E E' : Type*}
[normed_add_comm_group E] [normed_add_comm_group E']
[inner_product_space 𝕜 E] [inner_product_space 𝕜 E']
(f : E ≃ₗᵢ[𝕜] E') (K : submodule 𝕜 E) [complete_space K] :
reflection (K.map (f.to_linear_equiv : E →ₗ[𝕜] E')) = f.symm.trans ((reflection K).trans f) :=
linear_isometry_equiv.ext $ reflection_map_apply f K
/-- Reflection through the trivial subspace {0} is just negation. -/
@[simp] lemma reflection_bot : reflection (⊥ : submodule 𝕜 E) = linear_isometry_equiv.neg 𝕜 :=
by ext; simp [reflection_apply]
end reflection
section orthogonal
/-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/
lemma submodule.sup_orthogonal_inf_of_complete_space {K₁ K₂ : submodule 𝕜 E} (h : K₁ ≤ K₂)
[complete_space K₁] : K₁ ⊔ (K₁ᗮ ⊓ K₂) = K₂ :=
begin
ext x,
rw submodule.mem_sup,
let v : K₁ := orthogonal_projection K₁ x,
have hvm : x - v ∈ K₁ᗮ := sub_orthogonal_projection_mem_orthogonal x,
split,
{ rintro ⟨y, hy, z, hz, rfl⟩,
exact K₂.add_mem (h hy) hz.2 },
{ exact λ hx, ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel'_right _ _⟩ }
end
variables {K}
/-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/
lemma submodule.sup_orthogonal_of_complete_space [complete_space K] : K ⊔ Kᗮ = ⊤ :=
begin
convert submodule.sup_orthogonal_inf_of_complete_space (le_top : K ≤ ⊤),
simp
end
variables (K)
/-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/
lemma submodule.exists_sum_mem_mem_orthogonal [complete_space K] (v : E) :
∃ (y ∈ K) (z ∈ Kᗮ), v = y + z :=
begin
have h_mem : v ∈ K ⊔ Kᗮ := by simp [submodule.sup_orthogonal_of_complete_space],
obtain ⟨y, hy, z, hz, hyz⟩ := submodule.mem_sup.mp h_mem,
exact ⟨y, hy, z, hz, hyz.symm⟩
end
/-- If `K` is complete, then the orthogonal complement of its orthogonal complement is itself. -/
@[simp] lemma submodule.orthogonal_orthogonal [complete_space K] : Kᗮᗮ = K :=
begin
ext v,
split,
{ obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_sum_mem_mem_orthogonal v,
intros hv,
have hz' : z = 0,
{ have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_symm],
simpa [inner_add_right, hyz] using hv z hz },
simp [hy, hz'] },
{ intros hv w hw,
rw inner_eq_zero_symm,
exact hw v hv }
end
lemma submodule.orthogonal_orthogonal_eq_closure [complete_space E] :
Kᗮᗮ = K.topological_closure :=
begin
refine le_antisymm _ _,
{ convert submodule.orthogonal_orthogonal_monotone K.le_topological_closure,
haveI : complete_space K.topological_closure :=
K.is_closed_topological_closure.complete_space_coe,
rw K.topological_closure.orthogonal_orthogonal },
{ exact K.topological_closure_minimal K.le_orthogonal_orthogonal Kᗮ.is_closed_orthogonal }
end
variables {K}
/-- If `K` is complete, `K` and `Kᗮ` are complements of each other. -/
lemma submodule.is_compl_orthogonal_of_complete_space [complete_space K] : is_compl K Kᗮ :=
⟨K.orthogonal_disjoint, codisjoint_iff.2 submodule.sup_orthogonal_of_complete_space⟩
@[simp] lemma submodule.orthogonal_eq_bot_iff [complete_space (K : set E)] :
Kᗮ = ⊥ ↔ K = ⊤ :=
begin
refine ⟨_, λ h, by rw [h, submodule.top_orthogonal_eq_bot] ⟩,
intro h,
have : K ⊔ Kᗮ = ⊤ := submodule.sup_orthogonal_of_complete_space,
rwa [h, sup_comm, bot_sup_eq] at this,
end
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
lemma eq_orthogonal_projection_of_mem_orthogonal
[complete_space K] {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) :
(orthogonal_projection K u : E) = v :=
eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hv (λ w, inner_eq_zero_symm.mp ∘ (hvo w))
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
lemma eq_orthogonal_projection_of_mem_orthogonal'
[complete_space K] {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) :
(orthogonal_projection K u : E) = v :=
eq_orthogonal_projection_of_mem_orthogonal hv (by simpa [hu])
/-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/
lemma orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero
[complete_space K] {v : E} (hv : v ∈ Kᗮ) :
orthogonal_projection K v = 0 :=
by { ext, convert eq_orthogonal_projection_of_mem_orthogonal _ _; simp [hv] }
lemma orthogonal_projection_eq_linear_proj [complete_space K] (x : E) :
orthogonal_projection K x =
K.linear_proj_of_is_compl _ submodule.is_compl_orthogonal_of_complete_space x :=
begin
have : is_compl K Kᗮ := submodule.is_compl_orthogonal_of_complete_space,
nth_rewrite 0 [← submodule.linear_proj_add_linear_proj_of_is_compl_eq_self this x],
rw [map_add, orthogonal_projection_mem_subspace_eq_self,
orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero (submodule.coe_mem _),
add_zero]
end
lemma orthogonal_projection_coe_linear_map_eq_linear_proj [complete_space K] :
(orthogonal_projection K : E →ₗ[𝕜] K) =
K.linear_proj_of_is_compl _ submodule.is_compl_orthogonal_of_complete_space :=
linear_map.ext $ orthogonal_projection_eq_linear_proj
/-- The reflection in `K` of an element of `Kᗮ` is its negation. -/
lemma reflection_mem_subspace_orthogonal_complement_eq_neg
[complete_space K] {v : E} (hv : v ∈ Kᗮ) :
reflection K v = - v :=
by simp [reflection_apply, orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero hv]
/-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/
lemma orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero
[complete_space E] {v : E} (hv : v ∈ K) :
orthogonal_projection Kᗮ v = 0 :=
orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero (K.le_orthogonal_orthogonal hv)
/-- If `U ≤ V`, then projecting on `V` and then on `U` is the same as projecting on `U`. -/
lemma orthogonal_projection_orthogonal_projection_of_le {U V : submodule 𝕜 E} [complete_space U]
[complete_space V] (h : U ≤ V) (x : E) :
orthogonal_projection U (orthogonal_projection V x) = orthogonal_projection U x :=
eq.symm $ by simpa only [sub_eq_zero, map_sub] using
orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero
(submodule.orthogonal_le h (sub_orthogonal_projection_mem_orthogonal x))
/-- Given a monotone family `U` of complete submodules of `E` and a fixed `x : E`,
the orthogonal projection of `x` on `U i` tends to the orthogonal projection of `x` on
`(⨆ i, U i).topological_closure` along `at_top`. -/
lemma orthogonal_projection_tendsto_closure_supr [complete_space E] {ι : Type*}
[semilattice_sup ι] (U : ι → submodule 𝕜 E) [∀ i, complete_space (U i)]
(hU : monotone U) (x : E) :
filter.tendsto (λ i, (orthogonal_projection (U i) x : E)) at_top
(𝓝 (orthogonal_projection (⨆ i, U i).topological_closure x : E)) :=
begin
casesI is_empty_or_nonempty ι,
{ rw filter_eq_bot_of_is_empty (at_top : filter ι),
exact tendsto_bot },
let y := (orthogonal_projection (⨆ i, U i).topological_closure x : E),
have proj_x : ∀ i, orthogonal_projection (U i) x = orthogonal_projection (U i) y :=
λ i, (orthogonal_projection_orthogonal_projection_of_le
((le_supr U i).trans (supr U).le_topological_closure) _).symm,
suffices : ∀ ε > 0, ∃ I, ∀ i ≥ I, ‖(orthogonal_projection (U i) y : E) - y‖ < ε,
{ simpa only [proj_x, normed_add_comm_group.tendsto_at_top] using this },
intros ε hε,
obtain ⟨a, ha, hay⟩ : ∃ a ∈ ⨆ i, U i, dist y a < ε,
{ have y_mem : y ∈ (⨆ i, U i).topological_closure := submodule.coe_mem _,
rw [← set_like.mem_coe, submodule.topological_closure_coe, metric.mem_closure_iff] at y_mem,
exact y_mem ε hε },
rw dist_eq_norm at hay,
obtain ⟨I, hI⟩ : ∃ I, a ∈ U I,
{ rwa [submodule.mem_supr_of_directed _ (hU.directed_le)] at ha },
refine ⟨I, λ i (hi : I ≤ i), _⟩,
rw [norm_sub_rev, orthogonal_projection_minimal],
refine lt_of_le_of_lt _ hay,
change _ ≤ ‖y - (⟨a, hU hi hI⟩ : U i)‖,
exact cinfi_le ⟨0, set.forall_range_iff.mpr $ λ _, norm_nonneg _⟩ _,
end
/-- Given a monotone family `U` of complete submodules of `E` with dense span supremum,
and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to `x` along `at_top`. -/
lemma orthogonal_projection_tendsto_self [complete_space E] {ι : Type*} [semilattice_sup ι]
(U : ι → submodule 𝕜 E) [∀ t, complete_space (U t)] (hU : monotone U)
(x : E) (hU' : ⊤ ≤ (⨆ t, U t).topological_closure) :
filter.tendsto (λ t, (orthogonal_projection (U t) x : E)) at_top (𝓝 x) :=
begin
rw ← eq_top_iff at hU',
convert orthogonal_projection_tendsto_closure_supr U hU x,
rw orthogonal_projection_eq_self_iff.mpr _,
rw hU',
trivial
end
/-- The orthogonal complement satisfies `Kᗮᗮᗮ = Kᗮ`. -/
lemma submodule.triorthogonal_eq_orthogonal [complete_space E] : Kᗮᗮᗮ = Kᗮ :=
begin
rw Kᗮ.orthogonal_orthogonal_eq_closure,
exact K.is_closed_orthogonal.submodule_topological_closure_eq,
end
/-- The closure of `K` is the full space iff `Kᗮ` is trivial. -/
lemma submodule.topological_closure_eq_top_iff [complete_space E] :
K.topological_closure = ⊤ ↔ Kᗮ = ⊥ :=
begin
rw ←submodule.orthogonal_orthogonal_eq_closure,
split; intro h,
{ rw [←submodule.triorthogonal_eq_orthogonal, h, submodule.top_orthogonal_eq_bot] },
{ rw [h, submodule.bot_orthogonal_eq_top] }
end
namespace dense
open submodule
variables {x y : E} [complete_space E]
/-- If `S` is dense and `x - y ∈ Kᗮ`, then `x = y`. -/
lemma eq_of_sub_mem_orthogonal (hK : dense (K : set E)) (h : x - y ∈ Kᗮ) : x = y :=
begin
rw [dense_iff_topological_closure_eq_top, topological_closure_eq_top_iff] at hK,
rwa [hK, submodule.mem_bot, sub_eq_zero] at h,
end
lemma eq_zero_of_mem_orthogonal (hK : dense (K : set E)) (h : x ∈ Kᗮ) : x = 0 :=
hK.eq_of_sub_mem_orthogonal (by rwa [sub_zero])
lemma eq_of_inner_left (hK : dense (K : set E)) (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x = y :=
hK.eq_of_sub_mem_orthogonal (submodule.sub_mem_orthogonal_of_inner_left h)
lemma eq_zero_of_inner_left (hK : dense (K : set E)) (h : ∀ v : K, ⟪x, v⟫ = 0) : x = 0 :=
hK.eq_of_inner_left (λ v, by rw [inner_zero_left, h v])
lemma eq_of_inner_right (hK : dense (K : set E))
(h : ∀ v : K, ⟪(v : E), x⟫ = ⟪(v : E), y⟫) : x = y :=
hK.eq_of_sub_mem_orthogonal (submodule.sub_mem_orthogonal_of_inner_right h)
lemma eq_zero_of_inner_right (hK : dense (K : set E))
(h : ∀ v : K, ⟪(v : E), x⟫ = 0) : x = 0 :=
hK.eq_of_inner_right (λ v, by rw [inner_zero_right, h v])
end dense
/-- The reflection in `Kᗮ` of an element of `K` is its negation. -/
lemma reflection_mem_subspace_orthogonal_precomplement_eq_neg
[complete_space E] {v : E} (hv : v ∈ K) :
reflection Kᗮ v = -v :=
reflection_mem_subspace_orthogonal_complement_eq_neg (K.le_orthogonal_orthogonal hv)
/-- The orthogonal projection onto `(𝕜 ∙ v)ᗮ` of `v` is zero. -/
lemma orthogonal_projection_orthogonal_complement_singleton_eq_zero [complete_space E] (v : E) :
orthogonal_projection (𝕜 ∙ v)ᗮ v = 0 :=
orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero
(submodule.mem_span_singleton_self v)
/-- The reflection in `(𝕜 ∙ v)ᗮ` of `v` is `-v`. -/
lemma reflection_orthogonal_complement_singleton_eq_neg [complete_space E] (v : E) :
reflection (𝕜 ∙ v)ᗮ v = -v :=
reflection_mem_subspace_orthogonal_precomplement_eq_neg (submodule.mem_span_singleton_self v)
lemma reflection_sub [complete_space F] {v w : F} (h : ‖v‖ = ‖w‖) :
reflection (ℝ ∙ (v - w))ᗮ v = w :=
begin
set R : F ≃ₗᵢ[ℝ] F := reflection (ℝ ∙ (v - w))ᗮ,
suffices : R v + R v = w + w,
{ apply smul_right_injective F (by norm_num : (2:ℝ) ≠ 0),
simpa [two_smul] using this },
have h₁ : R (v - w) = -(v - w) := reflection_orthogonal_complement_singleton_eq_neg (v - w),
have h₂ : R (v + w) = v + w,
{ apply reflection_mem_subspace_eq_self,
rw submodule.mem_orthogonal_singleton_iff_inner_left,
rw real_inner_add_sub_eq_zero_iff,
exact h },
convert congr_arg2 (+) h₂ h₁ using 1,
{ simp },
{ abel }
end
variables (K)
/-- In a complete space `E`, a vector splits as the sum of its orthogonal projections onto a
complete submodule `K` and onto the orthogonal complement of `K`.-/
lemma eq_sum_orthogonal_projection_self_orthogonal_complement
[complete_space E] [complete_space K] (w : E) :
w = (orthogonal_projection K w : E) + (orthogonal_projection Kᗮ w : E) :=
begin
obtain ⟨y, hy, z, hz, hwyz⟩ := K.exists_sum_mem_mem_orthogonal w,
convert hwyz,
{ exact eq_orthogonal_projection_of_mem_orthogonal' hy hz hwyz },
{ rw add_comm at hwyz,
refine eq_orthogonal_projection_of_mem_orthogonal' hz _ hwyz,
simp [hy] }
end
/-- The Pythagorean theorem, for an orthogonal projection.-/
lemma norm_sq_eq_add_norm_sq_projection
(x : E) (S : submodule 𝕜 E) [complete_space E] [complete_space S] :
‖x‖^2 = ‖orthogonal_projection S x‖^2 + ‖orthogonal_projection Sᗮ x‖^2 :=
begin
let p1 := orthogonal_projection S,
let p2 := orthogonal_projection Sᗮ,
have x_decomp : x = p1 x + p2 x :=
eq_sum_orthogonal_projection_self_orthogonal_complement S x,
have x_orth : ⟪ (p1 x : E), p2 x ⟫ = 0 :=
submodule.inner_right_of_mem_orthogonal (set_like.coe_mem (p1 x)) (set_like.coe_mem (p2 x)),
nth_rewrite 0 [x_decomp],
simp only [sq, norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero ((p1 x) : E) (p2 x) x_orth,
add_left_inj, mul_eq_mul_left_iff, norm_eq_zero, true_or, eq_self_iff_true,
submodule.coe_norm, submodule.coe_eq_zero]
end
/-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal
complement sum to the identity. -/
lemma id_eq_sum_orthogonal_projection_self_orthogonal_complement
[complete_space E] [complete_space K] :
continuous_linear_map.id 𝕜 E
= K.subtypeL.comp (orthogonal_projection K)
+ Kᗮ.subtypeL.comp (orthogonal_projection Kᗮ) :=
by { ext w, exact eq_sum_orthogonal_projection_self_orthogonal_complement K w }
@[simp] lemma inner_orthogonal_projection_eq_of_mem_right [complete_space K] (u : K) (v : E) :
⟪orthogonal_projection K v, u⟫ = ⟪v, u⟫ :=
calc ⟪orthogonal_projection K v, u⟫
= ⟪(orthogonal_projection K v : E), u⟫ : K.coe_inner _ _
... = ⟪(orthogonal_projection K v : E), u⟫ + ⟪v - orthogonal_projection K v, u⟫ :
by rw [orthogonal_projection_inner_eq_zero _ _ (submodule.coe_mem _), add_zero]
... = ⟪v, u⟫ :
by rw [← inner_add_left, add_sub_cancel'_right]
@[simp] lemma inner_orthogonal_projection_eq_of_mem_left [complete_space K] (u : K) (v : E) :
⟪u, orthogonal_projection K v⟫ = ⟪(u : E), v⟫ :=
by rw [← inner_conj_symm, ← inner_conj_symm (u : E), inner_orthogonal_projection_eq_of_mem_right]
/-- The orthogonal projection is self-adjoint. -/
lemma inner_orthogonal_projection_left_eq_right
[complete_space K] (u v : E) :
⟪↑(orthogonal_projection K u), v⟫ = ⟪u, orthogonal_projection K v⟫ :=
by rw [← inner_orthogonal_projection_eq_of_mem_left, inner_orthogonal_projection_eq_of_mem_right]
/-- The orthogonal projection is symmetric. -/
lemma orthogonal_projection_is_symmetric
[complete_space K] :
(K.subtypeL ∘L orthogonal_projection K : E →ₗ[𝕜] E).is_symmetric :=
inner_orthogonal_projection_left_eq_right K
open finite_dimensional
/-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁`
containined in it, the dimensions of `K₁` and the intersection of its
orthogonal subspace with `K₂` add to that of `K₂`. -/
lemma submodule.finrank_add_inf_finrank_orthogonal {K₁ K₂ : submodule 𝕜 E}
[finite_dimensional 𝕜 K₂] (h : K₁ ≤ K₂) :
finrank 𝕜 K₁ + finrank 𝕜 (K₁ᗮ ⊓ K₂ : submodule 𝕜 E) = finrank 𝕜 K₂ :=
begin
haveI := submodule.finite_dimensional_of_le h,
haveI := proper_is_R_or_C 𝕜 K₁,
have hd := submodule.dim_sup_add_dim_inf_eq K₁ (K₁ᗮ ⊓ K₂),
rw [←inf_assoc, (submodule.orthogonal_disjoint K₁).eq_bot, bot_inf_eq, finrank_bot,
submodule.sup_orthogonal_inf_of_complete_space h] at hd,
rw add_zero at hd,
exact hd.symm
end
/-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁`
containined in it, the dimensions of `K₁` and the intersection of its
orthogonal subspace with `K₂` add to that of `K₂`. -/
lemma submodule.finrank_add_inf_finrank_orthogonal' {K₁ K₂ : submodule 𝕜 E}
[finite_dimensional 𝕜 K₂] (h : K₁ ≤ K₂) {n : ℕ} (h_dim : finrank 𝕜 K₁ + n = finrank 𝕜 K₂) :
finrank 𝕜 (K₁ᗮ ⊓ K₂ : submodule 𝕜 E) = n :=
by { rw ← add_right_inj (finrank 𝕜 K₁),
simp [submodule.finrank_add_inf_finrank_orthogonal h, h_dim] }
/-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to
that of `E`. -/
lemma submodule.finrank_add_finrank_orthogonal [finite_dimensional 𝕜 E] (K : submodule 𝕜 E) :
finrank 𝕜 K + finrank 𝕜 Kᗮ = finrank 𝕜 E :=
begin
convert submodule.finrank_add_inf_finrank_orthogonal (le_top : K ≤ ⊤) using 1,
{ rw inf_top_eq },
{ simp }
end
/-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to
that of `E`. -/
lemma submodule.finrank_add_finrank_orthogonal' [finite_dimensional 𝕜 E] {K : submodule 𝕜 E} {n : ℕ}
(h_dim : finrank 𝕜 K + n = finrank 𝕜 E) :
finrank 𝕜 Kᗮ = n :=
by { rw ← add_right_inj (finrank 𝕜 K), simp [submodule.finrank_add_finrank_orthogonal, h_dim] }
local attribute [instance] fact_finite_dimensional_of_finrank_eq_succ
/-- In a finite-dimensional inner product space, the dimension of the orthogonal complement of the
span of a nonzero vector is one less than the dimension of the space. -/
lemma finrank_orthogonal_span_singleton {n : ℕ} [_i : fact (finrank 𝕜 E = n + 1)]
{v : E} (hv : v ≠ 0) :
finrank 𝕜 (𝕜 ∙ v)ᗮ = n :=
submodule.finrank_add_finrank_orthogonal' $ by simp [finrank_span_singleton hv, _i.elim, add_comm]
/-- An element `φ` of the orthogonal group of `F` can be factored as a product of reflections, and
specifically at most as many reflections as the dimension of the complement of the fixed subspace
of `φ`. -/
lemma linear_isometry_equiv.reflections_generate_dim_aux [finite_dimensional ℝ F] {n : ℕ}
(φ : F ≃ₗᵢ[ℝ] F)
(hn : finrank ℝ (ker (continuous_linear_map.id ℝ F - φ))ᗮ ≤ n) :
∃ l : list F, l.length ≤ n ∧ φ = (l.map (λ v, reflection (ℝ ∙ v)ᗮ)).prod :=
begin
-- We prove this by strong induction on `n`, the dimension of the orthogonal complement of the
-- fixed subspace of the endomorphism `φ`
induction n with n IH generalizing φ,
{ -- Base case: `n = 0`, the fixed subspace is the whole space, so `φ = id`
refine ⟨[], rfl.le, show φ = 1, from _⟩,
have : ker (continuous_linear_map.id ℝ F - φ) = ⊤,
{ rwa [le_zero_iff, finrank_eq_zero, submodule.orthogonal_eq_bot_iff] at hn },
symmetry,
ext x,
have := linear_map.congr_fun (linear_map.ker_eq_top.mp this) x,
simpa only [sub_eq_zero, continuous_linear_map.to_linear_map_eq_coe,
continuous_linear_map.coe_sub, linear_map.sub_apply, linear_map.zero_apply]
using this },
{ -- Inductive step. Let `W` be the fixed subspace of `φ`. We suppose its complement to have
-- dimension at most n + 1.
let W := ker (continuous_linear_map.id ℝ F - φ),
have hW : ∀ w ∈ W, φ w = w := λ w hw, (sub_eq_zero.mp hw).symm,
by_cases hn' : finrank ℝ Wᗮ ≤ n,
{ obtain ⟨V, hV₁, hV₂⟩ := IH φ hn',
exact ⟨V, hV₁.trans n.le_succ, hV₂⟩ },
-- Take a nonzero element `v` of the orthogonal complement of `W`.
haveI : nontrivial Wᗮ := nontrivial_of_finrank_pos (by linarith [zero_le n] : 0 < finrank ℝ Wᗮ),
obtain ⟨v, hv⟩ := exists_ne (0 : Wᗮ),
have hφv : φ v ∈ Wᗮ,
{ intros w hw,
rw [← hW w hw, linear_isometry_equiv.inner_map_map],
exact v.prop w hw },
have hv' : (v:F) ∉ W,
{ intros h,
exact hv ((submodule.mem_left_iff_eq_zero_of_disjoint W.orthogonal_disjoint).mp h) },
-- Let `ρ` be the reflection in `v - φ v`; this is designed to swap `v` and `φ v`
let x : F := v - φ v,
let ρ := reflection (ℝ ∙ x)ᗮ,
-- Notation: Let `V` be the fixed subspace of `φ.trans ρ`
let V := ker (continuous_linear_map.id ℝ F - (φ.trans ρ)),
have hV : ∀ w, ρ (φ w) = w → w ∈ V,
{ intros w hw,
change w - ρ (φ w) = 0,
rw [sub_eq_zero, hw] },
-- Everything fixed by `φ` is fixed by `φ.trans ρ`
have H₂V : W ≤ V,
{ intros w hw,
apply hV,
rw hW w hw,
refine reflection_mem_subspace_eq_self _,
rw submodule.mem_orthogonal_singleton_iff_inner_left,
exact submodule.sub_mem _ v.prop hφv _ hw },
-- `v` is also fixed by `φ.trans ρ`
have H₁V : (v : F) ∈ V,
{ apply hV,
have : ρ v = φ v := reflection_sub (φ.norm_map v).symm,
rw ←this,
exact reflection_reflection _ _, },
-- By dimension-counting, the complement of the fixed subspace of `φ.trans ρ` has dimension at
-- most `n`
have : finrank ℝ Vᗮ ≤ n,
{ change finrank ℝ Wᗮ ≤ n + 1 at hn,
have : finrank ℝ W + 1 ≤ finrank ℝ V :=
submodule.finrank_lt_finrank_of_lt (set_like.lt_iff_le_and_exists.2 ⟨H₂V, v, H₁V, hv'⟩),
have : finrank ℝ V + finrank ℝ Vᗮ = finrank ℝ F := V.finrank_add_finrank_orthogonal,
have : finrank ℝ W + finrank ℝ Wᗮ = finrank ℝ F := W.finrank_add_finrank_orthogonal,
linarith },
-- So apply the inductive hypothesis to `φ.trans ρ`
obtain ⟨l, hl, hφl⟩ := IH (ρ * φ) this,
-- Prepend `ρ` to the factorization into reflections obtained for `φ.trans ρ`; this gives a
-- factorization into reflections for `φ`.
refine ⟨x :: l, nat.succ_le_succ hl, _⟩,
rw [list.map_cons, list.prod_cons],
have := congr_arg ((*) ρ) hφl,
rwa [←mul_assoc, reflection_mul_reflection, one_mul] at this, }
end
/-- The orthogonal group of `F` is generated by reflections; specifically each element `φ` of the
orthogonal group is a product of at most as many reflections as the dimension of `F`.
Special case of the **Cartan–Dieudonné theorem**. -/
lemma linear_isometry_equiv.reflections_generate_dim [finite_dimensional ℝ F] (φ : F ≃ₗᵢ[ℝ] F) :
∃ l : list F, l.length ≤ finrank ℝ F ∧ φ = (l.map (λ v, reflection (ℝ ∙ v)ᗮ)).prod :=
let ⟨l, hl₁, hl₂⟩ := φ.reflections_generate_dim_aux le_rfl in
⟨l, hl₁.trans (submodule.finrank_le _), hl₂⟩
/-- The orthogonal group of `F` is generated by reflections. -/
lemma linear_isometry_equiv.reflections_generate [finite_dimensional ℝ F] :
subgroup.closure (set.range (λ v : F, reflection (ℝ ∙ v)ᗮ)) = ⊤ :=
begin
rw subgroup.eq_top_iff',
intros φ,
rcases φ.reflections_generate_dim with ⟨l, _, rfl⟩,
apply (subgroup.closure _).list_prod_mem,
intros x hx,
rcases list.mem_map.mp hx with ⟨a, _, hax⟩,
exact subgroup.subset_closure ⟨a, hax⟩,
end
end orthogonal
section orthogonal_family
variables {ι : Type*}
/-- An orthogonal family of subspaces of `E` satisfies `direct_sum.is_internal` (that is,
they provide an internal direct sum decomposition of `E`) if and only if their span has trivial
orthogonal complement. -/
lemma orthogonal_family.is_internal_iff_of_is_complete [decidable_eq ι]
{V : ι → submodule 𝕜 E} (hV : orthogonal_family 𝕜 (λ i, V i) (λ i, (V i).subtypeₗᵢ))
(hc : is_complete (↑(supr V) : set E)) :
direct_sum.is_internal V ↔ (supr V)ᗮ = ⊥ :=
begin
haveI : complete_space ↥(supr V) := hc.complete_space_coe,
simp only [direct_sum.is_internal_submodule_iff_independent_and_supr_eq_top, hV.independent,
true_and, submodule.orthogonal_eq_bot_iff]
end
/-- An orthogonal family of subspaces of `E` satisfies `direct_sum.is_internal` (that is,
they provide an internal direct sum decomposition of `E`) if and only if their span has trivial
orthogonal complement. -/
lemma orthogonal_family.is_internal_iff [decidable_eq ι] [finite_dimensional 𝕜 E]
{V : ι → submodule 𝕜 E} (hV : orthogonal_family 𝕜 (λ i, V i) (λ i, (V i).subtypeₗᵢ)) :
direct_sum.is_internal V ↔ (supr V)ᗮ = ⊥ :=
begin
haveI h := finite_dimensional.proper_is_R_or_C 𝕜 ↥(supr V),
exact hV.is_internal_iff_of_is_complete
(complete_space_coe_iff_is_complete.mp infer_instance)
end
end orthogonal_family
section orthonormal_basis
variables {𝕜 E} {v : set E}
open finite_dimensional submodule set
/-- An orthonormal set in an `inner_product_space` is maximal, if and only if the orthogonal
complement of its span is empty. -/
lemma maximal_orthonormal_iff_orthogonal_complement_eq_bot (hv : orthonormal 𝕜 (coe : v → E)) :
(∀ u ⊇ v, orthonormal 𝕜 (coe : u → E) → u = v) ↔ (span 𝕜 v)ᗮ = ⊥ :=
begin
rw submodule.eq_bot_iff,
split,
{ contrapose!,
-- ** direction 1: nonempty orthogonal complement implies nonmaximal
rintros ⟨x, hx', hx⟩,
-- take a nonzero vector and normalize it
let e := (‖x‖⁻¹ : 𝕜) • x,
have he : ‖e‖ = 1 := by simp [e, norm_smul_inv_norm hx],
have he' : e ∈ (span 𝕜 v)ᗮ := smul_mem' _ _ hx',
have he'' : e ∉ v,
{ intros hev,
have : e = 0,
{ have : e ∈ (span 𝕜 v) ⊓ (span 𝕜 v)ᗮ := ⟨subset_span hev, he'⟩,
simpa [(span 𝕜 v).inf_orthogonal_eq_bot] using this },
have : e ≠ 0 := hv.ne_zero ⟨e, hev⟩,
contradiction },
-- put this together with `v` to provide a candidate orthonormal basis for the whole space
refine ⟨insert e v, v.subset_insert e, ⟨_, _⟩, (v.ne_insert_of_not_mem he'').symm⟩,
{ -- show that the elements of `insert e v` have unit length
rintros ⟨a, ha'⟩,
cases eq_or_mem_of_mem_insert ha' with ha ha,
{ simp [ha, he] },
{ exact hv.1 ⟨a, ha⟩ } },
{ -- show that the elements of `insert e v` are orthogonal
have h_end : ∀ a ∈ v, ⟪a, e⟫ = 0,
{ intros a ha,
exact he' a (submodule.subset_span ha) },
rintros ⟨a, ha'⟩,
cases eq_or_mem_of_mem_insert ha' with ha ha,
{ rintros ⟨b, hb'⟩ hab',
have hb : b ∈ v,
{ refine mem_of_mem_insert_of_ne hb' _,
intros hbe',
apply hab',
simp [ha, hbe'] },
rw inner_eq_zero_symm,
simpa [ha] using h_end b hb },
rintros ⟨b, hb'⟩ hab',
cases eq_or_mem_of_mem_insert hb' with hb hb,
{ simpa [hb] using h_end a ha },
have : (⟨a, ha⟩ : v) ≠ ⟨b, hb⟩,
{ intros hab'',
apply hab',
simpa using hab'' },
exact hv.2 this } },
{ -- ** direction 2: empty orthogonal complement implies maximal
simp only [subset.antisymm_iff],
rintros h u (huv : v ⊆ u) hu,
refine ⟨_, huv⟩,
intros x hxu,
refine ((mt (h x)) (hu.ne_zero ⟨x, hxu⟩)).imp_symm _,
intros hxv y hy,
have hxv' : (⟨x, hxu⟩ : u) ∉ (coe ⁻¹' v : set u) := by simp [huv, hxv],
obtain ⟨l, hl, rfl⟩ :
∃ l ∈ finsupp.supported 𝕜 𝕜 (coe ⁻¹' v : set u), (finsupp.total ↥u E 𝕜 coe) l = y,
{ rw ← finsupp.mem_span_image_iff_total,
simp [huv, inter_eq_self_of_subset_left, hy] },
exact hu.inner_finsupp_eq_zero hxv' hl }
end
variables [finite_dimensional 𝕜 E]
/-- An orthonormal set in a finite-dimensional `inner_product_space` is maximal, if and only if it
is a basis. -/
lemma maximal_orthonormal_iff_basis_of_finite_dimensional
(hv : orthonormal 𝕜 (coe : v → E)) :
(∀ u ⊇ v, orthonormal 𝕜 (coe : u → E) → u = v) ↔ ∃ b : basis v 𝕜 E, ⇑b = coe :=
begin
haveI := proper_is_R_or_C 𝕜 (span 𝕜 v),
rw maximal_orthonormal_iff_orthogonal_complement_eq_bot hv,
have hv_compl : is_complete (span 𝕜 v : set E) := (span 𝕜 v).complete_of_finite_dimensional,
rw submodule.orthogonal_eq_bot_iff,
have hv_coe : range (coe : v → E) = v := by simp,
split,
{ refine λ h, ⟨basis.mk hv.linear_independent _, basis.coe_mk _ _⟩,
convert h.ge },
{ rintros ⟨h, coe_h⟩,
rw [← h.span_eq, coe_h, hv_coe] }
end
end orthonormal_basis
|
{-# LANGUAGE DataKinds #-}
module Main where
import Control.Monad.State (execState)
import Data.List.Split (splitOn)
import Control.DeepSeq
import Control.Exception.Base
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.State
import Data.Bitraversable
import Data.IDX
import Data.Maybe
import Data.Traversable
import Data.Tuple
import qualified Data.Vector as V
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Unboxed as VU
import GHC.TypeLits
import qualified Numeric.LinearAlgebra as HM -- non-backprop hmatrix
import qualified Numeric.LinearAlgebra.Data as HMD
import qualified Numeric.LinearAlgebra.Static as HMS -- hmatrix with type-checked operations :D
import System.IO
import MNIST
import Neural
import Regression (activate, forward, loss, runTrain)
import Titanic (getAge, processFeatures, processTargets)
readCSV :: [Char] -> [[[Char]]]
readCSV file = [splitOn "," x | x <- (lines file)]
accuracy :: [Double] -> [Double] -> Int -> Double
accuracy targets predictions batchSize = (fromIntegral correct) / (fromIntegral batchSize) where
correct = length $ filter (\idx -> targets !! idx == (activate predictions) !! idx) [0..batchSize-1]
main = do
-- Logistic Regression
--
-- contents <- readFile "data/titanic/train.csv"
-- let weights = matrix 1 [0.0 | _ <- [0..7]]
-- let inputs = processFeatures $ tail (readCSV contents)
-- let targets = processTargets $ tail (readCSV contents)
-- -- subtract the header row
-- let batchSize = (length $ toLists inputs) - 1
-- let finalWeights = (execState (runTrain inputs targets batchSize) weights)
-- let finalPredictions = forward inputs finalWeights
-- print $ accuracy (concat $ toLists targets) (concat $ toLists finalPredictions) batchSize
-- print $ loss targets finalPredictions batchSize
-- MNIST Multilayer Perceptron
--
-- Just train <- loadMNIST "data/mnist/train-images-idx3-ubyte" "data/mnist/train-labels-idx1-ubyte"
-- Just test <- loadMNIST "data/mnist/t10k-images-idx3-ubyte" "data/mnist/t10k-labels-idx1-ubyte"
weightsInit <- HM.rand 728 300
inputsInit <- HM.rand 1 728
biasInit <- HM.rand 1 300
yInit <- HM.rand 1 10
let weights = HMS.matrix (concat $ HM.toLists weightsInit) :: HMS.L 728 300
let inputs = HMS.matrix (concat $ HM.toLists inputsInit) :: HMS.L 1 728
let bias = HMS.matrix (concat $ HM.toLists biasInit) :: HMS.L 1 300
let y = HMS.vector (concat $ HM.toLists yInit) :: HMS.R 10
print $ relu $ linear weights bias inputs
|
3
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to ◇
------------------------------------------------------------------------
module Data.Container.Any where
open import Algebra
open import Data.Container as C
open import Data.Container.Combinator
using (module Composition) renaming (_∘_ to _⟨∘⟩_)
open import Data.Product as Prod hiding (swap)
open import Data.Sum
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as Inv using (_↔_; module Inverse)
open import Function.Related as Related using (Related)
open import Function.Related.TypeIsomorphisms
import Relation.Binary.HeterogeneousEquality as H
open import Relation.Binary.Product.Pointwise
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≗_; refl)
import Relation.Binary.Sigma.Pointwise as Σ
open Related.EquationalReasoning
private
module ×⊎ {k ℓ} = CommutativeSemiring (×⊎-CommutativeSemiring k ℓ)
-- ◇ can be expressed using _∈_.
↔∈ : ∀ {c} (C : Container c) {X : Set c}
{P : X → Set c} {xs : ⟦ C ⟧ X} →
◇ P xs ↔ (∃ λ x → x ∈ xs × P x)
↔∈ _ {P = P} {xs} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = λ _ → refl
; right-inverse-of = to∘from
}
}
where
to : ◇ P xs → ∃ λ x → x ∈ xs × P x
to (p , Px) = (proj₂ xs p , (p , refl) , Px)
from : (∃ λ x → x ∈ xs × P x) → ◇ P xs
from (.(proj₂ xs p) , (p , refl) , Px) = (p , Px)
to∘from : to ∘ from ≗ id
to∘from (.(proj₂ xs p) , (p , refl) , Px) = refl
-- ◇ is a congruence for bag and set equality and related preorders.
cong : ∀ {k c} {C : Container c}
{X : Set c} {P₁ P₂ : X → Set c} {xs₁ xs₂ : ⟦ C ⟧ X} →
(∀ x → Related k (P₁ x) (P₂ x)) → xs₁ ∼[ k ] xs₂ →
Related k (◇ P₁ xs₁) (◇ P₂ xs₂)
cong {C = C} {P₁ = P₁} {P₂} {xs₁} {xs₂} P₁↔P₂ xs₁≈xs₂ =
◇ P₁ xs₁ ↔⟨ ↔∈ C ⟩
(∃ λ x → x ∈ xs₁ × P₁ x) ∼⟨ Σ.cong Inv.id (xs₁≈xs₂ ×-cong P₁↔P₂ _) ⟩
(∃ λ x → x ∈ xs₂ × P₂ x) ↔⟨ sym (↔∈ C) ⟩
◇ P₂ xs₂ ∎
-- Nested occurrences of ◇ can sometimes be swapped.
swap : ∀ {c} {C₁ C₂ : Container c} {X Y : Set c} {P : X → Y → Set c}
{xs : ⟦ C₁ ⟧ X} {ys : ⟦ C₂ ⟧ Y} →
let ◈ : ∀ {C : Container c} {X} → ⟦ C ⟧ X → (X → Set c) → Set c
◈ = λ {_} {_} → flip ◇ in
◈ xs (◈ ys ∘ P) ↔ ◈ ys (◈ xs ∘ flip P)
swap {c} {C₁} {C₂} {P = P} {xs} {ys} =
◇ (λ x → ◇ (P x) ys) xs ↔⟨ ↔∈ C₁ ⟩
(∃ λ x → x ∈ xs × ◇ (P x) ys) ↔⟨ Σ.cong Inv.id (λ {x} → Inv.id ⟨ ×⊎.*-cong {ℓ = c} ⟩ ↔∈ C₂ {P = P x}) ⟩
(∃ λ x → x ∈ xs × ∃ λ y → y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (λ {x} → ∃∃↔∃∃ {A = x ∈ xs} (λ _ y → y ∈ ys × P x y)) ⟩
(∃₂ λ x y → x ∈ xs × y ∈ ys × P x y) ↔⟨ ∃∃↔∃∃ (λ x y → x ∈ xs × y ∈ ys × P x y) ⟩
(∃₂ λ y x → x ∈ xs × y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → Σ.cong Inv.id (λ {x} →
(x ∈ xs × y ∈ ys × P x y) ↔⟨ sym $ ×⊎.*-assoc _ _ _ ⟩
((x ∈ xs × y ∈ ys) × P x y) ↔⟨ ×⊎.*-comm _ _ ⟨ ×⊎.*-cong {ℓ = c} ⟩ Inv.id ⟩
((y ∈ ys × x ∈ xs) × P x y) ↔⟨ ×⊎.*-assoc _ _ _ ⟩
(y ∈ ys × x ∈ xs × P x y) ∎)) ⟩
(∃₂ λ y x → y ∈ ys × x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → ∃∃↔∃∃ {B = y ∈ ys} (λ x _ → x ∈ xs × P x y)) ⟩
(∃ λ y → y ∈ ys × ∃ λ x → x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → Inv.id ⟨ ×⊎.*-cong {ℓ = c} ⟩ sym (↔∈ C₁ {P = flip P y})) ⟩
(∃ λ y → y ∈ ys × ◇ (flip P y) xs) ↔⟨ sym (↔∈ C₂) ⟩
◇ (λ y → ◇ (flip P y) xs) ys ∎
-- Nested occurrences of ◇ can sometimes be flattened.
flatten : ∀ {c} {C₁ C₂ : Container c} {X}
P (xss : ⟦ C₁ ⟧ (⟦ C₂ ⟧ X)) →
◇ (◇ P) xss ↔
◇ P (Inverse.from (Composition.correct C₁ C₂) ⟨$⟩ xss)
flatten {C₁ = C₁} {C₂} {X} P xss = record
{ to = P.→-to-⟶ t
; from = P.→-to-⟶ f
; inverse-of = record
{ left-inverse-of = λ _ → refl
; right-inverse-of = λ _ → refl
}
}
where
open Inverse
t : ◇ (◇ P) xss → ◇ P (from (Composition.correct C₁ C₂) ⟨$⟩ xss)
t (p₁ , p₂ , p) = ((p₁ , p₂) , p)
f : ◇ P (from (Composition.correct C₁ C₂) ⟨$⟩ xss) → ◇ (◇ P) xss
f ((p₁ , p₂) , p) = (p₁ , p₂ , p)
-- Sums commute with ◇ (for a fixed instance of a given container).
◇⊎↔⊎◇ : ∀ {c} {C : Container c} {X : Set c} {xs : ⟦ C ⟧ X}
{P Q : X → Set c} →
◇ (λ x → P x ⊎ Q x) xs ↔ (◇ P xs ⊎ ◇ Q xs)
◇⊎↔⊎◇ {xs = xs} {P} {Q} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = from∘to
; right-inverse-of = [ (λ _ → refl) , (λ _ → refl) ]
}
}
where
to : ◇ (λ x → P x ⊎ Q x) xs → ◇ P xs ⊎ ◇ Q xs
to (pos , inj₁ p) = inj₁ (pos , p)
to (pos , inj₂ q) = inj₂ (pos , q)
from : ◇ P xs ⊎ ◇ Q xs → ◇ (λ x → P x ⊎ Q x) xs
from = [ Prod.map id inj₁ , Prod.map id inj₂ ]
from∘to : from ∘ to ≗ id
from∘to (pos , inj₁ p) = refl
from∘to (pos , inj₂ q) = refl
-- Products "commute" with ◇.
×◇↔◇◇× : ∀ {c} {C₁ C₂ : Container c}
{X Y} {P : X → Set c} {Q : Y → Set c}
{xs : ⟦ C₁ ⟧ X} {ys : ⟦ C₂ ⟧ Y} →
◇ (λ x → ◇ (λ y → P x × Q y) ys) xs ↔ (◇ P xs × ◇ Q ys)
×◇↔◇◇× {C₁ = C₁} {C₂} {P = P} {Q} {xs} {ys} = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = λ _ → refl
; right-inverse-of = λ _ → refl
}
}
where
to : ◇ (λ x → ◇ (λ y → P x × Q y) ys) xs → ◇ P xs × ◇ Q ys
to (p₁ , p₂ , p , q) = ((p₁ , p) , (p₂ , q))
from : ◇ P xs × ◇ Q ys → ◇ (λ x → ◇ (λ y → P x × Q y) ys) xs
from ((p₁ , p) , (p₂ , q)) = (p₁ , p₂ , p , q)
-- map can be absorbed by the predicate.
map↔∘ : ∀ {c} (C : Container c) {X Y : Set c}
(P : Y → Set c) {xs : ⟦ C ⟧ X} (f : X → Y) →
◇ P (C.map f xs) ↔ ◇ (P ∘ f) xs
map↔∘ _ _ _ = Inv.id
-- Membership in a mapped container can be expressed without reference
-- to map.
∈map↔∈×≡ : ∀ {c} (C : Container c) {X Y : Set c} {f : X → Y}
{xs : ⟦ C ⟧ X} {y} →
y ∈ C.map f xs ↔ (∃ λ x → x ∈ xs × y ≡ f x)
∈map↔∈×≡ {c} C {f = f} {xs} {y} =
y ∈ C.map f xs ↔⟨ map↔∘ C (_≡_ y) f ⟩
◇ (λ x → y ≡ f x) xs ↔⟨ ↔∈ C ⟩
(∃ λ x → x ∈ xs × y ≡ f x) ∎
-- map is a congruence for bag and set equality and related preorders.
map-cong : ∀ {k c} {C : Container c} {X Y : Set c}
{f₁ f₂ : X → Y} {xs₁ xs₂ : ⟦ C ⟧ X} →
f₁ ≗ f₂ → xs₁ ∼[ k ] xs₂ →
C.map f₁ xs₁ ∼[ k ] C.map f₂ xs₂
map-cong {c = c} {C} {f₁ = f₁} {f₂} {xs₁} {xs₂} f₁≗f₂ xs₁≈xs₂ {x} =
x ∈ C.map f₁ xs₁ ↔⟨ map↔∘ C (_≡_ x) f₁ ⟩
◇ (λ y → x ≡ f₁ y) xs₁ ∼⟨ cong {xs₁ = xs₁} {xs₂ = xs₂} (Related.↔⇒ ∘ helper) xs₁≈xs₂ ⟩
◇ (λ y → x ≡ f₂ y) xs₂ ↔⟨ sym (map↔∘ C (_≡_ x) f₂) ⟩
x ∈ C.map f₂ xs₂ ∎
where
helper : ∀ y → (x ≡ f₁ y) ↔ (x ≡ f₂ y)
helper y = record
{ to = P.→-to-⟶ (λ x≡f₁y → P.trans x≡f₁y ( f₁≗f₂ y))
; from = P.→-to-⟶ (λ x≡f₂y → P.trans x≡f₂y (P.sym $ f₁≗f₂ y))
; inverse-of = record
{ left-inverse-of = λ _ → P.proof-irrelevance _ _
; right-inverse-of = λ _ → P.proof-irrelevance _ _
}
}
-- Uses of linear morphisms can be removed.
remove-linear :
∀ {c} {C₁ C₂ : Container c} {X} {xs : ⟦ C₁ ⟧ X}
(P : X → Set c) (m : C₁ ⊸ C₂) →
◇ P (⟪ m ⟫⊸ xs) ↔ ◇ P xs
remove-linear {xs = xs} P m = record
{ to = P.→-to-⟶ t
; from = P.→-to-⟶ f
; inverse-of = record
{ left-inverse-of = f∘t
; right-inverse-of = t∘f
}
}
where
open Inverse
t : ◇ P (⟪ m ⟫⊸ xs) → ◇ P xs
t = Prod.map (_⟨$⟩_ (to (position⊸ m))) id
f : ◇ P xs → ◇ P (⟪ m ⟫⊸ xs)
f = Prod.map (_⟨$⟩_ (from (position⊸ m)))
(P.subst (P ∘ proj₂ xs)
(P.sym $ right-inverse-of (position⊸ m) _))
f∘t : f ∘ t ≗ id
f∘t (p₂ , p) = H.≅-to-≡ $
H.cong₂ _,_ (H.≡-to-≅ $ left-inverse-of (position⊸ m) p₂)
(H.≡-subst-removable
(P ∘ proj₂ xs)
(P.sym (right-inverse-of (position⊸ m)
(to (position⊸ m) ⟨$⟩ p₂)))
p)
t∘f : t ∘ f ≗ id
t∘f (p₁ , p) = H.≅-to-≡ $
H.cong₂ _,_ (H.≡-to-≅ $ right-inverse-of (position⊸ m) p₁)
(H.≡-subst-removable
(P ∘ proj₂ xs)
(P.sym (right-inverse-of (position⊸ m) p₁))
p)
-- Linear endomorphisms are identity functions if bag equality is
-- used.
linear-identity :
∀ {c} {C : Container c} {X} {xs : ⟦ C ⟧ X} (m : C ⊸ C) →
⟪ m ⟫⊸ xs ∼[ bag ] xs
linear-identity {xs = xs} m {x} =
x ∈ ⟪ m ⟫⊸ xs ↔⟨ remove-linear (_≡_ x) m ⟩
x ∈ xs ∎
-- If join can be expressed using a linear morphism (in a certain
-- way), then it can be absorbed by the predicate.
join↔◇ : ∀ {c} {C₁ C₂ C₃ : Container c} {X}
P (join′ : (C₁ ⟨∘⟩ C₂) ⊸ C₃) (xss : ⟦ C₁ ⟧ (⟦ C₂ ⟧ X)) →
let join : ∀ {X} → ⟦ C₁ ⟧ (⟦ C₂ ⟧ X) → ⟦ C₃ ⟧ X
join = λ {_} → ⟪ join′ ⟫⊸ ∘
_⟨$⟩_ (Inverse.from (Composition.correct C₁ C₂)) in
◇ P (join xss) ↔ ◇ (◇ P) xss
join↔◇ {C₁ = C₁} {C₂} P join xss =
◇ P (⟪ join ⟫⊸ xss′) ↔⟨ remove-linear P join ⟩
◇ P xss′ ↔⟨ sym $ flatten P xss ⟩
◇ (◇ P) xss ∎
where xss′ = Inverse.from (Composition.correct C₁ C₂) ⟨$⟩ xss
|
If $M$ is a collection of subsets of $\Omega$ that is closed under finite unions, finite intersections, and complements, then $M$ is a ring of sets. |
(* Author: Stefan Berghofer, TU Muenchen, 2005; Lukas Bulwahn, TU Muenchen, 2009
*)
theory Execute
imports POPLmarkRecord "~~/src/HOL/Library/Code_Target_Numeral"
begin
section {* Executing the specification *}
text {*
\label{sec:exec}
An important criterion that a solution to the {\sc PoplMark} Challenge should
fulfill is the possibility to {\it animate} the specification. For example,
it should be possible to apply the reduction relation for the calculus to
example terms. Since the reduction relations are defined inductively, they can
be interpreted as a logic program in the style of {\sc Prolog}.
The definition of the single-step evaluation relation presented in \secref{sec:evaluation}
and \secref{sec:evaluation-rcd} is directly executable.
In order to compute the normal form of a term using the one-step evaluation
relation @{text "\<longmapsto>"}, we introduce the inductive predicate @{text "t \<Down> u"},
denoting that @{text u} is a normal form of @{text t}.
*}
inductive norm :: "trm \<Rightarrow> trm \<Rightarrow> bool" (infixl "\<Down>" 50)
where
"t \<in> value \<Longrightarrow> t \<Down> t"
| "t \<longmapsto> s \<Longrightarrow> s \<Down> u \<Longrightarrow> t \<Down> u"
definition normal_forms where
"normal_forms t \<equiv> {u. t \<Down> u}"
lemma [code_pred_intro Rcd_Nil]: "valuep (Rcd [])"
by (auto intro: valuep.intros)
lemma [code_pred_intro Rcd_Cons]: "valuep t \<Longrightarrow> valuep (Rcd fs) \<Longrightarrow> valuep (Rcd ((l, t) # fs))"
by (auto intro!: valuep.intros elim!: valuep.cases)
lemmas valuep.intros(1)[code_pred_intro Abs'] valuep.intros(2)[code_pred_intro TAbs']
code_pred (modes: i => bool) valuep
proof -
case valuep
from valuep.prems show thesis
proof (cases rule: valuep.cases)
case (Rcd fs)
from this Rcd_Nil Rcd_Cons show thesis
by (cases fs) (auto intro: valuep.intros)
next
case Abs
with Abs' show thesis .
next
case TAbs
with TAbs' show thesis .
qed
qed
thm valuep.equation
code_pred (modes: i => i => bool, i => o => bool as normalize) norm .
thm norm.equation
lemma [code_unfold]: "x \<in> value \<longleftrightarrow> valuep x"
by (simp add: value_def)
definition
natT :: type where
"natT \<equiv> \<forall><:Top. (\<forall><:TVar 0. (\<forall><:TVar 1. (TVar 2 \<rightarrow> TVar 1) \<rightarrow> TVar 0 \<rightarrow> TVar 1))"
definition
fact2 :: trm where
"fact2 \<equiv>
LET PVar natT =
(\<lambda><:Top. \<lambda><:TVar 0. \<lambda><:TVar 1. \<lambda>:TVar 2 \<rightarrow> TVar 1. \<lambda>: TVar 1. Var 1 \<bullet> Var 0)
IN
LET PRcd
[(''pluspp'', PVar (natT \<rightarrow> natT \<rightarrow> natT)),
(''multpp'', PVar (natT \<rightarrow> natT \<rightarrow> natT))] = Rcd
[(''multpp'', \<lambda>:natT. \<lambda>:natT. \<lambda><:Top. \<lambda><:TVar 0. \<lambda><:TVar 1. \<lambda>:TVar 2 \<rightarrow> TVar 1.
Var 5 \<bullet>\<^sub>\<tau> TVar 3 \<bullet>\<^sub>\<tau> TVar 2 \<bullet>\<^sub>\<tau> TVar 1 \<bullet> (Var 4 \<bullet>\<^sub>\<tau> TVar 3 \<bullet>\<^sub>\<tau> TVar 2 \<bullet>\<^sub>\<tau> TVar 1) \<bullet> Var 0),
(''pluspp'', \<lambda>:natT. \<lambda>:natT. \<lambda><:Top. \<lambda><:TVar 0. \<lambda><:TVar 1. \<lambda>:TVar 2 \<rightarrow> TVar 1. \<lambda>:TVar 1.
Var 6 \<bullet>\<^sub>\<tau> TVar 4 \<bullet>\<^sub>\<tau> TVar 3 \<bullet>\<^sub>\<tau> TVar 3 \<bullet> Var 1 \<bullet>
(Var 5 \<bullet>\<^sub>\<tau> TVar 4 \<bullet>\<^sub>\<tau> TVar 3 \<bullet>\<^sub>\<tau> TVar 2 \<bullet> Var 1 \<bullet> Var 0))]
IN
Var 0 \<bullet> (Var 1 \<bullet> Var 2 \<bullet> Var 2) \<bullet> Var 2"
value "normal_forms fact2"
text {*
Unfortunately, the definition based
on evaluation contexts from \secref{sec:evaluation-ctxt} is not directly executable.
The reason is that from the definition of evaluation contexts, the code generator
cannot immediately read off an algorithm that, given a term @{text t}, computes a context
@{text E} and a term @{text "t\<^sub>0"} such that @{text "t = E t\<^sub>0"}. In order to do this, one
would have to extract the algorithm contained in the proof of the {\it decomposition lemma}
from \secref{sec:evaluation-ctxt}.
*}
values "{u. norm fact2 u}"
end |
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Setoids.Setoids
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Sequences
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Functions.Definition
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
module Rings.Orders.Total.Cauchy {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {R : Ring S _+_ _*_} {pRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pRing) where
open import Rings.Orders.Total.Lemmas order
open import Rings.Orders.Total.AbsoluteValue order
cauchy : Sequence A → Set (m ⊔ o)
cauchy s = ∀ (ε : A) → (Ring.0R R < ε) → Sg ℕ (λ N → ∀ {m n : ℕ} → (N <N m) → (N <N n) → abs (Ring._-R_ R (index s m) (index s n)) < ε)
|
# Nonlinear Decision Boundaries
Load the data in `data.csv` as a data frame.
```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
dat = pd.read_csv("data.csv")
```
Plot the data with matplotlib as a 2D scatter plot, using different colors for the different classes.
```python
```
Which non-linear transformation $\phi$ will lead linearly separable data in the $\phi$-space? Compute this transformation, and plot the transformed data.
```python
```
# Kernel Density Estimators
In the lecture, you got to know kernel density estimatiors as a non-parametric method for representing a distribution. They represent the distribution of values $x$ as follows:
\begin{equation}
p(t) = \frac{1}{n \, h} \sum_{i=1}^n \varphi\left(\frac{t-x_i}{h}\right)
\end{equation}
Here, $\varphi$ is a windowing function, e.g. the Gauss window:
\begin{equation}
\varphi(u) = \frac{1}{\sqrt{2\pi}} e^{-u^2/2}
\end{equation}
## Exercise 1
Implement the function `kde(t,h,x)` that estimates the kernel density estimate $p(t)$, given a point $t$, a window size $h$ and an array of training samples $x$.
```python
```
## Exercise 2
Implement the function `classify_kde(xnew,x,classes)` that performs a classification with a kernel density estimator. Specifically, this is a Bayes classifier where the likelihood is represented by a kernel density estimator.
```python
```
|
[GOAL]
e : ℤˣ
⊢ ‖↑e‖₊ = 1
[PROOFSTEP]
obtain rfl | rfl := units_eq_one_or e
[GOAL]
case inl
⊢ ‖↑1‖₊ = 1
[PROOFSTEP]
simp only [Units.coe_neg_one, Units.val_one, nnnorm_neg, nnnorm_one]
[GOAL]
case inr
⊢ ‖↑(-1)‖₊ = 1
[PROOFSTEP]
simp only [Units.coe_neg_one, Units.val_one, nnnorm_neg, nnnorm_one]
[GOAL]
e : ℤˣ
⊢ ‖↑e‖ = 1
[PROOFSTEP]
rw [← coe_nnnorm, nnnorm_coe_units, NNReal.coe_one]
[GOAL]
n : ℤ
⊢ ↑(toNat n) + ↑(toNat (-n)) = ‖n‖₊
[PROOFSTEP]
rw [← Nat.cast_add, toNat_add_toNat_neg_eq_natAbs, NNReal.coe_natAbs]
[GOAL]
n : ℤ
⊢ ↑(toNat n) + ↑(toNat (-n)) = ‖n‖
[PROOFSTEP]
simpa only [NNReal.coe_nat_cast, NNReal.coe_add] using congrArg NNReal.toReal (toNat_add_toNat_neg_eq_nnnorm n)
|
{-# OPTIONS --sized-types #-}
open import Relation.Binary.Core
module BubbleSort.Correctness.Order {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import BubbleSort _≤_ tot≤
open import Data.Product
open import Data.List
open import Data.Sum
open import Function using (_∘_)
open import List.Sorted _≤_
open import Order.Total _≤_ tot≤
open import Size
open import SList
open import SList.Order _≤_
open import SList.Order.Properties _≤_
lemma-swap*-≤*-≤ : {ι : Size}{x t : A}{xs : SList A {ι}} → x ≤ t → xs ≤* t → proj₁ (swap* x xs) ≤* t × proj₂ (swap* x xs) ≤ t
lemma-swap*-≤*-≤ x≤t lenx = lenx , x≤t
lemma-swap*-≤*-≤ {x = x} x≤t (lecx {x = y} y≤t ys≤*t)
with tot≤ x y
... | inj₁ x≤y = lecx x≤t (proj₁ (lemma-swap*-≤*-≤ y≤t ys≤*t)), proj₂ (lemma-swap*-≤*-≤ y≤t ys≤*t)
... | inj₂ y≤x = lecx y≤t (proj₁ (lemma-swap*-≤*-≤ x≤t ys≤*t)), proj₂ (lemma-swap*-≤*-≤ x≤t ys≤*t)
lemma-bubbleSort-≤* : {ι : Size}{t : A}{xs : SList A {ι}} → xs ≤* t → bubbleSort xs ≤* t
lemma-bubbleSort-≤* lenx = lenx
lemma-bubbleSort-≤* (lecx x≤t xs≤*t)
with lemma-swap*-≤*-≤ x≤t xs≤*t
... | (zs≤*t , z≤t) = lemma-⊕≤* z≤t (lemma-bubbleSort-≤* zs≤*t)
lemma-swap*-≤ : {ι : Size}(x : A) → (xs : SList A {ι}) → x ≤ proj₂ (swap* x xs)
lemma-swap*-≤ x snil = refl≤
lemma-swap*-≤ x (y ∙ ys)
with tot≤ x y
... | inj₁ x≤y = trans≤ x≤y (lemma-swap*-≤ y ys)
... | inj₂ y≤x = lemma-swap*-≤ x ys
lemma-swap*-≤* : {ι : Size}(x : A) → (xs : SList A {ι}) → proj₁ (swap* x xs) ≤* proj₂ (swap* x xs)
lemma-swap*-≤* x snil = lenx
lemma-swap*-≤* x (y ∙ ys)
with tot≤ x y
... | inj₁ x≤y = lecx (trans≤ x≤y (lemma-swap*-≤ y ys)) (lemma-swap*-≤* y ys)
... | inj₂ y≤x = lecx (trans≤ y≤x (lemma-swap*-≤ x ys)) (lemma-swap*-≤* x ys)
lemma-bubbleSort-sorted : {ι : Size}(xs : SList A {ι}) → Sorted (unsize A (bubbleSort xs))
lemma-bubbleSort-sorted snil = nils
lemma-bubbleSort-sorted (x ∙ xs) = lemma-sorted⊕ (lemma-bubbleSort-≤* (lemma-swap*-≤* x xs)) (lemma-bubbleSort-sorted (proj₁ (swap* x xs)))
theorem-bubbleSort-sorted : (xs : List A) → Sorted (unsize A (bubbleSort (size A xs)))
theorem-bubbleSort-sorted = lemma-bubbleSort-sorted ∘ (size A)
|
If $h$ is bilinear and $f$ and $g$ are continuous, then $h(f(x), g(x))$ is continuous. |
Lemma mul_0_r : forall n : nat, n * 0 = 0.
induction n; simpl.
trivial.
apply IHn.
Optimize Proof.
Defined.
Print mul_0_r.
(*
fun n : nat =>
nat_ind (fun n0 : nat => n0 * 0 = 0) eq_refl (fun (n0 : nat) (IHn : n0 * 0 = 0) => IHn) n
*)
Lemma mul_1_l : forall n : nat, 1 * n = n.
simpl.
induction n; simpl.
trivial.
rewrite IHn.
trivial.
Optimize Proof.
Defined.
Print mul_1_l.
(*
nat_ind (fun n0 : nat => n0 + 0 = n0) eq_refl
(fun (n0 : nat) (IHn : n0 + 0 = n0) => eq_ind_r (fun n1 : nat => S n1 = S n0) eq_refl IHn) n
*)
Theorem m0r_m1l_subst_eq : (mul_0_r 1) = (mul_1_l 0).
simpl.
trivial.
Optimize Proof.
Defined.
Print m0r_m1l_subst_eq.
(*eq_refl*) |
theory Ex022
imports Main
begin
lemma "(A \<longrightarrow> B) \<longrightarrow> (A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> (A \<longrightarrow> C)"
proof -
{
assume "A \<longrightarrow> B"
{
assume "A \<longrightarrow> B \<longrightarrow> C"
{
assume A
with \<open>A \<longrightarrow> B\<close> have B by (rule mp)
from \<open>A \<longrightarrow> B \<longrightarrow> C\<close> and \<open>A\<close> have "B \<longrightarrow> C" by (rule mp)
from \<open>B \<longrightarrow> C\<close> and \<open>B\<close> have C by (rule mp)
}
hence "A \<longrightarrow> C" by (rule impI)
}
hence "(A \<longrightarrow> B \<longrightarrow> C) \<longrightarrow> A \<longrightarrow> C" by (rule impI)
}
thus ?thesis by (rule impI)
qed
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring -- for length
open import Lists.Definition
open import Lists.Fold.Fold
module Lists.Length where
length : {a : _} {A : Set a} (l : List A) → ℕ
length [] = zero
length (x :: l) = succ (length l)
length' : {a : _} {A : Set a} → (l : List A) → ℕ
length' = fold (λ _ → succ) 0
length=length' : {a : _} {A : Set a} (l : List A) → length l ≡ length' l
length=length' [] = refl
length=length' (x :: l) = applyEquality succ (length=length' l)
|
lemma emeasure_null_measure[simp]: "emeasure (null_measure M) X = 0" |
# ---
#
# Configuration for Achilles
# Change the parameters below to use your configuration.
# Run this script before running run-achilles.r
#
# ---
dbms <- "sql server"
user <- "synthea_micro"
password <- "Sneaker01"
server <- "localhost"
port <- "1433"
pathToDriver <- "D:\\NACHC\\SYNTHEA\\DQD\\resources\\jar\\sqlserver-jar" # location of the mssql-jdbc-10.2.0.jre8.jar
extraSettings <- ";databaseName=master;integratedSecurity=true;encrypt=false"
cdmVersion <- "5.4"
cdmDatabaseSchema <- "synthea_micro.dbo"
resultsDatabaseSchema <- "synthea_micro_achilles_results.dbo"
|
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Order
import Mathlib.Data.Int.Basic
import Mathlib.Data.Finset.Card
import Mathlib.Tactic.LibrarySearch
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Positivity
/-!
# USA Mathematical Olympiad 1998, Problem 5
Prove that for each n ≥ 2, there is a set S of n integers such that
(a-b)² divides ab for every distinct a,b ∈ S.
-/
namespace Usa1998Q5
open BigOperators
lemma usa1998_q5_stronger (n : ℕ) :
∃ S : Finset ℤ,
(∀ x ∈ S, 0 ≤ x) ∧
S.card = n ∧
∀ a ∈ S, ∀ b ∈ S, a ≠ b → (a - b)^2 ∣ a * b := by
-- (Adapation of informal proof from Andreescu & Feng.)
induction n with
| zero => use ∅; simp
| succ n ih =>
obtain ⟨Sp, sp_nonnegative, sp_card, hsp⟩ := ih
let L : ℤ := ∏ s in Sp, ∏ t in Sp.erase s, (s-t)^2
have all_terms_pos :
∀ s ∈ Sp, ∀ t ∈ Sp.erase s, 0 < (s-t)^2 := by
intros s _hs t ht
obtain ⟨t_ne_s, _⟩ := Finset.mem_erase.mp ht
have : s - t ≠ 0 := sub_ne_zero_of_ne t_ne_s.symm
positivity
have inner_prod_pos :
∀ s ∈ Sp, 0 < ∏ t in Sp.erase s, (s-t)^2 := by
intros s hs
exact Finset.prod_pos (all_terms_pos s hs)
have L_pos : 0 < L := Finset.prod_pos inner_prod_pos
-- Define Sₙ₊₁ = { L + a : a ∈ Sₙ } ∪ { 0 }.
let S : Finset ℤ := Sp.map (addLeftEmbedding L) ∪ {0}
use S
constructor
· -- all elements are nonnegative
intros x hx
rw[Finset.mem_union] at hx
cases hx with
| inl hx =>
rw[Finset.mem_map] at hx
obtain ⟨w, hw1, hw2⟩ := hx
have := sp_nonnegative w hw1
replace hw2 : L + w = x := hw2
linarith
| inr hx => simp_all
· constructor
· --cardinality is n + 1
have hdisj : Disjoint (Finset.map (addLeftEmbedding L) Sp) {0} := by
intros X hX h0 y hy
have hyy := h0 hy
rw[Finset.mem_singleton] at hyy
rw[hyy] at hy
have hxx := hX hy
rw[Finset.mem_map] at hxx
obtain ⟨z, hz, hz2⟩ := hxx
replace hz2 : L + z = 0 := hz2
have := sp_nonnegative z hz
clear hX h0 -- Finset ≤ relation confuses linarith
linarith
rw[Finset.card_disjoint_union hdisj, Finset.card_singleton,
Finset.card_map, sp_card]
· intros α hα β hβ α_ne_β
rw[Finset.mem_union, Finset.mem_map] at hα hβ
-- If α,β ∈ Sₙ₊₁ and either α or β is zero, then (α - β)² divides αβ.
cases hα with
| inr hα => simp_all
| inl hα =>
cases hβ with
| inr hβ => simp_all
| inl hβ =>
obtain ⟨a, ha, ha2⟩ := hα
replace ha2 : L + a = α := ha2
obtain ⟨b, hb, hb2⟩ := hβ
replace hb2 : L + b = β := hb2
have a_ne_b : a ≠ b := by aesop
have ih := hsp a ha b hb a_ne_b
have h5 : L = (∏ t in Sp.erase a, (a-t)^2) *
∏ s in Sp.erase a, ∏ t in Sp.erase s, (s-t)^2 :=
(Finset.mul_prod_erase Sp _ ha).symm
have hbb := Finset.mem_erase.mpr ⟨a_ne_b.symm, hb⟩
have h6 : (a-b)^2 * ∏ t in (Sp.erase a).erase b, (a-t)^2 =
∏ t in Sp.erase a, (a-t)^2 :=
Finset.mul_prod_erase (Sp.erase a) (fun x ↦ (a-x)^2) hbb
have Lmod : L % (a - b)^2 = 0 := by
rw[h5, ←h6, mul_assoc, Int.mul_emod, Int.emod_self]
norm_num
have Lmod' : (L + a) * (L + b) % (a-b)^2 = 0 := by
have h7 : (L + a) * (L + b) = L * (L + a + b) + a * b := by ring
rw[h7]
rw[Int.add_emod]
have h8 : L * (L + a + b) % (a - b) ^ 2 = 0 := by
rw[Int.mul_emod, Lmod]
norm_num
have h9 : a * b % (a - b) ^ 2 = 0 := Int.emod_eq_zero_of_dvd ih
rw[h8, h9]
norm_num
have hab : a-b = α - β := by linarith
rw[ha2, hb2, hab] at Lmod'
exact Int.dvd_of_emod_eq_zero Lmod'
theorem usa1998_q5 (n : ℕ) (_hn : 2 ≤ n) :
∃ S : Finset ℤ,
S.card = n ∧
∀ a ∈ S, ∀ b ∈ S, a ≠ b → (a - b)^2 ∣ a * b := by
obtain ⟨S, _, hS⟩ := usa1998_q5_stronger n
exact ⟨S, hS⟩
|
From BY.Hierarchy Require Import Definitions.
Local Open Scope mag_scope.
Section Magma.
Local Open Scope mag_scope.
Class Magma A `{Equiv A, Op1 A} :=
{
mag_setoid :> Setoid A;
mag_proper :> Proper ((≡) ==> (≡) ==> (≡)) (∘)
}.
Class MagmaMorph {A} {B} (f : A -> B) `{Magma A, Magma B} :=
{
mag_morph_setoid_morph :> SetoidMorph f;
mag_morph_op : forall x y, f (x ∘ y) = f x ∘ f y
}.
Class MagmaCongruence `{Magma A} (rel : relation A) :=
{
mag_cong_equiv :> Equivalence rel;
mag_cong_proper :> Proper (rel ==> rel ==> rel) (∘)
}.
End Magma.
Section Magma.
Context `{Magma A}
{rel : relation A}
`{!MagmaCongruence rel}.
Instance : @Magma _ rel _.
Proof. repeat split; try apply _. Qed.
End Magma.
|
State Before: ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ Prepartition.iUnion (filter π fun J => ¬p J) = Prepartition.iUnion π \ Prepartition.iUnion (filter π p) State After: ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ (⋃ (J : Box ι) (_ : J ∈ filter π fun J => ¬p J), ↑J) =
(⋃ (J : Box ι) (_ : J ∈ π), ↑J) \ ⋃ (J : Box ι) (_ : J ∈ filter π p), ↑J Tactic: simp only [Prepartition.iUnion] State Before: ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ (⋃ (J : Box ι) (_ : J ∈ filter π fun J => ¬p J), ↑J) =
(⋃ (J : Box ι) (_ : J ∈ π), ↑J) \ ⋃ (J : Box ι) (_ : J ∈ filter π p), ↑J State After: case h.e'_2.h.e'_3.h.pq.a.a
ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
x✝ : Box ι
⊢ (x✝ ∈ filter π fun J => ¬p J) ↔ x✝ ∈ ↑π.boxes \ ↑(filter π p).boxes
ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ PairwiseDisjoint (↑π.boxes ∪ ↑(filter π p).boxes) Box.toSet Tactic: convert (@Set.biUnion_diff_biUnion_eq _ (Box ι) π.boxes (π.filter p).boxes (↑) _).symm State Before: case h.e'_2.h.e'_3.h.pq.a.a
ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
x✝ : Box ι
⊢ (x✝ ∈ filter π fun J => ¬p J) ↔ x✝ ∈ ↑π.boxes \ ↑(filter π p).boxes State After: no goals Tactic: simp (config := { contextual := true }) State Before: ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ PairwiseDisjoint (↑π.boxes ∪ ↑(filter π p).boxes) Box.toSet State After: ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ Set.Pairwise (↑π.boxes ∪ ↑(filter π p).boxes) (Disjoint on Box.toSet) Tactic: rw [Set.PairwiseDisjoint] State Before: ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ Set.Pairwise (↑π.boxes ∪ ↑(filter π p).boxes) (Disjoint on Box.toSet) State After: case h.e'_2
ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ ↑π.boxes ∪ ↑(filter π p).boxes = ↑π.boxes Tactic: convert π.pairwiseDisjoint State Before: case h.e'_2
ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ ↑π.boxes ∪ ↑(filter π p).boxes = ↑π.boxes State After: case h.e'_2
ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ {x | x ∈ π.boxes ∧ p x} ⊆ ↑π.boxes Tactic: rw [Set.union_eq_left_iff_subset, filter_boxes, coe_filter] State Before: case h.e'_2
ι : Type u_1
I J J₁ J₂ : Box ι
π✝ π₁ π₂ : Prepartition I
x : ι → ℝ
πi πi₁ πi₂ : (J : Box ι) → Prepartition J
π : Prepartition I
p : Box ι → Prop
⊢ {x | x ∈ π.boxes ∧ p x} ⊆ ↑π.boxes State After: no goals Tactic: exact fun _ ⟨h, _⟩ => h |
(* Title: HOL/Equiv_Relations.thy
Author: Lawrence C Paulson, 1996 Cambridge University Computer Laboratory
*)
section \<open>Equivalence Relations in Higher-Order Set Theory\<close>
theory Equiv_Relations
imports Groups_Big
begin
subsection \<open>Equivalence relations -- set version\<close>
definition equiv :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool"
where "equiv A r \<longleftrightarrow> refl_on A r \<and> sym r \<and> trans r"
lemma equivI: "refl_on A r \<Longrightarrow> sym r \<Longrightarrow> trans r \<Longrightarrow> equiv A r"
by (simp add: equiv_def)
lemma equivE:
assumes "equiv A r"
obtains "refl_on A r" and "sym r" and "trans r"
using assms by (simp add: equiv_def)
text \<open>
Suppes, Theorem 70: \<open>r\<close> is an equiv relation iff \<open>r\<inverse> O r = r\<close>.
First half: \<open>equiv A r \<Longrightarrow> r\<inverse> O r = r\<close>.
\<close>
lemma sym_trans_comp_subset: "sym r \<Longrightarrow> trans r \<Longrightarrow> r\<inverse> O r \<subseteq> r"
unfolding trans_def sym_def converse_unfold by blast
lemma refl_on_comp_subset: "refl_on A r \<Longrightarrow> r \<subseteq> r\<inverse> O r"
unfolding refl_on_def by blast
lemma equiv_comp_eq: "equiv A r \<Longrightarrow> r\<inverse> O r = r"
unfolding equiv_def
by (iprover intro: sym_trans_comp_subset refl_on_comp_subset equalityI)
text \<open>Second half.\<close>
lemma comp_equivI:
assumes "r\<inverse> O r = r" "Domain r = A"
shows "equiv A r"
proof -
have *: "\<And>x y. (x, y) \<in> r \<Longrightarrow> (y, x) \<in> r"
using assms by blast
show ?thesis
unfolding equiv_def refl_on_def sym_def trans_def
using assms by (auto intro: *)
qed
subsection \<open>Equivalence classes\<close>
lemma equiv_class_subset: "equiv A r \<Longrightarrow> (a, b) \<in> r \<Longrightarrow> r``{a} \<subseteq> r``{b}"
\<comment> \<open>lemma for the next result\<close>
unfolding equiv_def trans_def sym_def by blast
theorem equiv_class_eq: "equiv A r \<Longrightarrow> (a, b) \<in> r \<Longrightarrow> r``{a} = r``{b}"
by (intro equalityI equiv_class_subset; force simp add: equiv_def sym_def)
lemma equiv_class_self: "equiv A r \<Longrightarrow> a \<in> A \<Longrightarrow> a \<in> r``{a}"
unfolding equiv_def refl_on_def by blast
lemma subset_equiv_class: "equiv A r \<Longrightarrow> r``{b} \<subseteq> r``{a} \<Longrightarrow> b \<in> A \<Longrightarrow> (a, b) \<in> r"
\<comment> \<open>lemma for the next result\<close>
unfolding equiv_def refl_on_def by blast
lemma eq_equiv_class: "r``{a} = r``{b} \<Longrightarrow> equiv A r \<Longrightarrow> b \<in> A \<Longrightarrow> (a, b) \<in> r"
by (iprover intro: equalityD2 subset_equiv_class)
lemma equiv_class_nondisjoint: "equiv A r \<Longrightarrow> x \<in> (r``{a} \<inter> r``{b}) \<Longrightarrow> (a, b) \<in> r"
unfolding equiv_def trans_def sym_def by blast
lemma equiv_type: "equiv A r \<Longrightarrow> r \<subseteq> A \<times> A"
unfolding equiv_def refl_on_def by blast
lemma equiv_class_eq_iff: "equiv A r \<Longrightarrow> (x, y) \<in> r \<longleftrightarrow> r``{x} = r``{y} \<and> x \<in> A \<and> y \<in> A"
by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type)
lemma eq_equiv_class_iff: "equiv A r \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> r``{x} = r``{y} \<longleftrightarrow> (x, y) \<in> r"
by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type)
subsection \<open>Quotients\<close>
definition quotient :: "'a set \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> 'a set set" (infixl "'/'/" 90)
where "A//r = (\<Union>x \<in> A. {r``{x}})" \<comment> \<open>set of equiv classes\<close>
lemma quotientI: "x \<in> A \<Longrightarrow> r``{x} \<in> A//r"
unfolding quotient_def by blast
lemma quotientE: "X \<in> A//r \<Longrightarrow> (\<And>x. X = r``{x} \<Longrightarrow> x \<in> A \<Longrightarrow> P) \<Longrightarrow> P"
unfolding quotient_def by blast
lemma Union_quotient: "equiv A r \<Longrightarrow> \<Union>(A//r) = A"
unfolding equiv_def refl_on_def quotient_def by blast
lemma quotient_disj: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> Y \<in> A//r \<Longrightarrow> X = Y \<or> X \<inter> Y = {}"
unfolding quotient_def equiv_def trans_def sym_def by blast
lemma quotient_eqI:
assumes "equiv A r" "X \<in> A//r" "Y \<in> A//r" and xy: "x \<in> X" "y \<in> Y" "(x, y) \<in> r"
shows "X = Y"
proof -
obtain a b where "a \<in> A" and a: "X = r `` {a}" and "b \<in> A" and b: "Y = r `` {b}"
using assms by (auto elim!: quotientE)
then have "(a,b) \<in> r"
using xy \<open>equiv A r\<close> unfolding equiv_def sym_def trans_def by blast
then show ?thesis
unfolding a b by (rule equiv_class_eq [OF \<open>equiv A r\<close>])
qed
lemma quotient_eq_iff:
assumes "equiv A r" "X \<in> A//r" "Y \<in> A//r" and xy: "x \<in> X" "y \<in> Y"
shows "X = Y \<longleftrightarrow> (x, y) \<in> r"
proof
assume L: "X = Y"
with assms show "(x, y) \<in> r"
unfolding equiv_def sym_def trans_def by (blast elim!: quotientE)
next
assume \<section>: "(x, y) \<in> r" show "X = Y"
by (rule quotient_eqI) (use \<section> assms in \<open>blast+\<close>)
qed
lemma eq_equiv_class_iff2: "equiv A r \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> {x}//r = {y}//r \<longleftrightarrow> (x, y) \<in> r"
by (simp add: quotient_def eq_equiv_class_iff)
lemma quotient_empty [simp]: "{}//r = {}"
by (simp add: quotient_def)
lemma quotient_is_empty [iff]: "A//r = {} \<longleftrightarrow> A = {}"
by (simp add: quotient_def)
lemma quotient_is_empty2 [iff]: "{} = A//r \<longleftrightarrow> A = {}"
by (simp add: quotient_def)
lemma singleton_quotient: "{x}//r = {r `` {x}}"
by (simp add: quotient_def)
lemma quotient_diff1: "inj_on (\<lambda>a. {a}//r) A \<Longrightarrow> a \<in> A \<Longrightarrow> (A - {a})//r = A//r - {a}//r"
unfolding quotient_def inj_on_def by blast
subsection \<open>Refinement of one equivalence relation WRT another\<close>
lemma refines_equiv_class_eq: "R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> R``(S``{a}) = S``{a}"
by (auto simp: equiv_class_eq_iff)
lemma refines_equiv_class_eq2: "R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> S``(R``{a}) = S``{a}"
by (auto simp: equiv_class_eq_iff)
lemma refines_equiv_image_eq: "R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> (\<lambda>X. S``X) ` (A//R) = A//S"
by (auto simp: quotient_def image_UN refines_equiv_class_eq2)
lemma finite_refines_finite:
"finite (A//R) \<Longrightarrow> R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> finite (A//S)"
by (erule finite_surj [where f = "\<lambda>X. S``X"]) (simp add: refines_equiv_image_eq)
lemma finite_refines_card_le:
"finite (A//R) \<Longrightarrow> R \<subseteq> S \<Longrightarrow> equiv A R \<Longrightarrow> equiv A S \<Longrightarrow> card (A//S) \<le> card (A//R)"
by (subst refines_equiv_image_eq [of R S A, symmetric])
(auto simp: card_image_le [where f = "\<lambda>X. S``X"])
subsection \<open>Defining unary operations upon equivalence classes\<close>
text \<open>A congruence-preserving function.\<close>
definition congruent :: "('a \<times> 'a) set \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
where "congruent r f \<longleftrightarrow> (\<forall>(y, z) \<in> r. f y = f z)"
lemma congruentI: "(\<And>y z. (y, z) \<in> r \<Longrightarrow> f y = f z) \<Longrightarrow> congruent r f"
by (auto simp add: congruent_def)
lemma congruentD: "congruent r f \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> f y = f z"
by (auto simp add: congruent_def)
abbreviation RESPECTS :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool" (infixr "respects" 80)
where "f respects r \<equiv> congruent r f"
lemma UN_constant_eq: "a \<in> A \<Longrightarrow> \<forall>y \<in> A. f y = c \<Longrightarrow> (\<Union>y \<in> A. f y) = c"
\<comment> \<open>lemma required to prove \<open>UN_equiv_class\<close>\<close>
by auto
lemma UN_equiv_class:
assumes "equiv A r" "f respects r" "a \<in> A"
shows "(\<Union>x \<in> r``{a}. f x) = f a"
\<comment> \<open>Conversion rule\<close>
proof -
have \<section>: "\<forall>x\<in>r `` {a}. f x = f a"
using assms unfolding equiv_def congruent_def sym_def by blast
show ?thesis
by (iprover intro: assms UN_constant_eq [OF equiv_class_self \<section>])
qed
lemma UN_equiv_class_type:
assumes r: "equiv A r" "f respects r" and X: "X \<in> A//r" and AB: "\<And>x. x \<in> A \<Longrightarrow> f x \<in> B"
shows "(\<Union>x \<in> X. f x) \<in> B"
using assms unfolding quotient_def
by (auto simp: UN_equiv_class [OF r])
text \<open>
Sufficient conditions for injectiveness. Could weaken premises!
major premise could be an inclusion; \<open>bcong\<close> could be
\<open>\<And>y. y \<in> A \<Longrightarrow> f y \<in> B\<close>.
\<close>
lemma UN_equiv_class_inject:
assumes "equiv A r" "f respects r"
and eq: "(\<Union>x \<in> X. f x) = (\<Union>y \<in> Y. f y)"
and X: "X \<in> A//r" and Y: "Y \<in> A//r"
and fr: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> f x = f y \<Longrightarrow> (x, y) \<in> r"
shows "X = Y"
proof -
obtain a b where "a \<in> A" and a: "X = r `` {a}" and "b \<in> A" and b: "Y = r `` {b}"
using assms by (auto elim!: quotientE)
then have "\<Union> (f ` r `` {a}) = f a" "\<Union> (f ` r `` {b}) = f b"
by (iprover intro: UN_equiv_class [OF \<open>equiv A r\<close>] assms)+
then have "f a = f b"
using eq unfolding a b by (iprover intro: trans sym)
then have "(a,b) \<in> r"
using fr \<open>a \<in> A\<close> \<open>b \<in> A\<close> by blast
then show ?thesis
unfolding a b by (rule equiv_class_eq [OF \<open>equiv A r\<close>])
qed
subsection \<open>Defining binary operations upon equivalence classes\<close>
text \<open>A congruence-preserving function of two arguments.\<close>
definition congruent2 :: "('a \<times> 'a) set \<Rightarrow> ('b \<times> 'b) set \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> bool"
where "congruent2 r1 r2 f \<longleftrightarrow> (\<forall>(y1, z1) \<in> r1. \<forall>(y2, z2) \<in> r2. f y1 y2 = f z1 z2)"
lemma congruent2I':
assumes "\<And>y1 z1 y2 z2. (y1, z1) \<in> r1 \<Longrightarrow> (y2, z2) \<in> r2 \<Longrightarrow> f y1 y2 = f z1 z2"
shows "congruent2 r1 r2 f"
using assms by (auto simp add: congruent2_def)
lemma congruent2D: "congruent2 r1 r2 f \<Longrightarrow> (y1, z1) \<in> r1 \<Longrightarrow> (y2, z2) \<in> r2 \<Longrightarrow> f y1 y2 = f z1 z2"
by (auto simp add: congruent2_def)
text \<open>Abbreviation for the common case where the relations are identical.\<close>
abbreviation RESPECTS2:: "('a \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> bool" (infixr "respects2" 80)
where "f respects2 r \<equiv> congruent2 r r f"
lemma congruent2_implies_congruent:
"equiv A r1 \<Longrightarrow> congruent2 r1 r2 f \<Longrightarrow> a \<in> A \<Longrightarrow> congruent r2 (f a)"
unfolding congruent_def congruent2_def equiv_def refl_on_def by blast
lemma congruent2_implies_congruent_UN:
assumes "equiv A1 r1" "equiv A2 r2" "congruent2 r1 r2 f" "a \<in> A2"
shows "congruent r1 (\<lambda>x1. \<Union>x2 \<in> r2``{a}. f x1 x2)"
unfolding congruent_def
proof clarify
fix c d
assume cd: "(c,d) \<in> r1"
then have "c \<in> A1" "d \<in> A1"
using \<open>equiv A1 r1\<close> by (auto elim!: equiv_type [THEN subsetD, THEN SigmaE2])
with assms show "\<Union> (f c ` r2 `` {a}) = \<Union> (f d ` r2 `` {a})"
proof (simp add: UN_equiv_class congruent2_implies_congruent)
show "f c a = f d a"
using assms cd unfolding congruent2_def equiv_def refl_on_def by blast
qed
qed
lemma UN_equiv_class2:
"equiv A1 r1 \<Longrightarrow> equiv A2 r2 \<Longrightarrow> congruent2 r1 r2 f \<Longrightarrow> a1 \<in> A1 \<Longrightarrow> a2 \<in> A2 \<Longrightarrow>
(\<Union>x1 \<in> r1``{a1}. \<Union>x2 \<in> r2``{a2}. f x1 x2) = f a1 a2"
by (simp add: UN_equiv_class congruent2_implies_congruent congruent2_implies_congruent_UN)
lemma UN_equiv_class_type2:
"equiv A1 r1 \<Longrightarrow> equiv A2 r2 \<Longrightarrow> congruent2 r1 r2 f
\<Longrightarrow> X1 \<in> A1//r1 \<Longrightarrow> X2 \<in> A2//r2
\<Longrightarrow> (\<And>x1 x2. x1 \<in> A1 \<Longrightarrow> x2 \<in> A2 \<Longrightarrow> f x1 x2 \<in> B)
\<Longrightarrow> (\<Union>x1 \<in> X1. \<Union>x2 \<in> X2. f x1 x2) \<in> B"
unfolding quotient_def
by (blast intro: UN_equiv_class_type congruent2_implies_congruent_UN
congruent2_implies_congruent quotientI)
lemma UN_UN_split_split_eq:
"(\<Union>(x1, x2) \<in> X. \<Union>(y1, y2) \<in> Y. A x1 x2 y1 y2) =
(\<Union>x \<in> X. \<Union>y \<in> Y. (\<lambda>(x1, x2). (\<lambda>(y1, y2). A x1 x2 y1 y2) y) x)"
\<comment> \<open>Allows a natural expression of binary operators,\<close>
\<comment> \<open>without explicit calls to \<open>split\<close>\<close>
by auto
lemma congruent2I:
"equiv A1 r1 \<Longrightarrow> equiv A2 r2
\<Longrightarrow> (\<And>y z w. w \<in> A2 \<Longrightarrow> (y,z) \<in> r1 \<Longrightarrow> f y w = f z w)
\<Longrightarrow> (\<And>y z w. w \<in> A1 \<Longrightarrow> (y,z) \<in> r2 \<Longrightarrow> f w y = f w z)
\<Longrightarrow> congruent2 r1 r2 f"
\<comment> \<open>Suggested by John Harrison -- the two subproofs may be\<close>
\<comment> \<open>\<^emph>\<open>much\<close> simpler than the direct proof.\<close>
unfolding congruent2_def equiv_def refl_on_def
by (blast intro: trans)
lemma congruent2_commuteI:
assumes equivA: "equiv A r"
and commute: "\<And>y z. y \<in> A \<Longrightarrow> z \<in> A \<Longrightarrow> f y z = f z y"
and congt: "\<And>y z w. w \<in> A \<Longrightarrow> (y,z) \<in> r \<Longrightarrow> f w y = f w z"
shows "f respects2 r"
proof (rule congruent2I [OF equivA equivA])
note eqv = equivA [THEN equiv_type, THEN subsetD, THEN SigmaE2]
show "\<And>y z w. \<lbrakk>w \<in> A; (y, z) \<in> r\<rbrakk> \<Longrightarrow> f y w = f z w"
by (iprover intro: commute [THEN trans] sym congt elim: eqv)
show "\<And>y z w. \<lbrakk>w \<in> A; (y, z) \<in> r\<rbrakk> \<Longrightarrow> f w y = f w z"
by (iprover intro: congt elim: eqv)
qed
subsection \<open>Quotients and finiteness\<close>
text \<open>Suggested by Florian Kammüller\<close>
lemma finite_quotient:
assumes "finite A" "r \<subseteq> A \<times> A"
shows "finite (A//r)"
\<comment> \<open>recall @{thm equiv_type}\<close>
proof -
have "A//r \<subseteq> Pow A"
using assms unfolding quotient_def by blast
moreover have "finite (Pow A)"
using assms by simp
ultimately show ?thesis
by (iprover intro: finite_subset)
qed
lemma finite_equiv_class: "finite A \<Longrightarrow> r \<subseteq> A \<times> A \<Longrightarrow> X \<in> A//r \<Longrightarrow> finite X"
unfolding quotient_def
by (erule rev_finite_subset) blast
lemma equiv_imp_dvd_card:
assumes "finite A" "equiv A r" "\<And>X. X \<in> A//r \<Longrightarrow> k dvd card X"
shows "k dvd card A"
proof (rule Union_quotient [THEN subst])
show "k dvd card (\<Union> (A // r))"
apply (rule dvd_partition)
using assms
by (auto simp: Union_quotient dest: quotient_disj)
qed (use assms in blast)
lemma card_quotient_disjoint:
assumes "finite A" "inj_on (\<lambda>x. {x} // r) A"
shows "card (A//r) = card A"
proof -
have "\<forall>i\<in>A. \<forall>j\<in>A. i \<noteq> j \<longrightarrow> r `` {j} \<noteq> r `` {i}"
using assms by (fastforce simp add: quotient_def inj_on_def)
with assms show ?thesis
by (simp add: quotient_def card_UN_disjoint)
qed
subsection \<open>Projection\<close>
definition proj :: "('b \<times> 'a) set \<Rightarrow> 'b \<Rightarrow> 'a set"
where "proj r x = r `` {x}"
lemma proj_preserves: "x \<in> A \<Longrightarrow> proj r x \<in> A//r"
unfolding proj_def by (rule quotientI)
lemma proj_in_iff:
assumes "equiv A r"
shows "proj r x \<in> A//r \<longleftrightarrow> x \<in> A"
(is "?lhs \<longleftrightarrow> ?rhs")
proof
assume ?rhs
then show ?lhs by (simp add: proj_preserves)
next
assume ?lhs
then show ?rhs
unfolding proj_def quotient_def
proof clarsimp
fix y
assume y: "y \<in> A" and "r `` {x} = r `` {y}"
moreover have "y \<in> r `` {y}"
using assms y unfolding equiv_def refl_on_def by blast
ultimately have "(x, y) \<in> r" by blast
then show "x \<in> A"
using assms unfolding equiv_def refl_on_def by blast
qed
qed
lemma proj_iff: "equiv A r \<Longrightarrow> {x, y} \<subseteq> A \<Longrightarrow> proj r x = proj r y \<longleftrightarrow> (x, y) \<in> r"
by (simp add: proj_def eq_equiv_class_iff)
(*
lemma in_proj: "\<lbrakk>equiv A r; x \<in> A\<rbrakk> \<Longrightarrow> x \<in> proj r x"
unfolding proj_def equiv_def refl_on_def by blast
*)
lemma proj_image: "proj r ` A = A//r"
unfolding proj_def[abs_def] quotient_def by blast
lemma in_quotient_imp_non_empty: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> X \<noteq> {}"
unfolding quotient_def using equiv_class_self by fast
lemma in_quotient_imp_in_rel: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> {x, y} \<subseteq> X \<Longrightarrow> (x, y) \<in> r"
using quotient_eq_iff[THEN iffD1] by fastforce
lemma in_quotient_imp_closed: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> x \<in> X \<Longrightarrow> (x, y) \<in> r \<Longrightarrow> y \<in> X"
unfolding quotient_def equiv_def trans_def by blast
lemma in_quotient_imp_subset: "equiv A r \<Longrightarrow> X \<in> A//r \<Longrightarrow> X \<subseteq> A"
using in_quotient_imp_in_rel equiv_type by fastforce
subsection \<open>Equivalence relations -- predicate version\<close>
text \<open>Partial equivalences.\<close>
definition part_equivp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
where "part_equivp R \<longleftrightarrow> (\<exists>x. R x x) \<and> (\<forall>x y. R x y \<longleftrightarrow> R x x \<and> R y y \<and> R x = R y)"
\<comment> \<open>John-Harrison-style characterization\<close>
lemma part_equivpI: "\<exists>x. R x x \<Longrightarrow> symp R \<Longrightarrow> transp R \<Longrightarrow> part_equivp R"
by (auto simp add: part_equivp_def) (auto elim: sympE transpE)
lemma part_equivpE:
assumes "part_equivp R"
obtains x where "R x x" and "symp R" and "transp R"
proof -
from assms have 1: "\<exists>x. R x x"
and 2: "\<And>x y. R x y \<longleftrightarrow> R x x \<and> R y y \<and> R x = R y"
unfolding part_equivp_def by blast+
from 1 obtain x where "R x x" ..
moreover have "symp R"
proof (rule sympI)
fix x y
assume "R x y"
with 2 [of x y] show "R y x" by auto
qed
moreover have "transp R"
proof (rule transpI)
fix x y z
assume "R x y" and "R y z"
with 2 [of x y] 2 [of y z] show "R x z" by auto
qed
ultimately show thesis by (rule that)
qed
lemma part_equivp_refl_symp_transp: "part_equivp R \<longleftrightarrow> (\<exists>x. R x x) \<and> symp R \<and> transp R"
by (auto intro: part_equivpI elim: part_equivpE)
lemma part_equivp_symp: "part_equivp R \<Longrightarrow> R x y \<Longrightarrow> R y x"
by (erule part_equivpE, erule sympE)
lemma part_equivp_transp: "part_equivp R \<Longrightarrow> R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
by (erule part_equivpE, erule transpE)
lemma part_equivp_typedef: "part_equivp R \<Longrightarrow> \<exists>d. d \<in> {c. \<exists>x. R x x \<and> c = Collect (R x)}"
by (auto elim: part_equivpE)
text \<open>Total equivalences.\<close>
definition equivp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
where "equivp R \<longleftrightarrow> (\<forall>x y. R x y = (R x = R y))" \<comment> \<open>John-Harrison-style characterization\<close>
lemma equivpI: "reflp R \<Longrightarrow> symp R \<Longrightarrow> transp R \<Longrightarrow> equivp R"
by (auto elim: reflpE sympE transpE simp add: equivp_def)
lemma equivpE:
assumes "equivp R"
obtains "reflp R" and "symp R" and "transp R"
using assms by (auto intro!: that reflpI sympI transpI simp add: equivp_def)
lemma equivp_implies_part_equivp: "equivp R \<Longrightarrow> part_equivp R"
by (auto intro: part_equivpI elim: equivpE reflpE)
lemma equivp_equiv: "equiv UNIV A \<longleftrightarrow> equivp (\<lambda>x y. (x, y) \<in> A)"
by (auto intro!: equivI equivpI [to_set] elim!: equivE equivpE [to_set])
lemma equivp_reflp_symp_transp: "equivp R \<longleftrightarrow> reflp R \<and> symp R \<and> transp R"
by (auto intro: equivpI elim: equivpE)
lemma identity_equivp: "equivp (=)"
by (auto intro: equivpI reflpI sympI transpI)
lemma equivp_reflp: "equivp R \<Longrightarrow> R x x"
by (erule equivpE, erule reflpE)
lemma equivp_symp: "equivp R \<Longrightarrow> R x y \<Longrightarrow> R y x"
by (erule equivpE, erule sympE)
lemma equivp_transp: "equivp R \<Longrightarrow> R x y \<Longrightarrow> R y z \<Longrightarrow> R x z"
by (erule equivpE, erule transpE)
lemma equivp_rtranclp: "symp r \<Longrightarrow> equivp r\<^sup>*\<^sup>*"
by(intro equivpI reflpI sympI transpI)(auto dest: sympD[OF symp_rtranclp])
lemmas equivp_rtranclp_symclp [simp] = equivp_rtranclp[OF symp_symclp]
lemma equivp_vimage2p: "equivp R \<Longrightarrow> equivp (vimage2p f f R)"
by(auto simp add: equivp_def vimage2p_def dest: fun_cong)
lemma equivp_imp_transp: "equivp R \<Longrightarrow> transp R"
by(simp add: equivp_reflp_symp_transp)
subsection \<open>Equivalence closure\<close>
definition equivclp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" where
"equivclp r = (symclp r)\<^sup>*\<^sup>*"
lemma transp_equivclp [simp]: "transp (equivclp r)"
by(simp add: equivclp_def)
lemma reflp_equivclp [simp]: "reflp (equivclp r)"
by(simp add: equivclp_def)
lemma symp_equivclp [simp]: "symp (equivclp r)"
by(simp add: equivclp_def)
lemma equivp_evquivclp [simp]: "equivp (equivclp r)"
by(simp add: equivpI)
lemma tranclp_equivclp [simp]: "(equivclp r)\<^sup>+\<^sup>+ = equivclp r"
by(simp add: equivclp_def)
lemma rtranclp_equivclp [simp]: "(equivclp r)\<^sup>*\<^sup>* = equivclp r"
by(simp add: equivclp_def)
lemma symclp_equivclp [simp]: "symclp (equivclp r) = equivclp r"
by(simp add: equivclp_def symp_symclp_eq)
lemma equivclp_symclp [simp]: "equivclp (symclp r) = equivclp r"
by(simp add: equivclp_def)
lemma equivclp_conversep [simp]: "equivclp (conversep r) = equivclp r"
by(simp add: equivclp_def)
lemma equivclp_sym [sym]: "equivclp r x y \<Longrightarrow> equivclp r y x"
by(rule sympD[OF symp_equivclp])
lemma equivclp_OO_equivclp_le_equivclp: "equivclp r OO equivclp r \<le> equivclp r"
by(rule transp_relcompp_less_eq transp_equivclp)+
lemma rtranlcp_le_equivclp: "r\<^sup>*\<^sup>* \<le> equivclp r"
unfolding equivclp_def by(rule rtranclp_mono)(simp add: symclp_pointfree)
lemma rtranclp_conversep_le_equivclp: "r\<inverse>\<inverse>\<^sup>*\<^sup>* \<le> equivclp r"
unfolding equivclp_def by(rule rtranclp_mono)(simp add: symclp_pointfree)
lemma symclp_rtranclp_le_equivclp: "symclp r\<^sup>*\<^sup>* \<le> equivclp r"
unfolding symclp_pointfree
by(rule le_supI)(simp_all add: rtranclp_conversep[symmetric] rtranlcp_le_equivclp rtranclp_conversep_le_equivclp)
lemma r_OO_conversep_into_equivclp:
"r\<^sup>*\<^sup>* OO r\<inverse>\<inverse>\<^sup>*\<^sup>* \<le> equivclp r"
by(blast intro: order_trans[OF _ equivclp_OO_equivclp_le_equivclp] relcompp_mono rtranlcp_le_equivclp rtranclp_conversep_le_equivclp del: predicate2I)
lemma equivclp_induct [consumes 1, case_names base step, induct pred: equivclp]:
assumes a: "equivclp r a b"
and cases: "P a" "\<And>y z. equivclp r a y \<Longrightarrow> r y z \<or> r z y \<Longrightarrow> P y \<Longrightarrow> P z"
shows "P b"
using a unfolding equivclp_def
by(induction rule: rtranclp_induct; fold equivclp_def; blast intro: cases elim: symclpE)
lemma converse_equivclp_induct [consumes 1, case_names base step]:
assumes major: "equivclp r a b"
and cases: "P b" "\<And>y z. r y z \<or> r z y \<Longrightarrow> equivclp r z b \<Longrightarrow> P z \<Longrightarrow> P y"
shows "P a"
using major unfolding equivclp_def
by(induction rule: converse_rtranclp_induct; fold equivclp_def; blast intro: cases elim: symclpE)
lemma equivclp_refl [simp]: "equivclp r x x"
by(rule reflpD[OF reflp_equivclp])
lemma r_into_equivclp [intro]: "r x y \<Longrightarrow> equivclp r x y"
unfolding equivclp_def by(blast intro: symclpI)
lemma converse_r_into_equivclp [intro]: "r y x \<Longrightarrow> equivclp r x y"
unfolding equivclp_def by(blast intro: symclpI)
lemma rtranclp_into_equivclp: "r\<^sup>*\<^sup>* x y \<Longrightarrow> equivclp r x y"
using rtranlcp_le_equivclp[of r] by blast
lemma converse_rtranclp_into_equivclp: "r\<^sup>*\<^sup>* y x \<Longrightarrow> equivclp r x y"
by(blast intro: equivclp_sym rtranclp_into_equivclp)
lemma equivclp_into_equivclp: "\<lbrakk> equivclp r a b; r b c \<or> r c b \<rbrakk> \<Longrightarrow> equivclp r a c"
unfolding equivclp_def by(erule rtranclp.rtrancl_into_rtrancl)(auto intro: symclpI)
lemma equivclp_trans [trans]: "\<lbrakk> equivclp r a b; equivclp r b c \<rbrakk> \<Longrightarrow> equivclp r a c"
using equivclp_OO_equivclp_le_equivclp[of r] by blast
hide_const (open) proj
end
|
import data.set.basic
import util.logic
namespace set
open function
universe variables u₀ u₁
lemma ne_empty_of_exists_mem {α} {s : set α}
(h : ∃ x : α, x ∈ s)
: s ≠ ∅ :=
exists.elim h (@ne_empty_of_mem _ s)
variables {α : Type u₀} {β : Type u₀}
variables {s : set α}
variables {f : α → β}
variables {g : β → α}
variables (Hinj : injective f)
lemma mem_fmap_of_mem
{x : α}
(h : x ∈ s)
: f x ∈ f '' s :=
begin
unfold functor.map image,
rw mem_set_of,
exact ⟨x,h,rfl⟩
end
include Hinj
lemma mem_of_mem_fmap
{x : α}
(h : f x ∈ f '' s)
: x ∈ s :=
begin
unfold functor.map image at h,
rw mem_set_of at h,
cases h with y h₀, cases h₀ with h₀ h₁,
rw ← Hinj h₁,
apply h₀
end
lemma mem_fmap_iff_mem_of_inj
{x : α}
: f x ∈ f '' s ↔ x ∈ s :=
⟨ mem_of_mem_fmap Hinj, mem_fmap_of_mem ⟩
lemma mem_fmap_iff_mem_of_bij
(Hinv : left_inverse f g)
{x : β}
: x ∈ f '' s ↔ g x ∈ s :=
begin
have H : bijective f,
{ unfold bijective, split,
{ apply Hinj },
{ apply surjective_of_has_right_inverse,
exact ⟨g,Hinv⟩ } },
rw [← Hinv x,mem_fmap_iff_mem_of_inj Hinj,Hinv x]
end
omit Hinj
set_option pp.all true
lemma fmap_eq_empty_iff_eq_empty
: f '' s = ∅ ↔ s = ∅ :=
begin
split
; intro h,
{ rw eq_empty_iff_forall_not_mem,
have h₁ := congr_fun h,
intros x h₂,
have h₃ := h₁ (f x),
change (∅ : set β) (f x),
rw ← iff_eq_eq at h₃,
apply h₃.1, apply mem_fmap_of_mem h₂, },
{ rw h,
rw eq_empty_iff_forall_not_mem,
intros x h',
unfold functor.map image at h',
rw mem_set_of at h',
cases h' with i h', cases h' with h₀ h₁,
apply not_mem_empty _ h₀ },
end
end set
|
lemma ball_trivial [simp]: "ball x 0 = {}" |
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_succ_n : Stream'.Seq.TerminatedAt s (n + 1)
⊢ squashSeq s n = s
[PROOFSTEP]
change s.get? (n + 1) = none at terminated_at_succ_n
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_succ_n : Stream'.Seq.get? s (n + 1) = none
⊢ squashSeq s n = s
[PROOFSTEP]
cases s_nth_eq : s.get? n
[GOAL]
case none
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_succ_n : Stream'.Seq.get? s (n + 1) = none
s_nth_eq : Stream'.Seq.get? s n = none
⊢ squashSeq s n = s
[PROOFSTEP]
simp only [*, squashSeq]
[GOAL]
case some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_succ_n : Stream'.Seq.get? s (n + 1) = none
val✝ : Pair K
s_nth_eq : Stream'.Seq.get? s n = some val✝
⊢ squashSeq s n = s
[PROOFSTEP]
simp only [*, squashSeq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_n gp_succ_n : Pair K
s_nth_eq : Stream'.Seq.get? s n = some gp_n
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
⊢ Stream'.Seq.get? (squashSeq s n) n = some { a := gp_n.a, b := gp_n.b + gp_succ_n.a / gp_succ_n.b }
[PROOFSTEP]
simp [*, squashSeq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
cases s_succ_nth_eq : s.get? (n + 1)
[GOAL]
case none
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = none
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
case some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
case none => rw [squashSeq_eq_self_of_terminated s_succ_nth_eq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = none
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
case none => rw [squashSeq_eq_self_of_terminated s_succ_nth_eq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = none
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
rw [squashSeq_eq_self_of_terminated s_succ_nth_eq]
[GOAL]
case some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
case some =>
obtain ⟨gp_n, s_nth_eq⟩ : ∃ gp_n, s.get? n = some gp_n
exact s.ge_stable n.le_succ s_succ_nth_eq
obtain ⟨gp_m, s_mth_eq⟩ : ∃ gp_m, s.get? m = some gp_m
exact s.ge_stable (le_of_lt m_lt_n) s_nth_eq
simp [*, squashSeq, m_lt_n.ne]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
case some =>
obtain ⟨gp_n, s_nth_eq⟩ : ∃ gp_n, s.get? n = some gp_n
exact s.ge_stable n.le_succ s_succ_nth_eq
obtain ⟨gp_m, s_mth_eq⟩ : ∃ gp_m, s.get? m = some gp_m
exact s.ge_stable (le_of_lt m_lt_n) s_nth_eq
simp [*, squashSeq, m_lt_n.ne]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
obtain ⟨gp_n, s_nth_eq⟩ : ∃ gp_n, s.get? n = some gp_n
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
⊢ ∃ gp_n, Stream'.Seq.get? s n = some gp_n
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
gp_n : Pair K
s_nth_eq : Stream'.Seq.get? s n = some gp_n
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
exact s.ge_stable n.le_succ s_succ_nth_eq
[GOAL]
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
gp_n : Pair K
s_nth_eq : Stream'.Seq.get? s n = some gp_n
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
obtain ⟨gp_m, s_mth_eq⟩ : ∃ gp_m, s.get? m = some gp_m
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
gp_n : Pair K
s_nth_eq : Stream'.Seq.get? s n = some gp_n
⊢ ∃ gp_m, Stream'.Seq.get? s m = some gp_m
case intro.intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
gp_n : Pair K
s_nth_eq : Stream'.Seq.get? s n = some gp_n
gp_m : Pair K
s_mth_eq : Stream'.Seq.get? s m = some gp_m
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
exact s.ge_stable (le_of_lt m_lt_n) s_nth_eq
[GOAL]
case intro.intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
gp_n : Pair K
s_nth_eq : Stream'.Seq.get? s n = some gp_n
gp_m : Pair K
s_mth_eq : Stream'.Seq.get? s m = some gp_m
⊢ Stream'.Seq.get? (squashSeq s n) m = Stream'.Seq.get? s m
[PROOFSTEP]
simp [*, squashSeq, m_lt_n.ne]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
cases' s_succ_succ_nth_eq : s.get? (n + 2) with gp_succ_succ_n
[GOAL]
case none
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = none
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
case some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
case none =>
cases s_succ_nth_eq : s.get? (n + 1) <;>
simp only [squashSeq, Stream'.Seq.get?_tail, s_succ_nth_eq, s_succ_succ_nth_eq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = none
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
case none =>
cases s_succ_nth_eq : s.get? (n + 1) <;>
simp only [squashSeq, Stream'.Seq.get?_tail, s_succ_nth_eq, s_succ_succ_nth_eq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = none
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
cases s_succ_nth_eq : s.get? (n + 1)
[GOAL]
case none
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = none
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = none
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
simp only [squashSeq, Stream'.Seq.get?_tail, s_succ_nth_eq, s_succ_succ_nth_eq]
[GOAL]
case some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = none
val✝ : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some val✝
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
simp only [squashSeq, Stream'.Seq.get?_tail, s_succ_nth_eq, s_succ_succ_nth_eq]
[GOAL]
case some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
case some =>
obtain ⟨gp_succ_n, s_succ_nth_eq⟩ : ∃ gp_succ_n, s.get? (n + 1) = some gp_succ_n;
exact s.ge_stable (n + 1).le_succ s_succ_succ_nth_eq
ext1 m
cases' Decidable.em (m = n) with m_eq_n m_ne_n
· simp [*, squashSeq]
· have : s.tail.get? m = s.get? (m + 1) := s.get?_tail m
cases s_succ_mth_eq : s.get? (m + 1)
all_goals have _ := this.trans s_succ_mth_eq
· simp only [*, squashSeq, Stream'.Seq.get?_tail, Stream'.Seq.get?_zipWith, Option.map₂_none_right]
· simp [*, squashSeq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
case some =>
obtain ⟨gp_succ_n, s_succ_nth_eq⟩ : ∃ gp_succ_n, s.get? (n + 1) = some gp_succ_n;
exact s.ge_stable (n + 1).le_succ s_succ_succ_nth_eq
ext1 m
cases' Decidable.em (m = n) with m_eq_n m_ne_n
· simp [*, squashSeq]
· have : s.tail.get? m = s.get? (m + 1) := s.get?_tail m
cases s_succ_mth_eq : s.get? (m + 1)
all_goals have _ := this.trans s_succ_mth_eq
· simp only [*, squashSeq, Stream'.Seq.get?_tail, Stream'.Seq.get?_zipWith, Option.map₂_none_right]
· simp [*, squashSeq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
obtain ⟨gp_succ_n, s_succ_nth_eq⟩ : ∃ gp_succ_n, s.get? (n + 1) = some gp_succ_n
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
⊢ ∃ gp_succ_n, Stream'.Seq.get? s (n + 1) = some gp_succ_n
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
exact s.ge_stable (n + 1).le_succ s_succ_succ_nth_eq
[GOAL]
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
⊢ Stream'.Seq.tail (squashSeq s (n + 1)) = squashSeq (Stream'.Seq.tail s) n
[PROOFSTEP]
ext1 m
[GOAL]
case intro.h
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
cases' Decidable.em (m = n) with m_eq_n m_ne_n
[GOAL]
case intro.h.inl
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_eq_n : m = n
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
simp [*, squashSeq]
[GOAL]
case intro.h.inr
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_ne_n : ¬m = n
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
have : s.tail.get? m = s.get? (m + 1) := s.get?_tail m
[GOAL]
case intro.h.inr
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_ne_n : ¬m = n
this : Stream'.Seq.get? (Stream'.Seq.tail s) m = Stream'.Seq.get? s (m + 1)
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
cases s_succ_mth_eq : s.get? (m + 1)
[GOAL]
case intro.h.inr.none
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_ne_n : ¬m = n
this : Stream'.Seq.get? (Stream'.Seq.tail s) m = Stream'.Seq.get? s (m + 1)
s_succ_mth_eq : Stream'.Seq.get? s (m + 1) = none
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
case intro.h.inr.some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_ne_n : ¬m = n
this : Stream'.Seq.get? (Stream'.Seq.tail s) m = Stream'.Seq.get? s (m + 1)
val✝ : Pair K
s_succ_mth_eq : Stream'.Seq.get? s (m + 1) = some val✝
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
all_goals have _ := this.trans s_succ_mth_eq
[GOAL]
case intro.h.inr.none
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_ne_n : ¬m = n
this : Stream'.Seq.get? (Stream'.Seq.tail s) m = Stream'.Seq.get? s (m + 1)
s_succ_mth_eq : Stream'.Seq.get? s (m + 1) = none
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
have _ := this.trans s_succ_mth_eq
[GOAL]
case intro.h.inr.some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_ne_n : ¬m = n
this : Stream'.Seq.get? (Stream'.Seq.tail s) m = Stream'.Seq.get? s (m + 1)
val✝ : Pair K
s_succ_mth_eq : Stream'.Seq.get? s (m + 1) = some val✝
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
have _ := this.trans s_succ_mth_eq
[GOAL]
case intro.h.inr.none
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_ne_n : ¬m = n
this : Stream'.Seq.get? (Stream'.Seq.tail s) m = Stream'.Seq.get? s (m + 1)
s_succ_mth_eq : Stream'.Seq.get? s (m + 1) = none
x✝ : Stream'.Seq.get? (Stream'.Seq.tail s) m = none
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
simp only [*, squashSeq, Stream'.Seq.get?_tail, Stream'.Seq.get?_zipWith, Option.map₂_none_right]
[GOAL]
case intro.h.inr.some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_succ_n : Pair K
s_succ_succ_nth_eq : Stream'.Seq.get? s (n + 2) = some gp_succ_succ_n
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
m : ℕ
m_ne_n : ¬m = n
this : Stream'.Seq.get? (Stream'.Seq.tail s) m = Stream'.Seq.get? s (m + 1)
val✝ : Pair K
s_succ_mth_eq : Stream'.Seq.get? s (m + 1) = some val✝
x✝ : Stream'.Seq.get? (Stream'.Seq.tail s) m = some val✝
⊢ Stream'.Seq.get? (Stream'.Seq.tail (squashSeq s (n + 1))) m = Stream'.Seq.get? (squashSeq (Stream'.Seq.tail s) n) m
[PROOFSTEP]
simp [*, squashSeq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
⊢ convergents'Aux s (n + 2) = convergents'Aux (squashSeq s n) (n + 1)
[PROOFSTEP]
cases' s_succ_nth_eq : s.get? <| n + 1 with gp_succ_n
[GOAL]
case none
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = none
⊢ convergents'Aux s (n + 2) = convergents'Aux (squashSeq s n) (n + 1)
case some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
⊢ convergents'Aux s (n + 2) = convergents'Aux (squashSeq s n) (n + 1)
[PROOFSTEP]
case none => rw [squashSeq_eq_self_of_terminated s_succ_nth_eq, convergents'Aux_stable_step_of_terminated s_succ_nth_eq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = none
⊢ convergents'Aux s (n + 2) = convergents'Aux (squashSeq s n) (n + 1)
[PROOFSTEP]
case none => rw [squashSeq_eq_self_of_terminated s_succ_nth_eq, convergents'Aux_stable_step_of_terminated s_succ_nth_eq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = none
⊢ convergents'Aux s (n + 2) = convergents'Aux (squashSeq s n) (n + 1)
[PROOFSTEP]
rw [squashSeq_eq_self_of_terminated s_succ_nth_eq, convergents'Aux_stable_step_of_terminated s_succ_nth_eq]
[GOAL]
case some
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
⊢ convergents'Aux s (n + 2) = convergents'Aux (squashSeq s n) (n + 1)
[PROOFSTEP]
case some =>
induction' n with m IH generalizing s gp_succ_n
case zero =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
exact s.ge_stable zero_le_one s_succ_nth_eq
have : (squashSeq s 0).head = some ⟨gp_head.a, gp_head.b + gp_succ_n.a / gp_succ_n.b⟩ :=
squashSeq_nth_of_not_terminated s_head_eq s_succ_nth_eq
simp_all [convergents'Aux, Stream'.Seq.head, Stream'.Seq.get?_tail]
case succ =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
exact s.ge_stable (m + 2).zero_le s_succ_nth_eq
suffices gp_head.a / (gp_head.b + convergents'Aux s.tail (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2) by
simpa only [convergents'Aux, s_head_eq]
have : convergents'Aux s.tail (m + 2) = convergents'Aux (squashSeq s.tail m) (m + 1) :=
by
refine' IH gp_succ_n _
simpa [Stream'.Seq.get?_tail] using s_succ_nth_eq
have : (squashSeq s (m + 1)).head = some gp_head := (squashSeq_nth_of_lt m.succ_pos).trans s_head_eq
simp_all [convergents'Aux, squashSeq_succ_n_tail_eq_squashSeq_tail_n]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
⊢ convergents'Aux s (n + 2) = convergents'Aux (squashSeq s n) (n + 1)
[PROOFSTEP]
case some =>
induction' n with m IH generalizing s gp_succ_n
case zero =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
exact s.ge_stable zero_le_one s_succ_nth_eq
have : (squashSeq s 0).head = some ⟨gp_head.a, gp_head.b + gp_succ_n.a / gp_succ_n.b⟩ :=
squashSeq_nth_of_not_terminated s_head_eq s_succ_nth_eq
simp_all [convergents'Aux, Stream'.Seq.head, Stream'.Seq.get?_tail]
case succ =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
exact s.ge_stable (m + 2).zero_le s_succ_nth_eq
suffices gp_head.a / (gp_head.b + convergents'Aux s.tail (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2) by
simpa only [convergents'Aux, s_head_eq]
have : convergents'Aux s.tail (m + 2) = convergents'Aux (squashSeq s.tail m) (m + 1) :=
by
refine' IH gp_succ_n _
simpa [Stream'.Seq.get?_tail] using s_succ_nth_eq
have : (squashSeq s (m + 1)).head = some gp_head := (squashSeq_nth_of_lt m.succ_pos).trans s_head_eq
simp_all [convergents'Aux, squashSeq_succ_n_tail_eq_squashSeq_tail_n]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (n + 1) = some gp_succ_n
⊢ convergents'Aux s (n + 2) = convergents'Aux (squashSeq s n) (n + 1)
[PROOFSTEP]
induction' n with m IH generalizing s gp_succ_n
[GOAL]
case zero
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.zero + 1) = some gp_succ_n
⊢ convergents'Aux s (Nat.zero + 2) = convergents'Aux (squashSeq s Nat.zero) (Nat.zero + 1)
case succ
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
⊢ convergents'Aux s (Nat.succ m + 2) = convergents'Aux (squashSeq s (Nat.succ m)) (Nat.succ m + 1)
[PROOFSTEP]
case zero =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
exact s.ge_stable zero_le_one s_succ_nth_eq
have : (squashSeq s 0).head = some ⟨gp_head.a, gp_head.b + gp_succ_n.a / gp_succ_n.b⟩ :=
squashSeq_nth_of_not_terminated s_head_eq s_succ_nth_eq
simp_all [convergents'Aux, Stream'.Seq.head, Stream'.Seq.get?_tail]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.zero + 1) = some gp_succ_n
⊢ convergents'Aux s (Nat.zero + 2) = convergents'Aux (squashSeq s Nat.zero) (Nat.zero + 1)
[PROOFSTEP]
case zero =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
exact s.ge_stable zero_le_one s_succ_nth_eq
have : (squashSeq s 0).head = some ⟨gp_head.a, gp_head.b + gp_succ_n.a / gp_succ_n.b⟩ :=
squashSeq_nth_of_not_terminated s_head_eq s_succ_nth_eq
simp_all [convergents'Aux, Stream'.Seq.head, Stream'.Seq.get?_tail]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.zero + 1) = some gp_succ_n
⊢ convergents'Aux s (Nat.zero + 2) = convergents'Aux (squashSeq s Nat.zero) (Nat.zero + 1)
[PROOFSTEP]
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.zero + 1) = some gp_succ_n
⊢ ∃ gp_head, Stream'.Seq.head s = some gp_head
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.zero + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
⊢ convergents'Aux s (Nat.zero + 2) = convergents'Aux (squashSeq s Nat.zero) (Nat.zero + 1)
[PROOFSTEP]
exact s.ge_stable zero_le_one s_succ_nth_eq
[GOAL]
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.zero + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
⊢ convergents'Aux s (Nat.zero + 2) = convergents'Aux (squashSeq s Nat.zero) (Nat.zero + 1)
[PROOFSTEP]
have : (squashSeq s 0).head = some ⟨gp_head.a, gp_head.b + gp_succ_n.a / gp_succ_n.b⟩ :=
squashSeq_nth_of_not_terminated s_head_eq s_succ_nth_eq
[GOAL]
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.zero + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
this : Stream'.Seq.head (squashSeq s 0) = some { a := gp_head.a, b := gp_head.b + gp_succ_n.a / gp_succ_n.b }
⊢ convergents'Aux s (Nat.zero + 2) = convergents'Aux (squashSeq s Nat.zero) (Nat.zero + 1)
[PROOFSTEP]
simp_all [convergents'Aux, Stream'.Seq.head, Stream'.Seq.get?_tail]
[GOAL]
case succ
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
⊢ convergents'Aux s (Nat.succ m + 2) = convergents'Aux (squashSeq s (Nat.succ m)) (Nat.succ m + 1)
[PROOFSTEP]
case succ =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
exact s.ge_stable (m + 2).zero_le s_succ_nth_eq
suffices gp_head.a / (gp_head.b + convergents'Aux s.tail (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2) by
simpa only [convergents'Aux, s_head_eq]
have : convergents'Aux s.tail (m + 2) = convergents'Aux (squashSeq s.tail m) (m + 1) :=
by
refine' IH gp_succ_n _
simpa [Stream'.Seq.get?_tail] using s_succ_nth_eq
have : (squashSeq s (m + 1)).head = some gp_head := (squashSeq_nth_of_lt m.succ_pos).trans s_head_eq
simp_all [convergents'Aux, squashSeq_succ_n_tail_eq_squashSeq_tail_n]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
⊢ convergents'Aux s (Nat.succ m + 2) = convergents'Aux (squashSeq s (Nat.succ m)) (Nat.succ m + 1)
[PROOFSTEP]
case succ =>
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
exact s.ge_stable (m + 2).zero_le s_succ_nth_eq
suffices gp_head.a / (gp_head.b + convergents'Aux s.tail (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2) by
simpa only [convergents'Aux, s_head_eq]
have : convergents'Aux s.tail (m + 2) = convergents'Aux (squashSeq s.tail m) (m + 1) :=
by
refine' IH gp_succ_n _
simpa [Stream'.Seq.get?_tail] using s_succ_nth_eq
have : (squashSeq s (m + 1)).head = some gp_head := (squashSeq_nth_of_lt m.succ_pos).trans s_head_eq
simp_all [convergents'Aux, squashSeq_succ_n_tail_eq_squashSeq_tail_n]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
⊢ convergents'Aux s (Nat.succ m + 2) = convergents'Aux (squashSeq s (Nat.succ m)) (Nat.succ m + 1)
[PROOFSTEP]
obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
⊢ ∃ gp_head, Stream'.Seq.head s = some gp_head
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
⊢ convergents'Aux s (Nat.succ m + 2) = convergents'Aux (squashSeq s (Nat.succ m)) (Nat.succ m + 1)
[PROOFSTEP]
exact s.ge_stable (m + 2).zero_le s_succ_nth_eq
[GOAL]
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
⊢ convergents'Aux s (Nat.succ m + 2) = convergents'Aux (squashSeq s (Nat.succ m)) (Nat.succ m + 1)
[PROOFSTEP]
suffices gp_head.a / (gp_head.b + convergents'Aux s.tail (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2) by
simpa only [convergents'Aux, s_head_eq]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
this :
gp_head.a / (gp_head.b + convergents'Aux (Stream'.Seq.tail s) (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2)
⊢ convergents'Aux s (Nat.succ m + 2) = convergents'Aux (squashSeq s (Nat.succ m)) (Nat.succ m + 1)
[PROOFSTEP]
simpa only [convergents'Aux, s_head_eq]
[GOAL]
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
⊢ gp_head.a / (gp_head.b + convergents'Aux (Stream'.Seq.tail s) (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2)
[PROOFSTEP]
have : convergents'Aux s.tail (m + 2) = convergents'Aux (squashSeq s.tail m) (m + 1) :=
by
refine' IH gp_succ_n _
simpa [Stream'.Seq.get?_tail] using s_succ_nth_eq
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
⊢ convergents'Aux (Stream'.Seq.tail s) (m + 2) = convergents'Aux (squashSeq (Stream'.Seq.tail s) m) (m + 1)
[PROOFSTEP]
refine' IH gp_succ_n _
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
⊢ Stream'.Seq.get? (Stream'.Seq.tail s) (m + 1) = some gp_succ_n
[PROOFSTEP]
simpa [Stream'.Seq.get?_tail] using s_succ_nth_eq
[GOAL]
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
this : convergents'Aux (Stream'.Seq.tail s) (m + 2) = convergents'Aux (squashSeq (Stream'.Seq.tail s) m) (m + 1)
⊢ gp_head.a / (gp_head.b + convergents'Aux (Stream'.Seq.tail s) (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2)
[PROOFSTEP]
have : (squashSeq s (m + 1)).head = some gp_head := (squashSeq_nth_of_lt m.succ_pos).trans s_head_eq
[GOAL]
case intro
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s✝ : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
gp_succ_n✝ : Pair K
s_succ_nth_eq✝ : Stream'.Seq.get? s✝ (n + 1) = some gp_succ_n✝
m : ℕ
IH :
∀ {s : Stream'.Seq (Pair K)} (gp_succ_n : Pair K),
Stream'.Seq.get? s (m + 1) = some gp_succ_n → convergents'Aux s (m + 2) = convergents'Aux (squashSeq s m) (m + 1)
s : Stream'.Seq (Pair K)
gp_succ_n : Pair K
s_succ_nth_eq : Stream'.Seq.get? s (Nat.succ m + 1) = some gp_succ_n
gp_head : Pair K
s_head_eq : Stream'.Seq.head s = some gp_head
this✝ : convergents'Aux (Stream'.Seq.tail s) (m + 2) = convergents'Aux (squashSeq (Stream'.Seq.tail s) m) (m + 1)
this : Stream'.Seq.head (squashSeq s (m + 1)) = some gp_head
⊢ gp_head.a / (gp_head.b + convergents'Aux (Stream'.Seq.tail s) (m + 2)) = convergents'Aux (squashSeq s (m + 1)) (m + 2)
[PROOFSTEP]
simp_all [convergents'Aux, squashSeq_succ_n_tail_eq_squashSeq_tail_n]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_n : TerminatedAt g n
⊢ squashGCF g n = g
[PROOFSTEP]
cases n
[GOAL]
case zero
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_n : TerminatedAt g Nat.zero
⊢ squashGCF g Nat.zero = g
case succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
terminated_at_n : TerminatedAt g (Nat.succ n✝)
⊢ squashGCF g (Nat.succ n✝) = g
[PROOFSTEP]
case zero =>
change g.s.get? 0 = none at terminated_at_n
simp only [convergents', squashGCF, convergents'Aux, terminated_at_n]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_n : TerminatedAt g Nat.zero
⊢ squashGCF g Nat.zero = g
[PROOFSTEP]
case zero =>
change g.s.get? 0 = none at terminated_at_n
simp only [convergents', squashGCF, convergents'Aux, terminated_at_n]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_n : TerminatedAt g Nat.zero
⊢ squashGCF g Nat.zero = g
[PROOFSTEP]
change g.s.get? 0 = none at terminated_at_n
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
terminated_at_n : Stream'.Seq.get? g.s 0 = none
⊢ squashGCF g Nat.zero = g
[PROOFSTEP]
simp only [convergents', squashGCF, convergents'Aux, terminated_at_n]
[GOAL]
case succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
terminated_at_n : TerminatedAt g (Nat.succ n✝)
⊢ squashGCF g (Nat.succ n✝) = g
[PROOFSTEP]
case succ =>
cases g
simp only [squashGCF, mk.injEq, true_and]
exact squashSeq_eq_self_of_terminated terminated_at_n
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
terminated_at_n : TerminatedAt g (Nat.succ n✝)
⊢ squashGCF g (Nat.succ n✝) = g
[PROOFSTEP]
case succ =>
cases g
simp only [squashGCF, mk.injEq, true_and]
exact squashSeq_eq_self_of_terminated terminated_at_n
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
terminated_at_n : TerminatedAt g (Nat.succ n✝)
⊢ squashGCF g (Nat.succ n✝) = g
[PROOFSTEP]
cases g
[GOAL]
case mk
K : Type u_1
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
h✝ : K
s✝ : Stream'.Seq (Pair K)
terminated_at_n : TerminatedAt { h := h✝, s := s✝ } (Nat.succ n✝)
⊢ squashGCF { h := h✝, s := s✝ } (Nat.succ n✝) = { h := h✝, s := s✝ }
[PROOFSTEP]
simp only [squashGCF, mk.injEq, true_and]
[GOAL]
case mk
K : Type u_1
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
h✝ : K
s✝ : Stream'.Seq (Pair K)
terminated_at_n : TerminatedAt { h := h✝, s := s✝ } (Nat.succ n✝)
⊢ squashSeq s✝ n✝ = s✝
[PROOFSTEP]
exact squashSeq_eq_self_of_terminated terminated_at_n
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
m_lt_n : m < n
⊢ Stream'.Seq.get? (squashGCF g (n + 1)).s m = Stream'.Seq.get? g.s m
[PROOFSTEP]
simp only [squashGCF, squashSeq_nth_of_lt m_lt_n, Nat.add_eq, add_zero]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
⊢ convergents' g (n + 1) = convergents' (squashGCF g n) n
[PROOFSTEP]
cases n
[GOAL]
case zero
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
⊢ convergents' g (Nat.zero + 1) = convergents' (squashGCF g Nat.zero) Nat.zero
case succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
⊢ convergents' g (Nat.succ n✝ + 1) = convergents' (squashGCF g (Nat.succ n✝)) (Nat.succ n✝)
[PROOFSTEP]
case zero =>
cases g_s_head_eq : g.s.get? 0 <;> simp [g_s_head_eq, squashGCF, convergents', convergents'Aux, Stream'.Seq.head]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
⊢ convergents' g (Nat.zero + 1) = convergents' (squashGCF g Nat.zero) Nat.zero
[PROOFSTEP]
case zero =>
cases g_s_head_eq : g.s.get? 0 <;> simp [g_s_head_eq, squashGCF, convergents', convergents'Aux, Stream'.Seq.head]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
⊢ convergents' g (Nat.zero + 1) = convergents' (squashGCF g Nat.zero) Nat.zero
[PROOFSTEP]
cases g_s_head_eq : g.s.get? 0
[GOAL]
case none
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
g_s_head_eq : Stream'.Seq.get? g.s 0 = none
⊢ convergents' g (Nat.zero + 1) = convergents' (squashGCF g Nat.zero) Nat.zero
[PROOFSTEP]
simp [g_s_head_eq, squashGCF, convergents', convergents'Aux, Stream'.Seq.head]
[GOAL]
case some
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
val✝ : Pair K
g_s_head_eq : Stream'.Seq.get? g.s 0 = some val✝
⊢ convergents' g (Nat.zero + 1) = convergents' (squashGCF g Nat.zero) Nat.zero
[PROOFSTEP]
simp [g_s_head_eq, squashGCF, convergents', convergents'Aux, Stream'.Seq.head]
[GOAL]
case succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
⊢ convergents' g (Nat.succ n✝ + 1) = convergents' (squashGCF g (Nat.succ n✝)) (Nat.succ n✝)
[PROOFSTEP]
case succ => simp only [succ_succ_nth_convergent'_aux_eq_succ_nth_convergent'_aux_squashSeq, convergents', squashGCF]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
⊢ convergents' g (Nat.succ n✝ + 1) = convergents' (squashGCF g (Nat.succ n✝)) (Nat.succ n✝)
[PROOFSTEP]
case succ => simp only [succ_succ_nth_convergent'_aux_eq_succ_nth_convergent'_aux_squashSeq, convergents', squashGCF]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n✝ : ℕ
⊢ convergents' g (Nat.succ n✝ + 1) = convergents' (squashGCF g (Nat.succ n✝)) (Nat.succ n✝)
[PROOFSTEP]
simp only [succ_succ_nth_convergent'_aux_eq_succ_nth_convergent'_aux_squashSeq, convergents', squashGCF]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
⊢ ∀ (n_1 : ℕ),
(∀ (m : ℕ), m < n_1 → m ≤ n → continuantsAux g m = continuantsAux (squashGCF g n) m) →
n_1 ≤ n → continuantsAux g n_1 = continuantsAux (squashGCF g n) n_1
[PROOFSTEP]
clear m
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
⊢ ∀ (n_1 : ℕ),
(∀ (m : ℕ), m < n_1 → m ≤ n → continuantsAux g m = continuantsAux (squashGCF g n) m) →
n_1 ≤ n → continuantsAux g n_1 = continuantsAux (squashGCF g n) n_1
[PROOFSTEP]
intro m IH m_le_n
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m : ℕ
IH : ∀ (m_1 : ℕ), m_1 < m → m_1 ≤ n → continuantsAux g m_1 = continuantsAux (squashGCF g n) m_1
m_le_n : m ≤ n
⊢ continuantsAux g m = continuantsAux (squashGCF g n) m
[PROOFSTEP]
cases' m with m'
[GOAL]
case zero
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
IH : ∀ (m : ℕ), m < Nat.zero → m ≤ n → continuantsAux g m = continuantsAux (squashGCF g n) m
m_le_n : Nat.zero ≤ n
⊢ continuantsAux g Nat.zero = continuantsAux (squashGCF g n) Nat.zero
[PROOFSTEP]
rfl
[GOAL]
case succ
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m' : ℕ
IH : ∀ (m : ℕ), m < Nat.succ m' → m ≤ n → continuantsAux g m = continuantsAux (squashGCF g n) m
m_le_n : Nat.succ m' ≤ n
⊢ continuantsAux g (Nat.succ m') = continuantsAux (squashGCF g n) (Nat.succ m')
[PROOFSTEP]
cases' n with n'
[GOAL]
case succ.zero
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m' : ℕ
IH : ∀ (m : ℕ), m < Nat.succ m' → m ≤ Nat.zero → continuantsAux g m = continuantsAux (squashGCF g Nat.zero) m
m_le_n : Nat.succ m' ≤ Nat.zero
⊢ continuantsAux g (Nat.succ m') = continuantsAux (squashGCF g Nat.zero) (Nat.succ m')
[PROOFSTEP]
exact (m'.not_succ_le_zero m_le_n).elim
[GOAL]
case succ.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
m' n' : ℕ
IH : ∀ (m : ℕ), m < Nat.succ m' → m ≤ Nat.succ n' → continuantsAux g m = continuantsAux (squashGCF g (Nat.succ n')) m
m_le_n : Nat.succ m' ≤ Nat.succ n'
⊢ continuantsAux g (Nat.succ m') = continuantsAux (squashGCF g (Nat.succ n')) (Nat.succ m')
[PROOFSTEP]
cases' m' with m''
[GOAL]
case succ.succ.zero
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n' : ℕ
IH :
∀ (m : ℕ), m < Nat.succ Nat.zero → m ≤ Nat.succ n' → continuantsAux g m = continuantsAux (squashGCF g (Nat.succ n')) m
m_le_n : Nat.succ Nat.zero ≤ Nat.succ n'
⊢ continuantsAux g (Nat.succ Nat.zero) = continuantsAux (squashGCF g (Nat.succ n')) (Nat.succ Nat.zero)
[PROOFSTEP]
rfl
[GOAL]
case succ.succ.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n' m'' : ℕ
IH :
∀ (m : ℕ),
m < Nat.succ (Nat.succ m'') → m ≤ Nat.succ n' → continuantsAux g m = continuantsAux (squashGCF g (Nat.succ n')) m
m_le_n : Nat.succ (Nat.succ m'') ≤ Nat.succ n'
⊢ continuantsAux g (Nat.succ (Nat.succ m'')) = continuantsAux (squashGCF g (Nat.succ n')) (Nat.succ (Nat.succ m''))
[PROOFSTEP]
have m'_lt_n : m'' + 1 < n' + 1 := m_le_n
[GOAL]
case succ.succ.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n' m'' : ℕ
IH :
∀ (m : ℕ),
m < Nat.succ (Nat.succ m'') → m ≤ Nat.succ n' → continuantsAux g m = continuantsAux (squashGCF g (Nat.succ n')) m
m_le_n : Nat.succ (Nat.succ m'') ≤ Nat.succ n'
m'_lt_n : m'' + 1 < n' + 1
⊢ continuantsAux g (Nat.succ (Nat.succ m'')) = continuantsAux (squashGCF g (Nat.succ n')) (Nat.succ (Nat.succ m''))
[PROOFSTEP]
have succ_m''th_conts_aux_eq := IH (m'' + 1) (lt_add_one (m'' + 1)) m'_lt_n.le
[GOAL]
case succ.succ.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n' m'' : ℕ
IH :
∀ (m : ℕ),
m < Nat.succ (Nat.succ m'') → m ≤ Nat.succ n' → continuantsAux g m = continuantsAux (squashGCF g (Nat.succ n')) m
m_le_n : Nat.succ (Nat.succ m'') ≤ Nat.succ n'
m'_lt_n : m'' + 1 < n' + 1
succ_m''th_conts_aux_eq : continuantsAux g (m'' + 1) = continuantsAux (squashGCF g (Nat.succ n')) (m'' + 1)
⊢ continuantsAux g (Nat.succ (Nat.succ m'')) = continuantsAux (squashGCF g (Nat.succ n')) (Nat.succ (Nat.succ m''))
[PROOFSTEP]
have : m'' < m'' + 2 := lt_add_of_pos_right m'' zero_lt_two
[GOAL]
case succ.succ.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n' m'' : ℕ
IH :
∀ (m : ℕ),
m < Nat.succ (Nat.succ m'') → m ≤ Nat.succ n' → continuantsAux g m = continuantsAux (squashGCF g (Nat.succ n')) m
m_le_n : Nat.succ (Nat.succ m'') ≤ Nat.succ n'
m'_lt_n : m'' + 1 < n' + 1
succ_m''th_conts_aux_eq : continuantsAux g (m'' + 1) = continuantsAux (squashGCF g (Nat.succ n')) (m'' + 1)
this : m'' < m'' + 2
⊢ continuantsAux g (Nat.succ (Nat.succ m'')) = continuantsAux (squashGCF g (Nat.succ n')) (Nat.succ (Nat.succ m''))
[PROOFSTEP]
have m''th_conts_aux_eq := IH m'' this (le_trans this.le m_le_n)
[GOAL]
case succ.succ.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n' m'' : ℕ
IH :
∀ (m : ℕ),
m < Nat.succ (Nat.succ m'') → m ≤ Nat.succ n' → continuantsAux g m = continuantsAux (squashGCF g (Nat.succ n')) m
m_le_n : Nat.succ (Nat.succ m'') ≤ Nat.succ n'
m'_lt_n : m'' + 1 < n' + 1
succ_m''th_conts_aux_eq : continuantsAux g (m'' + 1) = continuantsAux (squashGCF g (Nat.succ n')) (m'' + 1)
this : m'' < m'' + 2
m''th_conts_aux_eq : continuantsAux g m'' = continuantsAux (squashGCF g (Nat.succ n')) m''
⊢ continuantsAux g (Nat.succ (Nat.succ m'')) = continuantsAux (squashGCF g (Nat.succ n')) (Nat.succ (Nat.succ m''))
[PROOFSTEP]
have : (squashGCF g (n' + 1)).s.get? m'' = g.s.get? m'' := squashGCF_nth_of_lt (Nat.succ_lt_succ_iff.mp m'_lt_n)
[GOAL]
case succ.succ.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : DivisionRing K
n' m'' : ℕ
IH :
∀ (m : ℕ),
m < Nat.succ (Nat.succ m'') → m ≤ Nat.succ n' → continuantsAux g m = continuantsAux (squashGCF g (Nat.succ n')) m
m_le_n : Nat.succ (Nat.succ m'') ≤ Nat.succ n'
m'_lt_n : m'' + 1 < n' + 1
succ_m''th_conts_aux_eq : continuantsAux g (m'' + 1) = continuantsAux (squashGCF g (Nat.succ n')) (m'' + 1)
this✝ : m'' < m'' + 2
m''th_conts_aux_eq : continuantsAux g m'' = continuantsAux (squashGCF g (Nat.succ n')) m''
this : Stream'.Seq.get? (squashGCF g (n' + 1)).s m'' = Stream'.Seq.get? g.s m''
⊢ continuantsAux g (Nat.succ (Nat.succ m'')) = continuantsAux (squashGCF g (Nat.succ n')) (Nat.succ (Nat.succ m''))
[PROOFSTEP]
simp [continuantsAux, succ_m''th_conts_aux_eq, m''th_conts_aux_eq, this]
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
⊢ convergents g (n + 1) = convergents (squashGCF g n) n
[PROOFSTEP]
cases' Decidable.em (g.TerminatedAt n) with terminated_at_n not_terminated_at_n
[GOAL]
case inl
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
terminated_at_n : TerminatedAt g n
⊢ convergents g (n + 1) = convergents (squashGCF g n) n
[PROOFSTEP]
have : squashGCF g n = g := squashGCF_eq_self_of_terminated terminated_at_n
[GOAL]
case inl
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
terminated_at_n : TerminatedAt g n
this : squashGCF g n = g
⊢ convergents g (n + 1) = convergents (squashGCF g n) n
[PROOFSTEP]
simp only [this, convergents_stable_of_terminated n.le_succ terminated_at_n]
[GOAL]
case inr
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g n
⊢ convergents g (n + 1) = convergents (squashGCF g n) n
[PROOFSTEP]
obtain ⟨⟨a, b⟩, s_nth_eq⟩ : ∃ gp_n, g.s.get? n = some gp_n
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g n
⊢ ∃ gp_n, Stream'.Seq.get? g.s n = some gp_n
case inr.intro.mk
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g n
a b : K
s_nth_eq : Stream'.Seq.get? g.s n = some { a := a, b := b }
⊢ convergents g (n + 1) = convergents (squashGCF g n) n
[PROOFSTEP]
exact Option.ne_none_iff_exists'.mp not_terminated_at_n
[GOAL]
case inr.intro.mk
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g n
a b : K
s_nth_eq : Stream'.Seq.get? g.s n = some { a := a, b := b }
⊢ convergents g (n + 1) = convergents (squashGCF g n) n
[PROOFSTEP]
have b_ne_zero : b ≠ 0 := nth_part_denom_ne_zero (part_denom_eq_s_b s_nth_eq)
[GOAL]
case inr.intro.mk
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g n
a b : K
s_nth_eq : Stream'.Seq.get? g.s n = some { a := a, b := b }
b_ne_zero : b ≠ 0
⊢ convergents g (n + 1) = convergents (squashGCF g n) n
[PROOFSTEP]
cases' n with n'
[GOAL]
case inr.intro.mk.zero
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) Nat.zero = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g Nat.zero
s_nth_eq : Stream'.Seq.get? g.s Nat.zero = some { a := a, b := b }
⊢ convergents g (Nat.zero + 1) = convergents (squashGCF g Nat.zero) Nat.zero
case inr.intro.mk.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
case
zero =>
suffices (b * g.h + a) / b = g.h + a / b by
simpa [squashGCF, s_nth_eq, convergent_eq_conts_a_div_conts_b,
continuants_recurrenceAux s_nth_eq zeroth_continuant_aux_eq_one_zero first_continuant_aux_eq_h_one]
calc
(b * g.h + a) / b = b * g.h / b + a / b := by
ring
-- requires `Field`, not `DivisionRing`
_ = g.h + a / b := by rw [mul_div_cancel_left _ b_ne_zero]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) Nat.zero = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g Nat.zero
s_nth_eq : Stream'.Seq.get? g.s Nat.zero = some { a := a, b := b }
⊢ convergents g (Nat.zero + 1) = convergents (squashGCF g Nat.zero) Nat.zero
[PROOFSTEP]
case
zero =>
suffices (b * g.h + a) / b = g.h + a / b by
simpa [squashGCF, s_nth_eq, convergent_eq_conts_a_div_conts_b,
continuants_recurrenceAux s_nth_eq zeroth_continuant_aux_eq_one_zero first_continuant_aux_eq_h_one]
calc
(b * g.h + a) / b = b * g.h / b + a / b := by
ring
-- requires `Field`, not `DivisionRing`
_ = g.h + a / b := by rw [mul_div_cancel_left _ b_ne_zero]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) Nat.zero = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g Nat.zero
s_nth_eq : Stream'.Seq.get? g.s Nat.zero = some { a := a, b := b }
⊢ convergents g (Nat.zero + 1) = convergents (squashGCF g Nat.zero) Nat.zero
[PROOFSTEP]
suffices (b * g.h + a) / b = g.h + a / b by
simpa [squashGCF, s_nth_eq, convergent_eq_conts_a_div_conts_b,
continuants_recurrenceAux s_nth_eq zeroth_continuant_aux_eq_one_zero first_continuant_aux_eq_h_one]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) Nat.zero = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g Nat.zero
s_nth_eq : Stream'.Seq.get? g.s Nat.zero = some { a := a, b := b }
this : (b * g.h + a) / b = g.h + a / b
⊢ convergents g (Nat.zero + 1) = convergents (squashGCF g Nat.zero) Nat.zero
[PROOFSTEP]
simpa [squashGCF, s_nth_eq, convergent_eq_conts_a_div_conts_b,
continuants_recurrenceAux s_nth_eq zeroth_continuant_aux_eq_one_zero first_continuant_aux_eq_h_one]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) Nat.zero = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g Nat.zero
s_nth_eq : Stream'.Seq.get? g.s Nat.zero = some { a := a, b := b }
⊢ (b * g.h + a) / b = g.h + a / b
[PROOFSTEP]
calc
(b * g.h + a) / b = b * g.h / b + a / b := by
ring
-- requires `Field`, not `DivisionRing`
_ = g.h + a / b := by rw [mul_div_cancel_left _ b_ne_zero]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) Nat.zero = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g Nat.zero
s_nth_eq : Stream'.Seq.get? g.s Nat.zero = some { a := a, b := b }
⊢ (b * g.h + a) / b = b * g.h / b + a / b
[PROOFSTEP]
ring
-- requires `Field`, not `DivisionRing`
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) Nat.zero = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g Nat.zero
s_nth_eq : Stream'.Seq.get? g.s Nat.zero = some { a := a, b := b }
⊢ b * g.h / b + a / b = g.h + a / b
[PROOFSTEP]
rw [mul_div_cancel_left _ b_ne_zero]
[GOAL]
case inr.intro.mk.succ
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
case
succ =>
obtain ⟨⟨pa, pb⟩, s_n'th_eq⟩ : ∃ gp_n', g.s.get? n' = some gp_n' := g.s.ge_stable n'.le_succ s_nth_eq
let g' := squashGCF g (n' + 1)
set pred_conts := g.continuantsAux (n' + 1) with succ_n'th_conts_aux_eq
set ppred_conts := g.continuantsAux n' with n'th_conts_aux_eq
let pA := pred_conts.a
let pB := pred_conts.b
let ppA := ppred_conts.a
let ppB := ppred_conts.b
set pred_conts' := g'.continuantsAux (n' + 1) with succ_n'th_conts_aux_eq'
set ppred_conts' := g'.continuantsAux n' with n'th_conts_aux_eq'
let pA' := pred_conts'.a
let pB' := pred_conts'.b
let ppA' := ppred_conts'.a
let ppB' := ppred_conts'.b
have : g'.convergents (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB') :=
by
have : g'.s.get? n' = some ⟨pa, pb + a / b⟩ := squashSeq_nth_of_not_terminated s_n'th_eq s_nth_eq
rw [convergent_eq_conts_a_div_conts_b,
continuants_recurrenceAux this n'th_conts_aux_eq'.symm succ_n'th_conts_aux_eq'.symm]
rw [this]
-- then compute the convergent of the original gcf by recursively unfolding the continuants
-- computation twice
have : g.convergents (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) := by
-- use the recurrence once
have : g.continuantsAux (n' + 2) = ⟨pb * pA + pa * ppA, pb * pB + pa * ppB⟩ :=
continuantsAux_recurrence s_n'th_eq n'th_conts_aux_eq.symm succ_n'th_conts_aux_eq.symm
rw [convergent_eq_conts_a_div_conts_b, continuants_recurrenceAux s_nth_eq succ_n'th_conts_aux_eq.symm this]
rw [this]
suffices
((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
by
obtain ⟨eq1, eq2, eq3, eq4⟩ : pA' = pA ∧ pB' = pB ∧ ppA' = ppA ∧ ppB' = ppB := by
simp [*, (continuantsAux_eq_continuantsAux_squashGCF_of_le <| le_refl <| n' + 1).symm,
(continuantsAux_eq_continuantsAux_squashGCF_of_le n'.le_succ).symm]
symm
simpa only [eq1, eq2, eq3, eq4, mul_div_cancel _ b_ne_zero]
field_simp
congr 1 <;> ring
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
case
succ =>
obtain ⟨⟨pa, pb⟩, s_n'th_eq⟩ : ∃ gp_n', g.s.get? n' = some gp_n' := g.s.ge_stable n'.le_succ s_nth_eq
let g' := squashGCF g (n' + 1)
set pred_conts := g.continuantsAux (n' + 1) with succ_n'th_conts_aux_eq
set ppred_conts := g.continuantsAux n' with n'th_conts_aux_eq
let pA := pred_conts.a
let pB := pred_conts.b
let ppA := ppred_conts.a
let ppB := ppred_conts.b
set pred_conts' := g'.continuantsAux (n' + 1) with succ_n'th_conts_aux_eq'
set ppred_conts' := g'.continuantsAux n' with n'th_conts_aux_eq'
let pA' := pred_conts'.a
let pB' := pred_conts'.b
let ppA' := ppred_conts'.a
let ppB' := ppred_conts'.b
have : g'.convergents (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB') :=
by
have : g'.s.get? n' = some ⟨pa, pb + a / b⟩ := squashSeq_nth_of_not_terminated s_n'th_eq s_nth_eq
rw [convergent_eq_conts_a_div_conts_b,
continuants_recurrenceAux this n'th_conts_aux_eq'.symm succ_n'th_conts_aux_eq'.symm]
rw [this]
-- then compute the convergent of the original gcf by recursively unfolding the continuants
-- computation twice
have : g.convergents (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) := by
-- use the recurrence once
have : g.continuantsAux (n' + 2) = ⟨pb * pA + pa * ppA, pb * pB + pa * ppB⟩ :=
continuantsAux_recurrence s_n'th_eq n'th_conts_aux_eq.symm succ_n'th_conts_aux_eq.symm
rw [convergent_eq_conts_a_div_conts_b, continuants_recurrenceAux s_nth_eq succ_n'th_conts_aux_eq.symm this]
rw [this]
suffices
((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
by
obtain ⟨eq1, eq2, eq3, eq4⟩ : pA' = pA ∧ pB' = pB ∧ ppA' = ppA ∧ ppB' = ppB := by
simp [*, (continuantsAux_eq_continuantsAux_squashGCF_of_le <| le_refl <| n' + 1).symm,
(continuantsAux_eq_continuantsAux_squashGCF_of_le n'.le_succ).symm]
symm
simpa only [eq1, eq2, eq3, eq4, mul_div_cancel _ b_ne_zero]
field_simp
congr 1 <;> ring
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
obtain ⟨⟨pa, pb⟩, s_n'th_eq⟩ : ∃ gp_n', g.s.get? n' = some gp_n' := g.s.ge_stable n'.le_succ s_nth_eq
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let g' := squashGCF g (n' + 1)
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
set pred_conts := g.continuantsAux (n' + 1) with succ_n'th_conts_aux_eq
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
set ppred_conts := g.continuantsAux n' with n'th_conts_aux_eq
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let pA := pred_conts.a
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let pB := pred_conts.b
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let ppA := ppred_conts.a
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let ppB := ppred_conts.b
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
set pred_conts' := g'.continuantsAux (n' + 1) with succ_n'th_conts_aux_eq'
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
set ppred_conts' := g'.continuantsAux n' with n'th_conts_aux_eq'
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let pA' := pred_conts'.a
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let pB' := pred_conts'.b
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let ppA' := ppred_conts'.a
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
let ppB' := ppred_conts'.b
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
have : g'.convergents (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB') :=
by
have : g'.s.get? n' = some ⟨pa, pb + a / b⟩ := squashSeq_nth_of_not_terminated s_n'th_eq s_nth_eq
rw [convergent_eq_conts_a_div_conts_b,
continuants_recurrenceAux this n'th_conts_aux_eq'.symm succ_n'th_conts_aux_eq'.symm]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
⊢ convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
[PROOFSTEP]
have : g'.s.get? n' = some ⟨pa, pb + a / b⟩ := squashSeq_nth_of_not_terminated s_n'th_eq s_nth_eq
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this : Stream'.Seq.get? g'.s n' = some { a := pa, b := pb + a / b }
⊢ convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
[PROOFSTEP]
rw [convergent_eq_conts_a_div_conts_b,
continuants_recurrenceAux this n'th_conts_aux_eq'.symm succ_n'th_conts_aux_eq'.symm]
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
⊢ convergents g (Nat.succ n' + 1) = convergents (squashGCF g (Nat.succ n')) (Nat.succ n')
[PROOFSTEP]
rw [this]
-- then compute the convergent of the original gcf by recursively unfolding the continuants
-- computation twice
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
⊢ convergents g (Nat.succ n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
[PROOFSTEP]
have : g.convergents (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) := by
-- use the recurrence once
have : g.continuantsAux (n' + 2) = ⟨pb * pA + pa * ppA, pb * pB + pa * ppB⟩ :=
continuantsAux_recurrence s_n'th_eq n'th_conts_aux_eq.symm succ_n'th_conts_aux_eq.symm
rw [convergent_eq_conts_a_div_conts_b, continuants_recurrenceAux s_nth_eq succ_n'th_conts_aux_eq.symm this]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
⊢ convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
[PROOFSTEP]
have : g.continuantsAux (n' + 2) = ⟨pb * pA + pa * ppA, pb * pB + pa * ppB⟩ :=
continuantsAux_recurrence s_n'th_eq n'th_conts_aux_eq.symm succ_n'th_conts_aux_eq.symm
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this : continuantsAux g (n' + 2) = { a := pb * pA + pa * ppA, b := pb * pB + pa * ppB }
⊢ convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
[PROOFSTEP]
rw [convergent_eq_conts_a_div_conts_b, continuants_recurrenceAux s_nth_eq succ_n'th_conts_aux_eq.symm this]
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
⊢ convergents g (Nat.succ n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
[PROOFSTEP]
rw [this]
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
⊢ (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) =
((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
[PROOFSTEP]
suffices
((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
by
obtain ⟨eq1, eq2, eq3, eq4⟩ : pA' = pA ∧ pB' = pB ∧ ppA' = ppA ∧ ppB' = ppB := by
simp [*, (continuantsAux_eq_continuantsAux_squashGCF_of_le <| le_refl <| n' + 1).symm,
(continuantsAux_eq_continuantsAux_squashGCF_of_le n'.le_succ).symm]
symm
simpa only [eq1, eq2, eq3, eq4, mul_div_cancel _ b_ne_zero]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝¹ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this✝ : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
this :
((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
⊢ (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) =
((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
[PROOFSTEP]
obtain ⟨eq1, eq2, eq3, eq4⟩ : pA' = pA ∧ pB' = pB ∧ ppA' = ppA ∧ ppB' = ppB := by
simp [*, (continuantsAux_eq_continuantsAux_squashGCF_of_le <| le_refl <| n' + 1).symm,
(continuantsAux_eq_continuantsAux_squashGCF_of_le n'.le_succ).symm]
[GOAL]
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝¹ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this✝ : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
this :
((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
⊢ pA' = pA ∧ pB' = pB ∧ ppA' = ppA ∧ ppB' = ppB
[PROOFSTEP]
simp [*, (continuantsAux_eq_continuantsAux_squashGCF_of_le <| le_refl <| n' + 1).symm,
(continuantsAux_eq_continuantsAux_squashGCF_of_le n'.le_succ).symm]
[GOAL]
case intro.intro.intro
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝¹ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this✝ : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
this :
((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
eq1 : pA' = pA
eq2 : pB' = pB
eq3 : ppA' = ppA
eq4 : ppB' = ppB
⊢ (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) =
((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
[PROOFSTEP]
symm
[GOAL]
case intro.intro.intro
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝¹ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this✝ : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
this :
((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
eq1 : pA' = pA
eq2 : pB' = pB
eq3 : ppA' = ppA
eq4 : ppB' = ppB
⊢ ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB') =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
[PROOFSTEP]
simpa only [eq1, eq2, eq3, eq4, mul_div_cancel _ b_ne_zero]
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
⊢ ((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) =
(b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
[PROOFSTEP]
field_simp
[GOAL]
case intro.mk
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
⊢ ((pb * b + a) * (continuantsAux g (n' + 1)).a + pa * (continuantsAux g n').a * b) /
((pb * b + a) * (continuantsAux g (n' + 1)).b + pa * (continuantsAux g n').b * b) =
(b * (pb * (continuantsAux g (n' + 1)).a + pa * (continuantsAux g n').a) + a * (continuantsAux g (n' + 1)).a) /
(b * (pb * (continuantsAux g (n' + 1)).b + pa * (continuantsAux g n').b) + a * (continuantsAux g (n' + 1)).b)
[PROOFSTEP]
congr 1
[GOAL]
case intro.mk.e_a
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
⊢ (pb * b + a) * (continuantsAux g (n' + 1)).a + pa * (continuantsAux g n').a * b =
b * (pb * (continuantsAux g (n' + 1)).a + pa * (continuantsAux g n').a) + a * (continuantsAux g (n' + 1)).a
[PROOFSTEP]
ring
[GOAL]
case intro.mk.e_a
K : Type u_1
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : Field K
a b : K
b_ne_zero : b ≠ 0
n' : ℕ
nth_part_denom_ne_zero : ∀ {b : K}, Stream'.Seq.get? (partialDenominators g) (Nat.succ n') = some b → b ≠ 0
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n')
s_nth_eq : Stream'.Seq.get? g.s (Nat.succ n') = some { a := a, b := b }
pa pb : K
s_n'th_eq : Stream'.Seq.get? g.s n' = some { a := pa, b := pb }
g' : GeneralizedContinuedFraction K := squashGCF g (n' + 1)
pred_conts : Pair K := continuantsAux g (n' + 1)
succ_n'th_conts_aux_eq : pred_conts = continuantsAux g (n' + 1)
ppred_conts : Pair K := continuantsAux g n'
n'th_conts_aux_eq : ppred_conts = continuantsAux g n'
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
pred_conts' : Pair K := continuantsAux g' (n' + 1)
succ_n'th_conts_aux_eq' : pred_conts' = continuantsAux g' (n' + 1)
ppred_conts' : Pair K := continuantsAux g' n'
n'th_conts_aux_eq' : ppred_conts' = continuantsAux g' n'
pA' : K := pred_conts'.a
pB' : K := pred_conts'.b
ppA' : K := ppred_conts'.a
ppB' : K := ppred_conts'.b
this✝ : convergents g' (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB')
this : convergents g (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB)
⊢ (pb * b + a) * (continuantsAux g (n' + 1)).b + pa * (continuantsAux g n').b * b =
b * (pb * (continuantsAux g (n' + 1)).b + pa * (continuantsAux g n').b) + a * (continuantsAux g (n' + 1)).b
[PROOFSTEP]
ring
[GOAL]
K : Type u_1
n : ℕ
g : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
⊢ convergents g n = convergents' g n
[PROOFSTEP]
induction' n with n IH generalizing g
[GOAL]
case zero
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.zero → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
⊢ convergents g Nat.zero = convergents' g Nat.zero
case succ
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
⊢ convergents g (Nat.succ n) = convergents' g (Nat.succ n)
[PROOFSTEP]
case zero => simp
[GOAL]
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.zero → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
⊢ convergents g Nat.zero = convergents' g Nat.zero
[PROOFSTEP]
case zero => simp
[GOAL]
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.zero → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
⊢ convergents g Nat.zero = convergents' g Nat.zero
[PROOFSTEP]
simp
[GOAL]
case succ
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
⊢ convergents g (Nat.succ n) = convergents' g (Nat.succ n)
[PROOFSTEP]
case succ =>
let g' := squashGCF g n
suffices g.convergents (n + 1) = g'.convergents' n by rwa [succ_nth_convergent'_eq_squashGCF_nth_convergent']
cases' Decidable.em (TerminatedAt g n) with terminated_at_n not_terminated_at_n
· have g'_eq_g : g' = g := squashGCF_eq_self_of_terminated terminated_at_n
rw [convergents_stable_of_terminated n.le_succ terminated_at_n, g'_eq_g, IH _]
intro _ _ m_lt_n s_mth_eq
exact s_pos (Nat.lt.step m_lt_n) s_mth_eq
· suffices g.convergents (n + 1) = g'.convergents n by
-- invoke the IH for the squashed gcf
rwa [← IH]
intro gp' m m_lt_n s_mth_eq'
cases' m_lt_n with n succ_m_lt_n
·
-- the difficult case at the squashed position: we first obtain the values from
-- the sequence
obtain ⟨gp_succ_m, s_succ_mth_eq⟩ : ∃ gp_succ_m, g.s.get? (m + 1) = some gp_succ_m
exact Option.ne_none_iff_exists'.mp not_terminated_at_n
obtain ⟨gp_m, mth_s_eq⟩ : ∃ gp_m, g.s.get? m = some gp_m
exact g.s.ge_stable m.le_succ s_succ_mth_eq
suffices 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
by
have ot : g'.s.get? m = some ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ :=
squashSeq_nth_of_not_terminated mth_s_eq s_succ_mth_eq
have : gp' = ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ := by simp_all only [Option.some.injEq]
rwa [this]
have m_lt_n : m < m.succ := Nat.lt_succ_self m
refine' ⟨(s_pos (Nat.lt.step m_lt_n) mth_s_eq).left, _⟩
refine' add_pos (s_pos (Nat.lt.step m_lt_n) mth_s_eq).right _
have : 0 < gp_succ_m.a ∧ 0 < gp_succ_m.b := s_pos (lt_add_one <| m + 1) s_succ_mth_eq
exact div_pos this.left this.right
·
-- the easy case: before the squashed position, nothing changes
refine' s_pos (Nat.lt.step <| Nat.lt.step succ_m_lt_n) _
exact Eq.trans (squashGCF_nth_of_lt succ_m_lt_n).symm s_mth_eq'
have : ∀ ⦃b⦄, g.partialDenominators.get? n = some b → b ≠ 0 :=
by
intro b nth_part_denom_eq
obtain ⟨gp, s_nth_eq, ⟨refl⟩⟩ : ∃ gp, g.s.get? n = some gp ∧ gp.b = b
exact exists_s_b_of_part_denom nth_part_denom_eq
exact (ne_of_lt (s_pos (lt_add_one n) s_nth_eq).right).symm
exact succ_nth_convergent_eq_squashGCF_nth_convergent @this
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
⊢ convergents g (Nat.succ n) = convergents' g (Nat.succ n)
[PROOFSTEP]
case succ =>
let g' := squashGCF g n
suffices g.convergents (n + 1) = g'.convergents' n by rwa [succ_nth_convergent'_eq_squashGCF_nth_convergent']
cases' Decidable.em (TerminatedAt g n) with terminated_at_n not_terminated_at_n
· have g'_eq_g : g' = g := squashGCF_eq_self_of_terminated terminated_at_n
rw [convergents_stable_of_terminated n.le_succ terminated_at_n, g'_eq_g, IH _]
intro _ _ m_lt_n s_mth_eq
exact s_pos (Nat.lt.step m_lt_n) s_mth_eq
· suffices g.convergents (n + 1) = g'.convergents n by
-- invoke the IH for the squashed gcf
rwa [← IH]
intro gp' m m_lt_n s_mth_eq'
cases' m_lt_n with n succ_m_lt_n
·
-- the difficult case at the squashed position: we first obtain the values from
-- the sequence
obtain ⟨gp_succ_m, s_succ_mth_eq⟩ : ∃ gp_succ_m, g.s.get? (m + 1) = some gp_succ_m
exact Option.ne_none_iff_exists'.mp not_terminated_at_n
obtain ⟨gp_m, mth_s_eq⟩ : ∃ gp_m, g.s.get? m = some gp_m
exact g.s.ge_stable m.le_succ s_succ_mth_eq
suffices 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
by
have ot : g'.s.get? m = some ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ :=
squashSeq_nth_of_not_terminated mth_s_eq s_succ_mth_eq
have : gp' = ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ := by simp_all only [Option.some.injEq]
rwa [this]
have m_lt_n : m < m.succ := Nat.lt_succ_self m
refine' ⟨(s_pos (Nat.lt.step m_lt_n) mth_s_eq).left, _⟩
refine' add_pos (s_pos (Nat.lt.step m_lt_n) mth_s_eq).right _
have : 0 < gp_succ_m.a ∧ 0 < gp_succ_m.b := s_pos (lt_add_one <| m + 1) s_succ_mth_eq
exact div_pos this.left this.right
·
-- the easy case: before the squashed position, nothing changes
refine' s_pos (Nat.lt.step <| Nat.lt.step succ_m_lt_n) _
exact Eq.trans (squashGCF_nth_of_lt succ_m_lt_n).symm s_mth_eq'
have : ∀ ⦃b⦄, g.partialDenominators.get? n = some b → b ≠ 0 :=
by
intro b nth_part_denom_eq
obtain ⟨gp, s_nth_eq, ⟨refl⟩⟩ : ∃ gp, g.s.get? n = some gp ∧ gp.b = b
exact exists_s_b_of_part_denom nth_part_denom_eq
exact (ne_of_lt (s_pos (lt_add_one n) s_nth_eq).right).symm
exact succ_nth_convergent_eq_squashGCF_nth_convergent @this
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
⊢ convergents g (Nat.succ n) = convergents' g (Nat.succ n)
[PROOFSTEP]
let g' := squashGCF g n
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
⊢ convergents g (Nat.succ n) = convergents' g (Nat.succ n)
[PROOFSTEP]
suffices g.convergents (n + 1) = g'.convergents' n by rwa [succ_nth_convergent'_eq_squashGCF_nth_convergent']
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
this : convergents g (n + 1) = convergents' g' n
⊢ convergents g (Nat.succ n) = convergents' g (Nat.succ n)
[PROOFSTEP]
rwa [succ_nth_convergent'_eq_squashGCF_nth_convergent']
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
⊢ convergents g (n + 1) = convergents' g' n
[PROOFSTEP]
cases' Decidable.em (TerminatedAt g n) with terminated_at_n not_terminated_at_n
[GOAL]
case inl
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
terminated_at_n : TerminatedAt g n
⊢ convergents g (n + 1) = convergents' g' n
[PROOFSTEP]
have g'_eq_g : g' = g := squashGCF_eq_self_of_terminated terminated_at_n
[GOAL]
case inl
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
terminated_at_n : TerminatedAt g n
g'_eq_g : g' = g
⊢ convergents g (n + 1) = convergents' g' n
[PROOFSTEP]
rw [convergents_stable_of_terminated n.le_succ terminated_at_n, g'_eq_g, IH _]
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
terminated_at_n : TerminatedAt g n
g'_eq_g : g' = g
⊢ ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
[PROOFSTEP]
intro _ _ m_lt_n s_mth_eq
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
terminated_at_n : TerminatedAt g n
g'_eq_g : g' = g
gp✝ : Pair K
m✝ : ℕ
m_lt_n : m✝ < n
s_mth_eq : Stream'.Seq.get? g.s m✝ = some gp✝
⊢ 0 < gp✝.a ∧ 0 < gp✝.b
[PROOFSTEP]
exact s_pos (Nat.lt.step m_lt_n) s_mth_eq
[GOAL]
case inr
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
⊢ convergents g (n + 1) = convergents' g' n
[PROOFSTEP]
suffices g.convergents (n + 1) = g'.convergents n by
-- invoke the IH for the squashed gcf
rwa [← IH]
intro gp' m m_lt_n s_mth_eq'
cases' m_lt_n with n succ_m_lt_n
·
-- the difficult case at the squashed position: we first obtain the values from
-- the sequence
obtain ⟨gp_succ_m, s_succ_mth_eq⟩ : ∃ gp_succ_m, g.s.get? (m + 1) = some gp_succ_m
exact Option.ne_none_iff_exists'.mp not_terminated_at_n
obtain ⟨gp_m, mth_s_eq⟩ : ∃ gp_m, g.s.get? m = some gp_m
exact g.s.ge_stable m.le_succ s_succ_mth_eq
suffices 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
by
have ot : g'.s.get? m = some ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ :=
squashSeq_nth_of_not_terminated mth_s_eq s_succ_mth_eq
have : gp' = ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ := by simp_all only [Option.some.injEq]
rwa [this]
have m_lt_n : m < m.succ := Nat.lt_succ_self m
refine' ⟨(s_pos (Nat.lt.step m_lt_n) mth_s_eq).left, _⟩
refine' add_pos (s_pos (Nat.lt.step m_lt_n) mth_s_eq).right _
have : 0 < gp_succ_m.a ∧ 0 < gp_succ_m.b := s_pos (lt_add_one <| m + 1) s_succ_mth_eq
exact div_pos this.left this.right
·
-- the easy case: before the squashed position, nothing changes
refine' s_pos (Nat.lt.step <| Nat.lt.step succ_m_lt_n) _
exact Eq.trans (squashGCF_nth_of_lt succ_m_lt_n).symm s_mth_eq'
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
this : convergents g (n + 1) = convergents g' n
⊢ convergents g (n + 1) = convergents' g' n
[PROOFSTEP]
rwa [← IH]
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
this : convergents g (n + 1) = convergents g' n
⊢ ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g'.s m = some gp → 0 < gp.a ∧ 0 < gp.b
[PROOFSTEP]
intro gp' m m_lt_n s_mth_eq'
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
this : convergents g (n + 1) = convergents g' n
gp' : Pair K
m : ℕ
m_lt_n : m < n
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
cases' m_lt_n with n succ_m_lt_n
[GOAL]
case refl
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
obtain ⟨gp_succ_m, s_succ_mth_eq⟩ : ∃ gp_succ_m, g.s.get? (m + 1) = some gp_succ_m
[GOAL]
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
⊢ ∃ gp_succ_m, Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
case refl.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
exact Option.ne_none_iff_exists'.mp not_terminated_at_n
[GOAL]
case refl.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
obtain ⟨gp_m, mth_s_eq⟩ : ∃ gp_m, g.s.get? m = some gp_m
[GOAL]
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
⊢ ∃ gp_m, Stream'.Seq.get? g.s m = some gp_m
case refl.intro.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
exact g.s.ge_stable m.le_succ s_succ_mth_eq
[GOAL]
case refl.intro.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
suffices 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
by
have ot : g'.s.get? m = some ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ :=
squashSeq_nth_of_not_terminated mth_s_eq s_succ_mth_eq
have : gp' = ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ := by simp_all only [Option.some.injEq]
rwa [this]
[GOAL]
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this✝ : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
this : 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
have ot : g'.s.get? m = some ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ :=
squashSeq_nth_of_not_terminated mth_s_eq s_succ_mth_eq
[GOAL]
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this✝ : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
this : 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
ot : Stream'.Seq.get? g'.s m = some { a := gp_m.a, b := gp_m.b + gp_succ_m.a / gp_succ_m.b }
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
have : gp' = ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ := by simp_all only [Option.some.injEq]
[GOAL]
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this✝ : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
this : 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
ot : Stream'.Seq.get? g'.s m = some { a := gp_m.a, b := gp_m.b + gp_succ_m.a / gp_succ_m.b }
⊢ gp' = { a := gp_m.a, b := gp_m.b + gp_succ_m.a / gp_succ_m.b }
[PROOFSTEP]
simp_all only [Option.some.injEq]
[GOAL]
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this✝¹ : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
this✝ : 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
ot : Stream'.Seq.get? g'.s m = some { a := gp_m.a, b := gp_m.b + gp_succ_m.a / gp_succ_m.b }
this : gp' = { a := gp_m.a, b := gp_m.b + gp_succ_m.a / gp_succ_m.b }
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
rwa [this]
[GOAL]
case refl.intro.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
⊢ 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
[PROOFSTEP]
have m_lt_n : m < m.succ := Nat.lt_succ_self m
[GOAL]
case refl.intro.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
m_lt_n : m < Nat.succ m
⊢ 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
[PROOFSTEP]
refine' ⟨(s_pos (Nat.lt.step m_lt_n) mth_s_eq).left, _⟩
[GOAL]
case refl.intro.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
m_lt_n : m < Nat.succ m
⊢ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b
[PROOFSTEP]
refine' add_pos (s_pos (Nat.lt.step m_lt_n) mth_s_eq).right _
[GOAL]
case refl.intro.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
m_lt_n : m < Nat.succ m
⊢ 0 < gp_succ_m.a / gp_succ_m.b
[PROOFSTEP]
have : 0 < gp_succ_m.a ∧ 0 < gp_succ_m.b := s_pos (lt_add_one <| m + 1) s_succ_mth_eq
[GOAL]
case refl.intro.intro
K : Type u_1
n : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ m → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ m) = convergents' g (Nat.succ m)
s_pos :
∀ {gp : Pair K} {m_1 : ℕ}, m_1 < Nat.succ (Nat.succ m) → Stream'.Seq.get? g.s m_1 = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ m)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ m)
this✝ : convergents g (Nat.succ m + 1) = convergents g' (Nat.succ m)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
gp_succ_m : Pair K
s_succ_mth_eq : Stream'.Seq.get? g.s (m + 1) = some gp_succ_m
gp_m : Pair K
mth_s_eq : Stream'.Seq.get? g.s m = some gp_m
m_lt_n : m < Nat.succ m
this : 0 < gp_succ_m.a ∧ 0 < gp_succ_m.b
⊢ 0 < gp_succ_m.a / gp_succ_m.b
[PROOFSTEP]
exact div_pos this.left this.right
[GOAL]
case step
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m n : ℕ
succ_m_lt_n : Nat.le (Nat.succ m) n
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ n) = convergents' g (Nat.succ n)
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ (Nat.succ n) → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ n)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n)
this : convergents g (Nat.succ n + 1) = convergents g' (Nat.succ n)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
⊢ 0 < gp'.a ∧ 0 < gp'.b
[PROOFSTEP]
refine' s_pos (Nat.lt.step <| Nat.lt.step succ_m_lt_n) _
[GOAL]
case step
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g : GeneralizedContinuedFraction K
gp' : Pair K
m n : ℕ
succ_m_lt_n : Nat.le (Nat.succ m) n
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g (Nat.succ n) = convergents' g (Nat.succ n)
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ (Nat.succ n) → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g (Nat.succ n)
not_terminated_at_n : ¬TerminatedAt g (Nat.succ n)
this : convergents g (Nat.succ n + 1) = convergents g' (Nat.succ n)
s_mth_eq' : Stream'.Seq.get? g'.s m = some gp'
⊢ Stream'.Seq.get? g.s m = some gp'
[PROOFSTEP]
exact Eq.trans (squashGCF_nth_of_lt succ_m_lt_n).symm s_mth_eq'
[GOAL]
case inr
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
⊢ convergents g (n + 1) = convergents g' n
[PROOFSTEP]
have : ∀ ⦃b⦄, g.partialDenominators.get? n = some b → b ≠ 0 :=
by
intro b nth_part_denom_eq
obtain ⟨gp, s_nth_eq, ⟨refl⟩⟩ : ∃ gp, g.s.get? n = some gp ∧ gp.b = b
exact exists_s_b_of_part_denom nth_part_denom_eq
exact (ne_of_lt (s_pos (lt_add_one n) s_nth_eq).right).symm
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
⊢ ∀ ⦃b : K⦄, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
[PROOFSTEP]
intro b nth_part_denom_eq
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators g) n = some b
⊢ b ≠ 0
[PROOFSTEP]
obtain ⟨gp, s_nth_eq, ⟨refl⟩⟩ : ∃ gp, g.s.get? n = some gp ∧ gp.b = b
[GOAL]
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
b : K
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators g) n = some b
⊢ ∃ gp, Stream'.Seq.get? g.s n = some gp ∧ gp.b = b
case intro.intro.refl
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators g) n = some gp.b
⊢ gp.b ≠ 0
[PROOFSTEP]
exact exists_s_b_of_part_denom nth_part_denom_eq
[GOAL]
case intro.intro.refl
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
gp : Pair K
s_nth_eq : Stream'.Seq.get? g.s n = some gp
nth_part_denom_eq : Stream'.Seq.get? (partialDenominators g) n = some gp.b
⊢ gp.b ≠ 0
[PROOFSTEP]
exact (ne_of_lt (s_pos (lt_add_one n) s_nth_eq).right).symm
[GOAL]
case inr
K : Type u_1
n✝ : ℕ
g✝ : GeneralizedContinuedFraction K
s : Stream'.Seq (Pair K)
inst✝ : LinearOrderedField K
s_pos✝ : ∀ {gp : Pair K} {m : ℕ}, m < n✝ → Stream'.Seq.get? g✝.s m = some gp → 0 < gp.a ∧ 0 < gp.b
n : ℕ
IH :
∀ {g : GeneralizedContinuedFraction K},
(∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b) →
convergents g n = convergents' g n
g : GeneralizedContinuedFraction K
s_pos : ∀ {gp : Pair K} {m : ℕ}, m < Nat.succ n → Stream'.Seq.get? g.s m = some gp → 0 < gp.a ∧ 0 < gp.b
g' : GeneralizedContinuedFraction K := squashGCF g n
not_terminated_at_n : ¬TerminatedAt g n
this : ∀ ⦃b : K⦄, Stream'.Seq.get? (partialDenominators g) n = some b → b ≠ 0
⊢ convergents g (n + 1) = convergents g' n
[PROOFSTEP]
exact succ_nth_convergent_eq_squashGCF_nth_convergent @this
[GOAL]
K : Type u_1
n : ℕ
inst✝ : LinearOrderedField K
c : ContinuedFraction K
⊢ convergents ↑↑c = convergents' ↑↑c
[PROOFSTEP]
ext n
[GOAL]
case a
K : Type u_1
n✝ : ℕ
inst✝ : LinearOrderedField K
c : ContinuedFraction K
n : ℕ
⊢ Stream'.nth (convergents ↑↑c) n = Stream'.nth (convergents' ↑↑c) n
[PROOFSTEP]
apply convergents_eq_convergents'
[GOAL]
case a.s_pos
K : Type u_1
n✝ : ℕ
inst✝ : LinearOrderedField K
c : ContinuedFraction K
n : ℕ
⊢ ∀ {gp : Pair K} {m : ℕ}, m < n → Stream'.Seq.get? (↑↑c).s m = some gp → 0 < gp.a ∧ 0 < gp.b
[PROOFSTEP]
intro gp m _ s_nth_eq
[GOAL]
case a.s_pos
K : Type u_1
n✝ : ℕ
inst✝ : LinearOrderedField K
c : ContinuedFraction K
n : ℕ
gp : Pair K
m : ℕ
a✝ : m < n
s_nth_eq : Stream'.Seq.get? (↑↑c).s m = some gp
⊢ 0 < gp.a ∧ 0 < gp.b
[PROOFSTEP]
exact
⟨zero_lt_one.trans_le ((c : SimpleContinuedFraction K).property m gp.a (part_num_eq_s_a s_nth_eq)).symm.le,
c.property m gp.b <| part_denom_eq_s_b s_nth_eq⟩
|
[GOAL]
R : Type u_1
A : Type u_2
B : Type u_3
σ : Type u_4
inst✝⁶ : CommSemiring R
inst✝⁵ : CommSemiring A
inst✝⁴ : CommSemiring B
inst✝³ : Algebra R A
inst✝² : Algebra A B
inst✝¹ : Algebra R B
inst✝ : IsScalarTower R A B
x : σ → B
p : MvPolynomial σ R
⊢ ↑(aeval x) (↑(map (algebraMap R A)) p) = ↑(aeval x) p
[PROOFSTEP]
rw [aeval_def, aeval_def, eval₂_map, IsScalarTower.algebraMap_eq R A B]
[GOAL]
R : Type u_1
A : Type u_2
B : Type u_3
σ : Type u_4
inst✝⁶ : CommSemiring R
inst✝⁵ : CommSemiring A
inst✝⁴ : CommSemiring B
inst✝³ : Algebra R A
inst✝² : Algebra A B
inst✝¹ : Algebra R B
inst✝ : IsScalarTower R A B
x : σ → A
p : MvPolynomial σ R
⊢ ↑(aeval (↑(algebraMap A B) ∘ x)) p = ↑(algebraMap A B) (↑(aeval x) p)
[PROOFSTEP]
rw [aeval_def, aeval_def, ← coe_eval₂Hom, ← coe_eval₂Hom, map_eval₂Hom, ← IsScalarTower.algebraMap_eq]
-- Porting note: added
[GOAL]
R : Type u_1
A : Type u_2
B : Type u_3
σ : Type u_4
inst✝⁶ : CommSemiring R
inst✝⁵ : CommSemiring A
inst✝⁴ : CommSemiring B
inst✝³ : Algebra R A
inst✝² : Algebra A B
inst✝¹ : Algebra R B
inst✝ : IsScalarTower R A B
x : σ → A
p : MvPolynomial σ R
⊢ ↑(eval₂Hom (algebraMap R B) (↑(algebraMap A B) ∘ x)) p =
↑(eval₂Hom (algebraMap R B) fun i => ↑(algebraMap A B) (x i)) p
[PROOFSTEP]
simp only [Function.comp]
[GOAL]
R : Type u_1
A : Type u_2
B : Type u_3
σ : Type u_4
inst✝⁸ : CommSemiring R
inst✝⁷ : CommSemiring A
inst✝⁶ : CommSemiring B
inst✝⁵ : Algebra R A
inst✝⁴ : Algebra A B
inst✝³ : Algebra R B
inst✝² : IsScalarTower R A B
inst✝¹ : NoZeroSMulDivisors A B
inst✝ : Nontrivial B
x : σ → A
p : MvPolynomial σ R
⊢ ↑(aeval (↑(algebraMap A B) ∘ x)) p = 0 ↔ ↑(aeval x) p = 0
[PROOFSTEP]
rw [aeval_algebraMap_apply, Algebra.algebraMap_eq_smul_one, smul_eq_zero, iff_false_intro (one_ne_zero' B),
or_false_iff]
[GOAL]
R : Type u_1
A : Type u_2
B : Type u_3
σ : Type u_4
inst✝⁶ : CommSemiring R
inst✝⁵ : CommSemiring A
inst✝⁴ : CommSemiring B
inst✝³ : Algebra R A
inst✝² : Algebra A B
inst✝¹ : Algebra R B
inst✝ : IsScalarTower R A B
x : σ → A
p : MvPolynomial σ R
h : Function.Injective ↑(algebraMap A B)
⊢ ↑(aeval (↑(algebraMap A B) ∘ x)) p = 0 ↔ ↑(aeval x) p = 0
[PROOFSTEP]
rw [aeval_algebraMap_apply, ← (algebraMap A B).map_zero, h.eq_iff]
[GOAL]
R : Type u_1
A : Type u_2
B : Type u_3
σ : Type u_4
inst✝² : CommSemiring R
inst✝¹ : CommSemiring A
inst✝ : Algebra R A
S : Subalgebra R A
x : σ → { x // x ∈ S }
p : MvPolynomial σ R
⊢ ↑(aeval fun i => ↑(x i)) p = ↑(↑(aeval x) p)
[PROOFSTEP]
convert aeval_algebraMap_apply A x p
|
PROGRAM mean_entropy
IMPLICIT NONE
INTEGER (KIND=8),PARAMETER::n=5
INTEGER (KIND=8):: i
REAL (KIND=8):: Ra_av,Rb_av,Rd_av,Kad,Kab
REAL (KIND=8):: Ra_dev,Rb_dev,Rd_dev
REAL (KIND=8),DIMENSION(n):: Ra,Rb,Rd
!!!=======================================================================================
!!!=======================================================================================
OPEN(unit=11,file='entropy.dat')
OPEN(unit=12,file='entropy_av.dat')
OPEN(unit=13,file='S_av.dat')
!!! Tinh gia tri trung binh
Ra_av=0. ; Rb_av=0. ; Rd_av=0.
DO i=1,n
READ(11,*)Kad,Kab,Ra(i),Rb(i),Rd(i)
Ra_av=Ra_av+Ra(i)
Rb_av=Rb_av+Rb(i)
Rd_av=Rd_av+Rd(i)
END DO
Ra_av=Ra_av/n ; Rb_av=Rb_av/n ; Rd_av=Rd_av/n
!!! Tinh standard deviation
Ra_dev=0.
DO i=1,n
Ra_dev=Ra_dev+(Ra(i)-Ra_av)**2.
END DO
Ra_dev=sqrt(Ra_dev/n)
Rb_dev=0.
DO i=1,n
Rb_dev=Rb_dev+(Rb(i)-Rb_av)**2.
END DO
Rb_dev=sqrt(Rb_dev/n)
Rd_dev=0.
DO i=1,n
Rd_dev=Rd_dev+(Rd(i)-Rd_av)**2.
END DO
Rd_dev=sqrt(Rd_dev/n)
WRITE(12,*)Kad,Kab,Ra_av,Rb_av,Rd_av
WRITE(13,*)Ra_av,Ra_dev,Rb_av,Rb_dev,Rd_av,Rd_dev
CLOSE(11)
CLOSE(12)
CLOSE(13)
END PROGRAM mean_entropy
|
Streak, and Toshiba's Journe Touch.
thing is there. It works wonderfully."
day they went on sale.
"I love that little toy."
toy, however, became much more.
"I am able to get my email on the iPad.
attachments in full and living color,"
phone, but that's all I use it for now.
AccountingWEB Assistant Managing Editor Bill Grabarek reports. |
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Lib
( someFunc
) where
import Data.Functor.Foldable
import Data.Functor.Foldable.TH
import Data.List (intercalate, partition, foldl1', foldl', sort, sortOn)
import Data.Sparse.SpMatrix
import Data.Sparse.SpVector
import Numeric.LinearAlgebra.Sparse
a' :: SpMatrix Double
a' = fromListDenseSM 2 [ 1, 3
, 1, 1]
b' :: SpVector Double
b' = mkSpVR 2 [1, 3]
data Exp a = Add [Exp a]
| Mul [Exp a]
| Lit a
| Var Char
deriving (Show, Eq, Ord)
instance (Num a) => Num (Exp a) where
negate x = (Lit (-1) * x)
(+) x y = Add [x, y]
(*) x y = Mul [x, y]
fromInteger = Lit . fromInteger
abs = id
signum = id
makeBaseFunctor ''Exp
simp :: (Num a, Ord a) => Exp a -> Exp a
simp e = cata order . cata dist . cata flatten $ e
where flatten (MulF as) = let (ms, bs) = partition isMul as
in Mul $ concat [ms' | (Mul ms') <- ms ] ++ bs
flatten (AddF as) = let (ms, bs) = partition isAdd as
in Add $ concat [ms' | (Add ms') <- ms ] ++ bs
flatten x = embed x
dist (MulF as) = foldl1' (\l r -> Add $ (\l' r' -> flatten $ MulF [l', r']) <$> unAdd l <*> unAdd r) as
dist (AddF as) = flatten (AddF as)
dist x = embed x
order (MulF as) = let (ls, ns) = partition isLit as
in Mul $ sort ((Lit $ product [ x | (Lit x) <- ls]) : ns)
order (AddF as) = let adds = sortOn (filter (not . isLit) . unMul) as
x = foldl' (\((pl:pns):ps) (al:ans) -> if pns == ans then ((addLit pl al):pns):ps else (al:ans):(pl:pns):ps) [(unMul . head $ adds)] (unMul <$> tail adds)
in Add (Mul <$> x)
order x = embed x
unAdd (Add as) = as
unAdd x = [x]
unMul (Mul as) = as
unMul x = [x]
isMul (Mul _) = True
isMul _ = False
isAdd (Add _) = True
isAdd _ = False
isLit (Lit _) = True
isLit _ = False
addLit (Lit l) (Lit r) = Lit (l + r)
p :: (Show a) => [Exp a] -> String
p es = intercalate "\n" (pretty <$> es)
pretty :: (Show a) => Exp a -> String
pretty (Add as) = intercalate " + " (pretty <$> as)
pretty (Mul ms) = concat $ (\m -> case m of
Add _ -> "(" ++ pretty m ++ ")"
_ -> pretty m) <$> ms
pretty (Var c) = [c]
pretty (Lit a) = show a
a = Var 'a'
b = Var 'b'
c = Var 'c'
d = Var 'd'
e = Var 'e'
f = Var 'f'
test = (a + 1)^5
someFunc :: IO ()
someFunc = do
putStrLn (show test)
|
If $f$ is in $l F (g)$, and $c > 0$, then eventually $R(|f(x)|) \leq c |g(x)|$. |
[STATEMENT]
lemma Sample_L_buffer:
assumes
"Sample_L req dt a1 stop lose (fin_inf_append [init_state] st)
(fin_inf_append [[]] buffer)
ack i1 vc st buffer"
shows "buffer t = inf_last_ti dt t"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. buffer t = inf_last_ti dt t
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. buffer t = inf_last_ti dt t
[PROOF STEP]
from assms
[PROOF STATE]
proof (chain)
picking this:
Sample_L req dt a1 stop lose (fin_inf_append [init_state] st) (fin_inf_append [[]] buffer) ack i1 vc st buffer
[PROOF STEP]
have
"\<forall>t. buffer t =
(if dt t = [] then fin_inf_append [[]] buffer t else dt t)"
[PROOF STATE]
proof (prove)
using this:
Sample_L req dt a1 stop lose (fin_inf_append [init_state] st) (fin_inf_append [[]] buffer) ack i1 vc st buffer
goal (1 subgoal):
1. \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
[PROOF STEP]
by (simp add: Sample_L_def)
[PROOF STATE]
proof (state)
this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
goal (1 subgoal):
1. buffer t = inf_last_ti dt t
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
goal (1 subgoal):
1. buffer t = inf_last_ti dt t
[PROOF STEP]
proof (induct t)
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer 0 = inf_last_ti dt 0
2. \<And>t. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
goal (2 subgoals):
1. \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer 0 = inf_last_ti dt 0
2. \<And>t. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
goal (1 subgoal):
1. buffer 0 = inf_last_ti dt 0
[PROOF STEP]
by (simp add: fin_inf_append_def)
[PROOF STATE]
proof (state)
this:
buffer 0 = inf_last_ti dt 0
goal (1 subgoal):
1. \<And>t. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<And>t. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
fix t
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<And>t. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
case (Suc t)
[PROOF STATE]
proof (state)
this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
goal (1 subgoal):
1. \<And>t. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
goal (1 subgoal):
1. buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
proof (cases "dt t = []")
[PROOF STATE]
proof (state)
goal (2 subgoals):
1. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t); dt t = []\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
2. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t); dt t \<noteq> []\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
assume "dt t = []"
[PROOF STATE]
proof (state)
this:
dt t = []
goal (2 subgoals):
1. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t); dt t = []\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
2. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t); dt t \<noteq> []\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
from this and Suc
[PROOF STATE]
proof (chain)
picking this:
dt t = []
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
dt t = []
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
goal (1 subgoal):
1. buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
by (simp add: correct_fin_inf_append1)
[PROOF STATE]
proof (state)
this:
buffer (Suc t) = inf_last_ti dt (Suc t)
goal (1 subgoal):
1. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t); dt t \<noteq> []\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
1. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t); dt t \<noteq> []\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
assume "dt t \<noteq> []"
[PROOF STATE]
proof (state)
this:
dt t \<noteq> []
goal (1 subgoal):
1. \<lbrakk>\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t; \<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t); dt t \<noteq> []\<rbrakk> \<Longrightarrow> buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
from this and Suc
[PROOF STATE]
proof (chain)
picking this:
dt t \<noteq> []
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
dt t \<noteq> []
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t) \<Longrightarrow> buffer t = inf_last_ti dt t
\<forall>t. buffer t = (if dt t = [] then fin_inf_append [[]] buffer t else dt t)
goal (1 subgoal):
1. buffer (Suc t) = inf_last_ti dt (Suc t)
[PROOF STEP]
by (simp add: correct_fin_inf_append1)
[PROOF STATE]
proof (state)
this:
buffer (Suc t) = inf_last_ti dt (Suc t)
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
buffer (Suc t) = inf_last_ti dt (Suc t)
goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
buffer t = inf_last_ti dt t
goal:
No subgoals!
[PROOF STEP]
qed |
import algebra.group_power tactic.norm_num algebra.big_operators
theorem Q2 (n : ℕ) : n ≥ 2 → nat.pow 4 n > nat.pow 3 n + nat.pow 2 n :=
begin
intro H_n_ge_2,
cases n with n1,
exfalso,revert H_n_ge_2, exact dec_trivial,
cases n1 with n2,
exfalso,revert H_n_ge_2, exact dec_trivial,
clear H_n_ge_2,
induction n2 with d Hd,
exact dec_trivial,
let e := nat.succ (nat.succ d),
show nat.pow 4 e*4>nat.pow 3 e*3+nat.pow 2 e*2,
change nat.pow 4 (nat.succ (nat.succ d)) > nat.pow 3 (nat.succ (nat.succ d)) + nat.pow 2 (nat.succ (nat.succ d))
with nat.pow 4 e>nat.pow 3 e+nat.pow 2 e at Hd,
exact calc
nat.pow 4 e * 4 > (nat.pow 3 e + nat.pow 2 e) * 4 : mul_lt_mul_of_pos_right Hd (dec_trivial)
... = nat.pow 3 e*4+nat.pow 2 e*4 : add_mul _ _ _
... ≥ nat.pow 3 e*3+nat.pow 2 e*4 : add_le_add_right (nat.mul_le_mul_left _ (dec_trivial)) _
... ≥ nat.pow 3 e*3+nat.pow 2 e*2 : add_le_add_left (nat.mul_le_mul_left _ (dec_trivial)) _,
end
|
# Background
My washing machine broke. I discovered this as I had a pile of sopping wet clothes at the bottom.
And I had an idea.
My electric dryer still functions, and there was a spare bin in the corner.
# Experimental Protocol
I got the bin. As I pulled articles of clothing out of the washer, I wrung them out, collecting all the water runoff in the spare bin. I wrung each article as much as I thought reasonable, and the whole thing took about ten minutes.
After I wrung all the items and transferred them into the dryer, I weighed the bin (with water in it). Then, I dumped out as much water as I could and weighed the bin again.
# Research Questions
1. What's the approximate mass of water I wrung out?
2. If I wanted my clothes reasonably dry, how much energy did I save the dryer, given that I shunted off a bunch of water that it would no longer have to try to vaporize?
3. Given my electricity rate and the energy "savings" from wringing, how much money did I save?
4. What was my average power output for the time wringing?
5. Given the energy savings per time unit, would my time have been more profitable spent doing something else? That is, how much would I have to earn per unit time in order for the water wringing out to be a less profitable activity, and thus, have greater-than-zero opportunity cost?
# Assumptions
1. Because I lack a baseline, I'm assuming the water in the washer was about 60 degrees Fahrenheit, or about 16 degrees Centigrade
# Analysis
## What's the approximate mass of water I wrang out?
$$
\begin{equation}
\begin{split}
\Delta m & = W_{final} - W_{initial} \\
& = 1730\textrm{g} - 1130\textrm{g} \\
& = 600\textrm{g}
\end{split}
\end{equation}
$$
## How much energy did I save?
$$
\begin{equation}
\begin{split}
E_{saved} & = (\textrm{Energy to raise the water to 100 C}) + (\textrm{Energy to vaporize the water}) \\
& = m \times
\left(
\left(
\textrm{Specific heat of liquid water} \times \Delta T
\right)
+
\left(
\textrm{Specific heat of vaporization of water}
\right)
\right) \\
& = \left(
600 \mathrm{g}
\right)
\times
\left(
\left(
\frac{4.181 \mathrm{J}}{\mathrm{g} \times \mathrm{^\circ K}}
\times
\left(
100^{\circ} \mathrm{C} - 16^\circ \mathrm{C}
\right)
\right)
+
\left(
\frac{2230 \mathrm{J}}{\mathrm{g} \times \mathrm{^\circ K}}
\right)
\right)
\end{split}
\end{equation}
$$
```python
energy_savings = 600 * (
(4.181 * (100 - 16))
+
2230
)
print(energy_savings)
```
1548722.4000000001
## How much money did I save by wringing out my clothes
?? (you can start to figure it out now)
## What was my average power output?
What would you need to start figuring that out?
## What was the opportunity cost?
Or, how much would I have to earn at another equivalent activity to make wringing out clothes have a greater-than-zero opportunity cost in terms of electricity bill savings?
# Extra credit
What are some simplifications you can think of that the opportunity cost calculation is making? Here's one to get you started: running my dryer entails at least a little bit of wear and tear on the dryer, right? I mean, the thing can't run forever. So is the money in the opportunity cost *only* a function of how much I pay in electricity? What do you think? Argue your case.
```python
```
|
```python
def downloadDriveFile(file_id,file_name,file_extension):
'''
Allows charge of public files into colab's workspace
'''
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id='$file_id -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id="$file_id -O "$file_name"."$file_extension" && rm -rf /tmp/cookies.txt
if 'google.colab' in str(get_ipython()):
downloadDriveFile('1KkHZjTDShCz0uBEHWAZ9xx98F6ENMvrq','optimize','py')
```
```python
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
import optimize
```
Steepest Descent Method
=========
Example 1
----
Find the minimizer of $f(\mathbf{x}) = x_1^{e−(x_1^2 + x_2^2)}$.
```python
x = sp.symbols('x1 x2')
func = x[0]*sp.exp(-x[0]**2 - x[1]**2)
x0 = [-1, 1]
min, search_steps = optimize.steepest_descent(func, x, start=x0, full_output=True)
min_fix, search_steps_fix = optimize.steepest_descent(func, x, start=x0, step_type='fix', step=0.25, full_output=True)
```
# Sección nueva
```python
fig = plt.figure()
step = 0.01
x_vals = np.arange(-1.6, 0, step)
y_vals = np.arange(-1.6, 1.6, step)
X, Y = np.meshgrid(x_vals, y_vals)
function = sp.lambdify([*x], func, modules='numpy')
func_eval = function(X,Y)
ax1 = fig.add_subplot(1,2,1)
ax1.contour(X, Y, func_eval)
ax1.plot(search_steps[:, 0],search_steps[:, 1],'-k.', linewidth='0.8', markersize=6)
ax1.set_xlabel('$x_1$')
ax1.set_ylabel('$x_2$')
ax2 = fig.add_subplot(1,2,2)
ax2.contour(X, Y, func_eval)
ax2.plot(search_steps_fix[:, 0],search_steps_fix[:, 1],'-k.', linewidth='0.8' , markersize=6)
ax2.set_xlabel('$x_1$')
ax2.set_ylabel('$x_2$')
fig_dpi = 150
fig_width = 18.8/2.54
fig_height = 9.4/2.54
fig.dpi=fig_dpi
fig.set_size_inches((fig_width,fig_height))
fig.tight_layout()
plt.show()
```
Example 2
----
Find the minimizer of $f(\mathbf{x}) = 0.06e^{(2x_1+x_2)} + 0.05e^{(x_1-2x_2)} + e^{-x_1}$.
```python
x = sp.symbols('x1 x2')
func = 0.06*sp.exp(2*x[0]+x[1]) + 0.05*sp.exp(x[0]-2*x[1]) + sp.exp(-x[0])
x0 = [-0.5, 2]
min, search_steps = optimize.steepest_descent(func, x, start=x0, full_output=True)
min_fix, search_steps_fix = optimize.steepest_descent(func, x, start=x0, step_type='fix', step=0.25, full_output=True)
```
```python
fig = plt.figure()
step = 0.001
x_vals = np.arange(-1, 1.75, step)
y_vals = np.arange(-2, 3.5, step)
X, Y = np.meshgrid(x_vals, y_vals)
function = sp.lambdify([*x], func, modules='numpy')
func_eval = function(X,Y)
ax1 = fig.add_subplot(1,2,1)
ax1.contour(X, Y, func_eval)
ax1.plot(search_steps[:, 0],search_steps[:, 1],'-k.', linewidth='0.8', markersize=6)
ax1.set_xlabel('$x_1$')
ax1.set_ylabel('$x_2$')
ax2 = fig.add_subplot(1,2,2)
ax2.contour(X, Y, func_eval)
ax2.plot(search_steps_fix[:, 0],search_steps_fix[:, 1],'-k.', linewidth='0.8' , markersize=6)
ax2.set_xlabel('$x_1$')
ax2.set_ylabel('$x_2$')
fig_dpi = 150
fig_width = 18.8/2.54
fig_height = 9.4/2.54
fig.dpi=fig_dpi
fig.set_size_inches((fig_width,fig_height))
fig.tight_layout()
plt.show()
```
```python
```
|
submodule (ionization) glow_dummy
implicit none (type, external)
contains
module procedure glow_run
! these parameters are never used due to error stop.
! They just stop lint output for stringent compiler warning flags
ionrate = 0.
eheating = 0.
iver = 0.
error stop 'There appears to be a misconfiguration in your build'
end procedure glow_run
end submodule glow_dummy
|
Require Import Arith Metatheory.
Require Import LibTactics LambdaES_Tac.
Require Import LambdaES_Defs LambdaES_FV LambdaES_Infra.
Require Import Rewriting_Defs Rewriting_Lib.
Require Export Morphisms.
Instance iff_eq : Equivalence iff.
Proof.
split; intros_all.
split; trivial.
split; apply H.
split. intro H1. apply H0. apply H; trivial.
intro H1. apply H. apply H0; trivial.
Qed.
(** =e definition *)
Inductive eqc : pterm -> pterm -> Prop :=
| eqc_rf: forall u, eqc u u
| eqc_rx: forall t u v,
term u -> term v -> eqc (t[u][v]) ((& t)[v][u])
.
Lemma eqc_sym : forall t u, eqc t u -> eqc u t.
Proof.
intros t u H. destruct H.
apply eqc_rf. replace (t[u][v]) with ((& (& t))[u][v]).
apply eqc_rx; trivial.
unfold bswap. rewrite bswap_rec_id. trivial.
Qed.
Lemma eqc_trans: forall t u v, eqc t u -> eqc u v -> eqc t v.
Proof.
intros t u v H1 H2.
destruct H1. trivial. inversion H2.
apply eqc_rx; trivial. unfold bswap.
rewrite bswap_rec_id. apply eqc_rf.
Qed.
Instance eqc_eq : Equivalence eqc.
Proof.
split; intros_all.
apply eqc_rf.
apply eqc_sym; trivial.
generalize H H0. apply eqc_trans.
Qed.
(***)
Definition eqC (t : pterm) (u : pterm) := trans_closure (p_contextual_closure eqc) t u.
Notation "t =e u" := (eqC t u) (at level 66).
(** =e as equivalence relation *)
Lemma eqC_rf : forall t, t =e t.
Proof.
intro t.
apply one_step_reduction.
apply p_redex. reflexivity.
Qed.
Lemma pctx_eqc_sym : forall t u, (p_contextual_closure eqc t u) -> p_contextual_closure eqc u t.
Proof.
intros t u H. induction H.
apply p_redex. rewrite H. reflexivity.
apply p_app; trivial.
apply p_abs_in with (L:=L); trivial.
apply p_subst with (L:=L); trivial.
Qed.
Lemma eqC_sym : forall t u, t =e u -> u =e t.
Proof.
intros t u H. induction H.
apply one_step_reduction. apply pctx_eqc_sym; trivial.
apply transitive_closure_composition with (u := u); trivial.
apply one_step_reduction. apply pctx_eqc_sym; trivial.
Qed.
Lemma eqC_trans : forall t u v, t =e u -> u =e v -> t =e v.
Proof.
intros t u v H H'.
apply transitive_closure_composition with (u := u); trivial.
Qed.
Instance eqC_eq : Equivalence eqC.
Proof.
split; intros_all.
apply eqC_rf.
apply eqC_sym; trivial.
apply eqC_trans with (u := y); trivial.
Qed.
(*** =e inversion ***)
Lemma eqc_fvar_term : forall x t, eqc (pterm_fvar x) t -> pterm_fvar x = t.
Proof.
intros x t H. inversion H. trivial.
Qed.
Lemma eqc_app_term : forall t u v, eqc (pterm_app u v) t -> pterm_app u v = t.
Proof.
intros t u v H.
inversion H. trivial.
Qed.
Lemma eqc_abs_term : forall t t', eqc (pterm_abs t) t' -> pterm_abs t = t' .
Proof.
intros t t' H. inversion H. trivial.
Qed.
Lemma eqc_sub_term : forall t u t0, eqc (t[u]) t0 ->
(t[u] = t0 \/ exists t', exists v, term u /\ term v /\ t'[v] = t /\ (& t')[u][v] = t0) .
Proof.
intros t u t0 H. inversion H.
left; trivial. right. exists t1 u0.
split; trivial. split; trivial. split; trivial.
Qed.
(****)
Lemma pctx_eqc_fvar_term : forall x t, p_contextual_closure eqc (pterm_fvar x) t -> pterm_fvar x = t.
Proof.
intros x t H. inversion H. inversion H0; trivial.
Qed.
Lemma pctx_eqc_app_term : forall t u v, p_contextual_closure eqc (pterm_app u v) t ->
exists u', exists v', pterm_app u' v' = t /\ p_contextual_closure eqc u' u /\ p_contextual_closure eqc v' v.
Proof.
intros t u v H. inversion H.
exists u v. split; trivial. inversion H0; trivial.
split; apply p_redex; reflexivity.
exists t' u'. split; trivial.
split; apply pctx_eqc_sym; trivial.
Qed.
Lemma pctx_eqc_abs_term : forall t t', p_contextual_closure eqc (pterm_abs t) t' ->
exists u, exists L, pterm_abs u = t' /\ (forall x, x \notin L -> p_contextual_closure eqc (u ^ x) (t ^ x)).
Proof.
intros t t' H. inversion H.
exists t {}. split; trivial. inversion H0; trivial.
intros x H'. apply p_redex. reflexivity.
exists t'0 L. split; trivial. intros.
apply pctx_eqc_sym. apply H1. trivial.
Qed.
(**)
Lemma pctx_eqc_sub_term : forall t u t0, p_contextual_closure eqc (t[u]) t0 -> exists t', exists u', t'[u'] = t0 .
Proof.
intros t u t0 H. inversion H. inversion H0.
exists t u; trivial.
exists (& t2 [u]) u0; trivial.
exists t' u'; trivial.
Qed.
(**)
(****)
Lemma eqC_fvar_term : forall x t, pterm_fvar x =e t -> pterm_fvar x = t.
Proof.
intros x t H. gen_eq t0 : (pterm_fvar x). induction H.
intro H'. rewrite H' in *|-*. apply pctx_eqc_fvar_term; trivial.
intro H'. rewrite H' in *|-*. rewrite <- IHtrans_closure.
apply pctx_eqc_fvar_term; trivial.
apply pctx_eqc_fvar_term in H. rewrite H; trivial.
Qed.
Lemma eqC_app_term : forall t u v, pterm_app u v =e t ->
exists u', exists v', pterm_app u' v' = t /\ u' =e u /\ v' =e v.
Proof.
intros t u v H. gen_eq t0 : (pterm_app u v). generalize u v. clear u v. induction H.
intros u0 v0 H'. rewrite H' in *|-*. apply pctx_eqc_app_term in H.
case H; clear H; intros u' H. case H; clear H; intros v' H. destruct H. destruct H0.
exists u' v'. split; trivial. split; apply one_step_reduction; trivial.
intros u0 v0 H'. rewrite H' in H. apply pctx_eqc_app_term in H.
case H; clear H; intros u1 H. case H; clear H; intros v1 H. destruct H. destruct H1.
case (IHtrans_closure u1 v1). rewrite H; trivial. intros u2 H3.
case H3; clear H3; intros v2 H3. destruct H3. destruct H4.
exists u2 v2. split; trivial.
split; try rewrite H4; try rewrite H5; apply one_step_reduction; trivial.
Qed.
Lemma eqC_abs_term : forall t t', pterm_abs t =e t' ->
exists u, exists L, pterm_abs u = t' /\ (forall x, x \notin L -> (u ^ x) =e (t ^ x)).
Proof.
intros t t' H. gen_eq t0 : (pterm_abs t). generalize t; clear t. induction H.
intros t' H'. rewrite H' in H. apply pctx_eqc_abs_term in H.
case H; clear H; intros u0 H. case H; clear H; intros L H. destruct H.
exists u0 L. split; trivial. intros x Fr. apply one_step_reduction. apply H0; trivial.
intros t0 H'. rewrite H' in H. apply pctx_eqc_abs_term in H.
case H; clear H; intros u0 H. case H; clear H; intros L H. destruct H.
case (IHtrans_closure u0). rewrite H; trivial. intros t1 H2.
case H2; clear H2; intros L' H2. destruct H2. exists t1 (L \u L').
split; trivial. intros x Fr. apply notin_union in Fr. destruct Fr.
rewrite (H3 x); trivial. apply one_step_reduction. apply H1; trivial.
Qed.
(***)
Lemma eqC_sub_term : forall t u t0, t[u] =e t0 -> exists t', exists u', t'[u'] = t0 .
Proof.
intros t u v H. gen_eq t0 : (t [u]). generalize t u; clear t u. induction H.
intros t' u' H'. rewrite H' in H. apply pctx_eqc_sub_term in H; trivial.
intros t' u' H'. rewrite H' in H. apply pctx_eqc_sub_term in H.
case H; clear H; intros t0 H. case H; clear H; intros u0 H.
case (IHtrans_closure t0 u0). rewrite H; trivial. intros t1 H1.
case H1; clear H1; intros u1 H1. exists t1 u1; trivial.
Qed.
Lemma eqC_redex : forall t u v, term u -> term v -> (t[u][v]) =e ((& t)[v][u]) .
Proof.
intros t u v Tu Tv. apply one_step_reduction. apply p_redex. apply eqc_rx; trivial.
Qed.
Definition red_ctx_mod_eqC (R: pterm -> pterm -> Prop) (t: pterm) (u : pterm) :=
exists t', exists u', (t =e t')/\(contextual_closure R t' u')/\(u' =e u).
(* ********************************************************************** *)
(** =e Properties *)
Lemma lc_at_eqc : forall n t u, eqc t u -> (lc_at n t <-> lc_at n u).
Proof.
intros n t u H. destruct H; split; simpl; trivial.
intro H1. split. split.
unfold bswap. apply lc_at_bswap; try omega; trivial. apply H1.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial. intro H1.
replace t with (& & t). split. split.
apply lc_at_bswap; try omega; trivial. apply H1.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial.
rewrite bswap_rec_id with (n := 0); reflexivity.
Qed.
Lemma lc_at_pctx_eqc : forall n t u, (p_contextual_closure eqc) t u -> (lc_at n t <-> lc_at n u).
Proof.
intros n t u H. generalize n; clear n.
induction H; simpl. intro n. apply lc_at_eqc; trivial.
split; intro H1. destruct H1. split.
apply IHp_contextual_closure1; trivial.
apply IHp_contextual_closure2; trivial.
destruct H1. split.
apply IHp_contextual_closure1; trivial.
apply IHp_contextual_closure2; trivial.
case var_fresh with (L := L). intros x Fr. intro n.
assert (Q : forall t, lc_at (S n) (t ^ x) <-> lc_at (S n) t).
intro t1. apply lc_at_open'; try omega; trivial.
split. intro H1. apply Q. apply H0; trivial. apply Q; trivial.
intro H2. apply Q. apply H0; trivial. apply Q; trivial.
case var_fresh with (L := L). intros x Fr. intro n.
assert (Q : forall t, lc_at (S n) (t ^ x) <-> lc_at (S n) t).
intro t1. apply lc_at_open'; try omega; trivial.
split. intro H3. destruct H3. split.
apply Q. apply H0; trivial. apply Q; trivial.
apply IHp_contextual_closure; trivial.
intro H2. destruct H2. split.
apply Q. apply H0; trivial. apply Q; trivial.
apply IHp_contextual_closure; trivial.
Qed.
Lemma lc_at_eqC : forall n t t', t =e t' -> (lc_at n t <-> lc_at n t').
Proof.
intros n t t' H. generalize n; clear n.
induction H. intro n. apply lc_at_pctx_eqc; trivial.
intro n. apply (lc_at_pctx_eqc n) in H. rewrite H.
apply IHtrans_closure.
Qed.
Lemma red_regular'_eqc : red_regular' eqc.
Proof.
unfold red_regular'. intros t0 t1 H'. rewrite term_eq_term'. rewrite term_eq_term'.
unfold term'. apply lc_at_eqc; trivial.
Qed.
Lemma pctx_eqc_fv : forall x t u, (p_contextual_closure eqc) t u -> (x \in (fv t) <-> x \in (fv u)).
Proof.
intros x t u H. induction H. induction H.
split; trivial. simpl. split.
intro H1. apply in_union in H1. case H1; clear H1.
intro H1. apply in_union in H1. case H1; clear H1.
intro H1. apply in_union. left. apply in_union.
left. unfold bswap. rewrite fv_bswap_rec; trivial.
intro H1. apply in_union. right. trivial.
intro H1. apply in_union. left. apply in_union. right. trivial.
intro H1. apply in_union in H1. case H1; clear H1.
intro H1. apply in_union in H1. case H1; clear H1.
intro H1. apply in_union. left. apply in_union.
left. unfold bswap in H1. rewrite fv_bswap_rec in H1; trivial.
intro H1. apply in_union. right. trivial.
intro H1. apply in_union. left. apply in_union. right; trivial.
simpl. split.
intro H1. apply in_union in H1. case H1; clear H1.
intro H1. apply in_union. left. apply IHp_contextual_closure1; trivial.
intro H1. apply in_union. right; trivial. apply IHp_contextual_closure2; trivial.
intro H1. apply in_union in H1. case H1; clear H1.
intro H1. apply in_union. left. apply IHp_contextual_closure1; trivial.
intro H1. apply in_union. right; trivial. apply IHp_contextual_closure2; trivial.
simpl. pick_fresh z. apply notin_union in Fr. case Fr; clear Fr.
intros H1 H2. apply notin_union in H1. case H1; clear H1. intros H1 H3.
apply notin_union in H1. case H1; clear H1. intros H1 H4.
apply notin_singleton in H4.
assert (Q: (x \in fv (t ^ z) <-> x \in fv t)).
unfold open. apply fv_open_. intro.
apply H4. apply symmetry; trivial.
assert (Q': (x \in fv (t' ^ z) <-> x \in fv t')).
unfold open. apply fv_open_. intro.
apply H4. apply symmetry; trivial.
split.
intro H5. apply Q'. apply H0; trivial. apply Q; trivial.
intro H5. apply Q. apply H0; trivial. apply Q'; trivial.
simpl. pick_fresh z. apply notin_union in Fr. case Fr; clear Fr.
intros H2 H3. apply notin_union in H2. case H2; clear H2.
intros H2 H4. apply notin_union in H2. case H2; clear H2.
intros H2 H5. apply notin_union in H2. case H2; clear H2.
intros H2 H6. apply notin_union in H2. case H2; clear H2.
intros H2 H7. apply notin_singleton in H7.
assert (Q: (x \in fv (t ^ z) <-> x \in fv t)).
unfold open. apply fv_open_. intro.
apply H7. apply symmetry; trivial.
assert (Q': (x \in fv (t' ^ z) <-> x \in fv t')).
unfold open. apply fv_open_. intro.
apply H7. apply symmetry; trivial.
split.
intro H8. apply in_union in H8. apply in_union. case H8; clear H8; intro H8.
left. apply Q'. apply H0; trivial. apply Q; trivial.
right. apply IHp_contextual_closure; trivial.
intro H8. apply in_union in H8. apply in_union. case H8; clear H8; intro H8.
left. apply Q. apply H0; trivial. apply Q'; trivial.
right. apply IHp_contextual_closure; trivial.
Qed.
Lemma eqC_fv : forall x t t', t =e t' -> ((x \in fv t) <-> (x \in fv t')).
Proof.
intros x t t' H. induction H.
apply pctx_eqc_fv; trivial.
apply (pctx_eqc_fv x) in H. rewrite H; trivial.
Qed.
Lemma red_regular_eqC : forall R, red_regular R ->
red_regular (red_ctx_mod_eqC R).
Proof.
intros R H. unfold red_regular. intros t t' H'.
unfold red_ctx_mod_eqC in H'. case H'; clear H'; intros t0 H'.
case H'; clear H'; intros u0 H'.
assert (Q : red_regular (contextual_closure R)).
apply red_regular_ctx; trivial.
unfold red_regular in Q.
assert (Q': term t0 /\ term u0).
apply Q. apply H'.
case H'; clear H'; intros H0 H1.
case H1; clear H1; intros H1 H2.
apply (lc_at_eqC 0) in H0. apply (lc_at_eqC 0) in H2.
rewrite term_eq_term'. rewrite term_eq_term'.
rewrite term_eq_term' in Q'. rewrite term_eq_term' in Q'.
unfold term'. split; [apply H0; apply Q' | apply H2; apply Q'].
Qed.
Lemma red_out_eqc : red_out eqc.
Proof.
intros x t t' u T H. destruct H; simpl. apply eqc_rf.
rewrite (subst_bswap_rec 0). apply eqc_rx.
apply subst_term; trivial.
apply subst_term; trivial.
rewrite <- term_eq_term'; trivial.
Qed.
Lemma red_out_pctx_eqc : red_out (p_contextual_closure eqc).
Proof.
apply red_out_pctx. apply red_out_eqc.
Qed.
Lemma red_out_pctx_eqc' : forall x t u u', term t -> term u ->
p_contextual_closure eqc u u' ->
p_contextual_closure eqc ([x ~> u]t) ([x ~> u']t).
Proof.
intros x t u u' Tt Tu H.
apply term_size_induction with (t := t); trivial; simpl.
intro z. case (z == x). intro; trivial. intro. apply p_redex. apply eqc_rf.
intros t1 B Ht1. apply p_abs_in with (L := {{x}} \u (fv t1)).
intros z Fr. apply notin_union in Fr. destruct Fr.
apply notin_singleton in H0.
rewrite subst_open_var; trivial.
rewrite subst_open_var; trivial.
apply Ht1; trivial. apply body_to_term; trivial.
apply (lc_at_pctx_eqc 0) in H.
rewrite <- term_eq_term' in H.
rewrite <- term_eq_term' in H. apply H; trivial.
intros t1 t2 Tt1 Ht1 Tt2 Ht2. apply p_app; trivial.
intros t1 t2 Tt2 Ht2 B Ht1.
apply p_subst with (L := {{x}} \u (fv t1)); trivial.
intros z Fr. apply notin_union in Fr. destruct Fr.
apply notin_singleton in H0.
rewrite subst_open_var; trivial.
rewrite subst_open_var; trivial.
apply Ht1; trivial. apply body_to_term; trivial.
apply (lc_at_pctx_eqc 0) in H.
rewrite <- term_eq_term' in H.
rewrite <- term_eq_term' in H.
apply H; trivial.
Qed.
Lemma red_out_eqC : red_out eqC.
Proof.
intros x u t' t T H. induction H.
apply one_step_reduction. apply red_out_pctx_eqc; trivial.
apply transitive_reduction with (u := [x ~> u]u0); trivial.
apply red_out_pctx_eqc; trivial.
Qed.
Lemma red_all_eqC : forall x t t' u u', term t -> term u ->
t =e t' -> u =e u' -> [x ~> u]t =e [x ~> u']t'.
Proof.
intros x t t' u u' Tt Tu H0 H1.
apply transitive_closure_composition with (u := [x ~> u]t').
clear H1 Tt. induction H0.
apply one_step_reduction. apply red_out_pctx_eqc; trivial.
apply transitive_reduction with (u := ([x ~> u]u0)); trivial.
apply red_out_pctx_eqc; trivial.
assert (term t').
apply (lc_at_eqC 0) in H0.
rewrite <- term_eq_term' in H0.
rewrite <- term_eq_term' in H0.
apply H0; trivial.
clear H0 Tt. induction H1.
apply one_step_reduction. apply red_out_pctx_eqc'; trivial.
apply transitive_reduction with (u := ([x ~> u]t')); trivial.
apply red_out_pctx_eqc'; trivial.
apply IHtrans_closure.
apply (lc_at_pctx_eqc 0) in H0.
rewrite <- term_eq_term' in H0.
rewrite <- term_eq_term' in H0.
apply H0; trivial.
Qed.
Lemma red_rename_pctx_eqc : red_rename (p_contextual_closure eqc).
Proof.
intros_all.
rewrite* (@subst_intro x t).
rewrite* (@subst_intro x t').
apply red_out_pctx_eqc; trivial.
Qed.
Lemma red_rename_eqC : red_rename eqC.
Proof.
intros_all.
rewrite* (@subst_intro x t).
rewrite* (@subst_intro x t').
apply red_out_eqC; trivial.
Qed.
Lemma red_out_mod_eqC : forall R, red_regular R -> red_out R ->
red_out (red_ctx_mod_eqC R).
Proof.
intros R H1 H2. unfold red_out. intros x t t' u T H3.
unfold red_ctx_mod_eqC in *|-*.
case H3; clear H3; intros t0 H3.
case H3; clear H3; intros u0 H3.
case H3; clear H3; intros H3 H4.
case H4; clear H4; intros H4 H5.
assert (Q: red_regular (contextual_closure R)).
apply red_regular_ctx; trivial.
assert (Q': red_out (contextual_closure R)).
apply red_out_ctx; trivial.
exists ([x ~> t]t0) ([x ~> t]u0). split.
apply red_out_eqC; try reflexivity; trivial.
split. apply Q'; trivial.
apply red_out_eqC; try reflexivity; trivial.
Qed.
Lemma red_not_fv_mod_eqC : forall R, red_not_fv R -> red_not_fv (red_ctx_mod_eqC R).
Proof.
intros. apply red_not_fv_ctx in H.
unfold red_not_fv in *|-*. intros.
unfold red_ctx_mod_eqC in H0.
case H0; clear H0; intros t0 H0.
case H0; clear H0; intros t1 H0.
case H0; clear H0; intros H2 H3.
case H3; clear H3; intros H3 H4.
apply (H x) in H3.
apply (eqC_fv x) in H4. intro H5.
assert (Q : x \in fv t1).
apply H4; trivial.
contradiction.
apply (eqC_fv x) in H2.
intro H5. assert (Q : x \in fv t).
apply H2; trivial.
contradiction.
Qed.
Lemma red_fv_mod_eqC : forall R, red_fv R -> red_fv (red_ctx_mod_eqC R).
Proof.
intros. apply red_fv_ctx in H.
unfold red_fv in *|-*. intros.
unfold red_ctx_mod_eqC in H0.
case H0; clear H0; intros t0 H0.
case H0; clear H0; intros t1 H0.
case H0; clear H0; intros H2 H3.
case H3; clear H3; intros H3 H4.
apply (eqC_fv x) in H2. apply H2.
apply H with (t' := t1); trivial.
apply (eqC_fv x) in H4.
apply H4; trivial.
Qed.
Lemma pctx_eqc_open : forall n t t' u, term u -> p_contextual_closure eqc t t' ->
p_contextual_closure eqc ({n ~> u}t) ({n ~> u}t').
Proof.
intros n t t' u Tu H. generalize n; clear n.
induction H. destruct H. intro n. apply p_redex. apply eqc_rf.
intro n. unfold open. simpl.
replace ({S (S n) ~> u}(& t)) with (& ({S (S n) ~> u}t)).
replace ({S n ~> u}v) with v. replace ({n ~> u}v) with v.
replace ({S n ~> u}u0) with u0. replace ({n ~> u}u0) with u0.
apply p_redex. apply eqc_rx; trivial.
rewrite open_lc_at; trivial.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial.
rewrite open_lc_at; trivial.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial.
rewrite open_lc_at; trivial.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial.
rewrite open_lc_at; trivial.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial.
unfold bswap. rewrite <- bswap_open_rec; try omega; trivial.
apply lc_at_weaken_ind with (k1 := 0); try omega.
rewrite <- term_eq_term'; trivial.
simpl; intro n. apply p_app; trivial.
simpl; intro n. apply p_abs_in with (L := (fv u) \u L).
intros x H2. apply notin_union in H2. case H2; clear H2.
intros H2 H3. unfold open in *|-*.
replace ({0 ~> pterm_fvar x}({S n ~> u}t))
with ({S n ~> u}({0 ~> pterm_fvar x}t)).
replace ({0 ~> pterm_fvar x}({S n ~> u}t'))
with ({S n ~> u}({0 ~> pterm_fvar x}t')).
apply H0; trivial.
rewrite subst_com; trivial. omega.
rewrite subst_com; trivial. omega.
simpl; intro n. apply p_subst with (L := (fv u) \u L); trivial.
intros x H2. apply notin_union in H2. case H2; clear H2.
intros H2 H3. unfold open in *|-*.
replace ({0 ~> pterm_fvar x}({S n ~> u}t))
with ({S n ~> u}({0 ~> pterm_fvar x}t)).
replace ({0 ~> pterm_fvar x}({S n ~> u}t'))
with ({S n ~> u}({0 ~> pterm_fvar x}t')).
apply H0; trivial.
rewrite subst_com; trivial. omega.
rewrite subst_com; trivial. omega.
Qed.
Lemma eqC_open : forall n t t' u, term u -> t =e t'-> (open_rec n u t) =e (open_rec n u t').
Proof.
intros n t t' u Tu H. induction H.
apply one_step_reduction. apply pctx_eqc_open; trivial.
apply transitive_reduction with (u := ({n ~> u}u0)); trivial.
apply pctx_eqc_open; trivial.
Qed.
Lemma eqC_open_var : forall (x:var) t1 t2 u, x \notin (fv t1) ->
x \notin (fv t2) -> term u -> (t1 ^ x =e t2 ^ x) -> ((t1^^u) =e (t2^^u)).
Proof.
intros x t1 t2 u H1 H2 T H3.
assert (Q : subst x u (t1 ^ x) =e subst x u (t2 ^ x)).
apply red_out_eqC; trivial.
rewrite subst_intro with (x := x); trivial.
rewrite subst_intro with (x := x) (t := t2); trivial.
Qed.
(* ********************************************************************** *)
(** =e Rewriting *)
Instance rw_eqC_red : forall R, Proper (eqC ==> eqC ==> iff) (red_ctx_mod_eqC R).
Proof.
intros_all. split. intro H1.
unfold red_ctx_mod_eqC in *|-*.
destruct H1. destruct H1. destruct H1. destruct H2.
exists x1. exists x2. split.
rewrite <- H; trivial. split; trivial.
rewrite <- H0; trivial. intro H1.
unfold red_ctx_mod_eqC in *|-*.
destruct H1. destruct H1. destruct H1. destruct H2.
exists x1. exists x2. split.
rewrite <- H1; trivial. split; trivial.
rewrite H3. rewrite H0.
reflexivity.
Qed.
Instance rw_eqC_trs : forall R, Proper (eqC ==> eqC ==> iff) (trans_closure (red_ctx_mod_eqC R)).
Proof.
intros_all. split. intro H'.
apply transitive_star_derivation'.
apply transitive_star_derivation' in H'.
case H'. clear H'. intro H1. left.
rewrite <- H. rewrite <- H0; trivial.
clear H'. intro H1. right. destruct H1.
destruct H1. destruct H2. destruct H2.
exists x1. split. rewrite <- H; trivial.
exists x2. split; trivial. rewrite <- H0; trivial.
intro H'.
apply transitive_star_derivation'.
apply transitive_star_derivation' in H'.
case H'. clear H'. intro H1. left.
rewrite H. rewrite H0; trivial.
clear H'. intro H1. right. destruct H1.
destruct H1. destruct H2. destruct H2.
exists x1. split. rewrite H; trivial.
exists x2. split; trivial. rewrite H0; trivial.
Qed.
Instance rw_eqC_lc_at : forall n, Proper (eqC ==> iff) (lc_at n).
Proof.
intros_all. apply lc_at_eqC; trivial.
Qed.
Instance rw_eqC_body : Proper (eqC ==> iff) body.
Proof.
intros_all. rewrite body_eq_body'. rewrite body_eq_body'.
unfold body'. rewrite H. reflexivity.
Qed.
Instance rw_eqC_term : Proper (eqC ==> iff) term.
Proof.
intros_all. rewrite term_eq_term'. rewrite term_eq_term'.
unfold term'. rewrite H. reflexivity.
Qed.
Instance rw_eqC_fv : Proper (eqC ==> VarSet.Equal) fv.
Proof.
intros_all. apply eqC_fv; trivial.
Qed.
Instance rw_eqC_app : Proper (eqC ++> eqC ++> eqC) pterm_app.
Proof.
intros_all. apply transitive_closure_composition with (u:=pterm_app y x0).
clear H0. induction H. apply one_step_reduction. apply p_app; trivial.
apply p_redex. apply eqc_rf. apply transitive_reduction with (u:=pterm_app u x0); trivial.
apply p_app; trivial. apply p_redex. apply eqc_rf.
clear H. induction H0. apply one_step_reduction. apply p_app; trivial.
apply p_redex. apply eqc_rf. apply transitive_reduction with (u:=pterm_app y u); trivial.
apply p_app; trivial. apply p_redex. apply eqc_rf.
Qed.
Instance rw_eqC_subst_right : forall t, Proper (eqC ++> eqC) (pterm_sub t).
Proof.
intros_all. induction H.
apply one_step_reduction. apply p_subst with (L := {}); trivial. intros.
apply p_redex. apply eqc_rf.
apply transitive_reduction with (u:= t[u]); trivial.
apply p_subst with (L := {}); trivial. intros.
apply p_redex. apply eqc_rf.
Qed.
Instance SN_ind_mod_eqC : forall n R, Proper (eqC ==> iff) (SN_ind n (red_ctx_mod_eqC R)).
Proof.
intros_all. split. intro H'.
apply SN_intro. intros z H''. inversion H'.
case (H0 z). rewrite H; trivial. intros k H1. destruct H1.
exists k; split; try omega; trivial. intro H'.
apply SN_intro. intros z H''. inversion H'.
case (H0 z). rewrite <- H; trivial. intros k H1. destruct H1.
exists k; split; try omega; trivial.
Qed.
Instance NF_mod_eqC : forall R, Proper (eqC ==> iff) (NF (red_ctx_mod_eqC R)).
Proof.
intros_all. split; intro H'.
intros t0 H0. rewrite <- H in H0.
apply (H' t0); trivial.
intros t0 H0. rewrite H in H0.
apply (H' t0); trivial.
Qed.
(* ********************************************************************** *)
Lemma ctx_to_mod_eqC : forall R t t', contextual_closure R t t' -> red_ctx_mod_eqC R t t'.
Proof.
intros R t t' H.
exists t t'. split.
reflexivity. split; trivial.
reflexivity.
Qed.
Lemma eqC_abs_in_close : forall x L t t',
term t -> eqC t t' -> x \notin L ->
eqC (pterm_abs (close t x)) (pterm_abs (close t' x)).
Proof.
intros x L t t' B H Fr.
apply trs_pctx_abs_in_close with (L := L); trivial.
apply red_regular'_eqc. apply red_out_eqc.
Qed.
Lemma eqC_subst_left_close : forall x L t t' u, term t -> term u ->
eqC t t' -> x \notin L ->
eqC ((close t x)[u]) ((close t' x)[u]).
Proof.
intros x L t t' u Tt Tu H Fr.
apply trs_pctx_subst_close with (L := L); trivial.
apply red_regular'_eqc. apply red_out_eqc.
intros. apply eqc_rf. apply one_step_reduction. apply p_redex. apply eqc_rf.
Qed.
Lemma eqC_abs_in : forall L t t', body t ->
(forall x, x \notin L -> eqC (t^x) (t'^x)) ->
eqC (pterm_abs t) (pterm_abs t').
Proof.
intros L t t' B H.
apply trs_pctx_abs_in with (L := L); trivial.
apply red_regular'_eqc. apply red_out_eqc.
Qed.
Lemma eqC_subst_left : forall L t t' u, body t -> term u ->
(forall x, x \notin L -> eqC (t^x) (t'^x)) ->
eqC (t[u]) (t'[u]).
Proof.
intros L t t' u B T H.
apply trs_pctx_subst with (L := L); trivial.
apply red_regular'_eqc. apply red_out_eqc.
intros. apply eqc_rf. apply one_step_reduction. apply p_redex. apply eqc_rf.
Qed.
Lemma mod_eqC_app_left : forall R t t' u, term u -> red_ctx_mod_eqC R t t' ->
red_ctx_mod_eqC R (pterm_app t u) (pterm_app t' u).
Proof.
intros R t t' u T H.
case H; clear H; intros t0 H. case H; clear H; intros t1 H.
destruct H. destruct H0.
exists (pterm_app t0 u) (pterm_app t1 u). split.
rewrite H. reflexivity. split.
apply app_left; trivial.
rewrite H1. reflexivity.
Qed.
Lemma trs_mod_eqC_app_left : forall R t t' u, term u -> trans_closure (red_ctx_mod_eqC R) t t' ->
trans_closure (red_ctx_mod_eqC R) (pterm_app t u) (pterm_app t' u).
Proof.
intros R t t' u T H. induction H.
apply one_step_reduction. apply mod_eqC_app_left; trivial.
apply transitive_reduction with (u := pterm_app u0 u); trivial.
apply mod_eqC_app_left; trivial.
Qed.
Lemma str_mod_eqC_app_left : forall R t t' u, term u -> star_closure (red_ctx_mod_eqC R) t t' ->
star_closure (red_ctx_mod_eqC R) (pterm_app t u) (pterm_app t' u).
Proof.
intros R t t' u T H. induction H.
apply reflexive_reduction. apply star_trans_reduction.
apply trs_mod_eqC_app_left; trivial.
Qed.
Lemma mod_eqC_app_right : forall R t t' u, term u -> red_ctx_mod_eqC R t t' ->
red_ctx_mod_eqC R (pterm_app u t) (pterm_app u t').
Proof.
intros R t t' u T H.
case H; clear H; intros t0 H. case H; clear H; intros t1 H.
destruct H. destruct H0.
exists (pterm_app u t0) (pterm_app u t1). split.
rewrite H. reflexivity. split.
apply app_right; trivial.
rewrite H1. reflexivity.
Qed.
Lemma trs_mod_eqC_app_right : forall R t u u', term t -> trans_closure (red_ctx_mod_eqC R) u u' ->
trans_closure (red_ctx_mod_eqC R) (pterm_app t u) (pterm_app t u').
Proof.
intros R t u u' T H. induction H.
apply one_step_reduction. apply mod_eqC_app_right; trivial.
apply transitive_reduction with (u := pterm_app t u); trivial.
apply mod_eqC_app_right; trivial.
Qed.
Lemma str_mod_eqC_app_right : forall R t u u', term t -> star_closure (red_ctx_mod_eqC R) u u' ->
star_closure (red_ctx_mod_eqC R) (pterm_app t u) (pterm_app t u').
Proof.
intros R t u u' T H. induction H.
apply reflexive_reduction. apply star_trans_reduction.
apply trs_mod_eqC_app_right; trivial.
Qed.
Lemma mod_eqC_subst_right : forall R t u u', body t -> red_ctx_mod_eqC R u u' ->
red_ctx_mod_eqC R (pterm_sub t u) (pterm_sub t u').
Proof.
intros R t u u' B H.
case H; clear H; intros u0 H. case H; clear H; intros u1 H.
destruct H. destruct H0.
exists (t[u0]) (t[u1]). split.
rewrite H. reflexivity. split.
apply subst_right; trivial.
rewrite H1. reflexivity.
Qed.
Lemma trs_mod_eqC_subst_right : forall R t u u', body t -> trans_closure (red_ctx_mod_eqC R) u u' ->
trans_closure (red_ctx_mod_eqC R) (t[u]) (t[u']).
Proof.
intros R t u u' T H. induction H.
apply one_step_reduction. apply mod_eqC_subst_right; trivial.
apply transitive_reduction with (u := t[u]); trivial.
apply mod_eqC_subst_right; trivial.
Qed.
Lemma str_mod_eqC_subst_right : forall R t u u', body t -> star_closure (red_ctx_mod_eqC R) u u' ->
star_closure (red_ctx_mod_eqC R) (t[u]) (t[u']).
Proof.
intros R t u u' T H. induction H.
apply reflexive_reduction. apply star_trans_reduction.
apply trs_mod_eqC_subst_right; trivial.
Qed.
Lemma mod_eqC_abs_in_close : forall x R L t t', red_regular R -> red_out R ->
red_ctx_mod_eqC R t t' -> x \notin L ->
red_ctx_mod_eqC R (pterm_abs (close t x)) (pterm_abs (close t' x)).
Proof.
intros x R L t t' Reg Out H Fr.
case H; clear H; intros t0 H. case H; clear H; intros t1 H.
destruct H. destruct H0.
exists (pterm_abs (close t0 x)) (pterm_abs (close t1 x)). split.
apply eqC_abs_in_close with (L := L); trivial. rewrite H.
apply red_regular_ctx in Reg. apply Reg in H0. apply H0. split.
apply ctx_abs_in_close with (L := L); trivial.
apply eqC_abs_in_close with (L := L); trivial.
apply red_regular_ctx in Reg. apply Reg in H0. apply H0.
Qed.
Lemma mod_eqC_abs_in : forall R L t t', red_regular R -> red_out R ->
(forall x, x \notin L -> red_ctx_mod_eqC R (t ^ x) (t' ^ x)) ->
red_ctx_mod_eqC R (pterm_abs t) (pterm_abs t').
Proof.
intros R L t t' Reg Out H. case var_fresh with (L := L \u (fv t) \u (fv t')). intros x Fr.
apply notin_union in Fr. destruct Fr. apply notin_union in H0. destruct H0.
assert (Q: red_ctx_mod_eqC R (t ^ x) (t' ^ x)). apply H; trivial. clear H.
gen_eq t2 : (t ^ x). gen_eq t3 : (t' ^ x). intros Ht2 Ht3.
replace t with (close t2 x). replace t' with (close t3 x). clear Ht2 Ht3.
apply mod_eqC_abs_in_close with (L := L); trivial.
rewrite Ht2. rewrite <- close_open_term; trivial.
rewrite Ht3. rewrite <- close_open_term; trivial.
Qed.
Lemma trs_mod_eqC_abs_in : forall R L t t', red_regular R -> red_out R ->
(forall x, x \notin L -> trans_closure (red_ctx_mod_eqC R) (t ^ x) (t' ^ x)) ->
trans_closure (red_ctx_mod_eqC R) (pterm_abs t) (pterm_abs t').
Proof.
intros R L t t' H0 H1 H2. case var_fresh with (L := L \u (fv t) \u (fv t')). intros x Fr.
apply notin_union in Fr. destruct Fr. apply notin_union in H. destruct H.
assert (Q: trans_closure (red_ctx_mod_eqC R) (t ^ x) (t' ^ x)). apply H2; trivial. clear H2.
gen_eq t0 : (t ^ x). gen_eq t1 : (t' ^ x). intros Ht1 Ht0.
replace t with (close t0 x). replace t' with (close t1 x).
clear Ht0 Ht1. induction Q.
apply one_step_reduction. apply mod_eqC_abs_in_close with (L := L); trivial.
apply transitive_reduction with (u := pterm_abs (close u x)); trivial.
apply mod_eqC_abs_in_close with (L := L); trivial.
rewrite Ht1. rewrite <- close_open_term; trivial.
rewrite Ht0. rewrite <- close_open_term; trivial.
Qed.
Lemma str_mod_eqC_abs_in : forall R L t t', red_regular R -> red_out R ->
(forall x, x \notin L -> star_closure (red_ctx_mod_eqC R) (t ^ x) (t' ^ x)) ->
star_closure (red_ctx_mod_eqC R) (pterm_abs t) (pterm_abs t').
Proof.
intros R L t t' H0 H1 H2. case var_fresh with (L := L \u (fv t) \u (fv t')). intros x Fr.
apply notin_union in Fr. destruct Fr. apply notin_union in H. destruct H.
assert (Q: star_closure (red_ctx_mod_eqC R) (t ^ x) (t' ^ x)). apply H2; trivial. clear H2.
gen_eq t0 : (t ^ x). gen_eq t1 : (t' ^ x). intros Ht1 Ht0.
replace t with (close t0 x). replace t' with (close t1 x).
clear Ht0 Ht1. destruct Q. apply reflexive_reduction.
apply star_trans_reduction. induction H2.
apply one_step_reduction. apply mod_eqC_abs_in_close with (L := L); trivial.
apply transitive_reduction with (u := pterm_abs (close u x)); trivial.
apply mod_eqC_abs_in_close with (L := L); trivial.
rewrite Ht1. rewrite <- close_open_term; trivial.
rewrite Ht0. rewrite <- close_open_term; trivial.
Qed.
Lemma mod_eqC_subst_left_close : forall x R L t t' u, red_regular R -> red_out R ->
term u ->
red_ctx_mod_eqC R t t' -> x \notin L ->
red_ctx_mod_eqC R ((close t x)[u]) ((close t' x)[u]).
Proof.
intros x R L t t' u Reg Out T H Fr.
case H; clear H; intros t0 H. case H; clear H; intros t1 H.
destruct H. destruct H0.
exists ((close t0 x)[u]) ((close t1 x)[u]). split.
apply eqC_subst_left_close with (L := L); trivial. rewrite H.
apply red_regular_ctx in Reg. apply Reg in H0. apply H0. split.
apply ctx_subst_left_close with (L := L); trivial.
apply eqC_subst_left_close with (L := L); trivial.
apply red_regular_ctx in Reg. apply Reg in H0. apply H0.
Qed.
Lemma mod_eqC_subst_left : forall R L t t' u, red_regular R -> red_out R -> term u ->
(forall x, x \notin L -> red_ctx_mod_eqC R (t ^ x) (t' ^ x)) ->
red_ctx_mod_eqC R (t[u]) (t'[u]).
Proof.
intros R L t t' u Reg Out T H. case var_fresh with (L := L \u (fv t) \u (fv t')). intros x Fr.
apply notin_union in Fr. destruct Fr. apply notin_union in H0. destruct H0.
assert (Q: red_ctx_mod_eqC R (t ^ x) (t' ^ x)). apply H; trivial. clear H.
gen_eq t2 : (t ^ x). gen_eq t3 : (t' ^ x). intros Ht2 Ht3.
replace t with (close t2 x). replace t' with (close t3 x). clear Ht2 Ht3.
apply mod_eqC_subst_left_close with (L := L); trivial.
rewrite Ht2. rewrite <- close_open_term; trivial.
rewrite Ht3. rewrite <- close_open_term; trivial.
Qed.
Lemma trs_mod_eqC_subst_left : forall R L t t' u, red_regular R -> red_out R -> term u ->
(forall x, x \notin L -> trans_closure (red_ctx_mod_eqC R) (t ^ x) (t' ^ x)) ->
trans_closure (red_ctx_mod_eqC R) (t[u]) (t'[u]).
Proof.
intros R L t t' u H0 H1 T H2. case var_fresh with (L := L \u (fv t) \u (fv t')). intros x Fr.
apply notin_union in Fr. destruct Fr. apply notin_union in H. destruct H.
assert (Q: trans_closure (red_ctx_mod_eqC R) (t ^ x) (t' ^ x)). apply H2; trivial. clear H2.
gen_eq t0 : (t ^ x). gen_eq t1 : (t' ^ x). intros Ht1 Ht0.
replace t with (close t0 x). replace t' with (close t1 x).
clear Ht0 Ht1. induction Q.
apply one_step_reduction. apply mod_eqC_subst_left_close with (L := L); trivial.
apply transitive_reduction with (u := (close u0 x)[u]); trivial.
apply mod_eqC_subst_left_close with (L := L); trivial.
rewrite Ht1. rewrite <- close_open_term; trivial.
rewrite Ht0. rewrite <- close_open_term; trivial.
Qed.
Lemma str_mod_eqC_subst_left : forall R L t t' u, red_regular R -> red_out R -> term u ->
(forall x, x \notin L -> star_closure (red_ctx_mod_eqC R) (t ^ x) (t' ^ x)) ->
star_closure (red_ctx_mod_eqC R) (t[u]) (t'[u]).
Proof.
intros R L t t' u H0 H1 T H2. case var_fresh with (L := L \u (fv t) \u (fv t')). intros x Fr.
apply notin_union in Fr. destruct Fr. apply notin_union in H. destruct H.
assert (Q: star_closure (red_ctx_mod_eqC R) (t ^ x) (t' ^ x)). apply H2; trivial. clear H2.
gen_eq t0 : (t ^ x). gen_eq t1 : (t' ^ x). intros Ht1 Ht0.
replace t with (close t0 x). replace t' with (close t1 x).
clear Ht0 Ht1. destruct Q. apply reflexive_reduction.
apply star_trans_reduction. induction H2.
apply one_step_reduction. apply mod_eqC_subst_left_close with (L := L); trivial.
apply transitive_reduction with (u := (close u0 x)[u]); trivial.
apply mod_eqC_subst_left_close with (L := L); trivial.
rewrite Ht1. rewrite <- close_open_term; trivial.
rewrite Ht0. rewrite <- close_open_term; trivial.
Qed.
(*** about NF and SN modulo =e ***)
Lemma eqC_SN_app : forall n R t u, red_regular R -> term t -> term u ->
SN_ind n (red_ctx_mod_eqC R) (pterm_app t u) ->
SN_ind n (red_ctx_mod_eqC R) t /\ SN_ind n (red_ctx_mod_eqC R) u.
Proof.
intros n R t u Reg.
generalize t u; clear t u.
induction n. intros. split; rewrite <- NF_eq_SN0 in *|-*; unfold NF in *|-*.
intros t' H'. apply (H1 (pterm_app t' u)). apply mod_eqC_app_left; trivial.
intros u' H'. apply (H1 (pterm_app t u')). apply mod_eqC_app_right; trivial.
intros t u Tt Tu H. destruct H. split.
apply SN_intro. intros t' H'. exists n. split; try omega.
apply IHn with (t := t') (u := u); trivial. apply red_regular_eqC in Reg.
apply Reg in H'. apply H'. case (H (pterm_app t' u)). apply mod_eqC_app_left; trivial.
intros k H''. apply WSN with (k := k). omega. apply H''.
apply SN_intro. intros u' H'. exists n. split; try omega.
apply IHn with (t := t) (u := u'); trivial. apply red_regular_eqC in Reg.
apply Reg in H'. apply H'. case (H (pterm_app t u')). apply mod_eqC_app_right; trivial.
intros k H''. apply WSN with (k := k). omega. apply H''.
Qed.
Lemma eqC_SN_abs : forall x n R t, red_regular R -> red_out R ->
SN_ind n (red_ctx_mod_eqC R) (pterm_abs t) ->
x \notin (fv t) -> SN_ind n (red_ctx_mod_eqC R) (t ^ x).
Proof.
intros x n R t Reg Out.
generalize t; clear t.
generalize Out. intro Out'. apply red_out_mod_eqC in Out; trivial.
generalize Reg. intro Reg'. apply red_regular_eqC in Reg.
apply red_out_to_rename in Out.
induction n. intros.
apply SN0_to_NF in H.
apply NF_to_SN0; unfold NF in *|-*.
intros t' H'. gen_eq t0 : (close t' x). intro H1.
replace t' with (t0 ^ x) in H'.
assert (Q: red_ctx_mod_eqC R (pterm_abs t) (pterm_abs t0)).
apply mod_eqC_abs_in with (L := {{x}}); trivial. intros z H2.
apply notin_singleton in H2. apply Out with (x := x); trivial.
rewrite H1. apply fv_close'.
apply False_ind. apply (H (pterm_abs t0)); trivial.
rewrite H1. rewrite open_close_var with (x := x).
reflexivity. apply Reg in H'. apply H'.
intros. destruct H. apply SN_intro.
intros. exists n. split; try omega.
gen_eq t0 : (close t' x). intro H2.
replace t' with (t0 ^ x). replace t' with (t0 ^ x) in H1.
apply IHn; trivial. case (H (pterm_abs t0)); trivial.
apply mod_eqC_abs_in with (L := {{x}}); trivial.
intros z H3. apply notin_singleton in H3.
apply Out with (x := x); trivial.
rewrite H2. apply fv_close'.
intros k H3. apply WSN with (k := k); try omega.
apply H3. rewrite H2. apply fv_close'.
rewrite H2. rewrite open_close_var with (x := x).
reflexivity. apply Reg in H1. apply H1.
rewrite H2. rewrite open_close_var with (x := x).
reflexivity. apply Reg in H1. apply H1.
Qed.
Lemma eqC_SN_sub : forall x n R t u, red_regular R -> red_out R ->
body t -> term u -> x \notin (fv t) ->
SN_ind n (red_ctx_mod_eqC R) (t[u]) ->
SN_ind n (red_ctx_mod_eqC R) (t ^ x) /\
SN_ind n (red_ctx_mod_eqC R) u.
Proof.
intros x n R t u Reg Out B T.
generalize t u B T; clear t u B T.
generalize Out. intro Out'. apply red_out_mod_eqC in Out; trivial.
generalize Reg. intro Reg'. apply red_regular_eqC in Reg.
apply red_out_to_rename in Out.
induction n. intros. rewrite <- NF_eq_SN0 in *|-*; unfold NF in *|-*.
split. intros t' H'. gen_eq t0 : (close t' x). intro H1.
replace t' with (t0 ^ x) in H'.
assert (Q: red_ctx_mod_eqC R (t[u]) (t0[u])).
apply mod_eqC_subst_left with (L := {{x}}); trivial. intros z H2.
apply notin_singleton in H2. apply Out with (x := x); trivial.
rewrite H1. apply fv_close'.
apply (H0 (t0[u])); trivial.
rewrite H1. rewrite open_close_var with (x := x).
reflexivity. apply Reg in H'. apply H'.
rewrite <- NF_eq_SN0 in *|-*; unfold NF in *|-*. intros u' H'.
apply (H0 (t[u'])). apply mod_eqC_subst_right; trivial.
intros. split. destruct H0. apply SN_intro.
intros. exists n. split; try omega.
gen_eq t0 : (close t' x). intro H2.
replace t' with (t0 ^ x). replace t' with (t0 ^ x) in H1.
apply IHn with (u := u); trivial.
rewrite body_eq_body'. unfold body'.
apply Reg in H1. destruct H1.
rewrite term_eq_term' in H3. unfold term' in H3. unfold open in H3.
rewrite lc_at_open with (u := pterm_fvar x); trivial.
rewrite H2. apply fv_close'. case (H0 (t0[u])); trivial.
apply mod_eqC_subst_left with (L := {{x}}); trivial.
intros z H3. apply notin_singleton in H3.
apply Out with (x := x); trivial.
rewrite H2. apply fv_close'. intros k H3. destruct H3.
apply WSN with (k := k); try omega; trivial.
rewrite H2. rewrite open_close_var with (x := x).
reflexivity. apply Reg in H1. apply H1.
rewrite H2. rewrite open_close_var with (x := x).
reflexivity. apply Reg in H1. apply H1.
apply SN_intro. intros u' H'. exists n; split; try omega.
apply (IHn t u'); trivial. apply Reg in H'. apply H'.
destruct H0. case (H0 (t[u'])). apply mod_eqC_subst_right; trivial.
intros k H1. destruct H1.
apply WSN with (k := k); try omega; trivial.
Qed.
Lemma eqC_SN_app_list : forall n R t lu, red_regular R -> term t -> term %% lu ->
SN_ind n (red_ctx_mod_eqC R) (t // lu) ->
SN_ind n (red_ctx_mod_eqC R) t /\ SN_ind n (red_ctx_mod_eqC R) %% lu.
Proof.
intros n R t lu Reg. generalize n t; clear n t.
induction lu; simpl. intros n t T H0 H. split; trivial.
intros n t T H0 H. destruct H0. apply eqC_SN_app in H; trivial. destruct H.
assert (Q : SN_ind n (red_ctx_mod_eqC R) t /\ SN_ind n (red_ctx_mod_eqC R) %% lu).
apply IHlu; trivial.
clear IHlu. destruct Q. split; trivial. split; trivial.
rewrite term_mult_app. split; trivial.
Qed.
Lemma red_h_mult_app : forall R t t' lu, term %% lu -> (red_ctx_mod_eqC R) t t' -> (red_ctx_mod_eqC R) (t // lu) (t' // lu).
Proof.
intros R t t' lu Tlu H. induction lu; simpl in *|-*; trivial.
destruct Tlu. apply mod_eqC_app_left; trivial.
apply IHlu; trivial.
Qed.
Lemma red_t_mult_app : forall R t lu lu', term t -> term %% lu -> R_list (red_ctx_mod_eqC R) lu lu' -> (red_ctx_mod_eqC R) (t // lu) (t // lu').
Proof.
intros R t lu lu' Tt Tlu H. unfold R_list in H.
case H; clear H; intros t0 H.
case H; clear H; intros t1 H.
case H; clear H; intros l0 H.
case H; clear H; intros l1 H.
destruct H. destruct H0.
rewrite H. rewrite H0. rewrite H in Tlu.
clear H H0. induction l0; simpl. destruct l1; simpl.
apply mod_eqC_app_right; trivial.
apply mod_eqC_app_right; trivial.
simpl in Tlu. rewrite term_distribute_over_application.
rewrite term_mult_app. destruct Tlu. destruct H0.
split; trivial. split; trivial.
simpl in Tlu. destruct Tlu.
apply mod_eqC_app_left; trivial.
apply IHl0; trivial.
Qed.
(**** eqC and eqC' equivalence ***)
Inductive eqC' : pterm -> pterm -> Prop :=
| eqC'_refl: forall u, eqC' u u
| eqC'_trans: forall t u v, eqC' t u -> eqC' u v -> eqC' t v
| eqC'_redex: forall t u v,
term u -> term v -> eqC' (t[u][v]) ((& t)[v][u])
| eqC'_app : forall t t' u u', eqC' t t' -> eqC' u u' ->
eqC' (pterm_app t u) (pterm_app t' u')
| eqC'_abs : forall t t' L,
(forall x, x \notin L -> eqC' (t ^ x) (t' ^ x)) ->
eqC' (pterm_abs t) (pterm_abs t')
| eqC'_sub : forall t t' u u' L,
(forall x, x \notin L -> eqC' (t ^ x) (t' ^ x)) -> eqC' u u' ->
eqC' (t[u]) (t'[u'])
.
Notation "t =e' u" := (eqC' t u) (at level 66).
Lemma eqC'_sym : forall t u, t =e' u -> u =e' t.
Proof.
intros t u H.
induction H.
apply eqC'_refl.
apply eqC'_trans with (u := u); trivial.
replace (t[u]) with ((& (& t))[u]). apply eqC'_redex; trivial.
unfold bswap. rewrite bswap_rec_id. reflexivity.
apply eqC'_app; trivial.
apply eqC'_abs with (L := L); trivial.
apply eqC'_sub with (L := L); trivial.
Qed.
Instance eqC'_eq : Equivalence eqC'.
Proof.
split.
unfold Reflexive. apply eqC'_refl.
unfold Symmetric. apply eqC'_sym.
unfold Transitive. apply eqC'_trans.
Qed.
Lemma term_eqC' : forall t t', t =e' t' -> (term t <-> term t').
Proof.
intros t t' H. induction H.
split; trivial. split. intro.
apply IHeqC'2. apply IHeqC'1; trivial. intro.
apply IHeqC'1. apply IHeqC'2; trivial. split.
intro H'. apply body_to_subs; trivial.
apply body'_to_body. apply term_to_term' in H'.
unfold body'. unfold term' in H'. simpl in *|-*.
split. apply lc_at_bswap. omega. apply H'.
apply lc_at_weaken_ind with (k1 := 0); try omega.
apply H'. intro H'. apply body_to_subs; trivial.
apply body'_to_body. apply term_to_term' in H'.
unfold body'. unfold term' in H'. simpl in *|-*.
split. replace t with (& (& t)).
apply lc_at_bswap. omega. apply H'. apply bswap_rec_id.
apply lc_at_weaken_ind with (k1 := 0); try omega.
apply H'. split. intro H'.
apply term_distribute_over_application.
apply term_distribute_over_application in H'.
split. apply IHeqC'1; apply H'. apply IHeqC'2; apply H'.
intro H'. apply term_distribute_over_application.
apply term_distribute_over_application in H'.
split. apply IHeqC'1; apply H'. apply IHeqC'2; apply H'.
split. intro H'. apply body_to_term_abs.
apply term_abs_to_body in H'. unfold body in *|-*.
case H'. clear H'. intros L' H'. exists (L \u L').
intros x H''. apply notin_union in H''. apply H0.
apply H''. apply H'. apply H''.
intro H'. apply body_to_term_abs.
apply term_abs_to_body in H'. unfold body in *|-*.
case H'. clear H'. intros L' H'. exists (L \u L').
intros x H''. apply notin_union in H''. apply H0.
apply H''. apply H'. apply H''. split. intro H'.
generalize H'. intro H''. apply term_sub_to_body in H'.
apply term_sub_to_term in H''. apply body_to_subs.
unfold body in *|-*. case H'. clear H'. intros L' H'.
exists (L \u L'). intros x H'''. apply notin_union in H'''.
apply H0. apply H'''. apply H'. apply H'''. apply IHeqC'; trivial.
intro H'. generalize H'. intro H''. apply term_sub_to_body in H'.
apply term_sub_to_term in H''. apply body_to_subs.
unfold body in *|-*. case H'. clear H'. intros L' H'.
exists (L \u L'). intros x H'''. apply notin_union in H'''.
apply H0. apply H'''. apply H'. apply H'''. apply IHeqC'; trivial.
Qed.
Instance rw_eqC'_term : Proper (eqC' ==> iff) term.
Proof.
intros_all. apply term_eqC'; assumption.
Qed.
Lemma eqC_eq_eqC': forall t t', term t -> (t =e t' <-> t =e' t').
Proof.
intros t t' T. split.
assert (Q : forall u v, term u -> p_contextual_closure eqc u v -> u =e' v).
clear T t t'. intros t t' T H. induction H. destruct H.
reflexivity. rewrite eqC'_redex; trivial. reflexivity.
apply term_distribute_over_application in T. destruct T.
apply eqC'_app.
apply IHp_contextual_closure1; trivial.
apply IHp_contextual_closure2; trivial.
apply eqC'_abs with (L := L). intros. apply H0; trivial.
apply body_open_term; trivial. apply term_abs_to_body; trivial.
apply subs_to_body in T; destruct T.
apply eqC'_sub with (L := L). intros. apply H0; trivial.
apply body_open_term; trivial. apply IHp_contextual_closure; trivial.
intro H. induction H. apply Q; trivial.
apply eqC'_trans with (u := u). apply Q; trivial.
apply IHtrans_closure. apply (lc_at_pctx_eqc 0) in H.
rewrite term_eq_term'. apply H. rewrite <- term_eq_term'; trivial.
intro H. induction H. reflexivity.
apply transitive_closure_composition with (u := u).
apply IHeqC'1; trivial. apply IHeqC'2. rewrite <- H; trivial.
rewrite eqC_redex; trivial. reflexivity.
apply term_distribute_over_application in T. destruct T.
rewrite IHeqC'1; trivial. rewrite IHeqC'2; trivial. reflexivity.
apply eqC_abs_in with (L := L). apply term_abs_to_body; trivial.
intros x H1. apply H0; trivial. apply body_open_term; trivial.
apply term_abs_to_body; trivial. apply subs_to_body in T; destruct T.
rewrite IHeqC'; trivial. apply eqC_subst_left with (L := L); trivial.
rewrite <- H1; trivial. intros x H4. apply H0; trivial.
apply body_open_term; trivial.
Qed.
(* ********************************************************************** *)
(** =e' Rewriting *)
Lemma eqC'_fv : forall x t t',
(eqC' t t') -> ((x \in fv t) <-> (x \in fv t')).
Proof.
intros x t t' H. induction H.
split; trivial.
split.
intro H'. apply IHeqC'2. apply IHeqC'1; trivial.
intro H'. apply IHeqC'1. apply IHeqC'2; trivial.
simpl. split.
intro H2. apply in_union in H2. case H2; clear H2.
intro H2. apply in_union in H2. case H2; clear H2.
intro H2. apply in_union. left. apply in_union.
left. unfold bswap. rewrite fv_bswap_rec; trivial.
intro H2. apply in_union. right; trivial.
intro H2. apply in_union. left. apply in_union. right; trivial.
intro H2. apply in_union in H2. case H2; clear H2.
intro H2. apply in_union in H2. case H2; clear H2.
intro H2. apply in_union. left. apply in_union.
left. unfold bswap in H2. rewrite fv_bswap_rec in H2; trivial.
intro H2. apply in_union. right; trivial.
intro H2. apply in_union. left; apply in_union. right; trivial.
simpl. split.
intro H1. apply in_union in H1. case H1; clear H1.
intro H1. apply in_union. left. apply IHeqC'1; trivial.
intro H1. apply in_union. right; trivial. apply IHeqC'2; trivial.
intro H1. apply in_union in H1. case H1; clear H1.
intro H1. apply in_union. left. apply IHeqC'1; trivial.
intro H1. apply in_union. right; trivial. apply IHeqC'2; trivial.
simpl. pick_fresh z. apply notin_union in Fr. case Fr; clear Fr.
intros H1 H2. apply notin_union in H1. case H1; clear H1. intros H1 H3.
apply notin_union in H1. case H1; clear H1. intros H1 H4.
apply notin_singleton in H4.
assert (Q: (x \in fv (t ^ z) <-> x \in fv t)).
unfold open. apply fv_open_. intro.
apply H4. apply symmetry; trivial.
assert (Q': (x \in fv (t' ^ z) <-> x \in fv t')).
unfold open. apply fv_open_. intro.
apply H4. apply symmetry; trivial.
split.
intro H5. apply Q'. apply H0; trivial. apply Q; trivial.
intro H5. apply Q. apply H0; trivial. apply Q'; trivial.
simpl. pick_fresh z. apply notin_union in Fr. case Fr; clear Fr.
intros H2 H3. apply notin_union in H2. case H2; clear H2. intros H2 H4.
apply notin_union in H2. case H2; clear H2. intros H2 H5.
apply notin_union in H2. case H2; clear H2. intros H2 H6.
apply notin_union in H2. case H2; clear H2. intros H2 H7.
apply notin_singleton in H7.
assert (Q: (x \in fv (t ^ z) <-> x \in fv t)).
unfold open. apply fv_open_. intro.
apply H7. apply symmetry; trivial.
assert (Q': (x \in fv (t' ^ z) <-> x \in fv t')).
unfold open. apply fv_open_. intro.
apply H7. apply symmetry; trivial.
split.
intro H8. apply in_union in H8. case H8; clear H8.
intro H8. apply in_union. left.
apply Q'. apply H0; trivial. apply Q; trivial.
intro H8. apply in_union. right; trivial. apply IHeqC'; trivial.
intro H8. apply in_union in H8. case H8; clear H8.
intro H8. apply in_union. left.
apply Q. apply H0; trivial. apply Q'; trivial.
intro H8. apply in_union. right; trivial. apply IHeqC'; trivial.
Qed.
Instance rw_eqC'_fv : Proper (eqC' ==> VarSet.Equal) fv.
Proof.
intros_all. apply eqC'_fv; trivial.
Qed.
Definition Cofinite_q (L : VarSet.t) (R : pterm -> pterm -> Prop) (t t' : pterm) :=
forall x, x \notin L -> R (t ^ x) (t' ^ x) .
Definition term_R (R : pterm -> pterm -> Prop) (t t' : pterm) :=
term t /\ R t t'.
Instance rw_eqC'_app : Proper (eqC' ++> eqC' ++> eqC') pterm_app.
Proof.
intros_all.
apply eqC'_app; trivial.
Qed.
Lemma eq_app_l: forall t t' u, t =e t' -> pterm_app t u =e pterm_app t' u.
Proof.
intros t t' u eq.
rewrite eq.
reflexivity.
Qed.
Lemma eq_app_r: forall t u u', u =e u' -> pterm_app t u =e pterm_app t u'.
Proof.
intros t t' u eq.
rewrite eq.
reflexivity.
Qed.
Instance rw_eqC'_abs : forall L, Proper (Cofinite_q L eqC' ++> eqC') pterm_abs.
Proof.
intros_all. unfold Cofinite_q in H.
apply eqC'_abs with (L := L); trivial.
Qed.
Instance rw_eqC'_sub : forall L, Proper (Cofinite_q L eqC' ++> eqC' ++> eqC') pterm_sub.
Proof.
intros_all. unfold Cofinite_q in H.
apply eqC'_sub with (L := L); trivial.
Qed.
Lemma eqC'_open : forall n t t' u, term u ->
t =e' t'-> (open_rec n u t) =e' (open_rec n u t').
Proof.
intros n t t' u H.
intro H'. generalize n; clear n.
induction H'. reflexivity.
intro n. rewrite IHH'1; trivial.
intro n. unfold open. simpl.
rewrite open_lc_at with (t := u0).
rewrite open_lc_at with (t := u0).
rewrite open_lc_at with (t := v).
rewrite open_lc_at with (t := v).
replace ({S (S n) ~> u}(& t)) with (& ({S (S n) ~> u}t)).
apply eqC'_redex; trivial.
apply bswap_open_rec. omega.
apply term_to_term'; trivial.
apply lc_at_weaken_ind with (k1 := 0);
try omega. apply term_to_term'; trivial.
apply lc_at_weaken_ind with (k1 := 0);
try omega. apply term_to_term'; trivial.
apply lc_at_weaken_ind with (k1 := 0);
try omega. apply term_to_term'; trivial.
apply lc_at_weaken_ind with (k1 := 0);
try omega. apply term_to_term'; trivial.
simpl; intro n. rewrite IHH'1; rewrite IHH'2.
reflexivity.
simpl; intro n. apply eqC'_abs with (L := (fv u) \u L).
intros x H2. apply notin_union in H2. case H2; clear H2.
intros H2 H3. unfold open in *|-*.
replace ({0 ~> pterm_fvar x}({S n ~> u}t))
with ({S n ~> u}({0 ~> pterm_fvar x}t)).
replace ({0 ~> pterm_fvar x}({S n ~> u}t'))
with ({S n ~> u}({0 ~> pterm_fvar x}t')).
apply H1; trivial.
rewrite subst_com; trivial. omega.
rewrite subst_com; trivial. omega.
simpl; intro n. apply eqC'_sub with (L := (fv u) \u L).
intros x H2. apply notin_union in H2. case H2; clear H2.
intros H2 H3. unfold open in *|-*.
replace ({0 ~> pterm_fvar x}({S n ~> u}t))
with ({S n ~> u}({0 ~> pterm_fvar x}t)).
replace ({0 ~> pterm_fvar x}({S n ~> u}t'))
with ({S n ~> u}({0 ~> pterm_fvar x}t')).
apply H1; trivial.
rewrite subst_com; trivial. omega.
rewrite subst_com; trivial. omega.
apply IHH'.
Qed.
Instance rw_eqC'_abs' : Proper (eqC' ++> eqC') pterm_abs.
Proof.
intros_all. apply eqC'_abs with (L := {}).
intros x' H'. apply eqC'_open; trivial.
Qed.
Instance rw_eqC'_sub' : Proper (eqC' ++> eqC' ++> eqC') pterm_sub.
Proof.
intros_all. apply eqC'_sub with (L := {}); trivial.
intros x' H'. apply eqC'_open; trivial.
Qed.
Lemma eq_abs: forall t t', t =e' t' -> pterm_abs t =e' pterm_abs t'.
Proof.
intros t t' eq.
rewrite eq.
reflexivity.
Qed.
Lemma eq_subs: forall t t' u, t =e' t' -> pterm_sub t u =e' pterm_sub t' u.
Proof.
intros t t' u eq.
rewrite eq.
reflexivity.
Qed.
|
theory Chapter9_2
imports "~~/src/HOL/IMP/Sec_Typing"
begin
text{*
\exercise
Reformulate the inductive predicate @{const sec_type}
as a recursive function and prove the equivalence of the two formulations:
*}
fun ok :: "level \<Rightarrow> com \<Rightarrow> bool" where
(* your definition/proof here *)
theorem "(l \<turnstile> c) = ok l c"
(* your definition/proof here *)
text{*
Try to reformulate the bottom-up system @{prop "\<turnstile> c : l"}
as a function that computes @{text l} from @{text c}. What difficulty do you face?
\endexercise
\exercise
Define a bottom-up termination insensitive security type system
@{text"\<turnstile>' c : l"} with subsumption rule:
*}
inductive sec_type2' :: "com \<Rightarrow> level \<Rightarrow> bool" ("(\<turnstile>' _ : _)" [0,0] 50) where
(* your definition/proof here *)
text{*
Prove equivalence with the bottom-up system @{prop "\<turnstile> c : l"}
without subsumption rule:
*}
lemma "\<turnstile> c : l \<Longrightarrow> \<turnstile>' c : l"
(* your definition/proof here *)
lemma "\<turnstile>' c : l \<Longrightarrow> \<exists>l' \<ge> l. \<turnstile> c : l'"
(* your definition/proof here *)
text{*
\endexercise
\exercise
Define a function that erases those parts of a command that
contain variables above some security level: *}
fun erase :: "level \<Rightarrow> com \<Rightarrow> com" where
(* your definition/proof here *)
text{*
Function @{term "erase l"} should replace all assignments to variables with
security level @{text"\<ge> l"} by @{const SKIP}.
It should also erase certain @{text IF}s and @{text WHILE}s,
depending on the security level of the boolean condition. Now show
that @{text c} and @{term "erase l c"} behave the same on the variables up
to level @{text l}: *}
theorem "\<lbrakk> (c,s) \<Rightarrow> s'; (erase l c,t) \<Rightarrow> t'; 0 \<turnstile> c; s = t (< l) \<rbrakk>
\<Longrightarrow> s' = t' (< l)"
(* your definition/proof here *)
text{* This theorem looks remarkably like the noninterference lemma from
theory \mbox{@{theory Sec_Typing}} (although @{text"\<le>"} has been replaced by @{text"<"}).
You may want to start with that proof and modify it.
The structure should remain the same. You may also need one or
two simple additional lemmas.
In the theorem above we assume that both @{term"(c,s)"}
and @{term "(erase l c,t)"} terminate. How about the following two properties: *}
lemma "\<lbrakk> (c,s) \<Rightarrow> s'; 0 \<turnstile> c; s = t (< l) \<rbrakk>
\<Longrightarrow> \<exists>t'. (erase l c, t) \<Rightarrow> t' \<and> s' = t' (< l)"
(* your definition/proof here *)
lemma "\<lbrakk> (erase l c,s) \<Rightarrow> s'; 0 \<turnstile> c; s = t (< l) \<rbrakk>
\<Longrightarrow> \<exists>t'. (c,t) \<Rightarrow> t' \<and> s' = t' (< l)"
(* your definition/proof here *)
text{* Give proofs or counterexamples.
\endexercise
*}
end
|
#ifndef NonLinearLSQ_h
#define NonLinearLSQ_h
/**
* @file
* $Revision: 4928 $
* $Date: 2012-12-21 10:44:12 -0700 (Fri, 21 Dec 2012) $
* $Id: NonLinearLSQ.h 4928 2012-12-21 17:44:12Z [email protected] $
*
* Unless noted otherwise, the portions of Isis written by the USGS are
* public domain. See individual third-party library and package descriptions
* for intellectual property information, user agreements, and related
* information.
*
* Although Isis has been used by the USGS, no warranty, expressed or
* implied, is made by the USGS as to the accuracy and functioning of such
* software and related material nor shall the fact of distribution
* constitute any such warranty, and no responsibility is assumed by the
* USGS in connection therewith.
*
* For additional information, launch
* $ISISROOT/doc//documents/Disclaimers/Disclaimers.html
* in a browser or see the Privacy & Disclaimers page on the Isis website,
* http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
* http://www.usgs.gov/privacy.html.
*/
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <QString>
#include <tnt_array1d.h>
#include <tnt_array1d_utils.h>
#include <tnt_array2d.h>
#include <tnt_array2d_utils.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_multifit_nlin.h>
#include "IException.h"
namespace Isis {
/**
* @brief NonLinearLSQ Computes a fit using a Levenberg-Marquardt algorithm
*
* This virtual base class uses the GSL toolkit to apply the
* Levenberg-Marquardt algorithm to fit data to a non-linear equation using
* least squares.
*
* @ingroup Utility
* @author 2007-11-15 Kris Becker
*
* @internal
*/
class NonLinearLSQ {
public:
typedef TNT::Array1D<double> NLVector;
typedef TNT::Array2D<double> NLMatrix;
// Constructors and Destructor
NonLinearLSQ() : _fitParms(), _uncert(), _nIters(0), _maxIters(50),
_status(0), _userTerminated(false), _userMessage() {}
/** Destructor */
virtual ~NonLinearLSQ() { }
virtual int nSize() const = 0;
virtual int nParms() const = 0;
/**
* @brief Sets the maximum number of iterations
*
* @param m User provides the maximum number iterations
*/
void setMaxIters(int m) { _maxIters = m; }
/**
* @brief Maximum number iterations for valid solution
*
*
* @return int Maximum resolutions
*/
int maxIters() const { return (_maxIters); }
virtual NLVector guess() = 0;
virtual NLVector f_x(const NLVector &x) = 0;
virtual NLMatrix df_x(const NLVector &x) = 0;
virtual double absErr() const { return (1.0E-4); }
virtual double relErr() const { return (1.0E-4); }
int curvefit();
/** Return status of last fit processing */
inline int status() const { return (_status); }
/** Determine success from last fit processing */
inline bool success() const { return (_status == GSL_SUCCESS); }
/** Check status for success of the given condition */
inline bool success(int status) const { return (status == GSL_SUCCESS); }
/** Return error message pertaining to last fit procesing */
inline QString statusstr() const {
return (QString(gsl_strerror(_status)));
}
/** Return error message given status condition */
inline QString statusstr(int status) const {
return (QString(gsl_strerror(status)));
}
/** Default interation test simply returns input status */
virtual int checkIteration(const int Iter, const NLVector &fitcoefs,
const NLVector &uncerts, double cplxconj,
int Istatus) {
return (Istatus);
}
/** Return coefficients from last fit processing */
inline NLVector coefs() const { return (_fitParms); }
/** Return uncertainties from last fit processing */
inline NLVector uncert() const { return (_uncert); }
/** Return number of iterations from last fit processing */
inline int nIterations() const { return (_nIters); }
protected:
void Terminate(const QString &message = "");
void Abort(const QString &reason = "");
bool doContinue() const { return (!_userTerminated); }
private:
NLVector _fitParms;
NLVector _uncert;
int _nIters;
int _maxIters;
int _status;
bool _userTerminated;
QString _userMessage;
struct _nlsqPointer {
NonLinearLSQ *nlsq;
};
static int f(const gsl_vector *x, void *params, gsl_vector *fx);
static int df(const gsl_vector *x, void *params, gsl_matrix *J);
static int fdf(const gsl_vector *x, void *params, gsl_vector *fx,
gsl_matrix *J);
NLVector gslToNlsq(const gsl_vector *v) const;
NLMatrix gslToNlsq(const gsl_matrix *m) const;
gsl_vector *NlsqTogsl(const NLVector &v, gsl_vector *gv = 0) const;
gsl_matrix *NlsqTogsl(const NLMatrix &m, gsl_matrix *gm = 0) const;
NLVector getUncertainty(const gsl_matrix *m) const;
};
} // namespace Isis
#endif
|
!!
!! @HEADER
!!
!!!!**********************************************************************
!!
!! Zoltan Toolkit for Load-balancing, Partitioning, Ordering and Coloring
!! Copyright 2012 Sandia Corporation
!!
!! Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
!! the U.S. Government retains certain rights in this software.
!!
!! Redistribution and use in source and binary forms, with or without
!! modification, are permitted provided that the following conditions are
!! met:
!!
!! 1. Redistributions of source code must retain the above copyright
!! notice, this list of conditions and the following disclaimer.
!!
!! 2. Redistributions in binary form must reproduce the above copyright
!! notice, this list of conditions and the following disclaimer in the
!! documentation and/or other materials provided with the distribution.
!!
!! 3. Neither the name of the Corporation nor the names of the
!! contributors may be used to endorse or promote products derived from
!! this software without specific prior written permission.
!!
!! THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
!! EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
!! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
!! CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
!! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
!! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
!! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
!! LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
!! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
!! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!!
!! Questions? Contact Karen Devine [email protected]
!! Erik Boman [email protected]
!!
!!!!**********************************************************************
!!
!! @HEADER
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! //
!! File: driver.cc //
!! Project: Local HSFC Ordering //
!! Author: Michael Wolf //
!! Date Started: 11/02/2009 //
!! //
!! Description: //
!! File tests local HSFC ordering for simple test problem //
!! //
!! $Id: driver.cc 11 2009-11-10 00:15:18Z mmwolf $ //
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
program exampleRCB
use mpi_h
use zoltan
use zoltanRCBex
implicit none
integer(Zoltan_INT) :: error
real(Zoltan_FLOAT) :: version
!!! numGlobObjs, numLocObjs, GIDs, xcoords, ycoords defined in zoltanRCBex module
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
interface
subroutine readInputObjects(fname,numGlobObjs,numLocObjs,GIDs,xs,ys)
character (len=*) :: fname
integer :: numGlobObjs, numLocObjs
integer, allocatable :: GIDs(:)
real, allocatable :: xs(:), ys(:)
end subroutine readInputObjects
end interface
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Body of program
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call MPI_Init(error)
error = Zoltan_Initialize(version)
call readInputObjects("mesh.txt",numGlobObjs,numLocObjs,GIDs,xcoords,ycoords)
call partitionMeshWithRCB()
call visualizePartition()
deallocate(GIDs)
deallocate(xcoords,ycoords)
!! function in zoltanRCBex module that cleans up Zoltan data structures
call zoltanCleanUp()
call MPI_Finalize(error)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end program exampleRCB
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine readInputObjects(fname, numGlobObjs, numLocObjs,GIDs,xcoords,ycoords)
use mpi_h
implicit none
character (len=*) :: fname
integer :: numGlobObjs, numLocObjs
integer, allocatable :: GIDs(:)
real, allocatable :: xcoords(:), ycoords(:)
! Local declarations
integer :: fnum = 2, i, currIndx
integer :: myRank, numProcs, mpi_ierr
integer :: tmpGID
real :: tmpX, tmpY
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call MPI_Comm_rank(MPI_COMM_WORLD, myrank, mpi_ierr)
call MPI_Comm_size(MPI_COMM_WORLD, numProcs, mpi_ierr)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Scan data to determine # local objects
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
open(unit = fnum, file = fname)
read(fnum,*) numGlobObjs
numLocObjs=0
do i = 1, numGlobObjs, 1
read(fnum,*) tmpGID, tmpX, tmpY
!! assumes gids start at 1, gives round robin initial distribution
if ( MOD(tmpGID-1,numProcs) == myRank) then
numLocObjs = numLocObjs + 1
end if
end do
close(fnum)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Allocate data for my part of mesh
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
allocate(GIDs(numLocObjs))
allocate(xcoords(numLocObjs))
allocate(ycoords(numLocObjs))
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Fill data for my part of mesh
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
open(unit = fnum, file = fname)
read(fnum,*) numGlobObjs
currIndx = 1
do i = 1, numGlobObjs, 1
read(fnum,*) tmpGID, tmpX, tmpY
!! assumes gids start at 1, gives round robin initial distribution
if ( MOD(tmpGID-1,numProcs) == myRank) then
GIDs(currIndx) = tmpGID
xcoords(currIndx) = tmpX
ycoords(currIndx) = tmpY
currIndx = currIndx + 1
end if
end do
close(fnum)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end subroutine readInputObjects
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Works for this specific 6x6 mesh
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine showSimpleMeshPartitions(myProc, numIDs, GIDs, parts)
use mpi_h
implicit none
integer :: myProc, numIDs
integer :: GIDs(*), parts(*)
!! Local variables
integer :: partAssign(36)
integer :: allPartAssign(36)
integer :: i, j, part, mpi_ierr
integer :: partRow(6)
data partAssign/ 36 * 0/
do i = 1, numIDs, 1
partAssign(GIDs(i)) = parts(i);
end do
call MPI_Reduce(partAssign, allPartAssign, 36, MPI_INTEGER, MPI_MAX, 0, MPI_COMM_WORLD, mpi_ierr);
if (myProc == 0) then
do i=30, 0, -6
do j = 1, 6, 1
partRow(j) = allPartAssign(i+j);
end do
write(*,'(I1,A,I1,A,I1,A,I1,A,I1,A,I1)') partRow(1), '-----', partRow(2), '-----', partRow(3), '-----', &
partRow(4), '-----', partRow(5), '-----', partRow(6)
if (i > 0) then
write(*,'(A)') '| | | | | |'
end if
end do
write(*,*)
end if
end subroutine showSimpleMeshPartitions
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine visualizePartition()
use mpi_h
use zoltanRCBex
implicit none
!! Variables defined in zoltanRCBex module:
!! numLocObjs, GIDs, numExport, exportLocalGids, exportToPart
!! local variables
integer :: parts(numLocObjs)
integer :: myrank, i, error
call MPI_Comm_rank(MPI_COMM_WORLD, myrank, error)
do i=1, numLocObjs, 1
parts(i) = myRank;
end do
if (myRank== 0) then
write (*,*) 'Mesh part assignments before calling Zoltan'
end if
call showSimpleMeshPartitions(myRank, numLocObjs, GIDs, parts);
do i=1, numExport, 1
parts(exportLocalGids(i)) = exportToPart(i)
end do
if (myRank == 0) then
write (*,*) 'Mesh part assignments after calling Zoltan'
end if
call showSimpleMeshPartitions(myRank, numLocObjs, GIDs, parts)
end subroutine visualizePartition
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
# Trends and cycles in unemployment
Here we consider three methods for separating a trend and cycle in economic data. Supposing we have a time series $y_t$, the basic idea is to decompose it into these two components:
$$
y_t = \mu_t + \eta_t
$$
where $\mu_t$ represents the trend or level and $\eta_t$ represents the cyclical component. In this case, we consider a *stochastic* trend, so that $\mu_t$ is a random variable and not a deterministic function of time. Two of methods fall under the heading of "unobserved components" models, and the third is the popular Hodrick-Prescott (HP) filter. Consistent with e.g. Harvey and Jaeger (1993), we find that these models all produce similar decompositions.
This notebook demonstrates applying these models to separate trend from cycle in the U.S. unemployment rate.
```python
%matplotlib inline
```
```python
import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
```
```python
try:
from pandas_datareader.data import DataReader
except ImportError:
from pandas.io.data import DataReader
endog = DataReader('UNRATE', 'fred', start='1954-01-01')
```
### Hodrick-Prescott (HP) filter
The first method is the Hodrick-Prescott filter, which can be applied to a data series in a very straightforward method. Here we specify the parameter $\lambda=129600$ because the unemployment rate is observed monthly.
```python
hp_cycle, hp_trend = sm.tsa.filters.hpfilter(endog, lamb=129600)
```
### Unobserved components and ARIMA model (UC-ARIMA)
The next method is an unobserved components model, where the trend is modeled as a random walk and the cycle is modeled with an ARIMA model - in particular, here we use an AR(4) model. The process for the time series can be written as:
$$
\begin{align}
y_t & = \mu_t + \eta_t \\
\mu_{t+1} & = \mu_t + \epsilon_{t+1} \\
\phi(L) \eta_t & = \nu_t
\end{align}
$$
where $\phi(L)$ is the AR(4) lag polynomial and $\epsilon_t$ and $\nu_t$ are white noise.
```python
mod_ucarima = sm.tsa.UnobservedComponents(endog, 'rwalk', autoregressive=4)
# Here the powell method is used, since it achieves a
# higher loglikelihood than the default L-BFGS method
res_ucarima = mod_ucarima.fit(method='powell')
print(res_ucarima.summary())
```
### Unobserved components with stochastic cycle (UC)
The final method is also an unobserved components model, but where the cycle is modeled explicitly.
$$
\begin{align}
y_t & = \mu_t + \eta_t \\
\mu_{t+1} & = \mu_t + \epsilon_{t+1} \\
\eta_{t+1} & = \eta_t \cos \lambda_\eta + \eta_t^* \sin \lambda_\eta + \tilde \omega_t \qquad & \tilde \omega_t \sim N(0, \sigma_{\tilde \omega}^2) \\
\eta_{t+1}^* & = -\eta_t \sin \lambda_\eta + \eta_t^* \cos \lambda_\eta + \tilde \omega_t^* & \tilde \omega_t^* \sim N(0, \sigma_{\tilde \omega}^2)
\end{align}
$$
```python
mod_uc = sm.tsa.UnobservedComponents(
endog, 'rwalk',
cycle=True, stochastic_cycle=True, damped_cycle=True,
)
# Here the powell method gets close to the optimum
res_uc = mod_uc.fit(method='powell')
# but to get to the highest loglikelihood we do a
# second round using the L-BFGS method.
res_uc = mod_uc.fit(res_uc.params)
print(res_uc.summary())
```
### Graphical comparison
The output of each of these models is an estimate of the trend component $\mu_t$ and an estimate of the cyclical component $\eta_t$. Qualitatively the estimates of trend and cycle are very similar, although the trend component from the HP filter is somewhat more variable than those from the unobserved components models. This means that relatively mode of the movement in the unemployment rate is attributed to changes in the underlying trend rather than to temporary cyclical movements.
```python
fig, axes = plt.subplots(2, figsize=(13,5));
axes[0].set(title='Level/trend component')
axes[0].plot(endog.index, res_uc.level.smoothed, label='UC')
axes[0].plot(endog.index, res_ucarima.level.smoothed, label='UC-ARIMA(2,0)')
axes[0].plot(hp_trend, label='HP Filter')
axes[0].legend(loc='upper left')
axes[0].grid()
axes[1].set(title='Cycle component')
axes[1].plot(endog.index, res_uc.cycle.smoothed, label='UC')
axes[1].plot(endog.index, res_ucarima.autoregressive.smoothed, label='UC-ARIMA(2,0)')
axes[1].plot(hp_cycle, label='HP Filter')
axes[1].legend(loc='upper left')
axes[1].grid()
fig.tight_layout();
```
|
function imgs = modcrop(imgs, modulo)
for i = 1:numel(imgs)
sz = size(imgs{i});
sz = sz - mod(sz, modulo);
imgs{i} = imgs{i}(1:sz(1), 1:sz(2));
end
|
import data.real.basic
--OUTPUT 1
theorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=
begin
have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 9 / 2, from by {
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
rw [div_add_div_same, div_add_div_same, div_add_div_same],
end --Needs more than 2000 tokens!
--OUTPUT 2
theorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=
begin
have h1 : 0 < (a + b + c), from by {apply lt_add_of_pos_of_pos,exact ha,exact lt_add_of_pos_of_pos hb hc},
have h2 : (a + b + c) / 2 = (3 / 2) * (a + b + c), from by {rw mul_div_cancel,exact h1,ring},
have h3 : (a + b + c) / 2 = (a / (b + c)) + (b / (a + c)) + (c / (a + b)), from by {rw [mul_div_cancel,mul_div_cancel,mul_div_cancel,mul_div_cancel],
exact h1,exact hb,exact hc,exact ha,ring},
have h4 : (a + b + c) / 2 ≥ (3 / 2) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)), from by {rw [mul_div_cancel,mul_div_cancel,mul_div_cancel,mul_div_cancel],
exact h1,exact hb,exact hc,exact ha,apply arithmetic_mean_ge_harmonic_mean,},
have h5 : (3 / 2) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) = (3 / 2) * (1 / (b + c) + 1 / (a + c)) + (3 / 2) * (1 / (a + b)), from by ring,
have h6 : (3 / 2) * (1 / (b + c) + 1 / (a + c)) = (a + b + c) / ((b + c) + (a + c)), from by ring,
have h7 : (3 / 2) * (1 / (a + b)) = (a + b + c) / ((a + b) + (a + b + c)), from by ring,
have h8 : (a + b + c) / ((b + c) + (a + c)) + (a + b + c) / ((a + b) + (a + b + c)) = (a + b + c) / 2, from by ring,
have h9 : (3 / 2) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) = (a + b + c) / 2, from by {rw [h5,h6,h7,h8],},
show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2), from by {rw [h3,h9],exact h4,},
end
--OUTPUT 3
theorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=
begin
have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 9 / 2, from by {
have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (9 * (a + b + c)) / ((b + c) + (a + c) + (a + b)), from by {
have h3 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 3, from by {
rw [div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv],
have h4 : (a + b + c) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) = (a + b + c) * (2 / 3), from by {
rw [div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv,div_eq_mul_inv],
have h5 : (a + b + c) * (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) = ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))), from by {
rw [mul_add,mul_add,mul_add],
ring,
},
have h6 : ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) = ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))), from by {
rw [mul_add,mul_add,mul_add,mul_add,mul_add,mul_add],
ring,
},
have h7 : ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) = ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))), from by {
rw [mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add],
ring,
},
have h8 : ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) = ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))), from by {
rw [mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add],
ring,
},
have h9 : ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) = ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))) + ((a + b + c) * (1 / (b + c))) + ((a + b + c) * (1 / (a + c))) + ((a + b + c) * (1 / (a + b))), from by {
rw [mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add,mul_add],
ring,
},
have h10 : ((a + b + c) * (1 / (b +
end --Needs more than 2000 tokens!
--OUTPUT 4
theorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=
begin
calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ 3 * (1 / ((b + c) + (a + c) + (a + b))) : by {
rw [← add_halves,← add_halves,← add_halves,← add_halves,← add_halves,← add_halves],
rw [← div_add_div_same,← div_add_div_same,← div_add_div_same,← div_add_div_same,← div_add_div_same,← div_add_div_same],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [← mul_div_cancel_left,← mul_div_cancel_left,← mul_div_cancel_left],
rw [←
end --Needs more than 2000 tokens!
--OUTPUT 5
theorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=
begin
have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (9 * (a + b + c)) / (2 * (b + c + a + c + a + b)),
from by {rw mul_comm, rw mul_comm _ 2, apply arithmetic_mean_is_never_less_than_harmonic_mean,ring},
have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (3 * (a + b + c)) / (b + c + a + c + a + b),
from by {rw ← mul_assoc, rw mul_comm, rw mul_comm _ 3, apply h1, ring},
have h3 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 3 / 2,
from by {rw ← mul_assoc, rw mul_comm, rw mul_comm _ 3, apply h1, ring},
have h4 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ 3 / 2,
from by {rw ← mul_assoc, rw mul_comm, rw mul_comm _ 3, apply h1, ring},
show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ 3 / 2, from h4
end
--OUTPUT 6
theorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=
begin
have h1 : 0 < (a + b + c), from by {apply add_pos,exact ha,exact hb,exact hc},
have h2 : (a + b + c) / 2 = (3 / 2) * (a + b + c), from by {rw [div_mul_cancel h1,two_mul],},
have h3 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (9 / 2) * (a + b + c), from by {
rw [←h2,←h2,←h2,←h2,←h2,←h2],
apply am_ge_hm,
obviously,},
have h4 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (3 / 2) * (a + b + c), from by {
rw [←h2,←h2,←h2,←h2,←h2,←h2],
apply am_ge_hm,
obviously,},
have h5 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2), from by {
rw [←h2,←h2,←h2,←h2,←h2,←h2],
apply am_ge_hm,
obviously,},
show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2), from h5,
end
/- FEW SHOT PROMPTS TO CODEX(START)
/--`theorem`
Power Set is Closed under Intersection
Let $S$ be a set.
Let $\powerset S$ be the power set of $S$.
Then:
:$\forall A, B \in \powerset S: A \cap B \in \powerset S$
`proof`
Let $A, B \in \powerset S$.
Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$.
From Intersection is Subset we have that $A \cap B \subseteq A$.
It follows from Subset Relation is Transitive that $A \cap B \subseteq S$.
Thus $A \cap B \in \powerset S$ and closure is proved.
{{qed}}
-/
theorem power_set_intersection_closed {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S :=
begin
assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),
have h1 : (A ⊆ S) ∧ (B ⊆ S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB},
have h2 : (A ∩ B) ⊆ A, from by apply set.inter_subset_left,
have h3 : (A ∩ B) ⊆ S, from by {apply set.subset.trans h2 h1.left},
show (A ∩ B) ∈ 𝒫 S, from by {apply set.mem_powerset h3},
end
/--`theorem`
Square of Sum
:$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$
`proof`
Follows from the distribution of multiplication over addition:
{{begin-eqn}}
{{eqn | l = \left({x + y}\right)^2
| r = \left({x + y}\right) \cdot \left({x + y}\right)
}}
{{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right)
| c = Real Multiplication Distributes over Addition
}}
{{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y
| c = Real Multiplication Distributes over Addition
}}
{{eqn | r = x^2 + 2xy + y^2
| c =
}}
{{end-eqn}}
{{qed}}
-/
theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) :=
begin
calc (x + y)^2 = (x+y)*(x+y) : by rw sq
... = x*(x+y) + y*(x+y) : by rw add_mul
... = x*x + x*y + y*x + y*y : by {rw [mul_comm x (x+y),mul_comm y (x+y)], rw [add_mul,add_mul], ring}
... = x^2 + 2*x*y + y^2 : by {repeat {rw ← sq}, rw mul_comm y x, ring}
end
/--`theorem`
Identity of Group is Unique
Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$.
`proof`
From Group has Latin Square Property, there exists a unique $x \in G$ such that:
:$a x = b$
and there exists a unique $y \in G$ such that:
:$y a = b$
Setting $b = a$, this becomes:
There exists a unique $x \in G$ such that:
:$a x = a$
and there exists a unique $y \in G$ such that:
:$y a = a$
These $x$ and $y$ are both $e$, by definition of identity element.
{{qed}}
-/
theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a :=
begin
have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by {
assume a b : G, use a⁻¹ * b, obviously, },
have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by {
assume a b : G, use b * a⁻¹, obviously, },
have h3 : ∀ a : G, ∃! x : G, a * x = a, from
assume a : G, h1 a a,
have h4 : ∀ a : G, ∃! y : G, y * a = a, from
assume a : G, h2 a a,
have h5 : ∀ a : G, classical.some (h3 a).exists = (1 : G), from assume a :G,
exists_unique.unique (h3 a) (classical.some_spec (exists_unique.exists (h3 a)))
(mul_one a),
have h6 : ∀ a : G, classical.some (h4 a).exists = (1 : G), from assume a : G,
exists_unique.unique (h4 a) (classical.some_spec (exists_unique.exists (h4 a))) (one_mul a),
show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by {
use (1 : G),
have h7 : ∀ e : G, (∀ a : G, e * a = a ∧ a * e = a) → e = 1, from by {
assume (e : G) (hident : ∀ a : G, e * a = a ∧ a * e = a),
have h8 : ∀ a : G, e = classical.some (h3 a).exists, from assume (a : G),
exists_unique.unique (h3 a) (hident a).right
(classical.some_spec (exists_unique.exists (h3 a))),
have h9 : ∀ a : G, e = classical.some (h4 a).exists, from assume (a : G),
exists_unique.unique (h4 a) (hident a).left
(classical.some_spec (exists_unique.exists (h4 a))),
show e = (1 : G), from eq.trans (h9 e) (h6 _),
},
exact ⟨by obviously, h7⟩,
}
end
/--`theorem`
Nesbitt's inequality
Let $a$, $b$ and $c$ be positive real numbers.
Then:
:$\dfrac a {b + c} + \dfrac b {a + c} + \dfrac c {a + b} \ge \dfrac 3 2$
`proof`
{{begin-eqn}}
{{eqn | l = \frac a {b + c} + \frac b {a + c} + \frac c {a + b}
| o = \ge
| r = \dfrac 3 2
}}
{{eqn | ll= \leadstoandfrom
| l = \frac {a + b + c} {b + c} + \frac {a + b + c} {a + c} + \frac {a + b + c} {a + b}
| o = \ge
| r = \frac 9 2
| c = by adding $3$
}}
{{eqn | ll= \leadstoandfrom
| l = \frac {a + b + c} {b + c} + \frac {a + b + c} {a + c} + \frac {a + b + c} {a + b}
| o = \ge
| r = \frac {9 \paren {a + b + c} } {\paren {b + c} + \paren {a + c} + \paren {a + b} }
| c = as $\dfrac {a + b + c} {\paren {b + c} + \paren {a + c} + \paren {a + b} } = \dfrac 1 2$
}}
{{eqn | ll= \leadstoandfrom
| l = \frac {\frac 1 {b + c} + \frac 1 {a + c} + \frac 1 {a + b} } 3
| o = \ge
| r = \frac 3 {\paren {b + c} + \paren {a + c} + \paren {a + b} }
| c = dividing by $3 \paren {a + b + c}$
}}
{{end-eqn}}
These are the arithmetic mean and the harmonic mean of $\dfrac 1 {b + c}$, $\dfrac 1 {a + c}$ and $\dfrac 1 {a + b}$.
From Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.
Thus Nesbitt's Inequality holds.
{{qed}}
-/
theorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=
FEW SHOT PROMPTS TO CODEX(END)-/
|
example : String
example = ?example
|
= = Election of Clement XIV = =
|
func $ceilf64toi32 (
var %i f64
) i32 {
return (
ceil i32 f64(dread f64 %i))}
func $ceilf64toi64 (
var %i f64
) i64 {
return (
ceil i64 f64(dread f64 %i))}
func $ceilf32toi32 (
var %i f32
) i32 {
return (
ceil i32 f32(dread f32 %i))}
func $ceilf32toi64 (
var %i f32
) i64 {
return (
ceil i64 f32(dread f32 %i))}
# todo float ceil
# EXEC: %irbuild Main.mpl
# EXEC: %irbuild Main.irb.mpl
# EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl
|
c { dg-do compile }
c { dg-options "-fopenmp -fdump-tree-omplower" }
!$omp parallel
call bar
c$omp end parallel
C$omp p
*$omp+arallel
call bar
!$omp e
!$omp+ndparallel
end
! { dg-final { scan-tree-dump-times "pragma omp parallel" 2 "omplower" } }
|
Formal statement is: lemma analytic_on_mult [analytic_intros]: assumes f: "f analytic_on S" and g: "g analytic_on S" shows "(\<lambda>z. f z * g z) analytic_on S" Informal statement is: If $f$ and $g$ are analytic on a set $S$, then $f \cdot g$ is analytic on $S$. |
%% Copyright (C) 2016 Lagu
%% Copyright (C) 2019 Colin B. Macdonald
%%
%% 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 hilb (@var{n})
%% Return the symbolic Hilbert matrix.
%%
%% Example:
%% @example
%% @group
%% hilb (sym(2))
%% @result{} ans = (sym 2×2 matrix)
%% ⎡ 1 1/2⎤
%% ⎢ ⎥
%% ⎣1/2 1/3⎦
%% @end group
%% @end example
%%
%% @seealso{@@sym/invhilb}
%% @end defmethod
function y = hilb(x)
if (nargin ~= 1)
print_usage ();
end
y = pycall_sympy__ ('return Matrix(_ins[0], _ins[0], lambda i,j: 1 / (i + j + 1)),', x);
end
%!test
%! A = hilb (sym(3));
%! B = [sym(1) sym(1)/2 sym(1)/3; sym(1)/2 sym(1)/3 sym(1)/4; sym(1)/3 sym(1)/4 sym(1)/5];
%! assert (isequal (A, B))
|
open classical
variables (α : Type) (p q : α -> Prop)
variable a : α
variable r : Prop
variable z : Prop
theorem dne {z: Prop} (h: ¬¬z): z :=
by_contradiction
(assume h1 : not z,
show false, from h h1)
example : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) :=
iff.intro
(assume h: ∀ x, p x,
assume h2 : ∃ x, ¬p x,
match h2 with ⟨x, hnp⟩ :=
show false, from hnp (h x)
end)
(assume h: ¬(∃ x, ¬p x),
have h1: ∀ x, ¬¬p x, from forall_not_of_not_exists h,
show ∀ x, p x, from
assume x,
show p x, from dne (h1 x))
|
using ImageMethodReverb, Random, WAV, LinearAlgebra
Fs = 16e3 # sampling frequency
T60 = 0.9 # reverberation time
xs = [1, 2, 2] #src pos (in meters)
xr = [2, 1.5, 1] #mic pos
L = Lx, Ly, Lz = 4.,4.,4. # room dimensions in meters
Nt = round(Int,Fs) #time samples 1 sec
h_se, = rim(xs,xr,L,0.93.*ones(6),Nt,Fs; Rd=0) # with sweeping echo
h, = rim(xs,xr,L,0.93.*ones(6),Nt,Fs) # without sweeping echo
wavplay(0.8 .* h_se ./ norm(h,Inf),Fs)
wavplay(0.8 .* h ./ norm(h,Inf),Fs)
using Plots, FFTW
f = rfftfreq(Nt,Fs)
t = range(0; length = Nt, step = 1/Fs )
p1 = plot(t, h_se, xlabel="Time (t)", ylabel="Sound Pressure (Pa)")
plot!(p1, t, h)
p2 = plot(f, 10 .* log10.(abs.(rfft(h_se))),
xlabel="Frequency (Hz)",
ylabel="Sound Pressure (dB)",
xlim=[50;500],
)
plot!(p2, f, 10 .* log10.(abs.(rfft(h))))
plot(p1,p2)
|
Getting your contracts in writing is half the battle. You must also ensure that your contract says what you want it to say, and says it clearly.
The main issue in the case below was the interpretation of an employment agreement (the “Agreement”), between Joshua Medad (“Medad”) and Hope House Charities (“Hope House”) (see Medad v Hope, 2016 ONSC 3323 (CanLII)).
Hope House is a registered charity with a mission to provide a safe space for adolescents looking for support. It hired Medad as Director of Programming. Prior to joining Hope House, Medad had operated his own charitable organization to assist at–risk and homeless youth.
The relationship between the parties deteriorated, and Hope House terminated Medad, less than a year into his employment contract. At the time they signed the Agreement, and at the time Hope House terminated Medad, there was no agreement between Hope House and the Toronto District School Board (“TDSB”).
2. … In the event that either party wish to terminate this agreement, either party must provide at least 1 year of notice to the other side, in order to provide continuity to the TDSB agreement for a full school year.
Medad claimed a year of notice pay, on the basis of Paragraph 2.
A Deputy Judge at the Small Claims Court concluded that Hope House did not have just cause to terminate Medad, and that, in accordance with the Agreement, Medad was entitled to one year’s notice pay.
Did not follow the strict principles of contract interpretation, by failing to give the termination provision its plain and ordinary grammatical meaning and by failing to interpret the provision in light of the entire Agreement and in light of its purposes and commercial context.
Failed to identify that the termination provision is a condition precedent, dependent on the TDSB. In other words, for the termination provision between Medad and Hope House to be effective, there had to be an agreement between Hope House and the TDSB. If there was no agreement between Hope House and the TDSB, the termination provision is unenforceable and Hope House did not have to give Medad a year’s notice.
Should have based Medad’s notice period on the common law principles of reasonable notice, since the termination provision in the Agreement was unenforceable. Hope House submitted that given Medad’s brief period of employment, his young age and his low level of remuneration, two weeks would be reasonable notice under common law.
Do you agree with Hope House’s position and its interpretation of Paragraph 2?
Contractual interpretation involves a practical, common sense approach.
What is important is to determine the intent of the parties given the ordinary and grammatical meaning of the words themselves and the contract as a whole.
Before Medad joined Hope House he had his own charitable organization and was giving it up to join Hope House. Therefore, it was reasonable that Medad required sufficient notice of termination to protect his interests.
The parties did not appear to have any intention to make the one year notice provision conditional on a TDSB agreement. For instance, they never discussed what would happen if there was no TDSB agreement.
Paragraph 2 does not create a condition precedent, whereby an agreement between Hope House and the TDSB was necessary before the termination provision could apply. Instead, under the plain wording of Paragraph 2, an agreement with the TDSB was at most a reason for the notice, but not a condition for the notice to apply.
Hope House lost its Appeal, and the employee won the right to a year’s notice pay.
In Part 1 of this series, we reminded you to put agreements in writing, but cautioned that this did not provide perfect inoculation against lawsuits—litigants often misunderstand the obvious; provisions may be open to multiple interpretations; and people sue even when they have no case.
In Part 2, an employee and her employer entered into an unwritten employment contract, and ended up in court with “very different views of their meetings, conversations, and the ultimate terms of the employment agreement.” This forced the court to piece together testimony and the facts at the time the contract was made, to determine the nature of contract. That process would likely have been less time-consuming, subjective and expensive, if the parties had a written contract.
Finally, in Part 3, above, we examine some of the principles of contract interpretation which courts use to interpret written contracts that are ambiguous; when parties have a different take on what the contract provision means; and when, as the Judge said in this case, the provision is “inelegant and awkward”.
You can read Part 1 of this series here and Part 2 here. |
function clu = updateclu(clu,ix,newclu)
% updates identities in parts of a clu file
%% INPUTS
% clu - N x 1 vector of cluster identities for each extracted waveform
% ix - M x 1 vector of indices where new identities will be assigned
% newclu - integer value for the new cluster identity
%% OUTPUTS
% clu - N x 1 vector of updated cluster identities
% updated 2017/02/24 by David Tingley
for ii=1:length(ix)
clu(clu==ix(ii))=newclu;
end
% ix = unique(clu);
% for ii=1:length(ix)
% clu(clu==ix(ii))=ii;
% end
|
If two topological spaces are homeomorphic, then they are compact if and only if they are compact. |
About 60 % of antimony is consumed in flame retardants , and 20 % is used in alloys for batteries , plain bearings and solders .
|
Load LFindLoad.
Load LFindLoad.
From adtind Require Import goal10.
From lfind Require Import LFind.
Lemma lfind_state (n:natural) (l1:lst) (n0:natural) (l2:lst) (IHl2:@eq lst (rev (append (Cons n l1) l2)) (append (rev l2) (rev (Cons n l1)))):@eq lst (append (rev (append l1 (Cons n0 l2))) (Cons n Nil))
(append (append (rev l2) (Cons n0 Nil)) (append (rev l1) (Cons n Nil))).
Admitted.
From QuickChick Require Import QuickChick.
QCInclude "/home/yousef/lemmafinder/benchmark/_lfind_clam_lf_goal10_rev_append_54_append_rev_Cons/".
QCInclude ".".
Extract Constant defNumTests => "50".
Derive Show for natural.
Derive Arbitrary for natural.
Instance Dec_Eq_natural : Dec_Eq natural.
Proof. dec_eq. Qed.
Derive Show for lst.
Derive Arbitrary for lst.
Instance Dec_Eq_lst : Dec_Eq lst.
Proof. dec_eq. Qed.
Open Scope string_scope.
Parameter print : natural -> string -> natural.
Extract Constant print => "Extract.print".
Definition collect_data (n:natural) (l1:lst) (n0:natural) (l2:lst) :=
let lfind_var := "n:" ++ "(" ++ show n ++ ")"++ "|" ++"l1:" ++ "(" ++ show l1 ++ ")"++ "|" ++"n0:" ++ "(" ++ show n0 ++ ")"++ "|" ++"l2:" ++ "(" ++ show l2 ++ ")"
in let lfind_v := print n lfind_var
in lfind_state lfind_v l1 n0 l2.
QuickChick collect_data.
Success. |
PROGRAM TEST
C+++
C.IDENTIFICATION
C PROGRAM TEST
C
C.PURPOSE
C TEST THE EXTRACTION OF FORTRAN EXTENSIONS FROM A SOURCE FILE
C
C---
PARAMETER (MAX_ARRAY=100)
C
IMPLICIT NONE
INTEGER I,N
REAL ARRAY(MAX_ARRAY,MAX_ARRAY)
REAL THIS_IS_REAL,RESULT
print *,' This is a test of lower case statement'
C
C TEST ENDDO
C
DO I = 1,MAX_ARRAY
DO N = 1,MAX_ARRAY
IF (I.EQ.N) GOTO 200
ARRAY(I,N) = I*K
200 ENDDO
ENDDO
C
C INITIATE VARIABLES
C
RESULT = 0.0E0 ! RESET RESULT
C
C NEXT TEST
C
DO I = 1,MAX_ARRAY
DO 100, N = 1,MAX_ARRAY
THIS_IS_REAL = RESULT + ARRAY(I,N)
100 CONTINUE
ENDDO
C
C CALL SUBROUTINE
C
CALL DUMMTEST(RESULT)
C
C END TEST
C
STOP
END
C
C
SUBROUTINE DUMMTEST(X)
IMPLICIT NONE
REAL X
C
X = X * X
C
RETURN
END
|
function hermite_cubic_test12 ( )
%*****************************************************************************80
%
%% HERMITE_CUBIC_TEST12 tests HERMITE_CUBIC_LAGRANGE_INTEGRAL.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 14 February 2011
%
% Author:
%
% John Burkardt
%
fprintf ( 1, '\n' );
fprintf ( 1, 'HERMITE_CUBIC_TEST12:\n' );
fprintf ( 1, ' HERMITE_CUBIC_LAGRANGE_INTEGRAL returns the integrals\n' );
fprintf ( 1, ' of the four Lagrange basis functions associated \n' );
fprintf ( 1, ' with F1, D1, F2 and D2 such that\n' );
fprintf ( 1, '\n' );
fprintf ( 1, ' P(X) = F1 * LF1(X) + D1 * LD1(X)\n' );
fprintf ( 1, ' + F2 * LF2(X) + D2 * LD2(X).\n' );
fprintf ( 1, '\n' );
fprintf ( 1, ' The Lagrange basis function integrals:\n' );
fprintf ( 1, '\n' );
fprintf ( 1, ' X1 X2 LF1 LD1 LF2 LD2\n' );
fprintf ( 1, '\n' );
x2 = 1.0;
for x1 = -6 : +2
q = hermite_cubic_lagrange_integral ( x1, x2 );
fprintf ( 1, ' %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f\n', ...
x1, x2, q(1:4) )
end
return
end
|
/*
* Copyright (c) 2010-2011 frankee zhou (frankee.zhou at gmail dot com)
*
* Distributed under under the Apache License, version 2.0 (the "License").
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
#include <boost/crc.hpp>
#include "cetty/channel/AbstractChannel.h"
#include "cetty/channel/ChannelState.h"
#include "cetty/channel/DownstreamMessageEvent.h"
#include "cetty/channel/DownstreamChannelStateEvent.h"
namespace cetty { namespace channel {
AbstractChannel::IdDeallocator AbstractChannel::ID_DEALLOCATOR;
AbstractChannel::ChannelMap AbstractChannel::allChannels;
int AbstractChannel::hashCode() const {
boost::crc_32_type crc32;
crc32.process_bytes((void const*)this, sizeof(this));
return crc32.checksum();
}
std::string AbstractChannel::toString() const {
char buf[512] = {0};
bool connected = isConnected();
if (connected && !strVal.empty()) {
return strVal;
}
const SocketAddress& localAddress = getLocalAddress();
const SocketAddress& remoteAddress = getRemoteAddress();
if (remoteAddress.validated()) {
if (NULL == getParent()) { // server channel or client channel
sprintf(buf, "[id: 0x%08x, %s => %s]", getId().intValue(),
localAddress.toString().c_str(),
remoteAddress.toString().c_str());
}
else { // connection channel
sprintf(buf, "[id: 0x%08x, %s => %s]", getId().intValue(),
remoteAddress.toString().c_str(),
localAddress.toString().c_str());
}
}
else if (localAddress.validated()) {
sprintf(buf, "[id: 0x%08x, %s]", getId().intValue(),
localAddress.toString().c_str());
}
else {
sprintf(buf, "[id: 0x%08x]", getId().intValue());
}
if (connected) {
strVal = (const char*)buf;
}
else {
strVal.empty();
}
return buf;
}
ChannelFuturePtr AbstractChannel::write(const ChannelMessage& message,
bool withFuture /*= true*/) {
return AbstractChannel::write(message, getRemoteAddress(), withFuture);
}
ChannelFuturePtr AbstractChannel::write(const ChannelMessage& message,
const SocketAddress& remoteAddress,
bool withFuture /*= true*/) {
ChannelFuturePtr future;
if (withFuture) {
future = Channels::future(*this);
}
pipeline->sendDownstream(DownstreamMessageEvent(*this, future, message, remoteAddress));
return future;
}
ChannelFuturePtr AbstractChannel::unbind() {
ChannelFuturePtr future = Channels::future(*this);
pipeline->sendDownstream(DownstreamChannelStateEvent(
*this, future, ChannelState::BOUND));
return future;
}
ChannelFuturePtr AbstractChannel::close() {
if (closeFuture->isDone()) {
return closeFuture;
}
pipeline->sendDownstream(DownstreamChannelStateEvent(
*this, closeFuture, ChannelState::OPEN));
return closeFuture;
}
ChannelFuturePtr AbstractChannel::disconnect() {
ChannelFuturePtr future = Channels::future(*this);
pipeline->sendDownstream(DownstreamChannelStateEvent(
*this, future, ChannelState::CONNECTED));
return future;
}
ChannelFuturePtr AbstractChannel::setInterestOps(int interestOps) {
interestOps = Channels::validateAndFilterDownstreamInteresOps(interestOps);
ChannelFuturePtr future = Channels::future(*this);
pipeline->sendDownstream(DownstreamChannelStateEvent(
*this, future, ChannelState::INTEREST_OPS, boost::any(interestOps)));
return future;
}
}} |
rebol [
title: "MYSQL test"
]
rss/run %mysql-protocol
db: open mysql://skejtak:[email protected]/skateshop
mysql-handler: func[port /local bytes ud ][
probe bytes: copy/part port 10
print ["MySQL read" length? bytes "bytes"]
]
networking/add-port db :mysql-handler |
[STATEMENT]
lemma fbox_star_unfold_var [simp]: "d z \<cdot> |x] |x\<^sup>\<star>] z = |x\<^sup>\<star>] z"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
1. d z \<cdot> |x] |x\<^sup>\<star>] z = |x\<^sup>\<star>] z
[PROOF STEP]
using fbox_star_unfold
[PROOF STATE]
proof (prove)
using this:
|(1::'a)] ?z \<cdot> |?x] |?x\<^sup>\<star>] ?z = |?x\<^sup>\<star>] ?z
goal (1 subgoal):
1. d z \<cdot> |x] |x\<^sup>\<star>] z = |x\<^sup>\<star>] z
[PROOF STEP]
by auto |
function [out] = saturation_9(In,S,St,varargin)
%saturation_9
% Copyright (C) 2019, 2021 Wouter J.M. Knoben, Luca Trotter
% This file is part of the Modular Assessment of Rainfall-Runoff Models
% Toolbox (MARRMoT).
% MARRMoT is a free software (GNU GPL v3) and distributed WITHOUT ANY
% WARRANTY. See <https://www.gnu.org/licenses/> for details.
% Flux function
% ------------------
% Description: Deficit store: Saturation excess from a store that has
% reached maximum capacity
% Constraints: -
% @(Inputs): In - incoming flux [mm/d]
% S - current storage [mm]
% St - threshold for flow generation [mm], 0 for deficit
% store
% varargin(1) - smoothing variable r (default 0.01)
% varargin(2) - smoothing variable e (default 5.00)
if size(varargin,2) == 0
out = In.*smoothThreshold_storage_logistic(S,St);
elseif size(varargin,2) == 1
out = In.*smoothThreshold_storage_logistic(S,St,varargin(1));
elseif size(varargin,2) == 2
out = In.*smoothThreshold_storage_logistic(S,St,varargin(1),varargin(2));
end
end
|
!##########################################################################
subroutine wall_function(bound,cond)
! Bruño Fraga Bugallo
! Cardiff 2014
! werner/wengle type boundary conditions
!##########################################################################
use vars
use multidata
implicit none
integer i,j,k,ib,bound,cond
double precision delta,n_x,n_y,n_z,vnor,vtan,dvtan,sub
double precision uc,vc,wc,rrey,small,dycell,rycell,vtankr
double precision tausub,taupow
double precision aaa,bbb,const1,const2,const3,const4
rrey=1.0/Re
small = 1.e-30
SELECT CASE (cond)
CASE (63)
!.....specify constants for 1/6 power law ..............................
data aaa, bbb
& / 8.3, 0.1666666666/
CASE (64)
!.....specify constants for 1/7 power law ..............................
data aaa, bbb
& / 8.3, 0.1428571429/
CASE (65)
!.....specify constants for 1/8 power law ..............................
data aaa, bbb
& / 8.3, 0.125/
end select
!.....constant factors .................................................
const1 = 0.5 * (1. - bbb) * aaa ** ((1. + bbb) / (1. - bbb))
const2 = (1. + bbb) / aaa
const3 = aaa ** (2. / (1. - bbb))
const4 = 2. / (1. + bbb)
do ib=1,nbp
SELECT CASE (bound)
CASE (1)
delta=0.5*dom(ib)%dx
n_x=1.0
n_y=0.0
n_z=0.0
i=dom(ib)%isp
do k=dom(ib)%ksp-1,dom(ib)%kep+1
do j=dom(ib)%jsp-1,dom(ib)%jep+1
uc=0.5*(dom(ib)%u(i,j,k)+dom(ib)%u(i-1,j,k))
vc=0.5*(dom(ib)%v(i,j,k)+dom(ib)%v(i,j-1,k))
wc=0.5*(dom(ib)%w(i,j,k)+dom(ib)%w(i,j,k-1))
vnor=n_x*uc+n_y*vc+n_z*wc
vtan=sqrt(abs(uc*uc+vc*vc+wc*wc-vnor*vnor+small))
dycell = 2. * delta
rycell = 1. / dycell
vtankr = 0.5 * rrey * rycell * const3
dvtan = vtankr - vtan
sub = MAX (SIGN(1.,dvtan),0.)
tausub = rrey * vtan / delta
taupow = ( const1 * (rrey * rycell)**(1.+bbb) +
& ( const2 * (rrey * rycell)**bbb) * vtan)
& ** const4
dom(ib)%tauww(j,k)=(sub*tausub+(1.-sub)*taupow) !tau_1
dom(ib)%tauww2(j,k)=dom(ib)%tauww(j,k)/vtan !needs to be multiplied by a velocity component to provide tau_1j
end do
end do
CASE (2)
delta=0.5*dom(ib)%dx
n_x=-1.0
n_y=0.0
n_z=0.0
i=dom(ib)%iep
do k=dom(ib)%ksp-1,dom(ib)%kep+1
do j=dom(ib)%jsp-1,dom(ib)%jep+1
uc=0.5*(dom(ib)%u(i,j,k)+dom(ib)%u(i-1,j,k))
vc=0.5*(dom(ib)%v(i,j,k)+dom(ib)%v(i,j-1,k))
wc=0.5*(dom(ib)%w(i,j,k)+dom(ib)%w(i,j,k-1))
vnor=n_x*uc+n_y*vc+n_z*wc
vtan=sqrt(abs(uc*uc+vc*vc+wc*wc-vnor*vnor+small))
dycell = 2. * delta
rycell = 1. / dycell
vtankr = 0.5 * rrey * rycell * const3
dvtan = vtankr - vtan
sub = MAX (SIGN(1.,dvtan),0.)
tausub = rrey * vtan / delta
taupow = ( const1 * (rrey * rycell)**(1.+bbb) +
& ( const2 * (rrey * rycell)**bbb) * vtan)
& ** const4
dom(ib)%tauwe(j,k)=(sub*tausub+(1.-sub)*taupow) !units m2/s2
dom(ib)%tauwe2(j,k)=dom(ib)%tauwe(j,k)/vtan !units m/s
end do
end do
CASE(3)
delta=0.5*dom(ib)%dy
n_x=0.0
n_y=1.0
n_z=0.0
j=dom(ib)%jsp
do k=dom(ib)%ksp-1,dom(ib)%kep+1
do i=dom(ib)%isp-1,dom(ib)%iep+1
uc=0.5*(dom(ib)%u(i,j,k)+dom(ib)%u(i-1,j,k))
vc=0.5*(dom(ib)%v(i,j,k)+dom(ib)%v(i,j-1,k))
wc=0.5*(dom(ib)%w(i,j,k)+dom(ib)%w(i,j,k-1))
vnor=n_x*uc+n_y*vc+n_z*wc
vtan=sqrt(abs(uc*uc+vc*vc+wc*wc-vnor*vnor+small))
dycell = 2. * delta
rycell = 1. / dycell
vtankr = 0.5 * rrey * rycell * const3
dvtan = vtankr - vtan
sub = MAX (SIGN(1.,dvtan),0.)
tausub = rrey * vtan / delta
taupow = ( const1 * (rrey * rycell)**(1.+bbb) +
& ( const2 * (rrey * rycell)**bbb) * vtan)
& ** const4
dom(ib)%tauws(i,k)=(sub*tausub+(1.-sub)*taupow)
dom(ib)%tauws2(i,k)=dom(ib)%tauws(i,k)/vtan
end do
end do
CASE (4)
delta=0.5*dom(ib)%dy
n_x=0.0
n_y=-1.0
n_z=0.0
j=dom(ib)%jep
do k=dom(ib)%ksp-1,dom(ib)%kep+1
do i=dom(ib)%isp-1,dom(ib)%iep+1
uc=0.5*(dom(ib)%u(i,j,k)+dom(ib)%u(i-1,j,k))
vc=0.5*(dom(ib)%v(i,j,k)+dom(ib)%v(i,j-1,k))
wc=0.5*(dom(ib)%w(i,j,k)+dom(ib)%w(i,j,k-1))
vnor=n_x*uc+n_y*vc+n_z*wc
vtan=sqrt(abs(uc*uc+vc*vc+wc*wc-vnor*vnor+small))
dycell = 2. * delta
rycell = 1. / dycell
vtankr = 0.5 * rrey * rycell * const3
dvtan = vtankr - vtan
sub = MAX (SIGN(1.,dvtan),0.)
tausub = rrey * vtan / delta
taupow = ( const1 * (rrey * rycell)**(1.+bbb) +
& ( const2 * (rrey * rycell)**bbb) * vtan)
& ** const4
dom(ib)%tauwn(i,k)=(sub*tausub+(1.-sub)*taupow)
dom(ib)%tauwn2(i,k)=dom(ib)%tauwn(i,k)/vtan
end do
end do
CASE (5)
delta=0.5*dom(ib)%dz
n_x=0.0
n_y=0.0
n_z=1.0
k=dom(ib)%ksp
do j=dom(ib)%jsp-1,dom(ib)%jep+1
do i=dom(ib)%isp-1,dom(ib)%iep+1
uc=0.5*(dom(ib)%u(i,j,k)+dom(ib)%u(i-1,j,k))
vc=0.5*(dom(ib)%v(i,j,k)+dom(ib)%v(i,j-1,k))
wc=0.5*(dom(ib)%w(i,j,k)+dom(ib)%w(i,j,k-1))
vnor=n_x*uc+n_y*vc+n_z*wc
vtan=sqrt(abs(uc*uc+vc*vc+wc*wc-vnor*vnor+small))
dycell = 2. * delta
rycell = 1. / dycell
vtankr = 0.5 * rrey * rycell * const3
dvtan = vtankr - vtan
sub = MAX (SIGN(1.,dvtan),0.)
tausub = rrey * vtan / delta
taupow = ( const1 * (rrey * rycell)**(1.+bbb) +
& ( const2 * (rrey * rycell)**bbb) * vtan)
& ** const4
dom(ib)%tauwb(i,j)=(sub*tausub+(1.-sub)*taupow)
dom(ib)%tauwb2(i,j)=dom(ib)%tauwb(i,j)/vtan
end do
end do
CASE (6)
delta=0.5*dom(ib)%dz
n_x=0.0
n_y=0.0
n_z=-1.0
k=dom(ib)%kep
do j=dom(ib)%jsp-1,dom(ib)%jep+1
do i=dom(ib)%isp-1,dom(ib)%iep+1
uc=0.5*(dom(ib)%u(i,j,k)+dom(ib)%u(i-1,j,k))
vc=0.5*(dom(ib)%v(i,j,k)+dom(ib)%v(i,j-1,k))
wc=0.5*(dom(ib)%w(i,j,k)+dom(ib)%w(i,j,k-1))
vnor=n_x*uc+n_y*vc+n_z*wc
vtan=sqrt(abs(uc*uc+vc*vc+wc*wc-vnor*vnor+small))
dycell = 2. * delta
rycell = 1. / dycell
vtankr = 0.5 * rrey * rycell * const3
dvtan = vtankr - vtan
sub = MAX (SIGN(1.,dvtan),0.)
tausub = rrey * vtan / delta
taupow = ( const1 * (rrey * rycell)**(1.+bbb) +
& ( const2 * (rrey * rycell)**bbb) * vtan)
& ** const4
dom(ib)%tauwt(i,j)=(sub*tausub+(1.-sub)*taupow)
dom(ib)%tauwt2(i,j)=dom(ib)%tauwt(i,j)/vtan
end do
end do
end select
end do
return
end subroutine wall_function
!##########################################################################
|
import data.real.basic data.real.nnreal algebra.order.complete_field
/-!
# Extension of function ℝ≥0 → α into an almost odd function ℝ → α
The "odd" extension g : ℝ → α of f : ℝ≥0 → α is given by g(x) = f(x) for x ≥ 0 and
g(x) = -f(-x) for x ≤ 0. If one also has f(0) = -f(0), g is indeed an odd function.
Here, α is any type with negation.
A more useful aspect of the odd extension is when α is an additive group or a ring,
and f is a group/ring homomorphism. Then we always have f(0) = 0, so g(0) is always odd.
Furthermore, the odd extension is also a group/ring homomorphism, except with domain ℝ.
TODO: Add a `coe_factor` lemma (any map ℝ≥0 →+* R factors through the coercion ℝ≥0 →+* ℝ)
-/
open real
open_locale nnreal classical
namespace IMOSL
namespace extra
private lemma nnabs_neg (r : ℝ) : (-r).nnabs = r.nnabs :=
by rw [← nnreal.coe_eq, coe_nnabs, coe_nnabs, abs_neg]
section function
/-- The odd extension as a function. It is not guaranteed to be odd, however.
For the lemmas, we assume that the negation is always involutive. -/
noncomputable def nnreal_odd_ext {α : Type*} [has_neg α] (f : ℝ≥0 → α) : ℝ → α :=
λ x, ite (0 ≤ x) (f x.nnabs) (-f x.nnabs)
variables {α : Type*} [has_involutive_neg α]
lemma nnreal_odd_ext_of_nnreal (f : ℝ≥0 → α) (x : ℝ≥0) :
nnreal_odd_ext f (x : ℝ) = f x :=
by simp only [nnreal_odd_ext, if_true, nnreal.zero_le_coe, nnabs_of_nonneg, to_nnreal_coe]
lemma nnreal_odd_ext_of_nonneg (f : ℝ≥0 → α) {x : ℝ} (h : 0 ≤ x) :
nnreal_odd_ext f x = f x.nnabs :=
by simp only [nnreal_odd_ext, if_true, h]
lemma nnreal_odd_ext_of_negative (f : ℝ≥0 → α) {x : ℝ} (h : x < 0) :
nnreal_odd_ext f x = -f x.nnabs :=
by rw ← not_le at h; simp only [nnreal_odd_ext, if_false, h]
/-- If α has involutive negation, then `nnreal_odd_ext` is odd except possibly at 0. -/
lemma nnreal_odd_ext_is_odd' (f : ℝ≥0 → α) {x : ℝ} (h : x ≠ 0) :
nnreal_odd_ext f (-x) = -nnreal_odd_ext f x :=
begin
simp only [nnreal_odd_ext, neg_nonneg, nnabs_neg],
rw ne_iff_lt_or_gt at h,
cases h with h h,
rw [if_neg (not_le_of_lt h), if_pos (le_of_lt h), neg_neg],
rw [if_neg (not_le_of_lt h), if_pos (le_of_lt h)]
end
/-- If α has involutive negation and -f(0) = f(0), then `nnreal_odd_ext` is indeed odd. -/
lemma nnreal_odd_ext_is_odd (f : ℝ≥0 → α) (h : - f 0 = f 0) (x : ℝ) :
nnreal_odd_ext f (-x) = -nnreal_odd_ext f x :=
begin
rcases eq_or_ne x 0 with rfl | h,
simp only [nnreal_odd_ext, if_true, le_refl, neg_zero, nnabs_of_nonneg, to_nnreal_zero, h],
exact nnreal_odd_ext_is_odd' f h
end
end function
section add_group_hom
variables {G : Type*} [add_group G]
/-- Extension of a homomorphism ℝ≥0 →+ G to ℝ →+ G. -/
noncomputable def nnreal_add_group_hom_ext (φ : ℝ≥0 →+ G) : ℝ →+ G :=
{ to_fun := nnreal_odd_ext φ,
map_zero' := by simp only [le_refl, nnreal_odd_ext,
if_true, nnabs_of_nonneg, to_nnreal_zero, map_zero],
map_add' := begin
have odd_ext_neg : ∀ x : ℝ, nnreal_odd_ext φ (-x) = -nnreal_odd_ext φ x :=
nnreal_odd_ext_is_odd φ (by rw [map_zero, neg_zero]),
suffices : ∀ x y : ℝ, 0 ≤ y →
nnreal_odd_ext ⇑φ (x + y) = nnreal_odd_ext ⇑φ x + nnreal_odd_ext ⇑φ y,
{ intros x y,
cases le_total 0 y with h h,
exact this x y h,
rw [← add_left_inj (nnreal_odd_ext ⇑φ (-y)), ← this _ _ (neg_nonneg.mpr h),
add_neg_cancel_right, odd_ext_neg, add_neg_cancel_right] },
have T : ∀ x y : ℝ, 0 ≤ x → 0 ≤ y →
nnreal_odd_ext ⇑φ (x + y) = nnreal_odd_ext ⇑φ x + nnreal_odd_ext ⇑φ y :=
begin
intros x y hx hy,
simp only [nnreal_odd_ext, hx, hy, add_nonneg, if_true, nnabs_of_nonneg],
rw [to_nnreal_add hx hy, map_add]
end,
intros x y hy,
cases le_total 0 x with hx hx,
exact T x y hx hy,
rw [← add_right_inj (-nnreal_odd_ext ⇑φ x), neg_add_cancel_left, ← odd_ext_neg],
rw ← neg_nonneg at hx,
cases le_total 0 (x + y) with hxy hxy,
rw [← T _ _ hx hxy, neg_add_cancel_left],
rw [← add_left_inj (-nnreal_odd_ext ⇑φ (x + y)), add_neg_cancel_right, ← odd_ext_neg,
← T _ _ hy (neg_nonneg.mpr hxy), neg_add_rev, add_neg_cancel_left]
end }
noncomputable instance nnreal_add_group_hom.has_coe_to_real_add_group_hom :
has_coe (ℝ≥0 →+ G) (ℝ →+ G) := ⟨nnreal_add_group_hom_ext⟩
end add_group_hom
section ring_hom
variables {R : Type*} [ring R]
noncomputable def nnreal_ring_hom_ext (φ : ℝ≥0 →+* R) : ℝ →+* R :=
{ map_one' := begin
have h : 0 ≤ (1 : ℝ) := zero_le_one,
simp only [nnreal_add_group_hom_ext, nnreal_odd_ext, ring_hom.to_add_monoid_hom_eq_coe],
rw [if_pos h, ring_hom.coe_add_monoid_hom, nnabs_of_nonneg h, to_nnreal_one, map_one]
end,
map_mul' := begin
simp only [ring_hom.to_add_monoid_hom_eq_coe,
nnreal_add_group_hom_ext, ring_hom.coe_add_monoid_hom],
have X := nnreal_odd_ext_is_odd φ (by rw [map_zero, neg_zero]),
suffices : ∀ x y : ℝ, 0 ≤ y →
nnreal_odd_ext ⇑φ (x * y) = nnreal_odd_ext ⇑φ x * nnreal_odd_ext ⇑φ y,
{ intros x y,
cases le_total 0 y with h h,
exact this x y h,
rw [← neg_neg y, X, mul_neg, X, this _ _ (neg_nonneg.mpr h), mul_neg] },
have T : ∀ x y : ℝ, 0 ≤ x → 0 ≤ y →
nnreal_odd_ext ⇑φ (x * y) = nnreal_odd_ext ⇑φ x * nnreal_odd_ext ⇑φ y :=
begin
intros x y hx hy,
simp only [nnreal_odd_ext, hx, hy, mul_nonneg, if_true, nnabs_of_nonneg],
rw [to_nnreal_mul hx, map_mul]
end,
intros x y hy,
cases le_total 0 x with hx hx,
exact T x y hx hy,
rw [← neg_neg x, X, neg_mul, X, T _ _ (neg_nonneg.mpr hx) hy, neg_mul]
end,
.. nnreal_add_group_hom_ext φ.to_add_monoid_hom }
namespace nnreal_ring_hom
noncomputable instance has_coe_to_real_ring_hom :
has_coe (ℝ≥0 →+* R) (ℝ →+* R) := ⟨nnreal_ring_hom_ext⟩
lemma coe_fn_apply (φ : ℝ≥0 →+* R) (x : ℝ≥0) : (φ : ℝ →+* R) x = φ x :=
by change ⇑(φ : ℝ →+* R) with nnreal_odd_ext φ; rw nnreal_odd_ext_of_nnreal
lemma coe_unique {φ : ℝ≥0 →+* R} {ρ : ℝ →+* R}
(h : ∀ x : ℝ≥0, ρ x = φ x) : ρ = (φ : ℝ →+* R) :=
begin
ext x,
change ⇑(φ : ℝ →+* R) with nnreal_odd_ext φ,
cases le_or_lt 0 x with h0 h0,
rw [nnreal_odd_ext_of_nonneg _ h0, ← h, coe_nnabs, abs_eq_self.mpr h0],
rw [nnreal_odd_ext_of_negative _ h0, ← h, coe_nnabs,
abs_eq_neg_self.mpr (le_of_lt h0), map_neg, neg_neg]
end
lemma coe_inj (φ ρ : ℝ≥0 →+* R) : (φ : ℝ →+* R) = (ρ : ℝ →+* R) ↔ φ = ρ :=
begin
symmetry; split,
rintros rfl; refl,
intros h; ext x,
rw [← coe_fn_apply, h, coe_fn_apply]
end
instance to_real_ring_hom_unique : unique (ℝ≥0 →+* ℝ) :=
{ default := nnreal.to_real_hom,
uniq := λ φ, by rw [← coe_inj, eq_iff_true_of_subsingleton]; trivial }
end nnreal_ring_hom
end ring_hom
end extra
end IMOSL
|
[GOAL]
⊢ stirlingSeq 0 = 0
[PROOFSTEP]
rw [stirlingSeq, cast_zero, mul_zero, Real.sqrt_zero, zero_mul, div_zero]
[GOAL]
⊢ stirlingSeq 1 = exp 1 / Real.sqrt 2
[PROOFSTEP]
rw [stirlingSeq, pow_one, factorial_one, cast_one, mul_one, mul_one_div, one_div_div]
[GOAL]
n : ℕ
⊢ Real.log (stirlingSeq (succ n)) =
Real.log ↑(succ n)! - 1 / 2 * Real.log (2 * ↑(succ n)) - ↑(succ n) * Real.log (↑(succ n) / exp 1)
[PROOFSTEP]
rw [stirlingSeq, log_div, log_mul, sqrt_eq_rpow, log_rpow, Real.log_pow, tsub_tsub]
[GOAL]
case hx
n : ℕ
⊢ 0 < 2 * ↑(succ n)
[PROOFSTEP]
positivity
[GOAL]
case hx
n : ℕ
⊢ Real.sqrt (2 * ↑(succ n)) ≠ 0
[PROOFSTEP]
positivity
[GOAL]
case hy
n : ℕ
⊢ (↑(succ n) / exp 1) ^ succ n ≠ 0
[PROOFSTEP]
positivity
[GOAL]
case hx
n : ℕ
⊢ ↑(succ n)! ≠ 0
[PROOFSTEP]
positivity
[GOAL]
case hy
n : ℕ
⊢ Real.sqrt (2 * ↑(succ n)) * (↑(succ n) / exp 1) ^ succ n ≠ 0
[PROOFSTEP]
positivity
[GOAL]
m : ℕ
⊢ HasSum (fun k => 1 / (2 * ↑(succ k) + 1) * ((1 / (2 * ↑(succ m) + 1)) ^ 2) ^ succ k)
(Real.log (stirlingSeq (succ m)) - Real.log (stirlingSeq (succ (succ m))))
[PROOFSTEP]
change HasSum ((fun b : ℕ => (1 : ℝ) / ((2 : ℝ) * b + (1 : ℝ)) * (((1 : ℝ) / (2 * m.succ + 1)) ^ 2) ^ b) ∘ succ) _
[GOAL]
m : ℕ
⊢ HasSum ((fun b => 1 / (2 * ↑b + 1) * ((1 / (2 * ↑(succ m) + 1)) ^ 2) ^ b) ∘ succ)
(Real.log (stirlingSeq (succ m)) - Real.log (stirlingSeq (succ (succ m))))
[PROOFSTEP]
refine'
(hasSum_nat_add_iff (a := _ - _)
-- Porting note: must give implicit arguments (f :=
(fun b : ℕ => ↑1 / (↑2 * b + ↑1) * (((1 : ℝ) / (2 * m.succ + 1)) ^ 2) ^ b)) 1).mpr
_
[GOAL]
m : ℕ
⊢ HasSum (fun b => 1 / (2 * ↑b + 1) * ((1 / (2 * ↑(succ m) + 1)) ^ 2) ^ b)
(Real.log (stirlingSeq (succ m)) - Real.log (stirlingSeq (succ (succ m))) +
∑ i in range 1, 1 / (2 * ↑i + 1) * ((1 / (2 * ↑(succ m) + 1)) ^ 2) ^ i)
[PROOFSTEP]
convert (hasSum_log_one_add_inv <| cast_pos.mpr (succ_pos m)).mul_left ((m.succ : ℝ) + 1 / 2) using 1
[GOAL]
case h.e'_5
m : ℕ
⊢ (fun b => 1 / (2 * ↑b + 1) * ((1 / (2 * ↑(succ m) + 1)) ^ 2) ^ b) = fun i =>
(↑(succ m) + 1 / 2) * (2 * (1 / (2 * ↑i + 1)) * (1 / (2 * ↑(succ m) + 1)) ^ (2 * i + 1))
[PROOFSTEP]
ext k
[GOAL]
case h.e'_5.h
m k : ℕ
⊢ 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(succ m) + 1)) ^ 2) ^ k =
(↑(succ m) + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * (1 / (2 * ↑(succ m) + 1)) ^ (2 * k + 1))
[PROOFSTEP]
rw [← pow_mul, pow_add]
[GOAL]
case h.e'_5.h
m k : ℕ
⊢ 1 / (2 * ↑k + 1) * (1 / (2 * ↑(succ m) + 1)) ^ (2 * k) =
(↑(succ m) + 1 / 2) *
(2 * (1 / (2 * ↑k + 1)) * ((1 / (2 * ↑(succ m) + 1)) ^ (2 * k) * (1 / (2 * ↑(succ m) + 1)) ^ 1))
[PROOFSTEP]
push_cast
[GOAL]
case h.e'_5.h
m k : ℕ
⊢ 1 / (2 * ↑k + 1) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k) =
(↑m + 1 + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * ((1 / (2 * (↑m + 1) + 1)) ^ (2 * k) * (1 / (2 * (↑m + 1) + 1)) ^ 1))
[PROOFSTEP]
have : 2 * (k : ℝ) + 1 ≠ 0 := by norm_cast; exact succ_ne_zero (2 * k)
[GOAL]
m k : ℕ
⊢ 2 * ↑k + 1 ≠ 0
[PROOFSTEP]
norm_cast
[GOAL]
m k : ℕ
⊢ ¬2 * k + 1 = 0
[PROOFSTEP]
exact succ_ne_zero (2 * k)
[GOAL]
case h.e'_5.h
m k : ℕ
this : 2 * ↑k + 1 ≠ 0
⊢ 1 / (2 * ↑k + 1) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k) =
(↑m + 1 + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * ((1 / (2 * (↑m + 1) + 1)) ^ (2 * k) * (1 / (2 * (↑m + 1) + 1)) ^ 1))
[PROOFSTEP]
have : 2 * ((m : ℝ) + 1) + 1 ≠ 0 := by norm_cast; exact succ_ne_zero (2 * m.succ)
[GOAL]
m k : ℕ
this : 2 * ↑k + 1 ≠ 0
⊢ 2 * (↑m + 1) + 1 ≠ 0
[PROOFSTEP]
norm_cast
[GOAL]
m k : ℕ
this : 2 * ↑k + 1 ≠ 0
⊢ ¬2 * (m + 1) + 1 = 0
[PROOFSTEP]
exact succ_ne_zero (2 * m.succ)
[GOAL]
case h.e'_5.h
m k : ℕ
this✝ : 2 * ↑k + 1 ≠ 0
this : 2 * (↑m + 1) + 1 ≠ 0
⊢ 1 / (2 * ↑k + 1) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k) =
(↑m + 1 + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * ((1 / (2 * (↑m + 1) + 1)) ^ (2 * k) * (1 / (2 * (↑m + 1) + 1)) ^ 1))
[PROOFSTEP]
field_simp
[GOAL]
case h.e'_5.h
m k : ℕ
this✝ : 2 * ↑k + 1 ≠ 0
this : 2 * (↑m + 1) + 1 ≠ 0
⊢ (2 * ↑k + 1) * ((2 * (↑m + 1) + 1) ^ (2 * k) * (2 * (↑m + 1) + 1)) =
((↑m + 1) * 2 + 1) * ((2 * ↑k + 1) * (2 * (↑m + 1) + 1) ^ (2 * k))
[PROOFSTEP]
ring
[GOAL]
case h.e'_6
m : ℕ
⊢ Real.log (stirlingSeq (succ m)) - Real.log (stirlingSeq (succ (succ m))) +
∑ i in range 1, 1 / (2 * ↑i + 1) * ((1 / (2 * ↑(succ m) + 1)) ^ 2) ^ i =
(↑(succ m) + 1 / 2) * Real.log (1 + (↑(succ m))⁻¹)
[PROOFSTEP]
have h : ∀ (x : ℝ) (_ : x ≠ 0), 1 + x⁻¹ = (x + 1) / x := by intro x hx; rw [_root_.add_div, div_self hx, inv_eq_one_div]
[GOAL]
m : ℕ
⊢ ∀ (x : ℝ), x ≠ 0 → 1 + x⁻¹ = (x + 1) / x
[PROOFSTEP]
intro x hx
[GOAL]
m : ℕ
x : ℝ
hx : x ≠ 0
⊢ 1 + x⁻¹ = (x + 1) / x
[PROOFSTEP]
rw [_root_.add_div, div_self hx, inv_eq_one_div]
[GOAL]
case h.e'_6
m : ℕ
h : ∀ (x : ℝ), x ≠ 0 → 1 + x⁻¹ = (x + 1) / x
⊢ Real.log (stirlingSeq (succ m)) - Real.log (stirlingSeq (succ (succ m))) +
∑ i in range 1, 1 / (2 * ↑i + 1) * ((1 / (2 * ↑(succ m) + 1)) ^ 2) ^ i =
(↑(succ m) + 1 / 2) * Real.log (1 + (↑(succ m))⁻¹)
[PROOFSTEP]
simp (disch :=
norm_cast <;> apply_rules [mul_ne_zero, succ_ne_zero, factorial_ne_zero, exp_ne_zero]) only [log_stirlingSeq_formula,
log_div, log_mul, log_exp, factorial_succ, cast_mul, cast_succ, cast_zero, range_one, sum_singleton, h]
[GOAL]
case h.e'_6
m : ℕ
h : ∀ (x : ℝ), x ≠ 0 → 1 + x⁻¹ = (x + 1) / x
⊢ Real.log (↑m + 1) + Real.log ↑m ! - 1 / 2 * (Real.log 2 + Real.log (↑m + 1)) - (↑m + 1) * (Real.log (↑m + 1) - 1) -
(Real.log (↑m + 1 + 1) + (Real.log (↑m + 1) + Real.log ↑m !) - 1 / 2 * (Real.log 2 + Real.log (↑m + 1 + 1)) -
(↑m + 1 + 1) * (Real.log (↑m + 1 + 1) - 1)) +
1 / (2 * 0 + 1) * ((1 / (2 * (↑m + 1) + 1)) ^ 2) ^ 0 =
(↑m + 1 + 1 / 2) * (Real.log (↑m + 1 + 1) - Real.log (↑m + 1))
[PROOFSTEP]
ring
[GOAL]
n m : ℕ
⊢ 0 ≤ 1 / (2 * ↑(succ m) + 1) * ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ m
[PROOFSTEP]
positivity
[GOAL]
n : ℕ
⊢ Real.log (stirlingSeq (succ n)) - Real.log (stirlingSeq (succ (succ n))) ≤
(1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2)
[PROOFSTEP]
have h_nonneg : ↑0 ≤ ((1 : ℝ) / (2 * n.succ + 1)) ^ 2 := sq_nonneg _
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
⊢ Real.log (stirlingSeq (succ n)) - Real.log (stirlingSeq (succ (succ n))) ≤
(1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2)
[PROOFSTEP]
have g :
HasSum (fun k : ℕ => (((1 : ℝ) / (2 * n.succ + 1)) ^ 2) ^ k.succ)
(((1 : ℝ) / (2 * n.succ + 1)) ^ 2 / (↑1 - ((1 : ℝ) / (2 * n.succ + 1)) ^ 2)) :=
by
have := (hasSum_geometric_of_lt_1 h_nonneg ?_).mul_left (((1 : ℝ) / (2 * n.succ + 1)) ^ 2)
· simp_rw [← _root_.pow_succ] at this
exact this
rw [one_div, inv_pow]
exact inv_lt_one (one_lt_pow ((lt_add_iff_pos_left 1).mpr <| by positivity) two_ne_zero)
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
⊢ HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
[PROOFSTEP]
have := (hasSum_geometric_of_lt_1 h_nonneg ?_).mul_left (((1 : ℝ) / (2 * n.succ + 1)) ^ 2)
[GOAL]
case refine_2
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
this :
HasSum (fun i => (1 / (2 * ↑(succ n) + 1)) ^ 2 * ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ i)
((1 / (2 * ↑(succ n) + 1)) ^ 2 * (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2)⁻¹)
⊢ HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
[PROOFSTEP]
simp_rw [← _root_.pow_succ] at this
[GOAL]
case refine_2
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
this :
HasSum (fun i => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ (i + 1))
((1 / (2 * ↑(succ n) + 1)) ^ 2 * (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2)⁻¹)
⊢ HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
[PROOFSTEP]
exact this
[GOAL]
case refine_1
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
⊢ (1 / (2 * ↑(succ n) + 1)) ^ 2 < 1
[PROOFSTEP]
rw [one_div, inv_pow]
[GOAL]
case refine_1
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
⊢ ((2 * ↑(succ n) + 1) ^ 2)⁻¹ < 1
[PROOFSTEP]
exact inv_lt_one (one_lt_pow ((lt_add_iff_pos_left 1).mpr <| by positivity) two_ne_zero)
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
⊢ 0 < 2 * ↑(succ n)
[PROOFSTEP]
positivity
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
g :
HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
⊢ Real.log (stirlingSeq (succ n)) - Real.log (stirlingSeq (succ (succ n))) ≤
(1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2)
[PROOFSTEP]
have hab :
∀ k : ℕ,
(1 : ℝ) / (↑2 * k.succ + ↑1) * (((1 : ℝ) / (2 * n.succ + 1)) ^ 2) ^ k.succ ≤
(((1 : ℝ) / (2 * n.succ + 1)) ^ 2) ^ k.succ :=
by
refine' fun k => mul_le_of_le_one_left (pow_nonneg h_nonneg k.succ) _
rw [one_div]
exact inv_le_one (le_add_of_nonneg_left <| by positivity)
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
g :
HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
⊢ ∀ (k : ℕ),
1 / (2 * ↑(succ k) + 1) * ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k ≤ ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k
[PROOFSTEP]
refine' fun k => mul_le_of_le_one_left (pow_nonneg h_nonneg k.succ) _
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
g :
HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
k : ℕ
⊢ 1 / (2 * ↑(succ k) + 1) ≤ 1
[PROOFSTEP]
rw [one_div]
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
g :
HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
k : ℕ
⊢ (2 * ↑(succ k) + 1)⁻¹ ≤ 1
[PROOFSTEP]
exact inv_le_one (le_add_of_nonneg_left <| by positivity)
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
g :
HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
k : ℕ
⊢ 0 ≤ 2 * ↑(succ k)
[PROOFSTEP]
positivity
[GOAL]
n : ℕ
h_nonneg : 0 ≤ (1 / (2 * ↑(succ n) + 1)) ^ 2
g :
HasSum (fun k => ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k)
((1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2))
hab :
∀ (k : ℕ),
1 / (2 * ↑(succ k) + 1) * ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k ≤ ((1 / (2 * ↑(succ n) + 1)) ^ 2) ^ succ k
⊢ Real.log (stirlingSeq (succ n)) - Real.log (stirlingSeq (succ (succ n))) ≤
(1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2)
[PROOFSTEP]
exact hasSum_le hab (log_stirlingSeq_diff_hasSum n) g
[GOAL]
n : ℕ
⊢ Real.log (stirlingSeq (succ n)) - Real.log (stirlingSeq (succ (succ n))) ≤ 1 / (4 * ↑(succ n) ^ 2)
[PROOFSTEP]
have h₁ : ↑0 < ↑4 * ((n : ℝ) + 1) ^ 2 := by positivity
[GOAL]
n : ℕ
⊢ 0 < 4 * (↑n + 1) ^ 2
[PROOFSTEP]
positivity
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
⊢ Real.log (stirlingSeq (succ n)) - Real.log (stirlingSeq (succ (succ n))) ≤ 1 / (4 * ↑(succ n) ^ 2)
[PROOFSTEP]
have h₃ : ↑0 < (2 * ((n : ℝ) + 1) + 1) ^ 2 := by positivity
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
⊢ 0 < (2 * (↑n + 1) + 1) ^ 2
[PROOFSTEP]
positivity
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
⊢ Real.log (stirlingSeq (succ n)) - Real.log (stirlingSeq (succ (succ n))) ≤ 1 / (4 * ↑(succ n) ^ 2)
[PROOFSTEP]
have h₂ : ↑0 < ↑1 - (1 / (2 * ((n : ℝ) + 1) + 1)) ^ 2 :=
by
rw [← mul_lt_mul_right h₃]
have H : ↑0 < (2 * ((n : ℝ) + 1) + 1) ^ 2 - 1 := by nlinarith [@cast_nonneg ℝ _ n]
convert H using 1 <;> field_simp [h₃.ne']
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
⊢ 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
[PROOFSTEP]
rw [← mul_lt_mul_right h₃]
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
⊢ 0 * (2 * (↑n + 1) + 1) ^ 2 < (1 - (1 / (2 * (↑n + 1) + 1)) ^ 2) * (2 * (↑n + 1) + 1) ^ 2
[PROOFSTEP]
have H : ↑0 < (2 * ((n : ℝ) + 1) + 1) ^ 2 - 1 := by nlinarith [@cast_nonneg ℝ _ n]
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
⊢ 0 < (2 * (↑n + 1) + 1) ^ 2 - 1
[PROOFSTEP]
nlinarith [@cast_nonneg ℝ _ n]
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
H : 0 < (2 * (↑n + 1) + 1) ^ 2 - 1
⊢ 0 * (2 * (↑n + 1) + 1) ^ 2 < (1 - (1 / (2 * (↑n + 1) + 1)) ^ 2) * (2 * (↑n + 1) + 1) ^ 2
[PROOFSTEP]
convert H using 1
[GOAL]
case h.e'_3
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
H : 0 < (2 * (↑n + 1) + 1) ^ 2 - 1
⊢ 0 * (2 * (↑n + 1) + 1) ^ 2 = 0
[PROOFSTEP]
field_simp [h₃.ne']
[GOAL]
case h.e'_4
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
H : 0 < (2 * (↑n + 1) + 1) ^ 2 - 1
⊢ (1 - (1 / (2 * (↑n + 1) + 1)) ^ 2) * (2 * (↑n + 1) + 1) ^ 2 = (2 * (↑n + 1) + 1) ^ 2 - 1
[PROOFSTEP]
field_simp [h₃.ne']
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
h₂ : 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
⊢ Real.log (stirlingSeq (succ n)) - Real.log (stirlingSeq (succ (succ n))) ≤ 1 / (4 * ↑(succ n) ^ 2)
[PROOFSTEP]
refine' (log_stirlingSeq_diff_le_geo_sum n).trans _
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
h₂ : 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
⊢ (1 / (2 * ↑(succ n) + 1)) ^ 2 / (1 - (1 / (2 * ↑(succ n) + 1)) ^ 2) ≤ 1 / (4 * ↑(succ n) ^ 2)
[PROOFSTEP]
push_cast
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
h₂ : 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
⊢ (1 / (2 * (↑n + 1) + 1)) ^ 2 / (1 - (1 / (2 * (↑n + 1) + 1)) ^ 2) ≤ 1 / (4 * (↑n + 1) ^ 2)
[PROOFSTEP]
rw [div_le_div_iff h₂ h₁]
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
h₂ : 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
⊢ (1 / (2 * (↑n + 1) + 1)) ^ 2 * (4 * (↑n + 1) ^ 2) ≤ 1 * (1 - (1 / (2 * (↑n + 1) + 1)) ^ 2)
[PROOFSTEP]
field_simp [h₃.ne']
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
h₂ : 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
⊢ 4 * (↑n + 1) ^ 2 / (2 * (↑n + 1) + 1) ^ 2 ≤ ((2 * (↑n + 1) + 1) ^ 2 - 1) / (2 * (↑n + 1) + 1) ^ 2
[PROOFSTEP]
rw [div_le_div_right h₃]
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
h₂ : 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
⊢ 4 * (↑n + 1) ^ 2 ≤ (2 * (↑n + 1) + 1) ^ 2 - 1
[PROOFSTEP]
ring_nf
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
h₂ : 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
⊢ 4 + ↑n * 8 + ↑n ^ 2 * 4 ≤ 8 + ↑n * 12 + ↑n ^ 2 * 4
[PROOFSTEP]
norm_cast
[GOAL]
n : ℕ
h₁ : 0 < 4 * (↑n + 1) ^ 2
h₃ : 0 < (2 * (↑n + 1) + 1) ^ 2
h₂ : 0 < 1 - (1 / (2 * (↑n + 1) + 1)) ^ 2
⊢ 4 + n * 8 + n ^ 2 * 4 ≤ 8 + n * 12 + n ^ 2 * 4
[PROOFSTEP]
linarith
[GOAL]
⊢ ∃ c, ∀ (n : ℕ), Real.log (stirlingSeq 1) - Real.log (stirlingSeq (succ n)) ≤ c
[PROOFSTEP]
let d := ∑' k : ℕ, ↑1 / (k.succ : ℝ) ^ 2
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
⊢ ∃ c, ∀ (n : ℕ), Real.log (stirlingSeq 1) - Real.log (stirlingSeq (succ n)) ≤ c
[PROOFSTEP]
use(1 / 4 * d : ℝ)
[GOAL]
case h
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
⊢ ∀ (n : ℕ), Real.log (stirlingSeq 1) - Real.log (stirlingSeq (succ n)) ≤ 1 / 4 * d
[PROOFSTEP]
let log_stirlingSeq' : ℕ → ℝ := fun k => log (stirlingSeq k.succ)
[GOAL]
case h
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
⊢ ∀ (n : ℕ), Real.log (stirlingSeq 1) - Real.log (stirlingSeq (succ n)) ≤ 1 / 4 * d
[PROOFSTEP]
intro n
[GOAL]
case h
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
⊢ Real.log (stirlingSeq 1) - Real.log (stirlingSeq (succ n)) ≤ 1 / 4 * d
[PROOFSTEP]
have h₁ : ∀ k, log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ ↑1 / ↑4 * (↑1 / (k.succ : ℝ) ^ 2) := by intro k;
convert log_stirlingSeq_sub_log_stirlingSeq_succ k using 1; field_simp
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
⊢ ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
[PROOFSTEP]
intro k
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n k : ℕ
⊢ log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
[PROOFSTEP]
convert log_stirlingSeq_sub_log_stirlingSeq_succ k using 1
[GOAL]
case h.e'_4
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n k : ℕ
⊢ 1 / 4 * (1 / ↑(succ k) ^ 2) = 1 / (4 * ↑(succ k) ^ 2)
[PROOFSTEP]
field_simp
[GOAL]
case h
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
⊢ Real.log (stirlingSeq 1) - Real.log (stirlingSeq (succ n)) ≤ 1 / 4 * d
[PROOFSTEP]
have h₂ : (∑ k : ℕ in range n, ↑1 / (k.succ : ℝ) ^ 2) ≤ d :=
by
have := (summable_nat_add_iff 1).mpr <| Real.summable_one_div_nat_pow.mpr one_lt_two
simp only [rpow_nat_cast] at this
exact sum_le_tsum (range n) (fun k _ => by positivity) this
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
⊢ ∑ k in range n, 1 / ↑(succ k) ^ 2 ≤ d
[PROOFSTEP]
have := (summable_nat_add_iff 1).mpr <| Real.summable_one_div_nat_pow.mpr one_lt_two
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
this : Summable fun n => 1 / ↑(n + 1) ^ 2
⊢ ∑ k in range n, 1 / ↑(succ k) ^ 2 ≤ d
[PROOFSTEP]
simp only [rpow_nat_cast] at this
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
this : Summable fun n => 1 / ↑(n + 1) ^ 2
⊢ ∑ k in range n, 1 / ↑(succ k) ^ 2 ≤ d
[PROOFSTEP]
exact sum_le_tsum (range n) (fun k _ => by positivity) this
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
this : Summable fun n => 1 / ↑(n + 1) ^ 2
k : ℕ
x✝ : ¬k ∈ range n
⊢ 0 ≤ 1 / ↑(succ k) ^ 2
[PROOFSTEP]
positivity
[GOAL]
case h
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
h₂ : ∑ k in range n, 1 / ↑(succ k) ^ 2 ≤ d
⊢ Real.log (stirlingSeq 1) - Real.log (stirlingSeq (succ n)) ≤ 1 / 4 * d
[PROOFSTEP]
calc
log (stirlingSeq 1) - log (stirlingSeq n.succ) = log_stirlingSeq' 0 - log_stirlingSeq' n := rfl
_ = ∑ k in range n, (log_stirlingSeq' k - log_stirlingSeq' (k + 1)) := by rw [← sum_range_sub' log_stirlingSeq' n]
_ ≤ ∑ k in range n, ↑1 / ↑4 * (↑1 / ↑(k.succ) ^ 2) := (sum_le_sum fun k _ => h₁ k)
_ = ↑1 / ↑4 * ∑ k in range n, ↑1 / ↑(k.succ) ^ 2 := by rw [mul_sum]
_ ≤ 1 / 4 * d := mul_le_mul_of_nonneg_left h₂ <| by positivity
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
h₂ : ∑ k in range n, 1 / ↑(succ k) ^ 2 ≤ d
⊢ log_stirlingSeq' 0 - log_stirlingSeq' n = ∑ k in range n, (log_stirlingSeq' k - log_stirlingSeq' (k + 1))
[PROOFSTEP]
rw [← sum_range_sub' log_stirlingSeq' n]
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
h₂ : ∑ k in range n, 1 / ↑(succ k) ^ 2 ≤ d
⊢ ∑ k in range n, 1 / 4 * (1 / ↑(succ k) ^ 2) = 1 / 4 * ∑ k in range n, 1 / ↑(succ k) ^ 2
[PROOFSTEP]
rw [mul_sum]
[GOAL]
d : ℝ := ∑' (k : ℕ), 1 / ↑(succ k) ^ 2
log_stirlingSeq' : ℕ → ℝ := fun k => Real.log (stirlingSeq (succ k))
n : ℕ
h₁ : ∀ (k : ℕ), log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / ↑(succ k) ^ 2)
h₂ : ∑ k in range n, 1 / ↑(succ k) ^ 2 ≤ d
⊢ 0 ≤ 1 / 4
[PROOFSTEP]
positivity
[GOAL]
⊢ ∃ c, ∀ (n : ℕ), c ≤ Real.log (stirlingSeq (succ n))
[PROOFSTEP]
obtain ⟨d, h⟩ := log_stirlingSeq_bounded_aux
[GOAL]
case intro
d : ℝ
h : ∀ (n : ℕ), Real.log (stirlingSeq 1) - Real.log (stirlingSeq (succ n)) ≤ d
⊢ ∃ c, ∀ (n : ℕ), c ≤ Real.log (stirlingSeq (succ n))
[PROOFSTEP]
exact ⟨log (stirlingSeq 1) - d, fun n => sub_le_comm.mp (h n)⟩
[GOAL]
n : ℕ
⊢ 0 < stirlingSeq (succ n)
[PROOFSTEP]
unfold stirlingSeq
[GOAL]
n : ℕ
⊢ 0 < ↑(succ n)! / (Real.sqrt (2 * ↑(succ n)) * (↑(succ n) / exp 1) ^ succ n)
[PROOFSTEP]
positivity
[GOAL]
⊢ ∃ a, 0 < a ∧ ∀ (n : ℕ), a ≤ stirlingSeq (succ n)
[PROOFSTEP]
cases' log_stirlingSeq_bounded_by_constant with c h
[GOAL]
case intro
c : ℝ
h : ∀ (n : ℕ), c ≤ Real.log (stirlingSeq (succ n))
⊢ ∃ a, 0 < a ∧ ∀ (n : ℕ), a ≤ stirlingSeq (succ n)
[PROOFSTEP]
refine' ⟨exp c, exp_pos _, fun n => _⟩
[GOAL]
case intro
c : ℝ
h : ∀ (n : ℕ), c ≤ Real.log (stirlingSeq (succ n))
n : ℕ
⊢ exp c ≤ stirlingSeq (succ n)
[PROOFSTEP]
rw [← le_log_iff_exp_le (stirlingSeq'_pos n)]
[GOAL]
case intro
c : ℝ
h : ∀ (n : ℕ), c ≤ Real.log (stirlingSeq (succ n))
n : ℕ
⊢ c ≤ Real.log (stirlingSeq (succ n))
[PROOFSTEP]
exact h n
[GOAL]
⊢ ∃ a, 0 < a ∧ Tendsto stirlingSeq atTop (𝓝 a)
[PROOFSTEP]
obtain ⟨x, x_pos, hx⟩ := stirlingSeq'_bounded_by_pos_constant
[GOAL]
case intro.intro
x : ℝ
x_pos : 0 < x
hx : ∀ (n : ℕ), x ≤ stirlingSeq (succ n)
⊢ ∃ a, 0 < a ∧ Tendsto stirlingSeq atTop (𝓝 a)
[PROOFSTEP]
have hx' : x ∈ lowerBounds (Set.range (stirlingSeq ∘ succ)) := by simpa [lowerBounds] using hx
[GOAL]
x : ℝ
x_pos : 0 < x
hx : ∀ (n : ℕ), x ≤ stirlingSeq (succ n)
⊢ x ∈ lowerBounds (Set.range (stirlingSeq ∘ succ))
[PROOFSTEP]
simpa [lowerBounds] using hx
[GOAL]
case intro.intro
x : ℝ
x_pos : 0 < x
hx : ∀ (n : ℕ), x ≤ stirlingSeq (succ n)
hx' : x ∈ lowerBounds (Set.range (stirlingSeq ∘ succ))
⊢ ∃ a, 0 < a ∧ Tendsto stirlingSeq atTop (𝓝 a)
[PROOFSTEP]
refine' ⟨_, lt_of_lt_of_le x_pos (le_csInf (Set.range_nonempty _) hx'), _⟩
[GOAL]
case intro.intro
x : ℝ
x_pos : 0 < x
hx : ∀ (n : ℕ), x ≤ stirlingSeq (succ n)
hx' : x ∈ lowerBounds (Set.range (stirlingSeq ∘ succ))
⊢ Tendsto stirlingSeq atTop (𝓝 (sInf (Set.range (stirlingSeq ∘ succ))))
[PROOFSTEP]
rw [← Filter.tendsto_add_atTop_iff_nat 1]
[GOAL]
case intro.intro
x : ℝ
x_pos : 0 < x
hx : ∀ (n : ℕ), x ≤ stirlingSeq (succ n)
hx' : x ∈ lowerBounds (Set.range (stirlingSeq ∘ succ))
⊢ Tendsto (fun n => stirlingSeq (n + 1)) atTop (𝓝 (sInf (Set.range (stirlingSeq ∘ succ))))
[PROOFSTEP]
exact tendsto_atTop_ciInf stirlingSeq'_antitone ⟨x, hx'⟩
[GOAL]
⊢ Tendsto (fun n => ↑n / (2 * ↑n + 1)) atTop (𝓝 (1 / 2))
[PROOFSTEP]
conv =>
congr
·skip
·skip
rw [one_div, ← add_zero (2 : ℝ)]
[GOAL]
| Tendsto (fun n => ↑n / (2 * ↑n + 1)) atTop (𝓝 (1 / 2))
[PROOFSTEP]
congr
·skip
·skip
rw [one_div, ← add_zero (2 : ℝ)]
[GOAL]
| Tendsto (fun n => ↑n / (2 * ↑n + 1)) atTop (𝓝 (1 / 2))
[PROOFSTEP]
congr
·skip
·skip
rw [one_div, ← add_zero (2 : ℝ)]
[GOAL]
| Tendsto (fun n => ↑n / (2 * ↑n + 1)) atTop (𝓝 (1 / 2))
[PROOFSTEP]
congr
[GOAL]
case f
| fun n => ↑n / (2 * ↑n + 1)
case l₁
| atTop
case l₂ | 𝓝 (1 / 2)
[PROOFSTEP]
·skip
[GOAL]
case f
| fun n => ↑n / (2 * ↑n + 1)
[PROOFSTEP]
skip
[GOAL]
case f
| fun n => ↑n / (2 * ↑n + 1)
[PROOFSTEP]
skip
[GOAL]
case f
| fun n => ↑n / (2 * ↑n + 1)
[PROOFSTEP]
skip
[GOAL]
case l₁
| atTop
case l₂ | 𝓝 (1 / 2)
[PROOFSTEP]
·skip
[GOAL]
case l₁
| atTop
[PROOFSTEP]
skip
[GOAL]
case l₁
| atTop
[PROOFSTEP]
skip
[GOAL]
case l₁
| atTop
[PROOFSTEP]
skip
[GOAL]
case l₂
| 𝓝 (1 / 2)
[PROOFSTEP]
rw [one_div, ← add_zero (2 : ℝ)]
[GOAL]
⊢ Tendsto (fun n => ↑n / (2 * ↑n + 1)) atTop (𝓝 (2 + 0)⁻¹)
[PROOFSTEP]
refine'
(((tendsto_const_div_atTop_nhds_0_nat 1).const_add (2 : ℝ)).inv₀ ((add_zero (2 : ℝ)).symm ▸ two_ne_zero)).congr'
(eventually_atTop.mpr ⟨1, fun n hn => _⟩)
[GOAL]
n : ℕ
hn : n ≥ 1
⊢ (2 + 1 / ↑n)⁻¹ = (fun n => ↑n / (2 * ↑n + 1)) n
[PROOFSTEP]
rw [add_div' (1 : ℝ) 2 n (cast_ne_zero.mpr (one_le_iff_ne_zero.mp hn)), inv_div]
[GOAL]
n : ℕ
hn : n ≠ 0
⊢ stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (↑n / (2 * ↑n + 1)) = Wallis.W n
[PROOFSTEP]
have : 4 = 2 * 2 := by rfl
[GOAL]
n : ℕ
hn : n ≠ 0
⊢ 4 = 2 * 2
[PROOFSTEP]
rfl
[GOAL]
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (↑n / (2 * ↑n + 1)) = Wallis.W n
[PROOFSTEP]
rw [stirlingSeq, this, pow_mul, stirlingSeq, Wallis.W_eq_factorial_ratio]
[GOAL]
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ ((↑n ! / (Real.sqrt (2 * ↑n) * (↑n / exp 1) ^ n)) ^ 2) ^ 2 /
(↑(2 * n)! / (Real.sqrt (2 * ↑(2 * n)) * (↑(2 * n) / exp 1) ^ (2 * n))) ^ 2 *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
simp_rw [div_pow, mul_pow]
[GOAL]
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ (↑n ! ^ 2) ^ 2 / ((Real.sqrt (2 * ↑n) ^ 2) ^ 2 * ((↑n ^ n / exp 1 ^ n) ^ 2) ^ 2) /
(↑(2 * n)! ^ 2 / (Real.sqrt (2 * ↑(2 * n)) ^ 2 * (↑(2 * n) ^ (2 * n) / exp 1 ^ (2 * n)) ^ 2)) *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
rw [sq_sqrt, sq_sqrt]
[GOAL]
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ (↑n ! ^ 2) ^ 2 / ((2 * ↑n) ^ 2 * ((↑n ^ n / exp 1 ^ n) ^ 2) ^ 2) /
(↑(2 * n)! ^ 2 / (2 * ↑(2 * n) * (↑(2 * n) ^ (2 * n) / exp 1 ^ (2 * n)) ^ 2)) *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ 0 ≤ 2 * ↑(2 * n)
n : ℕ hn : n ≠ 0 this : 4 = 2 * 2 ⊢ 0 ≤ 2 * ↑n
[PROOFSTEP]
any_goals positivity
[GOAL]
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ (↑n ! ^ 2) ^ 2 / ((2 * ↑n) ^ 2 * ((↑n ^ n / exp 1 ^ n) ^ 2) ^ 2) /
(↑(2 * n)! ^ 2 / (2 * ↑(2 * n) * (↑(2 * n) ^ (2 * n) / exp 1 ^ (2 * n)) ^ 2)) *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
positivity
[GOAL]
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ 0 ≤ 2 * ↑(2 * n)
[PROOFSTEP]
positivity
[GOAL]
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ 0 ≤ 2 * ↑n
[PROOFSTEP]
positivity
[GOAL]
n : ℕ
hn : n ≠ 0
this : 4 = 2 * 2
⊢ (↑n ! ^ 2) ^ 2 / ((2 * ↑n) ^ 2 * ((↑n ^ n / exp 1 ^ n) ^ 2) ^ 2) /
(↑(2 * n)! ^ 2 / (2 * ↑(2 * n) * (↑(2 * n) ^ (2 * n) / exp 1 ^ (2 * n)) ^ 2)) *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
have : (n : ℝ) ≠ 0 := cast_ne_zero.mpr hn
[GOAL]
n : ℕ
hn : n ≠ 0
this✝ : 4 = 2 * 2
this : ↑n ≠ 0
⊢ (↑n ! ^ 2) ^ 2 / ((2 * ↑n) ^ 2 * ((↑n ^ n / exp 1 ^ n) ^ 2) ^ 2) /
(↑(2 * n)! ^ 2 / (2 * ↑(2 * n) * (↑(2 * n) ^ (2 * n) / exp 1 ^ (2 * n)) ^ 2)) *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
have : exp 1 ≠ 0 := exp_ne_zero 1
[GOAL]
n : ℕ
hn : n ≠ 0
this✝¹ : 4 = 2 * 2
this✝ : ↑n ≠ 0
this : exp 1 ≠ 0
⊢ (↑n ! ^ 2) ^ 2 / ((2 * ↑n) ^ 2 * ((↑n ^ n / exp 1 ^ n) ^ 2) ^ 2) /
(↑(2 * n)! ^ 2 / (2 * ↑(2 * n) * (↑(2 * n) ^ (2 * n) / exp 1 ^ (2 * n)) ^ 2)) *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
have : ((2 * n)! : ℝ) ≠ 0 := cast_ne_zero.mpr (factorial_ne_zero (2 * n))
[GOAL]
n : ℕ
hn : n ≠ 0
this✝² : 4 = 2 * 2
this✝¹ : ↑n ≠ 0
this✝ : exp 1 ≠ 0
this : ↑(2 * n)! ≠ 0
⊢ (↑n ! ^ 2) ^ 2 / ((2 * ↑n) ^ 2 * ((↑n ^ n / exp 1 ^ n) ^ 2) ^ 2) /
(↑(2 * n)! ^ 2 / (2 * ↑(2 * n) * (↑(2 * n) ^ (2 * n) / exp 1 ^ (2 * n)) ^ 2)) *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
have : 2 * (n : ℝ) + 1 ≠ 0 := by norm_cast; exact succ_ne_zero (2 * n)
[GOAL]
n : ℕ
hn : n ≠ 0
this✝² : 4 = 2 * 2
this✝¹ : ↑n ≠ 0
this✝ : exp 1 ≠ 0
this : ↑(2 * n)! ≠ 0
⊢ 2 * ↑n + 1 ≠ 0
[PROOFSTEP]
norm_cast
[GOAL]
n : ℕ
hn : n ≠ 0
this✝² : 4 = 2 * 2
this✝¹ : ↑n ≠ 0
this✝ : exp 1 ≠ 0
this : ↑(2 * n)! ≠ 0
⊢ ¬2 * n + 1 = 0
[PROOFSTEP]
exact succ_ne_zero (2 * n)
[GOAL]
n : ℕ
hn : n ≠ 0
this✝³ : 4 = 2 * 2
this✝² : ↑n ≠ 0
this✝¹ : exp 1 ≠ 0
this✝ : ↑(2 * n)! ≠ 0
this : 2 * ↑n + 1 ≠ 0
⊢ (↑n ! ^ 2) ^ 2 / ((2 * ↑n) ^ 2 * ((↑n ^ n / exp 1 ^ n) ^ 2) ^ 2) /
(↑(2 * n)! ^ 2 / (2 * ↑(2 * n) * (↑(2 * n) ^ (2 * n) / exp 1 ^ (2 * n)) ^ 2)) *
(↑n / (2 * ↑n + 1)) =
↑(2 ^ (4 * n)) * ↑(n ! ^ 4) / (↑((2 * n)! ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
field_simp
[GOAL]
n : ℕ
hn : n ≠ 0
this✝³ : 4 = 2 * 2
this✝² : ↑n ≠ 0
this✝¹ : exp 1 ≠ 0
this✝ : ↑(2 * n)! ≠ 0
this : 2 * ↑n + 1 ≠ 0
⊢ (↑n ! ^ 2) ^ 2 * ((exp 1 ^ n) ^ 2) ^ 2 * (2 * (2 * ↑n) * ((2 * ↑n) ^ (2 * n)) ^ 2) * ↑n *
(↑(2 * n)! ^ 2 * (2 * ↑n + 1)) =
2 ^ (4 * n) * ↑n ! ^ 4 *
((2 * ↑n) ^ 2 * ((↑n ^ n) ^ 2) ^ 2 * (↑(2 * n)! ^ 2 * (exp 1 ^ (2 * n)) ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
simp only [mul_pow, mul_comm 2 n, mul_comm 4 n, pow_mul]
[GOAL]
n : ℕ
hn : n ≠ 0
this✝³ : 4 = 2 * 2
this✝² : ↑n ≠ 0
this✝¹ : exp 1 ≠ 0
this✝ : ↑(2 * n)! ≠ 0
this : 2 * ↑n + 1 ≠ 0
⊢ (↑n ! ^ 2) ^ 2 * ((exp 1 ^ n) ^ 2) ^ 2 * (2 * (2 * ↑n) * (((2 ^ n) ^ 2) ^ 2 * ((↑n ^ n) ^ 2) ^ 2)) * ↑n *
(↑(n * 2)! ^ 2 * (2 * ↑n + 1)) =
(2 ^ n) ^ 4 * ↑n ! ^ 4 *
(2 ^ 2 * ↑n ^ 2 * ((↑n ^ n) ^ 2) ^ 2 * (↑(n * 2)! ^ 2 * ((exp 1 ^ n) ^ 2) ^ 2) * (2 * ↑n + 1))
[PROOFSTEP]
ring
[GOAL]
a : ℝ
hane : a ≠ 0
ha : Tendsto stirlingSeq atTop (𝓝 a)
⊢ Tendsto Wallis.W atTop (𝓝 (a ^ 2 / 2))
[PROOFSTEP]
refine'
Tendsto.congr'
(eventually_atTop.mpr ⟨1, fun n hn => stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq n (one_le_iff_ne_zero.mp hn)⟩)
_
[GOAL]
a : ℝ
hane : a ≠ 0
ha : Tendsto stirlingSeq atTop (𝓝 a)
⊢ Tendsto (fun n => stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (↑n / (2 * ↑n + 1))) atTop (𝓝 (a ^ 2 / 2))
[PROOFSTEP]
have h : a ^ 2 / ↑2 = a ^ 4 / a ^ 2 * (1 / 2) :=
by
rw [mul_one_div, ← mul_one_div (a ^ 4) (a ^ 2), one_div, ← pow_sub_of_lt a]
norm_num
[GOAL]
a : ℝ
hane : a ≠ 0
ha : Tendsto stirlingSeq atTop (𝓝 a)
⊢ a ^ 2 / 2 = a ^ 4 / a ^ 2 * (1 / 2)
[PROOFSTEP]
rw [mul_one_div, ← mul_one_div (a ^ 4) (a ^ 2), one_div, ← pow_sub_of_lt a]
[GOAL]
a : ℝ
hane : a ≠ 0
ha : Tendsto stirlingSeq atTop (𝓝 a)
⊢ 2 < 4
[PROOFSTEP]
norm_num
[GOAL]
a : ℝ
hane : a ≠ 0
ha : Tendsto stirlingSeq atTop (𝓝 a)
h : a ^ 2 / 2 = a ^ 4 / a ^ 2 * (1 / 2)
⊢ Tendsto (fun n => stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (↑n / (2 * ↑n + 1))) atTop (𝓝 (a ^ 2 / 2))
[PROOFSTEP]
rw [h]
[GOAL]
a : ℝ
hane : a ≠ 0
ha : Tendsto stirlingSeq atTop (𝓝 a)
h : a ^ 2 / 2 = a ^ 4 / a ^ 2 * (1 / 2)
⊢ Tendsto (fun n => stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (↑n / (2 * ↑n + 1))) atTop
(𝓝 (a ^ 4 / a ^ 2 * (1 / 2)))
[PROOFSTEP]
exact
((ha.pow 4).div ((ha.comp (tendsto_id.const_mul_atTop' two_pos)).pow 2) (pow_ne_zero 2 hane)).mul
tendsto_self_div_two_mul_self_add_one
[GOAL]
⊢ Tendsto (fun n => stirlingSeq n) atTop (𝓝 (Real.sqrt π))
[PROOFSTEP]
obtain ⟨a, hapos, halimit⟩ := stirlingSeq_has_pos_limit_a
[GOAL]
case intro.intro
a : ℝ
hapos : 0 < a
halimit : Tendsto stirlingSeq atTop (𝓝 a)
⊢ Tendsto (fun n => stirlingSeq n) atTop (𝓝 (Real.sqrt π))
[PROOFSTEP]
have hπ : π / 2 = a ^ 2 / 2 :=
tendsto_nhds_unique Wallis.tendsto_W_nhds_pi_div_two (second_wallis_limit a hapos.ne' halimit)
[GOAL]
case intro.intro
a : ℝ
hapos : 0 < a
halimit : Tendsto stirlingSeq atTop (𝓝 a)
hπ : π / ↑2 = a ^ 2 / 2
⊢ Tendsto (fun n => stirlingSeq n) atTop (𝓝 (Real.sqrt π))
[PROOFSTEP]
rwa [(div_left_inj' (two_ne_zero' ℝ)).mp hπ, sqrt_sq hapos.le]
|
lemma measurable_lfp_coinduct[consumes 1, case_names continuity step]: fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_lattice, countable})" assumes "P M" assumes F: "sup_continuous F" assumes *: "\<And>M A. P M \<Longrightarrow> (\<And>N. P N \<Longrightarrow> A \<in> measurable N (count_space UNIV)) \<Longrightarrow> F A \<in> measurable M (count_space UNIV)" shows "lfp F \<in> measurable M (count_space UNIV)" |
[GOAL]
R₁ : Type u_1
R₂ : Type u_2
inst✝⁵ : Semiring R₁
inst✝⁴ : Semiring R₂
σ₁₂ : R₁ →+* R₂
M₁ : Type u_3
M₂ : Type u_4
inst✝³ : TopologicalSpace M₁
inst✝² : AddCommMonoid M₁
inst✝¹ : TopologicalSpace M₂
inst✝ : T2Space M₂
f : M₁ → M₂
⊢ IsCompactOperator f ↔ ∃ V, V ∈ 𝓝 0 ∧ IsCompact (closure (f '' V))
[PROOFSTEP]
rw [isCompactOperator_iff_exists_mem_nhds_image_subset_compact]
[GOAL]
R₁ : Type u_1
R₂ : Type u_2
inst✝⁵ : Semiring R₁
inst✝⁴ : Semiring R₂
σ₁₂ : R₁ →+* R₂
M₁ : Type u_3
M₂ : Type u_4
inst✝³ : TopologicalSpace M₁
inst✝² : AddCommMonoid M₁
inst✝¹ : TopologicalSpace M₂
inst✝ : T2Space M₂
f : M₁ → M₂
⊢ (∃ V, V ∈ 𝓝 0 ∧ ∃ K, IsCompact K ∧ f '' V ⊆ K) ↔ ∃ V, V ∈ 𝓝 0 ∧ IsCompact (closure (f '' V))
[PROOFSTEP]
exact
⟨fun ⟨V, hV, K, hK, hKV⟩ => ⟨V, hV, isCompact_closure_of_subset_compact hK hKV⟩, fun ⟨V, hV, hVc⟩ =>
⟨V, hV, closure (f '' V), hVc, subset_closure⟩⟩
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝⁸ : NontriviallyNormedField 𝕜₁
inst✝⁷ : SeminormedRing 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁶ : TopologicalSpace M₁
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : TopologicalSpace M₂
inst✝³ : AddCommMonoid M₂
inst✝² : Module 𝕜₁ M₁
inst✝¹ : Module 𝕜₂ M₂
inst✝ : ContinuousConstSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
S : Set M₁
hS : IsVonNBounded 𝕜₁ S
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrS : ∀ (a : 𝕜₁), r ≤ ‖a‖ → S ⊆ a • ↑f ⁻¹' K
c : 𝕜₁
hc : r < ‖c‖
this : c ≠ 0 := ne_zero_of_norm_ne_zero (Ne.symm (LT.lt.ne (LT.lt.trans hr hc)))
⊢ ↑f '' S ⊆ ↑σ₁₂ c • K
[PROOFSTEP]
rw [image_subset_iff, preimage_smul_setₛₗ _ _ _ f this.isUnit]
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝⁸ : NontriviallyNormedField 𝕜₁
inst✝⁷ : SeminormedRing 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁶ : TopologicalSpace M₁
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : TopologicalSpace M₂
inst✝³ : AddCommMonoid M₂
inst✝² : Module 𝕜₁ M₁
inst✝¹ : Module 𝕜₂ M₂
inst✝ : ContinuousConstSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
S : Set M₁
hS : IsVonNBounded 𝕜₁ S
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrS : ∀ (a : 𝕜₁), r ≤ ‖a‖ → S ⊆ a • ↑f ⁻¹' K
c : 𝕜₁
hc : r < ‖c‖
this : c ≠ 0 := ne_zero_of_norm_ne_zero (Ne.symm (LT.lt.ne (LT.lt.trans hr hc)))
⊢ S ⊆ c • ↑f ⁻¹' K
[PROOFSTEP]
exact hrS c hc.le
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝⁷ : NontriviallyNormedField 𝕜₁
inst✝⁶ : SeminormedRing 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
M₃ : Type u_5
inst✝⁵ : SeminormedAddCommGroup M₁
inst✝⁴ : TopologicalSpace M₂
inst✝³ : AddCommMonoid M₂
inst✝² : NormedSpace 𝕜₁ M₁
inst✝¹ : Module 𝕜₂ M₂
inst✝ : ContinuousConstSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
S : Set M₁
hS : Metric.Bounded S
⊢ IsVonNBounded 𝕜₁ S
[PROOFSTEP]
rwa [NormedSpace.isVonNBounded_iff, ← Metric.bounded_iff_isBounded]
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝⁸ : NontriviallyNormedField 𝕜₁
inst✝⁷ : SeminormedRing 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
M₃ : Type u_5
inst✝⁶ : SeminormedAddCommGroup M₁
inst✝⁵ : TopologicalSpace M₂
inst✝⁴ : AddCommMonoid M₂
inst✝³ : NormedSpace 𝕜₁ M₁
inst✝² : Module 𝕜₂ M₂
inst✝¹ : ContinuousConstSMul 𝕜₂ M₂
inst✝ : T2Space M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
S : Set M₁
hS : Metric.Bounded S
⊢ IsVonNBounded 𝕜₁ S
[PROOFSTEP]
rwa [NormedSpace.isVonNBounded_iff, ← Metric.bounded_iff_isBounded]
[GOAL]
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
R₄ : Type u_4
inst✝¹² : Semiring R₁
inst✝¹¹ : Semiring R₂
inst✝¹⁰ : CommSemiring R₃
inst✝⁹ : CommSemiring R₄
σ₁₂ : R₁ →+* R₂
σ₁₄ : R₁ →+* R₄
σ₃₄ : R₃ →+* R₄
M₁ : Type u_5
M₂ : Type u_6
M₃ : Type u_7
M₄ : Type u_8
inst✝⁸ : TopologicalSpace M₁
inst✝⁷ : AddCommMonoid M₁
inst✝⁶ : TopologicalSpace M₂
inst✝⁵ : AddCommMonoid M₂
inst✝⁴ : TopologicalSpace M₃
inst✝³ : AddCommGroup M₃
inst✝² : TopologicalSpace M₄
inst✝¹ : AddCommGroup M₄
inst✝ : TopologicalAddGroup M₄
f g : M₁ → M₄
hf : IsCompactOperator f
hg : IsCompactOperator g
⊢ IsCompactOperator (f - g)
[PROOFSTEP]
rw [sub_eq_add_neg]
[GOAL]
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
R₄ : Type u_4
inst✝¹² : Semiring R₁
inst✝¹¹ : Semiring R₂
inst✝¹⁰ : CommSemiring R₃
inst✝⁹ : CommSemiring R₄
σ₁₂ : R₁ →+* R₂
σ₁₄ : R₁ →+* R₄
σ₃₄ : R₃ →+* R₄
M₁ : Type u_5
M₂ : Type u_6
M₃ : Type u_7
M₄ : Type u_8
inst✝⁸ : TopologicalSpace M₁
inst✝⁷ : AddCommMonoid M₁
inst✝⁶ : TopologicalSpace M₂
inst✝⁵ : AddCommMonoid M₂
inst✝⁴ : TopologicalSpace M₃
inst✝³ : AddCommGroup M₃
inst✝² : TopologicalSpace M₄
inst✝¹ : AddCommGroup M₄
inst✝ : TopologicalAddGroup M₄
f g : M₁ → M₄
hf : IsCompactOperator f
hg : IsCompactOperator g
⊢ IsCompactOperator (f + -g)
[PROOFSTEP]
exact hf.add hg.neg
[GOAL]
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
inst✝⁹ : Semiring R₁
inst✝⁸ : Semiring R₂
inst✝⁷ : Semiring R₃
σ₁₂ : R₁ →+* R₂
σ₂₃ : R₂ →+* R₃
M₁ : Type u_4
M₂ : Type u_5
M₃ : Type u_6
inst✝⁶ : TopologicalSpace M₁
inst✝⁵ : TopologicalSpace M₂
inst✝⁴ : TopologicalSpace M₃
inst✝³ : AddCommMonoid M₁
inst✝² : Module R₁ M₁
inst✝¹ : AddCommMonoid M₂
inst✝ : Module R₂ M₂
f : M₂ → M₃
hf : IsCompactOperator f
g : M₁ →SL[σ₁₂] M₂
⊢ IsCompactOperator (f ∘ ↑g)
[PROOFSTEP]
have := g.continuous.tendsto 0
[GOAL]
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
inst✝⁹ : Semiring R₁
inst✝⁸ : Semiring R₂
inst✝⁷ : Semiring R₃
σ₁₂ : R₁ →+* R₂
σ₂₃ : R₂ →+* R₃
M₁ : Type u_4
M₂ : Type u_5
M₃ : Type u_6
inst✝⁶ : TopologicalSpace M₁
inst✝⁵ : TopologicalSpace M₂
inst✝⁴ : TopologicalSpace M₃
inst✝³ : AddCommMonoid M₁
inst✝² : Module R₁ M₁
inst✝¹ : AddCommMonoid M₂
inst✝ : Module R₂ M₂
f : M₂ → M₃
hf : IsCompactOperator f
g : M₁ →SL[σ₁₂] M₂
this : Tendsto (↑g) (𝓝 0) (𝓝 (↑g 0))
⊢ IsCompactOperator (f ∘ ↑g)
[PROOFSTEP]
rw [map_zero] at this
[GOAL]
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
inst✝⁹ : Semiring R₁
inst✝⁸ : Semiring R₂
inst✝⁷ : Semiring R₃
σ₁₂ : R₁ →+* R₂
σ₂₃ : R₂ →+* R₃
M₁ : Type u_4
M₂ : Type u_5
M₃ : Type u_6
inst✝⁶ : TopologicalSpace M₁
inst✝⁵ : TopologicalSpace M₂
inst✝⁴ : TopologicalSpace M₃
inst✝³ : AddCommMonoid M₁
inst✝² : Module R₁ M₁
inst✝¹ : AddCommMonoid M₂
inst✝ : Module R₂ M₂
f : M₂ → M₃
hf : IsCompactOperator f
g : M₁ →SL[σ₁₂] M₂
this : Tendsto (↑g) (𝓝 0) (𝓝 0)
⊢ IsCompactOperator (f ∘ ↑g)
[PROOFSTEP]
rcases hf with ⟨K, hK, hKf⟩
[GOAL]
case intro.intro
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
inst✝⁹ : Semiring R₁
inst✝⁸ : Semiring R₂
inst✝⁷ : Semiring R₃
σ₁₂ : R₁ →+* R₂
σ₂₃ : R₂ →+* R₃
M₁ : Type u_4
M₂ : Type u_5
M₃ : Type u_6
inst✝⁶ : TopologicalSpace M₁
inst✝⁵ : TopologicalSpace M₂
inst✝⁴ : TopologicalSpace M₃
inst✝³ : AddCommMonoid M₁
inst✝² : Module R₁ M₁
inst✝¹ : AddCommMonoid M₂
inst✝ : Module R₂ M₂
f : M₂ → M₃
g : M₁ →SL[σ₁₂] M₂
this : Tendsto (↑g) (𝓝 0) (𝓝 0)
K : Set M₃
hK : IsCompact K
hKf : f ⁻¹' K ∈ 𝓝 0
⊢ IsCompactOperator (f ∘ ↑g)
[PROOFSTEP]
exact ⟨K, hK, this hKf⟩
[GOAL]
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
inst✝⁷ : Semiring R₁
inst✝⁶ : Semiring R₂
inst✝⁵ : Semiring R₃
σ₁₂ : R₁ →+* R₂
σ₂₃ : R₂ →+* R₃
M₁ : Type u_4
M₂ : Type u_5
M₃ : Type u_6
inst✝⁴ : TopologicalSpace M₁
inst✝³ : TopologicalSpace M₂
inst✝² : TopologicalSpace M₃
inst✝¹ : AddCommMonoid M₁
inst✝ : Module R₁ M₁
f : M₁ → M₂
hf : IsCompactOperator f
g : M₂ → M₃
hg : Continuous g
⊢ IsCompactOperator (g ∘ f)
[PROOFSTEP]
rcases hf with ⟨K, hK, hKf⟩
[GOAL]
case intro.intro
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
inst✝⁷ : Semiring R₁
inst✝⁶ : Semiring R₂
inst✝⁵ : Semiring R₃
σ₁₂ : R₁ →+* R₂
σ₂₃ : R₂ →+* R₃
M₁ : Type u_4
M₂ : Type u_5
M₃ : Type u_6
inst✝⁴ : TopologicalSpace M₁
inst✝³ : TopologicalSpace M₂
inst✝² : TopologicalSpace M₃
inst✝¹ : AddCommMonoid M₁
inst✝ : Module R₁ M₁
f : M₁ → M₂
g : M₂ → M₃
hg : Continuous g
K : Set M₂
hK : IsCompact K
hKf : f ⁻¹' K ∈ 𝓝 0
⊢ IsCompactOperator (g ∘ f)
[PROOFSTEP]
refine' ⟨g '' K, hK.image hg, mem_of_superset hKf _⟩
[GOAL]
case intro.intro
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
inst✝⁷ : Semiring R₁
inst✝⁶ : Semiring R₂
inst✝⁵ : Semiring R₃
σ₁₂ : R₁ →+* R₂
σ₂₃ : R₂ →+* R₃
M₁ : Type u_4
M₂ : Type u_5
M₃ : Type u_6
inst✝⁴ : TopologicalSpace M₁
inst✝³ : TopologicalSpace M₂
inst✝² : TopologicalSpace M₃
inst✝¹ : AddCommMonoid M₁
inst✝ : Module R₁ M₁
f : M₁ → M₂
g : M₂ → M₃
hg : Continuous g
K : Set M₂
hK : IsCompact K
hKf : f ⁻¹' K ∈ 𝓝 0
⊢ f ⁻¹' K ⊆ g ∘ f ⁻¹' (g '' K)
[PROOFSTEP]
rw [preimage_comp]
[GOAL]
case intro.intro
R₁ : Type u_1
R₂ : Type u_2
R₃ : Type u_3
inst✝⁷ : Semiring R₁
inst✝⁶ : Semiring R₂
inst✝⁵ : Semiring R₃
σ₁₂ : R₁ →+* R₂
σ₂₃ : R₂ →+* R₃
M₁ : Type u_4
M₂ : Type u_5
M₃ : Type u_6
inst✝⁴ : TopologicalSpace M₁
inst✝³ : TopologicalSpace M₂
inst✝² : TopologicalSpace M₃
inst✝¹ : AddCommMonoid M₁
inst✝ : Module R₁ M₁
f : M₁ → M₂
g : M₂ → M₃
hg : Continuous g
K : Set M₂
hK : IsCompact K
hKf : f ⁻¹' K ∈ 𝓝 0
⊢ f ⁻¹' K ⊆ f ⁻¹' (g ⁻¹' (g '' K))
[PROOFSTEP]
exact preimage_mono (subset_preimage_image _ _)
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
⊢ Continuous ↑f
[PROOFSTEP]
letI : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace _
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
this : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
⊢ Continuous ↑f
[PROOFSTEP]
haveI : UniformAddGroup M₂ := comm_topologicalAddGroup_is_uniform
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
⊢ Continuous ↑f
[PROOFSTEP]
refine' continuous_of_continuousAt_zero f fun U hU => _
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 (↑f 0)
⊢ U ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
rw [map_zero] at hU
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
hf : IsCompactOperator ↑f
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
⊢ U ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
rcases hf with
⟨K, hK, hKf⟩
-- But any compact set is totally bounded, hence Von-Neumann bounded. Thus, `K` absorbs `U`.
-- This gives `r > 0` such that `∀ a : 𝕜₂, r ≤ ‖a‖ → K ⊆ a • U`.
[GOAL]
case intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
⊢ U ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
rcases hK.totallyBounded.isVonNBounded 𝕜₂ hU with
⟨r, hr, hrU⟩
-- Choose `c : 𝕜₂` with `r < ‖c‖`.
[GOAL]
case intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
⊢ U ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
rcases NormedField.exists_lt_norm 𝕜₁ r with ⟨c, hc⟩
[GOAL]
case intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
⊢ U ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
have hcnz : c ≠ 0 := ne_zero_of_norm_ne_zero (hr.trans hc).ne.symm
[GOAL]
case intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
hcnz : c ≠ 0
⊢ U ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
suffices (σ₁₂ <| c⁻¹) • K ⊆ U by
refine' mem_of_superset _ this
have : IsUnit c⁻¹ := hcnz.isUnit.inv
rwa [mem_map, preimage_smul_setₛₗ _ _ _ f this, set_smul_mem_nhds_zero_iff (inv_ne_zero hcnz)]
-- Since `σ₁₂ c⁻¹` = `(σ₁₂ c)⁻¹`, we have to prove that `K ⊆ σ₁₂ c • U`.
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝¹ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this✝ : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
hcnz : c ≠ 0
this : ↑σ₁₂ c⁻¹ • K ⊆ U
⊢ U ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
refine' mem_of_superset _ this
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝¹ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this✝ : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
hcnz : c ≠ 0
this : ↑σ₁₂ c⁻¹ • K ⊆ U
⊢ ↑σ₁₂ c⁻¹ • K ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
have : IsUnit c⁻¹ := hcnz.isUnit.inv
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝² : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this✝¹ : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
hcnz : c ≠ 0
this✝ : ↑σ₁₂ c⁻¹ • K ⊆ U
this : IsUnit c⁻¹
⊢ ↑σ₁₂ c⁻¹ • K ∈ map (↑f) (𝓝 0)
[PROOFSTEP]
rwa [mem_map, preimage_smul_setₛₗ _ _ _ f this, set_smul_mem_nhds_zero_iff (inv_ne_zero hcnz)]
-- Since `σ₁₂ c⁻¹` = `(σ₁₂ c)⁻¹`, we have to prove that `K ⊆ σ₁₂ c • U`.
[GOAL]
case intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
hcnz : c ≠ 0
⊢ ↑σ₁₂ c⁻¹ • K ⊆ U
[PROOFSTEP]
rw [map_inv₀, ← subset_set_smul_iff₀ ((map_ne_zero σ₁₂).mpr hcnz)]
-- But `σ₁₂` is isometric, so `‖σ₁₂ c‖ = ‖c‖ > r`, which concludes the argument since
-- `∀ a : 𝕜₂, r ≤ ‖a‖ → K ⊆ a • U`.
[GOAL]
case intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
hcnz : c ≠ 0
⊢ K ⊆ ↑σ₁₂ c • U
[PROOFSTEP]
refine' hrU (σ₁₂ c) _
[GOAL]
case intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
hcnz : c ≠ 0
⊢ r ≤ ‖↑σ₁₂ c‖
[PROOFSTEP]
rw [RingHomIsometric.is_iso]
[GOAL]
case intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹² : NontriviallyNormedField 𝕜₁
inst✝¹¹ : NontriviallyNormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
inst✝¹⁰ : RingHomIsometric σ₁₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁹ : TopologicalSpace M₁
inst✝⁸ : AddCommGroup M₁
inst✝⁷ : TopologicalSpace M₂
inst✝⁶ : AddCommGroup M₂
inst✝⁵ : Module 𝕜₁ M₁
inst✝⁴ : Module 𝕜₂ M₂
inst✝³ : TopologicalAddGroup M₁
inst✝² : ContinuousConstSMul 𝕜₁ M₁
inst✝¹ : TopologicalAddGroup M₂
inst✝ : ContinuousSMul 𝕜₂ M₂
f : M₁ →ₛₗ[σ₁₂] M₂
this✝ : UniformSpace M₂ := TopologicalAddGroup.toUniformSpace M₂
this : UniformAddGroup M₂
U : Set M₂
hU : U ∈ 𝓝 0
K : Set M₂
hK : IsCompact K
hKf : ↑f ⁻¹' K ∈ 𝓝 0
r : ℝ
hr : 0 < r
hrU : ∀ (a : 𝕜₂), r ≤ ‖a‖ → K ⊆ a • U
c : 𝕜₁
hc : r < ‖c‖
hcnz : c ≠ 0
⊢ r ≤ ‖c‖
[PROOFSTEP]
exact hc.le
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
⊢ IsClosed {f | IsCompactOperator ↑f}
[PROOFSTEP]
refine' isClosed_of_closure_subset _
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
⊢ closure {f | IsCompactOperator ↑f} ⊆ {f | IsCompactOperator ↑f}
[PROOFSTEP]
rintro u hu
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu : u ∈ closure {f | IsCompactOperator ↑f}
⊢ u ∈ {f | IsCompactOperator ↑f}
[PROOFSTEP]
rw [mem_closure_iff_nhds_zero] at hu
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
⊢ u ∈ {f | IsCompactOperator ↑f}
[PROOFSTEP]
suffices TotallyBounded (u '' Metric.closedBall 0 1)
by
change IsCompactOperator (u : M₁ →ₛₗ[σ₁₂] M₂)
rw [isCompactOperator_iff_isCompact_closure_image_closedBall (u : M₁ →ₛₗ[σ₁₂] M₂) zero_lt_one]
exact isCompact_of_totallyBounded_isClosed this.closure isClosed_closure
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
this : TotallyBounded (↑u '' closedBall 0 1)
⊢ u ∈ {f | IsCompactOperator ↑f}
[PROOFSTEP]
change IsCompactOperator (u : M₁ →ₛₗ[σ₁₂] M₂)
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
this : TotallyBounded (↑u '' closedBall 0 1)
⊢ IsCompactOperator ↑↑u
[PROOFSTEP]
rw [isCompactOperator_iff_isCompact_closure_image_closedBall (u : M₁ →ₛₗ[σ₁₂] M₂) zero_lt_one]
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
this : TotallyBounded (↑u '' closedBall 0 1)
⊢ IsCompact (closure (↑↑u '' closedBall 0 1))
[PROOFSTEP]
exact isCompact_of_totallyBounded_isClosed this.closure isClosed_closure
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
⊢ TotallyBounded (↑u '' closedBall 0 1)
[PROOFSTEP]
rw [totallyBounded_iff_subset_finite_iUnion_nhds_zero]
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
⊢ ∀ (U : Set M₂), U ∈ 𝓝 0 → ∃ t, Set.Finite t ∧ ↑u '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ t), y +ᵥ U
[PROOFSTEP]
intro U hU
[GOAL]
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
⊢ ∃ t, Set.Finite t ∧ ↑u '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ t), y +ᵥ U
[PROOFSTEP]
rcases exists_nhds_zero_half hU with ⟨V, hV, hVU⟩
[GOAL]
case intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
⊢ ∃ t, Set.Finite t ∧ ↑u '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ t), y +ᵥ U
[PROOFSTEP]
let SV : Set M₁ × Set M₂ := ⟨closedBall 0 1, -V⟩
[GOAL]
case intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
⊢ ∃ t, Set.Finite t ∧ ↑u '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ t), y +ᵥ U
[PROOFSTEP]
rcases hu {f | ∀ x ∈ SV.1, f x ∈ SV.2}
(ContinuousLinearMap.hasBasis_nhds_zero.mem_of_mem
⟨NormedSpace.isVonNBounded_closedBall _ _ _, neg_mem_nhds_zero M₂ hV⟩) with
⟨v, hv, huv⟩
[GOAL]
case intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
⊢ ∃ t, Set.Finite t ∧ ↑u '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ t), y +ᵥ U
[PROOFSTEP]
rcases totallyBounded_iff_subset_finite_iUnion_nhds_zero.mp (hv.isCompact_closure_image_closedBall 1).totallyBounded V
hV with
⟨T, hT, hTv⟩
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
⊢ ∃ t, Set.Finite t ∧ ↑u '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ t), y +ᵥ U
[PROOFSTEP]
have hTv : v '' closedBall 0 1 ⊆ _ := subset_closure.trans hTv
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv✝ : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
hTv : ↑v '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
⊢ ∃ t, Set.Finite t ∧ ↑u '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ t), y +ᵥ U
[PROOFSTEP]
refine' ⟨T, hT, _⟩
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv✝ : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
hTv : ↑v '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
⊢ ↑u '' closedBall 0 1 ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ U
[PROOFSTEP]
rw [image_subset_iff, preimage_iUnion₂] at hTv ⊢
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv✝ : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
hTv : closedBall 0 1 ⊆ ⋃ (i : M₂) (_ : i ∈ T), ↑v ⁻¹' (i +ᵥ V)
⊢ closedBall 0 1 ⊆ ⋃ (i : M₂) (_ : i ∈ T), ↑u ⁻¹' (i +ᵥ U)
[PROOFSTEP]
intro x hx
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv✝ : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
hTv : closedBall 0 1 ⊆ ⋃ (i : M₂) (_ : i ∈ T), ↑v ⁻¹' (i +ᵥ V)
x : M₁
hx : x ∈ closedBall 0 1
⊢ x ∈ ⋃ (i : M₂) (_ : i ∈ T), ↑u ⁻¹' (i +ᵥ U)
[PROOFSTEP]
specialize hTv hx
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv✝ : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
x : M₁
hx : x ∈ closedBall 0 1
hTv : x ∈ ⋃ (i : M₂) (_ : i ∈ T), ↑v ⁻¹' (i +ᵥ V)
⊢ x ∈ ⋃ (i : M₂) (_ : i ∈ T), ↑u ⁻¹' (i +ᵥ U)
[PROOFSTEP]
rw [mem_iUnion₂] at hTv ⊢
[GOAL]
case intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv✝ : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
x : M₁
hx : x ∈ closedBall 0 1
hTv : ∃ i j, x ∈ ↑v ⁻¹' (i +ᵥ V)
⊢ ∃ i j, x ∈ ↑u ⁻¹' (i +ᵥ U)
[PROOFSTEP]
rcases hTv with ⟨t, ht, htx⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
x : M₁
hx : x ∈ closedBall 0 1
t : M₂
ht : t ∈ T
htx : x ∈ ↑v ⁻¹' (t +ᵥ V)
⊢ ∃ i j, x ∈ ↑u ⁻¹' (i +ᵥ U)
[PROOFSTEP]
refine' ⟨t, ht, _⟩
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
x : M₁
hx : x ∈ closedBall 0 1
t : M₂
ht : t ∈ T
htx : x ∈ ↑v ⁻¹' (t +ᵥ V)
⊢ x ∈ ↑u ⁻¹' (t +ᵥ U)
[PROOFSTEP]
rw [mem_preimage, mem_vadd_set_iff_neg_vadd_mem, vadd_eq_add, neg_add_eq_sub] at htx ⊢
[GOAL]
case intro.intro.intro.intro.intro.intro.intro.intro
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
x : M₁
hx : x ∈ closedBall 0 1
t : M₂
ht : t ∈ T
htx : ↑v x - t ∈ V
⊢ ↑u x - t ∈ U
[PROOFSTEP]
convert hVU _ htx _ (huv x hx) using 1
[GOAL]
case h.e'_4
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
x : M₁
hx : x ∈ closedBall 0 1
t : M₂
ht : t ∈ T
htx : ↑v x - t ∈ V
⊢ ↑u x - t = ↑v x - t + -↑(v - u) x
[PROOFSTEP]
rw [ContinuousLinearMap.sub_apply]
[GOAL]
case h.e'_4
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
x : M₁
hx : x ∈ closedBall 0 1
t : M₂
ht : t ∈ T
htx : ↑v x - t ∈ V
⊢ ↑u x - t = ↑v x - t + -(↑v x - ↑u x)
[PROOFSTEP]
abel
[GOAL]
case h.e'_4
𝕜₁ : Type u_1
𝕜₂ : Type u_2
inst✝¹⁰ : NontriviallyNormedField 𝕜₁
inst✝⁹ : NormedField 𝕜₂
σ₁₂ : 𝕜₁ →+* 𝕜₂
M₁ : Type u_3
M₂ : Type u_4
inst✝⁸ : SeminormedAddCommGroup M₁
inst✝⁷ : AddCommGroup M₂
inst✝⁶ : NormedSpace 𝕜₁ M₁
inst✝⁵ : Module 𝕜₂ M₂
inst✝⁴ : UniformSpace M₂
inst✝³ : UniformAddGroup M₂
inst✝² : ContinuousConstSMul 𝕜₂ M₂
inst✝¹ : T2Space M₂
inst✝ : CompleteSpace M₂
u : M₁ →SL[σ₁₂] M₂
hu✝ : u ∈ closure {f | IsCompactOperator ↑f}
hu : ∀ (U : Set (M₁ →SL[σ₁₂] M₂)), U ∈ 𝓝 0 → ∃ y, y ∈ {f | IsCompactOperator ↑f} ∧ y - u ∈ U
U : Set M₂
hU : U ∈ 𝓝 0
V : Set M₂
hV : V ∈ 𝓝 0
hVU : ∀ (v : M₂), v ∈ V → ∀ (w : M₂), w ∈ V → v + w ∈ U
SV : Set M₁ × Set M₂ := (closedBall 0 1, -V)
v : M₁ →SL[σ₁₂] M₂
hv : v ∈ {f | IsCompactOperator ↑f}
huv : v - u ∈ {f | ∀ (x : M₁), x ∈ SV.fst → ↑f x ∈ SV.snd}
T : Set M₂
hT : Set.Finite T
hTv : closure (↑↑v '' closedBall 0 1) ⊆ ⋃ (y : M₂) (_ : y ∈ T), y +ᵥ V
x : M₁
hx : x ∈ closedBall 0 1
t : M₂
ht : t ∈ T
htx : ↑v x - t ∈ V
⊢ ↑u x - t = ↑v x - t + -(↑v x - ↑u x)
[PROOFSTEP]
abel
|
/-
Grading rubric. 7 points per question up to 100 max.
Partial credit by subproblem.
-/
/-
Note: An incorrect answer above or below
a correct answer can cause Lean to be unable
to process the correct answer. If you are not
able to complete a problem succesfully please
comment out your incomplete answer so that we
can see your work but so that your incomplete
work does not cause problems for surrounding
problems and answers.
-/
/-
PART I: Functions. Functions are an essential
element of the language of predicate logic. In
this section, you show that you understand how
to define, use, and reason about functions in
Lean.
-/
/- 1.
Study each of the following definitions,
then answer the associated question about
the types involved in these definitions.
-/
-- Consider this function
def f (n : ℕ) (s : string) := s
/-
a. What is it's return type? Answer: string
-/
/-
b. What is the type of (f 5)? Answer: string → string
-/
#check f 5
/-
c. What is the value of (f 0 "yay") "yay"
-/
#eval f 0 "yay"
/-
d. What is the type of this function? nat → string → string
-/
#check f
/- 2.
Define three functions called square,
square', and square'', each of type
ℕ to ℕ. Each function must return the
square of the value to which it is
applied. Write the first function in
"C" style, the second using a tactic
script, and the third using a lambda
abstraction. Declare argument and return
types explicitly in each case.
-/
def square (n : ℕ) : ℕ := n^2
def square' (n : ℕ) : ℕ :=
begin
exact n^2
end
def square'' : ℕ → ℕ :=
λ n : ℕ, n^2
/- 3.
Construct three proofs to test your
function definitions. The first must
use "lemma" to define a proof, called
square_3_9, of the proposition that
(square 3) equals 9. The second must
use "theorem" to define a proof, called
square'_4_16, of the proposition that
square' applied to 4 reduces to 16. The
third must prove that square'' 5 is
equal to 25. This third proof must not
use the equals sign, =, but must use
"eq" instead to state the proposition
to be proved. Hint on #3, sometimes
you need to use parentheses to express
how you want terms to be grouped.
-/
lemma square_3_9 : square 3 = 9 := rfl
theorem square_4_16 : square' 4 = 16 := rfl
example : eq (square'' 5) 25 := rfl
/- 4.
Define a function called last_first.
It takes two string values, called
"first" and "last" (without quotes),
as arguments, and it returns a string
consisting of "last" followed by a
comma and a space followed by "first".
For example (first "Orson" "Welles").
Write a test case for your function to
prove that (last_first "Orson" "Welles")
is "Welles, Orson". Use "example", to
check the proof. Hint: The ++ operator
implements the string append function.
-/
def last_first (first last : string) :=
last ++ ", " ++ first
example: (last_first "Orson" "Welles") = "Welles, Orson" := rfl
/- 5.
Complete the following definition of a
function, called apply3. It takes, as an
argument, a function, you might call it f,
of type ℕ → ℕ. It must return a function,
also of type ℕ to ℕ, that, when applied
to a value, n, returns the result of
applying the given function, f, to the
given value, n, three times. That is, it
returns a function that computes f(f(f(n))).
-/
def apply3 : (ℕ → ℕ) → (ℕ → ℕ) :=
λ f : (ℕ → ℕ),
λ n, f (f (f n))
-- Just an extra sanity check, not required
#reduce apply3 (λ n, n^2) 2
/- 6.
The Lean libraries define a function,
string.length, that takes a string and
returns its length as a natural number.
Define a function, len2, that takes two
strings and returns the sum of their
lengths. You may use the ++ operator
but not the + operator in your answer.
Follow your function definition with a
test case in the form of a proof using
"example" showing that len2 applied to
"Orson" and "Welles" is 11.
-/
def len2 (s1 s2 : string) : ℕ :=
string.length (s1 ++ s2)
example : len2 "Orson" "Welles" = 11 := rfl
/- 7.
Use "example" to prove that there is a
function of the following type:
((ℕ → ℕ) → (ℕ → ℕ)) →
((ℕ → ℕ) → ℕ) →
((ℕ → ℕ) → ℕ)
-/
example :
((ℕ → ℕ) → (ℕ → ℕ)) →
((ℕ → ℕ) → ℕ) →
((ℕ → ℕ) → ℕ)
:= λ f g, g
/-
PART II: Functions, revited. In
mathematics, functions play a central
role. A function, f, in the mathematical
sense is a triple, f = { D, P, C }, where
D, a set, is the domain of definition of
f, C is the co-domain of f, and P is a
set of ordered pairs, each with a first
element from D and a second element from
C,. In addition, P has one additional
essential property, the subject of one
of the following questions.
-/
/- 8.
What one additional property is essential to
the definition of what it means for a triple,
{ D, P, C } to be a function?
Name the property. Answer: Single-Valued
Now explain precisely what it means: "That there
are no two pairs, (x, y) and (x', y') such that..."
Fill in the blank, and use a logical ∧ in answering.
You might also want to use = or ≠.
Answer: x = x' ∧ y ≠ y'
-/
/- 9.
Give names to the following concepts:
The set of all values appearing as the first
element of any pair in P.
Answer: domain
The set of all values appearing as the second
element of any pair in P.
Answer: range
The property that the set of all values
appearing as the first element of P is the
same as D.
Answer: total
Answer: The property that the set of all
values appearing as the first element of
P is the same as C.
Answer: surjective
The property of having both of the preceding
properties.
Answer: bijective
-/
/- 10.
What does it mean for a function, f, to be
injective? Give you answer by completing the
following sentences with logical expressions.
"A function, f, is said to be injective if
it has no two pairs, (x, y) and (x', y'),
such that ..."
Answer: x ≠ x' ∧ y = y'
In other words, "If (x, y) and (x', y') are
related by f and x ≠ x' then ..."
Answer: y ≠ y'
-/
/- 11.
Suppose that S and T are types and that f
is defined to be a function, *in Lean*, of
type S → T. Which of the following properties,
if any, does f necessarily have?
- N: injective
- N: surjective
- N: bijective
- N: one-to-many
- N: one-to-one
- N: onto
- Y: single-valued
- Y: partial (but not strictly partial)
- Y: total
Answer: single valued, total, partial (if we define partial functions
to include total functions)
-/
/-
PART III: Logic and Proof.
-/
/- 12a.
Use axiom and/or axioms in Lean to express,
in formal logic, the following assumptions:
- T is a type
- t1 and t2 are values of type T
- t1 = t2
Answer immediately after this comment block.
If you need to introduce a name, use eqt1t2.
-/
axiom T : Type
axioms t1 t2 : T
axiom eqt1t2 : t1 = t2
/- 12b.
Use axiom or axioms to represent the
additional assumptions that
- P is a property of objects of type T
- t1 has property P
If you need to use a name, use Pt1
-/
axiom P : T → Prop
axiom Pt1 : P t1
/- 12 c.
Now use "example" to assert, and then
prove, that t2 also has property P.
-/
example : P t2 := eq.subst eqt1t2 Pt1
/- 13 a.
Define eq_1_0 to be the proposition, 1 = 0.
-/
def eq_1_0 := 1 = 0
/- 13 b.
Define pf_eq_0_0 to be a proof of the
proposition that 0 = 0. Use the lemma
keyword.
-/
lemma pf_eq_0_0 : 0 = 0 := rfl
/- 13 c.
Write a function, w, that takes three
values, a, b, and c of type ℕ, and that
also takes proofs, cb : c = b, and
ba : b = a, and that returns a proof
that a = c.
-/
def w (a b c : ℕ) (cb : c = b) (ba : b = a) :
a = c :=
eq.trans (eq.symm ba) (eq.symm cb)
#check w
/- 13d.
What is the type of this function?
Answer: ∀ (a b c : ℕ), c = b → b = a → a = c
What is the form of this proposition?
Answer: universal generalization
What's the form the proposition after the
comma?
Answer: Implication
What is the premise of the proposition after
the comma?
Answer: c = b
-/
/- 14.
Complete the following proofs. Give each one
in the form indicate by a comment preceding
the statement of the conjecture to be proved.
When using tactic scripts, remember to write
begin/end pairs right away, so Lean knowns
you want to use a tactic script.
-/
-- lambda expression
example : ∀ (s : string), s = s :=
λ s, eq.refl s
-- lambda expresion
example : ∀ (n : ℕ), ∀ (m : ℕ), true :=
λ n m, true.intro
-- tactic script
example : ∀ (T : Type), ∀ (t : T), eq t t :=
begin
assume T t,
exact eq.refl t
end
-- tactic script
example :
∀ (T : Type),
∀ (P : T → Prop),
∀ t1 t2 : T,
∀ Pt1 : P t1,
∀ t2t1 : t2 = t1,
P t2 :=
begin
assume T P t1 t2 Pt1 t2t1,
exact eq.subst (eq.symm t2t1) Pt1
end
/-
The following problems involve implications.
For example, false → P in an implication. To
prove an implication, just show that there is
(by giving) a function of the specified type.
-/
-- lambda expression
example : ∀ (P : Prop), false → P :=
λ P, λ f, false.elim f
-- tactic script
example : ∀ (P : Prop), false → P :=
begin
assume P f,
exact false.elim f
end
-- lambda expression
example : ∀ (P Q : Prop), P ∧ Q → Q ∧ P :=
λ P Q pq, and.intro pq.right pq.left
-- tactic script
example : ∀ (P Q : Prop), P ∧ Q → Q ∧ P :=
begin
assume P Q pq,
exact and.intro pq.right pq.left
end
-- tactic script
example :
∀ T : Type,
∀ (t1 t2 t3 : T),
t1 = t2 ∧ t2 = t3 → t1 = t3 :=
begin
assume T t1 t2 t3 p,
exact eq.trans p.left p.right
end
/- 15.
Use Lean to model a world in which there
are Dogs, all Dogs are friendly, and Fido
is a Dog, then give a proof that in this
world, Fido must be friendly, too.
-/
axioms Dog : Type
axiom Fido : Dog
axiom Friendly : Dog → Prop
axiom allFriendly : ∀ d : Dog, Friendly d
-- proof is by application of forall elimination
example : Friendly Fido := allFriendly Fido |
# global.R
# Code here is in scope to both ui.R and server.R
#Load required library
library(leaflet)
# Get dataset from CSV
inputstn <- read.csv("/srv/shiny-server/data/inputdata.txt", header=TRUE)
# Create a vector of country subdivions (i.e. regions in France)
#inputstn <- subset(inputstn, Country == "FR" )
regions <- unique(as.vector(inputstn$REGION))
|
||| Test extended record syntax
data NotZero : Nat -> Type where
Is : {n : Nat} -> NotZero (S n)
record Positive (n : Nat) {auto 0 pos : NotZero n} where
constructor Check
a : Positive 1
a = Check
b : Positive 2
b = Check
{- Will not type-check
c : Positive 0
-}
data KindOfString = ASCII | UTF
UTForASCII : KindOfString -> Type
UTForASCII UTF = String
UTForASCII ASCII = List Char --- Just to demonstrate
record FlexiString { default UTF k : KindOfString} where
constructor MkFlexiString
val : UTForASCII k
c : FlexiString
c = MkFlexiString "hello"
d : FlexiString {k = ASCII}
d = MkFlexiString ['h', 'i']
|
# Week 3 worksheet 1: Root finding methods
This notebook is modified from one created by Charlotte Desvages.
This notebook investigates the first root finding algorithms to solve nonlinear equations: the **bisection method** and **fixed-point iteration**.
The best way to learn programming is to write code. Don't hesitate to edit the code in the example cells, or add your own code, to test your understanding. You will find practice exercises throughout the notebook, denoted by 🚩 ***Exercise $x$:***.
#### Displaying solutions
Solutions will be released one week after the worksheets are released, as a new `.txt` file in the same GitHub repository. After pulling the file to your workspace, run the following cell to create clickable buttons under each exercise, which will allow you to reveal the solutions.
```python
%run scripts/create_widgets.py W03-W1
```
---
### 📚 Book sections
- **ASC**: sections 5.1, **5.2**
- **PCP**: sections 7.1.3, 7.4
## Bracketing methods: bisection and regula falsi
**Bracketing methods** seek to find smaller and smaller **intervals** $[a, b]$ which contain a root.
They rely on the Intermediate Value Theorem: for a continuous function $F(x)$, if $F(a)$ has different sign than $F(b)$, then $F(x)$ has a root $x_\ast \in [a, b]$.
### Bisection
Key idea: start with an interval $[a, b]$ such that $F(a)$ and $F(b)$ have different signs.
Then, split the interval in two, and evaluate $F(\frac{a+b}{2})$ at the midpoint. Compare the sign of $F(\frac{a+b}{2})$ with the sign of $F(a)$ and $F(b)$, and choose the half-interval which still contains the root. Repeat the procedure with the new, smaller interval, until convergence.
### Regula falsi
Similar to bisection, but instead of choosing the midpoint, we choose the point of intersection between the x-axis and a straight line passing through the points $(a, F(a))$ and $(b, F(b))$.
---
## Solving nonlinear equations with root-finding algorithms
In this section, we consider equations of the form
$$
F(x) = 0,
$$
where $F(x)$ is a **nonlinear** function of $x$. Solving this equation is equivalent to finding the *root(s)* $x_\ast$ of the function $F$.
There are direct methods we can use to solve *linear* equations, even linear systems of equations as we saw previously; however, a nonlinear equation of the form given above doesn't always have a solution which can be found analytically.
The methods we will discuss to solve nonlinear equations are all **iterative**:
1. we start with a guess for where the root may be;
2. if we are close enough to the solution, for instance if the function is sufficiently close to zero for the current guess, we stop;
3. if not, we refine our guess using information we have about the function;
4. we go back to step 1 with our new guess.
Step 3 is what differentiates the methods we will use, as they each use a different process to refine the current best guess. For all these methods, the key idea is to reduce the nonlinear problem to smaller, simpler problems, which we solve repeatedly (iteratively).
### The bisection method
Given a continuous function $F \left( x \right)$, if $F \left( a \right) \le 0$ and $F \left( b \right) \ge 0$, the Intermediate Value Theorem tells us that there must be a root in the closed interval $\left[ a, b \right].$ The bisection method proceeds by testing the **sign** of $F \left( c \right)$ where $c$ is the **mid-point** of the interval $\left[ a, b \right]$, and uses this to halve the size of the interval in which a root is sought. The process is repeated with the new half-interval, until the interval is small enough to approximate the root with a given tolerance.
The next few exercises will guide you through implementing the bisection method yourself.
---
**📚 Learn more:**
- **ASC**: section 5.2
- **PCP**: section 7.4
---
🚩 ***Exercise 1:***
Consider the function
\begin{equation}\label{eqn:F}
F \left( x \right) = \sin \left( 2 \pi x \right) e^{4 x} + x.
\end{equation}
Plot this function in the interval $x \in \left[ 0, 1 \right]$ and identify the three roots in this interval. Check that $F \left( 0.2 \right)$ and $F \left( 0.6 \right)$ have opposite signs.
You may find it convenient to create a function `F`.
```python
```
```python
%run scripts/show_solutions.py W03-W1_ex1
```
---
🚩 ***Exercise 2:*** Define variables corresponding to $a = 0.2$ and $b = 0.6$. Define $c$ to be the midpoint $c = (a + b) / 2$.
Then, start a loop, which should iterate until the root is found. At each iteration:
- Depending on the sign of $F \left( a \right) F \left( c \right)$, decide whether to set $a$ or $b$ to be equal to $c$, so that there is a root of $F \left( x \right)$ in the *new* interval $\left[ a, b \right]$ (with half the width of the previous interval).
- Define $c$ to be the new midpoint $c = (a + b) / 2$.
- The loop should stop when you have found the root $x_\ast$ within an error of $10^{-10}$.
A possible convergence criterion is $|F(c)| < \varepsilon$, where $\varepsilon$ is the tolerance -- here, $10^{-10}$.
How many iterations are needed to find the root to within this error?
```python
```
```python
%run scripts/show_solutions.py W03-W1_ex2
```
---
🚩 ***Exercise 3:*** Choose different $a$ and $b$ values in order to find the root near $x = 1$, to within an error of $10^{-10}$.
You may wish to write your code from Exercise 2 into a function `bisection(F, a, b, tol)`, which finds the root of a function `F` in the interval `[a, b]` to within an error of `tol`, and returns the value of the roots and the number of iterations.
```python
```
```python
%run scripts/show_solutions.py W03-W1_ex3
```
---
### Regula falsi
The "regula falsi" method is similar to the bisection method, with an important difference: instead of selecting the midpoint of the interval $[a, b]$ at each iteration, we trace a straight line between the points $(a, F(a))$ and $(b, F(b))$, and select the point $c$ where this line intersects the x-axis. In other words, we interpolate $F$ linearly between $a$ and $b$, and we find the root of this interpolating polynomial (of degree 1) at each iteration.
---
🚩 ***Exercise 4:*** Show that $c$ is given by
$$
c = \frac{a F(b) - b F(a)}{F(b) - F(a)}.
$$
*Hint: a line with slope $\alpha$ which passes through the point $(x_0, y_0)$ has equation*
$$
y - y_0 = \alpha (x - x_0).
$$
```python
%run scripts/show_solutions.py W03-W1_ex4
```
---
🚩 ***Exercise 5:*** Consider the same function $F$ as in section 2.1.
Define variables corresponding to $a = 0.2$ and $b = 0.6$.
Then, proceed as you did for the bisection method, but instead of defining $c$ to be the midpoint of $[a, b]$, define $c$ as above.
How many iterations are needed to find the root to within a tolerance of $10^{-10}$?
You may wish to define a function `regula_falsi(F, a, b, tol)` to find a root of a function `F` within an interval `[a, b]` to within an error `tol`, which returns the computed root and the number of iterations.
```python
```
```python
%run scripts/show_solutions.py W03-W1_ex5
```
---
## Convergence of root-finding methods
The bisection and regula falsi methods are guaranteed to converge to a root, provided $F$ is sufficiently smooth and the starting interval $[a, b]$ is chosen appropriately.
But different methods may converge to a root at different *speeds*. The **order of convergence** for root-finding algorithms is defined in terms of successive values of the error $e_k := x_k - x_\ast$ between the true solution $x_\ast$ and the guess $x_k$ obtained at the $k$th iteration.
---
#### 🚩 Definition: Order of convergence of root-finding methods
A convergent root-finding algorithm converges **at $p$th order** if
$$
\lim_{k \to \infty} \frac{|e_{k+1}|}{|e_k|^p} = \alpha,
$$
where $\alpha \in \mathbb{R}$ is a constant.
---
For a $p$th order convergent method, we expect the error at the $k+1$th iteration to be roughly proportional to the $p$th power of the error at the $k$th iteration, for sufficiently large $k$ -- that is, when we are in a close enough neighbourhood of $x_\ast$.
Note that $p$ is not always an integer.
---
🚩 ***Exercise 6:*** Modify your code from Exercise 5 so that all the successive guesses $x_k$ are stored in a Numpy array. Perform the task from Exercise 6 again -- use the regula falsi method to find the same root of `F`, using the same starting interval and tolerance. You should obtain the same result, but now you should also have a vector `x` with length $k_\max + 1$ containing all the guesses.
Consider $x_{k_\max}$, the last guess obtained by the method, to be the "true solution". Compute the magnitude of the error $e_k$ between each of the previous guesses $x_k$ and the true solution.
For $p=1, 1.5, 2, 2.5$, compute the ratio $\frac{|e_{k+1}|}{|e_k|^p}$ for $k=0, 1, \dots, k_\max - 1$, and plot it against $k$. Set your y-axis limits to $[0, 1000]$ to start with, and reduce the range as necessary.
Given the definition above, what do you expect is the order of convergence of regula falsi? How do you explain the appearance of the graph?
```python
```
```python
%run scripts/show_solutions.py W03-W1_ex6
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.