Datasets:
AI4M
/

text
stringlengths
0
3.34M
// // Created by Tyler on 10/23/21. // #include <ndn-svs/svspubsub.hpp> #include <ndn-cxx/security/signing-helpers.hpp> #include <ndn-cxx/util/scheduler.hpp> #include <ndn-cxx/util/io.hpp> #include <boost/asio/io_service.hpp> #include <boost/program_options/options_description.hpp> #include <boost/program_options/variables_map.hpp> #include <boost/program_options/parsers.hpp> #include <iostream> #include <random> namespace po = boost::program_options; using namespace ndn; std::random_device rd; //Will be used to obtain a seed for the random number engine std::mt19937 random_gen(rd()); //Standard mersenne_twister_engine seeded with rd() void periodicAddRecord(KeyChain& keychain, shared_ptr<svs::SVSPubSub> pubSub, const Name& peerPrefix, Scheduler &scheduler) { std::uniform_int_distribution<int> distribution(0, INT_MAX); Data data(Name(peerPrefix).append(std::to_string(distribution(random_gen)))); data.setContent(makeStringBlock(tlv::Content, std::to_string(distribution(random_gen)))); keychain.sign(data, signingByIdentity(peerPrefix)); std::cout << "publishing: " << data.getFullName() << std::endl; pubSub->publishData(data); // schedule for the next record generation scheduler.schedule(time::seconds(5), [&keychain, pubSub, peerPrefix, &scheduler] { periodicAddRecord(keychain, pubSub, peerPrefix, scheduler); }); } int main(int argc, char **argv) { po::options_description description("Usage for Mnemosyne Test Client"); description.add_options() ("help,h", "Display this help message") ("interface-ps-prefix,i", po::value<std::string>()->default_value("/ndn/broadcast/mnemosyne"), "The prefix for Interface Pub/Sub") ("client-prefix,c", po::value<std::string>(), "The prefix for the client"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(description).run(), vm); po::notify(vm); if(vm.count("help")){ std::cout << description; return 0; } if (vm.count("client-prefix") == 0) { std::cout << "missing parameter: Client Prefix\n"; return 2; } boost::asio::io_service ioService; Face face(ioService); security::KeyChain keychain; std::shared_ptr<svs::SVSPubSub> interfacePS = std::make_shared<svs::SVSPubSub>(vm["interface-ps-prefix"].as<std::string>(), vm["client-prefix"].as<std::string>(), face, nullptr); Scheduler scheduler(ioService); periodicAddRecord(keychain, interfacePS, vm["client-prefix"].as<std::string>(), scheduler); face.processEvents(); return 0; }
(* * Copyright 2014, General Dynamics C4 Systems * * This software may be distributed and modified according to the terms of * the GNU General Public License version 2. Note that NO WARRANTY is provided. * See "LICENSE_GPLv2.txt" for details. * * @TAG(GD_GPL) *) theory ArchArch_AI imports "../Arch_AI" begin context Arch begin global_naming ARM definition "valid_aci aci \<equiv> case aci of MakePool frame slot parent base \<Rightarrow> \<lambda>s. cte_wp_at (\<lambda>c. c = cap.NullCap) slot s \<and> real_cte_at slot s \<and> ex_cte_cap_wp_to is_cnode_cap slot s \<and> slot \<noteq> parent \<and> cte_wp_at (\<lambda>cap. \<exists>idx. cap = cap.UntypedCap False frame pageBits idx ) parent s \<and> descendants_of parent (cdt s) = {} \<and> is_aligned base asid_low_bits \<and> base \<le> 2^asid_bits - 1 \<and> arm_asid_table (arch_state s) (asid_high_bits_of base) = None" lemma safe_parent_strg: "cte_wp_at (\<lambda>cap. cap = UntypedCap False frame pageBits idx) p s \<and> descendants_of p (cdt s) = {} \<and> valid_objs s \<longrightarrow> cte_wp_at (safe_parent_for (cdt s) p (ArchObjectCap (ASIDPoolCap frame base))) p s" apply (clarsimp simp: cte_wp_at_caps_of_state safe_parent_for_def is_physical_def arch_is_physical_def) apply (rule is_aligned_no_overflow) apply (drule (1) caps_of_state_valid_cap) apply (clarsimp simp: valid_cap_def cap_aligned_def) done lemma asid_low_bits_pageBits: "Suc (Suc asid_low_bits) = pageBits" by (simp add: pageBits_def asid_low_bits_def) (* 32-bit instance of Detype_AI.range_cover_full *) lemma range_cover_full: "\<lbrakk>is_aligned ptr sz;sz<word_bits\<rbrakk> \<Longrightarrow> range_cover (ptr::word32) sz sz (Suc 0)" by (clarsimp simp:range_cover_def unat_eq_0 le_mask_iff[symmetric] word_and_le1 word_bits_def) definition valid_arch_inv :: "arch_invocation \<Rightarrow> 'z::state_ext state \<Rightarrow> bool" where "valid_arch_inv ai \<equiv> case ai of InvokePageTable pti \<Rightarrow> valid_pti pti | InvokePageDirectory pdi \<Rightarrow> valid_pdi pdi | InvokePage pgi \<Rightarrow> valid_page_inv pgi | InvokeASIDControl aci \<Rightarrow> valid_aci aci | InvokeASIDPool ap \<Rightarrow> valid_apinv ap" lemma check_vp_wpR [wp]: "\<lbrace>\<lambda>s. vmsz_aligned w sz \<longrightarrow> P () s\<rbrace> check_vp_alignment sz w \<lbrace>P\<rbrace>, -" apply (simp add: check_vp_alignment_def unlessE_whenE cong: vmpage_size.case_cong) apply (rule hoare_pre) apply (wp hoare_whenE_wp|wpc)+ apply (simp add: vmsz_aligned_def) done lemma check_vp_inv: "\<lbrace>P\<rbrace> check_vp_alignment sz w \<lbrace>\<lambda>_. P\<rbrace>" apply (simp add: check_vp_alignment_def unlessE_whenE cong: vmpage_size.case_cong) apply (rule hoare_pre) apply (wp hoare_whenE_wp|wpc)+ apply simp done lemma p2_low_bits_max: "(2 ^ asid_low_bits - 1) = (max_word :: 10 word)" by (simp add: asid_low_bits_def max_word_def) lemma dom_ucast_eq: "(- dom (\<lambda>a::10 word. p (ucast a::word32)) \<inter> {x. x \<le> 2 ^ asid_low_bits - 1 \<and> ucast x + y \<noteq> 0} = {}) = (- dom p \<inter> {x. x \<le> 2 ^ asid_low_bits - 1 \<and> x + y \<noteq> 0} = {})" apply safe apply clarsimp apply (rule ccontr) apply (erule_tac x="ucast x" in in_emptyE) apply (clarsimp simp: p2_low_bits_max) apply (rule conjI) apply (clarsimp simp: ucast_ucast_mask) apply (subst (asm) less_mask_eq) apply (rule word_less_sub_le [THEN iffD1]) apply (simp add: word_bits_def) apply (simp add: asid_low_bits_def) apply simp apply (clarsimp simp: ucast_ucast_mask) apply (subst (asm) less_mask_eq) apply (rule word_less_sub_le [THEN iffD1]) apply (simp add: word_bits_def) apply (simp add: asid_low_bits_def) apply simp apply (clarsimp simp: p2_low_bits_max) apply (rule ccontr) apply simp apply (erule_tac x="ucast x" in in_emptyE) apply clarsimp apply (rule conjI, blast) apply (rule word_less_sub_1) apply (rule order_less_le_trans) apply (rule ucast_less, simp) apply (simp add: asid_low_bits_def) done lemma asid_high_bits_max_word: "(2 ^ asid_high_bits - 1 :: 7 word) = max_word" by (simp add: asid_high_bits_def max_word_def) lemma dom_ucast_eq_7: "(- dom (\<lambda>a::7 (*asid_high_bits*) word. p (ucast a::word32)) \<inter> {x. x \<le> 2 ^ asid_high_bits - 1} = {}) = (- dom p \<inter> {x. x \<le> 2 ^ asid_high_bits - 1} = {})" apply safe apply clarsimp apply (rule ccontr) apply (erule_tac x="ucast x" in in_emptyE) apply (clarsimp simp: asid_high_bits_max_word) apply (clarsimp simp: ucast_ucast_mask) apply (subst (asm) less_mask_eq) apply (rule word_less_sub_le [THEN iffD1]) apply (simp add: word_bits_def) apply (simp add: asid_high_bits_def) apply simp apply (clarsimp simp: asid_high_bits_max_word) apply (rule ccontr) apply simp apply (erule_tac x="ucast x" in in_emptyE) apply clarsimp apply (rule conjI, blast) apply (rule word_less_sub_1) apply (rule order_less_le_trans) apply (rule ucast_less, simp) apply (simp add: asid_high_bits_def) done lemma ucast_fst_hd_assocs: "- dom (\<lambda>x. pool (ucast (x::10 word)::word32)) \<inter> {x. x \<le> 2 ^ asid_low_bits - 1 \<and> ucast x + (w::word32) \<noteq> 0} \<noteq> {} \<Longrightarrow> fst (hd [(x, y)\<leftarrow>assocs pool . x \<le> 2 ^ asid_low_bits - 1 \<and> x + w \<noteq> 0 \<and> y = None]) = ucast (fst (hd [(x, y)\<leftarrow>assocs (\<lambda>a::10 word. pool (ucast a)) . x \<le> 2 ^ asid_low_bits - 1 \<and> ucast x + w \<noteq> 0 \<and> y = None]))" apply (simp add: ucast_assocs[unfolded o_def]) apply (simp add: filter_map split_def) apply (simp cong: conj_cong add: ucast_ucast_len) apply (simp add: asid_low_bits_def minus_one_norm) apply (simp add: ord_le_eq_trans [OF word_n1_ge]) apply (simp add: word_le_make_less) apply (subgoal_tac "P" for P) (* cut_tac but more awesome *) apply (subst hd_map, assumption) apply simp apply (rule sym, rule ucast_ucast_len) apply (drule hd_in_set) apply simp apply (simp add: assocs_empty_dom_comp null_def split_def) apply (simp add: ucast_assocs[unfolded o_def] filter_map split_def) apply (simp cong: conj_cong add: ucast_ucast_len) done crunch typ_at [wp]: perform_page_table_invocation, perform_page_invocation, perform_asid_pool_invocation, perform_page_directory_invocation "\<lambda>s. P (typ_at T p s)" (wp: crunch_wps) lemmas perform_page_table_invocation_typ_ats [wp] = abs_typ_at_lifts [OF perform_page_table_invocation_typ_at] lemmas perform_page_directory_invocation_typ_ats [wp] = abs_typ_at_lifts [OF perform_page_directory_invocation_typ_at] lemmas perform_page_invocation_typ_ats [wp] = abs_typ_at_lifts [OF perform_page_invocation_typ_at] lemmas perform_asid_pool_invocation_typ_ats [wp] = abs_typ_at_lifts [OF perform_asid_pool_invocation_typ_at] lemma perform_asid_control_invocation_tcb_at: "\<lbrace>invs and valid_aci aci and st_tcb_at active p and K (\<forall>w a b c. aci = asid_control_invocation.MakePool w a b c \<longrightarrow> w \<noteq> p)\<rbrace> perform_asid_control_invocation aci \<lbrace>\<lambda>rv. tcb_at p\<rbrace>" apply (simp add: perform_asid_control_invocation_def) apply (cases aci) apply clarsimp apply (wp |simp)+ apply (wp obj_at_delete_objects retype_region_obj_at_other2 hoare_vcg_const_imp_lift|assumption)+ apply (intro impI conjI) apply (clarsimp simp: retype_addrs_def obj_bits_api_def default_arch_object_def image_def ptr_add_def) apply (clarsimp simp: st_tcb_at_tcb_at)+ apply (frule st_tcb_ex_cap) apply fastforce apply (clarsimp split: Structures_A.thread_state.splits) apply auto[1] apply (clarsimp simp: ex_nonz_cap_to_def valid_aci_def) apply (frule invs_untyped_children) apply (clarsimp simp:cte_wp_at_caps_of_state) apply (erule_tac ptr="(aa,ba)" in untyped_children_in_mdbE[where P="\<lambda>c. t \<in> zobj_refs c" for t]) apply (simp add: cte_wp_at_caps_of_state) apply simp apply (simp add:cte_wp_at_caps_of_state) apply fastforce apply (clarsimp simp: zobj_refs_to_obj_refs) apply (erule(1) in_empty_interE) apply (clarsimp simp:page_bits_def) apply simp done lemma ucast_asid_high_btis_of_le [simp]: "ucast (asid_high_bits_of w) \<le> (2 ^ asid_high_bits - 1 :: word32)" apply (simp add: asid_high_bits_of_def) apply (rule word_less_sub_1) apply (rule order_less_le_trans) apply (rule ucast_less) apply simp apply (simp add: asid_high_bits_def) done lemma invoke_arch_tcb: "\<lbrace>invs and valid_arch_inv ai and st_tcb_at active tptr\<rbrace> arch_perform_invocation ai \<lbrace>\<lambda>rv. tcb_at tptr\<rbrace>" apply (simp add: arch_perform_invocation_def) apply (cases ai, simp_all) apply (wp, clarsimp simp: st_tcb_at_tcb_at)+ defer apply (wp, clarsimp simp: st_tcb_at_tcb_at) apply (wp perform_asid_control_invocation_tcb_at) apply (clarsimp simp add: valid_arch_inv_def) apply (clarsimp simp: valid_aci_def) apply (frule st_tcb_ex_cap) apply fastforce apply (clarsimp split: Structures_A.thread_state.splits) apply auto[1] apply (clarsimp simp: ex_nonz_cap_to_def) apply (frule invs_untyped_children) apply (clarsimp simp:cte_wp_at_caps_of_state) apply (erule_tac ptr="(aa,ba)" in untyped_children_in_mdbE[where P="\<lambda>c. t \<in> zobj_refs c" for t]) apply (simp add: cte_wp_at_caps_of_state)+ apply fastforce apply (clarsimp simp: zobj_refs_to_obj_refs cte_wp_at_caps_of_state) apply (drule_tac p="(aa,ba)" in caps_of_state_valid_cap, fastforce) apply (clarsimp simp: valid_cap_def cap_aligned_def) apply (drule_tac x=tptr in base_member_set, simp) apply (simp add: pageBits_def field_simps del: atLeastAtMost_iff) apply (metis (no_types) orthD1 x_power_minus_1) apply simp done end locale asid_update = Arch + fixes ap asid s s' assumes ko: "ko_at (ArchObj (ASIDPool empty)) ap s" assumes empty: "arm_asid_table (arch_state s) asid = None" defines "s' \<equiv> s\<lparr>arch_state := arch_state s\<lparr>arm_asid_table := arm_asid_table (arch_state s)(asid \<mapsto> ap)\<rparr>\<rparr>" context asid_update begin lemma vs_lookup1' [simp]: "vs_lookup1 s' = vs_lookup1 s" by (simp add: vs_lookup1_def s'_def) lemma vs_lookup_pages1' [simp]: "vs_lookup_pages1 s' = vs_lookup_pages1 s" by (simp add: vs_lookup_pages1_def s'_def) lemma vs_asid_refs' [simp]: "vs_asid_refs (arm_asid_table (arch_state s')) = vs_asid_refs (arm_asid_table (arch_state s)) \<union> {([VSRef (ucast asid) None], ap)}" apply (simp add: s'_def) apply (rule set_eqI) apply (rule iffI) apply (auto simp: vs_asid_refs_def split: if_split_asm)[1] apply clarsimp apply (erule disjE) apply (auto simp: vs_asid_refs_def)[1] apply (subst (asm) vs_asid_refs_def) apply (clarsimp dest!: graph_ofD) apply (rule vs_asid_refsI) apply (clarsimp simp: empty) done lemma vs_lookup': "vs_lookup s' = vs_lookup s \<union> {([VSRef (ucast asid) None], ap)}" using ko apply (simp add: vs_lookup_def) apply (rule rtrancl_insert) apply (clarsimp simp: vs_lookup1_def obj_at_def vs_refs_def) done lemma vs_lookup_pages': "vs_lookup_pages s' = vs_lookup_pages s \<union> {([VSRef (ucast asid) None], ap)}" using ko apply (simp add: vs_lookup_pages_def) apply (rule rtrancl_insert) apply (clarsimp simp: vs_lookup_pages1_def obj_at_def vs_refs_pages_def) done lemma arch_obj [simp]: "valid_arch_obj ao s' = valid_arch_obj ao s" by (cases ao, simp_all add: s'_def) lemma obj_at [simp]: "obj_at P p s' = obj_at P p s" by (simp add: s'_def) lemma arch_objs': "valid_arch_objs s \<Longrightarrow> valid_arch_objs s'" using ko apply (clarsimp simp: valid_arch_objs_def vs_lookup') apply (fastforce simp: obj_at_def) done lemma global_objs': "valid_global_objs s \<Longrightarrow> valid_global_objs s'" apply (clarsimp simp: valid_global_objs_def valid_ao_at_def) apply (auto simp: s'_def) done lemma caps_of_state_s': "caps_of_state s' = caps_of_state s" by (rule caps_of_state_pspace, simp add: s'_def) lemma valid_vs_lookup': "\<lbrakk> valid_vs_lookup s; \<exists>ptr cap. caps_of_state s ptr = Some cap \<and> ap \<in> obj_refs cap \<and> vs_cap_ref cap = Some [VSRef (ucast asid) None] \<rbrakk> \<Longrightarrow> valid_vs_lookup s'" by (clarsimp simp: valid_vs_lookup_def caps_of_state_s' vs_lookup_pages') lemma valid_table_caps': "\<lbrakk> valid_table_caps s \<rbrakk> \<Longrightarrow> valid_table_caps s'" apply (simp add: valid_table_caps_def caps_of_state_s') apply (simp add: s'_def) done lemma valid_arch_caps: "\<lbrakk> valid_arch_caps s; \<exists>ptr cap. caps_of_state s ptr = Some cap \<and> ap \<in> obj_refs cap \<and> vs_cap_ref cap = Some [VSRef (ucast asid) None] \<rbrakk> \<Longrightarrow> valid_arch_caps s'" by (simp add: valid_arch_caps_def caps_of_state_s' valid_table_caps' valid_vs_lookup') lemma valid_asid_map': "valid_asid_map s \<Longrightarrow> valid_asid_map s'" using empty apply (clarsimp simp: valid_asid_map_def s'_def) apply (drule bspec, blast) apply (clarsimp simp: vspace_at_asid_def) apply (drule vs_lookup_2ConsD) apply clarsimp apply (erule vs_lookup_atE) apply (drule vs_lookup1D) apply clarsimp apply (rule vs_lookupI[rotated]) apply (rule r_into_rtrancl) apply (rule vs_lookup1I) apply (fastforce simp: obj_at_def) apply assumption apply simp apply (clarsimp simp: vs_asid_refs_def graph_of_def) apply fastforce done end context Arch begin global_naming ARM lemma valid_arch_state_strg: "valid_arch_state s \<and> ap \<notin> ran (arm_asid_table (arch_state s)) \<and> asid_pool_at ap s \<longrightarrow> valid_arch_state (s\<lparr>arch_state := arch_state s\<lparr>arm_asid_table := arm_asid_table (arch_state s)(asid \<mapsto> ap)\<rparr>\<rparr>)" apply (clarsimp simp: valid_arch_state_def) apply (clarsimp simp: valid_asid_table_def ran_def) apply (fastforce intro!: inj_on_fun_updI) done lemma valid_vs_lookup_at_upd_strg: "valid_vs_lookup s \<and> ko_at (ArchObj (ASIDPool empty)) ap s \<and> arm_asid_table (arch_state s) asid = None \<and> (\<exists>ptr cap. caps_of_state s ptr = Some cap \<and> ap \<in> obj_refs cap \<and> vs_cap_ref cap = Some [VSRef (ucast asid) None]) \<longrightarrow> valid_vs_lookup (s\<lparr>arch_state := arch_state s\<lparr>arm_asid_table := arm_asid_table (arch_state s)(asid \<mapsto> ap)\<rparr>\<rparr>)" apply clarsimp apply (subgoal_tac "asid_update ap asid s") prefer 2 apply unfold_locales[1] apply assumption+ apply (erule (1) asid_update.valid_vs_lookup') apply fastforce done lemma retype_region_ap: "\<lbrace>\<top>\<rbrace> retype_region ap 1 0 (ArchObject ASIDPoolObj) dev \<lbrace>\<lambda>_. ko_at (ArchObj (arch_kernel_obj.ASIDPool empty)) ap\<rbrace>" apply (rule hoare_post_imp) prefer 2 apply (rule retype_region_obj_at) apply simp apply simp apply (clarsimp simp: retype_addrs_def obj_bits_api_def default_arch_object_def) apply (clarsimp simp: obj_at_def default_object_def default_arch_object_def) done lemma retype_region_ap': "\<lbrace>\<top>\<rbrace> retype_region ap 1 0 (ArchObject ASIDPoolObj) dev \<lbrace>\<lambda>rv. asid_pool_at ap\<rbrace>" apply (rule hoare_strengthen_post, rule retype_region_ap) apply (clarsimp simp: a_type_def elim!: obj_at_weakenE) done lemma no_cap_to_obj_with_diff_ref_null_filter: "no_cap_to_obj_with_diff_ref cap S = (\<lambda>s. \<forall>c \<in> ran (null_filter (caps_of_state s) |` (- S)). obj_refs c = obj_refs cap \<longrightarrow> table_cap_ref c = table_cap_ref cap)" apply (simp add: no_cap_to_obj_with_diff_ref_def ball_ran_eq cte_wp_at_caps_of_state) apply (simp add: Ball_def) apply (intro iff_allI ext) apply (simp add: restrict_map_def null_filter_def) apply (auto dest!: obj_ref_none_no_asid[rule_format] simp: table_cap_ref_def) done lemma retype_region_no_cap_to_obj: "\<lbrace>valid_pspace and valid_mdb and caps_overlap_reserved {ptr..ptr + 2 ^ obj_bits_api ty us - 1} and caps_no_overlap ptr sz and pspace_no_overlap_range_cover ptr sz and no_cap_to_obj_with_diff_ref cap S and (\<lambda>s. \<exists>slot. cte_wp_at (\<lambda>c. up_aligned_area ptr sz \<subseteq> cap_range c \<and> cap_is_device c = dev) slot s) and K (ty = Structures_A.CapTableObject \<longrightarrow> 0 < us) and K (range_cover ptr sz (obj_bits_api ty us) 1) \<rbrace> retype_region ptr 1 us ty dev \<lbrace>\<lambda>rv. no_cap_to_obj_with_diff_ref cap S\<rbrace>" apply (rule hoare_gen_asm)+ apply (simp add: no_cap_to_obj_with_diff_ref_null_filter) apply (wp retype_region_caps_of | simp)+ apply fastforce done lemma valid_table_caps_asid_upd [iff]: "valid_table_caps (s\<lparr>arch_state := (arm_asid_table_update f (arch_state s))\<rparr>) = valid_table_caps s" by (simp add: valid_table_caps_def) lemma vs_asid_ref_upd: "([VSRef (ucast (asid_high_bits_of asid')) None] \<rhd> ap') (s\<lparr>arch_state := arch_state s\<lparr>arm_asid_table := arm_asid_table (arch_state s)(asid_high_bits_of asid \<mapsto> ap)\<rparr>\<rparr>) = (if asid_high_bits_of asid' = asid_high_bits_of asid then ap' = ap else ([VSRef (ucast (asid_high_bits_of asid')) None] \<rhd> ap') s)" by (fastforce intro: vs_lookup_atI elim: vs_lookup_atE) lemma vs_asid_ref_eq: "([VSRef (ucast asid) None] \<rhd> ap) s = (arm_asid_table (arch_state s) asid = Some ap)" by (fastforce elim: vs_lookup_atE intro: vs_lookup_atI) lemma set_cap_reachable_pg_cap: "\<lbrace>\<lambda>s. P (reachable_pg_cap cap s)\<rbrace> set_cap x y \<lbrace>\<lambda>_ s. P (reachable_pg_cap cap s)\<rbrace>" by (unfold reachable_pg_cap_def, wp hoare_vcg_ex_lift set_cap.vs_lookup_pages) lemma cap_insert_simple_arch_caps_ap: "\<lbrace>valid_arch_caps and (\<lambda>s. cte_wp_at (safe_parent_for (cdt s) src cap) src s) and no_cap_to_obj_with_diff_ref cap {dest} and (\<lambda>s. arm_asid_table (arch_state s) (asid_high_bits_of asid) = None) and ko_at (ArchObj (ASIDPool empty)) ap and K (cap = ArchObjectCap (ASIDPoolCap ap asid)) \<rbrace> cap_insert cap src dest \<lbrace>\<lambda>rv s. valid_arch_caps (s\<lparr>arch_state := arch_state s \<lparr>arm_asid_table := arm_asid_table (arch_state s)(asid_high_bits_of asid \<mapsto> ap)\<rparr>\<rparr>)\<rbrace>" apply (simp add: cap_insert_def update_cdt_def set_cdt_def valid_arch_caps_def set_untyped_cap_as_full_def bind_assoc) apply (strengthen valid_vs_lookup_at_upd_strg) apply (wp get_cap_wp set_cap_valid_vs_lookup set_cap_arch_obj set_cap_valid_table_caps hoare_vcg_all_lift | simp split del: if_split)+ apply (rule_tac P = "cte_wp_at (op = src_cap) src" in set_cap_orth) apply (wp hoare_vcg_imp_lift hoare_vcg_ball_lift set_free_index_final_cap hoare_vcg_disj_lift set_cap_reachable_pg_cap set_cap.vs_lookup_pages | clarsimp)+ apply (wp set_cap_arch_obj set_cap_valid_table_caps hoare_vcg_ball_lift get_cap_wp static_imp_wp)+ apply (clarsimp simp: cte_wp_at_caps_of_state is_cap_simps) apply (rule conjI) apply (clarsimp simp: vs_cap_ref_def) apply (rule_tac x="fst dest" in exI) apply (rule_tac x="snd dest" in exI) apply simp apply (rule conjI) apply (simp add: unique_table_caps_def is_cap_simps) apply (subst unique_table_refs_def) apply (intro allI impI) apply (simp split: if_split_asm) apply (simp add: no_cap_to_obj_with_diff_ref_def cte_wp_at_caps_of_state) apply (simp add: no_cap_to_obj_with_diff_ref_def cte_wp_at_caps_of_state) apply (erule (3) unique_table_refsD) done lemma valid_asid_map_asid_upd_strg: "valid_asid_map s \<and> ko_at (ArchObj (ASIDPool empty)) ap s \<and> arm_asid_table (arch_state s) asid = None \<longrightarrow> valid_asid_map (s\<lparr>arch_state := arch_state s\<lparr>arm_asid_table := arm_asid_table (arch_state s)(asid \<mapsto> ap)\<rparr>\<rparr>)" apply clarsimp apply (subgoal_tac "asid_update ap asid s") prefer 2 apply unfold_locales[1] apply assumption+ apply (erule (1) asid_update.valid_asid_map') done lemma valid_arch_objs_asid_upd_strg: "valid_arch_objs s \<and> ko_at (ArchObj (ASIDPool empty)) ap s \<and> arm_asid_table (arch_state s) asid = None \<longrightarrow> valid_arch_objs (s\<lparr>arch_state := arch_state s\<lparr>arm_asid_table := arm_asid_table (arch_state s)(asid \<mapsto> ap)\<rparr>\<rparr>)" apply clarsimp apply (subgoal_tac "asid_update ap asid s") prefer 2 apply unfold_locales[1] apply assumption+ apply (erule (1) asid_update.arch_objs') done lemma valid_global_objs_asid_upd_strg: "valid_global_objs s \<and> ko_at (ArchObj (arch_kernel_obj.ASIDPool empty)) ap s \<and> arm_asid_table (arch_state s) asid = None \<longrightarrow> valid_global_objs (s\<lparr>arch_state := arch_state s\<lparr>arm_asid_table := arm_asid_table (arch_state s)(asid \<mapsto> ap)\<rparr>\<rparr>)" by clarsimp lemma safe_parent_cap_is_device: "safe_parent_for m p cap pcap \<Longrightarrow> cap_is_device cap = cap_is_device pcap" by (simp add: safe_parent_for_def) lemma cap_insert_ap_invs: "\<lbrace>invs and valid_cap cap and tcb_cap_valid cap dest and ex_cte_cap_wp_to (appropriate_cte_cap cap) dest and cte_wp_at (\<lambda>c. c = cap.NullCap) dest and no_cap_to_obj_with_diff_ref cap {dest} and (\<lambda>s. cte_wp_at (safe_parent_for (cdt s) src cap) src s) and K (cap = cap.ArchObjectCap (arch_cap.ASIDPoolCap ap asid)) and (\<lambda>s. \<forall>irq \<in> cap_irqs cap. irq_issued irq s) and ko_at (ArchObj (arch_kernel_obj.ASIDPool empty)) ap and (\<lambda>s. ap \<notin> ran (arm_asid_table (arch_state s)) \<and> arm_asid_table (arch_state s) (asid_high_bits_of asid) = None)\<rbrace> cap_insert cap src dest \<lbrace>\<lambda>rv s. invs (s\<lparr>arch_state := arch_state s \<lparr>arm_asid_table := (arm_asid_table \<circ> arch_state) s(asid_high_bits_of asid \<mapsto> ap)\<rparr>\<rparr>)\<rbrace>" apply (simp add: invs_def valid_state_def valid_pspace_def) apply (strengthen valid_arch_state_strg valid_arch_objs_asid_upd_strg valid_asid_map_asid_upd_strg ) apply (simp cong: conj_cong) apply (rule hoare_pre) apply (wp cap_insert_simple_mdb cap_insert_iflive cap_insert_zombies cap_insert_ifunsafe cap_insert_valid_global_refs cap_insert_idle valid_irq_node_typ cap_insert_simple_arch_caps_ap) apply (clarsimp simp: is_simple_cap_def cte_wp_at_caps_of_state is_cap_simps) apply (frule safe_parent_cap_is_device) apply (drule safe_parent_cap_range) apply (simp add: cap_range_def) apply (rule conjI) prefer 2 apply (clarsimp simp: obj_at_def a_type_def) apply (clarsimp simp: cte_wp_at_caps_of_state) apply (drule_tac p="(a,b)" in caps_of_state_valid_cap, fastforce) apply (auto simp: obj_at_def is_tcb_def is_cap_table_def valid_cap_def [where c="cap.Zombie a b x" for a b x] dest: obj_ref_is_tcb obj_ref_is_cap_table split: option.splits) done lemma max_index_upd_no_cap_to: "\<lbrace>\<lambda>s. no_cap_to_obj_with_diff_ref cap {slot} s \<and> cte_wp_at (op = ucap) cref s \<and> is_untyped_cap ucap\<rbrace> set_cap (max_free_index_update ucap) cref \<lbrace>\<lambda>rv s. no_cap_to_obj_with_diff_ref cap {slot} s \<rbrace>" apply (clarsimp simp:no_cap_to_obj_with_diff_ref_def) apply (wp hoare_vcg_ball_lift set_cap_cte_wp_at_neg) apply (clarsimp simp:cte_wp_at_caps_of_state free_index_update_def is_cap_simps) apply (drule_tac x = cref in bspec) apply clarsimp apply (clarsimp simp:table_cap_ref_def) done lemma perform_asid_control_invocation_st_tcb_at: "\<lbrace>st_tcb_at (P and (Not \<circ> inactive) and (Not \<circ> idle)) t and ct_active and invs and valid_aci aci\<rbrace> perform_asid_control_invocation aci \<lbrace>\<lambda>y. st_tcb_at P t\<rbrace>" including no_pre apply (clarsimp simp: perform_asid_control_invocation_def split: asid_control_invocation.splits) apply (rename_tac word1 a b aa ba word2) apply (wp hoare_vcg_const_imp_lift retype_region_st_tcb_at set_cap_no_overlap|simp)+ apply (strengthen invs_valid_objs invs_psp_aligned) apply (clarsimp simp:conj_comms) apply (wp max_index_upd_invs_simple get_cap_wp)+ apply (rule hoare_name_pre_state) apply (subgoal_tac "is_aligned word1 page_bits") prefer 2 apply (clarsimp simp: valid_aci_def cte_wp_at_caps_of_state) apply (drule(1) caps_of_state_valid[rotated])+ apply (simp add:valid_cap_simps cap_aligned_def page_bits_def) apply (subst delete_objects_rewrite) apply (simp add:page_bits_def word_bits_def pageBits_def)+ apply (simp add:is_aligned_neg_mask_eq) apply wp apply (clarsimp simp: valid_aci_def) apply (frule intvl_range_conv) apply (simp add:word_bits_def page_bits_def pageBits_def) apply (clarsimp simp:detype_clear_um_independent page_bits_def is_aligned_neg_mask_eq) apply (rule conjI) apply (clarsimp simp:cte_wp_at_caps_of_state) apply (rule pspace_no_overlap_detype) apply (rule caps_of_state_valid_cap) apply (simp add:page_bits_def)+ apply (simp add:invs_valid_objs invs_psp_aligned)+ apply (rule conjI) apply (erule pred_tcb_weakenE, simp) apply (rule conjI) apply (frule st_tcb_ex_cap) apply clarsimp apply (clarsimp split: Structures_A.thread_state.splits) apply (clarsimp simp: ex_nonz_cap_to_def) apply (frule invs_untyped_children) apply (clarsimp simp:cte_wp_at_caps_of_state) apply (erule_tac ptr="(aa,ba)" in untyped_children_in_mdbE[where P="\<lambda>c. t \<in> zobj_refs c" for t]) apply (simp add: cte_wp_at_caps_of_state)+ apply fastforce apply (clarsimp simp: zobj_refs_to_obj_refs) apply (fastforce simp:page_bits_def) apply simp apply (clarsimp simp:obj_bits_api_def arch_kobj_size_def cte_wp_at_caps_of_state default_arch_object_def empty_descendants_range_in) apply (frule_tac cap = "(cap.UntypedCap False word1 pageBits idx)" in detype_invariants[rotated 3],clarsimp+) apply (simp add:cte_wp_at_caps_of_state empty_descendants_range_in descendants_range_def2)+ apply (thin_tac "x = Some cap.NullCap" for x)+ apply (drule(1) caps_of_state_valid_cap[OF _ invs_valid_objs]) apply (intro conjI) apply (clarsimp simp:valid_cap_def cap_aligned_def range_cover_full invs_psp_aligned invs_valid_objs page_bits_def) apply (erule pspace_no_overlap_detype) apply (auto simp:page_bits_def detype_clear_um_independent) done lemma set_cap_idx_up_aligned_area: "\<lbrace>K (\<exists>idx. pcap = UntypedCap dev ptr pageBits idx) and cte_wp_at (op = pcap) slot and valid_objs\<rbrace> set_cap (max_free_index_update pcap) slot \<lbrace>\<lambda>rv s. (\<exists>slot. cte_wp_at (\<lambda>c. up_aligned_area ptr pageBits \<subseteq> cap_range c \<and> cap_is_device c = dev) slot s)\<rbrace>" apply (rule hoare_pre) apply (wp hoare_vcg_ex_lift set_cap_cte_wp_at) apply (rule_tac x = slot in exI) apply clarsimp apply (frule(1) cte_wp_valid_cap) apply (clarsimp simp: cte_wp_at_caps_of_state is_aligned_neg_mask_eq p_assoc_help valid_cap_def valid_untyped_def cap_aligned_def) done primrec(nonexhaustive) get_untyped_cap_idx :: "cap \<Rightarrow> nat" where "get_untyped_cap_idx (UntypedCap dev ref sz idx) = idx" lemma aci_invs': assumes Q_ignores_arch[simp]: "\<And>f s. Q (arch_state_update f s) = Q s" assumes Q_ignore_machine_state[simp]: "\<And>f s. Q (machine_state_update f s) = Q s" assumes Q_detype[simp]: "\<And>f s. Q (detype f s) = Q s" assumes cap_insert_Q: "\<And>cap src dest. \<lbrace>Q and invs and K (src \<noteq> dest)\<rbrace> cap_insert cap src dest \<lbrace>\<lambda>_.Q\<rbrace>" assumes retype_region_Q[wp]:"\<And>a b c d e. \<lbrace>Q\<rbrace> retype_region a b c d e \<lbrace>\<lambda>_.Q\<rbrace>" assumes set_cap_Q[wp]: "\<And>a b. \<lbrace>Q\<rbrace> set_cap a b \<lbrace>\<lambda>_.Q\<rbrace>" shows "\<lbrace>invs and Q and ct_active and valid_aci aci\<rbrace> perform_asid_control_invocation aci \<lbrace>\<lambda>y s. invs s \<and> Q s\<rbrace>" proof - have cap_insert_invsQ: "\<And>cap src dest ap asid. \<lbrace>Q and (invs and valid_cap cap and tcb_cap_valid cap dest and ex_cte_cap_wp_to (appropriate_cte_cap cap) dest and cte_wp_at (\<lambda>c. c = NullCap) dest and no_cap_to_obj_with_diff_ref cap {dest} and (\<lambda>s. cte_wp_at (safe_parent_for (cdt s) src cap) src s) and K (cap = ArchObjectCap (ASIDPoolCap ap asid)) and (\<lambda>s. \<forall>irq\<in>cap_irqs cap. irq_issued irq s) and ko_at (ArchObj (ASIDPool Map.empty)) ap and (\<lambda>s. ap \<notin> ran (arm_asid_table (arch_state s)) \<and> arm_asid_table (arch_state s) (asid_high_bits_of asid) = None))\<rbrace> cap_insert cap src dest \<lbrace>\<lambda>rv s. invs (s\<lparr>arch_state := arch_state s \<lparr>arm_asid_table := (arm_asid_table \<circ> arch_state) s (asid_high_bits_of asid \<mapsto> ap)\<rparr>\<rparr>) \<and> Q (s\<lparr>arch_state := arch_state s \<lparr>arm_asid_table := (arm_asid_table \<circ> arch_state) s (asid_high_bits_of asid \<mapsto> ap)\<rparr>\<rparr>)\<rbrace>" apply (wp cap_insert_ap_invs) apply simp apply (rule hoare_pre) apply (rule cap_insert_Q) apply (auto simp: cte_wp_at_caps_of_state) done show ?thesis apply (clarsimp simp: perform_asid_control_invocation_def valid_aci_def split: asid_control_invocation.splits) apply (rename_tac word1 a b aa ba word2) apply (rule hoare_pre) apply (wp hoare_vcg_const_imp_lift) apply (wp cap_insert_invsQ hoare_vcg_ex_lift | simp)+ apply (simp add: valid_cap_def | strengthen real_cte_tcb_valid safe_parent_strg invs_vobjs_strgs ex_cte_cap_to_cnode_always_appropriate_strg)+ apply (wp hoare_vcg_const_imp_lift set_free_index_invs retype_region_plain_invs[where sz = pageBits] retype_cte_wp_at[where sz = pageBits] hoare_vcg_ex_lift retype_region_obj_at_other3[where P="is_cap_table n" and sz = pageBits for n] retype_region_ex_cte_cap_to[where sz = pageBits] retype_region_ap[simplified] retype_region_ap'[simplified] retype_region_no_cap_to_obj[where sz = pageBits,simplified] | simp del: split_paired_Ex)+ apply (strengthen invs_valid_objs invs_psp_aligned invs_mdb invs_valid_pspace exI[where x="case aci of MakePool frame slot parent base \<Rightarrow> parent"] exI[where x="case aci of MakePool frame slot parent base \<Rightarrow> parent", simplified] caps_region_kernel_window_imp[where p = "case aci of MakePool frame slot parent base \<Rightarrow> parent"] invs_cap_refs_in_kernel_window)+ apply (wp set_cap_caps_no_overlap set_cap_no_overlap get_cap_wp max_index_upd_caps_overlap_reserved max_index_upd_invs_simple set_cap_cte_cap_wp_to set_cap_cte_wp_at max_index_upd_no_cap_to | simp split del: if_split | wp_once hoare_vcg_ex_lift)+ apply (rule_tac P = "is_aligned word1 page_bits" in hoare_gen_asm) apply (subst delete_objects_rewrite) apply (simp add:page_bits_def pageBits_def) apply (simp add:page_bits_def pageBits_def word_bits_def) apply (simp add:is_aligned_neg_mask_eq) apply wp apply (clarsimp simp: cte_wp_at_caps_of_state if_option_Some Word_Miscellaneous.if_bool_simps split del: if_split) apply (strengthen refl) apply (frule_tac cap = "(cap.UntypedCap False word1 pageBits idx)" in detype_invariants[rotated 3],clarsimp+) apply (simp add:cte_wp_at_caps_of_state)+ apply (simp add:descendants_range_def2 empty_descendants_range_in) apply (simp add:invs_mdb invs_valid_pspace invs_psp_aligned invs_valid_objs) apply (clarsimp dest!:caps_of_state_cteD) apply (frule(1) unsafe_protected[where p=t and p'=t for t]) apply (simp add:empty_descendants_range_in)+ apply fastforce apply clarsimp apply (frule_tac p = "(aa,ba)" in cte_wp_valid_cap) apply fastforce apply (clarsimp simp: detype_clear_um_independent obj_bits_api_def arch_kobj_size_def default_arch_object_def conj_comms) apply (rule conjI) apply (clarsimp simp:valid_cap_simps cap_aligned_def page_bits_def not_le) apply clarsimp apply (simp add:empty_descendants_range_in) apply (frule valid_cap_aligned) apply (clarsimp simp: cap_aligned_def is_aligned_neg_mask_eq) apply (subst caps_no_overlap_detype[OF descendants_range_caps_no_overlapI], assumption, simp add: is_aligned_neg_mask_eq, simp add: empty_descendants_range_in) apply (frule pspace_no_overlap_detype, clarify+) apply (frule intvl_range_conv[where bits = pageBits]) apply (simp add:pageBits_def word_bits_def) apply (simp add:is_aligned_neg_mask_eq) apply (clarsimp simp:is_aligned_neg_mask_eq page_bits_def) apply (frule(1) ex_cte_cap_protects) apply (simp add:empty_descendants_range_in) apply fastforce apply (rule subset_refl) apply fastforce apply (clarsimp simp: field_simps) apply (intro conjI impI, simp_all add:free_index_of_def valid_cap_simps valid_untyped_def empty_descendants_range_in range_cover_full clear_um_def max_free_index_def, (clarsimp simp:valid_untyped_def valid_cap_simps)+)[1] apply (erule(1) cap_to_protected) apply (simp add:empty_descendants_range_in descendants_range_def2)+ apply clarsimp apply (drule invs_arch_state)+ apply (clarsimp simp: valid_arch_state_def valid_asid_table_def) apply (drule (1) bspec)+ apply clarsimp apply (erule notE, erule is_aligned_no_overflow) apply (clarsimp simp: no_cap_to_obj_with_diff_ref_def) apply (thin_tac "cte_wp_at (op = cap.NullCap) p s" for p s) apply (subst(asm) eq_commute, erule(1) untyped_children_in_mdbE[where cap="cap.UntypedCap dev p bits idx" for dev p bits idx, simplified, rotated]) apply (simp add: is_aligned_no_overflow) apply simp apply clarsimp done qed lemmas aci_invs[wp] = aci_invs'[where Q=\<top>,simplified hoare_post_taut, OF refl refl refl TrueI TrueI TrueI,simplified] lemma invoke_arch_invs[wp]: "\<lbrace>invs and ct_active and valid_arch_inv ai\<rbrace> arch_perform_invocation ai \<lbrace>\<lambda>rv. invs\<rbrace>" apply (cases ai, simp_all add: valid_arch_inv_def arch_perform_invocation_def) apply (wp|simp)+ done lemma sts_empty_pde [wp]: "\<lbrace>empty_pde_at p\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv. empty_pde_at p\<rbrace>" apply (simp add: empty_pde_at_def) apply (rule hoare_pre) apply (wp hoare_vcg_ex_lift set_thread_state_ko) apply (clarsimp simp: is_tcb_def) done lemma sts_pd_at_asid [wp]: "\<lbrace>vspace_at_asid asid pd\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv. vspace_at_asid asid pd\<rbrace>" apply (simp add: vspace_at_asid_def) apply wp done lemma sts_same_refs_inv[wp]: "\<lbrace>\<lambda>s. same_refs m cap s\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv s. same_refs m cap s\<rbrace>" by (cases m, (clarsimp simp: same_refs_def, wp)+) lemma sts_valid_slots_inv[wp]: "\<lbrace>valid_slots m\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv. valid_slots m\<rbrace>" by (cases m, (clarsimp simp: valid_slots_def, wp hoare_vcg_ball_lift sts.vs_lookup sts_typ_ats)+) lemma sts_valid_page_inv[wp]: "\<lbrace>valid_page_inv page_invocation\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv. valid_page_inv page_invocation\<rbrace>" by (cases page_invocation, (wp hoare_vcg_const_Ball_lift hoare_vcg_ex_lift hoare_vcg_imp_lift sts_typ_ats | clarsimp simp: valid_page_inv_def same_refs_def | wps)+) lemma sts_valid_pdi_inv[wp]: "\<lbrace>valid_pdi page_directory_invocation\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv. valid_pdi page_directory_invocation\<rbrace>" apply (cases page_directory_invocation) apply (wp | simp add: valid_pdi_def)+ done lemma sts_valid_arch_inv: "\<lbrace>valid_arch_inv ai\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv. valid_arch_inv ai\<rbrace>" apply (cases ai, simp_all add: valid_arch_inv_def) apply (rename_tac page_table_invocation) apply (case_tac page_table_invocation, simp_all add: valid_pti_def)[1] apply ((wp valid_pde_lift set_thread_state_valid_cap hoare_vcg_all_lift hoare_vcg_const_imp_lift hoare_vcg_ex_lift set_thread_state_ko sts_typ_ats set_thread_state_cte_wp_at | clarsimp simp: is_tcb_def)+)[4] apply (rename_tac asid_control_invocation) apply (case_tac asid_control_invocation) apply (clarsimp simp: valid_aci_def cte_wp_at_caps_of_state) apply (rule hoare_pre, wp hoare_vcg_ex_lift cap_table_at_typ_at) apply clarsimp apply (clarsimp simp: valid_apinv_def split: asid_pool_invocation.splits) apply (rule hoare_pre) apply (wp hoare_vcg_ex_lift set_thread_state_ko) apply (clarsimp simp: is_tcb_def) done lemma ensure_safe_mapping_inv [wp]: "\<lbrace>P\<rbrace> ensure_safe_mapping m \<lbrace>\<lambda>_. P\<rbrace>" including no_pre apply (cases m, simp_all) apply (case_tac a, simp) apply (case_tac aa, simp_all)[1] apply (wp mapME_x_inv_wp hoare_drop_imps get_pte_wp|wpc|simp)+ apply (case_tac b, simp) apply (case_tac a, simp_all) apply (wp mapME_x_inv_wp hoare_drop_imps get_pde_wp|wpc|simp)+ done (* the induct rule matches the wrong parameters first -> crunch blows up *) lemma create_mapping_entries_inv [wp]: "\<lbrace>P\<rbrace> create_mapping_entries base vptr vmsz R A pd \<lbrace>\<lambda>_. P\<rbrace>" by (induct vmsz; wpsimp wp: lookup_pt_slot_inv) crunch_ignore (add: select_ext) crunch inv [wp]: arch_decode_invocation "P" (wp: crunch_wps select_wp select_ext_weak_wp simp: crunch_simps) lemma create_mappings_empty [wp]: "\<lbrace>\<top>\<rbrace> create_mapping_entries base vptr vmsz R A pd \<lbrace>\<lambda>m s. empty_refs m\<rbrace>, -" by (cases vmsz; wpsimp simp: pde_ref_def empty_refs_def) lemma empty_pde_atI: "\<lbrakk> ko_at (ArchObj (PageDirectory pd)) (p && ~~ mask pd_bits) s; pd (ucast (p && mask pd_bits >> 2)) = InvalidPDE \<rbrakk> \<Longrightarrow> empty_pde_at p s" by (fastforce simp add: empty_pde_at_def) declare lookup_slot_for_cnode_op_cap_to [wp] lemma shiftr_irrelevant: "x < 2 ^ asid_low_bits \<Longrightarrow> is_aligned (y :: word32) asid_low_bits \<Longrightarrow> x + y >> asid_low_bits = y >> asid_low_bits" apply (subst word_plus_and_or_coroll) apply (rule word_eqI) apply (clarsimp simp: is_aligned_nth) apply (drule(1) nth_bounded) apply (simp add: asid_low_bits_def word_bits_def) apply simp apply (rule word_eqI) apply (simp add: nth_shiftr) apply safe apply (drule(1) nth_bounded) apply (simp add: asid_low_bits_def word_bits_def) apply simp done lemma create_mapping_entries_parent_for_refs: "\<lbrace>invs and \<exists>\<rhd> pd and page_directory_at pd and K (is_aligned pd pd_bits) and K (vmsz_aligned vptr pgsz) and K (vptr < kernel_base)\<rbrace> create_mapping_entries ptr vptr pgsz rights attribs pd \<lbrace>\<lambda>rv s. \<exists>a b. cte_wp_at (parent_for_refs rv) (a, b) s\<rbrace>, -" apply (rule hoare_gen_asmE)+ apply (cases pgsz, simp_all add: vmsz_aligned_def) apply (rule hoare_pre) apply wp apply (rule hoare_post_imp_R, rule lookup_pt_slot_cap_to) apply (elim exEI) apply (clarsimp simp: cte_wp_at_caps_of_state parent_for_refs_def) apply simp apply (rule hoare_pre) apply wp apply (rule hoare_post_imp_R) apply (rule lookup_pt_slot_cap_to_multiple1) apply (elim conjE exEI cte_wp_at_weakenE) apply (clarsimp simp: cte_wp_at_caps_of_state parent_for_refs_def subset_iff p_0x3C_shift) apply simp apply (rule hoare_pre, wp) apply (clarsimp dest!:vs_lookup_pages_vs_lookupI) apply (drule valid_vs_lookupD, clarsimp) apply (simp, elim exEI) apply (clarsimp simp: cte_wp_at_caps_of_state parent_for_refs_def lookup_pd_slot_def Let_def) apply (subst pd_shifting, simp add: pd_bits_def pageBits_def) apply (clarsimp simp: vs_cap_ref_def split: cap.split_asm arch_cap.split_asm option.split_asm) apply (auto simp: valid_cap_def obj_at_def is_cap_simps cap_asid_def dest!: caps_of_state_valid_cap split:if_splits)[3] apply (frule(1) caps_of_state_valid) apply (clarsimp simp:valid_cap_def obj_at_def) apply (simp add:is_cap_simps) apply (rule hoare_pre, wp) apply (clarsimp dest!:vs_lookup_pages_vs_lookupI) apply (drule valid_vs_lookupD, clarsimp) apply (simp, elim exEI) apply (clarsimp simp: cte_wp_at_caps_of_state parent_for_refs_def) apply (rule conjI) apply (simp add: subset_eq) apply (subst p_0x3C_shift) apply (simp add: lookup_pd_slot_def Let_def) apply (erule aligned_add_aligned) apply (intro is_aligned_shiftl is_aligned_shiftr) apply simp apply (simp add: pd_bits_def pageBits_def) apply (clarsimp simp: lookup_pd_slot_add_eq) apply (clarsimp simp: vs_cap_ref_def split: cap.split_asm arch_cap.split_asm option.split_asm) apply (auto simp: valid_cap_def obj_at_def is_cap_simps cap_asid_def dest!: caps_of_state_valid_cap split:if_splits)[3] apply (frule(1) caps_of_state_valid) apply (clarsimp simp:valid_cap_def obj_at_def) apply (simp add:is_cap_simps) done lemma find_pd_for_asid_shifting_voodoo: "\<lbrace>pspace_aligned and valid_arch_objs\<rbrace> find_pd_for_asid asid \<lbrace>\<lambda>rv s. v >> 20 = rv + (v >> 20 << 2) && mask pd_bits >> 2\<rbrace>,-" apply (rule hoare_post_imp_R, rule find_pd_for_asid_aligned_pd) apply (subst pd_shifting_dual, simp) apply (rule word_eqI) apply (simp add: nth_shiftr nth_shiftl word_size) apply safe apply (drule test_bit_size) apply (simp add: word_size) done lemma find_pd_for_asid_ref_offset_voodoo: "\<lbrace>pspace_aligned and valid_arch_objs and K (ref = [VSRef (asid && mask asid_low_bits) (Some AASIDPool), VSRef (ucast (asid_high_bits_of asid)) None])\<rbrace> find_pd_for_asid asid \<lbrace>\<lambda>rv. (ref \<rhd> (rv + (v >> 20 << 2) && ~~ mask pd_bits))\<rbrace>,-" apply (rule hoare_gen_asmE) apply (rule_tac Q'="\<lambda>rv s. is_aligned rv 14 \<and> (ref \<rhd> rv) s" in hoare_post_imp_R) apply (simp add: ucast_ucast_mask mask_asid_low_bits_ucast_ucast) apply (fold asid_low_bits_def) apply (rule hoare_pre, wp find_pd_for_asid_lookup_ref) apply simp apply (simp add: pd_shifting) done declare asid_high_bits_of_shift [simp] declare mask_shift [simp] declare word_less_sub_le [simp del] declare ptrFormPAddr_addFromPPtr [simp] (* FIXME: move *) lemma valid_mask_vm_rights[simp]: "mask_vm_rights V R \<in> valid_vm_rights" by (simp add: mask_vm_rights_def) lemma vs_lookup_and_unique_refs: "\<lbrakk>(ref \<rhd> p) s; caps_of_state s cptr = Some cap; table_cap_ref cap = Some ref'; p \<in> obj_refs cap; valid_vs_lookup s; unique_table_refs (caps_of_state s)\<rbrakk> \<Longrightarrow> ref = ref'" apply (frule_tac ref=ref in valid_vs_lookupD[OF vs_lookup_pages_vs_lookupI], assumption) apply clarsimp apply (frule_tac cap'=capa in unique_table_refsD) apply simp+ apply (case_tac capa, simp_all) apply ((case_tac cap, simp_all)+)[6] apply (clarsimp simp add: table_cap_ref_def vs_cap_ref_def split: cap.splits arch_cap.splits option.splits) done lemma valid_global_ptsD2: "\<lbrakk>r \<in> set (arm_global_pts (arch_state s)); valid_global_pts s\<rbrakk> \<Longrightarrow> \<exists>pt. ko_at (ArchObj (PageTable pt)) r s" apply (clarsimp simp: valid_global_pts_def) apply (drule (1) bspec) apply (clarsimp simp: obj_at_def) done lemma create_mapping_entries_same_refs: "\<lbrace>valid_arch_state and valid_arch_objs and valid_vs_lookup and (\<lambda>s. unique_table_refs (caps_of_state s)) and pspace_aligned and valid_objs and valid_kernel_mappings and \<exists>\<rhd> pd and (\<lambda>s. \<exists>pd_cap pd_cptr. cte_wp_at (diminished pd_cap) pd_cptr s \<and> pd_cap = cap.ArchObjectCap (arch_cap.PageDirectoryCap pd (Some asid))) and page_directory_at pd and K (vaddr < kernel_base \<and> (cap = (cap.ArchObjectCap (arch_cap.PageCap dev p rights' pgsz (Some (asid, vaddr))))))\<rbrace> create_mapping_entries (addrFromPPtr p) vaddr pgsz rights attribs pd \<lbrace>\<lambda>rv s. same_refs rv cap s\<rbrace>,-" apply (rule hoare_gen_asmE) apply (cases pgsz, simp_all add: lookup_pt_slot_def) apply (wp get_pde_wp | wpc)+ apply (clarsimp simp: lookup_pd_slot_def) apply (frule (1) pd_aligned) apply (simp add:pd_shifting vaddr_segment_nonsense2) apply (frule (2) valid_arch_objsD[rotated], simp) apply (drule bspec, simp, erule kernel_base_kernel_mapping_slots) apply (simp, drule (1) pt_aligned) apply (clarsimp simp: same_refs_def vs_cap_ref_def split: option.splits) apply (simp add: vaddr_segment_nonsense4 shiftl_shiftr_id less_trans[OF and_mask_less'[where n=8, unfolded mask_def, simplified]] word_bits_def vaddr_segment_nonsense3) apply (rule conjI, simp add: mask_def) apply (clarsimp simp: cte_wp_at_caps_of_state diminished_def mask_cap_def cap_rights_update_def) apply (clarsimp split: Structures_A.cap.splits ) apply (clarsimp simp: acap_rights_update_def split: arch_cap.splits) apply (frule (1) vs_lookup_and_unique_refs) apply (simp_all add: table_cap_ref_def obj_refs_def)[4] apply (frule_tac p=pd and p'="ptrFromPAddr x" in vs_lookup_step) apply (clarsimp simp: vs_lookup1_def) apply (rule exI, erule conjI) apply (rule exI[where x="VSRef (vaddr >> 20) (Some APageDirectory)"]) apply (rule conjI, rule refl) apply (simp add: vs_refs_def) apply (rule_tac x="(ucast (vaddr >> 20), ptrFromPAddr x)" in image_eqI) apply (simp add: ucast_ucast_len[OF shiftr_less_t2n'] mask_32_max_word graph_of_def) apply (clarsimp simp:graph_of_def) apply (frule kernel_base_kernel_mapping_slots, simp add: pde_ref_def) apply simp apply (drule (1) ref_is_unique) apply (rule not_kernel_slot_not_global_pt[rotated]) apply (erule kernel_base_kernel_mapping_slots) apply (simp add: obj_at_def) apply (simp_all add: pde_ref_def valid_arch_state_def valid_objs_caps)[8] apply (wp get_pde_wp | wpc)+ apply (clarsimp simp: lookup_pd_slot_def) apply (frule (1) pd_aligned) apply (simp add:pd_shifting vaddr_segment_nonsense2) apply (frule (2) valid_arch_objsD[rotated], simp) apply (drule bspec, simp, erule kernel_base_kernel_mapping_slots) apply (simp, drule (1) pt_aligned) apply (clarsimp simp: same_refs_def vs_cap_ref_def upto_enum_step_def upto_enum_word upt_conv_Cons) apply (simp add: vaddr_segment_nonsense4 shiftl_shiftr_id less_trans[OF and_mask_less'[where n=8, unfolded mask_def, simplified]] word_bits_def vaddr_segment_nonsense3) apply (rule conjI, simp add: mask_def) apply (clarsimp simp: cte_wp_at_caps_of_state diminished_def mask_cap_def cap_rights_update_def) apply (clarsimp split: Structures_A.cap.splits ) apply (clarsimp simp: acap_rights_update_def split: arch_cap.splits) apply (frule (1) vs_lookup_and_unique_refs) apply (simp_all add: table_cap_ref_def obj_refs_def)[4] apply (frule_tac p=pd and p'="ptrFromPAddr x" in vs_lookup_step) apply (clarsimp simp: vs_lookup1_def) apply (rule exI, erule conjI) apply (rule exI[where x="VSRef (vaddr >> 20) (Some APageDirectory)"]) apply (rule conjI, rule refl) apply (simp add: vs_refs_def) apply (rule_tac x="(ucast (vaddr >> 20), ptrFromPAddr x)" in image_eqI) apply (simp add: ucast_ucast_len[OF shiftr_less_t2n'] mask_32_max_word graph_of_def) apply (clarsimp simp:graph_of_def) apply (frule kernel_base_kernel_mapping_slots, simp add: pde_ref_def) apply simp apply (drule (1) ref_is_unique) apply (rule not_kernel_slot_not_global_pt[rotated]) apply (erule kernel_base_kernel_mapping_slots) apply (simp add: obj_at_def) apply (simp_all add: pde_ref_def valid_arch_state_def valid_objs_caps)[8] apply (wp get_pde_wp returnOKE_R_wp | wpc)+ apply (clarsimp simp: lookup_pd_slot_def) apply (frule (1) pd_aligned) apply (clarsimp simp: same_refs_def vs_cap_ref_def pde_ref_pages_def) apply (simp add: vaddr_segment_nonsense vaddr_segment_nonsense2) apply (clarsimp simp: cte_wp_at_caps_of_state diminished_def mask_cap_def cap_rights_update_def) apply (clarsimp split: Structures_A.cap.splits ) apply (clarsimp simp: acap_rights_update_def split: arch_cap.splits) apply (frule (1) vs_lookup_and_unique_refs) apply (simp_all add: table_cap_ref_def obj_refs_def)[4] apply (drule (1) ref_is_unique) apply (clarsimp simp: valid_arch_state_def obj_at_def dest!:valid_global_ptsD2) apply (simp_all add: valid_arch_state_def valid_objs_caps)[6] apply (wp returnOKE_R_wp | wpc)+ apply (clarsimp simp: lookup_pd_slot_def) apply (frule (1) pd_aligned) apply (clarsimp simp: same_refs_def vs_cap_ref_def pde_ref_pages_def upto_enum_step_def upto_enum_word upt_conv_Cons) apply (simp add: vaddr_segment_nonsense vaddr_segment_nonsense2) apply (clarsimp simp: cte_wp_at_caps_of_state diminished_def mask_cap_def cap_rights_update_def) apply (clarsimp split: Structures_A.cap.splits ) apply (clarsimp simp: acap_rights_update_def split: arch_cap.splits) apply (frule (1) vs_lookup_and_unique_refs) apply (simp_all add: table_cap_ref_def obj_refs_def)[4] apply (drule (1) ref_is_unique) apply (clarsimp dest!: valid_global_ptsD2 simp: obj_at_def a_type_def valid_arch_state_def) apply (simp_all add: valid_arch_state_def valid_objs_caps) done lemma create_mapping_entries_same_refs_ex: "\<lbrace>valid_arch_state and valid_arch_objs and valid_vs_lookup and (\<lambda>s. unique_table_refs (caps_of_state s)) and pspace_aligned and valid_objs and valid_kernel_mappings and \<exists>\<rhd> pd and (\<lambda>s. \<exists>dev pd_cap pd_cptr asid rights'. cte_wp_at (diminished pd_cap) pd_cptr s \<and> pd_cap = cap.ArchObjectCap (arch_cap.PageDirectoryCap pd (Some asid)) \<and> page_directory_at pd s \<and> vaddr < kernel_base \<and> (cap = (cap.ArchObjectCap (arch_cap.PageCap dev p rights' pgsz (Some (asid, vaddr))))))\<rbrace> create_mapping_entries (addrFromPPtr p) vaddr pgsz rights attribs pd \<lbrace>\<lambda>rv s. same_refs rv cap s\<rbrace>,-" apply (clarsimp simp: validE_R_def validE_def valid_def split: sum.split) apply (erule use_validE_R[OF _ create_mapping_entries_same_refs]) apply fastforce done lemma diminished_pd_capD: "diminished (ArchObjectCap (PageDirectoryCap a b)) cap \<Longrightarrow> cap = (ArchObjectCap (PageDirectoryCap a b))" apply (clarsimp simp: diminished_def mask_cap_def cap_rights_update_def) apply (clarsimp simp: acap_rights_update_def split: cap.splits arch_cap.splits) done lemma diminished_pd_self: "diminished (ArchObjectCap (PageDirectoryCap a b)) (ArchObjectCap (PageDirectoryCap a b))" apply (clarsimp simp: diminished_def mask_cap_def cap_rights_update_def) apply (clarsimp simp: acap_rights_update_def split: cap.splits arch_cap.splits) done lemma cte_wp_at_page_cap_weaken: "cte_wp_at (diminished (ArchObjectCap (PageCap dev word seta vmpage_size None))) slot s \<Longrightarrow> cte_wp_at (\<lambda>a. \<exists>dev p R sz m. a = ArchObjectCap (PageCap dev p R sz m)) slot s" apply (clarsimp simp: cte_wp_at_def diminished_def mask_cap_def cap_rights_update_def) apply (clarsimp simp: acap_rights_update_def split: cap.splits arch_cap.splits) done lemma find_pd_for_asid_lookup_pd_wp: "\<lbrace> \<lambda>s. valid_arch_objs s \<and> (\<forall>pd. vspace_at_asid asid pd s \<and> page_directory_at pd s \<and> (\<exists>\<rhd> pd) s \<longrightarrow> Q pd s) \<rbrace> find_pd_for_asid asid \<lbrace> Q \<rbrace>, -" apply (rule hoare_post_imp_R) apply (rule hoare_vcg_conj_lift_R[OF find_pd_for_asid_page_directory]) apply (rule hoare_vcg_conj_lift_R[OF find_pd_for_asid_lookup, simplified]) apply (rule hoare_vcg_conj_lift_R[OF find_pd_for_asid_pd_at_asid, simplified]) apply (wp find_pd_for_asid_inv) apply auto done lemma aligned_sum_less_kernel_base: "vmsz_aligned p sz \<Longrightarrow> (p + 2 ^ pageBitsForSize sz - 1 < kernel_base) = (p < kernel_base)" apply (rule iffI) apply (rule le_less_trans) apply (rule is_aligned_no_overflow) apply (simp add: vmsz_aligned_def) apply simp apply (simp add:field_simps[symmetric]) apply (erule gap_between_aligned) apply (simp add: vmsz_aligned_def)+ apply (case_tac sz,simp_all add:kernel_base_def is_aligned_def)+ done lemma arch_decode_inv_wf[wp]: "\<lbrace>invs and valid_cap (cap.ArchObjectCap arch_cap) and cte_wp_at (diminished (cap.ArchObjectCap arch_cap)) slot and (\<lambda>s. \<forall>x \<in> set excaps. cte_wp_at (diminished (fst x)) (snd x) s)\<rbrace> arch_decode_invocation label args cap_index slot arch_cap excaps \<lbrace>valid_arch_inv\<rbrace>,-" apply (cases arch_cap) apply (rename_tac word1 word2) apply (simp add: arch_decode_invocation_def Let_def split_def cong: if_cong split del: if_split) apply (rule hoare_pre) apply ((wp whenE_throwError_wp check_vp_wpR ensure_empty_stronger select_wp select_ext_weak_wp| wpc| simp add: valid_arch_inv_def valid_apinv_def)+)[1] apply (simp add: valid_arch_inv_def valid_apinv_def) apply (intro allI impI ballI) apply (elim conjE exE) apply simp apply (clarsimp simp: dom_def neq_Nil_conv) apply (thin_tac "Ball S P" for S P)+ apply (clarsimp simp: valid_cap_def) apply (rule conjI) apply (clarsimp simp: obj_at_def) apply (subgoal_tac "ucast (ucast xa + word2) = xa") apply simp apply (simp add: p2_low_bits_max) apply (simp add: is_aligned_nth) apply (subst word_plus_and_or_coroll) apply (rule word_eqI) apply (clarsimp simp: word_size word_bits_def nth_ucast) apply (drule test_bit_size) apply (simp add: word_size asid_low_bits_def) apply (rule word_eqI) apply (clarsimp simp: word_size word_bits_def nth_ucast) apply (auto simp: asid_low_bits_def)[1] apply (rule conjI) apply (clarsimp simp add: cte_wp_at_caps_of_state) apply (rename_tac c c') apply (frule_tac cap=c' in caps_of_state_valid, assumption) apply (drule (1) diminished_is_update) apply (clarsimp simp: is_pd_cap_def cap_rights_update_def acap_rights_update_def) apply (clarsimp simp: word_neq_0_conv) apply (rule conjI) apply (subst field_simps, erule is_aligned_add_less_t2n) apply (simp add: asid_low_bits_def) apply (rule ucast_less[where 'b=10, simplified], simp) apply (simp add: asid_low_bits_def asid_bits_def) apply (simp add: asid_bits_def) apply (drule vs_lookup_atI) apply (subst asid_high_bits_of_add_ucast, assumption) apply assumption apply (simp add: arch_decode_invocation_def Let_def split_def cong: if_cong split del: if_split) apply (rule hoare_pre) apply ((wp whenE_throwError_wp check_vp_wpR ensure_empty_stronger| wpc| simp add: valid_arch_inv_def valid_aci_def is_aligned_shiftl_self)+)[1] apply (rule_tac Q'= "\<lambda>rv. real_cte_at rv and ex_cte_cap_wp_to is_cnode_cap rv and (\<lambda>s. descendants_of (snd (excaps!0)) (cdt s) = {}) and cte_wp_at (\<lambda>c. \<exists>idx. c = (cap.UntypedCap False frame pageBits idx)) (snd (excaps!0)) and (\<lambda>s. arm_asid_table (arch_state s) free = None)" in hoare_post_imp_R) apply (simp add: lookup_target_slot_def) apply wp apply (clarsimp simp: cte_wp_at_def) apply (rule conjI, clarsimp) apply (rule shiftl_less_t2n) apply (rule order_less_le_trans, rule ucast_less, simp) apply (simp add: asid_bits_def asid_low_bits_def) apply (simp add: asid_bits_def) apply (simp split del: if_split) apply (wp ensure_no_children_sp select_ext_weak_wp select_wp whenE_throwError_wp | wpc | simp add: K_bind_def)+ apply clarsimp apply (rule conjI, fastforce) apply (cases excaps, simp) apply (case_tac list, simp) apply clarsimp apply (rule conjI) apply (drule cte_wp_at_norm, clarsimp, drule cte_wp_valid_cap, fastforce)+ apply (clarsimp simp add: diminished_def) apply (rule conjI) apply clarsimp apply (simp add: ex_cte_cap_wp_to_def) apply (rule_tac x=ac in exI) apply (rule_tac x=ba in exI) apply (clarsimp simp add: cte_wp_at_caps_of_state) apply (drule (1) caps_of_state_valid[rotated])+ apply (drule (1) diminished_is_update)+ apply (clarsimp simp: is_cap_simps cap_rights_update_def) apply (clarsimp simp add: cte_wp_at_caps_of_state) apply (drule (1) caps_of_state_valid[rotated])+ apply (drule (1) diminished_is_update)+ apply (clarsimp simp: cap_rights_update_def) apply (clarsimp simp:diminished_def) apply (simp add: arch_decode_invocation_def Let_def split_def cong: if_cong split del: if_split) apply (cases "invocation_type label = ArchInvocationLabel ARMPageMap") apply (rename_tac dev word rights vmpage_size option) apply (simp split del: if_split) apply (rule hoare_pre) apply ((wp whenE_throwError_wp check_vp_wpR hoare_vcg_const_imp_lift_R create_mapping_entries_parent_for_refs find_pd_for_asid_pd_at_asid create_mapping_entries_valid_slots create_mapping_entries_same_refs_ex find_pd_for_asid_lookup_pd_wp | wpc | simp add: valid_arch_inv_def valid_page_inv_def is_pg_cap_def))+ apply (clarsimp simp: neq_Nil_conv invs_arch_objs) apply (frule diminished_cte_wp_at_valid_cap[where p="(a, b)" for a b], clarsimp) apply (frule diminished_cte_wp_at_valid_cap[where p=slot], clarsimp) apply (clarsimp simp: cte_wp_at_caps_of_state mask_cap_def conj_ac diminished_def[where cap="ArchObjectCap (PageCap d x y z w)" for d x y z w] linorder_not_le aligned_sum_less_kernel_base dest!: diminished_pd_capD) apply (clarsimp simp: cap_rights_update_def acap_rights_update_def split: cap.splits arch_cap.splits) apply (auto, auto simp: cte_wp_at_caps_of_state invs_def valid_state_def valid_cap_simps is_arch_update_def is_arch_cap_def cap_master_cap_simps vmsz_aligned_def vs_cap_ref_def cap_aligned_def data_at_def le_mask_iff_lt_2n[where 'a=32, folded word_bits_def, THEN iffD1] ord_eq_le_trans[OF pd_bits_14] elim: is_aligned_weaken split: vmpage_size.split split: if_splits intro!: is_aligned_addrFromPPtr pbfs_atleast_pageBits, (fastforce intro: diminished_pd_self)+)[1] apply (cases "invocation_type label = ArchInvocationLabel ARMPageRemap") apply (rename_tac word rights vmpage_size option) apply (simp split del: if_split) apply (rule hoare_pre) apply ((wp whenE_throwError_wp check_vp_wpR hoare_vcg_const_imp_lift_R create_mapping_entries_parent_for_refs find_pd_for_asid_lookup_pd_wp | wpc | simp add: valid_arch_inv_def valid_page_inv_def | (simp add: cte_wp_at_caps_of_state, wp create_mapping_entries_same_refs_ex hoare_vcg_ex_lift_R))+)[1] apply (clarsimp simp: valid_cap_def cap_aligned_def neq_Nil_conv) apply (frule diminished_cte_wp_at_valid_cap[where p="(a, b)" for a b], clarsimp) apply (clarsimp simp: cte_wp_at_caps_of_state mask_cap_def diminished_def[where cap="ArchObjectCap (PageCap d x y z w)" for d x y z w]) apply (clarsimp simp: cap_rights_update_def acap_rights_update_def split: cap.splits arch_cap.splits) apply (cases slot, auto simp: vmsz_aligned_def mask_def valid_arch_caps_def cte_wp_at_caps_of_state neq_Nil_conv invs_def valid_state_def data_at_def valid_cap_def cap_aligned_def ord_eq_le_trans[OF pd_bits_14] elim: is_aligned_weaken split: if_splits intro!: is_aligned_addrFromPPtr pbfs_atleast_pageBits, fastforce+)[1] apply (cases "invocation_type label = ArchInvocationLabel ARMPageUnmap") apply (simp split del: if_split) apply (rule hoare_pre, wp) apply (clarsimp simp: valid_arch_inv_def valid_page_inv_def) apply (thin_tac "Ball S P" for S P) apply (rule conjI) apply (clarsimp split: option.split) apply (clarsimp simp: valid_cap_def cap_aligned_def) apply (simp add: valid_unmap_def) apply (fastforce simp: vmsz_aligned_def elim: is_aligned_weaken intro!: pbfs_atleast_pageBits) apply (erule cte_wp_at_weakenE) apply (clarsimp simp: is_arch_diminished_def is_cap_simps) apply (cases "isPageFlushLabel (invocation_type label)") apply (simp split del: if_split) apply (rule hoare_pre) apply (wp whenE_throwError_wp static_imp_wp hoare_drop_imps) apply (simp add: valid_arch_inv_def valid_page_inv_def) apply (wp find_pd_for_asid_pd_at_asid | wpc)+ apply (clarsimp simp: valid_cap_def mask_def) apply (simp split del: if_split) apply (cases "invocation_type label = ArchInvocationLabel ARMPageGetAddress") apply (simp split del: if_split) apply (rule hoare_pre, wp) apply (clarsimp simp: valid_arch_inv_def valid_page_inv_def) apply (rule hoare_pre, wp) apply (simp) apply (simp add: arch_decode_invocation_def Let_def split_def is_final_cap_def cong: if_cong split del: if_split) apply (rename_tac word option) apply (rule hoare_pre) apply ((wp whenE_throwError_wp check_vp_wpR get_master_pde_wp hoare_vcg_all_lift_R| wpc| simp add: valid_arch_inv_def valid_pti_def unlessE_whenE vs_cap_ref_def| rule_tac x="fst p" in hoare_imp_eq_substR| wp_once hoare_vcg_ex_lift_R)+)[1] apply (rule_tac Q'="\<lambda>a b. ko_at (ArchObj (PageDirectory pd)) (a + (args ! 0 >> 20 << 2) && ~~ mask pd_bits) b \<longrightarrow> pd (ucast (a + (args ! 0 >> 20 << 2) && mask pd_bits >> 2)) = InvalidPDE \<longrightarrow> L word option p pd a b" for L in hoare_post_imp_R[rotated]) apply (intro impI) apply (erule impE) apply clarsimp apply (erule impE) apply (clarsimp split:pde.splits) apply assumption apply ((wp whenE_throwError_wp hoare_vcg_all_lift_R find_pd_for_asid_lookup_slot [unfolded lookup_pd_slot_def Let_def] find_pd_for_asid_ref_offset_voodoo find_pd_for_asid_shifting_voodoo find_pd_for_asid_inv| wpc| simp add: valid_arch_inv_def valid_pti_def unlessE_whenE empty_pde_atI vs_cap_ref_def| wp_once hoare_drop_imps hoare_vcg_ex_lift_R)+)[6] apply (clarsimp simp: is_cap_simps) apply (rule conjI) apply clarsimp apply (rule conjI, fastforce) apply (rule conjI, fastforce) apply (clarsimp simp: neq_Nil_conv) apply (thin_tac "Ball S P" for S P) apply (rule conjI) apply (clarsimp simp: valid_cap_def cap_aligned_def) apply (rule conjI) apply (drule cte_wp_at_norm, clarsimp, drule cte_wp_valid_cap, fastforce)+ apply (drule (1) diminished_is_update[rotated])+ apply (clarsimp simp add: cap_rights_update_def acap_rights_update_def) apply (clarsimp simp: valid_cap_def cap_aligned_def pt_bits_def pageBits_def linorder_not_le order_le_less_trans[OF word_and_le2]) apply (rule is_aligned_andI2) apply (simp add: is_aligned_mask) apply (rule conjI) apply (clarsimp simp add: cte_wp_at_caps_of_state) apply (drule (1) caps_of_state_valid[rotated]) apply (drule (1) diminished_is_update) apply clarsimp apply (clarsimp simp: cap_master_cap_def is_arch_update_def) apply (clarsimp simp: cap_asid_def cap_rights_update_def acap_rights_update_def is_cap_simps split: option.split) apply (rule conjI, fastforce) apply (rule conjI, fastforce) apply (clarsimp simp: pde_ref_def) apply (frule invs_pd_caps) apply (clarsimp simp: cte_wp_at_caps_of_state) apply (frule (1) caps_of_state_valid[rotated]) apply (drule (1) diminished_is_update) apply (clarsimp simp: cap_rights_update_def acap_rights_update_def valid_cap_def) apply (drule (2) valid_table_caps_ptD) apply (rule conjI, fastforce)+ apply (clarsimp simp: kernel_vsrefs_def) apply (simp add: linorder_not_le, drule minus_one_helper3) apply (drule le_shiftr[where n=20], drule(1) order_trans) apply (simp add: kernel_base_def) apply (clarsimp simp: cte_wp_at_def is_arch_diminished_def is_cap_simps) apply (simp add: arch_decode_invocation_def Let_def split del: if_split) apply (cases "isPDFlushLabel (invocation_type label)") apply (simp split del: if_split) apply (rule hoare_pre) apply (wp whenE_throwError_wp static_imp_wp hoare_drop_imp | wpc | simp)+ apply (simp add: resolve_vaddr_def) apply (wp get_master_pte_wp get_master_pde_wp whenE_throwError_wp | wpc | simp)+ apply (clarsimp simp: valid_arch_inv_def valid_pdi_def)+ apply (rule_tac Q'="\<lambda>pd' s. vspace_at_asid x2 pd' s \<and> x2 \<le> mask asid_bits \<and> x2 \<noteq> 0" in hoare_post_imp_R) apply wp apply clarsimp apply (wp | wpc)+ apply (clarsimp simp: valid_cap_def mask_def) apply (clarsimp, wp throwError_validE_R) done declare word_less_sub_le [simp] crunch pred_tcb_at: perform_page_table_invocation, perform_page_invocation, perform_asid_pool_invocation, perform_page_directory_invocation "pred_tcb_at proj P t" (wp: crunch_wps simp: crunch_simps) lemma arch_pinv_st_tcb_at: "\<lbrace>invs and valid_arch_inv ai and ct_active and st_tcb_at (P and (Not \<circ> inactive) and (Not \<circ> idle)) t\<rbrace> arch_perform_invocation ai \<lbrace>\<lambda>rv. st_tcb_at P t\<rbrace>" apply (cases ai, simp_all add: arch_perform_invocation_def valid_arch_inv_def) apply (wp perform_page_table_invocation_pred_tcb_at, fastforce elim!: pred_tcb_weakenE) apply (wp perform_page_directory_invocation_pred_tcb_at, fastforce elim: pred_tcb_weakenE) apply (wp perform_page_invocation_pred_tcb_at, fastforce elim!: pred_tcb_weakenE) apply (wp perform_asid_control_invocation_st_tcb_at, fastforce elim!: pred_tcb_weakenE) apply (wp perform_asid_pool_invocation_pred_tcb_at, fastforce elim!: pred_tcb_weakenE) done lemma get_cap_diminished: "\<lbrace>valid_objs\<rbrace> get_cap slot \<lbrace>\<lambda>cap. cte_wp_at (diminished cap) slot\<rbrace>" apply (wp get_cap_wp) apply (intro allI impI) apply (simp add: cte_wp_at_caps_of_state diminished_def) apply (frule (1) caps_of_state_valid_cap) apply (clarsimp simp add: valid_cap_def2 wellformed_cap_def mask_cap_def cap_rights_update_def acap_rights_update_def split: cap.splits arch_cap.splits) apply fastforce+ apply (clarsimp simp add: wellformed_acap_def split: cap.splits arch_cap.splits) apply (rename_tac rights vmpage_size option) apply (rule_tac x=rights in exI) apply auto done end context begin interpretation Arch . requalify_consts valid_arch_inv requalify_facts invoke_arch_tcb invoke_arch_invs sts_valid_arch_inv arch_decode_inv_wf arch_pinv_st_tcb_at get_cap_diminished end declare invoke_arch_invs[wp] declare arch_decode_inv_wf[wp] end
%compute speed in the direction perpendicular to tail-central direction function [data,units]=compute_velpertc(trx,n) larvae=trx.exp2flies{n}; numlarvae=numel(larvae); velpertc=cell(1,numlarvae); %tailcentralangperp=cell(1,numlarvae); for i=1:numlarvae larva=larvae(i); %tailcentralangperp{1,i}=trx(larva).tailcentralang-pi/2; velpertc{1,i}=trx(larva).velmag_ctr.*(cos(trx(larva).velang).*cos(trx(larva).tailcentralang(1,1:end-1)+pi/2)+sin(trx(larva).velang).*sin(trx(larva).tailcentralang(1,1:end-1)+pi/2)); end units=parseunits('mm/s'); data=velpertc;
[GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ [PROOFSTEP] have := edist_approxOn_le hf h₀ x n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : edist (↑(approxOn f hf s y₀ h₀ n) x) (f x) ≤ edist y₀ (f x) ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ [PROOFSTEP] rw [edist_comm y₀] at this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : edist (↑(approxOn f hf s y₀ h₀ n) x) (f x) ≤ edist (f x) y₀ ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ [PROOFSTEP] simp only [edist_nndist, nndist_eq_nnnorm] at this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ↑‖f x - y₀‖₊ ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ≤ ‖f x - y₀‖₊ [PROOFSTEP] exact_mod_cast this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ [PROOFSTEP] have := edist_approxOn_y0_le hf h₀ x n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : edist y₀ (↑(approxOn f hf s y₀ h₀ n) x) ≤ edist y₀ (f x) + edist y₀ (f x) ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ [PROOFSTEP] repeat' rw [edist_comm y₀, edist_eq_coe_nnnorm_sub] at this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : edist y₀ (↑(approxOn f hf s y₀ h₀ n) x) ≤ edist y₀ (f x) + edist y₀ (f x) ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ [PROOFSTEP] rw [edist_comm y₀, edist_eq_coe_nnnorm_sub] at this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : ↑‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖₊ ≤ edist y₀ (f x) + edist y₀ (f x) ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ [PROOFSTEP] rw [edist_comm y₀, edist_eq_coe_nnnorm_sub] at this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : ↑‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖₊ ≤ ↑‖f x - y₀‖₊ + ↑‖f x - y₀‖₊ ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ [PROOFSTEP] rw [edist_comm y₀, edist_eq_coe_nnnorm_sub] at this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : ↑‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖₊ ≤ ↑‖f x - y₀‖₊ + ↑‖f x - y₀‖₊ ⊢ ‖↑(approxOn f hf s y₀ h₀ n) x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ [PROOFSTEP] exact_mod_cast this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E h₀ : 0 ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ ⊢ ‖↑(approxOn f hf s 0 h₀ n) x‖ ≤ ‖f x‖ + ‖f x‖ [PROOFSTEP] have := edist_approxOn_y0_le hf h₀ x n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E h₀ : 0 ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : edist 0 (↑(approxOn f hf s 0 h₀ n) x) ≤ edist 0 (f x) + edist 0 (f x) ⊢ ‖↑(approxOn f hf s 0 h₀ n) x‖ ≤ ‖f x‖ + ‖f x‖ [PROOFSTEP] simp [edist_comm (0 : E), edist_eq_coe_nnnorm] at this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E h₀ : 0 ∈ s inst✝ : SeparableSpace ↑s x : β n : ℕ this : ↑‖↑(approxOn f hf s 0 h₀ n) x‖₊ ≤ ↑‖f x‖₊ + ↑‖f x‖₊ ⊢ ‖↑(approxOn f hf s 0 h₀ n) x‖ ≤ ‖f x‖ + ‖f x‖ [PROOFSTEP] exact_mod_cast this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ ⊢ Tendsto (fun n => snorm (↑(approxOn f hf s y₀ h₀ n) - f) p μ) atTop (𝓝 0) [PROOFSTEP] by_cases hp_zero : p = 0 [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : p = 0 ⊢ Tendsto (fun n => snorm (↑(approxOn f hf s y₀ h₀ n) - f) p μ) atTop (𝓝 0) [PROOFSTEP] simpa only [hp_zero, snorm_exponent_zero] using tendsto_const_nhds [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 ⊢ Tendsto (fun n => snorm (↑(approxOn f hf s y₀ h₀ n) - f) p μ) atTop (𝓝 0) [PROOFSTEP] have hp : 0 < p.toReal := toReal_pos hp_zero hp_ne_top [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p ⊢ Tendsto (fun n => snorm (↑(approxOn f hf s y₀ h₀ n) - f) p μ) atTop (𝓝 0) [PROOFSTEP] suffices Tendsto (fun n => ∫⁻ x, (‖approxOn f hf s y₀ h₀ n x - f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) atTop (𝓝 0) by simp only [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_ne_top] convert continuous_rpow_const.continuousAt.tendsto.comp this simp [zero_rpow_of_pos (_root_.inv_pos.mpr hp)] -- We simply check the conditions of the Dominated Convergence Theorem: -- (1) The function "`p`-th power of distance between `f` and the approximation" is measurable [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p this : Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ∂μ) atTop (𝓝 0) ⊢ Tendsto (fun n => snorm (↑(approxOn f hf s y₀ h₀ n) - f) p μ) atTop (𝓝 0) [PROOFSTEP] simp only [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_ne_top] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p this : Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ∂μ) atTop (𝓝 0) ⊢ Tendsto (fun n => (∫⁻ (x : β), ↑‖(↑(approxOn f hf s y₀ h₀ n) - f) x‖₊ ^ ENNReal.toReal p ∂μ) ^ (1 / ENNReal.toReal p)) atTop (𝓝 0) [PROOFSTEP] convert continuous_rpow_const.continuousAt.tendsto.comp this [GOAL] case h.e'_5.h.e'_3 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p this : Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ∂μ) atTop (𝓝 0) ⊢ 0 = 0 ^ (1 / ENNReal.toReal p) [PROOFSTEP] simp [zero_rpow_of_pos (_root_.inv_pos.mpr hp)] -- We simply check the conditions of the Dominated Convergence Theorem: -- (1) The function "`p`-th power of distance between `f` and the approximation" is measurable [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p ⊢ Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ∂μ) atTop (𝓝 0) [PROOFSTEP] have hF_meas : ∀ n, Measurable fun x => (‖approxOn f hf s y₀ h₀ n x - f x‖₊ : ℝ≥0∞) ^ p.toReal := by simpa only [← edist_eq_coe_nnnorm_sub] using fun n => (approxOn f hf s y₀ h₀ n).measurable_bind (fun y x => edist y (f x) ^ p.toReal) fun y => (measurable_edist_right.comp hf).pow_const p.toReal [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p ⊢ ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p [PROOFSTEP] simpa only [← edist_eq_coe_nnnorm_sub] using fun n => (approxOn f hf s y₀ h₀ n).measurable_bind (fun y x => edist y (f x) ^ p.toReal) fun y => (measurable_edist_right.comp hf).pow_const p.toReal [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p hF_meas : ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ⊢ Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ∂μ) atTop (𝓝 0) [PROOFSTEP] have h_bound : ∀ n, (fun x => (‖approxOn f hf s y₀ h₀ n x - f x‖₊ : ℝ≥0∞) ^ p.toReal) ≤ᵐ[μ] fun x => (‖f x - y₀‖₊ : ℝ≥0∞) ^ p.toReal := fun n => eventually_of_forall fun x => rpow_le_rpow (coe_mono (nnnorm_approxOn_le hf h₀ x n)) toReal_nonneg [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p hF_meas : ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p h_bound : ∀ (n : ℕ), (fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p) ≤ᵐ[μ] fun x => ↑‖f x - y₀‖₊ ^ ENNReal.toReal p ⊢ Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ∂μ) atTop (𝓝 0) [PROOFSTEP] have h_fin : (∫⁻ a : β, (‖f a - y₀‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) ≠ ⊤ := (lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_ne_top hi).ne [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p hF_meas : ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p h_bound : ∀ (n : ℕ), (fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p) ≤ᵐ[μ] fun x => ↑‖f x - y₀‖₊ ^ ENNReal.toReal p h_fin : ∫⁻ (a : β), ↑‖f a - y₀‖₊ ^ ENNReal.toReal p ∂μ ≠ ⊤ ⊢ Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ∂μ) atTop (𝓝 0) [PROOFSTEP] have h_lim : ∀ᵐ a : β ∂μ, Tendsto (fun n => (‖approxOn f hf s y₀ h₀ n a - f a‖₊ : ℝ≥0∞) ^ p.toReal) atTop (𝓝 0) := by filter_upwards [hμ] with a ha have : Tendsto (fun n => (approxOn f hf s y₀ h₀ n) a - f a) atTop (𝓝 (f a - f a)) := (tendsto_approxOn hf h₀ ha).sub tendsto_const_nhds convert continuous_rpow_const.continuousAt.tendsto.comp (tendsto_coe.mpr this.nnnorm) simp [zero_rpow_of_pos hp] -- Then we apply the Dominated Convergence Theorem [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p hF_meas : ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p h_bound : ∀ (n : ℕ), (fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p) ≤ᵐ[μ] fun x => ↑‖f x - y₀‖₊ ^ ENNReal.toReal p h_fin : ∫⁻ (a : β), ↑‖f a - y₀‖₊ ^ ENNReal.toReal p ∂μ ≠ ⊤ ⊢ ∀ᵐ (a : β) ∂μ, Tendsto (fun n => ↑‖↑(approxOn f hf s y₀ h₀ n) a - f a‖₊ ^ ENNReal.toReal p) atTop (𝓝 0) [PROOFSTEP] filter_upwards [hμ] with a ha [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p hF_meas : ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p h_bound : ∀ (n : ℕ), (fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p) ≤ᵐ[μ] fun x => ↑‖f x - y₀‖₊ ^ ENNReal.toReal p h_fin : ∫⁻ (a : β), ↑‖f a - y₀‖₊ ^ ENNReal.toReal p ∂μ ≠ ⊤ a : β ha : f a ∈ closure s ⊢ Tendsto (fun n => ↑‖↑(approxOn f hf s y₀ h₀ n) a - f a‖₊ ^ ENNReal.toReal p) atTop (𝓝 0) [PROOFSTEP] have : Tendsto (fun n => (approxOn f hf s y₀ h₀ n) a - f a) atTop (𝓝 (f a - f a)) := (tendsto_approxOn hf h₀ ha).sub tendsto_const_nhds [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p hF_meas : ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p h_bound : ∀ (n : ℕ), (fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p) ≤ᵐ[μ] fun x => ↑‖f x - y₀‖₊ ^ ENNReal.toReal p h_fin : ∫⁻ (a : β), ↑‖f a - y₀‖₊ ^ ENNReal.toReal p ∂μ ≠ ⊤ a : β ha : f a ∈ closure s this : Tendsto (fun n => ↑(approxOn f hf s y₀ h₀ n) a - f a) atTop (𝓝 (f a - f a)) ⊢ Tendsto (fun n => ↑‖↑(approxOn f hf s y₀ h₀ n) a - f a‖₊ ^ ENNReal.toReal p) atTop (𝓝 0) [PROOFSTEP] convert continuous_rpow_const.continuousAt.tendsto.comp (tendsto_coe.mpr this.nnnorm) [GOAL] case h.e'_5.h.e'_3 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p hF_meas : ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p h_bound : ∀ (n : ℕ), (fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p) ≤ᵐ[μ] fun x => ↑‖f x - y₀‖₊ ^ ENNReal.toReal p h_fin : ∫⁻ (a : β), ↑‖f a - y₀‖₊ ^ ENNReal.toReal p ∂μ ≠ ⊤ a : β ha : f a ∈ closure s this : Tendsto (fun n => ↑(approxOn f hf s y₀ h₀ n) a - f a) atTop (𝓝 (f a - f a)) ⊢ 0 = ↑‖f a - f a‖₊ ^ ENNReal.toReal p [PROOFSTEP] simp [zero_rpow_of_pos hp] -- Then we apply the Dominated Convergence Theorem [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hp_ne_top : p ≠ ⊤ μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : snorm (fun x => f x - y₀) p μ < ⊤ hp_zero : ¬p = 0 hp : 0 < ENNReal.toReal p hF_meas : ∀ (n : ℕ), Measurable fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p h_bound : ∀ (n : ℕ), (fun x => ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p) ≤ᵐ[μ] fun x => ↑‖f x - y₀‖₊ ^ ENNReal.toReal p h_fin : ∫⁻ (a : β), ↑‖f a - y₀‖₊ ^ ENNReal.toReal p ∂μ ≠ ⊤ h_lim : ∀ᵐ (a : β) ∂μ, Tendsto (fun n => ↑‖↑(approxOn f hf s y₀ h₀ n) a - f a‖₊ ^ ENNReal.toReal p) atTop (𝓝 0) ⊢ Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ^ ENNReal.toReal p ∂μ) atTop (𝓝 0) [PROOFSTEP] simpa using tendsto_lintegral_of_dominated_convergence _ hF_meas h_bound h_fin h_lim [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ ⊢ Memℒp (↑(approxOn f fmeas s y₀ h₀ n)) p [PROOFSTEP] refine' ⟨(approxOn f fmeas s y₀ h₀ n).aestronglyMeasurable, _⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ ⊢ snorm (↑(approxOn f fmeas s y₀ h₀ n)) p μ < ⊤ [PROOFSTEP] suffices snorm (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ < ⊤ by have : Memℒp (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ := ⟨(approxOn f fmeas s y₀ h₀ n - const β y₀).aestronglyMeasurable, this⟩ convert snorm_add_lt_top this hi₀ ext x simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ this : snorm (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p μ < ⊤ ⊢ snorm (↑(approxOn f fmeas s y₀ h₀ n)) p μ < ⊤ [PROOFSTEP] have : Memℒp (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ := ⟨(approxOn f fmeas s y₀ h₀ n - const β y₀).aestronglyMeasurable, this⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ this✝ : snorm (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p μ < ⊤ this : Memℒp (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p ⊢ snorm (↑(approxOn f fmeas s y₀ h₀ n)) p μ < ⊤ [PROOFSTEP] convert snorm_add_lt_top this hi₀ [GOAL] case h.e'_3.h.e'_5 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ this✝ : snorm (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p μ < ⊤ this : Memℒp (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p ⊢ ↑(approxOn f fmeas s y₀ h₀ n) = (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) + fun x => y₀ [PROOFSTEP] ext x [GOAL] case h.e'_3.h.e'_5.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ this✝ : snorm (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p μ < ⊤ this : Memℒp (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p x : β ⊢ ↑(approxOn f fmeas s y₀ h₀ n) x = ((fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) + fun x => y₀) x [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ ⊢ snorm (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p μ < ⊤ [PROOFSTEP] have hf' : Memℒp (fun x => ‖f x - y₀‖) p μ := by have h_meas : Measurable fun x => ‖f x - y₀‖ := by simp only [← dist_eq_norm] exact (continuous_id.dist continuous_const).measurable.comp fmeas refine' ⟨h_meas.aemeasurable.aestronglyMeasurable, _⟩ rw [snorm_norm] convert snorm_add_lt_top hf hi₀.neg with x simp [sub_eq_add_neg] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ ⊢ Memℒp (fun x => ‖f x - y₀‖) p [PROOFSTEP] have h_meas : Measurable fun x => ‖f x - y₀‖ := by simp only [← dist_eq_norm] exact (continuous_id.dist continuous_const).measurable.comp fmeas [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ ⊢ Measurable fun x => ‖f x - y₀‖ [PROOFSTEP] simp only [← dist_eq_norm] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ ⊢ Measurable fun x => dist (f x) y₀ [PROOFSTEP] exact (continuous_id.dist continuous_const).measurable.comp fmeas [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ h_meas : Measurable fun x => ‖f x - y₀‖ ⊢ Memℒp (fun x => ‖f x - y₀‖) p [PROOFSTEP] refine' ⟨h_meas.aemeasurable.aestronglyMeasurable, _⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ h_meas : Measurable fun x => ‖f x - y₀‖ ⊢ snorm (fun x => ‖f x - y₀‖) p μ < ⊤ [PROOFSTEP] rw [snorm_norm] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ h_meas : Measurable fun x => ‖f x - y₀‖ ⊢ snorm (fun x => f x - y₀) p μ < ⊤ [PROOFSTEP] convert snorm_add_lt_top hf hi₀.neg with x [GOAL] case h.e'_3.h.e'_5.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ h_meas : Measurable fun x => ‖f x - y₀‖ x : β ⊢ f x - y₀ = (f + -fun x => y₀) x [PROOFSTEP] simp [sub_eq_add_neg] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ hf' : Memℒp (fun x => ‖f x - y₀‖) p ⊢ snorm (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p μ < ⊤ [PROOFSTEP] have : ∀ᵐ x ∂μ, ‖approxOn f fmeas s y₀ h₀ n x - y₀‖ ≤ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ := by refine' eventually_of_forall _ intro x convert norm_approxOn_y₀_le fmeas h₀ x n using 1 rw [Real.norm_eq_abs, abs_of_nonneg] exact add_nonneg (norm_nonneg _) (norm_nonneg _) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ hf' : Memℒp (fun x => ‖f x - y₀‖) p ⊢ ∀ᵐ (x : β) ∂μ, ‖↑(approxOn f fmeas s y₀ h₀ n) x - y₀‖ ≤ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ [PROOFSTEP] refine' eventually_of_forall _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ hf' : Memℒp (fun x => ‖f x - y₀‖) p ⊢ ∀ (x : β), ‖↑(approxOn f fmeas s y₀ h₀ n) x - y₀‖ ≤ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ [PROOFSTEP] intro x [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ hf' : Memℒp (fun x => ‖f x - y₀‖) p x : β ⊢ ‖↑(approxOn f fmeas s y₀ h₀ n) x - y₀‖ ≤ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ [PROOFSTEP] convert norm_approxOn_y₀_le fmeas h₀ x n using 1 [GOAL] case h.e'_4 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ hf' : Memℒp (fun x => ‖f x - y₀‖) p x : β ⊢ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ = ‖f x - y₀‖ + ‖f x - y₀‖ [PROOFSTEP] rw [Real.norm_eq_abs, abs_of_nonneg] [GOAL] case h.e'_4 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ hf' : Memℒp (fun x => ‖f x - y₀‖) p x : β ⊢ 0 ≤ ‖f x - y₀‖ + ‖f x - y₀‖ [PROOFSTEP] exact add_nonneg (norm_nonneg _) (norm_nonneg _) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f p s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) p n : ℕ hf' : Memℒp (fun x => ‖f x - y₀‖) p this : ∀ᵐ (x : β) ∂μ, ‖↑(approxOn f fmeas s y₀ h₀ n) x - y₀‖ ≤ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ ⊢ snorm (fun x => ↑(approxOn f fmeas s y₀ h₀ n) x - y₀) p μ < ⊤ [PROOFSTEP] calc snorm (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ ≤ snorm (fun x => ‖f x - y₀‖ + ‖f x - y₀‖) p μ := snorm_mono_ae this _ < ⊤ := snorm_add_lt_top hf' hf' [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : snorm f p μ < ⊤ n : ℕ ⊢ 0 ∈ Set.range f ∪ {0} [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : snorm f p μ < ⊤ ⊢ Tendsto (fun n => snorm (↑(approxOn f fmeas (Set.range f ∪ {0}) 0 (_ : 0 ∈ Set.range f ∪ {0}) n) - f) p μ) atTop (𝓝 0) [PROOFSTEP] refine' tendsto_approxOn_Lp_snorm fmeas _ hp_ne_top _ _ [GOAL] case refine'_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : snorm f p μ < ⊤ ⊢ ∀ᵐ (x : β) ∂μ, f x ∈ closure (Set.range f ∪ {0}) [PROOFSTEP] apply eventually_of_forall [GOAL] case refine'_1.hp α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : snorm f p μ < ⊤ ⊢ ∀ (x : β), f x ∈ closure (Set.range f ∪ {0}) [PROOFSTEP] intro x [GOAL] case refine'_1.hp α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : snorm f p μ < ⊤ x : β ⊢ f x ∈ closure (Set.range f ∪ {0}) [PROOFSTEP] apply subset_closure [GOAL] case refine'_1.hp.a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : snorm f p μ < ⊤ x : β ⊢ f x ∈ Set.range f ∪ {0} [PROOFSTEP] simp [GOAL] case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : snorm f p μ < ⊤ ⊢ snorm (fun x => f x - 0) p μ < ⊤ [PROOFSTEP] simpa using hf [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : Memℒp f p n : ℕ ⊢ 0 ∈ Set.range f ∪ {0} [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : Memℒp f p n : ℕ ⊢ 0 ∈ Set.range f ∪ {0} [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : Memℒp f p n : ℕ ⊢ 0 ∈ Set.range f ∪ {0} [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace β inst✝⁴ : MeasurableSpace E inst✝³ : NormedAddCommGroup E inst✝² : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ inst✝¹ : BorelSpace E f : β → E hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : Memℒp f p ⊢ Tendsto (fun n => Memℒp.toLp ↑(approxOn f fmeas (Set.range f ∪ {0}) 0 (_ : 0 ∈ Set.range f ∪ {0}) n) (_ : Memℒp (↑(approxOn f fmeas (Set.range f ∪ {0}) 0 (_ : 0 ∈ Set.range f ∪ {0}) n)) p)) atTop (𝓝 (Memℒp.toLp f hf)) [PROOFSTEP] simpa only [Lp.tendsto_Lp_iff_tendsto_ℒp''] using tendsto_approxOn_range_Lp_snorm hp_ne_top fmeas hf.2 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 ⊢ ∃ g, snorm (f - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] borelize E [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E ⊢ ∃ g, snorm (f - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] let f' := hf.1.mk f [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) ⊢ ∃ g, snorm (f - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] rsuffices ⟨g, hg, g_mem⟩ : ∃ g : β →ₛ E, snorm (f' - ⇑g) p μ < ε ∧ Memℒp g p μ [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) g : β →ₛ E hg : snorm (f' - ↑g) p μ < ε g_mem : Memℒp (↑g) p ⊢ ∃ g, snorm (f - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] refine' ⟨g, _, g_mem⟩ [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) g : β →ₛ E hg : snorm (f' - ↑g) p μ < ε g_mem : Memℒp (↑g) p ⊢ snorm (f - ↑g) p μ < ε [PROOFSTEP] suffices snorm (f - ⇑g) p μ = snorm (f' - ⇑g) p μ by rwa [this] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) g : β →ₛ E hg : snorm (f' - ↑g) p μ < ε g_mem : Memℒp (↑g) p this : snorm (f - ↑g) p μ = snorm (f' - ↑g) p μ ⊢ snorm (f - ↑g) p μ < ε [PROOFSTEP] rwa [this] [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) g : β →ₛ E hg : snorm (f' - ↑g) p μ < ε g_mem : Memℒp (↑g) p ⊢ snorm (f - ↑g) p μ = snorm (f' - ↑g) p μ [PROOFSTEP] apply snorm_congr_ae [GOAL] case intro.intro.hfg α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) g : β →ₛ E hg : snorm (f' - ↑g) p μ < ε g_mem : Memℒp (↑g) p ⊢ f - ↑g =ᵐ[μ] f' - ↑g [PROOFSTEP] filter_upwards [hf.1.ae_eq_mk] with x hx [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) g : β →ₛ E hg : snorm (f' - ↑g) p μ < ε g_mem : Memℒp (↑g) p x : β hx : f x = AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) x ⊢ (f - ↑g) x = (AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) - ↑g) x [PROOFSTEP] simpa only [Pi.sub_apply, sub_left_inj] using hx [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) ⊢ ∃ g, snorm (f' - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] have hf' : Memℒp f' p μ := hf.ae_eq hf.1.ae_eq_mk [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) hf' : Memℒp f' p ⊢ ∃ g, snorm (f' - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] have f'meas : Measurable f' := hf.1.measurable_mk [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) hf' : Memℒp f' p f'meas : Measurable f' ⊢ ∃ g, snorm (f' - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] have : SeparableSpace (range f' ∪ {0} : Set E) := StronglyMeasurable.separableSpace_range_union_singleton hf.1.stronglyMeasurable_mk [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) hf' : Memℒp f' p f'meas : Measurable f' this : SeparableSpace ↑(Set.range f' ∪ {0}) ⊢ ∃ g, snorm (f' - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] rcases((tendsto_approxOn_range_Lp_snorm hp_ne_top f'meas hf'.2).eventually <| gt_mem_nhds hε.bot_lt).exists with ⟨n, hn⟩ [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) hf' : Memℒp f' p f'meas : Measurable f' this : SeparableSpace ↑(Set.range f' ∪ {0}) n : ℕ hn : snorm (↑(approxOn f' f'meas (Set.range f' ∪ {0}) 0 (_ : 0 ∈ Set.range f' ∪ {0}) n) - f') p μ < ε ⊢ ∃ g, snorm (f' - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] rw [← snorm_neg, neg_sub] at hn [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 E✝ : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E✝ inst✝² : NormedAddCommGroup E✝ inst✝¹ : NormedAddCommGroup F q : ℝ p : ℝ≥0∞ E : Type u_7 inst✝ : NormedAddCommGroup E f : β → E μ : Measure β hf : Memℒp f p hp_ne_top : p ≠ ⊤ ε : ℝ≥0∞ hε : ε ≠ 0 this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f' : β → E := AEStronglyMeasurable.mk f (_ : AEStronglyMeasurable f μ) hf' : Memℒp f' p f'meas : Measurable f' this : SeparableSpace ↑(Set.range f' ∪ {0}) n : ℕ hn : snorm (f' - ↑(approxOn f' f'meas (Set.range f' ∪ {0}) 0 (_ : 0 ∈ Set.range f' ∪ {0}) n)) p μ < ε ⊢ ∃ g, snorm (f' - ↑g) p μ < ε ∧ Memℒp (↑g) p [PROOFSTEP] exact ⟨_, hn, memℒp_approxOn_range f'meas hf' _⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : HasFiniteIntegral fun x => f x - y₀ ⊢ Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f hf s y₀ h₀ n) x - f x‖₊ ∂μ) atTop (𝓝 0) [PROOFSTEP] simpa [snorm_one_eq_lintegral_nnnorm] using tendsto_approxOn_Lp_snorm hf h₀ one_ne_top hμ (by simpa [snorm_one_eq_lintegral_nnnorm] using hi) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E hf : Measurable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s μ : Measure β hμ : ∀ᵐ (x : β) ∂μ, f x ∈ closure s hi : HasFiniteIntegral fun x => f x - y₀ ⊢ snorm (fun x => f x - y₀) 1 μ < ⊤ [PROOFSTEP] simpa [snorm_one_eq_lintegral_nnnorm] using hi [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Integrable f s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Integrable fun x => y₀ n : ℕ ⊢ Integrable ↑(approxOn f fmeas s y₀ h₀ n) [PROOFSTEP] rw [← memℒp_one_iff_integrable] at hf hi₀ ⊢ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f hf : Memℒp f 1 s : Set E y₀ : E h₀ : y₀ ∈ s inst✝ : SeparableSpace ↑s hi₀ : Memℒp (fun x => y₀) 1 n : ℕ ⊢ Memℒp (↑(approxOn f fmeas s y₀ h₀ n)) 1 [PROOFSTEP] exact memℒp_approxOn fmeas hf h₀ hi₀ n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E μ : Measure β inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) fmeas : Measurable f hf : Integrable f n : ℕ x : β ⊢ 0 ∈ Set.range f ∪ {0} [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E μ : Measure β inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) fmeas : Measurable f hf : Integrable f ⊢ Tendsto (fun n => ∫⁻ (x : β), ↑‖↑(approxOn f fmeas (Set.range f ∪ {0}) 0 (_ : 0 ∈ Set.range f ∪ {0}) n) x - f x‖₊ ∂μ) atTop (𝓝 0) [PROOFSTEP] apply tendsto_approxOn_L1_nnnorm fmeas [GOAL] case hμ α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E μ : Measure β inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) fmeas : Measurable f hf : Integrable f ⊢ ∀ᵐ (x : β) ∂μ, f x ∈ closure (Set.range f ∪ {0}) [PROOFSTEP] apply eventually_of_forall [GOAL] case hμ.hp α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E μ : Measure β inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) fmeas : Measurable f hf : Integrable f ⊢ ∀ (x : β), f x ∈ closure (Set.range f ∪ {0}) [PROOFSTEP] intro x [GOAL] case hμ.hp α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E μ : Measure β inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) fmeas : Measurable f hf : Integrable f x : β ⊢ f x ∈ closure (Set.range f ∪ {0}) [PROOFSTEP] apply subset_closure [GOAL] case hμ.hp.a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E μ : Measure β inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) fmeas : Measurable f hf : Integrable f x : β ⊢ f x ∈ Set.range f ∪ {0} [PROOFSTEP] simp [GOAL] case hi α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : OpensMeasurableSpace E f : β → E μ : Measure β inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) fmeas : Measurable f hf : Integrable f ⊢ HasFiniteIntegral fun x => f x - 0 [PROOFSTEP] simpa using hf.2 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁴ : MeasurableSpace β inst✝³ : MeasurableSpace E inst✝² : NormedAddCommGroup E inst✝¹ : BorelSpace E f : β → E μ : Measure β fmeas : Measurable f inst✝ : SeparableSpace ↑(Set.range f ∪ {0}) hf : Integrable f n : ℕ ⊢ 0 ∈ Set.range f ∪ {0} [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ✝ : Measure α p✝ : ℝ≥0∞ p : ℝ f : α →ₛ F μ : Measure α ⊢ snorm' (↑f) p μ = (∑ y in SimpleFunc.range f, ↑‖y‖₊ ^ p * ↑↑μ (↑f ⁻¹' {y})) ^ (1 / p) [PROOFSTEP] have h_map : (fun a => (‖f a‖₊ : ℝ≥0∞) ^ p) = f.map fun a : F => (‖a‖₊ : ℝ≥0∞) ^ p := by simp; rfl [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ✝ : Measure α p✝ : ℝ≥0∞ p : ℝ f : α →ₛ F μ : Measure α ⊢ (fun a => ↑‖↑f a‖₊ ^ p) = ↑(map (fun a => ↑‖a‖₊ ^ p) f) [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ✝ : Measure α p✝ : ℝ≥0∞ p : ℝ f : α →ₛ F μ : Measure α ⊢ (fun a => ↑‖↑f a‖₊ ^ p) = (fun a => ↑‖a‖₊ ^ p) ∘ ↑f [PROOFSTEP] rfl [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ✝ : Measure α p✝ : ℝ≥0∞ p : ℝ f : α →ₛ F μ : Measure α h_map : (fun a => ↑‖↑f a‖₊ ^ p) = ↑(map (fun a => ↑‖a‖₊ ^ p) f) ⊢ snorm' (↑f) p μ = (∑ y in SimpleFunc.range f, ↑‖y‖₊ ^ p * ↑↑μ (↑f ⁻¹' {y})) ^ (1 / p) [PROOFSTEP] rw [snorm', h_map, lintegral_eq_lintegral, map_lintegral] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] have hp_pos_real : 0 < p.toReal := ENNReal.toReal_pos hp_pos hp_ne_top [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] have hf_snorm := Memℒp.snorm_lt_top hf [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : snorm (↑f) p μ < ⊤ ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] rw [snorm_eq_snorm' hp_pos hp_ne_top, f.snorm'_eq, ← @ENNReal.lt_rpow_one_div_iff _ _ (1 / p.toReal) (by simp [hp_pos_real]), @ENNReal.top_rpow_of_pos (1 / (1 / p.toReal)) (by simp [hp_pos_real]), ENNReal.sum_lt_top_iff] at hf_snorm [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : (∑ y in SimpleFunc.range f, ↑‖y‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {y})) ^ (1 / ENNReal.toReal p) < ⊤ ⊢ 0 < 1 / ENNReal.toReal p [PROOFSTEP] simp [hp_pos_real] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∑ y in SimpleFunc.range f, ↑‖y‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {y}) < ⊤ ^ (1 / (1 / ENNReal.toReal p)) ⊢ 0 < 1 / (1 / ENNReal.toReal p) [PROOFSTEP] simp [hp_pos_real] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] by_cases hyf : y ∈ f.range [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : y ∈ SimpleFunc.range f ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] swap [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] suffices h_empty : f ⁻¹' { y } = ∅ [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f h_empty : ↑f ⁻¹' {y} = ∅ ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] rw [h_empty, measure_empty] [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f h_empty : ↑f ⁻¹' {y} = ∅ ⊢ 0 < ⊤ [PROOFSTEP] exact ENNReal.coe_lt_top [GOAL] case h_empty α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f ⊢ ↑f ⁻¹' {y} = ∅ [PROOFSTEP] ext1 x [GOAL] case h_empty.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f x : α ⊢ x ∈ ↑f ⁻¹' {y} ↔ x ∈ ∅ [PROOFSTEP] rw [Set.mem_preimage, Set.mem_singleton_iff, mem_empty_iff_false, iff_false_iff] [GOAL] case h_empty.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f x : α ⊢ ¬↑f x = y [PROOFSTEP] refine' fun hxy => hyf _ [GOAL] case h_empty.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f x : α hxy : ↑f x = y ⊢ y ∈ SimpleFunc.range f [PROOFSTEP] rw [mem_range, Set.mem_range] [GOAL] case h_empty.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : ¬y ∈ SimpleFunc.range f x : α hxy : ↑f x = y ⊢ ∃ y_1, ↑f y_1 = y [PROOFSTEP] exact ⟨x, hxy⟩ [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hf_snorm : ∀ (a : E), a ∈ SimpleFunc.range f → ↑‖a‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {a}) < ⊤ hyf : y ∈ SimpleFunc.range f ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] specialize hf_snorm y hyf [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {y}) < ⊤ ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] rw [ENNReal.mul_lt_top_iff] at hf_snorm [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p < ⊤ ∧ ↑↑μ (↑f ⁻¹' {y}) < ⊤ ∨ ↑‖y‖₊ ^ ENNReal.toReal p = 0 ∨ ↑↑μ (↑f ⁻¹' {y}) = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] cases hf_snorm with | inl hf_snorm => exact hf_snorm.2 | inr hf_snorm => cases hf_snorm with | inl hf_snorm => refine' absurd _ hy_ne simpa [hp_pos_real] using hf_snorm | inr hf_snorm => simp [hf_snorm] [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p < ⊤ ∧ ↑↑μ (↑f ⁻¹' {y}) < ⊤ ∨ ↑‖y‖₊ ^ ENNReal.toReal p = 0 ∨ ↑↑μ (↑f ⁻¹' {y}) = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] cases hf_snorm with | inl hf_snorm => exact hf_snorm.2 | inr hf_snorm => cases hf_snorm with | inl hf_snorm => refine' absurd _ hy_ne simpa [hp_pos_real] using hf_snorm | inr hf_snorm => simp [hf_snorm] [GOAL] case pos.inl α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p < ⊤ ∧ ↑↑μ (↑f ⁻¹' {y}) < ⊤ ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] | inl hf_snorm => exact hf_snorm.2 [GOAL] case pos.inl α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p < ⊤ ∧ ↑↑μ (↑f ⁻¹' {y}) < ⊤ ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] exact hf_snorm.2 [GOAL] case pos.inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p = 0 ∨ ↑↑μ (↑f ⁻¹' {y}) = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] | inr hf_snorm => cases hf_snorm with | inl hf_snorm => refine' absurd _ hy_ne simpa [hp_pos_real] using hf_snorm | inr hf_snorm => simp [hf_snorm] [GOAL] case pos.inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p = 0 ∨ ↑↑μ (↑f ⁻¹' {y}) = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] cases hf_snorm with | inl hf_snorm => refine' absurd _ hy_ne simpa [hp_pos_real] using hf_snorm | inr hf_snorm => simp [hf_snorm] [GOAL] case pos.inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p = 0 ∨ ↑↑μ (↑f ⁻¹' {y}) = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] cases hf_snorm with | inl hf_snorm => refine' absurd _ hy_ne simpa [hp_pos_real] using hf_snorm | inr hf_snorm => simp [hf_snorm] [GOAL] case pos.inr.inl α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] | inl hf_snorm => refine' absurd _ hy_ne simpa [hp_pos_real] using hf_snorm [GOAL] case pos.inr.inl α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] refine' absurd _ hy_ne [GOAL] case pos.inr.inl α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑‖y‖₊ ^ ENNReal.toReal p = 0 ⊢ y = 0 [PROOFSTEP] simpa [hp_pos_real] using hf_snorm [GOAL] case pos.inr.inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑↑μ (↑f ⁻¹' {y}) = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] | inr hf_snorm => simp [hf_snorm] [GOAL] case pos.inr.inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ f : α →ₛ E hf : Memℒp (↑f) p y : E hy_ne : y ≠ 0 hp_pos_real : 0 < ENNReal.toReal p hyf : y ∈ SimpleFunc.range f hf_snorm : ↑↑μ (↑f ⁻¹' {y}) = 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] simp [hf_snorm] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ ⊢ Memℒp (↑f) p [PROOFSTEP] by_cases hp0 : p = 0 [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : p = 0 ⊢ Memℒp (↑f) p [PROOFSTEP] rw [hp0, memℒp_zero_iff_aestronglyMeasurable] [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : p = 0 ⊢ AEStronglyMeasurable (↑f) μ [PROOFSTEP] exact f.aestronglyMeasurable [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 ⊢ Memℒp (↑f) p [PROOFSTEP] by_cases hp_top : p = ∞ [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : p = ⊤ ⊢ Memℒp (↑f) p [PROOFSTEP] rw [hp_top] [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : p = ⊤ ⊢ Memℒp ↑f ⊤ [PROOFSTEP] exact memℒp_top f μ [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : ¬p = ⊤ ⊢ Memℒp (↑f) p [PROOFSTEP] refine' ⟨f.aestronglyMeasurable, _⟩ [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : ¬p = ⊤ ⊢ snorm (↑f) p μ < ⊤ [PROOFSTEP] rw [snorm_eq_snorm' hp0 hp_top, f.snorm'_eq] [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : ¬p = ⊤ ⊢ (∑ y in SimpleFunc.range f, ↑‖y‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {y})) ^ (1 / ENNReal.toReal p) < ⊤ [PROOFSTEP] refine' ENNReal.rpow_lt_top_of_nonneg (by simp) (ENNReal.sum_lt_top_iff.mpr fun y _ => _).ne [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : ¬p = ⊤ ⊢ 0 ≤ 1 / ENNReal.toReal p [PROOFSTEP] simp [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : ¬p = ⊤ y : E x✝ : y ∈ SimpleFunc.range f ⊢ ↑‖y‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] by_cases hy0 : y = 0 [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : ¬p = ⊤ y : E x✝ : y ∈ SimpleFunc.range f hy0 : y = 0 ⊢ ↑‖y‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] simp [hy0, ENNReal.toReal_pos hp0 hp_top] [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : ¬p = ⊤ y : E x✝ : y ∈ SimpleFunc.range f hy0 : ¬y = 0 ⊢ ↑‖y‖₊ ^ ENNReal.toReal p * ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] refine' ENNReal.mul_lt_top _ (hf y hy0).ne [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p✝ p : ℝ≥0∞ f : α →ₛ E hf : ∀ (y : E), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ hp0 : ¬p = 0 hp_top : ¬p = ⊤ y : E x✝ : y ∈ SimpleFunc.range f hy0 : ¬y = 0 ⊢ ↑‖y‖₊ ^ ENNReal.toReal p ≠ ⊤ [PROOFSTEP] exact (ENNReal.rpow_lt_top_of_nonneg ENNReal.toReal_nonneg ENNReal.coe_ne_top).ne [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ f : α →ₛ E g : α →ₛ F ⊢ Integrable ↑f → Integrable ↑g → Integrable ↑(pair f g) [PROOFSTEP] simpa only [integrable_iff_finMeasSupp] using FinMeasSupp.pair [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ inst✝ : Zero β f : α →ₛ β hf : ∀ (y : β), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ ⊢ ↑↑μ (support ↑f) < ⊤ [PROOFSTEP] rw [support_eq] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ inst✝ : Zero β f : α →ₛ β hf : ∀ (y : β), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ ⊢ ↑↑μ (⋃ (y : β) (_ : y ∈ filter (fun y => y ≠ 0) (SimpleFunc.range f)), ↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] refine' (measure_biUnion_finset_le _ _).trans_lt (ENNReal.sum_lt_top_iff.mpr fun y hy => _) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ inst✝ : Zero β f : α →ₛ β hf : ∀ (y : β), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ y : β hy : y ∈ filter (fun y => y ≠ 0) (SimpleFunc.range f) ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] rw [Finset.mem_filter] at hy [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ inst✝ : Zero β f : α →ₛ β hf : ∀ (y : β), y ≠ 0 → ↑↑μ (↑f ⁻¹' {y}) < ⊤ y : β hy : y ∈ SimpleFunc.range f ∧ y ≠ 0 ⊢ ↑↑μ (↑f ⁻¹' {y}) < ⊤ [PROOFSTEP] exact hf y hy.2 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ c : E hc : c ≠ 0 s : Set α hs : MeasurableSet s hcs : Memℒp (↑(piecewise s hs (const α c) (const α 0))) p ⊢ ↑↑μ s < ⊤ [PROOFSTEP] have : Function.support (const α c) = Set.univ := Function.support_const hc [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F μ : Measure α p : ℝ≥0∞ hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ c : E hc : c ≠ 0 s : Set α hs : MeasurableSet s hcs : Memℒp (↑(piecewise s hs (const α c) (const α 0))) p this : support ↑(const α c) = Set.univ ⊢ ↑↑μ s < ⊤ [PROOFSTEP] simpa only [memℒp_iff_finMeasSupp hp_pos hp_ne_top, finMeasSupp_iff_support, support_indicator, Set.inter_univ, this] using hcs [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α ⊢ ∀ {a b : { x // x ∈ Lp E p }}, a ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} → b ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} → a + b ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} [PROOFSTEP] rintro f g ⟨s, hs⟩ ⟨t, ht⟩ [GOAL] case intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ Lp E p } s : α →ₛ E hs : AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f t : α →ₛ E ht : AEEqFun.mk ↑t (_ : AEStronglyMeasurable (↑t) μ) = ↑g ⊢ f + g ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} [PROOFSTEP] use s + t [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ Lp E p } s : α →ₛ E hs : AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f t : α →ₛ E ht : AEEqFun.mk ↑t (_ : AEStronglyMeasurable (↑t) μ) = ↑g ⊢ AEEqFun.mk ↑(s + t) (_ : AEStronglyMeasurable (↑(s + t)) μ) = ↑(f + g) [PROOFSTEP] simp only [← hs, ← ht, AEEqFun.mk_add_mk, AddSubgroup.coe_add, AEEqFun.mk_eq_mk, SimpleFunc.coe_add] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α ⊢ ∀ {x : { x // x ∈ Lp E p }}, x ∈ { toAddSubsemigroup := { carrier := {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f}, add_mem' := (_ : ∀ {f g : { x // x ∈ Lp E p }}, f ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} → g ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} → f + g ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f}) }, zero_mem' := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑0) }.toAddSubsemigroup.carrier → -x ∈ { toAddSubsemigroup := { carrier := {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f}, add_mem' := (_ : ∀ {f g : { x // x ∈ Lp E p }}, f ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} → g ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} → f + g ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f}) }, zero_mem' := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑0) }.toAddSubsemigroup.carrier [PROOFSTEP] rintro f ⟨s, hs⟩ [GOAL] case intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ Lp E p } s : α →ₛ E hs : AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f ⊢ -f ∈ { toAddSubsemigroup := { carrier := {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f}, add_mem' := (_ : ∀ {f g : { x // x ∈ Lp E p }}, f ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} → g ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f} → f + g ∈ {f | ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f}) }, zero_mem' := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑0) }.toAddSubsemigroup.carrier [PROOFSTEP] use-s [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ Lp E p } s : α →ₛ E hs : AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f ⊢ AEEqFun.mk ↑(-s) (_ : AEStronglyMeasurable (↑(-s)) μ) = ↑(-f) [PROOFSTEP] simp only [← hs, AEEqFun.neg_mk, SimpleFunc.coe_neg, AEEqFun.mk_eq_mk, AddSubgroup.coe_neg] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } ⊢ k • ↑f ∈ simpleFunc E p μ [PROOFSTEP] rcases f with ⟨f, ⟨s, hs⟩⟩ [GOAL] case mk.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ Lp E p } s : α →ₛ E hs : AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f ⊢ k • ↑{ val := f, property := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f) } ∈ simpleFunc E p μ [PROOFSTEP] use k • s [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ Lp E p } s : α →ₛ E hs : AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f ⊢ AEEqFun.mk ↑(k • s) (_ : AEStronglyMeasurable (↑(k • s)) μ) = ↑(k • ↑{ val := f, property := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f) }) [PROOFSTEP] apply Eq.trans (AEEqFun.smul_mk k s s.aestronglyMeasurable).symm _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ Lp E p } s : α →ₛ E hs : AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f ⊢ k • AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑(k • ↑{ val := f, property := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f) }) [PROOFSTEP] rw [hs] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ Lp E p } s : α →ₛ E hs : AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f ⊢ k • ↑f = ↑(k • ↑{ val := f, property := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑f) }) [PROOFSTEP] rfl [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E f : { x // x ∈ simpleFunc E p μ } ⊢ 1 • f = f [PROOFSTEP] ext1 [GOAL] case a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E f : { x // x ∈ simpleFunc E p μ } ⊢ ↑(1 • f) = ↑f [PROOFSTEP] exact one_smul _ _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E x y : 𝕜 f : { x // x ∈ simpleFunc E p μ } ⊢ (x * y) • f = x • y • f [PROOFSTEP] ext1 [GOAL] case a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E x y : 𝕜 f : { x // x ∈ simpleFunc E p μ } ⊢ ↑((x * y) • f) = ↑(x • y • f) [PROOFSTEP] exact mul_smul _ _ _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E x : 𝕜 ⊢ x • 0 = 0 [PROOFSTEP] ext1 [GOAL] case a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E x : 𝕜 ⊢ ↑(x • 0) = ↑0 [PROOFSTEP] exact smul_zero _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E x : 𝕜 f g : { x // x ∈ simpleFunc E p μ } ⊢ x • (f + g) = x • f + x • g [PROOFSTEP] ext1 [GOAL] case a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E x : 𝕜 f g : { x // x ∈ simpleFunc E p μ } ⊢ ↑(x • (f + g)) = ↑(x • f + x • g) [PROOFSTEP] exact smul_add _ _ _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E x y : 𝕜 f : { x // x ∈ simpleFunc E p μ } ⊢ (x + y) • f = x • f + y • f [PROOFSTEP] ext1 [GOAL] case a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E x y : 𝕜 f : { x // x ∈ simpleFunc E p μ } ⊢ ↑((x + y) • f) = ↑(x • f + y • f) [PROOFSTEP] exact add_smul _ _ _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E f : { x // x ∈ simpleFunc E p μ } ⊢ 0 • f = 0 [PROOFSTEP] ext1 [GOAL] case a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E f : { x // x ∈ simpleFunc E p μ } ⊢ ↑(0 • f) = ↑0 [PROOFSTEP] exact zero_smul _ _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : α →ₛ E hf : Memℒp (↑f) p hg : Memℒp (↑g) p ⊢ toLp (f - g) (_ : Memℒp (↑f - fun a => ↑g a) p) = toLp f hf - toLp g hg [PROOFSTEP] simp only [sub_eq_add_neg, ← toLp_neg, ← toLp_add] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } ⊢ ↑(toSimpleFunc f) =ᵐ[μ] ↑↑↑f [PROOFSTEP] convert (AEEqFun.coeFn_mk (toSimpleFunc f) (toSimpleFunc f).aestronglyMeasurable).symm using 2 [GOAL] case h.e'_5.h.e'_6 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } ⊢ ↑↑f = AEEqFun.mk ↑(toSimpleFunc f) (_ : AEStronglyMeasurable (↑(toSimpleFunc f)) μ) [PROOFSTEP] exact (Classical.choose_spec f.2).symm [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : α →ₛ E hfi : Memℒp (↑f) p ⊢ ↑(toSimpleFunc (toLp f hfi)) =ᵐ[μ] ↑f [PROOFSTEP] rw [← AEEqFun.mk_eq_mk] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : α →ₛ E hfi : Memℒp (↑f) p ⊢ AEEqFun.mk ↑(toSimpleFunc (toLp f hfi)) ?m.1694293 = AEEqFun.mk ↑f ?m.1694294 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : α →ₛ E hfi : Memℒp (↑f) p ⊢ AEStronglyMeasurable (↑(toSimpleFunc (toLp f hfi))) μ α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : α →ₛ E hfi : Memℒp (↑f) p ⊢ AEStronglyMeasurable (↑f) μ [PROOFSTEP] exact Classical.choose_spec (toLp f hfi).2 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α ⊢ ↑(toSimpleFunc 0) =ᵐ[μ] 0 [PROOFSTEP] filter_upwards [toSimpleFunc_eq_toFun (0 : Lp.simpleFunc E p μ), Lp.coeFn_zero E 1 μ] with _ h₁ _ [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α a✝¹ : α h₁ : ↑(toSimpleFunc 0) a✝¹ = ↑↑↑0 a✝¹ a✝ : ↑↑0 a✝¹ = OfNat.ofNat 0 a✝¹ ⊢ ↑(toSimpleFunc 0) a✝¹ = OfNat.ofNat 0 a✝¹ [PROOFSTEP] rwa [h₁] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } ⊢ ↑(toSimpleFunc (f + g)) =ᵐ[μ] ↑(toSimpleFunc f) + ↑(toSimpleFunc g) [PROOFSTEP] filter_upwards [toSimpleFunc_eq_toFun (f + g), toSimpleFunc_eq_toFun f, toSimpleFunc_eq_toFun g, Lp.coeFn_add (f : Lp E p μ) g] with _ [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (f + g)) a✝ = ↑↑↑(f + g) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑↑(↑f + ↑g) a✝ = (↑↑↑f + ↑↑↑g) a✝ → ↑(toSimpleFunc (f + g)) a✝ = (↑(toSimpleFunc f) + ↑(toSimpleFunc g)) a✝ [PROOFSTEP] simp only [AddSubgroup.coe_add, Pi.add_apply] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ → ↑(toSimpleFunc (f + g)) a✝ = ↑(toSimpleFunc f) a✝ + ↑(toSimpleFunc g) a✝ [PROOFSTEP] iterate 4 intro h; rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ → ↑(toSimpleFunc (f + g)) a✝ = ↑(toSimpleFunc f) a✝ + ↑(toSimpleFunc g) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h : ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ ⊢ ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ → ↑(toSimpleFunc (f + g)) a✝ = ↑(toSimpleFunc f) a✝ + ↑(toSimpleFunc g) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h : ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ ⊢ ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑(toSimpleFunc f) a✝ + ↑(toSimpleFunc g) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝ : ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ h : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ ⊢ ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑(toSimpleFunc f) a✝ + ↑(toSimpleFunc g) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝ : ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ h : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ ⊢ ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑(toSimpleFunc g) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝¹ : ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ h✝ : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ h : ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ ⊢ ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑(toSimpleFunc g) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝¹ : ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ h✝ : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ h : ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ ⊢ ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ → ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝² : ↑(toSimpleFunc (f + g)) a✝ = ↑(↑↑f + ↑↑g) a✝ h✝¹ : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ h✝ : ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ h : ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ ⊢ ↑(↑↑f + ↑↑g) a✝ = ↑↑↑f a✝ + ↑↑↑g a✝ [PROOFSTEP] rw [h] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } ⊢ ↑(toSimpleFunc (-f)) =ᵐ[μ] -↑(toSimpleFunc f) [PROOFSTEP] filter_upwards [toSimpleFunc_eq_toFun (-f), toSimpleFunc_eq_toFun f, Lp.coeFn_neg (f : Lp E p μ)] with _ [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (-f)) a✝ = ↑↑↑(-f) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑↑(-↑f) a✝ = (-↑↑↑f) a✝ → ↑(toSimpleFunc (-f)) a✝ = (-↑(toSimpleFunc f)) a✝ [PROOFSTEP] simp only [Pi.neg_apply, AddSubgroup.coe_neg] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (-f)) a✝ = ↑(-↑↑f) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(-↑↑f) a✝ = -↑↑↑f a✝ → ↑(toSimpleFunc (-f)) a✝ = -↑(toSimpleFunc f) a✝ [PROOFSTEP] repeat intro h; rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (-f)) a✝ = ↑(-↑↑f) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(-↑↑f) a✝ = -↑↑↑f a✝ → ↑(toSimpleFunc (-f)) a✝ = -↑(toSimpleFunc f) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } a✝ : α h : ↑(toSimpleFunc (-f)) a✝ = ↑(-↑↑f) a✝ ⊢ ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(-↑↑f) a✝ = -↑↑↑f a✝ → ↑(toSimpleFunc (-f)) a✝ = -↑(toSimpleFunc f) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } a✝ : α h : ↑(toSimpleFunc (-f)) a✝ = ↑(-↑↑f) a✝ ⊢ ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(-↑↑f) a✝ = -↑↑↑f a✝ → ↑(-↑↑f) a✝ = -↑(toSimpleFunc f) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } a✝ : α h✝ : ↑(toSimpleFunc (-f)) a✝ = ↑(-↑↑f) a✝ h : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ ⊢ ↑(-↑↑f) a✝ = -↑↑↑f a✝ → ↑(-↑↑f) a✝ = -↑(toSimpleFunc f) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } a✝ : α h✝ : ↑(toSimpleFunc (-f)) a✝ = ↑(-↑↑f) a✝ h : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ ⊢ ↑(-↑↑f) a✝ = -↑↑↑f a✝ → ↑(-↑↑f) a✝ = -↑↑↑f a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f : { x // x ∈ simpleFunc E p μ } a✝ : α h✝¹ : ↑(toSimpleFunc (-f)) a✝ = ↑(-↑↑f) a✝ h✝ : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ h : ↑(-↑↑f) a✝ = -↑↑↑f a✝ ⊢ ↑(-↑↑f) a✝ = -↑↑↑f a✝ [PROOFSTEP] rw [h] [GOAL] [PROOFSTEP] intro h [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } ⊢ ↑(toSimpleFunc (f - g)) =ᵐ[μ] ↑(toSimpleFunc f) - ↑(toSimpleFunc g) [PROOFSTEP] filter_upwards [toSimpleFunc_eq_toFun (f - g), toSimpleFunc_eq_toFun f, toSimpleFunc_eq_toFun g, Lp.coeFn_sub (f : Lp E p μ) g] with _ [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (f - g)) a✝ = ↑↑↑(f - g) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑↑(↑f - ↑g) a✝ = (↑↑↑f - ↑↑↑g) a✝ → ↑(toSimpleFunc (f - g)) a✝ = (↑(toSimpleFunc f) - ↑(toSimpleFunc g)) a✝ [PROOFSTEP] simp only [AddSubgroup.coe_sub, Pi.sub_apply] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ → ↑(toSimpleFunc (f - g)) a✝ = ↑(toSimpleFunc f) a✝ - ↑(toSimpleFunc g) a✝ [PROOFSTEP] repeat' intro h; rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ → ↑(toSimpleFunc (f - g)) a✝ = ↑(toSimpleFunc f) a✝ - ↑(toSimpleFunc g) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h : ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ ⊢ ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ → ↑(toSimpleFunc (f - g)) a✝ = ↑(toSimpleFunc f) a✝ - ↑(toSimpleFunc g) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h : ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ ⊢ ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑(toSimpleFunc f) a✝ - ↑(toSimpleFunc g) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝ : ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ h : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ ⊢ ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑(toSimpleFunc f) a✝ - ↑(toSimpleFunc g) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝ : ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ h : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ ⊢ ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑(toSimpleFunc g) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝¹ : ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ h✝ : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ h : ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ ⊢ ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑(toSimpleFunc g) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝¹ : ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ h✝ : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ h : ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ ⊢ ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ → ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α f g : { x // x ∈ simpleFunc E p μ } a✝ : α h✝² : ↑(toSimpleFunc (f - g)) a✝ = ↑(↑↑f - ↑↑g) a✝ h✝¹ : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ h✝ : ↑(toSimpleFunc g) a✝ = ↑↑↑g a✝ h : ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ ⊢ ↑(↑↑f - ↑↑g) a✝ = ↑↑↑f a✝ - ↑↑↑g a✝ [PROOFSTEP] rw [h] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } ⊢ ↑(toSimpleFunc (k • f)) =ᵐ[μ] k • ↑(toSimpleFunc f) [PROOFSTEP] filter_upwards [toSimpleFunc_eq_toFun (k • f), toSimpleFunc_eq_toFun f, Lp.coeFn_smul k (f : Lp E p μ)] with _ [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (k • f)) a✝ = ↑↑↑(k • f) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑↑(k • ↑f) a✝ = (k • ↑↑↑f) a✝ → ↑(toSimpleFunc (k • f)) a✝ = (k • ↑(toSimpleFunc f)) a✝ [PROOFSTEP] simp only [Pi.smul_apply, coe_smul] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (k • f)) a✝ = ↑↑(k • ↑f) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ → ↑(toSimpleFunc (k • f)) a✝ = k • ↑(toSimpleFunc f) a✝ [PROOFSTEP] repeat intro h; rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } a✝ : α ⊢ ↑(toSimpleFunc (k • f)) a✝ = ↑↑(k • ↑f) a✝ → ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ → ↑(toSimpleFunc (k • f)) a✝ = k • ↑(toSimpleFunc f) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } a✝ : α h : ↑(toSimpleFunc (k • f)) a✝ = ↑↑(k • ↑f) a✝ ⊢ ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ → ↑(toSimpleFunc (k • f)) a✝ = k • ↑(toSimpleFunc f) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } a✝ : α h : ↑(toSimpleFunc (k • f)) a✝ = ↑↑(k • ↑f) a✝ ⊢ ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ → ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ → ↑↑(k • ↑f) a✝ = k • ↑(toSimpleFunc f) a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } a✝ : α h✝ : ↑(toSimpleFunc (k • f)) a✝ = ↑↑(k • ↑f) a✝ h : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ ⊢ ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ → ↑↑(k • ↑f) a✝ = k • ↑(toSimpleFunc f) a✝ [PROOFSTEP] rw [h] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } a✝ : α h✝ : ↑(toSimpleFunc (k • f)) a✝ = ↑↑(k • ↑f) a✝ h : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ ⊢ ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ → ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ [PROOFSTEP] intro h [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁵ : MeasurableSpace α inst✝⁴ : NormedAddCommGroup E inst✝³ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝² : NormedRing 𝕜 inst✝¹ : Module 𝕜 E inst✝ : BoundedSMul 𝕜 E k : 𝕜 f : { x // x ∈ simpleFunc E p μ } a✝ : α h✝¹ : ↑(toSimpleFunc (k • f)) a✝ = ↑↑(k • ↑f) a✝ h✝ : ↑(toSimpleFunc f) a✝ = ↑↑↑f a✝ h : ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ ⊢ ↑↑(k • ↑f) a✝ = k • ↑↑↑f a✝ [PROOFSTEP] rw [h] [GOAL] [PROOFSTEP] intro h [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝⁶ : MeasurableSpace α inst✝⁵ : NormedAddCommGroup E inst✝⁴ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝³ : NormedRing 𝕜 inst✝² : Module 𝕜 E inst✝¹ : BoundedSMul 𝕜 E inst✝ : Fact (1 ≤ p) f : { x // x ∈ simpleFunc E p μ } ⊢ ‖f‖ = ENNReal.toReal (snorm (↑(toSimpleFunc f)) p μ) [PROOFSTEP] simpa [toLp_toSimpleFunc] using norm_toLp (toSimpleFunc f) (simpleFunc.memℒp f) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) f : { x // x ∈ simpleFunc E p μ } ⊢ P f [PROOFSTEP] suffices ∀ f : α →ₛ E, ∀ hf : Memℒp f p μ, P (toLp f hf) by rw [← toLp_toSimpleFunc f] apply this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) f : { x // x ∈ simpleFunc E p μ } this : ∀ (f : α →ₛ E) (hf : Memℒp (↑f) p), P (toLp f hf) ⊢ P f [PROOFSTEP] rw [← toLp_toSimpleFunc f] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) f : { x // x ∈ simpleFunc E p μ } this : ∀ (f : α →ₛ E) (hf : Memℒp (↑f) p), P (toLp f hf) ⊢ P (toLp (toSimpleFunc f) (_ : Memℒp (↑(toSimpleFunc f)) p)) [PROOFSTEP] apply this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) f : { x // x ∈ simpleFunc E p μ } ⊢ ∀ (f : α →ₛ E) (hf : Memℒp (↑f) p), P (toLp f hf) [PROOFSTEP] clear f [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) ⊢ ∀ (f : α →ₛ E) (hf : Memℒp (↑f) p), P (toLp f hf) [PROOFSTEP] apply SimpleFunc.induction [GOAL] case h_ind α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) ⊢ ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hf : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p), P (toLp (SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) hf) [PROOFSTEP] intro c s hs hf [GOAL] case h_ind α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) c : E s : Set α hs : MeasurableSet s hf : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p ⊢ P (toLp (SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) hf) [PROOFSTEP] by_cases hc : c = 0 [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) c : E s : Set α hs : MeasurableSet s hf : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c = 0 ⊢ P (toLp (SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) hf) [PROOFSTEP] convert h_ind 0 MeasurableSet.empty (by simp) using 1 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) c : E s : Set α hs : MeasurableSet s hf : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c = 0 ⊢ ↑↑μ ∅ < ⊤ [PROOFSTEP] simp [GOAL] case h.e'_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) c : E s : Set α hs : MeasurableSet s hf : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c = 0 ⊢ toLp (SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) hf = indicatorConst p (_ : MeasurableSet ∅) (_ : ↑↑μ ∅ ≠ ⊤) 0 [PROOFSTEP] ext1 [GOAL] case h.e'_1.a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) c : E s : Set α hs : MeasurableSet s hf : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c = 0 ⊢ ↑(toLp (SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) hf) = ↑(indicatorConst p (_ : MeasurableSet ∅) (_ : ↑↑μ ∅ ≠ ⊤) 0) [PROOFSTEP] simp [hc] [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) c : E s : Set α hs : MeasurableSet s hf : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : ¬c = 0 ⊢ P (toLp (SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) hf) [PROOFSTEP] exact h_ind c hs (SimpleFunc.measure_lt_top_of_memℒp_indicator hp_pos hp_ne_top hc hs hf) [GOAL] case h_add α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) ⊢ ∀ ⦃f g : α →ₛ E⦄, Disjoint (support ↑f) (support ↑g) → (∀ (hf : Memℒp (↑f) p), P (toLp f hf)) → (∀ (hf : Memℒp (↑g) p), P (toLp g hf)) → ∀ (hf : Memℒp (↑(f + g)) p), P (toLp (f + g) hf) [PROOFSTEP] intro f g hfg hf hg hfg' [GOAL] case h_add α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) f g : α →ₛ E hfg : Disjoint (support ↑f) (support ↑g) hf : ∀ (hf : Memℒp (↑f) p), P (toLp f hf) hg : ∀ (hf : Memℒp (↑g) p), P (toLp g hf) hfg' : Memℒp (↑(f + g)) p ⊢ P (toLp (f + g) hfg') [PROOFSTEP] obtain ⟨hf', hg'⟩ : Memℒp f p μ ∧ Memℒp g p μ := (memℒp_add_of_disjoint hfg f.stronglyMeasurable g.stronglyMeasurable).mp hfg' [GOAL] case h_add.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝² : MeasurableSpace α inst✝¹ : NormedAddCommGroup E inst✝ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α hp_pos : p ≠ 0 hp_ne_top : p ≠ ⊤ P : { x // x ∈ simpleFunc E p μ } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P (indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P (toLp f hf) → P (toLp g hg) → P (toLp f hf + toLp g hg) f g : α →ₛ E hfg : Disjoint (support ↑f) (support ↑g) hf : ∀ (hf : Memℒp (↑f) p), P (toLp f hf) hg : ∀ (hf : Memℒp (↑g) p), P (toLp g hf) hfg' : Memℒp (↑(f + g)) p hf' : Memℒp (↑f) p hg' : Memℒp (↑g) p ⊢ P (toLp (f + g) hfg') [PROOFSTEP] exact h_add hf' hg' hfg (hf hf') (hg hg') [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ ⊢ DenseEmbedding Subtype.val [PROOFSTEP] borelize E [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E ⊢ DenseEmbedding Subtype.val [PROOFSTEP] apply simpleFunc.uniformEmbedding.denseEmbedding [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E ⊢ DenseRange Subtype.val [PROOFSTEP] intro f [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f : { x // x ∈ Lp E p } ⊢ f ∈ closure (Set.range Subtype.val) [PROOFSTEP] rw [mem_closure_iff_seq_limit] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f : { x // x ∈ Lp E p } ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range Subtype.val) ∧ Tendsto x atTop (𝓝 f) [PROOFSTEP] have hfi' : Memℒp f p μ := Lp.memℒp f [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f : { x // x ∈ Lp E p } hfi' : Memℒp (↑↑f) p ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range Subtype.val) ∧ Tendsto x atTop (𝓝 f) [PROOFSTEP] haveI : SeparableSpace (range f ∪ {0} : Set E) := (Lp.stronglyMeasurable f).separableSpace_range_union_singleton [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f : { x // x ∈ Lp E p } hfi' : Memℒp (↑↑f) p this : SeparableSpace ↑(Set.range ↑↑f ∪ {0}) ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range Subtype.val) ∧ Tendsto x atTop (𝓝 f) [PROOFSTEP] refine' ⟨fun n => toLp (SimpleFunc.approxOn f (Lp.stronglyMeasurable f).measurable (range f ∪ {0}) 0 _ n) (SimpleFunc.memℒp_approxOn_range (Lp.stronglyMeasurable f).measurable hfi' n), fun n => mem_range_self _, _⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f : { x // x ∈ Lp E p } hfi' : Memℒp (↑↑f) p this : SeparableSpace ↑(Set.range ↑↑f ∪ {0}) ⊢ Tendsto (fun n => ↑(toLp (SimpleFunc.approxOn ↑↑f (_ : Measurable ↑↑f) (Set.range ↑↑f ∪ {0}) 0 (_ : 0 ∈ Set.range ↑↑f ∪ {0}) n) (_ : Memℒp (↑(SimpleFunc.approxOn ↑↑f (_ : Measurable ↑↑f) (Set.range ↑↑f ∪ {0}) 0 (_ : 0 ∈ Set.range ↑↑f ∪ {0}) n)) p))) atTop (𝓝 f) [PROOFSTEP] convert SimpleFunc.tendsto_approxOn_range_Lp hp_ne_top (Lp.stronglyMeasurable f).measurable hfi' [GOAL] case h.e'_5.h.e'_3 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α inst✝ : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ this✝¹ : MeasurableSpace E := borel E this✝ : BorelSpace E f : { x // x ∈ Lp E p } hfi' : Memℒp (↑↑f) p this : SeparableSpace ↑(Set.range ↑↑f ∪ {0}) ⊢ f = Memℒp.toLp (↑↑f) hfi' [PROOFSTEP] rw [toLp_coeFn f (Lp.memℒp f)] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f g : { x // x ∈ simpleFunc G p μ } ⊢ ↑↑↑f ≤ᵐ[μ] ↑↑↑g ↔ f ≤ g [PROOFSTEP] rw [← Subtype.coe_le_coe, ← Lp.coeFn_le] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G ⊢ CovariantClass { x // x ∈ simpleFunc G p μ } { x // x ∈ simpleFunc G p μ } (fun x x_1 => x + x_1) fun x x_1 => x ≤ x_1 [PROOFSTEP] refine' ⟨fun f g₁ g₂ hg₁₂ => _⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f g₁ g₂ : { x // x ∈ simpleFunc G p μ } hg₁₂ : g₁ ≤ g₂ ⊢ f + g₁ ≤ f + g₂ [PROOFSTEP] rw [← Lp.simpleFunc.coeFn_le] at hg₁₂ ⊢ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f g₁ g₂ : { x // x ∈ simpleFunc G p μ } hg₁₂ : ↑↑↑g₁ ≤ᵐ[μ] ↑↑↑g₂ ⊢ ↑↑↑(f + g₁) ≤ᵐ[μ] ↑↑↑(f + g₂) [PROOFSTEP] have h_add_1 : ((f + g₁ : Lp.simpleFunc G p μ) : α → G) =ᵐ[μ] (f : α → G) + g₁ := Lp.coeFn_add _ _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f g₁ g₂ : { x // x ∈ simpleFunc G p μ } hg₁₂ : ↑↑↑g₁ ≤ᵐ[μ] ↑↑↑g₂ h_add_1 : ↑↑↑(f + g₁) =ᵐ[μ] ↑↑↑f + ↑↑↑g₁ ⊢ ↑↑↑(f + g₁) ≤ᵐ[μ] ↑↑↑(f + g₂) [PROOFSTEP] have h_add_2 : ((f + g₂ : Lp.simpleFunc G p μ) : α → G) =ᵐ[μ] (f : α → G) + g₂ := Lp.coeFn_add _ _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f g₁ g₂ : { x // x ∈ simpleFunc G p μ } hg₁₂ : ↑↑↑g₁ ≤ᵐ[μ] ↑↑↑g₂ h_add_1 : ↑↑↑(f + g₁) =ᵐ[μ] ↑↑↑f + ↑↑↑g₁ h_add_2 : ↑↑↑(f + g₂) =ᵐ[μ] ↑↑↑f + ↑↑↑g₂ ⊢ ↑↑↑(f + g₁) ≤ᵐ[μ] ↑↑↑(f + g₂) [PROOFSTEP] filter_upwards [h_add_1, h_add_2, hg₁₂] with _ h1 h2 h3 [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f g₁ g₂ : { x // x ∈ simpleFunc G p μ } hg₁₂ : ↑↑↑g₁ ≤ᵐ[μ] ↑↑↑g₂ h_add_1 : ↑↑↑(f + g₁) =ᵐ[μ] ↑↑↑f + ↑↑↑g₁ h_add_2 : ↑↑↑(f + g₂) =ᵐ[μ] ↑↑↑f + ↑↑↑g₂ a✝ : α h1 : ↑↑↑(f + g₁) a✝ = (↑↑↑f + ↑↑↑g₁) a✝ h2 : ↑↑↑(f + g₂) a✝ = (↑↑↑f + ↑↑↑g₂) a✝ h3 : ↑↑↑g₁ a✝ ≤ ↑↑↑g₂ a✝ ⊢ ↑↑↑(f + g₁) a✝ ≤ ↑↑↑(f + g₂) a✝ [PROOFSTEP] rw [h1, h2, Pi.add_apply, Pi.add_apply] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f g₁ g₂ : { x // x ∈ simpleFunc G p μ } hg₁₂ : ↑↑↑g₁ ≤ᵐ[μ] ↑↑↑g₂ h_add_1 : ↑↑↑(f + g₁) =ᵐ[μ] ↑↑↑f + ↑↑↑g₁ h_add_2 : ↑↑↑(f + g₂) =ᵐ[μ] ↑↑↑f + ↑↑↑g₂ a✝ : α h1 : ↑↑↑(f + g₁) a✝ = (↑↑↑f + ↑↑↑g₁) a✝ h2 : ↑↑↑(f + g₂) a✝ = (↑↑↑f + ↑↑↑g₂) a✝ h3 : ↑↑↑g₁ a✝ ≤ ↑↑↑g₂ a✝ ⊢ ↑↑↑f a✝ + ↑↑↑g₁ a✝ ≤ ↑↑↑f a✝ + ↑↑↑g₂ a✝ [PROOFSTEP] exact add_le_add le_rfl h3 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f : { x // x ∈ simpleFunc G p μ } ⊢ 0 ≤ᵐ[μ] ↑↑↑f ↔ 0 ≤ f [PROOFSTEP] rw [← Subtype.coe_le_coe, Lp.coeFn_nonneg, AddSubmonoid.coe_zero] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G f : { x // x ∈ simpleFunc G p μ } hf : 0 ≤ f ⊢ ∃ f', 0 ≤ f' ∧ ↑↑↑f =ᵐ[μ] ↑f' [PROOFSTEP] rcases f with ⟨⟨f, hp⟩, g, (rfl : _ = f)⟩ [GOAL] case mk.mk.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G g : α →ₛ G hp : AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ) ∈ Lp G p hf : 0 ≤ { val := { val := AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ), property := hp }, property := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑{ val := AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ), property := hp }) } ⊢ ∃ f', 0 ≤ f' ∧ ↑↑↑{ val := { val := AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ), property := hp }, property := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑{ val := AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ), property := hp }) } =ᵐ[μ] ↑f' [PROOFSTEP] change 0 ≤ᵐ[μ] g at hf [GOAL] case mk.mk.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G g : α →ₛ G hp : AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ) ∈ Lp G p hf : 0 ≤ᵐ[μ] ↑g ⊢ ∃ f', 0 ≤ f' ∧ ↑↑↑{ val := { val := AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ), property := hp }, property := (_ : ∃ s, AEEqFun.mk ↑s (_ : AEStronglyMeasurable (↑s) μ) = ↑{ val := AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ), property := hp }) } =ᵐ[μ] ↑f' [PROOFSTEP] refine ⟨g ⊔ 0, le_sup_right, (AEEqFun.coeFn_mk _ _).trans ?_⟩ [GOAL] case mk.mk.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G g : α →ₛ G hp : AEEqFun.mk ↑g (_ : AEStronglyMeasurable (↑g) μ) ∈ Lp G p hf : 0 ≤ᵐ[μ] ↑g ⊢ ↑g =ᵐ[μ] ↑(g ⊔ 0) [PROOFSTEP] exact hf.mono fun x hx ↦ (sup_of_le_left hx).symm [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } ⊢ g ∈ closure (Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) [PROOFSTEP] borelize G [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G ⊢ g ∈ closure (Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) [PROOFSTEP] rw [mem_closure_iff_seq_limit] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have hg_memℒp : Memℒp (g : α → G) p μ := Lp.memℒp (g : Lp G p μ) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have zero_mem : (0 : G) ∈ (range (g : α → G) ∪ {0} : Set G) ∩ {y | 0 ≤ y} := by simp only [union_singleton, mem_inter_iff, mem_insert_iff, eq_self_iff_true, true_or_iff, mem_setOf_eq, le_refl, and_self_iff] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p ⊢ 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} [PROOFSTEP] simp only [union_singleton, mem_inter_iff, mem_insert_iff, eq_self_iff_true, true_or_iff, mem_setOf_eq, le_refl, and_self_iff] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have : SeparableSpace ((range (g : α → G) ∪ {0}) ∩ {y | 0 ≤ y} : Set G) := by apply IsSeparable.separableSpace apply IsSeparable.mono _ (Set.inter_subset_left _ _) exact (Lp.stronglyMeasurable (g : Lp G p μ)).isSeparable_range.union (finite_singleton _).isSeparable [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} ⊢ SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) [PROOFSTEP] apply IsSeparable.separableSpace [GOAL] case hs α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} ⊢ IsSeparable ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) [PROOFSTEP] apply IsSeparable.mono _ (Set.inter_subset_left _ _) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} ⊢ IsSeparable (Set.range ↑↑↑g ∪ {0}) [PROOFSTEP] exact (Lp.stronglyMeasurable (g : Lp G p μ)).isSeparable_range.union (finite_singleton _).isSeparable [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have g_meas : Measurable (g : α → G) := (Lp.stronglyMeasurable (g : Lp G p μ)).measurable [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] let x n := SimpleFunc.approxOn g g_meas ((range (g : α → G) ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have hx_nonneg : ∀ n, 0 ≤ x n := by intro n a change x n a ∈ {y : G | 0 ≤ y} have A : (range (g : α → G) ∪ {0} : Set G) ∩ {y | 0 ≤ y} ⊆ {y | 0 ≤ y} := inter_subset_right _ _ apply A exact SimpleFunc.approxOn_mem g_meas _ n a [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n ⊢ ∀ (n : ℕ), 0 ≤ x n [PROOFSTEP] intro n a [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n n : ℕ a : α ⊢ ↑0 a ≤ ↑(x n) a [PROOFSTEP] change x n a ∈ {y : G | 0 ≤ y} [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n n : ℕ a : α ⊢ ↑(x n) a ∈ {y | 0 ≤ y} [PROOFSTEP] have A : (range (g : α → G) ∪ {0} : Set G) ∩ {y | 0 ≤ y} ⊆ {y | 0 ≤ y} := inter_subset_right _ _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n n : ℕ a : α A : (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} ⊆ {y | 0 ≤ y} ⊢ ↑(x n) a ∈ {y | 0 ≤ y} [PROOFSTEP] apply A [GOAL] case a α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n n : ℕ a : α A : (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} ⊆ {y | 0 ≤ y} ⊢ ↑(x n) a ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} [PROOFSTEP] exact SimpleFunc.approxOn_mem g_meas _ n a [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have hx_memℒp : ∀ n, Memℒp (x n) p μ := SimpleFunc.memℒp_approxOn _ hg_memℒp _ ⟨aestronglyMeasurable_const, by simp⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n ⊢ snorm (fun x => 0) p μ < ⊤ [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have h_toLp := fun n => Memℒp.coeFn_toLp (hx_memℒp n) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have hx_nonneg_Lp : ∀ n, 0 ≤ toLp (x n) (hx_memℒp n) := by intro n rw [← Lp.simpleFunc.coeFn_le, Lp.simpleFunc.toLp_eq_toLp] filter_upwards [Lp.simpleFunc.coeFn_zero p μ G, h_toLp n] with a ha0 ha_toLp rw [ha0, ha_toLp] exact hx_nonneg n a [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) ⊢ ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) [PROOFSTEP] intro n [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) n : ℕ ⊢ 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) [PROOFSTEP] rw [← Lp.simpleFunc.coeFn_le, Lp.simpleFunc.toLp_eq_toLp] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) n : ℕ ⊢ ↑↑↑0 ≤ᵐ[μ] ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) [PROOFSTEP] filter_upwards [Lp.simpleFunc.coeFn_zero p μ G, h_toLp n] with a ha0 ha_toLp [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) n : ℕ a : α ha0 : ↑↑↑0 a = OfNat.ofNat 0 a ha_toLp : ↑↑(Memℒp.toLp ↑(SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n) (_ : Memℒp (↑(x n)) p)) a = ↑(SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n) a ⊢ ↑↑↑0 a ≤ ↑↑(Memℒp.toLp ↑(SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n) (_ : Memℒp (↑(x n)) p)) a [PROOFSTEP] rw [ha0, ha_toLp] [GOAL] case h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) n : ℕ a : α ha0 : ↑↑↑0 a = OfNat.ofNat 0 a ha_toLp : ↑↑(Memℒp.toLp ↑(SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n) (_ : Memℒp (↑(x n)) p)) a = ↑(SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n) a ⊢ OfNat.ofNat 0 a ≤ ↑(SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n) a [PROOFSTEP] exact hx_nonneg n a [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] have hx_tendsto : Tendsto (fun n : ℕ => snorm ((x n : α → G) - (g : α → G)) p μ) atTop (𝓝 0) := by apply SimpleFunc.tendsto_approxOn_Lp_snorm g_meas zero_mem hp_ne_top · have hg_nonneg : (0 : α → G) ≤ᵐ[μ] g := (Lp.coeFn_nonneg _).mpr g.2 refine' hg_nonneg.mono fun a ha => subset_closure _ simpa using ha · simp_rw [sub_zero]; exact hg_memℒp.snorm_lt_top [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) ⊢ Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) [PROOFSTEP] apply SimpleFunc.tendsto_approxOn_Lp_snorm g_meas zero_mem hp_ne_top [GOAL] case hμ α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) ⊢ ∀ᵐ (x : α) ∂μ, ↑↑↑g x ∈ closure ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) [PROOFSTEP] have hg_nonneg : (0 : α → G) ≤ᵐ[μ] g := (Lp.coeFn_nonneg _).mpr g.2 [GOAL] case hμ α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hg_nonneg : 0 ≤ᵐ[μ] ↑↑↑g ⊢ ∀ᵐ (x : α) ∂μ, ↑↑↑g x ∈ closure ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) [PROOFSTEP] refine' hg_nonneg.mono fun a ha => subset_closure _ [GOAL] case hμ α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hg_nonneg : 0 ≤ᵐ[μ] ↑↑↑g a : α ha : OfNat.ofNat 0 a ≤ ↑↑↑g a ⊢ ↑↑↑g a ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} [PROOFSTEP] simpa using ha [GOAL] case hi α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) ⊢ snorm (fun x => ↑↑↑g x - 0) p μ < ⊤ [PROOFSTEP] simp_rw [sub_zero] [GOAL] case hi α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) ⊢ snorm (fun x => ↑↑↑g x) p μ < ⊤ [PROOFSTEP] exact hg_memℒp.snorm_lt_top [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) ⊢ ∃ x, (∀ (n : ℕ), x n ∈ Set.range (coeSimpleFuncNonnegToLpNonneg p μ G)) ∧ Tendsto x atTop (𝓝 g) [PROOFSTEP] refine' ⟨fun n => (coeSimpleFuncNonnegToLpNonneg p μ G) ⟨toLp (x n) (hx_memℒp n), hx_nonneg_Lp n⟩, fun n => mem_range_self _, _⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) ⊢ Tendsto (fun n => coeSimpleFuncNonnegToLpNonneg p μ G { val := toLp (x n) (_ : Memℒp (↑(x n)) p), property := (_ : 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p)) }) atTop (𝓝 g) [PROOFSTEP] suffices Tendsto (fun n : ℕ => (toLp (x n) (hx_memℒp n) : Lp G p μ)) atTop (𝓝 (g : Lp G p μ)) by rw [tendsto_iff_dist_tendsto_zero] at this ⊢ simp_rw [Subtype.dist_eq] exact this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝² : MeasurableSpace G := borel G this✝¹ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this✝ : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) this : Tendsto (fun n => ↑(toLp (x n) (_ : Memℒp (↑(x n)) p))) atTop (𝓝 ↑g) ⊢ Tendsto (fun n => coeSimpleFuncNonnegToLpNonneg p μ G { val := toLp (x n) (_ : Memℒp (↑(x n)) p), property := (_ : 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p)) }) atTop (𝓝 g) [PROOFSTEP] rw [tendsto_iff_dist_tendsto_zero] at this ⊢ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝² : MeasurableSpace G := borel G this✝¹ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this✝ : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) this : Tendsto (fun b => dist ↑(toLp (x b) (_ : Memℒp (↑(x b)) p)) ↑g) atTop (𝓝 0) ⊢ Tendsto (fun b => dist (coeSimpleFuncNonnegToLpNonneg p μ G { val := toLp (x b) (_ : Memℒp (↑(x b)) p), property := (_ : 0 ≤ toLp (x b) (_ : Memℒp (↑(x b)) p)) }) g) atTop (𝓝 0) [PROOFSTEP] simp_rw [Subtype.dist_eq] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝² : MeasurableSpace G := borel G this✝¹ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this✝ : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) this : Tendsto (fun b => dist ↑(toLp (x b) (_ : Memℒp (↑(x b)) p)) ↑g) atTop (𝓝 0) ⊢ Tendsto (fun b => dist ↑(coeSimpleFuncNonnegToLpNonneg p μ G { val := toLp (SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem b) (_ : Memℒp (↑(x b)) p), property := (_ : 0 ≤ toLp (x b) (_ : Memℒp (↑(x b)) p)) }) ↑g) atTop (𝓝 0) [PROOFSTEP] exact this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) ⊢ Tendsto (fun n => ↑(toLp (x n) (_ : Memℒp (↑(x n)) p))) atTop (𝓝 ↑g) [PROOFSTEP] rw [Lp.tendsto_Lp_iff_tendsto_ℒp'] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) ⊢ Tendsto (fun n => snorm (↑↑↑(toLp (x n) (_ : Memℒp (↑(x n)) p)) - ↑↑↑g) p μ) atTop (𝓝 0) [PROOFSTEP] refine Filter.Tendsto.congr (fun n => snorm_congr_ae (EventuallyEq.sub ?_ ?_)) hx_tendsto [GOAL] case refine_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) n : ℕ ⊢ (fun x_1 => ↑(x n) x_1) =ᵐ[μ] fun x_1 => ↑↑↑(toLp (x n) (_ : Memℒp (↑(x n)) p)) x_1 [PROOFSTEP] symm [GOAL] case refine_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) n : ℕ ⊢ (fun x_1 => ↑↑↑(toLp (x n) (_ : Memℒp (↑(x n)) p)) x_1) =ᵐ[μ] fun x_1 => ↑(x n) x_1 [PROOFSTEP] rw [Lp.simpleFunc.toLp_eq_toLp] [GOAL] case refine_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) n : ℕ ⊢ (fun x_1 => ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) x_1) =ᵐ[μ] fun x_1 => ↑(x n) x_1 [PROOFSTEP] exact h_toLp n [GOAL] case refine_2 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝³ : MeasurableSpace α inst✝² : NormedAddCommGroup E inst✝¹ : NormedAddCommGroup F p : ℝ≥0∞ μ : Measure α G : Type u_7 inst✝ : NormedLatticeAddCommGroup G hp : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ g : { g // 0 ≤ g } this✝¹ : MeasurableSpace G := borel G this✝ : BorelSpace G hg_memℒp : Memℒp (↑↑↑g) p zero_mem : 0 ∈ (Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y} this : SeparableSpace ↑((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) g_meas : Measurable ↑↑↑g x : ℕ → α →ₛ G := fun n => SimpleFunc.approxOn (↑↑↑g) g_meas ((Set.range ↑↑↑g ∪ {0}) ∩ {y | 0 ≤ y}) 0 zero_mem n hx_nonneg : ∀ (n : ℕ), 0 ≤ x n hx_memℒp : ∀ (n : ℕ), Memℒp (↑(x n)) p h_toLp : ∀ (n : ℕ), ↑↑(Memℒp.toLp ↑(x n) (_ : Memℒp (↑(x n)) p)) =ᵐ[μ] ↑(x n) hx_nonneg_Lp : ∀ (n : ℕ), 0 ≤ toLp (x n) (_ : Memℒp (↑(x n)) p) hx_tendsto : Tendsto (fun n => snorm (↑(x n) - ↑↑↑g) p μ) atTop (𝓝 0) n : ℕ ⊢ (fun x => ↑↑↑g x) =ᵐ[μ] fun x => ↑↑↑g x [PROOFSTEP] rfl [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : { x // x ∈ Lp E p } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P ↑(simpleFunc.indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α → E⦄ (hf : Memℒp f p) (hg : Memℒp g p), Disjoint (support f) (support g) → P (Memℒp.toLp f hf) → P (Memℒp.toLp g hg) → P (Memℒp.toLp f hf + Memℒp.toLp g hg) h_closed : IsClosed {f | P f} ⊢ ∀ (f : { x // x ∈ Lp E p }), P f [PROOFSTEP] refine' fun f => (Lp.simpleFunc.denseRange hp_ne_top).induction_on f h_closed _ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : { x // x ∈ Lp E p } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P ↑(simpleFunc.indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α → E⦄ (hf : Memℒp f p) (hg : Memℒp g p), Disjoint (support f) (support g) → P (Memℒp.toLp f hf) → P (Memℒp.toLp g hg) → P (Memℒp.toLp f hf + Memℒp.toLp g hg) h_closed : IsClosed {f | P f} f : { x // x ∈ Lp E p } ⊢ ∀ (a : { x // x ∈ ↑(simpleFunc E p μ) }), P ↑a [PROOFSTEP] refine' Lp.simpleFunc.induction (α := α) (E := E) (lt_of_lt_of_le zero_lt_one _i.elim).ne' hp_ne_top _ _ [GOAL] case refine'_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : { x // x ∈ Lp E p } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P ↑(simpleFunc.indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α → E⦄ (hf : Memℒp f p) (hg : Memℒp g p), Disjoint (support f) (support g) → P (Memℒp.toLp f hf) → P (Memℒp.toLp g hg) → P (Memℒp.toLp f hf + Memℒp.toLp g hg) h_closed : IsClosed {f | P f} f : { x // x ∈ Lp E p } ⊢ ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P ↑(simpleFunc.indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) [PROOFSTEP] exact fun c s => h_ind c [GOAL] case refine'_2 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : { x // x ∈ Lp E p } → Prop h_ind : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : ↑↑μ s < ⊤), P ↑(simpleFunc.indicatorConst p hs (_ : ↑↑μ s ≠ ⊤) c) h_add : ∀ ⦃f g : α → E⦄ (hf : Memℒp f p) (hg : Memℒp g p), Disjoint (support f) (support g) → P (Memℒp.toLp f hf) → P (Memℒp.toLp g hg) → P (Memℒp.toLp f hf + Memℒp.toLp g hg) h_closed : IsClosed {f | P f} f : { x // x ∈ Lp E p } ⊢ ∀ ⦃f g : α →ₛ E⦄ (hf : Memℒp (↑f) p) (hg : Memℒp (↑g) p), Disjoint (support ↑f) (support ↑g) → P ↑(simpleFunc.toLp f hf) → P ↑(simpleFunc.toLp g hg) → P ↑(simpleFunc.toLp f hf + simpleFunc.toLp g hg) [PROOFSTEP] exact fun f g hf hg => h_add hf hg [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g ⊢ ∀ ⦃f : α → E⦄, Memℒp f p → P f [PROOFSTEP] have : ∀ f : SimpleFunc α E, Memℒp f p μ → P f := by apply SimpleFunc.induction · intro c s hs h by_cases hc : c = 0 · subst hc; convert h_ind 0 MeasurableSet.empty (by simp) using 1; ext; simp [const] have hp_pos : p ≠ 0 := (lt_of_lt_of_le zero_lt_one _i.elim).ne' exact h_ind c hs (SimpleFunc.measure_lt_top_of_memℒp_indicator hp_pos hp_ne_top hc hs h) · intro f g hfg hf hg int_fg rw [SimpleFunc.coe_add, memℒp_add_of_disjoint hfg f.stronglyMeasurable g.stronglyMeasurable] at int_fg refine' h_add hfg int_fg.1 int_fg.2 (hf int_fg.1) (hg int_fg.2) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g ⊢ ∀ (f : α →ₛ E), Memℒp (↑f) p → P ↑f [PROOFSTEP] apply SimpleFunc.induction [GOAL] case h_ind α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g ⊢ ∀ (c : E) {s : Set α} (hs : MeasurableSet s), Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p → P ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) [PROOFSTEP] intro c s hs h [GOAL] case h_ind α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g c : E s : Set α hs : MeasurableSet s h : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p ⊢ P ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) [PROOFSTEP] by_cases hc : c = 0 [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g c : E s : Set α hs : MeasurableSet s h : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c = 0 ⊢ P ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) [PROOFSTEP] subst hc [GOAL] case pos α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g s : Set α hs : MeasurableSet s h : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p ⊢ P ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) [PROOFSTEP] convert h_ind 0 MeasurableSet.empty (by simp) using 1 [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g s : Set α hs : MeasurableSet s h : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p ⊢ ↑↑μ ∅ < ⊤ [PROOFSTEP] simp [GOAL] case h.e'_1 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g s : Set α hs : MeasurableSet s h : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p ⊢ ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) = Set.indicator ∅ fun x => 0 [PROOFSTEP] ext [GOAL] case h.e'_1.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g s : Set α hs : MeasurableSet s h : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p x✝ : α ⊢ ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) x✝ = Set.indicator ∅ (fun x => 0) x✝ [PROOFSTEP] simp [const] [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g c : E s : Set α hs : MeasurableSet s h : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : ¬c = 0 ⊢ P ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) [PROOFSTEP] have hp_pos : p ≠ 0 := (lt_of_lt_of_le zero_lt_one _i.elim).ne' [GOAL] case neg α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g c : E s : Set α hs : MeasurableSet s h : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : ¬c = 0 hp_pos : p ≠ 0 ⊢ P ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) [PROOFSTEP] exact h_ind c hs (SimpleFunc.measure_lt_top_of_memℒp_indicator hp_pos hp_ne_top hc hs h) [GOAL] case h_add α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g ⊢ ∀ ⦃f g : α →ₛ E⦄, Disjoint (support ↑f) (support ↑g) → (Memℒp (↑f) p → P ↑f) → (Memℒp (↑g) p → P ↑g) → Memℒp (↑(f + g)) p → P ↑(f + g) [PROOFSTEP] intro f g hfg hf hg int_fg [GOAL] case h_add α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g f g : α →ₛ E hfg : Disjoint (support ↑f) (support ↑g) hf : Memℒp (↑f) p → P ↑f hg : Memℒp (↑g) p → P ↑g int_fg : Memℒp (↑(f + g)) p ⊢ P ↑(f + g) [PROOFSTEP] rw [SimpleFunc.coe_add, memℒp_add_of_disjoint hfg f.stronglyMeasurable g.stronglyMeasurable] at int_fg [GOAL] case h_add α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g f g : α →ₛ E hfg : Disjoint (support ↑f) (support ↑g) hf : Memℒp (↑f) p → P ↑f hg : Memℒp (↑g) p → P ↑g int_fg : Memℒp (↑f) p ∧ Memℒp (↑g) p ⊢ P ↑(f + g) [PROOFSTEP] refine' h_add hfg int_fg.1 int_fg.2 (hf int_fg.1) (hg int_fg.2) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g this : ∀ (f : α →ₛ E), Memℒp (↑f) p → P ↑f ⊢ ∀ ⦃f : α → E⦄, Memℒp f p → P f [PROOFSTEP] have : ∀ f : Lp.simpleFunc E p μ, P f := by intro f exact h_ae (Lp.simpleFunc.toSimpleFunc_eq_toFun f) (Lp.simpleFunc.memℒp f) (this (Lp.simpleFunc.toSimpleFunc f) (Lp.simpleFunc.memℒp f)) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g this : ∀ (f : α →ₛ E), Memℒp (↑f) p → P ↑f ⊢ ∀ (f : { x // x ∈ Lp.simpleFunc E p μ }), P ↑↑↑f [PROOFSTEP] intro f [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g this : ∀ (f : α →ₛ E), Memℒp (↑f) p → P ↑f f : { x // x ∈ Lp.simpleFunc E p μ } ⊢ P ↑↑↑f [PROOFSTEP] exact h_ae (Lp.simpleFunc.toSimpleFunc_eq_toFun f) (Lp.simpleFunc.memℒp f) (this (Lp.simpleFunc.toSimpleFunc f) (Lp.simpleFunc.memℒp f)) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g this✝ : ∀ (f : α →ₛ E), Memℒp (↑f) p → P ↑f this : ∀ (f : { x // x ∈ Lp.simpleFunc E p μ }), P ↑↑↑f ⊢ ∀ ⦃f : α → E⦄, Memℒp f p → P f [PROOFSTEP] have : ∀ f : Lp E p μ, P f := fun f => (Lp.simpleFunc.denseRange hp_ne_top).induction_on f h_closed this [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α _i : Fact (1 ≤ p) hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (Set.indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f p → Memℒp g p → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f p → P f → P g this✝¹ : ∀ (f : α →ₛ E), Memℒp (↑f) p → P ↑f this✝ : ∀ (f : { x // x ∈ Lp.simpleFunc E p μ }), P ↑↑↑f this : ∀ (f : { x // x ∈ Lp E p }), P ↑↑f ⊢ ∀ ⦃f : α → E⦄, Memℒp f p → P f [PROOFSTEP] exact fun f hf => h_ae hf.coeFn_toLp (Lp.memℒp _) (this (hf.toLp f)) [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 ⊢ ∃ g, snorm (f - g) p μ ≤ ε ∧ P g [PROOFSTEP] rcases eq_or_ne p 0 with (rfl | hp_pos) [GOAL] case inl α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E μ : Measure α P : (α → E) → Prop h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E ε : ℝ≥0∞ hε : ε ≠ 0 hp_ne_top : 0 ≠ ⊤ h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) 0 μ ≤ ε ∧ P g hf : Memℒp f 0 ⊢ ∃ g, snorm (f - g) 0 μ ≤ ε ∧ P g [PROOFSTEP] rcases h0P (0 : E) MeasurableSet.empty (by simp only [measure_empty, WithTop.zero_lt_top]) hε with ⟨g, _, Pg⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E μ : Measure α P : (α → E) → Prop h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E ε : ℝ≥0∞ hε : ε ≠ 0 hp_ne_top : 0 ≠ ⊤ h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) 0 μ ≤ ε ∧ P g hf : Memℒp f 0 ⊢ ↑↑μ ∅ < ⊤ [PROOFSTEP] simp only [measure_empty, WithTop.zero_lt_top] [GOAL] case inl.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E μ : Measure α P : (α → E) → Prop h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E ε : ℝ≥0∞ hε : ε ≠ 0 hp_ne_top : 0 ≠ ⊤ h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) 0 μ ≤ ε ∧ P g hf : Memℒp f 0 g : α → E left✝ : snorm (g - Set.indicator ∅ fun x => 0) 0 μ ≤ ε Pg : P g ⊢ ∃ g, snorm (f - g) 0 μ ≤ ε ∧ P g [PROOFSTEP] exact ⟨g, by simp only [snorm_exponent_zero, zero_le'], Pg⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E μ : Measure α P : (α → E) → Prop h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E ε : ℝ≥0∞ hε : ε ≠ 0 hp_ne_top : 0 ≠ ⊤ h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) 0 μ ≤ ε ∧ P g hf : Memℒp f 0 g : α → E left✝ : snorm (g - Set.indicator ∅ fun x => 0) 0 μ ≤ ε Pg : P g ⊢ snorm (f - g) 0 μ ≤ ε [PROOFSTEP] simp only [snorm_exponent_zero, zero_le'] [GOAL] case inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 ⊢ ∃ g, snorm (f - g) p μ ≤ ε ∧ P g [PROOFSTEP] suffices H : ∀ (f' : α →ₛ E) (δ : ℝ≥0∞) (hδ : δ ≠ 0), Memℒp f' p μ → ∃ g, snorm (⇑f' - g) p μ ≤ δ ∧ P g [GOAL] case inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 H : ∀ (f' : α →ₛ E) (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g ⊢ ∃ g, snorm (f - g) p μ ≤ ε ∧ P g [PROOFSTEP] obtain ⟨η, ηpos, hη⟩ := exists_Lp_half E μ p hε [GOAL] case inr.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 H : ∀ (f' : α →ₛ E) (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < ε ⊢ ∃ g, snorm (f - g) p μ ≤ ε ∧ P g [PROOFSTEP] rcases hf.exists_simpleFunc_snorm_sub_lt hp_ne_top ηpos.ne' with ⟨f', hf', f'_mem⟩ [GOAL] case inr.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 H : ∀ (f' : α →ₛ E) (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < ε f' : α →ₛ E hf' : snorm (f - ↑f') p μ < η f'_mem : Memℒp (↑f') p ⊢ ∃ g, snorm (f - g) p μ ≤ ε ∧ P g [PROOFSTEP] rcases H f' η ηpos.ne' f'_mem with ⟨g, hg, Pg⟩ [GOAL] case inr.intro.intro.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 H : ∀ (f' : α →ₛ E) (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < ε f' : α →ₛ E hf' : snorm (f - ↑f') p μ < η f'_mem : Memℒp (↑f') p g : α → E hg : snorm (↑f' - g) p μ ≤ η Pg : P g ⊢ ∃ g, snorm (f - g) p μ ≤ ε ∧ P g [PROOFSTEP] refine' ⟨g, _, Pg⟩ [GOAL] case inr.intro.intro.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 H : ∀ (f' : α →ₛ E) (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < ε f' : α →ₛ E hf' : snorm (f - ↑f') p μ < η f'_mem : Memℒp (↑f') p g : α → E hg : snorm (↑f' - g) p μ ≤ η Pg : P g ⊢ snorm (f - g) p μ ≤ ε [PROOFSTEP] convert (hη _ _ (hf.aestronglyMeasurable.sub f'.aestronglyMeasurable) (f'.aestronglyMeasurable.sub (h2P g Pg)) hf'.le hg).le using 2 [GOAL] case h.e'_3.h.e'_5 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 H : ∀ (f' : α →ₛ E) (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < ε f' : α →ₛ E hf' : snorm (f - ↑f') p μ < η f'_mem : Memℒp (↑f') p g : α → E hg : snorm (↑f' - g) p μ ≤ η Pg : P g ⊢ f - g = f - ↑f' + (↑f' - g) [PROOFSTEP] simp only [sub_add_sub_cancel] [GOAL] case H α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 ⊢ ∀ (f' : α →ₛ E) (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g [PROOFSTEP] apply SimpleFunc.induction [GOAL] case H.h_ind α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 ⊢ ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p → ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) - g) p μ ≤ δ ∧ P g [PROOFSTEP] intro c s hs ε εpos Hs [GOAL] case H.h_ind α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 c : E s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p ⊢ ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) - g) p μ ≤ ε ∧ P g [PROOFSTEP] rcases eq_or_ne c 0 with (rfl | hc) [GOAL] case H.h_ind.inl α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p ⊢ ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) - g) p μ ≤ ε ∧ P g [PROOFSTEP] rcases h0P (0 : E) MeasurableSet.empty (by simp only [measure_empty, WithTop.zero_lt_top]) εpos with ⟨g, hg, Pg⟩ [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p ⊢ ↑↑μ ∅ < ⊤ [PROOFSTEP] simp only [measure_empty, WithTop.zero_lt_top] [GOAL] case H.h_ind.inl.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p g : α → E hg : snorm (g - Set.indicator ∅ fun x => 0) p μ ≤ ε Pg : P g ⊢ ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) - g) p μ ≤ ε ∧ P g [PROOFSTEP] rw [← snorm_neg, neg_sub] at hg [GOAL] case H.h_ind.inl.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p g : α → E hg : snorm ((Set.indicator ∅ fun x => 0) - g) p μ ≤ ε Pg : P g ⊢ ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) - g) p μ ≤ ε ∧ P g [PROOFSTEP] refine' ⟨g, _, Pg⟩ [GOAL] case H.h_ind.inl.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p g : α → E hg : snorm ((Set.indicator ∅ fun x => 0) - g) p μ ≤ ε Pg : P g ⊢ snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) - g) p μ ≤ ε [PROOFSTEP] convert hg [GOAL] case h.e'_3.h.e'_5.h.e'_5 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p g : α → E hg : snorm ((Set.indicator ∅ fun x => 0) - g) p μ ≤ ε Pg : P g ⊢ ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) = Set.indicator ∅ fun x => 0 [PROOFSTEP] ext x [GOAL] case h.e'_3.h.e'_5.h.e'_5.h α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0))) p g : α → E hg : snorm ((Set.indicator ∅ fun x => 0) - g) p μ ≤ ε Pg : P g x : α ⊢ ↑(SimpleFunc.piecewise s hs (SimpleFunc.const α 0) (SimpleFunc.const α 0)) x = Set.indicator ∅ (fun x => 0) x [PROOFSTEP] simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_zero, piecewise_eq_indicator, indicator_zero', Pi.zero_apply, indicator_zero] [GOAL] case H.h_ind.inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 c : E s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c ≠ 0 ⊢ ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) - g) p μ ≤ ε ∧ P g [PROOFSTEP] have : μ s < ∞ := SimpleFunc.measure_lt_top_of_memℒp_indicator hp_pos hp_ne_top hc hs Hs [GOAL] case H.h_ind.inr α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 c : E s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c ≠ 0 this : ↑↑μ s < ⊤ ⊢ ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) - g) p μ ≤ ε ∧ P g [PROOFSTEP] rcases h0P c hs this εpos with ⟨g, hg, Pg⟩ [GOAL] case H.h_ind.inr.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 c : E s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c ≠ 0 this : ↑↑μ s < ⊤ g : α → E hg : snorm (g - Set.indicator s fun x => c) p μ ≤ ε Pg : P g ⊢ ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) - g) p μ ≤ ε ∧ P g [PROOFSTEP] rw [← snorm_neg, neg_sub] at hg [GOAL] case H.h_ind.inr.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε✝ : ℝ≥0∞ hε : ε✝ ≠ 0 hp_pos : p ≠ 0 c : E s : Set α hs : MeasurableSet s ε : ℝ≥0∞ εpos : ε ≠ 0 Hs : Memℒp (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0))) p hc : c ≠ 0 this : ↑↑μ s < ⊤ g : α → E hg : snorm ((Set.indicator s fun x => c) - g) p μ ≤ ε Pg : P g ⊢ ∃ g, snorm (↑(SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0)) - g) p μ ≤ ε ∧ P g [PROOFSTEP] exact ⟨g, hg, Pg⟩ [GOAL] case H.h_add α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f : α → E hf : Memℒp f p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 ⊢ ∀ ⦃f g : α →ₛ E⦄, Disjoint (support ↑f) (support ↑g) → (∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g) → (∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑g) p → ∃ g_1, snorm (↑g - g_1) p μ ≤ δ ∧ P g_1) → ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑(f + g)) p → ∃ g_1, snorm (↑(f + g) - g_1) p μ ≤ δ ∧ P g_1 [PROOFSTEP] intro f f' hff' hf hf' δ δpos int_ff' [GOAL] case H.h_add α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑(f + f')) p ⊢ ∃ g, snorm (↑(f + f') - g) p μ ≤ δ ∧ P g [PROOFSTEP] obtain ⟨η, ηpos, hη⟩ := exists_Lp_half E μ p δpos [GOAL] case H.h_add.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑(f + f')) p η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ ⊢ ∃ g, snorm (↑(f + f') - g) p μ ≤ δ ∧ P g [PROOFSTEP] rw [SimpleFunc.coe_add, memℒp_add_of_disjoint hff' f.stronglyMeasurable f'.stronglyMeasurable] at int_ff' [GOAL] case H.h_add.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑f) p ∧ Memℒp (↑f') p η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ ⊢ ∃ g, snorm (↑(f + f') - g) p μ ≤ δ ∧ P g [PROOFSTEP] rcases hf η ηpos.ne' int_ff'.1 with ⟨g, hg, Pg⟩ [GOAL] case H.h_add.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑f) p ∧ Memℒp (↑f') p η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ g : α → E hg : snorm (↑f - g) p μ ≤ η Pg : P g ⊢ ∃ g, snorm (↑(f + f') - g) p μ ≤ δ ∧ P g [PROOFSTEP] rcases hf' η ηpos.ne' int_ff'.2 with ⟨g', hg', Pg'⟩ [GOAL] case H.h_add.intro.intro.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑f) p ∧ Memℒp (↑f') p η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ g : α → E hg : snorm (↑f - g) p μ ≤ η Pg : P g g' : α → E hg' : snorm (↑f' - g') p μ ≤ η Pg' : P g' ⊢ ∃ g, snorm (↑(f + f') - g) p μ ≤ δ ∧ P g [PROOFSTEP] refine' ⟨g + g', _, h1P g g' Pg Pg'⟩ [GOAL] case H.h_add.intro.intro.intro.intro.intro.intro α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑f) p ∧ Memℒp (↑f') p η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ g : α → E hg : snorm (↑f - g) p μ ≤ η Pg : P g g' : α → E hg' : snorm (↑f' - g') p μ ≤ η Pg' : P g' ⊢ snorm (↑(f + f') - (g + g')) p μ ≤ δ [PROOFSTEP] convert (hη _ _ (f.aestronglyMeasurable.sub (h2P g Pg)) (f'.aestronglyMeasurable.sub (h2P g' Pg')) hg hg').le using 2 [GOAL] case h.e'_3.h.e'_5 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑f) p ∧ Memℒp (↑f') p η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ g : α → E hg : snorm (↑f - g) p μ ≤ η Pg : P g g' : α → E hg' : snorm (↑f' - g') p μ ≤ η Pg' : P g' ⊢ ↑(f + f') - (g + g') = ↑f - g + (↑f' - g') [PROOFSTEP] rw [SimpleFunc.coe_add] [GOAL] case h.e'_3.h.e'_5 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑f) p ∧ Memℒp (↑f') p η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ g : α → E hg : snorm (↑f - g) p μ ≤ η Pg : P g g' : α → E hg' : snorm (↑f' - g') p μ ≤ η Pg' : P g' ⊢ ↑f + ↑f' - (g + g') = ↑f - g + (↑f' - g') [PROOFSTEP] abel [GOAL] case h.e'_3.h.e'_5 α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝¹ : α → E p : ℝ≥0∞ μ : Measure α hp_ne_top : p ≠ ⊤ P : (α → E) → Prop h0P : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → ∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g, snorm (g - Set.indicator s fun x => c) p μ ≤ ε ∧ P g h1P : ∀ (f g : α → E), P f → P g → P (f + g) h2P : ∀ (f : α → E), P f → AEStronglyMeasurable f μ f✝ : α → E hf✝ : Memℒp f✝ p ε : ℝ≥0∞ hε : ε ≠ 0 hp_pos : p ≠ 0 f f' : α →ₛ E hff' : Disjoint (support ↑f) (support ↑f') hf : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f) p → ∃ g, snorm (↑f - g) p μ ≤ δ ∧ P g hf' : ∀ (δ : ℝ≥0∞), δ ≠ 0 → Memℒp (↑f') p → ∃ g, snorm (↑f' - g) p μ ≤ δ ∧ P g δ : ℝ≥0∞ δpos : δ ≠ 0 int_ff' : Memℒp (↑f) p ∧ Memℒp (↑f') p η : ℝ≥0∞ ηpos : 0 < η hη : ∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ → snorm f p μ ≤ η → snorm g p μ ≤ η → snorm (f + g) p μ < δ g : α → E hg : snorm (↑f - g) p μ ≤ η Pg : P g g' : α → E hg' : snorm (↑f' - g') p μ ≤ η Pg' : P g' ⊢ ↑f + ↑f' - (g + g') = ↑f - g + (↑f' - g') [PROOFSTEP] abel [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α f : { x // x ∈ Lp.simpleFunc E 1 μ } ⊢ Integrable ↑(Lp.simpleFunc.toSimpleFunc f) [PROOFSTEP] rw [← memℒp_one_iff_integrable] [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f✝ : α → E p : ℝ≥0∞ μ : Measure α f : { x // x ∈ Lp.simpleFunc E 1 μ } ⊢ Memℒp (↑(Lp.simpleFunc.toSimpleFunc f)) 1 [PROOFSTEP] exact Lp.simpleFunc.memℒp f [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (indicator s fun x => c) h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Integrable f → Integrable g → P f → P g → P (f + g) h_closed : IsClosed {f | P ↑↑f} h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Integrable f → P f → P g ⊢ ∀ ⦃f : α → E⦄, Integrable f → P f [PROOFSTEP] simp only [← memℒp_one_iff_integrable] at * [GOAL] α : Type u_1 β : Type u_2 ι : Type u_3 E : Type u_4 F : Type u_5 𝕜 : Type u_6 inst✝¹ : MeasurableSpace α inst✝ : NormedAddCommGroup E f : α → E p : ℝ≥0∞ μ : Measure α P : (α → E) → Prop h_ind : ∀ (c : E) ⦃s : Set α⦄, MeasurableSet s → ↑↑μ s < ⊤ → P (indicator s fun x => c) h_closed : IsClosed {f | P ↑↑f} h_add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → Memℒp f 1 → Memℒp g 1 → P f → P g → P (f + g) h_ae : ∀ ⦃f g : α → E⦄, f =ᵐ[μ] g → Memℒp f 1 → P f → P g ⊢ ∀ ⦃f : α → E⦄, Memℒp f 1 → P f [PROOFSTEP] exact Memℒp.induction one_ne_top (P := P) h_ind h_add h_closed h_ae
-- Properties of insertion sort {-# OPTIONS --without-K --safe #-} open import Relation.Binary as B module Algorithms.List.Sort.Insertion.Properties {c ℓ₁ ℓ₂} (DTO : DecTotalOrder c ℓ₁ ℓ₂) where -- agda-stdlib open import Level open import Data.Bool hiding (_≤_; _≤?_; _<_) open import Data.Empty using (⊥; ⊥-elim) open import Data.List import Data.List.Properties as Listₚ import Data.Nat as ℕ import Data.Nat.Properties as ℕₚ open import Data.Product hiding (swap) open import Data.Sum using (_⊎_; inj₁; inj₂) import Data.List.Relation.Binary.Equality.Setoid as ListSetoidEquality import Data.List.Relation.Binary.Permutation.Setoid as PermutationSetoid import Data.List.Relation.Binary.Permutation.Setoid.Properties as PermutationSetoidProperties open import Data.List.Relation.Unary.All as All import Data.List.Relation.Unary.All.Properties as Allₚ open import Data.List.Relation.Unary.Linked as Linked open import Data.List.Relation.Unary.Linked.Properties as Linkedₚ open import Data.List.Relation.Unary.AllPairs as AllPairs import Data.List.Relation.Unary.AllPairs.Properties as AllPairsₚ open import Function.Base using (_∘_; _$_; flip) import Relation.Binary.Properties.DecTotalOrder as DecTotalOrderProperties open import Relation.Binary.PropositionalEquality using (_≡_) import Relation.Binary.PropositionalEquality as ≡ hiding ([_]) import Relation.Binary.Reasoning.Setoid as SetoidReasoning open import Relation.Nullary open import Relation.Unary as U -- agda-misc open import Algorithms.List.Sort.Common DTO open import Algorithms.List.Sort.Insertion open import Experiment.ListRelationProperties using (foldr-preservesʳ; Linked-∷⁻ʳ; Linked-resp-≋) open DecTotalOrder DTO renaming (Carrier to A) open DecTotalOrderProperties DTO open PermutationSetoid Eq.setoid renaming (refl to PSrefl; trans to PStrans) open PermutationSetoidProperties Eq.setoid open ListSetoidEquality Eq.setoid open InsertionSortOperation _≤?_ private _≰_ : Rel A _ x ≰ y = ¬ (x ≤ y) -- stdlib <⇒≤ : ∀ {x y} → x < y → x ≤ y <⇒≤ = proj₁ ≰⇒≥ : ∀ {x y} → x ≰ y → y ≤ x ≰⇒≥ = <⇒≤ ∘ ≰⇒> ≰∧≱⇒⊥ : ∀ {x y} → x ≰ y → y ≰ x → ⊥ ≰∧≱⇒⊥ x≰y y≰x = x≰y (≰⇒≥ y≰x) ≰⇒≉ : ∀ {x y} → x ≰ y → ¬ (x ≈ y) ≰⇒≉ x≰y x≈y = x≰y (≤-respʳ-≈ x≈y refl) ≱⇒≉ : ∀ {x y} → y ≰ x → ¬ (x ≈ y) ≱⇒≉ x≱y x≈y = ≰⇒≉ x≱y (Eq.sym x≈y) -- stdlib _≈?_ : ∀ x y → Dec (x ≈ y) x ≈? y with x ≤? y | y ≤? x ... | yes x≤y | yes y≤x = yes (antisym x≤y y≤x) ... | yes x≤y | no y≰x = no (≱⇒≉ y≰x) ... | no x≰y | yes y≤x = no (≰⇒≉ x≰y) ... | no x≰y | no y≰x = ⊥-elim $ ≰∧≱⇒⊥ x≰y y≰x ≤⇒<∨≈ : ∀ {x y} → x ≤ y → x < y ⊎ x ≈ y ≤⇒<∨≈ {x} {y} x≤y with x ≈? y ... | yes x≈y = inj₂ x≈y ... | no x≉y = inj₁ (≤∧≉⇒< x≤y x≉y) insert-permutation : ∀ x xs → insert x xs ↭ x ∷ xs insert-permutation x [] = ↭-refl insert-permutation x (y ∷ ys) with x ≤? y ... | true because _ = ↭-refl ... | false because _ = ↭-trans (prep Eq.refl (insert-permutation x ys)) (swap Eq.refl Eq.refl ↭-refl) insert-pres-Sorted : ∀ x {xs} → Sorted xs → Sorted (insert x xs) insert-pres-Sorted x {[]} _ = [-] insert-pres-Sorted x {y ∷ ys} xs-Sorted with x ≤? y ... | yes x≤y = x≤y ∷ xs-Sorted ... | no x≰y = Linkedₚ.AllPairs⇒Linked (hd ∷ tl) where y≤x : y ≤ x y≤x = ≰⇒≥ x≰y lem : All (y ≤_) ys lem = AllPairs.head (toAllPairs xs-Sorted) hd : All (y ≤_) (insert x ys) hd = All-resp-↭ ≤-respʳ-≈ (↭-sym (insert-permutation x ys)) (y≤x ∷ lem) insert[x,ys]-Sorted : Sorted (insert x ys) insert[x,ys]-Sorted = insert-pres-Sorted x {ys} (Linked-∷⁻ʳ xs-Sorted) tl : AllPairs _≤_ (insert x ys) tl = toAllPairs insert[x,ys]-Sorted sort-Sorted : ∀ xs → Sorted (sort xs) sort-Sorted xs = foldr-preservesʳ insert-pres-Sorted [] xs sort-permutation : ∀ xs → sort xs ↭ xs sort-permutation [] = ↭-refl sort-permutation (x ∷ xs) = begin sort (x ∷ xs) ≡⟨⟩ insert x (sort xs) ≈⟨ insert-permutation x (sort xs) ⟩ x ∷ sort xs ≈⟨ prep Eq.refl (sort-permutation xs) ⟩ x ∷ xs ∎ where open SetoidReasoning ↭-setoid insert-cong-≋ : ∀ {x y xs ys} → x ≈ y → xs ≋ ys → insert x xs ≋ insert y ys insert-cong-≋ {x} {y} {[]} {[]} x≈y xs≋ys = x≈y ∷ [] insert-cong-≋ {x} {y} {x₁ ∷ xs} {y₁ ∷ ys} x≈y (x₁≈y₁ ∷ xs≋ys) with x ≤? x₁ | y ≤? y₁ ... | yes p | yes p₁ = x≈y ∷ x₁≈y₁ ∷ xs≋ys ... | yes p | no ¬p = ⊥-elim (¬p (≤-respʳ-≈ x₁≈y₁ (≤-respˡ-≈ x≈y p))) ... | no ¬p | yes p = ⊥-elim (¬p (≤-respʳ-≈ (Eq.sym x₁≈y₁) (≤-respˡ-≈ (Eq.sym x≈y) p))) ... | no ¬p | no ¬p₁ = x₁≈y₁ ∷ insert-cong-≋ x≈y xs≋ys insert-stop : ∀ {x y} ys → x ≤ y → insert x (y ∷ ys) ≋ x ∷ y ∷ ys insert-stop {x} {y} ys x≤y with x ≤? y ... | yes _ = ≋-refl ... | no x≰y = ⊥-elim (x≰y x≤y) insert-into : ∀ {x y} ys → x ≰ y → insert x (y ∷ ys) ≋ y ∷ insert x ys insert-into {x} {y} ys x≰y with x ≤? y ... | yes x≤y = ⊥-elim (x≰y x≤y) ... | no _ = ≋-refl Sorted-insert : ∀ {x xs} → Sorted (x ∷ xs) → insert x xs ≋ x ∷ xs Sorted-insert {x} {[]} _ = ≋-refl Sorted-insert {x} {y ∷ ys} (x≤y ∷ _) = insert-stop ys x≤y sort-Sorted-id : ∀ xs → Sorted xs → sort xs ≋ xs sort-Sorted-id [] xs-Sorted = ≋-refl sort-Sorted-id (x ∷ xs) x∷xs-Sorted = begin sort (x ∷ xs) ≡⟨⟩ insert x (sort xs) ≈⟨ insert-cong-≋ Eq.refl (sort-Sorted-id xs (Linked-∷⁻ʳ x∷xs-Sorted)) ⟩ insert x xs ≈⟨ Sorted-insert x∷xs-Sorted ⟩ x ∷ xs ∎ where open SetoidReasoning ≋-setoid sort-idem : ∀ xs → sort (sort xs) ≋ sort xs sort-idem xs = sort-Sorted-id (sort xs) (sort-Sorted xs) module _ where open SetoidReasoning ≋-setoid insert-swap : ∀ x y xs → insert x (insert y xs) ≋ insert y (insert x xs) insert-swap x y [] with x ≤? y | y ≤? x ... | yes x≤y | yes y≤x = x≈y ∷ Eq.sym x≈y ∷ [] where x≈y = antisym x≤y y≤x ... | yes _ | no _ = ≋-refl ... | no _ | yes _ = ≋-refl ... | no x≰y | no y≰x = ⊥-elim $ ≰∧≱⇒⊥ x≰y y≰x insert-swap x y (z ∷ zs) with y ≤? z | x ≤? z insert-swap x y (z ∷ zs) | yes _ | yes _ with x ≤? y | y ≤? x insert-swap x y (z ∷ zs) | yes y≤z | yes x≤z | yes x≤y | yes y≤x = x≈y ∷ Eq.sym x≈y ∷ ≋-refl where x≈y = antisym x≤y y≤x insert-swap x y (z ∷ zs) | yes y≤z | yes _ | yes _ | no _ = begin x ∷ y ∷ z ∷ zs ≈˘⟨ Eq.refl ∷ insert-stop zs y≤z ⟩ x ∷ insert y (z ∷ zs) ∎ insert-swap x y (z ∷ zs) | yes _ | yes x≤z | no _ | yes _ = begin y ∷ insert x (z ∷ zs) ≈⟨ Eq.refl ∷ insert-stop zs x≤z ⟩ y ∷ x ∷ z ∷ zs ∎ insert-swap x y (z ∷ zs) | yes y≤z | yes x≤z | no x≰y | no y≰x = ⊥-elim $ ≰∧≱⇒⊥ x≰y y≰x insert-swap x y (z ∷ zs) | yes _ | no _ with x ≤? y insert-swap x y (z ∷ zs) | yes y≤z | no x≰z | yes x≤y = ⊥-elim $ x≰z (trans x≤y y≤z) insert-swap x y (z ∷ zs) | yes y≤z | no x≰z | no x≰y = begin y ∷ insert x (z ∷ zs) ≈⟨ Eq.refl ∷ insert-into zs x≰z ⟩ y ∷ z ∷ insert x zs ≈˘⟨ insert-stop (insert x zs) y≤z ⟩ insert y (z ∷ insert x zs) ∎ insert-swap x y (z ∷ zs) | no _ | yes _ with y ≤? x insert-swap x y (z ∷ zs) | no y≰z | yes x≤z | yes y≤x = ⊥-elim (y≰z (trans y≤x x≤z)) insert-swap x y (z ∷ zs) | no y≰z | yes x≤z | no _ = begin insert x (z ∷ insert y zs) ≈⟨ insert-stop (insert y zs) x≤z ⟩ x ∷ z ∷ insert y zs ≈˘⟨ Eq.refl ∷ insert-into zs y≰z ⟩ x ∷ insert y (z ∷ zs) ∎ insert-swap x y (z ∷ zs) | no y≰z | no x≰z = begin insert x (z ∷ insert y zs) ≈⟨ insert-into (insert y zs) x≰z ⟩ z ∷ insert x (insert y zs) ≈⟨ Eq.refl ∷ insert-swap x y zs ⟩ z ∷ insert y (insert x zs) ≈˘⟨ insert-into (insert x zs) y≰z ⟩ insert y (z ∷ insert x zs) ∎ sort-cong-↭-≋ : ∀ {xs ys} → xs ↭ ys → sort xs ≋ sort ys sort-cong-↭-≋ {xs} {.xs} PSrefl = ≋-refl sort-cong-↭-≋ {_ ∷ _} {_ ∷ _} (prep eq xs↭ys) = insert-cong-≋ eq (sort-cong-↭-≋ xs↭ys) sort-cong-↭-≋ {x ∷ y ∷ xs} {y′ ∷ x′ ∷ ys} (swap eq₁ eq₂ xs↭ys) = begin insert x (insert y (sort xs)) ≈⟨ insert-cong-≋ eq₁ (insert-cong-≋ eq₂ (sort-cong-↭-≋ xs↭ys)) ⟩ insert x′ (insert y′ (sort ys)) ≈⟨ insert-swap x′ y′ (sort ys) ⟩ insert y′ (insert x′ (sort ys)) ∎ where open SetoidReasoning ≋-setoid sort-cong-↭-≋ {xs} {ys} (PStrans {ys = zs} xs↭zs zs↭ys) = begin sort xs ≈⟨ sort-cong-↭-≋ xs↭zs ⟩ sort zs ≈⟨ sort-cong-↭-≋ zs↭ys ⟩ sort ys ∎ where open SetoidReasoning ≋-setoid Sorted-unique : ∀ {xs ys} → xs ↭ ys → Sorted xs → Sorted ys → xs ≋ ys Sorted-unique {xs} {ys} xs↭ys ixs iys = begin xs ≈⟨ ≋-sym $ sort-Sorted-id xs ixs ⟩ sort xs ≈⟨ sort-cong-↭-≋ xs↭ys ⟩ sort ys ≈⟨ sort-Sorted-id ys iys ⟩ ys ∎ where open SetoidReasoning ≋-setoid
If $c \neq 0$, then the constant function $f(x) = c$ is in the linear span of $f$ if and only if the constant function $f(x) = 1$ is in the linear span of $f$.
submodule(nf_flatten_layer) nf_flatten_layer_submodule !! This module provides the concrete flatten layer type. !! It is used internally by the layer type. !! It is not intended to be used directly by the user. use nf_base_layer, only: base_layer implicit none contains elemental module function flatten_layer_cons() result(res) type(flatten_layer) :: res end function flatten_layer_cons pure module subroutine backward(self, input, gradient) class(flatten_layer), intent(in out) :: self real, intent(in) :: input(:,:,:) real, intent(in) :: gradient(:) self % gradient = reshape(gradient, shape(input)) end subroutine backward pure module subroutine forward(self, input) class(flatten_layer), intent(in out) :: self real, intent(in) :: input(:,:,:) self % output = pack(input, .true.) end subroutine forward module subroutine init(self, input_shape) class(flatten_layer), intent(in out) :: self integer, intent(in) :: input_shape(:) self % input_shape = input_shape self % output_size = product(input_shape) allocate(self % gradient(input_shape(1), input_shape(2), input_shape(3))) self % gradient = 0 allocate(self % output(self % output_size)) self % output = 0 end subroutine init end submodule nf_flatten_layer_submodule
function varargout = quantumstates(varargin) %QUANTUMSTATES Compute and plot Schroedinger eigenstates. % This program computes and plots eigenvalues lambda and eigenfunctions u % for the equation Lu = lambda*u, where L is the Schroedinger operator % defined by Lu(x) = -h^2*u"(x) + V(x)*u(x). Here h is a small parameter % and the potential function V is given as a Chebfun. The domain of the % problem is the domain of V, with boundary conditions u=0 at both ends. % % Inputs: % % QUANTUMSTATES(V) plots 10 eigenstates for h=0.1 % QUANTUMSTATES(V, n) plots n eigenstates for h=0.1 % QUANTUMSTATES(V, h), h noninteger, plots 10 eigenstates for given h % QUANTUMSTATES(V, n, h) plots n eigenstates for given h % QUANTUMSTATES(..., 'noplot') produces no plot % % Outputs: % % D = QUANTUMSTATES(...) returns a vector D of eigenvalues % [U, D] = QUANTUMSTATES(...) returns a quasimatrix U of eigenfunctions % and a diagonal matrix of eigenvalues % % Examples: % % x = chebfun('x', [-3, 3]); % V = x.^2; % harmonic oscillator, or % V = abs(x); % absolute value, or % V = (x.^2-1).^4; % double well % Copyright 2017 by The University of Oxford and The Chebfun Developers. % See http://www.chebfun.org/ for Chebfun information. % Nick Trefethen, January 2012 %% Parsing of inputs: noplot = strcmpi(varargin{nargin}, 'noplot'); % check for no plot nargin1 = nargin; % no of input args if ( noplot ) nargin1 = nargin1 - 1; end V = varargin{1}; % potential function n = 10; % default no of states h = 0.1; % default constant if ( nargin1 == 3 ) n = varargin{2}; h = varargin{3}; end if ( nargin1 == 2 ) v2 = varargin{2}; if ( v2 == round(v2) ) n = v2; else h = v2; end end %% Eigenvalue computation: [xmin, xmax] = domain(V); % domain of problem % Create a CHEBOP with Dirichlet BCs L = chebop([xmin, xmax]); L.lbc = 0; L.rbc = 0; L.op = @(x,u) -h^2*diff(u,2) + V.*u; % Schroedinger operator [U, D] = eigs(L, n, 'sr'); % compute evals/efuns d = diag(D); % vector of evals [d, ii] = sort(d); % sort them U = U(:,ii); %% Outputs: if ( nargout == 2 ) varargout = {U, diag(d)}; else varargout = {d}; end if ( noplot ) % If we're not plotting, then we return. return end %% Plot: holdState = ishold; % Plot the potential function: LW = 'linewidth'; lw = 1; plot(V, 'k', LW, lw, 'jumpline', '-k'), hold on s = sprintf('h = %4g %d eigenstates', h, n); title(s, 'fontsize', 12) % Vertical limits: ymax = max(d); ymin = min(V); ydiff = ymax - ymin; ymax = ymax + .2*ydiff; ymin = ymin - 0*ydiff; % V values at endpoints: Vxmin = feval(V, xmin); Vxmax = feval(V, xmax); if ( ymax > Vxmin ) % The potential plot(xmin*[1 1], [ymax, Vxmin], 'k', LW, lw) % V(x) effectively end % goes to infinity if ( ymax > Vxmax ) % at the endpoints, plot(xmax*[1 1], [ymax Vxmax], 'k', LW, lw) % so we make the end % plot show this. dx = .05*(xmax - xmin); dy = .25*ydiff/max(5, n); % Plot the eigenfunction, lifted by the corresponding eigenvalue: W = dy*U; W = num2cell(W); for j = 1:n umm = minandmax(W{j}); if ( umm(2) < -umm(1) ) W{j} = -W{j}; end W{j} = W{j} + d(j); end W = horzcat(W{:}); plot(W, LW, lw) % Plot V(x) again (so that black ends up on top): plot(V, 'k', LW, lw, 'jumpline', '-k') if ( ymax > Vxmin ) plot(xmin*[1, 1], [ymax, Vxmin], 'k', LW, lw) end if ( ymax > Vxmax ) plot(xmax*[1, 1], [ymax Vxmax], 'k', LW, lw) end % Set axis: axis([xmin - dx, xmax + dx, ymin - dy, ymax]), drawnow if ( ~holdState ) % Stop holding: hold off end end
Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 1 entry: +Offset +Info +Type +Sym\.Value +Sym\. Name \+ Addend 0*12340000 +[0-9a-f]+ +R_.*_COPY +0*12340000 +foo \+ 0
Require Export Iron.Language.SystemF2Cap.Type. Require Export Iron.Language.SystemF2Cap.Value. Require Export Iron.Language.SystemF2Cap.Store.Bind. (********************************************************************) (* Small Step Evaluation (pure rules) These are pure transitions that don't depend on the store. *) Inductive StepP : exp -> exp -> Prop := (* Value application. *) | SpAppSubst : forall t11 x12 v2 , StepP (XApp (VLam t11 x12) v2) (substVX 0 v2 x12) (* Type application. *) | SpAPPSubst : forall k11 x12 t2 , StepP (XAPP (VLAM k11 x12) t2) (substTX 0 t2 x12) (* Take the successor of a natural. *) | SpSucc : forall n , StepP (XOp1 OSucc (VConst (CNat n))) (XVal (VConst (CNat (S n)))) (* Test a natural for zero. *) | SpIsZero : forall n , StepP (XOp1 OIsZero (VConst (CNat n))) (XVal (VConst (CBool (beq_nat n 0)))). Hint Constructors StepP. (********************************************************************) (* Preservation for pure single step rules. *) Lemma stepp_preservation : forall se sp x x' t e , StepP x x' -> Forall ClosedT se -> TypeX nil nil se sp x t e -> TypeX nil nil se sp x' t e. Proof. intros se sp x x' t e HS HC HT. gen t e. induction HS; intros; inverts_type; rip. - Case "SpAppSubst". eapply subst_val_exp; eauto. - Case "SpAPPSubst". rrwrite (TBot KEffect = substTT 0 t2 (TBot KEffect)). have HTE: (nil = substTE 0 t2 nil). have HSE: (se = substTE 0 t2 se) by (symmetry; auto). rewrite HTE. rewrite HSE. lets D: subst_type_exp H4 H8. rrwrite (liftTE 0 se = se). simpl in D. simpl. auto. - Case "SpSucc". snorm. inverts H5. auto. - Case "SpIsZero". snorm. inverts H5. auto. Qed.
```python import numpy as np import tensorflow as tf import scipy.stats as spst ``` ```python from sif.models.sigmoid import sigmoid ``` ```python import matplotlib.pyplot as plt %matplotlib inline ``` # Introduction In this notebook, I will explore preconditioning of Langevin dynamics. The Langevin equation can be preconditioned and maintain the same stationary distribution through the following modification. \begin{align} \mathop{d}\theta_t = -\mathbf{M}\nabla_\theta V(\theta_t) + \sqrt{2\mathbf{M}} \mathop{d}B_t \end{align} where $\mathbf{M}$ is a preconditioning matrix. In this notebook, rather than define the potential well via numpy, I will specify the log-posterior ($V(\theta_t)$) directly in TensorFlow and exploit automatic differentiation in order to obtain the gradient ($\nabla_\theta V(\theta_t)$). ```python def inference(x_ph, n_feats, n_classes): if n_classes == 2: n_classes -= 1 with tf.name_scope("linear"): weights = tf.Variable(tf.zeros([n_feats, n_classes], name='weights')) logits = tf.matmul(x_ph, weights) return logits, weights ``` ```python def loss(labels_ph, logits, weights, l2_reg): if logits.get_shape()[1].value == 1: labels = tf.to_float(labels_ph) nll = tf.reduce_sum(tf.nn.sigmoid_cross_entropy_with_logits( labels=labels, logits=tf.squeeze(logits))) else: labels = tf.to_int64(labels_ph) nll = tf.losses.sparse_softmax_cross_entropy( labels=labels, logits=logits) reg = l2_reg * tf.reduce_sum(tf.square(weights)) return nll + reg ``` Define constants. ```python n_feats = 2 n_classes = 2 ``` Define placeholders. ```python x_ph = tf.placeholder(tf.float32, [None, n_feats]) labels_ph = tf.placeholder(tf.int32, [None]) ``` Define potential well. ```python logits, weights = inference(x_ph, n_feats, n_classes) V = loss(labels_ph, logits, weights, 0.5) ``` Compute gradient of the potential well. ```python grad_V = tf.gradients(V, [weights]) opt = tf.train.GradientDescentOptimizer(learning_rate=1e-3) ``` ```python grads_and_vars = opt.compute_gradients(V, [weights]) langevin_grads_and_vars = [ (g + np.sqrt(2) * tf.random.normal(g.get_shape(), stddev=1/np.sqrt(opt._learning_rate)), v) for g, v in grads_and_vars] train_op = opt.apply_gradients(langevin_grads_and_vars) ``` With the TensorFlow computational graph defined, we can proceed to applying the usual (un-preconditioned) Langevin dynamics equation to sample from this distribution. ```python np.random.seed(0) n = 500 x = np.random.normal(scale=2, size=(n, n_feats)) theta_star = np.array([2, -1]) y = np.random.binomial(1, sigmoid(x.dot(theta_star))) ``` ```python sess = tf.Session() sess.run(tf.global_variables_initializer()) ``` ```python n_samples = 5000 n_thin = 10 Theta = np.zeros((n_samples, n_feats)) ``` ```python sample_index = 0 for i in range(n_samples*n_thin): sess.run(train_op, {x_ph: x, labels_ph: y}) if (i+1) % n_thin == 0: Theta[sample_index] = sess.run(weights).ravel() sample_index += 1 ``` ```python kernel = spst.gaussian_kde(Theta.T) bounds_min, bounds_max = Theta.min(axis=0), Theta.max(axis=0) n_grid = 30 Theta_1_grid, Theta_2_grid = np.meshgrid( np.linspace(bounds_min[0], bounds_max[0], n_grid), np.linspace(bounds_min[1], bounds_max[1], n_grid)) Theta_grid = np.vstack([Theta_1_grid.ravel(), Theta_2_grid.ravel()]) f_grid = np.reshape(kernel(Theta_grid), Theta_1_grid.shape) ``` ```python plt.figure(figsize=(7, 7)) plt.grid() plt.contourf(Theta_1_grid, Theta_2_grid, f_grid, cmap='Blues') cset = plt.contour(Theta_1_grid, Theta_2_grid, f_grid, colors="k") plt.clabel(cset, inline=1, fontsize=14) plt.xlabel("$\\theta_1$", fontsize=18) plt.ylabel("$\\theta_2$", fontsize=18) plt.title("Stationary Distribution of Stochastic Dynamics", fontsize=18) plt.show() ``` ```python Theta ``` array([[ 1.72888517, -0.67463535], [ 1.7779882 , -0.69420904], [ 1.7275157 , -0.70228869], ..., [ 2.068645 , -0.74573219], [ 2.02805161, -0.8651185 ], [ 1.94896173, -0.72809547]]) ```python # sess.close() ``` ```python ``` ```python ``` ```python ```
From Hammer Require Import Hammer. Require Import OrderedType Orders. Set Implicit Arguments. Module Type OrderedTypeOrig := OrderedType.OrderedType. Module Type OrderedTypeAlt. Parameter t : Type. Parameter compare : t -> t -> comparison. Infix "?=" := compare (at level 70, no associativity). Parameter compare_sym : forall x y, (y?=x) = CompOpp (x?=y). Parameter compare_trans : forall c x y z, (x?=y) = c -> (y?=z) = c -> (x?=z) = c. End OrderedTypeAlt. Module Update_OT (O:OrderedTypeOrig) <: OrderedType. Include Update_DT O. Definition lt := O.lt. Instance lt_strorder : StrictOrder lt. Proof. hammer_hook "OrdersAlt" "OrdersAlt.Update_OT.lt_strorder". split. intros x Hx. apply (O.lt_not_eq Hx); auto with *. exact O.lt_trans. Qed. Instance lt_compat : Proper (eq==>eq==>iff) lt. Proof. hammer_hook "OrdersAlt" "OrdersAlt.Update_OT.lt_compat". apply proper_sym_impl_iff_2; auto with *. intros x x' Hx y y' Hy H. assert (H0 : lt x' y). destruct (O.compare x' y) as [H'|H'|H']; auto. elim (O.lt_not_eq H). transitivity x'; auto with *. elim (O.lt_not_eq (O.lt_trans H H')); auto. destruct (O.compare x' y') as [H'|H'|H']; auto. elim (O.lt_not_eq H). transitivity x'; auto with *. transitivity y'; auto with *. elim (O.lt_not_eq (O.lt_trans H' H0)); auto with *. Qed. Definition compare x y := match O.compare x y with | EQ _ => Eq | LT _ => Lt | GT _ => Gt end. Lemma compare_spec : forall x y, CompSpec eq lt x y (compare x y). Proof. hammer_hook "OrdersAlt" "OrdersAlt.Update_OT.compare_spec". intros; unfold compare; destruct O.compare; auto. Qed. End Update_OT. Module Backport_OT (O:OrderedType) <: OrderedTypeOrig. Include Backport_DT O. Definition lt := O.lt. Lemma lt_not_eq : forall x y, lt x y -> ~eq x y. Proof. hammer_hook "OrdersAlt" "OrdersAlt.Backport_OT.lt_not_eq". intros x y L E; rewrite E in L. apply (StrictOrder_Irreflexive y); auto. Qed. Lemma lt_trans : Transitive lt. Proof. hammer_hook "OrdersAlt" "OrdersAlt.Backport_OT.lt_trans". apply O.lt_strorder. Qed. Definition compare : forall x y, Compare lt eq x y. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OrderedTypeAlt.compare". intros x y; destruct (CompSpec2Type (O.compare_spec x y)); [apply EQ|apply LT|apply GT]; auto. Defined. End Backport_OT. Module OT_from_Alt (Import O:OrderedTypeAlt) <: OrderedType. Definition t := t. Definition eq x y := (x?=y) = Eq. Definition lt x y := (x?=y) = Lt. Instance eq_equiv : Equivalence eq. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_from_Alt.eq_equiv". split; red. unfold eq; intros x. assert (H:=compare_sym x x). destruct (x ?= x); simpl in *; auto; discriminate. unfold eq; intros x y H. rewrite compare_sym, H; simpl; auto. apply compare_trans. Qed. Instance lt_strorder : StrictOrder lt. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_from_Alt.lt_strorder". split; repeat red; unfold lt; try apply compare_trans. intros x H. assert (eq x x) by reflexivity. unfold eq in *; congruence. Qed. Lemma lt_eq : forall x y z, lt x y -> eq y z -> lt x z. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_from_Alt.lt_eq". unfold lt, eq; intros x y z Hxy Hyz. destruct (compare x z) eqn:Hxz; auto. rewrite compare_sym, CompOpp_iff in Hyz. simpl in Hyz. rewrite (compare_trans Hxz Hyz) in Hxy; discriminate. rewrite compare_sym, CompOpp_iff in Hxy. simpl in Hxy. rewrite (compare_trans Hxy Hxz) in Hyz; discriminate. Qed. Lemma eq_lt : forall x y z, eq x y -> lt y z -> lt x z. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_from_Alt.eq_lt". unfold lt, eq; intros x y z Hxy Hyz. destruct (compare x z) eqn:Hxz; auto. rewrite compare_sym, CompOpp_iff in Hxy. simpl in Hxy. rewrite (compare_trans Hxy Hxz) in Hyz; discriminate. rewrite compare_sym, CompOpp_iff in Hyz. simpl in Hyz. rewrite (compare_trans Hxz Hyz) in Hxy; discriminate. Qed. Instance lt_compat : Proper (eq==>eq==>iff) lt. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_from_Alt.lt_compat". apply proper_sym_impl_iff_2; auto with *. repeat red; intros. eapply lt_eq; eauto. eapply eq_lt; eauto. symmetry; auto. Qed. Definition compare := O.compare. Lemma compare_spec : forall x y, CompSpec eq lt x y (compare x y). Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_from_Alt.compare_spec". unfold eq, lt, compare; intros. destruct (O.compare x y) eqn:H; auto. apply CompGt. rewrite compare_sym, H; auto. Qed. Definition eq_dec : forall x y, { eq x y } + { ~ eq x y }. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_from_Alt.eq_dec". intros; unfold eq. case (x ?= y); [ left | right | right ]; auto; discriminate. Defined. End OT_from_Alt. Module OT_to_Alt (Import O:OrderedType) <: OrderedTypeAlt. Definition t := t. Definition compare := compare. Infix "?=" := compare (at level 70, no associativity). Lemma compare_sym : forall x y, (y?=x) = CompOpp (x?=y). Proof. hammer_hook "OrdersAlt" "OrdersAlt.OrderedTypeAlt.compare_sym". intros x y; unfold compare. destruct (compare_spec x y) as [U|U|U]; destruct (compare_spec y x) as [V|V|V]; auto. rewrite U in V. elim (StrictOrder_Irreflexive y); auto. rewrite U in V. elim (StrictOrder_Irreflexive y); auto. rewrite V in U. elim (StrictOrder_Irreflexive x); auto. rewrite V in U. elim (StrictOrder_Irreflexive x); auto. rewrite V in U. elim (StrictOrder_Irreflexive x); auto. rewrite V in U. elim (StrictOrder_Irreflexive y); auto. Qed. Lemma compare_Eq : forall x y, compare x y = Eq <-> eq x y. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_to_Alt.compare_Eq". unfold compare. intros x y; destruct (compare_spec x y); intuition; try discriminate. rewrite H0 in H. elim (StrictOrder_Irreflexive y); auto. rewrite H0 in H. elim (StrictOrder_Irreflexive y); auto. Qed. Lemma compare_Lt : forall x y, compare x y = Lt <-> lt x y. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_to_Alt.compare_Lt". unfold compare. intros x y; destruct (compare_spec x y); intuition; try discriminate. rewrite H in H0. elim (StrictOrder_Irreflexive y); auto. rewrite H in H0. elim (StrictOrder_Irreflexive x); auto. Qed. Lemma compare_Gt : forall x y, compare x y = Gt <-> lt y x. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OT_to_Alt.compare_Gt". intros x y. rewrite compare_sym, CompOpp_iff. apply compare_Lt. Qed. Lemma compare_trans : forall c x y z, (x?=y) = c -> (y?=z) = c -> (x?=z) = c. Proof. hammer_hook "OrdersAlt" "OrdersAlt.OrderedTypeAlt.compare_trans". intros c x y z. destruct c; unfold compare; rewrite ?compare_Eq, ?compare_Lt, ?compare_Gt; transitivity y; auto. Qed. End OT_to_Alt.
############################################################################# # transpose.jl # Returns the transpose of a matrix # All expressions and atoms are subtpyes of AbstractExpr. # Please read expressions.jl first. ############################################################################# import Base.transpose, Base.adjoint struct TransposeAtom <: AbstractExpr head::Symbol id_hash::UInt64 children::Tuple{AbstractExpr} size::Tuple{Int,Int} function TransposeAtom(x::AbstractExpr) children = (x,) return new(:transpose, hash(children), children, (x.size[2], x.size[1])) end end function sign(x::TransposeAtom) return sign(x.children[1]) end function monotonicity(x::TransposeAtom) return (Nondecreasing(),) end function curvature(x::TransposeAtom) return ConstVexity() end function evaluate(x::TransposeAtom) return transpose(evaluate(x.children[1])) end # Since everything is vectorized, we simply need to multiply x by a permutation # matrix such that coeff * vectorized(x) - vectorized(x') = 0 function conic_form!(x::TransposeAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = conic_form!(x.children[1], unique_conic_forms) sz = length(x) num_rows = x.size[1] num_cols = x.size[2] I = Array{Int}(undef, sz) J = Array{Int}(undef, sz) k = 1 for r in 1:num_rows for c in 1:num_cols I[k] = (c - 1) * num_rows + r J[k] = (r - 1) * num_cols + c k += 1 end end transpose_matrix = sparse(I, J, 1.0) objective = transpose_matrix * objective cache_conic_form!(unique_conic_forms, x, objective) end return get_conic_form(unique_conic_forms, x) end transpose(x::AbstractExpr) = TransposeAtom(x) struct AdjointAtom <: AbstractExpr head::Symbol id_hash::UInt64 children::Tuple{AbstractExpr} size::Tuple{Int,Int} function AdjointAtom(x::AbstractExpr) children = (x,) return new(:adjoint, hash(children), children, (x.size[2], x.size[1])) end end function sign(x::AdjointAtom) return sign(x.children[1]) end function monotonicity(x::AdjointAtom) return (Nondecreasing(),) end function curvature(x::AdjointAtom) return ConstVexity() end function evaluate(x::AdjointAtom) return evaluate(x.children[1])' end # Since everything is vectorized, we simply need to multiply x by a permutation # matrix such that coeff * vectorized(x) - vectorized(x') = 0 function conic_form!(x::AdjointAtom, unique_conic_forms::UniqueConicForms) if !has_conic_form(unique_conic_forms, x) objective = conic_form!(x.children[1], unique_conic_forms) sz = length(x) num_rows = x.size[1] num_cols = x.size[2] I = Array{Int}(undef, sz) J = Array{Int}(undef, sz) k = 1 for r in 1:num_rows for c in 1:num_cols I[k] = (c - 1) * num_rows + r J[k] = (r - 1) * num_cols + c k += 1 end end transpose_matrix = sparse(I, J, 1.0) objective = transpose_matrix * objective for var in keys(objective) x1 = conj(objective[var][1]) x2 = conj(objective[var][2]) objective[var] = (x1, x2) end cache_conic_form!(unique_conic_forms, x, objective) end return get_conic_form(unique_conic_forms, x) end adjoint(x::AbstractExpr) = AdjointAtom(x) adjoint(x::Constant) = Constant(x.value')
module Main tstr : String tstr = "abc123" tlist : List Int tlist = [1, 2, 3, 4, 5] main : IO () main = do printLn (abs (-8)) printLn (span isAlpha tstr) printLn (break isDigit tstr) printLn (span (\x => x < 3) tlist) printLn (break (\x => x > 2) tlist)
# NRPy+'s Reference Metric Interface ## Author: Zach Etienne ### Formatting improvements courtesy Brandon Clark ### NRPy+ Source Code for this module: [reference_metric.py](../edit/reference_metric.py) ## Introduction: ### Why use a reference metric? Benefits of choosing the best coordinate system for the problem When solving a partial differential equation on the computer, it is useful to first pick a coordinate system well-suited to the geometry of the problem. For example, if we are modeling a spherically-symmetric star, it would be hugely wasteful to model the star in 3-dimensional Cartesian coordinates ($x$,$y$,$z$). This is because in Cartesian coordinates, we would need to choose high sampling in all three Cartesian directions. If instead we chose to model the star in spherical coordinates ($r$,$\theta$,$\phi$), so long as the star is centered at $r=0$, we would not need to model the star with more than one point in the $\theta$ and $\phi$ directions! A similar argument holds for stars that are *nearly* spherically symmetric. Such stars may exhibit density distributions that vary slowly in $\theta$ and $\phi$ directions (e.g., isolated neutron stars or black holes). In these cases the number of points needed to sample the angular directions will still be much smaller than in the radial direction. Thus choice of an appropriate reference metric may directly mitigate the [Curse of Dimensionality](https://en.wikipedia.org/wiki/Curse_of_dimensionality). <a id='toc'></a> # Table of Contents $$\label{toc}$$ This notebook is organized as follow 1. [Step 1](#define_ref_metric): Defining a reference metric, [`reference_metric.py`](../edit/reference_metric.py) 1. [Step 2](#define_geometric): Defining geometric quantities, **`ref_metric__hatted_quantities()`** 1. [Step 3](#prescribed_ref_metric): Prescribed reference metrics in [`reference_metric.py`](../edit/reference_metric.py) 1. [Step 3.a](#sphericallike): Spherical-like coordinate systems 1. [Step 3.a.i](#spherical): **`reference_metric::CoordSystem = "Spherical"`** 1. [Step 3.a.ii](#sinhspherical): **`reference_metric::CoordSystem = "SinhSpherical"`** 1. [Step 3.a.iii](#sinhsphericalv2): **`reference_metric::CoordSystem = "SinhSphericalv2"`** 1. [Step 3.b](#cylindricallike): Cylindrical-like coordinate systems 1. [Step 3.b.i](#cylindrical): **`reference_metric::CoordSystem = "Cylindrical"`** 1. [Step 3.b.ii](#sinhcylindrical): **`reference_metric::CoordSystem = "SinhCylindrical"`** 1. [Step 3.b.iii](#sinhcylindricalv2): **`reference_metric::CoordSystem = "SinhCylindricalv2"`** 1. [Step 3.c](#cartesianlike): Cartesian-like coordinate systems 1. [Step 3.c.i](#cartesian): **`reference_metric::CoordSystem = "Cartesian"`** 1. [Step 3.d](#prolatespheroidal): Prolate spheroidal coordinates 1. [Step 3.d.i](#symtp): **`reference_metric::CoordSystem = "SymTP"`** 1. [Step 3.d.ii](#sinhsymtp): **`reference_metric::CoordSystem = "SinhSymTP"`** 1. [Step 4](#latex_pdf_output): Output this notebook to $\LaTeX$-formatted PDF file <a id='define_ref_metric'></a> # Step 1: Defining a reference metric, [`reference_metric.py`](../edit/reference_metric.py) \[Back to [top](#toc)\] $$\label{define_ref_metric}$$ ***Note that currently only orthogonal reference metrics of dimension 3 or fewer are supported. This can be extended if desired.*** NRPy+ assumes all curvilinear coordinate systems map directly from a uniform, Cartesian numerical grid with coordinates $(x,y,z)$=(`xx[0]`,`xx[1]`,`xx[2]`). Thus when defining reference metrics, all defined coordinate quantities must be in terms of the `xx[]` array. As we will see, this adds a great deal of flexibility For example, [**reference_metric.py**](../edit/reference_metric.py) requires that the *orthogonal coordinate scale factors* be defined. As described [here](https://en.wikipedia.org/wiki/Curvilinear_coordinates), the $i$th scale factor is the positive root of the metric element $g_{ii}$. In ordinary spherical coordinates $(r,\theta,\phi)$, with line element $ds^2 = g_{ij} dx^i dx^j = dr^2+ r^2 d \theta^2 + r^2 \sin^2\theta \ d\phi^2$, we would first define * $r = xx_0$ * $\theta = xx_1$ * $\phi = xx_2$, so that the scale factors are defined as * `scalefactor_orthog[0]` = $1$ * `scalefactor_orthog[1]` = $r$ * `scalefactor_orthog[2]` = $r \sin \theta$ Here is the corresponding code: ```python import sympy as sp # SymPy: The Python computer algebra package upon which NRPy+ depends import NRPy_param_funcs as par # NRPy+: parameter interface import reference_metric as rfm # NRPy+: Reference metric support r = rfm.xx[0] th = rfm.xx[1] ph = rfm.xx[2] rfm.scalefactor_orthog[0] = 1 rfm.scalefactor_orthog[1] = r rfm.scalefactor_orthog[2] = r*sp.sin(th) # Notice that the scale factor will be given # in terms of the fundamental Cartesian # grid variables, and not {r,th,ph}: print("r*sin(th) = "+str(rfm.scalefactor_orthog[2])) ``` r*sin(th) = xx0*sin(xx1) Next suppose we wish to modify our radial coordinate $r(xx_0)$ to be an exponentially increasing function, so that our numerical grid $(xx_0,xx_1,xx_2)$ will map to a spherical grid with radial grid spacing ($\Delta r$) that *increases* with $r$. Generally we will find it useful to define $r(xx_0)$ to be an odd function, so let's choose $$r(xx_0) = a \sinh(xx_0/s),$$ where $a$ is an overall radial scaling factor, and $s$ denotes the scale (in units of $xx_0$) over which exponential growth will take place. In our implementation below, note that we use the relation $$\sinh(x) = \frac{e^x - e^{-x}}{2},$$ as SymPy finds it easier to evaluate exponentials than hyperbolic trigonometric functions. ```python a,s = sp.symbols('a s',positive=True) xx0_rescaled = rfm.xx[0] / s r = a*(sp.exp(xx0_rescaled) - sp.exp(-xx0_rescaled))/2 # Must redefine the scalefactors since 'r' has been updated! rfm.scalefactor_orthog[0] = 1 rfm.scalefactor_orthog[1] = r rfm.scalefactor_orthog[2] = r*sp.sin(th) print(rfm.scalefactor_orthog[2]) ``` a*(exp(xx0/s) - exp(-xx0/s))*sin(xx1)/2 Often we will find it useful to also define the appropriate mappings from (`xx[0]`,`xx[1]`,`xx[2]`) to Cartesian coordinates (for plotting purposes) and ordinary spherical coordinates (e.g., in case initial data when solving a PDE are naturally written in spherical coordinates). For this purpose, reference_metric.py also declares lists **`xxCart[]`** and **`xxSph[]`**, which in this case are defined as ```python rfm.xxSph[0] = r rfm.xxSph[1] = th rfm.xxSph[2] = ph rfm.xxCart[0] = r*sp.sin(th)*sp.cos(ph) rfm.xxCart[1] = r*sp.sin(th)*sp.sin(ph) rfm.xxCart[2] = r*sp.cos(th) # Here we show off SymPy's pretty_print() # and simplify() functions. Nice, no? sp.pretty_print(sp.simplify(rfm.xxCart[0])) ``` ⎛xx₀⎞ a⋅sin(xx₁)⋅cos(xx₂)⋅sinh⎜───⎟ ⎝ s ⎠ <a id='define_geometric'></a> # Step 2: Define geometric quantities, `ref_metric__hatted_quantities()` \[Back to [top](#toc)\] $$\label{define_geometric}$$ Once `scalefactor_orthog[]` has been defined, the function **`ref_metric__hatted_quantities()`** within [reference_metric.py](../edit/reference_metric.py) can be called to define a number of geometric quantities useful for solving PDEs in curvilinear coordinate systems. Adopting the notation of [Baumgarte, Montero, Cordero-Carrión, and Müller, PRD 87, 044026 (2012)](https://arxiv.org/abs/1211.6632), geometric quantities related to the reference metric are named "hatted" quantities, . For example, the reference metric is defined as $\hat{g}_{ij}$=`ghatDD[i][j]`: ```python rfm.ref_metric__hatted_quantities() sp.pretty_print(sp.Matrix(rfm.ghatDD)) ``` ⎡1 0 0 ⎤ ⎢ ⎥ ⎢ 2 ⎥ ⎢ ⎛ xx₀ -xx₀ ⎞ ⎥ ⎢ ⎜ ─── ─────⎟ ⎥ ⎢ 2 ⎜ s s ⎟ ⎥ ⎢ a ⋅⎝ℯ - ℯ ⎠ ⎥ ⎢0 ─────────────────── 0 ⎥ ⎢ 4 ⎥ ⎢ ⎥ ⎢ 2 ⎥ ⎢ ⎛ xx₀ -xx₀ ⎞ ⎥ ⎢ ⎜ ─── ─────⎟ ⎥ ⎢ 2 ⎜ s s ⎟ 2 ⎥ ⎢ a ⋅⎝ℯ - ℯ ⎠ ⋅sin (xx₁)⎥ ⎢0 0 ─────────────────────────────⎥ ⎣ 4 ⎦ In addition to $\hat{g}_{ij}$, **`ref_metric__hatted_quantities()`** also provides: * The rescaling "matrix" `ReDD[i][j]`, used for separating singular (due to chosen coordinate system) pieces of smooth rank-2 tensor components from the smooth parts, so that the smooth parts can be used within temporal and spatial differential operators. * Inverse reference metric: $\hat{g}^{ij}$=`ghatUU[i][j]`. * Reference metric determinant: $\det\left(\hat{g}_{ij}\right)$=`detgammahat`. * First and second derivatives of the reference metric: $\hat{g}_{ij,k}$=`ghatDD_dD[i][j][k]`; $\hat{g}_{ij,kl}$=`ghatDD_dDD[i][j][k][l]` * Christoffel symbols associated with the reference metric, $\hat{\Gamma}^i_{jk}$ = `GammahatUDD[i][j][k]` and their first derivatives $\hat{\Gamma}^i_{jk,l}$ = `GammahatUDD_dD[i][j][k][l]` For example, the Christoffel symbol $\hat{\Gamma}^{xx_1}_{xx_2 xx_2}=\hat{\Gamma}^1_{22}$ is given by `GammahatUDD[1][2][2]`: ```python sp.pretty_print(sp.simplify(rfm.GammahatUDD[1][2][2])) ``` -sin(2⋅xx₁) ──────────── 2 Given the trigonometric identity $2\sin(x)\cos(x) = \sin(2x)$, notice that the above expression is equivalent to Eq. 18 of [Baumgarte, Montero, Cordero-Carrión, and Müller, PRD 87, 044026 (2012)](https://arxiv.org/abs/1211.6632). This is expected since the sinh-radial spherical coordinate system is equivalent to ordinary spherical coordinates in the angular components. <a id='prescribed_ref_metric'></a> # Step 3: Prescribed reference metrics in [`reference_metric.py`](../edit/reference_metric.py) \[Back to [top](#toc)\] $$\label{prescribed_ref_metric}$$ One need not manually define scale factors or other quantities for reference metrics, as a number of prescribed reference metrics are already defined in [reference_metric.py](../edit/reference_metric.py). These can be accessed by first setting the parameter **reference_metric::CoordSystem** to one of the following, and then calling the function **`rfm.reference_metric()`**. ```python import indexedexp as ixp # NRPy+: Symbolic indexed expression (e.g., tensors, vectors, etc.) support import grid as gri # NRPy+: Functions having to do with numerical grids # Step 0a: Initialize parameters thismodule = __name__ par.initialize_param(par.glb_param("char", thismodule, "CoordSystem", "Spherical")) # Step 0b: Declare global variables xx = gri.xx xxCart = ixp.zerorank1(DIM=4) # Must be set in terms of xx[]s Cart_to_xx = ixp.zerorank1(DIM=4) # Must be set in terms of xx[]s Cartx,Carty,Cartz = sp.symbols("Cartx Carty Cartz", real=True) Cart = [Cartx,Carty,Cartz] xxSph = ixp.zerorank1(DIM=4) # Must be set in terms of xx[]s scalefactor_orthog = ixp.zerorank1(DIM=4) # Must be set in terms of xx[]s have_already_called_reference_metric_function = False CoordSystem = par.parval_from_str("reference_metric::CoordSystem") M_PI,M_SQRT1_2 = par.Cparameters("#define",thismodule,["M_PI","M_SQRT1_2"],"") global xxmin global xxmax global UnitVectors UnitVectors = ixp.zerorank2(DIM=3) ``` We will find the following plotting function useful for analyzing coordinate systems in which the radial coordinate is rescaled. ```python def create_r_of_xx0_plots(CoordSystem, r_of_xx0,rprime_of_xx0): import matplotlib.pyplot as plt # matplotlib: Python module specializing in plotting capabilities plt.clf() Nr = 20 dxx0 = 1.0 / float(Nr) xx0s = [] rs = [] deltars = [] rprimes = [] for i in range(Nr): xx0 = (float(i) + 0.5)*dxx0 xx0s.append(xx0) rs.append( sp.sympify(str(r_of_xx0 ).replace("xx0",str(xx0)))) rprimes.append(sp.sympify(str(rprime_of_xx0).replace("xx0",str(xx0)))) if i>0: deltars.append(sp.log(rs[i]-rs[i-1],10)) else: deltars.append(sp.log(2*rs[0],10)) # fig, ax = plt.subplots() fig = plt.figure(figsize=(12,12)) # 8 in x 8 in ax = fig.add_subplot(221) ax.set_title('$r(xx_0)$ for '+CoordSystem,fontsize='x-large') ax.set_xlabel('$xx_0$',fontsize='x-large') ax.set_ylabel('$r(xx_0)$',fontsize='x-large') ax.plot(xx0s, rs, 'k.', label='Spacing between\nadjacent gridpoints') # legend = ax.legend(loc='lower right', shadow=True, fontsize='x-large') # legend.get_frame().set_facecolor('C1') ax = fig.add_subplot(222) ax.set_title('Grid spacing for '+CoordSystem,fontsize='x-large') ax.set_xlabel('$xx_0$',fontsize='x-large') ax.set_ylabel('$\log_{10}(\Delta r)$',fontsize='x-large') ax.plot(xx0s, deltars, 'k.', label='Spacing between\nadjacent gridpoints\nin $r(xx_0)$ plot') legend = ax.legend(loc='lower right', shadow=True, fontsize='x-large') legend.get_frame().set_facecolor('C1') ax = fig.add_subplot(223) ax.set_title('$r\'(xx_0)$ for '+CoordSystem,fontsize='x-large') ax.set_xlabel('$xx_0$',fontsize='x-large') ax.set_ylabel('$r\'(xx_0)$',fontsize='x-large') ax.plot(xx0s, rprimes, 'k.', label='Nr=96') # legend = ax.legend(loc='upper left', shadow=True, fontsize='x-large') # legend.get_frame().set_facecolor('C1') plt.tight_layout(pad=2) plt.show() ``` <a id='sphericallike'></a> ## Step 3.a: Spherical-like coordinate systems \[Back to [top](#toc)\] $$\label{sphericallike}$$ <a id='spherical'></a> ### Step 3.a.i: **`reference_metric::CoordSystem = "Spherical"`** \[Back to [top](#toc)\] $$\label{spherical}$$ Standard spherical coordinates, with $(r,\theta,\phi)=(xx_0,xx_1,xx_2)$ ```python if CoordSystem == "Spherical": # Adding assumption real=True can help simplify expressions involving xx[0] & xx[1] below. xx[0] = sp.symbols("xx0", real=True) xx[1] = sp.symbols("xx1", real=True) RMAX = par.Cparameters("REAL", thismodule, ["RMAX"],10.0) xxmin = [sp.sympify(0), sp.sympify(0), -M_PI] xxmax = [ RMAX, M_PI, M_PI] r = xx[0] th = xx[1] ph = xx[2] Cart_to_xx[0] = sp.sqrt(Cartx ** 2 + Carty ** 2 + Cartz ** 2) Cart_to_xx[1] = sp.acos(Cartz / Cart_to_xx[0]) Cart_to_xx[2] = sp.atan2(Carty, Cartx) xxSph[0] = r xxSph[1] = th xxSph[2] = ph # Now define xCart, yCart, and zCart in terms of x0,xx[1],xx[2]. # Note that the relation between r and x0 is not necessarily trivial in SinhSpherical coordinates. See above. xxCart[0] = xxSph[0]*sp.sin(xxSph[1])*sp.cos(xxSph[2]) xxCart[1] = xxSph[0]*sp.sin(xxSph[1])*sp.sin(xxSph[2]) xxCart[2] = xxSph[0]*sp.cos(xxSph[1]) scalefactor_orthog[0] = sp.diff(xxSph[0],xx[0]) scalefactor_orthog[1] = xxSph[0] scalefactor_orthog[2] = xxSph[0]*sp.sin(xxSph[1]) # Set the unit vectors UnitVectors = [[ sp.sin(xxSph[1])*sp.cos(xxSph[2]), sp.sin(xxSph[1])*sp.sin(xxSph[2]), sp.cos(xxSph[1])], [ sp.cos(xxSph[1])*sp.cos(xxSph[2]), sp.cos(xxSph[1])*sp.sin(xxSph[2]), -sp.sin(xxSph[1])], [ -sp.sin(xxSph[2]), sp.cos(xxSph[2]), sp.sympify(0) ]] ``` Now let's analyze $r(xx_0)$ for **"Spherical"** coordinates. ```python %matplotlib inline CoordSystem = "Spherical" par.set_parval_from_str("reference_metric::CoordSystem",CoordSystem) rfm.reference_metric() RMAX = 10.0 r_of_xx0 = sp.sympify(str(rfm.xxSph[0] ).replace("RMAX",str(RMAX))) rprime_of_xx0 = sp.sympify(str(sp.diff(rfm.xxSph[0],rfm.xx[0])).replace("RMAX",str(RMAX))) create_r_of_xx0_plots(CoordSystem, r_of_xx0,rprime_of_xx0) ``` <a id='sinhspherical'></a> ### Step 3.a.ii: **`reference_metric::CoordSystem = "SinhSpherical"`** \[Back to [top](#toc)\] $$\label{sinhspherical}$$ Spherical coordinates, but with $$r(xx_0) = \text{AMPL} \frac{\sinh\left(\frac{xx_0}{\text{SINHW}}\right)}{\sinh\left(\frac{1}{\text{SINHW}}\right)}.$$ SinhSpherical uses two parameters: `AMPL` and `SINHW`. `AMPL` sets the outer boundary distance; and `SINHW` sets the focusing of the coordinate points near $r=0$, where a small `SINHW` ($\sim 0.125$) will greatly focus the points near $r=0$ and a large `SINHW` will look more like an ordinary spherical polar coordinate system. ```python if CoordSystem == "SinhSpherical": xxmin = [sp.sympify(0), sp.sympify(0), -M_PI] xxmax = [sp.sympify(1), M_PI, M_PI] AMPL, SINHW = par.Cparameters("REAL",thismodule,["AMPL","SINHW"],[10.0,0.2]) # Set SinhSpherical radial coordinate by default; overwrite later if CoordSystem == "SinhSphericalv2". r = AMPL * (sp.exp(xx[0] / SINHW) - sp.exp(-xx[0] / SINHW)) / \ (sp.exp(1 / SINHW) - sp.exp(-1 / SINHW)) th = xx[1] ph = xx[2] Cart_to_xx[0] = SINHW*sp.asinh(sp.sqrt(Cartx ** 2 + Carty ** 2 + Cartz ** 2)*sp.sinh(1/SINHW)/AMPL) Cart_to_xx[1] = sp.acos(Cartz / sp.sqrt(Cartx ** 2 + Carty ** 2 + Cartz ** 2)) Cart_to_xx[2] = sp.atan2(Carty, Cartx) xxSph[0] = r xxSph[1] = th xxSph[2] = ph # Now define xCart, yCart, and zCart in terms of x0,xx[1],xx[2]. # Note that the relation between r and x0 is not necessarily trivial in SinhSpherical coordinates. See above. xxCart[0] = xxSph[0]*sp.sin(xxSph[1])*sp.cos(xxSph[2]) xxCart[1] = xxSph[0]*sp.sin(xxSph[1])*sp.sin(xxSph[2]) xxCart[2] = xxSph[0]*sp.cos(xxSph[1]) scalefactor_orthog[0] = sp.diff(xxSph[0],xx[0]) scalefactor_orthog[1] = xxSph[0] scalefactor_orthog[2] = xxSph[0]*sp.sin(xxSph[1]) # Set the unit vectors UnitVectors = [[ sp.sin(xxSph[1])*sp.cos(xxSph[2]), sp.sin(xxSph[1])*sp.sin(xxSph[2]), sp.cos(xxSph[1])], [ sp.cos(xxSph[1])*sp.cos(xxSph[2]), sp.cos(xxSph[1])*sp.sin(xxSph[2]), -sp.sin(xxSph[1])], [ -sp.sin(xxSph[2]), sp.cos(xxSph[2]), sp.sympify(0) ]] ``` Now we explore $r(xx_0)$ for `SinhSpherical` assuming `AMPL=10.0` and `SINHW=0.2`: ```python %matplotlib inline CoordSystem = "SinhSpherical" par.set_parval_from_str("reference_metric::CoordSystem",CoordSystem) rfm.reference_metric() AMPL = 10.0 SINHW = 0.2 r_of_xx0 = sp.sympify(str(rfm.xxSph[0] ).replace("AMPL",str(AMPL)).replace("SINHW",str(SINHW))) rprime_of_xx0 = sp.sympify(str(sp.diff(rfm.xxSph[0],rfm.xx[0])).replace("AMPL",str(AMPL)).replace("SINHW",str(SINHW))) create_r_of_xx0_plots(CoordSystem, r_of_xx0,rprime_of_xx0) ``` <a id='sinhsphericalv2'></a> ### Step 3.a.iii: **`reference_metric::CoordSystem = "SinhSphericalv2"`** \[Back to [top](#toc)\] $$\label{sinhsphericalv2}$$ The same as SinhSpherical coordinates, but with an additional `AMPL*const_dr*xx_0` term: $$r(xx_0) = \text{AMPL} \left[\text{const_dr}\ xx_0 + \frac{\sinh\left(\frac{xx_0}{\text{SINHW}}\right)}{\sinh\left(\frac{1}{\text{SINHW}}\right)}\right].$$ ```python if CoordSystem == "SinhSphericalv2": # SinhSphericalv2 adds the parameter "const_dr", which allows for a region near xx[0]=0 to have # constant radial resolution of const_dr, provided the sinh() term does not dominate near xx[0]=0. xxmin = [sp.sympify(0), sp.sympify(0), -M_PI] xxmax = [sp.sympify(1), M_PI, M_PI] AMPL, SINHW = par.Cparameters("REAL",thismodule,["AMPL","SINHW"],[10.0,0.2]) const_dr = par.Cparameters("REAL",thismodule,["const_dr"],0.0625) r = AMPL*( const_dr*xx[0] + (sp.exp(xx[0] / SINHW) - sp.exp(-xx[0] / SINHW)) / (sp.exp(1 / SINHW) - sp.exp(-1 / SINHW)) ) th = xx[1] ph = xx[2] # NO CLOSED-FORM EXPRESSION FOR RADIAL INVERSION. # Cart_to_xx[0] = "NewtonRaphson" # Cart_to_xx[1] = sp.acos(Cartz / sp.sqrt(Cartx ** 2 + Carty ** 2 + Cartz ** 2)) # Cart_to_xx[2] = sp.atan2(Carty, Cartx) xxSph[0] = r xxSph[1] = th xxSph[2] = ph # Now define xCart, yCart, and zCart in terms of x0,xx[1],xx[2]. # Note that the relation between r and x0 is not necessarily trivial in SinhSpherical coordinates. See above. xxCart[0] = xxSph[0]*sp.sin(xxSph[1])*sp.cos(xxSph[2]) xxCart[1] = xxSph[0]*sp.sin(xxSph[1])*sp.sin(xxSph[2]) xxCart[2] = xxSph[0]*sp.cos(xxSph[1]) scalefactor_orthog[0] = sp.diff(xxSph[0],xx[0]) scalefactor_orthog[1] = xxSph[0] scalefactor_orthog[2] = xxSph[0]*sp.sin(xxSph[1]) # Set the unit vectors UnitVectors = [[ sp.sin(xxSph[1])*sp.cos(xxSph[2]), sp.sin(xxSph[1])*sp.sin(xxSph[2]), sp.cos(xxSph[1])], [ sp.cos(xxSph[1])*sp.cos(xxSph[2]), sp.cos(xxSph[1])*sp.sin(xxSph[2]), -sp.sin(xxSph[1])], [ -sp.sin(xxSph[2]), sp.cos(xxSph[2]), sp.sympify(0) ]] ``` Now we explore $r(xx_0)$ for `SinhSphericalv2` assuming `AMPL=10.0`, `SINHW=0.2`, and `const_dr=0.05`. Notice that the `const_dr` term significantly increases the grid spacing near $xx_0=0$ relative to `SinhSpherical` coordinates. ```python %matplotlib inline CoordSystem = "SinhSphericalv2" par.set_parval_from_str("reference_metric::CoordSystem",CoordSystem) rfm.reference_metric() AMPL = 10.0 SINHW = 0.2 const_dr = 0.05 r_of_xx0 = sp.sympify(str(rfm.xxSph[0] ).replace("AMPL",str(AMPL)).replace("SINHW",str(SINHW)).replace("const_dr",str(const_dr))) rprime_of_xx0 = sp.sympify(str(sp.diff(rfm.xxSph[0],rfm.xx[0])).replace("AMPL",str(AMPL)).replace("SINHW",str(SINHW)).replace("const_dr",str(const_dr))) create_r_of_xx0_plots(CoordSystem, r_of_xx0,rprime_of_xx0) ``` <a id='cylindricallike'></a> ## Step 3.b: Cylindrical-like coordinate systems \[Back to [top](#toc)\] $$\label{cylindricallike}$$ <a id='cylindrical'></a> ### Step 3.b.i: **`reference_metric::CoordSystem = "Cylindrical"`** \[Back to [top](#toc)\] $$\label{cylindrical}$$ Standard cylindrical coordinates, with $(\rho,\phi,z)=(xx_0,xx_1,xx_2)$ ```python if CoordSystem == "Cylindrical": # Assuming the cylindrical radial coordinate # is positive makes nice simplifications of # unit vectors possible. xx[0] = sp.symbols("xx0", real=True) RHOMAX,ZMIN,ZMAX = par.Cparameters("REAL",thismodule,["RHOMAX","ZMIN","ZMAX"],[10.0,-10.0,10.0]) xxmin = [sp.sympify(0), -M_PI, ZMIN] xxmax = [ RHOMAX, M_PI, ZMAX] RHOCYL = xx[0] PHICYL = xx[1] ZCYL = xx[2] Cart_to_xx[0] = sp.sqrt(Cartx ** 2 + Carty ** 2) Cart_to_xx[1] = sp.atan2(Carty, Cartx) Cart_to_xx[2] = Cartz xxCart[0] = RHOCYL*sp.cos(PHICYL) xxCart[1] = RHOCYL*sp.sin(PHICYL) xxCart[2] = ZCYL xxSph[0] = sp.sqrt(RHOCYL**2 + ZCYL**2) xxSph[1] = sp.acos(ZCYL / xxSph[0]) xxSph[2] = PHICYL scalefactor_orthog[0] = sp.diff(RHOCYL,xx[0]) scalefactor_orthog[1] = RHOCYL scalefactor_orthog[2] = sp.diff(ZCYL,xx[2]) # Set the unit vectors UnitVectors = [[ sp.cos(PHICYL), sp.sin(PHICYL), sp.sympify(0)], [-sp.sin(PHICYL), sp.cos(PHICYL), sp.sympify(0)], [ sp.sympify(0), sp.sympify(0), sp.sympify(1)]] ``` Next let's plot **"Cylindrical"** coordinates. ```python %matplotlib inline import numpy as np # NumPy: A numerical methods module for Python import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D R = np.linspace(0, 2, 24) h = 2 u = np.linspace(0, 2*np.pi, 24) x = np.outer(R, np.cos(u)) y = np.outer(R, np.sin(u)) z = h * np.outer(np.ones(np.size(u)), np.ones(np.size(u))) r = np.arange(0,2,0.25) theta = 2*np.pi*r*0 fig = plt.figure(figsize=(12,12)) # 8 in x 8 in fig, (ax1, ax2) = plt.subplots(1, 2) ax1 = plt.axes(projection='polar') ax1.set_rmax(2) ax1.set_rgrids(r,labels=[]) thetas = np.linspace(0,360,24, endpoint=True) ax1.set_thetagrids(thetas,labels=[]) # ax.grid(True) ax1.grid(True,linewidth='1.0') ax1.set_title("Top Down View") plt.show() ax2 = plt.axes(projection='3d', xticklabels=[], yticklabels=[], zticklabels=[]) #ax2.plot_surface(x,y,z, alpha=.75, cmap = 'viridis') # z in case of disk which is parallel to XY plane is constant and you can directly use h x=np.linspace(-2, 2, 100) z=np.linspace(-2, 2, 100) Xc, Zc=np.meshgrid(x, z) Yc = np.sqrt(4-Xc**2) rstride = 10 cstride = 10 ax2.plot_surface(Xc, Yc, Zc, alpha=1.0, rstride=rstride, cstride=cstride, cmap = 'viridis') ax2.plot_surface(Xc, -Yc, Zc, alpha=1.0, rstride=rstride, cstride=cstride, cmap = 'viridis') ax2.set_title("Standard Cylindrical Grid in 3D") ax2.grid(False) plt.axis('off') plt.show() ``` <a id='sinhcylindrical'></a> ### Step 3.b.ii" **`reference_metric::CoordSystem = "SinhCylindrical"`** \[Back to [top](#toc)\] $$\label{sinhcylindrical}$$ Cylindrical coordinates, but with $$\rho(xx_0) = \text{AMPLRHO} \frac{\sinh\left(\frac{xx_0}{\text{SINHWRHO}}\right)}{\sinh\left(\frac{1}{\text{SINHWRHO}}\right)}$$ and $$z(xx_2) = \text{AMPLZ} \frac{\sinh\left(\frac{xx_2}{\text{SINHWZ}}\right)}{\sinh\left(\frac{1}{\text{SINHWZ}}\right)}$$ ```python if CoordSystem == "SinhCylindrical": # Assuming the cylindrical radial coordinate # is positive makes nice simplifications of # unit vectors possible. xx[0] = sp.symbols("xx0", real=True) xxmin = [sp.sympify(0), -M_PI, sp.sympify(-1)] xxmax = [sp.sympify(1), M_PI, sp.sympify(+1)] AMPLRHO, SINHWRHO, AMPLZ, SINHWZ = par.Cparameters("REAL",thismodule, ["AMPLRHO","SINHWRHO","AMPLZ","SINHWZ"], [ 10.0, 0.2, 10.0, 0.2]) # Set SinhCylindrical radial & z coordinates by default; overwrite later if CoordSystem == "SinhCylindricalv2". RHOCYL = AMPLRHO * (sp.exp(xx[0] / SINHWRHO) - sp.exp(-xx[0] / SINHWRHO)) / (sp.exp(1 / SINHWRHO) - sp.exp(-1 / SINHWRHO)) # phi coordinate remains unchanged. PHICYL = xx[1] ZCYL = AMPLZ * (sp.exp(xx[2] / SINHWZ) - sp.exp(-xx[2] / SINHWZ)) / (sp.exp(1 / SINHWZ) - sp.exp(-1 / SINHWZ)) Cart_to_xx[0] = SINHWRHO*sp.asinh(sp.sqrt(Cartx ** 2 + Carty ** 2)*sp.sinh(1/SINHWRHO)/AMPLRHO) Cart_to_xx[1] = sp.atan2(Carty, Cartx) Cart_to_xx[2] = SINHWZ*sp.asinh(Cartz*sp.sinh(1/SINHWZ)/AMPLZ) xxCart[0] = RHOCYL*sp.cos(PHICYL) xxCart[1] = RHOCYL*sp.sin(PHICYL) xxCart[2] = ZCYL xxSph[0] = sp.sqrt(RHOCYL**2 + ZCYL**2) xxSph[1] = sp.acos(ZCYL / xxSph[0]) xxSph[2] = PHICYL scalefactor_orthog[0] = sp.diff(RHOCYL,xx[0]) scalefactor_orthog[1] = RHOCYL scalefactor_orthog[2] = sp.diff(ZCYL,xx[2]) # Set the unit vectors UnitVectors = [[ sp.cos(PHICYL), sp.sin(PHICYL), sp.sympify(0)], [-sp.sin(PHICYL), sp.cos(PHICYL), sp.sympify(0)], [ sp.sympify(0), sp.sympify(0), sp.sympify(1)]] ``` Next let's plot **"SinhCylindrical"** coordinates. ```python fig=plt.figure() plt.clf() fig = plt.figure() ax = plt.subplot(1,1,1, projection='polar') ax.set_rmax(2) Nr = 20 xx0s = np.linspace(0,2,Nr, endpoint=True) + 1.0/(2.0*Nr) rs = [] AMPLRHO = 1.0 SINHW = 0.4 for i in range(Nr): rs.append(AMPLRHO * (np.exp(xx0s[i] / SINHW) - np.exp(-xx0s[i] / SINHW)) / \ (np.exp(1.0 / SINHW) - np.exp(-1.0 / SINHW))) ax.set_rgrids(rs,labels=[]) thetas = np.linspace(0,360,25, endpoint=True) ax.set_thetagrids(thetas,labels=[]) # ax.grid(True) ax.grid(True,linewidth='1.0') plt.show() ``` <a id='sinhcylindricalv2'></a> ### Step 3.b.iii: **`reference_metric::CoordSystem = "SinhCylindricalv2"`** \[Back to [top](#toc)\] $$\label{sinhcylindricalv2}$$ Cylindrical coordinates, but with $$\rho(xx_0) = \text{AMPLRHO} \left[\text{const_drho}\ xx_0 + \frac{\sinh\left(\frac{xx_0}{\text{SINHWRHO}}\right)}{\sinh\left(\frac{1}{\text{SINHWRHO}}\right)}\right]$$ and $$z(xx_2) = \text{AMPLZ} \left[\text{const_dz}\ xx_2 + \frac{\sinh\left(\frac{xx_2}{\text{SINHWZ}}\right)}{\sinh\left(\frac{1}{\text{SINHWZ}}\right)}\right]$$ ```python if CoordSystem == "SinhCylindricalv2": # Assuming the cylindrical radial coordinate # is positive makes nice simplifications of # unit vectors possible. xx[0] = sp.symbols("xx0", real=True) # SinhCylindricalv2 adds the parameters "const_drho", "const_dz", which allows for regions near xx[0]=0 # and xx[2]=0 to have constant rho and z resolution of const_drho and const_dz, provided the sinh() terms # do not dominate near xx[0]=0 and xx[2]=0. xxmin = [sp.sympify(0), -M_PI, sp.sympify(-1)] xxmax = [sp.sympify(1), M_PI, sp.sympify(+1)] AMPLRHO, SINHWRHO, AMPLZ, SINHWZ = par.Cparameters("REAL",thismodule, ["AMPLRHO","SINHWRHO","AMPLZ","SINHWZ"], [ 10.0, 0.2, 10.0, 0.2]) const_drho, const_dz = par.Cparameters("REAL",thismodule,["const_drho","const_dz"],[0.0625,0.0625]) RHOCYL = AMPLRHO * ( const_drho*xx[0] + (sp.exp(xx[0] / SINHWRHO) - sp.exp(-xx[0] / SINHWRHO)) / (sp.exp(1 / SINHWRHO) - sp.exp(-1 / SINHWRHO)) ) PHICYL = xx[1] ZCYL = AMPLZ * ( const_dz *xx[2] + (sp.exp(xx[2] / SINHWZ ) - sp.exp(-xx[2] / SINHWZ )) / (sp.exp(1 / SINHWZ ) - sp.exp(-1 / SINHWZ )) ) # NO CLOSED-FORM EXPRESSION FOR RADIAL OR Z INVERSION. # Cart_to_xx[0] = "NewtonRaphson" # Cart_to_xx[1] = sp.atan2(Carty, Cartx) # Cart_to_xx[2] = "NewtonRaphson" xxCart[0] = RHOCYL*sp.cos(PHICYL) xxCart[1] = RHOCYL*sp.sin(PHICYL) xxCart[2] = ZCYL xxSph[0] = sp.sqrt(RHOCYL**2 + ZCYL**2) xxSph[1] = sp.acos(ZCYL / xxSph[0]) xxSph[2] = PHICYL scalefactor_orthog[0] = sp.diff(RHOCYL,xx[0]) scalefactor_orthog[1] = RHOCYL scalefactor_orthog[2] = sp.diff(ZCYL,xx[2]) # Set the unit vectors UnitVectors = [[ sp.cos(PHICYL), sp.sin(PHICYL), sp.sympify(0)], [-sp.sin(PHICYL), sp.cos(PHICYL), sp.sympify(0)], [ sp.sympify(0), sp.sympify(0), sp.sympify(1)]] ``` For example, let's set up **`SinhCylindricalv2`** coordinates and output the Christoffel symbol $\hat{\Gamma}^{xx_2}_{xx_2 xx_2}$, or more simply $\hat{\Gamma}^2_{22}$: ```python par.set_parval_from_str("reference_metric::CoordSystem","SinhCylindricalv2") rfm.reference_metric() sp.pretty_print(sp.simplify(rfm.GammahatUDD[2][2][2])) ``` ⎛ 2⋅xx₂ ⎞ 1 ⎜ ────── ⎟ ────── ⎜ SINHWZ ⎟ SINHWZ -⎝ℯ - 1⎠⋅ℯ ──────────────────────────────────────────────────────────────────────── ⎛ ⎛ 2 ⎞ xx₂ ⎛ 2⋅xx₂ ⎞ 1 ⎞ ⎜ ⎜ ────── ⎟ ────── ⎜ ────── ⎟ ──────⎟ ⎜ ⎜ SINHWZ ⎟ SINHWZ ⎜ SINHWZ ⎟ SINHWZ⎟ SINHWZ⋅⎝- SINHWZ⋅const_dz⋅⎝ℯ - 1⎠⋅ℯ - ⎝ℯ + 1⎠⋅ℯ ⎠ As we will soon see, defining these "hatted" quantities will be quite useful when expressing hyperbolic ([wave-equation](https://en.wikipedia.org/wiki/Wave_equation)-like) PDEs in non-Cartesian coordinate systems. <a id='cartesianlike'></a> ## Step 3.c: Cartesian-like coordinate systems \[Back to [top](#toc)\] $$\label{cartesianlike}$$ <a id='cartesian'></a> ### Step 3.c.i: **`reference_metric::CoordSystem = "Cartesian"`** \[Back to [top](#toc)\] $$\label{cartesian}$$ Standard Cartesian coordinates, with $(x,y,z)=$ `(xx0,xx1,xx2)` ```python if CoordSystem == "Cartesian": xmin, xmax, ymin, ymax, zmin, zmax = par.Cparameters("REAL",thismodule, ["xmin","xmax","ymin","ymax","zmin","zmax"], [ -10.0, 10.0, -10.0, 10.0, -10.0, 10.0]) xxmin = ["xmin", "ymin", "zmin"] xxmax = ["xmax", "ymax", "zmax"] xxCart[0] = xx[0] xxCart[1] = xx[1] xxCart[2] = xx[2] xxSph[0] = sp.sqrt(xx[0] ** 2 + xx[1] ** 2 + xx[2] ** 2) xxSph[1] = sp.acos(xx[2] / xxSph[0]) xxSph[2] = sp.atan2(xx[1], xx[0]) Cart_to_xx[0] = Cartx Cart_to_xx[1] = Carty Cart_to_xx[2] = Cartz scalefactor_orthog[0] = sp.sympify(1) scalefactor_orthog[1] = sp.sympify(1) scalefactor_orthog[2] = sp.sympify(1) # Set the transpose of the matrix of unit vectors UnitVectors = [[sp.sympify(1), sp.sympify(0), sp.sympify(0)], [sp.sympify(0), sp.sympify(1), sp.sympify(0)], [sp.sympify(0), sp.sympify(0), sp.sympify(1)]] ``` ```python %matplotlib inline import numpy as np # NumPy: A numerical methods module for Python import matplotlib.pyplot as plt # matplotlib: Python module specializing in plotting capabilities plt.clf() fig = plt.figure() ax = fig.gca() Nx = 16 ax.set_xticks(np.arange(0, 1., 1./Nx)) ax.set_yticks(np.arange(0, 1., 1./Nx)) for tick in ax.get_xticklabels(): tick.set_rotation(60) # plt.scatter(x, y) ax.set_aspect('equal') plt.grid() # plt.savefig("Cartgrid.png",dpi=300) plt.show() # plt.close(fig) ``` <a id='cartesian'></a> ### Step 3.c.ii: **`reference_metric::CoordSystem = "SinhCartesian"`** \[Back to [top](#toc)\] $$\label{cartesian}$$ In this coordinate system, all three coordinates behave like the $z$-coordinate in SinhCylindrical coordinates, i.e. $$ \begin{align} x(xx_0) &= \text{AMPLX} \left[\frac{\sinh\left(\frac{xx_0}{\text{SINHWZ}}\right)}{\sinh\left(\frac{1}{\text{SINHWX}}\right)}\right]\ ,\\ y(xx_1) &= \text{AMPLY} \left[\frac{\sinh\left(\frac{xx_1}{\text{SINHWZ}}\right)}{\sinh\left(\frac{1}{\text{SINHWY}}\right)}\right]\ ,\\ z(xx_2) &= \text{AMPLZ} \left[\frac{\sinh\left(\frac{xx_2}{\text{SINHWZ}}\right)}{\sinh\left(\frac{1}{\text{SINHWZ}}\right)}\right]\ . \end{align} $$ ```python if CoordSystem == "SinhCartesian": # SinhCartesian coordinates allows us to push the outer boundary of the # computational domain a lot further away, while keeping reasonably high # resolution towards the center of the computational grid. # Set default values for min and max (x,y,z) xxmin = [sp.sympify(-1), sp.sympify(-1), sp.sympify(-1)] xxmax = [sp.sympify(+1), sp.sympify(+1), sp.sympify(+1)] # Declare basic parameters of the coordinate system and their default values AMPLX,SINHWX,AMPLY,SINHWY,AMPLZ,SINHWZ = par.Cparameters("REAL",thismodule, ["AMPLX","SINHWX","AMPLY","SINHWY","AMPLZ","SINHWZ"], [ 10.0, 0.2, 10.0, 0.2, 10.0, 0.2]) # Compute (xxCart0,xxCart1,xxCart2) from (xx0,xx1,xx2) xxCart[0] = AMPLX*(sp.exp(xx[0]/SINHWX) - sp.exp(-xx[0]/SINHWX))/(sp.exp(1/SINHWX) - sp.exp(-1/SINHWX)) xxCart[1] = AMPLY*(sp.exp(xx[1]/SINHWY) - sp.exp(-xx[1]/SINHWY))/(sp.exp(1/SINHWY) - sp.exp(-1/SINHWY)) xxCart[2] = AMPLZ*(sp.exp(xx[2]/SINHWZ) - sp.exp(-xx[2]/SINHWZ))/(sp.exp(1/SINHWZ) - sp.exp(-1/SINHWZ)) # Compute (r,th,ph) from (xxCart2,xxCart1,xxCart2) xxSph[0] = sp.sqrt(xxCart[0] ** 2 + xxCart[1] ** 2 + xxCart[2] ** 2) xxSph[1] = sp.acos(xxCart[2] / xxSph[0]) xxSph[2] = sp.atan2(xxCart[1], xxCart[0]) # Compute (xx0,xx1,xx2) from (Cartx,Carty,Cartz) Cart_to_xx[0] = SINHWX*sp.asinh(AMPLX*Cartx*(sp.exp(1/SINHWX) - sp.exp(-1/SINHWX))/2) Cart_to_xx[1] = SINHWY*sp.asinh(AMPLY*Carty*(sp.exp(1/SINHWY) - sp.exp(-1/SINHWY))/2) Cart_to_xx[2] = SINHWZ*sp.asinh(AMPLZ*Cartz*(sp.exp(1/SINHWZ) - sp.exp(-1/SINHWZ))/2) # Compute scale factors scalefactor_orthog[0] = sp.diff(xxCart[0],xx[0]) scalefactor_orthog[1] = sp.diff(xxCart[1],xx[1]) scalefactor_orthog[2] = sp.diff(xxCart[2],xx[2]) # Set the transpose of the matrix of unit vectors UnitVectors = [[sp.sympify(1), sp.sympify(0), sp.sympify(0)], [sp.sympify(0), sp.sympify(1), sp.sympify(0)], [sp.sympify(0), sp.sympify(0), sp.sympify(1)]] ``` ```python %matplotlib inline import numpy as np # NumPy: A numerical methods module for Python import matplotlib.pyplot as plt # matplotlib: Python module specializing in plotting capabilities plt.clf() fig = plt.figure() ax = fig.gca() # Set plot title ax.set_title(r"$z=0$ slice of the 3D grid") # Set SINH parameters. Here we assume: # # AMPLX = AMPLY = SINHA # SINHWX = SINHWY = SINHW SINHA = 10.0 SINHW = 0.3 # Set number of points. We assume the same point # distribution along the (x,y)-directions Nxxs = 20 xxis = np.linspace(-1,1,Nxxs, endpoint=True) # Compute axis ticks by evaluating x and y using SinhCartesian coordinates axis_ticks = [] for i in range(Nxxs): axis_ticks.append(SINHA * (np.exp(xxis[i] / SINHW) - np.exp(-xxis[i] / SINHW)) / \ (np.exp(1.0 / SINHW) - np.exp(-1.0 / SINHW))) # Set the axis ticks ax.set_xticks(axis_ticks) ax.set_yticks(axis_ticks) # Set x and y labels. Initialize array with empty strings labelsx = ["" for i in range(Nxxs)] labelsy = ["" for i in range(Nxxs)] # Set x_min and x_max tick label labelsx[0] = r"-AMPLX" labelsx[-1] = r"AMPLX" # Set y_min and y_max tick label labelsy[0] = r"-AMPLY" labelsy[-1] = r"AMPLY" # Set tick labels ax.set_xticklabels(labelsx) ax.set_yticklabels(labelsy) # Rotate x labels by 60 degrees for tick in ax.get_xticklabels(): tick.set_rotation(60) # Draw the x=0 and y=0 ticklabel ax.text(0,-11,"0",ha="center",va="center") ax.text(-11,0,"0",ha="center",va="center") # plt.scatter(x, y) ax.set_aspect('equal') plt.grid() # plt.savefig("Cartgrid.png",dpi=300) plt.show() # plt.close(fig) ``` <a id='prolatespheroidal'></a> ## Step 3.d: [Prolate spheroidal](https://en.wikipedia.org/wiki/Prolate_spheroidal_coordinates)-like coordinate systems \[Back to [top](#toc)\] $$\label{prolatespheroidal}$$ <a id='symtp'></a> ### Step 3.d.i: **`reference_metric::CoordSystem = "SymTP"`** \[Back to [top](#toc)\] $$\label{symtp}$$ Symmetric TwoPuncture coordinates, with $(\rho,\phi,z)=(xx_0\sin(xx_1), xx_2, \sqrt{xx_0^2 + \text{bScale}^2}\cos(xx_1))$ ```python if CoordSystem == "SymTP": var1, var2= sp.symbols('var1 var2',real=True) bScale, AW, AMAX, RHOMAX, ZMIN, ZMAX = par.Cparameters("REAL",thismodule, ["bScale","AW","AMAX","RHOMAX","ZMIN","ZMAX"], [0.5, 0.2, 10.0, 10.0, -10.0, 10.0]) # Assuming xx0, xx1, and bScale # are positive makes nice simplifications of # unit vectors possible. xx[0],xx[1] = sp.symbols("xx0 xx1", real=True) xxmin = [sp.sympify(0), sp.sympify(0),-M_PI] xxmax = [ AMAX, M_PI, M_PI] AA = xx[0] if CoordSystem == "SinhSymTP": AA = (sp.exp(xx[0]/AW)-sp.exp(-xx[0]/AW))/2 var1 = sp.sqrt(AA**2 + (bScale * sp.sin(xx[1]))**2) var2 = sp.sqrt(AA**2 + bScale**2) RHOSYMTP = AA*sp.sin(xx[1]) PHSYMTP = xx[2] ZSYMTP = var2*sp.cos(xx[1]) xxCart[0] = AA *sp.sin(xx[1])*sp.cos(xx[2]) xxCart[1] = AA *sp.sin(xx[1])*sp.sin(xx[2]) xxCart[2] = ZSYMTP xxSph[0] = sp.sqrt(RHOSYMTP**2 + ZSYMTP**2) xxSph[1] = sp.acos(ZSYMTP / xxSph[0]) xxSph[2] = PHSYMTP rSph = sp.sqrt(Cartx ** 2 + Carty ** 2 + Cartz ** 2) thSph = sp.acos(Cartz / rSph) phSph = sp.atan2(Carty, Cartx) # Mathematica script to compute Cart_to_xx[] # AA = x1; # var2 = Sqrt[AA^2 + bScale^2]; # RHOSYMTP = AA*Sin[x2]; # ZSYMTP = var2*Cos[x2]; # Solve[{rSph == Sqrt[RHOSYMTP^2 + ZSYMTP^2], # thSph == ArcCos[ZSYMTP/Sqrt[RHOSYMTP^2 + ZSYMTP^2]], # phSph == x3}, # {x1, x2, x3}] Cart_to_xx[0] = sp.sqrt(-bScale**2 + rSph**2 + sp.sqrt(bScale**4 + 2*bScale**2*rSph**2 + rSph**4 - 4*bScale**2*rSph**2*sp.cos(thSph)**2))*M_SQRT1_2 # M_SQRT1_2 = 1/sqrt(2); define this way for UnitTesting # The sign() function in the following expression ensures the correct root is taken. Cart_to_xx[1] = sp.acos(sp.sign(Cartz)*( sp.sqrt(1 + rSph**2/bScale**2 - sp.sqrt(bScale**4 + 2*bScale**2*rSph**2 + rSph**4 - 4*bScale**2*rSph**2*sp.cos(thSph)**2)/bScale**2)*M_SQRT1_2)) # M_SQRT1_2 = 1/sqrt(2); define this way for UnitTesting Cart_to_xx[2] = phSph ``` <a id='sinhsymtp'></a> ### Step 3.d.ii: **`reference_metric::CoordSystem = "SinhSymTP"`** \[Back to [top](#toc)\] $$\label{sinhsymtp}$$ Symmetric TwoPuncture coordinates, but with $$xx_0 \to \sinh(xx_0/\text{AW})$$ ```python if CoordSystem == "SinhSymTP": var1, var2= sp.symbols('var1 var2',real=True) bScale, AW, AMAX, RHOMAX, ZMIN, ZMAX = par.Cparameters("REAL",thismodule, ["bScale","AW","AMAX","RHOMAX","ZMIN","ZMAX"], [0.5, 0.2, 10.0, 10.0, -10.0, 10.0]) # Assuming xx0, xx1, and bScale # are positive makes nice simplifications of # unit vectors possible. xx[0],xx[1] = sp.symbols("xx0 xx1", real=True) xxmin = [sp.sympify(0), sp.sympify(0),-M_PI] xxmax = [ AMAX, M_PI, M_PI] AA = xx[0] if CoordSystem == "SinhSymTP": # With xxmax[0] == AMAX, sinh(xx0/AMAX) will evaluate to a number between 0 and 1. # Similarly, sinh(xx0/(AMAX*SINHWAA)) / sinh(1/SINHWAA) will also evaluate to a number between 0 and 1. # Then AA = AMAX*sinh(xx0/(AMAX*SINHWAA)) / sinh(1/SINHWAA) will evaluate to a number between 0 and AMAX. AA = AMAX * (sp.exp(xx[0] / (AMAX*SINHWAA)) - sp.exp(-xx[0] / (AMAX*SINHWAA))) / (sp.exp(1 / SINHWAA) - sp.exp(-1 / AMAX)) var1 = sp.sqrt(AA**2 + (bScale * sp.sin(xx[1]))**2) var2 = sp.sqrt(AA**2 + bScale**2) RHOSYMTP = AA*sp.sin(xx[1]) PHSYMTP = xx[2] ZSYMTP = var2*sp.cos(xx[1]) xxCart[0] = AA *sp.sin(xx[1])*sp.cos(xx[2]) xxCart[1] = AA *sp.sin(xx[1])*sp.sin(xx[2]) xxCart[2] = ZSYMTP xxSph[0] = sp.sqrt(RHOSYMTP**2 + ZSYMTP**2) xxSph[1] = sp.acos(ZSYMTP / xxSph[0]) xxSph[2] = PHSYMTP scalefactor_orthog[0] = sp.diff(AA,xx[0]) * var1 / var2 scalefactor_orthog[1] = var1 scalefactor_orthog[2] = AA * sp.sin(xx[1]) # Set the transpose of the matrix of unit vectors UnitVectors = [[sp.sin(xx[1]) * sp.cos(xx[2]) * var2 / var1, sp.sin(xx[1]) * sp.sin(xx[2]) * var2 / var1, AA * sp.cos(xx[1]) / var1], [AA * sp.cos(xx[1]) * sp.cos(xx[2]) / var1, AA * sp.cos(xx[1]) * sp.sin(xx[2]) / var1, -sp.sin(xx[1]) * var2 / var1], [-sp.sin(xx[2]), sp.cos(xx[2]), sp.sympify(0)]] ``` <a id='latex_pdf_output'></a> # Step 4: Output this notebook to $\LaTeX$-formatted PDF file \[Back to [top](#toc)\] $$\label{latex_pdf_output}$$ The following code cell converts this Jupyter notebook into a proper, clickable $\LaTeX$-formatted PDF file. After the cell is successfully run, the generated PDF may be found in the root NRPy+ tutorial directory, with filename [Tutorial-Reference_Metric.pdf](Tutorial-Reference_Metric.pdf) (Note that clicking on this link may not work; you may need to open the PDF file through another means.) ```python import cmdline_helper as cmd # NRPy+: Multi-platform Python command-line interface cmd.output_Jupyter_notebook_to_LaTeXed_PDF("Tutorial-Reference_Metric") ``` Created Tutorial-Reference_Metric.tex, and compiled LaTeX file to PDF file Tutorial-Reference_Metric.pdf
/* * This file is part of the DUDS project. It is subject to the BSD-style * license terms in the LICENSE file found in the top-level directory of this * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE. * No part of DUDS, including this file, may be copied, modified, propagated, * or distributed except according to the terms contained in the LICENSE file. * * Copyright (C) 2017 Jeff Jackowski */ #include <boost/exception/errinfo_file_name.hpp> #include <sstream> #include <duds/hardware/interface/linux/SysFsPort.hpp> #include <duds/hardware/interface/PinConfiguration.hpp> namespace duds { namespace hardware { namespace interface { namespace linux { static const char *prefix = "/sys/class/gpio/gpio"; SysFsPort::SysFsPort(const std::vector<unsigned int> &ids, unsigned int firstid) : DigitalPortIndependentPins(ids.size(), firstid), fspins(ids.size()) { PinVector::iterator piter = pins.begin(); FsPinVector::iterator fiter = fspins.begin(); std::vector<unsigned int>::const_iterator iiter = ids.cbegin(); for (; piter != pins.end(); ++firstid, ++iiter, ++fiter, ++piter) { // check for an empty spot if (*iiter == -1) { piter->markNonexistent(); } else { // attempt to access the resources try { fiter->open(piter->conf, piter->cap, *iiter); } catch (PinError &pe) { pe << PinErrorId(firstid); throw; } } } } std::shared_ptr<SysFsPort> SysFsPort::makeConfiguredPort( PinConfiguration &pc, const std::string &name ) { // find the port's config object const PinConfiguration::Port &port = pc.port(name); // enumerate the pins std::vector<unsigned int> gpios; unsigned int next = port.idOffset; gpios.reserve(port.pins.size()); for (auto const &pin : port.gidIndex()) { // need empty spots? if (pin.gid > next) { // add unavailable pins gpios.insert(gpios.end(), pin.gid - next, -1); } // add available pin gpios.push_back(pin.pid); next = pin.gid + 1; } std::shared_ptr<SysFsPort> sp = std::make_shared<SysFsPort>( gpios, port.idOffset ); pc.attachPort(sp, name); return sp; } SysFsPort::~SysFsPort() { shutdown(); // more stuff here? } bool SysFsPort::simultaneousOperations() const { return false; } void SysFsPort::configurePort( unsigned int localPinId, const DigitalPinConfig &cfg, DigitalPinAccessBase::PortData * ) { // only configure existing pins /** @bug Is this the right place for such a check? Should it be done * by the caller? */ if (pins[localPinId]) { assert(cfg & (DigitalPinConfig::DirInput | DigitalPinConfig::DirOutput)); try { // change direction fspins[localPinId].setDirection(cfg & DigitalPinConfig::DirOutput); } catch (PinError &pe) { pe << PinErrorId(globalId(localPinId)); throw; } } } bool SysFsPort::inputImpl(unsigned int gid, DigitalPinAccessBase::PortData *) try { return fspins[localId(gid)].read(); } catch (PinError &pe) { pe << PinErrorId(gid); throw; } void SysFsPort::outputImpl( unsigned int lid, bool state, DigitalPinAccessBase::PortData * ) try { fspins[lid].write(state); } catch (PinError &pe) { pe << PinErrorId(globalId(lid)); throw; } void SysFsPort::FsPin::open( DigitalPinConfig &conf, // uninitialized DigitalPinCap &cap, // uninitialized unsigned int pin ) { fsid = pin; /** @todo Flag events and interrupts when support is added. */ // initialize the configuration and capability values to clear / nonexistent conf = DigitalPinConfig(DigitalPinConfig::ClearAll()); cap = NonexistentDigitalPin; std::ostringstream fname; fname << prefix << pin << "/value"; value.open(fname.str().c_str()); bool noOutput = false; if (!value.is_open()) { // allow for input only value.open(fname.str().c_str(), std::ios_base::in); if (!value.is_open()) { DUDS_THROW_EXCEPTION(PinIoError() << PinErrorPortId(pin) << boost::errinfo_file_name(fname.str()) ); } // cannot change the value; still good for input noOutput = true; } else { // obtain current pin value curoutval = reqoutval = read(); } // unwrite "value" fname.seekp(-5, std::ios_base::cur); fname << "direction"; std::string dir; direction.open(fname.str().c_str()); if (!direction.is_open()) { // allow for no direction writes direction.open(fname.str().c_str(), std::ios_base::in); if (!direction.is_open()) { value.close(); DUDS_THROW_EXCEPTION(PinIoError() << PinErrorPortId(pin) << boost::errinfo_file_name(fname.str()) ); } // read current direction direction >> dir; // no longer needed direction.close(); } else { // read current direction direction >> dir; } // parse direction for initial setting & caps if (dir == "in") { // currently input isoutput = false; // stuck on input? if (!direction.is_open()) { noOutput = true; } cap.capabilities |= DigitalPinCap::Input; conf.options |= DigitalPinConfig::DirInput; } else if (dir == "out") { // currently output isoutput = true; // stuck on output? if (!direction.is_open()) { // check for non-writable value file if (noOutput) { // useless pin; an output that cannot be changed value.close(); DUDS_THROW_EXCEPTION(PinUnsupportedOperation() << PinErrorPortId(pin) ); } } else { // can input cap.capabilities |= DigitalPinCap::Input; } conf.options |= DigitalPinConfig::DirOutput | DigitalPinConfig::OutputPushPull; } else { // unexpected value DUDS_THROW_EXCEPTION(PinIoError() << PinErrorPortId(pin)); } // I don't like double negatives, but I'm not changing the logic to fix it. if (!noOutput) { // add output flag cap.capabilities |= DigitalPinCap::OutputPushPull; } } void SysFsPort::FsPin::setDirection(bool output) { // only change direction; do not set direction to what it already is if (output != isoutput) { if (output) { direction << "out" << std::endl; } else { direction << "in" << std::endl; } if (direction.fail()) { DUDS_THROW_EXCEPTION(PinIoError() << PinErrorPortId(fsid) ); } else if (output) { // assure the logic to avoid unneeded changes will see the next // write as a change curoutval = !reqoutval; write(reqoutval); } isoutput = output; } } bool SysFsPort::FsPin::read() { value.seekg(0); char v; value >> v; if (value.fail()) { DUDS_THROW_EXCEPTION(PinIoError() << PinErrorPortId(fsid) ); } return v == '1'; } void SysFsPort::FsPin::write(bool w) { // record this as the requested output value; used when switching from // input to output reqoutval = w; // Changing the output results in an error if the pin is configured // as an input; the filesystem interface does not allow for specifying // a value to output ahead of switching to output. // Don't continue if the request is the same as the current output. if (isoutput && (w != curoutval)) { char v = '0'; if (w) { ++v; } value << v << std::endl; if (value.fail()) { DUDS_THROW_EXCEPTION(PinIoError() << PinErrorPortId(fsid) ); } // record this as the current output curoutval = w; } } } } } } // namespaces
From Test Require Import tactic. Section FOFProblem. Variable Universe : Set. Variable UniverseElement : Universe. Variable wd_ : Universe -> Universe -> Prop. Variable col_ : Universe -> Universe -> Universe -> Prop. Variable col_swap1_1 : (forall A B C : Universe, (col_ A B C -> col_ B A C)). Variable col_swap2_2 : (forall A B C : Universe, (col_ A B C -> col_ B C A)). Variable col_triv_3 : (forall A B : Universe, col_ A B B). Variable wd_swap_4 : (forall A B : Universe, (wd_ A B -> wd_ B A)). Variable col_trans_5 : (forall P Q A B C : Universe, ((wd_ P Q /\ (col_ P Q A /\ (col_ P Q B /\ col_ P Q C))) -> col_ A B C)). Theorem pipo_6 : (forall O E Eprime A B AB Bprime : Universe, ((wd_ A O /\ (wd_ E O /\ (wd_ B O /\ (wd_ E O /\ (wd_ O E /\ (wd_ O Eprime /\ (wd_ E Eprime /\ (wd_ Eprime A /\ (col_ O E A /\ (col_ O E B /\ (col_ O E AB /\ (col_ O Eprime Bprime /\ col_ O Eprime A)))))))))))) -> col_ O E Eprime)). Proof. time tac. Qed. End FOFProblem.
import numpy as np from glob import glob import pandas as pd from sklearn.model_selection import StratifiedKFold import os def get_options(): import argparse parser = argparse.ArgumentParser( description='Creating training on heatmaps') parser.add_argument('--table', metavar="str", type=str, help='input table') parser.add_argument('--output_name', metavar="str", type=str, help='output csv table name') parser.add_argument('--folds', metavar="int", type=int, help='number of folds') args = parser.parse_args() return args def createfolds(table, num, strat_var): skf = StratifiedKFold(n_splits=num, shuffle=True) obj = skf.split(table.index, table[strat_var]) i = 0 for _, test_index in obj: table.ix[test_index, "fold"] = i i += 1 return table def main(): options = get_options() table = pd.read_csv(options.table) table = createfolds(table, options.folds, 'RCB_class') table.to_csv(options.output_name, index=False) if __name__ == '__main__': main()
function [E, T_noise_squared, d] = error_foo(Theta, X, sigma, P_inlier, parameters) % [E T_noise_squared d] = error_foo(Theta, X, sigma, P_inlier, parameters) % % DESC: % Template to estimate the error due to the foo constraint. To % return only the error threshold the function call should be: % % [dummy T_noise d] = error_foo([], [], sigma, P_inlier, parameters); % % INPUT: % Theta = foo parameter vector % X = samples on the manifold % sigma = noise std % P_inlier = Chi squared probability threshold for inliers % If 0 then use directly sigma. % parameters = the parameters used by the functions % % OUTPUT: % E = squared error % T_noise_squared = squared noise threshold % d = degrees of freedom of the error distribution % compute the error obtained by the orthogonal projection of % the data points X onto the model manifold instantiated with the % parameters Theta E = []; if ~isempty(Theta) && ~isempty(X) % error computation end; % compute the error threshold if (nargout > 1) if (P_inlier == 0) % in this case the parameter sigma coincides with the noise % threshold T_noise_squared = sigma; else % otherwise we compute the error threshold given the standard % deviation of the noise assuming that the errors are normally % distributed. Hence the sum of their squares is Chi2 % distributed with d degrees of freedom d = ; % compute the inverse probability T_noise_squared = sigma^2 * chi2inv_LUT(P_inlier, d); end; end; return;
function PlotCSD(csd,varargin) %PlotCSD - Plot current source density. % % USAGE % % PlotCSD(csd,<options>) % % csd current source density (see <a href="matlab:help CSD">CSD</a>) % <options> optional list of property-value pairs (see table below) % % ========================================================================= % Properties Values % ------------------------------------------------------------------------- % 'lfp' local field potential % 'scale' scale (arbitrary units) for LFP traces (default = 1) % 'cutoffs' cutoff values (default = [-M M] where M is the maximum % amplitude of the CSD) % ========================================================================= % % SEE % % See <a href="matlab:help CSD">CSD</a>. % Copyright (C) 2008-2011 by Michaël Zugaro % % 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. % Default values lfp = []; scale = 1; cutoffs = []; % Check number of parameters if nargin < 1 | mod(length(varargin),2) ~= 0, error('Incorrect number of parameters (type ''help <a href="matlab:help PlotCSD">PlotCSD</a>'' for details).'); end % Parse parameter list for i = 1:2:length(varargin), if ~ischar(varargin{i}), error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help PlotCSD">PlotCSD</a>'' for details).']); end switch(lower(varargin{i})), case 'lfp', lfp = varargin{i+1}; if ~isdmatrix(lfp) | size(lfp,1) ~= size(csd,1) | size(lfp,2) ~= size(csd,2)+2, error('Incorrect size for parameter ''lfp'' (type ''help <a href="matlab:help PlotCSD">PlotCSD</a>'' for details).'); end case 'scale', scale = varargin{i+1}; if ~isdscalar(scale,'>0'), error('Incorrect value for property ''scale'' (type ''help <a href="matlab:help PlotCSD">PlotCSD</a>'' for details).'); end case 'cutoffs', cutoffs = varargin{i+1}; if ~isdvector(cutoffs,'#2','<'), error('Incorrect value for property ''cutoffs'' (type ''help <a href="matlab:help PlotCSD">PlotCSD</a>'' for details).'); end otherwise, error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help PlotCSD">PlotCSD</a>'' for details).']); end end d = csd(:,2:end); d = interp2(d); d = d(1:2:size(d,1),:); pcolor(csd(:,1),1:size(d,2),flipud(transpose(d))); shading interp; if ~isempty(cutoffs), set(gca,'clim',cutoffs); end if ~isempty(lfp), hold on; y = lfp(:,2:end); y = y - repmat(mean(y),size(y,1),1); y = y / max(max(abs(y)))*scale; n = size(y,2); for i = 1:n, plot(lfp(:,1),y(:,i)+(n-i)*2-1,'k'); end ylim([-2 (n-1)*2]); end
Interview broadcast on Lebanese TV January 20 , 2008
\section{Fields}
module Effect.File import Effects import Control.IOExcept data OpenFile : Mode -> Type where FH : File -> OpenFile m openOK : Mode -> Bool -> Type openOK m True = OpenFile m openOK m False = () data FileIO : Effect where Open : String -> (m : Mode) -> {() ==> if result then OpenFile m else ()} FileIO Bool Close : {OpenFile m ==> ()} FileIO () ReadLine : {OpenFile Read} FileIO String WriteLine : String -> {OpenFile Write} FileIO () EOF : {OpenFile Read} FileIO Bool instance Handler FileIO IO where handle () (Open fname m) k = do h <- openFile fname m valid <- validFile h if valid then k True (FH h) else k False () handle (FH h) Close k = do closeFile h k () () handle (FH h) ReadLine k = do str <- fread h k str (FH h) handle (FH h) (WriteLine str) k = do fwrite h str k () (FH h) handle (FH h) EOF k = do e <- feof h k e (FH h) FILE_IO : Type -> EFFECT FILE_IO t = MkEff t FileIO open : Handler FileIO e => String -> (m : Mode) -> { [FILE_IO ()] ==> [FILE_IO (if result then OpenFile m else ())] } Eff e Bool open f m = Open f m close : Handler FileIO e => { [FILE_IO (OpenFile m)] ==> [FILE_IO ()] } Eff e () close = Close readLine : Handler FileIO e => { [FILE_IO (OpenFile Read)] } Eff e String readLine = ReadLine writeLine : Handler FileIO e => String -> { [FILE_IO (OpenFile Write)] } Eff e () writeLine str = WriteLine str eof : Handler FileIO e => { [FILE_IO (OpenFile Read)] } Eff e Bool eof = EOF
Require Import Crypto.Specific.Framework.RawCurveParameters. Require Import Crypto.Util.LetIn. (*** Modulus : 2^416 - 2^208 - 1 Base: 23 + 1/9 ***) Definition curve : CurveParameters := {| sz := 18%nat; base := 23 + 1/9; bitwidth := 32; s := 2^416; c := [(1, 1); (2^208, 1)]; carry_chains := Some [[8; 17]; [9; 0; 10; 1; 11; 2; 12; 3; 13; 4; 14; 5; 15; 6; 16; 7; 17; 8]; [9; 0]]%nat; a24 := None; coef_div_modulus := Some 2%nat; goldilocks := Some true; karatsuba := None; montgomery := false; freeze := Some true; ladderstep := false; mul_code := None; square_code := None; upper_bound_of_exponent_loose := None; upper_bound_of_exponent_tight := None; allowable_bit_widths := None; freeze_extra_allowable_bit_widths := None; modinv_fuel := None |}. Ltac extra_prove_mul_eq _ := idtac. Ltac extra_prove_square_eq _ := idtac.
module OmegaRejectionSample import Base.Threads import ..OmegaCore using ..Util, ..Sample, ..Conditioning, ..TrackError, ..RNG const OC = OmegaCore # import ..OmegaCore: randsample export RejectionSample "Rejection Sampling Algorithm" struct RejectionSampleAlg end const RejectionSample = RejectionSampleAlg() OmegaCore.defrandalg(args...) = RejectionSample function omegarandsample1(rng, ΩT::Type{OT}, y, alg::RejectionSampleAlg) where OT @label restart ω = ΩT() ω_ = tagrng(ω, rng) !y(ω_) && @goto restart ω end "`n` samples from ω::ΩT such that `y(ω)` is true" function OC.omegarandsample(rng, ΩT::Type{OT}, y, n, alg::RejectionSampleAlg) where OT hack = OT() ωsamples = Vector{typeof(hack)}(undef, n) # Fixme accepted = 0 i = 1 # rngs = OC.duplicaterng(rng, Threads.nthreads()) # Threads.@threads for i = 1:n # rng = rngs[Threads.threadid()] # @inbounds ωsamples[i] = omegarandsample1(rng, ΩT, y, n, alg) # end for i = 1:n # rng = rngs[Threads.threadid()] @inbounds ωsamples[i] = omegarandsample1(rng, ΩT, y, alg) end ωsamples end function OC.randsample(rng, ΩT::Type{OT}, x, n, alg::RejectionSampleAlg) where {OT} # introduce conditions # y = OC.mem(OC.indomain(x)) y = condvar(x, Bool) ωsamples = OC.omegarandsample(rng, ΩT, y, n, alg) # map(OC.mem(x), ωsamples) map(x, ωsamples) end end
for (depfun, newfun) in Dict( :num_columns => :ncol, :num_rows => :nrow, :bind_value! => :bind!, :bind_variable! => :bind!, :execute! => :execute, :close! => :close, :commit! => :commit, :rollback! => :rollback, :fetch! => :fetch, :fetch_row! => :fetchrow, :fetch_rows! => :fetchrows ) @eval begin ($depfun)(args...) = error($depfun, " was renamed to ", $newfun, ". Check release notes at https://github.com/felipenoris/Oracle.jl/releases.") end end
[STATEMENT] lemma \<R>_bisim: "strong_low_bisim_mm (\<R> \<Gamma>')" [PROOF STATE] proof (prove) goal (1 subgoal): 1. strong_low_bisim_mm (\<R> \<Gamma>') [PROOF STEP] unfolding strong_low_bisim_mm_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. sym (\<R> \<Gamma>') \<and> closed_glob_consistent (\<R> \<Gamma>') \<and> (\<forall>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 \<and> (\<forall>c\<^sub>1' mds' mem\<^sub>1'. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<longrightarrow> (\<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle>))) [PROOF STEP] proof (auto) [PROOF STATE] proof (state) goal (4 subgoals): 1. sym (\<R> \<Gamma>') 2. closed_glob_consistent (\<R> \<Gamma>') 3. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 4. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] from \<R>_sym [PROOF STATE] proof (chain) picking this: sym (\<R> ?\<Gamma>) [PROOF STEP] show "sym (\<R> \<Gamma>')" [PROOF STATE] proof (prove) using this: sym (\<R> ?\<Gamma>) goal (1 subgoal): 1. sym (\<R> \<Gamma>') [PROOF STEP] . [PROOF STATE] proof (state) this: sym (\<R> \<Gamma>') goal (3 subgoals): 1. closed_glob_consistent (\<R> \<Gamma>') 2. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 3. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] next [PROOF STATE] proof (state) goal (3 subgoals): 1. closed_glob_consistent (\<R> \<Gamma>') 2. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 3. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] from \<R>_closed_glob_consistent [PROOF STATE] proof (chain) picking this: closed_glob_consistent (\<R> ?\<Gamma>') [PROOF STEP] show "closed_glob_consistent (\<R> \<Gamma>')" [PROOF STATE] proof (prove) using this: closed_glob_consistent (\<R> ?\<Gamma>') goal (1 subgoal): 1. closed_glob_consistent (\<R> \<Gamma>') [PROOF STEP] . [PROOF STATE] proof (state) this: closed_glob_consistent (\<R> \<Gamma>') goal (2 subgoals): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 2. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] next [PROOF STATE] proof (state) goal (2 subgoals): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 2. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] fix c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 [PROOF STATE] proof (state) goal (2 subgoals): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 2. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] assume "\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>" [PROOF STATE] proof (state) this: \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> goal (2 subgoals): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 2. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] thus "mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2" [PROOF STATE] proof (prove) using this: \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> goal (1 subgoal): 1. mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 [PROOF STEP] apply (rule \<R>_elim) [PROOF STATE] proof (prove) goal (3 subgoals): 1. (case \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> \<lambda>xb ((xc, xd), xe). \<langle>x, xa, xb\<rangle> \<R>\<^sup>1\<^bsub>\<Gamma>'\<^esub> \<langle>xc, xd, xe\<rangle>) xa) \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 2. (case \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> \<lambda>xb ((xc, xd), xe). \<langle>x, xa, xb\<rangle> \<R>\<^sup>2\<^bsub>\<Gamma>'\<^esub> \<langle>xc, xd, xe\<rangle>) xa) \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 3. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>3\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 [PROOF STEP] by (auto simp: \<R>\<^sub>1_mem_eq \<R>\<^sub>2_mem_eq \<R>\<^sub>3_mem_eq) [PROOF STATE] proof (state) this: mem\<^sub>1 =\<^bsub>mds\<^esub>\<^sup>l mem\<^sub>2 goal (1 subgoal): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] fix c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1' [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] assume eval: "\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>" [PROOF STATE] proof (state) this: \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> goal (1 subgoal): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] assume R: "\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>" [PROOF STATE] proof (state) this: \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> goal (1 subgoal): 1. \<And>c\<^sub>1 mds mem\<^sub>1 c\<^sub>2 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] from R [PROOF STATE] proof (chain) picking this: \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> [PROOF STEP] show "\<exists> c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle>" [PROOF STATE] proof (prove) using this: \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> goal (1 subgoal): 1. \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] apply (rule \<R>_elim) [PROOF STATE] proof (prove) goal (3 subgoals): 1. (case \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> \<lambda>xb ((xc, xd), xe). \<langle>x, xa, xb\<rangle> \<R>\<^sup>1\<^bsub>\<Gamma>'\<^esub> \<langle>xc, xd, xe\<rangle>) xa) \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> 2. (case \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> \<lambda>xb ((xc, xd), xe). \<langle>x, xa, xb\<rangle> \<R>\<^sup>2\<^bsub>\<Gamma>'\<^esub> \<langle>xc, xd, xe\<rangle>) xa) \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> 3. \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>3\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] apply (insert \<R>\<^sub>1_weak_bisim \<R>\<^sub>2_weak_bisim \<R>\<^sub>3_weak_bisim eval weak_bisim_def) [PROOF STATE] proof (prove) goal (3 subgoals): 1. \<lbrakk>(case \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> \<lambda>xb ((xc, xd), xe). \<langle>x, xa, xb\<rangle> \<R>\<^sup>1\<^bsub>\<Gamma>'\<^esub> \<langle>xc, xd, xe\<rangle>) xa) \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>1 \<Gamma>') (\<R> \<Gamma>'); \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>2 \<Gamma>') (\<R> \<Gamma>'); \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>3 \<Gamma>') (\<R> \<Gamma>'); \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>; \<And>\<T>\<^sub>1 \<T>. weak_bisim \<T>\<^sub>1 \<T> \<equiv> \<forall>c\<^sub>1 c\<^sub>2 mds mem\<^sub>1 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. (\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle>, \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>) \<in> \<T>\<^sub>1 \<and> \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<longrightarrow> (\<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> (\<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>, \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle>) \<in> \<T>)\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> 2. \<lbrakk>(case \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> \<lambda>xb ((xc, xd), xe). \<langle>x, xa, xb\<rangle> \<R>\<^sup>2\<^bsub>\<Gamma>'\<^esub> \<langle>xc, xd, xe\<rangle>) xa) \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>1 \<Gamma>') (\<R> \<Gamma>'); \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>2 \<Gamma>') (\<R> \<Gamma>'); \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>3 \<Gamma>') (\<R> \<Gamma>'); \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>; \<And>\<T>\<^sub>1 \<T>. weak_bisim \<T>\<^sub>1 \<T> \<equiv> \<forall>c\<^sub>1 c\<^sub>2 mds mem\<^sub>1 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. (\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle>, \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>) \<in> \<T>\<^sub>1 \<and> \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<longrightarrow> (\<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> (\<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>, \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle>) \<in> \<T>)\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> 3. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>3\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>1 \<Gamma>') (\<R> \<Gamma>'); \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>2 \<Gamma>') (\<R> \<Gamma>'); \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>3 \<Gamma>') (\<R> \<Gamma>'); \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>; \<And>\<T>\<^sub>1 \<T>. weak_bisim \<T>\<^sub>1 \<T> \<equiv> \<forall>c\<^sub>1 c\<^sub>2 mds mem\<^sub>1 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. (\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle>, \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>) \<in> \<T>\<^sub>1 \<and> \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<longrightarrow> (\<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> (\<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>, \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle>) \<in> \<T>)\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] apply (clarify, blast)+ [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<R>\<^sup>3\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>; \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>1 \<Gamma>') (\<R> \<Gamma>'); \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>2 \<Gamma>') (\<R> \<Gamma>'); \<And>\<Gamma>'. weak_bisim (\<R>\<^sub>3 \<Gamma>') (\<R> \<Gamma>'); \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>; \<And>\<T>\<^sub>1 \<T>. weak_bisim \<T>\<^sub>1 \<T> \<equiv> \<forall>c\<^sub>1 c\<^sub>2 mds mem\<^sub>1 mem\<^sub>2 c\<^sub>1' mds' mem\<^sub>1'. (\<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle>, \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle>) \<in> \<T>\<^sub>1 \<and> \<langle>c\<^sub>1, mds, mem\<^sub>1\<rangle> \<leadsto> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<longrightarrow> (\<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> (\<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle>, \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle>) \<in> \<T>)\<rbrakk> \<Longrightarrow> \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> [PROOF STEP] by (metis mem_Collect_eq case_prodI) [PROOF STATE] proof (state) this: \<exists>c\<^sub>2' mem\<^sub>2'. \<langle>c\<^sub>2, mds, mem\<^sub>2\<rangle> \<leadsto> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> \<and> \<langle>c\<^sub>1', mds', mem\<^sub>1'\<rangle> \<R>\<^sup>u\<^bsub>\<Gamma>'\<^esub> \<langle>c\<^sub>2', mds', mem\<^sub>2'\<rangle> goal: No subgoals! [PROOF STEP] qed
Formal statement is: lemma eventually_floor_less: fixes f :: "'a \<Rightarrow> 'b::{order_topology,floor_ceiling}" assumes f: "(f \<longlongrightarrow> l) F" and l: "l \<notin> \<int>" shows "\<forall>\<^sub>F x in F. of_int (floor l) < f x" Informal statement is: If $f$ is a function that converges to a real number $l$ that is not an integer, then eventually $f$ is greater than the floor of $l$.
Removable intermediate vinyl film with the advanced repositionable Comply™ adhesive for easier, bubble-free application. Available in an opaque white gloss, opaque white matte, or clear finish. Use this where a versatile film is needed for general signage, POP, walls, trucks, partial vehicle wraps, and indoor floor and carpet graphics.
using TimeZones: Transition using Dates: Hour, Second, UTM, @dateformat_str @testset "ZonedDateTime" begin utc = FixedTimeZone("UTC", 0, 0) warsaw = first(compile("Europe/Warsaw", tzdata["europe"])) @testset "dateformat parsing" begin @testset "successful parsing: $f" for f in (parse, tryparse) # Make sure all dateformat codes parse correctly # yYmuUdHMSseEzZ and yyyymmdd zdt = ZonedDateTime(1, 2, 3, 4, 5, 6, 7, utc) # Test y, u, d, H, M, S, s, Z p_zdt = f( ZonedDateTime, "Feb 3 1, 4:5:6.007 UTC", dateformat"u d y, H:M:S.s Z", ) @test zdt == p_zdt # Test m, e, Y, z p_zdt = f( ZonedDateTime, "2 mon 3 1, 4:5:6.007+00:00", dateformat"m e d Y, H:M:S.s+z", ) @test zdt == p_zdt # Test E, U p_zdt = f( ZonedDateTime, "February Monday 3 1 4:5:6.007 UTC", dateformat"U E d y H:M:S.s Z", ) @test zdt == p_zdt # Test yyyymmdd p_zdt = f( ZonedDateTime, "00010203 4:5:6.007 UTC", dateformat"yyyymmdd H:M:S.s Z", ) @test zdt == p_zdt end @testset "failed parsing: parse" begin @test_throws ArgumentError parse( ZonedDateTime, "2015-07-29 11:12:13.456 FakeTZ", dateformat"yyyy-mm-dd HH:MM:SS.sss Z", ) @test_throws ArgumentError parse( ZonedDateTime, "2015-07-29 11:12:13.456", dateformat"yyyy-mm-dd HH:MM:SS.sss Z", ) end @testset "failed parsing: tryparse" begin @test tryparse( ZonedDateTime, "2015-07-29 11:12:13.456 FakeTZ", dateformat"yyyy-mm-dd HH:MM:SS.sss Z", ) === nothing @test tryparse( ZonedDateTime, "2015-07-29 11:12:13.456", dateformat"yyyy-mm-dd HH:MM:SS.sss Z", ) === nothing end end @testset "standard time" begin local_dt = DateTime(1916, 2, 1, 0) utc_dt = DateTime(1916, 1, 31, 23) # Disambiguating parameters ignored when there is no ambiguity. @test ZonedDateTime(local_dt, warsaw).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw, 0).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw, 1).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw, 2).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw, true).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw, false).zone.name == "CET" @test ZonedDateTime(utc_dt, warsaw, from_utc=true).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, 0).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, 1).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, 2).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, true).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, false).utc_datetime == utc_dt @test ZonedDateTime(utc_dt, warsaw, from_utc=true).utc_datetime == utc_dt end @testset "daylight saving time" begin local_dt = DateTime(1916, 6, 1, 0) utc_dt = DateTime(1916, 5, 31, 22) # Disambiguating parameters ignored when there is no ambiguity. @test ZonedDateTime(local_dt, warsaw).zone.name == "CEST" @test ZonedDateTime(local_dt, warsaw, 0).zone.name == "CEST" @test ZonedDateTime(local_dt, warsaw, 1).zone.name == "CEST" @test ZonedDateTime(local_dt, warsaw, 2).zone.name == "CEST" @test ZonedDateTime(local_dt, warsaw, true).zone.name == "CEST" @test ZonedDateTime(local_dt, warsaw, false).zone.name == "CEST" @test ZonedDateTime(utc_dt, warsaw, from_utc=true).zone.name == "CEST" @test ZonedDateTime(local_dt, warsaw).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, 0).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, 1).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, 2).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, true).utc_datetime == utc_dt @test ZonedDateTime(local_dt, warsaw, false).utc_datetime == utc_dt @test ZonedDateTime(utc_dt, warsaw, from_utc=true).utc_datetime == utc_dt end @testset "spring-forward" begin local_dts = ( DateTime(1916,4,30,22), DateTime(1916,4,30,23), DateTime(1916,5,1,0), ) utc_dts = ( DateTime(1916,4,30,21), DateTime(1916,4,30,22), ) @test_throws NonExistentTimeError ZonedDateTime(local_dts[2], warsaw) @test_throws NonExistentTimeError ZonedDateTime(local_dts[2], warsaw, 0) @test_throws NonExistentTimeError ZonedDateTime(local_dts[2], warsaw, 1) @test_throws NonExistentTimeError ZonedDateTime(local_dts[2], warsaw, 2) @test_throws NonExistentTimeError ZonedDateTime(local_dts[2], warsaw, true) @test_throws NonExistentTimeError ZonedDateTime(local_dts[2], warsaw, false) @test ZonedDateTime(local_dts[1], warsaw).zone.name == "CET" @test ZonedDateTime(local_dts[3], warsaw).zone.name == "CEST" @test ZonedDateTime(utc_dts[1], warsaw, from_utc=true).zone.name == "CET" @test ZonedDateTime(utc_dts[2], warsaw, from_utc=true).zone.name == "CEST" @test ZonedDateTime(local_dts[1], warsaw).utc_datetime == utc_dts[1] @test ZonedDateTime(local_dts[3], warsaw).utc_datetime == utc_dts[2] @test ZonedDateTime(utc_dts[1], warsaw, from_utc=true).utc_datetime == utc_dts[1] @test ZonedDateTime(utc_dts[2], warsaw, from_utc=true).utc_datetime == utc_dts[2] end @testset "fall-back" begin local_dt = DateTime(1916, 10, 1, 0) utc_dts = (DateTime(1916, 9, 30, 22), DateTime(1916, 9, 30, 23)) @test_throws AmbiguousTimeError ZonedDateTime(local_dt, warsaw) @test_throws AmbiguousTimeError ZonedDateTime(local_dt, warsaw, 0) @test ZonedDateTime(local_dt, warsaw, 1).zone.name == "CEST" @test ZonedDateTime(local_dt, warsaw, 2).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw, true).zone.name == "CEST" @test ZonedDateTime(local_dt, warsaw, false).zone.name == "CET" @test ZonedDateTime(utc_dts[1], warsaw, from_utc=true).zone.name == "CEST" @test ZonedDateTime(utc_dts[2], warsaw, from_utc=true).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw, 1).utc_datetime == utc_dts[1] @test ZonedDateTime(local_dt, warsaw, 2).utc_datetime == utc_dts[2] @test ZonedDateTime(local_dt, warsaw, true).utc_datetime == utc_dts[1] @test ZonedDateTime(local_dt, warsaw, false).utc_datetime == utc_dts[2] @test ZonedDateTime(utc_dts[1], warsaw, from_utc=true).utc_datetime == utc_dts[1] @test ZonedDateTime(utc_dts[2], warsaw, from_utc=true).utc_datetime == utc_dts[2] end @testset "standard offset reduced" begin # The zone's standard offset was changed from +2 to +1 creating an ambiguous hour local_dt = DateTime(1922,5,31,23) utc_dts = (DateTime(1922, 5, 31, 21), DateTime(1922, 5, 31, 22)) @test_throws AmbiguousTimeError ZonedDateTime(local_dt, warsaw) @test ZonedDateTime(local_dt, warsaw, 1).zone.name == "EET" @test ZonedDateTime(local_dt, warsaw, 2).zone.name == "CET" @test_throws AmbiguousTimeError ZonedDateTime(local_dt, warsaw, true) @test_throws AmbiguousTimeError ZonedDateTime(local_dt, warsaw, false) @test ZonedDateTime(utc_dts[1], warsaw, from_utc=true).zone.name == "EET" @test ZonedDateTime(utc_dts[2], warsaw, from_utc=true).zone.name == "CET" @test ZonedDateTime(local_dt, warsaw, 1).utc_datetime == utc_dts[1] @test ZonedDateTime(local_dt, warsaw, 2).utc_datetime == utc_dts[2] @test ZonedDateTime(utc_dts[1], warsaw, from_utc=true).utc_datetime == utc_dts[1] @test ZonedDateTime(utc_dts[2], warsaw, from_utc=true).utc_datetime == utc_dts[2] end @testset "2-hour daylight saving time offset" begin # Check behaviour when the "save" offset is larger than an hour. paris = first(compile("Europe/Paris", tzdata["europe"])) @test ZonedDateTime(DateTime(1945,4,2,1), paris).zone == FixedTimeZone("WEST", 0, 3600) @test_throws NonExistentTimeError ZonedDateTime(DateTime(1945,4,2,2), paris) @test ZonedDateTime(DateTime(1945,4,2,3), paris).zone == FixedTimeZone("WEMT", 0, 7200) @test_throws AmbiguousTimeError ZonedDateTime(DateTime(1945,9,16,2), paris) @test ZonedDateTime(DateTime(1945,9,16,2), paris, 1).zone == FixedTimeZone("WEMT", 0, 7200) @test ZonedDateTime(DateTime(1945,9,16,2), paris, 2).zone == FixedTimeZone("CET", 3600, 0) # Ensure that dates are continuous when both a UTC offset and the DST offset change. @test ZonedDateTime(DateTime(1945,9,16,1), paris).utc_datetime == DateTime(1945,9,15,23) @test ZonedDateTime(DateTime(1945,9,16,2), paris, 1).utc_datetime == DateTime(1945,9,16,0) @test ZonedDateTime(DateTime(1945,9,16,2), paris, 2).utc_datetime == DateTime(1945,9,16,1) @test ZonedDateTime(DateTime(1945,9,16,3), paris).utc_datetime == DateTime(1945,9,16,2) end @testset "multiple hour transitions" begin # Transitions changes that exceed an hour. Results in having two sequential # non-existent hour and two sequential ambiguous hours. t = VariableTimeZone("Testing", [ Transition(DateTime(1800,1,1), FixedTimeZone("TST",0,0)), Transition(DateTime(1950,4,1), FixedTimeZone("TDT",0,7200)), Transition(DateTime(1950,9,1), FixedTimeZone("TST",0,0)), ]) # A "spring forward" where 2 hours are skipped. @test ZonedDateTime(DateTime(1950,3,31,23), t).zone == FixedTimeZone("TST",0,0) @test_throws NonExistentTimeError ZonedDateTime(DateTime(1950,4,1,0), t) @test_throws NonExistentTimeError ZonedDateTime(DateTime(1950,4,1,1), t) @test ZonedDateTime(DateTime(1950,4,1,2), t).zone == FixedTimeZone("TDT",0,7200) # A "fall back" where 2 hours are duplicated. Never appears to occur in reality. @test ZonedDateTime(DateTime(1950,8,31,23), t).utc_datetime == DateTime(1950,8,31,21) # TDT # First occurrences of duplicated hours. @test ZonedDateTime(DateTime(1950,9,1,0), t, 1).utc_datetime == DateTime(1950,8,31,22) # TST @test ZonedDateTime(DateTime(1950,9,1,1), t, 1).utc_datetime == DateTime(1950,8,31,23) # TST # Second occurrences of duplicated hours. @test ZonedDateTime(DateTime(1950,9,1,0), t, 2).utc_datetime == DateTime(1950,9,1,0) # TDT @test ZonedDateTime(DateTime(1950,9,1,1), t, 2).utc_datetime == DateTime(1950,9,1,1) # TDT @test ZonedDateTime(DateTime(1950,9,1,2), t).utc_datetime == DateTime(1950,9,1,2) # TDT end @testset "highly ambiguous hour" begin # Ambiguous local DateTime that has more than 2 solutions. Never occurs in reality. t = VariableTimeZone("Testing", [ Transition(DateTime(1800,1,1), FixedTimeZone("TST",0,0)), Transition(DateTime(1960,4,1), FixedTimeZone("TDT",0,7200)), Transition(DateTime(1960,8,31,23), FixedTimeZone("TXT",0,3600)), Transition(DateTime(1960,9,1), FixedTimeZone("TST",0,0)), ]) @test ZonedDateTime(DateTime(1960,8,31,23), t).utc_datetime == DateTime(1960,8,31,21) # TDT @test ZonedDateTime(DateTime(1960,9,1,0), t, 1).utc_datetime == DateTime(1960,8,31,22) # TDT @test ZonedDateTime(DateTime(1960,9,1,0), t, 2).utc_datetime == DateTime(1960,8,31,23) # TXT @test ZonedDateTime(DateTime(1960,9,1,0), t, 3).utc_datetime == DateTime(1960,9,1,0) # TST @test ZonedDateTime(DateTime(1960,9,1,1), t).utc_datetime == DateTime(1960,9,1,1) # TST @test_throws AmbiguousTimeError ZonedDateTime(DateTime(1960,9,1,0), t, true) @test_throws AmbiguousTimeError ZonedDateTime(DateTime(1960,9,1,0), t, false) end @testset "skip an entire day" begin # Significant offset change: -11:00 -> 13:00. apia = first(compile("Pacific/Apia", tzdata["australasia"])) # Skips an entire day. @test ZonedDateTime(DateTime(2011,12,29,23),apia).utc_datetime == DateTime(2011,12,30,9) @test_throws NonExistentTimeError ZonedDateTime(DateTime(2011,12,30,0),apia) @test_throws NonExistentTimeError ZonedDateTime(DateTime(2011,12,30,23),apia) @test ZonedDateTime(DateTime(2011,12,31,0),apia).utc_datetime == DateTime(2011,12,30,10) end @testset "redundant transitions" begin # Redundant transitions should be ignored. # Note: that this can occur in reality if the TZ database parse has a Zone that ends # at the same time a Rule starts. When this occurs the duplicates always in standard # time with the same abbreviation. zone = Dict{AbstractString,FixedTimeZone}() zone["DTST"] = FixedTimeZone("DTST", 0, 0) zone["DTDT-1"] = FixedTimeZone("DTDT-1", 0, 3600) zone["DTDT-2"] = FixedTimeZone("DTDT-2", 0, 3600) dup = VariableTimeZone("DuplicateTest", [ Transition(DateTime(1800,1,1), zone["DTST"]) Transition(DateTime(1935,4,1), zone["DTDT-1"]) # Ignored Transition(DateTime(1935,4,1), zone["DTDT-2"]) Transition(DateTime(1935,9,1), zone["DTST"]) ]) # Make sure that the duplicated hour only doesn't contain an additional entry. @test_throws AmbiguousTimeError ZonedDateTime(DateTime(1935,9,1), dup) @test ZonedDateTime(DateTime(1935,9,1), dup, 1).zone.name == "DTDT-2" @test ZonedDateTime(DateTime(1935,9,1), dup, 2).zone.name == "DTST" @test_throws BoundsError ZonedDateTime(DateTime(1935,9,1), dup, 3) # Ensure that DTDT-1 is completely ignored. @test_throws NonExistentTimeError ZonedDateTime(DateTime(1935,4,1), dup) @test ZonedDateTime(DateTime(1935,4,1,1), dup).zone.name == "DTDT-2" @test ZonedDateTime(DateTime(1935,8,31,23), dup).zone.name == "DTDT-2" end @testset "equality" begin # Check equality between ZonedDateTimes apia = first(compile("Pacific/Apia", tzdata["australasia"])) spring_utc = ZonedDateTime(DateTime(2010, 5, 1, 12), utc) spring_apia = ZonedDateTime(DateTime(2010, 5, 1, 1), apia) @test spring_utc.zone == FixedTimeZone("UTC", 0, 0) @test spring_apia.zone == FixedTimeZone("SST", -39600, 0) @test spring_utc == spring_apia @test spring_utc !== spring_apia @test isequal(spring_utc, spring_apia) @test hash(spring_utc) == hash(spring_apia) @test astimezone(spring_utc, apia) === spring_apia # Since ZonedDateTime is immutable @test astimezone(spring_apia, utc) === spring_utc @test isequal(astimezone(spring_utc, apia), spring_apia) @test hash(astimezone(spring_utc, apia)) == hash(spring_apia) fall_utc = ZonedDateTime(DateTime(2010, 10, 1, 12), utc) fall_apia = ZonedDateTime(DateTime(2010, 10, 1, 2), apia) @test fall_utc.zone == FixedTimeZone("UTC", 0, 0) @test fall_apia.zone == FixedTimeZone("SDT", -39600, 3600) @test fall_utc == fall_apia @test fall_utc !== fall_apia @test !(fall_utc < fall_apia) @test !(fall_utc > fall_apia) @test isequal(fall_utc, fall_apia) @test hash(fall_utc) == hash(fall_apia) @test astimezone(fall_utc, apia) === fall_apia # Since ZonedDateTime is immutable @test astimezone(fall_apia, utc) === fall_utc @test isequal(astimezone(fall_utc, apia), fall_apia) @test hash(astimezone(fall_utc, apia)) == hash(fall_apia) end @testset "broadcastable" begin # Validate that ZonedDateTime is treated as a scalar during broadcasting zdt = ZonedDateTime(2000, 1, 2, 3, utc) @test size(zdt .== zdt) == () end @testset "deepcopy hash" begin # Issue #78 x = ZonedDateTime(2017, 7, 6, 15, 44, 55, 28, warsaw) y = deepcopy(x) @test x == y @test x !== y @test !(x < y) @test !(x > y) @test isequal(x, y) @test hash(x) == hash(y) # Check that the ZonedDateTime and plain DateTimes don't hash to the same value. @test hash(x) != hash(y.utc_datetime) end @testset "multiple time zones" begin # ZonedDateTime constructor that takes any number of Period or TimeZone types @test_throws ArgumentError ZonedDateTime(FixedTimeZone("UTC", 0, 0), FixedTimeZone("TMW", 86400, 0)) end @testset "cutoff" begin # The absolutely min DateTime you can create. Even smaller than `typemin(DateTime)` early_utc = ZonedDateTime(DateTime(UTM(typemin(Int64))), utc) # A FixedTimeZone is effective for all of time where as a VariableTimeZone has as # start. @test DateTime(early_utc, UTC) < warsaw.transitions[1].utc_datetime @test_throws NonExistentTimeError astimezone(early_utc, warsaw) end @testset "UnhandledTimeError" begin # VariableTimeZone with a cutoff set cutoff_tz = VariableTimeZone( "cutoff", [Transition(DateTime(1970, 1, 1), utc)], DateTime(1988, 5, 6), ) ZonedDateTime(DateTime(1970, 1, 1), cutoff_tz) # pre cutoff @test_throws UnhandledTimeError ZonedDateTime(DateTime(1988, 5, 6), cutoff_tz) # on cutoff @test_throws UnhandledTimeError ZonedDateTime(DateTime(1989, 5, 7), cutoff_tz) @test_throws UnhandledTimeError ZonedDateTime(DateTime(1988, 5, 5), cutoff_tz) + Hour(24) zdt = ZonedDateTime(DateTime(2038, 3, 28), warsaw, from_utc=true) @test_throws UnhandledTimeError zdt + Hour(1) end @testset "no cutoff" begin # TimeZones that no longer have any transitions after the max_year shouldn't have a cutoff # eg. Asia/Hong_Kong, Pacific/Honolulu, Australia/Perth perth = first(compile("Australia/Perth", tzdata["australasia"])) zdt = ZonedDateTime(DateTime(2200, 1, 1), perth, from_utc=true) end @testset "convenience constructors" begin # Convenience constructors for making a DateTime on-the-fly digits = [2010, 1, 2, 3, 4, 5, 6] for i in eachindex(digits) @test ZonedDateTime(digits[1:i]..., warsaw) == ZonedDateTime(DateTime(digits[1:i]...), warsaw) @test ZonedDateTime(digits[1:i]..., utc) == ZonedDateTime(DateTime(digits[1:i]...), utc) end # Convenience constructor dealing with ambiguous time digits = [1916, 10, 1, 0, 2, 3, 4] # Fall DST transition in Europe/Warsaw for i in eachindex(digits) expected = [ ZonedDateTime(DateTime(digits[1:i]...), warsaw, 1) ZonedDateTime(DateTime(digits[1:i]...), warsaw, 2) ] if i > 1 @test_throws AmbiguousTimeError ZonedDateTime(digits[1:i]..., warsaw) end @test ZonedDateTime(digits[1:i]..., warsaw, 1) == expected[1] @test ZonedDateTime(digits[1:i]..., warsaw, 2) == expected[2] @test ZonedDateTime(digits[1:i]..., warsaw, true) == expected[1] @test ZonedDateTime(digits[1:i]..., warsaw, false) == expected[2] end end @testset "promotion" begin @test_throws ErrorException promote_type(ZonedDateTime, Date) @test_throws ErrorException promote_type(ZonedDateTime, DateTime) @test_throws ErrorException promote_type(Date, ZonedDateTime) @test_throws ErrorException promote_type(DateTime, ZonedDateTime) @test promote_type(ZonedDateTime, ZonedDateTime) == ZonedDateTime # Issue #52 dt = now() @test_throws ErrorException ZonedDateTime(dt, warsaw) > dt end @testset "extrema" begin @test typemin(ZonedDateTime) <= ZonedDateTime(typemin(DateTime), utc) @test typemax(ZonedDateTime) >= ZonedDateTime(typemax(DateTime), utc) end end
#! /usr/bin/julia # Rosetta Code, Hickerson series of almost integers function makehickerson{T<:Real}(x::T) n = 0 h = one(T)/2x function hickerson() n += 1 h *= n/x end end function reporthickerson{T<:Real,U<:Integer}(a::T, nmax::U) h = makehickerson(a) hgm = makehickerson(prevfloat(a)) hgp = makehickerson(nextfloat(a)) println() print("Performing calculations using ", typeof(a)) println(", which has ", precision(a), "-bit precision.") for i in 1:nmax x = h() xm = hgm() xp = hgp() y = ifloor(10x) ym = ifloor(10xm) yp = ifloor(10xp) println() println("Hickerson series result for n = ", i) println(@sprintf(" -> %25.4f ", xm)) println(@sprintf(" 0> %25.4f ", x)) println(@sprintf(" +> %25.4f ", xp)) isprecok = isint = if ym == y == yp print("The precision is adequate, ") if digits(y)[1] in [0, 9] println("and the result is an almost integer.") else println("but the result is not an almost integer.") end else println("The precision is inadequate for a definite result.") end end end a = log(big(2.0)) reporthickerson(a, 17) a = log(2.0) reporthickerson(a, 17)
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import category_theory.limits.has_limits import category_theory.thin /-! # Wide pullbacks We define the category `wide_pullback_shape`, (resp. `wide_pushout_shape`) which is the category obtained from a discrete category of type `J` by adjoining a terminal (resp. initial) element. Limits of this shape are wide pullbacks (pushouts). The convenience method `wide_cospan` (`wide_span`) constructs a functor from this category, hitting the given morphisms. We use `wide_pullback_shape` to define ordinary pullbacks (pushouts) by using `J := walking_pair`, which allows easy proofs of some related lemmas. Furthermore, wide pullbacks are used to show the existence of limits in the slice category. Namely, if `C` has wide pullbacks then `C/B` has limits for any object `B` in `C`. Typeclasses `has_wide_pullbacks` and `has_finite_wide_pullbacks` assert the existence of wide pullbacks and finite wide pullbacks. -/ universes v u open category_theory category_theory.limits opposite namespace category_theory.limits variable (J : Type v) /-- A wide pullback shape for any type `J` can be written simply as `option J`. -/ @[derive inhabited] def wide_pullback_shape := option J /-- A wide pushout shape for any type `J` can be written simply as `option J`. -/ @[derive inhabited] def wide_pushout_shape := option J namespace wide_pullback_shape variable {J} /-- The type of arrows for the shape indexing a wide pullback. -/ @[derive decidable_eq] inductive hom : wide_pullback_shape J → wide_pullback_shape J → Type v | id : Π X, hom X X | term : Π (j : J), hom (some j) none attribute [nolint unused_arguments] hom.decidable_eq instance struct : category_struct (wide_pullback_shape J) := { hom := hom, id := λ j, hom.id j, comp := λ j₁ j₂ j₃ f g, begin cases f, exact g, cases g, apply hom.term _ end } instance hom.inhabited : inhabited (hom none none) := ⟨hom.id (none : wide_pullback_shape J)⟩ local attribute [tidy] tactic.case_bash instance subsingleton_hom (j j' : wide_pullback_shape J) : subsingleton (j ⟶ j') := ⟨by tidy⟩ instance category : small_category (wide_pullback_shape J) := thin_category @[simp] lemma hom_id (X : wide_pullback_shape J) : hom.id X = 𝟙 X := rfl variables {C : Type u} [category.{v} C] /-- Construct a functor out of the wide pullback shape given a J-indexed collection of arrows to a fixed object. -/ @[simps] def wide_cospan (B : C) (objs : J → C) (arrows : Π (j : J), objs j ⟶ B) : wide_pullback_shape J ⥤ C := { obj := λ j, option.cases_on j B objs, map := λ X Y f, begin cases f with _ j, { apply (𝟙 _) }, { exact arrows j } end, map_comp' := λ _ _ _ f g, begin cases f, { simpa }, cases g, simp end } /-- Every diagram is naturally isomorphic (actually, equal) to a `wide_cospan` -/ def diagram_iso_wide_cospan (F : wide_pullback_shape J ⥤ C) : F ≅ wide_cospan (F.obj none) (λ j, F.obj (some j)) (λ j, F.map (hom.term j)) := nat_iso.of_components (λ j, eq_to_iso $ by tidy) $ by tidy /-- Construct a cone over a wide cospan. -/ @[simps] def mk_cone {F : wide_pullback_shape J ⥤ C} {X : C} (f : X ⟶ F.obj none) (π : Π j, X ⟶ F.obj (some j)) (w : ∀ j, π j ≫ F.map (hom.term j) = f) : cone F := { X := X, π := { app := λ j, match j with | none := f | (some j) := π j end, naturality' := λ j j' f, by { cases j; cases j'; cases f; unfold_aux; dsimp; simp [w], }, } } end wide_pullback_shape namespace wide_pushout_shape variable {J} /-- The type of arrows for the shape indexing a wide psuhout. -/ @[derive decidable_eq] inductive hom : wide_pushout_shape J → wide_pushout_shape J → Type v | id : Π X, hom X X | init : Π (j : J), hom none (some j) attribute [nolint unused_arguments] hom.decidable_eq instance struct : category_struct (wide_pushout_shape J) := { hom := hom, id := λ j, hom.id j, comp := λ j₁ j₂ j₃ f g, begin cases f, exact g, cases g, apply hom.init _ end } instance hom.inhabited : inhabited (hom none none) := ⟨hom.id (none : wide_pushout_shape J)⟩ local attribute [tidy] tactic.case_bash instance subsingleton_hom (j j' : wide_pushout_shape J) : subsingleton (j ⟶ j') := ⟨by tidy⟩ instance category : small_category (wide_pushout_shape J) := thin_category @[simp] lemma hom_id (X : wide_pushout_shape J) : hom.id X = 𝟙 X := rfl variables {C : Type u} [category.{v} C] /-- Construct a functor out of the wide pushout shape given a J-indexed collection of arrows from a fixed object. -/ @[simps] def wide_span (B : C) (objs : J → C) (arrows : Π (j : J), B ⟶ objs j) : wide_pushout_shape J ⥤ C := { obj := λ j, option.cases_on j B objs, map := λ X Y f, begin cases f with _ j, { apply (𝟙 _) }, { exact arrows j } end, map_comp' := by { rintros (_|_) (_|_) (_|_) (_|_) (_|_); simpa <|> simp } } /-- Every diagram is naturally isomorphic (actually, equal) to a `wide_span` -/ def diagram_iso_wide_span (F : wide_pushout_shape J ⥤ C) : F ≅ wide_span (F.obj none) (λ j, F.obj (some j)) (λ j, F.map (hom.init j)) := nat_iso.of_components (λ j, eq_to_iso $ by tidy) $ by tidy /-- Construct a cocone over a wide span. -/ @[simps] def mk_cocone {F : wide_pushout_shape J ⥤ C} {X : C} (f : F.obj none ⟶ X) (ι : Π j, F.obj (some j) ⟶ X) (w : ∀ j, F.map (hom.init j) ≫ ι j = f) : cocone F := { X := X, ι := { app := λ j, match j with | none := f | (some j) := ι j end, naturality' := λ j j' f, by { cases j; cases j'; cases f; unfold_aux; dsimp; simp [w], }, } } end wide_pushout_shape variables (C : Type u) [category.{v} C] /-- `has_wide_pullbacks` represents a choice of wide pullback for every collection of morphisms -/ abbreviation has_wide_pullbacks : Prop := Π (J : Type v), has_limits_of_shape (wide_pullback_shape J) C /-- `has_wide_pushouts` represents a choice of wide pushout for every collection of morphisms -/ abbreviation has_wide_pushouts : Prop := Π (J : Type v), has_colimits_of_shape (wide_pushout_shape J) C variables {C J} /-- `has_wide_pullback B objs arrows` means that `wide_cospan B objs arrows` has a limit. -/ abbreviation has_wide_pullback (B : C) (objs : J → C) (arrows : Π (j : J), objs j ⟶ B) : Prop := has_limit (wide_pullback_shape.wide_cospan B objs arrows) /-- `has_wide_pushout B objs arrows` means that `wide_span B objs arrows` has a colimit. -/ abbreviation has_wide_pushout (B : C) (objs : J → C) (arrows : Π (j : J), B ⟶ objs j) : Prop := has_colimit (wide_pushout_shape.wide_span B objs arrows) /-- A choice of wide pullback. -/ noncomputable abbreviation wide_pullback (B : C) (objs : J → C) (arrows : Π (j : J), objs j ⟶ B) [has_wide_pullback B objs arrows] : C := limit (wide_pullback_shape.wide_cospan B objs arrows) /-- A choice of wide pushout. -/ noncomputable abbreviation wide_pushout (B : C) (objs : J → C) (arrows : Π (j : J), B ⟶ objs j) [has_wide_pushout B objs arrows] : C := colimit (wide_pushout_shape.wide_span B objs arrows) variable (C) namespace wide_pullback variables {C} {B : C} {objs : J → C} (arrows : Π (j : J), objs j ⟶ B) variables [has_wide_pullback B objs arrows] /-- The `j`-th projection from the pullback. -/ noncomputable abbreviation π (j : J) : wide_pullback _ _ arrows ⟶ objs j := limit.π (wide_pullback_shape.wide_cospan _ _ _) (option.some j) /-- The unique map to the base from the pullback. -/ noncomputable abbreviation base : wide_pullback _ _ arrows ⟶ B := limit.π (wide_pullback_shape.wide_cospan _ _ _) option.none @[simp, reassoc] variables {arrows} /-- Lift a collection of morphisms to a morphism to the pullback. -/ noncomputable abbreviation lift {X : C} (f : X ⟶ B) (fs : Π (j : J), X ⟶ objs j) (w : ∀ j, fs j ≫ arrows j = f) : X ⟶ wide_pullback _ _ arrows := limit.lift (wide_pullback_shape.wide_cospan _ _ _) (wide_pullback_shape.mk_cone f fs $ by exact w) variables (arrows) variables {X : C} (f : X ⟶ B) (fs : Π (j : J), X ⟶ objs j) (w : ∀ j, fs j ≫ arrows j = f) @[simp, reassoc] lemma lift_π (j : J) : lift f fs w ≫ π arrows j = fs _ := by { simp, refl } @[simp, reassoc] lemma lift_base : lift f fs w ≫ base arrows = f := by { simp, refl } lemma eq_lift_of_comp_eq (g : X ⟶ wide_pullback _ _ arrows) : (∀ j : J, g ≫ π arrows j = fs j) → g ≫ base arrows = f → g = lift f fs w := begin intros h1 h2, apply (limit.is_limit (wide_pullback_shape.wide_cospan B objs arrows)).uniq (wide_pullback_shape.mk_cone f fs $ by exact w), rintro (_|_), { apply h2 }, { apply h1 } end lemma hom_eq_lift (g : X ⟶ wide_pullback _ _ arrows) : g = lift (g ≫ base arrows) (λ j, g ≫ π arrows j) (by tidy) := begin apply eq_lift_of_comp_eq, tidy, end @[ext] lemma hom_ext (g1 g2 : X ⟶ wide_pullback _ _ arrows) : (∀ j : J, g1 ≫ π arrows j = g2 ≫ π arrows j) → g1 ≫ base arrows = g2 ≫ base arrows → g1 = g2 := begin intros h1 h2, apply limit.hom_ext, rintros (_|_), { apply h2 }, { apply h1 }, end end wide_pullback namespace wide_pushout variables {C} {B : C} {objs : J → C} (arrows : Π (j : J), B ⟶ objs j) variables [has_wide_pushout B objs arrows] /-- The `j`-th inclusion to the pushout. -/ noncomputable abbreviation ι (j : J) : objs j ⟶ wide_pushout _ _ arrows := colimit.ι (wide_pushout_shape.wide_span _ _ _) (option.some j) /-- The unique map from the head to the pushout. -/ noncomputable abbreviation head : B ⟶ wide_pushout B objs arrows := colimit.ι (wide_pushout_shape.wide_span _ _ _) option.none @[simp, reassoc] lemma arrow_ι (j : J) : arrows j ≫ ι arrows j = head arrows := by apply colimit.w (wide_pushout_shape.wide_span _ _ _) (wide_pushout_shape.hom.init j) variables {arrows} /-- Descend a collection of morphisms to a morphism from the pushout. -/ noncomputable abbreviation desc {X : C} (f : B ⟶ X) (fs : Π (j : J), objs j ⟶ X) (w : ∀ j, arrows j ≫ fs j = f) : wide_pushout _ _ arrows ⟶ X := colimit.desc (wide_pushout_shape.wide_span B objs arrows) (wide_pushout_shape.mk_cocone f fs $ by exact w) variables (arrows) variables {X : C} (f : B ⟶ X) (fs : Π (j : J), objs j ⟶ X) (w : ∀ j, arrows j ≫ fs j = f) @[simp, reassoc] lemma ι_desc (j : J) : ι arrows j ≫ desc f fs w = fs _ := by { simp, refl } @[simp, reassoc] lemma head_desc : head arrows ≫ desc f fs w = f := by { simp, refl } lemma eq_desc_of_comp_eq (g : wide_pushout _ _ arrows ⟶ X) : (∀ j : J, ι arrows j ≫ g = fs j) → head arrows ≫ g = f → g = desc f fs w := begin intros h1 h2, apply (colimit.is_colimit (wide_pushout_shape.wide_span B objs arrows)).uniq (wide_pushout_shape.mk_cocone f fs $ by exact w), rintro (_|_), { apply h2 }, { apply h1 } end lemma hom_eq_desc (g : wide_pushout _ _ arrows ⟶ X) : g = desc (head arrows ≫ g) (λ j, ι arrows j ≫ g) (λ j, by { rw ← category.assoc, simp }) := begin apply eq_desc_of_comp_eq, tidy, end @[ext] lemma hom_ext (g1 g2 : wide_pushout _ _ arrows ⟶ X) : (∀ j : J, ι arrows j ≫ g1 = ι arrows j ≫ g2) → head arrows ≫ g1 = head arrows ≫ g2 → g1 = g2 := begin intros h1 h2, apply colimit.hom_ext, rintros (_|_), { apply h2 }, { apply h1 }, end end wide_pushout variable (J) /-- The action on morphisms of the obvious functor `wide_pullback_shape_op : wide_pullback_shape J ⥤ (wide_pushout_shape J)ᵒᵖ`-/ def wide_pullback_shape_op_map : Π (X Y : wide_pullback_shape J), (X ⟶ Y) → ((op X : (wide_pushout_shape J)ᵒᵖ) ⟶ (op Y : (wide_pushout_shape J)ᵒᵖ)) | _ _ (wide_pullback_shape.hom.id X) := quiver.hom.op (wide_pushout_shape.hom.id _) | _ _ (wide_pullback_shape.hom.term j) := quiver.hom.op (wide_pushout_shape.hom.init _) /-- The obvious functor `wide_pullback_shape J ⥤ (wide_pushout_shape J)ᵒᵖ` -/ @[simps] def wide_pullback_shape_op : wide_pullback_shape J ⥤ (wide_pushout_shape J)ᵒᵖ := { obj := λ X, op X, map := wide_pullback_shape_op_map J, } /-- The action on morphisms of the obvious functor `wide_pushout_shape_op : `wide_pushout_shape J ⥤ (wide_pullback_shape J)ᵒᵖ` -/ def wide_pushout_shape_op_map : Π (X Y : wide_pushout_shape J), (X ⟶ Y) → ((op X : (wide_pullback_shape J)ᵒᵖ) ⟶ (op Y : (wide_pullback_shape J)ᵒᵖ)) | _ _ (wide_pushout_shape.hom.id X) := quiver.hom.op (wide_pullback_shape.hom.id _) | _ _ (wide_pushout_shape.hom.init j) := quiver.hom.op (wide_pullback_shape.hom.term _) /-- The obvious functor `wide_pushout_shape J ⥤ (wide_pullback_shape J)ᵒᵖ` -/ @[simps] def wide_pushout_shape_op : wide_pushout_shape J ⥤ (wide_pullback_shape J)ᵒᵖ := { obj := λ X, op X, map := wide_pushout_shape_op_map J, } /-- The obvious functor `(wide_pullback_shape J)ᵒᵖ ⥤ wide_pushout_shape J`-/ @[simps] def wide_pullback_shape_unop : (wide_pullback_shape J)ᵒᵖ ⥤ wide_pushout_shape J := (wide_pullback_shape_op J).left_op /-- The obvious functor `(wide_pushout_shape J)ᵒᵖ ⥤ wide_pullback_shape J` -/ @[simps] def wide_pushout_shape_unop : (wide_pushout_shape J)ᵒᵖ ⥤ wide_pullback_shape J := (wide_pushout_shape_op J).left_op /-- The inverse of the unit isomorphism of the equivalence `wide_pushout_shape_op_equiv : (wide_pushout_shape J)ᵒᵖ ≌ wide_pullback_shape J` -/ def wide_pushout_shape_op_unop : wide_pushout_shape_unop J ⋙ wide_pullback_shape_op J ≅ 𝟭 _ := nat_iso.of_components (λ X, iso.refl _) (λ X Y f, dec_trivial) /-- The counit isomorphism of the equivalence `wide_pullback_shape_op_equiv : (wide_pullback_shape J)ᵒᵖ ≌ wide_pushout_shape J` -/ def wide_pushout_shape_unop_op : wide_pushout_shape_op J ⋙ wide_pullback_shape_unop J ≅ 𝟭 _ := nat_iso.of_components (λ X, iso.refl _) (λ X Y f, dec_trivial) /-- The inverse of the unit isomorphism of the equivalence `wide_pullback_shape_op_equiv : (wide_pullback_shape J)ᵒᵖ ≌ wide_pushout_shape J` -/ def wide_pullback_shape_op_unop : wide_pullback_shape_unop J ⋙ wide_pushout_shape_op J ≅ 𝟭 _ := nat_iso.of_components (λ X, iso.refl _) (λ X Y f, dec_trivial) /-- The counit isomorphism of the equivalence `wide_pushout_shape_op_equiv : (wide_pushout_shape J)ᵒᵖ ≌ wide_pullback_shape J` -/ def wide_pullback_shape_unop_op : wide_pullback_shape_op J ⋙ wide_pushout_shape_unop J ≅ 𝟭 _ := nat_iso.of_components (λ X, iso.refl _) (λ X Y f, dec_trivial) /-- The duality equivalence `(wide_pushout_shape J)ᵒᵖ ≌ wide_pullback_shape J` -/ @[simps] def wide_pushout_shape_op_equiv : (wide_pushout_shape J)ᵒᵖ ≌ wide_pullback_shape J := { functor := wide_pushout_shape_unop J, inverse := wide_pullback_shape_op J, unit_iso := (wide_pushout_shape_op_unop J).symm, counit_iso := wide_pullback_shape_unop_op J, } /-- The duality equivalence `(wide_pullback_shape J)ᵒᵖ ≌ wide_pushout_shape J` -/ @[simps] def wide_pullback_shape_op_equiv : (wide_pullback_shape J)ᵒᵖ ≌ wide_pushout_shape J := { functor := wide_pullback_shape_unop J, inverse := wide_pushout_shape_op J, unit_iso := (wide_pullback_shape_op_unop J).symm, counit_iso := wide_pushout_shape_unop_op J, } end category_theory.limits
//================================================================================================== /*! @file @copyright 2015 NumScale SAS @copyright 2015 J.T. Lapreste Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ //================================================================================================== #ifndef BOOST_SIMD_ARCH_COMMON_GENERIC_FUNCTION_MINUSONE_HPP_INCLUDED #define BOOST_SIMD_ARCH_COMMON_GENERIC_FUNCTION_MINUSONE_HPP_INCLUDED #include <boost/simd/constant/one.hpp> #include <boost/simd/constant/valmin.hpp> #include <boost/simd/function/is_not_equal.hpp> #include <boost/simd/function/minus.hpp> #include <boost/simd/function/selsub.hpp> #include <boost/dispatch/function/overload.hpp> #include <boost/config.hpp> namespace boost { namespace simd { namespace ext { namespace bd = boost::dispatch; BOOST_DISPATCH_OVERLOAD ( minusone_ , (typename A0) , bd::cpu_ , bd::generic_<bd::arithmetic_<A0> > ) { BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT { return selsub(is_not_equal(a0, Valmin<A0>()), a0, One<A0>()); } }; BOOST_DISPATCH_OVERLOAD ( minusone_ , (typename A0) , bd::cpu_ , bd::generic_<bd::floating_<A0> > ) { BOOST_FORCEINLINE A0 operator() ( A0 a0) const BOOST_NOEXCEPT { return a0-One<A0>(); } }; } } } #endif
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.algebra.ring.ulift import Mathlib.ring_theory.witt_vector.basic import Mathlib.data.mv_polynomial.funext import Mathlib.PostPort universes u_2 u_1 u namespace Mathlib /-! # The `is_poly` predicate `witt_vector.is_poly` is a (type-valued) predicate on functions `f : Π R, 𝕎 R → 𝕎 R`. It asserts that there is a family of polynomials `φ : ℕ → mv_polynomial ℕ ℤ`, such that the `n`th coefficient of `f x` is equal to `φ n` evaluated on the coefficients of `x`. Many operations on Witt vectors satisfy this predicate (or an analogue for higher arity functions). We say that such a function `f` is a *polynomial function*. The power of satisfying this predicate comes from `is_poly.ext`. It shows that if `φ` and `ψ` witness that `f` and `g` are polynomial functions, then `f = g` not merely when `φ = ψ`, but in fact it suffices to prove ``` ∀ n, bind₁ φ (witt_polynomial p _ n) = bind₁ ψ (witt_polynomial p _ n) ``` (in other words, when evaluating the Witt polynomials on `φ` and `ψ`, we get the same values) which will then imply `φ = ψ` and hence `f = g`. Even though this sufficient condition looks somewhat intimidating, it is rather pleasant to check in practice; more so than direct checking of `φ = ψ`. In practice, we apply this technique to show that the composition of `witt_vector.frobenius` and `witt_vector.verschiebung` is equal to multiplication by `p`. ## Main declarations * `witt_vector.is_poly`, `witt_vector.is_poly₂`: two predicates that assert that a unary/binary function on Witt vectors is polynomial in the coefficients of the input values. * `witt_vector.is_poly.ext`, `witt_vector.is_poly₂.ext`: two polynomial functions are equal if their families of polynomials are equal after evaluating the Witt polynmials on them. * `witt_vector.is_poly.comp` (+ many variants) show that unary/binary compositions of polynomial functions are polynomial. * `witt_vector.id_is_poly`, `witt_vector.neg_is_poly`, `witt_vector.add_is_poly₂`, `witt_vector.mul_is_poly₂`: several well-known operations are polynomial functions (for Verschiebung, Frobenius, and multiplication by `p`, see their respective files). ## On higher arity analogues Ideally, there should be a predicate `is_polyₙ` for functions of higher arity, together with `is_polyₙ.comp` that shows how such functions compose. Since mathlib does not have a library on composition of higher arity functions, we have only implemented the unary and binary variants so far. Nullary functions (a.k.a. constants) are treated as constant functions and fall under the unary case. ## Tactics There are important metaprograms defined in this file: the tactics `ghost_simp` and `ghost_calc` and the attributes `@[is_poly]` and `@[ghost_simps]`. These are used in combination to discharge proofs of identities between polynomial functions. Any atomic proof of `is_poly` or `is_poly₂` (i.e. not taking additional `is_poly` arguments) should be tagged as `@[is_poly]`. Any lemma doing "ring equation rewriting" with polynomial functions should be tagged `@[ghost_simps]`, e.g. ```lean @[ghost_simps] lemma bind₁_frobenius_poly_witt_polynomial (n : ℕ) : bind₁ (frobenius_poly p) (witt_polynomial p ℤ n) = (witt_polynomial p ℤ (n+1)) ``` Proofs of identities between polynomial functions will often follow the pattern ```lean begin ghost_calc _, <minor preprocessing>, ghost_simp end ``` -/ /- ### Simplification tactics `ghost_simp` is used later in the development for certain simplifications. We define it here so it is a shared import. -/ namespace tactic namespace interactive /-- A macro for a common simplification when rewriting with ghost component equations. -/ /-- `ghost_calc` is a tactic for proving identities between polynomial functions. Typically, when faced with a goal like ```lean ∀ (x y : 𝕎 R), verschiebung (x * frobenius y) = verschiebung x * y ``` you can 1. call `ghost_calc` 2. do a small amount of manual work -- maybe nothing, maybe `rintro`, etc 3. call `ghost_simp` and this will close the goal. `ghost_calc` cannot detect whether you are dealing with unary or binary polynomial functions. You must give it arguments to determine this. If you are proving a universally quantified goal like the above, call `ghost_calc _ _`. If the variables are introduced already, call `ghost_calc x y`. In the unary case, use `ghost_calc _` or `ghost_calc x`. `ghost_calc` is a light wrapper around type class inference. All it does is apply the appropriate extensionality lemma and try to infer the resulting goals. This is subtle and Lean's elaborator doesn't like it because of the HO unification involved, so it is easier (and prettier) to put it in a tactic script. -/ end interactive end tactic namespace witt_vector /-! ### The `is_poly` predicate -/ theorem poly_eq_of_witt_polynomial_bind_eq' (p : ℕ) {idx : Type u_2} [hp : fact (nat.prime p)] (f : ℕ → mv_polynomial (idx × ℕ) ℤ) (g : ℕ → mv_polynomial (idx × ℕ) ℤ) (h : ∀ (n : ℕ), coe_fn (mv_polynomial.bind₁ f) (witt_polynomial p ℤ n) = coe_fn (mv_polynomial.bind₁ g) (witt_polynomial p ℤ n)) : f = g := sorry theorem poly_eq_of_witt_polynomial_bind_eq (p : ℕ) [hp : fact (nat.prime p)] (f : ℕ → mv_polynomial ℕ ℤ) (g : ℕ → mv_polynomial ℕ ℤ) (h : ∀ (n : ℕ), coe_fn (mv_polynomial.bind₁ f) (witt_polynomial p ℤ n) = coe_fn (mv_polynomial.bind₁ g) (witt_polynomial p ℤ n)) : f = g := sorry -- Ideally, we would generalise this to n-ary functions -- But we don't have a good theory of n-ary compositions in mathlib /-- A function `f : Π R, 𝕎 R → 𝕎 R` that maps Witt vectors to Witt vectors over arbitrary base rings is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th coefficient of `f x` is given by evaluating `φₙ` at the coefficients of `x`. See also `witt_vector.is_poly₂` for the binary variant. The `ghost_calc` tactic treats `is_poly` as a type class, and the `@[is_poly]` attribute derives certain specialized composition instances for declarations of type `is_poly f`. For the most part, users are not expected to treat `is_poly` as a class. -/ def is_poly (p : ℕ) (f : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R) := ∃ (φ : ℕ → mv_polynomial ℕ ℤ), ∀ {R : Type u_1} [_inst_4 : comm_ring R] (x : witt_vector p R), coeff (f x) = fun (n : ℕ) => coe_fn (mv_polynomial.aeval (coeff x)) (φ n) /-- The identity function on Witt vectors is a polynomial function. -/ protected instance id_is_poly (p : ℕ) : is_poly p fun (_x : Type u_1) (_x_1 : comm_ring _x) => id := Exists.intro mv_polynomial.X fun (R : Type u_1) (_inst_4 : comm_ring R) (x : witt_vector p R) => eq.mpr (id ((fun (a a_1 : ℕ → R) (e_1 : a = a_1) (ᾰ ᾰ_1 : ℕ → R) (e_2 : ᾰ = ᾰ_1) => congr (congr_arg Eq e_1) e_2) (coeff ((fun (_x : Type u_1) (_x_1 : comm_ring _x) => id) R _inst_4 x)) (coeff x) ((fun (x x_1 : witt_vector p R) (e_1 : x = x_1) => congr_arg coeff e_1) ((fun (_x : Type u_1) (_x_1 : comm_ring _x) => id) R _inst_4 x) x (id.equations._eqn_1 x)) (fun (n : ℕ) => coe_fn (mv_polynomial.aeval (coeff x)) (mv_polynomial.X n)) (coeff x) (funext fun (n : ℕ) => mv_polynomial.aeval_X (coeff x) n))) (Eq.refl (coeff x)) protected instance id_is_poly_i' (p : ℕ) : is_poly p fun (_x : Type u_1) (_x_1 : comm_ring _x) (a : witt_vector p _x) => a := witt_vector.id_is_poly p namespace is_poly protected instance inhabited (p : ℕ) : Inhabited (is_poly p fun (_x : Type u_1) (_x_1 : comm_ring _x) => id) := { default := witt_vector.id_is_poly p } theorem ext {p : ℕ} [hp : fact (nat.prime p)] {f : {R : Type u} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} {g : {R : Type u} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} (hf : is_poly p f) (hg : is_poly p g) (h : ∀ (R : Type u) [_Rcr : comm_ring R] (x : witt_vector p R) (n : ℕ), coe_fn (ghost_component n) (f x) = coe_fn (ghost_component n) (g x)) (R : Type u) [comm_ring R] (x : witt_vector p R) : f x = g x := sorry /-- The composition of polynomial functions is polynomial. -/ theorem comp {p : ℕ} {g : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} {f : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} (hg : is_poly p g) (hf : is_poly p f) : is_poly p fun (R : Type u_1) (_Rcr : comm_ring R) => g ∘ f := sorry end is_poly /-- A binary function `f : Π R, 𝕎 R → 𝕎 R → 𝕎 R` on Witt vectors is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th coefficient of `f x y` is given by evaluating `φₙ` at the coefficients of `x` and `y`. See also `witt_vector.is_poly` for the unary variant. The `ghost_calc` tactic treats `is_poly₂` as a type class, and the `@[is_poly]` attribute derives certain specialized composition instances for declarations of type `is_poly₂ f`. For the most part, users are not expected to treat `is_poly₂` as a class. -/ def is_poly₂ (p : ℕ) (f : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R) := ∃ (φ : ℕ → mv_polynomial (fin (bit0 1) × ℕ) ℤ), ∀ {R : Type u_1} [_inst_4 : comm_ring R] (x y : witt_vector p R), coeff (f x y) = fun (n : ℕ) => peval (φ n) (matrix.vec_cons (coeff x) (matrix.vec_cons (coeff y) matrix.vec_empty)) /-- The composition of polynomial functions is polynomial. -/ theorem is_poly₂.comp {p : ℕ} {h : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R} {f : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} {g : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} (hh : is_poly₂ p h) (hf : is_poly p f) (hg : is_poly p g) : is_poly₂ p fun (R : Type u_1) (_Rcr : comm_ring R) (x y : witt_vector p R) => h (f x) (g y) := sorry /-- The composition of a polynomial function with a binary polynomial function is polynomial. -/ theorem is_poly.comp₂ {p : ℕ} {g : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} {f : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R} (hg : is_poly p g) (hf : is_poly₂ p f) : is_poly₂ p fun (R : Type u_1) (_Rcr : comm_ring R) (x y : witt_vector p R) => g (f x y) := sorry /-- The diagonal `λ x, f x x` of a polynomial function `f` is polynomial. -/ theorem is_poly₂.diag {p : ℕ} {f : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R} (hf : is_poly₂ p f) : is_poly p fun (R : Type u_1) (_Rcr : comm_ring R) (x : witt_vector p R) => f x x := sorry namespace tactic /-! ### The `@[is_poly]` attribute This attribute is used to derive specialized composition instances for `is_poly` and `is_poly₂` declarations. -/ /-- If `n` is the name of a lemma with opened type `∀ vars, is_poly p _`, `mk_poly_comp_lemmas n vars p` adds composition instances to the environment `n.comp_i` and `n.comp₂_i`. -/ /-- If `n` is the name of a lemma with opened type `∀ vars, is_poly₂ p _`, `mk_poly₂_comp_lemmas n vars p` adds composition instances to the environment `n.comp₂_i` and `n.comp_diag`. -/ /-- The `after_set` function for `@[is_poly]`. Calls `mk_poly(₂)_comp_lemmas`. -/ /-- `@[is_poly]` is applied to lemmas of the form `is_poly f φ` or `is_poly₂ f φ`. These lemmas should *not* be tagged as instances, and only atomic `is_poly` defs should be tagged: composition lemmas should not. Roughly speaking, lemmas that take `is_poly` proofs as arguments should not be tagged. Type class inference struggles with function composition, and the higher order unification problems involved in inferring `is_poly` proofs are complex. The standard style writing these proofs by hand doesn't work very well. Instead, we construct the type class hierarchy "under the hood", with limited forms of composition. Applying `@[is_poly]` to a lemma creates a number of instances. Roughly, if the tagged lemma is a proof of `is_poly f φ`, the instances added have the form ```lean ∀ g ψ, [is_poly g ψ] → is_poly (f ∘ g) _ ``` Since `f` is fixed in this instance, it restricts the HO unification needed when the instance is applied. Composition lemmas relating `is_poly` with `is_poly₂` are also added. `id_is_poly` is an atomic instance. The user-written lemmas are not instances. Users should be able to assemble `is_poly` proofs by hand "as normal" if the tactic fails. -/ end tactic /-! ### `is_poly` instances These are not declared as instances at the top level, but the `@[is_poly]` attribute adds instances based on each one. Users are expected to use the non-instance versions manually. -/ /-- The additive negation is a polynomial function on Witt vectors. -/ theorem neg_is_poly {p : ℕ} [hp : fact (nat.prime p)] : is_poly p fun (R : Type u_1) (_x : comm_ring R) => Neg.neg := sorry /- To avoid a theory of 0-ary functions (a.k.a. constants) we model them as constant unary functions. -/ /-- The function that is constantly zero on Witt vectors is a polynomial function. -/ protected instance zero_is_poly {p : ℕ} [hp : fact (nat.prime p)] : is_poly p fun (_x : Type u_1) (_x_1 : comm_ring _x) (_x_2 : witt_vector p _x) => 0 := Exists.intro 0 fun (R : Type u_1) (_inst_4 : comm_ring R) (x : witt_vector p R) => funext fun (n : ℕ) => eq.mpr (id ((fun (a a_1 : R) (e_1 : a = a_1) (ᾰ ᾰ_1 : R) (e_2 : ᾰ = ᾰ_1) => congr (congr_arg Eq e_1) e_2) (coeff ((fun (_x : Type u_1) (_x_1 : comm_ring _x) (_x_2 : witt_vector p _x) => 0) R _inst_4 x) n) 0 (zero_coeff p R n) (coe_fn (mv_polynomial.aeval (coeff x)) (HasZero.zero n)) 0 (Eq.trans ((fun (x x_1 : alg_hom ℤ (mv_polynomial ℕ ℤ) R) (e_1 : x = x_1) (ᾰ ᾰ_1 : mv_polynomial ℕ ℤ) (e_2 : ᾰ = ᾰ_1) => congr (congr_arg coe_fn e_1) e_2) (mv_polynomial.aeval (coeff x)) (mv_polynomial.aeval (coeff x)) (Eq.refl (mv_polynomial.aeval (coeff x))) (HasZero.zero n) 0 (pi.zero_apply n)) (alg_hom.map_zero (mv_polynomial.aeval (coeff x)))))) (Eq.refl 0) @[simp] theorem bind₁_zero_witt_polynomial {p : ℕ} {R : Type u} [hp : fact (nat.prime p)] [comm_ring R] (n : ℕ) : coe_fn (mv_polynomial.bind₁ 0) (witt_polynomial p R n) = 0 := sorry /-- The coefficients of `1 : 𝕎 R` as polynomials. -/ def one_poly (n : ℕ) : mv_polynomial ℕ ℤ := ite (n = 0) 1 0 @[simp] theorem bind₁_one_poly_witt_polynomial {p : ℕ} [hp : fact (nat.prime p)] (n : ℕ) : coe_fn (mv_polynomial.bind₁ one_poly) (witt_polynomial p ℤ n) = 1 := sorry /-- The function that is constantly one on Witt vectors is a polynomial function. -/ protected instance one_is_poly {p : ℕ} [hp : fact (nat.prime p)] : is_poly p fun (_x : Type u_1) (_x_1 : comm_ring _x) (_x_2 : witt_vector p _x) => 1 := sorry /-- Addition of Witt vectors is a polynomial function. -/ theorem add_is_poly₂ {p : ℕ} [fact (nat.prime p)] : is_poly₂ p fun (_x : Type u_1) (_x_1 : comm_ring _x) => Add.add := Exists.intro (witt_add p) fun (R : Type u_1) (_inst_4 : comm_ring R) (x y : witt_vector p R) => Eq.refl (coeff ((fun (_x : Type u_1) (_x_1 : comm_ring _x) => Add.add) R _inst_4 x y)) /-- Multiplication of Witt vectors is a polynomial function. -/ theorem mul_is_poly₂ {p : ℕ} [fact (nat.prime p)] : is_poly₂ p fun (_x : Type u_1) (_x_1 : comm_ring _x) => Mul.mul := Exists.intro (witt_mul p) fun (R : Type u_1) (_inst_4 : comm_ring R) (x y : witt_vector p R) => Eq.refl (coeff ((fun (_x : Type u_1) (_x_1 : comm_ring _x) => Mul.mul) R _inst_4 x y)) -- unfortunately this is not universe polymorphic, merely because `f` isn't theorem is_poly.map {p : ℕ} {R : Type u} {S : Type u} [hp : fact (nat.prime p)] [comm_ring R] [comm_ring S] {f : {R : Type u} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} (hf : is_poly p f) (g : R →+* S) (x : witt_vector p R) : coe_fn (map g) (f x) = f (coe_fn (map g) x) := sorry namespace is_poly₂ protected instance inhabited {p : ℕ} [fact (nat.prime p)] : Inhabited (is_poly₂ p fun (_x : Type u_1) (_x_1 : comm_ring _x) => Add.add) := { default := add_is_poly₂ } /-- The composition of a binary polynomial function with a unary polynomial function in the first argument is polynomial. -/ theorem comp_left {p : ℕ} {g : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R} {f : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} (hg : is_poly₂ p g) (hf : is_poly p f) : is_poly₂ p fun (R : Type u_1) (_Rcr : comm_ring R) (x y : witt_vector p R) => g (f x) y := comp hg hf (witt_vector.id_is_poly p) /-- The composition of a binary polynomial function with a unary polynomial function in the second argument is polynomial. -/ theorem comp_right {p : ℕ} {g : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R} {f : {R : Type u_1} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R} (hg : is_poly₂ p g) (hf : is_poly p f) : is_poly₂ p fun (R : Type u_1) (_Rcr : comm_ring R) (x y : witt_vector p R) => g x (f y) := comp hg (witt_vector.id_is_poly p) hf theorem ext {p : ℕ} [hp : fact (nat.prime p)] {f : {R : Type u} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R} {g : {R : Type u} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R} (hf : is_poly₂ p f) (hg : is_poly₂ p g) (h : ∀ (R : Type u) [_Rcr : comm_ring R] (x y : witt_vector p R) (n : ℕ), coe_fn (ghost_component n) (f x y) = coe_fn (ghost_component n) (g x y)) (R : Type u) [comm_ring R] (x : witt_vector p R) (y : witt_vector p R) : f x y = g x y := sorry -- unfortunately this is not universe polymorphic, merely because `f` isn't theorem map {p : ℕ} {R : Type u} {S : Type u} [hp : fact (nat.prime p)] [comm_ring R] [comm_ring S] {f : {R : Type u} → [_inst_3 : comm_ring R] → witt_vector p R → witt_vector p R → witt_vector p R} (hf : is_poly₂ p f) (g : R →+* S) (x : witt_vector p R) (y : witt_vector p R) : coe_fn (map g) (f x y) = f (coe_fn (map g) x) (coe_fn (map g) y) := sorry end Mathlib
Glitz and glam in your hand, that’s what Chanel’s Silver Quilted Distressed Calfskin Cosmetic Bag is! The shiny skin is enhanced with silver hardware in the zipped top and cool logo on the front. There are no pockets in the gray-fabric-lined interior of this new and never worn case from 2011 that comes with a box and card. This little bit of Old Hollywood can do double duty as a clutch when you push your lip balm to one side and make room for your VIP passes!
```python import numpy as np import matplotlib.pyplot as plt import scipy.stats import scipy as sp from mpl_toolkits.mplot3d import Axes3D import statsmodels.api as sm import linregfunc as lr ``` E:\Anaconda\lib\site-packages\statsmodels\compat\pandas.py:65: FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead. from pandas import Int64Index as NumericIndex # <font face="gotham" color="purple"> Common Distributions in Hypothesis Testing </font> Here we will have a quick refresh of distributions that are commonly used in hypothesis testing. ## <font face="gotham" color="purple"> The Normal Distributions </font> Normal Distribution is the most important one among all, here we provide a graphic reminder of bivariate normal distribution. Please check out my notebooks of linear algebra, there is a whole chapter devoted for normal distribution. For your reference, the pdf of multivariate normal distribution is $$ p(\boldsymbol{x} ; \mu, \Sigma)=\frac{1}{(2 \pi)^{n / 2}|\Sigma|^{1 / 2}} \exp \left(-\frac{1}{2}(x-\mu)^{T} \Sigma^{-1}(x-\mu)\right) \tag{1}\label{1} $$ ```python x = np.linspace(-10,10,500) y = np.linspace(-10,10,500) X,Y = np.meshgrid(x,y) pos = np.array([X.flatten(),Y.flatten()]).T # two columns matrix fig = plt.figure(figsize=(14,14)) ######################### ax = fig.add_subplot(221, projection='3d') mu_x = 0 mu_y = 0 sigma_x = 3 sigma_y = 15 rho = 3 rv = sp.stats.multivariate_normal([mu_x, mu_y], [[sigma_x, rho], [rho, sigma_y]]) # frozen distribution ax.plot_surface(X, Y, rv.pdf(pos).reshape(500,500),cmap='coolwarm') ax = fig.add_subplot(223) ax.contour(rv.pdf(pos).reshape(500,500)) string1 = r'$\sigma_x = %.1f$, $\sigma_y = %.1f$, $\rho = %.1f$'% (sigma_x, sigma_y, rho) ax.annotate(text = string1, xy=(0.2, 0.05), xycoords='axes fraction', color = 'r') #### mu_x = 0 mu_y = 0 sigma_x = 10 sigma_y = 4 rho = 0 rv = sp.stats.multivariate_normal([mu_x, mu_y], [[sigma_x, rho], [rho, sigma_y]]) # frozen distribution ax = fig.add_subplot(222, projection='3d') ax.plot_surface(X, Y, rv.pdf(pos).reshape(500,500),cmap='coolwarm') ax = fig.add_subplot(224) ax.contour(rv.pdf(pos).reshape(500,500)) string2 = r'$\sigma_x = %.1f$, $\sigma_y = %.1f$, $\rho = %.1f$'% (sigma_x, sigma_y, rho) ax.annotate(text = string2, xy=(0.2, 0.05), xycoords='axes fraction', color = 'r') ######################### plt.show() ``` Keep in your mind: _any linear combination of normally distributed variables is yet a normal distribution_. ## <font face="gotham" color="purple"> The Chi-Squared Distribution </font> If an $n$-random vector follows $iid$ normal distribution, $\boldsymbol{z}\sim N(\boldsymbol{0}, \mathbf{I})$. Then the random variable $$ y = \boldsymbol{z}^T\boldsymbol{z} = \sum_{i=i}^n z_i^2 $$ is said to follow the **chi-squared distribution** with $n$ degrees of freedom. Denoted as $$ y\sim\chi^2(n) $$ The mean is $$\mathrm{E}(y)=\sum_{i=1}^{m} \mathrm{E}\left(z_{i}^{2}\right)=\sum_{i=1}^{m} 1=m$$ And the variance is $$\begin{aligned} \operatorname{Var}(y) &=\sum_{i=1}^{m} \operatorname{Var}\left(z_{i}^{2}\right)=m \mathrm{E}\left(\left(z_{i}^{2}-1\right)^{2}\right) \\ &=m \mathrm{E}\left(z_{i}^{4}-2 z_{i}^{2}+1\right)=m(3-2+1)=2 m \end{aligned}$$ As $n$ increases, the probability density function of $\chi^2$ approaches the $N(m, 2m)$. Here is the graphic demonstration shows how $\chi^2$ distribution changes as d.o.f. rises. ```python fig, ax = plt.subplots(figsize = (9, 9)) x = np.linspace(0, 50, 1000) for i in range(1, 14): chi_pdf = sp.stats.chi2.pdf(x, i) ax.plot(x, chi_pdf, lw = 3, label = '$\chi^2 (%.0d)$'%i) ax.legend(fontsize = 12) ax.axis([0, 20, 0, .6]) plt.show() ``` ### <font face="gotham" color="purple"> Quadratic Form of $\chi^2$ Distribution </font> If an $n$-random vector $\boldsymbol{y} \sim N(\boldsymbol{\mu}, \Sigma)$ then $$ (\boldsymbol{y} - \boldsymbol{\mu})^T\Sigma^{-1}(\boldsymbol{y}-\boldsymbol{\mu})\sim \chi^2(n) $$ If $\boldsymbol{y} \sim N(\boldsymbol{0}, \Sigma)$ simplifies the expression $$ \boldsymbol{y}^T\Sigma^{-1}\boldsymbol{y}\sim \chi^2(n) $$ We will show why that holds by using diagonal decomposition. Since the $\Sigma$ is symmetric, it is orthogonally diagonalizable, $$ \Sigma = QDQ^T $$ where $$ D=\left[\begin{array}{ccccc} \lambda_{1} & 0 & 0 & \ldots & 0 \\ 0 & \lambda_{2} & 0 & \ldots & 0 \\ \vdots & \vdots & \vdots & & \vdots \\ 0 & 0 & 0 & \ldots & \lambda_{n} \end{array}\right] $$ $\lambda$s are eigenvalues. And $Q^{-1} = Q^T$, $Q$ holds all the eigenvectors of $\Sigma$ which are mutually perpendicular. Denote $D^*$ as $$ D^* = \left[\begin{array}{ccccc} \frac{1}{\sqrt{\lambda_{1}}} & 0 & 0 & \ldots & 0 \\ 0 & \frac{1}{\sqrt{\lambda_{2}}} & 0 & \ldots & 0 \\ \vdots & \vdots & \vdots & & \vdots \\ 0 & 0 & 0 & \ldots & \frac{1}{\sqrt{\lambda_{n}}} \end{array}\right] $$ Let the matrix $H = QD^*Q^T$, since $H$ is also symmetric $$ HH^T= QD^*Q^TQD^*Q^T= Q^TD^*D^*Q = QD^{-1}Q^T =\Sigma^{-1} $$ Furthermore $$ H\Sigma H^T = QD^*Q^T\Sigma QD^*Q^T = QD^*Q^TQDQ^T QD^*Q^T = QD^*DD^*Q^T = QQ^T = I $$ Back to the results from above, we set $\boldsymbol{z} = H^T (\boldsymbol{y}-\boldsymbol{\mu})$, which is standard normal distribution since $$ E(\boldsymbol{z})= H^TE(\boldsymbol{y}-\boldsymbol{\mu})=\boldsymbol{0}\\ \text{Var}(\boldsymbol{z}) = H\text{Var}(\boldsymbol{y}-\boldsymbol{\mu})H^T =H\Sigma H^T = I $$ Back to where we started $$ (\boldsymbol{y}-\boldsymbol{\mu})^T\Sigma^{-1}(\boldsymbol{y}-\boldsymbol{\mu}) = (\boldsymbol{y}-\boldsymbol{\mu})^THH^T (\boldsymbol{y}-\boldsymbol{\mu}) = (H^T (\boldsymbol{y}-\boldsymbol{\mu}))^T(H^T (\boldsymbol{y}-\boldsymbol{\mu})) = \boldsymbol{z}^T\boldsymbol{z} $$ here we proved that $(\boldsymbol{y}-\boldsymbol{\mu})^T\Sigma^{-1}(\boldsymbol{y}-\boldsymbol{\mu}) \sim \chi^2(n)$. More details of proof in <a href='https://math.stackexchange.com/questions/2808041/x-normally-distributed-then-xt-sigma-1-x-follows-chi-square-distribut?noredirect=1&lq=1'>this page</a>. ## <font face="gotham" color="purple"> The Student’s $t$ Distribution </font> If $z\sim N(0, 1)$ and $y\sim \chi^2(m)$, and $z$ and $y$ are independent, then $$ t = \frac{z}{\sqrt{y/m}} $$ follows the **Student's t distribution** with $m$ d.o.f. Here is the plot of $t$-distribution, note that $t(1)$ is called **Cauchy distribution** which has no moments at all, because integral does not converge due to fat tails. ```python fig, ax = plt.subplots(figsize = (12, 7)) x = np.linspace(-5, 5, 1000) for i in range(1, 6): chi_pdf = sp.stats.t.pdf(x, i) if i == 1: ax.plot(x, chi_pdf, lw = 3, label = 'Cauchy', ls = '--') continue else: ax.plot(x, chi_pdf, lw = 3, label = '$t (%.0d)$'%i) ax.legend(fontsize = 12) ax.axis([-5, 5, 0, .4]) ax.set_title("Student's $t$ Distribution", size = 18) plt.show() ``` As $m \rightarrow \infty$, $t(m)\rightarrow N(0, 1)$, in the limit process, the tails of $t$ distribution will diminish, and becoming thinner. ## <font face="gotham" color="purple"> The $F$ Distribution </font> If $y_1$ and $y_2$ are independent random variables distributed as $\chi^2(m_1)$ and $\chi^2(m_2)$, then the random variable $$ F = \frac{y_1/m_1}{y_2/m_2} $$ follows the **$F$ distribution**, denoted $ F(m_1, m_2)$. ```python x = np.linspace(.001, 5, 100) fig, ax = plt.subplots(figsize = (12, 7)) df1 = 10 df2 = 2 f_pdf = sp.stats.f.pdf(x, dfn = df1, dfd = df2) ax.plot(x, f_pdf, lw =3, label = '$df_1 = %.d, df_2 = %.d$' %(df1, df2)) df1 = 2 df2 = 10 f_pdf = sp.stats.f.pdf(x, dfn = df1, dfd = df2) ax.plot(x, f_pdf, lw =3, label = '$df_1 = %.d, df_2 = %.d$ '%(df1, df2)) df1 = 8 df2 = 15 f_pdf = sp.stats.f.pdf(x, dfn = df1, dfd = df2) ax.plot(x, f_pdf, lw =3, color = 'red', label = '$df_1 = %.d, df_2 = %.d$' %(df1, df2)) df1 = 15 df2 = 8 f_pdf = sp.stats.f.pdf(x, dfn = df1, dfd = df2) ax.plot(x, f_pdf, lw =3, label = '$df_1 = %.d, df_2 = %.d$ '%(df1, df2)) ax.legend(fontsize = 15) ax.axis([0, 4, 0, .8]) ax.set_title("$F$ Distribution", size = 18) plt.show() ``` # <font face="gotham" color="purple">Single Restriction </font> Any linear restriction, such as $\beta_1 = 5$, $\beta_1 =2{\beta_2}$ can be tested, however, no loss of generality if linear restriction of $\beta_2=0$ is demonstrated. We first take a look at single restriction, see how FWL regression can help to construct statistic tests. The regression model is $$ \boldsymbol{y} = \boldsymbol{X}_1\boldsymbol{\beta}_1+\beta_2\boldsymbol{x}_2+\boldsymbol{u} $$ where $\boldsymbol{x}_2$ is an $n$-vector, whereas $\boldsymbol{X}_1$ is an $n\times (m-1)$ matrix. Project $\boldsymbol{X}_1$ off $\boldsymbol{x}_2$, the FWL regression is $$ \boldsymbol{M}_1\boldsymbol{y} = \beta_2\boldsymbol{M}_1\boldsymbol{x}_2 + \boldsymbol{M}_1\boldsymbol{u} $$ Applying OLS estimate and variance formula, $$ \hat{\beta}_2 = [(\boldsymbol{M}_1\boldsymbol{x}_2)^T\boldsymbol{M}_1\boldsymbol{x}_2]^{-1}(\boldsymbol{M}_1\boldsymbol{x}_2)^T\boldsymbol{M}_1\boldsymbol{y}=(\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{x}_2)^{-1}\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{y}=\frac{\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{y}}{\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{x}_2}\\ \text{Var}(\hat{\beta}_2) = \sigma^2 [(\boldsymbol{M}_1\boldsymbol{x}_2)^T(\boldsymbol{M}_1\boldsymbol{x}_2)]^{-1} = \sigma^2(\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{x}_2)^{-1} $$ If null hypothesis is $\beta_2^0=0$, also assuming that $\sigma^2$ is known. Construct a $z$-statistic $$ z_{\beta_2} = \frac{\hat{\beta}_2} {\sqrt{\text{Var}(\hat{\beta}_2)}}=\frac{\frac{\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{y}}{\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{x}_2}}{ \sigma(\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{x}_2)^{-\frac{1}{2}}} = \frac{\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{y}}{\sigma(\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{x}_2)^{\frac{1}{2}}} $$ However, $\sigma$ is not likely to be known, hence we replace it with $s$, the least square standard error estimator. Recall that $$ s^2 =\frac{1}{n-k} \sum_{t=1}^n u_t^2 = \frac{\boldsymbol{u}^T\boldsymbol{u}}{n-k}= \frac{(\boldsymbol{M_X y})^T\boldsymbol{M_X y}}{n-k}=\frac{\boldsymbol{y}^T\boldsymbol{M_X y}}{n-k} $$ Replace the $\sigma$ in $z_{\beta_2}$, we obtain $t$-statistic $$ t_{\beta_2} = \frac{\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{y}}{s(\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{x}_2)^{\frac{1}{2}}} = \left(\frac{\boldsymbol{y}^T\boldsymbol{M_X y}}{n-k}\right)^{-\frac{1}{2}}\frac{\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{y}}{(\boldsymbol{x}_2^T\boldsymbol{M}_1\boldsymbol{x}_2)^{\frac{1}{2}}} $$ Of course we can also show it indeed follows the $t$ distribution by using the definition that the ratio of standard normal variable to a $\chi^2$ variable. However, this is unnecessary for us. # <font face="gotham" color="purple"> Multiple Restrictions </font> Multiple restrictions test can be formulated as following $$ H_0:\quad \boldsymbol{y} = \boldsymbol{X}_1\boldsymbol{\beta_1} + \boldsymbol{u}\\ H_1:\quad \boldsymbol{y} = \boldsymbol{X}_1\boldsymbol{\beta_1} +\boldsymbol{X}_2\boldsymbol{\beta_2}+ \boldsymbol{u} $$ $H_0$ is restricted model, $H_1$ is unrestricted. And we denote restricted residual sum of squares as $\text{RRSS}$, and unrestricted residual sum of squares as $\text{URSS}$, the test statistic is $$ F_{\beta_2}= \frac{(\text{RRSS}-\text{URSS})/r}{\text{URSS}/(n-k)} $$ where $r=k_2$, the number of restrictions on $\beta_2$. Using FWL regression with $\boldsymbol{M}_1$ and $\text{TSS = ESS + RSS}$, $$ \boldsymbol{M}_1\boldsymbol{y}=\boldsymbol{M}_1\boldsymbol{X}_2\boldsymbol{\beta}_2+\boldsymbol{u} \tag{FWL regression} $$ \begin{align} \text{URSS}& =(\boldsymbol{M_1y})^T\boldsymbol{M_1y}- \underbrace{\left[\boldsymbol{M}_1\boldsymbol{X}_2[(\boldsymbol{M}_1\boldsymbol{X}_2)^T\boldsymbol{M}_1\boldsymbol{X}_2]^{-1}(\boldsymbol{M}_1\boldsymbol{X}_2)^T\boldsymbol{y}\right]^T}_{\text{projection matrix}\ P}\boldsymbol{y}\\ &= \boldsymbol{y}^T\boldsymbol{M}_1\boldsymbol{y} -\boldsymbol{y}^T\boldsymbol{M}_1\boldsymbol{X}_2(\boldsymbol{X}_2^T\boldsymbol{M}_1\boldsymbol{X}_2)^{-1}\boldsymbol{X}^T_2\boldsymbol{M}_1 \boldsymbol{y} = \boldsymbol{y}^T\boldsymbol{M_X}\boldsymbol{y} \end{align} $$ \text{RRSS} = (\boldsymbol{M}_1y)^T\boldsymbol{M}_1y = \boldsymbol{y}^T\boldsymbol{M}_1\boldsymbol{y} $$ Therefore $$ \text{RRSS}-\text{URSS}=\boldsymbol{y}^T\boldsymbol{M}_1\boldsymbol{X}_2(\boldsymbol{X}_2^T\boldsymbol{M}_1\boldsymbol{X}_2)^{-1}\boldsymbol{X}^T_2\boldsymbol{M}_1 \boldsymbol{y} $$ We have all parts of $F$ statistic, combine them $$ F_{\boldsymbol{\beta}_{2}}=\frac{\boldsymbol{y}^{T} \boldsymbol{M}_{1} \boldsymbol{X}_{2}\left(\boldsymbol{X}_{2}^{T} \boldsymbol{M}_{1} \boldsymbol{X}_{2}\right)^{-1} \boldsymbol{X}_{2}^{T} \boldsymbol{M}_{1} \boldsymbol{y} / r}{\boldsymbol{y}^{T} \boldsymbol{M}_{\boldsymbol{X}} \boldsymbol{y} /(n-k)} $$ In contrast, $t$ statistic will be $$ t_{\beta_{2}}=\sqrt{\frac{\boldsymbol{y}^{\top} \boldsymbol{M}_{1} \boldsymbol{x}_{2}\left(\boldsymbol{x}_{2}^{\top} \boldsymbol{M}_{1} \boldsymbol{x}_{2}\right)^{-1} \boldsymbol{x}_{2}^{\top} \boldsymbol{M}_{1} \boldsymbol{y}}{\boldsymbol{y}^{\top} \boldsymbol{M}_{\boldsymbol{X}} \boldsymbol{y} /(n-k)}} $$ To test the equality of two parameter vectors, we modify the $F$ test as $$ F_{\gamma}=\frac{\left(\mathrm{RRSS}-\mathrm{RSS}_{1}-\mathrm{RSS}_{2}\right) / k}{\left(\mathrm{RSS}_{1}+\mathrm{RSS}_{2}\right) /(n-2 k)} $$ for example, the sample being divided into two subsamples, to compare the stability of two subsamples, this so-called **Chow test** is a common practice. # <font face="gotham" color="purple"> Asymptotic Theory </font> **Asymptotic Theory** is concerned with the distribution of estimators and test statistics as the sample size $n$ tends to infinity. ## <font face="gotham" color="purple"> Law of Large Numbers </font> The widely-known **Law of Large Numbers** ($\text{LLN}$) takes the form $$ \bar{x} = \frac{1}{n}\sum_{t=1}^nx_t $$ where $x_t$ are independent variables with its own bounded variance $\sigma_t^2$ and a common mean $\mu$. $\text{LLN}$ tells that as $n\rightarrow \infty$, then $\bar{x} \rightarrow \mu$. The **Fundamental Theorem of Statistics** can be proved with $\text{LLN}$. An **empirical distribution function** ($\text{EDF}$) can be expressed as $$ \hat{F}(x) \equiv \frac{1}{n} \sum_{t=1}^{n} I\left(x_{t} \leq x\right) $$ where $I(\cdot)$ is an **indicator function**, which takes value $1$ when its argument is true, otherwise $0$. To prove the Fundamental Theorem of Statistics, we invoke the $\text{LLN}$, expand the expectation \begin{aligned} \mathrm{E}\left(I\left(x_{t} \leq x\right)\right) &=0 \cdot \operatorname{Pr}\left(I\left(x_{t} \leq x\right)=0\right)+1 \cdot \operatorname{Pr}\left(I\left(x_{t} \leq x\right)=1\right) \\ &=\operatorname{Pr}\left(I\left(x_{t} \leq x\right)=1\right)=\operatorname{Pr}\left(x_{t} \leq x\right)=F(x) \end{aligned} It turns out that $\hat{F}(x)$ is a consistent estimator of $F(x)$. ## <font face="gotham" color="purple"> Central Limit Theorems </font> The **Central Limit Theorems** ($\text{CLT}$) tells that $\frac{1}{n}$ times the sum of $n$ centered random variables will approximately follow a normal distribution when $n$ is sufficiently large. The most well $\text{CLT}$ is **Lindeberg-Lévy** $\text{CLT}$, the quantity $$ z \equiv \frac{1}{\sqrt{n}} \sum_{t=1}^{n} \frac{x_{t}-\mu}{\sigma} $$ is **asymptotically distributed** as $N(0,1)$. We won't bother to prove them, but they are the implicit theoretical foundation when we are discussing **simulation-based tests**. # <font face="gotham" color="purple"> Simulated $P$ Values </font> ```python t_stats_real_model = betahat.T[0]/np.sqrt(cov_betahat_prin_diag) print('t statistics: {}'.format(t_stats)) p_values_real_model = 2*(1-sp.stats.t.cdf(t_stats, df=n-k, loc=0, scale=1)) print('p_values: {}'.format(p_values)) ``` t statistics: [1.75043396 2.79293141 2.73485916] p_values: [0.25890776 0.00241733 0.07849986] Above will be our imaginary real data. ```python ``` ```python ``` ```python ``` ```python indicator_array = np.array([0, 0, 0]) sim_rounds = 5000 for i in range(sim_rounds): u = lr.gen_u(n) y = X@beta + 15*u betahat = lr.ols(y, X) resid = y - X@betahat cov_betahat, cov_betahat_prin_diag = lr.cov_beta_hat(resid, k, X) t_stats_sim = betahat.T[0]/np.sqrt(cov_betahat_prin_diag) indicator = t_stats_sim - t_stats_real_model indicator[indicator < 0] = 0 indicator[indicator > 0] = 1 indicator_array = np.vstack([indicator_array, indicator]) indicator_array = indicator_array[1:] ``` ```python np.sum(indicator_array, axis = 0)/sim_rounds ``` array([0.6924, 0.288 , 0.3778]) ```python indicator ``` array([1., 1., 0.]) ```python ``` ```python comparison = p_values - A comparison ``` array([-0.04109224, 0.00141733, 0.02849986]) ```python comparison[comparison<0] = 0 ``` ```python comparison[comparison>0] = 1 ``` ```python np.vstack([comparison, comparison1]) ``` array([[0., 1., 1.], [1., 2., 3.]]) ```python ```
function rnd = getround %GETROUND Get rounding mode % % rnd = getround % %On return, % % rnd = -1 for rounding downwards % rnd = 0 for rounding to nearest % rnd = 1 for rounding upwards % rnd = 2 for rounding towards zero (chop) % % written 11/23/98 S.M. Rump % modified 12/04/05 S.M. Rump improved performance % modified 12/15/07 T. Ogita modified for Intel-based Mac % e = []; e = 1e-30; x = 1 + e; y = 1 - e; if x == y % fast check for rounding to nearest rnd = 0; else e = []; e = 1e-30; z = (-1) + e; if ( x==1 ) & ( z==-1 ) % round downwards rnd = -1; elseif ( y==1 ) % round upwards rnd = +1; else rnd = 2; end end
(*************************************************************) (* Copyright Dominique Larchey-Wendling [*] *) (* *) (* [*] Affiliation LORIA -- CNRS *) (*************************************************************) (* This file is distributed under the terms of the *) (* CeCILL v2 FREE SOFTWARE LICENSE AGREEMENT *) (*************************************************************) (* Certified Undecidability of Intuitionistic Linear Logic via Binary Stack Machines and Minsky Machines. Yannick Forster and Dominique Larchey-Wendling. CPP '19. http://uds-psl.github.io/ill-undecidability/ *) Require Import List Permutation. From Undecidability.ILL Require Import ILL. Set Implicit Arguments. Local Infix "~p" := (@Permutation _) (at level 70). Notation eill_vars := nat. Inductive eill_cmd : Set := | in_eill_cmd_inc : eill_vars -> eill_vars -> eill_vars -> eill_cmd | in_eill_cmd_dec : eill_vars -> eill_vars -> eill_vars -> eill_cmd | in_eill_cmd_fork : eill_vars -> eill_vars -> eill_vars -> eill_cmd. Notation LL_INC := in_eill_cmd_inc. Notation LL_DEC := in_eill_cmd_dec. Notation LL_FORK := in_eill_cmd_fork. Definition eill_cmd_vars c := match c with | LL_INC a p q => a::p::q::nil | LL_DEC a p q => a::p::q::nil | LL_FORK p q r => p::q::r::nil end. (* The embedding of eill commands into ill or its (!,&,-o) fragment *) Definition eill_cmd_map c := match c with | LL_INC a p q => (£a ⊸ £p) ⊸ £ q | LL_DEC a p q => £a ⊸ £p ⊸ £ q | LL_FORK p q r => (£p & £q) ⊸ £ r end. (* Symbols for cut&paste ⟙ ⟘ 𝝐 ﹠ ⊗ ⊕ ⊸ ! ‼ ∅ ⊢ ⟦ ⟧ Γ Δ Σ *) Section GeILL. Reserved Notation "Σ ; Γ ⊦ u" (at level 70, no associativity). Inductive G_eill (Σ : list eill_cmd) : list eill_vars -> eill_vars -> Prop := | in_geill_ax : forall u, Σ; u::∅ ⊦ u | in_geill_perm : forall Γ Δ p, Γ ~p Δ -> Σ; Γ ⊦ p -> Σ; Δ ⊦ p | in_geill_inc : forall Γ a p q, In (LL_INC a p q) Σ -> Σ; a::Γ ⊦ p -> Σ; Γ ⊦ q | in_geill_dec : forall Γ Δ p q r, In (LL_DEC p q r) Σ -> Σ; Γ ⊦ p -> Σ; Δ ⊦ q -> Σ; Γ++Δ ⊦ r | in_geill_fork : forall Γ p q r, In (LL_FORK p q r) Σ -> Σ; Γ ⊦ p -> Σ; Γ ⊦ q -> Σ; Γ ⊦ r where "Σ ; Γ ⊦ u" := (G_eill Σ Γ u). End GeILL. Definition EILL_SEQUENT := (list eill_cmd * list eill_vars * eill_vars)%type. Definition EILL_PROVABILITY (c : EILL_SEQUENT) := match c with (Σ,Γ,u) => G_eill Σ Γ u end.
#redirect Angela Pourtabib
module Bodies import Base:diff,length,push!,vec using Statistics: mean export Body,RigidTransform,midpoints,dlength,normal,dlengthmid,centraldiff,normalmid abstract type Body{N} end include("bodies/bodylist.jl") """ RigidTransform(x::Tuple{Float64,Float64},α::Float64) Construct a rigid-body transform operator, with rotation by angle `α` and translation specified by `x`. The translation coordinates are specified in the target coordinate system. The resulting transform can be used as an operator on pairs of coordinate vectors, `x` and `y`, or on bodies. For transformation of bodies, it only overwrites the `x` and `y` fields of the body, but leaves the `x̃` and `ỹ` (body coordinates) intact. The translation can be provided as either a tuple `(x,y)` or as a complex number. # Constructors - `RigidTransform((x,y),α)` - `RigidTransform(u::Vector{Float64})` - `RigidTransform(u::NTuple{3,Float64})` - `RigidTransform.(u)` where `u` is a collection of vectors or tuples. # Example ```jldoctest julia> body = Bodies.Ellipse(0.5,0.1,100) Elliptical body with 100 points and semi-axes (0.5,0.1) Current position: (0.0,0.0) Current angle (rad): 0.0 julia> T = RigidTransform((1.0,1.0),π/4) Rigid-body transform Translation: (1.0,1.0) Rotation angle (rad): 0.7853981633974483 julia> T(body) Elliptical body with 100 points and semi-axes (0.5,0.1) Current position: (1.0,1.0) Current angle (rad): 0.7853981633974483 ``` """ struct RigidTransform α :: Float64 rot :: Matrix{Float64} trans :: Tuple{Float64,Float64} end function RigidTransform(x::Tuple{Float64,Float64},α::Float64) rot = [cos(α) -sin(α) sin(α) cos(α)] RigidTransform(α,rot,x) end RigidTransform(x::Union{Vector{Float64},NTuple{3,Float64}}) = RigidTransform((x[1],x[2]),x[3]) RigidTransform(c::ComplexF64,α::Float64) = RigidTransform((real(c),imag(c)),α) #RigidTransform(x::Vector{Vector{Float64}}) = function Base.show(io::IO, T::RigidTransform) name = "Rigid-body transform" println(io, name) println(io, " Translation: ($(T.trans[1]),$(T.trans[2]))") println(io, " Rotation angle (rad): $(T.α)") end """ vec(T::RigidTransform) -> Vector{Float64} Returns a length-3 vector of the form [x,y,α] corresponding to the translation and rotation specified by the given transform `T`. """ vec(T::RigidTransform) = [T.trans[1],T.trans[2],T.α] """ vec(tl::Vector{RigidTransform}) -> NTuple{N,Vector{Float64}} Returns a tuple of length-3 vectors of the form [x,y,α] corresponding to the translation and rotation specified by the given by the list of transforms `tl`. """ function vec(tl::Union{Vector{RigidTransform},NTuple{N,RigidTransform}}) where {N} u = (vec(tl[1]),) for i = 2:length(tl) u = u...,vec(tl[i]) end return u end function (T::RigidTransform)(x̃::Float64,ỹ::Float64) Xr = T.rot*[x̃,ỹ] return T.trans .+ (Xr[1],Xr[2]) end function (T::RigidTransform)(x̃::AbstractVector{Float64},ỹ::AbstractVector{Float64}) x = deepcopy(x̃) y = deepcopy(ỹ) for i = 1:length(x̃) x[i],y[i] = T(x̃[i],ỹ[i]) end return x, y end function (T::RigidTransform)(b::Body{N}) where {N} b.x, b.y = T(b.x̃,b.ỹ) b.α = T.α b.cent = T.trans return b end # Evaluate some geometric details of a body """ length(body::Body) Return the number of points on the body perimeter """ length(::Body{N}) where {N} = N """ diff(body::Body/BodyList) -> Tuple{Vector{Float64},Vector{Float64}} Compute the x and y differences of the faces on the perimeter of body `body`, whose ends are at the current `x` and `y` coordinates (in inertial space) of the body. Face 1 corresponds to the face between points 1 and 2, for example. If `body` is a `BodyList`, then it computes the differences separately on each constituent body. """ diff(b::Body{N}) where {N} = _diff(b.x,b.y) function diff(bl::BodyList) dx = Float64[] dy = Float64[] for b in bl dxb, dyb = diff(b) append!(dx,dxb) append!(dy,dyb) end return dx, dy end function _diff(x::Vector{Float64},y::Vector{Float64}) N = length(x) @assert N == length(y) ip1(i) = 1+mod(i,N) dxtmp = [x[ip1(i)] - x[i] for i = 1:N] dytmp = [y[ip1(i)] - y[i] for i = 1:N] return dxtmp, dytmp end """ midpoints(body::Body/BodyList) -> Tuple{Vector{Float64},Vector{Float64}} Compute the x and y midpoints of the faces on the perimeter of body `body`, whose ends are at the current `x` and `y` coordinates (in inertial space) of the body. Face 1 corresponds to the face between points 1 and 2, for example. If `body` is a `BodyList`, then it computes the differences separately on each constituent body. """ midpoints(b::Body{N}) where {N} = _midpoints(b.x,b.y) function midpoints(bl::BodyList) xc = Float64[] yc = Float64[] for b in bl xcb, ycb = midpoints(b) append!(xc,xcb) append!(yc,ycb) end return xc, yc end function _midpoints(x::Vector{Float64},y::Vector{Float64}) N = length(x) @assert N == length(y) ip1(i) = 1+mod(i,N) xc = 0.5*[x[ip1(i)] + x[i] for i = 1:N] yc = 0.5*[y[ip1(i)] + y[i] for i = 1:N] return xc, yc end """ centraldiff(body::Body/BodyList) -> Tuple{Vector{Float64},Vector{Float64}} Compute the circular central differences of coordinates on body `body` (or on each body in list `body`). """ function centraldiff(b::Body{N}) where {N} ip1(i) = 1+mod(i,N) xc, yc = midpoints(b) xc .= circshift(xc,1) yc .= circshift(yc,1) return _diff(xc,yc) end function centraldiff(bl::BodyList) dx = Float64[] dy = Float64[] for b in bl dxb, dyb = centraldiff(b) append!(dx,dxb) append!(dy,dyb) end return dx, dy end """ dlength(body::Body/BodyList) -> Vector{Float64} Compute the lengths of the faces on the perimeter of body `body`, whose ends are at the current `x` and `y` coordinates (in inertial space) of the body. Face 1 corresponds to the face between points 1 and 2, for example. """ function dlength(b::Union{Body,BodyList}) dx, dy = diff(b) return sqrt.(dx.^2+dy.^2) end """ dlengthmid(body::Body/BodyList) -> Vector{Float64} Compute the lengths of the faces formed between the face midpoints on the perimeter of body `body`. The indexing of these midpoint faces is consistent with that of the regular vertex points adjacent to both midpoints. Midpoint face 2 corresponds to the face between midpoints 1 and 2, for example. """ function dlengthmid(b::Union{Body,BodyList}) dx, dy = centraldiff(b) return sqrt.(dx.^2+dy.^2) end """ normal(body::Body/BodyList) -> Tuple{Vector{Float64},Vector{Float64}} Compute the current normals (in inertial components) of the faces on the perimeter of body `body`, whose ends are at the current `x` and `y` coordinates (in inertial space) of the body. Face 1 corresponds to the face between points 1 and 2, for example. """ function normal(b::Union{Body,BodyList}) dx, dy = diff(b) ds = dlength(b) return -dy./ds, dx./ds end """ normalmid(body::Body/BodyList) -> Tuple{Vector{Float64},Vector{Float64}} Compute the current normals (in inertial components) of the faces formed between midpoints on the perimeter of body `body` (or each body in list `body`). """ function normalmid(b::Union{Body,BodyList}) dx, dy = centraldiff(b) ds = dlengthmid(b) return -dy./ds, dx./ds end include("bodies/shapes.jl") end
r=0.69 https://sandbox.dams.library.ucdavis.edu/fcrepo/rest/collection/sherry-lehmann/catalogs/d7vc79/media/images/d7vc79-008/svc:tesseract/full/full/0.69/default.jpg Accept:application/hocr+xml
{-# OPTIONS --cubical --safe #-} module Data.Binary where open import Data.Binary.Definition public using (𝔹; 0ᵇ; 1ᵇ_; 2ᵇ_) open import Data.Binary.Conversion public using (⟦_⇑⟧; ⟦_⇓⟧) open import Data.Binary.Addition public using (_+_) open import Data.Binary.Multiplication public using (_*_) open import Data.Binary.Subtraction public using (_-_) open import Data.Binary.Isomorphism public using (𝔹⇔ℕ) open import Data.Binary.Increment public using (inc)
Formal statement is: lemma isCont_def: "isCont f a \<longleftrightarrow> f \<midarrow>a\<rightarrow> f a" Informal statement is: A function $f$ is continuous at $a$ if and only if $f$ has a limit at $a$.
\documentclass[12pt]{article} \linespread{1.5} \setlength\parindent{1cm} \usepackage[margin=1in]{geometry} \usepackage{amsmath, amssymb, amsthm} \usepackage{graphicx} \usepackage{titling} \usepackage{hyperref} \newcommand{\subtitle}[1]{% \posttitle{% \par\end{center} \begin{center}\Large#1\end{center} \vskip0.5em}% } \begin{document} \title{Evaluating the Impact of Community Development on Typhoon Resilience: Evidence from the Philippines} \author{Justin Abraham \\ Advisor: Solomon M. Hsiang \textsuperscript{1}} \date{\today} \maketitle \begin{abstract} The overwhelming majority of natural disaster victims reside in developing countries, where the human and material losses due to disasters are exacerbated by geography, economic situation, and lack of appropriate policy interventions. The aim of this paper is to analyze the effect of institutional quality on losses due to natural disasters. This study uses a household level panel survey from a community development program in the Philippines combined with data on regional typhoon intensity to retrospectively estimate the impact of institutional reform on natural disaster resilience. The project employs a randomized evaluation strategy to identify the causal effect of more inclusive institutions on sensitivity to natural disasters and aggregate shocks in general. I find that while exposure to more intense typhoon events negatively impacts economic activity, access to public services, and collective capacity, KALAHI-CIDSS does not significantly alter household storm resilience except on indicators of employment and participation in collective activities. \end{abstract} \footnotetext[1]{I would like to thank my advisor, Solomon M. Hsiang, for contributing his work on reconstructed cyclone data and for his invaluable guidance in the writing of this thesis. I would also like to acknowledge Julien Labonne for aiding in the understanding and use of the KALAHI-CIDSS Living Condition Survey.} \newpage \section{Introduction} \paragraph{ } Poorer countries suffer disproportionately from natural disasters. Not only do developing countries face more frequent and more intense disaster incidence, but the material and human marginal costs associated with each event are more acute for those living in a development setting. The overwhelming majority of disaster victims reside in developing countries; 99 percent of the people affected by natural disasters over the period 1970-2008 were in the Asia-Pacific region, Latin America and the Caribbean, or Africa (Cavallo and Noy 2011). Some studies have attributed the differences of disaster impact to underinvestment in preventative and adaptive interventions due to fewer available resources. Indeed, the existence of specific rules and policies such as land-use planning, building codes, and engineering solutions are the exception in less developed countries (Freeman et al. 2003; Jamarillo 2009). However, another line of research provides evidence that differences in institutional quality play a significant role in determining the extent of disaster loss (Kahn 2005; Skidmore and Toya 2007; Raschky 2008; Strömberg 2007). Studies that have focused on the larger effect of institutional quality on development cite the importance of inclusion, accountability, and tranparency of political institutions in spurring economic growth (Engerman and Sokoloff 1997; Acemoglu, Johnson, and Robinson 2001; Banerjee and Iyer 2002). Institutional quality may be further linked with disaster resilience, the ability to withstand to natural disasters. On the national level, better institutions may translate to more effective disbursion of aid funds, quicker mobilization of emergency reponses, and a smoother uptake of adaptive policies. Better local institutions could empower communities to implement adaptive policies suited to local needs, include marginalized groups in disaster preparedness, and hasten the organization of post-disaster recovery (Arnold et al. 2014). In an effort to better understand the link between local institutional quality and community response to natural disasters, this paper evaluates the impact of the Kapit-Bisig Laban sa Kahirapan - Comprehensive Integrated Delivery of Social Service (KALAHI-CIDSS), a community driven development intervention in the Philippines, on household sensitivity to tropical cyclones. This study utilizes a panel dataset of 2092 households collected from a randomized controlled trial of KALAHI-CIDSS combined with reconstructed data on regional tropical cyclone exposure to test three general hypotheses that represent different dimensions of cyclone risk. The array of outcome variables to be tested are similar to those tested in an earlier KALAHI-CIDSS impact evaluation (Labonne 2013). The paper uses a fixed effects model to obtain an unbiased average treatment effect of intensity of storm exposure, participation in KALAHI-CIDSS, and the interaction between the treatment and storm exposure, which is measured by maximum wind speed. \begin{center} \begin{flushleft} $H_A$: Participation in KALAHI-CIDSS mitigates negative welfare shocks due to typhoons $H_B$: Participation in KALAHI-CIDSS strengthens post-disaster access to public services $H_C$: Gains in collective capacity due to KALAHI-CIDSS are robust to typhoon events \end{flushleft} \end{center} Because multiple outcomes related to these hypotheses are available in the data, I submitted a pre-analysis plan as a safeguard against data mining and selective presentation of empirical results. The plan outlines the research question, a description of the data and variables to be used, the identification strategy, and the hypotheses. The pre-analysis plan was archived by the Registry for International Development Impact Evaluations\footnote{\url{http://ridie.3ieimpact.org/index.php?r=search/detailView&id=179}} on April 2014, before analyzing the key data sources. Results show that more intense tropical cyclone events have an adverse effect on economic activity, access to public services, and collective capacity. In terms of economic activity and welfare, more extreme storm episodes are associated with lower per capita food expenditures, reduced agricultural activity, and higher likelihood of being sick. With respect to public services, access to water, electricity, health services, and schools suffer with greater storm exposure. Some measures of collective capacity have a significant negative correlation with storm intensity. Participation in a bayanihan community activity and levels of trust among community members suffer with greater cyclone exposure. Overall, this study finds no significant impacts of the KALAHI-CIDSS program to household and individual resilience to tropical cyclones. Out of the 20 outcomes tested, only two resulted in statistically significant estimates for the interaction between the intervention and storm intensity. The reduction in participation in bayanihan community activities due to tropical cyclones can be attenuated between 70-90 percent by KALAHI-CIDSS, suggesting an important role of community driven development in preserving collective capacity through aggregate shocks. The effect of cyclone exposure on employment is magnified by the intervention to a level approximately double than that of the impact of storms without the intervention. This study extends previous research on institutional quality and natural disasters in three ways ways. First, the randomization of the treatment assignment can be interpreted as an exogenous shift in institutional quality, allowing the recovery of a causal effect of better institutions on disaster resilience. Second, the study examines household responses to tropical cyclones, complementing country level research and contributing to ongoing efforts to understand the impact of storms on a local level. Third, the study estimates the effect of tropical cyclone exposure on local collective capacity using a unique set of indicators regarding trust and civic participation. % Poor countries suffer disproportionately from natural disasters % The Intergovernmental Panel on Climate Change reports that 65 percent of world deaths from natural disasters between 1985 and 1999 took place in nations whose incomes were below USD 760 per-capita (IPCC 2001).2 % Direct and indirect costs % Lower incomes may mean that they just cannot afford to protect themselves (Cavallo and Noy) % Intuitively, the way in which a society organizes itself against disaster shocks should be important as well fixing income % Argument that institutional quality is a key determinant of economic performance (Engerman and Sokoloff 1997; Acemoglu, Johnson, and Robinson 2001; Banerjee and Iyer 2005) % In the way that AJR describes focus on inclusion, accountability, and transparency % Intuition and some evidence that it might also decreases vulnerability % whereas resilience is the ability to withstand aggregate shocks like natural disasters % Distinction: not just existence of certain policy measures but the nature of political participation and civic involvement % getting at this notion of `social capital' % Explain how this might be applied to natural disasters % National: better channel aid funds, mobilize emergency response, facilitate adaptation (Hsiang) % Local: bottom-up approaches better suited, diversification of activities, participatory scenario based planning for marg com % World Bank: % Support bottom-up approaches that make use of social networks and support autono- mous adaptation based on the lived experience of poor communities % Support communities to increase diversity and fallback options (e.g., diversification of liveli- hoods into activities less sensitive to climate-related or other forms of risk, such as through voluntary migration) % Enhance social learning and sound governance as a form of regulatory feedback (e.g., build- ing capacity in participatory approaches to scenario-based planning or measures to increase social accountability in the use of public finance for climate change response) (Hsiang adaptation) % Understand the gender dimensions of climate change and empower women as resilience champions. % Why is the research important? % CDDs that improve post-disaster response can represent a possible pre-disaster mitigation intervention on its own right % The aim of this study is two-fold: % *Do better institutions mitigate losses from natural disaster shocks? % *Do CDD interventions strengthen resilience against natural disasters? % Using KALAHI and LICRICE to look at the interaction between typhoon response and community driven development % Hypotheses % $H_A$: Participation in KALAHI mitigates negative welfare shocks due to typhoons % $H_B$: Participation in KALAHI strengthens post-disaster access to public services % $H_C$: Gains in social capital due to KALAHI are robust to typhoon events % Pre-analysis plan % why it is important % what it involved % What is the contribution to the literature? % only randomization achieves causal identification % one of the first studies to focus on the importance of local institutions against agg shocks % Results and brief conclusion % \section{Literature Review} % key definitions: CDD, social capital, aggregate shock, natural disasters as a human phenomenon % What is community driven development? % It is important to note that institutional quality as discussed here refers to the overall structure of political institutions and civic life as distinct from the existence of specific policy measures. % getting at this notion of `social capital' % How have CDDs been used in developing communities? % Casey % What is the impact of CDD on communities? % Casey % Effects on welfare and social capital % Labonne % How do we characterize the effect of disasters on developing communities? % aggregate shock vs idiosyncratic shock % Particularly tropical cyclones in such areas (Cavallo and Noy) % mostly country level gdp % micro Rodriguez-Oreggia et al. (2009) and Mechler (2009) % Short term and long term costs (human and material) of natural disasters (Antilla,Hsiang, etc.) % we dont really understand, most are just macro studies % What is the relationship between institutions and disaster loss? % Hsiang adaptation % Kahn 2005; Skidmore and Toya 2007; Raschky 2008; Strömberg 2007), more % CDDs that improve post-disaster response can represent a possible pre-disaster mitigation intervention on its own right % What is the study opportunity? % rarity in exogenous variation in institutional structure % difficulty in measuring institutional quality % difficulty in measuring social capital % What is the contribution to the literature? think about this more % only randomization achieves causal identification % one of the first studies to focus on the importance of local institutions against agg shocks \section{Context and Intervention} \subsection{Institutional reform and KALAHI-CIDSS} \paragraph{ } Initiated in January 2003 by the Department of Social Welfare and Development, KALAHI-CIDSS followed the community driven development approach to strengthen community participation in village governance and to develop local capacity to design, implement and manage development activities. The intervention was developed to complement local poverty reduction efforts beginning with institutional reform in 1991 that shifted more responsibility to village administrative units, or barangays. KALAHI-CIDSS targeted the 25 percent poorest municipalities in 42 of the poorest provinces and distributed approximately USD 7,400 to each barangay in the municipality to support local subprojects. The government of the Philippines initially committed USD 82 million to the project, complemented by a USD 100 million loan from the World Bank. KALAHI-CIDSS is consistent with community driven development practices. In each participating municipality, barangays implemented the program according to a `Community Empowerment Actvity Cycle' that involved a social preparation stage and a project funding stage. Community memmbers in the social preparation stage had to proritize local needs and were trained to design and deliver subproject proposals. Additionally, an Area Coordination Team deployed by KALAHI-CIDSS worked with community facilitators to ensure adequate and meaningful participation. Representantives in the Municipal Inter-Barangay forum then selected which proposals would continue on to the funding stage using a set of criteria they themselves developed. Villagers elected the members of the subproject management committee which are responsible for subproject implementation and monitoring. Throughout this process, community volunteers were wholly responsible for the procurement of subproject inputs and were required to contribute in-kind or cash to the subproject. Each municipality repeated the cycle three times, so barangays could receive funding for up to three subprojects. While most barangays in participating municipalities complete the social preparation stage, only a few actually succeeded in getting their proposal funded. This paper focuses on the period from 2003 to 2010, after which the intervention had been implemented in 184 municipalities. As of December 2010, KALAHI had supported 5,645 subprojects most of which involved the construction or improvement of roads, water systems, school buildings, health stations, and agricultural facilities. The project is currently being expanded through a USD 120 million grant from the Millennium Challenge Corporation and a USD 59 million loan from the World Bank. Future implentations of KALAHI-CIDSS will focus on areas hit by tropical cyclone in order to strengthen ``access to services and infrastructure for communities in affected provinces and their participation in more inclusive local disaster risk reduction and management planning, budgeting, and implementation'' (Asian Development Bank). %timeline of KALAHI-CIDSS rollout \subsection{Tropical cyclones in the Philippines} \paragraph{ } An average of ten typhoons of mild to severe intensity make landfall in the Philippines each year, making it one of the busiest regions in terms of cyclone activity in the world. The area of the Philippines is larger than the typical span of tropical cyclones, so different parts of the country can receive varying degrees of exposure in a given year. The island groups of Luzon in the north and Visayas in the east are the most frequently impacted regions in the country. See Fig. 1 for a summary of geographic exposure to cyclones. At least 30 percent of the annual rainfall in these regions are traced to tropical cyclones, while the southern islands receive less than 10 percent of their annual rainfall from tropical cyclones (Rodgers et al.). Typhoon Haiyan recently made landfall in eastern Visaya in November 2013, attaining a 10-minute sustained maximum windspeed of 230 km/h that makes it one of the strongest tropical cyclones ever recorded. The typhoon cut a path through central Philippines, causing USD 809 million worth of damage and leaving behind a death toll of over 6,000. %why it's good for research %fig - Storm intensity maps of the Philippines \section{Data} \subsection{KALAHI-CIDSS Living Condition Survey} \paragraph{ } The World Bank designed a rigorous impact evaluation to estimate the effects of KALAHI-CIDSS on poverty reduction, governance, and social capital (Labonne and Chase 2009; Labonne and Chase 2011; Labonne 2013). A survey team collected quantitative panel data over three rounds throughout the project implementation in a sample of KALAHI-CIDSS treatment municipalities and comparable control municipalities to compile the KALAHI-CIDSS Living Condition Survey. The survey was fielded in Albay, Capiz, Zamboanga del Sur and Agusan del Sur provinces, selected to represent the major island groups of the Philippines (see Fig. 2). These provinces were part of Phase III of project expansion that launched in 2005. Treatment was assigned randomly to two out of the four municipalities in each province using the `tambiolo' random process and household survey respondents from each barangay were chosen by multi-stage stratified random sampling. All in all, the quantitative sample includes 2,400 households in 135 barangays in 16 municipalities in 4 provinces. Labonne and Chase (2011) ran difference of means tests on each of the two study groups and reported that the treatment and comparison are well balanced across a host of covariates. See Table 1 and 2 for descriptive summaries for each group. The quantitative baseline survey was carried out in September-October 2003, the quantitative midterm - in October-November 2006 and the quantitative endline survey - in February-March 2010. Barangays in treatment municipalities entered the social preparation stage in October 2004, between the baseline and midline surveys. The endline survey collection ocurred a little over a year after the end of the project activities. Between 2003 and 2010, the survey was fielded to the same 135 villages with a household attrition of 21 percent for the treatment and 22 percent for the control group. The sample size was reduced from 2,400 households during the baseline survey to a little less than 1,900 households during the endline survey, mostly due to migration and deaths. One of the original control municipalities in Albay (Malinao) ended up being included in the PODER project, a KALAHI-CIDSS type program supported by a Spanish aid agency. As a result, baseline data had to be collected in a replacement control municipality (Oas). It is possible that if attrition among respondents varies with some outcome, then the estimate of the treatment effect on that outcome will be biased. To determine random attrition, Labonne (2013) runs a probit regression of the indicator for dropping out between 2003 and 2010 on the interaction of the outcome of interest with the treatment dummy, its interaction with the control dummy, the treatment dummy and a full set of province dummies. Nonsignificant coefficients reported in Table 3 for each of the outcomes suggest that attrition is unlikely to bias the primary estimates. While all barangays in the treatment completed the social preparation stage, only about a third of these received funding for at least one subproject as determined by the Municipal Inter-Barangay Forum. A barangay's ability to propose a successful project can be dependent on existing degrees of collective capacity, so it is an endogenous independent variable (Labonne and Chase 2011). Hence, this analysis takes October 2004, the beginning of the social preparation stage, as the treatment date for KALAHI-CIDSS to preserve exogeneity of the explanatory variable. We can then understand the coefficient estimate on the treatment to be the overall average treatment effect of the program rather than an effect due to social preparation or subproject completion alone. See Fig. 3-6 for the distribution of start and end dates of subproject implementation for each province. The survey instrument includes information on household and village characteristics, proximity to health stations and schools, road usage, participation in local governance, labor force participation, health, education, and consumption. Each variable to be analyzed from the Living Conditions Survey is categorized under one of the three hypotheses below. Outcomes are measured on the household level unless otherwise noted. Expenditure is observed in USD and is analyzed with a log transformation. Employment is observed as an indicator or whether an individual has had a job in the past six months. The interpretation for school enrollment and disease incidence is similar. The variable on agricultural activity indicates whether the household participated in crop farming, fishing, or raising livestock. Variables regarding access to public services indicates whether respondents believe they have better access than during the previous survey round. I include a variable indicating participation in a bayanihan, a type community activity, as one measure for collective capacity. Levels of trust are categorical variables represented by integers whose ordering is proportional to level of trust. \paragraph{$H_A$: Participation in KALAHI-CIDSS mitigates negative welfare shocks due to typhoons} \begin{enumerate} \item Consumption in log per capita expenditures (LNPCEXP) \item Consumption in log per capita expenditures for poor households (LNPCEXP) \item Food consumption in log per capita expenditures (LNPCFOOD) \item Non-food consumption in log per capita expenditures (LNPCNONFOO) \item Employment (individual level) (JOB) \item Engaging in crop farming, fishing, or raising livestock (AGR) \item Contracted a disease in the past 6 months (individual level) (SICK) \end{enumerate} \paragraph{$H_B$: Participation in KALAHI-CIDSS strengthens post-disaster access to public services} \begin{enumerate} \item Better access to potable water (WATER) \item Better access to electricity (ELECTR) \item Better access to health services (HEALTH) \item Better access to schools (SCHOOL) \item Current school enrollment (individual level) (ENROLL) \item Log per capita expenditures on transportation (LNTREXP) \end{enumerate} \paragraph{$H_C$: Gains in social capital due to KALAHI-CIDSS are robust to typhoon events} \begin{enumerate} \item Participation in a collective action activity (BAYANIHAN) \item Willingness to contribute time/money to a public project (GIVE-TIME, GIVE-CASH) \item Level of trust among community members (COM-TRUST) \item Level of trust in the local government (LOC-TRUST) \item Level of trust in the national government (NAT-TRUST) \item Attendance in a Barangay Assembly in the past 6 months (ASSEMBLY) \item Number of times attended a village assembly (ATTEND-F, ATTEND-M) \item Intent to vote in upcoming elections (VOTE) \end{enumerate} %map of provinces %schedule of Phase III program %table of probit attrition %distribution of subproject dates %descriptive statistics %balance: descriptive statistics for each study group \subsection{Limited Information Cyclone Reconstruction and Integration for Climate and Economics} \paragraph{ } This paper will utilize the KALAHI-CIDSS Living Conditions Survey with data on regional typhoon intensities to evaluate the impact of KALAHI on community disaster resilience. Information on typhoon exposure is generated by reconstructing tropical cyclone incidence using the Limited Information Cyclone Reconstruction and Integration for Climate and Economics (LICRICE) Model (Hsiang 2010; Hsiang and Narita 2012; Anttila-Hughes and Hsiang 2013). The model reconstructs wind field histories for tropical cyclone events passing through the region using non-satellite meteorological observations from the International Best Track Archive for Climate Stewardship. This study uses the maximum wind speed (m/s) achieved by a tropical cylone in a given year as a measure of cyclone intensity. Maximum wind speeds are aggregated and spatially averaged to obtain province-by-year observations from 1950 to 2012. If a province experiences multiple cyclones, the reported observation is the maximum of the maximum speed achieve in each storm. Maximum wind speed is a suitable measure of cyclone intensity for the context of this study becuse physical capital in a storm may fail at some critical level of stress, rather than in proportion with storm exposure (Nordhaus 2010). The reporting of the maximum observation, however, leaves maximum wind speed unchanged if provinces experience multiple identical storms in the same year. Furthermore, LICRICE only reconstructs wind fields and does not explicitly account for rains, flooding, or storm surges, possibly understating the true damage wrought by tropical cyclones. Fig. 7-8 presents a time series plot of annual maximum wind speeds disaggregated by provinces in the randomized evaluation. \section{Identification} \paragraph{ } A general framework for testing the effect of KALAHI on typhoon response that utilizes the panel structure of the data is to regress the outcomes of interest on a treatment indicator, a measure of typhoon exposure, and controls for cross-sectional and time-dependent covariates using the following fixed effects model. \[Y_{ihmt} = \alpha K_{ihmt} + \beta X_{ihmt} + u_{m} + v_{t} + \epsilon_{ihmt}\] $Y_{ihmt}$ is the outcome of interest observed for a single individual in a specific year. For outcomes observed at the household level, the regressand is $Y_{hmt}$. When $Y$ is an indicator, the regression fits a linear probability model. $K_{ihmt}$ is a binary variable indicating whether a municipality at year $t$ underwent the social preparation stage of the program. $X_{ihmt}$ is a province-specific measure of typhoon exposure by maximum wind speed. $u_{h}$ represents household level fixed effects and $v_{t}$ represents year fixed effects. I will also compare models that include a linear time trend instead of year fixed effects. $\epsilon_{ihmt}$ is the idiosyncratic error term. A fixed effects model can control for unobserved heterogeneity among households that could possibly be correlated with the explanatory variables. Since treatment was randomly assigned, it is necessary only to discuss correlation with maximum wind speed $X_{ihmt}$. There is evidence that environmental disasters play some part in shaping migration patterns so propensity for mobility may be linked to previous exposure to tropical cyclones (Boustan et al. 2012; Drabo and Mbaye 2011; Gray and Mueller 2011). If characteristics determining mobility are time invariant, then the within transformation of the fixed effects model will remove that source of heterogeneity. A key identifying assumption in this empirical model is that without the program, the two groups of municipalities would have evolved similarly over time. If this parallel trends hypothesis holds, then it is possible to recover the average treatment effect on the treated despite not being able to directly observe the counterfactual (Bertrand et al. 2004). Labonne (2013) compares muncipalities in the study groups using the Family Income and Expenditure Survey from 2000 to 2003, just before the treatment began. They find no significant differences between the treatment and comparison municipalities, which provides some justification to accept parallel trends. This fixed effects estimator will additionally estimate clustered standard errors to control for inter-cluster correlations of the error terms that could skew the resulting standard errors (Bertrand et al. 2003; Cameron and Miller 2013). Given that the program was implemented at the municipality level and that there could be intertemporal correlation, clustering by municipality seems ideal. Including a linear time trend and year fixed effects controls for overall correlation between different years, but not for province-specific correlation of errors. To estimate the effect of the community driven development program on household response to tropical cyclones, I include an interaction term between yearly maximum wind speed and the treatment indicator. The primary estimand is the cross partial $\gamma$ coefficient on the interaction term. The value of $\gamma$ should expose the differential impact of typhoon exposure that depends on treatment assignment. If $\beta$ and $\gamma$ take on opposite signs, then participating in KALAHI-CIDSS mitigates the impact of typhoon exposure. On the other hand, if $\beta$ and $\gamma$ take on the same sign, then participating in KALAHI-CIDSS exacerbates the impact of typhoon exposure. \[Y_{ihmt} = \alpha K_{ihmt} + \beta X_{ihmt} + \gamma K_{ihmt} X_{ihmt} + u_{m} + v_{t} + \epsilon_{ihmt}\] \[\frac{\partial Y}{\partial X} = \beta + \gamma K_{it} \hspace{1 in} \frac{\partial^2 Y}{\partial X \partial K} = \gamma\] In addition to contemporaneous typhoon incidence, a history of typhoon exposure may have a lagged impact on the dependent variables. To estimate these effects, the paper examines a finite distributed lag model over treatment assignment and typhoon exposure. In this model, I lag typhoon exposure with length $l$ determined by the Akaike information criterion. $\beta_{0\tau}$ represents the level effect of typhoon intensity experienced at year $t - \tau$. \[Y_{ihmt} = \alpha K_{ihmt} + \sum_{\tau = 0}^{l} \left[\beta_{0\tau} X_{ihmt - \tau} + \gamma_{0\tau} K_{ihmt} X_{ihmt - \tau} \right] + u_{h} + v_{t} + \epsilon_{ihmt}\] \section{Results and Discussion} \paragraph{ } Results for each outcome are presented by hypotheses in this section. This study focuses on the extended finite distributed lag model with a linear time trend and errors clustered at the municipality level (Column 6 of each regression table) as the primary regression specification but variants are presented for comparison. Note that this is the specification reported by Labonne (2013) in the previous KALAHI-CIDSS impact evaluation so it is possible to compare estimates as a check for robustness. Overall, I was unable to identify a significant relationship between the interaction of participation in KALAHI-CIDSS and tropical cyclone exposure and almost all outcome variables. However, I find evidence of a significant negative contemporaneous and lagged effect of cyclone intensity on economic activity and interestingly, indicators of social capital. Results show that KALAHI-CIDSS had a positive impact on economic activity, access to services, and measures of social capital, which are consistent with the findings in Labonne (2013). % multicoll % small amout of clusters % province specific trends % estimating lpm % gender dynamics % should have had more measures: income, health, spending patterns, vote, aid, housing \subsection{Impact on welfare and economic activity} \paragraph{ } This first hypothesis focuses on outcomes related to economic activity and human welfare. Treatment estimates for KALAHI-CIDSS are consistent with those found by Labonne (2013) and significant estimates for maximum windspeed vary with each outcome. Generally, I am unable to find evidence of a significant correlation between the interaction of KALAHI-CIDSS and cyclone intensity with all outcomes except for employment. Examining the estimates for total log per capita expenditures, year fixed effects and the linear year term were found to be significant at the 5 percent level and that including them in the fixed effects model increases $R^2$ from 0.36 to about 0.43. These results provide good evidence for accepting the regression specification estimating expenditures. The coefficient estimate of KALAHI-CIDSS on log per capita expenditures are nearly identical to Labonne (2013) at 0.113, but the inclusion of lagged maximum wind speed renders the effect insignificant. Examining log per capita expenditures for poor households, the coefficient on the intervention is significant at 0.151 with no significant correlation with maximum wind speed. Moreover, there is no significant correlation between the interaction and log per capita expenditures for either subsample. Focusing on log per capita expenditures is problematic because the relationship between cyclone exposure and overall expenditures is not intuitively obvious. For instance, more intense storms can boost spending on home repairs, but its effect can be attenuated by income losses. This suggests that it might be more informative to examine expenditure categories. Interpreting the relationship between log per capita food expenditures and storm exposure is more straightforward. It is reasonable to hypothesize that cyclones affect food spending mainly through purchasing ability. Just as in Labonne (2013), I find no significant effect of the intervention on log per capita food expenditures. A one unit increase in lagged maximum wind speed is significantly associated with a 1.5 percent reduction in food spending in Column 5 and a 0.7 percent reduction in Column 6. While there is no significant relationship with the interaction terms, the coefficient estimate on the one period lagged interaction is positive and is half the magnitude of the coefficient on lagged wind speed for both Column 5 and 6. While the estimate is noisy, this suggests that the intervention may attenuate shocks to food spending by about 50 percent. In contrast, log per capita non-food expenditures encompasses a large range of spending categories and including cyclone exposure in the regression increases standard errors around the coefficient on the intervention. The coefficient on lagged wind speed is estimated to be 0.025 which could be driven by spending on repairs or medical services (Anttila-Hughes and Hsiang 2013). In order to find a clear relationship between spending and cyclone exposure it is necessary to examine more detailed information about spending categories. According to the results, the fixed effects estimates of employment, including the interaction term, are found to be statistically significant in almost all specifications. The regression in Column 6 predicts that individuals in the intervention at 9 percent more likely to be employed, significant at the 5 percent level. For both models in Column 5 and 6, the estimates on contemporaneous wind speed is significant at the 1 percent level and predicts a 1 percent increase in likelihood of employment associated with a one unit increase wind speed. It is possible to understand this correlation as a case of ``investment-producing destruction'' that increases demand for labor after the destruction of physical capital (Noy and Vu 2010). In the regression with year fixed effects, the estimates on lagged wind speed are negative and have values of approximately 1 percent. See Fig. 9 for a plot of the lag distribution. The primary estimator, the coefficient on the interaction terms, is statistically significant at the 5 percent level for the model with year fixed effects and at the 1 percent level for the model with the linear time trend. It is interesting to note that the sign on the interaction coefficients are the same as their corresponding coefficients on wind speed, suggesting that the intervention actually exaggerates the effects of cyclone exposure on likelihood of being employed. Furthermore, the size of the coefficients on wind speed and the size of the interaction coefficients are nearly one-to-one, suggesting that the intervention approximately doubles the effect of tropical cyclone intensity on employment. In terms of agricultural activity there is no significant relationship with the intervention or the interaction terms. However, both Column 5 and 6 specifications yield similar estimates at a statistically significant level. A one unit increase in one year lagged wind speed is associated with a 1 percent lower probability of fishing, farming, or raising livestock. This effect is halved at 0.4 percent for the two year lag. These estimates are statistically significant but interpretation of the linear probability model makes determining economic significance difficult. Results show a significant relationship between lagged wind speed and whether an individual was sick within the past six months. These results are consistent with evidence of a delayed health burden in post-disaster scenarios (Anttila-Hughes and Hsiang 2013). I find no significant effect of the treatment or the interaction with this outcome. \subsection{Impact on post-disaster access to services} \paragraph{ } This second hypothesis explores the effect of KALAHI-CIDSS and storm intensity on transportation consumption and access to public services like electricity, water, healthcare, and schooling. The results show no significant relationship between access to services and the interaction terms. The level effect of KALAHI-CIDSS is insignificant with regards to public services, which mirrors the results in Labonne (2013). Households exposed to higher wind speeds lagged at one year are less likely to believe they have better access to water, health services, and electricity than during the previous survey round. Notably, the impact of storm intensity on access to health services may have a role in exacerbating the health cost of tropical cyclones since likelihood of becoming sick also increases with storm intensity. As in Labonne (2013), individuals residing in treatment municipalities are less likely to be enrolled in school. This estimate predicts a 7 percent reduction in enrollment propensity at a significance level of 1 percent. Column 6 reports a coefficient of -0.0036 for lagged wind speed and 0.005 for contemporaneous wind speed, both significant at 5 percent. The positive effect on contemporaneous wind speed may be an artifact of the data. This study takes observations annually, but most of the typhoon activity in the Philppines occurs between July and October while the academic calendar for that year ends in March (Ribera et al. 2004). Recording enrollment near the end of the academic year means that the measure will likely be affected by storms from the previous year, which is what the estimates illustrate. Unsurprisingly, the estimates for access to school are similar to the enrollment indicator. The intervention has no significant effect and a one unit increase in lagged wind speed reduces by 1 percent the likelihood that respondents believe they have better access to schools. The interaction term is insignificant for both outcomes. \subsection{Impact on social capital in disaster contexts} \paragraph{ } The third hypothesis means to explore the relationship between exposure to tropical cyclones and levels of social capital or collective capacity within a community. Overall, there is no significant relationship between KALAHI-CIDSS and the robustness of social capital to tropical cyclone events except with respect to participation in a bayanihan. The level effects of the treatment are mixed among the different outcomes in accordance with results in Labonne (2013). Note that because responses to VOTE were only collected in the 2010 endline survey, it was impossible to examine with the current research design. The results demonstrate no significant impact of the intervention on willingness to give time or money to a public project and participation in a bayanihan collective activity. In the specification with year fixed effects, there is a significant negative impact of storm intensity on participation in a bayanihan that diminishes with increasing lag distance. The coefficient estimate for the one year lag is -0.037 and -0.02 for the two year lag. These correspond to a 3.7 percent and a 2 percent decrease in the likelihood of participating in a bayanihan. See Fig. 10 for a plot of the lag distribution. In the same specifiction, the interaction of the treatment with the first two wind speed lags is positive significant at the 10 percent level, suggesting an attenuating effect of KALAHI-CIDSS on reductions in participation due to tropical cyclones. Calculating the ratio of the level effect over the interaction effect produces an attenuation rate of 70 percent for the one year lag and 90 percent for the two year lag. For outcomes measuring levels of trust, the interaction terms have no significant impact. Treatment is insignificant in determining levels of trust in the local and national government, but Column 6 and 5 report a significant coefficients of 0.199 and 0.275 on the treatment for level of trust among community members. In the specification with a linear time trend, one year lagged wind speed has a significant negative effect in community trust at -0.022, which is 10 percent of the magnitude of the coefficient on the intervention. The same estimate of -0.022 for lagged wind speed is produced for trust in local government. The coefficients on the interaction terms are insignificant for all measures of participation in Barangay Assemblies. The model predicts about a 0.10 increase in visits to assmebly meetings for males in treatment municipalities and about a 0.8 increase for females in treatment municipalities. There is no clear relationship between maximum wind speed and participation in assemblies. \section{Conclusion} \paragraph{ } Using a randomized evaluation design, this paper evaluates the impact of the KALAHI-CIDSS community driven development program on household resilience to tropical cyclones. While the intervention had a positive effect on economic activity, access to public services, and levels of social capital, it only impacts the typhoon response in 2 out of the 20 outcomes tested. Though its precise effect on multiple dimensions of social welfare remain unclear, the results demonstrate how insitutional quality may be an important determinant of household storm sensitivity. The intervention approximately doubles the effect of tropical cyclone intensity on employment. Focusing on social capital, the intervention mitigates the negative effects of typhoons on participation in collective activities by 70 to 90 percent. The study additionally finds significant negative effects of tropical cyclone intensity on nearly all outcomes studies, including social capital. This result suggests that current understanding of loss due to natural disasters may be incomplete without taking into consideration the effect of disasters on social dynamics. One policy implication is the opportunity for disaster interventions that conventionally focused on health and economic losses to now address post-disaster community relationships. From here there is an abundance of opportunity to further study the relationship between community driven development and natural disasters. The analysis conducted here is a general impact evaluation of KALAHI-CIDSS on multiple dimensions of household life. It is possible derive greater understanding of the causal effects of community driven developments by performing additional tests on each specific outcome of interest. This study analyzes the overall treatment effect of community driven development, but it could be fruitful to examine the long-term and short-term impact since the benefits of institutional reform may take varying durations to fully materialize. The evaluation design limited this analysis to the study of the social preparation component of KALAHI-CIDSS. Further investigation is required as to the difference in the treatment effect due to the social training and the treatment effect due to completion of a community subproject. % how many significant outcomes % multicollinearity with the finite distributed lag model % unstable estimates when doing robustness checks % either polynomial distributed lag or removing extra lagged regressors % reported one-way mun cluster % skew up SE estimates because few clusters % province specific time trends skew it down % how do we interpret these results % implications for policy % improvements % multicollinearity of lags % not enough clusters % within province variation of hurricanes is low % further investigations % long term short term impact of kalahi % distinguish between hardware and software effects % causal mechanisms \end{document}
State Before: R : Type u_1 V : Type u_2 V' : Type ?u.292206 P : Type u_3 P' : Type ?u.292212 inst✝⁷ : OrderedRing R inst✝⁶ : AddCommGroup V inst✝⁵ : Module R V inst✝⁴ : AddTorsor V P inst✝³ : AddCommGroup V' inst✝² : Module R V' inst✝¹ : AddTorsor V' P' inst✝ : NoZeroSMulDivisors R V w x y z : P h₁ : Wbtw R w x z h₂ : Sbtw R x y z ⊢ Sbtw R w y z State After: R : Type u_1 V : Type u_2 V' : Type ?u.292206 P : Type u_3 P' : Type ?u.292212 inst✝⁷ : OrderedRing R inst✝⁶ : AddCommGroup V inst✝⁵ : Module R V inst✝⁴ : AddTorsor V P inst✝³ : AddCommGroup V' inst✝² : Module R V' inst✝¹ : AddTorsor V' P' inst✝ : NoZeroSMulDivisors R V w x y z : P h₁ : Wbtw R z x w h₂ : Sbtw R x y z ⊢ Sbtw R w y z Tactic: rw [wbtw_comm] at * State Before: R : Type u_1 V : Type u_2 V' : Type ?u.292206 P : Type u_3 P' : Type ?u.292212 inst✝⁷ : OrderedRing R inst✝⁶ : AddCommGroup V inst✝⁵ : Module R V inst✝⁴ : AddTorsor V P inst✝³ : AddCommGroup V' inst✝² : Module R V' inst✝¹ : AddTorsor V' P' inst✝ : NoZeroSMulDivisors R V w x y z : P h₁ : Wbtw R z x w h₂ : Sbtw R x y z ⊢ Sbtw R w y z State After: R : Type u_1 V : Type u_2 V' : Type ?u.292206 P : Type u_3 P' : Type ?u.292212 inst✝⁷ : OrderedRing R inst✝⁶ : AddCommGroup V inst✝⁵ : Module R V inst✝⁴ : AddTorsor V P inst✝³ : AddCommGroup V' inst✝² : Module R V' inst✝¹ : AddTorsor V' P' inst✝ : NoZeroSMulDivisors R V w x y z : P h₁ : Wbtw R z x w h₂ : Sbtw R z y x ⊢ Sbtw R z y w Tactic: rw [sbtw_comm] at * State Before: R : Type u_1 V : Type u_2 V' : Type ?u.292206 P : Type u_3 P' : Type ?u.292212 inst✝⁷ : OrderedRing R inst✝⁶ : AddCommGroup V inst✝⁵ : Module R V inst✝⁴ : AddTorsor V P inst✝³ : AddCommGroup V' inst✝² : Module R V' inst✝¹ : AddTorsor V' P' inst✝ : NoZeroSMulDivisors R V w x y z : P h₁ : Wbtw R z x w h₂ : Sbtw R z y x ⊢ Sbtw R z y w State After: no goals Tactic: exact h₁.trans_sbtw_left h₂
!******************************************************************************* !> @file netcdf_inc.f !> @brief Contains module @ref netcdf_inc. ! ! Note separating the Doxygen comment block here so detailed decription is ! found in the Module not the file. ! !> Work around to fix some netcdf import problems with the Ezcdf. This module !> emulates the F77 interface using the F90 interface. !******************************************************************************* MODULE netcdf_inc USE netcdf IMPLICIT NONE !******************************************************************************* ! model module parameters !******************************************************************************* !> 32bit Real type. INTEGER, PARAMETER :: nf_real = nf90_real !> 32bit Real type. INTEGER, PARAMETER :: nf_float = nf90_float !> 64bit Real type. INTEGER, PARAMETER :: nf_double = nf90_double !> 8bit Integer type. INTEGER, PARAMETER :: nf_byte = nf90_byte !> Character type. INTEGER, PARAMETER :: nf_char = nf90_char !> 32bit Integer type. INTEGER, PARAMETER :: nf_int = nf90_int !> Maximum length of strings. INTEGER, PARAMETER :: nf_max_name = nf90_max_name !> Netcdf global . INTEGER, PARAMETER :: nf_global = nf90_global !> No error responce. INTEGER, PARAMETER :: nf_noerr = nf90_noerr !> Write flag. INTEGER, PARAMETER :: nf_write = nf90_write !> Readonly flag. INTEGER, PARAMETER :: nf_nowrite = nf90_nowrite !> Clobber flag. INTEGER, PARAMETER :: nf_clobber = nf90_clobber !> 64bit offset flag. INTEGER, PARAMETER :: nf_64bit_offset = nf90_64bit_offset !******************************************************************************* ! INTERFACE BLOCKS !******************************************************************************* !------------------------------------------------------------------------------- !> Interface to open a file. !------------------------------------------------------------------------------- INTERFACE nf_open MODULE PROCEDURE nf90_open END INTERFACE !------------------------------------------------------------------------------- !> Interface to open a file. !------------------------------------------------------------------------------- INTERFACE nf_create MODULE PROCEDURE nf90_create END INTERFACE !------------------------------------------------------------------------------- !> Interface to open a file. !------------------------------------------------------------------------------- INTERFACE nf_close MODULE PROCEDURE nf90_close END INTERFACE !------------------------------------------------------------------------------- !> Interface to inquire a dimension id. !------------------------------------------------------------------------------- INTERFACE nf_enddef MODULE PROCEDURE nf90_enddef END INTERFACE !------------------------------------------------------------------------------- !> Interface to inquire a dimension id. !------------------------------------------------------------------------------- INTERFACE nf_strerror MODULE PROCEDURE nf90_strerror END INTERFACE !------------------------------------------------------------------------------- !> Interface to inquire a dimension id. !------------------------------------------------------------------------------- INTERFACE nf_inq_dimid MODULE PROCEDURE nf90_inq_dimid END INTERFACE !------------------------------------------------------------------------------- !> Interface to define a dimension. !------------------------------------------------------------------------------- INTERFACE nf_def_dim MODULE PROCEDURE nf90_def_dim END INTERFACE !------------------------------------------------------------------------------- !> Interface to inquire a variable id. !------------------------------------------------------------------------------- INTERFACE nf_inq_varid MODULE PROCEDURE nf90_inq_varid END INTERFACE !------------------------------------------------------------------------------- !> Interface for reading integer variables. !------------------------------------------------------------------------------- INTERFACE nf_get_var_int MODULE PROCEDURE nf_get_var_int, nf_get_var_1d_int, & & nf_get_var_2d_int, nf_get_var_3d_int END INTERFACE !------------------------------------------------------------------------------- !> Interface for writing integer variables. !------------------------------------------------------------------------------- INTERFACE nf_put_var_int MODULE PROCEDURE nf_put_var_int, nf_put_var_1d_int, & & nf_put_var_2d_int, nf_put_var_3d_int END INTERFACE !------------------------------------------------------------------------------- !> Interface for writing integer variables. !------------------------------------------------------------------------------- INTERFACE nf_put_vara_int MODULE PROCEDURE nf_put_vara_int, nf_put_vara_3d_int END INTERFACE !------------------------------------------------------------------------------- !> Interface for reading real variables. Note double 2D array used by complex !> real array values. !------------------------------------------------------------------------------- INTERFACE nf_get_var_real MODULE PROCEDURE nf_get_var_cpx_real, nf_get_var_real, & & nf_get_var_1d_real, nf_get_var_1d_cpx_real, & & nf_get_var_2d_real, nf_get_var_2d_cpx_real, & & nf_get_var_2d_double, nf_get_var_3d_real, & & nf_get_var_3d_cpx_real END INTERFACE !------------------------------------------------------------------------------- !> Interface for reading real variables. Note double 2D array used by complex !> real array values. !------------------------------------------------------------------------------- INTERFACE nf_put_vara_real MODULE PROCEDURE nf_put_vara_cpx_real, nf_put_vara_real, & & nf_put_vara_2d_cpx_real, nf_put_vara_2d_real, & & nf_put_vara_3d_cpx_real, nf_put_vara_3d_real END INTERFACE !------------------------------------------------------------------------------- !> Interface for writing real variables. Note double 2D array used by complex !> real array values. !------------------------------------------------------------------------------- INTERFACE nf_put_var_real MODULE PROCEDURE nf_put_var_cpx_real, nf_put_var_real, & & nf_put_var_1d_real, nf_put_var_1d_cpx_real, & & nf_put_var_2d_real, nf_put_var_2d_cpx_real, & & nf_put_var_2d_double, nf_put_var_3d_real, & & nf_put_var_3d_cpx_real END INTERFACE !------------------------------------------------------------------------------- !> Interface for reading double variables. !------------------------------------------------------------------------------- INTERFACE nf_get_var_double MODULE PROCEDURE nf_get_var_cpx_double, nf_get_var_double, & & nf_get_var_1D_double, & & nf_get_var_1D_cpx_double, & & nf_get_var_2d_double, & & nf_get_var_2d_cpx_double, & & nf_get_var_3d_double, & & nf_get_var_3d_cpx_double END INTERFACE !------------------------------------------------------------------------------- !> Interface for reading double variables. Note double 2D array used by complex !> double array values. !------------------------------------------------------------------------------- INTERFACE nf_put_vara_double MODULE PROCEDURE nf_put_vara_cpx_double, nf_put_vara_double, & & nf_put_vara_2d_cpx_double, & & nf_put_vara_2d_double, & & nf_put_vara_3d_cpx_double, & & nf_put_vara_3d_double END INTERFACE !------------------------------------------------------------------------------- !> Interface for writing double variables. !------------------------------------------------------------------------------- INTERFACE nf_put_var_double MODULE PROCEDURE nf_put_var_cpx_double, nf_put_var_double, & & nf_put_var_1D_double, & & nf_put_var_1D_cpx_double, & & nf_put_var_2d_double, & & nf_put_var_2d_cpx_double, & & nf_put_var_3d_double, & & nf_put_var_3d_cpx_double END INTERFACE CONTAINS !******************************************************************************* ! CREATION SUBROUTINES !******************************************************************************* !------------------------------------------------------------------------------- !> @brief Define a variable. !> !> @param[in] ncid Netcdf file id. !> @param[in] name Variable id. !> @param[in] xtype Variable type. !> @param[in] ndims Number of dimensions. !> @param[in] dimids Dimension ids. !> @param[out] varid Variable id. !------------------------------------------------------------------------------- FUNCTION nf_def_var(ncid, name, xtype, ndims, dimids, varid) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_def_var INTEGER, INTENT(in) :: ncid CHARACTER (len=*), INTENT(in) :: name INTEGER, INTENT(in) :: xtype INTEGER, INTENT(in) :: ndims INTEGER, DIMENSION(:), INTENT(in) :: dimids INTEGER, INTENT(out) :: varid ! Start of executable code nf_def_var = nf90_def_var(ncid, name, xtype, & & dimids=dimids(:ndims), varid=varid) END FUNCTION !******************************************************************************* ! QUERY SUBROUTINES !******************************************************************************* !------------------------------------------------------------------------------- !> @brief Inquire a variable. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] name Variable id. !> @param[out] xtype Variable type. !> @param[out] ndims Number of dimensions. !> @param[out] dimids Dimension ids. !> @param[out] natts Number of attributes. !------------------------------------------------------------------------------- FUNCTION nf_inq_var(ncid, varid, name, xtype, ndims, dimids, & & natts) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_inq_var INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), OPTIONAL, INTENT(out) :: name INTEGER, OPTIONAL, INTENT(out) :: xtype INTEGER, OPTIONAL, INTENT(out) :: ndims INTEGER, DIMENSION(:), OPTIONAL, INTENT(out) :: dimids INTEGER, OPTIONAL, INTENT(out) :: natts ! Start of executable code nf_inq_var = nf90_inquire_variable(ncid, varid, name, xtype, & & ndims, dimids, natts) END FUNCTION !------------------------------------------------------------------------------- !> @brief Inquire a dimension name or length. !> !> @param[in] ncid Netcdf file id. !> @param[in] dimid Dimension id. !> @param[out] name Name of the dimension. !> @param[out] length Length of the dimension. !------------------------------------------------------------------------------- FUNCTION nf_inq_dim(ncid, dimid, name, length) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_inq_dim INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: dimid CHARACTER (len=*), OPTIONAL, INTENT(out) :: name INTEGER, OPTIONAL, INTENT(out) :: length ! Start of executable code nf_inq_dim = nf90_inquire_dimension(ncid, dimid, name, length) END FUNCTION !------------------------------------------------------------------------------- !> @brief Inquire a dimension length. !> !> @param[in] ncid Netcdf file id. !> @param[in] dimid Dimension id. !> @param[out] length Length of the dimension. !------------------------------------------------------------------------------- FUNCTION nf_inq_dimlen(ncid, dimid, length) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_inq_dimlen INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: dimid INTEGER, INTENT(out) :: length ! Start of executable code nf_inq_dimlen = nf90_inquire_dimension(ncid, dimid, len=length) END FUNCTION !******************************************************************************* ! SETTER SUBROUTINES !******************************************************************************* !------------------------------------------------------------------------------- !> @brief Read an string attribute. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] name Name of the attribute. !> @param[out] text String values of the attribute. !------------------------------------------------------------------------------- FUNCTION nf_get_att_text(ncid, varid, name, text) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_att_text INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: name CHARACTER (len=*), INTENT(out) :: text ! Start of executable code nf_get_att_text = nf90_get_att(ncid, varid, name, text) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read an double attribute. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] name Name of the attribute. !> @param[out] dvals Double values of the attribute. !------------------------------------------------------------------------------- FUNCTION nf_get_att_double(ncid, varid, name, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_att_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: name REAL (REAL64), DIMENSION(:), INTENT(out) :: dvals ! Start of executable code nf_get_att_double = nf90_get_att(ncid, varid, name, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read an real attribute. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] name Name of the attribute. !> @param[out] rvals Real values of the attribute. !------------------------------------------------------------------------------- FUNCTION nf_get_att_real(ncid, varid, name, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_att_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: name REAL (REAL32), DIMENSION(:), INTENT(out) :: rvals ! Start of executable code nf_get_att_real = nf90_get_att(ncid, varid, name, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read an integer attribute. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] name Name of the attribute. !> @param[out] ivals Integer values of the attribute. !------------------------------------------------------------------------------- FUNCTION nf_get_att_int(ncid, varid, name, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_att_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: name INTEGER, DIMENSION(:), INTENT(out) :: ivals ! Start of executable code nf_get_att_int = nf90_get_att(ncid, varid, name, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a double value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] dvals Double to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_double(ncid, varid, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL64), INTENT(out) :: dvals ! Start of executable code nf_get_var_double = nf90_get_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a double valued array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] dvals Double array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_1d_double(ncid, varid, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_1d_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL64), DIMENSION(:), INTENT(out) :: dvals ! Start of executable code nf_get_var_1d_double = nf90_get_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a double valued 2D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] dvals Double array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_2d_double(ncid, varid, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_2d_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL64), DIMENSION(:,:), INTENT(out) :: dvals ! Start of executable code nf_get_var_2d_double = nf90_get_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a double valued 3D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] dvals Double array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_3d_double(ncid, varid, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_3d_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL64), DIMENSION(:,:,:), INTENT(out) :: dvals ! Start of executable code nf_get_var_3d_double = nf90_get_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a 64bit complex value. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_cpx_double(ncid, varid, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL64), INTENT(out) :: cvals ! local variables REAL (REAL64), DIMENSION(2) :: dvals ! Start of executable code nf_get_var_cpx_double = nf90_get_var(ncid, varid, dvals) cvals = CMPLX(dvals(1), dvals(2)) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a 64bit complex valued array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a double array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_1d_cpx_double(ncid, varid, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_1d_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL64), DIMENSION(:), INTENT(out) :: cvals ! local variables REAL (REAL64), DIMENSION(:), ALLOCATABLE :: dvals INTEGER :: i ! Start of executable code ALLOCATE(dvals(SIZE(cvals)*2)) nf_get_var_1d_cpx_double = nf90_get_var(ncid, varid, dvals) DO i=1, SIZE(dvals), 2 cvals((i + 1)/2) = CMPLX(dvals(i), dvals(i + 1)) END DO DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a 64bit complex valued 2D array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a double array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_2d_cpx_double(ncid, varid, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_2d_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL64), DIMENSION(:,:), INTENT(out) :: cvals ! local variables REAL (REAL64), DIMENSION(:,:), ALLOCATABLE :: dvals INTEGER :: i INTEGER :: j ! Start of executable code ALLOCATE(dvals(SIZE(cvals, 1)*2, SIZE(cvals, 2))) nf_get_var_2d_cpx_double = nf90_get_var(ncid, varid, dvals) DO j=1, SIZE(dvals, 2), 2 DO i=1, SIZE(dvals, 1), 2 cvals((i + 1)/2,j) = CMPLX(dvals(i,j), dvals(i + 1,j)) END DO END DO DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a 64bit complex valued 3D array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a double array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_3d_cpx_double(ncid, varid, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_3d_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL64), DIMENSION(:,:,:), INTENT(out) :: cvals ! local variables REAL (REAL64), DIMENSION(:,:,:), ALLOCATABLE :: dvals INTEGER :: i INTEGER :: j INTEGER :: k ! Start of executable code ALLOCATE(dvals(SIZE(cvals,1)*2, SIZE(cvals,2), SIZE(cvals,3))) nf_get_var_3d_cpx_double = nf90_get_var(ncid, varid, dvals) DO k=1, SIZE(dvals, 3), 2 DO j=1, SIZE(dvals, 2), 2 DO i=1, SIZE(dvals, 1), 2 cvals((i + 1)/2,j,k) = CMPLX(dvals(i,j,k), & & dvals(i + 1,j,k)) END DO END DO END DO DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a real value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] rvals Real to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_real(ncid, varid, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL32), INTENT(out) :: rvals ! Start of executable code nf_get_var_real = nf90_get_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a real valued array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] rvals Real array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_1d_real(ncid, varid, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_1d_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL32), DIMENSION(:), INTENT(out) :: rvals ! Start of executable code nf_get_var_1d_real = nf90_get_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a real valued 2D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] rvals Real 2D array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_2d_real(ncid, varid, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_2d_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL32), DIMENSION(:,:), INTENT(out) :: rvals ! Start of executable code nf_get_var_2d_real = nf90_get_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a real valued 3D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] rvals Real 3D array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_3d_real(ncid, varid, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_3d_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL32), DIMENSION(:,:,:), INTENT(out) :: rvals ! Start of executable code nf_get_var_3d_real = nf90_get_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a 32bit complex value. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_cpx_real(ncid, varid, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL32), INTENT(out) :: cvals REAL (REAL32), DIMENSION(2) :: rvals ! Start of executable code nf_get_var_cpx_real = nf90_get_var(ncid, varid, rvals) cvals = CMPLX(rvals(1), rvals(2)) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a 32bit complex valued array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_1d_cpx_real(ncid, varid, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_1d_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL32), DIMENSION(:), INTENT(out) :: cvals ! local variables REAL (REAL32), DIMENSION(:), ALLOCATABLE :: rvals INTEGER :: i ! Start of executable code ALLOCATE(rvals(SIZE(cvals)*2)) nf_get_var_1d_cpx_real = nf90_get_var(ncid, varid, rvals) DO i=1, SIZE(rvals), 2 cvals((i + 1)/2) = CMPLX(rvals(i), rvals(i + 1)) END DO DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a 32bit complex valued 2D array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_2d_cpx_real(ncid, varid, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_2d_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL32), DIMENSION(:,:), INTENT(out) :: cvals ! local variables REAL (REAL32), DIMENSION(:,:), ALLOCATABLE :: rvals INTEGER :: i INTEGER :: j ! Start of executable code ALLOCATE(rvals(SIZE(cvals, 1)*2, SIZE(cvals, 2))) nf_get_var_2d_cpx_real = nf90_get_var(ncid, varid, rvals) DO j=1, SIZE(rvals, 2) DO i=1, SIZE(rvals, 1), 2 cvals((i + 1)/2, j) = CMPLX(rvals(i, j), rvals(i + 1, j)) END DO END DO DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a 32bit complex valued 3D array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_3d_cpx_real(ncid, varid, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_3d_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL32), DIMENSION(:,:,:), INTENT(out) :: cvals ! local variables REAL (REAL32), DIMENSION(:,:,:), ALLOCATABLE :: rvals INTEGER :: i INTEGER :: j INTEGER :: k ! Start of executable code ALLOCATE(rvals(SIZE(cvals, 1)*2, SIZE(cvals, 2), SIZE(cvals, 3))) nf_get_var_3d_cpx_real = nf90_get_var(ncid, varid, rvals) DO k=1, SIZE(rvals, 3) DO j=1, SIZE(rvals, 2) DO i=1, SIZE(rvals, 1), 2 cvals((i + 1)/2,j,k) = CMPLX(rvals(i,j,k), & & rvals(i + 1,j,k)) END DO END DO END DO DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read an integer value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] ivals Integer to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_int(ncid, varid, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, INTENT(out) :: ivals ! Start of executable code nf_get_var_int = nf90_get_var(ncid, varid, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read an integer valued array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] ivals Integer array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_1d_int(ncid, varid, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_1d_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(out) :: ivals ! Start of executable code nf_get_var_1d_int = nf90_get_var(ncid, varid, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read an integer valued 2D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] ivals Integer array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_2d_int(ncid, varid, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_2d_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:,:), INTENT(out) :: ivals ! Start of executable code nf_get_var_2d_int = nf90_get_var(ncid, varid, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read an integer valued 3D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] ivals Integer array to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_3d_int(ncid, varid, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_3d_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:,:,:), INTENT(out) :: ivals ! Start of executable code nf_get_var_3d_int = nf90_get_var(ncid, varid, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a text value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] text String to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_var_text(ncid, varid, text) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_var_text INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(out) :: text ! Start of executable code nf_get_var_text = nf90_get_var(ncid, varid, text) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a text valued array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting index of the string array. !> @param[in] count Number of elements to count. !> @param[out] text String to store the value. !------------------------------------------------------------------------------- FUNCTION nf_get_vara_text(ncid, varid, start, count, text) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_get_vara_text INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count CHARACTER (len=*), INTENT(out) :: text ! Start of executable code nf_get_vara_text = nf90_get_var(ncid, varid, text, start=start, & & count=count) END FUNCTION !******************************************************************************* ! SETTER SUBROUTINES !******************************************************************************* !------------------------------------------------------------------------------- !> @brief Put an text attribute. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] name Name of the atribute. !> @param[in] length Length of the real array. !> @param[in] text String value to asign to the attribute. !------------------------------------------------------------------------------- FUNCTION nf_put_att_text(ncid, varid, name, length, text) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_att_text INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: name INTEGER, INTENT(in) :: length CHARACTER (len=*), INTENT(in) :: text ! Start of executable code nf_put_att_text = nf90_put_att(ncid, varid, name, text) END FUNCTION !------------------------------------------------------------------------------- !> @brief Put an double attribute. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] name Name of the atribute. !> @param[in] xtype Type of the value. This is not used. !> @param[in] length Length of the real array. !> @param[in] dvals Real values to asign to the attribute. !------------------------------------------------------------------------------- FUNCTION nf_put_att_double(ncid, varid, name, xtype, length, & & dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_att_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: name INTEGER, INTENT(in) :: xtype INTEGER, INTENT(in) :: length REAL (REAL64), DIMENSION(:), INTENT(in) :: dvals ! Start of executable code nf_put_att_double = nf90_put_att(ncid, varid, name, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Put an real attribute. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] name Name of the atribute. !> @param[in] xtype Type of the value. This is not used. !> @param[in] length Length of the real array. !> @param[in] rvals Real values to asign to the attribute. !------------------------------------------------------------------------------- FUNCTION nf_put_att_real(ncid, varid, name, xtype, length, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_att_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: name INTEGER, INTENT(in) :: xtype INTEGER, INTENT(in) :: length REAL (REAL32), DIMENSION(:), INTENT(in) :: rvals ! Start of executable code nf_put_att_real = nf90_put_att(ncid, varid, name, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Put an integer attribute. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] name Name of the atribute. !> @param[in] xtype Type of the value. This is not used. !> @param[in] length Length of the integer array. !> @param[in] ivals Integer values to asign to the attribute. !------------------------------------------------------------------------------- FUNCTION nf_put_att_int(ncid, varid, name, xtype, length, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_att_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: name INTEGER, INTENT(in) :: xtype INTEGER, INTENT(in) :: length INTEGER, DIMENSION(:), INTENT(in) :: ivals ! Start of executable code nf_put_att_int = nf90_put_att(ncid, varid, name, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write an integer value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] ivals Integer value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_int(ncid, varid, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, INTENT(in) :: ivals ! Start of executable code nf_put_var_int = nf90_put_var(ncid, varid, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write an integer valued array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] ivals Integer value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_1d_int(ncid, varid, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_1d_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: ivals ! Start of executable code nf_put_var_1d_int = nf90_put_var(ncid, varid, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write an integer valued 2D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] ivals Integer value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_2d_int(ncid, varid, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_2d_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:,:), INTENT(in) :: ivals ! Start of executable code nf_put_var_2d_int = nf90_put_var(ncid, varid, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write an integer valued 3D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] ivals Integer value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_3d_int(ncid, varid, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_3d_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:,:,:), INTENT(in) :: ivals ! Start of executable code nf_put_var_3d_int = nf90_put_var(ncid, varid, ivals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a integer value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] ivals Double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_int(ncid, varid, start, count, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count INTEGER, DIMENSION(:,:), INTENT(in) :: ivals ! Start of executable code nf_put_vara_int = nf90_put_var(ncid, varid, ivals, start=start, & & count=count) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a integer value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] ivals Double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_3d_int(ncid, varid, start, count, ivals) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_3d_int INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count INTEGER, DIMENSION(:,:,:), INTENT(in) :: ivals ! Start of executable code nf_put_vara_3d_int = nf90_put_var(ncid, varid, ivals, start=start, & & count=count) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a double value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] dvals Double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_double(ncid, varid, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL64), INTENT(in) :: dvals ! Start of executable code nf_put_var_double = nf90_put_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a double valued array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] dvals Double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_1d_double(ncid, varid, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_1d_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL64), DIMENSION(:), INTENT(in) :: dvals ! Start of executable code nf_put_var_1d_double = nf90_put_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a double valued 2D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] dvals Double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_2d_double(ncid, varid, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_2d_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL64), DIMENSION(:,:), INTENT(in) :: dvals ! Start of executable code nf_put_var_2d_double = nf90_put_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a double valued 3D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] dvals Double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_3d_double(ncid, varid, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_3d_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL64), DIMENSION(:,:,:), INTENT(in) :: dvals ! Start of executable code nf_put_var_3d_double = nf90_put_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a 64bit complex value. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] cvals Complex value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_cpx_double(ncid, varid, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL64), INTENT(in) :: cvals ! local variables REAL (REAL64), DIMENSION(2) :: dvals ! Start of executable code dvals(1) = REAL(cvals) dvals(2) = AIMAG(cvals) nf_put_var_cpx_double = nf90_put_var(ncid, varid, dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a 64bit complex valued array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a double array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] cvals Complex value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_1d_cpx_double(ncid, varid, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_1d_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL64), DIMENSION(:), INTENT(in) :: cvals ! local variables REAL (REAL64), DIMENSION(:), ALLOCATABLE :: dvals INTEGER :: i ! Start of executable code ALLOCATE(dvals(SIZE(cvals)*2)) DO i=1, SIZE(dvals, 1), 2 dvals(i) = REAL(cvals((i + 1)/2)) dvals(i + 1) = AIMAG(cvals((i + 1)/2)) END DO nf_put_var_1d_cpx_double = nf90_put_var(ncid, varid, dvals) DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a 64bit complex valued 2D array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a double array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] cvals Complex value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_2d_cpx_double(ncid, varid, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_2d_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL64), DIMENSION(:,:), INTENT(in) :: cvals ! local variables REAL (REAL64), DIMENSION(:,:), ALLOCATABLE :: dvals INTEGER :: i INTEGER :: j ! Start of executable code ALLOCATE(dvals(SIZE(cvals, 1)*2, SIZE(cvals, 2))) DO j=1, SIZE(dvals, 2) DO i=1, SIZE(dvals, 1), 2 dvals(i,j) = REAL(cvals((i + 1)/2,j)) dvals(i + 1,j) = AIMAG(cvals((i + 1)/2,j)) END DO END DO nf_put_var_2d_cpx_double = nf90_put_var(ncid, varid, dvals) DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a 64bit complex valued 3D array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a double array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] cvals Complex value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_3d_cpx_double(ncid, varid, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_3d_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL64), DIMENSION(:,:,:), INTENT(in) :: cvals ! local variables REAL (REAL64), DIMENSION(:,:,:), ALLOCATABLE :: dvals INTEGER :: i INTEGER :: j INTEGER :: k ! Start of executable code ALLOCATE(dvals(SIZE(cvals,1)*2, SIZE(cvals,2), SIZE(cvals,3))) DO k=1, SIZE(dvals, 3) DO j=1, SIZE(dvals, 2) DO i=1, SIZE(dvals, 1), 2 dvals(i,j,k) = REAL(cvals((i + 1)/2,j,k)) dvals(i + 1,j,k) = AIMAG(cvals((i + 1)/2,j,k)) END DO END DO END DO nf_put_var_3d_cpx_double = nf90_put_var(ncid, varid, dvals) DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a double value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] dvals Double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_double(ncid, varid, start, count, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count REAL (REAL64), DIMENSION(:), INTENT(in) :: dvals ! Start of executable code nf_put_vara_double = nf90_put_var(ncid, varid, dvals, start=start, & & count=count) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a double value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] dvals Double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_2d_double(ncid, varid, start, count, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_2d_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count REAL (REAL64), DIMENSION(:,:), INTENT(in) :: dvals ! Start of executable code nf_put_vara_2d_double = nf90_put_var(ncid, varid, dvals, & & start=start, count=count) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a double value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] dvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_3d_double(ncid, varid, start, count, dvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_3d_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count REAL (REAL64), DIMENSION(:,:,:), INTENT(in) :: dvals ! Start of executable code nf_put_vara_3d_double = nf90_put_var(ncid, varid, dvals, & & start=start, count=count) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a complex double value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] cvals Complex double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_cpx_double(ncid, varid, start, count, cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count COMPLEX (REAL64), DIMENSION(:), INTENT(in) :: cvals ! local variables REAL (REAL64), DIMENSION(:), ALLOCATABLE :: dvals INTEGER :: i ! Start of executable code ALLOCATE(dvals(SIZE(cvals)*2)) DO i = 1, SIZE(dvals), 2 dvals(i) = REAL(cvals((i + 1)/2)) dvals(i + 1) = AIMAG(cvals((i + 1)/2)) END DO nf_put_vara_cpx_double = nf90_put_var(ncid, varid, dvals, & & start=start, count=count) DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a complex double value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] cvals Complex double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_2d_cpx_double(ncid, varid, start, count, & & cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_2d_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count COMPLEX (REAL64), DIMENSION(:,:), INTENT(in) :: cvals ! local variables REAL (REAL64), DIMENSION(:,:), ALLOCATABLE :: dvals INTEGER :: i INTEGER :: j ! Start of executable code ALLOCATE(dvals(SIZE(cvals, 1)*2, SIZE(cvals, 2))) DO j = 1, SIZE(dvals, 2) DO i = 1, SIZE(dvals, 1), 2 dvals(i,j) = REAL(cvals((i + 1)/2, j)) dvals(i + 1,j) = AIMAG(cvals((i + 1)/2, j)) END DO END DO nf_put_vara_2d_cpx_double = nf90_put_var(ncid, varid, dvals, & & start=start, count=count) DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a double value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] cvals Complex double value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_3d_cpx_double(ncid, varid, start, count, & & cvals) USE iso_fortran_env, only: REAL64 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_3d_cpx_double INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count COMPLEX (REAL64), DIMENSION(:,:,:), INTENT(in) :: cvals ! local variables REAL (REAL64), DIMENSION(:,:,:), ALLOCATABLE :: dvals INTEGER :: i INTEGER :: j INTEGER :: k ! Start of executable code ALLOCATE(dvals(SIZE(cvals, 1)*2, SIZE(cvals, 2), SIZE(cvals, 3))) DO k = 1, SIZE(dvals, 3) DO j = 1, SIZE(dvals, 2) DO i = 1, SIZE(dvals, 1), 2 dvals(i,j,k) = REAL(cvals((i + 1)/2,j,k)) dvals(i + 1,j,k) = AIMAG(cvals((i + 1)/2,j,k)) END DO END DO END DO nf_put_vara_3d_cpx_double = nf90_put_var(ncid, varid, dvals, & & start=start, count=count) DEALLOCATE(dvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a real value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] rvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_real(ncid, varid, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL32), INTENT(in) :: rvals ! Start of executable code nf_put_var_real = nf90_put_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a real valued array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] rvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_1d_real(ncid, varid, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_1d_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL32), DIMENSION(:), INTENT(in) :: rvals ! Start of executable code nf_put_var_1d_real = nf90_put_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Read a real valued 2D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] rvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_2d_real(ncid, varid, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_2d_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL32), DIMENSION(:,:), INTENT(in) :: rvals ! Start of executable code nf_put_var_2d_real = nf90_put_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a real valued 3D array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] rvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_3d_real(ncid, varid, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_3d_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid REAL (REAL32), DIMENSION(:,:,:), INTENT(in) :: rvals ! Start of executable code nf_put_var_3d_real = nf90_put_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a 32bit complex value. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_cpx_real(ncid, varid, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL32), INTENT(in) :: cvals ! local variables REAL (REAL32), DIMENSION(2) :: rvals ! Start of executable code rvals(1) = REAL(cvals) rvals(2) = AIMAG(cvals) nf_put_var_cpx_real = nf90_put_var(ncid, varid, rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a 32bit complex valued array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_1d_cpx_real(ncid, varid, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_1d_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL32), DIMENSION(:), INTENT(in) :: cvals ! local variables REAL (REAL32), DIMENSION(:), ALLOCATABLE :: rvals INTEGER :: i ! Start of executable code ALLOCATE(rvals(SIZE(cvals)*2)) DO i=1, SIZE(rvals, 1), 2 rvals(i) = REAL(cvals((i + 1)/2)) rvals(i + 1) = AIMAG(cvals((i + 1)/2)) END DO nf_put_var_1d_cpx_real = nf90_put_var(ncid, varid, rvals) DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a 32bit complex valued 2D array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_2d_cpx_real(ncid, varid, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_2d_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL32), DIMENSION(:,:), INTENT(in) :: cvals ! local variables REAL (REAL32), DIMENSION(:,:), ALLOCATABLE :: rvals INTEGER :: i INTEGER :: j ! Start of executable code ALLOCATE(rvals(SIZE(cvals, 1)*2, SIZE(cvals, 2))) DO j=1, SIZE(rvals, 2) DO i=1, SIZE(rvals, 1), 2 rvals(i,j) = REAL(cvals((i + 1)/2,j)) rvals(i + 1,j) = AIMAG(cvals((i + 1)/2,j)) END DO END DO nf_put_var_2d_cpx_real = nf90_put_var(ncid, varid, rvals) DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a 32bit complex valued 3D array. !> !> Netcdf does not support complex types directly. Instead these values are !> interweaved into a real array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[out] cvals Complex value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_3d_cpx_real(ncid, varid, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_3d_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid COMPLEX (REAL32), DIMENSION(:,:,:), INTENT(in) :: cvals ! local variables REAL (REAL32), DIMENSION(:,:,:), ALLOCATABLE :: rvals INTEGER :: i INTEGER :: j INTEGER :: k ! Start of executable code ALLOCATE(rvals(SIZE(cvals,1)*2, SIZE(cvals,2), SIZE(cvals,3))) DO k=1, SIZE(rvals, 3) DO j=1, SIZE(rvals, 2) DO i=1, SIZE(rvals, 1), 2 rvals(i,j,k) = REAL(cvals((i + 1)/2,j,k)) rvals(i + 1,j,k) = AIMAG(cvals((i + 1)/2,j,k)) END DO END DO END DO nf_put_var_3d_cpx_real = nf90_put_var(ncid, varid, rvals) DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a real value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] rvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_real(ncid, varid, start, count, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count REAL (REAL32), DIMENSION(:), INTENT(in) :: rvals ! Start of executable code nf_put_vara_real = nf90_put_var(ncid, varid, rvals, start=start, & & count=count) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a real value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] rvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_2d_real(ncid, varid, start, count, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_2d_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count REAL (REAL32), DIMENSION(:,:), INTENT(in) :: rvals ! Start of executable code nf_put_vara_2d_real = nf90_put_var(ncid, varid, rvals, & & start=start, count=count) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a real value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] rvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_3d_real(ncid, varid, start, count, rvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_3d_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count REAL (REAL32), DIMENSION(:,:,:), INTENT(in) :: rvals ! Start of executable code nf_put_vara_3d_real = nf90_put_var(ncid, varid, rvals, & & start=start, count=count) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a complex real value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] cvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_cpx_real(ncid, varid, start, count, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count COMPLEX (REAL32), DIMENSION(:), INTENT(in) :: cvals ! local variables REAL (REAL32), DIMENSION(:), ALLOCATABLE :: rvals INTEGER :: i ! Start of executable code ALLOCATE(rvals(SIZE(cvals)*2)) DO i = 1, SIZE(rvals), 2 rvals(i) = REAL(cvals((i + 1)/2)) rvals(i + 1) = AIMAG(cvals((i + 1)/2)) END DO nf_put_vara_cpx_real = nf90_put_var(ncid, varid, rvals, & & start=start, count=count) DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a complex real value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] cvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_2d_cpx_real(ncid, varid, start, count, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_2d_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count COMPLEX (REAL32), DIMENSION(:,:), INTENT(in) :: cvals ! local variables REAL (REAL32), DIMENSION(:,:), ALLOCATABLE :: rvals INTEGER :: i INTEGER :: j ! Start of executable code ALLOCATE(rvals(SIZE(cvals, 1)*2, SIZE(cvals, 2))) DO j = 1, SIZE(rvals, 2) DO i = 1, SIZE(rvals, 1), 2 rvals(i,j) = REAL(cvals((i + 1)/2, j)) rvals(i + 1,j) = AIMAG(cvals((i + 1)/2, j)) END DO END DO nf_put_vara_2d_cpx_real = nf90_put_var(ncid, varid, rvals, & & start=start, count=count) DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a complex real value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting indices. !> @param[in] count Number of elements to count. !> @param[in] cvals Real value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_3d_cpx_real(ncid, varid, start, count, cvals) USE iso_fortran_env, only: REAL32 IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_3d_cpx_real INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count COMPLEX (REAL32), DIMENSION(:,:,:), INTENT(in) :: cvals ! local variables REAL (REAL32), DIMENSION(:,:,:), ALLOCATABLE :: rvals INTEGER :: i INTEGER :: j INTEGER :: k ! Start of executable code ALLOCATE(rvals(SIZE(cvals, 1)*2, SIZE(cvals, 2), SIZE(cvals, 3))) DO k = 1, SIZE(rvals, 3) DO j = 1, SIZE(rvals, 2) DO i = 1, SIZE(rvals, 1), 2 rvals(i,j,k) = REAL(cvals((i + 1)/2,j,k)) rvals(i + 1,j,k) = AIMAG(cvals((i + 1)/2,j,k)) END DO END DO END DO nf_put_vara_3d_cpx_real = nf90_put_var(ncid, varid, rvals, & & start=start, count=count) DEALLOCATE(rvals) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a text value. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] text String value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_var_text(ncid, varid, text) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_var_text INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid CHARACTER (len=*), INTENT(in) :: text ! Start of executable code nf_put_var_text = nf90_put_var(ncid, varid, text) END FUNCTION !------------------------------------------------------------------------------- !> @brief Write a text valued array. !> !> @param[in] ncid Netcdf file id. !> @param[in] varid Variable id. !> @param[in] start Starting index of the string array. !> @param[in] count Number of elements to count. !> @param[in] text String value to write. !------------------------------------------------------------------------------- FUNCTION nf_put_vara_text(ncid, varid, start, count, text) IMPLICIT NONE ! Declare Arguments INTEGER :: nf_put_vara_text INTEGER, INTENT(in) :: ncid INTEGER, INTENT(in) :: varid INTEGER, DIMENSION(:), INTENT(in) :: start INTEGER, DIMENSION(:), INTENT(in) :: count CHARACTER (len=*), DIMENSION(:), INTENT(in) :: text ! Start of executable code nf_put_vara_text = nf90_put_var(ncid, varid, text, start=start, & & count=count) END FUNCTION END MODULE
```python %matplotlib inline import sys import pywt import numpy as np import scipy as sp import sympy as sym import numexpr as ne import matplotlib.pyplot as plt #import of acalib helper functions sys.path.append('/home/martin/Repositories/ACALIB') from acalib import acontainer as ac from acalib.io import graph as gp ``` ```python """ Loading data """ cont = ac.AContainer() #cont.load('/home/martin/Repositories/bindata/fits/cubes/Antennae_North.CO3_2Line.Clean.pcal1.image.fits') #cont.load('/home/martin/Repositories/bindata/fits/cubes/Antennae_South.CO3_2Line.Clean.pcal1.image.fits') #cont.load('/home/martin/Repositories/bindata/fits/cubes/CenA.CO2_1Line.Clean.image.fits') #cont.load('/home/martin/Repositories/bindata/fits/cubes/M100line.image.fits') cont.load('/home/martin/Repositories/bindata/fits/cubes/Orion.methanol.cbc.contsub.image.fits') cube = cont.primary spar = cube.standarize() data = cube.data data = data.filled(fill_value=0) data = data[:,18:82,18:82] ``` INFO: Processing HDU 0 (Image) [acalib.io.formats] INFO: 4D data detected: assuming RA-DEC-FREQ-STOKES (like CASA-generated ones), and dropping STOKES [acalib.io.formats] ```python def plot_helper(data, freqs=range(0,40,4)): fig = plt.figure(figsize=(17,9)) count = 1 for f in freqs: slc = data[f] fig.add_subplot(2,5,count) plt.imshow(slc) plt.axis('off') plt.title('Slice at freq={0}'.format(f)) count += 1 plt.show() ``` ```python data08 = data[8] data16 = data[16] data24 = data[24] data32 = data[32] ``` ```python fig = plt.figure(figsize=(17,9)) fig.add_subplot(1,4,1) plt.imshow(data08) plt.axis('off') plt.title('Slice at freq=8') fig.add_subplot(1,4,2) plt.imshow(data16) plt.axis('off') plt.title('Slice at freq=16') fig.add_subplot(1,4,3) plt.imshow(data24) plt.axis('off') plt.title('Slice at freq=24') fig.add_subplot(1,4,4) plt.imshow(data32) plt.axis('off') plt.title('Slice at freq=32') plt.show() ``` ```python wt08_1 = pywt.swt2(data08, 'haar', 6)[1][0] wt16_1 = pywt.swt2(data16, 'haar', 6)[1][0] wt24_1 = pywt.swt2(data24, 'haar', 6)[1][0] wt32_1 = pywt.swt2(data32, 'haar', 6)[1][0] wt08_3 = pywt.swt2(data08, 'haar', 6)[2][0] wt16_3 = pywt.swt2(data16, 'haar', 6)[2][0] wt24_3 = pywt.swt2(data24, 'haar', 6)[2][0] wt32_3 = pywt.swt2(data32, 'haar', 6)[2][0] wt08_5 = pywt.swt2(data08, 'haar', 6)[3][0] wt16_5 = pywt.swt2(data16, 'haar', 6)[3][0] wt24_5 = pywt.swt2(data24, 'haar', 6)[3][0] wt32_5 = pywt.swt2(data32, 'haar', 6)[3][0] wt08_4 = pywt.swt2(data08, 'haar', 6)[4][0] wt16_4 = pywt.swt2(data16, 'haar', 6)[4][0] wt24_4 = pywt.swt2(data24, 'haar', 6)[4][0] wt32_4 = pywt.swt2(data32, 'haar', 6)[4][0] ``` ```python type(wt08_1) ``` numpy.ndarray ```python fig = plt.figure(figsize=(17,9)) fig.add_subplot(1,4,1) plt.imshow(wt08_1) plt.axis('off') plt.title('Slice at freq=8') fig.add_subplot(1,4,2) plt.imshow(wt16_1) plt.axis('off') plt.title('Slice at freq=16') fig.add_subplot(1,4,3) plt.imshow(wt24_1) plt.axis('off') plt.title('Slice at freq=24') fig.add_subplot(1,4,4) plt.imshow(wt32_1) plt.axis('off') plt.title('Slice at freq=32') plt.show() ``` ```python fig = plt.figure(figsize=(17,9)) fig.add_subplot(1,4,1) plt.imshow(wt08_3) plt.axis('off') plt.title('Slice at freq=8') fig.add_subplot(1,4,2) plt.imshow(wt16_3) plt.axis('off') plt.title('Slice at freq=16') fig.add_subplot(1,4,3) plt.imshow(wt24_3) plt.axis('off') plt.title('Slice at freq=24') fig.add_subplot(1,4,4) plt.imshow(wt32_3) plt.axis('off') plt.title('Slice at freq=32') plt.show() ``` ```python fig = plt.figure(figsize=(17,9)) fig.add_subplot(1,4,1) plt.imshow(wt08_5) plt.axis('off') plt.title('Slice at freq=8') fig.add_subplot(1,4,2) plt.imshow(wt16_5) plt.axis('off') plt.title('Slice at freq=16') fig.add_subplot(1,4,3) plt.imshow(wt24_5) plt.axis('off') plt.title('Slice at freq=24') fig.add_subplot(1,4,4) plt.imshow(wt32_5) plt.axis('off') plt.title('Slice at freq=32') plt.show() ``` ```python asdf = pywt.swt2(data08, 'haar', 6) ``` ```python from numpy import mean, sqrt, square, arange ``` ```python rms08_1 = sqrt(mean(square(wt08_1))) rms16_1 = sqrt(mean(square(wt16_1))) rms24_1 = sqrt(mean(square(wt24_1))) rms32_1 = sqrt(mean(square(wt32_1))) ``` ```python wt08_1[wt08_1 < rms08_1] = 0 wt16_1[wt16_1 < rms16_1] = 0 wt24_1[wt24_1 < rms24_1] = 0 wt32_1[wt32_1 < rms32_1] = 0 ``` ```python fig = plt.figure(figsize=(17,9)) fig.add_subplot(1,4,1) plt.imshow(wt08_5) plt.axis('off') plt.title('Slice at freq=8') fig.add_subplot(1,4,2) plt.imshow(wt16_5) plt.axis('off') plt.title('Slice at freq=16') fig.add_subplot(1,4,3) plt.imshow(wt24_5) plt.axis('off') plt.title('Slice at freq=24') fig.add_subplot(1,4,4) plt.imshow(wt32_5) plt.axis('off') plt.title('Slice at freq=32') plt.show() ``` ```python fig = plt.figure(figsize=(17,9)) fig.add_subplot(1,4,1) plt.imshow(wt08_1) plt.axis('off') plt.title('Slice at freq=8') fig.add_subplot(1,4,2) plt.imshow(wt16_1) plt.axis('off') plt.title('Slice at freq=16') fig.add_subplot(1,4,3) plt.imshow(wt24_1) plt.axis('off') plt.title('Slice at freq=24') fig.add_subplot(1,4,4) plt.imshow(wt32_1) plt.axis('off') plt.title('Slice at freq=32') plt.show() ``` ```python ```
Chief Jim Hyde was the Police Chief for the Davis Police Department from 2003 to June 2006. The ninth Chief, he was preceded by Martin C. Ruiz and succeeded by Landy Black. Citing difficulties with the Davis Human Relations Commission as the reason, Jim announced his resignation and acceptance of a position as the Chief of Police, City of Antioch on 6/13/06. http://davisenterprise.com/articles/2006/06/14/news/200new1.txt Enterprise Link Around the time of his resignation, members of the Human Relations Commission were critical of Hyde because of his role in the Halema Buzayan case. The Humans Relations Commission also recommended the creation of a Police Review Board. Since leaving the Davis Police Department, Hyde has made several harsh criticisms of his former colleagues. According to a http://davisvanguard.org/index.php?optioncom_content&viewarticle&id2790:formerchiefoffersinsultingdepictionofdpd&catid54:lawenforcement&Itemid87 Davis Vanguard article, he compared the Davis police force to Reno 911 characters, stating they were dysfunctional, used obsolete equipment, and often made up statistics. In total, Hyde has been named in four federal civil rights lawsuits. His previous law enforcement assignments included Homicide, Career Criminal Apprehension, Gang Unit, Narcotic/Gang Task Force, SWAT, and Patrol with the Sacramento Police Department. Chief Hyde has a Bachelor of Science Degree in Criminal Justice from the University of South Dakota, a Masters Degree in Clinical Psychology from the Professional School of Psychology, Sacramento. He is a graduate of the Senior Management Institute for Police sponsored by the Kennedy School of Government, Harvard University and the Police Executive Research Forum. Chief Hyde is a certified Executive Coach and he is also a doctoral student studying Organizational Psychology. Ive talked with Hyde on a couple of occasions, notably when I was setting up a place to meet him. The man just couldnt get a good photo ever. evar. Users/StevenDaubert 20060614 05:21:57 nbsp Word has it that Hyde is resigning Users/HenryBianco 20060614 15:17:26 nbsp The City of Antioch website shows that the application period for the Chief of Police closed in early April and initial interviews took place the next week. This was in the midst of the HRCs meetings regarding forming a citizens police overview commission. Users/SharlaDaly 20060614 15:40:04 nbsp Salary Ranges for Police Chiefs. In Antioch the range is $130K to $158K. In Davis the range is $103K to $125K. The Chief would like us to believe he was driven from town by the HRC. Do Davis Police Officers ever tell the truth? Users/SteveHayes Come on, do you really have enough evidence to make this strong an assertion about Hydes motives? Users/KenjiYamada 20060614 20:20:11 nbsp I do not have enough evidence? We are aware of two possible motivations for why he wants to leave Davis. On the one hand there is a 30% salary increase which is worth at least $30K per year. On the other hand Mr. Hyde was annoyed by a group of people who challenged the actions of his organization. Guess which factor really caused him to leave Davis. He was going to leave regardless of Davis politics. It was unfortunate that he chose to take the low road on the way out as he cast out a couple of cheap shots. Users/SteveHayes I think youre significantly downplaying the hostile environment for police in Davis. Ill be the first to agree that the departments actions and poor response to criticism arent helping that situation any, but I really dont see how you can know with so much certainty that Hydes reason for leaving was just the money in Antioch and the controversy here in town was only a false pretext. Users/KenjiYamada 20060614 16:36:09 nbsp WOW Users/JamesSchwab 20060614 21:23:33 nbsp Well, problems with the HRC would explain a desire to move, considering the controversies lately. Its probably a combination of location, HRC, and pay. Users/KarlMogel 20060615 07:03:48 nbsp Granted I have reason to be biased in this, but I think Steve is probably closer to being correct. Hyde had a chance to move on to a bigger city, with more crime and a larger police force. He probably was tired of the criticism, which he really did not handle all that well and he made the situation much worse with his handling of it. But in the end, he took the highly unusual parting shot at the HRC and my wife, which served as a selfserving excuse that will if anything inflame polarization within this community. That certainly is not going to help this situation. Users/DavidGreenwald Sharlas comment removed. Decided I didnt want to discuss this in this venue. Needs face to face discussion. Users/SharlaDaly 20060615 08:32:14 nbsp Sharla: First of all, until there is an actual ombudsman, there is no system to steer people into. Second, the HRC has not touched this issue as a body since the February 21, 2006 meeting when they presented their report on the police oversight committee. So Im not exactly sure what the HRC has done to warrant your response. Ill also add, following what was said yesterday, Hyde did not give the HRC any choice. They tried to meet with him, found him very defensive and unwilling to acknowledge any mistakes, this was mainly dealing with the Buzayan case, but there were actually incidents last summer predating that. The family themselves tried to go through the system, were rebuffed, Gina Anderson turned the investigation of Ly into another investigation of Halema and Najat. Hyde withdrew, refused to meet anymore and things deteriorated. There was no willingness to reach common ground on the part of the Chief, and as a result we have had the drawn out battle for the last year. The HRC was put into this situation because there was no other outlet. Dr. Buzayan went before Council the night after the incident, but Council didnt act. It was only then that he went to the HRC who did act.Users/DavidGreenwald What David said. Dr. Buzayan made it clear on numerous occasions that all he wanted was for the charges to go away and the police department to apologize to him and his family. He specifically stated that he did not want to make money on a lawsuit. It took a judge to call bullshit on the charges and Jim Hyde stood firmly behind officer Ly and his conduct even after the case was tossed. As to the HRCs role in the Buzayan incident, I think it was minor to none. At the one meeting I attended, if anything, Dr. Buzayan seemed somewhat uncomfortable with Cecilia Greenwalds overall position. Personally, I got involved in the Buzayan incident because a good friend in Sacramento told me about it, and indeed, most of the people at the meeting I attented were of the Muslim faith and were of Northern Africa extraction and no connection with to the HRC. Another thing that Id like to point out is that many people, even before the Buzayan incident, considered Davis police to be unpopular and detached from Davis community values. If there was any other flaw of Chief Hyde it was not addressing this issue and instead focusing on stuff like boost the use of technology to enhance police work. Users/GrumpyoldGeek 20060615 16:30:55 nbsp I say good riddance. Users/PaulThober 20060615 17:19:52 nbsp Can someone please explain to this poor noob about the HRC complaints, or provide a link to a place that can? Users/CharlesGeorge 20060615 18:08:40 nbsp Okay. The Human Relations Commission is a group of people appointed by the City Council to criticize other people. Arguably, this is useful, but the Police Chief got annoyed with it so he quit when another city offered him more money. Also, the Davis Police Department Davis Police and the Human Relations Commission both include jerks as will any group of people. The social and political power that these groups have means that the jerks often get to be in the newspaper when they fight with each other. It was his duty to fix what problems the police department certainly has, so he failed, but I think quitting is understandable given the offer of more money combined with the uncooperative criticism, cheap shots, and Law Office of Dean Johansson fight the man, cops are pigs attitude the human relations commission and Police Misconduct Stories others often took. Users/NickSchmalenberger 20060615 19:33:27 nbsp Also, Hyde was looking to leave a year ago before any of this started. Users/DavidGreenwald 20070613 16:07:30 nbsp As an Antioch resident I thank you people in Davis very much! Jim Hyde is the BEST police chief this city has had for a long time. The previous chief denied that we had a problem with crime, while Chief Hyde is acknowledging that there is a problem and working to clean things up. Hes not afraid of hard work and he supports his officers when they are in the right and we appreciate his efforts. So thanks for your fear of cracking down on crime and false accusations of racial profiling, your loss is our gain! After all, you seem to forget that this girl committed a FELONY hit and run, so just offering to PAY OFF the victim and fix the car is not going to make a criminal act go away! Users/PLM HAHAHAHA! You are lucky to have Chief Hyde since he got his PhD on our money and time. The Chief only worked half the hours we paid him to work, the rest of the time he spent getting his PhD. I also dont understand your defense of him, the community did not accuse him of racial profiling, they accused him of not dealing with the officers that were accused of racial profiling. Guess he was too busy getting his PhD on our time and money. Wow, a police Chief who thinks crime is a problem, what a novelty, that education did him well.Users/JamesSchwab To add to James point. Your facts are wrong as well. The girl was charged with a misdemeanor not a felony. The case was dismissed. Now you call that paying off the victim. Actually the judge ruled that the purpose of a misdemeanor hit and run is to insure that people will take responsibility for the damage done to vehicle. The point at which the victim accepts a civil resolution, the crime is nulified in a noninjury situation. Ill be interested to see your opinion of Hyde in a few years, a year into his tenure in Davis, most people thought that Hyde was very good. That changed though over time. Perhaps hell have learned from his experience here, but until you get the first real flash point issue, its hard to judge anyone. Users/DavidGreenwald
module Sets.PredicateSet.Relations{ℓₗ}{ℓₒ} where import Lvl open import Functional open import Logic.Propositional{ℓₗ Lvl.⊔ ℓₒ} open import Logic.Predicate{ℓₗ}{ℓₒ} open import Numeral.Finite open import Numeral.Natural import Relator.Equals open import Sets.PredicateSet open import Structure.Function.Domain Empty : ∀{T} → PredSet{ℓₗ}{ℓₒ}(T) → Stmt Empty(S) = (∀{x} → (x ∉' S)) where _∉'_ = _∉_ {ℓₗ}{ℓₒ} NonEmpty : ∀{T} → PredSet{ℓₗ}{ℓₒ}(T) → Stmt NonEmpty(S) = ∃(x ↦ (x ∈' S)) where _∈'_ = _∈_ {ℓₗ}{ℓₒ}
\section{File List} Here is a list of all files with brief descriptions\+:\begin{DoxyCompactList} \item\contentsline{section}{libjpconj/\hyperlink{inflection_8cpp}{inflection.\+cpp} }{\pageref{inflection_8cpp}}{} \item\contentsline{section}{libjpconj/\hyperlink{inflection_8h}{inflection.\+h} }{\pageref{inflection_8h}}{} \item\contentsline{section}{libjpconj/\hyperlink{jpconj_8cpp}{jpconj.\+cpp} }{\pageref{jpconj_8cpp}}{} \item\contentsline{section}{libjpconj/\hyperlink{jpconj_8h}{jpconj.\+h} }{\pageref{jpconj_8h}}{} \item\contentsline{section}{libjpconj/\hyperlink{jpconj__global_8h}{jpconj\+\_\+global.\+h} }{\pageref{jpconj__global_8h}}{} \item\contentsline{section}{libjpconj/\hyperlink{lemmatization_8cpp}{lemmatization.\+cpp} }{\pageref{lemmatization_8cpp}}{} \item\contentsline{section}{libjpconj/\hyperlink{lemmatization_8h}{lemmatization.\+h} }{\pageref{lemmatization_8h}}{} \item\contentsline{section}{libjpconj/\hyperlink{type_defs_8h}{type\+Defs.\+h} }{\pageref{type_defs_8h}}{} \item\contentsline{section}{libjpconj/\hyperlink{verbstem_8cpp}{verbstem.\+cpp} }{\pageref{verbstem_8cpp}}{} \item\contentsline{section}{libjpconj/\hyperlink{verbstem_8h}{verbstem.\+h} }{\pageref{verbstem_8h}}{} \end{DoxyCompactList}
= = = Similar species = = =
= = = Similar species = = =
= = = Similar species = = =
subroutine z_uzd(j ,nmmaxj ,nmmax ,kmax ,icx , & & icy ,nsrc ,kcs ,kcs45 ,kcscut , & & kcu ,kfu ,kfuz0 ,kfumn0 ,kfumx0 , & & kfv ,kfvz0 ,kfvmn0 ,kfvmx0 ,dzv0 , & & kfs ,kfsz0 ,kfsmn0 ,kfsmx0 , & & u0 ,v0 ,w0 ,hu ,hv ,dzu0 ,dzs0 , & & guu ,gvv ,gvu ,guv ,gsqs , & & gud ,gvd ,guz ,gvz ,gsqiu , & & disch ,umdis ,kspu ,mnksrc ,dismmt , & & aak ,bbk ,cck ,ddk ,bdx , & & bux ,bdy ,buy ,buxuy ,buxdy , & & bdxuy ,bdxdy ,uvdwk ,vvdwk ,circ2d ,circ3d , & & vicuv ,vnu2d ,vicww ,tgfsep ,dps , & & dfu ,deltau ,tp ,rlabda ,fxw ,wsbodyu , & & drhodx ,wsu ,taubpu ,taubsu ,rxx , & & rxy ,windu ,patm ,fcorio ,p0 , & & ubrlsu ,pship ,diapl ,rnpl ,cfurou , & & u1 ,s0 ,dpu ,qxk ,qyk , & & norow ,nocol ,irocol ,nst ,umean , & & crbc ,ustokes ,gdp ) !----- GPL --------------------------------------------------------------------- ! ! Copyright (C) Stichting Deltares, 2011-2016. ! ! This program is free software: you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation version 3. ! ! 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/>. ! ! contact: [email protected] ! Stichting Deltares ! P.O. Box 177 ! 2600 MH Delft, The Netherlands ! ! All indications and logos of, and references to, "Delft3D" and "Deltares" ! are registered trademarks of Stichting Deltares, and remain the property of ! Stichting Deltares. All rights reserved. ! !------------------------------------------------------------------------------- ! $Id: z_uzd.f90 5717 2016-01-12 11:35:24Z mourits $ ! $HeadURL: https://svn.oss.deltares.nl/repos/delft3d/tags/6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute/z_uzd.f90 $ !!--description----------------------------------------------------------------- ! ! This subroutine evaluates/solves the horizontal momentum equation for a Z-layer ! vertical grid. It is called at each half time step for the case of a ! hydrostatic flow model or in the prediction step of the full non-hydrostatic method ! (full time step). ! For the spatial and temporal dsicretisation there are different options. ! Reference : A.O.I. - scheme (G.S. Stelling and ! J.J. Leendertse, Approximation of Convective ! Processes by Cyclic AOI Methods, Proceedings, ! ASCE Conference, Tampa, 1991). ! ! Z_UZD has the following options in the evaluation: ! ! For the horizontal advection: ! - Horizontal Advection: depending on the flag MOMSOL. Options: ! implicit, upwind scheme (IUPW) ! explicit, multi-directional upwind (MDUE) ! implicit, multi-directional upwind (MDUI) ! explicit, finite volume approach, conservation of momentum (FINVOL) ! explicit, combination of conservation of momentum and energy following ! Stelling and Duinmeyer (FLOOD) ! The vertical viscosity term is integrated implicitly ! - Horizontal Viscosity is integrated implicitly, along Z-planes ! - Vertical Advection is integrated with a flux formulation: ! implicitly, central scheme ! explicitly, flux formulation ! - Vertical viscosity is always integrated implicitly. ! !!--pseudo code and references-------------------------------------------------- ! NONE !!--declarations---------------------------------------------------------------- use precision use flow2d3d_timers use dfparall ! use globaldata ! implicit none ! type(globdat),target :: gdp ! ! The following list of pointer parameters is used to point inside the gdp structure ! include 'flow_steps_f.inc' ! real(fp) , pointer :: hdt real(fp) , pointer :: ag integer , pointer :: iro integer , pointer :: irov real(fp) , pointer :: rhow real(fp) , pointer :: vicmol character(8) , pointer :: dpsopt real(fp) , pointer :: eps integer , pointer :: lundia real(fp) , pointer :: drycrt real(fp) , pointer :: dryflc real(fp) , pointer :: gammax integer , pointer :: ibaroc logical , pointer :: cstbnd logical , pointer :: old_corio character(6) , pointer :: momsol logical , pointer :: slplim real(fp) , pointer :: rhofrac logical , pointer :: wind logical , pointer :: wave logical , pointer :: roller logical , pointer :: xbeach integer , pointer :: nh_level logical , pointer :: nonhyd real(fp) , pointer :: dzmin integer , pointer :: mfg integer , pointer :: nfg ! ! Global variables ! integer :: icx ! Increment in the X-dir., ! if icx=NMAX then computation proceeds in the X-dir., ! if icx=1 then computation proceeds in the Y-dir. integer :: icy ! Increment in the Y-dir. (see icx) integer :: j ! Begin pointer for arrays which have been transformed into 1D arrays. ! Due to the shift in the 2nd (M-)index, J = -2*NMAX + 1 integer :: kmax ! Description and declaration in esm_alloc_int.f90 integer :: nmmax ! Description and declaration in dimens.igs integer :: nmmaxj ! Description and declaration in dimens.igs integer , intent(in) :: nsrc ! Description and declaration in esm_alloc_int.f90 integer , intent(in) :: nst ! Time step number integer , dimension(7, nsrc) , intent(in) :: mnksrc ! Description and declaration in esm_alloc_int.f90 integer :: nocol ! Description and declaration in esm_alloc_int.f90 integer :: norow ! Description and declaration in esm_alloc_int.f90 integer , dimension(5, norow) :: irocol ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kcs ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kfs ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: kfsmn0 ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: kfsmx0 ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kfu ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kfumn0 ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kfumx0 ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kfvmn0 ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kfvmx0 ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kfv ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub, 0:kmax) , intent(in) :: kspu ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: kcs45 integer , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) , intent(in) :: kcscut ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub) :: kcu ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: kfsz0 ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: kfuz0 ! Description and declaration in esm_alloc_int.f90 integer , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: kfvz0 ! Description and declaration in esm_alloc_int.f90 real(fp) , dimension(4, norow) :: circ2d ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(kmax, 2, norow) :: circ3d ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, 3) :: cfurou ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(12, norow) :: crbc ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: deltau ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: dfu ! Description and declaration in esm_alloc_real.f90 real(prec) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: dps ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: dpu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: fcorio ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: fxw ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: gsqiu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: gsqs ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: gud ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: guu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: guv ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: guz ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: gvd ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: gvu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: gvv ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: gvz ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: hu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: hv ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: patm ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: pship ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: rlabda ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: s0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: taubpu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: taubsu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: tgfsep ! Water elevation induced by tide generating forces real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: tp ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: umean ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: vnu2d ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) , intent(in) :: windu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: wsu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub) :: wsbodyu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, 0:kmax) , intent(in) :: vicww ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, 0:kmax) , intent(in) :: w0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax + 2) :: vicuv ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: aak ! Internal work array, lower diagonal tridiagonal matrix, implicit coupling ! of layer velocity in (N,M,K) with layer velocity in (N,M,K-1) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: bbk ! Internal work array, coefficient layer velocity in (N,M,K) implicit part ! with layer velocity in (N+1,M,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: cck ! Internal work array, upper diagonal tridiagonal matrix, implicit coupling ! of layer velocity in (N,M,K) with layer velocity in (N,M,K+1) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: ddk ! Internal work array, diagonal space at (N,M,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: bdx ! Internal work array, implicit coupling of layer velocity in (N,M,K) ! with layer velocity in (N,M-1,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: bdy ! Internal work array, implicit coupling of layer velocity in (N,M,K) ! with layer velocity in (N-1,M,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: bux ! Internal work array, implicit coupling of layer velocity in (N,M,K) ! with layer velocity in (N,M+1,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: buy ! Internal work array, implicit coupling of layer velocity in (N,M,K) ! with layer velocity in (N+1,M,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: buxuy ! Internal work array, implicit coupling of layer velocity in (N,M,K) ! with layer velocity in (N+1,M+1,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: buxdy ! Internal work array, implicit coupling of layer velocity in (N,M,K) ! with layer velocity in (N-1,M+1,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: bdxuy ! Internal work array, implicit coupling of layer velocity in (N,M,K) ! with layer velocity in (N+1,M-1,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: bdxdy ! Internal work array, implicit coupling of layer velocity in (N,M,K) ! with layer velocity in (N-1,M-1,K) real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: diapl ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) , intent(in) :: drhodx ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) , intent(in) :: dzs0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) , intent(in) :: dzu0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) , intent(in) :: dzv0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) , intent(in) :: p0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: qxk ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: qyk ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: rnpl ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: rxx ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: rxy ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: u0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: u1 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) , intent(in) :: ubrlsu ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: ustokes ! Description and declaration in trisol.igs real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: v0 ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: uvdwk ! Internal work array for Jac.iteration real(fp) , dimension(gdp%d%nmlb:gdp%d%nmub, kmax) :: vvdwk ! Internal work array for Jac.iteration real(fp) , dimension(nsrc) , intent(in) :: disch ! Description and declaration in esm_alloc_real.f90 real(fp) , dimension(nsrc) , intent(in) :: umdis ! Description and declaration in esm_alloc_real.f90 character(1), dimension(nsrc) , intent(in) :: dismmt ! Description and declaration in esm_alloc_char.f90 ! ! Local variables ! integer :: ddb integer :: iada integer :: iadc integer :: ibf integer :: ibl integer :: ic integer :: icxy ! MAX value of ICX and ICY integer :: idifc integer :: idifd integer :: idifu integer :: isrc integer :: iter integer :: itr integer :: k integer :: kdo integer :: kenm integer :: kfad integer :: kk integer :: kkmax integer :: kmaxtl integer :: kmin integer :: kup integer :: maskval integer :: maxk integer :: mf integer :: ml integer :: n integer :: nmf integer :: nml integer :: nmsta integer :: ndm integer :: ndmd integer :: ndmu integer :: nm integer :: nmd integer :: nmdis integer :: nmu integer :: num integer :: numd integer :: numu integer :: nm_pos ! indicating the array to be exchanged has nm index at the 2nd place, e.g., dbodsd(lsedtot,nm) integer :: nhystp real(fp) :: advecx real(fp) :: advecy real(fp) :: adza real(fp) :: adzb real(fp) :: adzc real(fp) :: area real(fp) :: bdmwrp real(fp) :: bdmwrs real(fp) :: bi real(fp) :: cbot real(fp) :: cuu real(fp) :: cvv real(fp) :: dbk real(fp) :: ddx real(fp) :: ddy real(fp) :: ddza real(fp) :: ddzb real(fp) :: ddzc real(fp) :: dgeta real(fp) :: dgvnm real(fp) :: dpsmax real(fp) :: drythreshold real(fp) :: dux real(fp) :: duy real(fp) :: dz real(fp) :: dzdo real(fp) :: dzup real(fp) :: eps1 real(fp) :: facmax real(fp) :: ff real(fp) :: fxwl ! local, modified fxw real(fp) :: geta real(fp) :: getad real(fp) :: getau real(fp) :: gksi real(fp) :: gksid real(fp) :: gksiu real(fp) :: gsqi real(fp) :: hl real(fp) :: hr real(fp) :: hnm real(fp) :: drytrsh real(fp) :: hugsqs ! HU(NM/NMD) * GSQS(NM) Depending on UMDIS the HU of point NM or NMD will be used real(fp) :: qwind real(fp), external :: redvic real(fp) :: smax real(fp) :: svvv real(fp) :: thvert ! theta coefficient for vertical advection terms real(fp) :: timest real(fp) :: uuu real(fp) :: uweir real(fp) :: vih real(fp) :: viznm real(fp) :: viznmd real(fp) :: vvvc ! Tangential velocity component used in Coriolis term real(fp) :: www real(fp) :: wavg0 real(fp) :: wsbodyul ! local, modified wsbodyu real(fp) :: wsul ! local, modified wsu real(fp) :: wsumax real(fp) :: zz character(20) :: errtxt ! !! executable statements ------------------------------------------------------- ! ! eps => gdp%gdconst%eps lundia => gdp%gdinout%lundia drycrt => gdp%gdnumeco%drycrt dryflc => gdp%gdnumeco%dryflc gammax => gdp%gdnumeco%gammax hdt => gdp%gdnumeco%hdt ibaroc => gdp%gdnumeco%ibaroc cstbnd => gdp%gdnumeco%cstbnd old_corio => gdp%gdnumeco%old_corio momsol => gdp%gdnumeco%momsol slplim => gdp%gdnumeco%slplim ag => gdp%gdphysco%ag iro => gdp%gdphysco%iro irov => gdp%gdphysco%irov rhofrac => gdp%gdphysco%rhofrac rhow => gdp%gdphysco%rhow vicmol => gdp%gdphysco%vicmol wind => gdp%gdprocs%wind wave => gdp%gdprocs%wave roller => gdp%gdprocs%roller xbeach => gdp%gdprocs%xbeach dpsopt => gdp%gdnumeco%dpsopt nh_level => gdp%gdnonhyd%nh_level nonhyd => gdp%gdprocs%nonhyd dzmin => gdp%gdzmodel%dzmin mfg => gdp%gdparall%mfg nfg => gdp%gdparall%nfg ! drytrsh = drycrt drythreshold = 0.1_fp * dryflc nm_pos = 1 ! ! Flag for vertical advection set to 1.0 by default = Central implicit discretisation of ! advection in vertical (0.0 means 1st order upwind explicit) ! thvert = 1.0_fp ! ! Determine umean again based on the velocities in the whole water column ! instead of only the velocities in the top layer(s) as in z_checku ! ! needed in z_hormom_fls and in z_cucbp_nhfull for alpha-coefficient on open boundary ! umean = 0.0_fp do nm = 1, nmmax if (kfu(nm) == 1) then hnm = 0.0_fp do k = kfumn0(nm), kfumx0(nm) umean(nm) = umean(nm) + u0(nm,k)*dzu0(nm,k) hnm = hnm + dzu0(nm,k) enddo umean(nm) = umean(nm) / max(hnm, 0.01_fp) else endif enddo ! if (momsol /= 'mdue ' .or. (nonhyd .and. nh_level == nh_full) ) then ! ! Horizontal momentum using either ADI-scheme or in a fully non-hydrostatic computation ! call timer_start(timer_uzd_ini, gdp) ddb = gdp%d%ddbound icxy = max(icx, icy) if (nonhyd .and. nh_level == nh_full) then ! ! Fully non-hydrostatic mode: one whole timestep ! timest = 2.0_fp * hdt else ! ! Hydrostatic mode (ADI): half a time step ! timest = hdt endif ! ! ! factor in maximum wave force 1/4 alpha rho g gammax**2 h**2 / tp /(sqrt(g h) ! = facmax * h**1.5/tp ! facmax = 0.25_fp*sqrt(ag)*rhow*gammax**2 ! if (icx==1) then ff = -1.0_fp else ff = 1.0_fp endif kmaxtl = 0 ! ! Initialise arrays aak, bbk, cck and ddk for all (nm, k) ! aak = 0.0_fp bbk = 1.0_fp/timest cck = 0.0_fp ddk = 0.0_fp bdx = 0.0_fp bdy = 0.0_fp bux = 0.0_fp buy = 0.0_fp bdxuy= 0.0_fp bdxdy= 0.0_fp buxuy= 0.0_fp buxdy= 0.0_fp ! call timer_stop(timer_uzd_ini, gdp) ! ! Fill the array elements and the right hand side ! call timer_start(timer_uzd_rhs, gdp) do nm = 1, nmmax ndm = nm - icy nmu = nm + icx ndmu = nm + icx - icy gksi = gvu(nm) if (kfu(nm) == 1) then do k = kfumn0(nm), kfumx0(nm) if (kfuz0(nm, k)==1 .and. kcs(nm)*kcs(nmu)>0) then ! ! BAROCLINIC PRESSURE, CORIOLIS, ATMOSPHERIC PRES. and TIDE GEN. FORCE ! if (old_corio) then vvvc = 0.25_fp * (v0(ndm,k)+v0(ndmu,k)+v0(nm,k)+v0(nmu,k)) else ! ! Improved implementation Coriolis term for deep areas following ! Kleptsova, Pietrzak and Stelling, 2009. ! svvv = max(kfv(ndm) + kfv(ndmu) + kfv(nm) + kfv(nmu), 1) hl = real(dps(nm),fp) + s0(nm) hr = real(dps(nmu),fp) + s0(nmu) vvvc = ( ( v0(nm, k)*hv(nm )*kfv(nm ) & & + v0(ndm, k)*hv(ndm )*kfv(ndm ))/max(drythreshold,hl) & & + ( v0(nmu, k)*hv(nmu )*kfv(nmu ) & & + v0(ndmu,k)*hv(ndmu)*kfv(ndmu))/max(drythreshold,hr)) & & / svvv endif ddk(nm, k) = u0(nm, k)/timest & & - ag*(s0(nmu) - s0(nm))/gksi & & + ff*fcorio(nm)*vvvc & & - ag/rhow*drhodx(nm, k)*kfsz0(nm, k)*kfsz0(nmu, k) & & - (patm(nmu) - patm(nm))/(gksi*rhow) & & - (pship(nmu) - pship(nm))/(gksi*rhow) & & + ag*(tgfsep(nmu) - tgfsep(nm))/gksi & & - (p0(nmu, k) - p0(nm, k))*kfsz0(nmu,k)*kfsz0(nm,k)/(gksi*rhow) else ddk(nm, k) = u0(nm,k)/timest endif enddo endif enddo call timer_stop(timer_uzd_rhs, gdp) ! ! Horizontal advection ! call timer_start(timer_uzd_momsol, gdp) if (momsol == 'iupw ') then ! ! Horizontal advection (first order upwind implicit) ! call z_hormom_iupw(nmmax ,kmax ,icx ,icy ,kcs , & & kcscut ,kfu ,kfuz0 ,kfumn0 ,kfumx0 , & & kfvz0 ,u0 ,v0 ,guu ,gvu , & & gvd ,guz ,gsqiu ,bdx ,bux , & & bbk ,bdy ,ddk ,buy ,gdp ) elseif (momsol == 'mdui ') then ! ! Multi-direction upwind implicit advection ! call z_hormom_mdui(nmmax ,kmax ,icx , & & icy ,kcs ,kcs45 ,kcscut , & & kfu ,kfuz0 ,kfumn0 ,kfumx0 , & & kfvz0 ,kfsmn0 ,kfsmx0 , & & u0 ,v0 ,hu ,bdx ,& & bux ,bdy ,buy ,buxuy ,buxdy , & & bdxuy ,bdxdy ,bbk , & & guu ,gvv ,gvu ,guv ,gsqs , & & gud ,gvd ,guz ,gvz ,gsqiu , & & ddk ,gdp ) ! elseif (momsol == 'mdue ') then ! ! Advection determined explicitly using multi-directional upwind method ! Using the whole time step (fully non-hydrostatic mode) ! call z_hormom_mdue(nmmax ,kmax ,icx , & & icy ,kcs ,kcs45 ,kcscut , & & kfu ,kfuz0 ,kfumn0 ,kfumx0 , & & kfvz0 ,kfsmn0 ,kfsmx0 , & & u0 ,v0 ,hu , & & guu ,gvv ,gvu ,guv ,gsqs , & & gud ,gvd ,guz ,gvz ,gsqiu , & & ddk ,gdp ) ! elseif (momsol == 'finvol') then ! ! Finite volume approach for horizontal advection ! ! Temporary switch for vertical advection of horizontal momentum ! THVERT = 0 means explicit 1st order upwind vertical advection ! thvert = 0.0_fp ! call z_hormom_finvol(nmmax ,kmax ,icx ,icy ,kcs , & & kfu ,kcu ,kfv ,kfuz0 ,kfumn0 , & & kfumx0 ,kfvz0 ,kfs ,kfsz0 ,kfsmn0 , & & kfsmx0 ,u0 ,v0 ,w0 ,dzs0 , & & dzu0 ,dzv0 ,s0 ,guu ,gvv , & & gvu ,guv ,gsqs ,gud ,gvd , & & guz ,gvz ,ddk ,p0 ,gdp ) ! elseif (momsol == 'flood ') then ! ! Flooding solver for horizontal advection ! ! Temporary switch for vertical advection of horizontal momentum (PvdP 2009) ! THVERT = 0 means explicit 1st order upwind vertical advection ! !thvert = 0.0_fp ! call z_hormom_fls(nmmax ,kmax ,icx , & & icy ,kcs ,kcs45 ,kcscut , & & kfu ,kfuz0 ,kfumn0 ,kfumx0 ,kfv , & & kfvz0 ,kfsz0 ,kfsmn0 ,kfsmx0 ,kspu , & & u0 ,v0 ,hu ,kfvmn0 ,kfvmx0 , & & guu ,gvv ,gvu ,guv ,gsqs , & & gud ,gvd ,guz ,gvz ,gsqiu , & & qxk ,qyk ,dzu0 ,dzv0 ,dzs0 , & & ddk ,umean ,dps ,s0 ,uvdwk , & & vvdwk ,gdp ) ! ! Reset arrays uvdwk and vvdwk which have been used as workarrays in z_hormom_fls ! uvdwk = 0.0_fp vvdwk = 0.0_fp else ! ! No correct advection option specified: error? ! endif call timer_stop(timer_uzd_momsol, gdp) ! ! 2D Weir not included ! energy loss for CDW (remainder structure untested yet) ! call timer_start(timer_uzd_eloss, gdp) call usrbrl(icx ,icy ,nmmax ,kmax ,kfu , & & kspu ,gvu ,u0 ,v0 ,bbk , & & ubrlsu ,diapl ,rnpl ,gdp ) call timer_stop(timer_uzd_eloss, gdp) ! call timer_start(timer_uzd_stress, gdp) do nm = 1, nmmax nmu = nm + icx kmin = kfumn0(nm) if (kfu(nm) == 1 .and. kcs(nm)*kcs(nmu) > 0) then kkmax = max(kmin, kfumx0(nm)) ! ! WIND AND BOTTOM FRICTION ! qwind = 0.0_fp bdmwrp = 0.0_fp bdmwrs = 0.0_fp ! ! BOTTOM STRESS DUE TO FLOW AND WAVES ! ! Special measures for smooth inundation ! ! Estimate velocity on the basis of local equilibrium by solving u(nm) ! with an explicit procedure. So that high velocities can be avoided ! during flooding (kfu=1 and u=0.) in regions with steep topography. ! Velocity is estimated assuming critical flow over a short-crested ! weir. ! Gates are excluded ! if (dpsopt == 'dp' .or. slplim) then if (kfu(nm) == 1 .and. abs(u0(nm,kmin)) <= 1.0e-15_fp .and. kspu(nm, 0) /= 4 .and. kspu(nm, 0) /= 10) then ! ! cfurou(nm,1) contains u/u* ! uweir = sqrt( 2.0_fp/3.0_fp*ag*max(hu(nm),drytrsh) ) taubpu(nm) = uweir / (cfurou(nm,1)**2.0_fp) endif endif ! ! Slope correction for steep slopes ! if (slplim) then nmu = nm + icx dpsmax = max(-dps(nm),-dps(nmu)) if (s0(nm) < dpsmax) then do k = kfumn0(nm), kfumx0(nm) ddk(nm,k) = ddk(nm,k) - ag*(s0(nm)-dpsmax)/gvu(nm) enddo elseif (s0(nmu) < dpsmax) then do k = kfumn0(nm), kfumx0(nm) ddk(nm,k) = ddk(nm,k) + ag*(s0(nmu)-dpsmax)/gvu(nm) enddo endif endif ! ! End of special measures for smooth inundation ! cbot = taubpu(nm) qwind = windu(nm) / max(dzu0(nm, kkmax),drytrsh) bdmwrp = cbot / max(dzu0(nm, kmin),drytrsh) bdmwrs = taubsu(nm) / max(dzu0(nm, kmin),drytrsh) bbk(nm, kmin) = bbk(nm, kmin) + bdmwrp ddk(nm, kkmax) = ddk(nm, kkmax) - qwind/rhow ddk(nm, kmin) = ddk(nm, kmin) + bdmwrs ! ! WAVE FORCE AT SURFACE ! ! ! physical limit to wsu ! if (wave) then wsumax = facmax*hu(nm)**(1.5)/max(0.1_fp, 0.5_fp*(tp(nm)+tp(nmu))) wsul = sign(min(abs(wsu(nm)), wsumax), wsu(nm)) ! ddk(nm, kkmax) = ddk(nm, kkmax) + wsul/(rhow*max(dzu0(nm, kkmax),drytrsh)) ! ! WAVE INDUCED BODY FORCE ! if (roller .or. xbeach) then fxwl = sign(min(abs(fxw(nm)), wsumax), fxw(nm)) do k = kfumn0(nm), kfumx0(nm) ddk(nm, k) = ddk(nm, k) + fxwl/(rhow*hu(nm)) enddo else wsbodyul = sign(min(abs(wsbodyu(nm)), wsumax), wsbodyu(nm)) do k = kfumn0(nm), kfumx0(nm) ddk(nm, k) = ddk(nm, k) + wsbodyul/(rhow*hu(nm)) enddo endif endif endif enddo call timer_stop(timer_uzd_stress, gdp) ! ! In case of 3D waves: ! Added shear stress in wave boundary layer due to streaming ! call timer_start(timer_uzd_shrwav, gdp) if (wave .and. kmax>1) then call z_shrwav(nmmax ,kmax ,icx ,dfu ,deltau , & & tp ,rlabda ,hu ,kfu ,ddk , & & kfumn0 ,kfumx0 ,dzu0 ,gdp ) endif call timer_stop(timer_uzd_shrwav, gdp) ! ! DISCHARGE ADDITION OF MOMENTUM ! call timer_start(timer_uzd_dismmt, gdp) do isrc = 1, nsrc nm = (mnksrc(2, isrc) + ddb) + ((mnksrc(1, isrc) - 1) + ddb)*icxy nmd = nm - icx if (dismmt(isrc) == 'Y' .and. disch(isrc) > 0.0_fp) then if (umdis(isrc) >= 0.0_fp) then nmdis = nm hugsqs = hu(nm)*gsqs(nm) else nmdis = nmd hugsqs = hu(nmd)*gsqs(nm) endif kk = mnksrc(3, isrc) if (kfu(nmdis) == 1) then if (kk == 0) then do k = 1, kmax bbk(nmdis, k) = bbk(nmdis, k) + disch(isrc)/hugsqs ddk(nmdis, k) = ddk(nmdis, k) + umdis(isrc)*disch(isrc) & & /hugsqs enddo else bbk(nmdis, kk) = bbk(nmdis, kk) + disch(isrc) & & /(dzu0(nmdis, kk)*gsqs(nm)) ddk(nmdis, kk) = ddk(nmdis, kk) + umdis(isrc)*disch(isrc) & & /(dzu0(nmdis, kk)*gsqs(nm)) endif endif endif enddo call timer_stop(timer_uzd_dismmt, gdp) ! ! VERTICAL ADVECTION AND VISCOSITY, IMPLICIT ! call timer_start(timer_uzd_advdiffv, gdp) do nm = 1, nmmax if (kfu(nm)==1 .and. kfumx0(nm)>kfumn0(nm)) then kmaxtl = 1 nmu = nm + icx do k = kfumn0(nm), kfumx0(nm) if (kfuz0(nm, k) == 1) then kfad = 0 kdo = k - 1 kup = k + 1 if (k == kfumn0(nm)) then kfad = 1 kdo = k endif if (k == kfumx0(nm)) then kfad = -1 kup = k endif ! ! Free slip between open and closed layers of a gate ! iada = 1 iadc = 1 if (kspu(nm, 0) == 4 .or. kspu(nm, 0) == 10) then iada = max(1 - (kspu(nm, kdo) + kspu(nm, k)), 0) iadc = max(1 - (kspu(nm, k) + kspu(nm, kup)), 0) endif ! dzup = dzu0(nm, k) + dzu0(nm, kup) dzdo = dzu0(nm, k) + dzu0(nm, kdo) ! ! ADVECTION IN VERTICAL DIRECTION; W*DU/DZ ! ! Is this correct at the surface when there are no neighbours? ! if (thvert == 1.0_fp) then ! ! Central implicit ! maskval = min(kcs(nm), 2)*min(kcs(nmu), 2) www = 0.25_fp*abs(maskval)*(w0(nm, k - 1) + w0(nm, k) + w0(nmu, k - 1) + w0(nmu, k)) if (www < 0.0_fp) then adza = -2.0_fp*www/(dzup + dzdo)*(1 - abs(kfad)) adzc = 2.0_fp*www/(dzup + dzdo)*(1 - abs(kfad)) + kfad*(1 + kfad)*www/dzup else adza = -2.0_fp*www/(dzup + dzdo)*(1 - abs(kfad)) + abs(kfad)*( - 1 + kfad)*www/dzdo adzc = 2.0_fp*www/(dzup + dzdo)*(1 - abs(kfad)) endif adza = iada*adza adzc = iadc*adzc adzb = -adza - adzc else ! ! First order upwind explicit ! adza = 0.0_fp adzc = 0.0_fp adzb = 0.0_fp ! ! downwards face ! if (k > kfumn0(nm)) then area = guu(nm) * gvu(nm) wavg0 = 0.5_fp * (w0(nm,k-1)+w0(nmu,k-1)) if (wavg0 > 0.0_fp) then ddk(nm,k) = ddk(nm,k) + area*wavg0*u0(nm,k-1) else ddk(nm,k) = ddk(nm,k) + area*wavg0*u0(nm,k) endif endif ! ! upwards face ! if (k < kfumx0(nm)) then area = guu(nm) * gvu(nm) wavg0 = 0.5_fp * (w0(nm,k)+w0(nmu,k)) if (wavg0 > 0.0_fp) then ddk(nm,k) = ddk(nm,k) - area*wavg0*u0(nm,k) else ddk(nm,k) = ddk(nm,k) - area*wavg0*u0(nm,k+1) endif endif endif ! ! Subtitution in coefficients ! aak (nm, k) = aak(nm, k) + adza bbk (nm, k) = bbk(nm, k) + adzb cck (nm, k) = cck(nm, k) + adzc ! ! VERTICAL VISCOSITY ! ! ! viznmd calculation ! restriction is moved from Z_TURCLO to here ! viznmd = 0.25_fp * (2 - kfad*(1 + kfad)) & & * (2.0_fp*vicmol + redvic(vicww(nm , kdo), gdp) & & + redvic(vicww(nmu, kdo), gdp)) ! ! viznm calculation ! restriction is moved from Z_TURCLO to here ! viznm = 0.25_fp * (2 + kfad*(1 - kfad)) & & * (2.0_fp*vicmol + redvic(vicww(nm , k), gdp) & & + redvic(vicww(nmu, k), gdp)) dz = dzu0(nm, k) ! ddza = iada * 2.0_fp * viznmd / (dzdo*dz) ddzc = iadc * 2.0_fp * viznm / (dzup*dz) ddzb = -ddza - ddzc ! ! subtitution in coefficients ! aak(nm, k) = aak(nm, k) - ddza bbk(nm, k) = bbk(nm, k) - ddzb cck(nm, k) = cck(nm, k) - ddzc ! ! Effect of waves, due to Stokes drift ! ddk(nm, k) = ddk(nm,k) - ( ddzc*(ustokes(nm,kup)-ustokes(nm,k )) - & & ddza*(ustokes(nm,k )-ustokes(nm,kdo)) ) endif enddo endif enddo call timer_stop(timer_uzd_advdiffv, gdp) ! ! HORIZONTAL VISCOSITY ! call timer_start(timer_uzd_vih, gdp) if (irov>0) then ! ! Stresses due to rigid walls ! implemented fully explicit ! call z_vihrov(j ,nmmaxj ,nmmax ,kmax ,icx , & & icy ,kcs45 ,kcs ,kfu ,kfv , & & kfs ,u0 ,v0 ,vicuv ,vnu2d , & & gud ,guu ,gvd ,gvu ,gvz , & & ddk ,rxx ,rxy ,kfuz0 ,kfvz0 , & & kfsz0 ,kfumn0 ,kfumx0 ,gdp ) ! ! for Crank Nicolson method: is computed here (implicitly for the whole time step) ! for fractional step method: is computed in z_cucnp (explicitly for the whole time step) ! else do nm = 1, nmmax nmd = nm - icx ndm = nm - icy ndmd = nm - icx - icy nmu = nm + icx num = nm + icy numu = nm + icx + icy ndmu = nm + icx - icy numd = nm - icx + icy do k = kfumn0(nm), kfumx0(nm) if (kfu(nm) == 1 .and. kcs(nm) > 0 .and. kcs(nmu) > 0) then if (kfuz0(nm, k) == 1) then gksid = gvz(nm) gksiu = gvz(nmu) gksi = gvu(nm) getad = gud(ndm) getau = gud(nm) geta = guu(nm) idifd = kfvz0(ndm, k)*kfvz0(ndmu, k)*kfuz0(ndm, k) idifu = kfvz0(nm , k)*kfvz0(nmu , k)*kfuz0(num, k) idifc = abs(2 - abs(kcs(nm)))*abs(2 - abs(kcs(nmu))) ! ! EDDY VISCOSITY FOR KMAX = 1, USING LAPLACE OPERATOR ! (2*VIH*(D2U/DX2 + D2U/DY2) ! Vih multiplied by 1.0 (instead of 0.5) because it is included here for the whole time step ! vih = vicuv(nm, k) + vicuv(nmu, k) + vnu2d(nm) + vnu2d(ndm) bbk(nm, k) = bbk(nm, k) & & + 2.0_fp*vih/(gksid*gksiu)*idifc & & + vih/(getau*geta) *idifu & & + vih/(getad*geta) *idifd bux(nm, k) = bux(nm, k) - vih/(gksiu*gksi)*idifc bdx(nm, k) = bdx(nm, k) - vih/(gksid*gksi)*idifc buy(nm, k) = buy(nm, k) - vih/(getau*geta)*idifu bdy(nm, k) = bdy(nm, k) - vih/(getad*geta)*idifd endif endif enddo enddo ! endif call timer_stop(timer_uzd_vih, gdp) ! ! BOUNDARY CONDITIONS ! call timer_start(timer_uzd_bouncond, gdp) ! ! For fully non-hydrostatic simulations the boundary conditions are handled in z_cucbp_nhfull ! if (nonhyd .and. nh_level == nh_full) then call z_cucbp_nhfull(kmax ,norow ,icx , & & icy ,irocol ,kcs ,kfu , & & kfumn0 ,kfumx0 ,s0 ,u0 , & & hu ,umean ,guu ,gvu , & & dzu0 ,circ2d ,circ3d ,dpu , & & aak ,bbk ,cck ,ddk , & & crbc ,gdp ) else ! do ic = 1, norow ! n = irocol(1, ic) mf = irocol(2, ic) - 1 ml = irocol(3, ic) ibf = irocol(4, ic) ibl = irocol(5, ic) nmf = (n + ddb)*icy + (mf + ddb)*icx - icxy nml = (n + ddb)*icy + (ml + ddb)*icx - icxy ! ! IMPLEMENTATION OF BOUNDARY CONDITIONS ! if (kcu(nmf)==1 .and. kfu(nmf)==1) then if (ibf==3 .or. ibf==5 .or. ibf==6 .or. ibf==7) then do k = kfumn0(nmf), kfumx0(nmf) aak (nmf, k) = 0.0_fp bbk (nmf, k) = 1.0_fp bux (nmf, k) = 0.0_fp bdx (nmf, k) = 0.0_fp buy (nmf, k) = 0.0_fp bdy (nmf, k) = 0.0_fp buxuy(nmf, k) = 0.0_fp bdxuy(nmf, k) = 0.0_fp buxdy(nmf, k) = 0.0_fp bdxdy(nmf, k) = 0.0_fp cck (nmf, k) = 0.0_fp ddk (nmf, k) = u0(nmf, k) enddo endif endif if (kcu(nml)==1 .and. kfu(nml)==1) then if (ibl==3 .or. ibl==5 .or. ibl==6 .or. ibl==7) then do k = kfumn0(nml), kfumx0(nml) aak (nml, k) = 0.0_fp bbk (nml, k) = 1.0_fp bux (nml, k) = 0.0_fp bdx (nml, k) = 0.0_fp buy (nml, k) = 0.0_fp bdy (nml, k) = 0.0_fp buxuy(nml, k) = 0.0_fp bdxuy(nml, k) = 0.0_fp buxdy(nml, k) = 0.0_fp bdxdy(nml, k) = 0.0_fp cck (nml, k) = 0.0_fp ddk (nml, k) = u0(nml, k) enddo endif endif enddo endif call timer_stop(timer_uzd_bouncond, gdp) ! ! left hand-side is now set by Delft3D-FLOW instead of the mapper ! call timer_start(timer_uzd_lhs, gdp) do nm = 1, nmmax if (kcu(nm)==3 .or. kcu(nm)==-1) then do k = 1, kmax aak(nm,k) = 0.0_fp bbk(nm,k) = 1.0_fp cck(nm,k) = 0.0_fp ddk(nm,k) = u0(nm,k) enddo endif enddo call timer_stop(timer_uzd_lhs, gdp) ! ! Domain decomposition: ! end of "build_system_for_velocity", ! mapper can build the coupling equations ! call timer_start(timer_uzd_rest, gdp) if (icx == 1) then ! ! D3dFlowMap_Build_V: poke the coupling equations into system ! nhystp = nxtstp(d3dflow_build_v, gdp) else ! ! D3dFlowMap_Build_U: poke the coupling equations into system ! nhystp = nxtstp(d3dflow_build_u, gdp) endif call timer_stop(timer_uzd_rest, gdp) ! uvdwk = 0.0_fp vvdwk = 0.0_fp ! !***SCALE ROWS OF MATRIX/RIGHT HAND SIDE VECTOR ! call timer_start(timer_uzd_rowsc, gdp) do nm = 1, nmmax if (kfu(nm) == 1) then do k = kfumn0(nm), kfumx0(nm) bi = 1.0_fp / bbk(nm, k) aak (nm, k) = aak (nm, k) * bi bbk (nm, k) = 1.0_fp bux (nm, k) = bux (nm, k) * bi bdx (nm, k) = bdx (nm, k) * bi buy (nm, k) = buy (nm, k) * bi bdy (nm, k) = bdy (nm, k) * bi buxuy(nm, k) = buxuy(nm, k) * bi bdxuy(nm, k) = bdxuy(nm, k) * bi buxdy(nm, k) = buxdy(nm, k) * bi bdxdy(nm, k) = bdxdy(nm, k) * bi cck (nm, k) = cck (nm, k) * bi ddk (nm, k) = ddk (nm, k) * bi enddo endif enddo call timer_stop(timer_uzd_rowsc, gdp) ! !***SOLUTION PROCEDURE SYSTEM OF EQUATIONS ! call timer_start(timer_uzd_solve1, gdp) ! ! System of equations is reduced for all points ! right hand side is reduced within iterative loops ! ! Division by the pivot for k=1 is not needed anymore ! because of row scaling ! do nm = 1, nmmax if (kfu(nm) == 1) then do k = kfumn0(nm)+1, kfumx0(nm) bi = 1.0_fp/(bbk(nm, k) - aak(nm, k)*cck(nm, k - 1)) bbk(nm, k) = bi cck(nm, k) = cck(nm, k)*bi enddo endif enddo call timer_stop(timer_uzd_solve1, gdp) ! ! ITERATION LOOP ! call timer_start(timer_uzd_solve2, gdp) iter = 0 do nm = 1, nmmax if (kfu(nm) == 1) then do k = 1, kmax u1 (nm, k) = u0(nm, k) uvdwk(nm, k) = u0(nm, k) enddo endif enddo call timer_stop(timer_uzd_solve2, gdp) ! ! ensure that loop starts at point of correct color in own subdomain ! if (mod(mfg+nfg,2) == 1) then ! ! red points ! nmsta = 1 else ! ! black points ! nmsta = 2 endif ! ! Domain decomposition: ! resume point for next solve ! 222 continue gdp%dd%uzditer = gdp%dd%uzditer + 1 ! ! End Domain decomposition addition ! itr = 1 loop_iteration: do while (itr == 1 .and. iter < 50) iter = iter + 1 ! ! ITERATIVE SOLUTION METHOD USING CHECKERBOARD JACOBI ! IN HORIZONTAL DIRECTION ! ATTENTION : AN ODD NUMBER OF GRIDPOINTS IN V-DIRECTION ! ( NMAX ) IS ASSUMED!!!!! ! itr = 0 if (icx == 1) then call timer_start(timer_uzd_solve3u, gdp) else call timer_start(timer_uzd_solve5v, gdp) endif ! ! loop starts at red or black point depending on own subdomain ! nmsta = 3 - nmsta ! do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumn0(nm), kfumx0(nm) ! ! COMPUTE RIGHT HAND SIDE ! uvdwk(nm, k) = ddk(nm,k) & & - bdx (nm,k)*u1(nm-icx ,k) & & - bdy (nm,k)*u1(nm-icy ,k) & & - buy (nm,k)*u1(nm+icy ,k) & & - bux (nm,k)*u1(nm+icx ,k) & & - bdxdy(nm,k)*u1(nm-icx-icy,k) & & - bdxuy(nm,k)*u1(nm-icx+icy,k) & & - buxuy(nm,k)*u1(nm+icx+icy,k) & & - buxdy(nm,k)*u1(nm+icx-icy,k) enddo endif enddo if (icx == 1) then call timer_stop(timer_uzd_solve3u, gdp) call timer_start(timer_uzd_solve4u, gdp) else call timer_stop(timer_uzd_solve5v, gdp) call timer_start(timer_uzd_solve6v, gdp) endif ! do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then kmin = kfumn0(nm) vvdwk(nm, kmin) = uvdwk(nm, kmin)*bbk(nm, kmin) endif enddo do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumn0(nm)+1, kfumx0(nm) vvdwk(nm, k) = (uvdwk(nm, k) - aak(nm, k)*vvdwk(nm, k - 1))*bbk(nm, k) enddo endif enddo ! do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumx0(nm)-1, kfumn0(nm), -1 vvdwk(nm, k) = vvdwk(nm, k) - cck(nm, k)*vvdwk(nm, k + 1) enddo endif enddo ! ! CHECK FOR CONVERGENCE ! loop_nm_1: do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumn0(nm), kfumx0(nm) if (abs(vvdwk(nm,k)-u1(nm,k)) > eps) then itr = 1 exit loop_nm_1 endif enddo endif enddo loop_nm_1 if (icx == 1) then call timer_stop(timer_uzd_solve4u, gdp) call timer_start(timer_uzd_solve3u, gdp) else call timer_stop(timer_uzd_solve6v, gdp) call timer_start(timer_uzd_solve5v, gdp) endif ! do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumn0(nm), kfumx0(nm) u1(nm, k) = vvdwk(nm, k) enddo endif enddo ! ! exchange u1 with neighbours for parallel runs ! call dfexchg ( u1, 1, kmax, dfloat, nm_pos, gdp ) ! ! ! loop starts at point of other color now (black respectively red) ! nmsta = 3 - nmsta ! do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumn0(nm), kfumx0(nm) ! ! COMPUTE RIGHT HAND SIDE ! uvdwk(nm, k) = ddk(nm,k) & & - bdx (nm,k)*u1(nm-icx ,k) & & - bdy (nm,k)*u1(nm-icy ,k) & & - buy (nm,k)*u1(nm+icy ,k) & & - bux (nm,k)*u1(nm+icx ,k) & & - bdxdy(nm,k)*u1(nm-icx-icy,k) & & - bdxuy(nm,k)*u1(nm-icx+icy,k) & & - buxuy(nm,k)*u1(nm+icx+icy,k) & & - buxdy(nm,k)*u1(nm+icx-icy,k) enddo endif enddo ! if (icx == 1) then call timer_stop(timer_uzd_solve3u, gdp) call timer_start(timer_uzd_solve4u, gdp) else call timer_stop(timer_uzd_solve5v, gdp) call timer_start(timer_uzd_solve6v, gdp) endif ! do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then kmin = kfumn0(nm) vvdwk(nm,kmin) = uvdwk(nm,kmin) * bbk(nm, kmin) endif enddo do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumn0(nm)+1, kfumx0(nm) vvdwk(nm,k) = (uvdwk(nm,k) - aak(nm,k)*vvdwk(nm,k-1)) * bbk(nm,k) enddo endif enddo do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumx0(nm)-1, kfumn0(nm), -1 vvdwk(nm,k) = vvdwk(nm,k) - cck(nm,k)*vvdwk(nm,k+1) enddo endif enddo ! ! CHECK FOR CONVERGENCE ! loop_nm_2: do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumn0(nm), kfumx0(nm) if (abs(vvdwk(nm,k)-u1(nm,k)) > eps) then itr = 1 exit loop_nm_2 endif enddo endif enddo loop_nm_2 ! if (icx == 1) then call timer_stop(timer_uzd_solve4u, gdp) else call timer_stop(timer_uzd_solve6v, gdp) endif ! do nm = nmsta, nmmax, 2 if (kfu(nm) == 1) then do k = kfumn0(nm), kfumx0(nm) u1(nm, k) = vvdwk(nm, k) enddo endif enddo ! ! exchange u1 with neighbours for parallel runs ! call dfexchg ( u1, 1, kmax, dfloat, nm_pos, gdp ) ! ! set right-hand side to u1 in the halo area so that convergence check can be done safely ! do nm = 1, nmmax if ( kcu(nm) == -1 ) then do k = kfumn0(nm), kfumx0(nm) ddk(nm,k) = u1(nm,k) enddo endif enddo ! ! ! determine global maximum of 'itr' over all nodes ! Note: this enables to synchronize the iteration process ! call dfreduce_gdp( itr, 1, dfint, dfmax, gdp ) enddo loop_iteration ! if (gdp%gdflwpar%flwoutput%iteroutputsteps >= gdp%gdinttim%ntstep) then write (lundia, '(2(a,i0))') 'z_uzd (ntstep ,iter):',gdp%gdinttim%ntstep, ' ',iter endif if (iter >= 50) then write (errtxt, '(i0)') nst call prterr(lundia ,'S205' ,trim(errtxt) ) endif ! ! Domain decomposition: ! end "solve_system_for_velocity" ! if (icx == 1) then ! ! D3dFlowMap_Check_V: Check for convergence ! nhystp = nxtstp(d3dflow_solve_v, gdp) if (nhystp == d3dflow_solve_v) goto 222 else ! ! D3dFlowMap_Check_U: Check for convergence ! nhystp = nxtstp(d3dflow_solve_u, gdp) if (nhystp == d3dflow_solve_u) goto 222 endif ! ! End Domain decomposition addition ! ! ! DEFINE NEW DEPTH AVERAGED VELOCITY ! call timer_start(timer_uzd_umean, gdp) ! ! Initialise umean for all (nm) ! umean = 0.0 ! do nm = 1, nmmax if (kfu(nm) == 1) then hnm = 0.0_fp do k = kfumn0(nm), kfumx0(nm) umean(nm) = umean(nm) + dzu0(nm,k)*u1(nm, k) hnm = hnm + dzu0(nm,k) enddo umean(nm) = umean(nm) / hnm endif enddo call timer_stop(timer_uzd_umean, gdp) ! else ! if (momsol == 'mdue ') then ! ! Time integration following the original approach of Bijvelds and Stelling ! with a dummy UZD (velocities are computed in Z_SUD/Z_CUCNP and frozen ! for the second half timestep. This is done in this part. ! call timer_start(timer_uzd_ini, gdp) ! ! Initialise aak, bbk and cck for all (nm, k) ! aak = 0.0 bbk = 1.0 cck = 0.0 ! call timer_stop(timer_uzd_ini, gdp) call timer_start(timer_uzd_rhs, gdp) ! do nm = 1, nmmax if (kfu(nm) == 1) then do k = 1, kmax ddk(nm, k) = u0(nm, k) enddo endif enddo call timer_stop(timer_uzd_rhs, gdp) ! ! End of "build_system_for_velocity", ! mapper can build the coupling equations ! call timer_start(timer_uzd_rest, gdp) if (icx==1) then ! ! D3dFlowMap_Build_V: poke the coupling equations into system ! nhystp = nxtstp(d3dflow_build_v, gdp) ! else ! ! D3dFlowMap_Build_U: poke the coupling equations into system ! nhystp = nxtstp(d3dflow_build_u, gdp) ! endif call timer_stop(timer_uzd_rest, gdp) ! ! Resume point for next solve ! 333 continue gdp%dd%uzditer = gdp%dd%uzditer + 1 ! if (icx==1) then ! ! D3dFlowMap_Check_V: Check for convergence ! nhystp = nxtstp(d3dflow_solve_v, gdp) if (nhystp==d3dflow_solve_v) goto 333 else ! ! D3dFlowMap_Check_U: Check for convergence ! nhystp = nxtstp(d3dflow_solve_u, gdp) ! if (nhystp==d3dflow_solve_u) goto 333 endif endif end subroutine z_uzd
\name{hc_polygon-GenomicHilbertCurve-method} \alias{hc_polygon,GenomicHilbertCurve-method} \title{ Add text to Hilbert curve } \description{ Add text to Hilbert curve } \usage{ \S4method{hc_polygon}{GenomicHilbertCurve}(object, gr, gp = gpar(), end_type = c("average", "expanding", "shrinking")) } \arguments{ \item{object}{a \code{\link{GenomicHilbertCurve-class}} object} \item{gr}{a \code{\link[GenomicRanges:GRanges-class]{GRanges}} object which contains the genomic regions to be mapped to the curve} \item{gp}{pass to \code{\link{hc_polygon,HilbertCurve-method}}} \item{end_type}{pass to \code{\link{hc_polygon,HilbertCurve-method}}} } \details{ It is basically a wrapper of \code{\link{hc_polygon,HilbertCurve-method}}. } \value{ Refer to \code{\link{hc_polygon,HilbertCurve-method}} } \author{ Zuguang Gu <[email protected]> } \examples{ require(circlize) require(GenomicRanges) bed = generateRandomBed(nr = 20) gr = GRanges(seqnames = bed[[1]], ranges = IRanges(bed[[2]], bed[[3]])) hc = GenomicHilbertCurve() hc_polygon(hc, gr) }
classdef factorize %FACTORIZE an object-oriented method for solving linear systems % and least-squares problems, and for representing operations with the % inverse of a square matrix or the pseudo-inverse of a rectangular matrix. % % F = factorize(A) returns an object F that holds the factorization of a % non-singular matrix A. x=F\b then solves a linear system or a % least-squares problem. S=inverse(F) or S=inverse(A) returns a factorized % representation of the inverse of A so that inverse(A)*b is mathematically % equivalent to inv(A)*b, but the former does not actually compute the % inverse of A. % % Example % % F = factorize(A) ; % LU, QR, or Cholesky factorization of A % x = F\b ; % solve A*x=b; same as x=A\b % S = inverse (F) ; % S represents the factorization of inv(A) % x = S*b ; % same as x = A\b. % S = A-B*inverse(D)*C % efficiently computes the Schur complement % S = A-B*inv(D)*C % bad method for computing the Schur complement % S = inverse(A) ; S(:,1) % compute just the first column of inv(A), % % without computing inv(A) % % If A is square, symmetric (Hermitian for the complex case), and has a % real positive diagonal, then use F=factorize(A,1). If you know % otherwise, use F=factorize(A,0). Using this option improves performance, % since otherwise this condition must be checked to choose between a % Cholesky or LU factorization. The option is ignored if A is rectangular. % % For more details, type "help factorize1". % For a demo type "fdemo" or see the html/ directory. % % See also inverse, factorize1, mldivide, mrdivide, inv, pinv, linsolve % Copyright 2009, Timothy A. Davis, University of Florida properties (SetAccess = protected) % The factorize object holds a QR, LU, Cholesky factorization: A = [ ] ; % a copy of the input matrix L = [ ] ; % lower-triangular factor for LU and Cholesky U = [ ] ; % upper-triangular factor for LU Q = [ ] ; % Q factor for dense QR R = [ ] ; % R factor for QR p = [ ] ; % sparse row permutation matrix q = [ ] ; % sparse column permutation matrix is_inverse = false ; % F represents the factorization of A or inv(A) kind = 0 ; % F is one of 8 kinds of factorizations end methods function F = factorize (A,try_chol) % factorize constructor: compute a factorization of A if (ndims (A) > 2) error ('Matrix must be 2D.') ; end [m n] = size (A) ; F.A = A ; if (m > n) % QR factorization of A if (issparse (A)) % Q-less econonmy sparse QR: (A*q)'*(A*q) = R'*R q = sparse (colamd (A), 1:n, 1) ; R = qr (A*q, 0) ; F.q = q ; F.kind = 1 ; else % dense economy QR factorization: A = Q*R [Q R] = qr (A,0) ; F.Q = Q ; F.kind = 2 ; end ok = (nnz (diag (R)) == n) ; F.R = R ; elseif (m < n) % QR factorization of A' if (issparse (A)) % Q-less economy sparse QR: (p*A)*(p*A)' = R'*R C = A' ; p = sparse (1:m, colamd (C), 1) ; R = qr (C*p', 0) ; F.p = p ; F.kind = 3 ; else % dense economy LQ factorization: A' = Q*R [Q R] = qr (A',0) ; F.Q = Q ; F.kind = 4 ; end ok = (nnz (diag (R)) == m) ; F.R = R ; else % Cholesky or LU factorization of A g = 1 ; if (nargin == 1) % This is an expensive test, so skip it if the caller % already knows the matrix is a candidate for Cholesky. d = diag (A) ; try_chol = (all (d > 0) && nnz (imag (d)) == 0 && ... nnz (A-A') == 0) ; end if (try_chol) if (issparse (A)) % sparse Cholesky factorization: q'*A*q = L*L' [L g q] = chol (A, 'lower') ; else % dense Cholesky factorization: A = R'*R [R g] = chol (A) ; end end % do an LU factorization if Cholesky failed or was skipped ok = (g == 0) ; if (ok) % Cholesky was successful if (issparse (A)) F.L = L ; F.q = q ; F.kind = 5 ; else F.R = R ; F.kind = 6 ; end else % need an LU factorization if (issparse (A)) % sparse LU factorization: p*A*q = L*U [L U p q] = lu (A) ; F.q = q ; F.kind = 7 ; else % dense LU factorization: p*A = L*U [L U p] = lu (A, 'vector') ; p = sparse (1:n, p, 1) ; F.kind = 8 ; end F.L = L ; F.U = U ; F.p = p ; ok = (nnz (diag (U)) == n) ; end end if (~ok) error ('Matrix is rank deficient.') ; end end end end
[STATEMENT] lemma id_int_const[id_rules]: "(PR_CONST (a::int)) ::\<^sub>i TYPE(int)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. PR_CONST a ::\<^sub>i TYPE(int) [PROOF STEP] by simp
#pragma once #include <string> #include <vector> #include <boost/property_tree/ptree.hpp> namespace cv { class Mat; } class DataIO { public: /** * Format the json string and output to file. */ static void write2json(const std::string& filename, const boost::property_tree::ptree& root); }; // load and save depth map class DepthmapIO : public DataIO { public: static void save(const std::string& filepath, const cv::Mat& depth_mat); static void load(const std::string& filepath, cv::Mat& depth_mat); }; // load and save pixel corresponding ship class PixelsCorrIO : public DataIO { public: static void save(const std::string& file_path, const std::string& src_filename, const std::string& tar_filename, const cv::Mat& pixles_corresponding); static void load(const std::string& file_path, std::string& src_filename, std::string& tar_filename, cv::Mat& pixles_corresponding); };
[STATEMENT] lemma singleton_bot: "singleton default \<bottom> = default ()" for default [PROOF STATE] proof (prove) goal (1 subgoal): 1. singleton default \<bottom> = default () [PROOF STEP] by (auto simp add: bot_pred_def intro: singleton_undefinedI)
[STATEMENT] lemma singleton_bot: "singleton default \<bottom> = default ()" for default [PROOF STATE] proof (prove) goal (1 subgoal): 1. singleton default \<bottom> = default () [PROOF STEP] by (auto simp add: bot_pred_def intro: singleton_undefinedI)
\section{Installation} ADCL follows the regular UNIX/LINUX software configuration and installation model, requiring a sequence of \begin{verbatim} configure make make install \end{verbatim} \subsection{Prerequisites} ADCL requires a working installation of an MPI library, complying to the MPI-2 standard. ADCL has been tested with a large number of MPI libraries and on multiple platforms, including Open MPI, MPICH, MVAPICH, IBM MPI, and Cray MPI. For the non-blocking operations supported by ADCL, a valid and working installation of the libNBC library has to be provided, compiled with the same MPI library as the one being used for ADCL. The GNU scientific library is used for some clusternig algorithm, and can optionally be provided. The PAPI hardware performance counter library can be utilized by ADCL for high resolution timers. \subsection{Configure Options} ADCL can be customized with a number of options, which can be devided into three sections: enabling or disabling certain features, providing additional libraries (e.g. libNBC, GSL, PAPI) to enabel certain features, and change the default behavior of ADCL. The following is a list of all configure options supported by ADCL. \small \begin{verbatim} Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print `checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for `--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/home/gabriel/ADCL] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, `make install' will install all the files in `/home/gabriel/ADCL/bin', `/home/gabriel/ADCL/lib' etc. You can specify an installation prefix other than `/home/gabriel/ADCL' using `--prefix', for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] --target=TARGET configure for building compilers for TARGET [HOST] Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-gsl enable the usage of gsl (default=no) --enable-libnbc enable the usage of libNBC (default=no) --enable-onesided enable the usage of one-sided communication (default=no) --disable-printf-tofile dump printf statements to a file (default=yes) --enable-userlevel-timings disable ADCL internal timing routines (default=no) --enable-knowledge-tofile dump the ADCL knowledge to an XML file (default=no) --disable-saving-request-winner save the winner of a request (default=yes) --enable-smooth-hist smooth the history data (default=no) --enable-dummy-mpi enable the usage of dummy-mpi (default=no) --enable-cluster-classify enable the usage of clustering and classification with SVM for historic learning (default=no) --disable-fortran compile fortran wrappers (default=yes) Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-adcl-dir=dir Main ADCL directory (default=$PWD) --with-adcl-inc-dir=dir ADCL include directory (default=ADCL_DIR/include) --with-adcl-lib-dir=dir ADCL lib directory (default=ADCL_DIR/lib) --with-adcl-bin-dir=dir ADCL bin directory (default=ADCL_DIR/bin) --with-adcl-lib-name=name Name of the ADCL library (default=libadcl.a) --with-adcl-timer=timer Timer options (default=TIMER_GETTIMEOFDAY) --with-mpi-dir=dir Installation directory of MPI --with-mpi-inc-dir=dir Include directory of MPI (default=MPI_DIR/include) --with-mpi-lib-dir=dir Library directory of MPI (default=MPI_DIR/lib) --with-mpi-bin-dir=dir Bin directory of MPI (default=MPI_DIR/bin) --with-mpi-cc=mpicc MPI C compiler wrapper (default=mpicc) --with-mpi-cxx=mpicxx MPI C++ compiler wrapper (default=mpiCC) --with-mpi-f90=mpif90 MPI f90 compiler wrapper (default=mpif90) --with-papi-dir=dir Main PAPI directory (default=$PWD) --with-papi-inc-dir=dir PAPI include directory (default=PAPI_DIR/include) --with-papi-lib-dir=dir PAPI lib directory (default=PAPI_DIR/lib) --with-papi-lib-name=name Name of the PAPI library (default=papi) --with-gsl-dir=dir Main GSL directory (default=/usr/local) --with-gsl-inc-dir=dir GSL include directory (default=GSL_DIR/include/gsl) --with-gsl-lib-dir=dir GSL lib directory (default=GSL_DIR/lib) --with-libnbc-dir=dir Main libNBC directory (default=/usr/local) --with-libnbc-inc-dir=dir libNBC include directory (default=LIBNBC_DIR/include) --with-libnbc-lib-dir=dir libNBC lib directory (default=LIBNBC_DIR/lib) --with-num-tests=NUMTESTS Number of measurements per implementation (default=30) --with-perf-win=PERF-WIN Acceptable performance window (default=10) --with-pred-algo=algorithm Prediction algorithm options (default=ADCL_WMV) --with-smooth-win=WIN-SIZE Size of the smoothing window (default=3) Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> LIBS libraries to pass to the linker, e.g. -l<library> CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> CXX C++ compiler command CXXFLAGS C++ compiler flags F77 Fortran 77 compiler command FFLAGS Fortran 77 compiler flags Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. \end{verbatim}
lemma convex_hull_affinity: "convex hull ((\<lambda>x. a + c *\<^sub>R x) ` S) = (\<lambda>x. a + c *\<^sub>R x) ` (convex hull S)"
function list = qMRlistModel if nargout, list = list_models; end for im = list_models' header=qMRinfo(im{:}); % not compatible with octave if moxunit_util_platform_is_octave, return; end % get the first line ind = strfind(header,sprintf('\n')); header = header(1:ind-1); % remove space header = header(find(~isspace(header),1,'first'):end); % add tab after colons indcolons = strfind(header,':'); header = ['<strong>' header(1:indcolons) '</strong>' repmat(' ',[1 max(1,30 - indcolons)]) header((indcolons+find(~isspace(header(indcolons+1:end)),1,'first')):end)]; disp(header) end
(* begin hide *) From Coq Require Import Arith Lia. (* Fake dependency due to [eutt_iter'']. To remove once the lemma is moved to the itree library *) From Vellvm Require Import Utils.Tactics Utils.PropT. From ITree Require Import ITree Eq.Eqit. Set Implicit Arguments. Set Strict Implicit. Local Open Scope nat_scope. Import ITreeNotations. Local Open Scope itree. (* end hide *) (** * tfor: a bounded loop iterator for itrees *) Section TFor. (* The combinator [tfor body from to x0] simply sequences the computation: x1 <- body from x0;; x2 <- body (S from) x1;; ... body (to - 1) x_{to-from-1} i.e. it informally corresponds to: acc <- x0; for i = from, i < to, i++ do acc <- body i acc return acc *) Definition tfor {E X} (body : nat -> X -> itree E X) (from to : nat) : X -> itree E X := fun x => ITree.iter (fun '(p,x) => if beq_nat p to then Ret (inr x) else y <- (body p x);; Ret (inl (S p,y)) ) (from,x). (* [tfor] excludes the upper bound, hence [tfor body k k] does nothing *) Lemma tfor_0: forall {E A} k (body : nat -> A -> itree E A) a0, tfor body k k a0 ≈ Ret a0. Proof. intros; unfold tfor; cbn. unfold iter, CategoryKleisli.Iter_Kleisli, Basics.iter, MonadIter_itree. rewrite unfold_iter, Nat.eqb_refl, bind_ret_l. reflexivity. Qed. (* One step unrolling of the combinator *) Lemma tfor_unroll: forall {E A} i j (body : nat -> A -> itree E A) a0, i < j -> tfor body i j a0 ≈ a <- body i a0;; tfor body (S i) j a. Proof. intros; unfold tfor; cbn. unfold iter, CategoryKleisli.Iter_Kleisli, Basics.iter, MonadIter_itree. rewrite unfold_iter at 1. pose proof Nat.eqb_neq i j as [_ EQ]. rewrite EQ; try lia. rewrite bind_bind. apply eutt_eq_bind; intros ?; rewrite bind_ret_l, tau_eutt. reflexivity. Qed. (* We can always split a [tfor] into two sequential ones *) Lemma tfor_split: forall {E A} (body : nat -> A -> itree E A) i j k a0, i <= j -> j <= k -> tfor body i k a0 ≈ a <- tfor body i j a0;; tfor body j k a. Proof. intros * LE1 LE2. remember (j - i) as p; revert a0 i LE1 Heqp. induction p as [| p IH]; intros ? ? LE1 EQ. - replace i with j by lia. rewrite tfor_0, bind_ret_l. reflexivity. - rewrite tfor_unroll; [| lia]. rewrite tfor_unroll; [| lia]. rewrite bind_bind. apply eutt_eq_bind; intros ?. eapply IH; lia. Qed. (* We can substitute bodies under a [tfor] assuming that they are equivalent at all points. TODO: various stronger induction principles can be provided: - obviously restricting the range of indexes to the one iterated over - using a provided invariant constraining the accumulators. *) Lemma eutt_tfor: forall {E A} (body body' : nat -> A -> itree E A) i j a0, (forall k i, body i k ≈ body' i k) -> (tfor body i j a0) ≈ (tfor body' i j a0). Proof. intros. unfold tfor, iter, CategoryKleisli.Iter_Kleisli, Basics.iter, MonadIter_itree. eapply KTreeFacts.eutt_iter. intros []. break_match_goal. reflexivity. cbn. rewrite H. reflexivity. Qed. (* If the body does not depend on the index, we can re-index freely the bounds we iterate over *) Lemma tfor_ss : forall {E A} i j (body : nat -> A -> itree E A) a0, (forall x i j, body i x ≈ body j x) -> i <= j -> tfor body (S i) (S j) a0 ≈ tfor body i j a0. Proof. intros; unfold tfor; cbn. unfold iter, CategoryKleisli.Iter_Kleisli, Basics.iter, MonadIter_itree. apply eutt_iter'' with (RI1:=fun '(a,x) '(b, y) => a = S b /\ x = y) (RI2:=fun '(a,x) '(b, y) => a = S b /\ x = y); auto. intros [j1 acc1] [j2 acc2] H1. destruct H1. subst. cbn. pose proof (Nat.eq_dec j2 j) as [EQ | NEQ]. - subst. rewrite Nat.eqb_refl. apply eutt_Ret. constructor; auto. - apply Nat.eqb_neq in NEQ. rewrite NEQ. eapply eutt_clo_bind. rewrite H. reflexivity. intros; subst. apply eutt_Ret. constructor; auto. Qed. Lemma tfor_ss_dep : forall {E A} i j (body body' : nat -> A -> itree E A) a0, (forall x i, body' (S i) x ≈ body i x) -> i <= j -> tfor body' (S i) (S j) a0 ≈ tfor body i j a0. Proof. intros; unfold tfor; cbn. unfold iter, CategoryKleisli.Iter_Kleisli, Basics.iter, MonadIter_itree. eapply eutt_iter'' with (RI1:=fun '(a,x) '(b, y) => a = S b /\ x = y) (RI2:=fun '(a,x) '(b, y) => a = S b /\ x = y); auto. intros [j1 acc1] [j2 acc2] H1. destruct H1. subst. cbn. destruct (Nat.eq_dec j2 j) as [EQ | NEQ]. - subst. cbn. rewrite Nat.eqb_refl. apply eutt_Ret. constructor; auto. - apply Nat.eqb_neq in NEQ. rewrite NEQ. eapply eutt_clo_bind. rewrite H. reflexivity. intros; subst. apply eutt_Ret. constructor; auto. Qed. (* If the body does not depend on the index, we can unroll to the left while chipping at the upper bound *) Lemma tfor_unroll_down: forall {E A} i j (body : nat -> A -> itree E A) a0, i < S j -> (forall x i j, body i x ≈ body j x) -> tfor body i (S j) a0 ≈ a <- body i a0;; tfor body i j a. Proof. intros E A i j. revert E A i. induction j; intros E A i body a0 H H0. - rewrite tfor_unroll; auto. eapply eutt_clo_bind; [reflexivity|]. intros u1 u2 H1. subst. assert (i = 0) by lia; subst. repeat rewrite tfor_0. reflexivity. - rewrite tfor_unroll; auto. eapply eutt_clo_bind; [reflexivity|]. intros u1 u2 H1. subst. assert (i <= S j) by lia. apply le_lt_or_eq in H1. destruct H1. + rewrite IHj; [|lia|auto]. rewrite tfor_unroll; [|lia]. eapply eutt_clo_bind. erewrite H0; reflexivity. intros; subst. do 2 (rewrite tfor_ss; auto); [|lia]. reflexivity. + subst. repeat rewrite tfor_0. reflexivity. Qed. End TFor.
\chapter{Introduction} \label{intro} Knowledge management -- the practice of capturing, refining, and redistributing knowledge -- is an important activity for any organization. It is of particular importance to organizations that operate with a high degree of knowledge transfer between employees; learning organizations. What sets knowledge management apart from information management is that information management is primarily concerned with maintaining the integrity and availability of an organization's information stores, while knowledge management is concerned with ensuring that information is actionable and useful to members of the organization \cite{kmtoolkit}. In order for that to happen, a mechanism must exist to allow for information to be refined, consolidated, correlated, and accurately retrieved. To that end, knowledge management systems (KMS) are designed to provide organizations with a centralized means to collect, refine, and redistribute knowledge between members. One important component of any modern KMS is a readily accessible digital datastore that allows members of an organization to contribute and refine information, then retrieve it based on some set of criteria, such as filters or keyword matches. The purpose of Semantic Knowledge Management Framework (SKMF) is to provide the means to construct such a datastore using Semantic Web technologies. \section{The Semantic Web} \label{intro:semantic} The Semantic Web was proposed by Tim Burners-Lee in 1998 \cite{bernerslee} as a means of opening up the Internet in a machine readable manner that allows simple Web services to locate and correlate information on behalf of users. The Semantic Web provides some technologies with novel characteristics for knowledge management. The two Semantic Web technologies used by SKMF are RDF to form information links and SPARQL \cite{sparql} to retrieve the information. \subsection{RDF and Triplestores} \label{intro:rdf} Resource Description Framework \cite{rdf} (RDF) is the language that describes Semantic Web information. The smallest viable unit in RDF is the triple, a statement consisting of the uniform resource identifier (URI) of some resource, the URI of a specific property of that resource, and either a third URI or a literal value to provide meaning to the property. In RDF statements, these are referred to as the subject, predicate, and object, respectively. A collection of RDF statements provides a description of various resources and their relationships that can be represented as a directed graph, with subjects and objects as the nodes and predicates as the vertices directed from subjects to objects. While it is possible to serialize RDF statements into a form that is more compact than a complete list of triples, the information is typically kept in a triplestore that is further optimized for storage and retrieval of the statements, similar to a relational database system. Relational database systems allow developers to define data models that map well to the objects in object-oriented programming. It is straightforward to assign each column from a table to an attribute of one programming object and define some predetermined behaviors to perform on those attributes. Due to its graph-based nature, RDF does not provide such a convenient mapping. In fact, the shape of the information changes as triples are inserted into and deleted from the triplestore. SKMF uses RDF, however, because the nature of information that will be placed in the system cannot be known beforehand. Any attempt by a developer to devise a schema of tables is merely a guess of what will be useful to the customer and in what way it will be useful. While very good guesses are possible, there will always missing attributes that the customer desires and extra attributes that the customer never uses, limiting how customers can represent their data. Despite its limitations, RDF is flexible enough to allow the customer define a personalized schema as information is added and forged into knowledge. \section{Motivation for SKMF} \label{intro:motive} SKMF was originally conceived as a computer security incident response tool that would utilize Semantic Web linked data to build relationships between information assets, services, software, updates, vulnerabilities, patches, policy books, procedures, incident response team members, and other resources to aid incident responders in implementing security plans. Such a system would be able to pull information about vulnerabilities and patches from online sources of publication. It could be populated with asset information with the aid of a configuration management or network scanning tool that can identify networked resources. User information could be pulled from a network directory service or other source of team member information. Later, it was decided that the focus on incident response was not necessary and that a framework that would support quick deployment of such a system would be more useful. Thus, the focus of the project shifted to providing a general knowledge management platform that would allow users to define more specific uses of the application. The intention of SKMF is to provide a linked data management interface that allows users to build custom ontologies and use those ontologies to describe sets of information. SKMF should provide a means of inputting information with guidelines for the user to make that information more useful. It should also provide an administrative interface for managing the users who are allowed to access and modify data, as well as restricting sets of data to certain users. It is not meant to convert an organization's existing information repositories into a linked data form. It is also not meant to provide end-to-end protection of transmitted information, as that falls largely on the Web server and triplestore used in the deployment environment. It is not meant to act as an inferencing engine for advanced ontologies, such as the Web Ontology Language \cite{owl} (OWL). Finally, it is not meant to describe a single knowledge domain, such as computer security incident response. Since incident response was the original inspiration for SKMF, however, this scenario is used in a mock case study of the application.
State Before: ι : Type ?u.62901 α : Type u_1 β : Type ?u.62907 π : ι → Type ?u.62912 inst✝ : GeneralizedBooleanAlgebra α a b c d : α ⊢ a \ a ∆ b = a ⊓ b State After: no goals Tactic: simp [sdiff_symmDiff]
[GOAL] R : Type u_1 G : Type u_2 inst✝ : CancelCommMonoid G g : G ⊢ mulLeftEmbedding g = mulRightEmbedding g [PROOFSTEP] ext [GOAL] case h R : Type u_1 G : Type u_2 inst✝ : CancelCommMonoid G g x✝ : G ⊢ ↑(mulLeftEmbedding g) x✝ = ↑(mulRightEmbedding g) x✝ [PROOFSTEP] exact mul_comm _ _
function [min_width, min_angle] = minimumCaliperDiameter(points) %MINIMUMCALIPERDIAMETER Minimum caliper diameter of a set of points. % % WIDTH = minimumCaliperDiameter(POINTS) % Computes the minimum width of a set of points. As polygons and % polylines are represented as point lists, this function works also for % polygons and polylines. % % [WIDTH THETA] = minimumCaliperDiameter(POINTS) % Also returns the direction of minimum width. The direction corresponds % to the horizontal angle of the edge that minimizes the width. THETA is % given in radians, between 0 and PI. % % % Example % % Compute minimal caliper diameter, and check coords of rotated points % % have expected extent % points = randn(30, 2); % [width theta] = minimumCaliperDiameter(points); % points2 = transformPoint(points, createRotation(-theta)); % diff = max(points2) - min(points2); % abs(width - diff(2)) < 1e-10 % ans = % 1 % % References % Algorithms use rotating caliper. Implementation was based on that of % Wikipedia: % http://en.wikipedia.org/wiki/Rotating_calipers % % See also % polygons2d, convexHull, orientedBox % % ------ % Author: David Legland % E-mail: [email protected] % Created: 2011-04-08, using Matlab 7.9.0.529 (R2009b) % Copyright 2011-2022 INRA - Cepia Software Platform % first, compute convex hull of the polygon inds = convhull(points(:,1), points(:,2)); hull = points(inds, :); % if first and last points are the same, remove the last one if inds(1) == inds(end) hull = hull(1:end-1, :); end % number of hull vertices nV = size(hull, 1); % default values rotated_angle = 0; min_width = inf; min_angle = 0; % avoid degenerated cases if nV < 3 return; end [tmp, p_a] = min(hull(:, 2)); %#ok<ASGLU> [tmp, p_b] = max(hull(:, 2)); %#ok<ASGLU> caliper_a = [ 1 0]; % Caliper A points along the positive x-axis caliper_b = [-1 0]; % Caliper B points along the negative x-axis while rotated_angle < pi % compute the direction vectors corresponding to each edge ind_a2 = mod(p_a, nV) + 1; vector_a = hull(ind_a2, :) - hull(p_a, :); ind_b2 = mod(p_b, nV) + 1; vector_b = hull(ind_b2, :) - hull(p_b, :); % Determine the angle between each caliper and the next adjacent edge % in the polygon angle_a = vectorAngle(caliper_a, vector_a); angle_b = vectorAngle(caliper_b, vector_b); % Determine the smallest of these angles minAngle = min(angle_a, angle_b); % Rotate the calipers by the smallest angle caliper_a = rotateVector(caliper_a, minAngle); caliper_b = rotateVector(caliper_b, minAngle); rotated_angle = rotated_angle + minAngle; % compute current width, and update opposite vertex if angle_a < angle_b line = createLine(hull(p_a, :), hull(ind_a2, :)); width = distancePointLine(hull(p_b, :), line); p_a = mod(p_a, nV) + 1; else line = createLine(hull(p_b, :), hull(ind_b2, :)); width = distancePointLine(hull(p_a, :), line); p_b = mod(p_b, nV) + 1; end % update minimum width and corresponding angle if needed if width < min_width min_width = width; min_angle = rotated_angle; end end
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes, Johannes Hölzl, Yury Kudryashov -/ import algebra.group.commute import algebra.group_with_zero.defs import data.fun_like.basic /-! # Monoid and group homomorphisms This file defines the bundled structures for monoid and group homomorphisms. Namely, we define `monoid_hom` (resp., `add_monoid_hom`) to be bundled homomorphisms between multiplicative (resp., additive) monoids or groups. We also define coercion to a function, and usual operations: composition, identity homomorphism, pointwise multiplication and pointwise inversion. This file also defines the lesser-used (and notation-less) homomorphism types which are used as building blocks for other homomorphisms: * `zero_hom` * `one_hom` * `add_hom` * `mul_hom` * `monoid_with_zero_hom` ## Notations * `→+`: Bundled `add_monoid` homs. Also use for `add_group` homs. * `→*`: Bundled `monoid` homs. Also use for `group` homs. * `→*₀`: Bundled `monoid_with_zero` homs. Also use for `group_with_zero` homs. ## Implementation notes There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. There is no `group_hom` -- the idea is that `monoid_hom` is used. The constructor for `monoid_hom` needs a proof of `map_one` as well as `map_mul`; a separate constructor `monoid_hom.mk'` will construct group homs (i.e. monoid homs between groups) given only a proof that multiplication is preserved, Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the instances can be inferred because they are implicit arguments to the type `monoid_hom`. When they can be inferred from the type it is faster to use this method than to use type class inference. Historically this file also included definitions of unbundled homomorphism classes; they were deprecated and moved to `deprecated/group`. ## Tags monoid_hom, add_monoid_hom -/ variables {M : Type*} {N : Type*} {P : Type*} -- monoids variables {G : Type*} {H : Type*} -- groups variables {F : Type*} -- homs -- for easy multiple inheritance set_option old_structure_cmd true section zero /-- `zero_hom M N` is the type of functions `M → N` that preserve zero. When possible, instead of parametrizing results over `(f : zero_hom M N)`, you should parametrize over `(F : Type*) [zero_hom_class F M N] (f : F)`. When you extend this structure, make sure to also extend `zero_hom_class`. -/ structure zero_hom (M : Type*) (N : Type*) [has_zero M] [has_zero N] := (to_fun : M → N) (map_zero' : to_fun 0 = 0) /-- `zero_hom_class F M N` states that `F` is a type of zero-preserving homomorphisms. You should extend this typeclass when you extend `zero_hom`. -/ class zero_hom_class (F : Type*) (M N : out_param $ Type*) [has_zero M] [has_zero N] extends fun_like F M (λ _, N) := (map_zero : ∀ (f : F), f 0 = 0) -- Instances and lemmas are defined below through `@[to_additive]`. end zero section add /-- `add_hom M N` is the type of functions `M → N` that preserve addition. When possible, instead of parametrizing results over `(f : add_hom M N)`, you should parametrize over `(F : Type*) [add_hom_class F M N] (f : F)`. When you extend this structure, make sure to extend `add_hom_class`. -/ structure add_hom (M : Type*) (N : Type*) [has_add M] [has_add N] := (to_fun : M → N) (map_add' : ∀ x y, to_fun (x + y) = to_fun x + to_fun y) /-- `add_hom_class F M N` states that `F` is a type of addition-preserving homomorphisms. You should declare an instance of this typeclass when you extend `add_hom`. -/ class add_hom_class (F : Type*) (M N : out_param $ Type*) [has_add M] [has_add N] extends fun_like F M (λ _, N) := (map_add : ∀ (f : F) (x y : M), f (x + y) = f x + f y) -- Instances and lemmas are defined below through `@[to_additive]`. end add section add_zero /-- `M →+ N` is the type of functions `M → N` that preserve the `add_zero_class` structure. `add_monoid_hom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →+ N)`, you should parametrize over `(F : Type*) [add_monoid_hom_class F M N] (f : F)`. When you extend this structure, make sure to extend `add_monoid_hom_class`. -/ @[ancestor zero_hom add_hom] structure add_monoid_hom (M : Type*) (N : Type*) [add_zero_class M] [add_zero_class N] extends zero_hom M N, add_hom M N attribute [nolint doc_blame] add_monoid_hom.to_add_hom attribute [nolint doc_blame] add_monoid_hom.to_zero_hom infixr ` →+ `:25 := add_monoid_hom /-- `add_monoid_hom_class F M N` states that `F` is a type of `add_zero_class`-preserving homomorphisms. You should also extend this typeclass when you extend `add_monoid_hom`. -/ @[ancestor add_hom_class zero_hom_class] class add_monoid_hom_class (F : Type*) (M N : out_param $ Type*) [add_zero_class M] [add_zero_class N] extends add_hom_class F M N, zero_hom_class F M N -- Instances and lemmas are defined below through `@[to_additive]`. end add_zero section one variables [has_one M] [has_one N] /-- `one_hom M N` is the type of functions `M → N` that preserve one. When possible, instead of parametrizing results over `(f : one_hom M N)`, you should parametrize over `(F : Type*) [one_hom_class F M N] (f : F)`. When you extend this structure, make sure to also extend `one_hom_class`. -/ @[to_additive] structure one_hom (M : Type*) (N : Type*) [has_one M] [has_one N] := (to_fun : M → N) (map_one' : to_fun 1 = 1) /-- `one_hom_class F M N` states that `F` is a type of one-preserving homomorphisms. You should extend this typeclass when you extend `one_hom`. -/ @[to_additive] class one_hom_class (F : Type*) (M N : out_param $ Type*) [has_one M] [has_one N] extends fun_like F M (λ _, N) := (map_one : ∀ (f : F), f 1 = 1) @[to_additive] instance one_hom.one_hom_class : one_hom_class (one_hom M N) M N := { coe := one_hom.to_fun, coe_injective' := λ f g h, by cases f; cases g; congr', map_one := one_hom.map_one' } @[simp, to_additive] lemma map_one [one_hom_class F M N] (f : F) : f 1 = 1 := one_hom_class.map_one f @[to_additive] lemma map_eq_one_iff [one_hom_class F M N] (f : F) (hf : function.injective f) {x : M} : f x = 1 ↔ x = 1 := hf.eq_iff' (map_one f) @[to_additive] instance [one_hom_class F M N] : has_coe_t F (one_hom M N) := ⟨λ f, { to_fun := f, map_one' := map_one f }⟩ end one section mul variables [has_mul M] [has_mul N] /-- `mul_hom M N` is the type of functions `M → N` that preserve multiplication. When possible, instead of parametrizing results over `(f : mul_hom M N)`, you should parametrize over `(F : Type*) [mul_hom_class F M N] (f : F)`. When you extend this structure, make sure to extend `mul_hom_class`. -/ @[to_additive] structure mul_hom (M : Type*) (N : Type*) [has_mul M] [has_mul N] := (to_fun : M → N) (map_mul' : ∀ x y, to_fun (x * y) = to_fun x * to_fun y) /-- `mul_hom_class F M N` states that `F` is a type of multiplication-preserving homomorphisms. You should declare an instance of this typeclass when you extend `mul_hom`. -/ @[to_additive] class mul_hom_class (F : Type*) (M N : out_param $ Type*) [has_mul M] [has_mul N] extends fun_like F M (λ _, N) := (map_mul : ∀ (f : F) (x y : M), f (x * y) = f x * f y) @[to_additive] instance mul_hom.mul_hom_class : mul_hom_class (mul_hom M N) M N := { coe := mul_hom.to_fun, coe_injective' := λ f g h, by cases f; cases g; congr', map_mul := mul_hom.map_mul' } @[simp, to_additive] lemma map_mul [mul_hom_class F M N] (f : F) (x y : M) : f (x * y) = f x * f y := mul_hom_class.map_mul f x y @[to_additive] instance [mul_hom_class F M N] : has_coe_t F (mul_hom M N) := ⟨λ f, { to_fun := f, map_mul' := map_mul f }⟩ end mul section mul_one variables [mul_one_class M] [mul_one_class N] /-- `M →* N` is the type of functions `M → N` that preserve the `monoid` structure. `monoid_hom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →+ N)`, you should parametrize over `(F : Type*) [monoid_hom_class F M N] (f : F)`. When you extend this structure, make sure to extend `monoid_hom_class`. -/ @[ancestor one_hom mul_hom, to_additive] structure monoid_hom (M : Type*) (N : Type*) [mul_one_class M] [mul_one_class N] extends one_hom M N, mul_hom M N attribute [nolint doc_blame] monoid_hom.to_mul_hom attribute [nolint doc_blame] monoid_hom.to_one_hom infixr ` →* `:25 := monoid_hom /-- `monoid_hom_class F M N` states that `F` is a type of `monoid`-preserving homomorphisms. You should also extend this typeclass when you extend `monoid_hom`. -/ @[ancestor mul_hom_class one_hom_class, to_additive] class monoid_hom_class (F : Type*) (M N : out_param $ Type*) [mul_one_class M] [mul_one_class N] extends mul_hom_class F M N, one_hom_class F M N @[to_additive] instance monoid_hom.monoid_hom_class : monoid_hom_class (M →* N) M N := { coe := monoid_hom.to_fun, coe_injective' := λ f g h, by cases f; cases g; congr', map_mul := monoid_hom.map_mul', map_one := monoid_hom.map_one' } @[to_additive] instance [monoid_hom_class F M N] : has_coe_t F (M →* N) := ⟨λ f, { to_fun := f, map_one' := map_one f, map_mul' := map_mul f }⟩ @[to_additive] lemma map_mul_eq_one [monoid_hom_class F M N] (f : F) {a b : M} (h : a * b = 1) : f a * f b = 1 := by rw [← map_mul, h, map_one] /-- Group homomorphisms preserve inverse. -/ @[simp, to_additive] theorem map_inv [group G] [group H] [monoid_hom_class F G H] (f : F) (g : G) : f g⁻¹ = (f g)⁻¹ := eq_inv_of_mul_eq_one $ map_mul_eq_one f $ inv_mul_self g /-- Group homomorphisms preserve division. -/ @[simp, to_additive] theorem map_mul_inv [group G] [group H] [monoid_hom_class F G H] (f : F) (g h : G) : f (g * h⁻¹) = f g * (f h)⁻¹ := by rw [map_mul, map_inv] /-- Group homomorphisms preserve division. -/ @[simp, to_additive] lemma map_div [group G] [group H] [monoid_hom_class F G H] (f : F) (x y : G) : f (x / y) = f x / f y := by rw [div_eq_mul_inv, div_eq_mul_inv, map_mul_inv] @[simp, to_additive map_nsmul] theorem map_pow [monoid G] [monoid H] [monoid_hom_class F G H] (f : F) (a : G) : ∀ (n : ℕ), f (a ^ n) = (f a) ^ n | 0 := by rw [pow_zero, pow_zero, map_one] | (n+1) := by rw [pow_succ, pow_succ, map_mul, map_pow] @[to_additive] theorem map_zpow' [div_inv_monoid G] [div_inv_monoid H] [monoid_hom_class F G H] (f : F) (hf : ∀ (x : G), f (x⁻¹) = (f x)⁻¹) (a : G) : ∀ n : ℤ, f (a ^ n) = (f a) ^ n | (n : ℕ) := by rw [zpow_coe_nat, map_pow, zpow_coe_nat] | -[1+n] := by rw [zpow_neg_succ_of_nat, hf, map_pow, ← zpow_neg_succ_of_nat] /-- Group homomorphisms preserve integer power. -/ @[simp, to_additive /-" Additive group homomorphisms preserve integer scaling. "-/] theorem map_zpow [group G] [group H] [monoid_hom_class F G H] (f : F) (g : G) (n : ℤ) : f (g ^ n) = (f g) ^ n := map_zpow' f (map_inv f) g n end mul_one section mul_zero_one variables [mul_zero_one_class M] [mul_zero_one_class N] /-- `M →*₀ N` is the type of functions `M → N` that preserve the `monoid_with_zero` structure. `monoid_with_zero_hom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →+ N)`, you should parametrize over `(F : Type*) [monoid_with_zero_hom_class F M N] (f : F)`. When you extend this structure, make sure to extend `monoid_with_zero_hom_class`. -/ @[ancestor zero_hom monoid_hom] structure monoid_with_zero_hom (M : Type*) (N : Type*) [mul_zero_one_class M] [mul_zero_one_class N] extends zero_hom M N, monoid_hom M N attribute [nolint doc_blame] monoid_with_zero_hom.to_monoid_hom attribute [nolint doc_blame] monoid_with_zero_hom.to_zero_hom infixr ` →*₀ `:25 := monoid_with_zero_hom /-- `monoid_with_zero_hom_class F M N` states that `F` is a type of `monoid_with_zero`-preserving homomorphisms. You should also extend this typeclass when you extend `monoid_with_zero_hom`. -/ class monoid_with_zero_hom_class (F : Type*) (M N : out_param $ Type*) [mul_zero_one_class M] [mul_zero_one_class N] extends monoid_hom_class F M N, zero_hom_class F M N instance monoid_with_zero_hom.monoid_with_zero_hom_class : monoid_with_zero_hom_class (M →*₀ N) M N := { coe := monoid_with_zero_hom.to_fun, coe_injective' := λ f g h, by cases f; cases g; congr', map_mul := monoid_with_zero_hom.map_mul', map_one := monoid_with_zero_hom.map_one', map_zero := monoid_with_zero_hom.map_zero' } instance [monoid_with_zero_hom_class F M N] : has_coe_t F (M →*₀ N) := ⟨λ f, { to_fun := f, map_one' := map_one f, map_zero' := map_zero f, map_mul' := map_mul f }⟩ end mul_zero_one -- completely uninteresting lemmas about coercion to function, that all homs need section coes /-! Bundled morphisms can be down-cast to weaker bundlings -/ @[to_additive] instance monoid_hom.has_coe_to_one_hom {mM : mul_one_class M} {mN : mul_one_class N} : has_coe (M →* N) (one_hom M N) := ⟨monoid_hom.to_one_hom⟩ @[to_additive] instance monoid_hom.has_coe_to_mul_hom {mM : mul_one_class M} {mN : mul_one_class N} : has_coe (M →* N) (mul_hom M N) := ⟨monoid_hom.to_mul_hom⟩ instance monoid_with_zero_hom.has_coe_to_monoid_hom {mM : mul_zero_one_class M} {mN : mul_zero_one_class N} : has_coe (M →*₀ N) (M →* N) := ⟨monoid_with_zero_hom.to_monoid_hom⟩ instance monoid_with_zero_hom.has_coe_to_zero_hom {mM : mul_zero_one_class M} {mN : mul_zero_one_class N} : has_coe (M →*₀ N) (zero_hom M N) := ⟨monoid_with_zero_hom.to_zero_hom⟩ /-! The simp-normal form of morphism coercion is `f.to_..._hom`. This choice is primarily because this is the way things were before the above coercions were introduced. Bundled morphisms defined elsewhere in Mathlib may choose `↑f` as their simp-normal form instead. -/ @[simp, to_additive] lemma monoid_hom.coe_eq_to_one_hom {mM : mul_one_class M} {mN : mul_one_class N} (f : M →* N) : (f : one_hom M N) = f.to_one_hom := rfl @[simp, to_additive] lemma monoid_hom.coe_eq_to_mul_hom {mM : mul_one_class M} {mN : mul_one_class N} (f : M →* N) : (f : mul_hom M N) = f.to_mul_hom := rfl @[simp] lemma monoid_with_zero_hom.coe_eq_to_monoid_hom {mM : mul_zero_one_class M} {mN : mul_zero_one_class N} (f : M →*₀ N) : (f : M →* N) = f.to_monoid_hom := rfl @[simp] lemma monoid_with_zero_hom.coe_eq_to_zero_hom {mM : mul_zero_one_class M} {mN : mul_zero_one_class N} (f : M →*₀ N) : (f : zero_hom M N) = f.to_zero_hom := rfl -- Fallback `has_coe_to_fun` instances to help the elaborator @[to_additive] instance {mM : has_one M} {mN : has_one N} : has_coe_to_fun (one_hom M N) (λ _, M → N) := ⟨one_hom.to_fun⟩ @[to_additive] instance {mM : has_mul M} {mN : has_mul N} : has_coe_to_fun (mul_hom M N) (λ _, M → N) := ⟨mul_hom.to_fun⟩ @[to_additive] instance {mM : mul_one_class M} {mN : mul_one_class N} : has_coe_to_fun (M →* N) (λ _, M → N) := ⟨monoid_hom.to_fun⟩ instance {mM : mul_zero_one_class M} {mN : mul_zero_one_class N} : has_coe_to_fun (M →*₀ N) (λ _, M → N) := ⟨monoid_with_zero_hom.to_fun⟩ -- these must come after the coe_to_fun definitions initialize_simps_projections zero_hom (to_fun → apply) initialize_simps_projections add_hom (to_fun → apply) initialize_simps_projections add_monoid_hom (to_fun → apply) initialize_simps_projections one_hom (to_fun → apply) initialize_simps_projections mul_hom (to_fun → apply) initialize_simps_projections monoid_hom (to_fun → apply) initialize_simps_projections monoid_with_zero_hom (to_fun → apply) @[simp, to_additive] lemma one_hom.to_fun_eq_coe [has_one M] [has_one N] (f : one_hom M N) : f.to_fun = f := rfl @[simp, to_additive] lemma mul_hom.to_fun_eq_coe [has_mul M] [has_mul N] (f : mul_hom M N) : f.to_fun = f := rfl @[simp, to_additive] lemma monoid_hom.to_fun_eq_coe [mul_one_class M] [mul_one_class N] (f : M →* N) : f.to_fun = f := rfl @[simp] lemma monoid_with_zero_hom.to_fun_eq_coe [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) : f.to_fun = f := rfl @[simp, to_additive] lemma one_hom.coe_mk [has_one M] [has_one N] (f : M → N) (h1) : (one_hom.mk f h1 : M → N) = f := rfl @[simp, to_additive] lemma mul_hom.coe_mk [has_mul M] [has_mul N] (f : M → N) (hmul) : (mul_hom.mk f hmul : M → N) = f := rfl @[simp, to_additive] lemma monoid_hom.coe_mk [mul_one_class M] [mul_one_class N] (f : M → N) (h1 hmul) : (monoid_hom.mk f h1 hmul : M → N) = f := rfl @[simp] lemma monoid_with_zero_hom.coe_mk [mul_zero_one_class M] [mul_zero_one_class N] (f : M → N) (h0 h1 hmul) : (monoid_with_zero_hom.mk f h0 h1 hmul : M → N) = f := rfl @[simp, to_additive] lemma monoid_hom.to_one_hom_coe [mul_one_class M] [mul_one_class N] (f : M →* N) : (f.to_one_hom : M → N) = f := rfl @[simp, to_additive] lemma monoid_hom.to_mul_hom_coe [mul_one_class M] [mul_one_class N] (f : M →* N) : (f.to_mul_hom : M → N) = f := rfl @[simp] lemma monoid_with_zero_hom.to_zero_hom_coe [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) : (f.to_zero_hom : M → N) = f := rfl @[simp] lemma monoid_with_zero_hom.to_monoid_hom_coe [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) : (f.to_monoid_hom : M → N) = f := rfl @[to_additive] theorem one_hom.congr_fun [has_one M] [has_one N] {f g : one_hom M N} (h : f = g) (x : M) : f x = g x := congr_arg (λ h : one_hom M N, h x) h @[to_additive] theorem mul_hom.congr_fun [has_mul M] [has_mul N] {f g : mul_hom M N} (h : f = g) (x : M) : f x = g x := congr_arg (λ h : mul_hom M N, h x) h @[to_additive] theorem monoid_hom.congr_fun [mul_one_class M] [mul_one_class N] {f g : M →* N} (h : f = g) (x : M) : f x = g x := congr_arg (λ h : M →* N, h x) h theorem monoid_with_zero_hom.congr_fun [mul_zero_one_class M] [mul_zero_one_class N] {f g : M →*₀ N} (h : f = g) (x : M) : f x = g x := congr_arg (λ h : M →*₀ N, h x) h @[to_additive] theorem one_hom.congr_arg [has_one M] [has_one N] (f : one_hom M N) {x y : M} (h : x = y) : f x = f y := congr_arg (λ x : M, f x) h @[to_additive] theorem mul_hom.congr_arg [has_mul M] [has_mul N] (f : mul_hom M N) {x y : M} (h : x = y) : f x = f y := congr_arg (λ x : M, f x) h @[to_additive] theorem monoid_hom.congr_arg [mul_one_class M] [mul_one_class N] (f : M →* N) {x y : M} (h : x = y) : f x = f y := congr_arg (λ x : M, f x) h theorem monoid_with_zero_hom.congr_arg [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) {x y : M} (h : x = y) : f x = f y := congr_arg (λ x : M, f x) h @[to_additive] lemma one_hom.coe_inj [has_one M] [has_one N] ⦃f g : one_hom M N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl @[to_additive] lemma mul_hom.coe_inj [has_mul M] [has_mul N] ⦃f g : mul_hom M N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl @[to_additive] lemma monoid_hom.coe_inj [mul_one_class M] [mul_one_class N] ⦃f g : M →* N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl lemma monoid_with_zero_hom.coe_inj [mul_zero_one_class M] [mul_zero_one_class N] ⦃f g : M →*₀ N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl @[ext, to_additive] lemma one_hom.ext [has_one M] [has_one N] ⦃f g : one_hom M N⦄ (h : ∀ x, f x = g x) : f = g := one_hom.coe_inj (funext h) @[ext, to_additive] lemma mul_hom.ext [has_mul M] [has_mul N] ⦃f g : mul_hom M N⦄ (h : ∀ x, f x = g x) : f = g := mul_hom.coe_inj (funext h) @[ext, to_additive] lemma monoid_hom.ext [mul_one_class M] [mul_one_class N] ⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g := monoid_hom.coe_inj (funext h) @[ext] lemma monoid_with_zero_hom.ext [mul_zero_one_class M] [mul_zero_one_class N] ⦃f g : M →*₀ N⦄ (h : ∀ x, f x = g x) : f = g := monoid_with_zero_hom.coe_inj (funext h) @[to_additive] lemma one_hom.ext_iff [has_one M] [has_one N] {f g : one_hom M N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, one_hom.ext h⟩ @[to_additive] lemma mul_hom.ext_iff [has_mul M] [has_mul N] {f g : mul_hom M N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, mul_hom.ext h⟩ @[to_additive] lemma monoid_hom.ext_iff [mul_one_class M] [mul_one_class N] {f g : M →* N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, monoid_hom.ext h⟩ lemma monoid_with_zero_hom.ext_iff [mul_zero_one_class M] [mul_zero_one_class N] {f g : M →*₀ N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, monoid_with_zero_hom.ext h⟩ @[simp, to_additive] lemma one_hom.mk_coe [has_one M] [has_one N] (f : one_hom M N) (h1) : one_hom.mk f h1 = f := one_hom.ext $ λ _, rfl @[simp, to_additive] lemma mul_hom.mk_coe [has_mul M] [has_mul N] (f : mul_hom M N) (hmul) : mul_hom.mk f hmul = f := mul_hom.ext $ λ _, rfl @[simp, to_additive] lemma monoid_hom.mk_coe [mul_one_class M] [mul_one_class N] (f : M →* N) (h1 hmul) : monoid_hom.mk f h1 hmul = f := monoid_hom.ext $ λ _, rfl @[simp] lemma monoid_with_zero_hom.mk_coe [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) (h0 h1 hmul) : monoid_with_zero_hom.mk f h0 h1 hmul = f := monoid_with_zero_hom.ext $ λ _, rfl end coes /-- Copy of a `one_hom` with a new `to_fun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of a `zero_hom` with a new `to_fun` equal to the old one. Useful to fix definitional equalities."] protected def one_hom.copy {hM : has_one M} {hN : has_one N} (f : one_hom M N) (f' : M → N) (h : f' = f) : one_hom M N := { to_fun := f', map_one' := h.symm ▸ f.map_one' } /-- Copy of a `mul_hom` with a new `to_fun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of an `add_hom` with a new `to_fun` equal to the old one. Useful to fix definitional equalities."] protected def mul_hom.copy {hM : has_mul M} {hN : has_mul N} (f : mul_hom M N) (f' : M → N) (h : f' = f) : mul_hom M N := { to_fun := f', map_mul' := h.symm ▸ f.map_mul' } /-- Copy of a `monoid_hom` with a new `to_fun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of an `add_monoid_hom` with a new `to_fun` equal to the old one. Useful to fix definitional equalities."] protected def monoid_hom.copy {hM : mul_one_class M} {hN : mul_one_class N} (f : M →* N) (f' : M → N) (h : f' = f) : M →* N := { ..f.to_one_hom.copy f' h, ..f.to_mul_hom.copy f' h } /-- Copy of a `monoid_hom` with a new `to_fun` equal to the old one. Useful to fix definitional equalities. -/ protected def monoid_with_zero_hom.copy {hM : mul_zero_one_class M} {hN : mul_zero_one_class N} (f : M →*₀ N) (f' : M → N) (h : f' = f) : M →* N := { ..f.to_zero_hom.copy f' h, ..f.to_monoid_hom.copy f' h } @[to_additive] protected lemma one_hom.map_one [has_one M] [has_one N] (f : one_hom M N) : f 1 = 1 := f.map_one' /-- If `f` is a monoid homomorphism then `f 1 = 1`. -/ @[to_additive] protected lemma monoid_hom.map_one [mul_one_class M] [mul_one_class N] (f : M →* N) : f 1 = 1 := f.map_one' protected lemma monoid_with_zero_hom.map_one [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) : f 1 = 1 := f.map_one' /-- If `f` is an additive monoid homomorphism then `f 0 = 0`. -/ add_decl_doc add_monoid_hom.map_zero protected lemma monoid_with_zero_hom.map_zero [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) : f 0 = 0 := f.map_zero' @[to_additive] protected lemma mul_hom.map_mul [has_mul M] [has_mul N] (f : mul_hom M N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b /-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/ @[to_additive] protected lemma monoid_hom.map_mul [mul_one_class M] [mul_one_class N] (f : M →* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b protected lemma monoid_with_zero_hom.map_mul [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b /-- If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`. -/ add_decl_doc add_monoid_hom.map_add namespace monoid_hom variables {mM : mul_one_class M} {mN : mul_one_class N} {mP : mul_one_class P} variables [group G] [comm_group H] include mM mN @[to_additive] lemma map_mul_eq_one (f : M →* N) {a b : M} (h : a * b = 1) : f a * f b = 1 := map_mul_eq_one f h /-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse, then `f x` has a right inverse too. For elements invertible on both sides see `is_unit.map`. -/ @[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has a right inverse, then `f x` has a right inverse too."] lemma map_exists_right_inv (f : M →* N) {x : M} (hx : ∃ y, x * y = 1) : ∃ y, f x * y = 1 := let ⟨y, hy⟩ := hx in ⟨f y, f.map_mul_eq_one hy⟩ /-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see `is_unit.map`. -/ @[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see `is_add_unit.map`."] lemma map_exists_left_inv (f : M →* N) {x : M} (hx : ∃ y, y * x = 1) : ∃ y, y * f x = 1 := let ⟨y, hy⟩ := hx in ⟨f y, f.map_mul_eq_one hy⟩ end monoid_hom /-- Inversion on a commutative group, considered as a monoid homomorphism. -/ @[to_additive "Inversion on a commutative additive group, considered as an additive monoid homomorphism."] def comm_group.inv_monoid_hom {G : Type*} [comm_group G] : G →* G := { to_fun := has_inv.inv, map_one' := one_inv, map_mul' := mul_inv } /-- The identity map from a type with 1 to itself. -/ @[to_additive, simps] def one_hom.id (M : Type*) [has_one M] : one_hom M M := { to_fun := λ x, x, map_one' := rfl, } /-- The identity map from a type with multiplication to itself. -/ @[to_additive, simps] def mul_hom.id (M : Type*) [has_mul M] : mul_hom M M := { to_fun := λ x, x, map_mul' := λ _ _, rfl, } /-- The identity map from a monoid to itself. -/ @[to_additive, simps] def monoid_hom.id (M : Type*) [mul_one_class M] : M →* M := { to_fun := λ x, x, map_one' := rfl, map_mul' := λ _ _, rfl, } /-- The identity map from a monoid_with_zero to itself. -/ @[simps] def monoid_with_zero_hom.id (M : Type*) [mul_zero_one_class M] : M →*₀ M := { to_fun := λ x, x, map_zero' := rfl, map_one' := rfl, map_mul' := λ _ _, rfl, } /-- The identity map from an type with zero to itself. -/ add_decl_doc zero_hom.id /-- The identity map from an type with addition to itself. -/ add_decl_doc add_hom.id /-- The identity map from an additive monoid to itself. -/ add_decl_doc add_monoid_hom.id /-- Composition of `one_hom`s as a `one_hom`. -/ @[to_additive] def one_hom.comp [has_one M] [has_one N] [has_one P] (hnp : one_hom N P) (hmn : one_hom M N) : one_hom M P := { to_fun := hnp ∘ hmn, map_one' := by simp, } /-- Composition of `mul_hom`s as a `mul_hom`. -/ @[to_additive] def mul_hom.comp [has_mul M] [has_mul N] [has_mul P] (hnp : mul_hom N P) (hmn : mul_hom M N) : mul_hom M P := { to_fun := hnp ∘ hmn, map_mul' := by simp, } /-- Composition of monoid morphisms as a monoid morphism. -/ @[to_additive] def monoid_hom.comp [mul_one_class M] [mul_one_class N] [mul_one_class P] (hnp : N →* P) (hmn : M →* N) : M →* P := { to_fun := hnp ∘ hmn, map_one' := by simp, map_mul' := by simp, } /-- Composition of `monoid_with_zero_hom`s as a `monoid_with_zero_hom`. -/ def monoid_with_zero_hom.comp [mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P] (hnp : N →*₀ P) (hmn : M →*₀ N) : M →*₀ P := { to_fun := hnp ∘ hmn, map_zero' := by simp, map_one' := by simp, map_mul' := by simp, } /-- Composition of `zero_hom`s as a `zero_hom`. -/ add_decl_doc zero_hom.comp /-- Composition of `add_hom`s as a `add_hom`. -/ add_decl_doc add_hom.comp /-- Composition of additive monoid morphisms as an additive monoid morphism. -/ add_decl_doc add_monoid_hom.comp @[simp, to_additive] lemma one_hom.coe_comp [has_one M] [has_one N] [has_one P] (g : one_hom N P) (f : one_hom M N) : ⇑(g.comp f) = g ∘ f := rfl @[simp, to_additive] lemma mul_hom.coe_comp [has_mul M] [has_mul N] [has_mul P] (g : mul_hom N P) (f : mul_hom M N) : ⇑(g.comp f) = g ∘ f := rfl @[simp, to_additive] lemma monoid_hom.coe_comp [mul_one_class M] [mul_one_class N] [mul_one_class P] (g : N →* P) (f : M →* N) : ⇑(g.comp f) = g ∘ f := rfl @[simp] lemma monoid_with_zero_hom.coe_comp [mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P] (g : N →*₀ P) (f : M →*₀ N) : ⇑(g.comp f) = g ∘ f := rfl @[to_additive] lemma one_hom.comp_apply [has_one M] [has_one N] [has_one P] (g : one_hom N P) (f : one_hom M N) (x : M) : g.comp f x = g (f x) := rfl @[to_additive] lemma mul_hom.comp_apply [has_mul M] [has_mul N] [has_mul P] (g : mul_hom N P) (f : mul_hom M N) (x : M) : g.comp f x = g (f x) := rfl @[to_additive] lemma monoid_hom.comp_apply [mul_one_class M] [mul_one_class N] [mul_one_class P] (g : N →* P) (f : M →* N) (x : M) : g.comp f x = g (f x) := rfl lemma monoid_with_zero_hom.comp_apply [mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P] (g : N →*₀ P) (f : M →*₀ N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of monoid homomorphisms is associative. -/ @[to_additive] lemma one_hom.comp_assoc {Q : Type*} [has_one M] [has_one N] [has_one P] [has_one Q] (f : one_hom M N) (g : one_hom N P) (h : one_hom P Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] lemma mul_hom.comp_assoc {Q : Type*} [has_mul M] [has_mul N] [has_mul P] [has_mul Q] (f : mul_hom M N) (g : mul_hom N P) (h : mul_hom P Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] lemma monoid_hom.comp_assoc {Q : Type*} [mul_one_class M] [mul_one_class N] [mul_one_class P] [mul_one_class Q] (f : M →* N) (g : N →* P) (h : P →* Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl lemma monoid_with_zero_hom.comp_assoc {Q : Type*} [mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P] [mul_zero_one_class Q] (f : M →*₀ N) (g : N →*₀ P) (h : P →*₀ Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] lemma one_hom.cancel_right [has_one M] [has_one N] [has_one P] {g₁ g₂ : one_hom N P} {f : one_hom M N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, one_hom.ext $ hf.forall.2 (one_hom.ext_iff.1 h), λ h, h ▸ rfl⟩ @[to_additive] lemma mul_hom.cancel_right [has_mul M] [has_mul N] [has_mul P] {g₁ g₂ : mul_hom N P} {f : mul_hom M N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, mul_hom.ext $ hf.forall.2 (mul_hom.ext_iff.1 h), λ h, h ▸ rfl⟩ @[to_additive] lemma monoid_hom.cancel_right [mul_one_class M] [mul_one_class N] [mul_one_class P] {g₁ g₂ : N →* P} {f : M →* N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, monoid_hom.ext $ hf.forall.2 (monoid_hom.ext_iff.1 h), λ h, h ▸ rfl⟩ lemma monoid_with_zero_hom.cancel_right [mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P] {g₁ g₂ : N →*₀ P} {f : M →*₀ N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, monoid_with_zero_hom.ext $ hf.forall.2 (monoid_with_zero_hom.ext_iff.1 h), λ h, h ▸ rfl⟩ @[to_additive] lemma one_hom.cancel_left [has_one M] [has_one N] [has_one P] {g : one_hom N P} {f₁ f₂ : one_hom M N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, one_hom.ext $ λ x, hg $ by rw [← one_hom.comp_apply, h, one_hom.comp_apply], λ h, h ▸ rfl⟩ @[to_additive] lemma mul_hom.cancel_left [has_mul M] [has_mul N] [has_mul P] {g : mul_hom N P} {f₁ f₂ : mul_hom M N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, mul_hom.ext $ λ x, hg $ by rw [← mul_hom.comp_apply, h, mul_hom.comp_apply], λ h, h ▸ rfl⟩ @[to_additive] lemma monoid_hom.cancel_left [mul_one_class M] [mul_one_class N] [mul_one_class P] {g : N →* P} {f₁ f₂ : M →* N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, monoid_hom.ext $ λ x, hg $ by rw [← monoid_hom.comp_apply, h, monoid_hom.comp_apply], λ h, h ▸ rfl⟩ lemma monoid_with_zero_hom.cancel_left [mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P] {g : N →*₀ P} {f₁ f₂ : M →*₀ N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, monoid_with_zero_hom.ext $ λ x, hg $ by rw [ ← monoid_with_zero_hom.comp_apply, h, monoid_with_zero_hom.comp_apply], λ h, h ▸ rfl⟩ @[to_additive] lemma monoid_hom.to_one_hom_injective [mul_one_class M] [mul_one_class N] : function.injective (monoid_hom.to_one_hom : (M →* N) → one_hom M N) := λ f g h, monoid_hom.ext $ one_hom.ext_iff.mp h @[to_additive] lemma monoid_hom.to_mul_hom_injective [mul_one_class M] [mul_one_class N] : function.injective (monoid_hom.to_mul_hom : (M →* N) → mul_hom M N) := λ f g h, monoid_hom.ext $ mul_hom.ext_iff.mp h lemma monoid_with_zero_hom.to_monoid_hom_injective [monoid_with_zero M] [monoid_with_zero N] : function.injective (monoid_with_zero_hom.to_monoid_hom : (M →*₀ N) → M →* N) := λ f g h, monoid_with_zero_hom.ext $ monoid_hom.ext_iff.mp h lemma monoid_with_zero_hom.to_zero_hom_injective [monoid_with_zero M] [monoid_with_zero N] : function.injective (monoid_with_zero_hom.to_zero_hom : (M →*₀ N) → zero_hom M N) := λ f g h, monoid_with_zero_hom.ext $ zero_hom.ext_iff.mp h @[simp, to_additive] lemma one_hom.comp_id [has_one M] [has_one N] (f : one_hom M N) : f.comp (one_hom.id M) = f := one_hom.ext $ λ x, rfl @[simp, to_additive] lemma mul_hom.comp_id [has_mul M] [has_mul N] (f : mul_hom M N) : f.comp (mul_hom.id M) = f := mul_hom.ext $ λ x, rfl @[simp, to_additive] lemma monoid_hom.comp_id [mul_one_class M] [mul_one_class N] (f : M →* N) : f.comp (monoid_hom.id M) = f := monoid_hom.ext $ λ x, rfl @[simp] lemma monoid_with_zero_hom.comp_id [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) : f.comp (monoid_with_zero_hom.id M) = f := monoid_with_zero_hom.ext $ λ x, rfl @[simp, to_additive] lemma one_hom.id_comp [has_one M] [has_one N] (f : one_hom M N) : (one_hom.id N).comp f = f := one_hom.ext $ λ x, rfl @[simp, to_additive] lemma mul_hom.id_comp [has_mul M] [has_mul N] (f : mul_hom M N) : (mul_hom.id N).comp f = f := mul_hom.ext $ λ x, rfl @[simp, to_additive] lemma monoid_hom.id_comp [mul_one_class M] [mul_one_class N] (f : M →* N) : (monoid_hom.id N).comp f = f := monoid_hom.ext $ λ x, rfl @[simp] lemma monoid_with_zero_hom.id_comp [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N) : (monoid_with_zero_hom.id N).comp f = f := monoid_with_zero_hom.ext $ λ x, rfl @[to_additive add_monoid_hom.map_nsmul] protected theorem monoid_hom.map_pow [monoid M] [monoid N] (f : M →* N) (a : M) (n : ℕ) : f (a ^ n) = (f a) ^ n := map_pow f a n @[to_additive] protected theorem monoid_hom.map_zpow' [div_inv_monoid M] [div_inv_monoid N] (f : M →* N) (hf : ∀ x, f (x⁻¹) = (f x)⁻¹) (a : M) (n : ℤ) : f (a ^ n) = (f a) ^ n := map_zpow' f hf a n @[to_additive] theorem monoid_hom.map_div' [div_inv_monoid M] [div_inv_monoid N] (f : M →* N) (hf : ∀ x, f (x⁻¹) = (f x)⁻¹) (a b : M) : f (a / b) = f a / f b := by rw [div_eq_mul_inv, div_eq_mul_inv, f.map_mul, hf] section End namespace monoid variables (M) [mul_one_class M] /-- The monoid of endomorphisms. -/ protected def End := M →* M namespace End instance : monoid (monoid.End M) := { mul := monoid_hom.comp, one := monoid_hom.id M, mul_assoc := λ _ _ _, monoid_hom.comp_assoc _ _ _, mul_one := monoid_hom.comp_id, one_mul := monoid_hom.id_comp } instance : inhabited (monoid.End M) := ⟨1⟩ instance : has_coe_to_fun (monoid.End M) (λ _, M → M) := ⟨monoid_hom.to_fun⟩ end End @[simp] lemma coe_one : ((1 : monoid.End M) : M → M) = id := rfl @[simp] lemma coe_mul (f g) : ((f * g : monoid.End M) : M → M) = f ∘ g := rfl end monoid namespace add_monoid variables (A : Type*) [add_zero_class A] /-- The monoid of endomorphisms. -/ protected def End := A →+ A namespace End instance : monoid (add_monoid.End A) := { mul := add_monoid_hom.comp, one := add_monoid_hom.id A, mul_assoc := λ _ _ _, add_monoid_hom.comp_assoc _ _ _, mul_one := add_monoid_hom.comp_id, one_mul := add_monoid_hom.id_comp } instance : inhabited (add_monoid.End A) := ⟨1⟩ instance : has_coe_to_fun (add_monoid.End A) (λ _, A → A) := ⟨add_monoid_hom.to_fun⟩ end End @[simp] lemma coe_one : ((1 : add_monoid.End A) : A → A) = id := rfl @[simp] lemma coe_mul (f g) : ((f * g : add_monoid.End A) : A → A) = f ∘ g := rfl end add_monoid end End /-- `1` is the homomorphism sending all elements to `1`. -/ @[to_additive] instance [has_one M] [has_one N] : has_one (one_hom M N) := ⟨⟨λ _, 1, rfl⟩⟩ /-- `1` is the multiplicative homomorphism sending all elements to `1`. -/ @[to_additive] instance [has_mul M] [mul_one_class N] : has_one (mul_hom M N) := ⟨⟨λ _, 1, λ _ _, (one_mul 1).symm⟩⟩ /-- `1` is the monoid homomorphism sending all elements to `1`. -/ @[to_additive] instance [mul_one_class M] [mul_one_class N] : has_one (M →* N) := ⟨⟨λ _, 1, rfl, λ _ _, (one_mul 1).symm⟩⟩ /-- `0` is the homomorphism sending all elements to `0`. -/ add_decl_doc zero_hom.has_zero /-- `0` is the additive homomorphism sending all elements to `0`. -/ add_decl_doc add_hom.has_zero /-- `0` is the additive monoid homomorphism sending all elements to `0`. -/ add_decl_doc add_monoid_hom.has_zero @[simp, to_additive] lemma one_hom.one_apply [has_one M] [has_one N] (x : M) : (1 : one_hom M N) x = 1 := rfl @[simp, to_additive] lemma monoid_hom.one_apply [mul_one_class M] [mul_one_class N] (x : M) : (1 : M →* N) x = 1 := rfl @[simp, to_additive] lemma one_hom.one_comp [has_one M] [has_one N] [has_one P] (f : one_hom M N) : (1 : one_hom N P).comp f = 1 := rfl @[simp, to_additive] lemma one_hom.comp_one [has_one M] [has_one N] [has_one P] (f : one_hom N P) : f.comp (1 : one_hom M N) = 1 := by { ext, simp only [one_hom.map_one, one_hom.coe_comp, function.comp_app, one_hom.one_apply] } @[to_additive] instance [has_one M] [has_one N] : inhabited (one_hom M N) := ⟨1⟩ @[to_additive] instance [has_mul M] [mul_one_class N] : inhabited (mul_hom M N) := ⟨1⟩ @[to_additive] instance [mul_one_class M] [mul_one_class N] : inhabited (M →* N) := ⟨1⟩ -- unlike the other homs, `monoid_with_zero_hom` does not have a `1` or `0` instance [mul_zero_one_class M] : inhabited (M →*₀ M) := ⟨monoid_with_zero_hom.id M⟩ namespace monoid_hom variables [mM : mul_one_class M] [mN : mul_one_class N] [mP : mul_one_class P] variables [group G] [comm_group H] /-- Given two monoid morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid morphism sending `x` to `f x * g x`. -/ @[to_additive] instance {M N} {mM : mul_one_class M} [comm_monoid N] : has_mul (M →* N) := ⟨λ f g, { to_fun := λ m, f m * g m, map_one' := show f 1 * g 1 = 1, by simp, map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y), rw [f.map_mul, g.map_mul, ←mul_assoc, ←mul_assoc, mul_right_comm (f x)], end }⟩ /-- Given two additive monoid morphisms `f`, `g` to an additive commutative monoid, `f + g` is the additive monoid morphism sending `x` to `f x + g x`. -/ add_decl_doc add_monoid_hom.has_add @[simp, to_additive] lemma mul_apply {M N} {mM : mul_one_class M} {mN : comm_monoid N} (f g : M →* N) (x : M) : (f * g) x = f x * g x := rfl @[simp, to_additive] lemma one_comp [mul_one_class M] [mul_one_class N] [mul_one_class P] (f : M →* N) : (1 : N →* P).comp f = 1 := rfl @[simp, to_additive] lemma comp_one [mul_one_class M] [mul_one_class N] [mul_one_class P] (f : N →* P) : f.comp (1 : M →* N) = 1 := by { ext, simp only [map_one, coe_comp, function.comp_app, one_apply] } @[to_additive] lemma mul_comp [mul_one_class M] [comm_monoid N] [comm_monoid P] (g₁ g₂ : N →* P) (f : M →* N) : (g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl @[to_additive] lemma comp_mul [mul_one_class M] [comm_monoid N] [comm_monoid P] (g : N →* P) (f₁ f₂ : M →* N) : g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ := by { ext, simp only [mul_apply, function.comp_app, map_mul, coe_comp] } /-- If two homomorphism from a group to a monoid are equal at `x`, then they are equal at `x⁻¹`. -/ @[to_additive "If two homomorphism from an additive group to an additive monoid are equal at `x`, then they are equal at `-x`." ] lemma eq_on_inv {G} [group G] [monoid M] {f g : G →* M} {x : G} (h : f x = g x) : f x⁻¹ = g x⁻¹ := left_inv_eq_right_inv (map_mul_eq_one f $ inv_mul_self x) $ h.symm ▸ g.map_mul_eq_one $ mul_inv_self x /-- Group homomorphisms preserve inverse. -/ @[to_additive] protected theorem map_inv {G H} [group G] [group H] (f : G →* H) (g : G) : f g⁻¹ = (f g)⁻¹ := map_inv f g /-- Group homomorphisms preserve integer power. -/ @[to_additive /-" Additive group homomorphisms preserve integer scaling. "-/] protected theorem map_zpow {G H} [group G] [group H] (f : G →* H) (g : G) (n : ℤ) : f (g ^ n) = (f g) ^ n := map_zpow f g n /-- Group homomorphisms preserve division. -/ @[to_additive /-" Additive group homomorphisms preserve subtraction. "-/] protected theorem map_div {G H} [group G] [group H] (f : G →* H) (g h : G) : f (g / h) = f g / f h := map_div f g h /-- Group homomorphisms preserve division. -/ @[to_additive] protected theorem map_mul_inv {G H} [group G] [group H] (f : G →* H) (g h : G) : f (g * h⁻¹) = (f g) * (f h)⁻¹ := map_mul_inv f g h /-- A homomorphism from a group to a monoid is injective iff its kernel is trivial. For the iff statement on the triviality of the kernel, see `monoid_hom.injective_iff'`. -/ @[to_additive /-" A homomorphism from an additive group to an additive monoid is injective iff its kernel is trivial. For the iff statement on the triviality of the kernel, see `add_monoid_hom.injective_iff'`. "-/] lemma injective_iff {G H} [group G] [mul_one_class H] (f : G →* H) : function.injective f ↔ (∀ a, f a = 1 → a = 1) := ⟨λ h x, (map_eq_one_iff f h).mp, λ h x y hxy, mul_inv_eq_one.1 $ h _ $ by rw [f.map_mul, hxy, ← f.map_mul, mul_inv_self, f.map_one]⟩ /-- A homomorphism from a group to a monoid is injective iff its kernel is trivial, stated as an iff on the triviality of the kernel. For the implication, see `monoid_hom.injective_iff`. -/ @[to_additive /-" A homomorphism from an additive group to an additive monoid is injective iff its kernel is trivial, stated as an iff on the triviality of the kernel. For the implication, see `add_monoid_hom.injective_iff`. "-/] lemma injective_iff' {G H} [group G] [mul_one_class H] (f : G →* H) : function.injective f ↔ (∀ a, f a = 1 ↔ a = 1) := f.injective_iff.trans $ forall_congr $ λ a, ⟨λ h, ⟨h, λ H, H.symm ▸ f.map_one⟩, iff.mp⟩ include mM /-- Makes a group homomorphism from a proof that the map preserves multiplication. -/ @[to_additive "Makes an additive group homomorphism from a proof that the map preserves addition.", simps {fully_applied := ff}] def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G := { to_fun := f, map_mul' := map_mul, map_one' := mul_left_eq_self.1 $ by rw [←map_mul, mul_one] } omit mM /-- Makes a group homomorphism from a proof that the map preserves right division `λ x y, x * y⁻¹`. See also `monoid_hom.of_map_div` for a version using `λ x y, x / y`. -/ @[to_additive "Makes an additive group homomorphism from a proof that the map preserves the operation `λ a b, a + -b`. See also `add_monoid_hom.of_map_sub` for a version using `λ a b, a - b`."] def of_map_mul_inv {H : Type*} [group H] (f : G → H) (map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) : G →* H := mk' f $ λ x y, calc f (x * y) = f x * (f $ 1 * 1⁻¹ * y⁻¹)⁻¹ : by simp only [one_mul, one_inv, ← map_div, inv_inv] ... = f x * f y : by { simp only [map_div], simp only [mul_right_inv, one_mul, inv_inv] } @[simp, to_additive] lemma coe_of_map_mul_inv {H : Type*} [group H] (f : G → H) (map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) : ⇑(of_map_mul_inv f map_div) = f := rfl /-- Define a morphism of additive groups given a map which respects ratios. -/ @[to_additive /-"Define a morphism of additive groups given a map which respects difference."-/] def of_map_div {H : Type*} [group H] (f : G → H) (hf : ∀ x y, f (x / y) = f x / f y) : G →* H := of_map_mul_inv f (by simpa only [div_eq_mul_inv] using hf) @[simp, to_additive] lemma coe_of_map_div {H : Type*} [group H] (f : G → H) (hf : ∀ x y, f (x / y) = f x / f y) : ⇑(of_map_div f hf) = f := rfl /-- If `f` is a monoid homomorphism to a commutative group, then `f⁻¹` is the homomorphism sending `x` to `(f x)⁻¹`. -/ @[to_additive] instance {M G} [mul_one_class M] [comm_group G] : has_inv (M →* G) := ⟨λ f, mk' (λ g, (f g)⁻¹) $ λ a b, by rw [←mul_inv, f.map_mul]⟩ /-- If `f` is an additive monoid homomorphism to an additive commutative group, then `-f` is the homomorphism sending `x` to `-(f x)`. -/ add_decl_doc add_monoid_hom.has_neg @[simp, to_additive] lemma inv_apply {M G} {mM : mul_one_class M} {gG : comm_group G} (f : M →* G) (x : M) : f⁻¹ x = (f x)⁻¹ := rfl @[simp, to_additive] lemma inv_comp {M N A} {mM : mul_one_class M} {gN : mul_one_class N} {gA : comm_group A} (φ : N →* A) (ψ : M →* N) : φ⁻¹.comp ψ = (φ.comp ψ)⁻¹ := by { ext, simp only [function.comp_app, inv_apply, coe_comp] } @[simp, to_additive] lemma comp_inv {M A B} {mM : mul_one_class M} {mA : comm_group A} {mB : comm_group B} (φ : A →* B) (ψ : M →* A) : φ.comp ψ⁻¹ = (φ.comp ψ)⁻¹ := by { ext, simp only [function.comp_app, inv_apply, map_inv, coe_comp] } /-- If `f` and `g` are monoid homomorphisms to a commutative group, then `f / g` is the homomorphism sending `x` to `(f x) / (g x)`. -/ @[to_additive] instance {M G} [mul_one_class M] [comm_group G] : has_div (M →* G) := ⟨λ f g, mk' (λ x, f x / g x) $ λ a b, by simp [div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm]⟩ /-- If `f` and `g` are monoid homomorphisms to an additive commutative group, then `f - g` is the homomorphism sending `x` to `(f x) - (g x)`. -/ add_decl_doc add_monoid_hom.has_sub @[simp, to_additive] lemma div_apply {M G} {mM : mul_one_class M} {gG : comm_group G} (f g : M →* G) (x : M) : (f / g) x = f x / g x := rfl end monoid_hom /-- Given two monoid with zero morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid with zero morphism sending `x` to `f x * g x`. -/ instance {M N} {hM : mul_zero_one_class M} [comm_monoid_with_zero N] : has_mul (M →*₀ N) := ⟨λ f g, { to_fun := λ a, f a * g a, map_zero' := by rw [map_zero, zero_mul], ..(f * g : M →* N) }⟩ section commute variables [has_mul M] [has_mul N] {a x y : M} @[simp, to_additive] protected lemma semiconj_by.map [mul_hom_class F M N] (h : semiconj_by a x y) (f : F) : semiconj_by (f a) (f x) (f y) := by simpa only [semiconj_by, map_mul] using congr_arg f h @[simp, to_additive] protected lemma commute.map [mul_hom_class F M N] (h : commute x y) (f : F) : commute (f x) (f y) := h.map f end commute
using Test, Logging, Random using DecisionProgramming rng = MersenneTwister(4) @info "Testing random_diagram" @test_throws DomainError random_diagram(rng, -1, 1, 1, 1, 1) @test_throws DomainError random_diagram(rng, 1, -1, 1, 1, 1) @test_throws DomainError random_diagram(rng, 0, 0, 1, 1, 1) @test_throws DomainError random_diagram(rng, 1, 1, 0, 1, 1) @test_throws DomainError random_diagram(rng, 1, 1, 1, 0, 1) @test_throws DomainError random_diagram(rng, 1, 1, 1, 1, 0) for (n_C, n_D) in [(1, 0), (0, 1)] rng = RandomDevice() C, D, V = random_diagram(rng, n_C, n_D, 1, 1, 1) @test isa(C, Vector{ChanceNode}) @test isa(D, Vector{DecisionNode}) @test isa(V, Vector{ValueNode}) @test length(C) == n_C @test length(D) == n_D @test length(V) == 1 @test all(!isempty(v.I_j) for v in V) end @info "Testing random States" @test_throws DomainError States(rng, [0], 10) @test isa(States(rng, [2, 3], 10), States) @info "Testing random Probabilities" S = States([2, 3, 2]) c = ChanceNode(3, [1, 2]) @test isa(Probabilities(rng, c, S; n_inactive=0), Probabilities) @test isa(Probabilities(rng, c, S; n_inactive=1), Probabilities) @test isa(Probabilities(rng, c, S; n_inactive=2*3*(2-1)), Probabilities) @test_throws DomainError Probabilities(rng, c, S; n_inactive=2*3*(2-1)+1) @info "Testing random Consequences" S = States([2, 3]) v = ValueNode(3, [1, 2]) @test isa(Consequences(rng, v, S; low=-1.0, high=1.0), Consequences) @test_throws DomainError Consequences(rng, v, S; low=1.1, high=1.0) @info "Testing random LocalDecisionStrategy" S = States([2, 3, 2]) d = DecisionNode(3, [1, 2]) @test isa(LocalDecisionStrategy(rng, d, S), LocalDecisionStrategy)
#include "cnn/approximator.h" #include <string> #include <cassert> #include <vector> #include <iostream> #include <boost/lexical_cast.hpp> #include "cnn/nodes.h" #include "cnn/expr-xtra.h" #include <fstream> using namespace std; using namespace cnn::expr; using namespace cnn; namespace cnn { enum { X2C = 0, X2CB}; void ClsBasedBuilder::display(ComputationGraph& cg) { display_value(i_cls, cg); display_value(i_cls_bias, cg); for (unsigned i = 0; i < ncls; ++i) { const std::vector<Expression>& vars = param_vars[i]; for (size_t i = 0; i < vars.size(); i++) display_value(vars[i], cg); } } ClsBasedBuilder::ClsBasedBuilder( const unsigned int input_dim, const vector<int>& cls2nbrwords, /// #words for each class, class starts from 0 const vector<long>& word2cls, const vector<long>& dict_wrd_id2within_class_id, Model& model, cnn::real iscale, string name) : input_dim(input_dim), clssize(cls2nbrwords), word2cls(word2cls), dict_wrd_id2within_class_id(dict_wrd_id2within_class_id) { unsigned int n_cls = clssize.size(); p_cls = model.add_parameters({ n_cls, input_dim }, iscale, name + " to cls"); p_cls_bias = model.add_parameters({ n_cls }, iscale, name + " to cls bias"); for (size_t id = 0; id < n_cls; id++) { unsigned int clssize = cls2nbrwords[id]; p_R.push_back(model.add_parameters({ clssize, input_dim }, iscale, name + " to cls " + boost::lexical_cast<string>(id))); p_bias.push_back(model.add_parameters({ clssize }, iscale, name + " to cls bias " + boost::lexical_cast<string>(id))); } } void ClsBasedBuilder::new_graph_impl(ComputationGraph& cg) { param_vars.clear(); i_cls = parameter(cg, p_cls); i_cls_bias = parameter(cg, p_cls_bias); for (unsigned i = 0; i < clssize.size(); ++i) { Parameters* p_x2h = p_R[i]; Parameters* p_x2hb = p_bias[i]; Expression i_x2h = parameter(cg, p_x2h); Expression i_x2hb = parameter(cg, p_x2hb); vector<Expression> vars = { i_x2h, i_x2hb }; param_vars.push_back(vars); } errors.clear(); set_data_in_parallel(1); } void ClsBasedBuilder::set_data_in_parallel(int n) { dparallel = n; errors.clear(); errors.resize(n); } Expression ClsBasedBuilder::add_input_impl(const Expression &in, long target_wordid, unsigned uttid) { int cls_id = word2cls[target_wordid]; Expression newin = reshape(in, { input_dim * dparallel }); Expression x = pickrange(newin, uttid * input_dim, (uttid + 1)*input_dim); vector<Expression> param = param_vars[cls_id]; Expression i_r_t = param[X2CB] + param[X2C] * x; Expression i_c_t = i_cls_bias + i_cls * x; Expression i_err_cls = pick(log_softmax(i_c_t), cls_id); Expression i_err_prb = pick(log_softmax(i_r_t), dict_wrd_id2within_class_id[target_wordid]); errors[uttid].push_back(-(i_err_cls + i_err_prb)); return errors[uttid].back(); } vector<cnn::real> ClsBasedBuilder::respond(const Expression &in, ComputationGraph& cg) { Expression cls_log_prob = log_softmax(i_cls * in + i_cls_bias); vector<Expression> within_cls_log_prob; for (int cli = 0; cli < clssize.size(); cli++) { vector<Expression> param = param_vars[cli]; Expression i_r_t = param[X2CB] + param[X2C] * in; within_cls_log_prob.push_back(log_softmax(i_r_t)); } auto cls_dist = get_value(cls_log_prob, cg); vector<cnn::real> dist; for (int cli = 0; cli < clssize.size(); cli++){ auto within_cls_dist = get_value(within_cls_log_prob[cli], cg); vector<cnn::real> vtmp(clssize[cli], cls_dist[cli]); std::transform(within_cls_dist.begin(), within_cls_dist.end(), vtmp.begin(), within_cls_dist.begin(), std::plus<cnn::real>()); dist.insert(dist.end(), within_cls_dist.begin(), within_cls_dist.end()); } return dist; } void ClsBasedBuilder::copy(const ClsBasedBuilder& othercls) { const ClsBasedBuilder& clsref = (const ClsBasedBuilder&)othercls; assert(p_R.size() == clsref.p_R.size()); assert(p_bias.size() == clsref.p_bias.size()); for (size_t i = 0; i < clsref.p_R.size(); ++i) { p_R[i]->copy(*clsref.p_R[i]); p_bias[i]->copy(*clsref.p_bias[i]); } p_cls->copy(*clsref.p_cls); p_cls_bias->copy(*clsref.p_cls_bias); } /** dict_wrd_id2within_class_id : the dictionary word id to the id inside a class */ void ClsBasedBuilder::load_word2cls_fn(string word2clsfn, Dict& sd, std::vector<long>& wrd2cls, std::vector<long>& dict_wrd_id2within_class_id, std::vector<int> & cls2size) { ifstream in(word2clsfn); string line; /// go through one line at a time to match dictionay /// it is possible that the word clustering may have different words from the dictionary, /// so go through one more to add missing words into the dictionary vector<string> missing_words; while (getline(in, line)) { std::istringstream in(line); std::string word; in >> word; if (sd.Contains(word) == false) missing_words.push_back(word); sd.Convert(word, true); } in.close(); in.open(word2clsfn); wrd2cls.resize(sd.size()); dict_wrd_id2within_class_id.resize(sd.size(), -1); map<int, int> cls2acccnt; /// the count for each class so far while (getline(in, line)) { std::istringstream in(line); std::string word; string cls; in >> word; in >> cls; int icls = boost::lexical_cast<int>(cls)-1; int wridx = -1; if (sd.Contains(word)) { wridx = sd.Convert(word, true); wrd2cls[wridx] = icls; if (cls2acccnt.find(icls) == cls2acccnt.end()) cls2acccnt[icls] = 1; else cls2acccnt[icls] += 1; dict_wrd_id2within_class_id[wridx] = cls2acccnt[icls] - 1; } } in.close(); for (auto&p : sd.GetWordList()) { long wd = sd.Convert(p); if (wrd2cls[wd] == -1) throw("check word clustering procedure as there are words in dictionary that are not clustered"); } cls2size.clear(); for (int i = 0; i < cls2acccnt.size(); i++) { cls2size.push_back(cls2acccnt[i]); } } } // namespace cnn
(* Title: HOL/Auth/n_flash_lemma_on_inv__129.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_flash Protocol Case Study*} theory n_flash_lemma_on_inv__129 imports n_flash_base begin section{*All lemmas on causal relation between inv__129 and some rule r*} lemma n_PI_Remote_PutXVsinv__129: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_PI_Remote_PutX dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_PI_Remote_PutX dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Remote_ReplaceVsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Replace src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Replace src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Put_HeadVsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_PutVsinv__129: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_Put_HomeVsinv__129: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_1Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_2Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_3Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_4Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_5Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_6Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7__part__0Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7__part__1Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_HomeVsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8Vsinv__129: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_NODE_GetVsinv__129: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_9__part__0Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_9__part__1Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_10_HomeVsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_10Vsinv__129: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_11Vsinv__129: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_PutXVsinv__129: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_PutX_HomeVsinv__129: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_PutVsinv__129: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Put dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Put dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_PutXVsinv__129: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_PutX dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_PutX dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_InvVsinv__129: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Inv dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Inv dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__129: assumes a1: "(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__129: assumes a1: "(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "?P1 s" proof(cut_tac a1 a2 , auto) qed then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_NI_ShWbVsinv__129: assumes a1: "(r=n_NI_ShWb N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__129 p__Inv4" apply fastforce done have "?P3 s" apply (cut_tac a1 a2 , simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Cmd'')) (Const SHWB_ShWb))))" in exI, auto) done then show "invHoldForRule s f r (invariants N)" by auto qed lemma n_NI_Local_Get_Get__part__1Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_GetVsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_Get src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__0Vsinv__129: assumes a1: "r=n_PI_Local_GetX_PutX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_WbVsinv__129: assumes a1: "r=n_NI_Wb " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__129: assumes a1: "\<exists> src data. src\<le>N\<and>data\<le>N\<and>r=n_Store src data" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_GetX_GetX__part__1Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_3Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_3 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_1Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_1 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__1Vsinv__129: assumes a1: "r=n_PI_Local_GetX_GetX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__0Vsinv__129: assumes a1: "r=n_PI_Local_GetX_GetX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_Store_HomeVsinv__129: assumes a1: "\<exists> data. data\<le>N\<and>r=n_Store_Home data" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_ReplaceVsinv__129: assumes a1: "r=n_PI_Local_Replace " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_GetX_Nak__part__1Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_Get_Nak__part__1Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_Get_Get__part__0Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_existsVsinv__129: assumes a1: "\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_GetX_Nak__part__2Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_PutXVsinv__129: assumes a1: "r=n_PI_Local_PutX " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_Get_Nak__part__2Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_GetX_GetX__part__0Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_PutVsinv__129: assumes a1: "r=n_PI_Local_Get_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ReplaceVsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_GetX_Nak_HomeVsinv__129: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutXAcksDoneVsinv__129: assumes a1: "r=n_NI_Local_PutXAcksDone " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_GetX_NakVsinv__129: assumes a1: "\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_NakVsinv__129: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Nak dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_GetXVsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_GetX src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__1Vsinv__129: assumes a1: "r=n_PI_Local_GetX_PutX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Nak_HomeVsinv__129: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_Get_PutVsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_GetX_Nak__part__0Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_exists_HomeVsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_exists_Home src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Replace_HomeVsinv__129: assumes a1: "r=n_NI_Replace_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutVsinv__129: assumes a1: "r=n_NI_Local_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_NakVsinv__129: assumes a1: "\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_ClearVsinv__129: assumes a1: "r=n_NI_Nak_Clear " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_Get_Put_DirtyVsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_Get_Nak__part__0Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_GetVsinv__129: assumes a1: "r=n_PI_Local_Get_Get " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_HomeVsinv__129: assumes a1: "r=n_NI_Nak_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_2Vsinv__129: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_2 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_FAckVsinv__129: assumes a1: "r=n_NI_FAck " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__129 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
""" Gauss-Radau formula for numerical estimation of integrals. It requires :math:`m+1` points and fits all Polynomials to degree :math:`2m`, so it effectively fits exactly all Polynomials of degree :math:`2m-3`. Gauss-Radau is defined by having two abscissas to be fixed to the endpoints, while the others are built around these points. So if a distribution is defined on the interval ``(a, b)``, then both ``a`` and ``b`` are abscissas in this scheme. Note though that this does not always possible to achieve in practice, and an error might be raised. Example usage ------------- With increasing order:: >>> distribution = chaospy.Beta(2, 2, lower=-1, upper=1) >>> for order in range(4): # doctest: +NORMALIZE_WHITESPACE ... X, W = chaospy.generate_quadrature( ... order, distribution, rule="gauss_lobatto") ... print(X.round(2), W.round(2)) [[-1.]] [1.] [[-1. 1.]] [0.5 0.5] [[-1. -0.38 0.38 1. ]] [0.03 0.47 0.47 0.03] [[-1. -0.69 -0.25 0.25 0.69 1. ]] [0.01 0.15 0.35 0.35 0.15 0.01] Multivariate samples:: >>> distribution = chaospy.J(chaospy.Uniform(0, 1), chaospy.Beta(4, 5)) >>> X, W = chaospy.generate_quadrature( ... 2, distribution, rule="gauss_lobatto") >>> X.round(3) array([[-0. , -0. , -0. , -0. , 0.276, 0.276, 0.276, 0.276, 0.724, 0.724, 0.724, 0.724, 1. , 1. , 1. , 1. ], [ 0. , 0.318, 0.605, 1. , 0. , 0.318, 0.605, 1. , 0. , 0.318, 0.605, 1. , 0. , 0.318, 0.605, 1. ]]) >>> W.round(3) array([0.001, 0.045, 0.037, 0. , 0.006, 0.224, 0.184, 0.002, 0.006, 0.224, 0.184, 0.002, 0.001, 0.045, 0.037, 0. ]) """ import numpy from scipy.linalg import solve_banded, solve from .recurrence import ( construct_recurrence_coefficients, coefficients_to_quadrature) from .combine import combine_quadrature def quad_gauss_lobatto( order, dist, rule="fejer", accuracy=100, recurrence_algorithm="", ): """ Generate the abscissas and weights in Gauss-Loboto quadrature. Args: order (int): Quadrature order. dist (chaospy.distributions.baseclass.Distribution): The distribution weights to be used to create higher order nodes from. rule (str): In the case of ``lanczos`` or ``stieltjes``, defines the proxy-integration scheme. accuracy (int): In the case ``rule`` is used, defines the quadrature order of the scheme used. In practice, must be at least as large as ``order``. recurrence_algorithm (str): Name of the algorithm used to generate abscissas and weights. If omitted, ``analytical`` will be tried first, and ``stieltjes`` used if that fails. Returns: (numpy.ndarray, numpy.ndarray): abscissas: The quadrature points for where to evaluate the model function with ``abscissas.shape == (len(dist), N)`` where ``N`` is the number of samples. weights: The quadrature weights with ``weights.shape == (N,)``. Example: >>> abscissas, weights = quad_gauss_lobatto( ... 4, chaospy.Uniform(-1, 1)) >>> abscissas.round(3) array([[-1. , -0.872, -0.592, -0.209, 0.209, 0.592, 0.872, 1. ]]) >>> weights.round(3) array([0.018, 0.105, 0.171, 0.206, 0.206, 0.171, 0.105, 0.018]) """ assert not rule.startswith("gauss"), "recursive Gaussian quadrature call" if order == 0: return dist.lower.reshape(1, -1), numpy.array([1.]) coefficients = construct_recurrence_coefficients( 2*order-1, dist, rule, accuracy, recurrence_algorithm) coefficients = [_lobatto(coeffs, (lo, up)) for coeffs, lo, up in zip(coefficients, dist.lower, dist.upper)] abscissas, weights = coefficients_to_quadrature(coefficients) return combine_quadrature(abscissas, weights) def _lobatto(coefficients, preassigned): """ Compute the Lobatto nodes and weights with the preassigned value pair. Based on the section 7 of the paper Some modified matrix eigenvalue problems, Gene Golub, SIAM Review Vol 15, No. 2, April 1973, pp.318--334, and http://www.scientificpython.net/pyblog/radau-quadrature Args: coefficients (numpy.ndarray): Three terms recurrence coefficients. preassigned (Tuple[float, float]): Values that are assume to be fixed. """ alpha = numpy.array(coefficients[0]) beta = numpy.array(coefficients[1]) vec_en = numpy.zeros(len(alpha)-1) vec_en[-1] = 1 mat_a1 = numpy.vstack((numpy.sqrt(beta), alpha-preassigned[0])) mat_j1 = numpy.vstack((mat_a1[:, 0:-1], mat_a1[0, 1:])) mat_a2 = numpy.vstack((numpy.sqrt(beta), alpha - preassigned[1])) mat_j2 = numpy.vstack((mat_a2[:, 0:-1], mat_a2[0, 1:])) mat_g1 = solve_banded((1, 1), mat_j1, vec_en) mat_g2 = solve_banded((1, 1), mat_j2, vec_en) mat_c = numpy.array(((1, -mat_g1[-1]), (1, -mat_g2[-1]))) alpha[-1], beta[-1] = solve(mat_c, preassigned) return numpy.array([alpha, beta])
module Luau.Syntax where open import Agda.Builtin.Equality using (_≡_) open import Agda.Builtin.Bool using (Bool; true; false) open import Agda.Builtin.Float using (Float) open import Agda.Builtin.String using (String) open import Luau.Var using (Var) open import Luau.Addr using (Addr) open import Luau.Type using (Type) open import FFI.Data.Maybe using (Maybe; just; nothing) infixr 5 _∙_ data Annotated : Set where maybe : Annotated yes : Annotated data VarDec : Annotated → Set where var : Var → VarDec maybe var_∈_ : ∀ {a} → Var → Type → VarDec a name : ∀ {a} → VarDec a → Var name (var x) = x name (var x ∈ T) = x data FunDec : Annotated → Set where _⟨_⟩∈_ : ∀ {a} → Var → VarDec a → Type → FunDec a _⟨_⟩ : Var → VarDec maybe → FunDec maybe fun : ∀ {a} → FunDec a → VarDec a fun (f ⟨ x ⟩∈ T) = (var f ∈ T) fun (f ⟨ x ⟩) = (var f) arg : ∀ {a} → FunDec a → VarDec a arg (f ⟨ x ⟩∈ T) = x arg (f ⟨ x ⟩) = x data BinaryOperator : Set where + : BinaryOperator - : BinaryOperator * : BinaryOperator / : BinaryOperator < : BinaryOperator > : BinaryOperator == : BinaryOperator ~= : BinaryOperator <= : BinaryOperator >= : BinaryOperator ·· : BinaryOperator data Value : Set where nil : Value addr : Addr → Value number : Float → Value bool : Bool → Value string : String → Value data Block (a : Annotated) : Set data Stat (a : Annotated) : Set data Expr (a : Annotated) : Set data Block a where _∙_ : Stat a → Block a → Block a done : Block a data Stat a where function_is_end : FunDec a → Block a → Stat a local_←_ : VarDec a → Expr a → Stat a return : Expr a → Stat a data Expr a where var : Var → Expr a val : Value → Expr a _$_ : Expr a → Expr a → Expr a function_is_end : FunDec a → Block a → Expr a block_is_end : VarDec a → Block a → Expr a binexp : Expr a → BinaryOperator → Expr a → Expr a isAnnotatedᴱ : ∀ {a} → Expr a → Maybe (Expr yes) isAnnotatedᴮ : ∀ {a} → Block a → Maybe (Block yes) isAnnotatedᴱ (var x) = just (var x) isAnnotatedᴱ (val v) = just (val v) isAnnotatedᴱ (M $ N) with isAnnotatedᴱ M | isAnnotatedᴱ N isAnnotatedᴱ (M $ N) | just M′ | just N′ = just (M′ $ N′) isAnnotatedᴱ (M $ N) | _ | _ = nothing isAnnotatedᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) with isAnnotatedᴮ B isAnnotatedᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) | just B′ = just (function f ⟨ var x ∈ T ⟩∈ U is B′ end) isAnnotatedᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) | _ = nothing isAnnotatedᴱ (function _ is B end) = nothing isAnnotatedᴱ (block var b ∈ T is B end) with isAnnotatedᴮ B isAnnotatedᴱ (block var b ∈ T is B end) | just B′ = just (block var b ∈ T is B′ end) isAnnotatedᴱ (block var b ∈ T is B end) | _ = nothing isAnnotatedᴱ (block _ is B end) = nothing isAnnotatedᴱ (binexp M op N) with isAnnotatedᴱ M | isAnnotatedᴱ N isAnnotatedᴱ (binexp M op N) | just M′ | just N′ = just (binexp M′ op N′) isAnnotatedᴱ (binexp M op N) | _ | _ = nothing isAnnotatedᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) with isAnnotatedᴮ B | isAnnotatedᴮ C isAnnotatedᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) | just B′ | just C′ = just (function f ⟨ var x ∈ T ⟩∈ U is C′ end ∙ B′) isAnnotatedᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) | _ | _ = nothing isAnnotatedᴮ (function _ is C end ∙ B) = nothing isAnnotatedᴮ (local var x ∈ T ← M ∙ B) with isAnnotatedᴱ M | isAnnotatedᴮ B isAnnotatedᴮ (local var x ∈ T ← M ∙ B) | just M′ | just B′ = just (local var x ∈ T ← M′ ∙ B′) isAnnotatedᴮ (local var x ∈ T ← M ∙ B) | _ | _ = nothing isAnnotatedᴮ (local _ ← M ∙ B) = nothing isAnnotatedᴮ (return M ∙ B) with isAnnotatedᴱ M | isAnnotatedᴮ B isAnnotatedᴮ (return M ∙ B) | just M′ | just B′ = just (return M′ ∙ B′) isAnnotatedᴮ (return M ∙ B) | _ | _ = nothing isAnnotatedᴮ done = just done
If $d > 0$, then there exists a point $t$ in the ball of radius $d$ around $z$ such that $t \neq z$ and $t \in A$.
Formal statement is: proposition Lim_transform_eq: "((\<lambda>x. f x - g x) \<longlongrightarrow> 0) F \<Longrightarrow> (f \<longlongrightarrow> a) F \<longleftrightarrow> (g \<longlongrightarrow> a) F" for a :: "'a::real_normed_vector" Informal statement is: If $f$ and $g$ are two functions that converge to the same limit, then $f - g$ converges to $0$.
#pragma once #include <boost/uuid/uuid.hpp> #include <components/buffer/zmq_buffer.hpp> #include <components/configuration/configuration.hpp> #include <components/log/log.hpp> #include <components/python/python.hpp> #include <services/interactive_python/jupyter/pykernel.hpp> #include <goblin-engineer.hpp> #include <zmq.hpp> namespace services { class jupyter; class interactive_python_t final : public goblin_engineer::abstract_service { public: interactive_python_t( actor_zeta::intrusive_ptr<jupyter>, const components::python_sandbox_configuration&, components::log_t&); auto registration_step_one() -> std::vector<std::string>; auto registration(std::vector<std::string>&) -> void; auto dispatch_shell(components::zmq_buffer_t&) -> void; auto dispatch_control(components::zmq_buffer_t&) -> void; auto stop_session() -> void; auto start_session() -> void; void async_init(zmq::context_t&, boost::uuids::uuid identifier, std::function<void(const std::string&, std::vector<std::string>)>); void load(components::python_t&); private: auto jupyter_kernel_init(zmq::context_t& , boost::uuids::uuid , std::function<void(const std::string&, std::vector<std::string>)> ) -> void; auto jupyter_engine_init(boost::uuids::uuid , std::function<void(const std::string&, std::vector<std::string>)> ) -> void; components::sandbox_mode_t mode_; components::log_t log_; boost::filesystem::path jupyter_connection_path_; std::unique_ptr<components::python_t> python_interpreter_; std::unique_ptr<zmq::socket_t> stdin_socket_; boost::intrusive_ptr<interactive_python::jupyter::pykernel> jupyter_kernel_; }; } // namespace services
[STATEMENT] lemma spaceN_sum [simp]: assumes "\<And>i. i \<in> I \<Longrightarrow> x i \<in> space\<^sub>N N" shows "(\<Sum>i\<in>I. x i) \<in> space\<^sub>N N" [PROOF STATE] proof (prove) goal (1 subgoal): 1. sum x I \<in> space\<^sub>N N [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: ?i \<in> I \<Longrightarrow> x ?i \<in> space\<^sub>N N goal (1 subgoal): 1. sum x I \<in> space\<^sub>N N [PROOF STEP] by (induction I rule: infinite_finite_induct, auto)
REBOL [ System: "REBOL [R3] Language Interpreter and Run-time Environment" Title: "REBOL 3 Mezzanine: Function Helpers" Rights: { Copyright 2012 REBOL Technologies REBOL is a trademark of REBOL Technologies } License: { Licensed under the Apache License, Version 2.0 See: http://www.apache.org/licenses/LICENSE-2.0 } ] closure: func [ {Defines a closure function.} spec [block!] {Help string (opt) followed by arg words (and opt type and string)} body [block!] {The body block of the function} ][ make closure! copy/deep reduce [spec body] ] function: func [ {Defines a user function with local words.} spec [block!] {Optional help info followed by arg words (and optional type and string)} vars [block!] {List of words that are local to the function} body [block!] {The body block of the function} ][ make function! copy/deep reduce [compose [(spec) /local (vars)] body] ] has: func [ {A shortcut to define a function that has local variables but no arguments.} vars [block!] {List of words that are local to the function} body [block!] {The body block of the function} ][ make function! reduce [head insert copy/deep vars /local copy/deep body] ] context: func [ {Defines a unique object.} blk [block!] {Object words and values (modified).} ][ make object! blk ] map: func [ {Make a map value (hashed associative block).} val ][ make map! :val ] task: func [ {Creates a task.} spec [block!] {Name or spec block} body [block!] {The body block of the task} ][ make task! copy/deep reduce [spec body] ]
main : IO () main = do printLn $ cast {to = Integer} "end" printLn $ cast {to = Nat} "end" printLn $ cast {to = Double} "end" printLn $ cast {to = Bits8} "end" printLn $ cast {to = Bits16} "end" printLn $ cast {to = Bits32} "end" printLn $ cast {to = Bits64} "end" printLn $ cast {to = Int8} "end" printLn $ cast {to = Int16} "end" printLn $ cast {to = Int32} "end" printLn $ cast {to = Int64} "end" printLn $ cast {to = Int} "end"
[STATEMENT] lemma compact_space_proper_map_preimage: assumes f: "proper_map X Y f" and fim: "f ` (topspace X) = topspace Y" and "compact_space Y" shows "compact_space X" [PROOF STATE] proof (prove) goal (1 subgoal): 1. compact_space X [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. compact_space X [PROOF STEP] have eq: "topspace X = {x \<in> topspace X. f x \<in> topspace Y}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. topspace X = {x \<in> topspace X. f x \<in> topspace Y} [PROOF STEP] using fim [PROOF STATE] proof (prove) using this: f ` topspace X = topspace Y goal (1 subgoal): 1. topspace X = {x \<in> topspace X. f x \<in> topspace Y} [PROOF STEP] by blast [PROOF STATE] proof (state) this: topspace X = {x \<in> topspace X. f x \<in> topspace Y} goal (1 subgoal): 1. compact_space X [PROOF STEP] moreover [PROOF STATE] proof (state) this: topspace X = {x \<in> topspace X. f x \<in> topspace Y} goal (1 subgoal): 1. compact_space X [PROOF STEP] have "compactin Y (topspace Y)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. compactin Y (topspace Y) [PROOF STEP] using \<open>compact_space Y\<close> compact_space_def [PROOF STATE] proof (prove) using this: compact_space Y compact_space ?X \<equiv> compactin ?X (topspace ?X) goal (1 subgoal): 1. compactin Y (topspace Y) [PROOF STEP] by auto [PROOF STATE] proof (state) this: compactin Y (topspace Y) goal (1 subgoal): 1. compact_space X [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: topspace X = {x \<in> topspace X. f x \<in> topspace Y} compactin Y (topspace Y) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: topspace X = {x \<in> topspace X. f x \<in> topspace Y} compactin Y (topspace Y) goal (1 subgoal): 1. compact_space X [PROOF STEP] unfolding compact_space_def [PROOF STATE] proof (prove) using this: topspace X = {x \<in> topspace X. f x \<in> topspace Y} compactin Y (topspace Y) goal (1 subgoal): 1. compactin X (topspace X) [PROOF STEP] using eq f compactin_proper_map_preimage [PROOF STATE] proof (prove) using this: topspace X = {x \<in> topspace X. f x \<in> topspace Y} compactin Y (topspace Y) topspace X = {x \<in> topspace X. f x \<in> topspace Y} proper_map X Y f \<lbrakk>proper_map ?X ?Y ?f; compactin ?Y ?K\<rbrakk> \<Longrightarrow> compactin ?X {x \<in> topspace ?X. ?f x \<in> ?K} goal (1 subgoal): 1. compactin X (topspace X) [PROOF STEP] by fastforce [PROOF STATE] proof (state) this: compact_space X goal: No subgoals! [PROOF STEP] qed
Formal statement is: lemma contour_integral_zero: assumes "valid_path g" "path_image g \<subseteq> S" "pathfinish g = pathstart g" "f holomorphic_on S" "\<And>\<gamma> z. \<lbrakk>path \<gamma>; path_image \<gamma> \<subseteq> S; pathfinish \<gamma> = pathstart \<gamma>; z \<notin> S\<rbrakk> \<Longrightarrow> winding_number \<gamma> z = 0" shows "(f has_contour_integral 0) g" Informal statement is: If $f$ is holomorphic on a region $S$ and $g$ is a closed path in $S$, then $\int_g f(z) dz = 0$.
theory TailCallOptimization imports TailCall "../06TreeCode/TreeCode" "../00Utils/Iteration" begin fun tco_r :: "tree_code list \<Rightarrow> tco_return" where "tco_r [] = TCOReturn" | "tco_r (TApply # cd) = (case cd of [] \<Rightarrow> TCOJump | _ \<Rightarrow> tco_r cd)" | "tco_r (op # cd) = tco_r cd" fun tco_cd :: "tree_code list \<Rightarrow> tco_code list" where "tco_cd [] = []" | "tco_cd (TLookup x # cd) = TCOLookup x # tco_cd cd" | "tco_cd (TPushCon k # cd) = TCOPushCon k # tco_cd cd" | "tco_cd (TPushLam cd' # cd) = TCOPushLam (tco_cd cd') (tco_r cd') # tco_cd cd" | "tco_cd (TApply # cd) = (case cd of [] \<Rightarrow> [] | _ \<Rightarrow> TCOApply # tco_cd cd)" fun tco_cd_one :: "tree_code \<Rightarrow> tco_code" where "tco_cd_one (TLookup x) = TCOLookup x" | "tco_cd_one (TPushCon k) = TCOPushCon k" | "tco_cd_one (TPushLam cd') = TCOPushLam (tco_cd cd') (tco_r cd')" | "tco_cd_one TApply = TCOApply" definition tco :: "tree_code list \<Rightarrow> tco_code list \<times> tco_return" where "tco cd = (tco_cd cd, tco_r cd)" primrec tco_val :: "tclosure \<Rightarrow> tco_closure" where "tco_val (TConst k) = TCOConst k" | "tco_val (TLam vs cd) = TCOLam (map tco_val vs) (tco_cd cd) (tco_r cd)" fun tco_stack_frame :: "tree_stack_frame \<Rightarrow> tco_stack_frame" where "tco_stack_frame (vs, cd) = (map tco_val vs, tco_cd cd, tco_r cd)" fun live_frame :: "tco_stack_frame \<Rightarrow> bool" where "live_frame (vs, [], TCOReturn) = False" | "live_frame (vs, [], TCOJump) = True" | "live_frame (vs, op # cd, r) = True" primrec dead_frame :: "tree_stack_frame \<Rightarrow> bool" where "dead_frame (vs, cd) = (cd = [])" abbreviation tco_stack :: "tree_stack_frame list \<Rightarrow> tco_stack_frame list" where "tco_stack sfs \<equiv> filter live_frame (map tco_stack_frame sfs)" primrec tco_state :: "tree_code_state \<Rightarrow> tco_code_state" where "tco_state (TS vs sfs) = TCOS (map tco_val vs) (tco_stack sfs)" lemma tco_r_append [simp]: "cd' \<noteq> [] \<Longrightarrow> tco_r (cd @ cd') = tco_r cd'" by (induction cd) simp_all lemma [simp]: "cd \<noteq> [] \<Longrightarrow> tco_cd (op # cd) = tco_cd_one op # tco_cd cd" by (induction op) (simp_all split: list.splits) lemma tco_cd_append [simp]: "cd' \<noteq> [] \<Longrightarrow> tco_cd (cd @ cd') = map tco_cd_one cd @ tco_cd cd'" by (induction cd) simp_all lemma [simp]: "cd \<noteq> [] \<Longrightarrow> cd' \<noteq> [] \<Longrightarrow> tco_cd (cd @ cd') \<noteq> []" by (induction cd rule: tco_cd.induct) (simp_all split: list.splits) lemma [dest]: "(env, cd, r) # sfs = tco_stack sfs' \<Longrightarrow> \<exists>dsfs env' cd' sfs''. sfs' = dsfs @ (env', cd') # sfs'' \<and> env = map tco_val env' \<and> cd = tco_cd cd' \<and> r = tco_r cd' \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs''" proof (induction sfs') case (Cons sf sfs') thus ?case proof (induction sf) case (Pair env' cd') thus ?case proof (induction cd' rule: tco_cd.induct) case 1 then obtain dsfs env'' cd' sfs'' where X: "sfs' = dsfs @ (env'', cd') # sfs'' \<and> env = map tco_val env'' \<and> cd = tco_cd cd' \<and> r = tco_r cd' \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs''" by auto hence "\<exists>dsfsx. (env', []) # dsfs @ (env'', cd') # sfs'' = dsfsx @ (env'', cd') # sfs'' \<and> list_all dead_frame dsfsx \<and> sfs = tco_stack sfs''" by simp hence "\<exists>dsfsx sfs'''. (env', []) # dsfs @ (env'', cd') # sfs'' = dsfsx @ (env'', cd') # sfs''' \<and> list_all dead_frame dsfsx \<and> sfs = tco_stack sfs'''" by fastforce with X show ?case by fastforce next case (2 x cd') hence "env = map tco_val env' \<and> cd = TCOLookup x # tco_cd cd' \<and> r = tco_r cd' \<and> sfs = tco_stack sfs'" by simp thus ?case by fastforce next case (3 k cd') hence "env = map tco_val env' \<and> cd = TCOPushCon k # tco_cd cd' \<and> r = tco_r cd' \<and> sfs = tco_stack sfs'" by simp thus ?case by fastforce next case (4 cd\<^sub>l cd') hence "env = map tco_val env' \<and> cd = TCOPushLam (tco_cd cd\<^sub>l) (tco_r cd\<^sub>l) # tco_cd cd' \<and> r = tco_r cd' \<and> sfs = tco_stack sfs'" by simp thus ?case by fastforce next case (5 cd') thus ?case proof (cases cd') case Nil moreover with 5 have "env = map tco_val env' \<and> cd = [] \<and> r = TCOJump \<and> sfs = tco_stack sfs'" by simp ultimately show ?thesis by fastforce next case (Cons op cd'') moreover with 5 have "env = map tco_val env' \<and> cd = TCOApply # tco_cd (op # cd'') \<and> r = tco_r (op # cd'') \<and> sfs = tco_stack sfs'" by simp ultimately show ?thesis by fastforce qed qed qed qed simp_all lemma [dest]: "TCOS vs ((env, cd, r) # sfs) = tco_state \<Sigma> \<Longrightarrow> \<exists>dsfs vs' env' cd' sfs'. \<Sigma> = TS vs' (dsfs @ (env', cd') # sfs') \<and> vs = map tco_val vs' \<and> env = map tco_val env' \<and> cd = tco_cd cd' \<and> r = tco_r cd' \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs'" by (induction \<Sigma>) auto lemma [dest]: "TCOLookup x # cd = tco_cd cd' \<Longrightarrow> \<exists>cd''. cd' = TLookup x # cd'' \<and> cd = tco_cd cd''" by (induction cd' rule: tco_cd.induct) (simp_all split: list.splits) lemma [dest]: "TCOPushCon k # cd = tco_cd cd' \<Longrightarrow> \<exists>cd''. cd' = TPushCon k # cd'' \<and> cd = tco_cd cd''" by (induction cd' rule: tco_cd.induct) (simp_all split: list.splits) lemma [dest]: "TCOPushLam cd' r # cd = tco_cd cd\<^sub>t \<Longrightarrow> \<exists>cd\<^sub>t' cd\<^sub>t''. cd\<^sub>t = TPushLam cd\<^sub>t'' # cd\<^sub>t' \<and> cd = tco_cd cd\<^sub>t' \<and> r = tco_r cd\<^sub>t'' \<and> cd' = tco_cd cd\<^sub>t''" by (induction cd\<^sub>t rule: tco_cd.induct) (simp_all split: list.splits) lemma [dest]: "TCOApply # cd = tco_cd cd' \<Longrightarrow> \<exists>op cd''. cd' = TApply # op # cd'' \<and> cd = tco_cd (op # cd'')" by (induction cd' rule: tco_cd.induct) (simp_all split: list.splits) lemma [dest]: "TCOConst k = tco_val v \<Longrightarrow> v = TConst k" by (induction v) simp_all lemma [dest]: "TCOLam env cd r = tco_val v \<Longrightarrow> \<exists>env\<^sub>t cd\<^sub>t. v = TLam env\<^sub>t cd\<^sub>t \<and> env = map tco_val env\<^sub>t \<and> cd = tco_cd cd\<^sub>t \<and> r = tco_r cd\<^sub>t" by (induction v) simp_all lemma [dest]: "TCOReturn = tco_r cd \<Longrightarrow> [] = tco_cd cd \<Longrightarrow> cd = []" by (induction cd rule: tco_cd.induct) (simp_all split: list.splits) lemma [dest]: "TCOJump = tco_r cd \<Longrightarrow> [] = tco_cd cd \<Longrightarrow> cd = [TApply]" by (induction cd rule: tco_cd.induct) (simp_all split: list.splits) lemma [simp]: "list_all dead_frame dsfs \<Longrightarrow> iter (\<leadsto>\<^sub>t) (TS vs (dsfs @ sfs)) (TS vs sfs)" proof (induction dsfs) case (Cons sf dsfs) then obtain vs' where "sf = (vs', [])" by (cases sf) simp_all hence "TS vs ((sf # dsfs) @ sfs) \<leadsto>\<^sub>t TS vs (dsfs @ sfs)" by simp with Cons show ?case by simp qed simp_all lemma [simp]: "\<not> live_frame fr \<Longrightarrow> iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS vs (fr # sfs)) (TCOS vs sfs)" proof (induction fr rule: live_frame.induct) case (1 env) hence "TCOS vs ((env, [], TCOReturn) # sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS vs sfs" by simp thus ?case by (metis iter_one) qed simp_all lemma [simp]: "tco_cd (op # cd) = [] \<Longrightarrow> tco_r (op # cd) = TCOJump" by (induction op) (simp_all split: list.splits) lemma [simp]: "live_frame (env, cd, TCOJump)" by (induction cd) simp_all lemma tco_never_dead [simp]: "live_frame (env, tco_cd (op # cd), tco_r (op # cd))" by (induction op) (simp_all split: list.splits) theorem completetco [simp]: "tco_state \<Sigma>\<^sub>t \<leadsto>\<^sub>t\<^sub>c\<^sub>o \<Sigma>' \<Longrightarrow> full_state \<Sigma>\<^sub>t \<Longrightarrow> \<exists>\<Sigma>\<^sub>t'. iter (\<leadsto>\<^sub>t) \<Sigma>\<^sub>t \<Sigma>\<^sub>t' \<and> iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) \<Sigma>' (tco_state \<Sigma>\<^sub>t')" proof (induction "tco_state \<Sigma>\<^sub>t" \<Sigma>' rule: evaltco.induct) case (evtco_lookup env x v vs cd r sfs) then obtain dsfs vs' env' cd' sfs' where S: "\<Sigma>\<^sub>t = TS vs' (dsfs @ (env', TLookup x # cd') # sfs') \<and> vs = map tco_val vs' \<and> env = map tco_val env' \<and> cd = tco_cd cd' \<and> r = tco_r cd' \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs'" by fastforce with evtco_lookup obtain v' where V: "lookup env' x = Some v' \<and> v = tco_val v'" by fastforce from S have "iter (\<leadsto>\<^sub>t) (TS vs' (dsfs @ (env', TLookup x # cd') # sfs')) (TS vs' ((env', TLookup x # cd') # sfs'))" by simp moreover from V have "iter (\<leadsto>\<^sub>t) (TS vs' ((env', TLookup x # cd') # sfs')) (TS (v' # vs') ((env', cd') # sfs'))" by (metis evt_lookup iter_one) ultimately have X: "iter (\<leadsto>\<^sub>t) (TS vs' (dsfs @ (env', TLookup x # cd') # sfs')) (TS (v' # vs') ((env', cd') # sfs'))" by (metis iter_append) from S V have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS (v # map tco_val vs') ((map tco_val env', tco_cd cd', tco_r cd') # tco_stack sfs')) (tco_state (TS (v' # vs') ((env', cd') # sfs')))" by simp with S X show ?case by blast next case (evtco_pushcon vs env k cd r sfs) then obtain dsfs vs' env' cd' sfs' where S: "\<Sigma>\<^sub>t = TS vs' (dsfs @ (env', TPushCon k # cd') # sfs') \<and> vs = map tco_val vs' \<and> env = map tco_val env' \<and> cd = tco_cd cd' \<and> r = tco_r cd' \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs'" by fastforce hence "iter (\<leadsto>\<^sub>t) (TS vs' (dsfs @ (env', TPushCon k # cd') # sfs')) (TS vs' ((env', TPushCon k # cd') # sfs'))" by simp moreover have "iter (\<leadsto>\<^sub>t) (TS vs' ((env', TPushCon k # cd') # sfs')) (TS (TConst k # vs') ((env', cd') # sfs'))" by (metis evt_pushcon iter_one) ultimately have X: "iter (\<leadsto>\<^sub>t) (TS vs' (dsfs @ (env', TPushCon k # cd') # sfs')) (TS (TConst k # vs') ((env', cd') # sfs'))" by simp from S have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS (TCOConst k # map tco_val vs') ((map tco_val env', tco_cd cd', tco_r cd') # tco_stack sfs')) (tco_state (TS (TConst k # vs') ((env', cd') # sfs')))" by simp with S X show ?case by blast next case (evtco_pushlam vs env cd' r' cd r sfs) then obtain dsfs vs\<^sub>t env\<^sub>t cd\<^sub>t cd\<^sub>t' sfs\<^sub>t where S: "\<Sigma>\<^sub>t = TS vs\<^sub>t (dsfs @ (env\<^sub>t, TPushLam cd\<^sub>t' # cd\<^sub>t) # sfs\<^sub>t) \<and> vs = map tco_val vs\<^sub>t \<and> env = map tco_val env\<^sub>t \<and> cd = tco_cd cd\<^sub>t \<and> cd' = tco_cd cd\<^sub>t' \<and> r' = tco_r cd\<^sub>t' \<and> r = tco_r cd\<^sub>t \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs\<^sub>t" by fastforce hence "iter (\<leadsto>\<^sub>t) (TS vs\<^sub>t (dsfs @ (env\<^sub>t, TPushLam cd\<^sub>t' # cd\<^sub>t) # sfs\<^sub>t)) (TS vs\<^sub>t ((env\<^sub>t, TPushLam cd\<^sub>t' # cd\<^sub>t) # sfs\<^sub>t))" by simp moreover have "iter (\<leadsto>\<^sub>t) (TS vs\<^sub>t ((env\<^sub>t, TPushLam cd\<^sub>t' # cd\<^sub>t) # sfs\<^sub>t)) (TS (TLam env\<^sub>t cd\<^sub>t' # vs\<^sub>t) ((env\<^sub>t, cd\<^sub>t) # sfs\<^sub>t))" by (metis evt_pushlam iter_one) ultimately have X: "iter (\<leadsto>\<^sub>t) (TS vs\<^sub>t (dsfs @ (env\<^sub>t, TPushLam cd\<^sub>t' # cd\<^sub>t) # sfs\<^sub>t)) (TS (TLam env\<^sub>t cd\<^sub>t' # vs\<^sub>t) ((env\<^sub>t, cd\<^sub>t) # sfs\<^sub>t))" by simp from S have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS (TCOLam env cd' r' # map tco_val vs\<^sub>t) ((map tco_val env\<^sub>t, tco_cd cd\<^sub>t, tco_r cd\<^sub>t) # tco_stack sfs\<^sub>t)) (tco_state (TS (TLam env\<^sub>t cd\<^sub>t' # vs\<^sub>t) ((env\<^sub>t, cd\<^sub>t) # sfs\<^sub>t)))" by simp with S X show ?case by blast next case (evtco_apply v env' cd' r' vs env cd r sfs) then obtain dsfs v\<^sub>t vl vs\<^sub>t env\<^sub>t cd\<^sub>t'' sfs\<^sub>t where S: "\<Sigma>\<^sub>t = TS (v\<^sub>t # vl # vs\<^sub>t) (dsfs @ (env\<^sub>t, cd\<^sub>t'') # sfs\<^sub>t) \<and> v = tco_val v\<^sub>t \<and> TCOLam env' cd' r' = tco_val vl \<and> vs = map tco_val vs\<^sub>t \<and> env = map tco_val env\<^sub>t \<and> TCOApply # cd = tco_cd cd\<^sub>t'' \<and> r = tco_r cd\<^sub>t'' \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs\<^sub>t" by blast then obtain op cd\<^sub>t where C: "cd\<^sub>t'' = TApply # op # cd\<^sub>t \<and> cd = tco_cd (op # cd\<^sub>t)" by blast from S obtain env\<^sub>t' cd\<^sub>t' where V: "vl = TLam env\<^sub>t' cd\<^sub>t' \<and> env' = map tco_val env\<^sub>t' \<and> cd' = tco_cd cd\<^sub>t' \<and> r' = tco_r cd\<^sub>t'" by blast from S have "iter (\<leadsto>\<^sub>t) (TS (v\<^sub>t # TLam env\<^sub>t' cd\<^sub>t' # vs\<^sub>t) (dsfs @ (env\<^sub>t, TApply # op # cd\<^sub>t) # sfs\<^sub>t)) (TS (v\<^sub>t # TLam env\<^sub>t' cd\<^sub>t' # vs\<^sub>t) ((env\<^sub>t, TApply # op # cd\<^sub>t) # sfs\<^sub>t))" by simp moreover have "TS (v\<^sub>t # TLam env\<^sub>t' cd\<^sub>t' # vs\<^sub>t) ((env\<^sub>t, TApply # op # cd\<^sub>t) # sfs\<^sub>t) \<leadsto>\<^sub>t TS vs\<^sub>t ((v\<^sub>t # env\<^sub>t', cd\<^sub>t') # (env\<^sub>t, op # cd\<^sub>t) # sfs\<^sub>t)" by simp ultimately have X: "iter (\<leadsto>\<^sub>t) (TS (v\<^sub>t # TLam env\<^sub>t' cd\<^sub>t' # vs\<^sub>t) (dsfs @ (env\<^sub>t, TApply # op # cd\<^sub>t) # sfs\<^sub>t)) (TS vs\<^sub>t ((v\<^sub>t # env\<^sub>t', cd\<^sub>t') # (env\<^sub>t, op # cd\<^sub>t) # sfs\<^sub>t))" by simp from evtco_apply S V have "full_block cd\<^sub>t' 0 = Some (Suc 0)" by simp hence "live_frame (tco_val v\<^sub>t # map tco_val env\<^sub>t', tco_cd cd\<^sub>t', tco_r cd\<^sub>t')" by (induction cd\<^sub>t' rule: tco_cd.induct) (simp_all split: list.splits) with S have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS (map tco_val vs\<^sub>t) ((tco_val v\<^sub>t # map tco_val env\<^sub>t', tco_cd cd\<^sub>t', tco_r cd\<^sub>t') # (map tco_val env\<^sub>t, tco_cd (op # cd\<^sub>t), tco_r (TApply # op # cd\<^sub>t)) # tco_stack sfs\<^sub>t)) (tco_state (TS vs\<^sub>t ((v\<^sub>t # env\<^sub>t', cd\<^sub>t') # (env\<^sub>t, op # cd\<^sub>t) # sfs\<^sub>t)))" by simp with S C V X show ?case by blast next case (evtco_return vs env sfs) then obtain dsfs vs' env' sfs' where S: "\<Sigma>\<^sub>t = TS vs' (dsfs @ (env', []) # sfs') \<and> vs = map tco_val vs' \<and> env = map tco_val env' \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs'" by blast hence "iter (\<leadsto>\<^sub>t) (TS vs' (dsfs @ (env', []) # sfs')) (TS vs' ((env', []) # sfs'))" by simp moreover have "iter (\<leadsto>\<^sub>t) (TS vs' ((env', []) # sfs')) (TS vs' sfs')" by (simp add: iter_one) ultimately have X: "iter (\<leadsto>\<^sub>t) (TS vs' (dsfs @ (env', []) # sfs')) (TS vs' sfs')" by simp from S have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS vs sfs) (tco_state (TS vs' sfs'))" by simp with S X show ?case by blast next case (evtco_jump v env' cd' r' vs env sfs) then obtain dsfs v\<^sub>t vl vs\<^sub>t env\<^sub>t cd\<^sub>t sfs\<^sub>t where S: "\<Sigma>\<^sub>t = TS (v\<^sub>t # vl # vs\<^sub>t) (dsfs @ (env\<^sub>t, cd\<^sub>t) # sfs\<^sub>t) \<and> v = tco_val v\<^sub>t \<and> TCOLam env' cd' r' = tco_val vl \<and> vs = map tco_val vs\<^sub>t \<and> env = map tco_val env\<^sub>t \<and> [] = tco_cd cd\<^sub>t \<and> TCOJump = tco_r cd\<^sub>t \<and> list_all dead_frame dsfs \<and> sfs = tco_stack sfs\<^sub>t" by blast then obtain env\<^sub>t' cd\<^sub>t' where V: "vl = TLam env\<^sub>t' cd\<^sub>t' \<and> env' = map tco_val env\<^sub>t' \<and> cd' = tco_cd cd\<^sub>t' \<and> r' = tco_r cd\<^sub>t'" by blast from S have C: "cd\<^sub>t = [TApply]" by blast with S have "iter (\<leadsto>\<^sub>t) (TS (v\<^sub>t # TLam env\<^sub>t' cd\<^sub>t' # vs\<^sub>t) (dsfs @ (env\<^sub>t, [TApply]) # sfs\<^sub>t)) (TS (v\<^sub>t # TLam env\<^sub>t' cd\<^sub>t' # vs\<^sub>t) ((env\<^sub>t, [TApply]) # sfs\<^sub>t))" by simp moreover have "iter (\<leadsto>\<^sub>t) (TS (v\<^sub>t # TLam env\<^sub>t' cd\<^sub>t' # vs\<^sub>t) ((env\<^sub>t, [TApply]) # sfs\<^sub>t)) (TS vs\<^sub>t ((v\<^sub>t # env\<^sub>t', cd\<^sub>t') # (env\<^sub>t, []) # sfs\<^sub>t))" by (simp add: iter_one) ultimately have X: "iter (\<leadsto>\<^sub>t) (TS (v\<^sub>t # TLam env\<^sub>t' cd\<^sub>t' # vs\<^sub>t) (dsfs @ (env\<^sub>t, [TApply]) # sfs\<^sub>t)) (TS vs\<^sub>t ((v\<^sub>t # env\<^sub>t', cd\<^sub>t') # (env\<^sub>t, []) # sfs\<^sub>t))" using iter_append by fastforce have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS (map tco_val vs\<^sub>t) ((tco_val v\<^sub>t # map tco_val env\<^sub>t', tco_cd cd\<^sub>t', tco_r cd\<^sub>t') # tco_stack sfs\<^sub>t)) (tco_state (TS vs\<^sub>t ((v\<^sub>t # env\<^sub>t', cd\<^sub>t') # (env\<^sub>t, []) # sfs\<^sub>t)))" by simp with S V C X show ?case by blast qed theorem correcttco [simp]: "\<Sigma> \<leadsto>\<^sub>t \<Sigma>' \<Longrightarrow> iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (tco_state \<Sigma>) (tco_state \<Sigma>')" proof (induction \<Sigma> \<Sigma>' rule: evalt.induct) case (evt_lookup env x v vs cd sfs) thus ?case proof (cases cd) case Nil have "TCOS (tco_val v # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (tco_val v # map tco_val vs) (tco_stack sfs)" by (metis evtco_return) hence "TCOS (tco_val v # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS (v # vs) ((env, []) # sfs))" by simp moreover from evt_lookup have "tco_state (TS vs ((env, [TLookup x]) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (tco_val v # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs)" by simp ultimately have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (tco_state (TS vs ((env, [TLookup x]) # sfs))) (tco_state (TS (v # vs) ((env, []) # sfs)))" by (metis iter_refl iter_step) with Nil show ?thesis by simp next case (Cons op cd) moreover from evt_lookup have "tco_state (TS vs ((env, TLookup x # op # cd) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS (v # vs) ((env, op # cd) # sfs))" by simp ultimately show ?thesis by (metis iter_one) qed next case (evt_pushcon vs env k cd sfs) thus ?case proof (cases cd) case Nil have "TCOS (TCOConst k # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (TCOConst k # map tco_val vs) (tco_stack sfs)" by (metis evtco_return) hence "TCOS (TCOConst k # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS (TConst k # vs) ((env, []) # sfs))" by simp moreover have "tco_state (TS vs ((env, [TPushCon k]) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (TCOConst k # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs)" by simp ultimately have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (tco_state (TS vs ((env, [TPushCon k]) # sfs))) (tco_state (TS (TConst k # vs) ((env, []) # sfs)))" by (metis iter_refl iter_step) with Nil show ?thesis by simp next case (Cons op cd) moreover have "tco_state (TS vs ((env, TPushCon k # op # cd) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS (TConst k # vs) ((env, op # cd) # sfs))" by simp ultimately show ?thesis by (metis iter_one) qed next case (evt_pushlam vs env cd' cd sfs) thus ?case proof (cases cd) case Nil have "TCOS (map tco_val vs) ((map tco_val env, [TCOPushLam (tco_cd cd') (tco_r cd')], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (TCOLam (map tco_val env) (tco_cd cd') (tco_r cd') # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs)" by (metis evtco_pushlam) hence X: "tco_state (TS vs ((env, [TPushLam cd']) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (TCOLam (map tco_val env) (tco_cd cd') (tco_r cd') # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs)" by simp have "TCOS (TCOLam (map tco_val env) (tco_cd cd') (tco_r cd') # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (TCOLam (map tco_val env) (tco_cd cd') (tco_r cd') # map tco_val vs) (tco_stack sfs)" by (metis evtco_return) hence "TCOS (TCOLam (map tco_val env) (tco_cd cd') (tco_r cd') # map tco_val vs) ((map tco_val env, [], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS (TLam env cd' # vs) ((env, []) # sfs))" by simp with X have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (tco_state (TS vs ((env, [TPushLam cd']) # sfs))) (tco_state (TS (TLam env cd' # vs) ((env, []) # sfs)))" by (metis iter_refl iter_step) with Nil show ?thesis by simp next case (Cons op cd) have "TCOS (map tco_val vs) ((map tco_val env, TCOPushLam (tco_cd cd') (tco_r cd') # tco_cd (op # cd), tco_r (op # cd)) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (TCOLam (map tco_val env) (tco_cd cd') (tco_r cd') # map tco_val vs) ((map tco_val env, tco_cd (op # cd), tco_r (op # cd)) # tco_stack sfs)" by (metis evtco_pushlam) hence "tco_state (TS vs ((env, TPushLam cd' # op # cd) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS (TLam env cd' # vs) ((env, op # cd) # sfs))" by simp with Cons show ?thesis by (metis iter_one) qed next case (evt_apply v env' cd' vs env cd sfs) thus ?case proof (cases cd) case Nil note CD = Nil thus ?thesis proof (cases cd') case Nil have "TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (map tco_val vs) (tco_stack sfs)" by (metis evtco_return) hence "TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS vs ((v # env', []) # (env, []) # sfs))" by simp hence X: "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # tco_stack sfs)) (tco_state (TS vs ((v # env', []) # (env, []) # sfs)))" by (metis iter_one) have "TCOS (tco_val v # TCOLam (map tco_val env') [] TCOReturn # map tco_val vs) ((map tco_val env, [], TCOJump) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # tco_stack sfs)" by (metis evtco_jump) hence "tco_state (TS (v # TLam env' [] # vs) ((env, [TApply]) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # tco_stack sfs)" by simp with X have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (tco_state (TS (v # TLam env' [] # vs) ((env, [TApply]) # sfs))) (tco_state (TS vs ((v # env', []) # (env, []) # sfs)))" using iter_step by fast with CD Nil show ?thesis by simp next case (Cons op' cd'') have "TCOS (tco_val v # TCOLam (map tco_val env') (tco_cd (op' # cd'')) (tco_r (op' # cd'')) # map tco_val vs) ((map tco_val env, [], TCOJump) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (map tco_val vs) ((tco_val v # map tco_val env', tco_cd (op' # cd''), tco_r (op' # cd'')) # tco_stack sfs)" by (metis evtco_jump) hence "tco_state (TS (v # TLam env' (op' # cd'') # vs) ((env, [TApply]) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS vs ((v # env', op' # cd'') # (env, []) # sfs))" by simp with Nil Cons show ?thesis by (metis iter_one) qed next case (Cons op cd) note CD = Cons thus ?thesis proof (cases cd') case Nil have "TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # (map tco_val env, tco_cd (op # cd), tco_r (op # cd)) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (map tco_val vs) ((map tco_val env, tco_cd (op # cd), tco_r (op # cd)) # tco_stack sfs)" by (metis evtco_return) hence "TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # (map tco_val env, tco_cd (op # cd), tco_r (op # cd)) # tco_stack sfs) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS vs ((v # env', []) # (env, op # cd) # sfs))" by simp hence X: "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # (map tco_val env, tco_cd (op # cd), tco_r (op # cd)) # tco_stack sfs)) (tco_state (TS vs ((v # env', []) # (env, op # cd) # sfs)))" by (metis iter_one) have "tco_state (TS (v # TLam env' [] # vs) ((env, TApply # op # cd) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o TCOS (map tco_val vs) ((tco_val v # map tco_val env', [], TCOReturn) # (map tco_val env, tco_cd (op # cd), tco_r (op # cd)) # tco_stack sfs)" by simp with X have "iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (tco_state (TS (v # TLam env' [] # vs) ((env, TApply # op # cd) # sfs))) (tco_state (TS vs ((v # env', []) # (env, op # cd) # sfs)))" using iter_step by fast with Cons Nil show ?thesis by simp next case (Cons op' cd') have "tco_state (TS (v # TLam env' (op' # cd') # vs) ((env, TApply # op # cd) # sfs)) \<leadsto>\<^sub>t\<^sub>c\<^sub>o tco_state (TS vs ((v # env', (op' # cd')) # (env, op # cd) # sfs))" by simp with CD Cons show ?thesis by (metis iter_one) qed qed qed simp_all lemma iter_tco_eval [simp]: "iter (\<leadsto>\<^sub>t) \<Sigma> \<Sigma>' \<Longrightarrow> iter (\<leadsto>\<^sub>t\<^sub>c\<^sub>o) (tco_state \<Sigma>) (tco_state \<Sigma>')" by (induction \<Sigma> \<Sigma>' rule: iter.induct) (simp, metis iter_append correcttco) end
{- Formal verification of authenticated append-only skiplists in Agda, version 1.0. Copyright (c) 2020 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 Data.Unit.NonEta open import Data.Empty open import Data.Sum open import Data.Product open import Data.Product.Properties hiding (≡-dec) open import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_) open import Data.Nat.Properties open import Data.List renaming (map to List-map) open import Data.List.Properties using (∷-injective; ≡-dec) open import Data.List.Relation.Unary.Any open import Data.List.Relation.Unary.All open import Data.Bool hiding (_<_; _≤_) renaming (_≟_ to _≟Bool_) open import Data.Maybe renaming (map to Maybe-map) open import Function open import Relation.Binary.PropositionalEquality open import Relation.Binary.Core open import Relation.Nullary -- This module defins a type to represent hashes, functions for encoding -- them, and properties about them module AAOSL.Abstract.Hash where open import AAOSL.Lemmas -- We define a ByteString as a list of bits ByteString : Set ByteString = List Bool -- TODO-1 : Hash -> Digest (to be consistent with the paper)? Or just comment? Hash : Set Hash = Σ ByteString (λ bs → length bs ≡ 32) _≟Hash_ : (h₁ h₂ : Hash) → Dec (h₁ ≡ h₂) (l , pl) ≟Hash (m , pm) with ≡-dec _≟Bool_ l m ...| yes refl = yes (cong (_,_ l) (≡-irrelevant pl pm)) ...| no abs = no (abs ∘ ,-injectiveˡ) encodeH : Hash → ByteString encodeH (bs , _) = bs encodeH-inj : ∀ i j → encodeH i ≡ encodeH j → i ≡ j encodeH-inj (i , pi) (j , pj) refl = cong (_,_ i) (≡-irrelevant pi pj) encodeH-len : ∀{h} → length (encodeH h) ≡ 32 encodeH-len { bs , p } = p encodeH-len-lemma : ∀ i j → length (encodeH i) ≡ length (encodeH j) encodeH-len-lemma i j = trans (encodeH-len {i}) (sym (encodeH-len {j})) -- This means that we can make a helper function that combines -- the necessary injections into one big injection ++b-2-inj : (h₁ h₂ : Hash){l₁ l₂ : Hash} → encodeH h₁ ++ encodeH l₁ ≡ encodeH h₂ ++ encodeH l₂ → h₁ ≡ h₂ × l₁ ≡ l₂ ++b-2-inj h₁ h₂ {l₁} {l₂} hip with ++-inj {m = encodeH h₁} {n = encodeH h₂} (encodeH-len-lemma h₁ h₂) hip ...| hh , ll = encodeH-inj h₁ h₂ hh , encodeH-inj l₁ l₂ ll Collision : {A B : Set}(f : A → B)(a₁ a₂ : A) → Set Collision f a₁ a₂ = a₁ ≢ a₂ × f a₁ ≡ f a₂ module WithCryptoHash -- A Hash function maps a bytestring into a hash. (hash : ByteString → Hash) (hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y) where HashBroke : Set HashBroke = Σ ( ByteString × ByteString ) (λ { (x₁ , x₂) → Collision hash x₁ x₂ }) hash-concat : List Hash → Hash hash-concat l = hash (concat (List-map encodeH l)) -- hash-concat isinjective, modulo hash collisions hash-concat-inj : ∀{l₁ l₂} → hash-concat l₁ ≡ hash-concat l₂ → HashBroke ⊎ l₁ ≡ l₂ hash-concat-inj {[]} {x ∷ xs} h with hash-cr h ...| inj₁ col = inj₁ (([] , encodeH x ++ foldr _++_ [] (List-map encodeH xs)) , col) ...| inj₂ abs = ⊥-elim (++-abs (encodeH x) (subst (1 ≤_) (sym (encodeH-len {x})) (s≤s z≤n)) abs) hash-concat-inj {x ∷ xs} {[]} h with hash-cr h ...| inj₁ col = inj₁ ((encodeH x ++ foldr _++_ [] (List-map encodeH xs) , []) , col) ...| inj₂ abs = ⊥-elim (++-abs (encodeH x) (subst (1 ≤_) (sym (encodeH-len {x})) (s≤s z≤n)) (sym abs)) hash-concat-inj {[]} {[]} h = inj₂ refl hash-concat-inj {x ∷ xs} {y ∷ ys} h with hash-cr h ...| inj₁ col = inj₁ ((encodeH x ++ foldr _++_ [] (List-map encodeH xs) , encodeH y ++ foldr _++_ [] (List-map encodeH ys)) , col) ...| inj₂ res with ++-inj {m = encodeH x} {n = encodeH y} (encodeH-len-lemma x y) res ...| xy , xsys with hash-concat-inj {l₁ = xs} {l₂ = ys} (cong hash xsys) ...| inj₁ hb = inj₁ hb ...| inj₂ final = inj₂ (cong₂ _∷_ (encodeH-inj x y xy) final)
[STATEMENT] lemma bdd_aboveI2: assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le>\<^sub>a M" shows "bdd_above (f ` A)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. local.bdd_above (f ` A) [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: ?x \<in> A \<Longrightarrow> f ?x \<le>\<^sub>a M goal (1 subgoal): 1. local.bdd_above (f ` A) [PROOF STEP] by force
Require Import Crypto.Arithmetic.PrimeFieldTheorems. Require Import Crypto.Specific.montgomery32_2e495m31_16limbs.Synthesis. (* TODO : change this to field once field isomorphism happens *) Definition opp : { opp : feBW_small -> feBW_small | forall a, phiM_small (opp a) = F.opp (phiM_small a) }. Proof. Set Ltac Profiling. Time synthesize_opp (). Show Ltac Profile. Time Defined. Print Assumptions opp.
module Sub02Apply54x12 import ProofColDivSeqBase import ProofColDivSeqPostulate import ProofColDivSeqPostuProof %default total -- %language ElabReflection -- 3(18x+4) --A[6,-4]->E[2,-4]--> 3(2x) export apply54x12 : (Not . P) (S (S (plus (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (plus (plus (plus l l) l) (plus (plus l l) l)))))) -> (m : Nat ** (LTE (S m) (S (S (plus (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (plus (plus (plus l l) l) (plus (plus l l) l)))))), (Not . P) m)) apply54x12 {l} col = ((plus l l) ** (lte54x12 l, ae54x12To6x l col)) where lte54x12 : (l:Nat) -> LTE (S (plus l l)) (S (S (plus (plus (plus (plus (plus l l) l) (plus (plus l l) l)) (S (plus (plus (plus l l) l) (plus (plus l l) l)))) (S (plus (plus (plus l l) l) (plus (plus l l) l)))))) lte54x12 Z = LTESucc LTEZero lte54x12 (S k) = let lemma = lte54x12 k in rewrite (sym (plusSuccRightSucc k k)) in rewrite (sym (plusSuccRightSucc (plus k k) k)) in rewrite (sym (plusSuccRightSucc (plus (plus k k) k) (S (S (plus (plus k k) k))))) in rewrite (sym (plusSuccRightSucc (plus (plus k k) k) (S (plus (plus k k) k)))) in rewrite (sym (plusSuccRightSucc (plus (plus k k) k) (plus (plus k k) k))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus k k) k) (plus (plus k k) k)) (S (S (S (S (S (S (plus (plus (plus k k) k) (plus (plus k k) k)))))))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus k k) k) (plus (plus k k) k)) (S (S (S (S (S (plus (plus (plus k k) k) (plus (plus k k) k))))))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus k k) k) (plus (plus k k) k)) (S (S (S (S (plus (plus (plus k k) k) (plus (plus k k) k)))))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus k k) k) (plus (plus k k) k)) (S (S (S (plus (plus (plus k k) k) (plus (plus k k) k))))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus k k) k) (plus (plus k k) k)) (S (S (plus (plus (plus k k) k) (plus (plus k k) k)))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus k k) k) (plus (plus k k) k)) (S (plus (plus (plus k k) k) (plus (plus k k) k))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus k k) k) (plus (plus k k) k)) (S (plus (plus (plus k k) k) (plus (plus k k) k)))) (S (S (S (S (S (S (plus (plus (plus k k) k) (plus (plus k k) k)))))))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus k k) k) (plus (plus k k) k)) (S (plus (plus (plus k k) k) (plus (plus k k) k)))) (S (S (S (S (S (plus (plus (plus k k) k) (plus (plus k k) k))))))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus k k) k) (plus (plus k k) k)) (S (plus (plus (plus k k) k) (plus (plus k k) k)))) (S (S (S (S (plus (plus (plus k k) k) (plus (plus k k) k)))))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus k k) k) (plus (plus k k) k)) (S (plus (plus (plus k k) k) (plus (plus k k) k)))) (S (S (S (plus (plus (plus k k) k) (plus (plus k k) k))))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus k k) k) (plus (plus k k) k)) (S (plus (plus (plus k k) k) (plus (plus k k) k)))) (S (S (plus (plus (plus k k) k) (plus (plus k k) k)))))) in rewrite (sym (plusSuccRightSucc (plus (plus (plus (plus k k) k) (plus (plus k k) k)) (S (plus (plus (plus k k) k) (plus (plus k k) k)))) (S (plus (plus (plus k k) k) (plus (plus k k) k))))) in (lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . lteSuccRight . LTESucc . LTESucc) lemma
module lib.Library5 import lib.sub.Sub export salute5 : String salute5 = "Hello, this is Library5" ++ subslaute
import astropy.io.fits import numpy as np import matplotlib.pyplot as plt # Create an empty numpy array. 2D; spectra with 4 data elements. filtered = np.zeros((2040,4)) combined_extracted_1d_spectra_ = astropy.io.fits.open("xtfbrsnN20160705S0025.fits") exptime = float(combined_extracted_1d_spectra_[0].header['EXPTIME']) wstart = combined_extracted_1d_spectra_[1].header['CRVAL1'] wdelt = combined_extracted_1d_spectra_[1].header['CD1_1'] for i in range(len(filtered)): filtered[i][0] = wstart + (i*wdelt) print "Wavelength array: \n", filtered f = open("hk.txt") lines = f.readlines() f.close() lines = [lines[i].strip().split() for i in range(len(lines))] for i in range(len(lines)): lines[i][0] = float(lines[i][0])*10**4 for i in range(len(filtered)): mindif = min(lines, key=lambda x:abs(x[0]-filtered[i][0])) filtered[i][1] = mindif[2] calibspec = np.load("calibspec.npy") """ effspec = np.load("effspec.npy") print "Effspec:\n", effspec calibspec = np.zeros((2040)) for i in range(len(effspec)): if effspec[i] != 0: calibspec[i] = combined_extracted_1d_spectra_[1].data[i]/exptime/effspec[i] else: calibspec[i] = 0 """ filter_weighted_flux = [] temp_percentages = [] for i in range(len(calibspec)): filtered[i][2] = calibspec[i] filtered[i][3] = filtered[i][1] * filtered[i][2] * 0.01 filter_weighted_flux.append(filtered[i][3]) temp_percentages.append(filtered[i][1]*0.01) print "\nIntegral of filter_weighted_flux:" print np.trapz(filter_weighted_flux) print "\nIntegral of percentages:" print np.trapz(temp_percentages) print "Integral of filter_weighted_flux divided by integral of percentages:" print np.trapz(filter_weighted_flux)/np.trapz(temp_percentages) plt.figure(1) plt.plot(calibspec) plt.plot(filter_weighted_flux, "r--") plt.figure(2) plt.plot(temp_percentages) plt.show()
# sliding window size window_size <- 100000 # turn off scientific notation for output with large numbers in sliding windows options(scipen=999) # read in simple vcf vcf_names <- c("Dryobates_nuttallii_KU123600", "Dryobates_scalaris_KU128764", "Dryobates_scalaris_KU128776", "Dryobates_scalaris_KU128777", "Dryobates_scalaris_KU29797", "Dryobates_scalaris_KU30061", "Dryobates_nuttallii_KU123601", "Dryobates_nuttallii_KU131213", "Dryobates_nuttallii_KU29815", "Dryobates_nuttallii_KU29816", "Dryobates_pubescens_KU11987", "Dryobates_pubescens_KU130208", "Dryobates_pubescens_KU132134", "Dryobates_pubescens_KU15939") # read in reference index x <- read.table("Picoides_pubescens.fa.fai", sep="\t") x.list <- as.character(x[x[,2] >= 1000000,1]) #scaffold list of those > 1 Mbp # TE polymorphisms MELT <- read.table("MELT_for_ROH.txt", sep="\t", stringsAsFactors=F, header=T) # individual runs of homozygosity roh <- read.table("runs_of_homozygosity.txt", sep="\t", stringsAsFactors=F, header=T) # TEs TEs <- read.table("repeatmask.txt", sep="\t", stringsAsFactors=F) # genes genes <- read.table("genes.txt", sep="\t", stringsAsFactors=F) # loop for each scaffold # output headers = scaffold, start, end, prop TEs, prop genes output <- c() for(a in 1:length(x.list)) { num_windows <- floor(x[x[,1] == x.list[a], 2] / window_size) start <- 1 end <- window_size a_TEs <- TEs[TEs[,1] %in% x.list[a], ] a_genes <- genes[genes[,1] %in% x.list[a], ] # for each window for(b in 1:num_windows) { b_TEs <- a_TEs[a_TEs[,2] >= start & a_TEs[,2] <= end | a_TEs[,3] >= start & a_TEs[,3] <= end,] b_genes <- a_genes[a_genes[,2] >= start & a_genes[,2] <= end | a_genes[,3] >= start & a_genes[,3] <= end,] if(nrow(b_TEs) > 0) { b_TEs[b_TEs[,3] > end, 3] <- end b_TEs[b_TEs[,2] < start, 2] <- start b_seq <- c() for(c in 1:nrow(b_TEs)) { b_seq <- c(b_seq, b_TEs[c,2]:b_TEs[c,3]) } b_TE_count <- length(unique(b_seq)) / window_size } else { b_TE_count <- 0 } if(nrow(b_genes) > 0) { b_genes[b_genes[,3] > end, 3] <- end b_genes[b_genes[,2] < start, 2] <- start b_seq <- c() for(c in 1:nrow(b_genes)) { b_seq <- c(b_seq, b_genes[c,2]: b_genes[c,3]) } b_gene_count <- length(unique(b_seq)) / window_size if(b_gene_count > 1) { print(c(a,b)) } } else { b_gene_count <- 0 } output <- rbind(output, c(x.list[a], start, end, b_TE_count, b_gene_count)) start <- start + window_size end <- end + window_size } } output <- data.frame(Scaffold=as.character(output[,1]), Start=as.numeric(output[,2]), End=as.numeric(output[,3]), Prop_TEs=as.numeric(output[,4]), Prop_Genes=as.numeric(output[,5])) # loop for each individual output2 <- list() for(a in 1:length(vcf_names)) { a_roh <- roh[roh[,1] == vcf_names[a],] a_melt <- MELT[MELT[,1] == vcf_names[a],] output_rep <- c() # loop for each window for(b in 1:nrow(output)) { b_roh <- a_roh[a_roh[,2] == output[b,1], ] b_roh <- b_roh[b_roh[,3] >= output[b,2] & b_roh[,3] <= output[b,3] | b_roh[,4] >= output[b,2] & b_roh[,4] <= output[b,3],] b_melt <- a_melt[a_melt[,2] == output[b,1],] b_melt <- b_melt[b_melt[,3] >= output[b,2] & b_melt[,3] <= output[b,3],] sum_NR_TE <- nrow(b_melt) sum_NR_TE_poly <- nrow(b_melt[b_melt$het == "het",]) if(nrow(b_roh) > 0) { b_roh[b_roh[,4] > output[b,3], 3] <- output[b,3] b_roh[b_roh[,3] < output[b,2], 2] <- output[b,2] sum_b_roh <- sum(b_roh[,4] - b_roh[,3] + 1) / window_size } else { sum_b_roh <- 0 } output_rep <- rbind(output_rep, c(as.character(output[b,1]), as.numeric(output[b,2:5]), sum_b_roh, sum_NR_TE, sum_NR_TE_poly)) } output2[[a]] <- output_rep } # convert all output to dataframes for(a in 1:length(vcf_names)) { output2[[a]] <- data.frame(Scaffold=as.character(output2[[a]][,1]), Start=as.numeric(output2[[a]][,2]), End=as.numeric(output2[[a]][,3]), Prop_ROH=as.numeric(output2[[a]][,6]), Prop_TEs=as.numeric(output2[[a]][,4]), Prop_Genes=as.numeric(output2[[a]][,5]), Num_NR_TEs=as.numeric(output2[[a]][,7]), Num_Poly_NR_TEs=as.numeric(output2[[a]][,8])) } # correlation coefficients for each individual require(Hmisc) output_corr <- c() for(a in 1:length(vcf_names)) { a_rep <- rcorr(as.matrix(output2[[a]][,4:8]))$r a_rep <- c(vcf_names[a], as.vector(a_rep[2:nrow(a_rep), 1])) output_corr <- rbind(output_corr, a_rep) } output_corr <- data.frame(Individual=as.character(output_corr[,1]), TE_corr=as.numeric(output_corr[,2]), Gene_Corr=as.numeric(output_corr[,3]), Num_NR_TEs_corr=as.numeric(output_corr[,4]), Num_Poly_NR_TEs_corr=as.numeric(output_corr[,5])) # confidence intervals on correlation coefficients require(boot) require(DescTools) bootstrap.effect <- function(input, indices) { d <- input[indices] d <- FisherZ(d) d <- mean(d) d <- FisherZInv(d) return(d) } output3 <- c() # tes results <- boot(data=output_corr$TE_corr, statistic=bootstrap.effect, R=1000) ci <- boot.ci(results) ci2 <- c("TEs", mean(results$data), ci$bca[4:5]) output3 <- rbind(output3, ci2) # genes results <- boot(data=output_corr$Gene_Corr, statistic=bootstrap.effect, R=1000) ci <- boot.ci(results) ci2 <- c("Genes", mean(results$data), ci$bca[4:5]) output3 <- rbind(output3, ci2) #non-reference tes results <- boot(data=output_corr$Num_NR_TEs_corr, statistic=bootstrap.effect, R=1000) ci <- boot.ci(results) ci2 <- c("NR_TEs", mean(results$data), ci$bca[4:5]) output3 <- rbind(output3, ci2) # polymorphic non-reference tes results <- boot(data=output_corr$Num_Poly_NR_TEs_corr, statistic=bootstrap.effect, R=1000) ci <- boot.ci(results) ci2 <- c("NR_Poly_TEs", mean(results$data), ci$bca[4:5]) output3 <- rbind(output3, ci2) output3 <- data.frame(Dataset=as.character(output3[,1]), Mean=as.numeric(output3[,2]), CI_low=as.numeric(output3[,3]), CI_high=as.numeric(output3[,4])) write(paste("# Mean effect sizes (correlation coefficients) with ROH proportion per 100 kbp window"), file="per_100kbp_window_effect_sizes.txt", sep="\t") write.table(output3, file="per_100kbp_window_effect_sizes.txt", sep="\t", row.names=F, quote=F, append=T)
theory SeqLock_Lib imports Main Lib_ProofRules AbstractLock_Lib begin datatype PC = L1 | L2 | L3 | L4 consts t1 :: T consts t2 :: T consts glb :: L consts l :: L record prog_state = pc :: "T \<Rightarrow> PC" r :: "T \<Rightarrow> V" loc :: "T \<Rightarrow> bool" record refinement_rel = write_rel :: "(L\<times>TS) \<Rightarrow> (L\<times>TS)" definition "update_pc t nv pcf \<equiv> pcf (t := nv)" definition "update_loc t nv pcf \<equiv> pcf (t := nv)" definition seqLock :: "T \<Rightarrow> prog_state \<Rightarrow> lib_state \<Rightarrow> surrey_state \<Rightarrow> prog_state \<Rightarrow> lib_state \<Rightarrow> surrey_state \<Rightarrow> bool " where "seqLock t s ls cs s' ls' cs' \<equiv> ( if (pc s) t = L1 then ((ls) (cs) [r s' t \<leftarrow> lib(glb)]\<^sub>t (ls') (cs')) \<and> (even (r s' t) \<longrightarrow> pc s' = update_pc t L2 (pc s)) \<and> (\<not>even(r s' t) \<longrightarrow> pc s' = pc s) \<and> (loc s' t = loc s t) \<and> (\<forall>tt . tt\<noteq>t \<longrightarrow> r s' tt = r s tt) \<and> (\<forall>tt . tt\<noteq>t \<longrightarrow> loc s' tt = loc s tt) else if (pc s) t = L2 then ((ls) (cs) CAS[lib(glb), loc s' t, (r s t), (r s t + 1)]\<^sub>t (ls') (cs')) \<and> (loc s' t \<longrightarrow> pc s' = update_pc t L3 (pc s)) \<and> (\<not>loc s' t \<longrightarrow> pc s' = update_pc t L1 (pc s)) \<and> (r s' = r s) \<and> (\<forall>tt . tt\<noteq>t \<longrightarrow> loc s' tt = loc s tt) else False )" definition "seqLock_inv t p ls cs s \<equiv> (case p of L1 \<Rightarrow> True | L2 \<Rightarrow> even (r s t) | L3 \<Rightarrow> loc s t \<and> even (r s t) ) " definition seqLock_release :: "T \<Rightarrow> prog_state \<Rightarrow> lib_state \<Rightarrow> surrey_state \<Rightarrow> V \<Rightarrow> prog_state \<Rightarrow> lib_state \<Rightarrow> surrey_state \<Rightarrow> bool " where "seqLock_release t s ls cs ver s' ls' cs' \<equiv> ( if (pc s) t = L1 then ((ls) (cs) [lib(glb) :=\<^sup>R (ver + 1)]\<^sub>t (ls') (cs')) \<and> pc s' = update_pc t L2 (pc s) else if (pc s) t = L2 then True else False )" definition "seqLock_release_inv t p ls cs s \<equiv> (case p of L1 \<Rightarrow> \<exists> v . ([lib(glb) =\<^sub>t v] ls) \<and> (odd v) | L2 \<Rightarrow> True ) " lemma inv: assumes "wfs cs" and "lib_wfs ls cs" and "seqLock t s ls cs s' ls' cs'" and "seqLock_inv t (pc s t) ls cs s" shows "seqLock_inv t (pc s' t) ls' cs' s'" using assms apply(simp add: seqLock_def seqLock_inv_def update_pc_def) apply(case_tac "pc s t", simp_all) apply(case_tac "pc s' t", simp_all) apply(simp add: update_pc_def ) apply safe apply simp+ apply auto apply(simp_all add: update_pc_def ) by (meson PC.distinct(3) fun_upd_eqD) lemma inv_interf: assumes "wfs cs" and "lib_wfs ls cs" and "seqLock t' s ls cs s' ls' cs'" and "seqLock_inv t' (pc s t') ls cs s" and "seqLock_inv t (pc s t) ls cs s" shows "seqLock_inv t (pc s' t) ls' cs' s'" using assms apply(case_tac "t = t'", simp_all) apply (meson assms(3) inv seqLock_inv_def) apply(simp add: seqLock_def seqLock_inv_def update_pc_def) apply(cases "pc s t'", simp_all) apply(cases "pc s t", simp_all) apply(cases "pc s' t", simp_all) apply(elim conjE) apply(simp_all add: update_pc_def ) apply auto[1] apply auto apply(cases "pc s t", simp_all) apply presburger by presburger (*Proof of refinement*) (* cc = concrete client state ac = abstract client state al = abstract lock state cl = concrete lock state *) definition "writes_rel_inv al cl rr \<equiv> \<forall> cw . cw\<in>lib_writes_on cl glb \<longrightarrow> (\<exists> aw . aw\<in>lib_writes_on al l \<and> tst cw = tst aw \<and> lib_modView al aw CVARS = lib_modView cl cw CVARS \<and> lib_value al aw = lib_value cl cw \<and> lib_rel (lib_mods al aw) = lib_rel (lib_mods cl cw) \<and> (cw\<in>lib_covered cl \<longrightarrow> aw\<in>lib_covered al)\<and> (cw\<notin>lib_covered cl \<longrightarrow> aw\<notin>lib_covered al))" definition "same_writes al cl rr \<equiv> tst `lib_writes_on cl glb = tst ` lib_writes_on al l" definition "thrView_rel al cl t \<equiv> tst (lib_thrView cl t glb) \<ge> tst (lib_thrView al t l)" definition refinement_rel :: "lib_state \<Rightarrow> lib_state \<Rightarrow> surrey_state \<Rightarrow> surrey_state \<Rightarrow> T \<Rightarrow> refinement_rel \<Rightarrow> bool" where "refinement_rel al cl ac cc t rr \<equiv> writes_rel_inv al cl rr \<and> thrView_rel al cl t \<and> same_writes al cl rr" lemmas invs = writes_rel_inv_def thrView_rel_def update_pc_def seqLock_inv_def even_not_covered_last_def refinement_rel_def lemma not_acquired_sttutering: assumes "wfs cc" and "wfs ac" and "ac = cc" and "lib_wfs al ac" and "lib_wfs cl cc" and "abslock_invs al l" and "refinement_rel al cl ac cc t rr" and "pc s t = L2" and "loc s' t = False" and "seqLock_inv t (pc s t) cl cc s" and "seqLock t s cl cc s' cl' cc'" and "al' = al" and "ac' = ac" shows "refinement_rel al' cl' ac' cc' t rr \<and> ac' = cc'" using assms apply(simp add: refinement_rel_def seqLock_def lib_CAS_step_def) apply(elim conjE exE) apply(case_tac "lib_value cl (a, b) = r s t", simp_all) apply(simp add: lib_read_def all_updates_l) apply(intro conjI impI) apply(simp add: writes_rel_inv_def) apply(intro allI conjI impI) apply(simp add: lib_writes_on_def lib_value_def) apply(erule_tac x=ba in allE) apply(elim conjE, simp) apply(simp add: thrView_rel_def ts_oride_def) apply (simp_all add: lib_syncing_def) apply(simp add: writes_rel_inv_def) apply(intro allI conjI impI) apply(simp add: lib_writes_on_def) apply (metis (no_types, lifting) lib_state.select_convs(4) lib_state.surjective lib_state.update_convs(2) lib_value_def) apply(simp add: thrView_rel_def) apply(intro allI conjI impI) apply(simp add: lib_value_def lib_valid_fresh_ts_def lib_writes_on_def update_pc_def tst_def) apply (simp add: lib_visible_writes_def tst_def) by(simp add: same_writes_def lib_writes_on_def) lemma new_state_writes_on: "lib_wfs cl cc \<Longrightarrow> (xc, ts')\<notin>lib_writes_on cl xc \<Longrightarrow> lib_writes_on (cl\<lparr>lib_thrView := (lib_thrView cl) (t := ts_oride ((lib_thrView cl t)(xc := (xc, ts'))) (lib_modView cl (xc, b) LVARS)), lib_modView := (lib_modView cl) ((xc, ts') := (lib_modView cl (xc, ts')) (CVARS := ts_oride (thrView cc t) (lib_modView cl (xc, b) CVARS), LVARS := ts_oride ((lib_thrView cl t)(xc := (xc, ts'))) (lib_modView cl (xc, b) LVARS))), lib_mods := (lib_mods cl) ((xc, ts') := \<lparr>lib_val = v, lib_rel = bo\<rparr>), lib_writes := insert (xc, ts') (lib_writes cl), lib_covered := insert (xc, b) (lib_covered cl)\<rparr>) xc = lib_writes_on cl xc \<union> {(xc,ts')}" apply(simp add: lib_writes_on_def) apply(subgoal_tac " {w. fst w = xc \<and> w \<in> lib_writes cl} \<noteq> {}") apply(subgoal_tac "finite ( {w. fst w = xc \<and> w \<in> lib_writes cl})") apply force apply(simp add: lib_wfs_def) apply (simp add: lib_writes_on_def var_def) apply(simp add: lib_wfs_def) apply (simp add: lib_writes_on_def var_def) by (metis eq_fst_iff) lemma refinement_step_lock_acquired: assumes "wfs cc" and "wfs ac" and "ac = cc" and "lib_wfs al ac" and "lib_wfs cl cc" and "abslock_invs al l" and "refinement_rel al cl ac cc t rr" and "pc s t = L2" and "loc s' t = True" and "seqLock_inv t (pc s t) cl cc s" and "seqLock t s cl cc s' cl' cc'" shows "\<exists> al' ac' ver rr' . [ac al t LOCKACQ(l) ac' al' True ver] \<and> refinement_rel al' cl' ac' cc' t rr' \<and> ac'=cc'" using assms apply (simp add: refinement_rel_def lock_acquire_step_def) apply(simp add: seqLock_def lib_CAS_step_def invs same_writes_def) apply(subgoal_tac "\<exists>tt . (tt::T)\<noteq>t") defer apply (metis Zero_not_Suc) apply(elim exE) apply(elim conjE) apply(rotate_tac 14) apply(erule_tac x = tt in allE, simp) apply(rotate_tac 1) apply(elim conjE exE) apply(subgoal_tac "a = glb", simp) defer apply (simp add: a_is_x) apply(erule_tac x=glb in allE) apply(erule_tac x=b in allE, simp) apply(subgoal_tac "(glb, b) \<in> lib_writes_on cl glb", simp) defer apply(simp add: lib_visible_writes_def) apply(elim exE) apply(subgoal_tac "aa = l", simp) defer apply (metis (mono_tags, hide_lams) a_is_x abslock_invs_def assms(2) assms(4) assms(6) even_not_covered_last_def lib_last_in_visible_writes ) apply(elim conjE) apply(case_tac "lib_value cl (glb ,b) = r s t", simp_all) apply(case_tac "lib_releasing cl (glb, b)") apply(rule_tac x = "if lib_releasing cl (glb,b) then al\<lparr>lib_thrView := (lib_thrView al) (t := ts_oride ((lib_thrView al t)(l := (l, ts'))) (lib_modView al (l, b) LVARS)), lib_modView := (lib_modView al) ((l, ts') := (lib_modView al (l, ts')) (CVARS := ts_oride (thrView cc t) (lib_modView al (l, b) CVARS), LVARS := ts_oride ((lib_thrView al t)(l := (l, ts'))) (lib_modView al (l, b) LVARS))), lib_mods := (lib_mods al) ((l, ts') := \<lparr>lib_val = Suc (lib_value al (l, b)), lib_rel = True\<rparr>), lib_writes := insert (l, ts') (lib_writes al), lib_covered := insert (l, b) (lib_covered al)\<rparr> else al \<lparr>lib_thrView := (lib_thrView al) (t := (lib_thrView al t)(l := (l, ts'))), lib_modView := (lib_modView al) ((l, ts') := (lib_modView al (l, ts')) (CVARS := thrView cc t, LVARS := (lib_thrView al t)(l := (l, ts')))), lib_mods := (lib_mods al) ((l, ts') := \<lparr>lib_val = Suc (r s t), lib_rel = True\<rparr>), lib_writes := insert (l, ts') (lib_writes al), lib_covered := insert (l, b) (lib_covered al)\<rparr>" in exI) apply(simp add: lib_update_def lock_acquire_def all_updates_l) apply(intro conjI) apply(rule_tac x = "lib_value al (l, b)" in exI) apply(rule_tac x = "l" in exI) apply(rule_tac x = "b" in exI) apply(simp_all add: lib_releasing_def) apply(intro conjI) apply (metis abslock_invs_def even_not_covered_last_def lib_last_in_visible_writes) apply(rule_tac x=ts' in exI, intro conjI) using new_ts_is_the_same apply blast defer apply(simp add: lib_writes_on_def lib_value_def) apply(intro allI impI) using assms(7) apply(simp add: refinement_rel_def writes_rel_inv_def, elim conjE) apply(erule_tac x="glb" in allE) apply(erule_tac x="ba" in allE) apply(simp add: lib_writes_on_def) apply(case_tac "(glb, ba) \<in> lib_writes cl", simp_all) apply(elim conjE, intro conjI impI) apply blast+ apply (simp add: lib_value_def) apply(intro conjI impI, elim conjE) apply (simp add:lib_wfs_def subset_iff) apply(elim conjE, simp) apply(subgoal_tac "(l, ts') \<notin> lib_writes al") apply (simp add:lib_wfs_def subset_iff) apply force apply (smt Collect_cong tst_eq_writes_on) apply linarith+ apply blast+ apply(simp add: ts_oride_def lib_writes_on_def lib_visible_writes_def) apply(intro conjI impI) using assms(7) apply(simp add: refinement_rel_def writes_rel_inv_def) apply(elim conjE) apply(erule_tac x = glb in allE) apply(erule_tac x = b in allE) apply(subgoal_tac "lib_modView al (l, b) LVARS l = (l,b) \<and> lib_modView cl (glb, b) LVARS glb = (glb, b)") apply simp apply(simp add: lib_wfs_def) apply(subgoal_tac "tst (lib_modView al (l, b) LVARS l) = tst (lib_modView cl (glb, b) LVARS glb)") apply linarith apply(subgoal_tac "lib_modView al (l, b) LVARS l = (l,b) \<and> lib_modView cl (glb, b) LVARS glb = (glb, b)") apply simp apply(simp add: lib_wfs_def) apply(simp add: lib_writes_on_def) apply(subgoal_tac "{w. var w = glb \<and> (w = (glb, ts') \<or> w \<in> lib_writes cl)} = {w. var w = glb \<and> (w \<in> lib_writes cl)} \<union> {(glb, ts')} \<and> {w. var w = l \<and> (w = (l, ts') \<or> w \<in> lib_writes al)} = {w. var w = l \<and> (w \<in> lib_writes al)} \<union> {(l, ts')}") apply simp apply(intro conjI) apply(subgoal_tac "finite ( {w. var w = glb \<and> w \<in> lib_writes cl})") apply(simp add: var_def tst_def) using Collect_cong apply auto[1] apply (metis lib_wfs_def lib_writes_on_def) apply(subgoal_tac "finite ( {w. var w = glb \<and> w \<in> lib_writes cl})") apply(simp add: var_def tst_def) using Collect_cong apply auto[1] apply (metis lib_wfs_def lib_writes_on_def) using assms(7) apply(simp add:refinement_rel_def writes_rel_inv_def, elim conjE) apply(erule_tac x=glb in allE) apply(erule_tac x=b in allE, simp) apply(elim exE conjE) apply(subgoal_tac "ab = l", simp) defer apply (metis Pair_inject abslock_invs_def even_not_covered_last_def) apply(rule_tac x = " al \<lparr>lib_thrView := (lib_thrView al) (t := (lib_thrView al t)(l := (l, ts'))), lib_modView := (lib_modView al) ((l, ts') := (lib_modView al (l, ts')) (CVARS := thrView cc t, LVARS := (lib_thrView al t)(l := (l, ts')))), lib_mods := (lib_mods al) ((l, ts') := \<lparr>lib_val = Suc (r s t), lib_rel = True\<rparr>), lib_writes := insert (l, ts') (lib_writes al), lib_covered := insert (l, b) (lib_covered al)\<rparr>" in exI) apply(simp add: lib_update_def lock_acquire_def all_updates_l) apply(intro conjI) apply(simp_all add: lib_releasing_def) apply(intro conjI) apply(rule_tac x = "lib_value al (l, b)" in exI) apply(rule_tac x = "l" in exI) apply(rule_tac x = "b" in exI) apply(intro conjI, simp_all) apply(intro conjI) apply (metis abslock_invs_def even_not_covered_last_def lib_last_in_visible_writes) apply(rule_tac x=ts' in exI, intro conjI) using new_ts_is_the_same apply blast defer apply(simp add: lib_writes_on_def lib_value_def) apply(intro allI impI) using assms(7) apply(simp add: refinement_rel_def writes_rel_inv_def) apply(erule_tac x="glb" in allE) apply(erule_tac x="ba" in allE) apply(simp add: lib_writes_on_def) apply(case_tac "(glb, ba) \<in> lib_writes cl", simp_all) apply(elim conjE, intro conjI impI) apply blast+ apply (simp add: lib_value_def) apply(intro conjI impI, elim conjE) apply (simp add:lib_wfs_def subset_iff) apply(elim conjE, simp) apply(subgoal_tac "(l, ts') \<notin> lib_writes al") apply (simp add:lib_wfs_def subset_iff) apply force apply (smt Collect_cong tst_eq_writes_on) apply linarith+ apply blast apply blast apply blast apply blast apply blast apply blast apply(simp add: ts_oride_def lib_writes_on_def lib_visible_writes_def) apply(subgoal_tac "{w. var w = glb \<and> (w = (glb, ts') \<or> w \<in> lib_writes cl)} = {w. var w = glb \<and> (w \<in> lib_writes cl)} \<union> {(glb, ts')} \<and> {w. var w = l \<and> (w = (l, ts') \<or> w \<in> lib_writes al)} = {w. var w = l \<and> (w \<in> lib_writes al)} \<union> {(l, ts')}") apply simp apply(intro conjI) apply(subgoal_tac "finite ( {w. var w = glb \<and> w \<in> lib_writes cl})") apply(simp add: var_def tst_def) using Collect_cong apply auto[1] apply (metis lib_wfs_def lib_writes_on_def) apply(subgoal_tac "finite ( {w. var w = glb \<and> w \<in> lib_writes cl})") apply(simp add: var_def tst_def) using Collect_cong apply auto[1] apply (metis lib_wfs_def lib_writes_on_def) done (*************Release Operation Refinement**************) lemma refinement_step_release: assumes "wfs cc" and "wfs ac" and "ac = cc" and "lib_wfs al ac" and "lib_wfs cl cc" and "abslock_invs al l" and "refinement_rel al cl ac cc t rr" and "[lib(glb) =\<^sub>t ver] cl" and "odd ver" and "pc s t = L1" and "seqLock_release t s cl cc ver s' cl' cc'" shows "\<exists> al' ac' . [ac al t LOCKREL(l) al' ac'] \<and> refinement_rel al' cl' ac' cc' t rr' \<and> ac'=cc'" using assms apply(simp add: seqLock_release_def lock_release_step_def lib_write_step_def refinement_rel_def) apply(simp add: lib_write_def all_updates_l writes_rel_inv_def) apply(elim conjE exE) apply(rule_tac x = "al \<lparr>lib_thrView := (lib_thrView al) (t := (lib_thrView al t)(l := (l, ts'))), lib_modView := (lib_modView al) ((l, ts') := (lib_modView al (l, ts')) (CVARS := thrView cc t, LVARS := (lib_thrView al t)(l := (l, ts')))), lib_mods := (lib_mods al) ((l, ts') := \<lparr>lib_val = Suc (lib_value cl (a, b)), lib_rel = True\<rparr>), lib_writes := insert (l, ts') (lib_writes al)\<rparr>" in exI) apply(intro conjI ) apply(erule_tac x = a in allE) apply(erule_tac x = b in allE) apply (simp add: lib_visible_writes_def) apply(elim conjE exE) apply(subgoal_tac "aa = l", simp) apply(rule_tac x = l in exI) apply(rule_tac x = b in exI) apply(intro conjI) apply blast apply (meson order.trans thrView_rel_def) apply blast apply(rule_tac x = ts' in exI) apply(intro conjI) apply(simp add: same_writes_def lib_writes_on_def lib_valid_fresh_ts_def) apply(intro allI impI) apply (smt Collect_cong tst_eq_writes_on_not) apply(simp add: lock_release_def lib_write_def all_updates_l) apply(simp add: lib_writes_on_def) apply(intro allI impI) apply(simp add: lib_writes_on_def lib_value_def) apply(case_tac "ba = ts'", simp_all) apply(case_tac "glb = a", simp_all) apply(intro conjI impI) apply (metis lib_dobs_visible_writes lib_value_def) apply(subgoal_tac "(glb, ts') \<notin> lib_writes cl") apply(simp add: lib_wfs_def) using subset_iff apply auto[1] apply(simp add: lib_valid_fresh_ts_def lib_visible_writes_def lib_writes_on_def) apply blast apply(elim conjE disjE) apply(simp add: same_writes_def lib_writes_on_def var_def tst_def lib_visible_writes_def) apply(subgoal_tac "(glb, ts') \<notin> lib_writes cl") apply(subgoal_tac "ts' \<notin> snd ` {w. fst w = glb \<and> w \<in> lib_writes cl}") apply(subgoal_tac "(l, ts') \<notin> lib_writes al") apply(simp add: lib_wfs_def) apply auto[1] apply (simp add: image_iff) using imageE apply force apply (simp add: fresh_ts_not_in_writes) apply blast using a_is_x apply blast apply blast apply(simp add: thrView_rel_def) using a_is_x apply blast apply(simp add: same_writes_def lib_writes_on_def tst_def var_def lib_visible_writes_def) apply(subgoal_tac "finite {w. fst w = glb \<and> w \<in> lib_writes cl}") apply(subgoal_tac "finite {w. fst w = l \<and> w \<in> lib_writes al}") apply(subgoal_tac "{w. fst w = glb \<and> (w = (glb, ts') \<or> w \<in> lib_writes cl)} = {w. fst w = glb \<and> (w \<in> lib_writes cl)} \<union> {(glb,ts')}") apply(subgoal_tac "{w. fst w = l \<and> (w = (l, ts') \<or> w \<in> lib_writes al)} = {w. fst w = l \<and> ( w \<in> lib_writes al)} \<union> {(l,ts')}") apply simp_all apply (simp add: writes_ts_rewrite) apply (simp add: writes_ts_rewrite) apply(simp add: lib_wfs_def lib_writes_on_def) using var_def apply auto[1] apply(simp add: lib_wfs_def lib_writes_on_def) using var_def apply auto[1] done end
| pc = 0xc002 | a = 0xfa | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | | pc = 0xc003 | a = 0xfa | x = 0x00 | y = 0x00 | sp = 0x01fc | p[NV-BDIZC] = 10110100 | MEM[0x01fd] = 0xfa | | pc = 0xc004 | a = 0xfa | x = 0x00 | y = 0x00 | sp = 0x01fb | p[NV-BDIZC] = 10110100 | MEM[0x01fc] = 0xb4 | | pc = 0xc006 | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01fb | p[NV-BDIZC] = 00110110 | | pc = 0xc007 | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01fa | p[NV-BDIZC] = 00110110 | MEM[0x01fb] = 0x00 | | pc = 0xc008 | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01f9 | p[NV-BDIZC] = 00110110 | MEM[0x01fa] = 0x36 | | pc = 0xc00a | a = 0x11 | x = 0x00 | y = 0x00 | sp = 0x01f9 | p[NV-BDIZC] = 00110100 | | pc = 0xc00b | a = 0x11 | x = 0x00 | y = 0x00 | sp = 0x01f8 | p[NV-BDIZC] = 00110100 | MEM[0x01f9] = 0x11 | | pc = 0xc00c | a = 0x11 | x = 0x00 | y = 0x00 | sp = 0x01f7 | p[NV-BDIZC] = 00110100 | MEM[0x01f8] = 0x34 | | pc = 0xc00e | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01f7 | p[NV-BDIZC] = 00110110 | | pc = 0xc00f | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01f8 | p[NV-BDIZC] = 00110100 | MEM[0x01f8] = 0x34 | | pc = 0xc011 | a = 0x01 | x = 0x00 | y = 0x00 | sp = 0x01f8 | p[NV-BDIZC] = 00110100 | | pc = 0xc012 | a = 0x11 | x = 0x00 | y = 0x00 | sp = 0x01f9 | p[NV-BDIZC] = 00110100 | MEM[0x01f9] = 0x11 | | pc = 0xc014 | a = 0x01 | x = 0x00 | y = 0x00 | sp = 0x01f9 | p[NV-BDIZC] = 00110100 | | pc = 0xc015 | a = 0x01 | x = 0x00 | y = 0x00 | sp = 0x01fa | p[NV-BDIZC] = 00110110 | MEM[0x01fa] = 0x36 | | pc = 0xc017 | a = 0x01 | x = 0x00 | y = 0x00 | sp = 0x01fa | p[NV-BDIZC] = 00110100 | | pc = 0xc018 | a = 0x00 | x = 0x00 | y = 0x00 | sp = 0x01fb | p[NV-BDIZC] = 00110110 | MEM[0x01fb] = 0x00 | | pc = 0xc01a | a = 0x01 | x = 0x00 | y = 0x00 | sp = 0x01fb | p[NV-BDIZC] = 00110100 | | pc = 0xc01b | a = 0x01 | x = 0x00 | y = 0x00 | sp = 0x01fc | p[NV-BDIZC] = 10110100 | MEM[0x01fc] = 0xb4 | | pc = 0xc01d | a = 0x01 | x = 0x00 | y = 0x00 | sp = 0x01fc | p[NV-BDIZC] = 00110100 | | pc = 0xc01e | a = 0xfa | x = 0x00 | y = 0x00 | sp = 0x01fd | p[NV-BDIZC] = 10110100 | MEM[0x01fd] = 0xfa |
Joe and I are now the proud owners of two weeks off (hurrah!) - I will still be blogging away merrily though, no fear good people (unless you want a rest from me of course?!). The week running up to a holiday for me is both exciting and stressful because I am trying to get everything done so I can switch off and try not to worry for 14 whole days and another part of me is all 'come on Friday!' and throwing caution to the wind! But it is here, the day, Friday! Let's round up what has been happening this week shall we? Costas peach and lemonade on ice...oh my! Heavenly goodness in a plastic cup with a straw! A full on health overhaul. It is happening. Yesterday I was working from home and got up and went to the gym for 6.30am. I felt buzzing and ready for the day. I have really sorted the nutrition this week too; I've increased my protein intake and reduced the carbs down a notch. The biggest thing for me is not having things like cereal bars that are full of sugar right before bed just because I have a cup of tea (I need training that tea can be drunk without a companion!). Instead of that I am just drinking water and ending the day with a good protein shake made with water to feed and help heal the body over night. Teaching Joe about Twitter. He is running his bands Twitter Page now so go and follow and check it out if you fancy. You can also find them on Sound Cloud. I love their song 'Into the Air'. Lots of skincare samples in my magazines...let's face it, I can't afford them so it is nice to have a little insight into how young I could be looking! Seeing Joe get all soppy over all the cats on the cats protection website. From someone who, not so long ago, didn't want to go near any animals he is doing pretty well. (Am I allowed to say our new hoover?) Our new hoover. Every darn hoover I have ever owned has been beyond rubbish, I would have more success sucking up the dust through a straw (?!). As an early wedding present my mum and dad brought us a ruddy awesome hoover that we got all excited about as we pushed it around the just hoovered lounge and it picked up loads of floor junk! I know I am officially needing more to do in my life when I spend an evening saying to Joe 'just look at that carpet! It's amazing...there's hoover lines on the floor...I can't wait to do the whole house'...help me. A girly movie night. It is not often that I force Joe to watch a film that I really like that I don't think he will, in fact, I don't believe I have ever done that, but I am feeling a 'Notebook' night coming on. I adore that film and may have to throw it out there as an option this weekend. Maybe I can balance it out with some guitar hero Metallica afterwards.
\chapter{Training Job Co-location} \label{chap:profiling-training} \section{Problem Formulation} Since the individual jobs may be slowed down when being co-located, we need to have an aggregate formulation for representing the speed up of multiple jobs on a single GPU and compare it with the case when they run individually. We propose a simple speedup factor that makes it easy to measure the amount of speedup, compared to the original case. We are given n jobs that can be co-located all together on a single GPU. The time that it takes for a single iteration of job $i$ to complete when running alone is $t_i$. Define $t'_{i, S}$ as the time for single iteration of job $i$ to complete when being co-located with jobs that belong to $S \subset J$. The universal set J contains all the jobs. We are interested in cases where the ratio of the sum of the jobs' time running individually to the longest job time when being co-located is greater than 1, i.e. yields speedup. This is represented mathematically in \cref{eq:speedup}. \begin{equation} \delta = \frac{\sum_{j \in S} t_j}{\max_{j \in S} t'_{j,s}} \geq 1 \label{eq:speedup} \end{equation} \begin{figure} \centering \includegraphics[width=0.8\textwidth]{figs/colocationmodeling} \caption{Co-location of Multiple Jobs} \label{fig:co-location-modeling} \end{figure} \Cref{fig:co-location-modeling} illustrates why this formulation is valid. As shown in \cref{fig:co-location-modeling}, an individual $t'_i$ might be greater than $t_i$ but because all the jobs have started together, as long as the longest job takes less than the sum of all the jobs, co-location is better than running alone. In \cref{fig:co-location-modeling} we schedule 3 jobs and we want to find out whether co-location is suitable. We need to first calculate $t_i$ values which is the time that each iteration of the job takes when running alone. Then, we need to calculate the values for $t'_i$ which is the time that each iteration of the job takes when it is co-located with all the jobs in $S$. Next, we can use $t_i$ and $t'_i$ values and plug them in \cref{eq:speedup}. If the value for $\delta$ is larger than 1, these jobs will benefit from this co-location. It is worth noting that while every $t'_i$ may be larger than $t_i$, it may be still worth the co-location as long as each iteration of the longest job does not take as much as the sum of all the individual iterations. \section{Profiling Training Jobs} \begin{table} \centering \begin{tabular}{ccc} \hline Experiment Number & Models (Co-location of 2) & Models (Co-location of 3) \\ \hline \hline 0 & vgg19, resnet50 & resnet18, se\_resnet18, resnet50 \\ \hline 1 & se\_resnet18, resnet50 & resnet18, vgg19, resnet50\\ \hline 2 & vgg11, vgg19 & resnet18, vgg11, se\_resnet18\\ \hline 3 & resnet18, resnet50 & resnet18, vgg11, vgg19 \\ \hline 4 & vgg11, resnet50 & resnet18, vgg19, se\_resnet18 \\ \hline 5 & resnet18, vgg11 & vgg11, se\_resnet18, resnet50\\ \hline 6 & vgg19, se\_resnet18 & resnet18, vgg11, resnet50 \\ \hline 7 & vgg11, se\_resnet18 & vgg11, vgg19, se\_resnet18\\ \hline 8 & resnet18, se\_resnet18 & vgg11, vgg19, resnet50\\ \hline 9 & resnet18, vgg19 & vgg19, se\_resnet18, resnet50 \\ \hline \end{tabular} \caption{Description of the experiment numbers} \label{tab:exp-description} \end{table} We run a series of experiments to explore the value of $\delta$ in \cref{eq:speedup}. The models we used here are two variations of ResNet~\cite{resnet} models, two variations of VGG~\cite{vgg} models, and a more recent image classification architecture named SE-Net~\cite{senet}. We run all the possible combinations of these models. These combinations include cases of running more than two jobs together. Since we are studying five models, the total number of models used is equal to ${5 \choose 2} = 10$ when co-locating two jobs and ${5 \choose 3} = 10$ when co-locating three jobs. \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/model-parameters} \caption{Number of Parameters in the Benchmark Models} \label{fig:model-parameters} \end{figure} \Cref{fig:model-parameters} shows the number of parameters that the benchmarked models need. The values presented in this figure are for the time that the model is using a batch size of one. Increasing the batch size will increase the number of parameters for each model. VGG models require the largest number of parameters and ResNet family require fewer parameters in comparison. \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/layer-2-bs-pytorch} \caption{Co-locating two jobs together using various batch sizes. x-axis shows the experiment number described in \cref{tab:exp-description}. MPS is not enabled in this figure.} \label{fig:layer-2-bs-inter} \end{figure} \Cref{fig:layer-2-bs-inter} shows the value of $\delta$ when two jobs are placed together. The X axis shows the experiment number for all the possible combinations of the models described in \cref{fig:model-parameters}. As expected, smaller batch sizes provide higher speedups compared to large batch sizes. These results are for a per iteration speedup of the models. We sampled 10 iterations of the training and calculated the average of these samples. We used the mean as the value for $t'$ and $t$ values in \cref{eq:speedup}. MPS is not enabled in any of the experiments shown in this figure. Later in this chapter we will present some other experiments explaining the cause for peaks and valleys seen in this figure. \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/layer-2-mps-bs-pytorch} \caption{Co-locating two jobs together using various batch sizes. x-axis shows the experiment number described in \cref{tab:exp-description}. MPS is enabled in this figure.} \label{fig:layer-2-bs-inter-mps} \end{figure} \Cref{fig:layer-2-bs-inter-mps} shows the value of $\delta$ when two jobs are placed together when MPS is enabled. As expected, enabling MPS will lead to higher speedup compared to not enabling MPS. Gaining speed up when MPS is not enabled suggests that for certain batch sizes and certain models given the GPU that we used for benchmarking, there are time intervals that a GPU is not utilized at all and thus time-sharing leads to speedup. \begin{figure} \centering \begin{subfigure}[b]{\threecolfigwidth} \includegraphics[width=\textwidth]{figs/experiments/layers-bs-64-pytorch} \vspace*{\capshift} \caption{Batch Size $= 64$} \label{fig:layers-bs-64-inter} \end{subfigure} \begin{subfigure}[b]{\threecolfigwidth} \includegraphics[width=\textwidth]{figs/experiments/layers-bs-128-pytorch} \vspace*{\capshift} \caption{Batch Size $= 128$} \label{fig:layers-bs-128-inter} \end{subfigure} \begin{subfigure}[b]{\threecolfigwidth} \includegraphics[width=\textwidth]{figs/experiments/layers-bs-256-pytorch} \vspace*{\capshift} \caption{Batch Size $= 256$} \label{fig:layers-bs-256-inter} \end{subfigure} \caption{Co-location of two or three jobs together. x-axis shows the experiment number described in \cref{tab:exp-description}. MPS is not enabled in these experiments.} \label{fig:layers-bs-inter} \end{figure} \Cref{fig:layers-bs-64-inter,fig:layers-bs-128-inter,fig:layers-bs-256-inter} show the results when the batch size is constant and we are running two or three jobs together. The following trends can be observed from these experiments: \begin{itemize} \item \textbf{Larger batch sizes lead to smaller speedup}. As we increase the batch size the largest speedup decreases. \item \textbf{More than two jobs leads to higher speedup when using small batch sizes.} As shown in \cref{fig:layers-bs-64-inter}, in most of the cases co-locating three jobs together gives higher speedup than co-locating two jobs together. \item \textbf{Number of parameters is not the source of slowdown.} If we use the information in \cref{tab:exp-description}, we notice that the experiments that are slowest, are the ones that are being co-located with ResNet-50. In \cref{fig:model-parameters}, ResNet-50 is not the model that has the largest number of parameters in the models that we studied. Also, the model that has the best co-location behavior (i.e. leads to higher speedup) is the VGG11 model. The peaks occur when the job is being co-located with a VGG11 model. VGG11 neither has the fewest number of parameters or the largest number of parameters. \end{itemize} \begin{figure} \centering \begin{subfigure}[b]{\threecolfigwidth} \includegraphics[width=\textwidth]{figs/experiments/layers-bs-64-mps-pytorch} \vspace*{\capshift} \caption{Batch Size $= 64$} \label{fig:layers-bs-64-inter-mps} \end{subfigure} \begin{subfigure}[b]{\threecolfigwidth} \includegraphics[width=\textwidth]{figs/experiments/layers-bs-128-mps-pytorch} \vspace*{\capshift} \caption{Batch Size $= 128$} \label{fig:layers-bs-128-inter-mps} \end{subfigure} \begin{subfigure}[b]{\threecolfigwidth} \includegraphics[width=\textwidth]{figs/experiments/layers-bs-256-mps-pytorch} \vspace*{\capshift} \caption{Batch Size $= 256$} \label{fig:layers-bs-256-inter-mps} \end{subfigure} \caption{Co-location of two or three jobs together. x-axis shows the experiment number described in \cref{tab:exp-description}. MPS is enabled in these experiments.} \label{fig:layers-bs-inter-mps} \end{figure} \Cref{fig:layers-bs-64-inter,fig:layers-bs-128-inter,fig:layers-bs-256-inter} show the results when the batch size is constant and we are running two or three jobs together. In these experiments MPS is enabled. The same observations that we described for \Cref{fig:layers-bs-inter} hold for these experiments too. In addition the speedup gained from co-location is larger when MPS is enabled. This is what we expected. \subsection{Kernel Analysis of the Jobs} We want to find the underlying reason for the different values of speedup when co-locating different models. As described previously, we noticed that number of parameters that each model uses is not a good heuristic for determining the compatibility between a set of jobs. Each deep learning training job is composed of many kernels that are used to perform computation for each stage of the DL training. As discussed in \cref{chap:background}, deep learning frameworks implement many of the operations required for DL training on the specialized hardwares such as GPUs. The user requests to calculate a backpropagation, and the DL framework will launch a series of kernels to perform that computation on the GPU. In the following subsections, we propose simple metrics that can attribute a number to the whole job and we will use these metrics to describe the speedup observed in the experiments when MPS is enabled. Since the kernels are either memory-bound or compute-bound, we will focus on the memory bandwidth utilization of the GPU and kernel occupancy for the models that we are studying. The kernel analysis is performed using NVIDIA Nsight Compute~\cite{NsightCompute}. %[put a picture about job and number of kernels] \subsection{Memory Bandwidth Utilization} \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/memory-util-histo} \caption{Histogram of the memory utilization of the kernels for models under study. The batch size is equal to 64. If a kernel is run multiple times, the results are not grouped together and is assumed as a separate kernel. The unit for x-axis is in percent and the y-axis is log based. This graph includes the results for two iterations of training. The kernels were analyzed individually without sharing the resources with any other job.} \label{fig:memory-util-histo} \end{figure} Assume that each kernel takes $t_i$ time and utilizes $p_i$ percent from the memory bandwidth of our V100 GPU. A histogram for $p_i$ values is shown in \cref{fig:memory-util-histo}. Key takeaways from this figure are the following: \begin{itemize} \item ResNet-50 has more kernels in almost every utilization category. It is also the only kernel that has some kernels that are able to almost fully utilize the V100 bandwidth. \item VGG11 has fewer number of kernels in almost every utilization bucket. \item Kernels that utilize the memory bandwidth least constitute the largest number of kernels. \end{itemize} Using this profiling information, we aim to create a single number that represents the aggregate memory bandwidth utilization of each of these models. \begin{equation} M = \sum_{i=1}^N p_i t_i \label{eq:memory} \end{equation} \Cref{eq:memory} shows the formula for calculating the aggregate memory bandwidth for a given job. This is a weighted sum of the memory bandwidth utilization. The weights are the duration of the individual kernels. If a kernel uses all the memory bandwidth but doesn't take a very long time, it shouldn't affect the speedup very much. Likewise if the kernel does not utilize the memory bandwidth significantly but takes a very long time it should not affect the speedup to a great extent either. \Cref{fig:weighted-mem-util} shows the value of $M$ presented in \cref{eq:memory} for different models and different batch sizes. As we increase the batch size, the $M$ value increases for all the jobs that we studied. ResNet-50 utilizes the most amount of memory bandwidth compared to other deep learning models. While ResNet-50 does not have the largest number of parameters, it is able to utilize the memory bandwidth more effectively compared to all the other models. We suspect that this may be due to the popularity of this model and as a result the kernels used for training this model are highly optimized. \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/wa-mem-util} \caption{Weighted sum of the memory utilization of the models using various batch sizes} \label{fig:weighted-mem-util} \end{figure} \subsection{Compute Utilization} Analogous metrics can be created for compute utilization. Assume that each kernel takes $t_i$ time and $q_i$ is the occupancy of the kernel on the V100 GPU. Histogram for $q_i$ values is shown in \cref{fig:occupancy-histo}. Key takeaways from this figure are the following: \begin{itemize} \item ResNet-50 has a more kernels in almost every occupancy bucket. \item VGG11 has fewer number of kernels in almost every utilization bucket. \item Kernels that has the lowest occupancy constitute the majority of the observed kernels. \end{itemize} Using this profiling information, we aim to create a single number that represents the aggregate occupancy of each of these models. \begin{equation} C = \sum_{i=1}^N q_i t_i \label{eq:compute} \end{equation} \Cref{fig:weighted-compute-util} shows the value of $C$ presented in \cref{eq:compute} for different models and different batch sizes. As we increase the batch size, the $C$ value increases for all the jobs that we studied. ResNet-50 has the highest occupancy compared to all the other deep learning models. While ResNet-50 does not have the largest number of parameters, it is able to achieve higher occupancy compared to all the other models. Since $C$ and $M$ are correlated with each other in the models we studied, both of them can be used for predicting the speedup of the co-location of the deep learning models. \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/occupancy-histo} \caption{Histogram of the achieved occupancy of the kernels for models under study. The batch size is equal to 64. If a kernel is run multiple times, the results are not grouped together and is assumed as a separate kernel. The unit for x-axis is in percent and the y-axis is log based. This graph includes the results for two iterations of training.The kernels were analyzed individually without sharing the resources with any other application.} \label{fig:occupancy-histo} \end{figure} \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/wa-kernel-occupancy} \caption{Weighted average of the kernel occupancy of the models using various batch sizes} \label{fig:weighted-compute-util} \end{figure} \subsection{Identifying Relationship between Models and Speedup} Now, we want to use the metrics described in the previous subsections, to build a classifier that is able to predict when the jobs will benefit from co-location and when they will suffer from it. \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/speedup-colorful} \caption{Relationship between models and jobs speedup when MPS is disabled.} \label{fig:speedup} \end{figure} \Cref{fig:speedup} shows the job speedup vs the pair of metrics discussed in the previous subsections. In the experiments described in the figure, MPS is not enabled. Each dot represents a single co-location experiment. The experiments presented in this figure includes all the previous experiments described in this chapter. Each dot may represent an experiment with only two jobs or three jobs co-located. Also, the experiments contain all the batch sizes from 64 to 256 using all the models described. The y-axis is the sum of $C$ values of the individual jobs and x-axis is the sum of $M$ values. As shown in \Cref{fig:speedup}, speedup does not have a correlation with the sum of the $C$ and $M$ values when MPS is not enabled. This result is expected because when MPS is not enabled, a kernel with low occupancy that takes a long time to complete can block the execution of any other kernel. Thus, the speedup value when the MPS is not enabled does not have a linear correlation with either $M$ or $C$ values. \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/speedup-mps} \caption{Relationship between models and jobs speedup when MPS is enabled.} \label{fig:speedup-mps} \end{figure} \Cref{fig:speedup-mps} shows a similar figure but with MPS enabled. Contrary to \cref{fig:speedup-mps}, the cases where speedup is larger than 1 is linearly separable. Using this graph we can create simple classifiers that are able to predict the speedup given two or three different models. For example, a simple criteria like "$\sum C_i \leq 4 * 10^7$" is sufficient for our models and settings. This criteria is represented using the red line. Since the speedup gain is not very significant for the cases above the red line we will not co-locate the jobs above the red line together. We also investigated the cases where the red dots happen. All of the red dots happen when the batch size is 256. Co-location is not recommended for large batch sizes as it may lead to slowdown. \begin{figure} \centering \includegraphics[width=0.7\textwidth]{figs/experiments/speedup-colorful-mps} \caption{Relationship between models and jobs speedup when MPS is enabled.} \label{fig:colorful-speedup-mps} \end{figure} \Cref{fig:colorful-speedup-mps} shows the exact value of the speedup using colors. As you can see in this figure, jobs with smaller $C$ and $M$ values achieve higher speedups. We will use this heuristic for designing the scheduler that uses co-location in \cref{chap:scheduler}. \subsection{MPS Effect} \begin{figure}[h!] \centering \includegraphics[width=0.7\textwidth]{figs/experiments/mps-effect} \caption{MPS effect on Speedup} \label{fig:mps-impact} \end{figure} From the previous figures it is hard to argue whether MPS is helpful for the speedup or not. \Cref{fig:mps-impact} shows the histogram of the increase in speedup when using MPS. Using MPS leads to higher speedup in most cases. However, for large batch sizes (e.g. 256) using MPS may lead to resource contention and slowdown the jobs execution. \section{Summary} In this chapter we introduced the formulation for modeling the speedup. This formulation is able to generalize to co-location of more than two jobs on a single GPU and does not depend on the batch size. We presented detailed profiling of the models used in this study. We created metrics that described the overall performance of the job in terms of key utilization metrics. We also shown why the jobs speedup is not correlated with the values of $C$ and $M$ when MPS is not enabled. It was also shown how you can build classifiers for detecting the compatible jobs when deciding on which job should be co-located with a given job. In the next chapter, we will build on these insights to create a real scheduler that is able to utilize co-location to decrease the makespan and queuing time.
If $A$ and $B$ are measurable sets, then the measure of their union is the sum of the measures of $A$ and $B$ minus the measure of their intersection.
If $A$ and $B$ are measurable sets, then the measure of their union is the sum of the measures of $A$ and $B$ minus the measure of their intersection.
%% LaTeX Beamer presentation template (requires beamer package) %% see http://bitbucket.org/rivanvx/beamer/wiki/Home %% idea contributed by H. Turgut Uyar %% template based on a template by Till Tantau %% this template is still evolving - it might differ in future releases! \documentclass{beamer} \mode<presentation> { \usetheme{Singapore} \setbeamertemplate{footline}[frame number] \usefonttheme{serif} \setbeamertemplate{navigation symbols}{} \setbeamertemplate{caption}[numbered] % \setbeamercovered{transparent} } \usepackage{graphics} \usepackage{mathtools} \DeclarePairedDelimiter\ceil{\lceil}{\rceil} \DeclarePairedDelimiter\floor{\lfloor}{\rfloor} \title{Tutorial} %\subtitle{} %\author{Hengfeng Wei} % \institute[Universities of] % { % Institute of Computer Software, NJU % } \date{\today} % If you have a file called "university-logo-filename.xxx", where xxx % is a graphic format that can be processed by latex or pdflatex, % resp., then you can add a logo as follows: % \pgfdeclareimage[height=0.5cm]{university-logo}{university-logo-filename} % \logo{\pgfuseimage{university-logo}} % Delete this, if you do not want the table of contents to pop up at % the beginning of each subsection: \AtBeginSubsection[] { \begin{frame}<beamer> \frametitle{Tutorial} \tableofcontents[currentsection] \end{frame} } \AtBeginSection[] { \begin{frame}<beamer> \frametitle{Tutorial} \tableofcontents[currentsection] \end{frame} } % If you wish to uncover everything in a step-wise fashion, uncomment % the following command: %\beamerdefaultoverlayspecification{<+->} \begin{document} \begin{frame} \titlepage \end{frame} \begin{frame} \frametitle{Tutorial} \tableofcontents % You might wish to add the option [pausesections] \end{frame} %%%%%%%%%%%%%%% \section{Amortized Analysis} \begin{frame} \frametitle{Basic} \begin{quote} Amortized analysis is a strategy for analyzing \\ \textcolor{blue}{a sequence of operations} to show that \\ \textcolor{blue}{the average cost per operation} is small, \\ even though a \textcolor{blue}{single operation within the sequence might be expensive}. \end{quote} \vspace{0.30cm} Key points: \begin{itemize} \setlength{\itemsep}{3pt} \item $\neq$ average-case analysis; \textcolor{red}{no probability here}\\ (\textsc{Quick-Sort}, \textsc{HashTable}) \item worst-case analysis; upper-bound \item on operation sequence; not on separate operations \item cheap ops (often) vs. expensive ops (occasionally) \end{itemize} \end{frame} \begin{frame} \frametitle{Basic} Methods: \begin{itemize} \setlength{\itemsep}{3pt} \item summation method \begin{itemize} \item the op sequence is known and easy to analyze \item sum and then average \end{itemize} \item accounting method \begin{itemize} \item impose an extra charge on inexpensive ops and use it to pay for expensive ops later on \end{itemize} \end{itemize} \end{frame} \begin{frame} \frametitle{Example for Summation Method} \begin{example}[Binary Counter] \begin{itemize} \item start from 0 \item \textsc{Increment} \item measure: \emph{bit flip} \item cost sequence: $1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,\ldots$ \item think globally about each bit: \[ \sum_{i=0}^{\floor{\log n}} \floor{\frac{n}{2^i}} < n \sum_{i=0}^{\infty} \floor{\frac{1}{2^i}} = 2n \] \item average cost per op: $2$ \end{itemize} \end{example} \end{frame} \begin{frame} \frametitle{Accounting Method} Accounting method: \\ \emph{amortized cost = actual cost + accounting cost} \[ \hat{c_i} = c_i + a_i, a_i >=< 0. \] \[ \forall n, \sum_{i=1}^{n} \hat{c_i} = \sum_{i=1}^{n} c_i + \sum_{i=1}^{n} a_i \] \begin{itemize} \item upper bound: the \emph{total amortized cost} of a sequence of ops must be an upper bound on the \emph{total actual cost} of the sequence \[ \forall n, \sum_{i=1}^{n} \hat{c_i} \geq \sum_{i=1}^{n} c_i \Rightarrow \textcolor{red}{\forall n, \sum_{i=1}^{n} a_i \geq 0} \] \item put the accounting cost on specific objects \end{itemize} \end{frame} \begin{frame} \frametitle{Example for Accounting Method} \begin{example}[Binary Counter] To show that $\hat{c_i} = 2$: \begin{itemize} \item low-level bit: $0 \to 1 (c=2 = 1:set+1:accouting)$ \item put the accounting (1) on the bit 1; number of 1s = sum of accounting $\geq 0$ \item $1 \to 0 (c=0)$ \item \textsc{Increment} $\hat{c_i} = 2: (0 \to 1) + (1 \to 0)$; \emph{at most $0 \to 1$} \end{itemize} \end{example} \begin{block}{Remarks} \begin{itemize} \item \emph{you cannot say:} cost per operation = 2 \item \emph{you should say:} average cost per operation over any operation sequence $\leq$ 2 \item constant vs. variable \item \textsc{Decrement}? how to support \textsc{Decrement} in $O(1)$? \end{itemize} \end{block} \end{frame} \begin{frame} \frametitle{Table Expansion} \begin{example}[Table Expansion] \begin{itemize} \item ``double when it is full'' \item \textsc{Table-Insert} \item measure: \emph{elementary insert} \end{itemize} \begin{itemize} \item Summation Method: \\ \emph{a sequence of $n$ \textsc{Table-Insert}} \begin{itemize} \item \begin{displaymath} c_i = \left\{ \begin{array}{ll} i & \textrm{if $i-1$ is an exact power of 2}\\ l & \textrm{o.w.} \end{array} \right. \end{displaymath} \item \[ \sum_{i=1}^{n} c_i \leq n + \sum_{j=0}^{\floor{\lg n}} 2^j < n + 2n = 3n. \] \end{itemize} \end{itemize} \end{example} \end{frame} \begin{frame} \frametitle{Table Expansion} \begin{example}[Table Expansion] \begin{itemize} \item ``double when it is full'' \item \textsc{Table-Insert} \item measure: \emph{elementary insert} \end{itemize} \begin{itemize} \item Accounting Method: \\ \emph{why $\hat{c_i} = 3$? why not 2?} \begin{itemize} \setlength{\itemsep}{3pt} \item check $\hat{c_i} = 2 = 1 (insert) + 1 (move)$ \item problem: $2 \Rightarrow 4 (\textrm{after expansion}, \sum a_i = 0) \Rightarrow 8$ \item so, $\hat{c_i} = 3 = 1 (insert) + 1 (\textrm{move itself}) + 1 (\textrm{give a hand})$ \item Meta-method: \textcolor{red}{trial and error} \end{itemize} \end{itemize} \end{example} \end{frame} \begin{frame} \frametitle{Insertion Cost (4.2.7)} \begin{example}[Insertion Cost (4.2.7)] \begin{itemize} \item \textsc{Insert} \item measure: create + merge ($2m$) \end{itemize} Summation Method: \[ \sum_{i=1}^{n} c_i = \sum_{j=0}^{\lfloor \log n \rfloor} \lfloor \frac{n}{2^j} \rfloor 2^j \le n (\lfloor \log n \rfloor + 1) \] Accounting Method: \begin{itemize} \item $\hat{c_i} = 1 + \lfloor \log n \rfloor$ \item consider each inserted element \item to check $\sum a_i = \sum_{i} (\lg n - D_{a_i}) \geq 0$ \end{itemize} \end{example} \end{frame} \begin{frame} \frametitle{Union Find} \begin{example}[Union Find] \begin{itemize} \item \textsc{Make-Set} \item \textsc{wUnion} \item \textsc{cFind}: beautiful code ($P_{289}$, $P_{508}$) \item $\hat{c}$ \emph{are different} \item worst-case \end{itemize} \end{example} \end{frame} %%%%%%%%%%%%%%% \section{Adversary Argument} \begin{frame} \frametitle{Basic} \begin{itemize} \item lower bound \[ T(A) = \max_{I} T(A,I) \] \[ T(P) = \min_{A} \max_{I} T(A,I) \] \item two directions: \uppercase{Sorting} \[ n! \Rightarrow n^2 (cards) \Rightarrow n \lg n (\textrm{John von Neumann}@1948) \Rightarrow ??? \] \[ n \Rightarrow n \lg n \] \item adversary argument \begin{itemize} \setlength{\itemsep}{3pt} \item alg vs. adversary \item \emph{alg says:} I have a dream \item \emph{adversary says:} pay something \textcolor{red}{necessary} \item adversary strategy: also an alg; \textcolor{red}{How to construct it?} \item finding min and max; finding the second largest; \\ finding median; horse racing; matrix search \end{itemize} \end{itemize} \end{frame} \begin{frame} \frametitle{Finding the Median} \begin{example}[Finding the Median] \begin{itemize} \item decision tree \begin{itemize} \item tree vs. alg \item path vs. execution on input \item internal node vs. comparison \item leaf vs. output \end{itemize} \item $\forall$ leaf, $x^{\ast}$: every other keys are comparable to $x^{\ast}$. \textcolor{red}{why?} \item critical comparison (first): $\forall y, \exists y \textrm{ vs. } z: y > z \geq x^{\ast} \textrm{ or } y < z \leq x^{\ast}$ \begin{itemize} \item path, internal node \item \emph{alg:} how do I know? \item \emph{adversary:} no, you don't know. It is my \emph{private classification}. \item \emph{alg:} so you can cheat! \item \emph{adversary:} no, look at this path; critical, critical, non-critical $\ldots$ (example) \end{itemize} \end{itemize} \end{example} \end{frame} \begin{frame} \frametitle{Finding the Median} \begin{example}[Finding the Median] Adversary: \emph{to enfore critical comparisons + non-critical operations as many as possible} \begin{itemize} \item critical: $n-1$ \item non-critical: \begin{itemize} \item $L;N;S$ \item \textsc{Compare}$(x,y)$ until $|L| = \frac{n-1}{2}$ or $|R| = \frac{n-1}{2}$ $$N,N;N,S; S,N;N,L; L,N;$$ $$L,S; S,L;$$ $$L,L; S,S \textrm{(\emph{maybe critical}; however no new } L, S)$$ \end{itemize} \item \emph{alg:} do $|L| = \frac{n-1}{2}$ at least; via \textsc{Compare} \item \emph{adversary:} $1 L$ per compare at most; all non-critical \item \emph{alg:} at least $\frac{n-1}{2}$ non-critical comparisons \end{itemize} \end{example} \end{frame} \begin{frame} \frametitle{Horse Racing} \begin{example}[Horse Racing] \begin{itemize} \item 25;5;3 \item 7 rounds \item adversary argument \begin{itemize} \item $< 5$: \textcolor{red}{why?} \item $= 5$: which is the fastest? \item $= 6$: to know the fastest, you must run the five first ranked \textcolor{red}{why?} \item $= 6$: which is the second? ($a_2, b_1$) \end{itemize} \end{itemize} \end{example} \end{frame} \begin{frame} \frametitle{Matrix Search} \begin{example}[Matrix Search ($P_{246}$, 5.24)] \begin{itemize} \item $M[n][n]$; row; column \item $n^2 \Rightarrow T(n) = 3T(\frac{n}{2}) + O(1) = n^{\lg 3} \Rightarrow 2n-1$ \item $2n-1:$ check the below-left corner element \item worst case: check the two diagonals $i+j=n-1,i+j=n$ \item adversary \textsc{Compare$(x, M[i,j])$}: \[ i + j \leq n-1 : x > M[i,j]; i + j > n-1 : x < M[i,j] \] \item \emph{alg:} at least check every element in two diagonals \item \emph{adversary:} eliminates 1 at most per comparison \item \emph{alg:} at least $2n-1$ comparisons \end{itemize} \end{example} \end{frame} %%%%%%%%%%%%%%%%%% \section{Other Problems} \begin{frame} \frametitle{Other Problems} \begin{itemize} \setlength{\itemsep}{5pt} \item 4.2.3: sorted, distinct; $O(\lg n)$; $a_i = i$; binary search; $T(n) = T(\frac{n}{2}) + O(1)$ \item 4.2.5: search for two numbers; $x = a+b$; \textcolor{red}{extension: sorted}; Ex: 1,2,3,5,8,9;2,3,4,6,10,12 \textcolor{red}{[proof or counterexample]} \item 4.2.6: closed address hashing \[ Q_k = (\frac{1}{n})^k (1-\frac{1}{n})^{n-k} \binom{n}{k} \] \item 4.1.4,4.1.5,4.1.6: binomial tree \item 2.1.2: $H \leq N -1$ \end{itemize} \end{frame} %%%%%%%%%% % \section*{Summary} % \begin{frame} % \frametitle{} % % % \begin{figure}[htp] % % \centering % % \includegraphics[scale = 0.40]{figure/thankyou.png} % % \end{figure} % \end{frame} %%%%%%%%%% \end{document}
[STATEMENT] lemma pdevs_domain_nlex_pdevs[simp]: "pdevs_domain (nlex_pdevs x) = pdevs_domain x" [PROOF STATE] proof (prove) goal (1 subgoal): 1. pdevs_domain (nlex_pdevs x) = pdevs_domain x [PROOF STEP] by (auto simp: pdevs_domain_def)
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-} -- | -- Module : Statistics.Distribution.Geometric -- Copyright : (c) 2009 Bryan O'Sullivan -- License : BSD3 -- -- Maintainer : [email protected] -- Stability : experimental -- Portability : portable -- -- The Geometric distribution. There are two variants of -- distribution. First is the probability distribution of the number -- of Bernoulli trials needed to get one success, supported on the set -- [1,2..] ('GeometricDistribution'). Sometimes it's referred to as -- the /shifted/ geometric distribution to distinguish from another -- one. -- -- Second variant is probability distribution of the number of -- failures before first success, defined over the set [0,1..] -- ('GeometricDistribution0'). module Statistics.Distribution.Geometric ( GeometricDistribution , GeometricDistribution0 -- * Constructors , geometric , geometricE , geometric0 , geometric0E -- ** Accessors , gdSuccess , gdSuccess0 ) where import Control.Applicative import Control.Monad (liftM) import Data.Aeson (FromJSON(..), ToJSON, Value(..), (.:)) import Data.Binary (Binary(..)) import Data.Data (Data, Typeable) import GHC.Generics (Generic) import Numeric.MathFunctions.Constants (m_pos_inf, m_neg_inf) import qualified System.Random.MWC.Distributions as MWC import qualified Statistics.Distribution as D import Statistics.Internal ---------------------------------------------------------------- -- | Distribution over [1..] newtype GeometricDistribution = GD { gdSuccess :: Double } deriving (Eq, Typeable, Data, Generic) instance Show GeometricDistribution where showsPrec i (GD x) = defaultShow1 "geometric" x i instance Read GeometricDistribution where readPrec = defaultReadPrecM1 "geometric" geometricE instance ToJSON GeometricDistribution instance FromJSON GeometricDistribution where parseJSON (Object v) = do x <- v .: "gdSuccess" maybe (fail $ errMsg x) return $ geometricE x parseJSON _ = empty instance Binary GeometricDistribution where put (GD x) = put x get = do x <- get maybe (fail $ errMsg x) return $ geometricE x instance D.Distribution GeometricDistribution where cumulative = cumulative instance D.DiscreteDistr GeometricDistribution where probability (GD s) n | n < 1 = 0 | otherwise = s * (1-s) ** (fromIntegral n - 1) logProbability (GD s) n | n < 1 = m_neg_inf | otherwise = log s + log (1-s) * (fromIntegral n - 1) instance D.Mean GeometricDistribution where mean (GD s) = 1 / s instance D.Variance GeometricDistribution where variance (GD s) = (1 - s) / (s * s) instance D.MaybeMean GeometricDistribution where maybeMean = Just . D.mean instance D.MaybeVariance GeometricDistribution where maybeStdDev = Just . D.stdDev maybeVariance = Just . D.variance instance D.Entropy GeometricDistribution where entropy (GD s) | s == 0 = m_pos_inf | s == 1 = 0 | otherwise = negate $ (s * log s + (1-s) * log (1-s)) / s instance D.MaybeEntropy GeometricDistribution where maybeEntropy = Just . D.entropy instance D.DiscreteGen GeometricDistribution where genDiscreteVar (GD s) g = MWC.geometric1 s g instance D.ContGen GeometricDistribution where genContVar d g = fromIntegral `liftM` D.genDiscreteVar d g cumulative :: GeometricDistribution -> Double -> Double cumulative (GD s) x | x < 1 = 0 | isInfinite x = 1 | isNaN x = error "Statistics.Distribution.Geometric.cumulative: NaN input" | otherwise = 1 - (1-s) ^ (floor x :: Int) -- | Create geometric distribution. geometric :: Double -- ^ Success rate -> GeometricDistribution geometric x = maybe (error $ errMsg x) id $ geometricE x -- | Create geometric distribution. geometricE :: Double -- ^ Success rate -> Maybe GeometricDistribution geometricE x | x >= 0 && x <= 1 = Just (GD x) | otherwise = Nothing errMsg :: Double -> String errMsg x = "Statistics.Distribution.Geometric.geometric: probability must be in [0,1] range. Got " ++ show x ---------------------------------------------------------------- -- | Distribution over [0..] newtype GeometricDistribution0 = GD0 { gdSuccess0 :: Double } deriving (Eq, Typeable, Data, Generic) instance Show GeometricDistribution0 where showsPrec i (GD0 x) = defaultShow1 "geometric0" x i instance Read GeometricDistribution0 where readPrec = defaultReadPrecM1 "geometric0" geometric0E instance ToJSON GeometricDistribution0 instance FromJSON GeometricDistribution0 where parseJSON (Object v) = do x <- v .: "gdSuccess0" maybe (fail $ errMsg x) return $ geometric0E x parseJSON _ = empty instance Binary GeometricDistribution0 where put (GD0 x) = put x get = do x <- get maybe (fail $ errMsg x) return $ geometric0E x instance D.Distribution GeometricDistribution0 where cumulative (GD0 s) x = cumulative (GD s) (x + 1) instance D.DiscreteDistr GeometricDistribution0 where probability (GD0 s) n = D.probability (GD s) (n + 1) logProbability (GD0 s) n = D.logProbability (GD s) (n + 1) instance D.Mean GeometricDistribution0 where mean (GD0 s) = 1 / s - 1 instance D.Variance GeometricDistribution0 where variance (GD0 s) = D.variance (GD s) instance D.MaybeMean GeometricDistribution0 where maybeMean = Just . D.mean instance D.MaybeVariance GeometricDistribution0 where maybeStdDev = Just . D.stdDev maybeVariance = Just . D.variance instance D.Entropy GeometricDistribution0 where entropy (GD0 s) = D.entropy (GD s) instance D.MaybeEntropy GeometricDistribution0 where maybeEntropy = Just . D.entropy instance D.DiscreteGen GeometricDistribution0 where genDiscreteVar (GD0 s) g = MWC.geometric0 s g instance D.ContGen GeometricDistribution0 where genContVar d g = fromIntegral `liftM` D.genDiscreteVar d g -- | Create geometric distribution. geometric0 :: Double -- ^ Success rate -> GeometricDistribution0 geometric0 x = maybe (error $ errMsg0 x) id $ geometric0E x -- | Create geometric distribution. geometric0E :: Double -- ^ Success rate -> Maybe GeometricDistribution0 geometric0E x | x >= 0 && x <= 1 = Just (GD0 x) | otherwise = Nothing errMsg0 :: Double -> String errMsg0 x = "Statistics.Distribution.Geometric.geometric0: probability must be in [0,1] range. Got " ++ show x
## Cory Baird # Problem set 1 # Question 1 - Two-period consumption-savings problem - For this problem, I want you to redo the two-period consumption-savings problem under certainty presented in class assuming that the utility function is of the exponential family: $$U(c) = \frac{-1}{a}e^{-ac}, a>0$$ ## 1.A Draw a picture of this utility function over positive c, and verify that this utility function is increasing and concave. - Note that there is nothing wrong with having utility be negative for all positive c--remember that the purpose of a utility function is ordinal, not cardinal. ```python # Import libraries import os import sys import numpy as np import sympy as sy from sympy.abc import a,c,b import matplotlib.pyplot as plt ``` ### 1.A. Solution: Plot ```python # Import user created function to plot exponential function from ps1_functions import consum_function_plot #Show the exponential function u_exp = (-1/a)*sy.exp(-a*c) u_exp #Plot the exponential function consum_function_plot(u_exp) plt.title('Exponential example: CARA'); ``` ## 1.B Set up the maximization problem, derive the exact form of the Euler equation with this utility function, and derive a closed-form solution for optimal consumption at time 1. - Assume that capital markets are perfect. ### 1.B Solution: Using the intertemporal budget constraint # Question 2 This problem asks you to solve a general T-period consumption-savings problem under certainty with perfect capital markets. Agents preferences $$\sum_{t=0}^T\beta^t U(c_t)\tag{2.1}$$ Where $$U(c) = \frac{\sigma}{\sigma-1} c^{\frac{\sigma-1}{\sigma}}\tag{2.2}$$ The agent's dynamic budget constraint (DBC) each period is given by: $$a_{t+1}=(1+r)(a_t+y_t-c_t)\tag{2.3}$$ It is not optimal for agent to die with positive wealth $A_{T+1}=0$ ## 2.A. Show that DBC (eq 2.3) combined with solvency requirement implies the following IBC $$\sum_{t=1}(\frac{1}{1+r})^t c_t = a_0+\sum_{t=0}^T(\frac{1}{1+r})^t y_t\tag{2.4}$$ ### 2.A: solution ## 2.B. Set up the agent's maximization problem, derive the Euler Equation, and find a closed form solution for c0. ### 2.B.1 Agent's maximization problem ### 2.B.2 Derive Euler equation ### 2.B.3 Closed form solution for $c_0$ ## 2.C. Now suppose that there is a liquidity constraint, of the form that at must be greater than or equal to zero each period. - Rewrite the problem adding this set of constraints, and re-derive the Euler equation. - Prove that if β(1+r) = 1, then optimal consumption must be a non-decreasing function of time while the agent is alive. ### 2.C.1 Rewrite the problem adding this set of constraints, and re-derive the Euler equation. #### 2.C.1.1 Lagrangian with constraints #### 2.C.1.2 #### 2.C.2 Prove that if β(1+r) = 1, then optimal consumption must be a non-decreasing function of time while the agent is alive. ## 2.D. - Suppose someone lives for 3 periods. - Their incomes satisfy y(3) > y(1) > y(2). Assume β(1+ r) is equal to 1. - Draw pictures graphing what income and consumption will look like over time for this person under three scenarios: 1. the life cycle model with no liquidity constraints - Keynesian/Myopic behavior - liquidity constraints. ### 2.D.1 Life cycle model with no liquitidy constraints ```python def life_cycle(): #Assume income is present value income = np.array([20,10,40]) consumption = np.repeat(np.mean(np.array([20,10,40])),3) plt.plot(income) plt.plot(consumption) plt.legend(['Income', "Consumption"]) plt.xlabel('Time period') life_cycle() ``` ### 2.D.2 Keynesian ```python def keynesian(): #Assume income is present value income = np.array([20,10,40]) mpc=.9 consumption = mpc*income plt.plot(income) plt.plot(consumption) plt.legend(['Income', "Consumption"]) plt.xlabel('Time period') keynesian() ``` ### 2.D.3 Liquidity constraints ```python def liquidity(): #Assume income is present value income = np.array([20,10,40]) consumption = np.array([.75, 1.5, 1])*income plt.plot(income) plt.plot(consumption) plt.legend(['Income', "Consumption"]) plt.xlabel('Time period') liquidity() ``` ```python ```