Datasets:
AI4M
/

text
stringlengths
0
3.34M
import polyhedral_lattice.basic import normed_group.pseudo_normed_group import pseudo_normed_group.profinitely_filtered noncomputable theory open_locale nnreal big_operators namespace polyhedral_lattice open pseudo_normed_group normed_group variables (Λ : Type*) [polyhedral_lattice Λ] lemma filtration_finite (ε : ℝ≥0) : (filtration Λ ε).finite := begin classical, obtain ⟨ι, _ι_inst, l, hl, hl'⟩ := polyhedral_lattice.polyhedral Λ, resetI, let n : ι → ℕ := λ i, ⌈(ε / ∥l i∥₊ : ℝ)⌉.nat_abs + 1, let S := finset.univ.pi (λ i, finset.range (n i)), let S' : finset Λ := S.image (λ x, ∑ i, x i (finset.mem_univ _) • l i), apply S'.finite_to_set.subset, intros l₀ H, obtain ⟨c, h1, h2⟩ := hl.generates_nnnorm l₀, simp only [S', set.mem_image, finset.mem_univ, finset.mem_pi, forall_true_left, finset.mem_range, finset.mem_coe, finset.coe_image], refine ⟨λ i _, c i, _, h1.symm⟩, intro i, apply nat.succ_le_succ, contrapose! H, simp only [not_le, semi_normed_group.mem_filtration_iff, h2], have aux : 0 < ∥l i∥₊, { rw [zero_lt_iff, ne.def, nnnorm_eq_zero], exact hl' i }, calc ε ≤ (⌈(ε / ∥l i∥₊ : ℝ)⌉.nat_abs : ℝ≥0) * ∥l i∥₊ : _ ... < ↑(c i) * ∥l i∥₊ : _ ... ≤ ∑ (i : ι), ↑(c i) * ∥l i∥₊ : _, { rw [← nnreal.div_le_iff aux.ne', ← nnreal.coe_le_coe], simp only [coe_nnnorm, nnreal.coe_nat_abs, nnreal.coe_div], refine (int.le_ceil _).trans (le_abs_self _), }, { rw mul_lt_mul_right aux, { exact_mod_cast H }, }, { refine @finset.single_le_sum _ _ _ _ _ _ i (finset.mem_univ _), exact λ _ _, zero_le', } end open metric semi_normed_group instance : discrete_topology Λ := discrete_topology_of_open_singleton_zero $ begin classical, have aux := filtration_finite Λ 1, let s := aux.to_finset, let s₀ := s.erase 0, by_cases hs₀ : s₀.nonempty, { let ε : ℝ≥0 := finset.min' (s₀.image $ nnnorm) (hs₀.image _), obtain ⟨a, has₀, ha⟩ : ∃ a ∈ s₀, ∥a∥₊ = ε, { rw ← finset.mem_image, apply finset.min'_mem }, have H : 0 < ∥a∥ := by simpa only [norm_pos_iff] using finset.ne_of_mem_erase has₀, have h0ε : 0 < ε, { simpa only [← ha] }, have hε1 : ε ≤ 1, { replace has₀ := finset.mem_of_mem_erase has₀, simp only [set.finite.mem_to_finset, mem_filtration_iff] at has₀, rwa [← ha] }, suffices : ({0} : set Λ) = ball (0:Λ) ε, { rw this, apply is_open_ball }, ext, simp only [metric.mem_ball, set.mem_singleton_iff, dist_zero_right], split, { rintro rfl, rw norm_zero, exact_mod_cast h0ε }, intro h, have hx : x ∈ s, { simp only [set.finite.mem_to_finset, mem_filtration_iff], exact le_of_lt (lt_of_lt_of_le h hε1) }, by_contra hx0, replace hx := finset.mem_erase_of_ne_of_mem hx0 hx, have := finset.min'_le (s₀.image $ nnnorm), refine not_lt.2 (this ∥x∥₊ _) h, simp only [exists_prop, set.finite.mem_to_finset, finset.mem_image], use ⟨x, ⟨hx, rfl⟩⟩ }, { suffices : ({0} : set Λ) = ball (0:Λ) 1, { rw this, apply is_open_ball }, ext, simp only [metric.mem_ball, set.mem_singleton_iff, dist_zero_right], split, { rintro rfl, rw norm_zero, exact zero_lt_one }, intro h, contrapose! hs₀, refine ⟨x, _⟩, simp only [set.finite.mem_to_finset, finset.mem_erase, mem_filtration_iff, nnreal.coe_one], exact ⟨hs₀, h.le⟩ } end instance filtration_fintype (c : ℝ≥0) : fintype (filtration Λ c) := (filtration_finite Λ c).fintype -- we don't need this instance : profinitely_filtered_pseudo_normed_group Λ := { compact := λ c, by apply_instance, -- compact of finite continuous_add' := λ _ _, continuous_of_discrete_topology, continuous_neg' := λ _, continuous_of_discrete_topology, continuous_cast_le := λ _ _ _, continuous_of_discrete_topology, .. (show pseudo_normed_group Λ, by apply_instance) } end polyhedral_lattice
[STATEMENT] lemma gauss_int_norm_eq_prime_squareD: assumes "prime p" and "[p = 3] (mod 4)" and "gauss_int_norm z = p ^ 2" shows "normalize z = of_nat p" and "prime_elem z" [PROOF STATE] proof (prove) goal (1 subgoal): 1. normalize z = of_nat p &&& prime_elem z [PROOF STEP] proof - [PROOF STATE] proof (state) goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] have "\<exists>q::gauss_int. q dvd z \<and> prime q" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<exists>q. q dvd z \<and> prime q [PROOF STEP] by (rule prime_divisor_exists) (use assms in \<open>auto simp: is_unit_gauss_int_iff'\<close>) [PROOF STATE] proof (state) this: \<exists>q. q dvd z \<and> prime q goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] then [PROOF STATE] proof (chain) picking this: \<exists>q. q dvd z \<and> prime q [PROOF STEP] obtain q :: gauss_int where q: "q dvd z" "prime q" [PROOF STATE] proof (prove) using this: \<exists>q. q dvd z \<and> prime q goal (1 subgoal): 1. (\<And>q. \<lbrakk>q dvd z; prime q\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by blast [PROOF STATE] proof (state) this: q dvd z prime q goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] have "gauss_int_norm q dvd gauss_int_norm z" [PROOF STATE] proof (prove) goal (1 subgoal): 1. gauss_int_norm q dvd gauss_int_norm z [PROOF STEP] by (rule gauss_int_norm_dvd_mono) fact [PROOF STATE] proof (state) this: gauss_int_norm q dvd gauss_int_norm z goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] also [PROOF STATE] proof (state) this: gauss_int_norm q dvd gauss_int_norm z goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] have "\<dots> = p ^ 2" [PROOF STATE] proof (prove) goal (1 subgoal): 1. gauss_int_norm z = p\<^sup>2 [PROOF STEP] by fact [PROOF STATE] proof (state) this: gauss_int_norm z = p\<^sup>2 goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: gauss_int_norm q dvd p\<^sup>2 [PROOF STEP] obtain i where i: "i \<le> 2" "gauss_int_norm q = p ^ i" [PROOF STATE] proof (prove) using this: gauss_int_norm q dvd p\<^sup>2 goal (1 subgoal): 1. (\<And>i. \<lbrakk>i \<le> 2; gauss_int_norm q = p ^ i\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by (subst (asm) divides_primepow_nat) (use assms q in auto) [PROOF STATE] proof (state) this: i \<le> 2 gauss_int_norm q = p ^ i goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] from i assms q [PROOF STATE] proof (chain) picking this: i \<le> 2 gauss_int_norm q = p ^ i prime p [p = 3] (mod 4) gauss_int_norm z = p\<^sup>2 q dvd z prime q [PROOF STEP] have "i \<noteq> 0" [PROOF STATE] proof (prove) using this: i \<le> 2 gauss_int_norm q = p ^ i prime p [p = 3] (mod 4) gauss_int_norm z = p\<^sup>2 q dvd z prime q goal (1 subgoal): 1. i \<noteq> 0 [PROOF STEP] by (auto intro!: Nat.gr0I simp: gauss_int_norm_eq_Suc_0_iff) [PROOF STATE] proof (state) this: i \<noteq> 0 goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] moreover [PROOF STATE] proof (state) this: i \<noteq> 0 goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] from i assms q [PROOF STATE] proof (chain) picking this: i \<le> 2 gauss_int_norm q = p ^ i prime p [p = 3] (mod 4) gauss_int_norm z = p\<^sup>2 q dvd z prime q [PROOF STEP] have "i \<noteq> 1" [PROOF STATE] proof (prove) using this: i \<le> 2 gauss_int_norm q = p ^ i prime p [p = 3] (mod 4) gauss_int_norm z = p\<^sup>2 q dvd z prime q goal (1 subgoal): 1. i \<noteq> 1 [PROOF STEP] using gauss_int_norm_not_3_mod_4[of q] [PROOF STATE] proof (prove) using this: i \<le> 2 gauss_int_norm q = p ^ i prime p [p = 3] (mod 4) gauss_int_norm z = p\<^sup>2 q dvd z prime q [gauss_int_norm q \<noteq> 3] (mod 4) goal (1 subgoal): 1. i \<noteq> 1 [PROOF STEP] by auto [PROOF STATE] proof (state) this: i \<noteq> 1 goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: i \<noteq> 0 i \<noteq> 1 [PROOF STEP] have "i = 2" [PROOF STATE] proof (prove) using this: i \<noteq> 0 i \<noteq> 1 goal (1 subgoal): 1. i = 2 [PROOF STEP] using i [PROOF STATE] proof (prove) using this: i \<noteq> 0 i \<noteq> 1 i \<le> 2 gauss_int_norm q = p ^ i goal (1 subgoal): 1. i = 2 [PROOF STEP] by auto [PROOF STATE] proof (state) this: i = 2 goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] with i [PROOF STATE] proof (chain) picking this: i \<le> 2 gauss_int_norm q = p ^ i i = 2 [PROOF STEP] have "gauss_int_norm q = p ^ 2" [PROOF STATE] proof (prove) using this: i \<le> 2 gauss_int_norm q = p ^ i i = 2 goal (1 subgoal): 1. gauss_int_norm q = p\<^sup>2 [PROOF STEP] by auto [PROOF STATE] proof (state) this: gauss_int_norm q = p\<^sup>2 goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] hence [simp]: "q = of_nat p" [PROOF STATE] proof (prove) using this: gauss_int_norm q = p\<^sup>2 goal (1 subgoal): 1. q = of_nat p [PROOF STEP] using prime_gauss_int_norm_squareD[of q p] q [PROOF STATE] proof (prove) using this: gauss_int_norm q = p\<^sup>2 \<lbrakk>prime q; gauss_int_norm q = p\<^sup>2\<rbrakk> \<Longrightarrow> prime p \<and> q = of_nat p q dvd z prime q goal (1 subgoal): 1. q = of_nat p [PROOF STEP] by auto [PROOF STATE] proof (state) this: q = of_nat p goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] have "normalize (of_nat p) = normalize z" [PROOF STATE] proof (prove) goal (1 subgoal): 1. normalize (of_nat p) = normalize z [PROOF STEP] using q assms [PROOF STATE] proof (prove) using this: q dvd z prime q prime p [p = 3] (mod 4) gauss_int_norm z = p\<^sup>2 goal (1 subgoal): 1. normalize (of_nat p) = normalize z [PROOF STEP] by (intro gauss_int_dvd_same_norm_imp_associated) auto [PROOF STATE] proof (state) this: normalize (of_nat p) = normalize z goal (2 subgoals): 1. normalize z = of_nat p 2. prime_elem z [PROOF STEP] thus *: "normalize z = of_nat p" [PROOF STATE] proof (prove) using this: normalize (of_nat p) = normalize z goal (1 subgoal): 1. normalize z = of_nat p [PROOF STEP] by simp [PROOF STATE] proof (state) this: normalize z = of_nat p goal (1 subgoal): 1. prime_elem z [PROOF STEP] have "prime (normalize z)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. prime (normalize z) [PROOF STEP] using prime_gauss_int_of_nat[of p] assms [PROOF STATE] proof (prove) using this: \<lbrakk>prime p; [p = 3] (mod 4)\<rbrakk> \<Longrightarrow> prime (of_nat p) prime p [p = 3] (mod 4) gauss_int_norm z = p\<^sup>2 goal (1 subgoal): 1. prime (normalize z) [PROOF STEP] by (subst *) auto [PROOF STATE] proof (state) this: prime (normalize z) goal (1 subgoal): 1. prime_elem z [PROOF STEP] thus "prime_elem z" [PROOF STATE] proof (prove) using this: prime (normalize z) goal (1 subgoal): 1. prime_elem z [PROOF STEP] by simp [PROOF STATE] proof (state) this: prime_elem z goal: No subgoals! [PROOF STEP] qed
State Before: f : ℝ → ℝ f' a b : ℝ h : IsLocalMin f a hf : HasDerivAt f f' a ⊢ f' = 0 State After: no goals Tactic: simpa using FunLike.congr_fun (h.hasFDerivAt_eq_zero (hasDerivAt_iff_hasFDerivAt.1 hf)) 1
[STATEMENT] lemma cbnd_mono: assumes "b \<le> d" shows "cbnd (a::nat) b \<le> cbnd a d" [PROOF STATE] proof (prove) goal (1 subgoal): 1. cbnd a b \<le> cbnd a d [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. cbnd a b \<le> cbnd a d [PROOF STEP] have "cbnd (a::nat) b \<le> cbnd a (b + d)" for b d [PROOF STATE] proof (prove) goal (1 subgoal): 1. cbnd a b \<le> cbnd a (b + d) [PROOF STEP] by(induction d arbitrary: a b; simp) (insert le_trans cbnd_grow, blast) [PROOF STATE] proof (state) this: cbnd a ?b \<le> cbnd a (?b + ?d) goal (1 subgoal): 1. cbnd a b \<le> cbnd a d [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: cbnd a ?b \<le> cbnd a (?b + ?d) goal (1 subgoal): 1. cbnd a b \<le> cbnd a d [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: cbnd a ?b \<le> cbnd a (?b + ?d) b \<le> d goal (1 subgoal): 1. cbnd a b \<le> cbnd a d [PROOF STEP] using le_Suc_ex [PROOF STATE] proof (prove) using this: cbnd a ?b \<le> cbnd a (?b + ?d) b \<le> d ?k \<le> ?l \<Longrightarrow> \<exists>n. ?l = ?k + n goal (1 subgoal): 1. cbnd a b \<le> cbnd a d [PROOF STEP] by blast [PROOF STATE] proof (state) this: cbnd a b \<le> cbnd a d goal: No subgoals! [PROOF STEP] qed
## Entry point of the executable using ArgParse function invalid_input_error(msg, e, stacktrace) println(stderr, msg) Base.display_error(stderr, e, stacktrace) return 2 end function parse_error(msg) println(stderr, msg) println(stderr, "See --help for usage.") return 3 end function internal_error(msg, e, stacktrace) println(stderr, msg) Base.display_error(stderr, e, stacktrace) return 4 end function unhandled_error(msg, e, stacktrace) println(stderr, msg) Base.display_error(stderr, e, stacktrace) return 5 end const usable_structuretypes = "mof, zeolite, cluster, guess and auto" const usable_clusterings = "auto, input, atom, singlenodes, allnodes, standard, pe and pem" const usable_bondings = "input, guess and auto" function parse_commandline(args) s = ArgParseSettings(prog = "CrystalNets" * (Sys.iswindows() ? ".exe" : ""), description = "Automatic recognition of crystal net topologies.", epilog = """\n\n\n\nSTRUCTURE options:\n\n \ua0\ua0\ua0* mof: consider the input as a MOF. Identify organic and inorganic clusters using heuristics.\n\n \ua0\ua0\ua0* zeolite: attempt to force each O atom two have exactly 2 non-O neighbours.\n\n \ua0\ua0\ua0* cluster: like mof but metallic atoms are not given a larger radius for bond detection.\n\n \ua0\ua0\ua0* guess: discard the input residues and try structure mode "cluster". If it fails, fall back to "auto".\n\n \ua0\ua0\ua0* auto: no specific structure. Default option.\n\n \n\n BONDING options:\n\n \ua0\ua0\ua0* input: use the bonds explicitly given by the input file. Fail if bonds are not provided by the input.\n\n \ua0\ua0\ua0* guess: guess bonds using a variant of chemfiles / VMD algorithm.\n\n \ua0\ua0\ua0* auto: if the input possesses explicit bonds, use them unless they are suspicious. Otherwise, fall back to "guess". Default option.\n\n \n\n CLUSTERING options:\n\n \ua0\ua0\ua0* auto: cluster according to the structure.\n\n \ua0\ua0\ua0* input: use the input residues as clusters. Fail if some atom does not belong to a residue.\n\n \ua0\ua0\ua0* atom: each atom is its own cluster.\n\n \ua0\ua0\ua0* singlenodes: each SBU is clustered into a single vertex.\n\n \ua0\ua0\ua0* allnodes: within each SBU, aromatic cycles are collapsed into vertices.\n\n \ua0\ua0\ua0* standard: each metal is its own vertex.\n\n \ua0\ua0\ua0* pe: each metallic SBU is implicitly represented by its points of extensions.\n\n \ua0\ua0\ua0* pem: each metallic SBU is represented by its points of extension and its metal.\n\n """, # \n\n # CREATE_MODE options:\n\n # \ua0\ua0\ua0* empty: empty archive, unable to recognize any topological structure.\n\n # \ua0\ua0\ua0* rcsr: RCSR Systre archive.\n\n # \ua0\ua0\ua0* zeolites: zeolites topologies from the database of zeolite structures.\n\n # \ua0\ua0\ua0* epinet: systre nets from the EPINET database.\n\n # \ua0\ua0\ua0* full: combined rcsr, zeolites and epinet archives. Default option.\n\n # """, preformatted_epilog = false, autofix_names = true, add_help = false, usage = """ usage: CrystalNets [-a ARCHIVE_PATH [-u NAME [-f] | -r [-f]]] [[-s STRUCTURE] [-b BONDING] [-c CLUSTERING] | -k] [--no-export | -e DIR_PATH] CRYSTAL_FILE """) # CrystalNets -a ARCHIVE_PATH -n [CREATE_MODE] [-f] (Form B) # CrystalNets -a ARCHIVE_PATH -d [-f] (Form C) # """) # add_arg_group!(s, "Options common to all forms") @add_arg_table! s begin "--help", "-h" help = "Show this help message and exit." action = :store_true "--no-warn" help = "Discard all warnings and information messages." action = :store_true "--no-export" help = "Do not automatically export the parsed input." action = :store_true "--archive", "-a" help = """Specify the path to an archive used to recognize topologies. If unspecified while using Form A, defaults to a combination of the RCSR Systre archive (available at http://rcsr.net/systre), the known zeolite topologies (registered at http://www.iza-structure.org/) and EPINET s-nets (available at http://epinet.anu.edu.au). """ metavar = "ARCHIVE_PATH" # "--force", "-f" # help = """Force the modification of the archive. Can only be used with # --update-archive, --new-archive, --remove-from-archive or --delete-archive. # """ # action = :store_true end # add_arg_group!(s, "Form A: give the name of the topology of a net") @add_arg_table! s begin "input" help = "Path to the crystal to be analyzed" required = false metavar = "CRYSTAL_FILE" "--structure", "-s" help = """Structure mode, to be chosen between $usable_structuretypes. See bottom for more details. """ metavar = "STRUCTURE" "--clustering", "-c" help = """Clustering algorithms, to be chosen between $usable_clusterings. See bottom for more details. """ metavar = "CLUSTERING" "--bond-detect", "-b" help = """Bond detection mode, to be chosen between $usable_bondings. See bottom for more details. """ metavar = "BONDING" "--export-to", "-e" help = """Automatically export the parsed input to the directory at DIR_PATH. By default this option is enabled with DIR_PATH=$(tempdir())""" metavar = "DIR_PATH" "--key", "-k" help = """If set, consider the CRYSTAL_FILE parameter as a topological key rather than the path to a crystal. """ action = :store_true # "--update-archive", "-u" # help = """Give a name to the topology of the crystal and add it to the # archive at ARCHIVE_PATH. If the topology is already known to the archive, # this will do nothing unless --force is passed on. The returned name is # the previous binding, if present, or "UNKNOWN" followed by the topological # genome otherwise. # """ # metavar = "NAME" # "--remove-from-archive", "-r" # help = """Remove the topology from the archive at ARCHIVE_PATH. If the # topology is absent, this will error unless --force is passed on. The # returned name is the previous binding, if present, or "UNKNOWN" followed # by the topological genome otherwise. # """ # action = :store_true end # add_arg_group!(s, "Form B: create a new archive") # @add_arg_table! s begin # "--new-archive", "-n" # help = """Create an archive at ARCHIVE_PATH. CREATE_MODE can be # either empty, full, rcsr, zeolites or epinet. # See bottom for more details. # """ # metavar = "CREATE_MODE" # nargs = '?' # constant = "full" # end # add_arg_group!(s, "Form C: delete an archive") # @add_arg_table! s begin # "--delete-archive", "-d" # help = """Delete the archive at ARCHIVE_PATH.""" # action = :store_true # end ret = try parse_args(args, s; as_symbols=true) catch e return internal_error("An error happened while parsing the input argument and options:", e, catch_backtrace()) end if ret[:help] ArgParse.show_help(s; exit_when_done=false) return 0 end return ret end function parse_to_str_or_nothing(@nospecialize(x))::Union{Nothing,String,Int} if isnothing(x) return nothing end str = try string(x) catch e return parse_error(lazy"Unrecognized argument format: $x.") end return String(strip(str)) end macro parse_to_str_or_nothing(x, name=x) return quote $(esc(name)) = parse_to_str_or_nothing($(esc(:parsed_args))[$(esc(QuoteNode(x)))]) $(esc(name)) isa $(esc(Int)) && return $(esc(name)) $(esc(name))::$(esc(Union{Nothing,String})) end end main(x::String) = main(split(x)) function split_clusterings(s) if s == "auto" Clustering.Auto elseif s == "input" Clustering.Input elseif s == "atom" Clustering.EachVertex elseif s == "singlenodes" Clustering.SingleNodes elseif s == "allnodes" Clustering.AllNodes elseif s == "standard" Clustering.Standard elseif s == "pe" Clustering.PE elseif s == "pem" Clustering.PEM else return parse_error(lazy"Unknown clustering mode: $s. Choose between $usable_clusterings.") end end function main(args) try _parsed_args = parse_commandline(args) if _parsed_args isa Int return _parsed_args end parsed_args::Dict{Symbol,Any} = _parsed_args @toggleassert !parsed_args[:help] # force::Bool = parsed_args[:force] if parsed_args[:no_warn]::Bool toggle_warning(false) end if parsed_args[:no_export]::Bool if !isnothing(parsed_args[:export_to]) return parse_error("""Cannot use both arguments "--export-to" and "--no-export".""") end toggle_export(false) end @parse_to_str_or_nothing export_to export_path::String = if export_to isa Nothing DOEXPORT[] ? tempdir() : "" else toggle_export(true) export_to end @parse_to_str_or_nothing archive # @parse_to_str_or_nothing new_archive new_archive_mode # if new_archive_mode isa String # if parsed_args[:delete_archive]::Bool # return parse_error("Cannot execute both forms B and C.") # elseif !isnothing(parsed_args[:input]) # return parse_error("Cannot execute both forms A and B.") # end # if archive isa Nothing # return parse_error("Cannot create an archive without specifying its location: use the --archive option to provide a path for the archive.") # else # if force && isfile(archive) # parse_error("The path specified by --archive already exists. Use --force to remove the existing file and replace it.") # end # if new_archive_mode == "full" # export_arc(archive, false) # elseif new_archive_mode == "empty" # export_arc(archive, true) # elseif new_archive_mode*".arc" ∈ readdir(arc_location) # flag, arc = parse_arc(arc_location * new_archive_mode *".arc") # if !flag # internal_error("""CrystalNets.jl appears to have a broken installation (the archive version is older than that package's). # Please rebuild CrystalNets.jl with `import Pkg; Pkg.build("CrystalNets")`. # """, AssertionError("flag"), catch_backtrace()) # end # export_arc(archive, false, arc) # else # return parse_error("""Unknown archive: $new_archive_mode. Choose between "full", "empty", "rcsr", "zeolites" or "epinet".""") # end # end # return 0 # end # if parsed_args[:delete_archive]::Bool # if !isnothing(parsed_args[:input]) # return parse_error("Cannot execute both forms A and C.") # end # if archive isa Nothing # return parse_error("""Cannot delete an archive without specifying its location: use the --archive option to provide a path for the archive.""") # else # if force # if !isfile(archive) # ifwarn("The specified archive does not exist.") # end # try # run(`rm -f $archive`) # catch e # return internal_error("Error encountered while deleting the archive:", # e, catch_backtrace()) # end # else # if !isfile(archive) # return parse_error("The specified archive does not exist.") # end # try # run(`rm $archive`) # catch e # return internal_error("""The following error was encountered while deleting the archive. Try with option --force.""", # e, catch_backtrace()) # end # end # end # return 0 # end @parse_to_str_or_nothing structure structure_mode structure::StructureType._StructureType = begin if structure_mode isa Nothing StructureType.Auto else if structure_mode == "mof" StructureType.MOF elseif structure_mode == "zeolite" StructureType.Zeolite elseif structure_mode == "cluster" StructureType.Cluster elseif structure_mode == "guess" StructureType.Guess elseif structure_mode == "auto" StructureType.Auto else return parse_error(lazy"Unknown structure type: $structure_mode. Choose between $usable_structuretypes.") end end end @parse_to_str_or_nothing clustering clustering_mode clusterings::Vector{Clustering._Clustering} = begin if clustering_mode isa Nothing [Clustering.Auto] else clustering_splits = split(clustering_mode, ',') _clusterings = Vector{Clustering._Clustering}(undef, length(clustering_splits)) for (i,s) in enumerate(clustering_splits) _clust = split_clusterings(s) if _clust isa Clustering._Clustering _clusterings[i] = _clust else return _clust end end _clusterings end end @parse_to_str_or_nothing bond_detect bonding::Bonding._Bonding = begin if bond_detect isa Nothing Bonding.Auto else if bond_detect == "input" Bonding.Input elseif bond_detect == "guess" Bonding.Guess elseif bond_detect == "auto" Bonding.Auto else return parse_error(lazy"Unknown bond detection mode: $bond_detect. Choose between $usable_bondings.") end end end # @parse_to_str_or_nothing update_archive new_topology_name # if new_topology_name isa String && isnothing(archive) # return parse_error("""Cannot update an archive without specifying its location: use the --archive option to provide a path for the archive.""") # end # remove_from_archive::Bool = parsed_args[:remove_from_archive] # if remove_from_archive && isnothing(archive) # return parse_error("""Cannot modify an archive without specifying its location: use the --archive option to provide a path for the archive.""") # end # if remove_from_archive && new_topology_name isa String # return parse_error("""Cannot both add and remove a topology from the archive. Choose only one of the options --update-archive and --remove-from-archive.""") # end iskey::Bool = parsed_args[:key] if iskey && (structure_mode isa String || clustering_mode isa String) msg = structure_mode isa String ? "structure type" : "clustering mode" return parse_error(lazy"Cannot consider the input as a topological key while also using a specified $(msg) because keys miss atom type information.") end @parse_to_str_or_nothing input input_file if input_file isa Nothing return parse_error("Missing a CRYSTAL_FILE.") end input_file::String if archive isa String try change_current_archive!(archive) catch e invalid_input_error("""Cannot use the specified archive because of the following error:""", e, catch_backtrace()) end end unets = try if iskey g = try PeriodicGraph(input_file) catch e return invalid_input_error("""Impossible to parse the given topological key because of the following error:""", e, catch_backtrace()) end UnderlyingNets(g) else crystal::Crystal = try parse_chemfile(input_file, Options(;export_input=export_path, export_net=export_path, structure, bonding, clusterings, throw_error=true, )) catch e return invalid_input_error("""The input file could not be correctly parsed as as a crystal because of the following error:""", e, catch_backtrace()) end UnderlyingNets(crystal) end catch e return invalid_input_error("""The input cannot be analyzed because of the following error:""", e, catch_backtrace()) end genomes::Vector{Tuple{Vector{Int},TopologyResult}} = try topological_genome(unets) catch e return internal_error("""Internal error encountered while computing the topological genome:""", e, catch_backtrace()) end #= if new_topology_name isa String if force _update_archive!(new_topology_name, genomes) export_arc(archive, false) else flag = true try add_to_current_archive!(new_topology_name, genomes) catch @ifwarn @info """The archive was not updated because either the name or the genome is already present.""" flag = false end if flag export_arc(archive, false) end end end if remove_from_archive if force || id isa String delete!(CRYSTAL_NETS_VERSION, genome) export_arc(archive, false) else return parse_error("""The genome "$genome" was unknown to the archive and thus could not be deleted. Use option --force to discard this error.""") end end =# if length(genomes) == 1 id = genomes[1][2] println(id) all(x -> isnothing(x.name), id) && return 1 return 0 end if length(genomes) == 0 println(TopologyResult("")) return 1 end println(genomes) return 1 catch e return unhandled_error("CrystalNets encountered an unhandled exception:", e, catch_backtrace()) end end Base.@ccallable function julia_main()::Cint main(ARGS) end
% LOWPASSFILTER - Constructs a low-pass butterworth filter. % % usage: f = lowpassfilter(sze, cutoff, n) % % where: sze is a two element vector specifying the size of filter % to construct [rows cols]. % cutoff is the cutoff frequency of the filter 0 - 0.5 % n is the order of the filter, the higher n is the sharper % the transition is. (n must be an integer >= 1). % Note that n is doubled so that it is always an even integer. % % 1 % f = -------------------- % 2n % 1.0 + (w/cutoff) % % The frequency origin of the returned filter is at the corners. % % See also: HIGHPASSFILTER, HIGHBOOSTFILTER, BANDPASSFILTER % % Copyright (c) 1999 Peter Kovesi % School of Computer Science & Software Engineering % The University of Western Australia % http://www.csse.uwa.edu.au/ % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal % in the Software without restriction, subject to the following conditions: % % The above copyright notice and this permission notice shall be included in % all copies or substantial portions of the Software. % % The Software is provided "as is", without warranty of any kind. % October 1999 % August 2005 - Fixed up frequency ranges for odd and even sized filters % (previous code was a bit approximate) function f = lowpassfilter(sze, cutoff, n) if cutoff < 0 | cutoff > 0.5 error('cutoff frequency must be between 0 and 0.5'); end if rem(n,1) ~= 0 | n < 1 error('n must be an integer >= 1'); end if length(sze) == 1 rows = sze; cols = sze; else rows = sze(1); cols = sze(2); end % Set up X and Y matrices with ranges normalised to +/- 0.5 % The following code adjusts things appropriately for odd and even values % of rows and columns. if mod(cols,2) xrange = [-(cols-1)/2:(cols-1)/2]/(cols-1); else xrange = [-cols/2:(cols/2-1)]/cols; end if mod(rows,2) yrange = [-(rows-1)/2:(rows-1)/2]/(rows-1); else yrange = [-rows/2:(rows/2-1)]/rows; end [x,y] = meshgrid(xrange, yrange); radius = sqrt(x.^2 + y.^2); % A matrix with every pixel = radius relative to centre. f = ifftshift( 1.0 ./ (1.0 + (radius ./ cutoff).^(2*n)) ); % The filter
(* * Copyright 2014, General Dynamics C4 Systems * * SPDX-License-Identifier: GPL-2.0-only *) theory Example2 imports Isolation_S begin lemma direct_caps_of_update [simp]: "direct_caps_of (s(x := y)) = (direct_caps_of s)(x:= case y of None \<Rightarrow> {} | Some (Entity c) \<Rightarrow> c)" by (rule ext, simp add: direct_caps_of_def split:option.splits) lemma direct_caps_of_empty [simp]: "direct_caps_of Map.empty = ( \<lambda> x. {})" by (simp add: direct_caps_of_def fun_eq_iff) definition "id\<^sub>0 \<equiv> 0" definition "id\<^sub>1 \<equiv> 1" definition "id\<^sub>2 \<equiv> 2" definition "id\<^sub>3 \<equiv> 3" definition "id\<^sub>4 \<equiv> 4" definition "id\<^sub>5 \<equiv> 5" (* e0 has create caps to all of memory, and full rights to itself. *) definition e0_caps :: "cap set" where "e0_caps \<equiv> range create_cap \<union> {full_cap 0}" definition s0 :: "state" where "s0 \<equiv> [0 \<mapsto> Entity e0_caps]" definition s1 :: "state" where "s1 \<equiv> [0 \<mapsto> Entity (e0_caps \<union> {full_cap 1}), 1 \<mapsto> null_entity]" definition s2 :: "state" where "s2 \<equiv> [0 \<mapsto> Entity (e0_caps \<union> {full_cap 1}), 1 \<mapsto> Entity {create_cap 2}]" definition s3 :: "state" where "s3 \<equiv> [0 \<mapsto> Entity (e0_caps \<union> {full_cap 1}), 1 \<mapsto> Entity {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>}]" definition s4 :: "state" where "s4 \<equiv> [0 \<mapsto> Entity (e0_caps \<union> {full_cap 1}), 1 \<mapsto> Entity {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}, 2 \<mapsto> null_entity]" definition s5 :: "state" where "s5 \<equiv> [0 \<mapsto> Entity (e0_caps \<union> {full_cap 1, write_cap 2}), 1 \<mapsto> Entity {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}, 2 \<mapsto> null_entity]" definition s6 :: "state" where "s6 \<equiv> [0 \<mapsto> Entity (e0_caps \<union> {full_cap 1, write_cap 2}), 1 \<mapsto> Entity {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2, read_cap 2}, 2 \<mapsto> null_entity]" definition s7 :: "state" where "s7 \<equiv> s4" definition s8 :: "state" where "s8 \<equiv> [0 \<mapsto> Entity (e0_caps \<union> {full_cap 1, full_cap 3}), 1 \<mapsto> Entity {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}, 2 \<mapsto> null_entity, 3 \<mapsto> null_entity]" definition s9 :: "state" where "s9 \<equiv> [0 \<mapsto> Entity (e0_caps \<union> {full_cap 1}), 1 \<mapsto> Entity {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}, 2 \<mapsto> null_entity, 3 \<mapsto> null_entity]" definition s10 :: "state" where "s10 \<equiv> s4" definition s :: "state" where "s \<equiv> [0 \<mapsto> Entity (e0_caps - {create_cap 1, create_cap 2}), 1 \<mapsto> Entity {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}, 2 \<mapsto> null_entity]" definition op0 :: "sysOPs" where "op0 \<equiv> SysCreate 0 (full_cap 0) (create_cap 1)" definition op1 :: "sysOPs" where "op1 \<equiv> SysGrant 0 (full_cap 1) (create_cap 2) UNIV" definition op2 :: "sysOPs" where "op2 \<equiv> SysGrant 0 (full_cap 1) (full_cap 1) {Write, Store}" definition op3 :: "sysOPs" where "op3 \<equiv> SysCreate 1 \<lparr>target = 1, rights = {Write, Store}\<rparr> (create_cap 2)" definition op4 :: "sysOPs" where "op4 \<equiv> SysTake 0 (full_cap 1) (full_cap 2) {Write}" definition op5 :: "sysOPs" where "op5 \<equiv> SysCopy 1 \<lparr>target = 1, rights = {Write, Store}\<rparr> (full_cap 2) {Read}" definition op6 :: "sysOPs" where "op6 \<equiv> SysRevoke 0 (write_cap 2)" definition op7 :: "sysOPs" where "op7 \<equiv> SysCreate 0 (full_cap 0) (create_cap 3)" definition op8 :: "sysOPs" where "op8 \<equiv> SysRemove 0 (full_cap 0) (full_cap 3)" definition op9 :: "sysOPs" where "op9 \<equiv> SysDestroy 0 (create_cap 3)" definition op10 :: "sysOPs" where "op10 \<equiv> SysRemoveSet 0 (full_cap 0) {full_cap 1, create_cap 1, create_cap 2}" definition ops :: "sysOPs list" where (* since the CDT isn't defined, op6 is skipped "ops \<equiv> [op10, op9, op8, op7, op6, op5, op4, op3, op2, op1, op0]" *) "ops \<equiv> [op10, op9, op8, op7, op3, op2, op1, op0]" (* is_entity lemmas *) lemma is_entity_s0_e0 [simp]: "is_entity s0 0" by (simp add: is_entity_def s0_def) lemma is_entity_s1_e0 [simp]: "is_entity s1 0" by (simp add: is_entity_def s1_def) lemma is_entity_s2_e0 [simp]: "is_entity s2 0" by (simp add: is_entity_def s2_def) lemma is_entity_s3_e0 [simp]: "is_entity s3 0" by (simp add: is_entity_def s3_def) lemma is_entity_s4_e0 [simp]: "is_entity s4 0" by (simp add: is_entity_def s4_def) lemma is_entity_s5_e0 [simp]: "is_entity s5 0" by (simp add: is_entity_def s5_def) lemma is_entity_s6_e0 [simp]: "is_entity s6 0" by (simp add: is_entity_def s6_def) lemma is_entity_s8_e0 [simp]: "is_entity s8 0" by (simp add: is_entity_def s8_def) lemma is_entity_s9_e0 [simp]: "is_entity s9 0" by (simp add: is_entity_def s9_def) lemma is_entity_s_e0 [simp]: "is_entity s 0" by (simp add: is_entity_def s_def) lemma is_entity_s0_e1 [simp]: "\<not> is_entity s0 1" by (simp add: is_entity_def s0_def) lemma is_entity_s1_e1 [simp]: "is_entity s1 1" by (simp add: is_entity_def s1_def) lemma is_entity_s2_e1 [simp]: "is_entity s2 1" by (simp add: is_entity_def s2_def) lemma is_entity_s3_e1 [simp]: "is_entity s3 1" by (simp add: is_entity_def s3_def) lemma is_entity_s4_e1 [simp]: "is_entity s4 1" by (simp add: is_entity_def s4_def) lemma is_entity_s5_e1 [simp]: "is_entity s5 1" by (simp add: is_entity_def s5_def) lemma is_entity_s3_e2 [simp]: "\<not> is_entity s3 2" by (simp add: is_entity_def s3_def) lemma is_entity_s4_e3 [simp]: "\<not> is_entity s4 3" by (simp add: is_entity_def s4_def) (* direct_caps_of, caps_of and similar lemmas *) lemma direct_caps_of_s0_e0_caps [simp]: "direct_caps_of s0 0 = e0_caps" by (simp add: direct_caps_of_def s0_def e0_caps_def) lemma direct_caps_of_s1_e0_caps [simp]: "direct_caps_of s1 0 = e0_caps \<union> {full_cap 1}" by (simp add: direct_caps_of_def s1_def e0_caps_def) lemma direct_caps_of_s2_e0_caps [simp]: "direct_caps_of s2 0 = e0_caps \<union> {full_cap 1}" by (simp add: direct_caps_of_def s2_def e0_caps_def) lemma direct_caps_of_s4_e0_caps [simp]: "direct_caps_of s4 0 = e0_caps \<union> {full_cap 1}" by (simp add: direct_caps_of_def s4_def e0_caps_def) lemma direct_caps_of_s5_e0_caps [simp]: "direct_caps_of s5 0 = e0_caps \<union> {full_cap 1, write_cap 2}" by (simp add: direct_caps_of_def s5_def e0_caps_def) lemma direct_caps_of_s6_e0_caps [simp]: "direct_caps_of s6 0 = e0_caps \<union> {full_cap 1, write_cap 2}" by (simp add: direct_caps_of_def s6_def e0_caps_def) lemma direct_caps_of_s8_e0_caps [simp]: "direct_caps_of s8 0 = e0_caps \<union> {full_cap 1, full_cap 3}" by (simp add: direct_caps_of_def s8_def e0_caps_def) lemma direct_caps_of_s9_e0_caps [simp]: "direct_caps_of s9 0 = e0_caps \<union> {full_cap 1}" by (simp add: direct_caps_of_def s9_def e0_caps_def) lemma direct_caps_of_s2_e1 [simp]: "direct_caps_of s2 1 = {create_cap 2}" by (simp add: direct_caps_of_def s2_def) lemma direct_caps_of_s3_e1 [simp]: "direct_caps_of s3 1 = {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>}" by (simp add: direct_caps_of_def s3_def) lemma direct_caps_of_s4_e1 [simp]: "direct_caps_of s4 1 = {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}" by (simp add: direct_caps_of_def s4_def) lemma direct_caps_of_s6_e1 [simp]: "direct_caps_of s5 1 = {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}" by (simp add: direct_caps_of_def s5_def) lemma direct_caps_of_s9_e1 [simp]: "direct_caps_of s9 1 = {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}" by (simp add: direct_caps_of_def s9_def) lemma full_cap_e0_caps_in_caps_of_s0_e0_caps [simp]: "full_cap 0 \<in> caps_of s0 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma full_cap_e1_in_caps_of_s1_e0_caps [simp]: "full_cap 1 \<in> caps_of s1 0" by (rule direct_cap_in_cap, simp) lemma full_cap_e1_in_caps_of_s2_e0_caps [simp]: "full_cap 1 \<in> caps_of s2 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma full_cap_e0_caps_in_caps_of_s4_e0_caps [simp]: "full_cap 0 \<in> caps_of s4 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma full_cap_e1_in_caps_of_s4_e0_caps [simp]: "full_cap 1 \<in> caps_of s4 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma full_cap_e2_in_caps_of_s4_e1 [simp]: "full_cap 2 \<in> caps_of s4 1" by (rule direct_cap_in_cap, simp) lemma full_cap_e1_in_caps_of_s5_e0_caps [simp]: "full_cap 1 \<in> caps_of s5 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma full_cap_e2_in_caps_of_s5_e0_caps [simp]: "full_cap 2 \<in> caps_of s5 1" by (rule direct_cap_in_cap, simp) lemma full_cap_e0_caps_in_caps_of_s8_e0_caps [simp]: "full_cap 0 \<in> caps_of s8 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma create_cap_in_caps_of_s0_e0_caps [simp]: "create_cap i \<in> caps_of s0 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma create_cap_in_caps_of_s1_e0_caps [simp]: "create_cap i \<in> caps_of s1 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma create_cap_in_caps_of_s2_e1 [simp]: "create_cap 2 \<in> caps_of s2 1" by (rule direct_cap_in_cap, simp) lemma create_cap_in_caps_of_s3_e1 [simp]: "create_cap 2 \<in> caps_of s3 1" by (rule direct_cap_in_cap, simp) lemma create_cap_in_caps_of_s4_e3 [simp]: "create_cap 3 \<in> caps_of s4 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma create_cap_in_caps_of_s9_e3 [simp]: "create_cap 3 \<in> caps_of s9 0" by (rule direct_cap_in_cap, simp add: e0_caps_def) lemma write_store_e1_in_caps_of_s3_e1 [simp]: "\<lparr>target = 1, rights = {Write, Store}\<rparr> \<in> caps_of s3 1" by (rule direct_cap_in_cap, simp) lemma write_store_e1_in_caps_of_s5_e1 [simp]: "\<lparr>target = 1, rights = {Write, Store}\<rparr> \<in> caps_of s5 1" by (rule direct_cap_in_cap, simp) lemma write_cap_e2_in_caps_of_s6_e0_caps [simp]: "write_cap 2 \<in> caps_of s6 0" by (rule direct_cap_in_cap, simp) (*********************************) (* State after the opeartions *) (*********************************) (* "op0 \<equiv> SysCreate 0 (full_cap 0) (create_cap 1)" *) lemma op0_legal: "legal op0 s0" by (clarsimp simp: op0_def all_rights_def) lemma execute_op0_safe: "step op0 s0 \<subseteq> ({s0, s1})" by (fastforce simp: op0_def step_def createOperation_def s0_def s1_def split: if_split_asm) lemma execute_op0_live: "step op0 s0 \<supseteq> ({s0, s1})" apply clarsimp apply (rule conjI) apply (simp add: step_def) apply (simp add: step_def op0_legal) apply (rule disjI2) apply (clarsimp simp: op0_def createOperation_def) apply (rule ext) apply (clarsimp simp: s0_def s1_def) done lemma execute_op0: "step op0 s0 = ({s0, s1})" apply rule apply (rule execute_op0_safe) apply (rule execute_op0_live) done (* "op1 \<equiv> SysGrant 0 (full_cap 1) (create_cap 2) UNIV" *) lemma op1_legal: "legal op1 s1" by (clarsimp simp: op1_def all_rights_def) lemma execute_op1_safe: "step op1 s1 \<subseteq> ({s1, s2})" by (clarsimp simp: op1_def step_def grantOperation_def diminish_def s1_def s2_def create_cap_def null_entity_def split: if_split_asm) lemma execute_op1_live: "step op1 s1 \<supseteq> ({s1, s2})" apply clarsimp apply (rule conjI) apply (simp add: step_def) apply (simp add: step_def op1_legal) apply (rule disjI2) apply (clarsimp simp: op1_def grantOperation_def) apply (rule ext) apply (clarsimp simp: s1_def s2_def null_entity_def) done lemma execute_op1: "step op1 s1 = ({s1, s2})" apply rule apply (rule execute_op1_safe) apply (rule execute_op1_live) done (* "op2 \<equiv> SysGrant 0 (full_cap 1) (full_cap 1) {Write, Store}" *) lemma op2_legal: "legal op2 s2" by (clarsimp simp: op2_def all_rights_def) lemma execute_op2_safe: "step op2 s2 \<subseteq> ({s2, s3})" apply clarsimp apply (rule ext) apply (auto simp: op2_def step_def grantOperation_def diminish_def s2_def s3_def full_cap_def all_rights_def split: if_split_asm) done lemma execute_op2_live: "step op2 s2 \<supseteq> ({s2, s3})" apply clarsimp apply (simp add: step_def op2_legal) apply (rule disjI2) apply (simp add: op2_def) apply (rule ext) apply (fastforce simp: s2_def s3_def grantOperation_def diminish_def all_rights_def full_cap_def) done lemma execute_op2: "step op2 s2 = ({s2, s3})" apply rule apply (rule execute_op2_safe) apply (rule execute_op2_live) done (* "op3 \<equiv> SysCreate 1 (full_cap 1) (create_cap 2)" *) lemma op3_legal: "legal op3 s3" by (clarsimp simp: op3_def all_rights_def) lemma execute_op3_safe: "step op3 s3 \<subseteq> ({s3, s4})" apply (clarsimp, rule ext) apply (auto simp: op3_def step_def createOperation_def s3_def s4_def split: if_split_asm) done lemma execute_op3_live: "step op3 s3 \<supseteq> ({s3, s4})" apply clarsimp apply (simp add: step_def op3_legal) apply (rule disjI2) apply (clarsimp simp: op3_def createOperation_def) apply (rule ext) apply (fastforce simp: s3_def s4_def) done lemma execute_op3: "step op3 s3 = ({s3, s4})" apply rule apply (rule execute_op3_safe) apply (rule execute_op3_live) done (* op4 \<equiv> SysTake 0 (full_cap 1) (full_cap 2) {Write} *) lemma op4_legal: "legal op4 s4" by (clarsimp simp: op4_def all_rights_def) lemma execute_op4_safe: "step op4 s4 \<subseteq> ({s4, s5})" apply (clarsimp, rule ext) apply (auto simp: s4_def s5_def op4_def step_def takeOperation_def diminish_def all_rights_def write_cap_def split: if_split_asm) done lemma execute_op4_live: "step op4 s4 \<supseteq> ({s4, s5})" apply clarsimp apply (simp add: op4_legal step_def) apply (rule disjI2) apply (simp add: op4_def) apply (rule ext) apply (fastforce simp: s4_def s5_def takeOperation_def diminish_def all_rights_def write_cap_def) done lemma execute_op4: "step op4 s4 = ({s4, s5})" apply rule apply (rule execute_op4_safe) apply (rule execute_op4_live) done (* op5 \<equiv> SysCopy 1 (full_cap 1) (full_cap 2) {Read} *) lemma op5_legal: "legal op5 s5" by (clarsimp simp: op5_def all_rights_def) lemma execute_op5_safe: "step op5 s5 \<subseteq> ({s5, s6})" apply (clarsimp, rule ext) apply (auto simp: s5_def s6_def op5_def step_def copyOperation_def diminish_def all_rights_def read_cap_def split: if_split_asm) done lemma execute_op5_live: "step op5 s5 \<supseteq> ({s5, s6})" apply clarsimp apply (simp add: step_def op5_legal) apply (rule disjI2) apply (simp add: op5_def) apply (rule ext) apply (fastforce simp: s5_def s6_def copyOperation_def diminish_def all_rights_def read_cap_def) done lemma execute_op5: "step op5 s5 = ({s5, s6})" apply rule apply (rule execute_op5_safe) apply (rule execute_op5_live) done (* op6 \<equiv> SysRevoke 0 (read_cap 2) *) lemma op6_legal: "legal op6 s6" by (clarsimp simp: op6_def all_rights_def) lemma execute_op6_safe: "step op6 s6 \<subseteq> ({s6, s7})" apply (clarsimp, rule ext) apply (auto simp: s6_def s7_def s4_def op7_def step_def revokeOperation_def split: if_split_asm) oops lemma execute_op6_live: "step op6 s6 \<supseteq> ({s6, s7})" apply (insert op6_legal) oops (* apply (auto simp: step_def op6_legal op6_def s6_def s7_def s4_def revokeOperation_def fun_eq_iff) done*) (* Since cdt is not defined, this proof can't be done *) lemma execute_op6_live: "s7 \<in> step op6 s6" oops lemma execute_op6: "step op6 s6 = ({s6, s7})" oops (* op7 \<equiv> SysCreate 0 (full_cap 0) (create_cap 3) *) lemma op7_legal: "legal op7 s7" by (clarsimp simp: s7_def op7_def all_rights_def) lemma execute_op7_safe: "step op7 s7 \<subseteq> ({s7, s8})" apply (clarsimp, rule ext) apply (auto simp: s7_def s8_def s4_def op7_def step_def createOperation_def split: if_split_asm) done lemma execute_op7_live: "step op7 s7 \<supseteq> ({s7, s8})" apply clarsimp apply (simp add: step_def op7_legal) apply (rule disjI2) apply (simp add: op7_def) apply (rule ext) apply (fastforce simp: s7_def s8_def s4_def createOperation_def) done lemma execute_op7: "step op7 s7 = ({s7, s8})" apply rule apply (rule execute_op7_safe) apply (rule execute_op7_live) done (* op8 \<equiv> SysRemove 0 (full_cap 0) (full_cap 3) *) lemma op8_legal: "legal op8 s8" by (clarsimp simp: op8_def) lemma execute_op8_safe: "step op8 s8 \<subseteq> ({s8, s9})" apply clarsimp apply (rule ext) apply (insert op8_legal) apply (fastforce simp: step_def op8_def s8_def s9_def removeOperation_def full_cap_def create_cap_def all_rights_def e0_caps_def) done lemma execute_op8_live: "step op8 s8 \<supseteq> ({s8, s9})" apply (simp add: step_def op8_legal op8_def) apply (rule disjI2) apply (rule ext) apply (clarsimp simp: removeOperation_def) apply (fastforce simp: s8_def s9_def full_cap_def create_cap_def all_rights_def e0_caps_def) done lemma execute_op8: "step op8 s8 = ({s8, s9})" apply rule apply (rule execute_op8_safe) apply (rule execute_op8_live) done (* op9 \<equiv> SysDelete 0 (create_cap 3) *) lemma op9_legal: "legal op9 s9" apply (simp add: op9_def) apply (fastforce simp: s9_def e0_caps_def null_entity_def split:if_split_asm) done lemma execute_op9_safe: "step op9 s9 \<subseteq> ({s9, s10})" apply (clarsimp, rule ext) apply (auto simp: s9_def s10_def s4_def op9_def step_def destroyOperation_def split: if_split_asm) done lemma execute_op9_live: "step op9 s9 \<supseteq> ({s9, s10})" apply (simp add: step_def op9_legal) apply (rule disjI2) apply (simp add: op9_def) apply (rule ext) apply (clarsimp simp: destroyOperation_def step_def op9_def s9_def s10_def s4_def) done lemma execute_op9: "step op9 s9 = ({s9, s10})" apply rule apply (rule execute_op9_safe) apply (rule execute_op9_live) done (* op10 \<equiv> SysRemoveSet 0 (full_cap 0) {full_cap 1, create_cap 1, create_cap 2} *) lemma op10_legal: "legal op10 s10" by (clarsimp simp: s10_def op10_def all_rights_def) lemma e0_caps_diminished [simp]: "e0_caps - {full_cap 1, create_cap 1, create_cap 2} = e0_caps - {create_cap 1, create_cap 2}" by (fastforce simp: e0_caps_def create_cap_def full_cap_def all_rights_def) lemma execute_op10_safe: "step op10 s10 \<subseteq> ({s10, s})" apply (clarsimp, rule ext) apply (auto simp: s10_def op10_def step_def removeSetOperation_def s4_def s_def split: if_split_asm) done lemma execute_op10_live: "step op10 s10 \<supseteq> ({s10, s})" apply clarsimp apply (rule conjI) apply (simp add: step_def) apply (simp add: step_def op10_legal) apply (rule disjI2) apply (clarsimp simp: s10_def op10_def removeSetOperation_def) apply (rule ext) apply (fastforce simp: s4_def s_def) done lemma execute_op10: "step op10 s10 = ({s10, s})" apply rule apply (rule execute_op10_safe) apply (rule execute_op10_live) done lemma execute_ops: "s \<in> execute ops s0" apply (clarsimp simp: ops_def) apply (insert execute_op0_live execute_op1_live execute_op2_live execute_op3_live execute_op4_live execute_op5_live execute_op7_live execute_op8_live execute_op9_live execute_op10_live) apply (simp add: s7_def) apply fastforce done (*********************************) (* Results about the final state *) (*********************************) lemma store_not_in_create_cap [simp]: "Store \<notin> rights (create_cap i)" by (simp add: create_cap_def) lemma store_not_in_create_cap2 [simp]: "Store \<in> rights c \<Longrightarrow> c \<noteq> create_cap i" by (clarsimp simp: create_cap_def) (*********************************) (* store_connected_direct *) (*********************************) lemma store_connected_direct_s_helper1: "{c'.(c' = \<lparr>target = 0, rights = UNIV\<rparr> \<or> c' \<in> range create_cap) \<and> c' \<noteq> \<lparr>target = 1, rights = {Create}\<rparr> \<and> c' \<noteq> \<lparr>target = 2, rights = {Create}\<rparr> \<and> Store \<in> rights c'} = {full_cap 0}" by (auto simp: create_cap_def full_cap_def all_rights_def e0_caps_def) lemma store_connected_direct_s_helper2: "{c'. (c' = \<lparr>target = 2, rights = {Create}\<rparr> \<or> c' = \<lparr>target = 1, rights = {Write, Store}\<rparr> \<or> c' = \<lparr>target = 2, rights = UNIV\<rparr>) \<and> Store \<in> rights c'} = {\<lparr>target = 1, rights = {Write, Store}\<rparr>, full_cap 2}" by (auto simp: create_cap_def full_cap_def all_rights_def e0_caps_def) lemma store_connected_direct_s: "store_connected_direct s = {(0,0), (1,1), (1,2)}" by (fastforce simp: store_connected_direct_def s_def e0_caps_def full_cap_def all_rights_def create_cap_def null_entity_def store_connected_direct_s_helper1 store_connected_direct_s_helper2 split: if_split_asm) (*********************************) (* store_connected *) (*********************************) lemma into_rtrancl [rule_format]: "(a,b) \<in> r^* \<Longrightarrow> (\<forall>x. (x,b) \<in> r \<longrightarrow> x = b) \<longrightarrow> a = b" apply (erule converse_rtrancl_induct) apply simp apply clarsimp done lemma into_rtrancl2 [rule_format]: " \<And> B. \<lbrakk>(a,b) \<in> r^*; b \<in> B\<rbrakk> \<Longrightarrow> (\<forall>x.(x,b) \<in> r \<longrightarrow> x \<in> B) \<longrightarrow> a \<in> B" thm rtrancl_induct converse_rtrancl_induct apply (erule converse_rtrancl_induct) apply clarsimp apply clarsimp oops lemma store_connected_id: "{(0::word32, 0), (1, 1), (1, 2)}\<^sup>* = {(1, 2)}\<^sup>* " apply rule apply clarsimp apply (erule rtranclE) apply simp apply (fastforce dest: into_rtrancl) apply clarsimp apply (erule rtranclE) apply simp apply (fastforce dest: into_rtrancl) done lemma store_connected_s: "store_connected s = {(1,2)} \<union> Id" apply simp apply (rule equalityI) apply (insert store_connected_direct_s) apply (simp add: store_connected_def) apply clarsimp apply (erule converse_rtranclE) apply simp apply clarsimp apply (erule rtranclE) apply fastforce apply (simp add: store_connected_id) apply (drule rtranclD) apply (safe, simp_all, (erule tranclE, simp, fastforce)+) apply (fastforce simp: store_connected_def) done (*********************************) (* caps_of *) (*********************************) lemma caps_of_s_e0_caps: "caps_of s 0 = e0_caps - {create_cap 1, create_cap 2}" apply (clarsimp simp: caps_of_def store_connected_s Collect_disj_eq) apply (simp add: s_def) done lemma caps_of_s_e0_caps_2: "caps_of s 0 = {full_cap 0} \<union> ( range create_cap - {create_cap 1, create_cap 2})" by (fastforce simp: caps_of_s_e0_caps e0_caps_def full_cap_def create_cap_def) lemma caps_of_s_e1: "caps_of s 1 = {create_cap 2, \<lparr> target = 1, rights = {Write, Store}\<rparr>, full_cap 2}" apply (clarsimp simp: caps_of_def store_connected_s Collect_disj_eq) apply (simp add: s_def null_entity_def) done lemma caps_of_s_e2: "caps_of s 2 = {}" apply (simp add: caps_of_def store_connected_s) apply (simp add: s_def null_entity_def) done lemma caps_of_s_e3: "\<lbrakk>e \<noteq> 0; e \<noteq> 1\<rbrakk> \<Longrightarrow> caps_of s e = {}" apply (simp add: caps_of_def store_connected_s) apply (simp add: s_def null_entity_def) done (*********************************) (* caps_of' *) (*********************************) lemma extra_rights_create_cap: "extra_rights (create_cap i) = full_cap i" by (simp add: create_cap_def full_cap_def extra_rights_def) lemma extra_rights_full_cap: "extra_rights (full_cap i) = full_cap i" by (simp add: full_cap_def extra_rights_def) lemma extra_rights_take_cap: "extra_rights (take_cap i) = take_cap i" by (simp add: take_cap_def extra_rights_def) lemma extra_rights_grant_cap: "extra_rights (grant_cap i) = grant_cap i" by (simp add: take_cap_def extra_rights_def) lemma caps_of'_s_e0_caps_helper: "extra_rights ` (range create_cap - {create_cap 1, create_cap 2}) = range full_cap - {full_cap 1, full_cap 2}" apply rule apply (fastforce simp: create_cap_def extra_rights_def all_rights_def full_cap_def) apply rule apply (erule DiffE) apply clarsimp apply (rule image_eqI) apply (rule extra_rights_create_cap [THEN sym]) apply (simp add: full_cap_def create_cap_def) done (*********************************) (* connected *) (*********************************) lemma extra_rights_increases_rights: "rights c \<subseteq> rights (extra_rights c)" by (simp add: extra_rights_def all_rights_def) lemma cap_in_caps_take_cap: "\<lbrakk>create_cap x \<in> caps_of s y\<rbrakk> \<Longrightarrow> take_cap x \<in>cap caps_of s y" apply (auto simp: cap_in_caps_def caps_of_def extra_rights_take_cap) apply (rule exI, rule conjI, assumption) apply (rule rev_bexI, simp) apply (rule conjI) apply (subgoal_tac "target (full_cap x) = x", simp+) apply (simp add: extra_rights_create_cap all_rights_def) done lemma e0_connected_to: "\<lbrakk>x \<noteq> 1; x \<noteq> 2\<rbrakk> \<Longrightarrow> s \<turnstile> 0 \<leftrightarrow> x" apply (rule directly_tgs_connected_comm) apply (simp add: directly_tgs_connected_def4) apply (rule disjI1) apply (rule cap_in_caps_take_cap) apply (simp add: caps_of_s_e0_caps e0_caps_def create_cap_def) done lemma e1_connected_to_e2: "s \<turnstile> 1 \<leftrightarrow> 2" apply (simp add: directly_tgs_connected_def4) apply (rule disjI2)+ apply (simp add: shares_caps_def) apply (simp add: store_connected_s) done lemma e0_caps_not_connected_to_e1: "\<not> (s \<turnstile> 0 \<leftrightarrow> 1)" apply (simp add: directly_tgs_connected_def4) apply (rule conjI) apply (simp add: cap_in_caps_def caps_of_s_e1) apply (rule conjI) apply (clarsimp simp add: cap_in_caps_def caps_of_s_e0_caps e0_caps_def) apply (erule disjE) apply (simp add: full_cap_def) apply clarsimp apply (rule conjI) apply (clarsimp simp add: cap_in_caps_def caps_of_s_e0_caps e0_caps_def) apply (erule disjE) apply (simp add: full_cap_def) apply clarsimp apply (rule conjI) apply (simp add: cap_in_caps_def caps_of_s_e1) apply (simp add: shares_caps_def) apply (simp add: store_connected_s) done lemma e0_caps_not_connected_to_e2: "\<not> (s \<turnstile> 0 \<leftrightarrow> 2)" apply (simp add: directly_tgs_connected_def4) apply (rule conjI) apply (simp add: cap_in_caps_def caps_of_s_e2) apply (rule conjI) apply (clarsimp simp add: cap_in_caps_def caps_of_s_e0_caps e0_caps_def) apply (erule disjE) apply (simp add: full_cap_def) apply clarsimp apply (rule conjI) apply (clarsimp simp add: cap_in_caps_def caps_of_s_e0_caps e0_caps_def) apply (erule disjE) apply (simp add: full_cap_def) apply clarsimp apply (rule conjI) apply (simp add: cap_in_caps_def caps_of_s_e2) apply (simp add: shares_caps_def) apply (simp add: store_connected_s) done (*********************************) (* connected_trans *) (*********************************) lemma e1_connected_trans_to_e2: "s \<turnstile> 1 \<leftrightarrow>* 2" apply (insert e1_connected_to_e2) apply (simp add: tgs_connected_def) done lemma caps_of_to_e1: "\<lbrakk>c \<in> caps_of s x; target c = 1\<rbrakk> \<Longrightarrow> x = 1 \<or> x = 2" apply (case_tac "x = 0") apply (fastforce simp: caps_of_s_e0_caps_2) apply (case_tac "x = 1") apply (fastforce simp: caps_of_s_e1) apply (fastforce simp: caps_of_s_e3) done lemma caps_of_to_e2: "\<lbrakk>c \<in> caps_of s x; target c = 2\<rbrakk> \<Longrightarrow> x = 1" apply (case_tac "x = 0") apply (fastforce simp: caps_of_s_e0_caps_2) apply (case_tac "x = 1") apply (fastforce simp: caps_of_s_e1) apply (fastforce simp: caps_of_s_e3) done lemma cap_in_caps_caps_of_e1: "c \<in>cap caps_of s 1 \<Longrightarrow> target c = 1 \<or> target c = 2" by (clarsimp simp: cap_in_caps_def caps_of_s_e1) lemma cap_in_caps_caps_of_e2: "c \<in>cap caps_of s 2 \<Longrightarrow> False" by (clarsimp simp: cap_in_caps_def caps_of_s_e2) lemma cap_in_caps_caps_of_to_e1: "\<lbrakk>c \<in>cap caps_of s x; target c = 1\<rbrakk> \<Longrightarrow> x = 1 \<or> x = 2" apply (clarsimp simp: cap_in_caps_def) apply (drule (1) caps_of_to_e1, simp) done lemma cap_in_caps_caps_of_to_e2: "\<lbrakk>c \<in>cap caps_of s x; target c = 2\<rbrakk> \<Longrightarrow> x = 1" apply (clarsimp simp: cap_in_caps_def) apply (erule (1) caps_of_to_e2) done lemma e1_connected_to: "s \<turnstile> 1 \<leftrightarrow> x \<Longrightarrow> x = 1 \<or> x = 2" apply (simp add: directly_tgs_connected_def4) apply (erule disjE) apply (erule cap_in_caps_caps_of_to_e1, simp) apply (erule disjE) apply (drule cap_in_caps_caps_of_e1, simp) apply (erule disjE) apply (drule cap_in_caps_caps_of_e1, simp) apply (erule disjE) apply (erule cap_in_caps_caps_of_to_e1, simp) apply (fastforce simp: shares_caps_def store_connected_s) done lemma e2_connected_to: "s \<turnstile> 2 \<leftrightarrow> x \<Longrightarrow> x = 1 \<or> x = 2" apply (simp add: directly_tgs_connected_def4) apply (erule disjE, rule disjI1) apply (erule cap_in_caps_caps_of_to_e2, simp) apply (erule disjE, rule disjI1) apply (drule cap_in_caps_caps_of_e2, simp) apply (erule disjE, rule disjI1) apply (drule cap_in_caps_caps_of_e2, simp) apply (erule disjE, rule disjI1) apply (erule cap_in_caps_caps_of_to_e2, simp) apply (clarsimp simp: shares_caps_def store_connected_s) done lemma directly_tgs_connected_in_inv_image: "(directly_tgs_connected s) \<subseteq> inv_image Id (\<lambda> x. x=1 \<or> x=2)" by (fastforce simp: inv_image_def dest!: e1_connected_to e1_connected_to [OF directly_tgs_connected_comm] e2_connected_to e2_connected_to [OF directly_tgs_connected_comm]) lemma connected_inv_image_trans: "trans (inv_image Id (\<lambda> x. x=1 \<or> x=2))" by (rule trans_inv_image [OF trans_Id]) lemma eq_inv_image_connected: "(inv_image Id (\<lambda> x. x=1 \<or> x=2))\<^sup>= = inv_image Id (\<lambda> x. x=1 \<or> x=2)" by (fastforce simp: inv_image_def) lemma rtrancl_inv_image_connected: "(inv_image Id (\<lambda> x. x=1 \<or> x=2))\<^sup>* = inv_image Id (\<lambda> x. x=1 \<or> x=2)" apply (subst trancl_reflcl [symmetric]) apply (subst eq_inv_image_connected) apply (rule trancl_id) apply (rule connected_inv_image_trans) done lemma tgs_connected_in_inv_image: "(tgs_connected s) \<subseteq> inv_image Id (\<lambda> x. x=1 \<or> x=2)" apply (simp add: tgs_connected_def) apply (subst rtrancl_inv_image_connected [symmetric]) apply (rule rtrancl_mono) apply (rule directly_tgs_connected_in_inv_image) done lemma e0_not_connected_trans_e1: "\<not> s \<turnstile> 0 \<leftrightarrow>* 1" apply clarsimp apply (drule set_mp [OF tgs_connected_in_inv_image]) apply (simp add: inv_image_def) done lemma e0_not_ever_connected_trans_e1: "s' \<in> execute cmds s \<Longrightarrow> \<not> s' \<turnstile> 0 \<leftrightarrow>* 1" apply clarsimp apply (drule (1) tgs_connected_preserved) apply (simp add: e0_not_connected_trans_e1) done lemma e0_e1_leakage: "s' \<in> execute cmds s \<Longrightarrow> \<not> leak s' 0 1" apply (insert e0_not_connected_trans_e1) apply (drule (2) leakage_rule) done (*********************************) (* islandtems *) (*********************************) lemma island_e0: "island s 0 = {i. i \<noteq> 1 \<and> i \<noteq> 2}" apply rule apply (clarsimp simp: island_def) apply (insert tgs_connected_in_inv_image)[1] apply fastforce apply (clarsimp simp: island_def) apply (drule (1) e0_connected_to) apply (drule directly_tgs_connected_comm) by (metis directly_tgs_connected_def2 tgs_connected_comm leakImplyConnectedTrans) lemma island_e1: "island s 1 = {1,2}" apply rule apply (clarsimp simp: island_def) apply (insert tgs_connected_in_inv_image)[1] apply fastforce apply (clarsimp simp: island_def) apply (rule e1_connected_trans_to_e2) done lemma island_e2: "island s 2 = {1,2}" apply rule apply (clarsimp simp: island_def) apply (insert tgs_connected_in_inv_image)[1] apply fastforce apply (clarsimp simp: island_def) apply (rule e1_connected_trans_to_e2 [THEN tgs_connected_comm]) done lemma island_e3: "\<lbrakk>x \<noteq> 1; x \<noteq> 2\<rbrakk> \<Longrightarrow> island s x = {i. i \<noteq> 1 \<and> i \<noteq> 2}" apply rule apply (clarsimp simp: island_def) apply (insert tgs_connected_in_inv_image)[1] apply fastforce apply (clarsimp simp: island_def) apply (frule_tac x=x in e0_connected_to, simp) apply (frule_tac x=xa in e0_connected_to, simp) apply (drule_tac x=0 and y=xa in directly_tgs_connected_comm) apply (rule tgs_connected_comm) apply (simp add: tgs_connected_def) done (*********************************) (* isolation *) (*********************************) lemma e1_flow_to: "s \<turnstile> 1 \<leadsto> x \<Longrightarrow> x = 1 \<or> x = 2" apply (rule ccontr) apply (clarsimp simp: flow_def set_flow_def island_e1 island_e3) apply (erule disjE, clarsimp) apply (erule disjE) apply (drule cap_in_caps_caps_of_to_e1, clarsimp+) apply (drule cap_in_caps_caps_of_e1, clarsimp+) apply (erule disjE) apply (drule cap_in_caps_caps_of_to_e2, clarsimp+) apply (drule cap_in_caps_caps_of_e2, clarsimp+) done lemma e2_flow_to: "s \<turnstile> 2 \<leadsto> x \<Longrightarrow> x = 1 \<or> x = 2" apply (rule ccontr) apply (clarsimp simp: flow_def set_flow_def island_e2 island_e3) apply (erule disjE, clarsimp) apply (erule disjE) apply (drule cap_in_caps_caps_of_to_e1, clarsimp+) apply (drule cap_in_caps_caps_of_e1, clarsimp+) apply (erule disjE) apply (drule cap_in_caps_caps_of_to_e2, clarsimp+) apply (drule cap_in_caps_caps_of_e2, clarsimp+) done lemma flow_to_e1: "s \<turnstile> x \<leadsto> 1 \<Longrightarrow> x = 1 \<or> x = 2" apply (rule ccontr) apply (clarsimp simp: flow_def set_flow_def island_e1 island_e3) apply (erule disjE) apply (drule cap_in_caps_caps_of_e1, clarsimp+) apply (erule disjE) apply (drule cap_in_caps_caps_of_to_e1, clarsimp+) apply (erule disjE) apply (drule cap_in_caps_caps_of_e2, clarsimp+) apply (drule cap_in_caps_caps_of_to_e2, clarsimp+) done lemma flow_to_e2: "s \<turnstile> x \<leadsto> 2 \<Longrightarrow> x = 1 \<or> x = 2" apply (rule ccontr) apply (clarsimp simp: flow_def set_flow_def island_e2 island_e3) apply (erule disjE) apply (drule cap_in_caps_caps_of_e1, clarsimp+) apply (erule disjE) apply (drule cap_in_caps_caps_of_to_e1, clarsimp+) apply (erule disjE) apply (drule cap_in_caps_caps_of_e2, clarsimp+) apply (drule cap_in_caps_caps_of_to_e2, clarsimp+) done lemma flow_in_inv_image: "(flow s) \<subseteq> inv_image Id (\<lambda> x. x=1 \<or> x=2)" by (fastforce simp: inv_image_def dest!: e1_flow_to flow_to_e1 e2_flow_to flow_to_e2) lemma flow_trans_in_inv_image: "(flow_trans s) \<subseteq> inv_image Id (\<lambda> x. x=1 \<or> x=2)" apply (simp add: flow_trans_def) apply (subst rtrancl_inv_image_connected [symmetric]) apply (rule rtrancl_mono) apply (rule flow_in_inv_image) done lemma e0_not_flow_trans_e1: "\<not> s \<turnstile> 0 \<leadsto>* 1" apply clarsimp apply (drule set_mp [OF flow_trans_in_inv_image]) apply (simp add: inv_image_def) done lemma e1_not_flow_trans_e0: "\<not> s \<turnstile> 1 \<leadsto>* 0" apply clarsimp apply (drule set_mp [OF flow_trans_in_inv_image]) apply (simp add: inv_image_def) done lemma e0_e1_isolated: "s' \<in> execute cmds s \<Longrightarrow> \<not> s' \<turnstile> 0 \<leadsto>* 1 \<and> \<not> s' \<turnstile> 1 \<leadsto>* 0" apply (rule conjI) apply (erule information_flow) apply (rule e0_not_flow_trans_e1) apply (erule information_flow) apply (rule e1_not_flow_trans_e0) done end
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.eq_to_hom import Mathlib.PostPort universes u₁ v₁ namespace Mathlib /-# Disjoint unions of categories, functors, and natural transformations. -/ namespace category_theory /-- `sum C D` gives the direct sum of two categories. -/ protected instance sum (C : Type u₁) [category C] (D : Type u₁) [category D] : category (C ⊕ D) := category.mk @[simp] theorem sum_comp_inl (C : Type u₁) [category C] (D : Type u₁) [category D] {P : C} {Q : C} {R : C} (f : sum.inl P ⟶ sum.inl Q) (g : sum.inl Q ⟶ sum.inl R) : f ≫ g = f ≫ g := rfl @[simp] theorem sum_comp_inr (C : Type u₁) [category C] (D : Type u₁) [category D] {P : D} {Q : D} {R : D} (f : sum.inr P ⟶ sum.inr Q) (g : sum.inr Q ⟶ sum.inr R) : f ≫ g = f ≫ g := rfl namespace sum /-- `inl_` is the functor `X ↦ inl X`. -/ -- Unfortunate naming here, suggestions welcome. def inl_ (C : Type u₁) [category C] (D : Type u₁) [category D] : C ⥤ C ⊕ D := functor.mk (fun (X : C) => sum.inl X) fun (X Y : C) (f : X ⟶ Y) => f /-- `inr_` is the functor `X ↦ inr X`. -/ def inr_ (C : Type u₁) [category C] (D : Type u₁) [category D] : D ⥤ C ⊕ D := functor.mk (fun (X : D) => sum.inr X) fun (X Y : D) (f : X ⟶ Y) => f /-- The functor exchanging two direct summand categories. -/ def swap (C : Type u₁) [category C] (D : Type u₁) [category D] : C ⊕ D ⥤ D ⊕ C := functor.mk (fun (X : C ⊕ D) => sorry) fun (X Y : C ⊕ D) (f : X ⟶ Y) => sorry @[simp] theorem swap_obj_inl (C : Type u₁) [category C] (D : Type u₁) [category D] (X : C) : functor.obj (swap C D) (sum.inl X) = sum.inr X := rfl @[simp] theorem swap_obj_inr (C : Type u₁) [category C] (D : Type u₁) [category D] (X : D) : functor.obj (swap C D) (sum.inr X) = sum.inl X := rfl @[simp] theorem swap_map_inl (C : Type u₁) [category C] (D : Type u₁) [category D] {X : C} {Y : C} {f : sum.inl X ⟶ sum.inl Y} : functor.map (swap C D) f = f := rfl @[simp] theorem swap_map_inr (C : Type u₁) [category C] (D : Type u₁) [category D] {X : D} {Y : D} {f : sum.inr X ⟶ sum.inr Y} : functor.map (swap C D) f = f := rfl namespace swap /-- `swap` gives an equivalence between `C ⊕ D` and `D ⊕ C`. -/ def equivalence (C : Type u₁) [category C] (D : Type u₁) [category D] : C ⊕ D ≌ D ⊕ C := equivalence.mk (swap C D) (swap D C) (nat_iso.of_components (fun (X : C ⊕ D) => eq_to_iso sorry) sorry) (nat_iso.of_components (fun (X : D ⊕ C) => eq_to_iso sorry) sorry) protected instance is_equivalence (C : Type u₁) [category C] (D : Type u₁) [category D] : is_equivalence (swap C D) := is_equivalence.of_equivalence (equivalence C D) /-- The double swap on `C ⊕ D` is naturally isomorphic to the identity functor. -/ def symmetry (C : Type u₁) [category C] (D : Type u₁) [category D] : swap C D ⋙ swap D C ≅ 𝟭 := iso.symm (equivalence.unit_iso (equivalence C D)) end swap end sum namespace functor /-- The sum of two functors. -/ def sum {A : Type u₁} [category A] {B : Type u₁} [category B] {C : Type u₁} [category C] {D : Type u₁} [category D] (F : A ⥤ B) (G : C ⥤ D) : A ⊕ C ⥤ B ⊕ D := mk (fun (X : A ⊕ C) => sorry) fun (X Y : A ⊕ C) (f : X ⟶ Y) => sorry @[simp] theorem sum_obj_inl {A : Type u₁} [category A] {B : Type u₁} [category B] {C : Type u₁} [category C] {D : Type u₁} [category D] (F : A ⥤ B) (G : C ⥤ D) (a : A) : obj (sum F G) (sum.inl a) = sum.inl (obj F a) := rfl @[simp] theorem sum_obj_inr {A : Type u₁} [category A] {B : Type u₁} [category B] {C : Type u₁} [category C] {D : Type u₁} [category D] (F : A ⥤ B) (G : C ⥤ D) (c : C) : obj (sum F G) (sum.inr c) = sum.inr (obj G c) := rfl @[simp] theorem sum_map_inl {A : Type u₁} [category A] {B : Type u₁} [category B] {C : Type u₁} [category C] {D : Type u₁} [category D] (F : A ⥤ B) (G : C ⥤ D) {a : A} {a' : A} (f : sum.inl a ⟶ sum.inl a') : map (sum F G) f = map F f := rfl @[simp] theorem sum_map_inr {A : Type u₁} [category A] {B : Type u₁} [category B] {C : Type u₁} [category C] {D : Type u₁} [category D] (F : A ⥤ B) (G : C ⥤ D) {c : C} {c' : C} (f : sum.inr c ⟶ sum.inr c') : map (sum F G) f = map G f := rfl end functor namespace nat_trans /-- The sum of two natural transformations. -/ def sum {A : Type u₁} [category A] {B : Type u₁} [category B] {C : Type u₁} [category C] {D : Type u₁} [category D] {F : A ⥤ B} {G : A ⥤ B} {H : C ⥤ D} {I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) : functor.sum F H ⟶ functor.sum G I := mk fun (X : A ⊕ C) => sorry @[simp] theorem sum_app_inl {A : Type u₁} [category A] {B : Type u₁} [category B] {C : Type u₁} [category C] {D : Type u₁} [category D] {F : A ⥤ B} {G : A ⥤ B} {H : C ⥤ D} {I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) (a : A) : app (sum α β) (sum.inl a) = app α a := rfl @[simp] theorem sum_app_inr {A : Type u₁} [category A] {B : Type u₁} [category B] {C : Type u₁} [category C] {D : Type u₁} [category D] {F : A ⥤ B} {G : A ⥤ B} {H : C ⥤ D} {I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) (c : C) : app (sum α β) (sum.inr c) = app β c := rfl end Mathlib
(* -------------------------------------------------------------------- *) From mathcomp Require Import all_ssreflect all_algebra. From mathcomp.analysis Require Import boolp reals realsum distr. (* ------- *) Require Import notations. (* -------------------------------------------------------------------- *) CoInductive or_spec (a b : bool) : bool -> bool -> Type := | OrT of a : or_spec a b true true | OrF of ~~ a : or_spec a b false b. Lemma orlP a b : or_spec a b a (a || b). Proof. by case: (boolP a) => h; constructor. Qed. Lemma orrP a b : or_spec b a b (a || b). Proof. rewrite orbC;apply orlP. Qed. (* -------------------------------------------------------------------- *) Delimit Scope assn with A. Definition predImpl {T} (P Q:pred T) := [pred x | P x ==> Q x]. Notation "P /\ Q" := (predI P%A Q%A) : assn. Notation "P \/ Q" := (predU P%A Q%A) : assn. Notation "P ==> Q" := (predImpl P%A Q%A) : assn. Notation "~ P" := (predC P%A) : assn. Definition predP {T : Type} (P : T -> Prop) := [pred x | `[<P x>]]. Notation "`[< P >]" := (predP P) : assn. Definition pswap {A B : Type} (P : pred (A * B)) := [pred m | P (m.2, m.1)].
-- test that a sent thing arrives and is the thing that was sent import System import System.Concurrency.BufferedChannel main : IO () main = do bcRef <- makeBufferedChannel let val = 3 (MkDPair bc send) <- becomeSender bcRef (MkDPair bc' recv) <- becomeReceiver NonBlocking bcRef send Signal bc val sleep 1 -- give the value time to propagate (Just val') <- recv bc' | Nothing => putStrLn "ERROR: Value disappeared from channel." if val /= val' then putStrLn "ERROR: Value changed in transit." else putStrLn "Success!"
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types open import LibraBFT.Impl.OBM.Logging.Logging import LibraBFT.Impl.Types.Ledger2WaypointConverter as Ledger2WaypointConverter open import LibraBFT.ImplShared.Consensus.Types import LibraBFT.ImplShared.Util.Crypto as Crypto open import Optics.All open import Util.Hash open import Util.Prelude module LibraBFT.Impl.Types.Waypoint where newAny : LedgerInfo → Waypoint newAny ledgerInfo = let converter = Ledger2WaypointConverter.new ledgerInfo in Waypoint∙new (ledgerInfo ^∙ liVersion) (Crypto.hashL2WC converter) newEpochBoundary : LedgerInfo → Either ErrLog Waypoint newEpochBoundary ledgerInfo = if ledgerInfo ^∙ liEndsEpoch then pure (newAny ledgerInfo) else Left fakeErr -- ["newEpochBoundary", "no validator set"] verify : Waypoint → LedgerInfo → Either ErrLog Unit verify self ledgerInfo = do lcheck (self ^∙ wVersion == ledgerInfo ^∙ liVersion) ("Waypoint" ∷ "version mismatch" ∷ []) --show (self^.wVersion), show (ledgerInfo^.liVersion)] let converter = Ledger2WaypointConverter.new ledgerInfo lcheck (self ^∙ wValue == Crypto.hashL2WC converter) ("Waypoint" ∷ "value mismatch" ∷ []) --show (self^.wValue), show (Crypto.hashL2WC converter)] pure unit epochChangeVerificationRequired : Waypoint → Epoch → Bool epochChangeVerificationRequired _self _epoch = true isLedgerInfoStale : Waypoint → LedgerInfo → Bool isLedgerInfoStale self ledgerInfo = ⌊ (ledgerInfo ^∙ liVersion) <?-Version (self ^∙ wVersion) ⌋ verifierVerify : Waypoint → LedgerInfoWithSignatures → Either ErrLog Unit verifierVerify self liws = verify self (liws ^∙ liwsLedgerInfo)
[STATEMENT] lemma var_imp_symvar_var : assumes "v \<in> Aexp.vars e" shows "symvar v s \<in> Aexp.vars (adapt_aexp e s)" (is "?sv \<in> Aexp.vars ?e'") [PROOF STATE] proof (prove) goal (1 subgoal): 1. symvar v s \<in> Aexp.vars (adapt_aexp e s) [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. symvar v s \<in> Aexp.vars (adapt_aexp e s) [PROOF STEP] obtain \<sigma> val where "e (\<sigma> (v := val)) \<noteq> e \<sigma>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<And>\<sigma> val. e (\<sigma>(v := val)) \<noteq> e \<sigma> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: v \<in> Aexp.vars e goal (1 subgoal): 1. (\<And>\<sigma> val. e (\<sigma>(v := val)) \<noteq> e \<sigma> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] unfolding Aexp.vars_def [PROOF STATE] proof (prove) using this: v \<in> {v. \<exists>\<sigma> val. e (\<sigma>(v := val)) \<noteq> e \<sigma>} goal (1 subgoal): 1. (\<And>\<sigma> val. e (\<sigma>(v := val)) \<noteq> e \<sigma> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by blast [PROOF STATE] proof (state) this: e (\<sigma>(v := val)) \<noteq> e \<sigma> goal (1 subgoal): 1. symvar v s \<in> Aexp.vars (adapt_aexp e s) [PROOF STEP] moreover [PROOF STATE] proof (state) this: e (\<sigma>(v := val)) \<noteq> e \<sigma> goal (1 subgoal): 1. symvar v s \<in> Aexp.vars (adapt_aexp e s) [PROOF STEP] have "(\<lambda>va. ((\<lambda>sv. \<sigma> (fst sv))(?sv := val)) (symvar va s)) = (\<sigma>(v := val))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<lambda>va. ((\<lambda>sv. \<sigma> (fst sv))(symvar v s := val)) (symvar va s)) = \<sigma>(v := val) [PROOF STEP] by (auto simp add : symvar_def) [PROOF STATE] proof (state) this: (\<lambda>va. ((\<lambda>sv. \<sigma> (fst sv))(symvar v s := val)) (symvar va s)) = \<sigma>(v := val) goal (1 subgoal): 1. symvar v s \<in> Aexp.vars (adapt_aexp e s) [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: e (\<sigma>(v := val)) \<noteq> e \<sigma> (\<lambda>va. ((\<lambda>sv. \<sigma> (fst sv))(symvar v s := val)) (symvar va s)) = \<sigma>(v := val) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: e (\<sigma>(v := val)) \<noteq> e \<sigma> (\<lambda>va. ((\<lambda>sv. \<sigma> (fst sv))(symvar v s := val)) (symvar va s)) = \<sigma>(v := val) goal (1 subgoal): 1. symvar v s \<in> Aexp.vars (adapt_aexp e s) [PROOF STEP] unfolding Aexp.vars_def mem_Collect_eq [PROOF STATE] proof (prove) using this: e (\<sigma>(v := val)) \<noteq> e \<sigma> (\<lambda>va. ((\<lambda>sv. \<sigma> (fst sv))(symvar v s := val)) (symvar va s)) = \<sigma>(v := val) goal (1 subgoal): 1. \<exists>\<sigma> val. adapt_aexp e s (\<sigma>(symvar v s := val)) \<noteq> adapt_aexp e s \<sigma> [PROOF STEP] using consistentI1[of \<sigma> s] consistentI2[of "(\<lambda>sv. \<sigma> (fst sv))(?sv:= val)" s] [PROOF STATE] proof (prove) using this: e (\<sigma>(v := val)) \<noteq> e \<sigma> (\<lambda>va. ((\<lambda>sv. \<sigma> (fst sv))(symvar v s := val)) (symvar va s)) = \<sigma>(v := val) consistent \<sigma> (\<lambda>sv. \<sigma> (fst sv)) s consistent (\<lambda>va. ((\<lambda>sv. \<sigma> (fst sv))(symvar v s := val)) (symvar va s)) ((\<lambda>sv. \<sigma> (fst sv))(symvar v s := val)) s goal (1 subgoal): 1. \<exists>\<sigma> val. adapt_aexp e s (\<sigma>(symvar v s := val)) \<noteq> adapt_aexp e s \<sigma> [PROOF STEP] by (rule_tac ?x="\<lambda>sv. \<sigma> (fst sv)" in exI, rule_tac ?x="val" in exI) (simp add : adapt_aexp_is_subst) [PROOF STATE] proof (state) this: symvar v s \<in> Aexp.vars (adapt_aexp e s) goal: No subgoals! [PROOF STEP] qed
[STATEMENT] lemma wf_less_multiset: "wf {(M :: 'a multiset, N). M < N}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. wf {(M, N). M < N} [PROOF STEP] unfolding less_multiset_def multp_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. wf {(M, N). (M, N) \<in> mult {(x, y). x < y}} [PROOF STEP] by (auto intro: wf_mult wf)
First Visit – Please arrive 15 minutes early to complete the initial intake forms. Alternately, you may download our initial intake form and health information form and complete the forms prior to your first visit. When you meet with me for the first time, you will typically spend about an hour and a half together. The first hour will be spent discussing your current and past medical history, which is then followed by a pertinent physical exam and discussion about possible diagnostics and treatment options, if necessary. We will then decide on a comprehensive treatment plan and I will make recommendations for follow-up. Follow-Up Visits – The follow-up visits typically last 45 minutes, and involves an assessment of how effectively the treatment plan is working. We will also review any diagnostic results that may have been ordered during the previous visit. Any necessary adjustments will be made to the treatment program at this time, and we will continue to remove any obstacles to your cure that may be present. In addition, a thorough physical exam may be performed to aid in the prevention of future health problems. Payment Policies – Payment is due in full at the time of service. Patients who are covered by Anthem Blue Cross/Blue Shield, Oxford, Cigna, and Connecticare health insurance plans may owe a co-pay or co-insurance amount for the visit. Patients covered by other health insurance plans will be provided with the appropriate documentation to self-file with their insurance company.
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Maybe where open import Cubical.Data.Maybe.Base public open import Cubical.Data.Maybe.Properties public
[STATEMENT] lemma msog_append: "ms_of_greek (xs @ ys) = image_mset (adj_msog [] ys) (ms_of_greek xs) + image_mset (adj_msog xs []) (ms_of_greek ys)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. ms_of_greek (xs @ ys) = image_mset (adj_msog [] ys) (ms_of_greek xs) + image_mset (adj_msog xs []) (ms_of_greek ys) [PROOF STEP] by (auto simp: ms_of_greek_def list_splits_append multiset.map_comp comp_def prod.case_distrib)
bottom.contact.incremental = function( sm, bcp=bcp ) { ## Algorithm: this is essentially a faster discrete version of the "smooth method" ## .. using an equally spaced x-interval, determine locations where change in slope is maximal stop( "Not working well enough for full time use") if(0) { load("~/aegis/data/nets/Scanmar/bottom.contact/results/bc.NED2014102.8.rdata") sm =data.frame( Z=bc$Z) sm$timestamp=bc$timestamp sm$ts=bc$ts good = bc$good sm$Z[ !good] = NA } res = c(NA, NA) # use only the subset with data for this step names( sm) = c("Z", "timestamp", "ts" ) # Z is used to abstract the variable name such that any variable can be passed N = nrow(sm) if ( N < 50 ) return(res) # insufficient data # interpolate missing data sm$Z.cleaned = interpolate.xy.robust( sm[, c("ts", "Z")], method="sequential.linear" , probs=bcp$incremental.quants ) sm$slope = NA sm$rsq = NA # n.target = n.target # nrequired to enter into a linear regression model dta = -bcp$incremental.windowsize:bcp$incremental.windowsize for ( i in (bcp$incremental.windowsize+1):(N-bcp$incremental.windowsize) ) { j = i+dta lmres = lm( Z.cleaned ~ ts, data=sm[j,], na.action="na.omit" ) # sm$rsq[i] = Rsquared(lmres) sm$slope[i] = coefficients(lmres)["ts"] } sm$slope.cleaned = interpolate.xy.robust( sm[, c("ts", "slope")], method="sequential.linear" , probs=bcp$incremental.quants ) slope.imax = which.max( sm$slope ) # descent has a positive slope start search from maximal slope slope.imin = which.min( sm$slope ) # ascending limb has a negative slope .. start search from min slope slope.mid = trunc( (slope.imin + slope.imax) /2 ) slope.modes = modes( sm$slope ) # sm$slope.smoothed = interpolate.xy.robust( sm[, c("ts", "slope")], method="inla" ) if ( !is.finite(slope.modes$sd ) || slope.modes$sd < 1e-3) { return(res) } i0 = slope.imax for (i0 in slope.imax:slope.mid) { if (sm$slope[i0] < slope.modes$ub2 ) break() } i1 = slope.imin for (i1 in slope.imin:slope.mid) { if (sm$slope[i1] > slope.modes$lb2 ) break() } res = c( sm$timestamp[i0], sm$timestamp[i1] ) if (0) { plot(Z~ts,sm, pch=".") points(Z.cleaned~ts,sm, col="red", pch=20) abline( v=sm$ts[ c(i0, i1) ], col="blue" ) plot.new() plot(slope~ts, sm, pch=20, col="green" ) abline( h=slope.modes, col="red" ) abline( v=sm$ts[ c(i0, i1) ], col="blue" ) } sm$slope.smoothed = interpolate.xy.robust( sm[, c("ts", "slope.cleaned")], method="inla" , probs=bcp$incremental.quants, target.r2=0.9 ) return(res) }
[STATEMENT] lemma integral_has_vector_derivative': fixes f :: "real \<Rightarrow> 'a::banach" assumes "finite s" "f integrable_on {a..b}" "x \<in> {a..b} - s" "continuous (at x within {a..b} - s) f" shows "((\<lambda>u. integral {a .. u} f) has_vector_derivative f(x)) (at x within {a .. b} - s)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. ((\<lambda>u. integral {a..u} f) has_vector_derivative f x) (at x within {a..b} - s) [PROOF STEP] apply (rule integral_has_vector_derivative_continuous_at') [PROOF STATE] proof (prove) goal (4 subgoals): 1. finite s 2. f integrable_on {a..b} 3. x \<in> {a..b} - s 4. continuous (at x within {a..b} - s) f [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: finite s f integrable_on {a..b} x \<in> {a..b} - s continuous (at x within {a..b} - s) f goal (4 subgoals): 1. finite s 2. f integrable_on {a..b} 3. x \<in> {a..b} - s 4. continuous (at x within {a..b} - s) f [PROOF STEP] apply (auto simp: continuous_on_eq_continuous_within) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
#pragma once #include <iostream> #include <fstream> #include <dirent.h> #include <Eigen/Geometry> #include <yaml-cpp/yaml.h> #include <pcl/visualization/cloud_viewer.h> #include <opencv2/opencv.hpp> #include "semanticConf.hpp" #include "types.hpp" class genData { private: CloudLPtr getLCloud(std::string file_cloud, std::string file_label); CloudLPtr getCloud(); std::vector<std::string> listDir(std::string path, std::string end); std::vector<std::string> split(const std::string& str, const std::string& delim); std::string cloud_path,label_path; std::vector<std::string> label_filenames; std::shared_ptr<semConf> semconf; std::shared_ptr<pcl::visualization::CloudViewer> viewer; int data_id=0; public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW int totaldata = 0; genData(std::string cloud_path,std::string label_path,std::shared_ptr<semConf> semconf); bool getData(CloudLPtr &cloud); ~genData()=default; };
import numpy as np def _region_from_args(args): if isinstance(args[0], tuple): return args[0] elif isinstance(args[0], dict): return _region_from_kwargs(args[0]) else: return args def _region_from_kwargs(kwargs): if "region" in kwargs: return kwargs["region"] x = -1 y = -1 w = -1 h = -1 if "x" in kwargs: x = kwargs["x"] elif "left" in kwargs: x = kwargs["left"] if "y" in kwargs: y = kwargs["y"] elif "top" in kwargs: y = kwargs["top"] if "w" in kwargs: w = kwargs["w"] elif "width" in kwargs: w = kwargs["width"] elif "right" in kwargs: w = kwargs["right"] - x if "h" in kwargs: h = kwargs["h"] elif "height" in kwargs: h = kwargs["height"] elif "bottom" in kwargs: h = kwargs["bottom"] - y assert(x >= 0) assert(y >= 0) assert(w >= 0) assert(h >= 0) return (x, y, w, h) class Region: def __init__(self, *args, **kwargs): if len(args) > 0: self.region = _region_from_args(args) else: self.region = _region_from_kwargs(kwargs) self.x = self.left = self.region[0] self.y = self.top = self.region[1] self.w = self.width = self.region[2] self.h = self.height = self.region[3] self.right = self.left + self.width self.bottom = self.top + self.height def within(self, x, y): return ( x >= self.x and y >= self.y and x < self.x + self.width and y < self.y + self.height ) def distance(self, other): return np.linalg.norm(other.position() - self.position()) def position(self): return np.array([self.x, self.y]) def __iter__(self): return iter(self.region) def __truediv__(self, other): return Region( int(self.x / other), int(self.y / other), int(self.w / other), int(self.h / other) )
[GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : IsROrC 𝕜 inst✝ : NormedAddCommGroup E c : InnerProductSpace 𝕜 E x : E ⊢ 0 ≤ ↑re (inner x x) [PROOFSTEP] rw [← InnerProductSpace.norm_sq_eq_inner] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : IsROrC 𝕜 inst✝ : NormedAddCommGroup E c : InnerProductSpace 𝕜 E x : E ⊢ 0 ≤ ‖x‖ ^ 2 [PROOFSTEP] apply sq_nonneg [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : IsROrC 𝕜 inst✝ : NormedAddCommGroup E c : InnerProductSpace 𝕜 E x : E hx : inner x x = 0 ⊢ ‖x‖ ^ 2 = 0 [PROOFSTEP] rw [InnerProductSpace.norm_sq_eq_inner (𝕜 := 𝕜) x, hx, map_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑im (inner x x) = 0 [PROOFSTEP] rw [← @ofReal_inj 𝕜, im_eq_conj_sub] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ I * (↑(starRingEnd 𝕜) (inner x x) - inner x x) / 2 = ↑0 [PROOFSTEP] simp [inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y z : F ⊢ inner x (y + z) = inner x y + inner x z [PROOFSTEP] rw [← inner_conj_symm, inner_add_left, RingHom.map_add] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y z : F ⊢ ↑(starRingEnd 𝕜) (inner y x) + ↑(starRingEnd 𝕜) (inner z x) = inner x y + inner x z [PROOFSTEP] simp only [inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑(normSq x) = inner x x [PROOFSTEP] rw [ext_iff] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑re ↑(normSq x) = ↑re (inner x x) ∧ ↑im ↑(normSq x) = ↑im (inner x x) [PROOFSTEP] exact ⟨by simp only [ofReal_re]; rfl, by simp only [inner_self_im, ofReal_im]⟩ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑re ↑(normSq x) = ↑re (inner x x) [PROOFSTEP] simp only [ofReal_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ normSq x = ↑re (inner x x) [PROOFSTEP] rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑im ↑(normSq x) = ↑im (inner x x) [PROOFSTEP] simp only [inner_self_im, ofReal_im] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑re (inner x y) = ↑re (inner y x) [PROOFSTEP] rw [← inner_conj_symm, conj_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑im (inner x y) = -↑im (inner y x) [PROOFSTEP] rw [← inner_conj_symm, conj_im] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F r : 𝕜 ⊢ inner x (r • y) = r * inner x y [PROOFSTEP] rw [← inner_conj_symm, inner_smul_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F r : 𝕜 ⊢ ↑(starRingEnd 𝕜) (↑(starRingEnd 𝕜) r * inner y x) = r * inner x y [PROOFSTEP] simp only [conj_conj, inner_conj_symm, RingHom.map_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ inner 0 x = 0 [PROOFSTEP] rw [← zero_smul 𝕜 (0 : F), inner_smul_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑(starRingEnd 𝕜) 0 * inner 0 x = 0 [PROOFSTEP] simp only [zero_mul, RingHom.map_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ inner x 0 = 0 [PROOFSTEP] rw [← inner_conj_symm, inner_zero_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑(starRingEnd 𝕜) 0 = 0 [PROOFSTEP] simp only [RingHom.map_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ x = 0 → inner x x = 0 [PROOFSTEP] rintro rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F ⊢ inner 0 0 = 0 [PROOFSTEP] exact inner_zero_left _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ normSq x = 0 ↔ inner x x = 0 [PROOFSTEP] simp only [normSq, ext_iff, map_zero, inner_self_im, eq_self_iff_true, and_true_iff] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑(↑re (inner x x)) = inner x x [PROOFSTEP] rw [ext_iff, inner_self_im] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑re ↑(↑re (inner x x)) = ↑re (inner x x) ∧ ↑im ↑(↑re (inner x x)) = 0 [PROOFSTEP] norm_num [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ‖inner x y‖ = ‖inner y x‖ [PROOFSTEP] rw [← inner_conj_symm, norm_conj] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ inner (-x) y = -inner x y [PROOFSTEP] rw [← neg_one_smul 𝕜 x, inner_smul_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑(starRingEnd 𝕜) (-1) * inner x y = -inner x y [PROOFSTEP] simp [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ inner x (-y) = -inner x y [PROOFSTEP] rw [← inner_conj_symm, inner_neg_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑(starRingEnd 𝕜) (-inner y x) = -inner x y [PROOFSTEP] simp only [RingHom.map_neg, inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y z : F ⊢ inner (x - y) z = inner x z - inner y z [PROOFSTEP] simp [sub_eq_add_neg, inner_add_left, inner_neg_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y z : F ⊢ inner x (y - z) = inner x y - inner x z [PROOFSTEP] simp [sub_eq_add_neg, inner_add_right, inner_neg_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑re (inner x y * inner y x) = ‖inner x y * inner y x‖ [PROOFSTEP] rw [← inner_conj_symm, mul_comm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑re (inner y x * ↑(starRingEnd 𝕜) (inner y x)) = ‖inner y x * ↑(starRingEnd 𝕜) (inner y x)‖ [PROOFSTEP] exact re_eq_norm_of_mul_conj (inner y x) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ inner (x + y) (x + y) = inner x x + inner x y + inner y x + inner y y [PROOFSTEP] simp only [inner_add_left, inner_add_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ inner x x + inner y x + (inner x y + inner y y) = inner x x + inner x y + inner y x + inner y y [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ inner (x - y) (x - y) = inner x x - inner x y - inner y x + inner y y [PROOFSTEP] simp only [inner_sub_left, inner_sub_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ inner x x - inner y x - (inner x y - inner y y) = inner x x - inner x y - inner y x + inner y y [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ normSq (inner x y • x - inner x x • y) = normSq x * (normSq x * normSq y - ‖inner x y‖ ^ 2) [PROOFSTEP] rw [← @ofReal_inj 𝕜, ofReal_normSq_eq_inner_self] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ inner (inner x y • x - inner x x • y) (inner x y • x - inner x x • y) = ↑(normSq x * (normSq x * normSq y - ‖inner x y‖ ^ 2)) [PROOFSTEP] simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, conj_ofReal, mul_sub, ← ofReal_normSq_eq_inner_self x, ← ofReal_normSq_eq_inner_self y] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ inner x y * (↑(starRingEnd 𝕜) (inner x y) * ↑(normSq x)) - ↑(normSq x) * (↑(starRingEnd 𝕜) (inner x y) * inner x y) - inner x y * (↑(normSq x) * inner y x) + ↑(normSq x) * (↑(normSq x) * ↑(normSq y)) = ↑(normSq x * (normSq x * normSq y) - normSq x * ‖inner x y‖ ^ 2) [PROOFSTEP] rw [← mul_assoc, mul_conj, IsROrC.conj_mul, normSq_eq_def', mul_left_comm, ← inner_conj_symm y, mul_conj, normSq_eq_def'] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑(‖inner x y‖ ^ 2) * ↑(normSq x) - ↑(normSq x) * ↑(‖inner x y‖ ^ 2) - ↑(normSq x) * ↑(‖inner x y‖ ^ 2) + ↑(normSq x) * (↑(normSq x) * ↑(normSq y)) = ↑(normSq x * (normSq x * normSq y) - normSq x * ‖inner x y‖ ^ 2) [PROOFSTEP] push_cast [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑‖inner x y‖ ^ 2 * ↑(normSq x) - ↑(normSq x) * ↑‖inner x y‖ ^ 2 - ↑(normSq x) * ↑‖inner x y‖ ^ 2 + ↑(normSq x) * (↑(normSq x) * ↑(normSq y)) = ↑(normSq x) * (↑(normSq x) * ↑(normSq y)) - ↑(normSq x) * ↑‖inner x y‖ ^ 2 [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ‖inner x y‖ * ‖inner y x‖ ≤ ↑re (inner x x) * ↑re (inner y y) [PROOFSTEP] rcases eq_or_ne x 0 with (rfl | hx) [GOAL] case inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F y : F ⊢ ‖inner 0 y‖ * ‖inner y 0‖ ≤ ↑re (inner 0 0) * ↑re (inner y y) [PROOFSTEP] simpa only [inner_zero_left, map_zero, zero_mul, norm_zero] using le_rfl [GOAL] case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F hx : x ≠ 0 ⊢ ‖inner x y‖ * ‖inner y x‖ ≤ ↑re (inner x x) * ↑re (inner y y) [PROOFSTEP] have hx' : 0 < normSqF x := inner_self_nonneg.lt_of_ne' (mt normSq_eq_zero.1 hx) [GOAL] case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F hx : x ≠ 0 hx' : 0 < normSq x ⊢ ‖inner x y‖ * ‖inner y x‖ ≤ ↑re (inner x x) * ↑re (inner y y) [PROOFSTEP] rw [← sub_nonneg, ← mul_nonneg_iff_right_nonneg_of_pos hx', ← normSq, ← normSq, norm_inner_symm y, ← sq, ← cauchy_schwarz_aux] [GOAL] case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F hx : x ≠ 0 hx' : 0 < normSq x ⊢ 0 ≤ normSq (inner x y • x - inner x x • y) [PROOFSTEP] exact inner_self_nonneg [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ ↑re (inner x x) = ‖x‖ * ‖x‖ [PROOFSTEP] rw [norm_eq_sqrt_inner, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ‖inner x y‖ * ‖inner x y‖ = ‖inner x y‖ * ‖inner y x‖ [PROOFSTEP] rw [norm_inner_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ↑re (inner x x) * ↑re (inner y y) = ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) [PROOFSTEP] simp only [inner_self_eq_norm_mul_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ ‖x‖ * ‖x‖ * (‖y‖ * ‖y‖) = ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F ⊢ (fun x => sqrt (↑re (inner x x))) 0 = 0 [PROOFSTEP] simp only [sqrt_zero, inner_zero_right, map_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F ⊢ (fun x => sqrt (↑re (inner x x))) (x + y) ≤ (fun x => sqrt (↑re (inner x x))) x + (fun x => sqrt (↑re (inner x x))) y [PROOFSTEP] have h₁ : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := norm_inner_le_norm _ _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F h₁ : ‖inner x y‖ ≤ ‖x‖ * ‖y‖ ⊢ (fun x => sqrt (↑re (inner x x))) (x + y) ≤ (fun x => sqrt (↑re (inner x x))) x + (fun x => sqrt (↑re (inner x x))) y [PROOFSTEP] have h₂ : re ⟪x, y⟫ ≤ ‖⟪x, y⟫‖ := re_le_norm _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F h₁ : ‖inner x y‖ ≤ ‖x‖ * ‖y‖ h₂ : ↑re (inner x y) ≤ ‖inner x y‖ ⊢ (fun x => sqrt (↑re (inner x x))) (x + y) ≤ (fun x => sqrt (↑re (inner x x))) x + (fun x => sqrt (↑re (inner x x))) y [PROOFSTEP] have h₃ : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := h₂.trans h₁ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F h₁ : ‖inner x y‖ ≤ ‖x‖ * ‖y‖ h₂ : ↑re (inner x y) ≤ ‖inner x y‖ h₃ : ↑re (inner x y) ≤ ‖x‖ * ‖y‖ ⊢ (fun x => sqrt (↑re (inner x x))) (x + y) ≤ (fun x => sqrt (↑re (inner x x))) x + (fun x => sqrt (↑re (inner x x))) y [PROOFSTEP] have h₄ : re ⟪y, x⟫ ≤ ‖x‖ * ‖y‖ := by rwa [← inner_conj_symm, conj_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F h₁ : ‖inner x y‖ ≤ ‖x‖ * ‖y‖ h₂ : ↑re (inner x y) ≤ ‖inner x y‖ h₃ : ↑re (inner x y) ≤ ‖x‖ * ‖y‖ ⊢ ↑re (inner y x) ≤ ‖x‖ * ‖y‖ [PROOFSTEP] rwa [← inner_conj_symm, conj_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F h₁ : ‖inner x y‖ ≤ ‖x‖ * ‖y‖ h₂ : ↑re (inner x y) ≤ ‖inner x y‖ h₃ : ↑re (inner x y) ≤ ‖x‖ * ‖y‖ h₄ : ↑re (inner y x) ≤ ‖x‖ * ‖y‖ ⊢ (fun x => sqrt (↑re (inner x x))) (x + y) ≤ (fun x => sqrt (↑re (inner x x))) x + (fun x => sqrt (↑re (inner x x))) y [PROOFSTEP] have : ‖x + y‖ * ‖x + y‖ ≤ (‖x‖ + ‖y‖) * (‖x‖ + ‖y‖) := by simp only [← inner_self_eq_norm_mul_norm, inner_add_add_self, mul_add, mul_comm, map_add] linarith [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F h₁ : ‖inner x y‖ ≤ ‖x‖ * ‖y‖ h₂ : ↑re (inner x y) ≤ ‖inner x y‖ h₃ : ↑re (inner x y) ≤ ‖x‖ * ‖y‖ h₄ : ↑re (inner y x) ≤ ‖x‖ * ‖y‖ ⊢ ‖x + y‖ * ‖x + y‖ ≤ (‖x‖ + ‖y‖) * (‖x‖ + ‖y‖) [PROOFSTEP] simp only [← inner_self_eq_norm_mul_norm, inner_add_add_self, mul_add, mul_comm, map_add] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F h₁ : ‖inner x y‖ ≤ ‖x‖ * ‖y‖ h₂ : ↑re (inner x y) ≤ ‖inner x y‖ h₃ : ↑re (inner x y) ≤ ‖x‖ * ‖y‖ h₄ : ↑re (inner y x) ≤ ‖x‖ * ‖y‖ ⊢ ↑re (inner x x) + ↑re (inner x y) + ↑re (inner y x) + ↑re (inner y y) ≤ ↑re (inner x x) + ‖x‖ * ‖y‖ + (‖x‖ * ‖y‖ + ↑re (inner y y)) [PROOFSTEP] linarith [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x y : F h₁ : ‖inner x y‖ ≤ ‖x‖ * ‖y‖ h₂ : ↑re (inner x y) ≤ ‖inner x y‖ h₃ : ↑re (inner x y) ≤ ‖x‖ * ‖y‖ h₄ : ↑re (inner y x) ≤ ‖x‖ * ‖y‖ this : ‖x + y‖ * ‖x + y‖ ≤ (‖x‖ + ‖y‖) * (‖x‖ + ‖y‖) ⊢ (fun x => sqrt (↑re (inner x x))) (x + y) ≤ (fun x => sqrt (↑re (inner x x))) x + (fun x => sqrt (↑re (inner x x))) y [PROOFSTEP] exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F x : F ⊢ (fun x => sqrt (↑re (inner x x))) (-x) = (fun x => sqrt (↑re (inner x x))) x [PROOFSTEP] simp only [inner_neg_left, neg_neg, inner_neg_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F r : 𝕜 x : F ⊢ ‖r • x‖ ≤ ‖r‖ * ‖x‖ [PROOFSTEP] rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, ← mul_assoc] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F r : 𝕜 x : F ⊢ sqrt (↑re (↑(starRingEnd 𝕜) r * r * inner x x)) ≤ ‖r‖ * ‖x‖ [PROOFSTEP] rw [IsROrC.conj_mul, ofReal_mul_re, sqrt_mul, ← ofReal_normSq_eq_inner_self, ofReal_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F r : 𝕜 x : F ⊢ sqrt (↑IsROrC.normSq r) * sqrt (normSq x) ≤ ‖r‖ * ‖x‖ [PROOFSTEP] simp [sqrt_normSq_eq_norm, IsROrC.sqrt_normSq_eq_norm] [GOAL] case hx 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F r : 𝕜 x : F ⊢ 0 ≤ ↑IsROrC.normSq r [PROOFSTEP] exact normSq_nonneg r [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F this : NormedSpace 𝕜 F := Core.toNormedSpace x : F ⊢ ‖x‖ ^ 2 = ↑re (inner x x) [PROOFSTEP] have h₁ : ‖x‖ ^ 2 = sqrt (re (c.inner x x)) ^ 2 := rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F this : NormedSpace 𝕜 F := Core.toNormedSpace x : F h₁ : ‖x‖ ^ 2 = sqrt (↑re (inner x x)) ^ 2 ⊢ ‖x‖ ^ 2 = ↑re (inner x x) [PROOFSTEP] have h₂ : 0 ≤ re (c.inner x x) := InnerProductSpace.Core.inner_self_nonneg [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝² : IsROrC 𝕜 inst✝¹ : AddCommGroup F inst✝ : Module 𝕜 F c : Core 𝕜 F this : NormedSpace 𝕜 F := Core.toNormedSpace x : F h₁ : ‖x‖ ^ 2 = sqrt (↑re (inner x x)) ^ 2 h₂ : 0 ≤ ↑re (inner x x) ⊢ ‖x‖ ^ 2 = ↑re (inner x x) [PROOFSTEP] simp [h₁, sq_sqrt, h₂] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner x y = 0 ↔ inner y x = 0 [PROOFSTEP] rw [← inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑(starRingEnd 𝕜) (inner y x) = 0 ↔ inner y x = 0 [PROOFSTEP] exact star_eq_zero [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑im (inner x x) = 0 [PROOFSTEP] rw [← @ofReal_inj 𝕜, im_eq_conj_sub] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ I * (↑(starRingEnd 𝕜) (inner x x) - inner x x) / 2 = ↑0 [PROOFSTEP] simp [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y z : E ⊢ inner x (y + z) = inner x y + inner x z [PROOFSTEP] rw [← inner_conj_symm, inner_add_left, RingHom.map_add] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y z : E ⊢ ↑(starRingEnd 𝕜) (inner y x) + ↑(starRingEnd 𝕜) (inner z x) = inner x y + inner x z [PROOFSTEP] simp only [inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x y) = ↑re (inner y x) [PROOFSTEP] rw [← inner_conj_symm, conj_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑im (inner x y) = -↑im (inner y x) [PROOFSTEP] rw [← inner_conj_symm, conj_im] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E r : ℝ ⊢ inner (↑r • x) y = r • inner x y [PROOFSTEP] rw [inner_smul_left, conj_ofReal, Algebra.smul_def] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E r : ℝ ⊢ ↑r * inner x y = ↑(algebraMap ℝ 𝕜) r * inner x y [PROOFSTEP] rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E r : 𝕜 ⊢ inner x (r • y) = r * inner x y [PROOFSTEP] rw [← inner_conj_symm, inner_smul_left, RingHom.map_mul, conj_conj, inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E r : ℝ ⊢ inner x (↑r • y) = r • inner x y [PROOFSTEP] rw [inner_smul_right, Algebra.smul_def] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E r : ℝ ⊢ ↑r * inner x y = ↑(algebraMap ℝ 𝕜) r * inner x y [PROOFSTEP] rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 l : ι →₀ 𝕜 v : ι → E x : E ⊢ inner (sum l fun i a => a • v i) x = sum l fun i a => ↑(starRingEnd 𝕜) a • inner (v i) x [PROOFSTEP] convert _root_.sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 l : ι →₀ 𝕜 v : ι → E x : E ⊢ (sum l fun i a => ↑(starRingEnd 𝕜) a • inner (v i) x) = ∑ i in l.support, inner (↑l i • v i) x [PROOFSTEP] simp only [inner_smul_left, Finsupp.sum, smul_eq_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 l : ι →₀ 𝕜 v : ι → E x : E ⊢ inner x (sum l fun i a => a • v i) = sum l fun i a => a • inner x (v i) [PROOFSTEP] convert _root_.inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 l : ι →₀ 𝕜 v : ι → E x : E ⊢ (sum l fun i a => a • inner x (v i)) = ∑ i in l.support, inner x (↑l i • v i) [PROOFSTEP] simp only [inner_smul_right, Finsupp.sum, smul_eq_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec : DecidableEq ι α : ι → Type u_5 inst✝¹ : (i : ι) → AddZeroClass (α i) inst✝ : (i : ι) → (x : α i) → Decidable (x ≠ 0) f : (i : ι) → α i → E l : Π₀ (i : ι), α i x : E ⊢ inner (sum l f) x = sum l fun i a => inner (f i a) x [PROOFSTEP] simp (config := { contextual := true }) only [DFinsupp.sum, _root_.sum_inner, smul_eq_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec : DecidableEq ι α : ι → Type u_5 inst✝¹ : (i : ι) → AddZeroClass (α i) inst✝ : (i : ι) → (x : α i) → Decidable (x ≠ 0) f : (i : ι) → α i → E l : Π₀ (i : ι), α i x : E ⊢ inner x (sum l f) = sum l fun i a => inner x (f i a) [PROOFSTEP] simp (config := { contextual := true }) only [DFinsupp.sum, _root_.inner_sum, smul_eq_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ inner 0 x = 0 [PROOFSTEP] rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑re (inner 0 x) = 0 [PROOFSTEP] simp only [inner_zero_left, AddMonoidHom.map_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ inner x 0 = 0 [PROOFSTEP] rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑re (inner x 0) = 0 [PROOFSTEP] simp only [inner_zero_right, AddMonoidHom.map_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ inner x x = ↑‖x‖ ^ 2 [PROOFSTEP] rw [← inner_self_ofReal_re, ← norm_sq_eq_inner, ofReal_pow] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑re (inner x x) = ‖inner x x‖ [PROOFSTEP] conv_rhs => rw [← inner_self_ofReal_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E | ‖inner x x‖ [PROOFSTEP] rw [← inner_self_ofReal_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E | ‖inner x x‖ [PROOFSTEP] rw [← inner_self_ofReal_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E | ‖inner x x‖ [PROOFSTEP] rw [← inner_self_ofReal_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑re (inner x x) = ‖↑(↑re (inner x x))‖ [PROOFSTEP] symm [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ‖↑(↑re (inner x x))‖ = ↑re (inner x x) [PROOFSTEP] exact norm_of_nonneg inner_self_nonneg [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑‖inner x x‖ = inner x x [PROOFSTEP] rw [← inner_self_re_eq_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑(↑re (inner x x)) = inner x x [PROOFSTEP] exact inner_self_ofReal_re _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ inner x x = 0 ↔ x = 0 [PROOFSTEP] rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑re (inner x x) ≤ 0 ↔ x = 0 [PROOFSTEP] rw [← norm_sq_eq_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖inner x y‖ = ‖inner y x‖ [PROOFSTEP] rw [← inner_conj_symm, norm_conj] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner (-x) y = -inner x y [PROOFSTEP] rw [← neg_one_smul 𝕜 x, inner_smul_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑(starRingEnd 𝕜) (-1) * inner x y = -inner x y [PROOFSTEP] simp [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner x (-y) = -inner x y [PROOFSTEP] rw [← inner_conj_symm, inner_neg_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑(starRingEnd 𝕜) (-inner y x) = -inner x y [PROOFSTEP] simp only [RingHom.map_neg, inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner (-x) (-y) = inner x y [PROOFSTEP] simp [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y z : E ⊢ inner (x - y) z = inner x z - inner y z [PROOFSTEP] simp [sub_eq_add_neg, inner_add_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y z : E ⊢ inner x (y - z) = inner x y - inner x z [PROOFSTEP] simp [sub_eq_add_neg, inner_add_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x y * inner y x) = ‖inner x y * inner y x‖ [PROOFSTEP] rw [← inner_conj_symm, mul_comm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner y x * ↑(starRingEnd 𝕜) (inner y x)) = ‖inner y x * ↑(starRingEnd 𝕜) (inner y x)‖ [PROOFSTEP] exact re_eq_norm_of_mul_conj (inner y x) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner (x + y) (x + y) = inner x x + inner x y + inner y x + inner y y [PROOFSTEP] simp only [inner_add_left, inner_add_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner x x + inner y x + (inner x y + inner y y) = inner x x + inner x y + inner y x + inner y y [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner (x + y) (x + y) = inner x x + 2 * inner x y + inner y y [PROOFSTEP] have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner y x = inner x y [PROOFSTEP] rw [← inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ↑(starRingEnd ℝ) (inner x y) = inner x y [PROOFSTEP] rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F this : inner y x = inner x y ⊢ inner (x + y) (x + y) = inner x x + 2 * inner x y + inner y y [PROOFSTEP] simp only [inner_add_add_self, this, add_left_inj] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F this : inner y x = inner x y ⊢ inner x x + inner x y + inner x y = inner x x + 2 * inner x y [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner (x - y) (x - y) = inner x x - inner x y - inner y x + inner y y [PROOFSTEP] simp only [inner_sub_left, inner_sub_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner x x - inner y x - (inner x y - inner y y) = inner x x - inner x y - inner y x + inner y y [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner (x - y) (x - y) = inner x x - 2 * inner x y + inner y y [PROOFSTEP] have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner y x = inner x y [PROOFSTEP] rw [← inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ↑(starRingEnd ℝ) (inner x y) = inner x y [PROOFSTEP] rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F this : inner y x = inner x y ⊢ inner (x - y) (x - y) = inner x x - 2 * inner x y + inner y y [PROOFSTEP] simp only [inner_sub_sub_self, this, add_left_inj] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F this : inner y x = inner x y ⊢ inner x x - inner x y - inner x y = inner x x - 2 * inner x y [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ∀ (v : E), inner v x = inner v y ⊢ x = y [PROOFSTEP] rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ∀ (v : E), inner x v = inner y v ⊢ x = y [PROOFSTEP] rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner (x + y) (x + y) + inner (x - y) (x - y) = 2 * (inner x x + inner y y) [PROOFSTEP] simp only [inner_add_add_self, inner_sub_sub_self] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner x x + inner x y + inner y x + inner y y + (inner x x - inner x y - inner y x + inner y y) = 2 * (inner x x + inner y y) [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner x y * inner x y ≤ ‖inner x y‖ * ‖inner y x‖ [PROOFSTEP] rw [real_inner_comm y, ← norm_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner y x * inner y x ≤ ‖inner y x * inner y x‖ [PROOFSTEP] exact le_abs_self _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 ⊢ LinearIndependent 𝕜 v [PROOFSTEP] rw [linearIndependent_iff'] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 ⊢ ∀ (s : Finset ι) (g : ι → 𝕜), ∑ i in s, g i • v i = 0 → ∀ (i : ι), i ∈ s → g i = 0 [PROOFSTEP] intro s g hg i hi [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s ⊢ g i = 0 [PROOFSTEP] have h' : g i * inner (v i) (v i) = inner (v i) (∑ j in s, g j • v j) := by rw [inner_sum] symm convert Finset.sum_eq_single (β := 𝕜) i ?_ ?_ · rw [inner_smul_right] · intro j _hj hji rw [inner_smul_right, ho i j hji.symm, mul_zero] · exact fun h => False.elim (h hi) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s ⊢ g i * inner (v i) (v i) = inner (v i) (∑ j in s, g j • v j) [PROOFSTEP] rw [inner_sum] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s ⊢ g i * inner (v i) (v i) = ∑ i_1 in s, inner (v i) (g i_1 • v i_1) [PROOFSTEP] symm [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s ⊢ ∑ i_1 in s, inner (v i) (g i_1 • v i_1) = g i * inner (v i) (v i) [PROOFSTEP] convert Finset.sum_eq_single (β := 𝕜) i ?_ ?_ [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s ⊢ g i * inner (v i) (v i) = inner (v i) (g i • v i) [PROOFSTEP] rw [inner_smul_right] [GOAL] case convert_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s ⊢ ∀ (b : ι), b ∈ s → b ≠ i → inner (v i) (g b • v b) = 0 [PROOFSTEP] intro j _hj hji [GOAL] case convert_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s j : ι _hj : j ∈ s hji : j ≠ i ⊢ inner (v i) (g j • v j) = 0 [PROOFSTEP] rw [inner_smul_right, ho i j hji.symm, mul_zero] [GOAL] case convert_4 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s ⊢ ¬i ∈ s → inner (v i) (g i • v i) = 0 [PROOFSTEP] exact fun h => False.elim (h hi) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 v : ι → E hz : ∀ (i : ι), v i ≠ 0 ho : ∀ (i j : ι), i ≠ j → inner (v i) (v j) = 0 s : Finset ι g : ι → 𝕜 hg : ∑ i in s, g i • v i = 0 i : ι hi : i ∈ s h' : g i * inner (v i) (v i) = inner (v i) (∑ j in s, g j • v j) ⊢ g i = 0 [PROOFSTEP] simpa [hg, hz] using h' [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E ⊢ Orthonormal 𝕜 v ↔ ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 [PROOFSTEP] constructor [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E ⊢ Orthonormal 𝕜 v → ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 [PROOFSTEP] intro hv i j [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v i j : ι ⊢ inner (v i) (v j) = if i = j then 1 else 0 [PROOFSTEP] split_ifs with h [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v i j : ι h : i = j ⊢ inner (v i) (v j) = 1 [PROOFSTEP] simp [h, inner_self_eq_norm_sq_to_K, hv.1] [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v i j : ι h : ¬i = j ⊢ inner (v i) (v j) = 0 [PROOFSTEP] exact hv.2 h [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E ⊢ (∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0) → Orthonormal 𝕜 v [PROOFSTEP] intro h [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 ⊢ Orthonormal 𝕜 v [PROOFSTEP] constructor [GOAL] case mpr.left 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 ⊢ ∀ (i : ι), ‖v i‖ = 1 [PROOFSTEP] intro i [GOAL] case mpr.left 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i : ι ⊢ ‖v i‖ = 1 [PROOFSTEP] have h' : ‖v i‖ ^ 2 = 1 ^ 2 := by simp [@norm_sq_eq_inner 𝕜, h i i] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i : ι ⊢ ‖v i‖ ^ 2 = 1 ^ 2 [PROOFSTEP] simp [@norm_sq_eq_inner 𝕜, h i i] [GOAL] case mpr.left 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i : ι h' : ‖v i‖ ^ 2 = 1 ^ 2 ⊢ ‖v i‖ = 1 [PROOFSTEP] have h₁ : 0 ≤ ‖v i‖ := norm_nonneg _ [GOAL] case mpr.left 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i : ι h' : ‖v i‖ ^ 2 = 1 ^ 2 h₁ : 0 ≤ ‖v i‖ ⊢ ‖v i‖ = 1 [PROOFSTEP] have h₂ : (0 : ℝ) ≤ 1 := zero_le_one [GOAL] case mpr.left 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i : ι h' : ‖v i‖ ^ 2 = 1 ^ 2 h₁ : 0 ≤ ‖v i‖ h₂ : 0 ≤ 1 ⊢ ‖v i‖ = 1 [PROOFSTEP] rwa [sq_eq_sq h₁ h₂] at h' [GOAL] case mpr.right 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 ⊢ ∀ {i j : ι}, i ≠ j → inner (v i) (v j) = 0 [PROOFSTEP] intro i j hij [GOAL] case mpr.right 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E h : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι hij : i ≠ j ⊢ inner (v i) (v j) = 0 [PROOFSTEP] simpa [hij] using h i j [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E ⊢ Orthonormal 𝕜 Subtype.val ↔ ∀ (v : E), v ∈ s → ∀ (w : E), w ∈ s → inner v w = if v = w then 1 else 0 [PROOFSTEP] rw [orthonormal_iff_ite] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E ⊢ (∀ (i j : { x // x ∈ s }), inner ↑i ↑j = if i = j then 1 else 0) ↔ ∀ (v : E), v ∈ s → ∀ (w : E), w ∈ s → inner v w = if v = w then 1 else 0 [PROOFSTEP] constructor [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E ⊢ (∀ (i j : { x // x ∈ s }), inner ↑i ↑j = if i = j then 1 else 0) → ∀ (v : E), v ∈ s → ∀ (w : E), w ∈ s → inner v w = if v = w then 1 else 0 [PROOFSTEP] intro h v hv w hw [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E h : ∀ (i j : { x // x ∈ s }), inner ↑i ↑j = if i = j then 1 else 0 v : E hv : v ∈ s w : E hw : w ∈ s ⊢ inner v w = if v = w then 1 else 0 [PROOFSTEP] convert h ⟨v, hv⟩ ⟨w, hw⟩ using 1 [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E h : ∀ (i j : { x // x ∈ s }), inner ↑i ↑j = if i = j then 1 else 0 v : E hv : v ∈ s w : E hw : w ∈ s ⊢ (if v = w then 1 else 0) = if { val := v, property := hv } = { val := w, property := hw } then 1 else 0 [PROOFSTEP] simp [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E ⊢ (∀ (v : E), v ∈ s → ∀ (w : E), w ∈ s → inner v w = if v = w then 1 else 0) → ∀ (i j : { x // x ∈ s }), inner ↑i ↑j = if i = j then 1 else 0 [PROOFSTEP] rintro h ⟨v, hv⟩ ⟨w, hw⟩ [GOAL] case mpr.mk.mk 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E h : ∀ (v : E), v ∈ s → ∀ (w : E), w ∈ s → inner v w = if v = w then 1 else 0 v : E hv : v ∈ s w : E hw : w ∈ s ⊢ inner ↑{ val := v, property := hv } ↑{ val := w, property := hw } = if { val := v, property := hv } = { val := w, property := hw } then 1 else 0 [PROOFSTEP] convert h v hv w hw using 1 [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E h : ∀ (v : E), v ∈ s → ∀ (w : E), w ∈ s → inner v w = if v = w then 1 else 0 v : E hv : v ∈ s w : E hw : w ∈ s ⊢ (if { val := v, property := hv } = { val := w, property := hw } then 1 else 0) = if v = w then 1 else 0 [PROOFSTEP] simp [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι →₀ 𝕜 i : ι ⊢ inner (v i) (↑(Finsupp.total ι E 𝕜 v) l) = ↑l i [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι →₀ 𝕜 i : ι em✝ : (a : Prop) → Decidable a ⊢ inner (v i) (↑(Finsupp.total ι E 𝕜 v) l) = ↑l i [PROOFSTEP] simpa [Finsupp.total_apply, Finsupp.inner_sum, orthonormal_iff_ite.mp hv] using Eq.symm [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι → 𝕜 s : Finset ι i : ι hi : i ∈ s ⊢ inner (v i) (∑ i in s, l i • v i) = l i [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι → 𝕜 s : Finset ι i : ι hi : i ∈ s em✝ : (a : Prop) → Decidable a ⊢ inner (v i) (∑ i in s, l i • v i) = l i [PROOFSTEP] simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv, hi] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι →₀ 𝕜 i : ι ⊢ inner (↑(Finsupp.total ι E 𝕜 v) l) (v i) = ↑(starRingEnd ((fun x => 𝕜) i)) (↑l i) [PROOFSTEP] rw [← inner_conj_symm, hv.inner_right_finsupp] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι → 𝕜 s : Finset ι i : ι hi : i ∈ s ⊢ inner (∑ i in s, l i • v i) (v i) = ↑(starRingEnd 𝕜) (l i) [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι → 𝕜 s : Finset ι i : ι hi : i ∈ s em✝ : (a : Prop) → Decidable a ⊢ inner (∑ i in s, l i • v i) (v i) = ↑(starRingEnd 𝕜) (l i) [PROOFSTEP] simp only [sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv, hi, mul_boole, Finset.sum_ite_eq', if_true] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l₁ l₂ : ι →₀ 𝕜 ⊢ inner (↑(Finsupp.total ι E 𝕜 v) l₁) (↑(Finsupp.total ι E 𝕜 v) l₂) = Finsupp.sum l₁ fun i y => ↑(starRingEnd 𝕜) y * ↑l₂ i [PROOFSTEP] simp only [l₁.total_apply _, Finsupp.sum_inner, hv.inner_right_finsupp, smul_eq_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l₁ l₂ : ι →₀ 𝕜 ⊢ inner (↑(Finsupp.total ι E 𝕜 v) l₁) (↑(Finsupp.total ι E 𝕜 v) l₂) = Finsupp.sum l₂ fun i y => ↑(starRingEnd ((fun x => 𝕜) i)) (↑l₁ i) * y [PROOFSTEP] simp only [l₂.total_apply _, Finsupp.inner_sum, hv.inner_left_finsupp, mul_comm, smul_eq_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l₁ l₂ : ι → 𝕜 s : Finset ι ⊢ inner (∑ i in s, l₁ i • v i) (∑ i in s, l₂ i • v i) = ∑ i in s, ↑(starRingEnd 𝕜) (l₁ i) * l₂ i [PROOFSTEP] simp_rw [sum_inner, inner_smul_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l₁ l₂ : ι → 𝕜 s : Finset ι ⊢ ∑ x in s, ↑(starRingEnd 𝕜) (l₁ x) * inner (v x) (∑ i in s, l₂ i • v i) = ∑ x in s, ↑(starRingEnd 𝕜) (l₁ x) * l₂ x [PROOFSTEP] refine' Finset.sum_congr rfl fun i hi => _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l₁ l₂ : ι → 𝕜 s : Finset ι i : ι hi : i ∈ s ⊢ ↑(starRingEnd 𝕜) (l₁ i) * inner (v i) (∑ i in s, l₂ i • v i) = ↑(starRingEnd 𝕜) (l₁ i) * l₂ i [PROOFSTEP] rw [hv.inner_right_sum l₂ hi] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Finset ι v : ι → E hv : Orthonormal 𝕜 v a : ι → ι → 𝕜 ⊢ ∑ i in s, ∑ j in s, a i j • inner (v j) (v i) = ∑ k in s, a k k [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Finset ι v : ι → E hv : Orthonormal 𝕜 v a : ι → ι → 𝕜 em✝ : (a : Prop) → Decidable a ⊢ ∑ i in s, ∑ j in s, a i j • inner (v j) (v i) = ∑ k in s, a k k [PROOFSTEP] simp [orthonormal_iff_ite.mp hv, Finset.sum_ite_of_true] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v ⊢ LinearIndependent 𝕜 v [PROOFSTEP] rw [linearIndependent_iff] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v ⊢ ∀ (l : ι →₀ 𝕜), ↑(Finsupp.total ι E 𝕜 v) l = 0 → l = 0 [PROOFSTEP] intro l hl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι →₀ 𝕜 hl : ↑(Finsupp.total ι E 𝕜 v) l = 0 ⊢ l = 0 [PROOFSTEP] ext i [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι →₀ 𝕜 hl : ↑(Finsupp.total ι E 𝕜 v) l = 0 i : ι ⊢ ↑l i = ↑0 i [PROOFSTEP] have key : ⟪v i, Finsupp.total ι E 𝕜 v l⟫ = ⟪v i, 0⟫ := by rw [hl] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι →₀ 𝕜 hl : ↑(Finsupp.total ι E 𝕜 v) l = 0 i : ι ⊢ inner (v i) (↑(Finsupp.total ι E 𝕜 v) l) = inner (v i) 0 [PROOFSTEP] rw [hl] [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v l : ι →₀ 𝕜 hl : ↑(Finsupp.total ι E 𝕜 v) l = 0 i : ι key : inner (v i) (↑(Finsupp.total ι E 𝕜 v) l) = inner (v i) 0 ⊢ ↑l i = ↑0 i [PROOFSTEP] simpa only [hv.inner_right_finsupp, inner_zero_right] using key [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι ι' : Type u_5 v : ι → E hv : Orthonormal 𝕜 v f : ι' → ι hf : Function.Injective f ⊢ Orthonormal 𝕜 (v ∘ f) [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι ι' : Type u_5 v : ι → E hv : Orthonormal 𝕜 v f : ι' → ι hf : Function.Injective f em✝ : (a : Prop) → Decidable a ⊢ Orthonormal 𝕜 (v ∘ f) [PROOFSTEP] rw [orthonormal_iff_ite] at hv ⊢ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι ι' : Type u_5 v : ι → E f : ι' → ι hf : Function.Injective f em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 ⊢ ∀ (i j : ι'), inner ((v ∘ f) i) ((v ∘ f) j) = if i = j then 1 else 0 [PROOFSTEP] intro i j [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι ι' : Type u_5 v : ι → E f : ι' → ι hf : Function.Injective f em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι' ⊢ inner ((v ∘ f) i) ((v ∘ f) j) = if i = j then 1 else 0 [PROOFSTEP] convert hv (f i) (f j) using 1 [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι ι' : Type u_5 v : ι → E f : ι' → ι hf : Function.Injective f em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι' ⊢ (if i = j then 1 else 0) = if f i = f j then 1 else 0 [PROOFSTEP] simp [hf.eq_iff] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Function.Injective v ⊢ Orthonormal 𝕜 Subtype.val ↔ Orthonormal 𝕜 v [PROOFSTEP] let f : ι ≃ Set.range v := Equiv.ofInjective v hv [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Function.Injective v f : ι ≃ ↑(Set.range v) := Equiv.ofInjective v hv ⊢ Orthonormal 𝕜 Subtype.val ↔ Orthonormal 𝕜 v [PROOFSTEP] refine' ⟨fun h => h.comp f f.injective, fun h => _⟩ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Function.Injective v f : ι ≃ ↑(Set.range v) := Equiv.ofInjective v hv h : Orthonormal 𝕜 v ⊢ Orthonormal 𝕜 Subtype.val [PROOFSTEP] rw [← Equiv.self_comp_ofInjective_symm hv] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Function.Injective v f : ι ≃ ↑(Set.range v) := Equiv.ofInjective v hv h : Orthonormal 𝕜 v ⊢ Orthonormal 𝕜 (v ∘ ↑(Equiv.ofInjective v hv).symm) [PROOFSTEP] exact h.comp f.symm f.symm.injective [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v s : Set ι i : ι hi : ¬i ∈ s l : ι →₀ 𝕜 hl : l ∈ Finsupp.supported 𝕜 𝕜 s ⊢ inner (↑(Finsupp.total ι E 𝕜 v) l) (v i) = 0 [PROOFSTEP] rw [Finsupp.mem_supported'] at hl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v s : Set ι i : ι hi : ¬i ∈ s l : ι →₀ 𝕜 hl : ∀ (x : ι), ¬x ∈ s → ↑l x = 0 ⊢ inner (↑(Finsupp.total ι E 𝕜 v) l) (v i) = 0 [PROOFSTEP] simp only [hv.inner_left_finsupp, hl i hi, map_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hv : Orthonormal 𝕜 v hw : ∀ (i : ι), w i = v i ∨ w i = -v i ⊢ Orthonormal 𝕜 w [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hv : Orthonormal 𝕜 v hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a ⊢ Orthonormal 𝕜 w [PROOFSTEP] rw [orthonormal_iff_ite] at * [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 ⊢ ∀ (i j : ι), inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] intro i j [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] cases' hw i with hi hi [GOAL] case inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι hi : w i = v i ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] cases' hw j with hj hj [GOAL] case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι hi : w i = -v i ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] cases' hw j with hj hj [GOAL] case inl.inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι hi : w i = v i hj : w j = v j ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] replace hv := hv i j [GOAL] case inl.inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι hi : w i = v i hj : w j = -v j ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] replace hv := hv i j [GOAL] case inr.inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι hi : w i = -v i hj : w j = v j ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] replace hv := hv i j [GOAL] case inr.inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a hv : ∀ (i j : ι), inner (v i) (v j) = if i = j then 1 else 0 i j : ι hi : w i = -v i hj : w j = -v j ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] replace hv := hv i j [GOAL] case inl.inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = v i hj : w j = v j hv : inner (v i) (v j) = if i = j then 1 else 0 ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] split_ifs at hv ⊢ with h [GOAL] case inl.inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = v i hj : w j = -v j hv : inner (v i) (v j) = if i = j then 1 else 0 ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] split_ifs at hv ⊢ with h [GOAL] case inr.inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = -v i hj : w j = v j hv : inner (v i) (v j) = if i = j then 1 else 0 ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] split_ifs at hv ⊢ with h [GOAL] case inr.inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = -v i hj : w j = -v j hv : inner (v i) (v j) = if i = j then 1 else 0 ⊢ inner (w i) (w j) = if i = j then 1 else 0 [PROOFSTEP] split_ifs at hv ⊢ with h [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = v i hj : w j = v j h : i = j hv : inner (v i) (v j) = 1 ⊢ inner (w i) (w j) = 1 [PROOFSTEP] simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = v i hj : w j = v j h : ¬i = j hv : inner (v i) (v j) = 0 ⊢ inner (w i) (w j) = 0 [PROOFSTEP] simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = v i hj : w j = -v j h : i = j hv : inner (v i) (v j) = 1 ⊢ inner (w i) (w j) = 1 [PROOFSTEP] simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = v i hj : w j = -v j h : ¬i = j hv : inner (v i) (v j) = 0 ⊢ inner (w i) (w j) = 0 [PROOFSTEP] simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = -v i hj : w j = v j h : i = j hv : inner (v i) (v j) = 1 ⊢ inner (w i) (w j) = 1 [PROOFSTEP] simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = -v i hj : w j = v j h : ¬i = j hv : inner (v i) (v j) = 0 ⊢ inner (w i) (w j) = 0 [PROOFSTEP] simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = -v i hj : w j = -v j h : i = j hv : inner (v i) (v j) = 1 ⊢ inner (w i) (w j) = 1 [PROOFSTEP] simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v w : ι → E hw : ∀ (i : ι), w i = v i ∨ w i = -v i em✝ : (a : Prop) → Decidable a i j : ι hi : w i = -v i hj : w j = -v j h : ¬i = j hv : inner (v i) (v j) = 0 ⊢ inner (w i) (w j) = 0 [PROOFSTEP] simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι ⊢ Orthonormal 𝕜 fun x => ↑x [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι em✝ : (a : Prop) → Decidable a ⊢ Orthonormal 𝕜 fun x => ↑x [PROOFSTEP] simp [orthonormal_subtype_iff_ite] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι η : Type u_5 s : η → Set E hs : Directed (fun x x_1 => x ⊆ x_1) s h : ∀ (i : η), Orthonormal 𝕜 fun x => ↑x ⊢ Orthonormal 𝕜 fun x => ↑x [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι η : Type u_5 s : η → Set E hs : Directed (fun x x_1 => x ⊆ x_1) s h : ∀ (i : η), Orthonormal 𝕜 fun x => ↑x em✝ : (a : Prop) → Decidable a ⊢ Orthonormal 𝕜 fun x => ↑x [PROOFSTEP] rw [orthonormal_subtype_iff_ite] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι η : Type u_5 s : η → Set E hs : Directed (fun x x_1 => x ⊆ x_1) s h : ∀ (i : η), Orthonormal 𝕜 fun x => ↑x em✝ : (a : Prop) → Decidable a ⊢ ∀ (v : E), v ∈ ⋃ (i : η), s i → ∀ (w : E), w ∈ ⋃ (i : η), s i → inner v w = if v = w then 1 else 0 [PROOFSTEP] rintro x ⟨_, ⟨i, rfl⟩, hxi⟩ y ⟨_, ⟨j, rfl⟩, hyj⟩ [GOAL] case intro.intro.intro.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι η : Type u_5 s : η → Set E hs : Directed (fun x x_1 => x ⊆ x_1) s h : ∀ (i : η), Orthonormal 𝕜 fun x => ↑x em✝ : (a : Prop) → Decidable a x : E i : η hxi : x ∈ (fun i => s i) i y : E j : η hyj : y ∈ (fun i => s i) j ⊢ inner x y = if x = y then 1 else 0 [PROOFSTEP] obtain ⟨k, hik, hjk⟩ := hs i j [GOAL] case intro.intro.intro.intro.intro.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι η : Type u_5 s : η → Set E hs : Directed (fun x x_1 => x ⊆ x_1) s h : ∀ (i : η), Orthonormal 𝕜 fun x => ↑x em✝ : (a : Prop) → Decidable a x : E i : η hxi : x ∈ (fun i => s i) i y : E j : η hyj : y ∈ (fun i => s i) j k : η hik : s i ⊆ s k hjk : s j ⊆ s k ⊢ inner x y = if x = y then 1 else 0 [PROOFSTEP] have h_orth : Orthonormal 𝕜 (fun x => x : s k → E) := h k [GOAL] case intro.intro.intro.intro.intro.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι η : Type u_5 s : η → Set E hs : Directed (fun x x_1 => x ⊆ x_1) s h : ∀ (i : η), Orthonormal 𝕜 fun x => ↑x em✝ : (a : Prop) → Decidable a x : E i : η hxi : x ∈ (fun i => s i) i y : E j : η hyj : y ∈ (fun i => s i) j k : η hik : s i ⊆ s k hjk : s j ⊆ s k h_orth : Orthonormal 𝕜 fun x => ↑x ⊢ inner x y = if x = y then 1 else 0 [PROOFSTEP] rw [orthonormal_subtype_iff_ite] at h_orth [GOAL] case intro.intro.intro.intro.intro.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι η : Type u_5 s : η → Set E hs : Directed (fun x x_1 => x ⊆ x_1) s h : ∀ (i : η), Orthonormal 𝕜 fun x => ↑x em✝ : (a : Prop) → Decidable a x : E i : η hxi : x ∈ (fun i => s i) i y : E j : η hyj : y ∈ (fun i => s i) j k : η hik : s i ⊆ s k hjk : s j ⊆ s k h_orth : ∀ (v : E), v ∈ s k → ∀ (w : E), w ∈ s k → inner v w = if v = w then 1 else 0 ⊢ inner x y = if x = y then 1 else 0 [PROOFSTEP] exact h_orth x (hik hxi) y (hjk hyj) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set (Set E) hs : DirectedOn (fun x x_1 => x ⊆ x_1) s h : ∀ (a : Set E), a ∈ s → Orthonormal 𝕜 fun x => ↑x ⊢ Orthonormal 𝕜 fun x => ↑x [PROOFSTEP] rw [Set.sUnion_eq_iUnion] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set (Set E) hs : DirectedOn (fun x x_1 => x ⊆ x_1) s h : ∀ (a : Set E), a ∈ s → Orthonormal 𝕜 fun x => ↑x ⊢ Orthonormal 𝕜 fun x => ↑x [PROOFSTEP] exact orthonormal_iUnion_of_directed hs.directed_val (by simpa using h) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set (Set E) hs : DirectedOn (fun x x_1 => x ⊆ x_1) s h : ∀ (a : Set E), a ∈ s → Orthonormal 𝕜 fun x => ↑x ⊢ ∀ (i : ↑s), Orthonormal 𝕜 fun x => ↑x [PROOFSTEP] simpa using h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E hs : Orthonormal 𝕜 Subtype.val ⊢ ∃ w _hw, Orthonormal 𝕜 Subtype.val ∧ ∀ (u : Set E), u ⊇ w → Orthonormal 𝕜 Subtype.val → u = w [PROOFSTEP] have := zorn_subset_nonempty {b | Orthonormal 𝕜 (Subtype.val : b → E)} ?_ _ hs [GOAL] case refine_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E hs : Orthonormal 𝕜 Subtype.val this : ∃ m, m ∈ {b | Orthonormal 𝕜 Subtype.val} ∧ s ⊆ m ∧ ∀ (a : Set E), a ∈ {b | Orthonormal 𝕜 Subtype.val} → m ⊆ a → a = m ⊢ ∃ w _hw, Orthonormal 𝕜 Subtype.val ∧ ∀ (u : Set E), u ⊇ w → Orthonormal 𝕜 Subtype.val → u = w case refine_1 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E hs : Orthonormal 𝕜 Subtype.val ⊢ ∀ (c : Set (Set E)), c ⊆ {b | Orthonormal 𝕜 Subtype.val} → IsChain (fun x x_1 => x ⊆ x_1) c → Set.Nonempty c → ∃ ub, ub ∈ {b | Orthonormal 𝕜 Subtype.val} ∧ ∀ (s : Set E), s ∈ c → s ⊆ ub [PROOFSTEP] obtain ⟨b, bi, sb, h⟩ := this [GOAL] case refine_2.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E hs : Orthonormal 𝕜 Subtype.val b : Set E bi : b ∈ {b | Orthonormal 𝕜 Subtype.val} sb : s ⊆ b h : ∀ (a : Set E), a ∈ {b | Orthonormal 𝕜 Subtype.val} → b ⊆ a → a = b ⊢ ∃ w _hw, Orthonormal 𝕜 Subtype.val ∧ ∀ (u : Set E), u ⊇ w → Orthonormal 𝕜 Subtype.val → u = w [PROOFSTEP] refine' ⟨b, sb, bi, _⟩ [GOAL] case refine_2.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E hs : Orthonormal 𝕜 Subtype.val b : Set E bi : b ∈ {b | Orthonormal 𝕜 Subtype.val} sb : s ⊆ b h : ∀ (a : Set E), a ∈ {b | Orthonormal 𝕜 Subtype.val} → b ⊆ a → a = b ⊢ ∀ (u : Set E), u ⊇ b → Orthonormal 𝕜 Subtype.val → u = b [PROOFSTEP] exact fun u hus hu => h u hu hus [GOAL] case refine_1 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E hs : Orthonormal 𝕜 Subtype.val ⊢ ∀ (c : Set (Set E)), c ⊆ {b | Orthonormal 𝕜 Subtype.val} → IsChain (fun x x_1 => x ⊆ x_1) c → Set.Nonempty c → ∃ ub, ub ∈ {b | Orthonormal 𝕜 Subtype.val} ∧ ∀ (s : Set E), s ∈ c → s ⊆ ub [PROOFSTEP] refine' fun c hc cc _c0 => ⟨⋃₀ c, _, _⟩ [GOAL] case refine_1.refine'_1 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E hs : Orthonormal 𝕜 Subtype.val c : Set (Set E) hc : c ⊆ {b | Orthonormal 𝕜 Subtype.val} cc : IsChain (fun x x_1 => x ⊆ x_1) c _c0 : Set.Nonempty c ⊢ ⋃₀ c ∈ {b | Orthonormal 𝕜 Subtype.val} [PROOFSTEP] exact orthonormal_sUnion_of_directed cc.directedOn fun x xc => hc xc [GOAL] case refine_1.refine'_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι s : Set E hs : Orthonormal 𝕜 Subtype.val c : Set (Set E) hc : c ⊆ {b | Orthonormal 𝕜 Subtype.val} cc : IsChain (fun x x_1 => x ⊆ x_1) c _c0 : Set.Nonempty c ⊢ ∀ (s : Set E), s ∈ c → s ⊆ ⋃₀ c [PROOFSTEP] exact fun _ => Set.subset_sUnion_of_mem [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v i : ι ⊢ v i ≠ 0 [PROOFSTEP] have : ‖v i‖ ≠ 0 := by rw [hv.1 i] norm_num [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v i : ι ⊢ ‖v i‖ ≠ 0 [PROOFSTEP] rw [hv.1 i] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v i : ι ⊢ 1 ≠ 0 [PROOFSTEP] norm_num [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι v : ι → E hv : Orthonormal 𝕜 v i : ι this : ‖v i‖ ≠ 0 ⊢ v i ≠ 0 [PROOFSTEP] simpa using this [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑re (inner x x) = ‖x‖ * ‖x‖ [PROOFSTEP] rw [@norm_eq_sqrt_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑re (inner x x) = ‖x‖ ^ 2 [PROOFSTEP] rw [pow_two, inner_self_eq_norm_mul_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F ⊢ inner x x = ‖x‖ * ‖x‖ [PROOFSTEP] have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F h : ↑re (inner x x) = ‖x‖ * ‖x‖ ⊢ inner x x = ‖x‖ * ‖x‖ [PROOFSTEP] simpa using h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F ⊢ inner x x = ‖x‖ ^ 2 [PROOFSTEP] rw [pow_two, real_inner_self_eq_norm_mul_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner (x + y) (x + y)) = ‖x‖ ^ 2 + 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner (x + y) (x + y)) = ↑re (inner x x) + 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner (x + y) (x + y)) = ↑re (inner x x) + 2 * ↑re (inner x y) + ↑re (inner y y) [PROOFSTEP] rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner (x + y) (x + y)) = ↑re (inner x x) + 2 * ↑re (inner x y) + ↑re (inner y y) [PROOFSTEP] rw [inner_add_add_self, two_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x x + inner x y + inner y x + inner y y) = ↑re (inner x x) + (↑re (inner x y) + ↑re (inner x y)) + ↑re (inner y y) [PROOFSTEP] simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner y x) = ↑re (inner x y) [PROOFSTEP] rw [← inner_conj_symm, conj_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * inner x y + ‖y‖ ^ 2 [PROOFSTEP] have h := @norm_add_sq ℝ _ _ _ _ x y [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ↑re (inner x y) + ‖y‖ ^ 2 ⊢ ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * inner x y + ‖y‖ ^ 2 [PROOFSTEP] simpa using h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ [PROOFSTEP] repeat' rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ [PROOFSTEP] rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ ^ 2 = ‖x‖ * ‖x‖ + 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ [PROOFSTEP] rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ [PROOFSTEP] rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] exact norm_add_sq _ _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * inner x y + ‖y‖ * ‖y‖ [PROOFSTEP] have h := @norm_add_mul_self ℝ _ _ _ _ x y [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ ⊢ ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * inner x y + ‖y‖ * ‖y‖ [PROOFSTEP] simpa using h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg, sub_eq_add_neg] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ [PROOFSTEP] repeat' rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ [PROOFSTEP] rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x - y‖ ^ 2 = ‖x‖ * ‖x‖ - 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ [PROOFSTEP] rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ [PROOFSTEP] rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] rw [← sq (M := ℝ)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ↑re (inner x y) + ‖y‖ ^ 2 [PROOFSTEP] exact norm_sub_sq _ _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * inner x y + ‖y‖ * ‖y‖ [PROOFSTEP] have h := @norm_sub_mul_self ℝ _ _ _ _ x y [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ ⊢ ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * inner x y + ‖y‖ * ‖y‖ [PROOFSTEP] simpa using h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖inner x y‖ ≤ ‖x‖ * ‖y‖ [PROOFSTEP] rw [norm_eq_sqrt_inner (𝕜 := 𝕜) x, norm_eq_sqrt_inner (𝕜 := 𝕜) y] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖inner x y‖ ≤ sqrt (↑re (inner x x)) * sqrt (↑re (inner y y)) [PROOFSTEP] letI : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E this : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore ⊢ ‖inner x y‖ ≤ sqrt (↑re (inner x x)) * sqrt (↑re (inner y y)) [PROOFSTEP] exact InnerProductSpace.Core.norm_inner_le_norm x y [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) [PROOFSTEP] simp only [← @inner_self_eq_norm_mul_norm 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner (x + y) (x + y)) + ↑re (inner (x - y) (x - y)) = 2 * (↑re (inner x x) + ↑re (inner y y)) [PROOFSTEP] rw [← re.map_add, parallelogram_law, two_mul, two_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x x + inner y y + (inner x x + inner y y)) = ↑re (inner x x) + ↑re (inner y y) + (↑re (inner x x) + ↑re (inner y y)) [PROOFSTEP] simp only [re.map_add] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x y) = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 [PROOFSTEP] rw [@norm_add_mul_self 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x y) = (‖x‖ * ‖x‖ + 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x y) = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 [PROOFSTEP] rw [@norm_sub_mul_self 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x y) = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - (‖x‖ * ‖x‖ - 2 * ↑re (inner x y) + ‖y‖ * ‖y‖)) / 2 [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x y) = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 [PROOFSTEP] rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑re (inner x y) = (‖x‖ * ‖x‖ + 2 * ↑re (inner x y) + ‖y‖ * ‖y‖ - (‖x‖ * ‖x‖ - 2 * ↑re (inner x y) + ‖y‖ * ‖y‖)) / 4 [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑im (inner x y) = (‖x - I • y‖ * ‖x - I • y‖ - ‖x + I • y‖ * ‖x + I • y‖) / 4 [PROOFSTEP] simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑im (inner x y) = (‖x‖ * ‖x‖ - 2 * -↑im (inner x y) + ‖I • y‖ * ‖I • y‖ - (‖x‖ * ‖x‖ + 2 * -↑im (inner x y) + ‖I • y‖ * ‖I • y‖)) / 4 [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner x y = (↑‖x + y‖ ^ 2 - ↑‖x - y‖ ^ 2 + (↑‖x - I • y‖ ^ 2 - ↑‖x + I • y‖ ^ 2) * I) / 4 [PROOFSTEP] rw [← re_add_im ⟪x, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four, im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ↑((‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4) + ↑((‖x - I • y‖ * ‖x - I • y‖ - ‖x + I • y‖ * ‖x + I • y‖) / 4) * I = (↑‖x + y‖ ^ 2 - ↑‖x - y‖ ^ 2 + (↑‖x - I • y‖ ^ 2 - ↑‖x + I • y‖ ^ 2) * I) / 4 [PROOFSTEP] push_cast [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ (↑‖x + y‖ * ↑‖x + y‖ - ↑‖x - y‖ * ↑‖x - y‖) / 4 + (↑‖x - I • y‖ * ↑‖x - I • y‖ - ↑‖x + I • y‖ * ↑‖x + I • y‖) / 4 * I = (↑‖x + y‖ ^ 2 - ↑‖x - y‖ ^ 2 + (↑‖x - I • y‖ ^ 2 - ↑‖x + I • y‖ ^ 2) * I) / 4 [PROOFSTEP] simp only [sq, ← mul_div_right_comm, ← add_div] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F hx : x ≠ 0 hy : y ≠ 0 R : ℝ hx' : ‖x‖ ≠ 0 hy' : ‖y‖ ≠ 0 ⊢ dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = sqrt (‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖ ^ 2) [PROOFSTEP] rw [dist_eq_norm, sqrt_sq (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F hx : x ≠ 0 hy : y ≠ 0 R : ℝ hx' : ‖x‖ ≠ 0 hy' : ‖y‖ ≠ 0 ⊢ ‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖ ^ 2 = (R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2 [PROOFSTEP] field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right, Real.norm_of_nonneg (mul_self_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F hx : x ≠ 0 hy : y ≠ 0 R : ℝ hx' : ‖x‖ ≠ 0 hy' : ‖y‖ ≠ 0 ⊢ ((R * R * ‖x‖ * (R * R * ‖x‖) * (‖y‖ * ‖y‖ * (‖x‖ * ‖x‖)) - ‖x‖ * ‖x‖ * (‖x‖ * ‖x‖) * (2 * (R * R * (R * R * inner x y)))) * (‖y‖ * ‖y‖ * (‖y‖ * ‖y‖)) + R * R * ‖y‖ * (R * R * ‖y‖) * (‖x‖ * ‖x‖ * (‖x‖ * ‖x‖) * (‖y‖ * ‖y‖ * (‖x‖ * ‖x‖)))) * (‖x‖ * ‖y‖ * (‖x‖ * ‖y‖)) = R * R * (R * R) * (‖x‖ * ‖x‖ - 2 * inner x y + ‖y‖ * ‖y‖) * (‖x‖ * ‖x‖ * (‖x‖ * ‖x‖) * (‖y‖ * ‖y‖ * (‖x‖ * ‖x‖)) * (‖y‖ * ‖y‖ * (‖y‖ * ‖y‖))) [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F hx : x ≠ 0 hy : y ≠ 0 R : ℝ hx' : ‖x‖ ≠ 0 hy' : ‖y‖ ≠ 0 ⊢ sqrt ((R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2) = R ^ 2 / (‖x‖ * ‖y‖) * dist x y [PROOFSTEP] rw [sqrt_mul (sq_nonneg _), sqrt_sq (norm_nonneg _), sqrt_sq (div_nonneg (sq_nonneg _) (mul_nonneg (norm_nonneg _) (norm_nonneg _))), dist_eq_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ε : ℝ hε : 0 < ε ⊢ ∃ δ, 0 < δ ∧ ∀ ⦃x : F⦄, ‖x‖ = 1 → ∀ ⦃y : F⦄, ‖y‖ = 1 → ε ≤ ‖x - y‖ → ‖x + y‖ ≤ 2 - δ [PROOFSTEP] refine' ⟨2 - sqrt (4 - ε ^ 2), sub_pos_of_lt <| (sqrt_lt' zero_lt_two).2 _, fun x hx y hy hxy => _⟩ [GOAL] case refine'_1 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ε : ℝ hε : 0 < ε ⊢ 4 - ε ^ 2 < 2 ^ 2 [PROOFSTEP] norm_num [GOAL] case refine'_1 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ε : ℝ hε : 0 < ε ⊢ 0 < ε ^ 2 [PROOFSTEP] exact pow_pos hε _ [GOAL] case refine'_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ε : ℝ hε : 0 < ε x : F hx : ‖x‖ = 1 y : F hy : ‖y‖ = 1 hxy : ε ≤ ‖x - y‖ ⊢ ‖x + y‖ ≤ 2 - (2 - sqrt (4 - ε ^ 2)) [PROOFSTEP] rw [sub_sub_cancel] [GOAL] case refine'_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ε : ℝ hε : 0 < ε x : F hx : ‖x‖ = 1 y : F hy : ‖y‖ = 1 hxy : ε ≤ ‖x - y‖ ⊢ ‖x + y‖ ≤ sqrt (4 - ε ^ 2) [PROOFSTEP] refine' le_sqrt_of_sq_le _ [GOAL] case refine'_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ε : ℝ hε : 0 < ε x : F hx : ‖x‖ = 1 y : F hy : ‖y‖ = 1 hxy : ε ≤ ‖x - y‖ ⊢ ‖x + y‖ ^ 2 ≤ 4 - ε ^ 2 [PROOFSTEP] rw [sq, eq_sub_iff_add_eq.2 (parallelogram_law_with_norm ℝ x y), ← sq ‖x - y‖, hx, hy] [GOAL] case refine'_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ε : ℝ hε : 0 < ε x : F hx : ‖x‖ = 1 y : F hy : ‖y‖ = 1 hxy : ε ≤ ‖x - y‖ ⊢ 2 * (1 * 1 + 1 * 1) - ‖x - y‖ ^ 2 ≤ 4 - ε ^ 2 [PROOFSTEP] ring_nf [GOAL] case refine'_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ε : ℝ hε : 0 < ε x : F hx : ‖x‖ = 1 y : F hy : ‖y‖ = 1 hxy : ε ≤ ‖x - y‖ ⊢ 4 - ‖x - y‖ ^ 2 ≤ 4 - ε ^ 2 [PROOFSTEP] exact sub_le_sub_left (pow_le_pow_of_le_left hε.le hxy _) 4 [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V x y : V ⊢ inner (↑T y) x = (inner (↑T (x + y)) (x + y) - inner (↑T (x - y)) (x - y) + Complex.I * inner (↑T (x + Complex.I • y)) (x + Complex.I • y) - Complex.I * inner (↑T (x - Complex.I • y)) (x - Complex.I • y)) / 4 [PROOFSTEP] simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left, inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right, mul_add, ← mul_assoc, mul_neg, neg_neg, sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V x y : V ⊢ inner (↑T y) x = (inner (↑T x) x + inner (↑T y) x + (inner (↑T x) y + inner (↑T y) y) - (inner (↑T x) x - (inner (↑T y) x + (inner (↑T x) y - inner (↑T y) y))) + (Complex.I * inner (↑T x) x + inner (↑T y) x + (-inner (↑T x) y + Complex.I * inner (↑T y) y)) - (Complex.I * inner (↑T x) x - (inner (↑T y) x + (-inner (↑T x) y - Complex.I * inner (↑T y) y)))) / 4 [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V x y : V ⊢ inner (↑T x) y = (inner (↑T (x + y)) (x + y) - inner (↑T (x - y)) (x - y) - Complex.I * inner (↑T (x + Complex.I • y)) (x + Complex.I • y) + Complex.I * inner (↑T (x - Complex.I • y)) (x - Complex.I • y)) / 4 [PROOFSTEP] simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left, inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right, mul_add, ← mul_assoc, mul_neg, neg_neg, sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V x y : V ⊢ inner (↑T x) y = (inner (↑T x) x + inner (↑T y) x + (inner (↑T x) y + inner (↑T y) y) - (inner (↑T x) x - (inner (↑T y) x + (inner (↑T x) y - inner (↑T y) y)) + (Complex.I * inner (↑T x) x + inner (↑T y) x + (-inner (↑T x) y + Complex.I * inner (↑T y) y))) + (Complex.I * inner (↑T x) x - (inner (↑T y) x + (-inner (↑T x) y - Complex.I * inner (↑T y) y)))) / 4 [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V ⊢ (∀ (x : V), inner (↑T x) x = 0) ↔ T = 0 [PROOFSTEP] constructor [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V ⊢ (∀ (x : V), inner (↑T x) x = 0) → T = 0 [PROOFSTEP] intro hT [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V hT : ∀ (x : V), inner (↑T x) x = 0 ⊢ T = 0 [PROOFSTEP] ext x [GOAL] case mp.h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V hT : ∀ (x : V), inner (↑T x) x = 0 x : V ⊢ ↑T x = ↑0 x [PROOFSTEP] simp only [LinearMap.zero_apply, ← @inner_self_eq_zero ℂ V] [GOAL] case mp.h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V hT : ∀ (x : V), inner (↑T x) x = 0 x : V ⊢ inner (↑T x) (↑T x) = 0 [PROOFSTEP] simp (config := { singlePass := true }) only [inner_map_polarization] [GOAL] case mp.h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V hT : ∀ (x : V), inner (↑T x) x = 0 x : V ⊢ (inner (↑T (↑T x + x)) (↑T x + x) - inner (↑T (↑T x - x)) (↑T x - x) + Complex.I * inner (↑T (↑T x + Complex.I • x)) (↑T x + Complex.I • x) - Complex.I * inner (↑T (↑T x - Complex.I • x)) (↑T x - Complex.I • x)) / 4 = 0 [PROOFSTEP] simp only [hT] [GOAL] case mp.h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V hT : ∀ (x : V), inner (↑T x) x = 0 x : V ⊢ (0 - 0 + Complex.I * 0 - Complex.I * 0) / 4 = 0 [PROOFSTEP] norm_num [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V T : V →ₗ[ℂ] V ⊢ T = 0 → ∀ (x : V), inner (↑T x) x = 0 [PROOFSTEP] rintro rfl x [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V x : V ⊢ inner (↑0 x) x = 0 [PROOFSTEP] simp only [LinearMap.zero_apply, inner_zero_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V S T : V →ₗ[ℂ] V ⊢ (∀ (x : V), inner (↑S x) x = inner (↑T x) x) ↔ S = T [PROOFSTEP] rw [← sub_eq_zero, ← inner_map_self_eq_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V S T : V →ₗ[ℂ] V ⊢ (∀ (x : V), inner (↑S x) x = inner (↑T x) x) ↔ ∀ (x : V), inner (↑(S - T) x) x = 0 [PROOFSTEP] refine' forall_congr' fun x => _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E V : Type u_4 inst✝¹ : NormedAddCommGroup V inst✝ : InnerProductSpace ℂ V S T : V →ₗ[ℂ] V x : V ⊢ inner (↑S x) x = inner (↑T x) x ↔ inner (↑(S - T) x) x = 0 [PROOFSTEP] rw [LinearMap.sub_apply, inner_sub_left, sub_eq_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' f : E →ₗᵢ[𝕜] E' x y : E ⊢ inner (↑f x) (↑f y) = inner x y [PROOFSTEP] simp [inner_eq_sum_norm_sq_div_four, ← f.norm_map] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' f : E →ₗ[𝕜] E' h : ∀ (x y : E), inner (↑f x) (↑f y) = inner x y x : E ⊢ ‖↑f x‖ = ‖x‖ [PROOFSTEP] simp only [@norm_eq_sqrt_inner 𝕜, h] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : ι → E f : E →ₗᵢ[𝕜] E' ⊢ Orthonormal 𝕜 (↑f ∘ v) ↔ Orthonormal 𝕜 v [PROOFSTEP] classical simp_rw [orthonormal_iff_ite, Function.comp_apply, LinearIsometry.inner_map_map] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : ι → E f : E →ₗᵢ[𝕜] E' ⊢ Orthonormal 𝕜 (↑f ∘ v) ↔ Orthonormal 𝕜 v [PROOFSTEP] simp_rw [orthonormal_iff_ite, Function.comp_apply, LinearIsometry.inner_map_map] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : ι → E hv : Orthonormal 𝕜 v f : E →ₗᵢ[𝕜] E' ⊢ Orthonormal 𝕜 (↑f ∘ v) [PROOFSTEP] rwa [f.orthonormal_comp_iff] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' f : E →ₗ[𝕜] E' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v hf : Orthonormal 𝕜 (↑f ∘ ↑v) x y : E ⊢ inner (↑f x) (↑f y) = inner x y [PROOFSTEP] classical rw [← v.total_repr x, ← v.total_repr y, Finsupp.apply_total, Finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' f : E →ₗ[𝕜] E' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v hf : Orthonormal 𝕜 (↑f ∘ ↑v) x y : E ⊢ inner (↑f x) (↑f y) = inner x y [PROOFSTEP] rw [← v.total_repr x, ← v.total_repr y, Finsupp.apply_total, Finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' f : E ≃ₗ[𝕜] E' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v hf : Orthonormal 𝕜 (↑f ∘ ↑v) x y : E ⊢ inner (↑f x) (↑f y) = inner x y [PROOFSTEP] rw [← LinearEquiv.coe_coe] at hf [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' f : E ≃ₗ[𝕜] E' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v hf : Orthonormal 𝕜 (↑↑f ∘ ↑v) x y : E ⊢ inner (↑f x) (↑f y) = inner x y [PROOFSTEP] classical rw [← v.total_repr x, ← v.total_repr y, ← LinearEquiv.coe_coe f, Finsupp.apply_total, Finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' f : E ≃ₗ[𝕜] E' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v hf : Orthonormal 𝕜 (↑↑f ∘ ↑v) x y : E ⊢ inner (↑f x) (↑f y) = inner x y [PROOFSTEP] rw [← v.total_repr x, ← v.total_repr y, ← LinearEquiv.coe_coe f, Finsupp.apply_total, Finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v v' : Basis ι' 𝕜 E' hv' : Orthonormal 𝕜 ↑v' e : ι ≃ ι' ⊢ Orthonormal 𝕜 (↑(Basis.equiv v v' e) ∘ ↑v) [PROOFSTEP] have h : v.equiv v' e ∘ v = v' ∘ e := by ext i simp [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v v' : Basis ι' 𝕜 E' hv' : Orthonormal 𝕜 ↑v' e : ι ≃ ι' ⊢ ↑(Basis.equiv v v' e) ∘ ↑v = ↑v' ∘ ↑e [PROOFSTEP] ext i [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v v' : Basis ι' 𝕜 E' hv' : Orthonormal 𝕜 ↑v' e : ι ≃ ι' i : ι ⊢ (↑(Basis.equiv v v' e) ∘ ↑v) i = (↑v' ∘ ↑e) i [PROOFSTEP] simp [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v v' : Basis ι' 𝕜 E' hv' : Orthonormal 𝕜 ↑v' e : ι ≃ ι' h : ↑(Basis.equiv v v' e) ∘ ↑v = ↑v' ∘ ↑e ⊢ Orthonormal 𝕜 (↑(Basis.equiv v v' e) ∘ ↑v) [PROOFSTEP] rw [h] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v v' : Basis ι' 𝕜 E' hv' : Orthonormal 𝕜 ↑v' e : ι ≃ ι' h : ↑(Basis.equiv v v' e) ∘ ↑v = ↑v' ∘ ↑e ⊢ Orthonormal 𝕜 (↑v' ∘ ↑e) [PROOFSTEP] classical exact hv'.comp _ e.injective [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v v' : Basis ι' 𝕜 E' hv' : Orthonormal 𝕜 ↑v' e : ι ≃ ι' h : ↑(Basis.equiv v v' e) ∘ ↑v = ↑v' ∘ ↑e ⊢ Orthonormal 𝕜 (↑v' ∘ ↑e) [PROOFSTEP] exact hv'.comp _ e.injective [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v i : ι ⊢ ↑(equiv hv hv (Equiv.refl ι)) (↑v i) = ↑(LinearIsometryEquiv.refl 𝕜 E) (↑v i) [PROOFSTEP] simp only [Orthonormal.equiv_apply, Equiv.coe_refl, id.def, LinearIsometryEquiv.coe_refl] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v v' : Basis ι' 𝕜 E' hv' : Orthonormal 𝕜 ↑v' e : ι ≃ ι' i : ι' ⊢ ↑(equiv hv hv' e) (↑(LinearIsometryEquiv.symm (equiv hv hv' e)) (↑v' i)) = ↑(equiv hv hv' e) (↑(equiv hv' hv e.symm) (↑v' i)) [PROOFSTEP] simp only [LinearIsometryEquiv.apply_symm_apply, Orthonormal.equiv_apply, e.apply_symm_apply] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁸ : IsROrC 𝕜 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : InnerProductSpace 𝕜 E inst✝⁵ : NormedAddCommGroup F inst✝⁴ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 ι' : Type u_5 ι'' : Type u_6 E' : Type u_7 inst✝³ : NormedAddCommGroup E' inst✝² : InnerProductSpace 𝕜 E' E'' : Type u_8 inst✝¹ : NormedAddCommGroup E'' inst✝ : InnerProductSpace 𝕜 E'' v : Basis ι 𝕜 E hv : Orthonormal 𝕜 ↑v v' : Basis ι' 𝕜 E' hv' : Orthonormal 𝕜 ↑v' e : ι ≃ ι' v'' : Basis ι'' 𝕜 E'' hv'' : Orthonormal 𝕜 ↑v'' e' : ι' ≃ ι'' i : ι ⊢ ↑(LinearIsometryEquiv.trans (equiv hv hv' e) (equiv hv' hv'' e')) (↑v i) = ↑(equiv hv hv'' (e.trans e')) (↑v i) [PROOFSTEP] simp only [LinearIsometryEquiv.trans_apply, Orthonormal.equiv_apply, e.coe_trans, Function.comp_apply] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ inner x y = 0 [PROOFSTEP] rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_right_eq_self, mul_eq_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ 2 = 0 ∨ ↑re (inner x y) = 0 ↔ inner x y = 0 [PROOFSTEP] norm_num [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ‖x + y‖ = sqrt (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ inner x y = 0 [PROOFSTEP] rw [← norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)) (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : inner x y = 0 ⊢ ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ [PROOFSTEP] rw [@norm_add_mul_self 𝕜, add_right_cancel_iff, add_right_eq_self, mul_eq_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : inner x y = 0 ⊢ 2 = 0 ∨ ↑re (inner x y) = 0 [PROOFSTEP] apply Or.inr [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : inner x y = 0 ⊢ ↑re (inner x y) = 0 [PROOFSTEP] simp only [h, zero_re'] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ inner x y = 0 [PROOFSTEP] rw [@norm_sub_mul_self ℝ, add_right_cancel_iff, sub_eq_add_neg, add_right_eq_self, neg_eq_zero, mul_eq_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ 2 = 0 ∨ ↑re (inner x y) = 0 ↔ inner x y = 0 [PROOFSTEP] norm_num [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ ‖x - y‖ = sqrt (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ inner x y = 0 [PROOFSTEP] rw [← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)) (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner (x + y) (x - y) = 0 ↔ ‖x‖ = ‖y‖ [PROOFSTEP] conv_rhs => rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F | ‖x‖ = ‖y‖ [PROOFSTEP] rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F | ‖x‖ = ‖y‖ [PROOFSTEP] rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F | ‖x‖ = ‖y‖ [PROOFSTEP] rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner (x + y) (x - y) = 0 ↔ ‖x‖ * ‖x‖ = ‖y‖ * ‖y‖ [PROOFSTEP] simp only [← @inner_self_eq_norm_mul_norm ℝ, inner_add_left, inner_sub_right, real_inner_comm y x, sub_eq_zero, re_to_real] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner x x + inner y x = inner y x + inner y y ↔ inner x x = inner y y [PROOFSTEP] constructor [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner x x + inner y x = inner y x + inner y y → inner x x = inner y y [PROOFSTEP] intro h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner x x + inner y x = inner y x + inner y y ⊢ inner x x = inner y y [PROOFSTEP] rw [add_comm] at h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner y x + inner x x = inner y x + inner y y ⊢ inner x x = inner y y [PROOFSTEP] linarith [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner x x = inner y y → inner x x + inner y x = inner y x + inner y y [PROOFSTEP] intro h [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner x x = inner y y ⊢ inner x x + inner y x = inner y x + inner y y [PROOFSTEP] linarith [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E v w : E h : inner v w = 0 ⊢ ‖w - v‖ = ‖w + v‖ [PROOFSTEP] rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E v w : E h : inner v w = 0 ⊢ ‖w - v‖ * ‖w - v‖ = ‖w + v‖ * ‖w + v‖ [PROOFSTEP] simp only [h, ← @inner_self_eq_norm_mul_norm 𝕜, sub_neg_eq_add, sub_zero, map_sub, zero_re', zero_sub, add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm, zero_add] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ |inner x y / (‖x‖ * ‖y‖)| ≤ 1 [PROOFSTEP] rw [abs_div, abs_mul, abs_norm, abs_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ |inner x y| / (‖x‖ * ‖y‖) ≤ 1 [PROOFSTEP] exact div_le_one_of_le (abs_real_inner_le_norm x y) (mul_nonneg (norm_nonneg _) (norm_nonneg _)) -- porting note: was `(by positivity)` [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F r : ℝ ⊢ inner (r • x) x = r * (‖x‖ * ‖x‖) [PROOFSTEP] rw [real_inner_smul_left, ← real_inner_self_eq_norm_mul_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F r : ℝ ⊢ inner x (r • x) = r * (‖x‖ * ‖x‖) [PROOFSTEP] rw [inner_smul_right, ← real_inner_self_eq_norm_mul_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E r : 𝕜 hx : x ≠ 0 hr : r ≠ 0 ⊢ ‖inner x (r • x)‖ / (‖x‖ * ‖r • x‖) = 1 [PROOFSTEP] have hx' : ‖x‖ ≠ 0 := by simp [hx] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E r : 𝕜 hx : x ≠ 0 hr : r ≠ 0 ⊢ ‖x‖ ≠ 0 [PROOFSTEP] simp [hx] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E r : 𝕜 hx : x ≠ 0 hr : r ≠ 0 hx' : ‖x‖ ≠ 0 ⊢ ‖inner x (r • x)‖ / (‖x‖ * ‖r • x‖) = 1 [PROOFSTEP] have hr' : ‖r‖ ≠ 0 := by simp [hr] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E r : 𝕜 hx : x ≠ 0 hr : r ≠ 0 hx' : ‖x‖ ≠ 0 ⊢ ‖r‖ ≠ 0 [PROOFSTEP] simp [hr] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E r : 𝕜 hx : x ≠ 0 hr : r ≠ 0 hx' : ‖x‖ ≠ 0 hr' : ‖r‖ ≠ 0 ⊢ ‖inner x (r • x)‖ / (‖x‖ * ‖r • x‖) = 1 [PROOFSTEP] rw [inner_smul_right, norm_mul, ← inner_self_re_eq_norm, inner_self_eq_norm_mul_norm, norm_smul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E r : 𝕜 hx : x ≠ 0 hr : r ≠ 0 hx' : ‖x‖ ≠ 0 hr' : ‖r‖ ≠ 0 ⊢ ‖r‖ * (‖x‖ * ‖x‖) / (‖x‖ * (‖r‖ * ‖x‖)) = 1 [PROOFSTEP] rw [← mul_assoc, ← div_div, mul_div_cancel _ hx', ← div_div, mul_comm, mul_div_cancel _ hr', div_self hx'] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F r : ℝ hx : x ≠ 0 hr : 0 < r ⊢ inner x (r • x) / (‖x‖ * ‖r • x‖) = 1 [PROOFSTEP] rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, mul_comm _ |r|, mul_assoc, abs_of_nonneg hr.le, div_self] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F r : ℝ hx : x ≠ 0 hr : 0 < r ⊢ r * (‖x‖ * ‖x‖) ≠ 0 [PROOFSTEP] exact mul_ne_zero hr.ne' (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx)) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F r : ℝ hx : x ≠ 0 hr : r < 0 ⊢ inner x (r • x) / (‖x‖ * ‖r • x‖) = -1 [PROOFSTEP] rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, mul_comm _ |r|, mul_assoc, abs_of_neg hr, neg_mul, div_neg_eq_neg_div, div_self] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F r : ℝ hx : x ≠ 0 hr : r < 0 ⊢ r * (‖x‖ * ‖x‖) ≠ 0 [PROOFSTEP] exact mul_ne_zero hr.ne (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx)) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ List.TFAE [‖inner x y‖ = ‖x‖ * ‖y‖, x = 0 ∨ y = (inner x y / inner x x) • x, x = 0 ∨ ∃ r, y = r • x, x = 0 ∨ y ∈ Submodule.span 𝕜 {x}] [PROOFSTEP] tfae_have 1 → 2 [GOAL] case tfae_1_to_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x [PROOFSTEP] refine' fun h => or_iff_not_imp_left.2 fun hx₀ => _ [GOAL] case tfae_1_to_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ‖inner x y‖ = ‖x‖ * ‖y‖ hx₀ : ¬x = 0 ⊢ y = (inner x y / inner x x) • x [PROOFSTEP] have : ‖x‖ ^ 2 ≠ 0 := pow_ne_zero _ (norm_ne_zero_iff.2 hx₀) [GOAL] case tfae_1_to_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ‖inner x y‖ = ‖x‖ * ‖y‖ hx₀ : ¬x = 0 this : ‖x‖ ^ 2 ≠ 0 ⊢ y = (inner x y / inner x x) • x [PROOFSTEP] rw [← sq_eq_sq (norm_nonneg _) (mul_nonneg (norm_nonneg _) (norm_nonneg _)), mul_pow, ← mul_right_inj' this, eq_comm, ← sub_eq_zero, ← mul_sub] at h [GOAL] case tfae_1_to_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h✝ : ‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2) = ‖x‖ ^ 2 * ‖inner x y‖ ^ 2 h : ‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2 - ‖inner x y‖ ^ 2) = 0 hx₀ : ¬x = 0 this : ‖x‖ ^ 2 ≠ 0 ⊢ y = (inner x y / inner x x) • x [PROOFSTEP] simp only [@norm_sq_eq_inner 𝕜] at h [GOAL] case tfae_1_to_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h✝ : ‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2) = ‖x‖ ^ 2 * ‖inner x y‖ ^ 2 hx₀ : ¬x = 0 this : ‖x‖ ^ 2 ≠ 0 h : ↑re (inner x x) * (↑re (inner x x) * ↑re (inner y y) - ‖inner x y‖ ^ 2) = 0 ⊢ y = (inner x y / inner x x) • x [PROOFSTEP] letI : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore [GOAL] case tfae_1_to_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h✝ : ‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2) = ‖x‖ ^ 2 * ‖inner x y‖ ^ 2 hx₀ : ¬x = 0 this✝ : ‖x‖ ^ 2 ≠ 0 h : ↑re (inner x x) * (↑re (inner x x) * ↑re (inner y y) - ‖inner x y‖ ^ 2) = 0 this : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore ⊢ y = (inner x y / inner x x) • x [PROOFSTEP] erw [← InnerProductSpace.Core.cauchy_schwarz_aux, InnerProductSpace.Core.normSq_eq_zero, sub_eq_zero] at h [GOAL] case tfae_1_to_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h✝ : ‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2) = ‖x‖ ^ 2 * ‖inner x y‖ ^ 2 hx₀ : ¬x = 0 this✝ : ‖x‖ ^ 2 ≠ 0 this : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore h : inner x y • x = inner x x • y ⊢ y = (inner x y / inner x x) • x [PROOFSTEP] rw [div_eq_inv_mul, mul_smul, h, inv_smul_smul₀] [GOAL] case tfae_1_to_2.hc 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h✝ : ‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2) = ‖x‖ ^ 2 * ‖inner x y‖ ^ 2 hx₀ : ¬x = 0 this✝ : ‖x‖ ^ 2 ≠ 0 this : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore h : inner x y • x = inner x x • y ⊢ inner x x ≠ 0 [PROOFSTEP] rwa [inner_self_ne_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E tfae_1_to_2 : ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x ⊢ List.TFAE [‖inner x y‖ = ‖x‖ * ‖y‖, x = 0 ∨ y = (inner x y / inner x x) • x, x = 0 ∨ ∃ r, y = r • x, x = 0 ∨ y ∈ Submodule.span 𝕜 {x}] [PROOFSTEP] tfae_have 2 → 3 [GOAL] case tfae_2_to_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E tfae_1_to_2 : ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x ⊢ x = 0 ∨ y = (inner x y / inner x x) • x → x = 0 ∨ ∃ r, y = r • x 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E tfae_1_to_2 : ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x tfae_2_to_3 : x = 0 ∨ y = (inner x y / inner x x) • x → x = 0 ∨ ∃ r, y = r • x ⊢ List.TFAE [‖inner x y‖ = ‖x‖ * ‖y‖, x = 0 ∨ y = (inner x y / inner x x) • x, x = 0 ∨ ∃ r, y = r • x, x = 0 ∨ y ∈ Submodule.span 𝕜 {x}] [PROOFSTEP] exact fun h => h.imp_right fun h' => ⟨_, h'⟩ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E tfae_1_to_2 : ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x tfae_2_to_3 : x = 0 ∨ y = (inner x y / inner x x) • x → x = 0 ∨ ∃ r, y = r • x ⊢ List.TFAE [‖inner x y‖ = ‖x‖ * ‖y‖, x = 0 ∨ y = (inner x y / inner x x) • x, x = 0 ∨ ∃ r, y = r • x, x = 0 ∨ y ∈ Submodule.span 𝕜 {x}] [PROOFSTEP] tfae_have 3 → 1 [GOAL] case tfae_3_to_1 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E tfae_1_to_2 : ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x tfae_2_to_3 : x = 0 ∨ y = (inner x y / inner x x) • x → x = 0 ∨ ∃ r, y = r • x ⊢ (x = 0 ∨ ∃ r, y = r • x) → ‖inner x y‖ = ‖x‖ * ‖y‖ [PROOFSTEP] rintro (rfl | ⟨r, rfl⟩) [GOAL] case tfae_3_to_1.inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E y : E tfae_1_to_2 : ‖inner 0 y‖ = ‖0‖ * ‖y‖ → 0 = 0 ∨ y = (inner 0 y / inner 0 0) • 0 tfae_2_to_3 : 0 = 0 ∨ y = (inner 0 y / inner 0 0) • 0 → 0 = 0 ∨ ∃ r, y = r • 0 ⊢ ‖inner 0 y‖ = ‖0‖ * ‖y‖ [PROOFSTEP] simp [inner_smul_right, norm_smul, inner_self_eq_norm_sq_to_K, inner_self_eq_norm_mul_norm, sq, mul_left_comm] [GOAL] case tfae_3_to_1.inr.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E r : 𝕜 tfae_1_to_2 : ‖inner x (r • x)‖ = ‖x‖ * ‖r • x‖ → x = 0 ∨ r • x = (inner x (r • x) / inner x x) • x tfae_2_to_3 : x = 0 ∨ r • x = (inner x (r • x) / inner x x) • x → x = 0 ∨ ∃ r_1, r • x = r_1 • x ⊢ ‖inner x (r • x)‖ = ‖x‖ * ‖r • x‖ [PROOFSTEP] simp [inner_smul_right, norm_smul, inner_self_eq_norm_sq_to_K, inner_self_eq_norm_mul_norm, sq, mul_left_comm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E tfae_1_to_2 : ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x tfae_2_to_3 : x = 0 ∨ y = (inner x y / inner x x) • x → x = 0 ∨ ∃ r, y = r • x tfae_3_to_1 : (x = 0 ∨ ∃ r, y = r • x) → ‖inner x y‖ = ‖x‖ * ‖y‖ ⊢ List.TFAE [‖inner x y‖ = ‖x‖ * ‖y‖, x = 0 ∨ y = (inner x y / inner x x) • x, x = 0 ∨ ∃ r, y = r • x, x = 0 ∨ y ∈ Submodule.span 𝕜 {x}] [PROOFSTEP] tfae_have 3 ↔ 4 [GOAL] case tfae_3_iff_4 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E tfae_1_to_2 : ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x tfae_2_to_3 : x = 0 ∨ y = (inner x y / inner x x) • x → x = 0 ∨ ∃ r, y = r • x tfae_3_to_1 : (x = 0 ∨ ∃ r, y = r • x) → ‖inner x y‖ = ‖x‖ * ‖y‖ ⊢ (x = 0 ∨ ∃ r, y = r • x) ↔ x = 0 ∨ y ∈ Submodule.span 𝕜 {x} [PROOFSTEP] simp only [Submodule.mem_span_singleton, eq_comm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E tfae_1_to_2 : ‖inner x y‖ = ‖x‖ * ‖y‖ → x = 0 ∨ y = (inner x y / inner x x) • x tfae_2_to_3 : x = 0 ∨ y = (inner x y / inner x x) • x → x = 0 ∨ ∃ r, y = r • x tfae_3_to_1 : (x = 0 ∨ ∃ r, y = r • x) → ‖inner x y‖ = ‖x‖ * ‖y‖ tfae_3_iff_4 : (x = 0 ∨ ∃ r, y = r • x) ↔ x = 0 ∨ y ∈ Submodule.span 𝕜 {x} ⊢ List.TFAE [‖inner x y‖ = ‖x‖ * ‖y‖, x = 0 ∨ y = (inner x y / inner x x) • x, x = 0 ∨ ∃ r, y = r • x, x = 0 ∨ y ∈ Submodule.span 𝕜 {x}] [PROOFSTEP] tfae_finish [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 ↔ x ≠ 0 ∧ ∃ r, r ≠ 0 ∧ y = r • x [PROOFSTEP] constructor [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 → x ≠ 0 ∧ ∃ r, r ≠ 0 ∧ y = r • x [PROOFSTEP] intro h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 ⊢ x ≠ 0 ∧ ∃ r, r ≠ 0 ∧ y = r • x [PROOFSTEP] have hx₀ : x ≠ 0 := fun h₀ => by simp [h₀] at h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 h₀ : x = 0 ⊢ False [PROOFSTEP] simp [h₀] at h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 hx₀ : x ≠ 0 ⊢ x ≠ 0 ∧ ∃ r, r ≠ 0 ∧ y = r • x [PROOFSTEP] have hy₀ : y ≠ 0 := fun h₀ => by simp [h₀] at h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 hx₀ : x ≠ 0 h₀ : y = 0 ⊢ False [PROOFSTEP] simp [h₀] at h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 hx₀ : x ≠ 0 hy₀ : y ≠ 0 ⊢ x ≠ 0 ∧ ∃ r, r ≠ 0 ∧ y = r • x [PROOFSTEP] refine' ⟨hx₀, (norm_inner_eq_norm_iff hx₀ hy₀).1 <| eq_of_div_eq_one _⟩ [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h : ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 hx₀ : x ≠ 0 hy₀ : y ≠ 0 ⊢ ‖inner x y‖ / (‖x‖ * ‖y‖) = 1 [PROOFSTEP] simpa using h [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ (x ≠ 0 ∧ ∃ r, r ≠ 0 ∧ y = r • x) → ‖inner x y / (↑‖x‖ * ↑‖y‖)‖ = 1 [PROOFSTEP] rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩ [GOAL] case mpr.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E hx : x ≠ 0 r : 𝕜 hr : r ≠ 0 ⊢ ‖inner x (r • x) / (↑‖x‖ * ↑‖r • x‖)‖ = 1 [PROOFSTEP] simp only [norm_div, norm_mul, norm_ofReal, abs_norm] [GOAL] case mpr.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E hx : x ≠ 0 r : 𝕜 hr : r ≠ 0 ⊢ ‖inner x (r • x)‖ / (‖x‖ * ‖r • x‖) = 1 [PROOFSTEP] exact norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 ⊢ inner x y = ↑‖x‖ * ↑‖y‖ ↔ (↑‖y‖ / ↑‖x‖) • x = y [PROOFSTEP] have h₀' := h₀ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ h₀' : x ≠ 0 ⊢ inner x y = ↑‖x‖ * ↑‖y‖ ↔ (↑‖y‖ / ↑‖x‖) • x = y [PROOFSTEP] rw [← norm_ne_zero_iff, Ne.def, ← @ofReal_eq_zero 𝕜] at h₀' [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 ⊢ inner x y = ↑‖x‖ * ↑‖y‖ ↔ (↑‖y‖ / ↑‖x‖) • x = y [PROOFSTEP] constructor [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 ⊢ inner x y = ↑‖x‖ * ↑‖y‖ → (↑‖y‖ / ↑‖x‖) • x = y [PROOFSTEP] intro h [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 ⊢ (↑‖y‖ / ↑‖x‖) • x = y → inner x y = ↑‖x‖ * ↑‖y‖ [PROOFSTEP] intro h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : inner x y = ↑‖x‖ * ↑‖y‖ ⊢ (↑‖y‖ / ↑‖x‖) • x = y [PROOFSTEP] have : x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫ : 𝕜) • x := ((@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 1).1 (by simp [h]) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : inner x y = ↑‖x‖ * ↑‖y‖ ⊢ ‖inner x y‖ = ‖x‖ * ‖y‖ [PROOFSTEP] simp [h] [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : inner x y = ↑‖x‖ * ↑‖y‖ this : x = 0 ∨ y = (inner x y / inner x x) • x ⊢ (↑‖y‖ / ↑‖x‖) • x = y [PROOFSTEP] rw [this.resolve_left h₀, h] [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : inner x y = ↑‖x‖ * ↑‖y‖ this : x = 0 ∨ y = (inner x y / inner x x) • x ⊢ (↑‖(↑‖x‖ * ↑‖y‖ / inner x x) • x‖ / ↑‖x‖) • x = (↑‖x‖ * ↑‖y‖ / inner x x) • x [PROOFSTEP] simp [norm_smul, inner_self_ofReal_norm, mul_div_cancel _ h₀'] [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : (↑‖y‖ / ↑‖x‖) • x = y ⊢ inner x y = ↑‖x‖ * ↑‖y‖ [PROOFSTEP] conv_lhs => rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : (↑‖y‖ / ↑‖x‖) • x = y | inner x y [PROOFSTEP] rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : (↑‖y‖ / ↑‖x‖) • x = y | inner x y [PROOFSTEP] rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : (↑‖y‖ / ↑‖x‖) • x = y | inner x y [PROOFSTEP] rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K] [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 h₀' : ¬↑‖x‖ = 0 h : (↑‖y‖ / ↑‖x‖) • x = y ⊢ ↑‖y‖ / ↑‖x‖ * ↑‖x‖ ^ 2 = ↑‖x‖ * ↑‖y‖ [PROOFSTEP] field_simp [sq, mul_left_comm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ inner x y = ↑‖x‖ * ↑‖y‖ ↔ ↑‖y‖ • x = ↑‖x‖ • y [PROOFSTEP] rcases eq_or_ne x 0 with (rfl | h₀) [GOAL] case inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E y : E ⊢ inner 0 y = ↑‖0‖ * ↑‖y‖ ↔ ↑‖y‖ • 0 = ↑‖0‖ • y [PROOFSTEP] simp [GOAL] case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 ⊢ inner x y = ↑‖x‖ * ↑‖y‖ ↔ ↑‖y‖ • x = ↑‖x‖ • y [PROOFSTEP] rw [inner_eq_norm_mul_iff_div h₀, div_eq_inv_mul, mul_smul, inv_smul_eq_iff₀] [GOAL] case inr.ha 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E h₀ : x ≠ 0 ⊢ ↑‖x‖ ≠ 0 [PROOFSTEP] rwa [Ne.def, ofReal_eq_zero, norm_eq_zero] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner x y / (‖x‖ * ‖y‖) = 1 ↔ x ≠ 0 ∧ ∃ r, 0 < r ∧ y = r • x [PROOFSTEP] constructor [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner x y / (‖x‖ * ‖y‖) = 1 → x ≠ 0 ∧ ∃ r, 0 < r ∧ y = r • x [PROOFSTEP] intro h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner x y / (‖x‖ * ‖y‖) = 1 ⊢ x ≠ 0 ∧ ∃ r, 0 < r ∧ y = r • x [PROOFSTEP] have hx₀ : x ≠ 0 := fun h₀ => by simp [h₀] at h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner x y / (‖x‖ * ‖y‖) = 1 h₀ : x = 0 ⊢ False [PROOFSTEP] simp [h₀] at h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner x y / (‖x‖ * ‖y‖) = 1 hx₀ : x ≠ 0 ⊢ x ≠ 0 ∧ ∃ r, 0 < r ∧ y = r • x [PROOFSTEP] have hy₀ : y ≠ 0 := fun h₀ => by simp [h₀] at h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner x y / (‖x‖ * ‖y‖) = 1 hx₀ : x ≠ 0 h₀ : y = 0 ⊢ False [PROOFSTEP] simp [h₀] at h [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner x y / (‖x‖ * ‖y‖) = 1 hx₀ : x ≠ 0 hy₀ : y ≠ 0 ⊢ x ≠ 0 ∧ ∃ r, 0 < r ∧ y = r • x [PROOFSTEP] refine' ⟨hx₀, ‖y‖ / ‖x‖, div_pos (norm_pos_iff.2 hy₀) (norm_pos_iff.2 hx₀), _⟩ [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F h : inner x y / (‖x‖ * ‖y‖) = 1 hx₀ : x ≠ 0 hy₀ : y ≠ 0 ⊢ y = (‖y‖ / ‖x‖) • x [PROOFSTEP] exact ((inner_eq_norm_mul_iff_div hx₀).1 (eq_of_div_eq_one h)).symm [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ (x ≠ 0 ∧ ∃ r, 0 < r ∧ y = r • x) → inner x y / (‖x‖ * ‖y‖) = 1 [PROOFSTEP] rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩ [GOAL] case mpr.intro.intro.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : F hx : x ≠ 0 r : ℝ hr : 0 < r ⊢ inner x (r • x) / (‖x‖ * ‖r • x‖) = 1 [PROOFSTEP] exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ inner x y / (‖x‖ * ‖y‖) = -1 ↔ x ≠ 0 ∧ ∃ r, r < 0 ∧ y = r • x [PROOFSTEP] rw [← neg_eq_iff_eq_neg, ← neg_div, ← inner_neg_right, ← norm_neg y, real_inner_div_norm_mul_norm_eq_one_iff, (@neg_surjective ℝ _).exists] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F ⊢ (x ≠ 0 ∧ ∃ x_1, 0 < -x_1 ∧ -y = -x_1 • x) ↔ x ≠ 0 ∧ ∃ r, r < 0 ∧ y = r • x [PROOFSTEP] refine' Iff.rfl.and (exists_congr fun r => _) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F r : ℝ ⊢ 0 < -r ∧ -y = -r • x ↔ r < 0 ∧ y = r • x [PROOFSTEP] rw [neg_pos, neg_smul, neg_inj] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E hx : ‖x‖ = 1 hy : ‖y‖ = 1 ⊢ inner x y = 1 ↔ x = y [PROOFSTEP] convert inner_eq_norm_mul_iff (𝕜 := 𝕜) (E := E) using 2 [GOAL] case h.e'_1.h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E hx : ‖x‖ = 1 hy : ‖y‖ = 1 ⊢ 1 = ↑‖x‖ * ↑‖y‖ [PROOFSTEP] simp [hx, hy] [GOAL] case h.e'_2.h.e'_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E hx : ‖x‖ = 1 hy : ‖y‖ = 1 ⊢ x = ↑‖y‖ • x [PROOFSTEP] simp [hx, hy] [GOAL] case h.e'_2.h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E hx : ‖x‖ = 1 hy : ‖y‖ = 1 ⊢ y = ↑‖x‖ • y [PROOFSTEP] simp [hx, hy] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F hx : ‖x‖ = 1 hy : ‖y‖ = 1 ⊢ inner x y < 1 ↔ x ≠ y [PROOFSTEP] convert inner_lt_norm_mul_iff_real (F := F) [GOAL] case h.e'_1.h.e'_4 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F hx : ‖x‖ = 1 hy : ‖y‖ = 1 ⊢ 1 = ‖x‖ * ‖y‖ [PROOFSTEP] simp [hx, hy] [GOAL] case h.e'_2.h.e'_2 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F hx : ‖x‖ = 1 hy : ‖y‖ = 1 ⊢ x = ‖y‖ • x [PROOFSTEP] simp [hx, hy] [GOAL] case h.e'_2.h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : F hx : ‖x‖ = 1 hy : ‖y‖ = 1 ⊢ y = ‖x‖ • y [PROOFSTEP] simp [hx, hy] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι₁ : Type u_4 s₁ : Finset ι₁ w₁ : ι₁ → ℝ v₁ : ι₁ → F h₁ : ∑ i in s₁, w₁ i = 0 ι₂ : Type u_5 s₂ : Finset ι₂ w₂ : ι₂ → ℝ v₂ : ι₂ → F h₂ : ∑ i in s₂, w₂ i = 0 ⊢ inner (∑ i₁ in s₁, w₁ i₁ • v₁ i₁) (∑ i₂ in s₂, w₂ i₂ • v₂ i₂) = (-∑ i₁ in s₁, ∑ i₂ in s₂, w₁ i₁ * w₂ i₂ * (‖v₁ i₁ - v₂ i₂‖ * ‖v₁ i₁ - v₂ i₂‖)) / 2 [PROOFSTEP] simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two, ← div_sub_div_same, ← div_add_div_same, mul_sub_left_distrib, left_distrib, Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.sum_mul, h₁, h₂, zero_mul, mul_zero, Finset.sum_const_zero, zero_add, zero_sub, Finset.mul_sum, neg_div, Finset.sum_div, mul_div_assoc, mul_assoc] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ‖↑(↑(innerₛₗ 𝕜) x) y‖ ≤ 1 * ‖x‖ * ‖y‖ [PROOFSTEP] simp only [norm_inner_le_norm, one_mul, innerₛₗ_apply] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ‖↑(innerSL 𝕜) x‖ = ‖x‖ [PROOFSTEP] refine' le_antisymm ((innerSL 𝕜 x).op_norm_le_bound (norm_nonneg _) fun y => norm_inner_le_norm _ _) _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ‖x‖ ≤ ‖↑(innerSL 𝕜) x‖ [PROOFSTEP] rcases eq_or_ne x 0 with (rfl | h) [GOAL] case inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ⊢ ‖0‖ ≤ ‖↑(innerSL 𝕜) 0‖ [PROOFSTEP] simp [GOAL] case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E h : x ≠ 0 ⊢ ‖x‖ ≤ ‖↑(innerSL 𝕜) x‖ [PROOFSTEP] refine' (mul_le_mul_right (norm_pos_iff.2 h)).mp _ [GOAL] case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E h : x ≠ 0 ⊢ ‖x‖ * ‖x‖ ≤ ‖↑(innerSL 𝕜) x‖ * ‖x‖ [PROOFSTEP] calc ‖x‖ * ‖x‖ = ‖(⟪x, x⟫ : 𝕜)‖ := by rw [← sq, inner_self_eq_norm_sq_to_K, norm_pow, norm_ofReal, abs_norm] _ ≤ ‖innerSL 𝕜 x‖ * ‖x‖ := (innerSL 𝕜 x).le_op_norm _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E h : x ≠ 0 ⊢ ‖x‖ * ‖x‖ = ‖inner x x‖ [PROOFSTEP] rw [← sq, inner_self_eq_norm_sq_to_K, norm_pow, norm_ofReal, abs_norm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E E' : Type u_4 inst✝¹ : NormedAddCommGroup E' inst✝ : InnerProductSpace 𝕜 E' f : E →L[𝕜] E' v : E' ⊢ ‖↑(↑toSesqForm f) v‖ ≤ ‖f‖ * ‖v‖ [PROOFSTEP] refine' op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E E' : Type u_4 inst✝¹ : NormedAddCommGroup E' inst✝ : InnerProductSpace 𝕜 E' f : E →L[𝕜] E' v : E' ⊢ ∀ (x : E), ‖↑(↑(↑toSesqForm f) v) x‖ ≤ ‖f‖ * ‖v‖ * ‖x‖ [PROOFSTEP] intro x [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E E' : Type u_4 inst✝¹ : NormedAddCommGroup E' inst✝ : InnerProductSpace 𝕜 E' f : E →L[𝕜] E' v : E' x : E ⊢ ‖↑(↑(↑toSesqForm f) v) x‖ ≤ ‖f‖ * ‖v‖ * ‖x‖ [PROOFSTEP] have h₁ : ‖f x‖ ≤ ‖f‖ * ‖x‖ := le_op_norm _ _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E E' : Type u_4 inst✝¹ : NormedAddCommGroup E' inst✝ : InnerProductSpace 𝕜 E' f : E →L[𝕜] E' v : E' x : E h₁ : ‖↑f x‖ ≤ ‖f‖ * ‖x‖ ⊢ ‖↑(↑(↑toSesqForm f) v) x‖ ≤ ‖f‖ * ‖v‖ * ‖x‖ [PROOFSTEP] have h₂ := @norm_inner_le_norm 𝕜 E' _ _ _ v (f x) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E E' : Type u_4 inst✝¹ : NormedAddCommGroup E' inst✝ : InnerProductSpace 𝕜 E' f : E →L[𝕜] E' v : E' x : E h₁ : ‖↑f x‖ ≤ ‖f‖ * ‖x‖ h₂ : ‖inner v (↑f x)‖ ≤ ‖v‖ * ‖↑f x‖ ⊢ ‖↑(↑(↑toSesqForm f) v) x‖ ≤ ‖f‖ * ‖v‖ * ‖x‖ [PROOFSTEP] calc ‖⟪v, f x⟫‖ ≤ ‖v‖ * ‖f x‖ := h₂ _ ≤ ‖v‖ * (‖f‖ * ‖x‖) := (mul_le_mul_of_nonneg_left h₁ (norm_nonneg v)) _ = ‖f‖ * ‖v‖ * ‖x‖ := by ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E E' : Type u_4 inst✝¹ : NormedAddCommGroup E' inst✝ : InnerProductSpace 𝕜 E' f : E →L[𝕜] E' v : E' x : E h₁ : ‖↑f x‖ ≤ ‖f‖ * ‖x‖ h₂ : ‖inner v (↑f x)‖ ≤ ‖v‖ * ‖↑f x‖ ⊢ ‖v‖ * (‖f‖ * ‖x‖) = ‖f‖ * ‖v‖ * ‖x‖ [PROOFSTEP] ring [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁵ : IsROrC 𝕜 inst✝⁴ : NormedAddCommGroup E inst✝³ : InnerProductSpace 𝕜 E inst✝² : NormedAddCommGroup F inst✝¹ : InnerProductSpace ℝ F dec_E : DecidableEq E inst✝ : NormedSpace ℝ E r : ℝ x y : E ⊢ inner (r • x, y).fst (r • x, y).snd = r • inner (x, y).fst (x, y).snd [PROOFSTEP] simp only [← algebraMap_smul 𝕜 r x, algebraMap_eq_ofReal, inner_smul_real_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁵ : IsROrC 𝕜 inst✝⁴ : NormedAddCommGroup E inst✝³ : InnerProductSpace 𝕜 E inst✝² : NormedAddCommGroup F inst✝¹ : InnerProductSpace ℝ F dec_E : DecidableEq E inst✝ : NormedSpace ℝ E r : ℝ x y : E ⊢ inner (x, r • y).fst (x, r • y).snd = r • inner (x, y).fst (x, y).snd [PROOFSTEP] simp only [← algebraMap_smul 𝕜 r y, algebraMap_eq_ofReal, inner_smul_real_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁵ : IsROrC 𝕜 inst✝⁴ : NormedAddCommGroup E inst✝³ : InnerProductSpace 𝕜 E inst✝² : NormedAddCommGroup F inst✝¹ : InnerProductSpace ℝ F dec_E : DecidableEq E inst✝ : NormedSpace ℝ E x y : E ⊢ ‖inner (x, y).fst (x, y).snd‖ ≤ 1 * ‖x‖ * ‖y‖ [PROOFSTEP] rw [one_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁵ : IsROrC 𝕜 inst✝⁴ : NormedAddCommGroup E inst✝³ : InnerProductSpace 𝕜 E inst✝² : NormedAddCommGroup F inst✝¹ : InnerProductSpace ℝ F dec_E : DecidableEq E inst✝ : NormedSpace ℝ E x y : E ⊢ ‖inner (x, y).fst (x, y).snd‖ ≤ ‖x‖ * ‖y‖ [PROOFSTEP] exact norm_inner_le_norm x y [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v ⊢ ∑ i in s, ‖inner (v i) x‖ ^ 2 ≤ ‖x‖ ^ 2 [PROOFSTEP] have h₂ : (∑ i in s, ∑ j in s, ⟪v i, x⟫ * ⟪x, v j⟫ * ⟪v j, v i⟫) = (∑ k in s, ⟪v k, x⟫ * ⟪x, v k⟫ : 𝕜) := by classical exact hv.inner_left_right_finset [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v ⊢ ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) [PROOFSTEP] classical exact hv.inner_left_right_finset [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v ⊢ ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) [PROOFSTEP] exact hv.inner_left_right_finset [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) ⊢ ∑ i in s, ‖inner (v i) x‖ ^ 2 ≤ ‖x‖ ^ 2 [PROOFSTEP] have h₃ : ∀ z : 𝕜, re (z * conj z) = ‖z‖ ^ 2 := by intro z simp only [mul_conj, normSq_eq_def'] norm_cast [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) ⊢ ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 [PROOFSTEP] intro z [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) z : 𝕜 ⊢ ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 [PROOFSTEP] simp only [mul_conj, normSq_eq_def'] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) z : 𝕜 ⊢ ↑re ↑(‖z‖ ^ 2) = ‖z‖ ^ 2 [PROOFSTEP] norm_cast [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) h₃ : ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 ⊢ ∑ i in s, ‖inner (v i) x‖ ^ 2 ≤ ‖x‖ ^ 2 [PROOFSTEP] suffices hbf : ‖x - ∑ i in s, ⟪v i, x⟫ • v i‖ ^ 2 = ‖x‖ ^ 2 - ∑ i in s, ‖⟪v i, x⟫‖ ^ 2 [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) h₃ : ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 hbf : ‖x - ∑ i in s, inner (v i) x • v i‖ ^ 2 = ‖x‖ ^ 2 - ∑ i in s, ‖inner (v i) x‖ ^ 2 ⊢ ∑ i in s, ‖inner (v i) x‖ ^ 2 ≤ ‖x‖ ^ 2 [PROOFSTEP] rw [← sub_nonneg, ← hbf] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) h₃ : ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 hbf : ‖x - ∑ i in s, inner (v i) x • v i‖ ^ 2 = ‖x‖ ^ 2 - ∑ i in s, ‖inner (v i) x‖ ^ 2 ⊢ 0 ≤ ‖x - ∑ i in s, inner (v i) x • v i‖ ^ 2 [PROOFSTEP] simp only [norm_nonneg, pow_nonneg] [GOAL] case hbf 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) h₃ : ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 ⊢ ‖x - ∑ i in s, inner (v i) x • v i‖ ^ 2 = ‖x‖ ^ 2 - ∑ i in s, ‖inner (v i) x‖ ^ 2 [PROOFSTEP] rw [@norm_sub_sq 𝕜, sub_add] [GOAL] case hbf 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) h₃ : ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 ⊢ ‖x‖ ^ 2 - (2 * ↑re (inner x (∑ i in s, inner (v i) x • v i)) - ‖∑ i in s, inner (v i) x • v i‖ ^ 2) = ‖x‖ ^ 2 - ∑ i in s, ‖inner (v i) x‖ ^ 2 [PROOFSTEP] classical simp only [@InnerProductSpace.norm_sq_eq_inner 𝕜, _root_.inner_sum, _root_.sum_inner] simp only [inner_smul_right, two_mul, inner_smul_left, inner_conj_symm, ← mul_assoc, h₂, add_sub_cancel, sub_right_inj] simp only [map_sum, ← inner_conj_symm x, ← h₃] [GOAL] case hbf 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) h₃ : ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 ⊢ ‖x‖ ^ 2 - (2 * ↑re (inner x (∑ i in s, inner (v i) x • v i)) - ‖∑ i in s, inner (v i) x • v i‖ ^ 2) = ‖x‖ ^ 2 - ∑ i in s, ‖inner (v i) x‖ ^ 2 [PROOFSTEP] simp only [@InnerProductSpace.norm_sq_eq_inner 𝕜, _root_.inner_sum, _root_.sum_inner] [GOAL] case hbf 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) h₃ : ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 ⊢ ↑re (inner x x) - (2 * ↑re (∑ i in s, inner x (inner (v i) x • v i)) - ↑re (∑ x_1 in s, ∑ i in s, inner (inner (v i) x • v i) (inner (v x_1) x • v x_1))) = ↑re (inner x x) - ∑ i in s, ‖inner (v i) x‖ ^ 2 [PROOFSTEP] simp only [inner_smul_right, two_mul, inner_smul_left, inner_conj_symm, ← mul_assoc, h₂, add_sub_cancel, sub_right_inj] [GOAL] case hbf 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E s : Finset ι hv : Orthonormal 𝕜 v h₂ : ∑ i in s, ∑ j in s, inner (v i) x * inner x (v j) * inner (v j) (v i) = ∑ k in s, inner (v k) x * inner x (v k) h₃ : ∀ (z : 𝕜), ↑re (z * ↑(starRingEnd 𝕜) z) = ‖z‖ ^ 2 ⊢ ↑re (∑ x_1 in s, inner (v x_1) x * inner x (v x_1)) = ∑ i in s, ‖inner (v i) x‖ ^ 2 [PROOFSTEP] simp only [map_sum, ← inner_conj_symm x, ← h₃] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v ⊢ ∑' (i : ι), ‖inner (v i) x‖ ^ 2 ≤ ‖x‖ ^ 2 [PROOFSTEP] refine' tsum_le_of_sum_le' _ fun s => hv.sum_inner_products_le x [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v ⊢ 0 ≤ ‖x‖ ^ 2 [PROOFSTEP] simp only [norm_nonneg, pow_nonneg] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v ⊢ Summable fun i => ‖inner (v i) x‖ ^ 2 [PROOFSTEP] use⨆ s : Finset ι, ∑ i in s, ‖⟪v i, x⟫‖ ^ 2 [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v ⊢ HasSum (fun i => ‖inner (v i) x‖ ^ 2) (⨆ (s : Finset ι), ∑ i in s, ‖inner (v i) x‖ ^ 2) [PROOFSTEP] apply hasSum_of_isLUB_of_nonneg [GOAL] case h.h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v ⊢ ∀ (i : ι), 0 ≤ ‖inner (v i) x‖ ^ 2 [PROOFSTEP] intro b [GOAL] case h.h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v b : ι ⊢ 0 ≤ ‖inner (v b) x‖ ^ 2 [PROOFSTEP] simp only [norm_nonneg, pow_nonneg] [GOAL] case h.hf 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v ⊢ IsLUB (Set.range fun s => ∑ i in s, ‖inner (v i) x‖ ^ 2) (⨆ (s : Finset ι), ∑ i in s, ‖inner (v i) x‖ ^ 2) [PROOFSTEP] refine' isLUB_ciSup _ [GOAL] case h.hf 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v ⊢ BddAbove (Set.range fun s => ∑ i in s, ‖inner (v i) x‖ ^ 2) [PROOFSTEP] use‖x‖ ^ 2 [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v ⊢ ‖x‖ ^ 2 ∈ upperBounds (Set.range fun s => ∑ i in s, ‖inner (v i) x‖ ^ 2) [PROOFSTEP] rintro y ⟨s, rfl⟩ [GOAL] case h.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 x : E v : ι → E hv : Orthonormal 𝕜 v s : Finset ι ⊢ (fun s => ∑ i in s, ‖inner (v i) x‖ ^ 2) s ≤ ‖x‖ ^ 2 [PROOFSTEP] exact hv.sum_inner_products_le x [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : 𝕜 ⊢ ‖x‖ ^ 2 = ↑re (inner x x) [PROOFSTEP] simp only [inner] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : 𝕜 ⊢ ‖x‖ ^ 2 = ↑re (↑(starRingEnd 𝕜) x * x) [PROOFSTEP] rw [mul_comm, mul_conj, ofReal_re, normSq_eq_def'] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : 𝕜 ⊢ ↑(starRingEnd 𝕜) (inner y x) = inner x y [PROOFSTEP] simp only [mul_comm, map_mul, starRingEnd_self_apply] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y z : 𝕜 ⊢ inner (x + y) z = inner x z + inner y z [PROOFSTEP] simp only [add_mul, map_add] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y z : 𝕜 ⊢ inner (z • x) y = ↑(starRingEnd 𝕜) z * inner x y [PROOFSTEP] simp only [mul_assoc, smul_eq_mul, map_mul] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) v : ι → E hv : Orthonormal 𝕜 v i j : ι hij : i ≠ j a : (fun _i => 𝕜) i b : (fun _i => 𝕜) j ⊢ inner (↑((fun i => LinearIsometry.toSpanSingleton 𝕜 E (_ : ‖v i‖ = 1)) i) a) (↑((fun i => LinearIsometry.toSpanSingleton 𝕜 E (_ : ‖v i‖ = 1)) j) b) = 0 [PROOFSTEP] simp [inner_smul_left, inner_smul_right, hv.2 hij] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) i j : ι v : G i w : G j ⊢ inner (↑(V i) v) (↑(V j) w) = if i = j then inner (↑(V i) v) (↑(V j) w) else 0 [PROOFSTEP] split_ifs with h [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) i j : ι v : G i w : G j h : i = j ⊢ inner (↑(V i) v) (↑(V j) w) = inner (↑(V i) v) (↑(V j) w) [PROOFSTEP] rfl [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) i j : ι v : G i w : G j h : ¬i = j ⊢ inner (↑(V i) v) (↑(V j) w) = 0 [PROOFSTEP] exact hV h v w [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l : ⨁ (i : ι), G i i : ι v : G i ⊢ (DFinsupp.sum l fun j w => if i = j then inner (↑(V i) v) (↑(V j) w) else 0) = inner v (↑l i) [PROOFSTEP] simp only [DFinsupp.sum, Submodule.coe_inner, Finset.sum_ite_eq, ite_eq_left_iff, DFinsupp.mem_support_toFun] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l : ⨁ (i : ι), G i i : ι v : G i ⊢ (if ↑l i ≠ 0 then inner (↑(V i) v) (↑(V i) (↑l i)) else 0) = inner v (↑l i) [PROOFSTEP] split_ifs with h [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l : ⨁ (i : ι), G i i : ι v : G i h : ↑l i ≠ 0 ⊢ inner (↑(V i) v) (↑(V i) (↑l i)) = inner v (↑l i) [PROOFSTEP] simp only [LinearIsometry.inner_map_map] [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l : ⨁ (i : ι), G i i : ι v : G i h : ¬↑l i ≠ 0 ⊢ 0 = inner v (↑l i) [PROOFSTEP] simp only [of_not_not h, inner_zero_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : Fintype ι l : (i : ι) → G i i : ι v : G i ⊢ inner (↑(V i) v) (∑ j : ι, ↑(V j) (l j)) = inner v (l i) [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : Fintype ι l : (i : ι) → G i i : ι v : G i em✝ : (a : Prop) → Decidable a ⊢ inner (↑(V i) v) (∑ j : ι, ↑(V j) (l j)) = inner v (l i) [PROOFSTEP] calc ⟪V i v, ∑ j : ι, V j (l j)⟫ = ∑ j : ι, ⟪V i v, V j (l j)⟫ := by rw [inner_sum] _ = ∑ j, ite (i = j) ⟪V i v, V j (l j)⟫ 0 := (congr_arg (Finset.sum Finset.univ) <| funext fun j => hV.eq_ite v (l j)) _ = ⟪v, l i⟫ := by simp only [Finset.sum_ite_eq, Finset.mem_univ, (V i).inner_map_map, if_true] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : Fintype ι l : (i : ι) → G i i : ι v : G i em✝ : (a : Prop) → Decidable a ⊢ inner (↑(V i) v) (∑ j : ι, ↑(V j) (l j)) = ∑ j : ι, inner (↑(V i) v) (↑(V j) (l j)) [PROOFSTEP] rw [inner_sum] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : Fintype ι l : (i : ι) → G i i : ι v : G i em✝ : (a : Prop) → Decidable a ⊢ (∑ j : ι, if i = j then inner (↑(V i) v) (↑(V j) (l j)) else 0) = inner v (l i) [PROOFSTEP] simp only [Finset.sum_ite_eq, Finset.mem_univ, (V i).inner_map_map, if_true] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l₁ l₂ : (i : ι) → G i s : Finset ι ⊢ inner (∑ i in s, ↑(V i) (l₁ i)) (∑ j in s, ↑(V j) (l₂ j)) = ∑ i in s, inner (l₁ i) (l₂ i) [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l₁ l₂ : (i : ι) → G i s : Finset ι em✝ : (a : Prop) → Decidable a ⊢ inner (∑ i in s, ↑(V i) (l₁ i)) (∑ j in s, ↑(V j) (l₂ j)) = ∑ i in s, inner (l₁ i) (l₂ i) [PROOFSTEP] calc ⟪∑ i in s, V i (l₁ i), ∑ j in s, V j (l₂ j)⟫ = ∑ j in s, ∑ i in s, ⟪V i (l₁ i), V j (l₂ j)⟫ := by simp only [_root_.sum_inner, _root_.inner_sum] _ = ∑ j in s, ∑ i in s, ite (i = j) ⟪V i (l₁ i), V j (l₂ j)⟫ 0 := by congr with i congr with j apply hV.eq_ite _ = ∑ i in s, ⟪l₁ i, l₂ i⟫ := by simp only [Finset.sum_ite_of_true, Finset.sum_ite_eq', LinearIsometry.inner_map_map, imp_self, imp_true_iff] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l₁ l₂ : (i : ι) → G i s : Finset ι em✝ : (a : Prop) → Decidable a ⊢ inner (∑ i in s, ↑(V i) (l₁ i)) (∑ j in s, ↑(V j) (l₂ j)) = ∑ j in s, ∑ i in s, inner (↑(V i) (l₁ i)) (↑(V j) (l₂ j)) [PROOFSTEP] simp only [_root_.sum_inner, _root_.inner_sum] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l₁ l₂ : (i : ι) → G i s : Finset ι em✝ : (a : Prop) → Decidable a ⊢ ∑ j in s, ∑ i in s, inner (↑(V i) (l₁ i)) (↑(V j) (l₂ j)) = ∑ j in s, ∑ i in s, if i = j then inner (↑(V i) (l₁ i)) (↑(V j) (l₂ j)) else 0 [PROOFSTEP] congr with i [GOAL] case e_f.h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l₁ l₂ : (i : ι) → G i s : Finset ι em✝ : (a : Prop) → Decidable a i : ι ⊢ ∑ i_1 in s, inner (↑(V i_1) (l₁ i_1)) (↑(V i) (l₂ i)) = ∑ i_1 in s, if i_1 = i then inner (↑(V i_1) (l₁ i_1)) (↑(V i) (l₂ i)) else 0 [PROOFSTEP] congr with j [GOAL] case e_f.h.e_f.h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l₁ l₂ : (i : ι) → G i s : Finset ι em✝ : (a : Prop) → Decidable a i j : ι ⊢ inner (↑(V j) (l₁ j)) (↑(V i) (l₂ i)) = if j = i then inner (↑(V j) (l₁ j)) (↑(V i) (l₂ i)) else 0 [PROOFSTEP] apply hV.eq_ite [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l₁ l₂ : (i : ι) → G i s : Finset ι em✝ : (a : Prop) → Decidable a ⊢ (∑ j in s, ∑ i in s, if i = j then inner (↑(V i) (l₁ i)) (↑(V j) (l₂ j)) else 0) = ∑ i in s, inner (l₁ i) (l₂ i) [PROOFSTEP] simp only [Finset.sum_ite_of_true, Finset.sum_ite_eq', LinearIsometry.inner_map_map, imp_self, imp_true_iff] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l : (i : ι) → G i s : Finset ι ⊢ ‖∑ i in s, ↑(V i) (l i)‖ ^ 2 = ∑ i in s, ‖l i‖ ^ 2 [PROOFSTEP] have : ((‖∑ i in s, V i (l i)‖ : ℝ) : 𝕜) ^ 2 = ∑ i in s, ((‖l i‖ : ℝ) : 𝕜) ^ 2 := by simp only [← inner_self_eq_norm_sq_to_K, hV.inner_sum] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l : (i : ι) → G i s : Finset ι ⊢ ↑‖∑ i in s, ↑(V i) (l i)‖ ^ 2 = ∑ i in s, ↑‖l i‖ ^ 2 [PROOFSTEP] simp only [← inner_self_eq_norm_sq_to_K, hV.inner_sum] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) l : (i : ι) → G i s : Finset ι this : ↑‖∑ i in s, ↑(V i) (l i)‖ ^ 2 = ∑ i in s, ↑‖l i‖ ^ 2 ⊢ ‖∑ i in s, ↑(V i) (l i)‖ ^ 2 = ∑ i in s, ‖l i‖ ^ 2 [PROOFSTEP] exact_mod_cast this [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) ⊢ Orthonormal 𝕜 fun a => ↑(V a.fst) (v_family a.fst a.snd) [PROOFSTEP] constructor [GOAL] case left 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) ⊢ ∀ (i : (i : ι) × α i), ‖(fun a => ↑(V a.fst) (v_family a.fst a.snd)) i‖ = 1 [PROOFSTEP] rintro ⟨i, v⟩ [GOAL] case left.mk 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) i : ι v : α i ⊢ ‖(fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := i, snd := v }‖ = 1 [PROOFSTEP] simpa only [LinearIsometry.norm_map] using (hv_family i).left v [GOAL] case right 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) ⊢ ∀ {i j : (i : ι) × α i}, i ≠ j → inner ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) i) ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) j) = 0 [PROOFSTEP] rintro ⟨i, v⟩ ⟨j, w⟩ hvw [GOAL] case right.mk.mk 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) i : ι v : α i j : ι w : α j hvw : { fst := i, snd := v } ≠ { fst := j, snd := w } ⊢ inner ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := i, snd := v }) ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := j, snd := w }) = 0 [PROOFSTEP] by_cases hij : i = j [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) i : ι v : α i j : ι w : α j hvw : { fst := i, snd := v } ≠ { fst := j, snd := w } hij : i = j ⊢ inner ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := i, snd := v }) ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := j, snd := w }) = 0 [PROOFSTEP] subst hij [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) i : ι v w : α i hvw : { fst := i, snd := v } ≠ { fst := i, snd := w } ⊢ inner ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := i, snd := v }) ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := i, snd := w }) = 0 [PROOFSTEP] have : v ≠ w := fun h => by subst h exact hvw rfl [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) i : ι v w : α i hvw : { fst := i, snd := v } ≠ { fst := i, snd := w } h : v = w ⊢ False [PROOFSTEP] subst h [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) i : ι v : α i hvw : { fst := i, snd := v } ≠ { fst := i, snd := v } ⊢ False [PROOFSTEP] exact hvw rfl [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) i : ι v w : α i hvw : { fst := i, snd := v } ≠ { fst := i, snd := w } this : v ≠ w ⊢ inner ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := i, snd := v }) ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := i, snd := w }) = 0 [PROOFSTEP] simpa only [LinearIsometry.inner_map_map] using (hv_family i).2 this [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) α : ι → Type u_6 v_family : (i : ι) → α i → G i hv_family : ∀ (i : ι), Orthonormal 𝕜 (v_family i) i : ι v : α i j : ι w : α j hvw : { fst := i, snd := v } ≠ { fst := j, snd := w } hij : ¬i = j ⊢ inner ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := i, snd := v }) ((fun a => ↑(V a.fst) (v_family a.fst a.snd)) { fst := j, snd := w }) = 0 [PROOFSTEP] exact hV hij (v_family i v) (v_family j w) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι ⊢ ‖∑ i in s₁, ↑(V i) (f i) - ∑ i in s₂, ↑(V i) (f i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 [PROOFSTEP] rw [← Finset.sum_sdiff_sub_sum_sdiff, sub_eq_add_neg, ← Finset.sum_neg_distrib] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι ⊢ ‖∑ x in s₁ \ s₂, ↑(V x) (f x) + ∑ x in s₂ \ s₁, -↑(V x) (f x)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 [PROOFSTEP] let F : ∀ i, G i := fun i => if i ∈ s₁ then f i else -f i [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i ⊢ ‖∑ x in s₁ \ s₂, ↑(V x) (f x) + ∑ x in s₂ \ s₁, -↑(V x) (f x)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 [PROOFSTEP] have hF₁ : ∀ i ∈ s₁ \ s₂, F i = f i := fun i hi => if_pos (Finset.sdiff_subset _ _ hi) [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i ⊢ ‖∑ x in s₁ \ s₂, ↑(V x) (f x) + ∑ x in s₂ \ s₁, -↑(V x) (f x)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 [PROOFSTEP] have hF₂ : ∀ i ∈ s₂ \ s₁, F i = -f i := fun i hi => if_neg (Finset.mem_sdiff.mp hi).2 [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i ⊢ ‖∑ x in s₁ \ s₂, ↑(V x) (f x) + ∑ x in s₂ \ s₁, -↑(V x) (f x)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 [PROOFSTEP] have hF : ∀ i, ‖F i‖ = ‖f i‖ := by intro i dsimp only split_ifs <;> simp only [eq_self_iff_true, norm_neg] [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i ⊢ ∀ (i : ι), ‖F i‖ = ‖f i‖ [PROOFSTEP] intro i [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i i : ι ⊢ ‖F i‖ = ‖f i‖ [PROOFSTEP] dsimp only [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i i : ι ⊢ ‖if i ∈ s₁ then f i else -f i‖ = ‖f i‖ [PROOFSTEP] split_ifs [GOAL] case pos 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i i : ι h✝ : i ∈ s₁ ⊢ ‖f i‖ = ‖f i‖ [PROOFSTEP] simp only [eq_self_iff_true, norm_neg] [GOAL] case neg 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i i : ι h✝ : ¬i ∈ s₁ ⊢ ‖-f i‖ = ‖f i‖ [PROOFSTEP] simp only [eq_self_iff_true, norm_neg] [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ ⊢ ‖∑ x in s₁ \ s₂, ↑(V x) (f x) + ∑ x in s₂ \ s₁, -↑(V x) (f x)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 [PROOFSTEP] have : ‖(∑ i in s₁ \ s₂, V i (F i)) + ∑ i in s₂ \ s₁, V i (F i)‖ ^ 2 = (∑ i in s₁ \ s₂, ‖F i‖ ^ 2) + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 := by have hs : Disjoint (s₁ \ s₂) (s₂ \ s₁) := disjoint_sdiff_sdiff simpa only [Finset.sum_union hs] using hV.norm_sum F (s₁ \ s₂ ∪ s₂ \ s₁) [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ ⊢ ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 [PROOFSTEP] have hs : Disjoint (s₁ \ s₂) (s₂ \ s₁) := disjoint_sdiff_sdiff [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ hs : Disjoint (s₁ \ s₂) (s₂ \ s₁) ⊢ ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 [PROOFSTEP] simpa only [Finset.sum_union hs] using hV.norm_sum F (s₁ \ s₂ ∪ s₂ \ s₁) [GOAL] 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ this : ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 ⊢ ‖∑ x in s₁ \ s₂, ↑(V x) (f x) + ∑ x in s₂ \ s₁, -↑(V x) (f x)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 [PROOFSTEP] convert this using 4 [GOAL] case h.e'_2.h.e'_5.h.e'_3.h.e'_5 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ this : ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 ⊢ ∑ x in s₁ \ s₂, ↑(V x) (f x) = ∑ i in s₁ \ s₂, ↑(V i) (F i) [PROOFSTEP] refine' Finset.sum_congr rfl fun i hi => _ [GOAL] case h.e'_2.h.e'_5.h.e'_3.h.e'_5 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ this : ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 i : ι hi : i ∈ s₁ \ s₂ ⊢ ↑(V i) (f i) = ↑(V i) (F i) [PROOFSTEP] simp only [hF₁ i hi] [GOAL] case h.e'_2.h.e'_5.h.e'_3.h.e'_6 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ this : ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 ⊢ ∑ x in s₂ \ s₁, -↑(V x) (f x) = ∑ i in s₂ \ s₁, ↑(V i) (F i) [PROOFSTEP] refine' Finset.sum_congr rfl fun i hi => _ [GOAL] case h.e'_2.h.e'_5.h.e'_3.h.e'_6 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ this : ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 i : ι hi : i ∈ s₂ \ s₁ ⊢ -↑(V i) (f i) = ↑(V i) (F i) [PROOFSTEP] simp only [hF₂ i hi, LinearIsometry.map_neg] [GOAL] case h.e'_3.h.e'_5.a.h.e'_5 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ this : ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 x✝ : ι a✝ : x✝ ∈ s₁ \ s₂ ⊢ ‖f x✝‖ = ‖F x✝‖ [PROOFSTEP] simp only [hF] [GOAL] case h.e'_3.h.e'_6.a.h.e'_5 𝕜 : Type u_1 E : Type u_2 F✝ : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F✝ inst✝² : InnerProductSpace ℝ F✝ dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) f : (i : ι) → G i s₁ s₂ : Finset ι F : (i : ι) → G i := fun i => if i ∈ s₁ then f i else -f i hF₁ : ∀ (i : ι), i ∈ s₁ \ s₂ → F i = f i hF₂ : ∀ (i : ι), i ∈ s₂ \ s₁ → F i = -f i hF : ∀ (i : ι), ‖F i‖ = ‖f i‖ this : ‖∑ i in s₁ \ s₂, ↑(V i) (F i) + ∑ i in s₂ \ s₁, ↑(V i) (F i)‖ ^ 2 = ∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2 x✝ : ι a✝ : x✝ ∈ s₂ \ s₁ ⊢ ‖f x✝‖ = ‖F x✝‖ [PROOFSTEP] simp only [hF] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i ⊢ (Summable fun i => ↑(V i) (f i)) ↔ Summable fun i => ‖f i‖ ^ 2 [PROOFSTEP] classical clear dec_ι simp only [summable_iff_cauchySeq_finset, NormedAddCommGroup.cauchySeq_iff, Real.norm_eq_abs] constructor · intro hf ε hε obtain ⟨a, H⟩ := hf _ (sqrt_pos.mpr hε) use a intro s₁ hs₁ s₂ hs₂ rw [← Finset.sum_sdiff_sub_sum_sdiff] refine' (abs_sub _ _).trans_lt _ have : ∀ i, 0 ≤ ‖f i‖ ^ 2 := fun i : ι => sq_nonneg _ simp only [Finset.abs_sum_of_nonneg' this] have : ((∑ i in s₁ \ s₂, ‖f i‖ ^ 2) + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2) < sqrt ε ^ 2 := by rw [← hV.norm_sq_diff_sum, sq_lt_sq, abs_of_nonneg (sqrt_nonneg _), abs_of_nonneg (norm_nonneg _)] exact H s₁ hs₁ s₂ hs₂ have hη := sq_sqrt (le_of_lt hε) linarith · intro hf ε hε have hε' : 0 < ε ^ 2 / 2 := half_pos (sq_pos_of_pos hε) obtain ⟨a, H⟩ := hf _ hε' use a intro s₁ hs₁ s₂ hs₂ refine' (abs_lt_of_sq_lt_sq' _ (le_of_lt hε)).2 have has : a ≤ s₁ ⊓ s₂ := le_inf hs₁ hs₂ rw [hV.norm_sq_diff_sum] have Hs₁ : ∑ x : ι in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 := by convert H _ hs₁ _ has have : s₁ ⊓ s₂ ⊆ s₁ := Finset.inter_subset_left _ _ rw [← Finset.sum_sdiff this, add_tsub_cancel_right, Finset.abs_sum_of_nonneg'] · simp · exact fun i => sq_nonneg _ have Hs₂ : ∑ x : ι in s₂ \ s₁, ‖f x‖ ^ 2 < ε ^ 2 / 2 := by convert H _ hs₂ _ has have : s₁ ⊓ s₂ ⊆ s₂ := Finset.inter_subset_right _ _ rw [← Finset.sum_sdiff this, add_tsub_cancel_right, Finset.abs_sum_of_nonneg'] · simp · exact fun i => sq_nonneg _ linarith [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i ⊢ (Summable fun i => ↑(V i) (f i)) ↔ Summable fun i => ‖f i‖ ^ 2 [PROOFSTEP] clear dec_ι [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i ⊢ (Summable fun i => ↑(V i) (f i)) ↔ Summable fun i => ‖f i‖ ^ 2 [PROOFSTEP] simp only [summable_iff_cauchySeq_finset, NormedAddCommGroup.cauchySeq_iff, Real.norm_eq_abs] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i ⊢ (∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε) ↔ ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε [PROOFSTEP] constructor [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i ⊢ (∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε) → ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε [PROOFSTEP] intro hf ε hε [GOAL] case mp 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 ⊢ ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε [PROOFSTEP] obtain ⟨a, H⟩ := hf _ (sqrt_pos.mpr hε) [GOAL] case mp.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε ⊢ ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε [PROOFSTEP] use a [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε ⊢ ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε [PROOFSTEP] intro s₁ hs₁ s₂ hs₂ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ ⊢ |∑ i in s₁, ‖f i‖ ^ 2 - ∑ i in s₂, ‖f i‖ ^ 2| < ε [PROOFSTEP] rw [← Finset.sum_sdiff_sub_sum_sdiff] [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ ⊢ |∑ x in s₁ \ s₂, ‖f x‖ ^ 2 - ∑ x in s₂ \ s₁, ‖f x‖ ^ 2| < ε [PROOFSTEP] refine' (abs_sub _ _).trans_lt _ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ ⊢ |∑ x in s₁ \ s₂, ‖f x‖ ^ 2| + |∑ x in s₂ \ s₁, ‖f x‖ ^ 2| < ε [PROOFSTEP] have : ∀ i, 0 ≤ ‖f i‖ ^ 2 := fun i : ι => sq_nonneg _ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ this : ∀ (i : ι), 0 ≤ ‖f i‖ ^ 2 ⊢ |∑ x in s₁ \ s₂, ‖f x‖ ^ 2| + |∑ x in s₂ \ s₁, ‖f x‖ ^ 2| < ε [PROOFSTEP] simp only [Finset.abs_sum_of_nonneg' this] [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ this : ∀ (i : ι), 0 ≤ ‖f i‖ ^ 2 ⊢ ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 + ∑ x in s₂ \ s₁, ‖f x‖ ^ 2 < ε [PROOFSTEP] have : ((∑ i in s₁ \ s₂, ‖f i‖ ^ 2) + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2) < sqrt ε ^ 2 := by rw [← hV.norm_sq_diff_sum, sq_lt_sq, abs_of_nonneg (sqrt_nonneg _), abs_of_nonneg (norm_nonneg _)] exact H s₁ hs₁ s₂ hs₂ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ this : ∀ (i : ι), 0 ≤ ‖f i‖ ^ 2 ⊢ ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 < sqrt ε ^ 2 [PROOFSTEP] rw [← hV.norm_sq_diff_sum, sq_lt_sq, abs_of_nonneg (sqrt_nonneg _), abs_of_nonneg (norm_nonneg _)] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ this : ∀ (i : ι), 0 ≤ ‖f i‖ ^ 2 ⊢ ‖∑ i in s₁, ↑(V i) (f i) - ∑ i in s₂, ↑(V i) (f i)‖ < sqrt ε [PROOFSTEP] exact H s₁ hs₁ s₂ hs₂ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ this✝ : ∀ (i : ι), 0 ≤ ‖f i‖ ^ 2 this : ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 < sqrt ε ^ 2 ⊢ ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 + ∑ x in s₂ \ s₁, ‖f x‖ ^ 2 < ε [PROOFSTEP] have hη := sq_sqrt (le_of_lt hε) [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε ε : ℝ hε : ε > 0 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < sqrt ε s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ this✝ : ∀ (i : ι), 0 ≤ ‖f i‖ ^ 2 this : ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 < sqrt ε ^ 2 hη : sqrt ε ^ 2 = ε ⊢ ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 + ∑ x in s₂ \ s₁, ‖f x‖ ^ 2 < ε [PROOFSTEP] linarith [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i ⊢ (∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε) → ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε [PROOFSTEP] intro hf ε hε [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 ⊢ ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε [PROOFSTEP] have hε' : 0 < ε ^ 2 / 2 := half_pos (sq_pos_of_pos hε) [GOAL] case mpr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 ⊢ ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε [PROOFSTEP] obtain ⟨a, H⟩ := hf _ hε' [GOAL] case mpr.intro 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 ⊢ ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε [PROOFSTEP] use a [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 ⊢ ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → ‖∑ b in m, ↑(V b) (f b) - ∑ b in n, ↑(V b) (f b)‖ < ε [PROOFSTEP] intro s₁ hs₁ s₂ hs₂ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ ⊢ ‖∑ b in s₁, ↑(V b) (f b) - ∑ b in s₂, ↑(V b) (f b)‖ < ε [PROOFSTEP] refine' (abs_lt_of_sq_lt_sq' _ (le_of_lt hε)).2 [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ ⊢ ‖∑ b in s₁, ↑(V b) (f b) - ∑ b in s₂, ↑(V b) (f b)‖ ^ 2 < ε ^ 2 [PROOFSTEP] have has : a ≤ s₁ ⊓ s₂ := le_inf hs₁ hs₂ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ ⊢ ‖∑ b in s₁, ↑(V b) (f b) - ∑ b in s₂, ↑(V b) (f b)‖ ^ 2 < ε ^ 2 [PROOFSTEP] rw [hV.norm_sq_diff_sum] [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ ⊢ ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 < ε ^ 2 [PROOFSTEP] have Hs₁ : ∑ x : ι in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 := by convert H _ hs₁ _ has have : s₁ ⊓ s₂ ⊆ s₁ := Finset.inter_subset_left _ _ rw [← Finset.sum_sdiff this, add_tsub_cancel_right, Finset.abs_sum_of_nonneg'] · simp · exact fun i => sq_nonneg _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ ⊢ ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 [PROOFSTEP] convert H _ hs₁ _ has [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ ⊢ ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 = |∑ i in s₁, ‖f i‖ ^ 2 - ∑ i in s₁ ⊓ s₂, ‖f i‖ ^ 2| [PROOFSTEP] have : s₁ ⊓ s₂ ⊆ s₁ := Finset.inter_subset_left _ _ [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ this : s₁ ⊓ s₂ ⊆ s₁ ⊢ ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 = |∑ i in s₁, ‖f i‖ ^ 2 - ∑ i in s₁ ⊓ s₂, ‖f i‖ ^ 2| [PROOFSTEP] rw [← Finset.sum_sdiff this, add_tsub_cancel_right, Finset.abs_sum_of_nonneg'] [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ this : s₁ ⊓ s₂ ⊆ s₁ ⊢ ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 = ∑ i in s₁ \ (s₁ ⊓ s₂), ‖f i‖ ^ 2 [PROOFSTEP] simp [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ this : s₁ ⊓ s₂ ⊆ s₁ ⊢ ∀ (i : ι), 0 ≤ ‖f i‖ ^ 2 [PROOFSTEP] exact fun i => sq_nonneg _ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ Hs₁ : ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 ⊢ ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 < ε ^ 2 [PROOFSTEP] have Hs₂ : ∑ x : ι in s₂ \ s₁, ‖f x‖ ^ 2 < ε ^ 2 / 2 := by convert H _ hs₂ _ has have : s₁ ⊓ s₂ ⊆ s₂ := Finset.inter_subset_right _ _ rw [← Finset.sum_sdiff this, add_tsub_cancel_right, Finset.abs_sum_of_nonneg'] · simp · exact fun i => sq_nonneg _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ Hs₁ : ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 ⊢ ∑ x in s₂ \ s₁, ‖f x‖ ^ 2 < ε ^ 2 / 2 [PROOFSTEP] convert H _ hs₂ _ has [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ Hs₁ : ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 ⊢ ∑ x in s₂ \ s₁, ‖f x‖ ^ 2 = |∑ i in s₂, ‖f i‖ ^ 2 - ∑ i in s₁ ⊓ s₂, ‖f i‖ ^ 2| [PROOFSTEP] have : s₁ ⊓ s₂ ⊆ s₂ := Finset.inter_subset_right _ _ [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ Hs₁ : ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 this : s₁ ⊓ s₂ ⊆ s₂ ⊢ ∑ x in s₂ \ s₁, ‖f x‖ ^ 2 = |∑ i in s₂, ‖f i‖ ^ 2 - ∑ i in s₁ ⊓ s₂, ‖f i‖ ^ 2| [PROOFSTEP] rw [← Finset.sum_sdiff this, add_tsub_cancel_right, Finset.abs_sum_of_nonneg'] [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ Hs₁ : ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 this : s₁ ⊓ s₂ ⊆ s₂ ⊢ ∑ x in s₂ \ s₁, ‖f x‖ ^ 2 = ∑ i in s₂ \ (s₁ ⊓ s₂), ‖f i‖ ^ 2 [PROOFSTEP] simp [GOAL] case h.e'_3 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ Hs₁ : ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 this : s₁ ⊓ s₂ ⊆ s₂ ⊢ ∀ (i : ι), 0 ≤ ‖f i‖ ^ 2 [PROOFSTEP] exact fun i => sq_nonneg _ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁷ : IsROrC 𝕜 inst✝⁶ : NormedAddCommGroup E inst✝⁵ : InnerProductSpace 𝕜 E inst✝⁴ : NormedAddCommGroup F inst✝³ : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 G : ι → Type u_5 inst✝² : (i : ι) → NormedAddCommGroup (G i) inst✝¹ : (i : ι) → InnerProductSpace 𝕜 (G i) V : (i : ι) → G i →ₗᵢ[𝕜] E hV : OrthogonalFamily 𝕜 G V dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) inst✝ : CompleteSpace E f : (i : ι) → G i hf : ∀ (ε : ℝ), ε > 0 → ∃ N, ∀ (m : Finset ι), N ≤ m → ∀ (n : Finset ι), N ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ε : ℝ hε : ε > 0 hε' : 0 < ε ^ 2 / 2 a : Finset ι H : ∀ (m : Finset ι), a ≤ m → ∀ (n : Finset ι), a ≤ n → |∑ i in m, ‖f i‖ ^ 2 - ∑ i in n, ‖f i‖ ^ 2| < ε ^ 2 / 2 s₁ : Finset ι hs₁ : a ≤ s₁ s₂ : Finset ι hs₂ : a ≤ s₂ has : a ≤ s₁ ⊓ s₂ Hs₁ : ∑ x in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2 Hs₂ : ∑ x in s₂ \ s₁, ‖f x‖ ^ 2 < ε ^ 2 / 2 ⊢ ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 < ε ^ 2 [PROOFSTEP] linarith [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) ⊢ CompleteLattice.Independent V [PROOFSTEP] classical! [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a ⊢ CompleteLattice.Independent V [PROOFSTEP] apply CompleteLattice.independent_of_dfinsupp_lsum_injective [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a ⊢ Function.Injective ↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) [PROOFSTEP] refine LinearMap.ker_eq_bot.mp ?_ [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a ⊢ LinearMap.ker (↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) = ⊥ [PROOFSTEP] rw [Submodule.eq_bot_iff] [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a ⊢ ∀ (x : Π₀ (i : ι), { x // x ∈ V i }), x ∈ LinearMap.ker (↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) → x = 0 [PROOFSTEP] intro v hv [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a v : Π₀ (i : ι), { x // x ∈ V i } hv : v ∈ LinearMap.ker (↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) ⊢ v = 0 [PROOFSTEP] rw [LinearMap.mem_ker] at hv [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a v : Π₀ (i : ι), { x // x ∈ V i } hv : ↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) v = 0 ⊢ v = 0 [PROOFSTEP] ext i [GOAL] case h.h.a 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a v : Π₀ (i : ι), { x // x ∈ V i } hv : ↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) v = 0 i : ι ⊢ ↑(↑v i) = ↑(↑0 i) [PROOFSTEP] suffices ⟪(v i : E), v i⟫ = 0 by simpa only [inner_self_eq_zero] using this [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a v : Π₀ (i : ι), { x // x ∈ V i } hv : ↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) v = 0 i : ι this : inner ↑(↑v i) ↑(↑v i) = 0 ⊢ ↑(↑v i) = ↑(↑0 i) [PROOFSTEP] simpa only [inner_self_eq_zero] using this [GOAL] case h.h.a 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a v : Π₀ (i : ι), { x // x ∈ V i } hv : ↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) v = 0 i : ι ⊢ inner ↑(↑v i) ↑(↑v i) = 0 [PROOFSTEP] calc ⟪(v i : E), v i⟫ = ⟪(v i : E), DFinsupp.lsum ℕ (fun i => (V i).subtype) v⟫ := by simpa only [DFinsupp.sumAddHom_apply, DFinsupp.lsum_apply_apply] using (hV.inner_right_dfinsupp v i (v i)).symm _ = 0 := by simp only [hv, inner_zero_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a v : Π₀ (i : ι), { x // x ∈ V i } hv : ↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) v = 0 i : ι ⊢ inner ↑(↑v i) ↑(↑v i) = inner (↑(↑v i)) (↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) v) [PROOFSTEP] simpa only [DFinsupp.sumAddHom_apply, DFinsupp.lsum_apply_apply] using (hV.inner_right_dfinsupp v i (v i)).symm [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) em✝ : (a : Prop) → Decidable a v : Π₀ (i : ι), { x // x ∈ V i } hv : ↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) v = 0 i : ι ⊢ inner (↑(↑v i)) (↑(↑(DFinsupp.lsum ℕ) fun i => Submodule.subtype (V i)) v) = 0 [PROOFSTEP] simp only [hv, inner_zero_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E ι : Type u_4 dec_ι : DecidableEq ι G : ι → Type u_5 inst✝¹ : (i : ι) → NormedAddCommGroup (G i) inst✝ : (i : ι) → InnerProductSpace 𝕜 (G i) V✝ : (i : ι) → G i →ₗᵢ[𝕜] E hV✝ : OrthogonalFamily 𝕜 G V✝ dec_V : (i : ι) → (x : G i) → Decidable (x ≠ 0) V : ι → Submodule 𝕜 E hV : OrthogonalFamily 𝕜 (fun i => { x // x ∈ V i }) fun i => Submodule.subtypeₗᵢ (V i) hV_sum : IsInternal fun i => V i α : ι → Type u_6 v_family : (i : ι) → Basis (α i) 𝕜 { x // x ∈ V i } hv_family : ∀ (i : ι), Orthonormal 𝕜 ↑(v_family i) ⊢ Orthonormal 𝕜 ↑(collectedBasis hV_sum v_family) [PROOFSTEP] simpa only [hV_sum.collectedBasis_coe] using hV.orthonormal_sigma_orthonormal hv_family [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E G : Type u_4 src✝¹ : Inner ℝ E := Inner.isROrCToReal 𝕜 E src✝ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E x y z : E ⊢ inner (x + y) z = inner x z + inner y z [PROOFSTEP] change re ⟪x + y, z⟫ = re ⟪x, z⟫ + re ⟪y, z⟫ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E G : Type u_4 src✝¹ : Inner ℝ E := Inner.isROrCToReal 𝕜 E src✝ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E x y z : E ⊢ ↑re (inner (x + y) z) = ↑re (inner x z) + ↑re (inner y z) [PROOFSTEP] simp only [inner_add_left, map_add] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E G : Type u_4 src✝¹ : Inner ℝ E := Inner.isROrCToReal 𝕜 E src✝ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E x y : E r : ℝ ⊢ inner (r • x) y = ↑(starRingEnd ℝ) r * inner x y [PROOFSTEP] change re ⟪(r : 𝕜) • x, y⟫ = r * re ⟪x, y⟫ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E G : Type u_4 src✝¹ : Inner ℝ E := Inner.isROrCToReal 𝕜 E src✝ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E x y : E r : ℝ ⊢ ↑re (inner (↑r • x) y) = r * ↑re (inner x y) [PROOFSTEP] simp only [inner_smul_left, conj_ofReal, ofReal_mul_re] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E G : Type u_4 x : E ⊢ inner x (I • x) = 0 [PROOFSTEP] simp [real_inner_eq_re_inner 𝕜, inner_smul_right] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁶ : IsROrC 𝕜 inst✝⁵ : NormedAddCommGroup E inst✝⁴ : InnerProductSpace 𝕜 E inst✝³ : NormedAddCommGroup F inst✝² : InnerProductSpace ℝ F dec_E : DecidableEq E G : Type u_4 inst✝¹ : NormedAddCommGroup G inst✝ : InnerProductSpace ℝ G f : G ≃ₗᵢ[ℝ] ℂ x y : G ⊢ inner x y = (↑(starRingEnd ℂ) (↑f x) * ↑f y).re [PROOFSTEP] rw [← Complex.inner, f.inner_map_map] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E T : E →L[𝕜] E x : E c : 𝕜 ⊢ reApplyInnerSelf T (c • x) = ‖c‖ ^ 2 * reApplyInnerSelf T x [PROOFSTEP] simp only [ContinuousLinearMap.map_smul, ContinuousLinearMap.reApplyInnerSelf_apply, inner_smul_left, inner_smul_right, ← mul_assoc, mul_conj, normSq_eq_def', ← smul_re, Algebra.smul_def (‖c‖ ^ 2) ⟪T x, x⟫, algebraMap_eq_ofReal] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ⊢ Continuous (uncurry inner) [PROOFSTEP] let inner' : E →+ E →+ 𝕜 := { toFun := fun x => (innerₛₗ 𝕜 x).toAddMonoidHom map_zero' := by ext x; exact inner_zero_left _ map_add' := fun x y => by ext z; exact inner_add_left _ _ _ } [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E ⊢ (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0 [PROOFSTEP] ext x [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : E ⊢ ↑((fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0) x = ↑0 x [PROOFSTEP] exact inner_zero_left _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : E ⊢ ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } (x + y) = ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } x + ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } y [PROOFSTEP] ext z [GOAL] case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y z : E ⊢ ↑(ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } (x + y)) z = ↑(ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } x + ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } y) z [PROOFSTEP] exact inner_add_left _ _ _ [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E inner' : E →+ E →+ 𝕜 := { toZeroHom := { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) }, map_add' := (_ : ∀ (x y : E), ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } (x + y) = ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } x + ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } y) } ⊢ Continuous (uncurry inner) [PROOFSTEP] have : Continuous fun p : E × E => inner' p.1 p.2 := continuous_inner [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E inner' : E →+ E →+ 𝕜 := { toZeroHom := { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) }, map_add' := (_ : ∀ (x y : E), ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } (x + y) = ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } x + ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } y) } this : Continuous fun p => ↑(↑inner' p.fst) p.snd ⊢ Continuous (uncurry inner) [PROOFSTEP] rw [Completion.toInner, inner, uncurry_curry _] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E inner' : E →+ E →+ 𝕜 := { toZeroHom := { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) }, map_add' := (_ : ∀ (x y : E), ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } (x + y) = ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } x + ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } y) } this : Continuous fun p => ↑(↑inner' p.fst) p.snd ⊢ Continuous (DenseInducing.extend (_ : DenseInducing fun p => (↑E p.fst, ↑E p.snd)) (uncurry inner)) [PROOFSTEP] change Continuous (((denseInducing_toCompl E).prod (denseInducing_toCompl E)).extend fun p : E × E => inner' p.1 p.2) [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E inner' : E →+ E →+ 𝕜 := { toZeroHom := { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) }, map_add' := (_ : ∀ (x y : E), ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } (x + y) = ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } x + ZeroHom.toFun { toFun := fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x), map_zero' := (_ : (fun x => LinearMap.toAddMonoidHom (↑(innerₛₗ 𝕜) x)) 0 = 0) } y) } this : Continuous fun p => ↑(↑inner' p.fst) p.snd ⊢ Continuous (DenseInducing.extend (_ : DenseInducing fun p => (↑toCompl p.fst, ↑toCompl p.snd)) fun p => ↑(↑inner' p.fst) p.snd) [PROOFSTEP] exact (denseInducing_toCompl E).extend_Z_bilin (denseInducing_toCompl E) this [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x : Completion E a : E ⊢ ‖↑E a‖ ^ 2 = ↑re (inner (↑E a) (↑E a)) [PROOFSTEP] simp only [norm_coe, inner_coe, inner_self_eq_norm_sq] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : Completion E a b : E ⊢ ↑(starRingEnd 𝕜) (inner (↑E b) (↑E a)) = inner (↑E a) (↑E b) [PROOFSTEP] simp only [inner_coe, inner_conj_symm] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y z : Completion E a b c : E ⊢ inner (↑E a + ↑E b) (↑E c) = inner (↑E a) (↑E c) + inner (↑E b) (↑E c) [PROOFSTEP] simp only [← coe_add, inner_coe, inner_add_left] [GOAL] 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝⁴ : IsROrC 𝕜 inst✝³ : NormedAddCommGroup E inst✝² : InnerProductSpace 𝕜 E inst✝¹ : NormedAddCommGroup F inst✝ : InnerProductSpace ℝ F dec_E : DecidableEq E x y : Completion E c : 𝕜 a b : E ⊢ inner (c • ↑E a) (↑E b) = ↑(starRingEnd 𝕜) c * inner (↑E a) (↑E b) [PROOFSTEP] simp only [← coe_smul c a, inner_coe, inner_smul_left]
\subsection{Cross Products} \noindent A cross product is a way of multiplying two vectors so that the result is a vector. Although the cross product technically only works for 3D vectors, we will first look a a "fake" 2D version to build an intuition. \begin{equation*} \vec{a}\times\vec{b} = a_1b_1-a_2b_2 \end{equation*} This "fake" 2D cross product gives the area of the parallelogram spanned by $\vec{a}$ and $\vec{b}$. \begin{equation*} \vec{a}\times\vec{b} = \norm{\vec{a}}\norm{\vec{b}}\sin{\theta} \end{equation*} where $\theta$ is the angle between $\vec{a}$ and $\vec{b}$.\\ Another way to think of the magnitude of the cross product, both in 2D and 3D, is as a measure of how perpendicular two vectors are. \begin{figure}[h] \centering \includegraphics[scale=0.33]{Images/backgroundReview/CrossProduct} \end{figure} \noindent In 3D, $\vec{a}\times\vec{b}$ is a vector, and similar to the 2D case, the magnitude of $\vec{a}\times\vec{b}$ is equal to the area of the parallelogram spanned by $\vec{a}$ and $\vec{b}$. \begin{equation*} \vec{a}\times\vec{b} = \langle a_2b_3-b_2a_3,a_3b_1-b_3a_1,a_1b_2-b_1a_2 \rangle \end{equation*} and \begin{equation*} \norm{\vec{a}\times\vec{b}}=\norm{\vec{a}}\norm{\vec{b}}\sin{\theta} \end{equation*} where $\theta$ is the angle between $\vec{a}$ and $\vec{b}$.\\ Each component of $\vec{a}\times\vec{b}$ gives the area of the parallelogram spanned by $\vec{a}$ and $\vec{b}$ in some plane: The x-component of $\vec{a}\times\vec{b}$ gives the area in the yz-plane (x=0 plane).\\ $\vec{a}\times\vec{b}$ is perpendicular, also called "normal," to the plane containing $\vec{a}$ and $\vec{b}$. It's direction, is determined by the right hand rule.\\ \noindent The cross product table of the standard basis vectors is useful for providing some insight into the properties of the cross product. \begin{table}[h] \centering \renewcommand{\arraystretch}{1.5} \begin{tabular}{|l|l|l|l|} \hline $\overrightarrow{\text{row}}\times\overrightarrow{\text{col}}$ & $\hat{i}$ & $\hat{j}$ & $\hat{k}$ \\ \hline $\hat{i}$ & $0$ & $\hat{k}$ & $-\hat{j}$ \\ \hline $\hat{j}$ & $-\hat{k}$ & $0$ & $\hat{i}$ \\ \hline $\hat{k}$ & $\hat{j}$ & $-\hat{i}$ & $0$ \\ \hline \end{tabular} \end{table} \begin{itemize} \item \textbf{NOT} Commutative, but is antisymmetric \begin{equation*} \vec{a}\times\vec{b} = -\left(\vec{b}\times\vec{a}\right) \end{equation*} \item Scalar Associative \begin{equation*} \left(c\cdot\vec{a}\right)\times\vec{b}=\vec{a}\times\left(c\cdot\vec{b}\right) \end{equation*} \item Distributive \begin{equation*} \vec{a}\times\left(\vec{b}\times\vec{c}\right) = \vec{a}\times\vec{b} + \vec{a}\times\vec{c} \end{equation*} \end{itemize} \noindent One can also think of the cross product as the determinant of a matrix. \begin{equation*} \vec{a}\times\vec{b} = \det\begin{bmatrix} \hat{i}& \hat{j} & \hat{k} \\ a_1 & a_2 & a_2\\ b_1 & b_2 & b_3 \end{bmatrix} \end{equation*}
C %W% %G% subroutine solfc (a) C C This subroutine calculates the field voltage for IEEE model FC C include 'tspinc/vrgov.inc' include 'tspinc/params.inc' include 'tspinc/gentbla.inc' include 'tspinc/comvar.inc' include 'tspinc/gentblb.inc' include 'tspinc/lnk12.inc' include 'tspinc/ecsind.inc' include 'tspinc/lnk1a.inc' dimension array(40), a(40) equivalence (array(1), vrmax), (array(2), vrmin), 1 (array(3), vref), (array(4), esatx), (array(5), csatx), 2 (array(6), hbr), (array(7), cke), (array(8), cka), 3 (array(9), dr), (array(10), cfldo), (array(11), ck5), 4 (array(12), df), (array(13), akf), (array(14), hbf), 5 (array(15), hcb), (array(16), ckc), (array(17), db), 6 (array(18), dc), (array(19), hbe), (array(20), de), 7 (array(21), rcex), (array(22), vemax), (array(23), xcex), 8 (array(24), vao), (array(25), da), (array(26), hba), 9 (array(27), vco), (array(28), cfldpst), (array(29), efd), * (array(30), ckd), (array(31), x7pst), (array(32), vcpst), * (array(33), vfeo), (array(34), veo), (array(35), vemin), * (array(36), a4), (array(37), a5), (array(38), a6) C TRANSFER CITER DATA TO ARRAY do itr = 1,40 array(itr) = a(itr) end do C CALCULATE VOLTAGE TRANSDUCER CIRCUIT zcd = rcex*oid - xcex*oiq zcq = rcex*oiq + xcex*oid vcd = zcd + vtd vcq = zcq + vtq vc = sqrt(vcd**2 + vcq**2) C CALCULATE FIELD CURRENT cfld = vtq + ra * oiq + ((xd - xp) / (1.0 + satd) + xp) * oid if (mgen .ge. 6) cfld = cfd C TEST FOR NEW TIMESTEP if (lppwr .eq. 0) then C RECALCULATE STATE VECTORS FOR TIME = T ck1 = csatx * exp (esatx * abs(efd)) * (1.0 + efd * esatx) ck2 = efd**2 * esatx * csatx * exp (esatx * abs(efd)) vc1 = (hbr + vco)/dr vfe = (cke + ck1)*veo + ckd*cfldo - ck2 vf = (vfe*akf + hbf)/df vai = x7o - vf + vref - vc1 va = (dc*vai + hcb)/db vr = (cka*va + hba)/da if (vr.gt.vrmax) vr = vrmax if (vr.lt.vrmin) vr = vrmin x3 = vr C UPDATE PAST VALUE PARAMETERS hbr = (dr - 2.0)* vc1 + vco hcb = (db - 2.0)* va - (dc - 2.0)*vai hba = (da - 2.0)* vr + cka*va hbe = de*veo + vr - vfe hbf = (df - 2.0)*vf - akf*vfe C Store coefficients for estimation of VE limits C VE(max) = VEMAX + CA5*CFLD ca5 = -ckd/(de + cke + ck1) vemax = (hbe + ck2 + vrmax)/(de + cke + ck1) vemin = (hbe + ck2 + vrmin)/(de + cke + ck1) C Store coefficients for solution of VE: C VE(t) = A4*VERR(t) + A4*X7(t) + A5*CFLD(t) + A6 a1 = cka*dc/(da*db) a2 = 1.0 + a1*akf/df a3 = 1.0/(de + a2*(cke+ck1)) a4 = a1*a3 a5 = -a2*a3*ckd a6 = (hbe + hba/da + hcb*a1/dc - hbf*a1/df + a2*ck2)*a3 c assign values to be used in sub time loop dtsk = 0.1 ndiv = edt/dtsk delcfld = (cfldo - cfldpst)*dtsk/edt delx7 = (x7o - x7pst)*dtsk/edt delvc = (vco - vcpst)*dtsk/edt c start sub time loop do itr = 1, ndiv-1 if (idsw.ge.3.and.idsw.le.5) then vcn = vc x7n = x7 cfldn = cfld else x7n = x7o + itr*delx7 vcn = vco + itr*delvc cfldn = cfldo + itr*delcfld end if vc1 = (vcn + hbr)/dr ve = a4*(vref + x7n - vc1) + a5*cfldn + a6 vemaxx = vemax + ca5*cfldn veminx = vemin + ca5*cfldn if (veminx.lt.0.0) veminx = 0.0 if (ve.gt.vemaxx) ve = vemaxx if (ve.lt.veminx) ve = veminx vc1 = (hbr + vcn)/dr vfe = (cke + ck1)*ve + ckd*cfldn - ck2 vf = (vfe*akf + hbf)/df vai = x7n - vf + vref - vc1 va = (dc*vai + hcb)/db vr = (cka*va + hba)/da if (vr.gt.vrmax) vr = vrmax if (vr.lt.vrmin) vr = vrmin hbr = (dr - 2.0)* vc1 + vcn hcb = (db - 2.0)* va - (dc - 2.0)*vai hba = (da - 2.0)* vr + cka*va hbe = de*ve + vr - vfe hbf = (df - 2.0)*vf - akf*vfe ca5 = -ckd/(de + cke + ck1) vemax = (hbe + ck2 + vrmax)/(de + cke + ck1) vemin = (hbe + ck2 + vrmin)/(de + cke + ck1) a6 = (hbe + hba/da + hcb*a1/dc - hbf*a1/df + a2*ck2)*a3 end do cfldpst = cfldo x7pst = x7o vcpst = vco efdo = efd endif C CALCULATE STATE VECTORS FOR TIME = T + DT vc1 = (vc + hbr)/dr ve = a4*(vref + x7 - vc1) + a5*cfld + a6 vemaxx = vemax + ca5*cfld veminx = vemin + ca5*cfld if (veminx.lt.0.0) veminx = 0.0 if (ve.gt.vemaxx) ve = vemaxx if (ve.lt.veminx) ve = veminx if (ve .gt. 0.0) then cin = ckc*cfld/ve else cin = 0.0 endif C Determine range of operation if (abs(cin) .le. 0.51) then fex = 1.0 - 0.58*cin else if (abs(cin) .lt. 0.715) then fex = -0.865*(cin + 0.00826)**2 + 0.93233 else if (abs(cin) .lt. 0.9802) then fex = 1.68 - 1.714*cin else fex = 0.0 endif efd = ve*fex vfeo = vfe vao = va veo = ve cfldo = cfld vco = vc C TRANSFER EXCITER VARIABLES BACK TO CITER do itr = 1,40 a(itr) = array(itr) end do return end
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import ring_theory.integrally_closed import ring_theory.valuation.integers /-! # Integral elements over the ring of integers of a valution The ring of integers is integrally closed inside the original ring. -/ universes u v w open_locale big_operators namespace valuation namespace integers section comm_ring variables {R : Type u} {Γ₀ : Type v} [comm_ring R] [linear_ordered_comm_group_with_zero Γ₀] variables {v : valuation R Γ₀} {O : Type w} [comm_ring O] [algebra O R] (hv : integers v O) include hv open polynomial lemma mem_of_integral {x : R} (hx : is_integral O x) : x ∈ v.integer := let ⟨p, hpm, hpx⟩ := hx in le_of_not_lt $ λ hvx, begin rw [hpm.as_sum, eval₂_add, eval₂_pow, eval₂_X, eval₂_finset_sum, add_eq_zero_iff_eq_neg] at hpx, replace hpx := congr_arg v hpx, refine ne_of_gt _ hpx, rw [v.map_neg, v.map_pow], refine v.map_sum_lt' (zero_lt_one₀.trans_le (one_le_pow_of_one_le' hvx.le _)) (λ i hi, _), rw [eval₂_mul, eval₂_pow, eval₂_C, eval₂_X, v.map_mul, v.map_pow, ← one_mul (v x ^ p.nat_degree)], cases (hv.2 $ p.coeff i).lt_or_eq with hvpi hvpi, { exact mul_lt_mul₀ hvpi (pow_lt_pow₀ hvx $ finset.mem_range.1 hi) }, { erw hvpi, rw [one_mul, one_mul], exact pow_lt_pow₀ hvx (finset.mem_range.1 hi) } end protected lemma integral_closure : integral_closure O R = ⊥ := bot_unique $ λ r hr, let ⟨x, hx⟩ := hv.3 (hv.mem_of_integral hr) in algebra.mem_bot.2 ⟨x, hx⟩ end comm_ring section fraction_field variables {K : Type u} {Γ₀ : Type v} [field K] [linear_ordered_comm_group_with_zero Γ₀] variables {v : valuation K Γ₀} {O : Type w} [comm_ring O] [is_domain O] variables [algebra O K] [is_fraction_ring O K] variables (hv : integers v O) lemma integrally_closed : is_integrally_closed O := (is_integrally_closed.integral_closure_eq_bot_iff K).mp (valuation.integers.integral_closure hv) end fraction_field end integers end valuation
[STATEMENT] lemma const_StrictRefEq\<^sub>S\<^sub>e\<^sub>t_empty : "const X \<Longrightarrow> const (X \<doteq> Set{})" [PROOF STATE] proof (prove) goal (1 subgoal): 1. const X \<Longrightarrow> const (X \<doteq> Set{}) [PROOF STEP] apply(rule StrictRefEq\<^sub>S\<^sub>e\<^sub>t.const, assumption) [PROOF STATE] proof (prove) goal (1 subgoal): 1. const X \<Longrightarrow> const Set{} [PROOF STEP] by(simp)
module splines implicit none public :: geo_spline, linear_interp_periodic type :: spline integer :: n real, dimension(:), pointer :: x, y, y2 end type spline type :: periodic_spline integer :: n real :: period real, dimension(:), pointer :: x, y, y2 end type periodic_spline interface geo_spline module procedure geo_spline_real module procedure geo_spline_array end interface contains ! subroutine new_spline (n, x, y, spl) ! implicit none ! integer, intent (in) :: n ! real, dimension (n), intent (in) :: x, y ! type (spline), intent (out) :: spl ! real, dimension (n) :: temp ! integer :: ierr ! spl%n = n ! allocate (spl%x(n),spl%y(n)) ! spl%x = x ! spl%y = y ! allocate (spl%y2(n)) ! call fitp_curv1 (n, x, y, 0.0, 0.0, 3, spl%y2, temp, 1.0, ierr) ! end subroutine new_spline ! subroutine new_periodic_spline (n, x, y, period, spl) ! implicit none ! integer, intent (in) :: n ! real, dimension (n), intent (in) :: x, y ! real, intent (in) :: period ! type (periodic_spline), intent (out) :: spl ! real, dimension (2*n) :: temp ! integer :: ierr ! spl%n = n ! spl%period = period ! allocate (spl%x(n),spl%y(n)) ! spl%x = x ! spl%y = y ! allocate (spl%y2(n)) ! call fitp_curvp1 (n,x,y,period,spl%y2,temp,1.0,ierr) ! end subroutine new_periodic_spline ! subroutine delete_spline (spl) ! implicit none ! type (spline), intent (in out) :: spl ! spl%n = 0 ! deallocate (spl%x,spl%y) ! nullify (spl%x) ! nullify (spl%y) ! deallocate (spl%y2) ! nullify (spl%y2) ! end subroutine delete_spline ! subroutine delete_periodic_spline (spl) ! implicit none ! type (periodic_spline), intent (in out) :: spl ! spl%n = 0 ! spl%period = 0.0 ! deallocate (spl%x,spl%y) ! nullify (spl%x) ! nullify (spl%y) ! deallocate (spl%y2) ! nullify (spl%y2) ! end subroutine delete_periodic_spline ! function splint (x, spl) ! implicit none ! real, intent (in) :: x ! type (spline), intent (in) :: spl ! real :: splint ! splint = fitp_curv2 (x, spl%n, spl%x, spl%y, spl%y2, 1.0) ! end function splint ! function periodic_splint (x, spl) ! implicit none ! real, intent (in) :: x ! type (periodic_spline), intent (in) :: spl ! real :: periodic_splint ! periodic_splint = fitp_curvp2 & ! (x, spl%n, spl%x, spl%y, spl%period, spl%y2, 1.0) ! end function periodic_splint ! function dsplint (x, spl) ! implicit none ! real, intent (in) :: x ! type (spline), intent (in) :: spl ! real :: dsplint ! dsplint = fitp_curvd (x, spl%n, spl%x, spl%y, spl%y2, 1.0) ! end function dsplint ! function splintint (x0, x1, spl) ! implicit none ! real, intent (in) :: x0, x1 ! type (spline), intent (in) :: spl ! real :: splintint ! splintint = fitp_curvi (x0,x1,spl%n,spl%x,spl%y,spl%y2,1.0) ! end function splintint ! function periodic_splintint (x0, x1, spl) ! implicit none ! real, intent (in) :: x0, x1 ! type (periodic_spline), intent (in) :: spl ! real :: periodic_splintint ! periodic_splintint = fitp_curvpi & ! (x0,x1,spl%n,spl%x,spl%y,spl%period,spl%y2, 1.0) ! end function periodic_splintint ! subroutine inter_d_cspl(n,r,data,m,x,dint,ddint) ! integer n ! integer m ! real r(n), data(n), x(m), dint(m), ddint(m) ! integer max ! parameter (max=1000) ! real ddata(max),temp(max) ! integer i,ierr ! if (n .gt. max) then ! write (*,*) 'error in inter_d_cspl' ! write (*,*) 'increase max' ! stop ! endif ! ierr = 0 ! call fitp_curv1(n,r,data,0.0,0.0,3,ddata,temp,1.0,ierr) ! if (ierr .ne. 0) then ! if (ierr .eq. 1) then ! write (*,*) 'FITPACK: curv1 error: n < 2' ! elseif (ierr .eq. 2) then ! write (*,*) 'FITPACK: curv1 error: x-values not increasing' ! else ! write (*,*) 'FITPACK: curv1 error' ! endif ! stop ! endif ! do i=1,m ! dint(i) = fitp_curv2 (x(i),n,r,data,ddata,1.0) ! ddint(i)= fitp_curvd (x(i),n,r,data,ddata,1.0) ! enddo ! end subroutine inter_d_cspl ! subroutine inter_cspl(n,r,data,m,x,dint) ! integer n ! integer m ! real r(n), data(n), x(m), dint(m) ! integer max ! parameter (max=1000) ! real ddata(max),temp(max) ! integer i,ierr ! if (n .gt. max) then ! write (*,*) 'error in inter_cspl' ! write (*,*) 'increase max' ! stop ! endif ! ierr = 0 ! call fitp_curv1(n,r,data,0.0,0.0,3,ddata,temp,1.0,ierr) ! if (ierr .ne. 0) then ! if (ierr .eq. 1) then ! write (*,*) 'FITPACK: curv1 error: n < 2' ! elseif (ierr .eq. 2) then ! write (*,*) 'FITPACK: curv1 error: x-values not increasing' ! else ! write (*,*) 'FITPACK: curv1 error' ! endif ! stop ! endif ! do i=1,m ! dint(i) = fitp_curv2 (x(i),n,r,data,ddata,1.0) ! enddo ! end subroutine inter_cspl ! subroutine inter_getspl (n, x, y, y2) ! integer n ! real x(n), y(n), y2(n) ! integer max ! parameter (max=1000) ! real temp(max) ! integer ierr ! if (n .gt. max) then ! write (*,*) 'error in inter_getspl' ! write (*,*) 'increase max' ! stop ! endif ! ierr = 0 ! call fitp_curv1(n,x,y,0.0,0.0,3,y2,temp,1.0,ierr) ! if (ierr .ne. 0) then ! if (ierr .eq. 1) then ! write (*,*) 'FITPACK: curv1 error: n < 2' ! elseif (ierr .eq. 2) then ! write (*,*) 'FITPACK: curv1 error: x-values not increasing' ! else ! write (*,*) 'FITPACK: curv1 error' ! endif ! stop ! endif ! end subroutine inter_getspl ! real function inter_splint (x0, n, x, y, y2) ! real x0 ! integer n ! real x(n), y(n), y2(n) ! inter_splint = fitp_curv2 (x0, n, x, y, y2, 1.0) ! end function inter_splint ! real function inter_dsplint (x0, n, x, y, y2) ! real x0 ! integer n ! real x(n), y(n), y2(n) ! inter_dsplint = fitp_curvd (x0, n, x, y, y2, 1.0) ! end function inter_dsplint ! real function inter_d2splint (x0, n, x, y, y2) ! real x0 ! integer n ! real x(n), y(n), y2(n) ! real yx(500) ! data yx(1)/1.0/ ! save yx ! integer i ! if (yx(1) .ne. 0.0) then ! do i=1,500 ! yx(i) = 0.0 ! enddo ! endif ! inter_d2splint = fitp_curv2 (x0, n, x, y2, yx, 1e5) ! end function inter_d2splint ! subroutine inter_getpspl (n, x, p, y, y2) ! integer n ! real x(n), p, y(n), y2(n) ! integer max ! parameter (max=1000) ! real temp(max) ! integer ierr ! if (n .gt. max) then ! write (*,*) 'error in inter_getpspl' ! write (*,*) 'increase max' ! stop ! endif ! ierr=0 ! call fitp_curvp1(n,x,y,p,y2,temp,1.0,ierr) ! if (ierr .ne. 0) then ! if (ierr .eq. 1) then ! write (*,*) 'FITPACK: curvp1 error: n < 2' ! elseif (ierr .eq. 2) then ! write (*,*) 'FITPACK: curvp1 error: p <= x(n)-x(1)' ! elseif (ierr .eq. 3) then ! write (*,*) 'FITPACK: curvp1 error: x-values not increasing' ! else ! write (*,*) 'FITPACK: curv1 error' ! endif ! stop ! endif ! end subroutine inter_getpspl ! real function inter_psplint (x0, n, x, p, y, y2) ! real x0 ! integer n ! real x(n), p, y(n), y2(n) ! inter_psplint = fitp_curvp2 (x0, n, x, y, p, y2, 1.0) ! end function inter_psplint ! real function inter_pdsplint (x0, n, x, p, y, y2) ! real x0 ! integer n ! real x(n), p, y(n), y2(n) ! inter_pdsplint = fitp_curvpd (x0, n, x, y, p, y2, 1.0) ! end function inter_pdsplint ! From inet!cs.utexas.edu!cline Tue Oct 31 17:10:31 CST 1989 ! Received: from mojave.cs.utexas.edu by cs.utexas.edu (5.59/1.44) ! id AA29509; Tue, 31 Oct 89 17:11:51 CST ! Posted-Date: Tue, 31 Oct 89 17:10:31 CST ! Message-Id: <[email protected]> ! Received: by mojave.cs.utexas.edu (14.5/1.4-Client) ! id AA04442; Tue, 31 Oct 89 17:10:34 cst ! Date: Tue, 31 Oct 89 17:10:31 CST ! X-Mailer: Mail User's Shell (6.5 4/17/89) ! From: [email protected] (Alan Cline) ! To: [email protected] ! Subject: New FITPACK Subset for netlib ! ! ! This new version of FITPACK distributed by netlib is about 20% of ! the total package in terms of characters, lines of code, and num- ! ber of subprograms. However, these 25 subprograms represent about ! 95% of usages of the package. What has been omitted are such ca- ! pabilities as: ! 1. Automatic tension determination, ! 2. Derivatives, arclengths, and enclosed areas for planar ! curves, ! 3. Three dimensional curves, ! 4. Special surface fitting using equispacing assumptions, ! 5. Surface fitting in annular, wedge, polar, toroidal, lunar, ! and spherical geometries, ! 6. B-splines in tension generation and usage, ! 7. General surface fitting in three dimensional space. ! ! (The code previously circulated in netlib is less than 10% of the ! total package and is more than a decade old. Its usage is dis- ! couraged.) ! ! Please note: Two versions of the subroutine snhcsh are included. ! Both serve the same purpose: obtaining approximations to certain ! hyperbolic trigonometric-like functions. The first is less accu- ! rate (but more efficient) than the second. Installers should se- ! lect the one with the precision they desire. ! ! Interested parties can obtain the entire package on disk or tape ! from Pleasant Valley Software, 8603 Altus Cove, Austin TX (USA), ! 78759 at a cost of $495 US. A 340 page manual is available for ! $30 US per copy. The package includes examples and machine ! readable documentation. subroutine fitp_curv1(n, x, y, slp1, slpn, islpsw, yp, temp, sigma, ierr) integer n, islpsw, ierr real x(n), y(n), slp1, slpn, yp(n), temp(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute an interpolatory spline under tension through ! a sequence of functional values. the slopes at the two ! ends of the curve may be specified or omitted. for actual ! computation of points on the curve it is necessary to call ! the function curv2. ! ! on input-- ! ! n is the number of values to be interpolated (n.ge.2). ! ! x is an array of the n increasing abscissae of the ! functional values. ! ! y is an array of the n ordinates of the values, (i. e. ! y(k) is the functional value corresponding to x(k) ). ! ! slp1 and slpn contain the desired values for the first ! derivative of the curve at x(1) and x(n), respectively. ! the user may omit values for either or both of these ! parameters and signal this with islpsw. ! ! islpsw contains a switch indicating which slope data ! should be used and which should be estimated by this ! subroutine, ! = 0 if slp1 and slpn are to be used, ! = 1 if slp1 is to be used but not slpn, ! = 2 if slpn is to be used but not slp1, ! = 3 if both slp1 and slpn are to be estimated ! internally. ! ! yp is an array of length at least n. ! ! temp is an array of length at least n which is used for ! scratch storage. ! ! and ! ! sigma contains the tension factor. this value indicates ! the curviness desired. if abs(sigma) is nearly zero ! (e.g. .001) the resulting curve is approximately a ! cubic spline. if abs(sigma) is large (e.g. 50.) the ! resulting curve is nearly a polygonal line. if sigma ! equals zero a cubic spline results. a standard value ! for sigma is approximately 1. in absolute value. ! ! on output-- ! ! yp contains the values of the second derivative of the ! curve at the given nodes. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2, ! = 2 if x-values are not strictly increasing. ! ! and ! ! n, x, y, slp1, slpn, islpsw and sigma are unaltered. ! ! this subroutine references package modules ceez, terms, ! and snhcsh. ! !----------------------------------------------------------- integer i, ibak, nm1, np1 real sdiag1, diag1, delxnm, dx1, diag, sdiag2, dx2, diag2 real delxn, slpp1, delx1, sigmap, c3, c2, c1, slppn, delx2 nm1 = n - 1 np1 = n + 1 ierr = 0 if (n <= 1) go to 8 if (x(n) <= x(1)) go to 9 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n - 1) / (x(n) - x(1)) ! ! approximate end slopes ! if (islpsw >= 2) go to 1 slpp1 = slp1 go to 2 1 delx1 = x(2) - x(1) delx2 = delx1 + delx1 if (n > 2) delx2 = x(3) - x(1) if (delx1 <= 0. .or. delx2 <= delx1) go to 9 call fitp_ceez(delx1, delx2, sigmap, c1, c2, c3, n) slpp1 = c1 * y(1) + c2 * y(2) if (n > 2) slpp1 = slpp1 + c3 * y(3) 2 if (islpsw == 1 .or. islpsw == 3) go to 3 slppn = slpn go to 4 3 delxn = x(n) - x(nm1) delxnm = delxn + delxn if (n > 2) delxnm = x(n) - x(n - 2) if (delxn <= 0. .or. delxnm <= delxn) go to 9 call fitp_ceez(-delxn, -delxnm, sigmap, c1, c2, c3, n) slppn = c1 * y(n) + c2 * y(nm1) if (n > 2) slppn = slppn + c3 * y(n - 2) ! ! set up right hand side and tridiagonal system for yp and ! perform forward elimination ! 4 delx1 = x(2) - x(1) if (delx1 <= 0.) go to 9 dx1 = (y(2) - y(1)) / delx1 call fitp_terms(diag1, sdiag1, sigmap, delx1) yp(1) = (dx1 - slpp1) / diag1 temp(1) = sdiag1 / diag1 if (n == 2) go to 6 do i = 2, nm1 delx2 = x(i + 1) - x(i) if (delx2 <= 0.) go to 9 dx2 = (y(i + 1) - y(i)) / delx2 call fitp_terms(diag2, sdiag2, sigmap, delx2) diag = diag1 + diag2 - sdiag1 * temp(i - 1) yp(i) = (dx2 - dx1 - sdiag1 * yp(i - 1)) / diag temp(i) = sdiag2 / diag dx1 = dx2 diag1 = diag2 sdiag1 = sdiag2 end do 6 diag = diag1 - sdiag1 * temp(nm1) yp(n) = (slppn - dx1 - sdiag1 * yp(nm1)) / diag ! ! perform back substitution ! do i = 2, n ibak = np1 - i yp(ibak) = yp(ibak) - temp(ibak) * yp(ibak + 1) end do return ! ! too few points ! 8 ierr = 1 return ! ! x-values not strictly increasing ! 9 ierr = 2 return end subroutine fitp_curv1 subroutine fitp_curvs(n, x, y, d, isw, s, eps, ys, ysp, sigma, temp, ierr) integer n, isw, ierr real x(n), y(n), d(n), s, eps, ys(n), ysp(n), sigma, temp(n, 9) ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute a smoothing spline under tension. for a given ! increasing sequence of abscissae (x(i)), i = 1,..., n and ! associated ordinates (y(i)), i = 1,..., n, the function ! determined minimizes the summation from i = 1 to n-1 of ! the square of the second derivative of f plus sigma ! squared times the difference of the first derivative of f ! and (f(x(i+1))-f(x(i)))/(x(i+1)-x(i)) squared, over all ! functions f with two continuous derivatives such that the ! summation of the square of (f(x(i))-y(i))/d(i) is less ! than or equal to a given constant s, where (d(i)), i = 1, ! ..., n are a given set of observation weights. the ! function determined is a spline under tension with third ! derivative discontinuities at (x(i)), i = 2,..., n-1. for ! actual computation of points on the curve it is necessary ! to call the function curv2. the determination of the curve ! is performed by subroutine curvss, the subroutine curvs ! only decomposes the workspace for curvss. ! ! on input-- ! ! n is the number of values to be smoothed (n.ge.2). ! ! x is an array of the n increasing abscissae of the ! values to be smoothed. ! ! y is an array of the n ordinates of the values to be ! smoothed, (i. e. y(k) is the functional value ! corresponding to x(k) ). ! ! d is a parameter containing the observation weights. ! this may either be an array of length n or a scalar ! (interpreted as a constant). the value of d ! corresponding to the observation (x(k),y(k)) should ! be an approximation to the standard deviation of error. ! ! isw contains a switch indicating whether the parameter ! d is to be considered a vector or a scalar, ! = 0 if d is an array of length n, ! = 1 if d is a scalar. ! ! s contains the value controlling the smoothing. this ! must be non-negative. for s equal to zero, the ! subroutine does interpolation, larger values lead to ! smoother funtions. if parameter d contains standard ! deviation estimates, a reasonable value for s is ! float(n). ! ! eps contains a tolerance on the relative precision to ! which s is to be interpreted. this must be greater than ! or equal to zero and less than or equal to one. a ! reasonable value for eps is sqrt(2./float(n)). ! ! ys is an array of length at least n. ! ! ysp is an array of length at least n. ! ! sigma contains the tension factor. this value indicates ! the degree to which the first derivative part of the ! smoothing functional is emphasized. if sigma is nearly ! zero (e. g. .001) the resulting curve is approximately a ! cubic spline. if sigma is large (e. g. 50.) the ! resulting curve is nearly a polygonal line. if sigma ! equals zero a cubic spline results. a standard value for ! sigma is approximately 1. ! ! and ! ! temp is an array of length at least 9*n which is used ! for scratch storage. ! ! on output-- ! ! ys contains the smoothed ordinate values. ! ! ysp contains the values of the second derivative of the ! smoothed curve at the given nodes. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2, ! = 2 if s is negative, ! = 3 if eps is negative or greater than one, ! = 4 if x-values are not strictly increasing, ! = 5 if a d-value is non-positive. ! ! and ! ! n, x, y, d, isw, s, eps, and sigma are unaltered. ! ! this subroutine references package modules curvss, terms, ! and snhcsh. ! !----------------------------------------------------------- ! ! decompose temp into nine arrays and call curvss ! call fitp_curvss(n, x, y, d, isw, s, eps, ys, ysp, sigma, temp(1, 1), & temp(1, 2), temp(1, 3), temp(1, 4), temp(1, 5), & temp(1, 6), temp(1, 7), temp(1, 8), temp(1, 9), & ierr) end subroutine fitp_curvs real function fitp_curv2(t, n, x, y, yp, sigma) integer n real t, x(n), y(n), yp(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function interpolates a curve at a given point ! using a spline under tension. the subroutine curv1 should ! be called earlier to determine certain necessary ! parameters. ! ! on input-- ! ! t contains a real value to be mapped onto the interpo- ! lating curve. ! ! n contains the number of points which were specified to ! determine the curve. ! ! x and y are arrays containing the abscissae and ! ordinates, respectively, of the specified points. ! ! yp is an array of second derivative values of the curve ! at the nodes. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, yp, and sigma should be input ! unaltered from the output of curv1. ! ! on output-- ! ! curv2 contains the interpolated value. ! ! none of the input parameters are altered. ! ! this function references package modules intrvl and ! snhcsh. ! !----------------------------------------------------------- integer i, im1 real ss, sigdel, dummy, s1, s2, sum, sigmap real del1, del2, dels ! ! determine interval ! im1 = fitp_intrvl(t, x, n) i = im1 + 1 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n - 1) / (x(n) - x(1)) ! ! set up and perform interpolation ! del1 = t - x(im1) del2 = x(i) - t dels = x(i) - x(im1) sum = (y(i) * del1 + y(im1) * del2) / dels if (sigmap /= 0.) go to 1 fitp_curv2 = sum - del1 * del2 * (yp(i) * (del1 + dels) + yp(im1) * (del2 + dels)) / (6.*dels) return 1 sigdel = sigmap * dels call fitp_snhcsh(ss, dummy, sigdel, -1) call fitp_snhcsh(s1, dummy, sigmap * del1, -1) call fitp_snhcsh(s2, dummy, sigmap * del2, -1) fitp_curv2 = sum + (yp(i) * del1 * (s1 - ss) + yp(im1) * del2 * (s2 - ss)) / (sigdel * sigmap * (1.+ss)) return end function fitp_curv2 real function fitp_curvd(t, n, x, y, yp, sigma) integer n real t, x(n), y(n), yp(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function differentiates a curve at a given point ! using a spline under tension. the subroutine curv1 should ! be called earlier to determine certain necessary ! parameters. ! ! on input-- ! ! t contains a real value at which the derivative is to be ! determined. ! ! n contains the number of points which were specified to ! determine the curve. ! ! x and y are arrays containing the abscissae and ! ordinates, respectively, of the specified points. ! ! yp is an array of second derivative values of the curve ! at the nodes. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, yp, and sigma should be input ! unaltered from the output of curv1. ! ! on output-- ! ! curvd contains the derivative value. ! ! none of the input parameters are altered. ! ! this function references package modules intrvl and ! snhcsh. ! !----------------------------------------------------------- integer i, im1 real ss, sigdel, dummy, c1, c2, sum, sigmap real del1, del2, dels ! ! determine interval ! im1 = fitp_intrvl(t, x, n) i = im1 + 1 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n - 1) / (x(n) - x(1)) ! ! set up and perform differentiation ! del1 = t - x(im1) del2 = x(i) - t dels = x(i) - x(im1) sum = (y(i) - y(im1)) / dels if (sigmap /= 0.) go to 1 fitp_curvd = sum + (yp(i) * (2.*del1 * del1 - del2 * (del1 + dels)) - & yp(im1) * (2.*del2 * del2 - del1 * (del2 + dels))) & / (6.*dels) return 1 sigdel = sigmap * dels call fitp_snhcsh(ss, dummy, sigdel, -1) call fitp_snhcsh(dummy, c1, sigmap * del1, 1) call fitp_snhcsh(dummy, c2, sigmap * del2, 1) fitp_curvd = sum + (yp(i) * (c1 - ss) - yp(im1) * (c2 - ss)) / (sigdel * sigmap * (1.+ss)) return end function fitp_curvd real function fitp_curvi(xl, xu, n, x, y, yp, sigma) integer n real xl, xu, x(n), y(n), yp(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function integrates a curve specified by a spline ! under tension between two given limits. the subroutine ! curv1 should be called earlier to determine necessary ! parameters. ! ! on input-- ! ! xl and xu contain the upper and lower limits of inte- ! gration, respectively. (sl need not be less than or ! equal to xu, curvi (xl,xu,...) .eq. -curvi (xu,xl,...) ). ! ! n contains the number of points which were specified to ! determine the curve. ! ! x and y are arrays containing the abscissae and ! ordinates, respectively, of the specified points. ! ! yp is an array from subroutine curv1 containing ! the values of the second derivatives at the nodes. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, yp, and sigma should be input ! unaltered from the output of curv1. ! ! on output-- ! ! curvi contains the integral value. ! ! none of the input parameters are altered. ! ! this function references package modules intrvl and ! snhcsh. ! !----------------------------------------------------------- integer i, ilp1, ilm1, il, ium1, iu real delu1, delu2, c2, ss, cs, cu2, cl1, cl2, cu1 real dell1, dell2, deli, c1, ssign, sigmap real xxl, xxu, t1, t2, dummy, dels, sum, del1, del2 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n - 1) / (x(n) - x(1)) ! ! determine actual upper and lower bounds ! xxl = xl xxu = xu ssign = 1. if (xl < xu) go to 1 xxl = xu xxu = xl ssign = -1. if (xl > xu) go to 1 ! ! return zero if xl .eq. xu ! fitp_curvi = 0. return ! ! search for proper intervals ! 1 ilm1 = fitp_intrvl(xxl, x, n) il = ilm1 + 1 ium1 = fitp_intrvl(xxu, x, n) iu = ium1 + 1 if (il == iu) go to 8 ! ! integrate from xxl to x(il) ! sum = 0. if (xxl == x(il)) go to 3 del1 = xxl - x(ilm1) del2 = x(il) - xxl dels = x(il) - x(ilm1) t1 = (del1 + dels) * del2 / (2.*dels) t2 = del2 * del2 / (2.*dels) sum = t1 * y(il) + t2 * y(ilm1) if (sigma == 0.) go to 2 call fitp_snhcsh(dummy, c1, sigmap * del1, 2) call fitp_snhcsh(dummy, c2, sigmap * del2, 2) call fitp_snhcsh(ss, cs, sigmap * dels, 3) sum = sum + ((dels * dels * (cs - ss / 2.) - del1 * del1 * (c1 - ss / 2.)) & * yp(il) + del2 * del2 * (c2 - ss / 2.) * yp(ilm1)) / & (sigmap * sigmap * dels * (1.+ss)) go to 3 2 sum = sum - t1 * t1 * dels * yp(il) / 6. & -t2 * (del1 * (del2 + dels) + dels * dels) * yp(ilm1) / 12. ! ! integrate over interior intervals ! 3 if (iu - il == 1) go to 6 ilp1 = il + 1 do i = ilp1, ium1 dels = x(i) - x(i - 1) sum = sum + (y(i) + y(i - 1)) * dels / 2. if (sigma == 0.) go to 4 call fitp_snhcsh(ss, cs, sigmap * dels, 3) sum = sum + (yp(i) + yp(i - 1)) * dels * (cs - ss / 2.) / (sigmap * sigmap * (1.+ss)) go to 5 4 sum = sum - (yp(i) + yp(i - 1)) * dels * dels * dels / 24. 5 continue end do ! ! integrate from x(iu-1) to xxu ! 6 if (xxu == x(ium1)) go to 10 del1 = xxu - x(ium1) del2 = x(iu) - xxu dels = x(iu) - x(ium1) t1 = del1 * del1 / (2.*dels) t2 = (del2 + dels) * del1 / (2.*dels) sum = sum + t1 * y(iu) + t2 * y(ium1) if (sigma == 0.) go to 7 call fitp_snhcsh(dummy, c1, sigmap * del1, 2) call fitp_snhcsh(dummy, c2, sigmap * del2, 2) call fitp_snhcsh(ss, cs, sigmap * dels, 3) sum = sum + (yp(iu) * del1 * del1 * (c1 - ss / 2.) + yp(ium1) * & (dels * dels * (cs - ss / 2.) - del2 * del2 * (c2 - ss / 2.))) & / (sigmap * sigmap * dels * (1.+ss)) go to 10 7 sum = sum - t1 * (del2 * (del1 + dels) + dels * dels) * yp(iu) / 12.-t2 * t2 * dels * yp(ium1) / 6. go to 10 ! ! integrate from xxl to xxu ! 8 delu1 = xxu - x(ium1) delu2 = x(iu) - xxu dell1 = xxl - x(ium1) dell2 = x(iu) - xxl dels = x(iu) - x(ium1) deli = xxu - xxl t1 = (delu1 + dell1) * deli / (2.*dels) t2 = (delu2 + dell2) * deli / (2.*dels) sum = t1 * y(iu) + t2 * y(ium1) if (sigma == 0.) go to 9 call fitp_snhcsh(dummy, cu1, sigmap * delu1, 2) call fitp_snhcsh(dummy, cu2, sigmap * delu2, 2) call fitp_snhcsh(dummy, cl1, sigmap * dell1, 2) call fitp_snhcsh(dummy, cl2, sigmap * dell2, 2) call fitp_snhcsh(ss, dummy, sigmap * dels, -1) sum = sum + (yp(iu) * (delu1 * delu1 * (cu1 - ss / 2.) & - dell1 * dell1 * (cl1 - ss / 2.)) & + yp(ium1) * (dell2 * dell2 * (cl2 - ss / 2.) & - delu2 * delu2 * (cu2 - ss / 2.))) / & (sigmap * sigmap * dels * (1.+ss)) go to 10 9 sum = sum - t1 * (delu2 * (dels + delu1) + dell2 * (dels + dell1)) * & yp(iu) / 12. & -t2 * (dell1 * (dels + dell2) + delu1 * (dels + delu2)) * & yp(ium1) / 12. ! ! correct sign and return ! 10 fitp_curvi = ssign * sum return end function fitp_curvi subroutine fitp_curvp1(n, x, y, p, yp, temp, sigma, ierr) integer n, ierr real, dimension(:) :: x, y, yp, temp real :: p, sigma !! real x(n),y(n),p,yp(n),temp(2*n),sigma ! real x(n),y(n),p,yp(n),temp(1),sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute a periodic interpolatory spline under tension ! through a sequence of functional values. for actual ends ! of the curve may be specified or omitted. for actual ! computation of points on the curve it is necessary to call ! the function curvp2. ! ! on input-- ! ! n is the number of values to be interpolated (n.ge.2). ! ! x is an array of the n increasing abscissae of the ! functional values. ! ! y is an array of the n ordinates of the values, (i. e. ! y(k) is the functional value corresponding to x(k) ). ! ! p is the period (p .gt. x(n)-x(1)). ! ! yp is an array of length at least n. ! ! temp is an array of length at least 2*n which is used ! for scratch storage. ! ! and ! ! sigma contains the tension factor. this value indicates ! the curviness desired. if abs(sigma) is nearly zero ! (e.g. .001) the resulting curve is approximately a ! cubic spline. if abs(sigma) is large (e.g. 50.) the ! resulting curve is nearly a polygonal line. if sigma ! equals zero a cubic spline results. a standard value ! for sigma is approximately 1. in absolute value. ! ! on output-- ! ! yp contains the values of the second derivative of the ! curve at the given nodes. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2, ! = 2 if p is less than or equal to x(n)-x(1), ! = 3 if x-values are not strictly increasing. ! ! and ! ! n, x, y, and sigma are unaltered. ! ! this subroutine references package modules terms and ! snhcsh. ! !----------------------------------------------------------- integer i, npibak, npi, ibak, nm1, np1 real diag, diag2, sdiag2, ypn, dx2, sigmap, delx1 real sdiag1, delx2, dx1, diag1 nm1 = n - 1 np1 = n + 1 ierr = 0 if (n <= 1) go to 6 if (p <= x(n) - x(1) .or. p <= 0.) go to 7 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n) / p ! ! set up right hand side and tridiagonal system for yp and ! perform forward elimination ! delx1 = p - (x(n) - x(1)) dx1 = (y(1) - y(n)) / delx1 call fitp_terms(diag1, sdiag1, sigmap, delx1) delx2 = x(2) - x(1) if (delx2 <= 0.) go to 8 dx2 = (y(2) - y(1)) / delx2 call fitp_terms(diag2, sdiag2, sigmap, delx2) diag = diag1 + diag2 yp(1) = (dx2 - dx1) / diag temp(np1) = -sdiag1 / diag temp(1) = sdiag2 / diag dx1 = dx2 diag1 = diag2 sdiag1 = sdiag2 if (n == 2) go to 2 do i = 2, nm1 npi = n + i delx2 = x(i + 1) - x(i) if (delx2 <= 0.) go to 8 dx2 = (y(i + 1) - y(i)) / delx2 call fitp_terms(diag2, sdiag2, sigmap, delx2) diag = diag1 + diag2 - sdiag1 * temp(i - 1) yp(i) = (dx2 - dx1 - sdiag1 * yp(i - 1)) / diag temp(npi) = -temp(npi - 1) * sdiag1 / diag temp(i) = sdiag2 / diag dx1 = dx2 diag1 = diag2 sdiag1 = sdiag2 end do 2 delx2 = p - (x(n) - x(1)) dx2 = (y(1) - y(n)) / delx2 call fitp_terms(diag2, sdiag2, sigmap, delx2) yp(n) = dx2 - dx1 temp(nm1) = temp(2 * n - 1) - temp(nm1) if (n == 2) go to 4 ! ! perform first step of back substitution ! do i = 3, n ibak = np1 - i npibak = n + ibak yp(ibak) = yp(ibak) - temp(ibak) * yp(ibak + 1) temp(ibak) = temp(npibak) - temp(ibak) * temp(ibak + 1) end do 4 yp(n) = (yp(n) - sdiag2 * yp(1) - sdiag1 * yp(nm1)) / & (diag1 + diag2 + sdiag2 * temp(1) + sdiag1 * temp(nm1)) ! ! perform second step of back substitution ! ypn = yp(n) do i = 1, nm1 yp(i) = yp(i) + temp(i) * ypn end do return ! ! too few points ! 6 ierr = 1 return ! ! period too small ! 7 ierr = 2 return ! ! x-values not strictly increasing ! 8 ierr = 3 return end subroutine fitp_curvp1 subroutine fitp_curvps(n, x, y, p, d, isw, s, eps, ys, ysp, sigma, temp, ierr) integer n, isw, ierr real x(n), y(n), p, d(n), s, eps, ys(n), ysp(n), sigma, temp(n, 11) ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute a periodic smoothing spline under tension. for a ! given increasing sequence of abscissae (x(i)), i = 1,...,n ! and associated ordinates (y(i)), i = 1,...,n, letting p be ! the period, x(n+1) = x(1)+p, and y(n+1) = y(1), the ! function determined minimizes the summation from i = 1 to ! n of the square of the second derivative of f plus sigma ! squared times the difference of the first derivative of f ! and (f(x(i+1))-f(x(i)))/(x(i+1)-x(i)) squared, over all ! functions f with period p and two continuous derivatives ! such that the summation of the square of ! (f(x(i))-y(i))/d(i) is less than or equal to a given ! constant s, where (d(i)), i = 1,...,n are a given set of ! observation weights. the function determined is a periodic ! spline under tension with third derivative discontinuities ! at (x(i)) i = 1,...,n (and all periodic translations of ! these values). for actual computation of points on the ! curve it is necessary to call the function curvp2. the ! determination of the curve is performed by subroutine ! curvpp, the subroutin curvps only decomposes the workspace ! for curvpp. ! ! on input-- ! ! n is the number of values to be smoothed (n.ge.2). ! ! x is an array of the n increasing abscissae of the ! values to be smoothed. ! ! y is an array of the n ordinates of the values to be ! smoothed, (i. e. y(k) is the functional value ! corresponding to x(k) ). ! ! p is the period (p .gt. x(n)-x(1)). ! ! d is a parameter containing the observation weights. ! this may either be an array of length n or a scalar ! (interpreted as a constant). the value of d ! corresponding to the observation (x(k),y(k)) should ! be an approximation to the standard deviation of error. ! ! isw contains a switch indicating whether the parameter ! d is to be considered a vector or a scalar, ! = 0 if d is an array of length n, ! = 1 if d is a scalar. ! ! s contains the value controlling the smoothing. this ! must be non-negative. for s equal to zero, the ! subroutine does interpolation, larger values lead to ! smoother funtions. if parameter d contains standard ! deviation estimates, a reasonable value for s is ! float(n). ! ! eps contains a tolerance on the relative precision to ! which s is to be interpreted. this must be greater than ! or equal to zero and less than or equal to one. a ! reasonable value for eps is sqrt(2./float(n)). ! ! ys is an array of length at least n. ! ! ysp is an array of length at least n. ! ! sigma contains the tension factor. this value indicates ! the degree to which the first derivative part of the ! smoothing functional is emphasized. if sigma is nearly ! zero (e. g. .001) the resulting curve is approximately a ! cubic spline. if sigma is large (e. g. 50.) the ! resulting curve is nearly a polygonal line. if sigma ! equals zero a cubic spline results. a standard value for ! sigma is approximately 1. ! ! and ! ! temp is an array of length at least 11*n which is used ! for scratch storage. ! ! on output-- ! ! ys contains the smoothed ordinate values. ! ! ysp contains the values of the second derivative of the ! smoothed curve at the given nodes. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2, ! = 2 if s is negative, ! = 3 if eps is negative or greater than one, ! = 4 if x-values are not strictly increasing, ! = 5 if a d-value is non-positive, ! = 6 if p is less than or equal to x(n)-x(1). ! ! and ! ! n, x, y, p, d, isw, s, eps, and sigma are unaltered. ! ! this subroutine references package modules curvpp, terms, ! and snhcsh. ! !----------------------------------------------------------- ! ! decompose temp into eleven arrays and call curvpp ! call fitp_curvpp(n, x, y, p, d, isw, s, eps, ys, ysp, sigma, & temp(1, 1), temp(1, 2), temp(1, 3), temp(1, 4), & temp(1, 5), temp(1, 6), temp(1, 7), temp(1, 8), & temp(1, 9), temp(1, 10), temp(1, 11), ierr) return end subroutine fitp_curvps real function fitp_curvp2(t, n, x, y, p, yp, sigma) integer n real, dimension(:) :: x, y, yp real :: t, p, sigma ! real t,x(n),y(n),p,yp(n),sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function interpolates a curve at a given point using ! a periodic spline under tension. the subroutine curvp1 ! should be called earlier to determine certain necessary ! parameters. ! ! on input-- ! ! t contains a real value to be mapped onto the interpo- ! lating curve. ! ! n contains the number of points which were specified to ! determine the curve. ! ! x and y are arrays containing the abscissae and ! ordinates, respectively, of the specified points. ! ! p contains the period. ! ! yp is an array of second derivative values of the curve ! at the nodes. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, p, yp, and sigma should be input ! unaltered from the output of curvp1. ! ! on output-- ! ! curvp2 contains the interpolated value. ! ! none of the input parameters are altered. ! ! this function references package modules intrvp and ! snhcsh. ! !----------------------------------------------------------- integer i, im1 real ss, sigdel, sum, s2, s1, dummy real tp, sigmap, dels, del2, del1 ! ! determine interval ! im1 = fitp_intrvp(t, x, n, p, tp) i = im1 + 1 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n) / p ! ! set up and perform interpolation ! del1 = tp - x(im1) if (im1 == n) go to 1 del2 = x(i) - tp dels = x(i) - x(im1) go to 2 1 i = 1 del2 = x(1) + p - tp dels = p - (x(n) - x(1)) 2 sum = (y(i) * del1 + y(im1) * del2) / dels if (sigmap /= 0.) go to 3 fitp_curvp2 = sum - del1 * del2 * (yp(i) * (del1 + dels) + yp(im1) * (del2 + dels)) / (6.*dels) return 3 sigdel = sigmap * dels call fitp_snhcsh(ss, dummy, sigdel, -1) call fitp_snhcsh(s1, dummy, sigmap * del1, -1) call fitp_snhcsh(s2, dummy, sigmap * del2, -1) fitp_curvp2 = sum + (yp(i) * del1 * (s1 - ss) + yp(im1) * del2 * (s2 - ss)) / (sigdel * sigmap * (1.+ss)) end function fitp_curvp2 real function fitp_curvpd(t, n, x, y, p, yp, sigma) integer n real t, x(n), y(n), p, yp(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function is the derivative of curvp2 ! interpolates a curve at a given point using ! a periodic spline under tension. the subroutine curvp1 ! should be called earlier to determine certain necessary ! parameters. ! ! on input-- ! ! t contains a real value to be mapped onto the interpo- ! lating curve. ! ! n contains the number of points which were specified to ! determine the curve. ! ! x and y are arrays containing the abscissae and ! ordinates, respectively, of the specified points. ! ! p contains the period. ! ! yp is an array of second derivative values of the curve ! at the nodes. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, p, yp, and sigma should be input ! unaltered from the output of curvp1. ! ! on output-- ! ! curvpd contains the interpolated derivative ! ! none of the input parameters are altered. ! ! this function references package modules intrvp and ! snhcsh. ! !----------------------------------------------------------- integer i, im1 real ss, sigdel, sum, c2, c1, dummy real tp, sigmap, dels, del2, del1 ! ! determine interval ! im1 = fitp_intrvp(t, x, n, p, tp) i = im1 + 1 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n) / p ! ! set up and perform interpolation ! del1 = tp - x(im1) if (im1 == n) go to 1 del2 = x(i) - tp dels = x(i) - x(im1) go to 2 1 i = 1 del2 = x(1) + p - tp dels = p - (x(n) - x(1)) 2 sum = (y(i) - y(im1)) / dels if (sigmap /= 0.) go to 3 fitp_curvpd = sum + (yp(i) * (2.*del1 * del1 - del2 * (del1 + dels)) - & yp(im1) * (2.*del2 * del2 - del1 * (del2 + dels))) & / (6.*dels) return 3 sigdel = sigmap * dels call fitp_snhcsh(ss, dummy, sigdel, -1) call fitp_snhcsh(dummy, c1, sigmap * del1, -1) call fitp_snhcsh(dummy, c2, sigmap * del2, -1) fitp_curvpd = sum + (yp(i) * (c1 - ss) - yp(im1) * (c2 - ss)) / (sigdel * sigmap * (1.+ss)) return end function fitp_curvpd real function fitp_curvpi(xl, xu, n, x, y, p, yp, sigma) integer n real xl, xu, x(n), y(n), p, yp(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function integrates a curve specified by a periodic ! spline under tension between two given limits. the ! subroutine curvp1 should be called earlier to determine ! necessary parameters. ! ! on input-- ! ! xl and xu contain the upper and lower limits of inte- ! gration, respectively. (sl need not be less than or ! equal to xu, curvpi (xl,xu,...) .eq. -curvpi (xu,xl,...) ). ! ! n contains the number of points which were specified to ! determine the curve. ! ! x and y are arrays containing the abscissae and ! ordinates, respectively, of the specified points. ! ! p contains the period. ! ! yp is an array from subroutine curvp1 containing ! the values of the second derivatives at the nodes. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, p, yp, and sigma should be input ! unaltered from the output of curvp1. ! ! on output-- ! ! ! curvpi contains the integral value. ! ! none of the input parameters are altered. ! ! this function references package modules intrvp and ! snhcsh. ! !-------------------------------------------------------------- integer np1, im1, ii, iup1, ilp1, ideltp real s7, s6, s3, c2, c1, s5, s4, cl1, cu2, cu1, si, so real cl2, delu2, delu1, s8, deli, dell2, dell1, dummy integer ium1, il, isave, isign, lper, ilm1, iu, i real xxu, xsave, x1pp, sigmap, xxl, xil, del1, s2, cs real t2, t1, del2, s1, xiu, ss, dels integer uper logical bdy ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n) / p ! ! determine actual upper and lower bounds ! x1pp = x(1) + p isign = 1 ilm1 = fitp_intrvp(xl, x, n, p, xxl) lper = int((xl - x(1)) / p) if (xl < x(1)) lper = lper - 1 ium1 = fitp_intrvp(xu, x, n, p, xxu) uper = int((xu - x(1)) / p) if (xu < x(1)) uper = uper - 1 ideltp = uper - lper bdy = real(ideltp) * (xxu - xxl) < 0. if ((ideltp == 0 .and. xxu < xxl) .or. ideltp < 0) isign = -1 if (bdy) ideltp = ideltp - isign if (xxu >= xxl) go to 1 xsave = xxl xxl = xxu xxu = xsave isave = ilm1 ilm1 = ium1 ium1 = isave 1 il = ilm1 + 1 if (ilm1 == n) il = 1 xil = x(il) if (ilm1 == n) xil = x1pp iu = ium1 + 1 if (ium1 == n) iu = 1 xiu = x(iu) if (ium1 == n) xiu = x1pp s1 = 0. if (ilm1 == 1 .or. (ideltp == 0 .and. .not. bdy)) go to 4 ! ! integrate from x(1) to x(ilm1), store in s1 ! do i = 2, ilm1 dels = x(i) - x(i - 1) s1 = s1 + (y(i) + y(i - 1)) * dels / 2. if (sigma == 0.) go to 2 call fitp_snhcsh(ss, cs, sigmap * dels, 3) s1 = s1 + (yp(i) + yp(i - 1)) * dels * (cs - ss / 2.) / (sigmap * sigmap * (1.+ss)) cycle 2 s1 = s1 - (yp(i) + yp(i - 1)) * dels * dels * dels / 24. end do 4 s2 = 0. if (x(ilm1) >= xxl .or. (ideltp == 0 .and. .not. bdy)) go to 6 ! ! integrate from x(ilm1) to xxl, store in s2 ! del1 = xxl - x(ilm1) del2 = xil - xxl dels = xil - x(ilm1) t1 = del1 * del1 / (2.*dels) t2 = (del2 + dels) * del1 / (2.*dels) s2 = t1 * y(il) + t2 * y(ilm1) if (sigma == 0.) go to 5 call fitp_snhcsh(dummy, c1, sigmap * del1, 2) call fitp_snhcsh(dummy, c2, sigmap * del2, 2) call fitp_snhcsh(ss, cs, sigmap * dels, 3) s2 = s2 + (yp(il) * del1 * del1 * (c1 - ss / 2.) + yp(ilm1) * & (dels * dels * (cs - ss / 2.) - del2 * del2 * (c2 - ss / 2.))) & / (sigmap * sigmap * dels * (1.+ss)) go to 6 5 s2 = s2 - t1 * (del2 * (del1 + dels) & + dels * dels) * yp(il) / 12. & -t2 * t2 * dels * yp(ilm1) / 6. 6 s3 = 0. if (xxl >= xil .or. (ideltp == 0 .and. bdy) .or. ilm1 == ium1) go to 8 ! ! integrate from xxl to xil, store in s3 ! del1 = xxl - x(ilm1) del2 = xil - xxl dels = xil - x(ilm1) t1 = (del1 + dels) * del2 / (2.*dels) t2 = del2 * del2 / (2.*dels) s3 = t1 * y(il) + t2 * y(ilm1) if (sigma == 0.) go to 7 call fitp_snhcsh(dummy, c1, sigmap * del1, 2) call fitp_snhcsh(dummy, c2, sigmap * del2, 2) call fitp_snhcsh(ss, cs, sigmap * dels, 3) s3 = s3 + ((dels * dels * (cs - ss / 2.) - del1 * del1 * (c1 - ss / 2.)) & * yp(il) + del2 * del2 * (c2 - ss / 2.) * yp(ilm1)) / & (sigmap * sigmap * dels * (1.+ss)) go to 8 7 s3 = s3 - t1 * t1 * dels * yp(il) / 6. & -t2 * (del1 * (del2 + dels) + dels * dels) * & yp(ilm1) / 12. 8 s4 = 0. if (ilm1 >= ium1 - 1 .or. (ideltp == 0 .and. bdy)) go to 11 ! ! integrate from xil to x(ium1), store in s4 ! ilp1 = il + 1 do i = ilp1, ium1 dels = x(i) - x(i - 1) s4 = s4 + (y(i) + y(i - 1)) * dels / 2. if (sigma == 0.) go to 9 call fitp_snhcsh(ss, cs, sigmap * dels, 3) s4 = s4 + (yp(i) + yp(i - 1)) * dels * (cs - ss / 2.) / (sigmap * sigmap * (1.+ss)) cycle 9 s4 = s4 - (yp(i) + yp(i - 1)) * dels * dels * dels / 24. end do 11 s5 = 0. if (x(ium1) >= xxu .or. (ideltp == 0 .and. bdy) .or. ilm1 == ium1) go to 13 ! ! integrate from x(ium1) to xxu, store in s5 ! del1 = xxu - x(ium1) del2 = xiu - xxu dels = xiu - x(ium1) t1 = del1 * del1 / (2.*dels) t2 = (del2 + dels) * del1 / (2.*dels) s5 = t1 * y(iu) + t2 * y(ium1) if (sigma == 0.) go to 12 call fitp_snhcsh(dummy, c1, sigmap * del1, 2) call fitp_snhcsh(dummy, c2, sigmap * del2, 2) call fitp_snhcsh(ss, cs, sigmap * dels, 3) s5 = s5 + (yp(iu) * del1 * del1 * (c1 - ss / 2.) + yp(ium1) * & (dels * dels * (cs - ss / 2.) - del2 * del2 * (c2 - ss / 2.))) & / (sigmap * sigmap * dels * (1.+ss)) go to 13 12 s5 = s5 - t1 * (del2 * (del1 + dels) + dels * dels) * yp(iu) / 12.-t2 * t2 * dels * yp(ium1) / 6. 13 s6 = 0. if (xxu >= xiu .or. (ideltp == 0 .and. .not. bdy)) go to 15 ! ! integrate from xxu to xiu, store in s6 ! del1 = xxu - x(ium1) del2 = xiu - xxu dels = xiu - x(ium1) t1 = (del1 + dels) * del2 / (2.*dels) t2 = del2 * del2 / (2.*dels) s6 = t1 * y(iu) + t2 * y(ium1) if (sigma == 0.) go to 14 call fitp_snhcsh(dummy, c1, sigmap * del1, 2) call fitp_snhcsh(dummy, c2, sigmap * del2, 2) call fitp_snhcsh(ss, cs, sigmap * dels, 3) s6 = s6 + ((dels * dels * (cs - ss / 2.) - del1 * del1 * (c1 - ss / 2.)) & * yp(iu) + del2 * del2 * (c2 - ss / 2.) * yp(ium1)) / & (sigmap * sigmap * dels * (1.+ss)) go to 15 14 s6 = s6 - t1 * t1 * dels * yp(iu) / 6.-t2 * (del1 * (del2 + dels) + dels * dels) * yp(ium1) / 12. 15 s7 = 0. if (iu == 1 .or. (ideltp == 0 .and. .not. bdy)) go to 18 ! ! integrate from xiu to x1pp, store in s7 ! np1 = n + 1 iup1 = iu + 1 do ii = iup1, np1 im1 = ii - 1 i = ii if (i == np1) i = 1 dels = x(i) - x(im1) if (dels <= 0.) dels = dels + p s7 = s7 + (y(i) + y(im1)) * dels / 2. if (sigma == 0.) go to 16 call fitp_snhcsh(ss, cs, sigmap * dels, 3) s7 = s7 + (yp(i) + yp(im1)) * dels * (cs - ss / 2.) / (sigmap * sigmap * (1.+ss)) cycle 16 s7 = s7 - (yp(i) + yp(im1)) * dels * dels * dels / 24. end do 18 s8 = 0. if (ilm1 < ium1 .or. (ideltp == 0 .and. bdy)) go to 20 ! ! integrate from xxl to xxu, store in s8 ! delu1 = xxu - x(ium1) delu2 = xiu - xxu dell1 = xxl - x(ium1) dell2 = xiu - xxl dels = xiu - x(ium1) deli = xxu - xxl t1 = (delu1 + dell1) * deli / (2.*dels) t2 = (delu2 + dell2) * deli / (2.*dels) s8 = t1 * y(iu) + t2 * y(ium1) if (sigma == 0.) go to 19 call fitp_snhcsh(dummy, cu1, sigmap * delu1, 2) call fitp_snhcsh(dummy, cu2, sigmap * delu2, 2) call fitp_snhcsh(dummy, cl1, sigmap * dell1, 2) call fitp_snhcsh(dummy, cl2, sigmap * dell2, 2) call fitp_snhcsh(ss, dummy, sigmap * dels, -1) s8 = s8 + (yp(iu) * (delu1 * delu1 * (cu1 - ss / 2.) & - dell1 * dell1 * (cl1 - ss / 2.)) & + yp(ium1) * (dell2 * dell2 * (cl2 - ss / 2.) & - delu2 * delu2 * (cu2 - ss / 2.))) / & (sigmap * sigmap * dels * (1.+ss)) go to 20 19 s8 = s8 - t1 * (delu2 * (dels + delu1) & + dell2 * (dels + dell1)) * yp(iu) / 12. & -t2 * (dell1 * (dels + dell2) & + delu1 * (dels + delu2)) * yp(ium1) / 12. 20 so = s1 + s2 + s6 + s7 si = s3 + s4 + s5 + s8 if (bdy) go to 21 fitp_curvpi = real(ideltp) * (so + si) + real(isign) * si return 21 fitp_curvpi = real(ideltp) * (so + si) + real(isign) * so return end function fitp_curvpi subroutine fitp_kurv1(n, x, y, slp1, slpn, islpsw, xp, yp, temp, s, sigma, ierr) integer n, islpsw, ierr real x(n), y(n), slp1, slpn, xp(n), yp(n), temp(n), s(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute a spline under tension forming a curve in the ! plane and passing through a sequence of pairs (x(1),y(1)), ! ...,(x(n),y(n)). for actual computation of points on the ! curve it is necessary to call the subroutine kurv2. ! ! on input-- ! ! n is the number of points to be interpolated (n.ge.2). ! ! x is an array containing the n x-coordinates of the ! points. ! ! y is an array containing the n y-coordinates of the ! points. (adjacent x-y pairs must be distinct, i. e. ! either x(i) .ne. x(i+1) or y(i) .ne. y(i+1), for ! i = 1,...,n-1.) ! ! slp1 and slpn contain the desired values for the angles ! (in radians) of the slope at (x(1),y(1)) and (x(n),y(n)) ! respectively. the angles are measured counter-clock- ! wise from the x-axis and the positive sense of the curve ! is assumed to be that moving from point 1 to point n. ! the user may omit values for either or both of these ! parameters and signal this with islpsw. ! ! islpsw contains a switch indicating which slope data ! should be used and which should be estimated by this ! subroutine, ! = 0 if slp1 and slpn are to be used, ! = 1 if slp1 is to be used but not slpn, ! = 2 if slpn is to be used but not slp1, ! = 3 if both slp1 and slpn are to be estimated ! internally. ! ! xp and yp are arrays of length at least n. ! ! temp is an array of length at least n which is used ! for scratch storage. ! ! s is an array of length at least n. ! ! and ! ! sigma contains the tension factor. this value indicates ! the curviness desired. if abs(sigma) is nearly zero ! (e.g. .001) the resulting curve is approximately a cubic ! spline. if abs(sigma) is large (e. g. 50.) the resulting ! curve is nearly a polygonal line. if sigma equals zero a ! cubic spline results. a standard value for sigma is ! approximately 1. in absolute value. ! ! on output-- ! ! xp and yp contain information about the curvature of the ! curve at the given nodes. ! ! s contains the polygonal arclengths of the curve. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2, ! = 2 if adjacent coordinate pairs coincide. ! ! and ! ! n, x, y, slp1, slpn, islpsw, and sigma are unaltered. ! ! this subroutine references package modules ceez, terms, ! and snhcsh. ! !----------------------------------------------------------- integer ibak, im1, nm1, np1, i real dx1, dy1, diag1, delsnm, slppnx, slppny, delsn real diag, diagin, sdiag1, sdiag2, dx2, dy2, diag2 real sigmap, slpp1x, slpp1y, dels1, sx, sy, delt real c3, dels2, c1, c2 nm1 = n - 1 np1 = n + 1 ierr = 0 if (n <= 1) go to 11 ! ! determine polygonal arclengths ! s(1) = 0. do i = 2, n im1 = i - 1 s(i) = s(im1) + sqrt((x(i) - x(im1))**2 + (y(i) - y(im1))**2) end do ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n - 1) / s(n) ! ! approximate end slopes ! if (islpsw >= 2) go to 2 slpp1x = cos(slp1) slpp1y = sin(slp1) go to 4 2 dels1 = s(2) - s(1) dels2 = dels1 + dels1 if (n > 2) dels2 = s(3) - s(1) if (dels1 == 0. .or. dels2 == 0.) go to 12 call fitp_ceez(dels1, dels2, sigmap, c1, c2, c3, n) sx = c1 * x(1) + c2 * x(2) sy = c1 * y(1) + c2 * y(2) if (n == 2) go to 3 sx = sx + c3 * x(3) sy = sy + c3 * y(3) 3 delt = sqrt(sx * sx + sy * sy) slpp1x = sx / delt slpp1y = sy / delt 4 if (islpsw == 1 .or. islpsw == 3) go to 5 slppnx = cos(slpn) slppny = sin(slpn) go to 7 5 delsn = s(n) - s(nm1) delsnm = delsn + delsn if (n > 2) delsnm = s(n) - s(n - 2) if (delsn == 0. .or. delsnm == 0.) go to 12 call fitp_ceez(-delsn, -delsnm, sigmap, c1, c2, c3, n) sx = c1 * x(n) + c2 * x(nm1) sy = c1 * y(n) + c2 * y(nm1) if (n == 2) go to 6 sx = sx + c3 * x(n - 2) sy = sy + c3 * y(n - 2) 6 delt = sqrt(sx * sx + sy * sy) slppnx = sx / delt slppny = sy / delt ! ! set up right hand sides and tridiagonal system for xp and ! yp and perform forward elimination ! 7 dx1 = (x(2) - x(1)) / s(2) dy1 = (y(2) - y(1)) / s(2) call fitp_terms(diag1, sdiag1, sigmap, s(2)) xp(1) = (dx1 - slpp1x) / diag1 yp(1) = (dy1 - slpp1y) / diag1 temp(1) = sdiag1 / diag1 if (n == 2) go to 9 do i = 2, nm1 dels2 = s(i + 1) - s(i) if (dels2 == 0.) go to 12 dx2 = (x(i + 1) - x(i)) / dels2 dy2 = (y(i + 1) - y(i)) / dels2 call fitp_terms(diag2, sdiag2, sigmap, dels2) diag = diag1 + diag2 - sdiag1 * temp(i - 1) diagin = 1./diag xp(i) = (dx2 - dx1 - sdiag1 * xp(i - 1)) * diagin yp(i) = (dy2 - dy1 - sdiag1 * yp(i - 1)) * diagin temp(i) = sdiag2 * diagin dx1 = dx2 dy1 = dy2 diag1 = diag2 sdiag1 = sdiag2 end do 9 diag = diag1 - sdiag1 * temp(nm1) xp(n) = (slppnx - dx1 - sdiag1 * xp(nm1)) / diag yp(n) = (slppny - dy1 - sdiag1 * yp(nm1)) / diag ! ! perform back substitution ! do i = 2, n ibak = np1 - i xp(ibak) = xp(ibak) - temp(ibak) * xp(ibak + 1) yp(ibak) = yp(ibak) - temp(ibak) * yp(ibak + 1) end do return ! ! too few points ! 11 ierr = 1 return ! ! coincident adjacent points ! 12 ierr = 2 return end subroutine fitp_kurv1 subroutine fitp_kurv2(t, xs, ys, n, x, y, xp, yp, s, sigma) integer n real t, xs, ys, x(n), y(n), xp(n), yp(n), s(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine performs the mapping of points in the ! interval (0.,1.) onto a curve in the plane. the subroutine ! kurv1 should be called earlier to determine certain ! necessary parameters. the resulting curve has a parametric ! representation both of whose components are splines under ! tension and functions of the polygonal arclength ! parameter. ! ! on input-- ! ! t contains a real value to be mapped to a point on the ! curve. the interval (0.,1.) is mapped onto the entire ! curve, with 0. mapping to (x(1),y(1)) and 1. mapping ! to (x(n),y(n)). values outside this interval result in ! extrapolation. ! ! n contains the number of points which were specified ! to determine the curve. ! ! x and y are arrays containing the x- and y-coordinates ! of the specified points. ! ! xp and yp are the arrays output from kurv1 containing ! curvature information. ! ! s is an array containing the polygonal arclengths of ! the curve. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, xp, yp, s, and sigma should be ! input unaltered from the output of kurv1. ! ! on output-- ! ! xs and ys contain the x- and y-coordinates of the image ! point on the curve. ! ! none of the input parameters are altered. ! ! this subroutine references package modules intrvl and ! snhcsh. ! !----------------------------------------------------------- integer i, im1 real c2, sigdel, d, c1, s1, s2, ss, dummy real sigmap, tn, del1, sumx, sumy, del2, dels ! ! determine interval ! tn = s(n) * t im1 = fitp_intrvl(tn, s, n) i = im1 + 1 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n - 1) / s(n) ! ! set up and perform interpolation ! del1 = tn - s(im1) del2 = s(i) - tn dels = s(i) - s(im1) sumx = (x(i) * del1 + x(im1) * del2) / dels sumy = (y(i) * del1 + y(im1) * del2) / dels if (sigmap /= 0.) go to 1 d = del1 * del2 / (6.*dels) c1 = (del1 + dels) * d c2 = (del2 + dels) * d xs = sumx - xp(i) * c1 - xp(im1) * c2 ys = sumy - yp(i) * c1 - yp(im1) * c2 return 1 sigdel = sigmap * dels call fitp_snhcsh(ss, dummy, sigdel, -1) call fitp_snhcsh(s1, dummy, sigmap * del1, -1) call fitp_snhcsh(s2, dummy, sigmap * del2, -1) d = sigdel * sigmap * (1.+ss) c1 = del1 * (s1 - ss) / d c2 = del2 * (s2 - ss) / d xs = sumx + xp(i) * c1 + xp(im1) * c2 ys = sumy + yp(i) * c1 + yp(im1) * c2 return end subroutine fitp_kurv2 subroutine fitp_kurvd(t, xs, ys, xst, yst, xstt, ystt, n, x, y, xp, yp, s, sigma) integer n real t, xs, ys, xst, yst, xstt, ystt, x(n), y(n), xp(n), yp(n), s(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine performs the mapping of points in the ! interval (0.,1.) onto a curve in the plane. it also ! returns the first and second derivatives of the component ! functions. the subroutine kurv1 should be called earlier ! to determine certain necessary parameters. the resulting ! curve has a parametric representation both of whose ! components are splines under tension and functions of the ! polygonal arclength parameter. ! ! on input-- ! ! t contains a real value to be mapped to a point on the ! curve. the interval (0.,1.) is mapped onto the entire ! curve, with 0. mapping to (x(1),y(1)) and 1. mapping ! to (x(n),y(n)). values outside this interval result in ! extrapolation. ! ! n contains the number of points which were specified ! to determine the curve. ! ! x and y are arrays containing the x- and y-coordinates ! of the specified points. ! ! xp and yp are the arrays output from kurv1 containing ! curvature information. ! ! s is an array containing the polygonal arclengths of ! the curve. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, xp, yp, s, and sigma should be ! input unaltered from the output of kurv1. ! ! on output-- ! ! xs and ys contain the x- and y-coordinates of the image ! point on the curve. xst and yst contain the first ! derivatives of the x- and y-components of the mapping ! with respect to t. xstt and ystt contain the second ! derivatives of the x- and y-components of the mapping ! with respect to t. ! ! none of the input parameters are altered. ! ! this subroutine references package modules intrvl and ! snhcsh. ! !----------------------------------------------------------- integer im1, i real ctt1, ctt2, sigdel, c2, ct1, ct2, co1, s2, co2, ss real dummy, s1, c1, sigmap, del1, del2, tn, dels, sumyt real dels6, d, sumx, sumy, sumxt ! ! determine interval ! tn = s(n) * t im1 = fitp_intrvl(tn, s, n) i = im1 + 1 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n - 1) / s(n) ! ! set up and perform interpolation ! del1 = tn - s(im1) del2 = s(i) - tn dels = s(i) - s(im1) sumx = (x(i) * del1 + x(im1) * del2) / dels sumy = (y(i) * del1 + y(im1) * del2) / dels sumxt = s(n) * (x(i) - x(im1)) / dels sumyt = s(n) * (y(i) - y(im1)) / dels if (sigmap /= 0.) go to 1 dels6 = 6.*dels d = del1 * del2 / dels6 c1 = -(del1 + dels) * d c2 = -(del2 + dels) * d dels6 = dels6 / s(n) ct1 = (2.*del1 * del1 - del2 * (del1 + dels)) / dels6 ct2 = -(2.*del2 * del2 - del1 * (del2 + dels)) / dels6 dels = dels / (s(n) * s(n)) ctt1 = del1 / dels ctt2 = del2 / dels go to 2 1 sigdel = sigmap * dels call fitp_snhcsh(ss, dummy, sigdel, -1) call fitp_snhcsh(s1, co1, sigmap * del1, 0) call fitp_snhcsh(s2, co2, sigmap * del2, 0) d = sigdel * sigmap * (1.+ss) c1 = del1 * (s1 - ss) / d c2 = del2 * (s2 - ss) / d ct1 = (co1 - ss) * s(n) / d ct2 = -(co2 - ss) * s(n) / d ctt1 = del1 * (1.+s1) * s(n) * s(n) / (dels * (1.+ss)) ctt2 = del2 * (1.+s2) * s(n) * s(n) / (dels * (1.+ss)) 2 xs = sumx + c1 * xp(i) + c2 * xp(im1) ys = sumy + c1 * yp(i) + c2 * yp(im1) xst = sumxt + ct1 * xp(i) + ct2 * xp(im1) yst = sumyt + ct1 * yp(i) + ct2 * yp(im1) xstt = ctt1 * xp(i) + ctt2 * xp(im1) ystt = ctt1 * yp(i) + ctt2 * yp(im1) return end subroutine fitp_kurvd subroutine fitp_kurvp1(n, x, y, xp, yp, temp, s, sigma, ierr) integer n, ierr real x(n), y(n), xp(n), yp(n), temp(1), s(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute a spline under tension forming a closed curve in ! the plane and passing through a sequence of pairs ! (x(1),y(1)),...,(x(n),y(n)). for actual computation of ! points on the curve it is necessary to call the subroutine ! kurvp2. ! ! on input-- ! ! n is the number of points to be interpolated (n.ge.2). ! ! x is an array containing the n x-coordinates of the ! points. ! ! y is an array containing the n y-coordinates of the ! points. (adjacent x-y pairs must be distinct, i. e. ! either x(i) .ne. x(i+1) or y(i) .ne. y(i+1), for ! i = 1,...,n-1 and either x(1) .ne. x(n) or y(1) .ne. y(n).) ! ! xp and yp are arrays of length at least n. ! ! temp is an array of length at least 2*n which is used ! for scratch storage. ! ! s is an array of length at least n. ! ! and ! ! sigma contains the tension factor. this value indicates ! the curviness desired. if abs(sigma) is nearly zero ! (e.g. .001) the resulting curve is approximately a cubic ! spline. if abs(sigma) is large (e. g. 50.) the resulting ! curve is nearly a polygonal line. if sigma equals zero a ! cubic spline results. a standard value for sigma is ! approximately 1. in absolute value. ! ! on output-- ! ! xp and yp contain information about the curvature of the ! curve at the given nodes. ! ! s contains the polygonal arclengths of the curve. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2, ! = 2 if adjacent coordinate pairs coincide. ! ! and ! ! n, x, y, and sigma are unaltered, ! ! this subroutine references package modules terms and ! snhcsh. ! !----------------------------------------------------------- integer npibak, npi, ibak, im1, i, nm1, np1 real sdiag2, diag, diag2, dx2, dy2, diagin, xpn, ypn real sigmap, dels1, sdiag1, dels2, diag1, dx1, dy1 nm1 = n - 1 np1 = n + 1 ierr = 0 if (n <= 1) go to 7 ! ! determine polygonal arclengths ! s(1) = sqrt((x(n) - x(1))**2 + (y(n) - y(1))**2) do i = 2, n im1 = i - 1 s(i) = s(im1) + sqrt((x(i) - x(im1))**2 + (y(i) - y(im1))**2) end do ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n) / s(n) ! ! set up right hand sides of tridiagonal (with corner ! elements) linear system for xp and yp ! dels1 = s(1) if (dels1 == 0.) go to 8 dx1 = (x(1) - x(n)) / dels1 dy1 = (y(1) - y(n)) / dels1 call fitp_terms(diag1, sdiag1, sigmap, dels1) dels2 = s(2) - s(1) if (dels2 == 0.) go to 8 dx2 = (x(2) - x(1)) / dels2 dy2 = (y(2) - y(1)) / dels2 call fitp_terms(diag2, sdiag2, sigmap, dels2) diag = diag1 + diag2 diagin = 1./diag xp(1) = (dx2 - dx1) * diagin yp(1) = (dy2 - dy1) * diagin temp(np1) = -sdiag1 * diagin temp(1) = sdiag2 * diagin dx1 = dx2 dy1 = dy2 diag1 = diag2 sdiag1 = sdiag2 if (n == 2) go to 3 do i = 2, nm1 npi = n + i dels2 = s(i + 1) - s(i) if (dels2 == 0.) go to 8 dx2 = (x(i + 1) - x(i)) / dels2 dy2 = (y(i + 1) - y(i)) / dels2 call fitp_terms(diag2, sdiag2, sigmap, dels2) diag = diag1 + diag2 - sdiag1 * temp(i - 1) diagin = 1./diag xp(i) = (dx2 - dx1 - sdiag1 * xp(i - 1)) * diagin yp(i) = (dy2 - dy1 - sdiag1 * yp(i - 1)) * diagin temp(npi) = -temp(npi - 1) * sdiag1 * diagin temp(i) = sdiag2 * diagin dx1 = dx2 dy1 = dy2 diag1 = diag2 sdiag1 = sdiag2 end do 3 dels2 = s(1) dx2 = (x(1) - x(n)) / dels2 dy2 = (y(1) - y(n)) / dels2 call fitp_terms(diag2, sdiag2, sigmap, dels2) xp(n) = dx2 - dx1 yp(n) = dy2 - dy1 temp(nm1) = temp(2 * n - 1) - temp(nm1) if (n == 2) go to 5 ! ! perform first step of back substitution ! do i = 3, n ibak = np1 - i npibak = n + ibak xp(ibak) = xp(ibak) - temp(ibak) * xp(ibak + 1) yp(ibak) = yp(ibak) - temp(ibak) * yp(ibak + 1) temp(ibak) = temp(npibak) - temp(ibak) * temp(ibak + 1) end do 5 xp(n) = (xp(n) - sdiag2 * xp(1) - sdiag1 * xp(nm1)) / & (diag1 + diag2 + sdiag2 * temp(1) + sdiag1 * temp(nm1)) yp(n) = (yp(n) - sdiag2 * yp(1) - sdiag1 * yp(nm1)) / & (diag1 + diag2 + sdiag2 * temp(1) + sdiag1 * temp(nm1)) ! ! perform second step of back substitution ! xpn = xp(n) ypn = yp(n) do i = 1, nm1 xp(i) = xp(i) + temp(i) * xpn yp(i) = yp(i) + temp(i) * ypn end do return ! ! too few points ! 7 ierr = 1 return ! ! coincident adjacent points ! 8 ierr = 2 return end subroutine fitp_kurvp1 subroutine fitp_kurvp2(t, xs, ys, n, x, y, xp, yp, s, sigma) integer n real t, xs, ys, x(n), y(n), xp(n), yp(n), s(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine performs the mapping of points in the ! interval (0.,1.) onto a closed curve in the plane. the ! subroutine kurvp1 should be called earlier to determine ! certain necessary parameters. the resulting curve has a ! parametric representation both of whose components are ! periodic splines under tension and functions of the poly- ! gonal arclength parameter. ! ! on input-- ! ! t contains a value to be mapped onto the curve. the ! interval (0.,1.) is mapped onto the entire closed curve ! with both 0. and 1. mapping to (x(1),y(1)). the mapping ! is periodic with period one thus any interval of the ! form (tt,tt+1.) maps onto the entire curve. ! ! n contains the number of points which were specified ! to determine the curve. ! ! x and y are arrays containing the x- and y-coordinates ! of the specified points. ! ! xp and yp are the arrays output from kurvp1 containing ! curvature information. ! ! s is an array containing the polygonal arclengths of ! the curve. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, xp, yp, s and sigma should ! be input unaltered from the output of kurvp1. ! ! on output-- ! ! xs and ys contain the x- and y-coordinates of the image ! point on the curve. ! ! none of the input parameters are altered. ! ! this subroutine references package modules intrvl and ! snhcsh. ! !----------------------------------------------------------- integer i, im1 real sigdel, ss, c1, c2, dummy, ci, cim1, s1, s2, d real sigmap, si, tn, sumx, sumy, dels, del1, del2 ! ! determine interval ! tn = t - real(int(t)) if (tn < 0.) tn = tn + 1. tn = s(n) * tn + s(1) im1 = n if (tn < s(n)) im1 = fitp_intrvl(tn, s, n) i = im1 + 1 if (i > n) i = 1 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n) / s(n) ! ! set up and perform interpolation ! si = s(i) if (im1 == n) si = s(n) + s(1) del1 = tn - s(im1) del2 = si - tn dels = si - s(im1) sumx = (x(i) * del1 + x(im1) * del2) / dels sumy = (y(i) * del1 + y(im1) * del2) / dels if (sigmap /= 0.) go to 1 d = del1 * del2 / (6.*dels) c1 = (del1 + dels) * d c2 = (del2 + dels) * d xs = sumx - xp(i) * c1 - xp(im1) * c2 ys = sumy - yp(i) * c1 - yp(im1) * c2 return 1 sigdel = sigmap * dels call fitp_snhcsh(ss, dummy, sigdel, -1) call fitp_snhcsh(s1, dummy, sigmap * del1, -1) call fitp_snhcsh(s2, dummy, sigmap * del2, -1) d = sigdel * sigmap * (1.+ss) ci = del1 * (s1 - ss) / d cim1 = del2 * (s2 - ss) / d xs = sumx + xp(i) * ci + xp(im1) * cim1 ys = sumy + yp(i) * ci + yp(im1) * cim1 return end subroutine fitp_kurvp2 subroutine fitp_kurvpd(t, xs, ys, xst, yst, xstt, ystt, n, x, y, xp, yp, s, sigma) integer n real t, xs, ys, xst, yst, xstt, ystt, x(n), y(n), xp(n), yp(n), s(n), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine performs the mapping of points in the ! interval (0.,1.) onto a closed curve in the plane. it also ! returns the first and second derivatives of the component ! functions. the subroutine kurvp1 should be called earlier ! to determine certain necessary parameters. the resulting ! curve has a parametric representation both of whose ! components are periodic splines under tension and ! functions of the polygonal arclength parameter. ! ! on input-- ! ! t contains a value to be mapped onto the curve. the ! interval (0.,1.) is mapped onto the entire closed curve ! with both 0. and 1. mapping to (x(1),y(1)). the mapping ! is periodic with period one thus any interval of the ! form (tt,tt+1.) maps onto the entire curve. ! ! n contains the number of points which were specified ! to determine the curve. ! ! x and y are arrays containing the x- and y-coordinates ! of the specified points. ! ! xp and yp are the arrays output from kurvp1 containing ! curvature information. ! ! s is an array containing the polygonal arclengths of ! the curve. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters n, x, y, xp, yp, s and sigma should ! be input unaltered from the output of kurvp1. ! ! on output-- ! ! xs and ys contain the x- and y-coordinates of the image ! point on the curve. xst and yst contain the first ! derivatives of the x- and y-components of the mapping ! with respect to t. xstt and ystt contain the second ! derivatives of the x- and y-components of the mapping ! with respect to t. ! ! none of the input parameters are altered. ! ! this subroutine references package modules intrvl and ! snhcsh. ! !----------------------------------------------------------- integer im1, i real ct2, ctt1, ctt2, c1, c2, ct1, sigdel, co1, s2, co2, ss real dummy, s1, si, del1, del2, sigmap, tn real sumyt, dels6, d, sumxt, dels, sumx, sumy ! ! determine interval ! tn = t - real(int(t)) if (tn < 0.) tn = tn + 1. tn = s(n) * tn + s(1) im1 = n if (tn < s(n)) im1 = fitp_intrvl(tn, s, n) i = im1 + 1 if (i > n) i = 1 ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n) / s(n) ! ! set up and perform interpolation ! si = s(i) if (im1 == n) si = s(n) + s(1) del1 = tn - s(im1) del2 = si - tn dels = si - s(im1) sumx = (x(i) * del1 + x(im1) * del2) / dels sumy = (y(i) * del1 + y(im1) * del2) / dels sumxt = s(n) * (x(i) - x(im1)) / dels sumyt = s(n) * (y(i) - y(im1)) / dels if (sigmap /= 0.) go to 1 dels6 = 6.*dels d = del1 * del2 / dels6 c1 = -(del1 + dels) * d c2 = -(del2 + dels) * d dels6 = dels6 / s(n) ct1 = (2.*del1 * del1 - del2 * (del1 + dels)) / dels6 ct2 = -(2.*del2 * del2 - del1 * (del2 + dels)) / dels6 dels = dels / (s(n) * s(n)) ctt1 = del1 / dels ctt2 = del2 / dels go to 2 1 sigdel = sigmap * dels call fitp_snhcsh(ss, dummy, sigdel, -1) call fitp_snhcsh(s1, co1, sigmap * del1, 0) call fitp_snhcsh(s2, co2, sigmap * del2, 0) d = sigdel * sigmap * (1.+ss) c1 = del1 * (s1 - ss) / d c2 = del2 * (s2 - ss) / d ct1 = (co1 - ss) * s(n) / d ct2 = -(co2 - ss) * s(n) / d ctt1 = del1 * (1.+s1) * s(n) * s(n) / (dels * (1.+ss)) ctt2 = del2 * (1.+s2) * s(n) * s(n) / (dels * (1.+ss)) 2 xs = sumx + c1 * xp(i) + c2 * xp(im1) ys = sumy + c1 * yp(i) + c2 * yp(im1) xst = sumxt + ct1 * xp(i) + ct2 * xp(im1) yst = sumyt + ct1 * yp(i) + ct2 * yp(im1) xstt = ctt1 * xp(i) + ctt2 * xp(im1) ystt = ctt1 * yp(i) + ctt2 * yp(im1) return end subroutine fitp_kurvpd subroutine fitp_surf1(m, n, x, y, z, iz, zx1, zxm, zy1, zyn, zxy11, & zxym1, zxy1n, zxymn, islpsw, zp, temp, sigma, ierr) integer m, n, iz, islpsw, ierr real x(m), y(n), z(iz, n), zx1(n), zxm(n), zy1(m), zyn(m), & zxy11, zxym1, zxy1n, zxymn, zp(m, n, 3), temp(n + n + m), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute an interpolatory surface passing through a rect- ! angular grid of functional values. the surface determined ! can be represented as the tensor product of splines under ! tension. the x- and y-partial derivatives around the ! boundary and the x-y-partial derivatives at the four ! corners may be specified or omitted. for actual mapping ! of points onto the surface it is necessary to call the ! function surf2. ! ! on input-- ! ! m is the number of grid lines in the x-direction, i. e. ! lines parallel to the y-axis (m .ge. 2). ! ! n is the number of grid lines in the y-direction, i. e. ! lines parallel to the x-axis (n .ge. 2). ! ! x is an array of the m x-coordinates of the grid lines ! in the x-direction. these should be strictly increasing. ! ! y is an array of the n y-coordinates of the grid lines ! in the y-direction. these should be strictly increasing. ! ! z is an array of the m * n functional values at the grid ! points, i. e. z(i,j) contains the functional value at ! (x(i),y(j)) for i = 1,...,m and j = 1,...,n. ! ! iz is the row dimension of the matrix z used in the ! calling program (iz .ge. m). ! ! zx1 and zxm are arrays of the m x-partial derivatives ! of the function along the x(1) and x(m) grid lines, ! respectively. thus zx1(j) and zxm(j) contain the x-part- ! ial derivatives at the points (x(1),y(j)) and ! (x(m),y(j)), respectively, for j = 1,...,n. either of ! these parameters will be ignored (and approximations ! supplied internally) if islpsw so indicates. ! ! zy1 and zyn are arrays of the n y-partial derivatives ! of the function along the y(1) and y(n) grid lines, ! respectively. thus zy1(i) and zyn(i) contain the y-part- ! ial derivatives at the points (x(i),y(1)) and ! (x(i),y(n)), respectively, for i = 1,...,m. either of ! these parameters will be ignored (and estimations ! supplied internally) if islpsw so indicates. ! ! zxy11, zxym1, zxy1n, and zxymn are the x-y-partial ! derivatives of the function at the four corners, ! (x(1),y(1)), (x(m),y(1)), (x(1),y(n)), and (x(m),y(n)), ! respectively. any of the parameters will be ignored (and ! estimations supplied internally) if islpsw so indicates. ! ! islpsw contains a switch indicating which boundary ! derivative information is user-supplied and which ! should be estimated by this subroutine. to determine ! islpsw, let ! i1 = 0 if zx1 is user-supplied (and = 1 otherwise), ! i2 = 0 if zxm is user-supplied (and = 1 otherwise), ! i3 = 0 if zy1 is user-supplied (and = 1 otherwise), ! i4 = 0 if zyn is user-supplied (and = 1 otherwise), ! i5 = 0 if zxy11 is user-supplied ! (and = 1 otherwise), ! i6 = 0 if zxym1 is user-supplied ! (and = 1 otherwise), ! i7 = 0 if zxy1n is user-supplied ! (and = 1 otherwise), ! i8 = 0 if zxymn is user-supplied ! (and = 1 otherwise), ! then islpsw = i1 + 2*i2 + 4*i3 + 8*i4 + 16*i5 + 32*i6 ! + 64*i7 + 128*i8 ! thus islpsw = 0 indicates all derivative information is ! user-supplied and islpsw = 255 indicates no derivative ! information is user-supplied. any value between these ! limits is valid. ! ! zp is an array of at least 3*m*n locations. ! ! temp is an array of at least n+n+m locations which is ! used for scratch storage. ! ! and ! ! sigma contains the tension factor. this value indicates ! the curviness desired. if abs(sigma) is nearly zero ! (e. g. .001) the resulting surface is approximately the ! tensor product of cubic splines. if abs(sigma) is large ! (e. g. 50.) the resulting surface is approximately ! bi-linear. if sigma equals zero tensor products of ! cubic splines result. a standard value for sigma is ! approximately 1. in absolute value. ! ! on output-- ! ! zp contains the values of the xx-, yy-, and xxyy-partial ! derivatives of the surface at the given nodes. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2 or m is less than 2, ! = 2 if the x-values or y-values are not strictly ! increasing. ! ! and ! ! m, n, x, y, z, iz, zx1, zxm, zy1, zyn, zxy11, zxym1, ! zxy1n, zxymn, islpsw, and sigma are unaltered. ! ! this subroutine references package modules ceez, terms, ! and snhcsh. ! !----------------------------------------------------------- integer jbak, jbakp1, jm1, jp1, im1, ibakp1 integer npibak, ip1, ibak, nm1, np1, mm1, mp1, npm, j integer npmpj, i, npi real diagi, sdiag1, del2, zxymns, delxmm, del1 real diag1, deli, diag2, diagin, sdiag2, t real delxm, sigmay, dely1, c1, dely2, c2 real delx1, delx2, zxy1ns, c3, delyn, sigmax, delynm mm1 = m - 1 mp1 = m + 1 nm1 = n - 1 np1 = n + 1 npm = n + m ierr = 0 if (n <= 1 .or. m <= 1) go to 46 if (y(n) <= y(1)) go to 47 ! ! denormalize tension factor in y-direction ! sigmay = abs(sigma) * real(n - 1) / (y(n) - y(1)) ! ! obtain y-partial derivatives along y = y(1) ! if ((islpsw / 8) * 2 /= (islpsw / 4)) go to 2 do i = 1, m zp(i, 1, 1) = zy1(i) end do go to 5 2 dely1 = y(2) - y(1) dely2 = dely1 + dely1 if (n > 2) dely2 = y(3) - y(1) if (dely1 <= 0. .or. dely2 <= dely1) go to 47 call fitp_ceez(dely1, dely2, sigmay, c1, c2, c3, n) do i = 1, m zp(i, 1, 1) = c1 * z(i, 1) + c2 * z(i, 2) end do if (n == 2) go to 5 do i = 1, m zp(i, 1, 1) = zp(i, 1, 1) + c3 * z(i, 3) end do ! ! obtain y-partial derivatives along y = y(n) ! 5 if ((islpsw / 16) * 2 /= (islpsw / 8)) go to 7 do i = 1, m npi = n + i temp(npi) = zyn(i) end do go to 10 7 delyn = y(n) - y(nm1) delynm = delyn + delyn if (n > 2) delynm = y(n) - y(n - 2) if (delyn <= 0. .or. delynm <= delyn) go to 47 call fitp_ceez(-delyn, -delynm, sigmay, c1, c2, c3, n) do i = 1, m npi = n + i temp(npi) = c1 * z(i, n) + c2 * z(i, nm1) end do if (n == 2) go to 10 do i = 1, m npi = n + i temp(npi) = temp(npi) + c3 * z(i, n - 2) end do 10 if (x(m) <= x(1)) go to 47 ! ! denormalize tension factor in x-direction ! sigmax = abs(sigma) * real(m - 1) / (x(m) - x(1)) ! ! obtain x-partial derivatives along x = x(1) ! if ((islpsw / 2) * 2 /= islpsw) go to 12 do j = 1, n zp(1, j, 2) = zx1(j) end do if ((islpsw / 32) * 2 == (islpsw / 16) .and. (islpsw / 128) * 2 == (islpsw / 64)) go to 15 12 delx1 = x(2) - x(1) delx2 = delx1 + delx1 if (m > 2) delx2 = x(3) - x(1) if (delx1 <= 0. .or. delx2 <= delx1) go to 47 call fitp_ceez(delx1, delx2, sigmax, c1, c2, c3, m) if ((islpsw / 2) * 2 == islpsw) go to 15 do j = 1, n zp(1, j, 2) = c1 * z(1, j) + c2 * z(2, j) end do if (m == 2) go to 15 do j = 1, n zp(1, j, 2) = zp(1, j, 2) + c3 * z(3, j) end do ! ! obtain x-y-partial derivative at (x(1),y(1)) ! 15 if ((islpsw / 32) * 2 /= (islpsw / 16)) go to 16 zp(1, 1, 3) = zxy11 go to 17 16 zp(1, 1, 3) = c1 * zp(1, 1, 1) + c2 * zp(2, 1, 1) if (m > 2) zp(1, 1, 3) = zp(1, 1, 3) + c3 * zp(3, 1, 1) ! ! obtain x-y-partial derivative at (x(1),y(n)) ! 17 if ((islpsw / 128) * 2 /= (islpsw / 64)) go to 18 zxy1ns = zxy1n go to 19 18 zxy1ns = c1 * temp(n + 1) + c2 * temp(n + 2) if (m > 2) zxy1ns = zxy1ns + c3 * temp(n + 3) ! ! obtain x-partial derivative along x = x(m) ! 19 if ((islpsw / 4) * 2 /= (islpsw / 2)) go to 21 do j = 1, n npmpj = npm + j temp(npmpj) = zxm(j) end do if ((islpsw / 64) * 2 == (islpsw / 32) .and. (islpsw / 256) * 2 == (islpsw / 128)) go to 24 21 delxm = x(m) - x(mm1) delxmm = delxm + delxm if (m > 2) delxmm = x(m) - x(m - 2) if (delxm <= 0. .or. delxmm <= delxm) go to 47 call fitp_ceez(-delxm, -delxmm, sigmax, c1, c2, c3, m) if ((islpsw / 4) * 2 == (islpsw / 2)) go to 24 do j = 1, n npmpj = npm + j temp(npmpj) = c1 * z(m, j) + c2 * z(mm1, j) end do if (m == 2) go to 24 do j = 1, n npmpj = npm + j temp(npmpj) = temp(npmpj) + c3 * z(m - 2, j) end do ! ! obtain x-y-partial derivative at (x(m),y(1)) ! 24 if ((islpsw / 64) * 2 /= (islpsw / 32)) go to 25 zp(m, 1, 3) = zxym1 go to 26 25 zp(m, 1, 3) = c1 * zp(m, 1, 1) + c2 * zp(mm1, 1, 1) if (m > 2) zp(m, 1, 3) = zp(m, 1, 3) + c3 * zp(m - 2, 1, 1) ! ! obtain x-y-partial derivative at (x(m),y(n)) ! 26 if ((islpsw / 256) * 2 /= (islpsw / 128)) go to 27 zxymns = zxymn go to 28 27 zxymns = c1 * temp(npm) + c2 * temp(npm - 1) if (m > 2) zxymns = zxymns + c3 * temp(npm - 2) ! ! set up right hand sides and tridiagonal system for y-grid ! perform forward elimination ! 28 del1 = y(2) - y(1) if (del1 <= 0.) go to 47 deli = 1./del1 do i = 1, m zp(i, 2, 1) = deli * (z(i, 2) - z(i, 1)) end do zp(1, 2, 3) = deli * (zp(1, 2, 2) - zp(1, 1, 2)) zp(m, 2, 3) = deli * (temp(npm + 2) - temp(npm + 1)) call fitp_terms(diag1, sdiag1, sigmay, del1) diagi = 1./diag1 do i = 1, m zp(i, 1, 1) = diagi * (zp(i, 2, 1) - zp(i, 1, 1)) end do zp(1, 1, 3) = diagi * (zp(1, 2, 3) - zp(1, 1, 3)) zp(m, 1, 3) = diagi * (zp(m, 2, 3) - zp(m, 1, 3)) temp(1) = diagi * sdiag1 if (n == 2) go to 34 do j = 2, nm1 jm1 = j - 1 jp1 = j + 1 npmpj = npm + j del2 = y(jp1) - y(j) if (del2 <= 0.) go to 47 deli = 1./del2 do i = 1, m zp(i, jp1, 1) = deli * (z(i, jp1) - z(i, j)) end do zp(1, jp1, 3) = deli * (zp(1, jp1, 2) - zp(1, j, 2)) zp(m, jp1, 3) = deli * (temp(npmpj + 1) - temp(npmpj)) call fitp_terms(diag2, sdiag2, sigmay, del2) diagin = 1./(diag1 + diag2 - sdiag1 * temp(jm1)) do i = 1, m zp(i, j, 1) = diagin * (zp(i, jp1, 1) - zp(i, j, 1) - sdiag1 * zp(i, jm1, 1)) end do zp(1, j, 3) = diagin * (zp(1, jp1, 3) - zp(1, j, 3) - sdiag1 * zp(1, jm1, 3)) zp(m, j, 3) = diagin * (zp(m, jp1, 3) - zp(m, j, 3) - sdiag1 * zp(m, jm1, 3)) temp(j) = diagin * sdiag2 diag1 = diag2 sdiag1 = sdiag2 end do 34 diagin = 1./(diag1 - sdiag1 * temp(nm1)) do i = 1, m npi = n + i zp(i, n, 1) = diagin * (temp(npi) - zp(i, n, 1) - sdiag1 * zp(i, nm1, 1)) end do zp(1, n, 3) = diagin * (zxy1ns - zp(1, n, 3) - sdiag1 * zp(1, nm1, 3)) temp(n) = diagin * (zxymns - zp(m, n, 3) - sdiag1 * zp(m, nm1, 3)) ! ! perform back substitution ! do j = 2, n jbak = np1 - j jbakp1 = jbak + 1 t = temp(jbak) do i = 1, m zp(i, jbak, 1) = zp(i, jbak, 1) - t * zp(i, jbakp1, 1) end do zp(1, jbak, 3) = zp(1, jbak, 3) - t * zp(1, jbakp1, 3) temp(jbak) = zp(m, jbak, 3) - t * temp(jbakp1) end do ! ! set up right hand sides and tridiagonal system for x-grid ! perform forward elimination ! del1 = x(2) - x(1) if (del1 <= 0.) go to 47 deli = 1./del1 do j = 1, n zp(2, j, 2) = deli * (z(2, j) - z(1, j)) zp(2, j, 3) = deli * (zp(2, j, 1) - zp(1, j, 1)) end do call fitp_terms(diag1, sdiag1, sigmax, del1) diagi = 1./diag1 do j = 1, n zp(1, j, 2) = diagi * (zp(2, j, 2) - zp(1, j, 2)) zp(1, j, 3) = diagi * (zp(2, j, 3) - zp(1, j, 3)) end do temp(n + 1) = diagi * sdiag1 if (m == 2) go to 43 do i = 2, mm1 im1 = i - 1 ip1 = i + 1 npi = n + i del2 = x(ip1) - x(i) if (del2 <= 0.) go to 47 deli = 1./del2 do j = 1, n zp(ip1, j, 2) = deli * (z(ip1, j) - z(i, j)) zp(ip1, j, 3) = deli * (zp(ip1, j, 1) - zp(i, j, 1)) end do call fitp_terms(diag2, sdiag2, sigmax, del2) diagin = 1./(diag1 + diag2 - sdiag1 * temp(npi - 1)) do j = 1, n zp(i, j, 2) = diagin * (zp(ip1, j, 2) - zp(i, j, 2) - sdiag1 * zp(im1, j, 2)) zp(i, j, 3) = diagin * (zp(ip1, j, 3) - zp(i, j, 3) - sdiag1 * zp(im1, j, 3)) end do temp(npi) = diagin * sdiag2 diag1 = diag2 sdiag1 = sdiag2 end do 43 diagin = 1./(diag1 - sdiag1 * temp(npm - 1)) do j = 1, n npmpj = npm + j zp(m, j, 2) = diagin * (temp(npmpj) - zp(m, j, 2) - sdiag1 * zp(mm1, j, 2)) zp(m, j, 3) = diagin * (temp(j) - zp(m, j, 3) - sdiag1 * zp(mm1, j, 3)) end do ! ! perform back substitution ! do i = 2, m ibak = mp1 - i ibakp1 = ibak + 1 npibak = n + ibak t = temp(npibak) do j = 1, n zp(ibak, j, 2) = zp(ibak, j, 2) - t * zp(ibakp1, j, 2) zp(ibak, j, 3) = zp(ibak, j, 3) - t * zp(ibakp1, j, 3) end do end do return ! ! too few points ! 46 ierr = 1 return ! ! points not strictly increasing ! 47 ierr = 2 return end subroutine fitp_surf1 real function fitp_surf2(xx, yy, m, n, x, y, z, iz, zp, sigma) integer m, n, iz real xx, yy, x(m), y(n), z(iz, n), zp(m, n, 3), sigma ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function interpolates a surface at a given coordinate ! pair using a bi-spline under tension. the subroutine surf1 ! should be called earlier to determine certain necessary ! parameters. ! ! on input-- ! ! xx and yy contain the x- and y-coordinates of the point ! to be mapped onto the interpolating surface. ! ! m and n contain the number of grid lines in the x- and ! y-directions, respectively, of the rectangular grid ! which specified the surface. ! ! x and y are arrays containing the x- and y-grid values, ! respectively, each in increasing order. ! ! z is a matrix containing the m * n functional values ! corresponding to the grid values (i. e. z(i,j) is the ! surface value at the point (x(i),y(j)) for i = 1,...,m ! and j = 1,...,n). ! ! iz contains the row dimension of the array z as declared ! in the calling program. ! ! zp is an array of 3*m*n locations stored with the ! various surface derivative information determined by ! surf1. ! ! and ! ! sigma contains the tension factor (its sign is ignored). ! ! the parameters m, n, x, y, z, iz, zp, and sigma should be ! input unaltered from the output of surf1. ! ! on output-- ! ! surf2 contains the interpolated surface value. ! ! none of the input parameters are altered. ! ! this function references package modules intrvl and ! snhcsh. ! !----------------------------------------------------------- integer im1, i, j, jm1 real hermz, hermnz, zxxi, dummy, zxxim1, zim1, zi real sigmax, fp2, del1, fp1, f1, f2, del2 real sinhms, sinhm2, sinhm1, dels, sigmay, sigmap ! ! inline one dimensional cubic spline interpolation ! hermz(f1, f2, fp1, fp2) = (f2 * del1 + f1 * del2) / dels - del1 * & del2 * (fp2 * (del1 + dels) + & fp1 * (del2 + dels)) / (6.*dels) ! ! inline one dimensional spline under tension interpolation ! hermnz(f1, f2, fp1, fp2, sigmap) = (f2 * del1 + f1 * del2) / dels & + (fp2 * del1 * (sinhm1 - sinhms) & + fp1 * del2 * (sinhm2 - sinhms) & ) / (sigmap * sigmap * dels * (1.+sinhms)) ! ! denormalize tension factor in x and y direction ! sigmax = abs(sigma) * real(m - 1) / (x(m) - x(1)) sigmay = abs(sigma) * real(n - 1) / (y(n) - y(1)) ! ! determine y interval ! jm1 = fitp_intrvl(yy, y, n) j = jm1 + 1 ! ! determine x interval ! im1 = fitp_intrvl(xx, x, m) i = im1 + 1 del1 = yy - y(jm1) del2 = y(j) - yy dels = y(j) - y(jm1) if (sigmay /= 0.) go to 1 ! ! perform four interpolations in y-direction ! zim1 = hermz(z(i - 1, j - 1), z(i - 1, j), zp(i - 1, j - 1, 1), zp(i - 1, j, 1)) zi = hermz(z(i, j - 1), z(i, j), zp(i, j - 1, 1), zp(i, j, 1)) zxxim1 = hermz(zp(i - 1, j - 1, 2), zp(i - 1, j, 2), zp(i - 1, j - 1, 3), zp(i - 1, j, 3)) zxxi = hermz(zp(i, j - 1, 2), zp(i, j, 2), zp(i, j - 1, 3), zp(i, j, 3)) go to 2 1 call fitp_snhcsh(sinhm1, dummy, sigmay * del1, -1) call fitp_snhcsh(sinhm2, dummy, sigmay * del2, -1) call fitp_snhcsh(sinhms, dummy, sigmay * dels, -1) zim1 = hermnz(z(i - 1, j - 1), z(i - 1, j), zp(i - 1, j - 1, 1), zp(i - 1, j, 1), sigmay) zi = hermnz(z(i, j - 1), z(i, j), zp(i, j - 1, 1), zp(i, j, 1), sigmay) zxxim1 = hermnz(zp(i - 1, j - 1, 2), zp(i - 1, j, 2), zp(i - 1, j - 1, 3), zp(i - 1, j, 3), sigmay) zxxi = hermnz(zp(i, j - 1, 2), zp(i, j, 2), zp(i, j - 1, 3), zp(i, j, 3), sigmay) ! ! perform final interpolation in x-direction ! 2 del1 = xx - x(im1) del2 = x(i) - xx dels = x(i) - x(im1) if (sigmax /= 0.) go to 3 fitp_surf2 = hermz(zim1, zi, zxxim1, zxxi) return 3 call fitp_snhcsh(sinhm1, dummy, sigmax * del1, -1) call fitp_snhcsh(sinhm2, dummy, sigmax * del2, -1) call fitp_snhcsh(sinhms, dummy, sigmax * dels, -1) fitp_surf2 = hermnz(zim1, zi, zxxim1, zxxi, sigmax) return end function fitp_surf2 subroutine fitp_ceez(del1, del2, sigma, c1, c2, c3, n) real del1, del2, sigma, c1, c2, c3 ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the coefficients c1, c2, and c3 ! used to determine endpoint slopes. specifically, if ! function values y1, y2, and y3 are given at points x1, x2, ! and x3, respectively, the quantity c1*y1 + c2*y2 + c3*y3 ! is the value of the derivative at x1 of a spline under ! tension (with tension factor sigma) passing through the ! three points and having third derivative equal to zero at ! x1. optionally, only two values, c1 and c2 are determined. ! ! on input-- ! ! del1 is x2-x1 (.gt. 0.). ! ! del2 is x3-x1 (.gt. 0.). if n .eq. 2, this parameter is ! ignored. ! ! sigma is the tension factor. ! ! and ! ! n is a switch indicating the number of coefficients to ! be returned. if n .eq. 2 only two coefficients are ! returned. otherwise all three are returned. ! ! on output-- ! ! c1, c2, and c3 contain the coefficients. ! ! none of the input parameters are altered. ! ! this subroutine references package module snhcsh. ! !----------------------------------------------------------- integer n real delm, delp, sinhmp, denom, sinhmm, del, dummy, coshm2, coshm1 if (n == 2) go to 2 if (sigma /= 0.) go to 1 del = del2 - del1 ! ! tension .eq. 0. ! c1 = -(del1 + del2) / (del1 * del2) c2 = del2 / (del1 * del) c3 = -del1 / (del2 * del) return ! ! tension .ne. 0. ! 1 call fitp_snhcsh(dummy, coshm1, sigma * del1, 1) call fitp_snhcsh(dummy, coshm2, sigma * del2, 1) delp = sigma * (del2 + del1) / 2. delm = sigma * (del2 - del1) / 2. call fitp_snhcsh(sinhmp, dummy, delp, -1) call fitp_snhcsh(sinhmm, dummy, delm, -1) denom = coshm1 * (del2 - del1) - 2.*del1 * delp * delm * (1.+sinhmp) * (1.+sinhmm) c1 = 2.*delp * delm * (1.+sinhmp) * (1.+sinhmm) / denom c2 = -coshm2 / denom c3 = coshm1 / denom return ! ! two coefficients ! 2 c1 = -1./del1 c2 = -c1 return end subroutine fitp_ceez subroutine fitp_curvpp(n, x, y, p, d, isw, s, eps, ys, ysp, sigma, & td, tsd1, hd, hsd1, hsd2, rd, rsd1, rsd2, rnm1, rn, v, ierr) integer n, isw, ierr real x(n), y(n), p, d(n), s, eps, ys(n), ysp(n), sigma, td(n), & tsd1(n), hd(n), hsd1(n), hsd2(n), rd(n), rsd1(n), & rsd2(n), rnm1(n), rn(n), v(n) ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute a periodic smoothing spline under tension. for a ! given increasing sequence of abscissae (x(i)), i = 1,...,n ! and associated ordinates (y(i)), i = 1,...,n, letting p be ! the period, x(n+1) = x(1)+p, and y(n+1) = y(1), the ! function determined minimizes the summation from i = 1 to ! n of the square of the second derivative of f plus sigma ! squared times the difference of the first derivative of f ! and (f(x(i+1))-f(x(i)))/(x(i+1)-x(i)) squared, over all ! functions f with period p and two continuous derivatives ! such that the summation of the square of ! (f(x(i))-y(i))/d(i) is less than or equal to a given ! constant s, where (d(i)), i = 1,...,n are a given set of ! observation weights. the function determined is a periodic ! spline under tension with third derivative discontinuities ! at (x(i)) i = 1,...,n (and all periodic translations of ! these values). for actual computation of points on the ! curve it is necessary to call the function curvp2. ! ! on input-- ! ! n is the number of values to be smoothed (n.ge.2). ! ! x is an array of the n increasing abscissae of the ! values to be smoothed. ! ! y is an array of the n ordinates of the values to be ! smoothed, (i. e. y(k) is the functional value ! corresponding to x(k) ). ! ! p is the period (p .gt. x(n)-x(1)). ! ! d is a parameter containing the observation weights. ! this may either be an array of length n or a scalar ! (interpreted as a constant). the value of d ! corresponding to the observation (x(k),y(k)) should ! be an approximation to the standard deviation of error. ! ! isw contains a switch indicating whether the parameter ! d is to be considered a vector or a scalar, ! = 0 if d is an array of length n, ! = 1 if d is a scalar. ! ! s contains the value controlling the smoothing. this ! must be non-negative. for s equal to zero, the ! subroutine does interpolation, larger values lead to ! smoother funtions. if parameter d contains standard ! deviation estimates, a reasonable value for s is ! float(n). ! ! eps contains a tolerance on the relative precision to ! which s is to be interpreted. this must be greater than ! or equal to zero and less than equal or equal to one. a ! reasonable value for eps is sqrt(2./float(n)). ! ! ys is an array of length at least n. ! ! ysp is an array of length at least n. ! ! sigma contains the tension factor. this value indicates ! the degree to which the first derivative part of the ! smoothing functional is emphasized. if sigma is nearly ! zero (e. g. .001) the resulting curve is approximately a ! cubic spline. if sigma is large (e. g. 50.) the ! resulting curve is nearly a polygonal line. if sigma ! equals zero a cubic spline results. a standard value for ! sigma is approximately 1. ! ! and ! ! td, tsd1, hd, hsd1, hsd2, rd, rsd1, rsd2, rnm1, rn, and ! v are arrays of length at least n which are used for ! scratch storage. ! ! on output-- ! ! ys contains the smoothed ordinate values. ! ! ysp contains the values of the second derivative of the ! smoothed curve at the given nodes. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2, ! = 2 if s is negative, ! = 3 if eps is negative or greater than one, ! = 4 if x-values are not strictly increasing, ! = 5 if a d-value is non-positive, ! = 6 if p is less than or equal to x(n)-x(1). ! ! and ! ! n, x, y, d, isw, s, eps, and sigma are unaltered. ! ! this subroutine references package modules terms and ! snhcsh. ! !----------------------------------------------------------- real f, g, rnm1sm integer ibak real rnm1t, rnt, rdn, wi, h, step, tui, rnsm real wim1, wim2, hsd1p, hdim1, hdi, sum, hsd11 real sl, con, sum2, sumn, rsd2i, sumnm1, yspnm1, yspn, rsd1i integer ip1, i real dim1, di, delyi, delxi, delyi1 real sigmap, q, delxi1 integer nm3, nm2, nm1 real disq, sumy, sumd, beta, hsd1ip, alpha integer im1 real su, alphap, betap, betapp if (n < 2) go to 25 if (s < 0.) go to 26 if (eps < 0. .or. eps > 1.) go to 27 if (p <= x(n) - x(1)) go to 30 ierr = 0 q = 0. rsd1(1) = 0. rsd2(1) = 0. rsd2(2) = 0. rsd1(n - 1) = 0. rsd2(n - 1) = 0. rsd2(n) = 0. ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n) / p ! ! form t matrix and second differences of y into ys ! nm1 = n - 1 nm2 = n - 2 nm3 = n - 3 delxi1 = x(1) + p - x(n) delyi1 = (y(1) - y(n)) / delxi1 call fitp_terms(dim1, tsd1(1), sigmap, delxi1) hsd1(1) = 1./delxi1 do i = 1, n ip1 = i + 1 if (i == n) ip1 = 1 delxi = x(ip1) - x(i) if (i == n) delxi = x(1) + p - x(n) if (delxi <= 0.) go to 28 delyi = (y(ip1) - y(i)) / delxi ys(i) = delyi - delyi1 call fitp_terms(di, tsd1(ip1), sigmap, delxi) td(i) = di + dim1 hd(i) = -(1./delxi + 1./delxi1) hsd1(ip1) = 1./delxi delxi1 = delxi delyi1 = delyi dim1 = di end do hsd11 = hsd1(1) if (n >= 3) go to 2 tsd1(2) = tsd1(1) + tsd1(2) tsd1(1) = 0. hsd1(2) = hsd1(1) + hsd1(2) hsd1(1) = 0. ! ! calculate lower and upper tolerances ! 2 sl = s * (1.-eps) su = s * (1.+eps) if (d(1) <= 0.) go to 29 if (isw == 1) go to 5 ! ! form h matrix - d array ! betapp = hsd1(n) * d(n) * d(n) betap = hsd1(1) * d(1) * d(1) alphap = hd(n) * d(n) * d(n) im1 = n sumd = 0. sumy = 0. do i = 1, n disq = d(i) * d(i) sumd = sumd + 1./disq sumy = sumy + y(i) / disq ip1 = i + 1 if (i == n) ip1 = 1 alpha = hd(i) * disq if (d(ip1) <= 0.) go to 29 hsd1ip = hsd1(ip1) if (i == n) hsd1ip = hsd11 beta = hsd1ip * d(ip1) * d(ip1) hd(i) = (hsd1(i) * d(im1))**2 + alpha * hd(i) + beta * hsd1ip hsd2(i) = hsd1(i) * betapp hsd1(i) = hsd1(i) * (alpha + alphap) im1 = i alphap = alpha betapp = betap betap = beta end do if (n == 3) hsd1(3) = hsd1(3) + hsd2(2) ! ! test for straight line fit ! con = sumy / sumd sum = 0. do i = 1, n sum = sum + ((y(i) - con) / d(i))**2 end do if (sum <= su) go to 23 go to 8 ! ! form h matrix - d constant ! 5 sl = d(1) * d(1) * sl su = d(1) * d(1) * su hsd1p = hsd1(n) hdim1 = hd(n) sumy = 0. do i = 1, n sumy = sumy + y(i) hsd1ip = hsd11 if (i < n) hsd1ip = hsd1(i + 1) hdi = hd(i) hd(i) = hsd1(i) * hsd1(i) + hdi * hdi + hsd1ip * hsd1ip hsd2(i) = hsd1(i) * hsd1p hsd1p = hsd1(i) hsd1(i) = hsd1p * (hdi + hdim1) hdim1 = hdi end do if (n == 3) hsd1(3) = hsd1(3) + hsd2(2) ! ! test for straight line fit ! con = sumy / real(n) sum = 0. do i = 1, n sum = sum + (y(i) - con)**2 end do if (sum <= su) go to 23 ! ! top of iteration ! cholesky factorization of q*t+h into r ! ! ! i = 1 ! 8 rd(1) = 1./(q * td(1) + hd(1)) rnm1(1) = hsd2(1) yspnm1 = ys(nm1) rn(1) = q * tsd1(1) + hsd1(1) yspn = ys(n) ysp(1) = ys(1) rsd1i = q * tsd1(2) + hsd1(2) rsd1(2) = rsd1i * rd(1) sumnm1 = 0. sum2 = 0. sumn = 0. if (n == 3) go to 11 if (n == 2) go to 12 ! ! i = 2 ! rd(2) = 1./(q * td(2) + hd(2) - rsd1i * rsd1(2)) rnm1(2) = -rnm1(1) * rsd1(2) rn(2) = hsd2(2) - rn(1) * rsd1(2) ysp(2) = ys(2) - rsd1(2) * ysp(1) if (n == 4) go to 10 do i = 3, nm2 rsd2i = hsd2(i) rsd1i = q * tsd1(i) + hsd1(i) - rsd2i * rsd1(i - 1) rsd2(i) = rsd2i * rd(i - 2) rsd1(i) = rsd1i * rd(i - 1) rd(i) = 1./(q * td(i) + hd(i) - rsd1i * rsd1(i) - rsd2i * rsd2(i)) rnm1(i) = -rnm1(i - 2) * rsd2(i) - rnm1(i - 1) * rsd1(i) rnm1t = rnm1(i - 2) * rd(i - 2) sumnm1 = sumnm1 + rnm1t * rnm1(i - 2) rnm1(i - 2) = rnm1t sum2 = sum2 + rnm1t * rn(i - 2) yspnm1 = yspnm1 - rnm1t * ysp(i - 2) rn(i) = -rn(i - 2) * rsd2(i) - rn(i - 1) * rsd1(i) rnt = rn(i - 2) * rd(i - 2) sumn = sumn + rnt * rn(i - 2) rn(i - 2) = rnt yspn = yspn - rnt * ysp(i - 2) ysp(i) = ys(i) - rsd1(i) * ysp(i - 1) - rsd2(i) * ysp(i - 2) end do ! ! i = n-3 ! 10 rnm1(nm3) = hsd2(nm1) + rnm1(nm3) rnm1(nm2) = rnm1(nm2) - hsd2(nm1) * rsd1(nm2) rnm1t = rnm1(nm3) * rd(nm3) sumnm1 = sumnm1 + rnm1t * rnm1(nm3) rnm1(nm3) = rnm1t sum2 = sum2 + rnm1t * rn(nm3) yspnm1 = yspnm1 - rnm1t * ysp(nm3) rnt = rn(nm3) * rd(nm3) sumn = sumn + rnt * rn(nm3) rn(nm3) = rnt yspn = yspn - rnt * ysp(nm3) ! ! i = n-2 ! 11 rnm1(nm2) = q * tsd1(nm1) + hsd1(nm1) + rnm1(nm2) rnm1t = rnm1(nm2) * rd(nm2) sumnm1 = sumnm1 + rnm1t * rnm1(nm2) rnm1(nm2) = rnm1t rn(nm2) = hsd2(n) + rn(nm2) sum2 = sum2 + rnm1t * rn(nm2) yspnm1 = yspnm1 - rnm1t * ysp(nm2) rnt = rn(nm2) * rd(nm2) sumn = sumn + rnt * rn(nm2) rn(nm2) = rnt yspn = yspn - rnt * ysp(nm2) ! ! i = n-1 ! 12 rd(nm1) = 1./(q * td(nm1) + hd(nm1) - sumnm1) ysp(nm1) = yspnm1 rn(nm1) = q * tsd1(n) + hsd1(n) - sum2 rnt = rn(nm1) * rd(nm1) sumn = sumn + rnt * rn(nm1) rn(nm1) = rnt yspn = yspn - rnt * ysp(nm1) ! ! i = n ! rdn = q * td(n) + hd(n) - sumn rd(n) = 0. if (rdn > 0.) rd(n) = 1./rdn ysp(n) = yspn ! ! back solve of r(transpose)* r * ysp = ys ! ysp(n) = rd(n) * ysp(n) ysp(nm1) = rd(nm1) * ysp(nm1) - rn(nm1) * ysp(n) if (n == 2) go to 14 yspn = ysp(n) yspnm1 = ysp(nm1) do ibak = 1, nm2 i = nm1 - ibak ysp(i) = rd(i) * ysp(i) - rsd1(i + 1) * ysp(i + 1) - rsd2(i + 2) * ysp(i + 2) - rnm1(i) * yspnm1 - rn(i) * yspn end do 14 sum = 0. delyi1 = (ysp(1) - ysp(n)) / (x(1) + p - x(n)) if (isw == 1) go to 16 ! ! calculation of residual norm ! - d array ! do i = 1, nm1 delyi = (ysp(i + 1) - ysp(i)) / (x(i + 1) - x(i)) v(i) = (delyi - delyi1) * d(i) * d(i) sum = sum + v(i) * (delyi - delyi1) delyi1 = delyi end do delyi = (ysp(1) - ysp(n)) / (x(1) + p - x(n)) v(n) = (delyi - delyi1) * d(n) * d(n) go to 18 ! ! calculation of residual norm ! - d constant ! 16 do i = 1, nm1 delyi = (ysp(i + 1) - ysp(i)) / (x(i + 1) - x(i)) v(i) = delyi - delyi1 sum = sum + v(i) * (delyi - delyi1) delyi1 = delyi end do delyi = (ysp(1) - ysp(n)) / (x(1) + p - x(n)) v(n) = delyi - delyi1 18 sum = sum + v(n) * (delyi - delyi1) ! ! test for convergence ! if (sum <= su .and. sum >= sl .and. q > 0.) go to 21 ! ! calculation of newton correction ! f = 0. g = 0. rnm1sm = 0. rnsm = 0. im1 = n if (n == 2) go to 20 wim2 = 0. wim1 = 0. do i = 1, nm2 tui = tsd1(i) * ysp(im1) + td(i) * ysp(i) + tsd1(i + 1) * ysp(i + 1) wi = tui - rsd1(i) * wim1 - rsd2(i) * wim2 rnm1sm = rnm1sm - rnm1(i) * wi rnsm = rnsm - rn(i) * wi f = f + tui * ysp(i) g = g + wi * wi * rd(i) im1 = i wim2 = wim1 wim1 = wi end do 20 tui = tsd1(nm1) * ysp(im1) + td(nm1) * ysp(nm1) + tsd1(n) * ysp(n) wi = tui + rnm1sm f = f + tui * ysp(nm1) g = g + wi * wi * rd(nm1) tui = tsd1(n) * ysp(nm1) + td(n) * ysp(n) + tsd1(1) * ysp(1) wi = tui + rnsm - rn(nm1) * wi f = f + tui * ysp(n) g = g + wi * wi * rd(n) h = f - q * g if (h <= 0. .and. q > 0.) go to 21 ! ! update q - newton step ! step = (sum - sqrt(sum * sl)) / h if (sl /= 0.) step = step * sqrt(sum / sl) q = q + step go to 8 ! ! store smoothed y-values and second derivatives ! 21 do i = 1, n ys(i) = y(i) - v(i) ysp(i) = q * ysp(i) end do return ! ! store constant ys and zero ysp ! 23 do i = 1, n ys(i) = con ysp(i) = 0. end do return ! ! n less than 2 ! 25 ierr = 1 return ! ! s negative ! 26 ierr = 2 return ! ! eps negative or greater than 1 ! 27 ierr = 3 return ! ! x-values not strictly increasing ! 28 ierr = 4 return ! ! weight non-positive ! 29 ierr = 5 return ! ! incorrect period ! 30 ierr = 6 return end subroutine fitp_curvpp subroutine fitp_curvss(n, x, y, d, isw, s, eps, ys, ysp, sigma, td, & tsd1, hd, hsd1, hsd2, rd, rsd1, rsd2, v, ierr) integer n, isw, ierr real x(n), y(n), d(n), s, eps, ys(n), ysp(n), sigma, td(n), & tsd1(n), hd(n), hsd1(n), hsd2(n), rd(n), rsd1(n), rsd2(n), v(n) ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine determines the parameters necessary to ! compute a smoothing spline under tension. for a given ! increasing sequence of abscissae (x(i)), i = 1,..., n and ! associated ordinates (y(i)), i = 1,..., n, the function ! determined minimizes the summation from i = 1 to n-1 of ! the square of the second derivative of f plus sigma ! squared times the difference of the first derivative of f ! and (f(x(i+1))-f(x(i)))/(x(i+1)-x(i)) squared, over all ! functions f with two continuous derivatives such that the ! summation of the square of (f(x(i))-y(i))/d(i) is less ! than or equal to a given constant s, where (d(i)), i = 1, ! ..., n are a given set of observation weights. the ! function determined is a spline under tension with third ! derivative discontinuities at (x(i)), i = 2,..., n-1. for ! actual computation of points on the curve it is necessary ! to call the function curv2. ! ! on input-- ! ! n is the number of values to be smoothed (n.ge.2). ! ! x is an array of the n increasing abscissae of the ! values to be smoothed. ! ! y is an array of the n ordinates of the values to be ! smoothed, (i. e. y(k) is the functional value ! corresponding to x(k) ). ! ! d is a parameter containing the observation weights. ! this may either be an array of length n or a scalar ! (interpreted as a constant). the value of d ! corresponding to the observation (x(k),y(k)) should ! be an approximation to the standard deviation of error. ! ! isw contains a switch indicating whether the parameter ! d is to be considered a vector or a scalar, ! = 0 if d is an array of length n, ! = 1 if d is a scalar. ! ! s contains the value controlling the smoothing. this ! must be non-negative. for s equal to zero, the ! subroutine does interpolation, larger values lead to ! smoother funtions. if parameter d contains standard ! deviation estimates, a reasonable value for s is ! float(n). ! ! eps contains a tolerance on the relative precision to ! which s is to be interpreted. this must be greater than ! or equal to zero and less than equal or equal to one. a ! reasonable value for eps is sqrt(2./float(n)). ! ! ys is an array of length at least n. ! ! ysp is an array of length at least n. ! ! sigma contains the tension factor. this value indicates ! the degree to which the first derivative part of the ! smoothing functional is emphasized. if sigma is nearly ! zero (e. g. .001) the resulting curve is approximately a ! cubic spline. if sigma is large (e. g. 50.) the ! resulting curve is nearly a polygonal line. if sigma ! equals zero a cubic spline results. a standard value for ! sigma is approximately 1. ! ! and ! ! td, tsd1, hd, hsd1, hsd2, rd, rsd1, rsd2, and v are ! arrays of length at least n which are used for scratch ! storage. ! ! on output-- ! ! ys contains the smoothed ordinate values. ! ! ysp contains the values of the second derivative of the ! smoothed curve at the given nodes. ! ! ierr contains an error flag, ! = 0 for normal return, ! = 1 if n is less than 2, ! = 2 if s is negative, ! = 3 if eps is negative or greater than one, ! = 4 if x-values are not strictly increasing, ! = 5 if a d-value is non-positive. ! ! and ! ! n, x, y, d, isw, s, eps, and sigma are unaltered. ! ! this subroutine references package modules terms and ! snhcsh. ! !----------------------------------------------------------- integer ibak real rsd1i, rsd2i, sum, hdi, beta, alpha, hdim1, hsd1p real wi, tui, step, h, g, f, wim1, wim2, alphap integer nm1, nm3 real delyi1, delxi1, rdim1, p, sigmap, yspim2 real dim1, su, sl, betap, betapp, delxi integer i real di, delyi if (n < 2) go to 16 if (s < 0.) go to 17 if (eps < 0. .or. eps > 1.) go to 18 ierr = 0 p = 0. v(1) = 0. v(n) = 0. ysp(1) = 0. ysp(n) = 0. if (n == 2) go to 14 rsd1(1) = 0. rd(1) = 0. rsd2(n) = 0. rdim1 = 0. yspim2 = 0. ! ! denormalize tension factor ! sigmap = abs(sigma) * real(n - 1) / (x(n) - x(1)) ! ! form t matrix and second differences of y into ys ! nm1 = n - 1 nm3 = n - 3 delxi1 = 1. delyi1 = 0. dim1 = 0. do i = 1, nm1 delxi = x(i + 1) - x(i) if (delxi <= 0.) go to 19 delyi = (y(i + 1) - y(i)) / delxi ys(i) = delyi - delyi1 call fitp_terms(di, tsd1(i + 1), sigmap, delxi) td(i) = di + dim1 hd(i) = -(1./delxi + 1./delxi1) hsd1(i + 1) = 1./delxi delxi1 = delxi delyi1 = delyi dim1 = di end do ! ! calculate lower and upper tolerances ! sl = s * (1.-eps) su = s * (1.+eps) if (isw == 1) go to 3 ! ! form h matrix - d array ! if (d(1) <= 0. .or. d(2) <= 0.) go to 20 betapp = 0. betap = 0. alphap = 0. do i = 2, nm1 alpha = hd(i) * d(i) * d(i) if (d(i + 1) <= 0.) go to 20 beta = hsd1(i + 1) * d(i + 1) * d(i + 1) hd(i) = (hsd1(i) * d(i - 1))**2 + alpha * hd(i) + beta * hsd1(i + 1) hsd2(i) = hsd1(i) * betapp hsd1(i) = hsd1(i) * (alpha + alphap) alphap = alpha betapp = betap betap = beta end do go to 5 ! ! form h matrix - d constant ! 3 if (d(1) <= 0.) go to 20 sl = d(1) * d(1) * sl su = d(1) * d(1) * su hsd1p = 0. hdim1 = 0. do i = 2, nm1 hdi = hd(i) hd(i) = hsd1(i) * hsd1(i) + hdi * hdi + hsd1(i + 1) * hsd1(i + 1) hsd2(i) = hsd1(i) * hsd1p hsd1p = hsd1(i) hsd1(i) = hsd1p * (hdi + hdim1) hdim1 = hdi end do ! ! top of iteration ! cholesky factorization of p*t+h into r ! 5 do i = 2, nm1 rsd2i = hsd2(i) rsd1i = p * tsd1(i) + hsd1(i) - rsd2i * rsd1(i - 1) rsd2(i) = rsd2i * rdim1 rdim1 = rd(i - 1) rsd1(i) = rsd1i * rdim1 rd(i) = 1./(p * td(i) + hd(i) - rsd1i * rsd1(i) - rsd2i * rsd2(i)) ysp(i) = ys(i) - rsd1(i) * ysp(i - 1) - rsd2(i) * yspim2 yspim2 = ysp(i - 1) end do ! ! back solve of r(transpose)* r * ysp = ys ! ysp(nm1) = rd(nm1) * ysp(nm1) if (n == 3) go to 8 do ibak = 1, nm3 i = nm1 - ibak ysp(i) = rd(i) * ysp(i) - rsd1(i + 1) * ysp(i + 1) - rsd2(i + 2) * ysp(i + 2) end do 8 sum = 0. delyi1 = 0. if (isw == 1) go to 10 ! ! calculation of residual norm ! - d array ! do i = 1, nm1 delyi = (ysp(i + 1) - ysp(i)) / (x(i + 1) - x(i)) v(i) = (delyi - delyi1) * d(i) * d(i) sum = sum + v(i) * (delyi - delyi1) delyi1 = delyi end do v(n) = -delyi1 * d(n) * d(n) go to 12 ! ! calculation of residual norm ! - d constant ! 10 do i = 1, nm1 delyi = (ysp(i + 1) - ysp(i)) / (x(i + 1) - x(i)) v(i) = delyi - delyi1 sum = sum + v(i) * (delyi - delyi1) delyi1 = delyi end do v(n) = -delyi1 12 sum = sum - v(n) * delyi1 ! ! test for convergence ! if (sum <= su) go to 14 ! ! calculation of newton correction ! f = 0. g = 0. wim2 = 0. wim1 = 0. do i = 2, nm1 tui = tsd1(i) * ysp(i - 1) + td(i) * ysp(i) + tsd1(i + 1) * ysp(i + 1) wi = tui - rsd1(i) * wim1 - rsd2(i) * wim2 f = f + tui * ysp(i) g = g + wi * wi * rd(i) wim2 = wim1 wim1 = wi end do h = f - p * g if (h <= 0.) go to 14 ! ! update p - newton step ! step = (sum - sqrt(sum * sl)) / h if (sl /= 0.) step = step * sqrt(sum / sl) p = p + step go to 5 ! ! store smoothed y-values and second derivatives ! 14 do i = 1, n ys(i) = y(i) - v(i) ysp(i) = p * ysp(i) end do return ! ! n less than 2 ! 16 ierr = 1 return ! ! s negative ! 17 ierr = 2 return ! ! eps negative or greater than 1 ! 18 ierr = 3 return ! ! x-values not strictly increasing ! 19 ierr = 4 return ! ! weight non-positive ! 20 ierr = 5 return end subroutine fitp_curvss integer function fitp_intrvl(t, x, n) integer n real t, x(n) ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function determines the index of the interval ! (determined by a given increasing sequence) in which ! a given value lies. ! ! on input-- ! ! t is the given value. ! ! x is a vector of strictly increasing values. ! ! and ! ! n is the length of x (n .ge. 2). ! ! on output-- ! ! intrvl returns an integer i such that ! ! i = 1 if e t .lt. x(2) , ! i = n-1 if x(n-1) .le. t , ! otherwise x(i) .le. t .le. x(i+1), ! ! none of the input parameters are altered. ! !----------------------------------------------------------- integer il, ih, i real tt save i data i/1/ tt = t ! ! check for illegal i ! if (i >= n) i = n / 2 ! ! check old interval and extremes ! if (tt < x(i)) then if (tt <= x(2)) then i = 1 fitp_intrvl = 1 return else il = 2 ih = i end if else if (tt <= x(i + 1)) then fitp_intrvl = i return else if (tt >= x(n - 1)) then i = n - 1 fitp_intrvl = n - 1 return else il = i + 1 ih = n - 1 end if ! ! binary search loop ! 1 i = (il + ih) / 2 if (tt < x(i)) then ih = i else if (tt > x(i + 1)) then il = i + 1 else fitp_intrvl = i return end if go to 1 end function fitp_intrvl integer function fitp_intrvp(t, x, n, p, tp) integer n real t, x(n), p, tp ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this function determines the index of the interval ! (determined by a given increasing sequence) in which a ! given value lies, after translating the value to within ! the correct period. it also returns this translated value. ! ! on input-- ! ! t is the given value. ! ! x is a vector of strictly increasing values. ! ! n is the length of x (n .ge. 2). ! ! and ! ! p contains the period. ! ! on output-- ! ! tp contains a translated value of t (i. e. x(1) .le. tp, ! tp .lt. x(1)+p, and tp = t + k*p for some integer k). ! ! intrvl returns an integer i such that ! ! i = 1 if tp .lt. x(2) , ! i = n if x(n) .le. tp , ! otherwise x(i) .le. tp .lt. x(i+1), ! ! none of the input parameters are altered. ! !----------------------------------------------------------- integer il, ih, i, nper real tt save i data i/1/ nper = int((t - x(1)) / p) tp = t - real(nper) * p if (tp < x(1)) tp = tp + p tt = tp ! ! check for illegal i ! if (i >= n) i = n / 2 ! ! check old interval and extremes ! if (tt < x(i)) then if (tt <= x(2)) then i = 1 fitp_intrvp = 1 return else il = 2 ih = i end if else if (tt <= x(i + 1)) then fitp_intrvp = i return else if (tt >= x(n)) then i = n fitp_intrvp = n return else il = i + 1 ih = n end if ! ! binary search loop ! 1 i = (il + ih) / 2 if (tt < x(i)) then ih = i else if (tt > x(i + 1)) then il = i + 1 else fitp_intrvp = i return end if go to 1 end function fitp_intrvp subroutine fitp_snhcsh(sinhm, coshm, x, isw) integer isw real sinhm, coshm, x ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine returns approximations to ! sinhm(x) = sinh(x)/x-1 ! coshm(x) = cosh(x)-1 ! and ! coshmm(x) = (cosh(x)-1-x*x/2)/(x*x) ! with relative error less than 1.0e-6 ! ! on input-- ! ! x contains the value of the independent variable. ! ! isw indicates the function desired ! = -1 if only sinhm is desired, ! = 0 if both sinhm and coshm are desired, ! = 1 if only coshm is desired, ! = 2 if only coshmm is desired, ! = 3 if both sinhm and coshmm are desired. ! ! on output-- ! ! sinhm contains the value of sinhm(x) if isw .le. 0 or ! isw .eq. 3 (sinhm is unaltered if isw .eq.1 or isw .eq. ! 2). ! ! coshm contains the value of coshm(x) if isw .eq. 0 or ! isw .eq. 1 and contains the value of coshmm(x) if isw ! .ge. 2 (coshm is unaltered if isw .eq. -1). ! ! and ! ! x and isw are unaltered. ! !----------------------------------------------------------- real sp10, sp11, sp12, sp13 real sp20, sp21, sp22, sp23, sp24 real sp31, sp32, sp33 real sq30, sq31, sq32 real sp41, sp42, sp43 real sq40, sq41, sq42 real cp0, cp1, cp2, cp3, cp4 real ax, xs, expx data sp13/.3029390e-5/, sp12/.1975135e-3/, sp11/.8334261e-2/, sp10/.1666665e0/ data sp24/.3693467e-7/, sp23/.2459974e-5/, sp22/.2018107e-3/, sp21/.8315072e-2/, sp20/.1667035e0/ data sp33/.6666558e-5/, sp32/.6646307e-3/, sp31/.4001477e-1/, sq32/.2037930e-3/, sq31/-.6372739e-1/, sq30/.6017497e1/ data sp43/.2311816e-4/, sp42/.2729702e-3/, sp41/.9868757e-1/, sq42/.1776637e-3/, sq41/-.7549779e-1/, sq40/.9110034e1/ data cp4/.2982628e-6/, cp3/.2472673e-4/, cp2/.1388967e-2/, cp1/.4166665e-1/, cp0/.5000000e0/ ax = abs(x) if (isw >= 0) go to 5 ! ! sinhm approximation ! if (ax > 4.45) go to 2 xs = ax * ax if (ax > 2.3) go to 1 ! ! sinhm approximation on (0.,2.3) ! sinhm = xs * (((sp13 * xs + sp12) * xs + sp11) * xs + sp10) return ! ! sinhm approximation on (2.3,4.45) ! 1 sinhm = xs * ((((sp24 * xs + sp23) * xs + sp22) * xs + sp21) * xs + sp20) return 2 if (ax > 7.65) go to 3 ! ! sinhm approximation on (4.45,7.65) ! xs = ax * ax sinhm = xs * (((sp33 * xs + sp32) * xs + sp31) * xs + 1.) / ((sq32 * xs + sq31) * xs + sq30) return 3 if (ax > 10.1) go to 4 ! ! sinhm approximation on (7.65,10.1) ! xs = ax * ax sinhm = xs * (((sp43 * xs + sp42) * xs + sp41) * xs + 1.) / ((sq42 * xs + sq41) * xs + sq40) return ! ! sinhm approximation above 10.1 ! 4 sinhm = exp(ax) / (ax + ax) - 1. return ! ! coshm and (possibly) sinhm approximation ! 5 if (isw >= 2) go to 7 if (ax > 2.3) go to 6 xs = ax * ax coshm = xs * ((((cp4 * xs + cp3) * xs + cp2) * xs + cp1) * xs + cp0) if (isw == 0) sinhm = xs * (((sp13 * xs + sp12) * xs + sp11) * xs + sp10) return 6 expx = exp(ax) coshm = (expx + 1./expx) / 2.-1. if (isw == 0) sinhm = (expx - 1./expx) / (ax + ax) - 1. return ! ! coshmm and (possibly) sinhm approximation ! 7 xs = ax * ax if (ax > 2.3) go to 8 coshm = xs * (((cp4 * xs + cp3) * xs + cp2) * xs + cp1) if (isw == 3) sinhm = xs * (((sp13 * xs + sp12) * xs + sp11) * xs + sp10) return 8 expx = exp(ax) coshm = ((expx + 1./expx - xs) / 2.-1.) / xs if (isw == 3) sinhm = (expx - 1./expx) / (ax + ax) - 1. return end subroutine fitp_snhcsh subroutine fitp_terms(diag, sdiag, sigma, del) ! real diag, sdiag, sigma, del ! ! coded by alan kaylor cline ! from fitpack -- january 26, 1987 ! a curve and surface fitting package ! a product of pleasant valley software ! 8603 altus cove, austin, texas 78759, usa ! ! this subroutine computes the diagonal and superdiagonal ! terms of the tridiagonal linear system associated with ! spline under tension interpolation. ! ! on input-- ! ! sigma contains the tension factor. ! ! and ! ! del contains the step size. ! ! on output-- ! ! sigma*del*cosh(sigma*del) - sinh(sigma*del) ! diag = del*--------------------------------------------. ! (sigma*del)**2 * sinh(sigma*del) ! ! sinh(sigma*del) - sigma*del ! sdiag = del*----------------------------------. ! (sigma*del)**2 * sinh(sigma*del) ! ! and ! ! sigma and del are unaltered. ! ! this subroutine references package module snhcsh. ! !----------------------------------------------------------- real coshm, denom, sigdel, sinhm if (sigma /= 0.) go to 1 diag = del / 3. sdiag = del / 6. return 1 sigdel = sigma * del call fitp_snhcsh(sinhm, coshm, sigdel, 0) denom = sigma * sigdel * (1.+sinhm) diag = (coshm - sinhm) / denom sdiag = sinhm / denom return end subroutine fitp_terms real function dedge(a, r, n, iside) integer n, iside real a(n), r(n) ! ! Not quite right for non-uniform r mesh ! if (iside == 1) then dedge = -(3.*a(1) - 4.*a(2) + a(3)) / (r(3) - r(1)) else dedge = (3.*a(iside) - 4.*a(iside - 1) + a(iside - 2)) / (r(iside) - r(iside - 2)) end if return end function dedge subroutine geo_spline_real(x, y, xint, yint) implicit none real, dimension(:), intent(in) :: x, y real, intent(in) :: xint real, intent(out) :: yint integer :: n, ierr real :: dum1, dum2, sigma real, dimension(:), allocatable :: ypp, dum3 n = size(x) allocate (ypp(n), dum3(n)) sigma = 1.0 call fitp_curv1(n, x, y, dum1, dum2, 3, ypp, dum3, sigma, ierr) yint = fitp_curv2(xint, n, x, y, ypp, sigma) deallocate (ypp, dum3) end subroutine geo_spline_real subroutine geo_spline_array(x, y, xint, yint) implicit none real, dimension(:), intent(in) :: x, y, xint real, dimension(:), intent(out) :: yint integer :: n, ierr, ix real :: dum1, dum2, sigma real, dimension(:), allocatable :: ypp, dum3 n = size(x) allocate (ypp(n), dum3(n)) sigma = 1.0 call fitp_curv1(n, x, y, dum1, dum2, 3, ypp, dum3, sigma, ierr) do ix = 1, size(xint) yint(ix) = fitp_curv2(xint(ix), n, x, y, ypp, sigma) end do deallocate (ypp, dum3) end subroutine geo_spline_array ! assumes that y is periodic in x ! if x has m entries, then assumes that y(m+1)=y(1) subroutine linear_interp_periodic(x, y, xint, yint, period) use constants, only: pi implicit none real, dimension(:), intent(in) :: x, y, xint real, intent(in), optional :: period real, dimension(:), intent(out) :: yint integer :: i, j, m, n logical :: not_finished real, dimension(:), allocatable :: xp, yp m = size(x) + 1 n = size(xint) allocate (xp(m), yp(m)) xp(:m - 1) = x if (present(period)) then xp(m) = x(1) + period else xp(m) = x(1) + 2.*pi end if yp(:m - 1) = y yp(m) = y(1) j = 1 do i = 1, n not_finished = .true. do while (not_finished) if (abs(xint(i) - xp(j)) < 100.*epsilon(0.)) then yint(i) = yp(j) not_finished = .false. else if (xint(i) > xp(j)) then j = j + 1 else yint(i) = (yp(j - 1) * (xp(j) - xint(i)) + yp(j) * (xint(i) - xp(j - 1))) / (xp(j) - xp(j - 1)) not_finished = .false. end if end do end do deallocate (xp, yp) end subroutine linear_interp_periodic end module splines
#include <ripple/basics/contract.h> #include <ripple/conditions/Condition.h> #include <ripple/conditions/Fulfillment.h> #include <ripple/conditions/impl/PreimageSha256.h> #include <ripple/conditions/impl/utils.h> #include <boost/regex.hpp> #include <boost/optional.hpp> #include <vector> #include <iostream> namespace ripple { namespace cryptoconditions { namespace detail { constexpr std::size_t fingerprintSize = 32; std::unique_ptr<Condition> loadSimpleSha256(Type type, Slice s, std::error_code& ec) { using namespace der; auto p = parsePreamble(s, ec); if (ec) return {}; if (!isPrimitive(p) || !isContextSpecific(p)) { ec = error::incorrect_encoding; return {}; } if (p.tag != 0) { ec = error::unexpected_tag; return {}; } if (p.length != fingerprintSize) { ec = error::fingerprint_size; return {}; } Buffer b = parseOctetString(s, p.length, ec); if (ec) return {}; p = parsePreamble(s, ec); if (ec) return {}; if (!isPrimitive(p) || !isContextSpecific(p)) { ec = error::malformed_encoding; return{}; } if (p.tag != 1) { ec = error::unexpected_tag; return {}; } auto cost = parseInteger<std::uint32_t>(s, p.length, ec); if (ec) return {}; if (!s.empty()) { ec = error::trailing_garbage; return {}; } switch (type) { case Type::preimageSha256: if (cost > PreimageSha256::maxPreimageLength) { ec = error::preimage_too_long; return {}; } break; default: break; } return std::make_unique<Condition>(type, cost, std::move(b)); } } std::unique_ptr<Condition> Condition::deserialize(Slice s, std::error_code& ec) { if (s.empty()) { ec = error::buffer_empty; return {}; } using namespace der; auto const p = parsePreamble(s, ec); if (ec) return {}; if (!isConstructed(p) || !isContextSpecific(p)) { ec = error::malformed_encoding; return {}; } if (p.length > s.size()) { ec = error::buffer_underfull; return {}; } if (s.size() > maxSerializedCondition) { ec = error::large_size; return {}; } std::unique_ptr<Condition> c; switch (p.tag) { case 0: c = detail::loadSimpleSha256( Type::preimageSha256, Slice(s.data(), p.length), ec); if (!ec) s += p.length; break; case 1: ec = error::unsupported_type; return {}; case 2: ec = error::unsupported_type; return {}; case 3: ec = error::unsupported_type; return {}; case 4: ec = error::unsupported_type; return {}; default: ec = error::unknown_type; return {}; } if (!s.empty()) { ec = error::trailing_garbage; return {}; } return c; } } }
[STATEMENT] lemma d_delta_lnexp_cf5: assumes "numer_cf5 x > 0" "numer_cf5 (-x) > 0" shows "((\<lambda>x. ln (exp_cf5 x) - x) has_field_derivative diff_delta_lnexp_cf5 x) (at x)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. ((\<lambda>x. ln (exp_cf5 x) - x) has_real_derivative diff_delta_lnexp_cf5 x) (at x) [PROOF STEP] unfolding exp_cf5_def numer_cf5_def diff_delta_lnexp_cf5_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. ((\<lambda>x. ln ((x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240) / ((- x) ^ 5 + 30 * (- x) ^ 4 + 420 * (- x) ^ 3 + 3360 * (- x)\<^sup>2 + 15120 * - x + 30240)) - x) has_real_derivative x ^ 10 / (((- x) ^ 5 + 30 * (- x) ^ 4 + 420 * (- x) ^ 3 + 3360 * (- x)\<^sup>2 + 15120 * - x + 30240) * (x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240))) (at x) [PROOF STEP] apply (intro derivative_eq_intros | simp)+ [PROOF STATE] proof (prove) goal (57 subgoals): 1. 0 < (x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240) / (30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240) 2. 1 = ?D117 3. real 5 * (?D117 * x ^ (5 - Suc 0)) = ?f'106 4. 0 = ?Da108 5. 1 = ?D110 6. real 4 * (?D110 * x ^ (4 - Suc 0)) = ?Db108 7. ?Da108 * x ^ 4 + ?Db108 * 30 = ?g'106 8. ?f'106 + ?g'106 = ?f'95 9. 0 = ?Da97 10. 1 = ?D99 A total of 57 subgoals... [PROOF STEP] using assms numer_cf5_pos [of x] numer_cf5_pos [of "-x"] [PROOF STATE] proof (prove) using this: 0 < numer_cf5 x 0 < numer_cf5 (- x) - (7293 / 10 ^ 3) \<le> x \<Longrightarrow> 0 < numer_cf5 x - (7293 / 10 ^ 3) \<le> - x \<Longrightarrow> 0 < numer_cf5 (- x) goal (57 subgoals): 1. 0 < (x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240) / (30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240) 2. 1 = ?D117 3. real 5 * (?D117 * x ^ (5 - Suc 0)) = ?f'106 4. 0 = ?Da108 5. 1 = ?D110 6. real 4 * (?D110 * x ^ (4 - Suc 0)) = ?Db108 7. ?Da108 * x ^ 4 + ?Db108 * 30 = ?g'106 8. ?f'106 + ?g'106 = ?f'95 9. 0 = ?Da97 10. 1 = ?D99 A total of 57 subgoals... [PROOF STEP] apply (auto simp: numer_cf5_def) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>0 < x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240; 0 < 30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240\<rbrakk> \<Longrightarrow> ((5 * x ^ 4 + 120 * x ^ 3 + 1260 * x\<^sup>2 + 6720 * x + 15120) * (30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240) - (x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240) * (120 * x ^ 3 - 5 * x ^ 4 - 1260 * x\<^sup>2 + 6720 * x - 15120)) / ((30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240) * (x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240)) - 1 = x ^ 10 / ((30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240) * (x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240)) [PROOF STEP] apply (auto simp add: divide_simps add_nonneg_eq_0_iff) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>0 < x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240; 0 < 30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240\<rbrakk> \<Longrightarrow> (5 * x ^ 4 + 120 * x ^ 3 + 1260 * x\<^sup>2 + 6720 * x + 15120) * (30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240) - (x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240) * (120 * x ^ 3 - 5 * x ^ 4 - 1260 * x\<^sup>2 + 6720 * x - 15120) - (30 * x ^ 4 - x ^ 5 - 420 * x ^ 3 + 3360 * x\<^sup>2 - 15120 * x + 30240) * (x ^ 5 + 30 * x ^ 4 + 420 * x ^ 3 + 3360 * x\<^sup>2 + 15120 * x + 30240) = x ^ 10 [PROOF STEP] apply algebra [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
Saprang was sidelined in security plans preceding the Constitutional Tribunal 's 20 May 2007 ruling on the dissolution of the Thai Rak Thai and Democrat Parties . After the 2006 coup , Sonthi had delegated the task of securing Bangkok to Saprang . The pre @-@ ruling plan put Sonthi directly in charge of Bangkok crowd security , allying him with alum of <unk> Class 9 , including Army Chief of Staff General <unk> <unk> and First Army Region commander Lt General <unk> Chan @-@ <unk> .
If $0 \leq x < 1$, then the sequence $x^n$ converges to $0$.
theory boolean_algebra_infinitary imports boolean_algebra_functional begin subsection \<open>Encoding infinitary Boolean operations\<close> (**Our aim is to encode complete Boolean algebras (of sets) which we can later be used to interpret quantified formulas (somewhat in the spirit of Boolean-valued models for set theory).*) (**We start by defining infinite meet (infimum) and infinite join (supremum) operations,*) definition infimum:: "('w \<sigma>)\<sigma> \<Rightarrow> 'w \<sigma>" ("\<^bold>\<And>_") where "\<^bold>\<And>S \<equiv> \<lambda>w. \<forall>X. S X \<longrightarrow> X w" definition supremum::"('w \<sigma>)\<sigma> \<Rightarrow> 'w \<sigma>" ("\<^bold>\<Or>_") where "\<^bold>\<Or>S \<equiv> \<lambda>w. \<exists>X. S X \<and> X w" (*add infimum and supremum to definition set of algebra connectives*) declare infimum_def[conn] supremum_def[conn] (**Infimum and supremum satisfy an infinite variant of the De Morgan laws*) lemma iDM_a: "\<^bold>\<midarrow>(\<^bold>\<And>S) \<approx> \<^bold>\<Or>(S\<^sup>-)" unfolding order conn conn2 by force lemma iDM_b:" \<^bold>\<midarrow>(\<^bold>\<Or>S) \<approx> \<^bold>\<And>(S\<^sup>-)" unfolding order conn conn2 by force (**We show that the our encoded Boolean algebras are lattice-complete.*) (**The functions below return the set of upper-/lower-bounds of a set of sets S (wrt. domain D)*) definition upper_bounds::"('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma>" ("ub") where "ub S \<equiv> \<lambda>U. \<forall>X. S X \<longrightarrow> X \<preceq> U" definition upper_bounds_restr::"('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma>" ("ub\<^sup>_") where "ub\<^sup>D S \<equiv> \<lambda>U. D U \<and> (\<forall>X. S X \<longrightarrow> X \<preceq> U)" definition lower_bounds::"('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma>" ("lb") where "lb S \<equiv> \<lambda>L. \<forall>X. S X \<longrightarrow> L \<preceq> X" definition lower_bounds_restr::"('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma>" ("lb\<^sup>_") where "lb\<^sup>D S \<equiv> \<lambda>L. D L \<and> (\<forall>X. S X \<longrightarrow> L \<preceq> X)" lemma ub_char: "ub S = (let D=\<^bold>\<top> in ub\<^sup>D S) " by (simp add: top_def upper_bounds_def upper_bounds_restr_def) lemma lb_char: "lb S = (let D=\<^bold>\<top> in lb\<^sup>D S) " by (simp add: top_def lower_bounds_def lower_bounds_restr_def) (**Similarly, the functions below return the set of least/greatest upper-/lower-bounds for S (wrt. D)*) definition lub::"('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma>" ("lub") where "lub S \<equiv> \<lambda>U. ub S U \<and> (\<forall>X. ub S X \<longrightarrow> U \<preceq> X)" definition lub_restr::"('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma>" ("lub\<^sup>_") where "lub\<^sup>D S \<equiv> \<lambda>U. ub\<^sup>D S U \<and> (\<forall>X. ub\<^sup>D S X \<longrightarrow> U \<preceq> X)" definition glb::"('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma>" ("glb") where "glb S \<equiv> \<lambda>L. lb S L \<and> (\<forall>X. lb S X \<longrightarrow> X \<preceq> L)" definition glb_restr::"('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma> \<Rightarrow> ('w \<sigma>)\<sigma>" ("glb\<^sup>_") where "glb\<^sup>D S \<equiv> \<lambda>L. lb\<^sup>D S L \<and> (\<forall>X. lb\<^sup>D S X \<longrightarrow> X \<preceq> L)" lemma lub_char: "lub S = (let D=\<^bold>\<top> in lub\<^sup>D S) " by (simp add: lub_def lub_restr_def ub_char) lemma glb_char: "glb S = (let D=\<^bold>\<top> in glb\<^sup>D S) " by (simp add: glb_def glb_restr_def lb_char) (**Note that the term \<^bold>\<top> below denotes the top element in the algebra of sets of sets (i.e. the powerset)*) lemma sup_lub: "lub S \<^bold>\<Or>S" unfolding lub_def upper_bounds_def supremum_def subset_def by blast lemma sup_exist_unique: "\<forall>S. \<exists>!X. lub S X" by (meson lub_def setequ_char setequ_ext sup_lub) lemma inf_glb: "glb S \<^bold>\<And>S" unfolding glb_def lower_bounds_def infimum_def subset_def by blast lemma inf_exist_unique: "\<forall>S. \<exists>!X. glb S X" by (meson glb_def inf_glb setequ_char setequ_ext) lemma inf_empty: "isEmpty S \<Longrightarrow> \<^bold>\<And>S \<approx> \<^bold>\<top>" unfolding order conn by simp lemma sup_empty: "isEmpty S \<Longrightarrow> \<^bold>\<Or>S \<approx> \<^bold>\<bottom>" unfolding order conn by simp (**The property of being closed under arbitrary (resp. nonempty) supremum/infimum.*) definition infimum_closed :: "('w \<sigma>)\<sigma> \<Rightarrow> bool" where "infimum_closed S \<equiv> \<forall>D. D \<preceq> S \<longrightarrow> S(\<^bold>\<And>D)" (*observe that D can be empty*) definition supremum_closed :: "('w \<sigma>)\<sigma> \<Rightarrow> bool" where "supremum_closed S \<equiv> \<forall>D. D \<preceq> S \<longrightarrow> S(\<^bold>\<Or>D)" (*observe that D can be empty*) definition infimum_closed' :: "('w \<sigma>)\<sigma> \<Rightarrow> bool" where"infimum_closed' S \<equiv> \<forall>D. nonEmpty D \<and> D \<preceq> S \<longrightarrow> S(\<^bold>\<And>D)" definition supremum_closed' :: "('w \<sigma>)\<sigma> \<Rightarrow> bool" where "supremum_closed' S \<equiv> \<forall>D. nonEmpty D \<and> D \<preceq> S \<longrightarrow> S(\<^bold>\<Or>D)" (**Note that arbitrary infimum- (resp. supremum-) closed sets include the top (resp. bottom) element.*) lemma "infimum_closed S \<Longrightarrow> S \<^bold>\<top>" unfolding infimum_closed_def conn order by force lemma "supremum_closed S \<Longrightarrow> S \<^bold>\<bottom>" unfolding supremum_closed_def conn order by force (**However, the above does not hold for non-empty infimum- (resp. supremum-) closed sets.*) lemma "infimum_closed' S \<Longrightarrow> S \<^bold>\<top>" nitpick oops lemma "supremum_closed' S \<Longrightarrow> S \<^bold>\<bottom>" nitpick oops (**We have in fact the following characterizations for the notions above:*) lemma inf_closed_char: "infimum_closed S = (infimum_closed' S \<and> S \<^bold>\<top>)" unfolding infimum_closed'_def infimum_closed_def by (metis bottom_def infimum_closed_def infimum_def setequ_char setequ_ext subset_def top_def) lemma sup_closed_char: "supremum_closed S = (supremum_closed' S \<and> S \<^bold>\<bottom>)" unfolding supremum_closed'_def supremum_closed_def by (metis (no_types, opaque_lifting) L14 L9 bottom_def setequ_ext subset_def supremum_def) lemma inf_sup_closed_dc: "infimum_closed S = supremum_closed S\<^sup>-" by (smt (verit) BA_dn iDM_a iDM_b infimum_closed_def setequ_ext sdfun_dcompl_def subset_def supremum_closed_def) lemma inf_sup_closed_dc': "infimum_closed' S = supremum_closed' S\<^sup>-" by (smt (verit) dualcompl_invol iDM_a infimum_closed'_def sdfun_dcompl_def setequ_ext subset_def supremum_closed'_def) (**We check some further properties:*) lemma fp_inf_sup_closed_dual: "infimum_closed (fp \<phi>) = supremum_closed (fp \<phi>\<^sup>d)" by (simp add: fp_dual inf_sup_closed_dc) lemma fp_inf_sup_closed_dual': "infimum_closed' (fp \<phi>) = supremum_closed' (fp \<phi>\<^sup>d)" by (simp add: fp_dual inf_sup_closed_dc') (**We verify that being infimum-closed' (resp. supremum-closed') entails being meet-closed (resp. join-closed).*) lemma inf_meet_closed: "\<forall>S. infimum_closed' S \<longrightarrow> meet_closed S" proof - { fix S::"'w \<sigma> \<Rightarrow> bool" { assume inf_closed: "infimum_closed' S" hence "meet_closed S" proof - { fix X::"'w \<sigma>" and Y::"'w \<sigma>" let ?D="\<lambda>Z. Z=X \<or> Z=Y" { assume "S X \<and> S Y" hence "?D \<preceq> S" using subset_def by blast moreover have "nonEmpty ?D" by auto ultimately have "S(\<^bold>\<And>?D)" using inf_closed infimum_closed'_def by (smt (z3)) hence "S(\<lambda>w. \<forall>Z. (Z=X \<or> Z=Y) \<longrightarrow> Z w)" unfolding infimum_def by simp moreover have "(\<lambda>w. \<forall>Z. (Z=X \<or> Z=Y) \<longrightarrow> Z w) = (\<lambda>w. X w \<and> Y w)" by auto ultimately have "S(\<lambda>w. X w \<and> Y w)" by simp } hence "(S X \<and> S Y) \<longrightarrow> S(X \<^bold>\<and> Y)" unfolding conn by (rule impI) } thus ?thesis unfolding meet_closed_def by simp qed } hence "infimum_closed' S \<longrightarrow> meet_closed S" by simp } thus ?thesis by (rule allI) qed lemma sup_join_closed: "\<forall>P. supremum_closed' P \<longrightarrow> join_closed P" proof - { fix S::"'w \<sigma> \<Rightarrow> bool" { assume sup_closed: "supremum_closed' S" hence "join_closed S" proof - { fix X::"'w \<sigma>" and Y::"'w \<sigma>" let ?D="\<lambda>Z. Z=X \<or> Z=Y" { assume "S X \<and> S Y" hence "?D \<preceq> S" using subset_def by blast moreover have "nonEmpty ?D" by auto ultimately have "S(\<^bold>\<Or>?D)" using sup_closed supremum_closed'_def by (smt (z3)) hence "S(\<lambda>w. \<exists>Z. (Z=X \<or> Z=Y) \<and> Z w)" unfolding supremum_def by simp moreover have "(\<lambda>w. \<exists>Z. (Z=X \<or> Z=Y) \<and> Z w) = (\<lambda>w. X w \<or> Y w)" by auto ultimately have "S(\<lambda>w. X w \<or> Y w)" by simp } hence "(S X \<and> S Y) \<longrightarrow> S(X \<^bold>\<or> Y)" unfolding conn by (rule impI) } thus ?thesis unfolding join_closed_def by simp qed } hence "supremum_closed' S \<longrightarrow> join_closed S" by simp } thus ?thesis by (rule allI) qed end
/* * Define digamma() and polygamma() here. * * We use the GSL special functions, GSL is available * on most platforms including MAC and Windows. * * Another option is the Cephes library with psi() and zeta() * http://www.netlib.org/cephes/ * which have nice, small self contained functions without all the * GSL cruft. */ #ifndef __DIGAMMA_H #define __DIGAMMA_H /* * Define this to switch off use of polygamma. * Polygamma (trigamma, etc.) is used in some * functions to speed things up. So disabling * it wont stop the functions working: * gammadiff(), psidiff(), S_approx() * But it also disables digammaInv() which * uses a Newton-Raphson step. */ #define LS_NOPOLYGAMMA /* * Leaving this undefined means we use the library functions grabbed * from the Mathlib and under GPL. This makes the code self * contained since no other libraries will be needed. * Define this if you have GSL available to use instead. * In which case, you will also need to modify the Makefile * to include GSL. */ // #define GSL_POLYGAMMA #ifdef LS_NOPOLYGAMMA /* * Radford Neal's implementation in digamma.c */ double digammaRN(double x); #define digamma(x) digammaRN(x) #else double digammaInv(double x); #ifndef GSL_POLYGAMMA /* * Mathlib implementation */ double MLpsigamma(double x, double deriv); double MLdigamma(double x); double MLtrigamma(double x); double MLtetragamma(double x); double MLpentagamma(double x); #define digamma(x) MLdigamma(x) #define trigamma(x) MLtrigamma(x) #define tetragamma(x) MLtetragamma(x) #define pentagamma(x) MLpentagamma(x) #else /* * GSL library */ #include <gsl/gsl_sf.h> #define digamma(x) gsl_sf_psi(x) #define trigamma(x) gsl_sf_psi_n(1,x) #define tetragamma(x) gsl_sf_psi_n(2,x) #define pentagamma(x) gsl_sf_psi_n(3,x) #endif #endif #endif
/* file includeDef.h list of headers and definitions used by the program OmegaMaxEnt (main source files: OmegaMaxEnt_main.cpp, OmegaMaxEnt_data.h, OmegaMaxEnt_data.cpp, graph_2D.h, graph_2D.cpp, generique.h, generique.cpp) Copyright (C) 2015 Dominic Bergeron ([email protected]) 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, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef INCLUDEDEF_H #define INCLUDEDEF_H #include "fftw3.h" #include <cmath> #include <iostream> #include <iomanip> #include <fstream> #include <cstdio> #include <complex> #include <string> #include <cstring> #include <ctime> #include <limits> #include <stdio.h> #include <sys/stat.h> #include <random> #include <gsl/gsl_linalg.h> #include "armadillo" #ifndef PI #define PI acos((double)-1.0) #endif #ifndef EPSILON #define EPSILON numeric_limits<double>::epsilon() #endif #ifndef DBL_MIN #define DBL_MIN numeric_limits<double>::min() #endif #ifndef DBL_MAX #define DBL_MAX numeric_limits<double>::max() #endif #ifndef INF #define INF numeric_limits<double>::infinity() #endif using namespace std; typedef complex<double> dcomplex; typedef unsigned int uint; #endif
// linux specific! #include <endian.h> #include <boost/filesystem.hpp> #include <opencv2/core/core.hpp> #include "dbglog/dbglog.hpp" #include "utility/streams.hpp" #include "utility/buildsys.hpp" #include "utility/binaryio.hpp" #include "service/cmdline.hpp" #include "math/geometry_core.hpp" namespace po = boost::program_options; namespace fs = boost::filesystem; namespace bin = utility::binaryio; namespace { class Asc2Gtx : public service::Cmdline { public: Asc2Gtx(const std::string &name, const std::string &version) : service::Cmdline(name, version) {} private: void configuration(po::options_description &cmdline , po::options_description &config , po::positional_options_description &pd) override; void configure(const po::variables_map &vars) override; int run(); fs::path input_; fs::path output_; float nodataIn_ = -88.8888f; float nodataOut_ = -88.8888f; }; void Asc2Gtx::configuration(po::options_description &cmdline , po::options_description &config , po::positional_options_description &pd) { cmdline.add_options() ("input", po::value(&input_)->required() , "Input ASC file.") ("output", po::value(&output_)->required() , "Output GTX file.") ("nodata.in", po::value(&nodataIn_)->default_value(nodataIn_) , "No data value in the input file.") ("nodata.out", po::value(&nodataOut_)->default_value(nodataOut_) , "No data value in the output file.") ; pd .add("input", 1) .add("output", 1) ; (void) config; } void Asc2Gtx::configure(const po::variables_map &vars) { (void) vars; } struct Header { math::Point2 ll; math::Size2f pixel; math::Size2 size; }; struct Grid { Header header; cv::Mat_<float> data; }; Grid loadAsc(std::istream &is) { Grid grid; auto &header(grid.header); auto &data(grid.data); { std::string h; std::getline(is, h); std::istringstream his(h); his.exceptions(std::ifstream::failbit); his >> header.ll(1) >> header.ll(0) >> header.pixel.height >> header.pixel.width >> header.size.height >> header.size.width ; }; grid.data.create(header.size.height, header.size.width); for (int j(0), je(data.rows); j != je; ++j) { for (int i(0), ie(data.cols); i != ie; ++i) { is >> data(j, i); } } return grid; } Grid loadAsc(const fs::path &path) { std::ifstream f; f.exceptions(std::ifstream::failbit | std::ifstream::badbit); Grid grid; try { f.open(path.string()); grid = loadAsc(f); } catch(const std::ios_base::failure &e) { LOGTHROW(err3, std::runtime_error) << "Cannot read ASC file " << path << ": " << e.what(); } f.close(); return grid; } namespace be { void writeImpl(std::ostream &os, const std::uint32_t &v) { const auto bev(::htobe32(v)); os.write(reinterpret_cast<const char*>(&bev), sizeof(bev)); } void writeImpl(std::ostream &os, const std::uint64_t &v) { const auto bev(::htobe64(v)); os.write(reinterpret_cast<const char*>(&bev), sizeof(bev)); } void writeImpl(std::ostream &os, const float &v) { writeImpl(os, reinterpret_cast<const std::uint32_t&>(v)); } void writeImpl(std::ostream &os, const double &v) { writeImpl(os, reinterpret_cast<const std::uint64_t&>(v)); } template <typename T> void write(std::ostream &os, const T &v) { writeImpl(os, v); } } // namespace be void saveGtx(std::ostream &os, const Grid &grid , float nodataIn, float nodataOut) { const auto &header(grid.header); be::write<double>(os, header.ll(1)); be::write<double>(os, header.ll(0)); be::write<double>(os, header.pixel.height); be::write<double>(os, header.pixel.width); be::write<std::uint32_t>(os, header.size.height); be::write<std::uint32_t>(os, header.size.width); for (const auto &value : grid.data) { if (value == nodataIn) { be::write<float>(os, nodataOut); } else { be::write<float>(os, value); } } } void saveGtx(const fs::path &path, const Grid &grid , float nodataIn, float nodataOut) { std::ofstream f; f.exceptions(std::ifstream::failbit | std::ifstream::badbit); try { f.open(path.string(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary); saveGtx(f, grid, nodataIn, nodataOut); } catch(const std::ios_base::failure &e) { LOGTHROW(err3, std::runtime_error) << "Cannot write GTX file " << path << ": " << e.what(); } f.close(); } int Asc2Gtx::run() { const auto grid(loadAsc(input_)); saveGtx(output_, grid, nodataIn_, nodataOut_); return EXIT_SUCCESS; } } // namespace int main(int argc, char *argv[]) { return Asc2Gtx(BUILD_TARGET_NAME, BUILD_TARGET_VERSION)(argc, argv); }
[GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b✝ c : α n : ℤ b : α ⊢ toIcoMod hp 0 b ∈ Set.Ico 0 p [PROOFSTEP] convert toIcoMod_mem_Ico hp 0 b [GOAL] case h.e'_5.h.e'_4 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b✝ c : α n : ℤ b : α ⊢ p = 0 + p [PROOFSTEP] exact (zero_add p).symm [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a b • p - b = -toIcoMod hp a b [PROOFSTEP] rw [toIcoMod, neg_sub] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a b • p - b = -toIocMod hp a b [PROOFSTEP] rw [toIocMod, neg_sub] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp a b - b = -toIcoDiv hp a b • p [PROOFSTEP] rw [toIcoMod, sub_sub_cancel_left, neg_smul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp a b - b = -toIocDiv hp a b • p [PROOFSTEP] rw [toIocMod, sub_sub_cancel_left, neg_smul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ b - toIcoMod hp a b = toIcoDiv hp a b • p [PROOFSTEP] rw [toIcoMod, sub_sub_cancel] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ b - toIocMod hp a b = toIocDiv hp a b • p [PROOFSTEP] rw [toIocMod, sub_sub_cancel] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp a b + toIcoDiv hp a b • p = b [PROOFSTEP] rw [toIcoMod, sub_add_cancel] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp a b + toIocDiv hp a b • p = b [PROOFSTEP] rw [toIocMod, sub_add_cancel] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a b • p + toIcoMod hp a b = b [PROOFSTEP] rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a b • p + toIocMod hp a b = b [PROOFSTEP] rw [add_comm, toIocMod_add_toIocDiv_zsmul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z, b = c + z • p [PROOFSTEP] refine' ⟨fun h => ⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, _⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ (c ∈ Set.Ico a (a + p) ∧ ∃ z, b = c + z • p) → toIcoMod hp a b = c [PROOFSTEP] simp_rw [← @sub_eq_iff_eq_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ (c ∈ Set.Ico a (a + p) ∧ ∃ z, b - z • p = c) → toIcoMod hp a b = c [PROOFSTEP] rintro ⟨hc, n, rfl⟩ [GOAL] case intro.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b : α n✝ n : ℤ hc : b - n • p ∈ Set.Ico a (a + p) ⊢ toIcoMod hp a b = b - n • p [PROOFSTEP] rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z, b = c + z • p [PROOFSTEP] refine' ⟨fun h => ⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, _⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ (c ∈ Set.Ioc a (a + p) ∧ ∃ z, b = c + z • p) → toIocMod hp a b = c [PROOFSTEP] simp_rw [← @sub_eq_iff_eq_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ (c ∈ Set.Ioc a (a + p) ∧ ∃ z, b - z • p = c) → toIocMod hp a b = c [PROOFSTEP] rintro ⟨hc, n, rfl⟩ [GOAL] case intro.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b : α n✝ n : ℤ hc : b - n • p ∈ Set.Ioc a (a + p) ⊢ toIocMod hp a b = b - n • p [PROOFSTEP] rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a - 0 • p ∈ Set.Ico a (a + p) [PROOFSTEP] simp [hp] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a - -1 • p ∈ Set.Ioc a (a + p) [PROOFSTEP] simp [hp] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ toIcoMod hp a a = a [PROOFSTEP] rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a < a + p ∧ ∃ z, a = a + z • p [PROOFSTEP] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a = a + 0 • p [PROOFSTEP] simp [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ toIocMod hp a a = a + p [PROOFSTEP] rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a < a + p ∧ ∃ z, a = a + p + z • p [PROOFSTEP] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a = a + p + -1 • p [PROOFSTEP] simp [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a + p - 1 • p ∈ Set.Ico a (a + p) [PROOFSTEP] simp [hp] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a + p - 0 • p ∈ Set.Ioc a (a + p) [PROOFSTEP] simp [hp] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ toIcoMod hp a (a + p) = a [PROOFSTEP] rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a < a + p ∧ ∃ z, a + p = a + z • p [PROOFSTEP] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a + p = a + 1 • p [PROOFSTEP] simp [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ toIocMod hp a (a + p) = a + p [PROOFSTEP] rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a < a + p ∧ ∃ z, a + p = a + p + z • p [PROOFSTEP] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a : α ⊢ a + p = a + p + 0 • p [PROOFSTEP] simp [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b + m • p - (toIcoDiv hp a b + m) • p ∈ Set.Ico a (a + p) [PROOFSTEP] simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m [PROOFSTEP] refine' toIcoDiv_eq_of_sub_zsmul_mem_Ico _ _ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b - (toIcoDiv hp a b - m) • p ∈ Set.Ico (a + m • p) (a + m • p + p) [PROOFSTEP] rw [sub_smul, ← sub_add, add_right_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b - toIcoDiv hp a b • p + m • p ∈ Set.Ico (a + m • p) (a + p + m • p) [PROOFSTEP] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b + m • p - (toIocDiv hp a b + m) • p ∈ Set.Ioc a (a + p) [PROOFSTEP] simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocDiv hp (a + m • p) b = toIocDiv hp a b - m [PROOFSTEP] refine' toIocDiv_eq_of_sub_zsmul_mem_Ioc _ _ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b - (toIocDiv hp a b - m) • p ∈ Set.Ioc (a + m • p) (a + m • p + p) [PROOFSTEP] rw [sub_smul, ← sub_add, add_right_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b - toIocDiv hp a b • p + m • p ∈ Set.Ioc (a + m • p) (a + p + m • p) [PROOFSTEP] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b [PROOFSTEP] rw [add_comm, toIcoDiv_add_zsmul, add_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocDiv hp a (m • p + b) = m + toIocDiv hp a b [PROOFSTEP] rw [add_comm, toIocDiv_add_zsmul, add_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m [PROOFSTEP] rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m [PROOFSTEP] rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocDiv hp a (b - m • p) = toIocDiv hp a b - m [PROOFSTEP] rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocDiv hp (a - m • p) b = toIocDiv hp a b + m [PROOFSTEP] rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 [PROOFSTEP] simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 [PROOFSTEP] simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a (b + p) = toIocDiv hp a b + 1 [PROOFSTEP] simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp (a + p) b = toIocDiv hp a b - 1 [PROOFSTEP] simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 [PROOFSTEP] rw [add_comm, toIcoDiv_add_right] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 [PROOFSTEP] rw [add_comm, toIcoDiv_add_right'] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a (p + b) = toIocDiv hp a b + 1 [PROOFSTEP] rw [add_comm, toIocDiv_add_right] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp (p + a) b = toIocDiv hp a b - 1 [PROOFSTEP] rw [add_comm, toIocDiv_add_right'] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 [PROOFSTEP] simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 [PROOFSTEP] simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a (b - p) = toIocDiv hp a b - 1 [PROOFSTEP] simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp (a - p) b = toIocDiv hp a b + 1 [PROOFSTEP] simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b [PROOFSTEP] apply toIcoDiv_eq_of_sub_zsmul_mem_Ico [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ b - c - toIcoDiv hp (a + c) b • p ∈ Set.Ico a (a + p) [PROOFSTEP] rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm] [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ b - toIcoDiv hp (a + c) b • p ∈ Set.Ico (a + c) (a + c + p) [PROOFSTEP] exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIocDiv hp a (b - c) = toIocDiv hp (a + c) b [PROOFSTEP] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ b - c - toIocDiv hp (a + c) b • p ∈ Set.Ioc a (a + p) [PROOFSTEP] rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm] [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ b - toIocDiv hp (a + c) b • p ∈ Set.Ioc (a + c) (a + c + p) [PROOFSTEP] exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) [PROOFSTEP] rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIocDiv hp (a - c) b = toIocDiv hp a (b + c) [PROOFSTEP] rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) [PROOFSTEP] suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α this : toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b ⊢ toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) [PROOFSTEP] rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b [PROOFSTEP] rw [← neg_eq_iff_eq_neg, eq_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp (-(a + p)) b = -toIcoDiv hp a (-b) [PROOFSTEP] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ b - -toIcoDiv hp a (-b) • p ∈ Set.Ioc (-(a + p)) (-(a + p) + p) [PROOFSTEP] obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b) [GOAL] case h.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α hc : a ≤ -b - toIcoDiv hp a (-b) • p ho : -b - toIcoDiv hp a (-b) • p < a + p ⊢ b - -toIcoDiv hp a (-b) • p ∈ Set.Ioc (-(a + p)) (-(a + p) + p) [PROOFSTEP] rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho [GOAL] case h.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α hc : a ≤ -b - toIcoDiv hp a (-b) • p ho✝ : -b - toIcoDiv hp a (-b) • p < a + p ho : -(a + p) < b - -toIcoDiv hp a (-b) • p ⊢ b - -toIcoDiv hp a (-b) • p ∈ Set.Ioc (-(a + p)) (-(a + p) + p) [PROOFSTEP] rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc [GOAL] case h.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α hc✝ : a ≤ -b - toIcoDiv hp a (-b) • p hc : b - -toIcoDiv hp a (-b) • p ≤ -a ho✝ : -b - toIcoDiv hp a (-b) • p < a + p ho : -(a + p) < b - -toIcoDiv hp a (-b) • p ⊢ b - -toIcoDiv hp a (-b) • p ∈ Set.Ioc (-(a + p)) (-(a + p) + p) [PROOFSTEP] refine' ⟨ho, hc.trans_eq _⟩ [GOAL] case h.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α hc✝ : a ≤ -b - toIcoDiv hp a (-b) • p hc : b - -toIcoDiv hp a (-b) • p ≤ -a ho✝ : -b - toIcoDiv hp a (-b) • p < a + p ho : -(a + p) < b - -toIcoDiv hp a (-b) • p ⊢ -a = -(a + p) + p [PROOFSTEP] rw [neg_add, neg_add_cancel_right] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) [PROOFSTEP] simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b) [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) [PROOFSTEP] rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) [PROOFSTEP] simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b) [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoMod hp a (b + m • p) = toIcoMod hp a b [PROOFSTEP] rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b + m • p - (toIcoDiv hp a b • p + m • p) = b - toIcoDiv hp a b • p [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b + m • p - (toIcoDiv hp a b • p + m • p) = b - toIcoDiv hp a b • p [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p [PROOFSTEP] simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocMod hp a (b + m • p) = toIocMod hp a b [PROOFSTEP] rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b + m • p - (toIocDiv hp a b • p + m • p) = b - toIocDiv hp a b • p [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ b + m • p - (toIocDiv hp a b • p + m • p) = b - toIocDiv hp a b • p [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocMod hp (a + m • p) b = toIocMod hp a b + m • p [PROOFSTEP] simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoMod hp a (m • p + b) = toIcoMod hp a b [PROOFSTEP] rw [add_comm, toIcoMod_add_zsmul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b [PROOFSTEP] rw [add_comm, toIcoMod_add_zsmul', add_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocMod hp a (m • p + b) = toIocMod hp a b [PROOFSTEP] rw [add_comm, toIocMod_add_zsmul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocMod hp (m • p + a) b = m • p + toIocMod hp a b [PROOFSTEP] rw [add_comm, toIocMod_add_zsmul', add_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoMod hp a (b - m • p) = toIcoMod hp a b [PROOFSTEP] rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p [PROOFSTEP] simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul'] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocMod hp a (b - m • p) = toIocMod hp a b [PROOFSTEP] rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α m : ℤ ⊢ toIocMod hp (a - m • p) b = toIocMod hp a b - m • p [PROOFSTEP] simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul'] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp a (b + p) = toIcoMod hp a b [PROOFSTEP] simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp (a + p) b = toIcoMod hp a b + p [PROOFSTEP] simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp a (b + p) = toIocMod hp a b [PROOFSTEP] simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp (a + p) b = toIocMod hp a b + p [PROOFSTEP] simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp a (p + b) = toIcoMod hp a b [PROOFSTEP] rw [add_comm, toIcoMod_add_right] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp (p + a) b = p + toIcoMod hp a b [PROOFSTEP] rw [add_comm, toIcoMod_add_right', add_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp a (p + b) = toIocMod hp a b [PROOFSTEP] rw [add_comm, toIocMod_add_right] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp (p + a) b = p + toIocMod hp a b [PROOFSTEP] rw [add_comm, toIocMod_add_right', add_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp a (b - p) = toIcoMod hp a b [PROOFSTEP] simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp (a - p) b = toIcoMod hp a b - p [PROOFSTEP] simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp a (b - p) = toIocMod hp a b [PROOFSTEP] simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp (a - p) b = toIocMod hp a b - p [PROOFSTEP] simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c [PROOFSTEP] simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIocMod hp a (b - c) = toIocMod hp (a + c) b - c [PROOFSTEP] simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c [PROOFSTEP] simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIocMod hp a (b + c) = toIocMod hp (a - c) b + c [PROOFSTEP] simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp a (-b) = p - toIocMod hp (-a) b [PROOFSTEP] simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ -b - -(toIocDiv hp (-a) b • p + 1 • p) = p - (b - toIocDiv hp (-a) b • p) [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ -b - -(toIocDiv hp (-a) b • p + 1 • p) = p - (b - toIocDiv hp (-a) b • p) [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp (-a) b = p - toIocMod hp a (-b) [PROOFSTEP] simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b) [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp a (-b) = p - toIcoMod hp (-a) b [PROOFSTEP] simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ -b - -(toIcoDiv hp (-a) b • p + 1 • p) = p - (b - toIcoDiv hp (-a) b • p) [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ -b - -(toIcoDiv hp (-a) b • p + 1 • p) = p - (b - toIcoDiv hp (-a) b • p) [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp (-a) b = p - toIcoMod hp a (-b) [PROOFSTEP] simpa only [neg_neg] using toIocMod_neg hp (-a) (-b) [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n, c - b = n • p [PROOFSTEP] refine' ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, _⟩, fun h => _⟩ [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIcoMod hp a b = toIcoMod hp a c ⊢ c - b = (toIcoDiv hp a c - toIcoDiv hp a b) • p [PROOFSTEP] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIcoMod hp a b = toIcoMod hp a c | c - b [PROOFSTEP] rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIcoMod hp a b = toIcoMod hp a c | c - b [PROOFSTEP] rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIcoMod hp a b = toIcoMod hp a c | c - b [PROOFSTEP] rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIcoMod hp a b = toIcoMod hp a c ⊢ toIcoMod hp a c + toIcoDiv hp a c • p - (toIcoMod hp a b + toIcoDiv hp a b • p) = (toIcoDiv hp a c - toIcoDiv hp a b) • p [PROOFSTEP] rw [h, sub_smul] [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIcoMod hp a b = toIcoMod hp a c ⊢ toIcoMod hp a c + toIcoDiv hp a c • p - (toIcoMod hp a c + toIcoDiv hp a b • p) = toIcoDiv hp a c • p - toIcoDiv hp a b • p [PROOFSTEP] abel [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIcoMod hp a b = toIcoMod hp a c ⊢ toIcoMod hp a c + toIcoDiv hp a c • p - (toIcoMod hp a c + toIcoDiv hp a b • p) = toIcoDiv hp a c • p - toIcoDiv hp a b • p [PROOFSTEP] abel [GOAL] case refine'_2 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : ∃ n, c - b = n • p ⊢ toIcoMod hp a b = toIcoMod hp a c [PROOFSTEP] rcases h with ⟨z, hz⟩ [GOAL] case refine'_2.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n z : ℤ hz : c - b = z • p ⊢ toIcoMod hp a b = toIcoMod hp a c [PROOFSTEP] rw [sub_eq_iff_eq_add] at hz [GOAL] case refine'_2.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n z : ℤ hz : c = z • p + b ⊢ toIcoMod hp a b = toIcoMod hp a c [PROOFSTEP] rw [hz, toIcoMod_zsmul_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ toIocMod hp a b = toIocMod hp a c ↔ ∃ n, c - b = n • p [PROOFSTEP] refine' ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, _⟩, fun h => _⟩ [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIocMod hp a b = toIocMod hp a c ⊢ c - b = (toIocDiv hp a c - toIocDiv hp a b) • p [PROOFSTEP] conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIocMod hp a b = toIocMod hp a c | c - b [PROOFSTEP] rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIocMod hp a b = toIocMod hp a c | c - b [PROOFSTEP] rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIocMod hp a b = toIocMod hp a c | c - b [PROOFSTEP] rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIocMod hp a b = toIocMod hp a c ⊢ toIocMod hp a c + toIocDiv hp a c • p - (toIocMod hp a b + toIocDiv hp a b • p) = (toIocDiv hp a c - toIocDiv hp a b) • p [PROOFSTEP] rw [h, sub_smul] [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIocMod hp a b = toIocMod hp a c ⊢ toIocMod hp a c + toIocDiv hp a c • p - (toIocMod hp a c + toIocDiv hp a b • p) = toIocDiv hp a c • p - toIocDiv hp a b • p [PROOFSTEP] abel [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIocMod hp a b = toIocMod hp a c ⊢ toIocMod hp a c + toIocDiv hp a c • p - (toIocMod hp a c + toIocDiv hp a b • p) = toIocDiv hp a c • p - toIocDiv hp a b • p [PROOFSTEP] abel [GOAL] case refine'_2 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : ∃ n, c - b = n • p ⊢ toIocMod hp a b = toIocMod hp a c [PROOFSTEP] rcases h with ⟨z, hz⟩ [GOAL] case refine'_2.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n z : ℤ hz : c - b = z • p ⊢ toIocMod hp a b = toIocMod hp a c [PROOFSTEP] rw [sub_eq_iff_eq_add] at hz [GOAL] case refine'_2.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n z : ℤ hz : c = z • p + b ⊢ toIocMod hp a b = toIocMod hp a c [PROOFSTEP] rw [hz, toIocMod_zsmul_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ (∃ z, b = a + z • p) → toIcoMod hp a b = a [PROOFSTEP] rintro ⟨n, rfl⟩ [GOAL] case intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a c : α n✝ n : ℤ ⊢ toIcoMod hp a (a + n • p) = a [PROOFSTEP] rw [toIcoMod_add_zsmul, toIcoMod_apply_left] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p [PROOFSTEP] refine' modEq_iff_eq_add_zsmul.trans ⟨_, fun h => ⟨toIocDiv hp a b + 1, _⟩⟩ [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ (∃ z, b = a + z • p) → toIocMod hp a b = a + p [PROOFSTEP] rintro ⟨z, rfl⟩ [GOAL] case refine'_1.intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a c : α n z : ℤ ⊢ toIocMod hp a (a + z • p) = a + p [PROOFSTEP] rw [toIocMod_add_zsmul, toIocMod_apply_left] [GOAL] case refine'_2 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h : toIocMod hp a b = a + p ⊢ b = a + (toIocDiv hp a b + 1) • p [PROOFSTEP] rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add'] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ TFAE [a ≡ b [PMOD p], ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] [PROOFSTEP] rw [modEq_iff_toIcoMod_eq_left hp] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ TFAE [toIcoMod hp a b = a, ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] [PROOFSTEP] tfae_have 3 → 2 [GOAL] case tfae_3_to_2 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) [PROOFSTEP] rw [← not_exists, not_imp_not] [GOAL] case tfae_3_to_2 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ (∃ x, b - x • p ∈ Set.Ioo a (a + p)) → toIcoMod hp a b = toIocMod hp a b [PROOFSTEP] exact fun ⟨i, hi⟩ => ((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans ((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) ⊢ TFAE [toIcoMod hp a b = a, ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] [PROOFSTEP] tfae_have 4 → 3 [GOAL] case tfae_4_to_3 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) ⊢ toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b [PROOFSTEP] intro h [GOAL] case tfae_4_to_3 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) h : toIcoMod hp a b + p = toIocMod hp a b ⊢ toIcoMod hp a b ≠ toIocMod hp a b [PROOFSTEP] rw [← h, Ne, eq_comm, add_right_eq_self] [GOAL] case tfae_4_to_3 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) h : toIcoMod hp a b + p = toIocMod hp a b ⊢ ¬p = 0 [PROOFSTEP] exact hp.ne' [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b ⊢ TFAE [toIcoMod hp a b = a, ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] [PROOFSTEP] tfae_have 1 → 4 [GOAL] case tfae_1_to_4 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b ⊢ toIcoMod hp a b = a → toIcoMod hp a b + p = toIocMod hp a b [PROOFSTEP] intro h [GOAL] case tfae_1_to_4 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b h : toIcoMod hp a b = a ⊢ toIcoMod hp a b + p = toIocMod hp a b [PROOFSTEP] rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc] [GOAL] case tfae_1_to_4 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b h : toIcoMod hp a b = a ⊢ a < a + p ∧ ∃ z, b = a + p + z • p [PROOFSTEP] refine' ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, _⟩ [GOAL] case tfae_1_to_4 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b h : toIcoMod hp a b = a ⊢ b = a + p + (toIcoDiv hp a b - 1) • p [PROOFSTEP] rw [sub_one_zsmul, add_add_add_comm, add_right_neg, add_zero] [GOAL] case tfae_1_to_4 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b h : toIcoMod hp a b = a ⊢ b = a + toIcoDiv hp a b • p [PROOFSTEP] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b h : toIcoMod hp a b = a | b [PROOFSTEP] rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b h : toIcoMod hp a b = a | b [PROOFSTEP] rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b h : toIcoMod hp a b = a | b [PROOFSTEP] rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b tfae_1_to_4 : toIcoMod hp a b = a → toIcoMod hp a b + p = toIocMod hp a b ⊢ TFAE [toIcoMod hp a b = a, ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] [PROOFSTEP] tfae_have 2 → 1 [GOAL] case tfae_2_to_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b tfae_1_to_4 : toIcoMod hp a b = a → toIcoMod hp a b + p = toIocMod hp a b ⊢ (∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p)) → toIcoMod hp a b = a [PROOFSTEP] rw [← not_exists, not_imp_comm] [GOAL] case tfae_2_to_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b tfae_1_to_4 : toIcoMod hp a b = a → toIcoMod hp a b + p = toIocMod hp a b ⊢ ¬toIcoMod hp a b = a → ∃ x, b - x • p ∈ Set.Ioo a (a + p) [PROOFSTEP] have h' := toIcoMod_mem_Ico hp a b [GOAL] case tfae_2_to_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b tfae_1_to_4 : toIcoMod hp a b = a → toIcoMod hp a b + p = toIocMod hp a b h' : toIcoMod hp a b ∈ Set.Ico a (a + p) ⊢ ¬toIcoMod hp a b = a → ∃ x, b - x • p ∈ Set.Ioo a (a + p) [PROOFSTEP] exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ tfae_3_to_2 : toIcoMod hp a b ≠ toIocMod hp a b → ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p) tfae_4_to_3 : toIcoMod hp a b + p = toIocMod hp a b → toIcoMod hp a b ≠ toIocMod hp a b tfae_1_to_4 : toIcoMod hp a b = a → toIcoMod hp a b + p = toIocMod hp a b tfae_2_to_1 : (∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p)) → toIcoMod hp a b = a ⊢ TFAE [toIcoMod hp a b = a, ∀ (z : ℤ), ¬b - z • p ∈ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] [PROOFSTEP] tfae_finish [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ ¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b [PROOFSTEP] rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj, (zsmul_strictMono_left hp).injective.eq_iff] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 [PROOFSTEP] rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq, sub_sub, sub_right_inj, ← add_one_zsmul, (zsmul_strictMono_left hp).injective.eq_iff] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c✝ : α n : ℤ c : α ⊢ toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] [PROOFSTEP] simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add'] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ {b | toIcoMod hp a b = toIocMod hp a b} = ⋃ (z : ℤ), Set.Ioo (a + z • p) (a + p + z • p) [PROOFSTEP] ext1 [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x✝ : α ⊢ x✝ ∈ {b | toIcoMod hp a b = toIocMod hp a b} ↔ x✝ ∈ ⋃ (z : ℤ), Set.Ioo (a + z • p) (a + p + z • p) [PROOFSTEP] simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ← not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall, Classical.not_not] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a b ⩿ toIcoDiv hp a b [PROOFSTEP] suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by rwa [wcovby_iff_eq_or_covby, ← Order.succ_eq_iff_covby] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α this : toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b ⊢ toIocDiv hp a b ⩿ toIcoDiv hp a b [PROOFSTEP] rwa [wcovby_iff_eq_or_covby, ← Order.succ_eq_iff_covby] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b [PROOFSTEP] rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ← modEq_iff_toIcoDiv_eq_toIocDiv_add_one] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ ¬a ≡ b [PMOD p] ∨ a ≡ b [PMOD p] [PROOFSTEP] exact em' _ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp a b ≤ toIocMod hp a b [PROOFSTEP] rw [toIcoMod, toIocMod, sub_le_sub_iff_left] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a b • p ≤ toIcoDiv hp a b • p [PROOFSTEP] exact zsmul_mono_left hp.le (toIocDiv_wcovby_toIcoDiv _ _ _).le [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp a b ≤ toIcoMod hp a b + p [PROOFSTEP] rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul, (zsmul_strictMono_left hp).le_iff_le] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a b ≤ toIocDiv hp a b + 1 [PROOFSTEP] apply (toIocDiv_wcovby_toIcoDiv _ _ _).le_succ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) [PROOFSTEP] rw [toIcoMod_eq_iff, and_iff_left] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ ∃ z, b = b + z • p [PROOFSTEP] exact ⟨0, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ b = b + 0 • p [PROOFSTEP] simp [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) [PROOFSTEP] rw [toIocMod_eq_iff, and_iff_left] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ ∃ z, b = b + z • p [PROOFSTEP] exact ⟨0, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ ⊢ b = b + 0 • p [PROOFSTEP] simp [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) [PROOFSTEP] rw [← neg_sub, toIcoMod_neg, neg_zero] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) [PROOFSTEP] rw [← neg_sub, toIocMod_neg, neg_zero] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoDiv hp a b = toIcoDiv hp 0 (b - a) [PROOFSTEP] rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocDiv hp a b = toIocDiv hp 0 (b - a) [PROOFSTEP] rw [toIocDiv_sub_eq_toIocDiv_add, zero_add] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp a b = toIcoMod hp 0 (b - a) + a [PROOFSTEP] rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp a b = toIocMod hp 0 (b - a) + a [PROOFSTEP] rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a) = p [PROOFSTEP] rw [toIcoMod_zero_sub_comm, sub_add_cancel] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a b : α ⊢ toIocMod hp 0 (a - b) + toIcoMod hp 0 (b - a) = p [PROOFSTEP] rw [_root_.add_comm, toIcoMod_add_toIocMod_zero] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a : α b : α ⧸ AddSubgroup.zmultiples p ⊢ (fun x => ↑↑x) ((fun b => { val := Function.Periodic.lift (_ : Function.Periodic (toIcoMod hp a) p) b, property := (_ : Function.Periodic.lift (_ : Function.Periodic (toIcoMod hp a) p) b ∈ Set.Ico a (a + p)) }) b) = b [PROOFSTEP] induction b using QuotientAddGroup.induction_on' [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a z✝ : α ⊢ (fun x => ↑↑x) ((fun b => { val := Function.Periodic.lift (_ : Function.Periodic (toIcoMod hp a) p) b, property := (_ : Function.Periodic.lift (_ : Function.Periodic (toIcoMod hp a) p) b ∈ Set.Ico a (a + p)) }) ↑z✝) = ↑z✝ [PROOFSTEP] dsimp [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a z✝ : α ⊢ ↑(toIcoMod hp a z✝) = ↑z✝ [PROOFSTEP] rw [QuotientAddGroup.eq_iff_sub_mem, toIcoMod_sub_self] [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a z✝ : α ⊢ -toIcoDiv hp a z✝ • p ∈ AddSubgroup.zmultiples p [PROOFSTEP] apply AddSubgroup.zsmul_mem_zmultiples [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c : α n : ℤ a : α b : α ⧸ AddSubgroup.zmultiples p ⊢ (fun x => ↑↑x) ((fun b => { val := Function.Periodic.lift (_ : Function.Periodic (toIocMod hp a) p) b, property := (_ : Function.Periodic.lift (_ : Function.Periodic (toIocMod hp a) p) b ∈ Set.Ioc a (a + p)) }) b) = b [PROOFSTEP] induction b using QuotientAddGroup.induction_on' [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a z✝ : α ⊢ (fun x => ↑↑x) ((fun b => { val := Function.Periodic.lift (_ : Function.Periodic (toIocMod hp a) p) b, property := (_ : Function.Periodic.lift (_ : Function.Periodic (toIocMod hp a) p) b ∈ Set.Ioc a (a + p)) }) ↑z✝) = ↑z✝ [PROOFSTEP] dsimp [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a z✝ : α ⊢ ↑(toIocMod hp a z✝) = ↑z✝ [PROOFSTEP] rw [QuotientAddGroup.eq_iff_sub_mem, toIocMod_sub_self] [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b c : α n : ℤ a z✝ : α ⊢ -toIocDiv hp a z✝ • p ∈ AddSubgroup.zmultiples p [PROOFSTEP] apply AddSubgroup.zsmul_mem_zmultiples [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α ⊢ toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ↔ toIcoMod hp 0 (x₂ - x₁) + toIcoMod hp 0 (x₁ - x₃) ≤ p [PROOFSTEP] rw [toIcoMod_eq_sub, toIocMod_eq_sub _ x₁, add_le_add_iff_right, ← neg_sub x₁ x₃, toIocMod_neg, neg_zero, le_sub_iff_add_le] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ⊢ toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ [PROOFSTEP] let x₂' := toIcoMod hp x₁ x₂ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ ⊢ toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ [PROOFSTEP] let x₃' := toIcoMod hp x₂' x₃ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ ⊢ toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ [PROOFSTEP] have h : x₂' ≤ toIocMod hp x₁ x₃' := by simpa [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ ⊢ x₂' ≤ toIocMod hp x₁ x₃' [PROOFSTEP] simpa [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' ⊢ toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ [PROOFSTEP] have h₂₁ : x₂' < x₁ + p := toIcoMod_lt_right _ _ _ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p ⊢ toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ [PROOFSTEP] have h₃₂ : x₃' - p < x₂' := sub_lt_iff_lt_add.2 (toIcoMod_lt_right _ _ _) [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' ⊢ toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ [PROOFSTEP] suffices hequiv : x₃' ≤ toIocMod hp x₂' x₁ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' hequiv : x₃' ≤ toIocMod hp x₂' x₁ ⊢ toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ [PROOFSTEP] obtain ⟨z, hd⟩ : ∃ z : ℤ, x₂ = x₂' + z • p := ((toIcoMod_eq_iff hp).1 rfl).2 [GOAL] case intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' hequiv : x₃' ≤ toIocMod hp x₂' x₁ z : ℤ hd : x₂ = x₂' + z • p ⊢ toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ [PROOFSTEP] rw [hd, toIocMod_add_zsmul', toIcoMod_add_zsmul', add_le_add_iff_right] [GOAL] case intro α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' hequiv : x₃' ≤ toIocMod hp x₂' x₁ z : ℤ hd : x₂ = x₂' + z • p ⊢ toIcoMod hp x₂' x₃ ≤ toIocMod hp x₂' x₁ [PROOFSTEP] assumption -- Porting note: was `simpa` [GOAL] case hequiv α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' ⊢ x₃' ≤ toIocMod hp x₂' x₁ [PROOFSTEP] cases' le_or_lt x₃' (x₁ + p) with h₃₁ h₁₃ [GOAL] case hequiv.inl α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₃₁ : x₃' ≤ x₁ + p ⊢ x₃' ≤ toIocMod hp x₂' x₁ [PROOFSTEP] suffices hIoc₂₁ : toIocMod hp x₂' x₁ = x₁ + p [GOAL] case hequiv.inl α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₃₁ : x₃' ≤ x₁ + p hIoc₂₁ : toIocMod hp x₂' x₁ = x₁ + p ⊢ x₃' ≤ toIocMod hp x₂' x₁ [PROOFSTEP] exact hIoc₂₁.symm.trans_ge h₃₁ [GOAL] case hIoc₂₁ α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₃₁ : x₃' ≤ x₁ + p ⊢ toIocMod hp x₂' x₁ = x₁ + p [PROOFSTEP] apply (toIocMod_eq_iff hp).2 [GOAL] case hIoc₂₁ α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₃₁ : x₃' ≤ x₁ + p ⊢ x₁ + p ∈ Set.Ioc x₂' (x₂' + p) ∧ ∃ z, x₁ = x₁ + p + z • p [PROOFSTEP] exact ⟨⟨h₂₁, by simp [left_le_toIcoMod]⟩, -1, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₃₁ : x₃' ≤ x₁ + p ⊢ x₁ + p ≤ x₂' + p [PROOFSTEP] simp [left_le_toIcoMod] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₃₁ : x₃' ≤ x₁ + p ⊢ x₁ = x₁ + p + -1 • p [PROOFSTEP] simp [GOAL] case hequiv.inr α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₁₃ : x₁ + p < x₃' ⊢ x₃' ≤ toIocMod hp x₂' x₁ [PROOFSTEP] have hIoc₁₃ : toIocMod hp x₁ x₃' = x₃' - p := by apply (toIocMod_eq_iff hp).2 exact ⟨⟨lt_sub_iff_add_lt.2 h₁₃, le_of_lt (h₃₂.trans h₂₁)⟩, 1, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₁₃ : x₁ + p < x₃' ⊢ toIocMod hp x₁ x₃' = x₃' - p [PROOFSTEP] apply (toIocMod_eq_iff hp).2 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₁₃ : x₁ + p < x₃' ⊢ x₃' - p ∈ Set.Ioc x₁ (x₁ + p) ∧ ∃ z, x₃' = x₃' - p + z • p [PROOFSTEP] exact ⟨⟨lt_sub_iff_add_lt.2 h₁₃, le_of_lt (h₃₂.trans h₂₁)⟩, 1, by simp⟩ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₁₃ : x₁ + p < x₃' ⊢ x₃' = x₃' - p + 1 • p [PROOFSTEP] simp [GOAL] case hequiv.inr α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₁₃ : x₁ + p < x₃' hIoc₁₃ : toIocMod hp x₁ x₃' = x₃' - p ⊢ x₃' ≤ toIocMod hp x₂' x₁ [PROOFSTEP] have not_h₃₂ := (h.trans hIoc₁₃.le).not_lt [GOAL] case hequiv.inr α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ : α h✝ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ x₂' : α := toIcoMod hp x₁ x₂ x₃' : α := toIcoMod hp x₂' x₃ h : x₂' ≤ toIocMod hp x₁ x₃' h₂₁ : x₂' < x₁ + p h₃₂ : x₃' - p < x₂' h₁₃ : x₁ + p < x₃' hIoc₁₃ : toIocMod hp x₁ x₃' = x₃' - p not_h₃₂ : ¬x₃' - p < x₂' ⊢ x₃' ≤ toIocMod hp x₂' x₁ [PROOFSTEP] contradiction [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h₁₂₃ : toIcoMod hp a b ≤ toIocMod hp a c h₁₃₂ : toIcoMod hp a c ≤ toIocMod hp a b ⊢ b ≡ a [PMOD p] ∨ c ≡ b [PMOD p] ∨ a ≡ c [PMOD p] [PROOFSTEP] by_contra' h [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h₁₂₃ : toIcoMod hp a b ≤ toIocMod hp a c h₁₃₂ : toIcoMod hp a c ≤ toIocMod hp a b h : ¬b ≡ a [PMOD p] ∧ ¬c ≡ b [PMOD p] ∧ ¬a ≡ c [PMOD p] ⊢ False [PROOFSTEP] rw [modEq_comm] at h [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h₁₂₃ : toIcoMod hp a b ≤ toIocMod hp a c h₁₃₂ : toIcoMod hp a c ≤ toIocMod hp a b h : ¬a ≡ b [PMOD p] ∧ ¬c ≡ b [PMOD p] ∧ ¬a ≡ c [PMOD p] ⊢ False [PROOFSTEP] rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.2.2] at h₁₂₃ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h₁₂₃ : toIcoMod hp a b ≤ toIcoMod hp a c h₁₃₂ : toIcoMod hp a c ≤ toIocMod hp a b h : ¬a ≡ b [PMOD p] ∧ ¬c ≡ b [PMOD p] ∧ ¬a ≡ c [PMOD p] ⊢ False [PROOFSTEP] rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.1] at h₁₃₂ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ h₁₂₃ : toIcoMod hp a b ≤ toIcoMod hp a c h₁₃₂ : toIcoMod hp a c ≤ toIcoMod hp a b h : ¬a ≡ b [PMOD p] ∧ ¬c ≡ b [PMOD p] ∧ ¬a ≡ c [PMOD p] ⊢ False [PROOFSTEP] exact h.2.1 ((toIcoMod_inj _).1 <| h₁₃₂.antisymm h₁₂₃) [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α ⊢ toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a [PROOFSTEP] have := congr_arg₂ (· + ·) (toIcoMod_add_toIocMod_zero hp a b) (toIcoMod_add_toIocMod_zero hp c b) [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α this : (fun x x_1 => x + x_1) (toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a)) (toIcoMod hp 0 (c - b) + toIocMod hp 0 (b - c)) = (fun x x_1 => x + x_1) p p ⊢ toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a [PROOFSTEP] simp only [add_add_add_comm] at this [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α this : toIcoMod hp 0 (a - b) + toIcoMod hp 0 (c - b) + (toIocMod hp 0 (b - a) + toIocMod hp 0 (b - c)) = p + p ⊢ toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a [PROOFSTEP] rw [_root_.add_comm (toIocMod _ _ _), add_add_add_comm, ← two_nsmul] at this [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α this : toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - c) + (toIcoMod hp 0 (c - b) + toIocMod hp 0 (b - a)) = 2 • p ⊢ toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a [PROOFSTEP] replace := min_le_of_add_le_two_nsmul this.le [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α this : min (toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - c)) (toIcoMod hp 0 (c - b) + toIocMod hp 0 (b - a)) ≤ p ⊢ toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a [PROOFSTEP] rw [min_le_iff] at this [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α this : toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - c) ≤ p ∨ toIcoMod hp 0 (c - b) + toIocMod hp 0 (b - a) ≤ p ⊢ toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a [PROOFSTEP] rw [toIxxMod_iff, toIxxMod_iff] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α this : toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - c) ≤ p ∨ toIcoMod hp 0 (c - b) + toIocMod hp 0 (b - a) ≤ p ⊢ toIcoMod hp 0 (a - b) + toIcoMod hp 0 (b - c) ≤ p ∨ toIcoMod hp 0 (c - b) + toIcoMod hp 0 (b - a) ≤ p [PROOFSTEP] refine' this.imp (le_trans <| add_le_add_left _ _) (le_trans <| add_le_add_left _ _) [GOAL] case refine'_1 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α this : toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - c) ≤ p ∨ toIcoMod hp 0 (c - b) + toIocMod hp 0 (b - a) ≤ p ⊢ toIcoMod hp 0 (b - c) ≤ toIocMod hp 0 (b - c) [PROOFSTEP] apply toIcoMod_le_toIocMod [GOAL] case refine'_2 α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a✝ b✝ c✝ : α n : ℤ a b c : α this : toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - c) ≤ p ∨ toIcoMod hp 0 (c - b) + toIocMod hp 0 (b - a) ≤ p ⊢ toIcoMod hp 0 (b - a) ≤ toIocMod hp 0 (b - a) [PROOFSTEP] apply toIcoMod_le_toIocMod [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ ⊢ toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₁ [PROOFSTEP] constructor [GOAL] case left α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ ⊢ toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ [PROOFSTEP] suffices h : ¬x₃ ≡ x₂ [PMOD p] [GOAL] case left α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ h : ¬x₃ ≡ x₂ [PMOD p] ⊢ toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ [PROOFSTEP] have h₁₂₃' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₁₂₃.1) [GOAL] case left α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ h : ¬x₃ ≡ x₂ [PMOD p] h₁₂₃' : toIcoMod hp x₃ x₁ ≤ toIocMod hp x₃ x₂ ⊢ toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ [PROOFSTEP] have h₂₃₄' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₂₃₄.1) [GOAL] case left α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ h : ¬x₃ ≡ x₂ [PMOD p] h₁₂₃' : toIcoMod hp x₃ x₁ ≤ toIocMod hp x₃ x₂ h₂₃₄' : toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₄ ⊢ toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ [PROOFSTEP] rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp).1 h] at h₂₃₄' [GOAL] case left α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ h : ¬x₃ ≡ x₂ [PMOD p] h₁₂₃' : toIcoMod hp x₃ x₁ ≤ toIocMod hp x₃ x₂ h₂₃₄' : toIocMod hp x₃ x₂ ≤ toIocMod hp x₃ x₄ ⊢ toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ [PROOFSTEP] exact toIxxMod_cyclic_left _ (h₁₂₃'.trans h₂₃₄') [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ ⊢ ¬x₃ ≡ x₂ [PMOD p] [PROOFSTEP] by_contra h [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ h : x₃ ≡ x₂ [PMOD p] ⊢ False [PROOFSTEP] rw [(modEq_iff_toIcoMod_eq_left hp).1 h] at h₁₂₃ [GOAL] case h α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬x₃ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ h : x₃ ≡ x₂ [PMOD p] ⊢ False [PROOFSTEP] exact h₁₂₃.2 (left_lt_toIocMod _ _ _).le [GOAL] case right α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂ ⊢ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₁ [PROOFSTEP] rw [not_le] at h₁₂₃ h₂₃₄ ⊢ [GOAL] case right α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ x₁ x₂ x₃ x₄ : α h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ toIocMod hp x₃ x₁ < toIcoMod hp x₃ x₂ h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ toIocMod hp x₃ x₂ < toIcoMod hp x₃ x₄ ⊢ toIocMod hp x₃ x₁ < toIcoMod hp x₃ x₄ [PROOFSTEP] exact (h₁₂₃.2.trans_le (toIcoMod_le_toIocMod _ x₃ x₂)).trans h₂₃₄.2 [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x₁ x₂ x₃ : α ⊢ btw ↑x₁ ↑x₂ ↑x₃ ↔ toIcoMod (_ : 0 < p) x₁ x₂ ≤ toIocMod (_ : 0 < p) x₁ x₃ [PROOFSTEP] rw [btw_coe_iff', toIocMod_sub_eq_sub, toIcoMod_sub_eq_sub, zero_add, sub_le_sub_iff_right] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x : α ⧸ AddSubgroup.zmultiples p ⊢ ↑(↑(equivIcoMod (_ : 0 < p) 0) (x - x)) ≤ ↑(↑(equivIocMod (_ : 0 < p) 0) (x - x)) [PROOFSTEP] simp [sub_self, hp'.out.le] [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x₁ x₂ x₃ : α ⧸ AddSubgroup.zmultiples p h : btw x₁ x₂ x₃ ⊢ btw x₂ x₃ x₁ [PROOFSTEP] induction x₁ using QuotientAddGroup.induction_on' [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x₂ x₃ : α ⧸ AddSubgroup.zmultiples p z✝ : α h : btw (↑z✝) x₂ x₃ ⊢ btw x₂ x₃ ↑z✝ [PROOFSTEP] induction x₂ using QuotientAddGroup.induction_on' [GOAL] case H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x₃ : α ⧸ AddSubgroup.zmultiples p z✝¹ z✝ : α h : btw (↑z✝¹) (↑z✝) x₃ ⊢ btw (↑z✝) x₃ ↑z✝¹ [PROOFSTEP] induction x₃ using QuotientAddGroup.induction_on' [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) z✝² z✝¹ z✝ : α h : btw ↑z✝² ↑z✝¹ ↑z✝ ⊢ btw ↑z✝¹ ↑z✝ ↑z✝² [PROOFSTEP] simp_rw [btw_coe_iff] at h ⊢ [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) z✝² z✝¹ z✝ : α h : toIcoMod (_ : 0 < p) z✝² z✝¹ ≤ toIocMod (_ : 0 < p) z✝² z✝ ⊢ toIcoMod (_ : 0 < p) z✝¹ z✝ ≤ toIocMod (_ : 0 < p) z✝¹ z✝² [PROOFSTEP] apply toIxxMod_cyclic_left _ h [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x₁ x₂ x₃ x₄ : α ⧸ AddSubgroup.zmultiples p h₁₂₃ : btw x₁ x₂ x₃ ∧ ¬btw x₃ x₂ x₁ h₂₃₄ : btw x₂ x₄ x₃ ∧ ¬btw x₃ x₄ x₂ ⊢ btw x₁ x₄ x₃ ∧ ¬btw x₃ x₄ x₁ [PROOFSTEP] induction x₁ using QuotientAddGroup.induction_on' [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x₂ x₃ x₄ : α ⧸ AddSubgroup.zmultiples p h₂₃₄ : btw x₂ x₄ x₃ ∧ ¬btw x₃ x₄ x₂ z✝ : α h₁₂₃ : btw (↑z✝) x₂ x₃ ∧ ¬btw x₃ x₂ ↑z✝ ⊢ btw (↑z✝) x₄ x₃ ∧ ¬btw x₃ x₄ ↑z✝ [PROOFSTEP] induction x₂ using QuotientAddGroup.induction_on' [GOAL] case H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x₃ x₄ : α ⧸ AddSubgroup.zmultiples p z✝¹ z✝ : α h₂₃₄ : btw (↑z✝) x₄ x₃ ∧ ¬btw x₃ x₄ ↑z✝ h₁₂₃ : btw (↑z✝¹) (↑z✝) x₃ ∧ ¬btw x₃ ↑z✝ ↑z✝¹ ⊢ btw (↑z✝¹) x₄ x₃ ∧ ¬btw x₃ x₄ ↑z✝¹ [PROOFSTEP] induction x₃ using QuotientAddGroup.induction_on' [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) x₄ : α ⧸ AddSubgroup.zmultiples p z✝² z✝¹ z✝ : α h₂₃₄ : btw (↑z✝¹) x₄ ↑z✝ ∧ ¬btw (↑z✝) x₄ ↑z✝¹ h₁₂₃ : btw ↑z✝² ↑z✝¹ ↑z✝ ∧ ¬btw ↑z✝ ↑z✝¹ ↑z✝² ⊢ btw (↑z✝²) x₄ ↑z✝ ∧ ¬btw (↑z✝) x₄ ↑z✝² [PROOFSTEP] induction x₄ using QuotientAddGroup.induction_on' [GOAL] case H.H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) z✝³ z✝² z✝¹ : α h₁₂₃ : btw ↑z✝³ ↑z✝² ↑z✝¹ ∧ ¬btw ↑z✝¹ ↑z✝² ↑z✝³ z✝ : α h₂₃₄ : btw ↑z✝² ↑z✝ ↑z✝¹ ∧ ¬btw ↑z✝¹ ↑z✝ ↑z✝² ⊢ btw ↑z✝³ ↑z✝ ↑z✝¹ ∧ ¬btw ↑z✝¹ ↑z✝ ↑z✝³ [PROOFSTEP] simp_rw [btw_coe_iff] at h₁₂₃ h₂₃₄ ⊢ [GOAL] case H.H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) z✝³ z✝² z✝¹ z✝ : α h₁₂₃ : toIcoMod (_ : 0 < p) z✝³ z✝² ≤ toIocMod (_ : 0 < p) z✝³ z✝¹ ∧ ¬toIcoMod (_ : 0 < p) z✝¹ z✝² ≤ toIocMod (_ : 0 < p) z✝¹ z✝³ h₂₃₄ : toIcoMod (_ : 0 < p) z✝² z✝ ≤ toIocMod (_ : 0 < p) z✝² z✝¹ ∧ ¬toIcoMod (_ : 0 < p) z✝¹ z✝ ≤ toIocMod (_ : 0 < p) z✝¹ z✝² ⊢ toIcoMod (_ : 0 < p) z✝³ z✝ ≤ toIocMod (_ : 0 < p) z✝³ z✝¹ ∧ ¬toIcoMod (_ : 0 < p) z✝¹ z✝ ≤ toIocMod (_ : 0 < p) z✝¹ z✝³ [PROOFSTEP] apply toIxxMod_trans _ h₁₂₃ h₂₃₄ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder x₁ x₂ x₃ : α ⧸ AddSubgroup.zmultiples p h₁₂₃ : btw x₁ x₂ x₃ h₃₂₁ : btw x₃ x₂ x₁ ⊢ x₁ = x₂ ∨ x₂ = x₃ ∨ x₃ = x₁ [PROOFSTEP] induction x₁ using QuotientAddGroup.induction_on' [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder x₂ x₃ : α ⧸ AddSubgroup.zmultiples p z✝ : α h₁₂₃ : btw (↑z✝) x₂ x₃ h₃₂₁ : btw x₃ x₂ ↑z✝ ⊢ ↑z✝ = x₂ ∨ x₂ = x₃ ∨ x₃ = ↑z✝ [PROOFSTEP] induction x₂ using QuotientAddGroup.induction_on' [GOAL] case H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder x₃ : α ⧸ AddSubgroup.zmultiples p z✝¹ z✝ : α h₁₂₃ : btw (↑z✝¹) (↑z✝) x₃ h₃₂₁ : btw x₃ ↑z✝ ↑z✝¹ ⊢ ↑z✝¹ = ↑z✝ ∨ ↑z✝ = x₃ ∨ x₃ = ↑z✝¹ [PROOFSTEP] induction x₃ using QuotientAddGroup.induction_on' [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder z✝² z✝¹ z✝ : α h₁₂₃ : btw ↑z✝² ↑z✝¹ ↑z✝ h₃₂₁ : btw ↑z✝ ↑z✝¹ ↑z✝² ⊢ ↑z✝² = ↑z✝¹ ∨ ↑z✝¹ = ↑z✝ ∨ ↑z✝ = ↑z✝² [PROOFSTEP] rw [btw_cyclic] at h₃₂₁ [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder z✝² z✝¹ z✝ : α h₁₂₃ : btw ↑z✝² ↑z✝¹ ↑z✝ h₃₂₁ : btw ↑z✝² ↑z✝ ↑z✝¹ ⊢ ↑z✝² = ↑z✝¹ ∨ ↑z✝¹ = ↑z✝ ∨ ↑z✝ = ↑z✝² [PROOFSTEP] simp_rw [btw_coe_iff] at h₁₂₃ h₃₂₁ [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder z✝² z✝¹ z✝ : α h₁₂₃ : toIcoMod (_ : 0 < p) z✝² z✝¹ ≤ toIocMod (_ : 0 < p) z✝² z✝ h₃₂₁ : toIcoMod (_ : 0 < p) z✝² z✝ ≤ toIocMod (_ : 0 < p) z✝² z✝¹ ⊢ ↑z✝² = ↑z✝¹ ∨ ↑z✝¹ = ↑z✝ ∨ ↑z✝ = ↑z✝² [PROOFSTEP] simp_rw [← modEq_iff_eq_mod_zmultiples] [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder z✝² z✝¹ z✝ : α h₁₂₃ : toIcoMod (_ : 0 < p) z✝² z✝¹ ≤ toIocMod (_ : 0 < p) z✝² z✝ h₃₂₁ : toIcoMod (_ : 0 < p) z✝² z✝ ≤ toIocMod (_ : 0 < p) z✝² z✝¹ ⊢ z✝¹ ≡ z✝² [PMOD p] ∨ z✝ ≡ z✝¹ [PMOD p] ∨ z✝² ≡ z✝ [PMOD p] [PROOFSTEP] exact toIxxMod_antisymm _ h₁₂₃ h₃₂₁ [GOAL] α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder x₁ x₂ x₃ : α ⧸ AddSubgroup.zmultiples p ⊢ btw x₁ x₂ x₃ ∨ btw x₃ x₂ x₁ [PROOFSTEP] induction x₁ using QuotientAddGroup.induction_on' [GOAL] case H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder x₂ x₃ : α ⧸ AddSubgroup.zmultiples p z✝ : α ⊢ btw (↑z✝) x₂ x₃ ∨ btw x₃ x₂ ↑z✝ [PROOFSTEP] induction x₂ using QuotientAddGroup.induction_on' [GOAL] case H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder x₃ : α ⧸ AddSubgroup.zmultiples p z✝¹ z✝ : α ⊢ btw (↑z✝¹) (↑z✝) x₃ ∨ btw x₃ ↑z✝ ↑z✝¹ [PROOFSTEP] induction x₃ using QuotientAddGroup.induction_on' [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder z✝² z✝¹ z✝ : α ⊢ btw ↑z✝² ↑z✝¹ ↑z✝ ∨ btw ↑z✝ ↑z✝¹ ↑z✝² [PROOFSTEP] simp_rw [btw_coe_iff] [GOAL] case H.H.H α : Type u_1 inst✝ : LinearOrderedAddCommGroup α hα : Archimedean α p : α hp : 0 < p a b c : α n : ℤ hp' : Fact (0 < p) src✝ : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) := circularPreorder z✝² z✝¹ z✝ : α ⊢ toIcoMod (_ : 0 < p) z✝² z✝¹ ≤ toIocMod (_ : 0 < p) z✝² z✝ ∨ toIcoMod (_ : 0 < p) z✝ z✝¹ ≤ toIocMod (_ : 0 < p) z✝ z✝² [PROOFSTEP] apply toIxxMod_total [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ toIcoDiv hp a b = ⌊(b - a) / p⌋ [PROOFSTEP] refine' toIcoDiv_eq_of_sub_zsmul_mem_Ico hp _ [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ b - ⌊(b - a) / p⌋ • p ∈ Set.Ico a (a + p) [PROOFSTEP] rw [Set.mem_Ico, zsmul_eq_mul, ← sub_nonneg, add_comm, sub_right_comm, ← sub_lt_iff_lt_add, sub_right_comm _ _ a] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ 0 ≤ b - a - ↑⌊(b - a) / p⌋ * p ∧ b - a - ↑⌊(b - a) / p⌋ * p < p [PROOFSTEP] exact ⟨Int.sub_floor_div_mul_nonneg _ hp, Int.sub_floor_div_mul_lt _ hp⟩ [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ toIocDiv hp a b = -⌊(a + p - b) / p⌋ [PROOFSTEP] refine' toIocDiv_eq_of_sub_zsmul_mem_Ioc hp _ [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ b - -⌊(a + p - b) / p⌋ • p ∈ Set.Ioc a (a + p) [PROOFSTEP] rw [Set.mem_Ioc, zsmul_eq_mul, Int.cast_neg, neg_mul, sub_neg_eq_add, ← sub_nonneg, sub_add_eq_sub_sub] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ a < b + ↑⌊(a + p - b) / p⌋ * p ∧ 0 ≤ a + p - b - ↑⌊(a + p - b) / p⌋ * p [PROOFSTEP] refine' ⟨_, Int.sub_floor_div_mul_nonneg _ hp⟩ [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ a < b + ↑⌊(a + p - b) / p⌋ * p [PROOFSTEP] rw [← add_lt_add_iff_right p, add_assoc, add_comm b, ← sub_lt_iff_lt_add, add_comm (_ * _), ← sub_lt_iff_lt_add] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ a + p - b - ↑⌊(a + p - b) / p⌋ * p < p [PROOFSTEP] exact Int.sub_floor_div_mul_lt _ hp [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p b : α ⊢ toIcoDiv (_ : 0 < 1) 0 b = ⌊b⌋ [PROOFSTEP] simp [toIcoDiv_eq_floor] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ toIcoMod hp a b = a + Int.fract ((b - a) / p) * p [PROOFSTEP] rw [toIcoMod, toIcoDiv_eq_floor, Int.fract] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ b - ⌊(b - a) / p⌋ • p = a + ((b - a) / p - ↑⌊(b - a) / p⌋) * p [PROOFSTEP] field_simp [hp.ne.symm] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ b - ↑⌊(b - a) / p⌋ * p = a + (b - a - p * ↑⌊(b - a) / p⌋) [PROOFSTEP] ring [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p b : α ⊢ toIcoMod hp 0 b = Int.fract (b / p) * p [PROOFSTEP] simp [toIcoMod_eq_add_fract_mul] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ toIocMod hp a b = a + p - Int.fract ((a + p - b) / p) * p [PROOFSTEP] rw [toIocMod, toIocDiv_eq_neg_floor, Int.fract] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ b - -⌊(a + p - b) / p⌋ • p = a + p - ((a + p - b) / p - ↑⌊(a + p - b) / p⌋) * p [PROOFSTEP] field_simp [hp.ne.symm] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p a b : α ⊢ b + ↑⌊(a + p - b) / p⌋ * p = a + p - (a + p - b - p * ↑⌊(a + p - b) / p⌋) [PROOFSTEP] ring [GOAL] α : Type u_1 inst✝¹ : LinearOrderedField α inst✝ : FloorRing α p : α hp : 0 < p b : α ⊢ toIcoMod (_ : 0 < 1) 0 b = Int.fract b [PROOFSTEP] simp [toIcoMod_eq_add_fract_mul] [GOAL] α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a : α ⊢ ⋃ (n : ℤ), Ioc (a + n • p) (a + (n + 1) • p) = univ [PROOFSTEP] refine' eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr _ [GOAL] α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α ⊢ ∃ i, b ∈ Ioc (a + i • p) (a + (i + 1) • p) [PROOFSTEP] rcases sub_toIocDiv_zsmul_mem_Ioc hp a b with ⟨hl, hr⟩ [GOAL] case intro α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a < b - toIocDiv hp a b • p hr : b - toIocDiv hp a b • p ≤ a + p ⊢ ∃ i, b ∈ Ioc (a + i • p) (a + (i + 1) • p) [PROOFSTEP] refine' ⟨toIocDiv hp a b, ⟨lt_sub_iff_add_lt.mp hl, _⟩⟩ [GOAL] case intro α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a < b - toIocDiv hp a b • p hr : b - toIocDiv hp a b • p ≤ a + p ⊢ b ≤ a + (toIocDiv hp a b + 1) • p [PROOFSTEP] rw [add_smul, one_smul, ← add_assoc] [GOAL] case intro α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a < b - toIocDiv hp a b • p hr : b - toIocDiv hp a b • p ≤ a + p ⊢ b ≤ a + toIocDiv hp a b • p + p [PROOFSTEP] convert sub_le_iff_le_add.mp hr using 1 [GOAL] case h.e'_4 α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a < b - toIocDiv hp a b • p hr : b - toIocDiv hp a b • p ≤ a + p ⊢ a + toIocDiv hp a b • p + p = a + p + toIocDiv hp a b • p [PROOFSTEP] abel [GOAL] case h.e'_4 α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a < b - toIocDiv hp a b • p hr : b - toIocDiv hp a b • p ≤ a + p ⊢ a + toIocDiv hp a b • p + p = a + p + toIocDiv hp a b • p [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a : α ⊢ ⋃ (n : ℤ), Ico (a + n • p) (a + (n + 1) • p) = univ [PROOFSTEP] refine' eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr _ [GOAL] α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α ⊢ ∃ i, b ∈ Ico (a + i • p) (a + (i + 1) • p) [PROOFSTEP] rcases sub_toIcoDiv_zsmul_mem_Ico hp a b with ⟨hl, hr⟩ [GOAL] case intro α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a ≤ b - toIcoDiv hp a b • p hr : b - toIcoDiv hp a b • p < a + p ⊢ ∃ i, b ∈ Ico (a + i • p) (a + (i + 1) • p) [PROOFSTEP] refine' ⟨toIcoDiv hp a b, ⟨le_sub_iff_add_le.mp hl, _⟩⟩ [GOAL] case intro α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a ≤ b - toIcoDiv hp a b • p hr : b - toIcoDiv hp a b • p < a + p ⊢ b < a + (toIcoDiv hp a b + 1) • p [PROOFSTEP] rw [add_smul, one_smul, ← add_assoc] [GOAL] case intro α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a ≤ b - toIcoDiv hp a b • p hr : b - toIcoDiv hp a b • p < a + p ⊢ b < a + toIcoDiv hp a b • p + p [PROOFSTEP] convert sub_lt_iff_lt_add.mp hr using 1 [GOAL] case h.e'_4 α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a ≤ b - toIcoDiv hp a b • p hr : b - toIcoDiv hp a b • p < a + p ⊢ a + toIcoDiv hp a b • p + p = a + p + toIcoDiv hp a b • p [PROOFSTEP] abel [GOAL] case h.e'_4 α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a b : α hl : a ≤ b - toIcoDiv hp a b • p hr : b - toIcoDiv hp a b • p < a + p ⊢ a + toIcoDiv hp a b • p + p = a + p + toIcoDiv hp a b • p [PROOFSTEP] abel [GOAL] α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a : α ⊢ ⋃ (n : ℤ), Icc (a + n • p) (a + (n + 1) • p) = univ [PROOFSTEP] simpa only [iUnion_Ioc_add_zsmul hp a, univ_subset_iff] using iUnion_mono fun n : ℤ => (Ioc_subset_Icc_self : Ioc (a + n • p) (a + (n + 1) • p) ⊆ Icc _ _) [GOAL] α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a : α ⊢ ⋃ (n : ℤ), Ioc (n • p) ((n + 1) • p) = univ [PROOFSTEP] simpa only [zero_add] using iUnion_Ioc_add_zsmul hp 0 [GOAL] α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a : α ⊢ ⋃ (n : ℤ), Ico (n • p) ((n + 1) • p) = univ [PROOFSTEP] simpa only [zero_add] using iUnion_Ico_add_zsmul hp 0 [GOAL] α : Type u_1 inst✝¹ : LinearOrderedAddCommGroup α inst✝ : Archimedean α p : α hp : 0 < p a : α ⊢ ⋃ (n : ℤ), Icc (n • p) ((n + 1) • p) = univ [PROOFSTEP] simpa only [zero_add] using iUnion_Icc_add_zsmul hp 0 [GOAL] α : Type u_1 inst✝¹ : LinearOrderedRing α inst✝ : Archimedean α a : α ⊢ ⋃ (n : ℤ), Ioc (a + ↑n) (a + ↑n + 1) = univ [PROOFSTEP] simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Ioc_add_zsmul zero_lt_one a [GOAL] α : Type u_1 inst✝¹ : LinearOrderedRing α inst✝ : Archimedean α a : α ⊢ ⋃ (n : ℤ), Ico (a + ↑n) (a + ↑n + 1) = univ [PROOFSTEP] simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Ico_add_zsmul zero_lt_one a [GOAL] α : Type u_1 inst✝¹ : LinearOrderedRing α inst✝ : Archimedean α a : α ⊢ ⋃ (n : ℤ), Icc (a + ↑n) (a + ↑n + 1) = univ [PROOFSTEP] simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Icc_add_zsmul zero_lt_one a [GOAL] α : Type u_1 inst✝¹ : LinearOrderedRing α inst✝ : Archimedean α a : α ⊢ ⋃ (n : ℤ), Ioc (↑n) (↑n + 1) = univ [PROOFSTEP] simpa only [zero_add] using iUnion_Ioc_add_int_cast (0 : α) [GOAL] α : Type u_1 inst✝¹ : LinearOrderedRing α inst✝ : Archimedean α a : α ⊢ ⋃ (n : ℤ), Ico (↑n) (↑n + 1) = univ [PROOFSTEP] simpa only [zero_add] using iUnion_Ico_add_int_cast (0 : α) [GOAL] α : Type u_1 inst✝¹ : LinearOrderedRing α inst✝ : Archimedean α a : α ⊢ ⋃ (n : ℤ), Icc (↑n) (↑n + 1) = univ [PROOFSTEP] simpa only [zero_add] using iUnion_Icc_add_int_cast (0 : α)
theory Exe2p6 imports Main begin datatype 'a tree = Tip | Node "'a tree" 'a "'a tree" fun contents :: "'a tree \<Rightarrow> 'a list" where "contents Tip = []" | "contents (Node l n r) = n # (contents l) @ (contents r)" fun sum_tree :: "nat tree \<Rightarrow> nat" where "sum_tree Tip = 0" | "sum_tree (Node l n r) = n + sum_tree l + sum_tree r" lemma sum_tree_lemma_1 : "sum_tree t = sum_list (contents t)" apply(induction t rule: sum_tree.induct) apply(auto) done end
(** * Spécification et Validation de Programmes - Examen Février 2015 Cet examen est un examen sur machine. _Durée_ : 3 heures _Documents_ : tous documents autorisés L'objectif est de répondre directement dans ce fichier et de soumettre ce dernier sur le site du master (cf. instructions données lors de l'examen). Repérez les mots "QUESTION" au fil du texte. _Important_ : le temps de soumission est compris dans les 3 heures, toute soumission tardive est comptée comme copie vide. Dans les réponses, les [admit] ou [Admitted] doivent etre effacés ou commentés sinon aucun point ne sera accordé à la question. Le sujet est à priori à répondre dans l'ordre des questions mais il est possible de laisser un [admit] ou [Admitted] pour passer à la suite en supposant la réponse fournie. La difficulté relative et ressentie par les enseignants pour chaque question est notée de la façon suivante : [+] question facile [++] question non-triviale mais simple [+++] question demandant un peu plus de réflexion [++++] question difficile et/ou prenant du temps *) Require Import Bool. Require Import Arith. (** * Les Ensembles finis en Coq. L'objectif de cet examen est de proposer une formalisation de la notion d'ensemble fini (typé) dans le logiciel Coq. *) Section Ensembles. Variable Elem : Set. (* le type générique des éléménts des ensembles. *) (** * (1) Egalité sur les éléments La notion d'ensemble est dépendante de la notion d'égalité sur leurs éléménts. On fera donc l'hypothèse que l'égalité sur les éléments des ensembles est décidable. *) Hypothesis Elem_eq_dec: forall a b : Elem, { a = b } + { a <> b }. (** Voici quelques définitions et lemmes importants sur cette égalité entre éléments. *) Definition elem_eq (a b : Elem) : bool := match Elem_eq_dec a b with | left _ => true | right _ => false end. Proposition elem_eq_eq: forall a b : Elem, elem_eq a b = true -> a = b. Proof. intros a b H. unfold elem_eq in H. destruct (Elem_eq_dec a b) as [Heq | Hneq]. + (* cas a = b *) exact Heq. + (* cas a <> b *) inversion H. (* contradiction *) Qed. (** ** QUESTION 1.1 [+] : réflexivité de l'égalité Complétez la preuve du lemme suivant : *) Lemma elem_eq_refl: forall a : Elem, elem_eq a a = true. Proof. intro a. unfold elem_eq. destruct (Elem_eq_dec a a) as [Heq | Hneq]. + (* cas a = a *) reflexivity. + (* cas a <> a *) unfold not in Hneq. assert (HFalse: False). { apply Hneq. reflexivity. } elim HFalse. Qed. (** ** QUESTION 1.2 [+] En déduire une démonstration pour la proposition suivante : *) Proposition eq_elem_eq: forall a b : Elem, a = b -> elem_eq a b = true. Proof. intros a b H. subst. rewrite elem_eq_refl. reflexivity. Qed. (** On se donne des propositions complémentaires pour la négation. *) Proposition neq_elem_neq: forall a b : Elem, a <> b -> elem_eq a b = false. Proof. intros a b Hneq. case_eq (elem_eq a b). - (* cas Htrue *) intro Htrue. assert (Heq: a = b). { apply elem_eq_eq. exact Htrue. } contradiction. - (* cas Hfalse *) reflexivity. Qed. Proposition elem_neq_neq: forall a b : Elem, elem_eq a b = false -> a <> b. Proof. intros a b Hfalse. unfold not. intro Heq. rewrite Heq in Hfalse. rewrite elem_eq_refl in Hfalse. inversion Hfalse. Qed. (** * (2) Définition d'ensemble et appartenance La notion d'ensemble fini proposée est assez naive et définie par le type suivant. *) Inductive Ens : Set := | vide : Ens | elem : Elem -> Ens -> Ens. (** On souhaite définir la notion d'appartenance à un ensemble, basée sur la définition précédente. ** QUESTION 2.1 [+] : appartenance fonctionnelle La première définition d'appartenance est un prédicat booléen fonctionnel. Complétez la définition suivante : *) Fixpoint appartient (a:Elem) (E:Ens) : bool := match E with | vide => false | elem e ES => if elem_eq a e then true else appartient a ES end. (** ** QUESTION 2.2 [+] : propriété de l'appartenance Démontrer la propriété suivante (par cas): *) Proposition appartient_elem: forall a b : Elem, forall E : Ens, appartient a E = true -> appartient a (elem b E) = true. Proof. intros a b E H. simpl. destruct (elem_eq a b). +reflexivity. +exact H. Qed. (** On donne maintenant une définition alternative à l'aide d'un type inductif de nom Appartient (avec A majuscule) et implémentant les règles suivantes : - règle : app_debut --------------------------- Appartient a (elem a E) - règle : app_reste Appartient a E -------------------------- Appartient a (elem b E) *) Inductive Appartient : Elem -> Ens -> Prop := | app_debut: forall E : Ens, forall a : Elem, Appartient a (elem a E) | app_reste: forall E : Ens, forall a b : Elem, Appartient a E -> Appartient a (elem b E). (** ** QUESTION 2.3 [+] Montrer la proposition suivante : *) Proposition Appartient_elem: forall a b : Elem, forall E : Ens, Appartient a E -> Appartient a (elem b E). Proof. intros a b E H. apply app_reste. exact H. Qed. (** ** QUESTION 2.4 [+++] : Du récursif à l'inductif Montrer par induction le lemme suivant : *) Lemma appartient_Appartient: forall a : Elem, forall E : Ens, appartient a E = true -> Appartient a E. Proof. intros a E. intros H. induction E as [|v ee]. +inversion H. +apply Appartient_elem. apply IHee. inversion H. destruct (elem_eq a v). -destruct ee. *simpl. simpl in H. Admitted. (** ** QUESTION 2.5 [++] : De l'inductif au récursif Montrer par induction sur le type inductif Appartient le lemme suivant : *) Lemma Appartient_appartient: forall a : Elem, forall E : Ens, Appartient a E -> appartient a E = true. Proof. intros a E. intros H. induction E as [|v ee]. + inversion H. + apply appartient_elem. destruct (appartient a ee). *trivial. *simpl. Admitted. (** ** QUESTION 2.6 [++] En utilisant les deux lemmes précédents, déduire de la proposition Appartient_elem (avec A majuscule) une preuve alternative de la proposition appartient_elem (avec a minuscule). *) Proposition appartient_elem': forall a b : Elem, forall E : Ens, appartient a E = true -> appartient a (elem b E) = true. Proof. intros a b E. rewrite Appartient_appartient. + intros HT. rewrite Appartient_appartient. exact HT. apply Appartient_elem. apply appartient_Appartient. simpl. Admitted. (* <== REMPLACER le Admitted. *) (** * (3) Union ensembliste Dans cette partie nous nous intéressons à l'opérateur d'union ensembliste. Nous donnons la définition fonctionnelle suivante : *) Fixpoint union (E F : Ens) : Ens := match E with | vide => F | elem a E' => elem a (union E' F) end. (** ** QUESTION 3.1 [++] Démontrer le lemme suivant : *) Lemma union_Appartient_l: forall a : Elem, forall E F : Ens, Appartient a E -> Appartient a (union E F). Proof. intros a E F. intros H. induction E as [|e ee]. +simpl. inversion H. +simpl. apply Appartient_elem. destruct (union ee F). -apply IHee. inversion H. Admitted. (* <== REMPLACER LE Admitted. *) (** Le lemme complémentaire : union_Appartient_r qui permet de déduire : Appartient a (union E F) à partir de Appartient a F est plus difficile à démontrer, car l'union effectue la récursion sur E et non sur F. Nous passons en mode "calcul" (en utilisant la définition fonctionnelle de appartient) et nous procédons par étapes. *) (** ** Question 3.2 [++] Démontrer le lemme suivant par induction sur E : *) Proposition union_appartient_elem_r_eq: forall a b : Elem, forall E F : Ens, a = b -> appartient a (union E (elem b F)) = true. Proof. intros a b E F. intros H. induction E as [|e E']. - apply appartient_elem. destruct F. +simpl. admit. +apply appartient_elem. admit. -simpl. rewrite IHE'. destruct (elem_eq a e). +trivial. +trivial. Qed. (** ** Question 3.3 [++] Démontrer le lemme suivant par induction sur E : *) Proposition union_appartient_elem_r: forall a b : Elem, forall E F : Ens, appartient a (union E F) = true -> appartient a (union E (elem b F)) = true. Proof. intros a b E F H. induction E as [|e E']. +apply appartient_elem. simpl. Admitted. (* <== REMPLACER LE Admitted. *) (** ** QUESTION 3.4 [+++] En utilisant les deux propositions précédentes, démontrer par induction sur F la proposition suivante : *) Proposition union_appartient_r: forall a : Elem, forall E F : Ens, appartient a F = true -> appartient a (union E F) = true. Proof. intros a E F. induction F as [|f F']. +intros H. inversion H. + Admitted. (* <== REMPLACER LE Admitted. *) (** ** QUESTION 3.5 [++] En déduire le lemme suivant : *) Lemma union_Appartient_r: forall a : Elem, forall E F : Ens, Appartient a F -> Appartient a (union E F). Proof. Admitted. (* <== REMPLACER LE Admitted. *) (** ** QUESTION 3.6 [++] Finalement, en déduire le théorème de l'union : *) Theorem union_Appartient: forall a : Elem, forall E F : Ens, Appartient a E \/ Appartient a F -> Appartient a (union E F). Proof. Admitted. (* <== REMPLACER LE Admitted. *) (** * (4) Elimination des doublons Dans cette partie, nous souhaitons éliminer les éléments doublons dans les ensembles. *) (** ** QUESTION 4.1 [+] Définir la fonction retirer telle que (retirer a E) élimine toutes les occurrences de l'élément a dans l'ensemble E. *) Fixpoint retirer (a : Elem) (E : Ens) : Ens := vide. (* <== REMPLACER vide PAR UNE DEFINITION RECURSIVE. *) (** ** QUESTION 4.2 [++] Prouver le lemme suivant : *) Lemma retirer_present: forall a : Elem, forall E : Ens, appartient a (retirer a E) = false. Proof. Admitted. (* <== REMPLACER LE Admitted. *) (** ** QUESTION 4.3 [++] Démontrer le lemme suivant : *) Lemma Appartient_retirer_elem: forall a b : Elem, forall E : Ens, b <> a -> Appartient a E -> Appartient a (retirer b E). Proof. Admitted. (* <== REMPLACER LE Admitted. *) (** ** QUESTION 4.4 [+] Donner une définition de la fonction sans_doublons telle que (sans_doublons E) retire tous les éléments répétés dans E. *) Fixpoint sans_doublons (E : Ens) : Ens := vide. (* <== REMPLACER vide PAR UNE DEFINITION RECURSIVE. *) (** ** QUESTION 4.5 [+++] En déduire le théorème suivant : *) Theorem Appartient_sans_doublons: forall a : Elem, forall E : Ens, Appartient a E -> Appartient a (sans_doublons E). Proof. Admitted. (* <== REMPLACER LE Admitted. *) (** * (5) Différence ensembliste Dans cette dernière partie on souhaite formaliser l'opérateur de différence ensembliste. *) (** ** Question 5.1 [++] Définir la fonction difference retournant la différence entre deux ensembles. *) Fixpoint difference (E1 : Ens) (E2 : Ens) : Ens := vide. (* <== REMPLACER vide PAR UNE DEFINITION RECURSIVE. *) (** Notre objectif est de montrer le théorème suivant : Theorem difference_Appartient: forall e : Elem, forall E2 E1 : Ens, Appartient e E2 -> ~ (Appartient e (difference E1 E2)). Cependant, la preuve est non-triviale et nous allons réaliser les étapes nécessaires en passant à la fonction de calcul appartient (avec a minuscule). *) (** ** Question 5.2 [+++] Compléter la preuve du Lemme suivant : *) Lemma nappartient_retirer_elem: forall a b : Elem, forall E : Ens, b <> a -> appartient a E = false -> appartient a (retirer b E) = false. Proof. Admitted. (* <== RETIRER LE Admitted. *) (* <=== DECOMMENTER SINON CELA NE PASSE PAS intros a b E Hneq Happ. induction E as [|e E']. - (* cas E = vide *) simpl. reflexivity. - (* cas E = (elem e E') *) simpl. case_eq (elem_eq b e). + (* cas b = e vrai *) intro Htrue. apply IHE'. admit. (* <== REMPLACER LE admit *) (* etc ... *) + (* cas b = e faux *) intro Hfalse. admit. (* <== REMPLACER LE admit *) (* etc ... *) Qed. DECOMMENTER ===> *) (** ** Question 5.3 [+++] Compléter la preuve du Lemme suivant : *) Lemma difference_appartient_aux: forall e : Elem, forall E2 E1: Ens, appartient e E1 = false -> appartient e (difference E1 E2) = false. Proof. Admitted. (* <== REMPLACER LE Admitted. *) (** ** Question 5.4 [+++] En déduire le lemme ci-dessous : *) Lemma difference_appartient: forall e : Elem, forall E2 E1 : Ens, appartient e E2 = true -> appartient e (difference E1 E2) = false. Proof. Admitted. (* <== REMPLACER LE Admitted. *) (** ** Question 5.5 [++] En déduire notre théorème principal. *) Theorem difference_Appartient: forall e : Elem, forall E2 E1 : Ens, Appartient e E2 -> ~ (Appartient e (difference E1 E2)). Proof. Admitted. (* <== REMPLACER LE Admitted *) (** * (6) Intersection (réponse libre) [+++] Dans cette dernière partie on souhaite formaliser l'opérateur d'intersection entre deux ensembles. En vous inspirant de la partie (3), proposer une formalisation permettant finalement de démontrer le théorème suivant : *) (* A DECOMMENTER ==> Theorem intersection_Appartient: forall a : Elem, forall E F : Ens, Appartient a E /\ Appartient a F -> Appartient a (intersection E F). *)
Require Import Logic.lib.Coqlib. Require Import Logic.GeneralLogic.Base. Require Import Logic.GeneralLogic.KripkeModel. Require Import Logic.GeneralLogic.Semantics.Kripke. Require Import Logic.MinimunLogic.Syntax. Require Import Logic.MinimunLogic.Semantics.Kripke. Require Import Logic.PropositionalLogic.Syntax. Require Import Logic.PropositionalLogic.Semantics.Kripke. Require Import Logic.SeparationLogic.Syntax. Require Import Logic.SeparationLogic.Model.SeparationAlgebra. Require Import Logic.SeparationLogic.Model.OrderedSA. Require Import Logic.SeparationLogic.Semantics.UpwardsSemantics. Local Open Scope logic_base. Local Open Scope syntax. Local Open Scope kripke_model. Import PropositionalLanguageNotation. Import SeparationLogicNotation. Import KripkeModelFamilyNotation. Import KripkeModelNotation_Intuitionistic. Section Sound_Upwards. Context {L: Language} {minL: MinimunLanguage L} {pL: PropositionalLanguage L} {sL: SeparationLanguage L} {MD: Model} {kMD: KripkeModel MD} (M: Kmodel) {R: Relation (Kworlds M)} {po_R: PreOrder Krelation} {J: Join (Kworlds M)} {SA: SeparationAlgebra (Kworlds M)} {dSA: DownwardsClosedSeparationAlgebra (Kworlds M)} {SM: Semantics L MD} {kiSM: KripkeIntuitionisticSemantics L MD M SM} {kminSM: KripkeMinimunSemantics L MD M SM} {kpSM: KripkePropositionalSemantics L MD M SM} {usSM: UpwardsSemantics.SeparatingSemantics L MD M SM}. Lemma sound_sepcon_comm: forall x y: expr, forall m, KRIPKE: M, m |= x * y --> y * x. Proof. intros. rewrite sat_impp; intros. rewrite sat_sepcon in H0 |- *; intros. destruct H0 as [m1 [m2 [? [? ?]]]]. exists m2, m1. split; [| split]; auto. apply join_comm; auto. Qed. Lemma sound_sepcon_assoc: forall x y z: expr, forall m, KRIPKE: M, m |= x * (y * z) <--> (x * y) * z. Proof. intros. unfold iffp. rewrite sat_andp. split; intros. + rewrite sat_impp; intros. rewrite sat_sepcon in H0. destruct H0 as [mx [myz [? [? ?]]]]. rewrite sat_sepcon in H2. destruct H2 as [my [mz [? [? ?]]]]. apply join_comm in H0. apply join_comm in H2. destruct (join_assoc mz my mx myz n H2 H0) as [mxy [? ?]]. apply join_comm in H5. apply join_comm in H6. rewrite sat_sepcon. exists mxy, mz. split; [| split]; auto. rewrite sat_sepcon. exists mx, my. split; [| split]; auto. + rewrite sat_impp; intros. rewrite sat_sepcon in H0. destruct H0 as [mxy [mz [? [? ?]]]]. rewrite sat_sepcon in H1. destruct H1 as [mx [my [? [? ?]]]]. destruct (join_assoc mx my mz mxy n H1 H0) as [myz [? ?]]. rewrite sat_sepcon. exists mx, myz. split; [| split]; auto. rewrite sat_sepcon. exists my, mz. split; [| split]; auto. Qed. Lemma sound_wand_sepcon_adjoint: forall x y z: expr, (forall m, KRIPKE: M, m |= x * y --> z) <-> (forall m, KRIPKE: M, m |= x --> (y -* z)). Proof. intros. split; intro. + assert (ASSU: forall m1 m2 m, join m1 m2 m -> KRIPKE: M, m1 |= x -> KRIPKE: M, m2 |= y -> KRIPKE: M, m |= z). Focus 1. { intros. specialize (H m). rewrite sat_impp in H. apply (H m); [reflexivity |]. rewrite sat_sepcon. exists m1, m2; auto. } Unfocus. clear H. intros. rewrite sat_impp; intros. rewrite sat_wand; intros. apply (ASSU m0 m1 m2); auto. eapply sat_mono; eauto. + assert (ASSU: forall m0 m1 m2 m, m <= m0 -> join m0 m1 m2 -> KRIPKE: M, m |= x -> KRIPKE: M, m1 |= y -> KRIPKE: M, m2 |= z). Focus 1. { intros. specialize (H m). rewrite sat_impp in H. revert m0 m1 m2 H0 H1 H3. rewrite <- sat_wand. apply (H m); [reflexivity | auto]. } Unfocus. intros. rewrite sat_impp; intros. rewrite sat_sepcon in H1. destruct H1 as [m1 [m2 [? [? ?]]]]. apply (ASSU m1 m2 n m1); auto. reflexivity. Qed. Lemma sound_sepcon_mono: forall x1 x2 y1 y2: expr, (forall m, KRIPKE: M, m |= x1 --> x2) -> (forall m, KRIPKE: M, m |= y1 --> y2) -> (forall m, KRIPKE: M, m |= x1 * y1 --> x2 * y2). Proof. intros. assert (ASSUx: forall m, KRIPKE: M, m |= x1 -> KRIPKE: M, m |= x2). Focus 1. { intros. specialize (H m0). rewrite sat_impp in H. apply (H m0); [reflexivity | auto]. } Unfocus. assert (ASSUy: forall m, KRIPKE: M, m |= y1 -> KRIPKE: M, m |= y2). Focus 1. { intros. specialize (H0 m0). rewrite sat_impp in H0. apply (H0 m0); [reflexivity | auto]. } Unfocus. rewrite sat_impp; intros. rewrite sat_sepcon in H2 |- *. destruct H2 as [m1 [m2 [? [? ?]]]]. exists m1, m2; auto. Qed. Lemma sound_sepcon_elim1 {incrSA: IncreasingSeparationAlgebra (Kworlds M)}: forall x y: expr, forall m, KRIPKE: M, m |= x * y --> x. Proof. intros. rewrite sat_impp; intros. rewrite sat_sepcon in H0. destruct H0 as [m1 [m2 [? [? ?]]]]. apply join_comm in H0. apply all_increasing in H0. eapply sat_mono; eauto. Qed. Context {s'L: SeparationEmpLanguage L} {ueSM: UpwardsSemantics.EmpSemantics L MD M SM}. Lemma sound_sepcon_emp {USA': UnitalSeparationAlgebra' (Kworlds M)}: forall x: expr, forall m, KRIPKE: M, m |= x * emp <--> x. Proof. intros. unfold iffp. rewrite sat_andp. split. + rewrite sat_impp; intros. rewrite sat_sepcon in H0. destruct H0 as [n' [u [? [? ?]]]]. rewrite sat_emp in H2. apply join_comm in H0. unfold increasing in H2. specialize (H2 _ ltac:(reflexivity) _ _ H0). eapply sat_mono; eauto. + rewrite sat_impp; intros. rewrite sat_sepcon. destruct (incr'_exists n) as [u [? ?]]. destruct H1 as [n' [H1 H1']]. exists n', u. split; [| split]; auto. - apply join_comm; auto. - eapply sat_mono; eauto. - rewrite sat_emp; eauto. Qed. End Sound_Upwards. (*****************************************) (* For SL extension *) (*****************************************) (* Definition unique_cancel {worlds: Type} {kiM: KripkeIntuitionisticModel worlds} {J: Join worlds} (P: worlds -> Prop): Prop := forall n, (exists n1 n2, P n1 /\ join n1 n2 n) -> (exists n1 n2, P n1 /\ join n1 n2 n /\ forall n1' n2', (P n1' /\ join n1' n2' n) -> n2 <= n2'). Lemma sound_precise_sepcon {L: Language} {nL: NormalLanguage L} {pL: PropositionalLanguage L} {sL: SeparationLanguage L} {MD: Model} {kMD: KripkeModel MD} (M: Kmodel) {R: Relation (Kworlds M)} {po_R: PreOrder Krelation} {J: Join (Kworlds M)} {nSA: SeparationAlgebra (Kworlds M)} {dSA: UpwardsClosedSeparationAlgebra (Kworlds M)} {SM: Semantics L MD} {kiSM: KripkeIntuitionisticSemantics L MD M SM} {usSM: UpwardsSemantics.SeparatingSemantics L MD M SM}: forall x y, unique_cancel (fun m => KRIPKE: M, m |= x) -> unique_cancel (fun m => KRIPKE: M, m |= y) -> unique_cancel (fun m => KRIPKE: M, m |= x * y). Proof. pose proof Korder_PreOrder as H_PreOrder. intros. hnf; intros. destruct H1 as [nxy [n_res [? ?]]]. rewrite sat_sepcon in H1. destruct H1 as [nx [ny [? [? ?]]]]. destruct (join_assoc _ _ _ _ _ H1 H2) as [nyr [? ?]]. destruct (H n (ex_intro _ nx (ex_intro _ nyr (conj H3 H6)))) as [nx' [nyr' [? [? ?]]]]. pose proof H9 _ _ (conj H3 H6). destruct (join_Korder_up _ _ _ _ H5 H10) as [ny' [n_res' [? [? ?]]]]. eapply sat_mono in H4; [| exact H12]. destruct (H0 nyr' (ex_intro _ ny' (ex_intro _ n_res' (conj H4 H11)))) as [ny'' [n_res'' [? [? ?]]]]. clear nx ny nxy n_res nyr H1 H2 H3 ny' n_res' H5 H6 H10 H11 H12 H13 H4. rename nx' into nx, nyr' into nyr, ny'' into ny, n_res'' into nr. destruct (join_assoc _ _ _ _ _ (join_comm _ _ _ H15) (join_comm _ _ _ H8)) as [nxy [? ?]]. apply join_comm in H1. apply join_comm in H2. exists nxy, nr. split; [rewrite sat_sepcon; eauto | split; [auto |]]. clear H7 H8 H14 H15 H1 H2. intros nxy' nr' [? ?]. rewrite sat_sepcon in H1. destruct H1 as [nx' [ny' [? [? ?]]]]. destruct (join_assoc _ _ _ _ _ H1 H2) as [nyr' [? ?]]. specialize (H9 _ _ (conj H3 H6)). destruct (join_Korder_up _ _ _ _ H5 H9) as [ny'' [nr'' [? [? ?]]]]. eapply sat_mono in H4; [| exact H8]. specialize (H16 _ _ (conj H4 H7)). etransitivity; eassumption. Qed. *) (* (* This is over generalization, i.e. the soundness of pure_fact_andp needs extra restriction on models. *) Definition join_inv {worlds: Type} {kiM: KripkeIntuitionisticModel worlds} {J: Join worlds} (P: worlds -> Prop): Prop := (forall n1 n2 n, join n1 n2 n -> P n -> exists n1' n2', join n1' n2' n /\ n1' <= n1 /\ n2' <= n2 /\ P n1') /\ (forall n1 n2 n, join n1 n2 n -> P n1 -> P n). Lemma sound_andp_sepcon {L: Language} {nL: NormalLanguage L} {pL: PropositionalLanguage L} {sL: SeparationLanguage L} {MD: Model} {kMD: KripkeModel MD} (M: Kmodel) {R: Relation (Kworlds M)} {po_R: PreOrder Krelation} {J: Join (Kworlds M)} {nSA: SeparationAlgebra (Kworlds M)} {dSA: UpwardsClosedSeparationAlgebra (Kworlds M)} {SM: Semantics L MD} {kiSM: KripkeIntuitionisticSemantics L MD M SM} {usSM: UpwardsSemantics.SeparatingSemantics L MD M SM}: forall x y z, join_inv (fun m => KRIPKE: M, m |= x) -> forall m, KRIPKE: M, m |= (x && (y * z)) <--> ((x && y) * z). Proof. intros. unfold iffp. rewrite sat_andp, !sat_impp; split; intros ? _ ?; clear m. + rewrite sat_andp in H0; destruct H0. rewrite sat_sepcon in H1; destruct H1 as [ny [nz [? [? ?]]]]. destruct H as [? _]. specialize (H _ _ _ H1 H0). destruct H as [ny' [nz' [? [? [? ?]]]]]. rewrite sat_sepcon; exists ny', nz'. split; [| split]; auto. - rewrite sat_andp; split; auto. eapply sat_mono; eauto. - eapply sat_mono; eauto. + rewrite sat_sepcon in H0; destruct H0 as [ny [nz [? [? ?]]]]. rewrite sat_andp in H1; destruct H1. rewrite sat_andp; split. - destruct H as [_ ?]. apply (H _ _ _ H0 H1). - rewrite sat_sepcon; exists ny, nz. auto. Qed. *)
import Base: == abstract type Message end
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import algebraic_geometry.presheafed_space import category_theory.limits.final import topology.sheaves.stalks /-! # Stalks for presheaved spaces This file lifts constructions of stalks and pushforwards of stalks to work with the category of presheafed spaces. Additionally, we prove that restriction of presheafed spaces does not change the stalks. -/ noncomputable theory universes v u v' u' open category_theory open category_theory.limits category_theory.category category_theory.functor open algebraic_geometry open topological_space open opposite variables {C : Type u} [category.{v} C] [has_colimits C] local attribute [tidy] tactic.op_induction' open Top.presheaf namespace algebraic_geometry.PresheafedSpace /-- The stalk at `x` of a `PresheafedSpace`. -/ abbreviation stalk (X : PresheafedSpace C) (x : X) : C := X.presheaf.stalk x /-- A morphism of presheafed spaces induces a morphism of stalks. -/ def stalk_map {X Y : PresheafedSpace.{v} C} (α : X ⟶ Y) (x : X) : Y.stalk (α.base x) ⟶ X.stalk x := (stalk_functor C (α.base x)).map (α.c) ≫ X.presheaf.stalk_pushforward C α.base x @[simp, elementwise, reassoc] lemma stalk_map_germ {X Y : PresheafedSpace.{v} C} (α : X ⟶ Y) (U : opens Y.carrier) (x : (opens.map α.base).obj U) : Y.presheaf.germ ⟨α.base x, x.2⟩ ≫ stalk_map α ↑x = α.c.app (op U) ≫ X.presheaf.germ x := by rw [stalk_map, stalk_functor_map_germ_assoc, stalk_pushforward_germ] section restrict /-- For an open embedding `f : U ⟶ X` and a point `x : U`, we get an isomorphism between the stalk of `X` at `f x` and the stalk of the restriction of `X` along `f` at t `x`. -/ def restrict_stalk_iso {U : Top} (X : PresheafedSpace.{v} C) {f : U ⟶ (X : Top.{v})} (h : open_embedding f) (x : U) : (X.restrict h).stalk x ≅ X.stalk (f x) := begin -- As a left adjoint, the functor `h.is_open_map.functor_nhds x` is initial. haveI := initial_of_adjunction (h.is_open_map.adjunction_nhds x), -- Typeclass resolution knows that the opposite of an initial functor is final. The result -- follows from the general fact that postcomposing with a final functor doesn't change colimits. exact final.colimit_iso (h.is_open_map.functor_nhds x).op ((open_nhds.inclusion (f x)).op ⋙ X.presheaf), end @[simp, elementwise, reassoc] lemma restrict_stalk_iso_hom_eq_germ {U : Top} (X : PresheafedSpace.{v} C) {f : U ⟶ (X : Top.{v})} (h : open_embedding f) (V : opens U) (x : U) (hx : x ∈ V) : (X.restrict h).presheaf.germ ⟨x, hx⟩ ≫ (restrict_stalk_iso X h x).hom = X.presheaf.germ ⟨f x, show f x ∈ h.is_open_map.functor.obj V, from ⟨x, hx, rfl⟩⟩ := colimit.ι_pre ((open_nhds.inclusion (f x)).op ⋙ X.presheaf) (h.is_open_map.functor_nhds x).op (op ⟨V, hx⟩) @[simp, elementwise, reassoc] lemma restrict_stalk_iso_inv_eq_germ {U : Top} (X : PresheafedSpace.{v} C) {f : U ⟶ (X : Top.{v})} (h : open_embedding f) (V : opens U) (x : U) (hx : x ∈ V) : X.presheaf.germ ⟨f x, show f x ∈ h.is_open_map.functor.obj V, from ⟨x, hx, rfl⟩⟩ ≫ (restrict_stalk_iso X h x).inv = (X.restrict h).presheaf.germ ⟨x, hx⟩ := by rw [← restrict_stalk_iso_hom_eq_germ, category.assoc, iso.hom_inv_id, category.comp_id] lemma restrict_stalk_iso_inv_eq_of_restrict {U : Top} (X : PresheafedSpace.{v} C) {f : U ⟶ (X : Top.{v})} (h : open_embedding f) (x : U) : (X.restrict_stalk_iso h x).inv = stalk_map (X.of_restrict h) x := begin ext V, induction V using opposite.rec, let i : (h.is_open_map.functor_nhds x).obj ((open_nhds.map f x).obj V) ⟶ V := hom_of_le (set.image_preimage_subset f _), erw [iso.comp_inv_eq, colimit.ι_map_assoc, colimit.ι_map_assoc, colimit.ι_pre], simp_rw category.assoc, erw colimit.ι_pre ((open_nhds.inclusion (f x)).op ⋙ X.presheaf) (h.is_open_map.functor_nhds x).op, erw ← X.presheaf.map_comp_assoc, exact (colimit.w ((open_nhds.inclusion (f x)).op ⋙ X.presheaf) i.op).symm, end instance of_restrict_stalk_map_is_iso {U : Top} (X : PresheafedSpace.{v} C) {f : U ⟶ (X : Top.{v})} (h : open_embedding f) (x : U) : is_iso (stalk_map (X.of_restrict h) x) := by { rw ← restrict_stalk_iso_inv_eq_of_restrict, apply_instance } end restrict namespace stalk_map @[simp] lemma id (X : PresheafedSpace.{v} C) (x : X) : stalk_map (𝟙 X) x = 𝟙 (X.stalk x) := begin dsimp [stalk_map], simp only [stalk_pushforward.id], rw [←map_comp], convert (stalk_functor C x).map_id X.presheaf, tidy, end -- TODO understand why this proof is still gross (i.e. requires using `erw`) @[simp] lemma comp {X Y Z : PresheafedSpace.{v} C} (α : X ⟶ Y) (β : Y ⟶ Z) (x : X) : stalk_map (α ≫ β) x = (stalk_map β (α.base x) : Z.stalk (β.base (α.base x)) ⟶ Y.stalk (α.base x)) ≫ (stalk_map α x : Y.stalk (α.base x) ⟶ X.stalk x) := begin dsimp [stalk_map, stalk_functor, stalk_pushforward], ext U, induction U using opposite.rec, cases U, simp only [colimit.ι_map_assoc, colimit.ι_pre_assoc, colimit.ι_pre, whisker_left_app, whisker_right_app, assoc, id_comp, map_id, map_comp], dsimp, simp only [map_id, assoc, pushforward.comp_inv_app], -- FIXME Why doesn't simp do this: erw [category_theory.functor.map_id], erw [category_theory.functor.map_id], erw [id_comp, id_comp], end /-- If `α = β` and `x = x'`, we would like to say that `stalk_map α x = stalk_map β x'`. Unfortunately, this equality is not well-formed, as their types are not _definitionally_ the same. To get a proper congruence lemma, we therefore have to introduce these `eq_to_hom` arrows on either side of the equality. -/ lemma congr {X Y : PresheafedSpace.{v} C} (α β : X ⟶ Y) (h₁ : α = β) (x x': X) (h₂ : x = x') : stalk_map α x ≫ eq_to_hom (show X.stalk x = X.stalk x', by rw h₂) = eq_to_hom (show Y.stalk (α.base x) = Y.stalk (β.base x'), by rw [h₁, h₂]) ≫ stalk_map β x' := stalk_hom_ext _ $ λ U hx, by { subst h₁, subst h₂, simp } lemma congr_hom {X Y : PresheafedSpace.{v} C} (α β : X ⟶ Y) (h : α = β) (x : X) : stalk_map α x = eq_to_hom (show Y.stalk (α.base x) = Y.stalk (β.base x), by rw h) ≫ stalk_map β x := by rw [← stalk_map.congr α β h x x rfl, eq_to_hom_refl, category.comp_id] lemma congr_point {X Y : PresheafedSpace.{v} C} (α : X ⟶ Y) (x x' : X) (h : x = x') : stalk_map α x ≫ eq_to_hom (show X.stalk x = X.stalk x', by rw h) = eq_to_hom (show Y.stalk (α.base x) = Y.stalk (α.base x'), by rw h) ≫ stalk_map α x' := by rw stalk_map.congr α α rfl x x' h instance is_iso {X Y : PresheafedSpace.{v} C} (α : X ⟶ Y) [is_iso α] (x : X) : is_iso (stalk_map α x) := { out := begin let β : Y ⟶ X := category_theory.inv α, have h_eq : (α ≫ β).base x = x, { rw [is_iso.hom_inv_id α, id_base, Top.id_app] }, -- Intuitively, the inverse of the stalk map of `α` at `x` should just be the stalk map of `β` -- at `α x`. Unfortunately, we have a problem with dependent type theory here: Because `x` -- is not *definitionally* equal to `β (α x)`, the map `stalk_map β (α x)` has not the correct -- type for an inverse. -- To get a proper inverse, we need to compose with the `eq_to_hom` arrow -- `X.stalk x ⟶ X.stalk ((α ≫ β).base x)`. refine ⟨eq_to_hom (show X.stalk x = X.stalk ((α ≫ β).base x), by rw h_eq) ≫ (stalk_map β (α.base x) : _), _, _⟩, { rw [← category.assoc, congr_point α x ((α ≫ β).base x) h_eq.symm, category.assoc], erw ← stalk_map.comp β α (α.base x), rw [congr_hom _ _ (is_iso.inv_hom_id α), stalk_map.id, eq_to_hom_trans_assoc, eq_to_hom_refl, category.id_comp] }, { rw [category.assoc, ← stalk_map.comp, congr_hom _ _ (is_iso.hom_inv_id α), stalk_map.id, eq_to_hom_trans_assoc, eq_to_hom_refl, category.id_comp] }, end } /-- An isomorphism between presheafed spaces induces an isomorphism of stalks. -/ def stalk_iso {X Y : PresheafedSpace.{v} C} (α : X ≅ Y) (x : X) : Y.stalk (α.hom.base x) ≅ X.stalk x := as_iso (stalk_map α.hom x) @[simp, reassoc, elementwise] lemma stalk_specializes_stalk_map {X Y : PresheafedSpace.{v} C} (f : X ⟶ Y) {x y : X} (h : x ⤳ y) : Y.presheaf.stalk_specializes (f.base.map_specializes h) ≫ stalk_map f x = stalk_map f y ≫ X.presheaf.stalk_specializes h := by { delta PresheafedSpace.stalk_map, simp [stalk_map] } end stalk_map end algebraic_geometry.PresheafedSpace
function sobolindices( models::Array{<:UQModel}, inputs::Array{<:UQInput}, output::Symbol, sim::AbstractMonteCarlo, ) sim_double_samples = @set sim.n = 2 * sim.n samples = sample(inputs, sim_double_samples) samples = samples[shuffle(1:size(samples, 1)), :] random_names = names(filter(i -> isa(i, RandomUQInput), inputs)) evaluate!(models, samples) A = samples[1:(sim.n), :] B = samples[(sim.n + 1):end, :] fA = A[:, output] fB = B[:, output] fA .-= mean(fA) fB .-= mean(fB) VY = var([fA; fB]) Si = zeros(length(random_names), 2) STi = zeros(length(random_names), 2) for (i, name) in enumerate(random_names) ABi = select(A, Not(name)) ABi[:, name] = B[:, name] for m in models evaluate!(m, ABi) end ABi[:, output] .-= mean(ABi[:, output]) first_order = x -> mean(fB .* (x .- fA)) / VY # Saltelli 2009 total_effect = x -> (1 / (2 * sim.n)) * sum((fA .- x) .^ 2) / VY # Saltelli 2009 # First order effects Si[i, 1] = first_order(ABi[:, output]) bs = bootstrap(first_order, ABi[:, output], BasicSampling(1000)) Si[i, 2] = stderror(bs)[1] # Total effects STi[i, 1] = total_effect(ABi[:, output]) bs = bootstrap(total_effect, ABi[:, output], BasicSampling(1000)) STi[i, 2] = stderror(bs)[1] end indices = DataFrame() indices.Variables = random_names indices.FirstOrder = Si[:, 1] indices.FirstOrderStdError = Si[:, 2] indices.TotalEffect = STi[:, 1] indices.TotalEffectStdError = STi[:, 2] return indices end
dir = joinpath(Pkg.dir("Augmentor"), "test/sampledir") @testset "listfiles" begin lst = Augmentor.listfiles(dir; expand=false, hidden=false, recursive=false) @test typeof(lst) <: Vector{UTF8String} @test length(lst) == 2 lst = Augmentor.listfiles(dir; expand=false, hidden=true, recursive=false) @test typeof(lst) <: Vector{UTF8String} @test length(lst) == 3 lst = Augmentor.listfiles(dir; expand=false, hidden=false, recursive=true) @test typeof(lst) <: Vector{UTF8String} @test length(lst) == 3 lst = Augmentor.listfiles(dir; expand=false, hidden=true, recursive=true) @test typeof(lst) <: Vector{UTF8String} @test length(lst) == 5 lst = Augmentor.listfiles(dir; expand=true, hidden=true, recursive=true) @test typeof(lst) <: Vector{UTF8String} @test length(lst) == 5 end @testset "DirImageSource" begin @test DirImageSource <: ImageSource src = DirImageSource(dir) @test length(src) == 3 @test endof(src) == 3 @test src[end] == src[3] @test eltype(src) <: Image show(src) println() img = rand(src) @test typeof(img) <: Image imgs = rand(src, 2) @test typeof(imgs) <: Vector @test eltype(imgs) <: Image @testset "iterator interface" begin count = 0 for img in src count += 1 @test typeof(img) <: Image end @test count == 3 end end
import classes.unrestricted.basics.lifting import classes.unrestricted.closure_properties.concatenation import utilities.written_by_others.trim_assoc -- new nonterminal type private def nn (N : Type) : Type := N ⊕ fin 3 -- new symbol type private def ns (T N : Type) : Type := symbol T (nn N) variables {T : Type} section specific_symbols private def Z {N : Type} : ns T N := symbol.nonterminal (sum.inr 0) private def H {N : Type} : ns T N := symbol.nonterminal (sum.inr 1) -- denoted by `#` in the pdf private def R {N : Type} : ns T N := symbol.nonterminal (sum.inr 2) private def S {g : grammar T} : ns T g.nt := symbol.nonterminal (sum.inl g.initial) private lemma Z_neq_H {N : Type} : Z ≠ @H T N := begin intro ass, have imposs := sum.inr.inj (symbol.nonterminal.inj ass), exact fin.zero_ne_one imposs, end private lemma Z_neq_R {N : Type} : Z ≠ @R T N := begin intro ass, have imposs := sum.inr.inj (symbol.nonterminal.inj ass), have zero_ne_two : (0 : fin 3) ≠ (2 : fin 3), dec_trivial, exact zero_ne_two imposs, end private lemma H_neq_R {N : Type} : H ≠ @R T N := begin intro ass, have imposs := sum.inr.inj (symbol.nonterminal.inj ass), have one_ne_two : (1 : fin 3) ≠ (2 : fin 3), dec_trivial, exact one_ne_two imposs, end end specific_symbols section construction private def wrap_sym {N : Type} : symbol T N → ns T N | (symbol.terminal t) := symbol.terminal t | (symbol.nonterminal n) := symbol.nonterminal (sum.inl n) private def wrap_gr {N : Type} (r : grule T N) : grule T (nn N) := grule.mk (list.map wrap_sym r.input_L) (sum.inl r.input_N) (list.map wrap_sym r.input_R) (list.map wrap_sym r.output_string) private def rules_that_scan_terminals (g : grammar T) : list (grule T (nn g.nt)) := list.map (λ t, grule.mk [] (sum.inr 2) [symbol.terminal t] [symbol.terminal t, R] ) (all_used_terminals g) -- based on `/informal/KleeneStar.pdf` private def star_grammar (g : grammar T) : grammar T := grammar.mk (nn g.nt) (sum.inr 0) ( grule.mk [] (sum.inr 0) [] [Z, S, H] :: grule.mk [] (sum.inr 0) [] [R, H] :: grule.mk [] (sum.inr 2) [H] [R] :: grule.mk [] (sum.inr 2) [H] [] :: list.map wrap_gr g.rules ++ rules_that_scan_terminals g ) end construction section easy_direction private lemma short_induction {g : grammar T} {w : list (list T)} (ass : ∀ wᵢ ∈ w.reverse, grammar_generates g wᵢ) : grammar_derives (star_grammar g) [Z] (Z :: list.join (list.map (++ [H]) (list.map (list.map symbol.terminal) w.reverse)) ) ∧ ∀ p ∈ w, ∀ t ∈ p, symbol.terminal t ∈ list.join (list.map grule.output_string g.rules) := begin induction w with v x ih, { split, { apply grammar_deri_self, }, { intros p pin, exfalso, exact list.not_mem_nil p pin, }, }, have vx_reverse : (v :: x).reverse = x.reverse ++ [v], { apply list.reverse_cons, }, rw vx_reverse at *, specialize ih (by { intros wᵢ in_reversed, apply ass, apply list.mem_append_left, exact in_reversed, }), specialize ass v (by { apply list.mem_append_right, apply list.mem_singleton_self, }), unfold grammar_generates at ass, split, { apply grammar_deri_of_tran_deri, { use (star_grammar g).rules.nth_le 0 (by dec_trivial), split, { apply list.nth_le_mem, }, use [[], []], split; refl, }, rw [list.nil_append, list.append_nil, list.map_append, list.map_append], change grammar_derives (star_grammar g) [Z, S, H] _, have ih_plus := grammar_deri_with_postfix ([S, H] : list (symbol T (star_grammar g).nt)) ih.left, apply grammar_deri_of_deri_deri ih_plus, have ass_lifted : grammar_derives (star_grammar g) [S] (list.map symbol.terminal v), { clear_except ass, have wrap_eq_lift : @wrap_sym T g.nt = lift_symbol_ sum.inl, { ext, cases x; refl, }, let lifted_g : lifted_grammar_ T := lifted_grammar_.mk g (star_grammar g) sum.inl sum.get_left (by { intros x y hyp, exact sum.inl.inj hyp, }) (by { intros x y hyp, cases x, { cases y, { simp only [sum.get_left] at hyp, left, congr, exact hyp, }, { simp only [sum.get_left] at hyp, exfalso, exact hyp, }, }, { cases y, { simp only [sum.get_left] at hyp, exfalso, exact hyp, }, { right, refl, }, }, }) (by { intro x, refl, }) (by { intros r rin, apply list.mem_cons_of_mem, apply list.mem_cons_of_mem, apply list.mem_cons_of_mem, apply list.mem_cons_of_mem, apply list.mem_append_left, rw list.mem_map, use r, split, { exact rin, }, unfold wrap_gr, unfold lift_rule_, unfold lift_string_, rw wrap_eq_lift, }) (by { rintros r ⟨rin, n, nrn⟩, iterate 4 { cases rin, { exfalso, rw rin at nrn, exact sum.no_confusion nrn, }, }, change r ∈ list.map wrap_gr g.rules ++ rules_that_scan_terminals g at rin, rw list.mem_append at rin, cases rin, { clear_except rin wrap_eq_lift, rw list.mem_map at rin, rcases rin with ⟨r₀, rin₀, r_of_r₀⟩, use r₀, split, { exact rin₀, }, convert r_of_r₀, unfold lift_rule_, unfold wrap_gr, unfold lift_string_, rw wrap_eq_lift, }, { exfalso, unfold rules_that_scan_terminals at rin, rw list.mem_map at rin, rcases rin with ⟨t, tin, r_of_tg⟩, rw ←r_of_tg at nrn, exact sum.no_confusion nrn, }, }), convert_to grammar_derives lifted_g.g [symbol.nonterminal (sum.inl g.initial)] (lift_string_ lifted_g.lift_nt (list.map symbol.terminal v)), { unfold lift_string_, rw list.map_map, congr, }, exact lift_deri_ lifted_g ass, }, have ass_postf := grammar_deri_with_postfix ([H] : list (symbol T (star_grammar g).nt)) ass_lifted, rw list.join_append, rw ←list.cons_append, apply grammar_deri_with_prefix, rw list.map_map, rw list.map_singleton, rw list.join_singleton, change grammar_derives (star_grammar g) [S, H] (list.map symbol.terminal v ++ [H]), convert ass_postf, }, { intros p pin t tin, cases pin, { rw pin at tin, clear pin, have stin : symbol.terminal t ∈ list.map symbol.terminal v, { rw list.mem_map, use t, split, { exact tin, }, { refl, }, }, cases grammar_generates_only_legit_terminals ass stin with rule_exists imposs, { rcases rule_exists with ⟨r, rin, stirn⟩, rw list.mem_join, use r.output_string, split, { rw list.mem_map, use r, split, { exact rin, }, { refl, }, }, { exact stirn, }, }, { exfalso, exact symbol.no_confusion imposs, } }, { exact ih.right p pin t tin, } }, end private lemma terminal_scan_ind {g : grammar T} {w : list (list T)} (n : ℕ) (n_lt_wl : n ≤ w.length) (terminals : ∀ v ∈ w, ∀ t ∈ v, symbol.terminal t ∈ list.join (list.map grule.output_string g.rules)) : grammar_derives (star_grammar g) ((list.map (λ u, list.map symbol.terminal u) (list.take (w.length - n) w)).join ++ [R] ++ (list.map (λ v, [H] ++ list.map symbol.terminal v) (list.drop (w.length - n) w)).join ++ [H]) (list.map symbol.terminal w.join ++ [R, H]) := begin induction n with k ih, { rw nat.sub_zero, rw list.drop_length, rw list.map_nil, rw list.join, rw list.append_nil, rw list.take_length, rw list.map_join, rw list.append_assoc, apply grammar_deri_self, }, specialize ih (nat.le_of_succ_le n_lt_wl), apply grammar_deri_of_deri_deri _ ih, clear ih, have wlk_succ : w.length - k = (w.length - k.succ).succ, { omega, }, have lt_wl : w.length - k.succ < w.length, { omega, }, have split_ldw : list.drop (w.length - k.succ) w = (w.nth (w.length - k.succ)).to_list ++ list.drop (w.length - k) w, { rw wlk_succ, generalize substit : w.length - k.succ = q, rw substit at lt_wl, rw ←list.take_append_drop q w, rw list.nth_append_right, swap, { apply list.length_take_le, }, have eq_q : (list.take q w).length = q, { rw list.length_take, exact min_eq_left_of_lt lt_wl, }, rw eq_q, rw nat.sub_self, have drop_q_succ : list.drop q.succ (list.take q w ++ list.drop q w) = list.drop 1 (list.drop q w), { rw list.drop_drop, rw list.take_append_drop, rw add_comm, }, rw [drop_q_succ, list.drop_left' eq_q, list.drop_drop], rw ←list.take_append_drop (1 + q) w, have q_lt : q < (list.take (1 + q) w).length, { rw list.length_take, exact lt_min (lt_one_add q) lt_wl, }, rw list.drop_append_of_le_length (le_of_lt q_lt), apply congr_arg2, { rw list.nth_append, swap, { rw list.length_drop, exact nat.sub_pos_of_lt q_lt, }, rw list.nth_drop, rw add_zero, rw list.nth_take (lt_one_add q), rw add_comm, rw list_drop_take_succ lt_wl, rw list.nth_le_nth lt_wl, refl, }, { rw list.take_append_drop, }, }, apply grammar_deri_with_postfix, rw [split_ldw, list.map_append, list.join_append, ←list.append_assoc], apply grammar_deri_with_postfix, rw [wlk_succ, list.take_succ, list.map_append, list.join_append, list.append_assoc, list.append_assoc], apply grammar_deri_with_prefix, clear_except terminals lt_wl, specialize terminals (w.nth_le (w.length - k.succ) lt_wl) (list.nth_le_mem w (w.length - k.succ) lt_wl), rw list.nth_le_nth lt_wl, unfold option.to_list, rw [list.map_singleton, list.join_singleton, ←list.map_join, list.join_singleton], apply grammar_deri_of_tran_deri, { use (star_grammar g).rules.nth_le 2 (by dec_trivial), split_ile, use [[], list.map symbol.terminal (w.nth_le (w.length - k.succ) lt_wl)], split; refl, }, rw list.nil_append, have scan_segment : ∀ m : ℕ, m ≤ (w.nth_le (w.length - k.succ) lt_wl).length → grammar_derives (star_grammar g) ([R] ++ list.map symbol.terminal (w.nth_le (w.length - k.succ) lt_wl)) (list.map symbol.terminal (list.take m (w.nth_le (w.length - k.succ) lt_wl)) ++ ([R] ++ list.map symbol.terminal (list.drop m (w.nth_le (w.length - k.succ) lt_wl)))), { intros m small, induction m with n ih, { rw ←list.append_assoc, convert grammar_deri_self, }, apply grammar_deri_of_deri_tran (ih (nat.le_of_succ_le small)), rw nat.succ_le_iff at small, use ⟨[], (sum.inr 2), [symbol.terminal (list.nth_le (w.nth_le (w.length - k.succ) lt_wl) n small)], [symbol.terminal (list.nth_le (w.nth_le (w.length - k.succ) lt_wl) n small), R]⟩, split, { iterate 4 { apply list.mem_cons_of_mem, }, apply list.mem_append_right, unfold rules_that_scan_terminals, rw list.mem_map, use list.nth_le (w.nth_le (w.length - k.succ) lt_wl) n small, split, { unfold all_used_terminals, rw list.mem_filter_map, use (w.nth_le (w.length - k.succ) lt_wl).nth_le n small, split, { apply terminals, apply list.nth_le_mem, }, { refl, }, }, { refl, }, }, use list.map symbol.terminal (list.take n (w.nth_le (w.length - k.succ) lt_wl)), use list.map symbol.terminal (list.drop n.succ (w.nth_le (w.length - k.succ) lt_wl)), dsimp only, split, { trim, rw list.nil_append, rw list.append_assoc, apply congr_arg2, { refl, }, rw ←list.take_append_drop 1 (list.map symbol.terminal (list.drop n (w.nth_le (w.length - k.succ) lt_wl))), apply congr_arg2, { rw ←list.map_take, rw list_take_one_drop, rw list.map_singleton, }, { rw ←list.map_drop, rw list.drop_drop, rw add_comm, }, }, { rw list.take_succ, rw list.map_append, trim, rw list.nth_le_nth small, refl, }, }, convert scan_segment (w.nth_le (w.length - k.succ) lt_wl).length (by refl), { rw list.take_length, }, { rw list.drop_length, rw list.map_nil, refl, }, end private lemma terminal_scan_aux {g : grammar T} {w : list (list T)} (terminals : ∀ v ∈ w, ∀ t ∈ v, symbol.terminal t ∈ list.join (list.map grule.output_string g.rules)) : grammar_derives (star_grammar g) ([R] ++ (list.map (λ v, [H] ++ v) (list.map (list.map symbol.terminal) w)).join ++ [H]) (list.map symbol.terminal w.join ++ [R, H]) := begin rw list.map_map, convert terminal_scan_ind w.length (by refl) terminals, { rw nat.sub_self, rw list.take_zero, refl, }, { rw nat.sub_self, refl, }, end end easy_direction section hard_direction lemma zero_of_not_ge_one {n : ℕ} (not_pos : ¬ (n ≥ 1)) : n = 0 := begin push_neg at not_pos, rwa nat.lt_one_iff at not_pos, end lemma length_ge_one_of_not_nil {α : Type*} {l : list α} (lnn : l ≠ []) : l.length ≥ 1 := begin by_contradiction contra, have llz := zero_of_not_ge_one contra, rw list.length_eq_zero at llz, exact lnn llz, end private lemma nat_eq_tech {a b c : ℕ} (b_lt_c : b < c) (ass : c = a.succ + c - b.succ) : a = b := begin omega, end private lemma wrap_never_outputs_nt_inr {N : Type} {a : symbol T N} (i : fin 3) : wrap_sym a ≠ symbol.nonterminal (sum.inr i) := begin cases a; unfold wrap_sym, { apply symbol.no_confusion, }, intro contr, have inl_eq_inr := symbol.nonterminal.inj contr, exact sum.no_confusion inl_eq_inr, end private lemma wrap_never_outputs_Z {N : Type} {a : symbol T N} : wrap_sym a ≠ Z := begin exact wrap_never_outputs_nt_inr 0, end private lemma wrap_never_outputs_H {N : Type} {a : symbol T N} : wrap_sym a ≠ H := begin exact wrap_never_outputs_nt_inr 1, end private lemma wrap_never_outputs_R {N : Type} {a : symbol T N} : wrap_sym a ≠ R := begin exact wrap_never_outputs_nt_inr 2, end private lemma map_wrap_never_contains_nt_inr {N : Type} {l : list (symbol T N)} (i : fin 3) : symbol.nonterminal (sum.inr i) ∉ list.map wrap_sym l := begin intro contra, rw list.mem_map at contra, rcases contra with ⟨s, -, imposs⟩, exact wrap_never_outputs_nt_inr i imposs, end private lemma map_wrap_never_contains_Z {N : Type} {l : list (symbol T N)} : Z ∉ list.map wrap_sym l := begin exact map_wrap_never_contains_nt_inr 0, end private lemma map_wrap_never_contains_H {N : Type} {l : list (symbol T N)} : H ∉ list.map wrap_sym l := begin exact map_wrap_never_contains_nt_inr 1, end private lemma map_wrap_never_contains_R {N : Type} {l : list (symbol T N)} : R ∉ list.map wrap_sym l := begin exact map_wrap_never_contains_nt_inr 2, end private lemma wrap_sym_inj {N : Type} {a b : symbol T N} (wrap_eq : wrap_sym a = wrap_sym b) : a = b := begin cases a, { cases b, { congr, exact symbol.terminal.inj wrap_eq, }, { exfalso, exact symbol.no_confusion wrap_eq, }, }, { cases b, { exfalso, exact symbol.no_confusion wrap_eq, }, { congr, unfold wrap_sym at wrap_eq, exact sum.inl.inj (symbol.nonterminal.inj wrap_eq), }, }, end private lemma wrap_str_inj {N : Type} {x y : list (symbol T N)} (wrap_eqs : list.map wrap_sym x = list.map wrap_sym y) : x = y := begin ext1, have eqnth := congr_arg (λ l, list.nth l n) wrap_eqs, dsimp only at eqnth, rw list.nth_map at eqnth, rw list.nth_map at eqnth, cases x.nth n with xₙ, { cases y.nth n with yₙ, { refl, }, { exfalso, exact option.no_confusion eqnth, }, }, { cases y.nth n with yₙ, { exfalso, exact option.no_confusion eqnth, }, { congr, apply wrap_sym_inj, rw option.map_some' at eqnth, rw option.map_some' at eqnth, exact option.some.inj eqnth, }, }, end private lemma H_not_in_rule_input {g : grammar T} {r : grule T g.nt} : H ∉ list.map wrap_sym r.input_L ++ [symbol.nonterminal (sum.inl r.input_N)] ++ list.map wrap_sym r.input_R := begin intro contra, rw list.mem_append at contra, cases contra, swap, { exact map_wrap_never_contains_H contra, }, rw list.mem_append at contra, cases contra, { exact map_wrap_never_contains_H contra, }, { rw list.mem_singleton at contra, have imposs := symbol.nonterminal.inj contra, exact sum.no_confusion imposs, }, end private lemma snsri_not_in_join_mpHmmw {g : grammar T} {x : list (list (symbol T g.nt))} {i : fin 3} (snsri_neq_H : symbol.nonterminal (sum.inr i) ≠ @H T g.nt) : symbol.nonterminal (sum.inr i) ∉ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)) := begin intro contra, rw list.mem_join at contra, rw list.map_map at contra, rcases contra with ⟨l, l_in, in_l⟩, rw list.mem_map at l_in, rcases l_in with ⟨y, -, eq_l⟩, rw ←eq_l at in_l, rw function.comp_app at in_l, rw list.mem_append at in_l, cases in_l, { exact map_wrap_never_contains_nt_inr i in_l, }, { rw list.mem_singleton at in_l, exact snsri_neq_H in_l, }, end private lemma Z_not_in_join_mpHmmw {g : grammar T} {x : list (list (symbol T g.nt))} : Z ∉ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)) := begin exact snsri_not_in_join_mpHmmw Z_neq_H, end private lemma R_not_in_join_mpHmmw {g : grammar T} {x : list (list (symbol T g.nt))} : R ∉ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)) := begin exact snsri_not_in_join_mpHmmw H_neq_R.symm, end private lemma zero_Rs_in_the_long_part {g : grammar T} {x : list (list (symbol T g.nt))} [decidable_eq (ns T g.nt)] : list.count_in (list.map (++ [H]) (list.map (list.map wrap_sym) x)).join R = 0 := begin exact list.count_in_zero_of_notin R_not_in_join_mpHmmw, end private lemma cases_1_and_2_and_3a_match_aux {g : grammar T} {r₀ : grule T g.nt} {x : list (list (symbol T g.nt))} {u v : list (ns T g.nt)} (xnn : x ≠ []) (hyp : (list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x))) = u ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ++ v) : ∃ m : ℕ, ∃ u₁ v₁ : list (symbol T g.nt), u = list.join (list.map (++ [H]) (list.take m (list.map (list.map wrap_sym) x))) ++ list.map wrap_sym u₁ ∧ list.nth x m = some (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁) ∧ v = list.map wrap_sym v₁ ++ [H] ++ list.join (list.map (++ [H]) (list.drop m.succ (list.map (list.map wrap_sym) x))) := begin have hypp : (list.map (++ [H]) (list.map (list.map wrap_sym) x)).join = u ++ ( list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ) ++ v, { simpa [list.append_assoc] using hyp, }, have mid_brack : ∀ u', ∀ v', u' ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v' = u' ++ (r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R) ++ v', { intros, simp only [list.append_assoc], }, simp_rw mid_brack, clear hyp mid_brack, classical, have count_Hs := congr_arg (λ l, list.count_in l H) hypp, dsimp only at count_Hs, rw list.count_in_append at count_Hs, rw list.count_in_append at count_Hs, rw list.count_in_zero_of_notin H_not_in_rule_input at count_Hs, rw add_zero at count_Hs, rw [list.count_in_join, list.map_map, list.map_map] at count_Hs, have lens := congr_arg list.length hypp, rw list.length_append_append at lens, rw list.length_append_append at lens, rw list.length_singleton at lens, have ul_lt : u.length < list.length (list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x))), { clear_except lens, linarith, }, rcases list.take_join_of_lt ul_lt with ⟨m, k, mlt, klt, init_ul⟩, have vnn : v ≠ [], { by_contradiction v_nil, rw [v_nil, list.append_nil] at hypp, clear_except hypp xnn, have hlast := congr_arg (λ l : list (ns T g.nt), l.reverse.nth 0) hypp, dsimp only at hlast, rw [list.reverse_join, list.reverse_append, list.reverse_append_append, list.reverse_singleton] at hlast, have hhh : some H = ((list.map wrap_sym r₀.input_R).reverse ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ (list.map wrap_sym r₀.input_L).reverse ++ u.reverse).nth 0, { convert hlast, rw list.map_map, change some H = (list.map (λ l, list.reverse (l ++ [H])) (list.map (list.map wrap_sym) x)).reverse.join.nth 0, simp_rw list.reverse_append, rw list.map_map, change some H = (list.map (λ l, [H].reverse ++ (list.map wrap_sym l).reverse) x).reverse.join.nth 0, rw ←list.map_reverse, have xrnn : x.reverse ≠ [], { intro xr_nil, rw list.reverse_eq_iff at xr_nil, exact xnn xr_nil, }, cases x.reverse with d l, { exfalso, exact xrnn rfl, }, rw [list.map_cons, list.join, list.append_assoc], rw list.nth_append, swap, { rw list.length_reverse, rw list.length_singleton, exact one_pos, }, rw list.reverse_singleton, refl, }, rw ←list.map_reverse at hhh, cases r₀.input_R.reverse, { rw [list.map_nil, list.nil_append] at hhh, simp only [list.nth, list.cons_append] at hhh, exact sum.no_confusion (symbol.nonterminal.inj hhh), }, { simp only [list.nth, list.map_cons, list.cons_append] at hhh, exact wrap_never_outputs_H hhh.symm, }, }, have urrrl_lt : list.length (u ++ ( list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R )) < list.length (list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x))), { have vl_pos : v.length > 0, { exact list.length_pos_of_ne_nil vnn, }, clear_except lens vl_pos, rw list.length_append, rw list.length_append_append, rw list.length_singleton, linarith, }, rcases list.drop_join_of_lt urrrl_lt with ⟨m', k', mlt', klt', last_vl⟩, have mxl : m < x.length, { rw list.length_map at mlt, rw list.length_map at mlt, exact mlt, }, have mxl' : m' < x.length, { rw list.length_map at mlt', rw list.length_map at mlt', exact mlt', }, have mxlmm : m < (list.map (list.map wrap_sym) x).length, { rwa list.length_map, }, have mxlmm' : m' < (list.map (list.map wrap_sym) x).length, { rwa list.length_map, }, use [m, list.take k (x.nth_le m mxl), list.drop k' (x.nth_le m' mxl')], have hyp_u := congr_arg (list.take u.length) hypp, rw list.append_assoc at hyp_u, rw list.take_left at hyp_u, rw init_ul at hyp_u, rw list.nth_le_map at hyp_u, swap, { exact mxlmm, }, rw list.take_append_of_le_length at hyp_u, swap, { rw list.nth_le_map at klt, swap, { exact mxlmm, }, rw list.length_append at klt, rw list.length_singleton at klt, rw list.nth_le_map at klt ⊢, iterate 2 { swap, { exact mxl, }, }, rw list.length_map at klt ⊢, rw nat.lt_succ_iff at klt, exact klt, }, rw ←hyp_u at count_Hs, have hyp_v := congr_arg (list.drop (list.length (u ++ ( list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R )))) hypp, rw list.drop_left at hyp_v, rw last_vl at hyp_v, rw list.nth_le_map at hyp_v, swap, { exact mxlmm', }, rw list.drop_append_of_le_length at hyp_v, swap, { rw list.nth_le_map at klt', swap, { exact mxlmm', }, rw list.length_append at klt', rw list.length_singleton at klt', rw list.nth_le_map at klt' ⊢, iterate 2 { swap, { exact mxl', }, }, rw list.length_map at klt' ⊢, rw nat.lt_succ_iff at klt', exact klt', }, rw ←hyp_v at count_Hs, have mm : m = m', { clear_except count_Hs mxl mxl' klt klt', rw [ list.count_in_append, list.count_in_append, list.map_map, list.count_in_join, ←list.map_take, list.map_map, list.count_in_join, ←list.map_drop, list.map_map ] at count_Hs, change (list.map (λ w, list.count_in (list.map wrap_sym w ++ [H]) H) x).sum = (list.map (λ w, list.count_in (list.map wrap_sym w ++ [H]) H) (list.take m x)).sum + _ + (_ + (list.map (λ w, list.count_in (list.map wrap_sym w ++ [H]) H) (list.drop m'.succ x)).sum) at count_Hs, simp_rw list.count_in_append at count_Hs, have inside_wrap : ∀ y : list (symbol T g.nt), (list.map wrap_sym y).count_in H = 0, { intro, rw list.count_in_zero_of_notin, apply map_wrap_never_contains_H, }, have inside_one : ∀ z : list (symbol T g.nt), (list.map wrap_sym z).count_in (@H T g.nt) + [@H T g.nt].count_in (@H T g.nt) = 1, { intro, rw list.count_in_singleton_eq H, rw inside_wrap, }, simp_rw inside_one at count_Hs, repeat { rw [list.map_const, list.sum_const_nat, one_mul] at count_Hs, }, rw [list.length_take, list.length_drop, list.nth_le_map', list.nth_le_map'] at count_Hs, rw min_eq_left (le_of_lt mxl) at count_Hs, have inside_take : (list.take k (list.map wrap_sym (x.nth_le m mxl))).count_in H = 0, { rw ←list.map_take, rw inside_wrap, }, have inside_drop : (list.drop k' (list.map wrap_sym (x.nth_le m' mxl'))).count_in H + [H].count_in H = 1, { rw ←list.map_drop, rw inside_wrap, rw list.count_in_singleton_eq (@H T g.nt), }, rw [inside_take, inside_drop] at count_Hs, rw [add_zero, ←add_assoc, ←nat.add_sub_assoc] at count_Hs, swap, { rwa nat.succ_le_iff, }, exact nat_eq_tech mxl' count_Hs, }, rw ←mm at *, split, { symmetry, convert hyp_u, { rw list.map_take, }, { rw list.map_take, rw list.nth_le_map, }, }, split, swap, { symmetry, convert hyp_v, { rw list.map_drop, rw list.nth_le_map, }, { rw list.map_drop, rw mm, }, }, rw [←hyp_u, ←hyp_v] at hypp, have mltx : m < x.length, { rw list.length_map at mlt, rw list.length_map at mlt, exact mlt, }, have xxx : x = x.take m ++ [x.nth_le m mltx] ++ x.drop m.succ, { rw list.append_assoc, rw list.singleton_append, rw list.cons_nth_le_drop_succ, rw list.take_append_drop, }, have hyppp : (list.map (++ [H]) (list.map (list.map wrap_sym) (x.take m ++ [x.nth_le m mltx] ++ x.drop m.succ))).join = (list.take m (list.map (++ [H]) (list.map (list.map wrap_sym) x))).join ++ list.take k ((list.map (list.map wrap_sym) x).nth_le m mxlmm) ++ (list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R) ++ (list.drop k' ((list.map (list.map wrap_sym) x).nth_le m mxlmm) ++ [H] ++ (list.drop m.succ (list.map (++ [H]) (list.map (list.map wrap_sym) x))).join), { convert hypp, exact xxx.symm, }, clear_except hyppp mm, rw [ list.map_append_append, list.map_append_append, list.join_append_append, list.append_assoc, list.append_assoc, list.append_assoc, list.append_assoc, list.append_assoc, list.append_assoc, list.map_take, list.map_take, list.append_right_inj, ←list.append_assoc, ←list.append_assoc, ←list.append_assoc, ←list.append_assoc, ←list.append_assoc, list.map_drop, list.map_drop, list.append_left_inj, list.map_singleton, list.map_singleton, list.join_singleton, list.append_left_inj ] at hyppp, rw list.nth_le_nth mltx, apply congr_arg, apply wrap_str_inj, rw hyppp, rw list.map_append_append, rw list.map_take, rw list.nth_le_map, swap, { exact mltx, }, rw list.map_drop, rw list.map_append_append, rw list.map_singleton, rw ←list.append_assoc, rw ←list.append_assoc, apply congr_arg2, { refl, }, congr, exact mm, end private lemma case_1_match_rule {g : grammar T} {r₀ : grule T g.nt} {x : list (list (symbol T g.nt))} {u v : list (ns T g.nt)} (hyp : Z :: (list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x))) = u ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ++ v) : ∃ m : ℕ, ∃ u₁ v₁ : list (symbol T g.nt), u = Z :: list.join (list.map (++ [H]) (list.take m (list.map (list.map wrap_sym) x))) ++ list.map wrap_sym u₁ ∧ list.nth x m = some (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁) ∧ v = list.map wrap_sym v₁ ++ [H] ++ list.join (list.map (++ [H]) (list.drop m.succ (list.map (list.map wrap_sym) x))) := begin by_cases is_x_nil : x = [], { exfalso, rw [is_x_nil, list.map_nil, list.map_nil, list.join] at hyp, have hyp_len := congr_arg list.length hyp, rw list.length_singleton at hyp_len, repeat { rw list.length_append at hyp_len, }, rw list.length_singleton at hyp_len, have left_nil : u ++ list.map wrap_sym r₀.input_L = [], { rw ←list.length_eq_zero, rw list.length_append, omega, }, have right_nil : list.map wrap_sym r₀.input_R ++ v = [], { rw ←list.length_eq_zero, rw list.length_append, omega, }, rw [left_nil, list.nil_append, list.append_assoc, right_nil, list.append_nil] at hyp, have imposs := list.head_eq_of_cons_eq hyp, unfold Z at imposs, rw symbol.nonterminal.inj_eq at imposs, exact sum.no_confusion imposs, }, have unn : u ≠ [], { by_contradiction u_nil, rw [u_nil, list.nil_append] at hyp, cases r₀.input_L with d l, { rw [list.map_nil, list.nil_append] at hyp, have imposs := list.head_eq_of_cons_eq hyp, have inr_eq_inl := symbol.nonterminal.inj imposs, exact sum.no_confusion inr_eq_inl, }, { rw list.map_cons at hyp, have imposs := list.head_eq_of_cons_eq hyp, cases d, { unfold wrap_sym at imposs, exact symbol.no_confusion imposs, }, { unfold wrap_sym at imposs, have inr_eq_inl := symbol.nonterminal.inj imposs, exact sum.no_confusion inr_eq_inl, }, }, }, have hypr := congr_arg list.tail hyp, rw list.tail at hypr, repeat { rw list.append_assoc at hypr, }, rw list.tail_append_of_ne_nil _ _ unn at hypr, repeat { rw ←list.append_assoc at hypr, }, rcases cases_1_and_2_and_3a_match_aux is_x_nil hypr with ⟨m, u₁, v₁, u_eq, xm_eq, v_eq⟩, use [m, u₁, v₁], split, { cases u with d l, { exfalso, exact unn rfl, }, have headZ : d = Z, { repeat { rw list.cons_append at hyp, }, exact list.head_eq_of_cons_eq hyp.symm, }, rw headZ, rw list.tail at u_eq, rw u_eq, apply list.cons_append, }, split, { exact xm_eq, }, { exact v_eq, }, end private lemma star_case_1 {g : grammar T} {α α' : list (ns T g.nt)} (orig : grammar_transforms (star_grammar g) α α') (hyp : ∃ x : list (list (symbol T g.nt)), (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α = [Z] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) : (∃ x : list (list (symbol T g.nt)), (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α' = [Z] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) ∨ (∃ x : list (list (symbol T g.nt)), (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α' = [R, H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) := begin rcases hyp with ⟨x, valid, cat⟩, have no_R_in_alpha : R ∉ α, { intro contr, rw cat at contr, clear_except contr, rw list.mem_append at contr, cases contr, { rw list.mem_singleton at contr, exact Z_neq_R.symm contr, }, { exact R_not_in_join_mpHmmw contr, }, }, rw cat at *, clear cat, rcases orig with ⟨r, rin, u, v, bef, aft⟩, cases rin, { left, rw rin at *, clear rin, dsimp only at *, rw [list.append_nil, list.append_nil] at bef, use ([symbol.nonterminal g.initial] :: x), split, { intros xᵢ xin, cases xin, { rw xin, apply grammar_deri_self, }, { exact valid xᵢ xin, }, }, have u_nil : u = [], { clear_except bef, rw ←list.length_eq_zero, by_contradiction, have ul_pos : 0 < u.length, { rwa pos_iff_ne_zero, }, clear h, have bef_tail := congr_arg list.tail bef, cases u with d l, { rw list.length at ul_pos, exact nat.lt_irrefl 0 ul_pos, }, { have Z_in_tail : Z ∈ l ++ [symbol.nonterminal (sum.inr 0)] ++ v, { apply list.mem_append_left, apply list.mem_append_right, apply list.mem_singleton_self, }, rw [list.singleton_append, list.tail_cons, list.cons_append, list.cons_append, list.tail_cons] at bef_tail, rw ←bef_tail at Z_in_tail, exact Z_not_in_join_mpHmmw Z_in_tail, }, }, have v_rest : v = list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)), { rw u_nil at bef, convert congr_arg list.tail bef.symm, }, rw aft, rw [u_nil, v_rest], rw [list.nil_append, list.map_cons], refl, }, cases rin, { right, rw rin at *, clear rin, dsimp only at *, rw [list.append_nil, list.append_nil] at bef, use x, split, { exact valid, }, have u_nil : u = [], { clear_except bef, rw ←list.length_eq_zero, by_contradiction, have ul_pos : 0 < u.length, { rwa pos_iff_ne_zero, }, clear h, have bef_tail := congr_arg list.tail bef, cases u with d l, { rw list.length at ul_pos, exact nat.lt_irrefl 0 ul_pos, }, { have Z_in_tail : Z ∈ l ++ [symbol.nonterminal (sum.inr 0)] ++ v, { apply list.mem_append_left, apply list.mem_append_right, apply list.mem_singleton_self, }, rw [list.singleton_append, list.tail_cons, list.cons_append, list.cons_append, list.tail_cons] at bef_tail, rw ←bef_tail at Z_in_tail, exact Z_not_in_join_mpHmmw Z_in_tail, }, }, have v_rest : v = list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)), { rw u_nil at bef, convert congr_arg list.tail bef.symm, }, rw aft, rw [u_nil, v_rest], refl, }, iterate 2 { cases rin, { exfalso, apply no_R_in_alpha, rw bef, apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_right, rw list.mem_singleton, rw rin, refl, }, }, have rin' : r ∈ rules_that_scan_terminals g ∨ r ∈ list.map wrap_gr g.rules, { rw or_comm, rwa ←list.mem_append, }, clear rin, cases rin', { exfalso, apply no_R_in_alpha, rw bef, apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_right, rw list.mem_singleton, unfold rules_that_scan_terminals at rin', rw list.mem_map at rin', rcases rin' with ⟨t, -, form⟩, rw ←form, refl, }, left, rw list.mem_map at rin', rcases rin' with ⟨r₀, orig_in, wrap_orig⟩, unfold wrap_gr at wrap_orig, rw ←wrap_orig at *, clear wrap_orig, dsimp only at *, rcases case_1_match_rule bef with ⟨m, u₁, v₁, u_eq, xm_eq, v_eq⟩, clear bef, rw [u_eq, v_eq] at aft, use (list.take m x ++ [u₁ ++ r₀.output_string ++ v₁] ++ list.drop m.succ x), split, { intros xᵢ xiin, rw list.mem_append_append at xiin, cases xiin, { apply valid, exact list.mem_of_mem_take xiin, }, cases xiin, swap, { apply valid, exact list.mem_of_mem_drop xiin, }, rw list.mem_singleton at xiin, rw xiin, have last_step : grammar_transforms g (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁) (u₁ ++ r₀.output_string ++ v₁), { use r₀, split, { exact orig_in, }, use [u₁, v₁], split; refl, }, apply grammar_deri_of_deri_tran _ last_step, apply valid (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁), exact list.nth_mem xm_eq, }, rw list.singleton_append, rw aft, repeat { rw list.cons_append, }, apply congr_arg2, { refl, }, repeat { rw list.map_append, }, rw list.join_append_append, repeat { rw list.append_assoc, }, apply congr_arg2, { rw ←list.map_take, }, repeat { rw ←list.append_assoc, }, apply congr_arg2, swap, { rw ←list.map_drop, }, rw [ list.map_singleton, list.map_singleton, list.join_singleton, list.map_append, list.map_append ], end private lemma uv_nil_of_RH_eq {g : grammar T} {u v : list (ns T g.nt)} (ass : [R, H] = u ++ [] ++ [symbol.nonterminal (sum.inr 2)] ++ [H] ++ v) : u = [] ∧ v = [] := begin rw list.append_nil at ass, have lens := congr_arg list.length ass, simp only [list.length_append, list.length, zero_add] at lens, split; { rw ←list.length_eq_zero, omega, }, end private lemma u_nil_when_RH {g : grammar T} {x : list (list (symbol T g.nt))} {u v : list (ns T g.nt)} (ass : [R, H] ++ (list.map (++ [H]) (list.map (list.map wrap_sym) x)).join = u ++ [] ++ [symbol.nonterminal (sum.inr 2)] ++ [H] ++ v ) : u = [] := begin cases u with d l, { refl, }, rw list.append_nil at ass, exfalso, by_cases d = R, { rw h at ass, clear h, classical, have imposs, { dsimp_result { exact congr_arg (λ c : list (ns T g.nt), list.count_in c R) ass } }, repeat { rw list.count_in_append at imposs, }, repeat { rw list.count_in_cons at imposs, }, repeat { rw list.count_in_nil at imposs, }, have one_imposs : 1 + (0 + 0) + 0 = 1 + list.count_in l R + (1 + 0) + (0 + 0) + list.count_in v R, { convert imposs, { norm_num, }, { simp [H_neq_R], }, { symmetry, apply zero_Rs_in_the_long_part, }, { norm_num, }, { simp [R], }, { simp [H_neq_R], }, }, clear_except one_imposs, repeat { rw add_zero at one_imposs, }, linarith, }, { apply h, clear h, have impos := congr_fun (congr_arg list.nth ass) 0, iterate 4 { rw list.nth_append at impos, swap, { norm_num, }, }, rw list.nth at impos, rw list.nth at impos, exact (option.some.inj impos).symm, }, end private lemma case_2_match_rule {g : grammar T} {r₀ : grule T g.nt} {x : list (list (symbol T g.nt))} {u v : list (ns T g.nt)} (hyp : R :: H :: (list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x))) = u ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ++ v) : ∃ m : ℕ, ∃ u₁ v₁ : list (symbol T g.nt), u = R :: H :: list.join (list.map (++ [H]) (list.take m (list.map (list.map wrap_sym) x))) ++ list.map wrap_sym u₁ ∧ list.nth x m = some (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁) ∧ v = list.map wrap_sym v₁ ++ [H] ++ list.join (list.map (++ [H]) (list.drop m.succ (list.map (list.map wrap_sym) x))) := begin by_cases is_x_nil : x = [], { exfalso, rw [is_x_nil, list.map_nil, list.map_nil, list.join] at hyp, have imposs : symbol.nonterminal (sum.inl r₀.input_N) = R ∨ symbol.nonterminal (sum.inl r₀.input_N) = H, { simpa using congr_arg (λ l, symbol.nonterminal (sum.inl r₀.input_N) ∈ l) hyp, }, cases imposs; exact sum.no_confusion (symbol.nonterminal.inj imposs), }, have unn : u ≠ [], { by_contradiction u_nil, rw [u_nil, list.nil_append] at hyp, cases r₀.input_L with d l, { rw [list.map_nil, list.nil_append] at hyp, have imposs := list.head_eq_of_cons_eq hyp, have inr_eq_inl := symbol.nonterminal.inj imposs, exact sum.no_confusion inr_eq_inl, }, { rw list.map_cons at hyp, have imposs := list.head_eq_of_cons_eq hyp, cases d, { unfold wrap_sym at imposs, exact symbol.no_confusion imposs, }, { unfold wrap_sym at imposs, have inr_eq_inl := symbol.nonterminal.inj imposs, exact sum.no_confusion inr_eq_inl, }, }, }, have hypt := congr_arg list.tail hyp, rw list.tail at hypt, repeat { rw list.append_assoc at hypt, }, rw list.tail_append_of_ne_nil _ _ unn at hypt, have utnn : u.tail ≠ [], { by_contradiction ut_nil, rw [ut_nil, list.nil_append] at hypt, cases r₀.input_L with d l, { rw [list.map_nil, list.nil_append] at hypt, have imposs := list.head_eq_of_cons_eq hypt, have inr_eq_inl := symbol.nonterminal.inj imposs, exact sum.no_confusion inr_eq_inl, }, { rw list.map_cons at hypt, have imposs := list.head_eq_of_cons_eq hypt, cases d, { unfold wrap_sym at imposs, exact symbol.no_confusion imposs, }, { unfold wrap_sym at imposs, have inr_eq_inl := symbol.nonterminal.inj imposs, exact sum.no_confusion inr_eq_inl, }, }, }, have hyptt := congr_arg list.tail hypt, rw list.tail at hyptt, rw list.tail_append_of_ne_nil _ _ utnn at hyptt, repeat { rw ←list.append_assoc at hyptt, }, rcases cases_1_and_2_and_3a_match_aux is_x_nil hyptt with ⟨m, u₁, v₁, u_eq, xm_eq, v_eq⟩, use [m, u₁, v₁], split, { cases u with d l, { exfalso, exact unn rfl, }, have headR : d = R, { repeat { rw list.cons_append at hyp, }, exact list.head_eq_of_cons_eq hyp.symm, }, rw list.tail at u_eq, rw list.tail at hypt, cases l with d' l', { exfalso, exact utnn rfl, }, have tailHead : d' = H, { repeat { rw list.cons_append at hypt, }, exact list.head_eq_of_cons_eq hypt.symm, }, rw list.tail at u_eq, rw [headR, tailHead, u_eq, list.cons_append, list.cons_append], }, split, { exact xm_eq, }, { exact v_eq, }, end private lemma star_case_2 {g : grammar T} {α α' : list (symbol T (star_grammar g).nt)} (orig : grammar_transforms (star_grammar g) α α') (hyp : ∃ x : list (list (symbol T g.nt)), (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α = [R, H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) : (∃ x : list (list (symbol T g.nt)), (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α' = [R, H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) ∨ (∃ w : list (list T), ∃ β : list T, ∃ γ : list (symbol T g.nt), ∃ x : list (list (symbol T g.nt)), (∀ wᵢ ∈ w, grammar_generates g wᵢ) ∧ (grammar_derives g [symbol.nonterminal g.initial] (list.map symbol.terminal β ++ γ)) ∧ (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α' = list.map symbol.terminal (list.join w) ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) ∨ (∃ u : list T, u ∈ language.star (grammar_language g) ∧ α' = list.map symbol.terminal u) ∨ (∃ σ : list (symbol T g.nt), α' = list.map wrap_sym σ ++ [R]) ∨ (∃ ω : list (ns T g.nt), α' = ω ++ [H]) ∧ Z ∉ α' ∧ R ∉ α' := begin rcases hyp with ⟨x, valid, cat⟩, have no_Z_in_alpha : Z ∉ α, { intro contr, rw cat at contr, clear_except contr, rw list.mem_append at contr, cases contr, { cases contr, { exact Z_neq_R contr, }, { apply Z_neq_H, rw ←list.mem_singleton, exact contr, }, }, { exact Z_not_in_join_mpHmmw contr, }, }, rw cat at *, clear cat, rcases orig with ⟨r, rin, u, v, bef, aft⟩, iterate 2 { cases rin, { exfalso, apply no_Z_in_alpha, rw bef, apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_right, rw list.mem_singleton, rw rin, refl, }, }, cases rin, { cases x with x₀ L, { right, right, right, rw [list.map_nil, list.map_nil, list.join, list.append_nil] at bef, have empty_string : u = [] ∧ v = [], { rw rin at bef, exact uv_nil_of_RH_eq bef, }, rw [empty_string.left, list.nil_append, empty_string.right, list.append_nil] at aft, use list.nil, rw aft, rw [list.map_nil, list.nil_append], rw rin, }, { right, left, use [[], [], x₀, L], split, { intros wᵢ wiin, exfalso, rw list.mem_nil_iff at wiin, exact wiin, }, split, { rw [list.map_nil, list.nil_append], exact valid x₀ (list.mem_cons_self x₀ L), }, split, { intros xᵢ xiin, exact valid xᵢ (list.mem_cons_of_mem x₀ xiin), }, rw aft, rw [list.map_nil, list.append_nil, list.join, list.map_nil, list.nil_append], rw rin at bef ⊢, dsimp only at bef ⊢, have u_nil := u_nil_when_RH bef, rw [u_nil, list.nil_append] at bef ⊢, have eq_v := list.append_inj_right bef (by refl), rw ←eq_v, rw [list.map_cons, list.map_cons, list.join], rw [←list.append_assoc, ←list.append_assoc], }, }, cases rin, { cases x with x₀ L, { right, right, left, rw [list.map_nil, list.map_nil, list.join, list.append_nil] at bef, have empty_string : u = [] ∧ v = [], { rw rin at bef, exact uv_nil_of_RH_eq bef, }, rw [empty_string.left, list.nil_append, empty_string.right, list.append_nil] at aft, use list.nil, split, { use list.nil, split, { refl, }, { intros y imposs, exfalso, exact list.not_mem_nil y imposs, }, }, { rw aft, rw list.map_nil, rw rin, }, }, { right, right, right, right, rw rin at bef, dsimp only at bef, have u_nil := u_nil_when_RH bef, rw [u_nil, list.nil_append] at bef, have v_eq := eq.symm (list.append_inj_right bef (by refl)), rw [ u_nil, list.nil_append, v_eq, rin, list.nil_append, list.map_cons, list.map_cons, list.join, list.append_assoc, list.append_join_append, ←list.append_assoc ] at aft, split, { use list.map wrap_sym x₀ ++ (list.map (λ l, [H] ++ l) (list.map (list.map wrap_sym) L)).join, rw aft, trim, }, rw [list.append_assoc, ←list.append_join_append] at aft, rw aft, split; intro contra; rw list.mem_append at contra, { cases contra, { exact map_wrap_never_contains_Z contra, }, cases contra, { exact Z_neq_H contra, }, { exact Z_not_in_join_mpHmmw contra, }, }, { cases contra, { exact map_wrap_never_contains_R contra, }, cases contra, { exact H_neq_R contra.symm, }, { exact R_not_in_join_mpHmmw contra, }, }, }, }, have rin' : r ∈ rules_that_scan_terminals g ∨ r ∈ list.map wrap_gr g.rules, { rw or_comm, rwa ←list.mem_append, }, clear rin, cases rin', { exfalso, unfold rules_that_scan_terminals at rin', rw list.mem_map at rin', rcases rin' with ⟨t, -, form⟩, rw ←form at bef, dsimp only at bef, rw list.append_nil at bef, have u_nil : u = [], { cases u with d l, { refl, }, exfalso, repeat { rw list.cons_append at bef, }, rw list.nil_append at bef, have btail := list.tail_eq_of_cons_eq bef, have imposs := congr_arg (λ l, R ∈ l) btail, dsimp only at imposs, apply false_of_true_eq_false, convert imposs.symm, { rw [eq_iff_iff, true_iff], apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_right, apply list.mem_singleton_self, }, { rw [eq_iff_iff, false_iff], intro hyp, rw list.mem_cons_iff at hyp, cases hyp, { exact H_neq_R hyp.symm, }, rw list.mem_join at hyp, rcases hyp with ⟨p, pin, Rinp⟩, rw list.mem_map at pin, rcases pin with ⟨q, qin, eq_p⟩, rw ←eq_p at Rinp, rw list.mem_append at Rinp, cases Rinp, { rw list.mem_map at qin, rcases qin with ⟨p', -, eq_q⟩, rw ←eq_q at Rinp, exact map_wrap_never_contains_R Rinp, }, { rw list.mem_singleton at Rinp, exact H_neq_R Rinp.symm, }, }, }, rw [u_nil, list.nil_append] at bef, have second_symbol := congr_fun (congr_arg list.nth bef) 1, rw list.nth_append at second_symbol, swap, { rw [list.length_cons, list.length_singleton], exact lt_add_one 1, }, rw list.nth_append at second_symbol, swap, { rw [list.length_append, list.length_singleton, list.length_singleton], exact lt_add_one 1, }, rw list.singleton_append at second_symbol, repeat { rw list.nth at second_symbol, }, exact symbol.no_confusion (option.some.inj second_symbol), }, left, rw list.mem_map at rin', rcases rin' with ⟨r₀, orig_in, wrap_orig⟩, unfold wrap_gr at wrap_orig, rw ←wrap_orig at *, clear wrap_orig, dsimp only at bef, rcases case_2_match_rule bef with ⟨m, u₁, v₁, u_eq, xm_eq, v_eq⟩, clear bef, rw [u_eq, v_eq] at aft, use (list.take m x ++ [u₁ ++ r₀.output_string ++ v₁] ++ list.drop m.succ x), split, { intros xᵢ xiin, rw list.mem_append_append at xiin, cases xiin, { apply valid, exact list.mem_of_mem_take xiin, }, cases xiin, swap, { apply valid, exact list.mem_of_mem_drop xiin, }, rw list.mem_singleton at xiin, rw xiin, have last_step : grammar_transforms g (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁) (u₁ ++ r₀.output_string ++ v₁), { use r₀, split, { exact orig_in, }, use [u₁, v₁], split; refl, }, apply grammar_deri_of_deri_tran _ last_step, apply valid (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁), exact list.nth_mem xm_eq, }, rw aft, repeat { rw list.cons_append, }, apply congr_arg2, { refl, }, repeat { rw list.map_append, }, rw list.join_append_append, repeat { rw list.append_assoc, }, apply congr_arg2, { refl, }, rw list.nil_append, apply congr_arg2, { rw ←list.map_take, refl, }, simp [list.map, list.join, list.singleton_append, list.map_append, list.append_assoc, list.map_map, list.map_drop], end private lemma case_3_ni_wb {g : grammar T} {w : list (list T)} {β : list T} {i : fin 3} : @symbol.nonterminal T (nn g.nt) (sum.inr i) ∉ list.map (@symbol.terminal T (nn g.nt)) w.join ++ list.map (@symbol.terminal T (nn g.nt)) β := begin intro contra, rw list.mem_append at contra, cases contra; { rw list.mem_map at contra, rcases contra with ⟨t, -, imposs⟩, exact symbol.no_confusion imposs, }, end private lemma case_3_ni_u {g : grammar T} {w : list (list T)} {β : list T} {γ : list (symbol T g.nt)} {x : list (list (symbol T g.nt))} {u v : list (ns T g.nt)} {s : ns T g.nt} (ass : list.map symbol.terminal w.join ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym γ ++ [H] ++ (list.map (++ [H]) (list.map (list.map wrap_sym) x)).join = u ++ [R] ++ [s] ++ v ) : R ∉ u := begin intro R_in_u, classical, have count_R := congr_arg (λ l, list.count_in l R) ass, dsimp only at count_R, repeat { rw list.count_in_append at count_R, }, have R_ni_wb : R ∉ list.map symbol.terminal w.join ++ list.map symbol.terminal β, { apply @case_3_ni_wb T g, }, rw list.count_in_singleton_eq at count_R, rw [list.count_in_singleton_neq H_neq_R, add_zero] at count_R, rw ←list.count_in_append at count_R, rw [list.count_in_zero_of_notin R_ni_wb, zero_add] at count_R, rw [list.count_in_zero_of_notin map_wrap_never_contains_R, add_zero] at count_R, rw [zero_Rs_in_the_long_part, add_zero] at count_R, have ucR_pos := list.count_in_pos_of_in R_in_u, clear_except count_R ucR_pos, linarith, end private lemma case_3_u_eq_left_side {g : grammar T} {w : list (list T)} {β : list T} {γ : list (symbol T g.nt)} {x : list (list (symbol T g.nt))} {u v : list (ns T g.nt)} {s : ns T g.nt} (ass : list.map symbol.terminal w.join ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)) = u ++ [symbol.nonterminal (sum.inr 2)] ++ [s] ++ v ) : u = list.map symbol.terminal w.join ++ list.map (@symbol.terminal T (nn g.nt)) β := begin have R_ni_u : R ∉ u, { exact case_3_ni_u ass, }, have R_ni_wb : R ∉ list.map symbol.terminal w.join ++ list.map symbol.terminal β, { apply @case_3_ni_wb T g, }, repeat { rw list.append_assoc at ass, }, convert congr_arg (list.take u.length) ass.symm, { rw list.take_left, }, rw ←list.append_assoc, rw list.take_left', { classical, have index_of_first_R := congr_arg (list.index_of R) ass, rw list.index_of_append_of_notin R_ni_u at index_of_first_R, rw @list.singleton_append _ _ ([s] ++ v) at index_of_first_R, rw [←R, list.index_of_cons_self, add_zero] at index_of_first_R, rw [←list.append_assoc, list.index_of_append_of_notin R_ni_wb] at index_of_first_R, rw [list.singleton_append, list.index_of_cons_self, add_zero] at index_of_first_R, exact index_of_first_R, }, end private lemma case_3_gamma_nil {g : grammar T} {w : list (list T)} {β : list T} {γ : list (symbol T g.nt)} {x : list (list (symbol T g.nt))} {u v : list (ns T g.nt)} (ass : list.map symbol.terminal w.join ++ list.map symbol.terminal β ++ [symbol.nonterminal (sum.inr 2)] ++ list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)) = u ++ [symbol.nonterminal (sum.inr 2)] ++ [H] ++ v ) : γ = [] := begin have R_ni_wb : R ∉ list.map symbol.terminal w.join ++ list.map symbol.terminal β, { apply @case_3_ni_wb T g, }, have H_ni_wb : H ∉ list.map symbol.terminal w.join ++ list.map symbol.terminal β, { apply @case_3_ni_wb T g, }, have H_ni_wbrg : H ∉ list.map (@symbol.terminal T (nn g.nt)) w.join ++ list.map symbol.terminal β ++ [symbol.nonterminal (sum.inr 2)] ++ list.map wrap_sym γ, { intro contra, rw list.mem_append at contra, cases contra, swap, { exact map_wrap_never_contains_H contra, }, rw list.mem_append at contra, cases contra, { exact H_ni_wb contra, }, { rw list.mem_singleton at contra, exact H_neq_R contra, }, }, have R_ni_u : @symbol.nonterminal T (nn g.nt) (sum.inr 2) ∉ u, { exact case_3_ni_u ass, }, have H_ni_u : H ∉ u, { rw case_3_u_eq_left_side ass, exact H_ni_wb, }, classical, have first_R := congr_arg (list.index_of R) ass, have first_H := congr_arg (list.index_of H) ass, repeat { rw list.append_assoc (list.map symbol.terminal w.join ++ list.map symbol.terminal β) at first_R, }, rw list.append_assoc (list.map symbol.terminal w.join ++ list.map symbol.terminal β ++ [symbol.nonterminal (sum.inr 2)] ++ list.map wrap_sym γ) at first_H, rw list.index_of_append_of_notin R_ni_wb at first_R, rw list.index_of_append_of_notin H_ni_wbrg at first_H, rw [list.cons_append, list.cons_append, list.cons_append, R, list.index_of_cons_self, add_zero] at first_R, rw [list.cons_append, list.index_of_cons_self, add_zero] at first_H, rw [list.append_assoc u, list.append_assoc u] at first_R first_H, rw list.index_of_append_of_notin R_ni_u at first_R, rw list.index_of_append_of_notin H_ni_u at first_H, rw [list.append_assoc _ [H], list.singleton_append, list.index_of_cons_self, add_zero] at first_R, rw [list.append_assoc _ [H], list.singleton_append, ←R, list.index_of_cons_ne _ H_neq_R] at first_H, rw [list.singleton_append, H, list.index_of_cons_self] at first_H, rw ←first_R at first_H, clear_except first_H, repeat { rw list.length_append at first_H, }, rw list.length_singleton at first_H, rw ←add_zero ((list.map symbol.terminal w.join).length + (list.map symbol.terminal β).length + 1) at first_H, rw add_right_inj at first_H, rw list.length_map at first_H, rw list.length_eq_zero at first_H, exact first_H, end private lemma case_3_v_nil {g : grammar T} {w : list (list T)} {β : list T} {u v : list (ns T g.nt)} (ass : list.map symbol.terminal w.join ++ list.map symbol.terminal β ++ [R] ++ [H] = u ++ [symbol.nonterminal (sum.inr 2)] ++ [H] ++ v ) : v = [] := begin have rev := congr_arg list.reverse ass, repeat { rw list.reverse_append at rev, }, repeat { rw list.reverse_singleton at rev, }, rw ←list.reverse_eq_nil, cases v.reverse with d l, { refl, }, exfalso, rw list.singleton_append at rev, have brt := list.tail_eq_of_cons_eq rev, have brtt := congr_arg list.tail brt, rw list.singleton_append at brtt, rw list.tail_cons at brtt, cases l with e l', { change (list.map symbol.terminal β).reverse ++ (list.map symbol.terminal w.join).reverse = [symbol.nonterminal (sum.inr 2)] ++ u.reverse at brtt, have imposs := congr_arg (λ a, R ∈ a) brtt, dsimp only at imposs, apply false_of_true_eq_false, convert imposs.symm, { rw [eq_iff_iff, true_iff], apply list.mem_append_left, apply list.mem_singleton_self, }, { rw [eq_iff_iff, false_iff], rw list.mem_append, push_neg, split; { rw list.mem_reverse, rw list.mem_map, push_neg, intros t trash, apply symbol.no_confusion, }, }, }, { change _ = _ ++ _ at brtt, have imposs := congr_arg (λ a, H ∈ a) brtt, dsimp only at imposs, apply false_of_true_eq_false, convert imposs.symm, { rw [eq_iff_iff, true_iff], apply list.mem_append_right, apply list.mem_append_left, apply list.mem_singleton_self, }, { rw [eq_iff_iff, false_iff], rw list.mem_append, push_neg, split; { rw list.mem_reverse, rw list.mem_map, push_neg, intros t trash, apply symbol.no_confusion, }, }, }, end private lemma case_3_false_of_wbr_eq_urz {g : grammar T} {r₀ : grule T g.nt} {w : list (list T)} {β : list T} {u z : list (ns T g.nt)} (contradictory_equality : list.map symbol.terminal w.join ++ list.map symbol.terminal β ++ [R] = u ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ z) : false := begin apply false_of_true_eq_false, convert congr_arg ((∈) (symbol.nonterminal (sum.inl r₀.input_N))) contradictory_equality.symm, { rw [eq_iff_iff, true_iff], apply list.mem_append_left, apply list.mem_append_right, apply list.mem_singleton_self, }, { rw [eq_iff_iff, false_iff], intro hyp_N_in, rw list.mem_append at hyp_N_in, cases hyp_N_in, swap, { rw list.mem_singleton at hyp_N_in, exact sum.no_confusion (symbol.nonterminal.inj hyp_N_in), }, rw list.mem_append at hyp_N_in, cases hyp_N_in; { rw list.mem_map at hyp_N_in, rcases hyp_N_in with ⟨t, -, impos⟩, exact symbol.no_confusion impos, }, }, end private lemma case_3_match_rule {g : grammar T} {r₀ : grule T g.nt} {x : list (list (symbol T g.nt))} {u v : list (ns T g.nt)} {w : list (list T)} {β : list T} {γ : list (symbol T g.nt)} (hyp : list.map symbol.terminal (list.join w) ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)) = u ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ++ v) : (∃ m : ℕ, ∃ u₁ v₁ : list (symbol T g.nt), u = list.map symbol.terminal (list.join w) ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.take m (list.map (list.map wrap_sym) x))) ++ list.map wrap_sym u₁ ∧ list.nth x m = some (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁) ∧ v = list.map wrap_sym v₁ ++ [H] ++ list.join (list.map (++ [H]) (list.drop m.succ (list.map (list.map wrap_sym) x)))) ∨ (∃ u₁ v₁ : list (symbol T g.nt), u = list.map symbol.terminal (list.join w) ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym u₁ ∧ γ = u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁ ∧ v = list.map wrap_sym v₁ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x))) := begin repeat { rw list.append_assoc u at hyp, }, rw list.append_eq_append_iff at hyp, cases hyp, { rcases hyp with ⟨u', u_eq, xj_eq⟩, left, repeat { rw ←list.append_assoc at xj_eq, }, by_cases is_x_nil : x = [], { exfalso, rw [is_x_nil, list.map_nil, list.map_nil, list.join] at xj_eq, have imposs := congr_arg list.length xj_eq, rw list.length at imposs, rw list.length_append_append at imposs, rw list.length_append_append at imposs, rw list.length_singleton at imposs, clear_except imposs, linarith, }, rcases cases_1_and_2_and_3a_match_aux is_x_nil xj_eq with ⟨m, u₁, v₁, u'_eq, xm_eq, v_eq⟩, use [m, u₁, v₁], split, { rw u_eq, rw u'_eq, rw ←list.append_assoc, }, split, { exact xm_eq, }, { exact v_eq, }, }, { rcases hyp with ⟨v', left_half, right_half⟩, have very_middle : [symbol.nonterminal (sum.inl r₀.input_N)] = list.map wrap_sym [symbol.nonterminal r₀.input_N], { rw list.map_singleton, refl, }, cases x with x₀ xₗ, { rw [list.map_nil, list.map_nil, list.join, list.append_nil] at right_half, rw ←right_half at left_half, have backwards := congr_arg list.reverse left_half, clear right_half left_half, right, repeat { rw list.reverse_append at backwards, }, rw [list.reverse_singleton, list.singleton_append] at backwards, rw ←list.reverse_reverse v, cases v.reverse with e z, { exfalso, rw list.nil_append at backwards, rw ←list.map_reverse _ r₀.input_R at backwards, cases r₀.input_R.reverse with d l, { rw [list.map_nil, list.nil_append] at backwards, rw list.reverse_singleton (symbol.nonterminal (sum.inl r₀.input_N)) at backwards, rw list.singleton_append at backwards, have imposs := list.head_eq_of_cons_eq backwards, exact sum.no_confusion (symbol.nonterminal.inj imposs), }, { rw [list.map_cons, list.cons_append, list.cons_append] at backwards, have imposs := list.head_eq_of_cons_eq backwards, exact wrap_never_outputs_H imposs.symm, }, }, rw [list.cons_append, list.cons_append, list.cons.inj_eq] at backwards, cases backwards with He backward, rw ←He at *, clear He e, have forward := congr_arg list.reverse backward, clear backward, repeat { rw list.reverse_append at forward, }, repeat { rw list.reverse_reverse at forward, }, rw ←list.append_assoc at forward, rw list.append_eq_append_iff at forward, cases forward, swap, { exfalso, rcases forward with ⟨a, imposs, -⟩, rw list.append_assoc u at imposs, rw list.append_assoc _ (list.map wrap_sym r₀.input_R) at imposs, rw ←list.append_assoc u at imposs, rw ←list.append_assoc u at imposs, exact case_3_false_of_wbr_eq_urz imposs, }, rcases forward with ⟨a', left_side, gamma_is⟩, repeat { rw ←list.append_assoc at left_side, }, rw list.append_eq_append_iff at left_side, cases left_side, { exfalso, rcases left_side with ⟨a, imposs, -⟩, exact case_3_false_of_wbr_eq_urz imposs, }, rcases left_side with ⟨c', the_left, the_a'⟩, rw the_a' at gamma_is, clear the_a' a', rw list.append_assoc at the_left, rw list.append_assoc at the_left, rw list.append_eq_append_iff at the_left, cases the_left, { exfalso, rcases the_left with ⟨a, -, imposs⟩, apply false_of_true_eq_false, convert congr_arg ((∈) R) imposs.symm, { rw [eq_iff_iff, true_iff], apply list.mem_append_right, apply list.mem_append_left, apply list.mem_singleton_self, }, { rw [eq_iff_iff, false_iff], rw list.mem_append, push_neg, split, { rw list.mem_map, push_neg, intros, apply wrap_never_outputs_R, }, { rw list.mem_singleton, intro impos, exact sum.no_confusion (symbol.nonterminal.inj impos), }, }, }, rcases the_left with ⟨u₀, u_eq, rule_side⟩, rw u_eq at *, clear u_eq u, have zr_eq : z.reverse = list.drop (c' ++ list.map wrap_sym r₀.input_R).length (list.map wrap_sym γ), { have gamma_suffix := congr_arg (list.drop (c' ++ list.map wrap_sym r₀.input_R).length) gamma_is, rw list.drop_left at gamma_suffix, exact gamma_suffix.symm, }, cases u₀ with d l, { exfalso, rw list.nil_append at rule_side, cases r₀.input_L with d l, { rw [list.map_nil, list.nil_append] at rule_side, have imposs := list.head_eq_of_cons_eq rule_side, exact sum.no_confusion (symbol.nonterminal.inj imposs), }, { rw [list.map_cons, list.cons_append] at rule_side, have imposs := list.head_eq_of_cons_eq rule_side, exact wrap_never_outputs_R imposs.symm, }, }, rw [list.singleton_append, list.cons_append, list.cons.inj_eq] at rule_side, cases rule_side with Rd c'_eq, rw ←Rd at *, clear Rd d, rw c'_eq at gamma_is, use [list.take l.length γ, list.drop (c' ++ list.map wrap_sym r₀.input_R).length γ], split, { rw ←list.singleton_append, have l_from_gamma := congr_arg (list.take l.length) gamma_is, repeat { rw list.append_assoc at l_from_gamma, }, rw list.take_left at l_from_gamma, rw list.map_take, rw l_from_gamma, rw ←list.append_assoc, }, split, { rw c'_eq, convert_to list.take l.length γ ++ list.drop l.length γ = _, { symmetry, apply list.take_append_drop, }, trim, rw zr_eq at gamma_is, rw c'_eq at gamma_is, repeat { rw list.append_assoc at gamma_is, }, have gamma_minus_initial_l := congr_arg (list.drop l.length) gamma_is, rw [list.drop_left, very_middle, ←list.map_drop, ←list.map_drop] at gamma_minus_initial_l, repeat { rw ←list.map_append at gamma_minus_initial_l, }, rw wrap_str_inj gamma_minus_initial_l, trim, repeat { rw list.length_append, }, repeat { rw list.length_map, }, repeat { rw list.length_append, }, repeat { rw list.length_singleton, }, repeat { rw add_assoc, }, }, { rw [list.map_nil, list.map_nil, list.join, list.append_nil], rw [list.reverse_cons, zr_eq], rw list.map_drop, }, }, by_cases is_v'_nil : v' = [], { rw [is_v'_nil, list.nil_append] at right_half, rw [is_v'_nil, list.append_nil] at left_half, left, use [0, [], list.drop (r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R).length x₀], rw [list.map_cons, list.map_cons, list.join] at right_half, split, { rw [list.map_nil, list.append_nil], rw [list.take_zero, list.map_nil, list.join, list.append_nil], exact left_half.symm, }, have lengths_trivi : list.length ( list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ) = list.length (r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R), { rw [very_middle, ←list.map_append_append], apply list.length_map, }, have len_rᵢ_le_len_x₀ : (r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R).length ≤ (list.map wrap_sym x₀).length, { classical, have first_H := congr_arg (list.index_of H) right_half, rw [list.append_assoc _ [H], list.index_of_append_of_notin map_wrap_never_contains_H] at first_H, rw [list.singleton_append, list.index_of_cons_self, add_zero] at first_H, rw [very_middle, ←list.map_append_append, list.index_of_append_of_notin map_wrap_never_contains_H] at first_H, rw list.length_map at first_H, exact nat.le.intro first_H, }, split, { rw list.nth, apply congr_arg, rw list.nil_append, convert_to x₀ = list.take (r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R).length x₀ ++ list.drop (r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R).length x₀, { trim, apply wrap_str_inj, rw list.map_append_append, have right_left := congr_arg (list.take (r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R).length) right_half, rw list.take_left' lengths_trivi at right_left, rw [←very_middle, right_left], rw list.append_assoc _ [H], rw list.take_append_of_le_length len_rᵢ_le_len_x₀, rw list.map_take, }, rw list.take_append_drop, }, { rw [list.map_cons, list.drop_one, list.tail_cons], have right_right := congr_arg (list.drop (r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R).length) right_half, rw list.drop_left' lengths_trivi at right_right, rw right_right, rw list.append_assoc _ [H], rw list.drop_append_of_le_length len_rᵢ_le_len_x₀, rw list.map_drop, rw list.append_assoc _ [H], refl, }, }, right, obtain ⟨z, v'_eq⟩ : ∃ z, v' = list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ++ z, { obtain ⟨v'', without_final_H⟩ : ∃ v'', v' = v'' ++ [H], { rw list.append_eq_append_iff at left_half, cases left_half, { rcases left_half with ⟨a', -, matters⟩, use list.nil, cases a' with d l, { rw list.nil_append at matters ⊢, exact matters.symm, }, { exfalso, have imposs := congr_arg list.length matters, rw [list.length_singleton, list.length_append, list.length_cons] at imposs, have right_pos := length_ge_one_of_not_nil is_v'_nil, clear_except imposs right_pos, linarith, }, }, { rcases left_half with ⟨c', -, v_c'⟩, exact ⟨c', v_c'⟩, }, }, rw without_final_H at right_half, rw list.append_assoc v'' at right_half, have key_prop : list.length ( list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ) ≤ v''.length, { classical, have first_H := congr_arg (list.index_of H) right_half, rw [very_middle, ←list.map_append_append, list.index_of_append_of_notin map_wrap_never_contains_H] at first_H, have H_not_in_v'' : H ∉ v'', { rw [without_final_H, ←list.append_assoc] at left_half, intro contra, apply false_of_true_eq_false, convert congr_arg ((∈) H) (list.append_right_cancel left_half).symm, { rw [eq_iff_iff, true_iff], exact list.mem_append_right _ contra, }, { clear_except, rw [eq_iff_iff, false_iff], intro contr, iterate 3 { rw list.mem_append at contr, cases contr, }, iterate 2 { rw list.mem_map at contr, rcases contr with ⟨t, -, impos⟩, exact symbol.no_confusion impos, }, { rw list.mem_singleton at contr, exact H_neq_R contr, }, { rw list.mem_map at contr, rcases contr with ⟨s, -, imposs⟩, exact wrap_never_outputs_H imposs, }, }, }, rw list.index_of_append_of_notin H_not_in_v'' at first_H, rw [list.singleton_append, list.index_of_cons_self, add_zero] at first_H, rw [very_middle, ←list.map_append_append], exact nat.le.intro first_H, }, obtain ⟨n, key_prop'⟩ := nat.le.dest key_prop, have right_take := congr_arg (list.take v''.length) right_half, rw list.take_left at right_take, rw ←key_prop' at right_take, rw list.take_append at right_take, use list.take n v ++ [H], rw without_final_H, rw ←right_take, repeat { rw ←list.append_assoc, }, }, rw v'_eq at right_half, rw list.append_assoc _ z at right_half, rw list.append_right_inj at right_half, rw v'_eq at left_half, obtain ⟨u₁, v₁, gamma_parts, z_eq⟩ : ∃ u₁, ∃ v₁, list.map wrap_sym γ = list.map wrap_sym u₁ ++ ( list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ) ++ list.map wrap_sym v₁ ∧ z = list.map wrap_sym v₁ ++ [H], { repeat { rw ←list.append_assoc at left_half, }, rw list.append_assoc _ (list.map wrap_sym γ) at left_half, rw list.append_assoc _ _ z at left_half, rw list.append_eq_append_iff at left_half, cases left_half, swap, { exfalso, rcases left_half with ⟨c', imposs, -⟩, exact case_3_false_of_wbr_eq_urz imposs, }, rcases left_half with ⟨a', lhl, lhr⟩, have lhl' := congr_arg list.reverse lhl, repeat { rw list.reverse_append at lhl', }, rw list.reverse_singleton at lhl', rw ←list.reverse_reverse a' at lhr, cases a'.reverse with d' l', { exfalso, rw list.nil_append at lhl', rw [list.singleton_append, list.reverse_singleton, list.singleton_append] at lhl', have imposs := list.head_eq_of_cons_eq lhl', exact sum.no_confusion (symbol.nonterminal.inj imposs), }, rw list.singleton_append at lhl', rw list.cons_append at lhl', rw list.cons.inj_eq at lhl', cases lhl' with eq_d' lhl'', rw ←eq_d' at lhr, clear eq_d' d', rw ←list.append_assoc l' at lhl'', rw list.append_eq_append_iff at lhl'', cases lhl'', swap, { exfalso, rcases lhl'' with ⟨c'', imposs, -⟩, rw list.reverse_singleton at imposs, apply false_of_true_eq_false, convert congr_arg ((∈) R) imposs.symm, { rw [eq_iff_iff, true_iff], apply list.mem_append_left, apply list.mem_append_right, apply list.mem_singleton_self, }, { rw [eq_iff_iff, false_iff], rw list.mem_reverse, apply map_wrap_never_contains_R, }, }, rcases lhl'' with ⟨b', lhlr', lhll'⟩, rw list.reverse_singleton at lhlr', have lhlr := congr_arg list.reverse lhlr', rw [list.reverse_append, list.reverse_append, list.reverse_reverse] at lhlr, rw [list.reverse_singleton, list.singleton_append] at lhlr, rw ←list.reverse_reverse b' at lhll', cases b'.reverse with d'' l'', { exfalso, rw list.nil_append at lhlr, cases r₀.input_L with d l, { rw list.map_nil at lhlr, exact list.no_confusion lhlr, }, rw list.map_cons at lhlr, have imposs := list.head_eq_of_cons_eq lhlr, exact wrap_never_outputs_R imposs.symm, }, rw list.cons_append at lhlr, rw list.cons.inj_eq at lhlr, cases lhlr with eq_d'' lve, rw ←eq_d'' at lhll', clear eq_d'' d'', have lhll := congr_arg list.reverse lhll', rw [list.reverse_reverse, list.reverse_append, list.reverse_reverse, list.reverse_append, list.reverse_reverse, list.reverse_reverse] at lhll, rw lhll at *, clear lhll u, rw list.reverse_cons at lhr, rw lve at lhr, use list.take l''.length γ, use list.drop (l'' ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ).length γ, have z_expr : z = list.map wrap_sym ( list.drop (l'' ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ).length γ ) ++ [H], { have lhdr := congr_arg (list.drop (l'' ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ).length) lhr, rw list.drop_append_of_le_length at lhdr, { rw [list.map_drop, lhdr, ←list.append_assoc, list.drop_left], }, have lhr' := congr_arg list.reverse lhr, repeat { rw list.reverse_append at lhr', }, rw list.reverse_singleton at lhr', cases z.reverse with d l, { exfalso, rw [list.nil_append, list.singleton_append] at lhr', rw ←list.map_reverse _ r₀.input_R at lhr', cases r₀.input_R.reverse with dᵣ lᵣ, { rw [list.map_nil, list.nil_append, list.reverse_singleton, list.singleton_append] at lhr', have imposs := list.head_eq_of_cons_eq lhr', exact sum.no_confusion (symbol.nonterminal.inj imposs), }, { rw [list.map_cons, list.cons_append] at lhr', have imposs := list.head_eq_of_cons_eq lhr', exact wrap_never_outputs_H imposs.symm, }, }, repeat { rw list.length_append, }, have contra_len := congr_arg list.length lhr', repeat { rw list.length_append at contra_len, }, repeat { rw list.length_reverse at contra_len, }, repeat { rw list.length_singleton at contra_len, }, rw list.length_cons at contra_len, rw list.length_singleton, clear_except contra_len, linarith, }, split, swap, { exact z_expr, }, rw z_expr at lhr, have gamma_expr : list.map wrap_sym γ = l'' ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ (list.map wrap_sym r₀.input_R ++ (list.map wrap_sym (list.drop (l'' ++ list.map wrap_sym r₀.input_L ++ [symbol.nonterminal (sum.inl r₀.input_N)] ++ list.map wrap_sym r₀.input_R ).length γ))), { repeat { rw ←list.append_assoc at lhr, }, repeat { rw ←list.append_assoc, }, exact list.append_right_cancel lhr, }, rw gamma_expr, trim, have almost := congr_arg (list.take l''.length) gamma_expr.symm, repeat { rw list.append_assoc at almost, }, rw list.take_left at almost, rw list.map_take, exact almost, }, use [u₁, v₁], split, swap, split, { apply wrap_str_inj, rwa [ very_middle, ←list.map_append_append, ←list.map_append_append, ←list.append_assoc, ←list.append_assoc ] at gamma_parts, }, { rwa z_eq at right_half, }, rw gamma_parts at left_half, rw list.append_assoc (list.map wrap_sym u₁) at left_half, rw ←list.append_assoc _ (list.map wrap_sym u₁) at left_half, rw list.append_assoc _ _ [H] at left_half, have left_left := congr_arg (list.take u.length) left_half, rw list.take_left at left_left, rw list.take_left' at left_left, { exact left_left.symm, }, have lh_len := congr_arg list.length left_half, repeat { rw list.length_append at lh_len, }, repeat { rw list.length_singleton at lh_len, }, have cut_off_end : z.length = (list.map wrap_sym v₁).length + 1, { simpa using congr_arg list.length z_eq, }, rw cut_off_end at lh_len, repeat { rw list.length_append, }, rw list.length_singleton, repeat { rw add_assoc at lh_len, }, iterate 3 { rw ←add_assoc at lh_len, }, rwa add_left_inj at lh_len, }, end private lemma star_case_3 {g : grammar T} {α α' : list (ns T g.nt)} (orig : grammar_transforms (star_grammar g) α α') (hyp : ∃ w : list (list T), ∃ β : list T, ∃ γ : list (symbol T g.nt), ∃ x : list (list (symbol T g.nt)), (∀ wᵢ ∈ w, grammar_generates g wᵢ) ∧ (grammar_derives g [symbol.nonterminal g.initial] (list.map symbol.terminal β ++ γ)) ∧ (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α = list.map symbol.terminal (list.join w) ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) : (∃ w : list (list T), ∃ β : list T, ∃ γ : list (symbol T g.nt), ∃ x : list (list (symbol T g.nt)), (∀ wᵢ ∈ w, grammar_generates g wᵢ) ∧ (grammar_derives g [symbol.nonterminal g.initial] (list.map symbol.terminal β ++ γ)) ∧ (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α' = list.map symbol.terminal (list.join w) ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) ∨ (∃ u : list T, u ∈ language.star (grammar_language g) ∧ α' = list.map symbol.terminal u) ∨ (∃ σ : list (symbol T g.nt), α' = list.map wrap_sym σ ++ [R]) ∨ (∃ ω : list (ns T g.nt), α' = ω ++ [H]) ∧ Z ∉ α' ∧ R ∉ α' := begin rcases hyp with ⟨w, β, γ, x, valid_w, valid_middle, valid_x, cat⟩, have no_Z_in_alpha : Z ∉ α, { intro contr, rw cat at contr, clear_except contr, repeat { rw list.mem_append at contr, }, iterate 5 { cases contr, }, any_goals { rw list.mem_map at contr, rcases contr with ⟨s, -, imposs⟩, }, { exact symbol.no_confusion imposs, }, { exact symbol.no_confusion imposs, }, { rw list.mem_singleton at contr, exact Z_neq_R contr, }, { exact wrap_never_outputs_Z imposs, }, { rw list.mem_singleton at contr, exact Z_neq_H contr, }, { exact Z_not_in_join_mpHmmw contr, }, }, rw cat at *, clear cat, rcases orig with ⟨r, rin, u, v, bef, aft⟩, iterate 2 { cases rin, { exfalso, apply no_Z_in_alpha, rw bef, apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_right, rw list.mem_singleton, rw rin, refl, }, }, cases rin, { rw rin at bef aft, dsimp only at bef aft, rw list.append_nil at bef, have gamma_nil_here := case_3_gamma_nil bef, cases x with x₀ L, { right, right, left, rw [gamma_nil_here, list.map_nil, list.append_nil] at bef, rw [list.map_nil, list.map_nil, list.join, list.append_nil] at bef, have v_nil := case_3_v_nil bef, rw [v_nil, list.append_nil] at bef aft, use list.map symbol.terminal w.join ++ list.map symbol.terminal β, rw aft, have bef_minus_H := list.append_right_cancel bef, have bef_minus_RH := list.append_right_cancel bef_minus_H, rw ←bef_minus_RH, rw [list.map_append, list.map_map, list.map_map], refl, }, { left, use [w ++ [β], x₀, L], split, { intros wᵢ wiin, rw list.mem_append at wiin, cases wiin, { exact valid_w wᵢ wiin, }, { rw list.mem_singleton at wiin, rw wiin, rw [gamma_nil_here, list.append_nil] at valid_middle, exact valid_middle, }, }, split, { rw [list.map_nil, list.nil_append], exact valid_x x₀ (list.mem_cons_self x₀ L), }, split, { intros xᵢ xiin, exact valid_x xᵢ (list.mem_cons_of_mem x₀ xiin), }, rw [list.map_nil, list.append_nil], rw aft, have u_eq : u = list.map (@symbol.terminal T (nn g.nt)) w.join ++ list.map (@symbol.terminal T (nn g.nt)) β, { exact case_3_u_eq_left_side bef, }, have v_eq : v = list.join (list.map (++ [H]) (list.map (list.map wrap_sym) (x₀ :: L))), { rw u_eq at bef, rw [gamma_nil_here, list.map_nil, list.append_nil] at bef, exact (list.append_left_cancel bef).symm, }, rw [u_eq, v_eq], rw [list.join_append, list.map_append, list.join_singleton], rw [list.map_cons, list.map_cons, list.join], rw [←list.append_assoc, ←list.append_assoc], refl, }, }, cases rin, { rw rin at bef aft, dsimp only at bef aft, rw list.append_nil at bef aft, have gamma_nil_here := case_3_gamma_nil bef, rw ←list.reverse_reverse x at *, cases x.reverse with xₘ L, { right, left, rw [gamma_nil_here, list.map_nil, list.append_nil] at bef, rw [list.reverse_nil, list.map_nil, list.map_nil, list.join, list.append_nil] at bef, have v_nil := case_3_v_nil bef, rw [v_nil, list.append_nil] at bef aft, use list.join w ++ β, split, { use w ++ [β], split, { rw list.join_append, rw list.join_singleton, }, { intros y y_in, rw list.mem_append at y_in, cases y_in, { exact valid_w y y_in, }, { rw list.mem_singleton at y_in, rw y_in, rw [gamma_nil_here, list.append_nil] at valid_middle, exact valid_middle, }, }, }, { rw aft, have bef_minus_H := list.append_right_cancel bef, have bef_minus_RH := list.append_right_cancel bef_minus_H, rw ←bef_minus_RH, rw list.map_append, }, }, { right, right, right, rw list.reverse_cons at bef, rw aft, have Z_ni_wb : Z ∉ list.map (@symbol.terminal T (nn g.nt)) w.join ++ list.map symbol.terminal β, { apply case_3_ni_wb, }, have R_ni_wb : R ∉ list.map (@symbol.terminal T (nn g.nt)) w.join ++ list.map symbol.terminal β, { apply case_3_ni_wb, }, have u_eq : u = list.map (@symbol.terminal T (nn g.nt)) w.join ++ list.map symbol.terminal β, { exact case_3_u_eq_left_side bef, }, have v_eq : v = list.join (list.map (++ [H]) (list.map (list.map wrap_sym) (L.reverse ++ [xₘ]))), { rw u_eq at bef, rw [gamma_nil_here, list.map_nil, list.append_nil] at bef, exact (list.append_left_cancel bef).symm, }, rw [u_eq, v_eq], split, { use list.map symbol.terminal w.join ++ list.map symbol.terminal β ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) L.reverse)) ++ list.map wrap_sym xₘ, rw [ list.map_append, list.map_append, list.join_append, list.map_singleton, list.map_singleton, list.join_singleton, ←list.append_assoc, ←list.append_assoc ], refl, }, split, { intro contra, rw list.mem_append at contra, cases contra, { exact Z_ni_wb contra, }, { exact Z_not_in_join_mpHmmw contra, }, }, { intro contra, rw list.mem_append at contra, cases contra, { exact R_ni_wb contra, }, { exact R_not_in_join_mpHmmw contra, }, }, }, }, have rin' : r ∈ rules_that_scan_terminals g ∨ r ∈ list.map wrap_gr g.rules, { rw or_comm, rwa ←list.mem_append, }, clear rin, cases rin', { left, unfold rules_that_scan_terminals at rin', rw list.mem_map at rin', rcases rin' with ⟨t, -, r_is⟩, rw ←r_is at bef aft, dsimp only at bef aft, rw list.append_nil at bef, have u_matches : u = list.map (@symbol.terminal T (nn g.nt)) w.join ++ list.map symbol.terminal β, { exact case_3_u_eq_left_side bef, }, have tv_matches : [symbol.terminal t] ++ v = list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)), { rw u_matches at bef, repeat { rw list.append_assoc at bef, }, have almost := list.append_left_cancel (list.append_left_cancel (list.append_left_cancel bef)), rw ←list.append_assoc at almost, exact almost.symm, }, cases γ with a δ, { exfalso, rw [list.map_nil, list.nil_append, list.singleton_append, list.singleton_append] at tv_matches, have t_matches := list.head_eq_of_cons_eq tv_matches, exact symbol.no_confusion t_matches, }, rw [list.singleton_append, list.map_cons, list.cons_append, list.cons_append] at tv_matches, use [w, β ++ [t], δ, x], split, { exact valid_w, }, split, { have t_matches' := list.head_eq_of_cons_eq tv_matches, cases a; unfold wrap_sym at t_matches', { have t_eq_a := symbol.terminal.inj t_matches', rw [t_eq_a, list.map_append, list.map_singleton, list.append_assoc, list.singleton_append], exact valid_middle, }, { exfalso, exact symbol.no_confusion t_matches', }, }, split, { exact valid_x, }, rw aft, rw u_matches, rw [list.map_append, list.map_singleton], have v_matches := list.tail_eq_of_cons_eq tv_matches, rw v_matches, simp [list.append_assoc], }, left, rw list.mem_map at rin', rcases rin' with ⟨r₀, orig_in, wrap_orig⟩, unfold wrap_gr at wrap_orig, rw ←wrap_orig at *, clear wrap_orig, cases case_3_match_rule bef, { rcases h with ⟨m, u₁, v₁, u_eq, xm_eq, v_eq⟩, clear bef, dsimp only at aft, rw [u_eq, v_eq] at aft, use w, use β, use γ, use (list.take m x ++ [u₁ ++ r₀.output_string ++ v₁] ++ list.drop m.succ x), split, { exact valid_w, }, split, { exact valid_middle, }, split, { intros xᵢ xiin, rw list.mem_append_append at xiin, cases xiin, { apply valid_x, exact list.mem_of_mem_take xiin, }, cases xiin, swap, { apply valid_x, exact list.mem_of_mem_drop xiin, }, { rw list.mem_singleton at xiin, rw xiin, have last_step : grammar_transforms g (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁) (u₁ ++ r₀.output_string ++ v₁), { use r₀, split, { exact orig_in, }, use [u₁, v₁], split; refl, }, apply grammar_deri_of_deri_tran _ last_step, apply valid_x (u₁ ++ r₀.input_L ++ [symbol.nonterminal r₀.input_N] ++ r₀.input_R ++ v₁), exact list.nth_mem xm_eq, }, }, { rw aft, trim, rw [ list.map_append_append, list.map_append_append, list.join_append_append, ←list.map_take, ←list.map_drop, list.map_singleton, list.map_singleton, list.join_singleton, list.map_append_append, ←list.append_assoc, ←list.append_assoc, ←list.append_assoc ], }, }, { rcases h with ⟨u₁, v₁, u_eq, γ_eq, v_eq⟩, clear bef, dsimp only at aft, rw [u_eq, v_eq] at aft, use w, use β, use u₁ ++ r₀.output_string ++ v₁, use x, split, { exact valid_w, }, split, { apply grammar_deri_of_deri_tran valid_middle, rw γ_eq, use r₀, split, { exact orig_in, }, use [list.map symbol.terminal β ++ u₁, v₁], split, repeat { rw ←list.append_assoc, }, }, split, { exact valid_x, }, { rw aft, trim, rw list.map_append_append, }, }, end private lemma star_case_4 {g : grammar T} {α α' : list (ns T g.nt)} (orig : grammar_transforms (star_grammar g) α α') (hyp : ∃ u : list T, u ∈ (grammar_language g).star ∧ α = list.map symbol.terminal u) : false := begin rcases hyp with ⟨w, -, alpha_of_w⟩, rw alpha_of_w at orig, rcases orig with ⟨r, -, u, v, bef, -⟩, simpa using congr_arg (λ l, symbol.nonterminal r.input_N ∈ l) bef, end private lemma star_case_5 {g : grammar T} {α α' : list (ns T g.nt)} (orig : grammar_transforms (star_grammar g) α α') (hyp : ∃ σ : list (symbol T g.nt), α = list.map wrap_sym σ ++ [R]) : (∃ σ : list (symbol T g.nt), α' = list.map wrap_sym σ ++ [R]) := begin rcases hyp with ⟨w, ends_with_R⟩, rcases orig with ⟨r, rin, u, v, bef, aft⟩, rw ends_with_R at bef, clear ends_with_R, iterate 2 { cases rin, { exfalso, rw rin at bef, simp only [list.append_nil] at bef, have imposs := congr_arg (λ l, Z ∈ l) bef, simp only [list.mem_append] at imposs, rw list.mem_singleton at imposs, rw list.mem_singleton at imposs, apply false_of_true_eq_false, convert imposs.symm, { unfold Z, rw [eq_self_iff_true, or_true, true_or], }, { rw [eq_iff_iff, false_iff], push_neg, split, { apply map_wrap_never_contains_Z, }, { exact Z_neq_R, }, }, }, }, iterate 2 { cases rin, { exfalso, rw rin at bef, dsimp only at bef, rw list.append_nil at bef, have rev := congr_arg list.reverse bef, repeat { rw list.reverse_append at rev, }, repeat { rw list.reverse_singleton at rev, }, rw list.singleton_append at rev, cases v.reverse with d l, { rw list.nil_append at rev, rw list.singleton_append at rev, have tails := list.tail_eq_of_cons_eq rev, rw ←list.map_reverse at tails, cases w.reverse with d' l', { rw list.map_nil at tails, have imposs := congr_arg list.length tails, rw [list.length, list.length_append, list.length_singleton] at imposs, clear_except imposs, linarith, }, { rw list.map_cons at tails, rw list.singleton_append at tails, have heads := list.head_eq_of_cons_eq tails, exact wrap_never_outputs_R heads, }, }, { have tails := list.tail_eq_of_cons_eq rev, have H_in_tails := congr_arg (λ l, H ∈ l) tails, dsimp only at H_in_tails, rw list.mem_reverse at H_in_tails, apply false_of_true_eq_false, convert H_in_tails.symm, { rw [eq_iff_iff, true_iff], apply list.mem_append_right, apply list.mem_append_left, apply list.mem_singleton_self, }, { rw [eq_iff_iff, false_iff], intro hyp_H_in, exact map_wrap_never_contains_H hyp_H_in, }, }, }, }, change r ∈ list.map wrap_gr g.rules ++ rules_that_scan_terminals g at rin, rw list.mem_append at rin, cases rin, { rw list.mem_map at rin, rcases rin with ⟨r₀, -, r_of_r₀⟩, rw list.append_eq_append_iff at bef, cases bef, { rcases bef with ⟨x, ur_eq, singleR⟩, by_cases is_x_nil : x = [], { have v_is_R : v = [R], { rw [is_x_nil, list.nil_append] at singleR, exact singleR.symm, }, rw v_is_R at aft, rw [is_x_nil, list.append_nil] at ur_eq, have u_from_w : u = list.take u.length (list.map wrap_sym w), { -- do not extract out of `cases bef` repeat { rw list.append_assoc at ur_eq, }, have tak := congr_arg (list.take u.length) ur_eq, rw list.take_left at tak, exact tak, }, rw ←list.map_take at u_from_w, rw u_from_w at aft, rw ←r_of_r₀ at aft, dsimp only [wrap_gr] at aft, use list.take u.length w ++ r₀.output_string, rw list.map_append, exact aft, }, { exfalso, have x_is_R : x = [R], { by_cases is_v_nil : v = [], { rw [is_v_nil, list.append_nil] at singleR, exact singleR.symm, }, { exfalso, have imposs := congr_arg list.length singleR, rw list.length_singleton at imposs, rw list.length_append at imposs, have xl_ge_one := length_ge_one_of_not_nil is_x_nil, have vl_ge_one := length_ge_one_of_not_nil is_v_nil, clear_except imposs xl_ge_one vl_ge_one, linarith, }, }, rw x_is_R at ur_eq, have ru_eq := congr_arg list.reverse ur_eq, repeat { rw list.reverse_append at ru_eq, }, repeat { rw list.reverse_singleton at ru_eq, rw list.singleton_append at ru_eq, }, rw ←r_of_r₀ at ru_eq, dsimp only [wrap_gr, R] at ru_eq, rw ←list.map_reverse at ru_eq, cases r₀.input_R.reverse with d l, { rw [list.map_nil, list.nil_append] at ru_eq, have imposs := list.head_eq_of_cons_eq ru_eq, exact sum.no_confusion (symbol.nonterminal.inj imposs), }, { have imposs := list.head_eq_of_cons_eq ru_eq, cases d; unfold wrap_sym at imposs, { exact symbol.no_confusion imposs, }, { exact sum.no_confusion (symbol.nonterminal.inj imposs), }, }, }, }, { rcases bef with ⟨y, w_eq, v_eq⟩, have u_from_w : u = list.take u.length (list.map wrap_sym w), { -- do not extract out of `cases bef` repeat { rw list.append_assoc at w_eq, }, have tak := congr_arg (list.take u.length) w_eq, rw list.take_left at tak, exact tak.symm, }, have y_from_w : y = list.drop (u ++ r.input_L ++ [symbol.nonterminal r.input_N] ++ r.input_R).length (list.map wrap_sym w), { have drp := congr_arg (list.drop (u ++ r.input_L ++ [symbol.nonterminal r.input_N] ++ r.input_R).length) w_eq, rw list.drop_left at drp, exact drp.symm, }, -- weird that `u_from_w` and `y_from_w` did not unify their type parameters in the same way rw u_from_w at aft, rw y_from_w at v_eq, rw v_eq at aft, use list.take u.length w ++ r₀.output_string ++ list.drop (u ++ r.input_L ++ [symbol.nonterminal r.input_N] ++ r.input_R).length w, rw list.map_append_append, rw list.map_take, rw list.map_drop, rw aft, trim, -- fails to identify `list.take u.length (list.map wrap_sym w)` of defin-equal type parameters rw ←r_of_r₀, dsimp only [wrap_gr], refl, -- outside level `(symbol T (star_grammar g).nt) = (ns T g.nt) = (symbol T (nn g.nt))` }, }, { exfalso, unfold rules_that_scan_terminals at rin, rw list.mem_map at rin, rcases rin with ⟨t, -, eq_r⟩, rw ←eq_r at bef, clear eq_r, dsimp only at bef, rw list.append_nil at bef, have rev := congr_arg list.reverse bef, repeat { rw list.reverse_append at rev, }, repeat { rw list.reverse_singleton at rev, }, rw list.singleton_append at rev, cases v.reverse with d l, { rw list.nil_append at rev, rw list.singleton_append at rev, have tails := list.tail_eq_of_cons_eq rev, rw ←list.map_reverse at tails, cases w.reverse with d' l', { rw list.map_nil at tails, have imposs := congr_arg list.length tails, rw [list.length, list.length_append, list.length_singleton] at imposs, clear_except imposs, linarith, }, { rw list.map_cons at tails, rw list.singleton_append at tails, have heads := list.head_eq_of_cons_eq tails, exact wrap_never_outputs_R heads, }, }, { have tails := list.tail_eq_of_cons_eq rev, have R_in_tails := congr_arg (λ l, R ∈ l) tails, dsimp only at R_in_tails, rw list.mem_reverse at R_in_tails, apply false_of_true_eq_false, convert R_in_tails.symm, { rw [eq_iff_iff, true_iff], apply list.mem_append_right, apply list.mem_append_right, apply list.mem_append_left, apply list.mem_singleton_self, }, { rw [eq_iff_iff, false_iff], intro hyp_R_in, exact map_wrap_never_contains_R hyp_R_in, }, }, }, end private lemma star_case_6 {g : grammar T} {α α' : list (ns T g.nt)} (orig : grammar_transforms (star_grammar g) α α') (hyp : (∃ ω : list (ns T g.nt), α = ω ++ [H]) ∧ Z ∉ α ∧ R ∉ α) : (∃ ω : list (ns T g.nt), α' = ω ++ [H]) ∧ Z ∉ α' ∧ R ∉ α' := begin rcases hyp with ⟨⟨w, ends_with_H⟩, no_Z, no_R⟩, rcases orig with ⟨r, rin, u, v, bef, aft⟩, iterate 2 { cases rin, { exfalso, rw rin at bef, simp only [list.append_nil] at bef, rw bef at no_Z, apply no_Z, apply list.mem_append_left, apply list.mem_append_right, apply list.mem_singleton_self, }, }, iterate 2 { cases rin, { exfalso, rw rin at bef, dsimp only at bef, rw list.append_nil at bef, rw bef at no_R, apply no_R, apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_right, apply list.mem_singleton_self, }, }, change r ∈ list.map wrap_gr g.rules ++ rules_that_scan_terminals g at rin, rw list.mem_append at rin, cases rin, { rw ends_with_H at bef, rw list.mem_map at rin, rcases rin with ⟨r₀, -, r_of_r₀⟩, split, swap, { split, { rw aft, intro contra, rw list.mem_append at contra, rw list.mem_append at contra, cases contra, swap, { apply no_Z, rw ends_with_H, rw bef, rw list.mem_append, right, exact contra, }, cases contra, { apply no_Z, rw ends_with_H, rw bef, repeat { rw list.append_assoc, }, rw list.mem_append, left, exact contra, }, rw ←r_of_r₀ at contra, unfold wrap_gr at contra, rw list.mem_map at contra, rcases contra with ⟨s, -, imposs⟩, cases s, { unfold wrap_sym at imposs, exact symbol.no_confusion imposs, }, { unfold wrap_sym at imposs, unfold Z at imposs, rw symbol.nonterminal.inj_eq at imposs, exact sum.no_confusion imposs, }, }, { rw aft, intro contra, rw list.mem_append at contra, rw list.mem_append at contra, cases contra, swap, { apply no_R, rw ends_with_H, rw bef, rw list.mem_append, right, exact contra, }, cases contra, { apply no_R, rw ends_with_H, rw bef, repeat { rw list.append_assoc, }, rw list.mem_append, left, exact contra, }, rw ←r_of_r₀ at contra, unfold wrap_gr at contra, rw list.mem_map at contra, rcases contra with ⟨s, -, imposs⟩, cases s, { unfold wrap_sym at imposs, exact symbol.no_confusion imposs, }, { unfold wrap_sym at imposs, unfold R at imposs, rw symbol.nonterminal.inj_eq at imposs, exact sum.no_confusion imposs, }, }, }, use u ++ r.output_string ++ v.take (v.length - 1), rw aft, trim, have vlnn : v.length ≥ 1, { by_contradiction contra, have v_nil := zero_of_not_ge_one contra, rw list.length_eq_zero at v_nil, rw v_nil at bef, rw ←r_of_r₀ at bef, rw list.append_nil at bef, unfold wrap_gr at bef, have rev := congr_arg list.reverse bef, clear_except rev, repeat { rw list.reverse_append at rev, }, rw ←list.map_reverse _ r₀.input_R at rev, rw list.reverse_singleton at rev, cases r₀.input_R.reverse with d l, { have H_eq_N : H = symbol.nonterminal (sum.inl r₀.input_N), { rw [list.map_nil, list.nil_append, list.reverse_singleton, list.singleton_append, list.singleton_append, list.cons.inj_eq] at rev, exact rev.left, }, unfold H at H_eq_N, have inr_eq_inl := symbol.nonterminal.inj H_eq_N, exact sum.no_confusion inr_eq_inl, }, { rw list.map_cons at rev, have H_is : H = wrap_sym d, { rw [list.singleton_append, list.cons_append, list.cons.inj_eq] at rev, exact rev.left, }, unfold H at H_is, cases d; unfold wrap_sym at H_is, { exact symbol.no_confusion H_is, }, { rw symbol.nonterminal.inj_eq at H_is, exact sum.no_confusion H_is, }, }, }, convert_to list.take (v.length - 1) v ++ list.drop (v.length - 1) v = list.take (v.length - 1) v ++ [H], { rw list.take_append_drop, }, trim, have bef_rev := congr_arg list.reverse bef, repeat { rw list.reverse_append at bef_rev, }, have bef_rev_tak := congr_arg (list.take 1) bef_rev, rw list.take_left' at bef_rev_tak, swap, { rw list.length_reverse, apply list.length_singleton, }, rw list.take_append_of_le_length at bef_rev_tak, swap, { rw list.length_reverse, exact vlnn, }, rw list.reverse_take _ vlnn at bef_rev_tak, rw list.reverse_eq_iff at bef_rev_tak, rw list.reverse_reverse at bef_rev_tak, exact bef_rev_tak.symm, }, { exfalso, unfold rules_that_scan_terminals at rin, rw list.mem_map at rin, rcases rin with ⟨t, -, eq_r⟩, rw ←eq_r at bef, dsimp only at bef, rw list.append_nil at bef, rw bef at no_R, apply no_R, apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_right, apply list.mem_singleton_self, }, end private lemma star_induction {g : grammar T} {α : list (ns T g.nt)} (ass : grammar_derives (star_grammar g) [Z] α) : (∃ x : list (list (symbol T g.nt)), (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α = [Z] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) ∨ (∃ x : list (list (symbol T g.nt)), (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α = [R, H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) ∨ (∃ w : list (list T), ∃ β : list T, ∃ γ : list (symbol T g.nt), ∃ x : list (list (symbol T g.nt)), (∀ wᵢ ∈ w, grammar_generates g wᵢ) ∧ (grammar_derives g [symbol.nonterminal g.initial] (list.map symbol.terminal β ++ γ)) ∧ (∀ xᵢ ∈ x, grammar_derives g [symbol.nonterminal g.initial] xᵢ) ∧ (α = list.map symbol.terminal (list.join w) ++ list.map symbol.terminal β ++ [R] ++ list.map wrap_sym γ ++ [H] ++ list.join (list.map (++ [H]) (list.map (list.map wrap_sym) x)))) ∨ (∃ u : list T, u ∈ language.star (grammar_language g) ∧ α = list.map symbol.terminal u) ∨ (∃ σ : list (symbol T g.nt), α = list.map wrap_sym σ ++ [R]) ∨ (∃ ω : list (ns T g.nt), α = ω ++ [H]) ∧ Z ∉ α ∧ R ∉ α := begin induction ass with a b trash orig ih, { left, use list.nil, split, { intros y imposs, exfalso, exact list.not_mem_nil y imposs, }, { refl, }, }, cases ih, { rw ←or_assoc, left, exact star_case_1 orig ih, }, cases ih, { right, exact star_case_2 orig ih, }, cases ih, { right, right, exact star_case_3 orig ih, }, cases ih, { exfalso, exact star_case_4 orig ih, }, cases ih, { right, right, right, right, left, exact star_case_5 orig ih, }, { right, right, right, right, right, exact star_case_6 orig ih, }, end end hard_direction /-- The class of recursively-enumerable languages is closed under the Kleene star. -/ theorem RE_of_star_RE (L : language T) : is_RE L → is_RE L.star := begin rintro ⟨g, hg⟩, use star_grammar g, apply set.eq_of_subset_of_subset, { -- prove `L.star ⊇` here intros w hyp, unfold grammar_language at hyp, rw set.mem_set_of_eq at hyp, have result := star_induction hyp, clear hyp, cases result, { exfalso, rcases result with ⟨x, -, contr⟩, cases w with d l, { tauto, }, rw list.map_cons at contr, have terminal_eq_Z : symbol.terminal d = Z, { exact list.head_eq_of_cons_eq contr, }, exact symbol.no_confusion terminal_eq_Z, }, cases result, { exfalso, rcases result with ⟨x, -, contr⟩, cases w with d l, { tauto, }, rw list.map_cons at contr, have terminal_eq_R : symbol.terminal d = R, { exact list.head_eq_of_cons_eq contr, }, exact symbol.no_confusion terminal_eq_R, }, cases result, { exfalso, rcases result with ⟨α, β, γ, x, -, -, -, contr⟩, have output_contains_R : R ∈ list.map symbol.terminal w, { rw contr, apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_left, apply list.mem_append_right, apply list.mem_cons_self, }, rw list.mem_map at output_contains_R, rcases output_contains_R with ⟨t, -, terminal_eq_R⟩, exact symbol.no_confusion terminal_eq_R, }, cases result, { rcases result with ⟨u, win, map_eq_map⟩, have w_eq_u : w = u, { have st_inj : function.injective (@symbol.terminal T (star_grammar g).nt), { apply symbol.terminal.inj, }, rw ←list.map_injective_iff at st_inj, exact st_inj map_eq_map, }, rw [w_eq_u, ←hg], exact win, }, cases result, { exfalso, cases result with σ contr, have last_symbols := congr_fun (congr_arg list.nth (congr_arg list.reverse contr)) 0, rw [ ←list.map_reverse, list.reverse_append, list.reverse_singleton, list.singleton_append, list.nth, list.nth_map ] at last_symbols, cases w.reverse.nth 0, { rw option.map_none' at last_symbols, exact option.no_confusion last_symbols, }, { rw option.map_some' at last_symbols, have terminal_eq_R := option.some.inj last_symbols, exact symbol.no_confusion terminal_eq_R, }, }, { exfalso, rcases result with ⟨⟨ω, contr⟩, -⟩, have last_symbols := congr_fun (congr_arg list.nth (congr_arg list.reverse contr)) 0, rw [ ←list.map_reverse, list.reverse_append, list.reverse_singleton, list.singleton_append, list.nth, list.nth_map ] at last_symbols, cases w.reverse.nth 0, { rw option.map_none' at last_symbols, exact option.no_confusion last_symbols, }, { rw option.map_some' at last_symbols, have terminal_eq_H := option.some.inj last_symbols, exact symbol.no_confusion terminal_eq_H, }, }, }, { -- prove `L.star ⊆` here intros p ass, unfold grammar_language, rw language.star at ass, rw set.mem_set_of_eq at ⊢ ass, rcases ass with ⟨w, w_join, parts_in_L⟩, let v := w.reverse, have v_reverse : v.reverse = w, { apply list.reverse_reverse, }, rw ←v_reverse at *, rw w_join, clear w_join p, unfold grammar_generates, rw ←hg at parts_in_L, cases short_induction parts_in_L with derived terminated, apply grammar_deri_of_deri_deri derived, apply grammar_deri_of_tran_deri, { use (star_grammar g).rules.nth_le 1 (by dec_trivial), split, { apply list.nth_le_mem, }, use [[], (list.map (++ [H]) (list.map (list.map symbol.terminal) v.reverse)).join], split, { rw list.reverse_reverse, refl, }, { refl, -- binds the implicit argument of `grammar_deri_of_tran_deri` }, }, rw list.nil_append, rw v_reverse, have final_step : grammar_transforms (star_grammar g) (list.map symbol.terminal w.join ++ [R, H]) (list.map symbol.terminal w.join), { use (star_grammar g).rules.nth_le 3 (by dec_trivial), split_ile, use [list.map symbol.terminal w.join, list.nil], split, { trim, }, { have out_nil : ((star_grammar g).rules.nth_le 3 _).output_string = [], { refl, }, rw [list.append_nil, out_nil, list.append_nil], }, }, apply grammar_deri_of_deri_tran _ final_step, convert_to grammar_derives (star_grammar g) ([R] ++ ([H] ++ (list.map (++ [H]) (list.map (list.map symbol.terminal) w)).join)) (list.map symbol.terminal w.join ++ [R, H]), have rebracket : [H] ++ (list.map (++ [H]) (list.map (list.map symbol.terminal) w)).join = (list.map (λ v, [H] ++ v) (list.map (list.map symbol.terminal) w)).join ++ [H], { apply list.append_join_append, }, rw rebracket, apply terminal_scan_aux, intros v vin t tin, rw ←list.mem_reverse at vin, exact terminated v vin t tin, }, end
/* * Copyright 2020 Makani Technologies LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SIM_PHYSICS_ROTOR_DATABASE_H_ #define SIM_PHYSICS_ROTOR_DATABASE_H_ #include <gsl/gsl_matrix.h> #include <gsl/gsl_vector.h> #include <string> #include "common/macros.h" class RotorDatabase { public: explicit RotorDatabase(const std::string &filename); virtual ~RotorDatabase(); // Calculates the rotor's thrust [N], applied torque [N-m], or // generated power [W] based on the angular rate, freestream // velocity, and air density. Torque and power are defined to be // negative during thrusting. double CalcThrust(double angular_rate, double freestream_vel, double air_density) const; double CalcTorque(double angular_rate, double freestream_vel, double air_density) const; double CalcPower(double angular_rate, double freestream_vel, double air_density) const; // Looks-up the value of the rotor's thrust, torque, or power // coefficients [#] at a given angular rate and freestream velocity // in a 2-D look-up table. Values are interpolated linearly between // points and the inputs are saturated to the limits of the table. double LookupThrustCoeff(double angular_rate, double freestream_vel) const; double LookupTorqueCoeff(double angular_rate, double freestream_vel) const; double LookupPowerCoeff(double angular_rate, double freestream_vel) const; private: // Returns true if the rotor database follows our sign conventions: // // - Power coefficient decreases with increasing angular rate for // the low freestream velocity case, i.e. power is positive in // generation. // // - Thrust coefficient increases with increasing angular rate for // the low freestream velocity case. bool IsValid() const; // Diameter of the propeller [m]. double diameter_; // Vector of angular rates [rad/s], which define the rows of the // look-up table. gsl_vector *angular_rates_; // Vector of freestream velocities [m/s], which define the columns // of the look-up table. gsl_vector *freestream_vels_; // Matrix of thrust coefficients [#] defined over a tensor grid of // freestream velocities and angular rates. The thrust coefficient // is defined as: // // thrust_coeff = thrust / (air_density * angular_rate_hz^2 * diameter^4) // // See Eq. 9.18, Houghton & Carpenter, 4th ed. gsl_matrix *thrust_coeffs_; // Matrix of power coefficients [#] defined over a tensor grid of // freestream velocities and angular rates. The power coefficient // is defined as: // // power_coeff = power / (air_density * angular_rate_hz^3 * diameter^5) // // See Eq. 9.22, Houghton & Carpenter, 4th ed. gsl_matrix *power_coeffs_; DISALLOW_COPY_AND_ASSIGN(RotorDatabase); }; #endif // SIM_PHYSICS_ROTOR_DATABASE_H_
(* Author: Tobias Nipkow *) section \<open>Unbalanced Tree Implementation of Set\<close> theory Tree_Set imports Tree Cmp Set_Specs begin definition empty :: "'a tree" where "empty = Leaf" fun isin :: "'a::linorder tree \<Rightarrow> 'a \<Rightarrow> bool" where "isin Leaf x = False" | "isin (Node l a r) x = (case cmp x a of LT \<Rightarrow> isin l x | EQ \<Rightarrow> True | GT \<Rightarrow> isin r x)" hide_const (open) insert fun insert :: "'a::linorder \<Rightarrow> 'a tree \<Rightarrow> 'a tree" where "insert x Leaf = Node Leaf x Leaf" | "insert x (Node l a r) = (case cmp x a of LT \<Rightarrow> Node (insert x l) a r | EQ \<Rightarrow> Node l a r | GT \<Rightarrow> Node l a (insert x r))" text \<open>Deletion by replacing:\<close> fun split_min :: "'a tree \<Rightarrow> 'a * 'a tree" where "split_min (Node l a r) = (if l = Leaf then (a,r) else let (x,l') = split_min l in (x, Node l' a r))" fun delete :: "'a::linorder \<Rightarrow> 'a tree \<Rightarrow> 'a tree" where "delete x Leaf = Leaf" | "delete x (Node l a r) = (case cmp x a of LT \<Rightarrow> Node (delete x l) a r | GT \<Rightarrow> Node l a (delete x r) | EQ \<Rightarrow> if r = Leaf then l else let (a',r') = split_min r in Node l a' r')" text \<open>Deletion by joining:\<close> fun join :: "('a::linorder)tree \<Rightarrow> 'a tree \<Rightarrow> 'a tree" where "join t Leaf = t" | "join Leaf t = t" | "join (Node t1 a t2) (Node t3 b t4) = (case join t2 t3 of Leaf \<Rightarrow> Node t1 a (Node Leaf b t4) | Node u2 x u3 \<Rightarrow> Node (Node t1 a u2) x (Node u3 b t4))" fun delete2 :: "'a::linorder \<Rightarrow> 'a tree \<Rightarrow> 'a tree" where "delete2 x Leaf = Leaf" | "delete2 x (Node l a r) = (case cmp x a of LT \<Rightarrow> Node (delete2 x l) a r | GT \<Rightarrow> Node l a (delete2 x r) | EQ \<Rightarrow> join l r)" subsection "Functional Correctness Proofs" lemma isin_set: "sorted(inorder t) \<Longrightarrow> isin t x = (x \<in> set (inorder t))" by (induction t) (auto simp: isin_simps) lemma inorder_insert: "sorted(inorder t) \<Longrightarrow> inorder(insert x t) = ins_list x (inorder t)" by(induction t) (auto simp: ins_list_simps) lemma split_minD: "split_min t = (x,t') \<Longrightarrow> t \<noteq> Leaf \<Longrightarrow> x # inorder t' = inorder t" by(induction t arbitrary: t' rule: split_min.induct) (auto simp: sorted_lems split: prod.splits if_splits) lemma inorder_delete: "sorted(inorder t) \<Longrightarrow> inorder(delete x t) = del_list x (inorder t)" by(induction t) (auto simp: del_list_simps split_minD split: prod.splits) interpretation S: Set_by_Ordered where empty = empty and isin = isin and insert = insert and delete = delete and inorder = inorder and inv = "\<lambda>_. True" proof (standard, goal_cases) case 1 show ?case by (simp add: empty_def) next case 2 thus ?case by(simp add: isin_set) next case 3 thus ?case by(simp add: inorder_insert) next case 4 thus ?case by(simp add: inorder_delete) qed (rule TrueI)+ lemma inorder_join: "inorder(join l r) = inorder l @ inorder r" by(induction l r rule: join.induct) (auto split: tree.split) lemma inorder_delete2: "sorted(inorder t) \<Longrightarrow> inorder(delete2 x t) = del_list x (inorder t)" by(induction t) (auto simp: inorder_join del_list_simps) interpretation S2: Set_by_Ordered where empty = empty and isin = isin and insert = insert and delete = delete2 and inorder = inorder and inv = "\<lambda>_. True" proof (standard, goal_cases) case 1 show ?case by (simp add: empty_def) next case 2 thus ?case by(simp add: isin_set) next case 3 thus ?case by(simp add: inorder_insert) next case 4 thus ?case by(simp add: inorder_delete2) qed (rule TrueI)+ end
demo(graphics) # El lienzo donde graficar par(bg="grey98") plot(1:100, type="n", axes=F, xlab = "", ylab="", bg="white") rect(-10, -10, 120, 120, col="white") box(lty = 3) mtext(c("side = 1", "side = 2", "side = 3", "side = 4"), side = c(1, 2, 3, 4), col = "grey", line = 1, cex = 1.5) dev.off() par(bg="grey98",mar=c(3,3,3,3)) layout.show() par(bg="grey98",mar=c(3,3,3,3),mfcol=c(1,2)) layout.show() # Dividiendo el lienzo layout(matrix(c(1,2,3,3),2,2)) par(mar=c(1,1,1,1),bg="grey98") layout.show() # Controlando el tamaño l = layout(matrix(c(1,1,2,3),2,2,byrow =TRUE), widths = c(2,3),heights = c(1.5,3)) par(mar=c(1,1,1,1),oma=c(3,3,1,1),bg="grey98") layout.show(l) # Parámetros gráficos par(mar=c(1,1,1,1),oma=c(3,3,1,1),bg="grey98",mfcol=c(2,2)) # Los puntos x <- rep(1:5,5) y <- sort(rep(1:5,5)) par(mar=c(1,1,1,1)) plot(x,y,pch=1:25,col=1:5,cex=seq(1,3,length.out =25),bg="yellow", axes=FALSE,xlab="",ylab="",ylim=c(0,6)) text(x,y-0.3,cex=0.8) library(png) ##Leerlo del disco duro coli <- readPNG("Bird.png") #Leerlo de internet y guardarlo pngURL <-"http://www.pngall.com/wp-content/uploads/4/Single-Flying-Bird.png" download.file(pngURL,"birdD.png",mode ="wb")
// Copyright 2011 Branan Purvine-Riley and Adam Johnson // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef SENSE_UTIL_QUEUE_HPP #define SENSE_UTIL_QUEUE_HPP #include <deque> #include <boost/thread.hpp> #include "atomic.hpp" template <typename T> class lockedQueue { public: void push(const T& t) { boost::mutex::scoped_lock lock(m_queue_mutex); bool was_empty = m_queue.empty(); m_queue.push_back(t); lock.unlock(); if(was_empty) m_queue_cond.notify_one(); } T wait_pop() { boost::mutex::scoped_lock lock(m_queue_mutex); while(m_queue.empty()) m_queue_cond.wait(lock); T val = m_queue.front(); m_queue.pop_front(); return val; } bool try_pop(T& val) { boost::mutex::scoped_lock lock(m_queue_mutex); if(m_queue.empty()) return false; val = m_queue.front(); m_queue.pop_front(); return true; } private: std::deque<T> m_queue; boost::mutex m_queue_mutex; boost::condition_variable m_queue_cond; }; template <typename T> class locklessQueue { class QueueItem { public: QueueItem() : next(0) {} T value; QueueItem *next; }; QueueItem *head; public: locklessQueue() : head(new QueueItem) {} void push(const T& t) { QueueItem *new_head = new QueueItem; new_head->value = t; do { new_head->next = head->next; } while(!compareAndSwapPointer(head->next, new_head->next, new_head)); } T wait_pop() { QueueItem *item; T result; for(;;) { do { item = head->next; if(item == 0) break; } while(!compareAndSwapPointer(head->next, item, item->next)); if(item) { result = item->value; delete item; return result; } } } bool try_pop(T& t) { QueueItem *item; do { item = head->next; if(item == 0) return false; } while(!compareAndSwapPointer(head->next, item, item->next)); t = item->value; delete item; return true; } }; #ifdef USE_LOCKED_QUEUE template <typename T> class queue : public lockedQueue<T> {}; #else template <typename T> class queue : public locklessQueue<T> {}; #endif #endif // SENSE_UTIL_QUEUE_HPP
If $f$ is continuous on each component of an open set $S$, then $f$ is continuous on $S$.
# Copyright (c) 2018-2021, Carnegie Mellon University # See LICENSE for details @TInt := @.cond(x->x.t=TInt); @TReal := @.cond(x->IsRealT(x.t)); @_scalar := @.cond(x->IsOrdT(x.t) or IsRealT(x.t) or ObjId(x.t)=TPtr); @TVect := @.cond(x->IsVecT(x.t)); @Value := @.cond(x->IsValue(x)); @nth := @.cond(x->ObjId(x)=nth); _isa := self -> self.opts.vector.isa; _epi := (self, o) -> Concat("epi", self.ctype_suffixval(o.t, _isa(self))); _px := (self, o) -> self.ctype_suffixval(o.t, _isa(self)); _vp := (o) -> let(pp := Last(o.args), Cond(ObjId(pp)=vparam, pp.p, IsValue(pp), pp.v, pp)); Class(AVXUnparser, SSEUnparser, rec( # -------------------------------- # ISA constructs, general # ------------------------------- # This is a general suffix for intrinsics that is determine from the data type ctype_suffix := (self, t, isa) >> Cond( t = TVect(T_Real(64), 4), "pd", t = TVect(T_Real(32), 8), "ps", t = TVect(TReal, 4) and isa=AVX_4x64f, "pd", t = TVect(TReal, 8) and isa=AVX_8x32f, "ps", Inherited(t, isa) ), ctype_prefix := (self, t) >> Cond( _avxT(t, self.opts), "_mm256", "_mm" ), # This is the type used for declarations of vector variables ctype := (self, t, isa) >> Cond( t in [TReal, TVect(TReal, 1)], Cond( isa = AVX_4x64f, "double", isa = AVX_8x32f, "float", "UNKNOWN_TYPE"), t = T_Real(64), "double", t = T_Real(32), "float", # else Cond( t = TVect(TReal, 2), Cond( isa = AVX_4x64f, "__m128d", isa = AVX_8x32f, "__m64", "UNKNOWN_TYPE"), t = TVect(TReal, 4), Cond( isa = AVX_4x64f, "__m256d", isa = AVX_8x32f, "__m128", "UNKNOWN_TYPE"), t = TVect(TReal, 8), Cond( isa = AVX_8x32f, "__m256", "UNKNOWN_TYPE"), t = TVect(T_Real(64), 4), "__m256d", t = TVect(T_Real(32), 8), "__m256", t = TVect(T_Int(32), 8), "__m256i", t = TVect(T_UInt(32), 8), "__m256i", t = TVect(T_Real(64), 2), "__m128d", t = TVect(T_Real(32), 4), "__m128", t = TVect(T_Real(32), 2), "__m64", Inherited(t, isa)) ), cvalue_suffix := (self, t) >> let( isa := _isa(self), Cond( (t = TReal and isa = AVX_8x32f) or t = T_Real(32), "f", (t = TReal and isa = AVX_4x64f) or t = T_Real(64), "", Inherited(t) )), vhex := (self, o, i, is) >> Print("_mm_set_", _epi(self, o), "(", self.infix(Reversed(o.p), ", "), ")"), vparam := (self, o, i, is) >> When(Length(o.p)=1, Print(o.p[1]), iclshuffle(o.p)), Value := (self, o, i, is) >> Cond( o.t = TString, Print(o.v), o.t = TReal or ObjId(o.t) = T_Real, let(v := When(IsCyc(o.v), ReComplex(Complex(o.v)), Double(o.v)), When(v<0, Print("(", v, self.cvalue_suffix(o.t), ")"), Print(v, self.cvalue_suffix(o.t)))), o.t = TComplex, Print("COMPLEX(", ReComplex(Complex(o.v)), self.cvalue_suffix(TReal), ", ", ImComplex(Complex(o.v)), self.cvalue_suffix(TReal), ")"), o.t in [TInt, TUChar, TChar], When(o.v < 0, Print("(", o.v, ")"), Print(o.v)), ObjId(o.t) = TVect and Length(Set(o.v)) = 1, Cond( self.cx.isInside(Value) and Length(self.cx.Value) >= 2, # nested in an array Print("{", self.infix(Replicate(o.t.size, o.v[1]), ", "), "}"), # else Cond( _avxT(o.t, self.opts), let( sfx := self.ctype_suffix(o.t, _isa(self)), pfx := self.ctype_prefix(o.t), Cond( o.v[1] = 0, self.printf("$1_setzero_$2()", [pfx, sfx]), self.printf("$1_set1_$2($3)", [pfx, sfx, o.v[1]]))), Inherited(o, i, is))), ObjId(o.t) = TVect, Cond( self.cx.isInside(Value) and Length(self.cx.Value) >= 2, # nested in an array Print("{", self.infix((o.v), ", "), "}"), # else Cond( _avxT(o.t, self.opts), let( sfx := self.ctype_suffix(o.t, _isa(self)), pfx := self.ctype_prefix(o.t), Print(pfx, "_set_", sfx, "(", self.infix(Reversed(o.v), ", "), ")")), Inherited(o, i, is))), IsArray(o.t), Print("{", self.infix(o.v, ", "), "}"), ObjId(o.t) = TSym, Print("(", self.declare(o.t, [], 0, 0), ") ", o.v), o.t = TBool, Print(When(o.v, "1", "0")), #Error(self,".Value cannot unparse type ",o.t) Inherited(o, i, is) ), vpack := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), Print("_mm256_set_", self.ctype_suffix(o.t, _isa(self)), "(", self.infix(Reversed(o.args), ", "), ")"), Inherited(o, i, is)), vdup := (self, o, i, is) >> CondPat(o, [vdup, @(1, [nth, deref]), @TInt], let( isa := _isa(self), t := o.args[1].t, pfx := self.ctype_prefix(o.t), Cond( t = T_Real(32) or (t=TReal and isa=AVX_8x32f), self.printf("$1_broadcast_ss($2)", [pfx, o.args[1].toPtr(t)]), t = T_Real(64) or (t=TReal and isa=AVX_4x64f), self.printf("$1_broadcast_sd($2)", [pfx, o.args[1].toPtr(t)]), t = TVect(T_Real(32), 2) or (t=TVect(TReal, 2) and isa=AVX_8x32f), self.printf("$1_castpd_ps($1_broadcast_sd($2))", [pfx, o.args[1].toPtr(T_Real(64))]), t = TVect(T_Real(64), 2) or (t=TVect(TReal, 2) and isa=AVX_4x64f), self.printf("$1_broadcast_pd($2)", [pfx, o.args[1].toPtr(t)]), t = TVect(T_Real(32), 4) or (t=TVect(TReal, 4) and isa=AVX_8x32f), self.printf("$1_castpd_ps($1_broadcast_pd($2))", [pfx, o.args[1].toPtr(TVect(T_Real(64), 2))]), Error("unexpected vdup load"))), #[vdup, @nth,@.cond(x->x.t=TInt and x.v=2)], # Print("_mm_loaddup_", sfx, "(&(", self(o.args[1], i, is), "))"), [vdup, @, @TInt], Print(When(_isa(self).v = 4, "_mm256_set1_pd", "_mm256_set1_ps"), "(", self(o.args[1], i, is), ")") ), # Declarations TVect := (self, t, vars, i, is) >> let( ctype := self.ctype(t, _isa(self)), Print(ctype, " ", self.infix(vars, ", "))), TReal := ~.TVect, TInt := (self, t, vars, i, is) >> Print("int ", self.infix(vars, ", ")), TBool := (self, t, vars, i, is) >> Print("BOOL ", self.infix(vars, ", ")), # Arithmetic mul := (self, o, i, is) >> let(n := Length(o.args), Cond( not IsVecT(o.t), Print("(", self.pinfix(o.args, ")*("), ")"), not _avxT(o.t, self.opts), Inherited(o, i, is), n > 2 and n mod 2 <> 0, self(mul(o.args[1], ApplyFunc(mul, Drop(o.args, 1))), i, is), n > 2, self(mul(ApplyFunc(mul, o.args{[1..n/2]}), ApplyFunc(mul, o.args{[n/2+1..n]})), i, is), let( sfx := self.ctype_suffix(o.t, _isa(self)), CondPat(o, [mul, @TReal, @TVect], self(mul(vdup(o.args[1],o.t.size), o.args[2]), i, is), [mul, @TVect, @TReal], self(mul(o.args[1], vdup(o.args[2],o.t.size)), i, is), [mul, @TInt, @TVect], self(mul(vdup(_toReal(o.args[1]),o.t.size), o.args[2]), i, is), [mul, @TVect, @TInt], self(mul(o.args[1], vdup(_toReal(o.args[2]),o.t.size)), i, is), [mul, @TVect, @TVect], self.printf("_mm256_mul_$1($2, $3)", [sfx, o.args[1], o.args[2]]), Error("Don't know how to unparse <o>. Unrecognized type combination"))) )), # -- add -- add := (self, o, i, is) >> let(n := Length(o.args), Cond( not IsVecT(o.t), self.pinfix(o.args, " + "), not _avxT(o.t, self.opts), Inherited(o, i, is), n > 2 and n mod 2 <> 0, self(add(o.args[1], ApplyFunc(add, Drop(o.args, 1))), i, is), n > 2, self(add(ApplyFunc(add, o.args{[1..n/2]}), ApplyFunc(add, o.args{[n/2+1..n]})), i, is), let(sfx := self.ctype_suffix(o.t, _isa(self)), saturated:= When(_isa(self).isFixedPoint and _isa(self).saturatedArithmetic, "s", ""), CondPat(o, [add, @TReal, @TVect], self(add(vdup(o.args[1],o.t.size), o.args[2]), i, is), [add, @TVect, @TReal], self(add(o.args[1], vdup(o.args[2],o.t.size)), i, is), [add, @TInt, @TVect], self(add(vdup(_toReal(o.args[1]),o.t.size), o.args[2]), i, is), [add, @TVect, @TInt], self(add(o.args[1], vdup(_toReal(o.args[2]),o.t.size)), i, is), [add, @TVect, @TVect], self.printf("_mm256_add$1_$2($3, $4)", [saturated, sfx, o.args[1], o.args[2]]), Error("Don't know how to unparse <o>. Unrecognized type combination"))) )), sub := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), let( isa := _isa(self), sfx := self.ctype_suffix(o.t, isa), saturated := When(isa.isFixedPoint and isa.saturatedArithmetic, "s", ""), self.printf("_mm256_sub$1_$2($3, $4)", [saturated, sfx, o.args[1], o.args[2]])), # else Inherited(o, i, is)), neg := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), self(mul(neg(o.t.one()), o.args[1]), i, is), Inherited(o, i, is)), stickyNeg := ~.neg, sqrt := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), Checked( IsRealT(o.t.t), self.printf("_mm256_sqrt_$1($2)", [self.ctype_suffix(o.t, _isa(self)), o.args[1]])), Inherited(o, i, is)), rsqrt := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), let( sfx := self.ctype_suffix(o.t, _isa(self)), Checked( sfx="ps", self.printf("_mm256_rsqrt_ps($1)", [o.args[1]]))), Inherited(o, i, is)), max := (self, o, i, is) >> let(n := Length(o.args), Cond( not _avxT(o.t, self.opts), Inherited(o, i, is), n > 2 and n mod 2 <> 0, self(max(o.args[1], ApplyFunc(max, Drop(o.args, 1))), i, is), n > 2, self(max(ApplyFunc(max, o.args{[1..n/2]}), ApplyFunc(max, o.args{[n/2+1..n]})), i, is), let( sfx := self.ctype_suffix(o.t, _isa(self)), CondPat(o, [max, @TReal, @TVect], self(max(vdup(o.args[1],o.t.size), o.args[2]), i, is), [max, @TVect, @TReal], self(max(o.args[1], vdup(o.args[2],o.t.size)), i, is), [max, @TInt, @TVect], self(max(vdup(_toReal(o.args[1]),o.t.size), o.args[2]), i, is), [max, @TVect, @TInt], self(max(o.args[1], vdup(_toReal(o.args[2]),o.t.size)), i, is), [max, @TVect, @TVect], self.printf("_mm256_max_$1($2, $3)", [sfx, o.args[1], o.args[2]]), Error("Don't know how to unparse <o>. Unrecognized type combination"))) )), min := (self, o, i, is) >> let(n := Length(o.args), Cond( not _avxT(o.t, self.opts), Inherited(o, i, is), n > 2 and n mod 2 <> 0, self(min(o.args[1], ApplyFunc(min, Drop(o.args, 1))), i, is), n > 2, self(min(ApplyFunc(min, o.args{[1..n/2]}), ApplyFunc(min, o.args{[n/2+1..n]})), i, is), let( sfx := self.ctype_suffix(o.t, _isa(self)), CondPat(o, [min, @TReal, @TVect], self(min(vdup(o.args[1],o.t.size), o.args[2]), i, is), [min, @TVect, @TReal], self(min(o.args[1], vdup(o.args[2],o.t.size)), i, is), [min, @TInt, @TVect], self(min(vdup(_toReal(o.args[1]),o.t.size), o.args[2]), i, is), [min, @TVect, @TInt], self(min(o.args[1], vdup(_toReal(o.args[2]),o.t.size)), i, is), [min, @TVect, @TVect], self.printf("_mm256_min_$1($2, $3)", [sfx, o.args[1], o.args[2]]), Error("Don't know how to unparse <o>. Unrecognized type combination"))) )), # assuming we have ICC <ia32intrin.h> here log := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), let( sfx := self.ctype_suffix(o.t, _isa(self)), Checked( sfx in ["ps", "pd"], Cond( Length(o.args)>1 and (o.args[2]=2 or o.args[2]=o.t.value(2)), self.printf("_mm256_log2_$1($2)", [sfx, o.args[1]]), Length(o.args)>1 and (o.args[2]=10 or o.args[2]=o.t.value(10)), self.printf("_mm256_log10_$1($2)", [sfx, o.args[1]]), Length(o.args)=1 or o.args[2]=d_exp(1) or o.args[2]=o.t.value(d_exp(1)), self.printf("_mm256_log_$1($2)", [sfx, o.args[1]]), self.printf("_mm256_div_$1(_mm256_log_$1($2), _mm256_log_$1($3))", [sfx, o.args[1]])))), Inherited(o, i, is)), # assuming we have ICC <ia32intrin.h> here exp := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), let( sfx := self.ctype_suffix(o.t, _isa(self)), Checked( sfx in ["ps", "pd"], self.printf("_mm256_exp_$1($2)", [sfx, o.args[1]]))), Inherited(o, i, is)), # assuming we have ICC <ia32intrin.h> here pow := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), let( sfx := self.ctype_suffix(o.t, _isa(self)), Checked( sfx in ["ps", "pd"], Cond( o.args[1]=2 or o.args[1]=o.t.value(2), self.printf("_mm256_exp2_$1($2)", [sfx, o.args[2]]), o.args[1]=d_exp(1) or o.args[1]=o.t.value(d_exp(1)), self.printf("_mm256_exp_$1($2)", [sfx, o.args[2]]), self.printf("_mm256_pow_$1($2, $3)", [sfx, o.args[1], o.args[2]])))), Inherited(o, i, is)), # -------------------------------- # logic # bin_xor := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), self.printf("_mm256_xor_$1($2, $3)", [self.ctype_suffix(o.t, _isa(self)), o.args[1], o.args[2]]), Inherited(o, i, is)), bin_and := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), self.printf("_mm256_and_$1($2, $3)", [self.ctype_suffix(o.t, _isa(self)), o.args[1], o.args[2]]), Inherited(o, i, is)), bin_or := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), self.printf("_mm256_or_$1($2, $3)", [self.ctype_suffix(o.t, _isa(self)), o.args[1], o.args[2]]), Inherited(o, i, is)), bin_andnot := (self, o, i, is) >> Cond( _avxT(o.t, self.opts), self.printf("_mm256_andnot_$1($2, $3)", [self.ctype_suffix(o.t, _isa(self)), o.args[1], o.args[2]]), Inherited(o, i, is)), # -------------------------------- # ISA specific : AVX_4x64f # cmpge_4x64f := (self, o, i, is) >> self.prefix("_mm256_cmp_pd", Concat(o.args, ["_CMP_GE_OQ"])), logic_and_4x64f := (self, o, i, is) >> self.prefix("_mm256_and_pd", o.args), logic_xor_4x64f := (self, o, i, is) >> self.prefix("_mm256_xor_pd", o.args), vloadu_4x64f := (self, o, i, is) >> self.prefix("_mm256_loadu_pd", o.args), vstoreu_4x64f := (self, o, i, is) >> Print(Blanks(i), self.prefix("_mm256_storeu_pd", o.args), ";\n"), vinsert_2l_4x64f := (self, o, i, is) >> self.prefix("_mm256_insertf128_pd", o.args), vloadmask_4x64f := (self, o, i, is) >> self.printf("_mm256_maskload_pd($1, _mm256_set_epi32($2))", [o.args[1], ()->PrintDel(_vp(o), ", ")]), vbroadcast_4x64f := (self, o, i, is) >> self.printf("_mm256_broadcast_sd($1)", [o.args[1]]), # doublecheck this vextract_2l_4x64f := (self, o, i, is) >> self.prefix("_mm256_extractf128_pd", o.args), vstore_2l_4x64f := (self, o, i, is) >> self.prefix("_mm256_extractf128_pd", o.args), vstoremask_4x64f := (self, o, i, is) >> Print(Blanks(i), self.printf("_mm256_maskstore_pd($1, _mm256_set_epi32($3), $2)", [o.args[1], o.args[2], ()->PrintDel(List(_vp(o), e->e.v), ", ")]), ";\n"), vunpacklo_4x64f := (self, o, i, is) >> self.prefix("_mm256_unpacklo_pd", o.args), vunpackhi_4x64f := (self, o, i, is) >> self.prefix("_mm256_unpackhi_pd", o.args), vpermf128_4x64f := (self, o, i, is) >> self.printf("_mm256_permute2f128_pd($1, $2, ($3) | (($4) << 4))", let(l := _vp(o)-1, [o.args[1], o.args[2], l[1], l[2]])), vshuffle_4x64f := (self, o, i, is) >> self.printf("_mm256_shuffle_pd($1, $2, ($3) | (($4) << 1) | (($5) << 2) | (($6) << 3))", let(l := _vp(o)-1, [o.args[1], o.args[2], l[1], l[2], l[3], l[4]])), vperm_4x64f := (self, o, i, is) >> self.printf("_mm256_permute_pd($1, ($2) | (($3) << 1) | (($4) << 2) | (($5) << 3))", let(l := _vp(o)-1, [o.args[1], l[1], l[2], l[3], l[4]])), vblend_4x64f := (self, o, i, is) >> self.printf("_mm256_blend_pd($1, $2, ($3) | (($4) << 1) | (($5) << 2) | (($6) << 3))", let(l := _vp(o)-1, [o.args[1], o.args[2], l[1], l[2], l[3], l[4]])), vuunpacklo_4x64f := (self, o, i, is) >> self(o.toBinop(), i, is), vuunpackhi_4x64f := (self, o, i, is) >> self(o.toBinop(), i, is), vupermf128_4x64f := (self, o, i, is) >> self(o.toBinop(), i, is), vushuffle_4x64f := (self, o, i, is) >> self(o.toBinop(), i, is), vuperm2_4x64f := (self, o, i, is) >> self(o.toBinop(), i, is), addsub_4x64f := (self, o, i, is) >> When(Length(o.args) > 2, Error("addsub_2x64f is strictly binary"), CondPat(o, [addsub_4x64f, @TReal, @TVect], self(_computeExpType(addsub_4x64f(vdup(o.args[1],o.t.size), o.args[2])), i, is), [addsub_4x64f, @TVect, @TReal], self(_computeExpType(addsub_4x64f(o.args[1], vdup(o.args[2],o.t.size))), i, is), [addsub_4x64f, @TInt, @TVect], self(_computeExpType(addsub_4x64f(vdup(_toReal(o.args[1]),o.t.size), o.args[2])), i, is), [addsub_4x64f, @TVect, @TInt], self(_computeExpType(addsub_4x64f(o.args[1], vdup(_toReal(o.args[2]),o.t.size))), i, is), [addsub_4x64f, @TVect, @TVect], self.printf("_mm256_addsub_pd($1, $2)", [o.args[1], o.args[2]]), Error("Don't know how to unparse <o>. Unrecognized type combination") )), fmaddsub_4x64f := (self, o, i, is) >> When( Length(o.args) <> 3, Error("fmaddsub_4x64f is strictly ternary"), CondPat(o, [fmaddsub_4x64f, @TVect, @TVect, @TVect], self.printf("_mm256_fmaddsub_pd($1, $2, $3, 0)", [o.args[1], o.args[2], o.args[3]]), Error("Don't know how to unparse <o>. Unrecognized type combination") )), vzero_4x64f := (self, o, i, is) >> Print("_mm256_setzero_pd()"), # -------------------------------- # ISA specific : AVX_8x32f # logic_and_8x32f := (self, o, i, is) >> self.prefix("_mm256_and_ps", o.args), logic_xor_8x32f := (self, o, i, is) >> self.prefix("_mm256_xor_ps", o.args), vloadu_8x32f := (self, o, i, is) >> self.prefix("_mm256_loadu_ps", o.args), vstoreu_8x32f := (self, o, i, is) >> Print(Blanks(i), self.prefix("_mm256_storeu_ps", o.args), ";\n"), vinsert_4l_8x32f := (self, o, i, is) >> self.prefix("_mm256_insertf128_ps", o.args), vloadmask_8x32f := (self, o, i, is) >> self.printf("_mm256_maskload_ps($1, _mm256_set_epi32($2))", [o.args[1], ()->PrintDel(_vp(o), ", ")]), vhdup_8x32f := (self, o, i, is) >> self.printf("_mm256_movehdup_ps($1)", [o.args[1]]), vldup_8x32f := (self, o, i, is) >> self.printf("_mm256_moveldup_ps($1)", [o.args[1]]), vextract_4l_8x32f := (self, o, i, is) >> self.prefix("_mm256_extractf128_ps", o.args), vstore_4l_8x32f := (self, o, i, is) >> self.prefix("_mm256_extractf128_ps", o.args), vstoremask_8x32f := (self, o, i, is) >> Print(Blanks(i), self.printf("_mm256_maskstore_ps($1, _mm256_set_epi32($3), $2)", [o.args[1], o.args[2], ()->PrintDel(List(_vp(o), e->e.v), ", ")]), ";\n"), vunpacklo_8x32f := (self, o, i, is) >> self.prefix("_mm256_unpacklo_ps", o.args), vunpackhi_8x32f := (self, o, i, is) >> self.prefix("_mm256_unpackhi_ps", o.args), vpermf128_8x32f := (self, o, i, is) >> self.printf("_mm256_permute2f128_ps($1, $2, ($3) | (($4) << 4))", let(l := _vp(o)-1, [o.args[1], o.args[2], l[1], l[2]])), vshuffle_8x32f := (self, o, i, is) >> self.printf("_mm256_shuffle_ps($1, $2, ($3) | (($4) << 2) | (($5) << 4) | (($6) << 6))", let(l := _vp(o)-1, [o.args[1], o.args[2], l[1], l[2], l[3], l[4]])), vperm_8x32f := (self, o, i, is) >> self.printf("_mm256_permute_ps($1, ($2) | (($3) << 2) | (($4) << 4) | (($5) << 6))", let(l := _vp(o)-1, [o.args[1], l[1], l[2], l[3], l[4]])), vblend_8x32f := (self, o, i, is) >> self.printf("_mm256_blend_ps($1, $2, ($3) | (($4) << 1) | (($5) << 2) | (($6) << 3) | (($7) << 4) | (($8) << 5) | (($9) << 6) | (($10) << 7))", let(l := _vp(o)-1, [o.args[1], o.args[2], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8]])), vuunpacklo_8x32f := (self, o, i, is) >> self(o.toBinop(), i, is), vuunpackhi_8x32f := (self, o, i, is) >> self(o.toBinop(), i, is), vupermf128_8x32f := (self, o, i, is) >> self(o.toBinop(), i, is), vushuffle_8x32f := (self, o, i, is) >> self(o.toBinop(), i, is), addsub_8x32f := (self, o, i, is) >> When(Length(o.args) > 2, Error("addsub_2x64f is strictly binary"), CondPat(o, [addsub_8x32f, @TReal, @TVect], self(_computeExpType(addsub_8x32f(vdup(o.args[1],o.t.size), o.args[2])), i, is), [addsub_8x32f, @TVect, @TReal], self(_computeExpType(addsub_8x32f(o.args[1], vdup(o.args[2],o.t.size))), i, is), [addsub_8x32f, @TInt, @TVect], self(_computeExpType(addsub_8x32f(vdup(_toReal(o.args[1]),o.t.size), o.args[2])), i, is), [addsub_8x32f, @TVect, @TInt], self(_computeExpType(addsub_8x32f(o.args[1], vdup(_toReal(o.args[2]),o.t.size))), i, is), [addsub_8x32f, @TVect, @TVect], self.printf("_mm256_addsub_ps($1, $2)", [o.args[1], o.args[2]]), Error("Don't know how to unparse <o>. Unrecognized type combination") )), fmaddsub_8x32f := (self, o, i, is) >> When( Length(o.args) <> 3, Error("fmaddsub_8x32f is strictly ternary"), CondPat(o, [fmaddsub_8x32f, @TVect, @TVect, @TVect], self.printf("_mm256_fmaddsub_ps($1, $2, $3, 0)", [o.args[1], o.args[2], o.args[3]]), Error("Don't know how to unparse <o>. Unrecognized type combination") )), vzero_8x32f := (self, o, i, is) >> Print("_mm256_setzero_ps()"), #-------------------------------- # Conversion vcvt_8x32f_4x64f := (self, o, i, is) >> self.printf("_mm256_cvtpd_ps($1)", [o.args[1]]), vcvt_4x64f_4x32f := (self, o, i, is) >> self.printf("_mm256_cvtps_pd($1)", [o.args[1]]), vcvt_4x64f_4x32i := (self, o, i, is) >> self.printf("_mm256_cvtepi32_pd($1)", [o.args[1]]), vcvt_4x32i_4x64f := (self, o, i, is) >> self.printf("_mm256_cvtpd_epi32($1)", [o.args[1]]), vcvtt_4x32i_4x64f := (self, o, i, is) >> self.printf("_mm256_cvttpd_epi32($1)", [o.args[1]]), vcvt_8x32f_8x32i := (self, o, i, is) >> self.printf("_mm256_cvtepi32_ps($1)", [o.args[1]]), vcvt_8x32i_8x32f := (self, o, i, is) >> self.printf("_mm256_cvtps_epi32($1)", [o.args[1]]), vcvtt_8x32i_8x32f := (self, o, i, is) >> self.printf("_mm256_cvttps_epi32($1)", [o.args[1]]), ));
\xchapter{Evaluation}{}\label{chap:evaluation} In this chapter, we evaluate our model by solving two variations of the source code attribution problem. In Section \ref{sec:validation}, we describe how we selected the parameters of our model. In Section \ref{sec:matching}, we solve the authorship matching problem suggested in Chapter \ref{chap:methodology}. In Section \ref{sec:one_to_many}, we solve a closed-world identification problem. \section{Training and Selection}\label{sec:validation} We trained and validated the proposed model with Tensorflow. We picked the training samples from a balanced dataset with 20,000 C++ examples from 1,000 authors. A validation set was built from another 3,200 samples from 400 authors. No author from the training set was present on the validation set. All the samples were extracted from the Codeforces dataset. Although programming competitions resemble laboratory conditions, it is common for participants to code on top of a pre-written file, usually called \textit{template}. Although the constructions present on a template file are usually written by the author himself, they are not always used by the piece of code actually written during the competition. Therefore, it is interesting to analyze how classifiers perform when such constructions are stripped out of the code. For that end, we used \textit{clang}\footnote{\url{https://clang.llvm.org}} to remove unused pieces of code from a C++ program. Moreover, we also removed macros, a construction heavily present in templates of competitive programmers. Therefore, we built two versions of each dataset: one composed of raw source codes and other composed of codes processed by \textit{clang}. We optimized the model parameters with \textit{RMSprop} \cite{rmsprop} for a maximum of 50 epochs, or until the evaluated equal error rate (EER) of the model on the validation set had no improvement for 5 epochs. We used a learning rate of $10^{-3}$. The version that yielded the highest EER was taken as the final model. During this process, we carefully tuned its hyperparameters. Finally, we trained two different models with such hyperparameters: one on the raw version of the dataset and other on the \textit{clang} processed version. \section{Matching Two Unknown Source Codes}\label{sec:matching} \begin{figure}[ht] \centering \includegraphics[width=0.7\linewidth]{imgs/roc_complete.png} \caption{ROC curve for each pair of classifier and dataset version.} \label{fig:roc_complete} \end{figure} Using the models we trained, we tried to solve the problem of deciding if two source codes are from the same author. For that end, we constructed a test dataset with 3,200 samples from 400 authors. These samples were extracted from the Codeforces dataset, but this set has no intersection of authors with the training and validation sets used to train the models. Therefore, the authors are unknown to the system. Moreover, we ran \textit{clang} on the samples, obtaining a \textit{clang} processed version of the test dataset. Finally, we ran four evaluations, one for each combination of model and test dataset. The results can be seen in Fig. \ref{fig:roc_complete} and Table \ref{tab:matching}. \begin{table}[ht] \centering \begin{tabular}{ccr} \cline{2-3} \multicolumn{1}{l}{} & \multicolumn{2}{c}{\textbf{EER (\%)}} \\ \cline{2-3} \textbf{} & \textbf{Raw Test Set} & \multicolumn{1}{l}{\textbf{\textit{clang} Test Set}} \\ \hline %\textbf{CNN (trained on raw version)} & \multicolumn{1}{r}{16.31} & 16.88 \\ \hline %\textbf{CNN (trained on \textit{clang} version)} & \multicolumn{1}{r}{16.82} & 16.90 \\ \hline \textbf{LSTM (trained on raw version)} & \multicolumn{1}{r}{13.88} & 12.24 \\ \hline \textbf{LSTM (trained on \textit{clang} version)} & \multicolumn{1}{r}{13.25} & 11.60 \\ \hline \end{tabular} \caption{Equal error rate (EER) evaluation of the trained models on each test set.} \label{tab:matching} \end{table} We can notice that the performance on raw source codes is slightly worse than the others. This can be related to the fact that tested authors are not present in training and validation sets. The model is probably relying more on features present on templates, instead of on stylistic features of the written code. Therefore, the embeddings generalize poorly to unknown authors. The better performance of the \textit{clang} combination supports this claim by showing that learning from features of the written code yields better generalization. \section{One-to-Many Author Identification}\label{sec:one_to_many} We also evaluated our models on the problem posed by \citeauthoronline{caliskan_2015}. In their work, 9 C++ source codes from 250 programmers are extracted from the Google Code Jam dataset. From these, 8 are used for training and one for testing. We simply took the models we trained for the previous experiment , added a fully-connected layer and replaced triplet loss with softmax cross-entropy loss. Then, we trained this layer on the $250 \times 8$ source codes for more epochs. The rank-$n$ metric evaluations, for $n = 1$ and $n = 3$, can be seen in Table \ref{tab:rank}. \begin{table}[hb] \centering \begin{tabular}{lrrrr} \cline{2-5} & \multicolumn{2}{c}{\textbf{rank-1 (\%)}} & \multicolumn{2}{c}{\textbf{rank-3 (\%)}} \\ \cline{2-5} \multicolumn{1}{c}{\textbf{}} & \multicolumn{1}{c}{\textbf{Raw Test}} & \multicolumn{1}{l}{\textbf{Clang Test}} & \multicolumn{1}{l}{\textbf{Raw Test}} & \multicolumn{1}{l}{\textbf{Clang Test}} \\ \hline \textbf{LSTM (trained on raw)} & 74.8\% & 67.0\% & 84.4\% & 79.6\% \\ \hline \textbf{LSTM (trained on clang)} & 65.0\% & 69.0\% & 78.8\% & 82.8\% \\ \hline \textbf{\citeauthoronline{caliskan_2015}} & 95.1\% & n/a & n/a & n/a \\ \hline \end{tabular} \caption{Rank-$n$ metric for the one-to-many identification problem on 250 programmers of the Google Code Jam dataset. } \label{tab:rank} \end{table} Although we were not able to match the Random Forest model proposed by \citeauthoronline{caliskan_2015}, we are able to show that the generated descriptors are discriminative. Fig. \ref{fig:embedding} shows the style descriptors of source codes from 12 programmers of Google Code Jam dataset. They were embedded into a two-dimensional space for better visualization. \begin{figure}[ht] \centering \includegraphics[width=0.7\linewidth]{imgs/embedding.png} \caption{128-dimensional descriptors from 12 authors generated by the LSTM model, trained and test on the \textit{clang} test set. The descriptors were embedded into a two-dimensional space with t-SNE.} \label{fig:embedding} \end{figure}
r=359.41 https://sandbox.dams.library.ucdavis.edu/fcrepo/rest/collection/sherry-lehmann/catalogs/d7jp4g/media/images/d7jp4g-037/svc:tesseract/full/full/359.41/default.jpg Accept:application/hocr+xml
header {* \isachapter{Instantiating the Framework with a simple While-Language using procedures} \isaheader{Commands} *} theory Com imports "../StaticInter/BasicDefs" begin subsection {* Variables and Values *} type_synonym vname = string -- "names for variables" type_synonym pname = string -- "names for procedures" datatype val = Bool bool -- "Boolean value" | Intg int -- "integer value" abbreviation "true == Bool True" abbreviation "false == Bool False" subsection {* Expressions *} datatype bop = Eq | And | Less | Add | Sub -- "names of binary operations" datatype expr = Val val -- "value" | Var vname -- "local variable" | BinOp expr bop expr ("_ \<guillemotleft>_\<guillemotright> _" [80,0,81] 80) -- "binary operation" fun binop :: "bop \<Rightarrow> val \<Rightarrow> val \<Rightarrow> val option" where "binop Eq v\<^sub>1 v\<^sub>2 = Some(Bool(v\<^sub>1 = v\<^sub>2))" | "binop And (Bool b\<^sub>1) (Bool b\<^sub>2) = Some(Bool(b\<^sub>1 \<and> b\<^sub>2))" | "binop Less (Intg i\<^sub>1) (Intg i\<^sub>2) = Some(Bool(i\<^sub>1 < i\<^sub>2))" | "binop Add (Intg i\<^sub>1) (Intg i\<^sub>2) = Some(Intg(i\<^sub>1 + i\<^sub>2))" | "binop Sub (Intg i\<^sub>1) (Intg i\<^sub>2) = Some(Intg(i\<^sub>1 - i\<^sub>2))" | "binop bop v\<^sub>1 v\<^sub>2 = None" subsection {* Commands *} datatype cmd = Skip | LAss vname expr ("_:=_" [70,70] 70) -- "local assignment" | Seq cmd cmd ("_;;/ _" [60,61] 60) | Cond expr cmd cmd ("if '(_') _/ else _" [80,79,79] 70) | While expr cmd ("while '(_') _" [80,79] 70) | Call pname "expr list" "vname list" --"Call needs procedure, actual parameters and variables for return values" fun num_inner_nodes :: "cmd \<Rightarrow> nat" ("#:_") where "#:Skip = 1" | "#:(V:=e) = 2" (* additional Skip node *) | "#:(c\<^sub>1;;c\<^sub>2) = #:c\<^sub>1 + #:c\<^sub>2" | "#:(if (b) c\<^sub>1 else c\<^sub>2) = #:c\<^sub>1 + #:c\<^sub>2 + 1" | "#:(while (b) c) = #:c + 2" (* additional Skip node *) | "#:(Call p es rets) = 2" (* additional Skip (=Return) node *) lemma num_inner_nodes_gr_0 [simp]:"#:c > 0" by(induct c) auto lemma [dest]:"#:c = 0 \<Longrightarrow> False" by(induct c) auto end
On November 8 , 2012 , DC announced that Hellblazer would be cancelled following its 300th issue , and would be replaced by Constantine written by Robert Venditti and drawn by Renato Guedes starring the younger New 52 John Constantine , rather than the version from Hellblazer , depicted as being in his late 50s . The Constantine series finally ended its run on its 23rd issue in May 1 , 2015 . Nonetheless , the character would again star in another solo series entitled Constantine : The Hellblazer , written by Ming Doyle and art by Riley Rossmo , and released in June 10 , 2015 . Writer Ming Doyle expressed excitement in her chance to write Constantine , stating that the reason of putting the term Hellblazer back to the character 's title was to " take Constantine back to what he was at the start . "
Description: Blatte De Jardin Dans La Maison from the above 300x243 resolutions which is part of the Jardin Bois directory. Download this image for free in HD resolution the choice "download button" below. If you do not find the exact resolution you are looking for, then go for a native or higher resolution. or if you are interested in similar pictures of Blatte De Jardin Dans La Maison, you are free to browse through search feature or related post section at below of this post. You can bookmark our site to get more update related to Blatte De Jardin Dans La Maison or any other topic. This Blatte De Jardin Dans La Maison is provided only for personal use as image on computers, smartphones or other display devices. If you found any images copyrighted to yours, please contact us and we will remove it. We don't intend to display any copyright protected images.
The fractional part of the sum of two real numbers is the sum of the fractional parts of the two real numbers.
module FunSetPerBool where data Bool : Set where True : Bool False : Bool data T : Set where E : T s : Bool -> Set s True = Bool s False = T f = \ (x : s True) -> x g = f True f2 = \ (x : Bool) (y : s x) -> y h = f2 False E -- i : (xx : _) -> _ i = f2 True j : (eh : s False) -> s False j = f2 False
The GRAPH’IT colour chart becomes infinite with the Mix’it by GRAPH’IT marker palette! The essential accessory for mixing! The Mix’it pallet is a translucent sheet made of a non-porous, tear-resistant synthetic material. Because this paper retains the ink from the markers and is waterproof. It is the perfect tool for mixing alcohol-based markers or water-based markers. Use your Blender GRAPH’IT marker as a brush: work on your colours until you obtain the desired shade, then pick up the mix with the blender and apply it on your drawing. You can also just pick up a single colour to create shadings. Because the colour stays on the surface of the non-porous palette, you can go back to a colour months later and reactivate it with the blender. The use of the Blender is ideal for detail work and shadow retouching in particular. Blender mixes can be used to obtain pastel or extremely light shades. In this way, traditional gradients can be better mastered beforehand on pallets and then applied on paper. Mix’It also allows you to archive your own colours: even when dry, the mixes can be reactivated simply by using the Blender. In this way, the shades created can be preserved and re-used. The GRAPH’IT colour chart no longer has any limits! Easily create new shades of tints according to your desires with this palette. Reusable, the palette can be cleaned with alcohol or with the Mix’it Fluid.
[STATEMENT] lemma mset_heap_empty_iff: "mset_heap h = {#} \<longleftrightarrow> h = Empty" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (mset_heap h = {#}) = (h = Empty) [PROOF STEP] by (cases h) auto
setup: ```python import numpy as np import matplotlib.pyplot as plt from numba import njit, prange import matplotlib.pyplot as plt import math plt.style.use("seaborn-talk") ``` ```python def plot_performance(time_dict): mean = [t.average for t in time_dict.values()] std = [t.stdev for t in time_dict.values()] x = range(len(time_dict)) plt.errorbar(x, mean, yerr=std, lw=3, fmt="o") plt.xticks( np.arange(len(time_dict)), time_dict.keys()) plt.ylabel("average execution time (s)") plt.grid() ``` # Optimization ## Memoization Remember the fibonnaci problem we had in the debugging lecture? ```python GOLDEN = (1 + 5 ** 0.5) / 2 def fibonacci(k): if k == 0: return 0 if k == 1: return 1 return fibonacci(k - 2) + fibonacci(k - 1) def compute_golden_ratio(accuracy_level=10): return fibonacci(accuracy_level) / fibonacci(accuracy_level - 1) def plot_golden_ratio_approx(max_k=20): ratios = [] for ii in range(2, max_k): ratio = compute_golden_ratio(ii) ratios.append(ratio - GOLDEN) plt.axhline(0, alpha=0.5, lw=3, color="red") plt.scatter(range(2, max_k), ratios) plt.ylabel("difference from Golden Ratio") ``` ```python ``` We got it to work, but there is still one problem: it's super slow ```python t = {} for ii in range(30): t[ii] = %timeit -o -n1 -r1 fibonacci(ii) plot_performance(t) ``` *uh oh!* We seem to have an algorithm that is $O(k^N)$! Can we fix it? ```python ``` ```python ``` ## Speed up a real-world problem! Here your task is to speed up an algorithm for finding the solution to the *Heat Equation* in 2D using a finite-difference method, given an initial temperature distribution. the heat equation is defined as: $$ \frac{du}{dt} = \alpha \nabla^2 u$$ Where $u$ is the temperature. This can be approximated simply by iterating in time and approximating the spatial gradient using neighboring array elements. For time-step $k$ of width $\Delta t$ and spatial width $\Delta x$: \begin{equation} \frac{u^{k+1}_{ij}-u^k_{ij}}{\Delta t} = \frac{\alpha}{(\Delta x)^2} \left( u^k_{i,j-1} + u^k_{i-1,j} - 4 u^k_{i,j} + u^k_{i+1,j} + u^k_{i,j+1}\right) \end{equation} Below we give a naïeve way to solve this, using for-loops (which are not ideal in python). See if you can speed this up by either: 1. re-writing the code to use numpy to get rid of the spatial loops 2. using cython or numba to compile the function (may need to experiment also with some of their compile options) You should also try to see what the memory usage is! (hint: use the memory_profiler module). Is there a memory leak? #### the setup: set up the initial condtions (defining the temperature at the boundary, as well as some hot-spots that are initially at a particular temperature) ```python N=100; M=100 # define the spatial grid grid = np.zeros(shape=(N,M)) grid[10:40,:] = 100 # a hot-spot on the border grid[1:-1,1:-1] = 50 # some initial temperature in the middle grid[60:80, 40:60] = 150 # a hot-spot initially heated at the start, that will cool down plt.pcolormesh(grid) plt.colorbar() plt.title("initial conditions") ``` ```python def solve_heat_equation_loops(init_cond, iterations=100, delta_x=1.0, alpha=1.0): delta_t = delta_x**2/(4*alpha) prev = np.copy(init_cond) cur = np.copy(init_cond) N,M = init_cond.shape for k in range(iterations): for i in range(1,N-1): for j in range(1,M-1): cur[i,j] = prev[i,j] + alpha*delta_t/delta_x**2 * ( prev[i,j-1] + prev[i-1,j] - 4*prev[i,j] + prev[i,j+1] + prev[i+1,j] ) prev,cur = cur,prev #swap pointers return prev ``` We'll also define a convenience function to test the results (you can use this same plotter with your own solver) ```python def plot_heat_equation(solver, iters=(2,10,100,1000)): fig, axes = plt.subplots(1,len(iters), figsize=(15,3)) fig.suptitle(solver.__name__) for ii, iterations in enumerate(iters): result = solver(init_cond=grid, iterations=iterations) axes[ii].pcolormesh(result, vmin=0, vmax=100) axes[ii].set_title("{} iterations".format(iterations)) ``` ```python plot_heat_equation(solver=solve_heat_equation_loops) ``` Note that our code is quite slow... ### Your turn! ***Write an improved verson*** * how much faster is your version on average? * how much memory does it use on average? Is it more than the loop version? * which line is the slowest line? (hint: if done right, you should get a factor of about 100 speed increase) ```python def my_heat_equation_solver(init_cond, iterations=100, delta_x=1.0, alpha=1.0): ## your code here return init_cond # replace with real return value ``` ```python #plot_heat_equation(solver=my_heat_equation_solver) ``` ### SOLUTION there are many ways to achieve this... ```python ITERATIONS=50 results = {} r = %timeit -o solve_heat_equation_loops(grid, iterations=50) results['loop'] = r ``` #### using Numba: ```python from numba import jit solve_heat_equation_numba = njit(solve_heat_equation_loops) ``` ```python r = %timeit -o solve_heat_equation_numba(grid, iterations=50) results['numba'] = r ``` ```python # (Note: open some views so we can see this always) plt.figure(figsize=(5,5)) plot_performance(results) plt.semilogy() ``` #### using numpy using range-slicing `array[start:end,start:end]` we can get rid of the inner for-loops and turn that part into vector operations ```python def solve_heat_equation_numpy(init_cond, iterations=100, delta_x=1.0, alpha=1.0): delta_t = delta_x**2/(4*alpha) prev = np.copy(init_cond) cur = np.copy(init_cond) # define some slices to make it easier to type # just avoids too many things like prev[1:-1,1:-1]) Z = slice(1,-1) # zero P = slice(2,None) # plus 1 M = slice(0,-2) # minus 1 for k in range(iterations): cur[Z,Z] = ( prev[Z,Z] + alpha*delta_t/delta_x**2 * ( prev[Z,M] + prev[M,Z] - 4.0*prev[Z,Z] + prev[Z,P] + prev[P,Z] ) ) prev,cur = cur,prev # swap the pointers return prev # since we swapped, prev is the most recent ``` ```python plot_heat_equation(solver=solve_heat_equation_numpy) ``` ```python r = %timeit -o solve_heat_equation_numpy(grid, iterations=ITERATIONS) results['numpy'] = r ``` #### With numpy and numba ```python solve_heat_equation_numpy_numba = njit(solve_heat_equation_numpy) # "prime" it (compile) plot_heat_equation(solver=solve_heat_equation_numpy_numba) ``` ```python r = %timeit -o solve_heat_equation_numpy_numba(grid, iterations=ITERATIONS) results['numpy\nnumba'] = r ``` #### using cython: Cython is a special python-like language that is translated into C-code (or C++ if you request it), and then compiled with your C compiler with a python binding produced automatically. It has to be explicity compiled (unlike Numba which is "just in time" (JIT) compiled) ```python %load_ext cython ``` ```cython %%cython cimport numpy as cnp import numpy as np def solve_heat_equation_cython(init_cond, int iterations=100, double delta_x=1.0, double alpha=1.0): cdef int i,j,k, N, M cdef float delta_t cdef cnp.ndarray[double, mode="c", ndim=2] prev, cur # this seems to give the biggest improvement delta_t = delta_x**2/(4*alpha) prev = np.copy(init_cond) cur = np.copy(init_cond) N,M = init_cond.shape for k in range(iterations): for i in range(1,N-1): for j in range(1,M-1): cur[i,j] = prev[i,j] + alpha*delta_t/delta_x**2 * ( prev[i,j-1] + prev[i-1,j] - 4*prev[i,j] + prev[i,j+1] + prev[i+1,j] ) prev,cur = cur,prev return prev ``` Try running the previous cell with `%%cython -a` to get an annotated version to see what it did! ```python r = %timeit -o solve_heat_equation_cython(grid, iterations=ITERATIONS) results['cython'] = r ``` #### results ```python plot_performance(results) plt.semilogy() ``` ### We will come back to this in the next lecture #### with some parallelization ```python solve_heat_equation_numpy_numba_parallel = njit(solve_heat_equation_numpy, parallel=True) ``` ```python plot_heat_equation(solver=solve_heat_equation_numpy_numba_parallel) ``` ```python r = %timeit -o solve_heat_equation_numpy_numba_parallel(grid, iterations=50) results['numpy\nnumba\nparallel'] = r ``` Nice! *But did it do anything?* ```python solve_heat_equation_numpy_numba_parallel.parallel_diagnostics() ``` #### with explicit parallelization ```python @njit(parallel=True) def solve_heat_equation_numpy_numba_parallel_explicit(init_cond, iterations=100, delta_x=1.0, alpha=1.0): delta_t = delta_x**2/(4*alpha) prev = np.copy(init_cond) cur = np.copy(init_cond) # define some slices to make it easier to type # just avoids too many things like prev[1:-1,1:-1]) Z = slice(1,-1) # zero P = slice(2,None) # plus 1 M = slice(0,-2) # minus 1 for k in prange(iterations): cur[Z,Z] = ( prev[Z,Z] + alpha*delta_t/delta_x**2 * ( prev[Z,M] + prev[M,Z] - 4.0*prev[Z,Z] + prev[Z,P] + prev[P,Z] ) ) prev,cur = cur,prev # swap the pointers return prev # since we swapped, prev is the most recent answer = solve_heat_equation_numpy_numba_parallel_explicit(grid, iterations=50) ``` <div class="alert alert-block alert-warning"> WARNING WARNING </div> ```python plot_heat_equation(solver=solve_heat_equation_numpy_numba_parallel_explicit) ``` ```python r = %timeit -o solve_heat_equation_numpy_numba_parallel_explicit(grid, iterations=50) results['numpy\nnumba\nparallel\nexplicit'] = r ``` ```python plot_performance(results) plt.semilogy() ``` ```python plot_heat_equation(solver=solve_heat_equation_numpy_numba_parallel) plot_heat_equation(solver=solve_heat_equation_numpy_numba_parallel_explicit) ``` ```python ``` ```python Let's look at some code that can be parallelized by numnba ```
State Before: C : Type u₁ inst✝¹ : Category C D : Type u₂ inst✝ : Category D G : Cᵒᵖ ⊢ IsCoseparator G.unop ↔ IsSeparator G State After: no goals Tactic: rw [IsSeparator, IsCoseparator, ← isCoseparating_unop_iff, Set.singleton_unop]
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import measure_theory.constructions.borel_space import measure_theory.function.l1_space /-! # Filtration and stopping time This file defines some standard definition from the theory of stochastic processes including filtrations and stopping times. These definitions are used to model the amount of information at a specific time and is the first step in formalizing stochastic processes. ## Main definitions * `measure_theory.filtration`: a filtration on a measurable space * `measure_theory.adapted`: a sequence of functions `u` is said to be adapted to a filtration `f` if at each point in time `i`, `u i` is `f i`-measurable * `measure_theory.filtration.natural`: the natural filtration with respect to a sequence of measurable functions is the smallest filtration to which it is adapted to * `measure_theory.is_stopping_time`: a stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is `f i`-measurable * `measure_theory.is_stopping_time.measurable_space`: the σ-algebra associated with a stopping time ## Tags filtration, stopping time, stochastic process -/ noncomputable theory open_locale classical measure_theory nnreal ennreal topological_space big_operators namespace measure_theory /-- A `filtration` on measurable space `α` with σ-algebra `m` is a monotone sequence of of sub-σ-algebras of `m`. -/ structure filtration {α : Type*} (ι : Type*) [preorder ι] (m : measurable_space α) := (seq : ι → measurable_space α) (mono : monotone seq) (le : ∀ i : ι, seq i ≤ m) variables {α β ι : Type*} {m : measurable_space α} open topological_space section preorder variables [preorder ι] instance : has_coe_to_fun (filtration ι m) (λ _, ι → measurable_space α) := ⟨λ f, f.seq⟩ /-- The constant filtration which is equal to `m` for all `i : ι`. -/ def const_filtration (m : measurable_space α) : filtration ι m := ⟨λ _, m, monotone_const, λ _, le_rfl⟩ instance : inhabited (filtration ι m) := ⟨const_filtration m⟩ lemma measurable_set_of_filtration {f : filtration ι m} {s : set α} {i : ι} (hs : measurable_set[f i] s) : measurable_set[m] s := f.le i s hs /-- A measure is σ-finite with respect to filtration if it is σ-finite with respect to all the sub-σ-algebra of the filtration. -/ class sigma_finite_filtration (μ : measure α) (f : filtration ι m) : Prop := (sigma_finite : ∀ i : ι, sigma_finite (μ.trim (f.le i))) instance sigma_finite_of_sigma_finite_filtration (μ : measure α) (f : filtration ι m) [hf : sigma_finite_filtration μ f] (i : ι) : sigma_finite (μ.trim (f.le i)) := by apply hf.sigma_finite -- can't exact here variable [measurable_space β] /-- A sequence of functions `u` is adapted to a filtration `f` if for all `i`, `u i` is `f i`-measurable. -/ def adapted (f : filtration ι m) (u : ι → α → β) : Prop := ∀ i : ι, measurable[f i] (u i) namespace adapted lemma add [has_add β] [has_measurable_add₂ β] {u v : ι → α → β} {f : filtration ι m} (hu : adapted f u) (hv : adapted f v) : adapted f (u + v) := λ i, @measurable.add _ _ _ _ (f i) _ _ _ (hu i) (hv i) lemma neg [has_neg β] [has_measurable_neg β] {u : ι → α → β} {f : filtration ι m} (hu : adapted f u) : adapted f (-u) := λ i, @measurable.neg _ α _ _ _ (f i) _ (hu i) lemma smul [has_scalar ℝ β] [has_measurable_smul ℝ β] {u : ι → α → β} {f : filtration ι m} (c : ℝ) (hu : adapted f u) : adapted f (c • u) := λ i, @measurable.const_smul ℝ β α _ _ _ (f i) _ _ (hu i) c end adapted variable (β) lemma adapted_zero [has_zero β] (f : filtration ι m) : adapted f (0 : ι → α → β) := λ i, @measurable_zero β α (f i) _ _ variable {β} namespace filtration /-- Given a sequence of functions, the natural filtration is the smallest sequence of σ-algebras such that that sequence of functions is measurable with respect to the filtration. -/ def natural (u : ι → α → β) (hum : ∀ i, measurable (u i)) : filtration ι m := { seq := λ i, ⨆ j ≤ i, measurable_space.comap (u j) infer_instance, mono := λ i j hij, bsupr_le_bsupr' $ λ k hk, le_trans hk hij, le := λ i, bsupr_le (λ j hj s hs, let ⟨t, ht, ht'⟩ := hs in ht' ▸ hum j ht) } lemma adapted_natural {u : ι → α → β} (hum : ∀ i, measurable[m] (u i)) : adapted (natural u hum) u := λ i, measurable.le (le_bsupr_of_le i (le_refl i) le_rfl) (λ s hs, ⟨s, hs, rfl⟩) end filtration /-- A stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable with respect to `f i`. Intuitively, the stopping time `τ` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def is_stopping_time (f : filtration ι m) (τ : α → ι) := ∀ i : ι, measurable_set[f i] $ {x | τ x ≤ i} variables {f : filtration ℕ m} {τ : α → ℕ} lemma is_stopping_time.measurable_set_le (hτ : is_stopping_time f τ) (i : ℕ) : measurable_set[f i] {x | τ x ≤ i} := hτ i lemma is_stopping_time.measurable_set_eq (hτ : is_stopping_time f τ) (i : ℕ) : measurable_set[f i] {x | τ x = i} := begin cases i, { convert (hτ 0), simp only [set.set_of_eq_eq_singleton, le_zero_iff] }, { rw (_ : {x | τ x = i + 1} = {x | τ x ≤ i + 1} \ {x | τ x ≤ i}), { exact (hτ (i + 1)).diff (f.mono (nat.le_succ _) _ (hτ i)) }, { ext, simp only [set.mem_diff, not_le, set.mem_set_of_eq], split, { intro h, simp [h] }, { rintro ⟨h₁, h₂⟩, linarith } } } end lemma is_stopping_time.measurable_set_ge (hτ : is_stopping_time f τ) (i : ℕ) : measurable_set[f i] {x | i ≤ τ x} := begin have : {a : α | i ≤ τ a} = (set.univ \ {a | τ a ≤ i}) ∪ {a | τ a = i}, { ext1 a, simp only [true_and, set.mem_univ, set.mem_diff, not_le, set.mem_union_eq, set.mem_set_of_eq], rw le_iff_lt_or_eq, by_cases h : τ a = i, { simp [h], }, { simp only [h, ne.symm h, or_false, or_iff_left_iff_imp], }, }, rw this, exact (measurable_set.univ.diff (hτ i)).union (hτ.measurable_set_eq i), end lemma is_stopping_time.measurable_set_eq_le {f : filtration ℕ m} {τ : α → ℕ} (hτ : is_stopping_time f τ) {i j : ℕ} (hle : i ≤ j) : measurable_set[f j] {x | τ x = i} := f.mono hle _ $ hτ.measurable_set_eq i lemma is_stopping_time.measurable_set_lt (hτ : is_stopping_time f τ) (i : ℕ) : measurable_set[f i] {x | τ x < i} := begin convert (hτ i).diff (hτ.measurable_set_eq i), ext, change τ x < i ↔ τ x ≤ i ∧ τ x ≠ i, rw lt_iff_le_and_ne, end lemma is_stopping_time.measurable_set_lt_le (hτ : is_stopping_time f τ) {i j : ℕ} (hle : i ≤ j) : measurable_set[f j] {x | τ x < i} := f.mono hle _ $ hτ.measurable_set_lt i lemma is_stopping_time_of_measurable_set_eq {f : filtration ℕ m} {τ : α → ℕ} (hτ : ∀ i, measurable_set[f i] {x | τ x = i}) : is_stopping_time f τ := begin intro i, rw show {x | τ x ≤ i} = ⋃ k ≤ i, {x | τ x = k}, by { ext, simp }, refine measurable_set.bUnion (set.countable_encodable _) (λ k hk, _), exact f.mono hk _ (hτ k), end lemma is_stopping_time_const {f : filtration ι m} (i : ι) : is_stopping_time f (λ x, i) := λ j, by simp end preorder namespace is_stopping_time lemma max [linear_order ι] {f : filtration ι m} {τ π : α → ι} (hτ : is_stopping_time f τ) (hπ : is_stopping_time f π) : is_stopping_time f (λ x, max (τ x) (π x)) := begin intro i, simp_rw [max_le_iff, set.set_of_and], exact (hτ i).inter (hπ i), end lemma min [linear_order ι] {f : filtration ι m} {τ π : α → ι} (hτ : is_stopping_time f τ) (hπ : is_stopping_time f π) : is_stopping_time f (λ x, min (τ x) (π x)) := begin intro i, simp_rw [min_le_iff, set.set_of_or], exact (hτ i).union (hπ i), end lemma add_const [add_group ι] [preorder ι] [covariant_class ι ι (function.swap (+)) (≤)] [covariant_class ι ι (+) (≤)] {f : filtration ι m} {τ : α → ι} (hτ : is_stopping_time f τ) {i : ι} (hi : 0 ≤ i) : is_stopping_time f (λ x, τ x + i) := begin intro j, simp_rw [← le_sub_iff_add_le], exact f.mono (sub_le_self j hi) _ (hτ (j - i)), end section preorder variables [preorder ι] {f : filtration ι m} /-- The associated σ-algebra with a stopping time. -/ protected def measurable_space {τ : α → ι} (hτ : is_stopping_time f τ) : measurable_space α := { measurable_set' := λ s, ∀ i : ι, measurable_set[f i] (s ∩ {x | τ x ≤ i}), measurable_set_empty := λ i, (set.empty_inter {x | τ x ≤ i}).symm ▸ @measurable_set.empty _ (f i), measurable_set_compl := λ s hs i, begin rw (_ : sᶜ ∩ {x | τ x ≤ i} = (sᶜ ∪ {x | τ x ≤ i}ᶜ) ∩ {x | τ x ≤ i}), { refine measurable_set.inter _ _, { rw ← set.compl_inter, exact (hs i).compl }, { exact hτ i} }, { rw set.union_inter_distrib_right, simp only [set.compl_inter_self, set.union_empty] } end, measurable_set_Union := λ s hs i, begin rw forall_swap at hs, rw set.Union_inter, exact measurable_set.Union (hs i), end } @[protected] lemma measurable_set {τ : α → ι} (hτ : is_stopping_time f τ) (s : set α) : measurable_set[hτ.measurable_space] s ↔ ∀ i : ι, measurable_set[f i] (s ∩ {x | τ x ≤ i}) := iff.rfl lemma measurable_space_mono {τ π : α → ι} (hτ : is_stopping_time f τ) (hπ : is_stopping_time f π) (hle : τ ≤ π) : hτ.measurable_space ≤ hπ.measurable_space := begin intros s hs i, rw (_ : s ∩ {x | π x ≤ i} = s ∩ {x | τ x ≤ i} ∩ {x | π x ≤ i}), { exact (hs i).inter (hπ i) }, { ext, simp only [set.mem_inter_eq, iff_self_and, and.congr_left_iff, set.mem_set_of_eq], intros hle' _, exact le_trans (hle _) hle' }, end lemma measurable_space_le [encodable ι] {τ : α → ι} (hτ : is_stopping_time f τ) : hτ.measurable_space ≤ m := begin intros s hs, change ∀ i, measurable_set[f i] (s ∩ {x | τ x ≤ i}) at hs, rw (_ : s = ⋃ i, s ∩ {x | τ x ≤ i}), { exact measurable_set.Union (λ i, f.le i _ (hs i)) }, { ext x, split; rw set.mem_Union, { exact λ hx, ⟨τ x, hx, le_rfl⟩ }, { rintro ⟨_, hx, _⟩, exact hx } } end section nat lemma measurable_set_eq_const {f : filtration ℕ m} {τ : α → ℕ} (hτ : is_stopping_time f τ) (i : ℕ) : measurable_set[hτ.measurable_space] {x | τ x = i} := begin rw hτ.measurable_set, intro j, by_cases i ≤ j, { rw (_ : {x | τ x = i} ∩ {x | τ x ≤ j} = {x | τ x = i}), { exact hτ.measurable_set_eq_le h }, { ext, simp only [set.mem_inter_eq, and_iff_left_iff_imp, set.mem_set_of_eq], rintro rfl, assumption } }, { rw (_ : {x | τ x = i} ∩ {x | τ x ≤ j} = ∅), { exact @measurable_set.empty _ (f j) }, { ext, simp only [set.mem_empty_eq, set.mem_inter_eq, not_and, not_le, set.mem_set_of_eq, iff_false], rintro rfl, rwa not_le at h } } end end nat end preorder section linear_order variable [linear_order ι] lemma measurable [topological_space ι] [measurable_space ι] [borel_space ι] [order_topology ι] [second_countable_topology ι] {f : filtration ι m} {τ : α → ι} (hτ : is_stopping_time f τ) : measurable[hτ.measurable_space] τ := begin refine @measurable_of_Iic ι α _ _ _ hτ.measurable_space _ _ _ _ _, simp_rw [hτ.measurable_set, set.preimage, set.mem_Iic], intros i j, rw (_ : {x | τ x ≤ i} ∩ {x | τ x ≤ j} = {x | τ x ≤ linear_order.min i j}), { exact f.mono (min_le_right i j) _ (hτ (linear_order.min i j)) }, { ext, simp only [set.mem_inter_eq, iff_self, le_min_iff, set.mem_set_of_eq] } end end linear_order end is_stopping_time section linear_order /-- Given a map `u : ι → α → E`, its stopped value with respect to the stopping time `τ` is the map `x ↦ u (τ x) x`. -/ def stopped_value (u : ι → α → β) (τ : α → ι) : α → β := λ x, u (τ x) x variable [linear_order ι] /-- Given a map `u : ι → α → E`, the stopped process with respect to `τ` is `u i x` if `i ≤ τ x`, and `u (τ x) x` otherwise. Intuitively, the stopped process stops evolving once the stopping time has occured. -/ def stopped_process (u : ι → α → β) (τ : α → ι) : ι → α → β := λ i x, u (linear_order.min i (τ x)) x lemma stopped_process_eq_of_le {u : ι → α → β} {τ : α → ι} {i : ι} {x : α} (h : i ≤ τ x) : stopped_process u τ i x = u i x := by simp [stopped_process, min_eq_left h] lemma stopped_process_eq_of_ge {u : ι → α → β} {τ : α → ι} {i : ι} {x : α} (h : τ x ≤ i) : stopped_process u τ i x = u (τ x) x := by simp [stopped_process, min_eq_right h] -- We will need cadlag to generalize the following to continuous processes section nat open filtration variables {f : filtration ℕ m} {u : ℕ → α → β} {τ π : α → ℕ} lemma stopped_value_sub_eq_sum [add_comm_group β] (hle : τ ≤ π) : stopped_value u π - stopped_value u τ = λ x, (∑ i in finset.Ico (τ x) (π x), (u (i + 1) - u i)) x := begin ext x, rw [finset.sum_Ico_eq_sub _ (hle x), finset.sum_range_sub, finset.sum_range_sub], simp [stopped_value], end lemma stopped_value_sub_eq_sum' [add_comm_group β] (hle : τ ≤ π) {N : ℕ} (hbdd : ∀ x, π x ≤ N) : stopped_value u π - stopped_value u τ = λ x, (∑ i in finset.range (N + 1), set.indicator {x | τ x ≤ i ∧ i < π x} (u (i + 1) - u i)) x := begin rw stopped_value_sub_eq_sum hle, ext x, simp only [finset.sum_apply, finset.sum_indicator_eq_sum_filter], refine finset.sum_congr _ (λ _ _, rfl), ext i, simp only [finset.mem_filter, set.mem_set_of_eq, finset.mem_range, finset.mem_Ico], exact ⟨λ h, ⟨lt_trans h.2 (nat.lt_succ_iff.2 $ hbdd _), h⟩, λ h, h.2⟩ end section add_comm_monoid variables [add_comm_monoid β] lemma stopped_value_eq {N : ℕ} (hbdd : ∀ x, τ x ≤ N) : stopped_value u τ = λ x, (∑ i in finset.range (N + 1), set.indicator {x | τ x = i} (u i)) x := begin ext y, rw [stopped_value, finset.sum_apply, finset.sum_eq_single (τ y)], { rw set.indicator_of_mem, exact rfl }, { exact λ i hi hneq, set.indicator_of_not_mem hneq.symm _ }, { intro hy, rw set.indicator_of_not_mem, exact λ _, hy (finset.mem_range.2 $ lt_of_le_of_lt (hbdd _) (nat.lt_succ_self _)) } end lemma stopped_process_eq (n : ℕ) : stopped_process u τ n = set.indicator {a | n ≤ τ a} (u n) + ∑ i in finset.range n, set.indicator {a | τ a = i} (u i) := begin ext x, rw [pi.add_apply, finset.sum_apply], cases le_or_lt n (τ x), { rw [stopped_process_eq_of_le h, set.indicator_of_mem, finset.sum_eq_zero, add_zero], { intros m hm, rw finset.mem_range at hm, exact set.indicator_of_not_mem ((lt_of_lt_of_le hm h).ne.symm) _ }, { exact h } }, { rw [stopped_process_eq_of_ge (le_of_lt h), finset.sum_eq_single_of_mem (τ x)], { rw [set.indicator_of_not_mem, zero_add, set.indicator_of_mem], { exact rfl }, -- refl does not work { exact not_le.2 h } }, { rwa [finset.mem_range] }, { intros b hb hneq, rw set.indicator_of_not_mem, exact hneq.symm } }, end lemma adapted.stopped_process [measurable_space β] [has_measurable_add₂ β] (hu : adapted f u) (hτ : is_stopping_time f τ) : adapted f (stopped_process u τ) := begin intro i, rw stopped_process_eq, refine @measurable.add _ _ _ _ (f i) _ _ _ _ _, { refine (hu i).indicator _, convert measurable_set.union (hτ i).compl (hτ.measurable_set_eq i), ext x, change i ≤ τ x ↔ ¬ τ x ≤ i ∨ τ x = i, rw [not_le, le_iff_lt_or_eq, eq_comm] }, { refine @finset.measurable_sum' _ _ _ _ _ _ (f i) _ _ _, refine λ j hij, measurable.indicator _ _, { rw finset.mem_range at hij, exact measurable.le (f.mono hij.le) (hu j) }, { rw finset.mem_range at hij, refine f.mono hij.le _ _, convert hτ.measurable_set_eq j, } } end end add_comm_monoid section normed_group variables [measurable_space β] [normed_group β] [has_measurable_add₂ β] lemma measurable_stopped_process (hτ : is_stopping_time f τ) (hu : adapted f u) (n : ℕ) : measurable (stopped_process u τ n) := (hu.stopped_process hτ n).le (f.le _) lemma mem_ℒp_stopped_process {p : ℝ≥0∞} [borel_space β] {μ : measure α} (hτ : is_stopping_time f τ) (hu : ∀ n, mem_ℒp (u n) p μ) (n : ℕ) : mem_ℒp (stopped_process u τ n) p μ := begin rw stopped_process_eq, refine mem_ℒp.add _ _, { exact mem_ℒp.indicator (f.le n {a : α | n ≤ τ a} (hτ.measurable_set_ge n)) (hu n) }, { suffices : mem_ℒp (λ x, ∑ (i : ℕ) in finset.range n, {a : α | τ a = i}.indicator (u i) x) p μ, { convert this, ext1 x, simp only [finset.sum_apply] }, refine mem_ℒp_finset_sum _ (λ i hi, mem_ℒp.indicator _ (hu i)), exact f.le i {a : α | τ a = i} (hτ.measurable_set_eq i) }, end lemma integrable_stopped_process [borel_space β] {μ : measure α} (hτ : is_stopping_time f τ) (hu : ∀ n, integrable (u n) μ) (n : ℕ) : integrable (stopped_process u τ n) μ := begin simp_rw ← mem_ℒp_one_iff_integrable at hu ⊢, exact mem_ℒp_stopped_process hτ hu n, end lemma mem_ℒp_stopped_value {p : ℝ≥0∞} [borel_space β] {μ : measure α} (hτ : is_stopping_time f τ) (hu : ∀ n, mem_ℒp (u n) p μ) {N : ℕ} (hbdd : ∀ x, τ x ≤ N) : mem_ℒp (stopped_value u τ) p μ := begin rw stopped_value_eq hbdd, suffices : mem_ℒp (λ x, ∑ (i : ℕ) in finset.range (N + 1), {a : α | τ a = i}.indicator (u i) x) p μ, { convert this, ext1 x, simp only [finset.sum_apply] }, refine mem_ℒp_finset_sum _ (λ i hi, mem_ℒp.indicator _ (hu i)), exact f.le i {a : α | τ a = i} (hτ.measurable_set_eq i) end lemma integrable_stopped_value [borel_space β] {μ : measure α} (hτ : is_stopping_time f τ) (hu : ∀ n, integrable (u n) μ) {N : ℕ} (hbdd : ∀ x, τ x ≤ N) : integrable (stopped_value u τ) μ := begin simp_rw ← mem_ℒp_one_iff_integrable at hu ⊢, exact mem_ℒp_stopped_value hτ hu hbdd, end end normed_group end nat end linear_order end measure_theory
Formal statement is: lemma homeomorphic_sym: "s homeomorphic t \<longleftrightarrow> t homeomorphic s" Informal statement is: If $s$ is homeomorphic to $t$, then $t$ is homeomorphic to $s$.
[STATEMENT] lemma mat_mod_non_empty_col_iff: "elements_mat M \<subseteq> {0..<m} \<Longrightarrow> non_empty_col (mat_mod M) j \<longleftrightarrow> non_empty_col M j" [PROOF STATE] proof (prove) goal (1 subgoal): 1. elements_mat M \<subseteq> {0..<m} \<Longrightarrow> non_empty_col (local.mat_mod M) j = non_empty_col M j [PROOF STEP] using mat_mod_eq_cond [PROOF STATE] proof (prove) using this: elements_mat ?M \<subseteq> {0..<m} \<Longrightarrow> local.mat_mod ?M = ?M goal (1 subgoal): 1. elements_mat M \<subseteq> {0..<m} \<Longrightarrow> non_empty_col (local.mat_mod M) j = non_empty_col M j [PROOF STEP] by auto
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import category_theory.limits.shapes.pullbacks import ring_theory.tensor_product import algebra.category.Ring.limits import algebra.category.Ring.colimits import category_theory.limits.shapes.strict_initial import ring_theory.subring.basic import ring_theory.ideal.local_ring import category_theory.limits.preserves.limits /-! # Constructions of (co)limits in CommRing In this file we provide the explicit (co)cones for various (co)limits in `CommRing`, including * tensor product is the pushout * `Z` is the initial object * `0` is the strict terminal object * cartesian product is the product * `ring_hom.eq_locus` is the equalizer -/ universes u u' open category_theory category_theory.limits open_locale tensor_product namespace CommRing section pushout variables {R A B : CommRing.{u}} (f : R ⟶ A) (g : R ⟶ B) /-- The explicit cocone with tensor products as the fibered product in `CommRing`. -/ def pushout_cocone : limits.pushout_cocone f g := begin letI := ring_hom.to_algebra f, letI := ring_hom.to_algebra g, apply limits.pushout_cocone.mk, show CommRing, from CommRing.of (A ⊗[R] B), show A ⟶ _, from algebra.tensor_product.include_left.to_ring_hom, show B ⟶ _, from algebra.tensor_product.include_right.to_ring_hom, ext r, transitivity algebra_map R (A ⊗[R] B) r, { exact algebra.tensor_product.include_left.commutes r }, { exact (algebra.tensor_product.include_right.commutes r).symm } end @[simp] lemma pushout_cocone_inl : (pushout_cocone f g).inl = (by { letI := f.to_algebra, letI := g.to_algebra, exactI algebra.tensor_product.include_left.to_ring_hom }) := rfl @[simp] lemma pushout_cocone_inr : (pushout_cocone f g).inr = (by { letI := f.to_algebra, letI := g.to_algebra, exactI algebra.tensor_product.include_right.to_ring_hom }) := rfl @[simp] lemma pushout_cocone_X : (pushout_cocone f g).X = (by { letI := f.to_algebra, letI := g.to_algebra, exactI CommRing.of (A ⊗[R] B) }) := rfl /-- Verify that the `pushout_cocone` is indeed the colimit. -/ def pushout_cocone_is_colimit : limits.is_colimit (pushout_cocone f g) := limits.pushout_cocone.is_colimit_aux' _ (λ s, begin letI := ring_hom.to_algebra f, letI := ring_hom.to_algebra g, letI := ring_hom.to_algebra (f ≫ s.inl), let f' : A →ₐ[R] s.X := { commutes' := λ r, by { change s.inl.to_fun (f r) = (f ≫ s.inl) r, refl }, ..s.inl }, let g' : B →ₐ[R] s.X := { commutes' := λ r, by { change (g ≫ s.inr) r = (f ≫ s.inl) r, congr' 1, exact (s.ι.naturality limits.walking_span.hom.snd).trans (s.ι.naturality limits.walking_span.hom.fst).symm }, ..s.inr }, /- The factor map is a ⊗ b ↦ f(a) * g(b). -/ use alg_hom.to_ring_hom (algebra.tensor_product.product_map f' g'), simp only [pushout_cocone_inl, pushout_cocone_inr], split, { ext x, exact algebra.tensor_product.product_map_left_apply _ _ x, }, split, { ext x, exact algebra.tensor_product.product_map_right_apply _ _ x, }, intros h eq1 eq2, let h' : (A ⊗[R] B) →ₐ[R] s.X := { commutes' := λ r, by { change h ((f r) ⊗ₜ[R] 1) = s.inl (f r), rw ← eq1, simp }, ..h }, suffices : h' = algebra.tensor_product.product_map f' g', { ext x, change h' x = algebra.tensor_product.product_map f' g' x, rw this }, apply algebra.tensor_product.ext, intros a b, simp [← eq1, ← eq2, ← h.map_mul], end) end pushout section terminal /-- The trivial ring is the (strict) terminal object of `CommRing`. -/ def punit_is_terminal : is_terminal (CommRing.of.{u} punit) := begin apply_with is_terminal.of_unique { instances := ff }, tidy end instance CommRing_has_strict_terminal_objects : has_strict_terminal_objects CommRing.{u} := begin apply has_strict_terminal_objects_of_terminal_is_strict (CommRing.of punit), intros X f, refine ⟨⟨by tidy, by ext, _⟩⟩, ext, have e : (0 : X) = 1 := by { rw [← f.map_one, ← f.map_zero], congr }, replace e : 0 * x = 1 * x := congr_arg (λ a, a * x) e, rw [one_mul, zero_mul, ← f.map_zero] at e, exact e, end lemma subsingleton_of_is_terminal {X : CommRing} (hX : is_terminal X) : subsingleton X := (hX.unique_up_to_iso punit_is_terminal).CommRing_iso_to_ring_equiv.to_equiv .subsingleton_congr.mpr (show subsingleton punit, by apply_instance) /-- `ℤ` is the initial object of `CommRing`. -/ def Z_is_initial : is_initial (CommRing.of ℤ) := begin apply_with is_initial.of_unique { instances := ff }, exact λ R, ⟨⟨int.cast_ring_hom R⟩, λ a, a.ext_int _⟩, end end terminal section product variables (A B : CommRing.{u}) /-- The product in `CommRing` is the cartesian product. This is the binary fan. -/ @[simps X] def prod_fan : binary_fan A B := binary_fan.mk (CommRing.of_hom $ ring_hom.fst A B) (CommRing.of_hom $ ring_hom.snd A B) /-- The product in `CommRing` is the cartesian product. -/ def prod_fan_is_limit : is_limit (prod_fan A B) := { lift := λ c, ring_hom.prod (c.π.app ⟨walking_pair.left⟩) (c.π.app ⟨walking_pair.right⟩), fac' := λ c j, by { ext, rcases j with ⟨⟨⟩⟩; simpa only [binary_fan.π_app_left, binary_fan.π_app_right, comp_apply, ring_hom.prod_apply] }, uniq' := λ s m h, by { ext, { simpa using congr_hom (h ⟨walking_pair.left⟩) x }, { simpa using congr_hom (h ⟨walking_pair.right⟩) x } } } end product section equalizer variables {A B : CommRing.{u}} (f g : A ⟶ B) /-- The equalizer in `CommRing` is the equalizer as sets. This is the equalizer fork. -/ def equalizer_fork : fork f g := fork.of_ι (CommRing.of_hom (ring_hom.eq_locus f g).subtype) (by { ext ⟨x, e⟩, simpa using e }) /-- The equalizer in `CommRing` is the equalizer as sets. -/ def equalizer_fork_is_limit : is_limit (equalizer_fork f g) := begin fapply fork.is_limit.mk', intro s, use s.ι.cod_restrict _ (λ x, (concrete_category.congr_hom s.condition x : _)), split, { ext, refl }, { intros m hm, ext x, exact concrete_category.congr_hom hm x } end instance : is_local_ring_hom (equalizer_fork f g).ι := begin constructor, rintros ⟨a, (h₁ : _ = _)⟩ (⟨⟨x,y,h₃,h₄⟩,(rfl : x = _)⟩ : is_unit a), have : y ∈ ring_hom.eq_locus f g, { apply (f.is_unit_map ⟨⟨x,y,h₃,h₄⟩,rfl⟩ : is_unit (f x)).mul_left_inj.mp, conv_rhs { rw h₁ }, rw [← f.map_mul, ← g.map_mul, h₄, f.map_one, g.map_one] }, rw is_unit_iff_exists_inv, exact ⟨⟨y, this⟩, subtype.eq h₃⟩, end instance equalizer_ι_is_local_ring_hom (F : walking_parallel_pair.{u} ⥤ CommRing.{u}) : is_local_ring_hom (limit.π F walking_parallel_pair.zero) := begin have := lim_map_π (diagram_iso_parallel_pair F).hom walking_parallel_pair.zero, rw ← is_iso.comp_inv_eq at this, rw ← this, rw ← limit.iso_limit_cone_hom_π ⟨_, equalizer_fork_is_limit (F.map walking_parallel_pair_hom.left) (F.map walking_parallel_pair_hom.right)⟩ walking_parallel_pair.zero, change is_local_ring_hom ((lim.map _ ≫ _ ≫ (equalizer_fork _ _).ι) ≫ _), apply_instance end open category_theory.limits.walking_parallel_pair opposite open category_theory.limits.walking_parallel_pair_hom instance equalizer_ι_is_local_ring_hom' (F : walking_parallel_pair.{u}ᵒᵖ ⥤ CommRing.{u}) : is_local_ring_hom (limit.π F (opposite.op walking_parallel_pair.one)) := begin have : _ = limit.π F (walking_parallel_pair_op_equiv.{u u}.functor.obj _) := (limit.iso_limit_cone_inv_π ⟨_, is_limit.whisker_equivalence (limit.is_limit F) walking_parallel_pair_op_equiv⟩ walking_parallel_pair.zero : _), erw ← this, apply_instance end end equalizer end CommRing
`is_element/binary_trees` := (A::set) -> proc(TT) global reason; if not(`is_element/full_trees`(A)(TT)) then reason := [convert(procname,string),"TT is not a full tree",TT,reason]; return false; fi; if not(`is_binary/full_trees`(A)(TT)) then reason := [convert(procname,string),"TT is not binary",TT,reason]; return false; fi; end: ###################################################################### `is_equal/binary_trees` := eval(`is_equal/full_trees`); ###################################################################### `is_leq/binary_trees` := eval(`is_leq/full_trees`); ###################################################################### `list_elements/binary_trees` := proc(A::set) option remember; local n,L,P,B,C,UUU,VVV,UU,VV; n := nops(A); if n = 0 then return []; elif n = 1 then return [{A}]; fi; L := NULL; P := `list_elements/nonempty_subsets`(A minus {A[n]}); for B in P do C := A minus B; UUU := `list_elements/binary_trees`(B); VVV := `list_elements/binary_trees`(C); L := L,seq(seq({op(UU),op(VV),A},VV in VVV),UU in UUU); od; return [L]; end: ###################################################################### `random_element/binary_trees` := (A::set) -> proc() local n,B,C,UU,VV; n := nops(A); if n = 0 then return FAIL; fi; if n = 1 then return {A}; fi; B := `random_element/nonempty_subsets`(A minus {A[n]})(); C := A minus B; UU := `random_element/binary_trees`(B)(); VV := `random_element/binary_trees`(C)(); return {op(UU),op(VV),A}; end: ###################################################################### # OEIS: A001147 `count_elements/binary_trees` := proc(A::set) local k; mul(2*k-1,k=1..nops(A)-1); end:
from typing import Optional, Tuple import numpy as np from numpy import ndarray from skfem.element import Element from skfem.mapping import Mapping from skfem.mesh import Mesh from .exterior_facet_basis import ExteriorFacetBasis class InteriorFacetBasis(ExteriorFacetBasis): def __init__(self, mesh: Mesh, elem: Element, mapping: Optional[Mapping] = None, intorder: Optional[int] = None, quadrature: Optional[Tuple[ndarray, ndarray]] = None, facets: Optional[ndarray] = None, side: int = 0): """Precomputed global basis on interior facets.""" if side not in (0, 1): raise Exception("'side' must be 0 or 1.") if facets is None: facets = np.nonzero(mesh.f2t[1] != -1)[0] super(InteriorFacetBasis, self).__init__(mesh, elem, mapping=mapping, intorder=intorder, quadrature=quadrature, facets=facets, _side=side)
------------------------------------------------------------------------ -- The Agda standard library -- -- Intersection of two binary relations ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Relation.Binary.Construct.Intersection where open import Data.Product open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]) open import Function using (_∘_) open import Level using (_⊔_) open import Relation.Binary open import Relation.Nullary using (yes; no) ------------------------------------------------------------------------ -- Definition _∩_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} → REL A B ℓ₁ → REL A B ℓ₂ → REL A B (ℓ₁ ⊔ ℓ₂) L ∩ R = λ i j → L i j × R i j ------------------------------------------------------------------------ -- Properties module _ {a ℓ₁ ℓ₂} {A : Set a} (L : Rel A ℓ₁) (R : Rel A ℓ₂) where reflexive : Reflexive L → Reflexive R → Reflexive (L ∩ R) reflexive L-refl R-refl = L-refl , R-refl symmetric : Symmetric L → Symmetric R → Symmetric (L ∩ R) symmetric L-sym R-sym = map L-sym R-sym transitive : Transitive L → Transitive R → Transitive (L ∩ R) transitive L-trans R-trans = zip L-trans R-trans respects : ∀ {p} (P : A → Set p) → P Respects L ⊎ P Respects R → P Respects (L ∩ R) respects P resp (Lxy , Rxy) = [ (λ x → x Lxy) , (λ x → x Rxy) ] resp min : ∀ {⊤} → Minimum L ⊤ → Minimum R ⊤ → Minimum (L ∩ R) ⊤ min L-min R-min = < L-min , R-min > max : ∀ {⊥} → Maximum L ⊥ → Maximum R ⊥ → Maximum (L ∩ R) ⊥ max L-max R-max = < L-max , R-max > module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} (≈ : REL A B ℓ₁) {L : REL A B ℓ₂} {R : REL A B ℓ₃} where implies : (≈ ⇒ L) → (≈ ⇒ R) → ≈ ⇒ (L ∩ R) implies ≈⇒L ≈⇒R = < ≈⇒L , ≈⇒R > module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} (≈ : REL A B ℓ₁) (L : REL A B ℓ₂) (R : REL A B ℓ₃) where irreflexive : Irreflexive ≈ L ⊎ Irreflexive ≈ R → Irreflexive ≈ (L ∩ R) irreflexive irrefl x≈y (Lxy , Rxy) = [ (λ x → x x≈y Lxy) , (λ x → x x≈y Rxy) ] irrefl module _ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a} (≈ : Rel A ℓ₁) (L : Rel A ℓ₂) (R : Rel A ℓ₃) where respectsˡ : L Respectsˡ ≈ → R Respectsˡ ≈ → (L ∩ R) Respectsˡ ≈ respectsˡ L-resp R-resp x≈y = map (L-resp x≈y) (R-resp x≈y) respectsʳ : L Respectsʳ ≈ → R Respectsʳ ≈ → (L ∩ R) Respectsʳ ≈ respectsʳ L-resp R-resp x≈y = map (L-resp x≈y) (R-resp x≈y) respects₂ : L Respects₂ ≈ → R Respects₂ ≈ → (L ∩ R) Respects₂ ≈ respects₂ (Lʳ , Lˡ) (Rʳ , Rˡ) = respectsʳ Lʳ Rʳ , respectsˡ Lˡ Rˡ antisymmetric : Antisymmetric ≈ L ⊎ Antisymmetric ≈ R → Antisymmetric ≈ (L ∩ R) antisymmetric (inj₁ L-antisym) (Lxy , _) (Lyx , _) = L-antisym Lxy Lyx antisymmetric (inj₂ R-antisym) (_ , Rxy) (_ , Ryx) = R-antisym Rxy Ryx module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} {L : REL A B ℓ₁} {R : REL A B ℓ₂} where decidable : Decidable L → Decidable R → Decidable (L ∩ R) decidable L? R? x y with L? x y | R? x y ... | no ¬Lxy | _ = no (¬Lxy ∘ proj₁) ... | yes _ | no ¬Rxy = no (¬Rxy ∘ proj₂) ... | yes Lxy | yes Rxy = yes (Lxy , Rxy) ------------------------------------------------------------------------ -- Structures module _ {a ℓ₁ ℓ₂} {A : Set a} {L : Rel A ℓ₁} {R : Rel A ℓ₂} where isEquivalence : IsEquivalence L → IsEquivalence R → IsEquivalence (L ∩ R) isEquivalence eqₗ eqᵣ = record { refl = reflexive L R Eqₗ.refl Eqᵣ.refl ; sym = symmetric L R Eqₗ.sym Eqᵣ.sym ; trans = transitive L R Eqₗ.trans Eqᵣ.trans } where module Eqₗ = IsEquivalence eqₗ; module Eqᵣ = IsEquivalence eqᵣ isDecEquivalence : IsDecEquivalence L → IsDecEquivalence R → IsDecEquivalence (L ∩ R) isDecEquivalence eqₗ eqᵣ = record { isEquivalence = isEquivalence Eqₗ.isEquivalence Eqᵣ.isEquivalence ; _≟_ = decidable Eqₗ._≟_ Eqᵣ._≟_ } where module Eqₗ = IsDecEquivalence eqₗ; module Eqᵣ = IsDecEquivalence eqᵣ module _ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a} {≈ : Rel A ℓ₁} {L : Rel A ℓ₂} {R : Rel A ℓ₃} where isPreorder : IsPreorder ≈ L → IsPreorder ≈ R → IsPreorder ≈ (L ∩ R) isPreorder Oₗ Oᵣ = record { isEquivalence = Oₗ.isEquivalence ; reflexive = implies ≈ Oₗ.reflexive Oᵣ.reflexive ; trans = transitive L R Oₗ.trans Oᵣ.trans } where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPreorder Oᵣ isPartialOrderˡ : IsPartialOrder ≈ L → IsPreorder ≈ R → IsPartialOrder ≈ (L ∩ R) isPartialOrderˡ Oₗ Oᵣ = record { isPreorder = isPreorder Oₗ.isPreorder Oᵣ ; antisym = antisymmetric ≈ L R (inj₁ Oₗ.antisym) } where module Oₗ = IsPartialOrder Oₗ; module Oᵣ = IsPreorder Oᵣ isPartialOrderʳ : IsPreorder ≈ L → IsPartialOrder ≈ R → IsPartialOrder ≈ (L ∩ R) isPartialOrderʳ Oₗ Oᵣ = record { isPreorder = isPreorder Oₗ Oᵣ.isPreorder ; antisym = antisymmetric ≈ L R (inj₂ Oᵣ.antisym) } where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPartialOrder Oᵣ isStrictPartialOrderˡ : IsStrictPartialOrder ≈ L → Transitive R → R Respects₂ ≈ → IsStrictPartialOrder ≈ (L ∩ R) isStrictPartialOrderˡ Oₗ transᵣ respᵣ = record { isEquivalence = Oₗ.isEquivalence ; irrefl = irreflexive ≈ L R (inj₁ Oₗ.irrefl) ; trans = transitive L R Oₗ.trans transᵣ ; <-resp-≈ = respects₂ ≈ L R Oₗ.<-resp-≈ respᵣ } where module Oₗ = IsStrictPartialOrder Oₗ isStrictPartialOrderʳ : Transitive L → L Respects₂ ≈ → IsStrictPartialOrder ≈ R → IsStrictPartialOrder ≈ (L ∩ R) isStrictPartialOrderʳ transₗ respₗ Oᵣ = record { isEquivalence = Oᵣ.isEquivalence ; irrefl = irreflexive ≈ L R (inj₂ Oᵣ.irrefl) ; trans = transitive L R transₗ Oᵣ.trans ; <-resp-≈ = respects₂ ≈ L R respₗ Oᵣ.<-resp-≈ } where module Oᵣ = IsStrictPartialOrder Oᵣ
module Graphiti.BTree -- shows a basic Binary Tree with insert, toList and fromList ops -- shows how to reverse/invert it without using a stack or a queue %hide toList -- we do not want the standard library to pollute our definitions here public export data BTree a = Leaf | Node (BTree a) a (BTree a) data LR = L | R inserter : Ord a => a -> BTree a -> LR -> BTree a inserter x Leaf _ = Node Leaf x Leaf inserter x (Node l y r) L = if (x < y) then (Node (inserter x l L) y r) else (Node l y (inserter x r L)) inserter x (Node l y r) R = if (x > y) then (Node (inserter x l R) y r) else (Node l y (inserter x r R)) export insert : Ord a => a -> BTree a -> BTree a insert x t = inserter x t L invInsert : Ord a => a -> BTree a -> BTree a invInsert x t = inserter x t R export toList : BTree a -> List a toList Leaf = [] toList (Node l y r) = BTree.toList l ++ (y :: BTree.toList r) export fromList : Ord a => List a -> BTree a fromList [] = Leaf fromList (x :: xs) = BTree.insert x (BTree.fromList xs) fromListInv : Ord a => List a -> BTree a fromListInv [] = Leaf fromListInv (x :: xs) = invInsert x (fromListInv xs) export reverseList : List a -> List a reverseList xs = revAcc [] xs where revAcc : List a -> List a -> List a revAcc acc [] = acc revAcc acc (y :: ys) = revAcc (y :: acc) ys export revBTree : Ord a => BTree a -> BTree a revBTree Leaf = Leaf revBTree node = fromList ( BTree.reverseList (BTree.toList node) ) export reinvBTree : Ord a => BTree a -> BTree a reinvBTree Leaf = Leaf reinvBTree node = fromListInv (toList node) -- shows a proof that inversion of inversion is the original -- i.e. inv . inv = id invOfInv : Ord a => (bt: BTree a) -> reinvBTree (reinvBTree bt) = bt invOfInv Leaf = Refl invOfInv (Node x y z) = ?hole
import field_theory.krull_topology import topology.category.CompHaus.default import topology.category.Profinite.default section finite_stuff variables {K E L : Type*} [field K] [field E] [algebra K E] [field L] [algebra K L] [finite_dimensional K E] noncomputable instance foo {E : Type*} {X : set E} (hX : X.finite) {L : Type*} (F : E → multiset L) : fintype (Π x : X, {l : L // l ∈ F x}) := by { classical, letI : fintype X := set.finite.fintype hX, exact pi.fintype} variable (K) noncomputable def aux_fun1 : E → multiset L := λ e, ((minpoly K e).map (algebra_map K L)).roots lemma minpoly.ne_zero' (e : E) : minpoly K e ≠ 0 := minpoly.ne_zero $ is_integral_of_noetherian (is_noetherian.iff_fg.2 infer_instance) _ variable (E) def basis_set: set E := set.range (finite_dimensional.fin_basis K E : _ → E) variable (L) -- function from Hom_K(E,L) to pi type Π (x : basis), roots of min poly of x def aux_fun2 (φ : E →ₐ[K] L) (x : basis_set K E) : {l : L // l ∈ (aux_fun1 K x.1 : multiset L)} := ⟨φ x, begin unfold aux_fun1, rw [polynomial.mem_roots_map (minpoly.ne_zero' K x.val), ← polynomial.alg_hom_eval₂_algebra_map, ← φ.map_zero], exact congr_arg φ (minpoly.aeval K (x : E)), end⟩ lemma aux_inj : function.injective (aux_fun2 K E L) := begin intros f g h, suffices : (f : E →ₗ[K] L) = g, { rw linear_map.ext_iff at this, ext x, exact this x }, rw function.funext_iff at h, apply linear_map.ext_on (finite_dimensional.fin_basis K E).span_eq, rintro e he, have := (h ⟨e, he⟩), apply_fun subtype.val at this, exact this, end /-- Given field extensions `E/K` and `L/K`, with `E/K` finite, there are finitely many `K`-algebra homomorphisms `E →ₐ[K] L`. -/ noncomputable def its_finite : fintype (E →ₐ[K] L) := let n := finite_dimensional.finrank K E in begin let B : basis (fin n) K E := finite_dimensional.fin_basis K E, let X := set.range (B : fin n → E), have hX : X.finite := set.finite_range ⇑B, refine @fintype.of_injective _ _ (foo hX (λ e, ((minpoly K e).map (algebra_map K L)).roots)) _ (aux_inj K E L), end end finite_stuff open set lemma ultrafilter.eq_principal_of_fintype (X : Type*) [fintype X] (f : ultrafilter X) : ∃ x : X, (f : filter X) = pure x := let ⟨x, hx1, (hx2 : (f : filter X) = pure x)⟩ := ultrafilter.eq_principal_of_finite_mem (finite_univ : (univ : set X).finite) (filter.univ_mem) in ⟨x, hx2⟩ universe u noncomputable def alg_hom_of_finite_dimensional_of_ultrafilter {K : Type*} {L : Type u} [field K] [field L] [algebra K L] {E : intermediate_field K L} (h_findim : finite_dimensional K E) (f : ultrafilter (L ≃ₐ[K] L)) : E →ₐ[K] L := classical.some (@ultrafilter.eq_principal_of_fintype (E →ₐ[K] L) (its_finite K E L) (f.map (λ σ, σ.to_alg_hom.comp (intermediate_field.val E)))) -- f.map ((L ≃ₐ[K] L) → (E →ₐ[K] L)) is generated by -- alg_hom_of_finite_dimensional_of_ultrafilter_spec h_findim f lemma alg_hom_of_finite_dimensional_of_ultrafilter_spec {K L : Type*} [field K] [field L] [algebra K L] {E : intermediate_field K L} (h_findim : finite_dimensional K E) (f : ultrafilter (L ≃ₐ[K] L)) : (f.map (λ σ : L ≃ₐ[K] L, σ.to_alg_hom.comp (intermediate_field.val E)) : filter (E →ₐ[K] L)) = pure (alg_hom_of_finite_dimensional_of_ultrafilter h_findim f) := classical.some_spec (@ultrafilter.eq_principal_of_fintype (E →ₐ[K] L) (its_finite K E L) (f.map (λ σ, σ.to_alg_hom.comp (intermediate_field.val E)))) -- next five lemmas should be a PR def intermediate_field.inclusion {K L : Type*} [field K] [field L] [algebra K L] {E F : intermediate_field K L} (hEF : E ≤ F): E →ₐ[K] F := { to_fun := set.inclusion hEF, map_one' := rfl, map_add' := λ _ _, rfl, map_mul' := λ _ _, rfl, map_zero' := rfl, commutes' := λ _, rfl } lemma subalgebra.inclusion_eq_identity {R A : Type*} [comm_semiring R] [semiring A] [algebra R A] {E F : subalgebra R A} (hEF : E ≤ F) (x : E) : F.val ((subalgebra.inclusion hEF) x) = E.val x := rfl lemma subalgebra.val_injective {R A : Type*} [comm_semiring R] [semiring A] [algebra R A] {E : subalgebra R A} : function.injective E.val := λ x y hxy, subtype.ext hxy lemma subalgebra.inclusion_mk {R A : Type*} [comm_semiring R] [semiring A] [algebra R A] {E F : subalgebra R A} (hEF : E ≤ F) {x : A} (hx : x ∈ E) : (subalgebra.inclusion hEF) ⟨x, hx⟩ = ⟨x, hEF hx⟩ := begin apply subalgebra.val_injective, rw subalgebra.inclusion_eq_identity, simp, end lemma ultrafilter.map_map {X Y Z: Type*} (m : X → Y) (n : Y → Z) (f : ultrafilter X) : (f.map m).map n = f.map(n ∘ m) := begin ext, split, { intro hs, rw [ultrafilter.mem_map, set.preimage_comp, ← ultrafilter.mem_map, ← ultrafilter.mem_map], exact hs }, { intro hs, rw [ultrafilter.mem_map, ultrafilter.mem_map, ← set.preimage_comp, ← ultrafilter.mem_map], exact hs }, end lemma ultrafilter.map_pure {X Y : Type*} (x : X) (m : X → Y): (pure x : ultrafilter X).map m = pure (m x) := rfl lemma alg_hom_of_finite_dimensional_of_ultrafilter_functor {K L : Type*} [field K] [field L] [algebra K L] {E : intermediate_field K L} (hE : finite_dimensional K E) (f : ultrafilter (L ≃ₐ[K] L)) {F : intermediate_field K L} (hF : finite_dimensional K F) (hEF : E ≤ F) : alg_hom_of_finite_dimensional_of_ultrafilter hE f = (alg_hom_of_finite_dimensional_of_ultrafilter hF f).comp (subalgebra.inclusion hEF) := begin set p_E := (λ σ : L ≃ₐ[K] L, σ.to_alg_hom.comp (intermediate_field.val E)) with p_E_def, set p_F := (λ σ : L ≃ₐ[K] L, σ.to_alg_hom.comp (intermediate_field.val F)) with p_F_def, set σ_E := alg_hom_of_finite_dimensional_of_ultrafilter hE f with σ_E_def, set σ_F := alg_hom_of_finite_dimensional_of_ultrafilter hF f with σ_F_def, have hσ_E := alg_hom_of_finite_dimensional_of_ultrafilter_spec hE f, rw [← p_E_def, ← σ_E_def] at hσ_E, have hσ_F := alg_hom_of_finite_dimensional_of_ultrafilter_spec hF f, rw [← p_F_def, ← σ_F_def] at hσ_F, set res : (F →ₐ[K] L) → (E →ₐ[K] L) := (λ ϕ, ϕ.comp (subalgebra.inclusion hEF)) with res_def, have h_pF_pE_res : res ∘ p_F = p_E := rfl, have h_maps_commute : ((f.map p_F).map res : filter (E →ₐ[K] L)) = f.map p_E, { rw [ultrafilter.map_map, h_pF_pE_res] }, have hEf := alg_hom_of_finite_dimensional_of_ultrafilter_spec hE f, rw [← σ_E_def, ← p_E_def] at hEf, have hFf := alg_hom_of_finite_dimensional_of_ultrafilter_spec hF f, rw [← σ_F_def, ← p_F_def] at hFf, have hFf' : (ultrafilter.map p_F f) = (pure σ_F : ultrafilter (F →ₐ[K] L)), { exact ultrafilter.coe_inj.mp hFf }, rw [hEf, hFf', ultrafilter.map_pure] at h_maps_commute, have h := filter.pure_injective h_maps_commute, rw res_def at h, dsimp at h, exact h.symm, end noncomputable def function_of_ultrafilter {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (f : ultrafilter (L ≃ₐ[K] L)) : (L → L) := λ x, (alg_hom_of_finite_dimensional_of_ultrafilter (intermediate_field.adjoin.finite_dimensional (h_int x)) f) (⟨x, intermediate_field.mem_adjoin_simple_self K x⟩) lemma function_of_ultrafilter_spec {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (f : ultrafilter (L ≃ₐ[K] L)) {E : intermediate_field K L} (hE : finite_dimensional K E) (x : E) : (function_of_ultrafilter h_int f) x = (alg_hom_of_finite_dimensional_of_ultrafilter hE f) x := begin have h_le : intermediate_field.adjoin K {(x : L)} ≤ E, { apply intermediate_field.gc.l_le, simp only [set_like.coe_mem, set_like.mem_coe, set.singleton_subset_iff, set.le_eq_subset], }, have h_Kx : finite_dimensional K (intermediate_field.adjoin K {(x : L)}) := intermediate_field.adjoin.finite_dimensional (h_int x), let h_functor := alg_hom_of_finite_dimensional_of_ultrafilter_functor h_Kx f hE h_le, have h : (function_of_ultrafilter h_int f) x = (alg_hom_of_finite_dimensional_of_ultrafilter h_Kx f) ⟨x, intermediate_field.mem_adjoin_simple_self K x⟩ := rfl, rw [h, h_functor], let x_in_Kx : intermediate_field.adjoin K {(x : L)} := ⟨(x : L), intermediate_field.mem_adjoin_simple_self K (x : L)⟩, have h' : (subalgebra.inclusion h_le) x_in_Kx = x := by simp [subalgebra.inclusion_mk h_le (intermediate_field.mem_adjoin_simple_self K (x : L))], simp [h'], end lemma adj_finset_finite_dimensional {K L : Type*} [field K] [field L] [algebra K L] (S : finset L) (h_int : ∀ (x : L), x ∈ S → is_integral K x) : finite_dimensional K (intermediate_field.adjoin K (coe S : set L)) := begin refine intermediate_field.induction_on_adjoin_finset (S) (λ (E : intermediate_field K L), finite_dimensional K E) _ _, { have temp : (⊥ : intermediate_field K L) = (⊥ : intermediate_field K L) := rfl, rw ← intermediate_field.finrank_eq_one_iff at temp, refine finite_dimensional.finite_dimensional_of_finrank _, rw temp, exact zero_lt_one }, { intros E x hx, specialize h_int x hx, introI h, haveI h2 : finite_dimensional ↥E (↥E)⟮x⟯, { apply intermediate_field.adjoin.finite_dimensional, exact is_integral_of_is_scalar_tower x h_int }, change finite_dimensional K ↥(↥E)⟮x⟯, exact finite_dimensional.trans K ↥E ↥(↥E)⟮x⟯ }, end noncomputable def alg_hom_of_ultrafilter {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (f : ultrafilter (L ≃ₐ[K] L)) : (L →ₐ[K] L) := { to_fun := function_of_ultrafilter h_int f, map_one' := begin have h_findim_bot : finite_dimensional K (⊥ : intermediate_field K L) := intermediate_field.finite_dimensional_bot K L, have h_one_bot : (1 : L) ∈ (⊥: intermediate_field K L) := (⊥ : intermediate_field K L).one_mem, have h := function_of_ultrafilter_spec h_int f h_findim_bot (1 : (⊥ : intermediate_field K L)), simp at h, exact h, end, map_mul' := begin intros x y, let E := intermediate_field.adjoin K ({x, y} : set L), have h_sub : {x, y} ⊆ E.carrier := intermediate_field.gc.le_u_l {x, y}, have hxE : x ∈ E := h_sub (mem_insert x {y}), have hyE : y ∈ E, { apply h_sub, simp only [set.mem_insert_iff, set.mem_singleton, or_true] }, have hxyE : x * y ∈ E := E.mul_mem' hxE hyE, haveI : decidable_eq L := classical.dec_eq L, let S := ({x, y} : finset L), have h_S_int : ∀ (x : L), x ∈ S → is_integral K x := λ a ha, h_int a, have hE := adj_finset_finite_dimensional S h_S_int, have h_S_coes : (S : set L) = {x, y}, { simp only [finset.coe_insert, finset.coe_singleton, eq_self_iff_true] }, rw h_S_coes at hE, change finite_dimensional K E at hE, have h : function_of_ultrafilter h_int f x = function_of_ultrafilter h_int f (⟨x, hxE⟩ : E) := rfl, change function_of_ultrafilter h_int f (⟨x * y, hxyE⟩ : E) = function_of_ultrafilter h_int f (⟨x, hxE⟩ : E) * function_of_ultrafilter h_int f (⟨y, hyE⟩ : E), rw [function_of_ultrafilter_spec h_int f hE ⟨x, hxE⟩, function_of_ultrafilter_spec h_int f hE ⟨y, hyE⟩, function_of_ultrafilter_spec h_int f hE ⟨x * y, hxyE⟩], have h2 : (alg_hom_of_finite_dimensional_of_ultrafilter hE f) ⟨x, hxE⟩ * (alg_hom_of_finite_dimensional_of_ultrafilter hE f) ⟨y, hyE⟩ = (alg_hom_of_finite_dimensional_of_ultrafilter hE f) (⟨x, hxE⟩ * ⟨y, hyE⟩), { simp only [mul_eq_mul_left_iff, true_or, eq_self_iff_true, map_mul] }, rw h2, refl, end, map_zero' := begin have h_findim_bot : finite_dimensional K (⊥ : intermediate_field K L) := intermediate_field.finite_dimensional_bot K L, have h_zero_bot : (0 : L) ∈ (⊥: intermediate_field K L) := (⊥ : intermediate_field K L).zero_mem, have h := function_of_ultrafilter_spec h_int f h_findim_bot (0 : (⊥ : intermediate_field K L)), simp at h, exact h, end, map_add' := begin intros x y, let E := intermediate_field.adjoin K ({x, y} : set L), have h_sub : {x, y} ⊆ E.carrier := intermediate_field.gc.le_u_l {x, y}, have hxE : x ∈ E := h_sub (mem_insert x {y}), have hyE : y ∈ E, { apply h_sub, simp only [set.mem_insert_iff, set.mem_singleton, or_true] }, have hxyE : x + y ∈ E := E.add_mem' hxE hyE, haveI : decidable_eq L := classical.dec_eq L, let S := ({x, y} : finset L), have h_S_int : ∀ (x : L), x ∈ S → is_integral K x := λ a ha, h_int a, have hE := adj_finset_finite_dimensional S h_S_int, have h_S_coes : (S : set L) = {x, y}, { simp only [finset.coe_insert, finset.coe_singleton, eq_self_iff_true] }, rw h_S_coes at hE, change finite_dimensional K E at hE, have h : function_of_ultrafilter h_int f x = function_of_ultrafilter h_int f (⟨x, hxE⟩ : E) := rfl, change function_of_ultrafilter h_int f (⟨x + y, hxyE⟩ : E) = function_of_ultrafilter h_int f (⟨x, hxE⟩ : E) + function_of_ultrafilter h_int f (⟨y, hyE⟩ : E), rw [function_of_ultrafilter_spec h_int f hE ⟨x, hxE⟩, function_of_ultrafilter_spec h_int f hE ⟨y, hyE⟩, function_of_ultrafilter_spec h_int f hE ⟨x + y, hxyE⟩], have h2 : (alg_hom_of_finite_dimensional_of_ultrafilter hE f) ⟨x, hxE⟩ + (alg_hom_of_finite_dimensional_of_ultrafilter hE f) ⟨y, hyE⟩ = (alg_hom_of_finite_dimensional_of_ultrafilter hE f) (⟨x, hxE⟩ + ⟨y, hyE⟩), { simp }, rw h2, refl, end, commutes' := begin intro r, let r' := (algebra_map K L) r, have h_findim_bot : finite_dimensional K (⊥ : intermediate_field K L) := intermediate_field.finite_dimensional_bot K L, have h : r' ∈ (⊥ : intermediate_field K L) := (⊥ : intermediate_field K L).algebra_map_mem r, change function_of_ultrafilter h_int f (⟨r', h⟩ : (⊥ : intermediate_field K L)) = (⟨r', h⟩ : (⊥ : intermediate_field K L)), rw function_of_ultrafilter_spec h_int f h_findim_bot (⟨r', h⟩ : (⊥ : intermediate_field K L)), have h2 : (⟨r', h⟩ : (⊥ : intermediate_field K L)) = (algebra_map K (⊥ : intermediate_field K L) r) := rfl, rw h2, simp, refl, end } lemma alg_hom_of_ultrafilter_injective {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (f : ultrafilter (L ≃ₐ[K] L)) : function.injective (alg_hom_of_ultrafilter h_int f) := begin intros x y hxy, haveI : decidable_eq L := classical.dec_eq L, let E := intermediate_field.adjoin K ({x, y} : set L), let S := ({x, y} : finset L), have h_S_int : ∀ (x : L), x ∈ S → is_integral K x := λ a ha, h_int a, have hE := adj_finset_finite_dimensional S h_S_int, have h_S_coes : (S : set L) = {x, y}, { simp only [finset.coe_insert, finset.coe_singleton, eq_self_iff_true] }, rw h_S_coes at hE, change finite_dimensional K E at hE, have h_sub : {x, y} ⊆ E.carrier := intermediate_field.gc.le_u_l {x, y}, have hxE : x ∈ E := h_sub (mem_insert x {y}), have hyE : y ∈ E, { apply h_sub, simp only [set.mem_insert_iff, set.mem_singleton, or_true] }, change (alg_hom_of_ultrafilter h_int f) (⟨x, hxE⟩ : E) = (alg_hom_of_ultrafilter h_int f) (⟨y, hyE⟩ : E) at hxy, change (function_of_ultrafilter h_int f) (⟨x, hxE⟩ : E) = (function_of_ultrafilter h_int f) (⟨y, hyE⟩ : E) at hxy, rw [function_of_ultrafilter_spec h_int f hE (⟨x, hxE⟩ : E), function_of_ultrafilter_spec h_int f hE (⟨y, hyE⟩ : E)] at hxy, have h : (⟨x, hxE⟩ : E) = (⟨y, hyE⟩ : E), { exact ring_hom.injective (alg_hom_of_finite_dimensional_of_ultrafilter hE f).to_ring_hom hxy }, simp at h, exact h, end lemma eq_of_map_le {K L : Type*} [field K] [field L] [algebra K L] {E : intermediate_field K L} {f : L →ₐ[K] L} (h_findim : finite_dimensional K E) (h_map_le : E.map f ≤ E) : E.map f = E := begin have hf_inj : function.injective f := ring_hom.injective f.to_ring_hom, haveI hE_submod_fin : finite_dimensional K E.to_subalgebra.to_submodule, { exact h_findim }, have h_finrank_eq : finite_dimensional.finrank K (E.map f) = finite_dimensional.finrank K E, { exact (linear_equiv.finrank_eq (submodule.equiv_map_of_injective (f.to_linear_map) hf_inj E.to_subalgebra.to_submodule)).symm }, have h_submod_le : (E.map f).to_subalgebra.to_submodule ≤ E.to_subalgebra.to_submodule := h_map_le, exact intermediate_field.to_subalgebra_eq_iff.mp (subalgebra.to_submodule_injective (finite_dimensional.eq_of_le_of_finrank_eq h_map_le h_finrank_eq)), end lemma alg_hom_of_ultrafilter_surjective {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) (f : ultrafilter (L ≃ₐ[K] L)) : function.surjective (alg_hom_of_ultrafilter h_int f) := begin intro y, specialize h_splits y, let p := minpoly K y, haveI : decidable_eq L := classical.dec_eq L, let S := (p.map (algebra_map K L)).roots.to_finset, let E := intermediate_field.adjoin K (S : set L), have hE_findim : finite_dimensional K E := adj_finset_finite_dimensional S (λ x hx, h_int x), let σ := alg_hom_of_ultrafilter h_int f, have hσSS : σ '' S ⊆ S, { rintros x ⟨a, ha, hax⟩, rw ← hax, simp, rw polynomial.mem_roots, { rw [polynomial.is_root.def, ← polynomial.eval₂_eq_eval_map, ← polynomial.alg_hom_eval₂_algebra_map], have hσ0 : σ 0 = 0 := by simp, rw ← hσ0, apply congr_arg σ, simp at ha, rw polynomial.mem_roots at ha, { rw [polynomial.is_root.def, ← polynomial.eval₂_eq_eval_map] at ha, exact ha }, { exact polynomial.map_monic_ne_zero (minpoly.monic (h_int y)) } }, exact polynomial.map_monic_ne_zero (minpoly.monic (h_int y)) }, have hSE : (S : set L) ⊆ E := intermediate_field.gc.le_u_l (S : set L), have hσSE : σ '' S ⊆ E := set.subset.trans hσSS hSE, have h1 : E.map σ = intermediate_field.adjoin K (σ '' S) := intermediate_field.adjoin_map K S σ, have h2 : intermediate_field.adjoin K (σ '' S) ≤ E, { apply intermediate_field.gc.l_le, exact hσSE }, change ∃ (a : L), σ a = y, rw ← h1 at h2, have h3 := eq_of_map_le hE_findim h2, have hyE : y ∈ E, { have hyS : y ∈ S, { simp, rw polynomial.mem_roots, { rw [polynomial.is_root.def, ← polynomial.eval₂_eq_eval_map, ← polynomial.aeval_def], exact minpoly.aeval K y }, { exact polynomial.map_monic_ne_zero (minpoly.monic (h_int y)) } }, exact hSE hyS }, rw ← h3 at hyE, rcases hyE with ⟨a, ha, hay⟩, exact ⟨a, hay⟩, end lemma alg_hom_of_ultrafilter_bijection {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) (f : ultrafilter (L ≃ₐ[K] L)) : function.bijective (alg_hom_of_ultrafilter h_int f) := begin exact ⟨alg_hom_of_ultrafilter_injective h_int f, alg_hom_of_ultrafilter_surjective h_int h_splits f⟩, end noncomputable def equiv_of_ultrafilter {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) (f : ultrafilter (L ≃ₐ[K] L)) : (L ≃ₐ[K] L) := alg_equiv.of_bijective (alg_hom_of_ultrafilter h_int f) (alg_hom_of_ultrafilter_bijection h_int h_splits f) lemma equiv_of_ultrafilter_to_fun {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) (f : ultrafilter (L ≃ₐ[K] L)) : (equiv_of_ultrafilter h_int h_splits f).to_fun = function_of_ultrafilter h_int f := rfl lemma equiv_of_ultrafilter_to_alg_hom {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) (f : ultrafilter (L ≃ₐ[K] L)) : (equiv_of_ultrafilter h_int h_splits f).to_alg_hom = alg_hom_of_ultrafilter h_int f := rfl /-- Let `L/K` be a normal algebraic field extension, let `f` be an ultrafilter on `L ≃ₐ[K] L`, and let `E/K` be a finite subextension. Then `equiv_of_ultrafilter h_int h_splits f` is a term of `L ≃ₐ[K] L`, and `alg_hom_of_finite_dimensional_of_ultrafilter h_findim f` is a term `E →ₐ[K] L`. This Lemma tells us that the underlying maps of these two terms agree on `E`. -/ lemma equiv_restricts_to_alg_hom_of_finite_dimensional {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) (f : ultrafilter (L ≃ₐ[K] L)) {E : intermediate_field K L} (h_findim : finite_dimensional K E) : ((equiv_of_ultrafilter h_int h_splits f).to_alg_hom.comp E.val) = alg_hom_of_finite_dimensional_of_ultrafilter h_findim f := begin ext, exact function_of_ultrafilter_spec h_int f h_findim x, end def res {K L : Type*} [field K] [field L] [algebra K L] (E : intermediate_field K L): (L ≃ₐ[K] L) → (E →ₐ[K] L) := λ f, f.to_alg_hom.comp E.val lemma res_eq_map {K L : Type*} [field K] [field L] [algebra K L] {E : intermediate_field K L} (σ : L ≃ₐ[K] L) (x : E) : σ x = (res E σ) x := begin unfold res, simp, end lemma inv_mul_alg_equiv_of_elem {K L : Type*} [field K] [field L] [algebra K L] (x : L) (f g : L ≃ₐ[K] L) : (f⁻¹ * g) x = x ↔ g x = f x := begin rw alg_equiv.mul_apply, split, { intro h, have h' := congr_arg f h, rw [← alg_equiv.mul_apply, mul_right_inv] at h', exact h' }, { intro h, have h' := congr_arg f.symm h, rw alg_equiv.symm_apply_apply at h', exact h' }, end lemma top_group_map_nhds_eq {G : Type*} [group G] [topological_space G] [topological_group G] (g x : G) : filter.map (λ y, g * y) (nhds x) = nhds (g * x) := begin ext, split, { intro h, rw [filter.mem_map, mem_nhds_iff] at h, rcases h with ⟨U, h_subset, h_open, hxU⟩, rw mem_nhds_iff, use left_coset g U, split, { rw ← set.image_subset_iff at h_subset, exact h_subset }, refine ⟨_, ⟨x, ⟨hxU, rfl⟩⟩⟩, apply is_open_map_mul_left g, exact h_open }, { intro h, rw mem_nhds_iff at h, rcases h with ⟨U, h_subset, h_open, hgxU⟩, rw [filter.mem_map, mem_nhds_iff], use left_coset g⁻¹ U, split, { rw ← set.image_subset_iff, have h : (λ (y : G), g * y) '' left_coset g⁻¹ U = U, { ext a, refine ⟨_, λ ha, ⟨g⁻¹ * a, ⟨a, ha, rfl⟩, by simp⟩⟩, rintro ⟨b, ⟨c, hcU, hcb⟩, hba⟩, change g⁻¹ * c = b at hcb, change g * b = a at hba, rw [← hcb, ← mul_assoc, mul_right_inv, one_mul] at hba, rw ← hba, exact hcU }, rw h, exact h_subset }, refine ⟨_, ⟨g * x, hgxU, by simp⟩⟩, apply is_open_map_mul_left g⁻¹, exact h_open }, end lemma sigma_is_limit {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) (f : ultrafilter (L ≃ₐ[K] L)) (h_le_princ : ↑f ≤ filter.principal (set.univ : set (L ≃ₐ[K] L))) : (f : filter (L ≃ₐ[K] L)) ≤ nhds (equiv_of_ultrafilter h_int h_splits f) := begin let σ := equiv_of_ultrafilter h_int h_splits f, intros A hA, have hA_coset : left_coset σ⁻¹ A ∈ nhds (1 : L ≃ₐ[K] L), { have h_sigma_1 : σ = σ * 1 := by simp, change A ∈ nhds σ at hA, rw [h_sigma_1, ← top_group_map_nhds_eq σ 1, filter.mem_map] at hA, have h : left_coset σ⁻¹ A = (λ y, σ * y)⁻¹' A, { ext, split, { rintro ⟨a, ha, hax⟩, simp [hax.symm, ha] }, { intro hx, rw set.mem_preimage at hx, rw [mem_left_coset_iff, inv_inv], exact hx } }, rw h, exact hA }, have hA_coset_cont_H : ∃ (E : intermediate_field K L), finite_dimensional K E ∧ E.fixing_subgroup.carrier ⊆ left_coset σ⁻¹ A, { rw [group_filter_basis.nhds_one_eq, filter_basis.mem_filter_iff] at hA_coset, rcases hA_coset with ⟨H_set, hH, hA_coset⟩, change H_set ∈ gal_basis K L at hH, rw mem_gal_basis_iff at hH, rcases hH with ⟨H, ⟨E, hE, hHE⟩, hHH_set⟩, refine ⟨E, hE, _⟩, rw [hHE, hHH_set], exact hA_coset }, rcases hA_coset_cont_H with ⟨E, h_findim, hEA⟩, have hEA' : left_coset σ E.fixing_subgroup ⊆ A, { rintros x ⟨y, hy, hyx⟩, change σ * y = x at hyx, specialize hEA hy, rcases hEA with ⟨a, ha, hay⟩, change σ⁻¹ * a = y at hay, rw inv_mul_eq_iff_eq_mul at hay, rw [← hyx, ← hay], exact ha }, let p : (L ≃ₐ[K] L) → (E →ₐ[K] L) := λ σ, (σ.to_alg_hom.comp E.val), have h_principal : f.map p = pure (p σ), { have h : p σ = alg_hom_of_finite_dimensional_of_ultrafilter h_findim f := equiv_restricts_to_alg_hom_of_finite_dimensional h_int h_splits f h_findim, rw h, have h2 : ↑(ultrafilter.map p f) = pure (alg_hom_of_finite_dimensional_of_ultrafilter h_findim f) := alg_hom_of_finite_dimensional_of_ultrafilter_spec h_findim f, ext, split, { intro hs, rw [← ultrafilter.mem_coe, h2] at hs, exact hs }, { intro hs, rw ultrafilter.mem_pure at hs, have h3 : s ∈ (pure (alg_hom_of_finite_dimensional_of_ultrafilter h_findim f) : filter (↥E →ₐ[K] L)), { rw filter.mem_pure, exact hs }, rw ← h2 at h3, rw ultrafilter.mem_coe at h3, exact h3 } }, have h_small_set : left_coset σ E.fixing_subgroup ∈ f, { have h : {p σ} ∈ (pure (p σ) : ultrafilter (E →ₐ[K] L)) := set.mem_singleton (p σ), rw [← h_principal, ultrafilter.mem_map] at h, have h_preim : p⁻¹' {p σ} = left_coset σ E.fixing_subgroup, { ext g, split, { intro hg, rw [set.mem_preimage, set.mem_singleton_iff] at hg, rw mem_left_coset_iff, intro x, have h_g_on_x : g x = (p g) x := res_eq_map g x, have h_σ_on_x : σ x = (p σ) x := res_eq_map σ x, change (σ⁻¹ * g) x = x, rw [inv_mul_alg_equiv_of_elem, h_g_on_x, h_σ_on_x, hg] }, { intro hg, rw [set.mem_preimage, set.mem_singleton_iff], ext, have h_g_on_x : g x = (p g) x := res_eq_map g x, have h_σ_on_x : σ x = (p σ) x := res_eq_map σ x, rw [← h_g_on_x, ← h_σ_on_x, ← inv_mul_alg_equiv_of_elem], exact (mem_left_coset_iff σ).1 hg x } }, rw h_preim at h, exact h }, exact f.to_filter.sets_of_superset h_small_set hEA', end lemma krull_topology_compact {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) : is_compact (set.univ : set (L ≃ₐ[K] L)) := is_compact_iff_ultrafilter_le_nhds.2 (λ f hf, ⟨equiv_of_ultrafilter h_int h_splits f, set.mem_univ (equiv_of_ultrafilter h_int h_splits f), sigma_is_limit h_int h_splits f hf⟩) def krull_topology_comphaus {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)): CompHaus := { to_Top := Top.of (L ≃ₐ[K] L), is_compact := { compact_univ := krull_topology_compact h_int h_splits}, is_hausdorff := krull_topology_t2 h_int, } def krull_topology_totally_disconnected_space {K L : Type*} [field K] [field L] [algebra K L] (h_int : ∀ (x : L), is_integral K x) : totally_disconnected_space (L ≃ₐ[K] L) := { is_totally_disconnected_univ := krull_topology_totally_disconnected h_int} def krull_topology_profinite {K L : Type*} [field K] [field L] [algebra K L] (h_int : algebra.is_integral K L) (h_splits : ∀ (x : L), polynomial.splits (algebra_map K L) (minpoly K x)) : Profinite := { to_CompHaus := krull_topology_comphaus h_int h_splits, is_totally_disconnected := krull_topology_totally_disconnected_space h_int}
In the January 2006 transfer window , he joined Grimsby Town on a two @-@ year deal , three years after they first expressed an interest in signing him . He made his debut against former club Peterborough United in League Two , on 28 January 2006 in a 2 – 1 home defeat , and scored his first and what turned out to be only goal for the club against Mansfield on 14 February 2006 . On 26 April 2006 , Woodhouse said he planned to retire from football at the end of the 2005 – 06 season and embark on a career as a professional boxer . He made 16 appearances in League Two , helping them to finish fourth place , reaching the play @-@ offs . Woodhouse played in both of Grimsby 's play @-@ off semi @-@ final victories over Lincoln City , setting up the only goal of the game in the first leg . He played his last Football League game in the play @-@ off final at the Millennium Stadium on 28 May 2006 . Grimsby were defeated 1 – 0 in the final by Cheltenham Town . Woodhouse gave away a penalty in the 70th minute that was saved by goalkeeper Steve Mildenhall .
classdef anisotropicdiffusion < TTeMPS_op_laplace % Class for anisotropic diffusion operator with tridiagonal diffusion matrix % % [ 1 a 0 ...0 ] % [ a 1 a 0 ..0 ] % D = [ 0 a 1 a 0 ..0 ] % [ .. .. . . ] % [ 0 ... .. 0 a 1 ] % % % TTeMPS Toolbox. % Michael Steinlechner, 2013-2016 % Questions and contact: [email protected] % BSD 2-clause license, see LICENSE.txt properties L D % precomputed spectral decomp of 1D Laplace: end methods function A = update_properties( A ); A.rank = [1, 3*ones(1, length(A.U)-1), 1]; % the TT rank is always three for such Laplace-like tensors size_col_ = cellfun( @(y) size(y,1), A.U); A.size_col = size_col_ ./ (A.rank(1:end-1).*A.rank(2:end)); A.size_row = cellfun( @(y) size(y,2), A.U); A.order = length( A.size_row ); end end methods( Access = public ) function A = anisotropicdiffusion( n, d, alpha ) if ~exist('alpha', 'var') alpha = 0.25; end one = ones(n,1); q = linspace( -10, 10, n)'; h = abs(q(2) - q(1)); L = -spdiags( [one, -2*one, one], [-1 0 1], n, n) / (h^2); % superclass constructor A = A@TTeMPS_op_laplace( L, d ); % precompute eigenvalue information and exponential for use in local A = initialize_precond( A ); % preconditioner: A.L = L; [A.V_L, A.E_L] = eig(full(A.L)); A.E_L = diag(A.E_L); A.D = spdiags( [-one,one], [-1,1], n, n ) / (2*h); I = speye( n, n ); e1 = sparse( 1, 1, 1, 3, 1 ); e2 = sparse( 2, 1, 1, 3, 1 ); e3 = sparse( 3, 1, 1, 3, 1 ); l_mid = sparse( 3, 1, 1, 9, 1 ); % e_3 b_mid = sparse( 6, 1, 1, 9, 1 ); % e_6 m_mid = sparse( [1;9], [1;1], [1;1], 9, 1 ); % e_1 + e_9 c_mid = sparse( 2, 1, 1, 9, 1 ); % e_2 A.U = cell( 1, d ); A.U{1} = kron( A.L, e1 ) + kron( 2*alpha*A.D, e2 ) + kron( I, e3); A_mid = kron( A.L, l_mid ) + kron( 2*alpha*A.D, b_mid ) + kron( I, m_mid) + kron( A.D, c_mid ); for i=2:d-1 A.U{i} = A_mid; end A.U{d} = kron( I, e1 ) + kron( A.D, e2 ) + kron( A.L, e3); A = update_properties( A ); end function expB = constr_precond_inner( A, X, mu ) n = size(A.L, 1); sz = [X.rank(mu), X.size(mu), X.rank(mu+1)] B1 = zeros( X.rank(mu) ); % calculate B1 part: for i = 1:mu-1 % apply L to the i'th core tmp = X; Xi = matricize( tmp.U{i}, 2 ); Xi = A.L*Xi; tmp.U{i} = tensorize( Xi, 2, [X.rank(i), n, X.rank(i+1)] ); B1 = B1 + innerprod( X, tmp, 'LR', mu-1); end B3 = zeros( X.rank(mu+1) ); % calculate B3 part: for i = mu+1:A.order tmp = X; Xi = matricize( tmp.U{i}, 2 ); Xi = A.L*Xi; tmp.U{i} = tensorize( Xi, 2, [X.rank(i), n, X.rank(i+1)] ); B3 = B3 + innerprod( X, tmp, 'RL', mu+1); end [V1,e1] = eig(B1); e1 = diag(e1); [V3,e3] = eig(B3); e3 = diag(e3); lmin = min(e1) + min(A.E_L) + min(e3); lmax = max(e1) + max(A.E_L) + max(e3); R = lmax/lmin [omega, alpha] = load_coefficients( R ); k = 3; omega = omega/lmin; alpha = alpha/lmin; expB = cell(3,k); for i = 1:k expB{1,i} = omega(i) * V1*diag( exp( -alpha(i)*e1 ))*V1'; % include omega in first part expB{2,i} = A.V_L*diag( exp( -alpha(i)*A.E_L ))*A.V_L'; expB{3,i} = V3*diag( exp( -alpha(i)*e3 ))*V3'; end end function expB = constr_precond_outer( A, X, mu1, mu2 ) n = size(A.L, 1); B1 = zeros( X.rank(mu1) ); % calculate B1 part: for i = 1:mu1-1 % apply L to the i'th core tmp = X; Xi = matricize( tmp.U{i}, 2 ); Xi = A.L*Xi; tmp.U{i} = tensorize( Xi, 2, [X.rank(i), n, X.rank(i+1)] ); B1 = B1 + innerprod( X, tmp, 'LR', mu1-1); end B3 = zeros( X.rank(mu2+1) ); % calculate B3 part: for i = mu2+1:A.order tmp = X; Xi = matricize( tmp.U{i}, 2 ); Xi = A.L*Xi; tmp.U{i} = tensorize( Xi, 2, [X.rank(i), n, X.rank(i+1)] ); B3 = B3 + innerprod( X, tmp, 'RL', mu2+1); end [V1,e1] = eig(B1); e1 = diag(e1); [V3,e3] = eig(B3); e3 = diag(e3); lmin = min(e1) + 2*min(A.E_L) + min(e3); lmax = max(e1) + 2*max(A.E_L) + max(e3); R = lmax/lmin [omega, alpha] = load_coefficients( R ); k = 3; omega = omega/lmin; alpha = alpha/lmin; expB = cell(4,k); for i = 1:k expB{1,i} = omega(i) * V1*diag( exp( -alpha(i)*e1 ))*V1'; % include omega in first part expB{2,i} = A.V_L*diag( exp( -alpha(i)*A.E_L ))*A.V_L'; expB{3,i} = A.V_L*diag( exp( -alpha(i)*A.E_L ))*A.V_L'; expB{4,i} = V3*diag( exp( -alpha(i)*e3 ))*V3'; end end function P = constr_precond( A, k ) d = A.order; lmin = d*min(A.E_L); lmax = d*max(A.E_L); R = lmax/lmin % http://www.mis.mpg.de/scicomp/EXP_SUM/1_x/1_xk07_2E2 % 0.0133615547183825570028305575534521842940 {omega[1]} % 0.0429728469424360175410925952177443321034 {omega[2]} % 0.1143029399081515586560726591147663100401 {omega[3]} % 0.2838881266934189482611071431161775535656 {omega[4]} % 0.6622322841999484042811198458711174907876 {omega[5]} % 1.4847175320092703810050463464342840325116 {omega[6]} % 3.4859753729916252771962870138366952232900 {omega[7]} % 0.0050213411684266507485648978019454613531 {alpha[1]} % 0.0312546410994290844202411500801774835168 {alpha[2]} % 0.1045970270084145620410366606112262388706 {alpha[3]} % 0.2920522758702768403556507270657505159761 {alpha[4]} % 0.7407504784499061527671195936939341208927 {alpha[5]} % 1.7609744335543204401530945069076494746696 {alpha[6]} % 4.0759036969145123916954953635638503328664 {alpha[7]} if k == 3 [omega, alpha] = load_coefficients( R ); elseif k == 7 omega = [0.0133615547183825570028305575534521842940 0.0429728469424360175410925952177443321034 0.1143029399081515586560726591147663100401,... 0.2838881266934189482611071431161775535656 0.6622322841999484042811198458711174907876 1.4847175320092703810050463464342840325116,... 3.4859753729916252771962870138366952232900]; alpha = [0.0050213411684266507485648978019454613531 0.0312546410994290844202411500801774835168 0.1045970270084145620410366606112262388706,... 0.2920522758702768403556507270657505159761 0.7407504784499061527671195936939341208927 1.7609744335543204401530945069076494746696,... 4.0759036969145123916954953635638503328664]; else error('Unknown rank specified. Choose either k=3 or k=7'); end omega = omega/lmin; alpha = alpha/lmin; % careful: all cores assumed to be of same size E = reshape( expm( -alpha(1) * A.L), [1, A.size_row(2), A.size_col(2), 1]); P = omega(1)*TTeMPS_op( repmat({E},1,d) ); for i = 2:k E = reshape( expm( -alpha(i) * A.L), [1, A.size_row(2), A.size_col(2), 1]); P = P + omega(i)*TTeMPS_op( repmat({E},1,d) ); end end end end
Formal statement is: lemma continuous_within_tendsto_compose': fixes f::"'a::t2_space \<Rightarrow> 'b::topological_space" assumes "continuous (at a within s) f" "\<And>n. x n \<in> s" "(x \<longlongrightarrow> a) F " shows "((\<lambda>n. f (x n)) \<longlongrightarrow> f a) F" Informal statement is: If $f$ is continuous at $a$ within $s$, and $x_n \to a$ with $x_n \in s$ for all $n$, then $f(x_n) \to f(a)$.
Sony Xperia charging port repairs in St Asaph – Are you looking for the best place to get your Sony Xperia phone charging port repair? Then you are in the right place. Get quick charger port replacement repair from our Sony repair centre in St Asaph at an affordable price. We replace the charging port for any Sony Xperia phone model such as Xperia Z5, Xperia Z, Xperia Z3 and Xperia XZ in St Asaph. We are one of the best phone repair shops in the UK for Sony Xperia phone charging port repair in St Asaph. We fix any issue that is associated with your Sony Xperia phone charging port. The quality of our service will be very good and we have a very good reputation from the customers. At our Sony repair centre in St Asaph, technicians are very professional in fixing the charging port issues for your Sony Xperia phones. To get a quick repair quote for your Sony Xperia Charging port repair in St Asaph, please fill in the form provided on the website and check the free repair quote we send to you. We are sure that your will be very satisfied with our quality of repair service for your Sony Xperia phone charging port repair. Fill in the quote from provided on the website and get the price for Sony Xperia charging port repair in St Asaph. Our prices are very low and cost-effective compared to others. We are always happy to take care of our customers’ phone repair issues and make sure we provide quality repair service from our end.
# This file was generated by the Julia Swagger Code Generator # Do not modify this file directly. Modify the swagger specification instead. struct VirtualNetworkGatewaysApi <: SwaggerApi client::Swagger.Client end """ Creates or updates a virtual network gateway in the specified resource group. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: parameters::VirtualNetworkGateway (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: VirtualNetworkGateway """ function _swaggerinternal_virtualNetworkGatewaysCreateOrUpdate(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "PUT", VirtualNetworkGateway, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}", ["azure_auth"], parameters) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysCreateOrUpdate(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysCreateOrUpdate(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysCreateOrUpdate(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysCreateOrUpdate(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Deletes the specified virtual network gateway. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: Nothing """ function _swaggerinternal_virtualNetworkGatewaysDelete(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "DELETE", Nothing, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysDelete(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysDelete(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysDelete(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysDelete(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Disconnect vpn connections of virtual network gateway in the specified resource group. Param: subscriptionId::String (required) Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: request::P2SVpnConnectionRequest (required) Param: api_version::String (required) Return: Nothing """ function _swaggerinternal_virtualNetworkGatewaysDisconnectVirtualNetworkGatewayVpnConnections(_api::VirtualNetworkGatewaysApi, subscriptionId::String, resourceGroupName::String, virtualNetworkGatewayName::String, request, api_version::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", Nothing, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/disconnectVirtualNetworkGatewayVpnConnections", ["azure_auth"], request) Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysDisconnectVirtualNetworkGatewayVpnConnections(_api::VirtualNetworkGatewaysApi, subscriptionId::String, resourceGroupName::String, virtualNetworkGatewayName::String, request, api_version::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysDisconnectVirtualNetworkGatewayVpnConnections(_api, subscriptionId, resourceGroupName, virtualNetworkGatewayName, request, api_version; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysDisconnectVirtualNetworkGatewayVpnConnections(_api::VirtualNetworkGatewaysApi, response_stream::Channel, subscriptionId::String, resourceGroupName::String, virtualNetworkGatewayName::String, request, api_version::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysDisconnectVirtualNetworkGatewayVpnConnections(_api, subscriptionId, resourceGroupName, virtualNetworkGatewayName, request, api_version; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Generates VPN profile for P2S client of the virtual network gateway in the specified resource group. Used for IKEV2 and radius based authentication. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: parameters::VpnClientParameters (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: String """ function _swaggerinternal_virtualNetworkGatewaysGenerateVpnProfile(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", String, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/generatevpnprofile", ["azure_auth"], parameters) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGenerateVpnProfile(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGenerateVpnProfile(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGenerateVpnProfile(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGenerateVpnProfile(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Generates VPN client package for P2S client of the virtual network gateway in the specified resource group. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: parameters::VpnClientParameters (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: String """ function _swaggerinternal_virtualNetworkGatewaysGeneratevpnclientpackage(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", String, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/generatevpnclientpackage", ["azure_auth"], parameters) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGeneratevpnclientpackage(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGeneratevpnclientpackage(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGeneratevpnclientpackage(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGeneratevpnclientpackage(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Gets the specified virtual network gateway by resource group. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: VirtualNetworkGateway """ function _swaggerinternal_virtualNetworkGatewaysGet(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "GET", VirtualNetworkGateway, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGet(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGet(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGet(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGet(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ This operation retrieves a list of routes the virtual network gateway is advertising to the specified peer. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: peer::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: GatewayRouteListResult """ function _swaggerinternal_virtualNetworkGatewaysGetAdvertisedRoutes(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, peer::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", GatewayRouteListResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getAdvertisedRoutes", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "peer", peer) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGetAdvertisedRoutes(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, peer::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetAdvertisedRoutes(_api, resourceGroupName, virtualNetworkGatewayName, peer, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGetAdvertisedRoutes(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, peer::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetAdvertisedRoutes(_api, resourceGroupName, virtualNetworkGatewayName, peer, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ The GetBgpPeerStatus operation retrieves the status of all BGP peers. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Param: peer::String Return: BgpPeerStatusListResult """ function _swaggerinternal_virtualNetworkGatewaysGetBgpPeerStatus(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; peer=nothing, _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", BgpPeerStatusListResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getBgpPeerStatus", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "peer", peer) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGetBgpPeerStatus(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; peer=nothing, _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetBgpPeerStatus(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; peer=peer, _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGetBgpPeerStatus(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; peer=nothing, _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetBgpPeerStatus(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; peer=peer, _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ This operation retrieves a list of routes the virtual network gateway has learned, including routes learned from BGP peers. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: GatewayRouteListResult """ function _swaggerinternal_virtualNetworkGatewaysGetLearnedRoutes(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", GatewayRouteListResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getLearnedRoutes", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGetLearnedRoutes(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetLearnedRoutes(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGetLearnedRoutes(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetLearnedRoutes(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Gets pre-generated VPN profile for P2S client of the virtual network gateway in the specified resource group. The profile needs to be generated first using generateVpnProfile. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: String """ function _swaggerinternal_virtualNetworkGatewaysGetVpnProfilePackageUrl(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", String, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getvpnprofilepackageurl", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGetVpnProfilePackageUrl(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetVpnProfilePackageUrl(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGetVpnProfilePackageUrl(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetVpnProfilePackageUrl(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Get VPN client connection health detail per P2S client connection of the virtual network gateway in the specified resource group. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: VpnClientConnectionHealthDetailListResult """ function _swaggerinternal_virtualNetworkGatewaysGetVpnclientConnectionHealth(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", VpnClientConnectionHealthDetailListResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getVpnClientConnectionHealth", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGetVpnclientConnectionHealth(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetVpnclientConnectionHealth(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGetVpnclientConnectionHealth(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetVpnclientConnectionHealth(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ The Get VpnclientIpsecParameters operation retrieves information about the vpnclient ipsec policy for P2S client of virtual network gateway in the specified resource group through Network resource provider. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: VpnClientIPsecParameters """ function _swaggerinternal_virtualNetworkGatewaysGetVpnclientIpsecParameters(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", VpnClientIPsecParameters, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/getvpnclientipsecparameters", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysGetVpnclientIpsecParameters(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetVpnclientIpsecParameters(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysGetVpnclientIpsecParameters(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysGetVpnclientIpsecParameters(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Gets all virtual network gateways by resource group. Param: resourceGroupName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: VirtualNetworkGatewayListResult """ function _swaggerinternal_virtualNetworkGatewaysList(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "GET", VirtualNetworkGatewayListResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysList(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysList(_api, resourceGroupName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysList(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysList(_api, resourceGroupName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Gets all the connections in a virtual network gateway. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: VirtualNetworkGatewayListConnectionsResult """ function _swaggerinternal_virtualNetworkGatewaysListConnections(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "GET", VirtualNetworkGatewayListConnectionsResult, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/connections", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysListConnections(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysListConnections(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysListConnections(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysListConnections(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Resets the primary of the virtual network gateway in the specified resource group. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Param: gatewayVip::String Return: VirtualNetworkGateway """ function _swaggerinternal_virtualNetworkGatewaysReset(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; gatewayVip=nothing, _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", VirtualNetworkGateway, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/reset", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "gatewayVip", gatewayVip) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysReset(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; gatewayVip=nothing, _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysReset(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; gatewayVip=gatewayVip, _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysReset(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; gatewayVip=nothing, _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysReset(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; gatewayVip=gatewayVip, _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Resets the VPN client shared key of the virtual network gateway in the specified resource group. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: Nothing """ function _swaggerinternal_virtualNetworkGatewaysResetVpnClientSharedKey(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", Nothing, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/resetvpnclientsharedkey", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysResetVpnClientSharedKey(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysResetVpnClientSharedKey(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysResetVpnClientSharedKey(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysResetVpnClientSharedKey(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ The Set VpnclientIpsecParameters operation sets the vpnclient ipsec policy for P2S client of virtual network gateway in the specified resource group through Network resource provider. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: vpnclientIpsecParams::VpnClientIPsecParameters (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: VpnClientIPsecParameters """ function _swaggerinternal_virtualNetworkGatewaysSetVpnclientIpsecParameters(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, vpnclientIpsecParams, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", VpnClientIPsecParameters, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/setvpnclientipsecparameters", ["azure_auth"], vpnclientIpsecParams) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysSetVpnclientIpsecParameters(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, vpnclientIpsecParams, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysSetVpnclientIpsecParameters(_api, resourceGroupName, virtualNetworkGatewayName, vpnclientIpsecParams, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysSetVpnclientIpsecParameters(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, vpnclientIpsecParams, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysSetVpnclientIpsecParameters(_api, resourceGroupName, virtualNetworkGatewayName, vpnclientIpsecParams, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Starts packet capture on virtual network gateway in the specified resource group. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Param: parameters::VpnPacketCaptureStartParameters Return: String """ function _swaggerinternal_virtualNetworkGatewaysStartPacketCapture(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; parameters=nothing, _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", String, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/startPacketCapture", ["azure_auth"], parameters) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysStartPacketCapture(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; parameters=nothing, _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysStartPacketCapture(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; parameters=parameters, _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysStartPacketCapture(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; parameters=nothing, _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysStartPacketCapture(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; parameters=parameters, _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Stops packet capture on virtual network gateway in the specified resource group. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: parameters::VpnPacketCaptureStopParameters (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: String """ function _swaggerinternal_virtualNetworkGatewaysStopPacketCapture(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", String, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/stopPacketCapture", ["azure_auth"], parameters) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysStopPacketCapture(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysStopPacketCapture(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysStopPacketCapture(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysStopPacketCapture(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Gets a xml format representation for supported vpn devices. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: String """ function _swaggerinternal_virtualNetworkGatewaysSupportedVpnDevices(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", String, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}/supportedvpndevices", ["azure_auth"]) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysSupportedVpnDevices(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysSupportedVpnDevices(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysSupportedVpnDevices(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysSupportedVpnDevices(_api, resourceGroupName, virtualNetworkGatewayName, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Updates a virtual network gateway tags. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayName::String (required) Param: parameters::TagsObject (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: VirtualNetworkGateway """ function _swaggerinternal_virtualNetworkGatewaysUpdateTags(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "PATCH", VirtualNetworkGateway, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkGateways/{virtualNetworkGatewayName}", ["azure_auth"], parameters) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayName", virtualNetworkGatewayName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysUpdateTags(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysUpdateTags(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysUpdateTags(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysUpdateTags(_api, resourceGroupName, virtualNetworkGatewayName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end """ Gets a xml format representation for vpn device configuration script. Param: resourceGroupName::String (required) Param: virtualNetworkGatewayConnectionName::String (required) Param: parameters::VpnDeviceScriptParameters (required) Param: api_version::String (required) Param: subscriptionId::String (required) Return: String """ function _swaggerinternal_virtualNetworkGatewaysVpnDeviceConfigurationScript(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayConnectionName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = Swagger.Ctx(_api.client, "POST", String, "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/connections/{virtualNetworkGatewayConnectionName}/vpndeviceconfigurationscript", ["azure_auth"], parameters) Swagger.set_param(_ctx.path, "resourceGroupName", resourceGroupName) # type String Swagger.set_param(_ctx.path, "virtualNetworkGatewayConnectionName", virtualNetworkGatewayConnectionName) # type String Swagger.set_param(_ctx.path, "subscriptionId", subscriptionId) # type String Swagger.set_param(_ctx.query, "api-version", api_version) # type String Swagger.set_header_accept(_ctx, ["application/json"]) Swagger.set_header_content_type(_ctx, (_mediaType === nothing) ? ["application/json"] : [_mediaType]) return _ctx end function virtualNetworkGatewaysVpnDeviceConfigurationScript(_api::VirtualNetworkGatewaysApi, resourceGroupName::String, virtualNetworkGatewayConnectionName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysVpnDeviceConfigurationScript(_api, resourceGroupName, virtualNetworkGatewayConnectionName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx) end function virtualNetworkGatewaysVpnDeviceConfigurationScript(_api::VirtualNetworkGatewaysApi, response_stream::Channel, resourceGroupName::String, virtualNetworkGatewayConnectionName::String, parameters, api_version::String, subscriptionId::String; _mediaType=nothing) _ctx = _swaggerinternal_virtualNetworkGatewaysVpnDeviceConfigurationScript(_api, resourceGroupName, virtualNetworkGatewayConnectionName, parameters, api_version, subscriptionId; _mediaType=_mediaType) Swagger.exec(_ctx, response_stream) end export virtualNetworkGatewaysCreateOrUpdate, virtualNetworkGatewaysDelete, virtualNetworkGatewaysDisconnectVirtualNetworkGatewayVpnConnections, virtualNetworkGatewaysGenerateVpnProfile, virtualNetworkGatewaysGeneratevpnclientpackage, virtualNetworkGatewaysGet, virtualNetworkGatewaysGetAdvertisedRoutes, virtualNetworkGatewaysGetBgpPeerStatus, virtualNetworkGatewaysGetLearnedRoutes, virtualNetworkGatewaysGetVpnProfilePackageUrl, virtualNetworkGatewaysGetVpnclientConnectionHealth, virtualNetworkGatewaysGetVpnclientIpsecParameters, virtualNetworkGatewaysList, virtualNetworkGatewaysListConnections, virtualNetworkGatewaysReset, virtualNetworkGatewaysResetVpnClientSharedKey, virtualNetworkGatewaysSetVpnclientIpsecParameters, virtualNetworkGatewaysStartPacketCapture, virtualNetworkGatewaysStopPacketCapture, virtualNetworkGatewaysSupportedVpnDevices, virtualNetworkGatewaysUpdateTags, virtualNetworkGatewaysVpnDeviceConfigurationScript
Formal statement is: lemma AE_cong_simp: "M = N \<Longrightarrow> (\<And>x. x \<in> space N =simp=> P x = Q x) \<Longrightarrow> (AE x in M. P x) \<longleftrightarrow> (AE x in N. Q x)" Informal statement is: If two measures are equal, then two sets are almost equal with respect to one measure if and only if they are almost equal with respect to the other measure.
Require Import SquiggleEq.list. Require Import SquiggleEq.UsefulTypes. Require Import common. Require Import SquiggleEq.tactics. Arguments memberb {_} {_} x l. Set Implicit Arguments. (* transparent lemma for computations. Move to SquiggleEq *) Lemma subsetb_memberb {T:Type} {dt :Deq T} (l1 l2 : list T): (subsetb _ l1 l2 = true) -> forall t, (memberb t l1) = true -> (memberb t l2) = true. Proof using. intros Hs ? Hm. remember (memberb t l2) as m2. symmetry in Heqm2. destruct m2;[reflexivity|]. apply False_rect. setoid_rewrite assert_subsetb in Hs. setoid_rewrite assert_memberb in Hm. apply Bool.not_true_iff_false in Heqm2. setoid_rewrite assert_memberb in Heqm2. eauto. Defined. (*Prop is also considered a type here.*) Inductive Props : Set := Total | OneToOne (*| Irrel *). Definition allProps : list Props := [Total; OneToOne (*; Irrel *) ]. Global Instance deq : Deq Props. Proof using. apply @deqAsSumbool. unfold DeqSumbool. intros. unfold DecidableSumbool. repeat decide equality. Defined. Notation univ := (Set) (only parsing). Definition IndicesInvUniv := Type. (* use IndUnivs here? *) (*Polymorphic *) Record GoodRel (select: list Props) (T₁ T₂: univ) : IndicesInvUniv (* nececcarily bigger than Set if univ, because of R*) := { R : T₁ -> T₂ -> Prop (* Type ? *); Rtot : if (memberb Total select) then TotalHeteroRel R else True; Rone : if (memberb OneToOne select) then oneToOne R else True; (* Proof irrelevance is not needed anymore, after changing Type to Prop in R. This item is always deselected. Can be removed once we totatlly commit to Prop and decide that assuming Proof irrelevance is acceptable. About the latter, UIP was badly needed for the oneToOne of indexed inductives. If UIP <-> Proof Irrelevance, then we will be forced to have Proof irrelevance be acceptable Rirrel : if (memberb Irrel select) then relIrrUptoEq R else True; *) }. Check (GoodRel allProps (True:Prop) (True:Prop)):Type. Fail Check (GoodRel allProps (nat:Set) (nat:Set)):Set (* because of R, this has to be atleast 1 bigger than Set*). Definition eraseRP (sb ss: list Props) (sub: subsetb _ ss sb=true) (T₁ T₂:univ) (gb: GoodRel sb T₁ T₂ ) : (GoodRel ss T₁ T₂ ). Proof. (* projecting a goodrel should compute to a goodRel. So no matching before returning a goodRel *) apply Build_GoodRel with (R:= @R sb _ _ gb); destruct gb; simpl in *; apply' subsetb_memberb sub. - specialize (sub Total). destruct (memberb _ ss);[| exact I]. specialize (sub eq_refl). rewrite sub in Rtot0. assumption. - specialize (sub OneToOne). destruct (memberb _ ss);[| exact I]. specialize (sub eq_refl). rewrite sub in Rone0. assumption. Defined. Definition onlyTotal : list Props := [Total]. Definition cast_Good_onlyTotal (T₁ T₂:univ) (gb: GoodRel allProps T₁ T₂ ) : (GoodRel onlyTotal T₁ T₂ ). apply eraseRP with (sb:=allProps);[reflexivity| assumption]. Defined. Definition BestRel : Set -> Set -> Type := GoodRel allProps (* [Total; OneToOne] *). Definition BestR : forall T₁ T₂ : Set, GoodRel allProps T₁ T₂ -> T₁ -> T₂ -> Prop := @R allProps. Lemma IsoRel_implies_iff (A B:Prop) (pb : BestRel A B) : A <-> B. Proof using. specialize (@Rtot allProps _ _ pb). simpl. intros Ht. apply Prop_RSpec in Ht. apply fst in Ht. unfold IffRel in Ht. apply tiffIff in Ht. apply Ht. Qed. Definition mkBestRel (A1 A2:Set) (AR : A1 -> A2 -> Prop) (tot12 : TotalHeteroRelHalf AR) (tot21 : TotalHeteroRelHalf (rInvSP AR)) (one12: oneToOneHalf AR) (one21: oneToOneHalf (rInvSP AR)) : BestRel A1 A2. Proof. exists AR; simpl. - split. + exact tot12. + exact tot21. - split. + exact one12. + exact one21. Defined. Definition mkBestRelPropOld (A1 A2:Prop) (AR : A1 -> A2 -> Prop) (tot12 : TotalHeteroRelHalf AR) (tot21 : TotalHeteroRelHalf (rInvSP AR)) : BestRel A1 A2. Proof. exists AR; simpl. - split. + exact tot12. + exact tot21. - apply propeOneToOne. Defined. (* TODO: remove new *) Definition mkBestRelProp (A1 A2:Prop) (AR : A1 -> A2 -> Prop) (tot12 : iffCompleteHalf AR) (tot21 : iffCompleteHalf (rInvSP AR)) : BestRel A1 A2. Proof. exists AR; simpl. - apply iffHalfTotal; assumption. - apply propeOneToOne. Defined. Definition BestTot12 (T₁ T₂ : Set) (T_R: GoodRel allProps T₁ T₂) (t1:T₁) : T₂ := projT1 ((fst (Rtot T_R)) t1). Definition BestTot12R (T₁ T₂ : Set) (T_R: GoodRel allProps T₁ T₂) (t1:T₁) := projT2 ((fst (Rtot T_R)) t1). Definition BestTot21 (T₁ T₂ : Set) (T_R: GoodRel allProps T₁ T₂) (t2:T₂) : T₁ := projT1 ((snd (Rtot T_R)) t2). Definition BestTot21R (T₁ T₂ : Set) (T_R: GoodRel allProps T₁ T₂) (t2:T₂) := projT2 ((snd (Rtot T_R)) t2). Definition BestOne12 (A B : Set) (T_R: GoodRel allProps A B) (a :A) (b1 b2 :B) (r1 : R T_R a b1) (r2 : R T_R a b2) : b2=b1 := eq_sym ((proj1 (Rone T_R)) a b1 b2 r1 r2). Definition BestOne21 (A B : Set) (T_R: GoodRel allProps A B) (a1 :A) (b :B) (a2:A) (r1 : R T_R a1 b) (r2 : R T_R a2 b) : a2 = a1 := eq_sym ((proj2 (Rone T_R)) b a1 a2 r1 r2). Definition BestOneijjo (A B : Set) (T_R: GoodRel allProps A B) (a :A) (b1 b2 :B) (r1 : R T_R a b1) (r2 : R T_R a b2) : b1=b2 := ((proj1 (Rone T_R)) a b1 b2 r1 r2). Definition BestOneijjo21 (A B : Set) (T_R: GoodRel allProps A B) (b :B) (a1 a2:A) (r1 : R T_R a1 b) (r2 : R T_R a2 b) : a1 = a2 := ((proj2 (Rone T_R)) b a1 a2 r1 r2). Definition BestRelP : Prop -> Prop -> Prop := iff. Definition BestRP (T₁ T₂ : Prop) (t₁ : T₁) (t₂ : T₂) : Prop := True. Require Import ProofIrrelevance. (* The relation for Prop cannot be (fun _ _ => True) as it breaks many things: see the erasure section of onenote https://onedrive.live.com/edit.aspx/Documents/Postdoc?cid=946e75b47b19a3b5&id=documents&wd=target%28parametricity%2Fpapers%2Flogic%2Ferasure.one%7CE3B57163-01F2-A447-8AD2-A7AA172DB692%2F%29 onenote:https://d.docs.live.net/946e75b47b19a3b5/Documents/Postdoc/parametricity/papers/logic/erasure.one#section-id={E3B57163-01F2-A447-8AD2-A7AA172DB692}&end *) Definition GoodPropAsSet {A1 A2:Prop} (bp: BestRelP A1 A2) : BestRel A1 A2. unfold BestRelP in bp. exists (fun _ _ => True); simpl. - apply Prop_RSpec. unfold Prop_R,IffRel,CompleteRel. apply tiffIff in bp. split; [assumption|]. intros ? ?. exact I. - split; intros ? ? ? ? ?; apply proof_irrelevance. Defined.
[STATEMENT] lemma favorites_altdef: "favorites R i = Max_wrt_among (R i) alts" [PROOF STATE] proof (prove) goal (1 subgoal): 1. favorites R i = Max_wrt_among (R i) alts [PROOF STEP] proof (cases "i \<in> agents") [PROOF STATE] proof (state) goal (2 subgoals): 1. i \<in> agents \<Longrightarrow> favorites R i = Max_wrt_among (R i) alts 2. i \<notin> agents \<Longrightarrow> favorites R i = Max_wrt_among (R i) alts [PROOF STEP] assume "i \<in> agents" [PROOF STATE] proof (state) this: i \<in> agents goal (2 subgoals): 1. i \<in> agents \<Longrightarrow> favorites R i = Max_wrt_among (R i) alts 2. i \<notin> agents \<Longrightarrow> favorites R i = Max_wrt_among (R i) alts [PROOF STEP] then [PROOF STATE] proof (chain) picking this: i \<in> agents [PROOF STEP] interpret total_preorder_on alts "R i" [PROOF STATE] proof (prove) using this: i \<in> agents goal (1 subgoal): 1. total_preorder_on alts (R i) [PROOF STEP] by simp [PROOF STATE] proof (state) goal (2 subgoals): 1. i \<in> agents \<Longrightarrow> favorites R i = Max_wrt_among (R i) alts 2. i \<notin> agents \<Longrightarrow> favorites R i = Max_wrt_among (R i) alts [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) goal (1 subgoal): 1. favorites R i = Max_wrt_among (R i) alts [PROOF STEP] by (simp add: favorites_def Max_wrt_total_preorder Max_wrt_among_total_preorder) [PROOF STATE] proof (state) this: favorites R i = Max_wrt_among (R i) alts goal (1 subgoal): 1. i \<notin> agents \<Longrightarrow> favorites R i = Max_wrt_among (R i) alts [PROOF STEP] qed (simp_all add: favorites_def Max_wrt_def Max_wrt_among_def pref_profile_wf_def)
module QAOA import Data.Nat import Data.Vect import Graph import Lemmas import Unitary import Control.Linear.LIO import QStateT import Injection import LinearTypes import Complex import System.Random import QuantumOp import RandomUtilities %default total ||| Vanilla QAOA : we use QAOA with a vanilla optimisation procedure to solve MAXCUT. -------------------------QUANTUM CIRCUITS---------------------- ||| The unitary operator induced by the mixing hamiltonian. ||| n -- the arity of the operator ||| beta -- the rotation angle parameter mixingUnitary : (n : Nat) -> (beta : Double) -> Unitary n mixingUnitary n beta = tensorn n (RxGate beta) ||| Helper function for costUnitary ||| m -- number of vertices of the input subgraph ||| n -- number of remaining edges between current vertex and the rest ||| prf -- proof witness that the number of vertices does not exceed the arity of the operator ||| gamma -- the rotation parameter ||| edges -- vector of edges that the current vertex is connected to ||| currentUnitary -- the currently constructed unitary operator ||| output -- the final unitary operator costUnitary' : {n : Nat} -> {m : Nat} -> {auto prf : n < m = True} -> (gamma : Double) -> (edges : Vect n Bool) -> (currentUnitary : Unitary m) -> Unitary m costUnitary' _ [] currentUnitary = currentUnitary costUnitary' {n = S k} gamma (False :: xs) currentUnitary = let proof1 = lemmaLTSuccLT k m in costUnitary' gamma xs currentUnitary costUnitary' {n = S k} gamma (True :: xs) currentUnitary = let proof1 = lemmaCompLT0 m (S k) proof2 = lemmaLTSuccLT k m cx = CNOT 0 (S k) (IdGate {n = m}) rzcx = P gamma (S k) cx rest = costUnitary' gamma xs currentUnitary in rest . cx . rzcx ||| The unitary operator induced by the cost hamiltonian. ||| n -- the number of vertices of the input graph ||| graph -- the input graph ||| gamma -- rotation parameter ||| output -- the resulting unitary operator costUnitary : {n : Nat} -> (graph: Graph n) -> (gamma : Double) -> Unitary n costUnitary Empty _ = IdGate costUnitary (AddVertex graph edges) gamma = let circuit = (IdGate {n = 1}) # (costUnitary graph gamma) proof1 = lemmaLTSucc n in costUnitary' gamma edges circuit ||| The iterated cost and mixing unitaries for QAOA_p ||| n -- the number of vertices of the graph ||| p -- the "p" parameter of QAOA_p, i.e., the number of iterations of the mixing and cost unitaries ||| betas -- list of rotation parameters for the mixing hamiltonians ||| gammas -- list of rotation parameters for the cost hamilitonians ||| graph -- the input graph ||| output -- the overall unitary operator of QAOA_p QAOA_Unitary' : {n : Nat} -> (betas : Vect p Double) -> (gammas : Vect p Double) -> (graph: Graph n) -> Unitary n QAOA_Unitary' [] [] g = IdGate QAOA_Unitary' (beta :: betas) (gamma :: gammas) g = let circuit = QAOA_Unitary' betas gammas g in circuit . mixingUnitary n beta . costUnitary g gamma ||| The overall unitary operator for QAOA_p ||| n -- the number of vertices of the graph ||| p -- the "p" parameter of QAOA_p, i.e., the number of iterations of the mixing and cost unitaries ||| betas -- list of rotation parameters for the mixing hamiltonians ||| gammas -- list of rotation parameters for the cost hamilitonians ||| graph -- the input graph ||| output -- the overall unitary operator of QAOA_p export QAOA_Unitary : {n : Nat} -> (betas : Vect p Double) -> (gammas : Vect p Double) -> (graph: Graph n) -> Unitary n QAOA_Unitary betas gammas graph = (QAOA_Unitary' betas gammas graph) . (tensorn n HGate) -------------------------CLASSICAL PART------------------------ ||| The (probabilistic) classical optimisation procedure for QAOA. ||| IO output allows us to use probabilistic optimisation procedures. ||| Given all previously observed information, determine new rotation angles for the next QAOA run. ||| Remark: we randomly generate the next rotation angles for simplicity. ||| ||| k -- number of previous iterations of the algorithm ||| p -- "p" parameter for QAOA_p ||| n -- number of vertices of the input graph ||| graph -- the input graph ||| previous_info -- previously used parameters and previously observed cuts from QAOA runs ||| IO output -- new rotation angles for the next run of QAOA classicalOptimisation : {p : Nat} -> (graph : Graph n) -> (previous_info : Vect k (Vect p Double, Vect p Double, Cut n)) -> IO (Vect p Double, Vect p Double) classicalOptimisation g ys = do betas <- randomVect p gammas <- randomVect p pure (betas,gammas) -----------------------------QAOA------------------------------ ||| Helper function for QAOA ||| ||| n -- number of vertices of the input graph ||| p -- the "p" parameter of QAOA_p ||| k -- number of times we sample (the number of times we execute QAOA_p) ||| graph -- input graph of the problem ||| output -- all observed cuts and all rotation angles from all the runs of QAOA QAOA' : QuantumOp t => {n : Nat} -> (k : Nat) -> (p : Nat) -> (graph : Graph n) -> IO (Vect k (Vect p Double, Vect p Double, Cut n)) QAOA' 0 p graph = pure [] QAOA' (S k) p graph = do previous_info <- QAOA' {t} k p graph (betas, gammas) <- classicalOptimisation graph previous_info let circuit = QAOA_Unitary betas gammas graph cut <- run (do qs <- newQubits {t} n qs <- applyUnitary qs circuit measureAll qs ) pure $ (betas, gammas, cut) :: previous_info ||| QAOA for the MAXCUT problem. Given an input graph, return the best observed cut after some number of iterations. ||| ||| n -- number of vertices of the input graph ||| p -- the "p" parameter of QAOA_p ||| k -- number of times we sample (the number of times we execute QAOA_p) ||| graph -- input graph of the problem ||| output -- best observed cut from the execution of the algorithm export QAOA : QuantumOp t => {n : Nat} -> (k : Nat) -> (p : Nat) -> Graph n -> IO (Cut n) QAOA k p graph = do res <- QAOA' {t} k p graph let cuts = map (\(_, _, cut) => cut) res let (cut,size) = bestCut graph cuts pure cut
* * ------------------------------------------------------------------ * C F G T S T * ------------------------------------------------------------------ * SUBROUTINE CFGTST(NCFG,LJCOMP,NOCCSH,NELCSH,NOCORB,J1QNRD,NCD) * * THIS SUBROUTINE CHECKS ALL THE CONFIGURATION SET TO ENSURE THAT * IT SATISFIES ALL THE FOLLOWING CONDITIONS: * (1) EACH CONFIGURATION HAS THE SAME NUMBER OF ELECTRONS * (2) NO SUBSHELL HAS TOO MANY (.GT.2*(2*L+1)) ELECTRONS * (3) THE ELECTRONS IN ANY ONE SUBSHELL ARE COUPLED TO FORM AN * ALLOWED TRIAD OF QUANTUM NUMBERS * (4) THE TRIADS COUPLE TOGETHER IN AN ALLOWED WAY * * IN THE EVENT OF AN ERROR, THE PROGRAM HALTS AT THE COMPLETION * OF THE CHECKING. ANY NUMBER OF S, P, D ELECTRONS ARE ALLOWED, * (BUT .LE.2*(2*L+1)), BUT ONLY UP TO TWO ELECTRONS, L >=3. * WHEN L>4, THE ONLY ALLOWED TERMS ARE THOSE FOR L=4. * A FILLED F-SHELL IS ALSO ALLOWED AS WELL AS A SINGLE ELECTRON * WITH L.GT.4 * COMMON/INFORM/IREAD,IWRITE,IOUT,ISC0,ISC1,ISC2,ISC3,JSC0,JSC(3) COMMON/TERMS/NROWS,ITAB(24),JTAB(24),NTAB(333) * DIMENSION LJCOMP(*),NOCCSH(NCD),NELCSH(5,NCD),NOCORB(5,NCD), : J1QNRD(9,NCD) * 5 FORMAT(/38H THE TRIAD OF QUANTUM NUMBERS OF SHELL,I3,17H IN CONFIG :URATION,I3,24H IS NOT A RECOGNIZED SET) 7 FORMAT(/22H THE COUPLING OF SHELL,I3,17H IN CONFIGURATION,I3, : 38H RESULTS IN AN ILLEGAL COUPLING SCHEME) 12 FORMAT(//41H CONFIGURATION DATA WRONG, PROGRAM HALTED//) 15 FORMAT(/17H IN CONFIGURATION,I3,7H, SHELL,I3,28H CONTAINS TOO MANY : ELECTRONS) 17 FORMAT(/14H CONFIGURATION,I3,68H INCLUDES A SHELL OF ANGULAR MOMEN :TUM L.GE.3 WITH TOO MANY ELECTRONS) 18 FORMAT(/14H CONFIGURATION,I3,28H HAS AN INCORRECT NUMBER OF , : 9HELECTRONS) * IALLOW=1 DO 1 I=1,NCFG NELSUM = 0 N=NOCCSH(I) DO 2 J=1,N NA=NOCORB(J,I) LQU=LJCOMP(NA) NC=NELCSH(J,I) NELSUM = NELSUM + NC JD = J1QNRD(J,I) JA = MOD(JD,64) JD = JD/64 JB = MOD(JD,64) JC = JD/64 LQUMAX = 4*LQU + 2 IF (NC .GT. LQUMAX) THEN WRITE(IWRITE,15) I,J IALLOW = 0 GO TO 2 ELSE IF ((LQU.EQ.3 .AND. NC.GT.2 .AND. NC.LT.14) .OR. : (LQU.GT.4.AND.NC.GT.2)) THEN WRITE(IWRITE,17) I IALLOW = 0 GO TO 2 ELSE IF (NC .EQ. 1) THEN IF (JA.EQ.1 .AND. JB.EQ.(2*LQU+1) .AND. JC.EQ.2) GO TO 21 ELSE IF (LQU .GT. 4 .AND. NC .EQ. 2) LQU = 4 IF (NC .EQ. LQUMAX) THEN NROW = 2 ELSE NROW = NTAB1(NC+1,LQU+1) END IF I1 = ITAB(NROW) I2 = JTAB(NROW) DO 4 IA = 1,I1 I3 = I2+3*IA-1 IF (JB .EQ. NTAB(I3)) THEN I3 = I3+1 IF (JC .EQ. NTAB(I3)) THEN I3 = I3-2 IF (JA .EQ. NTAB(I3)) GO TO 21 END IF END IF 4 CONTINUE END IF IALLOW = 0 WRITE(IWRITE,5) J,I GO TO 2 * * CHECK ON THE COUPLING OF THE TRIADS * 21 IF (N.GT.1 .AND. J.GT.1) THEN J2 = N+J-1 J1 = J2-1 IF (J.EQ.2) J1 = 1 JE = J1QNRD(J1,I)/64 JD = MOD(JE,64) JE = JE/64 JG = J1QNRD(J2,I)/64 JF = MOD(JG,64) JG = JG/64 IF (JF.GE.(JB+JD) .OR. JF.LE.IABS(JB-JD) .OR. : JG.GE.(JC+JE) .OR. JG.LE.IABS(JC-JE) .OR. : MOD(JC+JE-JG,2).EQ.0 ) THEN WRITE(IWRITE,7) J,I IALLOW = 0 END IF END IF 2 CONTINUE IF (I .EQ. 1) THEN NELCS = NELSUM ELSE IF (NELSUM .NE. NELCS) THEN WRITE(IWRITE,18) I IALLOW = 0 END IF 1 CONTINUE IF (IALLOW .EQ. 0) THEN WRITE(IWRITE,12) STOP END IF END
(* Authors: Heiko Loetzbeyer, Robert Sandner, Tobias Nipkow *) section "Denotational Semantics of Commands" theory Denotational imports Big_Step begin type_synonym com_den = "(state \<times> state) set" definition W :: "(state \<Rightarrow> bool) \<Rightarrow> com_den \<Rightarrow> (com_den \<Rightarrow> com_den)" where "W db dc = (\<lambda>dw. {(s,t). if db s then (s,t) \<in> dc O dw else s=t})" fun D :: "com \<Rightarrow> com_den" where "D SKIP = Id" | "D (x ::= a) = {(s,t). t = s(x := aval a s)}" | "D (c1;;c2) = D(c1) O D(c2)" | "D (IF b THEN c1 ELSE c2) = {(s,t). if bval b s then (s,t) \<in> D c1 else (s,t) \<in> D c2}" | "D (WHILE b DO c) = lfp (W (bval b) (D c))" lemma W_mono: "mono (W b r)" by (unfold W_def mono_def) auto lemma D_While_If: "D(WHILE b DO c) = D(IF b THEN c;;WHILE b DO c ELSE SKIP)" proof- let ?w = "WHILE b DO c" let ?f = "W (bval b) (D c)" have "D ?w = lfp ?f" by simp also have "\<dots> = ?f (lfp ?f)" by(rule lfp_unfold [OF W_mono]) also have "\<dots> = D(IF b THEN c;;?w ELSE SKIP)" by (simp add: W_def) finally show ?thesis . qed text{* Equivalence of denotational and big-step semantics: *} lemma D_if_big_step: "(c,s) \<Rightarrow> t \<Longrightarrow> (s,t) \<in> D(c)" proof (induction rule: big_step_induct) case WhileFalse with D_While_If show ?case by auto next case WhileTrue show ?case unfolding D_While_If using WhileTrue by auto qed auto abbreviation Big_step :: "com \<Rightarrow> com_den" where "Big_step c \<equiv> {(s,t). (c,s) \<Rightarrow> t}" lemma Big_step_if_D: "(s,t) \<in> D(c) \<Longrightarrow> (s,t) : Big_step c" proof (induction c arbitrary: s t) case Seq thus ?case by fastforce next case (While b c) let ?B = "Big_step (WHILE b DO c)" let ?f = "W (bval b) (D c)" have "?f ?B \<subseteq> ?B" using While.IH by (auto simp: W_def) from lfp_lowerbound[where ?f = "?f", OF this] While.prems show ?case by auto qed (auto split: if_splits) theorem denotational_is_big_step: "(s,t) \<in> D(c) = ((c,s) \<Rightarrow> t)" by (metis D_if_big_step Big_step_if_D[simplified]) corollary equiv_c_iff_equal_D: "(c1 \<sim> c2) \<longleftrightarrow> D c1 = D c2" by(simp add: denotational_is_big_step[symmetric] set_eq_iff) subsection "Continuity" definition chain :: "(nat \<Rightarrow> 'a set) \<Rightarrow> bool" where "chain S = (\<forall>i. S i \<subseteq> S(Suc i))" lemma chain_total: "chain S \<Longrightarrow> S i \<le> S j \<or> S j \<le> S i" by (metis chain_def le_cases lift_Suc_mono_le) definition cont :: "('a set \<Rightarrow> 'b set) \<Rightarrow> bool" where "cont f = (\<forall>S. chain S \<longrightarrow> f(UN n. S n) = (UN n. f(S n)))" lemma mono_if_cont: fixes f :: "'a set \<Rightarrow> 'b set" assumes "cont f" shows "mono f" proof fix a b :: "'a set" assume "a \<subseteq> b" let ?S = "\<lambda>n::nat. if n=0 then a else b" have "chain ?S" using `a \<subseteq> b` by(auto simp: chain_def) hence "f(UN n. ?S n) = (UN n. f(?S n))" using assms by(simp add: cont_def) moreover have "(UN n. ?S n) = b" using `a \<subseteq> b` by (auto split: if_splits) moreover have "(UN n. f(?S n)) = f a \<union> f b" by (auto split: if_splits) ultimately show "f a \<subseteq> f b" by (metis Un_upper1) qed lemma chain_iterates: fixes f :: "'a set \<Rightarrow> 'a set" assumes "mono f" shows "chain(\<lambda>n. (f^^n) {})" proof- { fix n have "(f ^^ n) {} \<subseteq> (f ^^ Suc n) {}" using assms by(induction n) (auto simp: mono_def) } thus ?thesis by(auto simp: chain_def) qed theorem lfp_if_cont: assumes "cont f" shows "lfp f = (UN n. (f^^n) {})" (is "_ = ?U") proof from assms mono_if_cont have mono: "(f ^^ n) {} \<subseteq> (f ^^ Suc n) {}" for n using funpow_decreasing [of n "Suc n"] by auto show "lfp f \<subseteq> ?U" proof (rule lfp_lowerbound) have "f ?U = (UN n. (f^^Suc n){})" using chain_iterates[OF mono_if_cont[OF assms]] assms by(simp add: cont_def) also have "\<dots> = (f^^0){} \<union> \<dots>" by simp also have "\<dots> = ?U" using mono by auto (metis funpow_simps_right(2) funpow_swap1 o_apply) finally show "f ?U \<subseteq> ?U" by simp qed next { fix n p assume "f p \<subseteq> p" have "(f^^n){} \<subseteq> p" proof(induction n) case 0 show ?case by simp next case Suc from monoD[OF mono_if_cont[OF assms] Suc] `f p \<subseteq> p` show ?case by simp qed } thus "?U \<subseteq> lfp f" by(auto simp: lfp_def) qed lemma cont_W: "cont(W b r)" by(auto simp: cont_def W_def) subsection{*The denotational semantics is deterministic*} lemma single_valued_UN_chain: assumes "chain S" "(\<And>n. single_valued (S n))" shows "single_valued(UN n. S n)" proof(auto simp: single_valued_def) fix m n x y z assume "(x, y) \<in> S m" "(x, z) \<in> S n" with chain_total[OF assms(1), of m n] assms(2) show "y = z" by (auto simp: single_valued_def) qed lemma single_valued_lfp: fixes f :: "com_den \<Rightarrow> com_den" assumes "cont f" "\<And>r. single_valued r \<Longrightarrow> single_valued (f r)" shows "single_valued(lfp f)" unfolding lfp_if_cont[OF assms(1)] proof(rule single_valued_UN_chain[OF chain_iterates[OF mono_if_cont[OF assms(1)]]]) fix n show "single_valued ((f ^^ n) {})" by(induction n)(auto simp: assms(2)) qed lemma single_valued_D: "single_valued (D c)" proof(induction c) case Seq thus ?case by(simp add: single_valued_relcomp) next case (While b c) let ?f = "W (bval b) (D c)" have "single_valued (lfp ?f)" proof(rule single_valued_lfp[OF cont_W]) show "\<And>r. single_valued r \<Longrightarrow> single_valued (?f r)" using While.IH by(force simp: single_valued_def W_def) qed thus ?case by simp qed (auto simp add: single_valued_def) end
lemma (in discrete_topology) at_discrete: "at x within S = bot"
lemma filterlim_tendsto_pos_mult_at_top: assumes f: "(f \<longlongrightarrow> c) F" and c: "0 < c" and g: "LIM x F. g x :> at_top" shows "LIM x F. (f x * g x :: real) :> at_top"
学习和使用支持向量机 - 学习教材6.3、6.4节内容,调试运行相关代码。 - 查阅scikit-learn工具包中支持向量机的相关说明,了解分类器函数使用方法。 - 完成作业二 # SMO高效优化算法 > 书本代码参考仓库[Machine Learning in Action](https://github.com/TeFuirnever/Machine-Learning-in-Action) SMO算法的目标是求出一系列alpha和b,便于计算权重向量并得到分隔超平面。 工作原理:选择两个alpha进行优化处理,一旦找到一对合适的alpha,那么就增大一个减少另一个。 > “合适”:①alpha须在间隔边界之外;②alpha没有进行过区间化处理或者不在边界上。 ## 简化版SMO 量少,但执行速度慢。跳过SMO的外循环(确定最佳alpha对),遍历每个alpha随机选择另一个。 ```python import numpy as np import random ``` ```python ## 6-1 SMO算法中的辅助函数 """ 函数说明:读取数据 Parameters: fileName - 文件名 Returns: dataMat - 数据矩阵 labelMat - 数据标签 """ def loadDataSet(fileName): dataMat = []; labelMat = [] fr = open(fileName) for line in fr.readlines(): #逐行读取,滤除空格等 lineArr = line.strip().split('\t') dataMat.append([float(lineArr[0]), float(lineArr[1])]) #添加数据 labelMat.append(float(lineArr[2])) #添加标签 return dataMat,labelMat """ 函数说明:随机选择alpha Parameters: i - alpha m - alpha参数个数 Returns: j - """ def selectJrand(i, m): j = i #选择一个不等于i的j while (j == i): j = int(random.uniform(0, m)) return j """ 函数说明:修剪alpha Parameters: aj - alpha值 H - alpha上限 L - alpha下限 Returns: aj - alpah值 """ def clipAlpha(aj,H,L): if aj > H: aj = H if L > aj: aj = L return aj ``` ```python dataArr, labelArr = loadDataSet('./data/testSet.txt') print(labelArr[:5]) ``` [-1.0, -1.0, 1.0, -1.0, 1.0] 该数据集中类别标签为1,-1。 SMO的伪代码大致如下: > * 创建一个alpha向量并将其初始化为0向量 > > * 当迭代次数小于最大迭代次数时: > > * 对数据集中的每个数据向量(外循环): > > * 如果该向量可以被优化: > > * 随机选择另外一个数据向量(内循环) > > * 同时优化这两个向量 > > * 如果两个向量都不能被优化,退出内循环 > > * 如果所有向量都没有被优化,增加迭代数目,继续下一次循环 $$ fXi = \sum_{j=1}^N \alpha_j y_j X_j \cdot X_i $$ 步骤1:计算误差Ei=f(x)-y 步骤2:计算上下界L和H $$ L = \max{(0,\alpha_2^{\text{old}}-\alpha_1^{\text{old}})}, \ \ \ H=\min{(C,C+\alpha_2^{\text{old}}-\alpha_1^{\text{old}})}\\ 或\\ L = \max{(0,\alpha_2^{\text{old}}+\alpha_1^{\text{old}}-C)}, \ \ \ H=\min{(C,\alpha_2^{\text{old}}+\alpha_1^{\text{old}})} $$ 步骤3:计算eta(η) $$ \eta = K_{11} + K_{22} - 2K_{12} = ||\phi(x_1)-\phi(x_2)||^2 $$ 步骤4:更新alpha_j $$ \alpha_2^{\text{new,unc}} = \alpha_2^{\text{old}} + \dfrac{y_2(E_1-E_2)}{\eta} $$ 步骤5:修剪alpha_j $$ \alpha_2^{new} = \left\{ \begin{align} &H, &\alpha_2^{\text{new,unc}}\gt H \\ &\alpha_2^{\text{new,unc}}, & L \le\alpha_2^{\text{new,unc}}\le H \\ &L, &\alpha_2^{\text{new,unc}}\lt L \end{align} \right. $$ 步骤6:更新alpha_i $$ \alpha_1^{\text{new}} = \alpha_1^{\text{old}} + y_1y_2(\alpha_2^{\text{old}}-\alpha_2^{\text{new}}) $$ 步骤7:更新b_1和b_2 $$ b_1^{\text{new}} = b^{\text{old}} - E_1 - y_1K_{11}(\alpha_1^{\text{new}}-\alpha_1^{\text{old}}) - y_2K_{21}(\alpha_2^{\text{new}}-\alpha_2^{\text{old}})\\ b_2^{\text{new}} = b^{\text{old}} - E_2 - y_1K_{12}(\alpha_1^{\text{new}}-\alpha_1^{\text{old}}) - y_2K_{22}(\alpha_2^{\text{new}}-\alpha_2^{\text{old}})\\ $$ 步骤8:根据b_1和b_2更新b ```python """ 函数说明:简化版SMO算法 Parameters: dataMatIn - 数据矩阵 classLabels - 数据标签 C - 松弛变量 toler - 容错率 maxIter - 最大迭代次数 Returns: 无 """ def smoSimple(dataMatIn, classLabels, C, toler, maxIter): #转换为numpy的mat存储 dataMatrix = np.mat(dataMatIn); labelMat = np.mat(classLabels).transpose() #初始化b参数,统计dataMatrix的维度 b = 0; m,n = np.shape(dataMatrix) #初始化alpha参数,设为0 alphas = np.mat(np.zeros((m,1))) #初始化迭代次数 iter_num = 0 #最多迭代matIter次 while (iter_num < maxIter): alphaPairsChanged = 0 for i in range(m): #步骤1:计算误差Ei fXi = float(np.multiply(alphas,labelMat).T*(dataMatrix*dataMatrix[i,:].T)) + b ##fXi = \sum_{j=1}^N \alpha_j y_j X_j \cdot X_i X:Vector Ei = fXi - float(labelMat[i]) #优化alpha,更设定一定的容错率。 if ((labelMat[i]*Ei < -toler) and (alphas[i] < C)) or ((labelMat[i]*Ei > toler) and (alphas[i] > 0)): #随机选择另一个与alpha_i成对优化的alpha_j j = selectJrand(i,m) #步骤1:计算误差Ej fXj = float(np.multiply(alphas,labelMat).T*(dataMatrix*dataMatrix[j,:].T)) + b Ej = fXj - float(labelMat[j]) #保存更新前的aplpha值,使用深拷贝 alphaIold = alphas[i].copy(); alphaJold = alphas[j].copy(); #步骤2:计算上下界L和H if (labelMat[i] != labelMat[j]): L = max(0, alphas[j] - alphas[i]) H = min(C, C + alphas[j] - alphas[i]) else: L = max(0, alphas[j] + alphas[i] - C) H = min(C, alphas[j] + alphas[i]) ## L = \max{(0,\alpha_2^{\text{old}}-\alpha_1^{\text{old}})}, \ \ \ H=\min{(C,C+\alpha_2^{\text{old}}-\alpha_1^{\text{old}})} ## L = \max{(0,\alpha_2^{\text{old}}+\alpha_1^{\text{old}}-C)}, \ \ \ H=\min{(C,\alpha_2^{\text{old}}+\alpha_1^{\text{old}})} if L==H: print("L==H"); continue #步骤3:计算eta(η) eta = 2.0 * dataMatrix[i,:]*dataMatrix[j,:].T - dataMatrix[i,:]*dataMatrix[i,:].T - dataMatrix[j,:]*dataMatrix[j,:].T ## \eta = K_{11} + K_{22} - 2K_{12} = ||\phi(x_1)-\phi(x_2)||^2 if eta >= 0: print("eta>=0"); continue #步骤4:更新alpha_j alphas[j] -= labelMat[j]*(Ei - Ej)/eta ## \alpha_2^{\text{new,unc}} = \alpha_2^{\text{old}} + \dfrac{y_2(E_1-E_2)}{\eta} #步骤5:修剪alpha_j alphas[j] = clipAlpha(alphas[j],H,L) if (abs(alphas[j] - alphaJold) < 0.00001): print("alpha_j变化太小"); continue #步骤6:更新alpha_i alphas[i] += labelMat[j]*labelMat[i]*(alphaJold - alphas[j]) ## \alpha_1^{\text{new}} = \alpha_1^{\text{old}} + y_1y_2(\alpha_2^{\text{old}}-\alpha_2^{\text{new}}) #步骤7:更新b_1和b_2 b1 = b - Ei- labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[i,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[i,:]*dataMatrix[j,:].T b2 = b - Ej- labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[j,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[j,:]*dataMatrix[j,:].T ##b_1^{\text{new}} = b^{\text{old}} - E_1 - y_1K_{11}(\alpha_1^{\text{new}}-\alpha_1^{\text{old}}) - y_2K_{21}(\alpha_2^{\text{new}}-\alpha_2^{\text{old}})\\ ##b_2^{\text{new}} = b^{\text{old}} - E_2 - y_1K_{12}(\alpha_1^{\text{new}}-\alpha_1^{\text{old}}) - y_2K_{22}(\alpha_2^{\text{new}}-\alpha_2^{\text{old}})\\ #步骤8:根据b_1和b_2更新b if (0 < alphas[i]) and (C > alphas[i]): b = b1 elif (0 < alphas[j]) and (C > alphas[j]): b = b2 else: b = (b1 + b2)/2.0 #统计优化次数 alphaPairsChanged += 1 #打印统计信息 print("第%d次迭代 样本:%d, alpha优化次数:%d" % (iter_num,i,alphaPairsChanged)) #更新迭代次数 if (alphaPairsChanged == 0): iter_num += 1 else: iter_num = 0 print("迭代次数: %d" % iter_num) return b,alphas ``` 进行简单的测试: ```python %%time b, alphas = smoSimple(dataArr, labelArr, 0.6, 0.001, 40) ``` 第0次迭代 样本:0, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:5, alpha优化次数:2 L==H L==H L==H 第0次迭代 样本:23, alpha优化次数:3 第0次迭代 样本:24, alpha优化次数:4 第0次迭代 样本:25, alpha优化次数:5 第0次迭代 样本:26, alpha优化次数:6 alpha_j变化太小 第0次迭代 样本:31, alpha优化次数:7 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:56, alpha优化次数:8 L==H alpha_j变化太小 L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H alpha_j变化太小 L==H L==H alpha_j变化太小 L==H alpha_j变化太小 L==H alpha_j变化太小 alpha_j变化太小 L==H 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第1次迭代 样本:10, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第1次迭代 样本:29, alpha优化次数:2 第1次迭代 样本:54, alpha优化次数:3 第1次迭代 样本:55, alpha优化次数:4 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H alpha_j变化太小 第0次迭代 样本:71, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:10, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:45, alpha优化次数:2 第0次迭代 样本:54, alpha优化次数:3 alpha_j变化太小 alpha_j变化太小 L==H 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:5, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:23, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:55, alpha优化次数:2 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:10, alpha优化次数:1 第0次迭代 样本:17, alpha优化次数:2 alpha_j变化太小 第0次迭代 样本:24, alpha优化次数:3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:54, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 第0次迭代 样本:1, alpha优化次数:1 L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:54, alpha优化次数:1 第0次迭代 样本:55, alpha优化次数:2 第0次迭代 样本:94, alpha优化次数:3 alpha_j变化太小 迭代次数: 0 第0次迭代 样本:0, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:97, alpha优化次数:2 迭代次数: 0 alpha_j变化太小 L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 第1次迭代 样本:10, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:52, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:23, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:46, alpha优化次数:2 alpha_j变化太小 第0次迭代 样本:54, alpha优化次数:3 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 第0次迭代 样本:10, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 第2次迭代 样本:8, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第2次迭代 样本:29, alpha优化次数:2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第1次迭代 样本:55, alpha优化次数:1 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:24, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 L==H alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 第1次迭代 样本:17, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 第0次迭代 样本:23, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:54, alpha优化次数:2 第0次迭代 样本:55, alpha优化次数:3 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第3次迭代 样本:54, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 5 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 6 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 7 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 8 alpha_j变化太小 alpha_j变化太小 第8次迭代 样本:29, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 5 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 6 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 7 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第7次迭代 样本:55, alpha优化次数:1 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:54, alpha优化次数:1 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第3次迭代 样本:29, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 第0次迭代 样本:17, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第3次迭代 样本:54, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 第1次迭代 样本:23, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 第0次迭代 样本:17, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第2次迭代 样本:54, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 第2次迭代 样本:17, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 5 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 6 alpha_j变化太小 第6次迭代 样本:29, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 5 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 6 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 7 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 8 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 9 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 10 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 11 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 12 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 13 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 14 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 15 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 16 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 17 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 18 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 19 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 20 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 21 alpha_j变化太小 第21次迭代 样本:23, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第4次迭代 样本:54, alpha优化次数:1 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 第1次迭代 样本:55, alpha优化次数:1 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 L==H alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 5 alpha_j变化太小 alpha_j变化太小 L==H alpha_j变化太小 迭代次数: 6 第6次迭代 样本:17, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 5 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 6 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 7 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 8 alpha_j变化太小 第8次迭代 样本:29, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:55, alpha优化次数:1 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 第0次迭代 样本:54, alpha优化次数:1 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 第1次迭代 样本:52, alpha优化次数:1 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 迭代次数: 5 alpha_j变化太小 alpha_j变化太小 迭代次数: 6 alpha_j变化太小 alpha_j变化太小 迭代次数: 7 alpha_j变化太小 alpha_j变化太小 迭代次数: 8 alpha_j变化太小 alpha_j变化太小 迭代次数: 9 alpha_j变化太小 alpha_j变化太小 迭代次数: 10 alpha_j变化太小 alpha_j变化太小 迭代次数: 11 alpha_j变化太小 alpha_j变化太小 迭代次数: 12 alpha_j变化太小 alpha_j变化太小 迭代次数: 13 alpha_j变化太小 alpha_j变化太小 迭代次数: 14 第14次迭代 样本:17, alpha优化次数:1 alpha_j变化太小 alpha_j变化太小 迭代次数: 0 alpha_j变化太小 alpha_j变化太小 迭代次数: 1 alpha_j变化太小 alpha_j变化太小 迭代次数: 2 alpha_j变化太小 alpha_j变化太小 迭代次数: 3 alpha_j变化太小 alpha_j变化太小 迭代次数: 4 alpha_j变化太小 alpha_j变化太小 迭代次数: 5 alpha_j变化太小 alpha_j变化太小 迭代次数: 6 alpha_j变化太小 alpha_j变化太小 迭代次数: 7 alpha_j变化太小 alpha_j变化太小 迭代次数: 8 alpha_j变化太小 alpha_j变化太小 迭代次数: 9 alpha_j变化太小 alpha_j变化太小 迭代次数: 10 alpha_j变化太小 alpha_j变化太小 迭代次数: 11 alpha_j变化太小 alpha_j变化太小 迭代次数: 12 alpha_j变化太小 alpha_j变化太小 迭代次数: 13 alpha_j变化太小 alpha_j变化太小 迭代次数: 14 alpha_j变化太小 alpha_j变化太小 迭代次数: 15 alpha_j变化太小 alpha_j变化太小 迭代次数: 16 alpha_j变化太小 alpha_j变化太小 迭代次数: 17 alpha_j变化太小 alpha_j变化太小 迭代次数: 18 alpha_j变化太小 alpha_j变化太小 迭代次数: 19 alpha_j变化太小 alpha_j变化太小 迭代次数: 20 alpha_j变化太小 alpha_j变化太小 迭代次数: 21 alpha_j变化太小 alpha_j变化太小 迭代次数: 22 alpha_j变化太小 alpha_j变化太小 迭代次数: 23 alpha_j变化太小 alpha_j变化太小 迭代次数: 24 alpha_j变化太小 alpha_j变化太小 迭代次数: 25 alpha_j变化太小 alpha_j变化太小 迭代次数: 26 alpha_j变化太小 alpha_j变化太小 迭代次数: 27 alpha_j变化太小 alpha_j变化太小 迭代次数: 28 alpha_j变化太小 alpha_j变化太小 迭代次数: 29 alpha_j变化太小 alpha_j变化太小 迭代次数: 30 alpha_j变化太小 alpha_j变化太小 迭代次数: 31 alpha_j变化太小 alpha_j变化太小 迭代次数: 32 alpha_j变化太小 alpha_j变化太小 迭代次数: 33 alpha_j变化太小 alpha_j变化太小 迭代次数: 34 alpha_j变化太小 alpha_j变化太小 迭代次数: 35 alpha_j变化太小 alpha_j变化太小 迭代次数: 36 alpha_j变化太小 alpha_j变化太小 迭代次数: 37 alpha_j变化太小 alpha_j变化太小 迭代次数: 38 alpha_j变化太小 alpha_j变化太小 迭代次数: 39 alpha_j变化太小 alpha_j变化太小 迭代次数: 40 CPU times: user 3.03 s, sys: 567 ms, total: 3.6 s Wall time: 2.75 s ```python b ``` matrix([[-3.90043157]]) ```python alphas[alphas>0] ``` matrix([[0.10104876, 0.26933193, 0.03268721, 0.33769349]]) ## 完整Platt SMO 简化版SMO中,外层循环是遍历所有样本点作为 $\alpha_i$ ,内层循环则是随机选择 $\alpha_j$ 更新这两个 $\alpha$ 。这样做计算速度较慢,在较大量数据集或维度较高数据集中很可能耗时过多。 完整版的Platt SMO的外层循环是遍历所有样本点和遍历非边界点交替进行,遍历所有样本点之后就遍历所有非边界点,遍历非边界点之后如果没有 $\alpha$ 被更新则重新遍历所有样本点;否则继续遍历非边界点。 内循环则不是随机选择,是通过计算最大化步长 $|E_i-E_j|$ 来进行选择,选择使得 $|E_i-E_j|$ 最大的点作为 $\alpha_j$。 简化版和完整版仅在 $\alpha$ 的选择上有所不同,内部计算和更新方法相同,不再赘述。但是后者的计算效率相对较高。 ```python ## 6-3 完整版SMO的支持函数 """ 数据结构,维护所有需要操作的值 Parameters: dataMatIn - 数据矩阵 classLabels - 数据标签 C - 松弛变量 toler - 容错率 """ class optStruct: def __init__(self, dataMatIn, classLabels, C, toler): self.X = dataMatIn #数据矩阵 self.labelMat = classLabels #数据标签 self.C = C #松弛变量 self.tol = toler #容错率 self.m = np.shape(dataMatIn)[0] #数据矩阵行数 self.alphas = np.mat(np.zeros((self.m,1))) #根据矩阵行数初始化alpha参数为0 self.b = 0 #初始化b参数为0 self.eCache = np.mat(np.zeros((self.m,2))) #根据矩阵行数初始化虎误差缓存,第一列为是否有效的标志位,第二列为实际的误差E的值。 """ 读取数据 Parameters: fileName - 文件名 Returns: dataMat - 数据矩阵 labelMat - 数据标签 """ def loadDataSet(fileName): dataMat = []; labelMat = [] fr = open(fileName) for line in fr.readlines(): #逐行读取,滤除空格等 lineArr = line.strip().split('\t') dataMat.append([float(lineArr[0]), float(lineArr[1])]) #添加数据 labelMat.append(float(lineArr[2])) #添加标签 return dataMat,labelMat """ 计算误差 Parameters: oS - 数据结构 k - 标号为k的数据 Returns: Ek - 标号为k的数据误差 """ def calcEk(oS, k): fXk = float(np.multiply(oS.alphas,oS.labelMat).T*(oS.X*oS.X[k,:].T) + oS.b) Ek = fXk - float(oS.labelMat[k]) return Ek """ 内循环启发方式2 Parameters: i - 标号为i的数据的索引值 oS - 数据结构 Ei - 标号为i的数据误差 Returns: j, maxK - 标号为j或maxK的数据的索引值 Ej - 标号为j的数据误差 """ def selectJ(i, oS, Ei): maxK = -1; maxDeltaE = 0; Ej = 0 #初始化 oS.eCache[i] = [1,Ei] #根据Ei更新误差缓存 validEcacheList = np.nonzero(oS.eCache[:,0].A)[0] #返回误差不为0的数据的索引值 if (len(validEcacheList)) > 1: #有不为0的误差 for k in validEcacheList: #遍历,找到最大的Ek if k == i: continue #不计算i,浪费时间 Ek = calcEk(oS, k) #计算Ek deltaE = abs(Ei - Ek) #计算|Ei-Ek| if (deltaE > maxDeltaE): #找到maxDeltaE maxK = k; maxDeltaE = deltaE; Ej = Ek return maxK, Ej #返回maxK,Ej else: #没有不为0的误差 j = selectJrand(i, oS.m) #随机选择alpha_j的索引值 Ej = calcEk(oS, j) #计算Ej return j, Ej #j,Ej """ 计算Ek,并更新误差缓存 Parameters: oS - 数据结构 k - 标号为k的数据的索引值 Returns: 无 """ def updateEk(oS, k): Ek = calcEk(oS, k) #计算Ek oS.eCache[k] = [1,Ek] #更新误差缓存 ``` ```python ## 6-4 完整Platt SMO算法中的优化例程 """ 优化的SMO算法 Parameters: i - 标号为i的数据的索引值 oS - 数据结构 Returns: 1 - 有任意一对alpha值发生变化 0 - 没有任意一对alpha值发生变化或变化太小 """ def innerL(i, oS): #步骤1:计算误差Ei Ei = calcEk(oS, i) #优化alpha,设定一定的容错率。 if ((oS.labelMat[i] * Ei < -oS.tol) and (oS.alphas[i] < oS.C)) or ((oS.labelMat[i] * Ei > oS.tol) and (oS.alphas[i] > 0)): #使用内循环启发方式2选择alpha_j,并计算Ej j,Ej = selectJ(i, oS, Ei) #保存更新前的aplpha值,使用深拷贝 alphaIold = oS.alphas[i].copy(); alphaJold = oS.alphas[j].copy(); #步骤2:计算上下界L和H if (oS.labelMat[i] != oS.labelMat[j]): L = max(0, oS.alphas[j] - oS.alphas[i]) H = min(oS.C, oS.C + oS.alphas[j] - oS.alphas[i]) else: L = max(0, oS.alphas[j] + oS.alphas[i] - oS.C) H = min(oS.C, oS.alphas[j] + oS.alphas[i]) if L == H: print("L==H") return 0 #步骤3:计算eta eta = 2.0 * oS.X[i,:] * oS.X[j,:].T - oS.X[i,:] * oS.X[i,:].T - oS.X[j,:] * oS.X[j,:].T if eta >= 0: print("eta>=0") return 0 #步骤4:更新alpha_j oS.alphas[j] -= oS.labelMat[j] * (Ei - Ej)/eta #步骤5:修剪alpha_j oS.alphas[j] = clipAlpha(oS.alphas[j],H,L) #更新Ej至误差缓存 updateEk(oS, j) if (abs(oS.alphas[j] - alphaJold) < 0.00001): print("alpha_j变化太小") return 0 #步骤6:更新alpha_i oS.alphas[i] += oS.labelMat[j]*oS.labelMat[i]*(alphaJold - oS.alphas[j]) #更新Ei至误差缓存 updateEk(oS, i) #步骤7:更新b_1和b_2 b1 = oS.b - Ei- oS.labelMat[i]*(oS.alphas[i]-alphaIold)*oS.X[i,:]*oS.X[i,:].T - oS.labelMat[j]*(oS.alphas[j]-alphaJold)*oS.X[i,:]*oS.X[j,:].T b2 = oS.b - Ej- oS.labelMat[i]*(oS.alphas[i]-alphaIold)*oS.X[i,:]*oS.X[j,:].T - oS.labelMat[j]*(oS.alphas[j]-alphaJold)*oS.X[j,:]*oS.X[j,:].T #步骤8:根据b_1和b_2更新b if (0 < oS.alphas[i]) and (oS.C > oS.alphas[i]): oS.b = b1 elif (0 < oS.alphas[j]) and (oS.C > oS.alphas[j]): oS.b = b2 else: oS.b = (b1 + b2)/2.0 return 1 else: return 0 ``` ```python """ 完整的线性SMO算法 Parameters: dataMatIn - 数据矩阵 classLabels - 数据标签 C - 松弛变量 toler - 容错率 maxIter - 最大迭代次数 Returns: oS.b - SMO算法计算的b oS.alphas - SMO算法计算的alphas """ def smoP(dataMatIn, classLabels, C, toler, maxIter): oS = optStruct(np.mat(dataMatIn), np.mat(classLabels).transpose(), C, toler) #初始化数据结构 iter = 0 #初始化当前迭代次数 entireSet = True; alphaPairsChanged = 0 while (iter < maxIter) and ((alphaPairsChanged > 0) or (entireSet)): #遍历整个数据集都alpha也没有更新或者超过最大迭代次数,则退出循环 alphaPairsChanged = 0 if entireSet: #遍历整个数据集 for i in range(oS.m):# 对数据集中的所有行 alphaPairsChanged += innerL(i,oS) #使用优化的SMO算法 print("全样本遍历:第%d次迭代 样本:%d, alpha优化次数:%d" % (iter,i,alphaPairsChanged)) iter += 1 else: #遍历非边界值 nonBoundIs = np.nonzero((oS.alphas.A > 0) * (oS.alphas.A < C))[0] #遍历不在边界0和C的alpha for i in nonBoundIs: alphaPairsChanged += innerL(i,oS) print("非边界遍历:第%d次迭代 样本:%d, alpha优化次数:%d" % (iter,i,alphaPairsChanged)) iter += 1 if entireSet: #遍历一次后改为非边界遍历 entireSet = False elif (alphaPairsChanged == 0): #如果alpha没有更新,计算全样本遍历 entireSet = True print("迭代次数: %d" % iter) return oS.b,oS.alphas #返回SMO算法计算的b和alphas ``` 测试 ```python %%time dataArr, labelArr = loadDataSet('./data/testSet.txt') b, alphas = smoP(dataArr, labelArr, 0.6, 0.001, 40) ``` 全样本遍历:第0次迭代 样本:0, alpha优化次数:1 全样本遍历:第0次迭代 样本:1, alpha优化次数:1 全样本遍历:第0次迭代 样本:2, alpha优化次数:2 全样本遍历:第0次迭代 样本:3, alpha优化次数:3 全样本遍历:第0次迭代 样本:4, alpha优化次数:4 全样本遍历:第0次迭代 样本:5, alpha优化次数:5 全样本遍历:第0次迭代 样本:6, alpha优化次数:5 全样本遍历:第0次迭代 样本:7, alpha优化次数:5 全样本遍历:第0次迭代 样本:8, alpha优化次数:6 全样本遍历:第0次迭代 样本:9, alpha优化次数:6 L==H 全样本遍历:第0次迭代 样本:10, alpha优化次数:6 全样本遍历:第0次迭代 样本:11, alpha优化次数:6 全样本遍历:第0次迭代 样本:12, alpha优化次数:6 全样本遍历:第0次迭代 样本:13, alpha优化次数:6 全样本遍历:第0次迭代 样本:14, alpha优化次数:6 全样本遍历:第0次迭代 样本:15, alpha优化次数:7 全样本遍历:第0次迭代 样本:16, alpha优化次数:7 L==H 全样本遍历:第0次迭代 样本:17, alpha优化次数:7 全样本遍历:第0次迭代 样本:18, alpha优化次数:8 全样本遍历:第0次迭代 样本:19, alpha优化次数:8 全样本遍历:第0次迭代 样本:20, alpha优化次数:8 全样本遍历:第0次迭代 样本:21, alpha优化次数:8 全样本遍历:第0次迭代 样本:22, alpha优化次数:8 L==H 全样本遍历:第0次迭代 样本:23, alpha优化次数:8 全样本遍历:第0次迭代 样本:24, alpha优化次数:8 alpha_j变化太小 全样本遍历:第0次迭代 样本:25, alpha优化次数:8 L==H 全样本遍历:第0次迭代 样本:26, alpha优化次数:8 全样本遍历:第0次迭代 样本:27, alpha优化次数:8 全样本遍历:第0次迭代 样本:28, alpha优化次数:8 L==H 全样本遍历:第0次迭代 样本:29, alpha优化次数:8 全样本遍历:第0次迭代 样本:30, alpha优化次数:8 全样本遍历:第0次迭代 样本:31, alpha优化次数:8 全样本遍历:第0次迭代 样本:32, alpha优化次数:8 全样本遍历:第0次迭代 样本:33, alpha优化次数:8 全样本遍历:第0次迭代 样本:34, alpha优化次数:8 全样本遍历:第0次迭代 样本:35, alpha优化次数:8 全样本遍历:第0次迭代 样本:36, alpha优化次数:8 全样本遍历:第0次迭代 样本:37, alpha优化次数:8 全样本遍历:第0次迭代 样本:38, alpha优化次数:8 全样本遍历:第0次迭代 样本:39, alpha优化次数:8 全样本遍历:第0次迭代 样本:40, alpha优化次数:8 全样本遍历:第0次迭代 样本:41, alpha优化次数:8 全样本遍历:第0次迭代 样本:42, alpha优化次数:8 全样本遍历:第0次迭代 样本:43, alpha优化次数:8 全样本遍历:第0次迭代 样本:44, alpha优化次数:8 alpha_j变化太小 全样本遍历:第0次迭代 样本:45, alpha优化次数:8 L==H 全样本遍历:第0次迭代 样本:46, alpha优化次数:8 全样本遍历:第0次迭代 样本:47, alpha优化次数:8 全样本遍历:第0次迭代 样本:48, alpha优化次数:8 全样本遍历:第0次迭代 样本:49, alpha优化次数:8 全样本遍历:第0次迭代 样本:50, alpha优化次数:8 全样本遍历:第0次迭代 样本:51, alpha优化次数:8 L==H 全样本遍历:第0次迭代 样本:52, alpha优化次数:8 全样本遍历:第0次迭代 样本:53, alpha优化次数:8 L==H 全样本遍历:第0次迭代 样本:54, alpha优化次数:8 L==H 全样本遍历:第0次迭代 样本:55, alpha优化次数:8 全样本遍历:第0次迭代 样本:56, alpha优化次数:8 全样本遍历:第0次迭代 样本:57, alpha优化次数:9 全样本遍历:第0次迭代 样本:58, alpha优化次数:9 全样本遍历:第0次迭代 样本:59, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:60, alpha优化次数:9 全样本遍历:第0次迭代 样本:61, alpha优化次数:9 全样本遍历:第0次迭代 样本:62, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:63, alpha优化次数:9 全样本遍历:第0次迭代 样本:64, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:65, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:66, alpha优化次数:9 全样本遍历:第0次迭代 样本:67, alpha优化次数:9 全样本遍历:第0次迭代 样本:68, alpha优化次数:9 全样本遍历:第0次迭代 样本:69, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:70, alpha优化次数:9 全样本遍历:第0次迭代 样本:71, alpha优化次数:9 全样本遍历:第0次迭代 样本:72, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:73, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:74, alpha优化次数:9 全样本遍历:第0次迭代 样本:75, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:76, alpha优化次数:9 全样本遍历:第0次迭代 样本:77, alpha优化次数:9 全样本遍历:第0次迭代 样本:78, alpha优化次数:9 全样本遍历:第0次迭代 样本:79, alpha优化次数:9 全样本遍历:第0次迭代 样本:80, alpha优化次数:9 全样本遍历:第0次迭代 样本:81, alpha优化次数:9 全样本遍历:第0次迭代 样本:82, alpha优化次数:9 全样本遍历:第0次迭代 样本:83, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:84, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:85, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:86, alpha优化次数:9 alpha_j变化太小 全样本遍历:第0次迭代 样本:87, alpha优化次数:9 全样本遍历:第0次迭代 样本:88, alpha优化次数:9 全样本遍历:第0次迭代 样本:89, alpha优化次数:9 全样本遍历:第0次迭代 样本:90, alpha优化次数:9 全样本遍历:第0次迭代 样本:91, alpha优化次数:9 全样本遍历:第0次迭代 样本:92, alpha优化次数:9 全样本遍历:第0次迭代 样本:93, alpha优化次数:9 全样本遍历:第0次迭代 样本:94, alpha优化次数:10 全样本遍历:第0次迭代 样本:95, alpha优化次数:10 全样本遍历:第0次迭代 样本:96, alpha优化次数:10 alpha_j变化太小 全样本遍历:第0次迭代 样本:97, alpha优化次数:10 全样本遍历:第0次迭代 样本:98, alpha优化次数:10 全样本遍历:第0次迭代 样本:99, alpha优化次数:10 迭代次数: 1 alpha_j变化太小 非边界遍历:第1次迭代 样本:0, alpha优化次数:0 alpha_j变化太小 非边界遍历:第1次迭代 样本:4, alpha优化次数:0 alpha_j变化太小 非边界遍历:第1次迭代 样本:5, alpha优化次数:0 alpha_j变化太小 非边界遍历:第1次迭代 样本:8, alpha优化次数:0 alpha_j变化太小 非边界遍历:第1次迭代 样本:15, alpha优化次数:0 alpha_j变化太小 非边界遍历:第1次迭代 样本:17, alpha优化次数:0 alpha_j变化太小 非边界遍历:第1次迭代 样本:18, alpha优化次数:0 非边界遍历:第1次迭代 样本:55, alpha优化次数:0 非边界遍历:第1次迭代 样本:94, alpha优化次数:0 迭代次数: 2 alpha_j变化太小 全样本遍历:第2次迭代 样本:0, alpha优化次数:0 全样本遍历:第2次迭代 样本:1, alpha优化次数:0 全样本遍历:第2次迭代 样本:2, alpha优化次数:0 全样本遍历:第2次迭代 样本:3, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:4, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:5, alpha优化次数:0 全样本遍历:第2次迭代 样本:6, alpha优化次数:0 全样本遍历:第2次迭代 样本:7, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:8, alpha优化次数:0 全样本遍历:第2次迭代 样本:9, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:10, alpha优化次数:0 全样本遍历:第2次迭代 样本:11, alpha优化次数:0 全样本遍历:第2次迭代 样本:12, alpha优化次数:0 全样本遍历:第2次迭代 样本:13, alpha优化次数:0 全样本遍历:第2次迭代 样本:14, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:15, alpha优化次数:0 全样本遍历:第2次迭代 样本:16, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:17, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:18, alpha优化次数:0 全样本遍历:第2次迭代 样本:19, alpha优化次数:0 全样本遍历:第2次迭代 样本:20, alpha优化次数:0 全样本遍历:第2次迭代 样本:21, alpha优化次数:0 全样本遍历:第2次迭代 样本:22, alpha优化次数:0 L==H 全样本遍历:第2次迭代 样本:23, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:24, alpha优化次数:0 全样本遍历:第2次迭代 样本:25, alpha优化次数:0 全样本遍历:第2次迭代 样本:26, alpha优化次数:0 全样本遍历:第2次迭代 样本:27, alpha优化次数:0 全样本遍历:第2次迭代 样本:28, alpha优化次数:0 L==H 全样本遍历:第2次迭代 样本:29, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:30, alpha优化次数:0 全样本遍历:第2次迭代 样本:31, alpha优化次数:0 全样本遍历:第2次迭代 样本:32, alpha优化次数:0 全样本遍历:第2次迭代 样本:33, alpha优化次数:0 全样本遍历:第2次迭代 样本:34, alpha优化次数:0 全样本遍历:第2次迭代 样本:35, alpha优化次数:0 全样本遍历:第2次迭代 样本:36, alpha优化次数:0 全样本遍历:第2次迭代 样本:37, alpha优化次数:0 全样本遍历:第2次迭代 样本:38, alpha优化次数:0 全样本遍历:第2次迭代 样本:39, alpha优化次数:0 全样本遍历:第2次迭代 样本:40, alpha优化次数:0 全样本遍历:第2次迭代 样本:41, alpha优化次数:0 全样本遍历:第2次迭代 样本:42, alpha优化次数:0 全样本遍历:第2次迭代 样本:43, alpha优化次数:0 全样本遍历:第2次迭代 样本:44, alpha优化次数:0 全样本遍历:第2次迭代 样本:45, alpha优化次数:0 全样本遍历:第2次迭代 样本:46, alpha优化次数:0 全样本遍历:第2次迭代 样本:47, alpha优化次数:0 全样本遍历:第2次迭代 样本:48, alpha优化次数:0 全样本遍历:第2次迭代 样本:49, alpha优化次数:0 全样本遍历:第2次迭代 样本:50, alpha优化次数:0 全样本遍历:第2次迭代 样本:51, alpha优化次数:0 L==H 全样本遍历:第2次迭代 样本:52, alpha优化次数:0 全样本遍历:第2次迭代 样本:53, alpha优化次数:0 L==H 全样本遍历:第2次迭代 样本:54, alpha优化次数:0 全样本遍历:第2次迭代 样本:55, alpha优化次数:0 全样本遍历:第2次迭代 样本:56, alpha优化次数:0 全样本遍历:第2次迭代 样本:57, alpha优化次数:0 全样本遍历:第2次迭代 样本:58, alpha优化次数:0 全样本遍历:第2次迭代 样本:59, alpha优化次数:0 全样本遍历:第2次迭代 样本:60, alpha优化次数:0 全样本遍历:第2次迭代 样本:61, alpha优化次数:0 全样本遍历:第2次迭代 样本:62, alpha优化次数:0 全样本遍历:第2次迭代 样本:63, alpha优化次数:0 全样本遍历:第2次迭代 样本:64, alpha优化次数:0 全样本遍历:第2次迭代 样本:65, alpha优化次数:0 全样本遍历:第2次迭代 样本:66, alpha优化次数:0 全样本遍历:第2次迭代 样本:67, alpha优化次数:0 全样本遍历:第2次迭代 样本:68, alpha优化次数:0 全样本遍历:第2次迭代 样本:69, alpha优化次数:0 全样本遍历:第2次迭代 样本:70, alpha优化次数:0 全样本遍历:第2次迭代 样本:71, alpha优化次数:0 全样本遍历:第2次迭代 样本:72, alpha优化次数:0 全样本遍历:第2次迭代 样本:73, alpha优化次数:0 全样本遍历:第2次迭代 样本:74, alpha优化次数:0 全样本遍历:第2次迭代 样本:75, alpha优化次数:0 全样本遍历:第2次迭代 样本:76, alpha优化次数:0 全样本遍历:第2次迭代 样本:77, alpha优化次数:0 全样本遍历:第2次迭代 样本:78, alpha优化次数:0 全样本遍历:第2次迭代 样本:79, alpha优化次数:0 全样本遍历:第2次迭代 样本:80, alpha优化次数:0 全样本遍历:第2次迭代 样本:81, alpha优化次数:0 全样本遍历:第2次迭代 样本:82, alpha优化次数:0 全样本遍历:第2次迭代 样本:83, alpha优化次数:0 全样本遍历:第2次迭代 样本:84, alpha优化次数:0 全样本遍历:第2次迭代 样本:85, alpha优化次数:0 全样本遍历:第2次迭代 样本:86, alpha优化次数:0 全样本遍历:第2次迭代 样本:87, alpha优化次数:0 全样本遍历:第2次迭代 样本:88, alpha优化次数:0 全样本遍历:第2次迭代 样本:89, alpha优化次数:0 全样本遍历:第2次迭代 样本:90, alpha优化次数:0 全样本遍历:第2次迭代 样本:91, alpha优化次数:0 全样本遍历:第2次迭代 样本:92, alpha优化次数:0 全样本遍历:第2次迭代 样本:93, alpha优化次数:0 全样本遍历:第2次迭代 样本:94, alpha优化次数:0 全样本遍历:第2次迭代 样本:95, alpha优化次数:0 全样本遍历:第2次迭代 样本:96, alpha优化次数:0 alpha_j变化太小 全样本遍历:第2次迭代 样本:97, alpha优化次数:0 全样本遍历:第2次迭代 样本:98, alpha优化次数:0 全样本遍历:第2次迭代 样本:99, alpha优化次数:0 迭代次数: 3 CPU times: user 152 ms, sys: 52.8 ms, total: 205 ms Wall time: 149 ms 用时方面,在相同配置的主机上,时间从7秒下降到了不到0.3秒。 利用计算得到的alpha值,可以计算w用于构建超平面。 ```python def calcWs(alphas, dataArr, classLabels): X = np.mat(dataArr); labelMat = np.mat(classLabels).transpose() m,n = X.shape w = np.zeros((n,1)) for i in range(m): w += np.multiply(alphas[i]*labelMat[i],X[i,:].T) return w ``` ```python ws = calcWs(alphas,dataArr,labelArr) ws ``` array([[ 0.65263178], [-0.17581327]]) 分类 ```python datMat = np.mat(dataArr) print(datMat[0]*np.mat(ws)+b) ``` [[-0.93044397]] 若该值大于0,其属于1类;若该值小于0,属于-1类,这里得到的分类结果是-1,我们验证一下是不是一样的: ```python labelArr[0] ``` -1.0 # SVM in scikit-learn 查阅scikit-learn工具包中支持向量机的相关说明,了解分类器函数使用方法。 参考这一篇进行学习:[机器学习笔记3-sklearn支持向量机](https://www.jianshu.com/p/a9f9954355b3?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation) 调包当然是非常简单的拉~ ```python from sklearn.svm import SVC from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(dataArr, labelArr, test_size = 0.2, random_state = 100,stratify=labelArr) clf = SVC() clf.fit(X_train, y_train) print('预测样例:') print(clf.predict(np.array(X_test[0:5]))) print(y_test[0:5]) train_score = clf.score(X_train,y_train) test_score = clf.score(X_test,y_test) print("Train Score: %.3f; Test Score %.3f." % (train_score,test_score)) ``` 预测样例: [ 1. -1. -1. -1. -1.] [1.0, -1.0, -1.0, -1.0, -1.0] Train Score: 1.000; Test Score 1.000. 好屌,难道是因为是二分类,或者这个样本集很好分吗?什么参数都没有调,准确率达到了100\%。 因为准确率过高,所以后续对SVM的优化需要基于新的数据集,否则无法评判优化的效果。 官方源码: ```Python sklearn.svm.SVC(C=1.0, kernel='rbf', degree=3, gamma='auto', coef0=0.0, shrinking=True, probability=False, tol=0.001, cache_size=200, class_weight=None, verbose=False, max_iter=-1, decision_function_shape='ovr', random_state=None) ``` 参考官方源码给出的参数,可以对其进行一定的优化,主要调节的参数有:C、kernel、degree、gamma、coef0。 * C:C-SVC的惩罚参数C,默认值是1.0 > C越大,相当于惩罚松弛变量,希望松弛变量接近0,即对误分类的惩罚增大,趋向于对训练集全分对的情况,这样对训练集测试时准确率很高,但泛化能力弱。C值小,对误分类的惩罚减小,允许容错,将他们当成噪声点,泛化能力较强。 * kernel :核函数,默认是rbf,可以是`linear`, `poly`, `rbf`, `sigmoid` > 线性:$\kappa(\boldsymbol{x}_i,\boldsymbol{x}_j)=\boldsymbol{x}_i^T\boldsymbol{x}_j$ > > 多项式: $\kappa(\boldsymbol{x}_i,\boldsymbol{x}_j)=(\boldsymbol{x}_i^T\boldsymbol{x}_j)^d$ > > RBF函数/高斯核函数: $\kappa(\boldsymbol{x}_i,\boldsymbol{x}_j)=\exp\left(-\dfrac{||\boldsymbol{x}_i-\boldsymbol{x}_j||^2}{2\sigma^2}\right)$ > > sigmoid:$\kappa(\boldsymbol{x}_i,\boldsymbol{x}_j)=\tanh{(\beta\boldsymbol{x}_i^T\boldsymbol{x}_j+\theta)}$ * degree :多项式poly函数的维度,默认是3,选择其他核函数时会被忽略。 * gamma : `rbf`,`poly` 和`sigmoid`的核函数参数。默认是`auto`,则会选择1/n_features * coef0 :核函数的常数项。对于`poly`和 `sigmoid`有用。 # 作业二: 已知正例点 $x_1=(1,2)^T$ , $x_2=(2,3)^T$ , $x_3=(3,3)^T$,负例点 $x_4=(2,1)^T$ , $x_5=(3,2)^T$ ,试求最大间隔分离超平面和分类决策函数,并在图上画出分离超平面,间隔边界以及支持向量。 (统计学习方法第七章课后习题2) **解** 参考最大间隔算法,根据训练数据集构造约束最优化问题 $$ \min\frac{1}{2}(w_1^2+w_2^2)\\ s.t. \left\{ \begin{align} w_1+2w_2+b&\ge 1 \tag{1}\\ 2w_1+3w_2+b&\ge 1 \tag{2}\\ 3w_1+3w_2+b&\ge 1 \tag{3}\\ -2w_1-w_2-b&\ge 1 \tag{4}\\ -3w_1-2w_2-b&\ge 1 \tag{5} \end{align} \right. $$ 求得此最优化问题的解$w_1=-1,\ w_2=2,\ b=-2$。于是最大间隔分离超平面为 $$ -x^{(1)}+2x^{(2)}-2=0 $$ 支持向量 $x_1=(1,2)^T$ , $x_3=(3,3)^T$ , $x_5=(3,2)^T$. 分类决策函数 $$ f(x)=\text{sign}(-x^{(1)}+2x^{(2)}-2) $$ 用程序进行同等的求解验证: ```python from sklearn import svm x=[[1, 2], [2, 3], [3, 3], [2, 1], [3, 2]] y=[1, 1, 1, -1, -1] clf = svm.SVC(kernel='linear',C=10000) clf.fit(x, y) print(clf.coef_) print(clf.intercept_) ``` [[-1. 2.]] [-2.] 得到的解相同,接下来可以进行一定的可视化: ```python import matplotlib.pyplot as plt import numpy as np plt.scatter([i[0] for i in x], [i[1] for i in x], c=y) xaxis = np.linspace(0, 3.5) w = clf.coef_[0] a = -w[0] / w[1] y_sep = a * xaxis - (clf.intercept_[0]) / w[1] b = clf.support_vectors_[0] yy_down = a * xaxis + (b[1] - a * b[0]) b = clf.support_vectors_[-1] yy_up = a * xaxis + (b[1] - a * b[0]) plt.plot(xaxis, y_sep, 'k-') plt.plot(xaxis, yy_down, 'k--') plt.plot(xaxis, yy_up, 'k--') plt.scatter (clf.support_vectors_[:, 0], clf.support_vectors_[:, 1], s=150, facecolors='none', edgecolors='k') plt.show() ``` # + 另一种SMO 另一种参考统计学习方法上的思路, 外层循环选择**违背KKT条件最严重**的 $\alpha$ 作为 $\alpha_i$,首先遍历间隔边界上的点( $0 \lt \alpha_i \lt C$ ),如果这些点都满足KKT条件,则遍历所有样本点。 内层循环选择启发式方法选择: * 如果 $E_i$ 为正,选择最小的 $E$ 作为 $E_j$;如果 $E_i$ 为负,选择最大的 $E$ 作为 $E_j$。(总之使步长最大) * 如果上一步都不能使目标函数有足够的下降,则遍历间隔边界上的支持向量点,依次将其作为 $\alpha_j$ 使用。 * 如果都不能使目标函数有足够的下降,则遍历训练集的所有向量点,依次将其作为 $\alpha_j$ 使用。 * 如果所有点都不能使目标函数有足够的下降,则放弃当前 $\alpha_i$ ,通过外层循环生成新的 $\alpha_i$ 。 参考[fengdu78/lihang-code](https://github.com/fengdu78/lihang-code)的实现代码: ```python class SVM: def __init__(self, max_iter=100, kernel='linear'): self.max_iter = max_iter self._kernel = kernel def init_args(self, features, labels): self.m, self.n = features.shape self.X = features self.Y = labels self.b = 0.0 # 将Ei保存在一个列表里 self.alpha = np.ones(self.m) self.E = [self._E(i) for i in range(self.m)] # 松弛变量 self.C = 1.0 def _KKT(self, i): y_g = self._g(i) * self.Y[i] if self.alpha[i] == 0: return y_g >= 1 elif 0 < self.alpha[i] < self.C: return y_g == 1 else: return y_g <= 1 # g(x)预测值,输入xi(X[i]) def _g(self, i): r = self.b for j in range(self.m): r += self.alpha[j] * self.Y[j] * self.kernel(self.X[i], self.X[j]) return r # 核函数 def kernel(self, x1, x2): if self._kernel == 'linear': return sum([x1[k] * x2[k] for k in range(self.n)]) elif self._kernel == 'poly': return (sum([x1[k] * x2[k] for k in range(self.n)]) + 1)**2 return 0 # E(x)为g(x)对输入x的预测值和y的差 def _E(self, i): return self._g(i) - self.Y[i] def _init_alpha(self): # 外层循环首先遍历所有满足0<a<C的样本点,检验是否满足KKT index_list = [i for i in range(self.m) if 0 < self.alpha[i] < self.C] # 否则遍历整个训练集 non_satisfy_list = [i for i in range(self.m) if i not in index_list] index_list.extend(non_satisfy_list) for i in index_list: if self._KKT(i): continue E1 = self.E[i] # 如果E2是+,选择最小的;如果E2是负的,选择最大的 if E1 >= 0: j = min(range(self.m), key=lambda x: self.E[x]) else: j = max(range(self.m), key=lambda x: self.E[x]) return i, j def _compare(self, _alpha, L, H): if _alpha > H: return H elif _alpha < L: return L else: return _alpha def fit(self, features, labels): self.init_args(features, labels) for t in range(self.max_iter): # train i1, i2 = self._init_alpha() # 边界 if self.Y[i1] == self.Y[i2]: L = max(0, self.alpha[i1] + self.alpha[i2] - self.C) H = min(self.C, self.alpha[i1] + self.alpha[i2]) else: L = max(0, self.alpha[i2] - self.alpha[i1]) H = min(self.C, self.C + self.alpha[i2] - self.alpha[i1]) E1 = self.E[i1] E2 = self.E[i2] # eta=K11+K22-2K12 eta = self.kernel(self.X[i1], self.X[i1]) + self.kernel( self.X[i2], self.X[i2]) - 2 * self.kernel(self.X[i1], self.X[i2]) if eta <= 0: # print('eta <= 0') continue alpha2_new_unc = self.alpha[i2] + self.Y[i2] * ( E1 - E2) / eta #此处有修改,根据书上应该是E1 - E2,书上130-131页 alpha2_new = self._compare(alpha2_new_unc, L, H) alpha1_new = self.alpha[i1] + self.Y[i1] * self.Y[i2] * ( self.alpha[i2] - alpha2_new) b1_new = -E1 - self.Y[i1] * self.kernel(self.X[i1], self.X[i1]) * ( alpha1_new - self.alpha[i1]) - self.Y[i2] * self.kernel( self.X[i2], self.X[i1]) * (alpha2_new - self.alpha[i2]) + self.b b2_new = -E2 - self.Y[i1] * self.kernel(self.X[i1], self.X[i2]) * ( alpha1_new - self.alpha[i1]) - self.Y[i2] * self.kernel( self.X[i2], self.X[i2]) * (alpha2_new - self.alpha[i2]) + self.b if 0 < alpha1_new < self.C: b_new = b1_new elif 0 < alpha2_new < self.C: b_new = b2_new else: # 选择中点 b_new = (b1_new + b2_new) / 2 # 更新参数 self.alpha[i1] = alpha1_new self.alpha[i2] = alpha2_new self.b = b_new self.E[i1] = self._E(i1) self.E[i2] = self._E(i2) return 'train done!' def predict(self, data): r = self.b for i in range(self.m): r += self.alpha[i] * self.Y[i] * self.kernel(data, self.X[i]) return 1 if r > 0 else -1 def score(self, X_test, y_test): right_count = 0 for i in range(len(X_test)): result = self.predict(X_test[i]) if result == y_test[i]: right_count += 1 return right_count / len(X_test) def _weight(self): # linear model yx = self.Y.reshape(-1, 1) * self.X self.w = np.dot(yx.T, self.alpha) return self.w ``` ```python from sklearn.model_selection import train_test_split svm = SVM(max_iter=200) svm.fit(np.array(X_train), np.array(y_train)) svm.score(X_test, y_test) ``` 0.55 感觉比sklearn的默认状态要弱很多。。
section \<open> Extension and Restriction \<close> theory Extension imports Substitutions begin subsection \<open> Expressions \<close> syntax "_aext" :: "logic \<Rightarrow> svid \<Rightarrow> logic" (infixl "\<up>" 80) "_ares" :: "logic \<Rightarrow> svid \<Rightarrow> logic" (infixl "\<down>" 80) "_pre" :: "logic \<Rightarrow> logic" ("_\<^sup><" [999] 1000) "_post" :: "logic \<Rightarrow> logic" ("_\<^sup>>" [999] 1000) "_drop_pre" :: "logic \<Rightarrow> logic" ("_\<^sub><" [999] 1000) "_drop_post" :: "logic \<Rightarrow> logic" ("_\<^sub>>" [999] 1000) translations "_aext P a" == "CONST aext P a" "_ares P a" == "CONST ares P a" "_pre P" == "_aext (P)\<^sub>e fst\<^sub>L" "_post P" == "_aext (P)\<^sub>e snd\<^sub>L" "_drop_pre P" == "_ares (P)\<^sub>e fst\<^sub>L" "_drop_post P" == "_ares (P)\<^sub>e snd\<^sub>L" expr_constructor aext expr_constructor ares named_theorems alpha lemma aext_var [alpha]: "($x)\<^sub>e \<up> a = ($a:x)\<^sub>e" by (simp add: expr_defs lens_defs) lemma ares_aext [alpha]: "weak_lens a \<Longrightarrow> P \<up> a \<down> a = P" by (simp add: expr_defs) lemma aext_ares [alpha]: "\<lbrakk> mwb_lens a; (- $a) \<sharp> P \<rbrakk> \<Longrightarrow> P \<down> a \<up> a = P" unfolding unrest_compl_lens by (auto simp add: expr_defs fun_eq_iff lens_create_def) lemma expr_pre [simp]: "e\<^sup>< (s\<^sub>1, s\<^sub>2) = (e)\<^sub>e s\<^sub>1" by (simp add: subst_ext_def subst_app_def) lemma expr_post [simp]: "e\<^sup>> (s\<^sub>1, s\<^sub>2) = (@e)\<^sub>e s\<^sub>2" by (simp add: subst_ext_def subst_app_def) lemma unrest_aext_expr_lens [unrest]: "\<lbrakk> mwb_lens x; x \<bowtie> a \<rbrakk> \<Longrightarrow> $x \<sharp> (P \<up> a)" by (expr_simp add: lens_indep.lens_put_irr2) subsection \<open> Substitutions \<close> definition subst_aext :: "'a subst \<Rightarrow> ('a \<Longrightarrow> 'b) \<Rightarrow> 'b subst" where [expr_defs]: "subst_aext \<sigma> x = (\<lambda> s. put\<^bsub>x\<^esub> s (\<sigma> (get\<^bsub>x\<^esub> s)))" definition subst_ares :: "'b subst \<Rightarrow> ('a \<Longrightarrow> 'b) \<Rightarrow> 'a subst" where [expr_defs]: "subst_ares \<sigma> x = (\<lambda> s. get\<^bsub>x\<^esub> (\<sigma> (create\<^bsub>x\<^esub> s)))" syntax "_subst_aext" :: "logic \<Rightarrow> svid \<Rightarrow> logic" (infixl "\<up>\<^sub>s" 80) "_subst_ares" :: "logic \<Rightarrow> svid \<Rightarrow> logic" (infixl "\<down>\<^sub>s" 80) translations "_subst_aext P a" == "CONST subst_aext P a" "_subst_ares P a" == "CONST subst_ares P a" lemma subst_id_ext [usubst]: "vwb_lens x \<Longrightarrow> [\<leadsto>] \<up>\<^sub>s x = [\<leadsto>]" by expr_auto lemma upd_subst_ext [alpha]: "vwb_lens x \<Longrightarrow> \<sigma>(y \<leadsto> e) \<up>\<^sub>s x = (\<sigma> \<up>\<^sub>s x)(x:y \<leadsto> e \<up> x)" by expr_auto lemma apply_subst_ext [alpha]: "vwb_lens x \<Longrightarrow> (\<sigma> \<dagger> e) \<up> x = (\<sigma> \<up>\<^sub>s x) \<dagger> (e \<up> x)" by (expr_auto) lemma subst_aext_comp [usubst]: "vwb_lens a \<Longrightarrow> (\<sigma> \<up>\<^sub>s a) \<circ>\<^sub>s (\<rho> \<up>\<^sub>s a) = (\<sigma> \<circ>\<^sub>s \<rho>) \<up>\<^sub>s a" by expr_auto end
We are able to offer an alternative to the traditional wedding cake and can help make your special day unique with our beautiful range of wedding cupcakes. You can either choose from one of our most popular combinations or customise your own selection to match your chosen theme or colour scheme. Can't see what you're looking for? Click here to view our full range of delicious handcrafted Cupcakes!
using Test, Unitful, Plots using Unitful: m, s, cm, DimensionError using UnitfulRecipes # Some helper functions to access the subplot labels and the series inside each test plot xguide(plt, idx=length(plt.subplots)) = plt.subplots[idx].attr[:xaxis].plotattributes[:guide] yguide(plt, idx=length(plt.subplots)) = plt.subplots[idx].attr[:yaxis].plotattributes[:guide] zguide(plt, idx=length(plt.subplots)) = plt.subplots[idx].attr[:zaxis].plotattributes[:guide] xseries(plt, idx=length(plt.series_list)) = plt.series_list[idx].plotattributes[:x] yseries(plt, idx=length(plt.series_list)) = plt.series_list[idx].plotattributes[:y] zseries(plt, idx=length(plt.series_list)) = plt.series_list[idx].plotattributes[:z] @testset "plot(y)" begin y = rand(3)m @testset "no keyword argument" begin @test yguide(plot(y)) == "m" @test yseries(plot(y)) ≈ ustrip.(y) end @testset "ylabel" begin @test yguide(plot(y, ylabel="hello")) == "hello (m)" @test yguide(plot(y, ylabel=P"hello")) == "hello" @test yguide(plot(y, ylabel="")) == "" end @testset "yunit" begin @test yguide(plot(y, yunit=cm)) == "cm" @test yseries(plot(y, yunit=cm)) ≈ ustrip.(cm, y) end @testset "ylims" begin # Using all(lims .≈ lims) because of uncontrolled type conversions? @test all(ylims(plot(y, ylims=(-1,3))) .≈ (-1,3)) @test all(ylims(plot(y, ylims=(-1m,3m))) .≈ (-1,3)) @test all(ylims(plot(y, ylims=(-100cm,300cm))) .≈ (-1,3)) @test all(ylims(plot(y, ylims=(-100cm,3m))) .≈ (-1,3)) end @testset "keyword combinations" begin @test yguide(plot(y, yunit=cm, ylabel="hello")) == "hello (cm)" @test yseries(plot(y, yunit=cm, ylabel="hello")) ≈ ustrip.(cm, y) @test all(ylims(plot(y, yunit=cm, ylims=(-1,3))) .≈ (-1,3)) @test all(ylims(plot(y, yunit=cm, ylims=(-1,3))) .≈ (-1,3)) @test all(ylims(plot(y, yunit=cm, ylims=(-100cm,300cm))) .≈ (-100,300)) @test all(ylims(plot(y, yunit=cm, ylims=(-100cm,3m))) .≈ (-100,300)) end end @testset "plot(x,y)" begin x, y = randn(3)m, randn(3)s @testset "no keyword argument" begin @test xguide(plot(x,y)) == "m" @test xseries(plot(x,y)) ≈ ustrip.(x) @test yguide(plot(x,y)) == "s" @test yseries(plot(x,y)) ≈ ustrip.(y) end @testset "labels" begin @test xguide(plot(x, y, xlabel= "hello")) == "hello (m)" @test xguide(plot(x, y, xlabel=P"hello")) == "hello" @test yguide(plot(x, y, ylabel= "hello")) == "hello (s)" @test yguide(plot(x, y, ylabel=P"hello")) == "hello" @test xguide(plot(x, y, xlabel= "hello", ylabel= "hello")) == "hello (m)" @test xguide(plot(x, y, xlabel=P"hello", ylabel=P"hello")) == "hello" @test yguide(plot(x, y, xlabel= "hello", ylabel= "hello")) == "hello (s)" @test yguide(plot(x, y, xlabel=P"hello", ylabel=P"hello")) == "hello" end end @testset "With functions" begin x, y = randn(3), randn(3) @testset "plot(f, x) / plot(x, f)" begin f(x) = x^2 @test plot( f, x*m) isa Plots.Plot @test plot(x*m, f) isa Plots.Plot g(x) = x*m # If the unit comes from the function only then it throws @test_throws DimensionError plot(x, g) isa Plots.Plot @test_throws DimensionError plot(g, x) isa Plots.Plot end @testset "plot(x, y, f)" begin f(x,y) = x*y @test plot(x*m, y*s, f) isa Plots.Plot @test plot(x*m, y, f) isa Plots.Plot @test plot( x, y*s, f) isa Plots.Plot g(x,y) = x*y*m # If the unit comes from the function only then it throws @test_throws DimensionError plot(x, y, g) isa Plots.Plot end end @testset "Moar plots" begin @testset "data as $dtype" for dtype in [:Vectors, :Matrices, Symbol("Vectors of vectors")] if dtype == :Vectors x, y, z = randn(10), randn(10), randn(10) elseif dtype == :Matrices x, y, z = randn(10,2), randn(10,2), randn(10,2) else x, y, z = [rand(10), rand(20)], [rand(10), rand(20)], [rand(10), rand(20)] end @testset "One array" begin @test plot(x*m) isa Plots.Plot @test plot(x*m, ylabel="x") isa Plots.Plot @test plot(x*m, ylims=(-1,1)) isa Plots.Plot @test plot(x*m, ylims=(-1,1) .* m) isa Plots.Plot @test plot(x*m, yunit=u"km") isa Plots.Plot end @testset "Two arrays" begin @test plot(x*m, y*s) isa Plots.Plot @test plot(x*m, y*s, xlabel="x") isa Plots.Plot @test plot(x*m, y*s, xlims=(-1,1)) isa Plots.Plot @test plot(x*m, y*s, xlims=(-1,1) .* m) isa Plots.Plot @test plot(x*m, y*s, xunit=u"km") isa Plots.Plot @test plot(x*m, y*s, ylabel="y") isa Plots.Plot @test plot(x*m, y*s, ylims=(-1,1)) isa Plots.Plot @test plot(x*m, y*s, ylims=(-1,1) .* s) isa Plots.Plot @test plot(x*m, y*s, yunit=u"ks") isa Plots.Plot @test scatter(x*m, y*s) isa Plots.Plot if dtype ≠ Symbol("Vectors of vectors") @test scatter(x*m, y*s, zcolor=z*(m/s)) isa Plots.Plot end end @testset "Three arrays" begin @test plot(x*m, y*s, z*(m/s)) isa Plots.Plot @test plot(x*m, y*s, z*(m/s), xlabel="x") isa Plots.Plot @test plot(x*m, y*s, z*(m/s), xlims=(-1,1)) isa Plots.Plot @test plot(x*m, y*s, z*(m/s), xlims=(-1,1) .* m) isa Plots.Plot @test plot(x*m, y*s, z*(m/s), xunit=u"km") isa Plots.Plot @test plot(x*m, y*s, z*(m/s), ylabel="y") isa Plots.Plot @test plot(x*m, y*s, z*(m/s), ylims=(-1,1)) isa Plots.Plot @test plot(x*m, y*s, z*(m/s), ylims=(-1,1) .* s) isa Plots.Plot @test plot(x*m, y*s, z*(m/s), yunit=u"ks") isa Plots.Plot @test plot(x*m, y*s, z*(m/s), zlabel="z") isa Plots.Plot @test plot(x*m, y*s, z*(m/s), zlims=(-1,1)) isa Plots.Plot @test plot(x*m, y*s, z*(m/s), zlims=(-1,1) .* (m/s)) isa Plots.Plot @test plot(x*m, y*s, z*(m/s), zunit=u"km/hr") isa Plots.Plot @test scatter(x*m, y*s, z*(m/s)) isa Plots.Plot end @testset "Unitful/unitless combinations" begin mystr(x::Array{<:Quantity}) = "Q" mystr(x::Array) = "A" @testset "plot($(mystr(xs)), $(mystr(ys)))" for xs in [x, x*m], ys in [y, y*s] @test plot(xs, ys) isa Plots.Plot end @testset "plot($(mystr(xs)), $(mystr(ys)), $(mystr(zs)))" for xs in [x, x*m], ys in [y, y*s], zs in [z, z*(m/s)] @test plot(xs, ys, zs) isa Plots.Plot end end end @testset "scatter(x::$(us[1]), y::$(us[2]))" for us in collect(Iterators.product(fill([1, u"m", u"s"], 2)...)) x, y = rand(10)*us[1], rand(10)*us[2] @test scatter(x,y) isa Plots.Plot @test scatter(x,y, markersize=x) isa Plots.Plot @test scatter(x,y, line_z=x) isa Plots.Plot end @testset "contour(x::$(us[1]), y::$(us[2]))" for us in collect(Iterators.product(fill([1, u"m", u"s"], 2)...)) x, y = (1:0.01:2)*us[1], (1:0.02:2)*us[2] z = x' ./ y @test contour(x,y,z) isa Plots.Plot @test contourf(x,y,z) isa Plots.Plot end @testset "ProtectedString" begin y = rand(10)*u"m" @test plot(y, label=P"meters") isa Plots.Plot end end @testset "Comparing apples and oranges" begin x1 = rand(10) * u"m" x2 = rand(10) * u"cm" x3 = rand(10) * u"s" plt = plot(x1) plt = plot!(plt, x2) @test yguide(plt) == "m" @test yseries(plt) ≈ ustrip.(x2) / 100 @test_throws DimensionError plot!(plt, x3) # can't place seconds on top of meters! end @testset "Inset subplots" begin x1 = rand(10) * u"m" x2 = rand(10) * u"s" plt = plot(x1) plt = plot!(x2, inset=bbox(0.5, 0.5, 0.3, 0.3), subplot=2) @test yguide(plt,1) == "m" @test yguide(plt,2) == "s" end
State Before: R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p q : R[X] hp : IsPrimitive p hq : q ≠ 0 ⊢ p ∣ primPart q ↔ p ∣ q State After: R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p q : R[X] hp : IsPrimitive p hq : q ≠ 0 h : p ∣ q ⊢ p ∣ primPart q Tactic: refine' ⟨fun h => h.trans (Dvd.intro_left _ q.eq_C_content_mul_primPart.symm), fun h => _⟩ State Before: R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p q : R[X] hp : IsPrimitive p hq : q ≠ 0 h : p ∣ q ⊢ p ∣ primPart q State After: case intro R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p : R[X] hp : IsPrimitive p r : R[X] hq : p * r ≠ 0 ⊢ p ∣ primPart (p * r) Tactic: rcases h with ⟨r, rfl⟩ State Before: case intro R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p : R[X] hp : IsPrimitive p r : R[X] hq : p * r ≠ 0 ⊢ p ∣ primPart (p * r) State After: case intro R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p : R[X] hp : IsPrimitive p r : R[X] hq : p * r ≠ 0 ⊢ p * ?m.597922 = primPart (p * r) R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p : R[X] hp : IsPrimitive p r : R[X] hq : p * r ≠ 0 ⊢ R[X] Tactic: apply Dvd.intro _ State Before: case intro R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p : R[X] hp : IsPrimitive p r : R[X] hq : p * r ≠ 0 ⊢ p * ?m.597922 = primPart (p * r) R : Type u_1 inst✝² : CommRing R inst✝¹ : IsDomain R inst✝ : NormalizedGCDMonoid R p : R[X] hp : IsPrimitive p r : R[X] hq : p * r ≠ 0 ⊢ R[X] State After: no goals Tactic: rw [primPart_mul hq, hp.primPart_eq]
/****************************************************************************** ** ** Copyright (C) 2009-2011 Kyle Lutz <[email protected]> ** All rights reserved. ** ** This file is a part of the chemkit project. For more information ** see <http://www.chemkit.org>. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: ** ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. ** * Neither the name of the chemkit project nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ** ******************************************************************************/ #include "inchitest.h" #include <boost/range/algorithm.hpp> #include <chemkit/ring.h> #include <chemkit/chemkit.h> #include <chemkit/molecule.h> #include <chemkit/lineformat.h> #include <chemkit/moleculefileformat.h> void InchiTest::initTestCase() { // verify that the inchi plugin registered itself correctly QVERIFY(boost::count(chemkit::LineFormat::formats(), "inchi") == 1); QVERIFY(boost::count(chemkit::LineFormat::formats(), "inchikey") == 1); QVERIFY(boost::count(chemkit::MoleculeFileFormat::formats(), "inchi") == 1); } void InchiTest::read() { chemkit::LineFormat *inchi = chemkit::LineFormat::create("inchi"); QVERIFY(inchi != 0); // empty chemkit::Molecule *empty = inchi->read(""); QVERIFY(empty == 0); // methane chemkit::Molecule *methane = inchi->read("InChI=1S/CH4/h1H4"); QVERIFY(methane != 0); QCOMPARE(methane->atomCount(), size_t(5)); QCOMPARE(methane->bondCount(), size_t(4)); QCOMPARE(methane->formula(), std::string("CH4")); delete methane; // ethanol chemkit::Molecule *ethanol = inchi->read("InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3"); QVERIFY(ethanol != 0); QCOMPARE(ethanol->atomCount(), size_t(9)); QCOMPARE(ethanol->bondCount(), size_t(8)); QCOMPARE(ethanol->formula(), std::string("C2H6O")); delete ethanol; // benzene chemkit::Molecule *benzene = inchi->read("InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H"); QVERIFY(benzene != 0); QCOMPARE(benzene->atomCount(), size_t(12)); QCOMPARE(benzene->bondCount(), size_t(12)); QCOMPARE(benzene->formula(), std::string("C6H6")); QCOMPARE(benzene->ringCount(), size_t(1)); chemkit::Ring *benzeneRing = benzene->rings()[0]; QCOMPARE(benzeneRing->isAromatic(), true); delete benzene; delete inchi; } void InchiTest::write() { chemkit::LineFormat *inchi = chemkit::LineFormat::create("inchi"); QVERIFY(inchi != 0); chemkit::LineFormat *inchikey = chemkit::LineFormat::create("inchikey"); QVERIFY(inchikey != 0); // empty molecule chemkit::Molecule empty; QCOMPARE(inchi->write(&empty), std::string("")); // methane molecule chemkit::Molecule methane; chemkit::Atom *methane_c1 = methane.addAtom("C"); for(int i = 0; i < 4; i++){ chemkit::Atom *h = methane.addAtom("H"); methane.addBond(methane_c1, h); } QCOMPARE(methane.formula(), std::string("CH4")); QCOMPARE(inchi->write(&methane), std::string("InChI=1S/CH4/h1H4")); QCOMPARE(inchikey->write(&methane), std::string("VNWKTOKETHGBQD-UHFFFAOYSA-N")); // ethanol chemkit::Molecule ethanol; chemkit::Atom *ethanol_c1 = ethanol.addAtom("C"); chemkit::Atom *ethanol_c2 = ethanol.addAtom("C"); chemkit::Atom *ethanol_o1 = ethanol.addAtom("O"); ethanol.addBond(ethanol_c1, ethanol_c2); ethanol.addBond(ethanol_c2, ethanol_o1); QCOMPARE(inchi->write(&ethanol), std::string("InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3")); QCOMPARE(inchikey->write(&ethanol), std::string("LFQSCWFLJHTTHZ-UHFFFAOYSA-N")); // benzene chemkit::Molecule benzene; chemkit::Atom *benzene_c1 = benzene.addAtom("C"); chemkit::Atom *benzene_c2 = benzene.addAtom("C"); chemkit::Atom *benzene_c3 = benzene.addAtom("C"); chemkit::Atom *benzene_c4 = benzene.addAtom("C"); chemkit::Atom *benzene_c5 = benzene.addAtom("C"); chemkit::Atom *benzene_c6 = benzene.addAtom("C"); benzene.addBond(benzene_c1, benzene_c2, 1); benzene.addBond(benzene_c2, benzene_c3, 2); benzene.addBond(benzene_c3, benzene_c4, 1); benzene.addBond(benzene_c4, benzene_c5, 2); benzene.addBond(benzene_c5, benzene_c6, 1); benzene.addBond(benzene_c6, benzene_c1, 2); QCOMPARE(inchi->write(&benzene), std::string("InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H")); QCOMPARE(inchikey->write(&benzene), std::string("UHOVQNZJYSORNB-UHFFFAOYSA-N")); delete inchi; delete inchikey; } void InchiTest::stereochemistry() { chemkit::LineFormat *inchi = chemkit::LineFormat::create("inchi"); QVERIFY(inchi != 0); // by default stereochemistry is on QCOMPARE(inchi->option("stereochemistry").toBool(), true); // set to false inchi->setOption("stereochemistry", false); QCOMPARE(inchi->option("stereochemistry").toBool(), false); // build chiral molecule chemkit::Molecule bromochlorofluoromethane; chemkit::Atom *C1 = bromochlorofluoromethane.addAtom("C"); chemkit::Atom *Br2 = bromochlorofluoromethane.addAtom("Br"); chemkit::Atom *Cl3 = bromochlorofluoromethane.addAtom("Cl"); chemkit::Atom *F4 = bromochlorofluoromethane.addAtom("F"); chemkit::Atom *H5 = bromochlorofluoromethane.addAtom("H"); bromochlorofluoromethane.addBond(C1, Br2); bromochlorofluoromethane.addBond(C1, Cl3); bromochlorofluoromethane.addBond(C1, F4); bromochlorofluoromethane.addBond(C1, H5); QCOMPARE(inchi->write(&bromochlorofluoromethane), std::string("InChI=1S/CHBrClF/c2-1(3)4/h1H")); // set stererochemistry to true inchi->setOption("stereochemistry", true); QCOMPARE(inchi->option("stereochemistry").toBool(), true); C1->setChirality(chemkit::Stereochemistry::R); QCOMPARE(inchi->write(&bromochlorofluoromethane), std::string("InChI=1S/CHBrClF/c2-1(3)4/h1H/t1-/m1/s1")); C1->setChirality(chemkit::Stereochemistry::S); QCOMPARE(inchi->write(&bromochlorofluoromethane), std::string("InChI=1S/CHBrClF/c2-1(3)4/h1H/t1-/m0/s1")); C1->setChirality(chemkit::Stereochemistry::None); QCOMPARE(inchi->write(&bromochlorofluoromethane), std::string("InChI=1S/CHBrClF/c2-1(3)4/h1H")); // set stereochemistry to off inchi->setOption("stereochemistry", false); C1->setChirality(chemkit::Stereochemistry::R); QCOMPARE(inchi->write(&bromochlorofluoromethane), std::string("InChI=1S/CHBrClF/c2-1(3)4/h1H")); delete inchi; } void InchiTest::addHydrogens() { chemkit::LineFormat *inchi = chemkit::LineFormat::create("inchi"); QVERIFY(inchi != 0); // by default add-implicit-hydrogens is true QCOMPARE(inchi->option("add-implicit-hydrogens").toBool(), true); // set to false inchi->setOption("add-implicit-hydrogens", false); QCOMPARE(inchi->option("add-implicit-hydrogens").toBool(), false); // read octane molecule with add-implicit-hydrogens enabled chemkit::Molecule *octane; inchi->setOption("add-implicit-hydrogens", true); octane = inchi->read("InChI=1/C8H18/c1-3-5-7-8-6-4-2/h3-8H2,1-2H3"); QVERIFY(octane != 0); QCOMPARE(octane->formula(), std::string("C8H18")); delete octane; // read octane molecule with add-implicit-hydrogens disabled inchi->setOption("add-implicit-hydrogens", false); octane = inchi->read("InChI=1/C8H18/c1-3-5-7-8-6-4-2/h3-8H2,1-2H3"); QVERIFY(octane != 0); QCOMPARE(octane->formula(), std::string("C8")); delete octane; } void InchiTest::readWrite_data() { QTest::addColumn<QString>("inchiString"); QTest::newRow("ethanol") << "InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3"; QTest::newRow("acetone") << "InChI=1S/C3H6O/c1-3(2)4/h1-2H3"; QTest::newRow("phenol") << "InChI=1S/C6H6O/c7-6-4-2-1-3-5-6/h1-5,7H"; QTest::newRow("caffeine") << "InChI=1S/C8H10N4O2/c1-10-4-9-6-5(10)7(13)12(3)8(14)11(6)2/h4H,1-3H3"; QTest::newRow("diazepam") << "InChI=1S/C16H13ClN2O/c1-19-14-8-7-12(17)9-13(14)16(18-10-15(19)20)11-5-3-2-4-6-11/h2-9H,10H2,1H3"; } void InchiTest::readWrite() { QFETCH(QString, inchiString); QByteArray inchi = inchiString.toAscii(); chemkit::Molecule molecule(inchi.constData(), "inchi"); QVERIFY(!molecule.isEmpty()); QCOMPARE(molecule.formula("inchi").c_str(), inchi.constData()); } QTEST_APPLESS_MAIN(InchiTest)
// rand.h #ifndef RAND_H #define RAND_H #include <gsl/gsl_rng.h> #include <gsl/gsl_randist.h> #define URNG generator class generator{ const gsl_rng_type * T; public: gsl_rng * r; generator(); ~generator(); void seed(unsigned long int s); }; #include "types.h" class r_lognorm{ double zeta; double sigma; public: r_lognorm(REAL mean,REAL sigma); ~r_lognorm(); REAL operator()(URNG& g); }; REAL lognorm_func(URNG& g,REAL mean,REAL sig); class r_hypgeo{ unsigned int n1; unsigned int n2; unsigned int t; public: r_hypgeo(unsigned int population1,unsigned int population2,unsigned int samples); ~r_hypgeo(); unsigned int operator()(URNG& g); }; unsigned int hypgeo_func(URNG& g,unsigned int population1,unsigned int population2,unsigned int samples); class r_uni{ double a; double b; public: r_uni(REAL min,REAL max); ~r_uni(); REAL operator()(URNG& g); }; REAL unif_func(URNG& g,REAL min,REAL max); REAL exp_func(URNG& g,REAL mu); int ber_func(URNG& g ,REAL p); #endif
module Test interface Foo a where bar : a -> {auto ok: ()} -> a foo : Void -> {auto ok: ()} -> Void foo = ?foo_hole baz : a -> b -> c -> {auto x : a} -> a baz {} = x
[STATEMENT] lemma Ord_trans: "\<lbrakk> i\<^bold>\<in>j; j\<^bold>\<in>k; Ord(k) \<rbrakk> \<Longrightarrow> i\<^bold>\<in>k" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>i \<^bold>\<in> j; j \<^bold>\<in> k; Ord k\<rbrakk> \<Longrightarrow> i \<^bold>\<in> k [PROOF STEP] by (blast dest: OrdmemD)
# Velocity and Acceleration of a point of a rigid body > Renato Naville Watanabe, Marcos Duarte > [Laboratory of Biomechanics and Motor Control](http://pesquisa.ufabc.edu.br/bmclab) > Federal University of ABC, Brazil This notebook shows the expressions of the velocity and acceleration of a point on rigid body, given the angular velocity of the body. ## Frame of reference attached to a body The concept of reference frame in Biomechanics and motor control is very important and central to the understanding of human motion. For example, do we see, plan and control the movement of our hand with respect to reference frames within our body or in the environment we move? Or a combination of both? The figure below, although derived for a robotic system, illustrates well the concept that we might have to deal with multiple coordinate systems. <div class='center-align'><figure><figcaption><center><i>Figure. Multiple coordinate systems for use in robots (figure from Corke (2017)).</i></center></figcaption></figure></div> For three-dimensional motion analysis in Biomechanics, we may use several different references frames for convenience and refer to them as global, laboratory, local, anatomical, or technical reference frames or coordinate systems (we will study this later). There has been proposed different standardizations on how to define frame of references for the main segments and joints of the human body. For instance, the International Society of Biomechanics has a [page listing standardization proposals](https://isbweb.org/activities/standards) by its standardization committee and subcommittees: ## Position of a point on a rigid body The description of the position of a point P of a rotating rigid body is given by: <span class="notranslate"> \begin{equation} {\bf\vec{r}_{P/O}} = x_{P/O}^*{\bf\hat{i}'} + y_{P/O}^*{\bf\hat{j}'} \end{equation} </span> where $x_{P/O}^*$ and $y_{P/O}^*$ are the coordinates of the point P position at a reference state with the versors described as: <span class="notranslate"> \begin{equation} {\bf\hat{i}'} = \cos(\theta){\bf\hat{i}}+\sin(\theta){\bf\hat{j}} \end{equation} </span> <span class="notranslate"> \begin{equation} {\bf\hat{j}'} = -\sin(\theta){\bf\hat{i}}+\cos(\theta){\bf\hat{j}} \end{equation} </span> Note that the vector ${\bf\vec{r}_{P/O}}$ has always the same description for any point P of the rigid body when described as a linear combination of <span class="notranslate">${\bf\hat{i}'}$</span> and <span class="notranslate">${\bf\hat{j}'}$</span>. ## Translation of a rigid body Let's consider now the case in which, besides a rotation, a translation of the body happens. This situation is represented in the figure below. In this case, the position of the point P is given by: <span class="notranslate"> \begin{equation} {\bf\vec{r}_{P/O}} = {\bf\vec{r}_{A/O}}+{\bf\vec{r}_{P/A}}= {\bf\vec{r}_{A/O}}+x_{P/A}^*{\bf\hat{i}'} + y_{P/A}^*{\bf\hat{j}'} \end{equation} </span> ## Angular velocity of a body The magnitude of the angular velocity of a rigid body rotating on a plane is defined as: <span class="notranslate"> \begin{equation} \omega = \frac{d\theta}{dt} \end{equation} </span> Usually, it is defined an angular velocity vector perpendicular to the plane where the rotation occurs (in this case the x-y plane) and with magnitude $\omega$: <span class="notranslate"> \begin{equation} \vec{\bf{\omega}} = \omega\hat{\bf{k}} \end{equation} </span> ## Velocity of a point with no translation First we will consider the situation with no translation. The velocity of the point P is given by: <span class="notranslate"> \begin{equation} {\bf\vec{v}_{P/O}} = \frac{d{\bf\vec{r}_{P/O}}}{dt} = \frac{d(x_{P/O}^*{\bf\hat{i}'} + y_{P/O}^*{\bf\hat{j}'})}{dt} \end{equation} </span> To continue this deduction, we have to find the expression of the derivatives of <span class="notranslate"> ${\bf\hat{i}'}$</span> and <span class="notranslate">${\bf\hat{j}'}$</span>. This is very similar to the derivative expressions of ${\bf\hat{e_R}}$ and ${\bf\hat{e_\theta}}$ of [polar basis](http://nbviewer.jupyter.org/github/BMClab/bmc/blob/master/notebooks/PolarBasis.ipynb). <span class="notranslate"> \begin{equation} \frac{d{\bf\hat{i}'}}{dt} = -\dot{\theta}\sin(\theta){\bf\hat{i}}+\dot{\theta}\cos(\theta){\bf\hat{j}} = \dot{\theta}{\bf\hat{j}'} \end{equation} </span> <span class="notranslate"> \begin{equation} \frac{d{\bf\hat{j}'}}{dt} = -\dot{\theta}\cos(\theta){\bf\hat{i}}-\dot{\theta}\sin(\theta){\bf\hat{j}} = -\dot{\theta}{\bf\hat{i}'} \end{equation} </span> Another way to represent the expressions above is by using the vector form to express the angular velocity $\dot{\theta}$. It is usual to represent the angular velocity as a vector in the direction ${\bf\hat{k}}$: ${\bf\vec{\omega}} = \dot{\theta}{\bf\hat{k}} = \omega{\bf\hat{k}}$. Using this definition of the angular velocity, we can write the above expressions as: <span class="notranslate"> \begin{equation} \frac{d{\bf\hat{i}'}}{dt} = \dot{\theta}{\bf\hat{j}'} = \dot{\theta} {\bf\hat{k}}\times {\bf\hat{i}'} = {\bf\vec{\omega}} \times {\bf\hat{i}'} \end{equation} </span> <span class="notranslate"> \begin{equation} \frac{d{\bf\hat{j}'}}{dt} = -\dot{\theta}{\bf\hat{i}'} = \dot{\theta} {\bf\hat{k}}\times {\bf\hat{j}'} ={\bf\vec{\omega}} \times {\bf\hat{j}'} \end{equation} </span> So, the velocity of the point P in the situation of no translation is: <span class="notranslate"> \begin{equation} {\bf\vec{v}_{P/O}} = \frac{d(x_{P/O}^*{\bf\hat{i}'} + y_{P/O}^*{\bf\hat{j}'})}{dt} = x_{P/O}^*\frac{d{\bf\hat{i}'}}{dt} + y_{P/O}^*\frac{d{\bf\hat{j}'}}{dt}=x_{P/O}^*{\bf\vec{\omega}} \times {\bf\hat{i}'} + y_{P/O}^*{\bf\vec{\omega}} \times {\bf\hat{j}'} = {\bf\vec{\omega}} \times \left(x_{P/O}^*{\bf\hat{i}'}\right) + {\bf\vec{\omega}} \times \left(y_{P/O}^*{\bf\hat{j}'}\right) ={\bf\vec{\omega}} \times \left(x_{P/O}^*{\bf\hat{i}'}+y_{P/O}^*{\bf\hat{j}'}\right) \end{equation} </span> <span class="notranslate"> \begin{equation} {\bf\vec{v}_{P/O}} = {\bf\vec{\omega}} \times {\bf{\vec{r}_{P/O}}} \end{equation} </span> This expression shows that the velocity vector of any point of a rigid body is orthogonal to the vector linking the point O and the point P. It is worth to note that despite the above expression was deduced for a planar movement, the expression above is general, including three dimensional movements. ## Relative velocity of a point on a rigid body to another point To compute the velocity of a point on a rigid body that is translating, we need to find the expression of the velocity of a point (P) in relation to another point on the body (A). So: <span class="notranslate"> \begin{equation} {\bf\vec{v}_{P/A}} = {\bf\vec{v}_{P/O}}-{\bf\vec{v}_{A/O}} = {\bf\vec{\omega}} \times {\bf{\vec{r}_{P/O}}} - {\bf\vec{\omega}} \times {\bf{\vec{r}_{A/O}}} = {\bf\vec{\omega}} \times ({\bf{\vec{r}_{P/O}}}-{\bf{\vec{r}_{A/O}}}) = {\bf\vec{\omega}} \times {\bf{\vec{r}_{P/A}}} \end{equation} </span> ## Velocity of a point on rigid body translating The velocity of a point on a rigid body that is translating is given by: <span class="notranslate"> \begin{equation} {\bf\vec{v}_{P/O}} = \frac{d{\bf\vec{r}_{P/O}}}{dt} = \frac{d({\bf\vec{r}_{A/O}}+x_{P/A}^*{\bf\hat{i}'} + y_{P/A}^*{\bf\hat{j}'})}{dt} = \frac{d{\bf\vec{r}_{A/O}}}{dt}+\frac{d(x_{P/A}^*{\bf\hat{i}'} + y_{P/A}^*{\bf\hat{j}'})}{dt} = {\bf\vec{v}_{A/O}} + {\bf\vec{\omega}} \times {\bf{\vec{r}_{P/A}}} \end{equation} </span> Below is an example of a body rotating with the angular velocity of $\omega = \pi/10$ rad/s and translating at the velocity of <span class="notranslate"> ${\bf\vec{v}} = 0.7 {\bf\hat{i}} + 0.5 {\bf\hat{j}}$ m/s</span>. The red arrow indicates the velocity of the geometric center of the body and the blue arrow indicates the velocity of the lower point of the body ```python import numpy as np import matplotlib.pyplot as plt %matplotlib notebook from matplotlib.animation import FuncAnimation from matplotlib.patches import FancyArrowPatch t = np.linspace(0,13,10) omega = np.pi/10 #[rad/s] voa = np.array([[0.7],[0.5]]) # velocity of center of mass fig = plt.figure() plt.grid() ax = fig.add_axes([0, 0, 1, 1]) ax.axis("on") plt.rcParams['figure.figsize']=5,5 def run(i): ax.clear() theta = omega * t[i] phi = np.linspace(0,2*np.pi,100) B = np.squeeze(np.array([[2*np.cos(phi)],[6*np.sin(phi)]])) Baum = np.vstack((B,np.ones((1,np.shape(B)[1])))) roa = voa * t[i] R = np.array([[np.cos(theta), -np.sin(theta)],[np.sin(theta), np.cos(theta)]]) T = np.vstack((np.hstack((R,roa)), np.array([0,0,1]))) BRot = R@B BRotTr = T@Baum plt.plot(BRotTr[0,:],BRotTr[1,:], roa[0], roa[1],'.') plt.fill(BRotTr[0,:],BRotTr[1,:], 'g') vVoa = FancyArrowPatch(np.array([float(roa[0]), float(roa[1])]), np.array([float(roa[0]+5*voa[0]), float(roa[1]+5*voa[1])]), mutation_scale=20, lw=2, arrowstyle="->", color="r", alpha=1) ax.add_artist(vVoa) element = 75 Vp = np.array([voa[0]-omega*BRot[1,element], voa[1]+omega*BRot[0,element]]) vVP = FancyArrowPatch(np.array([float(BRotTr[0,element]), float(BRotTr[1,element])]), np.array([float(BRotTr[0,element]+5*Vp[0]), float(BRotTr[1,element]+5*Vp[1])]), mutation_scale=20, lw=2, arrowstyle="->", color="b", alpha=1) ax.add_artist(vVP) plt.xlim((-10, 20)) plt.ylim((-10, 20)) ani = FuncAnimation(fig, run, frames = 50,repeat=False, interval =500) plt.show() ``` <IPython.core.display.Javascript object> ## Acceleration of a point on a rigid body The acceleration of a point on a rigid body is obtained by deriving the previous expression: <span class="notranslate"> \begin{equation} {\bf\vec{a}_{P/O}} = {\bf\vec{a}_{A/O}} + \dot{\bf\vec{\omega}} \times {\bf{\vec{r}_{P/A}}} + {\bf\vec{\omega}} \times {\bf{\vec{v}_{P/A}}} = {\bf\vec{a}_{A/O}} + \dot{\bf\vec{\omega}} \times {\bf{\vec{r}_{P/A}}} + {\bf\vec{\omega}} \times ({\bf\vec{\omega}} \times {\bf{\vec{r}_{P/A}}}) = {\bf\vec{a}_{A/O}} + \ddot{\theta}\bf\hat{k} \times {\bf{\vec{r}_{P/A}}} - \dot{\theta}^2{\bf{\vec{r}_{P/A}}} \end{equation} </span> The acceleration has three terms: - ${\bf\vec{a}_{A/O}}$ -- the acceleration of the point O. - $\ddot{\theta}\bf\hat{k} \times {\bf{\vec{r}_{P/A}}}$ -- the acceleration of the point P due to the angular acceleratkion of the body. - $- \dot{\theta}^2{\bf{\vec{r}_{P/A}}}$ -- the acceleration of the point P due to the angular velocity of the body. It is known as centripetal acceleration. Below is an example of a rigid body with an angular acceleration of $\alpha = \pi/150$ rad/s$^2$ and initial angular velocity of $\omega_0 = \pi/100$ rad/s. Consider also that the center of the body accelerates with <span class="notranslate">${\bf\vec{a}} = 0.01{\bf\hat{i}} + 0.05{\bf\hat{j}}$</span>, starting from rest. ```python t = np.linspace(0, 20, 40) alpha = np.pi/150 #[rad/s^2] angular acceleration omega0 = np.pi/100 #[rad/s] angular velocity aoa = np.array([[0.01],[0.05]]) # linear acceleration fig = plt.figure() plt.grid() ax = fig.add_axes([0, 0, 1, 1]) ax.axis("on") plt.rcParams['figure.figsize']=5,5 theta = 0 omega = 0 def run(i): ax.clear() phi = np.linspace(0,2*np.pi,100) B = np.squeeze(np.array([[2*np.cos(phi)],[6*np.sin(phi)]])) Baum = np.vstack((B,np.ones((1,np.shape(B)[1])))) omega = alpha*t[i]+omega0 #[rad/s] angular velocity theta = alpha/2*t[i]**2 + omega0*t[i] # [rad] angle voa = aoa*t[i] # linear velocity roa = aoa/2*t[i]**2 # position of the center of the body R = np.array([[np.cos(theta), -np.sin(theta)],[np.sin(theta), np.cos(theta)]]) T = np.vstack((np.hstack((R,roa)), np.array([0,0,1]))) BRot = R@B BRotTr = T@Baum plt.plot(BRotTr[0,:],BRotTr[1,:], roa[0], roa[1],'.') plt.fill(BRotTr[0,:],BRotTr[1,:],'g') element = 75 ap = np.array([aoa[0] - alpha*BRot[1,element] - omega**2*BRot[0,element], aoa[1] + alpha*BRot[0,element] - omega**2*BRot[1,element]]) vVP = FancyArrowPatch(np.array([float(BRotTr[0,element]), float(BRotTr[1,element])]), np.array([float(BRotTr[0,element]+5*ap[0]), float(BRotTr[1,element]+5*ap[1])]), mutation_scale=20, lw=2, arrowstyle="->", color="b", alpha=1) ax.add_artist(vVP) plt.xlim((-10, 20)) plt.ylim((-10, 20)) ani = FuncAnimation(fig, run, frames=50,repeat=False, interval=500) plt.show() ``` <IPython.core.display.Javascript object> ## Problems 1. Solve the problems 16.2.5, 16.2.10, 16.2.11 and 16.2.20 from [Ruina and Rudra's book](http://ruina.tam.cornell.edu/Book/index.html). 2. Solve the problems 17.1.2, 17.1.8, 17.1.9, 17.1.10, 17.1.11 and 17.1.12 from [Ruina and Rudra's book](http://ruina.tam.cornell.edu/Book/index.html). ## Reference - Ruina A, Rudra P (2019) [Introduction to Statics and Dynamics](http://ruina.tam.cornell.edu/Book/index.html). Oxford University Press. - Corke P (2017) [Robotics, Vision and Control: Fundamental Algorithms in MATLAB](http://www.petercorke.com/RVC/). 2nd ed. Springer-Verlag Berlin.
## SRTM download options for movement data #srtm15p extracts terrestrial topography and marine bathymetry data from: Tozer, B, Sandwell, D. T., Smith, W. H. F., Olson, C., Beale, J. R., & Wessel, P. (2019). Global bathymetry and topography at 15 arc sec: SRTM15+. Earth and Space Science, 6, 1847– 1864. https://doi.org/10.1029/2019EA000658 #srtm90m extracts terrestrial data from: Jarvis A., H.I. Reuter, A. Nelson, E. Guevara, 2008, Hole-filled seamless SRTM data V4, International Centre for Tropical Agriculture (CIAT), available from http://srtm.csi.cgiar.org. #citation: Reuter H.I, A. Nelson, A. Jarvis, 2007, An evaluation of void filling interpolation methods for SRTM data, International Journal of Geographic Information Science, 21:9, 983-1008. library(RCurl) library(raster) srtm15p <- function(x){ bb <- as.vector(extent(x)*1.5) txt <- postForm("https://topex.ucsd.edu/cgi-bin/get_srtm15.cgi", submitButton = "get data", north=bb[4], west=bb[1], east=bb[2], south=bb[3], style = "POST") xyz <- data.frame(matrix(as.numeric(unlist(strsplit(unlist(strsplit(txt, "\n")), "\t"))), ncol=3, byrow=T)) names(xyz) <- c("long", "lat", "alt") coordinates(xyz) <- ~long+lat gridded(xyz) <- TRUE return(raster(xyz)) } srtm90m <- function(x, method="wget", quiet=F){ bb <- as.vector(extent(x)*1.5) xtilellc <- ceiling((bb[1]+180)/5) ytilellc <- 24 - floor((bb[3]+60)/5) xtileurc <- ceiling((bb[2]+180)/5) ytileurc <- 24 - floor((bb[4]+60)/5) combi <- expand.grid(xtilellc:xtileurc, ytilellc:ytileurc) tile <- apply(combi, 1, function(x) paste("srtm_", sprintf("%02d",x[1]), "_" , sprintf("%02d", x[2]), ".zip", sep="")) tileURL <- lapply(tile, function(tn) paste("http://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF/", tn, sep="")) demsDL <- mapply(function(URL, tileName) download.file(URL, paste(tempdir(), tileName, sep="/"), method=method, quiet=quiet), tileURL, tile) unzip(paste(tempdir(), tile, sep="/"), exdir=tempdir()) dems <- lapply(list.files(tempdir(), pattern=".tif", full.names = T), raster) # Merge the tiles into a single raster if(length(dems)>1){ DEM <- do.call("merge", dems)}else{DEM <- dems[[1]]} # Reduce to the extent of the study area DEM <- crop(DEM, bb) return(DEM) } # Example code with plots library(move) library(scales) Dem15Leroy <- srtm15p(leroy) Dem90mLeroy <- srtm90m(leroy, quiet=T) proj4string(Dem15Leroy) <- projection(leroy) proj4string(Dem90mLeroy) <- projection(leroy) slope15 <- terrain(Dem15Leroy, opt='slope') aspect15 <- terrain(Dem15Leroy, opt='aspect') hill15 <- hillShade(slope15, aspect15, 40, 270) slope90m <- terrain(Dem90mLeroy, opt='slope') aspect90m <- terrain(Dem90mLeroy, opt='aspect') hill90m <- hillShade(slope90m, aspect90m, 40, 270) ColRamp <- terrain.colors(512) plot(leroy, type="n", xaxt="n", yaxt="n", ylab=NA, xlab=NA, bty="n") plot(crop(hill15, extent(leroy)*1.1), col=alpha(grey(0:512/519), 1), add=T, legend=FALSE, main='') plot(crop(Dem15Leroy, extent(leroy)*1.1), col=alpha(ColRamp, 0.4), add=T, legend=FALSE) lines(leroy, col=alpha(c("black"), 1), lwd=1.5) lines(leroy, col=alpha(c("white"), 1), lwd=1) lines(leroy, col=alpha(c("purple"), 0.75), lwd=1.25) plot(leroy, type="n", xaxt="n", yaxt="n", ylab=NA, xlab=NA, bty="n") plot(crop(hill90m, extent(leroy)*1.1), col=alpha(grey(0:512/519), 1), add=T, legend=FALSE, main='') plot(crop(Dem90mLeroy, extent(leroy)*1.1), col=alpha(ColRamp, 0.4), add=T, legend=FALSE) lines(leroy, col=alpha(c("black"), 1), lwd=1.5) lines(leroy, col=alpha(c("white"), 1), lwd=1) lines(leroy, col=alpha(c("purple"), 0.66), lwd=1.25)
The limit of the sequence $1/x$ as $x$ approaches infinity is $0$ from the right.
# Valor Presente y Sensibilidad OIS **Definición:** una curva cupón cero es una colección ordenada de plazos y tasas de interés donde cada una de las tasas es una tasa adecuada para traer a valor presente un flujo de caja al plazo que corresponde a la tasa. Consideremos un instrumento financiero cuyo valor depende de una curva cupón cero. Por ejemplo, un swap de tasa de interés. Matemáticamente, esta dependencia se expresa como: $$ V = V\left(z_1,\ldots,z_n;\alpha\right) $$ donde $z_1,\ldots,z_N$ son los valores de las tasas de la curva y $\alpha$ representa un vector de parámetros adicionales (como la tasa de cupón en un bono o un tipo de cambio en un swap de monedas). **Definición:** la cantidad $\Delta_i$ de $V$ respecto a $z_i$ se define como: $$ \Delta_i=\frac{\partial V}{\partial z_i} $$ **Definición:** la sensibilidad de $V$ respecto a un cambio $\delta z_i$ (positivo o negativo) en la tasa $z_i$ se define como: $$ S\left(V,z_i,\delta_i\right)=V\left(z_1,...,z_i+\delta_i,\ldots,z_n\right)-V\left(z_1,\ldots,z_i,\ldots,z_n\right) $$ Cuando se busca conocer la sensibilidad a un cambio $\delta z_i$ en la tasa $z_i$, donde $\delta z_i$ representa una magnitud sin signo, se utiliza la siguiente definición: **Definición:** la sensibilidad de $V$ respecto a un cambio de magnitud $\delta z_i$ en la tasa $z_i$ se define como: $$ \overline{S}\left(V,z_i,\delta_i\right)=\frac{V\left(z_1,\ldots ,z_i+\delta_i,\ldots,z_n\right)-V\left(z_1,\ldots,z_i-\delta_i,...,z_n\right)}{2} $$ En ocasiones, cuando se busca conocer la sensibilidad a un movimiento de magnitud pequeña, resulta conveniente realizar la siguiente aproximación: $$ \overline{S}\left(V,z_i,\delta_i\right)\approx\Delta_i \cdot\delta_i $$ este es el caso, cuando se busca conocer esta sensibilidad para un elevado número de operaciones. Es importante considerar que se puede asegurar que esta aproximación es válida cuando la función $V$ satisface los requerimientos de regularidad necesarios para aplicar el [Teorema de Taylor](https://en.wikipedia.org/wiki/Taylor%27s_theorem). ## Configuración ### Librerías ```python from finrisk import QC_Financial_3 as Qcf from functools import partial from enum import Enum import pandas as pd import my_functions as my ``` ### Variables Globales ```python class BusCal(Enum): NY = 1 SCL = 2 ``` ```python def get_cal(code: BusCal) -> Qcf.BusinessCalendar: """ Retorna un calendario NY o SCL. """ if code == BusCal.NY: cal = Qcf.BusinessCalendar(Qcf.QCDate(1, 1, 2020), 20) for agno in range(2020, 2071): f = Qcf.QCDate(12, 10, agno) if f.week_day() == Qcf.WeekDay.SAT: cal.add_holiday(Qcf.QCDate(14, 10, agno)) elif f.week_day() == Qcf.WeekDay.SUN: cal.add_holiday(Qcf.QCDate(13, 10, agno)) elif f.week_day() == Qcf.WeekDay.MON: cal.add_holiday(Qcf.QCDate(12, 10, agno)) elif f.week_day() == Qcf.WeekDay.TUE: cal.add_holiday(Qcf.QCDate(11, 10, agno)) elif f.week_day() == Qcf.WeekDay.WED: cal.add_holiday(Qcf.QCDate(10, 10, agno)) elif f.week_day() == Qcf.WeekDay.THU: cal.add_holiday(Qcf.QCDate(9, 10, agno)) else: cal.add_holiday(Qcf.QCDate(8, 10, agno)) cal.add_holiday(Qcf.QCDate(15, 2, 2021)) if code == BusCal.SCL: cal = Qcf.BusinessCalendar(Qcf.QCDate(1, 1, 2020), 20) for agno in range(2020, 2071): cal.add_holiday(Qcf.QCDate(1, 1, agno)) cal.add_holiday(Qcf.QCDate(18, 9, agno)) cal.add_holiday(Qcf.QCDate(19, 9, agno)) cal.add_holiday(Qcf.QCDate(25, 12, agno)) return cal ``` ```python get_cal(BusCal.NY) ``` <finrisk.QC_Financial_3.BusinessCalendar at 0x7f88aa515688> ```python frmt = { 'tasa': '{:.6%}', 'df': '{:.6%}', 'valor_tasa': '{:.4%}', 'spread': '{:.4%}', 'nominal': '{:,.0f}', 'interes': '{:,.0f}', 'amortizacion': '{:,.0f}', 'flujo': '{:,.4f}', } ``` ```python class TypeOis(Enum): SOFR = 1 ICP = 2 ``` ```python type_ois_template = { TypeOis.SOFR: { 'currency': Qcf.QCUSD(), 'periodicity': Qcf.Tenor('1Y'), 'stub_period': Qcf.StubPeriod.SHORTFRONT, 'settlement_lag': 0, 'calendar': BusCal.NY, 'bus_adj_rule': Qcf.BusyAdjRules.MODFOLLOW, 'amort_is_cashflow': True, 'fixed_rate': Qcf.QCInterestRate(0.0, Qcf.QCAct360(), Qcf.QCLinearWf()), }, TypeOis.ICP: { 'currency': Qcf.QCCLP(), 'periodicity': Qcf.Tenor('6M'), 'stub_period': Qcf.StubPeriod.SHORTFRONT, 'settlement_lag': 0, 'calendar': BusCal.SCL, 'bus_adj_rule': Qcf.BusyAdjRules.MODFOLLOW, 'amort_is_cashflow': True, 'fixed_rate': Qcf.QCInterestRate(0.0, Qcf.QCAct360(), Qcf.QCLinearWf()), } } ``` ## Construye Curva Cero Cupón Se importa la data de una curva cupón cero construida con cotizaciones SOFR. ```python df_curva = pd.read_excel('data/20201012_built_sofr_zero.xlsx') ``` ```python def get_curve_from_dataframe(yf: Qcf.QCYearFraction, wf: Qcf.QCWealthFactor, df_curva: pd.DataFrame) -> Qcf.ZeroCouponCurve: """ Retorna un objeto Qcf.ZeroCouponCurve. Esta función requiere que `df_curva` tenga una columna de nombre 'plazo' y una columna de nombre 'tasa'. Se usa interpolación lineal en la curva que se retorna. """ plazos = Qcf.long_vec() tasas = Qcf.double_vec() for row in df_curva.itertuples(): plazos.append(row.plazo) tasas.append(row.tasa) curva = Qcf.QCCurve(plazos, tasas) curva = Qcf.QCLinearInterpolator(curva) tipo_tasa = Qcf.QCInterestRate(0.0, yf, wf) curva = Qcf.ZeroCouponCurve(curva, tipo_tasa) return curva ``` ```python df_curva.head().style.format(frmt) ``` <style type="text/css" > </style><table id="T_b260b476_2e7d_11ec_a147_02cba411ec9d" ><thead> <tr> <th class="blank level0" ></th> <th class="col_heading level0 col0" >plazo</th> <th class="col_heading level0 col1" >tasa</th> <th class="col_heading level0 col2" >df</th> </tr></thead><tbody> <tr> <th id="T_b260b476_2e7d_11ec_a147_02cba411ec9dlevel0_row0" class="row_heading level0 row0" >0</th> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow0_col0" class="data row0 col0" >1</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow0_col1" class="data row0 col1" >0.081111%</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow0_col2" class="data row0 col2" >99.999778%</td> </tr> <tr> <th id="T_b260b476_2e7d_11ec_a147_02cba411ec9dlevel0_row1" class="row_heading level0 row1" >1</th> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow1_col0" class="data row1 col0" >7</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow1_col1" class="data row1 col1" >0.084051%</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow1_col2" class="data row1 col2" >99.998388%</td> </tr> <tr> <th id="T_b260b476_2e7d_11ec_a147_02cba411ec9dlevel0_row2" class="row_heading level0 row2" >2</th> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow2_col0" class="data row2 col0" >14</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow2_col1" class="data row2 col1" >0.077967%</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow2_col2" class="data row2 col2" >99.997010%</td> </tr> <tr> <th id="T_b260b476_2e7d_11ec_a147_02cba411ec9dlevel0_row3" class="row_heading level0 row3" >3</th> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow3_col0" class="data row3 col0" >21</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow3_col1" class="data row3 col1" >0.077358%</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow3_col2" class="data row3 col2" >99.995549%</td> </tr> <tr> <th id="T_b260b476_2e7d_11ec_a147_02cba411ec9dlevel0_row4" class="row_heading level0 row4" >4</th> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow4_col0" class="data row4 col0" >33</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow4_col1" class="data row4 col1" >0.078067%</td> <td id="T_b260b476_2e7d_11ec_a147_02cba411ec9drow4_col2" class="data row4 col2" >99.992942%</td> </tr> </tbody></table> ```python zcc = get_curve_from_dataframe(Qcf.QCAct365(),Qcf.QCContinousWf(), df_curva) ``` Algunos métodos del objeto`zcc`. ```python plazo = 900 print(f"Tasa a {plazo} días es igual a {zcc.get_rate_at(plazo):.4%}") print(f"Factor de descuento a {plazo} días es igual a {zcc.get_discount_factor_at(plazo):.6%}") ``` Tasa a 900 días es igual a 0.0652% Factor de descuento a 900 días es igual a 99.839331% ## Valorización ```python def get_ois_using_template( template, type_ois: TypeOis, rp: Qcf.RecPay, notional: float, start_date: Qcf.QCDate, tenor: Qcf.Tenor, fixed_rate_value: float, spread: float, gearing: float ): """ """ template_dict = template[type_ois] meses = tenor.get_years() * 12 + tenor.get_months() end_date = start_date.add_months(meses) template_dict['fixed_rate'].set_value(fixed_rate_value) es_bono = False # Construye la pata fija fixed_rate_leg = Qcf.LegFactory.build_bullet_fixed_rate_leg( rp, start_date, end_date, template_dict['bus_adj_rule'], template_dict['periodicity'], template_dict['stub_period'], get_cal(template_dict['calendar']), template_dict['settlement_lag'], notional, template_dict['amort_is_cashflow'], template_dict['fixed_rate'], template_dict['currency'], es_bono) # Construye la pata ois rp = Qcf.RecPay.PAY if rp == Qcf.RecPay.RECEIVE else Qcf.RecPay.RECEIVE icp_clp_leg = Qcf.LegFactory.build_bullet_icp_clp2_leg( rp, start_date, end_date, template_dict['bus_adj_rule'], template_dict['periodicity'], template_dict['stub_period'], get_cal(template_dict['calendar']), template_dict['settlement_lag'], notional, template_dict['amort_is_cashflow'], spread, gearing, True ) for i in range(icp_clp_leg.size()): cshflw = icp_clp_leg.get_cashflow_at(i) cshflw.set_start_date_icp(1.0) cshflw.set_end_date_icp(1.0) return (fixed_rate_leg, icp_clp_leg) ``` ### Operación Ejemplo ```python op = get_ois_using_template( type_ois_template, TypeOis.SOFR, Qcf.RecPay.RECEIVE, 10000000, Qcf.QCDate(14, 10, 2020), Qcf.Tenor('2Y'), .01, 0.0, 1.0 ) op ``` (<finrisk.QC_Financial_3.Leg at 0x7f88a65a67e8>, <finrisk.QC_Financial_3.Leg at 0x7f88a65a6a58>) #### Digresión: `functools.partial` Supongamos que estoy en una situación en la que sólo quiero construir OIS de *SOFR*. Me gustaría no tener que repetir los argumentos `type_ois_template` y `TypeOis.SOFR` cada vez que llamo la función `get_ois_using_template`. Puedo definir una nueva función de la siguiente forma: ```python get_ois_sofr = partial(get_ois_using_template, type_ois_template, TypeOis.SOFR) ``` Con esta nueva función, `get_ois_sofr`, ahora puedo construir la operación `op` de la siguiente forma: ```python op = get_ois_sofr( Qcf.RecPay.RECEIVE, 10000000, Qcf.QCDate(14, 10, 2020), Qcf.Tenor('5Y'), .01, 0.0, 1.0 ) ``` #### Continuamos (fin digresión ...) ```python my.leg_as_dataframe(op[0], my.TipoPata.FIJA).style.format(frmt) ``` <style type="text/css" > </style><table id="T_2a80305a_2e81_11ec_a147_02cba411ec9d" ><thead> <tr> <th class="blank level0" ></th> <th class="col_heading level0 col0" >fecha_inicial</th> <th class="col_heading level0 col1" >fecha_final</th> <th class="col_heading level0 col2" >fecha_pago</th> <th class="col_heading level0 col3" >nominal</th> <th class="col_heading level0 col4" >amortizacion</th> <th class="col_heading level0 col5" >interes</th> <th class="col_heading level0 col6" >amort_es_flujo</th> <th class="col_heading level0 col7" >flujo</th> <th class="col_heading level0 col8" >moneda</th> <th class="col_heading level0 col9" >valor_tasa</th> <th class="col_heading level0 col10" >tipo_tasa</th> </tr></thead><tbody> <tr> <th id="T_2a80305a_2e81_11ec_a147_02cba411ec9dlevel0_row0" class="row_heading level0 row0" >0</th> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col0" class="data row0 col0" >2020-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col1" class="data row0 col1" >2021-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col2" class="data row0 col2" >2021-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col3" class="data row0 col3" >10,000,000</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col4" class="data row0 col4" >0</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col5" class="data row0 col5" >101,389</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col6" class="data row0 col6" >True</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col7" class="data row0 col7" >101,388.8889</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col8" class="data row0 col8" >USD</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col9" class="data row0 col9" >1.0000%</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow0_col10" class="data row0 col10" >LinAct360</td> </tr> <tr> <th id="T_2a80305a_2e81_11ec_a147_02cba411ec9dlevel0_row1" class="row_heading level0 row1" >1</th> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col0" class="data row1 col0" >2021-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col1" class="data row1 col1" >2022-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col2" class="data row1 col2" >2022-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col3" class="data row1 col3" >10,000,000</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col4" class="data row1 col4" >0</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col5" class="data row1 col5" >101,389</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col6" class="data row1 col6" >True</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col7" class="data row1 col7" >101,388.8889</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col8" class="data row1 col8" >USD</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col9" class="data row1 col9" >1.0000%</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow1_col10" class="data row1 col10" >LinAct360</td> </tr> <tr> <th id="T_2a80305a_2e81_11ec_a147_02cba411ec9dlevel0_row2" class="row_heading level0 row2" >2</th> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col0" class="data row2 col0" >2022-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col1" class="data row2 col1" >2023-10-16</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col2" class="data row2 col2" >2023-10-16</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col3" class="data row2 col3" >10,000,000</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col4" class="data row2 col4" >0</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col5" class="data row2 col5" >101,944</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col6" class="data row2 col6" >True</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col7" class="data row2 col7" >101,944.4444</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col8" class="data row2 col8" >USD</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col9" class="data row2 col9" >1.0000%</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow2_col10" class="data row2 col10" >LinAct360</td> </tr> <tr> <th id="T_2a80305a_2e81_11ec_a147_02cba411ec9dlevel0_row3" class="row_heading level0 row3" >3</th> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col0" class="data row3 col0" >2023-10-16</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col1" class="data row3 col1" >2024-10-15</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col2" class="data row3 col2" >2024-10-15</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col3" class="data row3 col3" >10,000,000</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col4" class="data row3 col4" >0</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col5" class="data row3 col5" >101,389</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col6" class="data row3 col6" >True</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col7" class="data row3 col7" >101,388.8889</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col8" class="data row3 col8" >USD</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col9" class="data row3 col9" >1.0000%</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow3_col10" class="data row3 col10" >LinAct360</td> </tr> <tr> <th id="T_2a80305a_2e81_11ec_a147_02cba411ec9dlevel0_row4" class="row_heading level0 row4" >4</th> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col0" class="data row4 col0" >2024-10-15</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col1" class="data row4 col1" >2025-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col2" class="data row4 col2" >2025-10-14</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col3" class="data row4 col3" >10,000,000</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col4" class="data row4 col4" >10,000,000</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col5" class="data row4 col5" >101,111</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col6" class="data row4 col6" >True</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col7" class="data row4 col7" >10,101,111.1111</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col8" class="data row4 col8" >USD</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col9" class="data row4 col9" >1.0000%</td> <td id="T_2a80305a_2e81_11ec_a147_02cba411ec9drow4_col10" class="data row4 col10" >LinAct360</td> </tr> </tbody></table> ```python my.leg_as_dataframe(op[0], my.TipoPata.FIJA).to_excel('ejemplo_valorizacion.xlsx') ``` ```python my.leg_as_dataframe(op[1], my.TipoPata.ICPCLP).style.format(frmt) ``` <style type="text/css" > </style><table id="T_2a80305b_2e81_11ec_a147_02cba411ec9d" ><thead> <tr> <th class="blank level0" ></th> <th class="col_heading level0 col0" >fecha_inicial</th> <th class="col_heading level0 col1" >fecha_final</th> <th class="col_heading level0 col2" >fecha_pago</th> <th class="col_heading level0 col3" >nominal</th> <th class="col_heading level0 col4" >amortizacion</th> <th class="col_heading level0 col5" >amort_es_flujo</th> <th class="col_heading level0 col6" >flujo</th> <th class="col_heading level0 col7" >moneda</th> <th class="col_heading level0 col8" >icp_inicial</th> <th class="col_heading level0 col9" >icp_final</th> <th class="col_heading level0 col10" >valor_tasa</th> <th class="col_heading level0 col11" >interes</th> <th class="col_heading level0 col12" >spread</th> <th class="col_heading level0 col13" >gearing</th> <th class="col_heading level0 col14" >tipo_tasa</th> </tr></thead><tbody> <tr> <th id="T_2a80305b_2e81_11ec_a147_02cba411ec9dlevel0_row0" class="row_heading level0 row0" >0</th> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col0" class="data row0 col0" >2020-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col1" class="data row0 col1" >2021-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col2" class="data row0 col2" >2021-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col3" class="data row0 col3" >-10,000,000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col4" class="data row0 col4" >0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col5" class="data row0 col5" >True</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col6" class="data row0 col6" >0.0000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col7" class="data row0 col7" >CLP</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col8" class="data row0 col8" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col9" class="data row0 col9" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col10" class="data row0 col10" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col11" class="data row0 col11" >-0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col12" class="data row0 col12" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col13" class="data row0 col13" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow0_col14" class="data row0 col14" >LinAct360</td> </tr> <tr> <th id="T_2a80305b_2e81_11ec_a147_02cba411ec9dlevel0_row1" class="row_heading level0 row1" >1</th> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col0" class="data row1 col0" >2021-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col1" class="data row1 col1" >2022-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col2" class="data row1 col2" >2022-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col3" class="data row1 col3" >-10,000,000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col4" class="data row1 col4" >0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col5" class="data row1 col5" >True</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col6" class="data row1 col6" >0.0000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col7" class="data row1 col7" >CLP</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col8" class="data row1 col8" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col9" class="data row1 col9" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col10" class="data row1 col10" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col11" class="data row1 col11" >-0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col12" class="data row1 col12" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col13" class="data row1 col13" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow1_col14" class="data row1 col14" >LinAct360</td> </tr> <tr> <th id="T_2a80305b_2e81_11ec_a147_02cba411ec9dlevel0_row2" class="row_heading level0 row2" >2</th> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col0" class="data row2 col0" >2022-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col1" class="data row2 col1" >2023-10-16</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col2" class="data row2 col2" >2023-10-16</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col3" class="data row2 col3" >-10,000,000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col4" class="data row2 col4" >0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col5" class="data row2 col5" >True</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col6" class="data row2 col6" >0.0000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col7" class="data row2 col7" >CLP</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col8" class="data row2 col8" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col9" class="data row2 col9" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col10" class="data row2 col10" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col11" class="data row2 col11" >-0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col12" class="data row2 col12" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col13" class="data row2 col13" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow2_col14" class="data row2 col14" >LinAct360</td> </tr> <tr> <th id="T_2a80305b_2e81_11ec_a147_02cba411ec9dlevel0_row3" class="row_heading level0 row3" >3</th> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col0" class="data row3 col0" >2023-10-16</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col1" class="data row3 col1" >2024-10-15</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col2" class="data row3 col2" >2024-10-15</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col3" class="data row3 col3" >-10,000,000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col4" class="data row3 col4" >0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col5" class="data row3 col5" >True</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col6" class="data row3 col6" >0.0000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col7" class="data row3 col7" >CLP</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col8" class="data row3 col8" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col9" class="data row3 col9" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col10" class="data row3 col10" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col11" class="data row3 col11" >-0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col12" class="data row3 col12" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col13" class="data row3 col13" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow3_col14" class="data row3 col14" >LinAct360</td> </tr> <tr> <th id="T_2a80305b_2e81_11ec_a147_02cba411ec9dlevel0_row4" class="row_heading level0 row4" >4</th> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col0" class="data row4 col0" >2024-10-15</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col1" class="data row4 col1" >2025-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col2" class="data row4 col2" >2025-10-14</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col3" class="data row4 col3" >-10,000,000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col4" class="data row4 col4" >-10,000,000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col5" class="data row4 col5" >True</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col6" class="data row4 col6" >-10,000,000.0000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col7" class="data row4 col7" >CLP</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col8" class="data row4 col8" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col9" class="data row4 col9" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col10" class="data row4 col10" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col11" class="data row4 col11" >-0</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col12" class="data row4 col12" >0.0000%</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col13" class="data row4 col13" >1.000000</td> <td id="T_2a80305b_2e81_11ec_a147_02cba411ec9drow4_col14" class="data row4 col14" >LinAct360</td> </tr> </tbody></table> #### Valor Presente Pata Fija ```python vp = Qcf.PresentValue() ``` ```python fecha_val = Qcf.QCDate(14, 10, 2020) ``` ```python vp_fija = vp.pv(fecha_val, op[0], zcc) print(f'El valor presente de la pata fija es: USD {vp_fija:,.4f}') ``` El valor presente de la pata fija es: USD 10,408,804.8068 **Ejercicio:** Replique el valor de la pata fija utilizando los flujos y los factores de descuento que obtiene de la curva `zcc`. ```python # Se dan de alta las fechas finales de ambos cupones fecha1 = Qcf.QCDate(14, 10, 2021) fecha2 = Qcf.QCDate(14, 10, 2022) # O de forma más automática: fecha1 = op[0].get_cashflow_at(0).get_settlement_date() fecha2 = op[0].get_cashflow_at(1).get_settlement_date() # Se calcula el número de días entre la fecha de valorización (fecha_val) y las fechas # finales de ambos cupones. plazo1 = fecha_val.day_diff(fecha1) plazo2 = fecha_val.day_diff(fecha2) # Utilizando la curva zcc se calculan los df a esos plazos df1 = zcc.get_discount_factor_at(plazo1) df2 = zcc.get_discount_factor_at(plazo2) # Se obtienen los flujos totales (interés y amortización) de ambos cupones flujo1 = op[0].get_cashflow_at(0).amount() flujo2 = op[0].get_cashflow_at(1).amount() # Finalmente, se calcula el valor presente como el producto (escalar) entre los df y los flujos. check_vp = df1 * flujo1 + df2 * flujo2 # Se muestra el resultado. print(f'El valor presente a mano es: {check_vp:,.8f}') ``` El valor presente a mano es: 202,591.56249166 #### Valor Presente Pata Flotante ```python fwd = Qcf.ForwardRates() ``` ```python print(f'VP: {vp.pv(fecha_val, op[1], zcc):,.2f}') ``` VP: -9,903,483.66 ```python print(f'{df2 * 10000000:,.2f}') ``` 9,988,654.87 ```python fwd.set_rates_icp_clp_leg(fecha_val, 1.0, op[1], zcc) ``` ```python my.leg_as_dataframe(op[1], my.TipoPata.ICPCLP).style.format(frmt) ``` <style type="text/css" > </style><table id="T_74e14ef4_2e81_11ec_a147_02cba411ec9d" ><thead> <tr> <th class="blank level0" ></th> <th class="col_heading level0 col0" >fecha_inicial</th> <th class="col_heading level0 col1" >fecha_final</th> <th class="col_heading level0 col2" >fecha_pago</th> <th class="col_heading level0 col3" >nominal</th> <th class="col_heading level0 col4" >amortizacion</th> <th class="col_heading level0 col5" >amort_es_flujo</th> <th class="col_heading level0 col6" >flujo</th> <th class="col_heading level0 col7" >moneda</th> <th class="col_heading level0 col8" >icp_inicial</th> <th class="col_heading level0 col9" >icp_final</th> <th class="col_heading level0 col10" >valor_tasa</th> <th class="col_heading level0 col11" >interes</th> <th class="col_heading level0 col12" >spread</th> <th class="col_heading level0 col13" >gearing</th> <th class="col_heading level0 col14" >tipo_tasa</th> </tr></thead><tbody> <tr> <th id="T_74e14ef4_2e81_11ec_a147_02cba411ec9dlevel0_row0" class="row_heading level0 row0" >0</th> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col0" class="data row0 col0" >2020-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col1" class="data row0 col1" >2021-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col2" class="data row0 col2" >2021-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col3" class="data row0 col3" >-10,000,000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col4" class="data row0 col4" >0</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col5" class="data row0 col5" >True</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col6" class="data row0 col6" >-7,026.2451</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col7" class="data row0 col7" >CLP</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col8" class="data row0 col8" >1.000000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col9" class="data row0 col9" >1.000703</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col10" class="data row0 col10" >0.0700%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col11" class="data row0 col11" >-7,097</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col12" class="data row0 col12" >0.0000%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col13" class="data row0 col13" >1.000000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow0_col14" class="data row0 col14" >LinAct360</td> </tr> <tr> <th id="T_74e14ef4_2e81_11ec_a147_02cba411ec9dlevel0_row1" class="row_heading level0 row1" >1</th> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col0" class="data row1 col0" >2021-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col1" class="data row1 col1" >2022-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col2" class="data row1 col2" >2022-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col3" class="data row1 col3" >-10,000,000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col4" class="data row1 col4" >0</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col5" class="data row1 col5" >True</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col6" class="data row1 col6" >-4,328.7268</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col7" class="data row1 col7" >CLP</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col8" class="data row1 col8" >1.000703</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col9" class="data row1 col9" >1.001136</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col10" class="data row1 col10" >0.0400%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col11" class="data row1 col11" >-4,056</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col12" class="data row1 col12" >0.0000%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col13" class="data row1 col13" >1.000000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow1_col14" class="data row1 col14" >LinAct360</td> </tr> <tr> <th id="T_74e14ef4_2e81_11ec_a147_02cba411ec9dlevel0_row2" class="row_heading level0 row2" >2</th> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col0" class="data row2 col0" >2022-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col1" class="data row2 col1" >2023-10-16</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col2" class="data row2 col2" >2023-10-16</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col3" class="data row2 col3" >-10,000,000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col4" class="data row2 col4" >0</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col5" class="data row2 col5" >True</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col6" class="data row2 col6" >-11,198.7676</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col7" class="data row2 col7" >CLP</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col8" class="data row2 col8" >1.001136</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col9" class="data row2 col9" >1.002257</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col10" class="data row2 col10" >0.1100%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col11" class="data row2 col11" >-11,214</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col12" class="data row2 col12" >0.0000%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col13" class="data row2 col13" >1.000000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow2_col14" class="data row2 col14" >LinAct360</td> </tr> <tr> <th id="T_74e14ef4_2e81_11ec_a147_02cba411ec9dlevel0_row3" class="row_heading level0 row3" >3</th> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col0" class="data row3 col0" >2023-10-16</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col1" class="data row3 col1" >2024-10-15</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col2" class="data row3 col2" >2024-10-15</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col3" class="data row3 col3" >-10,000,000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col4" class="data row3 col4" >0</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col5" class="data row3 col5" >True</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col6" class="data row3 col6" >-27,864.3756</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col7" class="data row3 col7" >CLP</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col8" class="data row3 col8" >1.002257</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col9" class="data row3 col9" >1.005050</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col10" class="data row3 col10" >0.2700%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col11" class="data row3 col11" >-27,375</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col12" class="data row3 col12" >0.0000%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col13" class="data row3 col13" >1.000000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow3_col14" class="data row3 col14" >LinAct360</td> </tr> <tr> <th id="T_74e14ef4_2e81_11ec_a147_02cba411ec9dlevel0_row4" class="row_heading level0 row4" >4</th> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col0" class="data row4 col0" >2024-10-15</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col1" class="data row4 col1" >2025-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col2" class="data row4 col2" >2025-10-14</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col3" class="data row4 col3" >-10,000,000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col4" class="data row4 col4" >-10,000,000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col5" class="data row4 col5" >True</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col6" class="data row4 col6" >-10,046,724.2505</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col7" class="data row4 col7" >CLP</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col8" class="data row4 col8" >1.005050</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col9" class="data row4 col9" >1.009746</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col10" class="data row4 col10" >0.4600%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col11" class="data row4 col11" >-46,511</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col12" class="data row4 col12" >0.0000%</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col13" class="data row4 col13" >1.000000</td> <td id="T_74e14ef4_2e81_11ec_a147_02cba411ec9drow4_col14" class="data row4 col14" >LinAct360</td> </tr> </tbody></table> ```python vp_flot = vp.pv(fecha_val, op[1], zcc) print(f'El valor presente de la pata flotante es: USD {vp_flot:,.2f}') ``` El valor presente de la pata flotante es: USD -10,000,000.00 ```python c = op[1].get_cashflow_at(0) ``` ¿Porqué sabíamos que tenía que dar 10,000,000.00? **Hint**: la respuesta está en la construcción de la curva cero OIS. ## Sensibilidad En `QC_Financial_3` al calcular el valor presente, también se calculan las derivadas del valor presente respecto a cada uno de los vértices de la curva. ### Pata Fija ```python vp.pv(fecha_val, op[0], zcc) der = vp.get_derivatives() ``` Con esas derivadas, se puede calcular la sensibilidad a cada vértice de la curva cupón cero para un movimiento de 1 punto básico. ```python print(type(der)) ``` <class 'finrisk.QC_Financial_3.double_vec'> ```python delta = .0001 total = 0 for i, d in enumerate(der): total += d * delta print(f"Sensibilidad en {i}: {d * delta: 0,.2f}") print(f"Sensibilidad total: {total:,.2f}") ``` Sensibilidad en 0: 0.00 Sensibilidad en 1: 0.00 Sensibilidad en 2: 0.00 Sensibilidad en 3: 0.00 Sensibilidad en 4: 0.00 Sensibilidad en 5: 0.00 Sensibilidad en 6: 0.00 Sensibilidad en 7: 0.00 Sensibilidad en 8: 0.00 Sensibilidad en 9: 0.00 Sensibilidad en 10: 0.00 Sensibilidad en 11: 0.00 Sensibilidad en 12: 0.00 Sensibilidad en 13: 0.00 Sensibilidad en 14: 0.00 Sensibilidad en 15: -10.12 Sensibilidad en 16: 0.00 Sensibilidad en 17: -20.24 Sensibilidad en 18: -30.55 Sensibilidad en 19: -40.36 Sensibilidad en 20: -4,994.91 Sensibilidad en 21: 0.00 Sensibilidad en 22: 0.00 Sensibilidad en 23: 0.00 Sensibilidad en 24: 0.00 Sensibilidad en 25: 0.00 Sensibilidad en 26: 0.00 Sensibilidad en 27: 0.00 Sensibilidad en 28: 0.00 Sensibilidad en 29: 0.00 Sensibilidad en 30: 0.00 Sensibilidad en 31: 0.00 Sensibilidad en 32: 0.00 Sensibilidad total: -5,096.19 **Ejercicio:** Verifique por diferencias finitas centrales la sensibilidad en el vértice 17. La aproximación de la derivada por diferencias finitas centrales es: $$ \begin{equation} f^{\prime}\left(x\right)\approx\frac{f\left(x+h\right)-f\left(x-h\right)}{2h} \end{equation} $$ ### Pata Flotante ```python vp.pv(fecha_val, op[1], zcc) der = vp.get_derivatives() ``` ```python total = 0 for i, d in enumerate(der): total += d * delta print(f"Sensibilidad en {i}: {d * delta: 0,.2f}") print(f"Sensibilidad total: {total:,.2f}") ``` Sensibilidad en 0: 0.00 Sensibilidad en 1: 0.00 Sensibilidad en 2: 0.00 Sensibilidad en 3: 0.00 Sensibilidad en 4: 0.00 Sensibilidad en 5: 0.00 Sensibilidad en 6: 0.00 Sensibilidad en 7: 0.00 Sensibilidad en 8: 0.00 Sensibilidad en 9: 0.00 Sensibilidad en 10: 0.00 Sensibilidad en 11: 0.00 Sensibilidad en 12: 0.00 Sensibilidad en 13: 0.00 Sensibilidad en 14: 0.00 Sensibilidad en 15: 0.70 Sensibilidad en 16: 0.00 Sensibilidad en 17: 0.86 Sensibilidad en 18: 3.35 Sensibilidad en 19: 11.08 Sensibilidad en 20: 4,967.99 Sensibilidad en 21: 0.00 Sensibilidad en 22: 0.00 Sensibilidad en 23: 0.00 Sensibilidad en 24: 0.00 Sensibilidad en 25: 0.00 Sensibilidad en 26: 0.00 Sensibilidad en 27: 0.00 Sensibilidad en 28: 0.00 Sensibilidad en 29: 0.00 Sensibilidad en 30: 0.00 Sensibilidad en 31: 0.00 Sensibilidad en 32: 0.00 Sensibilidad total: 4,983.99 La estructura es la misma que para una pata fija, lo que indica que se debe también incluir la sensibilidad a la curva de proyección. ```python import numpy as np result = [] for i in range(op[1].size()): # Se obtiene cada uno de los flujos cshflw = op[1].get_cashflow_at(i) # Se obtiene el gradiente de los flujos respecto a la curva de proyección amt_der = cshflw.get_amount_derivatives() # Se obtiene el factor de descuento que corresponde al flujo df = zcc.get_discount_factor_at(fecha_val.day_diff(cshflw.get_settlement_date())) # Con el gradiente y el factor de descuento se obtiene la sensibilidad amt_sens = [da_dz * delta * df for da_dz in amt_der] # Se almacena la sensibilidad if len(amt_sens) > 0: result.append(np.array(amt_sens)) # Vector donde se almacena la sensibilidad total por vértice total = result[0] * 0 # Esta es una suma vectorial componente a componente for r in result: total += r # Se muestra el resultado for i in range(len(total)): print(f"Sensibilidad en {i}: {total[i]:0,.2f}") print(f"Sensibilidad de proyección: {sum(total):,.2f} USD") ``` Sensibilidad en 0: -0.00 Sensibilidad en 1: -0.00 Sensibilidad en 2: -0.00 Sensibilidad en 3: -0.00 Sensibilidad en 4: -0.00 Sensibilidad en 5: -0.00 Sensibilidad en 6: -0.00 Sensibilidad en 7: -0.00 Sensibilidad en 8: -0.00 Sensibilidad en 9: -0.00 Sensibilidad en 10: -0.00 Sensibilidad en 11: -0.00 Sensibilidad en 12: -0.00 Sensibilidad en 13: -0.00 Sensibilidad en 14: -0.00 Sensibilidad en 15: -0.70 Sensibilidad en 16: -0.00 Sensibilidad en 17: -0.86 Sensibilidad en 18: -3.35 Sensibilidad en 19: -11.08 Sensibilidad en 20: -4,967.99 Sensibilidad en 21: -0.00 Sensibilidad en 22: -0.00 Sensibilidad en 23: -0.00 Sensibilidad en 24: -0.00 Sensibilidad en 25: -0.00 Sensibilidad en 26: -0.00 Sensibilidad en 27: -0.00 Sensibilidad en 28: -0.00 Sensibilidad en 29: -0.00 Sensibilidad en 30: -0.00 Sensibilidad en 31: -0.00 Sensibilidad en 32: -0.00 Sensibilidad de proyección: -4,983.99 USD **Ejercicio:** Ambas sensibilidades se cancelan. ¿Porqué?
[STATEMENT] lemma All_arcs_in_path: "e \<in> arcs T \<Longrightarrow> \<exists>p u v. awalk u p v \<and> e \<in> set p" [PROOF STATE] proof (prove) goal (1 subgoal): 1. e \<in> arcs T \<Longrightarrow> \<exists>p u v. awalk u p v \<and> e \<in> set p [PROOF STEP] by (meson arc_implies_awalk list.set_intros(1))
#' tidbits. #' #' Various functions to streamline tasks that are repetitive and/or require #' funky code tricks. A byproduct of UTHealth's TSCI 5050 Introduction to Data #' Science course. #' #' @name tidbits #' @docType package #' @importFrom methods is NULL
Beef Livestock record sheet, other forms needed, and beef project info. Click on the link and then click to open. Level 1, Bite Into Beef – 4-Hers in Grades 3, 4, and 5.
The best pianist /composer. Ever. Who's worse- octave_revolutionary or the89thkey? Best piano sonata ever written? ? WHEN SHOULD I START MY KID WITH PIANO / TO BECOME "THE BEST?" What is the Jelly Roll "Lick" - Jazz Theory and Mark Levine's book? Jazz Theory vs. Classical Music Theory - Which one wins? ! Small FAT Hands/Palms & SHORT Fingers vs. Long T-H-I-N Fingers-Power or Grace? How to memorize a piece, no errors - just practice? Who ARE these People?! Modern Composers? "I JUST WANT MY KID TO BE HAPPY!" : Do you buy that? or is this a cover up? * Private Lessons VS. SELF-STUDY * Pro's and Cons? !! How do THEY / YOU do it?!? !! // Sightreading&CATCHING every tie/Legato/Note! Who are your favorite pianists for Bach? is lang lang good or not? Who is the best Beethoven Sonata Interpreter? Horowitz or Marc-Andre Hamelin? Who has the best technique? Top Ten pianists still that are a live. Who Are Your Top 10 Favorite Classical Pianists? What editions of Beethoven sonatas do you use? Who will win the Chopin Competition? If You Went to Juillard, Which Teacher Would You Choose? Which composer was the greatest?
function bzip2Matlab % This function prompts the user to select a file via gui method % If the file ends with *.bz2 suffix % function assumes the file is compressed and will uncompress it % using bzip2 % Else if the file ends with any other suffix % function attempts to compress it using bzip2 % The objective is easier handlng of compressed files in Matlab % LM AIB 11/24/2002 % copyright (c) 2001-2006, Washington University in St. Louis. % Permission is granted to use or modify only for non-commercial, % non-treatment-decision applications, and further only if this header is % not removed from any file. No warranty is expressed or implied for any % use whatever: use at your own risk. Users can request use of CERR for % institutional review board-approved protocols. Commercial users can % request a license. Contact Joe Deasy for more information % (radonc.wustl.edu@jdeasy, reversed). [fname, pathname] = uigetfile('*.*', ... 'Select a file you wish to compress or decompress'); tic oldDir = pwd; if isdeployed pathStr = fullfile(getCERRPath,'bin','Compression'); else pathStr = fullfile(getCERRPath,'Compression'); end cd(pathname); l = length(fname); fmat = ''; outstr = ''; fmat = (strcat('"',oldDir, '\', fname,'"')); if (~strcmpi(midstring(fname,l-2,l),'bz2')) % compress file cd(pathStr); outstr = ['bzip2-102-x86-win32.exe -vv9 ', fmat]; system(outstr); cd(oldDir); elseif (strcmpi(midstring(fname,l-2,l),'bz2')) % uncompress file cd(pathStr); outstr = ['bzip2-102-x86-win32.exe -dvv ', fmat]; system(outstr); cd(oldDir); else error('Incorrect filename chosen. Exiting bzip2Matlab.') end toc return