Datasets:
AI4M
/

text
stringlengths
0
3.34M
(** * SfLib: Software Foundations Library *) (** Here we collect together a few useful definitions from earlier chapters that are not provided as part of the Coq standard library. Later chapters will [Import] or [Export] just this file, instead of cluttering the top-level environment with all the examples and false starts in those files. *) Definition admit {T: Type} : T. Admitted. Tactic Notation "solve_by_inversion_step" tactic(t) := match goal with | H : _ |- _ => solve [ inversion H; subst; t ] end || fail "because the goal is not solvable by inversion.". Tactic Notation "solve" "by" "inversion" "1" := solve_by_inversion_step idtac. Tactic Notation "solve" "by" "inversion" "2" := solve_by_inversion_step (solve by inversion 1). Tactic Notation "solve" "by" "inversion" "3" := solve_by_inversion_step (solve by inversion 2). Tactic Notation "solve" "by" "inversion" := solve by inversion 1. (** $Date: 2016-01-24 21:56:22 +0000 (Sun, 24 Jan 2016) $ *)
[STATEMENT] lemma dim_Macaulay_mat[simp]: "dim_row (Macaulay_mat ps) = length ps" "dim_col (Macaulay_mat ps) = card (Keys (set ps))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. dim_row (Macaulay_mat ps) = length ps &&& dim_col (Macaulay_mat ps) = card (Keys (set ps)) [PROOF STEP] by (simp_all add: Macaulay_mat_def length_Keys_to_list)
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne ! This file was ported from Lean 3 source module measure_theory.function.ae_eq_of_integral ! leanprover-community/mathlib commit 46b633fd842bef9469441c0209906f6dddd2b4f5 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Analysis.NormedSpace.Dual import Mathbin.MeasureTheory.Function.StronglyMeasurable.Lp import Mathbin.MeasureTheory.Integral.SetIntegral /-! # From equality of integrals to equality of functions This file provides various statements of the general form "if two functions have the same integral on all sets, then they are equal almost everywhere". The different lemmas use various hypotheses on the class of functions, on the target space or on the possible finiteness of the measure. ## Main statements All results listed below apply to two functions `f, g`, together with two main hypotheses, * `f` and `g` are integrable on all measurable sets with finite measure, * for all measurable sets `s` with finite measure, `∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ`. The conclusion is then `f =ᵐ[μ] g`. The main lemmas are: * `ae_eq_of_forall_set_integral_eq_of_sigma_finite`: case of a sigma-finite measure. * `ae_fin_strongly_measurable.ae_eq_of_forall_set_integral_eq`: for functions which are `ae_fin_strongly_measurable`. * `Lp.ae_eq_of_forall_set_integral_eq`: for elements of `Lp`, for `0 < p < ∞`. * `integrable.ae_eq_of_forall_set_integral_eq`: for integrable functions. For each of these results, we also provide a lemma about the equality of one function and 0. For example, `Lp.ae_eq_zero_of_forall_set_integral_eq_zero`. We also register the corresponding lemma for integrals of `ℝ≥0∞`-valued functions, in `ae_eq_of_forall_set_lintegral_eq_of_sigma_finite`. Generally useful lemmas which are not related to integrals: * `ae_eq_zero_of_forall_inner`: if for all constants `c`, `λ x, inner c (f x) =ᵐ[μ] 0` then `f =ᵐ[μ] 0`. * `ae_eq_zero_of_forall_dual`: if for all constants `c` in the dual space, `λ x, c (f x) =ᵐ[μ] 0` then `f =ᵐ[μ] 0`. -/ open MeasureTheory TopologicalSpace NormedSpace Filter open ENNReal NNReal MeasureTheory namespace MeasureTheory section AeEqOfForall variable {α E 𝕜 : Type _} {m : MeasurableSpace α} {μ : Measure α} [IsROrC 𝕜] theorem ae_eq_zero_of_forall_inner [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [SecondCountableTopology E] {f : α → E} (hf : ∀ c : E, (fun x => (inner c (f x) : 𝕜)) =ᵐ[μ] 0) : f =ᵐ[μ] 0 := by let s := dense_seq E have hs : DenseRange s := dense_range_dense_seq E have hf' : ∀ᵐ x ∂μ, ∀ n : ℕ, inner (s n) (f x) = (0 : 𝕜) := ae_all_iff.mpr fun n => hf (s n) refine' hf'.mono fun x hx => _ rw [Pi.zero_apply, ← @inner_self_eq_zero 𝕜] have h_closed : IsClosed { c : E | inner c (f x) = (0 : 𝕜) } := isClosed_eq (continuous_id.inner continuous_const) continuous_const exact @isClosed_property ℕ E _ s (fun c => inner c (f x) = (0 : 𝕜)) hs h_closed (fun n => hx n) _ #align measure_theory.ae_eq_zero_of_forall_inner MeasureTheory.ae_eq_zero_of_forall_inner -- mathport name: «expr⟪ , ⟫» local notation "⟪" x ", " y "⟫" => y x variable (𝕜) theorem ae_eq_zero_of_forall_dual_of_isSeparable [NormedAddCommGroup E] [NormedSpace 𝕜 E] {t : Set E} (ht : TopologicalSpace.IsSeparable t) {f : α → E} (hf : ∀ c : Dual 𝕜 E, (fun x => ⟪f x, c⟫) =ᵐ[μ] 0) (h't : ∀ᵐ x ∂μ, f x ∈ t) : f =ᵐ[μ] 0 := by rcases ht with ⟨d, d_count, hd⟩ haveI : Encodable d := d_count.to_encodable have : ∀ x : d, ∃ g : E →L[𝕜] 𝕜, ‖g‖ ≤ 1 ∧ g x = ‖(x : E)‖ := fun x => exists_dual_vector'' 𝕜 x choose s hs using this have A : ∀ a : E, a ∈ t → (∀ x, ⟪a, s x⟫ = (0 : 𝕜)) → a = 0 := by intro a hat ha contrapose! ha have a_pos : 0 < ‖a‖ := by simp only [ha, norm_pos_iff, Ne.def, not_false_iff] have a_mem : a ∈ closure d := hd hat obtain ⟨x, hx⟩ : ∃ x : d, dist a x < ‖a‖ / 2 := by rcases Metric.mem_closure_iff.1 a_mem (‖a‖ / 2) (half_pos a_pos) with ⟨x, h'x, hx⟩ exact ⟨⟨x, h'x⟩, hx⟩ use x have I : ‖a‖ / 2 < ‖(x : E)‖ := by have : ‖a‖ ≤ ‖(x : E)‖ + ‖a - x‖ := norm_le_insert' _ _ have : ‖a - x‖ < ‖a‖ / 2 := by rwa [dist_eq_norm] at hx linarith intro h apply lt_irrefl ‖s x x‖ calc ‖s x x‖ = ‖s x (x - a)‖ := by simp only [h, sub_zero, ContinuousLinearMap.map_sub] _ ≤ 1 * ‖(x : E) - a‖ := (ContinuousLinearMap.le_of_op_norm_le _ (hs x).1 _) _ < ‖a‖ / 2 := by rw [one_mul] rwa [dist_eq_norm'] at hx _ < ‖(x : E)‖ := I _ = ‖s x x‖ := by rw [(hs x).2, IsROrC.norm_coe_norm] have hfs : ∀ y : d, ∀ᵐ x ∂μ, ⟪f x, s y⟫ = (0 : 𝕜) := fun y => hf (s y) have hf' : ∀ᵐ x ∂μ, ∀ y : d, ⟪f x, s y⟫ = (0 : 𝕜) := by rwa [ae_all_iff] filter_upwards [hf', h't]with x hx h'x exact A (f x) h'x hx #align measure_theory.ae_eq_zero_of_forall_dual_of_is_separable MeasureTheory.ae_eq_zero_of_forall_dual_of_isSeparable theorem ae_eq_zero_of_forall_dual [NormedAddCommGroup E] [NormedSpace 𝕜 E] [SecondCountableTopology E] {f : α → E} (hf : ∀ c : Dual 𝕜 E, (fun x => ⟪f x, c⟫) =ᵐ[μ] 0) : f =ᵐ[μ] 0 := ae_eq_zero_of_forall_dual_of_isSeparable 𝕜 (isSeparable_of_separableSpace (Set.univ : Set E)) hf (eventually_of_forall fun x => Set.mem_univ _) #align measure_theory.ae_eq_zero_of_forall_dual MeasureTheory.ae_eq_zero_of_forall_dual variable {𝕜} end AeEqOfForall variable {α E : Type _} {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {p : ℝ≥0∞} section AeEqOfForallSetIntegralEq theorem ae_const_le_iff_forall_lt_measure_zero {β} [LinearOrder β] [TopologicalSpace β] [OrderTopology β] [FirstCountableTopology β] (f : α → β) (c : β) : (∀ᵐ x ∂μ, c ≤ f x) ↔ ∀ b < c, μ { x | f x ≤ b } = 0 := by rw [ae_iff] push_neg constructor · intro h b hb exact measure_mono_null (fun y hy => (lt_of_le_of_lt hy hb : _)) h intro hc by_cases h : ∀ b, c ≤ b · have : { a : α | f a < c } = ∅ := by apply Set.eq_empty_iff_forall_not_mem.2 fun x hx => _ exact (lt_irrefl _ (lt_of_lt_of_le hx (h (f x)))).elim simp [this] by_cases H : ¬IsLUB (Set.Iio c) c · have : c ∈ upperBounds (Set.Iio c) := fun y hy => le_of_lt hy obtain ⟨b, b_up, bc⟩ : ∃ b : β, b ∈ upperBounds (Set.Iio c) ∧ b < c := by simpa [IsLUB, IsLeast, this, lowerBounds] using H exact measure_mono_null (fun x hx => b_up hx) (hc b bc) push_neg at H h obtain ⟨u, u_mono, u_lt, u_lim, -⟩ : ∃ u : ℕ → β, StrictMono u ∧ (∀ n : ℕ, u n < c) ∧ tendsto u at_top (nhds c) ∧ ∀ n : ℕ, u n ∈ Set.Iio c := H.exists_seq_strict_mono_tendsto_of_not_mem (lt_irrefl c) h have h_Union : { x | f x < c } = ⋃ n : ℕ, { x | f x ≤ u n } := by ext1 x simp_rw [Set.mem_unionᵢ, Set.mem_setOf_eq] constructor <;> intro h · obtain ⟨n, hn⟩ := ((tendsto_order.1 u_lim).1 _ h).exists exact ⟨n, hn.le⟩ · obtain ⟨n, hn⟩ := h exact hn.trans_lt (u_lt _) rw [h_Union, measure_Union_null_iff] intro n exact hc _ (u_lt n) #align measure_theory.ae_const_le_iff_forall_lt_measure_zero MeasureTheory.ae_const_le_iff_forall_lt_measure_zero section ENNReal open Topology theorem ae_le_of_forall_set_lintegral_le_of_sigmaFinite [SigmaFinite μ] {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (h : ∀ s, MeasurableSet s → μ s < ∞ → (∫⁻ x in s, f x ∂μ) ≤ ∫⁻ x in s, g x ∂μ) : f ≤ᵐ[μ] g := by have A : ∀ (ε N : ℝ≥0) (p : ℕ), 0 < ε → μ ({ x | g x + ε ≤ f x ∧ g x ≤ N } ∩ spanning_sets μ p) = 0 := by intro ε N p εpos let s := { x | g x + ε ≤ f x ∧ g x ≤ N } ∩ spanning_sets μ p have s_meas : MeasurableSet s := by have A : MeasurableSet { x | g x + ε ≤ f x } := measurableSet_le (hg.add measurable_const) hf have B : MeasurableSet { x | g x ≤ N } := measurableSet_le hg measurable_const exact (A.inter B).inter (measurable_spanning_sets μ p) have s_lt_top : μ s < ∞ := (measure_mono (Set.inter_subset_right _ _)).trans_lt (measure_spanning_sets_lt_top μ p) have A : (∫⁻ x in s, g x ∂μ) + ε * μ s ≤ (∫⁻ x in s, g x ∂μ) + 0 := calc (∫⁻ x in s, g x ∂μ) + ε * μ s = (∫⁻ x in s, g x ∂μ) + ∫⁻ x in s, ε ∂μ := by simp only [lintegral_const, Set.univ_inter, MeasurableSet.univ, measure.restrict_apply] _ = ∫⁻ x in s, g x + ε ∂μ := (lintegral_add_right _ measurable_const).symm _ ≤ ∫⁻ x in s, f x ∂μ := (set_lintegral_mono (hg.add measurable_const) hf fun x hx => hx.1.1) _ ≤ (∫⁻ x in s, g x ∂μ) + 0 := by rw [add_zero] exact h s s_meas s_lt_top have B : (∫⁻ x in s, g x ∂μ) ≠ ∞ := by apply ne_of_lt calc (∫⁻ x in s, g x ∂μ) ≤ ∫⁻ x in s, N ∂μ := set_lintegral_mono hg measurable_const fun x hx => hx.1.2 _ = N * μ s := by simp only [lintegral_const, Set.univ_inter, MeasurableSet.univ, measure.restrict_apply] _ < ∞ := by simp only [lt_top_iff_ne_top, s_lt_top.ne, and_false_iff, ENNReal.coe_ne_top, WithTop.mul_eq_top_iff, Ne.def, not_false_iff, false_and_iff, or_self_iff] have : (ε : ℝ≥0∞) * μ s ≤ 0 := ENNReal.le_of_add_le_add_left B A simpa only [ENNReal.coe_eq_zero, nonpos_iff_eq_zero, mul_eq_zero, εpos.ne', false_or_iff] obtain ⟨u, u_mono, u_pos, u_lim⟩ : ∃ u : ℕ → ℝ≥0, StrictAnti u ∧ (∀ n, 0 < u n) ∧ tendsto u at_top (nhds 0) := exists_seq_strictAnti_tendsto (0 : ℝ≥0) let s := fun n : ℕ => { x | g x + u n ≤ f x ∧ g x ≤ (n : ℝ≥0) } ∩ spanning_sets μ n have μs : ∀ n, μ (s n) = 0 := fun n => A _ _ _ (u_pos n) have B : { x | f x ≤ g x }ᶜ ⊆ ⋃ n, s n := by intro x hx simp at hx have L1 : ∀ᶠ n in at_top, g x + u n ≤ f x := by have : tendsto (fun n => g x + u n) at_top (𝓝 (g x + (0 : ℝ≥0))) := tendsto_const_nhds.add (ENNReal.tendsto_coe.2 u_lim) simp at this exact eventually_le_of_tendsto_lt hx this have L2 : ∀ᶠ n : ℕ in (at_top : Filter ℕ), g x ≤ (n : ℝ≥0) := haveI : tendsto (fun n : ℕ => ((n : ℝ≥0) : ℝ≥0∞)) at_top (𝓝 ∞) := by simp only [ENNReal.coe_nat] exact ENNReal.tendsto_nat_nhds_top eventually_ge_of_tendsto_gt (hx.trans_le le_top) this apply Set.mem_unionᵢ.2 exact ((L1.and L2).And (eventually_mem_spanning_sets μ x)).exists refine' le_antisymm _ bot_le calc μ ({ x : α | (fun x : α => f x ≤ g x) x }ᶜ) ≤ μ (⋃ n, s n) := measure_mono B _ ≤ ∑' n, μ (s n) := (measure_Union_le _) _ = 0 := by simp only [μs, tsum_zero] #align measure_theory.ae_le_of_forall_set_lintegral_le_of_sigma_finite MeasureTheory.ae_le_of_forall_set_lintegral_le_of_sigmaFinite theorem ae_eq_of_forall_set_lintegral_eq_of_sigmaFinite [SigmaFinite μ] {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (h : ∀ s, MeasurableSet s → μ s < ∞ → (∫⁻ x in s, f x ∂μ) = ∫⁻ x in s, g x ∂μ) : f =ᵐ[μ] g := by have A : f ≤ᵐ[μ] g := ae_le_of_forall_set_lintegral_le_of_sigma_finite hf hg fun s hs h's => le_of_eq (h s hs h's) have B : g ≤ᵐ[μ] f := ae_le_of_forall_set_lintegral_le_of_sigma_finite hg hf fun s hs h's => ge_of_eq (h s hs h's) filter_upwards [A, B]with x using le_antisymm #align measure_theory.ae_eq_of_forall_set_lintegral_eq_of_sigma_finite MeasureTheory.ae_eq_of_forall_set_lintegral_eq_of_sigmaFinite end ENNReal section Real variable {f : α → ℝ} /-- Don't use this lemma. Use `ae_nonneg_of_forall_set_integral_nonneg`. -/ theorem ae_nonneg_of_forall_set_integral_nonneg_of_stronglyMeasurable (hfm : StronglyMeasurable f) (hf : Integrable f μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by simp_rw [eventually_le, Pi.zero_apply] rw [ae_const_le_iff_forall_lt_measure_zero] intro b hb_neg let s := { x | f x ≤ b } have hs : MeasurableSet s := hfm.measurable_set_le strongly_measurable_const have mus : μ s < ∞ := by let c : ℝ≥0 := ⟨|b|, abs_nonneg _⟩ have c_pos : (c : ℝ≥0∞) ≠ 0 := by simpa using hb_neg.ne calc μ s ≤ μ { x | (c : ℝ≥0∞) ≤ ‖f x‖₊ } := by apply measure_mono intro x hx simp only [Set.mem_setOf_eq] at hx simpa only [nnnorm, abs_of_neg hb_neg, abs_of_neg (hx.trans_lt hb_neg), Real.norm_eq_abs, Subtype.mk_le_mk, neg_le_neg_iff, Set.mem_setOf_eq, ENNReal.coe_le_coe] using hx _ ≤ (∫⁻ x, ‖f x‖₊ ∂μ) / c := (meas_ge_le_lintegral_div hfm.ae_measurable.ennnorm c_pos ENNReal.coe_ne_top) _ < ∞ := ENNReal.div_lt_top (ne_of_lt hf.2) c_pos have h_int_gt : (∫ x in s, f x ∂μ) ≤ b * (μ s).toReal := by have h_const_le : (∫ x in s, f x ∂μ) ≤ ∫ x in s, b ∂μ := by refine' set_integral_mono_ae_restrict hf.integrable_on (integrable_on_const.mpr (Or.inr mus)) _ rw [eventually_le, ae_restrict_iff hs] exact eventually_of_forall fun x hxs => hxs rwa [set_integral_const, smul_eq_mul, mul_comm] at h_const_le by_contra refine' (lt_self_iff_false (∫ x in s, f x ∂μ)).mp (h_int_gt.trans_lt _) refine' (mul_neg_iff.mpr (Or.inr ⟨hb_neg, _⟩)).trans_le _ swap · simp_rw [measure.restrict_restrict hs] exact hf_zero s hs mus refine' ENNReal.toReal_nonneg.lt_of_ne fun h_eq => h _ cases' (ENNReal.toReal_eq_zero_iff _).mp h_eq.symm with hμs_eq_zero hμs_eq_top · exact hμs_eq_zero · exact absurd hμs_eq_top mus.ne #align measure_theory.ae_nonneg_of_forall_set_integral_nonneg_of_strongly_measurable MeasureTheory.ae_nonneg_of_forall_set_integral_nonneg_of_stronglyMeasurable theorem ae_nonneg_of_forall_set_integral_nonneg (hf : Integrable f μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by rcases hf.1 with ⟨f', hf'_meas, hf_ae⟩ have hf'_integrable : integrable f' μ := integrable.congr hf hf_ae have hf'_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f' x ∂μ := by intro s hs h's rw [set_integral_congr_ae hs (hf_ae.mono fun x hx hxs => hx.symm)] exact hf_zero s hs h's exact (ae_nonneg_of_forall_set_integral_nonneg_of_strongly_measurable hf'_meas hf'_integrable hf'_zero).trans hf_ae.symm.le #align measure_theory.ae_nonneg_of_forall_set_integral_nonneg MeasureTheory.ae_nonneg_of_forall_set_integral_nonneg theorem ae_le_of_forall_set_integral_le {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (hf_le : ∀ s, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) ≤ ∫ x in s, g x ∂μ) : f ≤ᵐ[μ] g := by rw [← eventually_sub_nonneg] refine' ae_nonneg_of_forall_set_integral_nonneg (hg.sub hf) fun s hs => _ rw [integral_sub' hg.integrable_on hf.integrable_on, sub_nonneg] exact hf_le s hs #align measure_theory.ae_le_of_forall_set_integral_le MeasureTheory.ae_le_of_forall_set_integral_le theorem ae_nonneg_restrict_of_forall_set_integral_nonneg_inter {f : α → ℝ} {t : Set α} (hf : IntegrableOn f t μ) (hf_zero : ∀ s, MeasurableSet s → μ (s ∩ t) < ∞ → 0 ≤ ∫ x in s ∩ t, f x ∂μ) : 0 ≤ᵐ[μ.restrict t] f := by refine' ae_nonneg_of_forall_set_integral_nonneg hf fun s hs h's => _ simp_rw [measure.restrict_restrict hs] apply hf_zero s hs rwa [measure.restrict_apply hs] at h's #align measure_theory.ae_nonneg_restrict_of_forall_set_integral_nonneg_inter MeasureTheory.ae_nonneg_restrict_of_forall_set_integral_nonneg_inter theorem ae_nonneg_of_forall_set_integral_nonneg_of_sigmaFinite [SigmaFinite μ] {f : α → ℝ} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by apply ae_of_forall_measure_lt_top_ae_restrict intro t t_meas t_lt_top apply ae_nonneg_restrict_of_forall_set_integral_nonneg_inter (hf_int_finite t t_meas t_lt_top) intro s s_meas hs exact hf_zero _ (s_meas.inter t_meas) (lt_of_le_of_lt (measure_mono (Set.inter_subset_right _ _)) t_lt_top) #align measure_theory.ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite MeasureTheory.ae_nonneg_of_forall_set_integral_nonneg_of_sigmaFinite theorem AeFinStronglyMeasurable.ae_nonneg_of_forall_set_integral_nonneg {f : α → ℝ} (hf : AeFinStronglyMeasurable f μ) (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) : 0 ≤ᵐ[μ] f := by let t := hf.sigma_finite_set suffices : 0 ≤ᵐ[μ.restrict t] f exact ae_of_ae_restrict_of_ae_restrict_compl _ this hf.ae_eq_zero_compl.symm.le haveI : sigma_finite (μ.restrict t) := hf.sigma_finite_restrict refine' ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite (fun s hs hμts => _) fun s hs hμts => _ · rw [integrable_on, measure.restrict_restrict hs] rw [measure.restrict_apply hs] at hμts exact hf_int_finite (s ∩ t) (hs.inter hf.measurable_set) hμts · rw [measure.restrict_restrict hs] rw [measure.restrict_apply hs] at hμts exact hf_zero (s ∩ t) (hs.inter hf.measurable_set) hμts #align measure_theory.ae_fin_strongly_measurable.ae_nonneg_of_forall_set_integral_nonneg MeasureTheory.AeFinStronglyMeasurable.ae_nonneg_of_forall_set_integral_nonneg theorem ae_nonneg_restrict_of_forall_set_integral_nonneg {f : α → ℝ} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) {t : Set α} (ht : MeasurableSet t) (hμt : μ t ≠ ∞) : 0 ≤ᵐ[μ.restrict t] f := by refine' ae_nonneg_restrict_of_forall_set_integral_nonneg_inter (hf_int_finite t ht (lt_top_iff_ne_top.mpr hμt)) fun s hs h's => _ refine' hf_zero (s ∩ t) (hs.inter ht) _ exact (measure_mono (Set.inter_subset_right s t)).trans_lt (lt_top_iff_ne_top.mpr hμt) #align measure_theory.ae_nonneg_restrict_of_forall_set_integral_nonneg MeasureTheory.ae_nonneg_restrict_of_forall_set_integral_nonneg theorem ae_eq_zero_restrict_of_forall_set_integral_eq_zero_real {f : α → ℝ} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = 0) {t : Set α} (ht : MeasurableSet t) (hμt : μ t ≠ ∞) : f =ᵐ[μ.restrict t] 0 := by suffices h_and : f ≤ᵐ[μ.restrict t] 0 ∧ 0 ≤ᵐ[μ.restrict t] f exact h_and.1.mp (h_and.2.mono fun x hx1 hx2 => le_antisymm hx2 hx1) refine' ⟨_, ae_nonneg_restrict_of_forall_set_integral_nonneg hf_int_finite (fun s hs hμs => (hf_zero s hs hμs).symm.le) ht hμt⟩ suffices h_neg : 0 ≤ᵐ[μ.restrict t] -f · refine' h_neg.mono fun x hx => _ rw [Pi.neg_apply] at hx simpa using hx refine' ae_nonneg_restrict_of_forall_set_integral_nonneg (fun s hs hμs => (hf_int_finite s hs hμs).neg) (fun s hs hμs => _) ht hμt simp_rw [Pi.neg_apply] rw [integral_neg, neg_nonneg] exact (hf_zero s hs hμs).le #align measure_theory.ae_eq_zero_restrict_of_forall_set_integral_eq_zero_real MeasureTheory.ae_eq_zero_restrict_of_forall_set_integral_eq_zero_real end Real theorem ae_eq_zero_restrict_of_forall_set_integral_eq_zero {f : α → E} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = 0) {t : Set α} (ht : MeasurableSet t) (hμt : μ t ≠ ∞) : f =ᵐ[μ.restrict t] 0 := by rcases(hf_int_finite t ht hμt.lt_top).AeStronglyMeasurable.isSeparable_ae_range with ⟨u, u_sep, hu⟩ refine' ae_eq_zero_of_forall_dual_of_is_separable ℝ u_sep (fun c => _) hu refine' ae_eq_zero_restrict_of_forall_set_integral_eq_zero_real _ _ ht hμt · intro s hs hμs exact ContinuousLinearMap.integrableComp c (hf_int_finite s hs hμs) · intro s hs hμs rw [ContinuousLinearMap.integral_comp_comm c (hf_int_finite s hs hμs), hf_zero s hs hμs] exact ContinuousLinearMap.map_zero _ #align measure_theory.ae_eq_zero_restrict_of_forall_set_integral_eq_zero MeasureTheory.ae_eq_zero_restrict_of_forall_set_integral_eq_zero theorem ae_eq_restrict_of_forall_set_integral_eq {f g : α → E} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hg_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn g s μ) (hfg_zero : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = ∫ x in s, g x ∂μ) {t : Set α} (ht : MeasurableSet t) (hμt : μ t ≠ ∞) : f =ᵐ[μ.restrict t] g := by rw [← sub_ae_eq_zero] have hfg' : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, (f - g) x ∂μ) = 0 := by intro s hs hμs rw [integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs)] exact sub_eq_zero.mpr (hfg_zero s hs hμs) have hfg_int : ∀ s, MeasurableSet s → μ s < ∞ → integrable_on (f - g) s μ := fun s hs hμs => (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs) exact ae_eq_zero_restrict_of_forall_set_integral_eq_zero hfg_int hfg' ht hμt #align measure_theory.ae_eq_restrict_of_forall_set_integral_eq MeasureTheory.ae_eq_restrict_of_forall_set_integral_eq theorem ae_eq_zero_of_forall_set_integral_eq_of_sigmaFinite [SigmaFinite μ] {f : α → E} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = 0) : f =ᵐ[μ] 0 := by let S := spanning_sets μ rw [← @measure.restrict_univ _ _ μ, ← Union_spanning_sets μ, eventually_eq, ae_iff, measure.restrict_apply' (MeasurableSet.unionᵢ (measurable_spanning_sets μ))] rw [Set.inter_unionᵢ, measure_Union_null_iff] intro n have h_meas_n : MeasurableSet (S n) := measurable_spanning_sets μ n have hμn : μ (S n) < ∞ := measure_spanning_sets_lt_top μ n rw [← measure.restrict_apply' h_meas_n] exact ae_eq_zero_restrict_of_forall_set_integral_eq_zero hf_int_finite hf_zero h_meas_n hμn.ne #align measure_theory.ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite MeasureTheory.ae_eq_zero_of_forall_set_integral_eq_of_sigmaFinite theorem ae_eq_of_forall_set_integral_eq_of_sigmaFinite [SigmaFinite μ] {f g : α → E} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hg_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn g s μ) (hfg_eq : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = ∫ x in s, g x ∂μ) : f =ᵐ[μ] g := by rw [← sub_ae_eq_zero] have hfg : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, (f - g) x ∂μ) = 0 := by intro s hs hμs rw [integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs), sub_eq_zero.mpr (hfg_eq s hs hμs)] have hfg_int : ∀ s, MeasurableSet s → μ s < ∞ → integrable_on (f - g) s μ := fun s hs hμs => (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs) exact ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite hfg_int hfg #align measure_theory.ae_eq_of_forall_set_integral_eq_of_sigma_finite MeasureTheory.ae_eq_of_forall_set_integral_eq_of_sigmaFinite theorem AeFinStronglyMeasurable.ae_eq_zero_of_forall_set_integral_eq_zero {f : α → E} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = 0) (hf : AeFinStronglyMeasurable f μ) : f =ᵐ[μ] 0 := by let t := hf.sigma_finite_set suffices : f =ᵐ[μ.restrict t] 0 exact ae_of_ae_restrict_of_ae_restrict_compl _ this hf.ae_eq_zero_compl haveI : sigma_finite (μ.restrict t) := hf.sigma_finite_restrict refine' ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite _ _ · intro s hs hμs rw [integrable_on, measure.restrict_restrict hs] rw [measure.restrict_apply hs] at hμs exact hf_int_finite _ (hs.inter hf.measurable_set) hμs · intro s hs hμs rw [measure.restrict_restrict hs] rw [measure.restrict_apply hs] at hμs exact hf_zero _ (hs.inter hf.measurable_set) hμs #align measure_theory.ae_fin_strongly_measurable.ae_eq_zero_of_forall_set_integral_eq_zero MeasureTheory.AeFinStronglyMeasurable.ae_eq_zero_of_forall_set_integral_eq_zero theorem AeFinStronglyMeasurable.ae_eq_of_forall_set_integral_eq {f g : α → E} (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hg_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn g s μ) (hfg_eq : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = ∫ x in s, g x ∂μ) (hf : AeFinStronglyMeasurable f μ) (hg : AeFinStronglyMeasurable g μ) : f =ᵐ[μ] g := by rw [← sub_ae_eq_zero] have hfg : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, (f - g) x ∂μ) = 0 := by intro s hs hμs rw [integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs), sub_eq_zero.mpr (hfg_eq s hs hμs)] have hfg_int : ∀ s, MeasurableSet s → μ s < ∞ → integrable_on (f - g) s μ := fun s hs hμs => (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs) exact (hf.sub hg).ae_eq_zero_of_forall_set_integral_eq_zero hfg_int hfg #align measure_theory.ae_fin_strongly_measurable.ae_eq_of_forall_set_integral_eq MeasureTheory.AeFinStronglyMeasurable.ae_eq_of_forall_set_integral_eq theorem lp.ae_eq_zero_of_forall_set_integral_eq_zero (f : lp E p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = 0) : f =ᵐ[μ] 0 := AeFinStronglyMeasurable.ae_eq_zero_of_forall_set_integral_eq_zero hf_int_finite hf_zero (lp.finStronglyMeasurable _ hp_ne_zero hp_ne_top).AeFinStronglyMeasurable #align measure_theory.Lp.ae_eq_zero_of_forall_set_integral_eq_zero MeasureTheory.lp.ae_eq_zero_of_forall_set_integral_eq_zero theorem lp.ae_eq_of_forall_set_integral_eq (f g : lp E p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) (hf_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn f s μ) (hg_int_finite : ∀ s, MeasurableSet s → μ s < ∞ → IntegrableOn g s μ) (hfg : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = ∫ x in s, g x ∂μ) : f =ᵐ[μ] g := AeFinStronglyMeasurable.ae_eq_of_forall_set_integral_eq hf_int_finite hg_int_finite hfg (lp.finStronglyMeasurable _ hp_ne_zero hp_ne_top).AeFinStronglyMeasurable (lp.finStronglyMeasurable _ hp_ne_zero hp_ne_top).AeFinStronglyMeasurable #align measure_theory.Lp.ae_eq_of_forall_set_integral_eq MeasureTheory.lp.ae_eq_of_forall_set_integral_eq theorem ae_eq_zero_of_forall_set_integral_eq_of_finStronglyMeasurable_trim (hm : m ≤ m0) {f : α → E} (hf_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → IntegrableOn f s μ) (hf_zero : ∀ s : Set α, measurable_set[m] s → μ s < ∞ → (∫ x in s, f x ∂μ) = 0) (hf : FinStronglyMeasurable f (μ.trim hm)) : f =ᵐ[μ] 0 := by obtain ⟨t, ht_meas, htf_zero, htμ⟩ := hf.exists_set_sigma_finite haveI : sigma_finite ((μ.restrict t).trim hm) := by rwa [restrict_trim hm μ ht_meas] at htμ have htf_zero : f =ᵐ[μ.restrict (tᶜ)] 0 := by rw [eventually_eq, ae_restrict_iff' (MeasurableSet.compl (hm _ ht_meas))] exact eventually_of_forall htf_zero have hf_meas_m : strongly_measurable[m] f := hf.strongly_measurable suffices : f =ᵐ[μ.restrict t] 0 exact ae_of_ae_restrict_of_ae_restrict_compl _ this htf_zero refine' measure_eq_zero_of_trim_eq_zero hm _ refine' ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite _ _ · intro s hs hμs rw [integrable_on, restrict_trim hm (μ.restrict t) hs, measure.restrict_restrict (hm s hs)] rw [← restrict_trim hm μ ht_meas, measure.restrict_apply hs, trim_measurable_set_eq hm (hs.inter ht_meas)] at hμs refine' integrable.trim hm _ hf_meas_m exact hf_int_finite _ (hs.inter ht_meas) hμs · intro s hs hμs rw [restrict_trim hm (μ.restrict t) hs, measure.restrict_restrict (hm s hs)] rw [← restrict_trim hm μ ht_meas, measure.restrict_apply hs, trim_measurable_set_eq hm (hs.inter ht_meas)] at hμs rw [← integral_trim hm hf_meas_m] exact hf_zero _ (hs.inter ht_meas) hμs #align measure_theory.ae_eq_zero_of_forall_set_integral_eq_of_fin_strongly_measurable_trim MeasureTheory.ae_eq_zero_of_forall_set_integral_eq_of_finStronglyMeasurable_trim theorem Integrable.ae_eq_zero_of_forall_set_integral_eq_zero {f : α → E} (hf : Integrable f μ) (hf_zero : ∀ s, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = 0) : f =ᵐ[μ] 0 := by have hf_Lp : mem_ℒp f 1 μ := mem_ℒp_one_iff_integrable.mpr hf let f_Lp := hf_Lp.to_Lp f have hf_f_Lp : f =ᵐ[μ] f_Lp := (mem_ℒp.coe_fn_to_Lp hf_Lp).symm refine' hf_f_Lp.trans _ refine' Lp.ae_eq_zero_of_forall_set_integral_eq_zero f_Lp one_ne_zero ENNReal.coe_ne_top _ _ · exact fun s hs hμs => integrable.integrable_on (L1.integrable_coe_fn _) · intro s hs hμs rw [integral_congr_ae (ae_restrict_of_ae hf_f_Lp.symm)] exact hf_zero s hs hμs #align measure_theory.integrable.ae_eq_zero_of_forall_set_integral_eq_zero MeasureTheory.Integrable.ae_eq_zero_of_forall_set_integral_eq_zero theorem Integrable.ae_eq_of_forall_set_integral_eq (f g : α → E) (hf : Integrable f μ) (hg : Integrable g μ) (hfg : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, f x ∂μ) = ∫ x in s, g x ∂μ) : f =ᵐ[μ] g := by rw [← sub_ae_eq_zero] have hfg' : ∀ s : Set α, MeasurableSet s → μ s < ∞ → (∫ x in s, (f - g) x ∂μ) = 0 := by intro s hs hμs rw [integral_sub' hf.integrable_on hg.integrable_on] exact sub_eq_zero.mpr (hfg s hs hμs) exact integrable.ae_eq_zero_of_forall_set_integral_eq_zero (hf.sub hg) hfg' #align measure_theory.integrable.ae_eq_of_forall_set_integral_eq MeasureTheory.Integrable.ae_eq_of_forall_set_integral_eq end AeEqOfForallSetIntegralEq section Lintegral theorem AeMeasurable.ae_eq_of_forall_set_lintegral_eq {f g : α → ℝ≥0∞} (hf : AeMeasurable f μ) (hg : AeMeasurable g μ) (hfi : (∫⁻ x, f x ∂μ) ≠ ∞) (hgi : (∫⁻ x, g x ∂μ) ≠ ∞) (hfg : ∀ ⦃s⦄, MeasurableSet s → μ s < ∞ → (∫⁻ x in s, f x ∂μ) = ∫⁻ x in s, g x ∂μ) : f =ᵐ[μ] g := by refine' ENNReal.eventuallyEq_of_toReal_eventuallyEq (ae_lt_top' hf hfi).ne_of_lt (ae_lt_top' hg hgi).ne_of_lt (integrable.ae_eq_of_forall_set_integral_eq _ _ (integrable_to_real_of_lintegral_ne_top hf hfi) (integrable_to_real_of_lintegral_ne_top hg hgi) fun s hs hs' => _) rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae] · congr 1 rw [lintegral_congr_ae (of_real_to_real_ae_eq _), lintegral_congr_ae (of_real_to_real_ae_eq _)] · exact hfg hs hs' · refine' ae_lt_top' hg.restrict (ne_of_lt (lt_of_le_of_lt _ hgi.lt_top)) exact @set_lintegral_univ α _ μ g ▸ lintegral_mono_set (Set.subset_univ _) · refine' ae_lt_top' hf.restrict (ne_of_lt (lt_of_le_of_lt _ hfi.lt_top)) exact @set_lintegral_univ α _ μ f ▸ lintegral_mono_set (Set.subset_univ _) -- putting the proofs where they are used is extremely slow exacts[ae_of_all _ fun x => ENNReal.toReal_nonneg, hg.ennreal_to_real.restrict.ae_strongly_measurable, ae_of_all _ fun x => ENNReal.toReal_nonneg, hf.ennreal_to_real.restrict.ae_strongly_measurable] #align measure_theory.ae_measurable.ae_eq_of_forall_set_lintegral_eq MeasureTheory.AeMeasurable.ae_eq_of_forall_set_lintegral_eq end Lintegral end MeasureTheory
{-# OPTIONS --safe --warning=error --without-K #-} open import Groups.Definition open import Setoids.Setoids open import Groups.Subgroups.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Groups.Subgroups.Normal.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} (G : Group S _+_) where normalSubgroup : {c : _} {pred : A → Set c} (sub : Subgroup G pred) → Set (a ⊔ c) normalSubgroup {pred = pred} sub = {g k : A} → pred k → pred (g + (k + Group.inverse G g))
/- Copyright (c) 2020 Kevin Lacker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Lacker -/ import data.nat.prime import tactic.ring open nat /-! # IMO 1959 Q1 Prove that the fraction `(21n+4)/(14n+3)` is irreducible for every natural number `n`. Since Lean doesn't have a concept of "irreducible fractions" per se, we just formalize this as saying the numerator and denominator are relatively prime. -/ lemma calculation (n k : ℕ) (h1 : k ∣ 21 * n + 4) (h2 : k ∣ 14 * n + 3) : k ∣ 1 := have h3 : k ∣ 2 * (21 * n + 4), from dvd_mul_of_dvd_right h1 2, have h4 : k ∣ 3 * (14 * n + 3), from dvd_mul_of_dvd_right h2 3, have h5 : 3 * (14 * n + 3) = 2 * (21 * n + 4) + 1, by ring, (nat.dvd_add_right h3).mp (h5 ▸ h4) theorem imo1959_q1 : ∀ n : ℕ, coprime (21 * n + 4) (14 * n + 3) := assume n, coprime_of_dvd' $ λ k hp h1 h2, calculation n k h1 h2
(* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * * SPDX-License-Identifier: BSD-2-Clause *) theory Trace_Schematic_Insts imports Main "ml-helpers/MLUtils" "ml-helpers/TermPatternAntiquote" begin text \<open> See Trace_Schematic_Insts_Test for tests and examples. \<close> locale data_stash begin text \<open> We use this to stash a list of the schematics in the conclusion of the proof state. After running a method, we can read off the schematic instantiations (if any) from this list, then restore the original conclusion. Schematic types are added as "undefined :: ?'a" (for now, we don't worry about types that don't have sort "type"). TODO: there ought to be some standard way of stashing things into the proof state. Find out what that is and refactor \<close> definition container :: "'a \<Rightarrow> bool \<Rightarrow> bool" where "container a b \<equiv> True" lemma proof_state_add: "Pure.prop PROP P \<equiv> PROP Pure.prop (container True xs \<Longrightarrow> PROP P)" by (simp add: container_def) lemma proof_state_remove: "PROP Pure.prop (container True xs \<Longrightarrow> PROP P) \<equiv> Pure.prop (PROP P)" by (simp add: container_def) lemma rule_add: "PROP P \<equiv> (container True xs \<Longrightarrow> PROP P)" by (simp add: container_def) lemma rule_remove: "(container True xs \<Longrightarrow> PROP P) \<equiv> PROP P" by (simp add: container_def) lemma elim: "container a b" by (simp add: container_def) ML \<open> signature TRACE_SCHEMATIC_INSTS = sig type instantiations = { bounds: (string * typ) list, terms: (term * term) list, typs: (typ * typ) list } val empty_instantiations: instantiations val trace_schematic_insts: Method.method -> (instantiations -> unit) -> Method.method val default_report: Proof.context -> string -> instantiations -> unit val trace_schematic_insts_tac: Proof.context -> (instantiations -> instantiations -> unit) -> (thm -> int -> tactic) -> thm -> int -> tactic val default_rule_report: Proof.context -> string -> instantiations -> instantiations -> unit val skip_dummy_state: Method.method -> Method.method val make_term_container: term list -> term val dest_term_container: term -> term list val attach_proof_annotations: Proof.context -> term list -> thm -> thm val detach_proof_annotations: thm -> term list * thm val attach_rule_annotations: Proof.context -> term list -> thm -> thm val detach_rule_result_annotations: Proof.context -> thm -> ((string * typ) list * term list) * thm val instantiate_thm: Proof.context -> thm -> instantiations -> term end structure Trace_Schematic_Insts: TRACE_SCHEMATIC_INSTS = struct \<comment>\<open> Each pair in the terms and typs fields are a (schematic, instantiation) pair. The bounds field records the binders which are due to subgoal bounds. An explanation: if we instantiate some schematic `?P` within a subgoal like @{term "\<And>x y. Q"}, it might be instantiated to @{term "\<lambda>a. R a x"}. We need to capture `x` when reporting the instantiation, so we report that `?P` has been instantiated to @{term "\<lambda>x y a. R a x"}. In order to distinguish between the bound `x`, `y`, and `a`, we record the bound variables from the subgoal so that we can handle them as necessary. As an example, let us consider the case where the subgoal is @{term "\<And>x::int. foo (\<lambda>a. a::'e) (\<lambda>a. a + x) (0::nat)"} and the rule being applied is @{term "foo ((f::'d \<Rightarrow> 'a \<Rightarrow> 'a) y) (g::'b \<Rightarrow> 'b) (0::'c::zero)"}. This results in the instantiations {bounds: [("x", int)], terms: [(?f, \<lambda>x a b. b), (?g, \<lambda>x a. x + a), (?y, \<lambda>x. ?y x)], typs: [(?'a, 'e), (?'b, int), (?'c, nat)]}. \<close> type instantiations = { bounds: (string * typ) list, terms: (term * term) list, typs: (typ * typ) list } val empty_instantiations = {bounds = [], terms = [], typs = []} \<comment>\<open> Work around Isabelle running every apply method on a dummy proof state \<close> fun skip_dummy_state method = fn facts => fn (ctxt, st) => case Thm.prop_of st of Const (@{const_name Pure.prop}, _) $ (Const (@{const_name Pure.term}, _) $ Const (@{const_name Pure.dummy_pattern}, _)) => Seq.succeed (Seq.Result (ctxt, st)) | _ => method facts (ctxt, st); \<comment>\<open> Utils \<close> fun rewrite_state_concl eqn st = Conv.fconv_rule (Conv.concl_conv (Thm.nprems_of st) (K eqn)) st \<comment>\<open> Strip the @{term Pure.prop} that wraps proof state conclusions \<close> fun strip_prop ct = case Thm.term_of ct of Const (@{const_name "Pure.prop"}, @{typ "prop \<Rightarrow> prop"}) $ _ => Thm.dest_arg ct | _ => raise CTERM ("strip_prop: head is not Pure.prop", [ct]) fun cconcl_of st = funpow (Thm.nprems_of st) Thm.dest_arg (Thm.cprop_of st) |> strip_prop fun vars_of_term t = Term.add_vars t [] |> sort_distinct Term_Ord.var_ord fun type_vars_of_term t = Term.add_tvars t [] |> sort_distinct Term_Ord.tvar_ord \<comment>\<open> Create annotation list \<close> fun make_term_container ts = fold (fn t => fn container => Const (@{const_name container}, fastype_of t --> @{typ "bool \<Rightarrow> bool"}) $ t $ container) (rev ts) @{term "True"} \<comment>\<open> Retrieve annotation list \<close> fun dest_term_container (Const (@{const_name container}, _) $ x $ list) = x :: dest_term_container list | dest_term_container _ = [] \<comment>\<open> Attach some terms to a proof state, by "hiding" them in the protected goal. \<close> fun attach_proof_annotations ctxt terms st = let val container = make_term_container terms (* FIXME: this might affect st's maxidx *) val add_eqn = Thm.instantiate ([], [((("P", 0), @{typ prop}), cconcl_of st), ((("xs", 0), @{typ bool}), Thm.cterm_of ctxt container)]) @{thm proof_state_add} in rewrite_state_concl add_eqn st end \<comment>\<open> Retrieve attached terms from a proof state \<close> fun detach_proof_annotations st = let val st_concl = cconcl_of st val (ccontainer', real_concl) = Thm.dest_implies st_concl val ccontainer = ccontainer' |> Thm.dest_arg (* strip Trueprop *) |> Thm.dest_arg \<comment>\<open>strip outer @{term "container True"}\<close> val terms = ccontainer |> Thm.term_of |> dest_term_container val remove_eqn = Thm.instantiate ([], [((("P", 0), @{typ prop}), real_concl), ((("xs", 0), @{typ bool}), ccontainer)]) @{thm proof_state_remove} in (terms, rewrite_state_concl remove_eqn st) end \<comment> \<open> Attaches the given terms to the given thm by stashing them as a new @{term "container"} premise, *after* all the existing premises (this minimises disruption when the rule is used with things like `erule`). \<close> fun attach_rule_annotations ctxt terms thm = let val container = make_term_container terms (* FIXME: this might affect thm's maxidx *) val add_eqn = Thm.instantiate ([], [((("P", 0), @{typ prop}), Thm.cconcl_of thm), ((("xs", 0), @{typ bool}), Thm.cterm_of ctxt container)]) @{thm rule_add} in rewrite_state_concl add_eqn thm end \<comment> \<open> Finds all the variables and type variables in the given thm, then uses `attach` to stash them in a @{const "container"} within the thm. Returns a tuple containing the variables and type variables which were attached this way. \<close> fun annotate_with_vars_using (attach: Proof.context -> term list -> thm -> thm) ctxt thm = let val tvars = type_vars_of_term (Thm.prop_of thm) |> map TVar val tvar_carriers = map (fn tvar => Const (@{const_name undefined}, tvar)) tvars val vars = vars_of_term (Thm.prop_of thm) |> map Var val annotated_rule = attach ctxt (vars @ tvar_carriers) thm in ((vars, tvars), annotated_rule) end val annotate_rule = annotate_with_vars_using attach_rule_annotations val annotate_proof_state = annotate_with_vars_using attach_proof_annotations fun split_and_zip_instantiations (vars, tvars) (bounds, insts): instantiations = let val (var_insts, tvar_insts) = chop (length vars) insts val tvar_insts' = map (TermExtras.drop_binders (length bounds) o fastype_of) tvar_insts in { bounds = bounds, terms = vars ~~ var_insts, typs = tvars ~~ tvar_insts' } end \<comment>\<open> Matches subgoals of the form: @{term "\<And>A B C. X \<Longrightarrow> Y \<Longrightarrow> Z \<Longrightarrow> container True data"} Extracts the instantiation variables from `?data`, and re-applies the surrounding meta abstractions (in this case `\<And>A B C`). \<close> fun dest_instantiation_container_subgoal t = let val (vars, goal) = t |> TermExtras.strip_all val goal = goal |> Logic.strip_imp_concl in case goal of @{term_pat "Trueprop (container True ?data)"} => dest_term_container data |> map (fn t => Logic.rlist_abs (rev vars, t)) (* reapply variables *) |> pair vars |> SOME | _ => NONE end \<comment>\<open> Finds the first subgoal with a @{term container} conclusion. Extracts the data from the container and removes the subgoal. \<close> fun detach_rule_result_annotations ctxt st = let val (idx, data) = st |> Thm.prems_of |> Library.get_index dest_instantiation_container_subgoal |> OptionExtras.get_or_else (fn () => error "No container subgoal!") val st' = st |> resolve_tac ctxt @{thms elim} (idx + 1) |> Seq.hd in (data, st') end \<comment> \<open> Instantiate subterms of a given term, using the supplied var_insts. A complication is that to deal with bound variables, lambda terms might have been inserted to the instantiations. To handle this, we first generate some fresh free variables, apply them to the lambdas, do the substitution, re-abstract the frees, and then clean up any inner applications. subgoal: @{term "\<And>x::int. foo (\<lambda>a. a::'e) (\<lambda>a. a + x) (0::nat)"}, rule: @{term "foo ((f::'d \<Rightarrow> 'a \<Rightarrow> 'a) y) (g::'b \<Rightarrow> 'b) (0::'c::zero)"}, and instantiations: {bounds: [("x", int)], terms: [(?f, \<lambda>x a b. b), (?g, \<lambda>x a. x + a), (?y, \<lambda>x. ?y x)], typs: [(?'a, 'e), (?'b, int), (?'c, nat)]}, this leads to vars: [("x", int)], var_insts: [(?f, \<lambda>a b. b), (?g, \<lambda>a. x + a), (?y, ?y x)] subst_free: "foo ((\<lambda>a b. b) (?y x)) (\<lambda>a. a + x) 0" absfree: "\<lambda>x. foo ((\<lambda>a b. b) (?y x)) (\<lambda>a. a + x) 0" beta_norm: @{term "\<lambda>x. foo (\<lambda>a. a) (\<lambda>a. a + x) 0"} abs_all: @{term "\<And>x. foo (\<lambda>a. a) (\<lambda>a. a + x) 0"} \<close> fun instantiate_terms ctxt bounds var_insts term = let val vars = Variable.variant_frees ctxt (term :: map #2 var_insts) bounds fun var_inst_beta term term' = (term, Term.betapplys (term', map Free vars)) val var_insts' = map (uncurry var_inst_beta) var_insts in term |> Term.subst_free var_insts' |> fold Term.absfree vars |> Envir.beta_norm |> TermExtras.abs_all (length bounds) end \<comment> \<open> Instantiate subtypes of a given term, using the supplied tvar_insts. Similarly to above, to deal with bound variables we first need to drop any binders that had been added to the instantiations. \<close> fun instantiate_types ctxt bounds_num tvar_insts term = let fun instantiateT tvar_inst typ = let val tyenv = Sign.typ_match (Proof_Context.theory_of ctxt) tvar_inst Vartab.empty val S = Vartab.dest tyenv val S' = map (fn (s,(t,u)) => ((s,t),u)) S in Term_Subst.instantiateT S' typ end in fold (fn typs => Term.map_types (instantiateT typs)) tvar_insts term end \<comment> \<open> Instantiate a given thm with the supplied instantiations, returning a term. \<close> fun instantiate_thm ctxt thm {bounds, terms as var_insts, typs as tvar_insts} = Thm.prop_of thm |> instantiate_terms ctxt bounds var_insts |> instantiate_types ctxt (length bounds) tvar_insts fun filtered_instantiation_lines ctxt {bounds, terms, typs} = let val vars_lines = map (fn (var, inst) => if var = inst then "" (* don't show unchanged *) else " " ^ Syntax.string_of_term ctxt var ^ " => " ^ Syntax.string_of_term ctxt (TermExtras.abs_all (length bounds) inst) ^ "\n") terms val tvars_lines = map (fn (tvar, inst) => if tvar = inst then "" (* don't show unchanged *) else " " ^ Syntax.string_of_typ ctxt tvar ^ " => " ^ Syntax.string_of_typ ctxt inst ^ "\n") typs in vars_lines @ tvars_lines end \<comment>\<open> Default callback for black-box method tracing. Prints nontrivial instantiations to tracing output with the given title line. \<close> fun default_report ctxt title insts = let val all_insts = String.concat (filtered_instantiation_lines ctxt insts) (* TODO: add a quiet flag, to suppress output when nothing was instantiated *) in title ^ "\n" ^ (if all_insts = "" then " (no instantiations)\n" else all_insts) |> tracing end \<comment> \<open> Default callback for tracing rule applications. Prints nontrivial instantiations to tracing output with the given title line. Separates instantiations of rule variables and goal variables. \<close> fun default_rule_report ctxt title rule_insts proof_insts = let val rule_lines = String.concat (filtered_instantiation_lines ctxt rule_insts) val rule_lines = if rule_lines = "" then "(no rule instantiations)\n" else "rule instantiations:\n" ^ rule_lines; val proof_lines = String.concat (filtered_instantiation_lines ctxt proof_insts) val proof_lines = if proof_lines = "" then "(no goal instantiations)\n" else "goal instantiations:\n" ^ proof_lines; in title ^ "\n" ^ rule_lines ^ "\n" ^ proof_lines |> tracing end \<comment> \<open> `trace_schematic_insts_tac ctxt callback tactic thm idx` does the following: - Produce a @{term container}-annotated version of `thm`. - Runs `tactic` on subgoal `idx`, using the annotated version of `thm`. - If the tactic succeeds, call `callback` with the rule instantiations and the goal instantiations, in that order. \<close> fun trace_schematic_insts_tac ctxt (callback: instantiations -> instantiations -> unit) (tactic: thm -> int -> tactic) thm idx st = let val (rule_vars, annotated_rule) = annotate_rule ctxt thm val (proof_vars, annotated_proof_state) = annotate_proof_state ctxt st val st = tactic annotated_rule idx annotated_proof_state in st |> Seq.map (fn st => let val (rule_terms, st) = detach_rule_result_annotations ctxt st val (proof_terms, st) = detach_proof_annotations st val rule_insts = split_and_zip_instantiations rule_vars rule_terms val proof_insts = split_and_zip_instantiations proof_vars ([], proof_terms) val () = callback rule_insts proof_insts in st end ) end \<comment>\<open> ML interface, calls the supplied function with schematic unifications (will be given all variables, including those that haven't been instantiated). \<close> fun trace_schematic_insts (method: Method.method) callback = fn facts => fn (ctxt, st) => let val (vars, annotated_st) = annotate_proof_state ctxt st in (* Run the method *) method facts (ctxt, annotated_st) |> Seq.map_result (fn (ctxt', annotated_st') => let (* Retrieve the stashed list, now with unifications *) val (annotations, st') = detach_proof_annotations annotated_st' val insts = split_and_zip_instantiations vars ([], annotations) (* Report the list *) val _ = callback insts in (ctxt', st') end) end end \<close> end method_setup trace_schematic_insts = \<open> let open Trace_Schematic_Insts in (Scan.option (Scan.lift Parse.liberal_name) -- Method.text_closure) >> (fn (maybe_title, method_text) => fn ctxt => trace_schematic_insts (Method.evaluate method_text ctxt) (default_report ctxt (Option.getOpt (maybe_title, "trace_schematic_insts:"))) |> skip_dummy_state ) end \<close> "Method combinator to trace schematic variable and type instantiations" end
(* Copyright 2014 Cornell University This file is part of VPrl (the Verified Nuprl project). VPrl 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. VPrl 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 VPrl. If not, see <http://www.gnu.org/licenses/>. Website: http://nuprl.org/html/verification/ Authors: Abhishek Anand & Vincent Rahli *) Require Export type_sys. Require Import dest_close. Lemma cequivc_eqindomain {p} : forall lib, forall(a b : @CTerm p), forall (eqa: per), term_equality_symmetric eqa -> term_equality_transitive eqa -> term_equality_respecting lib eqa -> cequivc lib a b -> eqindomain eqa a b. Proof. intros. unfold eqindomain. unfold term_equality_symmetric in H. unfold term_equality_transitive in H0. unfold term_equality_respecting in H1. split; try split; intro. assert (eqa a b). apply H1; auto. sp. spcast. auto. assert (eqa b a). apply H; auto. eapply H0; eauto. assert (eqa b a). apply H1; auto. sp. spcast. apply cequivc_sym. auto. assert (eqa a b). apply H; auto. eapply H0; eauto. apply H1; auto. sp. spcast. auto. Qed. Lemma eqindomain_sym {p} : forall(a b : @CTerm p), forall (eqa: per), term_equality_symmetric eqa -> eqindomain eqa a b -> eqindomain eqa b a. Proof. intros. unfold eqindomain. unfold term_equality_symmetric in H. split; try split; intro. apply H0; auto. apply H0; auto. assert (eqa a b). apply H0; auto. apply H0; auto. apply H. auto. Qed. Lemma eqindomain_trans {p} : forall(a b c: @CTerm p), forall (eqa: per), term_equality_transitive eqa -> eqindomain eqa a b -> eqindomain eqa b c -> eqindomain eqa a c. Proof. unfold eqindomain. intros. unfold term_equality_symmetric in H. sp. rw H3; auto. assert (eqa b c). apply H1; rw <- H4; auto. eapply H; eauto. Qed. Lemma eqindomain_combine {p} : forall(a1 a2 b1 b2 : @CTerm p), forall (eqa: per), term_equality_symmetric eqa -> term_equality_transitive eqa -> eqindomain eqa a1 b1 -> eqindomain eqa a2 b2 -> eqa a1 a2 -> eqa b1 b2. Proof. intros. unfold eqindomain. unfold term_equality_symmetric in H. unfold term_equality_transitive in H0. assert (eqa a1 b1). apply H1. eapply H0; eauto. assert (eqa a2 b2). apply H2. eapply H0; eauto. eapply H0; eauto. Qed. Lemma eq_term_equals_eqindomain {p} : forall (eq1 eq2: per), eq1 <=2=> eq2 -> forall(a b : @CTerm p), eqindomain eq1 a b <=> eqindomain eq2 a b. Proof. intros. unfold eqindomain. repeat (rw H). sp. Qed. Lemma close_type_system_eq {p} : forall lib (ts : cts(p)), forall T T' (eq : per) A B a1 a2 b1 b2 eqa, type_system lib ts -> defines_only_universes lib ts -> computes_to_valc lib T (mkc_equality a1 a2 A) -> computes_to_valc lib T' (mkc_equality b1 b2 B) -> close lib ts A B eqa -> eqindomain eqa a1 b1 -> eqindomain eqa a2 b2 -> (forall t t' : CTerm, eq t t' <=> ccomputes_to_valc lib t mkc_axiom # ccomputes_to_valc lib t' mkc_axiom # eqa a1 a2) -> per_eq lib (close lib ts) T T' eq -> type_sys_props lib (close lib ts) A B eqa -> type_sys_props lib (close lib ts) T T' eq. Proof. introv X X0 c1 c2 X1 eos1 eos2 eqiff per IHX1. rw @type_sys_props_iff_type_sys_props3. prove_type_sys_props3 SCase; intros. + SCase "uniquely_valued". dclose_lr. * SSCase "CL_eq". clear per. allunfold @per_eq; sp. unfold eq_term_equals; sp. spcast; allrw. ccomputes_to_eqval. unfold type_sys_props in IHX1; sp. implies_ts_or_eq A B0 B h. apply IHX0 in h. unfold eq_term_equals in h. rw h; split; sp. + SCase "type_symmetric"; repdors; subst; dclose_lr; allunfold @per_eq; exrepd; ccomputes_to_eqval; apply CL_eq; unfold per_eq. (* 1 *) exists A B0 a1 a2 b0 b3 eqa0; sp; spcast; sp. allrw <-; sp. + SCase "type_value_respecting"; repdors; subst; apply CL_eq; allunfold @per_eq; sp; ccomputes_to_eqval. duplicate c1 as c0. apply cequivc_mkc_equality with (t' := T3) in c0; sp. exists A T'0 a1 a2 a' b' eqa; sp; spcast; sp; try (complete (right; spcast; sp)). allunfold @type_sys_props; sp. pose proof (cequivc_eqindomain lib a1 a' eqa). apply H0; auto; apply IHX1. pose proof (cequivc_eqindomain lib a2 b' eqa). apply H0; auto; apply IHX1. duplicate c2 as c0. apply cequivc_mkc_equality with (t' := T3) in c0; sp. exists B T'0 b1 b2 a' b' eqa; sp; spcast; sp; try (complete (right; spcast; sp)). allunfold @type_sys_props; sp. pose proof (cequivc_eqindomain lib b1 a' eqa). apply H0; auto; apply IHX1. pose proof (cequivc_eqindomain lib b2 b' eqa). apply H0; auto; apply IHX1. onedtsp uv tys tyt tyst tyvr tes tet tevr tygs tygt dum. rw eqiff; split; sp. eapply eqindomain_combine; eauto. pose proof (eqindomain_combine b1 b2 a1 a2 eqa) as xx; apply xx; auto; apply eqindomain_sym; auto. + SCase "term_symmetric". unfold term_equality_symmetric; sp. allrw; discover; sp. + SCase "term_transitive". unfold term_equality_transitive; sp. allrw; discover; sp. + SCase "term_value_respecting". unfold term_equality_respecting; sp. allrw; discover; sp; spcast. apply @cequivc_axiom with (t := t); sp. + SCase "type_gsymmetric". repdors; subst; split; sp; dclose_lr; apply CL_eq; clear per; allunfold @per_eq; exrepd; ccomputes_to_eqval; unfold per_eq; onedtsp uv tys tyt tyst tyvr tes tet tevr tygs tygt dum; try (assert (close lib ts A A0 eqa0) as k by (generalize (tygs A A0 eqa0); intro i; autodimp i h; rw <- i in c3; sp)); try (assert (close lib ts B A0 eqa0) as k by (generalize (tygs B A0 eqa0); intro i; autodimp i h; rw <- i in c3; sp)); try (assert (eq_term_equals eqa eqa0) as eqt by (apply uv with (T3 := A0); sp)); try (assert (eq_term_equals eqa eqa0) as eqt by (apply uv with (T3 := B0); sp)). (* 1 *) exists B0 A b0 b3 a1 a2 eqa0. assert (term_equality_symmetric eqa0). unfold term_equality_symmetric; intros; rw <- eqt; apply tes; rw eqt; auto. assert (forall a b : CTerm, eqindomain eqa a b <=> eqindomain eqa0 a b) as sameeq. apply eq_term_equals_eqindomain; auto. sp; spcast; sp. generalize (tygs A B0 eqa0); intro i; autodimp i h; rw <- i; sp. apply eqindomain_sym; auto. apply eqindomain_sym; auto. rw t; repeat (rw <- eqt). split; sp. pose proof (eqindomain_combine a1 a2 b0 b3 eqa) as xx; apply xx; auto; rw sameeq; auto. pose proof (eqindomain_combine b0 b3 a1 a2 eqa) as xx; apply xx; auto; apply eqindomain_sym; auto; rw sameeq; auto. (* 2 *) exists A A0 a1 a2 a0 a3 eqa0. assert (term_equality_symmetric eqa0). unfold term_equality_symmetric; intros; rw <- eqt; apply tes; rw eqt; auto. assert (forall a b : CTerm, eqindomain eqa a b <=> eqindomain eqa0 a b) as sameeq. apply eq_term_equals_eqindomain; auto. sp; spcast; sp. apply eqindomain_sym; auto. apply eqindomain_sym; auto. rw t; repeat (rw <- eqt). split; sp. pose proof (eqindomain_combine a0 a3 a1 a2 eqa) as xx; apply xx; auto; rw sameeq; auto. pose proof (eqindomain_combine a1 a2 a0 a3 eqa) as xx; apply xx; auto; apply eqindomain_sym; auto; rw sameeq; auto. + SCase "type_gtransitive"; sp. + SCase "type_mtransitive". repdors; subst; dclose_lr; try (move_term_to_top (per_eq lib (close lib ts) T T4 eq2)); try (move_term_to_top (per_eq lib (close lib ts) T' T4 eq2)); clear per; allunfold @per_eq; exrepd; ccomputes_to_eqval; applydup @type_sys_props_ts_refl in IHX1; repnd; onedtsp uv tys tyt tyst tyvr tes tet tevr tygs tygt tymt. (* 1 *) assert (close lib ts A A1 eqa1) as eqta1 by (generalize (tymt A A1 A eqa1 eqa); sp). assert (eq_term_equals eqa eqa1) as eqt1 by (apply uv with (T3 := A1); sp). assert (eq_term_equals eqa eqa0) as eqt2 by (apply uv with (T3 := B0); sp). assert (close lib ts A1 B0 eqa0) as eqta2 by (generalize (tymt A A1 B0 eqa1 eqa0); sp). assert (forall a b : CTerm, eqindomain eqa a b <=> eqindomain eqa0 a b) as sameeq1. apply eq_term_equals_eqindomain; auto. assert (forall a b : CTerm, eqindomain eqa a b <=> eqindomain eqa1 a b) as sameeq2. apply eq_term_equals_eqindomain; auto. dands; apply CL_eq; unfold per_eq. exists A1 B0 a4 a5 b0 b3 eqa0. allrw <- sameeq1. allrw <- sameeq2. sp; spcast; sp. eapply eqindomain_trans; eauto. eapply eqindomain_trans; eauto. rw t0. allrw <-; sp. exists A1 B0 a4 a5 b0 b3 eqa0. allrw <- sameeq1. allrw <- sameeq2. sp; spcast; sp. eapply eqindomain_trans; eauto. eapply eqindomain_trans; eauto. rw t. allrw <-; sp. rw eqiff; split; intros; sp. pose proof (eqindomain_combine a1 a2 a4 a5 eqa) as xx; apply xx; auto; apply eqindomain_sym; auto. pose proof (eqindomain_combine a4 a5 a1 a2 eqa) as xx; apply xx; auto. (* 2 *) assert (close lib ts B A1 eqa1) as eqta1 by (generalize (tymt B A1 B eqa1 eqa); sp). assert (eq_term_equals eqa eqa1) as eqt1 by (apply uv with (T3 := A1); sp). assert (eq_term_equals eqa eqa0) as eqt2 by (apply uv with (T3 := B0); sp). assert (close lib ts A1 B0 eqa1) as cl by (generalize (tymt B A1 B0 eqa1 eqa0); intro i; autodimp i h; sp). assert (forall a b : CTerm, eqindomain eqa a b <=> eqindomain eqa0 a b) as sameeq1. apply eq_term_equals_eqindomain; auto. assert (forall a b : CTerm, eqindomain eqa a b <=> eqindomain eqa1 a b) as sameeq2. apply eq_term_equals_eqindomain; auto. dands; apply CL_eq; unfold per_eq. exists A1 B0 a4 a5 b0 b3 eqa1. allrw <- sameeq1. allrw <- sameeq2. sp; spcast; sp. eapply eqindomain_trans; eauto. eapply eqindomain_trans; eauto. exists A1 B0 a4 a5 b0 b3 eqa1. allrw <- sameeq1. allrw <- sameeq2. sp; spcast; sp. eapply eqindomain_trans; eauto. eapply eqindomain_trans; eauto. rw t; repeat (rw <- eqt1); repeat (rw <- eqt2); split; sp. pose proof (eqindomain_combine b1 b2 a4 a5 eqa) as xx; apply xx; auto; apply eqindomain_sym; auto. pose proof (eqindomain_combine a4 a5 b1 b2 eqa) as xx; apply xx; auto. Qed.
import Data.Complex (cis, phase) meanAngle :: RealFloat c => [c] -> c meanAngle = (/ pi) . (* 180) . phase . sum . map (cis . (/ 180) . (* pi)) main :: IO () main = mapM_ (\angles -> putStrLn $ "The mean angle of " ++ show angles ++ " is: " ++ show (meanAngle angles) ++ " degrees") [[350, 10], [90, 180, 270, 360], [10, 20, 30]]
import category_theory.category import category_theory.functor import category_theory.types import help_functions import tactic.tidy universes v u namespace Sum open category_theory set classical function help_functions sum local notation f ` ⊚ `:80 g:80 := category_struct.comp g f /- Sum -/ /-- predicate to determine if S along with e₁ and e₂ is a Sum in category theory definition -/ def is_sum {X : Type v} [category X] {A B : X} (S: X) (e₁ : A ⟶ S) (e₂ : B ⟶ S) :Prop := Π (Q : X) (q₁ : A ⟶ Q) (q₂ : B ⟶ Q), ∃! s : S ⟶ Q, q₁ = s ⊚ e₁ ∧ q₂ = s ⊚ e₂ lemma jointly_epi_cat {X : Type v} [category X] {A B S Q : X} (e₁ : A ⟶ S) (e₂ : B ⟶ S) (is_sm : is_sum S e₁ e₂) (f g: S ⟶ Q) (h1 : f ⊚ e₁ = g ⊚ e₁) (h2 : f ⊚ e₂ = g ⊚ e₂) : f = g := begin have ex : _ := is_sm Q (f ⊚ e₁) (f ⊚ e₂), cases ex with s spec_s, have g_s : g = s := spec_s.2 g ⟨h1, h2⟩, rw g_s, exact spec_s.2 f ⟨rfl, rfl⟩ end lemma jointly_epi {A B Q : Type u} (s s₁: (A ⊕ B) → Q) (h1 : s₁ ∘ inl = s ∘ inl) (h2 : s₁ ∘ inr = s ∘ inr) : s₁ = s := begin have all_ab : ∀ ab : (A ⊕ B) , s₁ ab = s ab := begin intro ab, induction ab, case inl : { have s0 : (s₁ ∘ inl) ab = (s ∘ inl) ab := by rw h1, exact s0 }, case inr : begin have s0 : (s₁ ∘ inr) ab = (s ∘ inr) ab := by rw h2, exact s0 end, end, exact funext all_ab end variables {A B C: Type u} /-- A proof that the disjoint union, which is defined inductively (inl : A → sum, inr : B → sum) in lean is a sum in the category theory definition. -/ lemma disjoint_union_is_sum : is_sum (A ⊕ B) inl inr := begin intros Q q₁ q₂, -- competitor with 2 morphisms show ∃! s : (A ⊕ B) ⟶ Q, (q₁ = s ∘ inl ∧ q₂ = s ∘ inr) , from let s : (A ⊕ B) ⟶ Q := --defining the unique morphism s : sum → Q inductively begin intro ab, induction ab, case inl : begin exact q₁ ab end, case inr : begin exact q₂ ab end, end in have commut_A : q₁ = s ∘ inl := rfl, have commut_B : q₂ = s ∘ inr := rfl, have unique : ∀ s₁ , (q₁ = s₁ ∘ inl ∧ q₂ = s₁ ∘ inr) → s₁ = s := assume s₁ h₁, jointly_epi s s₁ (by rw [← h₁.1 ,commut_A ]) (by rw [← h₁.2 ,commut_B ]), exists_unique.intro s ⟨commut_A , commut_B⟩ unique end end Sum
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import analysis.calculus.iterated_deriv import analysis.calculus.mean_value import data.polynomial.basic import data.polynomial.module /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylor_coeff_within`: the Taylor coefficient using `deriv_within` * `taylor_within`: the Taylor polynomial using `deriv_within` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open_locale big_operators interval topology nat open set variables {𝕜 E F : Type*} variables [normed_add_comm_group E] [normed_space ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylor_coeff_within (f : ℝ → E) (k : ℕ) (s : set ℝ) (x₀ : ℝ) : E := (k! : ℝ)⁻¹ • (iterated_deriv_within k f s x₀) /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylor_within (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ : ℝ) : polynomial_module ℝ E := (finset.range (n+1)).sum (λ k, polynomial_module.comp (polynomial.X - polynomial.C x₀) (polynomial_module.single ℝ k (taylor_coeff_within f k s x₀))) /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylor_within_eval (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ x : ℝ) : E := polynomial_module.eval x (taylor_within f n s x₀) lemma taylor_within_succ (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ : ℝ) : taylor_within f (n+1) s x₀ = taylor_within f n s x₀ + polynomial_module.comp (polynomial.X - polynomial.C x₀) (polynomial_module.single ℝ (n+1) (taylor_coeff_within f (n+1) s x₀)) := begin dunfold taylor_within, rw finset.sum_range_succ, end @[simp] lemma taylor_within_eval_succ (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ x : ℝ) : taylor_within_eval f (n+1) s x₀ x = taylor_within_eval f n s x₀ x + (((n + 1 : ℝ) * n!)⁻¹ * (x - x₀)^(n+1)) • iterated_deriv_within (n + 1) f s x₀ := begin simp_rw [taylor_within_eval, taylor_within_succ, linear_map.map_add, polynomial_module.comp_eval], congr, simp only [polynomial.eval_sub, polynomial.eval_X, polynomial.eval_C, polynomial_module.eval_single, mul_inv_rev], dunfold taylor_coeff_within, rw [←mul_smul, mul_comm, nat.factorial_succ, nat.cast_mul, nat.cast_add, nat.cast_one, mul_inv_rev], end /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] lemma taylor_within_zero_eval (f : ℝ → E) (s : set ℝ) (x₀ x : ℝ) : taylor_within_eval f 0 s x₀ x = f x₀ := begin dunfold taylor_within_eval, dunfold taylor_within, dunfold taylor_coeff_within, simp, end /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] lemma taylor_within_eval_self (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ : ℝ) : taylor_within_eval f n s x₀ x₀ = f x₀ := begin induction n with k hk, { exact taylor_within_zero_eval _ _ _ _}, simp [hk] end lemma taylor_within_apply (f : ℝ → E) (n : ℕ) (s : set ℝ) (x₀ x : ℝ) : taylor_within_eval f n s x₀ x = ∑ k in finset.range (n+1), ((k! : ℝ)⁻¹ * (x - x₀)^k) • iterated_deriv_within k f s x₀ := begin induction n with k hk, { simp }, rw [taylor_within_eval_succ, finset.sum_range_succ, hk], simp, end /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylor_within_eval f n s x₀ x` is continuous in `x₀`. -/ lemma continuous_on_taylor_within_eval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : set ℝ} (hs : unique_diff_on ℝ s) (hf : cont_diff_on ℝ n f s) : continuous_on (λ t, taylor_within_eval f n s t x) s := begin simp_rw taylor_within_apply, refine continuous_on_finset_sum (finset.range (n+1)) (λ i hi, _), refine (continuous_on_const.mul ((continuous_on_const.sub continuous_on_id).pow _)).smul _, rw cont_diff_on_iff_continuous_on_differentiable_on_deriv hs at hf, cases hf, specialize hf_left i, simp only [finset.mem_range] at hi, refine (hf_left _), simp only [with_top.coe_le_coe], exact nat.lt_succ_iff.mp hi, end /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ lemma monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : has_deriv_at (λ y, (x - y)^(n+1)) (-(n+1) * (x - t)^n) t := begin simp_rw sub_eq_neg_add, rw [←neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ←mul_assoc], convert @has_deriv_at.pow _ _ _ _ _ (n+1) ((has_deriv_at_id t).neg.add_const x), simp only [nat.cast_add, nat.cast_one], end lemma has_deriv_within_at_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s s' : set ℝ} (hs'_unique : unique_diff_within_at ℝ s' y) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf' : differentiable_on ℝ (iterated_deriv_within (k+1) f s) s') : has_deriv_within_at (λ t, (((k+1 : ℝ) * k!)⁻¹ * (x - t)^(k+1)) • iterated_deriv_within (k+1) f s t) ((((k+1 : ℝ) * k!)⁻¹ * (x - y)^(k+1)) • iterated_deriv_within (k+2) f s y - ((k! : ℝ)⁻¹ * (x - y)^k) • iterated_deriv_within (k+1) f s y) s' y := begin have hf'' : has_deriv_within_at (λ t, iterated_deriv_within (k+1) f s t) (iterated_deriv_within (k+2) f s y) s' y := begin convert (hf' y hy).has_deriv_within_at, rw iterated_deriv_within_succ (hs'_unique.mono h), refine (deriv_within_subset h hs'_unique _).symm, exact (hf' y hy).antimono h hs', end, have : has_deriv_within_at (λ t, (((k+1 : ℝ) * k!)⁻¹ * (x - t)^(k+1))) (-((k! : ℝ)⁻¹ * (x - y)^k)) s' y := begin -- Commuting the factors: have : (-((k! : ℝ)⁻¹ * (x - y)^k)) = (((k+1 : ℝ) * k!)⁻¹ * (-(k+1) *(x - y)^k)) := by { field_simp [nat.cast_add_one_ne_zero k, nat.factorial_ne_zero k], ring_nf }, rw this, exact (monomial_has_deriv_aux y x _).has_deriv_within_at.const_mul _, end, convert this.smul hf'', field_simp [nat.cast_add_one_ne_zero k, nat.factorial_ne_zero k], rw [neg_div, neg_smul, sub_eq_add_neg], end /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ lemma has_deriv_within_at_taylor_within_eval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : set ℝ} (hs'_unique : unique_diff_within_at ℝ s' y) (hs_unique : unique_diff_on ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : cont_diff_on ℝ n f s) (hf' : differentiable_on ℝ (iterated_deriv_within n f s) s') : has_deriv_within_at (λ t, taylor_within_eval f n s t x) (((n! : ℝ)⁻¹ * (x - y)^n) • (iterated_deriv_within (n+1) f s y)) s' y := begin induction n with k hk, { simp only [taylor_within_zero_eval, nat.factorial_zero, nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul], simp only [iterated_deriv_within_zero] at hf', rw iterated_deriv_within_one hs_unique (h hy), refine has_deriv_within_at.mono _ h, refine differentiable_within_at.has_deriv_within_at _, exact (hf' y hy).antimono h hs' }, simp_rw [nat.add_succ, taylor_within_eval_succ], simp only [add_zero, nat.factorial_succ, nat.cast_mul, nat.cast_add, nat.cast_one], have hdiff : differentiable_on ℝ (iterated_deriv_within k f s) s' := begin have coe_lt_succ : (k : with_top ℕ) < k.succ := by { rw [with_top.coe_lt_coe], exact lt_add_one k }, refine differentiable_on.mono _ h, exact hf.differentiable_on_iterated_deriv_within coe_lt_succ hs_unique, end, specialize hk (cont_diff_on.of_succ hf) hdiff, convert hk.add (has_deriv_within_at_taylor_coeff_within hs'_unique hs' hy h hf'), exact (add_sub_cancel'_right _ _).symm, end /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ lemma taylor_within_eval_has_deriv_at_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : cont_diff_on ℝ n f (Icc a b)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc a b)) (Ioo a b)) : has_deriv_at (λ y, taylor_within_eval f n (Icc a b) y x) (((n! : ℝ)⁻¹ * (x - t)^n) • (iterated_deriv_within (n+1) f (Icc a b) t)) t := begin have h_nhds := is_open.mem_nhds is_open_Ioo ht, exact (has_deriv_within_at_taylor_within_eval (unique_diff_within_at_Ioo ht) (unique_diff_on_Icc hx) (nhds_within_le_nhds h_nhds) ht Ioo_subset_Icc_self hf hf') .has_deriv_at h_nhds, end /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ lemma has_deriv_within_taylor_within_eval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : cont_diff_on ℝ n f (Icc a b)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc a b)) (Icc a b)) : has_deriv_within_at (λ y, taylor_within_eval f n (Icc a b) y x) (((n! : ℝ)⁻¹ * (x - t)^n) • (iterated_deriv_within (n+1) f (Icc a b) t)) (Icc a b) t := has_deriv_within_at_taylor_within_eval (unique_diff_on_Icc hx t ht) (unique_diff_on_Icc hx) self_mem_nhds_within ht rfl.subset hf hf' /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists a `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ lemma taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : cont_diff_on ℝ n f (Icc x₀ x)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : continuous_on g (Icc x₀ x)) (gdiff : ∀ (x_1 : ℝ), x_1 ∈ Ioo x₀ x → has_deriv_at g (g' x_1) x_1) (g'_ne : ∀ (x_1 : ℝ), x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ (x' : ℝ) (hx' : x' ∈ Ioo x₀ x), f x - taylor_within_eval f n (Icc x₀ x) x₀ x = ((x - x')^n /n! * (g x - g x₀) / g' x') • (iterated_deriv_within (n+1) f (Icc x₀ x) x') := begin -- We apply the mean value theorem rcases exists_ratio_has_deriv_at_eq_ratio_slope (λ t, taylor_within_eval f n (Icc x₀ x) t x) (λ t, ((n! : ℝ)⁻¹ * (x - t)^n) • (iterated_deriv_within (n+1) f (Icc x₀ x) t)) hx (continuous_on_taylor_within_eval (unique_diff_on_Icc hx) hf) (λ _ hy, taylor_within_eval_has_deriv_at_Ioo x hx hy hf hf') g g' gcont gdiff with ⟨y, hy, h⟩, use [y, hy], -- The rest is simplifications and trivial calculations simp only [taylor_within_eval_self] at h, rw [mul_comm, ←div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h, rw ←h, field_simp [g'_ne y hy, n.factorial_ne_zero], ring, end /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists a `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ lemma taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : cont_diff_on ℝ n f (Icc x₀ x)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ (x' : ℝ) (hx' : x' ∈ Ioo x₀ x), f x - taylor_within_eval f n (Icc x₀ x) x₀ x = (iterated_deriv_within (n+1) f (Icc x₀ x) x') * (x - x₀)^(n+1) /(n+1)! := begin have gcont : continuous_on (λ (t : ℝ), (x - t) ^ (n + 1)) (Icc x₀ x) := by { refine continuous.continuous_on _, continuity }, have xy_ne : ∀ (y : ℝ), y ∈ Ioo x₀ x → (x - y)^n ≠ 0 := begin intros y hy, refine pow_ne_zero _ _, rw [mem_Ioo] at hy, rw sub_ne_zero, exact hy.2.ne.symm, end, have hg' : ∀ (y : ℝ), y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := λ y hy, mul_ne_zero (neg_ne_zero.mpr (nat.cast_add_one_ne_zero n)) (xy_ne y hy), -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (λ y _, monomial_has_deriv_aux y x _) hg' with ⟨y, hy, h⟩, use [y, hy], simp only [sub_self, zero_pow', ne.def, nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h, rw [h, neg_div, ←div_neg, neg_mul, neg_neg], field_simp [n.cast_add_one_ne_zero, n.factorial_ne_zero, xy_ne y hy], ring, end /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists a `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ lemma taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : cont_diff_on ℝ n f (Icc x₀ x)) (hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ (x' : ℝ) (hx' : x' ∈ Ioo x₀ x), f x - taylor_within_eval f n (Icc x₀ x) x₀ x = (iterated_deriv_within (n+1) f (Icc x₀ x) x') * (x - x')^n /n! * (x - x₀) := begin have gcont : continuous_on id (Icc x₀ x) := continuous.continuous_on (by continuity), have gdiff : (∀ (x_1 : ℝ), x_1 ∈ Ioo x₀ x → has_deriv_at id ((λ (t : ℝ), (1 : ℝ)) x_1) x_1) := λ _ _, has_deriv_at_id _, -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff (λ _ _, by simp) with ⟨y, hy, h⟩, use [y, hy], rw h, field_simp [n.factorial_ne_zero], ring, end /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ lemma taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≤ b) (hf : cont_diff_on ℝ (n+1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iterated_deriv_within (n + 1) f (Icc a b) y‖ ≤ C) : ‖f x - taylor_within_eval f n (Icc a b) a x‖ ≤ C * (x - a)^(n+1) / n! := begin rcases eq_or_lt_of_le hab with rfl|h, { rw [Icc_self, mem_singleton_iff] at hx, simp [hx] }, -- The nth iterated derivative is differentiable have hf' : differentiable_on ℝ (iterated_deriv_within n f (Icc a b)) (Icc a b) := hf.differentiable_on_iterated_deriv_within (with_top.coe_lt_coe.mpr n.lt_succ_self) (unique_diff_on_Icc h), -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ (y : ℝ) (hy : y ∈ Ico a x), ‖((n! : ℝ)⁻¹ * (x - y) ^ n) • iterated_deriv_within (n + 1) f (Icc a b) y‖ ≤ (n! : ℝ)⁻¹ * |(x - a)|^n * C, { rintro y ⟨hay, hyx⟩, rw [norm_smul, real.norm_eq_abs], -- Estimate the iterated derivative by `C` refine mul_le_mul _ (hC y ⟨hay, hyx.le.trans hx.2⟩) (by positivity) (by positivity), -- The rest is a trivial calculation rw [abs_mul, abs_pow, abs_inv, nat.abs_cast], mono* with [0 ≤ (n! : ℝ)⁻¹], any_goals { positivity }, linarith [hx.1, hyx] }, -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, has_deriv_within_at (λ y, taylor_within_eval f n (Icc a b) y x) (((↑n!)⁻¹ * (x - t) ^ n) • iterated_deriv_within (n + 1) f (Icc a b) t) (Icc a x) t, { assume t ht, have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2, exact (has_deriv_within_taylor_within_eval_at_Icc x h (I ht) hf.of_succ hf').mono I }, have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1), simp only [taylor_within_eval_self] at this, refine this.trans_eq _, -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)], ring_exp, end /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ lemma exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≤ b) (hf : cont_diff_on ℝ (n+1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylor_within_eval f n (Icc a b) a x‖ ≤ C * (x - a)^(n+1) := begin rcases eq_or_lt_of_le hab with rfl|h, { refine ⟨0, λ x hx, _⟩, have : a = x, by simpa [← le_antisymm_iff] using hx, simp [← this] }, -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := λ y, ‖iterated_deriv_within (n + 1) f (Icc a b) y‖, use [has_Sup.Sup (g '' Icc a b) / n!], intros x hx, rw div_mul_eq_mul_div₀, refine taylor_mean_remainder_bound hab hf hx (λ y, _), exact (hf.continuous_on_iterated_deriv_within rfl.le $ unique_diff_on_Icc h) .norm.le_Sup_image_Icc, end
#include <iostream> #include <typeinfo> #include <boost/simd/algorithm.hpp> #include <boost/simd/pack.hpp> struct adder { template <typename T> T operator()(T const& a, T const& b) { return a + b; } }; //! [runtime-dec] void compute(float* a, float* b, float* res, int size, BOOST_SIMD_DEFAULT_SITE const& arch) { //! [runtime-dec] std::cout << " Architecture: " << typeid(arch).name() << std::endl; namespace bs = boost::simd; bs::transform(a, a + size, b, res, adder{}); }
{-# OPTIONS --safe --warning=error --without-K #-} open import Functions.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Setoids.Subset open import Setoids.Setoids open import Setoids.Orders.Partial.Definition open import Fields.Fields open import Rings.Orders.Total.Definition open import Rings.Orders.Total.Lemmas open import Rings.Orders.Partial.Definition open import Rings.Definition module Fields.Orders.LeastUpperBounds.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {c : _} {_<_ : Rel {_} {c} A} (pOrder : SetoidPartialOrder S _<_) where UpperBound : {d : _} {pred : A → Set d} (sub : subset S pred) (x : A) → Set _ UpperBound {pred = pred} sub x = (y : A) → pred y → (y < x) || (Setoid._∼_ S y x) record LeastUpperBound {d : _} {pred : A → Set d} (sub : subset S pred) (x : A) : Set (a ⊔ b ⊔ c ⊔ d) where field upperBound : UpperBound sub x leastUpperBound : (y : A) → UpperBound sub y → (x < y) || (Setoid._∼_ S x y)
apply : ∀ {a b} {A : Set a} {B : A → Set b} → ((x : A) → B x) → (x : A) → B x apply f x = f x syntax apply f x = f x
[GOAL] ⊢ Dense {x | Irrational x} [PROOFSTEP] refine' Real.isTopologicalBasis_Ioo_rat.dense_iff.2 _ [GOAL] ⊢ ∀ (o : Set ℝ), o ∈ ⋃ (a : ℚ) (b : ℚ) (_ : a < b), {Ioo ↑a ↑b} → Set.Nonempty o → Set.Nonempty (o ∩ {x | Irrational x}) [PROOFSTEP] simp only [gt_iff_lt, Rat.cast_lt, not_lt, ge_iff_le, Rat.cast_le, mem_iUnion, mem_singleton_iff, exists_prop, forall_exists_index, and_imp] [GOAL] ⊢ ∀ (o : Set ℝ) (x x_1 : ℚ), x < x_1 → o = Ioo ↑x ↑x_1 → Set.Nonempty o → Set.Nonempty (o ∩ {x | Irrational x}) [PROOFSTEP] rintro _ a b hlt rfl _ [GOAL] a b : ℚ hlt : a < b a✝ : Set.Nonempty (Ioo ↑a ↑b) ⊢ Set.Nonempty (Ioo ↑a ↑b ∩ {x | Irrational x}) [PROOFSTEP] rw [inter_comm] [GOAL] a b : ℚ hlt : a < b a✝ : Set.Nonempty (Ioo ↑a ↑b) ⊢ Set.Nonempty ({x | Irrational x} ∩ Ioo ↑a ↑b) [PROOFSTEP] exact exists_irrational_btwn (Rat.cast_lt.2 hlt) [GOAL] x✝¹ : ℝ x✝ : { x // Irrational x } x : ℝ hx : Irrational x ⊢ { val := x, property := hx } < { val := x + ↑1, property := (_ : Irrational (x + ↑1)) } [PROOFSTEP] simp [GOAL] x✝¹ : ℝ x✝ : { x // Irrational x } x : ℝ hx : Irrational x ⊢ { val := x - ↑1, property := (_ : Irrational (x - ↑1)) } < { val := x, property := hx } [PROOFSTEP] simp [GOAL] x : ℝ hx : Irrational x n : ℕ ⊢ ∀ᶠ (ε : ℝ) in 𝓝 0, ∀ (m : ℤ), ε ≤ dist x (↑m / ↑n) [PROOFSTEP] have A : IsClosed (range (fun m => (n : ℝ)⁻¹ * m : ℤ → ℝ)) := ((isClosedMap_smul₀ (n⁻¹ : ℝ)).comp Int.closedEmbedding_coe_real.isClosedMap).closed_range [GOAL] x : ℝ hx : Irrational x n : ℕ A : IsClosed (range fun m => (↑n)⁻¹ * ↑m) ⊢ ∀ᶠ (ε : ℝ) in 𝓝 0, ∀ (m : ℤ), ε ≤ dist x (↑m / ↑n) [PROOFSTEP] have B : x ∉ range (fun m => (n : ℝ)⁻¹ * m : ℤ → ℝ) := by rintro ⟨m, rfl⟩ simp at hx [GOAL] x : ℝ hx : Irrational x n : ℕ A : IsClosed (range fun m => (↑n)⁻¹ * ↑m) ⊢ ¬x ∈ range fun m => (↑n)⁻¹ * ↑m [PROOFSTEP] rintro ⟨m, rfl⟩ [GOAL] case intro n : ℕ A : IsClosed (range fun m => (↑n)⁻¹ * ↑m) m : ℤ hx : Irrational ((fun m => (↑n)⁻¹ * ↑m) m) ⊢ False [PROOFSTEP] simp at hx [GOAL] x : ℝ hx : Irrational x n : ℕ A : IsClosed (range fun m => (↑n)⁻¹ * ↑m) B : ¬x ∈ range fun m => (↑n)⁻¹ * ↑m ⊢ ∀ᶠ (ε : ℝ) in 𝓝 0, ∀ (m : ℤ), ε ≤ dist x (↑m / ↑n) [PROOFSTEP] rcases Metric.mem_nhds_iff.1 (A.isOpen_compl.mem_nhds B) with ⟨ε, ε0, hε⟩ [GOAL] case intro.intro x : ℝ hx : Irrational x n : ℕ A : IsClosed (range fun m => (↑n)⁻¹ * ↑m) B : ¬x ∈ range fun m => (↑n)⁻¹ * ↑m ε : ℝ ε0 : ε > 0 hε : ball x ε ⊆ (range fun m => (↑n)⁻¹ * ↑m)ᶜ ⊢ ∀ᶠ (ε : ℝ) in 𝓝 0, ∀ (m : ℤ), ε ≤ dist x (↑m / ↑n) [PROOFSTEP] refine' (ge_mem_nhds ε0).mono fun δ hδ m => not_lt.1 fun hlt => _ [GOAL] case intro.intro x : ℝ hx : Irrational x n : ℕ A : IsClosed (range fun m => (↑n)⁻¹ * ↑m) B : ¬x ∈ range fun m => (↑n)⁻¹ * ↑m ε : ℝ ε0 : ε > 0 hε : ball x ε ⊆ (range fun m => (↑n)⁻¹ * ↑m)ᶜ δ : ℝ hδ : δ ≤ ε m : ℤ hlt : dist x (↑m / ↑n) < δ ⊢ False [PROOFSTEP] rw [dist_comm] at hlt [GOAL] case intro.intro x : ℝ hx : Irrational x n : ℕ A : IsClosed (range fun m => (↑n)⁻¹ * ↑m) B : ¬x ∈ range fun m => (↑n)⁻¹ * ↑m ε : ℝ ε0 : ε > 0 hε : ball x ε ⊆ (range fun m => (↑n)⁻¹ * ↑m)ᶜ δ : ℝ hδ : δ ≤ ε m : ℤ hlt : dist (↑m / ↑n) x < δ ⊢ False [PROOFSTEP] refine' hε (ball_subset_ball hδ hlt) ⟨m, _⟩ [GOAL] case intro.intro x : ℝ hx : Irrational x n : ℕ A : IsClosed (range fun m => (↑n)⁻¹ * ↑m) B : ¬x ∈ range fun m => (↑n)⁻¹ * ↑m ε : ℝ ε0 : ε > 0 hε : ball x ε ⊆ (range fun m => (↑n)⁻¹ * ↑m)ᶜ δ : ℝ hδ : δ ≤ ε m : ℤ hlt : dist (↑m / ↑n) x < δ ⊢ (fun m => (↑n)⁻¹ * ↑m) m = ↑m / ↑n [PROOFSTEP] simp [div_eq_inv_mul] [GOAL] x : ℝ hx : Irrational x n : ℕ ε : ℝ H : ∀ (k : ℕ), k ≤ n → ∀ (m : ℤ), ε ≤ dist x (↑m / ↑k) r : ℚ hr : r.den ≤ n ⊢ ε ≤ dist x ↑r [PROOFSTEP] simpa only [Rat.cast_def] using H r.den hr r.num
lemma degree_1 [simp]: "degree 1 = 0"
import click import cv2 import numpy as np class Configuration(): """Setup up data for the rest of the functions """ def __init__(self, criteria): self.MAXIMUM_ITERATIONS = 30 self.SUBPIXEL_RESOLUTION = 0.001 self.criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, self.MAXIMUM_ITERATIONS, self.SUBPIXEL_RESOLUTION) # prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0) # Set it the the maximum size array needed. objp = np.zeros((7 * 6, 3), np.float32) objp[:, :2] = np.mgrid[0:7, 0:6].T.reshape(-1, 2) pass_configuration = click.make_pass_decorator(Configuration) @click.group() @click.command() @click.argument('images', nargs=-1) @pass_configuration() def cli(images): # Arrays to store object points and image points from all the images. # objpoints = [] # 3d point in real world space # imgpoints = [] # 2d points in image plane. [show_image(image) for image in images] def show_image(filename): click.echo("\n" + filename + "\n") image = cv2.imread(filename) click.echo(image) cv2.imshow('image', image) cv2.waitKey(500)
/- Author: <Redacted for anonymized submission> -/ import data.mv_polynomial.comm_ring import data.polynomial.div import data.polynomial.field_division import algebra.polynomial.big_operators import .vars import ...attributes import ...integral_domain_tactic /-! # Knowledge Soundness This file proves the knowledge-soundness property of the second, refined protocol described in the GGPR paper. -/ open_locale big_operators section noncomputable theory universes u /-- The finite field parameter of our SNARK -/ parameter {F : Type u} parameter [field F] /-- The naturals representing: m - m from paper - The QAP size n_in - n from paper - the number of inputs n_out - n' from paper - the number of outputs n_mid - (m - N) from paper - the number of internal gates d - the degree of h -/ parameters {n_in n_out n_mid d : ℕ} -- N from paper def n_stmt := n_in + n_out -- Alternative name def n_wit := n_mid def m := n_stmt + n_wit /-- fin-indexed collections of polynomials from the quadratic arithmetic program -/ parameter {v_stmt : fin n_stmt → polynomial F } -- parameter {w_stmt : fin n_stmt → polynomial F } -- parameter {y_stmt : fin n_stmt → polynomial F } parameter {v_wit : fin n_wit → polynomial F } -- parameter {w_wit : fin n_wit → polynomial F } parameter {w : fin m → polynomial F } -- parameter {y_wit : fin n_wit → polynomial F } parameter {v_0 : polynomial F } parameter {w_0 : polynomial F } -- parameter {y_0 : polynomial F } /-- The roots of the polynomial t -/ parameter {r : fin m → F} /-- t is the polynomial divisibility by which is used to verify satisfaction of the QAP -/ def t : polynomial F := ∏ i in (finset.fin_range m), (polynomial.X - polynomial.C (r i)) /-- t has degree m -/ lemma nat_degree_t : t.nat_degree = m := begin -- rw polynomial.nat_degree, rw t, rw polynomial.nat_degree_prod, simp, intros i hi, exact polynomial.X_sub_C_ne_zero (r i), end lemma monic_t : t.monic := begin rw t, apply polynomial.monic_prod_of_monic, intros i hi, exact polynomial.monic_X_sub_C (r i), end lemma degree_t_pos : 0 < m → 0 < t.degree := begin intro hm, suffices h : t.degree = some m, rw h, apply with_bot.some_lt_some.2, exact hm, have h := nat_degree_t, rw polynomial.nat_degree at h, induction h1 : t.degree, rw h1 at h, rw option.get_or_else at h, rw h at hm, have h2 := has_lt.lt.false hm, exfalso, exact h2, rw h1 at h, rw option.get_or_else at h, rw h, end -- -- Single variable form of V_wit -- def V_wit_sv (a_wit : fin n_wit → F) : polynomial F -- := ∑ i in finset.fin_range n_wit, a_wit i • u_wit i -- /-- The statement polynomial that the verifier computes from the statement bits, as a single variable polynomial -/ -- def V_stmt_sv (a_stmt : fin n_stmt → F) : polynomial F -- := ∑ i in (finset.fin_range n_stmt), a_stmt i • u_stmt i def satisfying (a_stmt : fin n_stmt → F) (a_wit : fin n_wit → F) (b : fin m -> F) := ( (v_0 + (∑ i in (finset.fin_range n_stmt), a_stmt i • v_stmt i) + ∑ i in (finset.fin_range n_wit), a_wit i • v_wit i) * (w_0 + (∑ i in (finset.fin_range m), b i • w i))) %ₘ t = 0 /- Multivariable polynomial definititons and ultilities -/ run_cmd mk_simp_attr `poly run_cmd tactic.add_doc_string `simp_attr.poly "Attribute for defintions of poly elements" -- Helpers for representing vars as polynomials @[poly] def β_v_poly : mv_polynomial vars (polynomial F) := mv_polynomial.X vars.β_v @[poly] def β_w_poly : mv_polynomial vars (polynomial F) := mv_polynomial.X vars.β_w @[poly] def s_poly : mv_polynomial vars (polynomial F) := mv_polynomial.C (polynomial.X) @[poly] def α_poly : mv_polynomial vars (polynomial F) := mv_polynomial.X vars.α @[poly] def γ_poly : mv_polynomial vars (polynomial F) := mv_polynomial.X vars.γ @[poly] def crs_powers (i : fin d) : (mv_polynomial vars (polynomial F)) := mv_polynomial.C (polynomial.X ^ (i : ℕ)) @[poly] def crs_α_powers (i : fin d) : (mv_polynomial vars (polynomial F)) := α_poly * mv_polynomial.C (polynomial.X ^ (i : ℕ)) @[poly] def crs_v_wit_k (k : fin n_wit) : mv_polynomial vars (polynomial F) := mv_polynomial.C (v_wit k) @[poly] def crs_w_k (k : fin m) : mv_polynomial vars (polynomial F) := mv_polynomial.C (w k) @[poly] def crs_α_v_wit_k (k : fin n_wit) : mv_polynomial vars (polynomial F) := α_poly * mv_polynomial.C (v_wit k) @[poly] def crs_α_w_k (k : fin m) : mv_polynomial vars (polynomial F) := α_poly * mv_polynomial.C (w k) @[poly] def crs_β_v_wit_k (k : fin n_wit) : mv_polynomial vars (polynomial F) := β_v_poly * mv_polynomial.C (v_wit k) @[poly] def crs_β_w_k (k : fin m) : mv_polynomial vars (polynomial F) := β_w_poly * mv_polynomial.C (w k) -- The crs elements as multivariate polynomials of the toxic waste samples: Verification key elements @[poly] def crs_α : mv_polynomial vars (polynomial F) := α_poly @[poly] def crs_γ : mv_polynomial vars (polynomial F) := γ_poly @[poly] def crs_β_v_γ : mv_polynomial vars (polynomial F) := β_v_poly * γ_poly @[poly] def crs_β_w_γ : mv_polynomial vars (polynomial F) := β_w_poly * γ_poly @[poly] def crs_v_0 : mv_polynomial vars (polynomial F) := mv_polynomial.C (v_0) @[poly] def crs_v_stmt (i : fin n_stmt) : mv_polynomial vars (polynomial F) := mv_polynomial.C (v_stmt i) @[poly] def crs_w_0 : mv_polynomial vars (polynomial F) := mv_polynomial.C (w_0) @[poly] def crs_t : mv_polynomial vars (polynomial F) := mv_polynomial.C (t) -- Coefficients of the CRS elements in the representation of the v_wit proof element in the AGM parameters {v_wit_comp_crs_powers : fin d → F} parameters {v_wit_comp_crs_α_powers : fin d → F} parameters {v_wit_comp_crs_v_wit_k : fin n_wit → F} parameters {v_wit_comp_crs_w_k : fin m → F} parameters {v_wit_comp_crs_α_v_wit_k : fin n_wit → F} parameters {v_wit_comp_crs_α_w_k : fin m → F} parameters {v_wit_comp_crs_β_v_wit_k : fin n_wit → F} parameters {v_wit_comp_crs_β_w_k : fin m → F} parameters {v_wit_comp_crs_α : F} parameters {v_wit_comp_crs_γ : F} parameters {v_wit_comp_crs_β_v_γ : F} parameters {v_wit_comp_crs_β_w_γ : F} parameters {v_wit_comp_crs_v_0 : F} parameters {v_wit_comp_crs_w_0 : F} parameters {v_wit_comp_crs_v_stmt : fin n_stmt → F} parameters {v_wit_comp_crs_t : F} /-- Polynomial form of the representation of the v_wit proof element in the AGM -/ def proof_v_wit : mv_polynomial vars (polynomial F) := ∑ i in (finset.fin_range d), (crs_powers i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_powers i)) + ∑ i in (finset.fin_range d), (crs_α_powers i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_α_powers i)) + ∑ i in (finset.fin_range n_wit), (crs_v_wit_k i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_w_k i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_α_v_wit_k i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_α_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_α_w_k i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_α_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_β_v_wit_k i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_β_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_β_w_k i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_β_w_k i)) + crs_α * mv_polynomial.C (polynomial.C (v_wit_comp_crs_α)) + crs_γ * mv_polynomial.C (polynomial.C (v_wit_comp_crs_γ)) + crs_β_v_γ * mv_polynomial.C (polynomial.C (v_wit_comp_crs_β_v_γ)) + crs_β_w_γ * mv_polynomial.C (polynomial.C (v_wit_comp_crs_β_w_γ)) + crs_t * mv_polynomial.C (polynomial.C (v_wit_comp_crs_t)) + crs_v_0 * mv_polynomial.C (polynomial.C (v_wit_comp_crs_v_0)) + crs_w_0 * mv_polynomial.C (polynomial.C (v_wit_comp_crs_w_0)) + ∑ i in (finset.fin_range n_stmt), (crs_v_stmt i) * mv_polynomial.C (polynomial.C (v_wit_comp_crs_v_stmt i)) -- Coefficients of the CRS elements in the representation of the w proof element in the AGM parameters {w_comp_crs_powers : fin d → F} parameters {w_comp_crs_α_powers : fin d → F} parameters {w_comp_crs_v_wit_k : fin n_wit → F} parameters {w_comp_crs_w_k : fin m → F} parameters {w_comp_crs_α_v_wit_k : fin n_wit → F} parameters {w_comp_crs_α_w_k : fin m → F} parameters {w_comp_crs_β_v_wit_k : fin n_wit → F} parameters {w_comp_crs_β_w_k : fin m → F} parameters {w_comp_crs_α : F} parameters {w_comp_crs_γ : F} parameters {w_comp_crs_β_v_γ : F} parameters {w_comp_crs_β_w_γ : F} parameters {w_comp_crs_v_0 : F} parameters {w_comp_crs_w_0 : F} parameters {w_comp_crs_v_stmt : fin n_stmt → F} parameters {w_comp_crs_t : F} /-- Polynomial form of the representation of the w proof element in the AGM -/ def proof_w : mv_polynomial vars (polynomial F) := ∑ i in (finset.fin_range d), (crs_powers i) * mv_polynomial.C (polynomial.C (w_comp_crs_powers i)) + ∑ i in (finset.fin_range d), (crs_α_powers i) * mv_polynomial.C (polynomial.C (w_comp_crs_α_powers i)) + ∑ i in (finset.fin_range n_wit), (crs_v_wit_k i) * mv_polynomial.C (polynomial.C (w_comp_crs_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_w_k i) * mv_polynomial.C (polynomial.C (w_comp_crs_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_α_v_wit_k i) * mv_polynomial.C (polynomial.C (w_comp_crs_α_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_α_w_k i) * mv_polynomial.C (polynomial.C (w_comp_crs_α_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_β_v_wit_k i) * mv_polynomial.C (polynomial.C (w_comp_crs_β_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_β_w_k i) * mv_polynomial.C (polynomial.C (w_comp_crs_β_w_k i)) + crs_α * mv_polynomial.C (polynomial.C (w_comp_crs_α)) + crs_γ * mv_polynomial.C (polynomial.C (w_comp_crs_γ)) + crs_β_v_γ * mv_polynomial.C (polynomial.C (w_comp_crs_β_v_γ)) + crs_β_w_γ * mv_polynomial.C (polynomial.C (w_comp_crs_β_w_γ)) + crs_t * mv_polynomial.C (polynomial.C (w_comp_crs_t)) + crs_v_0 * mv_polynomial.C (polynomial.C (w_comp_crs_v_0)) + crs_w_0 * mv_polynomial.C (polynomial.C (w_comp_crs_w_0)) + ∑ i in (finset.fin_range n_stmt), (crs_v_stmt i) * mv_polynomial.C (polynomial.C (w_comp_crs_v_stmt i)) -- Coefficients of the CRS elements in the representation of the h proof element in the AGM parameters {h_comp_crs_powers : fin d → F} parameters {h_comp_crs_α_powers : fin d → F} parameters {h_comp_crs_v_wit_k : fin n_wit → F} parameters {h_comp_crs_w_k : fin m → F} parameters {h_comp_crs_α_v_wit_k : fin n_wit → F} parameters {h_comp_crs_α_w_k : fin m → F} parameters {h_comp_crs_β_v_wit_k : fin n_wit → F} parameters {h_comp_crs_β_w_k : fin m → F} parameters {h_comp_crs_α : F} parameters {h_comp_crs_γ : F} parameters {h_comp_crs_β_v_γ : F} parameters {h_comp_crs_β_w_γ : F} parameters {h_comp_crs_v_0 : F} parameters {h_comp_crs_w_0 : F} parameters {h_comp_crs_v_stmt : fin n_stmt → F} parameters {h_comp_crs_t : F} /-- Polynomial form of the representation of the v_wit proof element in the AGM -/ def proof_h : mv_polynomial vars (polynomial F) := ∑ i in (finset.fin_range d), (crs_powers i) * mv_polynomial.C (polynomial.C (h_comp_crs_powers i)) + ∑ i in (finset.fin_range d), (crs_α_powers i) * mv_polynomial.C (polynomial.C (h_comp_crs_α_powers i)) + ∑ i in (finset.fin_range n_wit), (crs_v_wit_k i) * mv_polynomial.C (polynomial.C (h_comp_crs_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_w_k i) * mv_polynomial.C (polynomial.C (h_comp_crs_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_α_v_wit_k i) * mv_polynomial.C (polynomial.C (h_comp_crs_α_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_α_w_k i) * mv_polynomial.C (polynomial.C (h_comp_crs_α_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_β_v_wit_k i) * mv_polynomial.C (polynomial.C (h_comp_crs_β_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_β_w_k i) * mv_polynomial.C (polynomial.C (h_comp_crs_β_w_k i)) + crs_α * mv_polynomial.C (polynomial.C (h_comp_crs_α)) + crs_γ * mv_polynomial.C (polynomial.C (h_comp_crs_γ)) + crs_β_v_γ * mv_polynomial.C (polynomial.C (h_comp_crs_β_v_γ)) + crs_β_w_γ * mv_polynomial.C (polynomial.C (h_comp_crs_β_w_γ)) + crs_t * mv_polynomial.C (polynomial.C (h_comp_crs_t)) + crs_v_0 * mv_polynomial.C (polynomial.C (h_comp_crs_v_0)) + crs_w_0 * mv_polynomial.C (polynomial.C (h_comp_crs_w_0)) + ∑ i in (finset.fin_range n_stmt), (crs_v_stmt i) * mv_polynomial.C (polynomial.C (h_comp_crs_v_stmt i)) -- Coefficients of the CRS elements in the representation of the α_v_wit proof element in the AGM parameters {α_v_wit_comp_crs_powers : fin d → F} parameters {α_v_wit_comp_crs_α_powers : fin d → F} parameters {α_v_wit_comp_crs_v_wit_k : fin n_wit → F} parameters {α_v_wit_comp_crs_w_k : fin m → F} parameters {α_v_wit_comp_crs_α_v_wit_k : fin n_wit → F} parameters {α_v_wit_comp_crs_α_w_k : fin m → F} parameters {α_v_wit_comp_crs_β_v_wit_k : fin n_wit → F} parameters {α_v_wit_comp_crs_β_w_k : fin m → F} parameters {α_v_wit_comp_crs_α : F} parameters {α_v_wit_comp_crs_γ : F} parameters {α_v_wit_comp_crs_β_v_γ : F} parameters {α_v_wit_comp_crs_β_w_γ : F} parameters {α_v_wit_comp_crs_v_0 : F} parameters {α_v_wit_comp_crs_w_0 : F} parameters {α_v_wit_comp_crs_v_stmt : fin n_stmt → F} parameters {α_v_wit_comp_crs_t : F} /-- Polynomial form of the representation of the v_wit proof element in the AGM -/ def proof_α_v_wit : mv_polynomial vars (polynomial F) := ∑ i in (finset.fin_range d), (crs_powers i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_powers i)) + ∑ i in (finset.fin_range d), (crs_α_powers i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_α_powers i)) + ∑ i in (finset.fin_range n_wit), (crs_v_wit_k i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_w_k i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_α_v_wit_k i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_α_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_α_w_k i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_α_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_β_v_wit_k i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_β_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_β_w_k i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_β_w_k i)) + crs_α * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_α)) + crs_γ * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_γ)) + crs_β_v_γ * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_β_v_γ)) + crs_β_w_γ * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_β_w_γ)) + crs_t * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_t)) + crs_v_0 * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_v_0)) + crs_w_0 * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_w_0)) + ∑ i in (finset.fin_range n_stmt), (crs_v_stmt i) * mv_polynomial.C (polynomial.C (α_v_wit_comp_crs_v_stmt i)) -- Coefficients of the CRS elements in the representation of the α_w proof element in the AGM parameters {α_w_comp_crs_powers : fin d → F} parameters {α_w_comp_crs_α_powers : fin d → F} parameters {α_w_comp_crs_v_wit_k : fin n_wit → F} parameters {α_w_comp_crs_w_k : fin m → F} parameters {α_w_comp_crs_α_v_wit_k : fin n_wit → F} parameters {α_w_comp_crs_α_w_k : fin m → F} parameters {α_w_comp_crs_β_v_wit_k : fin n_wit → F} parameters {α_w_comp_crs_β_w_k : fin m → F} parameters {α_w_comp_crs_α : F} parameters {α_w_comp_crs_γ : F} parameters {α_w_comp_crs_β_v_γ : F} parameters {α_w_comp_crs_β_w_γ : F} parameters {α_w_comp_crs_v_0 : F} parameters {α_w_comp_crs_w_0 : F} parameters {α_w_comp_crs_v_stmt : fin n_stmt → F} parameters {α_w_comp_crs_t : F} /-- Polynomial form of the representation of the v_wit proof element in the AGM -/ def proof_α_w : mv_polynomial vars (polynomial F) := ∑ i in (finset.fin_range d), (crs_powers i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_powers i)) + ∑ i in (finset.fin_range d), (crs_α_powers i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_α_powers i)) + ∑ i in (finset.fin_range n_wit), (crs_v_wit_k i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_w_k i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_α_v_wit_k i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_α_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_α_w_k i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_α_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_β_v_wit_k i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_β_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_β_w_k i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_β_w_k i)) + crs_α * mv_polynomial.C (polynomial.C (α_w_comp_crs_α)) + crs_γ * mv_polynomial.C (polynomial.C (α_w_comp_crs_γ)) + crs_β_v_γ * mv_polynomial.C (polynomial.C (α_w_comp_crs_β_v_γ)) + crs_β_w_γ * mv_polynomial.C (polynomial.C (α_w_comp_crs_β_w_γ)) + crs_t * mv_polynomial.C (polynomial.C (α_w_comp_crs_t)) + crs_v_0 * mv_polynomial.C (polynomial.C (α_w_comp_crs_v_0)) + crs_w_0 * mv_polynomial.C (polynomial.C (α_w_comp_crs_w_0)) + ∑ i in (finset.fin_range n_stmt), (crs_v_stmt i) * mv_polynomial.C (polynomial.C (α_w_comp_crs_v_stmt i)) -- Coefficients of the CRS elements in the representation of the α_h proof element in the AGM parameters {α_h_comp_crs_powers : fin d → F} parameters {α_h_comp_crs_α_powers : fin d → F} parameters {α_h_comp_crs_v_wit_k : fin n_wit → F} parameters {α_h_comp_crs_w_k : fin m → F} parameters {α_h_comp_crs_α_v_wit_k : fin n_wit → F} parameters {α_h_comp_crs_α_w_k : fin m → F} parameters {α_h_comp_crs_β_v_wit_k : fin n_wit → F} parameters {α_h_comp_crs_β_w_k : fin m → F} parameters {α_h_comp_crs_α : F} parameters {α_h_comp_crs_γ : F} parameters {α_h_comp_crs_β_v_γ : F} parameters {α_h_comp_crs_β_w_γ : F} parameters {α_h_comp_crs_v_0 : F} parameters {α_h_comp_crs_w_0 : F} parameters {α_h_comp_crs_v_stmt : fin n_stmt → F} parameters {α_h_comp_crs_t : F} /-- Polynomial form of the representation of the α_h proof element in the AGM -/ def proof_α_h : mv_polynomial vars (polynomial F) := ∑ i in (finset.fin_range d), (crs_powers i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_powers i)) + ∑ i in (finset.fin_range d), (crs_α_powers i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_α_powers i)) + ∑ i in (finset.fin_range n_wit), (crs_v_wit_k i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_w_k i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_α_v_wit_k i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_α_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_α_w_k i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_α_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_β_v_wit_k i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_β_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_β_w_k i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_β_w_k i)) + crs_α * mv_polynomial.C (polynomial.C (α_h_comp_crs_α)) + crs_γ * mv_polynomial.C (polynomial.C (α_h_comp_crs_γ)) + crs_β_v_γ * mv_polynomial.C (polynomial.C (α_h_comp_crs_β_v_γ)) + crs_β_w_γ * mv_polynomial.C (polynomial.C (α_h_comp_crs_β_w_γ)) + crs_t * mv_polynomial.C (polynomial.C (α_h_comp_crs_t)) + crs_v_0 * mv_polynomial.C (polynomial.C (α_h_comp_crs_v_0)) + crs_w_0 * mv_polynomial.C (polynomial.C (α_h_comp_crs_w_0)) + ∑ i in (finset.fin_range n_stmt), (crs_v_stmt i) * mv_polynomial.C (polynomial.C (α_h_comp_crs_v_stmt i)) -- Coefficients of the CRS elements in the representation of the y proof element in the AGM parameters {y_comp_crs_powers : fin d → F} parameters {y_comp_crs_α_powers : fin d → F} parameters {y_comp_crs_v_wit_k : fin n_wit → F} parameters {y_comp_crs_w_k : fin m → F} parameters {y_comp_crs_α_v_wit_k : fin n_wit → F} parameters {y_comp_crs_α_w_k : fin m → F} parameters {y_comp_crs_β_v_wit_k : fin n_wit → F} parameters {y_comp_crs_β_w_k : fin m → F} parameters {y_comp_crs_α : F} parameters {y_comp_crs_γ : F} parameters {y_comp_crs_β_v_γ : F} parameters {y_comp_crs_β_w_γ : F} parameters {y_comp_crs_v_0 : F} parameters {y_comp_crs_w_0 : F} parameters {y_comp_crs_v_stmt : fin n_stmt → F} parameters {y_comp_crs_t : F} /-- Polynomial form of the representation of the y proof element in the AGM -/ def proof_y : mv_polynomial vars (polynomial F) := ∑ i in (finset.fin_range d), (crs_powers i) * mv_polynomial.C (polynomial.C (y_comp_crs_powers i)) + ∑ i in (finset.fin_range d), (crs_α_powers i) * mv_polynomial.C (polynomial.C (y_comp_crs_α_powers i)) + ∑ i in (finset.fin_range n_wit), (crs_v_wit_k i) * mv_polynomial.C (polynomial.C (y_comp_crs_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_w_k i) * mv_polynomial.C (polynomial.C (y_comp_crs_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_α_v_wit_k i) * mv_polynomial.C (polynomial.C (y_comp_crs_α_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_α_w_k i) * mv_polynomial.C (polynomial.C (y_comp_crs_α_w_k i)) + ∑ i in (finset.fin_range n_wit), (crs_β_v_wit_k i) * mv_polynomial.C (polynomial.C (y_comp_crs_β_v_wit_k i)) + ∑ i in (finset.fin_range m), (crs_β_w_k i) * mv_polynomial.C (polynomial.C (y_comp_crs_β_w_k i)) + crs_α * mv_polynomial.C (polynomial.C (y_comp_crs_α)) + crs_γ * mv_polynomial.C (polynomial.C (y_comp_crs_γ)) + crs_β_v_γ * mv_polynomial.C (polynomial.C (y_comp_crs_β_v_γ)) + crs_β_w_γ * mv_polynomial.C (polynomial.C (y_comp_crs_β_w_γ)) + crs_t * mv_polynomial.C (polynomial.C (y_comp_crs_t)) + crs_v_0 * mv_polynomial.C (polynomial.C (y_comp_crs_v_0)) + crs_w_0 * mv_polynomial.C (polynomial.C (y_comp_crs_w_0)) + ∑ i in (finset.fin_range n_stmt), (crs_v_stmt i) * mv_polynomial.C (polynomial.C (y_comp_crs_v_stmt i)) -- Single variable form of V_wit def v_wit_sv (a_wit : fin n_wit → F) : polynomial F := ∑ i in finset.fin_range n_wit, a_wit i • v_wit i /-- The statement polynomial that the verifier computes from the statement bits, as a single variable polynomial -/ def v_stmt_sv (a_stmt : fin n_stmt → F) : polynomial F := ∑ i in (finset.fin_range n_stmt), a_stmt i • v_stmt i @[poly] def v_stmt_mv (a_stmt : fin n_stmt → F) : mv_polynomial vars (polynomial F) := mv_polynomial.C (v_stmt_sv a_stmt) /-- The statement polynomial that the verifier computes from the statement bits, as a single variable polynomial -/ def w_sv (b : fin m → F) : polynomial F := ∑ i in (finset.fin_range m), b i • w i @[poly] def w_mv (a : fin m → F) : mv_polynomial vars (polynomial F) := mv_polynomial.C (w_sv a) /-- Multivariable version of t -/ @[poly] def t_mv : mv_polynomial vars (polynomial F) := mv_polynomial.C t -- Equations def eqnI (c_stmt : fin n_stmt → F ) : Prop := (crs_v_0 + v_stmt_mv c_stmt + proof_v_wit) * (crs_w_0 + proof_w) = (t_mv * proof_h) def eqnII : Prop := proof_α_v_wit = proof_v_wit * crs_α def eqnIII : Prop := proof_α_w = proof_w * crs_α def eqnIV : Prop := proof_α_h = proof_h * crs_α def eqnV : Prop := proof_y * crs_γ = proof_v_wit * crs_β_v_γ + proof_w * crs_β_w_γ -- Coefficients open mv_polynomial finsupp -- lemma sadojfh (a b c : mv_polynomial vars (polynomial F)) : a + b - c = a -c + b := -- begin -- ring, -- end -- example (a b c d e f g h i : F) : a + d + b + e + c - (a + b) = 0 := -- begin -- abel, -- end lemma move_C_left (p : polynomial F) (f : F) : p * polynomial.C f = polynomial.C f * p := begin ring, end -- set_option profiler true lemma eqnIIresults (eqnII_verified : eqnII) : proof_v_wit = mv_polynomial.C ( ∑ i in (finset.fin_range n_wit), (v_wit i) * (polynomial.C (v_wit_comp_crs_v_wit_k i)) + v_0 * (polynomial.C v_wit_comp_crs_v_0) + ∑ i in finset.fin_range n_stmt, (v_stmt i) * (polynomial.C (v_wit_comp_crs_v_stmt i)) + ∑ x in finset.fin_range d, (polynomial.X ^ (x : ℕ)) * (polynomial.C (v_wit_comp_crs_powers x)) + polynomial.C v_wit_comp_crs_w_0 * w_0 + polynomial.C v_wit_comp_crs_t * t + ∑ (x : fin m) in finset.fin_range m, polynomial.C (v_wit_comp_crs_w_k x) * w x ) := begin rw eqnII at eqnII_verified, simp_rw [proof_v_wit, proof_α_v_wit] at eqnII_verified ⊢, -- simp_rw [proof_v_wit, proof_w_wit, proof_y_wit, proof_h, -- proof_v_wit', proof_w_wit', proof_y_wit', proof_Z] at eqnII_verified, simp only [] with poly at eqnII_verified ⊢, -- simp only [] with polynomial_nf_3 at eqn', simp only [mv_polynomial.X, C_apply, mv_polynomial.monomial_mul, one_mul, mul_one, add_zero, zero_add, finset.sum_add_distrib, finset.sum_hom, mul_add, add_mul, sum_monomial_hom] at eqnII_verified ⊢, have h11eqnII := congr_arg (coeff (single vars.α 1 + single vars.β_v 1 + single vars.γ 1)) eqnII_verified, have h12eqnII := congr_arg (coeff (single vars.α 1 + single vars.β_w 1 + single vars.γ 1)) eqnII_verified, have h19eqnII := congr_arg (coeff (single vars.α 1 + single vars.γ 1)) eqnII_verified, have h21eqnII := congr_arg (coeff (single vars.α 1 + single vars.β_v 1)) eqnII_verified, have h22eqnII := congr_arg (coeff (single vars.α 2)) eqnII_verified, have h71eqnII := congr_arg (coeff (single vars.α 1)) eqnII_verified, have h74eqnII := congr_arg (coeff (single vars.α 1 + single vars.β_w 1)) eqnII_verified, clear eqnII_verified, simp only [finsupp_vars_eq_ext] with coeff_simp finsupp_eq at *, simp only [] with finsupp_simp at *, simp only [h11eqnII, h12eqnII, h19eqnII, h21eqnII, h22eqnII, h71eqnII, h74eqnII], simp only [monomial_zero, add_zero, zero_add, <-monomial_add], rw <-sub_eq_iff_eq_add', ring_nf, rw <-sub_eq_zero, simp_rw [move_C_left], ring_nf, have h22eqnII' := congr_arg (monomial (single vars.α 1)) h22eqnII, simp only [monomial_zero, add_zero, zero_add, <-monomial_add] at h22eqnII', rw <-h22eqnII', rw <-sub_eq_iff_eq_add, -- simp_rw [add_assoc], abel, rw <-sub_eq_iff_eq_add', simp_rw [move_C_left], -- simp_rw [add_assoc], abel, end lemma eqnIIIresults (eqnIII_verified : eqnIII) : proof_w = mv_polynomial.C ( ∑ i in (finset.fin_range n_wit), (v_wit i) * (polynomial.C (w_comp_crs_v_wit_k i)) + v_0 * (polynomial.C w_comp_crs_v_0) + ∑ i in finset.fin_range n_stmt, (v_stmt i) * (polynomial.C (w_comp_crs_v_stmt i)) + ∑ x in finset.fin_range d, (polynomial.X ^ (x : ℕ)) * ( polynomial.C (w_comp_crs_powers x)) + polynomial.C w_comp_crs_w_0 * w_0 + polynomial.C w_comp_crs_t * t + ∑ (x : fin m) in finset.fin_range m, polynomial.C (w_comp_crs_w_k x) * w x ) := begin rw eqnIII at eqnIII_verified, simp_rw [proof_w, proof_α_w] at eqnIII_verified ⊢, -- simp_rw [proof_v_wit, proof_w_wit, proof_y_wit, proof_h, -- proof_v_wit', proof_w_wit', proof_y_wit', proof_Z] at eqnIII_verified, simp only [] with poly at eqnIII_verified ⊢, -- simp only [] with polynomial_nf_3 at eqn', simp only [mv_polynomial.X, C_apply, mv_polynomial.monomial_mul, one_mul, mul_one, add_zero, zero_add, finset.sum_add_distrib, finset.sum_hom, mul_add, add_mul, sum_monomial_hom] at eqnIII_verified ⊢, have h11eqnIII := congr_arg (coeff (single vars.α 1 + single vars.β_v 1 + single vars.γ 1)) eqnIII_verified, have h12eqnIII := congr_arg (coeff (single vars.α 1 + single vars.β_w 1 + single vars.γ 1)) eqnIII_verified, have h19eqnIII := congr_arg (coeff (single vars.α 1 + single vars.γ 1)) eqnIII_verified, have h21eqnIII := congr_arg (coeff (single vars.α 1 + single vars.β_v 1)) eqnIII_verified, have h22eqnIII := congr_arg (coeff (single vars.α 2)) eqnIII_verified, have h71eqnIII := congr_arg (coeff (single vars.α 1)) eqnIII_verified, have h74eqnIII := congr_arg (coeff (single vars.α 1 + single vars.β_w 1)) eqnIII_verified, clear eqnIII_verified, simp only [finsupp_vars_eq_ext] with coeff_simp finsupp_eq at *, simp only [] with finsupp_simp at *, simp only [h11eqnIII, h12eqnIII, h19eqnIII, h21eqnIII, h22eqnIII, h71eqnIII, h74eqnIII], simp only [monomial_zero, add_zero, zero_add, <-monomial_add], rw <-sub_eq_iff_eq_add', ring_nf, rw <-sub_eq_zero, simp_rw [move_C_left], ring_nf, have h22eqnIII' := congr_arg (monomial (single vars.α 1)) h22eqnIII, simp only [monomial_zero, add_zero, zero_add, <-monomial_add] at h22eqnIII', rw <-h22eqnIII', rw <-sub_eq_iff_eq_add, -- simp_rw [add_assoc], abel, rw <-sub_eq_iff_eq_add', simp_rw [move_C_left], -- simp_rw [add_assoc], abel, end -- lemma eqnIVresults (eqnIV_verified : eqnIV) : -- proof_h -- = mv_polynomial.C ( -- ∑ i in (finset.fin_range n_wit), (v_wit i) * (polynomial.C (h_comp_crs_v_wit_k i)) -- + v_0 * (polynomial.C h_comp_crs_v_0) -- + ∑ i in finset.fin_range n_stmt, (v_stmt i) * (polynomial.C (h_comp_crs_v_stmt i)) -- + ∑ x in finset.fin_range d, (polynomial.X ^ (x : ℕ)) * ( polynomial.C (h_comp_crs_powers x)) -- + polynomial.C h_comp_crs_w_0 * w_0 -- + polynomial.C h_comp_crs_t * t -- + ∑ (x : fin m) in finset.fin_range m, polynomial.C (h_comp_crs_w_k x) * w x -- ) := -- begin -- rw eqnIV at eqnIV_verified, -- simp_rw [proof_h, proof_α_h] at eqnIV_verified ⊢, -- -- simp_rw [proof_v_wit, proof_w_wit, proof_y_wit, proof_h, -- -- proof_v_wit', proof_w_wit', proof_y_wit', proof_Z] at eqnIV_verified, -- simp only [] with poly at eqnIV_verified ⊢, -- -- simp only [] with polynomial_nf_3 at eqn', -- simp only [mv_polynomial.X, C_apply, mv_polynomial.monomial_mul, one_mul, mul_one, add_zero, zero_add, finset.sum_add_distrib, finset.sum_hom, mul_add, add_mul, sum_monomial_hom] at eqnIV_verified ⊢, -- have h11eqnIV := congr_arg (coeff (single vars.α 1 + single vars.β_v 1 + single vars.γ 1)) eqnIV_verified, -- have h12eqnIV := congr_arg (coeff (single vars.α 1 + single vars.β_w 1 + single vars.γ 1)) eqnIV_verified, -- have h19eqnIV := congr_arg (coeff (single vars.α 1 + single vars.γ 1)) eqnIV_verified, -- have h21eqnIV := congr_arg (coeff (single vars.α 1 + single vars.β_v 1)) eqnIV_verified, -- have h22eqnIV := congr_arg (coeff (single vars.α 2)) eqnIV_verified, -- have h71eqnIV := congr_arg (coeff (single vars.α 1)) eqnIV_verified, -- have h74eqnIV := congr_arg (coeff (single vars.α 1 + single vars.β_w 1)) eqnIV_verified, -- clear eqnIV_verified, -- simp only [finsupp_vars_eq_ext] with coeff_simp finsupp_eq at *, -- simp only [] with finsupp_simp at *, -- simp only [h11eqnIV, h12eqnIV, h19eqnIV, h21eqnIV, h22eqnIV, h71eqnIV, h74eqnIV], -- simp only [monomial_zero, add_zero, zero_add, <-monomial_add], -- rw <-sub_eq_iff_eq_add', -- ring_nf, -- rw <-sub_eq_zero, -- simp_rw [move_C_left], -- ring_nf, -- have h22eqnIV' := congr_arg (monomial (single vars.α 1)) h22eqnIV, -- simp only [monomial_zero, add_zero, zero_add, <-monomial_add] at h22eqnIV', -- rw <-h22eqnIV', -- rw <-sub_eq_iff_eq_add, -- -- simp_rw [add_assoc], -- abel, -- rw <-sub_eq_iff_eq_add', -- simp_rw [move_C_left], -- -- simp_rw [add_assoc], -- abel, -- end lemma polynomial.mul_mod_by_monic (t p : polynomial F) (mt : t.monic) : (t * p) %ₘ t = 0 := begin rw polynomial.dvd_iff_mod_by_monic_eq_zero, apply dvd_mul_right, exact mt, end lemma soundness (c_stmt : fin n_stmt → F ) (eqnI_verified : eqnI c_stmt) (eqnII_verified : eqnII) (eqnIII_verified : eqnIII) -- (eqnIV_verified : eqnIV) (eqnV_verified : eqnV) : (satisfying c_stmt y_comp_crs_β_v_wit_k y_comp_crs_β_w_k) := begin rw eqnV at eqnV_verified, have eqnII' := eqnIIresults eqnII_verified, have eqnIII' := eqnIIIresults eqnIII_verified, -- have eqnIV' := eqnIVresults eqnIV_verified, simp_rw [eqnII', eqnIII', proof_y] at eqnV_verified, simp only [] with poly at eqnV_verified, -- simp only [] with polynomial_nf_3 at eqn', simp only [mv_polynomial.X, C_apply, mv_polynomial.monomial_mul, one_mul, mul_one, add_zero, zero_add, finset.sum_add_distrib, finset.sum_hom, mul_add, add_mul, sum_monomial_hom] at eqnV_verified, have h2eqnV := congr_arg (coeff (single vars.β_v 1 + single vars.γ 1)) eqnV_verified, have h3eqnV := congr_arg (coeff (single vars.β_w 1 + single vars.γ 1)) eqnV_verified, -- have h4eqnV := congr_arg (coeff (single vars.r_v 1 + single vars.r_w 1 + single vars.β 1 + single vars.γ 1)) eqnV_verified, clear eqnV_verified, simp only [finsupp_vars_eq_ext] with coeff_simp finsupp_eq at *, simp only [] with finsupp_simp at *, rw [<-h2eqnV] at eqnII', rw [<-h3eqnV] at eqnIII', -- rw [<-h4eqnV] at eqnIV', rw [eqnI] at eqnI_verified, rw satisfying, simp_rw [eqnII', eqnIII', proof_h] at eqnI_verified, simp only [] with poly at eqnI_verified, -- simp only [] with polynomial_nf_3 at eqn', simp only [mv_polynomial.X, C_apply, mv_polynomial.monomial_mul, one_mul, mul_one, add_zero, zero_add, finset.sum_add_distrib, finset.sum_hom, mul_add, add_mul, sum_monomial_hom] at eqnI_verified, have h1eqnI := congr_arg (coeff 0) eqnI_verified, clear eqnI_verified, simp only [finsupp_vars_eq_ext] with coeff_simp finsupp_eq at h1eqnI, simp only [] with finsupp_simp at h1eqnI, -- rw <-sub_eq_iff_eq_add at h1eqnI, simp_rw [<-mul_add t] at h1eqnI, -- rw <-sub_eq_zero at h1eqnI, -- rw polynomial.dvd_iff_mod_by_monic_eq_zero, have h2eqnI := congr_arg (%ₘ t) h1eqnI, simp only [polynomial.zero_mod_by_monic] at h2eqnI, rw polynomial.mul_mod_by_monic at h2eqnI, rw <- h2eqnI, congr' 1, simp_rw [v_stmt_sv, polynomial.smul_eq_C_mul], simp only [add_mul, mul_add], simp_rw [move_C_left], -- congr' 1, -- rw <-sub_eq_zero, abel, exact monic_t, end end
/- Copyright (c) 2022 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author : Kevin Buzzard -/ import tactic -- imports all the Lean tactics import data.real.basic -- imports the real numbers import solutions.section02reals.sheet5 -- import a bunch of previous stuff /- # Harder questions Here are some harder questions. Don't feel like you have to do them. We've seen enough techniques to be able to do all of these, but the truth is that we've seen a ton of stuff in this course already, so probably you're not on top of all of it yet, and furthermore we have not seen some techniques which will enable you to cut corners. If you want to become a real Lean expert then see how many of these you can do. I will go through them all in a solutions video, so if you like you can try some of them and then watch me solving them. Good luck! -/ /-- If `a(n)` tends to `t` then `37 * a(n)` tends to `37 * t`-/ theorem tendsto_thirtyseven_mul (a : ℕ → ℝ) (t : ℝ) (h : tendsto a t) : tendsto (λ n, 37 * a n) (37 * t) := begin sorry, end /-- If `a(n)` tends to `t` and `c` is a positive constant then `c * a(n)` tends to `c * t`. -/ theorem tendsto_pos_const_mul {a : ℕ → ℝ} {t : ℝ} (h : tendsto a t) {c : ℝ} (hc : 0 < c) : tendsto (λ n, c * a n) (c * t) := begin sorry, end /-- If `a(n)` tends to `t` and `c` is a negative constant then `c * a(n)` tends to `c * t`. -/ theorem tendsto_neg_const_mul {a : ℕ → ℝ} {t : ℝ} (h : tendsto a t) {c : ℝ} (hc : c < 0) : tendsto (λ n, c * a n) (c * t) := begin sorry, end /-- If `a(n)` tends to `t` and `c` is a constant then `c * a(n)` tends to `c * t`. -/ theorem tendsto_const_mul {a : ℕ → ℝ} {t : ℝ} (c : ℝ) (h : tendsto a t) : tendsto (λ n, c * a n) (c * t) := begin sorry, end /-- If `a(n)` tends to `t` and `c` is a constant then `a(n) * c` tends to `t * c`. -/ theorem tendsto_mul_const {a : ℕ → ℝ} {t : ℝ} (c : ℝ) (h : tendsto a t) : tendsto (λ n, a n * c) (t * c) := begin sorry end -- another proof of this result, showcasing some tactics -- which I've not covered yet. theorem tendsto_neg' {a : ℕ → ℝ} {t : ℝ} (ha : tendsto a t) : tendsto (λ n, - a n) (-t) := begin convert tendsto_const_mul (-1) ha, -- read about `convert` on the community web pages { ext, simp }, -- ext is a generic extensionality tactic. Here it's being -- used to deduce that two functions are the same if they take -- the same values everywhere { simp }, end /-- If `a(n)-b(n)` tends to `t` and `b(n)` tends to `u` then `a(n)` tends to `t + u`. -/ theorem tendsto_of_tendsto_sub {a b : ℕ → ℝ} {t u : ℝ} (h1 : tendsto (λ n, a n - b n) t) (h2 : tendsto b u) : tendsto a (t+u) := begin sorry, end /-- If `a(n)` tends to `t` then `a(n)-t` tends to `0`. -/ theorem tendsto_sub_lim {a : ℕ → ℝ} {t : ℝ} (h : tendsto a t) : tendsto (λ n, a n - t) 0 := begin sorry, end /-- If `a(n)` and `b(n)` both tend to zero, then their product tends to zero. -/ theorem tendsto_zero_mul_tendsto_zero {a b : ℕ → ℝ} (ha : tendsto a 0) (hb : tendsto b 0) : tendsto (λ n, a n * b n) 0 := begin sorry, end /-- If `a(n)` tends to `t` and `b(n)` tends to `u` then `a(n)*b(n)` tends to `t*u`. -/ theorem tendsto_mul (a b : ℕ → ℝ) (t u : ℝ) (ha : tendsto a t) (hb : tendsto b u) : tendsto (λ n, a n * b n) (t * u) := begin sorry, end -- something we never used! /-- A sequence has at most one limit. -/ theorem tendsto_unique (a : ℕ → ℝ) (s t : ℝ) (hs : tendsto a s) (ht : tendsto a t) : s = t := begin sorry, end
lemma set_coeffs_subset_singleton_0_iff [simp]: "set (coeffs p) \<subseteq> {0} \<longleftrightarrow> p = 0"
Formal statement is: lemma Sup_lexord_rel: assumes "\<And>i. i \<in> I \<Longrightarrow> k (A i) = k (B i)" "R (c (A ` {a \<in> I. k (B a) = (SUP x\<in>I. k (B x))})) (c (B ` {a \<in> I. k (B a) = (SUP x\<in>I. k (B x))}))" "R (s (A`I)) (s (B`I))" shows "R (Sup_lexord k c s (A`I)) (Sup_lexord k c s (B`I))" Informal statement is: If $k(A_i) = k(B_i)$ for all $i$, and $R(c(A_i))$ and $R(c(B_i))$ for all $i$ such that $k(B_i) = \sup_i k(B_i)$, and $R(s(A_i))$ and $R(s(B_i))$ for all $i$, then $R(\sup_i A_i)$ and $R(\sup_i B_i)$.
The measure of any set with respect to the null measure is zero.
[STATEMENT] lemma hcis_zero [simp]: "hcis 0 = 1" [PROOF STATE] proof (prove) goal (1 subgoal): 1. hcis 0 = 1 [PROOF STEP] by transfer (rule cis_zero)
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen ! This file was ported from Lean 3 source module data.int.associated ! leanprover-community/mathlib commit c3291da49cfa65f0d43b094750541c0731edc932 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Algebra.Associated import Mathbin.Data.Int.Units /-! # Associated elements and the integers > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains some results on equality up to units in the integers. ## Main results * `int.nat_abs_eq_iff_associated`: the absolute value is equal iff integers are associated -/ /- warning: int.nat_abs_eq_iff_associated -> Int.natAbs_eq_iff_associated is a dubious translation: lean 3 declaration is forall {a : Int} {b : Int}, Iff (Eq.{1} Nat (Int.natAbs a) (Int.natAbs b)) (Associated.{0} Int Int.monoid a b) but is expected to have type forall {a : Int} {b : Int}, Iff (Eq.{1} Nat (Int.natAbs a) (Int.natAbs b)) (Associated.{0} Int Int.instMonoidInt a b) Case conversion may be inaccurate. Consider using '#align int.nat_abs_eq_iff_associated Int.natAbs_eq_iff_associatedₓ'. -/ theorem Int.natAbs_eq_iff_associated {a b : ℤ} : a.natAbs = b.natAbs ↔ Associated a b := by refine' int.nat_abs_eq_nat_abs_iff.trans _ constructor · rintro (rfl | rfl) · rfl · exact ⟨-1, by simp⟩ · rintro ⟨u, rfl⟩ obtain rfl | rfl := Int.units_eq_one_or u · exact Or.inl (by simp) · exact Or.inr (by simp) #align int.nat_abs_eq_iff_associated Int.natAbs_eq_iff_associated
syntax "foo" !"(" term:max : term macro_rules | `(foo $x) => `($x + 1) syntax "foo" "(" term ")" : term macro_rules | `(foo ( $x )) => `($x + 2) #check foo 10 #check foo(10) theorem ex1 : foo 10 = 11 := rfl theorem ex2 : foo (10) = 12 := rfl
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import topology.algebra.uniform_convergence /-! # Algebra-related equicontinuity criterions -/ open function open_locale uniform_convergence @[to_additive] lemma equicontinuous_of_equicontinuous_at_one {ι G M hom : Type*} [topological_space G] [uniform_space M] [group G] [group M] [topological_group G] [uniform_group M] [monoid_hom_class hom G M] (F : ι → hom) (hf : equicontinuous_at (coe_fn ∘ F) (1 : G)) : equicontinuous (coe_fn ∘ F) := begin letI : has_coe_to_fun hom (λ _, G → M) := fun_like.has_coe_to_fun, rw equicontinuous_iff_continuous, rw equicontinuous_at_iff_continuous_at at hf, let φ : G →* (ι → M) := { to_fun := swap (coe_fn ∘ F), map_one' := by ext; exact map_one _, map_mul' := λ a b, by ext; exact map_mul _ _ _ }, exact continuous_of_continuous_at_one φ hf end @[to_additive] lemma uniform_equicontinuous_of_equicontinuous_at_one {ι G M hom : Type*} [uniform_space G] [uniform_space M] [group G] [group M] [uniform_group G] [uniform_group M] [monoid_hom_class hom G M] (F : ι → hom) (hf : equicontinuous_at (coe_fn ∘ F) (1 : G)) : uniform_equicontinuous (coe_fn ∘ F) := begin letI : has_coe_to_fun hom (λ _, G → M) := fun_like.has_coe_to_fun, rw uniform_equicontinuous_iff_uniform_continuous, rw equicontinuous_at_iff_continuous_at at hf, let φ : G →* (ι → M) := { to_fun := swap (coe_fn ∘ F), map_one' := by ext; exact map_one _, map_mul' := λ a b, by ext; exact map_mul _ _ _ }, exact uniform_continuous_of_continuous_at_one φ hf end
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark ! This file was ported from Lean 3 source module linear_algebra.matrix.charpoly.finite_field ! leanprover-community/mathlib commit b95b8c7a484a298228805c72c142f6b062eb0d70 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.LinearAlgebra.Matrix.Charpoly.Coeff import Mathbin.FieldTheory.Finite.Basic import Mathbin.Data.Matrix.CharP /-! # Results on characteristic polynomials and traces over finite fields. -/ noncomputable section open Polynomial Matrix open Polynomial variable {n : Type _} [DecidableEq n] [Fintype n] @[simp] theorem FiniteField.Matrix.charpoly_pow_card {K : Type _} [Field K] [Fintype K] (M : Matrix n n K) : (M ^ Fintype.card K).charpoly = M.charpoly := by cases (isEmpty_or_nonempty n).symm · cases' CharP.exists K with p hp letI := hp rcases FiniteField.card K p with ⟨⟨k, kpos⟩, ⟨hp, hk⟩⟩ haveI : Fact p.prime := ⟨hp⟩ dsimp at hk rw [hk] at * apply (frobenius_inj K[X] p).iterate k repeat' rw [iterate_frobenius]; rw [← hk] rw [← FiniteField.expand_card] unfold charpoly rw [AlgHom.map_det, ← coe_det_monoid_hom, ← (det_monoid_hom : Matrix n n K[X] →* K[X]).map_pow] apply congr_arg det refine' mat_poly_equiv.injective _ rw [AlgEquiv.map_pow, matPolyEquiv_charmatrix, hk, sub_pow_char_pow_of_commute, ← C_pow] · exact (id (matPolyEquiv_eq_x_pow_sub_c (p ^ k) M) : _) · exact (C M).commute_X · exact congr_arg _ (Subsingleton.elim _ _) #align finite_field.matrix.charpoly_pow_card FiniteField.Matrix.charpoly_pow_card @[simp] theorem ZMod.charpoly_pow_card {p : ℕ} [Fact p.Prime] (M : Matrix n n (ZMod p)) : (M ^ p).charpoly = M.charpoly := by have h := FiniteField.Matrix.charpoly_pow_card M rwa [ZMod.card] at h #align zmod.charpoly_pow_card ZMod.charpoly_pow_card theorem FiniteField.trace_pow_card {K : Type _} [Field K] [Fintype K] (M : Matrix n n K) : trace (M ^ Fintype.card K) = trace M ^ Fintype.card K := by cases isEmpty_or_nonempty n · simp [zero_pow Fintype.card_pos, Matrix.trace] rw [Matrix.trace_eq_neg_charpoly_coeff, Matrix.trace_eq_neg_charpoly_coeff, FiniteField.Matrix.charpoly_pow_card, FiniteField.pow_card] #align finite_field.trace_pow_card FiniteField.trace_pow_card theorem ZMod.trace_pow_card {p : ℕ} [Fact p.Prime] (M : Matrix n n (ZMod p)) : trace (M ^ p) = trace M ^ p := by have h := FiniteField.trace_pow_card M rwa [ZMod.card] at h #align zmod.trace_pow_card ZMod.trace_pow_card
structure A where x : Nat w : Nat structure B extends A where y : Nat structure C extends B where z : Nat def f1 (c : C) (a : A) : C := { c with toA := a, x := 0 } -- Error, `toA` and `x` are both updates to field `x` def f2 (c : C) (a : A) : C := { c with toA := a } def f3 (c : C) (a : A) : C := { a, c with x := 0 } theorem ex1 (a : A) (c : C) : (f3 c a).x = 0 := rfl theorem ex2 (a : A) (c : C) : (f3 c a).w = a.w := rfl def f4 (c : C) (a : A) : C := { c, a with x := 0 } -- TODO: generate error that `a` was not used? theorem ex3 (a : A) (c : C) : (f4 c a).w = c.w := rfl theorem ex4 (a : A) (c : C) : (f4 c a).x = 0 := rfl def f5 (c : C) (a : A) := { c, a with x := 0 } -- Error
lemma fold_coeffs_0_eq [simp]: "fold_coeffs f 0 = id"
State Before: p : ℕ G : Type u_1 inst✝ : Group G P : Subgroup G hP : IsPGroup p { x // x ∈ P } c : Set (Subgroup G) hc1 : c ⊆ {Q | IsPGroup p { x // x ∈ Q }} hc2 : IsChain (fun x x_1 => x ≤ x_1) c Q : Subgroup G hQ : Q ∈ c x✝ : { x // x ∈ { toSubmonoid := { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }, inv_mem' := (_ : ∀ {g : G}, g ∈ { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }.toSubsemigroup.carrier → g⁻¹ ∈ { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }.toSubsemigroup.carrier) } } g : G S : ↑c hg : g ∈ (fun R => ↑↑R) S ⊢ ∃ k, { val := g, property := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ g ∈ t) } ^ p ^ k = 1 State After: p : ℕ G : Type u_1 inst✝ : Group G P : Subgroup G hP : IsPGroup p { x // x ∈ P } c : Set (Subgroup G) hc1 : c ⊆ {Q | IsPGroup p { x // x ∈ Q }} hc2 : IsChain (fun x x_1 => x ≤ x_1) c Q : Subgroup G hQ : Q ∈ c x✝ : { x // x ∈ { toSubmonoid := { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }, inv_mem' := (_ : ∀ {g : G}, g ∈ { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }.toSubsemigroup.carrier → g⁻¹ ∈ { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }.toSubsemigroup.carrier) } } g : G S : ↑c hg : g ∈ (fun R => ↑↑R) S k : ℕ hk : { val := g, property := hg } ^ p ^ k = 1 ⊢ { val := g, property := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ g ∈ t) } ^ p ^ k = 1 Tactic: refine' Exists.imp (fun k hk => _) (hc1 S.2 ⟨g, hg⟩) State Before: p : ℕ G : Type u_1 inst✝ : Group G P : Subgroup G hP : IsPGroup p { x // x ∈ P } c : Set (Subgroup G) hc1 : c ⊆ {Q | IsPGroup p { x // x ∈ Q }} hc2 : IsChain (fun x x_1 => x ≤ x_1) c Q : Subgroup G hQ : Q ∈ c x✝ : { x // x ∈ { toSubmonoid := { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }, inv_mem' := (_ : ∀ {g : G}, g ∈ { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }.toSubsemigroup.carrier → g⁻¹ ∈ { toSubsemigroup := { carrier := ⋃ (R : ↑c), ↑↑R, mul_mem' := (_ : ∀ {g : G} (h : G), (g ∈ ⋃ (R : ↑c), ↑↑R) → (h ∈ ⋃ (R : ↑c), ↑↑R) → g * h ∈ ⋃ (R : ↑c), ↑↑R) }, one_mem' := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ 1 ∈ t) }.toSubsemigroup.carrier) } } g : G S : ↑c hg : g ∈ (fun R => ↑↑R) S k : ℕ hk : { val := g, property := hg } ^ p ^ k = 1 ⊢ { val := g, property := (_ : ∃ t, (t ∈ Set.range fun R => ↑↑R) ∧ g ∈ t) } ^ p ^ k = 1 State After: no goals Tactic: rwa [Subtype.ext_iff, coe_pow] at hk⊢
Air Miles Canada says it won’t reimburse collectors who spent their points in anticipation of an expiration policy that will no longer take effect at the end of the year. The company that runs the Air Miles loyalty points program, LoyaltyOne, announced Thursday it was cancelling plans that would have seen collectors lose miles older than five years. While some celebrated the news, others — who had scrambled to redeem their miles ahead of the expiry — were angered by the about face. Air Miles Canada’s Twitter account told two customers the company would not be reimbursing collectors who spent their points to avoid having them expire. The account sent tweets saying the company would not accept returns, cancellations or exchanges due to the cancellation of the expiry policy, once booked.
[GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p q : Submodule R M src✝ : AddSubmonoid M := ⊥ ⊢ ∀ (c : R) {x : M}, x ∈ { toAddSubsemigroup := { carrier := {0}, add_mem' := (_ : ∀ {a b : M}, a ∈ src✝.carrier → b ∈ src✝.carrier → a + b ∈ src✝.carrier) }, zero_mem' := (_ : 0 ∈ src✝.carrier) }.toAddSubsemigroup.carrier → c • x ∈ { toAddSubsemigroup := { carrier := {0}, add_mem' := (_ : ∀ {a b : M}, a ∈ src✝.carrier → b ∈ src✝.carrier → a + b ∈ src✝.carrier) }, zero_mem' := (_ : 0 ∈ src✝.carrier) }.toAddSubsemigroup.carrier [PROOFSTEP] simp [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q p : Submodule R M ⊢ restrictScalars S p = ⊥ ↔ p = ⊥ [PROOFSTEP] simp [SetLike.ext_iff] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q p : Submodule R M x : M ⊢ x ∈ ⊥ → x ∈ p [PROOFSTEP] simp (config := { contextual := true }) [zero_mem] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p q : Submodule R M x y : { x // x ∈ ⊥ } ⊢ x = y [PROOFSTEP] rcases x with ⟨x, xm⟩ [GOAL] case mk R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p q : Submodule R M y : { x // x ∈ ⊥ } x : M xm : x ∈ ⊥ ⊢ { val := x, property := xm } = y [PROOFSTEP] rcases y with ⟨y, ym⟩ [GOAL] case mk.mk R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p q : Submodule R M x : M xm : x ∈ ⊥ y : M ym : y ∈ ⊥ ⊢ { val := x, property := xm } = { val := y, property := ym } [PROOFSTEP] congr [GOAL] case mk.mk.e_val R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p q : Submodule R M x : M xm : x ∈ ⊥ y : M ym : y ∈ ⊥ ⊢ x = y [PROOFSTEP] rw [(Submodule.eq_bot_iff _).mp rfl x xm] [GOAL] case mk.mk.e_val R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p q : Submodule R M x : M xm : x ∈ ⊥ y : M ym : y ∈ ⊥ ⊢ 0 = y [PROOFSTEP] rw [(Submodule.eq_bot_iff _).mp rfl y ym] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q p : Submodule R M ⊢ p ≠ ⊥ ↔ ∃ x, x ∈ p ∧ x ≠ 0 [PROOFSTEP] simp only [ne_eq, p.eq_bot_iff, not_forall, exists_prop] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁷ : Semiring R inst✝⁶ : Semiring S inst✝⁵ : AddCommMonoid M inst✝⁴ : Module R M inst✝³ : Module S M inst✝² : SMul S R inst✝¹ : IsScalarTower S R M p✝ q p : Submodule R M inst✝ : Subsingleton { x // x ∈ p } ⊢ p = ⊥ [PROOFSTEP] rw [eq_bot_iff] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁷ : Semiring R inst✝⁶ : Semiring S inst✝⁵ : AddCommMonoid M inst✝⁴ : Module R M inst✝³ : Module S M inst✝² : SMul S R inst✝¹ : IsScalarTower S R M p✝ q p : Submodule R M inst✝ : Subsingleton { x // x ∈ p } ⊢ p ≤ ⊥ [PROOFSTEP] intro v hv [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁷ : Semiring R inst✝⁶ : Semiring S inst✝⁵ : AddCommMonoid M inst✝⁴ : Module R M inst✝³ : Module S M inst✝² : SMul S R inst✝¹ : IsScalarTower S R M p✝ q p : Submodule R M inst✝ : Subsingleton { x // x ∈ p } v : M hv : v ∈ p ⊢ v ∈ ⊥ [PROOFSTEP] exact congr_arg Subtype.val (Subsingleton.elim (⟨v, hv⟩ : p) 0) [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q p : Submodule R M ⊢ restrictScalars S p = ⊤ ↔ p = ⊤ [PROOFSTEP] simp [SetLike.ext_iff] [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q : Submodule R M S : Set (Submodule R M) ⊢ ∀ {a b : M}, a ∈ ⋂ (s : Submodule R M) (_ : s ∈ S), ↑s → b ∈ ⋂ (s : Submodule R M) (_ : s ∈ S), ↑s → a + b ∈ ⋂ (s : Submodule R M) (_ : s ∈ S), ↑s [PROOFSTEP] simp (config := { contextual := true }) [add_mem] [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q : Submodule R M S : Set (Submodule R M) ⊢ 0 ∈ { carrier := ⋂ (s : Submodule R M) (_ : s ∈ S), ↑s, add_mem' := (_ : ∀ (a a_1 : M), a ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i → a_1 ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i → a + a_1 ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i) }.carrier [PROOFSTEP] simp [zero_mem] [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q : Submodule R M S : Set (Submodule R M) ⊢ ∀ (c : R) {x : M}, x ∈ { toAddSubsemigroup := { carrier := ⋂ (s : Submodule R M) (_ : s ∈ S), ↑s, add_mem' := (_ : ∀ (a a_1 : M), a ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i → a_1 ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i → a + a_1 ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i) }, zero_mem' := (_ : 0 ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i) }.toAddSubsemigroup.carrier → c • x ∈ { toAddSubsemigroup := { carrier := ⋂ (s : Submodule R M) (_ : s ∈ S), ↑s, add_mem' := (_ : ∀ (a a_1 : M), a ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i → a_1 ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i → a + a_1 ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i) }, zero_mem' := (_ : 0 ∈ ⋂ (i : Submodule R M) (_ : i ∈ S), ↑i) }.toAddSubsemigroup.carrier [PROOFSTEP] simp (config := { contextual := true }) [smul_mem] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q✝ p q : Submodule R M ⊢ ∀ {a b : M}, a ∈ ↑p ∩ ↑q → b ∈ ↑p ∩ ↑q → a + b ∈ ↑p ∩ ↑q [PROOFSTEP] simp (config := { contextual := true }) [add_mem] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q✝ p q : Submodule R M ⊢ 0 ∈ { carrier := ↑p ∩ ↑q, add_mem' := (_ : ∀ (a a_1 : M), a ∈ ↑p ∩ ↑q → a_1 ∈ ↑p ∩ ↑q → a + a_1 ∈ ↑p ∩ ↑q) }.carrier [PROOFSTEP] simp [zero_mem] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q✝ p q : Submodule R M ⊢ ∀ (c : R) {x : M}, x ∈ { toAddSubsemigroup := { carrier := ↑p ∩ ↑q, add_mem' := (_ : ∀ (a a_1 : M), a ∈ ↑p ∩ ↑q → a_1 ∈ ↑p ∩ ↑q → a + a_1 ∈ ↑p ∩ ↑q) }, zero_mem' := (_ : 0 ∈ ↑p ∩ ↑q) }.toAddSubsemigroup.carrier → c • x ∈ { toAddSubsemigroup := { carrier := ↑p ∩ ↑q, add_mem' := (_ : ∀ (a a_1 : M), a ∈ ↑p ∩ ↑q → a_1 ∈ ↑p ∩ ↑q → a + a_1 ∈ ↑p ∩ ↑q) }, zero_mem' := (_ : 0 ∈ ↑p ∩ ↑q) }.toAddSubsemigroup.carrier [PROOFSTEP] simp (config := { contextual := true }) [smul_mem] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p q : Submodule R M src✝¹ : OrderTop (Submodule R M) := inferInstance src✝ : OrderBot (Submodule R M) := inferInstance x✝² : Set (Submodule R M) x✝¹ : Submodule R M hs : x✝¹ ∈ x✝² x✝ : Submodule R M hq : x✝ ∈ fun x => ∀ (b : Submodule R M), b ∈ x✝² → b ≤ x ⊢ x✝¹ ≤ x✝ [PROOFSTEP] exact hq _ hs [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Type u_4 s : Finset ι p : ι → Submodule R M ⊢ ↑(Finset.inf s p) = ⋂ (i : ι) (_ : i ∈ s), ↑(p i) [PROOFSTEP] letI := Classical.decEq ι [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Type u_4 s : Finset ι p : ι → Submodule R M this : DecidableEq ι := Classical.decEq ι ⊢ ↑(Finset.inf s p) = ⋂ (i : ι) (_ : i ∈ s), ↑(p i) [PROOFSTEP] refine' s.induction_on _ fun i s _ ih ↦ _ [GOAL] case refine'_1 R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Type u_4 s : Finset ι p : ι → Submodule R M this : DecidableEq ι := Classical.decEq ι ⊢ ↑(Finset.inf ∅ p) = ⋂ (i : ι) (_ : i ∈ ∅), ↑(p i) [PROOFSTEP] simp [GOAL] case refine'_2 R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Type u_4 s✝ : Finset ι p : ι → Submodule R M this : DecidableEq ι := Classical.decEq ι i : ι s : Finset ι x✝ : ¬i ∈ s ih : ↑(Finset.inf s p) = ⋂ (i : ι) (_ : i ∈ s), ↑(p i) ⊢ ↑(Finset.inf (insert i s) p) = ⋂ (i_1 : ι) (_ : i_1 ∈ insert i s), ↑(p i_1) [PROOFSTEP] rw [Finset.inf_insert, inf_coe, ih] [GOAL] case refine'_2 R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Type u_4 s✝ : Finset ι p : ι → Submodule R M this : DecidableEq ι := Classical.decEq ι i : ι s : Finset ι x✝ : ¬i ∈ s ih : ↑(Finset.inf s p) = ⋂ (i : ι) (_ : i ∈ s), ↑(p i) ⊢ ↑(p i) ∩ ⋂ (i : ι) (_ : i ∈ s), ↑(p i) = ⋂ (i_1 : ι) (_ : i_1 ∈ insert i s), ↑(p i_1) [PROOFSTEP] simp [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Sort u_4 p : ι → Submodule R M ⊢ ↑(⨅ (i : ι), p i) = ⋂ (i : ι), ↑(p i) [PROOFSTEP] rw [iInf, sInf_coe] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Sort u_4 p : ι → Submodule R M ⊢ ⋂ (p_1 : Submodule R M) (_ : p_1 ∈ Set.range fun i => p i), ↑p_1 = ⋂ (i : ι), ↑(p i) [PROOFSTEP] simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq'] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Sort u_4 p : ι → Submodule R M x : M ⊢ x ∈ ⨅ (i : ι), p i ↔ ∀ (i : ι), x ∈ p i [PROOFSTEP] rw [← SetLike.mem_coe, iInf_coe, Set.mem_iInter] [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Sort u_4 p : ι → Submodule R M x : M ⊢ (∀ (i : ι), x ∈ ↑(p i)) ↔ ∀ (i : ι), x ∈ p i [PROOFSTEP] rfl [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q : Submodule R M ι : Type u_4 s : Finset ι p : ι → Submodule R M x : M ⊢ x ∈ Finset.inf s p ↔ ∀ (i : ι), i ∈ s → x ∈ p i [PROOFSTEP] simp only [← SetLike.mem_coe, finset_inf_coe, Set.mem_iInter] [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q S T : Submodule R M ⊢ ∀ {x : M}, x ∈ S → x ∈ S ⊔ T [PROOFSTEP] have : S ≤ S ⊔ T := le_sup_left [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q S T : Submodule R M this : S ≤ S ⊔ T ⊢ ∀ {x : M}, x ∈ S → x ∈ S ⊔ T [PROOFSTEP] rw [LE.le] at this [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q S T : Submodule R M this : Preorder.toLE.1 S (S ⊔ T) ⊢ ∀ {x : M}, x ∈ S → x ∈ S ⊔ T [PROOFSTEP] exact this [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q S T : Submodule R M ⊢ ∀ {x : M}, x ∈ T → x ∈ S ⊔ T [PROOFSTEP] have : T ≤ S ⊔ T := le_sup_right [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q S T : Submodule R M this : T ≤ S ⊔ T ⊢ ∀ {x : M}, x ∈ T → x ∈ S ⊔ T [PROOFSTEP] rw [LE.le] at this [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q S T : Submodule R M this : Preorder.toLE.1 T (S ⊔ T) ⊢ ∀ {x : M}, x ∈ T → x ∈ S ⊔ T [PROOFSTEP] exact this [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁹ : Semiring R inst✝⁸ : Semiring S✝ inst✝⁷ : AddCommMonoid M inst✝⁶ : Module R M inst✝⁵ : Module S✝ M inst✝⁴ : SMul S✝ R inst✝³ : IsScalarTower S✝ R M p q : Submodule R M R' : Type u_4 M' : Type u_5 inst✝² : Ring R' inst✝¹ : AddCommGroup M' inst✝ : Module R' M' S T : Submodule R' M' s t : M' hs : s ∈ S ht : t ∈ T ⊢ s - t ∈ S ⊔ T [PROOFSTEP] rw [sub_eq_add_neg] [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁹ : Semiring R inst✝⁸ : Semiring S✝ inst✝⁷ : AddCommMonoid M inst✝⁶ : Module R M inst✝⁵ : Module S✝ M inst✝⁴ : SMul S✝ R inst✝³ : IsScalarTower S✝ R M p q : Submodule R M R' : Type u_4 M' : Type u_5 inst✝² : Ring R' inst✝¹ : AddCommGroup M' inst✝ : Module R' M' S T : Submodule R' M' s t : M' hs : s ∈ S ht : t ∈ T ⊢ s + -t ∈ S ⊔ T [PROOFSTEP] exact add_mem_sup hs (neg_mem ht) [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q : Submodule R M S : Set (Submodule R M) s : Submodule R M hs : s ∈ S ⊢ ∀ {x : M}, x ∈ s → x ∈ sSup S [PROOFSTEP] have := le_sSup hs [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q : Submodule R M S : Set (Submodule R M) s : Submodule R M hs : s ∈ S this : s ≤ sSup S ⊢ ∀ {x : M}, x ∈ s → x ∈ sSup S [PROOFSTEP] rw [LE.le] at this [GOAL] R : Type u_1 S✝ : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S✝ inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S✝ M inst✝¹ : SMul S✝ R inst✝ : IsScalarTower S✝ R M p q : Submodule R M S : Set (Submodule R M) s : Submodule R M hs : s ∈ S this : Preorder.toLE.1 s (sSup S) ⊢ ∀ {x : M}, x ∈ s → x ∈ sSup S [PROOFSTEP] exact this [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p✝ q p p' : Submodule R M ⊢ (∀ (x : M), x ∈ p ∧ x ∈ p' → x ∈ {0}) ↔ ∀ (x : M), x ∈ p → x ∈ p' → x = 0 [PROOFSTEP] simp [GOAL] R : Type u_1 S : Type u_2 M : Type u_3 inst✝⁶ : Semiring R inst✝⁵ : Semiring S inst✝⁴ : AddCommMonoid M inst✝³ : Module R M inst✝² : Module S M inst✝¹ : SMul S R inst✝ : IsScalarTower S R M p q : Submodule R M hpq : Disjoint p q a : { x // x ∈ p } ha : ↑a ∈ q ⊢ a = 0 [PROOFSTEP] exact_mod_cast disjoint_def.mp hpq a (coe_mem a) ha
State Before: x : ℝ≥0 ⊢ ↑(⊤ * ↑x) = ⊤ * ↑↑x State After: case inl ⊢ ↑(⊤ * ↑0) = ⊤ * ↑↑0 case inr x : ℝ≥0 h0 : x ≠ 0 ⊢ ↑(⊤ * ↑x) = ⊤ * ↑↑x Tactic: rcases eq_or_ne x 0 with (rfl | h0) State Before: case inl ⊢ ↑(⊤ * ↑0) = ⊤ * ↑↑0 State After: no goals Tactic: simp State Before: case inr x : ℝ≥0 h0 : x ≠ 0 ⊢ ↑(⊤ * ↑x) = ⊤ * ↑↑x State After: case inr x : ℝ≥0 h0 : x ≠ 0 ⊢ ↑⊤ = ⊤ * ↑↑x Tactic: rw [ENNReal.top_mul (ENNReal.coe_ne_zero.2 h0)] State Before: case inr x : ℝ≥0 h0 : x ≠ 0 ⊢ ↑⊤ = ⊤ * ↑↑x State After: no goals Tactic: exact Eq.symm <| if_pos <| NNReal.coe_pos.2 h0.bot_lt
""" ---yaml title: Setup author: Jonah E Havel ... """ using FileIO, Flux, Metalhead, Pages using Metalhead: classify ### # TEST_IMG = "" vgg = VGG19() img = load(TEST_IMG) ### classify(vgg, img) ### using Metalhead download(CIFAR10) ###
lemma sphere_trivial [simp]: "sphere x 0 = {x}"
/- Copyright (c) 2020 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Devon Tuma ! This file was ported from Lean 3 source module ring_theory.jacobson ! leanprover-community/mathlib commit 6ca1a09bc9aa75824bf97388c9e3b441fc4ccf3f ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.RingTheory.Localization.Away import Mathbin.RingTheory.Ideal.Over import Mathbin.RingTheory.JacobsonIdeal /-! # Jacobson Rings The following conditions are equivalent for a ring `R`: 1. Every radical ideal `I` is equal to its Jacobson radical 2. Every radical ideal `I` can be written as an intersection of maximal ideals 3. Every prime ideal `I` is equal to its Jacobson radical Any ring satisfying any of these equivalent conditions is said to be Jacobson. Some particular examples of Jacobson rings are also proven. `is_jacobson_quotient` says that the quotient of a Jacobson ring is Jacobson. `is_jacobson_localization` says the localization of a Jacobson ring to a single element is Jacobson. `is_jacobson_polynomial_iff_is_jacobson` says polynomials over a Jacobson ring form a Jacobson ring. ## Main definitions Let `R` be a commutative ring. Jacobson Rings are defined using the first of the above conditions * `is_jacobson R` is the proposition that `R` is a Jacobson ring. It is a class, implemented as the predicate that for any ideal, `I.is_radical` implies `I.jacobson = I`. ## Main statements * `is_jacobson_iff_prime_eq` is the equivalence between conditions 1 and 3 above. * `is_jacobson_iff_Inf_maximal` is the equivalence between conditions 1 and 2 above. * `is_jacobson_of_surjective` says that if `R` is a Jacobson ring and `f : R →+* S` is surjective, then `S` is also a Jacobson ring * `is_jacobson_mv_polynomial` says that multi-variate polynomials over a Jacobson ring are Jacobson. ## Tags Jacobson, Jacobson Ring -/ namespace Ideal open Polynomial open Polynomial section IsJacobson variable {R S : Type _} [CommRing R] [CommRing S] {I : Ideal R} /-- A ring is a Jacobson ring if for every radical ideal `I`, the Jacobson radical of `I` is equal to `I`. See `is_jacobson_iff_prime_eq` and `is_jacobson_iff_Inf_maximal` for equivalent definitions. -/ class IsJacobson (R : Type _) [CommRing R] : Prop where out' : ∀ I : Ideal R, I.IsRadical → I.jacobson = I #align ideal.is_jacobson Ideal.IsJacobson theorem isJacobson_iff {R} [CommRing R] : IsJacobson R ↔ ∀ I : Ideal R, I.IsRadical → I.jacobson = I := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align ideal.is_jacobson_iff Ideal.isJacobson_iff theorem IsJacobson.out {R} [CommRing R] : IsJacobson R → ∀ {I : Ideal R}, I.IsRadical → I.jacobson = I := isJacobson_iff.1 #align ideal.is_jacobson.out Ideal.IsJacobson.out /-- A ring is a Jacobson ring if and only if for all prime ideals `P`, the Jacobson radical of `P` is equal to `P`. -/ theorem isJacobson_iff_prime_eq : IsJacobson R ↔ ∀ P : Ideal R, IsPrime P → P.jacobson = P := by refine' is_jacobson_iff.trans ⟨fun h I hI => h I hI.IsRadical, _⟩ refine' fun h I hI => le_antisymm (fun x hx => _) fun x hx => mem_Inf.mpr fun _ hJ => hJ.left hx rw [← hI.radical, radical_eq_Inf I, mem_Inf] intro P hP rw [Set.mem_setOf_eq] at hP erw [mem_Inf] at hx erw [← h P hP.right, mem_Inf] exact fun J hJ => hx ⟨le_trans hP.left hJ.left, hJ.right⟩ #align ideal.is_jacobson_iff_prime_eq Ideal.isJacobson_iff_prime_eq /-- A ring `R` is Jacobson if and only if for every prime ideal `I`, `I` can be written as the infimum of some collection of maximal ideals. Allowing ⊤ in the set `M` of maximal ideals is equivalent, but makes some proofs cleaner. -/ theorem isJacobson_iff_infₛ_maximal : IsJacobson R ↔ ∀ {I : Ideal R}, I.IsPrime → ∃ M : Set (Ideal R), (∀ J ∈ M, IsMaximal J ∨ J = ⊤) ∧ I = infₛ M := ⟨fun H I h => eq_jacobson_iff_infₛ_maximal.1 (H.out h.IsRadical), fun H => isJacobson_iff_prime_eq.2 fun P hP => eq_jacobson_iff_infₛ_maximal.2 (H hP)⟩ #align ideal.is_jacobson_iff_Inf_maximal Ideal.isJacobson_iff_infₛ_maximal theorem isJacobson_iff_infₛ_maximal' : IsJacobson R ↔ ∀ {I : Ideal R}, I.IsPrime → ∃ M : Set (Ideal R), (∀ J ∈ M, ∀ (K : Ideal R), J < K → K = ⊤) ∧ I = infₛ M := ⟨fun H I h => eq_jacobson_iff_infₛ_maximal'.1 (H.out h.IsRadical), fun H => isJacobson_iff_prime_eq.2 fun P hP => eq_jacobson_iff_infₛ_maximal'.2 (H hP)⟩ #align ideal.is_jacobson_iff_Inf_maximal' Ideal.isJacobson_iff_infₛ_maximal' theorem radical_eq_jacobson [H : IsJacobson R] (I : Ideal R) : I.radical = I.jacobson := le_antisymm (le_infₛ fun J ⟨hJ, hJ_max⟩ => (IsPrime.radical_le_iff hJ_max.IsPrime).mpr hJ) (H.out (radical_isRadical I) ▸ jacobson_mono le_radical) #align ideal.radical_eq_jacobson Ideal.radical_eq_jacobson /-- Fields have only two ideals, and the condition holds for both of them. -/ instance (priority := 100) isJacobson_field {K : Type _} [Field K] : IsJacobson K := ⟨fun I hI => Or.rec_on (eq_bot_or_top I) (fun h => le_antisymm (infₛ_le ⟨le_rfl, h.symm ▸ bot_isMaximal⟩) (h.symm ▸ bot_le)) fun h => by rw [h, jacobson_eq_top_iff]⟩ #align ideal.is_jacobson_field Ideal.isJacobson_field theorem isJacobson_of_surjective [H : IsJacobson R] : (∃ f : R →+* S, Function.Surjective f) → IsJacobson S := by rintro ⟨f, hf⟩ rw [is_jacobson_iff_Inf_maximal] intro p hp use map f '' { J : Ideal R | comap f p ≤ J ∧ J.IsMaximal } use fun j ⟨J, hJ, hmap⟩ => hmap ▸ (map_eq_top_or_is_maximal_of_surjective f hf hJ.right).symm have : p = map f (comap f p).jacobson := (is_jacobson.out' _ <| hp.is_radical.comap f).symm ▸ (map_comap_of_surjective f hf p).symm exact this.trans (map_Inf hf fun J ⟨hJ, _⟩ => le_trans (Ideal.ker_le_comap f) hJ) #align ideal.is_jacobson_of_surjective Ideal.isJacobson_of_surjective instance (priority := 100) isJacobson_quotient [IsJacobson R] : IsJacobson (R ⧸ I) := isJacobson_of_surjective ⟨Quotient.mk I, by rintro ⟨x⟩ <;> use x <;> rfl⟩ #align ideal.is_jacobson_quotient Ideal.isJacobson_quotient theorem isJacobson_iso (e : R ≃+* S) : IsJacobson R ↔ IsJacobson S := ⟨fun h => @isJacobson_of_surjective _ _ _ _ h ⟨(e : R →+* S), e.Surjective⟩, fun h => @isJacobson_of_surjective _ _ _ _ h ⟨(e.symm : S →+* R), e.symm.Surjective⟩⟩ #align ideal.is_jacobson_iso Ideal.isJacobson_iso theorem isJacobson_of_isIntegral [Algebra R S] (hRS : Algebra.IsIntegral R S) (hR : IsJacobson R) : IsJacobson S := by rw [is_jacobson_iff_prime_eq] intro P hP by_cases hP_top : comap (algebraMap R S) P = ⊤ · simp [comap_eq_top_iff.1 hP_top] · haveI : Nontrivial (R ⧸ comap (algebraMap R S) P) := quotient.nontrivial hP_top rw [jacobson_eq_iff_jacobson_quotient_eq_bot] refine' eq_bot_of_comap_eq_bot (isIntegral_quotient_of_isIntegral hRS) _ rw [eq_bot_iff, ← jacobson_eq_iff_jacobson_quotient_eq_bot.1 ((is_jacobson_iff_prime_eq.1 hR) (comap (algebraMap R S) P) (comap_is_prime _ _)), comap_jacobson] refine' infₛ_le_infₛ fun J hJ => _ simp only [true_and_iff, Set.mem_image, bot_le, Set.mem_setOf_eq] have : J.is_maximal := by simpa using hJ exact exists_ideal_over_maximal_of_is_integral (isIntegral_quotient_of_isIntegral hRS) J (comap_bot_le_of_injective _ algebra_map_quotient_injective) #align ideal.is_jacobson_of_is_integral Ideal.isJacobson_of_isIntegral theorem isJacobson_of_is_integral' (f : R →+* S) (hf : f.IsIntegral) (hR : IsJacobson R) : IsJacobson S := @isJacobson_of_isIntegral _ _ _ _ f.toAlgebra hf hR #align ideal.is_jacobson_of_is_integral' Ideal.isJacobson_of_is_integral' end IsJacobson section Localization open IsLocalization Submonoid variable {R S : Type _} [CommRing R] [CommRing S] {I : Ideal R} variable (y : R) [Algebra R S] [IsLocalization.Away y S] theorem disjoint_powers_iff_not_mem (hI : I.IsRadical) : Disjoint (Submonoid.powers y : Set R) ↑I ↔ y ∉ I.1 := by refine' ⟨fun h => Set.disjoint_left.1 h (mem_powers _), fun h => disjoint_iff.mpr (eq_bot_iff.mpr _)⟩ rintro x ⟨⟨n, rfl⟩, hx'⟩ exact h (hI <| mem_radical_of_pow_mem <| le_radical hx') #align ideal.disjoint_powers_iff_not_mem Ideal.disjoint_powers_iff_not_mem variable (S) /-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y` correspond to maximal ideals in the original ring `R` that don't contain `y`. This lemma gives the correspondence in the particular case of an ideal and its comap. See `le_rel_iso_of_maximal` for the more general relation isomorphism -/ theorem isMaximal_iff_isMaximal_disjoint [H : IsJacobson R] (J : Ideal S) : J.IsMaximal ↔ (comap (algebraMap R S) J).IsMaximal ∧ y ∉ Ideal.comap (algebraMap R S) J := by constructor · refine' fun h => ⟨_, fun hy => h.ne_top (Ideal.eq_top_of_isUnit_mem _ hy (map_units _ ⟨y, Submonoid.mem_powers _⟩))⟩ have hJ : J.is_prime := is_maximal.is_prime h rw [is_prime_iff_is_prime_disjoint (Submonoid.powers y)] at hJ have : y ∉ (comap (algebraMap R S) J).1 := Set.disjoint_left.1 hJ.right (Submonoid.mem_powers _) erw [← H.out hJ.left.is_radical, mem_Inf] at this push_neg at this rcases this with ⟨I, hI, hI'⟩ convert hI.right by_cases hJ : J = map (algebraMap R S) I · rw [hJ, comap_map_of_is_prime_disjoint (powers y) S I (is_maximal.is_prime hI.right)] rwa [disjoint_powers_iff_not_mem y hI.right.is_prime.is_radical] · have hI_p : (map (algebraMap R S) I).IsPrime := by refine' is_prime_of_is_prime_disjoint (powers y) _ I hI.right.is_prime _ rwa [disjoint_powers_iff_not_mem y hI.right.is_prime.is_radical] have : J ≤ map (algebraMap R S) I := map_comap (Submonoid.powers y) S J ▸ map_mono hI.left exact absurd (h.1.2 _ (lt_of_le_of_ne this hJ)) hI_p.1 · refine' fun h => ⟨⟨fun hJ => h.1.ne_top (eq_top_iff.2 _), fun I hI => _⟩⟩ · rwa [eq_top_iff, ← (IsLocalization.orderEmbedding (powers y) S).le_iff_le] at hJ · have := congr_arg (map (algebraMap R S)) (h.1.1.2 _ ⟨comap_mono (le_of_lt hI), _⟩) rwa [map_comap (powers y) S I, map_top] at this refine' fun hI' => hI.right _ rw [← map_comap (powers y) S I, ← map_comap (powers y) S J] exact map_mono hI' #align ideal.is_maximal_iff_is_maximal_disjoint Ideal.isMaximal_iff_isMaximal_disjoint variable {S} /-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y` correspond to maximal ideals in the original ring `R` that don't contain `y`. This lemma gives the correspondence in the particular case of an ideal and its map. See `le_rel_iso_of_maximal` for the more general statement, and the reverse of this implication -/ theorem isMaximal_of_isMaximal_disjoint [IsJacobson R] (I : Ideal R) (hI : I.IsMaximal) (hy : y ∉ I) : (map (algebraMap R S) I).IsMaximal := by rw [is_maximal_iff_is_maximal_disjoint S y, comap_map_of_is_prime_disjoint (powers y) S I (is_maximal.is_prime hI) ((disjoint_powers_iff_not_mem y hI.is_prime.is_radical).2 hy)] exact ⟨hI, hy⟩ #align ideal.is_maximal_of_is_maximal_disjoint Ideal.isMaximal_of_isMaximal_disjoint /-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y` correspond to maximal ideals in the original ring `R` that don't contain `y` -/ def orderIsoOfMaximal [IsJacobson R] : { p : Ideal S // p.IsMaximal } ≃o { p : Ideal R // p.IsMaximal ∧ y ∉ p } where toFun p := ⟨Ideal.comap (algebraMap R S) p.1, (isMaximal_iff_isMaximal_disjoint S y p.1).1 p.2⟩ invFun p := ⟨Ideal.map (algebraMap R S) p.1, isMaximal_of_isMaximal_disjoint y p.1 p.2.1 p.2.2⟩ left_inv J := Subtype.eq (map_comap (powers y) S J) right_inv I := Subtype.eq (comap_map_of_isPrime_disjoint _ _ I.1 (IsMaximal.isPrime I.2.1) ((disjoint_powers_iff_not_mem y I.2.1.IsPrime.IsRadical).2 I.2.2)) map_rel_iff' I I' := ⟨fun h => show I.val ≤ I'.val from map_comap (powers y) S I.val ▸ map_comap (powers y) S I'.val ▸ Ideal.map_mono h, fun h x hx => h hx⟩ #align ideal.order_iso_of_maximal Ideal.orderIsoOfMaximal include y /-- If `S` is the localization of the Jacobson ring `R` at the submonoid generated by `y : R`, then `S` is Jacobson. -/ theorem isJacobson_localization [H : IsJacobson R] : IsJacobson S := by rw [is_jacobson_iff_prime_eq] refine' fun P' hP' => le_antisymm _ le_jacobson obtain ⟨hP', hPM⟩ := (IsLocalization.isPrime_iff_isPrime_disjoint (powers y) S P').mp hP' have hP := H.out hP'.is_radical refine' (IsLocalization.map_comap (powers y) S P'.jacobson).ge.trans ((map_mono _).trans (IsLocalization.map_comap (powers y) S P').le) have : Inf { I : Ideal R | comap (algebraMap R S) P' ≤ I ∧ I.IsMaximal ∧ y ∉ I } ≤ comap (algebraMap R S) P' := by intro x hx have hxy : x * y ∈ (comap (algebraMap R S) P').jacobson := by rw [Ideal.jacobson, mem_Inf] intro J hJ by_cases y ∈ J · exact J.mul_mem_left x h · exact J.mul_mem_right y ((mem_Inf.1 hx) ⟨hJ.left, ⟨hJ.right, h⟩⟩) rw [hP] at hxy cases' hP'.mem_or_mem hxy with hxy hxy · exact hxy · exact (hPM.le_bot ⟨Submonoid.mem_powers _, hxy⟩).elim refine' le_trans _ this rw [Ideal.jacobson, comap_Inf', infₛ_eq_infᵢ] refine' infᵢ_le_infᵢ_of_subset fun I hI => ⟨map (algebraMap R S) I, ⟨_, _⟩⟩ · exact ⟨le_trans (le_of_eq (IsLocalization.map_comap (powers y) S P').symm) (map_mono hI.1), is_maximal_of_is_maximal_disjoint y _ hI.2.1 hI.2.2⟩ · exact IsLocalization.comap_map_of_isPrime_disjoint _ S I (is_maximal.is_prime hI.2.1) ((disjoint_powers_iff_not_mem y hI.2.1.IsPrime.IsRadical).2 hI.2.2) #align ideal.is_jacobson_localization Ideal.isJacobson_localization end Localization namespace Polynomial open Polynomial section CommRing variable {R S : Type _} [CommRing R] [CommRing S] [IsDomain S] variable {Rₘ Sₘ : Type _} [CommRing Rₘ] [CommRing Sₘ] /-- If `I` is a prime ideal of `R[X]` and `pX ∈ I` is a non-constant polynomial, then the map `R →+* R[x]/I` descends to an integral map when localizing at `pX.leading_coeff`. In particular `X` is integral because it satisfies `pX`, and constants are trivially integral, so integrality of the entire extension follows by closure under addition and multiplication. -/ theorem isIntegral_isLocalization_polynomial_quotient (P : Ideal R[X]) (pX : R[X]) (hpX : pX ∈ P) [Algebra (R ⧸ P.comap (C : R →+* _)) Rₘ] [IsLocalization.Away (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff Rₘ] [Algebra (R[X] ⧸ P) Sₘ] [IsLocalization ((Submonoid.powers (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff).map (quotientMap P C le_rfl) : Submonoid (R[X] ⧸ P)) Sₘ] : (IsLocalization.map Sₘ (quotientMap P C le_rfl) (Submonoid.powers (pX.map (Quotient.mk (P.comap (C : R →+* R[X])))).leadingCoeff).le_comap_map : Rₘ →+* _).IsIntegral := by let P' : Ideal R := P.comap C let M : Submonoid (R ⧸ P') := Submonoid.powers (pX.map (Quotient.mk' (P.comap (C : R →+* R[X])))).leadingCoeff let M' : Submonoid (R[X] ⧸ P) := (Submonoid.powers (pX.map (Quotient.mk' (P.comap (C : R →+* R[X])))).leadingCoeff).map (QuotientMap P C le_rfl) let φ : R ⧸ P' →+* R[X] ⧸ P := QuotientMap P C le_rfl let φ' : Rₘ →+* Sₘ := IsLocalization.map Sₘ φ M.le_comap_map have hφ' : φ.comp (Quotient.mk' P') = (Quotient.mk' P).comp C := rfl intro p obtain ⟨⟨p', ⟨q, hq⟩⟩, hp⟩ := IsLocalization.surj M' p suffices φ'.is_integral_elem (algebraMap _ _ p') by obtain ⟨q', hq', rfl⟩ := hq obtain ⟨q'', hq''⟩ := isUnit_iff_exists_inv'.1 (IsLocalization.map_units Rₘ (⟨q', hq'⟩ : M)) refine' φ'.is_integral_of_is_integral_mul_unit p (algebraMap _ _ (φ q')) q'' _ (hp.symm ▸ this) convert trans (trans (φ'.map_mul _ _).symm (congr_arg φ' hq'')) φ'.map_one using 2 rw [← φ'.comp_apply, IsLocalization.map_comp, RingHom.comp_apply, Subtype.coe_mk] refine' is_integral_of_mem_closure'' ((algebraMap _ Sₘ).comp (Quotient.mk' P) '' insert X { p | p.degree ≤ 0 }) _ _ _ · rintro x ⟨p, hp, rfl⟩ refine' hp.rec_on (fun hy => _) fun hy => _ · refine' hy.symm ▸ φ.is_integral_elem_localization_at_leading_coeff ((Quotient.mk' P) X) (pX.map (Quotient.mk' P')) _ M ⟨1, pow_one _⟩ rwa [eval₂_map, hφ', ← hom_eval₂, quotient.eq_zero_iff_mem, eval₂_C_X] · rw [Set.mem_setOf_eq, degree_le_zero_iff] at hy refine' hy.symm ▸ ⟨X - C (algebraMap _ _ ((Quotient.mk' P') (p.coeff 0))), monic_X_sub_C _, _⟩ simp only [eval₂_sub, eval₂_C, eval₂_X] rw [sub_eq_zero, ← φ'.comp_apply, IsLocalization.map_comp] rfl · obtain ⟨p, rfl⟩ := quotient.mk_surjective p' refine' Polynomial.induction_on p (fun r => Subring.subset_closure <| Set.mem_image_of_mem _ (Or.inr degree_C_le)) (fun _ _ h1 h2 => _) fun n _ hr => _ · convert Subring.add_mem _ h1 h2 rw [RingHom.map_add, RingHom.map_add] · rw [pow_succ X n, mul_comm X, ← mul_assoc, RingHom.map_mul, RingHom.map_mul] exact Subring.mul_mem _ hr (Subring.subset_closure (Set.mem_image_of_mem _ (Or.inl rfl))) #align ideal.polynomial.is_integral_is_localization_polynomial_quotient Ideal.Polynomial.isIntegral_isLocalization_polynomial_quotient /-- If `f : R → S` descends to an integral map in the localization at `x`, and `R` is a Jacobson ring, then the intersection of all maximal ideals in `S` is trivial -/ theorem jacobson_bot_of_integral_localization {R : Type _} [CommRing R] [IsDomain R] [IsJacobson R] (Rₘ Sₘ : Type _) [CommRing Rₘ] [CommRing Sₘ] (φ : R →+* S) (hφ : Function.Injective φ) (x : R) (hx : x ≠ 0) [Algebra R Rₘ] [IsLocalization.Away x Rₘ] [Algebra S Sₘ] [IsLocalization ((Submonoid.powers x).map φ : Submonoid S) Sₘ] (hφ' : RingHom.IsIntegral (IsLocalization.map Sₘ φ (Submonoid.powers x).le_comap_map : Rₘ →+* Sₘ)) : (⊥ : Ideal S).jacobson = (⊥ : Ideal S) := by have hM : ((Submonoid.powers x).map φ : Submonoid S) ≤ nonZeroDivisors S := map_le_nonZeroDivisors_of_injective φ hφ (powers_le_nonZeroDivisors_of_noZeroDivisors hx) letI : IsDomain Sₘ := IsLocalization.isDomain_of_le_nonZeroDivisors _ hM let φ' : Rₘ →+* Sₘ := IsLocalization.map _ φ (Submonoid.powers x).le_comap_map suffices ∀ I : Ideal Sₘ, I.IsMaximal → (I.comap (algebraMap S Sₘ)).IsMaximal by have hϕ' : comap (algebraMap S Sₘ) (⊥ : Ideal Sₘ) = (⊥ : Ideal S) := by rw [← RingHom.ker_eq_comap_bot, ← RingHom.injective_iff_ker_eq_bot] exact IsLocalization.injective Sₘ hM have hSₘ : is_jacobson Sₘ := is_jacobson_of_is_integral' φ' hφ' (is_jacobson_localization x) refine' eq_bot_iff.mpr (le_trans _ (le_of_eq hϕ')) rw [← hSₘ.out is_radical_bot_of_no_zero_divisors, comap_jacobson] exact infₛ_le_infₛ fun j hj => ⟨bot_le, let ⟨J, hJ⟩ := hj hJ.2 ▸ this J hJ.1.2⟩ intro I hI -- Remainder of the proof is pulling and pushing ideals around the square and the quotient square haveI : (I.comap (algebraMap S Sₘ)).IsPrime := comap_is_prime _ I haveI : (I.comap φ').IsPrime := comap_is_prime φ' I haveI : (⊥ : Ideal (S ⧸ I.comap (algebraMap S Sₘ))).IsPrime := bot_prime have hcomm : φ'.comp (algebraMap R Rₘ) = (algebraMap S Sₘ).comp φ := IsLocalization.map_comp _ let f := QuotientMap (I.comap (algebraMap S Sₘ)) φ le_rfl let g := QuotientMap I (algebraMap S Sₘ) le_rfl have := is_maximal_comap_of_is_integral_of_is_maximal' φ' hφ' I hI have := ((is_maximal_iff_is_maximal_disjoint Rₘ x _).1 this).left have : ((I.comap (algebraMap S Sₘ)).comap φ).IsMaximal := by rwa [comap_comap, hcomm, ← comap_comap] at this rw [← bot_quotient_is_maximal_iff] at this⊢ refine' is_maximal_of_is_integral_of_is_maximal_comap' f _ ⊥ ((eq_bot_iff.2 (comap_bot_le_of_injective f quotient_map_injective)).symm ▸ this) exact f.is_integral_tower_bot_of_is_integral g quotient_map_injective ((comp_quotient_map_eq_of_comp_eq hcomm I).symm ▸ RingHom.isIntegral_trans _ _ (RingHom.isIntegral_of_surjective _ (IsLocalization.surjective_quotientMap_of_maximal_of_localization (Submonoid.powers x) Rₘ (by rwa [comap_comap, hcomm, ← bot_quotient_is_maximal_iff]))) (RingHom.isIntegral_quotient_of_isIntegral _ hφ')) #align ideal.polynomial.jacobson_bot_of_integral_localization Ideal.Polynomial.jacobson_bot_of_integral_localization /-- Used to bootstrap the proof of `is_jacobson_polynomial_iff_is_jacobson`. That theorem is more general and should be used instead of this one. -/ private theorem is_jacobson_polynomial_of_domain (R : Type _) [CommRing R] [IsDomain R] [hR : IsJacobson R] (P : Ideal R[X]) [IsPrime P] (hP : ∀ x : R, C x ∈ P → x = 0) : P.jacobson = P := by by_cases Pb : P = ⊥ · exact Pb.symm ▸ jacobson_bot_polynomial_of_jacobson_bot (hR.out is_radical_bot_of_no_zero_divisors) · rw [jacobson_eq_iff_jacobson_quotient_eq_bot] haveI : (P.comap (C : R →+* R[X])).IsPrime := comap_is_prime C P obtain ⟨p, pP, p0⟩ := exists_nonzero_mem_of_ne_bot Pb hP let x := (Polynomial.map (Quotient.mk' (comap (C : R →+* _) P)) p).leadingCoeff have hx : x ≠ 0 := by rwa [Ne.def, leading_coeff_eq_zero] refine' jacobson_bot_of_integral_localization (Localization.Away x) (Localization ((Submonoid.powers x).map (P.quotient_map C le_rfl) : Submonoid (R[X] ⧸ P))) (QuotientMap P C le_rfl) quotient_map_injective x hx _ -- `convert` is noticeably faster than `exact` here: convert is_integral_is_localization_polynomial_quotient P p pP #align ideal.polynomial.is_jacobson_polynomial_of_domain ideal.polynomial.is_jacobson_polynomial_of_domain theorem isJacobson_polynomial_of_isJacobson (hR : IsJacobson R) : IsJacobson R[X] := by refine' is_jacobson_iff_prime_eq.mpr fun I => _ intro hI let R' : Subring (R[X] ⧸ I) := ((Quotient.mk' I).comp C).range let i : R →+* R' := ((Quotient.mk' I).comp C).range_restrict have hi : Function.Surjective (i : R → R') := ((Quotient.mk' I).comp C).rangeRestrict_surjective have hi' : (Polynomial.mapRingHom i : R[X] →+* R'[X]).ker ≤ I := by refine' fun f hf => polynomial_mem_ideal_of_coeff_mem_ideal I f fun n => _ replace hf := congr_arg (fun g : Polynomial ((Quotient.mk' I).comp C).range => g.coeff n) hf change (Polynomial.map ((Quotient.mk' I).comp C).range_restrict f).coeff n = 0 at hf rw [coeff_map, Subtype.ext_iff] at hf rwa [mem_comap, ← quotient.eq_zero_iff_mem, ← RingHom.comp_apply] haveI := map_is_prime_of_surjective (show Function.Surjective (map_ring_hom i) from map_surjective i hi) hi' suffices (I.map (Polynomial.mapRingHom i)).jacobson = I.map (Polynomial.mapRingHom i) by replace this := congr_arg (comap (Polynomial.mapRingHom i)) this rw [← map_jacobson_of_surjective _ hi', comap_map_of_surjective _ _, comap_map_of_surjective _ _] at this refine' le_antisymm (le_trans (le_sup_of_le_left le_rfl) (le_trans (le_of_eq this) (sup_le le_rfl hi'))) le_jacobson all_goals exact Polynomial.map_surjective i hi exact @is_jacobson_polynomial_of_domain R' _ _ (is_jacobson_of_surjective ⟨i, hi⟩) (map (map_ring_hom i) I) _ (eq_zero_of_polynomial_mem_map_range I) #align ideal.polynomial.is_jacobson_polynomial_of_is_jacobson Ideal.Polynomial.isJacobson_polynomial_of_isJacobson theorem isJacobson_polynomial_iff_isJacobson : IsJacobson R[X] ↔ IsJacobson R := by refine' ⟨_, is_jacobson_polynomial_of_is_jacobson⟩ intro H exact is_jacobson_of_surjective ⟨eval₂_ring_hom (RingHom.id _) 1, fun x => ⟨C x, by simp only [coe_eval₂_ring_hom, RingHom.id_apply, eval₂_C]⟩⟩ #align ideal.polynomial.is_jacobson_polynomial_iff_is_jacobson Ideal.Polynomial.isJacobson_polynomial_iff_isJacobson instance [IsJacobson R] : IsJacobson R[X] := isJacobson_polynomial_iff_isJacobson.mpr ‹IsJacobson R› end CommRing section variable {R : Type _} [CommRing R] [IsJacobson R] variable (P : Ideal R[X]) [hP : P.IsMaximal] include P hP theorem isMaximal_comap_c_of_isMaximal [Nontrivial R] (hP' : ∀ x : R, C x ∈ P → x = 0) : IsMaximal (comap (C : R →+* R[X]) P : Ideal R) := by haveI hp'_prime : (P.comap (C : R →+* R[X]) : Ideal R).IsPrime := comap_is_prime C P obtain ⟨m, hm⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_of_maximal P polynomial_not_is_field) have : (m : R[X]) ≠ 0 rwa [Ne.def, Submodule.coe_eq_zero] let φ : R ⧸ P.comap (C : R →+* R[X]) →+* R[X] ⧸ P := QuotientMap P (C : R →+* R[X]) le_rfl let M : Submonoid (R ⧸ P.comap C) := Submonoid.powers ((m : R[X]).map (Quotient.mk' (P.comap (C : R →+* R[X]) : Ideal R))).leadingCoeff rw [← bot_quotient_is_maximal_iff] have hp0 : ((m : R[X]).map (Quotient.mk' (P.comap (C : R →+* R[X]) : Ideal R))).leadingCoeff ≠ 0 := fun hp0' => this <| map_injective (Quotient.mk' (P.comap (C : R →+* R[X]) : Ideal R)) ((injective_iff_map_eq_zero (Quotient.mk' (P.comap (C : R →+* R[X]) : Ideal R))).2 fun x hx => by rwa [quotient.eq_zero_iff_mem, (by rwa [eq_bot_iff] : (P.comap C : Ideal R) = ⊥)] at hx) (by simpa only [leading_coeff_eq_zero, Polynomial.map_zero] using hp0') have hM : (0 : R ⧸ P.comap C) ∉ M := fun ⟨n, hn⟩ => hp0 (pow_eq_zero hn) suffices (⊥ : Ideal (Localization M)).IsMaximal by rw [← IsLocalization.comap_map_of_isPrime_disjoint M (Localization M) ⊥ bot_prime (disjoint_iff_inf_le.mpr fun x hx => hM (hx.2 ▸ hx.1))] refine' ((is_maximal_iff_is_maximal_disjoint (Localization M) _ _).mp (by rwa [map_bot])).1 swap exact Localization.isLocalization let M' : Submonoid (R[X] ⧸ P) := M.map φ have hM' : (0 : R[X] ⧸ P) ∉ M' := fun ⟨z, hz⟩ => hM (quotient_map_injective (trans hz.2 φ.map_zero.symm) ▸ hz.1) haveI : IsDomain (Localization M') := IsLocalization.isDomain_localization (le_nonZeroDivisors_of_noZeroDivisors hM') suffices (⊥ : Ideal (Localization M')).IsMaximal by rw [le_antisymm bot_le (comap_bot_le_of_injective _ (IsLocalization.map_injective_of_injective M (Localization M) (Localization M') quotient_map_injective))] refine' is_maximal_comap_of_is_integral_of_is_maximal' _ _ ⊥ this apply is_integral_is_localization_polynomial_quotient P _ (Submodule.coe_mem m) rw [(map_bot.symm : (⊥ : Ideal (Localization M')) = map (algebraMap (R[X] ⧸ P) (Localization M')) ⊥)] let bot_maximal := (bot_quotient_is_maximal_iff _).mpr hP refine' map.is_maximal (algebraMap _ _) (IsField.localization_map_bijective hM' _) bot_maximal rwa [← quotient.maximal_ideal_iff_is_field_quotient, ← bot_quotient_is_maximal_iff] #align ideal.polynomial.is_maximal_comap_C_of_is_maximal Ideal.Polynomial.isMaximal_comap_c_of_isMaximal /-- Used to bootstrap the more general `quotient_mk_comp_C_is_integral_of_jacobson` -/ private theorem quotient_mk_comp_C_is_integral_of_jacobson' [Nontrivial R] (hR : IsJacobson R) (hP' : ∀ x : R, C x ∈ P → x = 0) : ((Quotient.mk P).comp C : R →+* R[X] ⧸ P).IsIntegral := by refine' (isIntegral_quotientMap_iff _).mp _ let P' : Ideal R := P.comap C obtain ⟨pX, hpX, hp0⟩ := exists_nonzero_mem_of_ne_bot (ne_of_lt (bot_lt_of_maximal P polynomial_not_is_field)).symm hP' let M : Submonoid (R ⧸ P') := Submonoid.powers (pX.map (Quotient.mk' P')).leadingCoeff let φ : R ⧸ P' →+* R[X] ⧸ P := QuotientMap P C le_rfl haveI hp'_prime : P'.is_prime := comap_is_prime C P have hM : (0 : R ⧸ P') ∉ M := fun ⟨n, hn⟩ => hp0 <| leading_coeff_eq_zero.mp (pow_eq_zero hn) let M' : Submonoid (R[X] ⧸ P) := M.map (QuotientMap P C le_rfl) refine' (QuotientMap P C le_rfl).isIntegral_tower_bot_of_isIntegral (algebraMap _ (Localization M')) _ _ · refine' IsLocalization.injective (Localization M') (show M' ≤ _ from le_nonZeroDivisors_of_noZeroDivisors fun hM' => hM _) exact let ⟨z, zM, z0⟩ := hM' quotient_map_injective (trans z0 φ.map_zero.symm) ▸ zM · rw [← IsLocalization.map_comp M.le_comap_map] refine' RingHom.isIntegral_trans (algebraMap (R ⧸ P') (Localization M)) (IsLocalization.map (Localization M') _ M.le_comap_map) _ _ · exact (algebraMap (R ⧸ P') (Localization M)).isIntegral_of_surjective (IsField.localization_map_bijective hM ((quotient.maximal_ideal_iff_is_field_quotient _).mp (is_maximal_comap_C_of_is_maximal P hP'))).2 ·-- `convert` here is faster than `exact`, and this proof is near the time limit. convert is_integral_is_localization_polynomial_quotient P pX hpX #align ideal.polynomial.quotient_mk_comp_C_is_integral_of_jacobson' ideal.polynomial.quotient_mk_comp_C_is_integral_of_jacobson' /-- If `R` is a Jacobson ring, and `P` is a maximal ideal of `R[X]`, then `R → R[X]/P` is an integral map. -/ theorem quotient_mk_comp_c_isIntegral_of_jacobson : ((Quotient.mk P).comp C : R →+* R[X] ⧸ P).IsIntegral := by let P' : Ideal R := P.comap C haveI : P'.is_prime := comap_is_prime C P let f : R[X] →+* Polynomial (R ⧸ P') := Polynomial.mapRingHom (Quotient.mk' P') have hf : Function.Surjective f := map_surjective (Quotient.mk' P') quotient.mk_surjective have hPJ : P = (P.map f).comap f := by rw [comap_map_of_surjective _ hf] refine' le_antisymm (le_sup_of_le_left le_rfl) (sup_le le_rfl _) refine' fun p hp => polynomial_mem_ideal_of_coeff_mem_ideal P p fun n => quotient.eq_zero_iff_mem.mp _ simpa only [coeff_map, coe_map_ring_hom] using (polynomial.ext_iff.mp hp) n refine' RingHom.isIntegral_tower_bot_of_isIntegral _ _ (injective_quotient_le_comap_map P) _ rw [← quotient_mk_maps_eq] refine' RingHom.isIntegral_trans _ _ ((Quotient.mk' P').isIntegral_of_surjective quotient.mk_surjective) _ apply quotient_mk_comp_C_is_integral_of_jacobson' _ _ fun x hx => _ any_goals exact Ideal.isJacobson_quotient · exact Or.rec_on (map_eq_top_or_is_maximal_of_surjective f hf hP) (fun h => absurd (trans (h ▸ hPJ : P = comap f ⊤) comap_top : P = ⊤) hP.ne_top) id · infer_instance · obtain ⟨z, rfl⟩ := quotient.mk_surjective x rwa [quotient.eq_zero_iff_mem, mem_comap, hPJ, mem_comap, coe_map_ring_hom, map_C] #align ideal.polynomial.quotient_mk_comp_C_is_integral_of_jacobson Ideal.Polynomial.quotient_mk_comp_c_isIntegral_of_jacobson theorem isMaximal_comap_c_of_isJacobson : (P.comap (C : R →+* R[X])).IsMaximal := by rw [← @mk_ker _ _ P, RingHom.ker_eq_comap_bot, comap_comap] exact is_maximal_comap_of_is_integral_of_is_maximal' _ (quotient_mk_comp_C_is_integral_of_jacobson P) ⊥ ((bot_quotient_is_maximal_iff _).mpr hP) #align ideal.polynomial.is_maximal_comap_C_of_is_jacobson Ideal.Polynomial.isMaximal_comap_c_of_isJacobson omit P hP theorem comp_c_integral_of_surjective_of_jacobson {S : Type _} [Field S] (f : R[X] →+* S) (hf : Function.Surjective f) : (f.comp C).IsIntegral := by haveI : f.ker.IsMaximal := RingHom.ker_isMaximal_of_surjective f hf let g : R[X] ⧸ f.ker →+* S := Ideal.Quotient.lift f.ker f fun _ h => h have hfg : g.comp (Quotient.mk' f.ker) = f := ring_hom_ext' rfl rfl rw [← hfg, RingHom.comp_assoc] refine' RingHom.isIntegral_trans _ g (quotient_mk_comp_C_is_integral_of_jacobson f.ker) (g.is_integral_of_surjective _) --(quotient.lift_surjective f.ker f _ hf)), rw [← hfg] at hf exact Function.Surjective.of_comp hf #align ideal.polynomial.comp_C_integral_of_surjective_of_jacobson Ideal.Polynomial.comp_c_integral_of_surjective_of_jacobson end end Polynomial open MvPolynomial RingHom namespace MvPolynomial theorem isJacobson_mvPolynomial_fin {R : Type _} [CommRing R] [H : IsJacobson R] : ∀ n : ℕ, IsJacobson (MvPolynomial (Fin n) R) | 0 => (isJacobson_iso ((renameEquiv R (Equiv.equivPEmpty (Fin 0))).toRingEquiv.trans (isEmptyRingEquiv R PEmpty))).mpr H | n + 1 => (isJacobson_iso (finSuccEquiv R n).toRingEquiv).2 (Polynomial.isJacobson_polynomial_iff_isJacobson.2 (is_jacobson_mv_polynomial_fin n)) #align ideal.mv_polynomial.is_jacobson_mv_polynomial_fin Ideal.MvPolynomial.isJacobson_mvPolynomial_fin /-- General form of the nullstellensatz for Jacobson rings, since in a Jacobson ring we have `Inf {P maximal | P ≥ I} = Inf {P prime | P ≥ I} = I.radical`. Fields are always Jacobson, and in that special case this is (most of) the classical Nullstellensatz, since `I(V(I))` is the intersection of maximal ideals containing `I`, which is then `I.radical` -/ instance isJacobson {R : Type _} [CommRing R] {ι : Type _} [Finite ι] [IsJacobson R] : IsJacobson (MvPolynomial ι R) := by cases nonempty_fintype ι haveI := Classical.decEq ι let e := Fintype.equivFin ι rw [is_jacobson_iso (rename_equiv R e).toRingEquiv] exact is_jacobson_mv_polynomial_fin _ #align ideal.mv_polynomial.is_jacobson Ideal.MvPolynomial.isJacobson variable {n : ℕ} theorem quotient_mk_comp_c_isIntegral_of_jacobson {R : Type _} [CommRing R] [IsJacobson R] (P : Ideal (MvPolynomial (Fin n) R)) [P.IsMaximal] : ((Quotient.mk P).comp MvPolynomial.C : R →+* MvPolynomial _ R ⧸ P).IsIntegral := by induction' n with n IH · refine' RingHom.isIntegral_of_surjective _ (Function.Surjective.comp quotient.mk_surjective _) exact C_surjective (Fin 0) · rw [← fin_succ_equiv_comp_C_eq_C, ← RingHom.comp_assoc, ← RingHom.comp_assoc, ← quotient_map_comp_mk le_rfl, RingHom.comp_assoc Polynomial.C, ← quotient_map_comp_mk le_rfl, RingHom.comp_assoc, RingHom.comp_assoc, ← quotient_map_comp_mk le_rfl, ← RingHom.comp_assoc (Quotient.mk' _)] refine' RingHom.isIntegral_trans _ _ _ _ · refine' RingHom.isIntegral_trans _ _ (isIntegral_of_surjective _ quotient.mk_surjective) _ refine' RingHom.isIntegral_trans _ _ _ _ · apply (isIntegral_quotientMap_iff _).mpr (IH _) apply polynomial.is_maximal_comap_C_of_is_jacobson _ · exact mv_polynomial.is_jacobson_mv_polynomial_fin n · apply comap_is_maximal_of_surjective exact (finSuccEquiv R n).symm.Surjective · refine' (isIntegral_quotientMap_iff _).mpr _ rw [← quotient_map_comp_mk le_rfl] refine' RingHom.isIntegral_trans _ _ _ ((isIntegral_quotientMap_iff _).mpr _) · exact RingHom.isIntegral_of_surjective _ quotient.mk_surjective · apply polynomial.quotient_mk_comp_C_is_integral_of_jacobson _ · exact mv_polynomial.is_jacobson_mv_polynomial_fin n · exact comap_is_maximal_of_surjective _ (finSuccEquiv R n).symm.Surjective · refine' (isIntegral_quotientMap_iff _).mpr _ refine' RingHom.isIntegral_trans _ _ _ (isIntegral_of_surjective _ quotient.mk_surjective) exact RingHom.isIntegral_of_surjective _ (finSuccEquiv R n).symm.Surjective #align ideal.mv_polynomial.quotient_mk_comp_C_is_integral_of_jacobson Ideal.MvPolynomial.quotient_mk_comp_c_isIntegral_of_jacobson theorem comp_c_integral_of_surjective_of_jacobson {R : Type _} [CommRing R] [IsJacobson R] {σ : Type _} [Finite σ] {S : Type _} [Field S] (f : MvPolynomial σ R →+* S) (hf : Function.Surjective f) : (f.comp C).IsIntegral := by cases nonempty_fintype σ have e := (Fintype.equivFin σ).symm let f' : MvPolynomial (Fin _) R →+* S := f.comp (rename_equiv R e).toRingEquiv.toRingHom have hf' : Function.Surjective f' := Function.Surjective.comp hf (rename_equiv R e).Surjective have : (f'.comp C).IsIntegral := by haveI : f'.ker.IsMaximal := ker_is_maximal_of_surjective f' hf' let g : MvPolynomial _ R ⧸ f'.ker →+* S := Ideal.Quotient.lift f'.ker f' fun _ h => h have hfg : g.comp (Quotient.mk' f'.ker) = f' := ring_hom_ext (fun r => rfl) fun i => rfl rw [← hfg, RingHom.comp_assoc] refine' RingHom.isIntegral_trans _ g (quotient_mk_comp_C_is_integral_of_jacobson f'.ker) (g.is_integral_of_surjective _) rw [← hfg] at hf' exact Function.Surjective.of_comp hf' rw [RingHom.comp_assoc] at this convert this refine' RingHom.ext fun x => _ exact ((rename_equiv R e).commutes' x).symm #align ideal.mv_polynomial.comp_C_integral_of_surjective_of_jacobson Ideal.MvPolynomial.comp_c_integral_of_surjective_of_jacobson end MvPolynomial end Ideal
[STATEMENT] lemma sep_extract_pure[simp]: "NO_MATCH True P \<Longrightarrow> (\<langle>P\<rangle> ** Q) h = (P \<and> (sep_true ** Q) h)" "(\<up>P ** Q) h = (P \<and> Q h)" "\<up>True = \<box>" "\<up>False = sep_false" [PROOF STATE] proof (prove) goal (1 subgoal): 1. ((NO_MATCH True P \<Longrightarrow> ((\<lambda>s. P) \<and>* Q) h = (P \<and> ((\<lambda>s. True) \<and>* Q) h)) &&& (\<up> P \<and>* Q) h = (P \<and> Q h)) &&& \<up> True = \<box> &&& \<up> False = (\<lambda>s. False) [PROOF STEP] using sep_conj_sep_true_right [PROOF STATE] proof (prove) using this: (?P \<and>* ?Q) ?h \<Longrightarrow> (?P \<and>* (\<lambda>s. True)) ?h goal (1 subgoal): 1. ((NO_MATCH True P \<Longrightarrow> ((\<lambda>s. P) \<and>* Q) h = (P \<and> ((\<lambda>s. True) \<and>* Q) h)) &&& (\<up> P \<and>* Q) h = (P \<and> Q h)) &&& \<up> True = \<box> &&& \<up> False = (\<lambda>s. False) [PROOF STEP] apply fastforce [PROOF STATE] proof (prove) goal (3 subgoals): 1. (\<up> P \<and>* Q) h = (P \<and> Q h) 2. \<up> True = \<box> 3. \<up> False = (\<lambda>s. False) [PROOF STEP] by (auto simp: puree_def sep_empty_def[symmetric])
Formal statement is: lemma measurable_pred_countable[measurable (raw)]: assumes "countable X" shows "(\<And>i. i \<in> X \<Longrightarrow> Measurable.pred M (\<lambda>x. P x i)) \<Longrightarrow> Measurable.pred M (\<lambda>x. \<forall>i\<in>X. P x i)" "(\<And>i. i \<in> X \<Longrightarrow> Measurable.pred M (\<lambda>x. P x i)) \<Longrightarrow> Measurable.pred M (\<lambda>x. \<exists>i\<in>X. P x i)" Informal statement is: If $X$ is a countable set and $P$ is a predicate on $X$, then the predicate $\forall i \in X. P(i)$ is measurable.
Coq < Section Simplification. Coq < Variables P Q : Prop. P is assumed Q is assumed Coq < Goal (P /\ Q) -> P. 1 subgoal P : Prop Q : Prop ============================ P /\ Q -> P Unnamed_thm < intro. 1 subgoal P : Prop Q : Prop H : P /\ Q ============================ P Unnamed_thm < elim H. 1 subgoal P : Prop Q : Prop H : P /\ Q ============================ P -> Q -> P Unnamed_thm < intro. 1 subgoal P : Prop Q : Prop H : P /\ Q H0 : P ============================ Q -> P Unnamed_thm < intro. 1 subgoal P : Prop Q : Prop H : P /\ Q H0 : P H1 : Q ============================ P Unnamed_thm < exact H0. Proof completed. Unnamed_thm < Qed. intro. elim H. intro. intro. exact H0. Unnamed_thm is defined
lemma cone_univ[intro, simp]: "cone UNIV"
theory Proof_3_6 imports HandDryer VCTheoryLemmas Extra begin theorem proof_3_6: "VC6 inv3 s0 hands_value" apply(simp only: VC6_def inv3_def R3_def dryer_def) apply(rule impI) apply(rule conjI) apply(rule conjI) apply(simp) proof - define s:: state where "s =(toEnv (setPstate (setVarAny s0 hands_value) Ctrl waiting))" assume VC: " ((toEnvP s0 \<and> (\<forall>s1 s2. substate s1 s2 \<and> substate s2 s0 \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s0 \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)))) \<and> extraInv s0) \<and> env (setVarAny s0 hands_value) hands_value \<and> getPstate (setVarAny s0 hands_value) Ctrl = drying \<and> getVarBool (setVarAny s0 hands_value) hands \<noteq> ON \<and> 10 \<le> ltimeEnv (setVarAny s0 hands_value) Ctrl" show "\<forall>s1 s2. substate s1 s2 \<and> substate s2 (toEnv (setPstate (setVarAny s0 hands_value) Ctrl waiting)) \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 (toEnv (setPstate (setVarAny s0 hands_value) Ctrl waiting)) \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 (toEnv (setPstate (setVarAny s0 hands_value) Ctrl waiting)) \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF))" apply(simp only: s_def[symmetric]) proof(rule allI; rule allI; rule impI) fix s1 s2 assume req_prems: "substate s1 s2 \<and> substate s2 s \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF" then obtain "10 \<le> toEnvNum s2 s" by auto from le_imp_less_or_eq[OF this] show " \<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof assume 1: "10 < toEnvNum s2 s" with req_prems substate_eq_or_predEnv toEnvNum_id s_def have 2: "substate s2 s0" by (simp add: s_def split: if_splits) from VC obtain "\<forall>s1 s2. substate s1 s2 \<and> substate s2 s0 \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s0 \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF))" by auto with req_prems 1 2 have "\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" by (auto simp add: s_def split: if_splits) then obtain s4 where 3: " toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" .. have "(toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON)) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof from 3 show "toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON)" by (simp add: s_def) next from 3 show "\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by simp qed thus ?thesis by auto next assume 4: "10 = toEnvNum s2 s" from substate_asym have 5: "\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s2 \<and> s3 \<noteq> s2 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto show ?thesis proof - define s5:: state where "s5=s2" have "toEnvP s5 \<and> substate s2 s5 \<and> substate s5 s \<longrightarrow>pred3 s2 s s5" proof(induction rule: state_down_ind) case 1 then show ?case using req_prems s_def by auto next case 2 then show ?case apply(simp only: pred3_def) proof assume 6: " \<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s \<and> s3 \<noteq> s \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" from VC have "\<exists> s3. ~ (toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s \<and> s3 \<noteq> s \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" apply(simp only: extraInv_def) proof - assume "((toEnvP s0 \<and> (\<forall>s1 s2. substate s1 s2 \<and> substate s2 s0 \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s0 \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)))) \<and> toEnvP s0 \<and> (getPstate s0 Ctrl = drying \<longrightarrow> 0 < ltimeEnv s0 Ctrl \<and> ltimeEnv s0 Ctrl \<le> 10 \<and> (\<forall>s1. toEnvP s1 \<and> substate s1 s0 \<and> toEnvNum s1 s0 + hands = ltimeEnv s0 Ctrl \<longrightarrow> getVarBool s1 hands = ON \<and> getVarBool s1 dryer = ON) \<and> (\<forall>s1. toEnvP s1 \<and> substate s1 s0 \<and> toEnvNum s1 s0 + hands < ltimeEnv s0 Ctrl \<longrightarrow> getVarBool s1 hands = OFF \<and> getVarBool s1 dryer = ON)) \<and> (\<forall>s1. toEnvP s1 \<and> substate s1 s0 \<longrightarrow> getPstate s1 Ctrl = waiting \<or> getPstate s1 Ctrl = drying)) \<and> env (setVarAny s0 hands_value) hands_value \<and> getPstate (setVarAny s0 hands_value) Ctrl = drying \<and> getVarBool (setVarAny s0 hands_value) hands \<noteq> ON \<and> 10 \<le> ltimeEnv (setVarAny s0 hands_value) Ctrl" then obtain 7: " 0 < ltimeEnv s0 Ctrl \<and> ltimeEnv s0 Ctrl \<le> 10 \<and> (\<forall>s1. toEnvP s1 \<and> substate s1 s0 \<and> toEnvNum s1 s0 + hands = ltimeEnv s0 Ctrl \<longrightarrow> getVarBool s1 hands = ON \<and> getVarBool s1 dryer = ON)" by auto from shiftEnv_substate have 8: "substate (shiftEnv s0 (ltimeEnv s0 Ctrl - 1)) s0" by auto from VC obtain 9: "toEnvP s0" by auto from 7 obtain 10: "0 < ltimeEnv s0 Ctrl" by auto from 9 10 ltime_le_toEnvNum[of s0 Ctrl] shift_spec have 11: "toEnvP (shiftEnv s0 (ltimeEnv s0 Ctrl - 1))" by auto have "toEnvNum (shiftEnv s0 (ltimeEnv s0 Ctrl - 1)) s0 + 1 = ltimeEnv s0 Ctrl" proof - from VC obtain 9: "toEnvP s0" by auto from 7 obtain 10: "0 < ltimeEnv s0 Ctrl" by auto with 9 10 ltime_le_toEnvNum[of s0 Ctrl] toEnvNum_shift show ?thesis by auto qed with 7 8 11 have 12: "getVarBool (shiftEnv s0 (ltimeEnv s0 Ctrl - 1)) hands = ON \<and> getVarBool (shiftEnv s0 (ltimeEnv s0 Ctrl - 1)) dryer = ON" by auto have 13:"substate s2 (shiftEnv s0 (ltimeEnv s0 Ctrl - 1))" proof - from 4 req_prems substate_eq_or_predEnv toEnvNum_id s_def have 2: "substate s2 s0" by (simp add: s_def split: if_splits) from 7 obtain 14: "ltimeEnv s0 Ctrl \<le> 10" by auto from req_prems obtain "toEnvP s2" by auto with 2 9 10 4 14 substate_shift[of s2 s0 "ltimeEnv s0 Ctrl - 1"] show ?thesis by (auto simp add: s_def split: if_splits) qed have 14: "substate (shiftEnv s0 (ltimeEnv s0 Ctrl - hands)) s0" using shiftEnv_substate by auto have 15: "substate s0 s" using substate_refl by (auto simp add: s_def) with 14 have 16: "substate (shiftEnv s0 (ltimeEnv s0 Ctrl - hands)) s" using substate_trans by blast have " (shiftEnv s0 (ltimeEnv s0 Ctrl - hands)) \<noteq> s" proof assume "shiftEnv s0 (ltimeEnv s0 Ctrl - hands) = s" with shiftEnv_substate have "substate s s0" by auto with 15 substate_asym have "s0 = s" by auto with s_def show False by auto qed with 11 12 13 16 show ?thesis by auto qed with 6 show " \<exists>s4. toEnvP s4 \<and> substate s s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" by auto qed next case (3 s5) then show ?case apply(simp only: pred3_def) proof from 3(3) have 6: " (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s5 \<and> s3 \<noteq> s5 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF) \<Longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s5 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s5 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)) " by (auto simp add: pred3_def) assume 7: " \<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 (predEnv s5) \<and> s3 \<noteq> predEnv s5 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" show "\<exists>s4. toEnvP s4 \<and> substate (predEnv s5) s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof cases assume 10: "(getVarBool (predEnv s5) (Suc (Suc 0)) = OFF \<or> getVarBool (predEnv s5) hands = ON)" from predEnv_substate 3 substate_trans have 8: "substate (predEnv s5) s" by blast from 3(2) substate_eq_or_predEnv req_prems have 9: "substate s2 (predEnv s5)" by auto have "toEnvP (predEnv s5) \<and> substate (predEnv s5) (predEnv s5) \<and> substate (predEnv s5) s \<and> toEnvNum s2 (predEnv s5) \<le> 10 \<and> (getVarBool (predEnv s5) (Suc (Suc 0)) = OFF \<or> getVarBool (predEnv s5) hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 (predEnv s5) \<and> s3 \<noteq> (predEnv s5) \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof - from predEnvP_or_emptyState[of s5] have "toEnvP (predEnv s5)" proof assume "toEnvP (predEnv s5)" thus ?thesis by assumption next assume "predEnv s5 = emptyState" with 9 req_prems show ?thesis by (cases s2; auto) qed moreover from substate_refl have " substate (predEnv s5) (predEnv s5)" by auto moreover from 8 have "substate (predEnv s5) s" by assumption moreover from 4 8 9 toEnvNum3 have "toEnvNum s2 (predEnv s5) \<le> 10" by auto moreover from 10 have "(getVarBool (predEnv s5) (Suc (Suc 0)) = OFF \<or> getVarBool (predEnv s5) hands = ON)" by assumption moreover from substate_asym have "\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 (predEnv s5) \<and> s3 \<noteq> predEnv s5 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto ultimately show ?thesis by auto qed thus ?thesis by auto next assume 10: "\<not> (getVarBool (predEnv s5) (Suc (Suc 0)) = OFF \<or> getVarBool (predEnv s5) hands = ON)" with substate_eq_or_predEnv 7 have " \<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s5 \<and> s3 \<noteq> s5 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto from 6[OF this] obtain s4 where 11: "toEnvP s4 \<and> substate s5 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s5 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" .. have "(toEnvP s4 \<and> substate (predEnv s5) s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON)) \<and> (\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof from 11 predEnv_substate substate_trans show "toEnvP s4 \<and> substate (predEnv s5) s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON)" by blast next show "\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" proof(rule allI; rule impI) fix s3 assume 12: "toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4" with 11 3(1) predEnv_substate_imp_eq_or_substate have "s3 = predEnv s5 \<or> substate s5 s3" by auto with 10 11 12 show "getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto qed qed thus ?thesis by auto qed qed qed with s5_def req_prems substate_refl pred3_def 5 show ?thesis by auto qed qed qed next assume "((toEnvP s0 \<and> (\<forall>s1 s2. substate s1 s2 \<and> substate s2 s0 \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s0 \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)))) \<and> extraInv s0) \<and> env (setVarAny s0 hands_value) hands_value \<and> getPstate (setVarAny s0 hands_value) Ctrl = drying \<and> getVarBool (setVarAny s0 hands_value) hands \<noteq> ON \<and> 10 \<le> ltimeEnv (setVarAny s0 hands_value) Ctrl " with extra6 show " extraInv (toEnv (setPstate (setVarAny s0 hands_value) Ctrl waiting))" by (auto simp add: VC6_def) qed end
module PLRTree.Heap {A : Set}(_≤_ : A → A → Set) where open import PLRTree {A} data _≤*_ : A → PLRTree → Set where lf≤* : (x : A) → x ≤* leaf nd≤* : {t : Tag}{x y : A}{l r : PLRTree} → x ≤ y → x ≤* l → x ≤* r → x ≤* node t y l r data Heap : PLRTree → Set where leaf : Heap leaf node : {t : Tag}{x : A}{l r : PLRTree} → x ≤* l → x ≤* r → Heap l → Heap r → Heap (node t x l r)
[GOAL] M : Type u α : Type v inst✝¹ : Monoid M inst✝ : MulAction M α a : α ⊢ (fun m => m • a) 1 = a [PROOFSTEP] simp [MulAction.one_smul] [GOAL] M : Type u α : Type v inst✝¹ : Monoid M inst✝ : MulAction M α a : α m m' : M ha : m • a = a hb : m' • a = a ⊢ (m * m') • a = a [PROOFSTEP] rw [← smul_smul, hb, ha] [GOAL] M : Type u α : Type v inst✝² : Monoid M inst✝¹ : MulAction M α a : α inst✝ : Fintype ↑(orbit M a) ⊢ a ∈ fixedPoints M α ↔ Fintype.card ↑(orbit M a) = 1 [PROOFSTEP] rw [Fintype.card_eq_one_iff, mem_fixedPoints] [GOAL] M : Type u α : Type v inst✝² : Monoid M inst✝¹ : MulAction M α a : α inst✝ : Fintype ↑(orbit M a) ⊢ (∀ (m : M), m • a = a) ↔ ∃ x, ∀ (y : ↑(orbit M a)), y = x [PROOFSTEP] constructor [GOAL] case mp M : Type u α : Type v inst✝² : Monoid M inst✝¹ : MulAction M α a : α inst✝ : Fintype ↑(orbit M a) ⊢ (∀ (m : M), m • a = a) → ∃ x, ∀ (y : ↑(orbit M a)), y = x [PROOFSTEP] exact fun h => ⟨⟨a, mem_orbit_self _⟩, fun ⟨a, ⟨x, hx⟩⟩ => Subtype.eq <| by simp [h x, hx.symm]⟩ [GOAL] M : Type u α : Type v inst✝² : Monoid M inst✝¹ : MulAction M α a✝ : α inst✝ : Fintype ↑(orbit M a✝) h : ∀ (m : M), m • a✝ = a✝ x✝ : ↑(orbit M a✝) a : α x : M hx : (fun m => m • a✝) x = a ⊢ ↑{ val := a, property := (_ : ∃ y, (fun m => m • a✝) y = a) } = ↑{ val := a✝, property := (_ : a✝ ∈ orbit M a✝) } [PROOFSTEP] simp [h x, hx.symm] [GOAL] case mpr M : Type u α : Type v inst✝² : Monoid M inst✝¹ : MulAction M α a : α inst✝ : Fintype ↑(orbit M a) ⊢ (∃ x, ∀ (y : ↑(orbit M a)), y = x) → ∀ (m : M), m • a = a [PROOFSTEP] intro h x [GOAL] case mpr M : Type u α : Type v inst✝² : Monoid M inst✝¹ : MulAction M α a : α inst✝ : Fintype ↑(orbit M a) h : ∃ x, ∀ (y : ↑(orbit M a)), y = x x : M ⊢ x • a = a [PROOFSTEP] rcases h with ⟨⟨z, hz⟩, hz₁⟩ [GOAL] case mpr.intro.mk M : Type u α : Type v inst✝² : Monoid M inst✝¹ : MulAction M α a : α inst✝ : Fintype ↑(orbit M a) x : M z : α hz : z ∈ orbit M a hz₁ : ∀ (y : ↑(orbit M a)), y = { val := z, property := hz } ⊢ x • a = a [PROOFSTEP] calc x • a = z := Subtype.mk.inj (hz₁ ⟨x • a, mem_orbit _ _⟩) _ = a := (Subtype.mk.inj (hz₁ ⟨a, mem_orbit_self _⟩)).symm [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a : α src✝ : Submonoid G := Stabilizer.submonoid G a m : G ha : m • a = a ⊢ m⁻¹ • a = a [PROOFSTEP] rw [inv_smul_eq_iff, ha] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α g : G a : α ⊢ orbit G a = orbit G (g⁻¹ • g • a) [PROOFSTEP] rw [inv_smul_smul] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a : α ⊢ ∀ (x y : ↑(orbit G a)), ∃ g, g • x = y [PROOFSTEP] rintro ⟨_, g, rfl⟩ ⟨_, h, rfl⟩ [GOAL] case mk.intro.mk.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a : α g h : G ⊢ ∃ g_1, g_1 • { val := (fun m => m • a) g, property := (_ : ∃ y, (fun m => m • a) y = (fun m => m • a) g) } = { val := (fun m => m • a) h, property := (_ : ∃ y, (fun m => m • a) y = (fun m => m • a) h) } [PROOFSTEP] use h * g⁻¹ [GOAL] case h G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a : α g h : G ⊢ (h * g⁻¹) • { val := (fun m => m • a) g, property := (_ : ∃ y, (fun m => m • a) y = (fun m => m • a) g) } = { val := (fun m => m • a) h, property := (_ : ∃ y, (fun m => m • a) y = (fun m => m • a) h) } [PROOFSTEP] ext1 [GOAL] case h.a G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a : α g h : G ⊢ ↑((h * g⁻¹) • { val := (fun m => m • a) g, property := (_ : ∃ y, (fun m => m • a) y = (fun m => m • a) g) }) = ↑{ val := (fun m => m • a) h, property := (_ : ∃ y, (fun m => m • a) y = (fun m => m • a) h) } [PROOFSTEP] simp [mul_smul] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α g : G a : α ⊢ a ∈ orbit G (g • a) [PROOFSTEP] simp only [orbit_smul, mem_orbit_self] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α g h : G a : α ⊢ g • a ∈ orbit G (h • a) [PROOFSTEP] simp only [orbit_smul, mem_orbit] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a b : α ⊢ a ∈ orbit G b → b ∈ orbit G a [PROOFSTEP] simp [orbit_eq_iff.symm, eq_comm] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a b : α ⊢ ∀ {z : α}, a ∈ orbit G b → b ∈ orbit G z → a ∈ orbit G z [PROOFSTEP] simp (config := { contextual := true }) [orbit_eq_iff.symm, eq_comm] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α ⊢ Quotient.mk' ⁻¹' (Quotient.mk' '' U) = ⋃ (g : G), (fun x x_1 => x • x_1) g '' U [PROOFSTEP] letI := orbitRel G α [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α ⊢ Quotient.mk' ⁻¹' (Quotient.mk' '' U) = ⋃ (g : G), (fun x x_1 => x • x_1) g '' U [PROOFSTEP] set f : α → Quotient (MulAction.orbitRel G α) := Quotient.mk' [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' ⊢ f ⁻¹' (f '' U) = ⋃ (g : G), (fun x x_1 => x • x_1) g '' U [PROOFSTEP] ext a [GOAL] case h G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α ⊢ a ∈ f ⁻¹' (f '' U) ↔ a ∈ ⋃ (g : G), (fun x x_1 => x • x_1) g '' U [PROOFSTEP] constructor [GOAL] case h.mp G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α ⊢ a ∈ f ⁻¹' (f '' U) → a ∈ ⋃ (g : G), (fun x x_1 => x • x_1) g '' U [PROOFSTEP] rintro ⟨b, hb, hab⟩ [GOAL] case h.mp.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a b : α hb : b ∈ U hab : f b = f a ⊢ a ∈ ⋃ (g : G), (fun x x_1 => x • x_1) g '' U [PROOFSTEP] obtain ⟨g, rfl⟩ := Quotient.exact hab [GOAL] case h.mp.intro.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G hb : (fun m => m • a) g ∈ U hab : f ((fun m => m • a) g) = f a ⊢ a ∈ ⋃ (g : G), (fun x x_1 => x • x_1) g '' U [PROOFSTEP] rw [Set.mem_iUnion] [GOAL] case h.mp.intro.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G hb : (fun m => m • a) g ∈ U hab : f ((fun m => m • a) g) = f a ⊢ ∃ i, a ∈ (fun x x_1 => x • x_1) i '' U [PROOFSTEP] exact ⟨g⁻¹, g • a, hb, inv_smul_smul g a⟩ [GOAL] case h.mpr G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α ⊢ a ∈ ⋃ (g : G), (fun x x_1 => x • x_1) g '' U → a ∈ f ⁻¹' (f '' U) [PROOFSTEP] intro hx [GOAL] case h.mpr G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α hx : a ∈ ⋃ (g : G), (fun x x_1 => x • x_1) g '' U ⊢ a ∈ f ⁻¹' (f '' U) [PROOFSTEP] rw [Set.mem_iUnion] at hx [GOAL] case h.mpr G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α hx : ∃ i, a ∈ (fun x x_1 => x • x_1) i '' U ⊢ a ∈ f ⁻¹' (f '' U) [PROOFSTEP] obtain ⟨g, u, hu₁, hu₂⟩ := hx [GOAL] case h.mpr.intro.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G u : α hu₁ : u ∈ U hu₂ : (fun x x_1 => x • x_1) g u = a ⊢ a ∈ f ⁻¹' (f '' U) [PROOFSTEP] rw [Set.mem_preimage, Set.mem_image_iff_bex] [GOAL] case h.mpr.intro.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G u : α hu₁ : u ∈ U hu₂ : (fun x x_1 => x • x_1) g u = a ⊢ ∃ x x_1, f x = f a [PROOFSTEP] refine' ⟨g⁻¹ • a, _, by simp only [Quotient.eq']; use g⁻¹⟩ [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G u : α hu₁ : u ∈ U hu₂ : (fun x x_1 => x • x_1) g u = a ⊢ f (g⁻¹ • a) = f a [PROOFSTEP] simp only [Quotient.eq'] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G u : α hu₁ : u ∈ U hu₂ : (fun x x_1 => x • x_1) g u = a ⊢ Setoid.r (g⁻¹ • a) a [PROOFSTEP] use g⁻¹ [GOAL] case h.mpr.intro.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G u : α hu₁ : u ∈ U hu₂ : (fun x x_1 => x • x_1) g u = a ⊢ g⁻¹ • a ∈ U [PROOFSTEP] rw [← hu₂] [GOAL] case h.mpr.intro.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G u : α hu₁ : u ∈ U hu₂ : (fun x x_1 => x • x_1) g u = a ⊢ g⁻¹ • (fun x x_1 => x • x_1) g u ∈ U [PROOFSTEP] convert hu₁ [GOAL] case h.e'_4 G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' a : α g : G u : α hu₁ : u ∈ U hu₂ : (fun x x_1 => x • x_1) g u = a ⊢ g⁻¹ • (fun x x_1 => x • x_1) g u = u [PROOFSTEP] simp only [inv_smul_smul] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α ⊢ Disjoint (Quotient.mk' '' U) (Quotient.mk' '' V) ↔ ∀ (x : α), x ∈ U → ∀ (g : G), ¬g • x ∈ V [PROOFSTEP] letI := orbitRel G α [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α this : Setoid α := orbitRel G α ⊢ Disjoint (Quotient.mk' '' U) (Quotient.mk' '' V) ↔ ∀ (x : α), x ∈ U → ∀ (g : G), ¬g • x ∈ V [PROOFSTEP] set f : α → Quotient (MulAction.orbitRel G α) := Quotient.mk' [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' ⊢ Disjoint (f '' U) (f '' V) ↔ ∀ (x : α), x ∈ U → ∀ (g : G), ¬g • x ∈ V [PROOFSTEP] refine' ⟨fun h a a_in_U g g_in_V => h.le_bot ⟨⟨a, a_in_U, Quotient.sound ⟨g⁻¹, _⟩⟩, ⟨g • a, g_in_V, rfl⟩⟩, _⟩ [GOAL] case refine'_1 G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' h : Disjoint (f '' U) (f '' V) a : α a_in_U : a ∈ U g : G g_in_V : g • a ∈ V ⊢ (fun m => m • g • a) g⁻¹ = a [PROOFSTEP] simp [GOAL] case refine'_2 G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' ⊢ (∀ (x : α), x ∈ U → ∀ (g : G), ¬g • x ∈ V) → Disjoint (f '' U) (f '' V) [PROOFSTEP] intro h [GOAL] case refine'_2 G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' h : ∀ (x : α), x ∈ U → ∀ (g : G), ¬g • x ∈ V ⊢ Disjoint (f '' U) (f '' V) [PROOFSTEP] rw [Set.disjoint_left] [GOAL] case refine'_2 G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' h : ∀ (x : α), x ∈ U → ∀ (g : G), ¬g • x ∈ V ⊢ ∀ ⦃a : Quotient (orbitRel G α)⦄, a ∈ f '' U → ¬a ∈ f '' V [PROOFSTEP] rintro _ ⟨b, hb₁, hb₂⟩ ⟨c, hc₁, hc₂⟩ [GOAL] case refine'_2.intro.intro.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' h : ∀ (x : α), x ∈ U → ∀ (g : G), ¬g • x ∈ V a✝ : Quotient (orbitRel G α) b : α hb₁ : b ∈ U hb₂ : f b = a✝ c : α hc₁ : c ∈ V hc₂ : f c = a✝ ⊢ False [PROOFSTEP] obtain ⟨g, rfl⟩ := Quotient.exact (hc₂.trans hb₂.symm) [GOAL] case refine'_2.intro.intro.intro.intro.intro G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α U V : Set α this : Setoid α := orbitRel G α f : α → Quotient (orbitRel G α) := Quotient.mk' h : ∀ (x : α), x ∈ U → ∀ (g : G), ¬g • x ∈ V a✝ : Quotient (orbitRel G α) b : α hb₁ : b ∈ U hb₂ : f b = a✝ g : G hc₁ : (fun m => m • b) g ∈ V hc₂ : f ((fun m => m • b) g) = a✝ ⊢ False [PROOFSTEP] exact h b hb₁ g hc₁ [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a : α x : Quotient G α ⊢ a ∈ orbit x ↔ Quotient.mk'' a = x [PROOFSTEP] induction x using Quotient.inductionOn' [GOAL] case h G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a a✝ : α ⊢ a ∈ orbit (Quotient.mk'' a✝) ↔ Quotient.mk'' a = Quotient.mk'' a✝ [PROOFSTEP] rw [Quotient.eq''] [GOAL] case h G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a a✝ : α ⊢ a ∈ orbit (Quotient.mk'' a✝) ↔ Setoid.r a a✝ [PROOFSTEP] rfl [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α x : Quotient G α φ : Quotient G α → α hφ : Function.RightInverse φ Quotient.mk' ⊢ orbit x = MulAction.orbit G (φ x) [PROOFSTEP] conv_lhs => rw [← hφ x] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α x : Quotient G α φ : Quotient G α → α hφ : Function.RightInverse φ Quotient.mk' | orbit x [PROOFSTEP] rw [← hφ x] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α x : Quotient G α φ : Quotient G α → α hφ : Function.RightInverse φ Quotient.mk' | orbit x [PROOFSTEP] rw [← hφ x] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α x : Quotient G α φ : Quotient G α → α hφ : Function.RightInverse φ Quotient.mk' | orbit x [PROOFSTEP] rw [← hφ x] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α g : G a : α ⊢ stabilizer G (g • a) = Subgroup.map (MulEquiv.toMonoidHom (↑MulAut.conj g)) (stabilizer G a) [PROOFSTEP] ext h [GOAL] case h G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α g : G a : α h : G ⊢ h ∈ stabilizer G (g • a) ↔ h ∈ Subgroup.map (MulEquiv.toMonoidHom (↑MulAut.conj g)) (stabilizer G a) [PROOFSTEP] rw [mem_stabilizer_iff, ← smul_left_cancel_iff g⁻¹, smul_smul, smul_smul, smul_smul, mul_left_inv, one_smul, ← mem_stabilizer_iff, Subgroup.mem_map_equiv, MulAut.conj_symm_apply] [GOAL] G : Type u α : Type v inst✝¹ : Group G inst✝ : MulAction G α a b : α h : Setoid.Rel (orbitRel G α) a b g : G := Classical.choose h hg : g • b = a ⊢ stabilizer G a = Subgroup.map (MulEquiv.toMonoidHom (↑MulAut.conj g)) (stabilizer G b) [PROOFSTEP] rw [← hg, stabilizer_smul_eq_stabilizer_map_conj] [GOAL] G : Type u α : Type v inst✝¹ : AddGroup G inst✝ : AddAction G α g : G a : α ⊢ stabilizer G (g +ᵥ a) = AddSubgroup.map (AddEquiv.toAddMonoidHom (↑AddAut.conj g)) (stabilizer G a) [PROOFSTEP] ext h [GOAL] case h G : Type u α : Type v inst✝¹ : AddGroup G inst✝ : AddAction G α g : G a : α h : G ⊢ h ∈ stabilizer G (g +ᵥ a) ↔ h ∈ AddSubgroup.map (AddEquiv.toAddMonoidHom (↑AddAut.conj g)) (stabilizer G a) [PROOFSTEP] rw [mem_stabilizer_iff, ← vadd_left_cancel_iff (-g), vadd_vadd, vadd_vadd, vadd_vadd, add_left_neg, zero_vadd, ← mem_stabilizer_iff, AddSubgroup.mem_map_equiv, AddAut.conj_symm_apply] [GOAL] G : Type u α : Type v inst✝¹ : AddGroup G inst✝ : AddAction G α a b : α h : Setoid.Rel (orbitRel G α) a b g : G := Classical.choose h hg : g +ᵥ b = a ⊢ stabilizer G a = AddSubgroup.map (AddEquiv.toAddMonoidHom (↑AddAut.conj g)) (stabilizer G b) [PROOFSTEP] rw [← hg, stabilizer_vadd_eq_stabilizer_map_conj] [GOAL] M : Type u_1 R : Type u_2 inst✝² : Monoid M inst✝¹ : NonUnitalNonAssocRing R inst✝ : DistribMulAction M R k : M h : ∀ (x : R), k • x = 0 → x = 0 a b : R h' : k • a = k • b ⊢ a = b [PROOFSTEP] rw [← sub_eq_zero] [GOAL] M : Type u_1 R : Type u_2 inst✝² : Monoid M inst✝¹ : NonUnitalNonAssocRing R inst✝ : DistribMulAction M R k : M h : ∀ (x : R), k • x = 0 → x = 0 a b : R h' : k • a = k • b ⊢ a - b = 0 [PROOFSTEP] refine' h _ _ [GOAL] M : Type u_1 R : Type u_2 inst✝² : Monoid M inst✝¹ : NonUnitalNonAssocRing R inst✝ : DistribMulAction M R k : M h : ∀ (x : R), k • x = 0 → x = 0 a b : R h' : k • a = k • b ⊢ k • (a - b) = 0 [PROOFSTEP] rw [smul_sub, h', sub_self]
# Decision Lens API # # No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # # OpenAPI spec version: 1.0 # # Generated by: https://github.com/swagger-api/swagger-codegen.git #' SpreadsheetReportProgress Class #' #' @field status #' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export SpreadsheetReportProgress <- R6::R6Class( 'SpreadsheetReportProgress', public = list( `status` = NULL, initialize = function(`status`){ if (!missing(`status`)) { stopifnot(R6::is.R6(`status`)) self$`status` <- `status` } }, toJSON = function() { SpreadsheetReportProgressObject <- list() if (!is.null(self$`status`)) { SpreadsheetReportProgressObject[['status']] <- self$`status`$toJSON() } SpreadsheetReportProgressObject }, fromJSON = function(SpreadsheetReportProgressJson) { SpreadsheetReportProgressObject <- dlensFromJSON(SpreadsheetReportProgressJson) if (!is.null(SpreadsheetReportProgressObject$`status`)) { statusObject <- SpreadsheetReportProgressStatus$new() statusObject$fromJSON(jsonlite::toJSON(SpreadsheetReportProgressObject$status, auto_unbox = TRUE)) self$`status` <- statusObject } }, toJSONString = function() { sprintf( '{ "status": %s }', self$`status`$toJSON() ) }, fromJSONString = function(SpreadsheetReportProgressJson) { SpreadsheetReportProgressObject <- dlensFromJSON(SpreadsheetReportProgressJson) SpreadsheetReportProgressStatusObject <- SpreadsheetReportProgressStatus$new() self$`status` <- SpreadsheetReportProgressStatusObject$fromJSON(jsonlite::toJSON(SpreadsheetReportProgressObject$status, auto_unbox = TRUE)) } ) )
(* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * * SPDX-License-Identifier: BSD-2-Clause *) theory initialised_decls imports "CParser.CTranslation" begin external_file "initialised_decls.c" install_C_file "initialised_decls.c" context initialised_decls_global_addresses begin thm f_body_def thm g_body_def end text \<open> Following proof confirms that we can prove stuff about g without needing to prove that f is side-effect free; which ain't true. The translation doesn't incorrectly reckon that the initialisation of local variable i is an "embedded" function call. This proof still works, but there aren't side-effect-free guards inserted at any point in the current translation so the point is a bit moot. \<close> lemma (in initialised_decls_global_addresses) foo: shows "\<Gamma> \<turnstile> \<lbrace> True \<rbrace> \<acute>ret__int :== PROC g() \<lbrace> \<acute>ret__int = 3 \<rbrace>" apply vcg done end
# include("plot/shader.jl") # include("plot/camera.jl") # include("plot/plot.jl") function plot(boxset::BoxSet{<:AbstractBoxPartition{<:Box{N}}}; kwargs...) where N m = HyperRectangle(GeometryBasics.Vec3f0(0), GeometryBasics.Vec3f0(1)) c = [box.center .- box.radius for box in boxset] r = [1.9 .* box.radius for box in boxset] fig, ax, ms = meshscatter(GeometryBasics.Vec{N, Float32}.(c), marker = m, markersize = r, color =:red; kwargs...) end function plot(boxfun::BoxFun{<:AbstractBoxPartition{<:Box{1}}}; kwargs...) c, r, v = Float32[], Float32[], Float32[] for (key, value) in boxfun.dict box = key_to_box(boxfun.partition, key) push!(c, box.center[1]) push!(r, 1.9 * box.radius[1]) push!(v, value) end fig, ax, bp = barplot(c, v, width = r; kwargs ...) end function plot(boxfun::BoxFun{<:AbstractBoxPartition{<:Box{3}}}; kwargs...) where N center, radius, color = GeometryBasics.Vec{3, Float32}[], GeometryBasics.Vec{3, Float32}[], Float32[] for (key, value) in boxfun.dict box = GAIO.key_to_box(boxfun.partition, key) push!(center, box.center) push!(radius, 1.9 .* box.radius) push!(color, value) end m = HyperRectangle(GeometryBasics.Vec3f0(0), GeometryBasics.Vec3f0(1)) fig = Figure() fig, ax, ms = meshscatter(center, marker = m, markersize = radius, color = color, colormap =:jet; kwargs...) Colorbar(fig[1,2], ms) fig end
section \<open>KBO\<close> text \<open> Below, we formalize a variant of KBO that includes subterm coefficient functions. A more standard definition is obtained by setting all subterm coefficients to 1. For this special case it would be possible to define more efficient code-equations that do not have to evaluate subterm coefficients at all. \<close> theory KBO imports Lexicographic_Extension Term_Aux Polynomial_Factorization.Missing_List begin subsection \<open>Subterm Coefficient Functions\<close> text \<open> Given a function @{term scf}, associating positions with subterm coefficients, and a list @{term xs}, the function @{term scf_list} yields an expanded list where each element of @{term xs} is replicated a number of times according to its subterm coefficient. \<close> definition scf_list :: "(nat \<Rightarrow> nat) \<Rightarrow> 'a list \<Rightarrow> 'a list" where "scf_list scf xs = concat (map (\<lambda>(x, i). replicate (scf i) x) (zip xs [0 ..< length xs]))" lemma set_scf_list [simp]: assumes "\<forall>i < length xs. scf i > 0" shows "set (scf_list scf xs) = set xs" using assms by (auto simp: scf_list_def set_zip set_conv_nth[of xs]) lemma scf_list_subset: "set (scf_list scf xs) \<subseteq> set xs" by (auto simp: scf_list_def set_zip) lemma scf_list_empty [simp]: "scf_list scf [] = []" by (auto simp: scf_list_def) lemma scf_list_bef_i_aft [simp]: "scf_list scf (bef @ i # aft) = scf_list scf bef @ replicate (scf (length bef)) i @ scf_list (\<lambda> i. scf (Suc (length bef + i))) aft" unfolding scf_list_def proof (induct aft rule: List.rev_induct) case (snoc a aft) define bia where "bia = bef @ i # aft" have bia: "bef @ i # aft @ [a] = bia @ [a]" by (simp add: bia_def) have zip: "zip (bia @ [a]) [0..<length (bia @ [a])] = zip bia [0..<length bia] @ [(a, length bia)]" by simp have concat: "concat (map (\<lambda>(x, i). replicate (scf i) x) (zip bia [0..<length bia] @ [(a, length bia)])) = concat (map (\<lambda>(x, i). replicate (scf i) x) (zip bia [0..<length bia])) @ replicate (scf (length bia)) a" by simp show ?case unfolding bia zip concat unfolding bia_def snoc by simp qed simp text \<open> The function @{term scf_term} replicates each argument a number of times according to its subterm coefficient function. \<close> fun scf_term :: "('f \<times> nat \<Rightarrow> nat \<Rightarrow> nat) \<Rightarrow> ('f, 'v) term \<Rightarrow> ('f, 'v) term" where "scf_term scf (Var x) = (Var x)" | "scf_term scf (Fun f ts) = Fun f (scf_list (scf (f, length ts)) (map (scf_term scf) ts))" lemma vars_term_scf_subset: "vars_term (scf_term scf s) \<subseteq> vars_term s" proof (induct s) case (Fun f ss) have "vars_term (scf_term scf (Fun f ss)) = (\<Union>x\<in>set (scf_list (scf (f, length ss)) ss). vars_term (scf_term scf x))" by auto also have "\<dots> \<subseteq> (\<Union>x\<in>set ss. vars_term (scf_term scf x))" using scf_list_subset [of _ ss] by blast also have "\<dots> \<subseteq> (\<Union>x\<in>set ss. vars_term x)" using Fun by auto finally show ?case by auto qed auto lemma scf_term_subst: "scf_term scf (t \<cdot> \<sigma>) = scf_term scf t \<cdot> (\<lambda> x. scf_term scf (\<sigma> x))" proof (induct t) case (Fun f ts) { fix t assume "t \<in> set (scf_list (scf (f, length ts)) ts)" with scf_list_subset [of _ ts] have "t \<in> set ts" by auto then have "scf_term scf (t \<cdot> \<sigma>) = scf_term scf t \<cdot> (\<lambda>x. scf_term scf (\<sigma> x))" by (rule Fun) } then show ?case by auto qed auto subsection \<open>Weight Functions\<close> locale weight_fun = fixes w :: "'f \<times> nat \<Rightarrow> nat" and w0 :: nat and scf :: "'f \<times> nat \<Rightarrow> nat \<Rightarrow> nat" begin text \<open> The \<^emph>\<open>weight\<close> of a term is computed recursively, where variables have weight @{term w0} and the weight of a compound term is computed by adding the weight of its root symbol @{term "w (f, n)"} to the weighted sum where weights of arguments are multiplied according to their subterm coefficients. \<close> fun weight :: "('f, 'v) term \<Rightarrow> nat" where "weight (Var x) = w0" | "weight (Fun f ts) = (let n = length ts; scff = scf (f, n) in w (f, n) + sum_list (map (\<lambda> (ti, i). weight ti * scff i) (zip ts [0 ..< n])))" text \<open> Alternatively, we can replicate arguments via @{const scf_list}. The advantage is that then both @{const weight} and @{const scf_term} are defined via @{const scf_list}. \<close> lemma weight_simp [simp]: "weight (Fun f ts) = w (f, length ts) + sum_list (map weight (scf_list (scf (f, length ts)) ts))" proof - define scff where "scff = (scf (f, length ts) :: nat \<Rightarrow> nat)" have "(\<Sum>(ti, i) \<leftarrow> zip ts [0..<length ts]. weight ti * scff i) = sum_list (map weight (scf_list scff ts))" proof (induct ts rule: List.rev_induct) case (snoc t ts) moreover { fix n have "sum_list (replicate n (weight t)) = n * weight t" by (induct n) auto } ultimately show ?case by (simp add: scf_list_def) qed simp then show ?thesis by (simp add: Let_def scff_def) qed declare weight.simps(2)[simp del] abbreviation "SCF \<equiv> scf_term scf" lemma sum_list_scf_list: assumes "\<And> i. i < length ts \<Longrightarrow> f i > 0" shows "sum_list (map weight ts) \<le> sum_list (map weight (scf_list f ts))" using assms unfolding scf_list_def proof (induct ts rule: List.rev_induct) case (snoc t ts) have "sum_list (map weight ts) \<le> sum_list (map weight (concat (map (\<lambda>(x, i). replicate (f i) x) (zip ts [0..<length ts]))))" by (auto intro!: snoc) moreover from snoc(2) [of "length ts"] obtain n where "f (length ts) = Suc n" by (auto elim: lessE) ultimately show ?case by simp qed simp end subsection \<open>Definition of KBO\<close> text \<open> The precedence is given by three parameters: \<^item> a predicate @{term pr_strict} for strict decrease between two function symbols, \<^item> a predicate @{term pr_weak} for weak decrease between two function symbols, and \<^item> a function indicating whether a symbol is least in the precedence. \<close> locale kbo = weight_fun w w0 scf for w w0 and scf :: "'f \<times> nat \<Rightarrow> nat \<Rightarrow> nat" + fixes least :: "'f \<Rightarrow> bool" and pr_strict :: "'f \<times> nat \<Rightarrow> 'f \<times> nat \<Rightarrow> bool" and pr_weak :: "'f \<times> nat \<Rightarrow> 'f \<times> nat \<Rightarrow> bool" begin text \<open> The result of @{term kbo} is a pair of Booleans encoding strict/weak decrease. Interestingly, the bound on the lengths of the lists in the lexicographic extension is not required for KBO. \<close> fun kbo :: "('f, 'v) term \<Rightarrow> ('f, 'v) term \<Rightarrow> bool \<times> bool" where "kbo s t = (if (vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF s) \<and> weight t \<le> weight s) then if (weight t < weight s) then (True, True) else (case s of Var y \<Rightarrow> (False, (case t of Var x \<Rightarrow> x = y | Fun g ts \<Rightarrow> ts = [] \<and> least g)) | Fun f ss \<Rightarrow> (case t of Var x \<Rightarrow> (True, True) | Fun g ts \<Rightarrow> if pr_strict (f, length ss) (g, length ts) then (True, True) else if pr_weak (f, length ss) (g, length ts) then lex_ext_unbounded kbo ss ts else (False, False))) else (False, False))" text \<open>Abbreviations for strict (S) and nonstrict (NS) KBO.\<close> abbreviation "S \<equiv> \<lambda> s t. fst (kbo s t)" abbreviation "NS \<equiv> \<lambda> s t. snd (kbo s t)" text \<open> For code-generation we do not compute the weights of @{term s} and @{term t} repeatedly. \<close> lemma kbo_code: "kbo s t = (let wt = weight t; ws = weight s in if (vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF s) \<and> wt \<le> ws) then if wt < ws then (True, True) else (case s of Var y \<Rightarrow> (False, (case t of Var x \<Rightarrow> True | Fun g ts \<Rightarrow> ts = [] \<and> least g)) | Fun f ss \<Rightarrow> (case t of Var x \<Rightarrow> (True, True) | Fun g ts \<Rightarrow> let ff = (f, length ss); gg = (g, length ts) in if pr_strict ff gg then (True, True) else if pr_weak ff gg then lex_ext_unbounded kbo ss ts else (False, False))) else (False, False))" unfolding kbo.simps[of s t] Let_def by (auto simp del: kbo.simps split: term.splits) end declare kbo.kbo_code[code] declare weight_fun.weight.simps[code] lemma mset_replicate_mono: assumes "m1 \<subseteq># m2" shows "\<Union># (mset (replicate n m1)) \<subseteq># \<Union># (mset (replicate n m2))" proof (induct n) case (Suc n) have "\<Union># (mset (replicate (Suc n) m1)) = \<Union># (mset (replicate n m1)) + m1" by simp also have "\<dots> \<subseteq># \<Union># (mset (replicate n m1)) + m2" using \<open>m1 \<subseteq># m2\<close> by auto also have "\<dots> \<subseteq># \<Union># (mset (replicate n m2)) + m2" using Suc by auto finally show ?case by (simp add: union_commute) qed simp text \<open> While the locale @{locale kbo} only fixes its parameters, we now demand that these parameters are sensible, e.g., encoding a well-founded precedence, etc. \<close> locale admissible_kbo = kbo w w0 scf least pr_strict pr_weak for w w0 pr_strict pr_weak and least :: "'f \<Rightarrow> bool" and scf + assumes w0: "w (f, 0) \<ge> w0" "w0 > 0" and adm: "w (f, 1) = 0 \<Longrightarrow> pr_weak (f, 1) (g, n)" and least: "least f = (w (f, 0) = w0 \<and> (\<forall> g. w (g, 0) = w0 \<longrightarrow> pr_weak (g, 0) (f, 0)))" and scf: "i < n \<Longrightarrow> scf (f, n) i > 0" and pr_weak_refl [simp]: "pr_weak fn fn" and pr_weak_trans: "pr_weak fn gm \<Longrightarrow> pr_weak gm hk \<Longrightarrow> pr_weak fn hk" and pr_strict: "pr_strict fn gm \<longleftrightarrow> pr_weak fn gm \<and> \<not> pr_weak gm fn" and pr_SN: "SN {(fn, gm). pr_strict fn gm}" begin lemma weight_w0: "weight t \<ge> w0" proof (induct t) case (Fun f ts) show ?case proof (cases ts) case Nil with w0(1) have "w0 \<le> w (f, length ts)" by auto then show ?thesis by auto next case (Cons s ss) then obtain i where i: "i < length ts" by auto from scf[OF this] have scf: "0 < scf (f, length ts) i" by auto then obtain n where scf: "scf (f, length ts) i = Suc n" by (auto elim: lessE) from id_take_nth_drop[OF i] i obtain bef aft where ts: "ts = bef @ ts ! i # aft" and ii: "length bef = i" by auto define tsi where "tsi = ts ! i" note ts = ts[folded tsi_def] from i have tsi: "tsi \<in> set ts" unfolding tsi_def by auto from Fun[OF this] have w0: "w0 \<le> weight tsi" . show ?thesis using scf ii w0 unfolding ts by simp qed qed simp lemma weight_gt_0: "weight t > 0" using weight_w0 [of t] and w0 by arith lemma weight_0 [iff]: "weight t = 0 \<longleftrightarrow> False" using weight_gt_0 [of t] by auto lemma not_S_Var: "\<not> S (Var x) t" using weight_w0[of t] by (cases t, auto) lemma S_imp_NS: "S s t \<Longrightarrow> NS s t" proof (induct s t rule: kbo.induct) case (1 s t) from 1(2) have S: "S s t" . from S have w: "vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF s) \<and> weight t \<le> weight s" by (auto split: if_splits) note S = S w note IH = 1(1)[OF w] show ?case proof (cases "weight t < weight s") case True with S show ?thesis by simp next case False note IH = IH[OF False] note S = S False from not_S_Var[of _ t] S obtain f ss where s: "s = Fun f ss" by (cases s, auto) note IH = IH[OF s] show ?thesis proof (cases t) case (Var x) from S show ?thesis by (auto, insert Var s, auto) next case (Fun g ts) note IH = IH[OF Fun] let ?f = "(f, length ss)" let ?g = "(g, length ts)" let ?lex = "lex_ext_unbounded kbo ss ts" from S[simplified, unfolded s Fun] have disj: "pr_strict ?f ?g \<or> pr_weak ?f ?g \<and> fst ?lex" by (auto split: if_splits) show ?thesis proof (cases "pr_strict ?f ?g") case True then show ?thesis using S s Fun by auto next case False with disj have fg: "pr_weak ?f ?g" and lex: "fst ?lex" by auto note IH = IH[OF False fg] from lex have "fst (lex_ext kbo (length ss + length ts) ss ts)" unfolding lex_ext_def Let_def by auto from lex_ext_stri_imp_nstri[OF this] have lex: "snd ?lex" unfolding lex_ext_def Let_def by auto with False fg S s Fun show ?thesis by auto qed qed qed qed subsection \<open>Reflexivity and Irreflexivity\<close> lemma NS_refl: "NS s s" proof (induct s) case (Fun f ss) have "snd (lex_ext kbo (length ss) ss ss)" by (rule all_nstri_imp_lex_nstri, insert Fun[unfolded set_conv_nth], auto) then have "snd (lex_ext_unbounded kbo ss ss)" unfolding lex_ext_def Let_def by simp then show ?case by auto qed simp lemma pr_strict_irrefl: "\<not> pr_strict fn fn" unfolding pr_strict by auto lemma S_irrefl: "\<not> S t t" proof (induct t) case (Var x) then show ?case by (rule not_S_Var) next case (Fun f ts) from pr_strict_irrefl have "\<not> pr_strict (f, length ts) (f, length ts)" . moreover { assume "fst (lex_ext_unbounded kbo ts ts)" then obtain i where "i < length ts" and "S (ts ! i) (ts ! i)" unfolding lex_ext_unbounded_iff by auto with Fun have False by auto } ultimately show ?case by auto qed subsection \<open>Monotonicity (a.k.a. Closure under Contexts)\<close> lemma S_mono_one: assumes S: "S s t" shows "S (Fun f (ss1 @ s # ss2)) (Fun f (ss1 @ t # ss2))" proof - let ?ss = "ss1 @ s # ss2" let ?ts = "ss1 @ t # ss2" let ?s = "Fun f ?ss" let ?t = "Fun f ?ts" from S have w: "weight t \<le> weight s" and v: "vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF s)" by (auto split: if_splits) have v': "vars_term_ms (SCF ?t) \<subseteq># vars_term_ms (SCF ?s)" using mset_replicate_mono[OF v] by simp have w': "weight ?t \<le> weight ?s" using sum_list_replicate_mono[OF w] by simp have lex: "fst (lex_ext_unbounded kbo ?ss ?ts)" unfolding lex_ext_unbounded_iff fst_conv by (rule disjI1, rule exI[of _ "length ss1"], insert S NS_refl, auto simp del: kbo.simps simp: nth_append) show ?thesis using v' w' lex by simp qed lemma S_ctxt: "S s t \<Longrightarrow> S (C\<langle>s\<rangle>) (C\<langle>t\<rangle>)" by (induct C, auto simp del: kbo.simps intro: S_mono_one) lemma NS_mono_one: assumes NS: "NS s t" shows "NS (Fun f (ss1 @ s # ss2)) (Fun f (ss1 @ t # ss2))" proof - let ?ss = "ss1 @ s # ss2" let ?ts = "ss1 @ t # ss2" let ?s = "Fun f ?ss" let ?t = "Fun f ?ts" from NS have w: "weight t \<le> weight s" and v: "vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF s)" by (auto split: if_splits) have v': "vars_term_ms (SCF ?t) \<subseteq># vars_term_ms (SCF ?s)" using mset_replicate_mono[OF v] by simp have w': "weight ?t \<le> weight ?s" using sum_list_replicate_mono[OF w] by simp have lex: "snd (lex_ext_unbounded kbo ?ss ?ts)" unfolding lex_ext_unbounded_iff snd_conv proof (intro disjI2 conjI allI impI) fix i assume "i < length (ss1 @ t # ss2)" then show "NS (?ss ! i) (?ts ! i)" using NS NS_refl by (cases "i = length ss1", auto simp del: kbo.simps simp: nth_append) qed simp show ?thesis using v' w' lex by simp qed lemma NS_ctxt: "NS s t \<Longrightarrow> NS (C\<langle>s\<rangle>) (C\<langle>t\<rangle>)" by (induct C, auto simp del: kbo.simps intro: NS_mono_one) subsection \<open>The Subterm Property\<close> lemma NS_Var_imp_eq_least: "NS (Var x) t \<Longrightarrow> t = Var x \<or> (\<exists> f. t = Fun f [] \<and> least f)" by (cases t, insert weight_w0[of t], auto split: if_splits) lemma kbo_supt_one: "NS s (t :: ('f, 'v) term) \<Longrightarrow> S (Fun f (bef @ s # aft)) t" proof (induct t arbitrary: f s bef aft) case (Var x) note NS = this let ?ss = "bef @ s # aft" let ?t = "Var x" have "length bef < length ?ss" by auto from scf[OF this, of f] obtain n where scf:"scf (f, length ?ss) (length bef) = Suc n" by (auto elim: lessE) obtain X where "vars_term_ms (SCF (Fun f ?ss)) = vars_term_ms (SCF s) + X" by (simp add: o_def scf[simplified]) then have vs: "vars_term_ms (SCF s) \<subseteq># vars_term_ms (SCF (Fun f ?ss))" by simp from NS have vt: "vars_term_ms (SCF ?t) \<subseteq># vars_term_ms (SCF s)" by (auto split: if_splits) from vt vs have v: "vars_term_ms (SCF ?t) \<subseteq># vars_term_ms (SCF (Fun f ?ss))" by (rule subset_mset.order_trans) from weight_w0[of "Fun f ?ss"] v show ?case by simp next case (Fun g ts f s bef aft) let ?t = "Fun g ts" let ?ss = "bef @ s # aft" note NS = Fun(2) note IH = Fun(1) have "length bef < length ?ss" by auto from scf[OF this, of f] obtain n where scff:"scf (f, length ?ss) (length bef) = Suc n" by (auto elim: lessE) note scff = scff[simplified] obtain X where "vars_term_ms (SCF (Fun f ?ss)) = vars_term_ms (SCF s) + X" by (simp add: o_def scff) then have vs: "vars_term_ms (SCF s) \<subseteq># vars_term_ms (SCF (Fun f ?ss))" by simp have ws: "weight s \<le> sum_list (map weight (scf_list (scf (f, length ?ss)) ?ss))" by (simp add: scff) from NS have wt: "weight ?t \<le> weight s" and vt: "vars_term_ms (SCF ?t) \<subseteq># vars_term_ms (SCF s)" by (auto split: if_splits) from ws wt have w: "weight ?t \<le> sum_list (map weight (scf_list (scf (f, length ?ss)) ?ss))" by simp from vt vs have v: "vars_term_ms (SCF ?t) \<subseteq># vars_term_ms (SCF (Fun f ?ss))" by auto then have v': "(vars_term_ms (SCF ?t) \<subseteq># vars_term_ms (SCF (Fun f ?ss))) = True" by simp show ?case proof (cases "weight ?t = weight (Fun f ?ss)") case False with w v show ?thesis by auto next case True from wt[unfolded True] weight_gt_0[of s] have wf: "w (f, length ?ss) = 0" and lsum: "sum_list (map weight (scf_list (scf (f, length ?ss)) bef)) = 0" "sum_list (map weight (scf_list (\<lambda> i. (scf (f, length ?ss) (Suc (length bef) + i))) aft)) = 0" and n: "n = 0" by (auto simp: scff) have "sum_list (map weight bef) \<le> sum_list (map weight (scf_list (scf (f, length ?ss)) bef))" by (rule sum_list_scf_list, rule scf, auto) with lsum(1) have "sum_list (map weight bef) = 0" by arith then have bef: "bef = []" using weight_gt_0[of "hd bef"] by (cases bef, auto) have "sum_list (map weight aft) \<le> sum_list (map weight (scf_list (\<lambda> i. (scf (f, length ?ss) (Suc (length bef) + i))) aft))" by (rule sum_list_scf_list, rule scf, auto) with lsum(2) have "sum_list (map weight aft) = 0" by arith then have aft: "aft = []" using weight_gt_0[of "hd aft"] by (cases aft, auto) note scff = scff[unfolded bef aft n, simplified] from bef aft have ba: "bef @ s # aft = [s]" by simp with wf have wf: "w (f, 1) = 0" by auto from wf have wst: "weight s = weight ?t" using scff unfolding True[unfolded ba] by (simp add: scf_list_def) let ?g = "(g, length ts)" let ?f = "(f, 1)" show ?thesis proof (cases "pr_strict ?f ?g") case True with w v show ?thesis unfolding ba by simp next case False note admf = adm[OF wf] from admf have pg: "pr_weak ?f ?g" . from pg False[unfolded pr_strict] have "pr_weak ?g ?f" by auto from pr_weak_trans[OF this admf] have g: "\<And> h k. pr_weak ?g (h, k)" . show ?thesis proof (cases ts) case Nil have "fst (lex_ext_unbounded kbo [s] ts)" unfolding Nil lex_ext_unbounded_iff by auto with pg w v show ?thesis unfolding ba by simp next case (Cons t tts) { fix x assume s: "s = Var x" from NS_Var_imp_eq_least[OF NS[unfolded s Cons]] have False by auto } then obtain h ss where s: "s = Fun h ss" by (cases s, auto) from NS wst g[of h "length ss"] pr_strict[of "(h, length ss)" "(g, length ts)"] have lex: "snd (lex_ext_unbounded kbo ss ts)" unfolding s by (auto split: if_splits) from lex obtain s0 sss where ss: "ss = s0 # sss" unfolding Cons lex_ext_unbounded_iff snd_conv by (cases ss, auto) from lex[unfolded ss Cons] have "S s0 t \<or> NS s0 t" by (cases "kbo s0 t", simp add: lex_ext_unbounded.simps del: kbo.simps split: if_splits) with S_imp_NS[of s0 t] have "NS s0 t" by blast from IH[OF _ this, of h Nil sss] have S: "S s t" unfolding Cons s ss by simp have "fst (lex_ext_unbounded kbo [s] ts)" unfolding Cons unfolding lex_ext_unbounded_iff fst_conv by (rule disjI1[OF exI[of _ 0]], insert S, auto simp del: kbo.simps) then have lex: "fst (lex_ext_unbounded kbo [s] ts) = True" by simp note all = lex wst[symmetric] S pg scff v' note all = all[unfolded ba, unfolded s ss Cons] have w: "weight (Fun f [t]) = weight (t :: ('f, 'v) term)" for t using wf scff by (simp add: scf_list_def) show ?thesis unfolding ba unfolding s ss Cons unfolding kbo.simps[of "Fun f [Fun h (s0 # sss)]"] unfolding all w using all by simp qed qed qed qed lemma S_supt: assumes supt: "s \<rhd> t" shows "S s t" proof - from supt obtain C where s: "s = C\<langle>t\<rangle>" and C: "C \<noteq> \<box>" by auto show ?thesis unfolding s using C proof (induct C arbitrary: t) case (More f bef C aft t) show ?case proof (cases "C = \<box>") case True from kbo_supt_one[OF NS_refl, of f bef t aft] show ?thesis unfolding True by simp next case False from kbo_supt_one[OF S_imp_NS[OF More(1)[OF False]], of f bef t aft] show ?thesis by simp qed qed simp qed lemma NS_supteq: assumes "s \<unrhd> t" shows "NS s t" using S_imp_NS[OF S_supt[of s t]] NS_refl[of s] using assms[unfolded subterm.le_less] by blast subsection \<open>Least Elements\<close> lemma NS_all_least: assumes l: "least f" shows "NS t (Fun f [])" proof (induct t) case (Var x) show ?case using l[unfolded least] l by auto next case (Fun g ts) show ?case proof (cases ts) case (Cons s ss) with Fun[of s] have "NS s (Fun f [])" by auto from S_imp_NS[OF kbo_supt_one[OF this, of g Nil ss]] show ?thesis unfolding Cons by simp next case Nil from weight_w0[of "Fun g []"] have w: "weight (Fun g []) \<ge> weight (Fun f [])" using l[unfolded least] by auto from lex_ext_least_1 have "snd (lex_ext kbo 0 [] [])" . then have lex: "snd (lex_ext_unbounded kbo [] [])" unfolding lex_ext_def Let_def by simp then show ?thesis using w l[unfolded least] unfolding Fun Nil by (auto simp: empty_le) qed qed lemma not_S_least: assumes l: "least f" shows "\<not> S (Fun f []) t" proof (cases t) case (Fun g ts) show ?thesis unfolding Fun proof assume S: "S (Fun f []) (Fun g ts)" from S[unfolded Fun, simplified] have w: "w (g, length ts) + sum_list (map weight (scf_list (scf (g, length ts)) ts)) \<le> weight (Fun f [])" by (auto split: if_splits) show False proof (cases ts) case Nil with w have "w (g, 0) \<le> weight (Fun f [])" by simp also have "weight (Fun f []) \<le> w0" using l[unfolded least] by simp finally have g: "w (g, 0) = w0" using w0(1)[of g] by auto with w Nil l[unfolded least] have gf: "w (g, 0) = w (f, 0)" by simp with S have p: "pr_weak (f, 0) (g, 0)" unfolding Nil by (simp split: if_splits add: pr_strict) with l[unfolded least, THEN conjunct2, rule_format, OF g] have p2: "pr_weak (g, 0) (f, 0)" by auto from p p2 gf S have "fst (lex_ext_unbounded kbo [] ts)" unfolding Nil by (auto simp: pr_strict) then show False unfolding lex_ext_unbounded_iff by auto next case (Cons s ss) then have ts: "ts = [] @ s # ss" by auto from scf[of 0 "length ts" g] obtain n where scff: "scf (g, length ts) 0 = Suc n" unfolding Cons by (auto elim: lessE) let ?e = "sum_list (map weight ( scf_list (\<lambda>i. scf (g, Suc (length ss)) (Suc i)) ss ))" have "w0 + sum_list (map weight (replicate n s)) \<le> weight s + sum_list (map weight (replicate n s))" using weight_w0[of s] by auto also have "\<dots> = sum_list (map weight (replicate (scf (g, length ts) 0) s))" unfolding scff by simp also have "w (g, length ts) + \<dots> + ?e \<le> w0" using w l[unfolded least] unfolding ts scf_list_bef_i_aft by auto finally have "w0 + sum_list (map weight (replicate n s)) + w (g, length ts) + ?e \<le> w0" by arith then have wg: "w (g, length ts) = 0" and null: "?e = 0" "sum_list (map weight (replicate n s)) = 0" by auto from null(2) weight_gt_0[of s] have n: "n = 0" by (cases n, auto) have "sum_list (map weight ss) \<le> ?e" by (rule sum_list_scf_list, rule scf, auto) from this[unfolded null] weight_gt_0[of "hd ss"] have ss: "ss = []" by (cases ss, auto) with Cons have ts: "ts = [s]" by simp note scff = scff[unfolded ts n, simplified] from wg ts have wg: "w (g, 1) = 0" by auto from adm[OF wg, rule_format, of f] have "pr_weak (g, 1) (f, 0)" by auto with S[unfolded Fun ts] l[unfolded least] weight_w0[of s] scff have "fst (lex_ext_unbounded kbo [] [s])" by (auto split: if_splits simp: scf_list_def pr_strict) then show ?thesis unfolding lex_ext_unbounded_iff by auto qed qed qed simp lemma NS_least_least: assumes l: "least f" and NS: "NS (Fun f []) t" shows "\<exists> g. t = Fun g [] \<and> least g" proof (cases t) case (Var x) show ?thesis using NS unfolding Var by simp next case (Fun g ts) from NS[unfolded Fun, simplified] have w: "w (g, length ts) + sum_list (map weight (scf_list (scf (g, length ts)) ts)) \<le> weight (Fun f [])" by (auto split: if_splits) show ?thesis proof (cases ts) case Nil with w have "w (g, 0) \<le> weight (Fun f [])" by simp also have "weight (Fun f []) \<le> w0" using l[unfolded least] by simp finally have g: "w (g, 0) = w0" using w0(1)[of g] by auto with w Nil l[unfolded least] have gf: "w (g, 0) = w (f, 0)" by simp with NS[unfolded Fun] have p: "pr_weak (f, 0) (g, 0)" unfolding Nil by (simp split: if_splits add: pr_strict) have least: "least g" unfolding least proof (rule conjI[OF g], intro allI) fix h from l[unfolded least] have "w (h, 0) = w0 \<longrightarrow> pr_weak (h, 0) (f, 0)" by blast with pr_weak_trans p show "w (h, 0) = w0 \<longrightarrow> pr_weak (h, 0) (g, 0)" by blast qed show ?thesis by (rule exI[of _ g], unfold Fun Nil, insert least, auto) next case (Cons s ss) then have ts: "ts = [] @ s # ss" by auto from scf[of 0 "length ts" g] obtain n where scff: "scf (g, length ts) 0 = Suc n" unfolding Cons by (auto elim: lessE) let ?e = "sum_list (map weight ( scf_list (\<lambda>i. scf (g, Suc (length ss)) (Suc i)) ss ))" have "w0 + sum_list (map weight (replicate n s)) \<le> weight s + sum_list (map weight (replicate n s))" using weight_w0[of s] by auto also have "\<dots> = sum_list (map weight (replicate (scf (g, length ts) 0) s))" unfolding scff by simp also have "w (g, length ts) + \<dots> + ?e \<le> w0" using w l[unfolded least] unfolding ts scf_list_bef_i_aft by auto finally have "w0 + sum_list (map weight (replicate n s)) + w (g, length ts) + ?e \<le> w0" by arith then have wg: "w (g, length ts) = 0" and null: "?e = 0" "sum_list (map weight (replicate n s)) = 0" by auto from null(2) weight_gt_0[of s] have n: "n = 0" by (cases n, auto) have "sum_list (map weight ss) \<le> ?e" by (rule sum_list_scf_list, rule scf, auto) from this[unfolded null] weight_gt_0[of "hd ss"] have ss: "ss = []" by (cases ss, auto) with Cons have ts: "ts = [s]" by simp note scff = scff[unfolded ts n, simplified] from wg ts have wg: "w (g, 1) = 0" by auto from adm[OF wg, rule_format, of f] have "pr_weak (g, 1) (f, 0)" by auto with NS[unfolded Fun ts] l[unfolded least] weight_w0[of s] scff have "snd (lex_ext_unbounded kbo [] [s])" by (auto split: if_splits simp: scf_list_def pr_strict) then show ?thesis unfolding lex_ext_unbounded_iff snd_conv by auto qed qed subsection \<open>Stability (a.k.a. Closure under Substitutions\<close> lemma weight_subst: "weight (t \<cdot> \<sigma>) = weight t + sum_mset (image_mset (\<lambda> x. weight (\<sigma> x) - w0) (vars_term_ms (SCF t)))" proof (induct t) case (Var x) show ?case using weight_w0[of "\<sigma> x"] by auto next case (Fun f ts) let ?ts = "scf_list (scf (f, length ts)) ts" define sts where "sts = ?ts" have id: "map (\<lambda> t. weight (t \<cdot> \<sigma>)) ?ts = map (\<lambda> t. weight t + sum_mset (image_mset (\<lambda> x. weight (\<sigma> x) - w0) (vars_term_ms (scf_term scf t)))) ?ts" by (rule map_cong[OF refl Fun], insert scf_list_subset[of _ ts], auto) show ?case by (simp add: o_def id, unfold sts_def[symmetric], induct sts, auto) qed lemma weight_stable_le: assumes ws: "weight s \<le> weight t" and vs: "vars_term_ms (SCF s) \<subseteq># vars_term_ms (SCF t)" shows "weight (s \<cdot> \<sigma>) \<le> weight (t \<cdot> \<sigma>)" proof - from vs[unfolded mset_subset_eq_exists_conv] obtain u where vt: "vars_term_ms (SCF t) = vars_term_ms (SCF s) + u" .. show ?thesis unfolding weight_subst vt using ws by auto qed lemma weight_stable_lt: assumes ws: "weight s < weight t" and vs: "vars_term_ms (SCF s) \<subseteq># vars_term_ms (SCF t)" shows "weight (s \<cdot> \<sigma>) < weight (t \<cdot> \<sigma>)" proof - from vs[unfolded mset_subset_eq_exists_conv] obtain u where vt: "vars_term_ms (SCF t) = vars_term_ms (SCF s) + u" .. show ?thesis unfolding weight_subst vt using ws by auto qed text \<open>KBO is stable, i.e., closed under substitutions.\<close> lemma kbo_stable: fixes \<sigma> :: "('f, 'v) subst" assumes "NS s t" shows "(S s t \<longrightarrow> S (s \<cdot> \<sigma>) (t \<cdot> \<sigma>)) \<and> NS (s \<cdot> \<sigma>) (t \<cdot> \<sigma>)" (is "?P s t") using assms proof (induct s arbitrary: t) case (Var y t) then have not: "\<not> S (Var y) t" using not_S_Var[of y t] by auto from NS_Var_imp_eq_least[OF Var] have "t = Var y \<or> (\<exists> f. t = Fun f [] \<and> least f)" by simp then obtain f where "t = Var y \<or> t = Fun f [] \<and> least f" by auto then have "NS (Var y \<cdot> \<sigma>) (t \<cdot> \<sigma>)" proof assume "t = Var y" then show ?thesis using NS_refl[of "t \<cdot> \<sigma>"] by auto next assume "t = Fun f [] \<and> least f" with NS_all_least[of f "Var y \<cdot> \<sigma>"] show ?thesis by auto qed with not show ?case by blast next case (Fun f ss t) note NS = Fun(2) note IH = Fun(1) let ?s = "Fun f ss" define s where "s = ?s" let ?ss = "map (\<lambda> s. s \<cdot> \<sigma>) ss" from NS have v: "vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF ?s)" and w: "weight t \<le> weight ?s" by (auto split: if_splits) from weight_stable_le[OF w v] have w\<sigma>: "weight (t \<cdot> \<sigma>) \<le> weight (?s \<cdot> \<sigma>)" by auto from vars_term_ms_subst_mono[OF v, of "\<lambda> x. SCF (\<sigma> x)"] have v\<sigma>: "vars_term_ms (SCF (t \<cdot> \<sigma>)) \<subseteq># vars_term_ms (SCF (?s \<cdot> \<sigma>))" unfolding scf_term_subst . show ?case proof (cases "weight (t \<cdot> \<sigma>) < weight (?s \<cdot> \<sigma>)") case True with v\<sigma> show ?thesis by auto next case False with weight_stable_lt[OF _ v, of \<sigma>] w have w: "weight t = weight ?s" by arith show ?thesis proof (cases t) case (Var y) from set_mset_mono[OF v, folded s_def] have "y \<in> vars_term (SCF s)" unfolding Var by (auto simp: o_def) also have "\<dots> \<subseteq> vars_term s" by (rule vars_term_scf_subset) finally have "y \<in> vars_term s" by auto from supteq_Var[OF this] have "?s \<rhd> Var y" unfolding s_def Fun by auto from S_supt[OF supt_subst[OF this]] have S: "S (?s \<cdot> \<sigma>) (t \<cdot> \<sigma>)" unfolding Var . from S_imp_NS[OF S] S show ?thesis by auto next case (Fun g ts) note t = this let ?f = "(f, length ss)" let ?g = "(g, length ts)" let ?ts = "map (\<lambda> s. s \<cdot> \<sigma>) ts" show ?thesis proof (cases "pr_strict ?f ?g") case True then have S: "S (?s \<cdot> \<sigma>) (t \<cdot> \<sigma>)" using w\<sigma> v\<sigma> unfolding t by simp from S S_imp_NS[OF S] show ?thesis by simp next case False note prec = this show ?thesis proof (cases "pr_weak ?f ?g") case False with v w prec have "\<not> NS ?s t" unfolding t by (auto simp del: vars_term_ms.simps) with NS show ?thesis by blast next case True from v w have "vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF ?s) \<and> weight t \<le> weight ?s" "\<not> weight t < weight ?s" by auto { fix i assume i: "i < length ss" "i < length ts" and S: "S (ss ! i) (ts ! i)" have "S (map (\<lambda>s. s \<cdot> \<sigma>) ss ! i) (map (\<lambda>s. s \<cdot> \<sigma>) ts ! i)" using IH[OF _ S_imp_NS[OF S]] S i unfolding set_conv_nth by (force simp del: kbo.simps) } note IH_S = this { fix i assume i: "i < length ss" "i < length ts" and NS: "NS (ss ! i) (ts ! i)" have "NS (map (\<lambda>s. s \<cdot> \<sigma>) ss ! i) (map (\<lambda>s. s \<cdot> \<sigma>) ts ! i)" using IH[OF _ NS] i unfolding set_conv_nth by (force simp del: kbo.simps) } note IH_NS = this { assume "S ?s t" with prec v w True have lex: "fst (lex_ext_unbounded kbo ss ts)" unfolding s_def t by simp have "fst (lex_ext_unbounded kbo ?ss ?ts)" by (rule lex_ext_unbounded_map_S[OF _ _ lex], insert IH_NS IH_S, blast+) with v\<sigma> w\<sigma> prec True have "S (?s \<cdot> \<sigma>) (t \<cdot> \<sigma>)" unfolding t by auto } moreover { from NS prec v w True have lex: "snd (lex_ext_unbounded kbo ss ts)" unfolding t by simp have "snd (lex_ext_unbounded kbo ?ss ?ts)" by (rule lex_ext_unbounded_map_NS[OF _ _ lex], insert IH_S IH_NS, blast) with v\<sigma> w\<sigma> prec True have "NS (?s \<cdot> \<sigma>) (t \<cdot> \<sigma>)" unfolding t by auto } ultimately show ?thesis by auto qed qed qed qed qed lemma S_subst: "S s t \<Longrightarrow> S (s \<cdot> (\<sigma> :: ('f, 'v) subst)) (t \<cdot> \<sigma>)" using kbo_stable[OF S_imp_NS, of s t \<sigma>] by auto lemma NS_subst: "NS s t \<Longrightarrow> NS (s \<cdot> (\<sigma> :: ('f, 'v) subst)) (t \<cdot> \<sigma>)" using kbo_stable[of s t \<sigma>] by auto subsection \<open>Transitivity and Compatibility\<close> lemma kbo_trans: "(S s t \<longrightarrow> NS t u \<longrightarrow> S s u) \<and> (NS s t \<longrightarrow> S t u \<longrightarrow> S s u) \<and> (NS s t \<longrightarrow> NS t u \<longrightarrow> NS s u)" (is "?P s t u") proof (induct s arbitrary: t u) case (Var x t u) from not_S_Var[of x t] have nS: "\<not> S (Var x) t" . show ?case proof (cases "NS (Var x) t") case False with nS show ?thesis by blast next case True from NS_Var_imp_eq_least[OF this] obtain f where "t = Var x \<or> t = Fun f [] \<and> least f" by blast then show ?thesis proof assume "t = Var x" then show ?thesis using nS by blast next assume "t = Fun f [] \<and> least f" then have t: "t = Fun f []" and least: "least f" by auto from not_S_least[OF least] have nS': "\<not> S t u" unfolding t . show ?thesis proof (cases "NS t u") case True with NS_least_least[OF least, of u] t obtain h where u: "u = Fun h []" and least: "least h" by auto from NS_all_least[OF least] have NS: "NS (Var x) u" unfolding u . with nS nS' show ?thesis by blast next case False with S_imp_NS[of t u] show ?thesis by blast qed qed qed next case (Fun f ss t u) note IH = this let ?s = "Fun f ss" show ?case proof (cases "NS ?s t") case False with S_imp_NS[of ?s t] show ?thesis by blast next case True note st = this then have vst: "vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF ?s)" and wst: "weight t \<le> weight ?s" by (auto split: if_splits) show ?thesis proof (cases "NS t u") case False with S_imp_NS[of t u] show ?thesis by blast next case True note tu = this then have vtu: "vars_term_ms (SCF u) \<subseteq># vars_term_ms (SCF t)" and wtu: "weight u \<le> weight t" by (auto split: if_splits) from vst vtu have v: "vars_term_ms (SCF u) \<subseteq># vars_term_ms (SCF ?s)" by simp from wst wtu have w: "weight u \<le> weight ?s" by simp show ?thesis proof (cases "weight u < weight ?s") case True with v show ?thesis by auto next case False with wst wtu have wst: "weight t = weight ?s" and wtu: "weight u = weight t" and w: "weight u = weight ?s" by arith+ show ?thesis proof (cases u) case (Var z) with v w show ?thesis by auto next case (Fun h us) note u = this show ?thesis proof (cases t) case (Fun g ts) note t = this let ?f = "(f, length ss)" let ?g = "(g, length ts)" let ?h = "(h, length us)" from st t wst have fg: "pr_weak ?f ?g" by (simp split: if_splits add: pr_strict) from tu t u wtu have gh: "pr_weak ?g ?h" by (simp split: if_splits add: pr_strict) from pr_weak_trans[OF fg gh] have fh: "pr_weak ?f ?h" . show ?thesis proof (cases "pr_strict ?f ?h") case True with w v u show ?thesis by auto next case False let ?lex = "lex_ext_unbounded kbo" from False fh have hf: "pr_weak ?h ?f" unfolding pr_strict by auto from pr_weak_trans[OF hf fg] have hg: "pr_weak ?h ?g" . from hg have gh2: "\<not> pr_strict ?g ?h" unfolding pr_strict by auto from pr_weak_trans[OF gh hf] have gf: "pr_weak ?g ?f" . from gf have fg2: "\<not> pr_strict ?f ?g" unfolding pr_strict by auto from st t wst fg2 have st: "snd (?lex ss ts)" by (auto split: if_splits) from tu t u wtu gh2 have tu: "snd (?lex ts us)" by (auto split: if_splits) { fix s t u assume "s \<in> set ss" from IH[OF this, of t u] have "(NS s t \<and> S t u \<longrightarrow> S s u) \<and> (S s t \<and> NS t u \<longrightarrow> S s u) \<and> (NS s t \<and> NS t u \<longrightarrow> NS s u) \<and> (S s t \<and> S t u \<longrightarrow> S s u)" using S_imp_NS[of s t] by blast } note IH = this let ?b = "length ss + length ts + length us" note lex = lex_ext_compat[of ss ts us kbo ?b, OF IH] let ?lexb = "lex_ext kbo ?b" note conv = lex_ext_def Let_def from st have st: "snd (?lexb ss ts)" unfolding conv by simp from tu have tu: "snd (?lexb ts us)" unfolding conv by simp from lex st tu have su: "snd (?lexb ss us)" by blast then have su: "snd (?lex ss us)" unfolding conv by simp from w v u su fh have NS: "NS ?s u" by simp { assume st: "S ?s t" with t wst fg fg2 have st: "fst (?lex ss ts)" by (auto split: if_splits) then have st: "fst (?lexb ss ts)" unfolding conv by simp from lex st tu have su: "fst (?lexb ss us)" by blast then have su: "fst (?lex ss us)" unfolding conv by simp from w v u su fh have S: "S ?s u" by simp } note S_left = this { assume tu: "S t u" with t u wtu gh2 have tu: "fst (?lex ts us)" by (auto split: if_splits) then have tu: "fst (?lexb ts us)" unfolding conv by simp from lex st tu have su: "fst (?lexb ss us)" by blast then have su: "fst (?lex ss us)" unfolding conv by simp from w v u su fh have S: "S ?s u" by simp } note S_right = this from NS S_left S_right show ?thesis by blast qed next case (Var x) note t = this from tu weight_w0[of u] have least: "least h" and u: "u = Fun h []" unfolding t u by (auto split: if_splits) from NS_all_least[OF least] have NS: "NS ?s u" unfolding u . from not_S_Var have nS': "\<not> S t u" unfolding t . show ?thesis proof (cases "S ?s t") case False with nS' NS show ?thesis by blast next case True then have "vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF ?s)" by (auto split: if_splits) from set_mset_mono[OF this, unfolded set_mset_vars_term_ms t] have "x \<in> vars_term (SCF ?s)" by simp also have "\<dots> \<subseteq> vars_term ?s" by (rule vars_term_scf_subset) finally obtain s sss where ss: "ss = s # sss" by (cases ss, auto) from kbo_supt_one[OF NS_all_least[OF least, of s], of f Nil sss] have "S ?s u" unfolding ss u by simp with NS show ?thesis by blast qed qed qed qed qed qed qed lemma S_trans: "S s t \<Longrightarrow> S t u \<Longrightarrow> S s u" using S_imp_NS[of s t] kbo_trans[of s t u] by blast lemma NS_trans: "NS s t \<Longrightarrow> NS t u \<Longrightarrow> NS s u" using kbo_trans[of s t u] by blast lemma NS_S_compat: "NS s t \<Longrightarrow> S t u \<Longrightarrow> S s u" using kbo_trans[of s t u] by blast lemma S_NS_compat: "S s t \<Longrightarrow> NS t u \<Longrightarrow> S s u" using kbo_trans[of s t u] by blast subsection \<open>Strong Normalization (a.k.a. Well-Foundedness)\<close> lemma kbo_strongly_normalizing: fixes s :: "('f, 'v) term" shows "SN_on {(s, t). S s t} {s}" proof - let ?SN = "\<lambda> t :: ('f, 'v) term. SN_on {(s, t). S s t} {t}" let ?m1 = "\<lambda> (f, ss). weight (Fun f ss)" let ?m2 = "\<lambda> (f, ss). (f, length ss)" let ?rel' = "lex_two {(fss, gts). ?m1 fss > ?m1 gts} {(fss, gts). ?m1 fss \<ge> ?m1 gts} {(fss, gts). pr_strict (?m2 fss) (?m2 gts)}" let ?rel = "inv_image ?rel' (\<lambda> x. (x, x))" have SN_rel: "SN ?rel" by (rule SN_inv_image, rule lex_two, insert SN_inv_image[OF pr_SN, of ?m2] SN_inv_image[OF SN_nat_gt, of ?m1], auto simp: inv_image_def) note conv = SN_on_all_reducts_SN_on_conv show "?SN s" proof (induct s) case (Var x) show ?case unfolding conv[of _ "Var x"] using not_S_Var[of x] by auto next case (Fun f ss) then have subset: "set ss \<subseteq> {s. ?SN s}" by blast let ?P = "\<lambda> (f, ss). set ss \<subseteq> {s. ?SN s} \<longrightarrow> ?SN (Fun f ss)" { fix fss have "?P fss" proof (induct fss rule: SN_induct[OF SN_rel]) case (1 fss) obtain f ss where fss: "fss = (f, ss)" by force { fix g ts assume "?m1 (f, ss) > ?m1 (g, ts) \<or> ?m1 (f, ss) \<ge> ?m1 (g, ts) \<and> pr_strict (?m2 (f, ss)) (?m2 (g, ts))" and "set ts \<subseteq> {s. ?SN s}" then have "?SN (Fun g ts)" using 1[rule_format, of "(g, ts)", unfolded fss split] by auto } note IH = this[unfolded split] show ?case unfolding fss split proof assume SN_s: "set ss \<subseteq> {s. ?SN s}" let ?f = "(f, length ss)" let ?s = "Fun f ss" let ?SNt = "\<lambda> g ts. ?SN (Fun g ts)" let ?sym = "\<lambda> g ts. (g, length ts)" let ?lex = "lex_ext kbo (weight ?s)" let ?lexu = "lex_ext_unbounded kbo" let ?lex_SN = "{(ys, xs). (\<forall> y \<in> set ys. ?SN y) \<and> fst (?lex ys xs)}" from lex_ext_SN[of kbo "weight ?s", OF NS_S_compat] have SN: "SN ?lex_SN" . { fix g and ts :: "('f, 'v) term list" assume "pr_weak ?f (?sym g ts) \<and> weight (Fun g ts) \<le> weight ?s \<and> set ts \<subseteq> {s. ?SN s}" then have "?SNt g ts" proof (induct ts arbitrary: g rule: SN_induct[OF SN]) case (1 ts g) note inner_IH = 1(1) let ?g = "(g, length ts)" let ?t = "Fun g ts" from 1(2) have fg: "pr_weak ?f ?g" and w: "weight ?t \<le> weight ?s" and SN: "set ts \<subseteq> {s. ?SN s}" by auto show "?SNt g ts" unfolding conv[of _ ?t] proof (intro allI impI) fix u assume "(?t, u) \<in> {(s, t). S s t}" then have tu: "S ?t u" by auto then show "?SN u" proof (induct u) case (Var x) then show ?case using not_S_Var[of x] unfolding conv[of _ "Var x"] by auto next case (Fun h us) let ?h = "(h, length us)" let ?u = "Fun h us" note tu = Fun(2) { fix u assume u: "u \<in> set us" then have "?u \<rhd> u" by auto from S_trans[OF tu S_supt[OF this]] have "S ?t u" by auto from Fun(1)[OF u this] have "?SN u" . } then have SNu: "set us \<subseteq> {s . ?SN s}" by blast note IH = IH[OF _ this] from tu have wut: "weight ?u \<le> weight ?t" by (simp split: if_splits) show ?case proof (cases "?m1 (f, ss) > ?m1 (h, us) \<or> ?m1 (f, ss) \<ge> ?m1 (h, us) \<and> pr_strict (?m2 (f, ss)) (?m2 (h, us))") case True from IH[OF True[unfolded split]] show ?thesis by simp next case False with wut w have wut: "weight ?t = weight ?u" "weight ?s = weight ?u" by auto note False = False[unfolded split wut] note tu = tu[unfolded kbo.simps[of ?t] wut, unfolded Fun term.simps, simplified] from tu have gh: "pr_weak ?g ?h" unfolding pr_strict by (auto split: if_splits) from pr_weak_trans[OF fg gh] have fh: "pr_weak ?f ?h" . from False wut fh have "\<not> pr_strict ?f ?h" unfolding pr_strict by auto with fh have hf: "pr_weak ?h ?f" unfolding pr_strict by auto from pr_weak_trans[OF hf fg] have hg: "pr_weak ?h ?g" . from hg have gh2: "\<not> pr_strict ?g ?h" unfolding pr_strict by auto from tu gh2 have lex: "fst (?lexu ts us)" by (auto split: if_splits) from fh wut SNu have "pr_weak ?f ?h \<and> weight ?u \<le> weight ?s \<and> set us \<subseteq> {s. ?SN s}" by auto note inner_IH = inner_IH[OF _ this] show ?thesis proof (rule inner_IH, rule, unfold split, intro conjI ballI) have "fst (?lexu ts us)" by (rule lex) moreover have "length us \<le> weight ?s" proof - have "length us \<le> sum_list (map weight us)" proof (induct us) case (Cons u us) from Cons have "length (u # us) \<le> Suc (sum_list (map weight us))" by auto also have "... \<le> sum_list (map weight (u # us))" using weight_gt_0[of u] by auto finally show ?case . qed simp also have "\<dots> \<le> sum_list (map weight (scf_list (scf (h, length us)) us))" by (rule sum_list_scf_list[OF scf]) also have "... \<le> weight ?s" using wut by simp finally show ?thesis . qed ultimately show "fst (?lex ts us)" unfolding lex_ext_def Let_def by auto qed (insert SN, blast) qed qed qed qed } from this[of f ss] SN_s show "?SN ?s" by auto qed qed } from this[of "(f, ss)", unfolded split] show ?case using Fun by blast qed qed lemma S_SN: "SN {(x, y). S x y}" using kbo_strongly_normalizing unfolding SN_defs by blast subsection \<open>Ground Totality\<close> lemma ground_SCF [simp]: "ground (SCF t) = ground t" proof - have *: "\<forall>i<length xs. scf (f, length xs) i > 0" for f :: 'f and xs :: "('f, 'v) term list" using scf by simp show ?thesis by (induct t) (auto simp: set_scf_list [OF *]) qed declare kbo.simps[simp del] lemma ground_vars_term_ms: "ground t \<Longrightarrow> vars_term_ms t = {#}" by (induct t) auto context fixes F :: "('f \<times> nat) set" assumes pr_weak: "pr_weak = pr_strict\<^sup>=\<^sup>=" and pr_gtotal: "\<And>f g. f \<in> F \<Longrightarrow> g \<in> F \<Longrightarrow> f = g \<or> pr_strict f g \<or> pr_strict g f" begin lemma S_ground_total: assumes "funas_term s \<subseteq> F" and "ground s" and "funas_term t \<subseteq> F" and "ground t" shows "s = t \<or> S s t \<or> S t s" using assms proof (induct s arbitrary: t) case IH: (Fun f ss) note [simp] = ground_vars_term_ms let ?s = "Fun f ss" have *: "(vars_term_ms (SCF t) \<subseteq># vars_term_ms (SCF ?s)) = True" "(vars_term_ms (SCF ?s) \<subseteq># vars_term_ms (SCF t)) = True" using \<open>ground ?s\<close> and \<open>ground t\<close> by (auto simp: scf) from IH(5) obtain g ts where t[simp]: "t = Fun g ts" by (cases t, auto) let ?t = "Fun g ts" let ?f = "(f, length ss)" let ?g = "(g, length ts)" from IH have f: "?f \<in> F" and g: "?g \<in> F" by auto { assume "\<not> ?case" note contra = this[unfolded kbo.simps[of ?s] kbo.simps[of t] *, unfolded t term.simps] from pr_gtotal[OF f g] contra have fg: "?f = ?g" by (auto split: if_splits) have IH: "\<forall>(s, t)\<in>set (zip ss ts). s = t \<or> S s t \<or> S t s" using IH by (auto elim!: in_set_zipE) blast from fg have len: "length ss = length ts" by auto from lex_ext_unbounded_total[OF IH NS_refl len] contra fg have False by (auto split: if_splits) } then show ?case by blast qed auto end subsection \<open>Summary\<close> text \<open> At this point we have shown well-foundedness @{thm [source] S_SN}, transitivity and compatibility @{thm [source] S_trans NS_trans NS_S_compat S_NS_compat}, closure under substitutions @{thm [source] S_subst NS_subst}, closure under contexts @{thm [source] S_ctxt NS_ctxt}, the subterm property @{thm [source] S_supt NS_supteq}, reflexivity of the weak @{thm [source] NS_refl} and irreflexivity of the strict part @{thm [source] S_irrefl}, and ground-totality @{thm [source] S_ground_total}. In particular, this allows us to show that KBO is an instance of strongly normalizing order pairs (@{locale SN_order_pair}). \<close> sublocale SN_order_pair "{(x, y). S x y}" "{(x, y). NS x y}" by (unfold_locales, insert NS_refl NS_trans S_trans S_SN NS_S_compat S_NS_compat) (auto simp: refl_on_def trans_def, blast+) end end
[STATEMENT] lemma nat_of_name_Abs_eq [simp]: "nat_of_name (Abs_name (Atom (Sort ''SyntaxN.name'' []) n)) = n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. nat_of_name (Abs_name (Atom (Sort ''SyntaxN.name'' []) n)) = n [PROOF STEP] by (auto simp: nat_of_name_def atom_name_def Abs_name_inverse)
(* * Usage: You may need "make equiv.vo" before * using this file. * In vscode, you may also need to add * "coqtop.args": [ "-Q", "/path/to/this/dir", "" ] * to settings.json. *) Require Export equiv. Require Export Lists.List. Local Open Scope type_scope. (* for '*' *) (* finite control states *) Parameter Q : Set. Definition Q' := Q * Phi. Inductive Com := | pop | skip | push (j : nat). Inductive Com' := | pop' | skip' | push' (phi : Phi). (* Stack and configurations *) Definition Stack := list (D * Theta). Definition Stack' := list Phi. Definition Config := Q * Theta * Stack. Definition Config' := Q' * Stack'. Definition update_stack (u : Stack) theta com := match com with | pop => match u with _ :: u' => u' | nil => nil end | skip => u | push j => (theta j, theta) :: u end. Definition update_stack' (u : Stack') com' := match com' with | pop' => match u with _ :: u' => u' | nil => nil end | skip' => u | push' z => z :: u end. Definition not_contain d (cell: D * Theta) := match cell with (_, theta) => forall i, theta i <> d end. Axiom stack_has_outside_data : forall (theta: Theta) (e: D) (u: Stack), exists d : D, d <> e /\ (forall i, theta i <> d) /\ Forall (not_contain d) u. Definition is_proper_stack (stack : Stack) := let is_proper_cell cell := match cell with (z, theta) => exists i, z = theta i end in Forall is_proper_cell stack. (* Bisimulation relation between configs *) (* The stack bottom of a given starting ID *) Parameter theta_0 : Theta. Parameter d_0 : D. Axiom proper_bottom : exists i, d_0 = theta_0 i. Inductive stack_R_stack' : Theta -> Stack -> Phi -> Stack' -> Prop := | Stack_R_stack'_nil : forall theta phi, (theta_0, d_0, theta) |= phi -> stack_R_stack' theta nil phi nil | Stack_R_stack'_cons : forall theta ptheta d phi pphi u v, (ptheta, d, theta) |= phi -> stack_R_stack' ptheta u pphi v -> stack_R_stack' theta ((d, ptheta) :: u) phi (pphi :: v). Inductive config_R_config' : Config -> Config' -> Prop := | Config_R_config' : forall q theta u phi v, stack_R_stack' theta u phi v -> config_R_config' (q, theta, u) ((q, phi), v). (* freshness_p on stack *) Inductive Forall2 {X : Type} (P : X -> X -> Prop) : list X -> Prop := | Forall2_nil : Forall2 P nil | Forall2_cons x l : Forall (P x) l -> Forall2 P l -> Forall2 P (x :: l). Inductive Forall3 {X : Type} (P : X -> X -> X -> Prop) : list X -> Prop := | Forall3_nil : Forall3 P nil | Forall3_cons x l : Forall2 (P x) l -> Forall3 P l -> Forall3 P (x :: l). Definition freshness_p_on_triple (p3 p2 p1 : D * Theta) := match (p3, p2, p1) with ((_, th3), (_, th2), (d, th1)) => freshness_p th1 d th2 th3 end. Definition freshness_p_on_stack theta stack := Forall3 freshness_p_on_triple ((bot, theta) :: stack). Local Example forall2_example_1 : Forall2 le (0 :: 1 :: 3 :: 8 :: nil). Proof. repeat apply Forall2_cons; repeat apply Forall_cons; repeat (apply le_S; try apply le_n); auto; try apply Forall2_nil. Qed. (* Lemmas *) (* Forall, Forall2, Forall3 *) Lemma Forall_sublist {A : Type} : forall p (a : A) u1 u2, Forall p (u1 ++ (a :: u2)) -> Forall p (u1 ++ u2). Proof. intros p a u1 u2. induction u1 as [| b u1 IHu1]. - (* u1 = nil -> ... *) unfold app. intros Hfor. inversion Hfor as [| x l Hpa Hfor' [EQx EQl]]. exact Hfor'. - (* u1 = b :: u1 -> ... *) repeat rewrite<- app_comm_cons. intros Hfor. inversion Hfor as [| x l Hpb Hfor' [EQx EQl]]. clear x EQx l EQl. apply Forall_cons; auto. Qed. Local Lemma Forall2_sublist {A : Type} : forall p (a : A) u1 u2, Forall2 p (u1 ++ (a :: u2)) -> Forall2 p (u1 ++ u2). Proof. intros p a u1 u2. induction u1 as [| b u1 IHu1]. - (* u1 = nil -> ... *) unfold app. intros Hfor2. inversion Hfor2 as [| x l Hfor Hfor2' [EQx EQl]]. exact Hfor2'. - (* u1 = b :: u1 -> ... *) repeat rewrite<- app_comm_cons. intros Hfor2. inversion Hfor2 as [| x l Hfor Hfor2' [EQx EQl]]. clear x EQx l EQl. apply Forall2_cons. + (* Forall ... *) now apply Forall_sublist with a. + (* Forall2 ... *) now apply IHu1. Qed. Lemma Forall3_sublist {A : Type} : forall p (a : A) u1 u2, Forall3 p (u1 ++ (a :: u2)) -> Forall3 p (u1 ++ u2). Proof. intros p a u1 u2. induction u1 as [| b u1 IHu1]. - (* u1 = nil -> ... *) unfold app. intros Hfor3. inversion Hfor3 as [| x l Hfor2 Hfor3' [EQx EQl]]. exact Hfor3'. - (* u1 = b :: u1 -> ... *) repeat rewrite<- app_comm_cons. intros Hfor3. inversion Hfor3 as [| x l Hfor2 Hfor3' [EQx EQl]]. clear x EQx l EQl. apply Forall3_cons. + (* Forall ... *) now apply Forall2_sublist with a. + (* Forall2 ... *) now apply IHu1. Qed. Local Lemma Forall2_hd2 {A : Type} : forall p (a : A) b u, Forall2 p (a :: b :: u) -> p a b. Proof. intros p a b u H. inversion H as [| x l Hfor Hfor2 [EQx EQl]]. clear x EQx l EQl H Hfor2. inversion Hfor as [| x l H Hfor' [EQx EQl]]. exact H. Qed. Lemma Forall3_hd3 {A : Type} : forall p (a : A) b c u, Forall3 p (a :: b :: c :: u) -> p a b c. Proof. intros p a b c u H. inversion H as [| x l Hfor2 Hfor3' [EQx EQl]]. clear x EQx l EQl Hfor3' H. apply Forall2_hd2 with u. exact Hfor2. Qed. (* is_proper_stack *) Lemma substack_is_proper_stack : forall a u1 u2, is_proper_stack (u1 ++ (a :: u2)) -> is_proper_stack (u1 ++ u2). Proof. apply Forall_sublist. Qed. (* freshness_p_on_stack *) Lemma substack_keeps_freshness_p_0 : forall theta d th u, freshness_p_on_stack theta ((d, th) :: u) -> freshness_p_on_stack th u. Proof. intros theta d th u. unfold freshness_p_on_stack. intros Hfor3. inversion Hfor3 as [| x l Hfor2 Hfor3' [EQx EQl]]. clear x l EQx EQl Hfor3. inversion Hfor3' as [| x l Hfor2' Hfor3 [EQx EQl]]. clear x l EQx EQl Hfor3'. now apply Forall3_cons. Qed. Lemma substack_keeps_freshness_p : forall theta a u1 u2, freshness_p_on_stack theta (u1 ++ (a :: u2)) -> freshness_p_on_stack theta (u1 ++ u2). Proof. intros theta a u1 u2. unfold freshness_p_on_stack. repeat rewrite app_comm_cons. apply Forall3_sublist. Qed. Lemma push_keeps_freshness_p : forall theta u z, freshness_p_on_stack theta u -> freshness_p_on_stack theta ((z, theta) :: u). Proof. intros theta u z. unfold freshness_p_on_stack. intros H. apply Forall3_cons. - (* Forall2 ... ((z, theta) :: u) *) apply Forall2_cons. + (* Forall ... u *) apply Forall_forall. intros [d1 th1] Hth1. unfold freshness_p_on_triple. unfold freshness_p. split. * (* forall i j, th1 i = ... -> ... *) intros i j H1. inversion H as [| x l Hfor2 Hfor3 [EQx EQl]]. clear x EQx l EQl Hfor3. inversion Hfor2 as [EQu | x l Hfor Hfor2' EQx]. -- (* u = nil -> ... *) rewrite<- EQu in Hth1. apply in_nil in Hth1. contradiction. -- (* u = x :: l -> ... *) exists j. exact H1. * (* forall j, d1 = ... -> ... *) intros j H1. exists j. exact H1. + (* Forall2 ... u *) inversion H as [| x l Hfor2 Hfor3 [EQx EQl]]. clear x EQx l EQl Hfor3. exact Hfor2. - (* Forall3 ... ((theta j, ) :: u) *) apply Forall3_cons. + (* Forall2 ... u *) induction u as [| [d1 th1] u IHu]. * (* u = nil -> ... *) apply Forall2_nil. * (* u = (d1, th1) :: u -> ... *) apply Forall2_cons. -- (* Forall ... u *) apply Forall_forall. intros [d2 th2] Hth2. unfold freshness_p_on_triple. inversion H as [| x l Hfor2 Hfor3 [EQx EQl]]. clear x EQx l EQl Hfor3. inversion Hfor2 as [| x l Hfor Hfor2' [EQx EQl]]. clear x EQx l EQl Hfor2 Hfor2'. rewrite Forall_forall in Hfor. unfold freshness_p_on_triple in Hfor. apply (Hfor (d2, th2)). exact Hth2. -- (* Forall2 ... u *) apply IHu. apply (Forall3_sublist _ (d1, th1) ((bot, theta) :: nil)). unfold app. exact H. + (* Forall3 ... u *) apply (Forall3_sublist _ (bot, theta) nil). unfold app. exact H. Qed. (* config_R_config' *) Lemma config_R_nil_nil_1 : forall q theta u phi, config_R_config' (q, theta, u) (q, phi, nil) -> u = nil. Proof. intros q theta u phi. intro H. inversion H as [q1 theta1 u1 phi1 v1 HR]. inversion HR. reflexivity. Qed. Lemma config_R_nil_nil_2 : forall q theta v phi, config_R_config' (q, theta, nil) (q, phi, v) -> v = nil. Proof. intros q theta v phi. intro H. inversion H as [q1 theta1 u1 phi1 v1 HR]. inversion HR. reflexivity. Qed.
section ex1 theorem test (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p := begin apply and.intro, exact hp, apply and.intro, exact hq, exact hp, end theorem test' (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p := begin apply and.intro hp, exact and.intro hq hp, end example (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := begin apply iff.intro, intro h, apply or.elim (and.right h), intro hq, apply or.inl, apply and.intro, exact and.left h, exact hq, intro hr, apply or.inr, apply and.intro, exact and.left h, exact hr, intro h, apply or.elim h, intro hpq, apply and.intro, exact and.left hpq, apply or.inl, exact and.right hpq, intro hpr, apply and.intro, exact and.left hpr, apply or.inr, exact and.right hpr, end example (α : Type*) : α → α := begin intro a, exact a, end end ex1
chapter\<open>Uniqueness Results: Syntactic Relations are Functions\<close> theory Functions imports Coding_Predicates begin subsection \<open>SeqStTermP\<close> lemma not_IndP_VarP: "{IndP x, VarP x} \<turnstile> A" proof - obtain m::name where "atom m \<sharp> (x,A)" by (metis obtain_fresh) thus ?thesis by (auto simp: fresh_Pair) (blast intro: ExFalso cut_same [OF VarP_cong [THEN Iff_MP_same]]) qed text\<open>It IS a pair, but not just any pair.\<close> lemma IndP_HPairE: "insert (IndP (HPair (HPair Zero (HPair Zero Zero)) x)) H \<turnstile> A" proof - obtain m::name where "atom m \<sharp> (x,A)" by (metis obtain_fresh) hence "{ IndP (HPair (HPair Zero (HPair Zero Zero)) x) } \<turnstile> A" by (auto simp: IndP.simps [of m] HTuple_minus_1 intro: thin1) thus ?thesis by (metis Assume cut1) qed lemma atom_HPairE: assumes "H \<turnstile> x EQ HPair (HPair Zero (HPair Zero Zero)) y" shows "insert (IndP x OR x NEQ v) H \<turnstile> A" proof - have "{ IndP x OR x NEQ v, x EQ HPair (HPair Zero (HPair Zero Zero)) y } \<turnstile> A" by (auto intro!: OrdNotEqP_OrdP_E IndP_HPairE intro: cut_same [OF IndP_cong [THEN Iff_MP_same]] cut_same [OF OrdP_cong [THEN Iff_MP_same]]) thus ?thesis by (metis Assume assms rcut2) qed lemma SeqStTermP_lemma: assumes "atom m \<sharp> (v,i,t,u,s,k,n,sm,sm',sn,sn')" "atom n \<sharp> (v,i,t,u,s,k,sm,sm',sn,sn')" "atom sm \<sharp> (v,i,t,u,s,k,sm',sn,sn')" "atom sm' \<sharp> (v,i,t,u,s,k,sn,sn')" "atom sn \<sharp> (v,i,t,u,s,k,sn')" "atom sn' \<sharp> (v,i,t,u,s,k)" shows "{ SeqStTermP v i t u s k } \<turnstile> ((t EQ v AND u EQ i) OR ((IndP t OR t NEQ v) AND u EQ t)) OR Ex m (Ex n (Ex sm (Ex sm' (Ex sn (Ex sn' (Var m IN k AND Var n IN k AND SeqStTermP v i (Var sm) (Var sm') s (Var m) AND SeqStTermP v i (Var sn) (Var sn') s (Var n) AND t EQ Q_Eats (Var sm) (Var sn) AND u EQ Q_Eats (Var sm') (Var sn')))))))" proof - obtain l::name and sl::name and sl'::name where "atom l \<sharp> (v,i,t,u,s,k,sl,sl',m,n,sm,sm',sn,sn')" "atom sl \<sharp> (v,i,t,u,s,k,sl',m,n,sm,sm',sn,sn')" "atom sl' \<sharp> (v,i,t,u,s,k,m,n,sm,sm',sn,sn')" by (metis obtain_fresh) thus ?thesis using assms apply (simp add: SeqStTermP.simps [of l s k v i sl sl' m n sm sm' sn sn']) apply (rule Conj_EH Ex_EH All2_SUCC_E [THEN rotate2] | simp)+ apply (rule cut_same [where A = "HPair t u EQ HPair (Var sl) (Var sl')"]) apply (metis Assume AssumeH(4) LstSeqP_EQ) apply clarify apply (rule Disj_EH) apply (rule Disj_I1) apply (rule anti_deduction) apply (rule Var_Eq_subst_Iff [THEN Sym_L, THEN Iff_MP_same]) apply (rule Sym_L [THEN rotate2]) apply (rule Var_Eq_subst_Iff [THEN Iff_MP_same], force) \<comment> \<open>now the quantified case\<close> \<comment> \<open>auto could be used but is VERY SLOW\<close> apply (rule Ex_EH Conj_EH)+ apply simp_all apply (rule Disj_I2) apply (rule Ex_I [where x = "Var m"], simp) apply (rule Ex_I [where x = "Var n"], simp) apply (rule Ex_I [where x = "Var sm"], simp) apply (rule Ex_I [where x = "Var sm'"], simp) apply (rule Ex_I [where x = "Var sn"], simp) apply (rule Ex_I [where x = "Var sn'"], simp) apply (simp_all add: SeqStTermP.simps [of l s _ v i sl sl' m n sm sm' sn sn']) apply ((rule Conj_I)+, blast intro: LstSeqP_Mem)+ \<comment> \<open>first SeqStTermP subgoal\<close> apply (rule All2_Subset [OF Hyp], blast) apply (blast intro!: SUCC_Subset_Ord LstSeqP_OrdP, blast, simp) \<comment> \<open>next SeqStTermP subgoal\<close> apply ((rule Conj_I)+, blast intro: LstSeqP_Mem)+ apply (rule All2_Subset [OF Hyp], blast) apply (blast intro!: SUCC_Subset_Ord LstSeqP_OrdP, blast, simp) \<comment> \<open>finally, the equality pair\<close> apply (blast intro: Trans) done qed lemma SeqStTermP_unique: "{SeqStTermP v a t u s kk, SeqStTermP v a t u' s' kk'} \<turnstile> u' EQ u" proof - obtain i::name and j::name and j'::name and k::name and k'::name and l::name and m::name and n::name and sm::name and sn::name and sm'::name and sn'::name and m2::name and n2::name and sm2::name and sn2::name and sm2'::name and sn2'::name where atoms: "atom i \<sharp> (s,s',v,a,t,u,u')" "atom j \<sharp> (s,s',v,a,t,i,t,u,u')" "atom j' \<sharp> (s,s',v,a,t,i,j,t,u,u')" "atom k \<sharp> (s,s',v,a,t,u,u',kk',i,j,j')" "atom k' \<sharp> (s,s',v,a,t,u,u',k,i,j,j')" "atom l \<sharp> (s,s',v,a,t,i,j,j',k,k')" "atom m \<sharp> (s,s',v,a,i,j,j',k,k',l)" "atom n \<sharp> (s,s',v,a,i,j,j',k,k',l,m)" "atom sm \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n)" "atom sn \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm)" "atom sm' \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn)" "atom sn' \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm')" "atom m2 \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn')" "atom n2 \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2)" "atom sm2 \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2,n2)" "atom sn2 \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2,n2,sm2)" "atom sm2' \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2,n2,sm2,sn2)" "atom sn2' \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2,n2,sm2,sn2,sm2')" by (metis obtain_fresh) have "{ OrdP (Var k), VarP v } \<turnstile> All i (All j (All j' (All k' (SeqStTermP v a (Var i) (Var j) s (Var k) IMP (SeqStTermP v a (Var i) (Var j') s' (Var k') IMP Var j' EQ Var j)))))" apply (rule OrdIndH [where j=l]) using atoms apply auto apply (rule Swap) apply (rule cut_same) apply (rule cut1 [OF SeqStTermP_lemma [of m v a "Var i" "Var j" s "Var k" n sm sm' sn sn']], simp_all, blast) apply (rule cut_same) apply (rule cut1 [OF SeqStTermP_lemma [of m2 v a "Var i" "Var j'" s' "Var k'" n2 sm2 sm2' sn2 sn2']], simp_all, blast) apply (rule Disj_EH Conj_EH)+ \<comment> \<open>case 1, both sides equal "v"\<close> apply (blast intro: Trans Sym) \<comment> \<open>case 2, @{term "Var i EQ v"} and also @{term "IndP (Var i) OR Var i NEQ v"}\<close> apply (rule Conj_EH Disj_EH)+ apply (blast intro: IndP_cong [THEN Iff_MP_same] not_IndP_VarP [THEN cut2]) apply (metis Assume OrdNotEqP_E) \<comment> \<open>case 3, both a variable and a pair\<close> apply (rule Ex_EH Conj_EH)+ apply simp_all apply (rule cut_same [where A = "VarP (Q_Eats (Var sm) (Var sn))"]) apply (blast intro: Trans Sym VarP_cong [where x=v, THEN Iff_MP_same] Hyp, blast) \<comment> \<open>towards remaining cases\<close> apply (rule Disj_EH Ex_EH)+ \<comment> \<open>case 4, @{term "Var i EQ v"} and also @{term "IndP (Var i) OR Var i NEQ v"}\<close> apply (blast intro: IndP_cong [THEN Iff_MP_same] not_IndP_VarP [THEN cut2] OrdNotEqP_E) \<comment> \<open>case 5, @{term "Var i EQ v"} for both\<close> apply (blast intro: Trans Sym) \<comment> \<open>case 6, both an atom and a pair\<close> apply (rule Ex_EH Conj_EH)+ apply simp_all apply (rule atom_HPairE) apply (simp add: HTuple.simps) apply (blast intro: Trans) \<comment> \<open>towards remaining cases\<close> apply (rule Conj_EH Disj_EH Ex_EH)+ apply simp_all \<comment> \<open>case 7, both an atom and a pair\<close> apply (rule cut_same [where A = "VarP (Q_Eats (Var sm2) (Var sn2))"]) apply (blast intro: Trans Sym VarP_cong [where x=v, THEN Iff_MP_same] Hyp, blast) \<comment> \<open>case 8, both an atom and a pair\<close> apply (rule Ex_EH Conj_EH)+ apply simp_all apply (rule atom_HPairE) apply (simp add: HTuple.simps) apply (blast intro: Trans) \<comment> \<open>case 9, two Eats terms\<close> apply (rule Ex_EH Disj_EH Conj_EH)+ apply simp_all apply (rule All_E' [OF Hyp, where x="Var m"], blast) apply (rule All_E' [OF Hyp, where x="Var n"], blast, simp) apply (rule Disj_EH, blast intro: thin1 ContraProve)+ apply (rule All_E [where x="Var sm"], simp) apply (rule All_E [where x="Var sm'"], simp) apply (rule All_E [where x="Var sm2'"], simp) apply (rule All_E [where x="Var m2"], simp) apply (rule All_E [where x="Var sn", THEN rotate2], simp) apply (rule All_E [where x="Var sn'"], simp) apply (rule All_E [where x="Var sn2'"], simp) apply (rule All_E [where x="Var n2"], simp) apply (rule cut_same [where A = "Q_Eats (Var sm) (Var sn) EQ Q_Eats (Var sm2) (Var sn2)"]) apply (blast intro: Sym Trans, clarify) apply (rule cut_same [where A = "SeqStTermP v a (Var sn) (Var sn2') s' (Var n2)"]) apply (blast intro: Hyp SeqStTermP_cong [OF Hyp Refl Refl, THEN Iff_MP2_same]) apply (rule cut_same [where A = "SeqStTermP v a (Var sm) (Var sm2') s' (Var m2)"]) apply (blast intro: Hyp SeqStTermP_cong [OF Hyp Refl Refl, THEN Iff_MP2_same]) apply (rule Disj_EH, blast intro: thin1 ContraProve)+ apply (blast intro: HPair_cong Trans [OF Hyp Sym]) done hence p1: "{OrdP (Var k), VarP v} \<turnstile> (All j (All j' (All k' (SeqStTermP v a (Var i) (Var j) s (Var k) IMP (SeqStTermP v a (Var i) (Var j') s' (Var k') IMP Var j' EQ Var j)))))(i::=t)" by (metis All_D) have p2: "{OrdP (Var k), VarP v} \<turnstile> (All j' (All k' (SeqStTermP v a t (Var j) s (Var k) IMP (SeqStTermP v a t (Var j') s' (Var k') IMP Var j' EQ Var j))))(j::=u)" apply (rule All_D) using atoms p1 by simp have p3: "{OrdP (Var k), VarP v} \<turnstile> (All k' (SeqStTermP v a t u s (Var k) IMP (SeqStTermP v a t (Var j') s' (Var k') IMP Var j' EQ u)))(j'::=u')" apply (rule All_D) using atoms p2 by simp have p4: "{OrdP (Var k), VarP v} \<turnstile> (SeqStTermP v a t u s (Var k) IMP (SeqStTermP v a t u' s' (Var k') IMP u' EQ u))(k'::=kk')" apply (rule All_D) using atoms p3 by simp hence "{SeqStTermP v a t u s (Var k), VarP v} \<turnstile> SeqStTermP v a t u s (Var k) IMP (SeqStTermP v a t u' s' kk' IMP u' EQ u)" using atoms apply simp by (metis SeqStTermP_imp_OrdP rcut1) hence "{VarP v} \<turnstile> ((SeqStTermP v a t u s (Var k) IMP (SeqStTermP v a t u' s' kk' IMP u' EQ u)))" by (metis Assume MP_same Imp_I) hence "{VarP v} \<turnstile> ((SeqStTermP v a t u s (Var k) IMP (SeqStTermP v a t u' s' kk' IMP u' EQ u)))(k::=kk)" using atoms by (force intro!: Subst) hence "{VarP v} \<turnstile> SeqStTermP v a t u s kk IMP (SeqStTermP v a t u' s' kk' IMP u' EQ u)" using atoms by simp hence "{SeqStTermP v a t u s kk} \<turnstile> SeqStTermP v a t u s kk IMP (SeqStTermP v a t u' s' kk' IMP u' EQ u)" by (metis SeqStTermP_imp_VarP rcut1) thus ?thesis by (metis Assume AssumeH(2) MP_same rcut1) qed theorem SubstTermP_unique: "{SubstTermP v tm t u, SubstTermP v tm t u'} \<turnstile> u' EQ u" proof - obtain s::name and s'::name and k::name and k'::name where "atom s \<sharp> (v,tm,t,u,u',k,k')" "atom s' \<sharp> (v,tm,t,u,u',k,k',s)" "atom k \<sharp> (v,tm,t,u,u')" "atom k' \<sharp> (v,tm,t,u,u',k)" by (metis obtain_fresh) thus ?thesis by (auto simp: SubstTermP.simps [of s v tm t u k] SubstTermP.simps [of s' v tm t u' k']) (metis SeqStTermP_unique rotate3 thin1) qed subsection\<open>@{term SubstAtomicP}\<close> lemma SubstTermP_eq: "\<lbrakk>H \<turnstile> SubstTermP v tm x z; insert (SubstTermP v tm y z) H \<turnstile> A\<rbrakk> \<Longrightarrow> insert (x EQ y) H \<turnstile> A" by (metis Assume rotate2 Iff_E1 cut_same thin1 SubstTermP_cong [OF Refl Refl _ Refl]) lemma SubstAtomicP_unique: "{SubstAtomicP v tm x y, SubstAtomicP v tm x y'} \<turnstile> y' EQ y" proof - obtain t::name and ts::name and u::name and us::name and t'::name and ts'::name and u'::name and us'::name where "atom t \<sharp> (v,tm,x,y,y',ts,u,us)" "atom ts \<sharp> (v,tm,x,y,y',u,us)" "atom u \<sharp> (v,tm,x,y,y',us)" "atom us \<sharp> (v,tm,x,y,y')" "atom t' \<sharp> (v,tm,x,y,y',t,ts,u,us,ts',u',us')" "atom ts' \<sharp> (v,tm,x,y,y',t,ts,u,us,u',us')" "atom u' \<sharp> (v,tm,x,y,y',t,ts,u,us,us')" "atom us' \<sharp> (v,tm,x,y,y',t,ts,u,us)" by (metis obtain_fresh) thus ?thesis apply (simp add: SubstAtomicP.simps [of t v tm x y ts u us] SubstAtomicP.simps [of t' v tm x y' ts' u' us']) apply (rule Ex_EH Disj_EH Conj_EH)+ apply simp_all apply (rule Eq_Trans_E [OF Hyp], auto simp: HTS) apply (rule SubstTermP_eq [THEN thin1], blast) apply (rule SubstTermP_eq [THEN rotate2], blast) apply (rule Trans [OF Hyp Sym], blast) apply (rule Trans [OF Hyp], blast) apply (metis Assume AssumeH(8) HPair_cong Refl cut2 [OF SubstTermP_unique] thin1) apply (rule Eq_Trans_E [OF Hyp], blast, force simp add: HTS) apply (rule Eq_Trans_E [OF Hyp], blast, force simp add: HTS) apply (rule Eq_Trans_E [OF Hyp], auto simp: HTS) apply (rule SubstTermP_eq [THEN thin1], blast) apply (rule SubstTermP_eq [THEN rotate2], blast) apply (rule Trans [OF Hyp Sym], blast) apply (rule Trans [OF Hyp], blast) apply (metis Assume AssumeH(8) HPair_cong Refl cut2 [OF SubstTermP_unique] thin1) done qed subsection\<open>@{term SeqSubstFormP}\<close> lemma SeqSubstFormP_lemma: assumes "atom m \<sharp> (v,u,x,y,s,k,n,sm,sm',sn,sn')" "atom n \<sharp> (v,u,x,y,s,k,sm,sm',sn,sn')" "atom sm \<sharp> (v,u,x,y,s,k,sm',sn,sn')" "atom sm' \<sharp> (v,u,x,y,s,k,sn,sn')" "atom sn \<sharp> (v,u,x,y,s,k,sn')" "atom sn' \<sharp> (v,u,x,y,s,k)" shows "{ SeqSubstFormP v u x y s k } \<turnstile> SubstAtomicP v u x y OR Ex m (Ex n (Ex sm (Ex sm' (Ex sn (Ex sn' (Var m IN k AND Var n IN k AND SeqSubstFormP v u (Var sm) (Var sm') s (Var m) AND SeqSubstFormP v u (Var sn) (Var sn') s (Var n) AND (((x EQ Q_Disj (Var sm) (Var sn) AND y EQ Q_Disj (Var sm') (Var sn')) OR (x EQ Q_Neg (Var sm) AND y EQ Q_Neg (Var sm')) OR (x EQ Q_Ex (Var sm) AND y EQ Q_Ex (Var sm'))))))))))" proof - obtain l::name and sl::name and sl'::name where "atom l \<sharp> (v,u,x,y,s,k,sl,sl',m,n,sm,sm',sn,sn')" "atom sl \<sharp> (v,u,x,y,s,k,sl',m,n,sm,sm',sn,sn')" "atom sl' \<sharp> (v,u,x,y,s,k,m,n,sm,sm',sn,sn')" by (metis obtain_fresh) thus ?thesis using assms apply (simp add: SeqSubstFormP.simps [of l s k v u sl sl' m n sm sm' sn sn']) apply (rule Conj_EH Ex_EH All2_SUCC_E [THEN rotate2] | simp)+ apply (rule cut_same [where A = "HPair x y EQ HPair (Var sl) (Var sl')"]) apply (metis Assume AssumeH(4) LstSeqP_EQ) apply clarify apply (rule Disj_EH) apply (blast intro: Disj_I1 SubstAtomicP_cong [THEN Iff_MP2_same]) \<comment> \<open>now the quantified cases\<close> apply (rule Ex_EH Conj_EH)+ apply simp_all apply (rule Disj_I2) apply (rule Ex_I [where x = "Var m"], simp) apply (rule Ex_I [where x = "Var n"], simp) apply (rule Ex_I [where x = "Var sm"], simp) apply (rule Ex_I [where x = "Var sm'"], simp) apply (rule Ex_I [where x = "Var sn"], simp) apply (rule Ex_I [where x = "Var sn'"], simp) apply (simp_all add: SeqSubstFormP.simps [of l s _ v u sl sl' m n sm sm' sn sn']) apply ((rule Conj_I)+, blast intro: LstSeqP_Mem)+ \<comment> \<open>first SeqSubstFormP subgoal\<close> apply (rule All2_Subset [OF Hyp], blast) apply (blast intro!: SUCC_Subset_Ord LstSeqP_OrdP, blast, simp) \<comment> \<open>next SeqSubstFormP subgoal\<close> apply ((rule Conj_I)+, blast intro: LstSeqP_Mem)+ apply (rule All2_Subset [OF Hyp], blast) apply (blast intro!: SUCC_Subset_Ord LstSeqP_OrdP, blast, simp) \<comment> \<open>finally, the equality pairs\<close> apply (rule anti_deduction [THEN thin1]) apply (rule Sym_L [THEN rotate4]) apply (rule Var_Eq_subst_Iff [THEN Iff_MP_same]) apply (rule Sym_L [THEN rotate5]) apply (rule Var_Eq_subst_Iff [THEN Iff_MP_same], force) done qed lemma shows Neg_SubstAtomicP_Fls: "{y EQ Q_Neg z, SubstAtomicP v tm y y'} \<turnstile> Fls" (is ?thesis1) and Disj_SubstAtomicP_Fls: "{y EQ Q_Disj z w, SubstAtomicP v tm y y'} \<turnstile> Fls" (is ?thesis2) and Ex_SubstAtomicP_Fls: "{y EQ Q_Ex z, SubstAtomicP v tm y y'} \<turnstile> Fls" (is ?thesis3) proof - obtain t::name and u::name and t'::name and u'::name where "atom t \<sharp> (z,w,v,tm,y,y',t',u,u')" "atom t' \<sharp> (z,w,v,tm,y,y',u,u')" "atom u \<sharp> (z,w,v,tm,y,y',u')" "atom u' \<sharp> (z,w,v,tm,y,y')" by (metis obtain_fresh) thus ?thesis1 ?thesis2 ?thesis3 by (auto simp: SubstAtomicP.simps [of t v tm y y' t' u u'] HTS intro: Eq_Trans_E [OF Hyp]) qed lemma SeqSubstFormP_eq: "\<lbrakk>H \<turnstile> SeqSubstFormP v tm x z s k; insert (SeqSubstFormP v tm y z s k) H \<turnstile> A\<rbrakk> \<Longrightarrow> insert (x EQ y) H \<turnstile> A" apply (rule cut_same [OF SeqSubstFormP_cong [OF Assume Refl Refl Refl, THEN Iff_MP_same]]) apply (auto simp: insert_commute intro: thin1) done lemma SeqSubstFormP_unique: "{SeqSubstFormP v a x y s kk, SeqSubstFormP v a x y' s' kk'} \<turnstile> y' EQ y" proof - obtain i::name and j::name and j'::name and k::name and k'::name and l::name and m::name and n::name and sm::name and sn::name and sm'::name and sn'::name and m2::name and n2::name and sm2::name and sn2::name and sm2'::name and sn2'::name where atoms: "atom i \<sharp> (s,s',v,a,x,y,y')" "atom j \<sharp> (s,s',v,a,x,i,x,y,y')" "atom j' \<sharp> (s,s',v,a,x,i,j,x,y,y')" "atom k \<sharp> (s,s',v,a,x,y,y',kk',i,j,j')" "atom k' \<sharp> (s,s',v,a,x,y,y',k,i,j,j')" "atom l \<sharp> (s,s',v,a,x,i,j,j',k,k')" "atom m \<sharp> (s,s',v,a,i,j,j',k,k',l)" "atom n \<sharp> (s,s',v,a,i,j,j',k,k',l,m)" "atom sm \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n)" "atom sn \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm)" "atom sm' \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn)" "atom sn' \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm')" "atom m2 \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn')" "atom n2 \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2)" "atom sm2 \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2,n2)" "atom sn2 \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2,n2,sm2)" "atom sm2' \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2,n2,sm2,sn2)" "atom sn2' \<sharp> (s,s',v,a,i,j,j',k,k',l,m,n,sm,sn,sm',sn',m2,n2,sm2,sn2,sm2')" by (metis obtain_fresh) have "{ OrdP (Var k) } \<turnstile> All i (All j (All j' (All k' (SeqSubstFormP v a (Var i) (Var j) s (Var k) IMP (SeqSubstFormP v a (Var i) (Var j') s' (Var k') IMP Var j' EQ Var j)))))" apply (rule OrdIndH [where j=l]) using atoms apply auto apply (rule Swap) apply (rule cut_same) apply (rule cut1 [OF SeqSubstFormP_lemma [of m v a "Var i" "Var j" s "Var k" n sm sm' sn sn']], simp_all, blast) apply (rule cut_same) apply (rule cut1 [OF SeqSubstFormP_lemma [of m2 v a "Var i" "Var j'" s' "Var k'" n2 sm2 sm2' sn2 sn2']], simp_all, blast) apply (rule Disj_EH Conj_EH)+ \<comment> \<open>case 1, both sides are atomic\<close> apply (blast intro: cut2 [OF SubstAtomicP_unique]) \<comment> \<open>case 2, atomic and also not\<close> apply (rule Ex_EH Conj_EH Disj_EH)+ apply simp_all apply (metis Assume AssumeH(7) Disj_I1 Neg_I anti_deduction cut2 [OF Disj_SubstAtomicP_Fls]) apply (rule Conj_EH Disj_EH)+ apply (metis Assume AssumeH(7) Disj_I1 Neg_I anti_deduction cut2 [OF Neg_SubstAtomicP_Fls]) apply (rule Conj_EH)+ apply (metis Assume AssumeH(7) Disj_I1 Neg_I anti_deduction cut2 [OF Ex_SubstAtomicP_Fls]) \<comment> \<open>towards remaining cases\<close> apply (rule Conj_EH Disj_EH Ex_EH)+ apply simp_all apply (metis Assume AssumeH(7) Disj_I1 Neg_I anti_deduction cut2 [OF Disj_SubstAtomicP_Fls]) apply (rule Conj_EH Disj_EH)+ apply (metis Assume AssumeH(7) Disj_I1 Neg_I anti_deduction cut2 [OF Neg_SubstAtomicP_Fls]) apply (rule Conj_EH)+ apply (metis Assume AssumeH(7) Disj_I1 Neg_I anti_deduction cut2 [OF Ex_SubstAtomicP_Fls]) \<comment> \<open>towards remaining cases\<close> apply (rule Conj_EH Disj_EH Ex_EH)+ apply simp_all \<comment> \<open>case two Disj terms\<close> apply (rule All_E' [OF Hyp, where x="Var m"], blast) apply (rule All_E' [OF Hyp, where x="Var n"], blast, simp) apply (rule Disj_EH, blast intro: thin1 ContraProve)+ apply (rule All_E [where x="Var sm"], simp) apply (rule All_E [where x="Var sm'"], simp) apply (rule All_E [where x="Var sm2'"], simp) apply (rule All_E [where x="Var m2"], simp) apply (rule All_E [where x="Var sn", THEN rotate2], simp) apply (rule All_E [where x="Var sn'"], simp) apply (rule All_E [where x="Var sn2'"], simp) apply (rule All_E [where x="Var n2"], simp) apply (rule rotate3) apply (rule Eq_Trans_E [OF Hyp], blast) apply (clarsimp simp add: HTS) apply (rule thin1) apply (rule Disj_EH [OF ContraProve], blast intro: thin1 SeqSubstFormP_eq)+ apply (blast intro: HPair_cong Trans [OF Hyp Sym]) \<comment> \<open>towards remaining cases\<close> apply (rule Conj_EH Disj_EH)+ \<comment> \<open>Negation = Disjunction?\<close> apply (rule Eq_Trans_E [OF Hyp], blast, force simp add: HTS) \<comment> \<open>Existential = Disjunction?\<close> apply (rule Conj_EH) apply (rule Eq_Trans_E [OF Hyp], blast, force simp add: HTS) \<comment> \<open>towards remaining cases\<close> apply (rule Conj_EH Disj_EH Ex_EH)+ apply simp_all \<comment> \<open>Disjunction = Negation?\<close> apply (rule Eq_Trans_E [OF Hyp], blast, force simp add: HTS) apply (rule Conj_EH Disj_EH)+ \<comment> \<open>case two Neg terms\<close> apply (rule Eq_Trans_E [OF Hyp], blast, clarify) apply (rule thin1) apply (rule All_E' [OF Hyp, where x="Var m"], blast, simp) apply (rule Disj_EH, blast intro: thin1 ContraProve)+ apply (rule All_E [where x="Var sm"], simp) apply (rule All_E [where x="Var sm'"], simp) apply (rule All_E [where x="Var sm2'"], simp) apply (rule All_E [where x="Var m2"], simp) apply (rule Disj_EH [OF ContraProve], blast intro: SeqSubstFormP_eq Sym_L)+ apply (blast intro: HPair_cong Sym Trans [OF Hyp]) \<comment> \<open>Existential = Negation?\<close> apply (rule Conj_EH)+ apply (rule Eq_Trans_E [OF Hyp], blast, force simp add: HTS) \<comment> \<open>towards remaining cases\<close> apply (rule Conj_EH Disj_EH Ex_EH)+ apply simp_all \<comment> \<open>Disjunction = Existential\<close> apply (rule Eq_Trans_E [OF Hyp], blast, force simp add: HTS) apply (rule Conj_EH Disj_EH Ex_EH)+ \<comment> \<open>Negation = Existential\<close> apply (rule Eq_Trans_E [OF Hyp], blast, force simp add: HTS) \<comment> \<open>case two Ex terms\<close> apply (rule Conj_EH)+ apply (rule Eq_Trans_E [OF Hyp], blast, clarify) apply (rule thin1) apply (rule All_E' [OF Hyp, where x="Var m"], blast, simp) apply (rule Disj_EH, blast intro: thin1 ContraProve)+ apply (rule All_E [where x="Var sm"], simp) apply (rule All_E [where x="Var sm'"], simp) apply (rule All_E [where x="Var sm2'"], simp) apply (rule All_E [where x="Var m2"], simp) apply (rule Disj_EH [OF ContraProve], blast intro: SeqSubstFormP_eq Sym_L)+ apply (blast intro: HPair_cong Sym Trans [OF Hyp]) done hence p1: "{OrdP (Var k)} \<turnstile> (All j (All j' (All k' (SeqSubstFormP v a (Var i) (Var j) s (Var k) IMP (SeqSubstFormP v a (Var i) (Var j') s' (Var k') IMP Var j' EQ Var j)))))(i::=x)" by (metis All_D) have p2: "{OrdP (Var k)} \<turnstile> (All j' (All k' (SeqSubstFormP v a x (Var j) s (Var k) IMP (SeqSubstFormP v a x (Var j') s' (Var k') IMP Var j' EQ Var j))))(j::=y)" apply (rule All_D) using atoms p1 by simp have p3: "{OrdP (Var k)} \<turnstile> (All k' (SeqSubstFormP v a x y s (Var k) IMP (SeqSubstFormP v a x (Var j') s' (Var k') IMP Var j' EQ y)))(j'::=y')" apply (rule All_D) using atoms p2 by simp have p4: "{OrdP (Var k)} \<turnstile> (SeqSubstFormP v a x y s (Var k) IMP (SeqSubstFormP v a x y' s' (Var k') IMP y' EQ y))(k'::=kk')" apply (rule All_D) using atoms p3 by simp hence "{OrdP (Var k)} \<turnstile> SeqSubstFormP v a x y s (Var k) IMP (SeqSubstFormP v a x y' s' kk' IMP y' EQ y)" using atoms by simp hence "{SeqSubstFormP v a x y s (Var k)} \<turnstile> SeqSubstFormP v a x y s (Var k) IMP (SeqSubstFormP v a x y' s' kk' IMP y' EQ y)" by (metis SeqSubstFormP_imp_OrdP rcut1) hence "{} \<turnstile> SeqSubstFormP v a x y s (Var k) IMP (SeqSubstFormP v a x y' s' kk' IMP y' EQ y)" by (metis Assume Disj_Neg_2 Disj_commute anti_deduction Imp_I) hence "{} \<turnstile> ((SeqSubstFormP v a x y s (Var k) IMP (SeqSubstFormP v a x y' s' kk' IMP y' EQ y)))(k::=kk)" using atoms by (force intro!: Subst) thus ?thesis using atoms by simp (metis DisjAssoc2 Disj_commute anti_deduction) qed subsection\<open>@{term SubstFormP}\<close> theorem SubstFormP_unique: "{SubstFormP v tm x y, SubstFormP v tm x y'} \<turnstile> y' EQ y" proof - obtain s::name and s'::name and k::name and k'::name where "atom s \<sharp> (v,tm,x,y,y',k,k')" "atom s' \<sharp> (v,tm,x,y,y',k,k',s)" "atom k \<sharp> (v,tm,x,y,y')" "atom k' \<sharp> (v,tm,x,y,y',k)" by (metis obtain_fresh) thus ?thesis by (force simp: SubstFormP.simps [of s v tm x y k] SubstFormP.simps [of s' v tm x y' k'] SeqSubstFormP_unique rotate3 thin1) qed end
SUBROUTINE removal (num) IMPLICIT NONE integer(kind=8) num integer i integer, parameter :: ARR_SIZE = 2000000 COMMON primes integer(kind=8), DIMENSION(ARR_SIZE) :: primes if (num /= 0) then do i=num+num, ARR_SIZE, num primes(i) = 0 end do end if END SUBROUTINE removal program problem_10 integer(kind=8) i integer, parameter :: ARR_SIZE = 2000000 integer(kind=8), DIMENSION(ARR_SIZE) :: primes integer(kind=8) total integer(kind=8) rez integer(kind=8) lg_sum COMMON primes total = 0 ! Set primes to 1, 2, .. ARR_SIZE primes = (/ (i, i = 1, ARR_SIZE) /) primes(1) = 0 ! Using: Sieve of Eratosthenes do i=1, ARR_SIZE CALL removal(primes(i)) total = total + primes(i) end do print *,"Problem 10:", total end program problem_10
{-# OPTIONS --cubical #-} module _ where module _ where import Agda.Primitive open import Agda.Primitive.Cubical public postulate Path' : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ {-# BUILTIN PATH Path' #-} {-# BUILTIN PATHP PathP #-} infix 4 _≡_ _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ _≡_ {A = A} = PathP (λ _ → A) Path = _≡_ refl : ∀ {a} {A : Set a} {x : A} → x ≡ x refl {x = x} = \ _ → x testPath : ∀ {A : Set} {b a : A} (let H : Path b b; H = _) → ∀ i → H i ≡ b testPath i = refl
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.sites.sheaf_of_types import Mathlib.PostPort universes v u namespace Mathlib /-! # The canonical topology on a category We define the finest (largest) Grothendieck topology for which a given presheaf `P` is a sheaf. This is well defined since if `P` is a sheaf for a topology `J`, then it is a sheaf for any coarser (smaller) topology. Nonetheless we define the topology explicitly by specifying its sieves: A sieve `S` on `X` is covering for `finest_topology_single P` iff for any `f : Y ⟶ X`, `P` satisfies the sheaf axiom for `S.pullback f`. Showing that this is a genuine Grothendieck topology (namely that it satisfies the transitivity axiom) forms the bulk of this file. This generalises to a set of presheaves, giving the topology `finest_topology Ps` which is the finest topology for which every presheaf in `Ps` is a sheaf. Using `Ps` as the set of representable presheaves defines the `canonical_topology`: the finest topology for which every representable is a sheaf. A Grothendieck topology is called `subcanonical` if it is smaller than the canonical topology, equivalently it is subcanonical iff every representable presheaf is a sheaf. ## References * https://ncatlab.org/nlab/show/canonical+topology * https://ncatlab.org/nlab/show/subcanonical+coverage * https://stacks.math.columbia.edu/tag/00Z9 * https://math.stackexchange.com/a/358709/ -/ namespace category_theory namespace sheaf /-- To show `P` is a sheaf for the binding of `U` with `B`, it suffices to show that `P` is a sheaf for `U`, that `P` is a sheaf for each sieve in `B`, and that it is separated for any pullback of any sieve in `B`. This is mostly an auxiliary lemma to show `is_sheaf_for_trans`. Adapted from [Elephant], Lemma C2.1.7(i) with suggestions as mentioned in https://math.stackexchange.com/a/358709/ -/ theorem is_sheaf_for_bind {C : Type u} [category C] {X : C} (P : Cᵒᵖ ⥤ Type v) (U : sieve X) (B : {Y : C} → {f : Y ⟶ X} → coe_fn U Y f → sieve Y) (hU : presieve.is_sheaf_for P ⇑U) (hB : ∀ {Y : C} {f : Y ⟶ X} (hf : coe_fn U Y f), presieve.is_sheaf_for P ⇑(B hf)) (hB' : ∀ {Y : C} {f : Y ⟶ X} (h : coe_fn U Y f) {Z : C} (g : Z ⟶ Y), presieve.is_separated_for P ⇑(sieve.pullback g (B h))) : presieve.is_sheaf_for P ⇑(sieve.bind (⇑U) B) := sorry /-- Given two sieves `R` and `S`, to show that `P` is a sheaf for `S`, we can show: * `P` is a sheaf for `R` * `P` is a sheaf for the pullback of `S` along any arrow in `R` * `P` is separated for the pullback of `R` along any arrow in `S`. This is mostly an auxiliary lemma to construct `finest_topology`. Adapted from [Elephant], Lemma C2.1.7(ii) with suggestions as mentioned in https://math.stackexchange.com/a/358709 -/ theorem is_sheaf_for_trans {C : Type u} [category C] {X : C} (P : Cᵒᵖ ⥤ Type v) (R : sieve X) (S : sieve X) (hR : presieve.is_sheaf_for P ⇑R) (hR' : ∀ {Y : C} {f : Y ⟶ X}, coe_fn S Y f → presieve.is_separated_for P ⇑(sieve.pullback f R)) (hS : ∀ {Y : C} {f : Y ⟶ X}, coe_fn R Y f → presieve.is_sheaf_for P ⇑(sieve.pullback f S)) : presieve.is_sheaf_for P ⇑S := sorry /-- Construct the finest (largest) Grothendieck topology for which the given presheaf is a sheaf. This is a special case of https://stacks.math.columbia.edu/tag/00Z9, but following a different proof (see the comments there). -/ def finest_topology_single {C : Type u} [category C] (P : Cᵒᵖ ⥤ Type v) : grothendieck_topology C := grothendieck_topology.mk (fun (X : C) (S : sieve X) => ∀ (Y : C) (f : Y ⟶ X), presieve.is_sheaf_for P ⇑(sieve.pullback f S)) sorry sorry sorry /-- Construct the finest (largest) Grothendieck topology for which all the given presheaves are sheaves. This is equal to the construction of https://stacks.math.columbia.edu/tag/00Z9. -/ def finest_topology {C : Type u} [category C] (Ps : set (Cᵒᵖ ⥤ Type v)) : grothendieck_topology C := Inf (finest_topology_single '' Ps) /-- Check that if `P ∈ Ps`, then `P` is indeed a sheaf for the finest topology on `Ps`. -/ theorem sheaf_for_finest_topology {C : Type u} [category C] {P : Cᵒᵖ ⥤ Type v} (Ps : set (Cᵒᵖ ⥤ Type v)) (h : P ∈ Ps) : presieve.is_sheaf (finest_topology Ps) P := sorry /-- Check that if each `P ∈ Ps` is a sheaf for `J`, then `J` is a subtopology of `finest_topology Ps`. -/ theorem le_finest_topology {C : Type u} [category C] (Ps : set (Cᵒᵖ ⥤ Type v)) (J : grothendieck_topology C) (hJ : ∀ (P : Cᵒᵖ ⥤ Type v), P ∈ Ps → presieve.is_sheaf J P) : J ≤ finest_topology Ps := sorry /-- The `canonical_topology` on a category is the finest (largest) topology for which every representable presheaf is a sheaf. See https://stacks.math.columbia.edu/tag/00ZA -/ def canonical_topology (C : Type u) [category C] : grothendieck_topology C := finest_topology (set.range (functor.obj yoneda)) /-- `yoneda.obj X` is a sheaf for the canonical topology. -/ theorem is_sheaf_yoneda_obj {C : Type u} [category C] (X : C) : presieve.is_sheaf (canonical_topology C) (functor.obj yoneda X) := fun (Y : C) (S : sieve Y) (hS : S ∈ coe_fn (canonical_topology C) Y) => sheaf_for_finest_topology (set.range (functor.obj yoneda)) (set.mem_range_self X) S hS /-- A representable functor is a sheaf for the canonical topology. -/ theorem is_sheaf_of_representable {C : Type u} [category C] (P : Cᵒᵖ ⥤ Type v) [representable P] : presieve.is_sheaf (canonical_topology C) P := presieve.is_sheaf_iso (canonical_topology C) representable.w (is_sheaf_yoneda_obj (representable.X P)) /-- A subcanonical topology is a topology which is smaller than the canonical topology. Equivalently, a topology is subcanonical iff every representable is a sheaf. -/ def subcanonical {C : Type u} [category C] (J : grothendieck_topology C) := J ≤ canonical_topology C namespace subcanonical /-- If every functor `yoneda.obj X` is a `J`-sheaf, then `J` is subcanonical. -/ theorem of_yoneda_is_sheaf {C : Type u} [category C] (J : grothendieck_topology C) (h : ∀ (X : C), presieve.is_sheaf J (functor.obj yoneda X)) : subcanonical J := le_finest_topology (set.range (functor.obj yoneda)) J fun (P : Cᵒᵖ ⥤ Type v) (H : P ∈ set.range (functor.obj yoneda)) => Exists.dcases_on H fun (X : C) (H_h : functor.obj yoneda X = P) => Eq._oldrec (h X) H_h /-- If `J` is subcanonical, then any representable is a `J`-sheaf. -/ theorem is_sheaf_of_representable {C : Type u} [category C] {J : grothendieck_topology C} (hJ : subcanonical J) (P : Cᵒᵖ ⥤ Type v) [representable P] : presieve.is_sheaf J P := presieve.is_sheaf_of_le P hJ (is_sheaf_of_representable P) end Mathlib
lemma content_1 [simp]: "content 1 = 1"
--- Will clean up these imports import tactic import analysis.calculus.iterated_deriv import topology.continuous_function.polynomial import topology.separation import topology.path_connected import analysis.complex.basic import analysis.calculus.tangent_cone import analysis.normed_space.units import analysis.asymptotics.asymptotic_equivalent import analysis.analytic.basic import geometry.manifold.algebra.smooth_functions import linear_algebra.finite_dimensional import analysis.normed_space.inner_product import topology.metric_space.basic import topology.continuous_on import analysis.calculus.formal_multilinear_series open set complex classical filter asymptotics continuous_linear_map set metric is_open differentiable open_locale topological_space classical nnreal asymptotics filter ennreal unit_interval noncomputable theory --- Some assumptions theorem holomorph_analytic (f : ℂ → ℂ) (z : ℂ) : differentiable_at ℂ f z ↔ analytic_at ℂ f z := sorry theorem smooth_within_at_iff_holomorph_within_at (f : ℂ → ℂ) {s : set ℂ} (h : is_open s) : ∀ (z : ℂ), (differentiable_within_at ℂ f s z ↔ times_cont_diff_within_at ℂ ⊤ f s z):= sorry theorem smooth_at_iff_holomorph_at (f : ℂ → ℂ) : ∀ (z : ℂ), (differentiable_at ℂ f z ↔ times_cont_diff_at ℂ ⊤ f z) := sorry theorem smooth_on_iff_holomorph_on (f : ℂ → ℂ) {s : set ℂ} (h : is_open s) : differentiable_on ℂ f s ↔ times_cont_diff_on ℂ ⊤ f s := sorry section accuml_pts --- Need this? --- def isolated_pt (X : Type*) [topological_space X] (U : set X) (z : X) : Prop := --- ∃ (V : set X), is_open V ∧ U ∩ (V \ {z}) = ∅ def accumulation_pt (X : Type*) [topological_space X] (U : set X) (z : X) : Prop := ∀ (V : set X), V ∈ (𝓝 z) → ∃ (v : X), v ∈ U ∩ V ∧ ¬ v = z lemma accumulation_pt_open_inter {X : Type*} [topological_space X] {U : set X} {U' : set X} {z : X} (hU' : is_open U') (HU' : z ∈ U') (hz : accumulation_pt X U z) : accumulation_pt X (U ∩ U') z := λ V hV, (set.inter_assoc U U' V).symm ▸ (hz (U' ∩ V) $ _root_.mem_nhds_iff.mpr $ let ⟨t, ht, ht₁, ht₂⟩ := _root_.mem_nhds_iff.mp hV in ⟨U' ∩ t, ⟨set.inter_subset_inter_right U' ht, ⟨is_open.inter hU' ht₁, ⟨HU', ht₂⟩⟩⟩⟩) -- lemma accumulation_pt_mem_closure {X : Type*} [topological_space X] {U : set X} {z : X} (hz : accumulation_pt X U z) : z ∈ closure U := begin rw _root_.mem_closure_iff, intros o ho hxo, rcases hz o (is_open.mem_nhds ho hxo) with ⟨v, hv₁, hv₂⟩, use v, rw set.inter_comm at hv₁, exact hv₁, end end accuml_pts section crowded_space class crowded_space (X : Type*) [t : topological_space X] := (is_crowded : ∀ (x : X), ¬ t.is_open {x}) lemma crowded_space.def (X : Type*) [t : topological_space X] [cr : crowded_space X] : ∀ (x : X), ¬ t.is_open {x} := cr.is_crowded lemma mem_frontier (X : Type*) [t : topological_space X] {U : set X} {z : X} : z ∈ frontier U → ∀ (V : set X), V ∈ 𝓝 z → (V ∩ U ≠ ∅ ∧ V \ U ≠ ∅) := begin intros hz, rw frontier at hz, have h : ∀ (o : set X), is_open o → z ∈ o → (o ∩ U).nonempty := _root_.mem_closure_iff.mp (mem_of_mem_diff hz), have h' : ¬ (∃ (o : set X) (H : o ⊆ U), is_open o ∧ z ∈ o), { let p := not_mem_of_mem_diff hz, rw [mem_interior] at p, exact p, }, simp at h', intros V hV, rcases _root_.mem_nhds_iff.mp hV with ⟨V', hV'₁, hV'₂, hV'₃⟩, split, { exact set.nonempty.ne_empty (set.nonempty.mono (set.inter_subset_inter_left _ hV'₁) $ h V' hV'₂ hV'₃), }, { by_contra w, simp at w, rw [diff_eq_empty] at w, show false, from (h' V' (set.subset.trans hV'₁ w) hV'₂) hV'₃, }, end lemma t1_space_connected_with_two_points_is_crowded (X : Type*) [t : topological_space X] [c : connected_space X] [h : t1_space X] (hX : ∀ (x : X), ∃ (y : X), ¬ y = x) (x : X) : ¬ t.is_open {x} := begin by_contra w, rcases hX x with ⟨y, hy⟩, have minor₁ : is_open {x}ᶜ := is_open_compl_singleton, have : set.nonempty {x}ᶜ, { use y, rw [← ne.def, ← mem_compl_singleton_iff] at hy, exact hy, }, exact (ne_empty_iff_nonempty.mpr $ nonempty_inter w (is_open_compl_singleton) (union_compl_self {x}) (set.singleton_nonempty x) this) (set.inter_compl_self {x}), end lemma accumulation_pt_of_mem_open_nondiscrete (X : Type*) [t : topological_space X] [cr : crowded_space X] {U : set X} (hU : is_open U) {z : X} (hz : z ∈ U) : accumulation_pt X U z := begin let ht := crowded_space.def X, intros V hV, rw is_open_iff_forall_mem_open at hU, rcases _root_.mem_nhds_iff.mp hV with ⟨V', hV'₁, hV'₂, hV'₃⟩, rcases hU z hz with ⟨U', hU'₁, hU'₂, hU'₃⟩, have : ¬ (U' ∩ V') = {z} := by_contra (λ h, ht z $ (not_not.mp h) ▸ is_open.inter hU'₂ hV'₂), rw set.ext_iff at this, simp at this, rcases this with ⟨v, hV⟩, use v, rw iff_iff_implies_and_implies at hV, cases not_and_distrib.mp hV, { simp at h, exact ⟨⟨hU'₁ h.1, hV'₁ h.2.1⟩, h.2.2⟩, }, { simp at h, exfalso, exact h.2 (h.1.symm ▸ hU'₃) (h.1.symm ▸ hV'₃), }, end lemma accumulation_pt_of_open_mem_frontier {X : Type*} [t : topological_space X] [cr : crowded_space X] {U : set X} (hU : is_open U) {z : X} (hz : z ∈ frontier U) : accumulation_pt X U z := if h : z ∈ U then accumulation_pt_of_mem_open_nondiscrete X hU h else begin rw accumulation_pt, intros V hV, let p := (mem_frontier X hz V hV).1, rcases set.nonempty_def.mp (set.ne_empty_iff_nonempty.mp p) with ⟨v, hv⟩, use v, have : ¬ v = z := begin by_contra w, rw ← w at h, exact h hv.2, end, rw set.inter_comm at hv, exact ⟨hv, this⟩, end instance complex_plane_crowded_space : crowded_space ℂ := { is_crowded := begin have : ∀ (x : ℂ), ∃ y, ¬ y = x := begin intros x, by_cases (x = 0), { rw h, exact ⟨1, one_ne_zero⟩, }, { exact ⟨0, λ h', h h'.symm⟩, }, end, exact t1_space_connected_with_two_points_is_crowded ℂ this, end } end crowded_space section accuml_pts_homeomorph lemma mem_image_closure_mem_closure {X : Type*} [topological_space X] {U : set X} {x : X} (hx : x ∈ closure U) {Y : Type*} [topological_space Y] {e : local_homeomorph X Y} (he : x ∈ e.to_local_equiv.source) : e x ∈ closure (e '' U) := begin rw _root_.mem_closure_iff at hx ⊢, intros o ho hxo, have : e.is_image (e⁻¹' o) o := begin intros y hy, split, { intros h, exact h, }, { intros h, exact set.mem_preimage.mp h }, end, let o' := e.to_local_equiv.source ∩ e⁻¹' o, have subkey : x ∈ o' := ⟨he, hxo⟩, have key : is_open o' := (local_homeomorph.is_image.is_open_iff this).mpr (is_open.inter e.open_target ho), rcases hx o' key subkey with ⟨z, hz₁, hz₂⟩, rcases hz₁ with ⟨hz₁₁, hz₁₂⟩, use e z, exact ⟨hz₁₂, set.mem_image_of_mem e hz₂⟩, end lemma mem_closure_inter {X : Type*} [topological_space X] {U : set X} {x : X} (hx : x ∈ closure U) {U' : set X} (hU' : is_open U') (h : x ∈ U') : x ∈ closure (U ∩ U') := begin rw _root_.mem_closure_iff at hx ⊢, intros o ho hxo, specialize hx (o ∩ U') (is_open.inter ho hU') ⟨hxo, h⟩, rw set.inter_assoc at hx, nth_rewrite 1 set.inter_comm at hx, exact hx, end lemma accumulation_pt_local_homeomorph {X : Type*} [topological_space X] {U : set X} {x : X} (hx : accumulation_pt X U x) {Y : Type*} [topological_space Y] {e : local_homeomorph X Y} (he : x ∈ e.to_local_equiv.source) : accumulation_pt Y (e '' U) (e x) := begin rw accumulation_pt at hx ⊢, intros V hV, rcases _root_.mem_nhds_iff.mp hV with ⟨V', hV'₁, hV'₂, hV'₃⟩, specialize hx (e.to_local_equiv.source ∩ e⁻¹' (V' ∩ e.to_local_equiv.target)), have : (e.to_local_equiv.source ∩ e⁻¹' (V' ∩ e.to_local_equiv.target)) ∈ 𝓝 x := begin have minor : is_open (V' ∩ e.to_local_equiv.target) := is_open.inter hV'₂ e.open_target, have key : x ∈ (e⁻¹' (V' ∩ e.to_local_equiv.target)) := set.mem_preimage.mpr ⟨hV'₃, local_equiv.map_source _ he⟩, refine is_open.mem_nhds _ ⟨he, key⟩, apply local_homeomorph.preimage_open_of_open, exact is_open.inter hV'₂ e.open_target, end, rcases hx this with ⟨a, ha₁, ha₂⟩, rcases ha₁ with ⟨haa, hab⟩, let p := set.mem_image_of_mem e hab, use e a, split, { split, exact set.mem_image_of_mem e haa, nth_rewrite 1 set.inter_comm at p, rw [← local_homeomorph.coe_coe, ← local_equiv.symm_image_target_inter_eq e.to_local_equiv V'] at p, have : set.left_inv_on ⇑(e.to_local_equiv) ⇑(e.to_local_equiv.symm) e.to_local_equiv.target := begin nth_rewrite 0 ← local_equiv.symm_symm e.to_local_equiv, rw [←local_homeomorph.symm_source, local_homeomorph.symm_to_local_equiv], exact local_equiv.left_inv_on e.to_local_equiv.symm, end, rw set.left_inv_on.image_image' this (set.inter_subset_left e.to_local_equiv.target V') at p, exact hV'₁ p.2, }, rw set.mem_image at p, rcases p with ⟨b, hb⟩, rcases hb with ⟨left, right⟩, rcases left with ⟨hb₁, hb₂⟩, { intros w, have key : a = b := by rwa [eq_comm, ←local_homeomorph.coe_coe e, set.inj_on.eq_iff (local_equiv.inj_on e.to_local_equiv) hab.1 hb₁] at right, rw ← right at w, rw [eq_comm, ←local_homeomorph.coe_coe e, set.inj_on.eq_iff (local_equiv.inj_on e.to_local_equiv) he hb₁] at w, rw ← key at w, exact ha₂ (eq_comm.mp w), }, end end accuml_pts_homeomorph section complex_theorems theorem identity_theorem {f : ℂ → ℂ} {g : ℂ → ℂ} {U : set ℂ} (hU₁ : is_open U) (hU₂ : is_connected U) (hf : differentiable_on ℂ f U) (hg : differentiable_on ℂ g U) {s₀ : ℂ} {S : set ℂ} (hS : S ⊆ U) (hS' : set.eq_on f g S) (hs₀ : s₀ ∈ S) (hs₀' : accumulation_pt ℂ S s₀): set.eq_on f g U := sorry theorem eq_of_eq_on_open {f : ℂ → ℂ} {g : ℂ → ℂ} {U : set ℂ} (hU₁ : is_open U) (hU₂ : is_connected U) (hf : differentiable_on ℂ f U) (hg : differentiable_on ℂ g U) {V : set ℂ} (hV₁ : is_open V) (hV₂ : V.nonempty) (hV₃ : set.eq_on f g V) (hV₄ : V ⊆ U) : set.eq_on f g U := let ⟨v, hv⟩ := hV₂ in identity_theorem hU₁ hU₂ hf hg hV₄ hV₃ hv $ accumulation_pt_of_mem_open_nondiscrete ℂ hV₁ hv theorem open_mapping_complex {f : ℂ → ℂ} {U : set ℂ} (hU₁ : is_open U) (hU₂ : is_connected U) (hf₁ : differentiable_on ℂ f U) (hf₂ : ∃ (x y : ℂ), x ∈ U ∧ y ∈ U ∧ ¬ f x = f y) : ∀ (U' : set ℂ), U' ⊆ U → is_open U' → is_open (f '' U'):= sorry end complex_theorems /- Trash codes. A bad attempt to prove the identity theorem only assuming some standard results -/ /- lemma nonvanishing_has_local_expansion (ε : ℝ) {hε : ε > 0} (f : ℂ → ℂ) (w : ℂ) {hf₁ : ∃ (z : ℂ), z ∈ ball w ε ∧ ¬f z = 0} {hf₂ : ∀ (z : ℂ), z ∈ ball w ε → analytic_at ℂ f z} {hf₂ : f w = 0}: ∃ (k : ℕ) (r : ℝ) (g : ℂ → ℂ), k > 0 ∧ r ≤ ε ∧ 0 < r ∧ ∀ (x : ℂ), x ∈ ball w r → f = (λ x, ((x - w) ^ k) * g x) ∧ ¬ g x = 0 ∧ analytic_at ℂ g x:= sorry -- I cannot prove the following theorem neatly. I tried to prove it with some disguting inductions, -- but Lean's treatments of derivatives are not quite nice in this case. Maybe using g's expansion -- would be easier. But again, that requires at least one induction. lemma nonvanishing_iter_deriv_of_nonvanishing (f : ℂ → ℂ) (w : ℂ) {hf : analytic_at ℂ f w}: (∃ (k : ℕ), ¬ iterated_deriv k f w = 0) ↔ (∃ (ε : ℝ), 0 < ε ∧ (∀ (z : ℂ), z ∈ ball w ε → analytic_at ℂ f z) ∧ (∃ (z : ℂ), z ∈ ball w ε ∧ ¬f z = 0)) := sorry lemma nonvanishing_disk_of_continuous (f : ℂ → ℂ) (z : ℂ) {hf₁ : continuous_at f z} {hf₂ : ¬ f z = 0}: ∃ (ε : ℝ), 0 < ε ∧ ∀ (x : ℂ), x ∈ ball z ε → ¬ f x = 0 := begin have := hf₁, rw continuous_at_iff at this, let ε' := ∥f z∥ / 2, rw [← ne.def, ← norm_pos_iff] at hf₂, have hε' : 0 < ∥f z∥ / 2 := by linarith, rcases this ε' hε' with ⟨δ, hδ, h⟩, use min ε' δ, split, simp, exact ⟨hε', hδ⟩, { intros x hx, rw [mem_ball', dist_comm] at hx, have lt_δ : dist x z < δ := lt_of_lt_of_le hx (min_le_right _ _), specialize h lt_δ, rw [dist_eq_norm, norm_sub_rev] at h, have key : 0 < ∥f x∥ := calc ∥f x∥ = ∥f z - (f z - f x)∥ : by simp ... ≥ ∥f z∥ - ∥f z - f x∥ : norm_sub_norm_le _ _ ... ≥ ∥f z∥ - ε' : begin simp, apply le_of_lt, exact h, end ... ≥ ∥f z∥ - ∥f z∥ / 2 : begin simp, apply le_of_eq, rw ← norm_eq_abs, end ... = ∥f z∥ / 2 : by linarith ... > 0 : hε', rw [norm_pos_iff] at key, exact key, }, end lemma is_open_nonvanishing_of_continuous (f : ℂ → ℂ) (U : set ℂ) {hU : is_open U} {hf : ∀ (z : ℂ), z ∈ U → continuous_at f z} : is_open {z : ℂ | z ∈ U ∧ ¬ f z = 0} := begin rw metric.is_open_iff at *, dsimp, intros z hz, rcases hz with ⟨hz₁, hz₂⟩, specialize hU z hz₁, specialize hf z hz₁, rcases hU with ⟨δ, hδ₁, hδ₂⟩, rcases nonvanishing_disk_of_continuous f z with ⟨ε, hε₁, hε₂⟩, assumption', use min δ ε, split, simp at hδ₁, exact lt_min hδ₁ hε₁, rw subset_def, dsimp, intros x hx, have key₁ : x ∈ U := hδ₂ ((ball_subset_ball $ min_le_left δ ε) hx), have key₂ : ¬ f x = 0 := hε₂ x ((ball_subset_ball $ min_le_right δ ε) hx), exact ⟨key₁, key₂⟩, end lemma isolated_zeros_of_nonvanishing (ε : ℝ) {hε : ε > 0} (f : ℂ → ℂ) (w : ℂ) {hf₁ : ∃ (z : ℂ), z ∈ ball w ε ∧ ¬f z = 0} {hf₂ : ∀ (z : ℂ), z ∈ ball w ε → analytic_at ℂ f z}: ∃ (r : ℝ), r ≤ ε ∧ 0 < r ∧ ∀ (x : ℂ), x ∈ ball w r → ¬ x - w = 0 → ¬ f x = 0:= begin by_cases (f w = 0), -- the case where f w = 0; use f's local expansion around w { rcases nonvanishing_has_local_expansion ε f w with ⟨k, r, g, H⟩, rcases H with ⟨H₁, H₂, H₃, H₄⟩, use r, split, exact H₂, { split, exact H₃, { intros x hx₁ hx₂, by_contra h', specialize H₄ x hx₁, rcases H₄ with ⟨h₂₁, h₂₂, h₂₃⟩, rw h₂₁ at h', have key : (x - w) ^ k = 0 ∨ g x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h', cases key with key₁ key₂, { rw [← complex.cpow_nat_cast, complex.cpow_eq_zero_iff] at key₁, exact hx₂ key₁.1, }, { exact h₂₂ key₂, }, }, }, assumption', }, -- the case where f w ≠ 0; use the continuity of f at w { specialize hf₂ w (mem_ball_self hε), rcases nonvanishing_disk_of_continuous f w with ⟨r, hr⟩, assumption', use min r ε, split, exact min_le_right _ _, split, { simp, exact ⟨hr.1, hε⟩, }, { intros x hx₁ hx₂, rw [mem_ball'] at hx₁, have key : dist w x < r := lt_of_lt_of_le hx₁ (min_le_left _ _), rw [← mem_ball'] at key, exact hr.2 x key, }, exact analytic_at.continuous_at hf₂, }, end def is_accumulation_point (U : set ℂ) (z : ℂ) : Prop := ∀ (V : set ℂ), V ∈ (𝓝 z) → ∃ (v : ℂ), v ∈ U ∩ V ∧ ¬ v - z = 0 lemma vanishing_disk_of_accumulation_point (U : set ℂ) {hU : is_open U} (f : ℂ → ℂ) {hf : ∀ (z : ℂ), z ∈ U → analytic_at ℂ f z} (s₀ : ℂ) {hs₀ : is_accumulation_point {s : ℂ | f s = 0 ∧ s ∈ U} s₀} {hs₀' : s₀ ∈ {s : ℂ | f s = 0 ∧ s ∈ U}}: ∃ (ε : ℝ), 0 < ε ∧ ball s₀ ε ⊆ U ∧ ∀ (z : ℂ), z ∈ ball s₀ ε → f z = 0 := begin by_contra w, simp only [not_exists, not_and] at w, dsimp at hs₀', rw metric.is_open_iff at hU, specialize hU s₀ hs₀'.2, rcases hU with ⟨ε, hε₁, hε₂⟩, specialize w ε hε₁ hε₂, simp only [not_forall] at w, rcases w with ⟨z, hz₁, hz₂⟩, have hf₁ : ∃ (z : ℂ), z ∈ ball s₀ ε ∧ ¬f z = 0 := ⟨z, ⟨hz₁, hz₂⟩⟩, have hf₂ : ∀ (x : ℂ), x ∈ ball s₀ ε → analytic_at ℂ f x := λ x hx, hf x $ hε₂ hx, rcases isolated_zeros_of_nonvanishing ε f s₀ with ⟨r, hr₁, hr₂, hr₃⟩, assumption', have : ∃ (v : ℂ), v ∈ {s : ℂ | f s = 0 ∧ s ∈ U} ∩ (ball s₀ r) ∧ ¬ v - s₀ = 0 := hs₀ (ball s₀ r) (ball_mem_nhds s₀ hr₂), rcases this with ⟨v, hv₁, hv₂⟩, dsimp at hv₁, show false, from (hr₃ v hv₁.2 hv₂) hv₁.1.1, end theorem vanishing_if_zeros_accumulate (U : set ℂ) {hU₁ : is_open U} {hU₂ : is_connected U} (f : ℂ → ℂ) {hf : ∀ (z : ℂ), z ∈ U → analytic_at ℂ f z} (s₀ : ℂ) {hs₀ : is_accumulation_point {s : ℂ | f s = 0 ∧ s ∈ U} s₀} {hs₀' : s₀ ∈ {s : ℂ | f s = 0 ∧ s ∈ U}}: ∀ (z : ℂ), z ∈ U → f z = 0:= begin let U₁ : set ℂ := {z : ℂ | z ∈ U ∧ ∃ (r : ℝ), 0 < r ∧ ball z r ⊆ U ∧ ∀ (x : ℂ), x ∈ ball z r → f x = 0}, let U₂ : set ℂ := {z : ℂ | z ∈ U ∧ ∃ (k : ℕ), ¬ iterated_deriv k f z = 0}, have h₁ : U₁ ∪ U₂ = U := begin ext, split, { intro h, dsimp at h, cases h with H₁ H₂, exact H₁.1, exact H₂.1, }, { intro H, by_cases (x ∈ U₂), exact (mem_union_right U₁) h, { by_cases h' : f x = 0, { have key : is_accumulation_point {s : ℂ | f s = 0 ∧ s ∈ U} x ∧ x ∈ {s : ℂ | f s = 0 ∧ s ∈ U}:= begin by_contradiction w, rw not_and_distrib at w, cases w with w₁ w₂, { -- sorry, unfold is_accumulation_point at w₁, simp at w₁, rcases w₁ with ⟨U', hU₁', hU₂'⟩, rw metric.mem_nhds_iff at hU₁', rcases hU₁' with ⟨r, hr₁, hr₂⟩, let U'' : set ℂ := ball x r ∩ U, have key₁ : is_open U'' := is_open.inter metric.is_open_ball hU₁, rw metric.is_open_iff at key₁, specialize key₁ x (mem_inter (mem_ball_self hr₁) H), rcases key₁ with ⟨ε, hε₁, hε₂⟩, let x' : ℂ := x + ε / 2, have key₂ : x' ∈ ball x ε := begin simp, have : 0 ≤ ε / 2 := by linarith, exact calc dist x' x = ∥(x + ε / 2) - x∥ : by rw dist_eq_norm ... = complex.abs ↑(ε / 2) : by simp ... = ε / 2 : by rw complex.abs_of_nonneg this ... < ε : by linarith, end, have key₃ : ¬ f x' = 0 := begin by_contra w', have : x' ∈ U'' := hε₂ key₂, simp only [mem_inter_eq] at this, specialize hU₂' x' w' this.2 (hr₂ this.1), have key : ¬ x' - x = 0 := begin simp, exact ne_of_gt hε₁, end, show false, from key hU₂', end, have : ∃ (ε : ℝ), ε > 0 ∧ (∀ (z : ℂ), z ∈ ball x ε → analytic_at ℂ f z) ∧ ∃ (z : ℂ), z ∈ ball x ε ∧ ¬f z = 0 := begin use ε, split, exact hε₁, split, intros z hz, exact hf z (mem_of_mem_inter_right (hε₂ hz)), exact ⟨x', ⟨key₂, key₃⟩⟩, end, have key₄ : x ∈ U₂ := begin dsimp, split, exact H, rcases iff.elim_right (nonvanishing_iter_deriv_of_nonvanishing f x) this with ⟨k, hk⟩, use k, exact hf x H, end, show false, from h key₄, }, { simp at w₂, show false, from (w₂ h') H, }, end, rcases vanishing_disk_of_accumulation_point U f x with ⟨ε, hε₁, hε₂, hε₃⟩, assumption', have : x ∈ U₁ := begin dsimp [U₁], split, exact H, { use ε, exact ⟨hε₁, ⟨hε₂, hε₃⟩⟩, }, end, exact (mem_union_left U₂) this, exact key.1, exact key.2, }, { have key₁ : ∃ (k : ℕ), ¬ iterated_deriv k f x = 0 := by use 0, have key₂ : x ∈ U₂ := begin simp, exact ⟨H, key₁⟩, end, exfalso, exact h key₂, }, }, }, end, have h₂ : U₁ ∩ U₂ = ∅ := begin by_contra, rw [← ne.def, ne_empty_iff_nonempty, nonempty_def] at h, rcases h with ⟨x, hx⟩, dsimp at hx, rcases iff.elim_left (nonvanishing_iter_deriv_of_nonvanishing f x) hx.2.2 with ⟨ε, hε₁, hε₂, hε₃⟩, rcases isolated_zeros_of_nonvanishing ε f x with ⟨r, hr₁, hr₂, hr₃⟩, assumption', swap, exact hf x hx.1.1, rcases hx.1.2 with ⟨r', hr₁', hr₂', hr₃'⟩, let r'' : ℝ := min r r', have minor₁ : 0 < r'' := begin rw lt_min_iff, exact ⟨hr₂, gt.lt hr₁'⟩, end, have minor₂ : ∃ (x' : ℂ), x' ∈ ball x r'' ∧ ¬ x' - x = 0 := begin let x' : ℂ := x + r'' / 2, use x', split, simp only [metric.mem_ball], have : 0 ≤ r'' / 2 := by linarith, exact calc dist x' x = ∥(x + r'' / 2) - x∥ : by rw dist_eq_norm ... = complex.abs ↑(r'' / 2) : by simp ... = r'' / 2 : by rw complex.abs_of_nonneg this ... < r'' : by linarith, simp, exact ne_of_gt minor₁, end, rcases minor₂ with ⟨x', hx₁', hx₂'⟩, have key₁ : f x' = 0 := hr₃' x' ((ball_subset_ball (min_le_right r r')) hx₁'), have key₂ : ¬ f x' = 0 := hr₃ x' ((ball_subset_ball (min_le_left r r')) hx₁') hx₂', show false, from key₂ key₁, end, have h₃ : is_open U₁ := begin rw metric.is_open_iff, intros x hx, dsimp at hx, rcases hx with ⟨hx₁, ε, hε₁, hε₂, hε₃⟩, use ε, split, exact hε₁, intros z hz, dsimp, split, exact hε₂ hz, have : ∃ (r : ℝ), (0 < r ∧ ball z r ⊆ U) ∧ ball z r ⊆ ball x ε := begin have key : is_open (ball x ε) := is_open_ball, rw metric.is_open_iff at key, specialize key z hz, rcases key with ⟨r, hr₁, hr₂⟩, use r, split, exact ⟨hr₁, subset.trans hr₂ hε₂⟩, exact hr₂, end, rcases this with ⟨r, hr₁, hr₂⟩, use r, split, exact hr₁.1, split, exact hr₁.2, intros x' hx', exact hε₃ x' (hr₂ hx'), end, have h₄ : is_open U₂ := begin sorry, end, have h₅ : U₁.nonempty := begin rw nonempty_def, use s₀, dsimp, simp at hs₀', split, exact hs₀'.2, rcases vanishing_disk_of_accumulation_point U f s₀ with ⟨ε, hε₁, hε₂, hε₃⟩, assumption', use ε, exact ⟨hε₁, ⟨hε₂, hε₃⟩⟩, end, have hfinal : U₁ = U := begin have : is_preconnected U := is_connected.is_preconnected hU₂, rw is_preconnected_iff_subset_of_disjoint at this, specialize this U₁ U₂ h₃ h₄ (eq.subset (eq.symm h₁)), have minor : U ∩ (U₁ ∩ U₂) = ∅ := begin rw h₂, simp, end, specialize this minor, cases this, { have minor' : U₁ ⊆ U := begin let h := set.subset_union_left U₁ U₂, rw h₁ at h, exact h, end, exact has_subset.subset.antisymm minor' this, }, { have minor₁ : U₁ ⊆ U := begin let h := set.subset_union_left U₁ U₂, rw h₁ at h, exact h, end, have minor₂ : U₂ ⊆ U := begin let h := set.subset_union_right U₁ U₂, rw h₁ at h, exact h, end, have minor₃ : U₂ = U := has_subset.subset.antisymm minor₂ this, have key : U₁ = ∅ := begin rw [inter_comm, ← set.subset_empty_iff, ← set.diff_eq_self] at h₂, rw ← h₂, by_contra w, rw [← ne.def, set.ne_empty_iff_nonempty, set.nonempty_diff, minor₃] at w, show false, from w minor₁, end, rw [← set.not_nonempty_iff_eq_empty] at key, exfalso, exact key h₅, }, end, intros z hz, have : z ∈ U₁ := (eq.subset (eq.symm hfinal)) hz, dsimp at this, rcases this.2 with ⟨r, hr₁, hr₂, hr₃⟩, specialize hr₃ z (mem_ball_self hr₁), exact hr₃, end theorem eq_if_eq_points_accumulate (U : set ℂ) {hU₁ : is_open U} {hU₂ : is_connected U} (f : ℂ → ℂ) {hf : ∀ (z : ℂ), z ∈ U → analytic_at ℂ f z} (g : ℂ → ℂ) {hg : ∀ (z : ℂ), z ∈ U → analytic_at ℂ g z} (s₀ : ℂ) {hs₀ : is_accumulation_point {s : ℂ | f s = g s ∧ s ∈ U} s₀} {hs₀' : s₀ ∈ {s : ℂ | f s = g s ∧ s ∈ U}} : ∀ (z : ℂ), z ∈ U → f z = g z := begin let h : ℂ → ℂ := f - g, have minor : ∀ (z : ℂ), z ∈ U → analytic_at ℂ h z := λ z hz, analytic_at.sub (hf z hz) $ hg z hz, have key : {s : ℂ | f s = g s ∧ s ∈ U} = {s : ℂ | h s = 0 ∧ s ∈ U} := begin ext, split, { intros hx, dsimp at hx, simp, split, exact calc h x = (f - g) x : by refl ... = f x - g x : by simp ... = f x - f x : by rw ← hx.1 ... = 0 : by ring, exact hx.2, }, { intros hx, dsimp at hx, simp, split, exact calc f x = f x - g x + g x : by simp ... = (f - g) x + g x : by simp ... = h x + g x : by refl ... = 0 + g x : by rw hx.1 ... = g x : by ring, exact hx.2, }, end, rw key at hs₀ hs₀', intros z hz, have : h z = 0 := vanishing_if_zeros_accumulate U h s₀ z hz, assumption', exact calc f z = f z - g z + g z : by simp ... = (f - g) z + g z : by simp ... = h z + g z : by refl ... = 0 + g z : by rw this ... = g z : by ring, end -/
State Before: C : Type u_2 inst✝⁵ : Category C X Y Z : C inst✝⁴ : HasPullbacks C S T : C f : X ⟶ T g : Y ⟶ T i : T ⟶ S inst✝³ : HasPullback i i inst✝² : HasPullback f g inst✝¹ : HasPullback (f ≫ i) (g ≫ i) inst✝ : HasPullback (diagonal i) (map (f ≫ i) (g ≫ i) i i f g (𝟙 S) (_ : (f ≫ i) ≫ 𝟙 S = f ≫ i) (_ : (g ≫ i) ≫ 𝟙 S = g ≫ i)) ⊢ (pullbackDiagonalMapIdIso f g i).inv ≫ snd ≫ snd = snd State After: C : Type u_2 inst✝⁵ : Category C X Y Z : C inst✝⁴ : HasPullbacks C S T : C f : X ⟶ T g : Y ⟶ T i : T ⟶ S inst✝³ : HasPullback i i inst✝² : HasPullback f g inst✝¹ : HasPullback (f ≫ i) (g ≫ i) inst✝ : HasPullback (diagonal i) (map (f ≫ i) (g ≫ i) i i f g (𝟙 S) (_ : (f ≫ i) ≫ 𝟙 S = f ≫ i) (_ : (g ≫ i) ≫ 𝟙 S = g ≫ i)) ⊢ snd ≫ snd = (pullbackDiagonalMapIdIso f g i).hom ≫ snd Tactic: rw [Iso.inv_comp_eq] State Before: C : Type u_2 inst✝⁵ : Category C X Y Z : C inst✝⁴ : HasPullbacks C S T : C f : X ⟶ T g : Y ⟶ T i : T ⟶ S inst✝³ : HasPullback i i inst✝² : HasPullback f g inst✝¹ : HasPullback (f ≫ i) (g ≫ i) inst✝ : HasPullback (diagonal i) (map (f ≫ i) (g ≫ i) i i f g (𝟙 S) (_ : (f ≫ i) ≫ 𝟙 S = f ≫ i) (_ : (g ≫ i) ≫ 𝟙 S = g ≫ i)) ⊢ snd ≫ snd = (pullbackDiagonalMapIdIso f g i).hom ≫ snd State After: no goals Tactic: simp
[GOAL] X : Type u_1 Y : Type u_2 Z : Type u_3 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : TopologicalSpace Z y : Y ⊢ Homotopic (const X y) (const X y) [PROOFSTEP] rfl [GOAL] X : Type u_1 Y : Type u_2 Z : Type u_3 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : TopologicalSpace Z f : C(X, Y) hf : Nullhomotopic f g : C(Y, Z) ⊢ Nullhomotopic (comp g f) [PROOFSTEP] cases' hf with y hy [GOAL] case intro X : Type u_1 Y : Type u_2 Z : Type u_3 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : TopologicalSpace Z f : C(X, Y) g : C(Y, Z) y : Y hy : Homotopic f (const X y) ⊢ Nullhomotopic (comp g f) [PROOFSTEP] use g y [GOAL] case h X : Type u_1 Y : Type u_2 Z : Type u_3 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : TopologicalSpace Z f : C(X, Y) g : C(Y, Z) y : Y hy : Homotopic f (const X y) ⊢ Homotopic (comp g f) (const X (↑g y)) [PROOFSTEP] exact Homotopic.hcomp hy (Homotopic.refl g) [GOAL] X : Type u_1 Y : Type u_2 Z : Type u_3 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : TopologicalSpace Z f : C(Y, Z) hf : Nullhomotopic f g : C(X, Y) ⊢ Nullhomotopic (comp f g) [PROOFSTEP] cases' hf with y hy [GOAL] case intro X : Type u_1 Y : Type u_2 Z : Type u_3 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : TopologicalSpace Z f : C(Y, Z) g : C(X, Y) y : Z hy : Homotopic f (const Y y) ⊢ Nullhomotopic (comp f g) [PROOFSTEP] use y [GOAL] case h X : Type u_1 Y : Type u_2 Z : Type u_3 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : TopologicalSpace Z f : C(Y, Z) g : C(X, Y) y : Z hy : Homotopic f (const Y y) ⊢ Homotopic (comp f g) (const X y) [PROOFSTEP] exact Homotopic.hcomp (Homotopic.refl g) hy [GOAL] X : Type u_1 inst✝¹ : TopologicalSpace X inst✝ : ContractibleSpace X ⊢ Nullhomotopic (ContinuousMap.id X) [PROOFSTEP] obtain ⟨hv⟩ := ContractibleSpace.hequiv_unit X [GOAL] case intro X : Type u_1 inst✝¹ : TopologicalSpace X inst✝ : ContractibleSpace X hv : X ≃ₕ Unit ⊢ Nullhomotopic (ContinuousMap.id X) [PROOFSTEP] use hv.invFun () [GOAL] case h X : Type u_1 inst✝¹ : TopologicalSpace X inst✝ : ContractibleSpace X hv : X ≃ₕ Unit ⊢ Homotopic (ContinuousMap.id X) (const X (↑hv.invFun ())) [PROOFSTEP] convert hv.left_inv.symm [GOAL] Y : Type u_1 inst✝ : TopologicalSpace Y ⊢ ContractibleSpace Y ↔ Nullhomotopic (ContinuousMap.id Y) [PROOFSTEP] constructor [GOAL] case mp Y : Type u_1 inst✝ : TopologicalSpace Y ⊢ ContractibleSpace Y → Nullhomotopic (ContinuousMap.id Y) [PROOFSTEP] intro [GOAL] case mp Y : Type u_1 inst✝ : TopologicalSpace Y a✝ : ContractibleSpace Y ⊢ Nullhomotopic (ContinuousMap.id Y) [PROOFSTEP] apply id_nullhomotopic [GOAL] case mpr Y : Type u_1 inst✝ : TopologicalSpace Y ⊢ Nullhomotopic (ContinuousMap.id Y) → ContractibleSpace Y [PROOFSTEP] rintro ⟨p, h⟩ [GOAL] case mpr.intro Y : Type u_1 inst✝ : TopologicalSpace Y p : Y h : Homotopic (ContinuousMap.id Y) (const Y p) ⊢ ContractibleSpace Y [PROOFSTEP] refine { hequiv_unit' := ⟨{ toFun := ContinuousMap.const _ () invFun := ContinuousMap.const _ p left_inv := ?_ right_inv := ?_ }⟩ } [GOAL] case mpr.intro.refine_1 Y : Type u_1 inst✝ : TopologicalSpace Y p : Y h : Homotopic (ContinuousMap.id Y) (const Y p) ⊢ Homotopic (comp (const Unit p) (const Y ())) (ContinuousMap.id Y) [PROOFSTEP] exact h.symm [GOAL] case mpr.intro.refine_2 Y : Type u_1 inst✝ : TopologicalSpace Y p : Y h : Homotopic (ContinuousMap.id Y) (const Y p) ⊢ Homotopic (comp (const Y ()) (const Unit p)) (ContinuousMap.id Unit) [PROOFSTEP] convert Homotopic.refl (ContinuousMap.id Unit) [GOAL] X : Type u_1 Y : Type u_2 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : ContractibleSpace X ⊢ PathConnectedSpace X [PROOFSTEP] obtain ⟨p, ⟨h⟩⟩ := id_nullhomotopic X [GOAL] case intro.intro X : Type u_1 Y : Type u_2 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : ContractibleSpace X p : X h : Homotopy (ContinuousMap.id X) (const X p) ⊢ PathConnectedSpace X [PROOFSTEP] have : ∀ x, Joined p x := fun x => ⟨(h.evalAt x).symm⟩ [GOAL] case intro.intro X : Type u_1 Y : Type u_2 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : ContractibleSpace X p : X h : Homotopy (ContinuousMap.id X) (const X p) this : ∀ (x : X), Joined p x ⊢ PathConnectedSpace X [PROOFSTEP] rw [pathConnectedSpace_iff_eq] [GOAL] case intro.intro X : Type u_1 Y : Type u_2 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : ContractibleSpace X p : X h : Homotopy (ContinuousMap.id X) (const X p) this : ∀ (x : X), Joined p x ⊢ ∃ x, pathComponent x = Set.univ [PROOFSTEP] use p [GOAL] case h X : Type u_1 Y : Type u_2 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : ContractibleSpace X p : X h : Homotopy (ContinuousMap.id X) (const X p) this : ∀ (x : X), Joined p x ⊢ pathComponent p = Set.univ [PROOFSTEP] ext [GOAL] case h.h X : Type u_1 Y : Type u_2 inst✝² : TopologicalSpace X inst✝¹ : TopologicalSpace Y inst✝ : ContractibleSpace X p : X h : Homotopy (ContinuousMap.id X) (const X p) this : ∀ (x : X), Joined p x x✝ : X ⊢ x✝ ∈ pathComponent p ↔ x✝ ∈ Set.univ [PROOFSTEP] tauto
(******************************************************************************) (* Project: Isabelle/UTP: Unifying Theories of Programming in Isabelle/HOL *) (* File: UNIV_TYPE.thy *) (* Author: Frank Zeyda, University of York (UK) *) (******************************************************************************) (* LAST REVIEWED: 27 March 2014 *) section \<open>Type Universe\<close> theory UNIV_TYPE imports Main begin definition UNIV_TYPE :: "'a itself \<Rightarrow> 'a set" where "UNIV_TYPE (t :: 'a itself) = (UNIV :: 'a set)" (* declare UNIV_TYPE_def [simp] *) syntax "_UNIV_TYPE" :: "type => logic" ("(1UNIV'_T/(1'(_')))") translations "UNIV_T('t)" \<rightleftharpoons> "(CONST UNIV_TYPE) TYPE('t)" theorem "0 \<in> UNIV_T(int)" apply (simp add: UNIV_TYPE_def) done theorem "\<forall>x. x \<in> UNIV_T('a)" apply (simp add: UNIV_TYPE_def) done theorem "UNIV_T('a) = UNIV" apply (simp add: UNIV_TYPE_def) done end
/- Copyright (c) 2022 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import data.real.ennreal import topology.continuous_function.bounded /-! # Thickened indicators This file is about thickened indicators of sets in (pseudo e)metric spaces. For a decreasing sequence of thickening radii tending to 0, the thickened indicators of a closed set form a decreasing pointwise converging approximation of the indicator function of the set, where the members of the approximating sequence are nonnegative bounded continuous functions. ## Main definitions * `thickened_indicator_aux δ E`: The `δ`-thickened indicator of a set `E` as an unbundled `ℝ≥0∞`-valued function. * `thickened_indicator δ E`: The `δ`-thickened indicator of a set `E` as a bundled bounded continuous `ℝ≥0`-valued function. ## Main results * For a sequence of thickening radii tending to 0, the `δ`-thickened indicators of a set `E` tend pointwise to the indicator of `closure E`. - `thickened_indicator_aux_tendsto_indicator_closure`: The version is for the unbundled `ℝ≥0∞`-valued functions. - `thickened_indicator_tendsto_indicator_closure`: The version is for the bundled `ℝ≥0`-valued bounded continuous functions. -/ noncomputable theory open_locale classical nnreal ennreal topological_space bounded_continuous_function open nnreal ennreal set metric emetric filter section thickened_indicator variables {α : Type*} [pseudo_emetric_space α] /-- The `δ`-thickened indicator of a set `E` is the function that equals `1` on `E` and `0` outside a `δ`-thickening of `E` and interpolates (continuously) between these values using `inf_edist _ E`. `thickened_indicator_aux` is the unbundled `ℝ≥0∞`-valued function. See `thickened_indicator` for the (bundled) bounded continuous function with `ℝ≥0`-values. -/ def thickened_indicator_aux (δ : ℝ) (E : set α) : α → ℝ≥0∞ := λ (x : α), (1 : ℝ≥0∞) - (inf_edist x E) / (ennreal.of_real δ) lemma continuous_thickened_indicator_aux {δ : ℝ} (δ_pos : 0 < δ) (E : set α) : continuous (thickened_indicator_aux δ E) := begin unfold thickened_indicator_aux, let f := λ (x : α), (⟨1, (inf_edist x E) / (ennreal.of_real δ)⟩ : ℝ≥0 × ℝ≥0∞), let sub := λ (p : ℝ≥0 × ℝ≥0∞), ((p.1 : ℝ≥0∞) - p.2), rw (show (λ (x : α), ((1 : ℝ≥0∞)) - (inf_edist x E) / (ennreal.of_real δ)) = sub ∘ f, by refl), apply (@ennreal.continuous_nnreal_sub 1).comp, apply (ennreal.continuous_div_const (ennreal.of_real δ) _).comp continuous_inf_edist, norm_num [δ_pos], end lemma thickened_indicator_aux_le_one (δ : ℝ) (E : set α) (x : α) : thickened_indicator_aux δ E x ≤ 1 := by apply @tsub_le_self _ _ _ _ (1 : ℝ≥0∞) lemma thickened_indicator_aux_lt_top {δ : ℝ} {E : set α} {x : α} : thickened_indicator_aux δ E x < ∞ := lt_of_le_of_lt (thickened_indicator_aux_le_one _ _ _) one_lt_top lemma thickened_indicator_aux_closure_eq (δ : ℝ) (E : set α) : thickened_indicator_aux δ (closure E) = thickened_indicator_aux δ E := by simp_rw [thickened_indicator_aux, inf_edist_closure] lemma thickened_indicator_aux_one (δ : ℝ) (E : set α) {x : α} (x_in_E : x ∈ E) : thickened_indicator_aux δ E x = 1 := by simp [thickened_indicator_aux, inf_edist_zero_of_mem x_in_E, tsub_zero] lemma thickened_indicator_aux_one_of_mem_closure (δ : ℝ) (E : set α) {x : α} (x_mem : x ∈ closure E) : thickened_indicator_aux δ E x = 1 := by rw [←thickened_indicator_aux_closure_eq, thickened_indicator_aux_one δ (closure E) x_mem] lemma thickened_indicator_aux_zero {δ : ℝ} (δ_pos : 0 < δ) (E : set α) {x : α} (x_out : x ∉ thickening δ E) : thickened_indicator_aux δ E x = 0 := begin rw [thickening, mem_set_of_eq, not_lt] at x_out, unfold thickened_indicator_aux, apply le_antisymm _ bot_le, have key := tsub_le_tsub (@rfl _ (1 : ℝ≥0∞)).le (ennreal.div_le_div x_out rfl.le), rw [ennreal.div_self (ne_of_gt (ennreal.of_real_pos.mpr δ_pos)) of_real_ne_top] at key, simpa using key, end lemma thickened_indicator_aux_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : set α) : thickened_indicator_aux δ₁ E ≤ thickened_indicator_aux δ₂ E := λ _, tsub_le_tsub (@rfl ℝ≥0∞ 1).le (ennreal.div_le_div rfl.le (of_real_le_of_real hle)) lemma indicator_le_thickened_indicator_aux (δ : ℝ) (E : set α) : E.indicator (λ _, (1 : ℝ≥0∞)) ≤ thickened_indicator_aux δ E := begin intro a, by_cases a ∈ E, { simp only [h, indicator_of_mem, thickened_indicator_aux_one δ E h, le_refl], }, { simp only [h, indicator_of_not_mem, not_false_iff, zero_le], }, end lemma thickened_indicator_aux_subset (δ : ℝ) {E₁ E₂ : set α} (subset : E₁ ⊆ E₂) : thickened_indicator_aux δ E₁ ≤ thickened_indicator_aux δ E₂ := λ _, tsub_le_tsub (@rfl ℝ≥0∞ 1).le (ennreal.div_le_div (inf_edist_anti subset) rfl.le) /-- As the thickening radius δ tends to 0, the δ-thickened indicator of a set E (in α) tends pointwise (i.e., w.r.t. the product topology on `α → ℝ≥0∞`) to the indicator function of the closure of E. This statement is for the unbundled `ℝ≥0∞`-valued functions `thickened_indicator_aux δ E`, see `thickened_indicator_tendsto_indicator_closure` for the version for bundled `ℝ≥0`-valued bounded continuous functions. -/ lemma thickened_indicator_aux_tendsto_indicator_closure {δseq : ℕ → ℝ} (δseq_lim : tendsto δseq at_top (𝓝 0)) (E : set α) : tendsto (λ n, (thickened_indicator_aux (δseq n) E)) at_top (𝓝 (indicator (closure E) (λ x, (1 : ℝ≥0∞)))) := begin rw tendsto_pi_nhds, intro x, by_cases x_mem_closure : x ∈ closure E, { simp_rw [thickened_indicator_aux_one_of_mem_closure _ E x_mem_closure], rw (show (indicator (closure E) (λ _, (1 : ℝ≥0∞))) x = 1, by simp only [x_mem_closure, indicator_of_mem]), exact tendsto_const_nhds, }, { rw (show (closure E).indicator (λ _, (1 : ℝ≥0∞)) x = 0, by simp only [x_mem_closure, indicator_of_not_mem, not_false_iff]), rw mem_closure_iff_inf_edist_zero at x_mem_closure, obtain ⟨ε, ⟨ε_pos, ε_le⟩⟩ : ∃ (ε : ℝ), 0 < ε ∧ ennreal.of_real ε ≤ inf_edist x E, { by_cases dist_infty : inf_edist x E = ∞, { rw dist_infty, use [1, zero_lt_one, le_top], }, { use (inf_edist x E).to_real, exact ⟨(to_real_lt_to_real zero_ne_top dist_infty).mpr (pos_iff_ne_zero.mpr x_mem_closure), of_real_to_real_le⟩, }, }, rw metric.tendsto_nhds at δseq_lim, specialize δseq_lim ε ε_pos, simp only [dist_zero_right, real.norm_eq_abs, eventually_at_top, ge_iff_le] at δseq_lim, rcases δseq_lim with ⟨N, hN⟩, apply @tendsto_at_top_of_eventually_const _ _ _ _ _ _ _ N, intros n n_large, have key : x ∉ thickening ε E, by rwa [thickening, mem_set_of_eq, not_lt], refine le_antisymm _ bot_le, apply (thickened_indicator_aux_mono (lt_of_abs_lt (hN n n_large)).le E x).trans, exact (thickened_indicator_aux_zero ε_pos E key).le, }, end /-- The `δ`-thickened indicator of a set `E` is the function that equals `1` on `E` and `0` outside a `δ`-thickening of `E` and interpolates (continuously) between these values using `inf_edist _ E`. `thickened_indicator` is the (bundled) bounded continuous function with `ℝ≥0`-values. See `thickened_indicator_aux` for the unbundled `ℝ≥0∞`-valued function. -/ @[simps] def thickened_indicator {δ : ℝ} (δ_pos : 0 < δ) (E : set α) : α →ᵇ ℝ≥0 := { to_fun := λ (x : α), (thickened_indicator_aux δ E x).to_nnreal, continuous_to_fun := begin apply continuous_on.comp_continuous continuous_on_to_nnreal (continuous_thickened_indicator_aux δ_pos E), intro x, exact (lt_of_le_of_lt (@thickened_indicator_aux_le_one _ _ δ E x) one_lt_top).ne, end, map_bounded' := begin use 2, intros x y, rw [nnreal.dist_eq], apply (abs_sub _ _).trans, rw [nnreal.abs_eq, nnreal.abs_eq, ←one_add_one_eq_two], have key := @thickened_indicator_aux_le_one _ _ δ E, apply add_le_add; { norm_cast, refine (to_nnreal_le_to_nnreal ((lt_of_le_of_lt (key _) one_lt_top).ne) one_ne_top).mpr (key _), }, end, } lemma thickened_indicator.coe_fn_eq_comp {δ : ℝ} (δ_pos : 0 < δ) (E : set α) : ⇑(thickened_indicator δ_pos E) = ennreal.to_nnreal ∘ thickened_indicator_aux δ E := rfl lemma thickened_indicator_le_one {δ : ℝ} (δ_pos : 0 < δ) (E : set α) (x : α) : thickened_indicator δ_pos E x ≤ 1 := begin rw [thickened_indicator.coe_fn_eq_comp], simpa using (to_nnreal_le_to_nnreal thickened_indicator_aux_lt_top.ne one_ne_top).mpr (thickened_indicator_aux_le_one δ E x), end lemma thickened_indicator_one_of_mem_closure {δ : ℝ} (δ_pos : 0 < δ) (E : set α) {x : α} (x_mem : x ∈ closure E) : thickened_indicator δ_pos E x = 1 := by rw [thickened_indicator_apply, thickened_indicator_aux_one_of_mem_closure δ E x_mem, one_to_nnreal] lemma thickened_indicator_one {δ : ℝ} (δ_pos : 0 < δ) (E : set α) {x : α} (x_in_E : x ∈ E) : thickened_indicator δ_pos E x = 1 := thickened_indicator_one_of_mem_closure _ _ (subset_closure x_in_E) lemma thickened_indicator_zero {δ : ℝ} (δ_pos : 0 < δ) (E : set α) {x : α} (x_out : x ∉ thickening δ E) : thickened_indicator δ_pos E x = 0 := by rw [thickened_indicator_apply, thickened_indicator_aux_zero δ_pos E x_out, zero_to_nnreal] lemma indicator_le_thickened_indicator {δ : ℝ} (δ_pos : 0 < δ) (E : set α) : E.indicator (λ _, (1 : ℝ≥0)) ≤ thickened_indicator δ_pos E := begin intro a, by_cases a ∈ E, { simp only [h, indicator_of_mem, thickened_indicator_one δ_pos E h, le_refl], }, { simp only [h, indicator_of_not_mem, not_false_iff, zero_le], }, end lemma thickened_indicator_mono {δ₁ δ₂ : ℝ} (δ₁_pos : 0 < δ₁) (δ₂_pos : 0 < δ₂) (hle : δ₁ ≤ δ₂) (E : set α) : ⇑(thickened_indicator δ₁_pos E) ≤ thickened_indicator δ₂_pos E := begin intro x, apply (to_nnreal_le_to_nnreal thickened_indicator_aux_lt_top.ne thickened_indicator_aux_lt_top.ne).mpr, apply thickened_indicator_aux_mono hle, end lemma thickened_indicator_subset {δ : ℝ} (δ_pos : 0 < δ) {E₁ E₂ : set α} (subset : E₁ ⊆ E₂) : ⇑(thickened_indicator δ_pos E₁) ≤ thickened_indicator δ_pos E₂ := λ x, (to_nnreal_le_to_nnreal thickened_indicator_aux_lt_top.ne thickened_indicator_aux_lt_top.ne).mpr (thickened_indicator_aux_subset δ subset x) /-- As the thickening radius δ tends to 0, the δ-thickened indicator of a set E (in α) tends pointwise to the indicator function of the closure of E. Note: This version is for the bundled bounded continuous functions, but the topology is not the topology on `α →ᵇ ℝ≥0`. Coercions to functions `α → ℝ≥0` are done first, so the topology instance is the product topology (the topology of pointwise convergence). -/ lemma thickened_indicator_tendsto_indicator_closure {δseq : ℕ → ℝ} (δseq_pos : ∀ n, 0 < δseq n) (δseq_lim : tendsto δseq at_top (𝓝 0)) (E : set α) : tendsto (λ (n : ℕ), (coe_fn : (α →ᵇ ℝ≥0) → (α → ℝ≥0)) (thickened_indicator (δseq_pos n) E)) at_top (𝓝 (indicator (closure E) (λ x, (1 : ℝ≥0)))) := begin have key := thickened_indicator_aux_tendsto_indicator_closure δseq_lim E, rw tendsto_pi_nhds at *, intro x, rw (show indicator (closure E) (λ x, (1 : ℝ≥0)) x = (indicator (closure E) (λ x, (1 : ℝ≥0∞)) x).to_nnreal, by refine (congr_fun (comp_indicator_const 1 ennreal.to_nnreal zero_to_nnreal) x).symm), refine tendsto.comp (tendsto_to_nnreal _) (key x), by_cases x_mem : x ∈ closure E; simp [x_mem], end end thickened_indicator -- section
(* Title: Category theory using Isar and Locales Author: Greg O'Keefe, June, July, August 2003 License: LGPL Define homfunctors, prove that they are functors. *) header HomFunctors theory HomFunctors imports SetCat Functors begin locale into_set = two_cats AA BB for AA :: "('o,'a,'m)category_scheme" (structure) and BB (structure) + fixes U and Set defines "U \<equiv> (UNIV::'a set)" defines "Set \<equiv> set_cat U" assumes BB_Set: "BB = Set" fixes homf ("Hom'(_,'_')") defines "homf A \<equiv> \<lparr> om = (\<lambda>B\<in>Ob. Hom A B), am = (\<lambda>f\<in>Ar. \<lparr>set_dom=Hom A (Dom f),set_func=(\<lambda>g\<in>Hom A (Dom f). f \<bullet> g),set_cod=Hom A (Cod f)\<rparr>) \<rparr>" lemma (in into_set) homf_preserves_objects: "Hom(A,_)\<^bsub>\<o>\<^esub> : Ob \<rightarrow> ob Set" proof (rule funcsetI) fix B assume B: "B \<in> Ob" have "Hom(A,_)\<^bsub>\<o>\<^esub> B = Hom A B" using B by (simp add: homf_def) moreover have "\<dots> \<in> ob Set" by (simp add: U_def Set_def set_cat_def) ultimately show "Hom(A,_)\<^bsub>\<o>\<^esub> B \<in> ob Set" by simp qed lemma (in into_set) homf_preserves_dom: assumes f: "f \<in> Ar" shows "Hom(A,_)\<^bsub>\<o>\<^esub> (Dom f) = dom Set (Hom(A,_)\<^bsub>\<a>\<^esub> f)" proof- have "Dom f \<in> Ob" using f .. hence 1: "Hom(A,_)\<^bsub>\<o>\<^esub> (Dom f) = Hom A (Dom f)" using f by (simp add: homf_def) have 2: "dom Set (Hom(A,_)\<^bsub>\<a>\<^esub> f) = Hom A (Dom f)" using f by (simp add: Set_def homf_def) from 1 and 2 show ?thesis by simp qed lemma (in into_set) homf_preserves_cod: assumes f: "f \<in> Ar" shows "Hom(A,_)\<^bsub>\<o>\<^esub> (Cod f) = cod Set (Hom(A,_)\<^bsub>\<a>\<^esub> f)" proof- have "Cod f \<in> Ob" using f .. hence 1: "Hom(A,_)\<^bsub>\<o>\<^esub> (Cod f) = Hom A (Cod f)" using f by (simp add: homf_def) have 2: "cod Set (Hom(A,_)\<^bsub>\<a>\<^esub> f) = Hom A (Cod f)" using f by (simp add: Set_def homf_def) from 1 and 2 show ?thesis by simp qed lemma (in into_set) homf_preserves_id: assumes B: "B \<in> Ob" shows "Hom(A,_)\<^bsub>\<a>\<^esub> (Id B) = id Set (Hom(A,_)\<^bsub>\<o>\<^esub> B)" proof- have 1: "Id B \<in> Ar" using B .. have 2: "Dom (Id B) = B" using B by (rule AA.id_dom_cod) have 3: "Cod (Id B) = B" using B by (rule AA.id_dom_cod) have 4: "(\<lambda>g\<in>Hom A B. (Id B) \<bullet> g) = (\<lambda>g\<in>Hom A B. g)" by (rule ext) (auto simp add: hom_def) have "Hom(A,_)\<^bsub>\<a>\<^esub> (Id B) = \<lparr> set_dom=Hom A B, set_func=(\<lambda>g\<in>Hom A B. g), set_cod=Hom A B\<rparr>" by (simp add: homf_def 1 2 3 4) also have "\<dots>= id Set (Hom(A,_)\<^bsub>\<o>\<^esub> B)" using B by (simp add: Set_def U_def set_cat_def set_id_def homf_def) finally show ?thesis . qed lemma (in into_set) homf_preserves_comp: assumes f: "f \<in> Ar" and g: "g \<in> Ar" and fg: "Cod f = Dom g" shows "Hom(A,_)\<^bsub>\<a>\<^esub> (g \<bullet> f) = (Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)" proof- have 1: "g \<bullet> f \<in> Ar" using assms .. have 2: "Dom (g \<bullet> f) = Dom f" using f g fg .. have 3: "Cod (g \<bullet> f) = Cod g" using f g fg .. have lhs: "Hom(A,_)\<^bsub>\<a>\<^esub> (g \<bullet> f) = \<lparr> set_dom=Hom A (Dom f), set_func=(\<lambda>h\<in>Hom A (Dom f). (g \<bullet> f) \<bullet> h), set_cod=Hom A (Cod g)\<rparr>" by (simp add: homf_def 1 2 3) have 4: "set_dom ((Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)) = Hom A (Dom f)" using f by (simp add: set_comp_def homf_def) have 5: "set_cod ((Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)) = Hom A (Cod g)" using g by (simp add: set_comp_def homf_def) have "set_func ((Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)) = compose (Hom A (Dom f)) (\<lambda>y\<in>Hom A (Dom g). g \<bullet> y) (\<lambda>x\<in>Hom A (Dom f). f \<bullet> x)" using f g by (simp add: set_comp_def homf_def) also have "\<dots> = (\<lambda>h\<in>Hom A (Dom f). (g \<bullet> f) \<bullet> h)" proof ( rule extensionalityI, rule compose_extensional, rule restrict_extensional, simp) fix h assume 10: "h \<in> Hom A (Dom f)" hence 11: "f \<bullet> h \<in> Hom A (Dom g)" proof- from 10 have "h \<in> Ar" by (simp add: hom_def) have 100: "(op \<bullet>) : Hom (Dom f) (Dom g) \<rightarrow> Hom A (Dom f) \<rightarrow> Hom A (Dom g)" by (rule AA.comp_types) have "f \<in> Hom (Dom f) (Cod f)" using f by (simp add: hom_def) hence 101: "f \<in> Hom (Dom f) (Dom g)" using fg by simp from 100 and 101 have "(op \<bullet>) f : Hom A (Dom f) \<rightarrow> Hom A (Dom g)" by (rule funcset_mem) from this and 10 show "f \<bullet> h \<in> Hom A (Dom g)" by (rule funcset_mem) qed hence "Cod (f \<bullet> h) = Dom g" and "Dom (f \<bullet> h) = A" and "f \<bullet> h \<in> Ar" by (simp_all add: hom_def) thus "compose (Hom A (Dom f)) (\<lambda>y\<in>Hom A (Dom g). g \<bullet> y) (\<lambda>x\<in>Hom A (Dom f). f \<bullet> x) h = (g \<bullet> f) \<bullet> h" using f g fg 10 by (simp add: compose_def 10 11 hom_def) qed finally have 6: "set_func ((Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f)) = (\<lambda>h\<in>Hom A (Dom f). (g \<bullet> f) \<bullet> h)" . from 4 and 5 and 6 have rhs: "(Hom(A,_)\<^bsub>\<a>\<^esub> g) \<odot> (Hom(A,_)\<^bsub>\<a>\<^esub> f) = \<lparr> set_dom=Hom A (Dom f), set_func=(\<lambda>h\<in>Hom A (Dom f). (g \<bullet> f) \<bullet> h), set_cod=Hom A (Cod g)\<rparr>" by simp show ?thesis by (simp add: lhs rhs) qed theorem (in into_set) homf_into_set: "Functor Hom(A,_) : AA \<longrightarrow> Set" proof (intro functor.intro functor_axioms.intro) show "Hom(A,_)\<^bsub>\<a>\<^esub> : Ar \<rightarrow> ar Set" by (rule homf_preserves_arrows) show "Hom(A,_)\<^bsub>\<o>\<^esub> : Ob \<rightarrow> ob Set" by (rule homf_preserves_objects) show "\<forall>f\<in>Ar. Hom(A,_)\<^bsub>\<o>\<^esub> (Dom f) = dom Set (Hom(A,_)\<^bsub>\<a>\<^esub> f)" by (intro ballI) (rule homf_preserves_dom) show "\<forall>f\<in>Ar. Hom(A,_)\<^bsub>\<o>\<^esub> (Cod f) = cod Set (Hom(A,_)\<^bsub>\<a>\<^esub> f)" by (intro ballI) (rule homf_preserves_cod) show "\<forall>B\<in>Ob. Hom(A,_)\<^bsub>\<a>\<^esub> (Id B) = id Set (Hom(A,_)\<^bsub>\<o>\<^esub> B)" by (intro ballI) (rule homf_preserves_id) show "\<forall>f\<in>Ar. \<forall>g\<in>Ar. Cod f = Dom g \<longrightarrow> Hom(A,_)\<^bsub>\<a>\<^esub> (g \<bullet> f) = comp Set (Hom(A,_)\<^bsub>\<a>\<^esub> g) (Hom(A,_)\<^bsub>\<a>\<^esub> f)" by (intro ballI impI, simp add: Set_def set_cat_def) (rule homf_preserves_comp) show "two_cats AA Set" proof intro_locales show "category Set" by (unfold Set_def, rule set_cat_cat) qed qed end
/* * Copyright: 2018 Gerard Choinka ([email protected]) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or * copy at http://www.boost.org/LICENSE_1_0.txt) */ #pragma once #include <boost/hana.hpp> namespace tup { namespace hana = boost::hana; using namespace hana::literals; // contains the _c suffix namespace tag { struct Move {}; struct Left {}; struct Right {}; struct IfFood {}; struct Prog2 {}; struct Prog3 {}; } // namespace tag template <typename ContextType, typename Child0T, typename Child1T, typename Child2T> void eval(hana::tuple<tag::Prog3, Child0T, Child1T, Child2T> node, ContextType& c); template <typename ContextType, typename Child0T, typename Child1T> void eval(hana::tuple<tag::Prog2, Child0T, Child1T> node, ContextType& c); template <typename ContextType, typename TrueBranchT, typename FalseBranchT> void eval(hana::tuple<tag::IfFood, TrueBranchT, FalseBranchT> node, ContextType& c); template <typename ContextType> void eval(hana::tuple<tag::Move>, ContextType& c) { c.move(); } template <typename ContextType> void eval(hana::tuple<tag::Left>, ContextType& c) { c.left(); } template <typename ContextType> void eval(hana::tuple<tag::Right>, ContextType& c) { c.right(); } template <typename ContextType, typename TrueBranchT, typename FalseBranchT> void eval(hana::tuple<tag::IfFood, TrueBranchT, FalseBranchT> node, ContextType& c) { if (c.is_food_in_front()) eval(node[1_c], c); else eval(node[2_c], c); } template <typename ContextType, typename Child0T, typename Child1T> void eval(hana::tuple<tag::Prog2, Child0T, Child1T> node, ContextType& c) { eval(node[1_c], c); eval(node[2_c], c); } template <typename ContextType, typename Child0T, typename Child1T, typename Child2T> void eval(hana::tuple<tag::Prog3, Child0T, Child1T, Child2T> node, ContextType& c) { eval(node[1_c], c); eval(node[2_c], c); eval(node[3_c], c); } } // namespace tup
#Define our Birthday Sim Function pbirthdaysim <- function(n, nsims=100000, feb29=TRUE) { ## Using nsims simulations, estimate the probability ## that a room of n people includes a shared birthday bdays <- 1:366 ## Feb 29 represented as day 366 ## We'll sample other days 4 times as often ## compared to day 366 probs <- c(rep(4,365),1) if(!feb29) { # drop Feb 29 from bdays and probs bdays <- bdays[-366] probs <- probs[-366] } probs <- probs/sum(probs) anydup <- function(ignored) ## simulate n birthdays, return TRUE if ## there's a duplicate any(duplicated(sample(bdays, n, prob=probs, replace=TRUE))) sum(sapply(seq(nsims), anydup)) / nsims } # install the package devtools #install.packages("devtools") # install the doAzureParallel and rAzureBatch package #devtools::install_github("Azure/rAzureBatch") #devtools::install_github("Azure/doAzureParallel") #Run on the cloud cluster library(doAzureParallel) setCredentials("credentials.json") cl <- makeCluster("cluster-birthday.json") registerDoAzureParallel(cl) system.time(bdayp <- foreach(n=1:100) %dopar% pbirthdaysim(n)) bdayp <- unlist(bdayp) plot(bdayp, xlab="People in room", ylab="Probability of shared birthday") abline(h=0.5) # de-provision your cluster in Azure #stopCluster(cl)
import LMT variable {I} [Nonempty I] {E} [Nonempty E] [Nonempty (A I E)] example {a1 a2 a3 : A I E} : (((a1).write i1 (v3)).write i3 (v3)) ≠ (((a1).write i3 (v3)).write i1 (v3)) → False := by arr
f1 : Nat f1 = g where namespace X export g : Nat g = 5 f3 : Nat f3 = Main.X.g f2 : Nat f2 = g where namespace X export g : Nat g = 5
-- Andreas, 2019-06-25, issue #3855 reported by nad -- Constraint solver needs to respect erasure. module _ (_≡_ : {A : Set₁} → A → A → Set) (refl : {A : Set₁} (x : A) → x ≡ x) where -- rejected : (@0 A : Set) → A ≡ A -- rejected A = refl A should-also-be-rejected : (@0 A : Set) → A ≡ A should-also-be-rejected A = refl _
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Mario Carneiro, Robert Y. Lewis -/ import Mathlib.Tactic.Basic import Mathlib.Tactic.NormCast import Mathlib.Tactic.Qify.Attr import Mathlib.Tactic.Zify import Mathlib.Data.Rat.Cast /-! # `qify` tactic The `qify` tactic is used to shift propositions from `ℕ` or `ℤ` to `ℚ`. This is often useful since `ℚ` has well-behaved division. ``` example (a b c x y z : ℕ) (h : ¬ x*y*z < 0) : c < a + 3*b := by qify qify at h /- h : ¬↑x * ↑y * ↑z < 0 ⊢ ↑c < ↑a + 3 * ↑b -/ sorry ``` -/ namespace Mathlib.Tactic.Qify open Lean open Lean.Meta open Lean.Parser.Tactic open Lean.Elab.Tactic /-- The `qify` tactic is used to shift propositions from `ℕ` or `ℤ` to `ℚ`. This is often useful since `ℚ` has well-behaved division. ``` example (a b c x y z : ℕ) (h : ¬ x*y*z < 0) : c < a + 3*b := by qify qify at h /- h : ¬↑x * ↑y * ↑z < 0 ⊢ ↑c < ↑a + 3 * ↑b -/ sorry ``` `qify` can be given extra lemmas to use in simplification. This is especially useful in the presence of nat subtraction: passing `≤` arguments will allow `push_cast` to do more work. ``` example (a b c : ℤ) (h : a / b = c) (hab : b ∣ a) (hb : b ≠ 0) : a = c * b := by qify [hab] at h hb ⊢ exact (div_eq_iff hb).1 h ``` `qify` makes use of the `@[zify_simps]` and `@[qify_simps]` attributes to move propositions, and the `push_cast` tactic to simplify the `ℚ`-valued expressions. -/ syntax (name := qify) "qify" (simpArgs)? (ppSpace location)? : tactic macro_rules | `(tactic| qify $[[$simpArgs,*]]? $[at $location]?) => let args := simpArgs.map (·.getElems) |>.getD #[] `(tactic| simp (config := {decide := false}) only [zify_simps, qify_simps, push_cast, $args,*] $[at $location]?) @[qify_simps] lemma int_cast_eq (a b : ℤ) : a = b ↔ (a : ℚ) = (b : ℚ) := by simp only [Int.cast_inj] @[qify_simps] lemma int_cast_le (a b : ℤ) : a ≤ b ↔ (a : ℚ) ≤ (b : ℚ) := Int.cast_le.symm @[qify_simps] lemma int_cast_lt (a b : ℤ) : a < b ↔ (a : ℚ) < (b : ℚ) := Int.cast_lt.symm @[qify_simps] lemma int_cast_ne (a b : ℤ) : a ≠ b ↔ (a : ℚ) ≠ (b : ℚ) := by simp only [ne_eq, Int.cast_inj]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.algebra.pointwise import Mathlib.order.filter.basic import Mathlib.PostPort universes u v namespace Mathlib /-! # Pointwise operations on filters. The pointwise operations on filters have nice properties, such as • `map m (f₁ * f₂) = map m f₁ * map m f₂` • `𝓝 x * 𝓝 y = 𝓝 (x * y)` -/ namespace filter protected instance has_one {α : Type u} [HasOne α] : HasOne (filter α) := { one := principal 1 } @[simp] theorem mem_zero {α : Type u} [HasZero α] (s : set α) : s ∈ 0 ↔ 0 ∈ s := sorry protected instance has_mul {α : Type u} [monoid α] : Mul (filter α) := { mul := fun (f g : filter α) => mk (set_of fun (s : set α) => ∃ (t₁ : set α), ∃ (t₂ : set α), t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ * t₂ ⊆ s) sorry sorry sorry } theorem mem_add {α : Type u} [add_monoid α] {f : filter α} {g : filter α} {s : set α} : s ∈ f + g ↔ ∃ (t₁ : set α), ∃ (t₂ : set α), t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ + t₂ ⊆ s := iff.rfl theorem mul_mem_mul {α : Type u} [monoid α] {f : filter α} {g : filter α} {s : set α} {t : set α} (hs : s ∈ f) (ht : t ∈ g) : s * t ∈ f * g := Exists.intro s (Exists.intro t { left := hs, right := { left := ht, right := set.subset.refl (s * t) } }) protected theorem mul_le_mul {α : Type u} [monoid α] {f₁ : filter α} {f₂ : filter α} {g₁ : filter α} {g₂ : filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁ * g₁ ≤ f₂ * g₂ := sorry theorem ne_bot.add {α : Type u} [add_monoid α] {f : filter α} {g : filter α} : ne_bot f → ne_bot g → ne_bot (f + g) := sorry protected theorem add_assoc {α : Type u} [add_monoid α] (f : filter α) (g : filter α) (h : filter α) : f + g + h = f + (g + h) := sorry protected theorem one_mul {α : Type u} [monoid α] (f : filter α) : 1 * f = f := sorry protected theorem add_zero {α : Type u} [add_monoid α] (f : filter α) : f + 0 = f := sorry protected instance monoid {α : Type u} [monoid α] : monoid (filter α) := monoid.mk Mul.mul filter.mul_assoc 1 filter.one_mul filter.mul_one protected theorem map_add {α : Type u} {β : Type v} [add_monoid α] [add_monoid β] (m : α → β) [is_add_hom m] {f₁ : filter α} {f₂ : filter α} : map m (f₁ + f₂) = map m f₁ + map m f₂ := sorry protected theorem map_one {α : Type u} {β : Type v} [monoid α] [monoid β] (m : α → β) [is_monoid_hom m] : map m 1 = 1 := sorry -- TODO: prove similar statements when `m` is group homomorphism etc. theorem Mathlib.map.is_add_monoid_hom {α : Type u} {β : Type v} [add_monoid α] [add_monoid β] (m : α → β) [is_add_monoid_hom m] : is_add_monoid_hom (map m) := is_add_monoid_hom.mk (filter.map_zero m) -- The other direction does not hold in general. theorem comap_mul_comap_le {α : Type u} {β : Type v} [monoid α] [monoid β] (m : α → β) [is_mul_hom m] {f₁ : filter β} {f₂ : filter β} : comap m f₁ * comap m f₂ ≤ comap m (f₁ * f₂) := sorry theorem tendsto.mul_mul {α : Type u} {β : Type v} [monoid α] [monoid β] {m : α → β} [is_mul_hom m] {f₁ : filter α} {g₁ : filter α} {f₂ : filter β} {g₂ : filter β} : tendsto m f₁ f₂ → tendsto m g₁ g₂ → tendsto m (f₁ * g₁) (f₂ * g₂) := fun (hf : tendsto m f₁ f₂) (hg : tendsto m g₁ g₂) => eq.mpr (id (Eq._oldrec (Eq.refl (tendsto m (f₁ * g₁) (f₂ * g₂))) (tendsto.equations._eqn_1 m (f₁ * g₁) (f₂ * g₂)))) (eq.mpr (id (Eq._oldrec (Eq.refl (map m (f₁ * g₁) ≤ f₂ * g₂)) (filter.map_mul m))) (filter.mul_le_mul hf hg)) end Mathlib
Its a pretty good bet that most banks and many credit unions offer safe deposit boxes. How big are they and how much do they cost? What sort of account, if any, does one have to have with the bank in order to open up a safe deposit box? Good questions! I dont know! WIKI PROJECT TIME! Choose one of the banks below, call them up, and tell us what you find out! Bank of America Chase has them, charges setup fee for free deposit box w/certain account types First Northern Bank has them, rates? XGolden 1 Credit UnionX Doesnt offer safe deposit boxes at their Davis branch. Premier West Bank River City Bank Travis Credit Union Has safe deposit boxes. Rates? US Bank Union Bank Has safe deposit boxes. Rates? XUSE Credit UnionX Doesnt offer safe deposit boxes at their Davis branch. Wells Fargo has them at the downtown location. $20 key deposit (one time fee), box rates start from $35/year. You need an account there to get a box. Yolo Federal Credit Union
[STATEMENT] lemma map_add_eq_empty_iff[simp]: "(f++g = empty) \<longleftrightarrow> f = empty \<and> g = empty" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (f ++ g = Map.empty) = (f = Map.empty \<and> g = Map.empty) [PROOF STEP] by (metis map_add_None)
Require MathClasses.misc.JMrelation. Require Import MathClasses.interfaces.abstract_algebra MathClasses.interfaces.functors MathClasses.theory.categories. Record Object := object { obj:> Type ; Arrows_inst: Arrows obj ; Equiv_inst: ∀ x y: obj, Equiv (x ⟶ y) ; CatId_inst: CatId obj ; CatComp_inst: CatComp obj ; Category_inst: Category obj }. Arguments object _ {Arrows_inst Equiv_inst CatId_inst CatComp_inst Category_inst}. Existing Instance Arrows_inst. Existing Instance Equiv_inst. Existing Instance CatId_inst. Existing Instance CatComp_inst. Existing Instance Category_inst. Record Arrow (x y: Object): Type := arrow { map_obj:> obj x → obj y ; Fmap_inst: Fmap map_obj ; Functor_inst: Functor map_obj _ }. Arguments arrow {x y} _ _ _. Arguments map_obj {x y} _ _. Existing Instance Fmap_inst. Existing Instance Functor_inst. Instance: Arrows Object := Arrow. (* Hint Extern 4 (Arrows Object) => exact Arrow: typeclass_instances. *) Section contents. Section more_arrows. Context (x y: Object). Global Instance e: Equiv (x ⟶ y) := λ a b, (∀ v, a v ≡ b v) ∧ (∀ `(f: v ⟶ w), JMrelation.R (=) (fmap a f) _ (=) (fmap b f)). Instance e_refl: Reflexive e. Proof. intro a. unfold e. intuition. apply JMrelation.reflexive, _. Qed. Instance e_sym: Symmetric e. Proof with intuition. unfold e. intros ?? [P Q]... apply JMrelation.symmetric... Qed. Instance e_trans: Transitive e. Proof with intuition. unfold e. intros a b c [P Q] [R S]... transitivity (b v)... apply JMrelation.transitive with _ (=) (fmap b f)... Qed. Global Instance: Setoid (x ⟶ y). Proof. split; apply _. Qed. End more_arrows. Global Instance: CatId Object := λ _, arrow id _ _. Global Program Instance: CatComp Object := λ _ _ _ x y, arrow (x ∘ y) _ _. Global Instance: ∀ x y z: Object, Proper ((=) ==> (=) ==> (=)) ((◎): (y ⟶ z) → (x ⟶ y) → (x ⟶ z)). Proof with intuition; try apply _. unfold equiv, e. intros x y z a b [P Q] c d [R S]. split; intros. change (a (c v) ≡ b (d v)). congruence. change (JMrelation.R (=) (fmap a (fmap c f)) _ (=) (fmap b (fmap d f))). apply JMrelation.transitive with _ (=) (fmap a (fmap d f))... specialize (S _ _ f). revert S. generalize (fmap c f) (fmap d f). repeat rewrite R. intros. apply JMrelation.relate. rewrite (JMrelation.unJM _ _ _ _ _ S)... (* <- uses K *) Qed. Global Instance: Category Object. Proof. repeat (split; try apply _); intuition; apply reflexivity. Qed. End contents.
lemmas tendsto_scaleR [tendsto_intros] = bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
State Before: K : Type u V : Type v inst✝⁴ : Ring K inst✝³ : AddCommGroup V inst✝² : Module K V V₂ : Type v' inst✝¹ : AddCommGroup V₂ inst✝ : Module K V₂ h : lift (Module.rank K V) ≤ lift (Module.rank K V₂) h' : Module.rank K V₂ < ℵ₀ ⊢ finrank K V ≤ finrank K V₂ State After: no goals Tactic: simpa only [toNat_lift] using toNat_le_of_le_of_lt_aleph0 (lift_lt_aleph0.mpr h') h
From FOL Require Import FullSyntax. From MetaCoq.Template Require Import utils All Pretty Checker. Require Export MetaCoq.Template.utils.bytestring. Require Import List String Lia. (* Both metacoq and FOL have terms. *) Notation term := Core.term. Notation string := String.t. (* * Reification Please read the PDF file giving a detailed description. We are given a Coq term and try to find a reification of it in the syntax of a specific kind of first-order theory. *) Section FailureMonad. (* ** FailureMonad Since our function is partial, and we want to give helpful error messages to the User, we use this monad, which represents either success or failure, along with an error message *) Inductive FailureMonad (A:Type) : Type := ret : A -> FailureMonad A | fail : string -> FailureMonad A. Arguments ret {_} _. Arguments fail {_} _. Definition bind {A B : Type} (k:FailureMonad A) (f:A -> FailureMonad B) := match k return FailureMonad B with fail x => fail x | ret k => f k end. Notation "x <- c1 ;; c2" := (bind c1 (fun x => c2)) (at level 100, c2 at level 100, c1 at next level). (* "Converts" from our monad to the TemplateMonad of MetaCoq. This is used to pass error messages back to the user *) Definition f2t {T:Type} (a:FailureMonad T) : TemplateMonad T := match a with ret k => monad_utils.ret k | fail s => tmFail (s) end. (* Structurally recursive definition of a monadic map *) Fixpoint flatten_monad {A:Type} (l:list (FailureMonad A)) : FailureMonad (list A) := match l with nil => ret nil | x::xr => (xm <- x;; (xrm <- flatten_monad xr;; ret (xm::xrm))) end. Definition map_monad {A B:Type} (f:A -> FailureMonad B) (l:list A) : FailureMonad (list B) := flatten_monad (map f l). (* If the first monad fails, use the second. Used to cascade failure handling *) Definition orelse {A:Type} (F1 F2 :FailureMonad A) := match F1 with fail _ => F2 | _ => F1 end. Definition fail_fmap {A B : Type} (f : A -> B) (a : FailureMonad A) : FailureMonad B := aa <- a ;; ret (f aa). Definition fail_fmap' {A B : Type} (a : FailureMonad A) (f : A -> B) : FailureMonad B := fail_fmap f a. End FailureMonad. Arguments ret {_} _. Arguments fail {_} _. Arguments orelse {_} _ _. Notation "x <- c1 ;; c2" := (bind c1 (fun x => c2)) (at level 100, c2 at level 100, c1 at next level). Notation "x >>= f" := (bind x f) (at level 100). Arguments Vector.cons {_} _ {_} _, _ _ _ _. Section MetaCoqUtils. (* ** MetaCoqUtils Here, we define various useful functions for working with MetaCoq terms *) (*+ Working with quoted vectors *) Notation vectorCons x T n xr := (tApp (tConstruct {| inductive_mind := (MPfile (["VectorDef"; "Vectors"; "Coq"]), "t"); inductive_ind := 0 |} 1 nil) ([T; x; n; xr])). Notation vectorNil T := (tApp (tConstruct {| inductive_mind := (MPfile (["VectorDef"; "Vectors"; "Coq"]), "t"); inductive_ind := 0 |} 0 nil) ([T])). (* Unquotes a vector (into a list) *) Fixpoint recoverVector (f : Ast.term) {struct f}: FailureMonad (list Ast.term) := let ffail := fail "not a vector application" in match f with vectorNil _ => ret nil | vectorCons x _ _ xr => xrl <- recoverVector xr;;ret (x::xrl) | _ => ffail end. (* *** General utils for quoted terms *) (* Remove the n first elements from a list *) Existing Instance config.default_checker_flags. Fixpoint popNElements (l : list Ast.term) (n:nat) : option (list Ast.term) := match (l,n) with (a,0) => Some a | (x::xr, S n) => popNElements xr n | _ => None end. (* If ls is a valid prefix of l, return the corresponding "suffix" (the remaining elements of l). Otherwise, return None *) Fixpoint popListStart (l : list Ast.term) (ls : list Ast.term) : option (list Ast.term) := match (l,ls) with (a,nil)=> Some a | (lx::lxr, lsx::lsxr) => if eq_term init_graph lx lsx then popListStart lxr lsxr else None | _ => None end. MetaCoq Quote Definition qNatZero := 0. MetaCoq Quote Definition qNatSucc := S. MetaCoq Quote Definition qeq_refl := (@eq_refl). (* Given n, yield a MetaCoq Ast.term representation of n *) Fixpoint quoteNumber (n:nat) : Ast.term:= match n with 0 => qNatZero | S n => tApp qNatSucc ([quoteNumber n]) end. (* Increases the indices of all tRel in t by amnt, assuming they are already larger than minn. If minn = 0, this increases all "free" tRel reference indices *) Definition addRelIndex (minn:nat) (amnt:nat) (t:Ast.term) : Ast.term := Ast.lift amnt minn t. (* Helper functions, adapted from Ast.subst (for lowerRelIndex) and its helpers *) Definition map_predicate_fail {term term' : Type} (uf : Instance.t -> Instance.t) (paramf preturnf : term -> FailureMonad term') (p : predicate term) : FailureMonad (predicate term') := pparams' <- map_monad paramf (pparams p) ;; preturn' <- preturnf (preturn p) ;; ret {| puinst := uf (puinst p); pparams := pparams'; pcontext := pcontext p; preturn := preturn' |}. Definition map_branch_fail {term term' : Type} (bbodyf : term -> FailureMonad term') (b : branch term) := bbody' <- bbodyf (bbody b) ;; ret {| bcontext := bcontext b; bbody := bbody' |}. Definition map_def_fail {A B : Type} (tyf bodyf : A -> FailureMonad B) (d : def A) := ty' <- tyf (dtype d);; body' <- bodyf (dbody d);; ret {| dname := dname d; dtype := ty'; dbody := body' ; rarg := rarg d |}. (* monadic single-term substitution. *) Fixpoint subst (s : FailureMonad Ast.term) (k:nat) (u:Ast.term) := match u with | tRel n => if k <=? n then ss <- s;; ret (addRelIndex 0 k ss) else ret (tRel n) | tEvar ev args => fail_fmap (tEvar ev) (map_monad (subst s k) args) | tLambda na T M => (subst s k T) >>= (fun T => fail_fmap (tLambda na T) (subst s (S k) M)) | tApp u v => (subst s k u) >>= (fun u => fail_fmap (mkApps u) (map_monad (subst s k) v)) | tProd na A B => (subst s k A) >>= (fun u => fail_fmap (tProd na u) (subst s (S k) B)) | tCast c kind ty => (subst s k c) >>= (fun c => fail_fmap (tCast c kind) (subst s k ty)) | tLetIn na b ty b' => b <- (subst s k b);; ty <- (subst s k ty) ;; b' <- (subst s (S k) b') ;; ret (tLetIn na b ty b') | tCase ind p c brs => let k' := List.length (pcontext p) + k in p' <- map_predicate_fail id (subst s k) (subst s k') p ;; brs' <- map_monad (fun b => map_branch_fail (subst s (#|b.(bcontext)| + k)) b) brs ;; c' <- (subst s k c) ;; ret (tCase ind p' c' brs') | tProj p c => fail_fmap (tProj p) (subst s k c) | tFix mfix idx => let k' := List.length mfix + k in mfix' <- map_monad (map_def_fail (subst s k) (subst s k')) mfix ;; ret (tFix mfix' idx) | tCoFix mfix idx => let k' := List.length mfix + k in mfix' <- map_monad (map_def_fail (subst s k) (subst s k')) mfix ;; ret (tCoFix mfix' idx) | x => ret x end. Definition lowerRelIndex (minn:nat) (tv:FailureMonad Ast.term) (t:Ast.term) : FailureMonad Ast.term := subst tv minn t. End MetaCoqUtils. Section AbstractReflectionDefinitions. (* ** AbstractReflectionDefinitions Here, we define basic terms and types used when reifying *) (* Type of term reification helper, which is given to extension points / base connective reifier. The arguments are: - tct:Ast.term -- the current instance of the tarski_reflector, quoted - qff:Ast.term -- the instance of falsity_flag - t:Ast.term -- the actual term to be reified - envTerm:Ast.term -- the env we are reifying into, quoted - env: -- a helper, which gives the env index for Coq terms - returning a pair of the reified term and a proof that it is correct, both quoted *) Definition helperTermReifierType := (Ast.term -> Ast.term -> Ast.term -> Ast.term -> (Ast.term -> FailureMonad nat) -> FailureMonad (prod Ast.term Ast.term)). (* The same, but used during the env constructing phase. The only arg is the term itself *) Definition helperTermVarsType := (Ast.term -> FailureMonad (list Ast.term)). (* Similar, but this helper is used to reify terms, not forms. Args: - qff:Ast.term -- as above - frees:nat -- when reifying a nary predicate, this is n. - t:Ast.term -- the actual term/form to be reified - envTerm -- as above - env -- as above - returning again a apair of reified term and proof *) Definition helperFormReifierType := (Ast.term -> Ast.term -> nat -> Ast.term -> (Ast.term -> FailureMonad nat) -> FailureMonad (prod Ast.term Ast.term)). Definition helperFormVarsType := (Ast.term->nat->FailureMonad (list Ast.term)). (* A base connective is an inductive in Coq.Init.Logic, like and. They are common and have their own subsystem. Arguments: - tct, qff:Ast.term -- as above - lst:list Ast.term -- for e.g. (and X Y), this list contains [X;Y]. - fuel:nat -- fuel (when 0, we stop) - envTerm - env - a helper to recursively reify forms - a helper to recursively reify terms - return again a a pair of term and proof *) Definition baseConnectiveReifier := Ast.term -> Ast.term -> list Ast.term -> nat -> Ast.term -> (Ast.term -> FailureMonad nat) -> helperFormReifierType -> helperTermReifierType -> FailureMonad (prod Ast.term Ast.term). Definition baseConnectiveVars := list Ast.term -> nat -> Ast.term -> helperFormVarsType -> helperTermVarsType -> FailureMonad (list Ast.term). (* Extension point for term reification. Args are: - tct:Ast.term - qff:Ast.term -- the instance of falsity_flag - fuel:nat (also for var finder) - t:term (also for var finder) -- the actual term - envTerm - env - recursion helper (also for var finder) - returning the usual *) Definition termFinderVars := nat -> Ast.term -> helperTermVarsType -> FailureMonad (list Ast.term). Definition termFinderReifier := Ast.term -> Ast.term -> nat -> Ast.term -> Ast.term -> (Ast.term -> FailureMonad nat) -> helperTermReifierType -> FailureMonad (prod Ast.term Ast.term). (* Extension point for form reification. Args are: - tct:Ast.term - qff:Ast.term -- the instance of falsity_flag - fuel:nat (also for var finder) - t:term (also for var finder) -- the actual term - frees - envTerm - env - recursion helper for forms (also for var finder) - recursion helper for terms (also for var finder) - returning the usual *) Definition propFinderVars := Ast.term -> nat -> Ast.term -> nat -> helperFormVarsType -> helperTermVarsType -> (FailureMonad (list Ast.term)). Definition propFinderReifier := Ast.term -> Ast.term -> nat -> Ast.term -> nat -> Ast.term -> (Ast.term -> FailureMonad nat) -> helperFormReifierType -> helperTermReifierType -> FailureMonad (prod Ast.term Ast.term). (* When running in no proof mode, extension points still expect proofs. We give this dummy term. If the extension point only uses this to build further proofs, the whole term is discarded in the end *) Definition noProofDummy := tVar "NoProofGivenBecauseWeAreInNoProofMode". (* An instance of this class is required for the reifier to work. From it the basic reification building blocks are derived *) Class tarski_reflector := { fs : funcs_signature; ps : preds_signature; (* ps and fs give the syntax *) D : Type; I : @interp fs ps D; (* D and I give our model *) emptyEnv : nat -> D; (* We need an "empty" env that returns some default value for our types *) isD : Ast.term -> bool; (* Returns true iff the given term references D used above *) }. (* Extension point to extend the libary to more syntactic constructs *) Class tarski_reflector_extensions (t:tarski_reflector) := { (* for reifying instances of inductive types Coq.Init.Logic.* applied to arguments. Mostly used for reifying eq *) baseLogicConnHelper : option (string -> baseConnectiveReifier); baseLogicVarHelper : option (string -> baseConnectiveVars); (* for reifying all terms that we fail to reify *) termReifierVarHelper : option termFinderVars; termReifierReifyHelper : option termFinderReifier; (* for reifying all forms that we fail to reify *) formReifierVarHelper : option propFinderVars; formReifierReifyHelper : option propFinderReifier }. (* Used if no instance of the above extension class can be found. Low priority *) Definition defaultExtensions tr : tarski_reflector_extensions tr := Build_tarski_reflector_extensions tr None None None None None None. (* Useful builder to build the main tarski_reflector class *) Definition buildDefaultTarski {fs:funcs_signature} {ps:preds_signature} {D:Type} {I:@interp fs ps D} (point:D) (isD:Ast.term -> bool) := @Build_tarski_reflector fs ps D I (fun n:nat => point) isD. Fixpoint anyVariableOf (l:list ident) (t:Ast.term) := match l with nil => false | lx::lr => if @Checker.eq_term config.default_checker_flags init_graph t (tVar lx) then true else anyVariableOf lr t end. Context {tr : tarski_reflector}. Context {ff : falsity_flag}. (* These types are used to define representability. A n-ary formula is representable if there is a syntactic formula and an environment that you can plug the relevant values into that is equivalent *) Fixpoint naryProp (n:nat) : Type := match n with 0 => Prop | S nn => D -> naryProp nn end. Fixpoint representsP {n:nat} phi rho : (forall (P:naryProp n), Prop) := match n return (forall (P:naryProp n), Prop) with 0 => (fun (P:Prop) => P <-> @sat fs ps D I ff rho phi) | S n => (fun (P:D -> naryProp n) => forall d, @representsP n phi (d.:rho) (P d)) end. Definition representableP (n:nat) (P : naryProp n) := {phi&{rho | representsP phi rho P}}. Definition representsF (d:D) trm rho := @eval fs ps D I rho trm = d. Definition representableF (d:D) := exists trm rho, representsF d trm rho. (* Functions that allow us to construct syntactic connective applications without building vectors in MetaCoq *) Fixpoint naryGFunc (n:nat) (A R : Type) := match n with 0 => R | S n => A -> @naryGFunc n A R end. Fixpoint takeMultiple {n : nat} (X Y:Type) : (Vector.t X n -> Y) -> @naryGFunc n X Y := match n as nn return (Vector.t X nn -> Y) -> @naryGFunc nn X Y with 0 => fun R => R (Vector.nil X) | S n => fun R v => @takeMultiple n X Y (fun vr => R (Vector.cons X v n vr)) end. Definition constructTerm (k:@syms (@fs tr)) := @takeMultiple (ar_syms k) term term (func k). Definition constructForm (k:(@preds (@ps tr))) := @takeMultiple (@ar_preds (@ps tr) k) (@term (@fs tr)) form (atom k). Fixpoint nary3GFunc (n:nat) (A B A' B':Type) (C:A -> B -> Type) (C':A'->B'->Type) : (Vector.t A n -> A') -> (Vector.t B n -> B') -> Type := match n with 0 => fun mA mB => C' (mA (Vector.nil A)) (mB (Vector.nil B)) | S n => fun mA mB => forall (a:A) (b:B), C a b -> @nary3GFunc n A B A' B' C C' (fun v => mA (Vector.cons A a n v)) (fun v => mB (Vector.cons B b n v)) end. Definition mergeTermBase (c:@syms (@fs tr)) : Type := forall (rho:nat -> D), @nary3GFunc (ar_syms c) term D term D (fun t d => representsF d t rho) (fun t d => representsF d t rho) (func c) (@i_func fs ps D I c). (* Hack to get these to use the proper type class instance *) Notation term := (@Core.term (@fs tr)). Notation form := (@Core.form (@fs tr) (@ps tr) full_operators ff). Notation syms := (@Core.syms (@fs tr)). Notation preds := (@Core.preds (@ps tr)). Definition mergeTermProtoType (rho:nat -> D) (n:nat) (fZ:Vector.t term n -> term) (ifZ : Vector.t D n -> D) := (forall v : Vector.t term n, @eval fs ps D I rho (fZ v) = ifZ (Vector.map (@eval fs ps D I rho) v)) -> @nary3GFunc n term D term D (fun t d => representsF d t rho) (fun t d => representsF d t rho) fZ ifZ. Definition mergeTermProto (rho:nat -> D) (n:nat) (fZ:Vector.t term n -> term) (ifZ : Vector.t D n -> D) : @mergeTermProtoType rho n fZ ifZ. Proof. intros H. induction n as [|n IH]. * cbn. unfold representsF. rewrite H. cbn. easy. * cbn. intros t d r. apply IH. cbn. intros v. specialize (H (Vector.cons t v)). unfold representsF in r. rewrite H. cbn. now rewrite r. Defined. Definition mergeTerm (c:syms) : mergeTermBase c. Proof. intros rho. eapply mergeTermProto. now intros v. Defined. Definition mergeFormBase (c:preds) : Type := forall (rho:nat -> D), @nary3GFunc (ar_preds c) term D form (naryProp 0) (fun t d => representsF d t rho) (fun t P => representsP t rho P) (atom c) (@i_atom fs ps D I c). Definition mergeFormProtoType (rho:nat -> D) (n:nat) (fZ:Vector.t term n -> form) (ifZ : Vector.t D n -> naryProp 0) := (forall v : Vector.t term n, @sat fs ps D I ff rho (fZ v) = ifZ (Vector.map (@eval fs ps D I rho) v)) -> @nary3GFunc n term D form (naryProp 0) (fun t d => representsF d t rho) (fun t P => representsP t rho P) fZ ifZ. (* Proof that the functions built using the above helper actually represent the syntactic construct they are supposed to represent *) Definition mergeFormProto (rho:nat -> D) (n:nat) (fZ:Vector.t term n -> form) (ifZ : Vector.t D n -> naryProp 0) : @mergeFormProtoType rho n fZ ifZ. Proof. intros H. induction n as [|n IH]. * cbn. unfold representsP. rewrite H. cbn. easy. * cbn. intros t d r. apply IH. cbn. intros v. specialize (H (Vector.cons t v)). unfold representsF in r. rewrite H. cbn. now rewrite r. Defined. Definition mergeForm (c:preds) : mergeFormBase c. Proof. intros rho. eapply mergeFormProto. now intros v. Defined. (*+ Quotes of these functions which are later used to construct (proof) terms *) MetaCoq Quote Definition qConstructTerm := constructTerm. MetaCoq Quote Definition qMergeTerm := mergeTerm. MetaCoq Quote Definition qConstructForm := constructForm. MetaCoq Quote Definition qMergeForm := mergeForm. End AbstractReflectionDefinitions. #[global] Arguments representableP {_} {_} _ _. Section TarskiMerging. (* **TarskiMerging Here we have reifiers for basic logical connectives which are part of the core Tarski semantics and thus every model. These are and, or, falsity, implication and both quantifiers *) Context {tr : tarski_reflector}. Context {te : tarski_reflector_extensions tr}. (* Hack to get these to use the proper type class instance *) Notation term := (@Core.term (@fs tr)). Notation form ff := (@Core.form (@fs tr) (@ps tr) full_operators ff). Notation syms := (@Core.syms (@fs tr)). Notation preds := (@Core.preds (@ps tr)). (* For each connective, we have a "merger" that takes subproof that a term is represented by its reification, and proof that the larger term also represents its subterm. For falsity, there are not subterms, so we just prove that fal represents False, which is trivial *) Definition mFalse : form falsity_on := falsity. Definition mergeFalse (rho:nat -> D) : @representsP tr falsity_on 0 falsity rho False. Proof. easy. Defined. (* We then define a quoted version of the above proof which is later used to build subterms *) MetaCoq Quote Definition qMergeFalse := @mergeFalse. (* We finally define a quoted form merger which will then later be applied to the subforms. It should yield the reflected representation *) MetaCoq Quote Definition qMergeFormFalse := @mFalse. (* The same development for And. Note that this time we have subproofs. Our function arguments follow this pattern: - tr_quoted - quoted tarski_reflector (not visible in the arguments, but it's a context variable. Note that since the functions don't acually use te, it does not become part of the arguments outside the section - environment - coq subterms that are to be reified - reified subterms - proof that the reified subterms are actually the reifications *) Definition mAnd {ff : falsity_flag} (fP fQ:form ff) : form ff := fP∧fQ. Definition mergeAnd {ff : falsity_flag} (rho:nat -> D) (P Q : naryProp 0) (fP fQ : form ff) : representsP fP rho P -> representsP fQ rho Q -> @representsP tr ff 0 (mAnd fP fQ) rho (P /\ Q). Proof. intros [pPl pPr] [pQl pQr]. split. * intros [pP pQ]. split. now apply pPl. now apply pQl. * intros [pP pQ]. split. now apply pPr. now apply pQr. Defined. MetaCoq Quote Definition qMergeAnd := @mergeAnd. (* This is the form merger for and. It is unfolded syntactic sugar, once one adds the arguments x and y, this will read x ∧ y. *) MetaCoq Quote Definition qMergeFormAnd := @mAnd. (* The same development for or*) Definition mOr {ff : falsity_flag} (fP fQ:form ff) : form ff := fP∨fQ. Definition mergeOr {ff : falsity_flag} (rho:nat -> D) (P Q : naryProp 0) (fP fQ : form ff) : representsP fP rho P -> representsP fQ rho Q -> @representsP tr ff 0 (mOr fP fQ) rho (P \/ Q). Proof. intros [pPl pPr] [pQl pQr]. split. * intros [pP|pQ]. left; now apply pPl. right; now apply pQl. * intros [pP|pQ]. left; now apply pPr. right; now apply pQr. Defined. MetaCoq Quote Definition qMergeOr := @mergeOr. MetaCoq Quote Definition qMergeFormOr := @mOr. (* The same development for existential quantifiaction. Note that the P argument is a 1-ary predicate.*) Definition mExists {ff : falsity_flag} (fP:form ff) : form ff := ∃ fP. Definition mergeExists {ff : falsity_flag} (rho:nat -> D) (P:naryProp 1) (fP:form ff) : representsP fP rho P -> @representsP tr ff 0 (mExists fP) rho (exists q:D, P q). Proof. intros pR. split. * intros [q Pq]. exists q. destruct (pR q) as [pRl pRr]. now apply pRl. * intros [q Pq]. exists q. destruct (pR q) as [pRl pRr]. now apply pRr. Defined. MetaCoq Quote Definition qMergeExists := @mergeExists. MetaCoq Quote Definition qMergeFormExists := @mExists. (* The same development for implication. Note that implication is handled in the main reification logic since P -> Q is just syntactic sugar for (forall _:P, Q)*) Definition mImpl {ff : falsity_flag} (fP fQ : form ff) : form ff := fP → fQ. Definition mergeImpl {ff : falsity_flag} (rho:nat -> D) (P Q : naryProp 0) (fP fQ : form ff) : representsP fP rho P -> representsP fQ rho Q -> @representsP tr ff 0 (mImpl fP fQ) rho (P -> Q). Proof. intros HP HQ. destruct HP as [pPl pPr]. destruct HQ as [pQl pQr]. split. * intros PQ pP. apply pQl, PQ, pPr, pP. * cbn. intros pPQ pP. apply pQr, pPQ, pPl, pP. Defined. MetaCoq Quote Definition qMergeImpl := @mergeImpl. MetaCoq Quote Definition qMergeFormImpl := @mImpl. (* The same development for forall. Since forall-quantification in Coq is a part of the proper syntax (product types), this will again be handled by the main reification*) Definition mForall {ff : falsity_flag} (fP:form ff) : form ff := ∀ fP. Definition mergeForall {ff : falsity_flag} (rho:nat -> D) (Q:naryProp 1) (phi:form ff) : representsP phi rho Q -> @representsP tr ff 0 (mForall phi) rho (forall x:D, Q x). Proof. intros H. cbn. split; intros HH d; specialize (HH d); specialize (H d); cbn in H; apply H, HH. Defined. MetaCoq Quote Definition qMergeForall := @mergeForall. MetaCoq Quote Definition qMergeFormForall := @mForall. Definition mIff {ff : falsity_flag} (fP fQ : form ff) : form ff := fP ↔ fQ. Definition mergeIff {ff : falsity_flag} (rho:nat -> D) (P Q : naryProp 0) (fP fQ : form ff) : representsP fP rho P -> representsP fQ rho Q -> @representsP _ ff 0 (mIff fP fQ) rho (P <-> Q). Proof. intros H1 H2. cbn. cbn in H1,H2. rewrite H2, H1. reflexivity. Defined. MetaCoq Quote Definition qMergeFormIff := @mIff. MetaCoq Quote Definition qMergeIff := @mergeIff. (* The same development for not X. *) Definition mNot (fP : form falsity_on) : form falsity_on := fP→falsity. Definition mergeNot (rho:nat -> D) (P:naryProp 0) (fP : form falsity_on) : @representsP _ falsity_on 0 fP rho P -> @representsP _ falsity_on 0 (mNot fP) rho (~P). Proof. cbn. tauto. Defined. MetaCoq Quote Definition qMergeFormNot := @mNot. MetaCoq Quote Definition qMergeNot := @mergeNot. (* The same development for truth. Note that truth has no canonical representative in the tarski semantics. It is equivalent to (falsity -> falsity), but not computationally equal. So using True in noProof mode would fail.*) Definition mTrue : form falsity_on := falsity → falsity. Definition mergeTrue (rho:nat -> D) : @representsP _ falsity_on 0 (mTrue) rho (True). Proof. cbn. tauto. Defined. MetaCoq Quote Definition qMergeFormTrue := @mTrue. MetaCoq Quote Definition qMergeTrue := @mergeTrue. (* Notation for matching constructs like Coq.Init.Logic.and prop1 prop2 -> (x:="and", l:=[term1, term2]) *) Notation baseLogicConn x l:= (tInd {| inductive_mind := (MPfile (["Logic"; "Init"; "Coq"]), x); inductive_ind := 0 |} l). (* We now define reification helpers for each of the primitives (except implication&forall). These helpers recursively apply the main reification function to the subterms and assemble the resulting term/prood*) Definition reifyFalse : baseConnectiveReifier := fun tct qff lst _ envTerm env fPR _ => match lst with nil => ret (tApp qMergeFormFalse ([tct]), tApp qMergeFalse ([tct;envTerm])) | _ => fail "False applied to terms" end. Definition reifyAnd : baseConnectiveReifier := fun tct qff lst _ envTerm env fPR _ => match lst with [x; y] => xr <- fPR qff x 0 envTerm env;;yr <- fPR qff y 0 envTerm env;; let '((xt,xp),(yt,yp)) := (xr,yr) in ret (tApp qMergeFormAnd ([tct;qff;xt;yt]), tApp qMergeAnd ([tct;qff;envTerm;x;y;xt;yt;xp;yp])) | _ => fail "And applied to != 2 terms" end. Definition reifyOr : baseConnectiveReifier := fun tct qff lst _ envTerm env fPR _ => match lst with [x; y] => xr <- fPR qff x 0 envTerm env;;yr <- fPR qff y 0 envTerm env;; let '((xt,xp),(yt,yp)) := (xr,yr) in ret (tApp qMergeFormOr ([tct;qff;xt;yt]),tApp qMergeOr ([tct;qff;envTerm;x;y;xt;yt;xp;yp])) | _ => fail "Or applied to != 2 terms" end. Definition reifyExist:baseConnectiveReifier := fun tct qff lst _ envTerm env fPR _ => match lst with [_; P] => rr <- fPR qff P 1 envTerm env;; let '(rt,rp) := rr in ret (tApp qMergeFormExists ([tct;qff;rt]), tApp qMergeExists ([tct;qff;envTerm;P;rt;rp])) | _ => fail "Exist applied to wrong terms" end. Definition reifyIff : baseConnectiveReifier := fun tct qff lst _ envTerm env fPR _ => match lst with [x; y] => xr <- fPR qff x 0 envTerm env;;yr <- fPR qff y 0 envTerm env;; let '((xt,xp),(yt,yp)) := (xr,yr) in ret (tApp qMergeFormIff ([tct;qff;xt;yt]), tApp qMergeIff ([tct;qff;envTerm;x;y;xt;yt;xp;yp])) | _ => fail "Iff applied to != 2 terms" end. Definition reifyNot : baseConnectiveReifier := fun tct qff lst _ envTerm env fPR _ => match lst with [x] => xr <- fPR qff x 0 envTerm env;; let '(xt,xp) := xr in ret (tApp qMergeFormNot ([tct;xt]),tApp qMergeNot ([tct;envTerm;x;xt;xp])) | _ => fail "not applied to != 1 terms" end. Definition reifyTrue : baseConnectiveReifier := fun tct qff l fuel envTerm env fPR _ => match l with nil => ret (tApp qMergeFormTrue ([tct]), tApp qMergeTrue ([tct;envTerm]))| _ => fail "True applied to terms" end. (* The main handler. Given the name of the base type, call the respective helper. If nothing matches, call the extension point *) Definition reifyBase (s:string): baseConnectiveReifier := match s with "and" => reifyAnd | "or" => reifyOr | "ex" => reifyExist | "False" => reifyFalse | "True" => reifyTrue | _ => match baseLogicConnHelper with None =>fun _ _ _ _ _ _ _ _ => fail (String.append "Unknown connective " s) | Some k => k s end end. (* The same development for no-proof mode. Similar, except we don't build proofs *) Definition baseConnectiveReifierNP := Ast.term -> Ast.term -> list Ast.term -> nat -> Ast.term -> (Ast.term -> FailureMonad nat) -> (Ast.term -> Ast.term -> nat -> Ast.term -> (Ast.term -> FailureMonad nat) -> FailureMonad ( Ast.term)) -> (Ast.term -> Ast.term -> Ast.term -> Ast.term -> (Ast.term -> FailureMonad nat) -> FailureMonad (Ast.term)) -> FailureMonad (Ast.term). Definition reifyFalseNP : baseConnectiveReifierNP := fun tct qff lst _ envTerm env fPR _ => match lst with nil => ret (tApp qMergeFormFalse ([tct])) | _ => fail "False applied to terms" end. Definition reifyAndNP : baseConnectiveReifierNP := fun tct qff lst _ envTerm env fPR _ => match lst with [x; y] => xt <- fPR qff x 0 envTerm env;;yt <- fPR qff y 0 envTerm env;; ret (tApp qMergeFormAnd ([tct;qff;xt;yt])) | _ => fail "And applied to != 2 terms" end. Definition reifyOrNP : baseConnectiveReifierNP := fun tct qff lst _ envTerm env fPR _ => match lst with [x; y] => xt <- fPR qff x 0 envTerm env;;yt <- fPR qff y 0 envTerm env;; ret (tApp qMergeFormOr ([tct;qff;xt;yt])) | _ => fail "Or applied to != 2 terms" end. Definition reifyExistNP:baseConnectiveReifierNP := fun tct qff lst _ envTerm env fPR _ => match lst with [_; P] => rt <- fPR qff P 1 envTerm env;; ret (tApp qMergeFormExists ([tct;qff;rt])) | _ => fail "Exist applied to wrong terms" end. Definition reifyIffNP : baseConnectiveReifierNP := fun tct qff lst _ envTerm env fPR _ => match lst with [x; y] => xt <- fPR qff x 0 envTerm env;;yt <- fPR qff y 0 envTerm env;; ret (tApp qMergeFormIff ([tct;qff;xt;yt])) | _ => fail "Iff applied to != 2 terms" end. Definition reifyNotNP : baseConnectiveReifierNP := fun tct qff l fuel envTerm env fPR _ => match l with [x] => xt <- fPR qff x 0 envTerm env;; ret (tApp qMergeFormNot ([tct;xt]))| _ => fail "not applied to != 1 terms" end. Definition reifyTrueNP : baseConnectiveReifierNP := fun tct qff l fuel envTerm env fPR _ => match l with nil => ret (tApp qMergeFormTrue ([tct]))| _ => fail "True applied to terms" end. (* The helper is a bit more interesting, since it calls the extension point, building a recursive "dummy proof" helper and discarding the resulting proof *) Definition reifyBaseNP (s:string): baseConnectiveReifierNP := match s with "and" => reifyAndNP | "or" => reifyOrNP | "ex" => reifyExistNP | "False" => reifyFalseNP | "True" => reifyTrueNP | _ => match baseLogicConnHelper with None =>fun _ _ _ _ _ _ _ _ => fail (String.append "Unknown connective " s) | Some k => fun tct qff lst fuel envTerm env fPR fTR => both <- k s tct qff lst fuel envTerm env (fun qff P n et e => rr <- fPR qff P n et e;; ret (rr, noProofDummy)) (fun tct qff t eT env => rr <- fTR tct qff t eT env;; ret (rr, noProofDummy));; let '(trm,_) := both in ret trm end end. End TarskiMerging. Section ReificationHelpers. (* **ReificationHelpers These functions reify atomic functions/relations *) (* Definition of the types. The arguments are: - tct:Ast.term - quoted instance of tarski_reflector - qff:Ast.term -- the instance of falsity_flag - av:list Ast.term - the arguments of an atomic relation/function to be recursively reified - envTerm - recursive helper, to which av is passed one-by-one - the return is again either a pair of term&proof, or just the term if in no proof mode *) Definition termReifier := Ast.term -> Ast.term -> list Ast.term -> Ast.term -> (Ast.term -> FailureMonad (prod Ast.term Ast.term)) -> FailureMonad (prod Ast.term Ast.term). Definition termReifierNP := Ast.term -> Ast.term -> list Ast.term -> Ast.term -> (Ast.term -> FailureMonad (Ast.term)) -> FailureMonad (Ast.term). (* Args: typeClassTerm -> vector of args -> env term -> recursion for arg vector -> prod (term, proof that term represents input *) Fixpoint applyRecursively (lt : list Ast.term) (IH : Ast.term -> FailureMonad (prod Ast.term Ast.term)) : FailureMonad (prod (list Ast.term) (list Ast.term)) := match lt with nil => ret (nil,nil) | t::tr => IHt <- IH t;; atrIH <- applyRecursively tr IH;;let '(rep,prf) := IHt in let '(replist,fulllist) := atrIH in ret (rep::replist, rep::t::prf::fulllist) end. Fixpoint applyRecursivelyNP (lt : list Ast.term) (IH : Ast.term -> FailureMonad (Ast.term)) : FailureMonad ((list Ast.term) ) := match lt with nil => ret (nil) | t::tr => rep <- IH t;; replist <- applyRecursivelyNP tr IH;;ret (rep::replist) end. Definition reifyTerm (c:Ast.term) : termReifier := fun tct qff av env IH => pr <- applyRecursively av IH;; let '(trm,fullarg) := pr in ret (tApp qConstructTerm (tct::c::trm), tApp qMergeTerm (tct::c::env::fullarg)). Definition reifyForm (c:Ast.term) : termReifier := fun tct qff av env IH => pr <- applyRecursively av IH;; let '(trm,fullarg) := pr in ret (tApp qConstructForm (tct::qff::c::trm), tApp qMergeForm (tct::qff::c::env::fullarg)). Definition reifyTermNP (c:Ast.term) : termReifierNP := fun tct qff av env IH => trm <- applyRecursivelyNP av IH;; ret (tApp qConstructTerm (tct::c::trm)). Definition reifyFormNP (c:Ast.term) : termReifierNP := fun tct qff av env IH => trm <- applyRecursivelyNP av IH;; ret (tApp qConstructForm (tct::qff::c::trm)). End ReificationHelpers. Section EnvHelpers. (* ** EnvHelpers Useful functions for extending the environment. A 3-ary predicate P(k1,k2,k3) (for example) is represented by a term t where t in environ (k3:k2:k1:env) represents P (k1,k2,k3).*) (* Appends something to the start of the env. *) Definition appendZero (env:Ast.term -> FailureMonad nat) (zv:FailureMonad nat) : (Ast.term -> FailureMonad nat) := fun (t:Ast.term) => match t with tRel n => (match n with 0 => zv | S n => env (tRel n) end) | _ => k <- lowerRelIndex 0 (fail "tRel 0 used when lowering") t;; (env k) end. (* Appends something to the start of the env. At the same time, it expects the terms given to the env helper to be one level deeper, so it "unshifts" the tRels first *) Definition appendAndLift (env:Ast.term -> FailureMonad nat) (zv:FailureMonad nat) : (Ast.term -> FailureMonad nat) := fun t => match t with tRel n => (match n with 0 => zv | S n => k <- env (tRel n);;ret (S k) end) | _ => k <- lowerRelIndex 0 (fail "tRel 0 used when lowering") t;; v <- env k;;ret (S v) end. MetaCoq Quote Definition qD := @D. MetaCoq Quote Definition qScons := @scons. (* Appends d to the env *) Definition raiseEnvTerm (tct:Ast.term) (d:Ast.term) (env:Ast.term) : Ast.term := tApp (qScons) ([tApp qD ([tct]);d;env]). (* The env helper for the empty environ, which always fails *) Definition unboundEnv := (fun a:Ast.term => @fail nat (String.append "unbound " (string_of_term a))). End EnvHelpers. Section EnvConstructor. (* ** EnvConstructor Constructs the environment used to help with free variables in terms *) (* Useful quotations *) Existing Instance config.default_checker_flags. MetaCoq Quote Definition qFs := @fs. MetaCoq Quote Definition qLocalVar := @var. MetaCoq Quote Definition qI_f := @i_func. MetaCoq Quote Definition qI_P := @i_atom. Context {tr : tarski_reflector}. Context {te : tarski_reflector_extensions tr}. (* Given a term in the semantic, construct an environment that contains all atoms that appear in the term (and are not otherwise representable) *) Fixpoint findUBRecursively (lt : list Ast.term) (IH : Ast.term -> FailureMonad (list Ast.term)) : FailureMonad ((list Ast.term) ) := match lt with nil => ret (nil) | t::tr => rep <- IH t;; replist <- findUBRecursively tr IH;;ret (rep++replist) end. (* Finds all free variables in a term *) Fixpoint findUnboundVariablesTerm (fuel:nat) (t:Ast.term) {struct fuel}: (FailureMonad (list Ast.term)) := match fuel with 0 => fail "Out of fuel" | S fuel => let ffail := orelse (match @termReifierVarHelper _ te with None => fail "Fallthrough" | Some k => k fuel t (findUnboundVariablesTerm fuel) end) (match t with tRel _ => ret nil | _ => ret ([t]) end) in (* tRel are things introduced by forall/exists and so on, which we do not add to the environment *) match t with tApp arg l => if Checker.eq_term init_graph arg qI_f then match popNElements l 4 with (*4 for funcs, preds, domain, interp *) Some ([fnc;v]) => vr <- recoverVector v;;findUBRecursively vr (findUnboundVariablesTerm fuel) | _ => ffail end else ffail | _ => ffail end end. (*Our notation from above*) Notation baseLogicConn x l:= (tInd {| inductive_mind := (MPfile (["Logic"; "Init"; "Coq"]), x); inductive_ind := 0 |} l). (* Find the unbound variables for our basic forms *) Definition findUBFalse :baseConnectiveVars := fun lst _ _ fPR _ => match lst with nil => ret (nil) | _ => fail "False applied to terms" end. Definition findUBAnd :baseConnectiveVars := fun lst _ _ fPR _ => match lst with [x; y] => xt <- fPR x 0;;yt <- fPR y 0;; ret (xt++yt) | _ => fail "And applied to != 2 terms" end. Definition findUBOr :baseConnectiveVars := fun lst _ _ fPR _ => match lst with [x; y] => xt <- fPR x 0;;yt <- fPR y 0;; ret (xt++yt) | _ => fail "Or applied to != 2 terms" end. Definition findUBExists:baseConnectiveVars := fun lst _ _ fPR _ => match lst with [_; P] => fPR P 1 | _ => fail "Exist applied to wrong terms" end. Definition findUBNot :baseConnectiveVars := fun lst _ _ fPR _ => match lst with [k] => fPR k 0 | _ => fail "not applied to wrong terms" end. Definition findUBTrue : baseConnectiveVars := fun lst fuel tct _ _ => match lst with nil => ret nil | _ => fail "True applied to terms" end. Definition findUBIff :baseConnectiveVars := fun lst _ _ fPR _ => match lst with [x; y] => xt <- fPR x 0;;yt <- fPR y 0;; ret (xt++yt) | _ => fail "Iff applied to != 2 terms" end. Definition findUBBase (s:string) : baseConnectiveVars := match s with "and" => findUBAnd | "or" => findUBOr | "ex" => findUBExists | "False" => findUBFalse | "True" => findUBTrue | _ => match @baseLogicVarHelper tr te with None => fun _ _ _ _ _ => fail (String.append "Unknown connective " s) | Some k => k s end end. MetaCoq Quote Definition qIff := @iff. MetaCoq Quote Definition qNot := @not. (* Checks whether a term is the type of theory terms in Coq. *) Definition maybeD : Ast.term -> Ast.term -> bool := fun tct mD => if @isD tr mD then true else Checker.eq_term init_graph mD (tApp qD ([tct])). (* Finds the unbound variables in a form *) Fixpoint findUnboundVariablesForm (tct:Ast.term) (fuel:nat) (t:Ast.term) (frees:nat) {struct fuel}: (FailureMonad (list Ast.term)) := let ffail := fail (String.append"Cannot introspect form " (string_of_term t)) in match fuel with 0 => fail "Out of fuel" | S fuel => match (frees,t) with (0,(baseLogicConn name nil)) => findUBBase name nil fuel tct (findUnboundVariablesForm tct fuel) (findUnboundVariablesTerm fuel) | (0,(tApp (baseLogicConn name nil) lst)) => findUBBase name lst fuel tct (findUnboundVariablesForm tct fuel) (findUnboundVariablesTerm fuel) | (0,(tApp arg lst)) => if Checker.eq_term init_graph arg qI_P then match popNElements lst 4 with Some ([fnc;v]) => vr <- recoverVector v;;findUBRecursively vr (fun t => findUnboundVariablesTerm fuel t) | _ => ffail end else if Checker.eq_term init_graph arg qIff then findUBIff lst fuel tct (findUnboundVariablesForm tct fuel) (findUnboundVariablesTerm fuel) else if Checker.eq_term init_graph arg qNot then findUBNot lst fuel tct (findUnboundVariablesForm tct fuel) (findUnboundVariablesTerm fuel) else ffail | (0,tProd x P Q) => if maybeD tct (P) then findUnboundVariablesForm tct fuel (tLambda x P Q) 1 else (*implication*) rP <- findUnboundVariablesForm tct fuel P 0;; Ql <- lowerRelIndex 0 (fail "Used var of implication precondition") Q;; rQ <- findUnboundVariablesForm tct fuel Ql 0;; ret (rP++rQ) | (S n,tLambda x T P) => if maybeD tct T then findUnboundVariablesForm tct fuel P n else ffail | _ => ffail end end. Fixpoint isIn (l:list Ast.term) (x:Ast.term) := match l with nil=>false | lx::lr => if Checker.eq_term init_graph lx x then true else isIn lr x end. Fixpoint dedup (l:list Ast.term) := match l with nil => nil | lx::lr => if isIn lr lx then dedup lr else lx::dedup lr end. (* Builds the actual env out of a list of free variables *) Fixpoint createEnvTerms (tct:Ast.term) (l:list Ast.term) (base:Ast.term) : prod (Ast.term) (Ast.term -> FailureMonad nat) := match l with nil => (base,unboundEnv) | x::xr => let '(envTerm,env) := createEnvTerms tct xr base in (raiseEnvTerm tct x envTerm, fun a:Ast.term => if Checker.eq_term init_graph x a then ret 0 else v <- env a;;ret (S v)) end. End EnvConstructor. Section MainReificationFunctions. (* ** MainReificationFunctions Constructs the actual reifications, putting everything together *) Context {tr : tarski_reflector}. Context {te : tarski_reflector_extensions tr}. Existing Instance config.default_checker_flags. (* *** Terms Constructs the representation for terms.*) (* Arguments: - tct -- the quoted instance of tarski_reflector - fuel -- fuel - qff -- the quoted instance of falsity_flag - t -- the term to reify - termEnv -- the env term - env -- the env helper - returns the pair of reification/proof *) Fixpoint findTermRepresentation (tct:Ast.term) (fuel:nat) (qff:Ast.term) (t:Ast.term) (termEnv:Ast.term) (env:Ast.term -> FailureMonad nat) {struct fuel}: (FailureMonad (prod Ast.term Ast.term)) := match fuel with 0 => fail "Out of fuel" | S fuel => let fallback := orelse (match @termReifierReifyHelper _ te with None => fail "none" | Some k => k tct qff fuel t termEnv env (fun l => findTermRepresentation l fuel) end) (envv <- env (t);;let num := quoteNumber (envv) in ret (tApp qLocalVar ([tApp qFs ([tct]);num]),tApp qeq_refl ([tApp qD ([tct]);t]))) in match t with tApp arg l => if Checker.eq_term init_graph arg qI_f then match popNElements l 4 with (*4 for funcs, preds, domain, interp *) Some ([fnc;v]) => vr <- recoverVector v;;reifyTerm fnc tct qff vr termEnv (fun t => findTermRepresentation tct fuel qff t termEnv env) | _ => fallback end else fallback | _ => fallback end end. (* Like the above, but without the proof *) Fixpoint findTermRepresentationNP (tct:Ast.term) (fuel:nat) (qff:Ast.term) (t:Ast.term) (termEnv:Ast.term) (env:Ast.term -> FailureMonad nat) {struct fuel}: (FailureMonad (Ast.term)) := match fuel with 0 => fail "Out of fuel" | S fuel => let fallback := orelse (match @termReifierReifyHelper _ te with None => fail "none" | Some k => pr <- k tct qff fuel t termEnv env (fun tct' qff' t' te' e' => v <- findTermRepresentationNP tct' fuel qff' t' te' e';;ret (v,noProofDummy));; let '(pr1,pr2) := pr in ret pr1 end) (envv <- env (t);;let num := quoteNumber (envv) in ret (tApp qLocalVar ([tApp qFs ([tct]);num]))) in match t with tApp arg l => if Checker.eq_term init_graph arg qI_f then match popNElements l 4 with (*4 for funcs, preds, domain, interp *) Some ([fnc;v]) => vr <- recoverVector v;;reifyTermNP fnc tct qff vr termEnv (fun t => findTermRepresentationNP tct fuel qff t termEnv env) | _ => fallback end else fallback | _ => fallback end end. Notation baseLogicConn x l:= (tInd {| inductive_mind := (MPfile (["Logic"; "Init"; "Coq"]), x); inductive_ind := 0 |} l). (* *** Forms *) (* Like the above, but here we do it for forms. Arguments: - tct -- like above - fuel -- like above - qff -- like above - t -- the term - frees: the arity of the form we are reifying. If nonzero, the form must be a lambda term - envTerm -- the env, quoted - env -- the env helper *) Fixpoint findPropRepresentation (tct:Ast.term) (fuel:nat) (qff:Ast.term) (t:Ast.term) (frees:nat) (envTerm:Ast.term) (env:Ast.term -> FailureMonad nat) {struct fuel}: (FailureMonad (prod Ast.term Ast.term)) := match fuel with 0 => fail "Out of fuel" | S fuel => let ffail := orelse (match @formReifierReifyHelper _ te with None => fail "none" | Some k => k tct qff fuel t frees envTerm env (findPropRepresentation tct fuel) (fun l => findTermRepresentation l fuel) end) (fail (String.append "Cannot represent form " (string_of_term t))) in match (frees,t) with (0,(baseLogicConn name nil)) => reifyBase name tct qff nil fuel envTerm env (findPropRepresentation tct fuel) (fun tct => findTermRepresentation tct fuel) | (0,(tApp (baseLogicConn name nil) lst)) => reifyBase name tct qff lst fuel envTerm env (findPropRepresentation tct fuel) (fun tct => findTermRepresentation tct fuel) | (0,(tApp arg lst)) => if Checker.eq_term init_graph arg qI_P then match popNElements lst 4 with Some ([fnc;v]) => vr <- recoverVector v;;reifyForm fnc tct qff vr envTerm (fun t => findTermRepresentation tct fuel qff t envTerm env) | _ => ffail end else if Checker.eq_term init_graph arg qIff then reifyIff tct qff lst fuel envTerm env (findPropRepresentation tct fuel) (fun tct => findTermRepresentation tct fuel) else if Checker.eq_term init_graph arg qNot then reifyNot tct qff lst fuel envTerm env (findPropRepresentation tct fuel) (fun tct => findTermRepresentation tct fuel) else ffail | (0,tProd x P Q) => if maybeD tct (P) then rQ <- findPropRepresentation tct fuel qff (tLambda x P Q) 1 envTerm env;; let '(tQ,pQ) := rQ in ret (tApp qMergeFormForall ([tct;qff;tQ]), tApp qMergeForall ([tct;qff;envTerm;tLambda x P Q;tQ;pQ])) else rP <- findPropRepresentation tct fuel qff P 0 envTerm env;; Ql <- lowerRelIndex 0 (fail "Used var of implication precondition") Q;; rQ <- findPropRepresentation tct fuel qff Ql 0 envTerm env;; let '((tP,pP),(tQ,pQ)) := (rP,rQ) in ret (tApp qMergeFormImpl ([tct;qff;tP;tQ]), tApp qMergeImpl ([tct;qff;envTerm;P;Ql;tP;tQ;pP;pQ])) | (S n,tLambda x T P) => if maybeD tct T then let envTermSub := raiseEnvTerm tct (tRel 0) (addRelIndex 0 1 envTerm) in let envSub := appendAndLift env (ret 0) in k <- findPropRepresentation tct fuel qff P n envTermSub envSub;; let '(tk,pk) := k in ret (tk,(tLambda x (tApp qD ([tct])) pk)) else ffail | _ => ffail end end. (* like the above but again the no-proof version *) Fixpoint findPropRepresentationNP (tct:Ast.term) (fuel:nat) (qff:Ast.term) (t:Ast.term) (frees:nat) (envTerm:Ast.term) (env:Ast.term -> FailureMonad nat) {struct fuel}: (FailureMonad (Ast.term)) := match fuel with 0 => fail "Out of fuel" | S fuel => let ffail := orelse (match @formReifierReifyHelper _ te with None => fail "none" | Some k => rr <- k tct qff fuel t frees envTerm env (fun qff' t f et e => v <- findPropRepresentationNP tct fuel qff' t f et e;; ret (v,noProofDummy)) (fun l qff' t et e => v <- findTermRepresentationNP l fuel qff' t et e;;ret (v,noProofDummy));;let '(trm,_) := rr in ret trm end) (fail (String.append "Cannot represent form " (string_of_term t))) in match (frees,t) with (0,(baseLogicConn name nil)) => reifyBaseNP name tct qff nil fuel envTerm env (findPropRepresentationNP tct fuel) (fun tct => findTermRepresentationNP tct fuel) | (0,(tApp (baseLogicConn name nil) lst)) => reifyBaseNP name tct qff lst fuel envTerm env (findPropRepresentationNP tct fuel) (fun tct => findTermRepresentationNP tct fuel) | (0,(tApp arg lst)) => if Checker.eq_term init_graph arg qI_P then match popNElements lst 4 with Some ([fnc;v]) => vr <- recoverVector v;;reifyFormNP fnc tct qff vr envTerm (fun t => findTermRepresentationNP tct fuel qff t envTerm env) | _ => ffail end else if Checker.eq_term init_graph arg qIff then reifyIffNP tct qff lst fuel envTerm env (findPropRepresentationNP tct fuel) (fun tct => findTermRepresentationNP tct fuel) else if Checker.eq_term init_graph arg qNot then reifyNotNP tct qff lst fuel envTerm env (findPropRepresentationNP tct fuel) (fun tct => findTermRepresentationNP tct fuel) else ffail | (0,tProd x P Q) => if maybeD tct (P) then tQ <- findPropRepresentationNP tct fuel qff (tLambda x P Q) 1 envTerm env;; ret (tApp qMergeFormForall ([tct;qff;tQ])) else tP <- findPropRepresentationNP tct fuel qff P 0 envTerm env;; Ql <- lowerRelIndex 0 (fail "Used var of implication precondition") Q;; tQ <- findPropRepresentationNP tct fuel qff Ql 0 envTerm env;; ret (tApp qMergeFormImpl ([tct;qff;tP;tQ])) | (S n,tLambda x T P) => if maybeD tct T then let envTermSub := raiseEnvTerm tct (tRel 0) (addRelIndex 0 1 envTerm) in let envSub := appendAndLift env (ret 0) in tk <- findPropRepresentationNP tct fuel qff P n envTermSub envSub;; ret (tk) else ffail | _ => ffail end end. End MainReificationFunctions. (* Default fuel. This is enough for all terms with depth 100 *) Definition FUEL := 100. (* ** Tactics All tactics expect the goal to be representable n P *) (* Tactic that calls findPropRepresentation. Given an env (unquoted) and a respective env helper *) Ltac representEnvP env env2:= match goal with [ |- @representableP ?i ?ff ?n ?G ] => let rep := fresh "rep" in let prf := fresh "prf" in let k y := (destruct y as [rep prf]) in (*pose ((match env1 with None => @emptyEnv i | Some kk => kk end)) as env;*) (run_template_program (monad_utils.bind (tmQuote i) (fun tct => monad_utils.bind (tmQuote G) (fun g => monad_utils.bind (tmQuote ff) (fun qff => monad_utils.bind (tmInferInstance None (tarski_reflector_extensions i)) (fun treO => let tre := match treO with my_Some kk => kk | my_None => defaultExtensions i end in monad_utils.bind (tmQuote env) (fun qe => monad_utils.bind (f2t (@findPropRepresentation i tre tct FUEL qff g n qe env2)) (fun '(tPq,pPq) => monad_utils.bind (tmUnquoteTyped (@form (@fs i) (@ps i) full_operators ff) tPq) (fun tP:(@form (@fs i) (@ps i) full_operators ff) => monad_utils.bind (tmUnquoteTyped (@representsP i ff n tP env G) pPq) (fun tQ : @representsP i ff n tP env G => monad_utils.ret (@existT (@form (@fs i) (@ps i) full_operators ff) (fun mm => @representsP i ff n mm env G) tP tQ)))))))))) k) ;exists rep;exists env;exact prf end. (* Like the above, but no-proof mode. We hope easy can proof it, if not the user must close (or alternatively try representEnvP )*) Ltac representEnvPNP env env2:= match goal with [ |- @representableP ?i ?ff ?n ?G ] => let rep := fresh "rep" in let prf := fresh "prf" in let k y := (pose y as rep) in (*pose ((match env1 with None => @emptyEnv i | Some kk => kk end)) as env;*) (run_template_program (monad_utils.bind (tmQuote i) (fun tct => monad_utils.bind (tmQuote G) (fun g => monad_utils.bind (tmQuote ff) (fun qff => monad_utils.bind (tmInferInstance None (tarski_reflector_extensions i)) (fun treO => let tre := match treO with my_Some kk => kk | my_None => defaultExtensions i end in monad_utils.bind (tmQuote env) (fun qe => monad_utils.bind (f2t ((@findPropRepresentationNP i tre tct FUEL qff g n qe env2))) (fun tPq => monad_utils.bind (tmUnquoteTyped (@form (@fs i) (@ps i) full_operators ff) tPq) (fun tP:(@form (@fs i) (@ps i) full_operators ff) => monad_utils.ret (tP))))))))) k) ;exists rep;exists env;try easy end. (* Construct the environment, then invoke another ltac with the build environment and the respective env helper (continuation-passing style) *) Definition HiddenTerm {X:Type} {x:X} := x. Ltac constructEnvCont cont := match goal with [ |- @representableP ?i ?ff ?n ?G ] => (*(pose (fst y) as envBase;pose (snd y) as envTerm*) (*let envBase := fresh "envBase" in let envTerm := fresh "envTerm" in *) (run_template_program (monad_utils.bind (tmQuote i) (fun tct => monad_utils.bind (tmQuote G) (fun g => monad_utils.bind (tmQuote ff) (fun qff => monad_utils.bind (tmInferInstance None (tarski_reflector_extensions i)) (fun treO => let tre := match treO with my_Some kk => kk | my_None => defaultExtensions i end in monad_utils.bind (tmQuote (@emptyEnv i)) (fun baseEnv => monad_utils.bind (f2t ((@findUnboundVariablesForm i tre tct FUEL g n))) (fun lst => let '(envToDR,envToNat) := (createEnvTerms tct (dedup lst) baseEnv) in monad_utils.bind (tmUnquoteTyped (nat -> @D i) envToDR) (fun envToD => monad_utils.ret (pair envToD envToNat))))))))) cont) end. (* Construct the env, then bind it to envBase and envTerm. Useful if one does not actually want to show representability with the automation but just build the environment*) Ltac constructEnv' envBase envTerm := match goal with [ |- @representableP ?i ?ff ?n ?G ] => let k y := (pose (@HiddenTerm (nat -> @D i) (fst y)) as envBase;pose (@HiddenTerm (Ast.term -> FailureMonad nat) (snd y)) as envTerm) in constructEnvCont k end. Ltac constructEnv := let envBase := fresh "envBase" in let envTerm := fresh "envTerm" in constructEnv' envBase envTerm. (* The main tactic. Builds an environment, finds a reification and a proof of correctness. Calls the above tactics *) Ltac represent := match goal with [ |- @representableP ?i ?ff ?n ?G ] => let tac k := (let envBase := fresh "envBase" in (pose (@HiddenTerm (nat -> @D i) (fst k)) as envBase); representEnvP envBase (snd k)) in constructEnvCont tac end. (* The same, but without the proof *) Ltac representNP := match goal with [ |- @representableP ?i ?ff ?n ?G ] => let tac k := (let envBase := fresh "envBase" in (pose (@HiddenTerm (nat -> @D i) (fst k)) as envBase); representEnvPNP envBase (snd k)) in constructEnvCont tac end. (*Ltac representNP := let envBase := fresh "envBase" in let envTerm := fresh "envTerm" in constructEnv' envBase envTerm; representEnvPNP envBase envTerm.*) Ltac representEnvPPP env env2:= match goal with [ |- @representableP ?i ?ff ?n ?G ] => let rep := fresh "rep" in let prf := fresh "prf" in let k y := (destruct y as [rep prf]) in (*pose ((match env1 with None => @emptyEnv i | Some kk => kk end)) as env;*) (run_template_program (monad_utils.bind (tmQuote i) (fun tct => monad_utils.bind (tmQuote G) (fun g => monad_utils.bind (tmQuote ff) (fun qff => monad_utils.bind (tmInferInstance None (tarski_reflector_extensions i)) (fun treO => let tre := match treO with my_Some kk => kk | my_None => defaultExtensions i end in monad_utils.bind (tmQuote env) (fun qe => monad_utils.bind (f2t (@findPropRepresentation i tre tct FUEL qff g n qe env2)) (fun '(tPq,pPq) => monad_utils.ret (tPq,pPq)))))))) k) ;exists rep;exists env;exact prf end.
function au_qmr_ilu_s_d(p) % % Deletes the global data that has been generated by 'au_qmr_ilu_s_i' % or 'au_qmr_ilu_s'. % % Calling sequence: % % au_qmr_ilu_s_d % % Input: % % p vector containing the ADI shift parameters. % % % LYAPACK 1.0 (Thilo Penzl, August 1999) l = length(p); % Delete them regardless if they have been % created at all. for i = 1:l eval(lp_e( 'global LP_L',i,' LP_U',i )); eval(lp_e( 'clear global LP_L',i,' LP_U',i )); end global LP_P clear global LP_P
lemma collinear_2 [iff]: "collinear {x, y}"
import data.real.irrational import topology.basic import algebra.order.floor --OUTPUT 1 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=density_of_irrational_orbit (α : ℝ) (hα : ¬ is_rat α) : ∀ y ∈ Icc 0 1, ∃ x ∈ Icc 0 1, ∃ N : ℤ, |y - (N : ℝ) * x| < 1 := begin assume (y : ℝ) (h1 : y ∈ Icc 0 1), -- Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then -- $i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor$, -- which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. Hence, -- $S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}$ -- is an infinite subset of $\left[0,1\right]$. have h2 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h3 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h4 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h5 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h6 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h7 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h8 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h9 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h10 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h11 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h12 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h13 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h14 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h15 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h16 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h17 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h18 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h19 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h20 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h21 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h22 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h23 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h24 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h25 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h26 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor (j : ℝ) * α, from sorry, have h27 : ∀ i j : ℤ, i ≠ j → (i : ℝ) * α - floor (i : ℝ) * α ≠ (j : ℝ) * α - floor end --Needs more than 2000 tokens! /- FEW SHOT PROMPTS TO CODEX(START) /--`theorem` Power Set is Closed under Intersection Let $S$ be a set. Let $\powerset S$ be the power set of $S$. Then: :$\forall A, B \in \powerset S: A \cap B \in \powerset S$ `proof` Let $A, B \in \powerset S$. Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$. From Intersection is Subset we have that $A \cap B \subseteq A$. It follows from Subset Relation is Transitive that $A \cap B \subseteq S$. Thus $A \cap B \in \powerset S$ and closure is proved. {{qed}} -/ theorem power_set_intersection_closed {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S := begin -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$ assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S), -- Then $A ⊆ S$ and $B ⊆ S$, by power set definition have h1 : (A ⊆ S) ∧ (B ⊆ S), from sorry, -- Then $(A ∩ B) ⊆ A$, by intersection of set is a subset have h2 : (A ∩ B) ⊆ A, from sorry, -- Then $(A ∩ B) ⊆ S$, by subset relation is transitive have h3 : (A ∩ B) ⊆ S, from sorry, -- Hence $(A ∩ B) ∈ 𝒫 S$, by power set definition show (A ∩ B) ∈ 𝒫 S, from sorry, end /--`theorem` Square of Sum :$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$ `proof` Follows from the distribution of multiplication over addition: {{begin-eqn}} {{eqn | l = \left({x + y}\right)^2 | r = \left({x + y}\right) \cdot \left({x + y}\right) }} {{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right) | c = Real Multiplication Distributes over Addition }} {{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y | c = Real Multiplication Distributes over Addition }} {{eqn | r = x^2 + 2xy + y^2 | c = }} {{end-eqn}} {{qed}} -/ theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) := begin -- expand the power calc (x + y)^2 = (x+y)*(x+y) : by sorry -- distributive property of multiplication over addition gives: ... = x*(x+y) + y*(x+y) : by sorry -- applying the above property further gives: ... = x*x + x*y + y*x + y*y : by sorry -- rearranging the terms using commutativity and adding gives: ... = x^2 + 2*x*y + y^2 : by sorry, end /--`theorem` Identity of Group is Unique Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$. `proof` From Group has Latin Square Property, there exists a unique $x \in G$ such that: :$a x = b$ and there exists a unique $y \in G$ such that: :$y a = b$ Setting $b = a$, this becomes: There exists a unique $x \in G$ such that: :$a x = a$ and there exists a unique $y \in G$ such that: :$y a = a$ These $x$ and $y$ are both $e$, by definition of identity element. {{qed}} -/ theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a := begin -- Group has Latin Square Property have h1 : ∀ a b : G, ∃! x : G, a * x = b, from sorry, have h2 : ∀ a b : G, ∃! y : G, y * a = b, from sorry, -- Setting $b = a$, this becomes: have h3 : ∀ a : G, ∃! x : G, a * x = a, from sorry, have h4 : ∀ a : G, ∃! y : G, y * a = a, from sorry, -- These $x$ and $y$ are both $(1 : G)$, by definition of identity element have h5 : ∀ a : G, classical.some (h3 a) = (1 : G), from sorry, have h6 : ∀ a : G, classical.some (h4 a) = (1 : G), from sorry, show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by { use (1 : G), have h7 : ∀ e : G, (∀ a : G, e * a = a ∧ a * e = a) → e = 1, from by { assume (e : G) (h7 : ∀ a : G, e * a = a ∧ a * e = a), have h8 : ∀ a : G, e = classical.some (h3 a), from sorry, have h9 : ∀ a : G, e = classical.some (h4 a), from sorry, show e = (1 : G), from sorry, }, sorry, } end /--`theorem` Squeeze Theorem for Real Numbers Let $\sequence {x_n}$, $\sequence {y_n}$ and $\sequence {z_n}$ be sequences in $\R$. Let $\sequence {y_n}$ and $\sequence {z_n}$ both be convergent to the following limit: :$\ds \lim_{n \mathop \to \infty} y_n = l, \lim_{n \mathop \to \infty} z_n = l$ Suppose that: :$\forall n \in \N: y_n \le x_n \le z_n$ Then: :$x_n \to l$ as $n \to \infty$ that is: :$\ds \lim_{n \mathop \to \infty} x_n = l$ `proof` From Negative of Absolute Value: :$\size {x - l} < \epsilon \iff l - \epsilon < x < l + \epsilon$ Let $\epsilon > 0$. We need to prove that: :$\exists N: \forall n > N: \size {x_n - l} < \epsilon$ As $\ds \lim_{n \mathop \to \infty} y_n = l$ we know that: :$\exists N_1: \forall n > N_1: \size {y_n - l} < \epsilon$ As $\ds \lim_{n \mathop \to \infty} z_n = l$ we know that: :$\exists N_2: \forall n > N_2: \size {z_n - l} < \epsilon$ Let $N = \max \set {N_1, N_2}$. Then if $n > N$, it follows that $n > N_1$ and $n > N_2$. So: :$\forall n > N: l - \epsilon < y_n < l + \epsilon$ :$\forall n > N: l - \epsilon < z_n < l + \epsilon$ But: :$\forall n \in \N: y_n \le x_n \le z_n$ So: :$\forall n > N: l - \epsilon < y_n \le x_n \le z_n < l + \epsilon$ and so: :$\forall n > N: l - \epsilon < x_n < l + \epsilon$ So: :$\forall n > N: \size {x_n - l} < \epsilon$ Hence the result. {{qed}} -/ theorem squeeze_theorem_real_numbers (x y z : ℕ → ℝ) (l : ℝ) : let seq_limit : (ℕ → ℝ) → ℝ → Prop := λ (u : ℕ → ℝ) (l : ℝ), ∀ ε > 0, ∃ N, ∀ n > N, |u n - l| < ε in seq_limit y l → seq_limit z l → (∀ n : ℕ, (y n) ≤ (x n) ∧ (x n) ≤ (z n)) → seq_limit x l := begin assume seq_limit (h2 : seq_limit y l) (h3 : seq_limit z l) (h4 : ∀ (n : ℕ), y n ≤ x n ∧ x n ≤ z n) (ε), --From Negative of Absolute Value: $\size {x - l} < \epsilon \iff l - \epsilon < x < l + \epsilon$ have h5 : ∀ x, |x - l| < ε ↔ (((l - ε) < x) ∧ (x < (l + ε))), from sorry, --Let $\epsilon > 0$. assume (h7 : ε > 0), --As $\ds \lim_{n \mathop \to \infty} y_n = l$ we know that $\exists N_1: \forall n > N_1: \size {y_n - l} < \epsilon$ cases h2 ε h7 with N1 h8, --As $\ds \lim_{n \mathop \to \infty} z_n = l$ we know that $\exists N_2: \forall n > N_2: \size {z_n - l} < \epsilon$ cases h3 ε h7 with N2 h9, --Let $N = \max \set {N_1, N_2}$. let N := max N1 N2, use N, --Then if $n > N$, it follows that $n > N_1$ and $n > N_2$. have h10 : ∀ n > N, n > N1 ∧ n > N2 := sorry, --$\forall n > N: l - \epsilon < y_n < l + \epsilon$ --$\forall n > N: l - \epsilon < z_n < l + \epsilon$ --$\forall n \in \N: y_n \le x_n \le z_n$ --So $\forall n > N: l - \epsilon < y_n \le x_n \le z_n < l + \epsilon$ have h11 : ∀ n > N, (((l - ε) < (y n)) ∧ ((y n) ≤ (x n))) ∧ (((x n) ≤ (z n)) ∧ ((z n) < l+ε)), from sorry, --$\forall n > N: l - \epsilon < x_n < l + \epsilon$ have h15 : ∀ n > N, ((l - ε) < (x n)) ∧ ((x n) < (l+ε)), from sorry, --So $\forall n > N: \size {x_n - l} < \epsilon$ --Hence the result show ∀ (n : ℕ), n > N → |x n - l| < ε, from sorry, end /--`theorem` Density of irrational orbit The fractional parts of the integer multiples of an irrational number form a dense subset of the unit interval `proof` Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then $$ i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor, $$ which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. Hence, $$ S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\} $$ is an infinite subset of $\left[0,1\right]$. By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$. To show that $S$ is dense in $[0, 1]$, consider $y \in[0,1]$, and $\epsilon>0$. Then by selecting $x \in S$ such that $\{x\}<\epsilon$ (which exists as $0$ is a limit point), and $N$ such that $N \cdot\{x\} \leq y<(N+1) \cdot\{x\}$, we get: $|y-\{N x\}|<\epsilon$. QED -/ theorem FEW SHOT PROMPTS TO CODEX(END)-/
module AutoHotkey.FFI %default total mutual public export data AutoHotkeyFn t = MkAutoHotkeyFn t public export data AHK_FnTypes : Type -> Type where AHK_Fn : AHK_Types s -> AHK_FnTypes t -> AHK_FnTypes (s -> t) AHK_FnIO : AHK_Types t -> AHK_FnTypes (IO' l t) AHK_FnBase : AHK_Types t -> AHK_FnTypes t public export data AHK_Types : Type -> Type where AHK_Str : AHK_Types String AHK_Int : AHK_Types Int AHK_Float : AHK_Types Double AHK_Unit : AHK_Types () AHK_Raw : AHK_Types (Raw a) AHK_FnT : AHK_FnTypes t -> AHK_Types (AutoHotkeyFn t) public export data AHK_Foreign = AHK_DotAccess String String | AHK_Command String %error_reverse public export FFI_AHK : FFI FFI_AHK = MkFFI AHK_Types AHK_Foreign String %error_reverse public export AHK_IO : Type -> Type AHK_IO = IO' FFI_AHK IO : Type -> Type IO a = IO' FFI_AHK a
(* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * * SPDX-License-Identifier: BSD-2-Clause *) theory jiraver439 imports "CParser.CTranslation" begin external_file "jiraver439.c" install_C_file "jiraver439.c" context jiraver439 begin thm f_body_def thm g1_body_def thm g2_body_def thm h3_body_def lemma "\<Gamma> \<turnstile> \<lbrace> True \<rbrace> \<acute>z :== CALL f();; \<acute>ret__unsigned :== CALL f() \<lbrace> \<acute>ret__unsigned = \<acute>z + 1 \<rbrace>" apply vcg apply simp done end (* context *) end
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <float.h> #include <omp.h> #include <math.h> #include "parmt_config.h" #ifdef PARMT_USE_INTEL #include <mkl_cblas.h> #else #include <cblas.h> #endif #include "parmt_mtsearch.h" #include "parmt_utils.h" #include "compearth.h" #include "iscl/array/array.h" #include "iscl/memory/memory.h" #ifndef MAX #define MAX(x,y) (((x) > (y)) ? (x) : (y)) #endif #ifndef MIN #define MIN(x,y) (((x) < (y)) ? (x) : (y)) #endif static int getNpMax(const int iobs, const struct parmtData_struct data, const struct localMT_struct mtloc); /* static int setDataOnG(const int iobs, const int iloc, const int npmax, const struct parmtData_struct data, double *__restrict__ G); */ int parmt_computeL1StationMagnitude64f(const int ldm, const int nmt, const int npts, const int blockSize, const double *__restrict__ Gxx, const double *__restrict__ Gyy, const double *__restrict__ Gzz, const double *__restrict__ Gxy, const double *__restrict__ Gxz, const double *__restrict__ Gyz, const double *__restrict__ mts, const double *__restrict__ d, double *__restrict__ mags); int parmt_locSearchL164f(const MPI_Comm locComm, const int iobs, const int blockSize, const int nlags, const bool lwantLags, const bool lrescale, struct localMT_struct mtloc, struct parmtData_struct *data, const double *__restrict__ CeInv, double *__restrict__ phi, double *__restrict__ var, int *__restrict__ lags) { const char *fcnm = "parmt_locSearchL164f\0"; double *G, *d, *phiLoc, *phiWork, *varLoc, *varWork, xrescaleNum; int *lagLoc, *lagWork, ierr, iloc, jndx, jloc, k, myloc, npmax, nlocProcs, npts; const int master = 0; ierr = 0; myloc =-1; if (mtloc.myid == master) { MPI_Comm_rank(locComm, &myloc); MPI_Comm_size(locComm, &nlocProcs); } MPI_Bcast(&myloc, 1, MPI_INT, master, mtloc.comm); MPI_Bcast(&nlocProcs, 1, MPI_INT, master, mtloc.comm); if (iobs < 0 || iobs >= data->nobs) { printf("%s: Invalid observation number %d\n", fcnm, iobs); return -1; } if (mtloc.ldm <= 6) { printf("%s: Error leading dimension must be at least 6\n", fcnm); return -1; } if (mtloc.mts == NULL || phi == NULL) { if (mtloc.mts == NULL) { fprintf(stderr, "%s: Error mts is NULL\n", __func__); } if (phi == NULL){fprintf(stderr, "%s: Error phi is NULL\n", __func__);} return -1; } npmax = getNpMax(iobs, *data, mtloc); if (npmax < 1) { printf("%s: No data points\n", fcnm); return -1; } // Set space and copy data lagLoc = NULL; lagWork = NULL; varWork = NULL; phiWork = NULL; G = memory_calloc64f(6*npmax); d = memory_calloc64f(npmax); varLoc = array_set64f(npmax, DBL_MAX, &ierr); phiLoc = memory_calloc64f(mtloc.nmt); if (nlocProcs > 1) { if (mtloc.myid == master) { phiWork = memory_calloc64f(data->nlocs*mtloc.nmtAll); varWork = memory_calloc64f(npmax); if (lwantLags) { lagWork = memory_calloc32i(data->nlocs*mtloc.nmtAll); } } else { phiWork = memory_calloc64f(1); varWork = memory_calloc64f(1); lagWork = memory_calloc32i(1); } } else { phiWork = phi; varWork = var; lagWork = lags; } if (lwantLags) { lagLoc = memory_calloc32i(mtloc.nmt); } else { lagLoc = memory_calloc32i(1); } npts = data->data[iobs].npts; cblas_dcopy(npts, data->data[iobs].data, 1, d, 1); for (jloc=0; jloc<data->nlocs; jloc=jloc+nlocProcs) { iloc = jloc + myloc; if (iloc >= data->nlocs){goto NEXT_LOCATION;} k = iobs*data->nlocs + iloc; // Get the Green's functions onto the matrix G ierr = parmt_utils_setDataOnG(iobs, iloc, npmax, *data, G); if (ierr != 0) { printf("%s: Error setting Greens functions\n", fcnm); return -1; } // Tally the objective function ierr = parmt_mtSearchL164f(mtloc.ldm, mtloc.nmt, npts, blockSize, nlags, lwantLags, lrescale, &G[0*npmax], &G[1*npmax], &G[2*npmax], &G[3*npmax], &G[4*npmax], &G[5*npmax], CeInv, mtloc.mts, d, phiLoc, varLoc, lagLoc); if (ierr != 0) { printf("%s: Error calling XC64f search %d %d\n", fcnm, myloc, mtloc.myid); return -1; } // Get the results on the master jndx = 0; if (mtloc.myid == master){jndx = iloc*mtloc.nmtAll;} if (mtloc.commSize == 1) { array_copy64f_work(mtloc.nmt, phiLoc, &phiWork[jndx]); if (lwantLags) { array_copy32i_work(mtloc.nmt, lagLoc, &lagWork[jndx]); } } else { MPI_Gatherv(phiLoc, mtloc.nmt, MPI_DOUBLE, &phiWork[jndx], mtloc.nmtProc, mtloc.offset, MPI_DOUBLE, master, mtloc.comm); if (lwantLags) { MPI_Gatherv(lagLoc, mtloc.nmt, MPI_INT, &lagWork[jndx], mtloc.nmtProc, mtloc.offset, MPI_INT, master, mtloc.comm); } } NEXT_LOCATION:; } // Reduce the variance onto varWork MPI_Reduce(varLoc, varWork, npts, MPI_DOUBLE, MPI_MIN, master, mtloc.comm); // Have the location masters reduce their result onto the master if (mtloc.myid == master) { if (nlocProcs > 1) { MPI_Reduce(phiWork, phi, data->nlocs*mtloc.nmtAll, MPI_DOUBLE, MPI_SUM, master, locComm); MPI_Reduce(varWork, var, npts, MPI_DOUBLE, MPI_MIN, master, locComm); if (lwantLags) { MPI_Reduce(lagWork, lags, data->nlocs*mtloc.nmtAll, MPI_INT, MPI_SUM, master, locComm); } } } cblas_dscal(npts, 1.0/(double) mtloc.nmtAll, varLoc, 1); // Free memory memory_free32i(&lagLoc); memory_free64f(&phiLoc); memory_free64f(&varLoc); memory_free64f(&d); memory_free64f(&G); if (nlocProcs > 1) { memory_free64f(&phiWork); memory_free64f(&varWork); memory_free32i(&lagWork); } phiWork = NULL; lagWork = NULL; // Block until everyone is done if (mtloc.myid == master){MPI_Barrier(locComm);} MPI_Barrier(mtloc.comm); return 0; } int parmt_locSearchXC64f(const MPI_Comm locComm, const int iobs, const int blockSize, const int nlags, const bool lwantLags, struct localMT_struct mtloc, struct parmtData_struct *data, double *__restrict__ phi, int *__restrict__ lags) { const char *fcnm = "parmt_locSearchXC64f\0"; double *G, *d, *phiLoc, *phiWork; int *lagLoc, *lagWork, ierr, iloc, jndx, jloc, k, myloc, npmax, nprocs, npts; const int master = 0; ierr = 0; myloc =-1; if (mtloc.myid == master) { MPI_Comm_rank(locComm, &myloc); MPI_Comm_size(locComm, &nprocs); } MPI_Bcast(&myloc, 1, MPI_INT, master, mtloc.comm); MPI_Bcast(&nprocs, 1, MPI_INT, master, mtloc.comm); if (iobs < 0 || iobs >= data->nobs) { printf("%s: Invalid observation number %d\n", fcnm, iobs); return -1; } if (mtloc.ldm <= 6) { printf("%s: Error leading dimension must be at least 6\n", fcnm); return -1; } if (mtloc.mts == NULL || phi == NULL) { if (mtloc.mts == NULL) { fprintf(stderr, "%s: Error mts is NULL\n", __func__); } if (phi == NULL){fprintf(stderr, "%s: Error phi is NULL\n", __func__);} return -1; } npmax = getNpMax(iobs, *data, mtloc); if (npmax < 1) { printf("%s: No data points\n", fcnm); return -1; } // Set space and copy data G = memory_calloc64f(6*npmax); d = memory_calloc64f(npmax); phiLoc = memory_calloc64f(mtloc.nmt); if (nprocs > 1) { if (mtloc.myid == master) { phiWork = memory_calloc64f(data->nlocs*mtloc.nmtAll); if (lwantLags) { lagWork = memory_calloc32i(data->nlocs*mtloc.nmtAll); } } else { phiWork = memory_calloc64f(1); lagWork = memory_calloc32i(1); } } else { phiWork = phi; lagWork = lags; } if (lwantLags) { lagLoc = memory_calloc32i(mtloc.nmt); } else { lagLoc = memory_calloc32i(1); } npts = data->data[iobs].npts; cblas_dcopy(npts, data->data[iobs].data, 1, d, 1); for (jloc=0; jloc<data->nlocs; jloc=jloc+nprocs) { iloc = jloc + myloc; if (iloc >= data->nlocs){goto NEXT_LOCATION;} k = iobs*data->nlocs + iloc; // Get the Green's functions onto the matrix G ierr = parmt_utils_setDataOnG(iobs, iloc, npmax, *data, G); if (ierr != 0) { printf("%s: Error setting Greens functions\n", fcnm); return -1; } // Tally the objective function ierr = parmt_mtSearchXC64f(mtloc.ldm, mtloc.nmt, npts, blockSize, nlags, lwantLags, &G[0*npmax], &G[1*npmax], &G[2*npmax], &G[3*npmax], &G[4*npmax], &G[5*npmax], mtloc.mts, d, phiLoc, lagLoc); if (ierr != 0) { printf("%s: Error calling XC64f search %d %d\n", fcnm, myloc, mtloc.myid); return -1; } // Get the results on the master jndx = 0; if (mtloc.myid == master){jndx = iloc*mtloc.nmtAll;} MPI_Gatherv(phiLoc, mtloc.nmt, MPI_DOUBLE, &phiWork[jndx], mtloc.nmtProc, mtloc.offset, MPI_DOUBLE, master, mtloc.comm); if (lwantLags) { MPI_Gatherv(lagLoc, mtloc.nmt, MPI_INT, &lagWork[jndx], mtloc.nmtProc, mtloc.offset, MPI_INT, master, mtloc.comm); } NEXT_LOCATION:; MPI_Barrier(mtloc.comm); } // Have the location masters reduce their result onto the master if (mtloc.myid == master && nprocs > 1) { MPI_Reduce(phiWork, phi, data->nlocs*mtloc.nmtAll, MPI_DOUBLE, MPI_SUM, master, locComm); if (lwantLags) { MPI_Reduce(lagWork, lags, data->nlocs*mtloc.nmtAll, MPI_INT, MPI_SUM, master, locComm); } } // Free memory memory_free32i(&lagLoc); memory_free64f(&phiLoc); memory_free64f(&d); memory_free64f(&G); if (nprocs > 1) { memory_free64f(&phiWork); memory_free32i(&lagWork); } phiWork = NULL; lagWork = NULL; return 0; } static int getNpMax(const int iobs, const struct parmtData_struct data, const struct localMT_struct mtloc) { const char *fcnm = "getNpMax\0"; int iloc, k, npmax, npts; const int master = 0; // Get the workspace size npmax = 0; npts = data.data[iobs].header.npts; if (mtloc.myid == master) { for (iloc=0; iloc<data.nlocs; iloc++) { k = iobs*data.nlocs + iloc; npmax = MAX(npmax, data.data[iobs].header.npts); if (data.data[iobs].header.npts != data.sacGxx[k].header.npts || data.data[iobs].header.npts != data.sacGyy[k].header.npts || data.data[iobs].header.npts != data.sacGzz[k].header.npts || data.data[iobs].header.npts != data.sacGxy[k].header.npts || data.data[iobs].header.npts != data.sacGxz[k].header.npts || data.data[iobs].header.npts != data.sacGyz[k].header.npts) { printf("%s: Inconsistent sizes\n", fcnm); npmax = 0; break; } } } MPI_Bcast(&npmax, 1, MPI_INTEGER, master, mtloc.comm); if (npmax < 1) { printf("%s: Error no data points\n", fcnm); return -1; } return npmax; } /* static int setDataOnG(const int iobs, const int iloc, const int npmax, const struct parmtData_struct data, double *__restrict__ G) { const char *fcnm = "setDataOnG\0"; int k; if (iobs < 0 || iobs >= data.nobs) { printf("%s: Error invalid observation\n", fcnm); return -1; } if (iloc < 0 || iloc >= data.nlocs) { printf("%s: Error invalid location\n", fcnm); return -1; } k = iobs*data.nlocs + iloc; if (npmax > data.sacGxx[k].npts || npmax > data.sacGyy[k].npts || npmax > data.sacGzz[k].npts || npmax > data.sacGxy[k].npts || npmax > data.sacGxz[k].npts || npmax > data.sacGyz[k].npts) { printf("%s: npmax is too small\n", fcnm); return -1; } if (data.sacGxx[k].data == NULL || data.sacGyy[k].data == NULL || data.sacGzz[k].data == NULL || data.sacGxy[k].data == NULL || data.sacGxz[k].data == NULL || data.sacGyz[k].data == NULL) { printf("%s: Greens function is null\n", fcnm); return -1; } // Get the Green's functions onto the matrix G array_zeros64f_work(6*npmax, G); cblas_dcopy(data.sacGxx[k].header.npts, data.sacGxx[k].data, 1, &G[0*npmax], 1); cblas_dcopy(data.sacGyy[k].header.npts, data.sacGyy[k].data, 1, &G[1*npmax], 1); cblas_dcopy(data.sacGzz[k].header.npts, data.sacGzz[k].data, 1, &G[2*npmax], 1); cblas_dcopy(data.sacGxy[k].header.npts, data.sacGxy[k].data, 1, &G[3*npmax], 1); cblas_dcopy(data.sacGxz[k].header.npts, data.sacGxz[k].data, 1, &G[4*npmax], 1); cblas_dcopy(data.sacGyz[k].header.npts, data.sacGyz[k].data, 1, &G[5*npmax], 1); return 0; } */
{- Jesper, 2019-07-05: At first, the fix to #3859 causes the line below to raise a type error: Cannot instantiate the metavariable _6 to solution Set (Agda.Primitive.lsuc (Agda.Primitive.lsuc Agda.Primitive.lzero) Agda.Primitive.⊔ Agda.Primitive.lsuc a) since it contains the variable a which is not in scope of the metavariable or irrelevant in the metavariable but relevant in the solution when checking that the expression λ (A : Set a) → Set has type (A : Set a) → Set₁ Now it is no longer the case. This test case is here to make sure the error doesn't come back. -} F = λ {a} (A : Set a) → Set
lemmas eucl_rel_poly_unique_div = eucl_rel_poly_unique [THEN conjunct1]
import LMT variable {I} [Nonempty I] {E} [Nonempty E] [Nonempty (A I E)] example {a1 a2 a3 : A I E} : ((a2).write i3 (v1)) ≠ (a2) → ((a1).write i3 (v1)) = (a2) → False := by arr
MODULE mymodule IMPLICIT NONE CONTAINS FUNCTION running_max(arg) INTEGER, INTENT(IN) :: arg INTEGER :: running_max INTEGER :: current_max = 0 current_max = MAX(current_max, arg) running_max = current_max END FUNCTION running_max END MODULE mymodule PROGRAM driver USE mymodule IMPLICIT NONE PRINT *, running_max(1) PRINT *, running_max(10) PRINT *, running_max(2) PRINT *, running_max(20) END PROGRAM driver
(* @SUITE inline *) theory inline imports "../Tactic_Inline" "../Lang_Simplifier" begin abbreviation "z == Variable ''z'' :: int variable" procedure proc1 :: "(int,int) procedure" where "proc1 = LOCAL x a. proc(a) { x := a; z := x; return z+a }" lemma assumes "LOCAL x a. hoare { True } z:=1; a := z; x := default; x := a; z := x; z := z+a { z=undefined }" shows "hoare { True } z:=1; z:=call proc1(z) { z=undefined }" apply (inline proc1) apply simp by (fact assms) end
[STATEMENT] lemma refines_replicate[refines_rule]: "refines f f' \<Longrightarrow> refines (replicatei n f) (replicatei n f')" [PROOF STATE] proof (prove) goal (1 subgoal): 1. refines f f' \<Longrightarrow> refines (replicatei n f) (replicatei n f') [PROOF STEP] apply (induction n) [PROOF STATE] proof (prove) goal (2 subgoals): 1. refines f f' \<Longrightarrow> refines (replicatei 0 f) (replicatei 0 f') 2. \<And>n. \<lbrakk>refines f f' \<Longrightarrow> refines (replicatei n f) (replicatei n f'); refines f f'\<rbrakk> \<Longrightarrow> refines (replicatei (Suc n) f) (replicatei (Suc n) f') [PROOF STEP] apply simp_all [PROOF STATE] proof (prove) goal (2 subgoals): 1. refines f f' \<Longrightarrow> refines (return []) (return []) 2. \<And>n. \<lbrakk>refines (replicatei n f) (replicatei n f'); refines f f'\<rbrakk> \<Longrightarrow> refines (f \<bind> (\<lambda>y. replicatei n f \<bind> (\<lambda>ys. return (y # ys)))) (f' \<bind> (\<lambda>y. replicatei n f' \<bind> (\<lambda>ys. return (y # ys)))) [PROOF STEP] apply refines [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
module ReflNotRefl2 import Data.Fin import ReflNotRefl1 prop : ind 3 (B 4 `W` (3, True)) = True prop = Refl
Last week was joyously punctuated by a couple of splendid nights strolling through Verona, all the while thumbing my nose at gout through whilst indulging in majestic consumption. One dinner was prefaced with Franciacorta (the champenoise sparkler from the 'handkerchief' sized production area near Lago D’iseo east of Milan) taken overlooking the Adige river in an unremarkable bar with an astounding terrace, a base camp from which we hiked up the hill to Re Teodorico. The steps were conquered (in the manner of Rocky but with more panting and sweating) and a trendy new restaurant/cocktail bar/nightclub exclusively populated with lithe and fey pretty young Italians was soon overrun by a glutton (my collective noun) of power-eaters. An outside table was requested, and duly appeared Goodfellas style, and we settled in to the amazing view. More bubbles, Durello from the hills around Verona, to further stimulate the appetite (and precipitate a hangover, why must I always mix?) and the food begins to arrive in those relatively small rectangular plates which make you feel like you could eat forever, a gastronomic Sisyphus. First up, Morbida polenta gialla con noci di capasanta and lucky for me one of my co-diners isn’t fond of seafood so I take his portion and I push the twin beds of polenta together to make double with a great fat scallop in each side under a paper thin squid ink flavoured bed sheet. Millefoglie di pescatrice con verdure e salsa di crostacei is missing 997 sheets but the filo 3 (top, middle, bottom) perfectly balance the vegetables and crustacean sauce. The wine drinking, until now steadily impressive, shifts up a gear, and we are motoring through the Zenato Valpolicella Superiore. My limited recollection becomes even more severely hampered (and I forget to take photos again). Insalata di magatello con primizie dell'orto e pane profumato which I can’t remember but definitely ate is quickly followed by (another) Millefoglie di mozzarella campana con pomodoro e la sua "pappa" which had mozzarella in it. I may have had a risotto and then a short break before they roll out Maltagliati con ragout di carni di cortile e sbriciolata di porcini, “badly cut pasta with ragout of hand chopped meat and a crumble of penny buns”. It’s a triumph (because I remember eating it). The majority skip dessert in favour of groaning and rubbing their distended paunches but I cannot overlook "Pensiero Stupendo" una creazione dello Chef Leonard Belluzzo dedicata al cioccolato - “georgeous thought dedicated to chocolate” and my seafood averse colleague orders something with fruit of which I eat half (heartedly) before enquiring where the chocolate is. We swap plates, embarrassed first-daters, and I polish off Chef Len’s creation then body-swerve the Grappa in favour of a camomile and mint tea and I’m done. Next day, CRASH!! I’m back home. Lovely wife has been wrangling 2 children whilst juggling a job and the house and fridge is full of rotting fruit, weary discoloured veg and out of date cheese; thus is born “Melanzane Veronese”. Chop the dry and malformed onion ends in the bottom of the fridge and fry in lots of olive oil with antibacterial garlic, oregano, fennel seeds and rosemary. Add a tin of chopped tomatoes and some squishy browning cherry toms without looking too closely at them. Simmer for 15 minutes to kill the bugs, then throw in a big handful of Cuquillo olives for flavour and to reduce microbiological loading. Slice 3 sad and saggy brown aubergines and griddle them back to health. Slice out of date mozzarella and grate those ends of blue (was it blue to begin with?), the soft white rind (possibly sheep) and the fractured yellow thing that might have been cheddar. Layer tomatoes, aubergines, cheese mix. Repeat. Top with more cheese mix. Bake for 30 minutes @ 180 degrees. Eat whilst hot to mask potentially rancid flavours. Accompany with well dressed (balsamic and olive oil) little gems topped with grated Grana Padano. There were no casualties.
(* Title: Examples/TTS_Foundations/Foundations/FNDS_Set_Ext.thy Author: Mihails Milehins Copyright 2021 (C) Mihails Milehins *) section\<open>Extension of the theory \<^text>\<open>Set\<close>\<close> theory FNDS_Set_Ext imports Main begin lemma Ex1_transfer[transfer_rule]: includes lifting_syntax assumes [transfer_rule]: "bi_unique A" "right_total A" shows "((A ===> (=)) ===> (=)) (\<lambda>P. (\<exists>!x\<in>(Collect (Domainp A)). P x)) Ex1" unfolding Ex1_def apply transfer_prover_start apply transfer_step+ by blast text\<open>\newpage\<close> end
State Before: b x y : Ordinal xy : x ≤ y hx : x = 0 ⊢ log b x ≤ log b y State After: no goals Tactic: simp only [hx, log_zero_right, Ordinal.zero_le] State Before: b x y : Ordinal xy : x ≤ y hx : ¬x = 0 hb : ¬1 < b ⊢ log b x ≤ log b y State After: no goals Tactic: simp only [log_of_not_one_lt_left hb, Ordinal.zero_le]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro The Schröder-Bernstein theorem, and well ordering of cardinals. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.order.fixed_points import Mathlib.order.zorn import Mathlib.PostPort universes u v namespace Mathlib namespace function namespace embedding theorem schroeder_bernstein {α : Type u} {β : Type v} {f : α → β} {g : β → α} (hf : injective f) (hg : injective g) : ∃ (h : α → β), bijective h := sorry theorem antisymm {α : Type u} {β : Type v} : (α ↪ β) → (β ↪ α) → Nonempty (α ≃ β) := sorry theorem min_injective {ι : Type u} {β : ι → Type v} (I : Nonempty ι) : ∃ (i : ι), Nonempty ((j : ι) → β i ↪ β j) := sorry theorem total {α : Type u} {β : Type v} : Nonempty (α ↪ β) ∨ Nonempty (β ↪ α) := sorry
[STATEMENT] theorem prf_encrypt_advantage: assumes "ind_cpa.ibounded_by \<A> q" and "lossless_gpv \<I>_full (fst \<A>)" and "\<And>cipher \<sigma>. lossless_gpv \<I>_full (snd \<A> cipher \<sigma>)" shows "ind_cpa.advantage \<A> \<le> prf.advantage (prf_adversary \<A>) + q / 2 ^ len" [PROOF STATE] proof (prove) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] note [split del] = if_split and [cong del] = if_weak_cong and [simp] = bind_spmf_const map_spmf_bind_spmf bind_map_spmf exec_gpv_bind exec_gpv_inline rel_spmf_bind_reflI rel_spmf_reflI [PROOF STATE] proof (state) this: ?P (if ?Q then ?x else ?y) = ((?Q \<longrightarrow> ?P ?x) \<and> (\<not> ?Q \<longrightarrow> ?P ?y)) ?b = ?c \<Longrightarrow> (if ?b then ?x else ?y) = (if ?c then ?x else ?y) ?p \<bind> (\<lambda>x. ?q) = scale_spmf (weight_spmf ?p) ?q map_spmf ?f (?p \<bind> ?g) = ?p \<bind> map_spmf ?f \<circ> ?g map_spmf ?f ?p \<bind> ?g = ?p \<bind> ?g \<circ> ?f exec_gpv ?callee (?c \<bind> ?f) ?s = exec_gpv ?callee ?c ?s \<bind> (\<lambda>xa. case xa of (x, s') \<Rightarrow> exec_gpv ?callee (?f x) s') exec_gpv ?callee (inline ?gpv ?c' ?s') ?s = map_spmf (\<lambda>(x, s', s). ((x, s'), s)) (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, s', s)) (exec_gpv ?callee (?gpv s' y) s)) ?c' (?s', ?s)) (\<And>x. x \<in> set_spmf ?p \<Longrightarrow> rel_spmf ?P (?f x) (?g x)) \<Longrightarrow> rel_spmf ?P (?p \<bind> ?f) (?p \<bind> ?g) (\<And>x. x \<in> set_spmf ?p \<Longrightarrow> ?P x x) \<Longrightarrow> rel_spmf ?P ?p ?p goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] obtain \<A>1 \<A>2 where \<A>: "\<A> = (\<A>1, \<A>2)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<And>\<A>1 \<A>2. \<A> = (\<A>1, \<A>2) \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by(cases "\<A>") [PROOF STATE] proof (state) this: \<A> = (\<A>1, \<A>2) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] from \<open>ind_cpa.ibounded_by _ _\<close> [PROOF STATE] proof (chain) picking this: local.ind_cpa.ibounded_by \<A> (enat q) [PROOF STEP] obtain q1 q2 :: nat where q1: "interaction_any_bounded_by \<A>1 q1" and q2: "\<And>cipher \<sigma>. interaction_any_bounded_by (\<A>2 cipher \<sigma>) q2" and "q1 + q2 \<le> q" [PROOF STATE] proof (prove) using this: local.ind_cpa.ibounded_by \<A> (enat q) goal (1 subgoal): 1. (\<And>q1 q2. \<lbrakk>interaction_bounded_by' (\<lambda>_. True) \<A>1 q1; \<And>cipher \<sigma>. interaction_bounded_by' (\<lambda>_. True) (\<A>2 cipher \<sigma>) q2; q1 + q2 \<le> q\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] unfolding \<A> [PROOF STATE] proof (prove) using this: local.ind_cpa.ibounded_by (\<A>1, \<A>2) (enat q) goal (1 subgoal): 1. (\<And>q1 q2. \<lbrakk>interaction_bounded_by' (\<lambda>_. True) \<A>1 q1; \<And>cipher \<sigma>. interaction_bounded_by' (\<lambda>_. True) (\<A>2 cipher \<sigma>) q2; q1 + q2 \<le> q\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by(rule ind_cpa.ibounded_byE)(auto simp add: iadd_le_enat_iff) [PROOF STATE] proof (state) this: interaction_bounded_by' (\<lambda>_. True) \<A>1 q1 interaction_bounded_by' (\<lambda>_. True) (\<A>2 ?cipher2 ?\<sigma>2) q2 q1 + q2 \<le> q goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] from \<A> assms [PROOF STATE] proof (chain) picking this: \<A> = (\<A>1, \<A>2) local.ind_cpa.ibounded_by \<A> (enat q) lossless_gpv \<I>_full (fst \<A>) lossless_gpv \<I>_full (snd \<A> ?cipher2 ?\<sigma>2) [PROOF STEP] have lossless1: "lossless_gpv \<I>_full \<A>1" and lossless2: "\<And>cipher \<sigma>. lossless_gpv \<I>_full (\<A>2 cipher \<sigma>)" [PROOF STATE] proof (prove) using this: \<A> = (\<A>1, \<A>2) local.ind_cpa.ibounded_by \<A> (enat q) lossless_gpv \<I>_full (fst \<A>) lossless_gpv \<I>_full (snd \<A> ?cipher2 ?\<sigma>2) goal (1 subgoal): 1. lossless_gpv \<I>_full \<A>1 &&& (\<And>cipher \<sigma>. lossless_gpv \<I>_full (\<A>2 cipher \<sigma>)) [PROOF STEP] by simp_all [PROOF STATE] proof (state) this: lossless_gpv \<I>_full \<A>1 lossless_gpv \<I>_full (\<A>2 ?cipher2 ?\<sigma>2) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have weight1: "\<And>oracle s. (\<And>s x. lossless_spmf (oracle s x)) \<Longrightarrow> weight_spmf (exec_gpv oracle \<A>1 s) = 1" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>oracle s. (\<And>s x. lossless_spmf (oracle s x)) \<Longrightarrow> weight_spmf (exec_gpv oracle \<A>1 s) = 1 [PROOF STEP] by(rule lossless_weight_spmfD)(rule lossless_exec_gpv[OF lossless1], simp_all) [PROOF STATE] proof (state) this: (\<And>s x. lossless_spmf (?oracle2 s x)) \<Longrightarrow> weight_spmf (exec_gpv ?oracle2 \<A>1 ?s2) = 1 goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have weight2: "\<And>oracle s cipher \<sigma>. (\<And>s x. lossless_spmf (oracle s x)) \<Longrightarrow> weight_spmf (exec_gpv oracle (\<A>2 cipher \<sigma>) s) = 1" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>oracle s cipher \<sigma>. (\<And>s x. lossless_spmf (oracle s x)) \<Longrightarrow> weight_spmf (exec_gpv oracle (\<A>2 cipher \<sigma>) s) = 1 [PROOF STEP] by(rule lossless_weight_spmfD)(rule lossless_exec_gpv[OF lossless2], simp_all) [PROOF STATE] proof (state) this: (\<And>s x. lossless_spmf (?oracle3 s x)) \<Longrightarrow> weight_spmf (exec_gpv ?oracle3 (\<A>2 ?cipher3 ?\<sigma>3) ?s3) = 1 goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] let ?oracle1 = "\<lambda>key (s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (prf.prf_oracle key) (prf_encrypt_oracle () y) ())" [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have bisim1: "\<And>key. rel_spmf (\<lambda>(x, _) (y, _). x = y) (exec_gpv (ind_cpa.encrypt_oracle key) \<A>1 ()) (exec_gpv (?oracle1 key) \<A>1 ((), ()))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>key. rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv (local.ind_cpa.encrypt_oracle key) \<A>1 ()) (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle key) (prf_encrypt_oracle () y) ())) \<A>1 ((), ())) [PROOF STEP] using TrueI [PROOF STATE] proof (prove) using this: True goal (1 subgoal): 1. \<And>key. rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv (local.ind_cpa.encrypt_oracle key) \<A>1 ()) (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle key) (prf_encrypt_oracle () y) ())) \<A>1 ((), ())) [PROOF STEP] by(rule exec_gpv_oracle_bisim)(auto simp add: encrypt_def prf_encrypt_oracle_def ind_cpa.encrypt_oracle_def prf.prf_oracle_def o_def) [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv (local.ind_cpa.encrypt_oracle ?key5) \<A>1 ()) (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle ?key5) (prf_encrypt_oracle () y) ())) \<A>1 ((), ())) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have bisim2: "\<And>key cipher \<sigma>. rel_spmf (\<lambda>(x, _) (y, _). x = y) (exec_gpv (ind_cpa.encrypt_oracle key) (\<A>2 cipher \<sigma>) ()) (exec_gpv (?oracle1 key) (\<A>2 cipher \<sigma>) ((), ()))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>key cipher \<sigma>. rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv (local.ind_cpa.encrypt_oracle key) (\<A>2 cipher \<sigma>) ()) (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle key) (prf_encrypt_oracle () y) ())) (\<A>2 cipher \<sigma>) ((), ())) [PROOF STEP] using TrueI [PROOF STATE] proof (prove) using this: True goal (1 subgoal): 1. \<And>key cipher \<sigma>. rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv (local.ind_cpa.encrypt_oracle key) (\<A>2 cipher \<sigma>) ()) (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle key) (prf_encrypt_oracle () y) ())) (\<A>2 cipher \<sigma>) ((), ())) [PROOF STEP] by(rule exec_gpv_oracle_bisim)(auto simp add: encrypt_def prf_encrypt_oracle_def ind_cpa.encrypt_oracle_def prf.prf_oracle_def o_def) [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv (local.ind_cpa.encrypt_oracle ?key5) (\<A>2 ?cipher5 ?\<sigma>5) ()) (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle ?key5) (prf_encrypt_oracle () y) ())) (\<A>2 ?cipher5 ?\<sigma>5) ((), ())) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have ind_cpa_0: "rel_spmf (=) (ind_cpa.ind_cpa \<A>) (prf.game_0 (prf_adversary \<A>))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (local.ind_cpa.ind_cpa \<A>) (local.prf.game_0 (prf_adversary \<A>)) [PROOF STEP] unfolding IND_CPA.ind_cpa.ind_cpa_def \<A> key_gen_def Let_def prf_adversary_def Pseudo_Random_Function.prf.game_0_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (case (\<A>1, \<A>2) of (\<A>1, \<A>2) \<Rightarrow> spmf_of_set (nlists UNIV len) \<bind> (\<lambda>key. coin_spmf \<bind> (\<lambda>b. exec_gpv (local.ind_cpa.encrypt_oracle key) (\<A>1 \<bind> (\<lambda>((m0, m1), \<sigma>). if valid_plain m0 \<and> valid_plain m1 then lift_spmf (encrypt key (if b then m0 else m1)) \<bind> (\<lambda>cipher. \<A>2 cipher \<sigma>) else lift_spmf coin_spmf)) () \<bind> (\<lambda>(guess, uu_). return_spmf (guess = b))))) (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>key. exec_gpv (local.prf.prf_oracle key) (case (\<A>1, \<A>2) of (\<A>1, \<A>2) \<Rightarrow> inline prf_encrypt_oracle \<A>1 () \<bind> (\<lambda>(((p1, p2), \<sigma>), n). if valid_plain p1 \<and> valid_plain p2 then lift_spmf coin_spmf \<bind> (\<lambda>b. lift_spmf (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>r. Generative_Probabilistic_Value.Pause r Generative_Probabilistic_Value.Done \<bind> (\<lambda>pad. inline prf_encrypt_oracle (\<A>2 (r, (if b then p1 else p2) [\<oplus>] pad) \<sigma>) n \<bind> (\<lambda>(b', uu_). Generative_Probabilistic_Value.Done (b' = b))))) else lift_spmf coin_spmf)) () \<bind> (\<lambda>(b, uu_). return_spmf b))) [PROOF STEP] apply(simp) [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>key. coin_spmf \<bind> (\<lambda>b. exec_gpv (local.ind_cpa.encrypt_oracle key) \<A>1 () \<bind> (\<lambda>y. (case y of (x, xa) \<Rightarrow> exec_gpv (local.ind_cpa.encrypt_oracle key) (case x of (x, xa) \<Rightarrow> (case x of (m0, m1) \<Rightarrow> \<lambda>\<sigma>. if valid_plain m0 \<and> valid_plain m1 then lift_spmf (encrypt key (if b then m0 else m1)) \<bind> (\<lambda>cipher. \<A>2 cipher \<sigma>) else lift_spmf coin_spmf) xa) xa) \<bind> (\<lambda>(guess, uu_). return_spmf (guess = b)))))) (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>key. exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle key) (prf_encrypt_oracle () y) ())) \<A>1 ((), ()) \<bind> (\<lambda>y. (case case y of (x, s', xb) \<Rightarrow> ((x, ()), xb) of (x, xa) \<Rightarrow> exec_gpv (local.prf.prf_oracle key) (case x of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> (case x of (p1, p2) \<Rightarrow> \<lambda>\<sigma> n. if valid_plain p1 \<and> valid_plain p2 then lift_spmf coin_spmf \<bind> (\<lambda>b. lift_spmf (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>r. Generative_Probabilistic_Value.Pause r (\<lambda>pad. inline prf_encrypt_oracle (\<A>2 (r, (if b then p1 else p2) [\<oplus>] pad) \<sigma>) () \<bind> (\<lambda>(b', uu_). Generative_Probabilistic_Value.Done (b' = b))))) else lift_spmf coin_spmf) xa) xa) xa) \<bind> (\<lambda>(b, uu_). return_spmf b)))) [PROOF STEP] apply(rewrite in "bind_spmf _ \<hole>" bind_commute_spmf) [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>key. exec_gpv (local.ind_cpa.encrypt_oracle key) \<A>1 () \<bind> (\<lambda>y. coin_spmf \<bind> (\<lambda>b. (case y of (x, xa) \<Rightarrow> exec_gpv (local.ind_cpa.encrypt_oracle key) (case x of (x, xa) \<Rightarrow> (case x of (m0, m1) \<Rightarrow> \<lambda>\<sigma>. if valid_plain m0 \<and> valid_plain m1 then lift_spmf (encrypt key (if b then m0 else m1)) \<bind> (\<lambda>cipher. \<A>2 cipher \<sigma>) else lift_spmf coin_spmf) xa) xa) \<bind> (\<lambda>(guess, uu_). return_spmf (guess = b)))))) (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>key. exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle key) (prf_encrypt_oracle () y) ())) \<A>1 ((), ()) \<bind> (\<lambda>y. (case case y of (x, s', xb) \<Rightarrow> ((x, ()), xb) of (x, xa) \<Rightarrow> exec_gpv (local.prf.prf_oracle key) (case x of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> (case x of (p1, p2) \<Rightarrow> \<lambda>\<sigma> n. if valid_plain p1 \<and> valid_plain p2 then lift_spmf coin_spmf \<bind> (\<lambda>b. lift_spmf (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>r. Generative_Probabilistic_Value.Pause r (\<lambda>pad. inline prf_encrypt_oracle (\<A>2 (r, (if b then p1 else p2) [\<oplus>] pad) \<sigma>) () \<bind> (\<lambda>(b', uu_). Generative_Probabilistic_Value.Done (b' = b))))) else lift_spmf coin_spmf) xa) xa) xa) \<bind> (\<lambda>(b, uu_). return_spmf b)))) [PROOF STEP] apply(rule rel_spmf_bind_reflI) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>x. x \<in> set_spmf (spmf_of_set (nlists UNIV len)) \<Longrightarrow> rel_spmf (=) (exec_gpv (local.ind_cpa.encrypt_oracle x) \<A>1 () \<bind> (\<lambda>y. coin_spmf \<bind> (\<lambda>b. (case y of (xa, xb) \<Rightarrow> exec_gpv (local.ind_cpa.encrypt_oracle x) (case xa of (xa, xb) \<Rightarrow> (case xa of (m0, m1) \<Rightarrow> \<lambda>\<sigma>. if valid_plain m0 \<and> valid_plain m1 then lift_spmf (encrypt x (if b then m0 else m1)) \<bind> (\<lambda>cipher. \<A>2 cipher \<sigma>) else lift_spmf coin_spmf) xb) xb) \<bind> (\<lambda>(guess, uu_). return_spmf (guess = b))))) (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle x) (prf_encrypt_oracle () y) ())) \<A>1 ((), ()) \<bind> (\<lambda>y. (case case y of (x, s', xb) \<Rightarrow> ((x, ()), xb) of (xa, xb) \<Rightarrow> exec_gpv (local.prf.prf_oracle x) (case xa of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> (case x of (p1, p2) \<Rightarrow> \<lambda>\<sigma> n. if valid_plain p1 \<and> valid_plain p2 then lift_spmf coin_spmf \<bind> (\<lambda>b. lift_spmf (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>r. Generative_Probabilistic_Value.Pause r (\<lambda>pad. inline prf_encrypt_oracle (\<A>2 (r, (if b then p1 else p2) [\<oplus>] pad) \<sigma>) () \<bind> (\<lambda>(b', uu_). Generative_Probabilistic_Value.Done (b' = b))))) else lift_spmf coin_spmf) xa) xa) xb) \<bind> (\<lambda>(b, uu_). return_spmf b))) [PROOF STEP] apply(rule rel_spmf_bindI[OF bisim1]) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>x xa y. \<lbrakk>x \<in> set_spmf (spmf_of_set (nlists UNIV len)); (case xa of (x, uu_) \<Rightarrow> \<lambda>(y, uu_). x = y) y\<rbrakk> \<Longrightarrow> rel_spmf (=) (coin_spmf \<bind> (\<lambda>b. (case xa of (xa, xb) \<Rightarrow> exec_gpv (local.ind_cpa.encrypt_oracle x) (case xa of (xa, xb) \<Rightarrow> (case xa of (m0, m1) \<Rightarrow> \<lambda>\<sigma>. if valid_plain m0 \<and> valid_plain m1 then lift_spmf (encrypt x (if b then m0 else m1)) \<bind> (\<lambda>cipher. \<A>2 cipher \<sigma>) else lift_spmf coin_spmf) xb) xb) \<bind> (\<lambda>(guess, uu_). return_spmf (guess = b)))) ((case case y of (x, s', xb) \<Rightarrow> ((x, ()), xb) of (xa, xb) \<Rightarrow> exec_gpv (local.prf.prf_oracle x) (case xa of (x, xa) \<Rightarrow> (case x of (x, xa) \<Rightarrow> (case x of (p1, p2) \<Rightarrow> \<lambda>\<sigma> n. if valid_plain p1 \<and> valid_plain p2 then lift_spmf coin_spmf \<bind> (\<lambda>b. lift_spmf (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>r. Generative_Probabilistic_Value.Pause r (\<lambda>pad. inline prf_encrypt_oracle (\<A>2 (r, (if b then p1 else p2) [\<oplus>] pad) \<sigma>) () \<bind> (\<lambda>(b', uu_). Generative_Probabilistic_Value.Done (b' = b))))) else lift_spmf coin_spmf) xa) xa) xb) \<bind> (\<lambda>(b, uu_). return_spmf b)) [PROOF STEP] apply(clarsimp simp add: if_distribs bind_coin_spmf_eq_const') [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>x aa bb bc. \<lbrakk>x \<in> nlists UNIV len; valid_plain aa; valid_plain bb\<rbrakk> \<Longrightarrow> rel_spmf (=) (coin_spmf \<bind> (\<lambda>b. encrypt x (if b then aa else bb) \<bind> (\<lambda>y. exec_gpv (local.ind_cpa.encrypt_oracle x) (\<A>2 y bc) () \<bind> (\<lambda>(guess, uu_). return_spmf (guess = b))))) (coin_spmf \<bind> (\<lambda>y. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>ya. local.prf.prf_oracle x () ya \<bind> (\<lambda>yb. (case yb of (xa, s') \<Rightarrow> exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), ())) (exec_gpv (local.prf.prf_oracle x) (prf_encrypt_oracle () y) ())) (\<A>2 (ya, (if y then aa else bb) [\<oplus>] xa) bc) ((), ()) \<bind> (\<lambda>(xa, ya). exec_gpv (local.prf.prf_oracle x) (case xa of (b', uu_) \<Rightarrow> Generative_Probabilistic_Value.Done (b' = y)) ya) \<circ> (\<lambda>(x, s', y). ((x, ()), y))) \<bind> (\<lambda>(b, uu_). return_spmf b))))) [PROOF STEP] apply(auto intro: rel_spmf_bindI[OF bisim2] intro!: rel_spmf_bind_reflI simp add: encrypt_def prf.prf_oracle_def cong del: if_cong) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done [PROOF STATE] proof (state) this: rel_spmf (=) (local.ind_cpa.ind_cpa \<A>) (local.prf.game_0 (prf_adversary \<A>)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define rf_encrypt where "rf_encrypt = (\<lambda>s plain. bind_spmf (spmf_of_set (nlists UNIV len)) (\<lambda>r :: bool list. bind_spmf (prf.random_oracle s r) (\<lambda>(pad, s'). return_spmf ((r, xor_list plain pad), s'))) )" [PROOF STATE] proof (state) this: rf_encrypt = (\<lambda>s plain. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. prf.random_oracle s r \<bind> (\<lambda>(pad, s'). return_spmf ((r, plain [\<oplus>] pad), s')))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] interpret rf_finite: callee_invariant_on rf_encrypt "\<lambda>s. finite (dom s)" \<I>_full [PROOF STATE] proof (prove) goal (1 subgoal): 1. callee_invariant rf_encrypt (\<lambda>s. finite (dom s)) [PROOF STEP] by unfold_locales(auto simp add: rf_encrypt_def dest: prf.finite.callee_invariant) [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have lossless_rf_encrypt [simp]: "\<And>s plain. lossless_spmf (rf_encrypt s plain)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>s plain. lossless_spmf (rf_encrypt s plain) [PROOF STEP] by(auto simp add: rf_encrypt_def) [PROOF STATE] proof (state) this: lossless_spmf (rf_encrypt ?s5 ?plain5) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define game2 where "game2 = do { (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); (cipher, s2) \<leftarrow> rf_encrypt s1 pb; (b', s3) \<leftarrow> exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2; return_spmf (b' = b) } else coin_spmf }" [PROOF STATE] proof (state) this: game2 = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in rf_encrypt s1 pb \<bind> (\<lambda>(cipher, s2). exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] let ?oracle2 = "\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), s)) (exec_gpv prf.random_oracle (prf_encrypt_oracle () y) s)" [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] let ?I = "\<lambda>(x, _, s) (y, s'). x = y \<and> s = s'" [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have bisim1: "rel_spmf ?I (exec_gpv ?oracle2 \<A>1 ((), Map.empty)) (exec_gpv rf_encrypt \<A>1 Map.empty)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (\<lambda>(x, uu_, s) (y, s'). x = y \<and> s = s') (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), s)) (exec_gpv prf.random_oracle (prf_encrypt_oracle () y) s)) \<A>1 ((), Map.empty)) (exec_gpv rf_encrypt \<A>1 Map.empty) [PROOF STEP] by(rule exec_gpv_oracle_bisim[where X="\<lambda>(_, s) s'. s = s'"]) (auto simp add: rf_encrypt_def prf_encrypt_oracle_def intro!: rel_spmf_bind_reflI) [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, uu_, s) (y, s'). x = y \<and> s = s') (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), s)) (exec_gpv prf.random_oracle (prf_encrypt_oracle () y) s)) \<A>1 ((), Map.empty)) (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have bisim2: "\<And>cipher \<sigma> s. rel_spmf ?I (exec_gpv ?oracle2 (\<A>2 cipher \<sigma>) ((), s)) (exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>cipher \<sigma> s. rel_spmf (\<lambda>(x, uu_, s) (y, s'). x = y \<and> s = s') (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), s)) (exec_gpv prf.random_oracle (prf_encrypt_oracle () y) s)) (\<A>2 cipher \<sigma>) ((), s)) (exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s) [PROOF STEP] by(rule exec_gpv_oracle_bisim[where X="\<lambda>(_, s) s'. s = s'"]) (auto simp add: prf_encrypt_oracle_def rf_encrypt_def intro!: rel_spmf_bind_reflI) [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, uu_, s) (y, s'). x = y \<and> s = s') (exec_gpv (\<lambda>(s', s) y. map_spmf (\<lambda>((x, s'), s). (x, (), s)) (exec_gpv prf.random_oracle (prf_encrypt_oracle () y) s)) (\<A>2 ?cipher7 ?\<sigma>7) ((), ?s7)) (exec_gpv rf_encrypt (\<A>2 ?cipher7 ?\<sigma>7) ?s7) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have game1_2 [unfolded spmf_rel_eq]: "rel_spmf (=) (prf.game_1 (prf_adversary \<A>)) game2" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (local.prf.game_1 (prf_adversary \<A>)) game2 [PROOF STEP] unfolding prf.game_1_def game2_def prf_adversary_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (exec_gpv prf.random_oracle (let (\<A>1, \<A>2) = \<A> in inline prf_encrypt_oracle \<A>1 () \<bind> (\<lambda>(((p1, p2), \<sigma>), n). if valid_plain p1 \<and> valid_plain p2 then lift_spmf coin_spmf \<bind> (\<lambda>b. let pb = if b then p1 else p2 in lift_spmf (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>r. Generative_Probabilistic_Value.Pause r Generative_Probabilistic_Value.Done \<bind> (\<lambda>pad. let c = (r, pb [\<oplus>] pad) in inline prf_encrypt_oracle (\<A>2 c \<sigma>) n \<bind> (\<lambda>(b', uu_). Generative_Probabilistic_Value.Done (b' = b))))) else lift_spmf coin_spmf)) Map.empty \<bind> (\<lambda>(b, uu_). return_spmf b)) (exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in rf_encrypt s1 pb \<bind> (\<lambda>(cipher, s2). exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf)) [PROOF STEP] by(rewrite in "if _ then \<hole> else _" rf_encrypt_def) (auto simp add: Let_def \<A> if_distribs intro!: rel_spmf_bindI[OF bisim2] rel_spmf_bind_reflI rel_spmf_bindI[OF bisim1]) [PROOF STATE] proof (state) this: local.prf.game_1 (prf_adversary \<A>) = game2 goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define game2_a where "game2_a = do { r \<leftarrow> spmf_of_set (nlists UNIV len); (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; let bad = r \<in> dom s1; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); (pad, s2) \<leftarrow> prf.random_oracle s1 r; let cipher = (r, xor_list pb pad); (b', s3) \<leftarrow> exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2; return_spmf (b' = b, bad) } else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad)) }" [PROOF STATE] proof (state) this: game2_a = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). let bad = r \<in> dom s1 in if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad)))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define game2_b where "game2_b = do { r \<leftarrow> spmf_of_set (nlists UNIV len); (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; let bad = r \<in> dom s1; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); pad \<leftarrow> spmf_of_set (nlists UNIV len); let cipher = (r, xor_list pb pad); (b', s3) \<leftarrow> exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) (s1(r \<mapsto> pad)); return_spmf (b' = b, bad) } else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad)) }" [PROOF STATE] proof (state) this: game2_b = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). let bad = r \<in> dom s1 in if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) (s1(r \<mapsto> pad)) \<bind> (\<lambda>(b', s3). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad)))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "game2 = do { r \<leftarrow> spmf_of_set (nlists UNIV len); (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); (pad, s2) \<leftarrow> prf.random_oracle s1 r; let cipher = (r, xor_list pb pad); (b', s3) \<leftarrow> exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2; return_spmf (b' = b) } else coin_spmf }" [PROOF STATE] proof (prove) goal (1 subgoal): 1. game2 = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf)) [PROOF STEP] including monad_normalisation [PROOF STATE] proof (prove) goal (1 subgoal): 1. game2 = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf)) [PROOF STEP] by(simp add: game2_def split_def rf_encrypt_def Let_def) [PROOF STATE] proof (state) this: game2 = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: game2 = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> = map_spmf fst game2_a" [PROOF STATE] proof (prove) goal (1 subgoal): 1. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf)) = map_spmf fst game2_a [PROOF STEP] unfolding game2_a_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf)) = map_spmf fst (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). let bad = r \<in> dom s1 in if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad))))) [PROOF STEP] by(clarsimp simp add: map_spmf_conv_bind_spmf Let_def if_distribR if_distrib split_def cong: if_cong) [PROOF STATE] proof (state) this: spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b)))) else coin_spmf)) = map_spmf fst game2_a goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: game2 = map_spmf fst game2_a [PROOF STEP] have game2_2a: "game2 = \<dots>" [PROOF STATE] proof (prove) using this: game2 = map_spmf fst game2_a goal (1 subgoal): 1. game2 = map_spmf fst game2_a [PROOF STEP] . [PROOF STATE] proof (state) this: game2 = map_spmf fst game2_a goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "map_spmf snd game2_a = map_spmf snd game2_b" [PROOF STATE] proof (prove) goal (1 subgoal): 1. map_spmf snd game2_a = map_spmf snd game2_b [PROOF STEP] unfolding game2_a_def game2_b_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. map_spmf snd (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). let bad = r \<in> dom s1 in if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad))))) = map_spmf snd (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). let bad = r \<in> dom s1 in if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) (s1(r \<mapsto> pad)) \<bind> (\<lambda>(b', s3). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad))))) [PROOF STEP] by(auto simp add: o_def Let_def split_def if_distribs weight2 split: option.split intro: bind_spmf_cong[OF refl]) [PROOF STATE] proof (state) this: map_spmf snd game2_a = map_spmf snd game2_b goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] moreover [PROOF STATE] proof (state) this: map_spmf snd game2_a = map_spmf snd game2_b goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "rel_spmf (=) (map_spmf fst (game2_a \<upharpoonleft> (snd -` {False}))) (map_spmf fst (game2_b \<upharpoonleft> (snd -` {False})))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf fst (game2_a \<upharpoonleft> (snd -` {False}))) (map_spmf fst (game2_b \<upharpoonleft> (snd -` {False}))) [PROOF STEP] unfolding game2_a_def game2_b_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf fst ((spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). let bad = r \<in> dom s1 in if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad))))) \<upharpoonleft> (snd -` {False}))) (map_spmf fst ((spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). let bad = r \<in> dom s1 in if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) (s1(r \<mapsto> pad)) \<bind> (\<lambda>(b', s3). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad))))) \<upharpoonleft> (snd -` {False}))) [PROOF STEP] by(clarsimp simp add: restrict_bind_spmf o_def Let_def if_distribs split_def restrict_return_spmf prf.random_oracle_def intro!: rel_spmf_bind_reflI split: option.splits) [PROOF STATE] proof (state) this: rel_spmf (=) (map_spmf fst (game2_a \<upharpoonleft> (snd -` {False}))) (map_spmf fst (game2_b \<upharpoonleft> (snd -` {False}))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] hence "spmf game2_a (True, False) = spmf game2_b (True, False)" [PROOF STATE] proof (prove) using this: rel_spmf (=) (map_spmf fst (game2_a \<upharpoonleft> (snd -` {False}))) (map_spmf fst (game2_b \<upharpoonleft> (snd -` {False}))) goal (1 subgoal): 1. spmf game2_a (True, False) = spmf game2_b (True, False) [PROOF STEP] unfolding spmf_rel_eq [PROOF STATE] proof (prove) using this: map_spmf fst (game2_a \<upharpoonleft> (snd -` {False})) = map_spmf fst (game2_b \<upharpoonleft> (snd -` {False})) goal (1 subgoal): 1. spmf game2_a (True, False) = spmf game2_b (True, False) [PROOF STEP] by(subst (1 2) spmf_map_restrict[symmetric]) simp [PROOF STATE] proof (state) this: spmf game2_a (True, False) = spmf game2_b (True, False) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: map_spmf snd game2_a = map_spmf snd game2_b spmf game2_a (True, False) = spmf game2_b (True, False) [PROOF STEP] have game2a_2b: "\<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> \<le> spmf (map_spmf snd game2_a) True" [PROOF STATE] proof (prove) using this: map_spmf snd game2_a = map_spmf snd game2_b spmf game2_a (True, False) = spmf game2_b (True, False) goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> \<le> spmf (map_spmf snd game2_a) True [PROOF STEP] by(subst (1 2) spmf_conv_measure_spmf)(rule identical_until_bad; simp add: spmf.map_id[unfolded id_def] spmf_conv_measure_spmf) [PROOF STATE] proof (state) this: \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> \<le> spmf (map_spmf snd game2_a) True goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define game2_a_bad where "game2_a_bad = do { r \<leftarrow> spmf_of_set (nlists UNIV len); (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; return_spmf (r \<in> dom s1) }" [PROOF STATE] proof (state) this: game2_a_bad = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). return_spmf (r \<in> dom s1))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have game2a_bad: "map_spmf snd game2_a = game2_a_bad" [PROOF STATE] proof (prove) goal (1 subgoal): 1. map_spmf snd game2_a = game2_a_bad [PROOF STEP] unfolding game2_a_def game2_a_bad_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. map_spmf snd (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). let bad = r \<in> dom s1 in if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in prf.random_oracle s1 r \<bind> (\<lambda>(pad, s2). let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s2 \<bind> (\<lambda>(b', s3). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, bad))))) = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). return_spmf (r \<in> dom s1))) [PROOF STEP] by(auto intro!: bind_spmf_cong[OF refl] simp add: o_def weight2 Let_def split_def split: if_split) [PROOF STATE] proof (state) this: map_spmf snd game2_a = game2_a_bad goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have card: "\<And>B :: bool list set. card (B \<inter> nlists UNIV len) \<le> card (nlists UNIV len :: bool list set)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>B. card (B \<inter> nlists UNIV len) \<le> card (nlists UNIV len) [PROOF STEP] by(rule card_mono) simp_all [PROOF STATE] proof (state) this: card (?B7 \<inter> nlists UNIV len) \<le> card (nlists UNIV len) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] then [PROOF STATE] proof (chain) picking this: card (?B7 \<inter> nlists UNIV len) \<le> card (nlists UNIV len) [PROOF STEP] have "spmf game2_a_bad True = \<integral>\<^sup>+ x. card (dom (snd x) \<inter> nlists UNIV len) / 2 ^ len \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty)" [PROOF STATE] proof (prove) using this: card (?B7 \<inter> nlists UNIV len) \<le> card (nlists UNIV len) goal (1 subgoal): 1. ennreal (spmf game2_a_bad True) = \<integral>\<^sup>+ x. ennreal (real (card (dom (snd x) \<inter> nlists UNIV len)) / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) [PROOF STEP] unfolding game2_a_bad_def [PROOF STATE] proof (prove) using this: card (?B7 \<inter> nlists UNIV len) \<le> card (nlists UNIV len) goal (1 subgoal): 1. ennreal (spmf (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). return_spmf (r \<in> dom s1)))) True) = \<integral>\<^sup>+ x. ennreal (real (card (dom (snd x) \<inter> nlists UNIV len)) / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) [PROOF STEP] by(rewrite bind_commute_spmf)(simp add: ennreal_spmf_bind split_def map_mem_spmf_of_set[unfolded map_spmf_conv_bind_spmf] card_nlists) [PROOF STATE] proof (state) this: ennreal (spmf game2_a_bad True) = \<integral>\<^sup>+ x. ennreal (real (card (dom (snd x) \<inter> nlists UNIV len)) / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: ennreal (spmf game2_a_bad True) = \<integral>\<^sup>+ x. ennreal (real (card (dom (snd x) \<inter> nlists UNIV len)) / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] { [PROOF STATE] proof (state) this: ennreal (spmf game2_a_bad True) = \<integral>\<^sup>+ x. ennreal (real (card (dom (snd x) \<inter> nlists UNIV len)) / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] fix x s [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] assume *: "(x, s) \<in> set_spmf (exec_gpv rf_encrypt \<A>1 Map.empty)" [PROOF STATE] proof (state) this: (x, s) \<in> set_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] hence "finite (dom s)" [PROOF STATE] proof (prove) using this: (x, s) \<in> set_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. finite (dom s) [PROOF STEP] by(rule rf_finite.exec_gpv_invariant) simp_all [PROOF STATE] proof (state) this: finite (dom s) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] hence 1: "card (dom s \<inter> nlists UNIV len) \<le> card (dom s)" [PROOF STATE] proof (prove) using this: finite (dom s) goal (1 subgoal): 1. card (dom s \<inter> nlists UNIV len) \<le> card (dom s) [PROOF STEP] by(intro card_mono) simp_all [PROOF STATE] proof (state) this: card (dom s \<inter> nlists UNIV len) \<le> card (dom s) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] moreover [PROOF STATE] proof (state) this: card (dom s \<inter> nlists UNIV len) \<le> card (dom s) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] from q1 * [PROOF STATE] proof (chain) picking this: interaction_bounded_by' (\<lambda>_. True) \<A>1 q1 (x, s) \<in> set_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) [PROOF STEP] have "card (dom s) \<le> q1 + card (dom (Map.empty :: (plain, plain) prf.dict))" [PROOF STATE] proof (prove) using this: interaction_bounded_by' (\<lambda>_. True) \<A>1 q1 (x, s) \<in> set_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. card (dom s) \<le> q1 + card (dom Map.empty) [PROOF STEP] by(rule rf_finite.interaction_bounded_by'_exec_gpv_count) (auto simp add: rf_encrypt_def eSuc_enat prf.random_oracle_def card_insert_if split: option.split_asm if_split) [PROOF STATE] proof (state) this: card (dom s) \<le> q1 + card (dom Map.empty) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: card (dom s \<inter> nlists UNIV len) \<le> card (dom s) card (dom s) \<le> q1 + card (dom Map.empty) [PROOF STEP] have "card (dom s \<inter> nlists UNIV len) \<le> q1" [PROOF STATE] proof (prove) using this: card (dom s \<inter> nlists UNIV len) \<le> card (dom s) card (dom s) \<le> q1 + card (dom Map.empty) goal (1 subgoal): 1. card (dom s \<inter> nlists UNIV len) \<le> q1 [PROOF STEP] by(simp) [PROOF STATE] proof (state) this: card (dom s \<inter> nlists UNIV len) \<le> q1 goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] } [PROOF STATE] proof (state) this: (?x9, ?s9) \<in> set_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<Longrightarrow> card (dom ?s9 \<inter> nlists UNIV len) \<le> q1 goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] then [PROOF STATE] proof (chain) picking this: (?x9, ?s9) \<in> set_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<Longrightarrow> card (dom ?s9 \<inter> nlists UNIV len) \<le> q1 [PROOF STEP] have "\<dots> \<le> \<integral>\<^sup>+ x. q1 / 2 ^ len \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty)" [PROOF STATE] proof (prove) using this: (?x9, ?s9) \<in> set_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<Longrightarrow> card (dom ?s9 \<inter> nlists UNIV len) \<le> q1 goal (1 subgoal): 1. \<integral>\<^sup>+ x. ennreal (real (card (dom (snd x) \<inter> nlists UNIV len)) / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<le> \<integral>\<^sup>+ x. ennreal (real q1 / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) [PROOF STEP] by(intro nn_integral_mono_AE)(clarsimp simp add: field_simps) [PROOF STATE] proof (state) this: \<integral>\<^sup>+ x. ennreal (real (card (dom (snd x) \<inter> nlists UNIV len)) / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<le> \<integral>\<^sup>+ x. ennreal (real q1 / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: \<integral>\<^sup>+ x. ennreal (real (card (dom (snd x) \<inter> nlists UNIV len)) / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<le> \<integral>\<^sup>+ x. ennreal (real q1 / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> \<le> q1 / 2 ^ len" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<integral>\<^sup>+ x. ennreal (real q1 / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<le> ennreal (real q1 / 2 ^ len) [PROOF STEP] by(simp add: measure_spmf.emeasure_eq_measure field_simps mult_left_le weight1) [PROOF STATE] proof (state) this: \<integral>\<^sup>+ x. ennreal (real q1 / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<le> ennreal (real q1 / 2 ^ len) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: ennreal (spmf game2_a_bad True) \<le> ennreal (real q1 / 2 ^ len) [PROOF STEP] have game2a_bad_bound: "spmf game2_a_bad True \<le> q1 / 2 ^ len" [PROOF STATE] proof (prove) using this: ennreal (spmf game2_a_bad True) \<le> ennreal (real q1 / 2 ^ len) goal (1 subgoal): 1. spmf game2_a_bad True \<le> real q1 / 2 ^ len [PROOF STEP] by simp [PROOF STATE] proof (state) this: spmf game2_a_bad True \<le> real q1 / 2 ^ len goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define rf_encrypt_bad where "rf_encrypt_bad = (\<lambda>secret (s :: (plain, plain) prf.dict, bad) plain. bind_spmf (spmf_of_set (nlists UNIV len)) (\<lambda>r. bind_spmf (prf.random_oracle s r) (\<lambda>(pad, s'). return_spmf ((r, xor_list plain pad), (s', bad \<or> r = secret)))))" [PROOF STATE] proof (state) this: rf_encrypt_bad = (\<lambda>secret (s, bad) plain. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. prf.random_oracle s r \<bind> (\<lambda>(pad, s'). return_spmf ((r, plain [\<oplus>] pad), s', bad \<or> r = secret)))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have rf_encrypt_bad_sticky [simp]: "\<And>s. callee_invariant (rf_encrypt_bad s) snd" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>s. callee_invariant (rf_encrypt_bad s) snd [PROOF STEP] by(unfold_locales)(auto simp add: rf_encrypt_bad_def) [PROOF STATE] proof (state) this: callee_invariant (rf_encrypt_bad ?s7) snd goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have lossless_rf_encrypt [simp]: "\<And>challenge s plain. lossless_spmf (rf_encrypt_bad challenge s plain)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>challenge s plain. lossless_spmf (rf_encrypt_bad challenge s plain) [PROOF STEP] by(clarsimp simp add: rf_encrypt_bad_def prf.random_oracle_def split: option.split) [PROOF STATE] proof (state) this: lossless_spmf (rf_encrypt_bad ?challenge7 ?s7 ?plain7) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define game2_c where "game2_c = do { r \<leftarrow> spmf_of_set (nlists UNIV len); (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); pad \<leftarrow> spmf_of_set (nlists UNIV len); let cipher = (r, xor_list pb pad); (b', (s2, bad)) \<leftarrow> exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s1(r \<mapsto> pad), False); return_spmf (b' = b, bad) } else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False)) }" [PROOF STATE] proof (state) this: game2_c = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s1(r \<mapsto> pad), False) \<bind> (\<lambda>(b', s2, bad). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False)))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have bisim2c_bad: "\<And>cipher \<sigma> s x r. rel_spmf (\<lambda>(x, _) (y, _). x = y) (exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) (s(x \<mapsto> r))) (exec_gpv (rf_encrypt_bad x) (\<A>2 cipher \<sigma>) (s(x \<mapsto> r), False))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>cipher \<sigma> s x r. rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) (s(x \<mapsto> r))) (exec_gpv (rf_encrypt_bad x) (\<A>2 cipher \<sigma>) (s(x \<mapsto> r), False)) [PROOF STEP] by(rule exec_gpv_oracle_bisim[where X="\<lambda>s (s', _). s = s'"]) (auto simp add: rf_encrypt_bad_def rf_encrypt_def intro!: rel_spmf_bind_reflI) [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv rf_encrypt (\<A>2 ?cipher7 ?\<sigma>7) (?s7(?x7 \<mapsto> ?r7))) (exec_gpv (rf_encrypt_bad ?x7) (\<A>2 ?cipher7 ?\<sigma>7) (?s7(?x7 \<mapsto> ?r7), False)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have game2b_c [unfolded spmf_rel_eq]: "rel_spmf (=) (map_spmf fst game2_b) (map_spmf fst game2_c)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf fst game2_b) (map_spmf fst game2_c) [PROOF STEP] by(auto simp add: game2_b_def game2_c_def o_def split_def Let_def if_distribs intro!: rel_spmf_bind_reflI rel_spmf_bindI[OF bisim2c_bad]) [PROOF STATE] proof (state) this: map_spmf fst game2_b = map_spmf fst game2_c goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define game2_d where "game2_d = do { r \<leftarrow> spmf_of_set (nlists UNIV len); (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); pad \<leftarrow> spmf_of_set (nlists UNIV len); let cipher = (r, xor_list pb pad); (b', (s2, bad)) \<leftarrow> exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s1, False); return_spmf (b' = b, bad) } else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False)) }" [PROOF STATE] proof (state) this: game2_d = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s1, False) \<bind> (\<lambda>(b', s2, bad). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False)))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] { [PROOF STATE] proof (state) this: game2_d = spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s1, False) \<bind> (\<lambda>(b', s2, bad). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False)))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] fix cipher \<sigma> and x :: plain and s r [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] let ?I = "(\<lambda>(x, s, bad) (y, s', bad'). (bad \<longleftrightarrow> bad') \<and> (\<not> bad' \<longrightarrow> x \<longleftrightarrow> y))" [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] let ?X = "\<lambda>(s, bad) (s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)" [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<And>s1 s2 x'. ?X s1 s2 \<Longrightarrow> rel_spmf (\<lambda>(a, s1') (b, s2'). snd s1' = snd s2' \<and> (\<not> snd s2' \<longrightarrow> a = b \<and> ?X s1' s2')) (rf_encrypt_bad x s1 x') (rf_encrypt_bad x s2 x')" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>s1 s2 x'. (case s1 of (s, bad) \<Rightarrow> \<lambda>(s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)) s2 \<Longrightarrow> rel_spmf (\<lambda>(a, s1') (b, s2'). snd s1' = snd s2' \<and> (\<not> snd s2' \<longrightarrow> a = b \<and> (case s1' of (s, bad) \<Rightarrow> \<lambda>(s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)) s2')) (rf_encrypt_bad x s1 x') (rf_encrypt_bad x s2 x') [PROOF STEP] by(case_tac "x = x'")(clarsimp simp add: rf_encrypt_bad_def prf.random_oracle_def rel_spmf_return_spmf1 rel_spmf_return_spmf2 Let_def split_def bind_UNION intro!: rel_spmf_bind_reflI split: option.split)+ [PROOF STATE] proof (state) this: (case ?s1.9 of (s, bad) \<Rightarrow> \<lambda>(s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)) ?s2.9 \<Longrightarrow> rel_spmf (\<lambda>(a, s1') (b, s2'). snd s1' = snd s2' \<and> (\<not> snd s2' \<longrightarrow> a = b \<and> (case s1' of (s, bad) \<Rightarrow> \<lambda>(s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)) s2')) (rf_encrypt_bad x ?s1.9 ?x'9) (rf_encrypt_bad x ?s2.9 ?x'9) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] with _ _ [PROOF STATE] proof (chain) picking this: PROP ?psi \<Longrightarrow> PROP ?psi PROP ?psi \<Longrightarrow> PROP ?psi (case ?s1.9 of (s, bad) \<Rightarrow> \<lambda>(s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)) ?s2.9 \<Longrightarrow> rel_spmf (\<lambda>(a, s1') (b, s2'). snd s1' = snd s2' \<and> (\<not> snd s2' \<longrightarrow> a = b \<and> (case s1' of (s, bad) \<Rightarrow> \<lambda>(s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)) s2')) (rf_encrypt_bad x ?s1.9 ?x'9) (rf_encrypt_bad x ?s2.9 ?x'9) [PROOF STEP] have "rel_spmf ?I (exec_gpv (rf_encrypt_bad x) (\<A>2 cipher \<sigma>) (s(x \<mapsto> r), False)) (exec_gpv (rf_encrypt_bad x) (\<A>2 cipher \<sigma>) (s, False))" [PROOF STATE] proof (prove) using this: PROP ?psi \<Longrightarrow> PROP ?psi PROP ?psi \<Longrightarrow> PROP ?psi (case ?s1.9 of (s, bad) \<Rightarrow> \<lambda>(s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)) ?s2.9 \<Longrightarrow> rel_spmf (\<lambda>(a, s1') (b, s2'). snd s1' = snd s2' \<and> (\<not> snd s2' \<longrightarrow> a = b \<and> (case s1' of (s, bad) \<Rightarrow> \<lambda>(s', bad'). bad = bad' \<and> (\<forall>z. z \<noteq> x \<longrightarrow> s z = s' z)) s2')) (rf_encrypt_bad x ?s1.9 ?x'9) (rf_encrypt_bad x ?s2.9 ?x'9) goal (1 subgoal): 1. rel_spmf (\<lambda>(x, s, bad) (y, s', bad'). bad = bad' \<and> (\<not> bad' \<longrightarrow> x = y)) (exec_gpv (rf_encrypt_bad x) (\<A>2 cipher \<sigma>) (s(x \<mapsto> r), False)) (exec_gpv (rf_encrypt_bad x) (\<A>2 cipher \<sigma>) (s, False)) [PROOF STEP] by(rule exec_gpv_oracle_bisim_bad_full)(auto simp add: lossless2) [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, s, bad) (y, s', bad'). bad = bad' \<and> (\<not> bad' \<longrightarrow> x = y)) (exec_gpv (rf_encrypt_bad x) (\<A>2 cipher \<sigma>) (s(x \<mapsto> r), False)) (exec_gpv (rf_encrypt_bad x) (\<A>2 cipher \<sigma>) (s, False)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] } [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, s, bad) (y, s', bad'). bad = bad' \<and> (\<not> bad' \<longrightarrow> x = y)) (exec_gpv (rf_encrypt_bad ?x9) (\<A>2 ?cipher9 ?\<sigma>9) (?s9(?x9 \<mapsto> ?r9), False)) (exec_gpv (rf_encrypt_bad ?x9) (\<A>2 ?cipher9 ?\<sigma>9) (?s9, False)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] note bisim_bad = this [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, s, bad) (y, s', bad'). bad = bad' \<and> (\<not> bad' \<longrightarrow> x = y)) (exec_gpv (rf_encrypt_bad ?x9) (\<A>2 ?cipher9 ?\<sigma>9) (?s9(?x9 \<mapsto> ?r9), False)) (exec_gpv (rf_encrypt_bad ?x9) (\<A>2 ?cipher9 ?\<sigma>9) (?s9, False)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have game2c_2d_bad [unfolded spmf_rel_eq]: "rel_spmf (=) (map_spmf snd game2_c) (map_spmf snd game2_d)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf snd game2_c) (map_spmf snd game2_d) [PROOF STEP] by(auto simp add: game2_c_def game2_d_def o_def Let_def split_def if_distribs intro!: rel_spmf_bind_reflI rel_spmf_bindI[OF bisim_bad]) [PROOF STATE] proof (state) this: map_spmf snd game2_c = map_spmf snd game2_d goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] moreover [PROOF STATE] proof (state) this: map_spmf snd game2_c = map_spmf snd game2_d goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "rel_spmf (=) (map_spmf fst (game2_c \<upharpoonleft> (snd -` {False}))) (map_spmf fst (game2_d \<upharpoonleft> (snd -` {False})))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf fst (game2_c \<upharpoonleft> (snd -` {False}))) (map_spmf fst (game2_d \<upharpoonleft> (snd -` {False}))) [PROOF STEP] unfolding game2_c_def game2_d_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf fst ((spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s1(r \<mapsto> pad), False) \<bind> (\<lambda>(b', s2, bad). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False))))) \<upharpoonleft> (snd -` {False}))) (map_spmf fst ((spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s1, False) \<bind> (\<lambda>(b', s2, bad). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False))))) \<upharpoonleft> (snd -` {False}))) [PROOF STEP] by(clarsimp simp add: restrict_bind_spmf o_def Let_def if_distribs split_def restrict_return_spmf intro!: rel_spmf_bind_reflI rel_spmf_bindI[OF bisim_bad]) [PROOF STATE] proof (state) this: rel_spmf (=) (map_spmf fst (game2_c \<upharpoonleft> (snd -` {False}))) (map_spmf fst (game2_d \<upharpoonleft> (snd -` {False}))) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] hence "spmf game2_c (True, False) = spmf game2_d (True, False)" [PROOF STATE] proof (prove) using this: rel_spmf (=) (map_spmf fst (game2_c \<upharpoonleft> (snd -` {False}))) (map_spmf fst (game2_d \<upharpoonleft> (snd -` {False}))) goal (1 subgoal): 1. spmf game2_c (True, False) = spmf game2_d (True, False) [PROOF STEP] unfolding spmf_rel_eq [PROOF STATE] proof (prove) using this: map_spmf fst (game2_c \<upharpoonleft> (snd -` {False})) = map_spmf fst (game2_d \<upharpoonleft> (snd -` {False})) goal (1 subgoal): 1. spmf game2_c (True, False) = spmf game2_d (True, False) [PROOF STEP] by(subst (1 2) spmf_map_restrict[symmetric]) simp [PROOF STATE] proof (state) this: spmf game2_c (True, False) = spmf game2_d (True, False) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: map_spmf snd game2_c = map_spmf snd game2_d spmf game2_c (True, False) = spmf game2_d (True, False) [PROOF STEP] have game2c_2d: "\<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> \<le> spmf (map_spmf snd game2_c) True" [PROOF STATE] proof (prove) using this: map_spmf snd game2_c = map_spmf snd game2_d spmf game2_c (True, False) = spmf game2_d (True, False) goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> \<le> spmf (map_spmf snd game2_c) True [PROOF STEP] apply(subst (1 2) spmf_conv_measure_spmf) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>map_spmf snd game2_c = map_spmf snd game2_d; spmf game2_c (True, False) = spmf game2_d (True, False)\<rbrakk> \<Longrightarrow> \<bar>Sigma_Algebra.measure (measure_spmf (map_spmf fst game2_c)) {True} - Sigma_Algebra.measure (measure_spmf (map_spmf fst game2_d)) {True}\<bar> \<le> spmf (map_spmf snd game2_c) True [PROOF STEP] apply(intro identical_until_bad) [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<lbrakk>map_spmf snd game2_c = map_spmf snd game2_d; spmf game2_c (True, False) = spmf game2_d (True, False)\<rbrakk> \<Longrightarrow> map_spmf snd game2_c = map_spmf snd game2_d 2. \<lbrakk>map_spmf snd game2_c = map_spmf snd game2_d; spmf game2_c (True, False) = spmf game2_d (True, False)\<rbrakk> \<Longrightarrow> Sigma_Algebra.measure (measure_spmf (map_spmf (\<lambda>x. (fst x, snd x)) game2_c)) ({True} \<times> {False}) = Sigma_Algebra.measure (measure_spmf (map_spmf (\<lambda>x. (fst x, snd x)) game2_d)) ({True} \<times> {False}) [PROOF STEP] apply(simp_all add: spmf.map_id[unfolded id_def] spmf_conv_measure_spmf) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done [PROOF STATE] proof (state) this: \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> \<le> spmf (map_spmf snd game2_c) True goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] { [PROOF STATE] proof (state) this: \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> \<le> spmf (map_spmf snd game2_c) True goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] fix cipher \<sigma> and challenge :: plain and s [PROOF STATE] proof (state) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "card (nlists UNIV len \<inter> (\<lambda>x. x = challenge) -` {True}) \<le> card {challenge}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. card (nlists UNIV len \<inter> (\<lambda>x. x = challenge) -` {True}) \<le> card {challenge} [PROOF STEP] by(rule card_mono) auto [PROOF STATE] proof (state) this: card (nlists UNIV len \<inter> (\<lambda>x. x = challenge) -` {True}) \<le> card {challenge} goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] then [PROOF STATE] proof (chain) picking this: card (nlists UNIV len \<inter> (\<lambda>x. x = challenge) -` {True}) \<le> card {challenge} [PROOF STEP] have "spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad challenge) (\<A>2 cipher \<sigma>) (s, False))) True \<le> (1 / 2 ^ len) * q2" [PROOF STATE] proof (prove) using this: card (nlists UNIV len \<inter> (\<lambda>x. x = challenge) -` {True}) \<le> card {challenge} goal (1 subgoal): 1. spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad challenge) (\<A>2 cipher \<sigma>) (s, False))) True \<le> 1 / 2 ^ len * real q2 [PROOF STEP] by(intro oi_True.interaction_bounded_by_exec_gpv_bad[OF q2])(simp_all add: rf_encrypt_bad_def o_def split_beta map_spmf_conv_bind_spmf[symmetric] spmf_map measure_spmf_of_set field_simps card_nlists) [PROOF STATE] proof (state) this: spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad challenge) (\<A>2 cipher \<sigma>) (s, False))) True \<le> 1 / 2 ^ len * real q2 goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] hence "(\<integral>\<^sup>+ x. ennreal (indicator {True} x) \<partial>measure_spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad challenge) (\<A>2 cipher \<sigma>) (s, False)))) \<le> (1 / 2 ^ len) * q2" [PROOF STATE] proof (prove) using this: spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad challenge) (\<A>2 cipher \<sigma>) (s, False))) True \<le> 1 / 2 ^ len * real q2 goal (1 subgoal): 1. \<integral>\<^sup>+ x. ennreal (indicat_real {True} x) \<partial>measure_spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad challenge) (\<A>2 cipher \<sigma>) (s, False))) \<le> ennreal (1 / 2 ^ len * real q2) [PROOF STEP] by(simp only: ennreal_indicator nn_integral_indicator sets_measure_spmf sets_count_space Pow_UNIV UNIV_I emeasure_spmf_single) simp [PROOF STATE] proof (state) this: \<integral>\<^sup>+ x. ennreal (indicat_real {True} x) \<partial>measure_spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad challenge) (\<A>2 cipher \<sigma>) (s, False))) \<le> ennreal (1 / 2 ^ len * real q2) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] } [PROOF STATE] proof (state) this: \<integral>\<^sup>+ x. ennreal (indicat_real {True} x) \<partial>measure_spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad ?challenge9) (\<A>2 ?cipher9 ?\<sigma>9) (?s9, False))) \<le> ennreal (1 / 2 ^ len * real q2) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] then [PROOF STATE] proof (chain) picking this: \<integral>\<^sup>+ x. ennreal (indicat_real {True} x) \<partial>measure_spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad ?challenge9) (\<A>2 ?cipher9 ?\<sigma>9) (?s9, False))) \<le> ennreal (1 / 2 ^ len * real q2) [PROOF STEP] have "spmf (map_spmf snd game2_d) True \<le> \<integral>\<^sup>+ (r :: plain). \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then \<integral>\<^sup>+ b . \<integral>\<^sup>+ (pad :: plain). q2 / 2 ^ len \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len))" [PROOF STATE] proof (prove) using this: \<integral>\<^sup>+ x. ennreal (indicat_real {True} x) \<partial>measure_spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad ?challenge9) (\<A>2 ?cipher9 ?\<sigma>9) (?s9, False))) \<le> ennreal (1 / 2 ^ len * real q2) goal (1 subgoal): 1. ennreal (spmf (map_spmf snd game2_d) True) \<le> \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then \<integral>\<^sup>+ b. \<integral>\<^sup>+ x. ennreal (real q2 / 2 ^ len) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) [PROOF STEP] unfolding game2_d_def [PROOF STATE] proof (prove) using this: \<integral>\<^sup>+ x. ennreal (indicat_real {True} x) \<partial>measure_spmf (map_spmf (snd \<circ> snd) (exec_gpv (rf_encrypt_bad ?challenge9) (\<A>2 ?cipher9 ?\<sigma>9) (?s9, False))) \<le> ennreal (1 / 2 ^ len * real q2) goal (1 subgoal): 1. ennreal (spmf (map_spmf snd (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s1, False) \<bind> (\<lambda>(b', s2, bad). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False)))))) True) \<le> \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then \<integral>\<^sup>+ b. \<integral>\<^sup>+ x. ennreal (real q2 / 2 ^ len) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) [PROOF STEP] by(simp add: ennreal_spmf_bind o_def split_def Let_def if_distribs if_distrib[where f="\<lambda>x. ennreal (spmf x _)"] indicator_single_Some nn_integral_mono if_mono_cong del: nn_integral_const cong: if_cong) [PROOF STATE] proof (state) this: ennreal (spmf (map_spmf snd game2_d) True) \<le> \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then \<integral>\<^sup>+ b. \<integral>\<^sup>+ x. ennreal (real q2 / 2 ^ len) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: ennreal (spmf (map_spmf snd game2_d) True) \<le> \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then \<integral>\<^sup>+ b. \<integral>\<^sup>+ x. ennreal (real q2 / 2 ^ len) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> \<le> \<integral>\<^sup>+ (r :: plain). \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then ennreal (q2 / 2 ^ len) else q2 / 2 ^ len) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then \<integral>\<^sup>+ b. \<integral>\<^sup>+ x. ennreal (real q2 / 2 ^ len) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<le> \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then ennreal (real q2 / 2 ^ len) else ennreal (real q2 / 2 ^ len)) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) [PROOF STEP] unfolding split_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<integral>\<^sup>+ r. \<integral>\<^sup>+ p. (if valid_plain (fst (fst (fst p))) \<and> valid_plain (snd (fst (fst p))) then \<integral>\<^sup>+ b. \<integral>\<^sup>+ x. ennreal (real q2 / 2 ^ len) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<le> \<integral>\<^sup>+ r. \<integral>\<^sup>+ p. (if valid_plain (fst (fst (fst p))) \<and> valid_plain (snd (fst (fst p))) then ennreal (real q2 / 2 ^ len) else ennreal (real q2 / 2 ^ len)) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) [PROOF STEP] by(intro nn_integral_mono if_mono_cong)(auto simp add: measure_spmf.emeasure_eq_measure) [PROOF STATE] proof (state) this: \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then \<integral>\<^sup>+ b. \<integral>\<^sup>+ x. ennreal (real q2 / 2 ^ len) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<le> \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then ennreal (real q2 / 2 ^ len) else ennreal (real q2 / 2 ^ len)) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then \<integral>\<^sup>+ b. \<integral>\<^sup>+ x. ennreal (real q2 / 2 ^ len) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<partial>measure_spmf coin_spmf else 0) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<le> \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then ennreal (real q2 / 2 ^ len) else ennreal (real q2 / 2 ^ len)) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> \<le> q2 / 2 ^ len" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then ennreal (real q2 / 2 ^ len) else ennreal (real q2 / 2 ^ len)) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<le> ennreal (real q2 / 2 ^ len) [PROOF STEP] by(simp add: split_def weight1 measure_spmf.emeasure_eq_measure) [PROOF STATE] proof (state) this: \<integral>\<^sup>+ r. \<integral>\<^sup>+ (((p0, p1), \<sigma>), s). (if valid_plain p0 \<and> valid_plain p1 then ennreal (real q2 / 2 ^ len) else ennreal (real q2 / 2 ^ len)) \<partial>measure_spmf (exec_gpv rf_encrypt \<A>1 Map.empty) \<partial>measure_spmf (spmf_of_set (nlists UNIV len)) \<le> ennreal (real q2 / 2 ^ len) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: ennreal (spmf (map_spmf snd game2_d) True) \<le> ennreal (real q2 / 2 ^ len) [PROOF STEP] have game2_d_bad: "spmf (map_spmf snd game2_d) True \<le> q2 / 2 ^ len" [PROOF STATE] proof (prove) using this: ennreal (spmf (map_spmf snd game2_d) True) \<le> ennreal (real q2 / 2 ^ len) goal (1 subgoal): 1. spmf (map_spmf snd game2_d) True \<le> real q2 / 2 ^ len [PROOF STEP] by simp [PROOF STATE] proof (state) this: spmf (map_spmf snd game2_d) True \<le> real q2 / 2 ^ len goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] define game3 where "game3 = do { (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); r \<leftarrow> spmf_of_set (nlists UNIV len); pad \<leftarrow> spmf_of_set (nlists UNIV len); let cipher = (r, xor_list pb pad); (b', s2) \<leftarrow> exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1; return_spmf (b' = b) } else coin_spmf }" [PROOF STATE] proof (state) this: game3 = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have bisim2d_3: "\<And>cipher \<sigma> s r. rel_spmf (\<lambda>(x, _) (y, _). x = y) (exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s, False)) (exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>cipher \<sigma> s r. rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv (rf_encrypt_bad r) (\<A>2 cipher \<sigma>) (s, False)) (exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s) [PROOF STEP] by(rule exec_gpv_oracle_bisim[where X="\<lambda>(s1, _) s2. s1 = s2"])(auto simp add: rf_encrypt_bad_def rf_encrypt_def intro!: rel_spmf_bind_reflI) [PROOF STATE] proof (state) this: rel_spmf (\<lambda>(x, uu_) (y, uu_). x = y) (exec_gpv (rf_encrypt_bad ?r7) (\<A>2 ?cipher7 ?\<sigma>7) (?s7, False)) (exec_gpv rf_encrypt (\<A>2 ?cipher7 ?\<sigma>7) ?s7) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have game2d_3: "rel_spmf (=) (map_spmf fst game2_d) game3" [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf fst game2_d) game3 [PROOF STEP] unfolding game2_d_def game3_def Let_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf fst (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. exec_gpv (rf_encrypt_bad r) (\<A>2 (r, (if b then p0 else p1) [\<oplus>] pad) \<sigma>) (s1, False) \<bind> (\<lambda>(b', s2, bad). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False)))))) (exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. exec_gpv rf_encrypt (\<A>2 (r, (if b then p0 else p1) [\<oplus>] pad) \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf)) [PROOF STEP] including monad_normalisation [PROOF STATE] proof (prove) goal (1 subgoal): 1. rel_spmf (=) (map_spmf fst (spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. exec_gpv (rf_encrypt_bad r) (\<A>2 (r, (if b then p0 else p1) [\<oplus>] pad) \<sigma>) (s1, False) \<bind> (\<lambda>(b', s2, bad). return_spmf (b' = b, bad)))) else coin_spmf \<bind> (\<lambda>b. return_spmf (b, False)))))) (exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. exec_gpv rf_encrypt (\<A>2 (r, (if b then p0 else p1) [\<oplus>] pad) \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf)) [PROOF STEP] by(clarsimp simp add: o_def split_def if_distribs cong: if_cong intro!: rel_spmf_bind_reflI rel_spmf_bindI[OF bisim2d_3]) [PROOF STATE] proof (state) this: rel_spmf (=) (map_spmf fst game2_d) game3 goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<bar>spmf game2 True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<bar>spmf game2 True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> [PROOF STEP] unfolding game2_2a [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_a) True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> [PROOF STEP] by(rule abs_diff_triangle_ineq2) [PROOF STATE] proof (state) this: \<bar>spmf game2 True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: \<bar>spmf game2 True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> \<le> q1 / 2 ^ len + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> [PROOF STEP] using game2a_2b game2a_bad_bound [PROOF STATE] proof (prove) using this: \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> \<le> spmf (map_spmf snd game2_a) True spmf game2_a_bad True \<le> real q1 / 2 ^ len goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> [PROOF STEP] unfolding game2a_bad [PROOF STATE] proof (prove) using this: \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> \<le> spmf game2_a_bad True spmf game2_a_bad True \<le> real q1 / 2 ^ len goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> [PROOF STEP] by(intro add_right_mono) simp [PROOF STATE] proof (state) this: \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: \<bar>spmf (map_spmf fst game2_a) True - spmf (map_spmf fst game2_b) True\<bar> + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> [PROOF STEP] unfolding game2b_c [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_c) True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> [PROOF STEP] by(rule abs_diff_triangle_ineq2) [PROOF STATE] proof (state) this: \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also (add_left_mono_trans) [PROOF STATE] proof (state) this: \<bar>spmf (map_spmf fst game2_b) True - 1 / 2\<bar> \<le> \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> \<le> q2 / 2 ^ len + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> \<le> real q2 / 2 ^ len + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> [PROOF STEP] using game2c_2d game2_d_bad [PROOF STATE] proof (prove) using this: \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> \<le> spmf (map_spmf snd game2_c) True spmf (map_spmf snd game2_d) True \<le> real q2 / 2 ^ len goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> \<le> real q2 / 2 ^ len + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> [PROOF STEP] unfolding game2c_2d_bad [PROOF STATE] proof (prove) using this: \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> \<le> spmf (map_spmf snd game2_d) True spmf (map_spmf snd game2_d) True \<le> real q2 / 2 ^ len goal (1 subgoal): 1. \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> \<le> real q2 / 2 ^ len + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> [PROOF STEP] by(intro add_right_mono) simp [PROOF STATE] proof (state) this: \<bar>spmf (map_spmf fst game2_c) True - spmf (map_spmf fst game2_d) True\<bar> + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> \<le> real q2 / 2 ^ len + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] finally (add_left_mono_trans) [PROOF STATE] proof (chain) picking this: \<bar>spmf game2 True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + (real q2 / 2 ^ len + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar>) [PROOF STEP] have game2: "\<bar>spmf game2 True - 1 / 2\<bar> \<le> q1 / 2 ^ len + q2 / 2 ^ len + \<bar>spmf game3 True - 1 / 2\<bar>" [PROOF STATE] proof (prove) using this: \<bar>spmf game2 True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + (real q2 / 2 ^ len + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar>) goal (1 subgoal): 1. \<bar>spmf game2 True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + real q2 / 2 ^ len + \<bar>spmf game3 True - 1 / 2\<bar> [PROOF STEP] using game2d_3 [PROOF STATE] proof (prove) using this: \<bar>spmf game2 True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + (real q2 / 2 ^ len + \<bar>spmf (map_spmf fst game2_d) True - 1 / 2\<bar>) rel_spmf (=) (map_spmf fst game2_d) game3 goal (1 subgoal): 1. \<bar>spmf game2 True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + real q2 / 2 ^ len + \<bar>spmf game3 True - 1 / 2\<bar> [PROOF STEP] by(simp add: field_simps spmf_rel_eq) [PROOF STATE] proof (state) this: \<bar>spmf game2 True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + real q2 / 2 ^ len + \<bar>spmf game3 True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "game3 = do { (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); r \<leftarrow> spmf_of_set (nlists UNIV len); pad \<leftarrow> map_spmf (xor_list pb) (spmf_of_set (nlists UNIV len)); let cipher = (r, xor_list pb pad); (b', s2) \<leftarrow> exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1; return_spmf (b' = b) } else coin_spmf }" [PROOF STATE] proof (prove) goal (1 subgoal): 1. game3 = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. map_spmf (([\<oplus>]) pb) (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf) [PROOF STEP] by(simp add: valid_plain_def game3_def Let_def one_time_pad del: bind_map_spmf map_spmf_of_set_inj_on cong: bind_spmf_cong_simp if_cong split: if_split) [PROOF STATE] proof (state) this: game3 = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. map_spmf (([\<oplus>]) pb) (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: game3 = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. map_spmf (([\<oplus>]) pb) (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> = do { (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; if valid_plain p0 \<and> valid_plain p1 then do { b \<leftarrow> coin_spmf; let pb = (if b then p0 else p1); r \<leftarrow> spmf_of_set (nlists UNIV len); pad \<leftarrow> spmf_of_set (nlists UNIV len); let cipher = (r, pad); (b', _) \<leftarrow> exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1; return_spmf (b' = b) } else coin_spmf }" [PROOF STATE] proof (prove) goal (1 subgoal): 1. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. map_spmf (([\<oplus>]) pb) (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf) = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). return_spmf (b' = b))))) else coin_spmf) [PROOF STEP] by(simp add: game3_def Let_def valid_plain_def in_nlists_UNIV cong: bind_spmf_cong_simp if_cong split: if_split) [PROOF STATE] proof (state) this: exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. map_spmf (([\<oplus>]) pb) (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf) = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). return_spmf (b' = b))))) else coin_spmf) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. map_spmf (([\<oplus>]) pb) (spmf_of_set (nlists UNIV len)) \<bind> (\<lambda>pad. let cipher = (r, pb [\<oplus>] pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', s2). return_spmf (b' = b))))) else coin_spmf) = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). return_spmf (b' = b))))) else coin_spmf) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> = do { (((p0, p1), \<sigma>), s1) \<leftarrow> exec_gpv rf_encrypt \<A>1 Map.empty; if valid_plain p0 \<and> valid_plain p1 then do { r \<leftarrow> spmf_of_set (nlists UNIV len); pad \<leftarrow> spmf_of_set (nlists UNIV len); let cipher = (r, pad); (b', _) \<leftarrow> exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1; map_spmf ((=) b') coin_spmf } else coin_spmf }" [PROOF STATE] proof (prove) goal (1 subgoal): 1. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). return_spmf (b' = b))))) else coin_spmf) = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). map_spmf ((=) b') coin_spmf))) else coin_spmf) [PROOF STEP] including monad_normalisation [PROOF STATE] proof (prove) goal (1 subgoal): 1. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). return_spmf (b' = b))))) else coin_spmf) = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). map_spmf ((=) b') coin_spmf))) else coin_spmf) [PROOF STEP] by(simp add: map_spmf_conv_bind_spmf split_def Let_def) [PROOF STATE] proof (state) this: exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). return_spmf (b' = b))))) else coin_spmf) = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). map_spmf ((=) b') coin_spmf))) else coin_spmf) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then coin_spmf \<bind> (\<lambda>b. let pb = if b then p0 else p1 in spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). return_spmf (b' = b))))) else coin_spmf) = exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). map_spmf ((=) b') coin_spmf))) else coin_spmf) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> = coin_spmf" [PROOF STATE] proof (prove) goal (1 subgoal): 1. exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). map_spmf ((=) b') coin_spmf))) else coin_spmf) = coin_spmf [PROOF STEP] by(simp add: map_eq_const_coin_spmf Let_def split_def weight2 weight1) [PROOF STATE] proof (state) this: exec_gpv rf_encrypt \<A>1 Map.empty \<bind> (\<lambda>(((p0, p1), \<sigma>), s1). if valid_plain p0 \<and> valid_plain p1 then spmf_of_set (nlists UNIV len) \<bind> (\<lambda>r. spmf_of_set (nlists UNIV len) \<bind> (\<lambda>pad. let cipher = (r, pad) in exec_gpv rf_encrypt (\<A>2 cipher \<sigma>) s1 \<bind> (\<lambda>(b', uu_). map_spmf ((=) b') coin_spmf))) else coin_spmf) = coin_spmf goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: game3 = coin_spmf [PROOF STEP] have game3: "game3 = coin_spmf" [PROOF STATE] proof (prove) using this: game3 = coin_spmf goal (1 subgoal): 1. game3 = coin_spmf [PROOF STEP] . [PROOF STATE] proof (state) this: game3 = coin_spmf goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "ind_cpa.advantage \<A> \<le> prf.advantage (prf_adversary \<A>) + \<bar>spmf (prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + \<bar>spmf (local.prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> [PROOF STEP] unfolding ind_cpa.advantage_def prf.advantage_def ind_cpa_0[unfolded spmf_rel_eq] [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<bar>spmf (local.prf.game_0 (prf_adversary \<A>)) True - 1 / 2\<bar> \<le> \<bar>spmf (local.prf.game_0 (prf_adversary \<A>)) True - spmf (local.prf.game_1 (prf_adversary \<A>)) True\<bar> + \<bar>spmf (local.prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> [PROOF STEP] by(rule abs_diff_triangle_ineq2) [PROOF STATE] proof (state) this: local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + \<bar>spmf (local.prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + \<bar>spmf (local.prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<bar>spmf (prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> \<le> q1 / 2 ^ len + q2 / 2 ^ len" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<bar>spmf (local.prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + real q2 / 2 ^ len [PROOF STEP] using game1_2 game2 game3 [PROOF STATE] proof (prove) using this: local.prf.game_1 (prf_adversary \<A>) = game2 \<bar>spmf game2 True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + real q2 / 2 ^ len + \<bar>spmf game3 True - 1 / 2\<bar> game3 = coin_spmf goal (1 subgoal): 1. \<bar>spmf (local.prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + real q2 / 2 ^ len [PROOF STEP] by(simp add: spmf_of_set) [PROOF STATE] proof (state) this: \<bar>spmf (local.prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + real q2 / 2 ^ len goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: \<bar>spmf (local.prf.game_1 (prf_adversary \<A>)) True - 1 / 2\<bar> \<le> real q1 / 2 ^ len + real q2 / 2 ^ len goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> = (q1 + q2) / 2 ^ len" [PROOF STATE] proof (prove) goal (1 subgoal): 1. real q1 / 2 ^ len + real q2 / 2 ^ len = real (q1 + q2) / 2 ^ len [PROOF STEP] by(simp add: field_simps) [PROOF STATE] proof (state) this: real q1 / 2 ^ len + real q2 / 2 ^ len = real (q1 + q2) / 2 ^ len goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] also [PROOF STATE] proof (state) this: real q1 / 2 ^ len + real q2 / 2 ^ len = real (q1 + q2) / 2 ^ len goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] have "\<dots> \<le> q / 2 ^ len" [PROOF STATE] proof (prove) goal (1 subgoal): 1. real (q1 + q2) / 2 ^ len \<le> real q / 2 ^ len [PROOF STEP] using \<open>q1 + q2 \<le> q\<close> [PROOF STATE] proof (prove) using this: q1 + q2 \<le> q goal (1 subgoal): 1. real (q1 + q2) / 2 ^ len \<le> real q / 2 ^ len [PROOF STEP] by(simp add: divide_right_mono) [PROOF STATE] proof (state) this: real (q1 + q2) / 2 ^ len \<le> real q / 2 ^ len goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: \<lbrakk>\<And>x y. x \<le> y \<Longrightarrow> local.prf.advantage (prf_adversary \<A>) + x \<le> local.prf.advantage (prf_adversary \<A>) + y; \<And>x y. x \<le> y \<Longrightarrow> local.prf.advantage (prf_adversary \<A>) + x \<le> local.prf.advantage (prf_adversary \<A>) + y\<rbrakk> \<Longrightarrow> local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: \<lbrakk>\<And>x y. x \<le> y \<Longrightarrow> local.prf.advantage (prf_adversary \<A>) + x \<le> local.prf.advantage (prf_adversary \<A>) + y; \<And>x y. x \<le> y \<Longrightarrow> local.prf.advantage (prf_adversary \<A>) + x \<le> local.prf.advantage (prf_adversary \<A>) + y\<rbrakk> \<Longrightarrow> local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len goal (1 subgoal): 1. local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len [PROOF STEP] by(simp add: field_simps) [PROOF STATE] proof (state) this: local.ind_cpa.advantage \<A> \<le> local.prf.advantage (prf_adversary \<A>) + real q / 2 ^ len goal: No subgoals! [PROOF STEP] qed
using LeastSquaresOptim @test_broken begin println("Use LeastSquaresOptim to fit the parameter") cost_function = build_lsoptim_objective(prob1,t,data,Tsit5(),verbose=false) x = [1.0] res = LeastSquaresOptim.optimize!(LeastSquaresOptim.LeastSquaresProblem(x = x, f! = cost_function, output_length = length(t)*length(prob1.u0)), LeastSquaresOptim.Dogleg(LeastSquaresOptim.LSMR())) @test result.minimizer[1] ≈ 1.5 atol=3e-1 cost_function = build_lsoptim_objective(prob2,t,data,Tsit5(),verbose=false) x = [1.3,2.7] res = LeastSquaresOptim.optimize!(LeastSquaresOptim.LeastSquaresProblem(x = x, f! = cost_function, output_length = length(t)*length(prob2.u0)), LeastSquaresOptim.Dogleg(LeastSquaresOptim.LSMR())) @test res.minimizer ≈ [1.5;3.0] atol=3e-1 cost_function = build_lsoptim_objective(prob3,t,data,Tsit5(),verbose=false) x = [1.3,0.8,2.8,1.2] res = LeastSquaresOptim.optimize!(LeastSquaresOptim.LeastSquaresProblem( x = x, f! = cost_function, output_length = length(t)*length(prob3.u0)), LeastSquaresOptim.Dogleg(LeastSquaresOptim.LSMR())) @test res.minimizer ≈ [1.5;1.0;3.0;1.0] atol=3e-1 end
[STATEMENT] lemma rec_stateT_parametric [transfer_rule]: "(((S ===> M) ===> A) ===> rel_stateT S M ===> A) rec_stateT rec_stateT" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (((S ===> M) ===> A) ===> rel_stateT S M ===> A) rec_stateT rec_stateT [PROOF STEP] apply(rule rel_funI)+ [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>x y xa ya. \<lbrakk>((S ===> M) ===> A) x y; rel_stateT S M xa ya\<rbrakk> \<Longrightarrow> A (rec_stateT x xa) (rec_stateT y ya) [PROOF STEP] subgoal for \<dots> m m' [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>((S ===> M) ===> A) x_ y_; rel_stateT S M m m'\<rbrakk> \<Longrightarrow> A (rec_stateT x_ m) (rec_stateT y_ m') [PROOF STEP] by(cases m; cases m')(auto 4 3 simp add: rel_stateT_def del: rel_funI intro!: rel_funI dest: rel_funD) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
//---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz <[email protected]> // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://boostorg.github.com/compute for more information. //---------------------------------------------------------------------------// #ifndef BOOST_COMPUTE_ALGORITHM_GENERATE_HPP #define BOOST_COMPUTE_ALGORITHM_GENERATE_HPP #include <boost/compute/system.hpp> #include <boost/compute/command_queue.hpp> #include <boost/compute/algorithm/copy.hpp> #include <boost/compute/iterator/function_input_iterator.hpp> #include <boost/compute/detail/iterator_range_size.hpp> namespace boost { namespace compute { /// Stores the result of \p generator for each element in the range /// [\p first, \p last). template<class OutputIterator, class Generator> inline void generate(OutputIterator first, OutputIterator last, Generator generator, command_queue &queue = system::default_queue()) { size_t count = detail::iterator_range_size(first, last); if(count == 0){ return; } ::boost::compute::copy( ::boost::compute::make_function_input_iterator(generator, first.get_index()), ::boost::compute::make_function_input_iterator(generator, last.get_index()), first, queue ); } } // end compute namespace } // end boost namespace #endif // BOOST_COMPUTE_ALGORITHM_GENERATE_HPP
State Before: i j : Nat h : i = 0 ∧ j = 0 ⊢ gcd i j = 0 State After: no goals Tactic: simp [h]
lemma coeff_0 [simp]: "coeff 0 n = 0"
(* * Copyright 2014, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) *) theory breakcontinue imports "../CTranslation" begin declare sep_conj_ac [simp add] install_C_file "breakcontinue.c" context breakcontinue_global_addresses begin thm f_body_def thm g_body_def thm h_body_def thm i_body_def thm dotest_body_def lemma h: "\<Gamma> \<turnstile> \<lbrace> -10 <=s \<acute>e & \<acute>e <s 0 \<rbrace> \<acute>ret__int :== PROC h(\<acute>e) \<lbrace> \<acute>ret__int = \<acute>e \<rbrace>" apply (hoare_rule HoarePartial.ProcNoRec1) apply (hoare_rule HoarePartial.Catch [where R = "\<lbrace> \<acute>ret__int = \<acute>e \<rbrace>"]) defer apply vcg apply (hoare_rule HoarePartial.conseq [where P' = "\<lambda>e. \<lbrace> \<acute>e = e & e <s 0 & -10 <=s e \<rbrace>" and Q' = "\<lambda>e. \<lbrace> \<acute>e = e & \<acute>ret__int = e \<rbrace>" and A' = "\<lambda>e. \<lbrace> \<acute>e = e & \<acute>ret__int = e \<rbrace>"]) defer apply (simp add: subset_iff) apply clarsimp apply (rule_tac R="{}" in HoarePartial.Seq) defer apply vcg apply (rule_tac R="\<lbrace> \<acute>e = Z \<rbrace>" in HoarePartial.Seq) defer apply vcg apply (rule_tac R = "\<lbrace> \<acute>e = Z & \<acute>global_exn_var = Break \<rbrace>" in HoarePartial.Catch) defer apply vcg apply simp apply (rule_tac P' = "\<lbrace> \<acute>e = Z & Z <s 0 & -10 <=s Z \<rbrace>" and Q' = "\<lbrace> \<acute>e = Z & Z <s 0 & -10 <=s Z \<rbrace> \<inter> - \<lbrace> \<acute>e <s 10 \<rbrace>" and A' = "\<lbrace> \<acute>e = Z & \<acute>global_exn_var = Break \<rbrace>" in HoarePartial.conseq_no_aux) defer apply simp apply (simp add: whileAnno_def) apply (rule HoarePartialDef.While) apply vcg apply (simp add: subset_iff) done (* another example where vcg fails, generating impossible sub-goals *) lemma dotest: "\<Gamma> \<turnstile> \<lbrace> \<acute>x = 4 \<rbrace> \<acute>ret__int :== PROC dotest(\<acute>x) \<lbrace> \<acute>ret__int = 4 \<rbrace>" apply (hoare_rule HoarePartial.ProcNoRec1) apply (hoare_rule HoarePartial.Catch [where R="\<lbrace> \<acute>ret__int = 4 \<rbrace>"]) apply (hoare_rule HoarePartial.Seq [where R="{}"]) apply (hoare_rule HoarePartial.Seq [where R="\<lbrace> \<acute>x = 4 \<rbrace>"]) apply (hoare_rule HoarePartial.Catch [where R="\<lbrace> \<acute>x = 4 & \<acute>global_exn_var = Break \<rbrace>"]) apply (hoare_rule HoarePartial.Seq [where R="\<lbrace> False \<rbrace>"]) apply (vcg, simp) apply (hoare_rule HoarePartial.conseq_exploit_pre, simp) apply (vcg, simp) apply vcg apply vcg apply vcg done end end
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes ! This file was ported from Lean 3 source module ring_theory.coprime.basic ! leanprover-community/mathlib commit a95b16cbade0f938fc24abd05412bde1e84bab9b ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathlib.Tactic.Ring import Mathlib.GroupTheory.GroupAction.Units import Mathlib.Algebra.Ring.Divisibility import Mathlib.Algebra.Hom.Ring import Mathlib.Algebra.GroupPower.Ring /-! # Coprime elements of a ring ## Main definitions * `IsCoprime x y`: that `x` and `y` are coprime, defined to be the existence of `a` and `b` such that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime, e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. See also `RingTheory.Coprime.Lemmas` for further development of coprime elements. -/ open Classical universe u v section CommSemiring variable {R : Type u} [CommSemiring R] (x y z : R) /-- The proposition that `x` and `y` are coprime, defined to be the existence of `a` and `b` such that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime, e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. -/ @[simp] def IsCoprime : Prop := ∃ a b, a * x + b * y = 1 #align is_coprime IsCoprime variable {x y z} theorem IsCoprime.symm (H : IsCoprime x y) : IsCoprime y x := let ⟨a, b, H⟩ := H ⟨b, a, by rw [add_comm, H]⟩ #align is_coprime.symm IsCoprime.symm theorem isCoprime_comm : IsCoprime x y ↔ IsCoprime y x := ⟨IsCoprime.symm, IsCoprime.symm⟩ #align is_coprime_comm isCoprime_comm theorem isCoprime_self : IsCoprime x x ↔ IsUnit x := ⟨fun ⟨a, b, h⟩ => isUnit_of_mul_eq_one x (a + b) <| by rwa [mul_comm, add_mul], fun h => let ⟨b, hb⟩ := isUnit_iff_exists_inv'.1 h ⟨b, 0, by rwa [zero_mul, add_zero]⟩⟩ #align is_coprime_self isCoprime_self theorem isCoprime_zero_left : IsCoprime 0 x ↔ IsUnit x := ⟨fun ⟨a, b, H⟩ => isUnit_of_mul_eq_one x b <| by rwa [mul_zero, zero_add, mul_comm] at H, fun H => let ⟨b, hb⟩ := isUnit_iff_exists_inv'.1 H ⟨1, b, by rwa [one_mul, zero_add]⟩⟩ #align is_coprime_zero_left isCoprime_zero_left theorem isCoprime_zero_right : IsCoprime x 0 ↔ IsUnit x := isCoprime_comm.trans isCoprime_zero_left #align is_coprime_zero_right isCoprime_zero_right theorem not_isCoprime_zero_zero [Nontrivial R] : ¬IsCoprime (0 : R) 0 := mt isCoprime_zero_right.mp not_isUnit_zero #align not_coprime_zero_zero not_isCoprime_zero_zero /-- If a 2-vector `p` satisfies `IsCoprime (p 0) (p 1)`, then `p ≠ 0`. -/ theorem IsCoprime.ne_zero [Nontrivial R] {p : Fin 2 → R} (h : IsCoprime (p 0) (p 1)) : p ≠ 0 := by rintro rfl exact not_isCoprime_zero_zero h #align is_coprime.ne_zero IsCoprime.ne_zero theorem isCoprime_one_left : IsCoprime 1 x := ⟨1, 0, by rw [one_mul, zero_mul, add_zero]⟩ #align is_coprime_one_left isCoprime_one_left theorem isCoprime_one_right : IsCoprime x 1 := ⟨0, 1, by rw [one_mul, zero_mul, zero_add]⟩ #align is_coprime_one_right isCoprime_one_right theorem IsCoprime.dvd_of_dvd_mul_right (H1 : IsCoprime x z) (H2 : x ∣ y * z) : x ∣ y := by let ⟨a, b, H⟩ := H1 rw [← mul_one y, ← H, mul_add, ← mul_assoc, mul_left_comm] exact dvd_add (dvd_mul_left _ _) (H2.mul_left _) #align is_coprime.dvd_of_dvd_mul_right IsCoprime.dvd_of_dvd_mul_right theorem IsCoprime.dvd_of_dvd_mul_left (H1 : IsCoprime x y) (H2 : x ∣ y * z) : x ∣ z := by let ⟨a, b, H⟩ := H1 rw [← one_mul z, ← H, add_mul, mul_right_comm, mul_assoc b] exact dvd_add (dvd_mul_left _ _) (H2.mul_left _) #align is_coprime.dvd_of_dvd_mul_left IsCoprime.dvd_of_dvd_mul_left theorem IsCoprime.mul_left (H1 : IsCoprime x z) (H2 : IsCoprime y z) : IsCoprime (x * y) z := let ⟨a, b, h1⟩ := H1 let ⟨c, d, h2⟩ := H2 ⟨a * c, a * x * d + b * c * y + b * d * z, calc a * c * (x * y) + (a * x * d + b * c * y + b * d * z) * z = (a * x + b * z) * (c * y + d * z) := by ring _ = 1 := by rw [h1, h2, mul_one] ⟩ #align is_coprime.mul_left IsCoprime.mul_left theorem IsCoprime.mul_right (H1 : IsCoprime x y) (H2 : IsCoprime x z) : IsCoprime x (y * z) := by rw [isCoprime_comm] at H1 H2⊢ exact H1.mul_left H2 #align is_coprime.mul_right IsCoprime.mul_right theorem IsCoprime.mul_dvd (H : IsCoprime x y) (H1 : x ∣ z) (H2 : y ∣ z) : x * y ∣ z := by obtain ⟨a, b, h⟩ := H rw [← mul_one z, ← h, mul_add] apply dvd_add · rw [mul_comm z, mul_assoc] exact (mul_dvd_mul_left _ H2).mul_left _ · rw [mul_comm b, ← mul_assoc] exact (mul_dvd_mul_right H1 _).mul_right _ #align is_coprime.mul_dvd IsCoprime.mul_dvd theorem IsCoprime.of_mul_left_left (H : IsCoprime (x * y) z) : IsCoprime x z := let ⟨a, b, h⟩ := H ⟨a * y, b, by rwa [mul_right_comm, mul_assoc]⟩ #align is_coprime.of_mul_left_left IsCoprime.of_mul_left_left theorem IsCoprime.of_mul_left_right (H : IsCoprime (x * y) z) : IsCoprime y z := by rw [mul_comm] at H exact H.of_mul_left_left #align is_coprime.of_mul_left_right IsCoprime.of_mul_left_right theorem IsCoprime.of_mul_right_left (H : IsCoprime x (y * z)) : IsCoprime x y := by rw [isCoprime_comm] at H⊢ exact H.of_mul_left_left #align is_coprime.of_mul_right_left IsCoprime.of_mul_right_left theorem IsCoprime.of_mul_right_right (H : IsCoprime x (y * z)) : IsCoprime x z := by rw [mul_comm] at H exact H.of_mul_right_left #align is_coprime.of_mul_right_right IsCoprime.of_mul_right_right theorem IsCoprime.mul_left_iff : IsCoprime (x * y) z ↔ IsCoprime x z ∧ IsCoprime y z := ⟨fun H => ⟨H.of_mul_left_left, H.of_mul_left_right⟩, fun ⟨H1, H2⟩ => H1.mul_left H2⟩ #align is_coprime.mul_left_iff IsCoprime.mul_left_iff theorem IsCoprime.mul_right_iff : IsCoprime x (y * z) ↔ IsCoprime x y ∧ IsCoprime x z := by rw [isCoprime_comm, IsCoprime.mul_left_iff, isCoprime_comm, @isCoprime_comm _ _ z] #align is_coprime.mul_right_iff IsCoprime.mul_right_iff theorem IsCoprime.of_isCoprime_of_dvd_left (h : IsCoprime y z) (hdvd : x ∣ y) : IsCoprime x z := by obtain ⟨d, rfl⟩ := hdvd exact IsCoprime.of_mul_left_left h #align is_coprime.of_coprime_of_dvd_left IsCoprime.of_isCoprime_of_dvd_left theorem IsCoprime.of_isCoprime_of_dvd_right (h : IsCoprime z y) (hdvd : x ∣ y) : IsCoprime z x := (h.symm.of_isCoprime_of_dvd_left hdvd).symm #align is_coprime.of_coprime_of_dvd_right IsCoprime.of_isCoprime_of_dvd_right theorem IsCoprime.isUnit_of_dvd (H : IsCoprime x y) (d : x ∣ y) : IsUnit x := let ⟨k, hk⟩ := d isCoprime_self.1 <| IsCoprime.of_mul_right_left <| show IsCoprime x (x * k) from hk ▸ H #align is_coprime.is_unit_of_dvd IsCoprime.isUnit_of_dvd theorem IsCoprime.isUnit_of_dvd' {a b x : R} (h : IsCoprime a b) (ha : x ∣ a) (hb : x ∣ b) : IsUnit x := (h.of_isCoprime_of_dvd_left ha).isUnit_of_dvd hb #align is_coprime.is_unit_of_dvd' IsCoprime.isUnit_of_dvd' theorem IsCoprime.map (H : IsCoprime x y) {S : Type v} [CommSemiring S] (f : R →+* S) : IsCoprime (f x) (f y) := let ⟨a, b, h⟩ := H ⟨f a, f b, by rw [← f.map_mul, ← f.map_mul, ← f.map_add, h, f.map_one]⟩ #align is_coprime.map IsCoprime.map theorem IsCoprime.of_add_mul_left_left (h : IsCoprime (x + y * z) y) : IsCoprime x y := let ⟨a, b, H⟩ := h ⟨a, a * z + b, by simpa only [add_mul, mul_add, add_assoc, add_comm, add_left_comm, mul_assoc, mul_comm, mul_left_comm] using H⟩ #align is_coprime.of_add_mul_left_left IsCoprime.of_add_mul_left_left theorem IsCoprime.of_add_mul_right_left (h : IsCoprime (x + z * y) y) : IsCoprime x y := by rw [mul_comm] at h exact h.of_add_mul_left_left #align is_coprime.of_add_mul_right_left IsCoprime.of_add_mul_right_left theorem IsCoprime.of_add_mul_left_right (h : IsCoprime x (y + x * z)) : IsCoprime x y := by rw [isCoprime_comm] at h⊢ exact h.of_add_mul_left_left #align is_coprime.of_add_mul_left_right IsCoprime.of_add_mul_left_right theorem IsCoprime.of_add_mul_right_right (h : IsCoprime x (y + z * x)) : IsCoprime x y := by rw [mul_comm] at h exact h.of_add_mul_left_right #align is_coprime.of_add_mul_right_right IsCoprime.of_add_mul_right_right theorem IsCoprime.of_mul_add_left_left (h : IsCoprime (y * z + x) y) : IsCoprime x y := by rw [add_comm] at h exact h.of_add_mul_left_left #align is_coprime.of_mul_add_left_left IsCoprime.of_mul_add_left_left theorem IsCoprime.of_mul_add_right_left (h : IsCoprime (z * y + x) y) : IsCoprime x y := by rw [add_comm] at h exact h.of_add_mul_right_left #align is_coprime.of_mul_add_right_left IsCoprime.of_mul_add_right_left theorem IsCoprime.of_mul_add_left_right (h : IsCoprime x (x * z + y)) : IsCoprime x y := by rw [add_comm] at h exact h.of_add_mul_left_right #align is_coprime.of_mul_add_left_right IsCoprime.of_mul_add_left_right theorem IsCoprime.of_mul_add_right_right (h : IsCoprime x (z * x + y)) : IsCoprime x y := by rw [add_comm] at h exact h.of_add_mul_right_right #align is_coprime.of_mul_add_right_right IsCoprime.of_mul_add_right_right end CommSemiring section ScalarTower variable {R G : Type _} [CommSemiring R] [Group G] [MulAction G R] [SMulCommClass G R R] [IsScalarTower G R R] (x : G) (y z : R) theorem isCoprime_group_smul_left : IsCoprime (x • y) z ↔ IsCoprime y z := ⟨fun ⟨a, b, h⟩ => ⟨x • a, b, by rwa [smul_mul_assoc, ← mul_smul_comm]⟩, fun ⟨a, b, h⟩ => ⟨x⁻¹ • a, b, by rwa [smul_mul_smul, inv_mul_self, one_smul]⟩⟩ #align is_coprime_group_smul_left isCoprime_group_smul_left theorem isCoprime_group_smul_right : IsCoprime y (x • z) ↔ IsCoprime y z := isCoprime_comm.trans <| (isCoprime_group_smul_left x z y).trans isCoprime_comm #align is_coprime_group_smul_right isCoprime_group_smul_right theorem isCoprime_group_smul : IsCoprime (x • y) (x • z) ↔ IsCoprime y z := (isCoprime_group_smul_left x y (x • z)).trans (isCoprime_group_smul_right x y z) #align is_coprime_group_smul isCoprime_group_smul end ScalarTower section CommSemiringUnit variable {R : Type _} [CommSemiring R] {x : R} (hu : IsUnit x) (y z : R) theorem isCoprime_mul_unit_left_left : IsCoprime (x * y) z ↔ IsCoprime y z := let ⟨u, hu⟩ := hu hu ▸ isCoprime_group_smul_left u y z #align is_coprime_mul_unit_left_left isCoprime_mul_unit_left_left theorem isCoprime_mul_unit_left_right : IsCoprime y (x * z) ↔ IsCoprime y z := let ⟨u, hu⟩ := hu hu ▸ isCoprime_group_smul_right u y z #align is_coprime_mul_unit_left_right isCoprime_mul_unit_left_right theorem isCoprime_mul_unit_left : IsCoprime (x * y) (x * z) ↔ IsCoprime y z := (isCoprime_mul_unit_left_left hu y (x * z)).trans (isCoprime_mul_unit_left_right hu y z) #align is_coprime_mul_unit_left isCoprime_mul_unit_left theorem isCoprime_mul_unit_right_left : IsCoprime (y * x) z ↔ IsCoprime y z := mul_comm x y ▸ isCoprime_mul_unit_left_left hu y z #align is_coprime_mul_unit_right_left isCoprime_mul_unit_right_left theorem isCoprime_mul_unit_right_right : IsCoprime y (z * x) ↔ IsCoprime y z := mul_comm x z ▸ isCoprime_mul_unit_left_right hu y z #align is_coprime_mul_unit_right_right isCoprime_mul_unit_right_right theorem isCoprime_mul_unit_right : IsCoprime (y * x) (z * x) ↔ IsCoprime y z := (isCoprime_mul_unit_right_left hu y (z * x)).trans (isCoprime_mul_unit_right_right hu y z) #align is_coprime_mul_unit_right isCoprime_mul_unit_right end CommSemiringUnit namespace IsCoprime section CommRing variable {R : Type u} [CommRing R] theorem add_mul_left_left {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime (x + y * z) y := @of_add_mul_left_left R _ _ _ (-z) <| by simpa only [mul_neg, add_neg_cancel_right] using h #align is_coprime.add_mul_left_left IsCoprime.add_mul_left_left theorem add_mul_right_left {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime (x + z * y) y := by rw [mul_comm] exact h.add_mul_left_left z #align is_coprime.add_mul_right_left IsCoprime.add_mul_right_left theorem add_mul_left_right {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime x (y + x * z) := by rw [isCoprime_comm] exact h.symm.add_mul_left_left z #align is_coprime.add_mul_left_right IsCoprime.add_mul_left_right theorem add_mul_right_right {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime x (y + z * x) := by rw [isCoprime_comm] exact h.symm.add_mul_right_left z #align is_coprime.add_mul_right_right IsCoprime.add_mul_right_right theorem mul_add_left_left {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime (y * z + x) y := by rw [add_comm] exact h.add_mul_left_left z #align is_coprime.mul_add_left_left IsCoprime.mul_add_left_left theorem mul_add_right_left {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime (z * y + x) y := by rw [add_comm] exact h.add_mul_right_left z #align is_coprime.mul_add_right_left IsCoprime.mul_add_right_left theorem mul_add_left_right {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime x (x * z + y) := by rw [add_comm] exact h.add_mul_left_right z #align is_coprime.mul_add_left_right IsCoprime.mul_add_left_right theorem mul_add_right_right {x y : R} (h : IsCoprime x y) (z : R) : IsCoprime x (z * x + y) := by rw [add_comm] exact h.add_mul_right_right z #align is_coprime.mul_add_right_right IsCoprime.mul_add_right_right theorem add_mul_left_left_iff {x y z : R} : IsCoprime (x + y * z) y ↔ IsCoprime x y := ⟨of_add_mul_left_left, fun h => h.add_mul_left_left z⟩ #align is_coprime.add_mul_left_left_iff IsCoprime.add_mul_left_left_iff theorem add_mul_right_left_iff {x y z : R} : IsCoprime (x + z * y) y ↔ IsCoprime x y := ⟨of_add_mul_right_left, fun h => h.add_mul_right_left z⟩ #align is_coprime.add_mul_right_left_iff IsCoprime.add_mul_right_left_iff theorem add_mul_left_right_iff {x y z : R} : IsCoprime x (y + x * z) ↔ IsCoprime x y := ⟨of_add_mul_left_right, fun h => h.add_mul_left_right z⟩ #align is_coprime.add_mul_left_right_iff IsCoprime.add_mul_left_right_iff theorem add_mul_right_right_iff {x y z : R} : IsCoprime x (y + z * x) ↔ IsCoprime x y := ⟨of_add_mul_right_right, fun h => h.add_mul_right_right z⟩ #align is_coprime.add_mul_right_right_iff IsCoprime.add_mul_right_right_iff theorem mul_add_left_left_iff {x y z : R} : IsCoprime (y * z + x) y ↔ IsCoprime x y := ⟨of_mul_add_left_left, fun h => h.mul_add_left_left z⟩ #align is_coprime.mul_add_left_left_iff IsCoprime.mul_add_left_left_iff theorem mul_add_right_left_iff {x y z : R} : IsCoprime (z * y + x) y ↔ IsCoprime x y := ⟨of_mul_add_right_left, fun h => h.mul_add_right_left z⟩ #align is_coprime.mul_add_right_left_iff IsCoprime.mul_add_right_left_iff theorem mul_add_left_right_iff {x y z : R} : IsCoprime x (x * z + y) ↔ IsCoprime x y := ⟨of_mul_add_left_right, fun h => h.mul_add_left_right z⟩ #align is_coprime.mul_add_left_right_iff IsCoprime.mul_add_left_right_iff theorem mul_add_right_right_iff {x y z : R} : IsCoprime x (z * x + y) ↔ IsCoprime x y := ⟨of_mul_add_right_right, fun h => h.mul_add_right_right z⟩ #align is_coprime.mul_add_right_right_iff IsCoprime.mul_add_right_right_iff theorem neg_left {x y : R} (h : IsCoprime x y) : IsCoprime (-x) y := by obtain ⟨a, b, h⟩ := h use -a, b rwa [neg_mul_neg] #align is_coprime.neg_left IsCoprime.neg_left theorem neg_left_iff (x y : R) : IsCoprime (-x) y ↔ IsCoprime x y := ⟨fun h => neg_neg x ▸ h.neg_left, neg_left⟩ #align is_coprime.neg_left_iff IsCoprime.neg_left_iff theorem neg_right {x y : R} (h : IsCoprime x y) : IsCoprime x (-y) := h.symm.neg_left.symm #align is_coprime.neg_right IsCoprime.neg_right theorem neg_right_iff (x y : R) : IsCoprime x (-y) ↔ IsCoprime x y := ⟨fun h => neg_neg y ▸ h.neg_right, neg_right⟩ #align is_coprime.neg_right_iff IsCoprime.neg_right_iff theorem neg_neg {x y : R} (h : IsCoprime x y) : IsCoprime (-x) (-y) := h.neg_left.neg_right #align is_coprime.neg_neg IsCoprime.neg_neg theorem neg_neg_iff (x y : R) : IsCoprime (-x) (-y) ↔ IsCoprime x y := (neg_left_iff _ _).trans (neg_right_iff _ _) #align is_coprime.neg_neg_iff IsCoprime.neg_neg_iff end CommRing end IsCoprime
[STATEMENT] lemma HMA_map_matrix [transfer_rule]: "((=) ===> HMA_M ===> HMA_M) map_mat map_matrix" [PROOF STATE] proof (prove) goal (1 subgoal): 1. ((=) ===> HMA_M ===> HMA_M) map_mat HMA_Connect.map_matrix [PROOF STEP] unfolding map_vector_def map_matrix_def[abs_def] map_mat_def[abs_def] HMA_M_def from_hma\<^sub>m_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. ((=) ===> (\<lambda>a b. a = Matrix.mat CARD('d) CARD('c) (\<lambda>(i, j). b $h Bij_Nat.from_nat i $h Bij_Nat.from_nat j)) ===> (\<lambda>a b. a = Matrix.mat CARD('d) CARD('c) (\<lambda>(i, j). b $h Bij_Nat.from_nat i $h Bij_Nat.from_nat j))) (\<lambda>f A. Matrix.mat (dim_row A) (dim_col A) (\<lambda>ij. f (A $$ ij))) (\<lambda>f A. \<chi>i ia. f (A $h i $h ia)) [PROOF STEP] by auto
Formal statement is: lemma of_real_inverse [simp]: "of_real (inverse x) = inverse (of_real x :: 'a::{real_div_algebra,division_ring})" Informal statement is: The inverse of a real number is the same as the inverse of the corresponding complex number.