Datasets:
AI4M
/

text
stringlengths
0
3.34M
lemma convex_UNIV[intro,simp]: "convex UNIV"
using EconPDEs Base.@kwdef struct CampbellCochraneModel # consumption process parameters μ::Float64 = 0.0189 σ::Float64 = 0.015 # utility γ::Float64 = 2.0 ρ::Float64 = 0.116 # habit κs::Float64 = 0.138 b::Float64 = 0.0 end # I choose persistence so that monthly simulation of the model matches processes in CC (1999) # ρ = 12 * (1 - 0.89^(1/12)) # κs = 12 * (1 - 0.87^(1/12)) function initialize_stategrid(m::CampbellCochraneModel; sn = 1000) μ = m.μ ; σ = m.σ ; γ = m.γ ; ρ = m.ρ ; κs = m.κs ; b = m.b Sbar = σ * sqrt(γ / (κs - b / γ)) sbar = log.(Sbar) smax = sbar + 0.5 * (1 - Sbar^2) # corresponds to Grid 3 in Wachter (2005) shigh = log.(range(0.0, exp(smax), length = div(sn, 10))) slow = range(-300.0, shigh[2], length = sn - div(sn, 10)) OrderedDict(:s => vcat(slow[1:(end-1)], shigh[2:end])) end function (m::CampbellCochraneModel)(state::NamedTuple, y::NamedTuple) (; μ, σ, γ, ρ, κs, b) = m (; s) = state (; p, ps_up, ps_down, pss) = y # drift and volatility of s and p Sbar = σ * sqrt(γ / (κs - b / γ)) sbar = log(Sbar) λ = 1 / Sbar * sqrt(1 - 2 * (s - sbar)) - 1 μs = - κs * (s - sbar) ps = (μs >= 0) ? ps_up : ps_down σs = λ * σ σp = ps / p * σs μp = ps / p * μs + 0.5 * pss / p * σs^2 # market price of risk κ κ = γ * (σ + σs) # risk free rate r r = ρ + γ * μ - (γ * κs - b) / 2 + b * (sbar - s) # PDE pt = - p * (1 / p + μ + μp + σp * σ - r - κ * (σ + σp)) return (; pt) end # Campbell Cochrane (1999) m = CampbellCochraneModel() stategrid = initialize_stategrid(m) yend = OrderedDict(:p => ones(length(stategrid[:s]))) result = pdesolve(m, stategrid, yend) @assert result.residual_norm <= 1e-5 # Wachter (2005) calibration # m = CampbellCochraneModel(μ = 0.022, σ = 0.0086, γ = 2.0, ρ = 0.073, κs = 0.116, b = 0.011) # stategrid = initialize_stategrid(m) # yend = OrderedDict(:p => ones(length(stategrid[:s]))) # y, result, distance = pdesolve(m, stategrid, yend)
State Before: c : Char ⊢ 0 < csize c State After: no goals Tactic: rcases csize_eq c with _|_|_|_ <;> simp_all
Formal statement is: lemma compactE_image: assumes "compact S" and opn: "\<And>T. T \<in> C \<Longrightarrow> open (f T)" and S: "S \<subseteq> (\<Union>c\<in>C. f c)" obtains C' where "C' \<subseteq> C" and "finite C'" and "S \<subseteq> (\<Union>c\<in>C'. f c)" Informal statement is: Suppose $S$ is a compact set and $f$ is a collection of open sets such that $S \subseteq \bigcup_{c \in C} f(c)$. Then there exists a finite subset $C'$ of $C$ such that $S \subseteq \bigcup_{c \in C'} f(c)$.
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import ring_theory.integrally_closed import ring_theory.polynomial.scale_roots /-! # 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 -/ section scale_roots variables {A K R S : Type*} [comm_ring A] [field K] [comm_ring R] [comm_ring S] variables {M : submonoid A} [algebra A S] [is_localization M S] [algebra A K] [is_fraction_ring A K] open finsupp is_fraction_ring is_localization polynomial lemma scale_roots_aeval_eq_zero_of_aeval_mk'_eq_zero {p : polynomial A} {r : A} {s : M} (hr : aeval (mk' S r s) p = 0) : aeval (algebra_map A S r) (scale_roots p s) = 0 := begin convert scale_roots_eval₂_eq_zero (algebra_map A S) hr, rw [aeval_def, mk'_spec' _ r s] end variables [is_domain A] lemma num_is_root_scale_roots_of_aeval_eq_zero [unique_factorization_monoid A] {p : polynomial A} {x : K} (hr : aeval x p = 0) : is_root (scale_roots p (denom A x)) (num A x) := begin apply is_root_of_eval₂_map_eq_zero (is_fraction_ring.injective A K), refine scale_roots_aeval_eq_zero_of_aeval_mk'_eq_zero _, rw mk'_num_denom, exact hr end end scale_roots section rational_root_theorem variables {A K : Type*} [comm_ring A] [is_domain A] [unique_factorization_monoid A] [field K] variables [algebra A K] [is_fraction_ring A K] open is_fraction_ring is_localization polynomial unique_factorization_monoid /-- 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 {p : polynomial A} {r : K} (hr : aeval r p = 0) : num A r ∣ p.coeff 0 := begin suffices : num A r ∣ (scale_roots p (denom A r)).coeff 0, { simp only [coeff_scale_roots, tsub_zero] at this, haveI := classical.prop_decidable, by_cases hr : num A r = 0, { obtain ⟨u, hu⟩ := (is_unit_denom_of_num_eq_zero hr).pow p.nat_degree, rw ←hu at this, exact units.dvd_mul_right.mp this }, { refine dvd_of_dvd_mul_left_of_no_prime_factors hr _ this, intros q dvd_num dvd_denom_pow hq, apply hq.not_unit, exact num_denom_reduced A r dvd_num (hq.dvd_of_dvd_pow dvd_denom_pow) } }, convert dvd_term_of_is_root_of_dvd_terms 0 (num_is_root_scale_roots_of_aeval_eq_zero hr) _, { rw [pow_zero, mul_one] }, intros j hj, apply dvd_mul_of_dvd_right, convert pow_dvd_pow (num A r) (nat.succ_le_of_lt (bot_lt_iff_ne_bot.mpr hj)), exact (pow_one _).symm end /-- 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 {p : polynomial A} {r : K} (hr : aeval r p = 0) : (denom A r : A) ∣ p.leading_coeff := begin suffices : (denom A r : A) ∣ p.leading_coeff * num A r ^ p.nat_degree, { refine dvd_of_dvd_mul_left_of_no_prime_factors (mem_non_zero_divisors_iff_ne_zero.mp (denom A r).2) _ this, intros q dvd_denom dvd_num_pow hq, apply hq.not_unit, exact num_denom_reduced A r (hq.dvd_of_dvd_pow dvd_num_pow) dvd_denom }, rw ←coeff_scale_roots_nat_degree, apply dvd_term_of_is_root_of_dvd_terms _ (num_is_root_scale_roots_of_aeval_eq_zero hr), intros j hj, by_cases h : j < p.nat_degree, { rw coeff_scale_roots, refine (dvd_mul_of_dvd_right _ _).mul_right _, convert pow_dvd_pow _ (nat.succ_le_iff.mpr (lt_tsub_iff_left.mpr _)), { exact (pow_one _).symm }, simpa using h }, rw [←nat_degree_scale_roots p (denom A r)] at *, rw [coeff_eq_zero_of_nat_degree_lt (lt_of_le_of_ne (le_of_not_gt h) hj.symm), zero_mul], exact dvd_zero _ end /-- 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 {p : polynomial A} (hp : monic p) {r : K} (hr : aeval r p = 0) : is_integer A r := is_integer_of_is_unit_denom (is_unit_of_dvd_one _ (hp ▸ denom_dvd_of_is_root hr)) namespace unique_factorization_monoid lemma integer_of_integral {x : K} : is_integral A x → is_integer A x := λ ⟨p, hp, hx⟩, is_integer_of_is_root_of_monic hp hx @[priority 100] -- See library note [lower instance priority] instance : is_integrally_closed A := ⟨λ x, integer_of_integral⟩ end unique_factorization_monoid end rational_root_theorem
# devtools::install_github("ficonsulting/RInno@2a980b9") library("RInno") mzEasyPath <- "C:/Users/CMC/Documents/GitHub/mzEASY" setwd(file.path(mzEasyPath, "build/Create_Executable/inst/app")) filesToInclude <- list.files("www", full.names = T, recursive = TRUE) filesToInclude <- list.files("library", full.names = T, recursive = TRUE) filesToInclude <- list.files("example_data", full.names = T, recursive = TRUE) create_app( app_name = "mzEASY", dir_out = "wizard", files = filesToInclude, include_R = TRUE, # Download R and install it with your app, if necessary R_version = "3.5.0", # Specified version to include of R privilege = "none", # Admin only installation default_dir = "userdocs", # app_icon = "icon.ico", # setup_icon = "install.ico", compression = "bzip", #info_after = "infoafter.txt", #info_before = "infobefore.txt", license_file = "License.txt", app_version = "0.0.1", app_repo_url = "https://github.com/chasemc/mzEASY") compile_iss()
function varargout = tapas_uniqc_example_slider4d() %creates 4D dataset numerically and runs tapas_uniqc_slider4d to show capability of it % % tapas_uniqc_example_slider4d() % % IN % % OUT % % EXAMPLE % tapas_uniqc_example_slider4d % % See also % Author: Lars Kasper % Created: 2013-05-15 % Copyright (C) 2013 Institute for Biomedical Engineering, ETH/Uni Zurich. Y = tapas_uniqc_create_shepp_logan_4d(); nSli = 1; tapas_uniqc_slider4d(Y, @tapas_uniqc_plot_image_diagnostics, nSli); if nargout > 1 varargout{1} = Y; end
header {* \isaheader{Information Flow for While} *} theory NonInterferenceWhile imports SemanticsWellFormed StaticControlDependences "../../InformationFlowSlicing/LiftingIntra" begin locale SecurityTypes = fixes H :: "vname set" fixes L :: "vname set" assumes HighLowDistinct: "H \<inter> L = {}" and HighLowUNIV: "H \<union> L = UNIV" begin subsection {* Lifting @{term labels_nodes} and Defining @{text final} *} fun labels_LDCFG_nodes :: "cmd \<Rightarrow> w_node LDCFG_node \<Rightarrow> cmd \<Rightarrow> bool" where "labels_LDCFG_nodes prog (Node n) c = labels_nodes prog n c" | "labels_LDCFG_nodes prog n c = False" lemmas WCFG_path_induct[consumes 1, case_names empty_path Cons_path] = CFG.path.induct[OF While_CFG_aux] lemma lift_valid_node: assumes "CFG.valid_node sourcenode targetnode (valid_edge prog) n" shows "CFG.valid_node src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (Node n)" proof - from `CFG.valid_node sourcenode targetnode (valid_edge prog) n` obtain a where "valid_edge prog a" and "n = sourcenode a \<or> n = targetnode a" by(fastforce simp:While_CFG.valid_node_def) from `n = sourcenode a \<or> n = targetnode a` show ?thesis proof assume "n = sourcenode a" show ?thesis proof(cases "sourcenode a = Entry") case True have "lift_valid_edge (valid_edge prog) sourcenode targetnode kind Entry Exit (NewEntry,(\<lambda>s. True)\<^sub>\<surd>,Node Entry)" by(fastforce intro:lve_Entry_edge) with While_CFGExit_wf_aux[of prog] `n = sourcenode a` True show ?thesis by(fastforce simp:CFG.valid_node_def[OF lift_CFG]) next case False with `valid_edge prog a` `n = sourcenode a \<or> n = targetnode a` have "lift_valid_edge (valid_edge prog) sourcenode targetnode kind Entry Exit (Node (sourcenode a),kind a,Node (targetnode a))" by(fastforce intro:lve_edge) with While_CFGExit_wf_aux[of prog] `n = sourcenode a` show ?thesis by(fastforce simp:CFG.valid_node_def[OF lift_CFG]) qed next assume "n = targetnode a" show ?thesis proof(cases "targetnode a = Exit") case True have "lift_valid_edge (valid_edge prog) sourcenode targetnode kind Entry Exit (Node Exit,(\<lambda>s. True)\<^sub>\<surd>,NewExit)" by(fastforce intro:lve_Exit_edge) with While_CFGExit_wf_aux[of prog] `n = targetnode a` True show ?thesis by(fastforce simp:CFG.valid_node_def[OF lift_CFG]) next case False with `valid_edge prog a` `n = sourcenode a \<or> n = targetnode a` have "lift_valid_edge (valid_edge prog) sourcenode targetnode kind Entry Exit (Node (sourcenode a),kind a,Node (targetnode a))" by(fastforce intro:lve_edge) with While_CFGExit_wf_aux[of prog] `n = targetnode a` show ?thesis by(fastforce simp:CFG.valid_node_def[OF lift_CFG]) qed qed qed lemma lifted_CFG_fund_prop: assumes "labels_LDCFG_nodes prog n c" and "\<langle>c,s\<rangle> \<rightarrow>* \<langle>c',s'\<rangle>" shows "\<exists>n' as. CFG.path src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) n as n' \<and> transfers (CFG.kinds knd as) s = s' \<and> preds (CFG.kinds knd as) s \<and> labels_LDCFG_nodes prog n' c'" proof - from `labels_LDCFG_nodes prog n c` obtain nx where "n = Node nx" and "labels_nodes prog nx c" by(cases n) auto from `labels_nodes prog nx c` `\<langle>c,s\<rangle> \<rightarrow>* \<langle>c',s'\<rangle>` obtain n' as where "prog \<turnstile> nx -as\<rightarrow>* n'" and "transfers (CFG.kinds kind as) s = s'" and "preds (CFG.kinds kind as) s" and "labels_nodes prog n' c'" by(auto dest:While_semantics_CFG_wf.fundamental_property) from `labels_nodes prog n' c'` have "labels_LDCFG_nodes prog (Node n') c'" by simp from `prog \<turnstile> nx -as\<rightarrow>* n'` `transfers (CFG.kinds kind as) s = s'` `preds (CFG.kinds kind as) s` `n = Node nx` `labels_nodes prog nx c` `labels_nodes prog n' c'` have "\<exists>es. CFG.path src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (Node nx) es (Node n') \<and> transfers (CFG.kinds knd es) s = s' \<and> preds (CFG.kinds knd es) s" proof(induct arbitrary:n s c rule:WCFG_path_induct) case (empty_path n nx) from `CFG.valid_node sourcenode targetnode (valid_edge prog) n` have valid_node:"CFG.valid_node src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (Node n)" by(rule lift_valid_node) have "CFG.kinds knd ([]::(w_node LDCFG_node \<times> state edge_kind \<times> w_node LDCFG_node) list) = []" by(simp add:CFG.kinds_def[OF lift_CFG[OF While_CFGExit_wf_aux]]) with `transfers (CFG.kinds kind []) s = s'` `preds (CFG.kinds kind []) s` valid_node show ?case by(fastforce intro:CFG.empty_path[OF lift_CFG[OF While_CFGExit_wf_aux]] simp:While_CFG.kinds_def) next case (Cons_path n'' as n' a nx) note IH = `\<And>n s c. \<lbrakk>transfers (CFG.kinds kind as) s = s'; preds (CFG.kinds kind as) s; n = LDCFG_node.Node n''; labels_nodes prog n'' c; labels_nodes prog n' c'\<rbrakk> \<Longrightarrow> \<exists>es. CFG.path src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (LDCFG_node.Node n'') es (LDCFG_node.Node n') \<and> transfers (CFG.kinds knd es) s = s' \<and> preds (CFG.kinds knd es) s` from `transfers (CFG.kinds kind (a # as)) s = s'` have "transfers (CFG.kinds kind as) (transfer (kind a) s) = s'" by(simp add:While_CFG.kinds_def) from `preds (CFG.kinds kind (a # as)) s` have "preds (CFG.kinds kind as) (transfer (kind a) s)" and "pred (kind a) s" by(simp_all add:While_CFG.kinds_def) show ?case proof(cases "sourcenode a = (_Entry_)") case True with `sourcenode a = nx` `labels_nodes prog nx c` have False by simp thus ?thesis by simp next case False with `valid_edge prog a` have edge:"lift_valid_edge (valid_edge prog) sourcenode targetnode kind Entry Exit (Node (sourcenode a),kind a,Node (targetnode a))" by(fastforce intro:lve_edge) from `prog \<turnstile> n'' -as\<rightarrow>* n'` have "CFG.valid_node sourcenode targetnode (valid_edge prog) n''" by(rule While_CFG.path_valid_node) then obtain c'' where "labels_nodes prog n'' c''" proof(cases rule:While_CFGExit.valid_node_cases) case Entry with `targetnode a = n''` `valid_edge prog a` have False by fastforce thus ?thesis by simp next case Exit with `prog \<turnstile> n'' -as\<rightarrow>* n'` have "n' = (_Exit_)" by fastforce with `labels_nodes prog n' c'` have False by fastforce thus ?thesis by simp next case inner then obtain l'' where [simp]:"n'' = (_ l'' _)" by(cases n'') auto with `valid_edge prog a` `targetnode a = n''` have "l'' < #:prog" by(fastforce intro:WCFG_targetlabel_less_num_nodes simp:valid_edge_def) then obtain c'' where "labels prog l'' c''" by(fastforce dest:less_num_inner_nodes_label) with that show ?thesis by fastforce qed from IH[OF `transfers (CFG.kinds kind as) (transfer (kind a) s) = s'` `preds (CFG.kinds kind as) (transfer (kind a) s)` _ this `labels_nodes prog n' c'`] obtain es where "CFG.path src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (LDCFG_node.Node n'') es (LDCFG_node.Node n')" and "transfers (CFG.kinds knd es) (transfer (kind a) s) = s'" and "preds (CFG.kinds knd es) (transfer (kind a) s)" by blast with `targetnode a = n''` `sourcenode a = nx` edge have path:"CFG.path src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (LDCFG_node.Node nx) ((Node (sourcenode a),kind a,Node (targetnode a))#es) (LDCFG_node.Node n')" by(fastforce intro:CFG.Cons_path[OF lift_CFG[OF While_CFGExit_wf_aux]]) from edge have "knd (Node (sourcenode a),kind a,Node (targetnode a)) = kind a" by(simp add:knd_def) with `transfers (CFG.kinds knd es) (transfer (kind a) s) = s'` `preds (CFG.kinds knd es) (transfer (kind a) s)` `pred (kind a) s` have "transfers (CFG.kinds knd ((Node (sourcenode a),kind a,Node (targetnode a))#es)) s = s'" and "preds (CFG.kinds knd ((Node (sourcenode a),kind a,Node (targetnode a))#es)) s" by(auto simp:CFG.kinds_def[OF lift_CFG[OF While_CFGExit_wf_aux]]) with path show ?thesis by blast qed qed with `n = Node nx` `labels_LDCFG_nodes prog (Node n') c'` show ?thesis by fastforce qed fun final :: "cmd \<Rightarrow> bool" where "final Skip = True" | "final c = False" lemma final_edge: "labels_nodes prog n Skip \<Longrightarrow> prog \<turnstile> n -\<Up>id\<rightarrow> (_Exit_)" proof(induct prog arbitrary:n) case Skip from `labels_nodes Skip n Skip` have "n = (_ 0 _)" by(cases n)(auto elim:labels.cases) thus ?case by(fastforce intro:WCFG_Skip) next case (LAss V e) from `labels_nodes (V:=e) n Skip` have "n = (_ 1 _)" by(cases n)(auto elim:labels.cases) thus ?case by(fastforce intro:WCFG_LAssSkip) next case (Seq c\<^sub>1 c\<^sub>2) note IH2 = `\<And>n. labels_nodes c\<^sub>2 n Skip \<Longrightarrow> c\<^sub>2 \<turnstile> n -\<Up>id\<rightarrow> (_Exit_)` from `labels_nodes (c\<^sub>1;; c\<^sub>2) n Skip` obtain l where "n = (_ l _)" and "l \<ge> #:c\<^sub>1" and "labels_nodes c\<^sub>2 (_ l - #:c\<^sub>1 _) Skip" by(cases n)(auto elim:labels.cases) from IH2[OF `labels_nodes c\<^sub>2 (_ l - #:c\<^sub>1 _) Skip`] have "c\<^sub>2 \<turnstile> (_ l - #:c\<^sub>1 _) -\<Up>id\<rightarrow> (_Exit_)" . with `l \<ge> #:c\<^sub>1` have "c\<^sub>1;;c\<^sub>2 \<turnstile> (_ l - #:c\<^sub>1 _) \<oplus> #:c\<^sub>1 -\<Up>id\<rightarrow> (_Exit_) \<oplus> #:c\<^sub>1" by(fastforce intro:WCFG_SeqSecond) with `n = (_ l _)` `l \<ge> #:c\<^sub>1` show ?case by(simp add:id_def) next case (Cond b c\<^sub>1 c\<^sub>2) note IH1 = `\<And>n. labels_nodes c\<^sub>1 n Skip \<Longrightarrow> c\<^sub>1 \<turnstile> n -\<Up>id\<rightarrow> (_Exit_)` note IH2 = `\<And>n. labels_nodes c\<^sub>2 n Skip \<Longrightarrow> c\<^sub>2 \<turnstile> n -\<Up>id\<rightarrow> (_Exit_)` from `labels_nodes (if (b) c\<^sub>1 else c\<^sub>2) n Skip` obtain l where "n = (_ l _)" and disj:"(l \<ge> 1 \<and> labels_nodes c\<^sub>1 (_ l - 1 _) Skip) \<or> (l \<ge> #:c\<^sub>1 + 1 \<and> labels_nodes c\<^sub>2 (_ l - #:c\<^sub>1 - 1 _) Skip)" by(cases n) (fastforce elim:labels.cases)+ from disj show ?case proof assume "1 \<le> l \<and> labels_nodes c\<^sub>1 (_ l - 1 _) Skip" hence "1 \<le> l" and "labels_nodes c\<^sub>1 (_ l - 1 _) Skip" by simp_all from IH1[OF `labels_nodes c\<^sub>1 (_ l - 1 _) Skip`] have "c\<^sub>1 \<turnstile> (_ l - 1 _) -\<Up>id\<rightarrow> (_Exit_)" . with `1 \<le> l` have "if (b) c\<^sub>1 else c\<^sub>2 \<turnstile> (_ l - 1 _) \<oplus> 1 -\<Up>id\<rightarrow> (_Exit_) \<oplus> 1" by(fastforce intro:WCFG_CondThen) with `n = (_ l _)` `1 \<le> l` show ?case by(simp add:id_def) next assume "#:c\<^sub>1 + 1 \<le> l \<and> labels_nodes c\<^sub>2 (_ l - #:c\<^sub>1 - 1 _) Skip" hence "#:c\<^sub>1 + 1 \<le> l" and "labels_nodes c\<^sub>2 (_ l - #:c\<^sub>1 - 1 _) Skip" by simp_all from IH2[OF `labels_nodes c\<^sub>2 (_ l - #:c\<^sub>1 - 1 _) Skip`] have "c\<^sub>2 \<turnstile> (_ l - #:c\<^sub>1 - 1 _) -\<Up>id\<rightarrow> (_Exit_)" . with `#:c\<^sub>1 + 1 \<le> l` have "if (b) c\<^sub>1 else c\<^sub>2 \<turnstile> (_ l - #:c\<^sub>1 - 1 _) \<oplus> (#:c\<^sub>1 + 1) -\<Up>id\<rightarrow> (_Exit_) \<oplus> (#:c\<^sub>1 + 1)" by(fastforce intro:WCFG_CondElse) with `n = (_ l _)` `#:c\<^sub>1 + 1 \<le> l` show ?case by(simp add:id_def) qed next case (While b c) from `labels_nodes (while (b) c) n Skip` have "n = (_ 1 _)" by(cases n)(auto elim:labels.cases) thus ?case by(fastforce intro:WCFG_WhileFalseSkip) qed subsection {* Semantic Non-Interference for Weak Order Dependence *} lemmas WODNonInterferenceGraph = lift_wod_backward_slice[OF While_CFGExit_wf_aux HighLowDistinct HighLowUNIV] lemma WODNonInterference: "NonInterferenceIntra src trg knd (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewEntry (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) id (CFG_wf.wod_backward_slice src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L)) reds (labels_LDCFG_nodes prog) NewExit H L (LDCFG_node.Node (_Entry_)) (LDCFG_node.Node (_Exit_)) final" proof - interpret NonInterferenceIntraGraph src trg knd "lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)" NewEntry "lift_Def (Defs prog) (_Entry_) (_Exit_) H L" "lift_Use (Uses prog) (_Entry_) (_Exit_) H L" id "CFG_wf.wod_backward_slice src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L)" NewExit H L "LDCFG_node.Node (_Entry_)" "LDCFG_node.Node (_Exit_)" by(rule WODNonInterferenceGraph) interpret BackwardSlice_wf src trg knd "lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)" NewEntry "lift_Def (Defs prog) (_Entry_) (_Exit_) H L" "lift_Use (Uses prog) (_Entry_) (_Exit_) H L" id "CFG_wf.wod_backward_slice src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L)" reds "labels_LDCFG_nodes prog" proof(unfold_locales) fix n c s c' s' assume "labels_LDCFG_nodes prog n c" and "\<langle>c,s\<rangle> \<rightarrow>* \<langle>c',s'\<rangle>" thus "\<exists>n' as. CFG.path src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) n as n' \<and> transfers (CFG.kinds knd as) s = s' \<and> preds (CFG.kinds knd as) s \<and> labels_LDCFG_nodes prog n' c'" by(rule lifted_CFG_fund_prop) qed show ?thesis proof(unfold_locales) fix c n assume "final c" and "labels_LDCFG_nodes prog n c" from `final c` have [simp]:"c = Skip" by(cases c) auto from `labels_LDCFG_nodes prog n c` obtain nx where [simp]:"n = Node nx" and "labels_nodes prog nx Skip" by(cases n) auto from `labels_nodes prog nx Skip` have "prog \<turnstile> nx -\<Up>id\<rightarrow> (_Exit_)" by(rule final_edge) then obtain a where "valid_edge prog a" and "sourcenode a = nx" and "kind a = \<Up>id" and "targetnode a = (_Exit_)" by(auto simp:valid_edge_def) with `labels_nodes prog nx Skip` show "\<exists>a. lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_) a \<and> src a = n \<and> trg a = LDCFG_node.Node (_Exit_) \<and> knd a = \<Up>id" by(rule_tac x="(Node nx,\<Up>id,Node (_Exit_))" in exI) (auto intro!:lve_edge simp:knd_def valid_edge_def) qed qed subsection {* Semantic Non-Interference for Standard Control Dependence *} lemma inner_node_exists:"\<exists>n. CFGExit.inner_node sourcenode targetnode (valid_edge prog) (_Entry_) (_Exit_) n" proof - have "prog \<turnstile> (_Entry_) -(\<lambda>s. True)\<^sub>\<surd>\<rightarrow> (_0_)" by(rule WCFG_Entry) hence "CFG.valid_node sourcenode targetnode (valid_edge prog) (_0_)" by(auto simp:While_CFG.valid_node_def valid_edge_def) thus ?thesis by(auto simp:While_CFGExit.inner_node_def) qed lemmas SCDNonInterferenceGraph = lift_PDG_standard_backward_slice[OF WStandardControlDependence.PDG_scd WhilePostdomination_aux _ HighLowDistinct HighLowUNIV] lemma SCDNonInterference: "NonInterferenceIntra src trg knd (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewEntry (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) id (PDG.PDG_BS src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) (Postdomination.standard_control_dependence src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewExit)) reds (labels_LDCFG_nodes prog) NewExit H L (LDCFG_node.Node (_Entry_)) (LDCFG_node.Node (_Exit_)) final" proof - from inner_node_exists obtain n where "CFGExit.inner_node sourcenode targetnode (valid_edge prog) (_Entry_) (_Exit_) n" by blast then interpret NonInterferenceIntraGraph src trg knd "lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)" NewEntry "lift_Def (Defs prog) (_Entry_) (_Exit_) H L" "lift_Use (Uses prog) (_Entry_) (_Exit_) H L" id "PDG.PDG_BS src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) (Postdomination.standard_control_dependence src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewExit)" NewExit H L "LDCFG_node.Node (_Entry_)" "LDCFG_node.Node (_Exit_)" by(fastforce intro:SCDNonInterferenceGraph) interpret BackwardSlice_wf src trg knd "lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)" NewEntry "lift_Def (Defs prog) (_Entry_) (_Exit_) H L" "lift_Use (Uses prog) (_Entry_) (_Exit_) H L" id "PDG.PDG_BS src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) (Postdomination.standard_control_dependence src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewExit)" reds "labels_LDCFG_nodes prog" proof(unfold_locales) fix n c s c' s' assume "labels_LDCFG_nodes prog n c" and "\<langle>c,s\<rangle> \<rightarrow>* \<langle>c',s'\<rangle>" thus "\<exists>n' as. CFG.path src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) n as n' \<and> transfers (CFG.kinds knd as) s = s' \<and> preds (CFG.kinds knd as) s \<and> labels_LDCFG_nodes prog n' c'" by(rule lifted_CFG_fund_prop) qed show ?thesis proof(unfold_locales) fix c n assume "final c" and "labels_LDCFG_nodes prog n c" from `final c` have [simp]:"c = Skip" by(cases c) auto from `labels_LDCFG_nodes prog n c` obtain nx where [simp]:"n = Node nx" and "labels_nodes prog nx Skip" by(cases n) auto from `labels_nodes prog nx Skip` have "prog \<turnstile> nx -\<Up>id\<rightarrow> (_Exit_)" by(rule final_edge) then obtain a where "valid_edge prog a" and "sourcenode a = nx" and "kind a = \<Up>id" and "targetnode a = (_Exit_)" by(auto simp:valid_edge_def) with `labels_nodes prog nx Skip` show "\<exists>a. lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_) a \<and> src a = n \<and> trg a = LDCFG_node.Node (_Exit_) \<and> knd a = \<Up>id" by(rule_tac x="(Node nx,\<Up>id,Node (_Exit_))" in exI) (auto intro!:lve_edge simp:knd_def valid_edge_def) qed qed subsection {* Semantic Non-Interference for Weak Control Dependence *} lemmas WCDNonInterferenceGraph = lift_PDG_weak_backward_slice[OF WWeakControlDependence.PDG_wcd WhileStrongPostdomination_aux _ HighLowDistinct HighLowUNIV] lemma WCDNonInterference: "NonInterferenceIntra src trg knd (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewEntry (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) id (PDG.PDG_BS src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) (StrongPostdomination.weak_control_dependence src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewExit)) reds (labels_LDCFG_nodes prog) NewExit H L (LDCFG_node.Node (_Entry_)) (LDCFG_node.Node (_Exit_)) final" proof - from inner_node_exists obtain n where "CFGExit.inner_node sourcenode targetnode (valid_edge prog) (_Entry_) (_Exit_) n" by blast then interpret NonInterferenceIntraGraph src trg knd "lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)" NewEntry "lift_Def (Defs prog) (_Entry_) (_Exit_) H L" "lift_Use (Uses prog) (_Entry_) (_Exit_) H L" id "PDG.PDG_BS src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) (StrongPostdomination.weak_control_dependence src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewExit)" NewExit H L "LDCFG_node.Node (_Entry_)" "LDCFG_node.Node (_Exit_)" by(fastforce intro:WCDNonInterferenceGraph) interpret BackwardSlice_wf src trg knd "lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)" NewEntry "lift_Def (Defs prog) (_Entry_) (_Exit_) H L" "lift_Use (Uses prog) (_Entry_) (_Exit_) H L" id "PDG.PDG_BS src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) (lift_Def (Defs prog) (_Entry_) (_Exit_) H L) (lift_Use (Uses prog) (_Entry_) (_Exit_) H L) (StrongPostdomination.weak_control_dependence src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) NewExit)" reds "labels_LDCFG_nodes prog" proof(unfold_locales) fix n c s c' s' assume "labels_LDCFG_nodes prog n c" and "\<langle>c,s\<rangle> \<rightarrow>* \<langle>c',s'\<rangle>" thus "\<exists>n' as. CFG.path src trg (lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_)) n as n' \<and> transfers (CFG.kinds knd as) s = s' \<and> preds (CFG.kinds knd as) s \<and> labels_LDCFG_nodes prog n' c'" by(rule lifted_CFG_fund_prop) qed show ?thesis proof(unfold_locales) fix c n assume "final c" and "labels_LDCFG_nodes prog n c" from `final c` have [simp]:"c = Skip" by(cases c) auto from `labels_LDCFG_nodes prog n c` obtain nx where [simp]:"n = Node nx" and "labels_nodes prog nx Skip" by(cases n) auto from `labels_nodes prog nx Skip` have "prog \<turnstile> nx -\<Up>id\<rightarrow> (_Exit_)" by(rule final_edge) then obtain a where "valid_edge prog a" and "sourcenode a = nx" and "kind a = \<Up>id" and "targetnode a = (_Exit_)" by(auto simp:valid_edge_def) with `labels_nodes prog nx Skip` show "\<exists>a. lift_valid_edge (valid_edge prog) sourcenode targetnode kind (_Entry_) (_Exit_) a \<and> src a = n \<and> trg a = LDCFG_node.Node (_Exit_) \<and> knd a = \<Up>id" by(rule_tac x="(Node nx,\<Up>id,Node (_Exit_))" in exI) (auto intro!:lve_edge simp:knd_def valid_edge_def) qed qed end end
module adapters_postgresql_multiple_databases_test using Test # @test using Octo.Adapters.SQLite # Repo Schema from SELECT FROM WHERE import SQLite # pathof(SQLite) dbfile = joinpath(dirname(pathof(SQLite)), "..", "test", "Chinook_Sqlite.sqlite") dbfile2 = joinpath(@__DIR__, "test.sqlite") cp(dbfile, dbfile2; force=true) chmod(dbfile2, 0o666) Repo.debug_sql() sqlite_connector = Repo.connect( adapter = Octo.Adapters.SQLite, dbfile = dbfile2, multiple = true, ) using Octo.Adapters.PostgreSQL # Repo Schema Raw include("options.jl") pg_connector = Repo.connect(; adapter = Octo.Adapters.PostgreSQL, multiple = true, Options.for_postgresql... ) struct Employee end Schema.model(Employee, table_name="Employee", primary_key="ID") for c in (sqlite_connector, pg_connector) Repo.execute([DROP TABLE IF EXISTS Employee], db=c) end Repo.execute(Raw(""" CREATE TABLE Employee ( ID INTEGER PRIMARY KEY, Name TEXT NOT NULL, Salary NUMERIC NOT NULL )"""), db=sqlite_connector) Repo.execute(Raw(""" CREATE TABLE Employee ( ID SERIAL, Name VARCHAR(255), Salary FLOAT(8), PRIMARY KEY (ID) )"""), db=pg_connector) result = Repo.insert!(Employee, (Name = "Jessica", Salary= 70000.50); db=sqlite_connector) @test keys(result) == (:id, :num_affected_rows) @test result.num_affected_rows == 1 result = Repo.insert!(Employee, (Name = "Jessica", Salary= 70000.50); db=pg_connector) @test keys(result) == (:id, :num_affected_rows) @test result.num_affected_rows == 1 Repo.query(Employee, db=sqlite_connector) Repo.query(Employee, db=pg_connector) Repo.disconnect(db=sqlite_connector) Repo.disconnect(db=pg_connector) end # module adapters_postgresql_multiple_databases_test
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro ! This file was ported from Lean 3 source module data.string.basic ! leanprover-community/mathlib commit d13b3a4a392ea7273dfa4727dbd1892e26cfd518 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Data.List.Lex import Mathbin.Data.Char /-! # Strings Supplementary theorems about the `string` type. -/ namespace String /-- `<` on string iterators. This coincides with `<` on strings as lists. -/ def ltb : Iterator → Iterator → Bool | s₁, s₂ => by cases s₂.has_next; · exact ff cases h₁ : s₁.has_next; · exact tt exact if s₁.curr = s₂.curr then have : s₁.next.2.length < s₁.2.length := match s₁, h₁ with | ⟨_, a :: l⟩, h => Nat.lt_succ_self _ ltb s₁.next s₂.next else s₁.curr < s₂.curr termination_by' ⟨_, measure_wf fun s => s.1.2.length⟩ #align string.ltb String.ltb instance hasLt' : LT String := ⟨fun s₁ s₂ => ltb s₁.mkIterator s₂.mkIterator⟩ #align string.has_lt' String.hasLt' instance decidableLt : @DecidableRel String (· < ·) := by infer_instance #align string.decidable_lt String.decidableLt -- short-circuit type class inference @[simp] theorem lt_iff_toList_lt : ∀ {s₁ s₂ : String}, s₁ < s₂ ↔ s₁.toList < s₂.toList | ⟨i₁⟩, ⟨i₂⟩ => by suffices ∀ {p₁ p₂ s₁ s₂}, ltb ⟨p₁, s₁⟩ ⟨p₂, s₂⟩ ↔ s₁ < s₂ from this intros induction' s₁ with a s₁ IH generalizing p₁ p₂ s₂ <;> cases' s₂ with b s₂ <;> rw [ltb] <;> simp [iterator.has_next] · rfl · exact iff_of_true rfl List.Lex.nil · exact iff_of_false Bool.false_ne_true (not_lt_of_lt List.Lex.nil) · dsimp [iterator.has_next, iterator.curr, iterator.next] split_ifs · subst b exact IH.trans list.lex.cons_iff.symm · simp refine' ⟨List.Lex.rel, fun e => _⟩ cases e · cases h rfl assumption #align string.lt_iff_to_list_lt String.lt_iff_toList_lt instance hasLe : LE String := ⟨fun s₁ s₂ => ¬s₂ < s₁⟩ #align string.has_le String.hasLe instance decidableLe : @DecidableRel String (· ≤ ·) := by infer_instance #align string.decidable_le String.decidableLe -- short-circuit type class inference @[simp] theorem le_iff_toList_le {s₁ s₂ : String} : s₁ ≤ s₂ ↔ s₁.toList ≤ s₂.toList := (not_congr lt_iff_toList_lt).trans not_lt #align string.le_iff_to_list_le String.le_iff_toList_le theorem toList_inj : ∀ {s₁ s₂}, toList s₁ = toList s₂ ↔ s₁ = s₂ | ⟨s₁⟩, ⟨s₂⟩ => ⟨congr_arg _, congr_arg _⟩ #align string.to_list_inj String.toList_inj theorem nil_asString_eq_empty : [].asString = "" := rfl #align string.nil_as_string_eq_empty String.nil_asString_eq_empty @[simp] theorem toList_empty : "".toList = [] := rfl #align string.to_list_empty String.toList_empty theorem asString_inv_toList (s : String) : s.toList.asString = s := by cases s rfl #align string.as_string_inv_to_list String.asString_inv_toList @[simp] theorem toList_singleton (c : Char) : (String.singleton c).toList = [c] := rfl #align string.to_list_singleton String.toList_singleton theorem toList_nonempty : ∀ {s : String}, s ≠ String.empty → s.toList = s.headI :: (s.popn 1).toList | ⟨s⟩, h => by cases s <;> [cases h rfl, rfl] #align string.to_list_nonempty String.toList_nonempty @[simp] theorem head_empty : "".headI = default := rfl #align string.head_empty String.head_empty @[simp] theorem popn_empty {n : ℕ} : "".popn n = "" := by induction' n with n hn · rfl · rcases hs : "" with ⟨_ | ⟨hd, tl⟩⟩ · rw [hs] at hn conv_rhs => rw [← hn] simp only [popn, mk_iterator, iterator.nextn, iterator.next] · simpa only [← to_list_inj] using hs #align string.popn_empty String.popn_empty instance : LinearOrder String where lt := (· < ·) le := (· ≤ ·) decidableLt := by infer_instance decidableLe := String.decidableLe DecidableEq := by infer_instance le_refl a := le_iff_toList_le.2 le_rfl le_trans a b c := by simp only [le_iff_to_list_le] exact fun h₁ h₂ => h₁.trans h₂ le_total a b := by simp only [le_iff_to_list_le] exact le_total _ _ le_antisymm a b := by simp only [le_iff_to_list_le, ← to_list_inj] apply le_antisymm lt_iff_le_not_le a b := by simp only [le_iff_to_list_le, lt_iff_to_list_lt, lt_iff_le_not_le] end String open String theorem List.toList_inv_asString (l : List Char) : l.asString.toList = l := by cases hl : l.as_string exact StringImp.mk.inj hl.symm #align list.to_list_inv_as_string List.toList_inv_asString @[simp] theorem List.length_asString (l : List Char) : l.asString.length = l.length := rfl #align list.length_as_string List.length_asString @[simp] theorem List.asString_inj {l l' : List Char} : l.asString = l'.asString ↔ l = l' := ⟨fun h => by rw [← List.toList_inv_asString l, ← List.toList_inv_asString l', to_list_inj, h], fun h => h ▸ rfl⟩ #align list.as_string_inj List.asString_inj @[simp] theorem String.length_toList (s : String) : s.toList.length = s.length := by rw [← String.asString_inv_toList s, List.toList_inv_asString, List.length_asString] #align string.length_to_list String.length_toList theorem List.asString_eq {l : List Char} {s : String} : l.asString = s ↔ l = s.toList := by rw [← as_string_inv_to_list s, List.asString_inj, as_string_inv_to_list s] #align list.as_string_eq List.asString_eq
\cleardoublepage \selectlanguage{dutch} \normalsize \chapter{Dankwoord} \setlength{\epigraphrule}{0pt} \setlength{\epigraphwidth}{0.75\textwidth} \epigraph{\textit{In science, one should use all available resources to solve difficult problems. One of our most powerful resources is the insight of our colleagues.}}{Peter Agre} Aan iedereen die heeft meegeholpen, bedankt! Aan iedereen die niet heeft meegeholpen, ook bedankt! \vspace*{\fill} \begin{flushright} Ward Poelmans \\ Gent, \today \end{flushright} \vspace*{\fill} \selectlanguage{english} % vim: spell spelllang=nl syntax=tex tw=140
import cv2 import numpy as np from typing import Dict, Tuple class SemanticSegmentationVisualizer: def __init__( self, label_dict: Dict[int, str], color_dict: Dict[int, Tuple[int, int, int]], transpose_to_numpy: bool = True, wait_time: int = 1): """ :param label_dict: [id, class_name] :param color_dict: [id, bgr] :param transpose_to_numpy: torch or numpy :param wait_time: """ self._label_dict = label_dict self._color_dict = color_dict self._transpose_to_numpy = transpose_to_numpy self._wait_time = wait_time def __call__(self, inputs: np.ndarray, preds: np.ndarray, teachers: np.ndarray): """ :param inputs: [batch, channel, height, width] :param preds: :param teachers: :return: """ print(self._encode_label(preds[0])) def _encode_label(self, labelmap, mode='RGB'): labelmap = labelmap.astype('int') labelmap_rgb = np.zeros((labelmap.shape[0], labelmap.shape[1], 3), dtype=np.uint8) for label in self._unique(labelmap): if label < 0: continue labelmap_rgb += (labelmap == label)[:, :, np.newaxis] * \ np.tile(self._color_dict[label], (labelmap.shape[0], labelmap.shape[1], 1)) if mode == 'BGR': return labelmap_rgb[:, :, ::-1] else: return labelmap_rgb @staticmethod def _unique(ar, return_index=False, return_inverse=False, return_counts=False): ar = np.asanyarray(ar).flatten() optional_indices = return_index or return_inverse optional_returns = optional_indices or return_counts if ar.size == 0: if not optional_returns: ret = ar else: ret = (ar,) if return_index: ret += (np.empty(0, np.bool),) if return_inverse: ret += (np.empty(0, np.bool),) if return_counts: ret += (np.empty(0, np.intp),) return ret if optional_indices: perm = ar.argsort(kind='mergesort' if return_index else 'quicksort') aux = ar[perm] else: ar.sort() aux = ar flag = np.concatenate(([True], aux[1:] != aux[:-1])) if not optional_returns: ret = aux[flag] else: ret = (aux[flag],) if return_index: ret += (perm[flag],) if return_inverse: iflag = np.cumsum(flag) - 1 inv_idx = np.empty(ar.shape, dtype=np.intp) inv_idx[perm] = iflag ret += (inv_idx,) if return_counts: idx = np.concatenate(np.nonzero(flag) + ([ar.size],)) ret += (np.diff(idx),) return ret
[GOAL] μ : Measure ℝ inst✝ : IsProbabilityMeasure μ x : ℝ ⊢ ENNReal.ofReal (↑(cdf μ) x) = ↑↑μ (Iic x) [PROOFSTEP] have h := lintegral_condCdf ((Measure.dirac Unit.unit).prod μ) x [GOAL] μ : Measure ℝ inst✝ : IsProbabilityMeasure μ x : ℝ h : ∫⁻ (a : Unit), ENNReal.ofReal (↑(condCdf (Measure.prod (Measure.dirac ()) μ) a) x) ∂Measure.fst (Measure.prod (Measure.dirac ()) μ) = ↑↑(Measure.prod (Measure.dirac ()) μ) (univ ×ˢ Iic x) ⊢ ENNReal.ofReal (↑(cdf μ) x) = ↑↑μ (Iic x) [PROOFSTEP] simpa only [MeasureTheory.Measure.fst_prod, Measure.prod_prod, measure_univ, one_mul, lintegral_dirac] using h [GOAL] μ : Measure ℝ inst✝ : IsProbabilityMeasure μ x : ℝ ⊢ ↑(cdf μ) x = ENNReal.toReal (↑↑μ (Iic x)) [PROOFSTEP] rw [← ofReal_cdf μ x, ENNReal.toReal_ofReal (cdf_nonneg μ x)] [GOAL] μ : Measure ℝ ⊢ IsProbabilityMeasure (StieltjesFunction.measure (cdf μ)) [PROOFSTEP] constructor [GOAL] case measure_univ μ : Measure ℝ ⊢ ↑↑(StieltjesFunction.measure (cdf μ)) univ = 1 [PROOFSTEP] simp only [StieltjesFunction.measure_univ _ (tendsto_cdf_atBot μ) (tendsto_cdf_atTop μ), sub_zero, ENNReal.ofReal_one] [GOAL] μ : Measure ℝ inst✝ : IsProbabilityMeasure μ ⊢ StieltjesFunction.measure (cdf μ) = μ [PROOFSTEP] refine Measure.ext_of_Iic (cdf μ).measure μ (fun a ↦ ?_) [GOAL] μ : Measure ℝ inst✝ : IsProbabilityMeasure μ a : ℝ ⊢ ↑↑(StieltjesFunction.measure (cdf μ)) (Iic a) = ↑↑μ (Iic a) [PROOFSTEP] rw [StieltjesFunction.measure_Iic _ (tendsto_cdf_atBot μ), sub_zero, ofReal_cdf] [GOAL] f : StieltjesFunction hf0 : Tendsto (↑f) atBot (𝓝 0) hf1 : Tendsto (↑f) atTop (𝓝 1) ⊢ cdf (StieltjesFunction.measure f) = f [PROOFSTEP] refine (cdf f.measure).eq_of_measure_of_tendsto_atBot f ?_ (tendsto_cdf_atBot _) hf0 [GOAL] f : StieltjesFunction hf0 : Tendsto (↑f) atBot (𝓝 0) hf1 : Tendsto (↑f) atTop (𝓝 1) ⊢ StieltjesFunction.measure (cdf (StieltjesFunction.measure f)) = StieltjesFunction.measure f [PROOFSTEP] have h_prob : IsProbabilityMeasure f.measure := ⟨by rw [f.measure_univ hf0 hf1, sub_zero, ENNReal.ofReal_one]⟩ [GOAL] f : StieltjesFunction hf0 : Tendsto (↑f) atBot (𝓝 0) hf1 : Tendsto (↑f) atTop (𝓝 1) ⊢ ↑↑(StieltjesFunction.measure f) univ = 1 [PROOFSTEP] rw [f.measure_univ hf0 hf1, sub_zero, ENNReal.ofReal_one] [GOAL] f : StieltjesFunction hf0 : Tendsto (↑f) atBot (𝓝 0) hf1 : Tendsto (↑f) atTop (𝓝 1) h_prob : IsProbabilityMeasure (StieltjesFunction.measure f) ⊢ StieltjesFunction.measure (cdf (StieltjesFunction.measure f)) = StieltjesFunction.measure f [PROOFSTEP] exact measure_cdf f.measure [GOAL] μ ν : Measure ℝ inst✝¹ : IsProbabilityMeasure μ inst✝ : IsProbabilityMeasure ν h : cdf μ = cdf ν ⊢ μ = ν [PROOFSTEP] rw [← measure_cdf μ, ← measure_cdf ν, h] [GOAL] μ ν : Measure ℝ inst✝¹ : IsProbabilityMeasure μ inst✝ : IsProbabilityMeasure ν h : μ = ν ⊢ cdf μ = cdf ν [PROOFSTEP] rw [h]
[STATEMENT] lemma integral_sin_and_cos_Z [simp]: fixes m n::real assumes "m \<in> \<int>" "n \<in> \<int>" shows "integral\<^sup>L (lebesgue_on {-pi..pi}) (\<lambda>x. cos(m * x) * cos(n * x)) = (if \<bar>m\<bar> = \<bar>n\<bar> then if n = 0 then 2 * pi else pi else 0)" "integral\<^sup>L (lebesgue_on {-pi..pi}) (\<lambda>x. cos(m * x) * sin(n * x)) = 0" "integral\<^sup>L (lebesgue_on {-pi..pi}) (\<lambda>x. sin(m * x) * cos(n * x)) = 0" "\<bar>integral\<^sup>L (lebesgue_on {-pi..pi}) (\<lambda>x. sin (m * x) * sin (n * x))\<bar> = (if \<bar>m\<bar> = \<bar>n\<bar> \<and> n \<noteq> 0 then pi else 0)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (LINT x|lebesgue_on {- pi..pi}. cos (m * x) * cos (n * x) = (if \<bar>m\<bar> = \<bar>n\<bar> then if n = 0 then 2 * pi else pi else 0) &&& LINT x|lebesgue_on {- pi..pi}. cos (m * x) * sin (n * x) = 0) &&& LINT x|lebesgue_on {- pi..pi}. sin (m * x) * cos (n * x) = 0 &&& \<bar>LINT x|lebesgue_on {- pi..pi}. sin (m * x) * sin (n * x)\<bar> = (if \<bar>m\<bar> = \<bar>n\<bar> \<and> n \<noteq> 0 then pi else 0) [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: m \<in> \<int> n \<in> \<int> goal (1 subgoal): 1. (LINT x|lebesgue_on {- pi..pi}. cos (m * x) * cos (n * x) = (if \<bar>m\<bar> = \<bar>n\<bar> then if n = 0 then 2 * pi else pi else 0) &&& LINT x|lebesgue_on {- pi..pi}. cos (m * x) * sin (n * x) = 0) &&& LINT x|lebesgue_on {- pi..pi}. sin (m * x) * cos (n * x) = 0 &&& \<bar>LINT x|lebesgue_on {- pi..pi}. sin (m * x) * sin (n * x)\<bar> = (if \<bar>m\<bar> = \<bar>n\<bar> \<and> n \<noteq> 0 then pi else 0) [PROOF STEP] unfolding Ints_def [PROOF STATE] proof (prove) using this: m \<in> range real_of_int n \<in> range real_of_int goal (1 subgoal): 1. (LINT x|lebesgue_on {- pi..pi}. cos (m * x) * cos (n * x) = (if \<bar>m\<bar> = \<bar>n\<bar> then if n = 0 then 2 * pi else pi else 0) &&& LINT x|lebesgue_on {- pi..pi}. cos (m * x) * sin (n * x) = 0) &&& LINT x|lebesgue_on {- pi..pi}. sin (m * x) * cos (n * x) = 0 &&& \<bar>LINT x|lebesgue_on {- pi..pi}. sin (m * x) * sin (n * x)\<bar> = (if \<bar>m\<bar> = \<bar>n\<bar> \<and> n \<noteq> 0 then pi else 0) [PROOF STEP] apply safe [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x xa. \<lbrakk>x \<in> UNIV; m = real_of_int x; xa \<in> UNIV; n = real_of_int xa\<rbrakk> \<Longrightarrow> LINT xb|lebesgue_on {- pi..pi}. cos (real_of_int x * xb) * cos (real_of_int xa * xb) = (if \<bar>real_of_int x\<bar> = \<bar>real_of_int xa\<bar> then if real_of_int xa = 0 then 2 * pi else pi else 0) 2. \<And>x xa. \<lbrakk>x \<in> UNIV; m = real_of_int x; xa \<in> UNIV; n = real_of_int xa\<rbrakk> \<Longrightarrow> LINT xb|lebesgue_on {- pi..pi}. cos (real_of_int x * xb) * sin (real_of_int xa * xb) = 0 3. \<And>x xa. \<lbrakk>x \<in> UNIV; m = real_of_int x; xa \<in> UNIV; n = real_of_int xa\<rbrakk> \<Longrightarrow> LINT xb|lebesgue_on {- pi..pi}. sin (real_of_int x * xb) * cos (real_of_int xa * xb) = 0 4. \<And>x xa. \<lbrakk>x \<in> UNIV; m = real_of_int x; xa \<in> UNIV; n = real_of_int xa\<rbrakk> \<Longrightarrow> \<bar>LINT xb|lebesgue_on {- pi..pi}. sin (real_of_int x * xb) * sin (real_of_int xa * xb)\<bar> = (if \<bar>real_of_int x\<bar> = \<bar>real_of_int xa\<bar> \<and> real_of_int xa \<noteq> 0 then pi else 0) [PROOF STEP] unfolding integral_sin_and_cos [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>x xa. \<lbrakk>x \<in> UNIV; m = real_of_int x; xa \<in> UNIV; n = real_of_int xa\<rbrakk> \<Longrightarrow> (if \<bar>x\<bar> = \<bar>xa\<bar> then if xa = 0 then 2 * pi else pi else 0) = (if \<bar>real_of_int x\<bar> = \<bar>real_of_int xa\<bar> then if real_of_int xa = 0 then 2 * pi else pi else 0) 2. \<And>x xa. \<lbrakk>x \<in> UNIV; m = real_of_int x; xa \<in> UNIV; n = real_of_int xa\<rbrakk> \<Longrightarrow> 0 = 0 3. \<And>x xa. \<lbrakk>x \<in> UNIV; m = real_of_int x; xa \<in> UNIV; n = real_of_int xa\<rbrakk> \<Longrightarrow> 0 = 0 4. \<And>x xa. \<lbrakk>x \<in> UNIV; m = real_of_int x; xa \<in> UNIV; n = real_of_int xa\<rbrakk> \<Longrightarrow> (if \<bar>x\<bar> = \<bar>xa\<bar> \<and> xa \<noteq> 0 then pi else 0) = (if \<bar>real_of_int x\<bar> = \<bar>real_of_int xa\<bar> \<and> real_of_int xa \<noteq> 0 then pi else 0) [PROOF STEP] apply auto [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
State Before: x : ℂ hx : cos x = 0 ⊢ Tendsto (fun x => ↑abs (tan x)) (𝓝[{x}ᶜ] x) atTop State After: x : ℂ hx : cos x = 0 ⊢ Tendsto (fun x => ‖sin x‖ / ‖cos x‖) (𝓝[{x}ᶜ] x) atTop Tactic: simp only [tan_eq_sin_div_cos, ← norm_eq_abs, norm_div] State Before: x : ℂ hx : cos x = 0 ⊢ Tendsto (fun x => ‖sin x‖ / ‖cos x‖) (𝓝[{x}ᶜ] x) atTop State After: x : ℂ hx : cos x = 0 A : sin x ≠ 0 ⊢ Tendsto (fun x => ‖sin x‖ / ‖cos x‖) (𝓝[{x}ᶜ] x) atTop Tactic: have A : sin x ≠ 0 := fun h => by simpa [*, sq] using sin_sq_add_cos_sq x State Before: x : ℂ hx : cos x = 0 A : sin x ≠ 0 ⊢ Tendsto (fun x => ‖sin x‖ / ‖cos x‖) (𝓝[{x}ᶜ] x) atTop State After: x : ℂ hx : cos x = 0 A : sin x ≠ 0 B : Tendsto cos (𝓝[{x}ᶜ] x) (𝓝[{0}ᶜ] 0) ⊢ Tendsto (fun x => ‖sin x‖ / ‖cos x‖) (𝓝[{x}ᶜ] x) atTop Tactic: have B : Tendsto cos (𝓝[≠] x) (𝓝[≠] 0) := hx ▸ (hasDerivAt_cos x).tendsto_punctured_nhds (neg_ne_zero.2 A) State Before: x : ℂ hx : cos x = 0 A : sin x ≠ 0 B : Tendsto cos (𝓝[{x}ᶜ] x) (𝓝[{0}ᶜ] 0) ⊢ Tendsto (fun x => ‖sin x‖ / ‖cos x‖) (𝓝[{x}ᶜ] x) atTop State After: no goals Tactic: exact continuous_sin.continuousWithinAt.norm.mul_atTop (norm_pos_iff.2 A) (tendsto_norm_nhdsWithin_zero.comp B).inv_tendsto_zero State Before: x : ℂ hx : cos x = 0 h : sin x = 0 ⊢ False State After: no goals Tactic: simpa [*, sq] using sin_sq_add_cos_sq x
(* This program is free software; you can redistribute it and/or *) (* modify it under the terms of the GNU Lesser General Public License *) (* as published by the Free Software Foundation; either version 2.1 *) (* of the License, or (at your option) any later version. *) (* *) (* This 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 Lesser General Public *) (* License along with this program; if not, write to the Free *) (* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *) (* 02110-1301 USA *) (* Contribution to the Coq Library V6.3 (July 1999) *) (****************************************************************************) (* The Calculus of Inductive Constructions *) (* *) (* Projet Coq *) (* *) (* INRIA ENS-CNRS *) (* Rocquencourt Lyon *) (* *) (* Coq V5.10 *) (* July 1st 1995 *) (* *) (****************************************************************************) (****************************************************************) (* Proof of a multiplier circuit *) (* C. Paulin-Mohring, June 95 *) (****************************************************************) (* Circ.v *) (* Representation of Circuits *) (****************************************************************) Require Import GFP. Require Import Streams. Section Circuits. Variable TI TR TO : Set. Variable output : TI -> TR -> TO. Variable update : TI -> TR -> TR. Definition CIRC (ri : TR) (si : Str TI) : Str TO := STRCOIT _ _ (fun x : Str TI * TR => let (s, r) return (TO * (Str TI * TR)) := x in (output (HD _ s) r, (TL _ s, update (HD _ s) r))) (si, ri). Let Circ := CIRC. Theorem Hd_Circ : forall (r : TR) (si : Str TI), HD _ (Circ r si) = output (HD _ si) r. trivial. Qed. Theorem Tl_Circ : forall (r : TR) (si : Str TI), TL _ (Circ r si) = Circ (update (HD _ si) r) (TL _ si). trivial. Qed. Definition Reg : Str TI * TR -> TR. simple destruct 1; trivial. Defined. Definition Input : Str TI * TR -> Str TI. simple destruct 1; trivial. Defined. Section CircProof. Variable i0 : Str TI. Variable r0 : TR. Variable P : nat -> TO -> Prop. Variable inv : nat -> TR -> Prop. Hypothesis inv_init : inv 0 r0. Hint Resolve inv_init. Let inv_aux (n : nat) (s : Str TO) : Prop := exists r : TR, inv n r /\ s = Circ r (NTHTL _ i0 n). Remark inv_aux_init : inv_aux 0 (Circ r0 i0). exists r0; auto. Qed. Hint Resolve inv_aux_init. Hypothesis inv_stable : forall (n : nat) (r : TR), inv n r -> P n (output (NTH _ i0 n) r) /\ inv (S n) (update (NTH _ i0 n) r). Remark inv_aux_stable : forall (n : nat) (s : Str TO), inv_aux n s -> P n (HD _ s) /\ inv_aux (S n) (TL _ s). simple induction 1; simple induction 1; intros. rewrite H2; rewrite Tl_Circ; rewrite Hd_Circ. elim (inv_stable n x); intros; trivial. split; trivial. exists (update (NTH _ i0 n) x); auto. Qed. Hint Resolve inv_aux_stable. Theorem Circ_property : forall n : nat, P n (NTH _ (Circ r0 i0) n). intro; apply All_Q_Nth with (Inv := inv_aux); auto. Qed. End CircProof. End Circuits. Notation Circ := (CIRC _ _ _) (only parsing). (* <Warning> : Syntax is discontinued *)
/- Copyright (c) 2022 Alex J. Best. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best -/ import Lean.Parser.Term import Lean.Parser.Do import Lean.Elab.Command import Mathlib.Data.KVMap /-! # The `unset_option` command This file defines an `unset_option` user command, which unsets user configurable options. For example inputing `set_option blah 7` and then `unset_option blah` returns the user to the default state before any `set_option` command is called. This is helpful when the user does not know the default value of the option or it is cleaner not to write it explicitly, or for some options where the default behaviour is different from any user set value. -/ namespace Lean.Elab variable [Monad m] [MonadOptions m] [MonadExceptOf Exception m] [MonadRef m] variable [AddErrorMessageContext m] [MonadLiftT (EIO Exception) m] [MonadInfoTree m] /-- unset the option specified by id -/ def elabUnsetOption (id : Syntax) : m Options := do -- We include the first argument (the keyword) for position information in case `id` is `missing`. addCompletionInfo <| CompletionInfo.option (← getRef) unsetOption id.getId.eraseMacroScopes where /-- unset the given option name -/ unsetOption (optionName : Name) : m Options := return (← getOptions).erase optionName namespace Command /-- Unset a user option -/ elab (name := unsetOption) "unset_option " opt:ident : command => do let options ← Elab.elabUnsetOption opt modify fun s ↦ { s with maxRecDepth := maxRecDepth.get options } modifyScope fun scope ↦ { scope with opts := options } end Command end Lean.Elab
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import algebra.group.with_one import algebra.group.type_tags import algebra.group.prod import algebra.order.monoid_lemmas import order.bounded_order import order.min_max import order.hom.basic /-! # Ordered monoids This file develops the basics of ordered monoids. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ set_option old_structure_cmd true open function universe u variable {α : Type u} /-- An ordered commutative monoid is a commutative monoid with a partial order such that `a ≤ b → c * a ≤ c * b` (multiplication is monotone) -/ @[protect_proj, ancestor comm_monoid partial_order] class ordered_comm_monoid (α : Type*) extends comm_monoid α, partial_order α := (mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b) /-- An ordered (additive) commutative monoid is a commutative monoid with a partial order such that `a ≤ b → c + a ≤ c + b` (addition is monotone) -/ @[protect_proj, ancestor add_comm_monoid partial_order] class ordered_add_comm_monoid (α : Type*) extends add_comm_monoid α, partial_order α := (add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) attribute [to_additive] ordered_comm_monoid section ordered_instances @[to_additive] instance ordered_comm_monoid.to_covariant_class_left (M : Type*) [ordered_comm_monoid M] : covariant_class M M (*) (≤) := { elim := λ a b c bc, ordered_comm_monoid.mul_le_mul_left _ _ bc a } /- This instance can be proven with `by apply_instance`. However, `with_bot ℕ` does not pick up a `covariant_class M M (function.swap (*)) (≤)` instance without it (see PR #7940). -/ @[to_additive] instance ordered_comm_monoid.to_covariant_class_right (M : Type*) [ordered_comm_monoid M] : covariant_class M M (swap (*)) (≤) := covariant_swap_mul_le_of_covariant_mul_le M /- This is not an instance, to avoid creating a loop in the type-class system: in a `left_cancel_semigroup` with a `partial_order`, assuming `covariant_class M M (*) (≤)` implies `covariant_class M M (*) (<)` . -/ @[to_additive] lemma has_mul.to_covariant_class_left (M : Type*) [has_mul M] [linear_order M] [covariant_class M M (*) (<)] : covariant_class M M (*) (≤) := { elim := λ a b c bc, by { rcases eq_or_lt_of_le bc with rfl | bc, { exact rfl.le }, { exact (mul_lt_mul_left' bc a).le } } } /- This is not an instance, to avoid creating a loop in the type-class system: in a `right_cancel_semigroup` with a `partial_order`, assuming `covariant_class M M (swap (*)) (<)` implies `covariant_class M M (swap (*)) (≤)` . -/ @[to_additive] lemma has_mul.to_covariant_class_right (M : Type*) [has_mul M] [linear_order M] [covariant_class M M (swap (*)) (<)] : covariant_class M M (swap (*)) (≤) := { elim := λ a b c bc, by { rcases eq_or_lt_of_le bc with rfl | bc, { exact rfl.le }, { exact (mul_lt_mul_right' bc a).le } } } end ordered_instances /-- An `ordered_comm_monoid` with one-sided 'division' in the sense that if `a ≤ b`, there is some `c` for which `a * c = b`. This is a weaker version of the condition on canonical orderings defined by `canonically_ordered_monoid`. -/ class has_exists_mul_of_le (α : Type u) [ordered_comm_monoid α] : Prop := (exists_mul_of_le : ∀ {a b : α}, a ≤ b → ∃ (c : α), b = a * c) /-- An `ordered_add_comm_monoid` with one-sided 'subtraction' in the sense that if `a ≤ b`, then there is some `c` for which `a + c = b`. This is a weaker version of the condition on canonical orderings defined by `canonically_ordered_add_monoid`. -/ class has_exists_add_of_le (α : Type u) [ordered_add_comm_monoid α] : Prop := (exists_add_of_le : ∀ {a b : α}, a ≤ b → ∃ (c : α), b = a + c) attribute [to_additive] has_exists_mul_of_le export has_exists_mul_of_le (exists_mul_of_le) export has_exists_add_of_le (exists_add_of_le) /-- A linearly ordered additive commutative monoid. -/ @[protect_proj, ancestor linear_order ordered_add_comm_monoid] class linear_ordered_add_comm_monoid (α : Type*) extends linear_order α, ordered_add_comm_monoid α. /-- A linearly ordered commutative monoid. -/ @[protect_proj, ancestor linear_order ordered_comm_monoid, to_additive] class linear_ordered_comm_monoid (α : Type*) extends linear_order α, ordered_comm_monoid α. /-- A linearly ordered commutative monoid with a zero element. -/ class linear_ordered_comm_monoid_with_zero (α : Type*) extends linear_ordered_comm_monoid α, comm_monoid_with_zero α := (zero_le_one : (0 : α) ≤ 1) /-- A linearly ordered commutative monoid with an additively absorbing `⊤` element. Instances should include number systems with an infinite element adjoined.` -/ @[protect_proj, ancestor linear_ordered_add_comm_monoid has_top] class linear_ordered_add_comm_monoid_with_top (α : Type*) extends linear_ordered_add_comm_monoid α, has_top α := (le_top : ∀ x : α, x ≤ ⊤) (top_add' : ∀ x : α, ⊤ + x = ⊤) @[priority 100] -- see Note [lower instance priority] instance linear_ordered_add_comm_monoid_with_top.to_order_top (α : Type u) [h : linear_ordered_add_comm_monoid_with_top α] : order_top α := { ..h } section linear_ordered_add_comm_monoid_with_top variables [linear_ordered_add_comm_monoid_with_top α] {a b : α} @[simp] lemma top_add (a : α) : ⊤ + a = ⊤ := linear_ordered_add_comm_monoid_with_top.top_add' a @[simp] lemma add_top (a : α) : a + ⊤ = ⊤ := trans (add_comm _ _) (top_add _) end linear_ordered_add_comm_monoid_with_top /-- Pullback an `ordered_comm_monoid` under an injective map. See note [reducible non-instances]. -/ @[reducible, to_additive function.injective.ordered_add_comm_monoid "Pullback an `ordered_add_comm_monoid` under an injective map."] def function.injective.ordered_comm_monoid [ordered_comm_monoid α] {β : Type*} [has_one β] [has_mul β] (f : β → α) (hf : function.injective f) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) : ordered_comm_monoid β := { mul_le_mul_left := λ a b ab c, show f (c * a) ≤ f (c * b), by { rw [mul, mul], apply mul_le_mul_left', exact ab }, ..partial_order.lift f hf, ..hf.comm_monoid f one mul } /-- Pullback a `linear_ordered_comm_monoid` under an injective map. See note [reducible non-instances]. -/ @[reducible, to_additive function.injective.linear_ordered_add_comm_monoid "Pullback an `ordered_add_comm_monoid` under an injective map."] def function.injective.linear_ordered_comm_monoid [linear_ordered_comm_monoid α] {β : Type*} [has_one β] [has_mul β] (f : β → α) (hf : function.injective f) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) : linear_ordered_comm_monoid β := { .. hf.ordered_comm_monoid f one mul, .. linear_order.lift f hf } lemma bit0_pos [ordered_add_comm_monoid α] {a : α} (h : 0 < a) : 0 < bit0 a := add_pos h h namespace units @[to_additive] instance [monoid α] [preorder α] : preorder αˣ := preorder.lift (coe : αˣ → α) @[simp, norm_cast, to_additive] theorem coe_le_coe [monoid α] [preorder α] {a b : αˣ} : (a : α) ≤ b ↔ a ≤ b := iff.rfl @[simp, norm_cast, to_additive] theorem coe_lt_coe [monoid α] [preorder α] {a b : αˣ} : (a : α) < b ↔ a < b := iff.rfl @[to_additive] instance [monoid α] [partial_order α] : partial_order αˣ := partial_order.lift coe units.ext @[to_additive] instance [monoid α] [linear_order α] : linear_order αˣ := linear_order.lift coe units.ext @[simp, norm_cast, to_additive] theorem max_coe [monoid α] [linear_order α] {a b : αˣ} : (↑(max a b) : α) = max a b := by by_cases b ≤ a; simp [max_def, h] @[simp, norm_cast, to_additive] theorem min_coe [monoid α] [linear_order α] {a b : αˣ} : (↑(min a b) : α) = min a b := by by_cases a ≤ b; simp [min_def, h] end units namespace with_zero local attribute [semireducible] with_zero instance [preorder α] : preorder (with_zero α) := with_bot.preorder instance [partial_order α] : partial_order (with_zero α) := with_bot.partial_order instance [partial_order α] : order_bot (with_zero α) := with_bot.order_bot lemma zero_le [partial_order α] (a : with_zero α) : 0 ≤ a := order_bot.bot_le a lemma zero_lt_coe [preorder α] (a : α) : (0 : with_zero α) < a := with_bot.bot_lt_coe a @[simp, norm_cast] lemma coe_lt_coe [partial_order α] {a b : α} : (a : with_zero α) < b ↔ a < b := with_bot.coe_lt_coe @[simp, norm_cast] lemma coe_le_coe [partial_order α] {a b : α} : (a : with_zero α) ≤ b ↔ a ≤ b := with_bot.coe_le_coe instance [lattice α] : lattice (with_zero α) := with_bot.lattice instance [linear_order α] : linear_order (with_zero α) := with_bot.linear_order lemma mul_le_mul_left {α : Type u} [has_mul α] [preorder α] [covariant_class α α (*) (≤)] : ∀ (a b : with_zero α), a ≤ b → ∀ (c : with_zero α), c * a ≤ c * b := begin rintro (_ | a) (_ | b) h (_ | c); try { exact λ f hf, option.no_confusion hf }, { exact false.elim (not_lt_of_le h (with_zero.zero_lt_coe a))}, { simp_rw [some_eq_coe] at h ⊢, norm_cast at h ⊢, exact covariant_class.elim _ h } end lemma lt_of_mul_lt_mul_left {α : Type u} [has_mul α] [partial_order α] [contravariant_class α α (*) (<)] : ∀ (a b c : with_zero α), a * b < a * c → b < c := begin rintro (_ | a) (_ | b) (_ | c) h; try { exact false.elim (lt_irrefl none h) }, { exact with_zero.zero_lt_coe c }, { exact false.elim (not_le_of_lt h (with_zero.zero_le _)) }, { simp_rw [some_eq_coe] at h ⊢, norm_cast at h ⊢, apply lt_of_mul_lt_mul_left' h } end instance [ordered_comm_monoid α] : ordered_comm_monoid (with_zero α) := { mul_le_mul_left := with_zero.mul_le_mul_left, ..with_zero.comm_monoid_with_zero, ..with_zero.partial_order } /- Note 1 : the below is not an instance because it requires `zero_le`. It seems like a rather pathological definition because α already has a zero. Note 2 : there is no multiplicative analogue because it does not seem necessary. Mathematicians might be more likely to use the order-dual version, where all elements are ≤ 1 and then 1 is the top element. -/ /-- If `0` is the least element in `α`, then `with_zero α` is an `ordered_add_comm_monoid`. -/ def ordered_add_comm_monoid [ordered_add_comm_monoid α] (zero_le : ∀ a : α, 0 ≤ a) : ordered_add_comm_monoid (with_zero α) := begin suffices, refine { add_le_add_left := this, ..with_zero.partial_order, ..with_zero.add_comm_monoid, .. }, { intros a b h c ca h₂, cases b with b, { rw le_antisymm h bot_le at h₂, exact ⟨_, h₂, le_rfl⟩ }, cases a with a, { change c + 0 = some ca at h₂, simp at h₂, simp [h₂], exact ⟨_, rfl, by simpa using add_le_add_left (zero_le b) _⟩ }, { simp at h, cases c with c; change some _ = _ at h₂; simp [-add_comm] at h₂; subst ca; refine ⟨_, rfl, _⟩, { exact h }, { exact add_le_add_left h _ } } } end end with_zero namespace with_top section has_one variables [has_one α] @[to_additive] instance : has_one (with_top α) := ⟨(1 : α)⟩ @[simp, norm_cast, to_additive] lemma coe_one : ((1 : α) : with_top α) = 1 := rfl @[simp, norm_cast, to_additive] lemma coe_eq_one {a : α} : (a : with_top α) = 1 ↔ a = 1 := coe_eq_coe @[simp, norm_cast, to_additive] theorem one_eq_coe {a : α} : 1 = (a : with_top α) ↔ a = 1 := trans eq_comm coe_eq_one @[simp, to_additive] theorem top_ne_one : ⊤ ≠ (1 : with_top α) . @[simp, to_additive] theorem one_ne_top : (1 : with_top α) ≠ ⊤ . end has_one instance [has_add α] : has_add (with_top α) := ⟨λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a + b))⟩ @[norm_cast] lemma coe_add [has_add α] {a b : α} : ((a + b : α) : with_top α) = a + b := rfl @[norm_cast] lemma coe_bit0 [has_add α] {a : α} : ((bit0 a : α) : with_top α) = bit0 a := rfl @[norm_cast] lemma coe_bit1 [has_add α] [has_one α] {a : α} : ((bit1 a : α) : with_top α) = bit1 a := rfl @[simp] lemma add_top [has_add α] : ∀{a : with_top α}, a + ⊤ = ⊤ | none := rfl | (some a) := rfl @[simp] lemma top_add [has_add α] {a : with_top α} : ⊤ + a = ⊤ := rfl lemma add_eq_top [has_add α] {a b : with_top α} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by cases a; cases b; simp [none_eq_top, some_eq_coe, ←with_top.coe_add, ←with_zero.coe_add] lemma add_lt_top [has_add α] [partial_order α] {a b : with_top α} : a + b < ⊤ ↔ a < ⊤ ∧ b < ⊤ := by simp [lt_top_iff_ne_top, add_eq_top, not_or_distrib] lemma add_eq_coe [has_add α] : ∀ {a b : with_top α} {c : α}, a + b = c ↔ ∃ (a' b' : α), ↑a' = a ∧ ↑b' = b ∧ a' + b' = c | none b c := by simp [none_eq_top] | (some a) none c := by simp [none_eq_top] | (some a) (some b) c := by simp only [some_eq_coe, ← coe_add, coe_eq_coe, exists_and_distrib_left, exists_eq_left] @[simp] lemma add_coe_eq_top_iff [has_add α] {x : with_top α} {y : α} : x + y = ⊤ ↔ x = ⊤ := by { induction x using with_top.rec_top_coe; simp [← coe_add, -with_zero.coe_add] } @[simp] lemma coe_add_eq_top_iff [has_add α] {x : α} {y : with_top α} : ↑x + y = ⊤ ↔ y = ⊤ := by { induction y using with_top.rec_top_coe; simp [← coe_add, -with_zero.coe_add] } instance [add_semigroup α] : add_semigroup (with_top α) := { add_assoc := begin repeat { refine with_top.rec_top_coe _ _; try { intro }}; simp [←with_top.coe_add, add_assoc] end, ..with_top.has_add } instance [add_comm_semigroup α] : add_comm_semigroup (with_top α) := { add_comm := begin repeat { refine with_top.rec_top_coe _ _; try { intro }}; simp [←with_top.coe_add, add_comm] end, ..with_top.add_semigroup } instance [add_monoid α] : add_monoid (with_top α) := { zero_add := begin refine with_top.rec_top_coe _ _, { simpa }, { intro, rw [←with_top.coe_zero, ←with_top.coe_add, zero_add] } end, add_zero := begin refine with_top.rec_top_coe _ _, { simpa }, { intro, rw [←with_top.coe_zero, ←with_top.coe_add, add_zero] } end, ..with_top.has_zero, ..with_top.add_semigroup } instance [add_comm_monoid α] : add_comm_monoid (with_top α) := { ..with_top.add_monoid, ..with_top.add_comm_semigroup } instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_top α) := { add_le_add_left := begin rintros a b h (_|c), { simp [none_eq_top] }, rcases b with (_|b), { simp [none_eq_top] }, rcases le_coe_iff.1 h with ⟨a, rfl, h⟩, simp only [some_eq_coe, ← coe_add, coe_le_coe] at h ⊢, exact add_le_add_left h c end, ..with_top.partial_order, ..with_top.add_comm_monoid } instance [linear_ordered_add_comm_monoid α] : linear_ordered_add_comm_monoid_with_top (with_top α) := { top_add' := λ x, with_top.top_add, ..with_top.order_top, ..with_top.linear_order, ..with_top.ordered_add_comm_monoid, ..option.nontrivial } /-- Coercion from `α` to `with_top α` as an `add_monoid_hom`. -/ def coe_add_hom [add_monoid α] : α →+ with_top α := ⟨coe, rfl, λ _ _, rfl⟩ @[simp] lemma coe_coe_add_hom [add_monoid α] : ⇑(coe_add_hom : α →+ with_top α) = coe := rfl @[simp] lemma zero_lt_top [ordered_add_comm_monoid α] : (0 : with_top α) < ⊤ := coe_lt_top 0 @[simp, norm_cast] lemma zero_lt_coe [ordered_add_comm_monoid α] (a : α) : (0 : with_top α) < a ↔ 0 < a := coe_lt_coe end with_top namespace with_bot instance [has_zero α] : has_zero (with_bot α) := with_top.has_zero instance [has_one α] : has_one (with_bot α) := with_top.has_one instance [add_semigroup α] : add_semigroup (with_bot α) := with_top.add_semigroup instance [add_comm_semigroup α] : add_comm_semigroup (with_bot α) := with_top.add_comm_semigroup instance [add_monoid α] : add_monoid (with_bot α) := with_top.add_monoid instance [add_comm_monoid α] : add_comm_monoid (with_bot α) := with_top.add_comm_monoid instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_bot α) := begin suffices, refine { add_le_add_left := this, ..with_bot.partial_order, ..with_bot.add_comm_monoid, ..}, { intros a b h c ca h₂, cases c with c, {cases h₂}, cases a with a; cases h₂, cases b with b, {cases le_antisymm h bot_le}, simp at h, exact ⟨_, rfl, add_le_add_left h _⟩, } end instance [linear_ordered_add_comm_monoid α] : linear_ordered_add_comm_monoid (with_bot α) := { ..with_bot.linear_order, ..with_bot.ordered_add_comm_monoid } -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_zero [has_zero α] : ((0 : α) : with_bot α) = 0 := rfl -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_one [has_one α] : ((1 : α) : with_bot α) = 1 := rfl -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_eq_zero {α : Type*} [add_monoid α] {a : α} : (a : with_bot α) = 0 ↔ a = 0 := by norm_cast -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_add [add_semigroup α] (a b : α) : ((a + b : α) : with_bot α) = a + b := by norm_cast -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_bit0 [add_semigroup α] {a : α} : ((bit0 a : α) : with_bot α) = bit0 a := by norm_cast -- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast` lemma coe_bit1 [add_semigroup α] [has_one α] {a : α} : ((bit1 a : α) : with_bot α) = bit1 a := by norm_cast @[simp] lemma bot_add [add_semigroup α] (a : with_bot α) : ⊥ + a = ⊥ := rfl @[simp] lemma add_bot [add_semigroup α] (a : with_bot α) : a + ⊥ = ⊥ := by cases a; refl @[simp] lemma add_eq_bot [add_semigroup α] {m n : with_bot α} : m + n = ⊥ ↔ m = ⊥ ∨ n = ⊥ := with_top.add_eq_top end with_bot /-- A canonically ordered additive monoid is an ordered commutative additive monoid in which the ordering coincides with the subtractibility relation, which is to say, `a ≤ b` iff there exists `c` with `b = a + c`. This is satisfied by the natural numbers, for example, but not the integers or other nontrivial `ordered_add_comm_group`s. -/ @[protect_proj, ancestor ordered_add_comm_monoid has_bot] class canonically_ordered_add_monoid (α : Type*) extends ordered_add_comm_monoid α, has_bot α := (bot_le : ∀ x : α, ⊥ ≤ x) (le_iff_exists_add : ∀ a b : α, a ≤ b ↔ ∃ c, b = a + c) @[priority 100] -- see Note [lower instance priority] instance canonically_ordered_add_monoid.to_order_bot (α : Type u) [h : canonically_ordered_add_monoid α] : order_bot α := { ..h } /-- A canonically ordered monoid is an ordered commutative monoid in which the ordering coincides with the divisibility relation, which is to say, `a ≤ b` iff there exists `c` with `b = a * c`. Examples seem rare; it seems more likely that the `order_dual` of a naturally-occurring lattice satisfies this than the lattice itself (for example, dual of the lattice of ideals of a PID or Dedekind domain satisfy this; collections of all things ≤ 1 seem to be more natural that collections of all things ≥ 1). -/ @[protect_proj, ancestor ordered_comm_monoid has_bot, to_additive] class canonically_ordered_monoid (α : Type*) extends ordered_comm_monoid α, has_bot α := (bot_le : ∀ x : α, ⊥ ≤ x) (le_iff_exists_mul : ∀ a b : α, a ≤ b ↔ ∃ c, b = a * c) @[priority 100, to_additive] -- see Note [lower instance priority] instance canonically_ordered_monoid.to_order_bot (α : Type u) [h : canonically_ordered_monoid α] : order_bot α := { ..h } section canonically_ordered_monoid variables [canonically_ordered_monoid α] {a b c d : α} @[to_additive] lemma le_iff_exists_mul : a ≤ b ↔ ∃c, b = a * c := canonically_ordered_monoid.le_iff_exists_mul a b @[to_additive] lemma self_le_mul_right (a b : α) : a ≤ a * b := le_iff_exists_mul.mpr ⟨b, rfl⟩ @[to_additive] lemma self_le_mul_left (a b : α) : a ≤ b * a := by { rw [mul_comm], exact self_le_mul_right a b } @[simp, to_additive zero_le] lemma one_le (a : α) : 1 ≤ a := le_iff_exists_mul.mpr ⟨a, (one_mul _).symm⟩ @[simp, to_additive] lemma bot_eq_one : (⊥ : α) = 1 := le_antisymm bot_le (one_le ⊥) @[simp, to_additive] lemma mul_eq_one_iff : a * b = 1 ↔ a = 1 ∧ b = 1 := mul_eq_one_iff' (one_le _) (one_le _) @[simp, to_additive] lemma le_one_iff_eq_one : a ≤ 1 ↔ a = 1 := iff.intro (assume h, le_antisymm h (one_le a)) (assume h, h ▸ le_refl a) @[to_additive] lemma one_lt_iff_ne_one : 1 < a ↔ a ≠ 1 := iff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (one_le _) hne.symm @[to_additive] lemma exists_pos_mul_of_lt (h : a < b) : ∃ c > 1, a * c = b := begin obtain ⟨c, hc⟩ := le_iff_exists_mul.1 h.le, refine ⟨c, one_lt_iff_ne_one.2 _, hc.symm⟩, rintro rfl, simpa [hc, lt_irrefl] using h end @[to_additive] lemma le_mul_left (h : a ≤ c) : a ≤ b * c := calc a = 1 * a : by simp ... ≤ b * c : mul_le_mul' (one_le _) h @[to_additive] lemma le_mul_self : a ≤ b * a := le_mul_left (le_refl a) @[to_additive] lemma le_mul_right (h : a ≤ b) : a ≤ b * c := calc a = a * 1 : by simp ... ≤ b * c : mul_le_mul' h (one_le _) @[to_additive] lemma le_self_mul : a ≤ a * c := le_mul_right (le_refl a) @[to_additive] lemma lt_iff_exists_mul [covariant_class α α (*) (<)] : a < b ↔ ∃ c > 1, b = a * c := begin simp_rw [lt_iff_le_and_ne, and_comm, le_iff_exists_mul, ← exists_and_distrib_left, exists_prop], apply exists_congr, intro c, rw [and.congr_left_iff, gt_iff_lt], rintro rfl, split, { rw [one_lt_iff_ne_one], apply mt, rintro rfl, rw [mul_one] }, { rw [← (self_le_mul_right a c).lt_iff_ne], apply lt_mul_of_one_lt_right' } end -- This instance looks absurd: a monoid already has a zero /-- Adding a new zero to a canonically ordered additive monoid produces another one. -/ instance with_zero.canonically_ordered_add_monoid {α : Type u} [canonically_ordered_add_monoid α] : canonically_ordered_add_monoid (with_zero α) := { le_iff_exists_add := λ a b, begin apply with_zero.cases_on a, { exact iff_of_true bot_le ⟨b, (zero_add b).symm⟩ }, apply with_zero.cases_on b, { intro b', refine iff_of_false (mt (le_antisymm bot_le) (by simp)) (not_exists.mpr (λ c, _)), apply with_zero.cases_on c; simp [←with_zero.coe_add] }, { simp only [le_iff_exists_add, with_zero.coe_le_coe], intros, split; rintro ⟨c, h⟩, { exact ⟨c, congr_arg coe h⟩ }, { induction c using with_zero.cases_on, { refine ⟨0, _⟩, simpa using h }, { refine ⟨c, _⟩, simpa [←with_zero.coe_add] using h } } } end, .. with_zero.order_bot, .. with_zero.ordered_add_comm_monoid zero_le } instance with_top.canonically_ordered_add_monoid {α : Type u} [canonically_ordered_add_monoid α] : canonically_ordered_add_monoid (with_top α) := { le_iff_exists_add := assume a b, match a, b with | a, none := show a ≤ ⊤ ↔ ∃c, ⊤ = a + c, by simp; refine ⟨⊤, _⟩; cases a; refl | (some a), (some b) := show (a:with_top α) ≤ ↑b ↔ ∃c:with_top α, ↑b = ↑a + c, begin simp [canonically_ordered_add_monoid.le_iff_exists_add, -add_comm], split, { rintro ⟨c, rfl⟩, refine ⟨c, _⟩, norm_cast }, { exact assume h, match b, h with _, ⟨some c, rfl⟩ := ⟨_, rfl⟩ end } end | none, some b := show (⊤ : with_top α) ≤ b ↔ ∃c:with_top α, ↑b = ⊤ + c, by simp end, .. with_top.order_bot, .. with_top.ordered_add_comm_monoid } @[priority 100, to_additive] instance canonically_ordered_monoid.has_exists_mul_of_le (α : Type u) [canonically_ordered_monoid α] : has_exists_mul_of_le α := { exists_mul_of_le := λ a b hab, le_iff_exists_mul.mp hab } end canonically_ordered_monoid lemma pos_of_gt {M : Type*} [canonically_ordered_add_monoid M] {n m : M} (h : n < m) : 0 < m := lt_of_le_of_lt (zero_le _) h /-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid whose ordering is a linear order. -/ @[protect_proj, ancestor canonically_ordered_add_monoid linear_order] class canonically_linear_ordered_add_monoid (α : Type*) extends canonically_ordered_add_monoid α, linear_order α /-- A canonically linear-ordered monoid is a canonically ordered monoid whose ordering is a linear order. -/ @[protect_proj, ancestor canonically_ordered_monoid linear_order, to_additive] class canonically_linear_ordered_monoid (α : Type*) extends canonically_ordered_monoid α, linear_order α section canonically_linear_ordered_monoid variables [canonically_linear_ordered_monoid α] @[priority 100, to_additive] -- see Note [lower instance priority] instance canonically_linear_ordered_monoid.semilattice_sup : semilattice_sup α := { ..linear_order.to_lattice } instance with_top.canonically_linear_ordered_add_monoid (α : Type*) [canonically_linear_ordered_add_monoid α] : canonically_linear_ordered_add_monoid (with_top α) := { .. (infer_instance : canonically_ordered_add_monoid (with_top α)), .. (infer_instance : linear_order (with_top α)) } @[to_additive] lemma min_mul_distrib (a b c : α) : min a (b * c) = min a (min a b * min a c) := begin cases le_total a b with hb hb, { simp [hb, le_mul_right] }, { cases le_total a c with hc hc, { simp [hc, le_mul_left] }, { simp [hb, hc] } } end @[to_additive] lemma min_mul_distrib' (a b c : α) : min (a * b) c = min (min a c * min b c) c := by simpa [min_comm _ c] using min_mul_distrib c a b @[simp, to_additive] lemma one_min (a : α) : min 1 a = 1 := min_eq_left (one_le a) @[simp, to_additive] lemma min_one (a : α) : min a 1 = 1 := min_eq_right (one_le a) end canonically_linear_ordered_monoid /-- An ordered cancellative additive commutative monoid is an additive commutative monoid with a partial order, in which addition is cancellative and monotone. -/ @[protect_proj, ancestor add_cancel_comm_monoid partial_order] class ordered_cancel_add_comm_monoid (α : Type u) extends add_cancel_comm_monoid α, partial_order α := (add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) (le_of_add_le_add_left : ∀ a b c : α, a + b ≤ a + c → b ≤ c) /-- An ordered cancellative commutative monoid is a commutative monoid with a partial order, in which multiplication is cancellative and monotone. -/ @[protect_proj, ancestor cancel_comm_monoid partial_order, to_additive] class ordered_cancel_comm_monoid (α : Type u) extends cancel_comm_monoid α, partial_order α := (mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b) (le_of_mul_le_mul_left : ∀ a b c : α, a * b ≤ a * c → b ≤ c) section ordered_cancel_comm_monoid variables [ordered_cancel_comm_monoid α] {a b c d : α} @[to_additive] lemma ordered_cancel_comm_monoid.lt_of_mul_lt_mul_left : ∀ a b c : α, a * b < a * c → b < c := λ a b c h, lt_of_le_not_le (ordered_cancel_comm_monoid.le_of_mul_le_mul_left a b c h.le) $ mt (λ h, ordered_cancel_comm_monoid.mul_le_mul_left _ _ h _) (not_le_of_gt h) @[to_additive] instance ordered_cancel_comm_monoid.to_contravariant_class_left (M : Type*) [ordered_cancel_comm_monoid M] : contravariant_class M M (*) (<) := { elim := λ a b c, ordered_cancel_comm_monoid.lt_of_mul_lt_mul_left _ _ _ } /- This instance can be proven with `by apply_instance`. However, by analogy with the instance `ordered_cancel_comm_monoid.to_covariant_class_right` above, I imagine that without this instance, some Type would not have a `contravariant_class M M (function.swap (*)) (<)` instance. -/ @[to_additive] instance ordered_cancel_comm_monoid.to_contravariant_class_right (M : Type*) [ordered_cancel_comm_monoid M] : contravariant_class M M (swap (*)) (<) := contravariant_swap_mul_lt_of_contravariant_mul_lt M @[priority 100, to_additive] -- see Note [lower instance priority] instance ordered_cancel_comm_monoid.to_ordered_comm_monoid : ordered_comm_monoid α := { ..‹ordered_cancel_comm_monoid α› } /-- Pullback an `ordered_cancel_comm_monoid` under an injective map. See note [reducible non-instances]. -/ @[reducible, to_additive function.injective.ordered_cancel_add_comm_monoid "Pullback an `ordered_cancel_add_comm_monoid` under an injective map."] def function.injective.ordered_cancel_comm_monoid {β : Type*} [has_one β] [has_mul β] (f : β → α) (hf : function.injective f) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) : ordered_cancel_comm_monoid β := { le_of_mul_le_mul_left := λ a b c (bc : f (a * b) ≤ f (a * c)), (mul_le_mul_iff_left (f a)).mp (by rwa [← mul, ← mul]), ..hf.left_cancel_semigroup f mul, ..hf.ordered_comm_monoid f one mul } end ordered_cancel_comm_monoid /-! Some lemmas about types that have an ordering and a binary operation, with no rules relating them. -/ @[to_additive] lemma fn_min_mul_fn_max {β} [linear_order α] [comm_semigroup β] (f : α → β) (n m : α) : f (min n m) * f (max n m) = f n * f m := by { cases le_total n m with h h; simp [h, mul_comm] } @[to_additive] lemma min_mul_max [linear_order α] [comm_semigroup α] (n m : α) : min n m * max n m = n * m := fn_min_mul_fn_max id n m /-- A linearly ordered cancellative additive commutative monoid is an additive commutative monoid with a decidable linear order in which addition is cancellative and monotone. -/ @[protect_proj, ancestor ordered_cancel_add_comm_monoid linear_ordered_add_comm_monoid] class linear_ordered_cancel_add_comm_monoid (α : Type u) extends ordered_cancel_add_comm_monoid α, linear_ordered_add_comm_monoid α /-- A linearly ordered cancellative commutative monoid is a commutative monoid with a linear order in which multiplication is cancellative and monotone. -/ @[protect_proj, ancestor ordered_cancel_comm_monoid linear_ordered_comm_monoid, to_additive] class linear_ordered_cancel_comm_monoid (α : Type u) extends ordered_cancel_comm_monoid α, linear_ordered_comm_monoid α section covariant_class_mul_le variables [linear_order α] section has_mul variable [has_mul α] section left variable [covariant_class α α (*) (≤)] @[to_additive] lemma min_mul_mul_left (a b c : α) : min (a * b) (a * c) = a * min b c := (monotone_id.const_mul' a).map_min.symm @[to_additive] lemma max_mul_mul_left (a b c : α) : max (a * b) (a * c) = a * max b c := (monotone_id.const_mul' a).map_max.symm end left section right variable [covariant_class α α (function.swap (*)) (≤)] @[to_additive] lemma min_mul_mul_right (a b c : α) : min (a * c) (b * c) = min a b * c := (monotone_id.mul_const' c).map_min.symm @[to_additive] lemma max_mul_mul_right (a b c : α) : max (a * c) (b * c) = max a b * c := (monotone_id.mul_const' c).map_max.symm end right end has_mul variable [monoid α] @[to_additive] lemma min_le_mul_of_one_le_right [covariant_class α α (*) (≤)] {a b : α} (hb : 1 ≤ b) : min a b ≤ a * b := min_le_iff.2 $ or.inl $ le_mul_of_one_le_right' hb @[to_additive] lemma min_le_mul_of_one_le_left [covariant_class α α (function.swap (*)) (≤)] {a b : α} (ha : 1 ≤ a) : min a b ≤ a * b := min_le_iff.2 $ or.inr $ le_mul_of_one_le_left' ha @[to_additive] lemma max_le_mul_of_one_le [covariant_class α α (*) (≤)] [covariant_class α α (function.swap (*)) (≤)] {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) : max a b ≤ a * b := max_le_iff.2 ⟨le_mul_of_one_le_right' hb, le_mul_of_one_le_left' ha⟩ end covariant_class_mul_le section linear_ordered_cancel_comm_monoid variables [linear_ordered_cancel_comm_monoid α] /-- Pullback a `linear_ordered_cancel_comm_monoid` under an injective map. See note [reducible non-instances]. -/ @[reducible, to_additive function.injective.linear_ordered_cancel_add_comm_monoid "Pullback a `linear_ordered_cancel_add_comm_monoid` under an injective map."] def function.injective.linear_ordered_cancel_comm_monoid {β : Type*} [has_one β] [has_mul β] (f : β → α) (hf : function.injective f) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) : linear_ordered_cancel_comm_monoid β := { ..hf.linear_ordered_comm_monoid f one mul, ..hf.ordered_cancel_comm_monoid f one mul } end linear_ordered_cancel_comm_monoid namespace order_dual @[to_additive] instance [h : has_mul α] : has_mul (order_dual α) := h @[to_additive] instance [h : has_one α] : has_one (order_dual α) := h @[to_additive] instance [h : monoid α] : monoid (order_dual α) := h @[to_additive] instance [h : comm_monoid α] : comm_monoid (order_dual α) := h @[to_additive] instance [h : cancel_comm_monoid α] : cancel_comm_monoid (order_dual α) := h @[to_additive] instance contravariant_class_mul_le [has_le α] [has_mul α] [c : contravariant_class α α (*) (≤)] : contravariant_class (order_dual α) (order_dual α) (*) (≤) := ⟨c.1.flip⟩ @[to_additive] instance covariant_class_mul_le [has_le α] [has_mul α] [c : covariant_class α α (*) (≤)] : covariant_class (order_dual α) (order_dual α) (*) (≤) := ⟨c.1.flip⟩ @[to_additive] instance contravariant_class_swap_mul_le [has_le α] [has_mul α] [c : contravariant_class α α (swap (*)) (≤)] : contravariant_class (order_dual α) (order_dual α) (swap (*)) (≤) := ⟨c.1.flip⟩ @[to_additive] instance covariant_class_swap_mul_le [has_le α] [has_mul α] [c : covariant_class α α (swap (*)) (≤)] : covariant_class (order_dual α) (order_dual α) (swap (*)) (≤) := ⟨c.1.flip⟩ @[to_additive] instance contravariant_class_mul_lt [has_lt α] [has_mul α] [c : contravariant_class α α (*) (<)] : contravariant_class (order_dual α) (order_dual α) (*) (<) := ⟨c.1.flip⟩ @[to_additive] instance covariant_class_mul_lt [has_lt α] [has_mul α] [c : covariant_class α α (*) (<)] : covariant_class (order_dual α) (order_dual α) (*) (<) := ⟨c.1.flip⟩ @[to_additive] instance contravariant_class_swap_mul_lt [has_lt α] [has_mul α] [c : contravariant_class α α (swap (*)) (<)] : contravariant_class (order_dual α) (order_dual α) (swap (*)) (<) := ⟨c.1.flip⟩ @[to_additive] instance covariant_class_swap_mul_lt [has_lt α] [has_mul α] [c : covariant_class α α (swap (*)) (<)] : covariant_class (order_dual α) (order_dual α) (swap (*)) (<) := ⟨c.1.flip⟩ @[to_additive] instance [ordered_comm_monoid α] : ordered_comm_monoid (order_dual α) := { mul_le_mul_left := λ a b h c, mul_le_mul_left' h c, .. order_dual.partial_order α, .. order_dual.comm_monoid } @[to_additive ordered_cancel_add_comm_monoid.to_contravariant_class] instance ordered_cancel_comm_monoid.to_contravariant_class [ordered_cancel_comm_monoid α] : contravariant_class (order_dual α) (order_dual α) has_mul.mul has_le.le := { elim := λ a b c bc, (ordered_cancel_comm_monoid.le_of_mul_le_mul_left a c b (dual_le.mp bc)) } @[to_additive] instance [ordered_cancel_comm_monoid α] : ordered_cancel_comm_monoid (order_dual α) := { le_of_mul_le_mul_left := λ a b c : α, le_of_mul_le_mul_left', .. order_dual.ordered_comm_monoid, .. order_dual.cancel_comm_monoid } @[to_additive] instance [linear_ordered_cancel_comm_monoid α] : linear_ordered_cancel_comm_monoid (order_dual α) := { .. order_dual.linear_order α, .. order_dual.ordered_cancel_comm_monoid } @[to_additive] instance [linear_ordered_comm_monoid α] : linear_ordered_comm_monoid (order_dual α) := { .. order_dual.linear_order α, .. order_dual.ordered_comm_monoid } end order_dual section linear_ordered_cancel_add_comm_monoid variables [linear_ordered_cancel_add_comm_monoid α] lemma lt_or_lt_of_add_lt_add {a b m n : α} (h : m + n < a + b) : m < a ∨ n < b := by { contrapose! h, exact add_le_add h.1 h.2 } end linear_ordered_cancel_add_comm_monoid section ordered_cancel_add_comm_monoid variable [ordered_cancel_add_comm_monoid α] namespace with_top lemma add_lt_add_iff_left {a b c : with_top α} (ha : a ≠ ⊤) : a + b < a + c ↔ b < c := begin lift a to α using ha, cases b; cases c, { simp [none_eq_top] }, { simp [some_eq_coe, none_eq_top, coe_lt_top] }, { simp [some_eq_coe, none_eq_top, ← coe_add, coe_lt_top] }, { simp [some_eq_coe, ← coe_add, coe_lt_coe] } end lemma add_lt_add_iff_right {a b c : with_top α} (ha : a ≠ ⊤) : (c + a < b + a ↔ c < b) := by simp only [← add_comm a, add_lt_add_iff_left ha] instance contravariant_class_add_lt : contravariant_class (with_top α) (with_top α) (+) (<) := begin refine ⟨λ a b c h, _⟩, cases a, { rw [none_eq_top, top_add, top_add] at h, exact (lt_irrefl ⊤ h).elim }, { exact (add_lt_add_iff_left coe_ne_top).1 h } end end with_top namespace with_bot lemma add_lt_add_iff_left {a b c : with_bot α} (ha : a ≠ ⊥) : a + b < a + c ↔ b < c := @with_top.add_lt_add_iff_left (order_dual α) _ a c b ha lemma add_lt_add_iff_right {a b c : with_bot α} (ha : a ≠ ⊥) : b + a < c + a ↔ b < c := @with_top.add_lt_add_iff_right (order_dual α) _ _ _ _ ha instance contravariant_class_add_lt : contravariant_class (with_bot α) (with_bot α) (+) (<) := @order_dual.contravariant_class_add_lt (with_top $ order_dual α) _ _ _ end with_bot end ordered_cancel_add_comm_monoid namespace prod variables {M N : Type*} @[to_additive] instance [ordered_cancel_comm_monoid M] [ordered_cancel_comm_monoid N] : ordered_cancel_comm_monoid (M × N) := { mul_le_mul_left := λ a b h c, ⟨mul_le_mul_left' h.1 _, mul_le_mul_left' h.2 _⟩, le_of_mul_le_mul_left := λ a b c h, ⟨le_of_mul_le_mul_left' h.1, le_of_mul_le_mul_left' h.2⟩, .. prod.cancel_comm_monoid, .. prod.partial_order M N } end prod section type_tags instance : Π [preorder α], preorder (multiplicative α) := id instance : Π [preorder α], preorder (additive α) := id instance : Π [partial_order α], partial_order (multiplicative α) := id instance : Π [partial_order α], partial_order (additive α) := id instance : Π [linear_order α], linear_order (multiplicative α) := id instance : Π [linear_order α], linear_order (additive α) := id instance [ordered_add_comm_monoid α] : ordered_comm_monoid (multiplicative α) := { mul_le_mul_left := @ordered_add_comm_monoid.add_le_add_left α _, ..multiplicative.partial_order, ..multiplicative.comm_monoid } instance [ordered_comm_monoid α] : ordered_add_comm_monoid (additive α) := { add_le_add_left := @ordered_comm_monoid.mul_le_mul_left α _, ..additive.partial_order, ..additive.add_comm_monoid } instance [ordered_cancel_add_comm_monoid α] : ordered_cancel_comm_monoid (multiplicative α) := { le_of_mul_le_mul_left := @ordered_cancel_add_comm_monoid.le_of_add_le_add_left α _, ..multiplicative.left_cancel_semigroup, ..multiplicative.ordered_comm_monoid } instance [ordered_cancel_comm_monoid α] : ordered_cancel_add_comm_monoid (additive α) := { le_of_add_le_add_left := @ordered_cancel_comm_monoid.le_of_mul_le_mul_left α _, ..additive.add_left_cancel_semigroup, ..additive.ordered_add_comm_monoid } instance [linear_ordered_add_comm_monoid α] : linear_ordered_comm_monoid (multiplicative α) := { ..multiplicative.linear_order, ..multiplicative.ordered_comm_monoid } instance [linear_ordered_comm_monoid α] : linear_ordered_add_comm_monoid (additive α) := { ..additive.linear_order, ..additive.ordered_add_comm_monoid } end type_tags /-- The order embedding sending `b` to `a * b`, for some fixed `a`. See also `order_iso.mul_left` when working in an ordered group. -/ @[to_additive "The order embedding sending `b` to `a + b`, for some fixed `a`. See also `order_iso.add_left` when working in an additive ordered group.", simps] def order_embedding.mul_left {α : Type*} [has_mul α] [linear_order α] [covariant_class α α (*) (<)] (m : α) : α ↪o α := order_embedding.of_strict_mono (λ n, m * n) (λ a b w, mul_lt_mul_left' w m) /-- The order embedding sending `b` to `b * a`, for some fixed `a`. See also `order_iso.mul_right` when working in an ordered group. -/ @[to_additive "The order embedding sending `b` to `b + a`, for some fixed `a`. See also `order_iso.add_right` when working in an additive ordered group.", simps] def order_embedding.mul_right {α : Type*} [has_mul α] [linear_order α] [covariant_class α α (swap (*)) (<)] (m : α) : α ↪o α := order_embedding.of_strict_mono (λ n, n * m) (λ a b w, mul_lt_mul_right' w m)
module Numeral.Natural.Prime.Proofs.Representation where import Lvl open import Data.Either as Either using () open import Data.Tuple as Tuple using () open import Functional open import Function.Equals open import Lang.Instance open import Logic.Predicate open import Logic.Propositional open import Numeral.CoordinateVector open import Numeral.Finite open import Numeral.Natural open import Numeral.Natural.Oper open import Numeral.Natural.Prime open import Numeral.Natural.Relation open import Numeral.Natural.Relation.Divisibility open import Numeral.Natural.Relation.Divisibility.Proofs open import Numeral.Natural.Relation.Divisibility.Proofs.Product open import Relator.Equals open import Relator.Equals.Proofs.Equiv open import Structure.Relator.Equivalence.Proofs open import Structure.Relator.Properties open import Structure.Setoid renaming (_≡_ to _≡ₛ_ ; _≢_ to _≢ₛ_) open import Structure.Setoid.Uniqueness open import Syntax.Transitivity open import Type open import Type.Dependent private variable a b : ℕ record PrimePowers(f : ℕ → ℕ) : Type{Lvl.𝟎} where constructor intro field positive-powers : Σ ℕ (n ↦ Vector(n)(ℕ)) zeroes-correctness : ∀{n} → Positive(f(n)) ↔ ∃(i ↦ (Σ.right positive-powers(i) ≡ n)) prime-correctness : ∀{i} → Prime(Σ.right positive-powers(i)) product : ℕ product = foldᵣ(_⋅_)(1) (map(n ↦ n ^ f(n)) (Σ.right positive-powers)) powers-is-positive : ∀{i} → Positive(f(Σ.right positive-powers(i))) powers-is-positive = [↔]-to-[←] zeroes-correctness ([∃]-intro _ ⦃ [≡]-intro ⦄) -- postulate power-divide-product : ∀{i} → (Σ.right positive-powers i ∣ product) {-power-divide-product {pp}{i = 𝟎} = divides-with-[⋅] {b = (PrimePowers.positive-powers pp 𝟎) ^ (PrimePowers.power pp (PrimePowers.positive-powers pp 𝟎))} {c = foldᵣ(_⋅_)(1) (tail(map(n ↦ n ^ PrimePowers.power pp(n)) (PrimePowers.positive-powers pp)))} ([∨]-introₗ (divides-withᵣ-[^] ⦃ PrimePowers.powers-is-positive pp ⦄ (reflexivity(_∣_)))) power-divide-product {pp}{i = 𝐒 i} = divides-with-[⋅] {b = (PrimePowers.positive-powers pp 𝟎) ^ (PrimePowers.power pp (PrimePowers.positive-powers pp 𝟎))} {c = foldᵣ(_⋅_)(1) (tail(map(n ↦ n ^ PrimePowers.power pp(n)) (PrimePowers.positive-powers pp)))} ([∨]-introᵣ {!!}) -} instance PrimePowers-equiv : Equiv(∃ PrimePowers) Equiv._≡_ PrimePowers-equiv = (_⊜_) on₂ [∃]-witness Equiv.equivalence PrimePowers-equiv = on₂-equivalence ⦃ Equiv.equivalence [⊜]-equiv ⦄ {- -- Each positive number have a corresponding finite multiset of prime numbers such that it is equal to the product of the numbers in the multiset. -- Examples: -- n = (p₁ ^ n₁) ⋅ (p₂ ^ n₂) ⋅ … ⋅ (pₖ ^ nₖ) -- Also called: -- • Fundamental theorem of arithmetic. -- • Canonical representation of positive integers by primes. -- • Unique prime factorization theorem. prime-representation : ∀{n} → ⦃ pos : Positive(n) ⦄ → ∃! ⦃ PrimePowers-equiv ⦄ (pp ↦ (n ≡ PrimePowers.product pp)) ∃.witness (Tuple.left prime-representation) = {!!} ∃.proof (Tuple.left prime-representation) = {!!} _⊜_.proof (Tuple.right (prime-representation {𝐒 n}) {pp1} {pp2} p1 p2) {p} = {!!} -} open import Logic.Classical open import Numeral.Natural.Decidable {- prime-representation : ∀{n} → ⦃ pos : Positive(n) ⦄ → ∃! ⦃ PrimePowers-equiv ⦄ (pp ↦ (n ≡ PrimePowers.product([∃]-proof pp))) prime-representation {𝐒 n} ⦃ pos ⦄ = [∧]-intro p1 (\{x}{y} → p2{x}{y}) where p1 : ∃(pp ↦ (𝐒(n) ≡ PrimePowers.product ([∃]-proof pp))) p2 : Unique(pp ↦ (𝐒(n) ≡ PrimePowers.product ([∃]-proof pp))) p2 {[∃]-intro x ⦃ ppx ⦄}{[∃]-intro y ⦃ ppy ⦄} px py with PrimePowers.positive-powers ppx | PrimePowers.positive-powers ppy p2 {[∃]-intro x ⦃ ppx ⦄} {[∃]-intro y ⦃ ppy ⦄} px py | intro 𝟎 b | intro 𝟎 d = intro {!!} p2 {[∃]-intro x ⦃ ppx ⦄} {[∃]-intro y ⦃ ppy ⦄} px py | intro 𝟎 b | intro (𝐒 c) d = {!!} p2 {[∃]-intro x ⦃ ppx ⦄} {[∃]-intro y ⦃ ppy ⦄} px py | intro (𝐒 a) b | intro 𝟎 d = {!!} p2 {[∃]-intro x ⦃ ppx ⦄} {[∃]-intro y ⦃ ppy ⦄} px py | intro (𝐒 a) b | intro (𝐒 c) d = {!!} -- let xy = symmetry(_≡_) px 🝖 py -- in intro \{p} → {!PrimePowers.power-divide-product ppx!} -}
(* Title: HOL/Algebra/Multiplicative_Group.thy Author: Simon Wimmer Author: Lars Noschinski *) theory Multiplicative_Group imports Complex_Main Group Coset UnivPoly Generated_Groups begin section \<open>Simplification Rules for Polynomials\<close> text_raw \<open>\label{sec:simp-rules}\<close> lemma (in ring_hom_cring) hom_sub[simp]: assumes "x \<in> carrier R" "y \<in> carrier R" shows "h (x \<ominus> y) = h x \<ominus>\<^bsub>S\<^esub> h y" using assms by (simp add: R.minus_eq S.minus_eq) context UP_ring begin lemma deg_nzero_nzero: assumes deg_p_nzero: "deg R p \<noteq> 0" shows "p \<noteq> \<zero>\<^bsub>P\<^esub>" using deg_zero deg_p_nzero by auto lemma deg_add_eq: assumes c: "p \<in> carrier P" "q \<in> carrier P" assumes "deg R q \<noteq> deg R p" shows "deg R (p \<oplus>\<^bsub>P\<^esub> q) = max (deg R p) (deg R q)" proof - let ?m = "max (deg R p) (deg R q)" from assms have "coeff P p ?m = \<zero> \<longleftrightarrow> coeff P q ?m \<noteq> \<zero>" by (metis deg_belowI lcoeff_nonzero[OF deg_nzero_nzero] linear max.absorb_iff2 max.absorb1) then have "coeff P (p \<oplus>\<^bsub>P\<^esub> q) ?m \<noteq> \<zero>" using assms by auto then have "deg R (p \<oplus>\<^bsub>P\<^esub> q) \<ge> ?m" using assms by (blast intro: deg_belowI) with deg_add[OF c] show ?thesis by arith qed lemma deg_minus_eq: assumes "p \<in> carrier P" "q \<in> carrier P" "deg R q \<noteq> deg R p" shows "deg R (p \<ominus>\<^bsub>P\<^esub> q) = max (deg R p) (deg R q)" using assms by (simp add: deg_add_eq a_minus_def) end context UP_cring begin lemma evalRR_add: assumes "p \<in> carrier P" "q \<in> carrier P" assumes x:"x \<in> carrier R" shows "eval R R id x (p \<oplus>\<^bsub>P\<^esub> q) = eval R R id x p \<oplus> eval R R id x q" proof - interpret UP_pre_univ_prop R R id by unfold_locales simp interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x]) show ?thesis using assms by simp qed lemma evalRR_sub: assumes "p \<in> carrier P" "q \<in> carrier P" assumes x:"x \<in> carrier R" shows "eval R R id x (p \<ominus>\<^bsub>P\<^esub> q) = eval R R id x p \<ominus> eval R R id x q" proof - interpret UP_pre_univ_prop R R id by unfold_locales simp interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x]) show ?thesis using assms by simp qed lemma evalRR_mult: assumes "p \<in> carrier P" "q \<in> carrier P" assumes x:"x \<in> carrier R" shows "eval R R id x (p \<otimes>\<^bsub>P\<^esub> q) = eval R R id x p \<otimes> eval R R id x q" proof - interpret UP_pre_univ_prop R R id by unfold_locales simp interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x]) show ?thesis using assms by simp qed lemma evalRR_monom: assumes a: "a \<in> carrier R" and x: "x \<in> carrier R" shows "eval R R id x (monom P a d) = a \<otimes> x [^] d" proof - interpret UP_pre_univ_prop R R id by unfold_locales simp show ?thesis using assms by (simp add: eval_monom) qed lemma evalRR_one: assumes x: "x \<in> carrier R" shows "eval R R id x \<one>\<^bsub>P\<^esub> = \<one>" proof - interpret UP_pre_univ_prop R R id by unfold_locales simp interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x]) show ?thesis using assms by simp qed lemma carrier_evalRR: assumes x: "x \<in> carrier R" and "p \<in> carrier P" shows "eval R R id x p \<in> carrier R" proof - interpret UP_pre_univ_prop R R id by unfold_locales simp interpret ring_hom_cring P R "eval R R id x" by unfold_locales (rule eval_ring_hom[OF x]) show ?thesis using assms by simp qed lemmas evalRR_simps = evalRR_add evalRR_sub evalRR_mult evalRR_monom evalRR_one carrier_evalRR end section \<open>Properties of the Euler \<open>\<phi>\<close>-function\<close> text_raw \<open>\label{sec:euler-phi}\<close> text\<open> In this section we prove that for every positive natural number the equation $\sum_{d | n}^n \varphi(d) = n$ holds. \<close> lemma dvd_div_ge_1: fixes a b :: nat assumes "a \<ge> 1" "b dvd a" shows "a div b \<ge> 1" proof - from \<open>b dvd a\<close> obtain c where "a = b * c" .. with \<open>a \<ge> 1\<close> show ?thesis by simp qed lemma dvd_nat_bounds: fixes n p :: nat assumes "p > 0" "n dvd p" shows "n > 0 \<and> n \<le> p" using assms by (simp add: dvd_pos_nat dvd_imp_le) (* Deviates from the definition given in the library in number theory *) definition phi' :: "nat => nat" where "phi' m = card {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m}" notation (latex output) phi' ("\<phi> _") lemma phi'_nonzero: assumes "m > 0" shows "phi' m > 0" proof - have "1 \<in> {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m}" using assms by simp hence "card {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m} > 0" by (auto simp: card_gt_0_iff) thus ?thesis unfolding phi'_def by simp qed lemma dvd_div_eq_1: fixes a b c :: nat assumes "c dvd a" "c dvd b" "a div c = b div c" shows "a = b" using assms dvd_mult_div_cancel[OF \<open>c dvd a\<close>] dvd_mult_div_cancel[OF \<open>c dvd b\<close>] by presburger lemma dvd_div_eq_2: fixes a b c :: nat assumes "c>0" "a dvd c" "b dvd c" "c div a = c div b" shows "a = b" proof - have "a > 0" "a \<le> c" using dvd_nat_bounds[OF assms(1-2)] by auto have "a*(c div a) = c" using assms dvd_mult_div_cancel by fastforce also have "\<dots> = b*(c div a)" using assms dvd_mult_div_cancel by fastforce finally show "a = b" using \<open>c>0\<close> dvd_div_ge_1[OF _ \<open>a dvd c\<close>] by fastforce qed lemma div_mult_mono: fixes a b c :: nat assumes "a > 0" "a\<le>d" shows "a * b div d \<le> b" proof - have "a*b div d \<le> b*a div a" using assms div_le_mono2 mult.commute[of a b] by presburger thus ?thesis using assms by force qed text\<open> We arrive at the main result of this section: For every positive natural number the equation $\sum_{d | n}^n \varphi(d) = n$ holds. The outline of the proof for this lemma is as follows: We count the $n$ fractions $1/n$, $\ldots$, $(n-1)/n$, $n/n$. We analyze the reduced form $a/d = m/n$ for any of those fractions. We want to know how many fractions $m/n$ have the reduced form denominator $d$. The condition $1 \leq m \leq n$ is equivalent to the condition $1 \leq a \leq d$. Therefore we want to know how many $a$ with $1 \leq a \leq d$ exist, s.t. @{term "gcd a d = 1"}. This number is exactly @{term "phi' d"}. Finally, by counting the fractions $m/n$ according to their reduced form denominator, we get: @{term [display] "(\<Sum>d | d dvd n . phi' d) = n"}. To formalize this proof in Isabelle, we analyze for an arbitrary divisor $d$ of $n$ \begin{itemize} \item the set of reduced form numerators @{term "{a. (1::nat) \<le> a \<and> a \<le> d \<and> coprime a d}"} \item the set of numerators $m$, for which $m/n$ has the reduced form denominator $d$, i.e. the set @{term "{m \<in> {1::nat .. n}. n div gcd m n = d}"} \end{itemize} We show that @{term "\<lambda>a. a*n div d"} with the inverse @{term "\<lambda>a. a div gcd a n"} is a bijection between theses sets, thus yielding the equality @{term [display] "phi' d = card {m \<in> {1 .. n}. n div gcd m n = d}"} This gives us @{term [display] "(\<Sum>d | d dvd n . phi' d) = card (\<Union>d \<in> {d. d dvd n}. {m \<in> {1 .. n}. n div gcd m n = d})"} and by showing @{term "(\<Union>d \<in> {d. d dvd n}. {m \<in> {1::nat .. n}. n div gcd m n = d}) \<supseteq> {1 .. n}"} (this is our counting argument) the thesis follows. \<close> lemma sum_phi'_factors: fixes n :: nat assumes "n > 0" shows "(\<Sum>d | d dvd n. phi' d) = n" proof - { fix d assume "d dvd n" then obtain q where q: "n = d * q" .. have "card {a. 1 \<le> a \<and> a \<le> d \<and> coprime a d} = card {m \<in> {1 .. n}. n div gcd m n = d}" (is "card ?RF = card ?F") proof (rule card_bij_eq) { fix a b assume "a * n div d = b * n div d" hence "a * (n div d) = b * (n div d)" using dvd_div_mult[OF \<open>d dvd n\<close>] by (fastforce simp add: mult.commute) hence "a = b" using dvd_div_ge_1[OF _ \<open>d dvd n\<close>] \<open>n>0\<close> by (simp add: mult.commute nat_mult_eq_cancel1) } thus "inj_on (\<lambda>a. a*n div d) ?RF" unfolding inj_on_def by blast { fix a assume a:"a\<in>?RF" hence "a * (n div d) \<ge> 1" using \<open>n>0\<close> dvd_div_ge_1[OF _ \<open>d dvd n\<close>] by simp hence ge_1:"a * n div d \<ge> 1" by (simp add: \<open>d dvd n\<close> div_mult_swap) have le_n:"a * n div d \<le> n" using div_mult_mono a by simp have "gcd (a * n div d) n = n div d * gcd a d" by (simp add: gcd_mult_distrib_nat q ac_simps) hence "n div gcd (a * n div d) n = d*n div (d*(n div d))" using a by simp hence "a * n div d \<in> ?F" using ge_1 le_n by (fastforce simp add: \<open>d dvd n\<close>) } thus "(\<lambda>a. a*n div d) ` ?RF \<subseteq> ?F" by blast { fix m l assume A: "m \<in> ?F" "l \<in> ?F" "m div gcd m n = l div gcd l n" hence "gcd m n = gcd l n" using dvd_div_eq_2[OF assms] by fastforce hence "m = l" using dvd_div_eq_1[of "gcd m n" m l] A(3) by fastforce } thus "inj_on (\<lambda>a. a div gcd a n) ?F" unfolding inj_on_def by blast { fix m assume "m \<in> ?F" hence "m div gcd m n \<in> ?RF" using dvd_div_ge_1 by (fastforce simp add: div_le_mono div_gcd_coprime) } thus "(\<lambda>a. a div gcd a n) ` ?F \<subseteq> ?RF" by blast qed force+ } hence phi'_eq:"\<And>d. d dvd n \<Longrightarrow> phi' d = card {m \<in> {1 .. n}. n div gcd m n = d}" unfolding phi'_def by presburger have fin:"finite {d. d dvd n}" using dvd_nat_bounds[OF \<open>n>0\<close>] by force have "(\<Sum>d | d dvd n. phi' d) = card (\<Union>d \<in> {d. d dvd n}. {m \<in> {1 .. n}. n div gcd m n = d})" using card_UN_disjoint[OF fin, of "(\<lambda>d. {m \<in> {1 .. n}. n div gcd m n = d})"] phi'_eq by fastforce also have "(\<Union>d \<in> {d. d dvd n}. {m \<in> {1 .. n}. n div gcd m n = d}) = {1 .. n}" (is "?L = ?R") proof show "?L \<supseteq> ?R" proof fix m assume m: "m \<in> ?R" thus "m \<in> ?L" using dvd_triv_right[of "n div gcd m n" "gcd m n"] by simp qed qed fastforce finally show ?thesis by force qed section \<open>Order of an Element of a Group\<close> text_raw \<open>\label{sec:order-elem}\<close> context group begin lemma pow_eq_div2: fixes m n :: nat assumes x_car: "x \<in> carrier G" assumes pow_eq: "x [^] m = x [^] n" shows "x [^] (m - n) = \<one>" proof (cases "m < n") case False have "\<one> \<otimes> x [^] m = x [^] m" by (simp add: x_car) also have "\<dots> = x [^] (m - n) \<otimes> x [^] n" using False by (simp add: nat_pow_mult x_car) also have "\<dots> = x [^] (m - n) \<otimes> x [^] m" by (simp add: pow_eq) finally show ?thesis by (simp add: x_car) qed simp definition ord where "ord a = Min {d \<in> {1 .. order G} . a [^] d = \<one>}" lemma assumes finite:"finite (carrier G)" assumes a:"a \<in> carrier G" shows ord_ge_1: "1 \<le> ord a" and ord_le_group_order: "ord a \<le> order G" and pow_ord_eq_1: "a [^] ord a = \<one>" proof - have "\<not>inj_on (\<lambda>x. a [^] x) {0 .. order G}" proof (rule notI) assume A: "inj_on (\<lambda>x. a [^] x) {0 .. order G}" have "order G + 1 = card {0 .. order G}" by simp also have "\<dots> = card ((\<lambda>x. a [^] x) ` {0 .. order G})" (is "_ = card ?S") using A by (simp add: card_image) also have "?S = {a [^] x | x. x \<in> {0 .. order G}}" by blast also have "\<dots> \<subseteq> carrier G" (is "?S \<subseteq> _") using a by blast then have "card ?S \<le> order G" unfolding order_def by (rule card_mono[OF finite]) finally show False by arith qed then obtain x y where x_y:"x \<noteq> y" "x \<in> {0 .. order G}" "y \<in> {0 .. order G}" "a [^] x = a [^] y" unfolding inj_on_def by blast obtain d where "1 \<le> d" "a [^] d = \<one>" "d \<le> order G" proof cases assume "y < x" with x_y show ?thesis by (intro that[where d="x - y"]) (auto simp add: pow_eq_div2[OF a]) next assume "\<not>y < x" with x_y show ?thesis by (intro that[where d="y - x"]) (auto simp add: pow_eq_div2[OF a]) qed hence "ord a \<in> {d \<in> {1 .. order G} . a [^] d = \<one>}" unfolding ord_def using Min_in[of "{d \<in> {1 .. order G} . a [^] d = \<one>}"] by fastforce then show "1 \<le> ord a" and "ord a \<le> order G" and "a [^] ord a = \<one>" by (auto simp: order_def) qed lemma finite_group_elem_finite_ord: assumes "finite (carrier G)" "x \<in> carrier G" shows "\<exists> d::nat. d \<ge> 1 \<and> x [^] d = \<one>" using assms ord_ge_1 pow_ord_eq_1 by auto lemma ord_min: assumes "finite (carrier G)" "1 \<le> d" "a \<in> carrier G" "a [^] d = \<one>" shows "ord a \<le> d" proof - define Ord where "Ord = {d \<in> {1..order G}. a [^] d = \<one>}" have fin: "finite Ord" by (auto simp: Ord_def) have in_ord: "ord a \<in> Ord" using assms pow_ord_eq_1 ord_ge_1 ord_le_group_order by (auto simp: Ord_def) then have "Ord \<noteq> {}" by auto show ?thesis proof (cases "d \<le> order G") case True then have "d \<in> Ord" using assms by (auto simp: Ord_def) with fin in_ord show ?thesis unfolding ord_def Ord_def[symmetric] by simp next case False then show ?thesis using in_ord by (simp add: Ord_def) qed qed lemma ord_inj: assumes finite: "finite (carrier G)" assumes a: "a \<in> carrier G" shows "inj_on (\<lambda> x . a [^] x) {0 .. ord a - 1}" proof (rule inj_onI, rule ccontr) fix x y assume A: "x \<in> {0 .. ord a - 1}" "y \<in> {0 .. ord a - 1}" "a [^] x= a [^] y" "x \<noteq> y" have "finite {d \<in> {1..order G}. a [^] d = \<one>}" by auto { fix x y assume A: "x < y" "x \<in> {0 .. ord a - 1}" "y \<in> {0 .. ord a - 1}" "a [^] x = a [^] y" hence "y - x < ord a" by auto also have "\<dots> \<le> order G" using assms by (simp add: ord_le_group_order) finally have y_x_range:"y - x \<in> {1 .. order G}" using A by force have "a [^] (y-x) = \<one>" using a A by (simp add: pow_eq_div2) hence y_x:"y - x \<in> {d \<in> {1.. order G}. a [^] d = \<one>}" using y_x_range by blast have "min (y - x) (ord a) = ord a" using Min.in_idem[OF \<open>finite {d \<in> {1 .. order G} . a [^] d = \<one>}\<close> y_x] ord_def by auto with \<open>y - x < ord a\<close> have False by linarith } note X = this { assume "x < y" with A X have False by blast } moreover { assume "x > y" with A X have False by metis } moreover { assume "x = y" then have False using A by auto} ultimately show False by fastforce qed lemma ord_inj': assumes finite: "finite (carrier G)" assumes a: "a \<in> carrier G" shows "inj_on (\<lambda> x . a [^] x) {1 .. ord a}" proof (rule inj_onI, rule ccontr) fix x y :: nat assume A:"x \<in> {1 .. ord a}" "y \<in> {1 .. ord a}" "a [^] x = a [^] y" "x\<noteq>y" { assume "x < ord a" "y < ord a" hence False using ord_inj[OF assms] A unfolding inj_on_def by fastforce } moreover { assume "x = ord a" "y < ord a" hence "a [^] y = a [^] (0::nat)" using pow_ord_eq_1[OF assms] A by auto hence "y=0" using ord_inj[OF assms] \<open>y < ord a\<close> unfolding inj_on_def by force hence False using A by fastforce } moreover { assume "y = ord a" "x < ord a" hence "a [^] x = a [^] (0::nat)" using pow_ord_eq_1[OF assms] A by auto hence "x=0" using ord_inj[OF assms] \<open>x < ord a\<close> unfolding inj_on_def by force hence False using A by fastforce } ultimately show False using A by force qed lemma ord_elems: assumes "finite (carrier G)" "a \<in> carrier G" shows "{a[^]x | x. x \<in> (UNIV :: nat set)} = {a[^]x | x. x \<in> {0 .. ord a - 1}}" (is "?L = ?R") proof show "?R \<subseteq> ?L" by blast { fix y assume "y \<in> ?L" then obtain x::nat where x:"y = a[^]x" by auto define r q where "r = x mod ord a" and "q = x div ord a" then have "x = q * ord a + r" by (simp add: div_mult_mod_eq) hence "y = (a[^]ord a)[^]q \<otimes> a[^]r" using x assms by (simp add: mult.commute nat_pow_mult nat_pow_pow) hence "y = a[^]r" using assms by (simp add: pow_ord_eq_1) have "r < ord a" using ord_ge_1[OF assms] by (simp add: r_def) hence "r \<in> {0 .. ord a - 1}" by (force simp: r_def) hence "y \<in> {a[^]x | x. x \<in> {0 .. ord a - 1}}" using \<open>y=a[^]r\<close> by blast } thus "?L \<subseteq> ?R" by auto qed (* Next three lemmas contributed by Paulo Emílio de Vilhena*) lemma generate_pow_on_finite_carrier: assumes "finite (carrier G)" and "a \<in> carrier G" shows "generate G { a } = { a [^] k | k. k \<in> (UNIV :: nat set) }" proof show "{ a [^] k | k. k \<in> (UNIV :: nat set) } \<subseteq> generate G { a }" proof fix b assume "b \<in> { a [^] k | k. k \<in> (UNIV :: nat set) }" then obtain k :: nat where "b = a [^] k" by blast hence "b = a [^] (int k)" using int_pow_def2 by auto thus "b \<in> generate G { a }" unfolding generate_pow[OF assms(2)] by blast qed next show "generate G { a } \<subseteq> { a [^] k | k. k \<in> (UNIV :: nat set) }" proof fix b assume "b \<in> generate G { a }" then obtain k :: int where k: "b = a [^] k" unfolding generate_pow[OF assms(2)] by blast show "b \<in> { a [^] k | k. k \<in> (UNIV :: nat set) }" proof (cases "k < 0") assume "\<not> k < 0" hence "b = a [^] (nat k)" using k int_pow_def2 by auto thus ?thesis by blast next assume "k < 0" hence b: "b = inv (a [^] (nat (- k)))" using k int_pow_def2 by auto obtain m where m: "ord a * m \<ge> nat (- k)" by (metis assms mult.left_neutral mult_le_mono1 ord_ge_1) hence "a [^] (ord a * m) = \<one>" by (metis assms nat_pow_one nat_pow_pow pow_ord_eq_1) then obtain k' :: nat where "(a [^] (nat (- k))) \<otimes> (a [^] k') = \<one>" using m assms(2) nat_le_iff_add nat_pow_mult by auto hence "b = a [^] k'" using b assms(2) by (metis inv_unique' nat_pow_closed nat_pow_comm) thus "b \<in> { a [^] k | k. k \<in> (UNIV :: nat set) }" by blast qed qed qed lemma generate_pow_card: assumes "finite (carrier G)" and "a \<in> carrier G" shows "ord a = card (generate G { a })" proof - have "generate G { a } = (([^]) a) ` {0..ord a - 1}" using generate_pow_on_finite_carrier[OF assms] unfolding ord_elems[OF assms] by auto thus ?thesis using ord_inj[OF assms] ord_ge_1[OF assms] by (simp add: card_image) qed (* This lemma was a suggestion of generalization given by Jeremy Avigad at the end of the theory FiniteProduct. *) corollary power_order_eq_one_group_version: assumes "finite (carrier G)" and "a \<in> carrier G" shows "a [^] (order G) = \<one>" proof - have "(ord a) dvd (order G)" using lagrange[OF generate_is_subgroup[of " { a }"]] assms(2) unfolding generate_pow_card[OF assms] by (metis dvd_triv_right empty_subsetI insert_subset) then obtain k :: nat where "order G = ord a * k" by blast thus ?thesis using assms(2) pow_ord_eq_1[OF assms] by (metis nat_pow_one nat_pow_pow) qed lemma ord_dvd_pow_eq_1 : assumes "finite (carrier G)" "a \<in> carrier G" "a [^] k = \<one>" shows "ord a dvd k" proof - define r where "r = k mod ord a" define r q where "r = k mod ord a" and "q = k div ord a" then have q: "k = q * ord a + r" by (simp add: div_mult_mod_eq) hence "a[^]k = (a[^]ord a)[^]q \<otimes> a[^]r" using assms by (simp add: mult.commute nat_pow_mult nat_pow_pow) hence "a[^]k = a[^]r" using assms by (simp add: pow_ord_eq_1) hence "a[^]r = \<one>" using assms(3) by simp have "r < ord a" using ord_ge_1[OF assms(1-2)] by (simp add: r_def) hence "r = 0" using \<open>a[^]r = \<one>\<close> ord_def[of a] ord_min[of r a] assms(1-2) by linarith thus ?thesis using q by simp qed lemma dvd_gcd : fixes a b :: nat obtains q where "a * (b div gcd a b) = b*q" proof have "a * (b div gcd a b) = (a div gcd a b) * b" by (simp add: div_mult_swap dvd_div_mult) also have "\<dots> = b * (a div gcd a b)" by simp finally show "a * (b div gcd a b) = b * (a div gcd a b) " . qed lemma ord_pow_dvd_ord_elem : assumes finite[simp]: "finite (carrier G)" assumes a[simp]:"a \<in> carrier G" shows "ord (a[^]n) = ord a div gcd n (ord a)" proof - have "(a[^]n) [^] ord a = (a [^] ord a) [^] n" by (simp add: mult.commute nat_pow_pow) hence "(a[^]n) [^] ord a = \<one>" by (simp add: pow_ord_eq_1) obtain q where "n * (ord a div gcd n (ord a)) = ord a * q" by (rule dvd_gcd) hence "(a[^]n) [^] (ord a div gcd n (ord a)) = (a [^] ord a)[^]q" by (simp add : nat_pow_pow) hence pow_eq_1: "(a[^]n) [^] (ord a div gcd n (ord a)) = \<one>" by (auto simp add : pow_ord_eq_1[of a]) have "ord a \<ge> 1" using ord_ge_1 by simp have ge_1:"ord a div gcd n (ord a) \<ge> 1" proof - have "gcd n (ord a) dvd ord a" by blast thus ?thesis by (rule dvd_div_ge_1[OF \<open>ord a \<ge> 1\<close>]) qed have "ord a \<le> order G" by (simp add: ord_le_group_order) have "ord a div gcd n (ord a) \<le> order G" proof - have "ord a div gcd n (ord a) \<le> ord a" by simp thus ?thesis using \<open>ord a \<le> order G\<close> by linarith qed hence ord_gcd_elem:"ord a div gcd n (ord a) \<in> {d \<in> {1..order G}. (a[^]n) [^] d = \<one>}" using ge_1 pow_eq_1 by force { fix d :: nat assume d_elem:"d \<in> {d \<in> {1..order G}. (a[^]n) [^] d = \<one>}" assume d_lt:"d < ord a div gcd n (ord a)" hence pow_nd:"a[^](n*d) = \<one>" using d_elem by (simp add : nat_pow_pow) hence "ord a dvd n*d" using assms by (auto simp add : ord_dvd_pow_eq_1) then obtain q where "ord a * q = n*d" by (metis dvd_mult_div_cancel) hence prod_eq:"(ord a div gcd n (ord a)) * q = (n div gcd n (ord a)) * d" by (simp add: dvd_div_mult) have cp:"coprime (ord a div gcd n (ord a)) (n div gcd n (ord a))" proof - have "coprime (n div gcd n (ord a)) (ord a div gcd n (ord a))" using div_gcd_coprime[of n "ord a"] ge_1 by fastforce thus ?thesis by (simp add: ac_simps) qed have dvd_d:"(ord a div gcd n (ord a)) dvd d" proof - have "ord a div gcd n (ord a) dvd (n div gcd n (ord a)) * d" using prod_eq by (metis dvd_triv_right mult.commute) hence "ord a div gcd n (ord a) dvd d * (n div gcd n (ord a))" by (simp add: mult.commute) then show ?thesis using cp by (simp add: coprime_dvd_mult_left_iff) qed have "d > 0" using d_elem by simp hence "ord a div gcd n (ord a) \<le> d" using dvd_d by (simp add : Nat.dvd_imp_le) hence False using d_lt by simp } hence ord_gcd_min: "\<And> d . d \<in> {d \<in> {1..order G}. (a[^]n) [^] d = \<one>} \<Longrightarrow> d\<ge>ord a div gcd n (ord a)" by fastforce have fin:"finite {d \<in> {1..order G}. (a[^]n) [^] d = \<one>}" by auto thus ?thesis using Min_eqI[OF fin ord_gcd_min ord_gcd_elem] unfolding ord_def by simp qed lemma ord_1_eq_1 : assumes "finite (carrier G)" shows "ord \<one> = 1" using assms ord_ge_1 ord_min[of 1 \<one>] by force lemma element_generates_subgroup: assumes finite[simp]: "finite (carrier G)" assumes a[simp]: "a \<in> carrier G" shows "subgroup {a [^] i | i. i \<in> {0 .. ord a - 1}} G" using generate_is_subgroup[of "{ a }"] assms(2) generate_pow_on_finite_carrier[OF assms] unfolding ord_elems[OF assms] by auto lemma ord_dvd_group_order: (* <- DELETE *) assumes "finite (carrier G)" and "a \<in> carrier G" shows "(ord a) dvd (order G)" using lagrange[OF generate_is_subgroup[of " { a }"]] assms(2) unfolding generate_pow_card[OF assms] by (metis dvd_triv_right empty_subsetI insert_subset) end section \<open>Number of Roots of a Polynomial\<close> text_raw \<open>\label{sec:number-roots}\<close> definition mult_of :: "('a, 'b) ring_scheme \<Rightarrow> 'a monoid" where "mult_of R \<equiv> \<lparr> carrier = carrier R - {\<zero>\<^bsub>R\<^esub>}, mult = mult R, one = \<one>\<^bsub>R\<^esub>\<rparr>" lemma carrier_mult_of [simp]: "carrier (mult_of R) = carrier R - {\<zero>\<^bsub>R\<^esub>}" by (simp add: mult_of_def) lemma mult_mult_of [simp]: "mult (mult_of R) = mult R" by (simp add: mult_of_def) lemma nat_pow_mult_of: "([^]\<^bsub>mult_of R\<^esub>) = (([^]\<^bsub>R\<^esub>) :: _ \<Rightarrow> nat \<Rightarrow> _)" by (simp add: mult_of_def fun_eq_iff nat_pow_def) lemma one_mult_of [simp]: "\<one>\<^bsub>mult_of R\<^esub> = \<one>\<^bsub>R\<^esub>" by (simp add: mult_of_def) lemmas mult_of_simps = carrier_mult_of mult_mult_of nat_pow_mult_of one_mult_of context field begin lemma mult_of_is_Units: "mult_of R = units_of R" unfolding mult_of_def units_of_def using field_Units by auto lemma m_inv_mult_of : "\<And>x. x \<in> carrier (mult_of R) \<Longrightarrow> m_inv (mult_of R) x = m_inv R x" using mult_of_is_Units units_of_inv unfolding units_of_def by simp lemma field_mult_group : shows "group (mult_of R)" apply (rule groupI) apply (auto simp: mult_of_simps m_assoc dest: integral) by (metis Diff_iff Units_inv_Units Units_l_inv field_Units singletonE) lemma finite_mult_of: "finite (carrier R) \<Longrightarrow> finite (carrier (mult_of R))" by (auto simp: mult_of_simps) lemma order_mult_of: "finite (carrier R) \<Longrightarrow> order (mult_of R) = order R - 1" unfolding order_def carrier_mult_of by (simp add: card.remove) end lemma (in monoid) Units_pow_closed : fixes d :: nat assumes "x \<in> Units G" shows "x [^] d \<in> Units G" by (metis assms group.is_monoid monoid.nat_pow_closed units_group units_of_carrier units_of_pow) lemma (in comm_monoid) is_monoid: shows "monoid G" by unfold_locales declare comm_monoid.is_monoid[intro?] lemma (in ring) r_right_minus_eq[simp]: assumes "a \<in> carrier R" "b \<in> carrier R" shows "a \<ominus> b = \<zero> \<longleftrightarrow> a = b" using assms by (metis a_minus_def add.inv_closed minus_equality r_neg) context UP_cring begin lemma is_UP_cring:"UP_cring R" by (unfold_locales) lemma is_UP_ring : shows "UP_ring R" by (unfold_locales) end context UP_domain begin lemma roots_bound: assumes f [simp]: "f \<in> carrier P" assumes f_not_zero: "f \<noteq> \<zero>\<^bsub>P\<^esub>" assumes finite: "finite (carrier R)" shows "finite {a \<in> carrier R . eval R R id a f = \<zero>} \<and> card {a \<in> carrier R . eval R R id a f = \<zero>} \<le> deg R f" using f f_not_zero proof (induction "deg R f" arbitrary: f) case 0 have "\<And>x. eval R R id x f \<noteq> \<zero>" proof - fix x have "(\<Oplus>i\<in>{..deg R f}. id (coeff P f i) \<otimes> x [^] i) \<noteq> \<zero>" using 0 lcoeff_nonzero_nonzero[where p = f] by simp thus "eval R R id x f \<noteq> \<zero>" using 0 unfolding eval_def P_def by simp qed then have *: "{a \<in> carrier R. eval R R (\<lambda>a. a) a f = \<zero>} = {}" by (auto simp: id_def) show ?case by (simp add: *) next case (Suc x) show ?case proof (cases "\<exists> a \<in> carrier R . eval R R id a f = \<zero>") case True then obtain a where a_carrier[simp]: "a \<in> carrier R" and a_root:"eval R R id a f = \<zero>" by blast have R_not_triv: "carrier R \<noteq> {\<zero>}" by (metis R.one_zeroI R.zero_not_one) obtain q where q:"(q \<in> carrier P)" and f:"f = (monom P \<one>\<^bsub>R\<^esub> 1 \<ominus>\<^bsub> P\<^esub> monom P a 0) \<otimes>\<^bsub>P\<^esub> q \<oplus>\<^bsub>P\<^esub> monom P (eval R R id a f) 0" using remainder_theorem[OF Suc.prems(1) a_carrier R_not_triv] by auto hence lin_fac: "f = (monom P \<one>\<^bsub>R\<^esub> 1 \<ominus>\<^bsub> P\<^esub> monom P a 0) \<otimes>\<^bsub>P\<^esub> q" using q by (simp add: a_root) have deg:"deg R (monom P \<one>\<^bsub>R\<^esub> 1 \<ominus>\<^bsub> P\<^esub> monom P a 0) = 1" using a_carrier by (simp add: deg_minus_eq) hence mon_not_zero:"(monom P \<one>\<^bsub>R\<^esub> 1 \<ominus>\<^bsub> P\<^esub> monom P a 0) \<noteq> \<zero>\<^bsub>P\<^esub>" by (fastforce simp del: r_right_minus_eq) have q_not_zero:"q \<noteq> \<zero>\<^bsub>P\<^esub>" using Suc by (auto simp add : lin_fac) hence "deg R q = x" using Suc deg deg_mult[OF mon_not_zero q_not_zero _ q] by (simp add : lin_fac) hence q_IH:"finite {a \<in> carrier R . eval R R id a q = \<zero>} \<and> card {a \<in> carrier R . eval R R id a q = \<zero>} \<le> x" using Suc q q_not_zero by blast have subs:"{a \<in> carrier R . eval R R id a f = \<zero>} \<subseteq> {a \<in> carrier R . eval R R id a q = \<zero>} \<union> {a}" (is "?L \<subseteq> ?R \<union> {a}") using a_carrier \<open>q \<in> _\<close> by (auto simp: evalRR_simps lin_fac R.integral_iff) have "{a \<in> carrier R . eval R R id a f = \<zero>} \<subseteq> insert a {a \<in> carrier R . eval R R id a q = \<zero>}" using subs by auto hence "card {a \<in> carrier R . eval R R id a f = \<zero>} \<le> card (insert a {a \<in> carrier R . eval R R id a q = \<zero>})" using q_IH by (blast intro: card_mono) also have "\<dots> \<le> deg R f" using q_IH \<open>Suc x = _\<close> by (simp add: card_insert_if) finally show ?thesis using q_IH \<open>Suc x = _\<close> using finite by force next case False hence "card {a \<in> carrier R. eval R R id a f = \<zero>} = 0" using finite by auto also have "\<dots> \<le> deg R f" by simp finally show ?thesis using finite by auto qed qed end lemma (in domain) num_roots_le_deg : fixes p d :: nat assumes finite:"finite (carrier R)" assumes d_neq_zero : "d \<noteq> 0" shows "card {x \<in> carrier R. x [^] d = \<one>} \<le> d" proof - let ?f = "monom (UP R) \<one>\<^bsub>R\<^esub> d \<ominus>\<^bsub> (UP R)\<^esub> monom (UP R) \<one>\<^bsub>R\<^esub> 0" have one_in_carrier:"\<one> \<in> carrier R" by simp interpret R: UP_domain R "UP R" by (unfold_locales) have "deg R ?f = d" using d_neq_zero by (simp add: R.deg_minus_eq) hence f_not_zero:"?f \<noteq> \<zero>\<^bsub>UP R\<^esub>" using d_neq_zero by (auto simp add : R.deg_nzero_nzero) have roots_bound:"finite {a \<in> carrier R . eval R R id a ?f = \<zero>} \<and> card {a \<in> carrier R . eval R R id a ?f = \<zero>} \<le> deg R ?f" using finite by (intro R.roots_bound[OF _ f_not_zero]) simp have subs:"{x \<in> carrier R. x [^] d = \<one>} \<subseteq> {a \<in> carrier R . eval R R id a ?f = \<zero>}" by (auto simp: R.evalRR_simps) then have "card {x \<in> carrier R. x [^] d = \<one>} \<le> card {a \<in> carrier R. eval R R id a ?f = \<zero>}" using finite by (simp add : card_mono) thus ?thesis using \<open>deg R ?f = d\<close> roots_bound by linarith qed section \<open>The Multiplicative Group of a Field\<close> text_raw \<open>\label{sec:mult-group}\<close> text \<open> In this section we show that the multiplicative group of a finite field is generated by a single element, i.e. it is cyclic. The proof is inspired by the first proof given in the survey~@{cite "conrad-cyclicity"}. \<close> lemma (in group) pow_order_eq_1: assumes "finite (carrier G)" "x \<in> carrier G" shows "x [^] order G = \<one>" using assms by (metis nat_pow_pow ord_dvd_group_order pow_ord_eq_1 dvdE nat_pow_one) (* XXX remove in AFP devel, replaced by div_eq_dividend_iff *) lemma nat_div_eq: "a \<noteq> 0 \<Longrightarrow> (a :: nat) div b = a \<longleftrightarrow> b = 1" apply rule apply (cases "b = 0") apply simp_all apply (metis (full_types) One_nat_def Suc_lessI div_less_dividend less_not_refl3) done lemma (in group) assumes finite': "finite (carrier G)" assumes "a \<in> carrier G" shows pow_ord_eq_ord_iff: "group.ord G (a [^] k) = ord a \<longleftrightarrow> coprime k (ord a)" (is "?L \<longleftrightarrow> ?R") proof assume A: ?L then show ?R using assms ord_ge_1 [OF assms] by (auto simp: nat_div_eq ord_pow_dvd_ord_elem coprime_iff_gcd_eq_1) next assume ?R then show ?L using ord_pow_dvd_ord_elem[OF assms, of k] by auto qed context field begin lemma num_elems_of_ord_eq_phi': assumes finite: "finite (carrier R)" and dvd: "d dvd order (mult_of R)" and exists: "\<exists>a\<in>carrier (mult_of R). group.ord (mult_of R) a = d" shows "card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d} = phi' d" proof - note mult_of_simps[simp] have finite': "finite (carrier (mult_of R))" using finite by (rule finite_mult_of) interpret G:group "mult_of R" rewrites "([^]\<^bsub>mult_of R\<^esub>) = (([^]) :: _ \<Rightarrow> nat \<Rightarrow> _)" and "\<one>\<^bsub>mult_of R\<^esub> = \<one>" by (rule field_mult_group) simp_all from exists obtain a where a:"a \<in> carrier (mult_of R)" and ord_a: "group.ord (mult_of R) a = d" by (auto simp add: card_gt_0_iff) have set_eq1:"{a[^]n| n. n \<in> {1 .. d}} = {x \<in> carrier (mult_of R). x [^] d = \<one>}" proof (rule card_seteq) show "finite {x \<in> carrier (mult_of R). x [^] d = \<one>}" using finite by auto show "{a[^]n| n. n \<in> {1 ..d}} \<subseteq> {x \<in> carrier (mult_of R). x[^]d = \<one>}" proof fix x assume "x \<in> {a[^]n | n. n \<in> {1 .. d}}" then obtain n where n:"x = a[^]n \<and> n \<in> {1 .. d}" by auto have "x[^]d =(a[^]d)[^]n" using n a ord_a by (simp add:nat_pow_pow mult.commute) hence "x[^]d = \<one>" using ord_a G.pow_ord_eq_1[OF finite' a] by fastforce thus "x \<in> {x \<in> carrier (mult_of R). x[^]d = \<one>}" using G.nat_pow_closed[OF a] n by blast qed show "card {x \<in> carrier (mult_of R). x [^] d = \<one>} \<le> card {a[^]n | n. n \<in> {1 .. d}}" proof - have *:"{a[^]n | n. n \<in> {1 .. d }} = ((\<lambda> n. a[^]n) ` {1 .. d})" by auto have "0 < order (mult_of R)" unfolding order_mult_of[OF finite] using card_mono[OF finite, of "{\<zero>, \<one>}"] by (simp add: order_def) have "card {x \<in> carrier (mult_of R). x [^] d = \<one>} \<le> card {x \<in> carrier R. x [^] d = \<one>}" using finite by (auto intro: card_mono) also have "\<dots> \<le> d" using \<open>0 < order (mult_of R)\<close> num_roots_le_deg[OF finite, of d] by (simp add : dvd_pos_nat[OF _ \<open>d dvd order (mult_of R)\<close>]) finally show ?thesis using G.ord_inj'[OF finite' a] ord_a * by (simp add: card_image) qed qed have set_eq2:"{x \<in> carrier (mult_of R) . group.ord (mult_of R) x = d} = (\<lambda> n . a[^]n) ` {n \<in> {1 .. d}. group.ord (mult_of R) (a[^]n) = d}" (is "?L = ?R") proof { fix x assume x:"x \<in> (carrier (mult_of R)) \<and> group.ord (mult_of R) x = d" hence "x \<in> {x \<in> carrier (mult_of R). x [^] d = \<one>}" by (simp add: G.pow_ord_eq_1[OF finite', of x, symmetric]) then obtain n where n:"x = a[^]n \<and> n \<in> {1 .. d}" using set_eq1 by blast hence "x \<in> ?R" using x by fast } thus "?L \<subseteq> ?R" by blast show "?R \<subseteq> ?L" using a by (auto simp add: carrier_mult_of[symmetric] simp del: carrier_mult_of) qed have "inj_on (\<lambda> n . a[^]n) {n \<in> {1 .. d}. group.ord (mult_of R) (a[^]n) = d}" using G.ord_inj'[OF finite' a, unfolded ord_a] unfolding inj_on_def by fast hence "card ((\<lambda>n. a[^]n) ` {n \<in> {1 .. d}. group.ord (mult_of R) (a[^]n) = d}) = card {k \<in> {1 .. d}. group.ord (mult_of R) (a[^]k) = d}" using card_image by blast thus ?thesis using set_eq2 G.pow_ord_eq_ord_iff[OF finite' \<open>a \<in> _\<close>, unfolded ord_a] by (simp add: phi'_def) qed end theorem (in field) finite_field_mult_group_has_gen : assumes finite:"finite (carrier R)" shows "\<exists> a \<in> carrier (mult_of R) . carrier (mult_of R) = {a[^]i | i::nat . i \<in> UNIV}" proof - note mult_of_simps[simp] have finite': "finite (carrier (mult_of R))" using finite by (rule finite_mult_of) interpret G: group "mult_of R" rewrites "([^]\<^bsub>mult_of R\<^esub>) = (([^]) :: _ \<Rightarrow> nat \<Rightarrow> _)" and "\<one>\<^bsub>mult_of R\<^esub> = \<one>" by (rule field_mult_group) (simp_all add: fun_eq_iff nat_pow_def) let ?N = "\<lambda> x . card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = x}" have "0 < order R - 1" unfolding order_def using card_mono[OF finite, of "{\<zero>, \<one>}"] by simp then have *: "0 < order (mult_of R)" using assms by (simp add: order_mult_of) have fin: "finite {d. d dvd order (mult_of R) }" using dvd_nat_bounds[OF *] by force have "(\<Sum>d | d dvd order (mult_of R). ?N d) = card (UN d:{d . d dvd order (mult_of R) }. {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d})" (is "_ = card ?U") using fin finite by (subst card_UN_disjoint) auto also have "?U = carrier (mult_of R)" proof { fix x assume x:"x \<in> carrier (mult_of R)" hence x':"x\<in>carrier (mult_of R)" by simp then have "group.ord (mult_of R) x dvd order (mult_of R)" using finite' G.ord_dvd_group_order[OF _ x'] by (simp add: order_mult_of) hence "x \<in> ?U" using dvd_nat_bounds[of "order (mult_of R)" "group.ord (mult_of R) x"] x by blast } thus "carrier (mult_of R) \<subseteq> ?U" by blast qed auto also have "card ... = order (mult_of R)" using order_mult_of finite' by (simp add: order_def) finally have sum_Ns_eq: "(\<Sum>d | d dvd order (mult_of R). ?N d) = order (mult_of R)" . { fix d assume d:"d dvd order (mult_of R)" have "card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d} \<le> phi' d" proof cases assume "card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d} = 0" thus ?thesis by presburger next assume "card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = d} \<noteq> 0" hence "\<exists>a \<in> carrier (mult_of R). group.ord (mult_of R) a = d" by (auto simp: card_eq_0_iff) thus ?thesis using num_elems_of_ord_eq_phi'[OF finite d] by auto qed } hence all_le:"\<And>i. i \<in> {d. d dvd order (mult_of R) } \<Longrightarrow> (\<lambda>i. card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = i}) i \<le> (\<lambda>i. phi' i) i" by fast hence le:"(\<Sum>i | i dvd order (mult_of R). ?N i) \<le> (\<Sum>i | i dvd order (mult_of R). phi' i)" using sum_mono[of "{d . d dvd order (mult_of R)}" "\<lambda>i. card {a \<in> carrier (mult_of R). group.ord (mult_of R) a = i}"] by presburger have "order (mult_of R) = (\<Sum>d | d dvd order (mult_of R). phi' d)" using * by (simp add: sum_phi'_factors) hence eq:"(\<Sum>i | i dvd order (mult_of R). ?N i) = (\<Sum>i | i dvd order (mult_of R). phi' i)" using le sum_Ns_eq by presburger have "\<And>i. i \<in> {d. d dvd order (mult_of R) } \<Longrightarrow> ?N i = (\<lambda>i. phi' i) i" proof (rule ccontr) fix i assume i1:"i \<in> {d. d dvd order (mult_of R)}" and "?N i \<noteq> phi' i" hence "?N i = 0" using num_elems_of_ord_eq_phi'[OF finite, of i] by (auto simp: card_eq_0_iff) moreover have "0 < i" using * i1 by (simp add: dvd_nat_bounds[of "order (mult_of R)" i]) ultimately have "?N i < phi' i" using phi'_nonzero by presburger hence "(\<Sum>i | i dvd order (mult_of R). ?N i) < (\<Sum>i | i dvd order (mult_of R). phi' i)" using sum_strict_mono_ex1[OF fin, of "?N" "\<lambda> i . phi' i"] i1 all_le by auto thus False using eq by force qed hence "?N (order (mult_of R)) > 0" using * by (simp add: phi'_nonzero) then obtain a where a:"a \<in> carrier (mult_of R)" and a_ord:"group.ord (mult_of R) a = order (mult_of R)" by (auto simp add: card_gt_0_iff) hence set_eq:"{a[^]i | i::nat. i \<in> UNIV} = (\<lambda>x. a[^]x) ` {0 .. group.ord (mult_of R) a - 1}" using G.ord_elems[OF finite'] by auto have card_eq:"card ((\<lambda>x. a[^]x) ` {0 .. group.ord (mult_of R) a - 1}) = card {0 .. group.ord (mult_of R) a - 1}" by (intro card_image G.ord_inj finite' a) hence "card ((\<lambda> x . a[^]x) ` {0 .. group.ord (mult_of R) a - 1}) = card {0 ..order (mult_of R) - 1}" using assms by (simp add: card_eq a_ord) hence card_R_minus_1:"card {a[^]i | i::nat. i \<in> UNIV} = order (mult_of R)" using * by (subst set_eq) auto have **:"{a[^]i | i::nat. i \<in> UNIV} \<subseteq> carrier (mult_of R)" using G.nat_pow_closed[OF a] by auto with _ have "carrier (mult_of R) = {a[^]i|i::nat. i \<in> UNIV}" by (rule card_seteq[symmetric]) (simp_all add: card_R_minus_1 finite order_def del: UNIV_I) thus ?thesis using a by blast qed end
downloadDataFromQualtrics <- function(apiTokenFile) { # requires curl and jsonlite library(curl) library(jsonlite) apiTokenInformation <- fromJSON(paste(readLines(apiTokenFile), collapse="")) # reading in the authentication tokens and survey IDs: myAPIToken = apiTokenInformation$apiToken mySurveyID = apiTokenInformation$surveyID # constructing and sending off the "export csv" request myHandle <- new_handle() handle_setopt(myHandle, copypostfields = paste('{ \n \"surveyId\": \"', mySurveyID, '\", \n \"format\": \"csv\" \n }', sep="")); handle_setheaders(myHandle, "X-API-TOKEN" = myAPIToken, "Content-Type" = "application/json") raw_response <- curl_fetch_memory("https://yourdatacenterid.qualtrics.com/API/v3/responseexports", handle = myHandle) #print(raw_response$status_code) if(raw_response$status_code!=200) { stop(paste("There was an error issuing the export request. The request came back with status code:", raw_response$status_code, "\n")) } else { cat("Successfully issued a request to Qualtrics to export data in a csv format.\n") resultID = fromJSON(rawToChar(raw_response$content))$result$id } cat("Will wait 3 seconds for Qualtrics to export data...\n") Sys.sleep(3) # Checking to see if the exporting is done. myHandle <- new_handle() handle_setheaders(myHandle, "X-API-TOKEN" = myAPIToken, "Content-Type" = "application/json") data_url = paste('https://yourdatacenterid.qualtrics.com/API/v3/responseexports/', resultID, sep="") response_export_progress <- curl_fetch_memory(data_url, handle = myHandle) progress = fromJSON(rawToChar(response_export_progress$content))$result$percentComplete while(progress < 100) { cat(paste("Qualtrics has not finished exporting yet (at ", progress,"%). Will wait 3 seconds to try again...\n", sep="")) Sys.sleep(3) response_export_progress <- curl_fetch_memory(data_url, handle = myHandle) progress = fromJSON(rawToChar(response_export_progress$content))$result$percentComplete } # Downloading and unzipping curl_download(paste(data_url, '/file', sep=""), 'results_file.zip', handle=myHandle) cat(paste("Downloaded results file to ", getwd(), "/results_file.zip\n", sep="")) unzip("results_file.zip") outputFilename = unzip("results_file.zip", list=T)[1] cat(paste("Done unzipping the data to ", getwd(), "/", outputFilename, "\n", sep="")) # Reading in the survey file into dSurvey and returning it dSurvey = read.csv(paste(getwd(), "/", outputFilename, sep=""), header=FALSE, skip=3) variableNames = read.csv(paste(getwd(), "/", outputFilename, sep=""), header=TRUE, nrows=1) colnames(dSurvey) = colnames(variableNames) return(dSurvey) }
Formal statement is: lemma primitive_part_fract_0 [simp]: "primitive_part_fract 0 = 0" Informal statement is: The primitive part of the fractional part of $0$ is $0$.
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Scott Morrison ! This file was ported from Lean 3 source module category_theory.preadditive.yoneda.projective ! leanprover-community/mathlib commit f8d8465c3c392a93b9ed226956e26dee00975946 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.CategoryTheory.Preadditive.Yoneda.Basic import Mathbin.CategoryTheory.Preadditive.Projective import Mathbin.Algebra.Category.Group.EpiMono import Mathbin.Algebra.Category.Module.EpiMono /-! An object is projective iff the preadditive coyoneda functor on it preserves epimorphisms. -/ universe v u open Opposite namespace CategoryTheory variable {C : Type u} [Category.{v} C] section Preadditive variable [Preadditive C] namespace Projective theorem projective_iff_preservesEpimorphisms_preadditiveCoyoneda_obj (P : C) : Projective P ↔ (preadditiveCoyoneda.obj (op P)).PreservesEpimorphisms := by rw [projective_iff_preserves_epimorphisms_coyoneda_obj] refine' ⟨fun h : (preadditive_coyoneda.obj (op P) ⋙ forget _).PreservesEpimorphisms => _, _⟩ · exact functor.preserves_epimorphisms_of_preserves_of_reflects (preadditive_coyoneda.obj (op P)) (forget _) · intro exact (inferInstance : (preadditive_coyoneda.obj (op P) ⋙ forget _).PreservesEpimorphisms) #align category_theory.projective.projective_iff_preserves_epimorphisms_preadditive_coyoneda_obj CategoryTheory.Projective.projective_iff_preservesEpimorphisms_preadditiveCoyoneda_obj theorem projective_iff_preservesEpimorphisms_preadditive_coyoneda_obj' (P : C) : Projective P ↔ (preadditiveCoyonedaObj (op P)).PreservesEpimorphisms := by rw [projective_iff_preserves_epimorphisms_coyoneda_obj] refine' ⟨fun h : (preadditive_coyoneda_obj (op P) ⋙ forget _).PreservesEpimorphisms => _, _⟩ · exact functor.preserves_epimorphisms_of_preserves_of_reflects (preadditive_coyoneda_obj (op P)) (forget _) · intro exact (inferInstance : (preadditive_coyoneda_obj (op P) ⋙ forget _).PreservesEpimorphisms) #align category_theory.projective.projective_iff_preserves_epimorphisms_preadditive_coyoneda_obj' CategoryTheory.Projective.projective_iff_preservesEpimorphisms_preadditive_coyoneda_obj' end Projective end Preadditive end CategoryTheory
# How ## How to include code in markdown To include code in markdown use three ` marks followed by the name of the language: `````{tip} ```` ```<language> <code> ``` ```` ````` For example: ```` ```python import sympy as sym x = sym.Symbol("x") ``` ```` Would render as: ```python import sympy as sym x = sym.Symbol("x") ``` It is also possible to include code in markdown using an indented block: For example: ```md Here is some code: import sympy as sym x = sym.Symbol("x") ``` Would render as: --- Here is some code: import sympy as sym x = sym.Symbol("x") --- ```{attention} Using an indented block does not allow you to specify the language and can lead to mistake when combining with other nested statement. ``` ## How to write a tutorial A tutorial should include step by step instructions with expected behaviours. This should not focus on any deeper explanation. An analogy of this is teaching a young toddler to build a toy train track. They do not need to know the physics related to how the train will go through the track. They need only to see how to lay the track pieces. ## How to write a how to guide A how to guide should provide a quick and to the point description of how to solve a specific problem. An analogy of this would be a recipe. The recipe will not necessarily explain how to chop an onion and/or why we are chopping an onion it will tell you to chop an onion as a step of cooking a particular meal. ## How to write an explanation section The explanation section should provide a deeper understanding of the concepts under the code. An analogy of this again related to a recipe would be a book on the chemistry of taste and why a chopped onion adds a specific type of flavour to a meal. ## How to write a reference section The reference section should provide an overview of the specific tools, commands and indeed place for background reading as well (although this can also be referred to in the explanation section).
theory HC_Compl_Consistency imports Consistency HC begin context begin private lemma dt: "F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H G \<Longrightarrow> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<^bold>\<rightarrow> G" by (metis AX100 Deduction_theorem Un_insert_right sup_left_commute) lemma sim: "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<Longrightarrow> F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H G \<Longrightarrow> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H G" using MP dt by blast lemma sim_conj: "F \<triangleright> G \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H H \<Longrightarrow> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<Longrightarrow> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H G \<Longrightarrow> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H H" using MP dt by (metis Un_insert_left) lemma sim_disj: "\<lbrakk>F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H H; G \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H H; \<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<^bold>\<or> G\<rbrakk> \<Longrightarrow> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H H" proof goal_cases case 1 have 2: "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<^bold>\<rightarrow> H" by (simp add: 1 dt) have 3: "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H G \<^bold>\<rightarrow> H" by (simp add: 1 dt) have 4: "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H (F \<^bold>\<or> G) \<^bold>\<rightarrow> H" by (meson 2 3 HC.simps HC_intros(7) HC_mono sup_ge2) thus ?case using 1(3) MP by blast qed private lemma someax: "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<^bold>\<rightarrow> \<^bold>\<not> F \<^bold>\<rightarrow> \<bottom>" proof - have "F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> F \<^bold>\<rightarrow> F \<^bold>\<rightarrow> \<bottom>" by (meson HC_intros(12) HC_mono subset_insertI sup_ge2) then have "\<^bold>\<not> F \<triangleright> F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<bottom>" by (meson HC.simps HC_mono insertI1 subset_insertI) then show ?thesis by (metis (no_types) Un_insert_left dt) qed lemma lem: "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> F \<^bold>\<or> F" proof - thm HC_intros(7)[of F \<bottom> "Not F"] have "F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H ( \<^bold>\<not> F \<^bold>\<or> F)" by (metis AX10.intros(3) Ax HC_mono MP Un_commute Un_insert_left insertI1 sup_ge1) hence "F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> ( \<^bold>\<not> F \<^bold>\<or> F) \<^bold>\<rightarrow> \<bottom>" using someax by (metis HC.simps Un_insert_left) hence "\<^bold>\<not> ( \<^bold>\<not> F \<^bold>\<or> F) \<triangleright> F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<bottom>" by (meson Ax HC_mono MP insertI1 subset_insertI) hence "\<^bold>\<not> ( \<^bold>\<not> F \<^bold>\<or> F) \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<^bold>\<rightarrow> \<bottom>" by (metis Un_insert_left dt insert_commute) have "\<^bold>\<not>F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H ( \<^bold>\<not> F \<^bold>\<or> F)" by (metis HC.simps HC_intros(5) HC_mono inf_sup_ord(4) insertI1 insert_is_Un) hence "\<^bold>\<not>F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> ( \<^bold>\<not> F \<^bold>\<or> F) \<^bold>\<rightarrow> \<bottom>" using someax by (metis HC.simps Un_insert_left) hence "\<^bold>\<not> ( \<^bold>\<not> F \<^bold>\<or> F) \<triangleright> \<^bold>\<not>F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<bottom>" by (meson Ax HC_mono MP insertI1 subset_insertI) hence "\<^bold>\<not> ( \<^bold>\<not> F \<^bold>\<or> F) \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not>F \<^bold>\<rightarrow> \<bottom>" by (metis Un_insert_left dt insert_commute) hence "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> ( \<^bold>\<not> F \<^bold>\<or> F) \<^bold>\<rightarrow> \<bottom>" by (meson HC_intros(13) HC_mono MP \<open>\<^bold>\<not> (\<^bold>\<not> F \<^bold>\<or> F) \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<^bold>\<rightarrow> \<bottom>\<close> dt subset_insertI sup_ge2) thus ?thesis by (meson HC.simps HC_intros(13) HC_mono sup_ge2) (* apply(insert HC_mono dt HC_intros(3-)[THEN HC_mono, OF sup_ge2] sim HC.intros) sledgehammer[debug,max_facts=50,timeout=120]*) qed lemma exchg: "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H F \<^bold>\<or> G \<Longrightarrow> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H G \<^bold>\<or> F" by (meson AX10.intros(3) HC.simps HC_intros(5) HC_intros(7) HC_mono sup_ge2) lemma nor_sim: assumes "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> (F \<^bold>\<or> G)" shows "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> F" " \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> G" using HC_contrapos_nn assms by (metis HC_intros(5,6) HC_mono sup_ge2)+ lemma HC_contrapos_np: "\<lbrakk>\<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> F; \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> G \<^bold>\<rightarrow> F\<rbrakk> \<Longrightarrow> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H G" by (meson HC_intros(12) HC_intros(13) HC_mono MP sup_ge2 HC_contrapos_nn[of \<Gamma> F "Not G"]) lemma not_imp: "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> F \<^bold>\<rightarrow> F \<^bold>\<rightarrow> G" proof goal_cases case 1 have "\<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<^bold>\<not> F \<^bold>\<rightarrow> F \<^bold>\<rightarrow> \<bottom>" by (simp add: AX10.intros(9) Ax) hence "\<^bold>\<not> F \<triangleright> F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<bottom>" by (meson HC.simps HC_mono insertI1 subset_insertI) hence "\<^bold>\<not> F \<triangleright> F \<triangleright> \<Gamma> \<union> AX10 \<turnstile>\<^sub>H G" by (metis (no_types, hide_lams) Un_commute Un_insert_right inpcp) thus ?case by (metis Un_insert_left dt insert_commute) qed lemma HC_consistent: "pcp {\<Gamma>| \<Gamma>. \<not>(\<Gamma> \<union> AX10 \<turnstile>\<^sub>H \<bottom>)}" unfolding pcp_def apply(intro ballI conjI; unfold mem_Collect_eq; elim exE conjE; erule contrapos_np; clarsimp) subgoal by (simp add: HC.Ax) subgoal by (meson Ax HC_intros(12) HC_mono MP Un_upper1 sup_ge2) subgoal using sim_conj by (metis (no_types, lifting) Ax HC_intros(8) HC_intros(9) HC_mono MP sup_ge1 sup_ge2) subgoal using sim_disj using Ax by blast subgoal by (erule (1) sim_disj) (simp add: Ax imp_sim) subgoal by (metis Ax HC_contrapos_nn MP Un_iff Un_insert_left dt inpcp someax) subgoal by(erule (1) sim_disj) (simp add: Ax nand_sim) subgoal by(erule sim_conj) (meson Ax Un_iff nor_sim)+ subgoal for \<Gamma> F G apply(erule sim_conj) subgoal by (meson Ax HC_Compl_Consistency.not_imp HC_contrapos_np Un_iff) subgoal by (metis Ax HC_contrapos_nn HC_intros(3) HC_mono sup_ge1 sup_ge2) done done end corollary HC_complete: fixes F :: "'a :: countable formula" shows "\<Turnstile> F \<Longrightarrow> AX10 \<turnstile>\<^sub>H F" proof(erule contrapos_pp) let ?W = "{\<Gamma>| \<Gamma>. \<not>((\<Gamma> :: ('a :: countable) formula set) \<union> AX10 \<turnstile>\<^sub>H \<bottom>)}" note [[show_types]] assume \<open>\<not> (AX10 \<turnstile>\<^sub>H F)\<close> hence "\<not> (\<^bold>\<not>F \<triangleright> AX10 \<turnstile>\<^sub>H \<bottom>)" by (metis AX100 Deduction_theorem HC_intros(13) MP Un_insert_right) hence "{\<^bold>\<not>F} \<in> ?W" by simp with pcp_sat HC_consistent have "sat {\<^bold>\<not> F}" . thus "\<not> \<Turnstile> F" by (simp add: sat_def) qed end
[GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I ⊢ ∀ {x y : A}, x * y ∈ I → x ∈ I ∨ y ∈ I [PROOFSTEP] intro x y hxy [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I ⊢ x ∈ I ∨ y ∈ I [PROOFSTEP] by_contra rid [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid : ¬(x ∈ I ∨ y ∈ I) ⊢ False [PROOFSTEP] push_neg at rid [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid : ¬x ∈ I ∧ ¬y ∈ I ⊢ False [PROOFSTEP] obtain ⟨rid₁, rid₂⟩ := rid [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I ⊢ False [PROOFSTEP] classical /- The idea of the proof is the following : since `x * y ∈ I` and `I` homogeneous, then `proj i (x * y) ∈ I` for any `i : ι`. Then consider two sets `{i ∈ x.support | xᵢ ∉ I}` and `{j ∈ y.support | yⱼ ∉ J}`; let `max₁, max₂` be the maximum of the two sets, then `proj (max₁ + max₂) (x * y) ∈ I`. Then, `proj max₁ x ∉ I` and `proj max₂ j ∉ I` but `proj i x ∈ I` for all `max₁ < i` and `proj j y ∈ I` for all `max₂ < j`. ` proj (max₁ + max₂) (x * y)` `= ∑ {(i, j) ∈ supports | i + j = max₁ + max₂}, xᵢ * yⱼ` `= proj max₁ x * proj max₂ y` ` + ∑ {(i, j) ∈ supports \ {(max₁, max₂)} | i + j = max₁ + max₂}, xᵢ * yⱼ`. This is a contradiction, because both `proj (max₁ + max₂) (x * y) ∈ I` and the sum on the right hand side is in `I` however `proj max₁ x * proj max₂ y` is not in `I`. -/ set set₁ := (decompose 𝒜 x).support.filter (fun i => proj 𝒜 i x ∉ I) with set₁_eq set set₂ := (decompose 𝒜 y).support.filter (fun i => proj 𝒜 i y ∉ I) with set₂_eq have nonempty : ∀ x : A, x ∉ I → ((decompose 𝒜 x).support.filter (fun i => proj 𝒜 i x ∉ I)).Nonempty := by intro x hx rw [filter_nonempty_iff] contrapose! hx simp_rw [proj_apply] at hx rw [← sum_support_decompose 𝒜 x] exact Ideal.sum_mem _ hx set max₁ := set₁.max' (nonempty x rid₁) set max₂ := set₂.max' (nonempty y rid₂) have mem_max₁ : max₁ ∈ set₁ := max'_mem set₁ (nonempty x rid₁) have mem_max₂ : max₂ ∈ set₂ := max'_mem set₂ (nonempty y rid₂) replace hxy : proj 𝒜 (max₁ + max₂) (x * y) ∈ I := hI _ hxy have mem_I : proj 𝒜 max₁ x * proj 𝒜 max₂ y ∈ I := by set antidiag := ((decompose 𝒜 x).support ×ˢ (decompose 𝒜 y).support).filter (fun z : ι × ι => z.1 + z.2 = max₁ + max₂) with ha have mem_antidiag : (max₁, max₂) ∈ antidiag := by simp only [add_sum_erase, mem_filter, mem_product] exact ⟨⟨mem_of_mem_filter _ mem_max₁, mem_of_mem_filter _ mem_max₂⟩, trivial⟩ have eq_add_sum := calc proj 𝒜 (max₁ + max₂) (x * y) = ∑ ij in antidiag, proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := by simp_rw [ha, proj_apply, DirectSum.decompose_mul, DirectSum.coe_mul_apply 𝒜] _ = proj 𝒜 max₁ x * proj 𝒜 max₂ y + ∑ ij in antidiag.erase (max₁, max₂), proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := (add_sum_erase _ _ mem_antidiag).symm rw [eq_sub_of_add_eq eq_add_sum.symm] refine' Ideal.sub_mem _ hxy (Ideal.sum_mem _ fun z H => _) rcases z with ⟨i, j⟩ simp only [mem_erase, Prod.mk.inj_iff, Ne.def, mem_filter, mem_product] at H rcases H with ⟨H₁, ⟨H₂, H₃⟩, H₄⟩ have max_lt : max₁ < i ∨ max₂ < j := by rcases lt_trichotomy max₁ i with (h | rfl | h) · exact Or.inl h · refine' False.elim (H₁ ⟨rfl, add_left_cancel H₄⟩) · apply Or.inr have := add_lt_add_right h j rw [H₄] at this exact lt_of_add_lt_add_left this cases' max_lt with max_lt max_lt · -- in this case `max₁ < i`, then `xᵢ ∈ I`; for otherwise `i ∈ set₁` then `i ≤ max₁`. have not_mem : i ∉ set₁ := fun h => lt_irrefl _ ((max'_lt_iff set₁ (nonempty x rid₁)).mp max_lt i h) rw [set₁_eq] at not_mem simp only [not_and, Classical.not_not, Ne.def, mem_filter] at not_mem exact Ideal.mul_mem_right _ I (not_mem H₂) · -- in this case `max₂ < j`, then `yⱼ ∈ I`; for otherwise `j ∈ set₂`, then `j ≤ max₂`. have not_mem : j ∉ set₂ := fun h => lt_irrefl _ ((max'_lt_iff set₂ (nonempty y rid₂)).mp max_lt j h) rw [set₂_eq] at not_mem simp only [not_and, Classical.not_not, Ne.def, mem_filter] at not_mem exact Ideal.mul_mem_left I _ (not_mem H₃) have not_mem_I : proj 𝒜 max₁ x * proj 𝒜 max₂ y ∉ I := by have neither_mem : proj 𝒜 max₁ x ∉ I ∧ proj 𝒜 max₂ y ∉ I := by rw [mem_filter] at mem_max₁ mem_max₂ exact ⟨mem_max₁.2, mem_max₂.2⟩ intro _rid cases' homogeneous_mem_or_mem ⟨max₁, SetLike.coe_mem _⟩ ⟨max₂, SetLike.coe_mem _⟩ mem_I with h h · apply neither_mem.1 h · apply neither_mem.2 h exact not_mem_I mem_I [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I ⊢ False [PROOFSTEP] set set₁ := (decompose 𝒜 x).support.filter (fun i => proj 𝒜 i x ∉ I) with set₁_eq [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) ⊢ False [PROOFSTEP] set set₂ := (decompose 𝒜 y).support.filter (fun i => proj 𝒜 i y ∉ I) with set₂_eq [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) ⊢ False [PROOFSTEP] have nonempty : ∀ x : A, x ∉ I → ((decompose 𝒜 x).support.filter (fun i => proj 𝒜 i x ∉ I)).Nonempty := by intro x hx rw [filter_nonempty_iff] contrapose! hx simp_rw [proj_apply] at hx rw [← sum_support_decompose 𝒜 x] exact Ideal.sum_mem _ hx [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) ⊢ ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) [PROOFSTEP] intro x hx [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x✝ y : A hxy : x✝ * y ∈ I rid₁ : ¬x✝ ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) x : A hx : ¬x ∈ I ⊢ Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) [PROOFSTEP] rw [filter_nonempty_iff] [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x✝ y : A hxy : x✝ * y ∈ I rid₁ : ¬x✝ ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) x : A hx : ¬x ∈ I ⊢ ∃ a, a ∈ DFinsupp.support (↑(decompose 𝒜) x) ∧ ¬↑(proj 𝒜 a) x ∈ I [PROOFSTEP] contrapose! hx [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x✝ y : A hxy : x✝ * y ∈ I rid₁ : ¬x✝ ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) x : A hx : ∀ (a : ι), a ∈ DFinsupp.support (↑(decompose 𝒜) x) → ↑(proj 𝒜 a) x ∈ I ⊢ x ∈ I [PROOFSTEP] simp_rw [proj_apply] at hx [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x✝ y : A hxy : x✝ * y ∈ I rid₁ : ¬x✝ ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) x : A hx : ∀ (a : ι), a ∈ DFinsupp.support (↑(decompose 𝒜) x) → ↑(↑(↑(decompose 𝒜) x) a) ∈ I ⊢ x ∈ I [PROOFSTEP] rw [← sum_support_decompose 𝒜 x] [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x✝ y : A hxy : x✝ * y ∈ I rid₁ : ¬x✝ ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x✝ ∈ I) (DFinsupp.support (↑(decompose 𝒜) x✝)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) x : A hx : ∀ (a : ι), a ∈ DFinsupp.support (↑(decompose 𝒜) x) → ↑(↑(↑(decompose 𝒜) x) a) ∈ I ⊢ ∑ i in DFinsupp.support (↑(decompose 𝒜) x), ↑(↑(↑(decompose 𝒜) x) i) ∈ I [PROOFSTEP] exact Ideal.sum_mem _ hx [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) ⊢ False [PROOFSTEP] set max₁ := set₁.max' (nonempty x rid₁) [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ⊢ False [PROOFSTEP] set max₂ := set₂.max' (nonempty y rid₂) [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) ⊢ False [PROOFSTEP] have mem_max₁ : max₁ ∈ set₁ := max'_mem set₁ (nonempty x rid₁) [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ ⊢ False [PROOFSTEP] have mem_max₂ : max₂ ∈ set₂ := max'_mem set₂ (nonempty y rid₂) [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A hxy : x * y ∈ I rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ ⊢ False [PROOFSTEP] replace hxy : proj 𝒜 (max₁ + max₂) (x * y) ∈ I := hI _ hxy [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I ⊢ False [PROOFSTEP] have mem_I : proj 𝒜 max₁ x * proj 𝒜 max₂ y ∈ I := by set antidiag := ((decompose 𝒜 x).support ×ˢ (decompose 𝒜 y).support).filter (fun z : ι × ι => z.1 + z.2 = max₁ + max₂) with ha have mem_antidiag : (max₁, max₂) ∈ antidiag := by simp only [add_sum_erase, mem_filter, mem_product] exact ⟨⟨mem_of_mem_filter _ mem_max₁, mem_of_mem_filter _ mem_max₂⟩, trivial⟩ have eq_add_sum := calc proj 𝒜 (max₁ + max₂) (x * y) = ∑ ij in antidiag, proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := by simp_rw [ha, proj_apply, DirectSum.decompose_mul, DirectSum.coe_mul_apply 𝒜] _ = proj 𝒜 max₁ x * proj 𝒜 max₂ y + ∑ ij in antidiag.erase (max₁, max₂), proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := (add_sum_erase _ _ mem_antidiag).symm rw [eq_sub_of_add_eq eq_add_sum.symm] refine' Ideal.sub_mem _ hxy (Ideal.sum_mem _ fun z H => _) rcases z with ⟨i, j⟩ simp only [mem_erase, Prod.mk.inj_iff, Ne.def, mem_filter, mem_product] at H rcases H with ⟨H₁, ⟨H₂, H₃⟩, H₄⟩ have max_lt : max₁ < i ∨ max₂ < j := by rcases lt_trichotomy max₁ i with (h | rfl | h) · exact Or.inl h · refine' False.elim (H₁ ⟨rfl, add_left_cancel H₄⟩) · apply Or.inr have := add_lt_add_right h j rw [H₄] at this exact lt_of_add_lt_add_left this cases' max_lt with max_lt max_lt · -- in this case `max₁ < i`, then `xᵢ ∈ I`; for otherwise `i ∈ set₁` then `i ≤ max₁`. have not_mem : i ∉ set₁ := fun h => lt_irrefl _ ((max'_lt_iff set₁ (nonempty x rid₁)).mp max_lt i h) rw [set₁_eq] at not_mem simp only [not_and, Classical.not_not, Ne.def, mem_filter] at not_mem exact Ideal.mul_mem_right _ I (not_mem H₂) · -- in this case `max₂ < j`, then `yⱼ ∈ I`; for otherwise `j ∈ set₂`, then `j ≤ max₂`. have not_mem : j ∉ set₂ := fun h => lt_irrefl _ ((max'_lt_iff set₂ (nonempty y rid₂)).mp max_lt j h) rw [set₂_eq] at not_mem simp only [not_and, Classical.not_not, Ne.def, mem_filter] at not_mem exact Ideal.mul_mem_left I _ (not_mem H₃) [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I ⊢ ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I [PROOFSTEP] set antidiag := ((decompose 𝒜 x).support ×ˢ (decompose 𝒜 y).support).filter (fun z : ι × ι => z.1 + z.2 = max₁ + max₂) with ha [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ⊢ ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I [PROOFSTEP] have mem_antidiag : (max₁, max₂) ∈ antidiag := by simp only [add_sum_erase, mem_filter, mem_product] exact ⟨⟨mem_of_mem_filter _ mem_max₁, mem_of_mem_filter _ mem_max₂⟩, trivial⟩ [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ⊢ (max₁, max₂) ∈ antidiag [PROOFSTEP] simp only [add_sum_erase, mem_filter, mem_product] [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ⊢ (max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∈ DFinsupp.support (↑(decompose 𝒜) x) ∧ max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) ∈ DFinsupp.support (↑(decompose 𝒜) y)) ∧ True [PROOFSTEP] exact ⟨⟨mem_of_mem_filter _ mem_max₁, mem_of_mem_filter _ mem_max₂⟩, trivial⟩ [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag ⊢ ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I [PROOFSTEP] have eq_add_sum := calc proj 𝒜 (max₁ + max₂) (x * y) = ∑ ij in antidiag, proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := by simp_rw [ha, proj_apply, DirectSum.decompose_mul, DirectSum.coe_mul_apply 𝒜] _ = proj 𝒜 max₁ x * proj 𝒜 max₂ y + ∑ ij in antidiag.erase (max₁, max₂), proj 𝒜 ij.1 x * proj 𝒜 ij.2 y := (add_sum_erase _ _ mem_antidiag).symm [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag ⊢ ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ∑ ij in antidiag, ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y [PROOFSTEP] simp_rw [ha, proj_apply, DirectSum.decompose_mul, DirectSum.coe_mul_apply 𝒜] [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y ⊢ ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I [PROOFSTEP] rw [eq_sub_of_add_eq eq_add_sum.symm] [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y ⊢ ↑(proj 𝒜 (max₁ + max₂)) (x * y) - ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y ∈ I [PROOFSTEP] refine' Ideal.sub_mem _ hxy (Ideal.sum_mem _ fun z H => _) [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y z : ι × ι H : z ∈ erase antidiag (max₁, max₂) ⊢ ↑(proj 𝒜 z.fst) x * ↑(proj 𝒜 z.snd) y ∈ I [PROOFSTEP] rcases z with ⟨i, j⟩ [GOAL] case mk ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H : (i, j) ∈ erase antidiag (max₁, max₂) ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] simp only [mem_erase, Prod.mk.inj_iff, Ne.def, mem_filter, mem_product] at H [GOAL] case mk ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) ∧ (i ∈ DFinsupp.support (↑(decompose 𝒜) x) ∧ j ∈ DFinsupp.support (↑(decompose 𝒜) y)) ∧ i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] rcases H with ⟨H₁, ⟨H₂, H₃⟩, H₄⟩ [GOAL] case mk.intro.intro.intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] have max_lt : max₁ < i ∨ max₂ < j := by rcases lt_trichotomy max₁ i with (h | rfl | h) · exact Or.inl h · refine' False.elim (H₁ ⟨rfl, add_left_cancel H₄⟩) · apply Or.inr have := add_lt_add_right h j rw [H₄] at this exact lt_of_add_lt_add_left this [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) ⊢ max₁ < i ∨ max₂ < j [PROOFSTEP] rcases lt_trichotomy max₁ i with (h | rfl | h) [GOAL] case inl ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) h : max₁ < i ⊢ max₁ < i ∨ max₂ < j [PROOFSTEP] exact Or.inl h [GOAL] case inr.inl ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y j : ι H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) H₁ : ¬(max₁ = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : max₁ + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : max₁ ∈ DFinsupp.support (↑(decompose 𝒜) x) ⊢ max₁ < max₁ ∨ max₂ < j [PROOFSTEP] refine' False.elim (H₁ ⟨rfl, add_left_cancel H₄⟩) [GOAL] case inr.inr ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) h : i < max₁ ⊢ max₁ < i ∨ max₂ < j [PROOFSTEP] apply Or.inr [GOAL] case inr.inr.h ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) h : i < max₁ ⊢ max₂ < j [PROOFSTEP] have := add_lt_add_right h j [GOAL] case inr.inr.h ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) h : i < max₁ this : i + j < max₁ + j ⊢ max₂ < j [PROOFSTEP] rw [H₄] at this [GOAL] case inr.inr.h ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) h : i < max₁ this : max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) < max₁ + j ⊢ max₂ < j [PROOFSTEP] exact lt_of_add_lt_add_left this [GOAL] case mk.intro.intro.intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₁ < i ∨ max₂ < j ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] cases' max_lt with max_lt max_lt [GOAL] case mk.intro.intro.intro.inl ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₁ < i ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] have not_mem : i ∉ set₁ := fun h => lt_irrefl _ ((max'_lt_iff set₁ (nonempty x rid₁)).mp max_lt i h) [GOAL] case mk.intro.intro.intro.inl ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₁ < i not_mem : ¬i ∈ set₁ ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] rw [set₁_eq] at not_mem [GOAL] case mk.intro.intro.intro.inl ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₁ < i not_mem : ¬i ∈ filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] simp only [not_and, Classical.not_not, Ne.def, mem_filter] at not_mem [GOAL] case mk.intro.intro.intro.inl ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₁ < i not_mem : i ∈ DFinsupp.support (↑(decompose 𝒜) x) → ↑(proj 𝒜 i) x ∈ I ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] exact Ideal.mul_mem_right _ I (not_mem H₂) [GOAL] case mk.intro.intro.intro.inr ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₂ < j ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] have not_mem : j ∉ set₂ := fun h => lt_irrefl _ ((max'_lt_iff set₂ (nonempty y rid₂)).mp max_lt j h) [GOAL] case mk.intro.intro.intro.inr ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₂ < j not_mem : ¬j ∈ set₂ ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] rw [set₂_eq] at not_mem [GOAL] case mk.intro.intro.intro.inr ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₂ < j not_mem : ¬j ∈ filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] simp only [not_and, Classical.not_not, Ne.def, mem_filter] at not_mem [GOAL] case mk.intro.intro.intro.inr ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I antidiag : Finset (ι × ι) := filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) ha : antidiag = filter (fun z => z.fst + z.snd = max₁ + max₂) (DFinsupp.support (↑(decompose 𝒜) x) ×ˢ DFinsupp.support (↑(decompose 𝒜) y)) mem_antidiag : (max₁, max₂) ∈ antidiag eq_add_sum : ↑(proj 𝒜 (max₁ + max₂)) (x * y) = ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y + ∑ ij in erase antidiag (max₁, max₂), ↑(proj 𝒜 ij.fst) x * ↑(proj 𝒜 ij.snd) y i j : ι H₁ : ¬(i = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) ∧ j = max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))))) H₄ : i + j = max' (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) + max' (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y))) (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) H₂ : i ∈ DFinsupp.support (↑(decompose 𝒜) x) H₃ : j ∈ DFinsupp.support (↑(decompose 𝒜) y) max_lt : max₂ < j not_mem : j ∈ DFinsupp.support (↑(decompose 𝒜) y) → ↑(proj 𝒜 j) y ∈ I ⊢ ↑(proj 𝒜 (i, j).fst) x * ↑(proj 𝒜 (i, j).snd) y ∈ I [PROOFSTEP] exact Ideal.mul_mem_left I _ (not_mem H₃) [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I ⊢ False [PROOFSTEP] have not_mem_I : proj 𝒜 max₁ x * proj 𝒜 max₂ y ∉ I := by have neither_mem : proj 𝒜 max₁ x ∉ I ∧ proj 𝒜 max₂ y ∉ I := by rw [mem_filter] at mem_max₁ mem_max₂ exact ⟨mem_max₁.2, mem_max₂.2⟩ intro _rid cases' homogeneous_mem_or_mem ⟨max₁, SetLike.coe_mem _⟩ ⟨max₂, SetLike.coe_mem _⟩ mem_I with h h · apply neither_mem.1 h · apply neither_mem.2 h [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I ⊢ ¬↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I [PROOFSTEP] have neither_mem : proj 𝒜 max₁ x ∉ I ∧ proj 𝒜 max₂ y ∉ I := by rw [mem_filter] at mem_max₁ mem_max₂ exact ⟨mem_max₁.2, mem_max₂.2⟩ [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I ⊢ ¬↑(proj 𝒜 max₁) x ∈ I ∧ ¬↑(proj 𝒜 max₂) y ∈ I [PROOFSTEP] rw [mem_filter] at mem_max₁ mem_max₂ [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ DFinsupp.support (↑(decompose 𝒜) x) ∧ ¬↑(proj 𝒜 max₁) x ∈ I mem_max₂ : max₂ ∈ DFinsupp.support (↑(decompose 𝒜) y) ∧ ¬↑(proj 𝒜 max₂) y ∈ I hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I ⊢ ¬↑(proj 𝒜 max₁) x ∈ I ∧ ¬↑(proj 𝒜 max₂) y ∈ I [PROOFSTEP] exact ⟨mem_max₁.2, mem_max₂.2⟩ [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I neither_mem : ¬↑(proj 𝒜 max₁) x ∈ I ∧ ¬↑(proj 𝒜 max₂) y ∈ I ⊢ ¬↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I [PROOFSTEP] intro _rid [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I neither_mem : ¬↑(proj 𝒜 max₁) x ∈ I ∧ ¬↑(proj 𝒜 max₂) y ∈ I _rid : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I ⊢ False [PROOFSTEP] cases' homogeneous_mem_or_mem ⟨max₁, SetLike.coe_mem _⟩ ⟨max₂, SetLike.coe_mem _⟩ mem_I with h h [GOAL] case inl ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I neither_mem : ¬↑(proj 𝒜 max₁) x ∈ I ∧ ¬↑(proj 𝒜 max₂) y ∈ I _rid : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I h : ↑(↑(AddMonoidHom.comp (DFinsupp.evalAddMonoidHom max₁) (RingHom.toAddMonoidHom (RingEquiv.toRingHom (decomposeRingEquiv 𝒜)))) x) ∈ I ⊢ False [PROOFSTEP] apply neither_mem.1 h [GOAL] case inr ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I neither_mem : ¬↑(proj 𝒜 max₁) x ∈ I ∧ ¬↑(proj 𝒜 max₂) y ∈ I _rid : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I h : ↑(↑(AddMonoidHom.comp (DFinsupp.evalAddMonoidHom max₂) (RingHom.toAddMonoidHom (RingEquiv.toRingHom (decomposeRingEquiv 𝒜)))) y) ∈ I ⊢ False [PROOFSTEP] apply neither_mem.2 h [GOAL] case intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I I_ne_top : I ≠ ⊤ homogeneous_mem_or_mem : ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ I → x ∈ I ∨ y ∈ I x y : A rid₁ : ¬x ∈ I rid₂ : ¬y ∈ I set₁ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₁_eq : set₁ = filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)) set₂ : Finset ι := filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) set₂_eq : set₂ = filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)) nonempty : ∀ (x : A), ¬x ∈ I → Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x))) max₁ : ι := max' set₁ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) x ∈ I) (DFinsupp.support (↑(decompose 𝒜) x)))) max₂ : ι := max' set₂ (_ : Finset.Nonempty (filter (fun i => ¬↑(proj 𝒜 i) y ∈ I) (DFinsupp.support (↑(decompose 𝒜) y)))) mem_max₁ : max₁ ∈ set₁ mem_max₂ : max₂ ∈ set₂ hxy : ↑(proj 𝒜 (max₁ + max₂)) (x * y) ∈ I mem_I : ↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I not_mem_I : ¬↑(proj 𝒜 max₁) x * ↑(proj 𝒜 max₂) y ∈ I ⊢ False [PROOFSTEP] exact not_mem_I mem_I [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsPrime I ⊢ IsPrime (HomogeneousIdeal.toIdeal (Ideal.homogeneousCore 𝒜 I)) [PROOFSTEP] apply (Ideal.homogeneousCore 𝒜 I).is_homogeneous'.isPrime_of_homogeneous_mem_or_mem [GOAL] case I_ne_top ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsPrime I ⊢ (Ideal.homogeneousCore 𝒜 I).toSubmodule ≠ ⊤ [PROOFSTEP] exact ne_top_of_le_ne_top h.ne_top (Ideal.toIdeal_homogeneousCore_le 𝒜 I) [GOAL] case homogeneous_mem_or_mem ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsPrime I ⊢ ∀ {x y : A}, Homogeneous 𝒜 x → Homogeneous 𝒜 y → x * y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule → x ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule ∨ y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule [PROOFSTEP] rintro x y hx hy hxy [GOAL] case homogeneous_mem_or_mem ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsPrime I x y : A hx : Homogeneous 𝒜 x hy : Homogeneous 𝒜 y hxy : x * y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule ⊢ x ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule ∨ y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule [PROOFSTEP] have H := h.mem_or_mem (Ideal.toIdeal_homogeneousCore_le 𝒜 I hxy) [GOAL] case homogeneous_mem_or_mem ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsPrime I x y : A hx : Homogeneous 𝒜 x hy : Homogeneous 𝒜 y hxy : x * y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule H : x ∈ I ∨ y ∈ I ⊢ x ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule ∨ y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule [PROOFSTEP] refine' H.imp _ _ [GOAL] case homogeneous_mem_or_mem.refine'_1 ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsPrime I x y : A hx : Homogeneous 𝒜 x hy : Homogeneous 𝒜 y hxy : x * y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule H : x ∈ I ∨ y ∈ I ⊢ x ∈ I → x ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule [PROOFSTEP] exact Ideal.mem_homogeneousCore_of_homogeneous_of_mem hx [GOAL] case homogeneous_mem_or_mem.refine'_2 ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsPrime I x y : A hx : Homogeneous 𝒜 x hy : Homogeneous 𝒜 y hxy : x * y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule H : x ∈ I ∨ y ∈ I ⊢ y ∈ I → y ∈ (Ideal.homogeneousCore 𝒜 I).toSubmodule [PROOFSTEP] exact Ideal.mem_homogeneousCore_of_homogeneous_of_mem hy [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I ⊢ radical I = InfSet.sInf {J | IsHomogeneous 𝒜 J ∧ I ≤ J ∧ IsPrime J} [PROOFSTEP] rw [Ideal.radical_eq_sInf] [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I ⊢ InfSet.sInf {J | I ≤ J ∧ IsPrime J} = InfSet.sInf {J | IsHomogeneous 𝒜 J ∧ I ≤ J ∧ IsPrime J} [PROOFSTEP] apply le_antisymm [GOAL] case a ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I ⊢ InfSet.sInf {J | I ≤ J ∧ IsPrime J} ≤ InfSet.sInf {J | IsHomogeneous 𝒜 J ∧ I ≤ J ∧ IsPrime J} [PROOFSTEP] exact sInf_le_sInf fun J => And.right [GOAL] case a ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I ⊢ InfSet.sInf {J | IsHomogeneous 𝒜 J ∧ I ≤ J ∧ IsPrime J} ≤ InfSet.sInf {J | I ≤ J ∧ IsPrime J} [PROOFSTEP] refine sInf_le_sInf_of_forall_exists_le ?_ [GOAL] case a ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I ⊢ ∀ (x : Ideal A), x ∈ {J | I ≤ J ∧ IsPrime J} → ∃ y, y ∈ {J | IsHomogeneous 𝒜 J ∧ I ≤ J ∧ IsPrime J} ∧ y ≤ x [PROOFSTEP] rintro J ⟨HJ₁, HJ₂⟩ [GOAL] case a.intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I J : Ideal A HJ₁ : I ≤ J HJ₂ : IsPrime J ⊢ ∃ y, y ∈ {J | IsHomogeneous 𝒜 J ∧ I ≤ J ∧ IsPrime J} ∧ y ≤ J [PROOFSTEP] refine ⟨(J.homogeneousCore 𝒜).toIdeal, ?_, J.toIdeal_homogeneousCore_le _⟩ [GOAL] case a.intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I J : Ideal A HJ₁ : I ≤ J HJ₂ : IsPrime J ⊢ HomogeneousIdeal.toIdeal (homogeneousCore 𝒜 J) ∈ {J | IsHomogeneous 𝒜 J ∧ I ≤ J ∧ IsPrime J} [PROOFSTEP] refine ⟨HomogeneousIdeal.isHomogeneous _, ?_, HJ₂.homogeneousCore⟩ [GOAL] case a.intro ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A hI : IsHomogeneous 𝒜 I J : Ideal A HJ₁ : I ≤ J HJ₂ : IsPrime J ⊢ I ≤ HomogeneousIdeal.toIdeal (homogeneousCore 𝒜 J) [PROOFSTEP] exact hI.toIdeal_homogeneousCore_eq_self.symm.trans_le (Ideal.homogeneousCore_mono _ HJ₁) [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsHomogeneous 𝒜 I ⊢ IsHomogeneous 𝒜 (Ideal.radical I) [PROOFSTEP] rw [h.radical_eq] [GOAL] ι : Type u_1 σ : Type u_2 A : Type u_3 inst✝⁴ : CommRing A inst✝³ : LinearOrderedCancelAddCommMonoid ι inst✝² : SetLike σ A inst✝¹ : AddSubmonoidClass σ A 𝒜 : ι → σ inst✝ : GradedRing 𝒜 I : Ideal A h : IsHomogeneous 𝒜 I ⊢ IsHomogeneous 𝒜 (InfSet.sInf {J | IsHomogeneous 𝒜 J ∧ I ≤ J ∧ IsPrime J}) [PROOFSTEP] exact Ideal.IsHomogeneous.sInf fun _ => And.left
function varargout = mul_const(x, h, der_y) % x is [m1, m2, p, b] % h is [m1, m2] % der_y is same size as x if nargin < 3 der_y = []; end if isempty(der_y) y = bsxfun(@times, x, h); varargout = {y}; else der_x = bsxfun(@times, der_y, h); der_h = sum(sum(der_y .* x, 3), 4); varargout = {der_x, der_h}; end end
module Main main : JS_IO () main = putStr' $ show $ take 5 $ repeat 1
# -*- coding: utf-8 -*- import numpy as np import lightgbm as lgb import matplotlib.pyplot as plt from time import time from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split from joblib import dump from dataset_split import DataSplit test_m = 5000 test_n = 100000 X_train, _, y_train, _ = DataSplit().split_dataset( test_malicious=test_m, test_normal=test_n) """ X_train, X_test, y_train, y_test = train_test_split( X_train, y_train, test_size=0.1, random_state=1024) """ train_size = len(y_train) train_m = sum(y_train) train_n = train_size - train_m print(">>> Train set: M=%d, N=%d" % (train_m, train_n)) """ test_size = len(y_test) test_m = sum(y_test) test_n = test_size - test_m print(">>> Test set: M=%d, N=%d" % (test_m, test_n)) """ model = RandomForestClassifier( n_estimators=100, max_depth=30, random_state=1024) # train and evaluate t0 = time() model.fit(X_train, y_train) t1 = time() print(">>> training time: ", t1 - t0) dump(model, 'RandomForestClassifier.joblib')
[STATEMENT] lemma t_ins_invariance: assumes XY: "Y \<in> t_ins_set X" and X: "t_ins_inv x xt X" shows "t_ins_inv x xt Y" [PROOF STATE] proof (prove) goal (1 subgoal): 1. t_ins_inv x xt Y [PROOF STEP] using XY [[simproc del: defined_all]] [PROOF STATE] proof (prove) using this: Y \<in> t_ins_set X goal (1 subgoal): 1. t_ins_inv x xt Y [PROOF STEP] proof (rule t_ins_set.induct, simp_all split del: if_split) [PROOF STATE] proof (state) goal (6 subgoals): 1. Y \<in> t_ins_set X \<Longrightarrow> t_ins_inv x xt X 2. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 5. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 6. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "t_ins_inv x xt X" [PROOF STATE] proof (prove) goal (1 subgoal): 1. t_ins_inv x xt X [PROOF STEP] using X [PROOF STATE] proof (prove) using this: t_ins_inv x xt X goal (1 subgoal): 1. t_ins_inv x xt X [PROOF STEP] . [PROOF STATE] proof (state) this: t_ins_inv x xt X goal (5 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 5. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (5 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 5. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix z :: "'a::linorder" and y yl yr ts [PROOF STATE] proof (state) goal (5 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 5. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume "z = x \<and> (\<forall>n \<in> {..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))))" (is "_ \<and> (\<forall>n \<in> {..<Suc (length ts)}. ?P n)") [PROOF STATE] proof (state) this: z = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (5 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 5. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I: "\<forall>n \<in> {..<Suc (length ts)}. ?P n" [PROOF STATE] proof (prove) using this: z = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (5 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 5. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume xy: "x \<le> y" [PROOF STATE] proof (state) this: x \<le> y goal (5 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 5. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "\<forall>n \<in> {..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))" (is "\<forall>n \<in> {..<Suc (Suc (length ts))}. ?Q n") [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (Suc (length ts))} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix n [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (Suc (length ts))} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume n: "n \<in> {..<Suc (Suc (length ts))}" [PROOF STATE] proof (state) this: n \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (Suc (length ts))} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "?Q n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (cases n) [PROOF STATE] proof (state) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case 0 [PROOF STATE] proof (state) this: n = 0 goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "0 \<in> {..<Suc (length ts)}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. 0 \<in> {..<Suc (length ts)} [PROOF STEP] by simp [PROOF STATE] proof (state) this: 0 \<in> {..<Suc (length ts)} goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (length ts)} [PROOF STEP] have "?P 0" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (length ts)} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. ts ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. ts ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. ts ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] by (simp add: Let_def xy 0) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case (Suc m) [PROOF STATE] proof (state) this: n = Suc m goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence "m \<in> {..<Suc (length ts)}" [PROOF STATE] proof (prove) using this: n = Suc m goal (1 subgoal): 1. m \<in> {..<Suc (length ts)} [PROOF STEP] using n [PROOF STATE] proof (prove) using this: n = Suc m n \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. m \<in> {..<Suc (length ts)} [PROOF STEP] by simp [PROOF STATE] proof (state) this: m \<in> {..<Suc (length ts)} goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) m \<in> {..<Suc (length ts)} [PROOF STEP] have "?P m" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) m \<in> {..<Suc (length ts)} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! m)) \<and> (0 < m \<longrightarrow> (\<exists>y' yl' yr'. ts ! (m - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! m) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! m) then t_multiset (t_left (ts' ! Suc m)) else t_multiset (t_right (ts' ! Suc m)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! m)) \<and> (0 < m \<longrightarrow> (\<exists>y' yl' yr'. ts ! (m - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! m) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! m) then t_multiset (t_left (ts' ! Suc m)) else t_multiset (t_right (ts' ! Suc m)))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! m)) \<and> (0 < m \<longrightarrow> (\<exists>y' yl' yr'. ts ! (m - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! m) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! m) then t_multiset (t_left (ts' ! Suc m)) else t_multiset (t_right (ts' ! Suc m)))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (simp add: Let_def Suc) [PROOF STATE] proof (state) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! m)) \<and> (0 < m \<longrightarrow> (\<exists>y' yl' yr'. ts ! (m - Suc 0) = Branch y' yl' yr')) \<and> t_multiset ((Branch y yl yr # ts) ! m) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! m) then t_multiset (t_left ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc m)) else t_multiset (t_right ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc m))) \<Longrightarrow> \<exists>y' yl' yr'. (Branch y yl yr # ts) ! m = Branch y' yl' yr' [PROOF STEP] qed (cases m, simp_all) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yl # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yl # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yl # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (4 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (4 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix z :: "'a::linorder" and y yl yr ts [PROOF STATE] proof (state) goal (4 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume "z = x \<and> (\<forall>n \<in> {..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))))" (is "_ \<and> (\<forall>n \<in> {..<Suc (length ts)}. ?P n)") [PROOF STATE] proof (state) this: z = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (4 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I: "\<forall>n \<in> {..<Suc (length ts)}. ?P n" [PROOF STATE] proof (prove) using this: z = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (4 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume xy: "\<not> x \<le> y" [PROOF STATE] proof (state) this: \<not> x \<le> y goal (4 subgoals): 1. \<And>xa y yl yr ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 4. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "\<forall>n \<in> {..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))" (is "\<forall>n \<in> {..<Suc (Suc (length ts))}. ?Q n") [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (Suc (length ts))} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix n [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (Suc (length ts))} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume n: "n \<in> {..<Suc (Suc (length ts))}" [PROOF STATE] proof (state) this: n \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (Suc (length ts))} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "?Q n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (cases n) [PROOF STATE] proof (state) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case 0 [PROOF STATE] proof (state) this: n = 0 goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "0 \<in> {..<Suc (length ts)}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. 0 \<in> {..<Suc (length ts)} [PROOF STEP] by simp [PROOF STATE] proof (state) this: 0 \<in> {..<Suc (length ts)} goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (length ts)} [PROOF STEP] have "?P 0" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (length ts)} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. ts ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. ts ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. ts ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] by (simp add: Let_def xy 0) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case (Suc m) [PROOF STATE] proof (state) this: n = Suc m goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence "m \<in> {..<Suc (length ts)}" [PROOF STATE] proof (prove) using this: n = Suc m goal (1 subgoal): 1. m \<in> {..<Suc (length ts)} [PROOF STEP] using n [PROOF STATE] proof (prove) using this: n = Suc m n \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. m \<in> {..<Suc (length ts)} [PROOF STEP] by simp [PROOF STATE] proof (state) this: m \<in> {..<Suc (length ts)} goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) m \<in> {..<Suc (length ts)} [PROOF STEP] have "?P m" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) m \<in> {..<Suc (length ts)} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! m)) \<and> (0 < m \<longrightarrow> (\<exists>y' yl' yr'. ts ! (m - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! m) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! m) then t_multiset (t_left (ts' ! Suc m)) else t_multiset (t_right (ts' ! Suc m)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! m)) \<and> (0 < m \<longrightarrow> (\<exists>y' yl' yr'. ts ! (m - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! m) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! m) then t_multiset (t_left (ts' ! Suc m)) else t_multiset (t_right (ts' ! Suc m)))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! m)) \<and> (0 < m \<longrightarrow> (\<exists>y' yl' yr'. ts ! (m - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl yr # ts) ! m) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! m) then t_multiset (t_left (ts' ! Suc m)) else t_multiset (t_right (ts' ! Suc m)))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (simp add: Let_def Suc) [PROOF STATE] proof (state) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl yr # ts) ! m)) \<and> (0 < m \<longrightarrow> (\<exists>y' yl' yr'. ts ! (m - Suc 0) = Branch y' yl' yr')) \<and> t_multiset ((Branch y yl yr # ts) ! m) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! m) then t_multiset (t_left ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc m)) else t_multiset (t_right ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc m))) \<Longrightarrow> \<exists>y' yl' yr'. (Branch y yl yr # ts) ! m = Branch y' yl' yr' [PROOF STEP] qed (cases m, simp_all) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((yr # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = yr # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((yr # Branch y yl yr # ts) ! n) = (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (3 subgoals): 1. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (3 subgoals): 1. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix z :: 'a and ts [PROOF STATE] proof (state) goal (3 subgoals): 1. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume "z = x \<and> (\<forall>n \<in> {..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))))" (is "_ \<and> (\<forall>n \<in> {..<Suc (length ts)}. ?P n)") [PROOF STATE] proof (state) this: z = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (3 subgoals): 1. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I: "\<forall>n \<in> {..<Suc (length ts)}. ?P n" [PROOF STATE] proof (prove) using this: z = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (3 subgoals): 1. \<And>xa ts. \<lbrakk>\<lparr>t_type.folding = False, item = x, subtrees = Leaf # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 3. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "\<forall>n \<in> {..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))" (is "\<forall>n \<in> {..<Suc (length ts)}. ?Q n") [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix n [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume n: "n \<in> {..<Suc (length ts)}" [PROOF STATE] proof (state) this: n \<in> {..<Suc (length ts)} goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "?Q n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (cases n) [PROOF STATE] proof (state) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case 0 [PROOF STATE] proof (state) this: n = 0 goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "0 \<in> {..<Suc (length ts)}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. 0 \<in> {..<Suc (length ts)} [PROOF STEP] by simp [PROOF STATE] proof (state) this: 0 \<in> {..<Suc (length ts)} goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (length ts)} [PROOF STEP] have "?P 0" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (length ts)} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y yl yr. ts ! (0 - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y yl yr. ts ! (0 - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y yl yr. ts ! (0 - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! 0) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] by (simp add: Let_def 0 split: if_split_asm) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case (Suc m) [PROOF STATE] proof (state) this: n = Suc m goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "?P n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] using I and n [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) n \<in> {..<Suc (length ts)} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((Leaf # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Leaf # ts) ! n) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] by (simp add: Let_def Suc) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch x Leaf Leaf # ts) ! n)) \<and> (let ts' = Branch x Leaf Leaf # ts @ [Branch x xt Leaf] in t_multiset ((Branch x Leaf Leaf # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (2 subgoals): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (2 subgoals): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix z :: 'a and zt y yl yr ts [PROOF STATE] proof (state) goal (2 subgoals): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume "z = x \<and> (\<forall>n \<in> {..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))))" (is "_ \<and> (\<forall>n \<in> {..<Suc (Suc (length ts))}. ?P n)") [PROOF STATE] proof (state) this: z = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (2 subgoals): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I: "\<forall>n \<in> {..<Suc (Suc (length ts))}. ?P n" [PROOF STATE] proof (prove) using this: z = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (2 subgoals): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume xy: "x \<le> y" [PROOF STATE] proof (state) this: x \<le> y goal (2 subgoals): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y xta yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y xta yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y xta yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "\<forall>n \<in> {..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))" (is "\<forall>n \<in> {..<Suc (length ts)}. ?Q n") [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix n [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume n: "n \<in> {..<Suc (length ts)}" [PROOF STATE] proof (state) this: n \<in> {..<Suc (length ts)} goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "?Q n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (cases n) [PROOF STATE] proof (state) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case 0 [PROOF STATE] proof (state) this: n = 0 goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "0 \<in> {..<Suc (Suc (length ts))}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. 0 \<in> {..<Suc (Suc (length ts))} [PROOF STEP] by simp [PROOF STATE] proof (state) this: 0 \<in> {..<Suc (Suc (length ts))} goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (Suc (length ts))} [PROOF STEP] have "?P 0" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! 0) = (if 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! 0) = (if 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I0: "(t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yl" [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! 0) = (if 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yl [PROOF STEP] by (simp add: Let_def xy) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yl goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "Suc 0 \<in> {..<Suc (Suc (length ts))}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Suc 0 \<in> {..<Suc (Suc (length ts))} [PROOF STEP] by simp [PROOF STATE] proof (state) this: Suc 0 \<in> {..<Suc (Suc (length ts))} goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) Suc 0 \<in> {..<Suc (Suc (length ts))} [PROOF STEP] have "?P (Suc 0)" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) Suc 0 \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc 0)) \<and> (0 < Suc 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc 0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc 0) = (if Suc 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc 0) then t_multiset (t_left (ts' ! Suc (Suc 0))) else t_multiset (t_right (ts' ! Suc (Suc 0))))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc 0)) \<and> (0 < Suc 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc 0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc 0) = (if Suc 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc 0) then t_multiset (t_left (ts' ! Suc (Suc 0))) else t_multiset (t_right (ts' ! Suc (Suc 0))))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I1: "(t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)))" [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc 0)) \<and> (0 < Suc 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc 0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc 0) = (if Suc 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc 0) then t_multiset (t_left (ts' ! Suc (Suc 0))) else t_multiset (t_right (ts' ! Suc (Suc 0))))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] by (simp add: Let_def) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (simp add: Let_def 0 del: t_sorted.simps split del: if_split, rule conjI, simp_all add: Let_def 0 del: t_sorted.simps, rule_tac [2] conjI, rule_tac [!] impI) [PROOF STATE] proof (state) goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y zt yr) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] assume s: "t_sorted xt" [PROOF STATE] proof (state) this: t_sorted xt goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y zt yr) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] hence "t_sorted zt" [PROOF STATE] proof (prove) using this: t_sorted xt goal (1 subgoal): 1. t_sorted zt [PROOF STEP] using I0 [PROOF STATE] proof (prove) using this: t_sorted xt (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yl goal (1 subgoal): 1. t_sorted zt [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_sorted zt goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y zt yr) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] moreover [PROOF STATE] proof (state) this: t_sorted zt goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y zt yr) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] have "t_sorted (Branch y yl yr)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. t_sorted (Branch y yl yr) [PROOF STEP] using I1 and s [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) t_sorted xt goal (1 subgoal): 1. t_sorted (Branch y yl yr) [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_sorted (Branch y yl yr) goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y zt yr) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] moreover [PROOF STATE] proof (state) this: t_sorted (Branch y yl yr) goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y zt yr) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] have "t_set zt = {x} \<union> t_set yl" [PROOF STATE] proof (prove) goal (1 subgoal): 1. t_set zt = {x} \<union> t_set yl [PROOF STEP] using I0 [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yl goal (1 subgoal): 1. t_set zt = {x} \<union> t_set yl [PROOF STEP] by (simp add: t_set_multiset) [PROOF STATE] proof (state) this: t_set zt = {x} \<union> t_set yl goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y zt yr) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: t_sorted zt t_sorted (Branch y yl yr) t_set zt = {x} \<union> t_set yl [PROOF STEP] show "t_sorted (Branch y zt yr)" [PROOF STATE] proof (prove) using this: t_sorted zt t_sorted (Branch y yl yr) t_set zt = {x} \<union> t_set yl goal (1 subgoal): 1. t_sorted (Branch y zt yr) [PROOF STEP] using xy [PROOF STATE] proof (prove) using this: t_sorted zt t_sorted (Branch y yl yr) t_set zt = {x} \<union> t_set yl x \<le> y goal (1 subgoal): 1. t_sorted (Branch y zt yr) [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_sorted (Branch y zt yr) goal (2 subgoals): 1. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 2. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] next [PROOF STATE] proof (state) goal (2 subgoals): 1. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 2. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] assume "x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0)" [PROOF STATE] proof (state) this: x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) goal (2 subgoals): 1. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 2. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] hence "t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr)" [PROOF STATE] proof (prove) using this: x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) goal (1 subgoal): 1. t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) [PROOF STEP] using I1 [PROOF STATE] proof (prove) using this: x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) goal (1 subgoal): 1. t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) goal (2 subgoals): 1. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 2. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] thus "add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)))" [PROOF STATE] proof (prove) using this: t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) goal (1 subgoal): 1. add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] using I0 [PROOF STATE] proof (prove) using this: t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yl goal (1 subgoal): 1. add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] by simp [PROOF STATE] proof (state) this: add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) goal (1 subgoal): 1. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] assume "\<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0)" [PROOF STATE] proof (state) this: \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) goal (1 subgoal): 1. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] hence "t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr)" [PROOF STATE] proof (prove) using this: \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) goal (1 subgoal): 1. t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) [PROOF STEP] using I1 [PROOF STATE] proof (prove) using this: \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) goal (1 subgoal): 1. t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) goal (1 subgoal): 1. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] thus "add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)))" [PROOF STATE] proof (prove) using this: t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) goal (1 subgoal): 1. add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] using I0 [PROOF STATE] proof (prove) using this: t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yl goal (1 subgoal): 1. add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] by simp [PROOF STATE] proof (state) this: add_mset y (t_multiset zt + t_multiset yr) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case (Suc m) [PROOF STATE] proof (state) this: n = Suc m goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "Suc n \<in> {..<Suc (Suc (length ts))}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Suc n \<in> {..<Suc (Suc (length ts))} [PROOF STEP] using n [PROOF STATE] proof (prove) using this: n \<in> {..<Suc (length ts)} goal (1 subgoal): 1. Suc n \<in> {..<Suc (Suc (length ts))} [PROOF STEP] by simp [PROOF STATE] proof (state) this: Suc n \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) Suc n \<in> {..<Suc (Suc (length ts))} [PROOF STEP] have "?P (Suc n)" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) Suc n \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc n)) \<and> (0 < Suc n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc n) = (if Suc n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc n) then t_multiset (t_left (ts' ! Suc (Suc n))) else t_multiset (t_right (ts' ! Suc (Suc n))))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc n)) \<and> (0 < Suc n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc n) = (if Suc n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc n) then t_multiset (t_left (ts' ! Suc (Suc n))) else t_multiset (t_right (ts' ! Suc (Suc n))))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc n)) \<and> (0 < Suc n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc n) = (if Suc n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc n) then t_multiset (t_left (ts' ! Suc (Suc n))) else t_multiset (t_right (ts' ! Suc (Suc n))))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] by (simp add: Let_def Suc) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y zt yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y zt yr # ts @ [Branch x xt Leaf] in t_multiset ((Branch y zt yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix z :: 'a and zt y yl yr ts [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume "z = x \<and> (\<forall>n \<in> {..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))))" (is "_ \<and> (\<forall>n \<in> {..<Suc (Suc (length ts))}. ?P n)") [PROOF STATE] proof (state) this: z = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (1 subgoal): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I: "\<forall>n \<in> {..<Suc (Suc (length ts))}. ?P n" [PROOF STATE] proof (prove) using this: z = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume xy: "\<not> x \<le> y" [PROOF STATE] proof (state) this: \<not> x \<le> y goal (1 subgoal): 1. \<And>xa xta y yl yr ts. \<lbrakk>\<lparr>t_type.folding = True, item = x, subtrees = xta # Branch y yl yr # ts\<rparr> \<in> t_ins_set X; xa = x \<and> (\<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((xta # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>ya yla yra. (Branch y yl yr # ts) ! (n - Suc 0) = Branch ya yla yra)) \<and> (let ts' = xta # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((xta # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))); \<not> x \<le> y; Y \<in> t_ins_set X\<rbrakk> \<Longrightarrow> \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl xta # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y yl yr. ts ! (n - Suc 0) = Branch y yl yr)) \<and> (let ts' = Branch y yl xta # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl xta # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "\<forall>n \<in> {..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n))))" (is "\<forall>n \<in> {..<Suc (length ts)}. ?Q n") [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] fix n [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] assume n: "n \<in> {..<Suc (length ts)}" [PROOF STATE] proof (state) this: n \<in> {..<Suc (length ts)} goal (1 subgoal): 1. \<And>n. n \<in> {..<Suc (length ts)} \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show "?Q n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (cases n) [PROOF STATE] proof (state) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case 0 [PROOF STATE] proof (state) this: n = 0 goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "0 \<in> {..<Suc (Suc (length ts))}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. 0 \<in> {..<Suc (Suc (length ts))} [PROOF STEP] by simp [PROOF STATE] proof (state) this: 0 \<in> {..<Suc (Suc (length ts))} goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (Suc (length ts))} [PROOF STEP] have "?P 0" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 0 \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! 0) = (if 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! 0) = (if 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I0: "(t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yr" [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! 0)) \<and> (0 < 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! 0) = (if 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left (ts' ! Suc 0)) else t_multiset (t_right (ts' ! Suc 0)))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yr [PROOF STEP] by (simp add: Let_def xy) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yr goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "Suc 0 \<in> {..<Suc (Suc (length ts))}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Suc 0 \<in> {..<Suc (Suc (length ts))} [PROOF STEP] by simp [PROOF STATE] proof (state) this: Suc 0 \<in> {..<Suc (Suc (length ts))} goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) Suc 0 \<in> {..<Suc (Suc (length ts))} [PROOF STEP] have "?P (Suc 0)" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) Suc 0 \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc 0)) \<and> (0 < Suc 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc 0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc 0) = (if Suc 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc 0) then t_multiset (t_left (ts' ! Suc (Suc 0))) else t_multiset (t_right (ts' ! Suc (Suc 0))))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc 0)) \<and> (0 < Suc 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc 0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc 0) = (if Suc 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc 0) then t_multiset (t_left (ts' ! Suc (Suc 0))) else t_multiset (t_right (ts' ! Suc (Suc 0))))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] hence I1: "(t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)))" [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc 0)) \<and> (0 < Suc 0 \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc 0 - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc 0) = (if Suc 0 = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc 0) then t_multiset (t_left (ts' ! Suc (Suc 0))) else t_multiset (t_right (ts' ! Suc (Suc 0))))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] by (simp add: Let_def) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) goal (2 subgoals): 1. n = 0 \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) 2. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] proof (simp add: Let_def 0 del: t_sorted.simps split del: if_split, rule conjI, simp_all add: Let_def 0 del: t_sorted.simps, rule_tac [2] conjI, rule_tac [!] impI) [PROOF STATE] proof (state) goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y yl zt) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] assume s: "t_sorted xt" [PROOF STATE] proof (state) this: t_sorted xt goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y yl zt) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] hence "t_sorted zt" [PROOF STATE] proof (prove) using this: t_sorted xt goal (1 subgoal): 1. t_sorted zt [PROOF STEP] using I0 [PROOF STATE] proof (prove) using this: t_sorted xt (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yr goal (1 subgoal): 1. t_sorted zt [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_sorted zt goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y yl zt) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] moreover [PROOF STATE] proof (state) this: t_sorted zt goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y yl zt) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] have "t_sorted (Branch y yl yr)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. t_sorted (Branch y yl yr) [PROOF STEP] using I1 and s [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) t_sorted xt goal (1 subgoal): 1. t_sorted (Branch y yl yr) [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_sorted (Branch y yl yr) goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y yl zt) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] moreover [PROOF STATE] proof (state) this: t_sorted (Branch y yl yr) goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y yl zt) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] have "t_set zt = {x} \<union> t_set yr" [PROOF STATE] proof (prove) goal (1 subgoal): 1. t_set zt = {x} \<union> t_set yr [PROOF STEP] using I0 [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yr goal (1 subgoal): 1. t_set zt = {x} \<union> t_set yr [PROOF STEP] by (simp add: t_set_multiset) [PROOF STATE] proof (state) this: t_set zt = {x} \<union> t_set yr goal (3 subgoals): 1. t_sorted xt \<Longrightarrow> t_sorted (Branch y yl zt) 2. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 3. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: t_sorted zt t_sorted (Branch y yl yr) t_set zt = {x} \<union> t_set yr [PROOF STEP] show "t_sorted (Branch y yl zt)" [PROOF STATE] proof (prove) using this: t_sorted zt t_sorted (Branch y yl yr) t_set zt = {x} \<union> t_set yr goal (1 subgoal): 1. t_sorted (Branch y yl zt) [PROOF STEP] using xy [PROOF STATE] proof (prove) using this: t_sorted zt t_sorted (Branch y yl yr) t_set zt = {x} \<union> t_set yr \<not> x \<le> y goal (1 subgoal): 1. t_sorted (Branch y yl zt) [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_sorted (Branch y yl zt) goal (2 subgoals): 1. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 2. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] next [PROOF STATE] proof (state) goal (2 subgoals): 1. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 2. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] assume "x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0)" [PROOF STATE] proof (state) this: x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) goal (2 subgoals): 1. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 2. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] hence "t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr)" [PROOF STATE] proof (prove) using this: x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) goal (1 subgoal): 1. t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) [PROOF STEP] using I1 [PROOF STATE] proof (prove) using this: x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) goal (1 subgoal): 1. t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) goal (2 subgoals): 1. x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) 2. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] thus "add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)))" [PROOF STATE] proof (prove) using this: t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) goal (1 subgoal): 1. add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] using I0 [PROOF STATE] proof (prove) using this: t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yr goal (1 subgoal): 1. add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] by simp [PROOF STATE] proof (state) this: add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0))) goal (1 subgoal): 1. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] assume "\<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0)" [PROOF STATE] proof (state) this: \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) goal (1 subgoal): 1. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] hence "t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr)" [PROOF STATE] proof (prove) using this: \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) goal (1 subgoal): 1. t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) [PROOF STEP] using I1 [PROOF STATE] proof (prove) using this: \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) (t_sorted xt \<longrightarrow> t_sorted (Branch y yl yr)) \<and> t_multiset (Branch y yl yr) = (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) then t_multiset (t_left ((ts @ [Branch x xt Leaf]) ! 0)) else t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) goal (1 subgoal): 1. t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) [PROOF STEP] by simp [PROOF STATE] proof (state) this: t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) goal (1 subgoal): 1. \<not> x \<le> t_val ((ts @ [Branch x xt Leaf]) ! 0) \<Longrightarrow> add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] thus "add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)))" [PROOF STATE] proof (prove) using this: t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) goal (1 subgoal): 1. add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] using I0 [PROOF STATE] proof (prove) using this: t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0)) = t_multiset (Branch y yl yr) (t_sorted xt \<longrightarrow> t_sorted zt) \<and> t_multiset zt = {#x#} + t_multiset yr goal (1 subgoal): 1. add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) [PROOF STEP] by simp [PROOF STATE] proof (state) this: add_mset y (t_multiset yl + t_multiset zt) = add_mset x (t_multiset (t_right ((ts @ [Branch x xt Leaf]) ! 0))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] case (Suc m) [PROOF STATE] proof (state) this: n = Suc m goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] have "Suc n \<in> {..<Suc (Suc (length ts))}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Suc n \<in> {..<Suc (Suc (length ts))} [PROOF STEP] using n [PROOF STATE] proof (prove) using this: n \<in> {..<Suc (length ts)} goal (1 subgoal): 1. Suc n \<in> {..<Suc (Suc (length ts))} [PROOF STEP] by simp [PROOF STATE] proof (state) this: Suc n \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] with I [PROOF STATE] proof (chain) picking this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) Suc n \<in> {..<Suc (Suc (length ts))} [PROOF STEP] have "?P (Suc n)" [PROOF STATE] proof (prove) using this: \<forall>n\<in>{..<Suc (Suc (length ts))}. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) Suc n \<in> {..<Suc (Suc (length ts))} goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc n)) \<and> (0 < Suc n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc n) = (if Suc n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc n) then t_multiset (t_left (ts' ! Suc (Suc n))) else t_multiset (t_right (ts' ! Suc (Suc n))))) [PROOF STEP] .. [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc n)) \<and> (0 < Suc n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc n) = (if Suc n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc n) then t_multiset (t_left (ts' ! Suc (Suc n))) else t_multiset (t_right (ts' ! Suc (Suc n))))) goal (1 subgoal): 1. \<And>nat. n = Suc nat \<Longrightarrow> (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: (t_sorted xt \<longrightarrow> t_sorted ((zt # Branch y yl yr # ts) ! Suc n)) \<and> (0 < Suc n \<longrightarrow> (\<exists>y' yl' yr'. (Branch y yl yr # ts) ! (Suc n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = zt # Branch y yl yr # ts @ [Branch x xt Leaf] in t_multiset ((zt # Branch y yl yr # ts) ! Suc n) = (if Suc n = 0 then {#x#} else {#}) + (if x \<le> t_val ((Branch y yl yr # ts @ [Branch x xt Leaf]) ! Suc n) then t_multiset (t_left (ts' ! Suc (Suc n))) else t_multiset (t_right (ts' ! Suc (Suc n))))) goal (1 subgoal): 1. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) [PROOF STEP] by (simp add: Let_def Suc) [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: \<forall>n\<in>{..<Suc (length ts)}. (t_sorted xt \<longrightarrow> t_sorted ((Branch y yl zt # ts) ! n)) \<and> (0 < n \<longrightarrow> (\<exists>y' yl' yr'. ts ! (n - Suc 0) = Branch y' yl' yr')) \<and> (let ts' = Branch y yl zt # ts @ [Branch x xt Leaf] in t_multiset ((Branch y yl zt # ts) ! n) = (if n = 0 then {#x#} else {#}) + (if x \<le> t_val ((ts @ [Branch x xt Leaf]) ! n) then t_multiset (t_left (ts' ! Suc n)) else t_multiset (t_right (ts' ! Suc n)))) goal: No subgoals! [PROOF STEP] qed
The interpretation of the poll is not accurate as everyone has their different preference of coach. Try Crean versus Alford and see where Collins/Marshall/Miller fans fall?!?!
#ifndef __GSL_BLOCK_H__ #define __GSL_BLOCK_H__ #if !defined( GSL_FUN ) # if !defined( GSL_DLL ) # define GSL_FUN extern # elif defined( BUILD_GSL_DLL ) # define GSL_FUN extern __declspec(dllexport) # else # define GSL_FUN extern __declspec(dllimport) # endif #endif #include <gsl/gsl_block_complex_long_double.h> #include <gsl/gsl_block_complex_double.h> #include <gsl/gsl_block_complex_float.h> #include <gsl/gsl_block_long_double.h> #include <gsl/gsl_block_double.h> #include <gsl/gsl_block_float.h> #include <gsl/gsl_block_ulong.h> #include <gsl/gsl_block_long.h> #include <gsl/gsl_block_uint.h> #include <gsl/gsl_block_int.h> #include <gsl/gsl_block_ushort.h> #include <gsl/gsl_block_short.h> #include <gsl/gsl_block_uchar.h> #include <gsl/gsl_block_char.h> #endif /* __GSL_BLOCK_H__ */
[STATEMENT] lemma unbounded_nat_set_infinite: assumes \<open>\<forall> (i::nat). \<exists> j\<ge>i. j \<in> A\<close> shows \<open>\<not> finite A\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. infinite A [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: \<forall>i. \<exists>j\<ge>i. j \<in> A goal (1 subgoal): 1. infinite A [PROOF STEP] by (metis finite_nat_set_iff_bounded_le not_less_eq_eq)
proposition\<^marker>\<open>tag unimportant\<close> homeomorphism_moving_points_exists: fixes S :: "'a::euclidean_space set" assumes 2: "2 \<le> DIM('a)" "open S" "connected S" "S \<subseteq> T" "finite K" and KS: "\<And>i. i \<in> K \<Longrightarrow> x i \<in> S \<and> y i \<in> S" and pw: "pairwise (\<lambda>i j. (x i \<noteq> x j) \<and> (y i \<noteq> y j)) K" and S: "S \<subseteq> T" "T \<subseteq> affine hull S" "connected S" obtains f g where "homeomorphism T T f g" "\<And>i. i \<in> K \<Longrightarrow> f(x i) = y i" "{x. \<not> (f x = x \<and> g x = x)} \<subseteq> S" "bounded {x. (\<not> (f x = x \<and> g x = x))}"
/- Copyright 2022 ACL & MIdFF-/ import algebra.module.graded_module section direct_sum universes u v w variables {ι : Type v} [decidable_eq ι] section mk variables {β : ι → Type w} [Π (i : ι), add_comm_monoid (β i)] lemma direct_sum.mk_apply_of_mem {s : finset ι} {f : Π (i : (↑s : set ι)), β i.val} {n : ι} (hn : n ∈ s): direct_sum.mk β s f n = f ⟨n, hn⟩ := by simp only [direct_sum.mk, add_monoid_hom.coe_mk, dfinsupp.mk_apply, dif_pos hn] lemma direct_sum.mk_apply_of_not_mem {s : finset ι} {f : Π (i : (↑s : set ι)), β i.val} {n : ι} (hn : n ∉ s): direct_sum.mk β s f n = 0 := by simp only [direct_sum.mk, add_monoid_hom.coe_mk, dfinsupp.mk_apply, dif_neg hn] end mk section internal variables {M : Type w} [decidable_eq M] [add_comm_monoid M] lemma direct_sum.coe_add_monoid_hom_eq_dfinsupp_sum {M : Type w} [decidable_eq M] [add_comm_monoid M] (A : ι → add_submonoid M) (x : direct_sum ι (λ i, A i)) : direct_sum.coe_add_monoid_hom A x = dfinsupp.sum x (λ i, coe):= by simp only [direct_sum.coe_add_monoid_hom, direct_sum.to_add_monoid, dfinsupp.lift_add_hom, add_equiv.coe_mk, dfinsupp.sum_add_hom_apply, add_submonoid_class.coe_subtype] lemma direct_sum.coe_linear_map_eq_dfinsupp_sum {R : Type u} [semiring R] [module R M] (A : ι → submodule R M) (x : direct_sum ι (λ i, A i)) : direct_sum.coe_linear_map A x = dfinsupp.sum x (λ i, coe):= by simp only [direct_sum.coe_linear_map, direct_sum.to_module, dfinsupp.lsum, linear_equiv.coe_mk, linear_map.coe_mk, dfinsupp.sum_add_hom_apply, linear_map.to_add_monoid_hom_coe, submodule.coe_subtype] lemma direct_sum.support_subset (A : ι → add_submonoid M) (x : direct_sum ι (λ i, A i)) : function.support (λ i, (x i : M)) ⊆ ↑(dfinsupp.support x) := begin intro m, rw [function.mem_support, finset.mem_coe, dfinsupp.mem_support_to_fun, not_imp_not], intro hm', rw [hm', add_submonoid.coe_zero], end lemma direct_sum.support_subset_submodule (R : Type*) [comm_semiring R] [module R M] (A : ι → submodule R M) (x : direct_sum ι (λ i, A i)) : function.support (λ i, (x i : M)) ⊆ ↑(dfinsupp.support x) := begin intro m, rw [function.mem_support, finset.mem_coe, dfinsupp.mem_support_to_fun, not_imp_not], intro hm', simp only [hm', submodule.coe_zero], end lemma direct_sum.finite_support (A : ι → add_submonoid M) (x : direct_sum ι (λ i, A i)) : (function.support (λ i, (x i : M))).finite := set.finite.subset (dfinsupp.support x : set ι).to_finite (direct_sum.support_subset _ x) end internal end direct_sum section theorem linear_map.map_finsum {α R S M N : Type*} [semiring R] [semiring S] (σ : R →+* S) [add_comm_monoid M] [add_comm_monoid N] [module R M] [module S N] {f : α → M} (g : M →ₛₗ[σ] N) (hf : (function.support f).finite) : g (finsum (λ (i : α), f i)) = finsum (λ (i : α), g (f i)) := begin rw ← linear_map.to_add_monoid_hom_coe, exact add_monoid_hom.map_finsum _ hf, end end noncomputable theory section direct_sum open direct_sum /- Given an R-algebra A and a family (ι → submodule R A) of submodules parameterized by an additive monoid and statisfying `set_like.graded_monoid M` (essentially, is multiplicative) such that `direct_sum.is_internal M` (A is the direct sum of the M i), we endow A with the structure of a graded algebra. The submodules are the *homogeneous* parts -/ variables (R : Type*) [comm_semiring R] (A : Type*) [comm_semiring A] [algebra R A] variables (ι : Type*) [decidable_eq ι] variables (M : ι → submodule R A) [add_monoid ι] [set_like.graded_monoid M] variables {R A ι M} -- The following lines were given on Zulip by Adam Topaz def direct_sum.is_internal.coe_alg_iso (hM : direct_sum.is_internal M) : direct_sum ι (λ i, ↥(M i)) ≃ₐ[R] A := { commutes' := λ r, by simp, ..(ring_equiv.of_bijective (direct_sum.coe_alg_hom M) hM) } def direct_sum.is_internal.graded_algebra (hM : direct_sum.is_internal M) : graded_algebra M := { decompose' := hM.coe_alg_iso.symm, -- (coe_alg_iso_of_is_internal hM).symm, left_inv := hM.coe_alg_iso.symm.left_inv, -- (coe_alg_iso_of_is_internal hM).symm.left_inv, right_inv := hM.coe_alg_iso.left_inv, -- (coe_alg_iso_of_is_internal hM).left_inv, ..(infer_instance : set_like.graded_monoid M) } def direct_sum.decomposition.graded_algebra (dM : direct_sum.decomposition M) : graded_algebra M := { to_decomposition := dM, ..(infer_instance : set_like.graded_monoid M) } end direct_sum #exit section weighted_homogeneous /- Here, given a weight `w : σ → M`, where `M` is an additive and commutative monoid, we endow the ring of multivariate polynomials `mv_polynomial σ R` with the structure of a graded algebra -/ variables {R : Type*} [comm_semiring R] variables {M : Type*} [add_comm_monoid M] [decidable_eq M] variables {σ : Type*} variable (w : σ → M) namespace mv_polynomial lemma weighted_homogeneous_component_mem (w : σ → M) (φ : mv_polynomial σ R) (m : M) : weighted_homogeneous_component R w m φ ∈ weighted_homogeneous_submodule R w m := begin rw mem_weighted_homogeneous_submodule, exact weighted_homogeneous_component_is_weighted_homogeneous m φ, end /- lemma toto (p : Prop) [decidable p] (u v : M) : (ite p u v = u) ↔ (¬ p → u = v) := begin by_cases hp : p, simp only [hp, if_true, eq_self_iff_true, not_true, is_empty.forall_iff], simp only [hp, if_false, not_false_iff, forall_true_left], exact comm, end -/ lemma decompose'_aux (φ : mv_polynomial σ R) (i : M) (hi : i ∉ finset.image (weighted_degree' w) φ.support) : weighted_homogeneous_component R w i φ = 0 := begin apply weighted_homogeneous_component_eq_zero', simp only [finset.mem_image, mem_support_iff, ne.def, exists_prop, not_exists, not_and] at hi, intros m hm, apply hi m, rw mem_support_iff at hm, exact hm, end /- lemma decompose'_aux' (φ : mv_polynomial σ R) (i : M) : ite (i ∈ finset.image (weighted_degree' w) φ.support) ((weighted_homogeneous_component R w i) φ) 0 = (weighted_homogeneous_component R w i) φ := begin split_ifs with hi hi, refl, rw decompose'_aux w φ i hi, end -/ variable (R) def decompose'_fun := λ (φ : mv_polynomial σ R), direct_sum.mk (λ (i : M), ↥(weighted_homogeneous_submodule R w i)) (finset.image (weighted_degree' w) φ.support) (λ m, ⟨weighted_homogeneous_component R w m φ, weighted_homogeneous_component_mem w φ m⟩) lemma decompose'_fun_apply (φ : mv_polynomial σ R) (m : M): (decompose'_fun R w φ m : mv_polynomial σ R) = weighted_homogeneous_component R w m φ := begin rw decompose'_fun, by_cases hm : m ∈ finset.image (weighted_degree' w) φ.support, simp only [direct_sum.mk_apply_of_mem hm, subtype.coe_mk], rw [direct_sum.mk_apply_of_not_mem hm, submodule.coe_zero, decompose'_aux w φ m hm], end instance [decidable_eq σ] [decidable_eq R] : Π (i : M) (x : ↥(weighted_homogeneous_submodule R w i)), decidable (x ≠ 0) := begin intros m x, rw [ne.def, ← set_like.coe_eq_coe], apply_instance, end -- Rewrite direct_sum.coe_linear_map lemma direct_sum.coe_linear_map_eq_support_sum [decidable_eq σ] [decidable_eq R] (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) : ((direct_sum.coe_linear_map (λ (i : M), weighted_homogeneous_submodule R w i)) x) = dfinsupp.sum x (λ m, coe) := begin rw direct_sum.coe_linear_map_eq_dfinsupp_sum, -- WEIRD: this is not yet finished simp only [dfinsupp.sum], apply finset.sum_congr, ext m, simp only [dfinsupp.mem_support_iff], intros m hm, refl, end -- Rewrite direct_sum.coe_add_monoid_hom lemma direct_sum.coe_add_monoid_hom_eq_support_sum [decidable_eq σ] [decidable_eq R] (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) : ((direct_sum.coe_add_monoid_hom (λ (i : M), weighted_homogeneous_submodule R w i)) x) = dfinsupp.sum x (λ m, coe) := direct_sum.coe_linear_map_eq_support_sum R w x -- Variants for finsum lemma direct_sum.coe_linear_map_eq_finsum [decidable_eq σ] [decidable_eq R] (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) /- [h_dec : Π (i : M) (x : ↥(weighted_homogeneous_submodule R w i)), decidable (x ≠ 0)] -/: ((direct_sum.coe_linear_map (λ (i : M), weighted_homogeneous_submodule R w i)) x) = finsum (λ m, x m) := begin rw [direct_sum.coe_linear_map_eq_support_sum, dfinsupp.sum], rw finsum_eq_sum_of_support_subset, -- direct_sum.support_subset ne marche pas… intro m, rw [function.mem_support, finset.mem_coe, dfinsupp.mem_support_to_fun, not_imp_not], intro hm', rw [hm', submodule.coe_zero], end lemma direct_sum.coe_add_monoid_hom_eq_finsum [decidable_eq σ] [decidable_eq R] (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) /- [h_dec : Π (i : M) (x : ↥(weighted_homogeneous_submodule R w i)), decidable (x ≠ 0)] -/: ((direct_sum.coe_add_monoid_hom (λ (i : M), weighted_homogeneous_submodule R w i)) x) = finsum (λ m, x m) := direct_sum.coe_linear_map_eq_finsum R w x -- TODO: move to weighted_homogeneous file lemma weighted_homogeneous_component_weighted_homogeneous_polynomial' (m : M) (x : weighted_homogeneous_submodule R w m) : (weighted_homogeneous_component R w m) ↑x = x := by rw [weighted_homogeneous_component_weighted_homogeneous_polynomial m m _ x.prop, if_pos rfl] lemma weighted_homogeneous_component_direct_sum [decidable_eq σ] [decidable_eq R] (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) (m : M) : (weighted_homogeneous_component R w m) ((direct_sum.coe_linear_map (λ (i : M), weighted_homogeneous_submodule R w i)) x) = x m := begin rw [direct_sum.coe_linear_map_eq_dfinsupp_sum], rw dfinsupp.sum, rw map_sum, rw finset.sum_eq_single m, { rw weighted_homogeneous_component_of_weighted_homogeneous_polynomial_same, rw ← mem_weighted_homogeneous_submodule, exact (x m).prop, }, { intros n hn hmn, rw weighted_homogeneous_component_of_weighted_homogeneous_polynomial_other, rw ← mem_weighted_homogeneous_submodule, exact (x n).prop, exact ne.symm hmn, }, { rw dfinsupp.not_mem_support_iff, intro hm, rw [hm, submodule.coe_zero, map_zero], }, end def mv_polynomial_weighted_decomposition [decidable_eq σ] [decidable_eq R] : direct_sum.decomposition (weighted_homogeneous_submodule R w) := { decompose' := decompose'_fun R w, left_inv := λ φ, begin conv_rhs { rw [← sum_weighted_homogeneous_component w φ], }, rw ← direct_sum.sum_support_of (λ m, ↥(weighted_homogeneous_submodule R w m)) (decompose'_fun R w φ), simp only [direct_sum.coe_add_monoid_hom_of, mv_polynomial.coeff_sum, map_sum], apply congr_arg2, { ext m, simp only [dfinsupp.mem_support_to_fun, ne.def, set.finite.mem_to_finset, function.mem_support, not_iff_not], conv_lhs { rw ← subtype.coe_inj }, rw [decompose'_fun_apply, submodule.coe_zero], }, { apply funext, intro m, rw decompose'_fun_apply, }, end, right_inv := λ x, begin apply dfinsupp.ext, intro m, rw ← subtype.coe_inj, rw decompose'_fun_apply, change (weighted_homogeneous_component R w m) ((direct_sum.coe_linear_map (weighted_homogeneous_submodule R w)) x) = ↑(x m), rw direct_sum.coe_linear_map_eq_dfinsupp_sum, rw dfinsupp.sum, rw map_sum, rw finset.sum_eq_single m, { rw weighted_homogeneous_component_of_weighted_homogeneous_polynomial_same, exact (x m).prop, }, { intros n hn hmn, rw weighted_homogeneous_component_of_weighted_homogeneous_polynomial_other, exact (x n).prop, exact ne.symm hmn, }, { intro hm, rw dfinsupp.not_mem_support_iff at hm, simp only [hm, submodule.coe_zero, map_zero], }, end } /-- mv_polynomial as a graded algebra, for an arbitrary weight -/ def mv_polynomial_weighted_graded_algebra [decidable_eq σ] [decidable_eq R] : graded_algebra (weighted_homogeneous_submodule R w) := { to_decomposition := mv_polynomial_weighted_decomposition R w, to_graded_monoid := infer_instance, } end mv_polynomial end weighted_homogeneous #exit --Unused draft below /- import algebra.free_algebra import algebra.ring_quot import algebra.triv_sq_zero_ext import algebra.algebra.operations import linear_algebra.multilinear.basic import ring_theory.graded_algebra.basic import ring_theory.tensor_product import divided_powers.basic import divided_powers.ideal_add import ..weighted_homogeneous -- PR #17855 -/ section /- Here, the goal is to define a graded_algebra structure on mv_polynomial with respect to a given degree map…  For the moment, I am stuck. -/ variables (R : Type*) [semiring R] variables (ι : Type*) [decidable_eq ι] {M : ι → Type* } [Π (i : ι), add_comm_monoid (M i)] [Π (i : ι), module R (M i)] variables {N : Type*} [add_comm_monoid N] [module R N] lemma yala (g : Π (i : ι), N →ₗ[R] M i) (hg : ∀ n, {i | g i n ≠ 0}.finite) (h : Π (i : ι), M i →ₗ[R] N) (n : N) : (direct_sum.to_module R ι N h) (direct_sum.mk M (hg n).to_finset (λ i, g i n)) = finsum (λ i, h i (g i n)) := begin classical, suffices : (function.support ((λ (i : ι), (h i) ((g i) n)) ∘ plift.down)).finite, let s := { i | g i n ≠ 0}, unfold finsum, rw dif_pos this, unfold direct_sum.mk,dsimp, end example (f : ℕ →+ ℕ) (a : ι →₀ ℕ) : f (finsupp.sum a (λ i m, m)) = finsupp.sum (finsupp.map_range f (f.map_zero) a) (λ i m, m) := begin rw map_finsupp_sum, rw finsupp.sum_map_range_index, intro i, refl, end example (f : ℕ →+ ℕ) (a : ι → ℕ) (ha : (function.support a).finite): f (finsum a) = finsum (λ i, f (a i)) := add_monoid_hom.map_finsum f ha #check yala end /-! The divided power algebra of a module -/ open finset mv_polynomial ring_quot section graded_algebra /- The mv_polynomial algebra with a degree, as a graded algebra -/ namespace mv_polynomial variables {R M : Type*} [comm_semiring R] [add_comm_monoid M] [decidable_eq M] variables {σ : Type*} variable (w : σ → M) #check weighted_degree' def w_degree : (σ →₀ ℕ) → M := λ p, finsupp.sum p (λ s n, n • (w s)) /- def weighted_degrees' (w : σ → M) (s : finset (σ →₀ ℕ)) : finset M := finset.image (weighted_degree' w) s -/ lemma weighted_homogeneous_component_mem (w : σ → M) (φ : mv_polynomial σ R) (m : M) : weighted_homogeneous_component w m φ ∈ weighted_homogeneous_submodule R w m := begin rw mem_weighted_homogeneous_submodule, exact weighted_homogeneous_component_is_weighted_homogeneous m φ, end example (s : finset ℕ) : s = ∅ ↔ s ⊆ ∅ := begin rw [← finset.bot_eq_empty, eq_bot_iff, le_iff_subset], end lemma decompose'_aux (φ : mv_polynomial σ R) (i : M) : ite (i ∈ finset.image (weighted_degree' w) φ.support) ((weighted_homogeneous_component w i) φ) 0 = (weighted_homogeneous_component w i) φ := begin split_ifs with hi hi, refl, apply symm, apply weighted_homogeneous_component_eq_zero', simp only [mem_image, mem_support_iff, ne.def, exists_prop, not_exists, not_and] at hi, intros m hm, apply hi m, rw mem_support_iff at hm, exact hm, end variable (R) /-- The linear map from polynomials to the direct sum of the homogeneous components -/ def decompose' : mv_polynomial σ R →ₗ[R] direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i)) := { to_fun := λ φ, direct_sum.mk (λ (i : M), ↥(weighted_homogeneous_submodule R w i)) (finset.image (weighted_degree' w) φ.support) (λ m, ⟨weighted_homogeneous_component w m φ, weighted_homogeneous_component_mem w φ m⟩), map_add' := λ φ ψ, begin rw dfinsupp.ext_iff, simp only [direct_sum.mk], intro i, dsimp, rw ← subtype.coe_inj, rw submodule.coe_add, simp only [apply_ite coe, subtype.coe_mk, submodule.coe_zero], simp only [decompose'_aux], rw [map_add], end, map_smul' := begin intros a φ, rw dfinsupp.ext_iff, simp only [direct_sum.mk], intro i, dsimp, rw ← subtype.coe_inj, rw submodule.coe_smul, simp only [apply_ite coe, subtype.coe_mk, submodule.coe_zero], simp only [decompose'_aux], rw [map_smul], end } #check decompose' def decompose'_fun : mv_polynomial σ R → direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i)) := λ φ, direct_sum.mk (λ (i : M), ↥(weighted_homogeneous_submodule R w i)) (finset.image (weighted_degree' w) φ.support) (λ m, ⟨weighted_homogeneous_component w m φ, weighted_homogeneous_component_mem w φ m⟩) fintype lemma decompose'_fun_coe_apply (φ : mv_polynomial σ R) (m : M) : (decompose'_fun R w φ m : mv_polynomial σ R) = weighted_homogeneous_component w m φ := begin simp only [decompose'_fun], -- simp only [direct_sum.mk, dfinsupp.mk_apply], simp only [direct_sum.mk, subtype.coe_mk, add_monoid_hom.coe_mk, dfinsupp.mk_apply, apply_dite coe, dite_eq_ite], exact decompose'_aux w φ m, end lemma decompose'_add' : ∀ (φ ψ : mv_polynomial σ R), decompose'_fun R w (φ + ψ) = decompose'_fun R w φ + decompose'_fun R w ψ := begin intros φ ψ, simp only [decompose'_fun], rw dfinsupp.ext_iff, simp only [direct_sum.mk], intro i, simp only [add_monoid_hom.coe_mk, dfinsupp.mk_apply], dsimp, rw ← subtype.coe_inj, rw submodule.coe_add, simp only [apply_dite coe, subtype.coe_mk, submodule.coe_zero, dite_eq_ite], simp only [decompose'_aux], rw [map_add], end lemma decompose'_map_zero' : decompose'_fun R w 0 = 0 := begin simp only [decompose'_fun], rw dfinsupp.ext_iff, simp only [direct_sum.mk], intro i, simp only [mem_image, mem_support_iff, coeff_zero, ne.def, eq_self_iff_true, not_true, is_empty.exists_iff, exists_false, not_false_iff, add_monoid_hom.coe_mk, dfinsupp.mk_apply, dif_neg, direct_sum.zero_apply], end lemma direct_sum_one_coeffs (i : M) : (((1 : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) i) : mv_polynomial σ R) = ite (i = 0) (1 : mv_polynomial σ R) (0 : mv_polynomial σ R) := begin conv_lhs { dsimp [has_one.one], }, split_ifs, rw h, rw direct_sum.of_eq_same, refl, rw direct_sum.of_eq_of_ne, refl, exact ne.symm h, end lemma decompose'_map_one' : decompose'_fun R w 1 = 1 := begin classical, simp only [decompose'_fun], rw dfinsupp.ext_iff, simp only [direct_sum.mk], intro i, simp only [subtype.coe_mk, add_monoid_hom.coe_mk, dfinsupp.mk_apply], rw ← subtype.coe_inj, simp only [apply_dite coe, subtype.coe_mk, submodule.coe_zero, dite_eq_ite], simp only [decompose'_aux], rw direct_sum_one_coeffs, rw weighted_homogeneous_component_weighted_homogeneous_polynomial, swap, apply is_weighted_homogeneous_one, by_cases hi : i = 0, rw [if_pos, if_pos], exact hi, exact hi, rw [if_neg hi, if_neg], exact hi, end lemma decompose'_map_mul' : ∀ (φ ψ : mv_polynomial σ R), decompose'_fun R w (φ * ψ) = decompose'_fun R w φ * decompose'_fun R w ψ := begin sorry, end /-- The alg_hom map from polynomials to the direct sum of the homogeneous components -/ def decompose'a : mv_polynomial σ R →ₐ[R] direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i)) := { to_fun := λ φ, direct_sum.mk (λ (i : M), ↥(weighted_homogeneous_submodule R w i)) (finset.image (weighted_degree' w) φ.support) (λ m, ⟨weighted_homogeneous_component w m φ, weighted_homogeneous_component_mem w φ m⟩), map_add' := decompose'_add' R w, /- map_smul' := begin intros a φ, rw dfinsupp.ext_iff, simp only [direct_sum.mk], intro i, dsimp, rw ← subtype.coe_inj, rw submodule.coe_smul, simp only [apply_ite coe, subtype.coe_mk, submodule.coe_zero], simp only [decompose'_aux], rw [map_smul], end, -/ map_mul' := begin intros φ ψ, rw dfinsupp.ext_iff, simp only [direct_sum.mk], intro i, -- dsimp, rw ← subtype.coe_inj, sorry, /- rw submodule.coe_mul, simp only [apply_ite coe, subtype.coe_mk, submodule.coe_zero], simp only [decompose'_aux], rw [map_mul], -/ end, map_one' := decompose'_map_one' R w, map_zero' := decompose'_map_zero' R w, commutes' := sorry } /- Better approach : this will work! -/ lemma is_internal_direct_sum_of_weighted_homogeneous_submodules : direct_sum.is_internal (weighted_homogeneous_submodule R w) := begin classical, split, { -- injectivity intros p q, intro hpq, rw mv_polynomial.ext_iff at hpq, ext, specialize hpq m, rw [← direct_sum.sum_support_of _ p, ← direct_sum.sum_support_of _ q ] at hpq, simp only [map_sum, direct_sum.coe_add_monoid_hom_of, mv_polynomial.coeff_sum] at hpq, by_cases hi : weighted_degree' w m = i, { suffices this : ∀ (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) (c : M), c ≠ i → coeff m ((x c) : mv_polynomial σ R) = 0, suffices this' : ∀ (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))), i ∉ dfinsupp.support x → coeff m ((x i) : mv_polynomial σ R) = 0, rw [finset.sum_eq_single i, finset.sum_eq_single i] at hpq, exact hpq, exact λ b hb, this q b, exact this' q, exact λ b hb, this p b, exact this' p, { intros x hx, simp only [dfinsupp.mem_support_to_fun, not_not] at hx, rw hx, exact mv_polynomial.coeff_zero m, }, { intros x b hbi, apply is_weighted_homogeneous.coeff_eq_zero _ m, rw hi, exact ne.symm hbi, rw ← mem_weighted_homogeneous_submodule, exact (x b).prop, } }, rw is_weighted_homogeneous.coeff_eq_zero (p i).prop m hi, rw is_weighted_homogeneous.coeff_eq_zero (q i).prop m hi, }, { -- surjectivity intro φ, use decompose'_fun R w φ, conv_lhs { rw ← direct_sum.sum_support_of _ (decompose'_fun R w φ) }, simp only [map_sum, direct_sum.coe_add_monoid_hom_of], simp_rw decompose'_fun_coe_apply, conv_rhs { rw ← sum_weighted_homogeneous_component w φ}, rw finsum_eq_sum _ (weighted_homogeneous_component_finsupp φ), apply congr_arg2 _ _ rfl, ext m, rw [dfinsupp.mem_support_to_fun, ne.def, set.finite.mem_to_finset, function.mem_support, not_iff_not], conv_lhs { rw [← subtype.coe_inj, decompose'_fun_coe_apply, submodule.coe_zero], } }, end def graded_polynomial_algebra : graded_algebra (weighted_homogeneous_submodule R w) := graded_algebra.of_alg_hom (weighted_homogeneous_submodule R w) (decompose'a R w) (sorry) (sorry) end mv_polynomial end graded_algebra
import data.equiv.basic import group_theory.subgroup universes u v section open tactic interactive (parse loc.wildcard) interactive.types (location) lean.parser (many ident) run_cmd mk_simp_attr `with_zero_simp meta def tactic.with_zero_cases : list expr → tactic unit | (h::t) := seq (induction h [] (some `with_zero.cases_on) >> skip) $ tactic.with_zero_cases t | [] := do try (interactive.norm_cast loc.wildcard), try (tactic.interactive.simp_core {} assumption ff [] [`with_zero_simp] loc.wildcard), try (do exfalso, assumption) /-- Case bashing for with_zero. If `x₁, ... x_n` have type `with_zero α` then `with_zero cases x₁ ... x_n` will split according to whether each `x_i` is zero or coerced from `α` then run `norm_cast at *`, try to simplify using the simp rules `with_zero_simp`, and try to get a contradiction. -/ meta def tactic.interactive.with_zero_cases (l : parse $ many ident) := l.mmap tactic.get_local >>= tactic.with_zero_cases end namespace with_zero variables {α : Type u} {β : Type v} @[simp, with_zero_simp] lemma zero_le [preorder α] {x : with_zero α} : 0 ≤ x := by { intros y hy, cases hy } @[simp, with_zero_simp] lemma zero_lt_coe [preorder α] {a : α} : (0 : with_zero α) < a := ⟨a, rfl, λ y hy, by cases hy⟩ @[simp, with_zero_simp] lemma not_coe_eq_zero [preorder α] {x : α} : ¬ (x : with_zero α) = 0 := λ h, option.no_confusion h @[elim_cast] lemma coe_le_coe [preorder α] {x y : α} : (x : with_zero α) ≤ (y : with_zero α) ↔ x ≤ y := ⟨λ h, by rcases (h x rfl) with ⟨z, ⟨h2⟩, h3⟩; exact h3, λ _ _ h, ⟨y, rfl, by cases h ; assumption⟩⟩ @[elim_cast] lemma coe_lt_coe [preorder α] {x y : α} : (x : with_zero α) < (y : with_zero α) ↔ x < y := by repeat { rw [lt_iff_le_not_le, coe_le_coe] } -- TODO: replace `coe_one` in mathlib by this one, which seems to be stated as needed by norm_cast. -- Same remark applies to the next two lemmas. @[elim_cast] lemma coe_one' [has_one α] : (1 : with_zero α) = ((1 : α) : with_zero α) := rfl @[move_cast] lemma inv_coe' {α : Type*} [has_inv α] (a : α) : ((a⁻¹ : α) : with_zero α) = (a : with_zero α)⁻¹ := rfl @[move_cast] lemma mul_coe' {α : Type*} [has_mul α] (a b : α) : ((a * b : α) : with_zero α) = (a : with_zero α) * b := rfl attribute [elim_cast] coe_inj @[simp] lemma le_zero_iff_eq_zero [preorder α] {x : with_zero α} : x ≤ 0 ↔ x = 0 := begin with_zero_cases x, intro h, rcases h x rfl with ⟨_, h, _⟩, exact option.no_confusion h, end @[simp] lemma not_coe_le_zero [preorder α] (x : α) : ¬ (x : with_zero α) ≤ 0 := begin intro h, rw le_zero_iff_eq_zero at h, exact not_coe_eq_zero h, end @[simp] lemma not_lt_zero [preorder α] (x : with_zero α) : ¬ x < 0 := begin intro h, with_zero_cases x, exact lt_irrefl _ h, exact not_coe_le_zero x (le_of_lt h), end @[simp] lemma map_zero {f : α → β} : map f 0 = 0 := option.map_none' @[simp, elim_cast] lemma map_coe {f : α → β} {a : α} : map f (a : with_zero α) = f a := option.map_some' @[simp] lemma map_id {α : Type*} : map (id : α → α) = id := option.map_id lemma map_comp {α β γ : Type*} (f : α → β) (g : β → γ) (r : with_zero α) : map (g ∘ f) r = map g (map f r) := by cases r; refl @[simp] lemma map_eq_zero_iff {f : α → β} {a : with_zero α} : map f a = 0 ↔ a = 0 := ⟨λ h, by with_zero_cases a, λ h, by simp [h]⟩ lemma injective_map {f : α → β} (H : function.injective f) : function.injective (map f) := option.injective_map H lemma map_monotone [preorder α] [preorder β] {f : α → β} (H : monotone f) : monotone (map f) := λ x y, by { with_zero_cases x y, exact λ h, H h } lemma map_strict_mono [linear_order α] [partial_order β] {f : α → β} (H : ∀ a b, a < b → f a < f b) : strict_mono (map f) := λ x y, by { with_zero_cases x y, exact λ h, H _ _ h } lemma map_le [preorder α] [preorder β] {f : α → β} (H : ∀ a b : α, a ≤ b ↔ f a ≤ f b) (x y : with_zero α) : x ≤ y ↔ map f x ≤ map f y := by { with_zero_cases x y, exact H x y } @[move_cast] lemma coe_min (x y : α) [decidable_linear_order α] : ((min x y : α) : with_zero α) = min x y := begin by_cases h: x ≤ y, { simp [min_eq_left, h] }, { simp [min_eq_right, le_of_not_le h] } end section group variables [group α] lemma mul_left_cancel : ∀ {x : with_zero α} (h : x ≠ 0) {y z : with_zero α}, x * y = x * z → y = z | 0 h := false.elim $ h rfl | (a : α) h := λ y z h2, begin have h3 : (a⁻¹ : with_zero α) * (a * y) = a⁻¹ * (a * z) := by rw h2, rwa [←mul_assoc, ←mul_assoc, mul_left_inv _ h, one_mul, one_mul] at h3, end lemma mul_right_cancel : ∀ {x : with_zero α} (h : x ≠ 0) {y z : with_zero α}, y * x = z * x → y = z | 0 h := false.elim $ h rfl | (a : α) h := λ y z h2, begin have h3 : (y * a) * a⁻¹ = (z * a) * a⁻¹ := by rw h2, rwa [mul_assoc, mul_assoc, mul_right_inv _ h, mul_one, mul_one] at h3, end lemma mul_inv_eq_of_eq_mul : ∀ {x : with_zero α} (h : x ≠ 0) {y z : with_zero α}, y = z * x → y * x⁻¹ = z | 0 h := false.elim $ h rfl | (x : α) h := λ _ _ _, mul_right_cancel h (by rwa [mul_assoc, mul_left_inv _ h, mul_one]) lemma eq_mul_inv_of_mul_eq {x : with_zero α} (h : x ≠ 0) {y z : with_zero α} (h2 : z * x = y) : z = y * x⁻¹ := eq.symm $ mul_inv_eq_of_eq_mul h h2.symm end group end with_zero
[GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ r : ℝ hr : Tendsto (fun n => ∑ i in Finset.range n, |f i|) atTop (𝓝 r) ⊢ Summable f [PROOFSTEP] refine' summable_of_summable_norm ⟨r, (hasSum_iff_tendsto_nat_of_nonneg _ _).2 _⟩ [GOAL] case refine'_1 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ r : ℝ hr : Tendsto (fun n => ∑ i in Finset.range n, |f i|) atTop (𝓝 r) ⊢ ∀ (i : ℕ), 0 ≤ ‖f i‖ case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ r : ℝ hr : Tendsto (fun n => ∑ i in Finset.range n, |f i|) atTop (𝓝 r) ⊢ Tendsto (fun n => ∑ i in Finset.range n, ‖f i‖) atTop (𝓝 r) [PROOFSTEP] exact fun i ↦ norm_nonneg _ [GOAL] case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ r : ℝ hr : Tendsto (fun n => ∑ i in Finset.range n, |f i|) atTop (𝓝 r) ⊢ Tendsto (fun n => ∑ i in Finset.range n, ‖f i‖) atTop (𝓝 r) [PROOFSTEP] simpa only using hr [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NormedField 𝕜 m : ℤ hm : m < 0 ⊢ Tendsto (fun x => ‖x ^ m‖) (𝓝[{0}ᶜ] 0) atTop [PROOFSTEP] rcases neg_surjective m with ⟨m, rfl⟩ [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NormedField 𝕜 m : ℤ hm : -m < 0 ⊢ Tendsto (fun x => ‖x ^ (-m)‖) (𝓝[{0}ᶜ] 0) atTop [PROOFSTEP] rw [neg_lt_zero] at hm [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NormedField 𝕜 m : ℤ hm : 0 < m ⊢ Tendsto (fun x => ‖x ^ (-m)‖) (𝓝[{0}ᶜ] 0) atTop [PROOFSTEP] lift m to ℕ using hm.le [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NormedField 𝕜 m : ℕ hm : 0 < ↑m ⊢ Tendsto (fun x => ‖x ^ (-↑m)‖) (𝓝[{0}ᶜ] 0) atTop [PROOFSTEP] rw [Int.coe_nat_pos] at hm [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NormedField 𝕜 m : ℕ hm : 0 < m ⊢ Tendsto (fun x => ‖x ^ (-↑m)‖) (𝓝[{0}ᶜ] 0) atTop [PROOFSTEP] simp only [norm_pow, zpow_neg, zpow_ofNat, ← inv_pow] [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NormedField 𝕜 m : ℕ hm : 0 < m ⊢ Tendsto (fun x => ‖x⁻¹‖ ^ m) (𝓝[{0}ᶜ] 0) atTop [PROOFSTEP] exact (tendsto_pow_atTop hm.ne').comp NormedField.tendsto_norm_inverse_nhdsWithin_0_atTop [GOAL] α : Type u_1 β : Type u_2 ι✝ : Type u_3 ι : Type u_4 𝕜 : Type u_5 𝔸 : Type u_6 inst✝² : NormedField 𝕜 inst✝¹ : NormedAddCommGroup 𝔸 inst✝ : NormedSpace 𝕜 𝔸 l : Filter ι ε : ι → 𝕜 f : ι → 𝔸 hε : Tendsto ε l (𝓝 0) hf : IsBoundedUnder (fun x x_1 => x ≤ x_1) l (norm ∘ f) ⊢ Tendsto (ε • f) l (𝓝 0) [PROOFSTEP] rw [← isLittleO_one_iff 𝕜] at hε ⊢ [GOAL] α : Type u_1 β : Type u_2 ι✝ : Type u_3 ι : Type u_4 𝕜 : Type u_5 𝔸 : Type u_6 inst✝² : NormedField 𝕜 inst✝¹ : NormedAddCommGroup 𝔸 inst✝ : NormedSpace 𝕜 𝔸 l : Filter ι ε : ι → 𝕜 f : ι → 𝔸 hε : ε =o[l] fun _x => 1 hf : IsBoundedUnder (fun x x_1 => x ≤ x_1) l (norm ∘ f) ⊢ (ε • f) =o[l] fun _x => 1 [PROOFSTEP] simpa using IsLittleO.smul_isBigO hε (hf.isBigO_const (one_ne_zero : (1 : 𝕜) ≠ 0)) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NontriviallyNormedField 𝕜 m : ℤ x : 𝕜 ⊢ ContinuousAt (fun x => x ^ m) x ↔ x ≠ 0 ∨ 0 ≤ m [PROOFSTEP] refine' ⟨_, continuousAt_zpow₀ _ _⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NontriviallyNormedField 𝕜 m : ℤ x : 𝕜 ⊢ ContinuousAt (fun x => x ^ m) x → x ≠ 0 ∨ 0 ≤ m [PROOFSTEP] contrapose! [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NontriviallyNormedField 𝕜 m : ℤ x : 𝕜 ⊢ x = 0 ∧ m < 0 → ¬ContinuousAt (fun x => x ^ m) x [PROOFSTEP] rintro ⟨rfl, hm⟩ hc [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NontriviallyNormedField 𝕜 m : ℤ hm : m < 0 hc : ContinuousAt (fun x => x ^ m) 0 ⊢ False [PROOFSTEP] exact not_tendsto_atTop_of_tendsto_nhds (hc.tendsto.mono_left nhdsWithin_le_nhds).norm (tendsto_norm_zpow_nhdsWithin_0_atTop hm) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝ : NontriviallyNormedField 𝕜 x : 𝕜 ⊢ ContinuousAt Inv.inv x ↔ x ≠ 0 [PROOFSTEP] simpa [(zero_lt_one' ℤ).not_le] using @continuousAt_zpow _ _ (-1) x [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 r₁ r₂ : ℝ h : |r₁| < |r₂| ⊢ (fun n => r₁ ^ n) =o[atTop] fun n => r₂ ^ n [PROOFSTEP] refine' (IsLittleO.of_norm_left _).of_norm_right [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 r₁ r₂ : ℝ h : |r₁| < |r₂| ⊢ (fun x => ‖r₁ ^ x‖) =o[atTop] fun x => ‖r₂ ^ x‖ [PROOFSTEP] exact (isLittleO_pow_pow_of_lt_left (abs_nonneg r₁) h).congr (pow_abs r₁) (pow_abs r₂) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] have A : Ico 0 R ⊆ Ioo (-R) R := fun x hx ↦ ⟨(neg_lt_zero.2 (hx.1.trans_lt hx.2)).trans_le hx.1, hx.2⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] have B : Ioo 0 R ⊆ Ioo (-R) R := Subset.trans Ioo_subset_Ico_self A [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 1 → 3 [GOAL] case tfae_1_to_3 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R ⊢ (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] exact fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 2 → 1 [GOAL] case tfae_2_to_1 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] exact fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 3 → 2 [GOAL] case tfae_3_to_2 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x ⊢ (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x [PROOFSTEP] rintro ⟨a, ha, H⟩ [GOAL] case tfae_3_to_2.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x a : ℝ ha : a ∈ Set.Ioo (-R) R H : f =O[atTop] fun x => a ^ x ⊢ ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x [PROOFSTEP] rcases exists_between (abs_lt.2 ha) with ⟨b, hab, hbR⟩ [GOAL] case tfae_3_to_2.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x a : ℝ ha : a ∈ Set.Ioo (-R) R H : f =O[atTop] fun x => a ^ x b : ℝ hab : |a| < b hbR : b < R ⊢ ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x [PROOFSTEP] exact ⟨b, ⟨(abs_nonneg a).trans_lt hab, hbR⟩, H.trans_isLittleO (isLittleO_pow_pow_of_abs_lt_left (hab.trans_le (le_abs_self b)))⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 2 → 4 [GOAL] case tfae_2_to_4 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x ⊢ (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] exact fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 4 → 3 [GOAL] case tfae_4_to_3 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x ⊢ (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] exact fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩ -- Add 5 and 6 using 4 → 6 → 5 → 3 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 4 → 6 [GOAL] case tfae_4_to_6 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n [PROOFSTEP] rintro ⟨a, ha, H⟩ [GOAL] case tfae_4_to_6.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x a : ℝ ha : a ∈ Set.Ioo 0 R H : f =O[atTop] fun x => a ^ x ⊢ ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n [PROOFSTEP] rcases bound_of_isBigO_nat_atTop H with ⟨C, hC₀, hC⟩ [GOAL] case tfae_4_to_6.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x a : ℝ ha : a ∈ Set.Ioo 0 R H : f =O[atTop] fun x => a ^ x C : ℝ hC₀ : C > 0 hC : ∀ ⦃x : ℕ⦄, a ^ x ≠ 0 → ‖f x‖ ≤ C * ‖a ^ x‖ ⊢ ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n [PROOFSTEP] refine' ⟨a, ha, C, hC₀, fun n ↦ _⟩ [GOAL] case tfae_4_to_6.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x a : ℝ ha : a ∈ Set.Ioo 0 R H : f =O[atTop] fun x => a ^ x C : ℝ hC₀ : C > 0 hC : ∀ ⦃x : ℕ⦄, a ^ x ≠ 0 → ‖f x‖ ≤ C * ‖a ^ x‖ n : ℕ ⊢ |f n| ≤ C * a ^ n [PROOFSTEP] simpa only [Real.norm_eq_abs, abs_pow, abs_of_nonneg ha.1.le] using hC (pow_ne_zero n ha.1.ne') [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 6 → 5 [GOAL] case tfae_6_to_5 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n ⊢ (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] exact fun ⟨a, ha, C, H₀, H⟩ ↦ ⟨a, ha.2, C, Or.inl H₀, H⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 5 → 3 [GOAL] case tfae_5_to_3 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n ⊢ (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x [PROOFSTEP] rintro ⟨a, ha, C, h₀, H⟩ [GOAL] case tfae_5_to_3.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n a : ℝ ha : a < R C : ℝ h₀ : 0 < C ∨ 0 < R H : ∀ (n : ℕ), |f n| ≤ C * a ^ n ⊢ ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x [PROOFSTEP] rcases sign_cases_of_C_mul_pow_nonneg fun n ↦ (abs_nonneg _).trans (H n) with (rfl | ⟨hC₀, ha₀⟩) [GOAL] case tfae_5_to_3.intro.intro.intro.intro.inl α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n a : ℝ ha : a < R h₀ : 0 < 0 ∨ 0 < R H : ∀ (n : ℕ), |f n| ≤ 0 * a ^ n ⊢ ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x [PROOFSTEP] obtain rfl : f = 0 := by ext n simpa using H n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n a : ℝ ha : a < R h₀ : 0 < 0 ∨ 0 < R H : ∀ (n : ℕ), |f n| ≤ 0 * a ^ n ⊢ f = 0 [PROOFSTEP] ext n [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n a : ℝ ha : a < R h₀ : 0 < 0 ∨ 0 < R H : ∀ (n : ℕ), |f n| ≤ 0 * a ^ n n : ℕ ⊢ f n = OfNat.ofNat 0 n [PROOFSTEP] simpa using H n [GOAL] case tfae_5_to_3.intro.intro.intro.intro.inl α : Type u_1 β : Type u_2 ι : Type u_3 R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R a : ℝ ha : a < R h₀ : 0 < 0 ∨ 0 < R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ 0 =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ 0 =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ 0 =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ 0 =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ 0 =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ 0 =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |OfNat.ofNat 0 n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |OfNat.ofNat 0 n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |OfNat.ofNat 0 n| ≤ C * a ^ n H : ∀ (n : ℕ), |OfNat.ofNat 0 n| ≤ 0 * a ^ n ⊢ ∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =O[atTop] fun x => a ^ x [PROOFSTEP] simp only [lt_irrefl, false_or_iff] at h₀ [GOAL] case tfae_5_to_3.intro.intro.intro.intro.inl α : Type u_1 β : Type u_2 ι : Type u_3 R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R a : ℝ ha : a < R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ 0 =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ 0 =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ 0 =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ 0 =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ 0 =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ 0 =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |OfNat.ofNat 0 n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |OfNat.ofNat 0 n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |OfNat.ofNat 0 n| ≤ C * a ^ n H : ∀ (n : ℕ), |OfNat.ofNat 0 n| ≤ 0 * a ^ n h₀ : 0 < R ⊢ ∃ a, a ∈ Set.Ioo (-R) R ∧ 0 =O[atTop] fun x => a ^ x [PROOFSTEP] exact ⟨0, ⟨neg_lt_zero.2 h₀, h₀⟩, isBigO_zero _ _⟩ [GOAL] case tfae_5_to_3.intro.intro.intro.intro.inr.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n a : ℝ ha : a < R C : ℝ h₀ : 0 < C ∨ 0 < R H : ∀ (n : ℕ), |f n| ≤ C * a ^ n hC₀ : 0 < C ha₀ : 0 ≤ a ⊢ ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x [PROOFSTEP] exact ⟨a, A ⟨ha₀, ha⟩, isBigO_of_le' _ fun n ↦ (H n).trans <| mul_le_mul_of_nonneg_left (le_abs_self _) hC₀.le⟩ -- Add 7 and 8 using 2 → 8 → 7 → 3 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 2 → 8 [GOAL] case tfae_2_to_8 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n [PROOFSTEP] rintro ⟨a, ha, H⟩ [GOAL] case tfae_2_to_8.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x a : ℝ ha : a ∈ Set.Ioo 0 R H : f =o[atTop] fun x => a ^ x ⊢ ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n [PROOFSTEP] refine' ⟨a, ha, (H.def zero_lt_one).mono fun n hn ↦ _⟩ [GOAL] case tfae_2_to_8.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x a : ℝ ha : a ∈ Set.Ioo 0 R H : f =o[atTop] fun x => a ^ x n : ℕ hn : ‖f n‖ ≤ 1 * ‖a ^ n‖ ⊢ |f n| ≤ a ^ n [PROOFSTEP] rwa [Real.norm_eq_abs, Real.norm_eq_abs, one_mul, abs_pow, abs_of_pos ha.1] at hn [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 8 → 7 [GOAL] case tfae_8_to_7 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n ⊢ (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] exact fun ⟨a, ha, H⟩ ↦ ⟨a, ha.2, H⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 7 → 3 [GOAL] case tfae_7_to_3 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n ⊢ (∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x [PROOFSTEP] rintro ⟨a, ha, H⟩ [GOAL] case tfae_7_to_3.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n a : ℝ ha : a < R H : ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n ⊢ ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x [PROOFSTEP] have : 0 ≤ a := nonneg_of_eventually_pow_nonneg (H.mono fun n ↦ (abs_nonneg _).trans) [GOAL] case tfae_7_to_3.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n a : ℝ ha : a < R H : ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n this : 0 ≤ a ⊢ ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x [PROOFSTEP] refine' ⟨a, A ⟨this, ha⟩, IsBigO.of_bound 1 _⟩ [GOAL] case tfae_7_to_3.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n a : ℝ ha : a < R H : ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n this : 0 ≤ a ⊢ ∀ᶠ (x : ℕ) in atTop, ‖f x‖ ≤ 1 * ‖a ^ x‖ [PROOFSTEP] simpa only [Real.norm_eq_abs, one_mul, abs_pow, abs_of_nonneg this] -- porting note: used to work without explicitly having 6 → 7 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_7_to_3 : (∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_have 6 → 7 [GOAL] case tfae_6_to_7 α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_7_to_3 : (∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x ⊢ (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n [PROOFSTEP] exact fun h ↦ tfae_8_to_7 <| tfae_2_to_8 <| tfae_3_to_2 <| tfae_5_to_3 <| tfae_6_to_5 h [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 f : ℕ → ℝ R : ℝ A : Set.Ico 0 R ⊆ Set.Ioo (-R) R B : Set.Ioo 0 R ⊆ Set.Ioo (-R) R tfae_1_to_3 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_1 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x tfae_3_to_2 : (∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x tfae_2_to_4 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_3 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_4_to_6 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_6_to_5 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n tfae_5_to_3 : (∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_2_to_8 : (∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x) → ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_8_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n tfae_7_to_3 : (∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n) → ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x tfae_6_to_7 : (∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n) → ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n ⊢ TFAE [∃ a, a ∈ Set.Ioo (-R) R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =o[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo (-R) R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a ∈ Set.Ioo 0 R ∧ f =O[atTop] fun x => a ^ x, ∃ a, a < R ∧ ∃ C x, ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∃ C, C > 0 ∧ ∀ (n : ℕ), |f n| ≤ C * a ^ n, ∃ a, a < R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n, ∃ a, a ∈ Set.Ioo 0 R ∧ ∀ᶠ (n : ℕ) in atTop, |f n| ≤ a ^ n] [PROOFSTEP] tfae_finish [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r ⊢ (fun n => ↑n ^ k) =o[atTop] fun n => r ^ n [PROOFSTEP] have : Tendsto (fun x : ℝ ↦ x ^ k) (𝓝[>] 1) (𝓝 1) := ((continuous_id.pow k).tendsto' (1 : ℝ) 1 (one_pow _)).mono_left inf_le_left [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) ⊢ (fun n => ↑n ^ k) =o[atTop] fun n => r ^ n [PROOFSTEP] obtain ⟨r' : ℝ, hr' : r' ^ k < r, h1 : 1 < r'⟩ := ((this.eventually (gt_mem_nhds hr)).and self_mem_nhdsWithin).exists [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' ⊢ (fun n => ↑n ^ k) =o[atTop] fun n => r ^ n [PROOFSTEP] have h0 : 0 ≤ r' := zero_le_one.trans h1.le [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' ⊢ (fun n => ↑n ^ k) =o[atTop] fun n => r ^ n [PROOFSTEP] suffices : (fun n ↦ (n : R) ^ k : ℕ → R) =O[atTop] fun n : ℕ ↦ (r' ^ k) ^ n [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this✝ : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' this : (fun n => ↑n ^ k) =O[atTop] fun n => (r' ^ k) ^ n ⊢ (fun n => ↑n ^ k) =o[atTop] fun n => r ^ n case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' ⊢ (fun n => ↑n ^ k) =O[atTop] fun n => (r' ^ k) ^ n [PROOFSTEP] exact this.trans_isLittleO (isLittleO_pow_pow_of_lt_left (pow_nonneg h0 _) hr') [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' ⊢ (fun n => ↑n ^ k) =O[atTop] fun n => (r' ^ k) ^ n [PROOFSTEP] conv in (r' ^ _) ^ _ => rw [← pow_mul, mul_comm, pow_mul] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' n : ℕ | (r' ^ k) ^ n [PROOFSTEP] rw [← pow_mul, mul_comm, pow_mul] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' n : ℕ | (r' ^ k) ^ n [PROOFSTEP] rw [← pow_mul, mul_comm, pow_mul] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' n : ℕ | (r' ^ k) ^ n [PROOFSTEP] rw [← pow_mul, mul_comm, pow_mul] [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' ⊢ (fun n => ↑n ^ k) =O[atTop] fun n => (r' ^ n) ^ k [PROOFSTEP] suffices : ∀ n : ℕ, ‖(n : R)‖ ≤ (r' - 1)⁻¹ * ‖(1 : R)‖ * ‖r' ^ n‖ [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this✝ : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' this : ∀ (n : ℕ), ‖↑n‖ ≤ (r' - 1)⁻¹ * ‖1‖ * ‖r' ^ n‖ ⊢ (fun n => ↑n ^ k) =O[atTop] fun n => (r' ^ n) ^ k case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' ⊢ ∀ (n : ℕ), ‖↑n‖ ≤ (r' - 1)⁻¹ * ‖1‖ * ‖r' ^ n‖ [PROOFSTEP] exact (isBigO_of_le' _ this).pow _ [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' ⊢ ∀ (n : ℕ), ‖↑n‖ ≤ (r' - 1)⁻¹ * ‖1‖ * ‖r' ^ n‖ [PROOFSTEP] intro n [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' n : ℕ ⊢ ‖↑n‖ ≤ (r' - 1)⁻¹ * ‖1‖ * ‖r' ^ n‖ [PROOFSTEP] rw [mul_right_comm] [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' n : ℕ ⊢ ‖↑n‖ ≤ (r' - 1)⁻¹ * ‖r' ^ n‖ * ‖1‖ [PROOFSTEP] refine' n.norm_cast_le.trans (mul_le_mul_of_nonneg_right _ (norm_nonneg _)) [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : ℝ hr : 1 < r this : Tendsto (fun x => x ^ k) (𝓝[Set.Ioi 1] 1) (𝓝 1) r' : ℝ hr' : r' ^ k < r h1 : 1 < r' h0 : 0 ≤ r' n : ℕ ⊢ ↑n ≤ (r' - 1)⁻¹ * ‖r' ^ n‖ [PROOFSTEP] simpa [_root_.div_eq_inv_mul, Real.norm_eq_abs, abs_of_nonneg h0] using n.cast_le_pow_div_sub h1 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R r : ℝ hr : 1 < r ⊢ Nat.cast =o[atTop] fun n => r ^ n [PROOFSTEP] simpa only [pow_one] using @isLittleO_pow_const_const_pow_of_one_lt R _ 1 _ hr [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ ⊢ (fun n => ↑n ^ k * r₁ ^ n) =o[atTop] fun n => r₂ ^ n [PROOFSTEP] by_cases h0 : r₁ = 0 [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ h0 : r₁ = 0 ⊢ (fun n => ↑n ^ k * r₁ ^ n) =o[atTop] fun n => r₂ ^ n [PROOFSTEP] refine' (isLittleO_zero _ _).congr' (mem_atTop_sets.2 <| ⟨1, fun n hn ↦ _⟩) EventuallyEq.rfl [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ h0 : r₁ = 0 n : ℕ hn : n ≥ 1 ⊢ n ∈ {x | (fun x => (fun _x => 0) x = (fun n => ↑n ^ k * r₁ ^ n) x) x} [PROOFSTEP] simp [zero_pow (zero_lt_one.trans_le hn), h0] [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ h0 : ¬r₁ = 0 ⊢ (fun n => ↑n ^ k * r₁ ^ n) =o[atTop] fun n => r₂ ^ n [PROOFSTEP] rw [← Ne.def, ← norm_pos_iff] at h0 [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ h0 : 0 < ‖r₁‖ ⊢ (fun n => ↑n ^ k * r₁ ^ n) =o[atTop] fun n => r₂ ^ n [PROOFSTEP] have A : (fun n ↦ (n : R) ^ k : ℕ → R) =o[atTop] fun n ↦ (r₂ / ‖r₁‖) ^ n := isLittleO_pow_const_const_pow_of_one_lt k ((one_lt_div h0).2 h) [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ h0 : 0 < ‖r₁‖ A : (fun n => ↑n ^ k) =o[atTop] fun n => (r₂ / ‖r₁‖) ^ n ⊢ (fun n => ↑n ^ k * r₁ ^ n) =o[atTop] fun n => r₂ ^ n [PROOFSTEP] suffices (fun n ↦ r₁ ^ n) =O[atTop] fun n ↦ ‖r₁‖ ^ n by simpa [div_mul_cancel _ (pow_pos h0 _).ne'] using A.mul_isBigO this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ h0 : 0 < ‖r₁‖ A : (fun n => ↑n ^ k) =o[atTop] fun n => (r₂ / ‖r₁‖) ^ n this : (fun n => r₁ ^ n) =O[atTop] fun n => ‖r₁‖ ^ n ⊢ (fun n => ↑n ^ k * r₁ ^ n) =o[atTop] fun n => r₂ ^ n [PROOFSTEP] simpa [div_mul_cancel _ (pow_pos h0 _).ne'] using A.mul_isBigO this [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ h0 : 0 < ‖r₁‖ A : (fun n => ↑n ^ k) =o[atTop] fun n => (r₂ / ‖r₁‖) ^ n ⊢ (fun n => r₁ ^ n) =O[atTop] fun n => ‖r₁‖ ^ n [PROOFSTEP] exact IsBigO.of_bound 1 (by simpa using eventually_norm_pow_le r₁) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r₁ : R r₂ : ℝ h : ‖r₁‖ < r₂ h0 : 0 < ‖r₁‖ A : (fun n => ↑n ^ k) =o[atTop] fun n => (r₂ / ‖r₁‖) ^ n ⊢ ∀ᶠ (x : ℕ) in atTop, ‖r₁ ^ x‖ ≤ 1 * ‖‖r₁‖ ^ x‖ [PROOFSTEP] simpa using eventually_norm_pow_le r₁ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 k : ℕ r : ℝ hr : |r| < 1 ⊢ Tendsto (fun n => ↑n ^ k * r ^ n) atTop (𝓝 0) [PROOFSTEP] by_cases h0 : r = 0 [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 k : ℕ r : ℝ hr : |r| < 1 h0 : r = 0 ⊢ Tendsto (fun n => ↑n ^ k * r ^ n) atTop (𝓝 0) [PROOFSTEP] exact tendsto_const_nhds.congr' (mem_atTop_sets.2 ⟨1, fun n hn ↦ by simp [zero_lt_one.trans_le hn, h0]⟩) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 k : ℕ r : ℝ hr : |r| < 1 h0 : r = 0 n : ℕ hn : n ≥ 1 ⊢ n ∈ {x | (fun x => 0 = (fun n => ↑n ^ k * r ^ n) x) x} [PROOFSTEP] simp [zero_lt_one.trans_le hn, h0] [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 k : ℕ r : ℝ hr : |r| < 1 h0 : ¬r = 0 ⊢ Tendsto (fun n => ↑n ^ k * r ^ n) atTop (𝓝 0) [PROOFSTEP] have hr' : 1 < |r|⁻¹ := one_lt_inv (abs_pos.2 h0) hr [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 k : ℕ r : ℝ hr : |r| < 1 h0 : ¬r = 0 hr' : 1 < |r|⁻¹ ⊢ Tendsto (fun n => ↑n ^ k * r ^ n) atTop (𝓝 0) [PROOFSTEP] rw [tendsto_zero_iff_norm_tendsto_zero] [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 k : ℕ r : ℝ hr : |r| < 1 h0 : ¬r = 0 hr' : 1 < |r|⁻¹ ⊢ Tendsto (fun e => ‖↑e ^ k * r ^ e‖) atTop (𝓝 0) [PROOFSTEP] simpa [div_eq_mul_inv] using tendsto_pow_const_div_const_pow_of_one_lt k hr' [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 r : ℝ hr : |r| < 1 ⊢ Tendsto (fun n => ↑n * r ^ n) atTop (𝓝 0) [PROOFSTEP] simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_abs_lt_one 1 hr [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 r : ℝ hr : 0 ≤ r h'r : r < 1 ⊢ Tendsto (fun n => ↑n * r ^ n) atTop (𝓝 0) [PROOFSTEP] simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_lt_one 1 hr h'r [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R x : R h : ‖x‖ < 1 ⊢ Tendsto (fun n => x ^ n) atTop (𝓝 0) [PROOFSTEP] apply squeeze_zero_norm' (eventually_norm_pow_le x) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R x : R h : ‖x‖ < 1 ⊢ Tendsto (fun n => ‖x‖ ^ n) atTop (𝓝 0) [PROOFSTEP] exact tendsto_pow_atTop_nhds_0_of_lt_1 (norm_nonneg _) h [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : ‖ξ‖ < 1 ⊢ HasSum (fun n => ξ ^ n) (1 - ξ)⁻¹ [PROOFSTEP] have xi_ne_one : ξ ≠ 1 := by contrapose! h simp [h] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : ‖ξ‖ < 1 ⊢ ξ ≠ 1 [PROOFSTEP] contrapose! h [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : ξ = 1 ⊢ 1 ≤ ‖ξ‖ [PROOFSTEP] simp [h] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : ‖ξ‖ < 1 xi_ne_one : ξ ≠ 1 ⊢ HasSum (fun n => ξ ^ n) (1 - ξ)⁻¹ [PROOFSTEP] have A : Tendsto (fun n ↦ (ξ ^ n - 1) * (ξ - 1)⁻¹) atTop (𝓝 ((0 - 1) * (ξ - 1)⁻¹)) := ((tendsto_pow_atTop_nhds_0_of_norm_lt_1 h).sub tendsto_const_nhds).mul tendsto_const_nhds [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : ‖ξ‖ < 1 xi_ne_one : ξ ≠ 1 A : Tendsto (fun n => (ξ ^ n - 1) * (ξ - 1)⁻¹) atTop (𝓝 ((0 - 1) * (ξ - 1)⁻¹)) ⊢ HasSum (fun n => ξ ^ n) (1 - ξ)⁻¹ [PROOFSTEP] rw [hasSum_iff_tendsto_nat_of_summable_norm] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : ‖ξ‖ < 1 xi_ne_one : ξ ≠ 1 A : Tendsto (fun n => (ξ ^ n - 1) * (ξ - 1)⁻¹) atTop (𝓝 ((0 - 1) * (ξ - 1)⁻¹)) ⊢ Tendsto (fun n => ∑ i in Finset.range n, ξ ^ i) atTop (𝓝 (1 - ξ)⁻¹) [PROOFSTEP] simpa [geom_sum_eq, xi_ne_one, neg_inv, div_eq_mul_inv] using A [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : ‖ξ‖ < 1 xi_ne_one : ξ ≠ 1 A : Tendsto (fun n => (ξ ^ n - 1) * (ξ - 1)⁻¹) atTop (𝓝 ((0 - 1) * (ξ - 1)⁻¹)) ⊢ Summable fun i => ‖ξ ^ i‖ [PROOFSTEP] simp [norm_pow, summable_geometric_of_lt_1 (norm_nonneg _) h] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K ⊢ (Summable fun n => ξ ^ n) ↔ ‖ξ‖ < 1 [PROOFSTEP] refine' ⟨fun h ↦ _, summable_geometric_of_norm_lt_1⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : Summable fun n => ξ ^ n ⊢ ‖ξ‖ < 1 [PROOFSTEP] obtain ⟨k : ℕ, hk : dist (ξ ^ k) 0 < 1⟩ := (h.tendsto_cofinite_zero.eventually (ball_mem_nhds _ zero_lt_one)).exists [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : Summable fun n => ξ ^ n k : ℕ hk : dist (ξ ^ k) 0 < 1 ⊢ ‖ξ‖ < 1 [PROOFSTEP] simp only [norm_pow, dist_zero_right] at hk [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : Summable fun n => ξ ^ n k : ℕ hk : ‖ξ‖ ^ k < 1 ⊢ ‖ξ‖ < 1 [PROOFSTEP] rw [← one_pow k] at hk [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 K : Type u_4 inst✝ : NormedField K ξ : K h : Summable fun n => ξ ^ n k : ℕ hk : ‖ξ‖ ^ k < 1 ^ k ⊢ ‖ξ‖ < 1 [PROOFSTEP] exact lt_of_pow_lt_pow _ zero_le_one hk [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : R hr : ‖r‖ < 1 ⊢ Summable fun n => ‖↑n ^ k * r ^ n‖ [PROOFSTEP] rcases exists_between hr with ⟨r', hrr', h⟩ [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝ : NormedRing R k : ℕ r : R hr : ‖r‖ < 1 r' : ℝ hrr' : ‖r‖ < r' h : r' < 1 ⊢ Summable fun n => ‖↑n ^ k * r ^ n‖ [PROOFSTEP] exact summable_of_isBigO_nat (summable_geometric_of_lt_1 ((norm_nonneg _).trans hrr'.le) h) (isLittleO_pow_const_mul_const_pow_const_pow_of_norm_lt _ hrr').isBigO.norm_left [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 ⊢ HasSum (fun n => ↑n * r ^ n) (r / (1 - r) ^ 2) [PROOFSTEP] have A : Summable (fun n ↦ (n : 𝕜) * r ^ n : ℕ → 𝕜) := by simpa only [pow_one] using summable_pow_mul_geometric_of_norm_lt_1 1 hr [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 ⊢ Summable fun n => ↑n * r ^ n [PROOFSTEP] simpa only [pow_one] using summable_pow_mul_geometric_of_norm_lt_1 1 hr [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n ⊢ HasSum (fun n => ↑n * r ^ n) (r / (1 - r) ^ 2) [PROOFSTEP] have B : HasSum (r ^ · : ℕ → 𝕜) (1 - r)⁻¹ := hasSum_geometric_of_norm_lt_1 hr [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ ⊢ HasSum (fun n => ↑n * r ^ n) (r / (1 - r) ^ 2) [PROOFSTEP] refine' A.hasSum_iff.2 _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ ⊢ ∑' (b : ℕ), ↑b * r ^ b = r / (1 - r) ^ 2 [PROOFSTEP] have hr' : r ≠ 1 := by rintro rfl simp [lt_irrefl] at hr [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ ⊢ r ≠ 1 [PROOFSTEP] rintro rfl [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 hr : ‖1‖ < 1 A : Summable fun n => ↑n * 1 ^ n B : HasSum (fun x => 1 ^ x) (1 - 1)⁻¹ ⊢ False [PROOFSTEP] simp [lt_irrefl] at hr [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ hr' : r ≠ 1 ⊢ ∑' (b : ℕ), ↑b * r ^ b = r / (1 - r) ^ 2 [PROOFSTEP] set s : 𝕜 := ∑' n : ℕ, n * r ^ n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ hr' : r ≠ 1 s : 𝕜 := ∑' (n : ℕ), ↑n * r ^ n ⊢ s = r / (1 - r) ^ 2 [PROOFSTEP] calc s = (1 - r) * s / (1 - r) := (mul_div_cancel_left _ (sub_ne_zero.2 hr'.symm)).symm _ = (s - r * s) / (1 - r) := by rw [_root_.sub_mul, one_mul] _ = (((0 : ℕ) * r ^ 0 + ∑' n : ℕ, (n + 1 : ℕ) * r ^ (n + 1)) - r * s) / (1 - r) := by rw [← tsum_eq_zero_add A] _ = ((r * ∑' n : ℕ, (n + 1) * r ^ n) - r * s) / (1 - r) := by simp [_root_.pow_succ, mul_left_comm _ r, _root_.tsum_mul_left] _ = r / (1 - r) ^ 2 := by simp [add_mul, tsum_add A B.summable, mul_add, B.tsum_eq, ← div_eq_mul_inv, sq, div_div] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ hr' : r ≠ 1 s : 𝕜 := ∑' (n : ℕ), ↑n * r ^ n ⊢ (1 - r) * s / (1 - r) = (s - r * s) / (1 - r) [PROOFSTEP] rw [_root_.sub_mul, one_mul] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ hr' : r ≠ 1 s : 𝕜 := ∑' (n : ℕ), ↑n * r ^ n ⊢ (s - r * s) / (1 - r) = (↑0 * r ^ 0 + ∑' (n : ℕ), ↑(n + 1) * r ^ (n + 1) - r * s) / (1 - r) [PROOFSTEP] rw [← tsum_eq_zero_add A] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ hr' : r ≠ 1 s : 𝕜 := ∑' (n : ℕ), ↑n * r ^ n ⊢ (↑0 * r ^ 0 + ∑' (n : ℕ), ↑(n + 1) * r ^ (n + 1) - r * s) / (1 - r) = (r * ∑' (n : ℕ), (↑n + 1) * r ^ n - r * s) / (1 - r) [PROOFSTEP] simp [_root_.pow_succ, mul_left_comm _ r, _root_.tsum_mul_left] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 𝕜 : Type u_4 inst✝¹ : NormedField 𝕜 inst✝ : CompleteSpace 𝕜 r : 𝕜 hr : ‖r‖ < 1 A : Summable fun n => ↑n * r ^ n B : HasSum (fun x => r ^ x) (1 - r)⁻¹ hr' : r ≠ 1 s : 𝕜 := ∑' (n : ℕ), ↑n * r ^ n ⊢ (r * ∑' (n : ℕ), (↑n + 1) * r ^ n - r * s) / (1 - r) = r / (1 - r) ^ 2 [PROOFSTEP] simp [add_mul, tsum_add A B.summable, mul_add, B.tsum_eq, ← div_eq_mul_inv, sq, div_div] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C r : ℝ hr : r < 1 u : ℕ → α h : ∀ (n : ℕ), ‖u n - u (n + 1)‖ ≤ C * r ^ n ⊢ ∀ (n : ℕ), dist (u n) (u (n + 1)) ≤ C * r ^ n [PROOFSTEP] simpa [dist_eq_norm] using h [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r C : ℝ f : ℕ → α hf : ∀ (n : ℕ), ‖f n‖ ≤ C * r ^ n n : ℕ ⊢ dist (∑ i in Finset.range n, f i) (∑ i in Finset.range (n + 1), f i) ≤ C * r ^ n [PROOFSTEP] rw [sum_range_succ, dist_eq_norm, ← norm_neg, neg_sub, add_sub_cancel'] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r C : ℝ f : ℕ → α hf : ∀ (n : ℕ), ‖f n‖ ≤ C * r ^ n n : ℕ ⊢ ‖f n‖ ≤ C * r ^ n [PROOFSTEP] exact hf n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r C : ℝ f : ℕ → α hr : r < 1 hf : ∀ (n : ℕ), ‖f n‖ ≤ C * r ^ n a : α ha : HasSum f a n : ℕ ⊢ ‖∑ x in Finset.range n, f x - a‖ ≤ C * r ^ n / (1 - r) [PROOFSTEP] rw [← dist_eq_norm] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r C : ℝ f : ℕ → α hr : r < 1 hf : ∀ (n : ℕ), ‖f n‖ ≤ C * r ^ n a : α ha : HasSum f a n : ℕ ⊢ dist (∑ x in Finset.range n, f x) a ≤ C * r ^ n / (1 - r) [PROOFSTEP] apply dist_le_of_le_geometric_of_tendsto r C hr (dist_partial_sum_le_of_le_geometric hf) [GOAL] case ha α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r C : ℝ f : ℕ → α hr : r < 1 hf : ∀ (n : ℕ), ‖f n‖ ≤ C * r ^ n a : α ha : HasSum f a n : ℕ ⊢ Tendsto (fun n => ∑ i in Finset.range n, f i) atTop (𝓝 a) [PROOFSTEP] exact ha.tendsto_sum_nat [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r C : ℝ f u : ℕ → α n : ℕ ⊢ dist (∑ k in Finset.range (n + 1), u k) (∑ k in Finset.range n, u k) = ‖u n‖ [PROOFSTEP] simp [dist_eq_norm, sum_range_succ] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r C : ℝ f u : ℕ → α n : ℕ ⊢ dist (∑ k in Finset.range n, u k) (∑ k in Finset.range (n + 1), u k) = ‖u n‖ [PROOFSTEP] simp [dist_eq_norm', sum_range_succ] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α r : ℝ hr : r < 1 h : ∀ (n : ℕ), ‖u n‖ ≤ C * r ^ n ⊢ ∀ (n : ℕ), dist (∑ k in Finset.range n, u k) (∑ k in Finset.range (n + 1), u k) ≤ C * r ^ n [PROOFSTEP] simp [h] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n ⊢ CauchySeq fun n => ∑ k in Finset.range (n + 1), u k [PROOFSTEP] set v : ℕ → α := fun n ↦ if n < N then 0 else u n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n ⊢ CauchySeq fun n => ∑ k in Finset.range (n + 1), u k [PROOFSTEP] have hC : 0 ≤ C := (zero_le_mul_right <| pow_pos hr₀ N).mp ((norm_nonneg _).trans <| h N <| le_refl N) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C ⊢ CauchySeq fun n => ∑ k in Finset.range (n + 1), u k [PROOFSTEP] have : ∀ n ≥ N, u n = v n := by intro n hn simp [hn, if_neg (not_lt.mpr hn)] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C ⊢ ∀ (n : ℕ), n ≥ N → u n = v n [PROOFSTEP] intro n hn [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C n : ℕ hn : n ≥ N ⊢ u n = v n [PROOFSTEP] simp [hn, if_neg (not_lt.mpr hn)] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n ⊢ CauchySeq fun n => ∑ k in Finset.range (n + 1), u k [PROOFSTEP] refine' cauchySeq_sum_of_eventually_eq this (NormedAddCommGroup.cauchy_series_of_le_geometric' hr₁ _) [GOAL] case refine'_1 α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n ⊢ ℝ [PROOFSTEP] exact C [GOAL] case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n ⊢ ∀ (n : ℕ), ‖v n‖ ≤ C * r ^ n [PROOFSTEP] intro n [GOAL] case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n n : ℕ ⊢ ‖v n‖ ≤ C * r ^ n [PROOFSTEP] simp only [GOAL] case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n n : ℕ ⊢ ‖if n < N then 0 else u n‖ ≤ C * r ^ n [PROOFSTEP] split_ifs with H [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n n : ℕ H : n < N ⊢ ‖0‖ ≤ C * r ^ n [PROOFSTEP] rw [norm_zero] [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n n : ℕ H : n < N ⊢ 0 ≤ C * r ^ n [PROOFSTEP] exact mul_nonneg hC (pow_nonneg hr₀.le _) [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n n : ℕ H : ¬n < N ⊢ ‖u n‖ ≤ C * r ^ n [PROOFSTEP] push_neg at H [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 inst✝ : SeminormedAddCommGroup α r✝ C✝ : ℝ f : ℕ → α C : ℝ u : ℕ → α N : ℕ r : ℝ hr₀ : 0 < r hr₁ : r < 1 h : ∀ (n : ℕ), n ≥ N → ‖u n‖ ≤ C * r ^ n v : ℕ → α := fun n => if n < N then 0 else u n hC : 0 ≤ C this : ∀ (n : ℕ), n ≥ N → u n = v n n : ℕ H : N ≤ n ⊢ ‖u n‖ ≤ C * r ^ n [PROOFSTEP] exact h _ H [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ Summable fun n => x ^ n [PROOFSTEP] have h1 : Summable fun n : ℕ ↦ ‖x‖ ^ n := summable_geometric_of_lt_1 (norm_nonneg _) h [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 h1 : Summable fun n => ‖x‖ ^ n ⊢ Summable fun n => x ^ n [PROOFSTEP] refine' summable_of_norm_bounded_eventually _ h1 _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 h1 : Summable fun n => ‖x‖ ^ n ⊢ ∀ᶠ (i : ℕ) in cofinite, ‖x ^ i‖ ≤ ‖x‖ ^ i [PROOFSTEP] rw [Nat.cofinite_eq_atTop] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 h1 : Summable fun n => ‖x‖ ^ n ⊢ ∀ᶠ (i : ℕ) in atTop, ‖x ^ i‖ ≤ ‖x‖ ^ i [PROOFSTEP] exact eventually_norm_pow_le x [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ ‖∑' (n : ℕ), x ^ n‖ ≤ ‖1‖ - 1 + (1 - ‖x‖)⁻¹ [PROOFSTEP] rw [tsum_eq_zero_add (NormedRing.summable_geometric_of_norm_lt_1 x h)] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ ‖x ^ 0 + ∑' (b : ℕ), x ^ (b + 1)‖ ≤ ‖1‖ - 1 + (1 - ‖x‖)⁻¹ [PROOFSTEP] simp only [_root_.pow_zero] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ ‖1 + ∑' (b : ℕ), x ^ (b + 1)‖ ≤ ‖1‖ - 1 + (1 - ‖x‖)⁻¹ [PROOFSTEP] refine' le_trans (norm_add_le _ _) _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ ‖1‖ + ‖∑' (b : ℕ), x ^ (b + 1)‖ ≤ ‖1‖ - 1 + (1 - ‖x‖)⁻¹ [PROOFSTEP] have : ‖∑' b : ℕ, (fun n ↦ x ^ (n + 1)) b‖ ≤ (1 - ‖x‖)⁻¹ - 1 := by refine' tsum_of_norm_bounded _ fun b ↦ norm_pow_le' _ (Nat.succ_pos b) convert (hasSum_nat_add_iff' 1).mpr (hasSum_geometric_of_lt_1 (norm_nonneg x) h) simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ ‖∑' (b : ℕ), (fun n => x ^ (n + 1)) b‖ ≤ (1 - ‖x‖)⁻¹ - 1 [PROOFSTEP] refine' tsum_of_norm_bounded _ fun b ↦ norm_pow_le' _ (Nat.succ_pos b) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ HasSum (fun b => ‖x‖ ^ (b + 1)) ((1 - ‖x‖)⁻¹ - 1) [PROOFSTEP] convert (hasSum_nat_add_iff' 1).mpr (hasSum_geometric_of_lt_1 (norm_nonneg x) h) [GOAL] case h.e'_6.h.e'_6 α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ 1 = ∑ i in Finset.range 1, ‖x‖ ^ i [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this : ‖∑' (b : ℕ), (fun n => x ^ (n + 1)) b‖ ≤ (1 - ‖x‖)⁻¹ - 1 ⊢ ‖1‖ + ‖∑' (b : ℕ), x ^ (b + 1)‖ ≤ ‖1‖ - 1 + (1 - ‖x‖)⁻¹ [PROOFSTEP] linarith [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ (∑' (i : ℕ), x ^ i) * (1 - x) = 1 [PROOFSTEP] have := (NormedRing.summable_geometric_of_norm_lt_1 x h).hasSum.mul_right (1 - x) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this : HasSum (fun i => x ^ i * (1 - x)) ((∑' (b : ℕ), x ^ b) * (1 - x)) ⊢ (∑' (i : ℕ), x ^ i) * (1 - x) = 1 [PROOFSTEP] refine' tendsto_nhds_unique this.tendsto_sum_nat _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this : HasSum (fun i => x ^ i * (1 - x)) ((∑' (b : ℕ), x ^ b) * (1 - x)) ⊢ Tendsto (fun n => ∑ i in Finset.range n, x ^ i * (1 - x)) atTop (𝓝 1) [PROOFSTEP] have : Tendsto (fun n : ℕ ↦ 1 - x ^ n) atTop (𝓝 1) := by simpa using tendsto_const_nhds.sub (tendsto_pow_atTop_nhds_0_of_norm_lt_1 h) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this : HasSum (fun i => x ^ i * (1 - x)) ((∑' (b : ℕ), x ^ b) * (1 - x)) ⊢ Tendsto (fun n => 1 - x ^ n) atTop (𝓝 1) [PROOFSTEP] simpa using tendsto_const_nhds.sub (tendsto_pow_atTop_nhds_0_of_norm_lt_1 h) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this✝ : HasSum (fun i => x ^ i * (1 - x)) ((∑' (b : ℕ), x ^ b) * (1 - x)) this : Tendsto (fun n => 1 - x ^ n) atTop (𝓝 1) ⊢ Tendsto (fun n => ∑ i in Finset.range n, x ^ i * (1 - x)) atTop (𝓝 1) [PROOFSTEP] convert ← this [GOAL] case h.e'_3.h α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this✝ : HasSum (fun i => x ^ i * (1 - x)) ((∑' (b : ℕ), x ^ b) * (1 - x)) this : Tendsto (fun n => 1 - x ^ n) atTop (𝓝 1) x✝ : ℕ ⊢ 1 - x ^ x✝ = ∑ i in Finset.range x✝, x ^ i * (1 - x) [PROOFSTEP] rw [← geom_sum_mul_neg, Finset.sum_mul] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 ⊢ (1 - x) * ∑' (i : ℕ), x ^ i = 1 [PROOFSTEP] have := (NormedRing.summable_geometric_of_norm_lt_1 x h).hasSum.mul_left (1 - x) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this : HasSum (fun i => (1 - x) * x ^ i) ((1 - x) * ∑' (b : ℕ), x ^ b) ⊢ (1 - x) * ∑' (i : ℕ), x ^ i = 1 [PROOFSTEP] refine' tendsto_nhds_unique this.tendsto_sum_nat _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this : HasSum (fun i => (1 - x) * x ^ i) ((1 - x) * ∑' (b : ℕ), x ^ b) ⊢ Tendsto (fun n => ∑ i in Finset.range n, (1 - x) * x ^ i) atTop (𝓝 1) [PROOFSTEP] have : Tendsto (fun n : ℕ ↦ 1 - x ^ n) atTop (nhds 1) := by simpa using tendsto_const_nhds.sub (tendsto_pow_atTop_nhds_0_of_norm_lt_1 h) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this : HasSum (fun i => (1 - x) * x ^ i) ((1 - x) * ∑' (b : ℕ), x ^ b) ⊢ Tendsto (fun n => 1 - x ^ n) atTop (𝓝 1) [PROOFSTEP] simpa using tendsto_const_nhds.sub (tendsto_pow_atTop_nhds_0_of_norm_lt_1 h) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this✝ : HasSum (fun i => (1 - x) * x ^ i) ((1 - x) * ∑' (b : ℕ), x ^ b) this : Tendsto (fun n => 1 - x ^ n) atTop (𝓝 1) ⊢ Tendsto (fun n => ∑ i in Finset.range n, (1 - x) * x ^ i) atTop (𝓝 1) [PROOFSTEP] convert ← this [GOAL] case h.e'_3.h α : Type u_1 β : Type u_2 ι : Type u_3 R : Type u_4 inst✝¹ : NormedRing R inst✝ : CompleteSpace R x : R h : ‖x‖ < 1 this✝ : HasSum (fun i => (1 - x) * x ^ i) ((1 - x) * ∑' (b : ℕ), x ^ b) this : Tendsto (fun n => 1 - x ^ n) atTop (𝓝 1) x✝ : ℕ ⊢ 1 - x ^ x✝ = ∑ i in Finset.range x✝, (1 - x) * x ^ i [PROOFSTEP] rw [← mul_neg_geom_sum, Finset.mul_sum] [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h : ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ ⊢ Summable f [PROOFSTEP] by_cases hr₀ : 0 ≤ r [GOAL] case pos α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h : ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ hr₀ : 0 ≤ r ⊢ Summable f [PROOFSTEP] rw [eventually_atTop] at h [GOAL] case pos α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h : ∃ a, ∀ (b : ℕ), b ≥ a → ‖f (b + 1)‖ ≤ r * ‖f b‖ hr₀ : 0 ≤ r ⊢ Summable f [PROOFSTEP] rcases h with ⟨N, hN⟩ [GOAL] case pos.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ ⊢ Summable f [PROOFSTEP] rw [← @summable_nat_add_iff α _ _ _ _ N] [GOAL] case pos.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ ⊢ Summable fun n => f (n + N) [PROOFSTEP] refine' summable_of_norm_bounded (fun n ↦ ‖f N‖ * r ^ n) (Summable.mul_left _ <| summable_geometric_of_lt_1 hr₀ hr₁) fun n ↦ _ [GOAL] case pos.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ n : ℕ ⊢ ‖f (n + N)‖ ≤ (fun n => ‖f N‖ * r ^ n) n [PROOFSTEP] simp only [GOAL] case pos.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ n : ℕ ⊢ ‖f (n + N)‖ ≤ ‖f N‖ * r ^ n [PROOFSTEP] conv_rhs => rw [mul_comm, ← zero_add N] [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ n : ℕ | ‖f N‖ * r ^ n [PROOFSTEP] rw [mul_comm, ← zero_add N] [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ n : ℕ | ‖f N‖ * r ^ n [PROOFSTEP] rw [mul_comm, ← zero_add N] [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ n : ℕ | ‖f N‖ * r ^ n [PROOFSTEP] rw [mul_comm, ← zero_add N] [GOAL] case pos.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ n : ℕ ⊢ ‖f (n + N)‖ ≤ r ^ n * ‖f (0 + N)‖ [PROOFSTEP] refine' le_geom (u := fun n ↦ ‖f (n + N)‖) hr₀ n fun i _ ↦ _ [GOAL] case pos.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ n i : ℕ x✝ : i < n ⊢ (fun n => ‖f (n + N)‖) (i + 1) ≤ r * (fun n => ‖f (n + N)‖) i [PROOFSTEP] convert hN (i + N) (N.le_add_left i) using 3 [GOAL] case h.e'_3.h.e'_3.h.e'_1 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 hr₀ : 0 ≤ r N : ℕ hN : ∀ (b : ℕ), b ≥ N → ‖f (b + 1)‖ ≤ r * ‖f b‖ n i : ℕ x✝ : i < n ⊢ i + 1 + N = i + N + 1 [PROOFSTEP] ac_rfl [GOAL] case neg α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h : ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ hr₀ : ¬0 ≤ r ⊢ Summable f [PROOFSTEP] push_neg at hr₀ [GOAL] case neg α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h : ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ hr₀ : r < 0 ⊢ Summable f [PROOFSTEP] refine' summable_of_norm_bounded_eventually 0 summable_zero _ [GOAL] case neg α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h : ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ hr₀ : r < 0 ⊢ ∀ᶠ (i : ℕ) in cofinite, ‖f i‖ ≤ OfNat.ofNat 0 i [PROOFSTEP] rw [Nat.cofinite_eq_atTop] [GOAL] case neg α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h : ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ hr₀ : r < 0 ⊢ ∀ᶠ (i : ℕ) in atTop, ‖f i‖ ≤ OfNat.ofNat 0 i [PROOFSTEP] filter_upwards [h] with _ hn [GOAL] case h α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h : ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ hr₀ : r < 0 a✝ : ℕ hn : ‖f (a✝ + 1)‖ ≤ r * ‖f a✝‖ ⊢ ‖f a✝‖ ≤ OfNat.ofNat 0 a✝ [PROOFSTEP] by_contra' h [GOAL] case h α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : SeminormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α r : ℝ hr₁ : r < 1 h✝ : ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ hr₀ : r < 0 a✝ : ℕ hn : ‖f (a✝ + 1)‖ ≤ r * ‖f a✝‖ h : OfNat.ofNat 0 a✝ < ‖f a✝‖ ⊢ False [PROOFSTEP] exact not_lt.mpr (norm_nonneg _) (lt_of_le_of_lt hn <| mul_neg_of_neg_of_pos hr₀ h) [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : NormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α l : ℝ hl₁ : l < 1 hf : ∀ᶠ (n : ℕ) in atTop, f n ≠ 0 h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) ⊢ Summable f [PROOFSTEP] rcases exists_between hl₁ with ⟨r, hr₀, hr₁⟩ [GOAL] case intro.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : NormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α l : ℝ hl₁ : l < 1 hf : ∀ᶠ (n : ℕ) in atTop, f n ≠ 0 h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) r : ℝ hr₀ : l < r hr₁ : r < 1 ⊢ Summable f [PROOFSTEP] refine' summable_of_ratio_norm_eventually_le hr₁ _ [GOAL] case intro.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : NormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α l : ℝ hl₁ : l < 1 hf : ∀ᶠ (n : ℕ) in atTop, f n ≠ 0 h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) r : ℝ hr₀ : l < r hr₁ : r < 1 ⊢ ∀ᶠ (n : ℕ) in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖ [PROOFSTEP] filter_upwards [eventually_le_of_tendsto_lt hr₀ h, hf] with _ _ h₁ [GOAL] case h α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝¹ : NormedAddCommGroup α inst✝ : CompleteSpace α f : ℕ → α l : ℝ hl₁ : l < 1 hf : ∀ᶠ (n : ℕ) in atTop, f n ≠ 0 h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) r : ℝ hr₀ : l < r hr₁ : r < 1 a✝¹ : ℕ a✝ : ‖f (a✝¹ + 1)‖ / ‖f a✝¹‖ ≤ r h₁ : f a✝¹ ≠ 0 ⊢ ‖f (a✝¹ + 1)‖ ≤ r * ‖f a✝¹‖ [PROOFSTEP] rwa [← div_le_iff (norm_pos_iff.mpr h₁)] [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∃ᶠ (n : ℕ) in atTop, ‖f n‖ ≠ 0 h : ∀ᶠ (n : ℕ) in atTop, r * ‖f n‖ ≤ ‖f (n + 1)‖ ⊢ ¬Summable f [PROOFSTEP] rw [eventually_atTop] at h [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∃ᶠ (n : ℕ) in atTop, ‖f n‖ ≠ 0 h : ∃ a, ∀ (b : ℕ), b ≥ a → r * ‖f b‖ ≤ ‖f (b + 1)‖ ⊢ ¬Summable f [PROOFSTEP] rcases h with ⟨N₀, hN₀⟩ [GOAL] case intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∃ᶠ (n : ℕ) in atTop, ‖f n‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ ⊢ ¬Summable f [PROOFSTEP] rw [frequently_atTop] at hf [GOAL] case intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ ⊢ ¬Summable f [PROOFSTEP] rcases hf N₀ with ⟨N, hNN₀ : N₀ ≤ N, hN⟩ [GOAL] case intro.intro.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 ⊢ ¬Summable f [PROOFSTEP] rw [← @summable_nat_add_iff α _ _ _ _ N] [GOAL] case intro.intro.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 ⊢ ¬Summable fun n => f (n + N) [PROOFSTEP] refine' mt Summable.tendsto_atTop_zero fun h' ↦ not_tendsto_atTop_of_tendsto_nhds (tendsto_norm_zero.comp h') _ [GOAL] case intro.intro.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) ⊢ Tendsto ((fun a => ‖a‖) ∘ fun n => f (n + N)) atTop atTop [PROOFSTEP] convert tendsto_atTop_of_geom_le _ hr _ [GOAL] case intro.intro.intro.convert_2 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) ⊢ 0 < ((fun a => ‖a‖) ∘ fun n => f (n + N)) 0 [PROOFSTEP] refine' lt_of_le_of_ne (norm_nonneg _) _ [GOAL] case intro.intro.intro.convert_2 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) ⊢ 0 ≠ ((fun a => ‖a‖) ∘ fun n => f (n + N)) 0 [PROOFSTEP] intro h'' [GOAL] case intro.intro.intro.convert_2 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) h'' : 0 = ((fun a => ‖a‖) ∘ fun n => f (n + N)) 0 ⊢ False [PROOFSTEP] specialize hN₀ N hNN₀ [GOAL] case intro.intro.intro.convert_2 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) h'' : 0 = ((fun a => ‖a‖) ∘ fun n => f (n + N)) 0 hN₀ : r * ‖f N‖ ≤ ‖f (N + 1)‖ ⊢ False [PROOFSTEP] simp only [comp_apply, zero_add] at h'' [GOAL] case intro.intro.intro.convert_2 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) hN₀ : r * ‖f N‖ ≤ ‖f (N + 1)‖ h'' : 0 = ‖f N‖ ⊢ False [PROOFSTEP] exact hN h''.symm [GOAL] case intro.intro.intro.convert_3 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) ⊢ ∀ (n : ℕ), r * ((fun a => ‖a‖) ∘ fun n => f (n + N)) n ≤ ((fun a => ‖a‖) ∘ fun n => f (n + N)) (n + 1) [PROOFSTEP] intro i [GOAL] case intro.intro.intro.convert_3 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) i : ℕ ⊢ r * ((fun a => ‖a‖) ∘ fun n => f (n + N)) i ≤ ((fun a => ‖a‖) ∘ fun n => f (n + N)) (i + 1) [PROOFSTEP] dsimp only [comp_apply] [GOAL] case intro.intro.intro.convert_3 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) i : ℕ ⊢ r * ‖f (i + N)‖ ≤ ‖f (i + 1 + N)‖ [PROOFSTEP] convert hN₀ (i + N) (hNN₀.trans (N.le_add_left i)) using 3 [GOAL] case h.e'_4.h.e'_3.h.e'_1 α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α r : ℝ hr : 1 < r hf : ∀ (a : ℕ), ∃ b, b ≥ a ∧ ‖f b‖ ≠ 0 N₀ : ℕ hN₀ : ∀ (b : ℕ), b ≥ N₀ → r * ‖f b‖ ≤ ‖f (b + 1)‖ N : ℕ hNN₀ : N₀ ≤ N hN : ‖f N‖ ≠ 0 h' : Tendsto (fun n => f (n + N)) atTop (𝓝 0) i : ℕ ⊢ i + 1 + N = i + N + 1 [PROOFSTEP] ac_rfl [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α l : ℝ hl : 1 < l h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) ⊢ ¬Summable f [PROOFSTEP] have key : ∀ᶠ n in atTop, ‖f n‖ ≠ 0 := by filter_upwards [eventually_ge_of_tendsto_gt hl h] with _ hn hc rw [hc, _root_.div_zero] at hn linarith [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α l : ℝ hl : 1 < l h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) ⊢ ∀ᶠ (n : ℕ) in atTop, ‖f n‖ ≠ 0 [PROOFSTEP] filter_upwards [eventually_ge_of_tendsto_gt hl h] with _ hn hc [GOAL] case h α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α l : ℝ hl : 1 < l h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) a✝ : ℕ hn : 1 ≤ ‖f (a✝ + 1)‖ / ‖f a✝‖ hc : ‖f a✝‖ = 0 ⊢ False [PROOFSTEP] rw [hc, _root_.div_zero] at hn [GOAL] case h α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α l : ℝ hl : 1 < l h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) a✝ : ℕ hn : 1 ≤ 0 hc : ‖f a✝‖ = 0 ⊢ False [PROOFSTEP] linarith [GOAL] α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α l : ℝ hl : 1 < l h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) key : ∀ᶠ (n : ℕ) in atTop, ‖f n‖ ≠ 0 ⊢ ¬Summable f [PROOFSTEP] rcases exists_between hl with ⟨r, hr₀, hr₁⟩ [GOAL] case intro.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α l : ℝ hl : 1 < l h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) key : ∀ᶠ (n : ℕ) in atTop, ‖f n‖ ≠ 0 r : ℝ hr₀ : 1 < r hr₁ : r < l ⊢ ¬Summable f [PROOFSTEP] refine' not_summable_of_ratio_norm_eventually_ge hr₀ key.frequently _ [GOAL] case intro.intro α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α l : ℝ hl : 1 < l h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) key : ∀ᶠ (n : ℕ) in atTop, ‖f n‖ ≠ 0 r : ℝ hr₀ : 1 < r hr₁ : r < l ⊢ ∀ᶠ (n : ℕ) in atTop, r * ‖f n‖ ≤ ‖f (n + 1)‖ [PROOFSTEP] filter_upwards [eventually_ge_of_tendsto_gt hr₁ h, key] with _ _ h₁ [GOAL] case h α✝ : Type u_1 β : Type u_2 ι : Type u_3 α : Type u_4 inst✝ : SeminormedAddCommGroup α f : ℕ → α l : ℝ hl : 1 < l h : Tendsto (fun n => ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l) key : ∀ᶠ (n : ℕ) in atTop, ‖f n‖ ≠ 0 r : ℝ hr₀ : 1 < r hr₁ : r < l a✝¹ : ℕ a✝ : r ≤ ‖f (a✝¹ + 1)‖ / ‖f a✝¹‖ h₁ : ‖f a✝¹‖ ≠ 0 ⊢ r * ‖f a✝¹‖ ≤ ‖f (a✝¹ + 1)‖ [PROOFSTEP] rwa [← le_div_iff (lt_of_le_of_ne (norm_nonneg _) h₁.symm)] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => ∑ i in Finset.range (n + 1), f i • z i [PROOFSTEP] simp_rw [Finset.sum_range_by_parts _ _ (Nat.succ _), sub_eq_add_neg, Nat.succ_sub_succ_eq_sub, tsub_zero] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => f n • ∑ i in Finset.range (succ n), z i + -∑ x in Finset.range n, (f (x + 1) + -f x) • ∑ i in Finset.range (x + 1), z i [PROOFSTEP] apply (NormedField.tendsto_zero_smul_of_tendsto_zero_of_bounded hf0 ⟨b, eventually_map.mpr <| eventually_of_forall fun n ↦ hgb <| n + 1⟩).cauchySeq.add [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => -∑ x in Finset.range n, (f (x + 1) + -f x) • ∑ i in Finset.range (x + 1), z i [PROOFSTEP] refine' CauchySeq.neg _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => ∑ x in Finset.range n, (f (x + 1) + -f x) • ∑ i in Finset.range (x + 1), z i [PROOFSTEP] refine' cauchySeq_range_of_norm_bounded _ _ (fun n ↦ _ : ∀ n, ‖(f (n + 1) + -f n) • (Finset.range (n + 1)).sum z‖ ≤ b * |f (n + 1) - f n|) [GOAL] case refine'_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => ∑ i in Finset.range n, b * |f (i + 1) - f i| [PROOFSTEP] simp_rw [abs_of_nonneg (sub_nonneg_of_le (hfa (Nat.le_succ _))), ← mul_sum] [GOAL] case refine'_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => b * ∑ x in Finset.range n, (f (succ x) - f x) [PROOFSTEP] apply Real.uniformContinuous_const_mul.comp_cauchySeq [GOAL] case refine'_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => ∑ x in Finset.range n, (f (succ x) - f x) [PROOFSTEP] simp_rw [sum_range_sub, sub_eq_add_neg] [GOAL] case refine'_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => f n + -f 0 [PROOFSTEP] exact (Tendsto.cauchySeq hf0).add_const [GOAL] case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b n : ℕ ⊢ ‖(f (n + 1) + -f n) • Finset.sum (Finset.range (n + 1)) z‖ ≤ b * |f (n + 1) - f n| [PROOFSTEP] rw [norm_smul, mul_comm] [GOAL] case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) hgb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b n : ℕ ⊢ ‖Finset.sum (Finset.range (n + 1)) z‖ * ‖f (n + 1) + -f n‖ ≤ b * |f (n + 1) - f n| [PROOFSTEP] exact mul_le_mul_of_nonneg_right (hgb _) (abs_nonneg _) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) hzb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b ⊢ CauchySeq fun n => ∑ i in Finset.range (n + 1), f i • z i [PROOFSTEP] have hfa' : Monotone fun n ↦ -f n := fun _ _ hab ↦ neg_le_neg <| hfa hab [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) hzb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b hfa' : Monotone fun n => -f n ⊢ CauchySeq fun n => ∑ i in Finset.range (n + 1), f i • z i [PROOFSTEP] have hf0' : Tendsto (fun n ↦ -f n) atTop (𝓝 0) := by convert hf0.neg norm_num [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) hzb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b hfa' : Monotone fun n => -f n ⊢ Tendsto (fun n => -f n) atTop (𝓝 0) [PROOFSTEP] convert hf0.neg [GOAL] case h.e'_5.h.e'_3 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) hzb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b hfa' : Monotone fun n => -f n ⊢ 0 = -0 [PROOFSTEP] norm_num [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) hzb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b hfa' : Monotone fun n => -f n hf0' : Tendsto (fun n => -f n) atTop (𝓝 0) ⊢ CauchySeq fun n => ∑ i in Finset.range (n + 1), f i • z i [PROOFSTEP] convert (hfa'.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0' hzb).neg [GOAL] case h.e'_5.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) hzb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b hfa' : Monotone fun n => -f n hf0' : Tendsto (fun n => -f n) atTop (𝓝 0) x✝ : ℕ ⊢ ∑ i in Finset.range (x✝ + 1), f i • z i = (-fun n => ∑ i in Finset.range (n + 1), -f i • z i) x✝ [PROOFSTEP] funext [GOAL] case h.e'_5.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) hzb : ∀ (n : ℕ), ‖∑ i in Finset.range n, z i‖ ≤ b hfa' : Monotone fun n => -f n hf0' : Tendsto (fun n => -f n) atTop (𝓝 0) x✝ : ℕ ⊢ ∑ i in Finset.range (x✝ + 1), f i • z i = (-fun n => ∑ i in Finset.range (n + 1), -f i • z i) x✝ [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E n : ℕ ⊢ ‖∑ i in Finset.range n, (-1) ^ i‖ ≤ 1 [PROOFSTEP] rw [neg_one_geom_sum] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E n : ℕ ⊢ ‖if Even n then 0 else 1‖ ≤ 1 [PROOFSTEP] split_ifs [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E n : ℕ h✝ : Even n ⊢ ‖0‖ ≤ 1 [PROOFSTEP] norm_num [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E n : ℕ h✝ : ¬Even n ⊢ ‖1‖ ≤ 1 [PROOFSTEP] norm_num [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) ⊢ CauchySeq fun n => ∑ i in Finset.range (n + 1), (-1) ^ i * f i [PROOFSTEP] simp_rw [mul_comm] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Monotone f hf0 : Tendsto f atTop (𝓝 0) ⊢ CauchySeq fun n => ∑ x in Finset.range (n + 1), f x * (-1) ^ x [PROOFSTEP] exact hfa.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0 norm_sum_neg_one_pow_le [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) ⊢ CauchySeq fun n => ∑ i in Finset.range (n + 1), (-1) ^ i * f i [PROOFSTEP] simp_rw [mul_comm] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E b : ℝ f : ℕ → ℝ z : ℕ → E hfa : Antitone f hf0 : Tendsto f atTop (𝓝 0) ⊢ CauchySeq fun n => ∑ x in Finset.range (n + 1), f x * (-1) ^ x [PROOFSTEP] exact hfa.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0 norm_sum_neg_one_pow_le [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ ⊢ Summable fun n => x ^ n / ↑n ! [PROOFSTEP] have A : (0 : ℝ) < ⌊‖x‖⌋₊ + 1 := zero_lt_one.trans_le (by simp) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ ⊢ 1 ≤ ↑⌊‖x‖⌋₊ + 1 [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ A : 0 < ↑⌊‖x‖⌋₊ + 1 ⊢ Summable fun n => x ^ n / ↑n ! [PROOFSTEP] have B : ‖x‖ / (⌊‖x‖⌋₊ + 1) < 1 := (div_lt_one A).2 (Nat.lt_floor_add_one _) -- Then we apply the ratio test. The estimate works for `n ≥ ⌊‖x‖⌋₊`. [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ A : 0 < ↑⌊‖x‖⌋₊ + 1 B : ‖x‖ / (↑⌊‖x‖⌋₊ + 1) < 1 ⊢ Summable fun n => x ^ n / ↑n ! [PROOFSTEP] suffices : ∀ n ≥ ⌊‖x‖⌋₊, ‖x ^ (n + 1) / (n + 1)!‖ ≤ ‖x‖ / (⌊‖x‖⌋₊ + 1) * ‖x ^ n / ↑n !‖ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ A : 0 < ↑⌊‖x‖⌋₊ + 1 B : ‖x‖ / (↑⌊‖x‖⌋₊ + 1) < 1 this : ∀ (n : ℕ), n ≥ ⌊‖x‖⌋₊ → ‖x ^ (n + 1) / ↑(n + 1)!‖ ≤ ‖x‖ / (↑⌊‖x‖⌋₊ + 1) * ‖x ^ n / ↑n !‖ ⊢ Summable fun n => x ^ n / ↑n ! case this α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ A : 0 < ↑⌊‖x‖⌋₊ + 1 B : ‖x‖ / (↑⌊‖x‖⌋₊ + 1) < 1 ⊢ ∀ (n : ℕ), n ≥ ⌊‖x‖⌋₊ → ‖x ^ (n + 1) / ↑(n + 1)!‖ ≤ ‖x‖ / (↑⌊‖x‖⌋₊ + 1) * ‖x ^ n / ↑n !‖ [PROOFSTEP] exact summable_of_ratio_norm_eventually_le B (eventually_atTop.2 ⟨⌊‖x‖⌋₊, this⟩) -- Finally, we prove the upper estimate [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ A : 0 < ↑⌊‖x‖⌋₊ + 1 B : ‖x‖ / (↑⌊‖x‖⌋₊ + 1) < 1 ⊢ ∀ (n : ℕ), n ≥ ⌊‖x‖⌋₊ → ‖x ^ (n + 1) / ↑(n + 1)!‖ ≤ ‖x‖ / (↑⌊‖x‖⌋₊ + 1) * ‖x ^ n / ↑n !‖ [PROOFSTEP] intro n hn [GOAL] case this α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ A : 0 < ↑⌊‖x‖⌋₊ + 1 B : ‖x‖ / (↑⌊‖x‖⌋₊ + 1) < 1 n : ℕ hn : n ≥ ⌊‖x‖⌋₊ ⊢ ‖x ^ (n + 1) / ↑(n + 1)!‖ ≤ ‖x‖ / (↑⌊‖x‖⌋₊ + 1) * ‖x ^ n / ↑n !‖ [PROOFSTEP] calc ‖x ^ (n + 1) / (n + 1)!‖ = ‖x‖ / (n + 1) * ‖x ^ n / (n !)‖ := by rw [_root_.pow_succ, Nat.factorial_succ, Nat.cast_mul, ← _root_.div_mul_div_comm, norm_mul, norm_div, Real.norm_coe_nat, Nat.cast_succ] _ ≤ ‖x‖ / (⌊‖x‖⌋₊ + 1) * ‖x ^ n / (n !)‖ := -- Porting note: this was `by mono* with 0 ≤ ‖x ^ n / (n !)‖, 0 ≤ ‖x‖ <;> apply norm_nonneg` -- but we can't wait on `mono`.mul_le_mul_of_nonneg_right (div_le_div (norm_nonneg x) (le_refl ‖x‖) A (add_le_add (mono_cast hn) (le_refl 1))) (norm_nonneg (x ^ n / n !)) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 x : ℝ A : 0 < ↑⌊‖x‖⌋₊ + 1 B : ‖x‖ / (↑⌊‖x‖⌋₊ + 1) < 1 n : ℕ hn : n ≥ ⌊‖x‖⌋₊ ⊢ ‖x ^ (n + 1) / ↑(n + 1)!‖ = ‖x‖ / (↑n + 1) * ‖x ^ n / ↑n !‖ [PROOFSTEP] rw [_root_.pow_succ, Nat.factorial_succ, Nat.cast_mul, ← _root_.div_mul_div_comm, norm_mul, norm_div, Real.norm_coe_nat, Nat.cast_succ]
section \<open> Multiplication Groups \<close> theory Groups_mult imports Main begin text \<open> The HOL standard library only has groups based on addition. Here, we build one based on multiplication. \<close> notation times (infixl "\<cdot>" 70) class group_mult = inverse + monoid_mult + assumes left_inverse: "inverse a \<cdot> a = 1" assumes multi_inverse_conv_div [simp]: "a \<cdot> (inverse b) = a / b" begin lemma div_conv_mult_inverse: "a / b = a \<cdot> (inverse b)" by simp sublocale mult: group times 1 inverse by standard (simp_all add: left_inverse) lemma diff_self [simp]: "a / a = 1" using mult.right_inverse by auto lemma mult_distrib_inverse [simp]: "(a * b) / b = a" by (metis local.mult_1_right local.multi_inverse_conv_div mult.right_inverse mult_assoc) end class ab_group_mult = comm_monoid_mult + group_mult begin lemma mult_distrib_inverse' [simp]: "(a * b) / a = b" using local.mult_distrib_inverse mult_commute by fastforce lemma inverse_distrib: "inverse (a * b) = (inverse a) * (inverse b)" by (simp add: local.mult.inverse_distrib_swap mult_commute) lemma inverse_divide [simp]: "inverse (a / b) = b / a" by (metis div_conv_mult_inverse inverse_distrib mult.commute mult.inverse_inverse) end abbreviation (input) npower :: "'a::{power,inverse} \<Rightarrow> nat \<Rightarrow> 'a" ("(_\<^sup>-\<^sup>_)" [1000,999] 999) where "npower x n \<equiv> inverse (x ^ n)" end
module DelayMishMash where open import Level --public using (Level) renaming (zero to lzero; suc to lsuc) open import Size public open import Prelude.Monad renaming (Monad to RawMonad) --open import Category.Monad public -- using (RawMonad; module RawMonad) open import Data.Empty --public using (⊥; ⊥-elim) open import Data.List --public using (List; []; _∷_; map) open import Data.Maybe --public using (Maybe; just; nothing) renaming (map to fmap) open import Data.Product public using (∃; _×_; _,_) renaming (proj₁ to fst; proj₂ to snd) --infixr 1 _,_ open import Data.Sum --public using (_⊎_; [_,_]′) renaming (inj₁ to inl; inj₂ to inr) open import Data.Unit --public using (⊤) open import Function --public using (_∘_; case_of_) open import Relation.Nullary --public using (Dec; yes; no) open import Relation.Binary --public using (Setoid; module Setoid) import Relation.Binary.PreorderReasoning module Pre = Relation.Binary.PreorderReasoning open import Relation.Binary.PropositionalEquality --public using (_≡_; refl; sym; trans; cong; cong₂; subst; module ≡-Reasoning) --open ≡-Reasoning renaming (begin_ to proof_) public open import Relation.Binary.HeterogeneousEquality --public using (_≅_; refl; ≡-to-≅; module ≅-Reasoning) renaming (sym to hsym; trans to htrans; cong to hcong; cong₂ to hcong₂; subst to hsubst) hcong₃ : {A : Set}{B : A → Set}{C : ∀ a → B a → Set}{D : ∀ a b → C a b → Set} (f : ∀ a b c → D a b c) {a a′ : A} → a ≅ a′ → {b : B a}{b′ : B a′} → b ≅ b′ → {c : C a b}{c′ : C a′ b′} → c ≅ c′ → f a b c ≅ f a′ b′ c′ hcong₃ f refl refl refl = refl ≅-to-≡ : ∀ {a} {A : Set a} {x y : A} → x ≅ y → x ≡ y ≅-to-≡ refl = refl mutual data Delay (i : Size) (A : Set) : Set where now : A → Delay i A later : ∞Delay i A → Delay i A record ∞Delay (i : Size) (A : Set) : Set where coinductive field force : {j : Size< i} → Delay j A open ∞Delay public never : ∀{i A} → ∞Delay i A force (never {i}) {j} = later (never {j}) module Bind where mutual bindDelay : ∀ {i A B} → Delay i A → (A → Delay i B) → Delay i B bindDelay (now a) f = f a bindDelay (later a∞) f = later (bind∞Delay a∞ f) bind∞Delay : ∀ {i A B} → ∞Delay i A → (A → Delay i B) → ∞Delay i B force (bind∞Delay a∞ f) = bindDelay (force a∞) f _d>>=_ : ∀ {i A B} → Delay i A → (A → Delay i B) → Delay i B _d>>=_ {i} = Bind.bindDelay {i} {- open import Prelude.Applicative using (Applicative) instance delayApplicative : ∀ {i} → Applicative (Delay i) Applicative.pure (delayApplicative {i}) x = now x Applicative._<*>_ (delayApplicative {i}) (now f) x = x d>>= (now ∘ f) Applicative._<*>_ (delayApplicative {i}) (later f) x = {!force f {i}!} {- Applicative._<*>_ (delayApplicative {i}) f (now x) = {!x!} -- Bind.bindDelay x (λ x₁ → {!!}) Applicative._<*>_ (delayApplicative {i}) (now f) (later x) = {!!} -- Bind.bindDelay x (λ x₁ → {!!}) Applicative._<*>_ (delayApplicative {i}) (later f) (later x) = {!!} -- Bind.bindDelay x (λ x₁ → {!!}) -} Applicative.super (delayApplicative {i}) = {!!} -} {- instance delayMonad : ∀ {i} → RawMonad (Delay i) delayMonad {i} = record { {-return = now ; -}_>>=_ = bindDelay {i} } where open Bind -} {- module _ {i : Size} where open module DelayMonad = RawMonad (delayMonad {i = i}) public -- renaming (_⊛_ to _<*>_) -} open Bind public using () renaming (bind∞Delay to _∞>>=_) -- Map for Delay dreturn : {i : Size} → {A : Set} → A → Delay i A dreturn {i} = Delay.now {i} _d<$>_ : ∀ {i A B} (f : A → B) (a : Delay i A) → Delay i B f d<$> a = a d>>= λ a → dreturn (f a) -- Map for ∞Delay _∞<$>_ : ∀ {i A B} (f : A → B) (∞a : ∞Delay i A) → ∞Delay i B f ∞<$> ∞a = ∞a ∞>>= λ a → dreturn (f a) -- force (f ∞<$> ∞a) = f <$> force ∞a -- Double bind _=<<2_,_ : ∀ {i A B C} → (A → B → Delay i C) → Delay i A → Delay i B → Delay i C f =<<2 x , y = x d>>= λ a → y d>>= λ b → f a b mutual data _∼_ {i : Size} {A : Set} : (a? b? : Delay ∞ A) → Set where ∼now : ∀ a → now a ∼ now a ∼later : ∀ {a∞ b∞} (eq : a∞ ∞∼⟨ i ⟩∼ b∞) → later a∞ ∼ later b∞ _∼⟨_⟩∼_ = λ {A} a? i b? → _∼_ {i}{A} a? b? record _∞∼⟨_⟩∼_ {A} (a∞ : ∞Delay ∞ A) i (b∞ : ∞Delay ∞ A) : Set where coinductive field ∼force : {j : Size< i} → force a∞ ∼⟨ j ⟩∼ force b∞ _∞∼_ = λ {i} {A} a∞ b∞ → _∞∼⟨_⟩∼_ {A} a∞ i b∞ open _∞∼⟨_⟩∼_ public ∼never : ∀{i A} → (never {A = A}) ∞∼⟨ i ⟩∼ never ∼force ∼never = ∼later ∼never ∼refl : ∀{i A} (a? : Delay ∞ A) → a? ∼⟨ i ⟩∼ a? ∞∼refl : ∀{i A} (a∞ : ∞Delay ∞ A) → a∞ ∞∼⟨ i ⟩∼ a∞ ∼sym : ∀{i A}{a? b? : Delay ∞ A } → a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ a? ∞∼sym : ∀{i A}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ a∞ ∼trans : ∀{i A}{a? b? c? : Delay ∞ A} → a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ c? → a? ∼⟨ i ⟩∼ c? ∞∼trans : ∀{i A}{a∞ b∞ c∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ c∞ → a∞ ∞∼⟨ i ⟩∼ c∞ ∼refl (now a) = ∼now a ∼refl (later a∞) = ∼later (∞∼refl a∞) ∼force (∞∼refl a∞) = ∼refl (force a∞) ∼sym (∼now a) = ∼now a ∼sym (∼later eq) = ∼later (∞∼sym eq) ∼force (∞∼sym eq) = ∼sym (∼force eq) ∼trans (∼now a) (∼now .a) = ∼now a ∼trans (∼later eq) (∼later eq′) = ∼later (∞∼trans eq eq′) ∼force (∞∼trans eq eq′) = ∼trans (∼force eq) (∼force eq′) -- Equality reasoning ∼setoid : (i : Size) (A : Set) → Setoid lzero lzero ∼setoid i A = record { Carrier = Delay ∞ A ; _≈_ = _∼_ {i} ; isEquivalence = record { refl = λ {a?} → ∼refl a? ; sym = ∼sym ; trans = ∼trans } } ∞∼setoid : (i : Size) (A : Set) → Setoid lzero lzero ∞∼setoid i A = record { Carrier = ∞Delay ∞ A ; _≈_ = _∞∼_ {i} ; isEquivalence = record { refl = λ {a?} → ∞∼refl a? ; sym = ∞∼sym ; trans = ∞∼trans } } module ∼-Reasoning {i : Size} {A : Set} where open Pre (Setoid.preorder (∼setoid i A)) public -- using (begin_; _∎) (_≈⟨⟩_ to _∼⟨⟩_; _≈⟨_⟩_ to _∼⟨_⟩_) renaming (_≈⟨⟩_ to _≡⟨⟩_; _≈⟨_⟩_ to _≡⟨_⟩_; _∼⟨_⟩_ to _∼⟨_⟩_; begin_ to proof_) module ∞∼-Reasoning {i : Size} {A : Set} where open Pre (Setoid.preorder (∞∼setoid i A)) public -- using (begin_; _∎) (_≈⟨⟩_ to _∼⟨⟩_; _≈⟨_⟩_ to _∼⟨_⟩_) renaming (_≈⟨⟩_ to _≡⟨⟩_; _≈⟨_⟩_ to _≡⟨_⟩_; _∼⟨_⟩_ to _∞∼⟨_⟩_; begin_ to proof_) mutual bind-assoc : ∀{i A B C} (m : Delay ∞ A) {k : A → Delay ∞ B} {l : B → Delay ∞ C} → ((m d>>= k) d>>= l) ∼⟨ i ⟩∼ (m d>>= λ a → (k a d>>= l)) bind-assoc (now a) = ∼refl _ bind-assoc (later a∞) = ∼later (∞bind-assoc a∞) ∞bind-assoc : ∀{i A B C} (a∞ : ∞Delay ∞ A) {k : A → Delay ∞ B} {l : B → Delay ∞ C} → ((a∞ ∞>>= k) ∞>>= l) ∞∼⟨ i ⟩∼ (a∞ ∞>>= λ a → (k a d>>= l)) ∼force (∞bind-assoc a∞) = bind-assoc (force a∞) bind-cong-l : ∀{i A B}{a? b? : Delay ∞ A} → a? ∼⟨ i ⟩∼ b? → (k : A → Delay ∞ B) → (a? d>>= k) ∼⟨ i ⟩∼ (b? d>>= k) ∞bind-cong-l : ∀{i A B}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ → (k : A → Delay ∞ B) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (b∞ ∞>>= k) bind-cong-r : ∀{i A B}(a? : Delay ∞ A){k l : A → Delay ∞ B} → (∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a? d>>= k) ∼⟨ i ⟩∼ (a? d>>= l) ∞bind-cong-r : ∀{i A B}(a∞ : ∞Delay ∞ A){k l : A → Delay ∞ B} → (∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (a∞ ∞>>= l) bind-cong-l (∼now a) k = ∼refl _ bind-cong-l (∼later eq) k = ∼later (∞bind-cong-l eq k) ∼force (∞bind-cong-l eq k) = bind-cong-l (∼force eq) k bind-cong-r (now a) h = h a bind-cong-r (later a∞) h = ∼later (∞bind-cong-r a∞ h) ∼force (∞bind-cong-r a∞ h) = bind-cong-r (force a∞) h open import Prelude.Functor using (Functor; _<$>_) {- instance FunctorDelay : {i : Size} → Functor (Delay i) Functor.fmap (FunctorDelay {i}) {A} {B} f (now x) = {!!} Functor.fmap (FunctorDelay {i}) {A} {B} f (later x) = {!!} -} open import Prelude.Function using (_∘′_) map-compose : ∀{i A B C} (a? : Delay ∞ A) {f : A → B} {g : B → C} → (g d<$> (f d<$> a?)) ∼⟨ i ⟩∼ ((g ∘ f) d<$> a?) map-compose a? = bind-assoc a? map-cong : ∀{i A B}{a? b? : Delay ∞ A} (f : A → B) → a? ∼⟨ i ⟩∼ b? → (f d<$> a?) ∼⟨ i ⟩∼ (f d<$> b?) map-cong f eq = bind-cong-l eq (now ∘ f) data _⇓_ {A : Set} : (a? : Delay ∞ A) (a : A) → Set where now⇓ : ∀{a} → now a ⇓ a later⇓ : ∀{a} {a∞ : ∞Delay ∞ A} → force a∞ ⇓ a → later a∞ ⇓ a _⇓ : {A : Set} (x : Delay ∞ A) → Set x ⇓ = ∃ λ a → x ⇓ a map⇓ : ∀{A B}{a : A}{a? : Delay ∞ A}(f : A → B) → a? ⇓ a → (f d<$> a?) ⇓ f a subst∼⇓ : ∀{A}{a? a?′ : Delay ∞ A}{a : A} → a? ⇓ a → a? ∼ a?′ → a?′ ⇓ a bind⇓ : ∀{A B}(f : A → Delay ∞ B){?a : Delay ∞ A}{a : A}{b : B} → ?a ⇓ a → f a ⇓ b → (?a d>>= f) ⇓ b map⇓ f now⇓ = now⇓ map⇓ f (later⇓ a⇓) = later⇓ (map⇓ f a⇓) subst∼⇓ now⇓ (∼now a) = now⇓ subst∼⇓ (later⇓ p) (∼later eq) = later⇓ (subst∼⇓ p (∼force eq)) bind⇓ f now⇓ q = q bind⇓ f (later⇓ p) q = later⇓ (bind⇓ f p q) --infixr 6 _⇒_ --infixl 1 _,_
[STATEMENT] lemma norm_ell2_code [code]: \<comment> \<open>Code equation for the norm of a vector\<close> "norm \<psi> = (let \<psi>' = vec_of_ell2 \<psi> in sqrt (\<Sum> i \<in> {0 ..< dim_vec \<psi>'}. let z = vec_index \<psi>' i in (Re z)\<^sup>2 + (Im z)\<^sup>2))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. norm \<psi> = (let \<psi>' = vec_of_ell2 \<psi> in sqrt (\<Sum>i = 0..<dim_vec \<psi>'. let z = \<psi>' $ i in (Re z)\<^sup>2 + (Im z)\<^sup>2)) [PROOF STEP] by (simp add: norm_ell2_vec_of_basis_enum vec_of_ell2_def)
lemma order_decomp: assumes "p \<noteq> 0" shows "\<exists>q. p = [:- a, 1:] ^ order a p * q \<and> \<not> [:- a, 1:] dvd q"
[STATEMENT] lemma (in weak_complete_lattice) inf_closed [simp]: "A \<subseteq> carrier L ==> \<Sqinter>A \<in> carrier L" [PROOF STATE] proof (prove) goal (1 subgoal): 1. A \<subseteq> carrier L \<Longrightarrow> \<Sqinter>A \<in> carrier L [PROOF STEP] by (rule infI) simp_all
/* $Header$ */ /* Purpose: GSL functions that handle missing values - stubs only Extra NCO code derived from GSL removed 2020-04-02 to avoid license conflict between GSL GPL and NCO BSD code */ /* Copyright (C) 1995--present Charlie Zender This file is part of NCO, the netCDF Operators. NCO is free software. You may redistribute and/or modify NCO under the terms of the 3-Clause BSD License with exceptions described in the LICENSE file */ #include <gsl/gsl_statistics.h> #include <gsl/gsl_fit.h> #include "nco_gsl.h" /* Missing value-aware GSL functions */ /* Fit the data (x_i, y_i) to the linear relationship Y = c0 + c1 x returning, c0, c1 -- coefficients cov00, cov01, cov11 -- variance-covariance matrix of c0 and c1, sumsq -- sum of squares of residuals This fit can be used in the case where the errors for the data are uknown, but assumed equal for all points. The resulting variance-covariance matrix estimates the error in the coefficients from the observed variance of the points around the best fit line. */ int nco_gsl_fit_linear (const double *x, const size_t xstride, const double *y, const size_t ystride, const size_t n, double *c0, double *c1, double *cov_00, double *cov_01, double *cov_11, double *sumsq, const double *mss_val) { return gsl_fit_linear(x, xstride, y, ystride, n, c0, c1, cov_00, cov_01, cov_11, sumsq); } static double compute_covariance (const double data1[], const size_t stride1, const double data2[], const size_t stride2, const size_t n, const double mean1, const double mean2, const double *mss_val) /* Missing value */ { /* takes a dataset and finds the covariance */ long double covariance = 0 ; size_t i; /* find the sum of the squares */ if (mss_val==NULL) { for (i = 0; i < n; i++) { const long double delta1 = (data1[i * stride1] - mean1); const long double delta2 = (data2[i * stride2] - mean2); covariance += (delta1 * delta2 - covariance) / (i + 1); } } else { for (i = 0; i < n; i++) { if (data2[i * stride2]!=*mss_val) { const long double delta1 = (data1[i * stride1] - mean1); const long double delta2 = (data2[i * stride2] - mean2); covariance += (delta1 * delta2 - covariance) / (i + 1); } } } return covariance ; } double nco_gsl_stats_covariance_m (const double data1[], const size_t stride1, const double data2[], const size_t stride2, const size_t n, const double mean1, const double mean2, const double *mss_val) /* Missing value */ { return gsl_stats_covariance_m(data1, stride1, data2,stride2,n,mean1,mean2); } double nco_gsl_stats_covariance (const double data1[], const size_t stride1, const double data2[], const size_t stride2, const size_t n, const double *mss_val) /* Missing value */ { return gsl_stats_covariance(data1, stride1, data2,stride2,n); } double nco_gsl_stats_mean (const double data[], const size_t stride, const size_t size, const double *mss_val) /* Missing value */ { return gsl_stats_mean(data, stride, size); }
(* Title: variants/c_gtobcast/OAodv.thy License: BSD 2-Clause. See LICENSE. Author: Timothy Bourke, Inria *) section "The `open' AODV model" theory C_OAodv imports C_Aodv AWN.OAWN_SOS_Labels AWN.OAWN_Convert begin text \<open>Definitions for stating and proving global network properties over individual processes.\<close> definition \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V' :: "((ip \<Rightarrow> state) \<times> ((state, msg, pseqp, pseqp label) seqp)) set" where "\<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V' \<equiv> {(\<lambda>i. aodv_init i, \<Gamma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V PAodv)}" abbreviation opaodv :: "ip \<Rightarrow> ((ip \<Rightarrow> state) \<times> (state, msg, pseqp, pseqp label) seqp, msg seq_action) automaton" where "opaodv i \<equiv> \<lparr> init = \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V', trans = oseqp_sos \<Gamma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V i \<rparr>" lemma initiali_aodv [intro!, simp]: "initiali i (init (opaodv i)) (init (paodv i))" unfolding \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V_def \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V'_def by rule simp_all lemma oaodv_control_within [simp]: "control_within \<Gamma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V (init (opaodv i))" unfolding \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V'_def by (rule control_withinI) (auto simp del: \<Gamma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V_simps) lemma \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V'_labels [simp]: "(\<sigma>, p) \<in> \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V' \<Longrightarrow> labels \<Gamma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V p = {PAodv-:0}" unfolding \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V'_def by simp lemma oaodv_init_kD_empty [simp]: "(\<sigma>, p) \<in> \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V' \<Longrightarrow> kD (rt (\<sigma> i)) = {}" unfolding \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V'_def kD_def by simp lemma oaodv_init_vD_empty [simp]: "(\<sigma>, p) \<in> \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V' \<Longrightarrow> vD (rt (\<sigma> i)) = {}" unfolding \<sigma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V'_def vD_def by simp lemma oaodv_trans: "trans (opaodv i) = oseqp_sos \<Gamma>\<^sub>A\<^sub>O\<^sub>D\<^sub>V i" by simp declare oseq_invariant_ctermsI [OF aodv_wf oaodv_control_within aodv_simple_labels oaodv_trans, cterms_intros] oseq_step_invariant_ctermsI [OF aodv_wf oaodv_control_within aodv_simple_labels oaodv_trans, cterms_intros] end
State Before: F : Type u → Type u inst✝¹ : Applicative F inst✝ : CommApplicative F α' β' : Type u f : α' → F β' α : Type u_1 x : Multiset α ⊢ traverse pure x = x State After: F : Type u → Type u inst✝¹ : Applicative F inst✝ : CommApplicative F α' β' : Type u f : α' → F β' α : Type u_1 x : Multiset α ⊢ ∀ (a : List α), traverse pure (Quotient.mk (isSetoid α) a) = Quotient.mk (isSetoid α) a Tactic: refine' Quotient.inductionOn x _ State Before: F : Type u → Type u inst✝¹ : Applicative F inst✝ : CommApplicative F α' β' : Type u f : α' → F β' α : Type u_1 x : Multiset α ⊢ ∀ (a : List α), traverse pure (Quotient.mk (isSetoid α) a) = Quotient.mk (isSetoid α) a State After: F : Type u → Type u inst✝¹ : Applicative F inst✝ : CommApplicative F α' β' : Type u f : α' → F β' α : Type u_1 x : Multiset α a✝ : List α ⊢ traverse pure (Quotient.mk (isSetoid α) a✝) = Quotient.mk (isSetoid α) a✝ Tactic: intro State Before: F : Type u → Type u inst✝¹ : Applicative F inst✝ : CommApplicative F α' β' : Type u f : α' → F β' α : Type u_1 x : Multiset α a✝ : List α ⊢ traverse pure (Quotient.mk (isSetoid α) a✝) = Quotient.mk (isSetoid α) a✝ State After: no goals Tactic: simp [traverse, Coe.coe]
The nave measures 98 feet ( 30 m ) between the entrance and the communion rail . An aisle passes down its center ; narrower aisles follow the north and south walls . Two rows of seven circular columns run along the nave . The columns are made of wood , plastered to conceal the material , and decorated with Corinthian capitals . The rib @-@ vaulted ceiling rises 30 feet ( 9 @.@ 1 m ) above the floor . Fourteen stained @-@ glass windows , depicting scenes from the life of Christ , occupy the nave 's walls . The 13 @.@ 5 @-@ by @-@ 5 @-@ foot ( 4 @.@ 1 m × 1 @.@ 5 m ) windows were produced by the Muenich Art Studio of Chicago . Between the windows are sculpted stations of the cross . In three spandrels above columns on each side are fresco paintings .
""" gams = parsegams(filename) Do low-level lexing and parsing, but do not try to compile into a module. """ function parsegams(lexed::Vector{AbstractLex}) gams = Dict{String,Any}() i = 1 while i <= length(lexed) stmt = lexed[i] if stmt isa StatementEnd # do nothing elseif stmt isa Keyword kwname = stmt.text if kwname == "sets" sets = getdefault!(gams, kwname, Dict{String,Any}) newsets = Dict{String,Vector{String}}() i = parse_slashed!(newsets, lexed, i) # Scan for i*j range declarations for (k, s) in newsets if length(s) == 1 m = match(r"(\d+)\s*\*\s*(\d+)", s[1]) if m != nothing lo, hi = parse(Int, m.captures[1]), parse(Int, m.captures[2]) sets[k] = lo == 1 ? Base.OneTo(hi) : (lo:hi) else sets[k] = s end else sets[k] = s end end elseif kwname == "alias" alias = lexed[i+=1] @assert(alias isa Parens && length(alias.args) == 3 && alias.args[2] == GText(",")) sets = gams["sets"] symold, symnew = string(alias.args[1]), string(alias.args[3]) if !haskey(sets, symold) # GAMS allows arbitrary ordering symnew, symold = symold, symnew end sets[symnew] = sets[symold] elseif kwname == "scalars" || kwname == "parameters" params = getdefault!(gams, "parameters", Dict{Any,Any}) i = parse_slashed!(params, lexed, i; parseitems=false) elseif kwname == "table" table = getdefault!(gams, "tables", Dict{Any,Any}) item = lexed[i+=1] table[item.name] = item.body # Some GAMS files declare it a parameter and then a table; remove it # from parameters if haskey(gams, "parameters") params = gams["parameters"] key = GText(getname(item.name)) if haskey(params, key) delete!(params, key) end end elseif kwname == "variables" || kwname ∈ vartypes attr = "free" if kwname ∈ vartypes attr = kwname kw = lexed[i+=1] @assert(kw == Keyword("variables")) end sets = get(gams, "sets", nothing) variables = getdefault!(gams, "variables", OrderedDict{Any,VarInfo}) while i < length(lexed) && !isa(lexed[i+1], StatementEnd) && !isa(lexed[i+1], Keyword) var = lexed[i+=1] var == GText(",") && continue @assert(var isa GText || var isa GArray) push!(variables, varinfo(var, attr, sets)) end elseif kwname == "models" models = getdefault!(gams, kwname, Dict{String,ModelInfo}) newmodels = Dict{String,Any}() i = parse_slashed!(newmodels, lexed, i) for (k,v) in newmodels models[k] = ModelInfo(v) end elseif kwname == "options" options = getdefault!(gams, kwname) str = lexed[i+=1] while !isa(lexed[i+1], StatementEnd) if lexed[i+1] == GText("=") options[str.text] = string(lexed[i+2]) i+=1 else options[str.text] = "" end i += 1 end elseif kwname == "solve" newkw = lexed[i+=1] while !isa(newkw, Keyword) || newkw.text == "using" newkw = lexed[i+=1] end @assert newkw.text == "minimizing" || newkw.text == "maximizing" modelname = lexed[i+=1] gams[newkw.text] = modelname.text elseif kwname == "equations" eqs = getdefault!(gams, kwname, OrderedDict{Any,Any}) while i < length(lexed) && !isa(lexed[i+1], StatementEnd) && !isa(lexed[i+1], Keyword) eq = lexed[i+=1] @assert(eq isa GText || eq isa GArray) # push!(eqs, eq=>"") # add later so the ordering respects the definition order, not decl order end elseif kwname == "files" filename = lexed[i+=1] newkw = lexed[i+=1] while newkw != GText("putclose") || lexed[i+1] != filename newkw = lexed[i+=1] end newkw = lexed[i+=1] while !isa(newkw, StatementEnd) newkw = lexed[i+=1] end elseif kwname ∈ Set(["display"]) newkw = lexed[i+=1] while !isa(newkw, StatementEnd) newkw = lexed[i+=1] end else error("unhandled keyword ", kwname) end else @assert(stmt isa GText || stmt isa GArray) if length(lexed) < i+1 # some files seem to have junk after the last semicolon println("skipping trailing ", stmt) break end if lexed[i+1] == Dots("..") # an equation definition eqs = gams["equations"] iend = seek_to_end(lexed, i+=2) eqs[stmt] = parseexprs1(lexed[i:iend]) i = iend elseif lexed[i+1] == Dots(".") # a variable or model attribute @assert(lexed[i+3] == GText("=")) attr = lexed[i+=2] iend = seek_to_end(lexed, i+=2) rhs = parseexprs1(lexed[i:iend]) if attr isa GText && string(attr) ∈ modelattributes m = gams["models"][string(stmt)] m.assignments[string(attr)] = rhs else attrstr = isa(attr, GText) ? string(attr) : attr.name varkey = isa(attr, GText) ? stmt : GArray(string(stmt), attr.indices) if attrstr ∈ varattributes v = gams["variables"][varkey] # gams["variables"][stmt] ? push!(v.assignments, attr=>rhs) else error(attr, " not a recognized attribute") end end i = iend else # general assignment (to, e.g., a parameter) @assert lexed[i+1] == GText("=") iend = seek_to_end(lexed, i+=2) assign = getdefault!(gams, "assignments", Vector{Pair{Any,Any}}) push!(assign, stmt=>parseexprs1(lexed[i:iend])) i = iend end end i += 1 end return gams end parsegams(arg) = parsegams(lex(arg)) function parse_slashed!(dest, lexed, i; parseitems::Bool=true) function parse_slashed1!(dest, lexed, i) name = lexed[i+=1] @assert(name isa GText || name isa GArray) if lexed[i+1] isa StatementEnd dest[name] = "" return i elseif lexed[i+1] isa Slashed val = lexed[i+=1] elseif lexed[i+1] isa GText && lexed[i+2] isa Slashed val = lexed[i+=2] else dest[name] = "" return i end @assert(val isa Slashed) if parseitems items = strip.(split(val.text, (',','\n'))) # drop text for each item for j = 1:length(items) itemname, itemtext = splitws(items[j]) items[j] = itemname end dest[convert(keytype(dest), name)] = items else dest[name] = val.text end return i end i = parse_slashed1!(dest, lexed, i) while i < length(lexed) && !isa(lexed[i+1], StatementEnd) && !isa(lexed[i+1], Keyword) i = parse_slashed1!(dest, lexed, i) end return i end function parseexprs(lexed, debug=false) # Step 1: split at commas args = [] thisarg = [] for i = 1:length(lexed) tok = lexed[i] if tok == GText(",") @assert(!isempty(thisarg)) push!(args, copy(thisarg)) empty!(thisarg) else push!(thisarg, tok) end end if !isempty(thisarg) push!(args, copy(thisarg)) empty!(thisarg) end # Step 2: parse each arg n = length(args) parsed = Vector{AbstractLex}(undef, n) todelete = Int[] for j = 1:n thisarg = args[j] # Step 2a: recurse into calls and parse their args debug && sexprlf.(thisarg) for i = 1:length(thisarg) tok = thisarg[i] if tok isa GCall callargs = parseexprs(tok.args, false) thisarg[i] = GCall(tok.name, callargs) elseif tok isa Parens pargs = parseexprs(tok.args, false) thisarg[i] = Parens(pargs) end end # Step 2b: process ^ (highest-precedence operator) debug && sexprlf.(thisarg) process_ops!(thisarg, ("^",), debug) # Step 2c: process * and / (next-highest) debug && sexprlf.(thisarg) process_ops!(thisarg, ("*", "/"), debug) # Step 2d: process + and - debug && println("prior to +/-") debug && sexprlf.(thisarg) process_ops!(thisarg, ("+", "-"), debug) # Step 2e: process "and" and "or" debug && println("post to +/-") debug && sexprlf.(thisarg) process_ops!(thisarg, ("and", "or"), debug) # Step 2f: process other boolean-returning operations process_ops!(thisarg, ("<", "<=", ">", ">="), debug) # Step 2g: process relations debug && sexprlf.(thisarg) process_ops!(thisarg, ("=e=", "=g=", "=l="), debug) if length(thisarg) != 1 println(stderr, "thisarg:") foreach(x->(print(stderr, " "); sexpr(stderr, x); println(stderr)), thisarg) end @assert(length(thisarg) == 1) parsed[j] = stripnewcall!(thisarg[1]) end return parsed end function parseexprs1(lexed) parsed = parseexprs(lexed) @assert(length(parsed) == 1) return parsed[1] end # A "temporary type" for marking calls that arose from operator-precedence resolution # Future lower-priority operators will need to recurse into any NewCalls struct NewCall <: AbstractLex call end function process_ops!(tokens::Vector, ops, debug) debug = false # i = length(tokens) i = 1 # while i > 0 while i < length(tokens) debug && @show i tok = tokens[i] debug && @show tok if tok isa NewCall newtok = tok.call for arg in newtok.args process_ops!(arg, ops) end end if !isa(tok, GText) || tok.text ∉ ops i += 1 continue end if i > 1 && !isoperator(tokens[i-1]) debug && @show tokens[i-1] isoperator(tokens[i-1]) tokens[i-1] = NewCall(GCall(tok.text, [tokens[i-1], tokens[i+1]])) deleteat!(tokens, (i,i+1)) i -= 1 else # unary + or - @assert(tok.text ∈ ("+", "-")) if tok.text == "+" tokens[i] = tokens[i+1] else nexttok = tokens[i+1] if nexttok isa GNumber tokens[i] = GNumber(-nexttok.val) else tokens[i] = NewCall(GCall("-", [nexttok])) end end deleteat!(tokens, (i+1,)) end i += 1 end return tokens end process_ops!(tokens, ops) = nothing isoperator(op) = op isa GText && op.text ∈ operatortokens function sexpr(io::IO, l::NewCall) print(io, "NewCall(") sexpr(io, l.call) print(io, ")") end function stripnewcall!(expr::NewCall) call = expr.call for i = 1:length(call.args) call.args[i] = stripnewcall!(call.args[i]) end return call end stripnewcall!(expr) = expr function deparen!(expr) if expr isa GCall for i = 1:length(expr.args) expr.args[i] = deparen!(expr.args[i]) end elseif expr isa Parens && length(expr.args) == 1 expr = expr.args[1] expr = deparen!(expr) end return expr end function varinfo(name::GText, attr, sets) return name=>VarInfo(attr, ()) end function varinfo(name::GArray, attr, sets) return name=>VarInfo(attr, getaxes(name.indices, sets)) end function seek_to_end(lexed, i) iend = i while iend < length(lexed) && !isa(lexed[iend+1], Union{StatementEnd, Keyword}) iend += 1 end return iend end function getwithkey(dict, key::AbstractString) for (k, v) in dict if getname(k) == key return v end end error(key, " not found") end function getdefault!(gams, tag, ::Type{T}) where T if !haskey(gams, tag) gams[tag] = T<:AbstractDict ? T() : (T<:Vector ? T(undef, 0) : error("type $T not handled")) end return gams[tag] end getdefault!(gams, tag) = getdefault!(gams, tag, Dict{String,String})
// // Licensed to Green Energy Corp (www.greenenergycorp.com) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. Green Enery Corp licenses this file // to you 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 "IOServiceThread.h" #include "Exception.h" #include "Logger.h" #include <boost/asio.hpp> #include <iostream> using namespace boost::asio; namespace apl { class IOServiceExitException : public Exception { public: IOServiceExitException(const std::string& aSource) throw() : Exception(aSource, "") {} }; IOServiceThread::IOServiceThread(Logger* apLogger, boost::asio::io_service* apService) : Loggable(apLogger), mpService(apService), mThread(this) { } void IOServiceThread::Stop() { mThread.RequestStop(); mThread.WaitForStop(); } void IOServiceThread::Throw() { throw IOServiceExitException(LOCATION); } void IOServiceThread::Run() { size_t num = 0; try { num = mpService->run(); } catch(IOServiceExitException&) { LOG_BLOCK(LEV_INFO, "IOService exited via IOServiceExitException"); } catch(const std::exception& ex) { LOG_BLOCK(LEV_ERROR, "Unexpected exception: " << ex.what()); } } void IOServiceThread::SignalStop() { mpService->post(boost::bind(&IOServiceThread::Throw, this)); } }
[GOAL] M : Type u_1 G : Type u_2 α : Type u_3 inst✝⁵ : Monoid M inst✝⁴ : Group G inst✝³ : TopologicalSpace α inst✝² : MulAction M α inst✝¹ : MulAction G α inst✝ : ContinuousConstSMul M α ⊢ IsMinimal M α ↔ ∀ (s : Set α), IsClosed s → (∀ (c : M), c • s ⊆ s) → s = ∅ ∨ s = univ [PROOFSTEP] constructor [GOAL] case mp M : Type u_1 G : Type u_2 α : Type u_3 inst✝⁵ : Monoid M inst✝⁴ : Group G inst✝³ : TopologicalSpace α inst✝² : MulAction M α inst✝¹ : MulAction G α inst✝ : ContinuousConstSMul M α ⊢ IsMinimal M α → ∀ (s : Set α), IsClosed s → (∀ (c : M), c • s ⊆ s) → s = ∅ ∨ s = univ [PROOFSTEP] intro _ _ [GOAL] case mp M : Type u_1 G : Type u_2 α : Type u_3 inst✝⁵ : Monoid M inst✝⁴ : Group G inst✝³ : TopologicalSpace α inst✝² : MulAction M α inst✝¹ : MulAction G α inst✝ : ContinuousConstSMul M α a✝ : IsMinimal M α s✝ : Set α ⊢ IsClosed s✝ → (∀ (c : M), c • s✝ ⊆ s✝) → s✝ = ∅ ∨ s✝ = univ [PROOFSTEP] exact eq_empty_or_univ_of_smul_invariant_closed M [GOAL] case mpr M : Type u_1 G : Type u_2 α : Type u_3 inst✝⁵ : Monoid M inst✝⁴ : Group G inst✝³ : TopologicalSpace α inst✝² : MulAction M α inst✝¹ : MulAction G α inst✝ : ContinuousConstSMul M α ⊢ (∀ (s : Set α), IsClosed s → (∀ (c : M), c • s ⊆ s) → s = ∅ ∨ s = univ) → IsMinimal M α [PROOFSTEP] refine' fun H ↦ ⟨fun _ ↦ dense_iff_closure_eq.2 <| (H _ _ _).resolve_left _⟩ [GOAL] case mpr.refine'_1 M : Type u_1 G : Type u_2 α : Type u_3 inst✝⁵ : Monoid M inst✝⁴ : Group G inst✝³ : TopologicalSpace α inst✝² : MulAction M α inst✝¹ : MulAction G α inst✝ : ContinuousConstSMul M α H : ∀ (s : Set α), IsClosed s → (∀ (c : M), c • s ⊆ s) → s = ∅ ∨ s = univ x✝ : α ⊢ IsClosed (closure (orbit M x✝)) case mpr.refine'_2 M : Type u_1 G : Type u_2 α : Type u_3 inst✝⁵ : Monoid M inst✝⁴ : Group G inst✝³ : TopologicalSpace α inst✝² : MulAction M α inst✝¹ : MulAction G α inst✝ : ContinuousConstSMul M α H : ∀ (s : Set α), IsClosed s → (∀ (c : M), c • s ⊆ s) → s = ∅ ∨ s = univ x✝ : α ⊢ ∀ (c : M), c • closure (orbit M x✝) ⊆ closure (orbit M x✝) case mpr.refine'_3 M : Type u_1 G : Type u_2 α : Type u_3 inst✝⁵ : Monoid M inst✝⁴ : Group G inst✝³ : TopologicalSpace α inst✝² : MulAction M α inst✝¹ : MulAction G α inst✝ : ContinuousConstSMul M α H : ∀ (s : Set α), IsClosed s → (∀ (c : M), c • s ⊆ s) → s = ∅ ∨ s = univ x✝ : α ⊢ ¬closure (orbit M x✝) = ∅ [PROOFSTEP] exacts [isClosed_closure, fun _ ↦ smul_closure_orbit_subset _ _, (orbit_nonempty _).closure.ne_empty]
Face Plate rings are subtly capped in Silver or Gold, with an exposed, polished agate base and druzy crystal slice on the face. Like the natural stone and like the wearer, every one unique. Do not submerge. Polish with a soft cloth and keep in soft pouch provided.
[GOAL] ⊢ Continuous sin [PROOFSTEP] change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 [GOAL] ⊢ Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 [PROOFSTEP] continuity [GOAL] ⊢ Continuous cos [PROOFSTEP] change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 [GOAL] ⊢ Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 [PROOFSTEP] continuity [GOAL] ⊢ Continuous sinh [PROOFSTEP] change Continuous fun z => (exp z - exp (-z)) / 2 [GOAL] ⊢ Continuous fun z => (exp z - exp (-z)) / 2 [PROOFSTEP] continuity [GOAL] ⊢ Continuous cosh [PROOFSTEP] change Continuous fun z => (exp z + exp (-z)) / 2 [GOAL] ⊢ Continuous fun z => (exp z + exp (-z)) / 2 [PROOFSTEP] continuity [GOAL] ⊢ 1 ≤ 2 [PROOFSTEP] norm_num [GOAL] ⊢ cos (π / 2) = 0 [PROOFSTEP] rw [Real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)] [GOAL] ⊢ cos (choose exists_cos_eq_zero) = 0 [PROOFSTEP] exact (Classical.choose_spec exists_cos_eq_zero).2 [GOAL] ⊢ 1 ≤ π / 2 [PROOFSTEP] rw [Real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)] [GOAL] ⊢ 1 ≤ choose exists_cos_eq_zero [PROOFSTEP] exact (Classical.choose_spec exists_cos_eq_zero).1.1 [GOAL] ⊢ π / 2 ≤ 2 [PROOFSTEP] rw [Real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)] [GOAL] ⊢ choose exists_cos_eq_zero ≤ 2 [PROOFSTEP] exact (Classical.choose_spec exists_cos_eq_zero).1.2 [GOAL] ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] ⊢ 2 / 2 ≤ π / 2 [PROOFSTEP] rw [div_self (two_ne_zero' ℝ)] [GOAL] ⊢ 1 ≤ π / 2 [PROOFSTEP] exact one_le_pi_div_two [GOAL] ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] ⊢ 2 = 4 / 2 [PROOFSTEP] norm_num [GOAL] ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] ⊢ 0 < 2 * π [PROOFSTEP] linarith [pi_pos] [GOAL] ⊢ 0 < pi [PROOFSTEP] exact_mod_cast Real.pi_pos [GOAL] ⊢ sin π = 0 [PROOFSTEP] rw [← mul_div_cancel_left π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two] [GOAL] ⊢ sin (π / 2) * 0 + 0 * sin (π / 2) = 0 [PROOFSTEP] simp [GOAL] ⊢ cos π = -1 [PROOFSTEP] rw [← mul_div_cancel_left π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] [GOAL] ⊢ 2 * 0 ^ 2 - 1 = -1 [PROOFSTEP] norm_num [GOAL] ⊢ sin (2 * π) = 0 [PROOFSTEP] simp [two_mul, sin_add] [GOAL] ⊢ cos (2 * π) = 1 [PROOFSTEP] simp [two_mul, cos_add] [GOAL] ⊢ Function.Antiperiodic sin π [PROOFSTEP] simp [sin_add] [GOAL] ⊢ Function.Antiperiodic cos π [PROOFSTEP] simp [cos_add] [GOAL] n : ℕ ⊢ cos (↑n * (2 * π) + π) = -1 [PROOFSTEP] simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic [GOAL] n : ℤ ⊢ cos (↑n * (2 * π) + π) = -1 [PROOFSTEP] simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic [GOAL] n : ℕ ⊢ cos (↑n * (2 * π) - π) = -1 [PROOFSTEP] simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic [GOAL] n : ℤ ⊢ cos (↑n * (2 * π) - π) = -1 [PROOFSTEP] simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic [GOAL] x : ℝ h0x : 0 < x hxp : x < π hx2 : ¬x ≤ 2 ⊢ 2 + 2 = 4 [PROOFSTEP] norm_num [GOAL] x : ℝ hx : x ∈ Icc 0 π ⊢ 0 ≤ sin x [PROOFSTEP] rw [← closure_Ioo pi_ne_zero.symm] at hx [GOAL] x : ℝ hx : x ∈ closure (Ioo 0 π) ⊢ 0 ≤ sin x [PROOFSTEP] exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) [GOAL] ⊢ sin (π / 2) = 1 ∨ sin (π / 2) = -1 [PROOFSTEP] simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2) [GOAL] this : sin (π / 2) = 1 ∨ sin (π / 2) = -1 h : sin (π / 2) = -1 ⊢ ¬0 < -1 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ sin (x + π / 2) = cos x [PROOFSTEP] simp [sin_add] [GOAL] x : ℝ ⊢ sin (x - π / 2) = -cos x [PROOFSTEP] simp [sub_eq_add_neg, sin_add] [GOAL] x : ℝ ⊢ sin (π / 2 - x) = cos x [PROOFSTEP] simp [sub_eq_add_neg, sin_add] [GOAL] x : ℝ ⊢ cos (x + π / 2) = -sin x [PROOFSTEP] simp [cos_add] [GOAL] x : ℝ ⊢ cos (x - π / 2) = sin x [PROOFSTEP] simp [sub_eq_add_neg, cos_add] [GOAL] x : ℝ ⊢ cos (π / 2 - x) = sin x [PROOFSTEP] rw [← cos_neg, neg_sub, cos_sub_pi_div_two] [GOAL] x : ℝ hx : x ∈ Ioo (-(π / 2)) (π / 2) ⊢ 0 < x + π / 2 [PROOFSTEP] linarith [hx.1] [GOAL] x : ℝ hx : x ∈ Ioo (-(π / 2)) (π / 2) ⊢ x + π / 2 < π [PROOFSTEP] linarith [hx.2] [GOAL] x : ℝ hx : x ∈ Icc (-(π / 2)) (π / 2) ⊢ 0 ≤ x + π / 2 [PROOFSTEP] linarith [hx.1] [GOAL] x : ℝ hx : x ∈ Icc (-(π / 2)) (π / 2) ⊢ x + π / 2 ≤ π [PROOFSTEP] linarith [hx.2] [GOAL] x : ℝ hx₁ : π / 2 < x hx₂ : x < π + π / 2 ⊢ -(π / 2) < π - x [PROOFSTEP] linarith [GOAL] x : ℝ hx₁ : π / 2 < x hx₂ : x < π + π / 2 ⊢ π - x < π / 2 [PROOFSTEP] linarith [GOAL] x : ℝ hx₁ : π / 2 ≤ x hx₂ : x ≤ π + π / 2 ⊢ -(π / 2) ≤ π - x [PROOFSTEP] linarith [GOAL] x : ℝ hx₁ : π / 2 ≤ x hx₂ : x ≤ π + π / 2 ⊢ π - x ≤ π / 2 [PROOFSTEP] linarith [GOAL] x : ℝ hl : 0 ≤ x hu : x ≤ π ⊢ sin x = sqrt (1 - cos x ^ 2) [PROOFSTEP] rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] [GOAL] x : ℝ hl : -(π / 2) ≤ x hu : x ≤ π / 2 ⊢ cos x = sqrt (1 - sin x ^ 2) [PROOFSTEP] rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)] [GOAL] x : ℝ hx₁ : -π < x hx₂ : x < π h : x = 0 ⊢ sin x = 0 [PROOFSTEP] simp [h] [GOAL] x : ℝ h : sin x = 0 h₃ : x - ↑⌊x / π⌋ * π > 0 ⊢ 0 = sin (x - ↑⌊x / π⌋ * π) [PROOFSTEP] simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi] [GOAL] x : ℝ ⊢ sin x ≠ 0 ↔ ∀ (n : ℤ), ↑n * π ≠ x [PROOFSTEP] rw [← not_exists, not_iff_not, sin_eq_zero_iff] [GOAL] x : ℝ ⊢ sin x = 0 ↔ cos x = 1 ∨ cos x = -1 [PROOFSTEP] rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self] [GOAL] x : ℝ ⊢ sin x = 0 ↔ 0 = sin x * sin x [PROOFSTEP] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ [GOAL] x : ℝ h : sin x = 0 ⊢ 0 = sin x * sin x [PROOFSTEP] rw [h, mul_zero] [GOAL] x : ℝ h : cos x = 1 n : ℤ hn : ↑n * π = x hn0 : n % 2 = 0 ⊢ ↑(n / 2) * (2 * π) = x [PROOFSTEP] rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel ((Int.dvd_iff_emod_eq_zero _ _).2 hn0)] [GOAL] x : ℝ h : cos x = 1 n : ℤ hn : ↑n * π = x hn1 : n % 2 = 1 ⊢ ↑(n / 2) * (2 * π) = x [PROOFSTEP] rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn [GOAL] x : ℝ h : cos x = 1 n : ℤ hn : ↑(n / 2) * (2 * π) + π = x hn1 : n % 2 = 1 ⊢ ↑(n / 2) * (2 * π) = x [PROOFSTEP] rw [← hn, cos_int_mul_two_pi_add_pi] at h [GOAL] x : ℝ n : ℤ h : -1 = 1 hn : ↑(n / 2) * (2 * π) + π = x hn1 : n % 2 = 1 ⊢ ↑(n / 2) * (2 * π) = x [PROOFSTEP] exact absurd h (by norm_num) [GOAL] x : ℝ n : ℤ h : -1 = 1 hn : ↑(n / 2) * (2 * π) + π = x hn1 : n % 2 = 1 ⊢ ¬-1 = 1 [PROOFSTEP] norm_num [GOAL] x : ℝ hx₁ : -(2 * π) < x hx₂ : x < 2 * π h : cos x = 1 ⊢ x = 0 [PROOFSTEP] rcases(cos_eq_one_iff _).1 h with ⟨n, rfl⟩ [GOAL] case intro n : ℤ hx₁ : -(2 * π) < ↑n * (2 * π) hx₂ : ↑n * (2 * π) < 2 * π h : cos (↑n * (2 * π)) = 1 ⊢ ↑n * (2 * π) = 0 [PROOFSTEP] rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂ [GOAL] case intro n : ℤ hx₁ : -(2 * π) < ↑n * (2 * π) hx₂ : ↑n < 1 h : cos (↑n * (2 * π)) = 1 ⊢ ↑n * (2 * π) = 0 [PROOFSTEP] rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ [GOAL] case intro n : ℤ hx₁ : -↑n < 1 hx₂ : ↑n < 1 h : cos (↑n * (2 * π)) = 1 ⊢ ↑n * (2 * π) = 0 [PROOFSTEP] norm_cast at hx₁ hx₂ [GOAL] case intro n : ℤ h : cos (↑n * (2 * π)) = 1 hx₁ : -n < 1 hx₂ : n < 1 ⊢ ↑n * (2 * π) = 0 [PROOFSTEP] obtain rfl : n = 0 := le_antisymm (by linarith) (by linarith) [GOAL] n : ℤ h : cos (↑n * (2 * π)) = 1 hx₁ : -n < 1 hx₂ : n < 1 ⊢ n ≤ 0 [PROOFSTEP] linarith [GOAL] n : ℤ h : cos (↑n * (2 * π)) = 1 hx₁ : -n < 1 hx₂ : n < 1 ⊢ 0 ≤ n [PROOFSTEP] linarith [GOAL] case intro h : cos (↑0 * (2 * π)) = 1 hx₁ : -0 < 1 hx₂ : 0 < 1 ⊢ ↑0 * (2 * π) = 0 [PROOFSTEP] simp [GOAL] x : ℝ hx₁ : -(2 * π) < x hx₂ : x < 2 * π h : x = 0 ⊢ cos x = 1 [PROOFSTEP] simp [h] [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ cos y < cos x [PROOFSTEP] rw [← sub_lt_zero, cos_sub_cos] [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ -2 * sin ((y + x) / 2) * sin ((y - x) / 2) < 0 [PROOFSTEP] have : 0 < sin ((y + x) / 2) := by refine' sin_pos_of_pos_of_lt_pi _ _ <;> linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ 0 < sin ((y + x) / 2) [PROOFSTEP] refine' sin_pos_of_pos_of_lt_pi _ _ [GOAL] case refine'_1 x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ 0 < (y + x) / 2 [PROOFSTEP] linarith [GOAL] case refine'_2 x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ (y + x) / 2 < π [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y this : 0 < sin ((y + x) / 2) ⊢ -2 * sin ((y + x) / 2) * sin ((y - x) / 2) < 0 [PROOFSTEP] have : 0 < sin ((y - x) / 2) := by refine' sin_pos_of_pos_of_lt_pi _ _ <;> linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y this : 0 < sin ((y + x) / 2) ⊢ 0 < sin ((y - x) / 2) [PROOFSTEP] refine' sin_pos_of_pos_of_lt_pi _ _ [GOAL] case refine'_1 x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y this : 0 < sin ((y + x) / 2) ⊢ 0 < (y - x) / 2 [PROOFSTEP] linarith [GOAL] case refine'_2 x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y this : 0 < sin ((y + x) / 2) ⊢ (y - x) / 2 < π [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π / 2 hxy : x < y this✝ : 0 < sin ((y + x) / 2) this : 0 < sin ((y - x) / 2) ⊢ -2 * sin ((y + x) / 2) * sin ((y - x) / 2) < 0 [PROOFSTEP] nlinarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx✝ : x ≤ π / 2 hy : π / 2 ≤ y hx : x < π / 2 ⊢ y ≤ π + π / 2 [PROOFSTEP] linarith [pi_pos] [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx✝ : x ≤ π / 2 hy : π / 2 ≤ y hx : x < π / 2 ⊢ -(π / 2) < x [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx✝ : x ≤ π / 2 hy : π / 2 ≤ y hx : x = π / 2 ⊢ π / 2 < y [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx✝ : x ≤ π / 2 hy : π / 2 ≤ y hx : x = π / 2 ⊢ y < π + π / 2 [PROOFSTEP] linarith [pi_pos] [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx✝ : x ≤ π / 2 hy : π / 2 ≤ y hx : x = π / 2 ⊢ 0 = cos x [PROOFSTEP] rw [hx, cos_pi_div_two] [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx : π / 2 ≤ x hy : y ≤ π / 2 ⊢ cos y < cos x [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx : π / 2 ≤ x hy : π / 2 ≤ y ⊢ -cos x < -cos y [PROOFSTEP] rw [← cos_pi_sub, ← cos_pi_sub] [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx : π / 2 ≤ x hy : π / 2 ≤ y ⊢ cos (π - x) < cos (π - y) [PROOFSTEP] apply cos_lt_cos_of_nonneg_of_le_pi_div_two [GOAL] case hx₁ x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx : π / 2 ≤ x hy : π / 2 ≤ y ⊢ 0 ≤ π - y [PROOFSTEP] linarith [GOAL] case hy₂ x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx : π / 2 ≤ x hy : π / 2 ≤ y ⊢ π - x ≤ π / 2 [PROOFSTEP] linarith [GOAL] case hxy x y : ℝ hx₁ : 0 ≤ x hy₂ : y ≤ π hxy : x < y hx : π / 2 ≤ x hy : π / 2 ≤ y ⊢ π - y < π - x [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : -(π / 2) ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ sin x < sin y [PROOFSTEP] rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)] [GOAL] x y : ℝ hx₁ : -(π / 2) ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ cos (-(x - π / 2)) < cos (-(y - π / 2)) [PROOFSTEP] apply cos_lt_cos_of_nonneg_of_le_pi [GOAL] case hx₁ x y : ℝ hx₁ : -(π / 2) ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ 0 ≤ -(y - π / 2) [PROOFSTEP] linarith [GOAL] case hy₂ x y : ℝ hx₁ : -(π / 2) ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ -(x - π / 2) ≤ π [PROOFSTEP] linarith [GOAL] case hxy x y : ℝ hx₁ : -(π / 2) ≤ x hy₂ : y ≤ π / 2 hxy : x < y ⊢ -(y - π / 2) < -(x - π / 2) [PROOFSTEP] linarith [GOAL] ⊢ SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) [PROOFSTEP] simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn [GOAL] ⊢ SurjOn cos (Icc 0 π) (Icc (-1) 1) [PROOFSTEP] simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn [GOAL] ⊢ Set.Infinite (range cos) [PROOFSTEP] rw [Real.range_cos] [GOAL] ⊢ Set.Infinite (Icc (-1) 1) [PROOFSTEP] exact Icc_infinite (by norm_num) [GOAL] ⊢ -1 < 1 [PROOFSTEP] norm_num [GOAL] ⊢ Set.Infinite (range sin) [PROOFSTEP] rw [Real.range_sin] [GOAL] ⊢ Set.Infinite (Icc (-1) 1) [PROOFSTEP] exact Icc_infinite (by norm_num) [GOAL] ⊢ -1 < 1 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ sqrtTwoAddSeries x 0 = x [PROOFSTEP] simp [GOAL] x : ℝ ⊢ sqrtTwoAddSeries 0 1 = sqrt 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ sqrtTwoAddSeries 0 2 = sqrt (2 + sqrt 2) [PROOFSTEP] simp [GOAL] x : ℝ ⊢ sqrtTwoAddSeries 0 0 < 2 [PROOFSTEP] norm_num [GOAL] x : ℝ n : ℕ ⊢ sqrtTwoAddSeries 0 (n + 1) < 2 [PROOFSTEP] refine' lt_of_lt_of_le _ (sqrt_sq zero_lt_two.le).le [GOAL] x : ℝ n : ℕ ⊢ sqrtTwoAddSeries 0 (n + 1) < sqrt (2 ^ 2) [PROOFSTEP] rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] [GOAL] x : ℝ n : ℕ ⊢ sqrtTwoAddSeries 0 n < 2 ^ 2 - 2 [PROOFSTEP] refine' (sqrtTwoAddSeries_lt_two n).trans_le _ [GOAL] x : ℝ n : ℕ ⊢ 2 ≤ 2 ^ 2 - 2 [PROOFSTEP] norm_num [GOAL] x : ℝ n : ℕ ⊢ 0 ≤ 2 + sqrtTwoAddSeries 0 n [PROOFSTEP] exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) [GOAL] x✝ x : ℝ n : ℕ ⊢ sqrtTwoAddSeries x (n + 1 + 1) = sqrtTwoAddSeries (sqrt (2 + x)) (n + 1) [PROOFSTEP] rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] [GOAL] x✝ x y : ℝ h : x ≤ y n : ℕ ⊢ sqrtTwoAddSeries x (n + 1) ≤ sqrtTwoAddSeries y (n + 1) [PROOFSTEP] rw [sqrtTwoAddSeries, sqrtTwoAddSeries] [GOAL] x✝ x y : ℝ h : x ≤ y n : ℕ ⊢ sqrt (2 + sqrtTwoAddSeries x n) ≤ sqrt (2 + sqrtTwoAddSeries y n) [PROOFSTEP] exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _) [GOAL] x : ℝ ⊢ cos (π / 2 ^ (0 + 1)) = sqrtTwoAddSeries 0 0 / 2 [PROOFSTEP] simp [GOAL] x : ℝ n : ℕ ⊢ cos (π / 2 ^ (n + 1 + 1)) = sqrtTwoAddSeries 0 (n + 1) / 2 [PROOFSTEP] have : (2 : ℝ) ≠ 0 := two_ne_zero [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ cos (π / 2 ^ (n + 1 + 1)) = sqrtTwoAddSeries 0 (n + 1) / 2 [PROOFSTEP] symm [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ sqrtTwoAddSeries 0 (n + 1) / 2 = cos (π / 2 ^ (n + 1 + 1)) [PROOFSTEP] rw [div_eq_iff_mul_eq this] [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ cos (π / 2 ^ (n + 1 + 1)) * 2 = sqrtTwoAddSeries 0 (n + 1) [PROOFSTEP] symm [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ sqrtTwoAddSeries 0 (n + 1) = cos (π / 2 ^ (n + 1 + 1)) * 2 [PROOFSTEP] rw [sqrtTwoAddSeries, sqrt_eq_iff_sq_eq, mul_pow, cos_sq, ← mul_div_assoc, Nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow _, add_mul] [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 1 / 2 * 2 ^ 2 + sqrtTwoAddSeries 0 n / 2 / 2 * 2 ^ 2 = 2 + sqrtTwoAddSeries 0 n case hx x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ 2 + sqrtTwoAddSeries 0 n case hy x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ cos (π / 2 ^ (n + 1 + 1)) * 2 [PROOFSTEP] congr [GOAL] case e_a x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 1 / 2 * 2 ^ 2 = 2 [PROOFSTEP] norm_num [GOAL] case e_a x : ℝ n : ℕ this : 2 ≠ 0 ⊢ sqrtTwoAddSeries 0 n / 2 / 2 * 2 ^ 2 = sqrtTwoAddSeries 0 n [PROOFSTEP] rw [mul_comm, sq, mul_assoc, ← mul_div_assoc, mul_div_cancel_left, ← mul_div_assoc, mul_div_cancel_left] [GOAL] case e_a.ha x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 2 ≠ 0 [PROOFSTEP] try exact this [GOAL] case e_a.ha x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 2 ≠ 0 [PROOFSTEP] exact this [GOAL] case e_a.ha x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 2 ≠ 0 [PROOFSTEP] try exact this [GOAL] case e_a.ha x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 2 ≠ 0 [PROOFSTEP] exact this [GOAL] case hx x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ 2 + sqrtTwoAddSeries 0 n case hy x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ cos (π / 2 ^ (n + 1 + 1)) * 2 [PROOFSTEP] apply add_nonneg [GOAL] case hx.ha x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ 2 case hx.hb x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ sqrtTwoAddSeries 0 n case hy x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ cos (π / 2 ^ (n + 1 + 1)) * 2 [PROOFSTEP] norm_num [GOAL] case hx.hb x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ sqrtTwoAddSeries 0 n case hy x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ cos (π / 2 ^ (n + 1 + 1)) * 2 [PROOFSTEP] apply sqrtTwoAddSeries_zero_nonneg [GOAL] case hy x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ cos (π / 2 ^ (n + 1 + 1)) * 2 [PROOFSTEP] norm_num [GOAL] case hy x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 ≤ cos (π / 2 ^ (n + 1 + 1)) [PROOFSTEP] apply le_of_lt [GOAL] case hy.a x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < cos (π / 2 ^ (n + 1 + 1)) [PROOFSTEP] apply cos_pos_of_mem_Ioo ⟨_, _⟩ [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ -(π / 2) < π / 2 ^ (n + 1 + 1) [PROOFSTEP] trans (0 : ℝ) [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ -(π / 2) < 0 x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < π / 2 ^ (n + 1 + 1) [PROOFSTEP] rw [neg_lt_zero] [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < π / 2 x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < π / 2 ^ (n + 1 + 1) [PROOFSTEP] apply pi_div_two_pos [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < π / 2 ^ (n + 1 + 1) [PROOFSTEP] apply div_pos pi_pos [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 ^ (n + 1 + 1) [PROOFSTEP] apply pow_pos [GOAL] case H x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ π / 2 ^ (n + 1 + 1) < π / 2 [PROOFSTEP] apply div_lt_div' (le_refl π) _ pi_pos _ [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 2 < 2 ^ (n + 1 + 1) x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 [PROOFSTEP] refine' lt_of_le_of_lt (le_of_eq (pow_one _).symm) _ [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 2 ^ 1 < 2 ^ (n + 1 + 1) x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 [PROOFSTEP] apply pow_lt_pow [GOAL] case h x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 1 < 2 case h2 x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 1 < n + 1 + 1 x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] case h2 x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 1 < n + 1 + 1 x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 [PROOFSTEP] apply Nat.succ_lt_succ [GOAL] case h2.a x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < n + 1 x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 [PROOFSTEP] apply Nat.succ_pos [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 [PROOFSTEP] all_goals norm_num [GOAL] x : ℝ n : ℕ this : 2 ≠ 0 ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] x : ℝ n : ℕ ⊢ sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 [PROOFSTEP] rw [sin_sq, cos_pi_over_two_pow] [GOAL] x : ℝ n : ℕ ⊢ sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 [PROOFSTEP] rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] [GOAL] x : ℝ n : ℕ ⊢ 1 - 2 / 2 ^ 2 - sqrtTwoAddSeries 0 n / 2 ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 x : ℝ n : ℕ ⊢ 0 ≤ 2 + sqrtTwoAddSeries 0 n [PROOFSTEP] congr [GOAL] case e_a x : ℝ n : ℕ ⊢ 1 - 2 / 2 ^ 2 = 1 / 2 case e_a.e_a x : ℝ n : ℕ ⊢ 2 ^ 2 = 4 x : ℝ n : ℕ ⊢ 0 ≤ 2 + sqrtTwoAddSeries 0 n [PROOFSTEP] norm_num [GOAL] case e_a.e_a x : ℝ n : ℕ ⊢ 2 ^ 2 = 4 x : ℝ n : ℕ ⊢ 0 ≤ 2 + sqrtTwoAddSeries 0 n [PROOFSTEP] norm_num [GOAL] x : ℝ n : ℕ ⊢ 0 ≤ 2 + sqrtTwoAddSeries 0 n [PROOFSTEP] apply add_nonneg [GOAL] case ha x : ℝ n : ℕ ⊢ 0 ≤ 2 case hb x : ℝ n : ℕ ⊢ 0 ≤ sqrtTwoAddSeries 0 n [PROOFSTEP] norm_num [GOAL] case hb x : ℝ n : ℕ ⊢ 0 ≤ sqrtTwoAddSeries 0 n [PROOFSTEP] apply sqrtTwoAddSeries_zero_nonneg [GOAL] x : ℝ n : ℕ ⊢ sin (π / 2 ^ (n + 2)) = sqrt (2 - sqrtTwoAddSeries 0 n) / 2 [PROOFSTEP] symm [GOAL] x : ℝ n : ℕ ⊢ sqrt (2 - sqrtTwoAddSeries 0 n) / 2 = sin (π / 2 ^ (n + 2)) [PROOFSTEP] rw [div_eq_iff_mul_eq] [GOAL] x : ℝ n : ℕ ⊢ sin (π / 2 ^ (n + 2)) * 2 = sqrt (2 - sqrtTwoAddSeries 0 n) x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] symm [GOAL] x : ℝ n : ℕ ⊢ sqrt (2 - sqrtTwoAddSeries 0 n) = sin (π / 2 ^ (n + 2)) * 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] rw [sqrt_eq_iff_sq_eq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul] [GOAL] x : ℝ n : ℕ ⊢ 1 / 2 * 2 ^ 2 - sqrtTwoAddSeries 0 n / 4 * 2 ^ 2 = 2 - sqrtTwoAddSeries 0 n [PROOFSTEP] congr [GOAL] case e_a x : ℝ n : ℕ ⊢ 1 / 2 * 2 ^ 2 = 2 [PROOFSTEP] norm_num [GOAL] case e_a x : ℝ n : ℕ ⊢ sqrtTwoAddSeries 0 n / 4 * 2 ^ 2 = sqrtTwoAddSeries 0 n [PROOFSTEP] norm_num [GOAL] case hx x : ℝ n : ℕ ⊢ 0 ≤ 2 - sqrtTwoAddSeries 0 n [PROOFSTEP] rw [sub_nonneg] [GOAL] case hx x : ℝ n : ℕ ⊢ sqrtTwoAddSeries 0 n ≤ 2 [PROOFSTEP] apply le_of_lt [GOAL] case hx.a x : ℝ n : ℕ ⊢ sqrtTwoAddSeries 0 n < 2 [PROOFSTEP] apply sqrtTwoAddSeries_lt_two [GOAL] case hy x : ℝ n : ℕ ⊢ 0 ≤ sin (π / 2 ^ (n + 2)) * 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] apply le_of_lt [GOAL] case hy.a x : ℝ n : ℕ ⊢ 0 < sin (π / 2 ^ (n + 2)) * 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] apply mul_pos [GOAL] case hy.a.ha x : ℝ n : ℕ ⊢ 0 < sin (π / 2 ^ (n + 2)) case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] apply sin_pos_of_pos_of_lt_pi [GOAL] case hy.a.ha.h0x x : ℝ n : ℕ ⊢ 0 < π / 2 ^ (n + 2) [PROOFSTEP] apply div_pos pi_pos [GOAL] case hy.a.ha.h0x x : ℝ n : ℕ ⊢ 0 < 2 ^ (n + 2) [PROOFSTEP] apply pow_pos [GOAL] case hy.a.ha.h0x.H x : ℝ n : ℕ ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] case hy.a.ha.hxp x : ℝ n : ℕ ⊢ π / 2 ^ (n + 2) < π case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] refine' lt_of_lt_of_le _ (le_of_eq (div_one _)) [GOAL] case hy.a.ha.hxp x : ℝ n : ℕ ⊢ π / 2 ^ (n + 2) < π / 1 case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] rw [div_lt_div_left] [GOAL] case hy.a.ha.hxp x : ℝ n : ℕ ⊢ 1 < 2 ^ (n + 2) case hy.a.ha.hxp.ha x : ℝ n : ℕ ⊢ 0 < π case hy.a.ha.hxp.hb x : ℝ n : ℕ ⊢ 0 < 2 ^ (n + 2) case hy.a.ha.hxp.hc x : ℝ n : ℕ ⊢ 0 < 1 case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] refine' lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _ [GOAL] case hy.a.ha.hxp x : ℝ n : ℕ ⊢ 2 ^ 0 < 2 ^ (n + 2) case hy.a.ha.hxp.ha x : ℝ n : ℕ ⊢ 0 < π case hy.a.ha.hxp.hb x : ℝ n : ℕ ⊢ 0 < 2 ^ (n + 2) case hy.a.ha.hxp.hc x : ℝ n : ℕ ⊢ 0 < 1 case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] apply pow_lt_pow [GOAL] case hy.a.ha.hxp.h x : ℝ n : ℕ ⊢ 1 < 2 case hy.a.ha.hxp.h2 x : ℝ n : ℕ ⊢ 0 < n + 2 case hy.a.ha.hxp.ha x : ℝ n : ℕ ⊢ 0 < π case hy.a.ha.hxp.hb x : ℝ n : ℕ ⊢ 0 < 2 ^ (n + 2) case hy.a.ha.hxp.hc x : ℝ n : ℕ ⊢ 0 < 1 case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] norm_num [GOAL] case hy.a.ha.hxp.h2 x : ℝ n : ℕ ⊢ 0 < n + 2 case hy.a.ha.hxp.ha x : ℝ n : ℕ ⊢ 0 < π case hy.a.ha.hxp.hb x : ℝ n : ℕ ⊢ 0 < 2 ^ (n + 2) case hy.a.ha.hxp.hc x : ℝ n : ℕ ⊢ 0 < 1 case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] apply Nat.succ_pos [GOAL] case hy.a.ha.hxp.ha x : ℝ n : ℕ ⊢ 0 < π case hy.a.ha.hxp.hb x : ℝ n : ℕ ⊢ 0 < 2 ^ (n + 2) case hy.a.ha.hxp.hc x : ℝ n : ℕ ⊢ 0 < 1 case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] apply pi_pos [GOAL] case hy.a.ha.hxp.hb x : ℝ n : ℕ ⊢ 0 < 2 ^ (n + 2) case hy.a.ha.hxp.hc x : ℝ n : ℕ ⊢ 0 < 1 case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] apply pow_pos [GOAL] case hy.a.ha.hxp.hb.H x : ℝ n : ℕ ⊢ 0 < 2 case hy.a.ha.hxp.hc x : ℝ n : ℕ ⊢ 0 < 1 case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] all_goals norm_num [GOAL] case hy.a.ha.hxp.hb.H x : ℝ n : ℕ ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] case hy.a.ha.hxp.hc x : ℝ n : ℕ ⊢ 0 < 1 [PROOFSTEP] norm_num [GOAL] case hy.a.hb x : ℝ n : ℕ ⊢ 0 < 2 [PROOFSTEP] norm_num [GOAL] x : ℝ n : ℕ ⊢ 2 ≠ 0 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ cos (π / 4) = sqrt 2 / 2 [PROOFSTEP] trans cos (π / 2 ^ 2) [GOAL] x : ℝ ⊢ cos (π / 4) = cos (π / 2 ^ 2) x : ℝ ⊢ cos (π / 2 ^ 2) = sqrt 2 / 2 [PROOFSTEP] congr [GOAL] case e_x.e_a x : ℝ ⊢ 4 = 2 ^ 2 x : ℝ ⊢ cos (π / 2 ^ 2) = sqrt 2 / 2 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ cos (π / 2 ^ 2) = sqrt 2 / 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ sin (π / 4) = sqrt 2 / 2 [PROOFSTEP] trans sin (π / 2 ^ 2) [GOAL] x : ℝ ⊢ sin (π / 4) = sin (π / 2 ^ 2) x : ℝ ⊢ sin (π / 2 ^ 2) = sqrt 2 / 2 [PROOFSTEP] congr [GOAL] case e_x.e_a x : ℝ ⊢ 4 = 2 ^ 2 x : ℝ ⊢ sin (π / 2 ^ 2) = sqrt 2 / 2 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ sin (π / 2 ^ 2) = sqrt 2 / 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ cos (π / 8) = sqrt (2 + sqrt 2) / 2 [PROOFSTEP] trans cos (π / 2 ^ 3) [GOAL] x : ℝ ⊢ cos (π / 8) = cos (π / 2 ^ 3) x : ℝ ⊢ cos (π / 2 ^ 3) = sqrt (2 + sqrt 2) / 2 [PROOFSTEP] congr [GOAL] case e_x.e_a x : ℝ ⊢ 8 = 2 ^ 3 x : ℝ ⊢ cos (π / 2 ^ 3) = sqrt (2 + sqrt 2) / 2 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ cos (π / 2 ^ 3) = sqrt (2 + sqrt 2) / 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ sin (π / 8) = sqrt (2 - sqrt 2) / 2 [PROOFSTEP] trans sin (π / 2 ^ 3) [GOAL] x : ℝ ⊢ sin (π / 8) = sin (π / 2 ^ 3) x : ℝ ⊢ sin (π / 2 ^ 3) = sqrt (2 - sqrt 2) / 2 [PROOFSTEP] congr [GOAL] case e_x.e_a x : ℝ ⊢ 8 = 2 ^ 3 x : ℝ ⊢ sin (π / 2 ^ 3) = sqrt (2 - sqrt 2) / 2 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ sin (π / 2 ^ 3) = sqrt (2 - sqrt 2) / 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ cos (π / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 [PROOFSTEP] trans cos (π / 2 ^ 4) [GOAL] x : ℝ ⊢ cos (π / 16) = cos (π / 2 ^ 4) x : ℝ ⊢ cos (π / 2 ^ 4) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 [PROOFSTEP] congr [GOAL] case e_x.e_a x : ℝ ⊢ 16 = 2 ^ 4 x : ℝ ⊢ cos (π / 2 ^ 4) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ cos (π / 2 ^ 4) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ sin (π / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 [PROOFSTEP] trans sin (π / 2 ^ 4) [GOAL] x : ℝ ⊢ sin (π / 16) = sin (π / 2 ^ 4) x : ℝ ⊢ sin (π / 2 ^ 4) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 [PROOFSTEP] congr [GOAL] case e_x.e_a x : ℝ ⊢ 16 = 2 ^ 4 x : ℝ ⊢ sin (π / 2 ^ 4) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ sin (π / 2 ^ 4) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ cos (π / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 [PROOFSTEP] trans cos (π / 2 ^ 5) [GOAL] x : ℝ ⊢ cos (π / 32) = cos (π / 2 ^ 5) x : ℝ ⊢ cos (π / 2 ^ 5) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 [PROOFSTEP] congr [GOAL] case e_x.e_a x : ℝ ⊢ 32 = 2 ^ 5 x : ℝ ⊢ cos (π / 2 ^ 5) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ cos (π / 2 ^ 5) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ sin (π / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 [PROOFSTEP] trans sin (π / 2 ^ 5) [GOAL] x : ℝ ⊢ sin (π / 32) = sin (π / 2 ^ 5) x : ℝ ⊢ sin (π / 2 ^ 5) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 [PROOFSTEP] congr [GOAL] case e_x.e_a x : ℝ ⊢ 32 = 2 ^ 5 x : ℝ ⊢ sin (π / 2 ^ 5) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 [PROOFSTEP] norm_num [GOAL] x : ℝ ⊢ sin (π / 2 ^ 5) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 [PROOFSTEP] simp [GOAL] x : ℝ ⊢ cos (π / 3) = 1 / 2 [PROOFSTEP] have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by have : cos (3 * (π / 3)) = cos π := by congr 1 ring linarith [cos_pi, cos_three_mul (π / 3)] [GOAL] x : ℝ ⊢ (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 [PROOFSTEP] have : cos (3 * (π / 3)) = cos π := by congr 1 ring [GOAL] x : ℝ ⊢ cos (3 * (π / 3)) = cos π [PROOFSTEP] congr 1 [GOAL] case e_x x : ℝ ⊢ 3 * (π / 3) = π [PROOFSTEP] ring [GOAL] x : ℝ this : cos (3 * (π / 3)) = cos π ⊢ (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 [PROOFSTEP] linarith [cos_pi, cos_three_mul (π / 3)] [GOAL] x : ℝ h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 ⊢ cos (π / 3) = 1 / 2 [PROOFSTEP] cases' mul_eq_zero.mp h₁ with h h [GOAL] case inl x : ℝ h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 h : (2 * cos (π / 3) - 1) ^ 2 = 0 ⊢ cos (π / 3) = 1 / 2 [PROOFSTEP] linarith [pow_eq_zero h] [GOAL] case inr x : ℝ h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 h : 2 * cos (π / 3) + 2 = 0 ⊢ cos (π / 3) = 1 / 2 [PROOFSTEP] have : cos π < cos (π / 3) := by refine' cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _ <;> linarith [pi_pos] [GOAL] x : ℝ h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 h : 2 * cos (π / 3) + 2 = 0 ⊢ cos π < cos (π / 3) [PROOFSTEP] refine' cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _ [GOAL] case refine'_1 x : ℝ h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 h : 2 * cos (π / 3) + 2 = 0 ⊢ 0 ≤ π / 3 [PROOFSTEP] linarith [pi_pos] [GOAL] case refine'_2 x : ℝ h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 h : 2 * cos (π / 3) + 2 = 0 ⊢ π / 3 < π [PROOFSTEP] linarith [pi_pos] [GOAL] case inr x : ℝ h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 h : 2 * cos (π / 3) + 2 = 0 this : cos π < cos (π / 3) ⊢ cos (π / 3) = 1 / 2 [PROOFSTEP] linarith [cos_pi] [GOAL] x : ℝ ⊢ cos (π / 6) ^ 2 = 3 / 4 [PROOFSTEP] have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2 := by convert cos_sq (π / 6) using 3 have h2 : 2 * (π / 6) = π / 3 := by linarith rw [h2, cos_pi_div_three] [GOAL] x : ℝ ⊢ cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2 [PROOFSTEP] convert cos_sq (π / 6) using 3 [GOAL] case h.e'_3.h.e'_6.h.e'_5 x : ℝ ⊢ 1 / 2 = cos (2 * (π / 6)) [PROOFSTEP] have h2 : 2 * (π / 6) = π / 3 := by linarith [GOAL] x : ℝ ⊢ 2 * (π / 6) = π / 3 [PROOFSTEP] linarith [GOAL] case h.e'_3.h.e'_6.h.e'_5 x : ℝ h2 : 2 * (π / 6) = π / 3 ⊢ 1 / 2 = cos (2 * (π / 6)) [PROOFSTEP] rw [h2, cos_pi_div_three] [GOAL] x : ℝ h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2 ⊢ cos (π / 6) ^ 2 = 3 / 4 [PROOFSTEP] rw [← sub_eq_zero] at h1 ⊢ [GOAL] x : ℝ h1✝ : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2 h1 : cos (π / 6) ^ 2 - (1 / 2 + 1 / 2 / 2) = 0 ⊢ cos (π / 6) ^ 2 - 3 / 4 = 0 [PROOFSTEP] convert h1 using 1 [GOAL] case h.e'_2 x : ℝ h1✝ : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2 h1 : cos (π / 6) ^ 2 - (1 / 2 + 1 / 2 / 2) = 0 ⊢ cos (π / 6) ^ 2 - 3 / 4 = cos (π / 6) ^ 2 - (1 / 2 + 1 / 2 / 2) [PROOFSTEP] ring [GOAL] x : ℝ ⊢ cos (π / 6) = sqrt 3 / 2 [PROOFSTEP] suffices sqrt 3 = cos (π / 6) * 2 by field_simp [(by norm_num : 0 ≠ 2)] exact this.symm [GOAL] x : ℝ this : sqrt 3 = cos (π / 6) * 2 ⊢ cos (π / 6) = sqrt 3 / 2 [PROOFSTEP] field_simp [(by norm_num : 0 ≠ 2)] [GOAL] x : ℝ this : sqrt 3 = cos (π / 6) * 2 ⊢ 0 ≠ 2 [PROOFSTEP] norm_num [GOAL] x : ℝ this : sqrt 3 = cos (π / 6) * 2 ⊢ cos (π / 6) * 2 = sqrt 3 [PROOFSTEP] exact this.symm [GOAL] x : ℝ ⊢ sqrt 3 = cos (π / 6) * 2 [PROOFSTEP] rw [sqrt_eq_iff_sq_eq] [GOAL] x : ℝ ⊢ (cos (π / 6) * 2) ^ 2 = 3 [PROOFSTEP] have h1 := (mul_right_inj' (by norm_num : (4 : ℝ) ≠ 0)).mpr sq_cos_pi_div_six [GOAL] x : ℝ ⊢ 4 ≠ 0 [PROOFSTEP] norm_num [GOAL] x : ℝ h1 : 4 * cos (π / 6) ^ 2 = 4 * (3 / 4) ⊢ (cos (π / 6) * 2) ^ 2 = 3 [PROOFSTEP] rw [← sub_eq_zero] at h1 ⊢ [GOAL] x : ℝ h1✝ : 4 * cos (π / 6) ^ 2 = 4 * (3 / 4) h1 : 4 * cos (π / 6) ^ 2 - 4 * (3 / 4) = 0 ⊢ (cos (π / 6) * 2) ^ 2 - 3 = 0 [PROOFSTEP] convert h1 using 1 [GOAL] case h.e'_2 x : ℝ h1✝ : 4 * cos (π / 6) ^ 2 = 4 * (3 / 4) h1 : 4 * cos (π / 6) ^ 2 - 4 * (3 / 4) = 0 ⊢ (cos (π / 6) * 2) ^ 2 - 3 = 4 * cos (π / 6) ^ 2 - 4 * (3 / 4) [PROOFSTEP] ring [GOAL] case hx x : ℝ ⊢ 0 ≤ 3 [PROOFSTEP] norm_num [GOAL] case hy x : ℝ ⊢ 0 ≤ cos (π / 6) * 2 [PROOFSTEP] have : 0 < cos (π / 6) := by apply cos_pos_of_mem_Ioo; constructor <;> linarith [pi_pos] [GOAL] x : ℝ ⊢ 0 < cos (π / 6) [PROOFSTEP] apply cos_pos_of_mem_Ioo [GOAL] case hx x : ℝ ⊢ π / 6 ∈ Ioo (-(π / 2)) (π / 2) [PROOFSTEP] constructor [GOAL] case hx.left x : ℝ ⊢ -(π / 2) < π / 6 [PROOFSTEP] linarith [pi_pos] [GOAL] case hx.right x : ℝ ⊢ π / 6 < π / 2 [PROOFSTEP] linarith [pi_pos] [GOAL] case hy x : ℝ this : 0 < cos (π / 6) ⊢ 0 ≤ cos (π / 6) * 2 [PROOFSTEP] linarith [GOAL] x : ℝ ⊢ sin (π / 6) = 1 / 2 [PROOFSTEP] rw [← cos_pi_div_two_sub, ← cos_pi_div_three] [GOAL] x : ℝ ⊢ cos (π / 2 - π / 6) = cos (π / 3) [PROOFSTEP] congr [GOAL] case e_x x : ℝ ⊢ π / 2 - π / 6 = π / 3 [PROOFSTEP] ring [GOAL] x : ℝ ⊢ sin (π / 3) ^ 2 = 3 / 4 [PROOFSTEP] rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six] [GOAL] x : ℝ ⊢ cos (π / 2 - π / 3) ^ 2 = cos (π / 6) ^ 2 [PROOFSTEP] congr [GOAL] case e_a.e_x x : ℝ ⊢ π / 2 - π / 3 = π / 6 [PROOFSTEP] ring [GOAL] x : ℝ ⊢ sin (π / 3) = sqrt 3 / 2 [PROOFSTEP] rw [← cos_pi_div_two_sub, ← cos_pi_div_six] [GOAL] x : ℝ ⊢ cos (π / 2 - π / 3) = cos (π / 6) [PROOFSTEP] congr [GOAL] case e_x x : ℝ ⊢ π / 2 - π / 3 = π / 6 [PROOFSTEP] ring [GOAL] ⊢ tan (π / 4) = 1 [PROOFSTEP] rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four] [GOAL] ⊢ sqrt 2 / 2 / (sqrt 2 / 2) = 1 [PROOFSTEP] have h : sqrt 2 / 2 > 0 := by cancel_denoms [GOAL] ⊢ sqrt 2 / 2 > 0 [PROOFSTEP] cancel_denoms [GOAL] ⊢ sqrt 2 / 2 > 0 [PROOFSTEP] cancel_denoms [GOAL] h : sqrt 2 / 2 > 0 ⊢ sqrt 2 / 2 / (sqrt 2 / 2) = 1 [PROOFSTEP] exact div_self (ne_of_gt h) [GOAL] ⊢ tan (π / 2) = 0 [PROOFSTEP] simp [tan_eq_sin_div_cos] [GOAL] x : ℝ h0x : 0 < x hxp : x < π / 2 ⊢ 0 < tan x [PROOFSTEP] rw [tan_eq_sin_div_cos] [GOAL] x : ℝ h0x : 0 < x hxp : x < π / 2 ⊢ 0 < sin x / cos x [PROOFSTEP] exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) [GOAL] x : ℝ h0x : 0 < x hxp : x < π / 2 ⊢ x < π [PROOFSTEP] linarith [GOAL] x : ℝ h0x : 0 < x hxp : x < π / 2 ⊢ -(π / 2) < x [PROOFSTEP] linarith [GOAL] x : ℝ h0x : 0 ≤ x hxp✝ : x ≤ π / 2 h✝ : 0 < x hxp : x = π / 2 ⊢ 0 ≤ tan x [PROOFSTEP] simp [hxp, tan_eq_sin_div_cos] [GOAL] x : ℝ h0x : 0 ≤ x hxp : x ≤ π / 2 hx0 : 0 = x x✝ : x < π / 2 ∨ x = π / 2 ⊢ 0 ≤ tan x [PROOFSTEP] simp [hx0.symm] [GOAL] x : ℝ hx0 : x < 0 hpx : -(π / 2) < x ⊢ 0 < -x [PROOFSTEP] linarith [GOAL] x : ℝ hx0 : x < 0 hpx : -(π / 2) < x ⊢ -x < π / 2 [PROOFSTEP] linarith [pi_pos] [GOAL] x : ℝ hx0 : x ≤ 0 hpx : -(π / 2) ≤ x ⊢ 0 ≤ -x [PROOFSTEP] linarith [GOAL] x : ℝ hx0 : x ≤ 0 hpx : -(π / 2) ≤ x ⊢ -x ≤ π / 2 [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y < π / 2 hxy : x < y ⊢ tan x < tan y [PROOFSTEP] rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos] [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y < π / 2 hxy : x < y ⊢ sin x / cos x < sin y / cos y [PROOFSTEP] exact div_lt_div (sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy) (cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy)) (sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hy₂⟩) [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y < π / 2 hxy : x < y ⊢ -(π / 2) ≤ x [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y < π / 2 hxy : x < y ⊢ y ≤ π [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y < π / 2 hxy : x < y ⊢ 0 ≤ y [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y < π / 2 hxy : x < y ⊢ y ≤ π [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : 0 ≤ x hy₂ : y < π / 2 hxy : x < y ⊢ -(π / 2) < y [PROOFSTEP] linarith [GOAL] x y : ℝ hx₁ : -(π / 2) < x hy₂ : y < π / 2 hxy : x < y hx0 : x ≤ 0 hy0 : y ≤ 0 ⊢ -tan y < -tan x [PROOFSTEP] rw [← tan_neg, ← tan_neg] [GOAL] x y : ℝ hx₁ : -(π / 2) < x hy₂ : y < π / 2 hxy : x < y hx0 : x ≤ 0 hy0 : y ≤ 0 ⊢ tan (-y) < tan (-x) [PROOFSTEP] exact tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0) (neg_lt.2 hx₁) (neg_lt_neg hxy) [GOAL] x y : ℝ hx₁ : -(π / 2) < x hy₂ : y < π / 2 hxy : x < y hx0 : x ≤ 0 hy0✝ : 0 ≤ y hy0 : 0 = y ⊢ tan x < tan y [PROOFSTEP] rw [← hy0, tan_zero] [GOAL] x y : ℝ hx₁ : -(π / 2) < x hy₂ : y < π / 2 hxy : x < y hx0 : x ≤ 0 hy0✝ : 0 ≤ y hy0 : 0 = y ⊢ tan x < 0 [PROOFSTEP] exact tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁ [GOAL] x y : ℝ hx₁ : -(π / 2) < x hy₂ : y < π / 2 hxy : x < y hx0 : 0 ≤ x hy0 : y ≤ 0 ⊢ tan x < tan y [PROOFSTEP] linarith [GOAL] ⊢ Function.Periodic tan π [PROOFSTEP] simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic [GOAL] ⊢ tan π = 0 [PROOFSTEP] rw [tan_periodic.eq, tan_zero] [GOAL] x : ℝ ⊢ tan (π / 2 - x) = (tan x)⁻¹ [PROOFSTEP] rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] [GOAL] ⊢ Tendsto sin (𝓝[Iio (π / 2)] (π / 2)) (𝓝 1) [PROOFSTEP] convert continuous_sin.continuousWithinAt.tendsto [GOAL] case h.e'_5.h.e'_3 ⊢ 1 = sin (π / 2) [PROOFSTEP] simp [GOAL] ⊢ Tendsto cos (𝓝[Iio (π / 2)] (π / 2)) (𝓝[Ioi 0] 0) [PROOFSTEP] apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within [GOAL] case h1 ⊢ Tendsto cos (𝓝[Iio (π / 2)] (π / 2)) (𝓝 0) [PROOFSTEP] convert continuous_cos.continuousWithinAt.tendsto [GOAL] case h.e'_5.h.e'_3 ⊢ 0 = cos (π / 2) [PROOFSTEP] simp [GOAL] case h2 ⊢ ∀ᶠ (x : ℝ) in 𝓝[Iio (π / 2)] (π / 2), cos x ∈ Ioi 0 [PROOFSTEP] filter_upwards [Ioo_mem_nhdsWithin_Iio (right_mem_Ioc.mpr (neg_lt_self pi_div_two_pos))] with x hx using cos_pos_of_mem_Ioo hx [GOAL] ⊢ Tendsto tan (𝓝[Iio (π / 2)] (π / 2)) atTop [PROOFSTEP] convert tendsto_cos_pi_div_two.inv_tendsto_zero.atTop_mul zero_lt_one tendsto_sin_pi_div_two using 1 [GOAL] case h.e'_3 ⊢ tan = fun x => cos⁻¹ x * sin x [PROOFSTEP] simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] [GOAL] ⊢ Tendsto sin (𝓝[Ioi (-(π / 2))] (-(π / 2))) (𝓝 (-1)) [PROOFSTEP] convert continuous_sin.continuousWithinAt.tendsto using 2 [GOAL] case h.e'_5.h.e'_3 ⊢ -1 = sin (-(π / 2)) [PROOFSTEP] simp [GOAL] ⊢ Tendsto cos (𝓝[Ioi (-(π / 2))] (-(π / 2))) (𝓝[Ioi 0] 0) [PROOFSTEP] apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within [GOAL] case h1 ⊢ Tendsto cos (𝓝[Ioi (-(π / 2))] (-(π / 2))) (𝓝 0) [PROOFSTEP] convert continuous_cos.continuousWithinAt.tendsto [GOAL] case h.e'_5.h.e'_3 ⊢ 0 = cos (-(π / 2)) [PROOFSTEP] simp [GOAL] case h2 ⊢ ∀ᶠ (x : ℝ) in 𝓝[Ioi (-(π / 2))] (-(π / 2)), cos x ∈ Ioi 0 [PROOFSTEP] filter_upwards [Ioo_mem_nhdsWithin_Ioi (left_mem_Ico.mpr (neg_lt_self pi_div_two_pos))] with x hx using cos_pos_of_mem_Ioo hx [GOAL] ⊢ Tendsto tan (𝓝[Ioi (-(π / 2))] (-(π / 2))) atBot [PROOFSTEP] convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.atTop_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two using 1 [GOAL] ⊢ -1 < 0 [PROOFSTEP] norm_num [GOAL] case h.e'_3 ⊢ tan = fun x => cos⁻¹ x * sin x [PROOFSTEP] simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] [GOAL] z : ℂ ⊢ sin z = 0 ↔ cos z = 1 ∨ cos z = -1 [PROOFSTEP] rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self] [GOAL] z : ℂ ⊢ sin z = 0 ↔ 0 = sin z * sin z [PROOFSTEP] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ [GOAL] z : ℂ h : sin z = 0 ⊢ 0 = sin z * sin z [PROOFSTEP] rw [h, mul_zero] [GOAL] ⊢ cos (↑π / 2) = ↑(Real.cos (π / 2)) [PROOFSTEP] rw [ofReal_cos] [GOAL] ⊢ cos (↑π / 2) = cos ↑(π / 2) [PROOFSTEP] simp [GOAL] ⊢ ↑(Real.cos (π / 2)) = 0 [PROOFSTEP] simp [GOAL] ⊢ sin (↑π / 2) = ↑(Real.sin (π / 2)) [PROOFSTEP] rw [ofReal_sin] [GOAL] ⊢ sin (↑π / 2) = sin ↑(π / 2) [PROOFSTEP] simp [GOAL] ⊢ ↑(Real.sin (π / 2)) = 1 [PROOFSTEP] simp [GOAL] ⊢ sin ↑π = 0 [PROOFSTEP] rw [← ofReal_sin, Real.sin_pi] [GOAL] ⊢ ↑0 = 0 [PROOFSTEP] simp [GOAL] ⊢ cos ↑π = -1 [PROOFSTEP] rw [← ofReal_cos, Real.cos_pi] [GOAL] ⊢ ↑(-1) = -1 [PROOFSTEP] simp [GOAL] ⊢ sin (2 * ↑π) = 0 [PROOFSTEP] simp [two_mul, sin_add] [GOAL] ⊢ cos (2 * ↑π) = 1 [PROOFSTEP] simp [two_mul, cos_add] [GOAL] ⊢ Function.Antiperiodic sin ↑π [PROOFSTEP] simp [sin_add] [GOAL] ⊢ Function.Antiperiodic cos ↑π [PROOFSTEP] simp [cos_add] [GOAL] n : ℕ ⊢ cos (↑n * (2 * ↑π) + ↑π) = -1 [PROOFSTEP] simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic [GOAL] n : ℤ ⊢ cos (↑n * (2 * ↑π) + ↑π) = -1 [PROOFSTEP] simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic [GOAL] n : ℕ ⊢ cos (↑n * (2 * ↑π) - ↑π) = -1 [PROOFSTEP] simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic [GOAL] n : ℤ ⊢ cos (↑n * (2 * ↑π) - ↑π) = -1 [PROOFSTEP] simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic [GOAL] x : ℂ ⊢ sin (x + ↑π / 2) = cos x [PROOFSTEP] simp [sin_add] [GOAL] x : ℂ ⊢ sin (x - ↑π / 2) = -cos x [PROOFSTEP] simp [sub_eq_add_neg, sin_add] [GOAL] x : ℂ ⊢ sin (↑π / 2 - x) = cos x [PROOFSTEP] simp [sub_eq_add_neg, sin_add] [GOAL] x : ℂ ⊢ cos (x + ↑π / 2) = -sin x [PROOFSTEP] simp [cos_add] [GOAL] x : ℂ ⊢ cos (x - ↑π / 2) = sin x [PROOFSTEP] simp [sub_eq_add_neg, cos_add] [GOAL] x : ℂ ⊢ cos (↑π / 2 - x) = sin x [PROOFSTEP] rw [← cos_neg, neg_sub, cos_sub_pi_div_two] [GOAL] ⊢ Function.Periodic tan ↑π [PROOFSTEP] simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic [GOAL] x : ℂ ⊢ tan (↑π / 2 - x) = (tan x)⁻¹ [PROOFSTEP] rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] [GOAL] ⊢ Function.Antiperiodic exp (↑π * I) [PROOFSTEP] simp [exp_add, exp_mul_I] [GOAL] ⊢ Function.Antiperiodic (fun x => exp (x * I)) ↑π [PROOFSTEP] simpa only [mul_inv_cancel_right₀ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero [GOAL] a b : ℝ ha : a ≤ 0 z : ℂ hz : |z.im| ≤ b hb : b ≤ π / 2 ⊢ ↑abs (exp (↑a * (exp z + exp (-z)))) ≤ Real.exp (a * Real.cos b * Real.exp |z.re|) [PROOFSTEP] simp only [abs_exp, Real.exp_le_exp, ofReal_mul_re, add_re, exp_re, neg_im, Real.cos_neg, ← add_mul, mul_assoc, mul_comm (Real.cos b), neg_re, ← Real.cos_abs z.im] [GOAL] a b : ℝ ha : a ≤ 0 z : ℂ hz : |z.im| ≤ b hb : b ≤ π / 2 ⊢ a * ((Real.exp z.re + Real.exp (-z.re)) * Real.cos |z.im|) ≤ a * (Real.exp |z.re| * Real.cos b) [PROOFSTEP] have : Real.exp |z.re| ≤ Real.exp z.re + Real.exp (-z.re) := apply_abs_le_add_of_nonneg (fun x => (Real.exp_pos x).le) z.re [GOAL] a b : ℝ ha : a ≤ 0 z : ℂ hz : |z.im| ≤ b hb : b ≤ π / 2 this : Real.exp |z.re| ≤ Real.exp z.re + Real.exp (-z.re) ⊢ a * ((Real.exp z.re + Real.exp (-z.re)) * Real.cos |z.im|) ≤ a * (Real.exp |z.re| * Real.cos b) [PROOFSTEP] refine' mul_le_mul_of_nonpos_left (mul_le_mul this _ _ ((Real.exp_pos _).le.trans this)) ha [GOAL] case refine'_1 a b : ℝ ha : a ≤ 0 z : ℂ hz : |z.im| ≤ b hb : b ≤ π / 2 this : Real.exp |z.re| ≤ Real.exp z.re + Real.exp (-z.re) ⊢ Real.cos b ≤ Real.cos |z.im| [PROOFSTEP] exact Real.cos_le_cos_of_nonneg_of_le_pi (_root_.abs_nonneg _) (hb.trans <| half_le_self <| Real.pi_pos.le) hz [GOAL] case refine'_2 a b : ℝ ha : a ≤ 0 z : ℂ hz : |z.im| ≤ b hb : b ≤ π / 2 this : Real.exp |z.re| ≤ Real.exp z.re + Real.exp (-z.re) ⊢ 0 ≤ Real.cos b [PROOFSTEP] refine' Real.cos_nonneg_of_mem_Icc ⟨_, hb⟩ [GOAL] case refine'_2 a b : ℝ ha : a ≤ 0 z : ℂ hz : |z.im| ≤ b hb : b ≤ π / 2 this : Real.exp |z.re| ≤ Real.exp z.re + Real.exp (-z.re) ⊢ -(π / 2) ≤ b [PROOFSTEP] exact (neg_nonpos.2 <| Real.pi_div_two_pos.le).trans ((_root_.abs_nonneg _).trans hz)
lemma zero_pow_zero : (0 : mynat) ^ (0 : mynat) = 1 := begin rwa pow_zero, end
lemma bounded_linear_ident[simp]: "bounded_linear (\<lambda>x. x)"
(* Title: HOL/Library/Extended_Real.thy Author: Johannes Hölzl, TU München Author: Robert Himmelmann, TU München Author: Armin Heller, TU München Author: Bogdan Grechuk, University of Edinburgh *) section {* Extended real number line *} theory Extended_Real imports Complex_Main Extended_Nat Liminf_Limsup begin text {* This should be part of @{theory Extended_Nat}, but then the AFP-entry @{text "Jinja_Thread"} fails, as it does overload certain named from @{theory Complex_Main}. *} instantiation enat :: linorder_topology begin definition open_enat :: "enat set \<Rightarrow> bool" where "open_enat = generate_topology (range lessThan \<union> range greaterThan)" instance proof qed (rule open_enat_def) end lemma open_enat: "open {enat n}" proof (cases n) case 0 then have "{enat n} = {..< eSuc 0}" by (auto simp: enat_0) then show ?thesis by simp next case (Suc n') then have "{enat n} = {enat n' <..< enat (Suc n)}" apply auto apply (case_tac x) apply auto done then show ?thesis by simp qed lemma open_enat_iff: fixes A :: "enat set" shows "open A \<longleftrightarrow> (\<infinity> \<in> A \<longrightarrow> (\<exists>n::nat. {n <..} \<subseteq> A))" proof safe assume "\<infinity> \<notin> A" then have "A = (\<Union>n\<in>{n. enat n \<in> A}. {enat n})" apply auto apply (case_tac x) apply auto done moreover have "open \<dots>" by (auto intro: open_enat) ultimately show "open A" by simp next fix n assume "{enat n <..} \<subseteq> A" then have "A = (\<Union>n\<in>{n. enat n \<in> A}. {enat n}) \<union> {enat n <..}" apply auto apply (case_tac x) apply auto done moreover have "open \<dots>" by (intro open_Un open_UN ballI open_enat open_greaterThan) ultimately show "open A" by simp next assume "open A" "\<infinity> \<in> A" then have "generate_topology (range lessThan \<union> range greaterThan) A" "\<infinity> \<in> A" unfolding open_enat_def by auto then show "\<exists>n::nat. {n <..} \<subseteq> A" proof induction case (Int A B) then obtain n m where "{enat n<..} \<subseteq> A" "{enat m<..} \<subseteq> B" by auto then have "{enat (max n m) <..} \<subseteq> A \<inter> B" by (auto simp add: subset_eq Ball_def max_def enat_ord_code(1)[symmetric] simp del: enat_ord_code(1)) then show ?case by auto next case (UN K) then obtain k where "k \<in> K" "\<infinity> \<in> k" by auto with UN.IH[OF this] show ?case by auto qed auto qed text {* For more lemmas about the extended real numbers go to @{file "~~/src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy"} *} subsection {* Definition and basic properties *} datatype ereal = ereal real | PInfty | MInfty instantiation ereal :: uminus begin fun uminus_ereal where "- (ereal r) = ereal (- r)" | "- PInfty = MInfty" | "- MInfty = PInfty" instance .. end instantiation ereal :: infinity begin definition "(\<infinity>::ereal) = PInfty" instance .. end declare [[coercion "ereal :: real \<Rightarrow> ereal"]] lemma ereal_uminus_uminus[simp]: fixes a :: ereal shows "- (- a) = a" by (cases a) simp_all lemma shows PInfty_eq_infinity[simp]: "PInfty = \<infinity>" and MInfty_eq_minfinity[simp]: "MInfty = - \<infinity>" and MInfty_neq_PInfty[simp]: "\<infinity> \<noteq> - (\<infinity>::ereal)" "- \<infinity> \<noteq> (\<infinity>::ereal)" and MInfty_neq_ereal[simp]: "ereal r \<noteq> - \<infinity>" "- \<infinity> \<noteq> ereal r" and PInfty_neq_ereal[simp]: "ereal r \<noteq> \<infinity>" "\<infinity> \<noteq> ereal r" and PInfty_cases[simp]: "(case \<infinity> of ereal r \<Rightarrow> f r | PInfty \<Rightarrow> y | MInfty \<Rightarrow> z) = y" and MInfty_cases[simp]: "(case - \<infinity> of ereal r \<Rightarrow> f r | PInfty \<Rightarrow> y | MInfty \<Rightarrow> z) = z" by (simp_all add: infinity_ereal_def) declare PInfty_eq_infinity[code_post] MInfty_eq_minfinity[code_post] lemma [code_unfold]: "\<infinity> = PInfty" "- PInfty = MInfty" by simp_all lemma inj_ereal[simp]: "inj_on ereal A" unfolding inj_on_def by auto lemma ereal_cases[cases type: ereal]: obtains (real) r where "x = ereal r" | (PInf) "x = \<infinity>" | (MInf) "x = -\<infinity>" using assms by (cases x) auto lemmas ereal2_cases = ereal_cases[case_product ereal_cases] lemmas ereal3_cases = ereal2_cases[case_product ereal_cases] lemma ereal_all_split: "\<And>P. (\<forall>x::ereal. P x) \<longleftrightarrow> P \<infinity> \<and> (\<forall>x. P (ereal x)) \<and> P (-\<infinity>)" by (metis ereal_cases) lemma ereal_ex_split: "\<And>P. (\<exists>x::ereal. P x) \<longleftrightarrow> P \<infinity> \<or> (\<exists>x. P (ereal x)) \<or> P (-\<infinity>)" by (metis ereal_cases) lemma ereal_uminus_eq_iff[simp]: fixes a b :: ereal shows "-a = -b \<longleftrightarrow> a = b" by (cases rule: ereal2_cases[of a b]) simp_all instantiation ereal :: real_of begin function real_ereal :: "ereal \<Rightarrow> real" where "real_ereal (ereal r) = r" | "real_ereal \<infinity> = 0" | "real_ereal (-\<infinity>) = 0" by (auto intro: ereal_cases) termination by default (rule wf_empty) instance .. end lemma real_of_ereal[simp]: "real (- x :: ereal) = - (real x)" by (cases x) simp_all lemma range_ereal[simp]: "range ereal = UNIV - {\<infinity>, -\<infinity>}" proof safe fix x assume "x \<notin> range ereal" "x \<noteq> \<infinity>" then show "x = -\<infinity>" by (cases x) auto qed auto lemma ereal_range_uminus[simp]: "range uminus = (UNIV::ereal set)" proof safe fix x :: ereal show "x \<in> range uminus" by (intro image_eqI[of _ _ "-x"]) auto qed auto instantiation ereal :: abs begin function abs_ereal where "\<bar>ereal r\<bar> = ereal \<bar>r\<bar>" | "\<bar>-\<infinity>\<bar> = (\<infinity>::ereal)" | "\<bar>\<infinity>\<bar> = (\<infinity>::ereal)" by (auto intro: ereal_cases) termination proof qed (rule wf_empty) instance .. end lemma abs_eq_infinity_cases[elim!]: fixes x :: ereal assumes "\<bar>x\<bar> = \<infinity>" obtains "x = \<infinity>" | "x = -\<infinity>" using assms by (cases x) auto lemma abs_neq_infinity_cases[elim!]: fixes x :: ereal assumes "\<bar>x\<bar> \<noteq> \<infinity>" obtains r where "x = ereal r" using assms by (cases x) auto lemma abs_ereal_uminus[simp]: fixes x :: ereal shows "\<bar>- x\<bar> = \<bar>x\<bar>" by (cases x) auto lemma ereal_infinity_cases: fixes a :: ereal shows "a \<noteq> \<infinity> \<Longrightarrow> a \<noteq> -\<infinity> \<Longrightarrow> \<bar>a\<bar> \<noteq> \<infinity>" by auto subsubsection "Addition" instantiation ereal :: "{one,comm_monoid_add,zero_neq_one}" begin definition "0 = ereal 0" definition "1 = ereal 1" function plus_ereal where "ereal r + ereal p = ereal (r + p)" | "\<infinity> + a = (\<infinity>::ereal)" | "a + \<infinity> = (\<infinity>::ereal)" | "ereal r + -\<infinity> = - \<infinity>" | "-\<infinity> + ereal p = -(\<infinity>::ereal)" | "-\<infinity> + -\<infinity> = -(\<infinity>::ereal)" proof - case (goal1 P x) then obtain a b where "x = (a, b)" by (cases x) auto with goal1 show P by (cases rule: ereal2_cases[of a b]) auto qed auto termination by default (rule wf_empty) lemma Infty_neq_0[simp]: "(\<infinity>::ereal) \<noteq> 0" "0 \<noteq> (\<infinity>::ereal)" "-(\<infinity>::ereal) \<noteq> 0" "0 \<noteq> -(\<infinity>::ereal)" by (simp_all add: zero_ereal_def) lemma ereal_eq_0[simp]: "ereal r = 0 \<longleftrightarrow> r = 0" "0 = ereal r \<longleftrightarrow> r = 0" unfolding zero_ereal_def by simp_all lemma ereal_eq_1[simp]: "ereal r = 1 \<longleftrightarrow> r = 1" "1 = ereal r \<longleftrightarrow> r = 1" unfolding one_ereal_def by simp_all instance proof fix a b c :: ereal show "0 + a = a" by (cases a) (simp_all add: zero_ereal_def) show "a + b = b + a" by (cases rule: ereal2_cases[of a b]) simp_all show "a + b + c = a + (b + c)" by (cases rule: ereal3_cases[of a b c]) simp_all show "0 \<noteq> (1::ereal)" by (simp add: one_ereal_def zero_ereal_def) qed end instance ereal :: numeral .. lemma real_of_ereal_0[simp]: "real (0::ereal) = 0" unfolding zero_ereal_def by simp lemma abs_ereal_zero[simp]: "\<bar>0\<bar> = (0::ereal)" unfolding zero_ereal_def abs_ereal.simps by simp lemma ereal_uminus_zero[simp]: "- 0 = (0::ereal)" by (simp add: zero_ereal_def) lemma ereal_uminus_zero_iff[simp]: fixes a :: ereal shows "-a = 0 \<longleftrightarrow> a = 0" by (cases a) simp_all lemma ereal_plus_eq_PInfty[simp]: fixes a b :: ereal shows "a + b = \<infinity> \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_plus_eq_MInfty[simp]: fixes a b :: ereal shows "a + b = -\<infinity> \<longleftrightarrow> (a = -\<infinity> \<or> b = -\<infinity>) \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_add_cancel_left: fixes a b :: ereal assumes "a \<noteq> -\<infinity>" shows "a + b = a + c \<longleftrightarrow> a = \<infinity> \<or> b = c" using assms by (cases rule: ereal3_cases[of a b c]) auto lemma ereal_add_cancel_right: fixes a b :: ereal assumes "a \<noteq> -\<infinity>" shows "b + a = c + a \<longleftrightarrow> a = \<infinity> \<or> b = c" using assms by (cases rule: ereal3_cases[of a b c]) auto lemma ereal_real: "ereal (real x) = (if \<bar>x\<bar> = \<infinity> then 0 else x)" by (cases x) simp_all lemma real_of_ereal_add: fixes a b :: ereal shows "real (a + b) = (if (\<bar>a\<bar> = \<infinity>) \<and> (\<bar>b\<bar> = \<infinity>) \<or> (\<bar>a\<bar> \<noteq> \<infinity>) \<and> (\<bar>b\<bar> \<noteq> \<infinity>) then real a + real b else 0)" by (cases rule: ereal2_cases[of a b]) auto subsubsection "Linear order on @{typ ereal}" instantiation ereal :: linorder begin function less_ereal where " ereal x < ereal y \<longleftrightarrow> x < y" | "(\<infinity>::ereal) < a \<longleftrightarrow> False" | " a < -(\<infinity>::ereal) \<longleftrightarrow> False" | "ereal x < \<infinity> \<longleftrightarrow> True" | " -\<infinity> < ereal r \<longleftrightarrow> True" | " -\<infinity> < (\<infinity>::ereal) \<longleftrightarrow> True" proof - case (goal1 P x) then obtain a b where "x = (a,b)" by (cases x) auto with goal1 show P by (cases rule: ereal2_cases[of a b]) auto qed simp_all termination by (relation "{}") simp definition "x \<le> (y::ereal) \<longleftrightarrow> x < y \<or> x = y" lemma ereal_infty_less[simp]: fixes x :: ereal shows "x < \<infinity> \<longleftrightarrow> (x \<noteq> \<infinity>)" "-\<infinity> < x \<longleftrightarrow> (x \<noteq> -\<infinity>)" by (cases x, simp_all) (cases x, simp_all) lemma ereal_infty_less_eq[simp]: fixes x :: ereal shows "\<infinity> \<le> x \<longleftrightarrow> x = \<infinity>" and "x \<le> -\<infinity> \<longleftrightarrow> x = -\<infinity>" by (auto simp add: less_eq_ereal_def) lemma ereal_less[simp]: "ereal r < 0 \<longleftrightarrow> (r < 0)" "0 < ereal r \<longleftrightarrow> (0 < r)" "ereal r < 1 \<longleftrightarrow> (r < 1)" "1 < ereal r \<longleftrightarrow> (1 < r)" "0 < (\<infinity>::ereal)" "-(\<infinity>::ereal) < 0" by (simp_all add: zero_ereal_def one_ereal_def) lemma ereal_less_eq[simp]: "x \<le> (\<infinity>::ereal)" "-(\<infinity>::ereal) \<le> x" "ereal r \<le> ereal p \<longleftrightarrow> r \<le> p" "ereal r \<le> 0 \<longleftrightarrow> r \<le> 0" "0 \<le> ereal r \<longleftrightarrow> 0 \<le> r" "ereal r \<le> 1 \<longleftrightarrow> r \<le> 1" "1 \<le> ereal r \<longleftrightarrow> 1 \<le> r" by (auto simp add: less_eq_ereal_def zero_ereal_def one_ereal_def) lemma ereal_infty_less_eq2: "a \<le> b \<Longrightarrow> a = \<infinity> \<Longrightarrow> b = (\<infinity>::ereal)" "a \<le> b \<Longrightarrow> b = -\<infinity> \<Longrightarrow> a = -(\<infinity>::ereal)" by simp_all instance proof fix x y z :: ereal show "x \<le> x" by (cases x) simp_all show "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x" by (cases rule: ereal2_cases[of x y]) auto show "x \<le> y \<or> y \<le> x " by (cases rule: ereal2_cases[of x y]) auto { assume "x \<le> y" "y \<le> x" then show "x = y" by (cases rule: ereal2_cases[of x y]) auto } { assume "x \<le> y" "y \<le> z" then show "x \<le> z" by (cases rule: ereal3_cases[of x y z]) auto } qed end lemma ereal_dense2: "x < y \<Longrightarrow> \<exists>z. x < ereal z \<and> ereal z < y" using lt_ex gt_ex dense by (cases x y rule: ereal2_cases) auto instance ereal :: dense_linorder by default (blast dest: ereal_dense2) instance ereal :: ordered_ab_semigroup_add proof fix a b c :: ereal assume "a \<le> b" then show "c + a \<le> c + b" by (cases rule: ereal3_cases[of a b c]) auto qed lemma real_of_ereal_positive_mono: fixes x y :: ereal shows "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<noteq> \<infinity> \<Longrightarrow> real x \<le> real y" by (cases rule: ereal2_cases[of x y]) auto lemma ereal_MInfty_lessI[intro, simp]: fixes a :: ereal shows "a \<noteq> -\<infinity> \<Longrightarrow> -\<infinity> < a" by (cases a) auto lemma ereal_less_PInfty[intro, simp]: fixes a :: ereal shows "a \<noteq> \<infinity> \<Longrightarrow> a < \<infinity>" by (cases a) auto lemma ereal_less_ereal_Ex: fixes a b :: ereal shows "x < ereal r \<longleftrightarrow> x = -\<infinity> \<or> (\<exists>p. p < r \<and> x = ereal p)" by (cases x) auto lemma less_PInf_Ex_of_nat: "x \<noteq> \<infinity> \<longleftrightarrow> (\<exists>n::nat. x < ereal (real n))" proof (cases x) case (real r) then show ?thesis using reals_Archimedean2[of r] by simp qed simp_all lemma ereal_add_mono: fixes a b c d :: ereal assumes "a \<le> b" and "c \<le> d" shows "a + c \<le> b + d" using assms apply (cases a) apply (cases rule: ereal3_cases[of b c d], auto) apply (cases rule: ereal3_cases[of b c d], auto) done lemma ereal_minus_le_minus[simp]: fixes a b :: ereal shows "- a \<le> - b \<longleftrightarrow> b \<le> a" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_minus_less_minus[simp]: fixes a b :: ereal shows "- a < - b \<longleftrightarrow> b < a" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_le_real_iff: "x \<le> real y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x \<le> y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x \<le> 0)" by (cases y) auto lemma real_le_ereal_iff: "real y \<le> x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y \<le> ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 \<le> x)" by (cases y) auto lemma ereal_less_real_iff: "x < real y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x < y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x < 0)" by (cases y) auto lemma real_less_ereal_iff: "real y < x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y < ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 < x)" by (cases y) auto lemma real_of_ereal_pos: fixes x :: ereal shows "0 \<le> x \<Longrightarrow> 0 \<le> real x" by (cases x) auto lemmas real_of_ereal_ord_simps = ereal_le_real_iff real_le_ereal_iff ereal_less_real_iff real_less_ereal_iff lemma abs_ereal_ge0[simp]: "0 \<le> x \<Longrightarrow> \<bar>x :: ereal\<bar> = x" by (cases x) auto lemma abs_ereal_less0[simp]: "x < 0 \<Longrightarrow> \<bar>x :: ereal\<bar> = -x" by (cases x) auto lemma abs_ereal_pos[simp]: "0 \<le> \<bar>x :: ereal\<bar>" by (cases x) auto lemma real_of_ereal_le_0[simp]: "real (x :: ereal) \<le> 0 \<longleftrightarrow> x \<le> 0 \<or> x = \<infinity>" by (cases x) auto lemma abs_real_of_ereal[simp]: "\<bar>real (x :: ereal)\<bar> = real \<bar>x\<bar>" by (cases x) auto lemma zero_less_real_of_ereal: fixes x :: ereal shows "0 < real x \<longleftrightarrow> 0 < x \<and> x \<noteq> \<infinity>" by (cases x) auto lemma ereal_0_le_uminus_iff[simp]: fixes a :: ereal shows "0 \<le> - a \<longleftrightarrow> a \<le> 0" by (cases rule: ereal2_cases[of a]) auto lemma ereal_uminus_le_0_iff[simp]: fixes a :: ereal shows "- a \<le> 0 \<longleftrightarrow> 0 \<le> a" by (cases rule: ereal2_cases[of a]) auto lemma ereal_add_strict_mono: fixes a b c d :: ereal assumes "a \<le> b" and "0 \<le> a" and "a \<noteq> \<infinity>" and "c < d" shows "a + c < b + d" using assms by (cases rule: ereal3_cases[case_product ereal_cases, of a b c d]) auto lemma ereal_less_add: fixes a b c :: ereal shows "\<bar>a\<bar> \<noteq> \<infinity> \<Longrightarrow> c < b \<Longrightarrow> a + c < a + b" by (cases rule: ereal2_cases[of b c]) auto lemma ereal_add_nonneg_eq_0_iff: fixes a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> a + b = 0 \<longleftrightarrow> a = 0 \<and> b = 0" by (cases a b rule: ereal2_cases) auto lemma ereal_uminus_eq_reorder: "- a = b \<longleftrightarrow> a = (-b::ereal)" by auto lemma ereal_uminus_less_reorder: "- a < b \<longleftrightarrow> -b < (a::ereal)" by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_less_minus) lemma ereal_uminus_le_reorder: "- a \<le> b \<longleftrightarrow> -b \<le> (a::ereal)" by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_le_minus) lemmas ereal_uminus_reorder = ereal_uminus_eq_reorder ereal_uminus_less_reorder ereal_uminus_le_reorder lemma ereal_bot: fixes x :: ereal assumes "\<And>B. x \<le> ereal B" shows "x = - \<infinity>" proof (cases x) case (real r) with assms[of "r - 1"] show ?thesis by auto next case PInf with assms[of 0] show ?thesis by auto next case MInf then show ?thesis by simp qed lemma ereal_top: fixes x :: ereal assumes "\<And>B. x \<ge> ereal B" shows "x = \<infinity>" proof (cases x) case (real r) with assms[of "r + 1"] show ?thesis by auto next case MInf with assms[of 0] show ?thesis by auto next case PInf then show ?thesis by simp qed lemma shows ereal_max[simp]: "ereal (max x y) = max (ereal x) (ereal y)" and ereal_min[simp]: "ereal (min x y) = min (ereal x) (ereal y)" by (simp_all add: min_def max_def) lemma ereal_max_0: "max 0 (ereal r) = ereal (max 0 r)" by (auto simp: zero_ereal_def) lemma fixes f :: "nat \<Rightarrow> ereal" shows ereal_incseq_uminus[simp]: "incseq (\<lambda>x. - f x) \<longleftrightarrow> decseq f" and ereal_decseq_uminus[simp]: "decseq (\<lambda>x. - f x) \<longleftrightarrow> incseq f" unfolding decseq_def incseq_def by auto lemma incseq_ereal: "incseq f \<Longrightarrow> incseq (\<lambda>x. ereal (f x))" unfolding incseq_def by auto lemma ereal_add_nonneg_nonneg[simp]: fixes a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a + b" using add_mono[of 0 a 0 b] by simp lemma image_eqD: "f ` A = B \<Longrightarrow> \<forall>x\<in>A. f x \<in> B" by auto lemma incseq_setsumI: fixes f :: "nat \<Rightarrow> 'a::{comm_monoid_add,ordered_ab_semigroup_add}" assumes "\<And>i. 0 \<le> f i" shows "incseq (\<lambda>i. setsum f {..< i})" proof (intro incseq_SucI) fix n have "setsum f {..< n} + 0 \<le> setsum f {..<n} + f n" using assms by (rule add_left_mono) then show "setsum f {..< n} \<le> setsum f {..< Suc n}" by auto qed lemma incseq_setsumI2: fixes f :: "'i \<Rightarrow> nat \<Rightarrow> 'a::{comm_monoid_add,ordered_ab_semigroup_add}" assumes "\<And>n. n \<in> A \<Longrightarrow> incseq (f n)" shows "incseq (\<lambda>i. \<Sum>n\<in>A. f n i)" using assms unfolding incseq_def by (auto intro: setsum_mono) lemma setsum_ereal[simp]: "(\<Sum>x\<in>A. ereal (f x)) = ereal (\<Sum>x\<in>A. f x)" proof (cases "finite A") case True then show ?thesis by induct auto next case False then show ?thesis by simp qed lemma setsum_Pinfty: fixes f :: "'a \<Rightarrow> ereal" shows "(\<Sum>x\<in>P. f x) = \<infinity> \<longleftrightarrow> finite P \<and> (\<exists>i\<in>P. f i = \<infinity>)" proof safe assume *: "setsum f P = \<infinity>" show "finite P" proof (rule ccontr) assume "\<not> finite P" with * show False by auto qed show "\<exists>i\<in>P. f i = \<infinity>" proof (rule ccontr) assume "\<not> ?thesis" then have "\<And>i. i \<in> P \<Longrightarrow> f i \<noteq> \<infinity>" by auto with `finite P` have "setsum f P \<noteq> \<infinity>" by induct auto with * show False by auto qed next fix i assume "finite P" and "i \<in> P" and "f i = \<infinity>" then show "setsum f P = \<infinity>" proof induct case (insert x A) show ?case using insert by (cases "x = i") auto qed simp qed lemma setsum_Inf: fixes f :: "'a \<Rightarrow> ereal" shows "\<bar>setsum f A\<bar> = \<infinity> \<longleftrightarrow> finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)" proof assume *: "\<bar>setsum f A\<bar> = \<infinity>" have "finite A" by (rule ccontr) (insert *, auto) moreover have "\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>" proof (rule ccontr) assume "\<not> ?thesis" then have "\<forall>i\<in>A. \<exists>r. f i = ereal r" by auto from bchoice[OF this] obtain r where "\<forall>x\<in>A. f x = ereal (r x)" .. with * show False by auto qed ultimately show "finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)" by auto next assume "finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)" then obtain i where "finite A" "i \<in> A" and "\<bar>f i\<bar> = \<infinity>" by auto then show "\<bar>setsum f A\<bar> = \<infinity>" proof induct case (insert j A) then show ?case by (cases rule: ereal3_cases[of "f i" "f j" "setsum f A"]) auto qed simp qed lemma setsum_real_of_ereal: fixes f :: "'i \<Rightarrow> ereal" assumes "\<And>x. x \<in> S \<Longrightarrow> \<bar>f x\<bar> \<noteq> \<infinity>" shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)" proof - have "\<forall>x\<in>S. \<exists>r. f x = ereal r" proof fix x assume "x \<in> S" from assms[OF this] show "\<exists>r. f x = ereal r" by (cases "f x") auto qed from bchoice[OF this] obtain r where "\<forall>x\<in>S. f x = ereal (r x)" .. then show ?thesis by simp qed lemma setsum_ereal_0: fixes f :: "'a \<Rightarrow> ereal" assumes "finite A" and "\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i" shows "(\<Sum>x\<in>A. f x) = 0 \<longleftrightarrow> (\<forall>i\<in>A. f i = 0)" proof assume "setsum f A = 0" with assms show "\<forall>i\<in>A. f i = 0" proof (induction A) case (insert a A) then have "f a = 0 \<and> (\<Sum>a\<in>A. f a) = 0" by (subst ereal_add_nonneg_eq_0_iff[symmetric]) (simp_all add: setsum_nonneg) with insert show ?case by simp qed simp qed auto subsubsection "Multiplication" instantiation ereal :: "{comm_monoid_mult,sgn}" begin function sgn_ereal :: "ereal \<Rightarrow> ereal" where "sgn (ereal r) = ereal (sgn r)" | "sgn (\<infinity>::ereal) = 1" | "sgn (-\<infinity>::ereal) = -1" by (auto intro: ereal_cases) termination by default (rule wf_empty) function times_ereal where "ereal r * ereal p = ereal (r * p)" | "ereal r * \<infinity> = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)" | "\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)" | "ereal r * -\<infinity> = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)" | "-\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)" | "(\<infinity>::ereal) * \<infinity> = \<infinity>" | "-(\<infinity>::ereal) * \<infinity> = -\<infinity>" | "(\<infinity>::ereal) * -\<infinity> = -\<infinity>" | "-(\<infinity>::ereal) * -\<infinity> = \<infinity>" proof - case (goal1 P x) then obtain a b where "x = (a, b)" by (cases x) auto with goal1 show P by (cases rule: ereal2_cases[of a b]) auto qed simp_all termination by (relation "{}") simp instance proof fix a b c :: ereal show "1 * a = a" by (cases a) (simp_all add: one_ereal_def) show "a * b = b * a" by (cases rule: ereal2_cases[of a b]) simp_all show "a * b * c = a * (b * c)" by (cases rule: ereal3_cases[of a b c]) (simp_all add: zero_ereal_def zero_less_mult_iff) qed end lemma one_not_le_zero_ereal[simp]: "\<not> (1 \<le> (0::ereal))" by (simp add: one_ereal_def zero_ereal_def) lemma real_ereal_1[simp]: "real (1::ereal) = 1" unfolding one_ereal_def by simp lemma real_of_ereal_le_1: fixes a :: ereal shows "a \<le> 1 \<Longrightarrow> real a \<le> 1" by (cases a) (auto simp: one_ereal_def) lemma abs_ereal_one[simp]: "\<bar>1\<bar> = (1::ereal)" unfolding one_ereal_def by simp lemma ereal_mult_zero[simp]: fixes a :: ereal shows "a * 0 = 0" by (cases a) (simp_all add: zero_ereal_def) lemma ereal_zero_mult[simp]: fixes a :: ereal shows "0 * a = 0" by (cases a) (simp_all add: zero_ereal_def) lemma ereal_m1_less_0[simp]: "-(1::ereal) < 0" by (simp add: zero_ereal_def one_ereal_def) lemma ereal_times[simp]: "1 \<noteq> (\<infinity>::ereal)" "(\<infinity>::ereal) \<noteq> 1" "1 \<noteq> -(\<infinity>::ereal)" "-(\<infinity>::ereal) \<noteq> 1" by (auto simp add: times_ereal_def one_ereal_def) lemma ereal_plus_1[simp]: "1 + ereal r = ereal (r + 1)" "ereal r + 1 = ereal (r + 1)" "1 + -(\<infinity>::ereal) = -\<infinity>" "-(\<infinity>::ereal) + 1 = -\<infinity>" unfolding one_ereal_def by auto lemma ereal_zero_times[simp]: fixes a b :: ereal shows "a * b = 0 \<longleftrightarrow> a = 0 \<or> b = 0" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_mult_eq_PInfty[simp]: "a * b = (\<infinity>::ereal) \<longleftrightarrow> (a = \<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = -\<infinity>)" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_mult_eq_MInfty[simp]: "a * b = -(\<infinity>::ereal) \<longleftrightarrow> (a = \<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = -\<infinity>)" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_abs_mult: "\<bar>x * y :: ereal\<bar> = \<bar>x\<bar> * \<bar>y\<bar>" by (cases x y rule: ereal2_cases) (auto simp: abs_mult) lemma ereal_0_less_1[simp]: "0 < (1::ereal)" by (simp_all add: zero_ereal_def one_ereal_def) lemma ereal_mult_minus_left[simp]: fixes a b :: ereal shows "-a * b = - (a * b)" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_mult_minus_right[simp]: fixes a b :: ereal shows "a * -b = - (a * b)" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_mult_infty[simp]: "a * (\<infinity>::ereal) = (if a = 0 then 0 else if 0 < a then \<infinity> else - \<infinity>)" by (cases a) auto lemma ereal_infty_mult[simp]: "(\<infinity>::ereal) * a = (if a = 0 then 0 else if 0 < a then \<infinity> else - \<infinity>)" by (cases a) auto lemma ereal_mult_strict_right_mono: assumes "a < b" and "0 < c" and "c < (\<infinity>::ereal)" shows "a * c < b * c" using assms by (cases rule: ereal3_cases[of a b c]) (auto simp: zero_le_mult_iff) lemma ereal_mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c < (\<infinity>::ereal) \<Longrightarrow> c * a < c * b" using ereal_mult_strict_right_mono by (simp add: mult.commute[of c]) lemma ereal_mult_right_mono: fixes a b c :: ereal shows "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c" using assms apply (cases "c = 0") apply simp apply (cases rule: ereal3_cases[of a b c]) apply (auto simp: zero_le_mult_iff) done lemma ereal_mult_left_mono: fixes a b c :: ereal shows "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b" using ereal_mult_right_mono by (simp add: mult.commute[of c]) lemma zero_less_one_ereal[simp]: "0 \<le> (1::ereal)" by (simp add: one_ereal_def zero_ereal_def) lemma ereal_0_le_mult[simp]: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * (b :: ereal)" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_right_distrib: fixes r a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> r * (a + b) = r * a + r * b" by (cases rule: ereal3_cases[of r a b]) (simp_all add: field_simps) lemma ereal_left_distrib: fixes r a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> (a + b) * r = a * r + b * r" by (cases rule: ereal3_cases[of r a b]) (simp_all add: field_simps) lemma ereal_mult_le_0_iff: fixes a b :: ereal shows "a * b \<le> 0 \<longleftrightarrow> (0 \<le> a \<and> b \<le> 0) \<or> (a \<le> 0 \<and> 0 \<le> b)" by (cases rule: ereal2_cases[of a b]) (simp_all add: mult_le_0_iff) lemma ereal_zero_le_0_iff: fixes a b :: ereal shows "0 \<le> a * b \<longleftrightarrow> (0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0)" by (cases rule: ereal2_cases[of a b]) (simp_all add: zero_le_mult_iff) lemma ereal_mult_less_0_iff: fixes a b :: ereal shows "a * b < 0 \<longleftrightarrow> (0 < a \<and> b < 0) \<or> (a < 0 \<and> 0 < b)" by (cases rule: ereal2_cases[of a b]) (simp_all add: mult_less_0_iff) lemma ereal_zero_less_0_iff: fixes a b :: ereal shows "0 < a * b \<longleftrightarrow> (0 < a \<and> 0 < b) \<or> (a < 0 \<and> b < 0)" by (cases rule: ereal2_cases[of a b]) (simp_all add: zero_less_mult_iff) lemma ereal_left_mult_cong: fixes a b c :: ereal shows "c = d \<Longrightarrow> (d \<noteq> 0 \<Longrightarrow> a = b) \<Longrightarrow> a * c = b * d" by (cases "c = 0") simp_all lemma ereal_right_mult_cong: fixes a b c :: ereal shows "c = d \<Longrightarrow> (d \<noteq> 0 \<Longrightarrow> a = b) \<Longrightarrow> c * a = d * b" by (cases "c = 0") simp_all lemma ereal_distrib: fixes a b c :: ereal assumes "a \<noteq> \<infinity> \<or> b \<noteq> -\<infinity>" and "a \<noteq> -\<infinity> \<or> b \<noteq> \<infinity>" and "\<bar>c\<bar> \<noteq> \<infinity>" shows "(a + b) * c = a * c + b * c" using assms by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps) lemma numeral_eq_ereal [simp]: "numeral w = ereal (numeral w)" apply (induct w rule: num_induct) apply (simp only: numeral_One one_ereal_def) apply (simp only: numeral_inc ereal_plus_1) done lemma setsum_ereal_right_distrib: fixes f :: "'a \<Rightarrow> ereal" shows "(\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> r * setsum f A = (\<Sum>n\<in>A. r * f n)" by (induct A rule: infinite_finite_induct) (auto simp: ereal_right_distrib setsum_nonneg) lemma setsum_ereal_left_distrib: "(\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> setsum f A * r = (\<Sum>n\<in>A. f n * r :: ereal)" using setsum_ereal_right_distrib[of A f r] by (simp add: mult_ac) lemma ereal_le_epsilon: fixes x y :: ereal assumes "\<forall>e. 0 < e \<longrightarrow> x \<le> y + e" shows "x \<le> y" proof - { assume a: "\<exists>r. y = ereal r" then obtain r where r_def: "y = ereal r" by auto { assume "x = -\<infinity>" then have ?thesis by auto } moreover { assume "x \<noteq> -\<infinity>" then obtain p where p_def: "x = ereal p" using a assms[rule_format, of 1] by (cases x) auto { fix e have "0 < e \<longrightarrow> p \<le> r + e" using assms[rule_format, of "ereal e"] p_def r_def by auto } then have "p \<le> r" apply (subst field_le_epsilon) apply auto done then have ?thesis using r_def p_def by auto } ultimately have ?thesis by blast } moreover { assume "y = -\<infinity> | y = \<infinity>" then have ?thesis using assms[rule_format, of 1] by (cases x) auto } ultimately show ?thesis by (cases y) auto qed lemma ereal_le_epsilon2: fixes x y :: ereal assumes "\<forall>e. 0 < e \<longrightarrow> x \<le> y + ereal e" shows "x \<le> y" proof - { fix e :: ereal assume "e > 0" { assume "e = \<infinity>" then have "x \<le> y + e" by auto } moreover { assume "e \<noteq> \<infinity>" then obtain r where "e = ereal r" using `e > 0` by (cases e) auto then have "x \<le> y + e" using assms[rule_format, of r] `e>0` by auto } ultimately have "x \<le> y + e" by blast } then show ?thesis using ereal_le_epsilon by auto qed lemma ereal_le_real: fixes x y :: ereal assumes "\<forall>z. x \<le> ereal z \<longrightarrow> y \<le> ereal z" shows "y \<le> x" by (metis assms ereal_bot ereal_cases ereal_infty_less_eq(2) ereal_less_eq(1) linorder_le_cases) lemma setprod_ereal_0: fixes f :: "'a \<Rightarrow> ereal" shows "(\<Prod>i\<in>A. f i) = 0 \<longleftrightarrow> finite A \<and> (\<exists>i\<in>A. f i = 0)" proof (cases "finite A") case True then show ?thesis by (induct A) auto next case False then show ?thesis by auto qed lemma setprod_ereal_pos: fixes f :: "'a \<Rightarrow> ereal" assumes pos: "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i" shows "0 \<le> (\<Prod>i\<in>I. f i)" proof (cases "finite I") case True from this pos show ?thesis by induct auto next case False then show ?thesis by simp qed lemma setprod_PInf: fixes f :: "'a \<Rightarrow> ereal" assumes "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i" shows "(\<Prod>i\<in>I. f i) = \<infinity> \<longleftrightarrow> finite I \<and> (\<exists>i\<in>I. f i = \<infinity>) \<and> (\<forall>i\<in>I. f i \<noteq> 0)" proof (cases "finite I") case True from this assms show ?thesis proof (induct I) case (insert i I) then have pos: "0 \<le> f i" "0 \<le> setprod f I" by (auto intro!: setprod_ereal_pos) from insert have "(\<Prod>j\<in>insert i I. f j) = \<infinity> \<longleftrightarrow> setprod f I * f i = \<infinity>" by auto also have "\<dots> \<longleftrightarrow> (setprod f I = \<infinity> \<or> f i = \<infinity>) \<and> f i \<noteq> 0 \<and> setprod f I \<noteq> 0" using setprod_ereal_pos[of I f] pos by (cases rule: ereal2_cases[of "f i" "setprod f I"]) auto also have "\<dots> \<longleftrightarrow> finite (insert i I) \<and> (\<exists>j\<in>insert i I. f j = \<infinity>) \<and> (\<forall>j\<in>insert i I. f j \<noteq> 0)" using insert by (auto simp: setprod_ereal_0) finally show ?case . qed simp next case False then show ?thesis by simp qed lemma setprod_ereal: "(\<Prod>i\<in>A. ereal (f i)) = ereal (setprod f A)" proof (cases "finite A") case True then show ?thesis by induct (auto simp: one_ereal_def) next case False then show ?thesis by (simp add: one_ereal_def) qed subsubsection {* Power *} lemma ereal_power[simp]: "(ereal x) ^ n = ereal (x^n)" by (induct n) (auto simp: one_ereal_def) lemma ereal_power_PInf[simp]: "(\<infinity>::ereal) ^ n = (if n = 0 then 1 else \<infinity>)" by (induct n) (auto simp: one_ereal_def) lemma ereal_power_uminus[simp]: fixes x :: ereal shows "(- x) ^ n = (if even n then x ^ n else - (x^n))" by (induct n) (auto simp: one_ereal_def) lemma ereal_power_numeral[simp]: "(numeral num :: ereal) ^ n = ereal (numeral num ^ n)" by (induct n) (auto simp: one_ereal_def) lemma zero_le_power_ereal[simp]: fixes a :: ereal assumes "0 \<le> a" shows "0 \<le> a ^ n" using assms by (induct n) (auto simp: ereal_zero_le_0_iff) subsubsection {* Subtraction *} lemma ereal_minus_minus_image[simp]: fixes S :: "ereal set" shows "uminus ` uminus ` S = S" by (auto simp: image_iff) lemma ereal_uminus_lessThan[simp]: fixes a :: ereal shows "uminus ` {..<a} = {-a<..}" proof - { fix x assume "-a < x" then have "- x < - (- a)" by (simp del: ereal_uminus_uminus) then have "- x < a" by simp } then show ?thesis by force qed lemma ereal_uminus_greaterThan[simp]: "uminus ` {(a::ereal)<..} = {..<-a}" by (metis ereal_uminus_lessThan ereal_uminus_uminus ereal_minus_minus_image) instantiation ereal :: minus begin definition "x - y = x + -(y::ereal)" instance .. end lemma ereal_minus[simp]: "ereal r - ereal p = ereal (r - p)" "-\<infinity> - ereal r = -\<infinity>" "ereal r - \<infinity> = -\<infinity>" "(\<infinity>::ereal) - x = \<infinity>" "-(\<infinity>::ereal) - \<infinity> = -\<infinity>" "x - -y = x + y" "x - 0 = x" "0 - x = -x" by (simp_all add: minus_ereal_def) lemma ereal_x_minus_x[simp]: "x - x = (if \<bar>x\<bar> = \<infinity> then \<infinity> else 0::ereal)" by (cases x) simp_all lemma ereal_eq_minus_iff: fixes x y z :: ereal shows "x = z - y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x + y = z) \<and> (y = -\<infinity> \<longrightarrow> x = \<infinity>) \<and> (y = \<infinity> \<longrightarrow> z = \<infinity> \<longrightarrow> x = \<infinity>) \<and> (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>)" by (cases rule: ereal3_cases[of x y z]) auto lemma ereal_eq_minus: fixes x y z :: ereal shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x = z - y \<longleftrightarrow> x + y = z" by (auto simp: ereal_eq_minus_iff) lemma ereal_less_minus_iff: fixes x y z :: ereal shows "x < z - y \<longleftrightarrow> (y = \<infinity> \<longrightarrow> z = \<infinity> \<and> x \<noteq> \<infinity>) \<and> (y = -\<infinity> \<longrightarrow> x \<noteq> \<infinity>) \<and> (\<bar>y\<bar> \<noteq> \<infinity>\<longrightarrow> x + y < z)" by (cases rule: ereal3_cases[of x y z]) auto lemma ereal_less_minus: fixes x y z :: ereal shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x < z - y \<longleftrightarrow> x + y < z" by (auto simp: ereal_less_minus_iff) lemma ereal_le_minus_iff: fixes x y z :: ereal shows "x \<le> z - y \<longleftrightarrow> (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>) \<and> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x + y \<le> z)" by (cases rule: ereal3_cases[of x y z]) auto lemma ereal_le_minus: fixes x y z :: ereal shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x \<le> z - y \<longleftrightarrow> x + y \<le> z" by (auto simp: ereal_le_minus_iff) lemma ereal_minus_less_iff: fixes x y z :: ereal shows "x - y < z \<longleftrightarrow> y \<noteq> -\<infinity> \<and> (y = \<infinity> \<longrightarrow> x \<noteq> \<infinity> \<and> z \<noteq> -\<infinity>) \<and> (y \<noteq> \<infinity> \<longrightarrow> x < z + y)" by (cases rule: ereal3_cases[of x y z]) auto lemma ereal_minus_less: fixes x y z :: ereal shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x - y < z \<longleftrightarrow> x < z + y" by (auto simp: ereal_minus_less_iff) lemma ereal_minus_le_iff: fixes x y z :: ereal shows "x - y \<le> z \<longleftrightarrow> (y = -\<infinity> \<longrightarrow> z = \<infinity>) \<and> (y = \<infinity> \<longrightarrow> x = \<infinity> \<longrightarrow> z = \<infinity>) \<and> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x \<le> z + y)" by (cases rule: ereal3_cases[of x y z]) auto lemma ereal_minus_le: fixes x y z :: ereal shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x - y \<le> z \<longleftrightarrow> x \<le> z + y" by (auto simp: ereal_minus_le_iff) lemma ereal_minus_eq_minus_iff: fixes a b c :: ereal shows "a - b = a - c \<longleftrightarrow> b = c \<or> a = \<infinity> \<or> (a = -\<infinity> \<and> b \<noteq> -\<infinity> \<and> c \<noteq> -\<infinity>)" by (cases rule: ereal3_cases[of a b c]) auto lemma ereal_add_le_add_iff: fixes a b c :: ereal shows "c + a \<le> c + b \<longleftrightarrow> a \<le> b \<or> c = \<infinity> \<or> (c = -\<infinity> \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>)" by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps) lemma ereal_add_le_add_iff2: fixes a b c :: ereal shows "a + c \<le> b + c \<longleftrightarrow> a \<le> b \<or> c = \<infinity> \<or> (c = -\<infinity> \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>)" by(cases rule: ereal3_cases[of a b c])(simp_all add: field_simps) lemma ereal_mult_le_mult_iff: fixes a b c :: ereal shows "\<bar>c\<bar> \<noteq> \<infinity> \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)" by (cases rule: ereal3_cases[of a b c]) (simp_all add: mult_le_cancel_left) lemma ereal_minus_mono: fixes A B C D :: ereal assumes "A \<le> B" "D \<le> C" shows "A - C \<le> B - D" using assms by (cases rule: ereal3_cases[case_product ereal_cases, of A B C D]) simp_all lemma real_of_ereal_minus: fixes a b :: ereal shows "real (a - b) = (if \<bar>a\<bar> = \<infinity> \<or> \<bar>b\<bar> = \<infinity> then 0 else real a - real b)" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_diff_positive: fixes a b :: ereal shows "a \<le> b \<Longrightarrow> 0 \<le> b - a" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_between: fixes x e :: ereal assumes "\<bar>x\<bar> \<noteq> \<infinity>" and "0 < e" shows "x - e < x" and "x < x + e" using assms apply (cases x, cases e) apply auto using assms apply (cases x, cases e) apply auto done lemma ereal_minus_eq_PInfty_iff: fixes x y :: ereal shows "x - y = \<infinity> \<longleftrightarrow> y = -\<infinity> \<or> x = \<infinity>" by (cases x y rule: ereal2_cases) simp_all subsubsection {* Division *} instantiation ereal :: inverse begin function inverse_ereal where "inverse (ereal r) = (if r = 0 then \<infinity> else ereal (inverse r))" | "inverse (\<infinity>::ereal) = 0" | "inverse (-\<infinity>::ereal) = 0" by (auto intro: ereal_cases) termination by (relation "{}") simp definition "x / y = x * inverse (y :: ereal)" instance .. end lemma real_of_ereal_inverse[simp]: fixes a :: ereal shows "real (inverse a) = 1 / real a" by (cases a) (auto simp: inverse_eq_divide) lemma ereal_inverse[simp]: "inverse (0::ereal) = \<infinity>" "inverse (1::ereal) = 1" by (simp_all add: one_ereal_def zero_ereal_def) lemma ereal_divide[simp]: "ereal r / ereal p = (if p = 0 then ereal r * \<infinity> else ereal (r / p))" unfolding divide_ereal_def by (auto simp: divide_real_def) lemma ereal_divide_same[simp]: fixes x :: ereal shows "x / x = (if \<bar>x\<bar> = \<infinity> \<or> x = 0 then 0 else 1)" by (cases x) (simp_all add: divide_real_def divide_ereal_def one_ereal_def) lemma ereal_inv_inv[simp]: fixes x :: ereal shows "inverse (inverse x) = (if x \<noteq> -\<infinity> then x else \<infinity>)" by (cases x) auto lemma ereal_inverse_minus[simp]: fixes x :: ereal shows "inverse (- x) = (if x = 0 then \<infinity> else -inverse x)" by (cases x) simp_all lemma ereal_uminus_divide[simp]: fixes x y :: ereal shows "- x / y = - (x / y)" unfolding divide_ereal_def by simp lemma ereal_divide_Infty[simp]: fixes x :: ereal shows "x / \<infinity> = 0" "x / -\<infinity> = 0" unfolding divide_ereal_def by simp_all lemma ereal_divide_one[simp]: "x / 1 = (x::ereal)" unfolding divide_ereal_def by simp lemma ereal_divide_ereal[simp]: "\<infinity> / ereal r = (if 0 \<le> r then \<infinity> else -\<infinity>)" unfolding divide_ereal_def by simp lemma ereal_inverse_nonneg_iff: "0 \<le> inverse (x :: ereal) \<longleftrightarrow> 0 \<le> x \<or> x = -\<infinity>" by (cases x) auto lemma zero_le_divide_ereal[simp]: fixes a :: ereal assumes "0 \<le> a" and "0 \<le> b" shows "0 \<le> a / b" using assms by (cases rule: ereal2_cases[of a b]) (auto simp: zero_le_divide_iff) lemma ereal_le_divide_pos: fixes x y z :: ereal shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> x * y \<le> z" by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps) lemma ereal_divide_le_pos: fixes x y z :: ereal shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> z \<le> x * y" by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps) lemma ereal_le_divide_neg: fixes x y z :: ereal shows "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> z \<le> x * y" by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps) lemma ereal_divide_le_neg: fixes x y z :: ereal shows "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> x * y \<le> z" by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps) lemma ereal_inverse_antimono_strict: fixes x y :: ereal shows "0 \<le> x \<Longrightarrow> x < y \<Longrightarrow> inverse y < inverse x" by (cases rule: ereal2_cases[of x y]) auto lemma ereal_inverse_antimono: fixes x y :: ereal shows "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> inverse y \<le> inverse x" by (cases rule: ereal2_cases[of x y]) auto lemma inverse_inverse_Pinfty_iff[simp]: fixes x :: ereal shows "inverse x = \<infinity> \<longleftrightarrow> x = 0" by (cases x) auto lemma ereal_inverse_eq_0: fixes x :: ereal shows "inverse x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity>" by (cases x) auto lemma ereal_0_gt_inverse: fixes x :: ereal shows "0 < inverse x \<longleftrightarrow> x \<noteq> \<infinity> \<and> 0 \<le> x" by (cases x) auto lemma ereal_mult_less_right: fixes a b c :: ereal assumes "b * a < c * a" and "0 < a" and "a < \<infinity>" shows "b < c" using assms by (cases rule: ereal3_cases[of a b c]) (auto split: split_if_asm simp: zero_less_mult_iff zero_le_mult_iff) lemma ereal_mult_divide: fixes a b :: ereal shows "0 < b \<Longrightarrow> b < \<infinity> \<Longrightarrow> b * (a / b) = a" by (cases a b rule: ereal2_cases) auto lemma ereal_power_divide: fixes x y :: ereal shows "y \<noteq> 0 \<Longrightarrow> (x / y) ^ n = x^n / y^n" by (cases rule: ereal2_cases [of x y]) (auto simp: one_ereal_def zero_ereal_def power_divide zero_le_power_eq) lemma ereal_le_mult_one_interval: fixes x y :: ereal assumes y: "y \<noteq> -\<infinity>" assumes z: "\<And>z. 0 < z \<Longrightarrow> z < 1 \<Longrightarrow> z * x \<le> y" shows "x \<le> y" proof (cases x) case PInf with z[of "1 / 2"] show "x \<le> y" by (simp add: one_ereal_def) next case (real r) note r = this show "x \<le> y" proof (cases y) case (real p) note p = this have "r \<le> p" proof (rule field_le_mult_one_interval) fix z :: real assume "0 < z" and "z < 1" with z[of "ereal z"] show "z * r \<le> p" using p r by (auto simp: zero_le_mult_iff one_ereal_def) qed then show "x \<le> y" using p r by simp qed (insert y, simp_all) qed simp lemma ereal_divide_right_mono[simp]: fixes x y z :: ereal assumes "x \<le> y" and "0 < z" shows "x / z \<le> y / z" using assms by (cases x y z rule: ereal3_cases) (auto intro: divide_right_mono) lemma ereal_divide_left_mono[simp]: fixes x y z :: ereal assumes "y \<le> x" and "0 < z" and "0 < x * y" shows "z / x \<le> z / y" using assms by (cases x y z rule: ereal3_cases) (auto intro: divide_left_mono simp: field_simps zero_less_mult_iff mult_less_0_iff split: split_if_asm) lemma ereal_divide_zero_left[simp]: fixes a :: ereal shows "0 / a = 0" by (cases a) (auto simp: zero_ereal_def) lemma ereal_times_divide_eq_left[simp]: fixes a b c :: ereal shows "b / c * a = b * a / c" by (cases a b c rule: ereal3_cases) (auto simp: field_simps zero_less_mult_iff mult_less_0_iff) lemma ereal_times_divide_eq: "a * (b / c :: ereal) = a * b / c" by (cases a b c rule: ereal3_cases) (auto simp: field_simps zero_less_mult_iff) subsection "Complete lattice" instantiation ereal :: lattice begin definition [simp]: "sup x y = (max x y :: ereal)" definition [simp]: "inf x y = (min x y :: ereal)" instance by default simp_all end instantiation ereal :: complete_lattice begin definition "bot = (-\<infinity>::ereal)" definition "top = (\<infinity>::ereal)" definition "Sup S = (SOME x :: ereal. (\<forall>y\<in>S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>S. y \<le> z) \<longrightarrow> x \<le> z))" definition "Inf S = (SOME x :: ereal. (\<forall>y\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> x))" lemma ereal_complete_Sup: fixes S :: "ereal set" shows "\<exists>x. (\<forall>y\<in>S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>S. y \<le> z) \<longrightarrow> x \<le> z)" proof (cases "\<exists>x. \<forall>a\<in>S. a \<le> ereal x") case True then obtain y where y: "\<And>a. a\<in>S \<Longrightarrow> a \<le> ereal y" by auto then have "\<infinity> \<notin> S" by force show ?thesis proof (cases "S \<noteq> {-\<infinity>} \<and> S \<noteq> {}") case True with `\<infinity> \<notin> S` obtain x where x: "x \<in> S" "\<bar>x\<bar> \<noteq> \<infinity>" by auto obtain s where s: "\<forall>x\<in>ereal -` S. x \<le> s" "\<And>z. (\<forall>x\<in>ereal -` S. x \<le> z) \<Longrightarrow> s \<le> z" proof (atomize_elim, rule complete_real) show "\<exists>x. x \<in> ereal -` S" using x by auto show "\<exists>z. \<forall>x\<in>ereal -` S. x \<le> z" by (auto dest: y intro!: exI[of _ y]) qed show ?thesis proof (safe intro!: exI[of _ "ereal s"]) fix y assume "y \<in> S" with s `\<infinity> \<notin> S` show "y \<le> ereal s" by (cases y) auto next fix z assume "\<forall>y\<in>S. y \<le> z" with `S \<noteq> {-\<infinity>} \<and> S \<noteq> {}` show "ereal s \<le> z" by (cases z) (auto intro!: s) qed next case False then show ?thesis by (auto intro!: exI[of _ "-\<infinity>"]) qed next case False then show ?thesis by (fastforce intro!: exI[of _ \<infinity>] ereal_top intro: order_trans dest: less_imp_le simp: not_le) qed lemma ereal_complete_uminus_eq: fixes S :: "ereal set" shows "(\<forall>y\<in>uminus`S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>uminus`S. y \<le> z) \<longrightarrow> x \<le> z) \<longleftrightarrow> (\<forall>y\<in>S. -x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> -x)" by simp (metis ereal_minus_le_minus ereal_uminus_uminus) lemma ereal_complete_Inf: "\<exists>x. (\<forall>y\<in>S::ereal set. x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> x)" using ereal_complete_Sup[of "uminus ` S"] unfolding ereal_complete_uminus_eq by auto instance proof show "Sup {} = (bot::ereal)" apply (auto simp: bot_ereal_def Sup_ereal_def) apply (rule some1_equality) apply (metis ereal_bot ereal_less_eq(2)) apply (metis ereal_less_eq(2)) done show "Inf {} = (top::ereal)" apply (auto simp: top_ereal_def Inf_ereal_def) apply (rule some1_equality) apply (metis ereal_top ereal_less_eq(1)) apply (metis ereal_less_eq(1)) done qed (auto intro: someI2_ex ereal_complete_Sup ereal_complete_Inf simp: Sup_ereal_def Inf_ereal_def bot_ereal_def top_ereal_def) end instance ereal :: complete_linorder .. instance ereal :: linear_continuum proof show "\<exists>a b::ereal. a \<noteq> b" using zero_neq_one by blast qed lemma ereal_Sup_uminus_image_eq: "Sup (uminus ` S::ereal set) = - Inf S" by (auto intro!: SUP_eqI simp: Ball_def[symmetric] ereal_uminus_le_reorder le_Inf_iff intro!: complete_lattice_class.Inf_lower2) lemma ereal_SUP_uminus_eq: fixes f :: "'a \<Rightarrow> ereal" shows "(SUP x:S. uminus (f x)) = - (INF x:S. f x)" using ereal_Sup_uminus_image_eq [of "f ` S"] by (simp add: comp_def) lemma ereal_inj_on_uminus[intro, simp]: "inj_on uminus (A :: ereal set)" by (auto intro!: inj_onI) lemma ereal_Inf_uminus_image_eq: "Inf (uminus ` S::ereal set) = - Sup S" using ereal_Sup_uminus_image_eq[of "uminus ` S"] by simp lemma ereal_INF_uminus_eq: fixes f :: "'a \<Rightarrow> ereal" shows "(INF x:S. uminus (f x)) = - (SUP x:S. f x)" using ereal_Inf_uminus_image_eq [of "f ` S"] by (simp add: comp_def) lemma ereal_SUP_not_infty: fixes f :: "_ \<Rightarrow> ereal" shows "A \<noteq> {} \<Longrightarrow> l \<noteq> -\<infinity> \<Longrightarrow> u \<noteq> \<infinity> \<Longrightarrow> \<forall>a\<in>A. l \<le> f a \<and> f a \<le> u \<Longrightarrow> \<bar>SUPREMUM A f\<bar> \<noteq> \<infinity>" using SUP_upper2[of _ A l f] SUP_least[of A f u] by (cases "SUPREMUM A f") auto lemma ereal_INF_not_infty: fixes f :: "_ \<Rightarrow> ereal" shows "A \<noteq> {} \<Longrightarrow> l \<noteq> -\<infinity> \<Longrightarrow> u \<noteq> \<infinity> \<Longrightarrow> \<forall>a\<in>A. l \<le> f a \<and> f a \<le> u \<Longrightarrow> \<bar>INFIMUM A f\<bar> \<noteq> \<infinity>" using INF_lower2[of _ A f u] INF_greatest[of A l f] by (cases "INFIMUM A f") auto lemma ereal_SUP_uminus: fixes f :: "'a \<Rightarrow> ereal" shows "(SUP i : R. -(f i)) = -(INF i : R. f i)" using ereal_Sup_uminus_image_eq[of "f`R"] by (simp add: image_image) lemma ereal_INF_uminus: fixes f :: "'a \<Rightarrow> ereal" shows "(INF i : R. - f i) = - (SUP i : R. f i)" using ereal_SUP_uminus [of _ "\<lambda>x. - f x"] by simp lemma ereal_image_uminus_shift: fixes X Y :: "ereal set" shows "uminus ` X = Y \<longleftrightarrow> X = uminus ` Y" proof assume "uminus ` X = Y" then have "uminus ` uminus ` X = uminus ` Y" by (simp add: inj_image_eq_iff) then show "X = uminus ` Y" by (simp add: image_image) qed (simp add: image_image) lemma Inf_ereal_iff: fixes z :: ereal shows "(\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> (\<exists>x\<in>X. x < y) \<longleftrightarrow> Inf X < y" by (metis complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower less_le_not_le linear order_less_le_trans) lemma Sup_eq_MInfty: fixes S :: "ereal set" shows "Sup S = -\<infinity> \<longleftrightarrow> S = {} \<or> S = {-\<infinity>}" unfolding bot_ereal_def[symmetric] by auto lemma Inf_eq_PInfty: fixes S :: "ereal set" shows "Inf S = \<infinity> \<longleftrightarrow> S = {} \<or> S = {\<infinity>}" using Sup_eq_MInfty[of "uminus`S"] unfolding ereal_Sup_uminus_image_eq ereal_image_uminus_shift by simp lemma Inf_eq_MInfty: fixes S :: "ereal set" shows "-\<infinity> \<in> S \<Longrightarrow> Inf S = -\<infinity>" unfolding bot_ereal_def[symmetric] by auto lemma Sup_eq_PInfty: fixes S :: "ereal set" shows "\<infinity> \<in> S \<Longrightarrow> Sup S = \<infinity>" unfolding top_ereal_def[symmetric] by auto lemma Sup_ereal_close: fixes e :: ereal assumes "0 < e" and S: "\<bar>Sup S\<bar> \<noteq> \<infinity>" "S \<noteq> {}" shows "\<exists>x\<in>S. Sup S - e < x" using assms by (cases e) (auto intro!: less_Sup_iff[THEN iffD1]) lemma Inf_ereal_close: fixes e :: ereal assumes "\<bar>Inf X\<bar> \<noteq> \<infinity>" and "0 < e" shows "\<exists>x\<in>X. x < Inf X + e" proof (rule Inf_less_iff[THEN iffD1]) show "Inf X < Inf X + e" using assms by (cases e) auto qed lemma SUP_nat_Infty: "(SUP i::nat. ereal (real i)) = \<infinity>" proof - { fix x :: ereal assume "x \<noteq> \<infinity>" then have "\<exists>k::nat. x < ereal (real k)" proof (cases x) case MInf then show ?thesis by (intro exI[of _ 0]) auto next case (real r) moreover obtain k :: nat where "r < real k" using ex_less_of_nat by (auto simp: real_eq_of_nat) ultimately show ?thesis by auto qed simp } then show ?thesis using SUP_eq_top_iff[of UNIV "\<lambda>n::nat. ereal (real n)"] by (auto simp: top_ereal_def) qed lemma Inf_less: fixes x :: ereal assumes "(INF i:A. f i) < x" shows "\<exists>i. i \<in> A \<and> f i \<le> x" proof (rule ccontr) assume "\<not> ?thesis" then have "\<forall>i\<in>A. f i > x" by auto then have "(INF i:A. f i) \<ge> x" by (subst INF_greatest) auto then show False using assms by auto qed lemma SUP_ereal_le_addI: fixes f :: "'i \<Rightarrow> ereal" assumes "\<And>i. f i + y \<le> z" and "y \<noteq> -\<infinity>" shows "SUPREMUM UNIV f + y \<le> z" proof (cases y) case (real r) then have "\<And>i. f i \<le> z - y" using assms by (simp add: ereal_le_minus_iff) then have "SUPREMUM UNIV f \<le> z - y" by (rule SUP_least) then show ?thesis using real by (simp add: ereal_le_minus_iff) qed (insert assms, auto) lemma SUP_ereal_add: fixes f g :: "nat \<Rightarrow> ereal" assumes "incseq f" and "incseq g" and pos: "\<And>i. f i \<noteq> -\<infinity>" "\<And>i. g i \<noteq> -\<infinity>" shows "(SUP i. f i + g i) = SUPREMUM UNIV f + SUPREMUM UNIV g" proof (rule SUP_eqI) fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> f i + g i \<le> y" have f: "SUPREMUM UNIV f \<noteq> -\<infinity>" using pos unfolding SUP_def Sup_eq_MInfty by (auto dest: image_eqD) { fix j { fix i have "f i + g j \<le> f i + g (max i j)" using `incseq g`[THEN incseqD] by (rule add_left_mono) auto also have "\<dots> \<le> f (max i j) + g (max i j)" using `incseq f`[THEN incseqD] by (rule add_right_mono) auto also have "\<dots> \<le> y" using * by auto finally have "f i + g j \<le> y" . } then have "SUPREMUM UNIV f + g j \<le> y" using assms(4)[of j] by (intro SUP_ereal_le_addI) auto then have "g j + SUPREMUM UNIV f \<le> y" by (simp add: ac_simps) } then have "SUPREMUM UNIV g + SUPREMUM UNIV f \<le> y" using f by (rule SUP_ereal_le_addI) then show "SUPREMUM UNIV f + SUPREMUM UNIV g \<le> y" by (simp add: ac_simps) qed (auto intro!: add_mono SUP_upper) lemma SUP_ereal_add_pos: fixes f g :: "nat \<Rightarrow> ereal" assumes inc: "incseq f" "incseq g" and pos: "\<And>i. 0 \<le> f i" "\<And>i. 0 \<le> g i" shows "(SUP i. f i + g i) = SUPREMUM UNIV f + SUPREMUM UNIV g" proof (intro SUP_ereal_add inc) fix i show "f i \<noteq> -\<infinity>" "g i \<noteq> -\<infinity>" using pos[of i] by auto qed lemma SUP_ereal_setsum: fixes f g :: "'a \<Rightarrow> nat \<Rightarrow> ereal" assumes "\<And>n. n \<in> A \<Longrightarrow> incseq (f n)" and pos: "\<And>n i. n \<in> A \<Longrightarrow> 0 \<le> f n i" shows "(SUP i. \<Sum>n\<in>A. f n i) = (\<Sum>n\<in>A. SUPREMUM UNIV (f n))" proof (cases "finite A") case True then show ?thesis using assms by induct (auto simp: incseq_setsumI2 setsum_nonneg SUP_ereal_add_pos) next case False then show ?thesis by simp qed lemma SUP_ereal_cmult: fixes f :: "nat \<Rightarrow> ereal" assumes "\<And>i. 0 \<le> f i" and "0 \<le> c" shows "(SUP i. c * f i) = c * SUPREMUM UNIV f" proof (rule SUP_eqI) fix i have "f i \<le> SUPREMUM UNIV f" by (rule SUP_upper) auto then show "c * f i \<le> c * SUPREMUM UNIV f" using `0 \<le> c` by (rule ereal_mult_left_mono) next fix y assume "\<And>i. i \<in> UNIV \<Longrightarrow> c * f i \<le> y" then have *: "\<And>i. c * f i \<le> y" by simp show "c * SUPREMUM UNIV f \<le> y" proof (cases "0 < c \<and> c \<noteq> \<infinity>") case True with * have "SUPREMUM UNIV f \<le> y / c" by (intro SUP_least) (auto simp: ereal_le_divide_pos) with True show ?thesis by (auto simp: ereal_le_divide_pos) next case False { assume "c = \<infinity>" have ?thesis proof (cases "\<forall>i. f i = 0") case True then have "range f = {0}" by auto with True show "c * SUPREMUM UNIV f \<le> y" using * by auto next case False then obtain i where "f i \<noteq> 0" by auto with *[of i] `c = \<infinity>` `0 \<le> f i` show ?thesis by (auto split: split_if_asm) qed } moreover note False ultimately show ?thesis using * `0 \<le> c` by auto qed qed lemma SUP_ereal_mult_right: fixes f :: "'a \<Rightarrow> ereal" assumes "I \<noteq> {}" assumes "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i" and "0 \<le> c" shows "(SUP i:I. c * f i) = c * (SUP i:I. f i)" proof (rule SUP_eqI) fix i assume "i \<in> I" then have "f i \<le> SUPREMUM I f" by (rule SUP_upper) then show "c * f i \<le> c * SUPREMUM I f" using `0 \<le> c` by (rule ereal_mult_left_mono) next fix y assume *: "\<And>i. i \<in> I \<Longrightarrow> c * f i \<le> y" { assume "c = \<infinity>" have "c * SUPREMUM I f \<le> y" proof cases assume "\<forall>i\<in>I. f i = 0" then show ?thesis using * `c = \<infinity>` by (auto simp: SUP_constant bot_ereal_def) next assume "\<not> (\<forall>i\<in>I. f i = 0)" then obtain i where "f i \<noteq> 0" "i \<in> I" by auto with *[of i] `c = \<infinity>` `i \<in> I \<Longrightarrow> 0 \<le> f i` show ?thesis by (auto split: split_if_asm) qed } moreover { assume "c \<noteq> 0" "c \<noteq> \<infinity>" moreover with `0 \<le> c` * have "SUPREMUM I f \<le> y / c" by (intro SUP_least) (auto simp: ereal_le_divide_pos) ultimately have "c * SUPREMUM I f \<le> y" using `0 \<le> c` * by (auto simp: ereal_le_divide_pos) } moreover { assume "c = 0" with * `I \<noteq> {}` have "c * SUPREMUM I f \<le> y" by auto } ultimately show "c * SUPREMUM I f \<le> y" by blast qed lemma SUP_ereal_add_left: fixes f :: "'a \<Rightarrow> ereal" assumes "I \<noteq> {}" assumes "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i" and "0 \<le> c" shows "(SUP i:I. f i + c) = SUPREMUM I f + c" proof (intro SUP_eqI) fix B assume *: "\<And>i. i \<in> I \<Longrightarrow> f i + c \<le> B" show "SUPREMUM I f + c \<le> B" proof cases assume "c = \<infinity>" with `I \<noteq> {}` * show ?thesis by auto next assume "c \<noteq> \<infinity>" with `0 \<le> c` have [simp]: "\<bar>c\<bar> \<noteq> \<infinity>" by simp have "SUPREMUM I f \<le> B - c" by (simp add: SUP_le_iff ereal_le_minus *) then show ?thesis by (simp add: ereal_le_minus) qed qed (auto intro: ereal_add_mono SUP_upper) lemma SUP_ereal_add_right: fixes c :: ereal shows "I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> 0 \<le> c \<Longrightarrow> (SUP i:I. c + f i) = c + SUPREMUM I f" using SUP_ereal_add_left[of I f c] by (simp add: add_ac) lemma SUP_PInfty: fixes f :: "'a \<Rightarrow> ereal" assumes "\<And>n::nat. \<exists>i\<in>A. ereal (real n) \<le> f i" shows "(SUP i:A. f i) = \<infinity>" unfolding SUP_def Sup_eq_top_iff[where 'a=ereal, unfolded top_ereal_def] apply simp proof safe fix x :: ereal assume "x \<noteq> \<infinity>" show "\<exists>i\<in>A. x < f i" proof (cases x) case PInf with `x \<noteq> \<infinity>` show ?thesis by simp next case MInf with assms[of "0"] show ?thesis by force next case (real r) with less_PInf_Ex_of_nat[of x] obtain n :: nat where "x < ereal (real n)" by auto moreover obtain i where "i \<in> A" "ereal (real n) \<le> f i" using assms .. ultimately show ?thesis by (auto intro!: bexI[of _ i]) qed qed lemma Sup_countable_SUP: assumes "A \<noteq> {}" shows "\<exists>f::nat \<Rightarrow> ereal. range f \<subseteq> A \<and> Sup A = SUPREMUM UNIV f" proof (cases "Sup A") case (real r) have "\<forall>n::nat. \<exists>x. x \<in> A \<and> Sup A < x + 1 / ereal (real n)" proof fix n :: nat have "\<exists>x\<in>A. Sup A - 1 / ereal (real n) < x" using assms real by (intro Sup_ereal_close) (auto simp: one_ereal_def) then obtain x where "x \<in> A" "Sup A - 1 / ereal (real n) < x" .. then show "\<exists>x. x \<in> A \<and> Sup A < x + 1 / ereal (real n)" by (auto intro!: exI[of _ x] simp: ereal_minus_less_iff) qed from choice[OF this] obtain f :: "nat \<Rightarrow> ereal" where f: "\<forall>x. f x \<in> A \<and> Sup A < f x + 1 / ereal (real x)" .. have "SUPREMUM UNIV f = Sup A" proof (rule SUP_eqI) fix i show "f i \<le> Sup A" using f by (auto intro!: complete_lattice_class.Sup_upper) next fix y assume bound: "\<And>i. i \<in> UNIV \<Longrightarrow> f i \<le> y" show "Sup A \<le> y" proof (rule ereal_le_epsilon, intro allI impI) fix e :: ereal assume "0 < e" show "Sup A \<le> y + e" proof (cases e) case (real r) then have "0 < r" using `0 < e` by auto then obtain n :: nat where *: "1 / real n < r" "0 < n" using ex_inverse_of_nat_less by (auto simp: real_eq_of_nat inverse_eq_divide) have "Sup A \<le> f n + 1 / ereal (real n)" using f[THEN spec, of n] by auto also have "1 / ereal (real n) \<le> e" using real * by (auto simp: one_ereal_def ) with bound have "f n + 1 / ereal (real n) \<le> y + e" by (rule add_mono) simp finally show "Sup A \<le> y + e" . qed (insert `0 < e`, auto) qed qed with f show ?thesis by (auto intro!: exI[of _ f]) next case PInf from `A \<noteq> {}` obtain x where "x \<in> A" by auto show ?thesis proof (cases "\<infinity> \<in> A") case True then have "\<infinity> \<le> Sup A" by (intro complete_lattice_class.Sup_upper) with True show ?thesis by (auto intro!: exI[of _ "\<lambda>x. \<infinity>"]) next case False have "\<exists>x\<in>A. 0 \<le> x" by (metis Infty_neq_0(2) PInf complete_lattice_class.Sup_least ereal_infty_less_eq2(1) linorder_linear) then obtain x where "x \<in> A" and "0 \<le> x" by auto have "\<forall>n::nat. \<exists>f. f \<in> A \<and> x + ereal (real n) \<le> f" proof (rule ccontr) assume "\<not> ?thesis" then have "\<exists>n::nat. Sup A \<le> x + ereal (real n)" by (simp add: Sup_le_iff not_le less_imp_le Ball_def) (metis less_imp_le) then show False using `x \<in> A` `\<infinity> \<notin> A` PInf by (cases x) auto qed from choice[OF this] obtain f :: "nat \<Rightarrow> ereal" where f: "\<forall>z. f z \<in> A \<and> x + ereal (real z) \<le> f z" .. have "SUPREMUM UNIV f = \<infinity>" proof (rule SUP_PInfty) fix n :: nat show "\<exists>i\<in>UNIV. ereal (real n) \<le> f i" using f[THEN spec, of n] `0 \<le> x` by (cases rule: ereal2_cases[of "f n" x]) (auto intro!: exI[of _ n]) qed then show ?thesis using f PInf by (auto intro!: exI[of _ f]) qed next case MInf with `A \<noteq> {}` have "A = {-\<infinity>}" by (auto simp: Sup_eq_MInfty) then show ?thesis using MInf by (auto intro!: exI[of _ "\<lambda>x. -\<infinity>"]) qed lemma SUP_countable_SUP: "A \<noteq> {} \<Longrightarrow> \<exists>f::nat \<Rightarrow> ereal. range f \<subseteq> g`A \<and> SUPREMUM A g = SUPREMUM UNIV f" using Sup_countable_SUP [of "g`A"] by auto lemma Sup_ereal_cadd: fixes A :: "ereal set" assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>" shows "Sup ((\<lambda>x. a + x) ` A) = a + Sup A" proof (rule antisym) have *: "\<And>a::ereal. \<And>A. Sup ((\<lambda>x. a + x) ` A) \<le> a + Sup A" by (auto intro!: add_mono complete_lattice_class.SUP_least complete_lattice_class.Sup_upper) then show "Sup ((\<lambda>x. a + x) ` A) \<le> a + Sup A" . show "a + Sup A \<le> Sup ((\<lambda>x. a + x) ` A)" proof (cases a) case PInf with `A \<noteq> {}` show ?thesis by (auto simp: image_constant max.absorb1) next case (real r) then have **: "op + (- a) ` op + a ` A = A" by (auto simp: image_iff ac_simps zero_ereal_def[symmetric]) from *[of "-a" "(\<lambda>x. a + x) ` A"] real show ?thesis unfolding ** by (cases rule: ereal2_cases[of "Sup A" "Sup (op + a ` A)"]) auto qed (insert `a \<noteq> -\<infinity>`, auto) qed lemma Sup_ereal_cminus: fixes A :: "ereal set" assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>" shows "Sup ((\<lambda>x. a - x) ` A) = a - Inf A" using Sup_ereal_cadd [of "uminus ` A" a] assms unfolding image_image minus_ereal_def by (simp add: ereal_SUP_uminus_eq) lemma SUP_ereal_cminus: fixes f :: "'i \<Rightarrow> ereal" fixes A assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>" shows "(SUP x:A. a - f x) = a - (INF x:A. f x)" using Sup_ereal_cminus[of "f`A" a] assms unfolding SUP_def INF_def image_image by auto lemma Inf_ereal_cminus: fixes A :: "ereal set" assumes "A \<noteq> {}" and "\<bar>a\<bar> \<noteq> \<infinity>" shows "Inf ((\<lambda>x. a - x) ` A) = a - Sup A" proof - { fix x have "-a - -x = -(a - x)" using assms by (cases x) auto } note * = this then have "(\<lambda>x. -a - x)`uminus`A = uminus ` (\<lambda>x. a - x) ` A" by (auto simp: image_image) with * show ?thesis using Sup_ereal_cminus [of "uminus ` A" "- a"] assms by (auto simp add: ereal_INF_uminus_eq ereal_SUP_uminus_eq) qed lemma INF_ereal_cminus: fixes a :: ereal assumes "A \<noteq> {}" and "\<bar>a\<bar> \<noteq> \<infinity>" shows "(INF x:A. a - f x) = a - (SUP x:A. f x)" using Inf_ereal_cminus[of "f`A" a] assms unfolding SUP_def INF_def image_image by auto lemma uminus_ereal_add_uminus_uminus: fixes a b :: ereal shows "a \<noteq> \<infinity> \<Longrightarrow> b \<noteq> \<infinity> \<Longrightarrow> - (- a + - b) = a + b" by (cases rule: ereal2_cases[of a b]) auto lemma INF_ereal_add: fixes f :: "nat \<Rightarrow> ereal" assumes "decseq f" "decseq g" and fin: "\<And>i. f i \<noteq> \<infinity>" "\<And>i. g i \<noteq> \<infinity>" shows "(INF i. f i + g i) = INFIMUM UNIV f + INFIMUM UNIV g" proof - have INF_less: "(INF i. f i) < \<infinity>" "(INF i. g i) < \<infinity>" using assms unfolding INF_less_iff by auto { fix i from fin[of i] have "- ((- f i) + (- g i)) = f i + g i" by (rule uminus_ereal_add_uminus_uminus) } then have "(INF i. f i + g i) = (INF i. - ((- f i) + (- g i)))" by simp also have "\<dots> = INFIMUM UNIV f + INFIMUM UNIV g" unfolding ereal_INF_uminus using assms INF_less by (subst SUP_ereal_add) (auto simp: ereal_SUP_uminus intro!: uminus_ereal_add_uminus_uminus) finally show ?thesis . qed subsection "Relation to @{typ enat}" definition "ereal_of_enat n = (case n of enat n \<Rightarrow> ereal (real n) | \<infinity> \<Rightarrow> \<infinity>)" declare [[coercion "ereal_of_enat :: enat \<Rightarrow> ereal"]] declare [[coercion "(\<lambda>n. ereal (real n)) :: nat \<Rightarrow> ereal"]] lemma ereal_of_enat_simps[simp]: "ereal_of_enat (enat n) = ereal n" "ereal_of_enat \<infinity> = \<infinity>" by (simp_all add: ereal_of_enat_def) lemma ereal_of_enat_le_iff[simp]: "ereal_of_enat m \<le> ereal_of_enat n \<longleftrightarrow> m \<le> n" by (cases m n rule: enat2_cases) auto lemma ereal_of_enat_less_iff[simp]: "ereal_of_enat m < ereal_of_enat n \<longleftrightarrow> m < n" by (cases m n rule: enat2_cases) auto lemma numeral_le_ereal_of_enat_iff[simp]: "numeral m \<le> ereal_of_enat n \<longleftrightarrow> numeral m \<le> n" by (cases n) (auto dest: natceiling_le intro: natceiling_le_eq[THEN iffD1]) lemma numeral_less_ereal_of_enat_iff[simp]: "numeral m < ereal_of_enat n \<longleftrightarrow> numeral m < n" by (cases n) auto lemma ereal_of_enat_ge_zero_cancel_iff[simp]: "0 \<le> ereal_of_enat n \<longleftrightarrow> 0 \<le> n" by (cases n) (auto simp: enat_0[symmetric]) lemma ereal_of_enat_gt_zero_cancel_iff[simp]: "0 < ereal_of_enat n \<longleftrightarrow> 0 < n" by (cases n) (auto simp: enat_0[symmetric]) lemma ereal_of_enat_zero[simp]: "ereal_of_enat 0 = 0" by (auto simp: enat_0[symmetric]) lemma ereal_of_enat_inf[simp]: "ereal_of_enat n = \<infinity> \<longleftrightarrow> n = \<infinity>" by (cases n) auto lemma ereal_of_enat_add: "ereal_of_enat (m + n) = ereal_of_enat m + ereal_of_enat n" by (cases m n rule: enat2_cases) auto lemma ereal_of_enat_sub: assumes "n \<le> m" shows "ereal_of_enat (m - n) = ereal_of_enat m - ereal_of_enat n " using assms by (cases m n rule: enat2_cases) auto lemma ereal_of_enat_mult: "ereal_of_enat (m * n) = ereal_of_enat m * ereal_of_enat n" by (cases m n rule: enat2_cases) auto lemmas ereal_of_enat_pushin = ereal_of_enat_add ereal_of_enat_sub ereal_of_enat_mult lemmas ereal_of_enat_pushout = ereal_of_enat_pushin[symmetric] subsection "Limits on @{typ ereal}" subsubsection "Topological space" instantiation ereal :: linear_continuum_topology begin definition "open_ereal" :: "ereal set \<Rightarrow> bool" where open_ereal_generated: "open_ereal = generate_topology (range lessThan \<union> range greaterThan)" instance by default (simp add: open_ereal_generated) end lemma open_PInfty: "open A \<Longrightarrow> \<infinity> \<in> A \<Longrightarrow> (\<exists>x. {ereal x<..} \<subseteq> A)" unfolding open_ereal_generated proof (induct rule: generate_topology.induct) case (Int A B) then obtain x z where "\<infinity> \<in> A \<Longrightarrow> {ereal x <..} \<subseteq> A" "\<infinity> \<in> B \<Longrightarrow> {ereal z <..} \<subseteq> B" by auto with Int show ?case by (intro exI[of _ "max x z"]) fastforce next case (Basis S) { fix x have "x \<noteq> \<infinity> \<Longrightarrow> \<exists>t. x \<le> ereal t" by (cases x) auto } moreover note Basis ultimately show ?case by (auto split: ereal.split) qed (fastforce simp add: vimage_Union)+ lemma open_MInfty: "open A \<Longrightarrow> -\<infinity> \<in> A \<Longrightarrow> (\<exists>x. {..<ereal x} \<subseteq> A)" unfolding open_ereal_generated proof (induct rule: generate_topology.induct) case (Int A B) then obtain x z where "-\<infinity> \<in> A \<Longrightarrow> {..< ereal x} \<subseteq> A" "-\<infinity> \<in> B \<Longrightarrow> {..< ereal z} \<subseteq> B" by auto with Int show ?case by (intro exI[of _ "min x z"]) fastforce next case (Basis S) { fix x have "x \<noteq> - \<infinity> \<Longrightarrow> \<exists>t. ereal t \<le> x" by (cases x) auto } moreover note Basis ultimately show ?case by (auto split: ereal.split) qed (fastforce simp add: vimage_Union)+ lemma open_ereal_vimage: "open S \<Longrightarrow> open (ereal -` S)" unfolding open_ereal_generated proof (induct rule: generate_topology.induct) case (Int A B) then show ?case by auto next case (Basis S) { fix x have "ereal -` {..<x} = (case x of PInfty \<Rightarrow> UNIV | MInfty \<Rightarrow> {} | ereal r \<Rightarrow> {..<r})" "ereal -` {x<..} = (case x of PInfty \<Rightarrow> {} | MInfty \<Rightarrow> UNIV | ereal r \<Rightarrow> {r<..})" by (induct x) auto } moreover note Basis ultimately show ?case by (auto split: ereal.split) qed (fastforce simp add: vimage_Union)+ lemma open_ereal: "open S \<Longrightarrow> open (ereal ` S)" unfolding open_generated_order[where 'a=real] proof (induct rule: generate_topology.induct) case (Basis S) moreover { fix x have "ereal ` {..< x} = { -\<infinity> <..< ereal x }" apply auto apply (case_tac xa) apply auto done } moreover { fix x have "ereal ` {x <..} = { ereal x <..< \<infinity> }" apply auto apply (case_tac xa) apply auto done } ultimately show ?case by auto qed (auto simp add: image_Union image_Int) lemma eventually_finite: fixes x :: ereal assumes "\<bar>x\<bar> \<noteq> \<infinity>" "(f ---> x) F" shows "eventually (\<lambda>x. \<bar>f x\<bar> \<noteq> \<infinity>) F" proof - have "(f ---> ereal (real x)) F" using assms by (cases x) auto then have "eventually (\<lambda>x. f x \<in> ereal ` UNIV) F" by (rule topological_tendstoD) (auto intro: open_ereal) also have "(\<lambda>x. f x \<in> ereal ` UNIV) = (\<lambda>x. \<bar>f x\<bar> \<noteq> \<infinity>)" by auto finally show ?thesis . qed lemma open_ereal_def: "open A \<longleftrightarrow> open (ereal -` A) \<and> (\<infinity> \<in> A \<longrightarrow> (\<exists>x. {ereal x <..} \<subseteq> A)) \<and> (-\<infinity> \<in> A \<longrightarrow> (\<exists>x. {..<ereal x} \<subseteq> A))" (is "open A \<longleftrightarrow> ?rhs") proof assume "open A" then show ?rhs using open_PInfty open_MInfty open_ereal_vimage by auto next assume "?rhs" then obtain x y where A: "open (ereal -` A)" "\<infinity> \<in> A \<Longrightarrow> {ereal x<..} \<subseteq> A" "-\<infinity> \<in> A \<Longrightarrow> {..< ereal y} \<subseteq> A" by auto have *: "A = ereal ` (ereal -` A) \<union> (if \<infinity> \<in> A then {ereal x<..} else {}) \<union> (if -\<infinity> \<in> A then {..< ereal y} else {})" using A(2,3) by auto from open_ereal[OF A(1)] show "open A" by (subst *) (auto simp: open_Un) qed lemma open_PInfty2: assumes "open A" and "\<infinity> \<in> A" obtains x where "{ereal x<..} \<subseteq> A" using open_PInfty[OF assms] by auto lemma open_MInfty2: assumes "open A" and "-\<infinity> \<in> A" obtains x where "{..<ereal x} \<subseteq> A" using open_MInfty[OF assms] by auto lemma ereal_openE: assumes "open A" obtains x y where "open (ereal -` A)" and "\<infinity> \<in> A \<Longrightarrow> {ereal x<..} \<subseteq> A" and "-\<infinity> \<in> A \<Longrightarrow> {..<ereal y} \<subseteq> A" using assms open_ereal_def by auto lemmas open_ereal_lessThan = open_lessThan[where 'a=ereal] lemmas open_ereal_greaterThan = open_greaterThan[where 'a=ereal] lemmas ereal_open_greaterThanLessThan = open_greaterThanLessThan[where 'a=ereal] lemmas closed_ereal_atLeast = closed_atLeast[where 'a=ereal] lemmas closed_ereal_atMost = closed_atMost[where 'a=ereal] lemmas closed_ereal_atLeastAtMost = closed_atLeastAtMost[where 'a=ereal] lemmas closed_ereal_singleton = closed_singleton[where 'a=ereal] lemma ereal_open_cont_interval: fixes S :: "ereal set" assumes "open S" and "x \<in> S" and "\<bar>x\<bar> \<noteq> \<infinity>" obtains e where "e > 0" and "{x-e <..< x+e} \<subseteq> S" proof - from `open S` have "open (ereal -` S)" by (rule ereal_openE) then obtain e where "e > 0" and e: "\<And>y. dist y (real x) < e \<Longrightarrow> ereal y \<in> S" using assms unfolding open_dist by force show thesis proof (intro that subsetI) show "0 < ereal e" using `0 < e` by auto fix y assume "y \<in> {x - ereal e<..<x + ereal e}" with assms obtain t where "y = ereal t" "dist t (real x) < e" by (cases y) (auto simp: dist_real_def) then show "y \<in> S" using e[of t] by auto qed qed lemma ereal_open_cont_interval2: fixes S :: "ereal set" assumes "open S" and "x \<in> S" and x: "\<bar>x\<bar> \<noteq> \<infinity>" obtains a b where "a < x" and "x < b" and "{a <..< b} \<subseteq> S" proof - obtain e where "0 < e" "{x - e<..<x + e} \<subseteq> S" using assms by (rule ereal_open_cont_interval) with that[of "x - e" "x + e"] ereal_between[OF x, of e] show thesis by auto qed subsubsection {* Convergent sequences *} lemma lim_ereal[simp]: "((\<lambda>n. ereal (f n)) ---> ereal x) net \<longleftrightarrow> (f ---> x) net" (is "?l = ?r") proof (intro iffI topological_tendstoI) fix S assume "?l" and "open S" and "x \<in> S" then show "eventually (\<lambda>x. f x \<in> S) net" using `?l`[THEN topological_tendstoD, OF open_ereal, OF `open S`] by (simp add: inj_image_mem_iff) next fix S assume "?r" and "open S" and "ereal x \<in> S" show "eventually (\<lambda>x. ereal (f x) \<in> S) net" using `?r`[THEN topological_tendstoD, OF open_ereal_vimage, OF `open S`] using `ereal x \<in> S` by auto qed lemma lim_real_of_ereal[simp]: assumes lim: "(f ---> ereal x) net" shows "((\<lambda>x. real (f x)) ---> x) net" proof (intro topological_tendstoI) fix S assume "open S" and "x \<in> S" then have S: "open S" "ereal x \<in> ereal ` S" by (simp_all add: inj_image_mem_iff) have "\<forall>x. f x \<in> ereal ` S \<longrightarrow> real (f x) \<in> S" by auto from this lim[THEN topological_tendstoD, OF open_ereal, OF S] show "eventually (\<lambda>x. real (f x) \<in> S) net" by (rule eventually_mono) qed lemma tendsto_PInfty: "(f ---> \<infinity>) F \<longleftrightarrow> (\<forall>r. eventually (\<lambda>x. ereal r < f x) F)" proof - { fix l :: ereal assume "\<forall>r. eventually (\<lambda>x. ereal r < f x) F" from this[THEN spec, of "real l"] have "l \<noteq> \<infinity> \<Longrightarrow> eventually (\<lambda>x. l < f x) F" by (cases l) (auto elim: eventually_elim1) } then show ?thesis by (auto simp: order_tendsto_iff) qed lemma tendsto_PInfty_eq_at_top: "((\<lambda>z. ereal (f z)) ---> \<infinity>) F \<longleftrightarrow> (LIM z F. f z :> at_top)" unfolding tendsto_PInfty filterlim_at_top_dense by simp lemma tendsto_MInfty: "(f ---> -\<infinity>) F \<longleftrightarrow> (\<forall>r. eventually (\<lambda>x. f x < ereal r) F)" unfolding tendsto_def proof safe fix S :: "ereal set" assume "open S" "-\<infinity> \<in> S" from open_MInfty[OF this] obtain B where "{..<ereal B} \<subseteq> S" .. moreover assume "\<forall>r::real. eventually (\<lambda>z. f z < r) F" then have "eventually (\<lambda>z. f z \<in> {..< B}) F" by auto ultimately show "eventually (\<lambda>z. f z \<in> S) F" by (auto elim!: eventually_elim1) next fix x assume "\<forall>S. open S \<longrightarrow> -\<infinity> \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F" from this[rule_format, of "{..< ereal x}"] show "eventually (\<lambda>y. f y < ereal x) F" by auto qed lemma Lim_PInfty: "f ----> \<infinity> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. f n \<ge> ereal B)" unfolding tendsto_PInfty eventually_sequentially proof safe fix r assume "\<forall>r. \<exists>N. \<forall>n\<ge>N. ereal r \<le> f n" then obtain N where "\<forall>n\<ge>N. ereal (r + 1) \<le> f n" by blast moreover have "ereal r < ereal (r + 1)" by auto ultimately show "\<exists>N. \<forall>n\<ge>N. ereal r < f n" by (blast intro: less_le_trans) qed (blast intro: less_imp_le) lemma Lim_MInfty: "f ----> -\<infinity> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. ereal B \<ge> f n)" unfolding tendsto_MInfty eventually_sequentially proof safe fix r assume "\<forall>r. \<exists>N. \<forall>n\<ge>N. f n \<le> ereal r" then obtain N where "\<forall>n\<ge>N. f n \<le> ereal (r - 1)" by blast moreover have "ereal (r - 1) < ereal r" by auto ultimately show "\<exists>N. \<forall>n\<ge>N. f n < ereal r" by (blast intro: le_less_trans) qed (blast intro: less_imp_le) lemma Lim_bounded_PInfty: "f ----> l \<Longrightarrow> (\<And>n. f n \<le> ereal B) \<Longrightarrow> l \<noteq> \<infinity>" using LIMSEQ_le_const2[of f l "ereal B"] by auto lemma Lim_bounded_MInfty: "f ----> l \<Longrightarrow> (\<And>n. ereal B \<le> f n) \<Longrightarrow> l \<noteq> -\<infinity>" using LIMSEQ_le_const[of f l "ereal B"] by auto lemma tendsto_explicit: "f ----> f0 \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> f0 \<in> S \<longrightarrow> (\<exists>N. \<forall>n\<ge>N. f n \<in> S))" unfolding tendsto_def eventually_sequentially by auto lemma Lim_bounded_PInfty2: "f ----> l \<Longrightarrow> \<forall>n\<ge>N. f n \<le> ereal B \<Longrightarrow> l \<noteq> \<infinity>" using LIMSEQ_le_const2[of f l "ereal B"] by fastforce lemma Lim_bounded_ereal: "f ----> (l :: 'a::linorder_topology) \<Longrightarrow> \<forall>n\<ge>M. f n \<le> C \<Longrightarrow> l \<le> C" by (intro LIMSEQ_le_const2) auto lemma Lim_bounded2_ereal: assumes lim:"f ----> (l :: 'a::linorder_topology)" and ge: "\<forall>n\<ge>N. f n \<ge> C" shows "l \<ge> C" using ge by (intro tendsto_le[OF trivial_limit_sequentially lim tendsto_const]) (auto simp: eventually_sequentially) lemma real_of_ereal_mult[simp]: fixes a b :: ereal shows "real (a * b) = real a * real b" by (cases rule: ereal2_cases[of a b]) auto lemma real_of_ereal_eq_0: fixes x :: ereal shows "real x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity> \<or> x = 0" by (cases x) auto lemma tendsto_ereal_realD: fixes f :: "'a \<Rightarrow> ereal" assumes "x \<noteq> 0" and tendsto: "((\<lambda>x. ereal (real (f x))) ---> x) net" shows "(f ---> x) net" proof (intro topological_tendstoI) fix S assume S: "open S" "x \<in> S" with `x \<noteq> 0` have "open (S - {0})" "x \<in> S - {0}" by auto from tendsto[THEN topological_tendstoD, OF this] show "eventually (\<lambda>x. f x \<in> S) net" by (rule eventually_rev_mp) (auto simp: ereal_real) qed lemma tendsto_ereal_realI: fixes f :: "'a \<Rightarrow> ereal" assumes x: "\<bar>x\<bar> \<noteq> \<infinity>" and tendsto: "(f ---> x) net" shows "((\<lambda>x. ereal (real (f x))) ---> x) net" proof (intro topological_tendstoI) fix S assume "open S" and "x \<in> S" with x have "open (S - {\<infinity>, -\<infinity>})" "x \<in> S - {\<infinity>, -\<infinity>}" by auto from tendsto[THEN topological_tendstoD, OF this] show "eventually (\<lambda>x. ereal (real (f x)) \<in> S) net" by (elim eventually_elim1) (auto simp: ereal_real) qed lemma ereal_mult_cancel_left: fixes a b c :: ereal shows "a * b = a * c \<longleftrightarrow> (\<bar>a\<bar> = \<infinity> \<and> 0 < b * c) \<or> a = 0 \<or> b = c" by (cases rule: ereal3_cases[of a b c]) (simp_all add: zero_less_mult_iff) lemma tendsto_add_ereal: fixes x y :: ereal assumes x: "\<bar>x\<bar> \<noteq> \<infinity>" and y: "\<bar>y\<bar> \<noteq> \<infinity>" assumes f: "(f ---> x) F" and g: "(g ---> y) F" shows "((\<lambda>x. f x + g x) ---> x + y) F" proof - from x obtain r where x': "x = ereal r" by (cases x) auto with f have "((\<lambda>i. real (f i)) ---> r) F" by simp moreover from y obtain p where y': "y = ereal p" by (cases y) auto with g have "((\<lambda>i. real (g i)) ---> p) F" by simp ultimately have "((\<lambda>i. real (f i) + real (g i)) ---> r + p) F" by (rule tendsto_add) moreover from eventually_finite[OF x f] eventually_finite[OF y g] have "eventually (\<lambda>x. f x + g x = ereal (real (f x) + real (g x))) F" by eventually_elim auto ultimately show ?thesis by (simp add: x' y' cong: filterlim_cong) qed lemma ereal_inj_affinity: fixes m t :: ereal assumes "\<bar>m\<bar> \<noteq> \<infinity>" and "m \<noteq> 0" and "\<bar>t\<bar> \<noteq> \<infinity>" shows "inj_on (\<lambda>x. m * x + t) A" using assms by (cases rule: ereal2_cases[of m t]) (auto intro!: inj_onI simp: ereal_add_cancel_right ereal_mult_cancel_left) lemma ereal_PInfty_eq_plus[simp]: fixes a b :: ereal shows "\<infinity> = a + b \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_MInfty_eq_plus[simp]: fixes a b :: ereal shows "-\<infinity> = a + b \<longleftrightarrow> (a = -\<infinity> \<and> b \<noteq> \<infinity>) \<or> (b = -\<infinity> \<and> a \<noteq> \<infinity>)" by (cases rule: ereal2_cases[of a b]) auto lemma ereal_less_divide_pos: fixes x y :: ereal shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y < z / x \<longleftrightarrow> x * y < z" by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps) lemma ereal_divide_less_pos: fixes x y z :: ereal shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y / x < z \<longleftrightarrow> y < x * z" by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps) lemma ereal_divide_eq: fixes a b c :: ereal shows "b \<noteq> 0 \<Longrightarrow> \<bar>b\<bar> \<noteq> \<infinity> \<Longrightarrow> a / b = c \<longleftrightarrow> a = b * c" by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps) lemma ereal_inverse_not_MInfty[simp]: "inverse (a::ereal) \<noteq> -\<infinity>" by (cases a) auto lemma ereal_mult_m1[simp]: "x * ereal (-1) = -x" by (cases x) auto lemma ereal_real': assumes "\<bar>x\<bar> \<noteq> \<infinity>" shows "ereal (real x) = x" using assms by auto lemma real_ereal_id: "real \<circ> ereal = id" proof - { fix x have "(real o ereal) x = id x" by auto } then show ?thesis using ext by blast qed lemma open_image_ereal: "open(UNIV-{ \<infinity> , (-\<infinity> :: ereal)})" by (metis range_ereal open_ereal open_UNIV) lemma ereal_le_distrib: fixes a b c :: ereal shows "c * (a + b) \<le> c * a + c * b" by (cases rule: ereal3_cases[of a b c]) (auto simp add: field_simps not_le mult_le_0_iff mult_less_0_iff) lemma ereal_pos_distrib: fixes a b c :: ereal assumes "0 \<le> c" and "c \<noteq> \<infinity>" shows "c * (a + b) = c * a + c * b" using assms by (cases rule: ereal3_cases[of a b c]) (auto simp add: field_simps not_le mult_le_0_iff mult_less_0_iff) lemma ereal_pos_le_distrib: fixes a b c :: ereal assumes "c \<ge> 0" shows "c * (a + b) \<le> c * a + c * b" using assms by (cases rule: ereal3_cases[of a b c]) (auto simp add: field_simps) lemma ereal_max_mono: "(a::ereal) \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> max a c \<le> max b d" by (metis sup_ereal_def sup_mono) lemma ereal_max_least: "(a::ereal) \<le> x \<Longrightarrow> c \<le> x \<Longrightarrow> max a c \<le> x" by (metis sup_ereal_def sup_least) lemma ereal_LimI_finite: fixes x :: ereal assumes "\<bar>x\<bar> \<noteq> \<infinity>" and "\<And>r. 0 < r \<Longrightarrow> \<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r" shows "u ----> x" proof (rule topological_tendstoI, unfold eventually_sequentially) obtain rx where rx: "x = ereal rx" using assms by (cases x) auto fix S assume "open S" and "x \<in> S" then have "open (ereal -` S)" unfolding open_ereal_def by auto with `x \<in> S` obtain r where "0 < r" and dist: "\<And>y. dist y rx < r \<Longrightarrow> ereal y \<in> S" unfolding open_real_def rx by auto then obtain n where upper: "\<And>N. n \<le> N \<Longrightarrow> u N < x + ereal r" and lower: "\<And>N. n \<le> N \<Longrightarrow> x < u N + ereal r" using assms(2)[of "ereal r"] by auto show "\<exists>N. \<forall>n\<ge>N. u n \<in> S" proof (safe intro!: exI[of _ n]) fix N assume "n \<le> N" from upper[OF this] lower[OF this] assms `0 < r` have "u N \<notin> {\<infinity>,(-\<infinity>)}" by auto then obtain ra where ra_def: "(u N) = ereal ra" by (cases "u N") auto then have "rx < ra + r" and "ra < rx + r" using rx assms `0 < r` lower[OF `n \<le> N`] upper[OF `n \<le> N`] by auto then have "dist (real (u N)) rx < r" using rx ra_def by (auto simp: dist_real_def abs_diff_less_iff field_simps) from dist[OF this] show "u N \<in> S" using `u N \<notin> {\<infinity>, -\<infinity>}` by (auto simp: ereal_real split: split_if_asm) qed qed lemma tendsto_obtains_N: assumes "f ----> f0" assumes "open S" and "f0 \<in> S" obtains N where "\<forall>n\<ge>N. f n \<in> S" using assms using tendsto_def using tendsto_explicit[of f f0] assms by auto lemma ereal_LimI_finite_iff: fixes x :: ereal assumes "\<bar>x\<bar> \<noteq> \<infinity>" shows "u ----> x \<longleftrightarrow> (\<forall>r. 0 < r \<longrightarrow> (\<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r))" (is "?lhs \<longleftrightarrow> ?rhs") proof assume lim: "u ----> x" { fix r :: ereal assume "r > 0" then obtain N where "\<forall>n\<ge>N. u n \<in> {x - r <..< x + r}" apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"]) using lim ereal_between[of x r] assms `r > 0` apply auto done then have "\<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r" using ereal_minus_less[of r x] by (cases r) auto } then show ?rhs by auto next assume ?rhs then show "u ----> x" using ereal_LimI_finite[of x] assms by auto qed lemma ereal_Limsup_uminus: fixes f :: "'a \<Rightarrow> ereal" shows "Limsup net (\<lambda>x. - (f x)) = - Liminf net f" unfolding Limsup_def Liminf_def ereal_SUP_uminus ereal_INF_uminus .. lemma liminf_bounded_iff: fixes x :: "nat \<Rightarrow> ereal" shows "C \<le> liminf x \<longleftrightarrow> (\<forall>B<C. \<exists>N. \<forall>n\<ge>N. B < x n)" (is "?lhs \<longleftrightarrow> ?rhs") unfolding le_Liminf_iff eventually_sequentially .. subsubsection {* Tests for code generator *} (* A small list of simple arithmetic expressions *) value "- \<infinity> :: ereal" value "\<bar>-\<infinity>\<bar> :: ereal" value "4 + 5 / 4 - ereal 2 :: ereal" value "ereal 3 < \<infinity>" value "real (\<infinity>::ereal) = 0" end
{-# OPTIONS --safe --warning=error --without-K --guardedness #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Groups.Lemmas open import Groups.Definition open import Setoids.Orders.Total.Definition open import Setoids.Setoids open import Functions.Definition open import Sets.EquivalenceRelations open import Rings.Definition open import Rings.Orders.Total.Definition open import Rings.Orders.Partial.Definition open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Numbers.Modulo.Definition open import Semirings.Definition open import Orders.Total.Definition open import Sequences open import Numbers.Integers.Definition open import Numbers.Integers.Addition open import Numbers.Integers.Multiplication open import Numbers.Integers.Order open import Numbers.Rationals.Definition open import Vectors open import Fields.Fields module Rings.Orders.Total.Examples where open import Rings.Orders.Total.BaseExpansion (ℚOrdered) {10} (le 8 refl) open Field ℚField t : Vec ℚ 5 t = take 5 (partialSums (funcToSequence injectionNQ)) u : Vec ℚ 5 u = vecMap injectionNQ (0 ,- (1 ,- (3 ,- (6 ,- (10 ,- []))))) pr : Vec (ℚ && ℚ) 5 pr = vecZip t u ans : vecAllTrue (λ x → _&&_.fst x =Q _&&_.snd x) pr ans = refl ,, (refl ,, (refl ,, (refl ,, (refl ,, record {})))) open import Rings.InitialRing ℚRing a : Sequence ℚ a with allInvertible (fromN 10) (λ ()) ... | 1/10 , pr1/10 = approximations 1/10 pr1/10 (baseNExpansion (underlying (allInvertible (injectionNQ 7) λ ())) (lessInherits (succIsPositive 0)) (lessInherits (le 5 refl))) expected : Vec ℚ _ expected = record { num = nonneg 1 ; denom = nonneg 10 ; denomNonzero = f } ,- record { num = nonneg 14 ; denom = nonneg 100 ; denomNonzero = λ () } ,- record { num = nonneg 142 ; denom = nonneg 1000 ; denomNonzero = λ () } ,- [] where f : nonneg 10 ≡ nonneg 0 → False f () ans' : vecAllTrue (λ x → _&&_.fst x =Q _&&_.snd x) (vecZip (take _ a) expected) ans' = refl ,, (refl ,, (refl ,, record {}))
/* Copyright (C) 2014 InfiniDB, Inc. Copyright (C) 2016 MariaDB Corporation This program 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; version 2 of the License. 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 program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include <unistd.h> #include <cstdlib> #include <cstdio> #include <cstring> #include <ctime> #include <vector> #include <string> #include <sstream> #include <iostream> #include <exception> #include <stdexcept> #include <cerrno> using namespace std; #include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_io.hpp> #include <boost/filesystem.hpp> #include "dataconvert.h" #include "liboamcpp.h" using namespace oam; #include "we_cmdargs.h" #include "installdir.h" #include "mcsconfig.h" namespace WriteEngine { //---------------------------------------------------------------------- //---------------------------------------------------------------------- WECmdArgs::WECmdArgs(int argc, char** argv) : fMultiTableCount(0), fJobLogOnly(false), fHelp(false), fMode(1), fArgMode(-1), fQuiteMode(true), fConsoleLog(false), fVerbose(0), fBatchQty(10000), fNoOfReadThrds(0), fDebugLvl(0), fMaxErrors(-1), fReadBufSize(0), fIOReadBufSize(0), fSetBufSize(0), fColDelim('|'), fEnclosedChar(0), fEscChar(0), fNoOfWriteThrds(0), fNullStrMode(false), fImportDataMode(IMPORT_DATA_TEXT), fCpiInvoke(false), fBlockMode3(false), fbTruncationAsError(false), fUUID(boost::uuids::nil_generator()()), fConsoleOutput(true), fTimeZone("SYSTEM"), fErrorDir(string(MCSLOGDIR)+"/cpimport/") { try { appTestFunction(); parseCmdLineArgs(argc, argv); } catch (std::exception& exp) { std::string exceptMsg( exp.what() ); exceptMsg += "\nTry 'cpimport -h' for more information."; throw (runtime_error( exceptMsg )); } } //---------------------------------------------------------------------- void WECmdArgs::appTestFunction() { // testing begins //std::string aJobFile("/home/bpaul/Calpont/data/bulk/job/Job_1234.xml"); //std::string aJobFile("/usr/local/mariadb/columnstore/data/bulk/job/Job_1234.xml"); //setSchemaAndTableFromJobFile(aJobFile); //setEnclByAndEscCharFromJobFile(aJobFile); //exit(1); //testing ends return; } //---------------------------------------------------------------------- std::string WECmdArgs::getCpImportCmdLine() { std::ostringstream aSS; std::string aCmdLine; aSS << fPrgmName; //prgm name as arg[0] if (fHelp) { aSS << " -h "; aCmdLine = aSS.str(); return aCmdLine; } //checkJobIdCase(); // check if JobID if ((fPmFile.length() > 0) && (0 == getMode())) aSS << " -l " << fPmFile; //BUG 4379 if -m is not given while prep args, default is m=1 but //on single node -m will set it to 3, after prep args. //if((fPmFilePath.length()>0)&&(1!=getMode())) // aSS << " -f " << fPmFilePath; if ((fPmFilePath.length() > 0) && (1 != getMode())) { if (fPmFilePath == "STDIN") //if stdin, must pass it aSS << " -f " << fPmFilePath; else if (2 == getArgMode()) //Mode 2 we need to pass the -f option aSS << " -f " << fPmFilePath; else if (3 == getArgMode()) //-m given, -f built in already. aSS << " -f " << fPmFilePath; else if (0 == fLocFile.length()) //No filename given, from job file aSS << " -f " << fPmFilePath; } if (fErrorDir.length() > 0) aSS << " -L " << fErrorDir; if (fUsername.length() > 0) aSS << " -U " << fUsername; if (fJobId.length() > 0) aSS << " -j " << fJobId; if (fNoOfReadThrds > 0) aSS << " -r " << fNoOfReadThrds; if (fNoOfWriteThrds > 0) aSS << " -w " << fNoOfWriteThrds; if (fMaxErrors >= 0) aSS << " -e " << fMaxErrors; // BUG 5088 if (fDebugLvl > 0) aSS << " -d " << fDebugLvl; if (fSetBufSize > 0) aSS << " -B " << fSetBufSize; if (fColDelim != '|') { if (fColDelim == '\t') aSS << " -s " << "\\t"; //- working with user '\t' // NONE of the following will work. //aSS << " -s " << "\t"; //aSS << " -s " << "\"\\t\""; //aSS << " -s " << "'\\t'"; else aSS << " -s " << fColDelim; } if (fEnclosedChar != 0) aSS << " -E " << fEnclosedChar; if (fEscChar != 0) aSS << " -C " << fEscChar; if (fNullStrMode) aSS << " -n " << '1'; if (fImportDataMode != IMPORT_DATA_TEXT) aSS << " -I " << fImportDataMode; //if(fConfig.length()>0) // aSS << " -c " << fConfig; if (fReadBufSize > 0) { cout << "setting fReadBufSize = " << fReadBufSize; aSS << " -c " << fReadBufSize; } if (fIOReadBufSize > 0) aSS << " -b " << fIOReadBufSize; if ((fJobPath.length() > 0) && (fMode == 3)) aSS << " -p " << fJobPath; if (fConsoleLog) aSS << " -i "; if ((fMode == 1) || (fMode == 2)) { aSS << " -R " << getBrmRptFileName(); aSS << " -m " << fMode; } aSS << " -P " << getModuleID(); aSS << " -T " << fTimeZone; if (fbTruncationAsError) aSS << " -S "; if (!fS3Key.empty() && !(fMode == 0 || fMode == 1)) { if (fS3Secret.empty() || fS3Bucket.empty() || fS3Region.empty()) throw (runtime_error("Not all required S3 options provided")); aSS << " -y " << fS3Key; aSS << " -K " << fS3Secret; aSS << " -t " << fS3Bucket; aSS << " -g " << fS3Region; if (!fS3Host.empty()) { aSS << " -H " << fS3Host; } } if ((fJobId.length() > 0) && (fMode == 1) && (!fJobLogOnly)) { // if JobPath provided, make it w.r.t WES aSS << " -p " << fTmpFileDir; aSS << " -fSTDIN"; } else if ((fJobId.length() > 0) && (fMode == 2) && (!fJobLogOnly)) { // if JobPath provided, make it w.r.t WES aSS << " -p " << fTmpFileDir; if (fPmFile.length() > 0) aSS << " -l " << fPmFile; if (fPmFilePath.length() > 0) aSS << " -f " << fPmFilePath; } else // do not provide schema & table with JobId { if (!fUUID.is_nil()) aSS << " -u" << boost::uuids::to_string(fUUID); if (fSchema.length() > 0) aSS << " " << fSchema; //else if((fMode != 0)||(fMode==3)) //TODO make it mode3 + jobID else if (fJobId.length() > 0) { }// may or may not contain Schema. //else if((fMode == 1)||(fMode==2)) //TODO make it mode3 + jobID else if (fMode != 0) throw (runtime_error("Schema not available")); if (fTable.length() > 0) aSS << " " << fTable; else if (fJobId.length() > 0) {} //may or may not contain Table. else if (fMode != 0) throw (runtime_error("Tablename not available")); //else if((fMode != 0)||(fMode==3)) //TODO make it mode3 + jobID //else if((fMode == 1)||(fMode == 2)) //TODO make it mode3 + jobID // throw (runtime_error("Tablename not available")); if ((fPmFile.length() > 0) && (2 == getMode())) { //if(fPmFilePath.length()>0) // aSS << " " << fPmFilePath; aSS << " " << fPmFile; } else if (2 == getMode()) throw (runtime_error("loadFile [-l ] not available")); } if ((fLocFile.length() > 0) && (fLocFile != "STDIN") && (3 == getMode())) { //Bug 4342 multi-files mode 3 support //convert all the spaces into 'commas' if (fLocFile.find_first_of(' ') == string::npos) aSS << " " << fLocFile; else { std::string aLocFiles = replaceCharInStr(fLocFile, ' ', ','); aSS << " " << aLocFiles; } } try { aCmdLine = aSS.str(); } catch (exception&) { throw runtime_error("getcpImportCmdLine failed"); } return aCmdLine; } //---------------------------------------------------------------------- //BUG 4205 (part FIX) - need to implement more into it bool WECmdArgs::checkForCornerCases() { //BUG 4210 this->checkJobIdCase(); //Need to do this before we go further if (fMode == 0) { if (!fJobId.empty()) { //cout << "Invalid option mode 0 with a Job File" << endl; throw (runtime_error("Mode 0 with a Job file option is not valid!!" "\nTry 'cpimport -h' for more information.")); } else if (!fJobPath.empty()) { cout << "Invalid option mode 0 with a Job Path" << endl; throw (runtime_error("Mismatched options" "\nTry 'cpimport -h' for more information.")); } else if (!fSchema.empty()) { cout << "Invalid option in mode 0 with a schema name" << endl; throw (runtime_error("Mismatched options.")); } else if (!fTable.empty()) { cout << "Invalid option in mode 0 with a table name" << endl; throw (runtime_error("Mismatched options.")); } else if ((!fPmFilePath.empty()) && (fPmFilePath != "STDIN")) { cout << "Invalid option -f in Mode 0 with value other than STDIN" << endl; throw (runtime_error("Mismatched options.")); } if (fSetBufSize) { cout << "Invalid option -B with Mode 0" << endl; throw (runtime_error("Mismatched options.")); } else if (fIOReadBufSize) { cout << "Invalid option -b with Mode 0" << endl; throw (runtime_error("Mismatched options.")); } else if (fMaxErrors >= 0) { cout << "Invalid option -e with Mode 0" << endl; throw (runtime_error("Mismatched options.")); } else if (fConsoleLog) { cout << "Invalid option -i with Mode 0" << endl; throw (runtime_error("Mismatched options.")); } else if (fReadBufSize) { cout << "Invalid option -c with Mode 0" << endl; throw (runtime_error("Mismatched options.")); } else if (fNoOfReadThrds) { cout << "Invalid option -r with Mode 0" << endl; throw (runtime_error("Mismatched options.")); } else if (fNoOfWriteThrds) { cout << "Invalid option -w with Mode 0" << endl; throw (runtime_error("Mismatched options.")); } if (fImportDataMode != IMPORT_DATA_TEXT) { cout << "Invalid option -I with Mode 0" << endl; throw (runtime_error("Mismatched options.")); } } if (fMode == 1) { if (!fJobId.empty()) { if ((!fPmFilePath.empty()) && (fPmFilePath == "STDIN")) { // do not do anything.. this is good. } } // Mode 1, if Input Path is existing and input file is not existing // it is an error, bce it assumes all the files in directory. // In mode 2, we are passing info to cpimport.bin, which will take care // of it, as in Mode 3. else if ((!fPmFilePath.empty()) && (fPmFile.empty())) { // assumed since position param is missing if ((fLocFile == "STDIN") && (fPmFilePath != "STDIN")) { cout << "Invalid options in Mode 1 : option -l " << endl; cout << " or input file position parameter needed" << endl; //cout << "\tOption (-j) should follow with option -l option or " // "an input file position parameter" << endl; throw (runtime_error("In Mode 1 Error occurred!! " "\nTry 'cpimport -h' for more information.")); } } } if (fMode == 2) { if (fPmFile.empty()) throw(runtime_error("Mode 2 require PM based filename [-l]" "\nTry 'cpimport -h' for more information.")); if ((fPmFilePath.empty()) && (fPmFile.at(0) != '/')) throw(runtime_error("Mode 2 require remote file opts -f and -l or "\ "a fully qualified path for the remote file." "\nTry 'cpimport -h' for more information.")); if (!fS3Key.empty()) throw(runtime_error("Mode 2 & an input file from S3 does not make sense.")); } if (fMode == 3) { if (fPmVec.size()) { cout << "Invalid option -P with Mode 3" << endl; throw (runtime_error("Mismatched options.")); } } return true; } //---------------------------------------------------------------------- bool WECmdArgs::str2PmList(std::string& PmList, VecInts& V) { const int BUFLEN = 512; char aBuff[BUFLEN]; int aLen = PmList.length(); if (aLen > 0) { strncpy(aBuff, PmList.c_str(), BUFLEN); aBuff[BUFLEN - 1] = 0; } else return false; char* pTok = strtok(aBuff, ","); while (pTok != NULL) { int aPmId = 0; try { aPmId = atoi(pTok); V.push_back(aPmId); } catch (exception& ex) { std::stringstream aErr; aErr << "Wrong PM id format : " << ex.what(); //cout << "Wrong PM id format : "<< ex.what() << endl; throw (runtime_error(aErr.str())); } pTok = strtok(NULL, ","); } return true; } //---------------------------------------------------------------------- void WECmdArgs::usage() { cout << "Simple usage using positional parameters (no XML job file):\n"; cout << "\tcpimport dbName tblName [loadFile] [-h] [-m mode]\n"; cout << "\t\t [-f path] [-d debugLevel] [-c readbufSize] [-b readBufs] \n"; cout << "\t\t [-r readers] [-j JobID] [-e maxErrs] [-B libBufSize] [-w parsers]\n"; cout << "\t\t [-s c] [-E enclosedChar] [-C escapeChar] [-n NullOption]\n"; cout << "\t\t [-q batchQty] [-p jobPath] [-P list of PMs] [-S] [-i] [-v verbose]\n"; cout << "\t\t [-I binaryOpt] [-T timeZone]\n"; cout << "Traditional usage without positional parameters (XML job file required):\n"; cout << "\tcpimport -j jobID\n"; cout << "\t\t [-h] [-m mode] [-r readers] [-w parsers] [-s c] [-f path]\n"; cout << "\t\t [-b readBufs] [-p path] [-c readBufSize] [-e maxErrs] [-B libBufSize]\n"; cout << "\t\t [-n NullOption] [-E encloseChar] [-C escapeChar] [-i] [-v verbose]\n"; cout << "\t\t [-d debugLevel] [-q batchQty] [-l loadFile] [-P list of PMs] [-S]\n"; cout << "\t\t [-I binaryOpt] [-T timeZone]\n"; cout << "\n\nPositional parameters:\n"; cout << "\tdbName Name of the database to load\n"; cout << "\ttblName Name of table to load\n"; cout << "\tloadFile Optional input file name in current directory,\n"; cout << "\t\t\tunless a fully qualified name is given.\n"; cout << "\t\t\tIf not given, input read from STDIN.\n"; cout << "\n\nOptions:\n" << "\t-b\tNumber of read buffers\n" << "\t-c\tApplication read buffer size(in bytes)\n" << "\t-d\tPrint different level(1-3) debug message\n" << "\t-e\tMax number of allowable error per table per PM\n" << "\t-f\tData file directory path.\n" << "\t\t\tDefault is current working directory.\n" << "\t\t\tIn Mode 1, -f represents the local input file path.\n" << "\t\t\tIn Mode 2, -f represents the PM based input file path.\n" << "\t\t\tIn Mode 3, -f represents the local input file path.\n" << "\t-l\tName of import file to be loaded, relative to -f path,\n" << "\t-h\tPrint this message.\n" << "\t-q\tBatch Quantity, Number of rows distributed per batch in Mode 1\n" << "\t-i\tPrint extended info to console in Mode 3.\n" << "\t-j\tJob ID. In simple usage, default is the table OID.\n" << "\t\t\tunless a fully qualified input file name is given.\n" << "\t-n\tNullOption (0-treat the string NULL as data (default);\n" << "\t\t\t1-treat the string NULL as a NULL value)\n" << "\t-p\tPath for XML job description file.\n" << "\t-r\tNumber of readers.\n" << "\t-s\t'c' is the delimiter between column values.\n" << "\t-B\tI/O library read buffer size (in bytes)\n" << "\t-w\tNumber of parsers.\n" << "\t-E\tEnclosed by character if field values are enclosed.\n" << "\t-C\tEscape character used in conjunction with 'enclosed by'\n" << "\t\t\tcharacter, or as part of NULL escape sequence ('\\N');\n" << "\t\t\tdefault is '\\'\n" << "\t-I\tImport binary data; how to treat NULL values:\n" << "\t\t\t1 - import NULL values\n" << "\t\t\t2 - saturate NULL values\n" << "\t-P\tList of PMs ex: -P 1,2,3. Default is all PMs.\n" << "\t-S\tTreat string truncations as errors.\n" << "\t-m\tmode\n" << "\t\t\t1 - rows will be loaded in a distributed manner across PMs.\n" << "\t\t\t2 - PM based input files loaded onto their respective PM.\n" << "\t\t\t3 - input files will be loaded on the local PM.\n" << "\t-T\tTimezone used for TIMESTAMP datatype.\n" << "\t\tPossible values: \"SYSTEM\" (default)\n" << "\t\t : Offset in the form +/-HH:MM\n" << "\t-y\tS3 Authentication Key (for S3 imports)\n" << "\t-K\tS3 Authentication Secret (for S3 imports)\n" << "\t-t\tS3 Bucket (for S3 imports)\n" << "\t-H\tS3 Hostname (for S3 imports, Amazon's S3 default)\n" << "\t-g\tS3 Region (for S3 imports)\n" << "\t-L\tDirectory for the output .err and .bad files.\n" << "\t\tDefault is " << string(MCSLOGDIR); cout << "\nExample1: Traditional usage\n" << "\tcpimport -j 1234"; cout << "\nExample2: Some column values are enclosed within double quotes.\n" << "\tcpimport -j 3000 -E '\"'"; cout << "\nExample3: Import a nation table without a Job XML file\n" << "\tcpimport -j 301 tpch nation nation.tbl"; cout << "\nExample4: Import a nation table to all PMs in Mode 1\n" << "\tcpimport -m 1 tpch nation nation.tbl"; cout << "\nExample4: Import a nation table to only PM1 and PM2 in Mode 1\n" << "\tcpimport -m 1 -P 1,2 tpch nation nation.tbl"; cout << "\nExample5: Import nation.tbl from PMs to nation table in Mode 2\n" << "\tcpimport -m 2 tpch nation -f /var/lib/columnstore/data/bulk/data/import/ -l nation.tbl"; cout << "\nExample6: Import nation.tbl in mode 3\n" << "\tcpimport -m 3 tpch nation nation.tbl\n\n"; exit(1); } //----------------------------------------------------------------------------- void WECmdArgs::parseCmdLineArgs(int argc, char** argv) { int aCh; std::string importPath; bool aJobType = false; if (argc > 0) fPrgmName = string(MCSBINDIR) + "/" + "cpimport.bin"; //argv[0] is splitter but we need cpimport while ((aCh = getopt(argc, argv, "d:j:w:s:v:l:r:b:e:B:f:q:ihm:E:C:P:I:n:p:c:ST:Ny:K:t:H:g:U:L:")) != EOF) { switch (aCh) { case 'm': { fArgMode = atoi(optarg); //cout << "Mode level set to " << fMode << endl; if ((fArgMode > -1) && (fArgMode <= 3)) {} else throw runtime_error("Wrong Mode level"); break; } case 'B': { errno = 0; long lValue = strtol(optarg, 0, 10); if ((errno != 0) || (lValue < 1) || (lValue > INT_MAX)) throw runtime_error("Option -B is invalid or out of range"); fSetBufSize = lValue; break; } case 'b': { errno = 0; long lValue = strtol(optarg, 0, 10); if ((errno != 0) || (lValue < 1) || (lValue > INT_MAX)) throw runtime_error("Option -b is invalid or out of range"); fIOReadBufSize = lValue; break; } case 'e': { errno = 0; long lValue = strtol(optarg, 0, 10); if ((errno != 0) || (lValue < 0) || (lValue > INT_MAX)) throw runtime_error("Option -e is invalid or out of range"); fMaxErrors = lValue; break; } case 'i': { fConsoleLog = true; break; } case 'c': { errno = 0; long lValue = strtol(optarg, 0, 10); if ((errno != 0) || (lValue < 1) || (lValue > INT_MAX)) throw runtime_error("Option -c is invalid or out of range"); fReadBufSize = lValue; break; } case 'j': // -j: jobID { errno = 0; long lValue = strtol(optarg, 0, 10); if ((errno != 0) || (lValue < 0) || (lValue > INT_MAX)) throw runtime_error("Option -j is invalid or out of range"); fJobId = optarg; fOrigJobId = fJobId; // in case if we need to split it. if (0 == fJobId.length()) throw runtime_error("Wrong JobID Value"); aJobType = true; break; } case 'v': // verbose { string aVerbLen = optarg; fVerbose = aVerbLen.length(); fDebugLvl = fVerbose; break; } case 'd': // -d debug { errno = 0; long lValue = strtol(optarg, 0, 10); if ((errno != 0) || (lValue < 1) || (lValue > INT_MAX)) throw runtime_error("Option -d is invalid or out of range"); fDebugLvl = lValue; if (fDebugLvl > 0 && fDebugLvl <= 3) { cout << "\nDebug level set to " << fDebugLvl << endl; } else { throw runtime_error("Wrong Debug level"); } break; } case 'r': // -r: num read threads { errno = 0; long lValue = strtol(optarg, 0, 10); if ((errno != 0) || (lValue < 1) || (lValue > INT_MAX)) throw runtime_error("Option -r is invalid or out of range"); fNoOfReadThrds = lValue; break; } case 'w': // -w: num parse threads { errno = 0; long lValue = strtol(optarg, 0, 10); if ((errno != 0) || (lValue < 1) || (lValue > INT_MAX)) throw runtime_error("Option -w is invalid or out of range"); fNoOfWriteThrds = lValue; break; } case 's': // -s: column delimiter { if (!strcmp(optarg, "\\t")) { fColDelim = '\t'; if (fDebugLvl) cout << "Column delimiter : " << "\\t" << endl; } else { fColDelim = optarg[0]; if (fDebugLvl) cout << "Column delimiter : " << fColDelim << endl; } break; } case 'l': // -l: if JobId (-j), it can be input file { fPmFile = optarg; if (0 == fPmFile.length()) throw runtime_error("Wrong local filename"); break; } case 'f': // -f: import file path { fPmFilePath = optarg; break; } case 'n': // -n: treat "NULL" as null { // default is 0, ie it is equal to not giving this option int nullStringMode = atoi(optarg); if ((nullStringMode != 0) && (nullStringMode != 1)) { throw (runtime_error( "Invalid NULL option; value can be 0 or 1")); } if (nullStringMode) fNullStrMode = true; else fNullStrMode = false; // This is default break; } case 'P': // -p: list of PM's { try { std::string aPmList = optarg; if (!str2PmList(aPmList, fPmVec)) throw(runtime_error("PM list is wrong")); } catch (runtime_error& ex) { throw (ex); } break; } case 'p': { fJobPath = optarg; break; } case 'E': // -E: enclosed by char { fEnclosedChar = optarg[0]; //cout << "Enclosed by Character : " << optarg[0] << endl; break; } case 'C': // -C: enclosed escape char { fEscChar = optarg[0]; //cout << "Escape Character : " << optarg[0] << endl; break; } case 'h': // -h: help { //usage(); // will exit(1) here fHelp = true; break; } case 'I': // -I: binary mode (null handling) { // default is text mode, unless -I option is specified int binaryMode = atoi(optarg); if (binaryMode == 1) { fImportDataMode = IMPORT_DATA_BIN_ACCEPT_NULL; } else if (binaryMode == 2) { fImportDataMode = IMPORT_DATA_BIN_SAT_NULL; } else { throw (runtime_error( "Invalid Binary mode; value can be 1 or 2")); } break; } case 'S': // -S: Treat string truncations as errors { setTruncationAsError(true); //cout << "TruncationAsError : true" << endl; break; } case 'T': { std::string timeZone = optarg; long offset; if (timeZone != "SYSTEM" && dataconvert::timeZoneToOffset(timeZone.c_str(), timeZone.size(), &offset)) { throw (runtime_error( "Value for option -T is invalid")); } fTimeZone = timeZone; break; } case 'q': // -q: batch quantity - default value is 10000 { errno = 0; long long lValue = strtoll(optarg, 0, 10); if ((errno != 0) || (lValue < 1) || (lValue > UINT_MAX)) throw runtime_error("Option -q is invalid or out of range"); fBatchQty = lValue; if (fBatchQty < 10000) fBatchQty = 10000; else if (fBatchQty > 100000) fBatchQty = 10000; break; } case 'N': //-N no console output { fConsoleOutput = false; break; } case 'y': //-y S3 Key { fS3Key = optarg; break; } case 'K': //-K S3 Secret { fS3Secret = optarg; break; } case 'H': //-H S3 Host { fS3Host = optarg; break; } case 't': //-t S3 bucket { fS3Bucket = optarg; break; } case 'g': //-g S3 Region { fS3Region = optarg; break; } case 'U': //-U username of the files owner { fUsername = optarg; break; } case 'L': // -L set the output location of .bad/.err files { fErrorDir = optarg; break; } default: { std::string aErr = std::string("Unknown command line option ") + std::to_string(aCh); //cout << "Unknown command line option " << aCh << endl; throw (runtime_error(aErr)); } } } if (fHelp) usage(); //BUG 4210 if (fArgMode != -1) fMode = fArgMode; //BUG 4210 std::string bulkRootPath = getBulkRootDir(); checkForBulkLogDir(bulkRootPath); if (2 == fArgMode && fPmFilePath.empty()) throw runtime_error("-f option is mandatory with mode 2."); if (aJobType) { if (0 == fArgMode) throw runtime_error("Incompatible mode and option types"); if (optind < argc) { fSchema = argv[optind]; // 1st pos parm optind++; if (optind < argc) { fTable = argv[optind]; // 2nd pos parm optind++; } else { // if schema is there, table name should be there throw runtime_error("No table name specified with schema."); } if (optind < argc) // see if input file name is given { // 3rd pos parm fLocFile = argv[optind]; if ((fLocFile.at(0) != '/') && (fLocFile != "STDIN")) { std::string aTmp = fLocFile; // BUG 4379 -f given? use that if ((!fPmFilePath.empty()) && (fMode == 1)) fLocFile = fPmFilePath + "/" + aTmp; else if (fPmFilePath.empty()) fLocFile = bulkRootPath + "/data/import/" + aTmp; } } else { if (!fPmFile.empty()) fLocFile = fPmFile; //BUG 4186 //else // else take it from the jobxml file // fLocFile = "STDIN"; //Historically cpimport works with jobfile as // -l <fileName> && -f <filePath> or // -fSTDIN as the stdin, it will override colxml loadfile entry // if -fSTDIN is not provided get i/p file from jobfile else if ((!fPmFilePath.empty()) && (fPmFilePath == "STDIN")) fLocFile = "STDIN"; // else take it from the jobxml file } if ((fSchema.length() > 0) && (fTable.length() > 0) && (fLocFile.length() > 0)) fJobLogOnly = true; } else { if (!fPmFile.empty()) { fLocFile = fPmFile; if (!fPmFilePath.empty()) { if (fPmFilePath == "STDIN") { throw runtime_error("Conflicting options -l and -fSTDIN"); } else { std::string aTmp = fLocFile; if ((!fPmFilePath.empty()) && (fMode == 1)) //BUG 4379 -f given? use that fLocFile = fPmFilePath + "/" + aTmp; else if (!fPmFilePath.empty()) fLocFile = bulkRootPath + "/data/import/" + aTmp; } } if ((fLocFile.at(0) != '/') && (fLocFile != "STDIN") && (fPmFilePath.empty())) { std::string aTmp = fLocFile; fLocFile = bulkRootPath + "/data/import/" + aTmp; } } //BUG 4186 //else // fLocFile = "STDIN"; //Historically cpimport works with jobfile as // -l <fileName> && -f <filePath> or // -fSTDIN as the stdin, it will override colxml loadfile entry // if -fSTDIN is not provided get i/p file from jobfile else if ((!fPmFilePath.empty()) && (fPmFilePath == "STDIN")) fLocFile = "STDIN"; // else take it from the jobxml file } } // Get positional arguments, User can provide: // 1. no positional parameters - Mode 0 & stdin // 2. Two positional parameters (schema and table names) - Mode 1/2, stdin // 3. Three positional parameters (schema, table, and import file name) else if (optind < argc) // see if db schema name is given { if (fArgMode == 0) { //added the code as per BUG 4245 if (!fPmFilePath.empty()) { fLocFile = fPmFilePath; if (fLocFile != "STDIN") throw(runtime_error("ERROR: In Mode 0, -f option can only have value STDIN")); } else { fLocFile = argv[optind]; optind++; } if (optind < argc) //dest filename provided { fPmFile = argv[optind]; if ((fPmFile.at(0) != '/') && (fS3Key.empty())) { std::string aTmp = fPmFile; fPmFile = bulkRootPath + "/data/import/" + aTmp; } } else // no dest filename { if (fLocFile == "STDIN") throw(runtime_error("ERROR: Destination file name required!!")); if (fLocFile.at(0) == '/') //local FQ-filename,parse out filename fPmFile = getFileNameFromPath(fLocFile); else fPmFile = fLocFile; if ((fPmFile.at(0) != '/') && (fS3Key.empty())) //should be true all the time { std::string aTmp = fPmFile; fPmFile = bulkRootPath + "/data/import/" + aTmp; } } /* commented out for BUG 4245 if(fPmFilePath.empty()) fLocFile = argv[optind]; else fLocFile = fPmFilePath +"/"+ argv[optind]; if (fPmFile.empty()) //BUG 4200 { //if(fLocFile.at(0)== '/') // fPmFile = fLocFile; //else if(fLocFile.at(0)!='/') fPmFile = bulkRootPath + "/data/import/"+ fLocFile; } else { if(fPmFile.at(0)!='/') { std::string aTmp = fPmFile; fPmFile = bulkRootPath + "/data/import/"+aTmp; } } */ } else fSchema = argv[optind]; // 1st pos parm optind++; if (optind < argc) // see if table name is given { fTable = argv[optind]; // 2nd pos parm optind++; if (optind < argc) // see if input file name is given { // 3rd pos parm fLocFile = argv[optind]; //BUG 4379 if -f option given we need to use that path, //over riding bug 4231. look at the code below //BUG 4231 - This bug over writes 4199 and commenting out changes //BUG 4199 //Path not provided, not fully qualified, Look in import dir //if((fLocFile.at(0)!= '/')&&(fLocFile != "STDIN")) //{ // std::string aTmp = fLocFile; // fLocFile = bulkRootPath + "/data/import/"+ aTmp; //} //BUG 4379 if -f option given we need to use that path if ((fLocFile.at(0) != '/') && (fLocFile != "STDIN")) { std::string aTmp = fLocFile; //if -f given? use that otherwise just go ahead with CWD if ((!fPmFilePath.empty()) && (fMode == 1)) fLocFile = fPmFilePath + "/" + aTmp; // TODO - if -f option is given and a list of files are // are provided, we need to be able to import all that. } } else { if (fPmFile.length() > 0) { // BUG 4210 //if (fPmFilePath.length() > 0) //{ // fLocFile = fPmFilePath +"/"+ fPmFile; //} //else if (fPmFilePath.empty()) { //NOTE - un-commenting with an if statement for Mode 2 //BUG 4231 makes it comment out the below changes, //This will not change even though directly, to be //on safer side, we should take out this too. //check path fully qualified? then set as data import if (2 == fArgMode) { //BUG 4342 if ((fPmFile.at(0) != '/') && (fS3Key.empty())) { std::string aTmp = fPmFile; fPmFile = PrepMode2ListOfFiles(aTmp); } else { if (fPmFile.find_first_of(' ') != string::npos) { std::string aPmFiles = replaceCharInStr(fPmFile, ' ', ','); fPmFile = aPmFiles; } } } fLocFile = fPmFile; } } else { fLocFile = "STDIN"; } //cout << "LocFile set as stdin" << endl; } } else { // If Mode is not 0 and table name is a required argument if (fArgMode != 0) throw(runtime_error("No table name specified with schema.")); } } else { // for testing we are allowing data from stdin even with Mode 0 // that is without LocFileName if (0 == fArgMode) { fLocFile = "STDIN"; //cout << "LocFile set as stdin" << endl; } else { // If Mode 0, LocFileName is reqd and otherwies Schema is required throw (runtime_error("No schema or local filename specified.")); } } /* check for all-or-nothing cmdline args to enable S3 import */ int s3Tmp = (fS3Key.empty() ? 0 : 1) + (fS3Bucket.empty() ? 0 : 1) + (fS3Secret.empty() ? 0 : 1) + (fS3Region.empty() ? 0 : 1); if (s3Tmp != 0 && s3Tmp != 4) throw runtime_error("The access key, secret, bucket, and region are all required to import from S3"); } std::string WECmdArgs::getJobFileName() { std::ostringstream aSS; string aJobIdFileName; if (fJobId.length() > 0) { if (fJobPath.length() > 0) aSS << fJobPath; else { fJobPath = config::Config::makeConfig()->getConfig("WriteEngine", "BulkRoot") + "/Job"; aSS << fJobPath; } aSS << "/Job_" << fJobId << ".xml"; aJobIdFileName = aSS.str(); } return aJobIdFileName; } bool WECmdArgs::getPmStatus(int Id) { // if no PMID's provided on cmdline, return true; if (0 == fPmVec.size()) return true; VecInts::iterator aIt = fPmVec.begin(); while (aIt != fPmVec.end()) { if (*aIt == static_cast<unsigned int>(Id)) return true; ++aIt; } return false; } //------------------------------------------------------------------------------ // It is a recursive call. std::string WECmdArgs::getBrmRptFileName() { if (!fBrmRptFile.empty()) return fBrmRptFile; string brmRptFileName = getTmpFileDir(); if (!brmRptFileName.empty()) { fTmpFileDir = brmRptFileName; char aBuff[64]; time_t aTime; struct tm pTm; time(&aTime); localtime_r(&aTime, &pTm); // BUG 4424 // M D H M S snprintf(aBuff, sizeof(aBuff), "/BrmRpt%02d%02d%02d%02d%02d%d.rpt", pTm.tm_mon, pTm.tm_mday, pTm.tm_hour, pTm.tm_min, pTm.tm_sec, getpid()); brmRptFileName += aBuff; } else { //cout << "ERROR: Could not find TempFileDir in Columnstore.xml" << endl; throw (runtime_error("Could not find TempFileDir in Columnstore.xml")); } setBrmRptFileName(brmRptFileName); return brmRptFileName; } //------------------------------------------------------------------------------ void WECmdArgs::addJobFilesToVector(std::string& JobName) { //if((!fSchema.empty())&&(!fTable.empty())&&(!fLocFile.empty())) return; WEXmlgetter aXmlGetter(JobName); vector<string> aSections; aSections.push_back("BulkJob"); aSections.push_back("Schema"); aSections.push_back("Table"); //BUG 4163 typedef std::vector<string> TableVec; TableVec aTableVec; aXmlGetter.getConfig(aSections[1], aSections[2], aTableVec); setMultiTableCount(aTableVec.size()); if (getMultiTableCount() > 1) { splitConfigFilePerTable(JobName, aTableVec.size()); } else { fVecJobFiles.push_back(JobName); } } //------------------------------------------------------------------------------ // Set the schema, table, and loadfile name from the xml job file. // If running in binary mode, we also get the list of columns for the table, // so that we can determine the exact fixed record length of the incoming data. //------------------------------------------------------------------------------ void WECmdArgs::setSchemaAndTableFromJobFile(std::string& JobName) { if (((fVecJobFiles.size() == 1) && (!fSchema.empty()) && (!fTable.empty()) && (!fLocFile.empty())) && (fImportDataMode == IMPORT_DATA_TEXT)) return; WEXmlgetter aXmlGetter(JobName); vector<string> aSections; aSections.push_back("BulkJob"); aSections.push_back("Schema"); aSections.push_back("Table"); // Reset the fSchema, fTable, and FLocFile if ((fVecJobFiles.size() > 1) || (fSchema.empty()) || (fTable.empty()) || (fLocFile.empty())) { std::string aSchemaTable; std::string aInputFile; aSchemaTable = aXmlGetter.getAttribute(aSections, "tblName"); if (getDebugLvl() > 1) cout << "schema.table = " << aSchemaTable << endl; aInputFile = aXmlGetter.getAttribute(aSections, "loadName"); if (getDebugLvl() > 1) cout << "xml::InputFile = " << aInputFile << endl; if (aSchemaTable.length() > 0) { char aSchema[64]; char aTable[64]; int aRet = aSchemaTable.find('.'); if (aRet > 0) { int aLen = aSchemaTable.copy(aSchema, aRet); if (getDebugLvl() > 1) cout << "Schema: " << aSchema << endl; aSchema[aLen] = 0; if (fSchema.empty()) fSchema = aSchema; aLen = aSchemaTable.copy(aTable, aSchemaTable.length(), aRet + 1 ); aTable[aLen] = 0; if (getDebugLvl() > 1) cout << "Table: " << aTable << endl; fTable = aTable; } else throw runtime_error( "JobFile ERROR: Can't get Schema and Table Name"); } else { throw runtime_error( "JobFile ERROR: Can't get Schema and Table Name"); } if ((fLocFile.empty()) && (!aInputFile.empty())) { string bulkRootPath = config::Config::makeConfig()->getConfig( "WriteEngine", "BulkRoot"); if (aInputFile.at(0) == '/') fLocFile = aInputFile; else if ((!fPmFilePath.empty()) && (fMode == 1)) fLocFile = fPmFilePath + "/" + aInputFile; else if ((!bulkRootPath.empty()) && (fPmFilePath.empty())) fLocFile = bulkRootPath + "/data/import/" + aInputFile; else fLocFile = aInputFile; if (fArgMode == 2) fPmFile = fLocFile; } if (getDebugLvl() > 1) cout << "schema = " << fSchema << endl; if (getDebugLvl() > 1) cout << "TableName = " << fTable << endl; if (getDebugLvl() > 1) cout << "Input File = " << fLocFile << endl; } // Reset the list of columns we will be importing from the input data fColFldsFromJobFile.clear(); if (fImportDataMode != IMPORT_DATA_TEXT) { aSections.push_back("Column"); aXmlGetter.getAttributeListForAllChildren( aSections, "colName", fColFldsFromJobFile); } } //------------------------------------------------------------------------------ void WECmdArgs::checkJobIdCase() { if ((fJobId.empty()) || (fJobLogOnly) || (fMode == 3) || (fMode == 0)) return; if (fJobPath.empty()) { string bulkRootPath = config::Config::makeConfig()->getConfig( "WriteEngine", "BulkRoot"); //cout << "checkJobIdCase::BulkRoot: " << bulkRootPath << endl; if (!bulkRootPath.empty()) fJobPath = bulkRootPath + "/job"; else throw runtime_error("Config Error: BulkRoot not found in Columnstore.xml"); } char aBuff[256]; if (!fJobPath.empty()) snprintf(aBuff, sizeof(aBuff), "%s/Job_%s.xml", fJobPath.c_str(), fJobId.c_str()); else // for time being snprintf(aBuff, sizeof(aBuff), "/var/log/mariadb/columnstore/data/bulk/job/Job_%s.xml", fJobId.c_str()); std::string aJobFileName(aBuff); //cout << "checkJobIdCase::aJobFileName: " << aJobFileName << endl; //BUG 4171 addJobFilesToVector(aJobFileName); aJobFileName = fVecJobFiles[0]; setSchemaAndTableFromJobFile(aJobFileName); setEnclByAndEscCharFromJobFile(aJobFileName); } //------------------------------------------------------------------------------ std::string WECmdArgs::getTmpFileDir() { if (!fTmpFileDir.empty()) return fTmpFileDir; fTmpFileDir = startup::StartUp::tmpDir(); if (fTmpFileDir.empty()) throw( runtime_error("Config ERROR: TmpFileDir not found!!")); else return fTmpFileDir; } //------------------------------------------------------------------------------ std::string WECmdArgs::getBulkRootDir() { if (!fBulkRoot.empty()) return fBulkRoot; fBulkRoot = config::Config::makeConfig()->getConfig("WriteEngine", "BulkRoot"); if (fBulkRoot.empty()) throw( runtime_error("Config ERROR: <BulkRoot> not found!!")); else return fBulkRoot; } //------------------------------------------------------------------------------ unsigned int WECmdArgs::getBatchQuantity() { return (fBatchQty >= 10000) ? fBatchQty : 10000; //default Batch Qty is 10000 } //------------------------------------------------------------------------------ void WECmdArgs::setEnclByAndEscCharFromJobFile(std::string& JobName) { if (fEnclosedChar == 0) // check anything in Jobxml file { WEXmlgetter aXmlGetter(JobName); vector<string> aSections; aSections.push_back("BulkJob"); aSections.push_back("EnclosedByChar"); try { //std::string aTable = aXmlGetter.getConfig(aSection, aElement); std::string aEnclosedBy = aXmlGetter.getValue(aSections); if (getDebugLvl() > 1)cout << "aEncloseBy = " << aEnclosedBy << endl; if (!aEnclosedBy.empty()) { fEnclosedChar = aEnclosedBy.at(0); } } catch (std::runtime_error&) { // do not do anything } } if (fEscChar == 0) // check anything in Jobxml file { WEXmlgetter aXmlGetter(JobName); vector<string> aSections; aSections.push_back("BulkJob"); aSections.push_back("EscapeChar"); try { //std::string aTable = aXmlGetter.getConfig(aSection, aElement); std::string aEscChar = aXmlGetter.getValue(aSections); if (getDebugLvl() > 1) cout << "aEscapeChar = " << aEscChar << endl; if (!aEscChar.empty()) { fEscChar = aEscChar.at(0); } } catch (std::runtime_error&) { // do not do anything } } } //------------------------------------------------------------------------------ std::string WECmdArgs::getFileNameFromPath(const std::string& Path) const { char aBuff[64]; int iDx = Path.find_last_of('/'); iDx++; // compensate for the forward slash int aCx = Path.size() - iDx; Path.copy(aBuff, aCx, iDx); aBuff[aCx] = 0; return aBuff; } //------------------------------------------------------------------------------ std::string WECmdArgs::getModuleID() { oam::Oam oam; oam::oamModuleInfo_t sModInfo; std::string sModuleID; char szModuleIDandPID[64]; int nModuleNumber; try { sModInfo = oam.getModuleInfo(); sModuleID = boost::get < 1 > (sModInfo); nModuleNumber = boost::get < 2 > (sModInfo); snprintf(szModuleIDandPID, sizeof(szModuleIDandPID), "%s%d-%d", sModuleID.c_str(), nModuleNumber, getpid()); sModuleID = szModuleIDandPID; } catch (exception&) { sModuleID = "unknown"; } return sModuleID; } //------------------------------------------------------------------------------ void WECmdArgs::splitConfigFilePerTable(std::string& ConfigName, int tblCount) { std::string aOpenTag = "<Table "; std::string aCloseTag = "</Table>"; std::string aCloseSchemaTag = "</Schema>"; std::vector<std::ofstream*> aVecFiles; //std::vector<std::string> aVecConfigs; for (int aIdx = 1; aIdx <= tblCount; aIdx++) { char aConfName[128]; snprintf(aConfName, sizeof(aConfName), "%s_%d.xml", ConfigName.c_str(), aIdx); //aVecConfigs.push_back(aConfName); fVecJobFiles.push_back(aConfName); std::ofstream* pCopy = new std::ofstream; //pCopy->open(aConfName, std::ios_base::app); pCopy->open(aConfName); aVecFiles.push_back(pCopy); } std::ifstream aMaster; aMaster.open(ConfigName.c_str()); if (aMaster.is_open()) { char aBuff[256]; int aTblNo = 0; size_t aStrPos = std::string::npos; bool aOpenFound = false; bool aCloseFound = false; while (!aMaster.eof()) { aMaster.getline(aBuff, sizeof(aBuff) - 1); unsigned int aLen = aMaster.gcount(); if ((aLen < (sizeof(aBuff) - 2)) && (aLen > 0)) { aBuff[aLen - 1] = '\n'; aBuff[aLen] = 0; string aData = aBuff; //cout << "Data Read " << aBuff; if (!aOpenFound) { aStrPos = aData.find(aOpenTag); if (aStrPos != std::string::npos) { aOpenFound = true; aTblNo++; write2ConfigFiles(aVecFiles, aBuff, aTblNo); } else { if ((!aOpenFound) && (aCloseFound)) { aStrPos = aData.find(aCloseSchemaTag); if (aStrPos != std::string::npos) { aOpenFound = false; aCloseFound = false; aTblNo = 0; } } write2ConfigFiles(aVecFiles, aBuff, aTblNo); } } else { aStrPos = aData.find(aCloseTag); if (aStrPos != std::string::npos) { aOpenFound = false; aCloseFound = true; write2ConfigFiles(aVecFiles, aBuff, aTblNo); } else { write2ConfigFiles(aVecFiles, aBuff, aTblNo); } } } }//while Master.eof } else { throw runtime_error("Could not open Job Config file"); } for (unsigned int Idx = 0; Idx < aVecFiles.size(); Idx++) { aVecFiles[Idx]->close(); delete aVecFiles[Idx]; } aVecFiles.clear(); } //------------------------------------------------------------------------------ void WECmdArgs::write2ConfigFiles(std::vector<std::ofstream*>& Files, char* pBuff, int FileIdx) { if (FileIdx == 0) { std::vector<std::ofstream*>::iterator aIt = Files.begin(); while (aIt != Files.end()) { std::ofstream* pCopy = (*aIt); pCopy->write(pBuff, strlen(pBuff)); ++aIt; } } else { Files[FileIdx - 1]->write(pBuff, strlen(pBuff)); } } //------------------------------------------------------------------------------ void WECmdArgs::updateWithJobFile(int Idx) { setLocFile(""); // resetting the from the previous import std::string aJobFileName = fVecJobFiles[Idx]; setSchemaAndTableFromJobFile(aJobFileName); setEnclByAndEscCharFromJobFile(aJobFileName); setJobFileName(aJobFileName); std::ostringstream aSS; aSS << fOrigJobId << ".xml_" << (Idx + 1); fJobId = aSS.str(); } //------------------------------------------------------------------------------ std::string WECmdArgs::replaceCharInStr(const std::string& Str, char C, char R) { std::stringstream aSs; size_t start = 0, end = 0; end = Str.find_first_of(C); do { if (end != string::npos) { aSs << Str.substr(start, end - start) << R; start = end + 1; } else { aSs << Str.substr(start, end - start); break; } end = Str.find_first_of(C, start); } while (start != end); return aSs.str(); } //------------------------------------------------------------------------------ // Introduced to handle Bug 4342 with Mode 2 std::string WECmdArgs::PrepMode2ListOfFiles(std::string& FileName) { VecArgs aInfileList; std::string bulkRootPath = getBulkRootDir(); //cout << "Inside PrepMode2ListOfFiles("<< FileName << ")" << endl; std::string aFileName = FileName; istringstream iss(aFileName); size_t start = 0, end = 0; const char* sep = " ,|"; end = aFileName.find_first_of(sep); do { if (end != string::npos) { std::string aFile = aFileName.substr(start, end - start); if (getDebugLvl() > 1) cout << "File: " << aFileName.substr(start, end - start) << endl; start = end + 1; aInfileList.push_back(aFile); } else { std::string aFile = aFileName.substr(start, end - start); if (getDebugLvl() > 1) cout << "Next Input File " << aFileName.substr(start, end - start) << endl; aInfileList.push_back(aFile); break; } end = aFileName.find_first_of(sep, start); } while (start != end); std::ostringstream aSS; int aVecSize = aInfileList.size(); int aVecIdx = 0; // Take file list one by one and append it to one string while (aVecIdx < aVecSize) { std::string aNextFile = aInfileList[aVecIdx]; aVecIdx++; //aInfileList.pop_front(); if (aNextFile.at(0) != '/') { aSS << bulkRootPath << "/data/import/" + aNextFile; } else { aSS << aNextFile; } if (aVecIdx < aVecSize) aSS << ","; } //cout << "File list are = " << aSS.str() << endl; return aSS.str(); } //------------------------------------------------------------------------------ // Get set of column names in the "current" table being processed from the // Job xml file. //------------------------------------------------------------------------------ void WECmdArgs::getColumnList( std::set<std::string>& columnList ) const { columnList.clear(); for (unsigned k = 0; k < fColFldsFromJobFile.size(); k++) { columnList.insert( fColFldsFromJobFile[k] ); } } //----------------------------------------------------------------------------- // check for the bulkload log directory. If it is not existing, create it // w.r.t Bug 6137 //----------------------------------------------------------------------------- void WECmdArgs::checkForBulkLogDir(const std::string& BulkRoot) { if ( !boost::filesystem::exists(BulkRoot.c_str()) ) { cout << "Creating directory : " << BulkRoot << endl; boost::filesystem::create_directories(BulkRoot.c_str()); } if ( boost::filesystem::exists(BulkRoot.c_str()) ) { // create the job directory also if not existing std::ostringstream aSS; aSS << BulkRoot; aSS << "/job"; std::string jobDir = aSS.str(); if ( !boost::filesystem::exists(jobDir.c_str()) ) { cout << "Creating directory : " << jobDir << endl; bool aSuccess = boost::filesystem::create_directories(jobDir.c_str()); if (!aSuccess) { cout << "\nFailed to create job directory, check permissions\n" << endl; throw runtime_error("Failed to create job directory, check permissions"); } } } else { cout << "\nFailed to create bulk directory, check permissions\n" << endl; throw runtime_error("Failed to create bulk directory, check permissions"); } } } /* namespace WriteEngine */
import .lemmas.substitution .lemmas.big_step open big_step lemma big_subst_complete {E e S r} : (E, compile e, S) ⟹ₙᵥ (E, r :: S) → big_subst E e ⟹ r := begin assume h, induction' e, case EVal { rw compile at h, cases' h, cases' h, rw big_subst_val, apply RunVal }, case EVar { rw compile at h, cases' h, cases' h, induction' _x, case bhead { rw [big_subst, subst, if_pos (eq.refl x), big_subst_val], apply RunVal }, case btail { rw [big_subst, subst, if_neg h.symm], exact ih } }, case EOp { rw compile at h, simp at h, rw big_subst_spread_op, cases' to_interm_results h with v h', cases' h' with he_1 h', cases' to_interm_results h' with u h'', cases' h'' with he h'', cases' h'', cases' h'', apply RunOp, exact ih_e he, exact ih_e_1 he_1 }, case EIf { rw compile at h, simp at h, rw big_subst_spread_if, cases' to_interm_results h with v h', cases' h' with he h', cases h', case ERunTBranch { cases' to_interm_results h'__x with u, cases' h_1 with he_1 h_1, cases' h_1, rw list.drop_length at h_1, cases' h_1, apply RunIfT, exact ih_e he, exact ih_e_1 he_1 }, case ERunFBranch { rename [h'__x hle, h'__x_1 he_2], simp at he_2, have H : ∀ xs, (compile e_1).append xs = compile e_1 ++ xs, assume xs, by refl, rw [nat.succ_eq_add_one, nat.add_comm, list.drop_add, list.drop_one, H, list.drop_append_of_le_length, list.drop_length, list.nil_append, list.tail] at he_2, apply RunIfF, exact ih_e he, exact ih_e_2 he_2, refl } }, case ELet { rw compile at h, simp at h, cases' to_interm_results h with v h', cases' h' with he h', cases' h', cases' to_interm_results h' with u h'', cases' h'' with he_1 h'', cases' h'', cases' h'', rw big_subst_spread_let, apply RunLet, exact ih_e he, rw [subst_merge, big_subst_remove_append], exact ih_e_1 he_1 } end theorem compile_complete_nv {e : exp} {r : val} : ([], compile e, []) ⟹ₙᵥ ([], [r]) → e ⟹ r := assume h, have H : big_subst [] e ⟹ r := big_subst_complete h, by rw big_subst at H; exact H
import data.mv_polynomial -- workaround for the "open_locale at top of file" issue in Lean 3 example : ℕ := 37 open_locale classical lemma sum.rec_comp_left (X : Type*) (Y : Type*) (β : Type*) (γ : Type*) (i : β → X) (j : γ → X) (f : X → Y) (x : β ⊕ γ) : f (sum.rec i j x) = sum.rec (f ∘ i) (f ∘ j) x := by cases x; refl namespace mv_polynomial /-- Evaluating the constant polynomial 1 anywhere gives 1 -/ theorem eval_one {X : Type*} {R : Type*} [comm_semiring R] (x : X → R) : eval x 1 = 1 := eval_C _ -- this must be done somewhere else because the analogue is -- in the polynomial namespace theorem eval_pow {X : Type*} {R : Type*} [comm_semiring R] (f : mv_polynomial X R) (m : ℕ) (x : X → R) : eval x (f ^ m) = (eval x f)^m := begin induction m with d hd, rw pow_zero, rw pow_zero, rw eval_one, rw pow_succ, rw pow_succ, rw eval_mul, rw hd, end end mv_polynomial namespace polynomial -- Thanks to Johan Commelin for doing a bunch of the eval stuff below. /-- Over an infinite integral domain a polynomial f is zero if it evaluates to zero everywhere -/ lemma eval_eq_zero {k : Type*} [integral_domain k] [infinite k] {f : polynomial k} (H : ∀ x, polynomial.eval x f = 0) : f = 0 := begin rcases infinite.exists_not_mem_finset (roots f) with ⟨x, hx⟩, contrapose! hx with hf, rw mem_roots hf, apply H, end /-- Over an infinite integral domain a polynomial f is zero iff it evaluates to zero everywhere -/ lemma eval_eq_zero_iff {k : Type*} [integral_domain k] [infinite k] {f : polynomial k} : (∀ x, polynomial.eval x f = 0) ↔ f = 0 := ⟨polynomial.eval_eq_zero, by { rintro rfl x, exact rfl }⟩ end polynomial def fin.equiv_empty : fin 0 ≃ empty := { to_fun := λ i, false.elim $ nat.not_lt_zero _ i.2, inv_fun := empty.elim, left_inv := λ i, false.elim $ nat.not_lt_zero _ i.2, right_inv := λ x, x.elim } def fin.equiv_pempty : fin 0 ≃ pempty := { to_fun := λ i, false.elim $ nat.not_lt_zero _ i.2, inv_fun := pempty.elim, left_inv := λ i, false.elim $ nat.not_lt_zero _ i.2, right_inv := λ x, x.elim } namespace mv_polynomial @[simp] lemma eval_rename {k : Type*} [comm_semiring k] {m : Type*} {n : Type*} (e : m → n) (f : mv_polynomial m k) (x) : eval x (rename e f) = eval (x ∘ e) f := by apply f.induction_on; { intros, simp * } lemma equiv_eval_eq_zero {k : Type*} [comm_semiring k] {m : Type*} {n : Type*} (e : m ≃ n) (H : (∀ f : mv_polynomial m k, (∀ x, eval x f = 0) → f = 0)) (f : mv_polynomial n k) (hf : ∀ x, eval x f = 0) : f = 0 := begin let φ := ring_equiv_of_equiv k e, suffices h : φ.symm f = 0, { simpa using congr_arg φ h }, apply H, intro x, show eval x (rename e.symm f) = 0, simp [hf], end end mv_polynomial universe variables u v def equiv.option {X : Type u} {Y : Type v} (e : X ≃ Y) : option X ≃ option Y := { to_fun := option.map e, inv_fun := option.map e.symm, left_inv := λ x, by { cases x, refl, simp }, right_inv := λ x, by { cases x, refl, simp } } /-- n ↦ none -/ def fin_succ_equiv_option' (n : ℕ) : fin (n+1) ≃ option (fin n) := { to_fun := λ x, if h : x.1 < n then some ⟨_, h⟩ else none, inv_fun := λ x, option.rec_on x ⟨n, nat.lt_succ_self _⟩ $ λ x, ⟨x.1, lt_trans x.2 $ nat.lt_succ_self _⟩, left_inv := λ x, begin cases x with x hx, rw [nat.lt_succ_iff, le_iff_lt_or_eq] at hx, cases hx with hx hx, { dsimp, rw dif_pos hx}, { dsimp, rw dif_neg _, cases hx, refl, apply not_lt_of_le, cases hx, refl} end, right_inv := begin intro x, cases x with x, { dsimp, rw dif_neg, apply lt_irrefl}, dsimp, cases x with x hx, rw dif_pos hx, end } /-- 0 ↦ none-/ def fin_succ_equiv_option (n : ℕ) : fin (n+1) ≃ option (fin n) := { to_fun := λ x, if h : x.1 = 0 then none else some ⟨x.1 - 1, begin rw nat.sub_lt_left_iff_lt_add, convert x.2 using 1, apply add_comm, exact nat.pos_of_ne_zero h, end⟩, inv_fun := λ x, option.rec ⟨0, nat.zero_lt_succ _⟩ (λ y, ⟨y.1 + 1, add_lt_add_right y.2 1⟩) x, left_inv := begin rintro ⟨⟨x⟩, hx⟩, refl, dsimp, rw dif_neg, simp, apply nat.succ_ne_zero end, right_inv := begin rintro (_ | ⟨x, h⟩), refl, dsimp, rw dif_neg, simp, apply nat.succ_ne_zero end } lemma fintype.induction {P : Π (X : Type*) [fintype X], Prop} (h0 : P pempty) (hs : ∀ (X : Type*) [fintype X], P X → P (option X)) (he : ∀ {X Y : Type*} [fintype X] [fintype Y] (e : X ≃ Y), P X → P Y) (X : Type*) [fintype X] : P X := begin rcases fintype.exists_equiv_fin X with ⟨n, ⟨e⟩⟩, apply he (equiv.ulift.trans e.symm), clear e, induction n with n ih, { exact he (equiv.ulift.trans fin.equiv_pempty).symm h0 }, { specialize hs _ ih, apply he _ hs, refine (equiv.ulift.trans _).symm, refine (fin_succ_equiv_option n).trans _, refine equiv.ulift.option.symm } end /- mv_polynomial.option_equiv_right : -- mv_polynomial (option β) α ≃+* mv_polynomial β (polynomial α) it's built from . mv_polynomial.ring_equiv_of_equiv . mv_polynomial.sum_ring_equiv . mv_polynomial.ring_equiv_congr glued together with . ring_equiv.trans -/ namespace mv_polynomial attribute [simp] sum_to_iter_Xr sum_to_iter_Xl sum_to_iter_C @[simp] theorem option_equiv_right_X_none {α β} [comm_semiring α] : option_equiv_right α β (X none) = C polynomial.X := show map (eval₂ polynomial.C (λu:punit, polynomial.X)) (sum_to_iter α β unit (rename (equiv.option_equiv_sum_punit._match_1 β) (X none))) = C polynomial.X, by simp @[simp] theorem option_equiv_right_X_some {α β} [comm_semiring α] (b : β) : option_equiv_right α β (X (some b)) = X b := show map (eval₂ polynomial.C (λu:punit, polynomial.X)) (sum_to_iter α β unit (rename (equiv.option_equiv_sum_punit._match_1 β) (X (some b)))) = X b, by simp @[simp] theorem option_equiv_right_C {α β} [comm_semiring α] (a : α) : option_equiv_right α β (C a) = C (polynomial.C a) := show map (eval₂ polynomial.C (λu:punit, polynomial.X)) (sum_to_iter α β unit (rename (equiv.option_equiv_sum_punit._match_1 β) (C a))) = C (polynomial.C a), by simp /- Mario Carneiro: I also brute forced my way through several other definitions here, that should have definitional lemmas: ring_equiv_of_equiv, option_equiv_sum_punit (the definition should not be simp), sum_comm (ditto), sum_ring_equiv, punit_ring_equiv Mario Carneiro: Ideally this proof should be dunfold option_equiv_right; simp -/ theorem eval₂_eval₂ (R : Type*) [comm_semiring R] (β : Type*) (γ : Type*) (S : Type*) [comm_semiring S] (f : R → S) [is_semiring_hom f] (i : β → S) (j : γ → S) (p : mv_polynomial β (mv_polynomial γ R)) : eval₂ (eval₂ f j) i p = eval i (map (eval₂ f j) p) := hom_eq_hom _ _ (by apply_instance) (by apply_instance) (λ _, by rw [eval₂_C, map_C, eval_C]) (λ _, by rw [eval₂_X, map_X, eval_X]) p set_option class.instance_max_depth 100 theorem map_eval₂' {R : Type*} [comm_semiring R] {β : Type*} {γ : Type*} {S : Type*} [comm_semiring S] {f : R → S} [is_semiring_hom f] {j : γ → S} {p : mv_polynomial β (mv_polynomial γ R)} : map (eval₂ f j) p = eval₂ (C ∘ f) (λ n, sum.rec X (C ∘ j) n) (iter_to_sum _ _ _ p) := begin rw iter_to_sum, rw eval₂_eval₂, rw ←eval₂_eq_eval_map, apply hom_eq_hom, apply_instance, apply_instance, { intro b, suffices : (C (eval₂ f j b) : mv_polynomial β S) = eval₂ (C ∘ f) (λ n, sum.rec X (C ∘ j) n) (eval₂ C (X ∘ sum.inr) b), simpa using this, rw ←rename, rw eval₂_rename, rw [show ((λ (n : β ⊕ γ), sum.rec X (C ∘ j) n) ∘ sum.inr : γ → mv_polynomial β S) = C ∘ j, by funext b; refl], apply eval₂_comp_left}, { intro b, simp}, end theorem eval₂_eval₂' (R : Type*) [comm_semiring R] (β : Type*) (γ : Type*) (S : Type*) [comm_semiring S] (f : R → S) [is_semiring_hom f] (i : β → S) (j : γ → S) (p : mv_polynomial β (mv_polynomial γ R)) : eval₂ (eval₂ f j) i p = eval₂ f (λ n, sum.rec i j n) (iter_to_sum _ _ _ p) := begin rw eval₂_eval₂, rw map_eval₂', generalize : iter_to_sum _ _ _ p = p', apply hom_eq_hom _ _ _ _ _ _ p', apply_instance, apply_instance, apply_instance, { intro r, rw [eval₂_C, eval₂_C, eval_C]}, { rintro (b | c), { simp}, { simp}, } end /-- Over an infinite integral domain a polynomial f in finitely many variables is zero if it evaluates to zero everywhere -/ lemma fin_eval_eq_zero {k : Type*} [int : integral_domain k] [inf : infinite k] {n : Type*} [fin : fintype n] : ∀ {f : mv_polynomial n k}, (∀ x, eval x f = 0) → f = 0 := begin unfreezeI, revert inf int k, revert fin n, refine fintype.induction _ _ _, { intros k int inf f H, have h : (pempty_ring_equiv k) f = 0 := H _, replace h := congr_arg (pempty_ring_equiv k).symm h, rw [ring_equiv.symm_apply_apply] at h, convert h, symmetry, exact ring_equiv.map_zero _ }, { intros n _ ih k int inf f hf, set φ := option_equiv_right k n with hφ, suffices h : φ f = 0, { simpa using congr_arg φ.symm h }, apply ih, { intro x, apply polynomial.eval_eq_zero, intro xoo, let xo : option n → k := λ j, option.rec xoo (λ i, polynomial.eval xoo (x i)) j, convert hf xo, rw hφ, apply hom_eq_hom _ _ _ _ _ _ f, apply_instance, apply_instance, apply_instance, { intro a, rw eval_C, simp}, { intro xn, cases xn with xn hxn, { simp }, { simp }, } }, { resetI, apply infinite.of_injective polynomial.C, swap, assumption, intros x y h, exact polynomial.C_inj.1 h, } }, { intros m n _ _ e H k int inf f, apply mv_polynomial.equiv_eval_eq_zero e, apply @H } end . -- no longer sure if I even care about `vars`. lemma mem_vars_iff_mem_degrees {R : Type*} [comm_semiring R] {σ : Type*} {p : mv_polynomial σ R} {n : σ} : n ∈ vars p ↔ n ∈ degrees p := multiset.mem_to_finset -- Chris Hughes' alternative definition of `mv_polynomial.vars` using `bind`. -- I have no idea whether this should be noncomputable. /-- `vars' p` is the set of variables appearing in the polynomial `p`. It's probably the same as `vars p`. -/ noncomputable def vars' {R : Type*} {σ : Type*} [comm_semiring R] (p : mv_polynomial σ R) : finset σ := p.support.bind finsupp.support -- things which might need proving? -- I will need to learn the interface for finsupp to do this one -- Remark: I think only need φ 0 = 0, not semiring hom, but coeff_map wanted it. lemma vars_map_sub {R : Type*} [comm_semiring R] {S : Type*} [comm_semiring S] {σ : Type*} {φ : R → S} [is_semiring_hom φ] {p : mv_polynomial σ R} : vars' (map φ p) ⊆ vars' p := begin intros i hi, unfold vars' at hi ⊢, rw finset.mem_bind at hi ⊢, rcases hi with ⟨s, hs, his⟩, use s, existsi _, exact his, clear his i, simp, intro hps, dunfold mv_polynomial at p, have hps' : φ (p.to_fun s) = 0, convert is_semiring_hom.map_zero _, assumption, revert hs, simp, intro h1, apply h1, convert hps', change mv_polynomial σ R at p, change (map φ p).coeff s = φ (p.coeff s), apply coeff_map, end -- Thanks to Chris for this one lemma eval₂_eq_of_eq_on_vars {R : Type*} [comm_semiring R] {S : Type*} [comm_semiring S] {σ : Type*} (f g : σ → S) (φ : R → S) (p : mv_polynomial σ R) [is_semiring_hom φ] -- do we need this?? (h : ∀ i ∈ vars' p, f i = g i) : eval₂ φ f p = eval₂ φ g p := begin unfold eval₂, unfold finsupp.sum finsupp.prod, refine finset.sum_congr rfl _, intros x hx, congr' 1, refine finset.prod_congr rfl _, intros i hi, simp only [vars', finset.mem_bind, exists_imp_distrib] at h, have := h i x hx hi, rw this, end -- KB practicing. example {R : Type*} [comm_semiring R] {S : Type*} [comm_semiring S] {σ : Type*} (f g : σ → S) (φ : R → S) (p : mv_polynomial σ R) [is_semiring_hom φ] -- do we need this?? (h : ∀ i ∈ vars' p, f i = g i) : eval₂ φ f p = eval₂ φ g p := begin unfold eval₂, unfold finsupp.prod finsupp.sum, rw finset.sum_congr rfl, intros x hx, congr' 1, rw finset.prod_congr rfl, intros i hi, rw h, unfold vars', rw finset.mem_bind, use x, use hx, assumption, end def eq_sum_monomial_coeff {R : Type*} [comm_semiring R] {σ : Type*} {p : mv_polynomial σ R} : finset.sum p.support (λ s, monomial s (p.coeff s)) = p := begin apply mv_polynomial.ext, intro s, rw coeff_sum, simp only [coeff_monomial], by_cases hs : s ∈ p.support, { rw ←finset.sum_subset (show {s} ⊆ p.support, begin intros i hi, convert hs, cases hi, assumption, cases hi end), swap, { intros t ht hts, rw if_neg, intro hts2, apply hts, rw hts2, apply set.mem_singleton, }, convert finset.sum_singleton, rw if_pos, refl }, { rw ←finset.sum_subset (finset.empty_subset p.support), swap, { intros t ht1 ht2, rw if_neg, intro hts, apply hs, rwa hts at ht1, }, rw finset.sum_empty, rw finsupp.not_mem_support_iff at hs, exact hs.symm } end /- Is this a sensible thing to prove? lemma mem_rename_range {R : Type*} [comm_semiring R] {σ τ : Type*} {g : σ → τ} (p : mv_polynomial τ R) (h : (vars' p).to_set ⊆ set.range g) : ∃ q : mv_polynomial σ R, rename g q = p := sorry -/ lemma preimage_subtype_range {R : Type*} [comm_semiring R] {σ : Type*} (p : mv_polynomial σ R) : ∃ q : mv_polynomial {i : σ // i ∈ p.vars'} R, rename subtype.val q = p := begin use finset.sum p.support (λ s, monomial (finsupp.comap_domain subtype.val s (λ _ _ _ _, subtype.eq)) (p.coeff s)), apply mv_polynomial.ext, intro s, rw ←finset.sum_hom p.support (rename subtype.val), all_goals {try {apply_instance}}, rw coeff_sum, conv begin to_rhs, rw ←@eq_sum_monomial_coeff _ _ _ p, end, rw coeff_sum, apply finset.sum_congr rfl, intros t ht, rw coeff_monomial, rw rename_monomial, rw coeff_monomial, congr', rw finsupp.map_domain_comap_domain, intros i j, exact subtype.eq, suffices : t.support ⊆ vars' p, by simpa, unfold vars', intros i hi, rw finset.mem_bind, use t, use ht, assumption, end -- We know `fin_eval_eq_zero` from above, which is the below -- theorem in the special case where `n` is finite. -- We now use it to prove the general case. /-- Over an infinite integral domain a polynomial f is zero iff it evaluates to zero everywhere -/ lemma eval_eq_zero {k : Type*} [integral_domain k] [infinite k] {σ : Type*} {p : mv_polynomial σ k} : (∀ x, eval x p = 0) ↔ p = 0 := begin split, swap, intros hf x, rw [hf, eval_zero], -- easy direction intro hev, cases preimage_subtype_range p with q hq, suffices : q = 0, rw this at hq, rw ←hq, apply is_semiring_hom.map_zero, apply fin_eval_eq_zero, intro s₀, set s : σ → k := λ i, if hi : i ∈ p.vars' then s₀ ⟨i, hi⟩ else 0 with hs, have hs₀ : s₀ = s ∘ subtype.val, ext i, rw hs, dsimp, split_ifs, simp, cases i, contradiction, rw hs₀, rw ←eval_rename, rw hq, apply hev, end -- finset.sum p.support (λ s, monomial s (p.coeff s)) = p := end mv_polynomial
/** * * @generated s Tue Jan 7 11:45:26 2014 * **/ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <cblas.h> #include <lapacke.h> #include <plasma.h> #include <core_blas.h> #include "auxiliary.h" /*------------------------------------------------------------------- * Check the orthogonality of Q */ int s_check_orthogonality(int M, int N, int LDQ, float *Q) { float alpha, beta; float normQ; int info_ortho; int i; int minMN = min(M, N); float eps; float *work = (float *)malloc(minMN*sizeof(float)); eps = LAPACKE_slamch_work('e'); alpha = 1.0; beta = -1.0; /* Build the idendity matrix USE DLASET?*/ float *Id = (float *) malloc(minMN*minMN*sizeof(float)); memset((void*)Id, 0, minMN*minMN*sizeof(float)); for (i = 0; i < minMN; i++) Id[i*minMN+i] = (float)1.0; /* Perform Id - Q'Q */ if (M >= N) cblas_ssyrk(CblasColMajor, CblasUpper, CblasTrans, N, M, alpha, Q, LDQ, beta, Id, N); else cblas_ssyrk(CblasColMajor, CblasUpper, CblasNoTrans, M, N, alpha, Q, LDQ, beta, Id, M); normQ = LAPACKE_slansy_work(LAPACK_COL_MAJOR, 'i', 'u', minMN, Id, minMN, work); printf("============\n"); printf("Checking the orthogonality of Q \n"); printf("||Id-Q'*Q||_oo / (N*eps) = %e \n",normQ/(minMN*eps)); if ( isnan(normQ / (minMN * eps)) || (normQ / (minMN * eps) > 10.0) ) { printf("-- Orthogonality is suspicious ! \n"); info_ortho=1; } else { printf("-- Orthogonality is CORRECT ! \n"); info_ortho=0; } free(work); free(Id); return info_ortho; } /*------------------------------------------------------------ * Check the factorization QR */ int s_check_QRfactorization(int M, int N, float *A1, float *A2, int LDA, float *Q) { float Anorm, Rnorm; float alpha, beta; int info_factorization; int i,j; float eps; eps = LAPACKE_slamch_work('e'); float *Ql = (float *)malloc(M*N*sizeof(float)); float *Residual = (float *)malloc(M*N*sizeof(float)); float *work = (float *)malloc(max(M,N)*sizeof(float)); alpha=1.0; beta=0.0; if (M >= N) { /* Extract the R */ float *R = (float *)malloc(N*N*sizeof(float)); memset((void*)R, 0, N*N*sizeof(float)); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'u', M, N, A2, LDA, R, N); /* Perform Ql=Q*R */ memset((void*)Ql, 0, M*N*sizeof(float)); cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, N, (alpha), Q, LDA, R, N, (beta), Ql, M); free(R); } else { /* Extract the L */ float *L = (float *)malloc(M*M*sizeof(float)); memset((void*)L, 0, M*M*sizeof(float)); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'l', M, N, A2, LDA, L, M); /* Perform Ql=LQ */ memset((void*)Ql, 0, M*N*sizeof(float)); cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, M, (alpha), L, M, Q, LDA, (beta), Ql, M); free(L); } /* Compute the Residual */ for (i = 0; i < M; i++) for (j = 0 ; j < N; j++) Residual[j*M+i] = A1[j*LDA+i]-Ql[j*M+i]; Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Residual, M, work); Anorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, A2, LDA, work); if (M >= N) { printf("============\n"); printf("Checking the QR Factorization \n"); printf("-- ||A-QR||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps)); } else { printf("============\n"); printf("Checking the LQ Factorization \n"); printf("-- ||A-LQ||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps)); } if (isnan(Rnorm / (Anorm * N *eps)) || (Rnorm / (Anorm * N * eps) > 10.0) ) { printf("-- Factorization is suspicious ! \n"); info_factorization = 1; } else { printf("-- Factorization is CORRECT ! \n"); info_factorization = 0; } free(work); free(Ql); free(Residual); return info_factorization; } /*------------------------------------------------------------------------ * Check the factorization of the matrix A2 */ int s_check_LLTfactorization(int N, float *A1, float *A2, int LDA, int uplo) { float Anorm, Rnorm; float alpha; int info_factorization; int i,j; float eps; eps = LAPACKE_slamch_work('e'); float *Residual = (float *)malloc(N*N*sizeof(float)); float *L1 = (float *)malloc(N*N*sizeof(float)); float *L2 = (float *)malloc(N*N*sizeof(float)); float *work = (float *)malloc(N*sizeof(float)); memset((void*)L1, 0, N*N*sizeof(float)); memset((void*)L2, 0, N*N*sizeof(float)); alpha= 1.0; LAPACKE_slacpy_work(LAPACK_COL_MAJOR,' ', N, N, A1, LDA, Residual, N); /* Dealing with L'L or U'U */ if (uplo == PlasmaUpper){ LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'u', N, N, A2, LDA, L1, N); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'u', N, N, A2, LDA, L2, N); cblas_strmm(CblasColMajor, CblasLeft, CblasUpper, CblasTrans, CblasNonUnit, N, N, (alpha), L1, N, L2, N); } else{ LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'l', N, N, A2, LDA, L1, N); LAPACKE_slacpy_work(LAPACK_COL_MAJOR,'l', N, N, A2, LDA, L2, N); cblas_strmm(CblasColMajor, CblasRight, CblasLower, CblasTrans, CblasNonUnit, N, N, (alpha), L1, N, L2, N); } /* Compute the Residual || A -L'L|| */ for (i = 0; i < N; i++) for (j = 0; j < N; j++) Residual[j*N+i] = L2[j*N+i] - Residual[j*N+i]; Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', N, N, Residual, N, work); Anorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', N, N, A1, LDA, work); printf("============\n"); printf("Checking the Cholesky Factorization \n"); printf("-- ||L'L-A||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps)); if ( isnan(Rnorm/(Anorm*N*eps)) || (Rnorm/(Anorm*N*eps) > 10.0) ){ printf("-- Factorization is suspicious ! \n"); info_factorization = 1; } else{ printf("-- Factorization is CORRECT ! \n"); info_factorization = 0; } free(Residual); free(L1); free(L2); free(work); return info_factorization; } /*-------------------------------------------------------------- * Check the gemm */ float s_check_gemm(PLASMA_enum transA, PLASMA_enum transB, int M, int N, int K, float alpha, float *A, int LDA, float *B, int LDB, float beta, float *Cplasma, float *Cref, int LDC, float *Cinitnorm, float *Cplasmanorm, float *Clapacknorm ) { float beta_const = -1.0; float Rnorm; float *work = (float *)malloc(max(K,max(M, N))* sizeof(float)); *Cinitnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work); *Cplasmanorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Cplasma, LDC, work); cblas_sgemm(CblasColMajor, (CBLAS_TRANSPOSE)transA, (CBLAS_TRANSPOSE)transB, M, N, K, (alpha), A, LDA, B, LDB, (beta), Cref, LDC); *Clapacknorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work); cblas_saxpy(LDC * N, (beta_const), Cplasma, 1, Cref, 1); Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, Cref, LDC, work); free(work); return Rnorm; } /*-------------------------------------------------------------- * Check the trsm */ float s_check_trsm(PLASMA_enum side, PLASMA_enum uplo, PLASMA_enum trans, PLASMA_enum diag, int M, int NRHS, float alpha, float *A, int LDA, float *Bplasma, float *Bref, int LDB, float *Binitnorm, float *Bplasmanorm, float *Blapacknorm ) { float beta_const = -1.0; float Rnorm; float *work = (float *)malloc(max(M, NRHS)* sizeof(float)); /*float eps = LAPACKE_slamch_work('e');*/ *Binitnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, NRHS, Bref, LDB, work); *Bplasmanorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bplasma, LDB, work); cblas_strsm(CblasColMajor, (CBLAS_SIDE)side, (CBLAS_UPLO)uplo, (CBLAS_TRANSPOSE)trans, (CBLAS_DIAG)diag, M, NRHS, (alpha), A, LDA, Bref, LDB); *Blapacknorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bref, LDB, work); cblas_saxpy(LDB * NRHS, (beta_const), Bplasma, 1, Bref, 1); Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'm', M, NRHS, Bref, LDB, work); Rnorm = Rnorm / *Blapacknorm; /* max(M,NRHS) * eps);*/ free(work); return Rnorm; } /*-------------------------------------------------------------- * Check the solution */ float s_check_solution(int M, int N, int NRHS, float *A, int LDA, float *B, float *X, int LDB, float *anorm, float *bnorm, float *xnorm ) { /* int info_solution; */ float Rnorm = -1.00; float zone = 1.0; float mzone = -1.0; float *work = (float *)malloc(max(M, N)* sizeof(float)); *anorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, N, A, LDA, work); *xnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', M, NRHS, X, LDB, work); *bnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', N, NRHS, B, LDB, work); cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, NRHS, N, (zone), A, LDA, X, LDB, (mzone), B, LDB); Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, 'i', N, NRHS, B, LDB, work); free(work); return Rnorm; }
State Before: ⊢ comap re (comap Real.exp (𝓝 0)) = comap re atBot State After: no goals Tactic: rw [Real.comap_exp_nhds_zero]
using MyExample using Test @test my_f(1,2) == 4 @testset "MyExample.jl" begin # Write your tests here. @test my_f(1,2) == 4 @test my_f(2,1) == 5 end
theory Sorted imports Main "../Sorting" HardL begin lemma leqRev [] : "\<not> leq r t \<Longrightarrow> leq t r" (* without other lemmas, requires schemes *) by hipster_induct_schemes (* apply(induction r rule: leq.induct) apply(simp_all) done*) lemma leqLeqEq : "\<lbrakk> leq r t ; leq t r \<rbrakk> \<Longrightarrow> r = t" by (hipster_induct_schemes) (* without other lemmas, requires schemes *) lemma insSorted : "insert r (isort ts) = isort (insert r ts)" apply(induction ts rule: isort.induct) apply(simp_all add: leqRev leqLeqEq) (* case with r = Z *) oops lemma insTwiceComm : "insert r (insert t ts) = insert t (insert r ts)" (* case with r = Z *) oops lemma isortIds : "sorted ts \<Longrightarrow> isort ts = ts" by hipster_induct_schemes (* apply(induction ts rule: sorted.induct) apply(simp_all) done*) lemma insSortInvarZ : "sorted ts \<Longrightarrow> sorted (insert Z ts)" by (hipster_induct_simp_metis) (* alternative: apply(case_tac ts) apply(simp_all) done *) setup\<open>Hip_Tac_Ops.toggle_full_types @{context} ;\<close> setup\<open>Hip_Tac_Ops.set_metis_to @{context} 1000;\<close> ML\<open> Hip_Tac_Ops.metis_to @{context} ; Hip_Tac_Ops.use_full_types @{context};\<close> lemma insSortInvar : "sorted ts \<Longrightarrow> sorted (insert t ts)" by (hipster_induct_schemes sorted.simps insert.simps Nat.exhaust leqRev list.exhaust) (* by (hipster_induct_schemes sorted.simps leqRev) apply(induction ts rule: sorted.induct) apply(simp_all) apply(metis sorted.simps insert.simps leqRev) sledgehammer by (metis (full_types) leqRev)*) lemma isortSorts : "sorted (isort ts)" by (hipster_induct_simp_metis insSortInvar) (* started as: apply(induction ts rule: isort.induct) apply(simp_all) apply(simp add: insSortInvar) *) lemma isortIdsP : "sorted ts \<Longrightarrow> sorted (isort ts)" by (hipster_induct_simp_metis isortSorts) lemma kerIsort : "isort (isort ts) = isort ts" by (hipster_induct_simp_metis isortSorts isortIds) (* apply(induction ts rule: isort.induct) apply(simp_all add: isortIds) *) lemma insMinInsorted : "sorted ts \<Longrightarrow> isort (insert Z ts) = insert Z ts" by (hipster_induct_simp_metis isortIds insSortInvar) lemma insSomeInsorted : "sorted ts \<Longrightarrow> isort (insert t ts) = insert t ts" by (hipster_induct_simp_metis isortIds insSortInvar) lemma postOverPrecond: "sorted (insert t ts) \<Longrightarrow> sorted ts" apply(induction t ts rule: insert.induct) apply(simp_all add: leqRev leqLeqEq) oops end
Formal statement is: lemma setdist_empty1 [simp]: "setdist {} t = 0" Informal statement is: The distance between the empty set and any set is zero.
Oxyhalides are more common for antimony than arsenic and phosphorus . Antimony trioxide dissolves in concentrated acid to form <unk> compounds such as <unk> and ( SbO )
logis(x) = 1 ./(1 .+ exp(-x))
#import Pkg #Pkg.add("Gadfly") include("../src/ID_ENGINE.jl") using PyPlot using DelimitedFiles printstyled("STARTING THE TEST...\n",bold=true,color=:light_cyan) printstyled("Loading the pictures... ",bold=true,color=:bold) m = ImgtoFloat("test.png") mi = ImgtoFloat("test_ID.png") printstyled("DONE\n",bold=false,color=:yellow) printstyled("Creating Lighting Environnement... ",bold=true,color=:bold) sl = SceneLights() printstyled("DONE\n",bold=false,color=:yellow) printstyled("Setting the layers... ",bold=true,color=:bold) spwnLayer!(sl,"land",5.0) spwnLayer!(sl,"rocks",-0.5) printstyled("DONE\n",bold=false,color=:yellow) printstyled("Spawning the lights... ",bold=true,color=:bold) spwnLight!(sl,"jose",[2,2],"central",20.0,0.0,[1.0,1.0,0.0]) spwnLight!(sl,"mob",[5,18],"land",20.0,0.0,[1.0,0.0,1.0]) printstyled("DONE\n",bold=false,color=:yellow) printstyled("Spawning the objects... ",bold=true,color=:bold) spwnObject!(sl,"carreau",[4,4],"central","test.png","test_ID.png") printstyled("DONE\n",bold=false,color=:yellow) askSceneLights(sl) printstyled("Processing... ",bold=true,color=:bold) pp,dd = Ray_ID(sl,"carreau") printstyled("DONE\n",bold=false,color=:yellow) printstyled("Displaying the pictures... ",bold=true,color=:bold) subplot(1,3,1) imshow(m) subplot(1,3,2) imshow(mi) subplot(1,3,3) imshow(pp) scatter(sl.Light["jose"].Coord[1]-sl.Object["carreau"].Coord[1],sl.Light["jose"].Coord[2]-sl.Object["carreau"].Coord[2]) scatter(sl.Light["mob"].Coord[1]-sl.Object["carreau"].Coord[1],sl.Light["mob"].Coord[2]-sl.Object["carreau"].Coord[2]) printstyled("DONE\n",bold=false,color=:yellow) printstyled("ENDING THE TEST...\n",bold=true,color=:light_magenta) #How to display #bring light
lemma setdist_closure_2 [simp]: "setdist T (closure S) = setdist T S"
Mushroom polysaccharides from a number of species have attracted research interest for their <unk> and antitumor properties . Extracts from A. hygrometricus containing the polysaccharide named AE2 were found to inhibit the growth of several tumor cell lines in laboratory tests , and stimulated the growth of <unk> , <unk> , and bone marrow cells from mice . The extract also stimulated mouse cells associated with the immune system ; specifically , it enhanced the activity of mouse natural killer cells , stimulated macrophages to produce nitric oxide , and enhanced production of cytokines . The activation of macrophages by AE2 might be mediated by a mitogen @-@ activated protein kinase pathway of signal transduction . AE2 is made of the simple sugars mannose , glucose , and <unk> in a 1 : 2 : 1 ratio .
function test_approx_test02 ( ) %*****************************************************************************80 % %% TEST_APPROX_TEST02 shows how P00_STORY can be called. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 12 August 2011 % % Author: % % John Burkardt % fprintf ( 1, '\n' ); fprintf ( 1, 'TEST_APPROX_TEST02\n' ); fprintf ( 1, ' P00_STORY prints the problem "story".\n' ); prob_num = p00_prob_num ( ); for prob = 1 : prob_num fprintf ( 1, '\n' ); fprintf ( 1, ' Problem %d\n', prob ); p00_story ( prob ); end return end
[GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat src✝ : AddGroupWithOne (ColimitType F) := ColimitType.AddGroupWithOne F x✝ y✝ z✝ : ColimitType F x y z : Prequotient F ⊢ Quot.mk Setoid.r x * (Quot.mk Setoid.r y + Quot.mk Setoid.r z) = Quot.mk Setoid.r x * Quot.mk Setoid.r y + Quot.mk Setoid.r x * Quot.mk Setoid.r z [PROOFSTEP] simp only [(· + ·), (· * ·), Add.add] [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat src✝ : AddGroupWithOne (ColimitType F) := ColimitType.AddGroupWithOne F x✝ y✝ z✝ : ColimitType F x y z : Prequotient F ⊢ Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.mk Setoid.r x) (Quotient.map₂ add (_ : ∀ (x x' : Prequotient F), x ≈ x' → ∀ (y y' : Prequotient F), y ≈ y' → add x y ≈ add x' y') (Quot.mk Setoid.r y) (Quot.mk Setoid.r z)) = Quotient.map₂ add (_ : ∀ (x x' : Prequotient F), x ≈ x' → ∀ (y y' : Prequotient F), y ≈ y' → add x y ≈ add x' y') (Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.mk Setoid.r x) (Quot.mk Setoid.r y)) (Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.mk Setoid.r x) (Quot.mk Setoid.r z)) [PROOFSTEP] exact Quot.sound (Relation.left_distrib _ _ _) [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat src✝ : AddGroupWithOne (ColimitType F) := ColimitType.AddGroupWithOne F x✝ y✝ z✝ : ColimitType F x y z : Prequotient F ⊢ (Quot.mk Setoid.r x + Quot.mk Setoid.r y) * Quot.mk Setoid.r z = Quot.mk Setoid.r x * Quot.mk Setoid.r z + Quot.mk Setoid.r y * Quot.mk Setoid.r z [PROOFSTEP] simp only [(· + ·), (· * ·), Add.add] [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat src✝ : AddGroupWithOne (ColimitType F) := ColimitType.AddGroupWithOne F x✝ y✝ z✝ : ColimitType F x y z : Prequotient F ⊢ Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quotient.map₂ add (_ : ∀ (x x' : Prequotient F), x ≈ x' → ∀ (y y' : Prequotient F), y ≈ y' → add x y ≈ add x' y') (Quot.mk Setoid.r x) (Quot.mk Setoid.r y)) (Quot.mk Setoid.r z) = Quotient.map₂ add (_ : ∀ (x x' : Prequotient F), x ≈ x' → ∀ (y y' : Prequotient F), y ≈ y' → add x y ≈ add x' y') (Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.mk Setoid.r x) (Quot.mk Setoid.r z)) (Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.mk Setoid.r y) (Quot.mk Setoid.r z)) [PROOFSTEP] exact Quot.sound (Relation.right_distrib _ _ _) [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat src✝ : AddGroupWithOne (ColimitType F) := ColimitType.AddGroupWithOne F x✝ y✝ z✝ : ColimitType F x y z : Prequotient F ⊢ Quot.mk Setoid.r x * Quot.mk Setoid.r y * Quot.mk Setoid.r z = Quot.mk Setoid.r x * (Quot.mk Setoid.r y * Quot.mk Setoid.r z) [PROOFSTEP] simp only [(· * ·)] [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat src✝ : AddGroupWithOne (ColimitType F) := ColimitType.AddGroupWithOne F x✝ y✝ z✝ : ColimitType F x y z : Prequotient F ⊢ Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.mk Setoid.r x) (Quot.mk Setoid.r y)) (Quot.mk Setoid.r z) = Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.mk Setoid.r x) (Quot.map₂ mul (_ : ∀ (x y y' : Prequotient F), Relation F y y' → Relation F (mul x y) (mul x y')) (_ : ∀ (x x' y : Prequotient F), Relation F x x' → Relation F (mul x y) (mul x' y)) (Quot.mk Setoid.r y) (Quot.mk Setoid.r z)) [PROOFSTEP] exact Quot.sound (Relation.mul_assoc _ _ _) [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J ⊢ coconeFun F j 1 = 1 [PROOFSTEP] apply Quot.sound [GOAL] case a J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J ⊢ Setoid.r (Prequotient.of j 1) one [PROOFSTEP] apply Relation.one [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J ⊢ ∀ (x y : ↑(F.obj j)), OneHom.toFun { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) } (x * y) = OneHom.toFun { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) } x * OneHom.toFun { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) } y [PROOFSTEP] intros [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J x✝ y✝ : ↑(F.obj j) ⊢ OneHom.toFun { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) } (x✝ * y✝) = OneHom.toFun { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) } x✝ * OneHom.toFun { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) } y✝ [PROOFSTEP] apply Quot.sound [GOAL] case a J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J x✝ y✝ : ↑(F.obj j) ⊢ Setoid.r (Prequotient.of j (x✝ * y✝)) (mul (Prequotient.of j x✝) (Prequotient.of j y✝)) [PROOFSTEP] apply Relation.mul [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J ⊢ OneHom.toFun (↑{ toOneHom := { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) }, map_mul' := (_ : ∀ (x y : ↑(F.obj j)), Quot.mk Setoid.r (Prequotient.of j (x * y)) = Quot.mk Setoid.r (mul (Prequotient.of j x) (Prequotient.of j y))) }) 0 = 0 [PROOFSTEP] apply Quot.sound [GOAL] case a J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J ⊢ Setoid.r (Prequotient.of j 0) zero [PROOFSTEP] apply Relation.zero [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J ⊢ ∀ (x y : ↑(F.obj j)), OneHom.toFun (↑{ toOneHom := { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) }, map_mul' := (_ : ∀ (x y : ↑(F.obj j)), Quot.mk Setoid.r (Prequotient.of j (x * y)) = Quot.mk Setoid.r (mul (Prequotient.of j x) (Prequotient.of j y))) }) (x + y) = OneHom.toFun (↑{ toOneHom := { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) }, map_mul' := (_ : ∀ (x y : ↑(F.obj j)), Quot.mk Setoid.r (Prequotient.of j (x * y)) = Quot.mk Setoid.r (mul (Prequotient.of j x) (Prequotient.of j y))) }) x + OneHom.toFun (↑{ toOneHom := { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) }, map_mul' := (_ : ∀ (x y : ↑(F.obj j)), Quot.mk Setoid.r (Prequotient.of j (x * y)) = Quot.mk Setoid.r (mul (Prequotient.of j x) (Prequotient.of j y))) }) y [PROOFSTEP] intros [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J x✝ y✝ : ↑(F.obj j) ⊢ OneHom.toFun (↑{ toOneHom := { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) }, map_mul' := (_ : ∀ (x y : ↑(F.obj j)), Quot.mk Setoid.r (Prequotient.of j (x * y)) = Quot.mk Setoid.r (mul (Prequotient.of j x) (Prequotient.of j y))) }) (x✝ + y✝) = OneHom.toFun (↑{ toOneHom := { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) }, map_mul' := (_ : ∀ (x y : ↑(F.obj j)), Quot.mk Setoid.r (Prequotient.of j (x * y)) = Quot.mk Setoid.r (mul (Prequotient.of j x) (Prequotient.of j y))) }) x✝ + OneHom.toFun (↑{ toOneHom := { toFun := coconeFun F j, map_one' := (_ : Quot.mk Setoid.r (Prequotient.of j 1) = Quot.mk Setoid.r one) }, map_mul' := (_ : ∀ (x y : ↑(F.obj j)), Quot.mk Setoid.r (Prequotient.of j (x * y)) = Quot.mk Setoid.r (mul (Prequotient.of j x) (Prequotient.of j y))) }) y✝ [PROOFSTEP] apply Quot.sound [GOAL] case a J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j : J x✝ y✝ : ↑(F.obj j) ⊢ Setoid.r (Prequotient.of j (x✝ + y✝)) (add (Prequotient.of j x✝) (Prequotient.of j y✝)) [PROOFSTEP] apply Relation.add [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j j' : J f : j ⟶ j' ⊢ F.map f ≫ coconeMorphism F j' = coconeMorphism F j [PROOFSTEP] ext [GOAL] case w J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j j' : J f : j ⟶ j' x✝ : (forget CommRingCat).obj (F.obj j) ⊢ ↑(F.map f ≫ coconeMorphism F j') x✝ = ↑(coconeMorphism F j) x✝ [PROOFSTEP] apply Quot.sound [GOAL] case w.a J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j j' : J f : j ⟶ j' x✝ : (forget CommRingCat).obj (F.obj j) ⊢ Setoid.r (Prequotient.of j' (↑(F.map f) x✝)) (Prequotient.of j x✝) [PROOFSTEP] apply Relation.map [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j j' : J f : j ⟶ j' x : ↑(F.obj j) ⊢ ↑(coconeMorphism F j') (↑(F.map f) x) = ↑(coconeMorphism F j) x [PROOFSTEP] rw [← cocone_naturality F f] [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat j j' : J f : j ⟶ j' x : ↑(F.obj j) ⊢ ↑(coconeMorphism F j') (↑(F.map f) x) = ↑(F.map f ≫ coconeMorphism F j') x [PROOFSTEP] rfl [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F ⊢ ColimitType F → ↑s.pt [PROOFSTEP] fapply Quot.lift [GOAL] case f J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F ⊢ Prequotient F → ↑s.pt [PROOFSTEP] exact descFunLift F s [GOAL] case a J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F ⊢ ∀ (a b : Prequotient F), Setoid.r a b → descFunLift F s a = descFunLift F s b [PROOFSTEP] intro x y r [GOAL] case a J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : Prequotient F r : Setoid.r x y ⊢ descFunLift F s x = descFunLift F s y [PROOFSTEP] induction r with | refl => rfl | symm x y _ ih => exact ih.symm | trans x y z _ _ ih1 ih2 => exact ih1.trans ih2 | map j j' f x => exact RingHom.congr_fun (s.ι.naturality f) x | zero j => simp | one j => simp | neg j x => simp | add j x y => simp | mul j x y => simp | neg_1 x x' r ih => dsimp; rw [ih] | add_1 x x' y r ih => dsimp; rw [ih] | add_2 x y y' r ih => dsimp; rw [ih] | mul_1 x x' y r ih => dsimp; rw [ih] | mul_2 x y y' r ih => dsimp; rw [ih] | zero_add x => dsimp; rw [zero_add] | add_zero x => dsimp; rw [add_zero] | one_mul x => dsimp; rw [one_mul] | mul_one x => dsimp; rw [mul_one] | add_left_neg x => dsimp; rw [add_left_neg] | add_comm x y => dsimp; rw [add_comm] | mul_comm x y => dsimp; rw [mul_comm] | add_assoc x y z => dsimp; rw [add_assoc] | mul_assoc x y z => dsimp; rw [mul_assoc] | left_distrib x y z => dsimp; rw [mul_add] | right_distrib x y z => dsimp; rw [add_mul] | zero_mul x => dsimp; rw [zero_mul] | mul_zero x => dsimp; rw [mul_zero] [GOAL] case a J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : Prequotient F r : Setoid.r x y ⊢ descFunLift F s x = descFunLift F s y [PROOFSTEP] induction r with | refl => rfl | symm x y _ ih => exact ih.symm | trans x y z _ _ ih1 ih2 => exact ih1.trans ih2 | map j j' f x => exact RingHom.congr_fun (s.ι.naturality f) x | zero j => simp | one j => simp | neg j x => simp | add j x y => simp | mul j x y => simp | neg_1 x x' r ih => dsimp; rw [ih] | add_1 x x' y r ih => dsimp; rw [ih] | add_2 x y y' r ih => dsimp; rw [ih] | mul_1 x x' y r ih => dsimp; rw [ih] | mul_2 x y y' r ih => dsimp; rw [ih] | zero_add x => dsimp; rw [zero_add] | add_zero x => dsimp; rw [add_zero] | one_mul x => dsimp; rw [one_mul] | mul_one x => dsimp; rw [mul_one] | add_left_neg x => dsimp; rw [add_left_neg] | add_comm x y => dsimp; rw [add_comm] | mul_comm x y => dsimp; rw [mul_comm] | add_assoc x y z => dsimp; rw [add_assoc] | mul_assoc x y z => dsimp; rw [mul_assoc] | left_distrib x y z => dsimp; rw [mul_add] | right_distrib x y z => dsimp; rw [add_mul] | zero_mul x => dsimp; rw [zero_mul] | mul_zero x => dsimp; rw [mul_zero] [GOAL] case a.refl J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y x✝ : Prequotient F ⊢ descFunLift F s x✝ = descFunLift F s x✝ [PROOFSTEP] | refl => rfl [GOAL] case a.refl J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y x✝ : Prequotient F ⊢ descFunLift F s x✝ = descFunLift F s x✝ [PROOFSTEP] rfl [GOAL] case a.symm J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝¹ y✝ x y : Prequotient F x✝ : Relation F x y ih : descFunLift F s x = descFunLift F s y ⊢ descFunLift F s y = descFunLift F s x [PROOFSTEP] | symm x y _ ih => exact ih.symm [GOAL] case a.symm J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝¹ y✝ x y : Prequotient F x✝ : Relation F x y ih : descFunLift F s x = descFunLift F s y ⊢ descFunLift F s y = descFunLift F s x [PROOFSTEP] exact ih.symm [GOAL] case a.trans J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝² y✝ x y z : Prequotient F x✝¹ : Relation F x y x✝ : Relation F y z ih1 : descFunLift F s x = descFunLift F s y ih2 : descFunLift F s y = descFunLift F s z ⊢ descFunLift F s x = descFunLift F s z [PROOFSTEP] | trans x y z _ _ ih1 ih2 => exact ih1.trans ih2 [GOAL] case a.trans J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝² y✝ x y z : Prequotient F x✝¹ : Relation F x y x✝ : Relation F y z ih1 : descFunLift F s x = descFunLift F s y ih2 : descFunLift F s y = descFunLift F s z ⊢ descFunLift F s x = descFunLift F s z [PROOFSTEP] exact ih1.trans ih2 [GOAL] case a.map J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y : Prequotient F j j' : J f : j ⟶ j' x : ↑(F.obj j) ⊢ descFunLift F s (Prequotient.of j' (↑(F.map f) x)) = descFunLift F s (Prequotient.of j x) [PROOFSTEP] | map j j' f x => exact RingHom.congr_fun (s.ι.naturality f) x [GOAL] case a.map J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y : Prequotient F j j' : J f : j ⟶ j' x : ↑(F.obj j) ⊢ descFunLift F s (Prequotient.of j' (↑(F.map f) x)) = descFunLift F s (Prequotient.of j x) [PROOFSTEP] exact RingHom.congr_fun (s.ι.naturality f) x [GOAL] case a.zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : Prequotient F j : J ⊢ descFunLift F s (Prequotient.of j 0) = descFunLift F s zero [PROOFSTEP] | zero j => simp [GOAL] case a.zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : Prequotient F j : J ⊢ descFunLift F s (Prequotient.of j 0) = descFunLift F s zero [PROOFSTEP] simp [GOAL] case a.one J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : Prequotient F j : J ⊢ descFunLift F s (Prequotient.of j 1) = descFunLift F s one [PROOFSTEP] | one j => simp [GOAL] case a.one J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : Prequotient F j : J ⊢ descFunLift F s (Prequotient.of j 1) = descFunLift F s one [PROOFSTEP] simp [GOAL] case a.neg J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y : Prequotient F j : J x : ↑(F.obj j) ⊢ descFunLift F s (Prequotient.of j (-x)) = descFunLift F s (neg (Prequotient.of j x)) [PROOFSTEP] | neg j x => simp [GOAL] case a.neg J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y : Prequotient F j : J x : ↑(F.obj j) ⊢ descFunLift F s (Prequotient.of j (-x)) = descFunLift F s (neg (Prequotient.of j x)) [PROOFSTEP] simp [GOAL] case a.add J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ : Prequotient F j : J x y : ↑(F.obj j) ⊢ descFunLift F s (Prequotient.of j (x + y)) = descFunLift F s (add (Prequotient.of j x) (Prequotient.of j y)) [PROOFSTEP] | add j x y => simp [GOAL] case a.add J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ : Prequotient F j : J x y : ↑(F.obj j) ⊢ descFunLift F s (Prequotient.of j (x + y)) = descFunLift F s (add (Prequotient.of j x) (Prequotient.of j y)) [PROOFSTEP] simp [GOAL] case a.mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ : Prequotient F j : J x y : ↑(F.obj j) ⊢ descFunLift F s (Prequotient.of j (x * y)) = descFunLift F s (mul (Prequotient.of j x) (Prequotient.of j y)) [PROOFSTEP] | mul j x y => simp [GOAL] case a.mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ : Prequotient F j : J x y : ↑(F.obj j) ⊢ descFunLift F s (Prequotient.of j (x * y)) = descFunLift F s (mul (Prequotient.of j x) (Prequotient.of j y)) [PROOFSTEP] simp [GOAL] case a.neg_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x x' : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ descFunLift F s (neg x) = descFunLift F s (neg x') [PROOFSTEP] | neg_1 x x' r ih => dsimp; rw [ih] [GOAL] case a.neg_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x x' : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ descFunLift F s (neg x) = descFunLift F s (neg x') [PROOFSTEP] dsimp [GOAL] case a.neg_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x x' : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ -descFunLift F s x = -descFunLift F s x' [PROOFSTEP] rw [ih] [GOAL] case a.add_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x x' y : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ descFunLift F s (add x y) = descFunLift F s (add x' y) [PROOFSTEP] | add_1 x x' y r ih => dsimp; rw [ih] [GOAL] case a.add_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x x' y : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ descFunLift F s (add x y) = descFunLift F s (add x' y) [PROOFSTEP] dsimp [GOAL] case a.add_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x x' y : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ descFunLift F s x + descFunLift F s y = descFunLift F s x' + descFunLift F s y [PROOFSTEP] rw [ih] [GOAL] case a.add_2 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y y' : Prequotient F r : Relation F y y' ih : descFunLift F s y = descFunLift F s y' ⊢ descFunLift F s (add x y) = descFunLift F s (add x y') [PROOFSTEP] | add_2 x y y' r ih => dsimp; rw [ih] [GOAL] case a.add_2 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y y' : Prequotient F r : Relation F y y' ih : descFunLift F s y = descFunLift F s y' ⊢ descFunLift F s (add x y) = descFunLift F s (add x y') [PROOFSTEP] dsimp [GOAL] case a.add_2 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y y' : Prequotient F r : Relation F y y' ih : descFunLift F s y = descFunLift F s y' ⊢ descFunLift F s x + descFunLift F s y = descFunLift F s x + descFunLift F s y' [PROOFSTEP] rw [ih] [GOAL] case a.mul_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x x' y : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ descFunLift F s (mul x y) = descFunLift F s (mul x' y) [PROOFSTEP] | mul_1 x x' y r ih => dsimp; rw [ih] [GOAL] case a.mul_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x x' y : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ descFunLift F s (mul x y) = descFunLift F s (mul x' y) [PROOFSTEP] dsimp [GOAL] case a.mul_1 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x x' y : Prequotient F r : Relation F x x' ih : descFunLift F s x = descFunLift F s x' ⊢ descFunLift F s x * descFunLift F s y = descFunLift F s x' * descFunLift F s y [PROOFSTEP] rw [ih] [GOAL] case a.mul_2 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y y' : Prequotient F r : Relation F y y' ih : descFunLift F s y = descFunLift F s y' ⊢ descFunLift F s (mul x y) = descFunLift F s (mul x y') [PROOFSTEP] | mul_2 x y y' r ih => dsimp; rw [ih] [GOAL] case a.mul_2 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y y' : Prequotient F r : Relation F y y' ih : descFunLift F s y = descFunLift F s y' ⊢ descFunLift F s (mul x y) = descFunLift F s (mul x y') [PROOFSTEP] dsimp [GOAL] case a.mul_2 J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y y' : Prequotient F r : Relation F y y' ih : descFunLift F s y = descFunLift F s y' ⊢ descFunLift F s x * descFunLift F s y = descFunLift F s x * descFunLift F s y' [PROOFSTEP] rw [ih] [GOAL] case a.zero_add J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (add zero x) = descFunLift F s x [PROOFSTEP] | zero_add x => dsimp; rw [zero_add] [GOAL] case a.zero_add J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (add zero x) = descFunLift F s x [PROOFSTEP] dsimp [GOAL] case a.zero_add J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ 0 + descFunLift F s x = descFunLift F s x [PROOFSTEP] rw [zero_add] [GOAL] case a.add_zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (add x zero) = descFunLift F s x [PROOFSTEP] | add_zero x => dsimp; rw [add_zero] [GOAL] case a.add_zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (add x zero) = descFunLift F s x [PROOFSTEP] dsimp [GOAL] case a.add_zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s x + 0 = descFunLift F s x [PROOFSTEP] rw [add_zero] [GOAL] case a.one_mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (mul one x) = descFunLift F s x [PROOFSTEP] | one_mul x => dsimp; rw [one_mul] [GOAL] case a.one_mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (mul one x) = descFunLift F s x [PROOFSTEP] dsimp [GOAL] case a.one_mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ 1 * descFunLift F s x = descFunLift F s x [PROOFSTEP] rw [one_mul] [GOAL] case a.mul_one J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (mul x one) = descFunLift F s x [PROOFSTEP] | mul_one x => dsimp; rw [mul_one] [GOAL] case a.mul_one J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (mul x one) = descFunLift F s x [PROOFSTEP] dsimp [GOAL] case a.mul_one J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s x * 1 = descFunLift F s x [PROOFSTEP] rw [mul_one] [GOAL] case a.add_left_neg J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (add (neg x) x) = descFunLift F s zero [PROOFSTEP] | add_left_neg x => dsimp; rw [add_left_neg] [GOAL] case a.add_left_neg J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (add (neg x) x) = descFunLift F s zero [PROOFSTEP] dsimp [GOAL] case a.add_left_neg J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ -descFunLift F s x + descFunLift F s x = 0 [PROOFSTEP] rw [add_left_neg] [GOAL] case a.add_comm J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y : Prequotient F ⊢ descFunLift F s (add x y) = descFunLift F s (add y x) [PROOFSTEP] | add_comm x y => dsimp; rw [add_comm] [GOAL] case a.add_comm J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y : Prequotient F ⊢ descFunLift F s (add x y) = descFunLift F s (add y x) [PROOFSTEP] dsimp [GOAL] case a.add_comm J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y : Prequotient F ⊢ descFunLift F s x + descFunLift F s y = descFunLift F s y + descFunLift F s x [PROOFSTEP] rw [add_comm] [GOAL] case a.mul_comm J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y : Prequotient F ⊢ descFunLift F s (mul x y) = descFunLift F s (mul y x) [PROOFSTEP] | mul_comm x y => dsimp; rw [mul_comm] [GOAL] case a.mul_comm J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y : Prequotient F ⊢ descFunLift F s (mul x y) = descFunLift F s (mul y x) [PROOFSTEP] dsimp [GOAL] case a.mul_comm J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y : Prequotient F ⊢ descFunLift F s x * descFunLift F s y = descFunLift F s y * descFunLift F s x [PROOFSTEP] rw [mul_comm] [GOAL] case a.add_assoc J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s (add (add x y) z) = descFunLift F s (add x (add y z)) [PROOFSTEP] | add_assoc x y z => dsimp; rw [add_assoc] [GOAL] case a.add_assoc J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s (add (add x y) z) = descFunLift F s (add x (add y z)) [PROOFSTEP] dsimp [GOAL] case a.add_assoc J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s x + descFunLift F s y + descFunLift F s z = descFunLift F s x + (descFunLift F s y + descFunLift F s z) [PROOFSTEP] rw [add_assoc] [GOAL] case a.mul_assoc J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s (mul (mul x y) z) = descFunLift F s (mul x (mul y z)) [PROOFSTEP] | mul_assoc x y z => dsimp; rw [mul_assoc] [GOAL] case a.mul_assoc J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s (mul (mul x y) z) = descFunLift F s (mul x (mul y z)) [PROOFSTEP] dsimp [GOAL] case a.mul_assoc J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s x * descFunLift F s y * descFunLift F s z = descFunLift F s x * (descFunLift F s y * descFunLift F s z) [PROOFSTEP] rw [mul_assoc] [GOAL] case a.left_distrib J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s (mul x (add y z)) = descFunLift F s (add (mul x y) (mul x z)) [PROOFSTEP] | left_distrib x y z => dsimp; rw [mul_add] [GOAL] case a.left_distrib J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s (mul x (add y z)) = descFunLift F s (add (mul x y) (mul x z)) [PROOFSTEP] dsimp [GOAL] case a.left_distrib J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s x * (descFunLift F s y + descFunLift F s z) = descFunLift F s x * descFunLift F s y + descFunLift F s x * descFunLift F s z [PROOFSTEP] rw [mul_add] [GOAL] case a.right_distrib J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s (mul (add x y) z) = descFunLift F s (add (mul x z) (mul y z)) [PROOFSTEP] | right_distrib x y z => dsimp; rw [add_mul] [GOAL] case a.right_distrib J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ descFunLift F s (mul (add x y) z) = descFunLift F s (add (mul x z) (mul y z)) [PROOFSTEP] dsimp [GOAL] case a.right_distrib J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y✝ x y z : Prequotient F ⊢ (descFunLift F s x + descFunLift F s y) * descFunLift F s z = descFunLift F s x * descFunLift F s z + descFunLift F s y * descFunLift F s z [PROOFSTEP] rw [add_mul] [GOAL] case a.zero_mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (mul zero x) = descFunLift F s zero [PROOFSTEP] | zero_mul x => dsimp; rw [zero_mul] [GOAL] case a.zero_mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (mul zero x) = descFunLift F s zero [PROOFSTEP] dsimp [GOAL] case a.zero_mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ 0 * descFunLift F s x = 0 [PROOFSTEP] rw [zero_mul] [GOAL] case a.mul_zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (mul x zero) = descFunLift F s zero [PROOFSTEP] | mul_zero x => dsimp; rw [mul_zero] [GOAL] case a.mul_zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s (mul x zero) = descFunLift F s zero [PROOFSTEP] dsimp [GOAL] case a.mul_zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ y x : Prequotient F ⊢ descFunLift F s x * 0 = 0 [PROOFSTEP] rw [mul_zero] [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : ↑(colimit F) ⊢ OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } (x * y) = OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } x * OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } y [PROOFSTEP] exact Quot.induction_on₂ x y fun a b => rfl [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : ↑(colimit F) ⊢ OneHom.toFun (↑{ toOneHom := { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) }, map_mul' := (_ : ∀ (x y : ↑(colimit F)), OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } (x * y) = OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } x * OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } y) }) (x + y) = OneHom.toFun (↑{ toOneHom := { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) }, map_mul' := (_ : ∀ (x y : ↑(colimit F)), OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } (x * y) = OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } x * OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } y) }) x + OneHom.toFun (↑{ toOneHom := { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) }, map_mul' := (_ : ∀ (x y : ↑(colimit F)), OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } (x * y) = OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } x * OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } y) }) y [PROOFSTEP] refine Quot.induction_on₂ x y fun a b => ?_ [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : ↑(colimit F) a b : Prequotient F ⊢ OneHom.toFun (↑{ toOneHom := { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) }, map_mul' := (_ : ∀ (x y : ↑(colimit F)), OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } (x * y) = OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } x * OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } y) }) (Quot.mk Setoid.r a + Quot.mk Setoid.r b) = OneHom.toFun (↑{ toOneHom := { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) }, map_mul' := (_ : ∀ (x y : ↑(colimit F)), OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } (x * y) = OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } x * OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } y) }) (Quot.mk Setoid.r a) + OneHom.toFun (↑{ toOneHom := { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) }, map_mul' := (_ : ∀ (x y : ↑(colimit F)), OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } (x * y) = OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } x * OneHom.toFun { toFun := descFun F s, map_one' := (_ : descFun F s 1 = descFun F s 1) } y) }) (Quot.mk Setoid.r b) [PROOFSTEP] dsimp [descFun, (· + ·)] [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : ↑(colimit F) a b : Prequotient F ⊢ Quot.lift (descFunLift F s) (_ : ∀ (x y : Prequotient F), Setoid.r x y → descFunLift F s x = descFunLift F s y) (Add.add (Quot.mk Setoid.r a) (Quot.mk Setoid.r b)) = Add.add (descFunLift F s a) (descFunLift F s b) [PROOFSTEP] rw [← quot_add] [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x y : ↑(colimit F) a b : Prequotient F ⊢ Quot.lift (descFunLift F s) (_ : ∀ (x y : Prequotient F), Setoid.r x y → descFunLift F s x = descFunLift F s y) (Quot.mk Setoid.r (add a b)) = Add.add (descFunLift F s a) (descFunLift F s b) [PROOFSTEP] rfl [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F m : (colimitCocone F).pt ⟶ s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x : ↑(colimitCocone F).pt ⊢ ↑m x = ↑((fun s => descMorphism F s) s) x [PROOFSTEP] change (colimitCocone F).pt →+* s.pt at m [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j ⊢ ↑m x = ↑((fun s => descMorphism F s) s) x [PROOFSTEP] refine Quot.inductionOn x ?_ [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j ⊢ ∀ (a : Prequotient F), ↑m (Quot.mk Setoid.r a) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r a) [PROOFSTEP] intro x [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x : Prequotient F ⊢ ↑m (Quot.mk Setoid.r x) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r x) [PROOFSTEP] induction x with | zero => erw [quot_zero, map_zero (f := m), (descMorphism F s).map_zero] | one => erw [quot_one, map_one (f := m), (descMorphism F s).map_one] | neg x ih => erw [quot_neg, map_neg (f := m), (descMorphism F s).map_neg, ih] | of j x => exact congr_fun (congr_arg (fun f : F.obj j ⟶ s.pt => (f : F.obj j → s.pt)) (w j)) x | add x y ih_x ih_y => erw [quot_add, map_add (f := m), (descMorphism F s).map_add, ih_x, ih_y] | mul x y ih_x ih_y => erw [quot_mul, map_mul (f := m), (descMorphism F s).map_mul, ih_x, ih_y] [GOAL] J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x : Prequotient F ⊢ ↑m (Quot.mk Setoid.r x) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r x) [PROOFSTEP] induction x with | zero => erw [quot_zero, map_zero (f := m), (descMorphism F s).map_zero] | one => erw [quot_one, map_one (f := m), (descMorphism F s).map_one] | neg x ih => erw [quot_neg, map_neg (f := m), (descMorphism F s).map_neg, ih] | of j x => exact congr_fun (congr_arg (fun f : F.obj j ⟶ s.pt => (f : F.obj j → s.pt)) (w j)) x | add x y ih_x ih_y => erw [quot_add, map_add (f := m), (descMorphism F s).map_add, ih_x, ih_y] | mul x y ih_x ih_y => erw [quot_mul, map_mul (f := m), (descMorphism F s).map_mul, ih_x, ih_y] [GOAL] case zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j ⊢ ↑m (Quot.mk Setoid.r zero) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r zero) [PROOFSTEP] | zero => erw [quot_zero, map_zero (f := m), (descMorphism F s).map_zero] [GOAL] case zero J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j ⊢ ↑m (Quot.mk Setoid.r zero) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r zero) [PROOFSTEP] erw [quot_zero, map_zero (f := m), (descMorphism F s).map_zero] [GOAL] case one J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j ⊢ ↑m (Quot.mk Setoid.r one) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r one) [PROOFSTEP] | one => erw [quot_one, map_one (f := m), (descMorphism F s).map_one] [GOAL] case one J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j ⊢ ↑m (Quot.mk Setoid.r one) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r one) [PROOFSTEP] erw [quot_one, map_one (f := m), (descMorphism F s).map_one] [GOAL] case neg J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x : Prequotient F ih : ↑m (Quot.mk Setoid.r x) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r x) ⊢ ↑m (Quot.mk Setoid.r (neg x)) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r (neg x)) [PROOFSTEP] | neg x ih => erw [quot_neg, map_neg (f := m), (descMorphism F s).map_neg, ih] [GOAL] case neg J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x : Prequotient F ih : ↑m (Quot.mk Setoid.r x) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r x) ⊢ ↑m (Quot.mk Setoid.r (neg x)) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r (neg x)) [PROOFSTEP] erw [quot_neg, map_neg (f := m), (descMorphism F s).map_neg, ih] [GOAL] case of J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j j : J x : ↑(F.obj j) ⊢ ↑m (Quot.mk Setoid.r (Prequotient.of j x)) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r (Prequotient.of j x)) [PROOFSTEP] | of j x => exact congr_fun (congr_arg (fun f : F.obj j ⟶ s.pt => (f : F.obj j → s.pt)) (w j)) x [GOAL] case of J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j j : J x : ↑(F.obj j) ⊢ ↑m (Quot.mk Setoid.r (Prequotient.of j x)) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r (Prequotient.of j x)) [PROOFSTEP] exact congr_fun (congr_arg (fun f : F.obj j ⟶ s.pt => (f : F.obj j → s.pt)) (w j)) x [GOAL] case add J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x y : Prequotient F ih_x : ↑m (Quot.mk Setoid.r x) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r x) ih_y : ↑m (Quot.mk Setoid.r y) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r y) ⊢ ↑m (Quot.mk Setoid.r (add x y)) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r (add x y)) [PROOFSTEP] | add x y ih_x ih_y => erw [quot_add, map_add (f := m), (descMorphism F s).map_add, ih_x, ih_y] [GOAL] case add J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x y : Prequotient F ih_x : ↑m (Quot.mk Setoid.r x) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r x) ih_y : ↑m (Quot.mk Setoid.r y) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r y) ⊢ ↑m (Quot.mk Setoid.r (add x y)) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r (add x y)) [PROOFSTEP] erw [quot_add, map_add (f := m), (descMorphism F s).map_add, ih_x, ih_y] [GOAL] case mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x y : Prequotient F ih_x : ↑m (Quot.mk Setoid.r x) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r x) ih_y : ↑m (Quot.mk Setoid.r y) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r y) ⊢ ↑m (Quot.mk Setoid.r (mul x y)) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r (mul x y)) [PROOFSTEP] | mul x y ih_x ih_y => erw [quot_mul, map_mul (f := m), (descMorphism F s).map_mul, ih_x, ih_y] [GOAL] case mul J : Type v inst✝ : SmallCategory J F : J ⥤ CommRingCat s : Cocone F x✝ : ↑(colimitCocone F).pt m : ↑(colimitCocone F).pt →+* ↑s.pt w : ∀ (j : J), NatTrans.app (colimitCocone F).ι j ≫ m = NatTrans.app s.ι j x y : Prequotient F ih_x : ↑m (Quot.mk Setoid.r x) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r x) ih_y : ↑m (Quot.mk Setoid.r y) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r y) ⊢ ↑m (Quot.mk Setoid.r (mul x y)) = ↑((fun s => descMorphism F s) s) (Quot.mk Setoid.r (mul x y)) [PROOFSTEP] erw [quot_mul, map_mul (f := m), (descMorphism F s).map_mul, ih_x, ih_y]
(* Author: Alexander Maletzky *) section \<open>Preliminaries\<close> theory Dube_Prelims imports Groebner_Bases.General begin subsection \<open>Sets\<close> lemma card_geq_ex_subset: assumes "card A \<ge> n" obtains B where "card B = n" and "B \<subseteq> A" using assms proof (induct n arbitrary: thesis) case base: 0 show ?case proof (rule base(1)) show "card {} = 0" by simp next show "{} \<subseteq> A" .. qed next case ind: (Suc n) from ind(3) have "n < card A" by simp obtain B where card: "card B = n" and "B \<subseteq> A" proof (rule ind(1)) from \<open>n < card A\<close> show "n \<le> card A" by simp qed from \<open>n < card A\<close> have "card A \<noteq> 0" by simp with card.infinite[of A] have "finite A" by blast let ?C = "A - B" have "?C \<noteq> {}" proof assume "A - B = {}" hence "A \<subseteq> B" by simp from this \<open>B \<subseteq> A\<close> have "A = B" .. from \<open>n < card A\<close> show False unfolding \<open>A = B\<close> card by simp qed then obtain c where "c \<in> ?C" by auto hence "c \<notin> B" by simp hence "B - {c} = B" by simp show ?case proof (rule ind(2)) thm card.insert_remove have "card (B \<union> {c}) = card (insert c B)" by simp also have "... = Suc (card (B - {c}))" by (rule card.insert_remove, rule finite_subset, fact \<open>B \<subseteq> A\<close>, fact) finally show "card (B \<union> {c}) = Suc n" unfolding \<open>B - {c} = B\<close> card . next show "B \<union> {c} \<subseteq> A" unfolding Un_subset_iff proof (intro conjI, fact) from \<open>c \<in> ?C\<close> show "{c} \<subseteq> A" by auto qed qed qed lemma card_2_E_1: assumes "card A = 2" and "x \<in> A" obtains y where "x \<noteq> y" and "A = {x, y}" proof - have "A - {x} \<noteq> {}" proof assume "A - {x} = {}" with assms(2) have "A = {x}" by auto hence "card A = 1" by simp with assms show False by simp qed then obtain y where "y \<in> A - {x}" by auto hence "y \<in> A" and "x \<noteq> y" by auto show ?thesis proof show "A = {x, y}" proof (rule sym, rule card_seteq) from assms(1) show "finite A" using card.infinite by fastforce next from \<open>x \<in> A\<close> \<open>y \<in> A\<close> show "{x, y} \<subseteq> A" by simp next from \<open>x \<noteq> y\<close> show "card A \<le> card {x, y}" by (simp add: assms(1)) qed qed fact qed lemma card_2_E: assumes "card A = 2" obtains x y where "x \<noteq> y" and "A = {x, y}" proof - from assms have "A \<noteq> {}" by auto then obtain x where "x \<in> A" by blast with assms obtain y where "x \<noteq> y" and "A = {x, y}" by (rule card_2_E_1) thus ?thesis .. qed subsection \<open>Sums\<close> lemma sum_tail_nat: "0 < b \<Longrightarrow> a \<le> (b::nat) \<Longrightarrow> sum f {a..b} = f b + sum f {a..b - 1}" by (metis One_nat_def Suc_pred add.commute not_le sum.cl_ivl_Suc) lemma sum_atLeast_Suc_shift: "0 < b \<Longrightarrow> a \<le> b \<Longrightarrow> sum f {Suc a..b} = (\<Sum>i=a..b - 1. f (Suc i))" by (metis Suc_pred' sum.shift_bounds_cl_Suc_ivl) lemma sum_split_nat_ivl: "a \<le> Suc j \<Longrightarrow> j \<le> b \<Longrightarrow> sum f {a..j} + sum f {Suc j..b} = sum f {a..b}" by (metis Suc_eq_plus1 le_Suc_ex sum.ub_add_nat) subsection \<open>@{const count_list}\<close> lemma count_list_gr_1_E: assumes "1 < count_list xs x" obtains i j where "i < j" and "j < length xs" and "xs ! i = x" and "xs ! j = x" proof - from assms have "count_list xs x \<noteq> 0" by simp hence "x \<in> set xs" by (simp only: count_list_0_iff not_not) then obtain ys zs where xs: "xs = ys @ x # zs" and "x \<notin> set ys" by (meson split_list_first) hence "count_list xs x = Suc (count_list zs x)" by (simp) with assms have "count_list zs x \<noteq> 0" by simp hence "x \<in> set zs" by (simp only: count_list_0_iff not_not) then obtain j where "j < length zs" and "x = zs ! j" by (metis in_set_conv_nth) show ?thesis proof show "length ys < length ys + Suc j" by simp next from \<open>j < length zs\<close> show "length ys + Suc j < length xs" by (simp add: xs) next show "xs ! length ys = x" by (simp add: xs) next show "xs ! (length ys + Suc j) = x" by (simp only: xs \<open>x = zs ! j\<close> nth_append_length_plus nth_Cons_Suc) qed qed subsection \<open>@{const listset}\<close> lemma listset_Cons: "listset (x # xs) = (\<Union>y\<in>x. (#) y ` listset xs)" by (auto simp: set_Cons_def) lemma listset_ConsI: "y \<in> x \<Longrightarrow> ys' \<in> listset xs \<Longrightarrow> ys = y # ys' \<Longrightarrow> ys \<in> listset (x # xs)" by (simp add: set_Cons_def) lemma listset_ConsE: assumes "ys \<in> listset (x# xs)" obtains y ys' where "y \<in> x" and "ys' \<in> listset xs" and "ys = y # ys'" using assms by (auto simp: set_Cons_def) lemma listsetI: "length ys = length xs \<Longrightarrow> (\<And>i. i < length xs \<Longrightarrow> ys ! i \<in> xs ! i) \<Longrightarrow> ys \<in> listset xs" by (induct ys xs rule: list_induct2) (simp_all, smt Suc_mono list.sel(3) mem_Collect_eq nth_Cons_0 nth_tl set_Cons_def zero_less_Suc) lemma listsetD: assumes "ys \<in> listset xs" shows "length ys = length xs" and "\<And>i. i < length xs \<Longrightarrow> ys ! i \<in> xs ! i" proof - from assms have "length ys = length xs \<and> (\<forall>i<length xs. ys ! i \<in> xs ! i)" proof (induct xs arbitrary: ys) case Nil thus ?case by simp next case (Cons x xs) from Cons.prems obtain y ys' where "y \<in> x" and "ys' \<in> listset xs" and ys: "ys = y # ys'" by (rule listset_ConsE) from this(2) have "length ys' = length xs \<and> (\<forall>i<length xs. ys' ! i \<in> xs ! i)" by (rule Cons.hyps) hence 1: "length ys' = length xs" and 2: "\<And>i. i < length xs \<Longrightarrow> ys' ! i \<in> xs ! i" by simp_all show ?case proof (intro conjI allI impI) fix i assume "i < length (x # xs)" show "ys ! i \<in> (x # xs) ! i" proof (cases i) case 0 with \<open>y \<in> x\<close> show ?thesis by (simp add: ys) next case (Suc j) with \<open>i < length (x # xs)\<close> have "j < length xs" by simp hence "ys' ! j \<in> xs ! j" by (rule 2) thus ?thesis by (simp add: ys \<open>i = Suc j\<close>) qed qed (simp add: ys 1) qed thus "length ys = length xs" and "\<And>i. i < length xs \<Longrightarrow> ys ! i \<in> xs ! i" by simp_all qed lemma listset_singletonI: "a \<in> A \<Longrightarrow> ys = [a] \<Longrightarrow> ys \<in> listset [A]" by simp lemma listset_singletonE: assumes "ys \<in> listset [A]" obtains a where "a \<in> A" and "ys = [a]" using assms by auto lemma listset_doubletonI: "a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> ys = [a, b] \<Longrightarrow> ys \<in> listset [A, B]" by (simp add: set_Cons_def) lemma listset_doubletonE: assumes "ys \<in> listset [A, B]" obtains a b where "a \<in> A" and "b \<in> B" and "ys = [a, b]" using assms by (auto simp: set_Cons_def) lemma listset_appendI: "ys1 \<in> listset xs1 \<Longrightarrow> ys2 \<in> listset xs2 \<Longrightarrow> ys = ys1 @ ys2 \<Longrightarrow> ys \<in> listset (xs1 @ xs2)" by (induct xs1 arbitrary: ys ys1 ys2) (simp, auto simp del: listset.simps elim!: listset_ConsE intro!: listset_ConsI) lemma listset_appendE: assumes "ys \<in> listset (xs1 @ xs2)" obtains ys1 ys2 where "ys1 \<in> listset xs1" and "ys2 \<in> listset xs2" and "ys = ys1 @ ys2" using assms proof (induct xs1 arbitrary: thesis ys) case Nil have "[] \<in> listset []" by simp moreover from Nil(2) have "ys \<in> listset xs2" by simp ultimately show ?case by (rule Nil) simp next case (Cons x xs1) from Cons.prems(2) have "ys \<in> listset (x # (xs1 @ xs2))" by simp then obtain y ys' where "y \<in> x" and "ys' \<in> listset (xs1 @ xs2)" and ys: "ys = y # ys'" by (rule listset_ConsE) from _ this(2) obtain ys1 ys2 where ys1: "ys1 \<in> listset xs1" and "ys2 \<in> listset xs2" and ys': "ys' = ys1 @ ys2" by (rule Cons.hyps) show ?case proof (rule Cons.prems) from \<open>y \<in> x\<close> ys1 refl show "y # ys1 \<in> listset (x # xs1)" by (rule listset_ConsI) next show "ys = (y # ys1) @ ys2" by (simp add: ys ys') qed fact qed lemma listset_map_imageI: "ys' \<in> listset xs \<Longrightarrow> ys = map f ys' \<Longrightarrow> ys \<in> listset (map ((`) f) xs)" by (induct xs arbitrary: ys ys') (simp, auto simp del: listset.simps elim!: listset_ConsE intro!: listset_ConsI) lemma listset_map_imageE: assumes "ys \<in> listset (map ((`) f) xs)" obtains ys' where "ys' \<in> listset xs" and "ys = map f ys'" using assms proof (induct xs arbitrary: thesis ys) case Nil from Nil(2) have "ys = map f []" by simp with _ show ?case by (rule Nil) simp next case (Cons x xs) from Cons.prems(2) have "ys \<in> listset (f ` x # map ((`) f) xs)" by simp then obtain y ys' where "y \<in> f ` x" and "ys' \<in> listset (map ((`) f) xs)" and ys: "ys = y # ys'" by (rule listset_ConsE) from _ this(2) obtain ys1 where ys1: "ys1 \<in> listset xs" and ys': "ys' = map f ys1" by (rule Cons.hyps) from \<open>y \<in> f ` x\<close> obtain y1 where "y1 \<in> x" and y: "y = f y1" .. show ?case proof (rule Cons.prems) from \<open>y1 \<in> x\<close> ys1 refl show "y1 # ys1 \<in> listset (x # xs)" by (rule listset_ConsI) qed (simp add: ys ys' y) qed lemma listset_permE: assumes "ys \<in> listset xs" and "bij_betw f {..<length xs} {..<length xs'}" and "\<And>i. i < length xs \<Longrightarrow> xs' ! i = xs ! f i" obtains ys' where "ys' \<in> listset xs'" and "length ys' = length ys" and "\<And>i. i < length ys \<Longrightarrow> ys' ! i = ys ! f i" proof - from assms(1) have len_ys: "length ys = length xs" by (rule listsetD) from assms(2) have "card {..<length xs} = card {..<length xs'}" by (rule bij_betw_same_card) hence len_xs: "length xs = length xs'" by simp define ys' where "ys' = map (\<lambda>i. ys ! (f i)) [0..<length ys]" have 1: "ys' ! i = ys ! f i" if "i < length ys" for i using that by (simp add: ys'_def) show ?thesis proof show "ys' \<in> listset xs'" proof (rule listsetI) show "length ys' = length xs'" by (simp add: ys'_def len_ys len_xs) fix i assume "i < length xs'" hence "i < length xs" by (simp only: len_xs) hence "i < length ys" by (simp only: len_ys) hence "ys' ! i = ys ! (f i)" by (rule 1) also from assms(1) have "\<dots> \<in> xs ! (f i)" proof (rule listsetD) from \<open>i < length xs\<close> have "i \<in> {..<length xs}" by simp hence "f i \<in> f ` {..<length xs}" by (rule imageI) also from assms(2) have "\<dots> = {..<length xs'}" by (simp add: bij_betw_def) finally show "f i < length xs" by (simp add: len_xs) qed also have "\<dots> = xs' ! i" by (rule sym) (rule assms(3), fact) finally show "ys' ! i \<in> xs' ! i" . qed next show "length ys' = length ys" by (simp add: ys'_def) qed (rule 1) qed lemma listset_closed_map: assumes "ys \<in> listset xs" and "\<And>x y. x \<in> set xs \<Longrightarrow> y \<in> x \<Longrightarrow> f y \<in> x" shows "map f ys \<in> listset xs" using assms proof (induct xs arbitrary: ys) case Nil from Nil(1) show ?case by simp next case (Cons x xs) from Cons.prems(1) obtain y ys' where "y \<in> x" and "ys' \<in> listset xs" and ys: "ys = y # ys'" by (rule listset_ConsE) show ?case proof (rule listset_ConsI) from _ \<open>y \<in> x\<close> show "f y \<in> x" by (rule Cons.prems) simp next show "map f ys' \<in> listset xs" proof (rule Cons.hyps) fix x0 y0 assume "x0 \<in> set xs" hence "x0 \<in> set (x # xs)" by simp moreover assume "y0 \<in> x0" ultimately show "f y0 \<in> x0" by (rule Cons.prems) qed fact qed (simp add: ys) qed lemma listset_closed_map2: assumes "ys1 \<in> listset xs" and "ys2 \<in> listset xs" and "\<And>x y1 y2. x \<in> set xs \<Longrightarrow> y1 \<in> x \<Longrightarrow> y2 \<in> x \<Longrightarrow> f y1 y2 \<in> x" shows "map2 f ys1 ys2 \<in> listset xs" using assms proof (induct xs arbitrary: ys1 ys2) case Nil from Nil(1) show ?case by simp next case (Cons x xs) from Cons.prems(1) obtain y1 ys1' where "y1 \<in> x" and "ys1' \<in> listset xs" and ys1: "ys1 = y1 # ys1'" by (rule listset_ConsE) from Cons.prems(2) obtain y2 ys2' where "y2 \<in> x" and "ys2' \<in> listset xs" and ys2: "ys2 = y2 # ys2'" by (rule listset_ConsE) show ?case proof (rule listset_ConsI) from _ \<open>y1 \<in> x\<close> \<open>y2 \<in> x\<close> show "f y1 y2 \<in> x" by (rule Cons.prems) simp next show "map2 f ys1' ys2' \<in> listset xs" proof (rule Cons.hyps) fix x' y1' y2' assume "x' \<in> set xs" hence "x' \<in> set (x # xs)" by simp moreover assume "y1' \<in> x'" and "y2' \<in> x'" ultimately show "f y1' y2' \<in> x'" by (rule Cons.prems) qed fact+ qed (simp add: ys1 ys2) qed lemma listset_empty_iff: "listset xs = {} \<longleftrightarrow> {} \<in> set xs" by (induct xs) (auto simp: listset_Cons simp del: listset.simps(2)) lemma listset_mono: assumes "length xs = length ys" and "\<And>i. i < length ys \<Longrightarrow> xs ! i \<subseteq> ys ! i" shows "listset xs \<subseteq> listset ys" using assms proof (induct xs ys rule: list_induct2) case Nil show ?case by simp next case (Cons x xs y ys) show ?case proof fix zs' assume "zs' \<in> listset (x # xs)" then obtain z zs where "z \<in> x" and zs: "zs \<in> listset xs" and zs': "zs' = z # zs" by (rule listset_ConsE) have "0 < length (y # ys)" by simp hence "(x # xs) ! 0 \<subseteq> (y # ys) ! 0" by (rule Cons.prems) hence "x \<subseteq> y" by simp with \<open>z \<in> x\<close> have "z \<in> y" .. moreover from zs have "zs \<in> listset ys" proof show "listset xs \<subseteq> listset ys" proof (rule Cons.hyps) fix i assume "i < length ys" hence "Suc i < length (y # ys)" by simp hence "(x # xs) ! Suc i \<subseteq> (y # ys) ! Suc i" by (rule Cons.prems) thus "xs ! i \<subseteq> ys ! i" by simp qed qed ultimately show "zs' \<in> listset (y # ys)" using zs' by (rule listset_ConsI) qed qed end (* theory *)
module Main ( main ) where import Debug.Trace import Codec.Wav (importFile) import Data.Audio (Audio(..)) import Data.Array.Unboxed (elems, assocs) import Data.Array.IArray (Array(..), listArray, array) import Data.Complex (magnitude) import Data.Int (Int64, Int32, Int16, Int8) import Common (importantFrequencies, breakChunks, slice) import SongId (ft, mapChunk2Freqs, chunkIdentifier) type WordSize = Int32 chunkSize = 5000 file = "" main :: IO () main = do input <- importFile file song_dft <- case input :: Either String (Audio WordSize) of Left err -> do putStrLn err return [(array (0,0) [])] Right a@(Audio _ _ samples) -> return (ft chunkSize samples) putStrLn $ show (length song_dft) ++ " " ++ show (length . elems $ head song_dft) let ys = map (mapChunk2Freqs . elems) song_dft let freqs = importantFrequencies 5 (8 * chunkSize `quot` 50 `quot` 2) let chunks = map (chunkIdentifier freqs) ys foldl (\acc x -> acc >> print x) (return ()) $ chunks
[STATEMENT] lemma ta_lang_to_gta_lang [simp]: "ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A>" (is "?Ls = ?Rs") [PROOF STATE] proof (prove) goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] { [PROOF STATE] proof (state) goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] fix t [PROOF STATE] proof (state) goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] assume "t \<in> ?Ls" [PROOF STATE] proof (state) this: t \<in> ta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] from ta_langE[OF this] [PROOF STATE] proof (chain) picking this: (\<And>t' q. \<lbrakk>ground t'; q |\<in>| Q; q |\<in>| ta_der \<A> t'; t = adapt_vars t'\<rbrakk> \<Longrightarrow> ?thesis) \<Longrightarrow> ?thesis [PROOF STEP] obtain q t' where "ground t'" "q |\<in>| Q" "q |\<in>| ta_der \<A> t'" "t = adapt_vars t'" [PROOF STATE] proof (prove) using this: (\<And>t' q. \<lbrakk>ground t'; q |\<in>| Q; q |\<in>| ta_der \<A> t'; t = adapt_vars t'\<rbrakk> \<Longrightarrow> ?thesis) \<Longrightarrow> ?thesis goal (1 subgoal): 1. (\<And>t' q. \<lbrakk>ground t'; q |\<in>| Q; q |\<in>| ta_der \<A> t'; t = adapt_vars t'\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by blast [PROOF STATE] proof (state) this: ground t' q |\<in>| Q q |\<in>| ta_der \<A> t' t = adapt_vars t' goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] then [PROOF STATE] proof (chain) picking this: ground t' q |\<in>| Q q |\<in>| ta_der \<A> t' t = adapt_vars t' [PROOF STEP] have "t \<in> ?Rs" [PROOF STATE] proof (prove) using this: ground t' q |\<in>| Q q |\<in>| ta_der \<A> t' t = adapt_vars t' goal (1 subgoal): 1. t \<in> term_of_gterm ` gta_lang Q \<A> [PROOF STEP] unfolding gta_lang_def gta_der_def [PROOF STATE] proof (prove) using this: ground t' q |\<in>| Q q |\<in>| ta_der \<A> t' t = adapt_vars t' goal (1 subgoal): 1. t \<in> term_of_gterm ` {t. Q |\<inter>| ta_der \<A> (term_of_gterm t) \<noteq> {||}} [PROOF STEP] by (auto simp: image_iff gterm_of_term_inv' intro!: exI[of _ "gterm_of_term t'"]) [PROOF STATE] proof (state) this: t \<in> term_of_gterm ` gta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] } [PROOF STATE] proof (state) this: ?t2 \<in> ta_lang Q \<A> \<Longrightarrow> ?t2 \<in> term_of_gterm ` gta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] moreover [PROOF STATE] proof (state) this: ?t2 \<in> ta_lang Q \<A> \<Longrightarrow> ?t2 \<in> term_of_gterm ` gta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] { [PROOF STATE] proof (state) this: ?t2 \<in> ta_lang Q \<A> \<Longrightarrow> ?t2 \<in> term_of_gterm ` gta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] fix t [PROOF STATE] proof (state) goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] assume "t \<in> ?Rs" [PROOF STATE] proof (state) this: t \<in> term_of_gterm ` gta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] then [PROOF STATE] proof (chain) picking this: t \<in> term_of_gterm ` gta_lang Q \<A> [PROOF STEP] have "t \<in> ?Ls" [PROOF STATE] proof (prove) using this: t \<in> term_of_gterm ` gta_lang Q \<A> goal (1 subgoal): 1. t \<in> ta_lang Q \<A> [PROOF STEP] using ta_langI[OF ground_term_of_gterm _ _ gterm_of_term_inv'[OF ground_term_of_gterm]] [PROOF STATE] proof (prove) using this: t \<in> term_of_gterm ` gta_lang Q \<A> \<lbrakk>?q |\<in>| ?Q; ?q |\<in>| ta_der ?\<A> (term_of_gterm ?s2)\<rbrakk> \<Longrightarrow> term_of_gterm (gterm_of_term (term_of_gterm ?s2)) \<in> ta_lang ?Q ?\<A> goal (1 subgoal): 1. t \<in> ta_lang Q \<A> [PROOF STEP] by (force simp: gta_lang_def gta_der_def) [PROOF STATE] proof (state) this: t \<in> ta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] } [PROOF STATE] proof (state) this: ?t2 \<in> term_of_gterm ` gta_lang Q \<A> \<Longrightarrow> ?t2 \<in> ta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: ?t2 \<in> ta_lang Q \<A> \<Longrightarrow> ?t2 \<in> term_of_gterm ` gta_lang Q \<A> ?t2 \<in> term_of_gterm ` gta_lang Q \<A> \<Longrightarrow> ?t2 \<in> ta_lang Q \<A> [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: ?t2 \<in> ta_lang Q \<A> \<Longrightarrow> ?t2 \<in> term_of_gterm ` gta_lang Q \<A> ?t2 \<in> term_of_gterm ` gta_lang Q \<A> \<Longrightarrow> ?t2 \<in> ta_lang Q \<A> goal (1 subgoal): 1. ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> [PROOF STEP] by blast [PROOF STATE] proof (state) this: ta_lang Q \<A> = term_of_gterm ` gta_lang Q \<A> goal: No subgoals! [PROOF STEP] qed
PROGRAM Reducedriver use num_types use vector_matrix_utilities use rational_mathematics use cwrapper implicit none real(dp) rand(9), R(3,3), Out(3,3) integer L(3,3), H(3,3),S(3,3), T1(2,2), T2(2,2), T3(2,2) integer i,j,sz sz=10 call random_seed() !do i=1,10 call random_number(rand) print *, "starting new matrix" R = reshape((rand*sz)-sz/2,(/3,3/)) !call reduce_to_shortest_basis(R,out,1e-12_dp) call aflow_reduce_to_shortest_basis(R,out,1e-12_dp) !H = reshape((/(/1,0,0/),(/0,3,0/),(/0,-2,2/)/),(/3,3/)) !call SmithNormalForm(H,L,S,R) !enddo do i = 1,3 write(*,'(2(3(f7.3,1x)))') R(:,i), Out(:,i) enddo ENDPROGRAM Reducedriver
\section*{Chapter 7: Deriving a Generic Algorithm} \paragraph{Exercise 7.1} How many additions are needed to compute \texttt{fib0(n)}? \begin{proof}[Answer] Let $\alpha(n)$ be the number of additions needed to compute \texttt{fib0(}$n$\texttt{)}. $\alpha(n)$ can be characterized by the following recurrence relation: $$ \alpha(n) = \begin{cases} 0 & \textrm{if } n \leq 1 \\ 1 + \alpha(n-1) + \alpha(n-2) & \textrm{if } n \geq 2 \end{cases} $$ It can be shown by induction on $n$ that $\alpha(n) = F_{n+1} - 1$. In fact, if $n \leq 1$, $\alpha(n) = 0 = F_{n+1} - 1$, since by definition $F_1 = F_2 = 1$. For $n \geq 2$, \begin{eqnarray*} \alpha(n) &=& 1 + \alpha(n-1) + \alpha(n-2) \\ &=& 1 + (F_n - 1) + (F_{n-1} - 1) \\ &=& (F_n + F_{n-1}) - 1 \\ &=& F_{n+1} - 1 \end{eqnarray*} Thus, the number of additions we seek is $\alpha(n) = F_{n+1} -1 \in \Theta(\varphi^n)$, where $\varphi$ is the golden ratio. \end{proof}
% AUTHORSHIP % Math Lead & Primary Developer: Connor Meehan <[email protected]> % Secondary Developer: Stephen Meehan <[email protected]> % Bioinformatics Lead: Wayne Moore <[email protected]> % Funded by the Herzenberg Lab at Stanford University % License: BSD 3 clause % function [rows, cols, vals] = compute_membership_strengths(knn_indices, knn_dists, sigmas, rhos, same_set) %COMPUTE_MEMBERSHIP_STRENGTHS Construct the membership strength data for % the 1-skeleton of each local fuzzy simplicial set -- this is formed as a % sparse matrix where each row is a local fuzzy simplicial set, with a % membership strength for the 1-simplex to each other data point. % % [rows, cols, vals] = COMPUTE_MEMBERSHIP_STRENGTHS(knn_indices, knn_dists, sigmas, rhos, same_set) % % Parameters % ---------- % knn_indices: array of size (n_samples, n_neighbors) % The indices on the "n_neighbors" closest points in the dataset. % % knn_dists: array of size (n_samples, n_neighbors) % The distances to the "n_neighbors" closest points in the dataset. % % sigmas: array of size (n_samples, 1) % The normalization factor derived from the metric tensor approximation. % % rhos: array of size (n_samples, 1) % The local connectivity adjustment. % % Returns % ------- % rows: array of size (n_samples*n_neighbors, 1) % Row data for the resulting sparse matrix. % % cols: array of size (n_samples*n_neighbors, 1) % Column data for the resulting sparse matrix. % % vals: array of size (n_samples*n_neighbors, 1) % Entries for the resulting sparse matrix. if nargin < 5 same_set = true; end [n_samples, n_neighbors] = size(knn_indices); knn_fail = knn_indices == -1; rows = repmat((1:n_samples)', 1, n_neighbors); rows(knn_fail) = NaN; rows = rows'; rows = rows(:); cols = knn_indices; cols(knn_fail) = NaN; cols = cols'; cols = cols(:); d = knn_dists - rhos; vals = exp(-max(0, d./repmat(sigmas, [1 n_neighbors]))); if same_set itself = knn_indices == repmat((1:n_samples)', 1, n_neighbors); vals(itself) = 0; end vals(knn_fail) = NaN; vals = vals'; vals = vals(:);
State Before: A B : GroupCat f : A ⟶ B x : X' y : ↑(Set.range (Function.swap leftCoset (MonoidHom.range f).toSubmonoid.toSubsemigroup.carrier)) ⊢ 1 • fromCoset y = fromCoset y State After: A B : GroupCat f : A ⟶ B x : X' y : ↑(Set.range (Function.swap leftCoset (MonoidHom.range f).toSubmonoid.toSubsemigroup.carrier)) ⊢ fromCoset { val := 1 *l ↑y, property := (_ : 1 *l ↑y ∈ Set.range (Function.swap leftCoset (MonoidHom.range f).toSubmonoid.toSubsemigroup.carrier)) } = fromCoset y Tactic: change fromCoset _ = fromCoset _ State Before: A B : GroupCat f : A ⟶ B x : X' y : ↑(Set.range (Function.swap leftCoset (MonoidHom.range f).toSubmonoid.toSubsemigroup.carrier)) ⊢ fromCoset { val := 1 *l ↑y, property := (_ : 1 *l ↑y ∈ Set.range (Function.swap leftCoset (MonoidHom.range f).toSubmonoid.toSubsemigroup.carrier)) } = fromCoset y State After: no goals Tactic: simp only [one_leftCoset, Subtype.ext_iff_val]
(* Title: Conservation of CSP Noninterference Security under Sequential Composition Author: Pasquale Noce Security Certification Specialist at Arjo Systems, Italy pasquale dot noce dot lavoro at gmail dot com pasquale dot noce at arjosystems dot com *) section "Propaedeutic definitions and lemmas" theory Propaedeutics imports Noninterference_Ipurge_Unwinding.DeterministicProcesses begin text \<open> \null \emph{To our Lord Jesus Christ, my dear parents, and my "little" sister,} \emph{for the immense love with which they surround me.} \null In his outstanding work on Communicating Sequential Processes \<^cite>\<open>"R4"\<close>, Hoare has defined two fundamental binary operations allowing to compose the input processes into another, typically more complex, process: sequential composition and concurrent composition. Particularly, the output of the former operation is a process that initially behaves like the first operand, and then like the second operand once the execution of the first one has terminated successfully, as long as it does. In order to distinguish it from deadlock, successful termination is regarded as a special event in the process alphabet (required to be the same for both the input processes and the output one). This paper formalizes Hoare's definition of sequential composition and proves, in the general case of a possibly intransitive policy, that CSP noninterference security \<^cite>\<open>"R2"\<close> is conserved under this operation, viz. the security of both of the input processes implies that of the output process. This property is conditional on two nontrivial assumptions. The first assumption is that the policy do not allow successful termination to be affected by confidential events, viz. by other events not allowed to affect some event in the process alphabet. The second assumption is that successful termination do not occur as an alternative to other events in the traces of the first operand, viz. that whenever the process can terminate successfully, it cannot engage in any other event. Both of these assumptions are shown, by means of counterexamples, to be necessary for the theorem to hold. From the above sketch of the sequential composition of two processes @{term P} and @{term Q}, notwithstanding its informal character, it clearly follows that any failure of the output process is either a failure of @{term P} (case A), or a pair @{term "(xs @ ys, Y)"}, where @{term xs} is a trace of @{term P} and @{term "(ys, Y)"} is a failure of @{term Q} (case B). On the other hand, according to the definition of security given in \<^cite>\<open>"R2"\<close>, the output process is secure just in case, for each of its failures, any event @{term x} contained in the failure trace can be removed from the trace, or inserted into the trace of another failure after the same previous events as in the original trace, and the resulting pair is still a failure of the process, provided that the future of @{term x} is deprived of the events that may be affected by @{term x}. In case A, this transformation is performed on a failure of process @{term P}; being it secure, the result is still a failure of @{term P}, and then of the output process. In case B, the transformation may involve either @{term ys} alone, or both @{term xs} and @{term ys}, depending on the position at which @{term x} is removed or inserted. In the former subcase, being @{term Q} secure, the result has the form @{term "(xs @ ys', Y')"} where @{term "(ys', Y')"} is a failure of @{term Q}, thus it is still a failure of the output process. In the latter subcase, @{term ys} has to be deprived of the events that may be affected by @{term x}, as well as by any event affected by @{term x} in the involved portion of @{term xs}, and a similar transformation applies to @{term Y}. In order that the output process be secure, the resulting pair @{term "(ys'', Y'')"} must still be a failure of @{term Q}, so that the pair @{term "(xs' @ ys'', Y'')"}, where @{term xs'} results from the transformation of @{term xs}, be a failure of the output process. The transformations bringing from @{term ys} and @{term Y} to @{term ys''} and @{term Y''} are implemented by the functions @{term ipurge_tr_aux} and @{term ipurge_ref_aux} defined in \<^cite>\<open>"R3"\<close>. Therefore, the proof of the target security conservation theorem requires that of the following lemma: given a process @{term P}, a noninterference policy @{term I}, and an event-domain map @{term D}, if @{term P} is secure with respect to @{term I} and @{term D} and @{term "(xs, X)"} is a failure of @{term P}, then @{term "(ipurge_tr_aux I D U xs, ipurge_ref_aux I D U xs X)"} is still a failure of @{term P}. In other words, the lemma states that the failures of a secure process are closed under intransitive purge. This section contains a proof of such closure lemma, as well as further definitions and lemmas required for the proof of the target theorem. Throughout this paper, the salient points of definitions and proofs are commented; for additional information, cf. Isabelle documentation, particularly \<^cite>\<open>"R6"\<close>, \<^cite>\<open>"R7"\<close>, \<^cite>\<open>"R8"\<close>, and \<^cite>\<open>"R9"\<close>. \<close> subsection "Preliminary propaedeutic lemmas" text \<open> In what follows, some lemmas required for the demonstration of the target closure lemma are proven. Here below is the proof of some properties of functions @{term ipurge_tr} and @{term ipurge_ref}. \null \<close> lemma ipurge_tr_length: "length (ipurge_tr I D u xs) \<le> length xs" by (induction xs rule: rev_induct, simp_all) lemma ipurge_ref_swap: "ipurge_ref I D u xs {x \<in> X. P x} = {x \<in> ipurge_ref I D u xs X. P x}" proof (simp add: ipurge_ref_def) qed blast lemma ipurge_ref_last: "ipurge_ref I D u (xs @ [x]) X = (if (u, D x) \<in> I \<or> (\<exists>v \<in> sinks I D u xs. (v, D x) \<in> I) then ipurge_ref I D u xs {x' \<in> X. (D x, D x') \<notin> I} else ipurge_ref I D u xs X)" proof (cases "(u, D x) \<in> I \<or> (\<exists>v \<in> sinks I D u xs. (v, D x) \<in> I)", simp_all add: ipurge_ref_def) qed blast text \<open> \null Here below is the proof of some properties of function @{term sinks_aux}. \null \<close> lemma sinks_aux_append: "sinks_aux I D U (xs @ ys) = sinks_aux I D (sinks_aux I D U xs) ys" proof (induction ys rule: rev_induct, simp, subst append_assoc [symmetric]) qed (simp del: append_assoc) lemma sinks_aux_union: "sinks_aux I D (U \<union> V) xs = sinks_aux I D U xs \<union> sinks_aux I D V (ipurge_tr_aux I D U xs)" proof (induction xs rule: rev_induct, simp) fix x xs assume A: "sinks_aux I D (U \<union> V) xs = sinks_aux I D U xs \<union> sinks_aux I D V (ipurge_tr_aux I D U xs)" show "sinks_aux I D (U \<union> V) (xs @ [x]) = sinks_aux I D U (xs @ [x]) \<union> sinks_aux I D V (ipurge_tr_aux I D U (xs @ [x]))" proof (cases "\<exists>w \<in> sinks_aux I D (U \<union> V) xs. (w, D x) \<in> I") case True hence "\<exists>w \<in> sinks_aux I D U xs \<union> sinks_aux I D V (ipurge_tr_aux I D U xs). (w, D x) \<in> I" using A by simp hence "(\<exists>w \<in> sinks_aux I D U xs. (w, D x) \<in> I) \<or> (\<exists>w \<in> sinks_aux I D V (ipurge_tr_aux I D U xs). (w, D x) \<in> I)" by blast thus ?thesis using A and True by (cases "\<exists>w \<in> sinks_aux I D U xs. (w, D x) \<in> I", simp_all) next case False hence "\<not> (\<exists>w \<in> sinks_aux I D U xs \<union> sinks_aux I D V (ipurge_tr_aux I D U xs). (w, D x) \<in> I)" using A by simp hence "\<not> (\<exists>w \<in> sinks_aux I D U xs. (w, D x) \<in> I) \<and> \<not> (\<exists>w \<in> sinks_aux I D V (ipurge_tr_aux I D U xs). (w, D x) \<in> I)" by blast thus ?thesis using A and False by simp qed qed lemma sinks_aux_subset_dom: assumes A: "U \<subseteq> V" shows "sinks_aux I D U xs \<subseteq> sinks_aux I D V xs" proof (induction xs rule: rev_induct, simp add: A, rule subsetI) fix x xs w assume B: "sinks_aux I D U xs \<subseteq> sinks_aux I D V xs" and C: "w \<in> sinks_aux I D U (xs @ [x])" show "w \<in> sinks_aux I D V (xs @ [x])" proof (cases "\<exists>u \<in> sinks_aux I D U xs. (u, D x) \<in> I") case True hence "w = D x \<or> w \<in> sinks_aux I D U xs" using C by simp moreover { assume D: "w = D x" obtain u where E: "u \<in> sinks_aux I D U xs" and F: "(u, D x) \<in> I" using True .. have "u \<in> sinks_aux I D V xs" using B and E .. with F have "\<exists>u \<in> sinks_aux I D V xs. (u, D x) \<in> I" .. hence ?thesis using D by simp } moreover { assume "w \<in> sinks_aux I D U xs" with B have "w \<in> sinks_aux I D V xs" .. hence ?thesis by simp } ultimately show ?thesis .. next case False hence "w \<in> sinks_aux I D U xs" using C by simp with B have "w \<in> sinks_aux I D V xs" .. thus ?thesis by simp qed qed lemma sinks_aux_subset_ipurge_tr_aux: "sinks_aux I D U (ipurge_tr_aux I' D' U' xs) \<subseteq> sinks_aux I D U xs" proof (induction xs rule: rev_induct, simp, rule subsetI) fix x xs w assume A: "sinks_aux I D U (ipurge_tr_aux I' D' U' xs) \<subseteq> sinks_aux I D U xs" and B: "w \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' (xs @ [x]))" show "w \<in> sinks_aux I D U (xs @ [x])" proof (cases "\<exists>u \<in> sinks_aux I D U xs. (u, D x) \<in> I", simp_all (no_asm_simp)) from B have "w = D x \<or> w \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs)" proof (cases "\<exists>u' \<in> sinks_aux I' D' U' xs. (u', D' x) \<in> I'", simp_all) qed (cases "\<exists>u \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs). (u, D x) \<in> I", simp_all) moreover { assume "w = D x" hence "w = D x \<or> w \<in> sinks_aux I D U xs" .. } moreover { assume "w \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs)" with A have "w \<in> sinks_aux I D U xs" .. hence "w = D x \<or> w \<in> sinks_aux I D U xs" .. } ultimately show "w = D x \<or> w \<in> sinks_aux I D U xs" .. next assume C: "\<not> (\<exists>u \<in> sinks_aux I D U xs. (u, D x) \<in> I)" have "w \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs)" proof (cases "\<exists>u' \<in> sinks_aux I' D' U' xs. (u', D' x) \<in> I'") case True thus "w \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs)" using B by simp next case False hence "w \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs @ [x])" using B by simp moreover have "\<not> (\<exists>u \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs). (u, D x) \<in> I)" (is "\<not> ?P") proof assume ?P then obtain u where D: "u \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs)" and E: "(u, D x) \<in> I" .. have "u \<in> sinks_aux I D U xs" using A and D .. with E have "\<exists>u \<in> sinks_aux I D U xs. (u, D x) \<in> I" .. thus False using C by contradiction qed ultimately show "w \<in> sinks_aux I D U (ipurge_tr_aux I' D' U' xs)" by simp qed with A show "w \<in> sinks_aux I D U xs" .. qed qed lemma sinks_aux_subset_ipurge_tr: "sinks_aux I D U (ipurge_tr I' D' u' xs) \<subseteq> sinks_aux I D U xs" by (simp add: ipurge_tr_aux_single_dom [symmetric] sinks_aux_subset_ipurge_tr_aux) lemma sinks_aux_member_ipurge_tr_aux [rule_format]: "u \<in> sinks_aux I D (U \<union> V) xs \<longrightarrow> (u, w) \<in> I \<longrightarrow> \<not> (\<exists>v \<in> sinks_aux I D V xs. (v, w) \<in> I) \<longrightarrow> u \<in> sinks_aux I D U (ipurge_tr_aux I D V xs)" proof (induction xs arbitrary: u w rule: rev_induct, (rule_tac [!] impI)+, simp) fix u w assume A: "(u, w) \<in> I" and B: "\<forall>v \<in> V. (v, w) \<notin> I" assume "u \<in> U \<or> u \<in> V" moreover { assume "u \<in> U" } moreover { assume "u \<in> V" with B have "(u, w) \<notin> I" .. hence "u \<in> U" using A by contradiction } ultimately show "u \<in> U" .. next fix x xs u w assume A: "\<And>u w. u \<in> sinks_aux I D (U \<union> V) xs \<longrightarrow> (u, w) \<in> I \<longrightarrow> \<not> (\<exists>v \<in> sinks_aux I D V xs. (v, w) \<in> I) \<longrightarrow> u \<in> sinks_aux I D U (ipurge_tr_aux I D V xs)" and B: "u \<in> sinks_aux I D (U \<union> V) (xs @ [x])" and C: "(u, w) \<in> I" and D: "\<not> (\<exists>v \<in> sinks_aux I D V (xs @ [x]). (v, w) \<in> I)" show "u \<in> sinks_aux I D U (ipurge_tr_aux I D V (xs @ [x]))" proof (cases "\<exists>u' \<in> sinks_aux I D (U \<union> V) xs. (u', D x) \<in> I") case True hence "u = D x \<or> u \<in> sinks_aux I D (U \<union> V) xs" using B by simp moreover { assume E: "u = D x" obtain u' where "u' \<in> sinks_aux I D (U \<union> V) xs" and F: "(u', D x) \<in> I" using True .. moreover have "u' \<in> sinks_aux I D (U \<union> V) xs \<longrightarrow> (u', D x) \<in> I \<longrightarrow> \<not> (\<exists>v \<in> sinks_aux I D V xs. (v, D x) \<in> I) \<longrightarrow> u' \<in> sinks_aux I D U (ipurge_tr_aux I D V xs)" (is "_ \<longrightarrow> _ \<longrightarrow> \<not> ?P \<longrightarrow> ?Q") using A . ultimately have "\<not> ?P \<longrightarrow> ?Q" by simp moreover have "\<not> ?P" proof have "(D x, w) \<in> I" using C and E by simp moreover assume ?P hence "D x \<in> sinks_aux I D V (xs @ [x])" by simp ultimately have "\<exists>v \<in> sinks_aux I D V (xs @ [x]). (v, w) \<in> I" .. moreover have "\<not> (\<exists>v \<in> sinks_aux I D V (xs @ [x]). (v, w) \<in> I)" using D by simp ultimately show False by contradiction qed ultimately have ?Q .. with F have "\<exists>u' \<in> sinks_aux I D U (ipurge_tr_aux I D V xs). (u', D x) \<in> I" .. hence "D x \<in> sinks_aux I D U (ipurge_tr_aux I D V xs @ [x])" by simp moreover have "ipurge_tr_aux I D V xs @ [x] = ipurge_tr_aux I D V (xs @ [x])" using \<open>\<not> ?P\<close> by simp ultimately have ?thesis using E by simp } moreover { assume "u \<in> sinks_aux I D (U \<union> V) xs" moreover have "u \<in> sinks_aux I D (U \<union> V) xs \<longrightarrow> (u, w) \<in> I \<longrightarrow> \<not> (\<exists>v \<in> sinks_aux I D V xs. (v, w) \<in> I) \<longrightarrow> u \<in> sinks_aux I D U (ipurge_tr_aux I D V xs)" (is "_ \<longrightarrow> _ \<longrightarrow> \<not> ?P \<longrightarrow> ?Q") using A . ultimately have "\<not> ?P \<longrightarrow> ?Q" using C by simp moreover have "\<not> ?P" proof assume ?P hence "\<exists>v \<in> sinks_aux I D V (xs @ [x]). (v, w) \<in> I" by simp thus False using D by contradiction qed ultimately have "u \<in> sinks_aux I D U (ipurge_tr_aux I D V xs)" .. hence ?thesis by simp } ultimately show ?thesis .. next case False hence "u \<in> sinks_aux I D (U \<union> V) xs" using B by simp moreover have "u \<in> sinks_aux I D (U \<union> V) xs \<longrightarrow> (u, w) \<in> I \<longrightarrow> \<not> (\<exists>v \<in> sinks_aux I D V xs. (v, w) \<in> I) \<longrightarrow> u \<in> sinks_aux I D U (ipurge_tr_aux I D V xs)" (is "_ \<longrightarrow> _ \<longrightarrow> \<not> ?P \<longrightarrow> ?Q") using A . ultimately have "\<not> ?P \<longrightarrow> ?Q" using C by simp moreover have "\<not> ?P" proof assume ?P hence "\<exists>v \<in> sinks_aux I D V (xs @ [x]). (v, w) \<in> I" by simp thus False using D by contradiction qed ultimately have "u \<in> sinks_aux I D U (ipurge_tr_aux I D V xs)" .. thus ?thesis by simp qed qed lemma sinks_aux_member_ipurge_tr: assumes A: "u \<in> sinks_aux I D (insert v U) xs" and B: "(u, w) \<in> I" and C: "\<not> ((v, w) \<in> I \<or> (\<exists>v' \<in> sinks I D v xs. (v', w) \<in> I))" shows "u \<in> sinks_aux I D U (ipurge_tr I D v xs)" proof (subst ipurge_tr_aux_single_dom [symmetric], rule_tac w = w in sinks_aux_member_ipurge_tr_aux) show "u \<in> sinks_aux I D (U \<union> {v}) xs" using A by simp next show "(u, w) \<in> I" using B . next show "\<not> (\<exists>v' \<in> sinks_aux I D {v} xs. (v', w) \<in> I)" using C by (simp add: sinks_aux_single_dom) qed text \<open> \null Here below is the proof of some properties of functions @{term ipurge_tr_aux} and @{term ipurge_ref_aux}. \null \<close> lemma ipurge_tr_aux_single_event: "ipurge_tr_aux I D U [x] = (if \<exists>v \<in> U. (v, D x) \<in> I then [] else [x])" by (subst (2) append_Nil [symmetric], simp del: append_Nil) lemma ipurge_tr_aux_cons: "ipurge_tr_aux I D U (x # xs) = (if \<exists>u \<in> U. (u, D x) \<in> I then ipurge_tr_aux I D (insert (D x) U) xs else x # ipurge_tr_aux I D U xs)" proof - have "ipurge_tr_aux I D U (x # xs) = ipurge_tr_aux I D U ([x] @ xs)" by simp also have "\<dots> = ipurge_tr_aux I D U [x] @ ipurge_tr_aux I D (sinks_aux I D U [x]) xs" by (simp only: ipurge_tr_aux_append) finally show ?thesis by (simp add: sinks_aux_single_event ipurge_tr_aux_single_event) qed lemma ipurge_tr_aux_union: "ipurge_tr_aux I D (U \<union> V) xs = ipurge_tr_aux I D V (ipurge_tr_aux I D U xs)" proof (induction xs rule: rev_induct, simp) fix x xs assume A: "ipurge_tr_aux I D (U \<union> V) xs = ipurge_tr_aux I D V (ipurge_tr_aux I D U xs)" show "ipurge_tr_aux I D (U \<union> V) (xs @ [x]) = ipurge_tr_aux I D V (ipurge_tr_aux I D U (xs @ [x]))" proof (cases "\<exists>v \<in> sinks_aux I D (U \<union> V) xs. (v, D x) \<in> I") case True hence "\<exists>w \<in> sinks_aux I D U xs \<union> sinks_aux I D V (ipurge_tr_aux I D U xs). (w, D x) \<in> I" by (simp add: sinks_aux_union) hence "(\<exists>w \<in> sinks_aux I D U xs. (w, D x) \<in> I) \<or> (\<exists>w \<in> sinks_aux I D V (ipurge_tr_aux I D U xs). (w, D x) \<in> I)" by blast thus ?thesis using A and True by (cases "\<exists>w \<in> sinks_aux I D U xs. (w, D x) \<in> I", simp_all) next case False hence "\<not> (\<exists>w \<in> sinks_aux I D U xs \<union> sinks_aux I D V (ipurge_tr_aux I D U xs). (w, D x) \<in> I)" by (simp add: sinks_aux_union) hence "\<not> (\<exists>w \<in> sinks_aux I D U xs. (w, D x) \<in> I) \<and> \<not> (\<exists>w \<in> sinks_aux I D V (ipurge_tr_aux I D U xs). (w, D x) \<in> I)" by blast thus ?thesis using A and False by simp qed qed lemma ipurge_tr_aux_insert: "ipurge_tr_aux I D (insert v U) xs = ipurge_tr_aux I D U (ipurge_tr I D v xs)" by (subst insert_is_Un, simp only: ipurge_tr_aux_union ipurge_tr_aux_single_dom) lemma ipurge_ref_aux_subset: "ipurge_ref_aux I D U xs X \<subseteq> X" by (subst ipurge_ref_aux_def, rule subsetI, simp) subsection "Intransitive purge of event sets with trivial base case" text \<open> Here below are the definitions of variants of functions @{term sinks_aux} and @{term ipurge_ref_aux}, respectively named \<open>sinks_aux_less\<close> and \<open>ipurge_ref_aux_less\<close>, such that their base cases in correspondence with an empty input list are trivial, viz. such that @{term "sinks_aux_less I D U [] = {}"} and @{term "ipurge_ref_aux_less I D U [] X = X"}. These functions will prove to be useful in what follows. \null \<close> function sinks_aux_less :: "('d \<times> 'd) set \<Rightarrow> ('a \<Rightarrow> 'd) \<Rightarrow> 'd set \<Rightarrow> 'a list \<Rightarrow> 'd set" where "sinks_aux_less _ _ _ [] = {}" | "sinks_aux_less I D U (xs @ [x]) = (if \<exists>v \<in> U \<union> sinks_aux_less I D U xs. (v, D x) \<in> I then insert (D x) (sinks_aux_less I D U xs) else sinks_aux_less I D U xs)" proof (atomize_elim, simp_all add: split_paired_all) qed (rule rev_cases, rule disjI1, assumption, simp) termination by lexicographic_order definition ipurge_ref_aux_less :: "('d \<times> 'd) set \<Rightarrow> ('a \<Rightarrow> 'd) \<Rightarrow> 'd set \<Rightarrow> 'a list \<Rightarrow> 'a set \<Rightarrow> 'a set" where "ipurge_ref_aux_less I D U xs X \<equiv> {x \<in> X. \<forall>v \<in> sinks_aux_less I D U xs. (v, D x) \<notin> I}" text \<open> \null Here below is the proof of some properties of function @{term sinks_aux_less} used in what follows. \null \<close> lemma sinks_aux_sinks_aux_less: "sinks_aux I D U xs = U \<union> sinks_aux_less I D U xs" by (induction xs rule: rev_induct, simp_all) lemma sinks_aux_less_single_dom: "sinks_aux_less I D {u} xs = sinks I D u xs" by (induction xs rule: rev_induct, simp_all) lemma sinks_aux_less_single_event: "sinks_aux_less I D U [x] = (if \<exists>u \<in> U. (u, D x) \<in> I then {D x} else {})" by (subst append_Nil [symmetric], simp del: append_Nil) lemma sinks_aux_less_append: "sinks_aux_less I D U (xs @ ys) = sinks_aux_less I D U xs \<union> sinks_aux_less I D (U \<union> sinks_aux_less I D U xs) ys" proof (induction ys rule: rev_induct, simp, subst append_assoc [symmetric]) qed (simp del: append_assoc) lemma sinks_aux_less_cons: "sinks_aux_less I D U (x # xs) = (if \<exists>u \<in> U. (u, D x) \<in> I then insert (D x) (sinks_aux_less I D (insert (D x) U) xs) else sinks_aux_less I D U xs)" proof - have "sinks_aux_less I D U (x # xs) = sinks_aux_less I D U ([x] @ xs)" by simp also have "\<dots> = sinks_aux_less I D U [x] \<union> sinks_aux_less I D (U \<union> sinks_aux_less I D U [x]) xs" by (simp only: sinks_aux_less_append) finally show ?thesis by (cases "\<exists>u \<in> U. (u, D x) \<in> I", simp_all add: sinks_aux_less_single_event) qed text \<open> \null Here below is the proof of some properties of function @{term ipurge_ref_aux_less} used in what follows. \null \<close> lemma ipurge_ref_aux_less_last: "ipurge_ref_aux_less I D U (xs @ [x]) X = (if \<exists>v \<in> U \<union> sinks_aux_less I D U xs. (v, D x) \<in> I then ipurge_ref_aux_less I D U xs {x' \<in> X. (D x, D x') \<notin> I} else ipurge_ref_aux_less I D U xs X)" by (cases "\<exists>v \<in> U \<union> sinks_aux_less I D U xs. (v, D x) \<in> I", simp_all add: ipurge_ref_aux_less_def) lemma ipurge_ref_aux_less_nil: "ipurge_ref_aux_less I D U xs (ipurge_ref_aux I D U [] X) = ipurge_ref_aux I D U xs X" proof (simp add: ipurge_ref_aux_def ipurge_ref_aux_less_def sinks_aux_sinks_aux_less) qed blast lemma ipurge_ref_aux_less_cons_1: assumes A: "\<exists>u \<in> U. (u, D x) \<in> I" shows "ipurge_ref_aux_less I D U (x # xs) X = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs) (ipurge_ref I D (D x) xs X)" proof (induction xs arbitrary: X rule: rev_induct, simp add: ipurge_ref_def ipurge_ref_aux_less_def sinks_aux_less_single_event A) fix x' xs X assume B: "\<And>X. ipurge_ref_aux_less I D U (x # xs) X = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs) (ipurge_ref I D (D x) xs X)" show "ipurge_ref_aux_less I D U (x # xs @ [x']) X = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) (xs @ [x'])) (ipurge_ref I D (D x) (xs @ [x']) X)" proof (cases "\<exists>v \<in> U \<union> sinks_aux_less I D U (x # xs). (v, D x') \<in> I") assume C: "\<exists>v \<in> U \<union> sinks_aux_less I D U (x # xs). (v, D x') \<in> I" hence "ipurge_ref_aux_less I D U (x # xs @ [x']) X = ipurge_ref_aux_less I D U (x # xs) {y \<in> X. (D x', D y) \<notin> I}" by (subst append_Cons [symmetric], simp add: ipurge_ref_aux_less_last del: append_Cons) also have "\<dots> = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs) (ipurge_ref I D (D x) xs {y \<in> X. (D x', D y) \<notin> I})" using B . finally have D: "ipurge_ref_aux_less I D U (x # xs @ [x']) X = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs) (ipurge_ref I D (D x) xs {y \<in> X. (D x', D y) \<notin> I})" . show ?thesis proof (cases "(D x, D x') \<in> I \<or> (\<exists>v \<in> sinks I D (D x) xs. (v, D x') \<in> I)") case True hence "ipurge_ref I D (D x) xs {y \<in> X. (D x', D y) \<notin> I} = ipurge_ref I D (D x) (xs @ [x']) X" by (simp add: ipurge_ref_last) moreover have "D x' \<in> sinks I D (D x) (xs @ [x'])" using True by (simp only: sinks_interference_eq) hence "ipurge_tr I D (D x) xs = ipurge_tr I D (D x) (xs @ [x'])" by simp ultimately show ?thesis using D by simp next case False hence "ipurge_ref I D (D x) xs {y \<in> X. (D x', D y) \<notin> I} = ipurge_ref I D (D x) (xs @ [x']) {y \<in> X. (D x', D y) \<notin> I}" by (simp add: ipurge_ref_last) also have "\<dots> = {y \<in> ipurge_ref I D (D x) (xs @ [x']) X. (D x', D y) \<notin> I}" by (simp add: ipurge_ref_swap) finally have "ipurge_ref_aux_less I D U (x # xs @ [x']) X = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs) {y \<in> ipurge_ref I D (D x) (xs @ [x']) X. (D x', D y) \<notin> I}" using D by simp also have "\<dots> = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs @ [x']) (ipurge_ref I D (D x) (xs @ [x']) X)" proof - have "\<exists>v \<in> U \<union> sinks_aux_less I D U (ipurge_tr I D (D x) xs). (v, D x') \<in> I" proof - obtain v where E: "v \<in> U \<union> sinks_aux_less I D U (x # xs)" and F: "(v, D x') \<in> I" using C .. have "v \<in> sinks_aux I D U (x # xs)" using E by (simp add: sinks_aux_sinks_aux_less) hence "v \<in> sinks_aux I D (insert (D x) U) xs" using A by (simp add: sinks_aux_cons) hence "v \<in> sinks_aux I D U (ipurge_tr I D (D x) xs)" using F and False by (rule sinks_aux_member_ipurge_tr) hence "v \<in> U \<union> sinks_aux_less I D U (ipurge_tr I D (D x) xs)" by (simp add: sinks_aux_sinks_aux_less) with F show ?thesis .. qed thus ?thesis by (simp add: ipurge_ref_aux_less_last) qed finally have "ipurge_ref_aux_less I D U (x # xs @ [x']) X = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs @ [x']) (ipurge_ref I D (D x) (xs @ [x']) X)" . moreover have "D x' \<notin> sinks I D (D x) (xs @ [x'])" using False by (simp only: sinks_interference_eq, simp) hence "ipurge_tr I D (D x) xs @ [x'] = ipurge_tr I D (D x) (xs @ [x'])" by simp ultimately show ?thesis by simp qed next assume C: "\<not> (\<exists>v \<in> U \<union> sinks_aux_less I D U (x # xs). (v, D x') \<in> I)" hence "ipurge_ref_aux_less I D U (x # xs @ [x']) X = ipurge_ref_aux_less I D U (x # xs) X" by (subst append_Cons [symmetric], simp add: ipurge_ref_aux_less_last del: append_Cons) also have "\<dots> = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs) (ipurge_ref I D (D x) xs X)" using B . also have "\<dots> = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs @ [x']) (ipurge_ref I D (D x) xs X)" proof - have "\<not> (\<exists>v \<in> U \<union> sinks_aux_less I D U (ipurge_tr I D (D x) xs). (v, D x') \<in> I)" (is "\<not> ?P") proof assume ?P then obtain v where D: "v \<in> U \<union> sinks_aux_less I D U (ipurge_tr I D (D x) xs)" and E: "(v, D x') \<in> I" .. have "sinks_aux I D U (ipurge_tr I D (D x) xs) \<subseteq> sinks_aux I D U xs" by (rule sinks_aux_subset_ipurge_tr) moreover have "v \<in> sinks_aux I D U (ipurge_tr I D (D x) xs)" using D by (simp add: sinks_aux_sinks_aux_less) ultimately have "v \<in> sinks_aux I D U xs" .. moreover have "U \<subseteq> insert (D x) U" by (rule subset_insertI) hence "sinks_aux I D U xs \<subseteq> sinks_aux I D (insert (D x) U) xs" by (rule sinks_aux_subset_dom) ultimately have "v \<in> sinks_aux I D (insert (D x) U) xs" .. hence "v \<in> sinks_aux I D U (x # xs)" using A by (simp add: sinks_aux_cons) hence "v \<in> U \<union> sinks_aux_less I D U (x # xs)" by (simp add: sinks_aux_sinks_aux_less) with E have "\<exists>v \<in> U \<union> sinks_aux_less I D U (x # xs). (v, D x') \<in> I" .. thus False using C by contradiction qed thus ?thesis by (simp add: ipurge_ref_aux_less_last) qed also have "\<dots> = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) (xs @ [x'])) (ipurge_ref I D (D x) (xs @ [x']) X)" proof - have "\<not> ((D x, D x') \<in> I \<or> (\<exists>v \<in> sinks I D (D x) xs. (v, D x') \<in> I))" (is "\<not> ?P") proof (rule notI, erule disjE) assume D: "(D x, D x') \<in> I" have "insert (D x) U \<subseteq> sinks_aux I D (insert (D x) U) xs" by (rule sinks_aux_subset) moreover have "D x \<in> insert (D x) U" by simp ultimately have "D x \<in> sinks_aux I D (insert (D x) U) xs" .. hence "D x \<in> sinks_aux I D U (x # xs)" using A by (simp add: sinks_aux_cons) hence "D x \<in> U \<union> sinks_aux_less I D U (x # xs)" by (simp add: sinks_aux_sinks_aux_less) with D have "\<exists>v \<in> U \<union> sinks_aux_less I D U (x # xs). (v, D x') \<in> I" .. thus False using C by contradiction next assume "\<exists>v \<in> sinks I D (D x) xs. (v, D x') \<in> I" then obtain v where D: "v \<in> sinks I D (D x) xs" and E: "(v, D x') \<in> I" .. have "{D x} \<subseteq> insert (D x) U" by simp hence "sinks_aux I D {D x} xs \<subseteq> sinks_aux I D (insert (D x) U) xs" by (rule sinks_aux_subset_dom) moreover have "v \<in> sinks_aux I D {D x} xs" using D by (simp add: sinks_aux_single_dom) ultimately have "v \<in> sinks_aux I D (insert (D x) U) xs" .. hence "v \<in> sinks_aux I D U (x # xs)" using A by (simp add: sinks_aux_cons) hence "v \<in> U \<union> sinks_aux_less I D U (x # xs)" by (simp add: sinks_aux_sinks_aux_less) with E have "\<exists>v \<in> U \<union> sinks_aux_less I D U (x # xs). (v, D x') \<in> I" .. thus False using C by contradiction qed hence "ipurge_tr I D (D x) xs @ [x'] = ipurge_tr I D (D x) (xs @ [x'])" by (simp only: sinks_interference_eq, simp) moreover have "ipurge_ref I D (D x) xs X = ipurge_ref I D (D x) (xs @ [x']) X" using \<open>\<not> ?P\<close> by (simp add: ipurge_ref_last) ultimately show ?thesis by simp qed finally show ?thesis . qed qed lemma ipurge_ref_aux_less_cons_2: "\<not> (\<exists>u \<in> U. (u, D x) \<in> I) \<Longrightarrow> ipurge_ref_aux_less I D U (x # xs) X = ipurge_ref_aux_less I D U xs X" by (simp add: ipurge_ref_aux_less_def sinks_aux_less_cons) subsection "Closure of the failures of a secure process under intransitive purge" text \<open> The intransitive purge of an event list @{term xs} with regard to a policy @{term I}, an event-domain map @{term D}, and a set of domains @{term U} can equivalently be computed as follows: for each item @{term x} of @{term xs}, if @{term x} may be affected by some domain in @{term U}, discard @{term x} and go on recursively using @{term "ipurge_tr I D (D x) xs'"} as input, where @{term xs'} is the sublist of @{term xs} following @{term x}; otherwise, retain @{term x} and go on recursively using @{term xs'} as input. In fact, in each recursive step, any item allowed to be indirectly affected by @{term U} through the effect of some item preceding @{term x} within @{term xs} has already been removed from the list. Hence, it is sufficient to check whether @{term x} may be directly affected by @{term U}, and remove @{term x}, as well as any residual item allowed to be affected by @{term x}, if this is the case. Similarly, the intransitive purge of an event set @{term X} with regard to a policy @{term I}, an event-domain map @{term D}, a set of domains @{term U}, and an event list @{term xs} can be computed as follows. First of all, compute @{term "ipurge_ref_aux I D U [] X"} and use this set, along with @{term xs}, as the input for the subsequent step. Then, for each item @{term x} of @{term xs}, if @{term x} may be affected by some domain in @{term U}, go on recursively using @{term "ipurge_tr I D (D x) xs'"} and @{term "ipurge_ref I D (D x) xs' X'"} as input, where @{term X'} is the set input to the current recursive step; otherwise, go on recursively using @{term xs'} and @{term X'} as input. In fact, in each recursive step, any item allowed to be affected by @{term U} either directly, or through the effect of some item preceding @{term x} within @{term xs}, has already been removed from the set (in the initial step and in subsequent steps, respectively). Thus, it is sufficient to check whether @{term x} may be directly affected by @{term U}, and remove any residual item allowed to be affected by @{term x} if this is the case. Assume that the two computations be performed simultaneously by a single function, which will then take as input an event list-event set pair and return as output another such pair. Then, if the input pair is a failure of a secure process, the output pair is still a failure. In fact, for each item @{term x} of @{term xs} allowed to be affected by @{term U}, if @{term ys} is the partial output list for the sublist of @{term xs} preceding @{term x}, then @{term "(ys @ ipurge_tr I D (D x) xs', ipurge_ref I D (D x) xs' X')"} is a failure provided that such is @{term "(ys @ x # xs', X')"}, by virtue of the definition of CSP noninterference security \<^cite>\<open>"R2"\<close>. Hence, the property of being a failure is conserved upon each recursive call by the event list-event set pair such that the list matches the concatenation of the partial output list with the residual input list, and the set matches the residual input set. This holds until the residual input list is nil, which is the base case determining the end of the computation. As shown by this argument, a proof by induction that the output event list-event set pair, under the aforesaid assumptions, is still a failure, requires that the partial output list be passed to the function as a further argument, in addition to the residual input list, in the recursive calls contained within the definition of the function. Therefore, the output list has to be accumulated into a parameter of the function, viz. the function needs to be tail-recursive. This suggests to prove the properties of interest of the function by applying the ten-step proof method for theorems on tail-recursive functions described in \<^cite>\<open>"R1"\<close>. The starting point is to formulate a naive definition of the function, which will then be refined as specified by the proof method. A slight complication is due to the preliminary replacement of the input event set @{term X} with @{term "ipurge_ref_aux I D U [] X"}, to be performed before the items of the input event list start to be consumed recursively. A simple solution to this problem is to nest the accumulator of the output list within data type \<open>option\<close>. In this way, the initial state can be distinguished from the subsequent one, in which the input event list starts to be consumed, by assigning the distinct values @{term None} and @{term "Some []"}, respectively, to the accumulator. Everything is now ready for giving a naive definition of the function under consideration: \null \<close> function (sequential) ipurge_fail_aux_t_naive :: "('d \<times> 'd) set \<Rightarrow> ('a \<Rightarrow> 'd) \<Rightarrow> 'd set \<Rightarrow> 'a list \<Rightarrow> 'a list option \<Rightarrow> 'a set \<Rightarrow> 'a failure" where "ipurge_fail_aux_t_naive I D U xs None X = ipurge_fail_aux_t_naive I D U xs (Some []) (ipurge_ref_aux I D U [] X)" | "ipurge_fail_aux_t_naive I D U (x # xs) (Some ys) X = (if \<exists>u \<in> U. (u, D x) \<in> I then ipurge_fail_aux_t_naive I D U (ipurge_tr I D (D x) xs) (Some ys) (ipurge_ref I D (D x) xs X) else ipurge_fail_aux_t_naive I D U xs (Some (ys @ [x])) X)" | "ipurge_fail_aux_t_naive _ _ _ _ (Some ys) X = (ys, X)" oops text \<open> \null The parameter into which the output list is accumulated is the last but one. As shown by the above informal argument, function \<open>ipurge_fail_aux_t_naive\<close> enjoys the following properties: \null @{term "fst (ipurge_fail_aux_t_naive I D U xs None X) = ipurge_tr_aux I D U xs"} \null @{term "snd (ipurge_fail_aux_t_naive I D U xs None X) = ipurge_ref_aux I D U xs X"} \null @{term "\<lbrakk>secure P I D; (xs, X) \<in> failures P\<rbrakk> \<Longrightarrow> ipurge_fail_aux_t_naive I D U xs None X \<in> failures P"} \null which altogether imply the target lemma, viz. the closure of the failures of a secure process under intransitive purge. In what follows, the steps provided for by the aforesaid proof method will be dealt with one after the other, with the purpose of proving the target closure lemma in the final step. For more information on this proof method, cf. \<^cite>\<open>"R1"\<close>. \<close> subsubsection "Step 1" text \<open> In the definition of the auxiliary tail-recursive function \<open>ipurge_fail_aux_t_aux\<close>, the Cartesian product of the input parameter types of function \<open>ipurge_fail_aux_t_naive\<close> will be implemented as the following record type: \null \<close> record ('a, 'd) ipurge_rec = Pol :: "('d \<times> 'd) set" Map :: "'a \<Rightarrow> 'd" Doms :: "'d set" List :: "'a list" ListOp :: "'a list option" Set :: "'a set" text \<open> \null Here below is the resulting definition of function \<open>ipurge_fail_aux_t_aux\<close>: \null \<close> function ipurge_fail_aux_t_aux :: "('a, 'd) ipurge_rec \<Rightarrow> ('a, 'd) ipurge_rec" where "ipurge_fail_aux_t_aux \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr> = ipurge_fail_aux_t_aux \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = Some [], Set = ipurge_ref_aux I D U [] X\<rparr>" | "ipurge_fail_aux_t_aux \<lparr>Pol = I, Map = D, Doms = U, List = x # xs, ListOp = Some ys, Set = X\<rparr> = (if \<exists>u \<in> U. (u, D x) \<in> I then ipurge_fail_aux_t_aux \<lparr>Pol = I, Map = D, Doms = U, List = ipurge_tr I D (D x) xs, ListOp = Some ys, Set = ipurge_ref I D (D x) xs X\<rparr> else ipurge_fail_aux_t_aux \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = Some (ys @ [x]), Set = X\<rparr>)" | "ipurge_fail_aux_t_aux \<lparr>Pol = I, Map = D, Doms = U, List = [], ListOp = Some ys, Set = X\<rparr> = \<lparr>Pol = I, Map = D, Doms = U, List = [], ListOp = Some ys, Set = X\<rparr>" proof (simp_all, atomize_elim) fix Y :: "('a, 'd) ipurge_rec" show "(\<exists>I D U xs X. Y = \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>) \<or> (\<exists>I D U x xs ys X. Y = \<lparr>Pol = I, Map = D, Doms = U, List = x # xs, ListOp = Some ys, Set = X\<rparr>) \<or> (\<exists>I D U ys X. Y = \<lparr>Pol = I, Map = D, Doms = U, List = [], ListOp = Some ys, Set = X\<rparr>)" proof (cases Y, simp) fix xs :: "'a list" and yso :: "'a list option" show "yso = None \<or> (\<exists>x' xs'. xs = x' # xs') \<and> (\<exists>ys. yso = Some ys) \<or> xs = [] \<and> (\<exists>ys. yso = Some ys)" proof (cases yso, simp_all) qed (subst disj_commute, rule spec [OF list.nchotomy]) qed qed text \<open> \null The length of the input event list of function @{term ipurge_fail_aux_t_aux} decreases in every recursive call except for the first one, where the input list is left unchanged while the nested output list passes from @{term None} to @{term "Some []"}. A measure function decreasing in the first recursive call as well can then be obtained by increasing the length of the input list by one in case the nested output list matches @{term None}. Using such a measure function, the termination of function @{term ipurge_fail_aux_t_aux} is guaranteed by the fact that the event lists output by function @{term ipurge_tr} are not longer than the corresponding input ones. \null \<close> termination ipurge_fail_aux_t_aux proof (relation "measure (\<lambda>Y. (if ListOp Y = None then Suc else id) (length (List Y)))", simp_all) fix D :: "'a \<Rightarrow> 'd" and I x xs have "length (ipurge_tr I D (D x) xs) \<le> length xs" by (rule ipurge_tr_length) thus "length (ipurge_tr I D (D x) xs) < Suc (length xs)" by simp qed subsubsection "Step 2" definition ipurge_fail_aux_t_in :: "('d \<times> 'd) set \<Rightarrow> ('a \<Rightarrow> 'd) \<Rightarrow> 'd set \<Rightarrow> 'a list \<Rightarrow> 'a set \<Rightarrow> ('a, 'd) ipurge_rec" where "ipurge_fail_aux_t_in I D U xs X \<equiv> \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>" definition ipurge_fail_aux_t_out :: "('a, 'd) ipurge_rec \<Rightarrow> 'a failure" where "ipurge_fail_aux_t_out Y \<equiv> (case ListOp Y of Some ys \<Rightarrow> ys, Set Y)" definition ipurge_fail_aux_t :: "('d \<times> 'd) set \<Rightarrow> ('a \<Rightarrow> 'd) \<Rightarrow> 'd set \<Rightarrow> 'a list \<Rightarrow> 'a set \<Rightarrow> 'a failure" where "ipurge_fail_aux_t I D U xs X \<equiv> ipurge_fail_aux_t_out (ipurge_fail_aux_t_aux (ipurge_fail_aux_t_in I D U xs X))" text \<open> \null Since the significant inputs of function \<open>ipurge_fail_aux_t_naive\<close> match pattern \<open>_, _, _, _, None, _\<close>, those of function @{term ipurge_fail_aux_t_aux}, as returned by function @{term ipurge_fail_aux_t_in}, match pattern \<open>\<lparr>Pol = _, Map = _, Doms = _, List = _, ListOp = None, Set = _\<rparr>\<close>. Likewise, since the nested output lists returned by function @{term ipurge_fail_aux_t_aux} match pattern \<open>Some _\<close>, function @{term ipurge_fail_aux_t_out} does not need to worry about dealing with nested output lists equal to @{term None}. In terms of function @{term ipurge_fail_aux_t}, the statements to be proven in order to demonstrate the target closure lemma, previously expressed using function \<open>ipurge_fail_aux_t_naive\<close> and henceforth respectively named \<open>ipurge_fail_aux_t_eq_tr\<close>, \<open>ipurge_fail_aux_t_eq_ref\<close>, and \<open>ipurge_fail_aux_t_failures\<close>, take the following form: \null @{term "fst (ipurge_fail_aux_t I D U xs X) = ipurge_tr_aux I D U xs"} \null @{term "snd (ipurge_fail_aux_t I D U xs X) = ipurge_ref_aux I D U xs X"} \null @{term "\<lbrakk>secure P I D; (xs, X) \<in> failures P\<rbrakk> \<Longrightarrow> ipurge_fail_aux_t I D U xs X \<in> failures P"} \<close> subsubsection "Step 3" inductive_set ipurge_fail_aux_t_set :: "('a, 'd) ipurge_rec \<Rightarrow> ('a, 'd) ipurge_rec set" for Y :: "('a, 'd) ipurge_rec" where R0: "Y \<in> ipurge_fail_aux_t_set Y" | R1: "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr> \<in> ipurge_fail_aux_t_set Y \<Longrightarrow> \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = Some [], Set = ipurge_ref_aux I D U [] X\<rparr> \<in> ipurge_fail_aux_t_set Y" | R2: "\<lbrakk>\<lparr>Pol = I, Map = D, Doms = U, List = x # xs, ListOp = Some ys, Set = X\<rparr> \<in> ipurge_fail_aux_t_set Y; \<exists>u \<in> U. (u, D x) \<in> I\<rbrakk> \<Longrightarrow> \<lparr>Pol = I, Map = D, Doms = U, List = ipurge_tr I D (D x) xs, ListOp = Some ys, Set = ipurge_ref I D (D x) xs X\<rparr> \<in> ipurge_fail_aux_t_set Y" | R3: "\<lbrakk>\<lparr>Pol = I, Map = D, Doms = U, List = x # xs, ListOp = Some ys, Set = X\<rparr> \<in> ipurge_fail_aux_t_set Y; \<not> (\<exists>u \<in> U. (u, D x) \<in> I)\<rbrakk> \<Longrightarrow> \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = Some (ys @ [x]), Set = X\<rparr> \<in> ipurge_fail_aux_t_set Y" subsubsection "Step 4" lemma ipurge_fail_aux_t_subset: assumes A: "Z \<in> ipurge_fail_aux_t_set Y" shows "ipurge_fail_aux_t_set Z \<subseteq> ipurge_fail_aux_t_set Y" proof (rule subsetI, erule ipurge_fail_aux_t_set.induct) show "Z \<in> ipurge_fail_aux_t_set Y" using A . next fix I D U xs X assume "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr> \<in> ipurge_fail_aux_t_set Y" thus "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = Some [], Set = ipurge_ref_aux I D U [] X\<rparr> \<in> ipurge_fail_aux_t_set Y" by (rule R1) next fix I D U x xs ys X assume "\<lparr>Pol = I, Map = D, Doms = U, List = x # xs, ListOp = Some ys, Set = X\<rparr> \<in> ipurge_fail_aux_t_set Y" and "\<exists>u \<in> U. (u, D x) \<in> I" thus "\<lparr>Pol = I, Map = D, Doms = U, List = ipurge_tr I D (D x) xs, ListOp = Some ys, Set = ipurge_ref I D (D x) xs X\<rparr> \<in> ipurge_fail_aux_t_set Y" by (rule R2) next fix I D U x xs ys X assume "\<lparr>Pol = I, Map = D, Doms = U, List = x # xs, ListOp = Some ys, Set = X\<rparr> \<in> ipurge_fail_aux_t_set Y" and "\<not> (\<exists>u \<in> U. (u, D x) \<in> I)" thus "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = Some (ys @ [x]), Set = X\<rparr> \<in> ipurge_fail_aux_t_set Y" by (rule R3) qed lemma ipurge_fail_aux_t_aux_set: "ipurge_fail_aux_t_aux Y \<in> ipurge_fail_aux_t_set Y" proof (induction rule: ipurge_fail_aux_t_aux.induct, simp_all add: R0 del: ipurge_fail_aux_t_aux.simps(2)) fix I U xs X and D :: "'a \<Rightarrow> 'd" let ?Y = "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>" and ?Y' = "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = Some [], Set = ipurge_ref_aux I D U [] X\<rparr>" have "?Y \<in> ipurge_fail_aux_t_set ?Y" by (rule R0) moreover have "?Y \<in> ipurge_fail_aux_t_set ?Y \<Longrightarrow> ?Y' \<in> ipurge_fail_aux_t_set ?Y" by (rule R1) ultimately have "?Y' \<in> ipurge_fail_aux_t_set ?Y" by simp hence "ipurge_fail_aux_t_set ?Y' \<subseteq> ipurge_fail_aux_t_set ?Y" by (rule ipurge_fail_aux_t_subset) moreover assume "ipurge_fail_aux_t_aux ?Y' \<in> ipurge_fail_aux_t_set ?Y'" ultimately show "ipurge_fail_aux_t_aux ?Y' \<in> ipurge_fail_aux_t_set ?Y" .. next fix I U x xs ys X and D :: "'a \<Rightarrow> 'd" let ?Y = "\<lparr>Pol = I, Map = D, Doms = U, List = x # xs, ListOp = Some ys, Set = X\<rparr>" and ?Y' = "\<lparr>Pol = I, Map = D, Doms = U, List = ipurge_tr I D (D x) xs, ListOp = Some ys, Set = ipurge_ref I D (D x) xs X\<rparr>" and ?Y'' = "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = Some (ys @ [x]), Set = X\<rparr>" assume A: "\<exists>u \<in> U. (u, D x) \<in> I \<Longrightarrow> ipurge_fail_aux_t_aux ?Y' \<in> ipurge_fail_aux_t_set ?Y'" and B: "\<forall>u \<in> U. (u, D x) \<notin> I \<Longrightarrow> ipurge_fail_aux_t_aux ?Y'' \<in> ipurge_fail_aux_t_set ?Y''" show "ipurge_fail_aux_t_aux ?Y \<in> ipurge_fail_aux_t_set ?Y" proof (cases "\<exists>u \<in> U. (u, D x) \<in> I", simp_all (no_asm_simp)) case True have "?Y \<in> ipurge_fail_aux_t_set ?Y" by (rule R0) moreover have "?Y \<in> ipurge_fail_aux_t_set ?Y \<Longrightarrow> \<exists>u \<in> U. (u, D x) \<in> I \<Longrightarrow> ?Y' \<in> ipurge_fail_aux_t_set ?Y" by (rule R2) ultimately have "?Y' \<in> ipurge_fail_aux_t_set ?Y" using True by simp hence "ipurge_fail_aux_t_set ?Y' \<subseteq> ipurge_fail_aux_t_set ?Y" by (rule ipurge_fail_aux_t_subset) moreover have "ipurge_fail_aux_t_aux ?Y' \<in> ipurge_fail_aux_t_set ?Y'" using A and True by simp ultimately show "ipurge_fail_aux_t_aux ?Y' \<in> ipurge_fail_aux_t_set ?Y" .. next case False have "?Y \<in> ipurge_fail_aux_t_set ?Y" by (rule R0) moreover have "?Y \<in> ipurge_fail_aux_t_set ?Y \<Longrightarrow> \<not> (\<exists>u \<in> U. (u, D x) \<in> I) \<Longrightarrow> ?Y'' \<in> ipurge_fail_aux_t_set ?Y" by (rule R3) ultimately have "?Y'' \<in> ipurge_fail_aux_t_set ?Y" using False by simp hence "ipurge_fail_aux_t_set ?Y'' \<subseteq> ipurge_fail_aux_t_set ?Y" by (rule ipurge_fail_aux_t_subset) moreover have "ipurge_fail_aux_t_aux ?Y'' \<in> ipurge_fail_aux_t_set ?Y''" using B and False by simp ultimately show "ipurge_fail_aux_t_aux ?Y'' \<in> ipurge_fail_aux_t_set ?Y" .. qed qed subsubsection "Step 5" definition ipurge_fail_aux_t_inv_1 :: "('d \<times> 'd) set \<Rightarrow> ('a \<Rightarrow> 'd) \<Rightarrow> 'd set \<Rightarrow> 'a list \<Rightarrow> ('a, 'd) ipurge_rec \<Rightarrow> bool" where "ipurge_fail_aux_t_inv_1 I D U xs Y \<equiv> (case ListOp Y of None \<Rightarrow> [] | Some ys \<Rightarrow> ys) @ ipurge_tr_aux I D U (List Y) = ipurge_tr_aux I D U xs" definition ipurge_fail_aux_t_inv_2 :: "('d \<times> 'd) set \<Rightarrow> ('a \<Rightarrow> 'd) \<Rightarrow> 'd set \<Rightarrow> 'a list \<Rightarrow> 'a set \<Rightarrow> ('a, 'd) ipurge_rec \<Rightarrow> bool" where "ipurge_fail_aux_t_inv_2 I D U xs X Y \<equiv> if ListOp Y = None then List Y = xs \<and> Set Y = X else ipurge_ref_aux_less I D U (List Y) (Set Y) = ipurge_ref_aux I D U xs X" definition ipurge_fail_aux_t_inv_3 :: "'a process \<Rightarrow> ('d \<times> 'd) set \<Rightarrow> ('a \<Rightarrow> 'd) \<Rightarrow> 'a list \<Rightarrow> 'a set \<Rightarrow> ('a, 'd) ipurge_rec \<Rightarrow> bool" where "ipurge_fail_aux_t_inv_3 P I D xs X Y \<equiv> secure P I D \<longrightarrow> (xs, X) \<in> failures P \<longrightarrow> ((case ListOp Y of None \<Rightarrow> [] | Some ys \<Rightarrow> ys) @ List Y, Set Y) \<in> failures P" text \<open> \null Three invariants have been defined, one for each of lemmas \<open>ipurge_fail_aux_t_eq_tr\<close>, \<open>ipurge_fail_aux_t_eq_ref\<close>, and \<open>ipurge_fail_aux_t_failures\<close>. More precisely, the invariants are @{term "ipurge_fail_aux_t_inv_1 I D U xs"}, @{term "ipurge_fail_aux_t_inv_2 I D U xs X"}, and @{term "ipurge_fail_aux_t_inv_3 P I D xs X"}, where the free variables are intended to match those appearing in the aforesaid lemmas. Particularly: \begin{itemize} \item The first invariant expresses the fact that in each recursive step, any item of the residual input list @{term "List Y"} indirectly affected by @{term U} through the effect of previous, already consumed items has already been removed from the list, so that applying function @{term "ipurge_tr_aux I D U"} to the list is sufficient to obtain the intransitive purge of the whole original list. \item The second invariant expresses the fact that in each recursive step, any item of the residual input set @{term "Set Y"} affected by @{term U} either directly, or through the effect of previous, already consumed items, has already been removed from the set, so that applying function @{term "ipurge_ref_aux_less I D U (List Y)"} to the set is sufficient to obtain the intransitive purge of the whole original set. \\The use of function @{term ipurge_ref_aux_less} ensures that the invariant implies the equality @{term "Set Y = ipurge_ref_aux I D U xs X"} for @{term "List Y = []"}, viz. for the output values of function @{term ipurge_fail_aux_t_aux}, which is the reason requiring the introduction of function @{term ipurge_ref_aux_less}. \item The third invariant expresses the fact that in each recursive step, the event list-event set pair such that the list matches the concatenation of the partial output list with @{term "List Y"}, and the set matches @{term "Set Y"}, is a failure provided that the original input pair is such as well. \end{itemize} \<close> subsubsection "Step 6" lemma ipurge_fail_aux_t_input_1: "ipurge_fail_aux_t_inv_1 I D U xs \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>" by (simp add: ipurge_fail_aux_t_inv_1_def) lemma ipurge_fail_aux_t_input_2: "ipurge_fail_aux_t_inv_2 I D U xs X \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>" by (simp add: ipurge_fail_aux_t_inv_2_def) lemma ipurge_fail_aux_t_input_3: "ipurge_fail_aux_t_inv_3 P I D xs X \<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>" by (simp add: ipurge_fail_aux_t_inv_3_def) subsubsection "Step 7" definition ipurge_fail_aux_t_form :: "('a, 'd) ipurge_rec \<Rightarrow> bool" where "ipurge_fail_aux_t_form Y \<equiv> case ListOp Y of None \<Rightarrow> False | Some ys \<Rightarrow> List Y = []" lemma ipurge_fail_aux_t_intro_1: "\<lbrakk>ipurge_fail_aux_t_inv_1 I D U xs Y; ipurge_fail_aux_t_form Y\<rbrakk> \<Longrightarrow> fst (ipurge_fail_aux_t_out Y) = ipurge_tr_aux I D U xs" proof (simp add: ipurge_fail_aux_t_inv_1_def ipurge_fail_aux_t_form_def ipurge_fail_aux_t_out_def) qed (simp split: option.split_asm) lemma ipurge_fail_aux_t_intro_2: "\<lbrakk>ipurge_fail_aux_t_inv_2 I D U xs X Y; ipurge_fail_aux_t_form Y\<rbrakk> \<Longrightarrow> snd (ipurge_fail_aux_t_out Y) = ipurge_ref_aux I D U xs X" proof (simp add: ipurge_fail_aux_t_inv_2_def ipurge_fail_aux_t_form_def ipurge_fail_aux_t_out_def) qed (simp add: ipurge_ref_aux_less_def split: option.split_asm) subsubsection "Step 8" lemma ipurge_fail_aux_t_form_aux: "ipurge_fail_aux_t_form (ipurge_fail_aux_t_aux Y)" by (induction Y rule: ipurge_fail_aux_t_aux.induct, simp_all add: ipurge_fail_aux_t_form_def) subsubsection "Step 9" lemma ipurge_fail_aux_t_invariance_aux: "Z \<in> ipurge_fail_aux_t_set Y \<Longrightarrow> Pol Z = Pol Y \<and> Map Z = Map Y \<and> Doms Z = Doms Y" by (erule ipurge_fail_aux_t_set.induct, simp_all) text \<open> \null The lemma just proven, stating the invariance of the first three record fields over inductive set @{term "ipurge_fail_aux_t_set Y"}, is used in the following proofs of the invariance of predicates @{term "ipurge_fail_aux_t_inv_1 I D U xs"}, @{term "ipurge_fail_aux_t_inv_2 I D U xs X"}, and @{term "ipurge_fail_aux_t_inv_3 P I D xs X"}. The equality between the free variables appearing in the predicates and the corresponding fields of the record generating the set, which is required for such invariance properties to hold, is asserted in the enunciation of the properties by means of record updates. In the subsequent proofs of lemmas \<open>ipurge_fail_aux_t_eq_tr\<close>, \<open>ipurge_fail_aux_t_eq_ref\<close>, and \<open>ipurge_fail_aux_t_failures\<close>, the enforcement of this equality will be ensured by the identification of both predicate variables and record fields with the related free variables appearing in the lemmas. \null \<close> lemma ipurge_fail_aux_t_invariance_1: "\<lbrakk>Z \<in> ipurge_fail_aux_t_set (Y\<lparr>Pol := I, Map := D, Doms := U\<rparr>); ipurge_fail_aux_t_inv_1 I D U xs (Y\<lparr>Pol := I, Map := D, Doms := U\<rparr>)\<rbrakk> \<Longrightarrow> ipurge_fail_aux_t_inv_1 I D U xs Z" proof (erule ipurge_fail_aux_t_set.induct, assumption, drule_tac [!] ipurge_fail_aux_t_invariance_aux, simp_all add: ipurge_fail_aux_t_inv_1_def) fix x xs' ys assume "ys @ ipurge_tr_aux I D U (x # xs') = ipurge_tr_aux I D U xs" (is "?A = ?C") moreover assume "\<exists>u \<in> U. (u, D x) \<in> I" hence "?A = ys @ ipurge_tr_aux I D (insert (D x) U) xs'" by (simp add: ipurge_tr_aux_cons) hence "?A = ys @ ipurge_tr_aux I D U (ipurge_tr I D (D x) xs')" (is "_ = ?B") by (simp add: ipurge_tr_aux_insert) ultimately show "?B = ?C" by simp next fix x xs' ys assume "ys @ ipurge_tr_aux I D U (x # xs') = ipurge_tr_aux I D U xs" (is "?A = ?C") moreover assume "\<forall>u \<in> U. (u, D x) \<notin> I" hence "?A = ys @ x # ipurge_tr_aux I D U xs'" (is "_ = ?B") by (simp add: ipurge_tr_aux_cons) ultimately show "?B = ?C" by simp qed lemma ipurge_fail_aux_t_invariance_2: "\<lbrakk>Z \<in> ipurge_fail_aux_t_set (Y\<lparr>Pol := I, Map := D, Doms := U\<rparr>); ipurge_fail_aux_t_inv_2 I D U xs X (Y\<lparr>Pol := I, Map := D, Doms := U\<rparr>)\<rbrakk> \<Longrightarrow> ipurge_fail_aux_t_inv_2 I D U xs X Z" proof (erule ipurge_fail_aux_t_set.induct, assumption, drule_tac [!] ipurge_fail_aux_t_invariance_aux, simp_all add: ipurge_fail_aux_t_inv_2_def) show "ipurge_ref_aux_less I D U xs (ipurge_ref_aux I D U [] X) = ipurge_ref_aux I D U xs X" by (rule ipurge_ref_aux_less_nil) next fix x xs' X' assume "ipurge_ref_aux_less I D U (x # xs') X' = ipurge_ref_aux I D U xs X" (is "?A = ?C") moreover assume "\<exists>u \<in> U. (u, D x) \<in> I" hence "?A = ipurge_ref_aux_less I D U (ipurge_tr I D (D x) xs') (ipurge_ref I D (D x) xs' X')" (is "_ = ?B") by (rule ipurge_ref_aux_less_cons_1) ultimately show "?B = ?C" by simp next fix x xs' X' assume "ipurge_ref_aux_less I D U (x # xs') X' = ipurge_ref_aux I D U xs X" (is "?A = ?C") moreover assume "\<forall>u \<in> U. (u, D x) \<notin> I" hence "\<not> (\<exists>u \<in> U. (u, D x) \<in> I)" by simp hence "?A = ipurge_ref_aux_less I D U xs' X'" (is "_ = ?B") by (rule ipurge_ref_aux_less_cons_2) ultimately show "?B = ?C" by simp qed lemma ipurge_fail_aux_t_invariance_3: "\<lbrakk>Z \<in> ipurge_fail_aux_t_set (Y\<lparr>Pol := I, Map := D\<rparr>); ipurge_fail_aux_t_inv_3 P I D xs X (Y\<lparr>Pol := I, Map := D\<rparr>)\<rbrakk> \<Longrightarrow> ipurge_fail_aux_t_inv_3 P I D xs X Z" proof (erule ipurge_fail_aux_t_set.induct, assumption, drule_tac [!] ipurge_fail_aux_t_invariance_aux, simp_all add: ipurge_fail_aux_t_inv_3_def, (rule_tac [!] impI)+) fix xs' X' assume "secure P I D" and "(xs, X) \<in> failures P" and "secure P I D \<longrightarrow> (xs, X) \<in> failures P \<longrightarrow> (xs', X') \<in> failures P" hence "(xs', X') \<in> failures P" by simp moreover have "ipurge_ref_aux I D (Doms Y) [] X' \<subseteq> X'" by (rule ipurge_ref_aux_subset) ultimately show "(xs', ipurge_ref_aux I D (Doms Y) [] X') \<in> failures P" by (rule process_rule_3) next fix x xs' ys X' assume S: "secure P I D" and "(xs, X) \<in> failures P" and "secure P I D \<longrightarrow> (xs, X) \<in> failures P \<longrightarrow> (ys @ x # xs', X') \<in> failures P" hence "(ys @ x # xs', X') \<in> failures P" by simp hence "(x # xs', X') \<in> futures P ys" by (simp add: futures_def) hence "(ipurge_tr I D (D x) xs', ipurge_ref I D (D x) xs' X') \<in> futures P ys" using S by (simp add: secure_def) thus "(ys @ ipurge_tr I D (D x) xs', ipurge_ref I D (D x) xs' X') \<in> failures P" by (simp add: futures_def) qed subsubsection "Step 10" text \<open> Here below are the proofs of lemmas \<open>ipurge_fail_aux_t_eq_tr\<close>, \<open>ipurge_fail_aux_t_eq_ref\<close>, and \<open>ipurge_fail_aux_t_failures\<close>, which are then applied to demonstrate the target closure lemma. \null \<close> lemma ipurge_fail_aux_t_eq_tr: "fst (ipurge_fail_aux_t I D U xs X) = ipurge_tr_aux I D U xs" proof - let ?Y = "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>" have "ipurge_fail_aux_t_aux ?Y \<in> ipurge_fail_aux_t_set (?Y\<lparr>Pol := I, Map := D, Doms := U\<rparr>)" by (simp add: ipurge_fail_aux_t_aux_set del: ipurge_fail_aux_t_aux.simps) moreover have "ipurge_fail_aux_t_inv_1 I D U xs (?Y\<lparr>Pol := I, Map := D, Doms := U\<rparr>)" by (simp add: ipurge_fail_aux_t_input_1) ultimately have "ipurge_fail_aux_t_inv_1 I D U xs (ipurge_fail_aux_t_aux ?Y)" by (rule ipurge_fail_aux_t_invariance_1) moreover have "ipurge_fail_aux_t_form (ipurge_fail_aux_t_aux ?Y)" by (rule ipurge_fail_aux_t_form_aux) ultimately have "fst (ipurge_fail_aux_t_out (ipurge_fail_aux_t_aux ?Y)) = ipurge_tr_aux I D U xs" by (rule ipurge_fail_aux_t_intro_1) moreover have "?Y = ipurge_fail_aux_t_in I D U xs X" by (simp add: ipurge_fail_aux_t_in_def) ultimately show ?thesis by (simp add: ipurge_fail_aux_t_def) qed lemma ipurge_fail_aux_t_eq_ref: "snd (ipurge_fail_aux_t I D U xs X) = ipurge_ref_aux I D U xs X" proof - let ?Y = "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>" have "ipurge_fail_aux_t_aux ?Y \<in> ipurge_fail_aux_t_set (?Y\<lparr>Pol := I, Map := D, Doms := U\<rparr>)" by (simp add: ipurge_fail_aux_t_aux_set del: ipurge_fail_aux_t_aux.simps) moreover have "ipurge_fail_aux_t_inv_2 I D U xs X (?Y\<lparr>Pol := I, Map := D, Doms := U\<rparr>)" by (simp add: ipurge_fail_aux_t_input_2) ultimately have "ipurge_fail_aux_t_inv_2 I D U xs X (ipurge_fail_aux_t_aux ?Y)" by (rule ipurge_fail_aux_t_invariance_2) moreover have "ipurge_fail_aux_t_form (ipurge_fail_aux_t_aux ?Y)" by (rule ipurge_fail_aux_t_form_aux) ultimately have "snd (ipurge_fail_aux_t_out (ipurge_fail_aux_t_aux ?Y)) = ipurge_ref_aux I D U xs X" by (rule ipurge_fail_aux_t_intro_2) moreover have "?Y = ipurge_fail_aux_t_in I D U xs X" by (simp add: ipurge_fail_aux_t_in_def) ultimately show ?thesis by (simp add: ipurge_fail_aux_t_def) qed lemma ipurge_fail_aux_t_failures [rule_format]: "secure P I D \<longrightarrow> (xs, X) \<in> failures P \<longrightarrow> ipurge_fail_aux_t I D U xs X \<in> failures P" proof - let ?Y = "\<lparr>Pol = I, Map = D, Doms = U, List = xs, ListOp = None, Set = X\<rparr>" have "ipurge_fail_aux_t_aux ?Y \<in> ipurge_fail_aux_t_set (?Y\<lparr>Pol := I, Map := D\<rparr>)" by (simp add: ipurge_fail_aux_t_aux_set del: ipurge_fail_aux_t_aux.simps) moreover have "ipurge_fail_aux_t_inv_3 P I D xs X (?Y\<lparr>Pol := I, Map := D\<rparr>)" by (simp add: ipurge_fail_aux_t_input_3) ultimately have "ipurge_fail_aux_t_inv_3 P I D xs X (ipurge_fail_aux_t_aux ?Y)" by (rule ipurge_fail_aux_t_invariance_3) moreover have "ipurge_fail_aux_t_form (ipurge_fail_aux_t_aux ?Y)" by (rule ipurge_fail_aux_t_form_aux) ultimately have "secure P I D \<longrightarrow> (xs, X) \<in> failures P \<longrightarrow> ipurge_fail_aux_t_out (ipurge_fail_aux_t_aux ?Y) \<in> failures P" by (rule ipurge_fail_aux_t_intro_3) moreover have "?Y = ipurge_fail_aux_t_in I D U xs X" by (simp add: ipurge_fail_aux_t_in_def) ultimately show ?thesis by (simp add: ipurge_fail_aux_t_def) qed lemma ipurge_tr_ref_aux_failures: "\<lbrakk>secure P I D; (xs, X) \<in> failures P\<rbrakk> \<Longrightarrow> (ipurge_tr_aux I D U xs, ipurge_ref_aux I D U xs X) \<in> failures P" proof (drule ipurge_fail_aux_t_failures [where U = U], assumption, cases "ipurge_fail_aux_t I D U xs X") qed (simp add: ipurge_fail_aux_t_eq_tr [where X = X, symmetric] ipurge_fail_aux_t_eq_ref [symmetric]) subsection "Additional propaedeutic lemmas" text \<open> In what follows, additional lemmas required for the demonstration of the target security conservation theorem are proven. Here below is the proof of some properties of functions @{term ipurge_tr_aux} and @{term ipurge_ref_aux}. Particularly, it is shown that in case an event list and its intransitive purge for some set of domains are both traces of a secure process, and the purged list has a future not affected by any purged event, then that future is also a future for the full event list. \null \<close> lemma ipurge_tr_aux_idem: "ipurge_tr_aux I D U (ipurge_tr_aux I D U xs) = ipurge_tr_aux I D U xs" by (simp add: ipurge_tr_aux_union [symmetric]) lemma ipurge_tr_aux_set: "set (ipurge_tr_aux I D U xs) \<subseteq> set xs" proof (induction xs rule: rev_induct, simp_all) qed blast lemma ipurge_tr_aux_nil [rule_format]: assumes A: "u \<in> U" shows "(\<forall>x \<in> set xs. (u, D x) \<in> I) \<longrightarrow> ipurge_tr_aux I D U xs = []" proof (induction xs rule: rev_induct, simp, rule impI) fix x xs assume "(\<forall>x' \<in> set xs. (u, D x') \<in> I) \<longrightarrow> ipurge_tr_aux I D U xs = []" moreover assume B: "\<forall>x' \<in> set (xs @ [x]). (u, D x') \<in> I" ultimately have C: "ipurge_tr_aux I D U xs = []" by simp have "(u, D x) \<in> I" using B by simp moreover have "U \<subseteq> sinks_aux I D U xs" by (rule sinks_aux_subset) hence "u \<in> sinks_aux I D U xs" using A .. ultimately have "\<exists>u \<in> sinks_aux I D U xs. (u, D x) \<in> I" .. hence "ipurge_tr_aux I D U (xs @ [x]) = ipurge_tr_aux I D U xs" by simp thus "ipurge_tr_aux I D U (xs @ [x]) = []" using C by simp qed lemma ipurge_tr_aux_del_failures [rule_format]: assumes S: "secure P I D" shows "(\<forall>u \<in> sinks_aux_less I D U ys. \<forall>z \<in> Z \<union> set zs. (u, D z) \<notin> I) \<longrightarrow> (xs @ ipurge_tr_aux I D U ys @ zs, Z) \<in> failures P \<longrightarrow> xs @ ys \<in> traces P \<longrightarrow> (xs @ ys @ zs, Z) \<in> failures P" proof (induction ys arbitrary: zs rule: rev_induct, simp, (rule impI)+) fix y ys zs assume A: "\<And>zs. (\<forall>u \<in> sinks_aux_less I D U ys. \<forall>z \<in> Z \<union> set zs. (u, D z) \<notin> I) \<longrightarrow> (xs @ ipurge_tr_aux I D U ys @ zs, Z) \<in> failures P \<longrightarrow> xs @ ys \<in> traces P \<longrightarrow> (xs @ ys @ zs, Z) \<in> failures P" and B: "\<forall>u \<in> sinks_aux_less I D U (ys @ [y]). \<forall>z \<in> Z \<union> set zs. (u, D z) \<notin> I" and C: "(xs @ ipurge_tr_aux I D U (ys @ [y]) @ zs, Z) \<in> failures P" and D: "xs @ (ys @ [y]) \<in> traces P" show "(xs @ (ys @ [y]) @ zs, Z) \<in> failures P" proof (cases "\<exists>u \<in> sinks_aux I D U ys. (u, D y) \<in> I", simp_all (no_asm)) case True have "(\<forall>u \<in> sinks_aux_less I D U ys. \<forall>z \<in> Z \<union> set zs. (u, D z) \<notin> I) \<longrightarrow> (xs @ ipurge_tr_aux I D U ys @ zs, Z) \<in> failures P \<longrightarrow> xs @ ys \<in> traces P \<longrightarrow> (xs @ ys @ zs, Z) \<in> failures P" using A . moreover have "\<exists>u \<in> U \<union> sinks_aux_less I D U ys. (u, D y) \<in> I" using True by (simp add: sinks_aux_sinks_aux_less) hence E: "\<forall>u \<in> insert (D y) (sinks_aux_less I D U ys). \<forall>z \<in> Z \<union> set zs. (u, D z) \<notin> I" using B by (simp only: sinks_aux_less.simps if_True) hence "\<forall>u \<in> sinks_aux_less I D U ys. \<forall>z \<in> Z \<union> set zs. (u, D z) \<notin> I" by simp moreover have "(xs @ ipurge_tr_aux I D U ys @ zs, Z) \<in> failures P" using C and True by simp moreover have "(xs @ ys) @ [y] \<in> traces P" using D by simp hence "xs @ ys \<in> traces P" by (rule process_rule_2_traces) ultimately have "(xs @ ys @ zs, Z) \<in> failures P" by simp hence "(zs, Z) \<in> futures P (xs @ ys)" by (simp add: futures_def) moreover have "(xs @ ys @ [y], {}) \<in> failures P" using D by (rule traces_failures) hence "([y], {}) \<in> futures P (xs @ ys)" by (simp add: futures_def) ultimately have "(y # ipurge_tr I D (D y) zs, ipurge_ref I D (D y) zs Z) \<in> futures P (xs @ ys)" using S by (simp add: secure_def) moreover have "ipurge_tr I D (D y) zs = zs" by (subst ipurge_tr_all, simp add: E) moreover have "ipurge_ref I D (D y) zs Z = Z" by (rule ipurge_ref_all, simp add: E) ultimately have "(y # zs, Z) \<in> futures P (xs @ ys)" by simp thus "(xs @ ys @ y # zs, Z) \<in> failures P" by (simp add: futures_def) next case False have E: "(\<forall>u \<in> sinks_aux_less I D U ys. \<forall>z \<in> Z \<union> set (y # zs). (u, D z) \<notin> I) \<longrightarrow> (xs @ ipurge_tr_aux I D U ys @ (y # zs), Z) \<in> failures P \<longrightarrow> xs @ ys \<in> traces P \<longrightarrow> (xs @ ys @ (y # zs), Z) \<in> failures P" using A . have F: "\<not> (\<exists>u \<in> U \<union> sinks_aux_less I D U ys. (u, D y) \<in> I)" using False by (simp add: sinks_aux_sinks_aux_less) hence "\<forall>u \<in> sinks_aux_less I D U ys. \<forall>z \<in> Z \<union> set zs. (u, D z) \<notin> I" using B by (simp only: sinks_aux_less.simps if_False) moreover have "\<forall>u \<in> sinks_aux_less I D U ys. (u, D y) \<notin> I" using F by simp ultimately have "\<forall>u \<in> sinks_aux_less I D U ys. \<forall>z \<in> Z \<union> set (y # zs). (u, D z) \<notin> I" by simp with E have "(xs @ ipurge_tr_aux I D U ys @ (y # zs), Z) \<in> failures P \<longrightarrow> xs @ ys \<in> traces P \<longrightarrow> (xs @ ys @ (y # zs), Z) \<in> failures P" .. moreover have "(xs @ ipurge_tr_aux I D U ys @ (y # zs), Z) \<in> failures P" using C and False by simp moreover have "(xs @ ys) @ [y] \<in> traces P" using D by simp hence "xs @ ys \<in> traces P" by (rule process_rule_2_traces) ultimately show "(xs @ ys @ (y # zs), Z) \<in> failures P" by simp qed qed lemma ipurge_ref_aux_append: "ipurge_ref_aux I D U (xs @ ys) X = ipurge_ref_aux I D (sinks_aux I D U xs) ys X" by (simp add: ipurge_ref_aux_def sinks_aux_append) lemma ipurge_ref_aux_empty [rule_format]: assumes A: "u \<in> sinks_aux I D U xs" and B: "\<forall>x \<in> X. (u, D x) \<in> I" shows "ipurge_ref_aux I D U xs X = {}" proof (rule equals0I, simp add: ipurge_ref_aux_def, erule conjE) fix x assume "x \<in> X" with B have "(u, D x) \<in> I" .. moreover assume "\<forall>u \<in> sinks_aux I D U xs. (u, D x) \<notin> I" hence "(u, D x) \<notin> I" using A .. ultimately show False by contradiction qed text \<open> \null Here below is the proof of some properties of functions @{term sinks}, @{term ipurge_tr}, and @{term ipurge_ref}. Particularly, using the previous analogous result on function @{term ipurge_tr_aux}, it is shown that in case an event list and its intransitive purge for some domain are both traces of a secure process, and the purged list has a future not affected by any purged event, then that future is also a future for the full event list. \null \<close> lemma sinks_idem: "sinks I D u (ipurge_tr I D u xs) = {}" by (induction xs rule: rev_induct, simp_all) lemma sinks_elem [rule_format]: "v \<in> sinks I D u xs \<longrightarrow> (\<exists>x \<in> set xs. v = D x)" by (induction xs rule: rev_induct, simp_all) lemma ipurge_tr_append: "ipurge_tr I D u (xs @ ys) = ipurge_tr I D u xs @ ipurge_tr_aux I D (insert u (sinks I D u xs)) ys" proof (simp add: sinks_aux_single_dom [symmetric] ipurge_tr_aux_single_dom [symmetric]) qed (simp add: ipurge_tr_aux_append) lemma ipurge_tr_idem: "ipurge_tr I D u (ipurge_tr I D u xs) = ipurge_tr I D u xs" by (simp add: ipurge_tr_aux_single_dom [symmetric] ipurge_tr_aux_idem) lemma ipurge_tr_set: "set (ipurge_tr I D u xs) \<subseteq> set xs" by (simp add: ipurge_tr_aux_single_dom [symmetric] ipurge_tr_aux_set) lemma ipurge_tr_del_failures [rule_format]: assumes S: "secure P I D" and A: "\<forall>v \<in> sinks I D u ys. \<forall>z \<in> Z \<union> set zs. (v, D z) \<notin> I" and B: "(xs @ ipurge_tr I D u ys @ zs, Z) \<in> failures P" and C: "xs @ ys \<in> traces P" shows "(xs @ ys @ zs, Z) \<in> failures P" proof (rule ipurge_tr_aux_del_failures [OF S _ _ C, where U = "{u}"]) qed (simp add: A sinks_aux_less_single_dom, simp add: B ipurge_tr_aux_single_dom) lemma ipurge_ref_append: "ipurge_ref I D u (xs @ ys) X = ipurge_ref_aux I D (insert u (sinks I D u xs)) ys X" proof (simp add: sinks_aux_single_dom [symmetric] ipurge_ref_aux_single_dom [symmetric]) qed (simp add: ipurge_ref_aux_append) lemma ipurge_ref_distrib_inter: "ipurge_ref I D u xs (X \<inter> Y) = ipurge_ref I D u xs X \<inter> ipurge_ref I D u xs Y" proof (simp add: ipurge_ref_def) qed blast lemma ipurge_ref_distrib_union: "ipurge_ref I D u xs (X \<union> Y) = ipurge_ref I D u xs X \<union> ipurge_ref I D u xs Y" proof (simp add: ipurge_ref_def) qed blast lemma ipurge_ref_subset: "ipurge_ref I D u xs X \<subseteq> X" by (subst ipurge_ref_def, rule subsetI, simp) lemma ipurge_ref_subset_union: "ipurge_ref I D u xs (X \<union> Y) \<subseteq> X \<union> ipurge_ref I D u xs Y" proof (simp add: ipurge_ref_def) qed blast lemma ipurge_ref_subset_insert: "ipurge_ref I D u xs (insert x X) \<subseteq> insert x (ipurge_ref I D u xs X)" by (simp only: insert_def ipurge_ref_subset_union) lemma ipurge_ref_empty [rule_format]: assumes A: "v = u \<or> v \<in> sinks I D u xs" and B: "\<forall>x \<in> X. (v, D x) \<in> I" shows "ipurge_ref I D u xs X = {}" proof (subst ipurge_ref_aux_single_dom [symmetric], rule ipurge_ref_aux_empty [of v]) show "v \<in> sinks_aux I D {u} xs" using A by (simp add: sinks_aux_single_dom) next fix x assume "x \<in> X" with B show "(v, D x) \<in> I" .. qed text \<open> \null Finally, in what follows, properties @{term process_prop_1}, @{term process_prop_5}, and @{term process_prop_6} of processes (cf. \<^cite>\<open>"R2"\<close>) are put into the form of introduction rules. \null \<close> lemma process_rule_1: "([], {}) \<in> failures P" proof (simp add: failures_def) have "Rep_process P \<in> process_set" (is "?P' \<in> _") by (rule Rep_process) thus "([], {}) \<in> fst ?P'" by (simp add: process_set_def process_prop_1_def) qed lemma process_rule_5 [rule_format]: "xs \<in> divergences P \<longrightarrow> xs @ [x] \<in> divergences P" proof (simp add: divergences_def) have "Rep_process P \<in> process_set" (is "?P' \<in> _") by (rule Rep_process) hence "\<forall>xs x. xs \<in> snd ?P' \<longrightarrow> xs @ [x] \<in> snd ?P'" by (simp add: process_set_def process_prop_5_def) thus "xs \<in> snd ?P' \<longrightarrow> xs @ [x] \<in> snd ?P'" by blast qed lemma process_rule_6 [rule_format]: "xs \<in> divergences P \<longrightarrow> (xs, X) \<in> failures P" proof (simp add: failures_def divergences_def) have "Rep_process P \<in> process_set" (is "?P' \<in> _") by (rule Rep_process) hence "\<forall>xs X. xs \<in> snd ?P' \<longrightarrow> (xs, X) \<in> fst ?P'" by (simp add: process_set_def process_prop_6_def) thus "xs \<in> snd ?P' \<longrightarrow> (xs, X) \<in> fst ?P'" by blast qed end
/- Copyright © 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Nicolò Cavalleri. -/ import .preamble_results noncomputable theory /-! # Lie groups We define product manifolds and prove smoothness of the classical maps associated with products. ## Main definitions and statements * `smooth.prod_map` : `prod_map` is always smooth. * `smooth_fst` : `prod.fst` is always smooth. * `smooth_snd` : `prod.snd` is always smooth. * `smooth.prod_mk` : `prod_mk` is always smooth. * `smooth_iff_proj_smooth` : A map is smooth iff its projections are. -/ section prod_charted_space section prod_charted_space variables {H : Type*} [topological_space H] {M : Type*} [topological_space M] [charted_space H M] {H' : Type*} [topological_space H'] {M' : Type*} [topological_space M'] [charted_space H' M'] {x : M×M'} /-@[simp] lemma chart_of_prod_eq_prod_of_charts_coe : (chart_at (H×H') x : M × M' → H × H') = (prod.map (chart_at H x.fst) (chart_at H' x.snd)) := rfl @[simp] lemma chart_of_prod_eq_prod_of_charts_coe_symm : ((chart_at (H×H') x).symm : H × H' → M × M') = (prod.map (chart_at H x.fst).symm (chart_at H' x.snd).symm) := rfl @[simp] lemma chart_of_prod_eq_prod_of_charts_coe_to_local_equiv_trans {α : Type*} {β : Type*} {e : local_equiv H α} {e' : local_equiv H' β} : (chart_at (H×H') x).to_local_equiv.trans (e.prod e') = (((chart_at H x.fst).to_local_equiv.trans e).prod ((chart_at H' x.snd).to_local_equiv.trans e')) := begin cases x, ext1, {refl,}, { intro y, refl, }, { ext1 z, cases z, simp only [local_homeomorph.prod_to_local_equiv, local_homeomorph.trans_to_local_equiv, set.prod_mk_mem_set_prod_eq, local_equiv.prod_source], fsplit, { rintro ⟨⟨h1, h2⟩, h3, h4⟩, exact ⟨⟨h1, h3⟩, ⟨h2, h4⟩⟩, }, { rintro ⟨⟨h1, h2⟩, h3, h4⟩, exact ⟨⟨h1, h3⟩, ⟨h2, h4⟩⟩, } } end @[simp] lemma chart_of_prod_eq_prod_of_charts_coe_trans {α : Type*} {β : Type*} [topological_space α] [topological_space β] {e : local_homeomorph H α} {e' : local_homeomorph H' β} : (chart_at (H×H') x).trans (e.prod e') = ((chart_at H x.fst).trans e).prod ((chart_at H' x.snd).trans e') := /- Same proof as above! How can I use it?-/ begin cases x, ext1, {refl,}, { intro y, refl, }, { ext1 z, cases z, simp only [local_homeomorph.prod_to_local_equiv, local_homeomorph.trans_to_local_equiv, set.prod_mk_mem_set_prod_eq, local_equiv.prod_source], fsplit, { rintro ⟨⟨h1, h2⟩, h3, h4⟩, exact ⟨⟨h1, h3⟩, ⟨h2, h4⟩⟩, }, { rintro ⟨⟨h1, h2⟩, h3, h4⟩, exact ⟨⟨h1, h3⟩, ⟨h2, h4⟩⟩, } } end-/ end prod_charted_space section smooth variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {E' : Type*} [normed_group E'] [normed_space 𝕜 E'] {F : Type*} [normed_group F] [normed_space 𝕜 F] {F' : Type*} [normed_group F'] [normed_space 𝕜 F'] {H : Type*} [topological_space H] {H' : Type*} [topological_space H'] {G : Type*} [topological_space G] {G' : Type*} [topological_space G'] {I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'} {J : model_with_corners 𝕜 F G} {J' : model_with_corners 𝕜 F' G'} {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] {M' : Type*} [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] {N : Type*} [topological_space N] [charted_space G N] [smooth_manifold_with_corners J N] {N' : Type*} [topological_space N'] [charted_space G' N'] [smooth_manifold_with_corners J' N'] lemma smooth_in_charts.prod_map {f : M → M'} {g : N → N'} (hf : smooth_in_charts I I' f) (hg : smooth_in_charts J J' g) : smooth_in_charts (I.prod J) (I'.prod J') (prod.map f g) := begin intros x y, simp only [function.comp, ext_chart_at, prod.map, model_with_corners.to_local_equiv_coe_symm, local_homeomorph.coe_coe_symm, local_homeomorph.coe_coe, local_equiv.coe_trans, local_equiv.coe_trans_symm, model_with_corners.to_local_equiv_coe], have f_smooth_at := hf x.fst y.fst, have g_smooth_at := hg x.snd y.snd, clear hf hg, have h := f_smooth_at.map_prod g_smooth_at, clear f_smooth_at g_smooth_at, simp only [function.comp, ext_chart_at, model_with_corners.to_local_equiv_coe_symm, local_homeomorph.coe_coe_symm, local_homeomorph.coe_coe, local_equiv.coe_trans, local_equiv.coe_trans_symm, model_with_corners.to_local_equiv_coe] at h, convert h using 1, clear h, ext1 z, simp only [local_equiv.trans_source, local_equiv.trans_target, model_with_corners.to_local_equiv_coe_symm, set.mem_preimage, set.mem_range, set.mem_inter_eq, set.mem_prod, set.preimage_univ, model_with_corners.target, model_with_corners.source_eq, prod.map_mk, prod.exists, set.inter_univ], split, { rintro ⟨⟨⟨⟨a, b⟩, rfl⟩, h1, h2⟩, h3, h4⟩, rw prod.map_fst at h3, rw prod.map_snd at h4, exact ⟨⟨⟨⟨a, rfl⟩, h1⟩, h3⟩, ⟨⟨b, rfl⟩, h2⟩, h4⟩, }, { rintro ⟨⟨⟨⟨h, hh⟩, h2⟩, h3⟩, ⟨⟨⟨g, hg⟩, h5⟩, h6⟩⟩, sorry, /-refine ⟨⟨⟨h, g, _⟩, ⟨h2, h5⟩⟩, ⟨h3, h6⟩⟩, { ext, exacts [hh, hg], }-/ } end lemma smooth_in_charts_fst : smooth_in_charts (I.prod J) I (@prod.fst M N) := begin intros x y, simp only [function.comp, ext_chart_at, prod.map, model_with_corners.to_local_equiv_coe_symm, local_homeomorph.coe_coe_symm, local_homeomorph.coe_coe, local_equiv.coe_trans, local_equiv.coe_trans_symm, model_with_corners.to_local_equiv_coe], have h1 := (has_groupoid.compatible (times_cont_diff_groupoid ⊤ (I.prod J)) (chart_mem_atlas (H×G) x) (chart_mem_atlas (H×G) (y, x.snd))).1, let s := (prod.map (I.symm) (J.symm) ⁻¹' ((chart_at (model_prod H G) x).to_local_equiv.symm.trans (chart_at (model_prod H G) (y, x.snd)).to_local_equiv).source ∩ set.range (prod.map I J)), have hs : (s ⊆ (λ (x_1 : E × F), (I ((chart_at (model_prod H G) (y, x.snd)) (((chart_at (model_prod H G) x).symm) ((I.symm) x_1.fst, (J.symm) x_1.snd))).fst, J ((chart_at (model_prod H G) (y, x.snd)) (((chart_at (model_prod H G) x).symm) ((I.symm) x_1.fst, (J.symm) x_1.snd))).snd)) ⁻¹' (set.univ)) := begin simp only [set.subset_univ, set.preimage_univ], end, have h2 := times_cont_diff_on.comp (times_cont_diff.times_cont_diff_on times_cont_diff_fst) h1 hs, simp only [function.comp, prod.map, model_with_corners_prod_coe_symm, local_homeomorph.trans_to_local_equiv, local_homeomorph.coe_trans, model_with_corners_prod_coe, local_homeomorph.symm_to_local_equiv] at h2, convert h2 using 1, clear h1 hs h2, ext1 z, simp only [prod.map, set.mem_preimage, set.mem_range, set.mem_inter_eq, prod.exists], fsplit, { rintro ⟨⟨⟨⟨a, h_a⟩, b, h_b⟩, h1, h2⟩, h3, h4⟩, simp only [model_with_corners.to_local_equiv_coe_symm, model_with_corners_prod_coe_symm, prod.map_fst] at h1 h2, rw local_equiv.symm_target at h3, simp only [set.mem_univ, set.preimage_univ, model_with_corners.source_eq] at h4, cases z, simp only [prod.map_mk] at h_a h_b h1 h2 h3, refine ⟨⟨⟨h1, h2⟩, _⟩, _⟩, { simp only [set.mem_preimage, local_homeomorph.coe_coe_symm, local_equiv.symm_symm, prod.map_mk], refine ⟨h3, _⟩, apply local_homeomorph.map_target, /- WHY DID NOT SIMP DO IT BY ITSELF? IT TOOK ME TWO DAYS-/ exact h2, }, { use [a, b], ext1, exacts [h_a, h_b], } }, { rintro ⟨⟨⟨h1, h2⟩, h3, h4⟩, w, g, rfl⟩, repeat {rw model_with_corners.left_inv at h1 h2}, simp only [local_homeomorph.coe_coe_symm, local_equiv.symm_symm, model_with_corners.left_inv] at h3 h4, refine ⟨⟨_, _⟩,_⟩, { /-use [w.1, g],-/ sorry, }, { simp only [model_with_corners.to_local_equiv_coe_symm, set.mem_preimage, model_with_corners_prod_coe_symm, model_with_corners.left_inv, prod.map_mk], exact ⟨h1, h2⟩, }, { simp only [local_equiv.trans_source, local_homeomorph.prod_coe, local_homeomorph.prod_symm, prod_charted_space_chart_at, model_with_corners_prod_coe_symm, set.preimage_univ, model_with_corners.left_inv, model_with_corners.source_eq, prod.map_mk, set.inter_univ], exact h3, } } end lemma smooth_in_charts_snd : smooth_in_charts (I.prod J) J (@prod.snd M N) := begin intros x y, simp only [function.comp, ext_chart_at, prod.map, model_with_corners.to_local_equiv_coe_symm, local_homeomorph.coe_coe_symm, local_homeomorph.coe_coe, model_with_corners_prod_coe_symm, local_equiv.coe_trans, local_equiv.coe_trans_symm, model_with_corners.to_local_equiv_coe], have h1 := (has_groupoid.compatible (times_cont_diff_groupoid ⊤ (I.prod J)) (chart_mem_atlas (H×G) x) (chart_mem_atlas (H×G) (x.fst, y))).1, let s := (prod.map (I.symm) (J.symm) ⁻¹' ((chart_at (model_prod H G) x).to_local_equiv.symm.trans (chart_at (model_prod H G) (x.fst, y)).to_local_equiv).source ∩ set.range (prod.map I J)), have hs : (s ⊆ (λ (x_1 : E × F), (I ((chart_at (model_prod H G) (x.fst, y)) (((chart_at (model_prod H G) x).symm) ((I.symm) x_1.fst, (J.symm) x_1.snd))).fst, J ((chart_at (model_prod H G) (x.fst, y)) (((chart_at (model_prod H G) x).symm) ((I.symm) x_1.fst, (J.symm) x_1.snd))).snd)) ⁻¹' (set.univ)) := by simp only [set.subset_univ, set.preimage_univ], have h2 := times_cont_diff_on.comp (times_cont_diff.times_cont_diff_on times_cont_diff_snd) h1 hs, simp only [function.comp, prod.map, model_with_corners_prod_coe_symm, local_homeomorph.trans_to_local_equiv, local_homeomorph.coe_trans, model_with_corners_prod_coe, local_homeomorph.symm_to_local_equiv] at h2, convert h2 using 1, clear h1 hs h2, ext1 z, simp only [prod.map, set.mem_preimage, set.mem_range, set.mem_inter_eq, prod.exists], split, { rintro ⟨⟨⟨⟨a, h_a⟩, b, h_b⟩, h1, h2⟩, h3, h4⟩, simp only [model_with_corners.to_local_equiv_coe_symm, model_with_corners_prod_coe_symm, prod.map_fst] at h1 h2, rw local_equiv.symm_target at h3, simp only [set.mem_univ, set.preimage_univ, model_with_corners.source_eq] at h4, cases z, simp only [prod.map_mk] at h_a h_b h1 h2 h3, refine ⟨⟨⟨h1, h2⟩, ⟨_, h3⟩⟩, _⟩, { simp only [local_homeomorph.coe_coe_symm, local_equiv.symm_symm, prod.map_mk], apply local_homeomorph.map_target, exact h1, }, { use [a, b], ext1, exacts [h_a, h_b], } }, { rintro ⟨⟨⟨h1, h2⟩, h3, h4⟩, w, g, rfl⟩, repeat {rw model_with_corners.left_inv at h1 h2}, simp only [local_homeomorph.coe_coe_symm, local_equiv.symm_symm, model_with_corners.left_inv] at h3 h4, sorry, /-refine ⟨⟨⟨⟨w, rfl⟩, ⟨g, rfl⟩⟩, _⟩, _⟩, { simp only [model_with_corners.to_local_equiv_coe_symm, set.mem_preimage, model_with_corners_prod_coe_symm, model_with_corners.left_inv, prod.map_mk], exact ⟨h1, h2⟩, }, { cases x, simp only [model_with_corners.left_inv], refine ⟨h4, _⟩, simp only [model_with_corners.source_eq], }-/ } end variables {E'' : Type*} [normed_group E''] [normed_space 𝕜 E''] {H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''} {M'' : Type*} [topological_space M''] [charted_space H'' M''] lemma smooth_in_charts.prod_mk {f : M → M'} {g : M → N'} (hf : smooth_in_charts I I' f) (hg : smooth_in_charts I J' g) : smooth_in_charts I (I'.prod J') (λx, (f x, g x)) := begin intros x y, simp only [function.comp, model_with_corners_prod_to_local_equiv] with mfld_simps, let s := ((ext_chart_at I x).target ∩ ((ext_chart_at I x).symm) ⁻¹' (f ⁻¹' (ext_chart_at I' y.fst).source)), let t := ((ext_chart_at I x).target ∩ ((ext_chart_at I x).symm) ⁻¹' (g ⁻¹' (ext_chart_at J' y.snd).source)), let inter := s ∩ t, have hs : (inter ⊆ s) := by exact set.inter_subset_left s t, have ht : (inter ⊆ t) := by exact set.inter_subset_right s t, have f_smooth_at := times_cont_diff_on.mono (hf x y.fst) hs, have g_smooth_at := times_cont_diff_on.mono (hg x y.snd) ht, clear hf hg, have h := times_cont_diff_on.prod f_smooth_at g_smooth_at, clear f_smooth_at g_smooth_at, simp only [function.comp, ext_chart_at, model_with_corners.to_local_equiv_coe_symm, local_homeomorph.coe_coe_symm, local_homeomorph.coe_coe, local_equiv.coe_trans, local_equiv.coe_trans_symm, model_with_corners.to_local_equiv_coe] at h, convert h using 1, clear h, /- Why does unfold s not work? I don't want to use change. -/ simp only [inter, s, t, function.comp] with mfld_simps, ext1 z, fsplit, { rintro ⟨⟨⟨w, rfl⟩, h1⟩, h2, h3⟩, exact ⟨⟨⟨⟨w, rfl⟩, h1⟩, h2⟩, ⟨⟨w, rfl⟩, h1⟩, h3⟩, }, { rintro ⟨⟨⟨⟨w, rfl⟩, h1⟩, h2⟩, ⟨⟨v, h_v⟩, h3⟩, h4⟩, refine ⟨⟨⟨w, rfl⟩, h1⟩, h2, h4⟩, } end lemma smooth_in_charts_iff_proj_smooth_in_charts {f : M → M' × N'} : (smooth_in_charts I (I'.prod J') f) ↔ (smooth_in_charts I I' (prod.fst ∘ f)) ∧ (smooth_in_charts I J' (prod.snd ∘ f)) := begin split, { intro h, exact ⟨smooth_in_charts.comp smooth_in_charts_fst h, smooth_in_charts.comp smooth_in_charts_snd h⟩ }, { rintro ⟨h_fst, h_snd⟩, have h := smooth_in_charts.prod_mk h_fst h_snd, simp only [prod.mk.eta] at h, /- What is simp doing? I would like to find a way to replace it. -/ exact h, } end lemma smooth_in_charts.map_diag : smooth_in_charts I (I.prod I) (map.diag M) := smooth_in_charts_id.prod_mk smooth_in_charts_id end smooth end prod_charted_space
open Lean instance : IsAssociative (α := Nat) HAdd.hAdd := ⟨Nat.add_assoc⟩ instance : IsCommutative (α := Nat) HAdd.hAdd := ⟨Nat.add_comm⟩ instance : IsNeutral HAdd.hAdd 0 := ⟨Nat.zero_add, Nat.add_zero⟩ instance : IsAssociative (α := Nat) HMul.hMul := ⟨Nat.mul_assoc⟩ instance : IsCommutative (α := Nat) HMul.hMul := ⟨Nat.mul_comm⟩ instance : IsNeutral HMul.hMul 1 := ⟨Nat.one_mul, Nat.mul_one⟩ @[simp] theorem succ_le_succ_iff {x y : Nat} : x.succ ≤ y.succ ↔ x ≤ y := ⟨Nat.le_of_succ_le_succ, Nat.succ_le_succ⟩ @[simp] theorem add_le_add_right_iff {x y z : Nat} : x + z ≤ y + z ↔ x ≤ y := by induction z <;> simp_all [Nat.add_succ] set_option linter.unusedVariables false in theorem le_ext : ∀ {x y : Nat} (h : ∀ z, z ≤ x ↔ z ≤ y), x = y | 0, 0, _ => rfl | x+1, y+1, h => congrArg (· + 1) <| le_ext fun z => have := h (z + 1); by simp_all | 0, y+1, h => have := h 1; by simp_all | x+1, 0, h => have := h 1; by simp_all theorem le_or_le : ∀ (a b : Nat), a ≤ b ∨ b ≤ a | x+1, y+1 => by simp [le_or_le x y] | 0, 0 | x+1, 0 | 0, y+1 => by simp theorem le_of_not_le {a b : Nat} (h : ¬ a ≤ b) : b ≤ a := match le_or_le a b with | .inl ab => (h ab).rec | .inr ba => ba @[simp] theorem le_max_iff {x y z : Nat} : x ≤ max y z ↔ x ≤ y ∨ x ≤ z := by simp only [Nat.max_def] split · exact Iff.intro .inr fun | .inl xy => Nat.le_trans ‹_› ‹_› | .inr xz => ‹_› · exact Iff.intro .inl fun | .inl xy => ‹_› | .inr xz => Nat.le_trans ‹_› (le_of_not_le ‹_›) theorem or_assoc : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := by by_cases p <;> by_cases q <;> by_cases r <;> simp_all theorem or_comm : p ∨ q ↔ q ∨ p := by by_cases p <;> by_cases q <;> simp_all theorem max_assoc (n m k : Nat) : max (max n m) k = max n (max m k) := le_ext (by simp [or_assoc]) theorem max_comm (n m : Nat) : max n m = max m n := le_ext (by simp [or_comm]) theorem max_idem (n : Nat) : max n n = n := le_ext (by simp) theorem Nat.zero_max (n : Nat) : max 0 n = n := by simp [Nat.max_def] theorem Nat.max_zero (n : Nat) : max n 0 = n := by rw [max_comm, Nat.zero_max] instance : IsAssociative (α := Nat) max := ⟨max_assoc⟩ instance : IsCommutative (α := Nat) max := ⟨max_comm⟩ instance : IsIdempotent (α := Nat) max := ⟨max_idem⟩ instance : IsNeutral max 0 := ⟨Nat.zero_max, Nat.max_zero⟩ instance : IsAssociative And := ⟨λ p q r => propext ⟨λ ⟨⟨hp, hq⟩, hr⟩ => ⟨hp, hq, hr⟩, λ ⟨hp, hq, hr⟩ => ⟨⟨hp, hq⟩, hr⟩⟩⟩ instance : IsCommutative And := ⟨λ p q => propext ⟨λ ⟨hp, hq⟩ => ⟨hq, hp⟩, λ ⟨hq, hp⟩ => ⟨hp, hq⟩⟩⟩ instance : IsIdempotent And := ⟨λ p => propext ⟨λ ⟨hp, _⟩ => hp, λ hp => ⟨hp, hp⟩⟩⟩ instance : IsNeutral And True := ⟨λ p => propext ⟨λ ⟨_, hp⟩ => hp, λ hp => ⟨True.intro, hp⟩⟩, λ p => propext ⟨λ ⟨hp, _⟩ => hp, λ hp => ⟨hp, True.intro⟩⟩⟩ instance : IsAssociative Or := ⟨by simp [or_assoc]⟩ instance : IsCommutative Or := ⟨λ p q => propext ⟨λ hpq => hpq.elim Or.inr Or.inl, λ hqp => hqp.elim Or.inr Or.inl⟩⟩ instance : IsIdempotent Or := ⟨λ p => propext ⟨λ hp => hp.elim id id, Or.inl⟩⟩ instance : IsNeutral Or False := ⟨λ p => propext ⟨λ hfp => hfp.elim False.elim id, Or.inr⟩, λ p => propext ⟨λ hpf => hpf.elim id False.elim, Or.inl⟩⟩ example (x y z : Nat) : x + y + 0 + z = z + (x + y) := by ac_rfl example (x y z : Nat) : (x + y) * (0 + z) = (x + y) * z:= by ac_rfl example (x y z : Nat) : (x + y) * (0 + z) = 1 * z * (y + 0 + x) := by ac_rfl theorem ex₁ (x y z : Nat) : max (0 + (max x (max z (max (0 + 0) ((max 1 0) + 0 + 0) * y)))) y = max (max x y) z := by ac_rfl #print ex₁ example (x y : Nat) : 1 + 0 + 0 = 0 + 1 := by ac_rfl example (x y : Nat) : (x + y = 42) = (y + x = 42) := by ac_rfl example (x y : Nat) (P : Prop) : (x + y = 42 → P) = (y + x = 42 → P) := by ac_rfl inductive Vector (α : Type u) : Nat → Type u where | nil : Vector α 0 | cons : α → Vector α n → Vector α (n+1) def f (n : Nat) (xs : Vector α n) := xs -- Repro: Dependent types trigger incorrect proofs theorem ex₂ (n m : Nat) (xs : Vector α (n+m)) (ys : Vector α (m+n)) : (f (n+m) xs, f (m+n) ys, n+m) = (f (n+m) xs, f (m+n) ys, m+n) := by ac_rfl -- Repro: Binders also trigger invalid proofs theorem ex₃ (n : Nat) : (fun x => n + x) = (fun x => x + n) := by ac_rfl #print ex₃ -- Repro: the Prop universe doesn't work example (p q : Prop) : (p ∨ p ∨ q ∧ True) = (q ∨ p) := by ac_rfl -- Repro: missing withContext example : ∀ x : Nat, x = x := by intro x; ac_rfl
theory Munkres imports "HOL-Analysis.Analysis" begin (* problem_number:13_1 natural language statement: Let $X$ be a topological space; let $A$ be a subset of $X$. Suppose that for each $x \in A$ there is an open set $U$ containing $x$ such that $U \subset A$. Show that $A$ is open in $X$. lean statement: theorem exercise_13_1 (X : Type* ) [topological_space X] (A : set X) (h1 : \<forall> x \<in> A, \<exists> U : set X, x \<in> U \<and> is_open U \<and> U \<subseteq> A) : is_open A := begin have : A = \<Union> x, \<Union> h : x \<in> A, (classical.some (h1 x h)), { ext x, simp, split, { intro xA, use [x, xA], exact (classical.some_spec (h1 x xA)).1}, { rintros \<langle>y, yA, yspec\<rangle>, have h := classical.some_spec (h1 y yA), exact h.2.2 yspec }, }, rw this, apply is_open_Union, intro x, apply is_open_Union, intro xA, have h := classical.some_spec (h1 x xA), exact h.2.1 end codex statement: theorem subset_of_open_subset_is_open: fixes T::"'a topology" and A::"'a set" assumes "A \<subseteq> topspace T" "\<forall>x\<in>A. \<exists> U \<subseteq> topspace T. openin T U \<and> x\<in>U \<and> U \<subseteq> A" shows "openin T A" Our comment on the codex statement: very good! *) theorem exercise_13_1: (*FIRST ASSUMPTION NOT NECESSARY*) fixes T::"'a topology" and A::"'a set" assumes "A \<subseteq> topspace T" "\<forall>x\<in>A. \<exists>U. openin T U \<and> x\<in>U \<and> U \<subseteq> A" shows "openin T A" using assms(2) openin_subopen by fastforce (* problem_number:13_5a natural language statement: Show that if $\mathcal{A}$ is a basis for a topology on $X$, then the topology generated by $\mathcal{A}$ equals the intersection of all topologies on $X$ that contain $\mathcal{A}$. lean statement: theorem exercise_13_5a {X : Type*} [topological_space X] (A : set (set X)) (hA : is_topological_basis A) : generate_from A = generate_from (sInter {T | is_topology X T \<and> A \<subseteq> T}) := codex statement: theorem topology_generated_by_basis_eq_intersection_of_topologies_containing_basis: fixes X::"'a set" and A::"'a set set" assumes "topological_basis A" shows "topology_generated_by A = \<Inter>T. topological_space T \<and> A \<subseteq> sets T" Our comment on the codex statement: "basis of a topology" is not directly available *) theorem exercise_13_5a: undefined oops (* problem_number:13_5b natural language statement: Show that if $\mathcal{A}$ is a subbasis for a topology on $X$, then the topology generated by $\mathcal{A}$ equals the intersection of all topologies on $X$ that contain $\mathcal{A}$. lean statement: theorem exercise_13_5b {X : Type*} [t : topological_space X] (A : set (set X)) (hA : t = generate_from A) : generate_from A = generate_from (sInter {T | is_topology X T \<and> A \<subseteq> T}) := codex statement: theorem topology_generated_by_subbasis_eq_intersection_of_topologies_containing_subbasis: fixes X::"'a set" and A::"'a set set" assumes "subbasis A X" shows "topology_generated_by A = \<Inter>T. topology T \<and> A \<subseteq> T" Our comment on the codex statement: mostly wrong. This was very tricky to get right, and I proved it to check *) theorem exercise_13_5b: (*"subbasis of a topology" is not directly available*) shows "topology_generated_by \<A> = topology(\<lambda>S. \<forall>T \<in> {T::'a topology. \<A> \<subseteq> {S. openin T S}}. openin T S)" proof - have istop: "istopology (\<lambda>S. \<forall>T. \<A> \<subseteq> Collect (openin T) \<longrightarrow> openin T S)" by (simp add: istopology_def openin_Int openin_Union) show ?thesis apply (simp add: topology_eq openin_topology_generated_by_iff topology_inverse' [OF istop]) by (metis Ball_Collect Basis generate_topology_on_coarsest istopology_generate_topology_on istopology_openin topology_inverse') qed (* problem_number:16_1 natural language statement: Show that if $Y$ is a subspace of $X$, and $A$ is a subset of $Y$, then the topology $A$ inherits as a subspace of $Y$ is the same as the topology it inherits as a subspace of $X$. lean statement: theorem exercise_16_1 {X : Type*} [topological_space X] (Y : set X) (A : set Y) : \<forall> U : set A, is_open U \<longleftrightarrow> is_open (subtype.val '' U) := codex statement: theorem subspace_topology_of_subspace_eq_subspace_topology_of_superspace: fixes X::"'a::topological_space set" and Y::"'a::topological_space set" and A::"'a::topological_space set" assumes "subspace Y" "A \<subseteq> Y" shows "subtopology (subspace_topology Y A) (subspace_topology X A)" Our comment on the codex statement: Wrong and in particular it keeps wanting to use the typeclass-based versions *) theorem exercise_16_1: assumes "Y = subtopology X S" "A \<subseteq> topspace Y" shows "subtopology X A = subtopology Y A" by (metis assms inf.absorb2 le_inf_iff subtopology_subtopology topspace_subtopology) (* problem_number:16_4 natural language statement: A map $f: X \rightarrow Y$ is said to be an open map if for every open set $U$ of $X$, the set $f(U)$ is open in $Y$. Show that $\pi_{1}: X \times Y \rightarrow X$ and $\pi_{2}: X \times Y \rightarrow Y$ are open maps. lean statement: theorem exercise_16_4 {X Y : Type*} [topological_space X] [topological_space Y] (\<pi>_1 : X \<times> Y \<rightarrow> X) (\<pi>_2 : X \<times> Y \<rightarrow> Y) (h_1 : \<pi>_1 = prod.fst) (h_2 : \<pi>_2 = prod.snd) : is_open_map \<pi>_1 \<and> is_open_map \<pi>_2 := codex statement: theorem open_map_of_prod_space: fixes X Y::"'a::topological_space" shows "open_map (prod_topology X Y) (X \<times> Y) (\<lambda>x. fst x)" "open_map (prod_topology X Y) (X \<times> Y) (\<lambda>x. snd x)" Our comment on the codex statement: partly right. Again used the typeclass version *) theorem exercise_16_4: fixes X Y::"'a topology" shows "open_map (prod_topology X Y) X fst" "open_map (prod_topology X Y) Y snd" by (auto simp: open_map_fst open_map_snd) (* problem_number:16_6 natural language statement: Show that the countable collection \[\{(a, b) \times (c, d) | a < b \text{ and } c < d, \text{ and } a, b, c, d \text{ are rational}\}\] is a basis for $\mathbb{R}^2$. lean statement: theorem exercise_16_6 (S : set (set (\<real> \<times> \<real>))) (hS : \<forall> s, s \<in> S \<rightarrow> \<exists> a b c d, (rational a \<and> rational b \<and> rational c \<and> rational d \<and> s = {x | \<exists> x_1 x_2, x = (x_1, x_2) \<and> a < x_1 \<and> x_1 < b \<and> c < x_2 \<and> x_2 < d})) : is_topological_basis S := codex statement: theorem basis_of_rational_interval: fixes a b c d::rat assumes "a < b" "c < d" shows "openin (subtopology euclidean_space (UNIV::real^2 set)) ((a, b) \<times> (c, d))" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_16_6: defines "\<B> \<equiv> { {a<..<b::real} \<times> {c<..<d::real} | a b c d. a \<in> \<rat> \<and> b \<in> \<rat> \<and> c \<in> \<rat> \<and> d \<in> \<rat> \<and> a<b \<and> c<d }" shows "topology_generated_by \<B> = euclidean" oops (* problem_number:16_9 natural language statement: Show that the dictionary order topology on the set $\mathbb{R} \times \mathbb{R}$ is the same as the product topology $\mathbb{R}_d \times \mathbb{R}$, where $\mathbb{R}_d$ denotes $\mathbb{R}$ in the discrete topology. lean statement: codex statement: theorem dictionary_order_topology_eq_product_topology: shows "dictionary_order_topology = product_topology (discrete_topology::'a::linorder_topology topology) (discrete_topology::'b::linorder_topology topology)" Our comment on the codex statement: wrong, but this was difficult *) definition "dictless x y \<equiv> fst x < fst y \<or> fst x \<le> fst y \<and> snd x < snd y" definition "dict_basis \<equiv> range (\<lambda>a. {x. dictless x a}) \<union> range (\<lambda>a. {x. dictless a x})" theorem exercise_16_9: shows "topology_generated_by dict_basis = prod_topology (discrete_topology (UNIV::real set)) euclidean" oops (* problem_number:17_2 natural language statement: Show that if $A$ is closed in $Y$ and $Y$ is closed in $X$, then $A$ is closed in $X$. lean statement: codex statement: theorem closed_of_closed_subset: fixes A::"'a::topological_space set" and X::"'b::topological_space set" assumes "closed_in (subtopology (top_of_set X) Y) A" "closed_in (top_of_set X) Y" shows "closed_in (top_of_set X) A" Our comment on the codex statement: not bad but again the typeclass issue *) theorem exercise_17_2: assumes "closedin (subtopology X Y) A" "closedin X Y" shows "closedin X A" using assms closedin_closed_subtopology by blast (* problem_number:17_3 natural language statement: Show that if $A$ is closed in $X$ and $B$ is closed in $Y$, then $A \times B$ is closed in $X \times Y$. lean statement: codex statement: theorem closed_of_closed_times_closed: fixes A::"'a::topological_space set" and B::"'b::topological_space set" assumes "closedin (top_of_set (UNIV::'a set)) A" "closedin (top_of_set (UNIV::'b set)) B" shows "closedin (top_of_set (UNIV::('a\<times>'b) set)) (A\<times>B)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_17_3: assumes "closedin X A" "closedin Y B" shows "closedin (prod_topology X Y) (A\<times>B)" by (simp add: assms closedin_prod_Times_iff) (* problem_number:17_4 natural language statement: Show that if $U$ is open in $X$ and $A$ is closed in $X$, then $U-A$ is open in $X$, and $A-U$ is closed in $X$. lean statement: theorem exercise_17_4 {X : Type*} [topological_space X] (U A : set X) (hU : is_open U) (hA : is_closed A) : is_open (U \ A) \<and> is_closed (A \ U) := codex statement: theorem open_of_open_diff_closed: fixes U A::"'a::topological_space set" assumes "open U" "closed A" shows "open (U - A)" Our comment on the codex statement: Not bad but it is the type class version *) theorem exercise_17_4: assumes "openin X U" "closedin X A" shows "openin X (U - A) \<and> closedin X (A - U)" by (simp add: assms closedin_diff openin_diff) (* problem_number:18_8a natural language statement: Let $Y$ be an ordered set in the order topology. Let $f, g: X \rightarrow Y$ be continuous. Show that the set $\{x \mid f(x) \leq g(x)\}$ is closed in $X$. lean statement: theorem exercise_18_8a {X Y : Type*} [topological_space X] [topological_space Y] [linear_order Y] [order_topology Y] {f g : X \<rightarrow> Y} (hf : continuous f) (hg : continuous g) : is_closed {x | f x \<le> g x} := codex statement: theorem closed_of_continuous_leq: fixes f g::"'a::topological_space \<Rightarrow> 'b::order_topology" assumes "continuous_on UNIV f" "continuous_on UNIV g" shows "closed {x. f x \<le> g x}" Our comment on the codex statement: perfect except it is for type classes *) definition "order_topology \<equiv> topology_generated_by (range (\<lambda>a. {..<a}) \<union> range (\<lambda>a::'a::linorder. {a<..}))" theorem exercise_18_8a: fixes A :: "'a::linorder set" defines "X \<equiv> order_topology" defines "Y \<equiv> subtopology X A" assumes "continuous_map X Y f" "continuous_map X Y g" shows "closedin Y {x. f x \<le> g x}" oops theorem closed_of_continuous_leq: fixes f g::"'a::topological_space \<Rightarrow> 'b::order_topology" assumes "continuous_on UNIV f" "continuous_on UNIV g" shows "closed {x. f x \<le> g x}" oops (* problem_number:18_8b natural language statement: Let $Y$ be an ordered set in the order topology. Let $f, g: X \rightarrow Y$ be continuous. Let $h: X \rightarrow Y$ be the function $h(x)=\min \{f(x), g(x)\}.$ Show that $h$ is continuous. lean statement: theorem exercise_18_8b {X Y : Type*} [topological_space X] [topological_space Y] [linear_order Y] [order_topology Y] {f g : X \<rightarrow> Y} (hf : continuous f) (hg : continuous g) : continuous (\<lambda> x, min (f x) (g x)) := codex statement: theorem continuous_of_continuous_min: fixes f g::"'a::topological_space \<Rightarrow> 'b::order_topology" assumes "continuous_on UNIV f" "continuous_on UNIV g" shows "continuous_on UNIV (\<lambda>x. min (f x) (g x))" Our comment on the codex statement: type classes *) theorem exercise_18_8b: fixes A :: "'a::linorder set" defines "X \<equiv> order_topology" defines "Y \<equiv> subtopology X A" assumes "continuous_map X Y f" "continuous_map X Y g" defines "h \<equiv> \<lambda>x. min (f x) (g x)" shows "continuous_map X Y h" oops (* problem_number:18_13 natural language statement: Let $A \subset X$; let $f: A \rightarrow Y$ be continuous; let $Y$ be Hausdorff. Show that if $f$ may be extended to a continuous function $g: \bar{A} \rightarrow Y$, then $g$ is uniquely determined by $f$. lean statement: theorem exercise_18_13 {X : Type*} [topological_space X] {Y : Type*} [topological_space Y] [t2_space Y] {A : set X} {f : A \<rightarrow> Y} (hf : continuous f) (g : closure A \<rightarrow> Y) (g_con : continuous g) : \<forall> (g' : closure A \<rightarrow> Y), continuous g' \<rightarrow> (\<forall> (x : closure A), g x = g' x) := codex statement: theorem unique_continuous_extension_of_continuous_on_closure: fixes f::"'a::t1_space \<Rightarrow> 'b::t2_space" and g::"'a::t1_space \<Rightarrow> 'b::t2_space" assumes "continuous_on A f" "continuous_on (closure A) g" "g|`A = f" shows "g = f" Our comment on the codex statement: it went wrong and it is the type class version *) theorem exercise_18_13: fixes A :: "'a set" and X :: "'a topology" defines "A' \<equiv> subtopology X (X closure_of A)" assumes "A \<subseteq> topspace X" "Hausdorff_space Y" "continuous_map (subtopology X A) Y f" and "continuous_map A' Y g1" "restrict g1 A = f" and "continuous_map A' Y g2" "restrict g2 A = f" shows "g1 = g2" oops (* problem_number:19_4 natural language statement: Show that $(X_1 \times \cdots \times X_{n-1}) \times X_n$ is homeomorphic with $X_1 \times \cdots \times X_n$. lean statement: codex statement: theorem homeomorphic_of_prod_prod_prod: fixes X::"'a::topological_space set" and Y::"'b::topological_space set" and Z::"'c::topological_space set" assumes "topological_space X" "topological_space Y" "topological_space Z" shows "X \<times> Y \<times> Z \<cong> (X \<times> Y) \<times> Z" Our comment on the codex statement: kind of model with kind of muddled with the type class setup *) theorem exercise_19_4: (*only for n=3: trickery is needed to express the general case, cf DirProd_list in Algebra/Weak_Morphisms*) shows "prod_topology (prod_topology X1 X2) X3 homeomorphic_space prod_topology X1 (prod_topology X2 X3)" oops (* problem_number:19_6a natural language statement: Let $\mathbf{x}_1, \mathbf{x}_2, \ldots$ be a sequence of the points of the product space $\prod X_\alpha$. Show that this sequence converges to the point $\mathbf{x}$ if and only if the sequence $\pi_\alpha(\mathbf{x}_i)$ converges to $\pi_\alpha(\mathbf{x})$ for each $\alpha$. lean statement: theorem exercise_19_6a {n : \<nat>} {f : fin n \<rightarrow> Type*} {x : \<nat> \<rightarrow> \<pi>a, f a} (y : \<pi>i, f i) [\<pi>a, topological_space (f a)] : tendsto x at_top (\<N> y) \<longleftrightarrow> \<forall> i, tendsto (\<lambda> j, (x j) i) at_top (\<N> (y i)) := codex statement: theorem convergent_of_prod_convergent: fixes X::"('a::metric_space) set" and f::"nat \<Rightarrow> 'a" assumes "\<forall>n. f n \<in> X" "\<forall>n. (\<forall>x\<in>X. (f n x) = (f (n+1) x)) \<longrightarrow> (f n = f (n+1))" shows "convergent f" Our comment on the codex statement: just no. *) theorem exercise_19_6a: "limitin (product_topology X I) x a sequentially \<longleftrightarrow> (\<forall>i\<in>I. limitin (X i) (x i) (a i) sequentially)" oops (* problem_number:19_9 natural language statement: Show that the choice axiom is equivalent to the statement that for any indexed family of nonempty sets, $\{A_\alpha\}_{\alpha \in J}$ with $J \neq 0$, the cartesian product \[\prod_{\alpha \in J} A_\alpha\] is not empty. lean statement: codex statement: theorem choice_iff_cartesian_product_not_empty: fixes J::"'a set" and A::"'a \<Rightarrow> 'b set" assumes "J \<noteq> \<emptyset>" shows "\<exists>f. \<forall>x\<in>J. f x \<in> A x \<Longleftrightarrow> (\<exists>f. \<forall>x\<in>J. f x \<in> A x)" Our comment on the codex statement: not really *) theorem exercise_19_9: (* not expressible in full because AC is included in Isabelle/HOL*) assumes "J \<noteq> {}" "\<And>j. j \<in> J \<Longrightarrow> A j \<noteq> {}" shows "Pi J A \<noteq> {}" by (simp add: assms(2)) (* problem_number:20_2 natural language statement: Show that $\mathbb{R} \times \mathbb{R}$ in the dictionary order topology is metrizable. lean statement: theorem exercise_20_2 [topological_space (\<real> \<times>ₗ \<real>)] [order_topology (\<real> \<times>ₗ \<real>)] : metrizable_space (\<real> \<times>ₗ \<real>) := codex statement: theorem metrizable_of_dictionary_order_topology: fixes X::"real set" assumes "X = UNIV" shows "metrizable_space (order_topology (dictionary_order X))" Our comment on the codex statement: it kind of assumes we have everything *) theorem exercise_20_2: undefined oops (* shows "topology_generated_by dict_basis = XXX" NOT POSSIBLE until we get an abstract formalisation of metric spaces*) (* problem_number:20_5 natural language statement: Let $\mathbb{R}^\infty$ be the subset of $\mathbb{R}^\omega$ consisting of all sequences that are eventually zero. What is the closure of $\mathbb{R}^\infty$ in $\mathbb{R}^\omega$ in the uniform topology? Justify your answer. lean statement: codex statement: theorem closure_of_eventually_zero_seq_is_all_seq: fixes f::"nat \<Rightarrow> 'a::real_normed_vector" assumes "\<forall>n. \<exists>m. \<forall>k. m \<le> k \<longrightarrow> f k = 0" shows "closure {f. \<forall>n. \<exists>m. \<forall>k. m \<le> k \<longrightarrow> f k = 0} = UNIV" Our comment on the codex statement: nonsense *) theorem exercise_20_5: undefined oops (* this is a "WHAT-IS" exercise with no actual theorem statement*) (* problem_number:21_6a natural language statement: Define $f_{n}:[0,1] \rightarrow \mathbb{R}$ by the equation $f_{n}(x)=x^{n}$. Show that the sequence $\left(f_{n}(x)\right)$ converges for each $x \in[0,1]$. lean statement: theorem exercise_21_6a (f : \<nat> \<rightarrow> I \<rightarrow> \<real> ) (h : \<forall> x n, f n x = x ^ n) : \<forall> x, \<exists> y, tendsto (\<lambda> n, f n x) at_top (\<N> y) := codex statement: theorem converges_of_power_seq: fixes x::real assumes "0 \<le> x \<and> x \<le> 1" shows "convergent (\<lambda>n. x^n)" Our comment on the codex statement: perfect! *) theorem exercise_21_6a: fixes x::real assumes "0 \<le> x \<and> x \<le> 1" shows "convergent (\<lambda>n. x^n)" using assms convergent_realpow by presburger (* problem_number:21_6b natural language statement: Define $f_{n}:[0,1] \rightarrow \mathbb{R}$ by the equation $f_{n}(x)=x^{n}$. Show that the sequence $\left(f_{n}\right)$ does not converge uniformly. lean statement: theorem exercise_21_6b (f : \<nat> \<rightarrow> I \<rightarrow> \<real> ) (h : \<forall> x n, f n x = x ^ n) : \<not> \<exists> f₀, tendsto_uniformly f f₀ at_top := codex statement: theorem not_uniformly_convergent_of_power_function: fixes n::nat shows "\<forall>\<epsilon>>0. \<exists>x. \<forall>n. dist (x^n) (x^(n+1)) > \<epsilon>" Our comment on the codex statement: Interesting *) theorem exercise_21_6b: shows "\<not> uniformly_convergent_on {0..1} (\<lambda>x n. x^n)" oops (* problem_number:21_8 natural language statement: Let $X$ be a topological space and let $Y$ be a metric space. Let $f_{n}: X \rightarrow Y$ be a sequence of continuous functions. Let $x_{n}$ be a sequence of points of $X$ converging to $x$. Show that if the sequence $\left(f_{n}\right)$ converges uniformly to $f$, then $\left(f_{n}\left(x_{n}\right)\right)$ converges to $f(x)$. lean statement: theorem exercise_21_8 {X : Type*} [topological_space X] {Y : Type*} [metric_space Y] {f : \<nat> \<rightarrow> X \<rightarrow> Y} {x : \<nat> \<rightarrow> X} (hf : \<forall> n, continuous (f n)) (x₀ : X) (hx : tendsto x at_top (\<N> x₀)) (f₀ : X \<rightarrow> Y) (hh : tendsto_uniformly f f₀ at_top) : tendsto (\<lambda> n, f n (x n)) at_top (\<N> (f₀ x₀)) := codex statement: theorem converges_of_uniformly_converges_and_converges: fixes f::"'a::metric_space \<Rightarrow> 'b::metric_space" and X::"'a set" and Y::"'b set" assumes "compact X" "continuous_on X f" "uniformly_convergent_on X (f \<circ> g)" "convergent g" shows "convergent (f \<circ> g)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_21_8: undefined oops (*NOT POSSIBLE until we get an abstract formalisation of metric spaces*) (* problem_number:22_2a natural language statement: Let $p: X \rightarrow Y$ be a continuous map. Show that if there is a continuous map $f: Y \rightarrow X$ such that $p \circ f$ equals the identity map of $Y$, then $p$ is a quotient map. lean statement: theorem exercise_22_2a {X Y : Type*} [topological_space X] [topological_space Y] (p : X \<rightarrow> Y) (h : continuous p) : quotient_map p \<longleftrightarrow> \<exists> (f : Y \<rightarrow> X), continuous f \<and> p \<circ> f = id := codex statement: theorem quotient_map_of_continuous_map_and_continuous_map_comp_id: fixes p::"'a::topological_space \<Rightarrow> 'b::topological_space" and f::"'b::topological_space \<Rightarrow> 'a::topological_space" assumes "continuous_on UNIV p" "continuous_on UNIV f" "\<forall>x. p (f x) = x" shows "quotient_map p" Our comment on the codex statement: it is the type class version and it is scrambled *) theorem exercise_22_2a: assumes "continuous_map X Y p" "continuous_map Y X f" and "\<And>y. y \<in> topspace Y \<Longrightarrow> p (f y) = y" shows "quotient_map X Y p" by (smt (verit) assms comp_apply continuous_map_compose continuous_open_imp_quotient_map homeomorphic_eq_everything_map homeomorphic_map_involution quotient_map_from_composition) (* problem_number:22_2b natural language statement: If $A \subset X$, a retraction of $X$ onto $A$ is a continuous map $r: X \rightarrow A$ such that $r(a)=a$ for each $a \in A$. Show that a retraction is a quotient map. lean statement: theorem exercise_22_2b {X : Type*} [topological_space X] {A : set X} (r : X \<rightarrow> A) (hr : continuous r) (h : \<forall> x : A, r x = x) : quotient_map r := codex statement: theorem retraction_is_quotient_map: fixes X::"'a::topological_space topology" and A::"'a set" and r::"'a \<Rightarrow> 'a" assumes "continuous_on (carrier X) r" "r ` (carrier X) \<subseteq> A" "\<forall>x\<in>A. r x = x" shows "quotient_map X (subtopology X A) r" Our comment on the codex statement: partly right *) theorem exercise_22_2b: assumes "A \<subseteq> topspace X" "continuous_map X (subtopology X A) r" and "\<And>x. x \<in> A \<Longrightarrow> r x = x" shows "quotient_map X (subtopology X A) r" by (metis assms continuous_map_from_subtopology continuous_map_into_fulltopology exercise_22_2a topspace_subtopology_subset) (* problem_number:22_5 natural language statement: Let $p \colon X \rightarrow Y$ be an open map. Show that if $A$ is open in $X$, then the map $q \colon A \rightarrow p(A)$ obtained by restricting $p$ is an open map. lean statement: theorem exercise_22_5 {X Y : Type*} [topological_space X] [topological_space Y] (p : X \<rightarrow> Y) (hp : is_open_map p) (A : set X) (hA : is_open A) : is_open_map (p \<circ> subtype.val : A \<rightarrow> Y) := codex statement: theorem open_map_of_open_subset: fixes p::"'a::topological_space \<Rightarrow> 'b::topological_space" assumes "open_map p" "openin (top_of_set (UNIV::'a set)) A" shows "open_map (p|A)" Our comment on the codex statement: type class primitives, and scrambled *) theorem exercise_22_5: assumes "open_map X Y p" "openin X A" shows "open_map (subtopology X A) (subtopology Y (p ` A)) (restrict p A)" oops (* problem_number:23_2 natural language statement: Let $\left\{A_{n}\right\}$ be a sequence of connected subspaces of $X$, such that $A_{n} \cap A_{n+1} \neq \varnothing$ for all $n$. Show that $\bigcup A_{n}$ is connected. lean statement: theorem exercise_23_2 {X : Type*} [topological_space X] {A : \<nat> \<rightarrow> set X} (hA : \<forall> n, is_connected (A n)) (hAn : \<forall> n, A n \<inter> A (n + 1) \<noteq> \<emptyset>) : is_connected (\<Union> n, A n) := codex statement: theorem connected_of_connected_inter_nonempty: fixes X::"'a::topological_space set" and A::"nat \<Rightarrow> 'a set" assumes "\<forall>n. connected (A n)" "\<forall>n. A n \<inter> A (n+1) \<noteq> {}" shows "connected (\<Union>i. A i)" Our comment on the codex statement: very good but uses type classes *) theorem exercise_23_2: assumes "\<And>n. connectedin X (A n)" "\<And>n. A n \<inter> A (Suc n) \<noteq> {}" shows "connectedin X (\<Union>i. A i)" oops (* problem_number:23_3 natural language statement: Let $\left\{A_{\alpha}\right\}$ be a collection of connected subspaces of $X$; let $A$ be a connectea eubsen of $X$ Show that if $A \cap A_{\alpha} \neq \varnothing$ for all $\alpha$, then $A \cup\left(\bigcup A_{\alpha}\right)$ is connected. lean statement: theorem exercise_23_3 {X : Type*} [topological_space X] [topological_space X] {A : \<nat> \<rightarrow> set X} (hAn : \<forall> n, is_connected (A n)) (A₀ : set X) (hA : is_connected A₀) (h : \<forall> n, A₀ \<inter> A n \<noteq> \<emptyset>) : is_connected (A₀ \<union> (\<Union> n, A n)) := codex statement: theorem connected_of_connected_inter_nonempty: fixes X::"'a::topological_space set" and A::"'a set" and A\<alpha>::"'a set" assumes "\<forall>\<alpha>. connected (A\<alpha> \<alpha>)" "connected A" "\<forall>\<alpha>. A \<inter> A\<alpha> \<alpha> \<noteq> {}" shows "connected (A \<union> (\<Union>\<alpha>. A\<alpha> \<alpha>))" Our comment on the codex statement: very good but uses type classes *) theorem exercise_23_3: assumes "\<And>\<alpha>. connectedin X (\<A> \<alpha>)" "\<And>n. \<A> n \<inter> \<A> (Suc n) \<noteq> {}" "A \<subseteq> topspace X" "connectedin X A" shows "connectedin X (A \<union> (\<Union>i. \<A> i))" oops (* problem_number:23_4 natural language statement: Show that if $X$ is an infinite set, it is connected in the finite complement topology. lean statement: theorem exercise_23_4 {X : Type*} [topological_space X] [cofinite_topology X] (s : set X) : set.infinite s \<rightarrow> is_connected s := codex statement: theorem connected_of_infinite_set: fixes X::"'a set" assumes "infinite X" shows "connected_space (subtopology (discrete_topology X) X)" Our comment on the codex statement: not about discrete topology; uses type classes *) theorem exercise_23_4: assumes "infinite A" shows "connectedin (topology (\<lambda>U. finite (-U))) A" oops (* problem_number:23_6 natural language statement: Let $A \subset X$. Show that if $C$ is a connected subspace of $X$ that intersects both $A$ and $X-A$, then $C$ intersects $\operatorname{Bd} A$. lean statement: theorem exercise_23_6 {X : Type*} [topological_space X] {A C : set X} (hc : is_connected C) (hCA : C \<inter> A \<noteq> \<emptyset>) (hCXA : C \<inter> Aᶜ \<noteq> \<emptyset>) : C \<inter> (frontier A) \<noteq> \<emptyset> := codex statement: theorem connected_intersect_of_subset_intersect_diff_subset_intersect_boundary: fixes A::"'a::topological_space set" and C::"'a set" assumes "connected C" "C \<inter> A \<noteq> {}" "C \<inter> (UNIV - A) \<noteq> {}" shows "C \<inter> (boundary A) \<noteq> {}" Our comment on the codex statement: very good but uses type classes; it's frontier not boundary *) theorem exercise_23_6: assumes "connectedin X C" "C \<inter> A \<noteq> {}" "C \<inter> (-A) \<noteq> {}" shows "C \<inter> (frontier A) \<noteq> {}" oops (* problem_number:23_9 natural language statement: Let $A$ be a proper subset of $X$, and let $B$ be a proper subset of $Y$. If $X$ and $Y$ are connected, show that $(X \times Y)-(A \times B)$ is connected. lean statement: theorem exercise_23_9 {X Y : Type*} [topological_space X] [topological_space Y] (A_1 A_2 : set X) (B_1 B_2 : set Y) (hA : A_1 \<subset> A_2) (hB : B_1 \<subset> B_2) (hA : is_connected A_2) (hB : is_connected B_2) : is_connected ({x | \<exists> a b, x = (a, b) \<and> a \<in> A_2 \<and> b \<in> B_2} \ {x | \<exists> a b, x = (a, b) \<and> a \<in> A_1 \<and> b \<in> B_1}) := codex statement: theorem connected_of_connected_times_connected_minus_proper_subset: fixes X Y::"'a::topological_space set" assumes "connected X" "connected Y" "A \<subset> X" "B \<subset> Y" shows "connected ((X \<inter> Y) - (A \<inter> B))" Our comment on the codex statement: where did those intersections come from? *) theorem exercise_23_9: assumes "connected_space X" "connected_space Y" "A \<subset> topspace X" "B \<subset> topspace Y" shows "connectedin (prod_topology X Y) ((topspace X \<times> topspace Y) - (A \<times> B))" oops (* problem_number:23_11 natural language statement: Let $p: X \rightarrow Y$ be a quotient map. Show that if each set $p^{-1}(\{y\})$ is connected, and if $Y$ is connected, then $X$ is connected. lean statement: theorem exercise_23_11 {X Y : Type*} [topological_space X] [topological_space Y] (p : X \<rightarrow> Y) (hq : quotient_map p) (hY : connected_space Y) (hX : \<forall> y : Y, is_connected (p ⁻¹' {y})) : connected_space X := codex statement: theorem connected_of_connected_quotient_map: fixes X::"'a topology" and Y::"'b topology" assumes "continuous_map X Y p" "\<forall>y\<in>Y. connected (p -` {y})" "connected Y" shows "connected X" Our comment on the codex statement: very good but uses type classes *) theorem exercise_23_11: assumes "quotient_map X Y p" "\<forall>y \<in> topspace Y. connectedin X (p -` {y})" "connected_space Y" shows "connected_space X" oops (* problem_number:23_12 natural language statement: Let $Y \subset X$; let $X$ and $Y$ be connected. Show that if $A$ and $B$ form a separation of $X-Y$, then $Y \cup A$ and $Y \cup B$ are connected. lean statement: codex statement: theorem connected_of_connected_of_separation: fixes X Y::"'a::topological_space set" assumes "connected X" "connected Y" "Y \<subseteq> X" "separation_set (X - Y) A B" shows "connected (Y \<union> A)" "connected (Y \<union> B)" Our comment on the codex statement: very good but uses type classes *) theorem exercise_23_12: assumes "connected_space X" "connectedin X Y" assumes "openin X A" "A \<noteq> {}" "openin X B" "B \<noteq> {}" "A \<inter> B = {}" "A \<union> B = topspace X - Y" shows "connectedin X (Y \<union> A)" "connectedin X (Y \<union> B)" oops (* problem_number:24_2 natural language statement: Let $f: S^{1} \rightarrow \mathbb{R}$ be a continuous map. Show there exists a point $x$ of $S^{1}$ such that $f(x)=f(-x)$. lean statement: theorem exercise_24_2 {f : (metric.sphere 0 1 : set \<real>) \<rightarrow> \<real>} (hf : continuous f) : \<exists> x, f x = f (-x) := codex statement: theorem exists_eq_of_continuous_map: fixes f::"complex \<Rightarrow> real" assumes "continuous_on (sphere 1) f" shows "\<exists>x. f x = f (-x)" Our comment on the codex statement: Uses type classes and overlooks that x must lie on the sphere *) theorem exercise_24_2: fixes f::"complex \<Rightarrow> real" assumes "continuous_map (top_of_set (sphere 0 1)) euclidean f" shows "\<exists>x \<in> sphere 0 1. f x = f (-x)" proof - have "continuous_on (sphere 0 1) f" using assms continuous_map_iff_continuous by blast then show ?thesis oops (* problem_number:24_3a natural language statement: Let $f \colon X \rightarrow X$ be continuous. Show that if $X = [0, 1]$, there is a point $x$ such that $f(x) = x$. (The point $x$ is called a fixed point of $f$.) lean statement: theorem exercise_24_3a [topological_space I] (f : I \<rightarrow> I) (hf : continuous f) : \<exists> (x : I), f x = x := codex statement: theorem exists_fixed_point_of_continuous_on_closed_interval: fixes f::"'a::metric_space \<Rightarrow> 'a" assumes "continuous_on {0..1} f" shows "\<exists>x. f x = x" Our comment on the codex statement: very good but uses type classes *) theorem exercise_24_3a: fixes f::"real \<Rightarrow> real" defines "X \<equiv> top_of_set {0..1}" assumes "continuous_map X X f" shows "\<exists>x \<in> {0..1}. f x = x" oops (* problem_number:24_4 natural language statement: Let $X$ be an ordered set in the order topology. Show that if $X$ is connected, then $X$ is a linear continuum. lean statement: codex statement: theorem connected_of_linear_continuum: fixes X::"'a::linorder_topology" assumes "connected X" shows "linear_continuum X" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_24_4: undefined oops (* NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:24_6 natural language statement: Show that if $X$ is a well-ordered set, then $X \times [0, 1)$ in the dictionary order is a linear continuum. lean statement: codex statement: theorem linear_continuum_of_well_order: fixes X::"'a::wellorder set" assumes "well_order X" shows "linear_continuum (X \<times> {0..<1})" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_24_6: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:25_4 natural language statement: Let $X$ be locally path connected. Show that every connected open set in $X$ is path connected. lean statement: theorem exercise_25_4 {X : Type*} [topological_space X] [loc_path_connected_space X] (U : set X) (hU : is_open U) (hcU : is_connected U) : is_path_connected U := codex statement: theorem connected_open_is_path_connected: fixes X::"'a::topological_space topology" assumes "locally path_connected X" "openin X U" "connected U" shows "path_connected U" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_25_4: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:25_9 natural language statement: Let $G$ be a topological group; let $C$ be the component of $G$ containing the identity element $e$. Show that $C$ is a normal subgroup of $G$. lean statement: theorem exercise_25_9 {G : Type*} [topological_space G] [group G] [topological_group G] (C : set G) (h : C = connected_component 1) : is_normal_subgroup C := codex statement: theorem component_of_topological_group_is_normal: fixes G::"('a, 'b) topological_group_scheme" assumes "topological_group G" shows "normal_subgroup (component_of G (\<one> G)) G" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_25_9: undefined oops (* no idea what this is about*) (* problem_number:26_9 natural language statement: Let $A$ and $B$ be subspaces of $X$ and $Y$, respectively; let $N$ be an open set in $X \times Y$ containing $A \times B$. If $A$ and $B$ are compact, then there exist open sets $U$ and $V$ in $X$ and $Y$, respectively, such that $A \times B \subset U \times V \subset N .$ lean statement: codex statement: theorem exists_open_subset_of_compact_subset_in_open_set: fixes A B::"'a::euclidean_space set" and N::"'a set \<times> 'a set" assumes "compact A" "compact B" "open N" "A \<times> B \<subseteq> N" shows "\<exists>U V. open U \<and> open V \<and> A \<times> B \<subseteq> U \<times> V \<and> U \<times> V \<subseteq> N" Our comment on the codex statement: very good but uses type classes *) theorem exercise_26_9: assumes "A \<subseteq> topspace X" "B \<subseteq> topspace Y" "openin (prod_topology X Y) N" "A \<times> B \<subseteq> N" assumes "compact A" "compact B" shows "\<exists>U V. openin X U \<and> openin Y V \<and> A \<times> B \<subseteq> U \<times> V \<and> U \<times> V \<subseteq> N" oops (* problem_number:26_11 natural language statement: Let $X$ be a compact Hausdorff space. Let $\mathcal{A}$ be a collection of closed connected subsets of $X$ that is simply ordered by proper inclusion. Then $Y=\bigcap_{A \in \mathcal{A}} A$ is connected. lean statement: theorem exercise_26_11 {X : Type*} [topological_space X] [compact_space X] [t2_space X] (A : set (set X)) (hA : \<forall> (a b : set X), a \<in> A \<rightarrow> b \<in> A \<rightarrow> a \<subseteq> b \<or> b \<subseteq> a) (hA' : \<forall> a \<in> A, is_closed a) (hA'' : \<forall> a \<in> A, is_connected a) : is_connected (\<Inter>₀ A) := codex statement: theorem connected_of_compact_hausdorff_simply_ordered_closed_connected_subsets: fixes X::"'a::t2_space set" and A::"'a set set" assumes "compact X" "hausdorff X" "\<forall>A B. A \<in> A \<and> B \<in> A \<longrightarrow> A \<subseteq> B \<or> B \<subseteq> A" "\<forall>A\<in>A. closedin (subtopology X UNIV) A \<and> connected A" shows "connected (\<Inter>A\<in>A. A)" Our comment on the codex statement: very good but uses type classes *) theorem exercise_26_11: assumes "compact_space X" "Hausdorff_space X" "\<Union>\<A> \<subseteq> topspace X" "\<forall>A\<in>\<A>. closedin X A \<and> connectedin X A" "\<forall>A\<in>\<A>. \<forall>B\<in>\<A>. A \<subseteq> B \<or> B \<subseteq> A" shows "connectedin X (\<Inter>A\<in>A. A)" oops (* problem_number:26_12 natural language statement: Let $p: X \rightarrow Y$ be a closed continuous surjective map such that $p^{-1}(\{y\})$ is compact, for each $y \in Y$. (Such a map is called a perfect map.) Show that if $Y$ is compact, then $X$ is compact. lean statement: theorem exercise_26_12 {X Y : Type*} [topological_space X] [topological_space Y] (p : X \<rightarrow> Y) (h : function.surjective p) (hc : continuous p) (hp : \<forall> y, is_compact (p ⁻¹' {y})) (hY : compact_space Y) : compact_space X := codex statement: theorem compact_of_perfect_map_compact: fixes f::"'a::metric_space \<Rightarrow> 'b::metric_space" assumes "compact (UNIV::'b set)" "continuous_on UNIV f" "surj f" "\<forall>y\<in>UNIV. compact (f -` {y})" shows "compact (UNIV::'a set)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_26_12: assumes "closed_map X Y p" "continuous_map X Y p" "p ` topspace X = topspace Y" assumes "\<forall>y \<in> topspace Y. compactin X (f -` {y})" "compact_space Y" shows "compact_space X" oops (* problem_number:27_1 natural language statement: Prove that if $X$ is an ordered set in which every closed interval is compact, then $X$ has the least upper bound property. lean statement: codex statement: theorem least_upper_bound_of_compact_closed_interval: fixes X::"'a::{order_topology, linorder_topology} set" assumes "compact {a..b}" shows "\<exists>c. is_lub {a..b} c" Our comment on the codex statement: many quantification issues *) theorem exercise_27_1: (*this version assumes type classes*) fixes A::"'a::linorder_topology set" assumes "\<And>a b. a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> compact {a..b}" assumes "A' \<subseteq> A" "bdd_above A'" shows "\<exists>x \<in> A. A' \<subseteq> {..x}" oops (* problem_number:27_4 natural language statement: Show that a connected metric space having more than one point is uncountable. lean statement: theorem exercise_27_4 {X : Type*} [metric_space X] [connected_space X] (hX : \<exists> x y : X, x \<noteq> y) : \<not> countable (univ : set X) := codex statement: theorem connected_metric_space_of_more_than_one_point_is_uncountable: fixes X::"'a::metric_space set" assumes "connected X" "card X > 1" shows "uncountable X" Our comment on the codex statement: perfect, because for this one we have to use type classes ATM *) theorem exercise_27_4: (*this version assumes type classes*) fixes X::"'a::metric_space set" assumes "connected X" "card X > 1" shows "uncountable X" using assms connected_finite_iff_sing by fastforce (* problem_number:28_4 natural language statement: A space $X$ is said to be countably compact if every countable open covering of $X$ contains a finite subcollection that covers $X$. Show that for a $T_1$ space $X$, countable compactness is equivalent to limit point compactness. lean statement: theorem exercise_28_4 {X : Type*} [topological_space X] (hT1 : t1_space X) : countably_compact X \<longleftrightarrow> limit_point_compact X := codex statement: theorem countably_compact_of_limit_point_compact: fixes X::"'a::t1_space topological_space" assumes "limit_point_compact X" shows "countably_compact X" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_28_4: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:28_5 natural language statement: Show that X is countably compact if and only if every nested sequence $C_1 \supset C_2 \supset \cdots$ of closed nonempty sets of X has a nonempty intersection. lean statement: theorem exercise_28_5 (X : Type* ) [topological_space X] : countably_compact X \<longleftrightarrow> \<forall> (C : \<nat> \<rightarrow> set X), (\<forall> n, is_closed (C n)) \<and> (\<forall> n, C n \<noteq> \<emptyset>) \<and> (\<forall> n, C n \<subseteq> C (n + 1)) \<rightarrow> \<exists> x, \<forall> n, x \<in> C n := codex statement: theorem countably_compact_of_nested_closed_nonempty_has_nonempty_intersection: fixes X::"'a::t2_space set" assumes "\<forall>n. closed (C n)" "\<forall>n. C n \<noteq> {}" "\<forall>n. C n \<subseteq> C (n+1)" shows "\<exists>x. x\<in>\<Inter>n. C n" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_28_5: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:28_6 natural language statement: Let $(X, d)$ be a metric space. If $f: X \rightarrow X$ satisfies the condition $d(f(x), f(y))=d(x, y)$ for all $x, y \in X$, then $f$ is called an isometry of $X$. Show that if $f$ is an isometry and $X$ is compact, then $f$ is bijective and hence a homeomorphism. lean statement: theorem exercise_28_6 {X : Type*} [metric_space X] [compact_space X] {f : X \<rightarrow> X} (hf : isometry f) : function.bijective f := codex statement: theorem isometry_of_compact_is_homeomorphism: fixes f::"'a::metric_space \<Rightarrow> 'a" assumes "compact (UNIV::'a set)" "\<forall>x y. dist (f x) (f y) = dist x y" shows "homeomorphism (UNIV::'a set) (UNIV::'a set) f" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_28_6: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:29_1 natural language statement: Show that the rationals $\mathbb{Q}$ are not locally compact. lean statement: theorem exercise_29_1 : \<not> locally_compact_space \<rat> := codex statement: theorem not_locally_compact_of_Q: shows "\<forall>x\<in>UNIV. \<exists>U. open U \<and> x\<in>U \<and> (\<forall>V. open V \<and> x\<in>V \<longrightarrow> \<exists>y\<in>V. y\<notin>U)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_29_1: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:29_4 natural language statement: Show that $[0, 1]^\omega$ is not locally compact in the uniform topology. lean statement: theorem exercise_29_4 [topological_space (\<nat> \<rightarrow> I)] : \<not> locally_compact_space (\<nat> \<rightarrow> I) := codex statement: theorem not_locally_compact_of_uniform_topology: fixes X::"nat \<Rightarrow> real" assumes "\<forall>n. 0 \<le> X n \<and> X n \<le> 1" shows "\<forall>U. openin (uniform_topology (product_topology real UNIV)) U \<longrightarrow> \<exists>V. openin (uniform_topology (product_topology real UNIV)) V \<and> compact V \<and> X \<in> V \<and> V \<subseteq> U" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_29_4: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:29_5 natural language statement: If $f \colon X_1 \rightarrow X_2$ is a homeomorphism of locally compact Hausdorff spaces, show that $f$ extends to a homeomorphism of their one-point compactifications. lean statement: codex statement: theorem homeomorphism_of_one_point_compactification: fixes f::"'a::t2_space \<Rightarrow> 'b::t2_space" assumes "homeomorphism X1 X2 f" "locally compact X1" "locally compact X2" "compact_space X1" "compact_space X2" shows "homeomorphism (one_point_compactification X1) (one_point_compactification X2) (extend_map f)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_29_5: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:29_6 natural language statement: Show that the one-point compactification of $\mathbb{R}$ is homeomorphic with the circle $S^1$. lean statement: codex statement: theorem homeomorphic_of_one_point_compactification_of_real_is_circle: shows "one_point_compactification \<real> homeomorphic (sphere (1::real) 0)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_29_6: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:29_10 natural language statement: Show that if $X$ is a Hausdorff space that is locally compact at the point $x$, then for each neighborhood $U$ of $x$, there is a neighborhood $V$ of $x$ such that $\bar{V}$ is compact and $\bar{V} \subset U$. lean statement: theorem exercise_29_10 {X : Type*} [topological_space X] [t2_space X] (x : X) (hx : \<exists> U : set X, x \<in> U \<and> is_open U \<and> (\<exists> K : set X, U \<subset> K \<and> is_compact K)) (U : set X) (hU : is_open U) (hxU : x \<in> U) : \<exists> (V : set X), is_open V \<and> x \<in> V \<and> is_compact (closure V) \<and> closure V \<subseteq> U := codex statement: theorem exists_compact_subset_of_neighborhood: fixes X::"'a::metric_space topology" and x::'a assumes "x\<in>topspace X" "t1_space X" "locally_compact_space X" "\<exists>U. openin X U \<and> x\<in>U" shows "\<exists>V. openin X V \<and> x\<in>V \<and> compact (closure V) \<and> closure V \<subseteq> U" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_29_10: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:30_10 natural language statement: Show that if $X$ is a countable product of spaces having countable dense subsets, then $X$ has a countable dense subset. lean statement: theorem exercise_30_10 {X : \<nat> \<rightarrow> Type*} [\<forall> i, topological_space (X i)] (h : \<forall> i, \<exists> (s : set (X i)), countable s \<and> dense s) : \<exists> (s : set (\<pi> i, X i)), countable s \<and> dense s := codex statement: theorem countable_dense_subset_of_countable_product_of_countable_dense_subset: fixes X::"'a::{second_countable_topology, t2_space} set" assumes "countable X" "\<forall>x\<in>X. \<exists>D. countable D \<and> dense_in (top_of_set X) D" shows "\<exists>D. countable D \<and> dense_in (top_of_set X) D" Our comment on the codex statement: plausible *) theorem exercise_30_10: fixes Y :: "'a \<Rightarrow> 'b topology" assumes "countable I" "\<forall>i\<in>I. \<exists>D. countable D \<and> D \<subseteq> topspace (Y i) \<and> Y i closure_of D = topspace (Y i)" defines "X \<equiv> product_topology Y I" shows "\<exists>D. countable D \<and> D \<subseteq> topspace X \<and> X closure_of D = topspace X" oops (* problem_number:30_13 natural language statement: Show that if $X$ has a countable dense subset, every collection of disjoint open sets in $X$ is countable. lean statement: theorem exercise_30_13 {X : Type*} [topological_space X] (h : \<exists> (s : set X), countable s \<and> dense s) (U : set (set X)) (hU : \<forall> (x y : set X), x \<in> U \<rightarrow> y \<in> U \<rightarrow> x \<noteq> y \<rightarrow> x \<inter> y = \<emptyset>) : countable U := codex statement: theorem countable_of_dense_countable: fixes X::"'a::metric_space set" assumes "countable (UNIV::'a set)" "\<forall>x\<in>X. \<exists>U. open U \<and> x\<in>U \<and> U \<subseteq> X" shows "countable X" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_30_13: assumes "countable D" "D \<subseteq> topspace X" "X closure_of D = topspace X" "\<forall>A\<in>\<A>. openin X A" "disjoint \<A>" shows "countable \<A>" oops (* problem_number:31_1 natural language statement: Show that if $X$ is regular, every pair of points of $X$ have neighborhoods whose closures are disjoint. lean statement: theorem exercise_31_1 {X : Type*} [topological_space X] (hX : regular_space X) (x y : X) : \<exists> (U V : set X), is_open U \<and> is_open V \<and> x \<in> U \<and> y \<in> V \<and> closure U \<inter> closure V = \<emptyset> := codex statement: theorem regular_implies_disjoint_closure_of_neighborhoods: fixes X::"'a::t1_space topology" assumes "regular_space X" shows "\<forall>x y. x \<in> topspace X \<and> y \<in> topspace X \<longrightarrow> \<exists>U V. openin X U \<and> openin X V \<and> x\<in>U \<and> y\<in>V \<and> closure U \<inter> closure V = {}" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_31_1: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:31_2 natural language statement: Show that if $X$ is normal, every pair of disjoint closed sets have neighborhoods whose closures are disjoint. lean statement: theorem exercise_31_2 {X : Type*} [topological_space X] [normal_space X] {A B : set X} (hA : is_closed A) (hB : is_closed B) (hAB : disjoint A B) : \<exists> (U V : set X), is_open U \<and> is_open V \<and> A \<subseteq> U \<and> B \<subseteq> V \<and> closure U \<inter> closure V = \<emptyset> := codex statement: theorem disjoint_closed_sets_have_disjoint_neighborhoods: fixes X::"'a::t2_space topology" and A B::"'a set" assumes "normal_space X" "closedin X A" "closedin X B" "A \<inter> B = {}" shows "\<exists>U V. openin X U \<and> openin X V \<and> A \<subseteq> U \<and> B \<subseteq> V \<and> closure U \<inter> closure V = {}" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_31_2: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:31_3 natural language statement: Show that every order topology is regular. lean statement: theorem exercise_31_3 {\<alpha> : Type*} [partial_order \<alpha>] [topological_space \<alpha>] (h : order_topology \<alpha>) : regular_space \<alpha> := codex statement: theorem regular_of_order_topology: fixes T::"'a::order topology" shows "regular_space T" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_31_3: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:32_1 natural language statement: Show that a closed subspace of a normal space is normal. lean statement: theorem exercise_32_1 {X : Type*} [topological_space X] (hX : normal_space X) (A : set X) (hA : is_closed A) : normal_space {x // x \<in> A} := codex statement: theorem closed_subspace_of_normal_is_normal: fixes X::"'a::t2_space set" and Y::"'b::t2_space set" assumes "closed_in (subtopology euclidean X) Y" "normal_space X" shows "normal_space Y" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_32_1: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:32_2 natural language statement: Show that if $\prod X_\alpha$ is Hausdorff, or regular, or normal, then so is $X_\alpha$. Assume that each $X_\alpha$ is nonempty. lean statement: theorem exercise_32_2a {\<iota> : Type*} {X : \<iota> \<rightarrow> Type*} [\<forall> i, topological_space (X i)] (h : \<forall> i, nonempty (X i)) (h2 : t2_space (\<pi> i, X i)) : \<forall> i, t2_space (X i) := codex statement: theorem prod_topology_of_topology_is_topology: fixes \<alpha>::"'a" and X::"'a \<Rightarrow> 'b::topological_space" assumes "\<forall>\<alpha>. x \<in> X \<alpha>" shows "\<forall>\<alpha>. openin (prod_topology (\<alpha>::'a) X) {x} \<longrightarrow> openin (X \<alpha>) {x \<alpha>}" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_32_2: fixes X :: "'a \<Rightarrow> 'b topology" assumes "\<forall>i\<in>I. topspace (X i) \<noteq> {}" "Hausdorff_space (product_topology X I)" "i \<in> I" shows "Hausdorff_space (X i)" oops (* problem_number:32_2 natural language statement: Show that every locally compact Hausdorff space is regular. lean statement: theorem exercise_32_2a {\<iota> : Type*} {X : \<iota> \<rightarrow> Type*} [\<forall> i, topological_space (X i)] (h : \<forall> i, nonempty (X i)) (h2 : t2_space (\<pi> i, X i)) : \<forall> i, t2_space (X i) := codex statement: theorem regular_of_locally_compact_hausdorff: fixes X::"'a::metric_space topology" assumes "locally_compact_space X" "hausdorff_space X" shows "regular_space X" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_32_2: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:33_7 natural language statement: Show that every locally compact Hausdorff space is completely regular. lean statement: theorem exercise_33_7 {X : Type*} [topological_space X] (hX : locally_compact_space X) (hX' : t2_space X) : \<forall> x A, is_closed A \<and> \<not> x \<in> A \<rightarrow> \<exists> (f : X \<rightarrow> I), continuous f \<and> f x = 1 \<and> f '' A = {0} := codex statement: theorem locally_compact_hausdorff_is_completely_regular: fixes T::"'a::metric_space topology" assumes "locally_compact T" "T_2_space T" shows "completely_regular_space T" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_33_7: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:33_8 natural language statement: Let $X$ be completely regular, let $A$ and $B$ be disjoint closed subsets of $X$. Show that if $A$ is compact, there is a continuous function $f \colon X \rightarrow [0, 1]$ such that $f(A) = \{0\}$ and $f(B) = \{1\}$. lean statement: theorem exercise_33_8 (X : Type* ) [topological_space X] [regular_space X] (h : \<forall> x A, is_closed A \<and> \<not> x \<in> A \<rightarrow> \<exists> (f : X \<rightarrow> I), continuous f \<and> f x = (1 : I) \<and> f '' A = {0}) (A B : set X) (hA : is_closed A) (hB : is_closed B) (hAB : disjoint A B) (hAc : is_compact A) : \<exists> (f : X \<rightarrow> I), continuous f \<and> f '' A = {0} \<and> f '' B = {1} := codex statement: theorem exists_continuous_function_of_disjoint_compact_closed_sets: fixes X::"'a::t2_space" and A B::"'a set" assumes "compact A" "closed A" "closed B" "A \<inter> B = \<emptyset>" shows "\<exists>f. continuous_on X f \<and> f ` X \<subseteq> {0..1} \<and> f ` A = {0} \<and> f ` B = {1}" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_33_8: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:34_9 natural language statement: Let $X$ be a compact Hausdorif space that is the union of the closed subspaces $X_1$ and $X_2$. If $X_1$ and $X_2$ are metrizable, show that $X$ is metrizable. lean statement: theorem exercise_34_9 (X : Type* ) [topological_space X] [compact_space X] (X1 X2 : set X) (hX1 : is_closed X1) (hX2 : is_closed X2) (hX : X1 \<union> X2 = univ) (hX1m : metrizable_space X1) (hX2m : metrizable_space X2) : metrizable_space X := codex statement: theorem metrizable_of_compact_union_of_metrizable: fixes X::"'a::metric_space set" and X1 X2::"'a set" assumes "compact X" "closed X1" "closed X2" "X = X1 \<union> X2" "metrizable X1" "metrizable X2" shows "metrizable X" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_34_9: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:37_2 natural language statement: A collection $\mathcal{A}$ of subsets of $X$ has the countable intersection property if every countable intersection of elements of $\mathcal{A}$ is nonempty. Show that $X$ is a Lindelöf space if and only if for every collection $\mathcal{A}$ of subsets of $X$ having the countable intersection property, $\bigcap_{A \in \mathcal{A}} \bar{A}$ is nonempty. lean statement: codex statement: theorem lindelof_iff_countable_intersection_property: fixes X::"'a::metric_space topology" assumes "countable_basis X" shows "Lindelöf_space X \<longleftrightarrow> (\<forall>A. (\<forall>a\<in>A. openin X a) \<longrightarrow> (\<exists>b. openin X b \<and> \<forall>a\<in>A. a \<subseteq> b) \<longrightarrow> (\<exists>x. \<forall>a\<in>A. x\<in>a))" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_37_2: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:38_4 natural language statement: Let $Y$ be an arbitrary compactification of $X$; let $\beta(X)$ be the Stone-Čech compactification. Show there is a continuous surjective closed map $g \colon \beta(X)\rightarrow Y$ that equals the identity on $X$. lean statement: codex statement: theorem exists_continuous_surjective_closed_map_of_compactification: fixes X::"'a::t1_space set" and Y::"'b::t1_space set" assumes "compactification X Y" shows "\<exists>g. continuous_on (UNIV::'b set) g \<and> g ` (UNIV::'b set) = UNIV \<and> closed_in (subtopology (top_of_set (UNIV::'b set)) (UNIV::'b set)) (g -` (UNIV::'a set)) \<and> g ` (UNIV::'a set) = (UNIV::'a set)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_38_4: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:38_6 natural language statement: Let $X$ be completely regular. Show that $X$ is connected if and only if $\beta(X)$ is connected. lean statement: theorem exercise_38_6 {X : Type*} (X : Type* ) [topological_space X] [regular_space X] (h : \<forall> x A, is_closed A \<and> \<not> x \<in> A \<rightarrow> \<exists> (f : X \<rightarrow> I), continuous f \<and> f x = (1 : I) \<and> f '' A = {0}) : is_connected (univ : set X) \<longleftrightarrow> is_connected (univ : set (stone_cech X)) := codex statement: theorem connected_of_completely_regular_iff_connected_beta: fixes X::"'a::t2_space topology" assumes "completely_regular_space X" shows "connected X \<longleftrightarrow> connected (\<beta> X)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_38_6: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:39_5 natural language statement: Show that if X has a countable basis, a collection $\mathcal{A}$ of subsets of $X$ is countably locally finite if and only if it is countable. lean statement: codex statement: theorem countable_of_countably_locally_finite: fixes X::"'a::metric_space set" and A::"'a set set" assumes "countable_basis X" "countably_locally_finite A" shows "countable A" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_39_5: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:43_2 natural language statement: Let $(X, d_X)$ and $(Y, d_Y)$ be metric spaces; let $Y$ be complete. Let $A \subset X$. Show that if $f \colon A \rightarrow Y$ is uniformly continuous, then $f$ can be uniquely extended to a continuous function $g \colon \bar{A} \rightarrow Y$, and $g$ is uniformly continuous. lean statement: theorem exercise_43_2 {X : Type*} [metric_space X] {Y : Type*} [metric_space Y] [complete_space Y] (A : set X) (f : X \<rightarrow> Y) (hf : uniform_continuous_on f A) : \<exists>! (g : X \<rightarrow> Y), continuous_on g (closure A) \<and> uniform_continuous_on g (closure A) \<and> \<forall> (x : A), g x = f x := codex statement: theorem uniformly_continuous_extends_to_continuous_uniformly_continuous: fixes f::"'a::metric_space \<Rightarrow> 'b::complete_space" assumes "uniformly_continuous_on A f" shows "\<exists>g. continuous_on (closure A) g \<and> g|`A = f \<and> uniformly_continuous_on (closure A) g" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_43_2: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) (* problem_number:43_7 natural language statement: Show that the set of all sequences $(x_1, x_2, \ldots)$ such that $\sum x_i^2$ converges is complete in $l^2$-metric. lean statement: codex statement: theorem complete_of_sum_square_converges: fixes X::"nat \<Rightarrow> 'a::real_normed_vector" assumes "\<forall>n. norm (X n) < \<infinity>" shows "\<exists>l. (\<forall>n. norm (X n - l) < e) \<longrightarrow> (\<exists>N. \<forall>n\<ge>N. norm (X n - l) < e)" Our comment on the codex statement: <YOU CAN LEAVE YOUR COMMENT HERE> *) theorem exercise_43_7: undefined oops (*NOT EASILY EXPRESSIBLE using our primitives*) end
/- Copyright (c) 2022 James Gallicchio. Authors: James Gallicchio -/ import LeanColls.AuxLemmas import LeanColls.Array import LeanColls.View import LeanColls.Classes import LeanColls.FoldableOps namespace LeanColls structure HashMap (κ τ : Type) [Hashable κ] [DecidableEq κ] where cap : Nat h_cap : 0 < cap ∧ cap < UInt64.size backing : COWArray (AList κ τ) cap size : Cached ( View.view backing |>.map AList.size |> FoldableOps.sum) namespace HashMap variable {κ τ : Type} [Hashable κ] [DecidableEq κ] opaque finishHash (x : UInt64) : UInt64 := let x := x ^^^ (x >>> 30) let x := x * 0xbf58476d1ce4e5b9 let x := x ^^^ (x >>> 27) let x := x * 0x94d049bb133111eb let x := x ^^^ (x >>> 31) x structure Hashed (κ) [Hashable κ] where k : κ hashk : Cached (finishHash (hash k)) @[inline] def mkHashed [Hashable κ] (k : κ) : Hashed κ where k := k hashk := Cached.cached _ def new (cap : Nat := 16) (h_cap : 0 < cap ∧ cap < UInt64.size := by decide) : HashMap κ τ := ⟨cap, h_cap, COWArray.new [] cap, cached' 0 (by clear h_cap simp [View.map, View.view, FoldableOps.sum, FoldableOps.defaultImpl, Foldable.fold, Foldable'.Correct.fold'] simp [Size.size, COWArray.new, Indexed.nth, COWArray.get, Array.new, Array.get] generalize Range.foldl'' _ _ _ _ = res match res with | ⟨_,A,hA⟩ => clear res simp conv => rhs arg 2 intro acc i h rw [hA] simp clear hA A induction cap case zero => simp case succ n ih _ => simp apply ih simp)⟩ instance : Inhabited (HashMap κ τ) := ⟨HashMap.new⟩ @[inline] private def calc_idx' (k : κ) (cap : Nat) (h_cap : cap > 0) (h : cap < UInt64.size) : Fin cap := let idx := (hash k) % (UInt64.ofNat cap) ⟨idx.toNat, by simp [UInt64.mod_def, Fin.mod_def] apply Nat.mod_lt_of_lt rw [UInt64.val_eq_of_lt h] apply Nat.mod_lt assumption exact UInt64.size_positive ⟩ @[inline] def calc_idx (k : κ) (m : HashMap κ τ) : Fin m.cap := match m with | ⟨cap, h_cap, _, _⟩ => calc_idx' k cap h_cap.1 h_cap.2 /- TODO: add Array.getU64 -/ def get? (k : κ) (m : HashMap κ τ) : Option τ := m.backing.get (calc_idx k m) |> MapLike.get?.{0,0,0,0} k @[inline] private def updateNoRebalance (k : κ) (t : Option τ) (m : HashMap κ τ) : Option τ × HashMap κ τ := let idx := calc_idx k m match h : m.backing.get idx |> AList.getAndUpdate k t with | (old, newSlot) => let newSize := (if t.isSome then 1 else 0) + match old with | none => m.size | some _ => m.size - 1 ⟨old, m.cap, m.h_cap, m.backing.set idx newSlot, newSize, by have : newSize = _ + match old, h with | none, h => _ | some _, h => _ := rfl rw [this] clear this newSize have := AList.size_update k t (COWArray.get m.backing idx) simp at h rw [h.1, h.2] at this match old with | none => simp at this ⊢ conv => lhs; rw [View.view_eq_view_canonicalToList] conv => rhs; rw [View.view_eq_view_canonicalToList] simp simp [List.map_set] rw [List.sum_set] case h_i => simp [idx.isLt] simp rw [this] have := List.get_map_reverse AList.size (l := Array.toList m.backing.backing) (n := ⟨calc_idx k m, by simp [idx.isLt]⟩) rw [this] rw [←Nat.sub_add_comm (by apply List.get_le_sum)] conv => rhs; arg 1; arg 2 rw [Nat.add_comm] rw [←Nat.add_assoc] simp [COWArray.get, ←Array.toList_get] rw [Nat.add_comm] | some _ => simp at this ⊢ conv => lhs; rw [View.view_eq_view_canonicalToList] conv => rhs; rw [View.view_eq_view_canonicalToList] simp simp [List.map_set] rw [List.sum_set] case h_i => simp [idx.isLt] simp; stop rw [this] have := List.get_map_reverse AList.size (l := Array.toList m.backing.backing) (n := ⟨calc_idx k m, by simp [idx.isLt]⟩) rw [this] rw [←Nat.sub_add_comm (by apply List.get_le_sum)] simp [COWArray.get, ←Array.toList_get] ⟩ def rebalance : HashMap κ τ → HashMap κ τ | ⟨cap, h_cap, backing, size⟩ => if size >= cap then new (cap := min (2 * cap) (UInt64.size - 1)) (by constructor case left => simp [min] split case inl => rw [(by simp : 0 = 0 * 0)] apply Nat.mul_lt_mul' decide exact h_cap.1 decide case inr => simp case right => simp [min] split case inl h => exact Nat.succ_le_succ h case inr h => simp) |> Foldable.fold backing (fun acc L => L.foldl (fun acc (k,t) => (acc.updateNoRebalance k (some t)).2) acc) else ⟨cap, h_cap, backing, size⟩ def set' (k : κ) (t : τ) (m : HashMap κ τ) : Option τ × HashMap κ τ := let (o, h) := m.updateNoRebalance k (some t) (o, rebalance h) def set (k : κ) (t : τ) (m : HashMap κ τ) : HashMap κ τ := rebalance (m.updateNoRebalance k (some t)).2 def fold (m : HashMap κ τ) (f : β → (κ × τ) → β) (acc : β) := Foldable.fold m.backing (fun acc l => Foldable.fold l f acc ) acc instance : Membership κ (HashMap κ τ) where mem k m := get? k m |>.isSome instance : MapLike (HashMap κ τ) κ τ where get? := get? fold := fold instance : FoldableOps (HashMap κ τ) (κ × τ) := default theorem get_rebalance (k : κ) (m : HashMap κ τ) : m.rebalance.get? k = m.get? k := by simp [rebalance] split <;> simp simp [get?] sorry theorem get_set_eq [Hashable κ] (k : κ) (t : τ) (m : HashMap κ τ) : (m.set k t |>.get? k) = some t := by simp [set, get_rebalance] simp [get?, updateNoRebalance, calc_idx, calc_idx'] simp [COWArray.get, COWArray.set] simp [MapLike.get?] theorem get_set_ne [Hashable κ] (k : κ) (t : τ) (k' : κ) (m : HashMap κ τ) (h_k : k ≠ k') : (m.set k t |>.get? k') = m.get? k' := by simp [set, get_rebalance] simp [get?, updateNoRebalance] simp [COWArray.get, COWArray.set] simp [calc_idx] generalize calc_idx' k _ _ _ = k_idx generalize calc_idx' k' _ _ _ = k'_idx match h : decide (k_idx = k'_idx) with | true => simp at h simp [h] simp [MapLike.get?, h_k.symm] | false => have : k_idx ≠ k'_idx := by intro h; cases h; simp at h simp [this, Array.copy_def]
-- {-# OPTIONS -v tc.meta:30 --show-irrelevant #-} -- Andreas, 2013-10-29 submitted by sanzhiyan -- Documents need for different treating of DontCare in -- linearity analysis of Miller unification. -- Now, there can be DontCares stemming from irrelevant projections. module Issue927 where import Common.Level module Fails where postulate Σ : (B : Set) (C : B → Set) → Set <_,_> : {A : Set} {B : A → Set} {C : ∀ x → B x → Set} (f : (x : A) → B x) → (g : (x : A) → C x (f x)) → ((x : A) → Σ (B x) (C x)) record _⟶_ (A B : Set) : Set where field .app : A → B open _⟶_ public .⟪_,_⟫ : ∀ (A B C : Set) → (A ⟶ B) → (A ⟶ C) → A → Σ B (\ _ → C) ⟪_,_⟫ A B C f₁ f₂ = < app f₁ , app f₂ > -- Using darcs Agda, the following code triggers an -- internal error at src/full/Agda/TypeChecking/MetaVars.hs:897
# Inelastic Scattering for Ar Pre-Plated MCM-41 Nanopores ```python import numpy as np import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects from mpl_toolkits.axes_grid1.inset_locator import inset_axes from dgutils import colors as colortools import dgutils import spens import matplotlib as mpl import matplotlib.colors as mplcolors import importlib from heprops import helium import pickle,os # Notebook display options %config InlineBackend.figure_format = 'svg' # plot style plot_style = {'sans':'../include/sans_NC.mplstyle', 'notebook':'../include/notebook.mplstyle'} plt.style.reload_library() plt.style.use(plot_style['sans']) figsize = plt.rcParams['figure.figsize'] π = np.pi colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] ``` ```python import poreutils as pore importlib.reload(pore) from poreutils import red,orange,green,lblue,blue,dblue,purple from poreutils import pore_colors,pore_labels,font_path ``` ## Load the Neutron Scattering Data ```python # load the Neutron Scattering data Q,E,S,ΔS = spens.load_file('../data/SQW_2p5A_25-22_sf975.spe') # we mask the low-energy scattering that is influenced by the elastic spill-over. idx = np.where(E<0.5)[0] S[:,idx] = 100 # create meshes for plotting Enew = np.zeros(69) Enew[1:] = np.copy(E) Enew[0] = np.min(E)-(E[5]-E[4]) Qnew = np.zeros(49) Qnew[1:] = np.copy(Q) Qnew[0] = np.min(Q)-(Q[5]-Q[4]) Emesh,Qmesh = np.meshgrid(E,Q) ``` ## Load the Bulk Helium and 1D threshold ### The predicted threshold for hard rods \begin{equation} \omega_{\pm}(q) = \frac{4}{K_L} \left \lvert \frac{q}{2q_{\rm F}} \pm \left(\frac{q}{2q_{\rm F}}\right)^2\right \rvert \end{equation} ```python _Q = np.linspace(0.0,4.0,10000) ϵ = helium.helium_dispersion_svp(_Q)*0.0862 # convert from K to meV # these values have been extracted from an external analysis KL = 1.18 kF = 0.8 # get the theoretical value for the threshold energy _ω = pore.ω_LL(-1,_Q,KL,kF) ``` ### Experiment with different colormaps ```python cptfile = '../include/GMT_haxby.cpt' palette = pore.get_masked_palette(cptfile) ``` ```python from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size import matplotlib.colors as mpl_colors plt.style.reload_library() with plt.style.context(plot_style['sans']): figsize=plt.rcParams['figure.figsize'] dgutils.fonts.set_custom_font(pore.font_path) fig,ax = plt.subplots(1,1,figsize=(figsize[0],0.8*figsize[0]),constrained_layout=True, dpi=300) # nipy_spectral is also good pcm = ax.pcolormesh(Qmesh-0*(Q[5]-Q[4]),Emesh,S, edgecolor='None', rasterized=True, shading='auto', norm=mpl_colors.Normalize(vmin=0.0, vmax=32),cmap=palette, snap=True) #pcm = ax.imshow(S.T, rasterized=True, interpolation='lanczos', origin='lower', # extent=[np.min(Q),np.max(Q),np.min(E),np.max(E)],cmap=palette, vmin=0, vmax=30, aspect='auto') ax.plot(_Q,ϵ, color='#CCCCCC', ls='--') ax.plot(_Q+(Q[5]-Q[4])/2,_ω+(E[5]-E[4])/2, color=purple, ls='-') ax.set_xlabel(r'$\;Q\; (\mathrm{\AA})^{-1}$') ax.set_ylabel(r' E (meV)') ax.set_ylim(0,4.99) ax.set_xlim(1.0,4) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="3%", pad=0.025) plt.colorbar(pcm, cax=cax, label=r'Intensity $\;\;S(Q,E)\;\;$ (Arb. unit)', extend='max') plt.savefig('../figures/SQE.pdf', dpi=600) ``` ## Plot the theoretical scattering ```python data_1d = np.load("../data/1D-helium_T1.6_N28_L200.0.npz") dsf=data_1d["dsf"] extent=data_1d["extent"] vmax=0.1 #vmax=None aspect = (extent[1] - extent[0])/(4); aspect = 3.0/4.0; #aspect = plt.rcParams['figure.figsize'][1]/plt.rcParams['figure.figsize'][0]/1.1 fig, ax = plt.subplots(figsize=(4,4*0.78), dpi=240, constrained_layout=True) im = ax.imshow(dsf,origin="lower",extent=extent,aspect=aspect,interpolation="None",vmax=vmax, cmap=palette) ax.set_ylim(0,4) ax.plot(_Q,pore.ω_LL(-1,_Q,2.1,0.7)) ax.set_xlim(0,3) cb = fig.colorbar(im, label="$S(q,\omega)\\ \\mathrm{[meV^{-1}]}$", extend="max") ax.set_ylabel("Energy Transfer $\\hbar\\omega\\ \\mathrm{[meV]}$", fontweight="regular") ax.set_xlabel("Wavevector $q\\ [\\mathrm{Å^{-1}}]$", fontweight="regular") ``` Text(0.5, 0, 'Wavevector $q\\ [\\mathrm{Å^{-1}}]$') ## Plot the Combined Figure ### Horizontal ```python with plt.style.context(plot_style['sans']): figsize = plt.rcParams['figure.figsize'] dgutils.fonts.set_custom_font(font_path) fig,ax = plt.subplots(nrows=1,ncols=2, sharey=True,figsize=(1.75*figsize[0],1*figsize[1]), constrained_layout=False) fig.subplots_adjust(wspace=0.01) #fig = plt.figure(figsize=(1.5*figsize[0],1*figsize[1]), constrained_layout=True) #exp_fig,theory_fig = fig.subfigures(nrows=1,ncols=2) #ax = plt.subplots(1,2, sharey=True, sharex=True)## gridspec_kw={"left":0.05}) ax_exp,ax_theory = ax #ax_theory = theory_fig.subplots(1,1) # experimental plot pcm = ax_exp.pcolormesh(Qmesh-0*(Q[5]-Q[4]),Emesh,S, edgecolor='None', rasterized=True, shading='auto', norm=mpl_colors.Normalize(vmin=0.0, vmax=32),cmap=palette, snap=True) ax_exp.plot(_Q,ϵ, color='#CCCCCC', ls='--', lw=1.5) ax_exp.plot(_Q+(Q[5]-Q[4])/2,_ω+(E[5]-E[4])/2, color=purple, ls='-', lw=1.5) ax_exp.set_xlabel(r'$\;Q\; (\mathrm{\AA}^{-1})$') ax_exp.set_ylabel(r' E (meV)') ax_exp.set_ylim(0,4.99) ax_exp.set_xlim(1.0,3.99) path_eff = [path_effects.withSimplePatchShadow(offset=(0.06, -0.06), shadow_rgbFace='k', alpha=1.0)] cT = 1.6 cQ = 1.71 ax_exp.text(0.02,0.98,f'$T = {cT:3.1f}\; \mathrm{{K}}$', ha='left',va='top', color='w', transform=ax_exp.transAxes, fontsize=8, path_effects=path_eff) label = r'$Q_{\rm in} = $' + f'{cQ:4.2f} ' +r'$\mathrm{\AA}^{-1}$' ax_exp.text(0.02,0.92,label, ha='left',va='top', transform=ax_exp.transAxes, color='w', fontsize=8,path_effects=path_eff) # Theory Plot im = ax_theory.imshow(dsf,origin="lower",extent=extent,aspect=0.44,interpolation="None",vmax=0.18, cmap=palette) ax_theory.set_xlim(1,3.99) ax_theory.set_ylim(0,4.99) ax_theory.set_xlabel(r'$\;Q\; (\mathrm{\AA}^{-1})$') #ax_theory.plot(_Q,pore.ω_LL(-1,_Q,2.1,0.68),color=purple, ls='-', lw=1.5) # Add plot labels ax_exp.text(0.5,1.02,'Experiment', ha='center',transform=ax_exp.transAxes) ax_theory.text(0.5,1.02,'1D Simulation', ha='center',transform=ax_theory.transAxes) ## add a colorbar sm = plt.cm.ScalarMappable(cmap=palette, norm=mpl_colors.Normalize(vmin=0, vmax=vmax)) sm._A = [] loc = 'right' vshift = 0.00 axins1 = inset_axes(ax_theory, width="5%", height="100%", loc=loc, bbox_to_anchor=(0.075, vshift, 1, 1), bbox_transform=ax_theory.transAxes, borderpad=0) cb = fig.colorbar(sm, cax=axins1, orientation='vertical', ticks=[0,vmax], extend='both') cb.set_label(r'Intensity $\;\;S(Q,E)\;\;$ (a.u.)',labelpad=-10) cb.ax.xaxis.set_tick_params(pad=2) cb.ax.set_yticklabels(['0', 'max']) # panel labels font_props = dgutils.fonts.get_custom_font_props(pore.bold_font_path) ax_exp.text(-0.11,1.08,'a', ha='left',va='top', transform=ax_exp.transAxes, font=font_props) ax_theory.text(-0.0,1.08,'b', ha='left',va='top', transform=ax_theory.transAxes, font=font_props) #ax_theory.plot(_Q+(Q[5]-Q[4])/2,_ω+(E[5]-E[4])/2, color=purple, ls='-', lw=1.5) plt.savefig('../figures/SQE_exp_theory.pdf', dpi=600) ``` ### Vertical ```python with plt.style.context(plot_style['sans']): figsize = plt.rcParams['figure.figsize'] dgutils.fonts.set_custom_font(font_path) fig,ax = plt.subplots(nrows=2,ncols=1, sharey=True, sharex=True, figsize=(figsize[0],2*figsize[1]), constrained_layout=True) #fig.subplots_adjust(wspace=0.01) #ax = plt.subplots(1,2, sharey=True, sharex=True)## gridspec_kw={"left":0.05}) ax_exp,ax_theory = ax #ax_theory = theory_fig.subplots(1,1) # experimental plot pcm = ax_exp.pcolormesh(Qmesh-0*(Q[5]-Q[4]),Emesh,S, edgecolor='None', rasterized=True, shading='auto', norm=mpl_colors.Normalize(vmin=0.0, vmax=32),cmap=palette, snap=True) ax_exp.plot(_Q,ϵ, color='#CCCCCC', ls='--', lw=1.5) ax_exp.plot(_Q+(Q[5]-Q[4])/2,_ω+(E[5]-E[4])/2, color=purple, ls='-', lw=1.5) #ax_exp.set_xlabel(r'$\;Q\; (\mathrm{\AA}^{-1})$') ax_exp.set_ylabel(r' E (meV)') ax_exp.set_ylim(0,4.99) ax_exp.set_xlim(1.0,3.99) path_eff = [path_effects.withSimplePatchShadow(offset=(0.06, -0.06), shadow_rgbFace='k', alpha=1.0)] cT = 1.6 cQ = 1.71 ax_exp.text(0.98,0.98,f'$T = {cT:3.1f}\; \mathrm{{K}}$', ha='right',va='top', color='w', transform=ax_exp.transAxes, fontsize=8, path_effects=path_eff) label = r'$Q_{\rm in} = $' + f'{cQ:4.2f} ' +r'$\mathrm{\AA}^{-1}$' ax_exp.text(0.98,0.92,label, ha='right',va='top', transform=ax_exp.transAxes, color='w', fontsize=8,path_effects=path_eff) ax_exp.text(0.9,0.4,'3D', ha='right',va='top', transform=ax_exp.transAxes, color='#CCCCCC', path_effects=path_eff) ax_exp.text(0.6,0.95,'1D', ha='right',va='top', transform=ax_exp.transAxes, color=purple, path_effects=path_eff) # Theory Plot im = ax_theory.imshow(dsf,origin="lower",aspect=0.35,extent=extent,interpolation="None",vmax=0.18, cmap=palette) ax_theory.set_xlim(1,3.99) ax_theory.set_ylim(0,4.99) ax_theory.set_xlabel(r'$\;Q\;\; (\mathrm{\AA}^{-1})$') ax_theory.set_ylabel(r' E (meV)') # Add plot labels ax_exp.text(0.02,0.98,'Experiment', ha='left',va='top',transform=ax_exp.transAxes, path_effects=path_eff, color='w') ax_theory.text(0.02,0.98,'1D Simulation', ha='left',va='top',transform=ax_theory.transAxes, path_effects=path_eff, color='w') ## add a colorbar sm = plt.cm.ScalarMappable(cmap=palette, norm=mpl_colors.Normalize(vmin=0, vmax=vmax)) sm._A = [] loc = 'right' vshift = 0.00 axins1 = inset_axes(ax_theory, width="3%", height="95%", loc=loc, bbox_to_anchor=(-0.1, vshift, 1, 1), bbox_transform=ax_theory.transAxes, borderpad=0) cb = fig.colorbar(sm, cax=axins1, orientation='vertical', ticks=[0,vmax], extend='both') cb.set_label(r'$\;\;S(Q,E)\;\;$ (arb. units)',labelpad=-10, color='w') cb.ax.xaxis.set_tick_params(pad=0) cb.ax.set_yticklabels(['0', 'max'], color='w') # panel labels font_props = dgutils.fonts.get_custom_font_props(pore.bold_font_path) ax_exp.text(-0.075,1.0,'a', ha='left',va='top', transform=ax_exp.transAxes, font=font_props) ax_theory.text(-0.075,1.0,'b', ha='left',va='top', transform=ax_theory.transAxes, font=font_props) plt.savefig('../figures/SQE_exp_theory_vert.pdf', dpi=600) plt.savefig('../figures/SQE_exp_theory_vert.svg') ``` ```python ```
import data.real.basic import order.filter.at_top_bot import order.liminf_limsup import topology.metric_space.basic import topology.algebra.order.monotone_convergence import topology.instances.nnreal open_locale filter topological_space theorem real.exists_is_glb {S : set ℝ} (hne : S.nonempty) (hbdd : bdd_below S) : ∃ x, is_glb S x := begin set T := - S with hT, have hT_ne : T.nonempty := set.nonempty_neg.mpr hne, have hT_bdd : bdd_above T := bdd_above_neg.mpr hbdd, use -classical.some (real.exists_is_lub T hT_ne hT_bdd), simpa [← is_lub_neg] using (classical.some_spec (real.exists_is_lub T hT_ne hT_bdd)), end /- lemma le_of_is_lub {α : Type*} [preorder α] (S : set α) (B : α) (hB : is_lub S B) : ∀ s ∈ S, s ≤ B := begin intros s hs, simp [is_lub, is_least, mem_upper_bounds] at hB, exact hB.1 s hs, end -/ lemma filter.tendsto_of_is_bounded_monotone {f : ℕ → ℝ} (h_bdd : bdd_above (set.range f)) (h_mon : monotone f) : ∃ r : ℝ, filter.tendsto f filter.at_top (𝓝 r) := begin obtain ⟨B, hB⟩ := (real.exists_is_lub ((set.range f)) (set.range_nonempty f) h_bdd), use B, exact tendsto_at_top_is_lub h_mon hB, end lemma real.tendsto_of_is_bounded_antitone {f : ℕ → ℝ} (h_bdd : bdd_below (set.range f)) (h_ant : antitone f) : ∃ r : ℝ, filter.tendsto f filter.at_top (𝓝 r) := begin obtain ⟨B, hB⟩ := (real.exists_is_glb (set.range_nonempty f) h_bdd), use B, exact tendsto_at_top_is_glb h_ant hB, end lemma nnreal.tendsto_of_is_bounded_antitone {f : ℕ → nnreal} (h_bdd : bdd_below (set.range f)) (h_ant : antitone f) : ∃ r : nnreal, filter.tendsto f filter.at_top (𝓝 r) := begin have h_bdd_0 : (0 : ℝ) ∈ lower_bounds (set.range (λ (n : ℕ), (f n : ℝ))), { intros r hr, obtain ⟨n, hn⟩ := set.mem_range.mpr hr, simp_rw [← hn], exact nnreal.coe_nonneg _ }, have h_bdd : bdd_below (set.range (λ n, (f n : ℝ))) := ⟨0, h_bdd_0⟩, obtain ⟨L, hL⟩ := real.tendsto_of_is_bounded_antitone h_bdd h_ant, have hL0 : 0 ≤ L, { have h_glb : is_glb (set.range (λ n, (f n : ℝ))) L := is_glb_of_tendsto_at_top h_ant hL, exact (le_is_glb_iff h_glb).mpr h_bdd_0 }, use ⟨L, hL0⟩, rw ← nnreal.tendsto_coe, exact hL, end
------------------------------------------------------------------------ -- Partiality algebra categories ------------------------------------------------------------------------ {-# OPTIONS --cubical --safe #-} module Partiality-algebra.Category where open import Equality.Propositional.Cubical open import Logical-equivalence using (_⇔_) open import Prelude hiding (T) open import Bijection equality-with-J as Bijection using (_↔_) open import Category equality-with-J as Category open import Equality.Path.Isomorphisms.Univalence equality-with-paths open import Equivalence equality-with-J as Eq using (_≃_) open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import Structure-identity-principle equality-with-J open import Univalence-axiom equality-with-J open import Partiality-algebra as PA hiding (id; _∘_) ------------------------------------------------------------------------ -- Equality characterisation lemmas for Partiality-algebra-with abstract -- An equality characterisation lemma for Partiality-algebra-with. equality-characterisation-Partiality-algebra-with₁ : ∀ {a p q} {A : Type a} {T : Type p} {P₁ P₂ : Partiality-algebra-with T q A} → let module P₁ = Partiality-algebra-with P₁ module P₂ = Partiality-algebra-with P₂ in (∃ λ (⊑≡⊑ : ∀ x y → (x P₁.⊑ y) ≡ (x P₂.⊑ y)) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (≡⇒→ (⊑≡⊑ _ _) ∘_) s)) ↔ P₁ ≡ P₂ equality-characterisation-Partiality-algebra-with₁ {q = q} {A} {T} {P₁} {P₂} = (∃ λ (⊑≡⊑ : ∀ x y → (x P₁.⊑ y) ≡ (x P₂.⊑ y)) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (≡⇒→ (⊑≡⊑ _ _) ∘_) s)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ s → ≡⇒↝ _ $ cong (λ (p : {f : ℕ → T} → _) → P₁.⨆ s ≡ P₂.⨆ (Σ-map id p s)) $ (implicit-Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → P₂.⊑-propositional) (≡⇒→ (⊑≡⊑ _ _) ∘_) (λ {f} → ≡⇒→ (cong (λ _⊑_ → ∀ n → f n ⊑ f (suc n)) (⟨ext⟩ (⟨ext⟩ ∘ ⊑≡⊑))))) ⟩ (∃ λ (⊑≡⊑ : ∀ x y → (x P₁.⊑ y) ≡ (x P₂.⊑ y)) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (λ {f} → ≡⇒→ (cong (λ _⊑_ → ∀ n → f n ⊑ f (suc n)) (⟨ext⟩ (⟨ext⟩ ∘ ⊑≡⊑)))) s)) ↝⟨ Σ-cong (∀-cong ext λ _ → Eq.extensionality-isomorphism bad-ext) (λ _ → F.id) ⟩ (∃ λ (⊑≡⊑ : ∀ x → P₁._⊑_ x ≡ P₂._⊑_ x) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (λ {f} → ≡⇒→ (cong (λ _⊑_ → ∀ n → f n ⊑ f (suc n)) (⟨ext⟩ ⊑≡⊑))) s)) ↝⟨ Σ-cong (Eq.extensionality-isomorphism bad-ext) (λ _ → F.id) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (λ {f} → ≡⇒→ (cong (λ _⊑_ → ∀ n → f n ⊑ f (suc n)) ⊑≡⊑)) s)) ↔⟨⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ ( proj₁ s , ≡⇒→ (cong (λ _⊑_ → ∀ n → proj₁ s n ⊑ proj₁ s (suc n)) ⊑≡⊑) (proj₂ s) )) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ eq → _ ≡ P₂.⨆ (_ , ≡⇒→ eq _)) $ sym $ cong-∘ _ _ ⊑≡⊑) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ ( proj₁ s , ≡⇒→ (cong (uncurry λ _⊑_ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n)) (cong (_, _) ⊑≡⊑)) (proj₂ s) )) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ inc → _ ≡ P₂.⨆ (_ , inc)) $ sym $ subst-in-terms-of-≡⇒↝ equivalence (cong (_, _) ⊑≡⊑) _ _) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ ( proj₁ s , subst (uncurry λ _⊑_ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n)) (cong (_, _) ⊑≡⊑) (proj₂ s) )) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ eq → _ ≡ P₂.⨆ (_ , subst (uncurry λ _⊑_ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n)) eq _)) $ sym $ Σ-≡,≡→≡-subst-const ⊑≡⊑ refl) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ ( proj₁ s , subst (uncurry λ _⊑_ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n)) (Σ-≡,≡→≡ ⊑≡⊑ (subst-const ⊑≡⊑)) (proj₂ s) )) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ s → _ ≡ P₂.⨆ s) $ sym $ push-subst-pair′ {y≡z = ⊑≡⊑} _ _ (subst-const ⊑≡⊑)) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (subst (λ _⊑_ → ∃ λ f → ∀ n → f n ⊑ f (suc n)) ⊑≡⊑ s)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ eq → _ ≡ P₂.⨆ (subst (λ _⊑_ → ∃ λ f → ∀ n → f n ⊑ f (suc n)) eq _)) $ sym $ sym-sym ⊑≡⊑) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (subst (λ _⊑_ → ∃ λ f → ∀ n → f n ⊑ f (suc n)) (sym (sym ⊑≡⊑)) s)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (_ ≡_) $ sym $ subst-→-domain _ (sym ⊑≡⊑)) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ subst (λ _⊑_ → ∃ (λ f → ∀ n → f n ⊑ f (suc n)) → T) (sym ⊑≡⊑) P₂.⨆ s) ↔⟨ ∃-cong (λ _ → ∃-cong λ _ → Eq.extensionality-isomorphism ext ×-cong Eq.extensionality-isomorphism ext) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × P₁.now ≡ P₂.now × P₁.⨆ ≡ subst _ (sym ⊑≡⊑) P₂.⨆) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ≡⇒↝ _ $ elim (λ ⊑≡⊑ → ∀ {⨆₁ ⨆₂} → (⨆₁ ≡ subst _ (sym ⊑≡⊑) ⨆₂) ≡ (subst _ ⊑≡⊑ ⨆₁ ≡ ⨆₂)) (λ _ → refl) ⊑≡⊑) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → P₁.never ≡ P₂.never × P₁.now ≡ P₂.now × subst _ ⊑≡⊑ P₁.⨆ ≡ P₂.⨆) ↝⟨ ∃-cong (λ ⊑≡⊑ → ≡⇒↝ _ (cong (_≡ _) $ sym $ subst-const ⊑≡⊑) ×-cong ≡⇒↝ _ (cong (_≡ _) $ sym $ subst-const ⊑≡⊑) ×-cong F.id) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → subst _ ⊑≡⊑ P₁.never ≡ P₂.never × subst _ ⊑≡⊑ P₁.now ≡ P₂.now × subst _ ⊑≡⊑ P₁.⨆ ≡ P₂.⨆) ↝⟨ ∃-cong (λ _ → ∃-cong λ _ → ≡×≡↔≡) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → subst _ ⊑≡⊑ P₁.never ≡ P₂.never × (subst _ ⊑≡⊑ P₁.now , subst _ ⊑≡⊑ P₁.⨆) ≡ (P₂.now , P₂.⨆)) ↝⟨ ∃-cong (λ _ → ≡×≡↔≡) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → (subst _ ⊑≡⊑ P₁.never , subst _ ⊑≡⊑ P₁.now , subst _ ⊑≡⊑ P₁.⨆) ≡ (P₂.never , P₂.now , P₂.⨆)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ≡⇒↝ _ $ cong (λ x → (subst _ ⊑≡⊑ P₁.never , x) ≡ _) $ sym $ push-subst-, {y≡z = ⊑≡⊑} _ (λ _⊑_ → (∃ λ f → ∀ n → f n ⊑ f (suc n)) → _)) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → (subst _ ⊑≡⊑ P₁.never , subst _ ⊑≡⊑ (P₁.now , P₁.⨆)) ≡ (P₂.never , P₂.now , P₂.⨆)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ≡⇒↝ _ $ cong (_≡ _) $ sym $ push-subst-, {y≡z = ⊑≡⊑} _ _) ⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → subst _ ⊑≡⊑ (P₁.never , P₁.now , P₁.⨆) ≡ (P₂.never , P₂.now , P₂.⨆)) ↔⟨⟩ (∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) → subst _ ⊑≡⊑ (proj₂ (proj₁ (_↔_.to rearrange P₁))) ≡ proj₂ (proj₁ (_↔_.to rearrange P₂))) ↝⟨ Bijection.Σ-≡,≡↔≡ ⟩ proj₁ (_↔_.to rearrange P₁) ≡ proj₁ (_↔_.to rearrange P₂) ↝⟨ ignore-propositional-component (×-closure 1 (implicit-Π-closure ext 1 λ _ → implicit-Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → P₂.T-is-set) $ ×-closure 1 (H-level-propositional ext 2) $ ×-closure 1 (Π-closure ext 1 λ _ → P₂.⊑-propositional) $ ×-closure 1 (implicit-Π-closure ext 1 λ _ → implicit-Π-closure ext 1 λ _ → implicit-Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → P₂.⊑-propositional) $ ×-closure 1 (Π-closure ext 1 λ _ → P₂.⊑-propositional) $ ×-closure 1 (Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → P₂.⊑-propositional) $ ×-closure 1 (Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → P₂.⊑-propositional) (implicit-Π-closure ext 1 λ _ → implicit-Π-closure ext 1 λ _ → Is-proposition-propositional ext)) ⟩ _↔_.to rearrange P₁ ≡ _↔_.to rearrange P₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ rearrange) ⟩□ P₁ ≡ P₂ □ where module P₁ = Partiality-algebra-with P₁ module P₂ = Partiality-algebra-with P₂ rearrange : Partiality-algebra-with T q A ↔ ∃ λ ((_⊑_ , never , _ , ⨆) : ∃ λ (_⊑_ : T → T → Type q) → T × (A → T) × ((∃ λ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n)) → T)) → (∀ {x y} → x ⊑ y → y ⊑ x → x ≡ y) × Is-set T × (∀ x → x ⊑ x) × (∀ {x y z} → x ⊑ y → y ⊑ z → x ⊑ z) × (∀ x → never ⊑ x) × (∀ s → ∀ n → proj₁ s n ⊑ ⨆ s) × (∀ s ub → (∀ n → proj₁ s n ⊑ ub) → ⨆ s ⊑ ub) × (∀ {x y} → Is-proposition (x ⊑ y)) rearrange = record { surjection = record { logical-equivalence = record { to = λ P → let open Partiality-algebra-with P in ( _⊑_ , never , now , ⨆ ) , antisymmetry , T-is-set-unused , ⊑-refl , ⊑-trans , never⊑ , upper-bound , least-upper-bound , ⊑-propositional ; from = λ where ((LE , ne , n , l) , a , u , r , t , le , ub , lub , p) → record { _⊑_ = LE ; never = ne ; now = n ; ⨆ = l ; antisymmetry = a ; T-is-set-unused = u ; ⊑-refl = r ; ⊑-trans = t ; never⊑ = le ; upper-bound = ub ; least-upper-bound = lub ; ⊑-propositional = p } } ; right-inverse-of = λ _ → refl } ; left-inverse-of = λ _ → refl } -- Another equality characterisation lemma for -- Partiality-algebra-with. equality-characterisation-Partiality-algebra-with₂ : ∀ {a p q} {A : Type a} {T : Type p} {P₁ P₂ : Partiality-algebra-with T q A} → let module P₁ = Partiality-algebra-with P₁ module P₂ = Partiality-algebra-with P₂ in (∃ λ (⊑⇔⊑ : ∀ x y → x P₁.⊑ y ⇔ x P₂.⊑ y) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (_⇔_.to (⊑⇔⊑ _ _) ∘_) s)) ↔ P₁ ≡ P₂ equality-characterisation-Partiality-algebra-with₂ {q = q} {A} {T} {P₁} {P₂} = (∃ λ (⊑⇔⊑ : ∀ x y → x P₁.⊑ y ⇔ x P₂.⊑ y) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (_⇔_.to (⊑⇔⊑ _ _) ∘_) s)) ↝⟨ Σ-cong (∀-cong ext λ _ → ∀-cong ext λ _ → Eq.⇔↔≃ ext P₁.⊑-propositional P₂.⊑-propositional) (λ _ → F.id) ⟩ (∃ λ (⊑≃⊑ : ∀ x y → (x P₁.⊑ y) ≃ (x P₂.⊑ y)) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (_≃_.to (⊑≃⊑ _ _) ∘_) s)) ↝⟨ inverse $ Σ-cong (∀-cong ext λ _ → ∀-cong ext λ _ → ≡≃≃ (_≃_.to (Propositional-extensionality-is-univalence-for-propositions ext) prop-ext P₁.⊑-propositional P₂.⊑-propositional)) (λ _ → F.id) ⟩ (∃ λ (⊑≡⊑ : ∀ x y → (x P₁.⊑ y) ≡ (x P₂.⊑ y)) → P₁.never ≡ P₂.never × (∀ x → P₁.now x ≡ P₂.now x) × ∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (≡⇒→ (⊑≡⊑ _ _) ∘_) s)) ↝⟨ equality-characterisation-Partiality-algebra-with₁ ⟩□ P₁ ≡ P₂ □ where module P₁ = Partiality-algebra-with P₁ module P₂ = Partiality-algebra-with P₂ ------------------------------------------------------------------------ -- Partiality algebra categories -- Partiality algebras (with fixed levels and types) form -- precategories. precategory : ∀ {a} p q (A : Type a) → Precategory (a ⊔ lsuc (p ⊔ q)) (a ⊔ p ⊔ q) Precategory.precategory (precategory p q A) = Partiality-algebra p q A , (λ P Q → Morphism P Q , Morphism-set) , PA.id , PA._∘_ , _↔_.to equality-characterisation-Morphism refl , _↔_.to equality-characterisation-Morphism refl , _↔_.to equality-characterisation-Morphism refl -- A "standard notion of structure" built using -- Partiality-algebra-with. standard-notion-of-structure : ∀ {a} p q (A : Type a) → Standard-notion-of-structure _ _ (precategory-Set p ext) standard-notion-of-structure p q A = record { P = λ B → Partiality-algebra-with (proj₁ B) q A ; H = Is-morphism-with ; H-prop = λ { {p = P} {q = Q} _ → Is-morphism-with-propositional P Q } ; H-id = λ { {p = P} → proj₂ $ _↔_.to Morphism↔Morphism-as-Σ (PA.id {P = ⟨ P ⟩}) } ; H-∘ = λ { {p = P} {q = Q} {r = R} f-morphism g-morphism → proj₂ $ _↔_.to Morphism↔Morphism-as-Σ (_↔_.from (Morphism↔Morphism-as-Σ {P₁ = ⟨ Q ⟩} {P₂ = ⟨ R ⟩}) (_ , g-morphism) PA.∘ _↔_.from (Morphism↔Morphism-as-Σ {P₁ = ⟨ P ⟩}) (_ , f-morphism)) } ; H-antisymmetric = λ P Q id-morphism-P→Q id-morphism-Q→P → _↔_.to (equality-characterisation-Partiality-algebra-with₂) ( (λ x y → record { to = proj₁ id-morphism-P→Q ; from = proj₁ id-morphism-Q→P }) , proj₁ (proj₂ id-morphism-P→Q) , proj₁ (proj₂ (proj₂ id-morphism-P→Q)) , proj₂ (proj₂ (proj₂ id-morphism-P→Q)) ) } abstract -- The precategory obtained from the standard notion of structure is -- equal to the direct definition above. precategories-equal : ∀ {a p q} {A : Type a} → Standard-notion-of-structure.Str (standard-notion-of-structure p q A) ≡ precategory p q A precategories-equal {p = p} {q} {A} = _↔_.to (equality-characterisation-Precategory ext univ univ) ( ≃Partiality-algebra , (λ _ _ → Eq.↔⇒≃ $ inverse $ Morphism↔Morphism-as-Σ) , (λ _ → refl) , (λ _ _ _ _ _ → refl) ) where ≃Partiality-algebra : (∃ λ (T : Set p) → Partiality-algebra-with (proj₁ T) q A) ≃ Partiality-algebra p q A ≃Partiality-algebra = (∃ λ (T : Set p) → Partiality-algebra-with (proj₁ T) q A) ↔⟨ inverse Σ-assoc ⟩ (∃ λ (T : Type p) → Is-set T × Partiality-algebra-with T q A) ↔⟨ ∃-cong (λ _ → drop-⊤-left-× λ P → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (H-level-propositional ext 2) (Partiality-algebra-with.T-is-set P)) ⟩ (∃ λ (T : Type p) → Partiality-algebra-with T q A) ↝⟨ Eq.↔⇒≃ record { surjection = record { logical-equivalence = record { to = uncurry λ _ P → ⟨ P ⟩ ; from = λ P → T P , partiality-algebra-with P } ; right-inverse-of = λ _ → refl } ; left-inverse-of = λ _ → refl } ⟩□ Partiality-algebra p q A □ where open Partiality-algebra -- Thus the precategory is a category. category : ∀ {a} p q (A : Type a) → Category (a ⊔ lsuc (p ⊔ q)) (a ⊔ p ⊔ q) Category.category (category p q A) = precategory _ _ A , subst (λ C → ∀ {P Q} → Eq.Is-equivalence (Precategory.≡→≅ C {P} {Q})) precategories-equal (structure-identity-principle ext (category-Set _ ext (λ _ _ → univ)) (standard-notion-of-structure p q A)) private precategory-category : ∀ {a p q} {A : Type a} → Category.precategory (category p q A) ≡ precategory p q A precategory-category = refl
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Simon Hudon -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.control.functor import Mathlib.PostPort universes u v w l s t u_1 namespace Mathlib /-! # Traversable type class Type classes for traversing collections. The concepts and laws are taken from <http://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Traversable.html> Traversable collections are a generalization of functors. Whereas functors (such as `list`) allow us to apply a function to every element, it does not allow functions which external effects encoded in a monad. Consider for instance a functor `invite : email → io response` that takes an email address, sends an email and waits for a response. If we have a list `guests : list email`, using calling `invite` using `map` gives us the following: `map invite guests : list (io response)`. It is not what we need. We need something of type `io (list response)`. Instead of using `map`, we can use `traverse` to send all the invites: `traverse invite guests : io (list response)`. `traverse` applies `invite` to every element of `guests` and combines all the resulting effects. In the example, the effect is encoded in the monad `io` but any applicative functor is accepted by `traverse`. For more on how to use traversable, consider the Haskell tutorial: <https://en.wikibooks.org/wiki/Haskell/Traversable> ## Main definitions * `traversable` type class - exposes the `traverse` function * `sequence` - based on `traverse`, turns a collection of effects into an effect returning a collection * `is_lawful_traversable` - laws for a traversable functor * `applicative_transformation` - the notion of a natural transformation for applicative functors ## Tags traversable iterator functor applicative ## References * "Applicative Programming with Effects", by Conor McBride and Ross Paterson, Journal of Functional Programming 18:1 (2008) 1-13, online at <http://www.soi.city.ac.uk/~ross/papers/Applicative.html> * "The Essence of the Iterator Pattern", by Jeremy Gibbons and Bruno Oliveira, in Mathematically-Structured Functional Programming, 2006, online at <http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/#iterator> * "An Investigation of the Laws of Traversals", by Mauro Jaskelioff and Ondrej Rypacek, in Mathematically-Structured Functional Programming, 2012, online at <http://arxiv.org/pdf/1202.2919> -/ /-- A transformation between applicative functors. It a natural transformation such that `app` preserves the `has_pure.pure` and `functor.map` (`<*>`) operations. See `applicative_transformation.preserves_map` for naturality. -/ structure applicative_transformation (F : Type u → Type v) [Applicative F] [is_lawful_applicative F] (G : Type u → Type w) [Applicative G] [is_lawful_applicative G] where app : (α : Type u) → F α → G α preserves_pure' : ∀ {α : Type u} (x : α), app α (pure x) = pure x preserves_seq' : ∀ {α β : Type u} (x : F (α → β)) (y : F α), app β (x <*> y) = app (α → β) x <*> app α y namespace applicative_transformation protected instance has_coe_to_fun (F : Type u → Type v) [Applicative F] [is_lawful_applicative F] (G : Type u → Type w) [Applicative G] [is_lawful_applicative G] : has_coe_to_fun (applicative_transformation F G) := has_coe_to_fun.mk (fun (_x : applicative_transformation F G) => {α : Type u} → F α → G α) fun (a : applicative_transformation F G) => app a @[simp] theorem app_eq_coe {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) : app η = ⇑η := rfl @[simp] theorem coe_mk {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (f : (α : Type u) → F α → G α) (pp : ∀ {α : Type u} (x : α), f α (pure x) = pure x) (ps : ∀ {α β : Type u} (x : F (α → β)) (y : F α), f β (x <*> y) = f (α → β) x <*> f α y) : ⇑(mk f pp ps) = f := rfl protected theorem congr_fun {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) (η' : applicative_transformation F G) (h : η = η') {α : Type u} (x : F α) : coe_fn η α x = coe_fn η' α x := congr_arg (fun (η'' : applicative_transformation F G) => coe_fn η'' α x) h protected theorem congr_arg {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) {α : Type u} {x : F α} {y : F α} (h : x = y) : coe_fn η α x = coe_fn η α y := congr_arg (fun (z : F α) => coe_fn η α z) h theorem coe_inj {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] {η : applicative_transformation F G} {η' : applicative_transformation F G} (h : ⇑η = ⇑η') : η = η' := sorry theorem ext {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] {η : applicative_transformation F G} {η' : applicative_transformation F G} (h : ∀ (α : Type u) (x : F α), coe_fn η α x = coe_fn η' α x) : η = η' := coe_inj (funext fun (α : Type u) => funext (h α)) theorem ext_iff {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] {η : applicative_transformation F G} {η' : applicative_transformation F G} : η = η' ↔ ∀ (α : Type u) (x : F α), coe_fn η α x = coe_fn η' α x := { mp := fun (h : η = η') (α : Type u) (x : F α) => h ▸ rfl, mpr := fun (h : ∀ (α : Type u) (x : F α), coe_fn η α x = coe_fn η' α x) => ext h } theorem preserves_pure {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) {α : Type u} (x : α) : coe_fn η α (pure x) = pure x := preserves_pure' η theorem preserves_seq {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) {α : Type u} {β : Type u} (x : F (α → β)) (y : F α) : coe_fn η β (x <*> y) = coe_fn η (α → β) x <*> coe_fn η α y := preserves_seq' η theorem preserves_map {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) {α : Type u} {β : Type u} (x : α → β) (y : F α) : coe_fn η β (x <$> y) = x <$> coe_fn η α y := sorry theorem preserves_map' {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) {α : Type u} {β : Type u} (x : α → β) : coe_fn η β ∘ Functor.map x = Functor.map x ∘ coe_fn η α := funext fun (y : F α) => preserves_map η x y /-- The identity applicative transformation from an applicative functor to itself. -/ def id_transformation {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] : applicative_transformation F F := mk (fun (α : Type u) => id) sorry sorry protected instance inhabited {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] : Inhabited (applicative_transformation F F) := { default := id_transformation } /-- The composition of applicative transformations. -/ def comp {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] {H : Type u → Type s} [Applicative H] [is_lawful_applicative H] (η' : applicative_transformation G H) (η : applicative_transformation F G) : applicative_transformation F H := mk (fun (α : Type u) (x : F α) => coe_fn η' α (coe_fn η α x)) sorry sorry @[simp] theorem comp_apply {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] {H : Type u → Type s} [Applicative H] [is_lawful_applicative H] (η' : applicative_transformation G H) (η : applicative_transformation F G) {α : Type u} (x : F α) : coe_fn (comp η' η) α x = coe_fn η' α (coe_fn η α x) := rfl theorem comp_assoc {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] {H : Type u → Type s} [Applicative H] [is_lawful_applicative H] {I : Type u → Type t} [Applicative I] [is_lawful_applicative I] (η'' : applicative_transformation H I) (η' : applicative_transformation G H) (η : applicative_transformation F G) : comp (comp η'' η') η = comp η'' (comp η' η) := rfl @[simp] theorem comp_id {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) : comp η id_transformation = η := ext fun (α : Type u) (x : F α) => rfl @[simp] theorem id_comp {F : Type u → Type v} [Applicative F] [is_lawful_applicative F] {G : Type u → Type w} [Applicative G] [is_lawful_applicative G] (η : applicative_transformation F G) : comp id_transformation η = η := ext fun (α : Type u) (x : F α) => rfl end applicative_transformation /-- A traversable functor is a functor along with a way to commute with all applicative functors (see `sequence`). For example, if `t` is the traversable functor `list` and `m` is the applicative functor `io`, then given a function `f : α → io β`, the function `functor.map f` is `list α → list (io β)`, but `traverse f` is `list α → io (list β)`. -/ class traversable (t : Type u → Type u) extends Functor t where traverse : {m : Type u → Type u} → [_inst_1 : Applicative m] → {α β : Type u} → (α → m β) → t α → m (t β) /-- A traversable functor commutes with all applicative functors. -/ def sequence {t : Type u → Type u} {α : Type u} {f : Type u → Type u} [Applicative f] [traversable t] : t (f α) → f (t α) := traverse id /-- A traversable functor is lawful if its `traverse` satisfies a number of additional properties. It must send `id.mk` to `id.mk`, send the composition of applicative functors to the composition of the `traverse` of each, send each function `f` to `λ x, f <$> x`, and satisfy a naturality condition with respect to applicative transformations. -/ class is_lawful_traversable (t : Type u → Type u) [traversable t] extends is_lawful_functor t where id_traverse : ∀ {α : Type u} (x : t α), traverse id.mk x = x comp_traverse : ∀ {F G : Type u → Type u} [_inst_1_1 : Applicative F] [_inst_2 : Applicative G] [_inst_3 : is_lawful_applicative F] [_inst_4 : is_lawful_applicative G] {α β γ : Type u} (f : β → F γ) (g : α → G β) (x : t α), traverse (functor.comp.mk ∘ Functor.map f ∘ g) x = functor.comp.mk (traverse f <$> traverse g x) traverse_eq_map_id : ∀ {α β : Type u} (f : α → β) (x : t α), traverse (id.mk ∘ f) x = id.mk (f <$> x) naturality : ∀ {F G : Type u → Type u} [_inst_1_1 : Applicative F] [_inst_2 : Applicative G] [_inst_3 : is_lawful_applicative F] [_inst_4 : is_lawful_applicative G] (η : applicative_transformation F G) {α β : Type u} (f : α → F β) (x : t α), coe_fn η (t β) (traverse f x) = traverse (coe_fn η β ∘ f) x protected instance id.traversable : traversable id := traversable.mk fun (_x : Type u_1 → Type u_1) (_x_1 : Applicative _x) (_x_2 _x_3 : Type u_1) => id protected instance id.is_lawful_traversable : is_lawful_traversable id := is_lawful_traversable.mk sorry sorry sorry sorry protected instance option.traversable : traversable Option := traversable.mk option.traverse protected instance list.traversable : traversable List := traversable.mk list.traverse namespace sum /-- Defines a `traverse` function on the second component of a sum type. This is used to give a `traversable` instance for the functor `σ ⊕ -`. -/ protected def traverse {σ : Type u} {F : Type u → Type u} [Applicative F] {α : Type u_1} {β : Type u} (f : α → F β) : σ ⊕ α → F (σ ⊕ β) := sorry end sum protected instance sum.traversable {σ : Type u} : traversable (sum σ) := traversable.mk sum.traverse end Mathlib
function test_failed=test_demos %TEST_DEMOS Test if all the demos runs without errors. test_failed=0; s=dir([ltfatbasepath,filesep,'demos',filesep,'demo_*.m']); for ii=1:numel(s) filename = s(ii).name; disp(filename); % The demo is run in separate function to avoid % variable name clash rundemo(filename(1:end-2)); end function rundemo(demoname) close all; eval(demoname); clear all;
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis ! This file was ported from Lean 3 source module number_theory.padics.padic_numbers ! leanprover-community/mathlib commit b9b2114f7711fec1c1e055d507f082f8ceb2c3b7 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.NumberTheory.Padics.PadicNorm import Mathbin.Analysis.Normed.Field.Basic /-! # p-adic numbers This file defines the `p`-adic numbers (rationals) `ℚ_[p]` as the completion of `ℚ` with respect to the `p`-adic norm. We show that the `p`-adic norm on `ℚ` extends to `ℚ_[p]`, that `ℚ` is embedded in `ℚ_[p]`, and that `ℚ_[p]` is Cauchy complete. ## Important definitions * `padic` : the type of `p`-adic numbers * `padic_norm_e` : the rational valued `p`-adic norm on `ℚ_[p]` * `padic.add_valuation` : the additive `p`-adic valuation on `ℚ_[p]`, with values in `with_top ℤ` ## Notation We introduce the notation `ℚ_[p]` for the `p`-adic numbers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[fact p.prime]` as a type class argument. We use the same concrete Cauchy sequence construction that is used to construct `ℝ`. `ℚ_[p]` inherits a field structure from this construction. The extension of the norm on `ℚ` to `ℚ_[p]` is *not* analogous to extending the absolute value to `ℝ` and hence the proof that `ℚ_[p]` is complete is different from the proof that ℝ is complete. A small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence indices in the proof that the norm extends. `padic_norm_e` is the rational-valued `p`-adic norm on `ℚ_[p]`. To instantiate `ℚ_[p]` as a normed field, we must cast this into a `ℝ`-valued norm. The `ℝ`-valued norm, using notation `‖ ‖` from normed spaces, is the canonical representation of this norm. `simp` prefers `padic_norm` to `padic_norm_e` when possible. Since `padic_norm_e` and `‖ ‖` have different types, `simp` does not rewrite one to the other. Coercions from `ℚ` to `ℚ_[p]` are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion -/ noncomputable section open Classical open Nat multiplicity padicNorm CauSeq CauSeq.Completion Metric /-- The type of Cauchy sequences of rationals with respect to the `p`-adic norm. -/ @[reducible] def PadicSeq (p : ℕ) := CauSeq _ (padicNorm p) #align padic_seq PadicSeq namespace PadicSeq section variable {p : ℕ} [Fact p.Prime] /-- The `p`-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually constant. -/ theorem stationary {f : CauSeq ℚ (padicNorm p)} (hf : ¬f ≈ 0) : ∃ N, ∀ m n, N ≤ m → N ≤ n → padicNorm p (f n) = padicNorm p (f m) := have : ∃ ε > 0, ∃ N1, ∀ j ≥ N1, ε ≤ padicNorm p (f j) := CauSeq.abv_pos_of_not_limZero <| not_limZero_of_not_congr_zero hf let ⟨ε, hε, N1, hN1⟩ := this let ⟨N2, hN2⟩ := CauSeq.cauchy₂ f hε ⟨max N1 N2, fun n m hn hm => by have : padicNorm p (f n - f m) < ε := hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2 have : padicNorm p (f n - f m) < padicNorm p (f n) := lt_of_lt_of_le this <| hN1 _ (max_le_iff.1 hn).1 have : padicNorm p (f n - f m) < max (padicNorm p (f n)) (padicNorm p (f m)) := lt_max_iff.2 (Or.inl this) by_contra hne rw [← padicNorm.neg (f m)] at hne have hnam := add_eq_max_of_ne hne rw [padicNorm.neg, max_comm] at hnam rw [← hnam, sub_eq_add_neg, add_comm] at this apply _root_.lt_irrefl _ this⟩ #align padic_seq.stationary PadicSeq.stationary /-- For all `n ≥ stationary_point f hf`, the `p`-adic norm of `f n` is the same. -/ def stationaryPoint {f : PadicSeq p} (hf : ¬f ≈ 0) : ℕ := Classical.choose <| stationary hf #align padic_seq.stationary_point PadicSeq.stationaryPoint theorem stationaryPoint_spec {f : PadicSeq p} (hf : ¬f ≈ 0) : ∀ {m n}, stationaryPoint hf ≤ m → stationaryPoint hf ≤ n → padicNorm p (f n) = padicNorm p (f m) := Classical.choose_spec <| stationary hf #align padic_seq.stationary_point_spec PadicSeq.stationaryPoint_spec /-- Since the norm of the entries of a Cauchy sequence is eventually stationary, we can lift the norm to sequences. -/ def norm (f : PadicSeq p) : ℚ := if hf : f ≈ 0 then 0 else padicNorm p (f (stationaryPoint hf)) #align padic_seq.norm PadicSeq.norm theorem norm_zero_iff (f : PadicSeq p) : f.norm = 0 ↔ f ≈ 0 := by constructor · intro h by_contra hf unfold norm at h split_ifs at h apply hf intro ε hε exists stationary_point hf intro j hj have heq := stationary_point_spec hf le_rfl hj simpa [h, HEq] · intro h simp [norm, h] #align padic_seq.norm_zero_iff PadicSeq.norm_zero_iff end section Embedding open CauSeq variable {p : ℕ} [Fact p.Prime] theorem equiv_zero_of_val_eq_of_equiv_zero {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) (hf : f ≈ 0) : g ≈ 0 := fun ε hε => let ⟨i, hi⟩ := hf _ hε ⟨i, fun j hj => by simpa [h] using hi _ hj⟩ #align padic_seq.equiv_zero_of_val_eq_of_equiv_zero PadicSeq.equiv_zero_of_val_eq_of_equiv_zero theorem norm_nonzero_of_not_equiv_zero {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm ≠ 0 := hf ∘ f.norm_zero_iff.1 #align padic_seq.norm_nonzero_of_not_equiv_zero PadicSeq.norm_nonzero_of_not_equiv_zero theorem norm_eq_norm_app_of_nonzero {f : PadicSeq p} (hf : ¬f ≈ 0) : ∃ k, f.norm = padicNorm p k ∧ k ≠ 0 := have heq : f.norm = padicNorm p (f <| stationaryPoint hf) := by simp [norm, hf] ⟨f <| stationaryPoint hf, HEq, fun h => norm_nonzero_of_not_equiv_zero hf (by simpa [h] using HEq)⟩ #align padic_seq.norm_eq_norm_app_of_nonzero PadicSeq.norm_eq_norm_app_of_nonzero theorem not_limZero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬LimZero (const (padicNorm p) q) := fun h' => hq <| const_limZero.1 h' #align padic_seq.not_lim_zero_const_of_nonzero PadicSeq.not_limZero_const_of_nonzero theorem not_equiv_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬const (padicNorm p) q ≈ 0 := fun h : LimZero (const (padicNorm p) q - 0) => not_limZero_const_of_nonzero hq <| by simpa using h #align padic_seq.not_equiv_zero_const_of_nonzero PadicSeq.not_equiv_zero_const_of_nonzero theorem norm_nonneg (f : PadicSeq p) : 0 ≤ f.norm := if hf : f ≈ 0 then by simp [hf, norm] else by simp [norm, hf, padicNorm.nonneg] #align padic_seq.norm_nonneg PadicSeq.norm_nonneg /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_left_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v2 v3 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max (stationaryPoint hf) (max v2 v3))) := by apply stationary_point_spec hf · apply le_max_left · exact le_rfl #align padic_seq.lift_index_left_left PadicSeq.lift_index_left_left /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v3 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max v1 (max (stationaryPoint hf) v3))) := by apply stationary_point_spec hf · apply le_trans · apply le_max_left _ v3 · apply le_max_right · exact le_rfl #align padic_seq.lift_index_left PadicSeq.lift_index_left /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_right {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v2 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max v1 (max v2 (stationaryPoint hf)))) := by apply stationary_point_spec hf · apply le_trans · apply le_max_right v2 · apply le_max_right · exact le_rfl #align padic_seq.lift_index_right PadicSeq.lift_index_right end Embedding section Valuation open CauSeq variable {p : ℕ} [Fact p.Prime] /-! ### Valuation on `padic_seq` -/ /-- The `p`-adic valuation on `ℚ` lifts to `padic_seq p`. `valuation f` is defined to be the valuation of the (`ℚ`-valued) stationary point of `f`. -/ def valuation (f : PadicSeq p) : ℤ := if hf : f ≈ 0 then 0 else padicValRat p (f (stationaryPoint hf)) #align padic_seq.valuation PadicSeq.valuation theorem norm_eq_pow_val {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm = p ^ (-f.Valuation : ℤ) := by rw [norm, Valuation, dif_neg hf, dif_neg hf, padicNorm, if_neg] intro H apply CauSeq.not_limZero_of_not_congr_zero hf intro ε hε use stationary_point hf intro n hn rw [stationary_point_spec hf le_rfl hn] simpa [H] using hε #align padic_seq.norm_eq_pow_val PadicSeq.norm_eq_pow_val theorem val_eq_iff_norm_eq {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : f.Valuation = g.Valuation ↔ f.norm = g.norm := by rw [norm_eq_pow_val hf, norm_eq_pow_val hg, ← neg_inj, zpow_inj] · exact_mod_cast (Fact.out p.prime).Pos · exact_mod_cast (Fact.out p.prime).ne_one #align padic_seq.val_eq_iff_norm_eq PadicSeq.val_eq_iff_norm_eq end Valuation end PadicSeq section open PadicSeq private unsafe def index_simp_core (hh hf hg : expr) (at_ : Interactive.Loc := Interactive.Loc.ns [none]) : tactic Unit := do let [v1, v2, v3] ← [hh, hf, hg].mapM fun n => tactic.mk_app `` stationary_point [n] <|> return n let e1 ← tactic.mk_app `` lift_index_left_left [hh, v2, v3] <|> return q(True) let e2 ← tactic.mk_app `` lift_index_left [hf, v1, v3] <|> return q(True) let e3 ← tactic.mk_app `` lift_index_right [hg, v1, v2] <|> return q(True) let sl ← [e1, e2, e3].foldlM (fun s e => simp_lemmas.add s e) simp_lemmas.mk when at_ (tactic.simp_target sl >> tactic.skip) let hs ← at_.get_locals hs (tactic.simp_hyp sl []) #align index_simp_core index_simp_core /-- This is a special-purpose tactic that lifts `padic_norm (f (stationary_point f))` to `padic_norm (f (max _ _ _))`. -/ unsafe def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list) (at_ : interactive.parse interactive.types.location) : tactic Unit := do let [h, f, g] ← l.mapM tactic.i_to_expr index_simp_core h f g at_ #align tactic.interactive.padic_index_simp tactic.interactive.padic_index_simp end namespace PadicSeq section Embedding open CauSeq variable {p : ℕ} [hp : Fact p.Prime] include hp theorem norm_mul (f g : PadicSeq p) : (f * g).norm = f.norm * g.norm := if hf : f ≈ 0 then by have hg : f * g ≈ 0 := mul_equiv_zero' _ hf simp only [hf, hg, norm, dif_pos, MulZeroClass.zero_mul] else if hg : g ≈ 0 then by have hf : f * g ≈ 0 := mul_equiv_zero _ hg simp only [hf, hg, norm, dif_pos, MulZeroClass.mul_zero] else by have hfg : ¬f * g ≈ 0 := by apply mul_not_equiv_zero <;> assumption unfold norm split_ifs padic_index_simp [hfg, hf, hg] apply padicNorm.mul #align padic_seq.norm_mul PadicSeq.norm_mul theorem eq_zero_iff_equiv_zero (f : PadicSeq p) : mk f = 0 ↔ f ≈ 0 := mk_eq #align padic_seq.eq_zero_iff_equiv_zero PadicSeq.eq_zero_iff_equiv_zero theorem ne_zero_iff_nequiv_zero (f : PadicSeq p) : mk f ≠ 0 ↔ ¬f ≈ 0 := not_iff_not.2 (eq_zero_iff_equiv_zero _) #align padic_seq.ne_zero_iff_nequiv_zero PadicSeq.ne_zero_iff_nequiv_zero theorem norm_const (q : ℚ) : norm (const (padicNorm p) q) = padicNorm p q := if hq : q = 0 then by have : const (padicNorm p) q ≈ 0 := by simp [hq] <;> apply Setoid.refl (const (padicNorm p) 0) subst hq <;> simp [norm, this] else by have : ¬const (padicNorm p) q ≈ 0 := not_equiv_zero_const_of_nonzero hq simp [norm, this] #align padic_seq.norm_const PadicSeq.norm_const theorem norm_values_discrete (a : PadicSeq p) (ha : ¬a ≈ 0) : ∃ z : ℤ, a.norm = p ^ (-z) := by let ⟨k, hk, hk'⟩ := norm_eq_norm_app_of_nonzero ha simpa [hk] using padicNorm.values_discrete hk' #align padic_seq.norm_values_discrete PadicSeq.norm_values_discrete theorem norm_one : norm (1 : PadicSeq p) = 1 := by have h1 : ¬(1 : PadicSeq p) ≈ 0 := one_not_equiv_zero _ simp [h1, norm, hp.1.one_lt] #align padic_seq.norm_one PadicSeq.norm_one private theorem norm_eq_of_equiv_aux {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) (h : padicNorm p (f (stationaryPoint hf)) ≠ padicNorm p (g (stationaryPoint hg))) (hlt : padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) : False := by have hpn : 0 < padicNorm p (f (stationary_point hf)) - padicNorm p (g (stationary_point hg)) := sub_pos_of_lt hlt cases' hfg _ hpn with N hN let i := max N (max (stationary_point hf) (stationary_point hg)) have hi : N ≤ i := le_max_left _ _ have hN' := hN _ hi padic_index_simp [N, hf, hg] at hN' h hlt have hpne : padicNorm p (f i) ≠ padicNorm p (-g i) := by rwa [← padicNorm.neg (g i)] at h let hpnem := add_eq_max_of_ne hpne have hpeq : padicNorm p ((f - g) i) = max (padicNorm p (f i)) (padicNorm p (g i)) := by rwa [padicNorm.neg] at hpnem rw [hpeq, max_eq_left_of_lt hlt] at hN' have : padicNorm p (f i) < padicNorm p (f i) := by apply lt_of_lt_of_le hN' apply sub_le_self apply padicNorm.nonneg exact lt_irrefl _ this #align padic_seq.norm_eq_of_equiv_aux padic_seq.norm_eq_of_equiv_aux private theorem norm_eq_of_equiv {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (g (stationaryPoint hg)) := by by_contra h cases' Decidable.em (padicNorm p (g (stationary_point hg)) < padicNorm p (f (stationary_point hf))) with hlt hnlt · exact norm_eq_of_equiv_aux hf hg hfg h hlt · apply norm_eq_of_equiv_aux hg hf (Setoid.symm hfg) (Ne.symm h) apply lt_of_le_of_ne apply le_of_not_gt hnlt apply h #align padic_seq.norm_eq_of_equiv padic_seq.norm_eq_of_equiv theorem norm_equiv {f g : PadicSeq p} (hfg : f ≈ g) : f.norm = g.norm := if hf : f ≈ 0 then by have hg : g ≈ 0 := Setoid.trans (Setoid.symm hfg) hf simp [norm, hf, hg] else by have hg : ¬g ≈ 0 := hf ∘ Setoid.trans hfg unfold norm <;> split_ifs <;> exact norm_eq_of_equiv hf hg hfg #align padic_seq.norm_equiv PadicSeq.norm_equiv private theorem norm_nonarchimedean_aux {f g : PadicSeq p} (hfg : ¬f + g ≈ 0) (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : (f + g).norm ≤ max f.norm g.norm := by unfold norm; split_ifs padic_index_simp [hfg, hf, hg] apply padicNorm.nonarchimedean #align padic_seq.norm_nonarchimedean_aux padic_seq.norm_nonarchimedean_aux theorem norm_nonarchimedean (f g : PadicSeq p) : (f + g).norm ≤ max f.norm g.norm := if hfg : f + g ≈ 0 then by have : 0 ≤ max f.norm g.norm := le_max_of_le_left (norm_nonneg _) simpa only [hfg, norm, Ne.def, le_max_iff, CauSeq.add_apply, not_true, dif_pos] else if hf : f ≈ 0 then by have hfg' : f + g ≈ g := by change lim_zero (f - 0) at hf show lim_zero (f + g - g); · simpa only [sub_zero, add_sub_cancel] using hf have hcfg : (f + g).norm = g.norm := norm_equiv hfg' have hcl : f.norm = 0 := (norm_zero_iff f).2 hf have : max f.norm g.norm = g.norm := by rw [hcl] <;> exact max_eq_right (norm_nonneg _) rw [this, hcfg] else if hg : g ≈ 0 then by have hfg' : f + g ≈ f := by change lim_zero (g - 0) at hg show lim_zero (f + g - f); · simpa only [add_sub_cancel', sub_zero] using hg have hcfg : (f + g).norm = f.norm := norm_equiv hfg' have hcl : g.norm = 0 := (norm_zero_iff g).2 hg have : max f.norm g.norm = f.norm := by rw [hcl] <;> exact max_eq_left (norm_nonneg _) rw [this, hcfg] else norm_nonarchimedean_aux hfg hf hg #align padic_seq.norm_nonarchimedean PadicSeq.norm_nonarchimedean theorem norm_eq {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) : f.norm = g.norm := if hf : f ≈ 0 then by have hg : g ≈ 0 := equiv_zero_of_val_eq_of_equiv_zero h hf simp only [hf, hg, norm, dif_pos] else by have hg : ¬g ≈ 0 := fun hg => hf <| equiv_zero_of_val_eq_of_equiv_zero (by simp only [h, forall_const, eq_self_iff_true]) hg simp only [hg, hf, norm, dif_neg, not_false_iff] let i := max (stationary_point hf) (stationary_point hg) have hpf : padicNorm p (f (stationary_point hf)) = padicNorm p (f i) := by apply stationary_point_spec apply le_max_left exact le_rfl have hpg : padicNorm p (g (stationary_point hg)) = padicNorm p (g i) := by apply stationary_point_spec apply le_max_right exact le_rfl rw [hpf, hpg, h] #align padic_seq.norm_eq PadicSeq.norm_eq theorem norm_neg (a : PadicSeq p) : (-a).norm = a.norm := norm_eq <| by simp #align padic_seq.norm_neg PadicSeq.norm_neg theorem norm_eq_of_add_equiv_zero {f g : PadicSeq p} (h : f + g ≈ 0) : f.norm = g.norm := by have : LimZero (f + g - 0) := h have : f ≈ -g := show LimZero (f - -g) by simpa only [sub_zero, sub_neg_eq_add] have : f.norm = (-g).norm := norm_equiv this simpa only [norm_neg] using this #align padic_seq.norm_eq_of_add_equiv_zero PadicSeq.norm_eq_of_add_equiv_zero theorem add_eq_max_of_ne {f g : PadicSeq p} (hfgne : f.norm ≠ g.norm) : (f + g).norm = max f.norm g.norm := have hfg : ¬f + g ≈ 0 := mt norm_eq_of_add_equiv_zero hfgne if hf : f ≈ 0 then by have : LimZero (f - 0) := hf have : f + g ≈ g := show LimZero (f + g - g) by simpa only [sub_zero, add_sub_cancel] have h1 : (f + g).norm = g.norm := norm_equiv this have h2 : f.norm = 0 := (norm_zero_iff _).2 hf rw [h1, h2] <;> rw [max_eq_right (norm_nonneg _)] else if hg : g ≈ 0 then by have : LimZero (g - 0) := hg have : f + g ≈ f := show LimZero (f + g - f) by rw [add_sub_cancel'] <;> simpa only [sub_zero] have h1 : (f + g).norm = f.norm := norm_equiv this have h2 : g.norm = 0 := (norm_zero_iff _).2 hg rw [h1, h2] <;> rw [max_eq_left (norm_nonneg _)] else by unfold norm at hfgne⊢; split_ifs at hfgne⊢ padic_index_simp [hfg, hf, hg] at hfgne⊢ exact padicNorm.add_eq_max_of_ne hfgne #align padic_seq.add_eq_max_of_ne PadicSeq.add_eq_max_of_ne end Embedding end PadicSeq /-- The `p`-adic numbers `ℚ_[p]` are the Cauchy completion of `ℚ` with respect to the `p`-adic norm. -/ def Padic (p : ℕ) [Fact p.Prime] := @CauSeq.Completion.Cauchy _ _ _ _ (padicNorm p) _ #align padic Padic -- mathport name: «exprℚ_[ ]» notation "ℚ_[" p "]" => Padic p namespace Padic section Completion variable {p : ℕ} [Fact p.Prime] instance : Field ℚ_[p] := Cauchy.field instance : Inhabited ℚ_[p] := ⟨0⟩ -- short circuits instance : CommRing ℚ_[p] := Cauchy.commRing instance : Ring ℚ_[p] := Cauchy.ring instance : Zero ℚ_[p] := by infer_instance instance : One ℚ_[p] := by infer_instance instance : Add ℚ_[p] := by infer_instance instance : Mul ℚ_[p] := by infer_instance instance : Sub ℚ_[p] := by infer_instance instance : Neg ℚ_[p] := by infer_instance instance : Div ℚ_[p] := by infer_instance instance : AddCommGroup ℚ_[p] := by infer_instance /-- Builds the equivalence class of a Cauchy sequence of rationals. -/ def mk : PadicSeq p → ℚ_[p] := Quotient.mk' #align padic.mk Padic.mk variable (p) theorem zero_def : (0 : ℚ_[p]) = ⟦0⟧ := rfl #align padic.zero_def Padic.zero_def theorem mk_eq {f g : PadicSeq p} : mk f = mk g ↔ f ≈ g := Quotient.eq' #align padic.mk_eq Padic.mk_eq theorem const_equiv {q r : ℚ} : const (padicNorm p) q ≈ const (padicNorm p) r ↔ q = r := ⟨fun heq => eq_of_sub_eq_zero <| const_limZero.1 HEq, fun heq => by rw [HEq] <;> apply Setoid.refl _⟩ #align padic.const_equiv Padic.const_equiv @[norm_cast] theorem coe_inj {q r : ℚ} : (↑q : ℚ_[p]) = ↑r ↔ q = r := ⟨(const_equiv p).1 ∘ Quotient.eq'.1, fun h => by rw [h]⟩ #align padic.coe_inj Padic.coe_inj instance : CharZero ℚ_[p] := ⟨fun m n => by rw [← Rat.cast_coe_nat] norm_cast exact id⟩ @[norm_cast] theorem coe_add : ∀ {x y : ℚ}, (↑(x + y) : ℚ_[p]) = ↑x + ↑y := Rat.cast_add #align padic.coe_add Padic.coe_add @[norm_cast] theorem coe_neg : ∀ {x : ℚ}, (↑(-x) : ℚ_[p]) = -↑x := Rat.cast_neg #align padic.coe_neg Padic.coe_neg @[norm_cast] theorem coe_mul : ∀ {x y : ℚ}, (↑(x * y) : ℚ_[p]) = ↑x * ↑y := Rat.cast_mul #align padic.coe_mul Padic.coe_mul @[norm_cast] theorem coe_sub : ∀ {x y : ℚ}, (↑(x - y) : ℚ_[p]) = ↑x - ↑y := Rat.cast_sub #align padic.coe_sub Padic.coe_sub @[norm_cast] theorem coe_div : ∀ {x y : ℚ}, (↑(x / y) : ℚ_[p]) = ↑x / ↑y := Rat.cast_div #align padic.coe_div Padic.coe_div @[norm_cast] theorem coe_one : (↑1 : ℚ_[p]) = 1 := rfl #align padic.coe_one Padic.coe_one @[norm_cast] theorem coe_zero : (↑0 : ℚ_[p]) = 0 := rfl #align padic.coe_zero Padic.coe_zero end Completion end Padic /-- The rational-valued `p`-adic norm on `ℚ_[p]` is lifted from the norm on Cauchy sequences. The canonical form of this function is the normed space instance, with notation `‖ ‖`. -/ def padicNormE {p : ℕ} [hp : Fact p.Prime] : AbsoluteValue ℚ_[p] ℚ where toFun := Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _ map_mul' q r := Quotient.induction_on₂ q r <| PadicSeq.norm_mul nonneg' q := Quotient.inductionOn q <| PadicSeq.norm_nonneg eq_zero' q := Quotient.inductionOn q <| by simpa only [Padic.zero_def, Quotient.eq'] using PadicSeq.norm_zero_iff add_le' q r := by trans max ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) q) ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) r) exact Quotient.induction_on₂ q r <| PadicSeq.norm_nonarchimedean refine' max_le_add_of_nonneg (Quotient.inductionOn q <| PadicSeq.norm_nonneg) _ exact Quotient.inductionOn r <| PadicSeq.norm_nonneg #align padic_norm_e padicNormE namespace padicNormE section Embedding open PadicSeq variable {p : ℕ} [Fact p.Prime] theorem defn (f : PadicSeq p) {ε : ℚ} (hε : 0 < ε) : ∃ N, ∀ i ≥ N, padicNormE (⟦f⟧ - f i) < ε := by dsimp [padicNormE] change ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε by_contra' h cases' cauchy₂ f hε with N hN rcases h N with ⟨i, hi, hge⟩ have hne : ¬f - const (padicNorm p) (f i) ≈ 0 := by intro h unfold PadicSeq.norm at hge <;> split_ifs at hge exact not_lt_of_ge hge hε unfold PadicSeq.norm at hge <;> split_ifs at hge apply not_le_of_gt _ hge cases' em (N ≤ stationary_point hne) with hgen hngen · apply hN _ hgen _ hi · have := stationary_point_spec hne le_rfl (le_of_not_le hngen) rw [← this] exact hN _ le_rfl _ hi #align padic_norm_e.defn padicNormE.defn /-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the equivalent theorems about `norm` (`‖ ‖`). -/ theorem nonarchimedean' (q r : ℚ_[p]) : padicNormE (q + r) ≤ max (padicNormE q) (padicNormE r) := Quotient.induction_on₂ q r <| norm_nonarchimedean #align padic_norm_e.nonarchimedean' padicNormE.nonarchimedean' /-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the equivalent theorems about `norm` (`‖ ‖`). -/ theorem add_eq_max_of_ne' {q r : ℚ_[p]} : padicNormE q ≠ padicNormE r → padicNormE (q + r) = max (padicNormE q) (padicNormE r) := Quotient.induction_on₂ q r fun _ _ => PadicSeq.add_eq_max_of_ne #align padic_norm_e.add_eq_max_of_ne' padicNormE.add_eq_max_of_ne' @[simp] theorem eq_padic_norm' (q : ℚ) : padicNormE (q : ℚ_[p]) = padicNorm p q := norm_const _ #align padic_norm_e.eq_padic_norm' padicNormE.eq_padic_norm' protected theorem image' {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, padicNormE q = p ^ (-n) := Quotient.inductionOn q fun f hf => have : ¬f ≈ 0 := (ne_zero_iff_nequiv_zero f).1 hf norm_values_discrete f this #align padic_norm_e.image' padicNormE.image' end Embedding end padicNormE namespace Padic section Complete open PadicSeq Padic variable {p : ℕ} [Fact p.Prime] (f : CauSeq _ (@padicNormE p _)) /- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (m n «expr ≥ » N) -/ theorem rat_dense' (q : ℚ_[p]) {ε : ℚ} (hε : 0 < ε) : ∃ r : ℚ, padicNormE (q - r) < ε := Quotient.inductionOn q fun q' => have : ∃ N, ∀ (m) (_ : m ≥ N) (n) (_ : n ≥ N), padicNorm p (q' m - q' n) < ε := cauchy₂ _ hε let ⟨N, hN⟩ := this ⟨q' N, by dsimp [padicNormE] change PadicSeq.norm (q' - const _ (q' N)) < ε cases' Decidable.em (q' - const (padicNorm p) (q' N) ≈ 0) with heq hne' · simpa only [HEq, PadicSeq.norm, dif_pos] · simp only [PadicSeq.norm, dif_neg hne'] change padicNorm p (q' _ - q' _) < ε have := stationary_point_spec hne' cases' Decidable.em (stationary_point hne' ≤ N) with hle hle · have := Eq.symm (this le_rfl hle) simp only [const_apply, sub_apply, padicNorm.zero, sub_self] at this simpa only [this] · exact hN _ (lt_of_not_ge hle).le _ le_rfl⟩ #align padic.rat_dense' Padic.rat_dense' open Classical private theorem div_nat_pos (n : ℕ) : 0 < 1 / (n + 1 : ℚ) := div_pos zero_lt_one (by exact_mod_cast succ_pos _) #align padic.div_nat_pos padic.div_nat_pos /-- `lim_seq f`, for `f` a Cauchy sequence of `p`-adic numbers, is a sequence of rationals with the same limit point as `f`. -/ def limSeq : ℕ → ℚ := fun n => Classical.choose (rat_dense' (f n) (div_nat_pos n)) #align padic.lim_seq Padic.limSeq theorem exi_rat_seq_conv {ε : ℚ} (hε : 0 < ε) : ∃ N, ∀ i ≥ N, padicNormE (f i - (limSeq f i : ℚ_[p])) < ε := by refine' (exists_nat_gt (1 / ε)).imp fun N hN i hi => _ have h := Classical.choose_spec (rat_dense' (f i) (div_nat_pos i)) refine' lt_of_lt_of_le h ((div_le_iff' <| by exact_mod_cast succ_pos _).mpr _) rw [right_distrib] apply le_add_of_le_of_nonneg · exact (div_le_iff hε).mp (le_trans (le_of_lt hN) (by exact_mod_cast hi)) · apply le_of_lt simpa #align padic.exi_rat_seq_conv Padic.exi_rat_seq_conv theorem exi_rat_seq_conv_cauchy : IsCauSeq (padicNorm p) (limSeq f) := fun ε hε => by have hε3 : 0 < ε / 3 := div_pos hε (by norm_num) let ⟨N, hN⟩ := exi_rat_seq_conv f hε3 let ⟨N2, hN2⟩ := f.cauchy₂ hε3 exists max N N2 intro j hj suffices padicNormE (lim_seq f j - f (max N N2) + (f (max N N2) - lim_seq f (max N N2))) < ε by ring_nf at this⊢ rw [← padicNormE.eq_padic_norm'] exact_mod_cast this · apply lt_of_le_of_lt · apply padic_norm_e.add_le · have : (3 : ℚ) ≠ 0 := by norm_num have : ε = ε / 3 + ε / 3 + ε / 3 := by field_simp [this] simp only [bit0, bit1, mul_add, mul_one] rw [this] apply add_lt_add · suffices padicNormE (lim_seq f j - f j + (f j - f (max N N2))) < ε / 3 + ε / 3 by simpa only [sub_add_sub_cancel] apply lt_of_le_of_lt · apply padic_norm_e.add_le · apply add_lt_add · rw [padic_norm_e.map_sub] apply_mod_cast hN exact le_of_max_le_left hj · exact hN2 _ (le_of_max_le_right hj) _ (le_max_right _ _) · apply_mod_cast hN apply le_max_left #align padic.exi_rat_seq_conv_cauchy Padic.exi_rat_seq_conv_cauchy private def lim' : PadicSeq p := ⟨_, exi_rat_seq_conv_cauchy f⟩ #align padic.lim' padic.lim' private def lim : ℚ_[p] := ⟦lim' f⟧ #align padic.lim padic.lim theorem complete' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (q - f i) < ε := ⟨limUnder f, fun ε hε => by obtain ⟨N, hN⟩ := exi_rat_seq_conv f (half_pos hε) obtain ⟨N2, hN2⟩ := padicNormE.defn (lim' f) (half_pos hε) refine' ⟨max N N2, fun i hi => _⟩ rw [← sub_add_sub_cancel _ (lim' f i : ℚ_[p]) _] refine' (padic_norm_e.add_le _ _).trans_lt _ rw [← add_halves ε] apply add_lt_add · apply hN2 _ (le_of_max_le_right hi) · rw [padic_norm_e.map_sub] exact hN _ (le_of_max_le_left hi)⟩ #align padic.complete' Padic.complete' end Complete section NormedSpace variable (p : ℕ) [Fact p.Prime] instance : Dist ℚ_[p] := ⟨fun x y => padicNormE (x - y)⟩ instance : MetricSpace ℚ_[p] where dist_self := by simp [dist] dist := dist dist_comm x y := by simp [dist, ← padic_norm_e.map_neg (x - y)] dist_triangle x y z := by unfold dist exact_mod_cast padic_norm_e.sub_le _ _ _ eq_of_dist_eq_zero := by unfold dist; intro _ _ h apply eq_of_sub_eq_zero apply padic_norm_e.eq_zero.1 exact_mod_cast h instance : Norm ℚ_[p] := ⟨fun x => padicNormE x⟩ instance : NormedField ℚ_[p] := { Padic.field, Padic.metricSpace p with dist_eq := fun _ _ => rfl norm_mul' := by simp [Norm.norm, map_mul] norm := norm } instance isAbsoluteValue : IsAbsoluteValue fun a : ℚ_[p] => ‖a‖ where abv_nonneg := norm_nonneg abv_eq_zero _ := norm_eq_zero abv_add := norm_add_le abv_mul := by simp [Norm.norm, map_mul] #align padic.is_absolute_value Padic.isAbsoluteValue theorem rat_dense (q : ℚ_[p]) {ε : ℝ} (hε : 0 < ε) : ∃ r : ℚ, ‖q - r‖ < ε := let ⟨ε', hε'l, hε'r⟩ := exists_rat_btwn hε let ⟨r, hr⟩ := rat_dense' q (by simpa using hε'l) ⟨r, lt_trans (by simpa [Norm.norm] using hr) hε'r⟩ #align padic.rat_dense Padic.rat_dense end NormedSpace end Padic namespace padicNormE section NormedSpace variable {p : ℕ} [hp : Fact p.Prime] include hp @[simp] protected theorem mul (q r : ℚ_[p]) : ‖q * r‖ = ‖q‖ * ‖r‖ := by simp [Norm.norm, map_mul] #align padic_norm_e.mul padicNormE.mul protected theorem is_norm (q : ℚ_[p]) : ↑(padicNormE q) = ‖q‖ := rfl #align padic_norm_e.is_norm padicNormE.is_norm theorem nonarchimedean (q r : ℚ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := by unfold Norm.norm exact_mod_cast nonarchimedean' _ _ #align padic_norm_e.nonarchimedean padicNormE.nonarchimedean theorem add_eq_max_of_ne {q r : ℚ_[p]} (h : ‖q‖ ≠ ‖r‖) : ‖q + r‖ = max ‖q‖ ‖r‖ := by unfold Norm.norm apply_mod_cast add_eq_max_of_ne' intro h' apply h unfold Norm.norm exact_mod_cast h' #align padic_norm_e.add_eq_max_of_ne padicNormE.add_eq_max_of_ne @[simp] theorem eq_padicNorm (q : ℚ) : ‖(q : ℚ_[p])‖ = padicNorm p q := by unfold Norm.norm rw [← padicNormE.eq_padic_norm'] #align padic_norm_e.eq_padic_norm padicNormE.eq_padicNorm @[simp] theorem norm_p : ‖(p : ℚ_[p])‖ = p⁻¹ := by have p₀ : p ≠ 0 := hp.1.NeZero have p₁ : p ≠ 1 := hp.1.ne_one rw [← @Rat.cast_coe_nat ℝ _ p] rw [← @Rat.cast_coe_nat ℚ_[p] _ p] simp [p₀, p₁, norm, padicNorm, padicValRat, padicValInt, zpow_neg, -Rat.cast_coe_nat] #align padic_norm_e.norm_p padicNormE.norm_p theorem norm_p_lt_one : ‖(p : ℚ_[p])‖ < 1 := by rw [norm_p] apply inv_lt_one exact_mod_cast hp.1.one_lt #align padic_norm_e.norm_p_lt_one padicNormE.norm_p_lt_one @[simp] theorem norm_p_zpow (n : ℤ) : ‖(p ^ n : ℚ_[p])‖ = p ^ (-n) := by rw [norm_zpow, norm_p, zpow_neg, inv_zpow] #align padic_norm_e.norm_p_zpow padicNormE.norm_p_zpow @[simp] theorem norm_p_pow (n : ℕ) : ‖(p ^ n : ℚ_[p])‖ = p ^ (-n : ℤ) := by rw [← norm_p_zpow, zpow_ofNat] #align padic_norm_e.norm_p_pow padicNormE.norm_p_pow instance : NontriviallyNormedField ℚ_[p] := { Padic.normedField p with non_trivial := ⟨p⁻¹, by rw [norm_inv, norm_p, inv_inv] exact_mod_cast hp.1.one_lt⟩ } protected theorem image {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, ‖q‖ = ↑((p : ℚ) ^ (-n)) := Quotient.inductionOn q fun f hf => have : ¬f ≈ 0 := (PadicSeq.ne_zero_iff_nequiv_zero f).1 hf let ⟨n, hn⟩ := PadicSeq.norm_values_discrete f this ⟨n, congr_arg coe hn⟩ #align padic_norm_e.image padicNormE.image protected theorem is_rat (q : ℚ_[p]) : ∃ q' : ℚ, ‖q‖ = q' := if h : q = 0 then ⟨0, by simp [h]⟩ else let ⟨n, hn⟩ := padicNormE.image h ⟨_, hn⟩ #align padic_norm_e.is_rat padicNormE.is_rat /-- `rat_norm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number. The lemma `padic_norm_e.eq_rat_norm` asserts `‖q‖ = rat_norm q`. -/ def ratNorm (q : ℚ_[p]) : ℚ := Classical.choose (padicNormE.is_rat q) #align padic_norm_e.rat_norm padicNormE.ratNorm theorem eq_ratNorm (q : ℚ_[p]) : ‖q‖ = ratNorm q := Classical.choose_spec (padicNormE.is_rat q) #align padic_norm_e.eq_rat_norm padicNormE.eq_ratNorm theorem norm_rat_le_one : ∀ {q : ℚ} (hq : ¬p ∣ q.den), ‖(q : ℚ_[p])‖ ≤ 1 | ⟨n, d, hn, hd⟩ => fun hq : ¬p ∣ d => if hnz : n = 0 then by have : (⟨n, d, hn, hd⟩ : ℚ) = 0 := Rat.zero_iff_num_zero.mpr hnz norm_num [this] else by have hnz' : { num := n den := d Pos := hn cop := hd } ≠ 0 := mt Rat.zero_iff_num_zero.1 hnz rw [padicNormE.eq_padicNorm] norm_cast rw [padicNorm.eq_zpow_of_nonzero hnz', padicValRat, neg_sub, padicValNat.eq_zero_of_not_dvd hq] norm_cast rw [zero_sub, zpow_neg, zpow_ofNat] apply inv_le_one · norm_cast apply one_le_pow exact hp.1.Pos #align padic_norm_e.norm_rat_le_one padicNormE.norm_rat_le_one theorem norm_int_le_one (z : ℤ) : ‖(z : ℚ_[p])‖ ≤ 1 := suffices ‖((z : ℚ) : ℚ_[p])‖ ≤ 1 by simpa norm_rat_le_one <| by simp [hp.1.ne_one] #align padic_norm_e.norm_int_le_one padicNormE.norm_int_le_one theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k := by constructor · intro h contrapose! h apply le_of_eq rw [eq_comm] calc ‖(k : ℚ_[p])‖ = ‖((k : ℚ) : ℚ_[p])‖ := by norm_cast _ = padicNorm p k := (padicNormE.eq_padicNorm _) _ = 1 := _ rw [padicNorm] split_ifs with H · exfalso apply h norm_cast at H rw [H] apply dvd_zero · norm_cast at H⊢ convert zpow_zero _ rw [neg_eq_zero, padicValRat.of_int] norm_cast apply padicValInt.eq_zero_of_not_dvd h · rintro ⟨x, rfl⟩ push_cast rw [padicNormE.mul] calc _ ≤ ‖(p : ℚ_[p])‖ * 1 := mul_le_mul le_rfl (by simpa using norm_int_le_one _) (norm_nonneg _) (norm_nonneg _) _ < 1 := _ · rw [mul_one, padicNormE.norm_p] apply inv_lt_one exact_mod_cast hp.1.one_lt #align padic_norm_e.norm_int_lt_one_iff_dvd padicNormE.norm_int_lt_one_iff_dvd theorem norm_int_le_pow_iff_dvd (k : ℤ) (n : ℕ) : ‖(k : ℚ_[p])‖ ≤ ↑p ^ (-n : ℤ) ↔ ↑(p ^ n) ∣ k := by have : (p : ℝ) ^ (-n : ℤ) = ↑(p ^ (-n : ℤ) : ℚ) := by simp rw [show (k : ℚ_[p]) = ((k : ℚ) : ℚ_[p]) by norm_cast, eq_padic_norm, this] norm_cast rw [← padicNorm.dvd_iff_norm_le] #align padic_norm_e.norm_int_le_pow_iff_dvd padicNormE.norm_int_le_pow_iff_dvd theorem eq_of_norm_add_lt_right {z1 z2 : ℚ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ := by_contradiction fun hne => not_lt_of_ge (by rw [padicNormE.add_eq_max_of_ne hne] <;> apply le_max_right) h #align padic_norm_e.eq_of_norm_add_lt_right padicNormE.eq_of_norm_add_lt_right theorem eq_of_norm_add_lt_left {z1 z2 : ℚ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ := by_contradiction fun hne => not_lt_of_ge (by rw [padicNormE.add_eq_max_of_ne hne] <;> apply le_max_left) h #align padic_norm_e.eq_of_norm_add_lt_left padicNormE.eq_of_norm_add_lt_left end NormedSpace end padicNormE namespace Padic variable {p : ℕ} [hp : Fact p.Prime] include hp /- ./././Mathport/Syntax/Translate/Basic.lean:334:40: warning: unsupported option eqn_compiler.zeta -/ set_option eqn_compiler.zeta true instance complete : CauSeq.IsComplete ℚ_[p] norm := by constructor intro f have cau_seq_norm_e : IsCauSeq padicNormE f := by intro ε hε let h := is_cau f ε (by exact_mod_cast hε) unfold norm at h apply_mod_cast h cases' Padic.complete' ⟨f, cau_seq_norm_e⟩ with q hq exists q intro ε hε cases' exists_rat_btwn hε with ε' hε' norm_cast at hε' cases' hq ε' hε'.1 with N hN exists N intro i hi let h := hN i hi unfold norm rw_mod_cast [padic_norm_e.map_sub] refine' lt_trans _ hε'.2 exact_mod_cast hN i hi #align padic.complete Padic.complete theorem padic_norm_e_lim_le {f : CauSeq ℚ_[p] norm} {a : ℝ} (ha : 0 < a) (hf : ∀ i, ‖f i‖ ≤ a) : ‖f.lim‖ ≤ a := let ⟨N, hN⟩ := Setoid.symm (CauSeq.equiv_lim f) _ ha calc ‖f.lim‖ = ‖f.lim - f N + f N‖ := by simp _ ≤ max ‖f.lim - f N‖ ‖f N‖ := (padicNormE.nonarchimedean _ _) _ ≤ a := max_le (le_of_lt (hN _ le_rfl)) (hf _) #align padic.padic_norm_e_lim_le Padic.padic_norm_e_lim_le open Filter Set instance : CompleteSpace ℚ_[p] := by apply complete_of_cauchy_seq_tendsto intro u hu let c : CauSeq ℚ_[p] norm := ⟨u, metric.cauchy_seq_iff'.mp hu⟩ refine' ⟨c.lim, fun s h => _⟩ rcases Metric.mem_nhds_iff.1 h with ⟨ε, ε0, hε⟩ have := c.equiv_lim ε ε0 simp only [mem_map, mem_at_top_sets, mem_set_of_eq] exact this.imp fun N hN n hn => hε (hN n hn) /-! ### Valuation on `ℚ_[p]` -/ /-- `padic.valuation` lifts the `p`-adic valuation on rationals to `ℚ_[p]`. -/ def valuation : ℚ_[p] → ℤ := Quotient.lift (@PadicSeq.valuation p _) fun f g h => by by_cases hf : f ≈ 0 · have hg : g ≈ 0 := Setoid.trans (Setoid.symm h) hf simp [hf, hg, PadicSeq.valuation] · have hg : ¬g ≈ 0 := fun hg => hf (Setoid.trans h hg) rw [PadicSeq.val_eq_iff_norm_eq hf hg] exact PadicSeq.norm_equiv h #align padic.valuation Padic.valuation @[simp] theorem valuation_zero : valuation (0 : ℚ_[p]) = 0 := dif_pos ((const_equiv p).2 rfl) #align padic.valuation_zero Padic.valuation_zero @[simp] theorem valuation_one : valuation (1 : ℚ_[p]) = 0 := by change dite (CauSeq.const (padicNorm p) 1 ≈ _) _ _ = _ have h : ¬CauSeq.const (padicNorm p) 1 ≈ 0 := by intro H erw [const_equiv p] at H exact one_ne_zero H rw [dif_neg h] simp #align padic.valuation_one Padic.valuation_one theorem norm_eq_pow_val {x : ℚ_[p]} : x ≠ 0 → ‖x‖ = p ^ (-x.Valuation) := by apply Quotient.inductionOn' x; clear x intro f hf change (PadicSeq.norm _ : ℝ) = (p : ℝ) ^ (-PadicSeq.valuation _) rw [PadicSeq.norm_eq_pow_val] change ↑((p : ℚ) ^ (-PadicSeq.valuation f)) = (p : ℝ) ^ (-PadicSeq.valuation f) · rw [Rat.cast_zpow, Rat.cast_coe_nat] · apply CauSeq.not_limZero_of_not_congr_zero contrapose! hf apply Quotient.sound simpa using hf #align padic.norm_eq_pow_val Padic.norm_eq_pow_val @[simp] theorem valuation_p : valuation (p : ℚ_[p]) = 1 := by have h : (1 : ℝ) < p := by exact_mod_cast (Fact.out p.prime).one_lt refine' neg_injective ((zpow_strictMono h).Injective <| (norm_eq_pow_val _).symm.trans _) · exact_mod_cast (Fact.out p.prime).NeZero · simp #align padic.valuation_p Padic.valuation_p theorem valuation_map_add {x y : ℚ_[p]} (hxy : x + y ≠ 0) : min (valuation x) (valuation y) ≤ valuation (x + y) := by by_cases hx : x = 0 · rw [hx, zero_add] exact min_le_right _ _ · by_cases hy : y = 0 · rw [hy, add_zero] exact min_le_left _ _ · have h_norm : ‖x + y‖ ≤ max ‖x‖ ‖y‖ := padicNormE.nonarchimedean x y have hp_one : (1 : ℝ) < p := by rw [← Nat.cast_one, Nat.cast_lt] exact Nat.Prime.one_lt hp.elim rwa [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val hxy, zpow_le_max_iff_min_le hp_one] at h_norm #align padic.valuation_map_add Padic.valuation_map_add @[simp] theorem valuation_map_mul {x y : ℚ_[p]} (hx : x ≠ 0) (hy : y ≠ 0) : valuation (x * y) = valuation x + valuation y := by have h_norm : ‖x * y‖ = ‖x‖ * ‖y‖ := norm_mul x y have hp_ne_one : (p : ℝ) ≠ 1 := by rw [← Nat.cast_one, Ne.def, Nat.cast_inj] exact Nat.Prime.ne_one hp.elim have hp_pos : (0 : ℝ) < p := by rw [← Nat.cast_zero, Nat.cast_lt] exact Nat.Prime.pos hp.elim rw [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val (mul_ne_zero hx hy), ← zpow_add₀ (ne_of_gt hp_pos), zpow_inj hp_pos hp_ne_one, ← neg_add, neg_inj] at h_norm exact h_norm #align padic.valuation_map_mul Padic.valuation_map_mul /-- The additive `p`-adic valuation on `ℚ_[p]`, with values in `with_top ℤ`. -/ def addValuationDef : ℚ_[p] → WithTop ℤ := fun x => if x = 0 then ⊤ else x.Valuation #align padic.add_valuation_def Padic.addValuationDef @[simp] theorem AddValuation.map_zero : addValuationDef (0 : ℚ_[p]) = ⊤ := by simp only [add_valuation_def, if_pos (Eq.refl _)] #align padic.add_valuation.map_zero Padic.AddValuation.map_zero @[simp] theorem AddValuation.map_one : addValuationDef (1 : ℚ_[p]) = 0 := by simp only [add_valuation_def, if_neg one_ne_zero, valuation_one, WithTop.coe_zero] #align padic.add_valuation.map_one Padic.AddValuation.map_one theorem AddValuation.map_mul (x y : ℚ_[p]) : addValuationDef (x * y) = addValuationDef x + addValuationDef y := by simp only [add_valuation_def] by_cases hx : x = 0 · rw [hx, if_pos (Eq.refl _), MulZeroClass.zero_mul, if_pos (Eq.refl _), WithTop.top_add] · by_cases hy : y = 0 · rw [hy, if_pos (Eq.refl _), MulZeroClass.mul_zero, if_pos (Eq.refl _), WithTop.add_top] · rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← WithTop.coe_add, WithTop.coe_eq_coe, valuation_map_mul hx hy] #align padic.add_valuation.map_mul Padic.AddValuation.map_mul theorem AddValuation.map_add (x y : ℚ_[p]) : min (addValuationDef x) (addValuationDef y) ≤ addValuationDef (x + y) := by simp only [add_valuation_def] by_cases hxy : x + y = 0 · rw [hxy, if_pos (Eq.refl _)] exact le_top · by_cases hx : x = 0 · simp only [hx, if_pos (Eq.refl _), min_eq_right, le_top, zero_add, le_refl] · by_cases hy : y = 0 · simp only [hy, if_pos (Eq.refl _), min_eq_left, le_top, add_zero, le_refl] · rw [if_neg hx, if_neg hy, if_neg hxy, ← WithTop.coe_min, WithTop.coe_le_coe] exact valuation_map_add hxy #align padic.add_valuation.map_add Padic.AddValuation.map_add /-- The additive `p`-adic valuation on `ℚ_[p]`, as an `add_valuation`. -/ def addValuation : AddValuation ℚ_[p] (WithTop ℤ) := AddValuation.of addValuationDef AddValuation.map_zero AddValuation.map_one AddValuation.map_add AddValuation.map_mul #align padic.add_valuation Padic.addValuation @[simp] theorem addValuation.apply {x : ℚ_[p]} (hx : x ≠ 0) : x.AddValuation = x.Valuation := by simp only [AddValuation, AddValuation.of_apply, add_valuation_def, if_neg hx] #align padic.add_valuation.apply Padic.addValuation.apply section NormLeIff /-! ### Various characterizations of open unit balls -/ theorem norm_le_pow_iff_norm_lt_pow_add_one (x : ℚ_[p]) (n : ℤ) : ‖x‖ ≤ p ^ n ↔ ‖x‖ < p ^ (n + 1) := by have aux : ∀ n : ℤ, 0 < (p ^ n : ℝ) := by apply Nat.zpow_pos_of_pos exact hp.1.Pos by_cases hx0 : x = 0 · simp [hx0, norm_zero, aux, le_of_lt (aux _)] rw [norm_eq_pow_val hx0] have h1p : 1 < (p : ℝ) := by exact_mod_cast hp.1.one_lt have H := zpow_strictMono h1p rw [H.le_iff_le, H.lt_iff_lt, Int.lt_add_one_iff] #align padic.norm_le_pow_iff_norm_lt_pow_add_one Padic.norm_le_pow_iff_norm_lt_pow_add_one theorem norm_lt_pow_iff_norm_le_pow_sub_one (x : ℚ_[p]) (n : ℤ) : ‖x‖ < p ^ n ↔ ‖x‖ ≤ p ^ (n - 1) := by rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel] #align padic.norm_lt_pow_iff_norm_le_pow_sub_one Padic.norm_lt_pow_iff_norm_le_pow_sub_one theorem norm_le_one_iff_val_nonneg (x : ℚ_[p]) : ‖x‖ ≤ 1 ↔ 0 ≤ x.Valuation := by by_cases hx : x = 0 · simp only [hx, norm_zero, valuation_zero, zero_le_one, le_refl] · rw [norm_eq_pow_val hx, ← zpow_zero (p : ℝ), zpow_le_iff_le, Right.neg_nonpos_iff] exact Nat.one_lt_cast.2 (Nat.Prime.one_lt' p).1 #align padic.norm_le_one_iff_val_nonneg Padic.norm_le_one_iff_val_nonneg end NormLeIff end Padic
module OrientationAnalysis where import Control.Monad as M import Data.Array.Repa as R import Data.Binary (decodeFile) import Data.Complex import Data.List as L import DFT.Plan import Filter.Pinwheel import FokkerPlanck.MonteCarlo import FokkerPlanck.Pinwheel import Image.IO import STC.CompletionField (makeImagePlan, makeR2Z1T0Plan) import STC.CompletionField import STC.OrientationScaleAnalysis import System.Directory import System.Environment import System.FilePath main = do args@(numPointStr:numOrientationStr:sigmaStr:taoStr:lenStr:initStr:numTrailStr:maxTrailStr:theta0FreqsStr:thetaFreqsStr:histFilePath:alphaStr:pinwheelFlagStr:imagePath:idxStr:numOrientationSampleStr:numThreadStr:_) <- getArgs print args let numPoint = read numPointStr :: Int numOrientation = read numOrientationStr :: Int sigma = read sigmaStr :: Double tao = read taoStr :: Double len = read lenStr :: Int init = read initStr :: (Double, Double, Double, Double, Double, Double) numTrail = read numTrailStr :: Int maxTrail = read maxTrailStr :: Int theta0Freq = read theta0FreqsStr :: Double theta0Freqs = [-theta0Freq .. theta0Freq] thetaFreq = read thetaFreqsStr :: Double thetaFreqs = [-thetaFreq .. thetaFreq] alpha = read alphaStr :: Double pinwheelFlag = read pinwheelFlagStr :: Bool idx = read idxStr :: (Int, Int) numOrientationSample = read numOrientationSampleStr :: Int numThread = read numThreadStr :: Int pinwheelParams = PinwheelParams numPoint numPoint alpha (exp 1) theta0Freqs [0] folderPath = "output/test/OrientationAnalysis" createDirectoryIfMissing True folderPath flag <- doesFileExist histFilePath arrR2Z1T0 <- if pinwheelFlag then error "Using pinwheels to construct the Green's function has not been implemented yet." --computeR2Z1T0Array numPoint numPoint alpha thetaFreqs theta0Freqs else if flag then do getNormalizedHistogramArr <$> decodeFile histFilePath else solveMonteCarloR2Z1T0 numThread numTrail maxTrail numPoint numPoint sigma tao len theta0Freqs thetaFreqs "" (emptyHistogram [ numPoint , numPoint , L.length theta0Freqs , L.length thetaFreqs ] 0) (ImageRepa _ img) <- readImageRepa imagePath False plotImageRepa (folderPath </> "input.png") (ImageRepa 8 img) plan0 <- makeR2Z1T0Plan emptyPlan arrR2Z1T0 (plan1, imgF) <- makeImagePlan plan0 img (plan, filterF, filterPIF) <- pinwheelFilter plan1 pinwheelParams arrR2Z1T0F <- dftR2Z1T0 plan . makeFilterR2Z1T0 $ arrR2Z1T0 convolvedImg <- fmap (\x -> R.slice x (Z :. All :. (0 :: Int) :. All :. All)) $ convolvePinwheel plan filterF (R.slice imgF (Z :. (0 :: Int) :. All :. All)) plotMagnitudeOrientationSource plan folderPath numOrientationSample numOrientation thetaFreqs arrR2Z1T0F convolvedImg idx plotMagnitudeOrientation folderPath numOrientationSample numOrientation thetaFreqs convolvedImg idx
(* File: Buffons_Needle.thy Author: Manuel Eberl <[email protected]> A formal solution of Buffon's needle problem. *) section \<open>Buffon's Needle Problem\<close> theory Buffons_Needle imports "HOL-Probability.Probability" begin subsection \<open>Auxiliary material\<close> lemma sin_le_zero': "sin x \<le> 0" if "x \<ge> -pi" "x \<le> 0" for x by (metis minus_le_iff neg_0_le_iff_le sin_ge_zero sin_minus that(1) that(2)) subsection \<open>Problem definition\<close> text \<open> Consider a needle of length $l$ whose centre has the $x$-coordinate $x$. The following then defines the set of all $x$-coordinates that the needle covers (i.e. the projection of the needle onto the $x$-axis.) \<close> definition needle :: "real \<Rightarrow> real \<Rightarrow> real \<Rightarrow> real set" where "needle l x \<phi> = closed_segment (x - l / 2 * sin \<phi>) (x + l / 2 * sin \<phi>)" text_raw \<open> \begin{figure} \begin{center} \begin{tikzpicture} \coordinate (lefttick) at (-3,0); \coordinate (righttick) at (3,0); \draw (lefttick) -- (righttick); \draw [thick] (lefttick) ++ (0,0.4) -- ++(0,3); \draw [thick] (righttick) ++ (0,0.4) -- ++(0,3); \coordinate (needle) at (1,2); \newcommand{\needleangle}{55} \newcommand{\needlelength}{{1}} \newcommand{\needlethickness}{0.6pt} \draw ($(lefttick)+(0,4pt)$) -- ($(lefttick)-(0,4pt)$); \draw ($(righttick)+(0,4pt)$) -- ($(righttick)-(0,4pt)$); \draw (0,4pt) -- (0,-4pt); \draw [densely dashed, thin] let \p1 = (needle) in (\x1, 0) -- (needle); \draw [densely dashed, thin] let \p1 = (needle) in (needle) -- (3, \y1); \draw (needle) ++ (15pt,0) arc(0:\needleangle:15pt); \path (needle) -- ++(15pt,0) node [above, midway, yshift=-1.9pt, xshift=1.8pt] {$\scriptstyle\varphi$}; \node [below, xshift=-3.5pt] at ($(lefttick)-(0,4pt)$) {$-\nicefrac{d}{2}$}; \node [below] at ($(righttick)-(0,4pt)$) {$\nicefrac{d}{2}$}; \node [below,yshift=-1pt] at (0,-4pt) {$0$}; \node [below,yshift=-2pt] at (needle |- 0,-4pt) {$x$}; \draw[<->] (needle) ++({\needleangle+90}:5pt) ++(\needleangle:{-\needlelength}) -- ++(\needleangle:2) node [midway, above, rotate=\needleangle] {$\scriptstyle l$}; \draw [line width=0.7pt,fill=white] (needle) ++({\needleangle+90}:\needlethickness) -- ++(\needleangle:\needlelength) arc({\needleangle+90}:{\needleangle-90}:\needlethickness) -- ++(\needleangle:-\needlelength) -- ++(\needleangle:-\needlelength) arc({\needleangle+270}:{\needleangle+90}:\needlethickness) -- ++(\needleangle:\needlelength); \end{tikzpicture} \end{center} \caption{A sketch of the situation in Buffon's needle experiment. There is a needle of length $l$ with its centre at a certain $x$ coordinate, angled at an angle $\varphi$ off the horizontal axis. The two vertical lines are a distance of $d$ apart, each being $\nicefrac{d}{2}$ away from the origin.} \label{fig:buffon} \end{figure} \definecolor{myred}{HTML}{cc2428} \begin{figure}[h] \begin{center} \begin{tikzpicture} \begin{axis}[ xmin=0, xmax=7, ymin=0, ymax=1, width=\textwidth, height=0.6\textwidth, xlabel={$l/d$}, ylabel={$\mathcal P$}, tick style={thin,black}, ylabel style = {rotate=270,anchor=west}, ] \addplot [color=myred, line width=1pt, mark=none,domain=0:1,samples=200] ({x}, {2/pi*x}); \addplot [color=myred, line width=1pt, mark=none,domain=1:7,samples=200] ({x}, {2/pi*(x-sqrt(x*x-1)+acos(1/x)/180*pi)}); \end{axis} \end{tikzpicture} \caption{The probability $\mathcal P$ of the needle hitting one of the lines, as a function of the quotient $l/d$ (where $l$ is the length of the needle and $d$ the horizontal distance between the lines).} \label{fig:buffonplot} \end{center} \end{figure} \<close> text \<open> Buffon's Needle problem is then this: Assuming the needle's $x$ position is chosen uniformly at random in a strip of width $d$ centred at the origin, what is the probability that the needle crosses at least one of the left/right boundaries of that strip (located at $x = \pm\frac{1}{2}d$)? We will show that, if we let $x := \nicefrac{l}{d}$, the probability of this is \[ \mathcal P_{l,d} = \begin{cases} \nicefrac{2}{\pi} \cdot x & \text{if}\ l \leq d\\ \nicefrac{2}{\pi}\cdot(x - \sqrt{x^2 - 1} + \arccos (\nicefrac{1}{x})) & \text{if}\ l \geq d \end{cases} \] A plot of this function can be found in Figure~\ref{fig:buffonplot}. \<close> locale Buffon = fixes d l :: real assumes d: "d > 0" and l: "l > 0" begin definition Buffon :: "(real \<times> real) measure" where "Buffon = uniform_measure lborel ({-d/2..d/2} \<times> {-pi..pi})" lemma space_Buffon [simp]: "space Buffon = UNIV" by (simp add: Buffon_def) definition Buffon_set :: "(real \<times> real) set" where "Buffon_set = {(x,\<phi>) \<in> {-d/2..d/2} \<times> {-pi..pi}. needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}}" subsection \<open>Derivation of the solution\<close> text \<open> The following form is a bit easier to handle. \<close> lemma Buffon_set_altdef1: "Buffon_set = {(x,\<phi>) \<in> {-d/2..d/2} \<times> {-pi..pi}. let a = x - l / 2 * sin \<phi>; b = x + l / 2 * sin \<phi> in min a b + d/2 \<le> 0 \<and> max a b + d/2 \<ge> 0 \<or> min a b - d/2 \<le> 0 \<and> max a b - d/2 \<ge> 0}" proof - have "(\<lambda>(x,\<phi>). needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}) = (\<lambda>(x,\<phi>). let a = x - l / 2 * sin \<phi>; b = x + l / 2 * sin \<phi> in -d/2 \<ge> min a b \<and> -d/2 \<le> max a b \<or> min a b \<le> d/2 \<and> max a b \<ge> d/2)" by (auto simp: needle_def Let_def closed_segment_eq_real_ivl min_def max_def) also have "\<dots> = (\<lambda>(x,\<phi>). let a = x - l / 2 * sin \<phi>; b = x + l / 2 * sin \<phi> in min a b + d/2 \<le> 0 \<and> max a b + d/2 \<ge> 0 \<or> min a b - d/2 \<le> 0 \<and> max a b - d/2 \<ge> 0)" by (auto simp add: algebra_simps Let_def) finally show ?thesis unfolding Buffon_set_def case_prod_unfold by (intro Collect_cong conj_cong refl) meson qed lemma Buffon_set_altdef2: "Buffon_set = {(x,\<phi>) \<in> {-d/2..d/2} \<times> {-pi..pi}. abs x \<ge> d / 2 - abs (sin \<phi>) * l / 2}" unfolding Buffon_set_altdef1 proof (intro Collect_cong prod.case_cong refl conj_cong) fix x \<phi> assume *: "(x, \<phi>) \<in> {-d/2..d/2} \<times> {-pi..pi}" let ?P = "\<lambda>x \<phi>. let a = x - l / 2 * sin \<phi>; b = x + l / 2 * sin \<phi> in min a b + d/2 \<le> 0 \<and> max a b + d/2 \<ge> 0 \<or> min a b - d/2 \<le> 0 \<and> max a b - d/2 \<ge> 0" show "?P x \<phi> \<longleftrightarrow> (d / 2 - \<bar>sin \<phi>\<bar> * l / 2 \<le> \<bar>x\<bar>)" proof (cases "\<phi> \<ge> 0") case True have "x - l / 2 * sin \<phi> \<le> x + l / 2 * sin \<phi>" using l True * by (auto simp: sin_ge_zero) moreover from True and * have "sin \<phi> \<ge> 0" by (auto simp: sin_ge_zero) ultimately show ?thesis using * True by (force simp: field_simps Let_def min_def max_def case_prod_unfold abs_if) next case False with * have "x - l / 2 * sin \<phi> \<ge> x + l / 2 * sin \<phi>" using l by (auto simp: sin_le_zero' mult_nonneg_nonpos) moreover from False and * have "sin \<phi> \<le> 0" by (auto simp: sin_le_zero') ultimately show ?thesis using * False l d by (force simp: field_simps Let_def min_def max_def case_prod_unfold abs_if) qed qed text \<open> By using the symmetry inherent in the problem, we can reduce the problem to the following set, which corresponds to one quadrant of the original set: \<close> definition Buffon_set' :: "(real \<times> real) set" where "Buffon_set' = {(x,\<phi>) \<in> {0..d/2} \<times> {0..pi}. x \<ge> d / 2 - sin \<phi> * l / 2}" lemma closed_buffon_set [simp, intro, measurable]: "closed Buffon_set" proof - have "Buffon_set = ({-d/2..d/2} \<times> {-pi..pi}) \<inter> (\<lambda>z. abs (fst z) + abs (sin (snd z)) * l / 2 - d / 2) -` {0..}" (is "_ = ?A") unfolding Buffon_set_altdef2 by auto also have "closed \<dots>" by (intro closed_Int closed_vimage closed_Times) (auto intro!: continuous_intros) finally show ?thesis by simp qed lemma closed_buffon_set' [simp, intro, measurable]: "closed Buffon_set'" proof - have "Buffon_set' = ({0..d/2} \<times> {0..pi}) \<inter> (\<lambda>z. fst z + sin (snd z) * l / 2 - d / 2) -` {0..}" (is "_ = ?A") unfolding Buffon_set'_def by auto also have "closed \<dots>" by (intro closed_Int closed_vimage closed_Times) (auto intro!: continuous_intros) finally show ?thesis by simp qed lemma measurable_buffon_set [measurable]: "Buffon_set \<in> sets borel" by measurable lemma measurable_buffon_set' [measurable]: "Buffon_set' \<in> sets borel" by measurable sublocale prob_space Buffon unfolding Buffon_def proof - have "emeasure lborel ({- d / 2..d / 2} \<times> {- pi..pi}) = ennreal (2 * d * pi)" unfolding lborel_prod [symmetric] using d by (subst lborel.emeasure_pair_measure_Times) (auto simp: ennreal_mult mult_ac simp flip: ennreal_numeral) also have "\<dots> \<noteq> 0 \<and> \<dots> \<noteq> \<infinity>" using d by auto finally show "prob_space (uniform_measure lborel ({- d / 2..d / 2} \<times> {- pi..pi}))" by (intro prob_space_uniform_measure) auto qed lemma buffon_prob_aux: "emeasure Buffon {(x,\<phi>). needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}} = emeasure lborel Buffon_set / ennreal (2 * d * pi)" proof - have [measurable]: "A \<times> B \<in> sets borel" if "A \<in> sets borel" "B \<in> sets borel" for A B :: "real set" using that unfolding borel_prod [symmetric] by simp have "{(x, \<phi>). needle l x \<phi> \<inter> {- d / 2, d / 2} \<noteq> {}} \<in> sets borel" by (intro pred_Collect_borel) (simp add: borel_prod [symmetric] needle_def closed_segment_eq_real_ivl case_prod_unfold) hence "emeasure Buffon {(x,\<phi>). needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}} = emeasure lborel (({-d/2..d/2} \<times> {- pi..pi}) \<inter> {(x,\<phi>). needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}}) / emeasure lborel ({-(d/2)..d/2} \<times> {-pi..pi})" unfolding Buffon_def Buffon_set_def by (subst emeasure_uniform_measure) simp_all also have "({-d/2..d/2} \<times> {- pi..pi}) \<inter> {(x, \<phi>). needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}} = Buffon_set" unfolding Buffon_set_def by auto also have "emeasure lborel ({-(d/2)..d/2} \<times> {-pi..pi}) = ennreal (2 * d * pi)" using d by (simp flip: lborel_prod ennreal_mult add: lborel.emeasure_pair_measure_Times) finally show ?thesis . qed lemma emeasure_buffon_set_conv_buffon_set': "emeasure lborel Buffon_set = 4 * emeasure lborel Buffon_set'" proof - have distr_lborel [simp]: "distr M lborel f = distr M borel f" for M and f :: "real \<Rightarrow> real" by (rule distr_cong) simp_all define A where "A = Buffon_set'" define B C D where "B = (\<lambda>x. (-fst x, snd x)) -` A" and "C = (\<lambda>x. (fst x, -snd x)) -` A" and "D = (\<lambda>x. (-fst x, -snd x)) -` A" have meas [measurable]: "(\<lambda>x::real \<times> real. (-fst x, snd x)) \<in> borel_measurable borel" "(\<lambda>x::real \<times> real. (fst x, -snd x)) \<in> borel_measurable borel" "(\<lambda>x::real \<times> real. (-fst x, -snd x)) \<in> borel_measurable borel" unfolding borel_prod [symmetric] by measurable have meas' [measurable]: "A \<in> sets borel" "B \<in> sets borel" "C \<in> sets borel" "D \<in> sets borel" unfolding A_def B_def C_def D_def by (rule measurable_buffon_set' measurable_sets_borel meas)+ have *: "Buffon_set = A \<union> B \<union> C \<union> D" proof (intro equalityI subsetI, goal_cases) case (1 z) show ?case proof (cases "fst z \<ge> 0"; cases "snd z \<ge> 0") assume "fst z \<ge> 0" "snd z \<ge> 0" with 1 have "z \<in> A" by (auto split: prod.splits simp: Buffon_set_altdef2 Buffon_set'_def sin_ge_zero A_def B_def) thus ?thesis by blast next assume "\<not>(fst z \<ge> 0)" "snd z \<ge> 0" with 1 have "z \<in> B" by (auto split: prod.splits simp: Buffon_set_altdef2 Buffon_set'_def sin_ge_zero A_def B_def) thus ?thesis by blast next assume "fst z \<ge> 0" "\<not>(snd z \<ge> 0)" with 1 have "z \<in> C" by (auto split: prod.splits simp: Buffon_set_altdef2 Buffon_set'_def sin_le_zero' A_def B_def C_def) thus ?thesis by blast next assume "\<not>(fst z \<ge> 0)" "\<not>(snd z \<ge> 0)" with 1 have "z \<in> D" by (auto split: prod.splits simp: Buffon_set_altdef2 Buffon_set'_def sin_le_zero' A_def B_def D_def) thus ?thesis by blast qed next case (2 z) thus ?case using d l by (auto simp: Buffon_set_altdef2 Buffon_set'_def sin_ge_zero sin_le_zero' A_def B_def C_def D_def) qed have "A \<inter> B = {0} \<times> ({0..pi} \<inter> {\<phi>. sin \<phi> * l - d \<ge> 0})" using d l by (auto simp: Buffon_set'_def A_def B_def C_def D_def) moreover have "emeasure lborel \<dots> = 0" unfolding lborel_prod [symmetric] by (subst lborel.emeasure_pair_measure_Times) simp_all ultimately have AB: "(A \<inter> B) \<in> null_sets lborel" unfolding lborel_prod [symmetric] by (simp add: null_sets_def) have "C \<inter> D = {0} \<times> ({-pi..0} \<inter> {\<phi>. -sin \<phi> * l - d \<ge> 0})" using d l by (auto simp: Buffon_set'_def A_def B_def C_def D_def) moreover have "emeasure lborel \<dots> = 0" unfolding lborel_prod [symmetric] by (subst lborel.emeasure_pair_measure_Times) simp_all ultimately have CD: "(C \<inter> D) \<in> null_sets lborel" unfolding lborel_prod [symmetric] by (simp add: null_sets_def) have "A \<inter> D = {}" "B \<inter> C = {}" using d l by (auto simp: Buffon_set'_def A_def D_def B_def C_def) moreover have "A \<inter> C = {(d/2, 0)}" "B \<inter> D = {(-d/2, 0)}" using d l by (auto simp: case_prod_unfold Buffon_set'_def A_def B_def C_def D_def) ultimately have AD: "A \<inter> D \<in> null_sets lborel" and BC: "B \<inter> C \<in> null_sets lborel" and AC: "A \<inter> C \<in> null_sets lborel" and BD: "B \<inter> D \<in> null_sets lborel" by auto note * also have "emeasure lborel (A \<union> B \<union> C \<union> D) = emeasure lborel (A \<union> B \<union> C) + emeasure lborel D" using AB AC AD BC BD CD by (intro emeasure_Un') (auto simp: Int_Un_distrib2) also have "emeasure lborel (A \<union> B \<union> C) = emeasure lborel (A \<union> B) + emeasure lborel C" using AB AC BC using AB AC AD BC BD CD by (intro emeasure_Un') (auto simp: Int_Un_distrib2) also have "emeasure lborel (A \<union> B) = emeasure lborel A + emeasure lborel B" using AB using AB AC AD BC BD CD by (intro emeasure_Un') (auto simp: Int_Un_distrib2) also have "emeasure lborel B = emeasure (distr lborel lborel (\<lambda>(x,y). (-x, y))) A" (is "_ = emeasure ?M _") unfolding B_def by (subst emeasure_distr) (simp_all add: case_prod_unfold) also have "?M = lborel" unfolding lborel_prod [symmetric] by (subst pair_measure_distr [symmetric]) (simp_all add: sigma_finite_lborel lborel_distr_uminus) also have "emeasure lborel C = emeasure (distr lborel lborel (\<lambda>(x,y). (x, -y))) A" (is "_ = emeasure ?M _") unfolding C_def by (subst emeasure_distr) (simp_all add: case_prod_unfold) also have "?M = lborel" unfolding lborel_prod [symmetric] by (subst pair_measure_distr [symmetric]) (simp_all add: sigma_finite_lborel lborel_distr_uminus) also have "emeasure lborel D = emeasure (distr lborel lborel (\<lambda>(x,y). (-x, -y))) A" (is "_ = emeasure ?M _") unfolding D_def by (subst emeasure_distr) (simp_all add: case_prod_unfold) also have "?M = lborel" unfolding lborel_prod [symmetric] by (subst pair_measure_distr [symmetric]) (simp_all add: sigma_finite_lborel lborel_distr_uminus) finally have "emeasure lborel Buffon_set = of_nat (Suc (Suc (Suc (Suc 0)))) * emeasure lborel A" unfolding of_nat_Suc ring_distribs by simp also have "of_nat (Suc (Suc (Suc (Suc 0)))) = (4 :: ennreal)" by simp finally show ?thesis unfolding A_def . qed text \<open> It only remains now to compute the measure of @{const Buffon_set'}. We first reduce this problem to a relatively simple integral: \<close> lemma emeasure_buffon_set': "emeasure lborel Buffon_set' = ennreal (integral {0..pi} (\<lambda>x. min (d / 2) (sin x * l / 2)))" (is "emeasure lborel ?A = _") proof - have "emeasure lborel ?A = nn_integral lborel (\<lambda>x. indicator ?A x)" by (intro nn_integral_indicator [symmetric]) simp_all also have "(lborel :: (real \<times> real) measure) = lborel \<Otimes>\<^sub>M lborel" by (simp only: lborel_prod) also have "nn_integral \<dots> (indicator ?A) = (\<integral>\<^sup>+\<phi>. \<integral>\<^sup>+x. indicator ?A (x, \<phi>) \<partial>lborel \<partial>lborel)" by (subst lborel_pair.nn_integral_snd [symmetric]) (simp_all add: lborel_prod borel_prod) also have "\<dots> = (\<integral>\<^sup>+\<phi>. \<integral>\<^sup>+x. indicator {0..pi} \<phi> * indicator {max 0 (d/2 - sin \<phi> * l / 2) .. d/2} x \<partial>lborel \<partial>lborel)" using d l by (intro nn_integral_cong) (auto simp: indicator_def field_simps Buffon_set'_def) also have "\<dots> = \<integral>\<^sup>+ \<phi>. indicator {0..pi} \<phi> * emeasure lborel {max 0 (d / 2 - sin \<phi> * l / 2)..d / 2} \<partial>lborel" by (subst nn_integral_cmult) simp_all also have "\<dots> = \<integral>\<^sup>+ \<phi>. ennreal (indicator {0..pi} \<phi> * min (d / 2) (sin \<phi> * l / 2)) \<partial>lborel" (is "_ = ?I") using d l by (intro nn_integral_cong) (auto simp: indicator_def sin_ge_zero max_def min_def) also have "integrable lborel (\<lambda>\<phi>. (d / 2) * indicator {0..pi} \<phi>)" by simp hence int: "integrable lborel (\<lambda>\<phi>. indicator {0..pi} \<phi> * min (d / 2) (sin \<phi> * l / 2))" by (rule Bochner_Integration.integrable_bound) (insert l d, auto intro!: AE_I2 simp: indicator_def min_def sin_ge_zero) hence "?I = set_lebesgue_integral lborel {0..pi} (\<lambda>\<phi>. min (d / 2) (sin \<phi> * l / 2))" by (subst nn_integral_eq_integral, assumption) (insert d l, auto intro!: AE_I2 simp: sin_ge_zero min_def indicator_def set_lebesgue_integral_def) also have "\<dots> = ennreal (integral {0..pi} (\<lambda>x. min (d / 2) (sin x * l / 2)))" (is "_ = ennreal ?I") using int by (subst set_borel_integral_eq_integral) (simp_all add: set_integrable_def) finally show ?thesis by (simp add: lborel_prod) qed text \<open> We now have to distinguish two cases: The first and easier one is that where the length of the needle, $l$, is less than or equal to the strip width, $d$: \<close> context assumes l_le_d: "l \<le> d" begin lemma emeasure_buffon_set'_short: "emeasure lborel Buffon_set' = ennreal l" proof - have "emeasure lborel Buffon_set' = ennreal (integral {0..pi} (\<lambda>x. min (d / 2) (sin x * l / 2)))" (is "_ = ennreal ?I") by (rule emeasure_buffon_set') also have *: "sin \<phi> * l \<le> d" if "\<phi> \<ge> 0" "\<phi> \<le> pi" for \<phi> using mult_mono[OF l_le_d sin_le_one _ sin_ge_zero] that d by (simp add: algebra_simps) have "?I = integral {0..pi} (\<lambda>x. (l / 2) * sin x)" using l d l_le_d by (intro integral_cong) (auto dest: * simp: min_def sin_ge_zero) also have "\<dots> = l / 2 * integral {0..pi} sin" by simp also have "(sin has_integral (-cos pi - (- cos 0))) {0..pi}" by (intro fundamental_theorem_of_calculus) (auto intro!: derivative_eq_intros simp: has_field_derivative_iff_has_vector_derivative [symmetric]) hence "integral {0..pi} sin = -cos pi - (-cos 0)" by (simp add: has_integral_iff) finally show ?thesis by (simp add: lborel_prod) qed lemma emeasure_buffon_set_short: "emeasure lborel Buffon_set = 4 * ennreal l" by (simp add: emeasure_buffon_set_conv_buffon_set' emeasure_buffon_set'_short l_le_d) lemma prob_short_aux: "Buffon {(x, \<phi>). needle l x \<phi> \<inter> {- d / 2, d / 2} \<noteq> {}} = ennreal (2 * l / (d * pi))" unfolding buffon_prob_aux emeasure_buffon_set_short using d l by (simp flip: ennreal_mult ennreal_numeral add: divide_ennreal) lemma prob_short: "\<P>((x,\<phi>) in Buffon. needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}) = 2 * l / (d * pi)" using prob_short_aux unfolding emeasure_eq_measure using l d by (subst (asm) ennreal_inj) auto end text \<open> The other case where the needle is at least as long as the strip width is more complicated: \<close> context assumes l_ge_d: "l \<ge> d" begin lemma emeasure_buffon_set'_long: shows "l * (1 - sqrt (1 - (d / l)\<^sup>2)) + arccos (d / l) * d \<ge> 0" and "emeasure lborel Buffon_set' = ennreal (l * (1 - sqrt (1 - (d / l)\<^sup>2)) + arccos (d / l) * d)" proof - define \<phi>' where "\<phi>' = arcsin (d / l)" have \<phi>'_nonneg: "\<phi>' \<ge> 0" unfolding \<phi>'_def using d l l_ge_d arcsin_le_mono[of 0 "d/l"] by (simp add: \<phi>'_def) have \<phi>'_le: "\<phi>' \<le> pi / 2" unfolding \<phi>'_def using arcsin_bounded[of "d/l"] d l l_ge_d by (simp add: field_simps) have ge_phi': "sin \<phi> \<ge> d / l" if "\<phi> \<ge> \<phi>'" "\<phi> \<le> pi / 2" for \<phi> using arcsin_le_iff[of "d / l" "\<phi>"] d l_ge_d that \<phi>'_nonneg by (auto simp: \<phi>'_def field_simps) have le_phi': "sin \<phi> \<le> d / l" if "\<phi> \<le> \<phi>'" "\<phi> \<ge> 0" for \<phi> using le_arcsin_iff[of "d / l" "\<phi>"] d l_ge_d that \<phi>'_le by (auto simp: \<phi>'_def field_simps) have "cos \<phi>' = sqrt (1 - (d / l)^2)" unfolding \<phi>'_def by (rule cos_arcsin) (insert d l l_ge_d, auto simp: field_simps) have "l * (1 - cos \<phi>') + arccos (d / l) * d \<ge> 0" using l d l_ge_d by (intro add_nonneg_nonneg mult_nonneg_nonneg arccos_lbound) (auto simp: field_simps) thus "l * (1 - sqrt (1 - (d / l)\<^sup>2)) + arccos (d / l) * d \<ge> 0" by (simp add: \<open>cos \<phi>' = sqrt (1 - (d / l)^2)\<close>) let ?f = "(\<lambda>x. min (d / 2) (sin x * l / 2))" have "emeasure lborel Buffon_set' = ennreal (integral {0..pi} ?f)" (is "_ = ennreal ?I") by (rule emeasure_buffon_set') also have "?I = integral {0..pi/2} ?f + integral {pi/2..pi} ?f" by (rule Henstock_Kurzweil_Integration.integral_combine [symmetric]) (auto intro!: integrable_continuous_real continuous_intros) also have "integral {pi/2..pi} ?f = integral {-pi/2..0} (?f \<circ> (\<lambda>\<phi>. \<phi> + pi))" by (subst integral_shift) (auto intro!: continuous_intros) also have "\<dots> = integral {-(pi/2)..-0} (\<lambda>x. min (d / 2) (sin (-x) * l / 2))" by (simp add: o_def) also have "\<dots> = integral {0..pi/2} ?f" (is "_ = ?I") by (subst Henstock_Kurzweil_Integration.integral_reflect_real) simp_all also have "\<dots> + \<dots> = 2 * \<dots>" by simp also have "?I = integral {0..\<phi>'} ?f + integral {\<phi>'..pi/2} ?f" using l d l_ge_d \<phi>'_nonneg \<phi>'_le by (intro Henstock_Kurzweil_Integration.integral_combine [symmetric]) (auto intro!: integrable_continuous_real continuous_intros) also have "integral {0..\<phi>'} ?f = integral {0..\<phi>'} (\<lambda>x. l / 2 * sin x)" using l by (intro integral_cong) (auto simp: min_def field_simps dest: le_phi') also have "((\<lambda>x. l / 2 * sin x) has_integral (- (l / 2 * cos \<phi>') - (- (l / 2 * cos 0)))) {0..\<phi>'}" using \<phi>'_nonneg by (intro fundamental_theorem_of_calculus) (auto simp: has_field_derivative_iff_has_vector_derivative [symmetric] intro!: derivative_eq_intros) hence "integral {0..\<phi>'} (\<lambda>x. l / 2 * sin x) = (1 - cos \<phi>') * l / 2" by (simp add: has_integral_iff algebra_simps) also have "integral {\<phi>'..pi/2} ?f = integral {\<phi>'..pi/2} (\<lambda>_. d / 2)" using l by (intro integral_cong) (auto simp: min_def field_simps dest: ge_phi') also have "\<dots> = arccos (d / l) * d / 2" using \<phi>'_le d l l_ge_d by (subst arccos_arcsin_eq) (auto simp: field_simps \<phi>'_def) also note \<open>cos \<phi>' = sqrt (1 - (d / l)^2)\<close> also have "2 * ((1 - sqrt (1 - (d / l)\<^sup>2)) * l / 2 + arccos (d / l) * d / 2) = l * (1 - sqrt (1 - (d / l)\<^sup>2)) + arccos (d / l) * d" using d l by (simp add: field_simps) finally show "emeasure lborel Buffon_set' = ennreal (l * (1 - sqrt (1 - (d / l)\<^sup>2)) + arccos (d / l) * d)" . qed lemma emeasure_set_long: "emeasure lborel Buffon_set = 4 * ennreal (l * (1 - sqrt (1 - (d / l)\<^sup>2)) + arccos (d / l) * d)" by (simp add: emeasure_buffon_set_conv_buffon_set' emeasure_buffon_set'_long l_ge_d) lemma prob_long_aux: shows "2 / pi * ((l / d) - sqrt ((l / d)\<^sup>2 - 1) + arccos (d / l)) \<ge> 0" and "Buffon {(x, \<phi>). needle l x \<phi> \<inter> {- d / 2, d / 2} \<noteq> {}} = ennreal (2 / pi * ((l / d) - sqrt ((l / d)\<^sup>2 - 1) + arccos (d / l)))" using emeasure_buffon_set'_long(1) proof - have *: "l * sqrt ((l\<^sup>2 - d\<^sup>2) / l\<^sup>2) + 0 \<le> l + d * arccos (d / l)" using d l_ge_d by (intro add_mono mult_nonneg_nonneg arccos_lbound) (auto simp: field_simps) have "l / d \<ge> sqrt ((l / d)\<^sup>2 - 1)" using l d l_ge_d by (intro real_le_lsqrt) (auto simp: field_simps) thus "2 / pi * ((l / d) - sqrt ((l / d)\<^sup>2 - 1) + arccos (d / l)) \<ge> 0" using d l l_ge_d by (intro mult_nonneg_nonneg add_nonneg_nonneg arccos_lbound) (auto simp: field_simps) have "emeasure Buffon {(x,\<phi>). needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}} = ennreal (4 * (l - l * sqrt (1 - (d / l)\<^sup>2) + arccos (d / l) * d)) / ennreal (2 * d * pi)" using d l l_ge_d * unfolding buffon_prob_aux emeasure_set_long ennreal_numeral [symmetric] by (subst ennreal_mult [symmetric]) (auto intro!: add_nonneg_nonneg mult_nonneg_nonneg simp: field_simps) also have "\<dots> = ennreal ((4 * (l - l * sqrt (1 - (d / l)\<^sup>2) + arccos (d / l) * d)) / (2 * d * pi))" using d l * by (subst divide_ennreal) (auto simp: field_simps) also have "(4 * (l - l * sqrt (1 - (d / l)\<^sup>2) + arccos (d / l) * d)) / (2 * d * pi) = 2 / pi * (l / d - l / d * sqrt ((d / l)^2 * ((l / d)^2 - 1)) + arccos (d / l))" using d l by (simp add: field_simps) also have "l / d * sqrt ((d / l)^2 * ((l / d)^2 - 1)) = sqrt ((l / d) ^ 2 - 1)" using d l l_ge_d unfolding real_sqrt_mult real_sqrt_abs by simp finally show "emeasure Buffon {(x,\<phi>). needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}} = ennreal (2 / pi * ((l / d) - sqrt ((l / d)\<^sup>2 - 1) + arccos (d / l)))" . qed lemma prob_long: "\<P>((x,\<phi>) in Buffon. needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}) = 2 / pi * ((l / d) - sqrt ((l / d)\<^sup>2 - 1) + arccos (d / l))" using prob_long_aux unfolding emeasure_eq_measure by (subst (asm) ennreal_inj) simp_all end theorem prob_eq: defines "x \<equiv> l / d" shows "\<P>((x,\<phi>) in Buffon. needle l x \<phi> \<inter> {-d/2, d/2} \<noteq> {}) = (if l \<le> d then 2 / pi * x else 2 / pi * (x - sqrt (x\<^sup>2 - 1) + arccos (1 / x)))" using prob_short prob_long unfolding x_def by auto end end
REBOL [ title: {Text2Key} author: {[email protected]} date: 24-May-2020 file: %text2key.r ] ; === Default settings === key: {ctrl alt f12} ; === Generic backend context === backend: context [ data: copy [] output: copy [] current: 1 file: extension: none emit: func [data] [ repend output data ] export: does [ write/lines file output ] new: func [file'] [ make self [ replace file: to-rebol-file file' suffix? file extension ] ] ] ; === AutoHotKey backend context === autohotkey: make backend [ ; === Variables === extension: %.ahk remove-count: highlight-count: 0 remove-data: none ; === Initialization === emit {Esc::ExitApp} emit {S(text) { if %A_KeyDelay% = 0 { SendEvent {Text}%text% } else { Loop, parse, text { SendEvent {text}%A_LoopField% Random delay, 0, %KeyVariation% Sleep %delay% } } }} ; === Functions === copy: func [source target count] [ ; TODO ] pause: func [duration] [ emit rejoin [{Sleep } to-integer 1000 * to-decimal duration] ] highlight: func [delta] [ if highlight-count != 0 [ emit either highlight-count > 0 [{SendEvent {Left}}] [{SendEvent {Right}}] highlight-count: 0 ] if remove-count != 0 [ emit rejoin [{SendEvent {Shift Down}^{Down } remove-count {^}{Shift Up}{Delete}}] remove-count: 0 ] emit rejoin [{SendEvent {Shift Down}^{} pick [{Down } {Up }] delta > 0 abs delta {^}{Shift Up}}] highlight-count: delta ] insert: func [lines /local carry text] [ if highlight-count != 0 [ emit either highlight-count > 0 [{SendEvent {Left}}] [{SendEvent {Right}}] highlight-count: 0 ] either remove-count != 0 [ foreach line lines [ either remove-count > 0 [ emit {SetKeyDelay %A_KeyDelay%, 100} emit {SendEvent {Insert}} emit {SetKeyDelay %A_KeyDelay%, 0} emit rejoin [{S("} replace/all replace/all system/words/copy line {;} {`;} {"} {""} {")}] if (length? line) < (length? remove-data/1) [ emit {SendEvent {Shift Down}{End}{Shift Up}{Delete}} ] emit {SendEvent {Right}} emit {SetKeyDelay %A_KeyDelay%, 100} emit {SendEvent {Insert}} emit {SetKeyDelay %A_KeyDelay%, 0} remove-count: remove-count - 1 remove-data: next remove-data ] [ emit rejoin [{S("} replace/all replace/all system/words/copy line {;} {`;} {"} {""} {`n} {")}] ] ] if remove-count > 0 [ emit rejoin [{SendEvent {Shift Down}^{Down } remove-count {^}{Shift Up}{Delete}}] remove-count: 0 ] ] [ if carry: to-logic all [current < length? data not empty? lines not empty? data/:current] [ emit {SendEvent {Text}`n} emit {SendEvent {Up}} ] forall lines [ text: replace/all replace/all system/words/copy lines/1 {;} {`;} {"} {""} if any [not carry not last? lines] [ append text {`n} ] emit rejoin [{S("} text {")}] ] if carry [ emit {SendEvent {Right}} ] ] ] key: func [value] [ foreach [src dst] [ {ctrl} {^^} {alt} {!} {shift} {+} {win} {#} { } {} ] [ replace/all value src dst ] emit rejoin [uppercase value {::}] ] move: func [delta] [ if highlight-count != 0 [ emit either highlight-count > 0 [{SendEvent {Left}}] [{SendEvent {Right}}] highlight-count: 0 ] if remove-count != 0 [ emit rejoin [{SendEvent {Shift Down}^{Down } remove-count {^}{Shift Up}{Delete}}] remove-count: 0 ] emit rejoin [{SendEvent ^{} pick [{Up} {Down}] delta < 0 { } abs delta {^}}] ] rate: func [values] [ emit rejoin [{SetKeyDelay } either values/1 = 0 [0] [to-integer 1000 * 1.0 / values/1] {, 0}] either 1 < length? values [ emit reform [{global KeyVariation :=} to-integer (1000 * values/2)] ] [ emit {global KeyVariation := 0} ] ] remove: func [count] [ remove-count: count remove-data: system/words/copy/deep/part at data current count ] save: does [ emit {SendEvent {Control Down}{s}{Control Up}} pause 0.1 ] scroll: func [delta] [ delta: to-integer delta emit rejoin [{SendEvent {Control Down}^{} pick [{Down } {Up }] delta > 0 abs delta {^}{Control Up}}] ] send: func [value] [ emit {SetKeyDelay %A_KeyDelay%, 100} emit reform [either find value #"@" [{ControlSend, ahk_parent,}] [{Send}] replace value #"@" ", ahk_exe "] emit {SetKeyDelay %A_KeyDelay%, 0} ] window: func [value] [ emit {SetTitleMatchMode, 2} emit reform [{WinWait,} replace value #"@" " ahk_exe "] emit reform [{WinActivate,} replace value #"@" " ahk_exe "] ] ] ; === Log === echo %text2key.log ; === Fetch args === either attempt [exists? file: to-rebol-file system/options/args/1] [ begin: now/precise/time ; === Implement backend exporter === exporter: autohotkey/new file ; === Parse sections and steps === do funct [] [ label: [spaces opt #"-" integer! opt ["." integer!]] option-marker: #":" option-value: complement charset reduce [option-marker #"]"] option: [ (action: arg: none) spaces option-marker [ #"<" (action: 'copy) | #"#" (action: 'highlight) | #"|" (action: 'pause) | #"'" (action: 'rate) spaces copy arg 1 2 label (arg: to-block load arg) | #">" (action: 'replace) | #"^^" (action: 'scroll) | #"!" (action: 'save) | #"%" (action: 'send) spaces copy arg any option-value (arg: trim arg) | #"@" (action: 'window) spaces copy arg any option-value (arg: trim arg) | #"." (action: 'move) | #"~" (action: 'fast) spaces opt [copy arg label] | #"-" (actions: post-actions) ] opt [copy arg label (arg: load arg)] ] options: [(actions: pre-actions: copy [] post-actions: copy []) any [option (all [action repend actions [action arg]])]] space: charset [#" " #"^-"] spaces: [any space] comment-rule: [{//} | #";" | #"#"] section-rule: [ spaces comment-rule spaces #"[" (current: none) [ copy section label options #"]" (current: add-section section pre-actions post-actions) | [ #"]" (section: {}) | copy section to #"]" ] (print [{ - Skipping section} rejoin [{[} section {]}]]) ] thru lf ] key-rule: [ spaces comment-rule spaces #"[" {key} #":" copy value to #"]" thru lf (set 'key trim value) ] set 'sections make hash! [] current: 1 add-section: func [ label pre-actions' post-actions' ] [ last append sections reduce [trim to-string label context [pre-actions: pre-actions' post-actions: post-actions' line-count: 0 content: copy []]] ] print [{== Parsing [} to-local-file file {]}] parse/all read file [ any [ key-rule | section-rule | copy line thru lf (all [current append current/content trim/tail line current/line-count: current/line-count + 1]) ] ] set 'steps sort/compare extract sections 2 func [a b] [(load a) < (load b)] ] ; === Process all steps === either steps = unique steps [ print [{== Setting key [} key {]}] exporter/key key print [{== Processing} length? steps {steps}] do funct [] [ find-line: funct [section /with current /post] [ section: to-string section result: 1 foreach [label content] sections [ case [ label = section [ break ] all [ not find replaced label do get to-lit-word pick [{<=} {<}] to-logic post (load label) (load either with [to-string current] [section]) ] [ result: result + sections/:label/line-count ] ] ] result ] move-to: func [line] [ if exporter/current != line [ print [{ . Moving to line} line rejoin [{[} pick [{+} {}] line > exporter/current line - exporter/current {]}]] exporter/move line - exporter/current exporter/current: line ] ] replaced: copy [] fast: false rate: [] foreach step steps [ section: sections/:step print [{ - Step [} step {]}] ; === Pre-Actions === do process-actions: funct [actions] [ foreach [action arg] actions [ switch action [ copy [ target: either actions = section/post-actions [find-line/with/post arg step] [find-line/with arg step] print [{ . Copying from [} arg {]} sections/(to-string arg)/line-count {lines at line} target] ] fast [ set 'fast case [ arg [arg] fast [false] true [1] ] exporter/rate either fast [ print [{ . Setting fast mode to ON, pause override = [} fast {]}] [0] ] [ print { . Setting fast mode to OFF} rate ] ] highlight [ arg: any [arg step] target: either actions = section/post-actions [find-line/with/post arg step] [find-line/with arg step] print [{ . Highlighting to beginning of [} arg {], line} target] exporter/highlight target - exporter/current ] move [ move-to find-line step ] pause [ print [{ . Pausing} arg {seconds}] exporter/pause any [fast arg] ] rate [ print rejoin [{ . Set rate to } arg/1 either 2 = length? arg [rejoin [{ +/-} to-integer (1000 * arg/2) {ms}]] [{}] { cps}] set 'rate arg if not fast [ exporter/rate rate ] ] replace [ arg: to-string arg either not find replaced arg [ move-to target: either actions = section/post-actions [find-line/with/post arg step] [find-line/with arg step] print [{ . Replacing [} arg {], removing} sections/(arg)/line-count {lines at line} target] exporter/remove sections/(arg)/line-count remove/part at exporter/data target sections/(arg)/line-count append replaced arg ] [ print [{!! Aborting: trying to replace [} arg {] which was already replaced earlier}] break ] ] save [ print [{ . Saving document}] exporter/save ] scroll [ print [{ . Scrolling [} arg {] lines}] exporter/scroll arg ] send [ print [{ . Sending [} arg {]}] exporter/send arg ] window [ print [{ . Focusing window [} arg {]}] exporter/window arg ] ] ] ] section/pre-actions ; === Insertion === move-to find-line step print [{ . Inserting} section/line-count {lines}] exporter/insert section/content insert at exporter/data find-line step section/content exporter/current: exporter/current + section/line-count ; === Post-Actions === do process-actions section/post-actions ] ; === Saving print [{== Saving [} to-local-file exporter/file {]}] exporter/export end: now/precise/time print [{== [} (end - begin) {] Success!}] ] ] [ print [{!! Can't process, found duplicated steps [} unique collect [forall steps [if find next steps steps/1 [keep steps/1]]] {]}] ] ] [ print [{== Usage:} to-local-file second split-path system/options/script {[textfile]}] ]
State Before: α : Type u_2 β : Type ?u.1911 γ : Type ?u.1914 ι : Type u_1 inst✝¹ : TopologicalSpace α inst✝ : Encodable ι s : ι → Set α hs : ∀ (i : ι), IsGδ (s i) ⊢ IsGδ (⋂ (i : ι), s i) State After: α : Type u_2 β : Type ?u.1911 γ : Type ?u.1914 ι : Type u_1 inst✝¹ : TopologicalSpace α inst✝ : Encodable ι s : ι → Set α T : ι → Set (Set α) hTo : ∀ (i : ι) (t : Set α), t ∈ T i → IsOpen t hTc : ∀ (i : ι), Set.Countable (T i) hTs : ∀ (i : ι), s i = ⋂₀ T i ⊢ IsGδ (⋂ (i : ι), s i) Tactic: choose T hTo hTc hTs using hs State Before: α : Type u_2 β : Type ?u.1911 γ : Type ?u.1914 ι : Type u_1 inst✝¹ : TopologicalSpace α inst✝ : Encodable ι s : ι → Set α T : ι → Set (Set α) hTo : ∀ (i : ι) (t : Set α), t ∈ T i → IsOpen t hTc : ∀ (i : ι), Set.Countable (T i) hTs : ∀ (i : ι), s i = ⋂₀ T i ⊢ IsGδ (⋂ (i : ι), s i) State After: α : Type u_2 β : Type ?u.1911 γ : Type ?u.1914 ι : Type u_1 inst✝¹ : TopologicalSpace α inst✝ : Encodable ι T : ι → Set (Set α) hTo : ∀ (i : ι) (t : Set α), t ∈ T i → IsOpen t hTc : ∀ (i : ι), Set.Countable (T i) hTs : ∀ (i : ι), (fun i => ⋂₀ T i) i = ⋂₀ T i ⊢ IsGδ (⋂ (i : ι), (fun i => ⋂₀ T i) i) Tactic: obtain rfl : s = fun i => ⋂₀ T i := funext hTs State Before: α : Type u_2 β : Type ?u.1911 γ : Type ?u.1914 ι : Type u_1 inst✝¹ : TopologicalSpace α inst✝ : Encodable ι T : ι → Set (Set α) hTo : ∀ (i : ι) (t : Set α), t ∈ T i → IsOpen t hTc : ∀ (i : ι), Set.Countable (T i) hTs : ∀ (i : ι), (fun i => ⋂₀ T i) i = ⋂₀ T i ⊢ IsGδ (⋂ (i : ι), (fun i => ⋂₀ T i) i) State After: α : Type u_2 β : Type ?u.1911 γ : Type ?u.1914 ι : Type u_1 inst✝¹ : TopologicalSpace α inst✝ : Encodable ι T : ι → Set (Set α) hTo : ∀ (i : ι) (t : Set α), t ∈ T i → IsOpen t hTc : ∀ (i : ι), Set.Countable (T i) hTs : ∀ (i : ι), (fun i => ⋂₀ T i) i = ⋂₀ T i ⊢ ∀ (t : Set α), (t ∈ ⋃ (i : ι), T i) → IsOpen t Tactic: refine' ⟨⋃ i, T i, _, countable_iUnion hTc, (sInter_iUnion _).symm⟩ State Before: α : Type u_2 β : Type ?u.1911 γ : Type ?u.1914 ι : Type u_1 inst✝¹ : TopologicalSpace α inst✝ : Encodable ι T : ι → Set (Set α) hTo : ∀ (i : ι) (t : Set α), t ∈ T i → IsOpen t hTc : ∀ (i : ι), Set.Countable (T i) hTs : ∀ (i : ι), (fun i => ⋂₀ T i) i = ⋂₀ T i ⊢ ∀ (t : Set α), (t ∈ ⋃ (i : ι), T i) → IsOpen t State After: no goals Tactic: simpa [@forall_swap ι] using hTo
[STATEMENT] lemma Arccos_0 [simp]: "Arccos 0 = pi/2" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Arccos 0 = complex_of_real (pi / 2) [PROOF STEP] by (rule Arccos_unique) auto
function toms446_test02 ( ) %*****************************************************************************80 % %% TOMS446_TEST02 tests MULTPLY, which multiplies two Chebyshev series. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 21 September 2011 % % Author: % % John Burkardt % nf = 5; npl = 10; fprintf ( 1, '\n' ); fprintf ( 1, 'TOMS446_TEST02\n' ); fprintf ( 1, ' Test MLTPLY, which computes the\n' ); fprintf ( 1, ' product of two Chebyshev series.\n' ); fprintf ( 1, '\n' ); fprintf ( 1, ' Multiply series for SIN(X) and COS(X)\n' ); fprintf ( 1, ' and compare with series for 1/2*SIN(2X).\n' ); x = cheby ( nf, npl, @functn ); for i = 1 : npl x1(i) = x(i,1); x2(i) = x(i,2); x(i,3) = 0.5 * x(i,3); end x3 = mltply ( x1, x2, npl ); fprintf ( 1, '\n' ); fprintf ( 1, ' Sin(x) Cos(x) 1/2*Sin(2x) RESULT\n' ); fprintf ( 1, '\n' ); for i = 1 : npl fprintf ( 1, ' %10.4f %10.4f %10.4f %10.4f\n', x(i,1:3), x3(i) ); end return end
! { dg-do run } ! PR34325 Wrong error message for syntax error program aa implicit none real(kind=8)::r1=0 character(25) :: a a = 'I am not a )))))'')''.' if ((((((a /= "I am not a )))))')'.")))))) call abort if ((((((a /= 'I am not a )))))'')''.')))))) call abort a = "I am not a )))))"")""." if ((((((a /= "I am not a )))))"")"".")))))) call abort if (((3*r1)**2)>= 0) a = "good" if (a /= "good") call abort end
--------------------------------------------------------------------------- -- | Module : Numeric.Optimization.Basic.LP -- Copyright : (c) 2016 Marco Zocca -- License : GPL-3 -- -- Maintainer : zocca.marco gmail -- Stability : experimental -- Portability : portable -- -- This module implements a general interior-point method for LP, based on the logarithmic barrier penalization -- -- * [1] Primal-dual interior point algorithms for linear programming, G. Tzallas-Regas -- -------------------------------------------------------------------------- module Numeric.Optimization.Basic.LP where import Control.Monad.State import Data.Sparse -- (reexports Data.Sparse.Common from sparse-linear-algebra) import Numeric.LinearAlgebra.Sparse feasX :: (Foldable t, Ord a, Num a) => t a -> Bool feasX = all (> 0) linesearch amax x s dx ds = undefined where -- * Karmarkar algorithm karmIpLP :: SpMatrix Double -> SpVector Double -> KarmLPData karmIpLP aa c = execState (untilConverged (\x -> c `dot` _xKarm x) (karmarkarLPstep aa c ar)) kInit where ar = alpha * r kInit = KarmLPData x0 y0 0 (m, n) = dimSM aa n' = fromIntegral n r = 1 / sqrt (n' * (n'-1)) alpha = (n' - 1)/ (3*n') x0 = recip (fromIntegral n) .* onesSV n y0 = x0 data KarmLPData = KarmLPData { _xKarm, _yKarm:: SpVector Double, _niter :: Int } deriving (Eq, Show) -- | alphar = alpha * r karmarkarLPstep :: SpMatrix Double -> SpVector Double -> Double -> KarmLPData -> KarmLPData karmarkarLPstep aa c alphar (KarmLPData x y k) = KarmLPData xnew ynew (k + 1) where (m, n) = dim aa ddk = diagonalSM x pp = (aa #~# ddk) -=- svToSM (onesSV n) cdk = c <# ddk cp = cdk ^-^ (transposeSM pp #> ((pp ##^ pp) <\> (pp #> cdk))) cp0 = normalize 2 cp ynew = y ^-^ (alphar .* cp0) dy = ddk #> ynew xnew = recip (sum dy) .* dy -- z = c `dot` xnew -- untilConverged :: MonadState a m => (a -> SpVector Double) -> (a -> a) -> m a untilConverged fproj = modifyInspectN 200 (normDiffConverged fproj) normDiffConverged f [x1,x2] = nearZero $ f x1 - f x2 -- normDiffConverged fp xx = nearZero $ normSq (foldrMap fp (^-^) (zeroSV 0) xx) {- | Interior point, log-penalized LP (PLP): max_x <c, x> - rho B(x) s.t. A x = b where B(x) := sum_j( log(x_j) ) (i.e. non-negativity constraint) 1. Write Lagrangian for PLP L(x, rho, y) 2. Write KKT conditions (first order optimality of L(x, rho, y)) 3. Write Newton equations for KKT system -} -- | Update primal `x`, dual `y` and slack `s` variables by applying Newton's method to the KKT system of the log-penalized LP. -- This requires one linear solve and a line search for a stepsize `alpha` that preserves feasibility : (x, s) > 0. -- NB : It assumes the dimensions of vectors are x :: Rn , y :: Rm , s :: Rn -- pdIpLPstep :: -- (SpVector Double -> -- SpVector Double -> -- SpVector Double -> -- SpVector Double -> -- Double) -> -- SpMatrix Double -> -- Double -> -- (SpVector Double, SpVector Double, SpVector Double, Int) -> -- (SpVector Double, SpVector Double, SpVector Double, Int) -- pdIpLPstep chooseAlpha aa tau (x, y, s, k) = (xNew, yNew, sNew, k+1) where -- gamma = (x `dot` s) / fromIntegral n -- duality measure -- rho = tau * gamma -- Lagrange multiplier of barrier penalty -- ss = diagonalSM s -- xx = diagonalSM x -- arow1 = zn -||- transposeSM aa -||- eye n -- arow2 = aa -||- zm -||- zm -- arow3 = ss -||- zm -||- xx -- amat = arow1 -=- (arow2 -=- arow3) -- rhs = concatSV zvn $ concatSV zvm $ negated (xx #> s) ^+^ (rho .* onesSV m) -- xysStep = amat <\> rhs -- xStep = takeSV n xysStep -- 0 .. n-1 -- yStep = takeSV m (dropSV n xysStep) -- n .. n+m-1 -- sStep = dropSV (m + n) xysStep -- n+m .. 2n+m -- xNew = x ^+^ (alpha .* xStep) -- yNew = y ^+^ (alpha .* yStep) -- sNew = s ^+^ (alpha .* sStep) -- alpha = chooseAlpha x s xStep sStep -- (m, n) = dim aa -- zm = zeroSM m m -- zn = zeroSM n n -- zvn = zeroSV n -- zvm = zeroSV m
module JuliaPackageExample greet() = print("Hello World!") include("extra_file.jl") export my_f, my_g end # module
import data.nat.basic import data.nat.prime import tactic.norm_num open nat -- https://www.dpmms.cam.ac.uk/study/II/NumberTheory/2019-2020/number_theory-19-1.pdf -- A proof of question 5 from here lemma division_lemma { a n : ℕ } ( ha : a ≥ 1 ) : a - 1 ∣ a ^ n - 1 := begin apply dvd_of_mod_eq_zero, induction n with n, simp, suffices: (a^n * (a - 1 + 1) - 1) % (a - 1) = 0, by rwa nat.sub_add_cancel ha at this, rw [mul_add, mul_one, nat.add_sub_assoc (pow_pos ha _)], simpa end lemma division_lemma' { a p q : ℕ } ( ha : a ≥ 1 ) : a ^ p - 1 ∣ a ^ (p * q) - 1 := begin cases p, simp, rw nat.pow_mul, apply division_lemma (pow_pos ‹a ≥ 1› _), end lemma eq_add_of_sub_eq'' { a m n : ℕ } ( ha : a ≥ m ) : a - m = n → a = n + m := (nat.sub_eq_iff_eq_add ha).1 lemma pow_monotonic { a m n : ℕ } ( ha : a ≥ 2 ) ( k : a^m ≥ a^n ) : m ≥ n := le_of_not_gt (λ r, not_le_of_lt (pow_lt_pow_of_lt_right ha r) k) lemma pow_inj { a m n : ℕ } ( ha : a ≥ 2 ) ( k : a^m = a^n ) : m = n := by apply le_antisymm; apply pow_monotonic ha; apply le_of_eq; rw k lemma question5i { a n : ℕ } { ha : a > 1 } { hn : n > 1 } : prime (a^n - 1) → a = 2 ∧ prime n := begin have: a ≥ 1, from le_of_succ_le ‹a ≥ 2›, have: n ≥ 1, from le_of_succ_le ‹n ≥ 2›, have: a^n > 0, from pow_pos ‹a > 0› n, intro b, split, cases b.right _ (division_lemma ‹a ≥ 1›), apply eq_add_of_sub_eq'' ‹a ≥ 1› ‹a - 1 = 1›, have: a^n = a^1, rw nat.pow_one, from nat.sub_cancel ‹a^n ≥ 1› ‹a ≥ 1› ‹a - 1 = a^n - 1›.symm, exfalso, have: a^n > a^1 := pow_lt_pow_of_lt_right ‹a > 1› ‹n > 1›, apply ne_of_gt ‹a^n > a^1› ‹a^n = a^1›, refine ⟨‹n ≥ 2›, _⟩, intros m _, have: a^m ≥ 1, from pow_pos ‹a ≥ 1› m, have: a^m - 1 ∣ a^_ - 1 := division_lemma' ‹a ≥ 1›, rw nat.mul_div_cancel_left' ‹m ∣ n› at this, apply or.imp _ _ (b.right (a^m - 1) this); intro, have: a^m ≤ a, by calc a^m ≤ 2 : le_of_eq $ eq_add_of_sub_eq'' ‹a^m ≥ 1› ‹a^m - 1 = 1› ... ≤ a : ‹a ≥ 2›, have: m ≤ 1, apply pow_monotonic ‹a ≥ 2›, rwa nat.pow_one, have: m > 0 := pos_of_dvd_of_pos ‹m ∣ n› ‹n > 0›, apply le_antisymm ‹m ≤ 1› ‹m > 0›, have: a^m = a^n, from nat.sub_cancel ‹a^m ≥ 1› ‹a^n ≥ 1› ‹a^m - 1 = a^n - 1›, exact pow_inj ‹a ≥ 2› this, end lemma question5ii: ¬ (∀ { a n : ℕ }, a = 2 ∧ prime n → prime (a^n - 1)) := begin intro h, have: prime 11 := by norm_num, have: prime 2047 := h ⟨rfl, ‹prime 11›⟩, norm_num at this end
module Issue756b where data Nat : Set where zero : Nat suc : Nat → Nat data T : (Nat → Nat) → Set where idId : T (λ { zero → zero; (suc n) → suc n }) bad : ∀ f → T f → Nat bad .(λ { zero → zero ; (suc n) → suc n }) idId = zero