Datasets:
AI4M
/

text
stringlengths
0
3.34M
hello world hello world! line 1 line 2 line 3 line 4 hello world!! line5
Mutinus elegans is saprobic — deriving nutrients by breaking down dead or dying organic matter . It is commonly found in gardens and farm areas enriched with manure , near well @-@ decayed stumps and logs , and in wood chips . A Japanese publication mentioned its occurrence in Takatsuki and Osaka @-@ fu , where it fruited in November and December on the ground along paths or in open spaces , under or near bamboo ( <unk> <unk> ) and hardwoods such as the Sawtooth Oak , the Japanese <unk> , and the Camphor tree .
Formal statement is: lemma eucl_rel_poly_mult: assumes "eucl_rel_poly x y (q, r)" "eucl_rel_poly q z (q', r')" shows "eucl_rel_poly x (y * z) (q', y * r' + r)" Informal statement is: If $x = qy + r$ and $q = q'z + r'$, then $x = q'yz + yr' + r$.
theory Scratch imports Main begin theorem A: "A \<longrightarrow> A \<or> B" apply (rule impI) apply (rule disjI1) apply assumption done theorem B: "A \<or> B \<longrightarrow> B \<or> A" apply (rule impI) apply (erule disjE) apply (rule disjI2) apply assumption apply (rule disjI1) apply assumption done \<lbrakk> \<rbrakk> \<not> \<longrightarrow> \<longleftrightarrow> \<rightarrow> \<Rightarrow> \<forall> \<exists> \<and> \<or> \<Longrightarrow> \<rightleftharpoons> end
import requests from requests import get from bs4 import BeautifulSoup import pandas as pd import numpy as np #empty lists name = [] cmc = [] manacost = [] typeline = [] rulestxt = [] #main loop #manually changing number of pages, ik there is a better way page = -1 while page <= 3: page = page + 1 url = 'https://gatherer.wizards.com/Pages/Search/Default.aspx?page={}&format=[%22Commander%22]'.format(page) results = requests.get(url) soup = BeautifulSoup(results.text, "html.parser") mtgAll = soup.find_all('table') for tables in mtgAll: #name cardtitle = tables.find('span', class_='cardTitle').text name.append(cardtitle) #converted mana cost mcost = tables.find('span', class_='convertedManaCost').text cmc.append(mcost) #typeline cardtype = tables.find('span', class_='typeLine').text typeline.append(cardtype) #rulestext rules = tables.find('div', class_='rulesText').text rulestxt.append(rules) #make data frame #I need to add more data frames cards = pd.DataFrame({ 'CardName': name, 'CMC': cmc, 'Rules': rulestxt, 'Types': typeline, }) #cleaningdata cards['CMC'] = cards['CMC'].astype(int) cards['CardName'] = cards['CardName'].str.replace('\n', '') cards.to_csv('cardlistTest.csv')
function IW = get_BMS_capacity(W) %This function is employed here to verify the correctness of the program %that is being writen HYX = sum(W(1, :).*log2(W(1, :))); PY = (W(1, :) + W(2, :))/2; HY = sum(-PY.*log2(PY)); IW = HY + HYX; end
import data.real.irrational import topology.basic import algebra.order.floor --OUTPUT 1 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := begin begin have h1 : ∀ i j : ℤ, i ≠ j → abs ((int.fract (α * ↑i)) - (int.fract (α * ↑j))) < 1, from assume (i j : ℤ) (h1 : i ≠ j), begin let iα := (α * ↑i), let jα := (α * ↑j), have h2 : abs (iα - (iα.floor + (int.fract iα))) < 1, from by auto [int.fract_lt_one], have h3 : abs (jα - (jα.floor + (int.fract jα))) < 1, from by auto [int.fract_lt_one], have h4 : (int.fract iα) = (int.fract jα), from by auto [h2, h3, add_sub_cancel, h1], have h5 : (iα - iα.floor) = (jα - jα.floor), from by auto [h4], have h6 : iα = jα, from by auto [h5], have h7 : (α * ↑i) - (α * ↑j) = 0, from by auto [h6], have h8 : (α * (↑i - ↑j)) = 0, from by auto [h7], have h9 : (α * (↑i - ↑j)) ∈ ℚ, from by auto [h8, set.mem_coe, set.mem_image, set.mem_univ], have h10 : α ∈ ℚ, from by auto [hα_irrat, rational_iff_exists_int, h9, mul_left_cancel_iff], have h11 : false, from by auto [hα_irrat, h10], show abs ((int.fract (α * ↑i)) - (int.fract (α * ↑j))) < 1, from by auto [h11], end, have h2 : ∀ i : ℤ, int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one], have h3 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [h2], have h4 : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) ⊆ set.Icc 0 1, from by auto [h3, set.subset_closure_iff], have h5 : ∀ i j : ℤ, i ≠ j → abs ((int.fract (α * ↑i)) - (int.fract (α * ↑j))) < 1, from by auto [h1], have h6 : ∀ x : ℝ, x ∈ closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) → x ∈ set.Icc 0 1, from by auto [h5, set.subset_closure_iff], have h7 : ∀ x : ℝ, x ∈ set.Icc 0 1 → x ∈ closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)), from by auto [h6], have h8 : set.Icc 0 1 ⊆ closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)), from by auto [h7], show closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1, from by auto [h4, h8, set.subset.antisymm_iff], end, end --OUTPUT 2 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := begin -- Let $\alpha$ be an irrational number. 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 h1 : ∀ (i j : ℤ), i ≠ j → int.fract (α*↑i) ≠ int.fract (α*↑j), from by intros i j h_ineq; have h1_1 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_2 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_3 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_4 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_5 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_6 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_7 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_8 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_9 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_10 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_11 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_12 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_13 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_14 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_15 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_16 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_17 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_18 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_19 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_20 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_21 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_22 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_23 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_24 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_25 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_26 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_27 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_28 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_29 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_30 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_31 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_32 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_33 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_34 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_35 : α = (int.fract (α*↑i)) + (int.nat_abs (α*↑i)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_36 : α = (int.fract (α*↑j)) + (int.nat_abs (α*↑j)), from by auto [int.fract_eq_iff_exists_nat_abs], have h1_37 : (int.fract (α*↑i)) = (int.fract (α*↑j)), from by linarith, have h1_38 : (int.nat_abs (α*↑i)) = (int.nat_abs (α*↑j)), from by linarith, have h1_39 : α = (int.fract (α*↑i end --Needs more than 2000 tokens! --OUTPUT 3 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := begin --Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then have h1 : ∀ m n : ℤ, m ≠ n → int.fract (α * ↑m) ≠ int.fract (α * ↑n), from by auto [int.fract_add, int.fract_mul, int.fract_eq_of_add_fract_eq_add_fract, int.fract_lt_one, int.fract_lt_one_iff, int.fract_ne_of_ne], --$S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}$ is an infinite subset of $\left[0,1\right]$. have h2 : (∀ m : ℤ, int.fract (α * ↑m) ∈ set.Icc 0 1), from by auto [int.fract_lt_one, int.fract_lt_one_iff], have h3 : (∀ m : ℤ, int.fract (α * ↑m) ∈ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)), from by auto [h2], have h4 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [h3], have h5 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅, from by auto [h3], have h6 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅, from by auto [h5], have h7 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ ∀ A B : set ℝ, (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) → ¬ (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅), from by auto [h5], have h8 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ ∀ A B : set ℝ, (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) → ¬ (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅, from by auto [h7, h6], have h9 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ ∀ A B : set ℝ, (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) → ¬ (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [h8, h4], have h10 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ ∀ A B : set ℝ, (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) → ¬ (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅, from by auto [h9], have h11 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ ∀ A B : set ℝ, (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) → ¬ (A ⊆ B ∧ A ≠ ∅ ∧ B ≠ ∅) ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ ∀ (A B : set ℝ), A ⊆ B → ¬ A = ∅ → ¬ B = ∅ → ¬ A = B, from by auto [h10], have h12 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ ∀ (A B : set ℝ), A ⊆ B → ¬ A = ∅ → ¬ B = ∅ → ¬ A = B ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅, from by auto [h11], have h13 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ ∀ (A B : set ℝ), A ⊆ B → ¬ A = ∅ → ¬ B = ∅ → ¬ A = B ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅ ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1 ∧ (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) end --Needs more than 2000 tokens! --OUTPUT 4 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := begin -- Let $\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}$. have h1 : ∀ (i j : ℤ), i ≠ j → int.fract (α * ↑i) ≠ int.fract (α * ↑j), from by auto [hα_irrat, int.fract_eq_iff] using [int.fract_eq_iff], -- Hence, -- $$S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}$$ -- is an infinite subset of $\left[0,1\right]$. have h2 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅, from by auto [set.mem_univ], have h3 : finite ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = ff, from by auto [finite.empty_iff_finite, h2], -- By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. -- One can thus find pairs of elements of $S$ that are arbitrarily close. -- Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$. have h4 : limit_point ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) 0, from by auto [limit_point_iff_limit_point_of_image] using [limit_point_iff_limit_point_of_image, h3, int.fract_in_range, h1], -- 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$. have h5 : ∀ y : ℝ, y ∈ set.Icc 0 1 → ∀ ε > 0, ∃ N : ℤ, ∃ x : ℤ, x ∈ set.univ ∧ int.fract (α * ↑x) ∈ set.Icc 0 ε ∧ (int.fract (α * ↑N) ≤ y) ∧ (y < int.fract (α * ↑(N + 1))) ∧ (abs (y - int.fract (α * ↑(N * x))) < ε), from by auto [int.fract_in_range] using [int.fract_in_range, h1, h4, int.fract_eq_iff, int.fract_add_int, int.fract_mul_int, int.fract_mul_self_eq_zero, int.fract_eq_zero_iff_int_mul_eq], --Hence the result show closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1, from by auto [closure_eq_of_is_open, is_open_Icc, is_open_iff_forall_mem_open, h5], end --OUTPUT 5 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := begin --Let $\alpha$ be an irrational number. Then 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 h1 : ∀ (i j : ℤ), i ≠ j → int.fract (α * ↑i) ≠ int.fract (α * ↑j), from by auto [hα_irrat, int.fract_eq_of_int, int.fract_eq_of_int], have h2 : ∀ (i : ℤ), int.fract (α * ↑i) ∈ set.Icc 0 1, from by auto [int.fract_lt_one], have h3 : set.Ioc 0 1 ≠ ∅, from by auto [h2], have h4 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ≠ ∅, from by auto [h3, exists.intro], have h5 : (λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [h2], have h6 : closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ⊆ set.Icc 0 1, from by auto [set.subset.trans, closure_subset], have h7 : set.Icc 0 1 ⊆ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)), from by auto [closure_eq, h4, h5], have h8 : closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1, from by auto [set.subset.antisymm, h6, h7], show closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1, from by auto [h8], end --OUTPUT 6 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := begin -- Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then have h1 : ∀ m n : ℤ, m ≠ n → (int.fract (α * ↑m)) ≠ (int.fract (α * ↑n)), from begin assume m n hmn, have h1 : (α * ↑m) ≠ (α * ↑n), from by auto [hα_irrat, mul_eq_zero], have h2 : (int.fract (α * ↑m)) = (α * ↑m) - (int.nat_abs (α * ↑m)), from by auto [int.fract_eq], have h3 : (int.fract (α * ↑n)) = (α * ↑n) - (int.nat_abs (α * ↑n)), from by auto [int.fract_eq], show (int.fract (α * ↑m)) ≠ (int.fract (α * ↑n)), from by auto [h2, h3, h1], end, -- Hence, $S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}$ is an infinite subset of $[0,1]$. have h2 : (set.univ ∈ set.univ) ∧ (∀ A B : set ℤ, A ∈ set.univ → B ∈ set.univ → A ≠ B → ((λ (m : ℤ), int.fract (α * ↑m)) '' A) ≠ ((λ (m : ℤ), int.fract (α * ↑m)) '' B)), from by auto, have h3 : (λ (m : ℤ), int.fract (α * ↑m)) '' (set.univ) ≠ ∅, from by auto [h2], have h4 : set.finite (set.univ) = ff, from by auto [set.finite_univ], have h5 : set.finite ((λ (m : ℤ), int.fract (α * ↑m)) '' set.univ) = ff, from by auto [set.finite_image], have h6 : set.infinite ((λ (m : ℤ), int.fract (α * ↑m)) '' set.univ), from by auto [h4, h5, set.infinite_iff_nonempty_and_injective, h3, h2], -- By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$. have h7 : ∀ (a : ℝ), ¬(a = 0) → ∃ (ε : ℝ), ε > 0 ∧ ∀ (x : ℝ), x ≠ 0 → x ∉ set.Icc (a - ε) (a + ε), from by auto [not_forall], have h8 : ∀ (ε : ℝ), ε > 0 → ∃ (x : ℝ), x ∉ set.Icc (-ε) ε, from begin assume ε hε, have h1 : (0 : ℝ) ≠ (ε : ℝ), from by auto [lt_iff_not_ge] using [hε], cases h7 ε h1 with ε1 h9, have h10 : (ε1 : ℝ) > 0, from by auto [h9], have h11 : ε1 ∈ set.Icc (-ε) ε, from by auto [set.mem_Icc], have h12 : ε1 ∉ set.Icc (-ε) ε, from by auto [h9, h10, h11], show ∃ (x : ℝ), x ∉ set.Icc (-ε) ε, from by auto [h12], end, have h9 : closure ((λ m : ℤ, int.fract (α * ↑m)) '' set.univ) ≠ set.Icc 0 1, from by auto [not_forall, h8], -- 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$. have h10 : ∀ (y : ℝ), y ∈ set.Icc 0 1 → ∀ (ε : ℝ), ε > 0 → ∃ (x n : ℤ), (int.fract (α * ↑x)) ∈ (λ (m : ℤ), int.fract (α * ↑m)) '' set.univ ∧ (int.fract (α * ↑x)) < ε ∧ (int.nat_abs (α * ↑n)) ≤ y ∧ y < (int.nat_abs (α * ↑n)) + (int.fract (α * ↑x)), from begin assume y hy ε hε, have h1 : ∀ (n : ℤ), (int.fract (α * ↑n)) ∈ set.Icc 0 1, from by auto [int.fract_lt_one], have h2 : ∀ (n : ℤ), (int.fract (α * ↑n)) ∈ (λ (m : ℤ), int.fract (α * ↑m)) '' set.univ, from by auto [set.mem_image], have h3 : ∀ (n : ℤ), (int.fract (α * ↑n)) ≠ 0, from by auto [int.fract_ne_zero], have h4 : ∀ (n : ℤ), (int.fract (α * ↑n)) > 0, from by auto [lt_iff_le_and_ne, int.fract_pos], have h5 : ∀ (n : ℤ), (int.nat_abs (α * ↑n)) ≥ 0, from by auto [int.nat_abs_nonneg], have h6 : ∀ (n : ℤ), (int.nat_abs (α * ↑n)) < (int.nat_abs (α * ↑n)) + (int.fract (α * ↑n)), from by auto [int.nat_abs_lt_add_one_iff], have h7 : ∀ (n : ℤ), (int.nat_abs (α * ↑n)) < (int.nat_abs (α * ↑n)) + (int.fract (α * ↑n)), from by auto [int.nat_abs_lt_add_one_iff], have h8 : ∀ (n : ℤ), (int.nat_abs (α * ↑n)) < (int.nat_abs (α * ↑n)) + (int.fract (α * ↑n)), from by auto [int.nat_abs_lt_add_one_iff], have h9 : ∀ (n : ℤ), (int.nat_abs (α * ↑n)) < (int.nat_abs (α * ↑n)) + (int.fract (α * ↑n)), from by auto [int.nat_abs_lt_add_one_iff], have h10 : ∀ (n : ℤ), (int.nat_abs (α * ↑n)) < (int.nat_abs (α * ↑n)) + (int.fract (α * ↑n)), from by auto [int.nat_abs_lt_add_one_iff], have h11 : ∀ (n : ℤ), (int.fract (α * end --Needs more than 2000 tokens! --OUTPUT 7 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := begin --$\alpha$ is an irrational number. assume (α : ℝ) (hα_irrat : irrational α), --Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. have h1 : ∀ (i j : ℤ), (i ≠ j) → (int.fract (α * ↑i) ≠ int.fract (α * ↑j)), from begin assume (i j : ℤ) (h1 : i ≠ j), have h2 : (int.fract (α * ↑i)) - (int.fract (α * ↑j)) = (α * ↑i) - (int.fract (α * ↑i)) - ((α * ↑j) - (int.fract (α * ↑j))), by ring, have h3 : (α * ↑i) - (int.fract (α * ↑i)) = (α * ↑j) - (int.fract (α * ↑j)), from by auto [h2, sub_eq_add_neg, int.fract_mul_self_eq, int.fract_add_self_eq, int.fract_mul_self_eq, int.fract_add_self_eq, int.fract_mul_self_eq, int.fract_add_self_eq], have h4 : α = (int.fract (α * ↑i) - int.fract (α * ↑j)) / (i - j), from by auto [sub_eq_add_neg, int.fract_mul_self_eq, int.fract_add_self_eq, int.fract_mul_self_eq, int.fract_add_self_eq], show (int.fract (α * ↑i)) ≠ (int.fract (α * ↑j)), from by auto [h1, h3, h4, hα_irrat, quotient.exists_rep], end, --Hence, $S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}$ is an infinite subset of $\left[0,1\right]$. have h2 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h3 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h4 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h5 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h6 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h7 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h8 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h9 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h10 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h11 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h12 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h13 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h14 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h15 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h16 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h17 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h18 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h19 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h20 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h21 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h22 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h23 : (λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ) ⊆ set.Icc 0 1, from by auto [int.fract_nonneg, int.fract_lt_one], have h24 : (λ m : ℤ, int. end --Needs more than 2000 tokens! --OUTPUT 8 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := begin -- Let $\alpha$ be an irrational number. -- Then 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}$. have h1 : ∀ (i j : ℤ), i ≠ j → (int.fract (α * ↑i)) ≠ (int.fract (α * ↑j)), from begin -- We consider two cases, when $i=j$ and when $i\neq j$. assume (i j : ℤ) (h3 : i ≠ j), -- In the first case, we assume $i=j$. assume h4 : (int.fract (α * ↑i)) = (int.fract (α * ↑j)), -- Then we have a contradiction, as $i\neq j$. have h5 : i = j, from by auto [h4], have h6 : false, from by auto [h3, h5], show (int.fract (α * ↑i)) ≠ (int.fract (α * ↑j)), from by auto [h6], end, -- Hence, -- $$ -- S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\} -- $$ -- is an infinite subset of $\left[0,1\right]$. have h7 : nonempty ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)), from by auto [h1], -- By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. have h8 : ∃ x, x ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)), from by auto using [h7, set.finite_univ], -- One can thus find pairs of elements of $S$ that are arbitrarily close. have h9 : ∀ ε > 0, ∃ x y, x ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ∧ y ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ∧ abs (x - y) < ε, from begin assume (ε : ℝ) (h10 : ε > 0), cases h8 with x h11, cases h11 ε h10 with N h12, cases h12 N with y h13, have h14 : y ∈ _, from by auto [set.mem_univ, set.mem_image, set.mem_closure, set.subset_univ], use x, use y, have h15 : abs (x - y) < ε, from by auto [h13], show x ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ∧ y ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ∧ abs (x - y) < ε, from by auto [h11, h14, h15], end, -- Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$. have h16 : ∀ ε > 0, ∃ (y : ℝ), y ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ∧ abs y < ε, from begin assume (ε : ℝ) (h17 : ε > 0), cases h9 ε h17 with x h18, cases h18 with y h19, cases h19 with h20 h21, cases h21 with h22 h23, have h24 : abs (0 - y) < ε, from by auto [h23], use y, show y ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ∧ abs y < ε, from by auto [h20, h24], end, -- To show that $S$ is dense in $[0, 1]$, consider $y \in[0,1]$, and $\epsilon>0$. have h25 : ∀ (y : ℝ), y ∈ Icc 0 1 → ∀ ε > 0, ∃ (x : ℝ), x ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ∧ abs (y - x) < ε, from begin assume (y : ℝ) (h26 : y ∈ Icc 0 1) (ε : ℝ) (h27 : ε > 0), cases h16 ε h27 with x h28, cases h28 with h29 h30, -- 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$. have h31 : ∃ (m : ℤ), ((m : ℝ) * x) ≤ y ∧ y < ((m + 1) : ℝ) * x, from by auto [int.coe_nat_lt, int.coe_nat_le, int.coe_nat_pos, int.coe_nat_add, int.coe_nat_mul, int.fract_lt_one], cases h31 with m h32, cases h32 with h33 h34, have h35 : abs (y - int.fract (↑m * x)) < ε, from by auto [h26, h30, h33, h34], use int.fract (↑m * x), show int.fract (↑m * x) ∈ closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)) ∧ abs (y - int.fract (↑m * x)) < ε, from by auto [h29, h35], end, -- Let $A := closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ))$. let A := closure ((λ (m : ℤ), int.fract (α * ↑m)) '' (@set.univ ℤ)), -- Then $A \subseteq \{0, 1\}$ have h36 : A ⊆ {0, 1}, from by auto [set.mem_closure, set.mem_univ, set.mem_image, int.fract_lt_one, set.mem_singleton], -- Let $B := \{0, 1\}$. let B := {0, 1}, -- Then $A = B$ have h37 : A = B, from by auto [set.ext, set.mem_singleton, h36], -- Then $A = \{0, 1\}$ have h38 : A = {0, 1}, from by auto [h37], -- Then $A$ is dense in $\{0, 1\}$ have h39 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 by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset], -- Then $(A ∩ B) ⊆ A$, by intersection of set is a subset have h2 : (A ∩ B) ⊆ A, from by auto [set.inter_subset_left], -- Then $(A ∩ B) ⊆ S$, by subset relation is transitive have h3 : (A ∩ B) ⊆ S, from by auto [set.subset.trans], -- Hence $(A ∩ B) ∈ 𝒫 S$, by power set definition show (A ∩ B) ∈ 𝒫 S, from by auto [set.mem_powerset], 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 auto [sq] -- distributive property of multiplication over addition gives: ... = x*(x+y) + y*(x+y) : by auto [add_mul] -- applying the above property further gives: ... = x*x + x*y + y*x + y*y : by auto [mul_comm, add_mul] using [ring] -- rearranging the terms using commutativity and adding gives: ... = x^2 + 2*x*y + y^2 : by auto [sq, mul_comm] using [ring] end /--`theorem` Identity of Group is Unique Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$. `proof` From Group has Latin Square Property, there exists a unique $x \in G$ such that: :$a x = b$ and there exists a unique $y \in G$ such that: :$y a = b$ Setting $b = a$, this becomes: There exists a unique $x \in G$ such that: :$a x = a$ and there exists a unique $y \in G$ such that: :$y a = a$ These $x$ and $y$ are both $e$, by definition of identity element. {{qed}} -/ theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a := begin -- Group has Latin Square Property have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by auto using [use (a⁻¹ * b)], have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by auto using [use b * a⁻¹], -- Setting $b = a$, this becomes: have h3 : ∀ a : G, ∃! x : G, a * x = a, from by auto [h1], have h4 : ∀ a : G, ∃! y : G, y * a = a, from by auto [h2], -- These $x$ and $y$ are both $(1 : G)$, by definition of identity element have h5 : ∀ a : G, classical.some (h3 a).exists = (1 : G), from by auto [exists_unique.unique, h3, classical.some_spec, exists_unique.exists, mul_one], have h6 : ∀ a : G, classical.some (h4 a).exists = (1 : G), from by auto [exists_unique.unique, h4, classical.some_spec, exists_unique.exists, one_mul], show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by auto [h3, h4, exists_unique.unique, classical.some_spec, exists_unique.exists] using [use (1 : G)], 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 by auto [abs_sub_lt_iff] using [linarith], --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 := by auto [lt_of_le_of_lt, le_max_left, le_max_right], --$\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 by auto [h8, h10, h5, h9], --$\forall n > N: l - \epsilon < x_n < l + \epsilon$ have h15 : ∀ n > N, ((l - ε) < (x n)) ∧ ((x n) < (l+ε)), from by auto [h11] using [linarith], --So $\forall n > N: \size {x_n - l} < \epsilon$ --Hence the result show ∀ (n : ℕ), n > N → |x n - l| < ε, from by auto [h5, h15], end /--`theorem` Density of irrational orbit The fractional parts of the integer multiples of an irrational number form a dense subset of the unit interval `proof` Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then $$ i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor, $$ which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. Hence, $$ S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\} $$ is an infinite subset of $\left[0,1\right]$. By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$. To show that $S$ is dense in $[0, 1]$, consider $y \in[0,1]$, and $\epsilon>0$. Then by selecting $x \in S$ such that $\{x\}<\epsilon$ (which exists as $0$ is a limit point), and $N$ such that $N \cdot\{x\} \leq y<(N+1) \cdot\{x\}$, we get: $|y-\{N x\}|<\epsilon$. QED -/ theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 := FEW SHOT PROMPTS TO CODEX(END)-/
import data.nat.choose import data.set import data.set.finite import data.multiset import data.finset import data.list import data.finset algebra.big_operators import algebra.big_operators import init.algebra.functions import algebra.group_power #eval choose 5 4 #check nat.rec_on /- Collaboration between Travis Hance (thance) Katherine Cordwell (kcordwell) -/ /- Following the proof at https://artofproblemsolving.com/wiki/index.php/Combinatorial_identity -/ /- sum_for_hockey_stick takes r and k and computes the sum from i = r to i = r + k of (i choose r) -/ def sum_for_hockey_stick (r k : ℕ) : ℕ := nat.rec_on k 1 (λ k ih, ih + (choose (r + k + 1) r)) #eval sum_for_hockey_stick 5 0 /- this is really saying 5 choose 5 is 1 -/ #eval sum_for_hockey_stick 5 1 /- this is saying 5 choose 5 + 6 choose 5 is 7 -/ #eval choose 7 6 #eval sum_for_hockey_stick 5 2 /- calculates 5 choose 5 + 6 choose 5 + 7 choose 5-/ #eval choose 8 6 #eval sum_for_hockey_stick 5 3 /- calculates 5 choose 5 + 6 choose 5 + 7 choose 5 + 8 choose 5-/ #eval choose 9 6 /- Says that for natural numbers r and n, if n >= r, then the sum from i = r to n of i choose r equals n + 1 choose r + 1 -/ theorem hockey_stick_identity (k r : ℕ) : sum_for_hockey_stick r k = (choose (r + k + 1) (r + 1)) := begin induction k with k ih, {have h: sum_for_hockey_stick r 0 = 1, by refl, simp[*, refl]}, { calc sum_for_hockey_stick r (nat.succ k) = (sum_for_hockey_stick r k) + (choose (r + k + 1) r): by simp[sum_for_hockey_stick] ... = (choose (r + k + 1) (r + 1)) + (choose (r + k + 1) r) : by rw[ih] ... = (choose (r + k + 1) r) + (choose (r + k + 1) (r + 1)): by simp ... = choose (r + k + 1) r + choose (r + k + 1) (nat.succ r) : by refl ... = choose (r + k + 1 + 1) (r + 1) : by rw[←choose] } end /- Here is my first attempt at stating Vandermonde's identity. Vandermonde's identity says that m + n choose r equals the sum from k = 0 to r of (m choose k)*(n choose r - k). I tried to do an inductive proof as at https://math.stackexchange.com/questions/219928/inductive-proof-for-vandermondes-identity/219938, but this was not so good because the induction was on both n and r, and it got fairly messy. So I decided to try a different approach (see below). -/ def sum_for_vandermonde (m n r i: ℕ) : ℕ := nat.rec_on i ((choose m 0)*(choose n r)) (λ i ih, ih + (choose m (i + 1))*(choose n (r - (i + 1)))) #eval sum_for_vandermonde 3 4 6 6 #eval choose (3 + 4) 6 #eval sum_for_vandermonde 12 5 8 8 #eval choose (12 + 5) 8 /- double-checked with Mathematica -/ #eval sum_for_vandermonde 12 5 8 3 #eval sum_for_vandermonde 3 4 6 5 lemma sum_for_vandermonde_with_n_is_zero (m r: ℕ) : sum_for_vandermonde m 0 r r = choose m r := begin induction r with r ih, { calc sum_for_vandermonde m 0 0 0 = (choose m 0)*(choose 0 0) : by refl ... = choose m 0 : by simp }, calc sum_for_vandermonde m 0 (nat.succ r) (nat.succ r) = sorry : sorry ... = choose m (nat.succ r): sorry end theorem vandermonde_identity (m n : ℕ) : ∀ r : ℕ, sum_for_vandermonde m n r r = choose (m + n) r := begin induction n with n ih1, {simp[choose, sum_for_vandermonde_with_n_is_zero]}, intro r, simp[sum_for_vandermonde, choose], sorry end /- Next I decided to restate Vandermonde's theorem using big_ops and started on the algebraic proof of Vandermonde's as found on Wikipedia: https://en.wikipedia.org/wiki/Vandermonde%27s_identity. I proved the first few steps but ended up spending time on some other parts of the project and didn't finish. -/ /- Lemma for a case of using the binomial theorem -/ variables x y : ℕ lemma binomial_theorem_with_1 (x n : ℕ) : ∀ n : ℕ, (x + 1)^n = (finset.range (nat.succ n)).sum (λ m, x ^ m * choose n m) := begin intro n, have h3 := add_pow x 1 n, simp at h3, apply h3 end /-show sum from r = 0 to m + n (m + n choose r) x^r = (1 + x)^(m + n) = ( 1 + x)^m = (1 + x)^n = (scary) * (scary) -/ #check pow_add lemma binomial_theorem_for_vandermonde (x m n : ℕ) : ∀ n m: ℕ, (finset.range (m + nat.succ n)).sum(λ r, x^r * (choose (m + n) r)) = (finset.range (nat.succ m)).sum(λ r, x^r * choose m r)*(finset.range (nat.succ n)).sum(λ r, x^r * choose n r) := begin intros n m, have h := pow_add (x + 1) m n, have h1 : n + m = m + n, by simp[add_comm], simp at h, rw h1 at h, calc (finset.range (m + nat.succ n)).sum(λ r, x^r * (choose (m + n) r)) = (x + 1)^(m + n): by rw ← binomial_theorem_with_1 x (m + nat.succ n) ... = (x + 1)^m * (x + 1)^n: h ... = (finset.range (nat.succ m)).sum(λ r, x^r * choose m r) * (x + 1)^n: by rw binomial_theorem_with_1 x (nat.succ m) ... = (finset.range (nat.succ m)).sum(λ r, x^r * choose m r)*(finset.range (nat.succ n)).sum(λ r, x^r * choose n r) : by rw binomial_theorem_with_1 x (nat.succ n) end /- Vandermonde's identity (restated) -/ theorem vandermonde_thm (m n r : ℕ) : ∀ r : ℕ, (finset.range (nat.succ r)).sum(λ k, (choose m k)*(choose n (r-k)))= choose (m + n) r := begin sorry end
record _×_ (A B : Set) : Set where constructor _,_ field fst : A snd : B open _×_ infixr 1 _,_ _∩_ : {I : Set} → (I → Set) → (I → Set) → I → Set P ∩ Q = λ i → P i × Q i record Preorder : Set₁ where no-eta-equality field I : Set infix 4 _∈_ postulate Ty World Cxt : Set All : (P : Ty → Set) → Cxt → Set _∈_ : Ty → World → Set module Monotone (pre : Preorder) where open Preorder pre postulate Monotone : (I → Set) → Set instance postulate all-monotone : {Γ : Cxt} {C : Ty → I → Set} ⦃ w : ∀ {ty} → Monotone (C ty) ⦄ → Monotone (λ W → All (λ ty → C ty W) Γ) module Monad (pre : Preorder) (let open Preorder pre) (M : (I → Set) → I → Set) where postulate _>>=_ : ∀ {P Q W} → M P W → (∀ {W'} → P W' → M Q W') → M Q W postulate M : (World → Set) → World → Set Val : World → Set preorder : Preorder preorder .Preorder.I = World module Inner (Dummy : Set) where -- Succeeds if no Dummy private -- Succeeds if type is given pre : _ -- Preorder pre = preorder open Monotone pre open Monad pre M postulate R : World → Set instance any-monotone : ∀ {ty} → Monotone (ty ∈_) local : ∀ Γ {W} → R W × All (_∈ W) Γ → M Val W ^ : ∀ {Q : World → Set} ⦃ m : Monotone Q ⦄ → ∀ {W} → Q W → M (R ∩ Q) W eval-method : ∀ Γ {W} → All (_∈ W) Γ → M Val W eval-method Γ args = ^ args >>= local _ -- Succeeds if giving Γ for _
import plane_separation_world.level06 --hide open IncidencePlane --hide /- # Plane Separation World ## Level 7: on the way to the final level (IV). This is the fourth of five lemmas that we need to prove before jumping into the final level of the game! You will be provided with its mathematical proof in paper right below. Remember that you can use all the theorem statements from the left-hand side box. ## Mathematical proof in paper... **Claim:** If two points A and C are not on the same side of the line ℓ, there exists a point in the segment A·C which is incident with the line ℓ. **Proof:** Let us assume that there exists a point P, such that `P ∈ pts (A⬝C) ∧ P ∈ ℓ`. Then, either `P = A` or `A * P * C` or `P = C`, and `P ∈ ℓ`. Now, we proceed with the proof of by contradiction. If there does not exist such point P, we have to prove that the intersection of the segment `A·C` with the line ℓ is empty, and `P ∉ ℓ`. That is, there exists a point X such that `x ∈ pts (A⬝C) ∩ ↑ℓ ↔ x ∈ ∅`. Then we have to prove (a) `x ∈ pts (A⬝C) ∩ ↑ℓ → x ∈ ∅` and (b) `x ∈ ∅ → x ∈ pts (A⬝C) ∩ ↑ℓ`. **Proof (a):** Let us assume that `x ∈ pts (A⬝C) ∩ ↑ℓ`. Then, we have to prove that `x ∈ ∅`. That is, `x ∈ U → false`, where `U` is the `universal set`. Because of this reason, we assume that `x ∈ U` is true and then it suffices to prove `false`. At this point, let the point P be `x`, such that `x = A` or `A * x * C` or `x = C`, and `x ∉ ℓ`. If we assume that `A * x * C`, the `finish` tactic will close the goal. Because the fact that `A * x * C` implies that `x ∈ ℓ`, then we reach a contradiction with `x ∈ ∅`. Therefore, the first case is proved. **Proof (b):** Note that the point `x` being an element of the empty set cannot imply that `x` is an element of the intersection between the segment `A·C` and the line ℓ, since this is not an empty set. Then, propositional logic proves this case. (You can use the `tauto` tactic to solve it in Lean.) Therefore, we have proved that there exists a point P such that P is an element of the segment `A·C` and that `P ∈ ℓ`. -/ /- Hint : Click here for a hint, in case you get stuck. To solve this level, we have used high levels tactics which weren't taught in the Tutorial World.. In case you feel bewildered, do not hesitate to click on "View source" (located on the top right corner of the game screen) to see the solution. -/ variables {Ω : Type} [IncidencePlane Ω] --hide variables {A B C P Q R : Ω} --hide variables {ℓ r s t : Line Ω} --hide /- Lemma : If two points A and C are not on the same side of the line ℓ, there exists a point in the segment A·C which is incident with the line ℓ. -/ lemma not_same_side_intersection (h : ¬ same_side ℓ A C) : ∃ P , P ∈ pts (A⬝C) ∧ P ∈ ℓ := begin simp, by_contra hlAC, push_neg at hlAC, apply h, unfold same_side, ext, split, { intro hx, simp, specialize hlAC x, have hAxC : A*x*C, { finish, }, apply hlAC, { tauto, }, { finish, }, }, { tauto, }, end
Pneumocystis jiroveci antibody LS-C528763 is a biotin-conjugated mouse monoclonal antibody to pneumocystis jiroveci Pneumocystis jiroveci. Validated for IF and WB. Pneumocystis carinii cysts and trophozoites. Recognizes an antigen at ~50kD.
State Before: c : Char cs : List Char b e : Pos ⊢ go₁ (c :: cs) 0 (b + c) (e + c) = go₁ cs 0 b e State After: c : Char cs : List Char b e : Pos ⊢ go₁ cs (0 + c) (b + c) (e + c) = go₁ cs 0 b e Tactic: simp [go₁, Pos.ext_iff, Nat.ne_of_lt add_csize_pos] State Before: c : Char cs : List Char b e : Pos ⊢ go₁ cs (0 + c) (b + c) (e + c) = go₁ cs 0 b e State After: no goals Tactic: apply go₁_add_right_cancel
lemma measurable_Max_nat[measurable (raw)]: fixes P :: "nat \<Rightarrow> 'a \<Rightarrow> bool" assumes [measurable]: "\<And>i. Measurable.pred M (P i)" shows "(\<lambda>x. Max {i. P i x}) \<in> measurable M (count_space UNIV)"
function test03 ( dim_num, level_max ) %*****************************************************************************80 % %% TEST03 call SPARSE_GRID_GL to create a Gauss-Legendre sparse grid. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 26 September 2007 % % Author: % % John Burkardt % % Parameters: % % Input, integer DIM_NUM, the spatial dimension. % % Input, integer LEVEL_MAX, the level. % fprintf ( 1, '\n' ); fprintf ( 1, 'TEST03:\n' ); fprintf ( 1, ' SPARSE_GRID_GL makes a sparse Gauss-Legendre grid.\n' ); level_min = max ( 0, level_max + 1 - dim_num ); fprintf ( 1, '\n' ); fprintf ( 1, ' LEVEL_MIN = %d\n', level_min ); fprintf ( 1, ' LEVEL_MAX = %d\n', level_max ); fprintf ( 1, ' Spatial dimension DIM_NUM = %d\n', dim_num ); % % Determine the number of points. % point_num = sparse_grid_gl_size ( dim_num, level_max ); fprintf ( 1, '\n' ); fprintf ( 1, ' Number of unique points in the grid = %d\n', point_num ); % % Compute the weights and points. % [ grid_weight, grid_point ] = sparse_grid_gl ( dim_num, level_max, point_num ); % % Print them out. % fprintf ( 1, '\n' ); fprintf ( 1, ' Grid weights:\n' ); fprintf ( 1, '\n' ); for point = 1 : point_num fprintf ( 1, ' %4d %10f\n', point, grid_weight(point) ); end fprintf ( 1, '\n' ); fprintf ( 1, ' Grid points:\n' ); fprintf ( 1, '\n' ); for point = 1 : point_num fprintf ( 1, ' %4d', point ); for dim = 1 : dim_num fprintf ( 1, '%10f', grid_point(dim,point) ); end fprintf ( 1, '\n' ); end return end
# Copyright (c) 2018-2021, Carnegie Mellon University # See LICENSE for details Import(paradigms.common, paradigms.vector.breakdown); # NOTE: Phase out!! Enable_tSPL := function() Print("\n\nImportant change: \"Enable_tSPL\" is to be phased out -- use \"tSPL_Globals.getDPOpts()\" and ask Franz\n\n"); SwitchRulesQuiet(DFT, []); SwitchRulesQuiet(WHT, []); SwitchRulesQuiet(MDDFT, []); SwitchRulesName([DFT_Base, DFT_Rader, DFT_SplitRadix, DFT_tSPL_CT, DFT_CT, WHT_Base, WHT_tSPL_BinSplit, MDDFT_Base, MDDFT_tSPL_RowCol, WHT_tSPL_Pease], true); SwitchRulesName([DFT_vecrec, IxA_L_vecrec, DFT_vecrec_T, L_IxA_vecrec], USE_VECREC); SwitchRulesName([IxA_L_vec, L_IxA_vec], true); end; Class(tSPL_Globals, rec( getDPOpts := self >> rec(breakdownRules := self.breakdownRules()), breakdownRules := self >> rec( DFT := [ DFT_Base, DFT_Rader, DFT_SplitRadix, DFT_CT_Mincost, DFT_GoodThomas, DFT_tSPL_CT, DFT_tSPL_Rader, DFT_CT ], WHT := [ WHT_Base, WHT_tSPL_BinSplit, WHT_tSPL_Pease ], MDDFT := [ MDDFT_Base, MDDFT_tSPL_RowCol ], TTensor := [ AxI_IxB, IxB_AxI ], TTensorI := [ IxA_base, AxI_base, IxA_L_base, L_IxA_base ], TL := [ L_base ], #D TTag := [ TTag_down ], TRC := [TRC_tag ], TDiag := [ TDiag_tag ], TRaderMid:= [ TRaderMid_tag ], TDirectSum := [ A_dirsum_B ], TCompose := [ TCompose_tag ], TICompose := [ TICompose_tag ], TGrp := [ TGrp_tag ], TDR := [TDR_base ] ) )); # [DFT_vecrec, IxA_L_vecrec, DFT_vecrec_T, L_IxA_vecrec], USE_VECREC # [IxA_L_vec_LS, L_IxA_vec_LS], USE_LOOPSPLITTING
Section ml. Theorem Dm_alln: forall A:Set -> Prop, (forall x:Set, ~ A x) -> (~ exists x:Set, A x). Proof. intro f. intro h0. intro h1. case h1. intro x. intro fx. apply h0 with x. assumption. Qed. End ml. Check Dm_alln.
import set_theory.game open pgame namespace pgame local infix ` ≈ ` := pgame.equiv theorem equiv_of_mk_equiv {x y : pgame} (L : x.left_moves ≃ y.left_moves) (R : x.right_moves ≃ y.right_moves) (hl : ∀ (i : x.left_moves), x.move_left i ≈ y.move_left (L i)) (hr : ∀ (j : y.right_moves), x.move_right (R.symm j) ≈ y.move_right j) : x ≈ y := sorry theorem equiv_of_game_eq {x y : pgame} (L : x.left_moves ≃ y.left_moves) (R : x.right_moves ≃ y.right_moves) (hl : ∀ (i : x.left_moves), ⟦x.move_left i⟧ = ⟦y.move_left (L i)⟧) (hr : ∀ (j : y.right_moves), ⟦x.move_right (R.symm j)⟧ = ⟦y.move_right j⟧) : -- (hl : ∀ (i : x.left_moves), x.move_left i ≈ y.move_left (L i)) -- (hr : ∀ (j : y.right_moves), x.move_right (R.symm j) ≈ y.move_right j) : x ≈ y := sorry -- begin -- fsplit; rw le_def, -- { exact ⟨λ i, or.inl ⟨L i, (hl i).1⟩, λ j, or.inr ⟨R.symm j, (hr j).1⟩⟩ }, -- { fsplit; apply quotient.sound, -- { intro i, -- left, -- specialize hl (L.symm i), -- simp only [move_left_mk, equiv.apply_symm_apply] at hl, -- use ⟨L.symm i, hl.2⟩ }, -- { intro j, -- right, -- specialize hr (R j), -- simp only [move_right_mk, equiv.symm_apply_apply] at hr, -- use ⟨R j, hr.2⟩ } } -- end #check add_congr def mul (x y : pgame) : pgame := begin induction x with xl xr xL xR IHxl IHxr generalizing y, induction y with yl yr yL yR IHyl IHyr, have y := mk yl yr yL yR, refine ⟨xl × yl ⊕ xr × yr, xl × yr ⊕ xr × yl, _, _⟩; rintro (⟨i, j⟩ | ⟨i, j⟩), { exact IHxl i y + IHyl j - IHxl i (yL j) }, { exact IHxr i y + IHyr j - IHxr i (yR j) }, { exact IHxl i y + IHyr j - IHxl i (yR j) }, { exact IHxr i y + IHyl j - IHxr i (yL j) } end instance : has_mul pgame := ⟨mul⟩ theorem mul_congr {w x y z : pgame} (h₁ : w ≈ x) (h₂ : y ≈ z) : w * y ≈ x * z := begin refine equiv_of_mk_equiv _ _ _ _, end end pgame
##INVESTIGATE COST OF SLICE SAMPLING WITHIN RE-ABC using RareEventABC ##GENERATE OBSERVATIONS srand(1); d = 25; yobs = randn(d) .* 3.0; a = RareEventABC.IIDNormalDetails(yobs, d); ##INITIALISE SMC TUNING CHOICES nparticles = 200; parameters = [3.0]; schedule = doSMC(a, [3.0], 1.35, nparticles=200, quiet=true).schedule ##SPECIALISED VERSIONS OF SMC SUBROUTINES FOR THIS INVESTIGATION ##Slice sampling outputting the number of iterations required function slicesample_(u::Array{Float64, 1}, dosim::Function, epsilon::Float64; w=1.0) ##Initialisation p = length(u) v = randn(p) a = -rand()*w b = w + a nits = 0 ##Main loop while true z = a + rand() * (b-a) uprop = RareEventABC.reflect(u+z*v) sim, dist = dosim(uprop) ##Profiling suggests this line doesn't cause type-stability problems nits += 1 if dist <= epsilon return uprop, sim, z, nits end if z < 0 a = z else b = z end end end ##Update particles storing mean number of slice sampling iterations required function updateParticles_!(a::RareEventABC.IIDNormalDetails, p::RareEventABC.IIDNormalParticles, θ::Array{Float64, 1}, mean_ss_its::Vector; adaptive_w = true) function dosim(u::Array{Float64, 1}) y = RareEventABC.u2y(u, θ[1]) d = RareEventABC.getDistance(a, y) return (y, d) end z = zeros(p.nparticles) s = zeros(p.nparticles) for i in 1:p.nparticles if adaptive_w p.u[i], p.y[i], z[i], s[i] = slicesample_(p.u[i], dosim, p.ε, w=min(1.0,2.0*p.maxz)) else p.u[i], p.y[i], z[i], s[i] = slicesample_(p.u[i], dosim, p.ε) end end p.maxz = maximum(abs(z)) push!(mean_ss_its, mean(s)) return nothing end ##SMC - as usual but call functions above function doSMC_(a::RareEventABC.ApplicationDetails, parameters::Array{Float64, 1}, schedule::Array{Float64, 1}, mean_ss_its::Vector; nparticles=200, llBound=-Inf, d=0, quiet=false, adaptive_w = true) ##Initialise SMC, including sampling from prior particles::RareEventABC.Particles = RareEventABC.Particles(a, nparticles, parameters) particles.schedule = schedule particles.llest = lgamma(1+d/2)-(d/2)*log(pi)-d*log(schedule[end]) ##log(1/V) where V is Lebesgue measure of a radius schedule[end] and dimension d particles.iteration = 0 ##Number of *completed* iterations particles.maxz = 1.0 ##Override what's currently in RareEventABC! ##Main loop nits = length(schedule) for ε in schedule particles.ε = ε dists::Array{Float64, 1} = RareEventABC.getDistances(a, particles) acc = (dists .<= ε) particles.llest += log(mean(acc)) particles.iteration += 1 ##quiet || report(a, particles, schedule[end], d, false) if particles.llest <= llBound particles.reachedBound = true break end if particles.iteration < nits ##These steps can be skipped on the last iteration RareEventABC.resample!(particles, acc) updateParticles_!(a, particles, parameters, mean_ss_its, adaptive_w=adaptive_w) end end particles end ##A DETAILED COMPARISON S_adaptive = Float64[]; S_nonadaptive = Float64[]; srand(2); doSMC_(a, [3.0], schedule, S_adaptive, nparticles=200, quiet=true, adaptive_w = true).llest doSMC_(a, [3.0], schedule, S_nonadaptive, nparticles=200, quiet=true, adaptive_w = false).llest using DataFrames using Plots; pgfplots() using StatPlots df = vcat(DataFrame(iteration=1:length(schedule)-1, mean_its=S_adaptive, w="adaptive"), DataFrame(iteration=1:length(schedule)-1, mean_its=S_nonadaptive, w="nonadaptive")); default(guidefont=font(25), tickfont=font(25), legendfont=font(25), size=(500,500)); p1 = scatter(df, :iteration, :mean_its, group=:w, marker=:auto, xlabel="SMC iteration", ylabel="Mean slice sampling iterations", ylims=(1.0,11.0)); ##Hack to prevent legend getting in the way savefig(p1, "slice_cost.pdf") ##REPEATED COMPARISONS TO SEE HOW TIME COST AND LIKELIHOOD ESTIMATES DIFFER srand(0); ll_adaptive = @time Float64[doSMC_(a, [3.0], schedule, S_adaptive, nparticles=200, quiet=true, adaptive_w = true).llest for i in 1:50]; ll_nonadaptive = @time Float64[doSMC_(a, [3.0], schedule, S_nonadaptive, nparticles=200, quiet=true, adaptive_w = false).llest for i in 1:50]; using HypothesisTests UnequalVarianceTTest(exp(ll_adaptive), exp(ll_nonadaptive)) std(ll_adaptive) std(ll_nonadaptive)
#include <boost/preprocessor/facilities/is_empty.hpp>
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Sébastien Gouëzel, Heather Macbeth -/ import analysis.inner_product_space.projection import analysis.normed_space.pi_Lp /-! # `L²` inner product space structure on finite products of inner product spaces The `L²` norm on a finite product of inner product spaces is compatible with an inner product $$ \langle x, y\rangle = \sum \langle x_i, y_i \rangle. $$ This is recorded in this file as an inner product space instance on `pi_Lp 2`. ## Main definitions - `euclidean_space 𝕜 n`: defined to be `pi_Lp 2 (n → 𝕜)` for any `fintype n`, i.e., the space from functions to `n` to `𝕜` with the `L²` norm. We register several instances on it (notably that it is a finite-dimensional inner product space). - `orthonormal_basis 𝕜 ι`: defined to be an isometry to Euclidean space from a given finite-dimensional innner product space, `E ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι`. - `basis.to_orthonormal_basis`: constructs an `orthonormal_basis` for a finite-dimensional Euclidean space from a `basis` which is `orthonormal`. - `linear_isometry_equiv.of_inner_product_space`: provides an arbitrary isometry to Euclidean space from a given finite-dimensional inner product space, induced by choosing an arbitrary basis. - `complex.isometry_euclidean`: standard isometry from `ℂ` to `euclidean_space ℝ (fin 2)` -/ open real set filter is_R_or_C open_locale big_operators uniformity topological_space nnreal ennreal complex_conjugate direct_sum noncomputable theory variables {ι : Type*} variables {𝕜 : Type*} [is_R_or_C 𝕜] {E : Type*} [inner_product_space 𝕜 E] variables {E' : Type*} [inner_product_space 𝕜 E'] variables {F : Type*} [inner_product_space ℝ F] variables {F' : Type*} [inner_product_space ℝ F'] local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y /- If `ι` is a finite type and each space `f i`, `i : ι`, is an inner product space, then `Π i, f i` is an inner product space as well. Since `Π i, f i` is endowed with the sup norm, we use instead `pi_Lp 2 f` for the product space, which is endowed with the `L^2` norm. -/ instance pi_Lp.inner_product_space {ι : Type*} [fintype ι] (f : ι → Type*) [Π i, inner_product_space 𝕜 (f i)] : inner_product_space 𝕜 (pi_Lp 2 f) := { inner := λ x y, ∑ i, inner (x i) (y i), norm_sq_eq_inner := begin intro x, have h₁ : ∑ (i : ι), ∥x i∥ ^ (2 : ℕ) = ∑ (i : ι), ∥x i∥ ^ (2 : ℝ), { apply finset.sum_congr rfl, intros j hj, simp [←rpow_nat_cast] }, have h₂ : 0 ≤ ∑ (i : ι), ∥x i∥ ^ (2 : ℝ), { rw [←h₁], exact finset.sum_nonneg (λ j (hj : j ∈ finset.univ), pow_nonneg (norm_nonneg (x j)) 2) }, simp [norm, add_monoid_hom.map_sum, ←norm_sq_eq_inner], rw [←rpow_nat_cast ((∑ (i : ι), ∥x i∥ ^ (2 : ℝ)) ^ (2 : ℝ)⁻¹) 2], rw [←rpow_mul h₂], norm_num [h₁], end, conj_sym := begin intros x y, unfold inner, rw ring_hom.map_sum, apply finset.sum_congr rfl, rintros z -, apply inner_conj_sym, end, add_left := λ x y z, show ∑ i, inner (x i + y i) (z i) = ∑ i, inner (x i) (z i) + ∑ i, inner (y i) (z i), by simp only [inner_add_left, finset.sum_add_distrib], smul_left := λ x y r, show ∑ (i : ι), inner (r • x i) (y i) = (conj r) * ∑ i, inner (x i) (y i), by simp only [finset.mul_sum, inner_smul_left] } @[simp] lemma pi_Lp.inner_apply {ι : Type*} [fintype ι] {f : ι → Type*} [Π i, inner_product_space 𝕜 (f i)] (x y : pi_Lp 2 f) : ⟪x, y⟫ = ∑ i, ⟪x i, y i⟫ := rfl lemma pi_Lp.norm_eq_of_L2 {ι : Type*} [fintype ι] {f : ι → Type*} [Π i, inner_product_space 𝕜 (f i)] (x : pi_Lp 2 f) : ∥x∥ = sqrt (∑ (i : ι), ∥x i∥ ^ 2) := by { rw [pi_Lp.norm_eq_of_nat 2]; simp [sqrt_eq_rpow] } /-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional space use `euclidean_space 𝕜 (fin n)`. -/ @[reducible, nolint unused_arguments] def euclidean_space (𝕜 : Type*) [is_R_or_C 𝕜] (n : Type*) [fintype n] : Type* := pi_Lp 2 (λ (i : n), 𝕜) lemma euclidean_space.norm_eq {𝕜 : Type*} [is_R_or_C 𝕜] {n : Type*} [fintype n] (x : euclidean_space 𝕜 n) : ∥x∥ = real.sqrt (∑ (i : n), ∥x i∥ ^ 2) := pi_Lp.norm_eq_of_L2 x variables [fintype ι] section local attribute [reducible] pi_Lp instance : finite_dimensional 𝕜 (euclidean_space 𝕜 ι) := by apply_instance instance : inner_product_space 𝕜 (euclidean_space 𝕜 ι) := by apply_instance @[simp] lemma finrank_euclidean_space : finite_dimensional.finrank 𝕜 (euclidean_space 𝕜 ι) = fintype.card ι := by simp lemma finrank_euclidean_space_fin {n : ℕ} : finite_dimensional.finrank 𝕜 (euclidean_space 𝕜 (fin n)) = n := by simp /-- A finite, mutually orthogonal family of subspaces of `E`, which span `E`, induce an isometry from `E` to `pi_Lp 2` of the subspaces equipped with the `L2` inner product. -/ def direct_sum.submodule_is_internal.isometry_L2_of_orthogonal_family [decidable_eq ι] {V : ι → submodule 𝕜 E} (hV : direct_sum.submodule_is_internal V) (hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) : E ≃ₗᵢ[𝕜] pi_Lp 2 (λ i, V i) := begin let e₁ := direct_sum.linear_equiv_fun_on_fintype 𝕜 ι (λ i, V i), let e₂ := linear_equiv.of_bijective _ hV.injective hV.surjective, refine (e₂.symm.trans e₁).isometry_of_inner _, suffices : ∀ v w, ⟪v, w⟫ = ⟪e₂ (e₁.symm v), e₂ (e₁.symm w)⟫, { intros v₀ w₀, convert this (e₁ (e₂.symm v₀)) (e₁ (e₂.symm w₀)); simp only [linear_equiv.symm_apply_apply, linear_equiv.apply_symm_apply] }, intros v w, transitivity ⟪(∑ i, (V i).subtypeₗᵢ (v i)), ∑ i, (V i).subtypeₗᵢ (w i)⟫, { simp only [sum_inner, hV'.inner_right_fintype, pi_Lp.inner_apply] }, { congr; simp } end @[simp] lemma direct_sum.submodule_is_internal.isometry_L2_of_orthogonal_family_symm_apply [decidable_eq ι] {V : ι → submodule 𝕜 E} (hV : direct_sum.submodule_is_internal V) (hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) (w : pi_Lp 2 (λ i, V i)) : (hV.isometry_L2_of_orthogonal_family hV').symm w = ∑ i, (w i : E) := begin classical, let e₁ := direct_sum.linear_equiv_fun_on_fintype 𝕜 ι (λ i, V i), let e₂ := linear_equiv.of_bijective _ hV.injective hV.surjective, suffices : ∀ v : ⨁ i, V i, e₂ v = ∑ i, e₁ v i, { exact this (e₁.symm w) }, intros v, simp [e₂, direct_sum.submodule_coe, direct_sum.to_module, dfinsupp.sum_add_hom_apply] end end /-- The vector given in euclidean space by being `1 : 𝕜` at coordinate `i : ι` and `0 : 𝕜` at all other coordinates. -/ def euclidean_space.single [decidable_eq ι] (i : ι) (a : 𝕜) : euclidean_space 𝕜 ι := pi.single i a @[simp] theorem euclidean_space.single_apply [decidable_eq ι] (i : ι) (a : 𝕜) (j : ι) : (euclidean_space.single i a) j = ite (j = i) a 0 := by { rw [euclidean_space.single, ← pi.single_apply i a j] } lemma euclidean_space.inner_single_left [decidable_eq ι] (i : ι) (a : 𝕜) (v : euclidean_space 𝕜 ι) : ⟪euclidean_space.single i (a : 𝕜), v⟫ = conj a * (v i) := by simp [apply_ite conj] lemma euclidean_space.inner_single_right [decidable_eq ι] (i : ι) (a : 𝕜) (v : euclidean_space 𝕜 ι) : ⟪v, euclidean_space.single i (a : 𝕜)⟫ = a * conj (v i) := by simp [apply_ite conj, mul_comm] variables (ι 𝕜 E) /-- An orthonormal basis on E is an identification of `E` with its dimensional-matching `euclidean_space 𝕜 ι`. -/ structure orthonormal_basis := of_repr :: (repr : E ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι) variables {ι 𝕜 E} namespace orthonormal_basis instance : inhabited (orthonormal_basis ι 𝕜 (euclidean_space 𝕜 ι)) := ⟨of_repr (linear_isometry_equiv.refl 𝕜 (euclidean_space 𝕜 ι))⟩ /-- `b i` is the `i`th basis vector. -/ instance : has_coe_to_fun (orthonormal_basis ι 𝕜 E) (λ _, ι → E) := { coe := λ b i, by classical; exact b.repr.symm (euclidean_space.single i (1 : 𝕜)) } @[simp] protected lemma repr_symm_single [decidable_eq ι] (b : orthonormal_basis ι 𝕜 E) (i : ι) : b.repr.symm (euclidean_space.single i (1:𝕜)) = b i := by { classical, congr, simp, } @[simp] protected lemma repr_self [decidable_eq ι] (b : orthonormal_basis ι 𝕜 E) (i : ι) : b.repr (b i) = euclidean_space.single i (1:𝕜) := begin classical, rw [← b.repr_symm_single i, linear_isometry_equiv.apply_symm_apply], congr, simp, end protected lemma repr_apply_apply (b : orthonormal_basis ι 𝕜 E) (v : E) (i : ι) : b.repr v i = ⟪b i, v⟫ := begin classical, rw [← b.repr.inner_map_map (b i) v, b.repr_self i, euclidean_space.inner_single_left], simp only [one_mul, eq_self_iff_true, map_one], end @[simp] protected lemma orthonormal (b : orthonormal_basis ι 𝕜 E) : orthonormal 𝕜 b := begin classical, rw orthonormal_iff_ite, intros i j, rw [← b.repr.inner_map_map (b i) (b j), b.repr_self i, b.repr_self j], rw euclidean_space.inner_single_left, rw euclidean_space.single_apply, simp only [mul_boole, map_one], end /-- The `basis ι 𝕜 E` underlying the `orthonormal_basis` --/ protected def to_basis (b : orthonormal_basis ι 𝕜 E) : basis ι 𝕜 E := basis.of_equiv_fun b.repr.to_linear_equiv @[simp] protected lemma coe_to_basis (b : orthonormal_basis ι 𝕜 E) : (⇑b.to_basis : ι → E) = ⇑b := begin change ⇑(basis.of_equiv_fun b.repr.to_linear_equiv) = b, ext j, rw basis.coe_of_equiv_fun, simp only [orthonormal_basis.repr_symm_single], congr, end @[simp] protected lemma coe_to_basis_repr (b : orthonormal_basis ι 𝕜 E) : b.to_basis.equiv_fun = b.repr.to_linear_equiv := begin change (basis.of_equiv_fun b.repr.to_linear_equiv).equiv_fun = b.repr.to_linear_equiv, ext x j, simp only [basis.of_equiv_fun_repr_apply, eq_self_iff_true, linear_isometry_equiv.coe_to_linear_equiv, basis.equiv_fun_apply], end protected lemma sum_repr_symm (b : orthonormal_basis ι 𝕜 E) (v : euclidean_space 𝕜 ι) : ∑ i , v i • b i = (b.repr.symm v) := by { classical, simpa using (b.to_basis.equiv_fun_symm_apply v).symm } variable {v : ι → E} /-- A basis that is orthonormal is an orthonormal basis. -/ def _root_.basis.to_orthonormal_basis (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : orthonormal_basis ι 𝕜 E := orthonormal_basis.of_repr $ linear_equiv.isometry_of_inner v.equiv_fun begin intros x y, let p : euclidean_space 𝕜 ι := v.equiv_fun x, let q : euclidean_space 𝕜 ι := v.equiv_fun y, have key : ⟪p, q⟫ = ⟪∑ i, p i • v i, ∑ i, q i • v i⟫, { simp [sum_inner, inner_smul_left, hv.inner_right_fintype] }, convert key, { rw [← v.equiv_fun.symm_apply_apply x, v.equiv_fun_symm_apply] }, { rw [← v.equiv_fun.symm_apply_apply y, v.equiv_fun_symm_apply] } end @[simp] lemma _root_.basis.coe_to_orthonormal_basis_repr (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : ((v.to_orthonormal_basis hv).repr : E → euclidean_space 𝕜 ι) = v.equiv_fun := rfl @[simp] lemma _root_.basis.coe_to_orthonormal_basis_repr_symm (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : ((v.to_orthonormal_basis hv).repr.symm : euclidean_space 𝕜 ι → E) = v.equiv_fun.symm := rfl @[simp] lemma _root_.basis.to_basis_to_orthonormal_basis (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : (v.to_orthonormal_basis hv).to_basis = v := by simp [basis.to_orthonormal_basis, orthonormal_basis.to_basis] @[simp] lemma _root_.basis.coe_to_orthonormal_basis (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : (v.to_orthonormal_basis hv : ι → E) = (v : ι → E) := calc (v.to_orthonormal_basis hv : ι → E) = ((v.to_orthonormal_basis hv).to_basis : ι → E) : by { classical, rw orthonormal_basis.coe_to_basis } ... = (v : ι → E) : by simp /-- An orthonormal set that spans is an orthonormal basis -/ protected def mk (hon : orthonormal 𝕜 v) (hsp: submodule.span 𝕜 (set.range v) = ⊤): orthonormal_basis ι 𝕜 E := (basis.mk (orthonormal.linear_independent hon) hsp).to_orthonormal_basis (by rwa basis.coe_mk) @[simp] protected lemma coe_mk (hon : orthonormal 𝕜 v) (hsp: submodule.span 𝕜 (set.range v) = ⊤) : ⇑(orthonormal_basis.mk hon hsp) = v := by classical; rw [orthonormal_basis.mk, _root_.basis.coe_to_orthonormal_basis, basis.coe_mk] end orthonormal_basis /-- If `f : E ≃ₗᵢ[𝕜] E'` is a linear isometry of inner product spaces then an orthonormal basis `v` of `E` determines a linear isometry `e : E' ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι`. This result states that `e` may be obtained either by transporting `v` to `E'` or by composing with the linear isometry `E ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι` provided by `v`. -/ @[simp] lemma basis.map_isometry_euclidean_of_orthonormal (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') : ((v.map f.to_linear_equiv).to_orthonormal_basis (hv.map_linear_isometry_equiv f)).repr = f.symm.trans (v.to_orthonormal_basis hv).repr := linear_isometry_equiv.to_linear_equiv_injective $ v.map_equiv_fun _ /-- `ℂ` is isometric to `ℝ²` with the Euclidean inner product. -/ def complex.isometry_euclidean : ℂ ≃ₗᵢ[ℝ] (euclidean_space ℝ (fin 2)) := (complex.basis_one_I.to_orthonormal_basis begin rw orthonormal_iff_ite, intros i, fin_cases i; intros j; fin_cases j; simp [real_inner_eq_re_inner] end).repr @[simp] lemma complex.isometry_euclidean_symm_apply (x : euclidean_space ℝ (fin 2)) : complex.isometry_euclidean.symm x = (x 0) + (x 1) * I := begin convert complex.basis_one_I.equiv_fun_symm_apply x, { simpa }, { simp }, end lemma complex.isometry_euclidean_proj_eq_self (z : ℂ) : ↑(complex.isometry_euclidean z 0) + ↑(complex.isometry_euclidean z 1) * (I : ℂ) = z := by rw [← complex.isometry_euclidean_symm_apply (complex.isometry_euclidean z), complex.isometry_euclidean.symm_apply_apply z] @[simp] lemma complex.isometry_euclidean_apply_zero (z : ℂ) : complex.isometry_euclidean z 0 = z.re := by { conv_rhs { rw ← complex.isometry_euclidean_proj_eq_self z }, simp } @[simp] lemma complex.isometry_euclidean_apply_one (z : ℂ) : complex.isometry_euclidean z 1 = z.im := by { conv_rhs { rw ← complex.isometry_euclidean_proj_eq_self z }, simp } /-- The isometry between `ℂ` and a two-dimensional real inner product space given by a basis. -/ def complex.isometry_of_orthonormal {v : basis (fin 2) ℝ F} (hv : orthonormal ℝ v) : ℂ ≃ₗᵢ[ℝ] F := complex.isometry_euclidean.trans (v.to_orthonormal_basis hv).repr.symm @[simp] lemma complex.map_isometry_of_orthonormal {v : basis (fin 2) ℝ F} (hv : orthonormal ℝ v) (f : F ≃ₗᵢ[ℝ] F') : complex.isometry_of_orthonormal (hv.map_linear_isometry_equiv f) = (complex.isometry_of_orthonormal hv).trans f := by simp [complex.isometry_of_orthonormal, linear_isometry_equiv.trans_assoc] lemma complex.isometry_of_orthonormal_symm_apply {v : basis (fin 2) ℝ F} (hv : orthonormal ℝ v) (f : F) : (complex.isometry_of_orthonormal hv).symm f = (v.coord 0 f : ℂ) + (v.coord 1 f : ℂ) * I := by simp [complex.isometry_of_orthonormal] lemma complex.isometry_of_orthonormal_apply {v : basis (fin 2) ℝ F} (hv : orthonormal ℝ v) (z : ℂ) : complex.isometry_of_orthonormal hv z = z.re • v 0 + z.im • v 1 := by simp [complex.isometry_of_orthonormal, (dec_trivial : (finset.univ : finset (fin 2)) = {0, 1})] open finite_dimensional /-- Given a natural number `n` equal to the `finrank` of a finite-dimensional inner product space, there exists an isometry from the space to `euclidean_space 𝕜 (fin n)`. -/ def linear_isometry_equiv.of_inner_product_space [finite_dimensional 𝕜 E] {n : ℕ} (hn : finrank 𝕜 E = n) : E ≃ₗᵢ[𝕜] (euclidean_space 𝕜 (fin n)) := ((fin_std_orthonormal_basis hn).to_orthonormal_basis (fin_std_orthonormal_basis_orthonormal hn)).repr local attribute [instance] fact_finite_dimensional_of_finrank_eq_succ /-- Given a natural number `n` one less than the `finrank` of a finite-dimensional inner product space, there exists an isometry from the orthogonal complement of a nonzero singleton to `euclidean_space 𝕜 (fin n)`. -/ def linear_isometry_equiv.from_orthogonal_span_singleton (n : ℕ) [fact (finrank 𝕜 E = n + 1)] {v : E} (hv : v ≠ 0) : (𝕜 ∙ v)ᗮ ≃ₗᵢ[𝕜] (euclidean_space 𝕜 (fin n)) := linear_isometry_equiv.of_inner_product_space (finrank_orthogonal_span_singleton hv) section linear_isometry variables {V : Type*} [inner_product_space 𝕜 V] [finite_dimensional 𝕜 V] variables {S : submodule 𝕜 V} {L : S →ₗᵢ[𝕜] V} open finite_dimensional /-- Let `S` be a subspace of a finite-dimensional complex inner product space `V`. A linear isometry mapping `S` into `V` can be extended to a full isometry of `V`. TODO: The case when `S` is a finite-dimensional subspace of an infinite-dimensional `V`.-/ noncomputable def linear_isometry.extend (L : S →ₗᵢ[𝕜] V): V →ₗᵢ[𝕜] V := begin -- Build an isometry from Sᗮ to L(S)ᗮ through euclidean_space let d := finrank 𝕜 Sᗮ, have dim_S_perp : finrank 𝕜 Sᗮ = d := rfl, let LS := L.to_linear_map.range, have E : Sᗮ ≃ₗᵢ[𝕜] LSᗮ, { have dim_LS_perp : finrank 𝕜 LSᗮ = d, calc finrank 𝕜 LSᗮ = finrank 𝕜 V - finrank 𝕜 LS : by simp only [← LS.finrank_add_finrank_orthogonal, add_tsub_cancel_left] ... = finrank 𝕜 V - finrank 𝕜 S : by simp only [linear_map.finrank_range_of_inj L.injective] ... = finrank 𝕜 Sᗮ : by simp only [← S.finrank_add_finrank_orthogonal, add_tsub_cancel_left] ... = d : dim_S_perp, let BS := ((fin_std_orthonormal_basis dim_S_perp).to_orthonormal_basis (fin_std_orthonormal_basis_orthonormal dim_S_perp)), let BLS := ((fin_std_orthonormal_basis dim_LS_perp).to_orthonormal_basis (fin_std_orthonormal_basis_orthonormal dim_LS_perp)), exact BS.repr.trans BLS.repr.symm }, let L3 := (LS)ᗮ.subtypeₗᵢ.comp E.to_linear_isometry, -- Project onto S and Sᗮ haveI : complete_space S := finite_dimensional.complete 𝕜 S, haveI : complete_space V := finite_dimensional.complete 𝕜 V, let p1 := (orthogonal_projection S).to_linear_map, let p2 := (orthogonal_projection Sᗮ).to_linear_map, -- Build a linear map from the isometries on S and Sᗮ let M := L.to_linear_map.comp p1 + L3.to_linear_map.comp p2, -- Prove that M is an isometry have M_norm_map : ∀ (x : V), ∥M x∥ = ∥x∥, { intro x, -- Apply M to the orthogonal decomposition of x have Mx_decomp : M x = L (p1 x) + L3 (p2 x), { simp only [linear_map.add_apply, linear_map.comp_apply, linear_map.comp_apply, linear_isometry.coe_to_linear_map]}, -- Mx_decomp is the orthogonal decomposition of M x have Mx_orth : ⟪ L (p1 x), L3 (p2 x) ⟫ = 0, { have Lp1x : L (p1 x) ∈ L.to_linear_map.range := L.to_linear_map.mem_range_self (p1 x), have Lp2x : L3 (p2 x) ∈ (L.to_linear_map.range)ᗮ, { simp only [L3, linear_isometry.coe_comp, function.comp_app, submodule.coe_subtypeₗᵢ, ← submodule.range_subtype (LSᗮ)], apply linear_map.mem_range_self}, apply submodule.inner_right_of_mem_orthogonal Lp1x Lp2x}, -- Apply the Pythagorean theorem and simplify rw [← sq_eq_sq (norm_nonneg _) (norm_nonneg _), norm_sq_eq_add_norm_sq_projection x S], simp only [sq, Mx_decomp], rw norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (L (p1 x)) (L3 (p2 x)) Mx_orth, simp only [linear_isometry.norm_map, p1, p2, continuous_linear_map.to_linear_map_eq_coe, add_left_inj, mul_eq_mul_left_iff, norm_eq_zero, true_or, eq_self_iff_true, continuous_linear_map.coe_coe, submodule.coe_norm, submodule.coe_eq_zero] }, exact { to_linear_map := M, norm_map' := M_norm_map }, end lemma linear_isometry.extend_apply (L : S →ₗᵢ[𝕜] V) (s : S): L.extend s = L s := begin haveI : complete_space S := finite_dimensional.complete 𝕜 S, simp only [linear_isometry.extend, continuous_linear_map.to_linear_map_eq_coe, ←linear_isometry.coe_to_linear_map], simp only [add_right_eq_self, linear_isometry.coe_to_linear_map, linear_isometry_equiv.coe_to_linear_isometry, linear_isometry.coe_comp, function.comp_app, orthogonal_projection_mem_subspace_eq_self, linear_map.coe_comp, continuous_linear_map.coe_coe, submodule.coe_subtype, linear_map.add_apply, submodule.coe_eq_zero, linear_isometry_equiv.map_eq_zero_iff, submodule.coe_subtypeₗᵢ, orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero, submodule.orthogonal_orthogonal, submodule.coe_mem], end end linear_isometry section matrix open_locale matrix variables {n m : ℕ} local notation `⟪`x`, `y`⟫ₘ` := @inner 𝕜 (euclidean_space 𝕜 (fin m)) _ x y local notation `⟪`x`, `y`⟫ₙ` := @inner 𝕜 (euclidean_space 𝕜 (fin n)) _ x y /-- The inner product of a row of A and a row of B is an entry of B ⬝ Aᴴ. -/ lemma inner_matrix_row_row (A B : matrix (fin n) (fin m) 𝕜) (i j : (fin n)) : ⟪A i, B j⟫ₘ = (B ⬝ Aᴴ) j i := by {simp only [inner, matrix.mul_apply, star_ring_end_apply, matrix.conj_transpose_apply,mul_comm]} /-- The inner product of a column of A and a column of B is an entry of Aᴴ ⬝ B -/ lemma inner_matrix_col_col (A B : matrix (fin n) (fin m) 𝕜) (i j : (fin m)) : ⟪Aᵀ i, Bᵀ j⟫ₙ = (Aᴴ ⬝ B) i j := rfl end matrix
\section{Methodology} \label{sec:methodology} Given the research objectives identified in Section \ref{sec:objectives}, a new hybrid method that incorporates angular information into the variance reduction parameters it generates will be proposed. The incorporation of angular information will address issues of strong anisotropy in applications, and aid in variance reduction for those problems. In this dissertation, a new hybrid method that incorporates angular information into the variance reduction parameters it generates is proposed. The method, named the $\Omega$-method or CADIS-$\Omega$-method, rests on a strong theoretical basis. As mentioned in Section \ref{sec:motivation}, there are many flavors of hybrid method that exist for radiation transport. The hybrid $\Omega$-methods have been implemented in the Oak Ridge National Laboratory code suite Exnihilo and hybrid methods software ADVANTG.
module TrainUtils where import Control.Lens hiding (para) import System.Random import Control.Monad import Prelude hiding (id, (.)) import Numeric.LinearAlgebra.Array import Numeric.LinearAlgebra.Array.Util import CategoricDefinitions import Autodiff.GAD import Autodiff.Dual import Autodiff.Additive import Autodiff.D import Autodiff.Cont import Ops import Para import TensorUtils import OnesLike ------------------------------------------- showNNInfo :: (ArrShow p, ArrShow a, ArrShow b) => Int -> a -> b -> LearnerType p a b -> IO () showNNInfo n a b nn = do putStrLn "-------------------------" putStrLn $ "Step " ++ arrShow n putStrLn $ "p\n" ++ arrShow (nn ^. p) putStrLn $ "a\n" ++ arrShow a putStrLn $ "a\n" ++ arrShow b -- | Supervised learning training -- Takes in a Learner, input-output pairs and a cost function -- it partially applies the output to the cost function and composes the result inside learner trainStepWithCost :: (OnesLike c, _) => LearnerType p a b -> (Int, IO (a, b), DType (b, b) c) -> IO (LearnerType p a b) trainStepWithCost l (step, dataSampler, cost) = do (i, o) <- dataSampler when (step `mod` 100 == 0) $ showNNInfo step i o l let cost' = partiallyApply cost o (pGrad, _) = grad (cost' . (l ^. para . fn)) (l ^. p, i) return $ l & p .~ (l ^. optimizer) (l ^. p, pGrad) instance (Random a, Random b) => Random (a, b) where random gen1 = let (x, gen2) = random gen1 (y, gen3) = random gen2 in ((x, y), gen3) randomR ((x1, y1), (x2, y2)) gen1 = let (x, gen2) = randomR (x1, x2) gen1 (y, gen3) = randomR (y1, y2) gen2 in ((x, y), gen3)
module Hwequivalence where open import Relation.Binary.PropositionalEquality open import Data.Bool -- A 1-bit adder bit-adder-spec : Bool → Bool → Bool → Bool bit-adder-spec A B C = X ∧ Y where X : Bool X = (A ∧ not B ∧ not C) ∨ (not A ∧ B ∧ not C) ∨ (not A ∧ not B ∧ C) ∨ (A ∧ B ∧ C) Y : Bool Y = (A ∧ B) ∨ (A ∧ C) ∨ (B ∧ C) bit-adder-imp : Bool → Bool → Bool → Bool bit-adder-imp A B C = X ∧ Y where u : Bool u = (A ∧ not B) ∨ (not A ∧ B) v : Bool v = u ∧ C w : Bool w = A ∧ B X : Bool X = (u ∧ not C) ∨ (not u ∧ C) Y : Bool Y = (w ∨ v) data _≃_ {A : Set} (f : A → A) (g : A → A) : Set where f≃g : ((x y : A) → (x ≡ y) → (f x ≡ g y)) → f ≃ g -- Prove equivalence of specification and implementation using -- ≃ data type. equivalence-spec-imp : ∀ (A B : Bool) → (bit-adder-spec A B) ≃ (bit-adder-imp A B) equivalence-spec-imp A B = f≃g (λ x y x₁ → prove x y x₁) where pr1 : (x y : Bool) → (bit-adder-spec x y true) ≡ (bit-adder-imp x y true) pr1 true true = refl pr1 true false = refl pr1 false true = refl pr1 false false = refl pr2 : (x y : Bool) → (bit-adder-spec x y false) ≡ (bit-adder-imp x y false) pr2 true true = refl pr2 true false = refl pr2 false true = refl pr2 false false = refl prove : (x y : Bool) → (p : x ≡ y) → (bit-adder-spec A B x) ≡ (bit-adder-imp A B y) prove true .true refl = pr1 A B prove false .false refl = pr2 A B
----------------------------------------------------------------------------- -- | -- Module : Numeric.Particle -- Copyright : (c) 2016 FP Complete Corporation -- License : MIT (see LICENSE) -- Maintainer : [email protected] -- -- =The Theory -- -- The particle filter, `runPF`, in this library is applicable to the -- state space model given by -- -- \[ -- \begin{aligned} -- \boldsymbol{x}_i &= \boldsymbol{a}_i(\boldsymbol{x}_{i-1}) + \boldsymbol{\psi}_{i-1} \\ -- \boldsymbol{y}_i &= \boldsymbol{h}_i(\boldsymbol{x}_i) + \boldsymbol{\upsilon}_i -- \end{aligned} -- \] -- -- where -- -- * \(\boldsymbol{a_i}\)\ is some non-linear vector-valued possibly -- time-varying state update function. -- -- * \(\boldsymbol{\psi}_{i}\) are independent normally -- distributed random variables with mean 0 representing the fact that -- the state update is noisy: \(\boldsymbol{\psi}_{i} \sim {\cal{N}}(0,Q_i)\). -- -- * \(\boldsymbol{h}_i\)\ is some non-linear vector-valued possibly time-varying -- function describing how we observe the hidden state process. -- -- * \(\boldsymbol{\upsilon}_i\) are independent normally -- distributed random variables with mean 0 represent the fact that -- the observations are noisy: \(\boldsymbol{\upsilon}_{i} \sim {\cal{N}}(0,R_i)\). -- -- Clearly this could be generalised further; anyone wishing for such -- a generalisation is encouraged to contribute to the library. -- -- The smoother, `oneSmoothingPath` implements [Forward filtering / -- backward -- smoothing](https://en.wikipedia.org/wiki/Particle_filter#Backward_particle_smoothers) -- and returns just one path from the particle filter; in most cases, -- this will need to be run many times to provide good estimates of -- the past. Note that `oneSmoothingPath` uses /all/ observation up -- until the current time. This could be generalised to select only a -- window of observations up to the current time. Again, contributions -- to implement this generalisation are welcomed. -- -- = An Extended Example -- -- The equation of motion for a pendulum of unit length subject to -- [Gaussian white -- noise](https://en.wikipedia.org/wiki/White_noise#Mathematical_definitions) -- is -- -- \[ -- \frac{\mathrm{d}^2\alpha}{\mathrm{d}t^2} = -g\sin\alpha + w(t) -- \] -- -- We can discretize this via the usual [Euler method](https://en.wikipedia.org/wiki/Euler_method) -- -- \[ -- \begin{bmatrix} -- x_{1,i} \\ -- x_{2,i} -- \end{bmatrix} -- = -- \begin{bmatrix} -- x_{1,i-1} + x_{2,i-1}\Delta t \\ -- x_{2,i-1} - g\sin x_{1,i-1}\Delta t -- \end{bmatrix} -- + -- \mathbf{q}_{i-1} -- \] -- -- where \(q_i \sim {\mathcal{N}}(0,Q)\) and -- -- \[ -- Q -- = -- \begin{bmatrix} -- \frac{q^c \Delta t^3}{3} & \frac{q^c \Delta t^2}{2} \\ -- \frac{q^c \Delta t^2}{2} & {q^c \Delta t} -- \end{bmatrix} -- \] -- -- Assume that we can only measure the horizontal position of the -- pendulum and further that this measurement is subject to error so that -- -- \[ -- y_i = \sin x_i + r_i -- \] -- -- where \(r_i \sim {\mathcal{N}}(0,R)\). -- -- -- First let's set the time step and the acceleration caused by -- earth's gravity and the covariance matrices for the state and -- observation. -- -- -- > {-# LANGUAGE DataKinds #-} -- > -- > import Numeric.Particle -- > -- > deltaT, g :: Double -- > deltaT = 0.01 -- > g = 9.81 -- > -- > bigQ :: Sym 2 -- > bigQ = sym $ matrix bigQl -- > -- > qc :: Double -- > qc = 0.01 -- > -- > bigQl :: [Double] -- > bigQl = [ qc * deltaT^3 / 3, qc * deltaT^2 / 2, -- > qc * deltaT^2 / 2, qc * deltaT -- > ] -- > -- > bigR :: Sym 1 -- > bigR = sym $ matrix [0.2] -- > -- > data SystemState a = SystemState { x1 :: a, x2 :: a } -- > deriving Show -- > -- > newtype SystemObs a = SystemObs { y1 :: a } -- > deriving Show -- > -- -- We use the data generated using code made available with Simo -- Särkkä's -- [book](http://www.cambridge.org/gb/academic/subjects/statistics-probability/applied-probability-and-stochastic-networks/bayesian-filtering-and-smoothing) -- which starts with an angle of 1.5 radians and an angular velocity -- of 0.0 radians per second. We set our prior to have a mean of 1.6, not too far from the actual value. -- -- > {-# LANGUAGE DataKinds #-} -- > -- > m0 :: PendulumState -- > m0 = vector [1.6, 0] -- > -- > bigP :: Sym 2 -- > bigP = sym $ diag 0.1 -- > -- > initParticles :: R.MonadRandom m => -- > m (Particles (SystemState Double)) -- > initParticles = V.replicateM nParticles $ do -- > r <- R.sample $ R.rvar (Normal m0 bigP) -- > let x1 = fst $ headTail r -- > x2 = fst $ headTail $ snd $ headTail r -- > return $ SystemState { x1 = x1, x2 = x2} -- > -- > nObs :: Int -- > nObs = 200 -- > -- > nParticles :: Int -- > nParticles = 20 -- > -- > (.+), (.*), (.-) :: (Num a) => V.Vector a -> V.Vector a -> V.Vector a -- > (.+) = V.zipWith (+) -- > (.*) = V.zipWith (*) -- > (.-) = V.zipWith (-) -- > -- > stateUpdateP :: Particles (SystemState Double) -> -- > Particles (SystemState Double) -- > stateUpdateP xPrevs = V.zipWith SystemState x1s x2s -- > where -- > ix = V.length xPrevs -- > -- > x1Prevs = V.map x1 xPrevs -- > x2Prevs = V.map x2 xPrevs -- > -- > deltaTs = V.replicate ix deltaT -- > gs = V.replicate ix g -- > x1s = x1Prevs .+ (x2Prevs .* deltaTs) -- > x2s = x2Prevs .- (gs .* (V.map sin x1Prevs) .* deltaTs) -- -- -- <<diagrams/src_Numeric_Particle_diagV.svg#diagram=diagV&height=600&width=500>> -- -- === Code for Plotting -- -- The full code for plotting the results: -- -- > {-# LANGUAGE ExplicitForAll #-} -- > {-# LANGUAGE TypeOperators #-} -- > {-# LANGUAGE DataKinds #-} -- > -- > import qualified Graphics.Rendering.Chart as C -- > import Graphics.Rendering.Chart.Backend.Diagrams -- > import Data.Colour -- > import Data.Colour.Names -- > import Data.Default.Class -- > import Control.Lens -- > -- > import Data.Csv -- > import System.IO hiding ( hGetContents ) -- > import Data.ByteString.Lazy ( hGetContents ) -- > import qualified Data.Vector as V -- > -- > import Data.Random.Distribution.Static.MultivariateNormal ( Normal(..) ) -- > import qualified Data.Random as R -- > import Data.Random.Source.PureMT ( pureMT ) -- > import Control.Monad.State ( evalState, replicateM ) -- > -- > import Data.List ( transpose ) -- > -- > import GHC.TypeLits ( KnownNat ) -- > -- > import Numeric.LinearAlgebra.Static -- > -- > chartEstimated :: String -> -- > [(Double, Double)] -> -- > [(Double, Double)] -> -- > [(Double, Double)] -> -- > C.Renderable () -- > chartEstimated title acts obs ests = C.toRenderable layout -- > where -- > -- > actuals = C.plot_lines_values .~ [acts] -- > $ C.plot_lines_style . C.line_color .~ opaque red -- > $ C.plot_lines_title .~ "Actual Trajectory" -- > $ C.plot_lines_style . C.line_width .~ 1.0 -- > $ def -- > -- > measurements = C.plot_points_values .~ obs -- > $ C.plot_points_style . C.point_color .~ opaque blue -- > $ C.plot_points_title .~ "Measurements" -- > $ def -- > -- > estimas = C.plot_lines_values .~ [ests] -- > $ C.plot_lines_style . C.line_color .~ opaque black -- > $ C.plot_lines_title .~ "Inferred Trajectory" -- > $ C.plot_lines_style . C.line_width .~ 1.0 -- > $ def -- > -- > layout = C.layout_title .~ title -- > $ C.layout_plots .~ [C.toPlot actuals, C.toPlot measurements, C.toPlot estimas] -- > $ C.layout_y_axis . C.laxis_title .~ "Angle / Horizontal Displacement" -- > $ C.layout_y_axis . C.laxis_override .~ C.axisGridHide -- > $ C.layout_x_axis . C.laxis_title .~ "Time" -- > $ C.layout_x_axis . C.laxis_override .~ C.axisGridHide -- > $ def -- > -- > stateUpdateNoisy :: R.MonadRandom m => -- > Sym 2 -> -- > Particles (SystemState Double) -> -- > m (Particles (SystemState Double)) -- > stateUpdateNoisy bigQ xPrevs = do -- > let xs = stateUpdateP xPrevs -- > -- > x1s = V.map x1 xs -- > x2s = V.map x2 xs -- > -- > let ix = V.length xPrevs -- > etas <- replicateM ix $ R.sample $ R.rvar (Normal 0.0 bigQ) -- > -- > let eta1s, eta2s :: V.Vector Double -- > eta1s = V.fromList $ map (fst . headTail) etas -- > eta2s = V.fromList $ map (fst . headTail . snd . headTail) etas -- > -- > return (V.zipWith SystemState (x1s .+ eta1s) (x2s .+ eta2s)) -- > -- > obsUpdate :: Particles (SystemState Double) -> -- > Particles (SystemObs Double) -- > obsUpdate xs = V.map (SystemObs . sin . x1) xs -- > -- > weight :: forall a n . KnownNat n => -- > (a -> R n) -> -- > Sym n -> -- > a -> a -> Double -- > weight f bigR obs obsNew = R.pdf (Normal (f obsNew) bigR) (f obs) -- > -- > runFilter :: Particles (SystemObs Double) -> V.Vector (Particles (SystemState Double)) -- > runFilter pendulumSamples = evalState action (pureMT 19) -- > where -- > action = do -- > xs <- initParticles -- > scanMapM -- > (runPF (stateUpdateNoisy bigQ) obsUpdate (weight f bigR)) -- > return -- > xs -- > pendulumSamples -- > -- > testSmoothing :: Particles (SystemObs Double) -> Int -> [Double] -- > testSmoothing ss n = V.toList $ evalState action (pureMT 23) -- > where -- > action = do -- > xss <- V.replicateM n $ oneSmoothingPath (stateUpdateNoisy bigQ) (weight h bigQ) nParticles (runFilter ss) -- > let yss = V.fromList $ map V.fromList $ -- > transpose $ -- > V.toList $ V.map (V.toList) $ -- > xss -- > return $ V.map (/ (fromIntegral n)) $ V.map V.sum $ V.map (V.map x1) yss -- > -- > type PendulumState = R 2 -- > -- > f :: SystemObs Double -> R 1 -- > f = vector . pure . y1 -- > -- > h :: SystemState Double -> R 2 -- > h u = vector [x1 u , x2 u] -- > -- > diagV = do -- > h <- openFile "data/matlabRNGs.csv" ReadMode -- > cs <- hGetContents h -- > let df = (decode NoHeader cs) :: Either String (V.Vector (Double, Double)) -- > case df of -- > Left _ -> error "Whatever" -- > Right generatedSamples -> do -- > let preObs = V.take nObs $ V.map fst generatedSamples -- > let obs = V.toList preObs -- > let acts = V.toList $ V.take nObs $ V.map snd generatedSamples -- > let nus = take nObs (testSmoothing (V.map SystemObs preObs) 50) -- > denv <- defaultEnv C.vectorAlignmentFns 600 500 -- > let charte = chartEstimated "Particle Smoother" -- > (zip [0,1..] acts) -- > (zip [0,1..] obs) -- > (zip [0,1..] nus) -- > return $ fst $ runBackend denv (C.render charte (600, 500)) -- ----------------------------------------------------------------------------- {-# OPTIONS_GHC -Wall #-} {-# LANGUAGE BangPatterns #-} module Numeric.Particle ( runPF , oneSmoothingPath , Particles , Path ) where import Data.Random hiding ( StdNormal, Normal ) import Control.Monad import qualified Data.Vector as V import Data.Vector ( Vector ) import Data.Bits ( shiftR ) type Particles a = Vector a -- ^ As an aid for the reader type Path a = Vector a -- ^ As an aid for the reader runPF :: MonadRandom m => (Particles a -> m (Particles a)) -- ^ System evolution at a point -- \(\boldsymbol{a}_i(\boldsymbol{x})\) -> (Particles a -> Particles b) -- ^ Measurement operator at a point \(\boldsymbol{h}_i\) -> (b -> b -> Double) -- ^ Observation probability density function \(p(\boldsymbol{y}_k|\boldsymbol{x}^{(i)}_k)\) -> Particles a -- ^ Current estimate -- \(\big\{\big(w^{(i)}_k, \boldsymbol{x}^{(i)}_k\big) : i \in \{1,\ldots,N\}\big\}\) -- where \(N\) is the number of particles -> b -- ^ New measurement \(\boldsymbol{y}_i\) -> m (Particles a) -- ^ New estimate -- \(\big\{\big(w^{(i)}_{k+1}, \boldsymbol{x}^{(i)}_{k+1}\big) : i \in \{1,\ldots,N\}\big\}\) -- where \(N\) is the number of particles runPF stateUpdate obsUpdate weight statePrevs obs = do stateNews <- stateUpdate statePrevs let obsNews = obsUpdate stateNews let weights = V.map (weight obs) obsNews cumSumWeights = V.tail $ V.scanl (+) 0 weights totWeight = V.last cumSumWeights nParticles = V.length statePrevs vs <- V.replicateM nParticles (sample $ uniform 0.0 totWeight) let js = indices cumSumWeights vs stateTildes = V.map (stateNews V.!) js return stateTildes oneSmoothingPath :: MonadRandom m => (Particles a -> m (Particles a)) -- ^ System evolution at a point -- \(\boldsymbol{a}_i(\boldsymbol{x})\) -> (a -> a -> Double) -- ^ State probability density function \(p(\boldsymbol{x}^{(i)}_k|\boldsymbol{x}^{(i)}_{k-1})\) -> Int -- ^ Number of particles \(N\) -> (Vector (Particles a)) -- ^ Filtering estimates -- \(\bigg\{\big\{\big(w^{(i)}_{k+1}, \boldsymbol{x}^{(i)}_{k+1}\big) : i \in \{1,\ldots,N\}\big\} : k \in \{1,\ldots,T\}\bigg\}\) -- where \(T\) is the number of timesteps -> m (Path a) -- ^ A path for the smoothed particle \(\{\boldsymbol{x}_k : k \in T\}\) where \(T\) is the number of timesteps oneSmoothingPath stateUpdate weight nParticles filterEstss = do let ys = filterEstss ix <- sample $ uniform 0 (nParticles - 1) let xn = (V.head ys) V.! ix scanMapM (oneSmoothingStep stateUpdate weight) return xn (V.tail ys) oneSmoothingStep :: MonadRandom m => (Particles a -> m (Particles a)) -> (a -> a -> Double) -> a -> Particles a -> m a oneSmoothingStep stateUpdate stateDensity smoothingSampleAtiPlus1 filterSamplesAti = do it where it = do mus <- stateUpdate filterSamplesAti let weights = V.map (stateDensity smoothingSampleAtiPlus1) mus cumSumWeights = V.tail $ V.scanl (+) 0 weights totWeight = V.last cumSumWeights v <- sample $ uniform 0.0 totWeight let ix = binarySearch cumSumWeights v xnNew = filterSamplesAti V.! ix return $ xnNew indices :: Vector Double -> Vector Double -> Vector Int indices bs xs = V.map (binarySearch bs) xs binarySearch :: (Ord a) => Vector a -> a -> Int binarySearch vec x = loop 0 (V.length vec - 1) where loop !l !u | u <= l = l | otherwise = let e = vec V.! k in if x <= e then loop l k else loop (k+1) u where k = l + (u - l) `shiftR` 1 scanMapM :: Monad m => (s -> a -> m s) -> (s -> m b) -> s -> Vector a -> m (Vector b) scanMapM f g !s0 !xs | V.null xs = do r <- g s0 return $ V.singleton r | otherwise = do s <- f s0 (V.head xs) r <- g s0 liftM (r `V.cons`) (scanMapM f g s (V.tail xs))
Terrain Group is focused on developing and maintaining leisure and recreational facilities that ensure outstanding value and distinctive environmental design. The optimal use of open spaces is of significant value across our communities and this is where Terrain Group understands the demand for considered, aesthetic solutions. From project management, planning and design to supply and implementation of product, Terrain provides a complete service. Be it longevity of design or the quality of our products and practices, our no compromise philosophy always results in turning open spaces into attractive and engaging places. So, you receive designed solutions, delivered on time to your deadline with complete satisfaction.
struct EventObservations{T <: EpidemicModel} infection::Vector{Float64} removal::Union{Nothing, Vector{Float64}} individuals::Int64 function EventObservations{T}(i::V, r::V) where {V<:Vector{Float64}, T <: Union{SEIR, SIR}} if length(i) != length(r) error("Length of infection and removal times must be equal") end return new{T}(i, r, length(i)) end function EventObservations{T}(i::V) where {V<:Vector{Float64}, T <: Union{SEI, SI}} return new{T}(i, nothing, length(i)) end end function EventObservations{T}(i::Array{Float64, 2}) where T <: Union{SEI, SI} if size(i, 2) != 1 @error "Invalid Array dimensions for observations of a $T model" end return EventObservations{T}(i[:,1]) end function EventObservations{T}(ir::Array{Float64, 2}) where T <: Union{SEIR, SIR} if size(ir, 2) != 2 @error "Invalid Array dimensions for observations of a $T model" end return EventObservations(ir[:, 1], ir[:, 2]) end function Base.show(io::IO, x::EventObservations{T}) where T <: EpidemicModel return print(io, "$T model observations (n=$(x.individuals))") end function Base.getindex(x::EventObservations{T}, new_state::DiseaseState) where T <: EpidemicModel if new_state == State_I return x.infection elseif (new_state == State_R) && (T ∈ [SEIR, SIR]) return x.removal else error("Unrecognized indexing disease state") end end function Base.getindex(x::EventObservations{T}, states::Vector{DiseaseState}) where T <: EpidemicModel y = x[states[1]] for i = 2:length(states) y = hcat(y, x[states[i]]) end return y end function Base.convert(::Type{Array{Float64, 2}}, x::EventObservations{T}) where T <: EpidemicModel states = T ∈ [SEI, SI] ? [State_I] : [State_I, State_R] return x[states] end function Base.convert(::Type{Vector{Float64}}, x::EventObservations{T}) where T <: EpidemicModel states = T ∈ [SEI, SI] ? [State_I] : [State_I, State_R] return x[states][:] end function Base.minimum(x::EventObservations{T}) where T <: EpidemicModel y = convert(Array{Float64, 2}, x) return minimum(y[.!isnan.(y)]) end function Base.maximum(x::EventObservations{T}) where T <: EpidemicModel y = convert(Array{Float64, 2}, x) return maximum(y[.!isnan.(y)]) end
State Before: l : Type ?u.338640 m : Type u n : Type u' α : Type v inst✝² : Fintype n inst✝¹ : DecidableEq n inst✝ : CommRing α A B : Matrix n n α v : n → α ⊢ IsUnit (diagonal v) ↔ IsUnit v State After: no goals Tactic: simp only [← nonempty_invertible_iff_isUnit, (diagonalInvertibleEquivInvertible v).nonempty_congr]
module Isumi.Math.FFT.Internal.Bruun2D ( fft2dBruun ) where import Data.Complex import qualified Data.Vector.Generic as GV import Isumi.Math.FFT.Internal.Bruun (fftBruun, fftBruunC) import qualified Numeric.LinearAlgebra as LA import Numeric.LinearAlgebra.Data (Matrix) fft2dBruun :: Matrix Double -> Maybe (Matrix (Complex Double)) fft2dBruun m = do rows' <- traverse (fftBruun . GV.convert) (LA.toRows m) cols' <- traverse (fftBruunC . GV.convert) . LA.toColumns . LA.fromRows $ fmap GV.convert rows' pure $ LA.fromColumns (fmap GV.convert cols')
/- Copyright (c) 2020 Wojciech Nawrocki. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wojciech Nawrocki, Leonardo de Moura, Sebastian Ullrich -/ import Lean.Data.Position import Lean.Data.OpenDecl import Lean.MetavarContext import Lean.Environment import Lean.Data.Json namespace Lean.Elab /-- Context after executing `liftTermElabM`. Note that the term information collected during elaboration may contain metavariables, and their assignments are stored at `mctx`. -/ structure ContextInfo where env : Environment fileMap : FileMap mctx : MetavarContext := {} options : Options := {} currNamespace : Name := Name.anonymous openDecls : List OpenDecl := [] ngen : NameGenerator -- We must save the name generator to implement `ContextInfo.runMetaM` and making we not create `MVarId`s used in `mctx`. /-- Base structure for `TermInfo`, `CommandInfo` and `TacticInfo`. -/ structure ElabInfo where /-- The name of the elaborator that created this info. -/ elaborator : Name /-- The piece of syntax that the elaborator created this info for. Note that this also implicitly stores the code position in the syntax's SourceInfo. -/ stx : Syntax deriving Inhabited structure TermInfo extends ElabInfo where lctx : LocalContext -- The local context when the term was elaborated. expectedType? : Option Expr expr : Expr isBinder : Bool := false deriving Inhabited structure CommandInfo extends ElabInfo where deriving Inhabited /-- A completion is an item that appears in the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense) box that appears as you type. -/ inductive CompletionInfo where | dot (termInfo : TermInfo) (field? : Option Syntax) (expectedType? : Option Expr) | id (stx : Syntax) (id : Name) (danglingDot : Bool) (lctx : LocalContext) (expectedType? : Option Expr) | dotId (stx : Syntax) (id : Name) (lctx : LocalContext) (expectedType? : Option Expr) | fieldId (stx : Syntax) (id : Name) (lctx : LocalContext) (structName : Name) | namespaceId (stx : Syntax) | option (stx : Syntax) | endSection (stx : Syntax) (scopeNames : List String) | tactic (stx : Syntax) (goals : List MVarId) -- TODO `import` /-- Info for an option reference (e.g. in `set_option`). -/ structure OptionInfo where stx : Syntax optionName : Name declName : Name structure FieldInfo where /-- Name of the projection. -/ projName : Name /-- Name of the field as written. -/ fieldName : Name lctx : LocalContext val : Expr stx : Syntax deriving Inhabited /-- The information needed to render the tactic state in the infoview. We store the list of goals before and after the execution of a tactic. We also store the metavariable context at each time since we want metavariables unassigned at tactic execution time to be displayed as `?m...`. -/ structure TacticInfo extends ElabInfo where mctxBefore : MetavarContext goalsBefore : List MVarId mctxAfter : MetavarContext goalsAfter : List MVarId deriving Inhabited structure MacroExpansionInfo where lctx : LocalContext -- The local context when the macro was expanded. stx : Syntax output : Syntax deriving Inhabited /-- Dynamic info for custom use cases. -/ structure CustomInfo where stx : Syntax value : Dynamic /-- An info that represents a user-widget. User-widgets are custom pieces of code that run on the editor client. You can learn about user widgets at `src/Lean/Widget/UserWidget` -/ structure UserWidgetInfo where stx : Syntax /-- Id of `WidgetSource` object to use. -/ widgetId : Name /-- Json representing the props to be loaded in to the component. -/ props : Json deriving Inhabited /-- Specifies that the given free variables should be considered semantically identical. The free variable `baseId` might not be in the current local context because it has been cleared. Used for e.g. connecting variables before and after `match` generalization. -/ structure FVarAliasInfo where userName : Name id : FVarId baseId : FVarId /-- Contains the syntax of an identifier which is part of a field redeclaration, like: ``` structure Foo := x : Nat structure Bar extends Foo := x := 0 --^ here ``` -/ structure FieldRedeclInfo where stx : Syntax /-- Header information for a node in `InfoTree`. -/ inductive Info where | ofTacticInfo (i : TacticInfo) | ofTermInfo (i : TermInfo) | ofCommandInfo (i : CommandInfo) | ofMacroExpansionInfo (i : MacroExpansionInfo) | ofOptionInfo (i : OptionInfo) | ofFieldInfo (i : FieldInfo) | ofCompletionInfo (i : CompletionInfo) | ofUserWidgetInfo (i : UserWidgetInfo) | ofCustomInfo (i : CustomInfo) | ofFVarAliasInfo (i : FVarAliasInfo) | ofFieldRedeclInfo (i : FieldRedeclInfo) deriving Inhabited /-- The InfoTree is a structure that is generated during elaboration and used by the language server to look up information about objects at particular points in the Lean document. For example, tactic information and expected type information in the infoview and information about completions. The infotree consists of nodes which may have child nodes. Each node has an `Info` object that contains details about what kind of information is present. Each `Info` object also contains a `Syntax` instance, this is used to map positions in the Lean document to particular info objects. An example of a function that extracts information from an infotree for a given position is `InfoTree.goalsAt?` which finds `TacticInfo`. Information concerning expressions requires that a context also be saved. `context` nodes store a local context that is used to process expressions in nodes below. Because the info tree is generated during elaboration, some parts of the infotree for a particular piece of syntax may not be ready yet. Hence InfoTree supports metavariable-like `hole`s which are filled in later in the same way that unassigned metavariables are. -/ inductive InfoTree where /-- The context object is created by `liftTermElabM` at `Command.lean` -/ | context (i : ContextInfo) (t : InfoTree) /-- The children contain information for nested term elaboration and tactic evaluation -/ | node (i : Info) (children : PersistentArray InfoTree) /-- The elaborator creates holes (aka metavariables) for tactics and postponed terms -/ | hole (mvarId : MVarId) deriving Inhabited /-- This structure is the state that is being used to build an InfoTree object. During elaboration, some parts of the info tree may be `holes` which need to be filled later. The `assignments` field is used to assign these holes. The `trees` field is a list of pending child trees for the infotree node currently being built. You should not need to use `InfoState` directly, instead infotrees should be built with the help of the methods here such as `pushInfoLeaf` to create leaf nodes and `withInfoContext` to create a nested child node. To see how `trees` is used, look at the function body of `withInfoContext'`. -/ structure InfoState where /-- Whether info trees should be recorded. -/ enabled : Bool := true /-- Map from holes in the infotree to child infotrees. -/ assignment : PersistentHashMap MVarId InfoTree := {} /-- Pending child trees of a node. -/ trees : PersistentArray InfoTree := {} deriving Inhabited class MonadInfoTree (m : Type → Type) where getInfoState : m InfoState modifyInfoState : (InfoState → InfoState) → m Unit export MonadInfoTree (getInfoState modifyInfoState) instance [MonadLift m n] [MonadInfoTree m] : MonadInfoTree n where getInfoState := liftM (getInfoState : m _) modifyInfoState f := liftM (modifyInfoState f : m _) def setInfoState [MonadInfoTree m] (s : InfoState) : m Unit := modifyInfoState fun _ => s end Lean.Elab
theory nat_alt_mul_assoc imports Main "$HIPSTER_HOME/IsaHipster" begin datatype Nat = Z | S "Nat" fun plus :: "Nat => Nat => Nat" where "plus (Z) y = y" | "plus (S n) y = S (plus n y)" fun altmul :: "Nat => Nat => Nat" where "altmul (Z) y = Z" | "altmul (S z) (Z) = Z" | "altmul (S z) (S x2) = S (plus (plus (altmul z x2) z) x2)" (*hipster plus altmul *) theorem x0 : "!! (x :: Nat) (y :: Nat) (z :: Nat) . (altmul x (altmul y z)) = (altmul (altmul x y) z)" by (tactic \<open>Subgoal.FOCUS_PARAMS (K (Tactic_Data.hard_tac @{context})) @{context} 1\<close>) end
sharing/display.cpp sharing/main.cpp sharing/sharing.cpp sharing/stimulus.cpp
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import probability.stopping /-! # Hitting time Given a stochastic process, the hitting time provides the first time the process ``hits'' some subset of the state space. The hitting time is a stopping time in the case that the time index is discrete and the process is adapted (this is true in a far more general setting however we have only proved it for the discrete case so far). ## Main definition * `measure_theory.hitting`: the hitting time of a stochastic process ## Main results * `measure_theory.hitting_is_stopping_time`: a discrete hitting time of an adapted process is a stopping time ## Implementation notes In the definition of the hitting time, we bound the hitting time by an upper and lower bound. This is to ensure that our result is meaningful in the case we are taking the infimum of an empty set or the infimum of a set which is unbounded from below. With this, we can talk about hitting times indexed by the natural numbers or the reals. By taking the bounds to be `⊤` and `⊥`, we obtain the standard definition in the case that the index is `with_top ℕ` or `ℝ≥0∞`. -/ open filter order topological_space open_locale classical measure_theory nnreal ennreal topological_space big_operators namespace measure_theory variables {α β ι : Type*} {m : measurable_space α} /-- Hitting time: given a stochastic process `u` and a set `s`, `hitting u s n m` is the first time `u` is in `s` after time `n` and before time `m` (if `u` does not hit `s` after time `n` and before `m` then the hitting time is simply `m`). The hitting time is a stopping time if the process is adapted and discrete. -/ noncomputable def hitting [preorder ι] [has_Inf ι] (u : ι → α → β) (s : set β) (n m : ι) : α → ι := λ x, if ∃ j ∈ set.Icc n m, u j x ∈ s then Inf (set.Icc n m ∩ {i : ι | u i x ∈ s}) else m section inequalities variables [conditionally_complete_linear_order ι] {u : ι → α → β} {s : set β} {n i : ι} {x : α} lemma hitting_of_lt {m : ι} (h : m < n) : hitting u s n m x = m := begin simp_rw [hitting], have h_not : ¬∃ (j : ι) (H : j ∈ set.Icc n m), u j x ∈ s, { push_neg, intro j, rw set.Icc_eq_empty_of_lt h, simp only [set.mem_empty_eq, forall_false_left], }, simp only [h_not, if_false], end lemma hitting_le {m : ι} (x : α) : hitting u s n m x ≤ m := begin cases le_or_lt n m with h_le h_lt, { simp only [hitting], split_ifs, { obtain ⟨j, hj₁, hj₂⟩ := h, exact (cInf_le (bdd_below.inter_of_left bdd_below_Icc) (set.mem_inter hj₁ hj₂)).trans hj₁.2 }, { exact le_rfl }, }, { rw hitting_of_lt h_lt, }, end lemma le_hitting {m : ι} (hnm : n ≤ m) (x : α) : n ≤ hitting u s n m x := begin simp only [hitting], split_ifs, { refine le_cInf _ (λ b hb, _), { obtain ⟨k, hk_Icc, hk_s⟩ := h, exact ⟨k, hk_Icc, hk_s⟩, }, { rw set.mem_inter_iff at hb, exact hb.1.1, }, }, { exact hnm }, end lemma le_hitting_of_exists {m : ι} (h_exists : ∃ j ∈ set.Icc n m, u j x ∈ s) : n ≤ hitting u s n m x := begin refine le_hitting _ x, by_contra, rw set.Icc_eq_empty_of_lt (not_le.mp h) at h_exists, simpa using h_exists, end lemma hitting_mem_Icc {m : ι} (hnm : n ≤ m) (x : α) : hitting u s n m x ∈ set.Icc n m := ⟨le_hitting hnm x, hitting_le x⟩ lemma hitting_mem_set [is_well_order ι (<)] {m : ι} (h_exists : ∃ j ∈ set.Icc n m, u j x ∈ s) : u (hitting u s n m x) x ∈ s := begin simp_rw [hitting, if_pos h_exists], have h_nonempty : (set.Icc n m ∩ {i : ι | u i x ∈ s}).nonempty, { obtain ⟨k, hk₁, hk₂⟩ := h_exists, exact ⟨k, set.mem_inter hk₁ hk₂⟩, }, have h_mem := Inf_mem h_nonempty, rw [set.mem_inter_iff] at h_mem, exact h_mem.2, end lemma hitting_le_of_mem {m : ι} (hin : n ≤ i) (him : i ≤ m) (his : u i x ∈ s) : hitting u s n m x ≤ i := begin have h_exists : ∃ k ∈ set.Icc n m, u k x ∈ s := ⟨i, ⟨hin, him⟩, his⟩, simp_rw [hitting, if_pos h_exists], exact cInf_le (bdd_below.inter_of_left bdd_below_Icc) (set.mem_inter ⟨hin, him⟩ his), end lemma hitting_le_iff_of_exists [is_well_order ι (<)] {m : ι} (h_exists : ∃ j ∈ set.Icc n m, u j x ∈ s) : hitting u s n m x ≤ i ↔ ∃ j ∈ set.Icc n i, u j x ∈ s := begin split; intro h', { exact ⟨hitting u s n m x, ⟨le_hitting_of_exists h_exists, h'⟩, hitting_mem_set h_exists⟩, }, { have h'' : ∃ k ∈ set.Icc n (min m i), u k x ∈ s, { obtain ⟨k₁, hk₁_mem, hk₁_s⟩ := h_exists, obtain ⟨k₂, hk₂_mem, hk₂_s⟩ := h', refine ⟨min k₁ k₂, ⟨le_min hk₁_mem.1 hk₂_mem.1, min_le_min hk₁_mem.2 hk₂_mem.2⟩, _⟩, exact min_rec' (λ j, u j x ∈ s) hk₁_s hk₂_s, }, obtain ⟨k, hk₁, hk₂⟩ := h'', refine le_trans _ (hk₁.2.trans (min_le_right _ _)), exact hitting_le_of_mem hk₁.1 (hk₁.2.trans (min_le_left _ _)) hk₂, }, end lemma hitting_le_iff_of_lt [is_well_order ι (<)] {m : ι} (i : ι) (hi : i < m) : hitting u s n m x ≤ i ↔ ∃ j ∈ set.Icc n i, u j x ∈ s := begin by_cases h_exists : ∃ j ∈ set.Icc n m, u j x ∈ s, { rw hitting_le_iff_of_exists h_exists, }, { simp_rw [hitting, if_neg h_exists], push_neg at h_exists, simp only [not_le.mpr hi, set.mem_Icc, false_iff, not_exists, and_imp], exact λ k hkn hki, h_exists k ⟨hkn, hki.trans hi.le⟩, }, end lemma hitting_lt_iff [is_well_order ι (<)] {m : ι} (i : ι) (hi : i ≤ m) : hitting u s n m x < i ↔ ∃ j ∈ set.Ico n i, u j x ∈ s := begin split; intro h', { have h : ∃ j ∈ set.Icc n m, u j x ∈ s, { by_contra, simp_rw [hitting, if_neg h, ← not_le] at h', exact h' hi, }, exact ⟨hitting u s n m x, ⟨le_hitting_of_exists h, h'⟩, hitting_mem_set h⟩, }, { obtain ⟨k, hk₁, hk₂⟩ := h', refine lt_of_le_of_lt _ hk₁.2, exact hitting_le_of_mem hk₁.1 (hk₁.2.le.trans hi) hk₂, }, end end inequalities /-- A discrete hitting time is a stopping time. -/ lemma hitting_is_stopping_time [conditionally_complete_linear_order ι] [is_well_order ι (<)] [encodable ι] [topological_space β] [pseudo_metrizable_space β] [measurable_space β] [borel_space β] {f : filtration ι m} {u : ι → α → β} {s : set β} {n n' : ι} (hu : adapted f u) (hs : measurable_set s) : is_stopping_time f (hitting u s n n') := begin intro i, cases le_or_lt n' i with hi hi, { have h_le : ∀ x, hitting u s n n' x ≤ i := λ x, (hitting_le x).trans hi, simp [h_le], }, { have h_set_eq_Union : {x | hitting u s n n' x ≤ i} = ⋃ j ∈ set.Icc n i, u j ⁻¹' s, { ext x, rw [set.mem_set_of_eq, hitting_le_iff_of_lt _ hi], simp only [set.mem_Icc, exists_prop, set.mem_Union, set.mem_preimage], }, rw h_set_eq_Union, exact measurable_set.Union (λ j, measurable_set.Union_Prop $ λ hj, f.mono hj.2 _ ((hu j).measurable hs)) } end section complete_lattice variables [complete_lattice ι] {u : ι → α → β} {s : set β} {f : filtration ι m} lemma hitting_eq_Inf (x : α) : hitting u s ⊥ ⊤ x = Inf {i : ι | u i x ∈ s} := begin simp only [hitting, set.mem_Icc, bot_le, le_top, and_self, exists_true_left, set.Icc_bot, set.Iic_top, set.univ_inter, ite_eq_left_iff, not_exists], intro h_nmem_s, symmetry, rw Inf_eq_top, exact λ i hi_mem_s, absurd hi_mem_s (h_nmem_s i), end end complete_lattice section conditionally_complete_linear_order_bot variables [conditionally_complete_linear_order_bot ι] [is_well_order ι (<)] variables {u : ι → α → β} {s : set β} {f : filtration ℕ m} lemma hitting_bot_le_iff {i n : ι} {x : α} (hx : ∃ j, j ≤ n ∧ u j x ∈ s) : hitting u s ⊥ n x ≤ i ↔ ∃ j ≤ i, u j x ∈ s := begin cases lt_or_le i n with hi hi, { rw hitting_le_iff_of_lt _ hi, simp, }, { simp only [(hitting_le x).trans hi, true_iff], obtain ⟨j, hj₁, hj₂⟩ := hx, exact ⟨j, hj₁.trans hi, hj₂⟩, }, end end conditionally_complete_linear_order_bot end measure_theory
Encouraged by the news of the uprisings , Madero crossed the border back into Mexico in February 1911 . He was joined by Pancho Villa and Orozco and in April the army began approaching Ciudad Juárez . Orozco and Villa led the way with 500 men each , while Madero followed up with 1 @,@ 500 riders . The city was besieged by the end of the month , after Madero 's army encountered some resistance in the Chihuahuan countryside . Madero asked the commander of the city 's garrison to surrender but the latter refused , hoping that the fortifications he had constructed would allow him to defend the city until reinforcements arrived . Concerned also with the possibility that a direct attack on the town would cause artillery shells to cross the border into the United States which could provoke an outside intervention , and faced with a series of peace proposals from Díaz , Madero hesitated in attacking the city . He in fact ordered his commanders to lift the siege . Orozco , however disregarded the order and , joined by Villa , attacked . After two days of fighting the city fell to the insurrectionists . Madero intervened personally to spare the life of the city 's commander , Gen. Navarro , whom both Orozco and Villa wanted executed for his previous killing of rebel POWs . This , coupled with the fact that both leaders were ignored by Madero in his political appointments , outraged and estranged them from him .
(***************************************************************************** * ESPL --- an embedded security protocol logic * http://people.inf.ethz.ch/meiersi/espl/ * * Copyright (c) 2009-2011, Simon Meier, ETH Zurich, Switzerland * * Extension to compromising adversaries: * * Copyright (c) 2010-2011, Martin Schaub, ETH Zurich, Switzerland * * All rights reserved. See file LICENCE for more information. ******************************************************************************) theory "PFS_acm" imports "../ESPLogic" begin section{* Security Proofs for a protocol guaranteeing PFS *} subsection{* Protocol Specificiation *} role A where "A = [ Send ''1'' ( PEnc \<langle> sC ''1'', sAV ''B'', PAsymPK ( sN ''na'' ) \<rangle> ( sSK ''A'' ) ) , Recv ''2'' ( PEnc ( PEnc \<langle> sC ''2'', sAV ''A'', sMV ''k'' \<rangle> ( sSK ''B'' ) ) ( PAsymPK ( sN ''na'' ) ) ) , Send ''3'' (PEnc \<langle> sC ''3'', sAV ''B'', PHash ( sMV ''k'') \<rangle> ( sSK ''A'' )) , Note ''4'' SessKey (sMV ''k'') ]" role B where "B = [ Recv ''1'' ( PEnc \<langle> sC ''1'', sAV ''B'', sMV ''pkNa'' \<rangle> ( sSK ''A'' ) ) , Send ''2'' ( PEnc ( PEnc \<langle> sC ''2'', sAV ''A'', sN ''k'' \<rangle> ( sSK ''B'' ) ) ( sMV ''pkNa'' ) ) , Recv ''3'' (PEnc \<langle> sC ''3'', sAV ''B'', PHash ( sN ''k'') \<rangle> ( sSK ''A'' )) , Note ''4'' SessKey (sN ''k'') ]" protocol PFS where "PFS = { A, B }" (* TODO remove *) declare (in PFS_state) A_4_def[simp] declare (in PFS_state) B_4_def[simp] subsection {* Typing Definition *} type_invariant auto_msc_typing for PFS where "auto_msc_typing = mk_typing [ ((A, ''k''), (SumT (KnownT A_2) (NonceT B ''k''))) , ((B, ''pkNa''), (SumT (KnownT B_1) (PKT (NonceT A ''na'')))) ]" sublocale PFS_state \<subseteq> auto_msc_typing_state proof - have "(t,r,s) \<in> approx auto_msc_typing" proof(cases rule: reachable_in_approxI_ext [OF auto_msc_typing.monoTyp, completeness_cases_rule]) case (A_2_k t r s tid0) note facts = this then interpret state: auto_msc_typing_state t r s by unfold_locales auto show ?case using facts proof(sources! " Enc ( Enc \<lbrace> LC ''2'', s(AV ''A'' tid0), s(MV ''k'' tid0) \<rbrace> ( SK ( s(AV ''B'' tid0) ) ) ) ( PK ( LN ''na'' tid0 ) ) ") case fake note_unified facts = this facts thus ?thesis proof(sources! " Enc \<lbrace> LC ''2'', s(AV ''A'' tid0), s(MV ''k'' tid0) \<rbrace> ( SK ( s(AV ''B'' tid0) ) ) ") qed (insert facts, ((fastforce intro: event_predOrdI split: if_splits) | (fastforce intro: event_predOrdI split: if_splits))+)? qed (insert facts, ((fastforce intro: event_predOrdI split: if_splits))+)? next case (B_1_pkNa t r s tid0) note facts = this then interpret state: auto_msc_typing_state t r s by unfold_locales auto show ?case using facts proof(sources! " Enc \<lbrace> LC ''1'', s(AV ''B'' tid0), s(MV ''pkNa'' tid0) \<rbrace> ( SK ( s(AV ''A'' tid0) ) ) ") qed (insert facts, ((fastforce intro: event_predOrdI split: if_splits) | (fastforce intro: event_predOrdI split: if_splits))+)? qed thus "auto_msc_typing_state t r s" by unfold_locales auto qed subsection{* Partnering Definition *} definition PFS_trusted :: "partnering" where "PFS_trusted q = Id \<union> mk_partnering A B {(sAV ''A'', sAV ''A'', B_1), (sAV ''B'', sAV ''B'', B_1), (sMV ''k'', sN ''k'', B_2), ( PAsymPK ( sN ''na'' ), sMV ''pkNa'', B_1)} q \<union> mk_partnering B A {(sAV ''A'', sAV ''A'', A_1), (sAV ''B'', sAV ''B'', A_1), (sN ''k'', sMV ''k'', A_2), (sMV ''pkNa'', PAsymPK ( sN ''na'' ), A_1)} q" lemmas (in PFS_state) PFS_trusted_conv = setEqImpTupleIn[OF PFS_trusted_def, of _ _ "(t,r,s)", simplified] lemmas (in PFS_state) PFS_trustedI[intro!] = PFS_trusted_conv[THEN iffD2,simplified mk_partnering_conv,simplified] subsection{* Adversary Compromise Model Definitions *} definition (in PFS_state) ADVall :: "tid \<Rightarrow> state set" where "ADVall i = acm {LKRothers i, LKRafter i, SkR i PFS_trusted}" locale PFS_state_ADVall = PFS_state + fixes test :: tid assumes compromiseModel [simp,intro!]: "(t,r,s) \<in> ADVall test" begin lemmas allowed_reveals = acm_to_caps[OF compromiseModel[simplified ADVall_def], simplified] end section {* Security Properties *} subsection{* Origin Proofs *} lemma (in PFS_state) B_k_origin [rule_format]: assumes facts: "roleMap r test = Some B" shows "LN ''k'' test \<in> knows t \<longrightarrow> LKR (s(AV ''A'' test)) \<prec> St (test, B_2) \<or> (\<exists> tid1. (test,tid1) \<in> PFS_trusted (t,r,s) \<and> RCompr SessKey tid1 \<in> reveals t)" (is "?knows \<longrightarrow> ?origins") proof assume "?knows" thus "?origins" using facts proof(sources " LN ''k'' test ") case B_2_k thus ?thesis proof(sources "Enc \<lbrace> LC ''1'', s(AV ''B'' test), s(MV ''pkNa'' test) \<rbrace> ( SK ( s(AV ''A'' test) ) ) ") case fake thus ?thesis by (sources "SK (s (AV ''A'' test))") (fastforce intro: predOrd_distinct'_trans) next case (A_1_enc tid1) thus ?thesis proof(sources " SK ( LN ''na'' tid1 ) ") qed qed next case (A_4_k tid1) thus ?thesis proof(sources "Enc (Enc \<lbrace>LC ''2'', s (AV ''A'' tid1), LN ''k'' test\<rbrace> (SK (s (AV ''B'' tid1)))) (PK (LN ''na'' tid1))") case fake thus ?thesis proof(sources "Enc \<lbrace>LC ''2'', s (AV ''A'' tid1), LN ''k'' test\<rbrace> (SK (s (AV ''B'' tid1)))") case B_2_enc_1 thus ?thesis proof(sources "Enc \<lbrace>LC ''1'', s (AV ''B'' tid1), s (MV ''pkNa'' test)\<rbrace> (SK (s (AV ''A'' tid1)))") case fake thus ?thesis by (sources "SK (s (AV ''A'' test))") (fastforce intro: predOrd_distinct'_trans) next case (A_1_enc tid1') thus ?thesis by (sources "SK (LN ''na'' tid1')") qed qed next case B_2_enc thus ?thesis by (auto intro: compr_predOrdI) qed next case B_4_k thus ?thesis by (auto intro: compr_predOrdI) qed qed lemma (in PFS_state) A_k_origin [rule_format]: assumes facts: "roleMap r test = Some A" "( test, A_3 ) \<in> steps t" shows "s(MV ''k'' test) \<in> knows t \<longrightarrow> LKR (s(AV ''A'' test)) \<prec> St (test, A_2) \<or> LKR (s(AV ''B'' test)) \<prec> St (test, A_2) \<or> (\<exists> tid1. (test,tid1) \<in> PFS_trusted (t,r,s) \<and> RCompr SessKey tid1 \<in> reveals t)" (is "?knows \<longrightarrow> ?origins") proof assume "?knows" note_prefix_closed facts = facts this thus "?origins" proof(sources "Enc ( Enc \<lbrace> LC ''2'', s(AV ''A'' test), s(MV ''k'' test) \<rbrace> ( SK ( s(AV ''B'' test) ) ) )( PK ( LN ''na'' test ) ) ") case fake thus ?thesis proof(sources "Enc \<lbrace> LC ''2'', s(AV ''A'' test), s(MV ''k'' test) \<rbrace> ( SK ( s(AV ''B'' test) ) ) ") case fake thus ?thesis by (sources "SK (s (AV ''B'' test))") (fastforce intro: predOrd_distinct'_trans) next case (B_2_enc_1 tid1) thus ?thesis proof(sources "Enc \<lbrace>LC ''1'', s (AV ''B'' test), s (MV ''pkNa'' tid1)\<rbrace> (SK (s (AV ''A'' test)))") case fake thus ?thesis by (sources "SK (s (AV ''A'' tid1))")(fastforce intro: predOrd_distinct'_trans) next case (A_1_enc tid1') thus ?thesis by (sources "SK (LN ''na'' tid1')") qed qed next case (B_2_enc tid1) thus ?thesis proof(sources "LN ''k'' tid1") case (A_4_k test') note facts = facts this thus ?thesis proof(sources "Enc (Enc \<lbrace>LC ''2'', s (AV ''A'' test'), LN ''k'' tid1\<rbrace> (SK (s (AV ''B'' test')))) (PK (LN ''na'' test'))") case fake thus ?thesis proof(sources "Enc \<lbrace>LC ''2'', s (AV ''A'' test'), LN ''k'' tid1\<rbrace> (SK (s (AV ''B'' test')))") case B_2_enc_1 thus ?thesis by (sources "SK (LN ''na'' test)") qed next case B_2_enc note_unified facts = facts this thus ?thesis by (auto intro: compr_predOrdI) qed next case B_2_k thus ?thesis by (sources "SK (LN ''na'' test)") next case B_4_k thus ?thesis by (auto intro: compr_predOrdI) qed qed qed subsection{* Secrecy Proofs *} lemma (in PFS_state_ADVall) B_sec_k: assumes facts: "roleMap r test = Some B" "LN ''k'' test \<in> knows t" "(test,B_3) \<in> steps t" shows "False" proof - note_prefix_closed facts = facts moreover { assume "LKR (s (AV ''A'' test)) \<prec> St (test, B_2)" hence "?thesis" using facts apply - apply(frule lkr_in_reveals_predOrd1) by (auto dest: allowed_reveals) } moreover { assume "(\<exists>tid1. (test, tid1) \<in> PFS_trusted (t, r, s) \<and> RCompr SessKey tid1 \<in> reveals t) \<or> (\<exists>tid1. (test, tid1) \<in> PFS_trusted (t, r, s) \<and> RCompr State tid1 \<in> reveals t)" hence "?thesis" using facts by(auto dest: allowed_reveals) } ultimately show ?thesis by (auto dest: B_k_origin) qed lemma (in PFS_state_ADVall) A_sec_k: assumes facts: "roleMap r test = Some A" "( test, A_3 ) \<in> steps t" "s(MV ''k'' test) \<in> knows t" shows "False" proof - note_prefix_closed facts = facts moreover { assume "LKR (s (AV ''A'' test)) \<prec> St (test, A_2)" hence "?thesis" using facts apply - apply(frule lkr_in_reveals_predOrd1) by (auto dest: allowed_reveals) } moreover { assume "LKR (s (AV ''B'' test)) \<prec> St (test, A_2)" hence "?thesis" using facts apply - apply(frule lkr_in_reveals_predOrd1) by (auto dest: allowed_reveals) } moreover { assume "(\<exists>tid1. (test, tid1) \<in> PFS_trusted (t, r, s) \<and> RCompr SessKey tid1 \<in> reveals t) \<or> (\<exists>tid1. (test, tid1) \<in> PFS_trusted (t, r, s) \<and> RCompr State tid1 \<in> reveals t)" hence "?thesis" using facts by(auto dest: allowed_reveals) } ultimately show ?thesis by (auto dest: A_k_origin) qed subsection{* Authentication Proofs *} lemma (in PFS_state_ADVall) A_ni_auth: assumes facts: "roleMap r test = Some A" "(test, A_3) \<in> steps t" shows "\<exists> tid1. roleMap r tid1 = Some B \<and> s(AV ''A'' test) = s(AV ''A'' tid1) \<and> s(AV ''B'' test) = s(AV ''B'' tid1) \<and> s(MV ''k'' test) = LN ''k'' tid1 \<and> PK (LN ''na'' test) = s (MV ''pkNa'' tid1) \<and> St (test, A_1) \<prec> St (tid1, B_1) \<and> St (tid1, B_2) \<prec> St (test, A_2)" proof - note_prefix_closed facts = facts thus ?thesis proof(sources "Enc (Enc \<lbrace>LC ''2'', s (AV ''A'' test), s (MV ''k'' test)\<rbrace> (SK (s (AV ''B'' test)))) (PK (LN ''na'' test))") case fake thus ?thesis proof(sources "Enc \<lbrace>LC ''2'', s (AV ''A'' test), s (MV ''k'' test)\<rbrace> (SK (s (AV ''B'' test)))") case fake thus ?thesis by (fastforce dest: A_sec_k event_predOrdI) next case (B_2_enc_1 tid1) thus ?thesis proof(sources "Enc \<lbrace>LC ''1'', s (AV ''B'' test), s (MV ''pkNa'' tid1)\<rbrace> (SK (s (AV ''A'' test)))") case fake thus ?thesis proof(sources "SK (s (AV ''A'' tid1))") case asym_lkr thus ?thesis apply - apply(frule lkr_in_reveals_predOrd1) by (fastforce dest: allowed_reveals) qed next case (A_1_enc test) thus ?thesis by (sources "SK (LN ''na'' test)") qed qed next case (B_2_enc tid1) thus ?thesis proof(sources "Enc \<lbrace>LC ''1'', s (AV ''B'' test), PK (LN ''na'' test)\<rbrace> (SK (s (AV ''A'' test)))") case fake thus ?thesis proof(sources "SK (s (AV ''A'' tid1))") case asym_lkr thus ?thesis apply - apply(frule lkr_in_reveals_predOrd1) by (fastforce dest: allowed_reveals) qed next case A_1_enc thus ?thesis by force qed qed qed lemma (in PFS_state_ADVall) B_ni_auth: assumes facts: "roleMap r test = Some B" "(test, B_3) \<in> steps t" shows "\<exists> tid1. roleMap r tid1 = Some A \<and> s(AV ''A'' tid1) = s(AV ''A'' test) \<and> s(AV ''B'' tid1) = s(AV ''B'' test) \<and> s(MV ''k'' tid1) = LN ''k'' test \<and> PK (LN ''na'' tid1) = s (MV ''pkNa'' test) \<and> St (tid1, A_1) \<prec> St (test, B_1) \<and> St (test, B_2) \<prec> St (tid1, A_2) \<and> St (tid1, A_3) \<prec> St (test, B_3)" proof - note_prefix_closed facts = facts thus ?thesis proof(sources "Enc \<lbrace>LC ''3'', s (AV ''B'' test), Hash (LN ''k'' test)\<rbrace> (SK (s (AV ''A'' test)))") case fake thus ?thesis proof(sources "SK (s (AV ''A'' test))") case asym_lkr thus ?thesis apply - apply(frule lkr_in_reveals_predOrd1) by (auto dest: allowed_reveals) qed next case (A_3_enc tid3) thus ?thesis proof(sources "Enc (Enc \<lbrace>LC ''2'', s (AV ''A'' test), LN ''k'' test\<rbrace> (SK (s (AV ''B'' tid3)))) (PK (LN ''na'' tid3))") case fake thus ?thesis proof(sources "Enc \<lbrace>LC ''2'', s (AV ''A'' tid3), LN ''k'' test\<rbrace> (SK (s (AV ''B'' tid3)))") case fake thus ?thesis proof(sources "SK (s (AV ''B'' tid3))") case asym_lkr thus ?thesis apply - apply(frule lkr_in_reveals_predOrd1) by (fastforce dest: allowed_reveals) qed next case B_2_enc_1 thus ?thesis proof(sources "Enc \<lbrace>LC ''1'', s (AV ''B'' tid3), s (MV ''pkNa'' test)\<rbrace> (SK (s (AV ''A'' tid3)))") case fake thus ?thesis proof(sources "SK (s (AV ''A'' tid3))") case asym_lkr thus ?thesis apply - apply(frule lkr_in_reveals_predOrd1) by (fastforce dest: allowed_reveals) qed next case (A_1_enc tid2) thus ?thesis by (sources "SK (LN ''na'' tid2)") qed qed next case B_2_enc thus ?thesis proof(sources "Enc \<lbrace>LC ''1'', s (AV ''B'' tid3), PK (LN ''na'' tid3)\<rbrace> (SK (s (AV ''A'' tid3)))") case fake thus ?thesis proof(sources "SK (s (AV ''A'' tid3))") case asym_lkr thus ?thesis apply - apply(frule lkr_in_reveals_predOrd1) by (fastforce dest: allowed_reveals) qed next case A_1_enc thus ?thesis by force qed qed qed qed end
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang ! This file was ported from Lean 3 source module algebraic_geometry.limits ! leanprover-community/mathlib commit 70fd9563a21e7b963887c9360bd29b2393e6225a ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.AlgebraicGeometry.Pullbacks import Mathbin.AlgebraicGeometry.AffineScheme /-! # (Co)Limits of Schemes We construct various limits and colimits in the category of schemes. * The existence of fibred products was shown in `algebraic_geometry/pullbacks.lean`. * `Spec ℤ` is the terminal object. * The preceding two results imply that `Scheme` has all finite limits. * The empty scheme is the (strict) initial object. ## Todo * Coproducts exists (and the forgetful functors preserve them). -/ universe u open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace namespace AlgebraicGeometry /-- `Spec ℤ` is the terminal object in the category of schemes. -/ noncomputable def specZIsTerminal : IsTerminal (Scheme.spec.obj (op <| CommRingCat.of ℤ)) := @IsTerminal.isTerminalObj _ _ Scheme.spec _ inferInstance (terminalOpOfInitial CommRingCat.zIsInitial) #align algebraic_geometry.Spec_Z_is_terminal AlgebraicGeometry.specZIsTerminal instance : HasTerminal Scheme := hasTerminal_of_hasTerminal_of_preservesLimit Scheme.spec instance : IsAffine (⊤_ Scheme.{u}) := isAffineOfIso (PreservesTerminal.iso Scheme.spec).inv instance : HasFiniteLimits Scheme := hasFiniteLimits_of_hasTerminal_and_pullbacks section Initial /-- The map from the empty scheme. -/ @[simps] def Scheme.emptyTo (X : Scheme.{u}) : ∅ ⟶ X := ⟨{ base := ⟨fun x => PEmpty.elim x, by continuity⟩ c := { app := fun U => CommRingCat.punitIsTerminal.from _ } }, fun x => PEmpty.elim x⟩ #align algebraic_geometry.Scheme.empty_to AlgebraicGeometry.Scheme.emptyTo @[ext] theorem Scheme.empty_ext {X : Scheme.{u}} (f g : ∅ ⟶ X) : f = g := by ext a exact PEmpty.elim a #align algebraic_geometry.Scheme.empty_ext AlgebraicGeometry.Scheme.empty_ext theorem Scheme.eq_emptyTo {X : Scheme.{u}} (f : ∅ ⟶ X) : f = Scheme.emptyTo X := Scheme.empty_ext f (Scheme.emptyTo X) #align algebraic_geometry.Scheme.eq_empty_to AlgebraicGeometry.Scheme.eq_emptyTo instance (X : Scheme.{u}) : Unique (∅ ⟶ X) := ⟨⟨Scheme.emptyTo _⟩, fun _ => Scheme.empty_ext _ _⟩ /-- The empty scheme is the initial object in the category of schemes. -/ def emptyIsInitial : IsInitial (∅ : Scheme.{u}) := IsInitial.ofUnique _ #align algebraic_geometry.empty_is_initial AlgebraicGeometry.emptyIsInitial @[simp] theorem emptyIsInitial_to : emptyIsInitial.to = Scheme.emptyTo := rfl #align algebraic_geometry.empty_is_initial_to AlgebraicGeometry.emptyIsInitial_to instance : IsEmpty Scheme.empty.carrier := show IsEmpty PEmpty by infer_instance instance spec_pUnit_isEmpty : IsEmpty (Scheme.spec.obj (op <| CommRingCat.of PUnit)).carrier := ⟨PrimeSpectrum.pUnit⟩ #align algebraic_geometry.Spec_punit_is_empty AlgebraicGeometry.spec_pUnit_isEmpty instance (priority := 100) isOpenImmersion_of_isEmpty {X Y : Scheme} (f : X ⟶ Y) [IsEmpty X.carrier] : IsOpenImmersion f := by apply (config := { instances := false }) is_open_immersion.of_stalk_iso · apply openEmbedding_of_continuous_injective_open · continuity · rintro (i : X.carrier) exact isEmptyElim i · intro U hU convert isOpen_empty ext apply (iff_false_iff _).mpr exact fun x => isEmptyElim (show X.carrier from x.some) · rintro (i : X.carrier) exact isEmptyElim i #align algebraic_geometry.is_open_immersion_of_is_empty AlgebraicGeometry.isOpenImmersion_of_isEmpty instance (priority := 100) isIso_of_isEmpty {X Y : Scheme} (f : X ⟶ Y) [IsEmpty Y.carrier] : IsIso f := by haveI : IsEmpty X.carrier := ⟨fun x => isEmptyElim (show Y.carrier from f.1.base x)⟩ have : epi f.1.base := by rw [TopCat.epi_iff_surjective] rintro (x : Y.carrier) exact isEmptyElim x apply is_open_immersion.to_iso #align algebraic_geometry.is_iso_of_is_empty AlgebraicGeometry.isIso_of_isEmpty /-- A scheme is initial if its underlying space is empty . -/ noncomputable def isInitialOfIsEmpty {X : Scheme} [IsEmpty X.carrier] : IsInitial X := emptyIsInitial.of_iso (asIso <| emptyIsInitial.to _) #align algebraic_geometry.is_initial_of_is_empty AlgebraicGeometry.isInitialOfIsEmpty /-- `Spec 0` is the initial object in the category of schemes. -/ noncomputable def specPunitIsInitial : IsInitial (Scheme.spec.obj (op <| CommRingCat.of PUnit)) := emptyIsInitial.of_iso (asIso <| emptyIsInitial.to _) #align algebraic_geometry.Spec_punit_is_initial AlgebraicGeometry.specPunitIsInitial instance (priority := 100) isAffineOfIsEmpty {X : Scheme} [IsEmpty X.carrier] : IsAffine X := isAffineOfIso (inv (emptyIsInitial.to X) ≫ emptyIsInitial.to (Scheme.spec.obj (op <| CommRingCat.of PUnit))) #align algebraic_geometry.is_affine_of_is_empty AlgebraicGeometry.isAffineOfIsEmpty instance : HasInitial Scheme := hasInitial_of_unique Scheme.empty instance initial_isEmpty : IsEmpty (⊥_ Scheme).carrier := ⟨fun x => ((initial.to Scheme.empty : _).1.base x).elim⟩ #align algebraic_geometry.initial_is_empty AlgebraicGeometry.initial_isEmpty theorem bot_isAffineOpen (X : Scheme) : IsAffineOpen (⊥ : Opens X.carrier) := by convert range_is_affine_open_of_open_immersion (initial.to X) ext exact (false_iff_iff _).mpr fun x => isEmptyElim (show (⊥_ Scheme).carrier from x.some) #align algebraic_geometry.bot_is_affine_open AlgebraicGeometry.bot_isAffineOpen instance : HasStrictInitialObjects Scheme := hasStrictInitialObjects_of_initial_is_strict fun A f => by infer_instance end Initial end AlgebraicGeometry
State Before: a b : Nat ⊢ a * a - b * b = (a + b) * (a - b) State After: no goals Tactic: rw [Nat.mul_sub_left_distrib, Nat.right_distrib, Nat.right_distrib, Nat.mul_comm b a, Nat.add_comm (a*a) (a*b), Nat.add_sub_add_left]
export VolumeMesh export points, name, groups, materials, material_names, ishomogeneous, points_in_vtk_type struct VolumeMesh{Dim,T,U} <: AbstractMesh points::Vector{Point{Dim,T}} offsets::Vector{U} # First index in connectivity connectivity::Vector{U} # Point IDs that compose each element types::Vector{UInt8} # VTK integer type of the element materials::Vector{UInt8} # ID of the element's material material_names::Vector{String} name::String groups::Dict{String,BitSet} # "Label"=>{IDs of elements with this label} end points(mesh::VolumeMesh) = mesh.points name(mesh::VolumeMesh) = mesh.name groups(mesh::VolumeMesh) = mesh.groups materials(mesh::VolumeMesh) = mesh.materials material_names(mesh::VolumeMesh) = mesh.material_names const VTK_TRIANGLE::UInt8 = 5 const VTK_QUAD::UInt8 = 9 const VTK_QUADRATIC_TRIANGLE::UInt8 = 22 const VTK_QUADRATIC_QUAD::UInt8 = 23 const VTK_TETRA::UInt8 = 10 const VTK_HEXAHEDRON::UInt8 = 12 const VTK_QUADRATIC_TETRA::UInt8 = 24 const VTK_QUADRATIC_HEXAHEDRON::UInt8 = 25 ishomogeneous(mesh::VolumeMesh) = all(i->mesh.types[1] === mesh.types[i], 2:length(mesh.types)) function points_in_vtk_type(vtk_type::I) where {I<:Integer} if vtk_type == VTK_TRIANGLE return 3 elseif vtk_type == VTK_QUAD return 4 elseif vtk_type == VTK_QUADRATIC_TRIANGLE return 6 elseif vtk_type == VTK_QUADRATIC_QUAD return 8 elseif vtk_type == VTK_TETRA return 4 elseif vtk_type == VTK_HEXAHEDRON return 8 elseif vtk_type == VTK_QUADRATIC_TETRA return 10 elseif vtk_type == VTK_QUADRATIC_HEXAHEDRON return 12 else error("Unsupported type.") return nothing end end function vtk_alias_string(vtk_type::I) where {I<:Integer} if vtk_type == VTK_TRIANGLE return "Triangle" elseif vtk_type == VTK_QUAD return "Quadrilateral" elseif vtk_type == VTK_QUADRATIC_TRIANGLE return "QuadraticTriangle" elseif vtk_type == VTK_QUADRATIC_QUAD return "QuadraticQuadrilateral" elseif vtk_type == VTK_TETRA return "Tetrahedron" elseif vtk_type == VTK_HEXAHEDRON return "Hexahedron" elseif vtk_type == VTK_QUADRATIC_TETRA return "QuadraticTetrahedron" elseif vtk_type == VTK_QUADRATIC_HEXAHEDRON return "QuadraticHexahedron" else error("Unsupported type.") return nothing end end function Base.show(io::IO, mesh::VolumeMesh{Dim,T,U}) where {Dim,T,U} println(io, "VolumeMesh{",Dim, ", ",T,", ",U,"}") println(io, " ├─ Name : ", mesh.name) size_B = Base.summarysize(mesh) if size_B < 1e6 println(io, " ├─ Size (KB) : ", string(@sprintf("%.3f", size_B/1000))) else println(io, " ├─ Size (MB) : ", string(@sprintf("%.3f",size_B/1e6))) end println(io, " ├─ Points : ", length(mesh.points)) if Dim === 3 println(io, " ├─ Faces : ", length(mesh.offsets) - 1) else println(io, " ├─ Cells : ", length(mesh.offsets) - 1) end unique_types = unique(mesh.types) nunique_types = length(unique_types) for i = 1:nunique_types type = unique_types[i] nelements = count(x->x === type, mesh.types) if i === nunique_types println(io, " │ └─ ", rpad(vtk_alias_string(type), 22), ": ", nelements) else println(io, " │ ├─ ", rpad(vtk_alias_string(type), 22), ": ", nelements) end end println(io, " ├─ Materials : ", length(mesh.material_names)) ngroups = length(mesh.groups) println(io, " └─ Groups : ", ngroups) if 0 < ngroups ≤ 5 group_keys = sort!(collect(keys(mesh.groups))) for i = 1:ngroups if i === ngroups println(io, " └─ ", group_keys[i]) else println(io, " ├─ ", group_keys[i]) end end end end
Require Import extraction. Require Import lang. Require Import syntax. Require Import Integers. Definition rotate10 : prog. refine (VDecl Input "w" (Int.repr 12) _). refine (VDecl Local "r" (Int.repr 4) _). refine (VDecl Output "b" (Int.repr 0) _). refine (PSeq (SAssign Blocking "b" (r_rotate (evar "w") (evar "r"))) _). apply PDone. Defined. Definition rotate_print_tb := pretty_print_tb "rotate" rotate10. Extract Constant main => "Prelude.putStrLn rotate_print_tb". (* run the program 'sha.hs' and pipe to a file to get verilog *) Extraction "rotate.hs" rotate_print_tb main.
I’m having a very funny time. I like going shopping. But, I’ll go by bus, not on foot. I’ll take care of myself. I’ll buy some clothes: A jacket, pants, a shirt, a dress, a coat; and “Dundee marmalade” for my parents. I’m going to buy a skirt for my mum and a coat for my dad. Do you know that “Dundee marmalade” was invented in Scotland? It is made with Seville oranges. I am sending you the recipe. P.D: I’ll go to the Loch Ness, and I’ll buy a T-shirt with a photo of Nessie, the monster of the Loch Ness.
[GOAL] x y : ℂ ⊢ SameRay ℝ x y ↔ x = 0 ∨ y = 0 ∨ arg x = arg y [PROOFSTEP] rcases eq_or_ne x 0 with (rfl | hx) [GOAL] case inl y : ℂ ⊢ SameRay ℝ 0 y ↔ 0 = 0 ∨ y = 0 ∨ arg 0 = arg y [PROOFSTEP] simp [GOAL] case inr x y : ℂ hx : x ≠ 0 ⊢ SameRay ℝ x y ↔ x = 0 ∨ y = 0 ∨ arg x = arg y [PROOFSTEP] rcases eq_or_ne y 0 with (rfl | hy) [GOAL] case inr.inl x : ℂ hx : x ≠ 0 ⊢ SameRay ℝ x 0 ↔ x = 0 ∨ 0 = 0 ∨ arg x = arg 0 [PROOFSTEP] simp [GOAL] case inr.inr x y : ℂ hx : x ≠ 0 hy : y ≠ 0 ⊢ SameRay ℝ x y ↔ x = 0 ∨ y = 0 ∨ arg x = arg y [PROOFSTEP] simp only [hx, hy, false_or_iff, sameRay_iff_norm_smul_eq, arg_eq_arg_iff hx hy] [GOAL] case inr.inr x y : ℂ hx : x ≠ 0 hy : y ≠ 0 ⊢ ‖x‖ • y = ‖y‖ • x ↔ ↑(↑abs y) / ↑(↑abs x) * x = y [PROOFSTEP] field_simp [hx, hy] [GOAL] case inr.inr x y : ℂ hx : x ≠ 0 hy : y ≠ 0 ⊢ ↑(↑abs x) * y = ↑(↑abs y) * x ↔ ↑(↑abs y) * x = y * ↑(↑abs x) [PROOFSTEP] rw [mul_comm, eq_comm] [GOAL] x y : ℂ ⊢ SameRay ℝ x y ↔ arg (x / y) = 0 [PROOFSTEP] rw [← Real.Angle.toReal_zero, ← arg_coe_angle_eq_iff_eq_toReal, sameRay_iff] [GOAL] x y : ℂ ⊢ x = 0 ∨ y = 0 ∨ arg x = arg y ↔ ↑(arg (x / y)) = 0 [PROOFSTEP] by_cases hx : x = 0 [GOAL] case pos x y : ℂ hx : x = 0 ⊢ x = 0 ∨ y = 0 ∨ arg x = arg y ↔ ↑(arg (x / y)) = 0 [PROOFSTEP] simp [hx] [GOAL] case neg x y : ℂ hx : ¬x = 0 ⊢ x = 0 ∨ y = 0 ∨ arg x = arg y ↔ ↑(arg (x / y)) = 0 [PROOFSTEP] by_cases hy : y = 0 [GOAL] case pos x y : ℂ hx : ¬x = 0 hy : y = 0 ⊢ x = 0 ∨ y = 0 ∨ arg x = arg y ↔ ↑(arg (x / y)) = 0 [PROOFSTEP] simp [hy] [GOAL] case neg x y : ℂ hx : ¬x = 0 hy : ¬y = 0 ⊢ x = 0 ∨ y = 0 ∨ arg x = arg y ↔ ↑(arg (x / y)) = 0 [PROOFSTEP] simp [hx, hy, arg_div_coe_angle, sub_eq_zero]
/- Copyright (c) 2015 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis -/ import algebra.invertible import data.int.cast /-! # Lemmas about power operations on monoids and groups This file contains lemmas about `monoid.pow`, `group.pow`, `nsmul`, `zsmul` which require additional imports besides those available in `algebra.group_power.basic`. -/ universes u v w x y z u₁ u₂ variables {M : Type u} {N : Type v} {G : Type w} {H : Type x} {A : Type y} {B : Type z} {R : Type u₁} {S : Type u₂} /-! ### (Additive) monoid -/ section monoid variables [monoid M] [monoid N] [add_monoid A] [add_monoid B] @[simp] theorem nsmul_one [has_one A] : ∀ n : ℕ, n • (1 : A) = n := begin refine eq_nat_cast' (⟨_, _, _⟩ : ℕ →+ A) _, { simp [zero_nsmul] }, { simp [add_nsmul] }, { simp } end @[simp, norm_cast, to_additive] lemma units.coe_pow (u : Mˣ) (n : ℕ) : ((u ^ n : Mˣ) : M) = u ^ n := (units.coe_hom M).map_pow u n instance invertible_pow (m : M) [invertible m] (n : ℕ) : invertible (m ^ n) := { inv_of := ⅟ m ^ n, inv_of_mul_self := by rw [← (commute_inv_of m).symm.mul_pow, inv_of_mul_self, one_pow], mul_inv_of_self := by rw [← (commute_inv_of m).mul_pow, mul_inv_of_self, one_pow] } lemma inv_of_pow (m : M) [invertible m] (n : ℕ) [invertible (m ^ n)] : ⅟(m ^ n) = ⅟m ^ n := @invertible_unique M _ (m ^ n) (m ^ n) rfl ‹_› (invertible_pow m n) lemma is_unit.pow {m : M} (n : ℕ) : is_unit m → is_unit (m ^ n) := λ ⟨u, hu⟩, ⟨u ^ n, by simp *⟩ @[simp] lemma is_unit_pow_succ_iff {m : M} {n : ℕ} : is_unit (m ^ (n + 1)) ↔ is_unit m := begin refine ⟨_, λ h, h.pow _⟩, rw [pow_succ, ((commute.refl _).pow_right _).is_unit_mul_iff], exact and.left end lemma is_unit_pos_pow_iff {m : M} : ∀ {n : ℕ} (h : 0 < n), is_unit (m ^ n) ↔ is_unit m | (n + 1) _ := is_unit_pow_succ_iff /-- If `x ^ n.succ = 1` then `x` has an inverse, `x^n`. -/ def invertible_of_pow_succ_eq_one (x : M) (n : ℕ) (hx : x ^ n.succ = 1) : invertible x := ⟨x ^ n, (pow_succ' x n).symm.trans hx, (pow_succ x n).symm.trans hx⟩ /-- If `x ^ n = 1` then `x` has an inverse, `x^(n - 1)`. -/ def invertible_of_pow_eq_one (x : M) (n : ℕ) (hx : x ^ n = 1) (hn : 0 < n) : invertible x := begin apply invertible_of_pow_succ_eq_one x (n - 1), convert hx, exact tsub_add_cancel_of_le (nat.succ_le_of_lt hn), end lemma is_unit_of_pow_eq_one (x : M) (n : ℕ) (hx : x ^ n = 1) (hn : 0 < n) : is_unit x := begin haveI := invertible_of_pow_eq_one x n hx hn, exact is_unit_of_invertible x end lemma smul_pow [mul_action M N] [is_scalar_tower M N N] [smul_comm_class M N N] (k : M) (x : N) (p : ℕ) : (k • x) ^ p = k ^ p • x ^ p := begin induction p with p IH, { simp }, { rw [pow_succ', IH, smul_mul_smul, ←pow_succ', ←pow_succ'] } end @[simp] lemma smul_pow' [mul_distrib_mul_action M N] (x : M) (m : N) (n : ℕ) : x • m ^ n = (x • m) ^ n := begin induction n with n ih, { rw [pow_zero, pow_zero], exact smul_one x }, { rw [pow_succ, pow_succ], exact (smul_mul' x m (m ^ n)).trans (congr_arg _ ih) } end end monoid section group variables [group G] [group H] [add_group A] [add_group B] open int local attribute [ematch] le_of_lt open nat theorem zsmul_one [has_one A] (n : ℤ) : n • (1 : A) = n := by cases n; simp @[to_additive add_one_zsmul] lemma zpow_add_one (a : G) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a | (of_nat n) := by simp [← int.coe_nat_succ, pow_succ'] | -[1+0] := by simp [int.neg_succ_of_nat_eq] | -[1+(n+1)] := by rw [int.neg_succ_of_nat_eq, zpow_neg, neg_add, neg_add_cancel_right, zpow_neg, ← int.coe_nat_succ, zpow_coe_nat, zpow_coe_nat, pow_succ _ (n + 1), mul_inv_rev, inv_mul_cancel_right] @[to_additive zsmul_sub_one] lemma zpow_sub_one (a : G) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ := calc a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ : (mul_inv_cancel_right _ _).symm ... = a^n * a⁻¹ : by rw [← zpow_add_one, sub_add_cancel] @[to_additive add_zsmul] lemma zpow_add (a : G) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := begin induction n using int.induction_on with n ihn n ihn, case hz : { simp }, { simp only [← add_assoc, zpow_add_one, ihn, mul_assoc] }, { rw [zpow_sub_one, ← mul_assoc, ← ihn, ← zpow_sub_one, add_sub_assoc] } end @[to_additive add_zsmul_self] lemma mul_self_zpow (b : G) (m : ℤ) : b*b^m = b^(m+1) := by { conv_lhs {congr, rw ← zpow_one b }, rw [← zpow_add, add_comm] } @[to_additive add_self_zsmul] lemma mul_zpow_self (b : G) (m : ℤ) : b^m*b = b^(m+1) := by { conv_lhs {congr, skip, rw ← zpow_one b }, rw [← zpow_add, add_comm] } @[to_additive sub_zsmul] lemma zpow_sub (a : G) (m n : ℤ) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by rw [sub_eq_add_neg, zpow_add, zpow_neg] @[to_additive one_add_zsmul] theorem zpow_one_add (a : G) (i : ℤ) : a ^ (1 + i) = a * a ^ i := by rw [zpow_add, zpow_one] @[to_additive] theorem zpow_mul_comm (a : G) (i j : ℤ) : a ^ i * a ^ j = a ^ j * a ^ i := by rw [← zpow_add, ← zpow_add, add_comm] -- note that `mul_zsmul` and `zpow_mul` have the primes swapped since their argument order -- and therefore the more "natural" choice of lemma is reversed. @[to_additive mul_zsmul'] theorem zpow_mul (a : G) (m n : ℤ) : a ^ (m * n) = (a ^ m) ^ n := int.induction_on n (by simp) (λ n ihn, by simp [mul_add, zpow_add, ihn]) (λ n ihn, by simp only [mul_sub, zpow_sub, ihn, mul_one, zpow_one]) @[to_additive mul_zsmul] theorem zpow_mul' (a : G) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [mul_comm, zpow_mul] @[to_additive bit0_zsmul] theorem zpow_bit0 (a : G) (n : ℤ) : a ^ bit0 n = a ^ n * a ^ n := zpow_add _ _ _ @[to_additive bit1_zsmul] theorem zpow_bit1 (a : G) (n : ℤ) : a ^ bit1 n = a ^ n * a ^ n * a := by rw [bit1, zpow_add, zpow_bit0, zpow_one] @[simp, norm_cast, to_additive] lemma units.coe_zpow (u : Gˣ) (n : ℤ) : ((u ^ n : Gˣ) : G) = u ^ n := (units.coe_hom G).map_zpow u n end group section ordered_add_comm_group variables [ordered_add_comm_group A] /-! Lemmas about `zsmul` under ordering, placed here (rather than in `algebra.group_power.order` with their friends) because they require facts from `data.int.basic`-/ open int lemma zsmul_pos {a : A} (ha : 0 < a) {k : ℤ} (hk : (0:ℤ) < k) : 0 < k • a := begin lift k to ℕ using int.le_of_lt hk, rw coe_nat_zsmul, apply nsmul_pos ha, exact (coe_nat_pos.mp hk).ne', end theorem zsmul_strict_mono_left {a : A} (ha : 0 < a) : strict_mono (λ n : ℤ, n • a) := λ n m h, calc n • a = n • a + 0 : (add_zero _).symm ... < n • a + (m - n) • a : add_lt_add_left (zsmul_pos ha (sub_pos.mpr h)) _ ... = m • a : by { rw [← add_zsmul], simp } theorem zsmul_mono_left {a : A} (ha : 0 ≤ a) : monotone (λ n : ℤ, n • a) := λ n m h, calc n • a = n • a + 0 : (add_zero _).symm ... ≤ n • a + (m - n) • a : add_le_add_left (zsmul_nonneg ha (sub_nonneg.mpr h)) _ ... = m • a : by { rw [← add_zsmul], simp } theorem zsmul_le_zsmul {a : A} {n m : ℤ} (ha : 0 ≤ a) (h : n ≤ m) : n • a ≤ m • a := zsmul_mono_left ha h theorem zsmul_lt_zsmul {a : A} {n m : ℤ} (ha : 0 < a) (h : n < m) : n • a < m • a := zsmul_strict_mono_left ha h theorem zsmul_le_zsmul_iff {a : A} {n m : ℤ} (ha : 0 < a) : n • a ≤ m • a ↔ n ≤ m := (zsmul_strict_mono_left ha).le_iff_le theorem zsmul_lt_zsmul_iff {a : A} {n m : ℤ} (ha : 0 < a) : n • a < m • a ↔ n < m := (zsmul_strict_mono_left ha).lt_iff_lt variables (A) lemma zsmul_strict_mono_right {n : ℤ} (hn : 0 < n) : strict_mono ((•) n : A → A) := λ a b hab, begin rw ← sub_pos at hab, rw [← sub_pos, ← zsmul_sub], exact zsmul_pos hab hn, end lemma zsmul_mono_right {n : ℤ} (hn : 0 ≤ n) : monotone ((•) n : A → A) := λ a b hab, begin rw ← sub_nonneg at hab, rw [← sub_nonneg, ← zsmul_sub], exact zsmul_nonneg hab hn, end variables {A} theorem zsmul_le_zsmul' {n : ℤ} (hn : 0 ≤ n) {a₁ a₂ : A} (h : a₁ ≤ a₂) : n • a₁ ≤ n • a₂ := zsmul_mono_right A hn h theorem zsmul_lt_zsmul' {n : ℤ} (hn : 0 < n) {a₁ a₂ : A} (h : a₁ < a₂) : n • a₁ < n • a₂ := zsmul_strict_mono_right A hn h lemma abs_nsmul {α : Type*} [linear_ordered_add_comm_group α] (n : ℕ) (a : α) : |n • a| = n • |a| := begin cases le_total a 0 with hneg hpos, { rw [abs_of_nonpos hneg, ← abs_neg, ← neg_nsmul, abs_of_nonneg], exact nsmul_nonneg (neg_nonneg.mpr hneg) n }, { rw [abs_of_nonneg hpos, abs_of_nonneg], exact nsmul_nonneg hpos n } end lemma abs_zsmul {α : Type*} [linear_ordered_add_comm_group α] (n : ℤ) (a : α) : |n • a| = |n| • |a| := begin by_cases n0 : 0 ≤ n, { lift n to ℕ using n0, simp only [abs_nsmul, coe_nat_abs, coe_nat_zsmul] }, { lift (- n) to ℕ using int.le_of_lt (neg_pos.mpr (not_le.mp n0)) with m h, rw [← abs_neg (n • a), ← neg_zsmul, ← abs_neg n, ← h, coe_nat_zsmul, coe_nat_abs, coe_nat_zsmul], exact abs_nsmul m _ }, end lemma abs_add_eq_add_abs_le {α : Type*} [linear_ordered_add_comm_group α] {a b : α} (hle : a ≤ b) : |a + b| = |a| + |b| ↔ (0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0) := begin by_cases a0 : 0 ≤ a; by_cases b0 : 0 ≤ b, { simp [a0, b0, abs_of_nonneg, add_nonneg a0 b0] }, { exact (lt_irrefl (0 : α) (a0.trans_lt (hle.trans_lt (not_le.mp b0)))).elim }, any_goals { simp [(not_le.mp a0).le, (not_le.mp b0).le, abs_of_nonpos, add_nonpos, add_comm] }, obtain F := (not_le.mp a0), have : (|a + b| = -a + b ↔ b ≤ 0) ↔ (|a + b| = |a| + |b| ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0), { simp [a0, b0, abs_of_neg, abs_of_nonneg, F, F.le] }, refine this.mp ⟨λ h, _, λ h, by simp only [le_antisymm h b0, abs_of_neg F, add_zero]⟩, by_cases ba : a + b ≤ 0, { refine le_of_eq (eq_zero_of_neg_eq _), rwa [abs_of_nonpos ba, neg_add_rev, add_comm, add_right_inj] at h }, { refine (lt_irrefl (0 : α) _).elim, rw [abs_of_pos (not_le.mp ba), add_left_inj] at h, rwa eq_zero_of_neg_eq h.symm at F } end lemma abs_add_eq_add_abs_iff {α : Type*} [linear_ordered_add_comm_group α] (a b : α) : |a + b| = |a| + |b| ↔ (0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0) := begin by_cases ab : a ≤ b, { exact abs_add_eq_add_abs_le ab }, { rw [add_comm a, add_comm (abs _), abs_add_eq_add_abs_le ((not_le.mp ab).le), and.comm, @and.comm (b ≤ 0 ) _] } end end ordered_add_comm_group section linear_ordered_add_comm_group variable [linear_ordered_add_comm_group A] theorem zsmul_le_zsmul_iff' {n : ℤ} (hn : 0 < n) {a₁ a₂ : A} : n • a₁ ≤ n • a₂ ↔ a₁ ≤ a₂ := (zsmul_strict_mono_right A hn).le_iff_le theorem zsmul_lt_zsmul_iff' {n : ℤ} (hn : 0 < n) {a₁ a₂ : A} : n • a₁ < n • a₂ ↔ a₁ < a₂ := (zsmul_strict_mono_right A hn).lt_iff_lt theorem nsmul_le_nsmul_iff {a : A} {n m : ℕ} (ha : 0 < a) : n • a ≤ m • a ↔ n ≤ m := begin refine ⟨λ h, _, nsmul_le_nsmul $ le_of_lt ha⟩, by_contra H, exact lt_irrefl _ (lt_of_lt_of_le (nsmul_lt_nsmul ha (not_le.mp H)) h) end theorem nsmul_lt_nsmul_iff {a : A} {n m : ℕ} (ha : 0 < a) : n • a < m • a ↔ n < m := begin refine ⟨λ h, _, nsmul_lt_nsmul ha⟩, by_contra H, exact lt_irrefl _ (lt_of_le_of_lt (nsmul_le_nsmul (le_of_lt ha) $ not_lt.mp H) h) end /-- See also `smul_right_injective`. TODO: provide a `no_zero_smul_divisors` instance. We can't do that here because importing that definition would create import cycles. -/ lemma zsmul_right_injective {m : ℤ} (hm : m ≠ 0) : function.injective ((•) m : A → A) := begin cases hm.symm.lt_or_lt, { exact (zsmul_strict_mono_right A h).injective, }, { intros a b hab, refine (zsmul_strict_mono_right A (neg_pos.mpr h)).injective _, rw [neg_zsmul, neg_zsmul, hab], }, end lemma zsmul_right_inj {a b : A} {m : ℤ} (hm : m ≠ 0) : m • a = m • b ↔ a = b := (zsmul_right_injective hm).eq_iff /-- Alias of `zsmul_right_inj`, for ease of discovery alongside `zsmul_le_zsmul_iff'` and `zsmul_lt_zsmul_iff'`. -/ lemma zsmul_eq_zsmul_iff' {a b : A} {m : ℤ} (hm : m ≠ 0) : m • a = m • b ↔ a = b := zsmul_right_inj hm end linear_ordered_add_comm_group @[simp] lemma with_bot.coe_nsmul [add_monoid A] (a : A) (n : ℕ) : ((n • a : A) : with_bot A) = n • a := add_monoid_hom.map_nsmul ⟨(coe : A → with_bot A), with_bot.coe_zero, with_bot.coe_add⟩ a n theorem nsmul_eq_mul' [semiring R] (a : R) (n : ℕ) : n • a = a * n := by induction n with n ih; [rw [zero_nsmul, nat.cast_zero, mul_zero], rw [succ_nsmul', ih, nat.cast_succ, mul_add, mul_one]] @[simp] theorem nsmul_eq_mul [semiring R] (n : ℕ) (a : R) : n • a = n * a := by rw [nsmul_eq_mul', (n.cast_commute a).eq] theorem mul_nsmul_left [semiring R] (a b : R) (n : ℕ) : n • (a * b) = a * (n • b) := by rw [nsmul_eq_mul', nsmul_eq_mul', mul_assoc] theorem mul_nsmul_assoc [semiring R] (a b : R) (n : ℕ) : n • (a * b) = n • a * b := by rw [nsmul_eq_mul, nsmul_eq_mul, mul_assoc] @[simp, norm_cast] theorem nat.cast_pow [semiring R] (n m : ℕ) : (↑(n ^ m) : R) = ↑n ^ m := begin induction m with m ih, { rw [pow_zero, pow_zero], exact nat.cast_one }, { rw [pow_succ', pow_succ', nat.cast_mul, ih] } end @[simp, norm_cast] theorem int.coe_nat_pow (n m : ℕ) : ((n ^ m : ℕ) : ℤ) = n ^ m := by induction m with m ih; [exact int.coe_nat_one, rw [pow_succ', pow_succ', int.coe_nat_mul, ih]] theorem int.nat_abs_pow (n : ℤ) (k : ℕ) : int.nat_abs (n ^ k) = (int.nat_abs n) ^ k := by induction k with k ih; [refl, rw [pow_succ', int.nat_abs_mul, pow_succ', ih]] -- The next four lemmas allow us to replace multiplication by a numeral with a `zsmul` expression. -- They are used by the `noncomm_ring` tactic, to normalise expressions before passing to `abel`. lemma bit0_mul [ring R] {n r : R} : bit0 n * r = (2 : ℤ) • (n * r) := by { dsimp [bit0], rw [add_mul, add_zsmul, one_zsmul], } lemma mul_bit0 [ring R] {n r : R} : r * bit0 n = (2 : ℤ) • (r * n) := by { dsimp [bit0], rw [mul_add, add_zsmul, one_zsmul], } lemma bit1_mul [ring R] {n r : R} : bit1 n * r = (2 : ℤ) • (n * r) + r := by { dsimp [bit1], rw [add_mul, bit0_mul, one_mul], } lemma mul_bit1 [ring R] {n r : R} : r * bit1 n = (2 : ℤ) • (r * n) + r := by { dsimp [bit1], rw [mul_add, mul_bit0, mul_one], } @[simp] theorem zsmul_eq_mul [ring R] (a : R) : ∀ (n : ℤ), n • a = n * a | (n : ℕ) := by { rw [coe_nat_zsmul, nsmul_eq_mul], refl } | -[1+ n] := by simp [nat.cast_succ, neg_add_rev, int.cast_neg_succ_of_nat, add_mul] theorem zsmul_eq_mul' [ring R] (a : R) (n : ℤ) : n • a = a * n := by rw [zsmul_eq_mul, (n.cast_commute a).eq] theorem mul_zsmul_left [ring R] (a b : R) (n : ℤ) : n • (a * b) = a * (n • b) := by rw [zsmul_eq_mul', zsmul_eq_mul', mul_assoc] theorem mul_zsmul_assoc [ring R] (a b : R) (n : ℤ) : n • (a * b) = n • a * b := by rw [zsmul_eq_mul, zsmul_eq_mul, mul_assoc] lemma zsmul_int_int (a b : ℤ) : a • b = a * b := by simp lemma zsmul_int_one (n : ℤ) : n • 1 = n := by simp @[simp, norm_cast] theorem int.cast_pow [ring R] (n : ℤ) (m : ℕ) : (↑(n ^ m) : R) = ↑n ^ m := begin induction m with m ih, { rw [pow_zero, pow_zero, int.cast_one] }, { rw [pow_succ, pow_succ, int.cast_mul, ih] } end lemma neg_one_pow_eq_pow_mod_two [ring R] {n : ℕ} : (-1 : R) ^ n = (-1) ^ (n % 2) := by rw [← nat.mod_add_div n 2, pow_add, pow_mul]; simp [sq] section ordered_semiring variables [ordered_semiring R] {a : R} /-- Bernoulli's inequality. This version works for semirings but requires additional hypotheses `0 ≤ a * a` and `0 ≤ (1 + a) * (1 + a)`. -/ theorem one_add_mul_le_pow' (Hsq : 0 ≤ a * a) (Hsq' : 0 ≤ (1 + a) * (1 + a)) (H : 0 ≤ 2 + a) : ∀ (n : ℕ), 1 + (n : R) * a ≤ (1 + a) ^ n | 0 := by simp | 1 := by simp | (n+2) := have 0 ≤ (n : R) * (a * a * (2 + a)) + a * a, from add_nonneg (mul_nonneg n.cast_nonneg (mul_nonneg Hsq H)) Hsq, calc 1 + (↑(n + 2) : R) * a ≤ 1 + ↑(n + 2) * a + (n * (a * a * (2 + a)) + a * a) : (le_add_iff_nonneg_right _).2 this ... = (1 + a) * (1 + a) * (1 + n * a) : by { simp [add_mul, mul_add, bit0, mul_assoc, (n.cast_commute (_ : R)).left_comm], ac_refl } ... ≤ (1 + a) * (1 + a) * (1 + a)^n : mul_le_mul_of_nonneg_left (one_add_mul_le_pow' n) Hsq' ... = (1 + a)^(n + 2) : by simp only [pow_succ, mul_assoc] private lemma pow_le_pow_of_le_one_aux (h : 0 ≤ a) (ha : a ≤ 1) (i : ℕ) : ∀ k : ℕ, a ^ (i + k) ≤ a ^ i | 0 := by simp | (k+1) := by { rw [←add_assoc, ←one_mul (a^i), pow_succ], exact mul_le_mul ha (pow_le_pow_of_le_one_aux _) (pow_nonneg h _) zero_le_one } lemma pow_le_pow_of_le_one (h : 0 ≤ a) (ha : a ≤ 1) {i j : ℕ} (hij : i ≤ j) : a ^ j ≤ a ^ i := let ⟨k, hk⟩ := nat.exists_eq_add_of_le hij in by rw hk; exact pow_le_pow_of_le_one_aux h ha _ _ lemma pow_le_of_le_one (h₀ : 0 ≤ a) (h₁ : a ≤ 1) {n : ℕ} (hn : n ≠ 0) : a ^ n ≤ a := (pow_one a).subst (pow_le_pow_of_le_one h₀ h₁ (nat.pos_of_ne_zero hn)) lemma sq_le (h₀ : 0 ≤ a) (h₁ : a ≤ 1) : a ^ 2 ≤ a := pow_le_of_le_one h₀ h₁ two_ne_zero end ordered_semiring section linear_ordered_semiring variables [linear_ordered_semiring R] lemma sign_cases_of_C_mul_pow_nonneg {C r : R} (h : ∀ n : ℕ, 0 ≤ C * r ^ n) : C = 0 ∨ (0 < C ∧ 0 ≤ r) := begin have : 0 ≤ C, by simpa only [pow_zero, mul_one] using h 0, refine this.eq_or_lt.elim (λ h, or.inl h.symm) (λ hC, or.inr ⟨hC, _⟩), refine nonneg_of_mul_nonneg_left _ hC, simpa only [pow_one] using h 1 end end linear_ordered_semiring section linear_ordered_ring variables [linear_ordered_ring R] {a : R} {n : ℕ} @[simp] lemma abs_pow (a : R) (n : ℕ) : |a ^ n| = |a| ^ n := (pow_abs a n).symm @[simp] theorem pow_bit1_neg_iff : a ^ bit1 n < 0 ↔ a < 0 := ⟨λ h, not_le.1 $ λ h', not_le.2 h $ pow_nonneg h' _, λ ha, pow_bit1_neg ha n⟩ @[simp] theorem pow_bit1_nonneg_iff : 0 ≤ a ^ bit1 n ↔ 0 ≤ a := le_iff_le_iff_lt_iff_lt.2 pow_bit1_neg_iff @[simp] theorem pow_bit1_nonpos_iff : a ^ bit1 n ≤ 0 ↔ a ≤ 0 := by simp only [le_iff_lt_or_eq, pow_bit1_neg_iff, pow_eq_zero_iff (bit1_pos (zero_le n))] @[simp] theorem pow_bit1_pos_iff : 0 < a ^ bit1 n ↔ 0 < a := lt_iff_lt_of_le_iff_le pow_bit1_nonpos_iff lemma even.pow_nonneg (hn : even n) (a : R) : 0 ≤ a ^ n := by cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_nonneg a k lemma even.pow_pos (hn : even n) (ha : a ≠ 0) : 0 < a ^ n := by cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_pos ha k lemma odd.pow_nonpos (hn : odd n) (ha : a ≤ 0) : a ^ n ≤ 0:= by cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_nonpos_iff.mpr ha lemma odd.pow_neg (hn : odd n) (ha : a < 0) : a ^ n < 0:= by cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_neg_iff.mpr ha lemma odd.pow_nonneg_iff (hn : odd n) : 0 ≤ a ^ n ↔ 0 ≤ a := ⟨λ h, le_of_not_lt (λ ha, h.not_lt $ hn.pow_neg ha), λ ha, pow_nonneg ha n⟩ lemma odd.pow_nonpos_iff (hn : odd n) : a ^ n ≤ 0 ↔ a ≤ 0 := ⟨λ h, le_of_not_lt (λ ha, h.not_lt $ pow_pos ha _), hn.pow_nonpos⟩ lemma odd.pow_pos_iff (hn : odd n) : 0 < a ^ n ↔ 0 < a := ⟨λ h, lt_of_not_ge' (λ ha, h.not_le $ hn.pow_nonpos ha), λ ha, pow_pos ha n⟩ lemma odd.pow_neg_iff (hn : odd n) : a ^ n < 0 ↔ a < 0 := ⟨λ h, lt_of_not_ge' (λ ha, h.not_le $ pow_nonneg ha _), hn.pow_neg⟩ lemma even.pow_pos_iff (hn : even n) (h₀ : 0 < n) : 0 < a ^ n ↔ a ≠ 0 := ⟨λ h ha, by { rw [ha, zero_pow h₀] at h, exact lt_irrefl 0 h }, hn.pow_pos⟩ lemma even.pow_abs {p : ℕ} (hp : even p) (a : R) : |a| ^ p = a ^ p := begin rw [←abs_pow, abs_eq_self], exact hp.pow_nonneg _ end @[simp] lemma pow_bit0_abs (a : R) (p : ℕ) : |a| ^ bit0 p = a ^ bit0 p := (even_bit0 _).pow_abs _ lemma strict_mono_pow_bit1 (n : ℕ) : strict_mono (λ a : R, a ^ bit1 n) := begin intros a b hab, cases le_total a 0 with ha ha, { cases le_or_lt b 0 with hb hb, { rw [← neg_lt_neg_iff, ← neg_pow_bit1, ← neg_pow_bit1], exact pow_lt_pow_of_lt_left (neg_lt_neg hab) (neg_nonneg.2 hb) (bit1_pos (zero_le n)) }, { exact (pow_bit1_nonpos_iff.2 ha).trans_lt (pow_bit1_pos_iff.2 hb) } }, { exact pow_lt_pow_of_lt_left hab ha (bit1_pos (zero_le n)) } end lemma odd.strict_mono_pow (hn : odd n) : strict_mono (λ a : R, a ^ n) := by cases hn with k hk; simpa only [hk, two_mul] using strict_mono_pow_bit1 _ /-- Bernoulli's inequality for `n : ℕ`, `-2 ≤ a`. -/ theorem one_add_mul_le_pow (H : -2 ≤ a) (n : ℕ) : 1 + (n : R) * a ≤ (1 + a) ^ n := one_add_mul_le_pow' (mul_self_nonneg _) (mul_self_nonneg _) (neg_le_iff_add_nonneg'.1 H) _ /-- Bernoulli's inequality reformulated to estimate `a^n`. -/ theorem one_add_mul_sub_le_pow (H : -1 ≤ a) (n : ℕ) : 1 + (n : R) * (a - 1) ≤ a ^ n := have -2 ≤ a - 1, by rwa [bit0, neg_add, ← sub_eq_add_neg, sub_le_sub_iff_right], by simpa only [add_sub_cancel'_right] using one_add_mul_le_pow this n end linear_ordered_ring /-- Bernoulli's inequality reformulated to estimate `(n : K)`. -/ theorem nat.cast_le_pow_sub_div_sub {K : Type*} [linear_ordered_field K] {a : K} (H : 1 < a) (n : ℕ) : (n : K) ≤ (a ^ n - 1) / (a - 1) := (le_div_iff (sub_pos.2 H)).2 $ le_sub_left_of_add_le $ one_add_mul_sub_le_pow ((neg_le_self $ @zero_le_one K _).trans H.le) _ /-- For any `a > 1` and a natural `n` we have `n ≤ a ^ n / (a - 1)`. See also `nat.cast_le_pow_sub_div_sub` for a stronger inequality with `a ^ n - 1` in the numerator. -/ theorem nat.cast_le_pow_div_sub {K : Type*} [linear_ordered_field K] {a : K} (H : 1 < a) (n : ℕ) : (n : K) ≤ a ^ n / (a - 1) := (n.cast_le_pow_sub_div_sub H).trans $ div_le_div_of_le (sub_nonneg.2 H.le) (sub_le_self _ zero_le_one) namespace int lemma units_sq (u : ℤˣ) : u ^ 2 = 1 := (sq u).symm ▸ units_mul_self u alias int.units_sq ← int.units_pow_two lemma units_pow_eq_pow_mod_two (u : ℤˣ) (n : ℕ) : u ^ n = u ^ (n % 2) := by conv {to_lhs, rw ← nat.mod_add_div n 2}; rw [pow_add, pow_mul, units_sq, one_pow, mul_one] @[simp] lemma nat_abs_sq (x : ℤ) : (x.nat_abs ^ 2 : ℤ) = x ^ 2 := by rw [sq, int.nat_abs_mul_self', sq] alias int.nat_abs_sq ← int.nat_abs_pow_two lemma abs_le_self_sq (a : ℤ) : (int.nat_abs a : ℤ) ≤ a ^ 2 := by { rw [← int.nat_abs_sq a, sq], norm_cast, apply nat.le_mul_self } alias int.abs_le_self_sq ← int.abs_le_self_pow_two lemma le_self_sq (b : ℤ) : b ≤ b ^ 2 := le_trans (le_nat_abs) (abs_le_self_sq _) alias int.le_self_sq ← int.le_self_pow_two lemma pow_right_injective {x : ℤ} (h : 1 < x.nat_abs) : function.injective ((^) x : ℕ → ℤ) := begin suffices : function.injective (nat_abs ∘ ((^) x : ℕ → ℤ)), { exact function.injective.of_comp this }, convert nat.pow_right_injective h, ext n, rw [function.comp_app, nat_abs_pow] end end int variables (M G A) /-- Monoid homomorphisms from `multiplicative ℕ` are defined by the image of `multiplicative.of_add 1`. -/ def powers_hom [monoid M] : M ≃ (multiplicative ℕ →* M) := { to_fun := λ x, ⟨λ n, x ^ n.to_add, by { convert pow_zero x, exact to_add_one }, λ m n, pow_add x m n⟩, inv_fun := λ f, f (multiplicative.of_add 1), left_inv := pow_one, right_inv := λ f, monoid_hom.ext $ λ n, by { simp [← f.map_pow, ← of_add_nsmul] } } /-- Monoid homomorphisms from `multiplicative ℤ` are defined by the image of `multiplicative.of_add 1`. -/ def zpowers_hom [group G] : G ≃ (multiplicative ℤ →* G) := { to_fun := λ x, ⟨λ n, x ^ n.to_add, zpow_zero x, λ m n, zpow_add x m n⟩, inv_fun := λ f, f (multiplicative.of_add 1), left_inv := zpow_one, right_inv := λ f, monoid_hom.ext $ λ n, by { simp [← f.map_zpow, ← of_add_zsmul ] } } /-- Additive homomorphisms from `ℕ` are defined by the image of `1`. -/ def multiples_hom [add_monoid A] : A ≃ (ℕ →+ A) := { to_fun := λ x, ⟨λ n, n • x, zero_nsmul x, λ m n, add_nsmul _ _ _⟩, inv_fun := λ f, f 1, left_inv := one_nsmul, right_inv := λ f, add_monoid_hom.ext_nat $ one_nsmul (f 1) } /-- Additive homomorphisms from `ℤ` are defined by the image of `1`. -/ def zmultiples_hom [add_group A] : A ≃ (ℤ →+ A) := { to_fun := λ x, ⟨λ n, n • x, zero_zsmul x, λ m n, add_zsmul _ _ _⟩, inv_fun := λ f, f 1, left_inv := one_zsmul, right_inv := λ f, add_monoid_hom.ext_int $ one_zsmul (f 1) } attribute [to_additive multiples_hom] powers_hom attribute [to_additive zmultiples_hom] zpowers_hom variables {M G A} @[simp] lemma powers_hom_apply [monoid M] (x : M) (n : multiplicative ℕ) : powers_hom M x n = x ^ n.to_add := rfl @[simp] lemma powers_hom_symm_apply [monoid M] (f : multiplicative ℕ →* M) : (powers_hom M).symm f = f (multiplicative.of_add 1) := rfl @[simp] lemma zpowers_hom_apply [group G] (x : G) (n : multiplicative ℤ) : zpowers_hom G x n = x ^ n.to_add := rfl @[simp] lemma zpowers_hom_symm_apply [group G] (f : multiplicative ℤ →* G) : (zpowers_hom G).symm f = f (multiplicative.of_add 1) := rfl @[simp] lemma multiples_hom_apply [add_monoid A] (x : A) (n : ℕ) : multiples_hom A x n = n • x := rfl attribute [to_additive multiples_hom_apply] powers_hom_apply @[simp] lemma multiples_hom_symm_apply [add_monoid A] (f : ℕ →+ A) : (multiples_hom A).symm f = f 1 := rfl attribute [to_additive multiples_hom_symm_apply] powers_hom_symm_apply @[simp] lemma zmultiples_hom_apply [add_group A] (x : A) (n : ℤ) : zmultiples_hom A x n = n • x := rfl attribute [to_additive zmultiples_hom_apply] zpowers_hom_apply @[simp] lemma zmultiples_hom_symm_apply [add_group A] (f : ℤ →+ A) : (zmultiples_hom A).symm f = f 1 := rfl attribute [to_additive zmultiples_hom_symm_apply] zpowers_hom_symm_apply -- TODO use to_additive in the rest of this file lemma monoid_hom.apply_mnat [monoid M] (f : multiplicative ℕ →* M) (n : multiplicative ℕ) : f n = (f (multiplicative.of_add 1)) ^ n.to_add := by rw [← powers_hom_symm_apply, ← powers_hom_apply, equiv.apply_symm_apply] @[ext] lemma monoid_hom.ext_mnat [monoid M] ⦃f g : multiplicative ℕ →* M⦄ (h : f (multiplicative.of_add 1) = g (multiplicative.of_add 1)) : f = g := monoid_hom.ext $ λ n, by rw [f.apply_mnat, g.apply_mnat, h] lemma monoid_hom.apply_mint [group M] (f : multiplicative ℤ →* M) (n : multiplicative ℤ) : f n = (f (multiplicative.of_add 1)) ^ n.to_add := by rw [← zpowers_hom_symm_apply, ← zpowers_hom_apply, equiv.apply_symm_apply] /-! `monoid_hom.ext_mint` is defined in `data.int.cast` -/ lemma add_monoid_hom.apply_nat [add_monoid M] (f : ℕ →+ M) (n : ℕ) : f n = n • (f 1) := by rw [← multiples_hom_symm_apply, ← multiples_hom_apply, equiv.apply_symm_apply] /-! `add_monoid_hom.ext_nat` is defined in `data.nat.cast` -/ lemma add_monoid_hom.apply_int [add_group M] (f : ℤ →+ M) (n : ℤ) : f n = n • (f 1) := by rw [← zmultiples_hom_symm_apply, ← zmultiples_hom_apply, equiv.apply_symm_apply] /-! `add_monoid_hom.ext_int` is defined in `data.int.cast` -/ variables (M G A) /-- If `M` is commutative, `powers_hom` is a multiplicative equivalence. -/ def powers_mul_hom [comm_monoid M] : M ≃* (multiplicative ℕ →* M) := { map_mul' := λ a b, monoid_hom.ext $ by simp [mul_pow], ..powers_hom M} /-- If `M` is commutative, `zpowers_hom` is a multiplicative equivalence. -/ def zpowers_mul_hom [comm_group G] : G ≃* (multiplicative ℤ →* G) := { map_mul' := λ a b, monoid_hom.ext $ by simp [mul_zpow], ..zpowers_hom G} /-- If `M` is commutative, `multiples_hom` is an additive equivalence. -/ def multiples_add_hom [add_comm_monoid A] : A ≃+ (ℕ →+ A) := { map_add' := λ a b, add_monoid_hom.ext $ by simp [nsmul_add], ..multiples_hom A} /-- If `M` is commutative, `zmultiples_hom` is an additive equivalence. -/ def zmultiples_add_hom [add_comm_group A] : A ≃+ (ℤ →+ A) := { map_add' := λ a b, add_monoid_hom.ext $ by simp [zsmul_add], ..zmultiples_hom A} variables {M G A} @[simp] lemma powers_mul_hom_apply [comm_monoid M] (x : M) (n : multiplicative ℕ) : powers_mul_hom M x n = x ^ n.to_add := rfl @[simp] lemma powers_mul_hom_symm_apply [comm_monoid M] (f : multiplicative ℕ →* M) : (powers_mul_hom M).symm f = f (multiplicative.of_add 1) := rfl @[simp] lemma zpowers_mul_hom_apply [comm_group G] (x : G) (n : multiplicative ℤ) : zpowers_mul_hom G x n = x ^ n.to_add := rfl @[simp] lemma zpowers_mul_hom_symm_apply [comm_group G] (f : multiplicative ℤ →* G) : (zpowers_mul_hom G).symm f = f (multiplicative.of_add 1) := rfl @[simp] lemma multiples_add_hom_apply [add_comm_monoid A] (x : A) (n : ℕ) : multiples_add_hom A x n = n • x := rfl @[simp] lemma multiples_add_hom_symm_apply [add_comm_monoid A] (f : ℕ →+ A) : (multiples_add_hom A).symm f = f 1 := rfl @[simp] lemma zmultiples_add_hom_apply [add_comm_group A] (x : A) (n : ℤ) : zmultiples_add_hom A x n = n • x := rfl @[simp] lemma zmultiples_add_hom_symm_apply [add_comm_group A] (f : ℤ →+ A) : (zmultiples_add_hom A).symm f = f 1 := rfl /-! ### Commutativity (again) Facts about `semiconj_by` and `commute` that require `zpow` or `zsmul`, or the fact that integer multiplication equals semiring multiplication. -/ namespace semiconj_by section variables [semiring R] {a x y : R} @[simp] lemma cast_nat_mul_right (h : semiconj_by a x y) (n : ℕ) : semiconj_by a ((n : R) * x) (n * y) := semiconj_by.mul_right (nat.commute_cast _ _) h @[simp] lemma cast_nat_mul_left (h : semiconj_by a x y) (n : ℕ) : semiconj_by ((n : R) * a) x y := semiconj_by.mul_left (nat.cast_commute _ _) h @[simp] lemma cast_nat_mul_cast_nat_mul (h : semiconj_by a x y) (m n : ℕ) : semiconj_by ((m : R) * a) (n * x) (n * y) := (h.cast_nat_mul_left m).cast_nat_mul_right n end variables [monoid M] [group G] [ring R] @[simp, to_additive] lemma units_zpow_right {a : M} {x y : Mˣ} (h : semiconj_by a x y) : ∀ m : ℤ, semiconj_by a (↑(x^m)) (↑(y^m)) | (n : ℕ) := by simp only [zpow_coe_nat, units.coe_pow, h, pow_right] | -[1+n] := by simp only [zpow_neg_succ_of_nat, units.coe_pow, units_inv_right, h, pow_right] variables {a b x y x' y' : R} @[simp] lemma cast_int_mul_right (h : semiconj_by a x y) (m : ℤ) : semiconj_by a ((m : ℤ) * x) (m * y) := semiconj_by.mul_right (int.commute_cast _ _) h @[simp] lemma cast_int_mul_left (h : semiconj_by a x y) (m : ℤ) : semiconj_by ((m : R) * a) x y := semiconj_by.mul_left (int.cast_commute _ _) h @[simp] lemma cast_int_mul_cast_int_mul (h : semiconj_by a x y) (m n : ℤ) : semiconj_by ((m : R) * a) (n * x) (n * y) := (h.cast_int_mul_left m).cast_int_mul_right n end semiconj_by namespace commute section variables [semiring R] {a b : R} @[simp] theorem cast_nat_mul_right (h : commute a b) (n : ℕ) : commute a ((n : R) * b) := h.cast_nat_mul_right n @[simp] theorem cast_nat_mul_left (h : commute a b) (n : ℕ) : commute ((n : R) * a) b := h.cast_nat_mul_left n @[simp] theorem cast_nat_mul_cast_nat_mul (h : commute a b) (m n : ℕ) : commute ((m : R) * a) (n * b) := h.cast_nat_mul_cast_nat_mul m n @[simp] theorem self_cast_nat_mul (n : ℕ) : commute a (n * a) := (commute.refl a).cast_nat_mul_right n @[simp] theorem cast_nat_mul_self (n : ℕ) : commute ((n : R) * a) a := (commute.refl a).cast_nat_mul_left n @[simp] theorem self_cast_nat_mul_cast_nat_mul (m n : ℕ) : commute ((m : R) * a) (n * a) := (commute.refl a).cast_nat_mul_cast_nat_mul m n end variables [monoid M] [group G] [ring R] @[simp, to_additive] lemma units_zpow_right {a : M} {u : Mˣ} (h : commute a u) (m : ℤ) : commute a (↑(u^m)) := h.units_zpow_right m @[simp, to_additive] lemma units_zpow_left {u : Mˣ} {a : M} (h : commute ↑u a) (m : ℤ) : commute (↑(u^m)) a := (h.symm.units_zpow_right m).symm variables {a b : R} @[simp] lemma cast_int_mul_right (h : commute a b) (m : ℤ) : commute a (m * b) := h.cast_int_mul_right m @[simp] lemma cast_int_mul_left (h : commute a b) (m : ℤ) : commute ((m : R) * a) b := h.cast_int_mul_left m lemma cast_int_mul_cast_int_mul (h : commute a b) (m n : ℤ) : commute ((m : R) * a) (n * b) := h.cast_int_mul_cast_int_mul m n variables (a) (m n : ℤ) @[simp] lemma cast_int_left : commute (m : R) a := by { rw [← mul_one (m : R)], exact (one_left a).cast_int_mul_left m } @[simp] lemma cast_int_right : commute a m := by { rw [← mul_one (m : R)], exact (one_right a).cast_int_mul_right m } @[simp] theorem self_cast_int_mul : commute a (n * a) := (commute.refl a).cast_int_mul_right n @[simp] theorem cast_int_mul_self : commute ((n : R) * a) a := (commute.refl a).cast_int_mul_left n theorem self_cast_int_mul_cast_int_mul : commute ((m : R) * a) (n * a) := (commute.refl a).cast_int_mul_cast_int_mul m n end commute section multiplicative open multiplicative @[simp] lemma nat.to_add_pow (a : multiplicative ℕ) (b : ℕ) : to_add (a ^ b) = to_add a * b := begin induction b with b ih, { erw [pow_zero, to_add_one, mul_zero] }, { simp [*, pow_succ, add_comm, nat.mul_succ] } end @[simp] lemma nat.of_add_mul (a b : ℕ) : of_add (a * b) = of_add a ^ b := (nat.to_add_pow _ _).symm @[simp] lemma int.to_add_pow (a : multiplicative ℤ) (b : ℕ) : to_add (a ^ b) = to_add a * b := by induction b; simp [*, mul_add, pow_succ, add_comm] @[simp] lemma int.to_add_zpow (a : multiplicative ℤ) (b : ℤ) : to_add (a ^ b) = to_add a * b := int.induction_on b (by simp) (by simp [zpow_add, mul_add] {contextual := tt}) (by simp [zpow_add, mul_add, sub_eq_add_neg, -int.add_neg_one] {contextual := tt}) @[simp] lemma int.of_add_mul (a b : ℤ) : of_add (a * b) = of_add a ^ b := (int.to_add_zpow _ _).symm end multiplicative namespace units variables [monoid M] lemma conj_pow (u : Mˣ) (x : M) (n : ℕ) : (↑u * x * ↑(u⁻¹))^n = u * x^n * ↑(u⁻¹) := (divp_eq_iff_mul_eq.2 ((u.mk_semiconj_by x).pow_right n).eq.symm).symm lemma conj_pow' (u : Mˣ) (x : M) (n : ℕ) : (↑(u⁻¹) * x * u)^n = ↑(u⁻¹) * x^n * u:= (u⁻¹).conj_pow x n end units namespace mul_opposite /-- Moving to the opposite monoid commutes with taking powers. -/ @[simp] lemma op_pow [monoid M] (x : M) (n : ℕ) : op (x ^ n) = (op x) ^ n := rfl @[simp] lemma unop_pow [monoid M] (x : Mᵐᵒᵖ) (n : ℕ) : unop (x ^ n) = (unop x) ^ n := rfl /-- Moving to the opposite group or group_with_zero commutes with taking powers. -/ @[simp] lemma op_zpow [div_inv_monoid M] (x : M) (z : ℤ) : op (x ^ z) = (op x) ^ z := rfl @[simp] lemma unop_zpow [div_inv_monoid M] (x : Mᵐᵒᵖ) (z : ℤ) : unop (x ^ z) = (unop x) ^ z := rfl end mul_opposite
""" Solve method for DiffEq solution """ function get_de_ic(prob,eqs,u0=nothing) if u0 == nothing @info "Setting a random initial condition..." rand(eqs,prob.d) elseif typeof(u0) <: Number typeof(eqs) == CE2 ? fullrank(eqs,prob.d,u0) : rand(eqs,prob.d,u0) else @info "Converting QL solution to CE2 initial condition..." convert(eqs,u0,prob.d) # u0 = convert(eqs,u0,prob.d) # small noise to m = 1 # for n = 1:2prob.d.ny-1 # u0.x[2][n,n,1] += 1e-6*exp(im*rand(Uniform(0,2π))) # @show u0.x[2][n,n,1] # end # return u0 end end function get_de_params(prob,eqs)::AbstractParams A = acoeffs(prob) B = bcoeffs(prob) C⁺,C⁻ = ccoeffs(prob,eqs) F = fcoeffs(prob,eqs) get_de_p(prob.d,eqs,[A,B,C⁺,C⁻,F]) end get_de_p(d,eqs::NL,p) = NLParams(d.nx,d.ny,p...) get_de_p(d,eqs::GQL,p) = GQLParams(d.nx,d.ny,eqs.Λ,p...) get_de_p(d,eqs::CE2,p) = CE2Params(d.nx,d.ny,p...) get_de_p(d,eqs::GCE2,p) = GCE2Params(d.nx,d.ny,eqs.Λ,p...) get_de_probalg(prob,eqs,u0,t,p) = ODEProblem(f!,u0,t,p), DP5() get_de_probalg(prob::BetaPlane{T,Stochastic{T}},eqs::CE2,u0,t,p) where T = ODEProblem(f!,u0,t,p), RK4() get_de_probalg(prob::BetaPlane{T,Stochastic{T}},eqs,u0,t,p) where T = SDEProblem(f!,g!,u0,t,p), SRIW1() get_de_kwargs(prob,eqs::AbstractEquations,tspan;kwargs...) = kwargs function get_de_kwargs(prob,eqs::GCE2,tspan;kwargs...) if(!eqs.poscheck) return kwargs end @info "Setting positivity check callback..." poschecktimes = [tt for tt=tspan[1]:eqs.poscheckat:tspan[2]] condition(u,t,integrator) = t ∈ poschecktimes && !ispositive(u.x[2],prob.d.nx,prob.d.ny,eqs.Λ) affect!(integrator) = positivity!(integrator.u.x[2],prob.d.nx,prob.d.ny,eqs.Λ) poscheckcb = DiscreteCallback(condition,affect!,save_positions=(false,false)) merge((callback=poscheckcb,tstops=poschecktimes),kwargs) end function get_de_kwargs(prob,eqs::CE2,tspan;kwargs...) if(!eqs.poscheck && !eqs.eigmax) return kwargs elseif(eqs.poscheck && !eqs.eigmax) @info "Setting positivity check callback..." poschecktimes = [tt for tt=tspan[1]:eqs.poscheckat:tspan[2]] condition(u,t,integrator) = t ∈ poschecktimes temp = zeros(ComplexF64,2*prob.d.ny-1,prob.d.nx-1,2*prob.d.ny-1,prob.d.nx-1) posaffect!(integrator) = positivity!(integrator.u.x[2],temp,prob.d.nx,prob.d.ny) poscondition(u,t,integrator) = t > 0.0 poscheckcb = DiscreteCallback(poscondition,posaffect!,save_positions=(false,false)) return merge((callback=poscheckcb,tstops=poschecktimes),kwargs) else @info "Removing all but the largest modal eigenvalues..." temp = zeros(ComplexF64,2*prob.d.ny-1,2*prob.d.ny-1,prob.d.nx-1) maxcondition(u,t,integrator) = true maxaffect!(integrator) = truncatecumulant!(prob.d,integrator.u.x[2],temp) eigmaxcb = DiscreteCallback(maxcondition,maxaffect!,save_positions=(false,false)) return merge((callback=eigmaxcb,tspan=tspan),kwargs) end end function integrate(prob,eqs::AbstractEquations,tspan;u0=nothing,kwargs...) Random.seed!(123) _u0 = get_de_ic(prob,eqs,u0) _p = get_de_params(prob,eqs) _prob,_alg = get_de_probalg(prob,eqs,_u0,tspan,_p) _kwargs = get_de_kwargs(prob,eqs,tspan;kwargs...) @time solve(_prob,_alg;_kwargs...) end integrate(prob,eqs::Vector{AbstractEquations},tspan;kwargs...) = [integrate(prob,eq,tspan;kwargs...) for eq in eqs]
[GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E x : E x✝ : x ∈ univ ⊢ (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x ∈ ball 0 1 [PROOFSTEP] have : 0 < 1 + ‖x‖ ^ 2 := by positivity [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E x : E x✝ : x ∈ univ ⊢ 0 < 1 + ‖x‖ ^ 2 [PROOFSTEP] positivity [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E x : E x✝ : x ∈ univ this : 0 < 1 + ‖x‖ ^ 2 ⊢ (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x ∈ ball 0 1 [PROOFSTEP] rw [mem_ball_zero_iff, norm_smul, Real.norm_eq_abs, abs_inv, ← _root_.div_eq_inv_mul, div_lt_one (abs_pos.mpr <| Real.sqrt_ne_zero'.mpr this), ← abs_norm x, ← sq_lt_sq, abs_norm, Real.sq_sqrt this.le] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E x : E x✝ : x ∈ univ this : 0 < 1 + ‖x‖ ^ 2 ⊢ ‖x‖ ^ 2 < 1 + ‖x‖ ^ 2 [PROOFSTEP] exact lt_one_add _ [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E x : E x✝ : x ∈ univ ⊢ (fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y) ((fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x) = x [PROOFSTEP] field_simp [norm_smul, smul_smul, (zero_lt_one_add_norm_sq x).ne', sq_abs, Real.sq_sqrt (zero_lt_one_add_norm_sq x).le, ← Real.sqrt_div (zero_lt_one_add_norm_sq x).le] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E y : E hy : y ∈ ball 0 1 ⊢ (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) ((fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y) y) = y [PROOFSTEP] have : 0 < 1 - ‖y‖ ^ 2 := by nlinarith [norm_nonneg y, mem_ball_zero_iff.1 hy] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E y : E hy : y ∈ ball 0 1 ⊢ 0 < 1 - ‖y‖ ^ 2 [PROOFSTEP] nlinarith [norm_nonneg y, mem_ball_zero_iff.1 hy] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E y : E hy : y ∈ ball 0 1 this : 0 < 1 - ‖y‖ ^ 2 ⊢ (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) ((fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y) y) = y [PROOFSTEP] field_simp [norm_smul, smul_smul, this.ne', sq_abs, Real.sq_sqrt this.le, ← Real.sqrt_div this.le] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E ⊢ ContinuousOn ↑{ toFun := fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x, invFun := fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y, source := univ, target := ball 0 1, map_source' := (_ : ∀ (x : E), x ∈ univ → (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x ∈ ball 0 1), map_target' := (_ : ∀ (x : E), x ∈ ball 0 1 → True), left_inv' := (_ : ∀ (x : E), x ∈ univ → (Real.sqrt (1 - ‖(Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x‖ ^ 2))⁻¹ • (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x = x), right_inv' := (_ : ∀ (y : E), y ∈ ball 0 1 → (Real.sqrt (1 + ‖(Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y‖ ^ 2))⁻¹ • (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y = y) } { toFun := fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x, invFun := fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y, source := univ, target := ball 0 1, map_source' := (_ : ∀ (x : E), x ∈ univ → (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x ∈ ball 0 1), map_target' := (_ : ∀ (x : E), x ∈ ball 0 1 → True), left_inv' := (_ : ∀ (x : E), x ∈ univ → (Real.sqrt (1 - ‖(Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x‖ ^ 2))⁻¹ • (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x = x), right_inv' := (_ : ∀ (y : E), y ∈ ball 0 1 → (Real.sqrt (1 + ‖(Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y‖ ^ 2))⁻¹ • (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y = y) }.source [PROOFSTEP] suffices Continuous fun (x : E) => (1 + ‖x‖ ^ 2).sqrt⁻¹ from (this.smul continuous_id).continuousOn [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E ⊢ Continuous fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ [PROOFSTEP] refine' Continuous.inv₀ _ fun x => Real.sqrt_ne_zero'.mpr (by positivity) [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E x : E ⊢ 0 < 1 + ‖x‖ ^ 2 [PROOFSTEP] positivity [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E ⊢ Continuous fun x => Real.sqrt (1 + ‖x‖ ^ 2) [PROOFSTEP] continuity [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E ⊢ ContinuousOn { toFun := fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x, invFun := fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y, source := univ, target := ball 0 1, map_source' := (_ : ∀ (x : E), x ∈ univ → (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x ∈ ball 0 1), map_target' := (_ : ∀ (x : E), x ∈ ball 0 1 → True), left_inv' := (_ : ∀ (x : E), x ∈ univ → (Real.sqrt (1 - ‖(Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x‖ ^ 2))⁻¹ • (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x = x), right_inv' := (_ : ∀ (y : E), y ∈ ball 0 1 → (Real.sqrt (1 + ‖(Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y‖ ^ 2))⁻¹ • (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y = y) }.invFun { toFun := fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x, invFun := fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y, source := univ, target := ball 0 1, map_source' := (_ : ∀ (x : E), x ∈ univ → (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x ∈ ball 0 1), map_target' := (_ : ∀ (x : E), x ∈ ball 0 1 → True), left_inv' := (_ : ∀ (x : E), x ∈ univ → (Real.sqrt (1 - ‖(Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x‖ ^ 2))⁻¹ • (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x = x), right_inv' := (_ : ∀ (y : E), y ∈ ball 0 1 → (Real.sqrt (1 + ‖(Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y‖ ^ 2))⁻¹ • (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y = y) }.target [PROOFSTEP] have : ∀ y ∈ ball (0 : E) 1, (1 - ‖(y : E)‖ ^ 2).sqrt ≠ 0 := fun y hy ↦ by rw [Real.sqrt_ne_zero'] nlinarith [norm_nonneg y, mem_ball_zero_iff.1 hy] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E y : E hy : y ∈ ball 0 1 ⊢ Real.sqrt (1 - ‖y‖ ^ 2) ≠ 0 [PROOFSTEP] rw [Real.sqrt_ne_zero'] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E y : E hy : y ∈ ball 0 1 ⊢ 0 < 1 - ‖y‖ ^ 2 [PROOFSTEP] nlinarith [norm_nonneg y, mem_ball_zero_iff.1 hy] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E this : ∀ (y : E), y ∈ ball 0 1 → Real.sqrt (1 - ‖y‖ ^ 2) ≠ 0 ⊢ ContinuousOn { toFun := fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x, invFun := fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y, source := univ, target := ball 0 1, map_source' := (_ : ∀ (x : E), x ∈ univ → (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x ∈ ball 0 1), map_target' := (_ : ∀ (x : E), x ∈ ball 0 1 → True), left_inv' := (_ : ∀ (x : E), x ∈ univ → (Real.sqrt (1 - ‖(Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x‖ ^ 2))⁻¹ • (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x = x), right_inv' := (_ : ∀ (y : E), y ∈ ball 0 1 → (Real.sqrt (1 + ‖(Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y‖ ^ 2))⁻¹ • (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y = y) }.invFun { toFun := fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x, invFun := fun y => (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y, source := univ, target := ball 0 1, map_source' := (_ : ∀ (x : E), x ∈ univ → (fun x => (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x) x ∈ ball 0 1), map_target' := (_ : ∀ (x : E), x ∈ ball 0 1 → True), left_inv' := (_ : ∀ (x : E), x ∈ univ → (Real.sqrt (1 - ‖(Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x‖ ^ 2))⁻¹ • (Real.sqrt (1 + ‖x‖ ^ 2))⁻¹ • x = x), right_inv' := (_ : ∀ (y : E), y ∈ ball 0 1 → (Real.sqrt (1 + ‖(Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y‖ ^ 2))⁻¹ • (Real.sqrt (1 - ‖y‖ ^ 2))⁻¹ • y = y) }.target [PROOFSTEP] exact ContinuousOn.smul (ContinuousOn.inv₀ (continuousOn_const.sub (continuous_norm.continuousOn.pow _)).sqrt this) continuousOn_id [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E ⊢ ↑univUnitBall 0 = 0 [PROOFSTEP] simp [LocalHomeomorph.univUnitBall_apply] [GOAL] E : Type u_1 inst✝¹ : SeminormedAddCommGroup E inst✝ : NormedSpace ℝ E ⊢ ↑(LocalHomeomorph.symm univUnitBall) 0 = 0 [PROOFSTEP] simp [LocalHomeomorph.univUnitBall_symm_apply] [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ hr : 0 < r ⊢ ↑(Homeomorph.trans (Homeomorph.smulOfNeZero r (_ : r ≠ 0)) (IsometryEquiv.toHomeomorph (IsometryEquiv.vaddConst c))) '' ball 0 1 = ball c r [PROOFSTEP] change (IsometryEquiv.vaddConst c) ∘ (r • ·) '' ball (0 : E) 1 = ball c r [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ hr : 0 < r ⊢ (↑(IsometryEquiv.vaddConst c) ∘ fun x => r • x) '' ball 0 1 = ball c r [PROOFSTEP] rw [image_comp, image_smul, smul_unitBall hr.ne', IsometryEquiv.image_ball] [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ hr : 0 < r ⊢ ball (↑(IsometryEquiv.vaddConst c) 0) ‖r‖ = ball c r [PROOFSTEP] simp [abs_of_pos hr] [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ ⊢ (univBall c r).toLocalEquiv.source = univ [PROOFSTEP] unfold univBall [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ ⊢ (if h : 0 < r then LocalHomeomorph.trans' univUnitBall (unitBallBall c r h) (_ : univUnitBall.toLocalEquiv.target = univUnitBall.toLocalEquiv.target) else Homeomorph.toLocalHomeomorph (IsometryEquiv.toHomeomorph (IsometryEquiv.vaddConst c))).toLocalEquiv.source = univ [PROOFSTEP] split_ifs [GOAL] case pos E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ h✝ : 0 < r ⊢ (LocalHomeomorph.trans' univUnitBall (unitBallBall c r h✝) (_ : univUnitBall.toLocalEquiv.target = univUnitBall.toLocalEquiv.target)).toLocalEquiv.source = univ [PROOFSTEP] rfl [GOAL] case neg E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ h✝ : ¬0 < r ⊢ (Homeomorph.toLocalHomeomorph (IsometryEquiv.toHomeomorph (IsometryEquiv.vaddConst c))).toLocalEquiv.source = univ [PROOFSTEP] rfl [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ hr : 0 < r ⊢ (univBall c r).toLocalEquiv.target = ball c r [PROOFSTEP] rw [univBall, dif_pos hr] [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ hr : 0 < r ⊢ (LocalHomeomorph.trans' univUnitBall (unitBallBall c r hr) (_ : univUnitBall.toLocalEquiv.target = univUnitBall.toLocalEquiv.target)).toLocalEquiv.target = ball c r [PROOFSTEP] rfl [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ ⊢ ball c r ⊆ (univBall c r).toLocalEquiv.target [PROOFSTEP] by_cases hr : 0 < r [GOAL] case pos E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ hr : 0 < r ⊢ ball c r ⊆ (univBall c r).toLocalEquiv.target [PROOFSTEP] rw [univBall_target c hr] [GOAL] case neg E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ hr : ¬0 < r ⊢ ball c r ⊆ (univBall c r).toLocalEquiv.target [PROOFSTEP] rw [univBall, dif_neg hr] [GOAL] case neg E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ hr : ¬0 < r ⊢ ball c r ⊆ (Homeomorph.toLocalHomeomorph (IsometryEquiv.toHomeomorph (IsometryEquiv.vaddConst c))).toLocalEquiv.target [PROOFSTEP] exact subset_univ _ [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ ⊢ ↑(univBall c r) 0 = c [PROOFSTEP] unfold univBall [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ ⊢ ↑(if h : 0 < r then LocalHomeomorph.trans' univUnitBall (unitBallBall c r h) (_ : univUnitBall.toLocalEquiv.target = univUnitBall.toLocalEquiv.target) else Homeomorph.toLocalHomeomorph (IsometryEquiv.toHomeomorph (IsometryEquiv.vaddConst c))) 0 = c [PROOFSTEP] split_ifs [GOAL] case pos E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ h✝ : 0 < r ⊢ ↑(LocalHomeomorph.trans' univUnitBall (unitBallBall c r h✝) (_ : univUnitBall.toLocalEquiv.target = univUnitBall.toLocalEquiv.target)) 0 = c [PROOFSTEP] simp [GOAL] case neg E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ h✝ : ¬0 < r ⊢ ↑(Homeomorph.toLocalHomeomorph (IsometryEquiv.toHomeomorph (IsometryEquiv.vaddConst c))) 0 = c [PROOFSTEP] simp [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ ⊢ ↑(LocalHomeomorph.symm (univBall c r)) c = 0 [PROOFSTEP] have : 0 ∈ (univBall c r).source := by simp [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ ⊢ 0 ∈ (univBall c r).toLocalEquiv.source [PROOFSTEP] simp [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ this : 0 ∈ (univBall c r).toLocalEquiv.source ⊢ ↑(LocalHomeomorph.symm (univBall c r)) c = 0 [PROOFSTEP] simpa only [univBall_apply_zero] using (univBall c r).left_inv this [GOAL] E : Type u_1 inst✝³ : SeminormedAddCommGroup E inst✝² : NormedSpace ℝ E P : Type u_2 inst✝¹ : PseudoMetricSpace P inst✝ : NormedAddTorsor E P c : P r : ℝ ⊢ Continuous ↑(univBall c r) [PROOFSTEP] simpa [continuous_iff_continuousOn_univ] using (univBall c r).continuousOn
theory Prelude_ListWithNumbers__RE1 imports "$HETS_ISABELLE_LIB/MainHC" uses "$HETS_ISABELLE_LIB/prelude" begin setup "Header.initialize [\"ga_monotonicity\", \"ga_monotonicity_1\", \"ga_monotonicity_2\", \"ga_monotonicity_3\", \"ga_monotonicity_4\", \"ga_monotonicity_5\", \"ga_monotonicity_6\", \"ga_monotonicity_7\", \"ga_monotonicity_8\", \"ga_monotonicity_9\", \"ga_monotonicity_10\", \"ga_monotonicity_11\", \"ga_monotonicity_12\", \"ga_monotonicity_13\", \"ga_monotonicity_14\", \"ga_monotonicity_15\", \"ga_monotonicity_16\", \"ga_monotonicity_17\", \"ga_monotonicity_18\", \"ga_monotonicity_19\", \"ga_monotonicity_20\", \"ga_monotonicity_21\", \"ga_monotonicity_22\", \"ga_monotonicity_23\", \"ga_monotonicity_24\", \"ga_monotonicity_25\", \"ga_monotonicity_26\", \"ga_monotonicity_27\", \"ga_monotonicity_28\", \"ga_monotonicity_29\", \"ga_monotonicity_30\", \"ga_monotonicity_31\", \"ga_monotonicity_32\", \"ga_monotonicity_33\", \"ga_monotonicity_34\", \"ga_monotonicity_35\", \"ga_monotonicity_36\", \"ga_monotonicity_37\", \"ga_monotonicity_38\", \"ga_monotonicity_39\", \"ga_monotonicity_40\", \"ga_monotonicity_41\", \"ga_monotonicity_42\", \"ga_monotonicity_43\", \"ga_monotonicity_44\", \"ga_monotonicity_45\", \"ga_monotonicity_46\", \"ga_monotonicity_47\", \"ga_monotonicity_48\", \"ga_monotonicity_49\", \"ga_monotonicity_50\", \"ga_monotonicity_51\", \"ga_monotonicity_52\", \"ga_monotonicity_53\", \"ga_monotonicity_54\", \"ga_monotonicity_55\", \"ga_monotonicity_56\", \"ga_monotonicity_57\", \"ga_monotonicity_58\", \"ga_monotonicity_59\", \"ga_monotonicity_60\", \"ga_monotonicity_61\", \"ga_monotonicity_62\", \"ga_monotonicity_63\", \"ga_monotonicity_64\", \"ga_monotonicity_65\", \"ga_monotonicity_66\", \"ga_monotonicity_67\", \"ga_monotonicity_68\", \"ga_monotonicity_69\", \"ga_monotonicity_70\", \"ga_monotonicity_71\", \"ga_monotonicity_72\", \"ga_monotonicity_73\", \"ga_monotonicity_74\", \"ga_monotonicity_75\", \"ga_monotonicity_76\", \"ga_monotonicity_77\", \"ga_monotonicity_78\", \"ga_monotonicity_79\", \"ga_monotonicity_80\", \"ga_monotonicity_81\", \"ga_monotonicity_82\", \"ga_monotonicity_83\", \"ga_monotonicity_84\", \"ga_monotonicity_85\", \"ga_monotonicity_86\", \"ga_monotonicity_87\", \"ga_monotonicity_88\", \"ga_monotonicity_89\", \"ga_monotonicity_90\", \"ga_subt_reflexive\", \"ga_subt_transitive\", \"ga_subt_inj_proj\", \"ga_inj_transitive\", \"ga_subt_Int_XLt_Rat\", \"ga_subt_Nat_XLt_Int\", \"ga_subt_Pos_XLt_Nat\", \"Comp1\", \"IdDef\", \"FlipDef\", \"FstDef\", \"SndDef\", \"CurryDef\", \"UncurryDef\", \"NotFalse\", \"NotTrue\", \"AndFalse\", \"AndTrue\", \"AndSym\", \"OrDef\", \"OtherwiseDef\", \"NotFalse1\", \"NotTrue1\", \"notNot1\", \"notNot2\", \"EqualTDef\", \"EqualSymDef\", \"EqualReflex\", \"EqualTransT\", \"DiffDef\", \"DiffSymDef\", \"DiffTDef\", \"DiffFDef\", \"TE1\", \"TE2\", \"TE3\", \"TE4\", \"IBE1\", \"IBE2\", \"IBE3\", \"IBE4\", \"IBE5\", \"IBE6\", \"IBE7\", \"IBE8\", \"IUE1\", \"IUE2\", \"IOE01\", \"IOE02\", \"IOE03\", \"IOE04\", \"IOE05\", \"IOE06\", \"IOE07\", \"IOE08\", \"IOE09\", \"LeIrreflexivity\", \"LeTAsymmetry\", \"LeTTransitive\", \"LeTTotal\", \"GeDef\", \"GeIrreflexivity\", \"GeTAsymmetry\", \"GeTTransitive\", \"GeTTotal\", \"LeqDef\", \"LeqReflexivity\", \"LeqTTransitive\", \"LeqTTotal\", \"GeqDef\", \"GeqReflexivity\", \"GeqTTransitive\", \"GeqTTotal\", \"EqTSOrdRel\", \"EqFSOrdRel\", \"EqTOrdRel\", \"EqFOrdRel\", \"EqTOrdTSubstE\", \"EqTOrdFSubstE\", \"EqTOrdTSubstD\", \"EqTOrdFSubstD\", \"LeTGeFEqFRel\", \"LeFGeTEqTRel\", \"LeTGeTRel\", \"LeFGeFRel\", \"LeqTGetTRel\", \"LeqFGetFRel\", \"GeTLeTRel\", \"GeFLeFRel\", \"GeqTLeqTRel\", \"GeqFLeqFRel\", \"LeqTGeFRel\", \"LeqFGeTRel\", \"GeTLeFEqFRel\", \"GeFLeTEqTRel\", \"GeqTLeFRel\", \"GeqFLeTRel\", \"LeqTLeTEqTRel\", \"LeqFLeFEqFRel\", \"GeqTGeTEqTRel\", \"GeqFGeFEqFRel\", \"LeTGeqFRel\", \"GeTLeqFRel\", \"LeLeqDiff\", \"CmpLTDef\", \"CmpEQDef\", \"CmpGTDef\", \"MaxYDef\", \"MaxXDef\", \"MinXDef\", \"MinYDef\", \"MaxSym\", \"MinSym\", \"TO1\", \"TO3\", \"TO4\", \"TO5\", \"IOO13\", \"IOO14\", \"IOO15\", \"IOO16\", \"IOO17\", \"IOO18\", \"IOO19\", \"IOO20\", \"IOO21\", \"IOO22\", \"IOO23\", \"IOO24\", \"IOO25\", \"IOO26\", \"IOO27\", \"IOO28\", \"IOO29\", \"IOO30\", \"IOO31\", \"IOO32\", \"IOO33\", \"IBO5\", \"IBO6\", \"IBO7\", \"IBO8\", \"IBO9\", \"IBO10\", \"IBO11\", \"IBO12\", \"IUO01\", \"IUO02\", \"IUO03\", \"IUO04\", \"IUO05\", \"IUO06\", \"IUO07\", \"NotDefHead\", \"HeadDef\", \"NotDefTail\", \"TailDef\", \"FoldrNil\", \"FoldrCons\", \"FoldlNil\", \"FoldlCons\", \"MapNil\", \"MapCons\", \"XPlusXPlusNil\", \"XPlusXPlusCons\", \"FilterNil\", \"FilterConsT\", \"FilterConsF\", \"ZipNil\", \"ZipConsNil\", \"ZipConsCons\", \"UnzipNil\", \"UnzipCons\", \"ILE01\", \"ILE02\", \"ILO01\", \"ILO02\", \"ILO03\", \"ILO04\", \"ILO05\", \"ILO06\", \"ILO07\", \"ILO08\", \"ILO09\", \"ILO10\", \"ILO11\", \"ILO12\", \"ILO13\", \"ILO14\", \"ILO15\", \"ILO16\", \"ILO17\", \"ILO18\", \"ILO19\", \"ILO20\", \"ILO21\", \"ILO22\", \"FoldlDecomp\", \"MapDecomp\", \"MapFunctor\", \"FilterProm\", \"InitNil\", \"InitConsNil\", \"InitConsCons\", \"LastNil\", \"LastConsNil\", \"LastConsCons\", \"NullNil\", \"NullCons\", \"ReverseNil\", \"ReverseCons\", \"Foldr1Nil\", \"Foldr1ConsNil\", \"Foldr1ConsCons\", \"Foldl1Nil\", \"Foldl1ConsNil\", \"Foldl1ConsCons\", \"ScanlNil\", \"ScanlCons\", \"Scanl1Nil\", \"Scanl1Cons\", \"ScanrNil\", \"ScanrCons\", \"Scanr1Nil\", \"Scanr1ConsNil\", \"Scanr1ConsCons\", \"ScanlProperty\", \"ScanrProperty\", \"AndLNil\", \"AndLCons\", \"OrLNil\", \"OrLCons\", \"AnyDef\", \"AllDef\", \"ConcatDef\", \"ConcatMapDef\", \"MaximunNil\", \"MaximumDef\", \"MinimunNil\", \"MinimumDef\", \"TakeWhileNil\", \"TakeWhileConsT\", \"TakeWhileConsF\", \"DropWhileNil\", \"DropWhileConsT\", \"DropWhileConsF\", \"SpanNil\", \"SpanConsT\", \"SpanConsF\", \"SpanThm\", \"BreakDef\", \"BreakThm\", \"InsertNil\", \"InsertCons1\", \"InsertCons2\", \"DeleteNil\", \"DeleteConsT\", \"DeleteConsF\", \"SelectT\", \"SelectF\", \"Partition\", \"PartitionProp\", \"PartialTest\", \"ga_selector_pre\", \"ga_injective_suc\", \"ga_disjoint_0_suc\", \"ga_selector_undef_pre_0\", \"X1_def_Nat\", \"X2_def_Nat\", \"X3_def_Nat\", \"X4_def_Nat\", \"X5_def_Nat\", \"X6_def_Nat\", \"X7_def_Nat\", \"X8_def_Nat\", \"X9_def_Nat\", \"decimal_def\", \"ga_comm___XPlus__\", \"ga_assoc___XPlus__\", \"ga_right_unit___XPlus__\", \"ga_left_unit___XPlus__\", \"ga_left_comm___XPlus__\", \"ga_comm___Xx__\", \"ga_assoc___Xx__\", \"ga_right_unit___Xx__\", \"ga_left_unit___Xx__\", \"ga_left_comm___Xx__\", \"ga_comm_min\", \"ga_assoc_min\", \"ga_left_comm_min\", \"ga_comm_max\", \"ga_assoc_max\", \"ga_right_unit_max\", \"ga_left_unit_max\", \"ga_left_comm_max\", \"leq_def1_Nat\", \"dvd_def_Nat\", \"leq_def2_Nat\", \"leq_def3_Nat\", \"geq_def_Nat\", \"less_def_Nat\", \"greater_def_Nat\", \"even_0_Nat\", \"even_suc_Nat\", \"odd_def_Nat\", \"factorial_0\", \"factorial_suc\", \"add_0_Nat\", \"add_suc_Nat\", \"mult_0_Nat\", \"mult_suc_Nat\", \"power_0_Nat\", \"power_suc_Nat\", \"min_def_Nat\", \"max_def_Nat\", \"subTotal_def1_Nat\", \"subTotal_def2_Nat\", \"sub_dom_Nat\", \"sub_def_Nat\", \"divide_dom_Nat\", \"divide_0_Nat\", \"divide_Pos_Nat\", \"div_dom_Nat\", \"div_Nat\", \"mod_dom_Nat\", \"mod_Nat\", \"distr1_Nat\", \"distr2_Nat\", \"Pos_def\", \"X1_as_Pos_def\", \"min_0\", \"div_mod_Nat\", \"power_Nat\", \"ga_generated_Int\", \"equality_Int\", \"Nat2Int_embedding\", \"ga_comm___XPlus___80\", \"ga_assoc___XPlus___76\", \"ga_right_unit___XPlus___90\", \"ga_left_unit___XPlus___88\", \"ga_left_comm___XPlus___84\", \"ga_comm___Xx___79\", \"ga_assoc___Xx___75\", \"ga_right_unit___Xx___89\", \"ga_left_unit___Xx___87\", \"ga_left_comm___Xx___83\", \"ga_comm_min_82\", \"ga_comm_max_81\", \"ga_assoc_min_78\", \"ga_assoc_max_77\", \"ga_left_comm_min_86\", \"ga_left_comm_max_85\", \"leq_def_Int\", \"geq_def_Int\", \"less_def_Int\", \"greater_def_Int\", \"even_def_Int\", \"odd_def_Int\", \"odd_alt_Int\", \"neg_def_Int\", \"sign_def_Int\", \"abs_def_Int\", \"add_def_Int\", \"mult_def_Int\", \"sub_def_Int\", \"min_def_Int\", \"max_def_Int\", \"power_neg1_Int\", \"power_others_Int\", \"divide_dom2_Int\", \"divide_alt_Int\", \"divide_Int\", \"div_dom_Int\", \"div_Int\", \"quot_dom_Int\", \"quot_neg_Int\", \"quot_nonneg_Int\", \"rem_dom_Int\", \"rem_neg_Int\", \"rem_nonneg_Int\", \"mod_dom_Int\", \"mod_Int\", \"distr1_Int\", \"distr2_Int\", \"Int_Nat_sub_compat\", \"abs_decomp_Int\", \"mod_abs_Int\", \"div_mod_Int\", \"quot_abs_Int\", \"rem_abs_Int\", \"quot_rem_Int\", \"power_Int\", \"ga_generated_Rat\", \"equality_Rat\", \"Int2Rat_embedding\", \"ga_comm___XPlus___139\", \"ga_assoc___XPlus___135\", \"ga_right_unit___XPlus___149\", \"ga_left_unit___XPlus___147\", \"ga_left_comm___XPlus___143\", \"ga_comm___Xx___138\", \"ga_assoc___Xx___134\", \"ga_right_unit___Xx___148\", \"ga_left_unit___Xx___146\", \"ga_left_comm___Xx___142\", \"ga_comm_min_141\", \"ga_comm_max_140\", \"ga_assoc_min_137\", \"ga_assoc_max_136\", \"ga_left_comm_min_145\", \"ga_left_comm_max_144\", \"leq_def_Rat\", \"geq_def_Rat\", \"less_def_Rat\", \"greater_def_Rat\", \"minus_def_Rat\", \"abs_def_Rat\", \"add_def_Rat\", \"sub_def_Rat\", \"mult_def_Rat\", \"min_def_Rat\", \"max_def_Rat\", \"divide_def1_Rat\", \"divide_def2_Rat\", \"power_0_Rat\", \"power_suc_Rat\", \"power_neg_Rat\", \"distr1_Rat\", \"distr2_Rat\", \"sub_rule_Rat\", \"divide_dom_Rat\", \"divide_rule_Rat\", \"power_Rat\", \"AbsSignumLaw\", \"IPN01\", \"IPN02\", \"IPN03\", \"IPN04\", \"IPN05\", \"IPN06\", \"IPN07\", \"INN01\", \"INN02\", \"INN03\", \"INN04\", \"INN05\", \"INN06\", \"INN07\", \"IIN01\", \"IIN02\", \"IIN03\", \"IIN04\", \"IIN05\", \"IIN06\", \"IIN07\", \"IIN07_1\", \"IIN08\", \"IIN09\", \"IRN01\", \"IRN02\", \"IRN03\", \"IRN04\", \"IRN05\", \"IRN06\", \"IRN07\", \"IRN07_2\", \"IRN08\", \"IRN09\", \"IRI01\", \"IRI02\", \"IRI03\", \"IRI04\", \"IRI05\", \"IRI06\", \"IRI01_3\", \"IRI02_4\", \"IRF01\", \"IRF02\", \"LengthNil\", \"LengthCons\", \"TakeNegative\", \"TakeNil\", \"TakeCons\", \"DropNegative\", \"DropNil\", \"DropCons\", \"SplitAt\", \"Sum'Nil\", \"Sum'Cons\", \"SumL\", \"Prod'Nil\", \"Prod'Cons\", \"ProdL\", \"LengthNil1\", \"LengthEqualNil\", \"LengthEqualCons\", \"ZipSpec\"]" typedecl Pos typedecl Rat typedecl Unit typedecl X_Int datatype Bool = X_False ("False''") | X_True ("True''") datatype Ordering = EQ | GT | LT datatype 'a List = X_Cons 'a "'a List" | X_Nil ("Nil''") datatype X_Nat = X0X2 ("0''''") | sucX1 "X_Nat" ("suc''/'(_')" [3] 999) consts X0X1 :: "X_Int" ("0''") X0X3 :: "Rat" ("0'_3") X1X1 :: "X_Int" ("1''") X1X2 :: "X_Nat" ("1''''") X1X3 :: "Pos" ("1'_3") X1X4 :: "Rat" ("1'_4") X2X1 :: "X_Int" ("2''") X2X2 :: "X_Nat" ("2''''") X2X3 :: "Rat" ("2'_3") X3X1 :: "X_Int" ("3''") X3X2 :: "X_Nat" ("3''''") X3X3 :: "Rat" ("3'_3") X4X1 :: "X_Int" ("4''") X4X2 :: "X_Nat" ("4''''") X4X3 :: "Rat" ("4'_3") X5X1 :: "X_Int" ("5''") X5X2 :: "X_Nat" ("5''''") X5X3 :: "Rat" ("5'_3") X6X1 :: "X_Int" ("6''") X6X2 :: "X_Nat" ("6''''") X6X3 :: "Rat" ("6'_3") X7X1 :: "X_Int" ("7''") X7X2 :: "X_Nat" ("7''''") X7X3 :: "Rat" ("7'_3") X8X1 :: "X_Int" ("8''") X8X2 :: "X_Nat" ("8''''") X8X3 :: "Rat" ("8'_3") X9X1 :: "X_Int" ("9''") X9X2 :: "X_Nat" ("9''''") X9X3 :: "Rat" ("9'_3") XMinus__XX1 :: "X_Int => X_Int" ("(-''/ _)" [56] 56) XMinus__XX2 :: "Rat => Rat" ("(-''''/ _)" [56] 56) X__XAmpXAmp__X :: "Bool => Bool => Bool" ("(_/ &&/ _)" [54,54] 52) X__XAtXAt__X :: "X_Nat => X_Nat => X_Nat" ("(_/ @@/ _)" [54,54] 52) X__XCaret__XX1 :: "X_Int => X_Nat => X_Int" ("(_/ ^''/ _)" [54,54] 52) X__XCaret__XX2 :: "X_Nat => X_Nat => X_Nat" ("(_/ ^''''/ _)" [54,54] 52) X__XCaret__XX3 :: "Rat => X_Int => Rat partial" ("(_/ ^'_3/ _)" [54,54] 52) X__XEqXEq__X :: "'a => 'a => Bool" ("(_/ ==''/ _)" [54,54] 52) X__XExclam :: "X_Nat => X_Nat" ("(_/ !'')" [58] 58) X__XGtXEq__XX1 :: "X_Int => X_Int => bool" ("(_/ >=''/ _)" [44,44] 42) X__XGtXEq__XX2 :: "X_Nat => X_Nat => bool" ("(_/ >=''''/ _)" [44,44] 42) X__XGtXEq__XX3 :: "Rat => Rat => bool" ("(_/ >='_3/ _)" [44,44] 42) X__XGtXEq__XX4 :: "'a => 'a => Bool" ("(_/ >='_4/ _)" [54,54] 52) X__XGt__XX1 :: "X_Int => X_Int => bool" ("(_/ >''/ _)" [44,44] 42) X__XGt__XX2 :: "X_Nat => X_Nat => bool" ("(_/ >''''/ _)" [44,44] 42) X__XGt__XX3 :: "Rat => Rat => bool" ("(_/ >'_3/ _)" [44,44] 42) X__XGt__XX4 :: "'a => 'a => Bool" ("(_/ >'_4/ _)" [54,54] 52) X__XLtXEq__XX1 :: "X_Int => X_Int => bool" ("(_/ <=''/ _)" [44,44] 42) X__XLtXEq__XX2 :: "X_Nat => X_Nat => bool" ("(_/ <=''''/ _)" [44,44] 42) X__XLtXEq__XX3 :: "Rat => Rat => bool" ("(_/ <='_3/ _)" [44,44] 42) X__XLtXEq__XX4 :: "'a => 'a => Bool" ("(_/ <='_4/ _)" [54,54] 52) X__XLt__XX1 :: "X_Int => X_Int => bool" ("(_/ <''/ _)" [44,44] 42) X__XLt__XX2 :: "X_Nat => X_Nat => bool" ("(_/ <''''/ _)" [44,44] 42) X__XLt__XX3 :: "Rat => Rat => bool" ("(_/ <'_3/ _)" [44,44] 42) X__XLt__XX4 :: "'a => 'a => Bool" ("(_/ <'_4/ _)" [54,54] 52) X__XMinusXExclam__X :: "X_Nat => X_Nat => X_Nat" ("(_/ -!/ _)" [54,54] 52) X__XMinusXQuest__X :: "X_Nat => X_Nat => X_Nat partial" ("(_/ -?/ _)" [54,54] 52) X__XMinus__XX1 :: "X_Int => X_Int => X_Int" ("(_/ -''/ _)" [54,54] 52) X__XMinus__XX2 :: "X_Nat => X_Nat => X_Int" ("(_/ -''''/ _)" [54,54] 52) X__XMinus__XX3 :: "Rat => Rat => Rat" ("(_/ -'_3/ _)" [54,54] 52) X__XMinus__XX4 :: "'a => 'a => 'a" ("(_/ -'_4/ _)" [54,54] 52) X__XPlusXPlus__X :: "'a List => 'a List => 'a List" ("(_/ ++''/ _)" [54,54] 52) X__XPlus__XX1 :: "X_Int => X_Int => X_Int" ("(_/ +''/ _)" [54,54] 52) X__XPlus__XX2 :: "X_Nat => X_Nat => X_Nat" ("(_/ +''''/ _)" [54,54] 52) X__XPlus__XX3 :: "X_Nat => Pos => Pos" ("(_/ +'_3/ _)" [54,54] 52) X__XPlus__XX4 :: "Pos => X_Nat => Pos" ("(_/ +'_4/ _)" [54,54] 52) X__XPlus__XX5 :: "Rat => Rat => Rat" ("(_/ +'_5/ _)" [54,54] 52) X__XPlus__XX6 :: "'a => 'a => 'a" ("(_/ +'_6/ _)" [54,54] 52) X__XSlashXEq__X :: "'a => 'a => Bool" ("(_/ '/=/ _)" [54,54] 52) X__XSlashXQuest__XX1 :: "X_Int => X_Int => X_Int partial" ("(_/ '/?''/ _)" [54,54] 52) X__XSlashXQuest__XX2 :: "X_Nat => X_Nat => X_Nat partial" ("(_/ '/?''''/ _)" [54,54] 52) X__XSlash__XX1 :: "X_Int => Pos => Rat" ("(_/ '/''/ _)" [54,54] 52) X__XSlash__XX2 :: "Rat => Rat => Rat partial" ("(_/ '/''''/ _)" [54,54] 52) X__XSlash__XX3 :: "'a => 'a => 'a" ("(_/ '/'_3/ _)" [54,54] 52) X__XVBarXVBar__X :: "Bool => Bool => Bool" ("(_/ ||/ _)" [54,54] 52) X__Xx__XX1 :: "X_Int => X_Int => X_Int" ("(_/ *''/ _)" [54,54] 52) X__Xx__XX2 :: "X_Nat => X_Nat => X_Nat" ("(_/ *''''/ _)" [54,54] 52) X__Xx__XX3 :: "Pos => Pos => Pos" ("(_/ *'_3/ _)" [54,54] 52) X__Xx__XX4 :: "Rat => Rat => Rat" ("(_/ *'_4/ _)" [54,54] 52) X__Xx__XX5 :: "'a => 'a => 'a" ("(_/ *'_5/ _)" [54,54] 52) X__div__XX1 :: "X_Int => X_Int => X_Int partial" ("(_/ div''/ _)" [54,54] 52) X__div__XX2 :: "X_Nat => X_Nat => X_Nat partial" ("(_/ div''''/ _)" [54,54] 52) X__div__XX3 :: "'a => 'a => 'a" ("(_/ div'_3/ _)" [54,54] 52) X__dvd__X :: "X_Nat => X_Nat => bool" ("(_/ dvd''/ _)" [44,44] 42) X__mod__XX1 :: "X_Int => X_Int => X_Nat partial" ("(_/ mod''/ _)" [54,54] 52) X__mod__XX2 :: "X_Nat => X_Nat => X_Nat partial" ("(_/ mod''''/ _)" [54,54] 52) X__mod__XX3 :: "'a => 'a => 'a" ("(_/ mod'_3/ _)" [54,54] 52) X__o__X :: "('b => 'c) * ('a => 'b) => 'a => 'c" X__quot__XX1 :: "X_Int => X_Int => X_Int partial" ("(_/ quot''/ _)" [54,54] 52) X__quot__XX2 :: "'a => 'a => 'a" ("(_/ quot''''/ _)" [54,54] 52) X__rem__XX1 :: "X_Int => X_Int => X_Int partial" ("(_/ rem''/ _)" [54,54] 52) X__rem__XX2 :: "'a => 'a => 'a" ("(_/ rem''''/ _)" [54,54] 52) X_absX1 :: "X_Int => X_Nat" ("abs''/'(_')" [3] 999) X_absX2 :: "Rat => Rat" ("abs''''/'(_')" [3] 999) X_absX3 :: "'a => 'a" ("abs'_3/'(_')" [3] 999) X_all :: "('a => Bool) => 'a List => Bool" X_andL :: "Bool List => Bool" ("andL/'(_')" [3] 999) X_any :: "('a => Bool) => 'a List => Bool" X_concat :: "'a List List => 'a List" ("concat''/'(_')" [3] 999) X_curry :: "('a * 'b => 'c) => 'a => 'b => 'c" X_drop :: "X_Int => 'a List => 'a List" X_dropWhile :: "('a => Bool) => 'a List => 'a List" X_evenX1 :: "X_Int => bool" ("even''/'(_')" [3] 999) X_evenX2 :: "X_Nat => bool" ("even''''/'(_')" [3] 999) X_filter :: "('a => Bool) => 'a List => 'a List" X_flip :: "('a => 'b => 'c) => 'b => 'a => 'c" X_foldl :: "('a => 'b => 'a) => 'a => 'b List => 'a partial" X_foldr :: "('a => 'b => 'b) => 'b => 'a List => 'b partial" X_fromInteger :: "X_Int => 'a" ("fromInteger/'(_')" [3] 999) X_fst :: "'a => 'b => 'a" ("fst''/'(_,/ _')" [3,3] 999) X_gn_inj :: "'a => 'b" ("gn'_inj/'(_')" [3] 999) X_gn_proj :: "'a => 'b partial" ("gn'_proj/'(_')" [3] 999) X_gn_subt :: "'a => 'b => bool" ("gn'_subt/'(_,/ _')" [3,3] 999) X_head :: "'a List => 'a partial" ("head/'(_')" [3] 999) X_id :: "'a => 'a" ("id''/'(_')" [3] 999) X_init :: "'a List => 'a List partial" ("init/'(_')" [3] 999) X_insert :: "'d => 'd List => 'd List" X_last :: "'a List => 'a partial" ("last''/'(_')" [3] 999) X_length :: "'a List => X_Int" ("length''/'(_')" [3] 999) X_map :: "('a => 'b) => 'a List => 'b List" X_maxX1 :: "X_Int => X_Int => X_Int" ("max''/'(_,/ _')" [3,3] 999) X_maxX2 :: "X_Nat => X_Nat => X_Nat" ("max''''/'(_,/ _')" [3,3] 999) X_maxX3 :: "Rat => Rat => Rat" ("max'_3/'(_,/ _')" [3,3] 999) X_maxX4 :: "'a => 'a => 'a" X_maximum :: "'d List => 'd partial" ("maximum/'(_')" [3] 999) X_minX1 :: "X_Int => X_Int => X_Int" ("min''/'(_,/ _')" [3,3] 999) X_minX2 :: "X_Nat => X_Nat => X_Nat" ("min''''/'(_,/ _')" [3,3] 999) X_minX3 :: "Rat => Rat => Rat" ("min'_3/'(_,/ _')" [3,3] 999) X_minX4 :: "'a => 'a => 'a" X_minimum :: "'d List => 'd partial" ("minimum/'(_')" [3] 999) X_negate :: "'a => 'a" ("negate/'(_')" [3] 999) X_null :: "'a List => Bool" ("null''/'(_')" [3] 999) X_oddX1 :: "X_Int => bool" ("odd''/'(_')" [3] 999) X_oddX2 :: "X_Nat => bool" ("odd''''/'(_')" [3] 999) X_orL :: "Bool List => Bool" ("orL/'(_')" [3] 999) X_pre :: "X_Nat => X_Nat partial" ("pre/'(_')" [3] 999) X_product :: "'c List => 'c" ("product/'(_')" [3] 999) X_recip :: "'a => 'a" ("recip/'(_')" [3] 999) X_reverse :: "'a List => 'a List" ("reverse/'(_')" [3] 999) X_sign :: "X_Int => X_Int" ("sign/'(_')" [3] 999) X_signum :: "'a => 'a" ("signum/'(_')" [3] 999) X_snd :: "'a => 'b => 'b" ("snd''/'(_,/ _')" [3,3] 999) X_sum :: "'c List => 'c" ("sum/'(_')" [3] 999) X_tail :: "'a List => 'a List partial" ("tail/'(_')" [3] 999) X_take :: "X_Int => 'a List => 'a List" X_takeWhile :: "('a => Bool) => 'a List => 'a List" X_toInteger :: "'a => X_Int" ("toInteger/'(_')" [3] 999) X_unzip :: "('a * 'b) List => 'a List * 'b List" ("unzip/'(_')" [3] 999) X_zip :: "'a List => 'b List => ('a * 'b) List" break :: "('a => Bool) => 'a List => 'a List * 'a List" compare :: "'a => 'a => Ordering" concatMap :: "('a => 'b List) => 'a List => 'b List" delete :: "'e => 'e List => 'e List" divMod :: "'a => 'a => 'a * 'a" foldl1 :: "('a => 'a => 'a) => 'a List => 'a partial" foldr1 :: "('a => 'a => 'a) => 'a List => 'a partial" notH__X :: "Bool => Bool" ("(notH/ _)" [56] 56) otherwiseH :: "Bool" partition :: "('a => Bool) => 'a List => 'a List * 'a List" product' :: "'c List => 'c => 'c" quotRem :: "'a => 'a => 'a * 'a" scanl :: "('a => 'b => 'a) => 'a => 'b List => 'a List" scanl1 :: "('a => 'a => 'a) => 'a List => 'a List" scanr :: "('a => 'b => 'b) => 'b => 'a List => 'b List" scanr1 :: "('a => 'a => 'a) => 'a List => 'a List" select :: "('a => Bool) => 'a => 'a List * 'a List => 'a List * 'a List" span :: "('a => Bool) => 'a List => 'a List * 'a List" splitAt :: "X_Int => 'a List => 'a List * 'a List" sucX2 :: "X_Nat => Pos" ("suc''''/'(_')" [3] 999) sum' :: "'c List => 'c => 'c" uncurry :: "('a => 'b => 'c) => 'a * 'b => 'c" axioms ga_monotonicity [rule_format] : "(X_gn_inj :: (X_Int => X_Int) => X_Int => Rat) XMinus__XX1 = (X_gn_inj :: (Rat => Rat) => X_Int => Rat) XMinus__XX2" ga_monotonicity_1 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 0' = (X_gn_inj :: X_Nat => X_Int) 0''" ga_monotonicity_2 [rule_format] : "(X_gn_inj :: X_Int => Rat) 0' = (X_gn_inj :: Rat => Rat) 0_3" ga_monotonicity_3 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 0'' = (X_gn_inj :: Rat => Rat) 0_3" ga_monotonicity_4 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 1' = (X_gn_inj :: X_Nat => X_Int) 1''" ga_monotonicity_5 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 1' = (X_gn_inj :: Pos => X_Int) 1_3" ga_monotonicity_6 [rule_format] : "(X_gn_inj :: X_Int => Rat) 1' = (X_gn_inj :: Rat => Rat) 1_4" ga_monotonicity_7 [rule_format] : "(X_gn_inj :: X_Nat => X_Nat) 1'' = (X_gn_inj :: Pos => X_Nat) 1_3" ga_monotonicity_8 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 1'' = (X_gn_inj :: Rat => Rat) 1_4" ga_monotonicity_9 [rule_format] : "(X_gn_inj :: Pos => Rat) 1_3 = (X_gn_inj :: Rat => Rat) 1_4" ga_monotonicity_10 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 2' = (X_gn_inj :: X_Nat => X_Int) 2''" ga_monotonicity_11 [rule_format] : "(X_gn_inj :: X_Int => Rat) 2' = (X_gn_inj :: Rat => Rat) 2_3" ga_monotonicity_12 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 2'' = (X_gn_inj :: Rat => Rat) 2_3" ga_monotonicity_13 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 3' = (X_gn_inj :: X_Nat => X_Int) 3''" ga_monotonicity_14 [rule_format] : "(X_gn_inj :: X_Int => Rat) 3' = (X_gn_inj :: Rat => Rat) 3_3" ga_monotonicity_15 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 3'' = (X_gn_inj :: Rat => Rat) 3_3" ga_monotonicity_16 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 4' = (X_gn_inj :: X_Nat => X_Int) 4''" ga_monotonicity_17 [rule_format] : "(X_gn_inj :: X_Int => Rat) 4' = (X_gn_inj :: Rat => Rat) 4_3" ga_monotonicity_18 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 4'' = (X_gn_inj :: Rat => Rat) 4_3" ga_monotonicity_19 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 5' = (X_gn_inj :: X_Nat => X_Int) 5''" ga_monotonicity_20 [rule_format] : "(X_gn_inj :: X_Int => Rat) 5' = (X_gn_inj :: Rat => Rat) 5_3" ga_monotonicity_21 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 5'' = (X_gn_inj :: Rat => Rat) 5_3" ga_monotonicity_22 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 6' = (X_gn_inj :: X_Nat => X_Int) 6''" ga_monotonicity_23 [rule_format] : "(X_gn_inj :: X_Int => Rat) 6' = (X_gn_inj :: Rat => Rat) 6_3" ga_monotonicity_24 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 6'' = (X_gn_inj :: Rat => Rat) 6_3" ga_monotonicity_25 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 7' = (X_gn_inj :: X_Nat => X_Int) 7''" ga_monotonicity_26 [rule_format] : "(X_gn_inj :: X_Int => Rat) 7' = (X_gn_inj :: Rat => Rat) 7_3" ga_monotonicity_27 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 7'' = (X_gn_inj :: Rat => Rat) 7_3" ga_monotonicity_28 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 8' = (X_gn_inj :: X_Nat => X_Int) 8''" ga_monotonicity_29 [rule_format] : "(X_gn_inj :: X_Int => Rat) 8' = (X_gn_inj :: Rat => Rat) 8_3" ga_monotonicity_30 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 8'' = (X_gn_inj :: Rat => Rat) 8_3" ga_monotonicity_31 [rule_format] : "(X_gn_inj :: X_Int => X_Int) 9' = (X_gn_inj :: X_Nat => X_Int) 9''" ga_monotonicity_32 [rule_format] : "(X_gn_inj :: X_Int => Rat) 9' = (X_gn_inj :: Rat => Rat) 9_3" ga_monotonicity_33 [rule_format] : "(X_gn_inj :: X_Nat => Rat) 9'' = (X_gn_inj :: Rat => Rat) 9_3" ga_monotonicity_34 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X__Xx__XX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Int) (uncurryOp X__Xx__XX2)" ga_monotonicity_35 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => Pos * Pos => X_Int) (uncurryOp X__Xx__XX1) = (X_gn_inj :: (Pos * Pos => Pos) => Pos * Pos => X_Int) (uncurryOp X__Xx__XX3)" ga_monotonicity_36 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => Rat) (uncurryOp X__Xx__XX1) = (X_gn_inj :: (Rat * Rat => Rat) => X_Int * X_Int => Rat) (uncurryOp X__Xx__XX4)" ga_monotonicity_37 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => X_Int) (uncurryOp X__Xx__XX1) = (X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => X_Int) (uncurryOp X__Xx__XX5)" ga_monotonicity_38 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => Pos * Pos => X_Nat) (uncurryOp X__Xx__XX2) = (X_gn_inj :: (Pos * Pos => Pos) => Pos * Pos => X_Nat) (uncurryOp X__Xx__XX3)" ga_monotonicity_39 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => Rat) (uncurryOp X__Xx__XX2) = (X_gn_inj :: (Rat * Rat => Rat) => X_Nat * X_Nat => Rat) (uncurryOp X__Xx__XX4)" ga_monotonicity_40 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Nat) (uncurryOp X__Xx__XX2) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Nat) (uncurryOp X__Xx__XX5)" ga_monotonicity_41 [rule_format] : "(X_gn_inj :: (Pos * Pos => Pos) => Pos * Pos => Rat) (uncurryOp X__Xx__XX3) = (X_gn_inj :: (Rat * Rat => Rat) => Pos * Pos => Rat) (uncurryOp X__Xx__XX4)" ga_monotonicity_42 [rule_format] : "(X_gn_inj :: (Pos * Pos => Pos) => Pos * Pos => Pos) (uncurryOp X__Xx__XX3) = (X_gn_inj :: (Pos * Pos => Pos) => Pos * Pos => Pos) (uncurryOp X__Xx__XX5)" ga_monotonicity_43 [rule_format] : "(X_gn_inj :: (Rat * Rat => Rat) => Rat * Rat => Rat) (uncurryOp X__Xx__XX4) = (X_gn_inj :: (Rat * Rat => Rat) => Rat * Rat => Rat) (uncurryOp X__Xx__XX5)" ga_monotonicity_44 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X__XPlus__XX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Int) (uncurryOp X__XPlus__XX2)" ga_monotonicity_45 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Nat * Pos => X_Int) (uncurryOp X__XPlus__XX1) = (X_gn_inj :: (X_Nat * Pos => Pos) => X_Nat * Pos => X_Int) (uncurryOp X__XPlus__XX3)" ga_monotonicity_46 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => Pos * X_Nat => X_Int) (uncurryOp X__XPlus__XX1) = (X_gn_inj :: (Pos * X_Nat => Pos) => Pos * X_Nat => X_Int) (uncurryOp X__XPlus__XX4)" ga_monotonicity_47 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => Rat) (uncurryOp X__XPlus__XX1) = (X_gn_inj :: (Rat * Rat => Rat) => X_Int * X_Int => Rat) (uncurryOp X__XPlus__XX5)" ga_monotonicity_48 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => X_Int) (uncurryOp X__XPlus__XX1) = (X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => X_Int) (uncurryOp X__XPlus__XX6)" ga_monotonicity_49 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * Pos => X_Nat) (uncurryOp X__XPlus__XX2) = (X_gn_inj :: (X_Nat * Pos => Pos) => X_Nat * Pos => X_Nat) (uncurryOp X__XPlus__XX3)" ga_monotonicity_50 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => Pos * X_Nat => X_Nat) (uncurryOp X__XPlus__XX2) = (X_gn_inj :: (Pos * X_Nat => Pos) => Pos * X_Nat => X_Nat) (uncurryOp X__XPlus__XX4)" ga_monotonicity_51 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => Rat) (uncurryOp X__XPlus__XX2) = (X_gn_inj :: (Rat * Rat => Rat) => X_Nat * X_Nat => Rat) (uncurryOp X__XPlus__XX5)" ga_monotonicity_52 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Nat) (uncurryOp X__XPlus__XX2) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Nat) (uncurryOp X__XPlus__XX6)" ga_monotonicity_53 [rule_format] : "(X_gn_inj :: (X_Nat * Pos => Pos) => Pos * Pos => Pos) (uncurryOp X__XPlus__XX3) = (X_gn_inj :: (Pos * X_Nat => Pos) => Pos * Pos => Pos) (uncurryOp X__XPlus__XX4)" ga_monotonicity_54 [rule_format] : "(X_gn_inj :: (X_Nat * Pos => Pos) => X_Nat * Pos => Rat) (uncurryOp X__XPlus__XX3) = (X_gn_inj :: (Rat * Rat => Rat) => X_Nat * Pos => Rat) (uncurryOp X__XPlus__XX5)" ga_monotonicity_55 [rule_format] : "(X_gn_inj :: (Pos * X_Nat => Pos) => Pos * X_Nat => Rat) (uncurryOp X__XPlus__XX4) = (X_gn_inj :: (Rat * Rat => Rat) => Pos * X_Nat => Rat) (uncurryOp X__XPlus__XX5)" ga_monotonicity_56 [rule_format] : "(X_gn_inj :: (Rat * Rat => Rat) => Rat * Rat => Rat) (uncurryOp X__XPlus__XX5) = (X_gn_inj :: (Rat * Rat => Rat) => Rat * Rat => Rat) (uncurryOp X__XPlus__XX6)" ga_monotonicity_57 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X__XMinus__XX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X__XMinus__XX2)" ga_monotonicity_58 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => Rat) (uncurryOp X__XMinus__XX1) = (X_gn_inj :: (Rat * Rat => Rat) => X_Int * X_Int => Rat) (uncurryOp X__XMinus__XX3)" ga_monotonicity_59 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => X_Int) (uncurryOp X__XMinus__XX1) = (X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => X_Int) (uncurryOp X__XMinus__XX4)" ga_monotonicity_60 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Int) => X_Nat * X_Nat => Rat) (uncurryOp X__XMinus__XX2) = (X_gn_inj :: (Rat * Rat => Rat) => X_Nat * X_Nat => Rat) (uncurryOp X__XMinus__XX3)" ga_monotonicity_61 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X__XMinus__XX2) = (X_gn_inj :: (X_Int * X_Int => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X__XMinus__XX4)" ga_monotonicity_62 [rule_format] : "(X_gn_inj :: (Rat * Rat => Rat) => Rat * Rat => Rat) (uncurryOp X__XMinus__XX3) = (X_gn_inj :: (Rat * Rat => Rat) => Rat * Rat => Rat) (uncurryOp X__XMinus__XX4)" ga_monotonicity_63 [rule_format] : "(X_gn_inj :: (X_Int * Pos => Rat) => X_Int * Pos => Rat) (uncurryOp X__XSlash__XX1) = (X_gn_inj :: (Rat * Rat => Rat) => X_Int * Pos => Rat) (uncurryOp X__XSlash__XX3)" ga_monotonicity_64 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int partial) => X_Nat * X_Nat => X_Int partial) (uncurryOp X__XSlashXQuest__XX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat partial) => X_Nat * X_Nat => X_Int partial) (uncurryOp X__XSlashXQuest__XX2)" ga_monotonicity_65 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XLt__XX1) = (X_gn_inj :: (X_Nat * X_Nat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XLt__XX2)" ga_monotonicity_66 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => bool) => X_Int * X_Int => bool) (uncurryOp X__XLt__XX1) = (X_gn_inj :: (Rat * Rat => bool) => X_Int * X_Int => bool) (uncurryOp X__XLt__XX3)" ga_monotonicity_67 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XLt__XX2) = (X_gn_inj :: (Rat * Rat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XLt__XX3)" ga_monotonicity_68 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XLtXEq__XX1) = (X_gn_inj :: (X_Nat * X_Nat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XLtXEq__XX2)" ga_monotonicity_69 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => bool) => X_Int * X_Int => bool) (uncurryOp X__XLtXEq__XX1) = (X_gn_inj :: (Rat * Rat => bool) => X_Int * X_Int => bool) (uncurryOp X__XLtXEq__XX3)" ga_monotonicity_70 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XLtXEq__XX2) = (X_gn_inj :: (Rat * Rat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XLtXEq__XX3)" ga_monotonicity_71 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XGt__XX1) = (X_gn_inj :: (X_Nat * X_Nat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XGt__XX2)" ga_monotonicity_72 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => bool) => X_Int * X_Int => bool) (uncurryOp X__XGt__XX1) = (X_gn_inj :: (Rat * Rat => bool) => X_Int * X_Int => bool) (uncurryOp X__XGt__XX3)" ga_monotonicity_73 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XGt__XX2) = (X_gn_inj :: (Rat * Rat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XGt__XX3)" ga_monotonicity_74 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XGtXEq__XX1) = (X_gn_inj :: (X_Nat * X_Nat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XGtXEq__XX2)" ga_monotonicity_75 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => bool) => X_Int * X_Int => bool) (uncurryOp X__XGtXEq__XX1) = (X_gn_inj :: (Rat * Rat => bool) => X_Int * X_Int => bool) (uncurryOp X__XGtXEq__XX3)" ga_monotonicity_76 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XGtXEq__XX2) = (X_gn_inj :: (Rat * Rat => bool) => X_Nat * X_Nat => bool) (uncurryOp X__XGtXEq__XX3)" ga_monotonicity_77 [rule_format] : "(X_gn_inj :: (X_Int * X_Nat => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X__XCaret__XX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Int) (uncurryOp X__XCaret__XX2)" ga_monotonicity_78 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int partial) => X_Nat * X_Nat => X_Int partial) (uncurryOp X__div__XX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat partial) => X_Nat * X_Nat => X_Int partial) (uncurryOp X__div__XX2)" ga_monotonicity_79 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Nat partial) => X_Nat * X_Nat => X_Nat partial) (uncurryOp X__mod__XX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat partial) => X_Nat * X_Nat => X_Nat partial) (uncurryOp X__mod__XX2)" ga_monotonicity_80 [rule_format] : "(X_gn_inj :: (X_Int => X_Nat) => X_Int => Rat) X_absX1 = (X_gn_inj :: (Rat => Rat) => X_Int => Rat) X_absX2" ga_monotonicity_81 [rule_format] : "(X_gn_inj :: (Rat => Rat) => Rat => Rat) X_absX2 = (X_gn_inj :: (Rat => Rat) => Rat => Rat) X_absX3" ga_monotonicity_82 [rule_format] : "(X_gn_inj :: (X_Int => bool) => X_Nat => bool) X_evenX1 = (X_gn_inj :: (X_Nat => bool) => X_Nat => bool) X_evenX2" ga_monotonicity_83 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X_maxX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Int) (uncurryOp X_maxX2)" ga_monotonicity_84 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => Rat) (uncurryOp X_maxX1) = (X_gn_inj :: (Rat * Rat => Rat) => X_Int * X_Int => Rat) (uncurryOp X_maxX3)" ga_monotonicity_85 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => Rat) (uncurryOp X_maxX2) = (X_gn_inj :: (Rat * Rat => Rat) => X_Nat * X_Nat => Rat) (uncurryOp X_maxX3)" ga_monotonicity_86 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Nat * X_Nat => X_Int) (uncurryOp X_minX1) = (X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => X_Int) (uncurryOp X_minX2)" ga_monotonicity_87 [rule_format] : "(X_gn_inj :: (X_Int * X_Int => X_Int) => X_Int * X_Int => Rat) (uncurryOp X_minX1) = (X_gn_inj :: (Rat * Rat => Rat) => X_Int * X_Int => Rat) (uncurryOp X_minX3)" ga_monotonicity_88 [rule_format] : "(X_gn_inj :: (X_Nat * X_Nat => X_Nat) => X_Nat * X_Nat => Rat) (uncurryOp X_minX2) = (X_gn_inj :: (Rat * Rat => Rat) => X_Nat * X_Nat => Rat) (uncurryOp X_minX3)" ga_monotonicity_89 [rule_format] : "(X_gn_inj :: (X_Int => bool) => X_Nat => bool) X_oddX1 = (X_gn_inj :: (X_Nat => bool) => X_Nat => bool) X_oddX2" ga_monotonicity_90 [rule_format] : "(X_gn_inj :: (X_Nat => X_Nat) => X_Nat => X_Nat) sucX1 = (X_gn_inj :: (X_Nat => Pos) => X_Nat => X_Nat) sucX2" ga_subt_reflexive [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). gn_subt(x, y)" ga_subt_transitive [rule_format] : "ALL (x :: 'a). ALL (y :: 'b). ALL (z :: 'c). gn_subt(x, y) & gn_subt(y, z) --> gn_subt(x, z)" ga_subt_inj_proj [rule_format] : "ALL (x :: 'a). ALL (y :: 'b). gn_subt(x, y) --> y = (X_gn_inj :: 'a => 'b) x = (makePartial x = (X_gn_proj :: 'b => 'a partial) y)" ga_inj_transitive [rule_format] : "ALL (x :: 'a). ALL (y :: 'b). ALL (z :: 'c). gn_subt(x, y) & gn_subt(y, z) & y = (X_gn_inj :: 'a => 'b) x --> z = (X_gn_inj :: 'a => 'c) x = (z = (X_gn_inj :: 'b => 'c) y)" ga_subt_Int_XLt_Rat [rule_format] : "ALL (x :: X_Int). ALL (y :: Rat). gn_subt(x, y)" ga_subt_Nat_XLt_Int [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Int). gn_subt(x, y)" ga_subt_Pos_XLt_Nat [rule_format] : "ALL (x :: Pos). ALL (y :: X_Nat). gn_subt(x, y)" Comp1 [rule_format] : "ALL (f :: 'b => 'c). ALL (g :: 'a => 'b). ALL (y :: 'a). X__o__X (f, g) y = f (g y)" IdDef [rule_format] : "ALL (x :: 'a). id'(x) = x" FlipDef [rule_format] : "ALL (f :: 'a => 'b => 'c). ALL (x :: 'a). ALL (y :: 'b). X_flip f y x = f x y" FstDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'b). fst'(x, y) = x" SndDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'b). snd'(x, y) = y" CurryDef [rule_format] : "ALL (g :: 'a * 'b => 'c). ALL (x :: 'a). ALL (y :: 'b). X_curry g x y = g (x, y)" UncurryDef [rule_format] : "ALL (f :: 'a => 'b => 'c). ALL (x :: 'a). ALL (y :: 'b). uncurry f (x, y) = f x y" NotFalse [rule_format] : "notH False' = True'" NotTrue [rule_format] : "notH True' = False'" AndFalse [rule_format] : "ALL (x :: Bool). False' && x = False'" AndTrue [rule_format] : "ALL (x :: Bool). True' && x = x" AndSym [rule_format] : "ALL (x :: Bool). ALL (y :: Bool). x && y = y && x" OrDef [rule_format] : "ALL (x :: Bool). ALL (y :: Bool). x || y = notH (notH x && notH y)" OtherwiseDef [rule_format] : "otherwiseH = True'" NotFalse1 [rule_format] : "ALL (x :: Bool). notH x = True' = (x = False')" NotTrue1 [rule_format] : "ALL (x :: Bool). notH x = False' = (x = True')" notNot1 [rule_format] : "ALL (x :: Bool). (~ x = True') = (notH x = True')" notNot2 [rule_format] : "ALL (x :: Bool). (~ x = False') = (notH x = False')" EqualTDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x = y --> x ==' y = True'" EqualSymDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x ==' y = y ==' x" EqualReflex [rule_format] : "ALL (x :: 'a). x ==' x = True'" EqualTransT [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). x ==' y = True' & y ==' z = True' --> x ==' z = True'" DiffDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x /= y = notH (x ==' y)" DiffSymDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x /= y = y /= x" DiffTDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x /= y = True' = (notH (x ==' y) = True')" DiffFDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x /= y = False' = (x ==' y = True')" TE1 [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x ==' y = False' --> ~ x = y" TE2 [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). notH (x ==' y) = True' = (x ==' y = False')" TE3 [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). notH (x ==' y) = False' = (x ==' y = True')" TE4 [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). (~ x ==' y = True') = (x ==' y = False')" IBE1 [rule_format] : "True' ==' True' = True'" IBE2 [rule_format] : "False' ==' False' = True'" IBE3 [rule_format] : "False' ==' True' = False'" IBE4 [rule_format] : "True' ==' False' = False'" IBE5 [rule_format] : "True' /= False' = True'" IBE6 [rule_format] : "False' /= True' = True'" IBE7 [rule_format] : "notH (True' ==' False') = True'" IBE8 [rule_format] : "notH notH (True' ==' False') = False'" IUE1 [rule_format] : "() ==' () = True'" IUE2 [rule_format] : "() /= () = False'" IOE01 [rule_format] : "LT ==' LT = True'" IOE02 [rule_format] : "EQ ==' EQ = True'" IOE03 [rule_format] : "GT ==' GT = True'" IOE04 [rule_format] : "LT ==' EQ = False'" IOE05 [rule_format] : "LT ==' GT = False'" IOE06 [rule_format] : "EQ ==' GT = False'" IOE07 [rule_format] : "LT /= EQ = True'" IOE08 [rule_format] : "LT /= GT = True'" IOE09 [rule_format] : "EQ /= GT = True'" LeIrreflexivity [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x ==' y = True' --> x <_4 y = False'" LeTAsymmetry [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <_4 y = True' --> y <_4 x = False'" LeTTransitive [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). x <_4 y = True' & y <_4 z = True' --> x <_4 z = True'" LeTTotal [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). (x <_4 y = True' | y <_4 x = True') | x ==' y = True'" GeDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >_4 y = y <_4 x" GeIrreflexivity [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x ==' y = True' --> x >_4 y = False'" GeTAsymmetry [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >_4 y = True' --> y >_4 x = False'" GeTTransitive [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). (x >_4 y) && (y >_4 z) = True' --> x >_4 z = True'" GeTTotal [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ((x >_4 y) || (y >_4 x)) || (x ==' y) = True'" LeqDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <=_4 y = (x <_4 y) || (x ==' y)" LeqReflexivity [rule_format] : "ALL (x :: 'a). x <=_4 x = True'" LeqTTransitive [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). (x <=_4 y) && (y <=_4 z) = True' --> x <=_4 z = True'" LeqTTotal [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). (x <=_4 y) && (y <=_4 x) = x ==' y" GeqDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >=_4 y = (x >_4 y) || (x ==' y)" GeqReflexivity [rule_format] : "ALL (x :: 'a). x >=_4 x = True'" GeqTTransitive [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). (x >=_4 y) && (y >=_4 z) = True' --> x >=_4 z = True'" GeqTTotal [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). (x >=_4 y) && (y >=_4 x) = x ==' y" EqTSOrdRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x ==' y = True' = (x <_4 y = False' & x >_4 y = False')" EqFSOrdRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x ==' y = False' = (x <_4 y = True' | x >_4 y = True')" EqTOrdRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x ==' y = True' = (x <=_4 y = True' & x >=_4 y = True')" EqFOrdRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x ==' y = False' = (x <=_4 y = True' | x >=_4 y = True')" EqTOrdTSubstE [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). x ==' y = True' & y <_4 z = True' --> x <_4 z = True'" EqTOrdFSubstE [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). x ==' y = True' & y <_4 z = False' --> x <_4 z = False'" EqTOrdTSubstD [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). x ==' y = True' & z <_4 y = True' --> z <_4 x = True'" EqTOrdFSubstD [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). x ==' y = True' & z <_4 y = False' --> z <_4 x = False'" LeTGeFEqFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <_4 y = True' = (x >_4 y = False' & x ==' y = False')" LeFGeTEqTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <_4 y = False' = (x >_4 y = True' | x ==' y = True')" LeTGeTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <_4 y = True' = (y >_4 x = True')" LeFGeFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <_4 y = False' = (y >_4 x = False')" LeqTGetTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <=_4 y = True' = (y >=_4 x = True')" LeqFGetFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <=_4 y = False' = (y >=_4 x = False')" GeTLeTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >_4 y = True' = (y <_4 x = True')" GeFLeFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >_4 y = False' = (y <_4 x = False')" GeqTLeqTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >=_4 y = True' = (y <=_4 x = True')" GeqFLeqFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >=_4 y = False' = (y <=_4 x = False')" LeqTGeFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <=_4 y = True' = (x >_4 y = False')" LeqFGeTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <=_4 y = False' = (x >_4 y = True')" GeTLeFEqFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >_4 y = True' = (x <_4 y = False' & x ==' y = False')" GeFLeTEqTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >_4 y = False' = (x <_4 y = True' | x ==' y = True')" GeqTLeFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >=_4 y = True' = (x <_4 y = False')" GeqFLeTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >=_4 y = False' = (x <_4 y = True')" LeqTLeTEqTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <=_4 y = True' = (x <_4 y = True' | x ==' y = True')" LeqFLeFEqFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <=_4 y = False' = (x <_4 y = False' & x ==' y = False')" GeqTGeTEqTRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >=_4 y = True' = (x >_4 y = True' | x ==' y = True')" GeqFGeFEqFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >=_4 y = False' = (x >_4 y = False' & x ==' y = False')" LeTGeqFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <_4 y = True' = (x >=_4 y = False')" GeTLeqFRel [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x >_4 y = True' = (x <=_4 y = False')" LeLeqDiff [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <_4 y = (x <=_4 y) && (x /= y)" CmpLTDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). compare x y ==' LT = x <_4 y" CmpEQDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). compare x y ==' EQ = x ==' y" CmpGTDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). compare x y ==' GT = x >_4 y" MaxYDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). X_maxX4 x y ==' y = x <=_4 y" MaxXDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). X_maxX4 x y ==' x = y <=_4 x" MinXDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). X_minX4 x y ==' x = x <=_4 y" MinYDef [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). X_minX4 x y ==' y = y <=_4 x" MaxSym [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). X_maxX4 x y ==' y = X_maxX4 y x ==' y" MinSym [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). X_minX4 x y ==' y = X_minX4 y x ==' y" TO1 [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). (x ==' y = True' | x <_4 y = True') = (x <=_4 y = True')" TO3 [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). notH notH (x <_4 y) = True' | notH (x <_4 y) = True'" TO4 [rule_format] : "ALL (x :: 'a). ALL (y :: 'a). x <_4 y = True' --> notH (x ==' y) = True'" TO5 [rule_format] : "ALL (w :: 'a). ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). (x <_4 y = True' & y <_4 z = True') & z <_4 w = True' --> x <_4 w = True'" IOO13 [rule_format] : "LT <_4 EQ = True'" IOO14 [rule_format] : "EQ <_4 GT = True'" IOO15 [rule_format] : "LT <_4 GT = True'" IOO16 [rule_format] : "LT <=_4 EQ = True'" IOO17 [rule_format] : "EQ <=_4 GT = True'" IOO18 [rule_format] : "LT <=_4 GT = True'" IOO19 [rule_format] : "EQ >=_4 LT = True'" IOO20 [rule_format] : "GT >=_4 EQ = True'" IOO21 [rule_format] : "GT >=_4 LT = True'" IOO22 [rule_format] : "EQ >_4 LT = True'" IOO23 [rule_format] : "GT >_4 EQ = True'" IOO24 [rule_format] : "GT >_4 LT = True'" IOO25 [rule_format] : "X_maxX4 LT EQ ==' EQ = True'" IOO26 [rule_format] : "X_maxX4 EQ GT ==' GT = True'" IOO27 [rule_format] : "X_maxX4 LT GT ==' GT = True'" IOO28 [rule_format] : "X_minX4 LT EQ ==' LT = True'" IOO29 [rule_format] : "X_minX4 EQ GT ==' EQ = True'" IOO30 [rule_format] : "X_minX4 LT GT ==' LT = True'" IOO31 [rule_format] : "compare LT LT ==' EQ = True'" IOO32 [rule_format] : "compare EQ EQ ==' EQ = True'" IOO33 [rule_format] : "compare GT GT ==' EQ = True'" IBO5 [rule_format] : "False' <_4 True' = True'" IBO6 [rule_format] : "False' >=_4 True' = False'" IBO7 [rule_format] : "True' >=_4 False' = True'" IBO8 [rule_format] : "True' <_4 False' = False'" IBO9 [rule_format] : "X_maxX4 False' True' ==' True' = True'" IBO10 [rule_format] : "X_minX4 False' True' ==' False' = True'" IBO11 [rule_format] : "compare True' True' ==' EQ = True'" IBO12 [rule_format] : "compare False' False' ==' EQ = True'" IUO01 [rule_format] : "() <=_4 () = True'" IUO02 [rule_format] : "() <_4 () = False'" IUO03 [rule_format] : "() >=_4 () = True'" IUO04 [rule_format] : "() >_4 () = False'" IUO05 [rule_format] : "X_maxX4 () () ==' () = True'" IUO06 [rule_format] : "X_minX4 () () ==' () = True'" IUO07 [rule_format] : "compare () () ==' EQ = True'" NotDefHead [rule_format] : "~ defOp (head(Nil'))" HeadDef [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). head(X_Cons x xs) = makePartial x" NotDefTail [rule_format] : "~ defOp (tail(Nil'))" TailDef [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). tail(X_Cons x xs) = makePartial xs" FoldrNil [rule_format] : "ALL (f :: 'a => 'b => 'b). ALL (s :: 'b). X_foldr f s Nil' = makePartial s" FoldrCons [rule_format] : "ALL (f :: 'a => 'b => 'b). ALL (s :: 'b). ALL (x :: 'a). ALL (xs :: 'a List). X_foldr f s (X_Cons x xs) = restrictOp (makePartial (f x (makeTotal (X_foldr f s xs)))) (defOp (X_foldr f s xs))" FoldlNil [rule_format] : "ALL (g :: 'a => 'b => 'a). ALL (t :: 'a). X_foldl g t Nil' = makePartial t" FoldlCons [rule_format] : "ALL (g :: 'a => 'b => 'a). ALL (t :: 'a). ALL (z :: 'b). ALL (zs :: 'b List). X_foldl g t (X_Cons z zs) = X_foldl g (g t z) zs" MapNil [rule_format] : "ALL (h :: 'a => 'b). X_map h Nil' = Nil'" MapCons [rule_format] : "ALL (h :: 'a => 'b). ALL (x :: 'a). ALL (xs :: 'a List). X_map h (X_Cons x xs) = X_Cons (h x) (X_map h xs)" XPlusXPlusNil [rule_format] : "ALL (l :: 'a List). Nil' ++' l = l" XPlusXPlusCons [rule_format] : "ALL (l :: 'a List). ALL (x :: 'a). ALL (xs :: 'a List). X_Cons x xs ++' l = X_Cons x (xs ++' l)" FilterNil [rule_format] : "ALL (p :: 'a => Bool). X_filter p Nil' = Nil'" FilterConsT [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). p x = True' --> X_filter p (X_Cons x xs) = X_Cons x (X_filter p xs)" FilterConsF [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). p x = False' --> X_filter p (X_Cons x xs) = X_filter p xs" ZipNil [rule_format] : "ALL (l :: 'a List). X_zip Nil' l = Nil'" ZipConsNil [rule_format] : "ALL (l :: 'a List). ALL (x :: 'a). ALL (xs :: 'a List). l = Nil' --> X_zip (X_Cons x xs) l = Nil'" ZipConsCons [rule_format] : "ALL (l :: 'a List). ALL (x :: 'a). ALL (xs :: 'a List). ALL (y :: 'a). ALL (ys :: 'a List). l = X_Cons y ys --> X_zip (X_Cons x xs) l = X_Cons (x, y) (X_zip xs ys)" UnzipNil [rule_format] : "unzip(Nil') = (Nil', Nil')" UnzipCons [rule_format] : "ALL (ps :: ('a * 'b) List). ALL (x :: 'a). ALL (z :: 'b). unzip(X_Cons (x, z) ps) = (let (ys, zs) = unzip(ps) in (X_Cons x ys, X_Cons z zs))" ILE01 [rule_format] : "Nil' ==' Nil' = True'" ILE02 [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). ALL (y :: 'a). ALL (ys :: 'a List). X_Cons x xs ==' X_Cons y ys = (x ==' y) && (xs ==' ys)" ILO01 [rule_format] : "Nil' <_4 Nil' = False'" ILO02 [rule_format] : "Nil' <=_4 Nil' = True'" ILO03 [rule_format] : "Nil' >_4 Nil' = False'" ILO04 [rule_format] : "Nil' >=_4 Nil' = True'" ILO05 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). z <_4 w = True' --> X_Cons z zs <_4 X_Cons w ws = True'" ILO06 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). z ==' w = True' --> X_Cons z zs <_4 X_Cons w ws = zs <_4 ws" ILO07 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). z <_4 w = False' & z ==' w = False' --> X_Cons z zs <_4 X_Cons w ws = False'" ILO08 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). X_Cons z zs <=_4 X_Cons w ws = (X_Cons z zs <_4 X_Cons w ws) || (X_Cons z zs ==' X_Cons w ws)" ILO09 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). X_Cons z zs >_4 X_Cons w ws = X_Cons w ws <_4 X_Cons z zs" ILO10 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). X_Cons z zs >=_4 X_Cons w ws = (X_Cons z zs >_4 X_Cons w ws) || (X_Cons z zs ==' X_Cons w ws)" ILO11 [rule_format] : "compare Nil' Nil' ==' EQ = Nil' ==' Nil'" ILO12 [rule_format] : "compare Nil' Nil' ==' LT = Nil' <_4 Nil'" ILO13 [rule_format] : "compare Nil' Nil' ==' GT = Nil' >_4 Nil'" ILO14 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). compare (X_Cons z zs) (X_Cons w ws) ==' EQ = X_Cons z zs ==' X_Cons w ws" ILO15 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). compare (X_Cons z zs) (X_Cons w ws) ==' LT = X_Cons z zs <_4 X_Cons w ws" ILO16 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). compare (X_Cons z zs) (X_Cons w ws) ==' GT = X_Cons z zs >_4 X_Cons w ws" ILO17 [rule_format] : "X_maxX4 Nil' Nil' ==' Nil' = Nil' <=_4 Nil'" ILO18 [rule_format] : "X_minX4 Nil' Nil' ==' Nil' = Nil' <=_4 Nil'" ILO19 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). X_Cons z zs <=_4 X_Cons w ws = X_maxX4 (X_Cons z zs) (X_Cons w ws) ==' X_Cons w ws" ILO20 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). X_Cons w ws <=_4 X_Cons z zs = X_maxX4 (X_Cons z zs) (X_Cons w ws) ==' X_Cons z zs" ILO21 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). X_Cons z zs <=_4 X_Cons w ws = X_minX4 (X_Cons z zs) (X_Cons w ws) ==' X_Cons z zs" ILO22 [rule_format] : "ALL (w :: 'b). ALL (ws :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). X_Cons w ws <=_4 X_Cons z zs = X_minX4 (X_Cons z zs) (X_Cons w ws) ==' X_Cons w ws" FoldlDecomp [rule_format] : "ALL (e :: 'a). ALL (i :: 'a => 'b => 'a). ALL (ts :: 'b List). ALL (ys :: 'b List). X_foldl i e (ys ++' ts) = restrictOp (X_foldl i (makeTotal (X_foldl i e ys)) ts) (defOp (X_foldl i e ys))" MapDecomp [rule_format] : "ALL (f :: 'a => 'b). ALL (xs :: 'a List). ALL (zs :: 'a List). X_map f (xs ++' zs) = X_map f xs ++' X_map f zs" MapFunctor [rule_format] : "ALL (f :: 'a => 'b). ALL (g :: 'b => 'c). ALL (xs :: 'a List). X_map (X__o__X (g, f)) xs = X_map g (X_map f xs)" FilterProm [rule_format] : "ALL (f :: 'a => 'b). ALL (p :: 'b => Bool). ALL (xs :: 'a List). X_filter p (X_map f xs) = X_map f (X_filter (X__o__X (p, f)) xs)" InitNil [rule_format] : "~ defOp (init(Nil'))" InitConsNil [rule_format] : "ALL (x :: 'a). init(X_Cons x Nil') = makePartial Nil'" InitConsCons [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). init(X_Cons x xs) = restrictOp (makePartial (X_Cons x (makeTotal (init(xs))))) (defOp (init(xs)))" LastNil [rule_format] : "~ defOp (last'(Nil'))" LastConsNil [rule_format] : "ALL (x :: 'a). last'(X_Cons x Nil') = makePartial x" LastConsCons [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). last'(X_Cons x xs) = last'(xs)" NullNil [rule_format] : "null'(Nil') = True'" NullCons [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). null'(X_Cons x xs) = False'" ReverseNil [rule_format] : "reverse(Nil') = Nil'" ReverseCons [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). reverse(X_Cons x xs) = reverse(xs) ++' X_Cons x Nil'" Foldr1Nil [rule_format] : "ALL (f :: 'a => 'a => 'a). ~ defOp (foldr1 f Nil')" Foldr1ConsNil [rule_format] : "ALL (f :: 'a => 'a => 'a). ALL (x :: 'a). foldr1 f (X_Cons x Nil') = makePartial x" Foldr1ConsCons [rule_format] : "ALL (f :: 'a => 'a => 'a). ALL (x :: 'a). ALL (xs :: 'a List). foldr1 f (X_Cons x xs) = restrictOp (makePartial (f x (makeTotal (foldr1 f xs)))) (defOp (foldr1 f xs))" Foldl1Nil [rule_format] : "ALL (f :: 'a => 'a => 'a). ~ defOp (foldl1 f Nil')" Foldl1ConsNil [rule_format] : "ALL (f :: 'a => 'a => 'a). ALL (x :: 'a). foldl1 f (X_Cons x Nil') = makePartial x" Foldl1ConsCons [rule_format] : "ALL (f :: 'a => 'a => 'a). ALL (x :: 'a). ALL (xs :: 'a List). foldl1 f (X_Cons x xs) = restrictOp (makePartial (f x (makeTotal (foldr1 f xs)))) (defOp (foldr1 f xs))" ScanlNil [rule_format] : "ALL (g :: 'a => 'b => 'a). ALL (q :: 'a). ALL (ys :: 'b List). ys = Nil' --> scanl g q ys = X_Cons q Nil'" ScanlCons [rule_format] : "ALL (g :: 'a => 'b => 'a). ALL (q :: 'a). ALL (ys :: 'b List). ALL (z :: 'b). ALL (zs :: 'b List). ys = X_Cons z zs --> scanl g q ys = X_Cons q (scanl g (g q z) zs)" Scanl1Nil [rule_format] : "ALL (f :: 'a => 'a => 'a). scanl1 f Nil' = Nil'" Scanl1Cons [rule_format] : "ALL (f :: 'a => 'a => 'a). ALL (x :: 'a). ALL (xs :: 'a List). scanl1 f (X_Cons x xs) = scanl f x xs" ScanrNil [rule_format] : "ALL (h :: 'a => 'b => 'b). ALL (z :: 'b). scanr h z Nil' = X_Cons z Nil'" ScanrCons [rule_format] : "ALL (h :: 'a => 'b => 'b). ALL (x :: 'a). ALL (xs :: 'a List). ALL (y :: 'b). ALL (ys :: 'b List). ALL (z :: 'b). X_Cons y ys = scanr h z xs --> scanr h z (X_Cons x xs) = X_Cons (h x y) (X_Cons y ys)" Scanr1Nil [rule_format] : "ALL (f :: 'a => 'a => 'a). scanr1 f Nil' = Nil'" Scanr1ConsNil [rule_format] : "ALL (f :: 'a => 'a => 'a). ALL (x :: 'a). scanr1 f (X_Cons x Nil') = X_Cons x Nil'" Scanr1ConsCons [rule_format] : "ALL (f :: 'a => 'a => 'a). ALL (q :: 'a). ALL (qs :: 'a List). ALL (x :: 'a). ALL (xs :: 'a List). X_Cons q qs = scanr1 f xs --> scanr1 f (X_Cons x xs) = X_Cons (f x q) (X_Cons q qs)" ScanlProperty [rule_format] : "ALL (g :: 'a => 'b => 'a). ALL (x :: 'a). ALL (ys :: 'b List). last'(scanl g x ys) = X_foldl g x ys" ScanrProperty [rule_format] : "ALL (h :: 'a => 'b => 'b). ALL (xs :: 'a List). ALL (y :: 'b). head(scanr h y xs) = X_foldr h y xs" AndLNil [rule_format] : "andL(Nil') = True'" AndLCons [rule_format] : "ALL (b1 :: Bool). ALL (bs :: Bool List). andL(X_Cons b1 bs) = b1 && andL(bs)" OrLNil [rule_format] : "orL(Nil') = False'" OrLCons [rule_format] : "ALL (b1 :: Bool). ALL (bs :: Bool List). orL(X_Cons b1 bs) = b1 || orL(bs)" AnyDef [rule_format] : "ALL (p :: 'a => Bool). ALL (xs :: 'a List). X_any p xs = orL(X_map p xs)" AllDef [rule_format] : "ALL (p :: 'a => Bool). ALL (xs :: 'a List). X_all p xs = andL(X_map p xs)" ConcatDef [rule_format] : "ALL (xxs :: 'a List List). makePartial (concat'(xxs)) = X_foldr (X_curry (uncurryOp X__XPlusXPlus__X)) Nil' xxs" ConcatMapDef [rule_format] : "ALL (g :: 'a => 'b List). ALL (xs :: 'a List). concatMap g xs = concat'(X_map g xs)" MaximunNil [rule_format] : "~ defOp (maximum(Nil'))" MaximumDef [rule_format] : "ALL (ds :: 'd List). maximum(ds) = foldl1 X_maxX4 ds" MinimunNil [rule_format] : "~ defOp (minimum(Nil'))" MinimumDef [rule_format] : "ALL (ds :: 'd List). minimum(ds) = foldl1 X_minX4 ds" TakeWhileNil [rule_format] : "ALL (p :: 'a => Bool). X_takeWhile p Nil' = Nil'" TakeWhileConsT [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). p x = True' --> X_takeWhile p (X_Cons x xs) = X_Cons x (X_takeWhile p xs)" TakeWhileConsF [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). p x = False' --> X_takeWhile p (X_Cons x xs) = Nil'" DropWhileNil [rule_format] : "ALL (p :: 'a => Bool). X_dropWhile p Nil' = Nil'" DropWhileConsT [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). p x = True' --> X_dropWhile p (X_Cons x xs) = X_dropWhile p xs" DropWhileConsF [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). p x = False' --> X_dropWhile p (X_Cons x xs) = X_Cons x xs" SpanNil [rule_format] : "ALL (p :: 'a => Bool). span p Nil' = (Nil', Nil')" SpanConsT [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). p x = True' --> span p (X_Cons x xs) = (let (ys, zs) = span p xs in (X_Cons x ys, zs))" SpanConsF [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). p x = False' --> span p (X_Cons x xs) = (let (ys, zs) = span p xs in (Nil', X_Cons x xs))" SpanThm [rule_format] : "ALL (p :: 'a => Bool). ALL (xs :: 'a List). span p xs = (X_takeWhile p xs, X_dropWhile p xs)" BreakDef [rule_format] : "ALL (p :: 'a => Bool). ALL (xs :: 'a List). break p xs = (let q = X__o__X (notH__X, p) in span q xs)" BreakThm [rule_format] : "ALL (p :: 'a => Bool). ALL (xs :: 'a List). break p xs = span (X__o__X (notH__X, p)) xs" InsertNil [rule_format] : "ALL (q :: 'd). X_insert q Nil' = X_Cons q Nil'" InsertCons1 [rule_format] : "ALL (q :: 'd). ALL (r :: 'd). ALL (rs :: 'd List). q <=_4 r = True' --> X_insert q (X_Cons r rs) = X_Cons q (X_Cons r rs)" InsertCons2 [rule_format] : "ALL (q :: 'd). ALL (r :: 'd). ALL (rs :: 'd List). q >_4 r = True' --> X_insert q (X_Cons r rs) = X_Cons r (X_insert q rs)" DeleteNil [rule_format] : "ALL (s :: 'e). delete s Nil' = Nil'" DeleteConsT [rule_format] : "ALL (s :: 'e). ALL (t :: 'e). ALL (ts :: 'e List). s ==' t = True' --> delete s (X_Cons t ts) = ts" DeleteConsF [rule_format] : "ALL (s :: 'e). ALL (t :: 'e). ALL (ts :: 'e List). s ==' t = False' --> delete s (X_Cons t ts) = X_Cons t (delete s ts)" SelectT [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). ALL (ys :: 'a List). p x = True' --> select p x (xs, ys) = (X_Cons x xs, ys)" SelectF [rule_format] : "ALL (p :: 'a => Bool). ALL (x :: 'a). ALL (xs :: 'a List). ALL (ys :: 'a List). p x = False' --> select p x (xs, ys) = (xs, X_Cons x ys)" Partition [rule_format] : "ALL (p :: 'a => Bool). ALL (xs :: 'a List). makePartial (partition p xs) = X_foldr (select p) (Nil', Nil') xs" PartitionProp [rule_format] : "ALL (p :: 'a => Bool). ALL (xs :: 'a List). partition p xs = (X_filter p xs, X_filter (X__o__X (notH__X, p)) xs)" PartialTest [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). makePartial (X_Cons x xs) = restrictOp (makePartial (X_Cons (makeTotal (head(X_Cons x xs))) (makeTotal (tail(X_Cons x xs))))) (defOp (head(X_Cons x xs)) & defOp (tail(X_Cons x xs)))" ga_selector_pre [rule_format] : "ALL (XX1 :: X_Nat). pre(suc'(XX1)) = makePartial XX1" ga_injective_suc [rule_format] : "ALL (XX1 :: X_Nat). ALL (Y1 :: X_Nat). suc'(XX1) = suc'(Y1) = (XX1 = Y1)" ga_disjoint_0_suc [rule_format] : "ALL (Y1 :: X_Nat). ~ 0'' = suc'(Y1)" ga_selector_undef_pre_0 [rule_format] : "~ defOp (pre(0''))" X1_def_Nat [rule_format] : "1'' = suc'(0'')" X2_def_Nat [rule_format] : "2'' = suc'(1'')" X3_def_Nat [rule_format] : "3'' = suc'(2'')" X4_def_Nat [rule_format] : "4'' = suc'(3'')" X5_def_Nat [rule_format] : "5'' = suc'(4'')" X6_def_Nat [rule_format] : "6'' = suc'(5'')" X7_def_Nat [rule_format] : "7'' = suc'(6'')" X8_def_Nat [rule_format] : "8'' = suc'(7'')" X9_def_Nat [rule_format] : "9'' = suc'(8'')" decimal_def [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). m @@ X_n = (m *'' suc'(9'')) +'' X_n" ga_comm___XPlus__ [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). x +'' y = y +'' x" ga_assoc___XPlus__ [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). ALL (z :: X_Nat). (x +'' y) +'' z = x +'' (y +'' z)" ga_right_unit___XPlus__ [rule_format] : "ALL (x :: X_Nat). x +'' 0'' = x" ga_left_unit___XPlus__ [rule_format] : "ALL (x :: X_Nat). 0'' +'' x = x" ga_left_comm___XPlus__ [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). ALL (z :: X_Nat). x +'' (y +'' z) = y +'' (x +'' z)" ga_comm___Xx__ [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). x *'' y = y *'' x" ga_assoc___Xx__ [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). ALL (z :: X_Nat). (x *'' y) *'' z = x *'' (y *'' z)" ga_right_unit___Xx__ [rule_format] : "ALL (x :: X_Nat). x *'' 1'' = x" ga_left_unit___Xx__ [rule_format] : "ALL (x :: X_Nat). 1'' *'' x = x" ga_left_comm___Xx__ [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). ALL (z :: X_Nat). x *'' (y *'' z) = y *'' (x *'' z)" ga_comm_min [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). min''(x, y) = min''(y, x)" ga_assoc_min [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). ALL (z :: X_Nat). min''(min''(x, y), z) = min''(x, min''(y, z))" ga_left_comm_min [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). ALL (z :: X_Nat). min''(x, min''(y, z)) = min''(y, min''(x, z))" ga_comm_max [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). max''(x, y) = max''(y, x)" ga_assoc_max [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). ALL (z :: X_Nat). max''(max''(x, y), z) = max''(x, max''(y, z))" ga_right_unit_max [rule_format] : "ALL (x :: X_Nat). max''(x, 0'') = x" ga_left_unit_max [rule_format] : "ALL (x :: X_Nat). max''(0'', x) = x" ga_left_comm_max [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). ALL (z :: X_Nat). max''(x, max''(y, z)) = max''(y, max''(x, z))" leq_def1_Nat [rule_format] : "ALL (X_n :: X_Nat). 0'' <='' X_n" dvd_def_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). (m dvd' X_n) = (EX (k :: X_Nat). X_n = m *'' k)" leq_def2_Nat [rule_format] : "ALL (X_n :: X_Nat). ~ suc'(X_n) <='' 0''" leq_def3_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). (suc'(m) <='' suc'(X_n)) = (m <='' X_n)" geq_def_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). (m >='' X_n) = (X_n <='' m)" less_def_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). (m <'' X_n) = (m <='' X_n & ~ m = X_n)" greater_def_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). (m >'' X_n) = (X_n <'' m)" even_0_Nat [rule_format] : "even''(0'')" even_suc_Nat [rule_format] : "ALL (m :: X_Nat). even''(suc'(m)) = odd''(m)" odd_def_Nat [rule_format] : "ALL (m :: X_Nat). odd''(m) = (~ even''(m))" factorial_0 [rule_format] : "0'' !' = 1''" factorial_suc [rule_format] : "ALL (X_n :: X_Nat). suc'(X_n) !' = suc'(X_n) *'' X_n !'" add_0_Nat [rule_format] : "ALL (m :: X_Nat). 0'' +'' m = m" add_suc_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). suc'(X_n) +'' m = suc'(X_n +'' m)" mult_0_Nat [rule_format] : "ALL (m :: X_Nat). 0'' *'' m = 0''" mult_suc_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). suc'(X_n) *'' m = (X_n *'' m) +'' m" power_0_Nat [rule_format] : "ALL (m :: X_Nat). m ^'' 0'' = 1''" power_suc_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). m ^'' suc'(X_n) = m *'' (m ^'' X_n)" min_def_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). min''(m, X_n) = (if m <='' X_n then m else X_n)" max_def_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). max''(m, X_n) = (if m <='' X_n then X_n else m)" subTotal_def1_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). m >'' X_n --> X_n -! m = 0''" subTotal_def2_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). m <='' X_n --> makePartial (X_n -! m) = X_n -? m" sub_dom_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). defOp (m -? X_n) = (m >='' X_n)" sub_def_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). ALL (r :: X_Nat). m -? X_n = makePartial r = (m = r +'' X_n)" divide_dom_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). defOp (m /?'' X_n) = (~ X_n = 0'' & m mod'' X_n = makePartial 0'')" divide_0_Nat [rule_format] : "ALL (m :: X_Nat). ~ defOp (m /?'' 0'')" divide_Pos_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). ALL (r :: X_Nat). X_n >'' 0'' --> m /?'' X_n = makePartial r = (m = r *'' X_n)" div_dom_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). defOp (m div'' X_n) = (~ X_n = 0'')" div_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). ALL (r :: X_Nat). m div'' X_n = makePartial r = (EX (s :: X_Nat). m = (X_n *'' r) +'' s & s <'' X_n)" mod_dom_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). defOp (m mod'' X_n) = (~ X_n = 0'')" mod_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). ALL (s :: X_Nat). m mod'' X_n = makePartial s = (EX (r :: X_Nat). m = (X_n *'' r) +'' s & s <'' X_n)" distr1_Nat [rule_format] : "ALL (r :: X_Nat). ALL (s :: X_Nat). ALL (t :: X_Nat). (r +'' s) *'' t = (r *'' t) +'' (s *'' t)" distr2_Nat [rule_format] : "ALL (r :: X_Nat). ALL (s :: X_Nat). ALL (t :: X_Nat). t *'' (r +'' s) = (t *'' r) +'' (t *'' s)" Pos_def [rule_format] : "ALL (p :: X_Nat). defOp ((X_gn_proj :: X_Nat => Pos partial) p) = (p >'' 0'')" X1_as_Pos_def [rule_format] : "1_3 = suc''(0'')" min_0 [rule_format] : "ALL (m :: X_Nat). min''(m, 0'') = 0''" div_mod_Nat [rule_format] : "ALL (m :: X_Nat). ALL (X_n :: X_Nat). ~ X_n = 0'' --> makePartial m = restrictOp (makePartial ((makeTotal (m div'' X_n) *'' X_n) +'' makeTotal (m mod'' X_n))) (defOp (m div'' X_n) & defOp (m mod'' X_n))" power_Nat [rule_format] : "ALL (m :: X_Nat). ALL (r :: X_Nat). ALL (s :: X_Nat). m ^'' (r +'' s) = (m ^'' r) *'' (m ^'' s)" ga_generated_Int [rule_format] : "ALL (p_Int :: X_Int => bool). (ALL (x_1 :: X_Nat). ALL (x_2 :: X_Nat). p_Int (x_1 -'' x_2)) --> (ALL (x :: X_Int). p_Int x)" equality_Int [rule_format] : "ALL (a :: X_Nat). ALL (b :: X_Nat). ALL (c :: X_Nat). ALL (d :: X_Nat). a -'' b = c -'' d = (a +'' d = c +'' b)" Nat2Int_embedding [rule_format] : "ALL (a :: X_Nat). (X_gn_inj :: X_Nat => X_Int) a = a -'' 0''" ga_comm___XPlus___80 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). x +' y = y +' x" ga_assoc___XPlus___76 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). ALL (z :: X_Int). (x +' y) +' z = x +' (y +' z)" ga_right_unit___XPlus___90 [rule_format] : "ALL (x :: X_Int). x +' (X_gn_inj :: X_Nat => X_Int) 0'' = x" ga_left_unit___XPlus___88 [rule_format] : "ALL (x :: X_Int). (X_gn_inj :: X_Nat => X_Int) 0'' +' x = x" ga_left_comm___XPlus___84 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). ALL (z :: X_Int). x +' (y +' z) = y +' (x +' z)" ga_comm___Xx___79 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). x *' y = y *' x" ga_assoc___Xx___75 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). ALL (z :: X_Int). (x *' y) *' z = x *' (y *' z)" ga_right_unit___Xx___89 [rule_format] : "ALL (x :: X_Int). x *' (X_gn_inj :: Pos => X_Int) 1_3 = x" ga_left_unit___Xx___87 [rule_format] : "ALL (x :: X_Int). (X_gn_inj :: Pos => X_Int) 1_3 *' x = x" ga_left_comm___Xx___83 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). ALL (z :: X_Int). x *' (y *' z) = y *' (x *' z)" ga_comm_min_82 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). min'(x, y) = min'(y, x)" ga_comm_max_81 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). max'(x, y) = max'(y, x)" ga_assoc_min_78 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). ALL (z :: X_Int). min'(min'(x, y), z) = min'(x, min'(y, z))" ga_assoc_max_77 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). ALL (z :: X_Int). max'(max'(x, y), z) = max'(x, max'(y, z))" ga_left_comm_min_86 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). ALL (z :: X_Int). min'(x, min'(y, z)) = min'(y, min'(x, z))" ga_left_comm_max_85 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). ALL (z :: X_Int). max'(x, max'(y, z)) = max'(y, max'(x, z))" leq_def_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). (m <=' X_n) = defOp ((X_gn_proj :: X_Int => X_Nat partial) (X_n -' m))" geq_def_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). (m >=' X_n) = (X_n <=' m)" less_def_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). (m <' X_n) = (m <=' X_n & ~ m = X_n)" greater_def_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). (m >' X_n) = (X_n <' m)" even_def_Int [rule_format] : "ALL (m :: X_Int). even'(m) = even''(abs'(m))" odd_def_Int [rule_format] : "ALL (m :: X_Int). odd'(m) = (~ even'(m))" odd_alt_Int [rule_format] : "ALL (m :: X_Int). odd'(m) = odd''(abs'(m))" neg_def_Int [rule_format] : "ALL (a :: X_Nat). ALL (b :: X_Nat). -' (a -'' b) = b -'' a" sign_def_Int [rule_format] : "ALL (m :: X_Int). sign(m) = (if m = (X_gn_inj :: X_Nat => X_Int) 0'' then (X_gn_inj :: X_Nat => X_Int) 0'' else if m >' (X_gn_inj :: X_Nat => X_Int) 0'' then (X_gn_inj :: Pos => X_Int) 1_3 else -' (X_gn_inj :: Pos => X_Int) 1_3)" abs_def_Int [rule_format] : "ALL (m :: X_Int). (X_gn_inj :: X_Nat => X_Int) (abs'(m)) = (if m <' (X_gn_inj :: X_Nat => X_Int) 0'' then -' m else m)" add_def_Int [rule_format] : "ALL (a :: X_Nat). ALL (b :: X_Nat). ALL (c :: X_Nat). ALL (d :: X_Nat). (a -'' b) +' (c -'' d) = (a +'' c) -'' (b +'' d)" mult_def_Int [rule_format] : "ALL (a :: X_Nat). ALL (b :: X_Nat). ALL (c :: X_Nat). ALL (d :: X_Nat). (a -'' b) *' (c -'' d) = ((a *'' c) +'' (b *'' d)) -'' ((b *'' c) +'' (a *'' d))" sub_def_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). m -' X_n = m +' -' X_n" min_def_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). min'(m, X_n) = (if m <=' X_n then m else X_n)" max_def_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). max'(m, X_n) = (if m <=' X_n then X_n else m)" power_neg1_Int [rule_format] : "ALL (a :: X_Nat). -' (X_gn_inj :: Pos => X_Int) 1_3 ^' a = (if even''(a) then (X_gn_inj :: Pos => X_Int) 1_3 else -' (X_gn_inj :: Pos => X_Int) 1_3)" power_others_Int [rule_format] : "ALL (m :: X_Int). ALL (a :: X_Nat). ~ m = -' (X_gn_inj :: Pos => X_Int) 1_3 --> m ^' a = (sign(m) ^' a) *' (X_gn_inj :: X_Nat => X_Int) (abs'(m) ^'' a)" divide_dom2_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). defOp (m /?' X_n) = (m mod' X_n = makePartial 0'')" divide_alt_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ALL (r :: X_Int). m /?' X_n = makePartial r = (~ X_n = (X_gn_inj :: X_Nat => X_Int) 0'' & X_n *' r = m)" divide_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). m /?' X_n = restrictOp (makePartial ((sign(m) *' sign(X_n)) *' (X_gn_inj :: X_Nat => X_Int) (makeTotal (abs'(m) /?'' abs'(X_n))))) (defOp (abs'(m) /?'' abs'(X_n)))" div_dom_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). defOp (m div' X_n) = (~ X_n = (X_gn_inj :: X_Nat => X_Int) 0'')" div_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ALL (r :: X_Int). m div' X_n = makePartial r = (EX (a :: X_Nat). m = (X_n *' r) +' (X_gn_inj :: X_Nat => X_Int) a & a <'' abs'(X_n))" quot_dom_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). defOp (m quot' X_n) = (~ X_n = (X_gn_inj :: X_Nat => X_Int) 0'')" quot_neg_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ALL (r :: X_Int). m <' (X_gn_inj :: X_Nat => X_Int) 0'' --> m quot' X_n = makePartial r = (EX (s :: X_Int). m = (X_n *' r) +' s & (X_gn_inj :: X_Nat => X_Int) 0'' >=' s & s >' -' (X_gn_inj :: X_Nat => X_Int) (abs'(X_n)))" quot_nonneg_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ALL (r :: X_Int). m >=' (X_gn_inj :: X_Nat => X_Int) 0'' --> m quot' X_n = makePartial r = (EX (s :: X_Int). m = (X_n *' r) +' s & (X_gn_inj :: X_Nat => X_Int) 0'' <=' s & s <' (X_gn_inj :: X_Nat => X_Int) (abs'(X_n)))" rem_dom_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). defOp (m rem' X_n) = (~ X_n = (X_gn_inj :: X_Nat => X_Int) 0'')" rem_neg_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ALL (s :: X_Int). m <' (X_gn_inj :: X_Nat => X_Int) 0'' --> m rem' X_n = makePartial s = (EX (r :: X_Int). m = (X_n *' r) +' s & (X_gn_inj :: X_Nat => X_Int) 0'' >=' s & s >' -' (X_gn_inj :: X_Nat => X_Int) (abs'(X_n)))" rem_nonneg_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ALL (s :: X_Int). m >=' (X_gn_inj :: X_Nat => X_Int) 0'' --> m rem' X_n = makePartial s = (EX (r :: X_Int). m = (X_n *' r) +' s & (X_gn_inj :: X_Nat => X_Int) 0'' <=' s & s <' (X_gn_inj :: X_Nat => X_Int) (abs'(X_n)))" mod_dom_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). defOp (m mod' X_n) = (~ X_n = (X_gn_inj :: X_Nat => X_Int) 0'')" mod_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ALL (a :: X_Nat). m mod' X_n = makePartial a = (EX (r :: X_Int). m = (X_n *' r) +' (X_gn_inj :: X_Nat => X_Int) a & a <'' abs'(X_n))" distr1_Int [rule_format] : "ALL (r :: X_Int). ALL (s :: X_Int). ALL (t :: X_Int). (r +' s) *' t = (r *' t) +' (s *' t)" distr2_Int [rule_format] : "ALL (r :: X_Int). ALL (s :: X_Int). ALL (t :: X_Int). t *' (r +' s) = (t *' r) +' (t *' s)" Int_Nat_sub_compat [rule_format] : "ALL (a :: X_Nat). ALL (b :: X_Nat). defOp (a -? b) --> restrictOp (makePartial ((X_gn_inj :: X_Nat => X_Int) (makeTotal (a -? b)))) (defOp (a -? b)) = makePartial (a -'' b)" abs_decomp_Int [rule_format] : "ALL (m :: X_Int). m = sign(m) *' (X_gn_inj :: X_Nat => X_Int) (abs'(m))" mod_abs_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). m mod' X_n = m mod' (X_gn_inj :: X_Nat => X_Int) (abs'(X_n))" div_mod_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ~ X_n = (X_gn_inj :: X_Nat => X_Int) 0'' --> makePartial m = restrictOp (makePartial ((makeTotal (m div' X_n) *' X_n) +' (X_gn_inj :: X_Nat => X_Int) (makeTotal (m mod' X_n)))) (defOp (m div' X_n) & defOp (m mod' X_n))" quot_abs_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). restrictOp (makePartial ((X_gn_inj :: X_Nat => X_Int) (abs'(makeTotal (m quot' X_n))))) (defOp (m quot' X_n)) = (X_gn_inj :: X_Nat => X_Int) (abs'(m)) quot' (X_gn_inj :: X_Nat => X_Int) (abs'(X_n))" rem_abs_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). restrictOp (makePartial ((X_gn_inj :: X_Nat => X_Int) (abs'(makeTotal (m rem' X_n))))) (defOp (m rem' X_n)) = (X_gn_inj :: X_Nat => X_Int) (abs'(m)) rem' (X_gn_inj :: X_Nat => X_Int) (abs'(X_n))" quot_rem_Int [rule_format] : "ALL (m :: X_Int). ALL (X_n :: X_Int). ~ X_n = (X_gn_inj :: X_Nat => X_Int) 0'' --> makePartial m = restrictOp (makePartial ((makeTotal (m quot' X_n) *' X_n) +' makeTotal (m rem' X_n))) (defOp (m quot' X_n) & defOp (m rem' X_n))" power_Int [rule_format] : "ALL (m :: X_Int). ALL (a :: X_Nat). ALL (b :: X_Nat). m ^' (a +'' b) = (m ^' a) *' (m ^' b)" ga_generated_Rat [rule_format] : "ALL (p_Rat :: Rat => bool). (ALL (x_1 :: X_Int). ALL (x_2 :: Pos). p_Rat (x_1 /' x_2)) --> (ALL (x :: Rat). p_Rat x)" equality_Rat [rule_format] : "ALL (i :: X_Int). ALL (j :: X_Int). ALL (p :: Pos). ALL (q :: Pos). i /' p = j /' q = (i *' (X_gn_inj :: Pos => X_Int) q = j *' (X_gn_inj :: Pos => X_Int) p)" Int2Rat_embedding [rule_format] : "ALL (i :: X_Int). (X_gn_inj :: X_Int => Rat) i = i /' 1_3" ga_comm___XPlus___139 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). x +_5 y = y +_5 x" ga_assoc___XPlus___135 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). (x +_5 y) +_5 z = x +_5 (y +_5 z)" ga_right_unit___XPlus___149 [rule_format] : "ALL (x :: Rat). x +_5 (X_gn_inj :: X_Nat => Rat) 0'' = x" ga_left_unit___XPlus___147 [rule_format] : "ALL (x :: Rat). (X_gn_inj :: X_Nat => Rat) 0'' +_5 x = x" ga_left_comm___XPlus___143 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). x +_5 (y +_5 z) = y +_5 (x +_5 z)" ga_comm___Xx___138 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). x *_4 y = y *_4 x" ga_assoc___Xx___134 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). (x *_4 y) *_4 z = x *_4 (y *_4 z)" ga_right_unit___Xx___148 [rule_format] : "ALL (x :: Rat). x *_4 (X_gn_inj :: Pos => Rat) 1_3 = x" ga_left_unit___Xx___146 [rule_format] : "ALL (x :: Rat). (X_gn_inj :: Pos => Rat) 1_3 *_4 x = x" ga_left_comm___Xx___142 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). x *_4 (y *_4 z) = y *_4 (x *_4 z)" ga_comm_min_141 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). min_3(x, y) = min_3(y, x)" ga_comm_max_140 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). max_3(x, y) = max_3(y, x)" ga_assoc_min_137 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). min_3(min_3(x, y), z) = min_3(x, min_3(y, z))" ga_assoc_max_136 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). max_3(max_3(x, y), z) = max_3(x, max_3(y, z))" ga_left_comm_min_145 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). min_3(x, min_3(y, z)) = min_3(y, min_3(x, z))" ga_left_comm_max_144 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). max_3(x, max_3(y, z)) = max_3(y, max_3(x, z))" leq_def_Rat [rule_format] : "ALL (p :: Pos). ALL (q :: Pos). ALL (i :: X_Int). ALL (j :: X_Int). (i /' p <=_3 j /' q) = (i *' (X_gn_inj :: Pos => X_Int) q <=' j *' (X_gn_inj :: Pos => X_Int) p)" geq_def_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). (x >=_3 y) = (y <=_3 x)" less_def_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). (x <_3 y) = (x <=_3 y & ~ x = y)" greater_def_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). (x >_3 y) = (y <_3 x)" minus_def_Rat [rule_format] : "ALL (p :: Pos). ALL (i :: X_Int). -'' (i /' p) = -' i /' p" abs_def_Rat [rule_format] : "ALL (p :: Pos). ALL (i :: X_Int). abs''(i /' p) = (X_gn_inj :: X_Nat => X_Int) (abs'(i)) /' p" add_def_Rat [rule_format] : "ALL (p :: Pos). ALL (q :: Pos). ALL (i :: X_Int). ALL (j :: X_Int). (i /' p) +_5 (j /' q) = ((i *' (X_gn_inj :: Pos => X_Int) q) +' (j *' (X_gn_inj :: Pos => X_Int) p)) /' (p *_3 q)" sub_def_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). x -_3 y = x +_5 -'' y" mult_def_Rat [rule_format] : "ALL (p :: Pos). ALL (q :: Pos). ALL (i :: X_Int). ALL (j :: X_Int). (i /' p) *_4 (j /' q) = (i *' j) /' (p *_3 q)" min_def_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). min_3(x, y) = (if x <=_3 y then x else y)" max_def_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). max_3(x, y) = (if x <=_3 y then y else x)" divide_def1_Rat [rule_format] : "ALL (x :: Rat). ~ defOp (x /'' (X_gn_inj :: X_Nat => Rat) 0'')" divide_def2_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). ~ y = (X_gn_inj :: X_Nat => Rat) 0'' --> x /'' y = makePartial z = (x = z *_4 y)" power_0_Rat [rule_format] : "ALL (x :: Rat). x ^_3 (X_gn_inj :: X_Nat => X_Int) 0'' = makePartial ((X_gn_inj :: Pos => Rat) 1_3)" power_suc_Rat [rule_format] : "ALL (X_n :: X_Nat). ALL (x :: Rat). x ^_3 (X_gn_inj :: Pos => X_Int) (suc''(X_n)) = restrictOp (makePartial (x *_4 makeTotal (x ^_3 (X_gn_inj :: X_Nat => X_Int) X_n))) (defOp (x ^_3 (X_gn_inj :: X_Nat => X_Int) X_n))" power_neg_Rat [rule_format] : "ALL (p :: Pos). ALL (x :: Rat). x ^_3 -' (X_gn_inj :: Pos => X_Int) p = restrictOp ((X_gn_inj :: Pos => Rat) 1_3 /'' makeTotal (x ^_3 (X_gn_inj :: Pos => X_Int) p)) (defOp (x ^_3 (X_gn_inj :: Pos => X_Int) p))" distr1_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). (x +_5 y) *_4 z = (x *_4 z) +_5 (y *_4 z)" distr2_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). ALL (z :: Rat). z *_4 (x +_5 y) = (z *_4 x) +_5 (z *_4 y)" sub_rule_Rat [rule_format] : "ALL (i :: X_Int). ALL (j :: X_Int). ALL (p :: Pos). ALL (q :: Pos). (i /' p) -_3 (j /' q) = ((i *' (X_gn_inj :: Pos => X_Int) q) -' (j *' (X_gn_inj :: Pos => X_Int) p)) /' (p *_3 q)" divide_dom_Rat [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). defOp (x /'' y) = (~ y = (X_gn_inj :: X_Nat => Rat) 0'')" divide_rule_Rat [rule_format] : "ALL (i :: X_Int). ALL (j :: X_Int). ALL (p :: Pos). ALL (q :: Pos). ~ j = (X_gn_inj :: X_Nat => X_Int) 0'' --> (i /' p) /'' (j /' q) = (X_gn_inj :: X_Int => Rat) (i *' (X_gn_inj :: Pos => X_Int) q) /'' (X_gn_inj :: X_Int => Rat) ((X_gn_inj :: Pos => X_Int) p *' j)" power_Rat [rule_format] : "ALL (i :: X_Int). ALL (j :: X_Int). ALL (x :: Rat). x ^_3 (i +' j) = restrictOp (makePartial (makeTotal (x ^_3 i) *_4 makeTotal (x ^_3 j))) (defOp (x ^_3 i) & defOp (x ^_3 j))" AbsSignumLaw [rule_format] : "ALL (x :: 'a). abs_3(x) *_5 signum(x) = x" IPN01 [rule_format] : "ALL (x :: Pos). ALL (y :: Pos). (X_gn_inj :: Pos => X_Int) x +' (X_gn_inj :: Pos => X_Int) y = (X_gn_inj :: X_Nat => X_Int) ((X_gn_inj :: Pos => X_Nat) x +'' (X_gn_inj :: Pos => X_Nat) y)" IPN02 [rule_format] : "ALL (x :: Pos). ALL (y :: Pos). (X_gn_inj :: Pos => X_Int) x *' (X_gn_inj :: Pos => X_Int) y = (X_gn_inj :: X_Nat => X_Int) ((X_gn_inj :: Pos => X_Nat) x *'' (X_gn_inj :: Pos => X_Nat) y)" IPN03 [rule_format] : "ALL (x :: Pos). ALL (y :: Pos). (X_gn_inj :: Pos => X_Int) x -' (X_gn_inj :: Pos => X_Int) y = (X_gn_inj :: X_Nat => X_Int) ((X_gn_inj :: Pos => X_Nat) x -! (X_gn_inj :: Pos => X_Nat) y)" IPN04 [rule_format] : "ALL (x :: Pos). (X_gn_inj :: Pos => X_Nat) (negate(x)) = 0'' -! (X_gn_inj :: Pos => X_Nat) x" IPN05 [rule_format] : "ALL (x :: Pos). abs_3(x) = x" IPN06 [rule_format] : "ALL (x :: Pos). signum(x) = 1_3" IPN07 [rule_format] : "ALL (z :: X_Int). makePartial (fromInteger(z)) = (X_gn_proj :: X_Int => Pos partial) z" INN01 [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). (X_gn_inj :: X_Nat => X_Int) x +' (X_gn_inj :: X_Nat => X_Int) y = (X_gn_inj :: X_Nat => X_Int) (x +'' y)" INN02 [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). (X_gn_inj :: X_Nat => X_Int) x *' (X_gn_inj :: X_Nat => X_Int) y = (X_gn_inj :: X_Nat => X_Int) (x *'' y)" INN03 [rule_format] : "ALL (x :: X_Nat). ALL (y :: X_Nat). (X_gn_inj :: X_Nat => X_Int) x -' (X_gn_inj :: X_Nat => X_Int) y = (X_gn_inj :: X_Nat => X_Int) (x -! y)" INN04 [rule_format] : "ALL (x :: X_Nat). negate(x) = 0'' -! x" INN05 [rule_format] : "ALL (x :: X_Nat). abs_3(x) = x" INN06 [rule_format] : "ALL (x :: X_Nat). signum(x) = (X_gn_inj :: Pos => X_Nat) 1_3" INN07 [rule_format] : "ALL (z :: X_Int). makePartial (fromInteger(z)) = (X_gn_proj :: X_Int => X_Nat partial) z" IIN01 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). x +' y = x +' y" IIN02 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). x *' y = x *' y" IIN03 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). x -' y = x -' y" IIN04 [rule_format] : "ALL (x :: X_Int). negate(x) = (X_gn_inj :: X_Nat => X_Int) 0'' -' x" IIN05 [rule_format] : "ALL (x :: X_Int). x >=_4 (X_gn_inj :: X_Nat => X_Int) 0'' = True' --> abs_3(x) = x" IIN06 [rule_format] : "ALL (x :: X_Int). x <_4 (X_gn_inj :: X_Nat => X_Int) 0'' = True' --> abs_3(x) = negate(x)" IIN07 [rule_format] : "ALL (x :: X_Int). x >_4 (X_gn_inj :: X_Nat => X_Int) 0'' = True' --> signum(x) = (X_gn_inj :: Pos => X_Int) 1_3" IIN07_1 [rule_format] : "ALL (x :: X_Int). x ==' (X_gn_inj :: X_Nat => X_Int) 0'' = True' --> signum(x) = (X_gn_inj :: X_Nat => X_Int) 0''" IIN08 [rule_format] : "ALL (x :: X_Int). x <_4 (X_gn_inj :: X_Nat => X_Int) 0'' = True' --> signum(x) = -' (X_gn_inj :: Pos => X_Int) 1_3" IIN09 [rule_format] : "ALL (x :: X_Int). fromInteger(x) = x" IRN01 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). x +_5 y = x +_5 y" IRN02 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). x *_4 y = x *_4 y" IRN03 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). x -_3 y = x -_3 y" IRN04 [rule_format] : "ALL (x :: Rat). negate(x) = (X_gn_inj :: X_Nat => Rat) 0'' -_3 x" IRN05 [rule_format] : "ALL (x :: Rat). x >=_4 (X_gn_inj :: X_Nat => Rat) 0'' = True' --> abs_3(x) = x" IRN06 [rule_format] : "ALL (x :: Rat). x <_4 (X_gn_inj :: X_Nat => Rat) 0'' = True' --> abs_3(x) = negate(x)" IRN07 [rule_format] : "ALL (x :: Rat). x >_4 (X_gn_inj :: X_Nat => Rat) 0'' = True' --> signum(x) = (X_gn_inj :: Pos => Rat) 1_3" IRN07_2 [rule_format] : "ALL (x :: Rat). x ==' (X_gn_inj :: X_Nat => Rat) 0'' = True' --> signum(x) = (X_gn_inj :: X_Nat => Rat) 0''" IRN08 [rule_format] : "ALL (x :: Rat). x <_4 (X_gn_inj :: X_Nat => Rat) 0'' = True' --> signum(x) = (X_gn_inj :: X_Int => Rat) (-' (X_gn_inj :: Pos => X_Int) 1_3)" IRN09 [rule_format] : "ALL (z :: X_Int). fromInteger(z) = z /' 1_3" IRI01 [rule_format] : "ALL (w :: 'a). ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). (z, w) = quotRem x y --> x quot'' y = z" IRI02 [rule_format] : "ALL (w :: 'a). ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). (z, w) = quotRem x y --> x rem'' y = w" IRI03 [rule_format] : "ALL (w :: 'a). ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). (z, w) = divMod x y --> x div_3 y = z" IRI04 [rule_format] : "ALL (w :: 'a). ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). (z, w) = divMod x y --> x mod_3 y = w" IRI05 [rule_format] : "ALL (s :: 'a). ALL (w :: 'a). ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). signum(w) = negate(signum(y)) & (z, w) = quotRem x y --> divMod x y = (z -_4 fromInteger(toInteger((X_gn_inj :: Pos => X_Nat) 1_3)), w +_6 s)" IRI06 [rule_format] : "ALL (w :: 'a). ALL (x :: 'a). ALL (y :: 'a). ALL (z :: 'a). ~ signum(w) = negate(signum(y)) & (z, w) = quotRem x y --> divMod x y = (z, w)" IRI01_3 [rule_format] : "ALL (x :: X_Int). makePartial ((X_gn_inj :: X_Int => Rat) (recip(x))) = (X_gn_inj :: Pos => Rat) 1_3 /'' (X_gn_inj :: X_Int => Rat) x" IRI02_4 [rule_format] : "ALL (x :: X_Int). ALL (y :: X_Int). (X_gn_inj :: X_Int => Rat) x /'' (X_gn_inj :: X_Int => Rat) y = makePartial ((X_gn_inj :: X_Int => Rat) (x *' recip(y)))" IRF01 [rule_format] : "ALL (x :: Rat). makePartial (recip(x)) = (X_gn_inj :: Pos => Rat) 1_3 /'' x" IRF02 [rule_format] : "ALL (x :: Rat). ALL (y :: Rat). x /'' y = makePartial (x *_4 recip(y))" LengthNil [rule_format] : "length'(Nil') = (X_gn_inj :: X_Nat => X_Int) 0''" LengthCons [rule_format] : "ALL (x :: 'a). ALL (xs :: 'a List). length'(X_Cons x xs) = length'(xs) +' (X_gn_inj :: Pos => X_Int) 1_3" TakeNegative [rule_format] : "ALL (X_n :: X_Int). ALL (xs :: 'a List). (X_gn_inj :: X_Int => Rat) X_n <=_3 (X_gn_inj :: X_Nat => Rat) 0'' --> X_take X_n xs = Nil'" TakeNil [rule_format] : "ALL (X_n :: X_Int). X_take X_n Nil' = Nil'" TakeCons [rule_format] : "ALL (X_n :: X_Int). ALL (x :: 'a). ALL (xs :: 'a List). X_take X_n (X_Cons x xs) = X_Cons x (X_take (X_n -' (X_gn_inj :: Pos => X_Int) 1_3) xs)" DropNegative [rule_format] : "ALL (X_n :: X_Int). ALL (xs :: 'a List). (X_gn_inj :: X_Int => Rat) X_n <=_3 (X_gn_inj :: X_Nat => Rat) 0'' --> X_drop X_n xs = xs" DropNil [rule_format] : "ALL (X_n :: X_Int). X_drop X_n Nil' = Nil'" DropCons [rule_format] : "ALL (X_n :: X_Int). ALL (x :: 'a). ALL (xs :: 'a List). X_drop X_n (X_Cons x xs) = X_drop (X_n -' (X_gn_inj :: Pos => X_Int) 1_3) xs" SplitAt [rule_format] : "ALL (X_n :: X_Int). ALL (xs :: 'a List). splitAt X_n xs = (X_take X_n xs, X_drop X_n xs)" Sum'Nil [rule_format] : "ALL (z :: X_Int). sum' Nil' z = z" Sum'Cons [rule_format] : "ALL (w :: X_Int). ALL (z :: X_Int). ALL (zs :: X_Int List). sum' (X_Cons z zs) w = sum' zs (w +_6 z)" SumL [rule_format] : "ALL (zs :: X_Int List). sum(zs) = sum' zs ((X_gn_inj :: X_Nat => X_Int) 0'')" Prod'Nil [rule_format] : "ALL (z :: X_Int). product' Nil' z = z" Prod'Cons [rule_format] : "ALL (w :: X_Int). ALL (z :: X_Int). ALL (zs :: X_Int List). product' (X_Cons z zs) w = product' zs (w *_5 z)" ProdL [rule_format] : "ALL (zs :: X_Int List). product(zs) = product' zs ((X_gn_inj :: Pos => X_Int) 1_3)" declare ga_subt_reflexive [simp] declare ga_subt_Int_XLt_Rat [simp] declare ga_subt_Nat_XLt_Int [simp] declare ga_subt_Pos_XLt_Nat [simp] declare Comp1 [simp] declare IdDef [simp] declare FlipDef [simp] declare FstDef [simp] declare SndDef [simp] declare CurryDef [simp] declare UncurryDef [simp] declare NotFalse [simp] declare NotTrue [simp] declare AndFalse [simp] declare AndTrue [simp] declare EqualReflex [simp] declare IBE1 [simp] declare IBE2 [simp] declare IBE3 [simp] declare IBE4 [simp] declare IBE5 [simp] declare IBE6 [simp] declare IBE7 [simp] declare IBE8 [simp] declare IOE01 [simp] declare IOE02 [simp] declare IOE03 [simp] declare IOE04 [simp] declare IOE05 [simp] declare IOE06 [simp] declare IOE07 [simp] declare IOE08 [simp] declare IOE09 [simp] declare LeIrreflexivity [simp] declare LeTAsymmetry [simp] declare GeIrreflexivity [simp] declare GeTAsymmetry [simp] declare GeTTransitive [simp] declare GeTTotal [simp] declare LeqReflexivity [simp] declare LeqTTransitive [simp] declare LeqTTotal [simp] declare GeqReflexivity [simp] declare GeqTTransitive [simp] declare GeqTTotal [simp] declare CmpLTDef [simp] declare CmpEQDef [simp] declare CmpGTDef [simp] declare MaxYDef [simp] declare MaxXDef [simp] declare MinXDef [simp] declare MinYDef [simp] declare TO4 [simp] declare IOO13 [simp] declare IOO14 [simp] declare IOO15 [simp] declare IOO16 [simp] declare IOO17 [simp] declare IOO18 [simp] declare IOO19 [simp] declare IOO20 [simp] declare IOO21 [simp] declare IOO22 [simp] declare IOO23 [simp] declare IOO24 [simp] declare IOO25 [simp] declare IOO26 [simp] declare IOO27 [simp] declare IOO28 [simp] declare IOO29 [simp] declare IOO30 [simp] declare IOO31 [simp] declare IOO32 [simp] declare IOO33 [simp] declare IBO5 [simp] declare IBO6 [simp] declare IBO7 [simp] declare IBO8 [simp] declare IBO9 [simp] declare IBO10 [simp] declare IBO11 [simp] declare IBO12 [simp] declare IUO05 [simp] declare IUO06 [simp] declare IUO07 [simp] declare NotDefHead [simp] declare HeadDef [simp] declare NotDefTail [simp] declare TailDef [simp] declare FoldrNil [simp] declare FoldlNil [simp] declare MapNil [simp] declare XPlusXPlusNil [simp] declare FilterNil [simp] declare FilterConsF [simp] declare ZipNil [simp] declare ILE01 [simp] declare ILO01 [simp] declare ILO02 [simp] declare ILO03 [simp] declare ILO04 [simp] declare ILO05 [simp] declare ILO06 [simp] declare ILO11 [simp] declare ILO12 [simp] declare ILO13 [simp] declare ILO14 [simp] declare ILO15 [simp] declare ILO16 [simp] declare ILO17 [simp] declare ILO18 [simp] declare InitNil [simp] declare InitConsNil [simp] declare LastNil [simp] declare LastConsNil [simp] declare LastConsCons [simp] declare NullNil [simp] declare NullCons [simp] declare ReverseNil [simp] declare Foldr1Nil [simp] declare Foldr1ConsNil [simp] declare Foldl1Nil [simp] declare Foldl1ConsNil [simp] declare Scanl1Nil [simp] declare Scanl1Cons [simp] declare ScanrNil [simp] declare Scanr1Nil [simp] declare Scanr1ConsNil [simp] declare ScanlProperty [simp] declare ScanrProperty [simp] declare AndLNil [simp] declare OrLNil [simp] declare MaximunNil [simp] declare MinimunNil [simp] declare TakeWhileNil [simp] declare TakeWhileConsF [simp] declare DropWhileNil [simp] declare DropWhileConsT [simp] declare DropWhileConsF [simp] declare SpanNil [simp] declare DeleteNil [simp] declare DeleteConsT [simp] declare SelectT [simp] declare SelectF [simp] declare ga_selector_pre [simp] declare ga_selector_undef_pre_0 [simp] declare ga_comm___XPlus__ [simp] declare ga_assoc___XPlus__ [simp] declare ga_right_unit___XPlus__ [simp] declare ga_left_unit___XPlus__ [simp] declare ga_left_comm___XPlus__ [simp] declare ga_comm___Xx__ [simp] declare ga_assoc___Xx__ [simp] declare ga_right_unit___Xx__ [simp] declare ga_left_unit___Xx__ [simp] declare ga_left_comm___Xx__ [simp] declare ga_comm_min [simp] declare ga_assoc_min [simp] declare ga_left_comm_min [simp] declare ga_comm_max [simp] declare ga_assoc_max [simp] declare ga_right_unit_max [simp] declare ga_left_unit_max [simp] declare ga_left_comm_max [simp] declare leq_def1_Nat [simp] declare dvd_def_Nat [simp] declare leq_def2_Nat [simp] declare leq_def3_Nat [simp] declare geq_def_Nat [simp] declare less_def_Nat [simp] declare greater_def_Nat [simp] declare even_0_Nat [simp] declare even_suc_Nat [simp] declare odd_def_Nat [simp] declare factorial_0 [simp] declare factorial_suc [simp] declare add_0_Nat [simp] declare add_suc_Nat [simp] declare mult_0_Nat [simp] declare mult_suc_Nat [simp] declare power_0_Nat [simp] declare power_suc_Nat [simp] declare subTotal_def1_Nat [simp] declare subTotal_def2_Nat [simp] declare sub_dom_Nat [simp] declare divide_0_Nat [simp] declare min_0 [simp] declare ga_comm___XPlus___80 [simp] declare ga_assoc___XPlus___76 [simp] declare ga_right_unit___XPlus___90 [simp] declare ga_left_unit___XPlus___88 [simp] declare ga_left_comm___XPlus___84 [simp] declare ga_comm___Xx___79 [simp] declare ga_assoc___Xx___75 [simp] declare ga_right_unit___Xx___89 [simp] declare ga_left_unit___Xx___87 [simp] declare ga_left_comm___Xx___83 [simp] declare ga_comm_min_82 [simp] declare ga_comm_max_81 [simp] declare ga_assoc_min_78 [simp] declare ga_assoc_max_77 [simp] declare ga_left_comm_min_86 [simp] declare ga_left_comm_max_85 [simp] declare leq_def_Int [simp] declare even_def_Int [simp] declare odd_alt_Int [simp] declare neg_def_Int [simp] declare sign_def_Int [simp] declare abs_def_Int [simp] declare add_def_Int [simp] declare mult_def_Int [simp] declare sub_def_Int [simp] declare min_def_Int [simp] declare max_def_Int [simp] declare power_neg1_Int [simp] declare power_others_Int [simp] declare divide_Int [simp] declare div_Int [simp] declare quot_neg_Int [simp] declare quot_nonneg_Int [simp] declare rem_neg_Int [simp] declare rem_nonneg_Int [simp] declare mod_Int [simp] declare Int_Nat_sub_compat [simp] declare quot_abs_Int [simp] declare rem_abs_Int [simp] declare ga_comm___XPlus___139 [simp] declare ga_assoc___XPlus___135 [simp] declare ga_right_unit___XPlus___149 [simp] declare ga_left_unit___XPlus___147 [simp] declare ga_left_comm___XPlus___143 [simp] declare ga_comm___Xx___138 [simp] declare ga_assoc___Xx___134 [simp] declare ga_right_unit___Xx___148 [simp] declare ga_left_unit___Xx___146 [simp] declare ga_left_comm___Xx___142 [simp] declare ga_comm_min_141 [simp] declare ga_comm_max_140 [simp] declare ga_assoc_min_137 [simp] declare ga_assoc_max_136 [simp] declare ga_left_comm_min_145 [simp] declare ga_left_comm_max_144 [simp] declare divide_def1_Rat [simp] declare power_0_Rat [simp] declare AbsSignumLaw [simp] declare IPN05 [simp] declare IPN06 [simp] declare IPN07 [simp] declare INN01 [simp] declare INN02 [simp] declare INN03 [simp] declare INN05 [simp] declare INN07 [simp] declare IIN05 [simp] declare IIN09 [simp] declare IRN05 [simp] declare TakeNegative [simp] declare TakeNil [simp] declare DropNegative [simp] declare DropNil [simp] declare Sum'Nil [simp] declare Prod'Nil [simp] theorem LengthNil1 : "ALL (xs :: 'a List). length'(xs) = (X_gn_inj :: X_Nat => X_Int) 0'' = (xs = Nil')" apply(auto) apply(case_tac xs) apply(auto) apply(simp add: LengthCons) oops setup "Header.record \"LengthNil1\"" theorem LengthEqualNil : "ALL (ys :: 'b List). length'(Nil') = length'(ys) --> ys = Nil'" apply(auto) apply(simp add: LengthNil) oops setup "Header.record \"LengthEqualNil\"" theorem LengthEqualCons : "ALL (x :: 'a). ALL (xs :: 'a List). ALL (y :: 'b). ALL (ys :: 'b List). length'(X_Cons x xs) = length'(X_Cons y ys) --> length'(xs) = length'(ys)" apply(auto) apply(simp add: LengthCons) oops setup "Header.record \"LengthEqualCons\"" theorem ZipSpec : "ALL (xs :: 'a List). ALL (ys :: 'b List). length'(xs) = length'(ys) --> unzip(X_zip xs ys) = (xs, ys)" apply(auto) apply(induct_tac xs, induct_tac ys) apply(auto) oops setup "Header.record \"ZipSpec\"" end
Dry Skin Giving You The Winter Blues? I know everyone thinks that living in sunny South Florida prevents us from suffering during the winter. We do have a lot of warm days in comparison to the rest of the U.S., but no sooner am I preparing for Thanksgiving, does the moisture from my skin begin to deplete. Luckily I have my favorite duo of body products to rescue me! For years, I've been using Neutrogena Rainbath ($7.99) refreshing shower and bath gel. It's gentle enough to use year-round no matter how sensitive my skin is, and the fresh fragrance turns my shower into my own personal spa. Speaking of the scent, unlike its fruity and floral counterparts, Rainbath can be enjoyed by both men and women. After indulging in a warm shower, put some Neutrogena Body Oil ($9.99) on your hands and rehydrate your body with its light sesame formula. At first you might worry, as I did, that it would leave a greasy mess. But it's powerful enough to bring your skin back to life without leaving behind any evidence. *Disclosure: I received these products for review, but all thoughts are my own. To be honest, I used these to re-stock my own personal supply!
function handles = togglePlotData(hObject, handles, state) set(handles.btnPlotData, 'Enable', state); if isequal(handles.foundExportFig, 1) set(handles.btnPlotDataSave, 'Enable', state); end guidata(hObject, handles);
theory Percentage imports HOL.Real begin section\<open>Implementation Detail: Percentage Type\<close> (*thx pruvisto!*) typedef percentage = \<open>{0..(1::real)}\<close> morphisms real_of_percentage Abs_percentage by auto setup_lifting type_definition_percentage instantiation percentage :: \<open>zero\<close> begin lift_definition zero_percentage :: \<open>percentage\<close> is \<open>0 :: real\<close> by auto instance .. end instantiation percentage :: \<open>monoid_mult\<close> begin lift_definition one_percentage :: \<open>percentage\<close> is \<open>1 :: real\<close> by auto lift_definition times_percentage :: \<open>percentage \<Rightarrow> percentage \<Rightarrow> percentage\<close> is \<open>(*) :: real \<Rightarrow> _\<close> by (auto simp: mult_le_one) instance by standard (transfer; simp; fail)+ end text\<open>A \<^term>\<open>Abs_percentage 0.1\<close> would give a "Abstraction violation" in a value command. So here is some magic to make code work.\<close> definition percentage :: \<open>real \<Rightarrow> percentage\<close> where \<open>percentage p \<equiv> if p \<le> 0 then 0 else if p \<ge> 1 then 1 else Abs_percentage p\<close> lemma percentage_code [code abstract]: \<open>real_of_percentage (percentage p) = (if p \<le> 0 then 0 else if p \<ge> 1 then 1 else p)\<close> unfolding percentage_def by (simp add: Abs_percentage_inverse one_percentage.rep_eq zero_percentage.rep_eq) value[code] \<open>percentage 0.1\<close> (*no longer an error*) lemma \<open>real_of_percentage (percentage 0.1) * (25::real) = 2.5\<close> by eval lemma \<open>(25::real) * real_of_percentage (percentage 0.1) = 2.5\<close> by eval text\<open>And now we get rid of explicit calls to \<^const>\<open>real_of_percentage\<close>\<close> declare [[coercion \<open>real_of_percentage :: percentage \<Rightarrow> real\<close>]] lemma \<open>(percentage 0.1) * (25::real) = 2.5\<close> by eval lemma \<open>(25::real) * (percentage 0.1) = 2.5\<close> by eval lemma \<open>(percentage 0.1) * (25::nat) = 2.5\<close> by eval lemma \<open>(25::nat) * (percentage 0.1) = 2.5\<close> by eval lemma percentage_range: fixes p :: \<open>percentage\<close> shows \<open>0 \<le> p \<and> p \<le> 1\<close> using real_of_percentage by auto lemma real_of_percentage_range: \<open>0 \<le> real_of_percentage p\<close> \<open>real_of_percentage p \<le> 1\<close> by(simp add: percentage_range)+ (*will cause simplifier looping*) lemma percentage_min_max_simps: \<open>real_of_percentage p = min 1 p\<close> \<open>real_of_percentage p = max 0 p\<close> by (simp add: percentage_range)+ lemma real_of_percentage_mult: \<open>real a * real_of_percentage p \<le> a\<close> \<open>real_of_percentage p * real a \<le> a\<close> by (simp add: mult.commute mult_left_le percentage_range)+ lemma percentage_percentage_mult_right: fixes a p ::\<open>percentage\<close> shows \<open>a * p \<le> a\<close> by (simp add: mult_right_le_one_le real_of_percentage_range times_percentage.rep_eq) lemma percentage_percentage_mult_left: fixes a p ::\<open>percentage\<close> shows \<open>p * a \<le> a\<close> by (simp add: mult.commute percentage_percentage_mult_right mult_right_le_one_le percentage_range times_percentage.rep_eq) lemma percentage_real_pos_mult_right: \<open>a \<ge> 0 \<Longrightarrow> a * real_of_percentage p \<le> a\<close> by (simp add: mult_left_le percentage_range) lemma percentage_real_pos_mult_left: \<open>a \<ge> 0 \<Longrightarrow> real_of_percentage p * a \<le> a\<close> by (simp add: mult_left_le_one_le percentage_range) lemma percentage_mult_right_mono: fixes a b p :: \<open>percentage\<close> shows \<open>a \<le> b \<Longrightarrow> a * p \<le> b * p\<close> by transfer (simp add: mult_right_mono) lemma percentage_real_mult_right_mono: fixes p :: \<open>percentage\<close> and a b :: \<open>real\<close> shows \<open>a \<le> b \<Longrightarrow> a * p \<le> b * p\<close> by transfer (simp add: mult_right_mono) lemma percentage_real_diff_mult_right_mono: \<open>a \<le> b \<Longrightarrow> a - a * (real_of_percentage p) \<le> b - b * (real_of_percentage p)\<close> proof - assume a: \<open>a \<le> b\<close> have \<open>0 \<le> b - a\<close> by (simp add: a) hence \<open>(b - a) * real_of_percentage p \<le> b - a\<close> by (simp add: percentage_real_pos_mult_right) with a show \<open>?thesis\<close> by (simp add: a left_diff_distrib') qed lemma percentage_nat_diff_mult_right_mono: (*warning: coertion*) fixes p :: \<open>percentage\<close> and a b :: \<open>nat\<close> shows \<open>(a :: nat) \<le> b \<Longrightarrow> a - a * p \<le> b - b * p\<close> by (simp add: percentage_real_diff_mult_right_mono) lemma percentage_add_limit_helper: \<open>a \<ge> 0 \<Longrightarrow> b \<le> c - a \<Longrightarrow> a * real_of_percentage prozent + b \<le> c\<close> by (metis add.commute le_diff_eq order_trans percentage_real_pos_mult_right) end
# 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 #' ResourcePoolBudgetAmountPatchItem Class #' #' @field resourcePoolId #' @field timePeriod #' @field operations #' #' @importFrom R6 R6Class #' @importFrom jsonlite fromJSON toJSON #' @export ResourcePoolBudgetAmountPatchItem <- R6::R6Class( 'ResourcePoolBudgetAmountPatchItem', public = list( `resourcePoolId` = NULL, `timePeriod` = NULL, `operations` = NULL, initialize = function(`resourcePoolId`, `timePeriod`, `operations`){ if (!missing(`resourcePoolId`)) { stopifnot(is.character(`resourcePoolId`), length(`resourcePoolId`) == 1) self$`resourcePoolId` <- `resourcePoolId` } if (!missing(`timePeriod`)) { stopifnot(R6::is.R6(`timePeriod`)) self$`timePeriod` <- `timePeriod` } if (!missing(`operations`)) { stopifnot(R6::is.R6(`operations`)) self$`operations` <- `operations` } }, toJSON = function() { ResourcePoolBudgetAmountPatchItemObject <- list() if (!is.null(self$`resourcePoolId`)) { ResourcePoolBudgetAmountPatchItemObject[['resourcePoolId']] <- self$`resourcePoolId` } if (!is.null(self$`timePeriod`)) { ResourcePoolBudgetAmountPatchItemObject[['timePeriod']] <- self$`timePeriod`$toJSON() } if (!is.null(self$`operations`)) { ResourcePoolBudgetAmountPatchItemObject[['operations']] <- self$`operations`$toJSON() } ResourcePoolBudgetAmountPatchItemObject }, fromJSON = function(ResourcePoolBudgetAmountPatchItemJson) { ResourcePoolBudgetAmountPatchItemObject <- dlensFromJSON(ResourcePoolBudgetAmountPatchItemJson) if (!is.null(ResourcePoolBudgetAmountPatchItemObject$`resourcePoolId`)) { self$`resourcePoolId` <- ResourcePoolBudgetAmountPatchItemObject$`resourcePoolId` } if (!is.null(ResourcePoolBudgetAmountPatchItemObject$`timePeriod`)) { timePeriodObject <- TimePeriod$new() timePeriodObject$fromJSON(jsonlite::toJSON(ResourcePoolBudgetAmountPatchItemObject$timePeriod, auto_unbox = TRUE)) self$`timePeriod` <- timePeriodObject } if (!is.null(ResourcePoolBudgetAmountPatchItemObject$`operations`)) { operationsObject <- Operations$new() operationsObject$fromJSON(jsonlite::toJSON(ResourcePoolBudgetAmountPatchItemObject$operations, auto_unbox = TRUE)) self$`operations` <- operationsObject } }, toJSONString = function() { sprintf( '{ "resourcePoolId": %s, "timePeriod": %s, "operations": %s }', self$`resourcePoolId`, self$`timePeriod`$toJSON(), self$`operations`$toJSON() ) }, fromJSONString = function(ResourcePoolBudgetAmountPatchItemJson) { ResourcePoolBudgetAmountPatchItemObject <- dlensFromJSON(ResourcePoolBudgetAmountPatchItemJson) self$`resourcePoolId` <- ResourcePoolBudgetAmountPatchItemObject$`resourcePoolId` TimePeriodObject <- TimePeriod$new() self$`timePeriod` <- TimePeriodObject$fromJSON(jsonlite::toJSON(ResourcePoolBudgetAmountPatchItemObject$timePeriod, auto_unbox = TRUE)) OperationsObject <- Operations$new() self$`operations` <- OperationsObject$fromJSON(jsonlite::toJSON(ResourcePoolBudgetAmountPatchItemObject$operations, auto_unbox = TRUE)) } ) )
import data.polynomial import missing_mathlib.ring_theory.algebra universe variables u v w namespace polynomial variables {α : Type u} {β : Type v} open polynomial lemma leading_coeff_X_add_C {α : Type v} [integral_domain α] [decidable_eq α] (a b : α) (ha : a ≠ 0): leading_coeff (C a * X + C b) = a := begin rw [add_comm, leading_coeff_add_of_degree_lt], { simp }, { simp [degree_C ha], apply lt_of_le_of_lt degree_C_le (with_bot.coe_lt_coe.2 zero_lt_one)} end end polynomial section eval₂ variables {α : Type u} {β : Type v} [comm_ring α] [decidable_eq α] [semiring β] variables (f : α →+* β) (x : β) (p q : polynomial α) open is_semiring_hom open polynomial finsupp finset lemma eval₂_mul_noncomm (hf : ∀ b a, a * f b = f b * a) : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x := begin dunfold eval₂, rw [add_monoid_algebra.mul_def, finsupp.sum_mul _ p], simp only [finsupp.mul_sum _ q], rw [sum_sum_index], { apply sum_congr rfl, assume i hi, dsimp only, rw [sum_sum_index], { apply sum_congr rfl, assume j hj, dsimp only, rw [sum_single_index, is_semiring_hom.map_mul f, pow_add], { rw [mul_assoc, ←mul_assoc _ (x ^ i), ← hf _ (x ^ i)], simp only [mul_assoc] }, { rw [is_semiring_hom.map_zero f, zero_mul] } }, { intro, rw [is_semiring_hom.map_zero f, zero_mul] }, { intros, rw [is_semiring_hom.map_add f, add_mul] } }, { intro, rw [is_semiring_hom.map_zero f, zero_mul] }, { intros, rw [is_semiring_hom.map_add f, add_mul] } end end eval₂ lemma finsupp_sum_eq_eval₂ (α : Type v) (β : Type w) [decidable_eq α] [comm_ring α] [decidable_eq β] [add_comm_group β] [module α β] (f : β →ₗ[α] β) (v : β) (p : polynomial α) : (finsupp.sum p (λ n b, b • (f ^ n) v)) = polynomial.eval₂ (algebra_map α (β →ₗ[α] β)) f p v := begin dunfold polynomial.eval₂ finsupp.sum, convert @finset.sum_hom _ _ _ _ _ p.support _ (λ h : β →ₗ[α] β, h v) _, simp [module.endomorphism_algebra_map_apply] end lemma eval₂_prod_noncomm {α β : Type*} [comm_ring α] [decidable_eq α] [semiring β] (f : α →+* β) (hf : ∀ b a, a * f b = f b * a) (x : β) (ps : list (polynomial α)) : polynomial.eval₂ f x ps.prod = (ps.map (λ p, (polynomial.eval₂ f x p))).prod := begin induction ps, simp, simp [eval₂_mul_noncomm f _ _ _ hf, ps_ih] {contextual := tt} end
From Undecidability Require Import TM.Util.TM_facts. Set Default Goal Selector "!". (* * Tactics that help verifying complex machines *) Ltac destruct_param_tape_pair := once lazymatch goal with | [ x : _ * tapes _ _ |- _] => let ymid := fresh "ymid" in let tmid := fresh "tmid" in destruct x as (ymid&tmid) end. Ltac destruct_unit := repeat once lazymatch goal with | [ x : unit |- _ ] => destruct x end. Fixpoint all_vec {X:Type} {n:nat} {struct n}: (Vector.t X n -> Prop) -> Prop := match n with 0 => fun A => A (@Vector.nil _) | S n => fun A => forall x, all_vec (fun xs => A (x:::xs)) end. Lemma all_vec_correct {X:Type} {n:nat} (P : Vector.t X n -> Prop): all_vec P -> forall xs, P xs. Proof. revert P. induction n;cbn;intros. - now apply Vector.case0. - intros. apply Vector.caseS'. intro. now eapply IHn. Qed. Lemma all_vec_correct2 {X:Type} {n:nat} (P : Vector.t X n -> Prop): (forall xs, P xs) -> all_vec P. Proof. revert P. induction n;cbn;intros. - now apply Vector.case0. - eauto. Qed. Tactic Notation "vector_destruct" hyp(tin) := let rec introT n := once lazymatch n with | S ?n => let x := fresh tin "_0" in intro x;introT n | 0 => try clear tin | _ => simple apply all_vec_correct2;try clear tin;let tin' := fresh tin in intros tin' end in let tac n := revert dependent tin; refine (all_vec_correct _); cbn [all_vec];introT n;cbn [Vector.nth Vector.caseS];intros in once lazymatch type of tin with tapes _ ?n => tac n | Vector.t _ ?n => tac n end. Lemma eq_nth_iff' X n (v w : Vector.t X n): (forall i : Fin.t n, v[@i] = w[@i]) -> v = w. Proof. intros. eapply Vector.eq_nth_iff. now intros ? ? ->. Qed. Lemma list_cons_inj {X : Type} {x1 x2 : X} {l1 l2 : list X} : x1 :: l1 = x2 :: l2 -> x1 = x2 /\ l1 = l2. Proof. intros H. now inversion H. Qed. Lemma Some_inj {X : Type} {x1 x2 : X} : Some x1 = Some x2 -> x1 = x2. Proof. intros H. now inversion H. Qed. Ltac TMSimp1 T := try destruct_param_tape_pair; destruct_unit; (*simpl_not_in;*) cbn in *; repeat match goal with | [ H : ?x = _ |- _ ] => is_var x;move x at bottom;subst x | [ H : _ = ?x |- _ ] => is_var x;move x at bottom;symmetry in H;subst x | [ H : (forall i : Fin.t _, _[@i] = _[@i]) |- _ ] => apply eq_nth_iff' in H end; unfold finType_CS in *; try T; repeat once lazymatch goal with | [ x : unit |- _ ] => destruct x | [ H : _ ::: _ = [| |] |- _ ] => discriminate H | [ H : [| |] = _ ::: _ |- _ ] => discriminate H | [ H : _ ::: _ = _ ::: _ |- _ ] => apply VectorSpec.cons_inj in H | [ H : _ :: _ = [] |- _ ] => discriminate H | [ H : [] = _ :: _ |- _ ] => discriminate H | [ H : _ :: _ = _ :: _ |- _ ] => apply list_cons_inj in H | [ H : Some _ = Some _ |- _ ] => apply Some_inj in H; subst | [ H : None = Some _ |- _ ] => discriminate H | [ H : Some _ = None |- _ ] => discriminate H | [ H : _ /\ _ |- _] => destruct H | [ H : @ex ?A ?P |- _] => once lazymatch A with | tapes _ _ => let tmid := fresh "tmid" in destruct H as (tmid&H) | _ => (* probably some label *) let ymid := fresh "ymid" in destruct H as (ymid&H) end | [ x : _ * _ |- _ ] => destruct x | [ H : ?x = _ |- _ ] => is_var x;subst x | [ H : _ = ?x |- _ ] => is_var x;symmetry in H;subst x end. Ltac TMSimp2 := let tac ts n := once lazymatch n with S _ => vector_destruct ts end in once match goal with | [ ts: tapes _ ?n|- _ ] => tac ts n | [ ts: Vector.t _ ?n|- _ ] => tac ts n | [H : @Vector.nil _ = @Vector.nil _ |-_ ] => clear H end. Tactic Notation "TMSimp" tactic(T) := repeat progress (repeat progress TMSimp1 T; repeat TMSimp2; unlock all). Tactic Notation "TMSimp" := TMSimp idtac.
------------------------------------------------------------------------ -- Definitional interpreters can model systems with unbounded space ------------------------------------------------------------------------ -- As a follow-up to the development in Bounded-space I asked Ancona, -- Dagnino and Zucca for further examples of properties for which it -- is not clear to them if definitional interpreters work well. They -- asked for a semantics that returns the largest heap size used by -- the program, or infinity if there is no bound on this size. They -- also asked how one can prove that a program transformation does not -- increase the maximum heap usage. -- It is impossible to write an Agda program that computes the maximum -- heap usage, but one can at least produce a potentially infinite -- list containing all heap sizes encountered in the execution of a -- program, and then reason about this list. This approach is taken -- below. module Unbounded-space where open import Equality.Propositional open import Logical-equivalence using (_⇔_) open import Prelude open import Tactic.By.Propositional open import Prelude.Size open import Colist equality-with-J as Colist open import Conat equality-with-J as Conat hiding (pred) renaming (_+_ to _⊕_) open import Function-universe equality-with-J as F hiding (_∘_) open import Nat equality-with-J as Nat using (_≤_; _≤↑_; pred) open import Omniscience equality-with-J open import Only-allocation open import Upper-bounds ------------------------------------------------------------------------ -- Definitional interpreter -- Modifies the heap size according to the given instruction. modify : Stmt → ℕ → ℕ modify alloc = suc modify dealloc = pred -- A definitional interpreter. It returns a trace of all heap sizes -- encountered during the program's run. The input is the initial heap -- size. mutual ⟦_⟧ : ∀ {i} → Program i → ℕ → Colist ℕ i ⟦ p ⟧ h = h ∷ ⟦ p ⟧′ h ⟦_⟧′ : ∀ {i} → Program i → ℕ → Colist′ ℕ i ⟦ [] ⟧′ h .force = [] ⟦ s ∷ p ⟧′ h .force = ⟦ p .force ⟧ (modify s h) ------------------------------------------------------------------------ -- The maximum heap usage predicate -- The smallest heap size that is required to run the given program -- when the initial heap is empty. Heap-usage : Program ∞ → Conat ∞ → Type Heap-usage p n = LUB (⟦ p ⟧ 0) n -- The smallest extra heap size that is required to run the given -- program, for arbitrary initial heaps. Heap-usage′ : Program ∞ → Conat ∞ → Type Heap-usage′ p n = (∀ h → [ ∞ ] ⟦ p ⟧ h ⊑ n ⊕ ⌜ h ⌝) × (∀ n′ → (∀ h → [ ∞ ] ⟦ p ⟧ h ⊑ n′ ⊕ ⌜ h ⌝) → [ ∞ ] n ≤ n′) -- The number n is an upper bound of the heap size required for a -- program when it is started with an empty heap iff, for any initial -- heap h, n plus the size of h is an upper bound. -- -- Note that this kind of property might not hold for a more -- complicated programming language, in which a program's actions -- could depend on the contents of the initial heap. ∀⟦⟧⊑⇔⟦⟧⊑ : ∀ {p n i} → [ i ] ⟦ p ⟧ 0 ⊑ n ⇔ (∀ h → [ i ] ⟦ p ⟧ h ⊑ n ⊕ ⌜ h ⌝) ∀⟦⟧⊑⇔⟦⟧⊑ {p} {n} {i} = record { to = to p ; from = (∀ h → [ i ] ⟦ p ⟧ h ⊑ n ⊕ ⌜ h ⌝) ↝⟨ _$ 0 ⟩ [ i ] ⟦ p ⟧ 0 ⊑ n ⊕ ⌜ 0 ⌝ ↝⟨ flip transitive-⊑≤ (∼→≤ (+-right-identity _)) ⟩□ [ i ] ⟦ p ⟧ 0 ⊑ n □ } where +⊕-cong : ∀ {m₁ m₂ n i} → [ i ] ⌜ m₁ ⌝ ≤ m₂ → [ i ] ⌜ m₁ + n ⌝ ≤ m₂ ⊕ ⌜ n ⌝ +⊕-cong {m₁} {m₂} {n} {i} = [ i ] ⌜ m₁ ⌝ ≤ m₂ ↝⟨ _+-mono reflexive-≤ _ ⟩ [ i ] ⌜ m₁ ⌝ ⊕ ⌜ n ⌝ ≤ m₂ ⊕ ⌜ n ⌝ ↝⟨ transitive-≤ (∼→≤ (⌜⌝-+ m₁)) ⟩□ [ i ] ⌜ m₁ + n ⌝ ≤ m₂ ⊕ ⌜ n ⌝ □ to : ∀ {m i} p → [ i ] ⟦ p ⟧ m ⊑ n → ∀ h → [ i ] ⟦ p ⟧ (m + h) ⊑ n ⊕ ⌜ h ⌝ to [] (m≤n ∷ _) _ = +⊕-cong m≤n ∷ λ { .force → [] } to (s ∷ p) (m≤n ∷ p⊑) h = +⊕-cong m≤n ∷ λ { .force → to′ _ s (force p⊑) } where to′ : ∀ {i} m s → [ i ] ⟦ force p ⟧ (modify s m) ⊑ n → [ i ] ⟦ force p ⟧ (modify s (m + h)) ⊑ n ⊕ ⌜ h ⌝ to′ _ alloc p⊑ = to (force p) p⊑ h to′ (suc m) dealloc p⊑ = to (force p) p⊑ h to′ zero dealloc p⊑ = transitive-⊑≤ (to (force p) p⊑ (pred h)) (reflexive-≤ n +-mono ⌜⌝-mono (Nat.pred≤ _)) -- Heap-usage p n holds iff Heap-usage′ p n holds. For this reason the -- former, less complicated definition will be used below. Heap-usage⇔Heap-usage′ : ∀ p n → Heap-usage p n ⇔ Heap-usage′ p n Heap-usage⇔Heap-usage′ p n = ([ ∞ ] ⟦ p ⟧ 0 ⊑ n ↝⟨ ∀⟦⟧⊑⇔⟦⟧⊑ ⟩□ (∀ h → [ ∞ ] ⟦ p ⟧ h ⊑ n ⊕ ⌜ h ⌝) □) ×-cong ((∀ n′ → [ ∞ ] ⟦ p ⟧ 0 ⊑ n′ → [ ∞ ] n ≤ n′) ↝⟨ ∀-cong _ (λ _ → →-cong _ ∀⟦⟧⊑⇔⟦⟧⊑ F.id) ⟩□ (∀ n′ → (∀ h → [ ∞ ] ⟦ p ⟧ h ⊑ n′ ⊕ ⌜ h ⌝) → [ ∞ ] n ≤ n′) □) -- The maximum heap usage is unique (up to bisimilarity). max-unique : ∀ {p m n i} → Heap-usage p m → Heap-usage p n → Conat.[ i ] m ∼ n max-unique = lub-unique -- Heap-usage p respects bisimilarity. max-respects-∼ : ∀ {p q m n} → Colist.[ ∞ ] ⟦ p ⟧ 0 ∼ ⟦ q ⟧ 0 → Conat.[ ∞ ] m ∼ n → Heap-usage p m → Heap-usage q n max-respects-∼ {p} {q} {m} {n} p∼q m∼n = Σ-map ([ ∞ ] ⟦ p ⟧ 0 ⊑ m ↝⟨ (λ hyp → transitive-⊑≤ (□-∼ p∼q hyp) (∼→≤ m∼n)) ⟩□ [ ∞ ] ⟦ q ⟧ 0 ⊑ n □) ((∀ o → [ ∞ ] ⟦ p ⟧ 0 ⊑ o → [ ∞ ] m ≤ o) ↝⟨ (λ hyp₁ o hyp₂ → transitive-≤ (∼→≤ (Conat.symmetric-∼ m∼n)) (hyp₁ o (□-∼ (Colist.symmetric-∼ p∼q) hyp₂))) ⟩□ (∀ o → [ ∞ ] ⟦ q ⟧ 0 ⊑ o → [ ∞ ] n ≤ o) □) -- If the semantics of a program started in the empty heap does not -- have a finite upper bound, then the maximum heap usage of the -- program is infinity. no-finite-max→infinite-max : ∀ p → (∀ n → ¬ [ ∞ ] ⟦ p ⟧ 0 ⊑ ⌜ n ⌝) → Heap-usage p infinity no-finite-max→infinite-max p hyp = (⟦ p ⟧ 0 ⊑infinity) , λ n′ → [ ∞ ] ⟦ p ⟧ 0 ⊑ n′ ↝⟨ no-finite→infinite hyp ⟩ Conat.[ ∞ ] n′ ∼ infinity ↝⟨ ∼→≤ ∘ Conat.symmetric-∼ ⟩□ [ ∞ ] infinity ≤ n′ □ -- If the maximum heap usage could always be determined (in a certain -- sense), then WLPO (which is a constructive taboo) would hold. max→wlpo : (∀ p → ∃ λ n → Heap-usage p n) → WLPO max→wlpo find-max = λ f → case find-max (p f) of λ where (zero , max-0) → inj₁ (_⇔_.to 0⇔≡false max-0) (suc _ , max-+) → inj₂ (+→≢false max-+) where -- If f takes the value true, then p f contains exactly one -- occurrence of alloc, at the first index for which f takes the -- value true. Otherwise p f contains zero occurrences of alloc. p : ∀ {i} → (ℕ → Bool) → Program i p f = helper (f 0) module P where helper : ∀ {i} → Bool → Program i helper = if_then alloc ∷′ [] else dealloc ∷ λ { .force → p (λ n → f (1 + n)) } -- The maximum heap usage of p f is zero iff f always takes the -- value false. 0⇔≡false : ∀ {f} → Heap-usage (p f) ⌜ 0 ⌝ ⇔ (∀ n → f n ≡ false) 0⇔≡false = record { to = →≡false _ ∘ proj₁ ; from = λ ≡false → ≡false→ _ ≡false Nat.≤-refl , (λ _ _ → zero) } where →≡false : ∀ f → [ ∞ ] ⟦ p f ⟧ 0 ⊑ ⌜ 0 ⌝ → ∀ n → f n ≡ false →≡false f ⟦pf⟧0⊑0 _ = helper _ _ refl ⟦pf⟧0⊑0 where helper : ∀ b n → f 0 ≡ b → [ ∞ ] ⟦ P.helper f b ⟧ 0 ⊑ ⌜ 0 ⌝ → f n ≡ false helper false zero f0≡false = λ _ → f0≡false helper false (suc n) _ = [ ∞ ] ⟦ P.helper f false ⟧ 0 ⊑ ⌜ 0 ⌝ ↝⟨ □-tail ⟩ [ ∞ ] ⟦ p (f ∘ suc) ⟧ 0 ⊑ ⌜ 0 ⌝ ↝⟨ (λ hyp → →≡false (f ∘ suc) hyp n) ⟩□ (f ∘ suc) n ≡ false □ helper true n _ = [ ∞ ] ⟦ P.helper f true ⟧ 0 ⊑ ⌜ 0 ⌝ ↝⟨ □-head ∘ □-tail ⟩ ([ ∞ ] ⌜ 1 ⌝ ≤ ⌜ 0 ⌝) ↝⟨ ⌜⌝-mono⁻¹ ⟩ 1 ≤ 0 ↝⟨ Nat.+≮ 0 ⟩ ⊥ ↝⟨ ⊥-elim ⟩□ f n ≡ false □ ≡false→ : ∀ {m n i} f → (∀ n → f n ≡ false) → m ≤ n → [ i ] ⟦ p f ⟧ m ⊑ ⌜ n ⌝ ≡false→ {m} {n} f ≡false m≤n with f 0 | ≡false 0 ... | true | () ... | false | _ = zero +-mono ⌜⌝-mono m≤n ∷ λ { .force → ≡false→ (f ∘ suc) (≡false ∘ suc) ( pred m Nat.≤⟨ Nat.pred≤ _ ⟩ m Nat.≤⟨ m≤n ⟩∎ n ∎≤) } -- If the maximum heap usage of p f is positive, then f does not -- always take the value false. +→≢false : ∀ {f n} → Heap-usage (p f) (suc n) → ¬ (∀ n → f n ≡ false) +→≢false {f} {n} = Heap-usage (p f) (suc n) ↝⟨ (λ max-+ → Heap-usage (p f) ⌜ 0 ⌝ ↝⟨ max-unique max-+ ⟩ Conat.[ ∞ ] suc n ∼ ⌜ 0 ⌝ ↝⟨ (λ ()) ⟩□ ⊥ □) ⟩ ¬ Heap-usage (p f) ⌜ 0 ⌝ ↝⟨ (λ hyp ≡false → hyp (_⇔_.from 0⇔≡false ≡false)) ⟩□ ¬ (∀ n → f n ≡ false) □ -- In fact, WLPO is logically equivalent to a certain formulation of -- "the maximum heap usage can always be determined". wlpo⇔max : WLPO ⇔ (∀ p → ∃ λ n → Heap-usage p n) wlpo⇔max = record { to = λ wlpo p → wlpo→lub wlpo (⟦ p ⟧ 0) ; from = max→wlpo } -- We also get that WLPO is logically equivalent to a certain -- formulation of "least upper bounds of colists of natural numbers -- can always be determined". wlpo⇔lub : WLPO ⇔ (∀ ms → ∃ λ n → LUB ms n) wlpo⇔lub = record { to = wlpo→lub ; from = λ find-lub → max→wlpo (λ p → find-lub (⟦ p ⟧ 0)) } ------------------------------------------------------------------------ -- Some examples -- When this semantics is used all three programs are non-terminating, -- in the sense that their traces are infinitely long. bounded-loops : ∀ {i n} → Conat.[ i ] length (⟦ bounded ⟧ n) ∼ infinity bounded-loops = suc λ { .force → suc λ { .force → bounded-loops }} bounded₂-loops : ∀ {i n} → Conat.[ i ] length (⟦ bounded₂ ⟧ n) ∼ infinity bounded₂-loops = suc λ { .force → suc λ { .force → suc λ { .force → suc λ { .force → bounded₂-loops }}}} unbounded-loops : ∀ {i n} → Conat.[ i ] length (⟦ unbounded ⟧ n) ∼ infinity unbounded-loops = suc λ { .force → unbounded-loops } -- Zero is not an upper bound of the semantics of bounded when it is -- started with an empty heap. ⟦bounded⟧⋢0 : ¬ [ ∞ ] ⟦ bounded ⟧ 0 ⊑ ⌜ 0 ⌝ ⟦bounded⟧⋢0 = [ ∞ ] ⟦ bounded ⟧ 0 ⊑ ⌜ 0 ⌝ ↝⟨ □-head ∘ □-tail ⟩ [ ∞ ] ⌜ 1 ⌝ ≤ ⌜ 0 ⌝ ↝⟨ ⌜⌝-mono⁻¹ ⟩ (1 ≤ 0) ↝⟨ Nat.+≮ 0 ⟩□ ⊥ □ -- However, one is. ⟦bounded⟧⊑1 : ∀ {i} → [ i ] ⟦ bounded ⟧ 0 ⊑ ⌜ 1 ⌝ ⟦bounded⟧⊑1 = ≤suc ∷ λ { .force → reflexive-≤ _ ∷ λ { .force → ⟦bounded⟧⊑1 }} -- The maximum heap usage of bounded is 1. max-bounded-1 : Heap-usage bounded ⌜ 1 ⌝ max-bounded-1 = ⟦bounded⟧⊑1 , λ n′ → [ ∞ ] ⟦ bounded ⟧ 0 ⊑ n′ ↝⟨ □-head ∘ □-tail ⟩□ [ ∞ ] ⌜ 1 ⌝ ≤ n′ □ -- Two is an upper bound of the semantics of bounded₂ when it is -- started in an empty heap. ⟦bounded₂⟧⊑2 : ∀ {i} → [ i ] ⟦ bounded₂ ⟧ 0 ⊑ ⌜ 2 ⌝ ⟦bounded₂⟧⊑2 = zero ∷ λ { .force → suc (λ { .force → zero }) ∷ λ { .force → reflexive-≤ _ ∷ λ { .force → suc (λ { .force → zero }) ∷ λ { .force → ⟦bounded₂⟧⊑2 }}}} -- The maximum heap usage of bounded₂ is 2. max-bounded₂-2 : Heap-usage bounded₂ ⌜ 2 ⌝ max-bounded₂-2 = ⟦bounded₂⟧⊑2 , λ n′ → [ ∞ ] ⟦ bounded₂ ⟧ 0 ⊑ n′ ↝⟨ □-head ∘ □-tail ∘ □-tail ⟩□ [ ∞ ] ⌜ 2 ⌝ ≤ n′ □ -- There is no finite upper bound of the semantics of unbounded. ⟦unbounded⟧⋢⌜⌝ : ∀ {n} → ¬ [ ∞ ] ⟦ unbounded ⟧ 0 ⊑ ⌜ n ⌝ ⟦unbounded⟧⋢⌜⌝ {n} = helper (Nat.≤→≤↑ (Nat.zero≤ _)) where helper : ∀ {h} → h ≤↑ 1 + n → ¬ [ ∞ ] ⟦ unbounded ⟧ h ⊑ ⌜ n ⌝ helper (Nat.≤↑-refl refl) = [ ∞ ] ⟦ unbounded ⟧ (1 + n) ⊑ ⌜ n ⌝ ↝⟨ □-head ⟩ [ ∞ ] ⌜ 1 + n ⌝ ≤ ⌜ n ⌝ ↝⟨ ⌜⌝-mono⁻¹ ⟩ (1 + n ≤ n) ↝⟨ Nat.+≮ 0 ⟩□ ⊥ □ helper {h} (Nat.≤↑-step 1+h≤1+n) = [ ∞ ] ⟦ unbounded ⟧ h ⊑ ⌜ n ⌝ ↝⟨ □-tail ⟩ [ ∞ ] ⟦ unbounded ⟧ (1 + h) ⊑ ⌜ n ⌝ ↝⟨ helper 1+h≤1+n ⟩□ ⊥ □ -- The maximum heap usage of unbounded is infinity. max-unbounded-∞ : Heap-usage unbounded infinity max-unbounded-∞ = no-finite-max→infinite-max unbounded λ _ → ⟦unbounded⟧⋢⌜⌝ ------------------------------------------------------------------------ -- A simple optimiser -- An optimiser that replaces subsequences of the form "alloc, alloc, -- dealloc" with "alloc". opt : ∀ {i} → Program ∞ → Program i opt [] = [] opt (dealloc ∷ p) = dealloc ∷ λ { .force → opt (p .force) } opt {i} (alloc ∷ p) = opt₁ (p .force) module Opt where default : Program i default = alloc ∷ λ { .force → opt (p .force) } opt₂ : Program ∞ → Program i opt₂ (dealloc ∷ p″) = alloc ∷ λ { .force → opt (p″ .force) } opt₂ _ = default opt₁ : Program ∞ → Program i opt₁ (alloc ∷ p′) = opt₂ (p′ .force) opt₁ _ = default -- The semantics of opt bounded₂ matches that of bounded. opt-bounded₂∼bounded : ∀ {i n} → Colist.[ i ] ⟦ opt bounded₂ ⟧ n ∼ ⟦ bounded ⟧ n opt-bounded₂∼bounded = refl ∷ λ { .force → refl ∷ λ { .force → opt-bounded₂∼bounded }} -- Sometimes the optimised program's maximum heap usage is less than -- that of the original program. opt-improves : ∃ λ p → Heap-usage p ⌜ 2 ⌝ × Heap-usage (opt p) ⌜ 1 ⌝ opt-improves = bounded₂ , max-bounded₂-2 , max-respects-∼ (Colist.symmetric-∼ opt-bounded₂∼bounded) (_ ∎∼) max-bounded-1 -- The optimised program's maximum heap usage is at most as large as -- that of the original program (assuming that these maximums exist). mutual opt-correct : ∀ {i m n} p → Heap-usage (opt p) m → Heap-usage p n → [ i ] m ≤ n opt-correct p max₁ max₂ = _⇔_.to (≲⇔least-upper-bounds-≤ max₁ max₂) (opt-correct-≲ p) opt-correct-≲ : ∀ {h i} p → [ i ] ⟦ opt p ⟧ h ≲ ⟦ p ⟧ h opt-correct-≲ {h} [] = ⟦ opt [] ⟧ h ∼⟨ ∷∼∷′ ⟩≲ h ∷′ [] ∼⟨ Colist.symmetric-∼ ∷∼∷′ ⟩□≲ ⟦ [] ⟧ h opt-correct-≲ {h} (dealloc ∷ p) = ⟦ opt (dealloc ∷ p) ⟧ h ∼⟨ ∷∼∷′ ⟩≲ h ∷′ ⟦ opt (p .force) ⟧ (pred h) ≲⟨ (cons′-≲ λ { hyp .force → opt-correct-≲ (p .force) hyp }) ⟩ h ∷′ ⟦ p .force ⟧ (pred h) ∼⟨ Colist.symmetric-∼ ∷∼∷′ ⟩□≲ ⟦ dealloc ∷ p ⟧ h opt-correct-≲ {h} (alloc ∷ p) = ⟦ opt (alloc ∷ p) ⟧ h ≡⟨⟩≲ ⟦ Opt.opt₁ p (p .force) ⟧ h ≲⟨ opt-correct₁ _ refl ⟩ h ∷′ ⟦ p .force ⟧ (1 + h) ∼⟨ Colist.symmetric-∼ ∷∼∷′ ⟩□≲ ⟦ alloc ∷ p ⟧ h where default-correct : ∀ {p′ i} → p′ ≡ p .force → [ i ] ⟦ Opt.default p ⟧ h ≲ h ∷′ ⟦ p′ ⟧ (1 + h) default-correct refl = ⟦ Opt.default p ⟧ h ∼⟨ ∷∼∷′ ⟩≲ h ∷′ ⟦ opt (p .force) ⟧ (1 + h) ≲⟨ (cons′-≲ λ { hyp .force → opt-correct-≲ (p .force) hyp }) ⟩□ h ∷′ ⟦ p .force ⟧ (1 + h) opt-correct₁ : ∀ {i} p′ → p′ ≡ p .force → [ i ] ⟦ Opt.opt₁ p p′ ⟧ h ≲ h ∷′ ⟦ p′ ⟧ (1 + h) opt-correct₁ [] []≡ = default-correct []≡ opt-correct₁ (dealloc ∷ p′) d∷≡ = default-correct d∷≡ opt-correct₁ (alloc ∷ p′) a∷≡ = ⟦ Opt.opt₂ p (p′ .force) ⟧ h ≲⟨ opt-correct₂ (p′ .force) refl ⟩ h ∷′ 1 + h ∷′ ⟦ p′ .force ⟧ (2 + h) ∼⟨ (refl ∷ λ { .force → Colist.symmetric-∼ ∷∼∷′ }) ⟩□≲ h ∷′ ⟦ alloc ∷ p′ ⟧ (1 + h) where default-correct′ : ∀ {i p″} → p″ ≡ p′ .force → [ i ] ⟦ Opt.default p ⟧ h ≲ h ∷′ 1 + h ∷′ ⟦ p″ ⟧ (2 + h) default-correct′ refl = ⟦ Opt.default p ⟧ h ≲⟨ default-correct refl ⟩ h ∷′ ⟦ p .force ⟧ (1 + h) ≡⟨ by a∷≡ ⟩≲ h ∷′ ⟦ alloc ∷ p′ ⟧ (1 + h) ∼⟨ (refl ∷ λ { .force → ∷∼∷′ }) ⟩□≲ h ∷′ 1 + h ∷′ ⟦ p′ .force ⟧ (2 + h) opt-correct₂ : ∀ {i} p″ → p″ ≡ p′ .force → [ i ] ⟦ Opt.opt₂ p p″ ⟧ h ≲ h ∷′ 1 + h ∷′ ⟦ p″ ⟧ (2 + h) opt-correct₂ [] []≡ = default-correct′ []≡ opt-correct₂ (alloc ∷ p″) a∷≡ = default-correct′ a∷≡ opt-correct₂ (dealloc ∷ p″) _ = ⟦ Opt.opt₂ p (dealloc ∷ p″) ⟧ h ∼⟨ ∷∼∷′ ⟩≲ h ∷′ ⟦ opt (p″ .force) ⟧ (1 + h) ≲⟨ (cons′-≲ λ { hyp .force → opt-correct-≲ (p″ .force) hyp }) ⟩ h ∷′ ⟦ p″ .force ⟧ (1 + h) ≲⟨ (cons′-≲ λ { hyp .force → consʳ-≲ (consʳ-≲ (_ □≲)) hyp }) ⟩ h ∷′ 1 + h ∷′ 2 + h ∷′ ⟦ p″ .force ⟧ (1 + h) ∼⟨ (refl ∷ λ { .force → refl ∷ λ { .force → Colist.symmetric-∼ ∷∼∷′ } }) ⟩□≲ h ∷′ 1 + h ∷′ ⟦ dealloc ∷ p″ ⟧ (2 + h)
```python import numpy as np import sympy as sm sm.init_printing() ``` ```python epsilon = 1.0 state_energies = np.array([0, 1, 1, 1])*epsilon ``` ```python def ways(state_energies, T, kB, numpy=True): if numpy: return np.exp(-state_energies/ (kB*T)) else: return [sm.exp(-e / (kB*T)) for e in state_energies] ``` ```python w = ways(state_energies, T=1, kB=1) ``` ```python def probabilities(state_energies, T, kB, numpy=True): w = ways(state_energies, T, kB, numpy) if numpy: return w / sum(w) else: total_ways = sum(w) return [way/total_ways for way in w] ``` ```python probabilities(state_energies, 1, kB=1) ``` array([0.47536689, 0.1748777 , 0.1748777 , 0.1748777 ]) ```python epsilon, k_B, T = sm.symbols('epsilon k_B T', positive=True) i = sm.symbols('i', integer=True, nonnegative=True) se = [0, epsilon, epsilon, epsilon] ``` ```python probabilities(se, T, k_B, False) ``` ```python def ways_levels(level_energies, level_degeneracies, T, kB, numpy=True): if numpy: return np.exp(-level_energies/ (kB*T))*level_degeneracies else: return [g*sm.exp(-e / (kB*T)) for e, g in zip(level_energies, level_degeneracies)] ``` ```python wl = ways_levels(sm.sequence(i*(i+1)*epsilon, (i, 0, 10)), sm.sequence(2*i+1, (i, 0, 10)), T, k_B, False) ``` ```python def probabilities_levels(level_energies, level_degeneracies, T, kB, numpy=True): w = ways_levels(state_energies, level_degeneracies, T, kB, numpy) if numpy: return w / sum(w) else: total_ways = sum(w) return [way/total_ways for way in w] ``` ```python probabilities_levels() ```
import sheaves.sheaf Kenny.sandbox universes v w u₁ v₁ u open topological_space lattice namespace opens variables {X : Type u} [topological_space X] theorem Inf_eq (s : set (opens X)) : Inf s = opens.interior (Inf $ subtype.val '' s) := le_antisymm ((subset_interior_iff_subset_of_open (Inf s).2).2 $ show (Inf s).1 ≤ Inf (subtype.val '' s), from le_Inf $ λ t ⟨u, hus, hut⟩, le_trans interior_subset $ Inf_le ⟨u, show Inf (set.range (λ (H : u ∈ s), u.val)) = t, from le_antisymm (Inf_le ⟨hus, hut⟩) (le_Inf $ λ b ⟨c, hc⟩, hc ▸ ge_of_eq hut)⟩) (le_Inf $ λ U hus, set.subset.trans interior_subset $ show Inf (subtype.val '' s) ≤ U.1, from Inf_le $ set.mem_image_of_mem _ hus) theorem inter_val (U V : opens X) : (U ∩ V).1 = U.1 ∩ V.1 := rfl theorem inf_val (U V : opens X) : (U ⊓ V).1 = U.1 ∩ V.1 := rfl theorem inf_Sup (U : opens X) (s : set (opens X)) : U ⊓ Sup s = Sup ((⊓) U '' s) := opens.ext $ by rw [inf_val, opens.Sup_s, opens.Sup_s, set.sUnion_eq_Union, set.inter_Union, ← set.image_comp]; exact set.subset.antisymm (set.Union_subset $ λ ⟨t, i, his, hit⟩, set.subset_sUnion_of_mem ⟨i, his, congr_arg ((∩) U.1) hit⟩) (set.sUnion_subset $ λ t ⟨i, his, hit⟩, set.subset_sUnion_of_mem ⟨⟨i.1, i, his, rfl⟩, hit⟩) def covering_inf_left (U V : opens X) (OC : covering U) : covering (V ⊓ U) := { γ := OC.γ, Uis := λ i : OC.γ, V ⊓ OC.Uis i, Hcov := by conv_rhs { rw ← OC.Hcov }; rw [supr, supr, inf_Sup]; congr' 1; ext x; exact ⟨λ ⟨i, hix⟩, ⟨OC.Uis i, ⟨i, rfl⟩, hix⟩, λ ⟨_, ⟨i, rfl⟩, hix⟩, ⟨i, hix⟩⟩ } def covering_res (U V : opens X) (H : V ⊆ U) (OC : covering U) : covering V := { γ := OC.γ, Uis := λ i : OC.γ, V ⊓ OC.Uis i, Hcov := by erw [(covering_inf_left U V OC).Hcov, (inf_of_le_left $ show V ≤ U, from H)] } end opens def presheaf.covering (X : Type u) [topological_space X] : presheaf.{u (u+1)} X := { F := covering, res := opens.covering_res, Hid := λ U, funext $ λ OC, by cases OC; dsimp only [opens.covering_res, id]; congr' 1; funext i; apply opens.ext; apply set.inter_eq_self_of_subset_right; rw ← OC_Hcov; apply set.subset_sUnion_of_mem; refine ⟨_, ⟨_, rfl⟩, rfl⟩, Hcomp := λ U V W HWV HVU, funext $ λ OC, by dsimp only [opens.covering_res, function.comp_apply]; congr' 1; funext i; rw [← lattice.inf_assoc, lattice.inf_of_le_left (show W ≤ V, from HWV)] } def sheaf_on_opens (X : Type u) [topological_space X] (U : opens X) : Type (max u (v+1)) := sheaf.{u v} X namespace sheaf_on_opens variables {X : Type u} [topological_space X] {U : opens X} def eval (F : sheaf_on_opens X U) (V : opens X) (HVU : V ≤ U) : Type v := presheaf.F F.to_presheaf V def res (F : sheaf_on_opens X U) (V : opens X) (HVU : V ≤ U) (W : opens X) (HWU : W ≤ U) (HWV : W ≤ V) : F.eval V HVU → F.eval W HWU := presheaf.res _ _ _ HWV theorem res_self (F : sheaf_on_opens X U) (V HVU HV x) : F.res V HVU V HVU HV x = x := presheaf.Hid' _ _ _ theorem res_res (F : sheaf_on_opens X U) (V HVU W HWU HWV S HSU HSW x) : F.res W HWU S HSU HSW (F.res V HVU W HWU HWV x) = F.res V HVU S HSU (le_trans HSW HWV) x := (presheaf.Hcomp' _ _ _ _ _ _ _).symm theorem locality (F : sheaf_on_opens X U) (V HVU s t) (OC : covering V) (H : ∀ i : OC.γ, F.res V HVU (OC.Uis i) (le_trans (subset_covering i) HVU) (subset_covering i) s = F.res V HVU (OC.Uis i) (le_trans (subset_covering i) HVU) (subset_covering i) t) : s = t := F.locality OC s t H noncomputable def glue (F : sheaf_on_opens X U) (V HVU) (OC : covering V) (s : Π i : OC.γ, F.eval (OC.Uis i) (le_trans (subset_covering i) HVU)) (H : ∀ i j : OC.γ, F.res _ _ (OC.Uis i ⊓ OC.Uis j) (le_trans inf_le_left (le_trans (subset_covering i) HVU)) inf_le_left (s i) = F.res _ _ (OC.Uis i ⊓ OC.Uis j) (le_trans inf_le_left (le_trans (subset_covering i) HVU)) inf_le_right (s j)) : F.eval V HVU := classical.some $ F.gluing OC s H theorem res_glue (F : sheaf_on_opens X U) (V HVU) (OC : covering V) (s H i) : F.res V HVU (OC.Uis i) (le_trans (subset_covering i) HVU) (subset_covering i) (F.glue V HVU OC s H) = s i := classical.some_spec (F.gluing OC s H) i theorem eq_glue (F : sheaf_on_opens X U) (V HVU) (OC : covering V) (s : Π i : OC.γ, F.eval (OC.Uis i) (le_trans (subset_covering i) HVU)) (H t) (ht : ∀ i, F.res V HVU (OC.Uis i) (le_trans (subset_covering i) HVU) (subset_covering i) t = s i) : F.glue V HVU OC s H = t := F.locality V HVU _ _ OC $ λ i, by rw [res_glue, ht] def res_subset (F : sheaf_on_opens X U) (V : opens X) (HVU : V ≤ U) : sheaf_on_opens X V := F theorem res_res_subset (F : sheaf_on_opens X U) (V HVU S HSV T HTV HTS x) : (F.res_subset V HVU).res S HSV T HTV HTS x = F.res S (le_trans HSV HVU) T (le_trans HTV HVU) HTS x := rfl def stalk (F : sheaf_on_opens.{v} X U) (x : X) (hx : x ∈ U) : Type (max u v) := stalk F.1 x def to_stalk (F : sheaf_on_opens X U) (x : X) (hx : x ∈ U) (V : opens X) (hxV : x ∈ V) (HVU : V ≤ U) (s : F.eval V HVU) : F.stalk x hx := ⟦⟨V, hxV, s⟩⟧ @[simp] lemma to_stalk_res (F : sheaf_on_opens X U) (x : X) (hx : x ∈ U) (V : opens X) (hxV : x ∈ V) (HVU : V ≤ U) (W : opens X) (hxW : x ∈ W) (HWV : W ≤ V) (s : F.eval V HVU) : F.to_stalk x hx W hxW (le_trans HWV HVU) (F.res _ _ _ _ HWV s) = F.to_stalk x hx V hxV HVU s := quotient.sound ⟨W, hxW, set.subset.refl W.1, HWV, by dsimp only [res]; rw ← presheaf.Hcomp'; refl⟩ @[elab_as_eliminator] theorem stalk.induction_on {F : sheaf_on_opens X U} {x : X} {hx : x ∈ U} {C : F.stalk x hx → Prop} (g : F.stalk x hx) (H : ∀ V : opens X, ∀ hxV : x ∈ V, ∀ HVU : V ≤ U, ∀ s : F.eval V HVU, C (F.to_stalk x hx V hxV HVU s)) : C g := quotient.induction_on g $ λ e, have (⟦e⟧ : F.stalk x hx) = ⟦⟨e.1 ⊓ U, ⟨e.2, hx⟩, F.to_presheaf.res _ _ (set.inter_subset_left _ _) e.3⟩⟧, from quotient.sound ⟨e.1 ⊓ U, ⟨e.2, hx⟩, set.inter_subset_left _ _, set.subset.refl _, by dsimp only; rw ← presheaf.Hcomp'; refl⟩, this.symm ▸ H (e.1 ⊓ U) ⟨e.2, hx⟩ inf_le_right _ structure morphism (F : sheaf_on_opens.{v} X U) (G : sheaf_on_opens.{w} X U) : Type (max u v w) := (map : ∀ V ≤ U, F.eval V H → G.eval V H) (commutes : ∀ (V : opens X) (HV : V ≤ U) (W : opens X) (HW : W ≤ U) (HWV : W ≤ V) (x), map W HW (F.res V HV W HW HWV x) = G.res V HV W HW HWV (map V HV x)) namespace morphism protected def id (F : sheaf_on_opens.{v} X U) : F.morphism F := { map := λ V HV, id, commutes := λ V HV W HW HWV x, rfl } def comp {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} {H : sheaf_on_opens.{u₁} X U} (η : G.morphism H) (ξ : F.morphism G) : F.morphism H := { map := λ V HV x, η.map V HV (ξ.map V HV x), commutes := λ V HV W HW HWV x, by rw [ξ.commutes, η.commutes] } @[simp] lemma comp_apply {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} {H : sheaf_on_opens.{u₁} X U} (η : G.morphism H) (ξ : F.morphism G) (V HV s) : (η.comp ξ).1 V HV s = η.1 V HV (ξ.1 V HV s) := rfl @[ext] lemma ext {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} {η ξ : F.morphism G} (H : ∀ V HV x, η.map V HV x = ξ.map V HV x) : η = ξ := by cases η; cases ξ; congr; ext; apply H @[simp] lemma id_comp {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (η : F.morphism G) : (morphism.id G).comp η = η := ext $ λ V HV x, rfl @[simp] lemma comp_id {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (η : F.morphism G) : η.comp (morphism.id F) = η := ext $ λ V HV x, rfl @[simp] lemma comp_assoc {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} {H : sheaf_on_opens.{u₁} X U} {I : sheaf_on_opens.{v₁} X U} (η : H.morphism I) (ξ : G.morphism H) (χ : F.morphism G) : (η.comp ξ).comp χ = η.comp (ξ.comp χ) := rfl def res_subset {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (η : F.morphism G) (V : opens X) (HVU : V ≤ U) : (F.res_subset V HVU).morphism (G.res_subset V HVU) := { map := λ W HWV, η.map W (le_trans HWV HVU), commutes := λ S HSV T HTV, η.commutes S (le_trans HSV HVU) T (le_trans HTV HVU) } @[simp] lemma res_subset_apply {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (η : F.morphism G) (V : opens X) (HVU : V ≤ U) (W HWV s) : (η.res_subset V HVU).1 W HWV s = η.1 W (le_trans HWV HVU) s := rfl @[simp] lemma comp_res_subset {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} {H : sheaf_on_opens.{u₁} X U} (η : G.morphism H) (ξ : F.morphism G) (V : opens X) (HVU : V ≤ U) : (η.res_subset V HVU).comp (ξ.res_subset V HVU) = (η.comp ξ).res_subset V HVU := rfl @[simp] lemma id_res_subset {F : sheaf_on_opens.{v} X U} (V : opens X) (HVU : V ≤ U) : (morphism.id F).res_subset V HVU = morphism.id (F.res_subset V HVU) := rfl def stalk {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (η : F.morphism G) (x : X) (hx : x ∈ U) (s : F.stalk x hx) : G.stalk x hx := quotient.lift_on s (λ g, ⟦(⟨g.1 ⊓ U, (⟨g.2, hx⟩ : x ∈ g.1 ⊓ U), η.map _ inf_le_right (presheaf.res F.1 _ _ (set.inter_subset_left _ _) g.3)⟩ : stalk.elem _ _)⟧) $ λ g₁ g₂ ⟨V, hxV, HV1, HV2, hg⟩, quotient.sound ⟨V ⊓ U, ⟨hxV, hx⟩, set.inter_subset_inter_left _ HV1, set.inter_subset_inter_left _ HV2, calc G.res _ _ (V ⊓ U) inf_le_right (inf_le_inf HV1 (le_refl _)) (η.map (g₁.U ⊓ U) inf_le_right (F.to_presheaf.res (g₁.U) (g₁.U ⊓ U) (set.inter_subset_left _ _) (g₁.s))) = η.map (V ⊓ U) inf_le_right (F.to_presheaf.res V (V ⊓ U) (set.inter_subset_left _ _) (F.to_presheaf.res (g₁.U) V HV1 (g₁.s))) : by rw [← η.2, res, ← presheaf.Hcomp', ← presheaf.Hcomp'] ... = G.res _ _ (V ⊓ U) _ _ (η.map (g₂.U ⊓ U) inf_le_right (F.to_presheaf.res (g₂.U) (g₂.U ⊓ U) _ (g₂.s))) : by rw [hg, ← η.2, res, ← presheaf.Hcomp', ← presheaf.Hcomp']⟩ @[simp] lemma stalk_to_stalk {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (η : F.morphism G) (x : X) (hx : x ∈ U) (V : opens X) (HVU : V ≤ U) (hxV : x ∈ V) (s : F.eval V HVU) : η.stalk x hx (F.to_stalk x hx V hxV HVU s) = G.to_stalk x hx V hxV HVU (η.map V HVU s) := quotient.sound ⟨V, hxV, set.subset_inter (set.subset.refl _) HVU, set.subset.refl _, calc G.res (V ⊓ U) inf_le_right V HVU (le_inf (le_refl V) HVU) (η.map (V ⊓ U) inf_le_right (F.res V HVU (V ⊓ U) inf_le_right inf_le_left s)) = G.res V HVU V HVU (le_refl V) (η.map V HVU s) : by rw [η.2, res_res]⟩ end morphism structure equiv (F : sheaf_on_opens.{v} X U) (G : sheaf_on_opens.{w} X U) : Type (max u v w) := (to_fun : morphism F G) (inv_fun : morphism G F) (left_inv : ∀ V HVU s, inv_fun.1 V HVU (to_fun.1 V HVU s) = s) (right_inv : ∀ V HVU s, to_fun.1 V HVU (inv_fun.1 V HVU s) = s) namespace equiv def refl (F : sheaf_on_opens.{v} X U) : equiv F F := ⟨morphism.id F, morphism.id F, λ _ _ _, rfl, λ _ _ _, rfl⟩ @[simp] lemma refl_apply (F : sheaf_on_opens.{v} X U) (V HV s) : (refl F).1.1 V HV s = s := rfl def symm {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{v} X U} (e : equiv F G) : equiv G F := ⟨e.2, e.1, e.4, e.3⟩ def trans {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{v} X U} {H : sheaf_on_opens.{u₁} X U} (e₁ : equiv F G) (e₂ : equiv G H) : equiv F H := ⟨e₂.1.comp e₁.1, e₁.2.comp e₂.2, λ _ _ _, by rw [morphism.comp_apply, morphism.comp_apply, e₂.3, e₁.3], λ _ _ _, by rw [morphism.comp_apply, morphism.comp_apply, e₁.4, e₂.4]⟩ @[simp] lemma trans_apply {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{v} X U} {H : sheaf_on_opens.{u₁} X U} (e₁ : equiv F G) (e₂ : equiv G H) (V HV s) : (e₁.trans e₂).1.1 V HV s = e₂.1.1 V HV (e₁.1.1 V HV s) := rfl def res_subset {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (e : equiv F G) (V : opens X) (HVU : V ≤ U) : equiv (F.res_subset V HVU) (G.res_subset V HVU) := ⟨e.1.res_subset V HVU, e.2.res_subset V HVU, λ _ _ _, by rw [morphism.res_subset_apply, morphism.res_subset_apply, e.3], λ _ _ _, by rw [morphism.res_subset_apply, morphism.res_subset_apply, e.4]⟩ @[simp] lemma res_subset_apply {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (e : equiv F G) (V : opens X) (HVU : V ≤ U) (W HW s) : (e.res_subset V HVU).1.1 W HW s = e.1.1 W (le_trans HW HVU) s := rfl def stalk {F : sheaf_on_opens.{v} X U} {G : sheaf_on_opens.{w} X U} (e : equiv F G) (x : X) (hx : x ∈ U) : F.stalk x hx ≃ G.stalk x hx := { to_fun := e.1.stalk x hx, inv_fun := e.2.stalk x hx, left_inv := λ g, stalk.induction_on g $ λ V hxV HVU s, by rw [morphism.stalk_to_stalk, morphism.stalk_to_stalk, e.3], right_inv := λ g, stalk.induction_on g $ λ V hxV HVU s, by rw [morphism.stalk_to_stalk, morphism.stalk_to_stalk, e.4] } end equiv namespace sheaf_glue variables {I : Type u} (S : I → opens X) (F : Π (i : I), sheaf_on_opens.{v} X (S i)) variables (φ : Π (i j : I), equiv ((F i).res_subset ((S i) ⊓ (S j)) inf_le_left) ((F j).res_subset ((S i) ⊓ (S j)) inf_le_right)) variables (Hφ1 : ∀ i, φ i i = equiv.refl (res_subset (F i) (S i ⊓ S i) _)) variables (Hφ2 : ∀ i j k, ((φ i j).res_subset ((S i) ⊓ (S j) ⊓ (S k)) inf_le_left).trans ((φ j k).res_subset ((S i) ⊓ (S j) ⊓ (S k)) (le_inf (le_trans inf_le_left inf_le_right) inf_le_right)) = (φ i k).res_subset ((S i) ⊓ (S j) ⊓ (S k)) (le_inf (le_trans inf_le_left inf_le_left) inf_le_right)) @[reducible] def compat (W : opens X) : Type (max u v) := { f : Π i, (F i).eval ((S i) ⊓ W) inf_le_left // ∀ i j, (φ i j).1.map ((S i) ⊓ (S j) ⊓ W) inf_le_left ((F i).res ((S i) ⊓ W) _ _ (le_trans inf_le_left inf_le_left) (le_inf (le_trans inf_le_left inf_le_left) inf_le_right) (f i)) = (F j).res ((S j) ⊓ W) _ _ (le_trans inf_le_left inf_le_right) (le_inf (le_trans inf_le_left inf_le_right) inf_le_right) (f j) } def res (U V : opens X) (HVU : V ≤ U) (f : compat S F φ U) : compat S F φ V := ⟨λ i, (F i).res (S i ⊓ U) _ (S i ⊓ V) _ (inf_le_inf (le_refl _) HVU) (f.1 i), λ i j, calc (φ i j).1.map (S i ⊓ S j ⊓ V) inf_le_left (res (F i) (S i ⊓ V) inf_le_left (S i ⊓ S j ⊓ V) (le_trans inf_le_left inf_le_left) (le_inf (le_trans inf_le_left inf_le_left) inf_le_right) (res (F i) (S i ⊓ U) inf_le_left (S i ⊓ V) inf_le_left (inf_le_inf (le_refl _) HVU) (f.1 i)) : (F i).eval (S i ⊓ S j ⊓ V) (le_trans _ _)) = (φ i j).1.map (S i ⊓ S j ⊓ V) inf_le_left (res (res_subset (F i) (S i ⊓ S j) inf_le_left) (S i ⊓ S j ⊓ U) inf_le_left (S i ⊓ S j ⊓ V) inf_le_left (inf_le_inf (le_refl _) HVU) (res (F i) (S i ⊓ U) inf_le_left (S i ⊓ S j ⊓ U) (le_trans inf_le_left inf_le_left) (le_inf (le_trans inf_le_left inf_le_left) inf_le_right) (f.1 i) : (F i).eval (S i ⊓ S j ⊓ U) (le_trans inf_le_left inf_le_left))) : by rw [res_res_subset, res_res, res_res] ... = (res (F j) (S j ⊓ V) inf_le_left (S i ⊓ S j ⊓ V) (le_trans inf_le_left inf_le_right) (le_inf (le_trans inf_le_left inf_le_right) inf_le_right) (res (F j) (S j ⊓ U) inf_le_left (S j ⊓ V) inf_le_left (inf_le_inf (le_refl _) HVU) (f.1 j)) : (F j).eval (S i ⊓ S j ⊓ V) _) : by rw [(φ i j).1.commutes, f.2 i j, res_res_subset, res_res, res_res]⟩ theorem locality (U : opens X) (OC : covering U) (s t : sheaf_glue.compat S F φ U) (H : ∀ i : OC.γ, sheaf_glue.res S F φ U (OC.Uis i) (subset_covering i) s = sheaf_glue.res S F φ U (OC.Uis i) (subset_covering i) t) : s = t := subtype.eq $ funext $ λ i, (F i).locality _ _ _ _ (opens.covering_inf_left U (S i) OC) $ λ j, by have := H j; simp only [sheaf_glue.res, subtype.mk.inj_eq] at this; exact congr_fun this i noncomputable def gluing.aux1 (U : opens X) (OC : covering U) (s : Π i : OC.γ, sheaf_glue.compat S F φ (OC.Uis i)) (H : ∀ i j : OC.γ, sheaf_glue.res S F φ _ _ inf_le_left (s i) = sheaf_glue.res S F φ _ _ inf_le_right (s j)) (i : I) : (F i).eval (S i ⊓ U) inf_le_left := (F i).glue _ _ (opens.covering_inf_left U (S i) OC) (λ j, (s j).1 i) $ λ j k, have h1 : S i ⊓ OC.Uis j ⊓ (S i ⊓ OC.Uis k) ≤ S i ⊓ (OC.Uis j ⊓ OC.Uis k), by rw [inf_assoc, inf_left_comm (OC.Uis j), ← inf_assoc, inf_idem]; exact le_refl _, have h2 : S i ⊓ (OC.Uis j ⊓ OC.Uis k) ≤ S i ⊓ OC.Uis j, from inf_le_inf (le_refl _) inf_le_left, have h3 : S i ⊓ (OC.Uis j ⊓ OC.Uis k) ≤ S i ⊓ OC.Uis k, from inf_le_inf (le_refl _) inf_le_right, have (F i).res (S i ⊓ OC.Uis j) _ (S i ⊓ (OC.Uis j ⊓ OC.Uis k)) inf_le_left h2 ((s j).1 i) = (F i).res (S i ⊓ OC.Uis k) _ (S i ⊓ (OC.Uis j ⊓ OC.Uis k)) inf_le_left h3 ((s k).1 i), from congr_fun (congr_arg subtype.val (H j k)) i, calc _ = (F i).res (S i ⊓ OC.Uis j) _ ((S i ⊓ OC.Uis j) ⊓ (S i ⊓ OC.Uis k)) _ _ ((s j).1 i) : rfl ... = (F i).res (S i ⊓ (OC.Uis j ⊓ OC.Uis k)) _ ((S i ⊓ OC.Uis j) ⊓ (S i ⊓ OC.Uis k)) _ h1 ((F i).res (S i ⊓ OC.Uis j) _ (S i ⊓ (OC.Uis j ⊓ OC.Uis k)) inf_le_left h2 ((s j).1 i)) : (res_res _ _ _ _ _ _ _ _ _ _).symm ... = (F i).res (S i ⊓ OC.Uis k) _ ((S i ⊓ OC.Uis j) ⊓ (S i ⊓ OC.Uis k)) _ inf_le_right ((s k).1 i) : by rw [this, res_res] theorem gluing.aux2 (U : opens X) (OC : covering U) (s : Π i : OC.γ, sheaf_glue.compat S F φ (OC.Uis i)) (H : ∀ i j : OC.γ, sheaf_glue.res S F φ _ _ inf_le_left (s i) = sheaf_glue.res S F φ _ _ inf_le_right (s j)) (i j : I) : (φ i j).1.map (S i ⊓ S j ⊓ U) inf_le_left ((F i).res (S i ⊓ U) _ (S i ⊓ S j ⊓ U) (le_trans inf_le_left inf_le_left) (le_inf (le_trans inf_le_left inf_le_left) inf_le_right) (gluing.aux1 S F φ U OC s H i)) = (F j).res (S j ⊓ U) _ (S i ⊓ S j ⊓ U) (le_trans inf_le_left inf_le_right) (by rw inf_assoc; exact inf_le_right) (gluing.aux1 S F φ U OC s H j) := (F j).locality _ _ _ _ (opens.covering_inf_left _ _ OC) $ λ k, calc ((F j).res_subset (S i ⊓ S j) inf_le_right).res (S i ⊓ S j ⊓ U) inf_le_left ((S i ⊓ S j) ⊓ OC.Uis k) inf_le_left (inf_le_inf (le_refl _) (subset_covering k)) ((φ i j).1.map (S i ⊓ S j ⊓ U) inf_le_left ((F i).res (S i ⊓ U) _ (S i ⊓ S j ⊓ U) _ (le_inf (le_trans inf_le_left inf_le_left) inf_le_right) (gluing.aux1 S F φ U OC s H i))) = (φ i j).1.map (S i ⊓ S j ⊓ OC.Uis k) inf_le_left ((F i).res ((opens.covering_inf_left U (S i) OC).Uis k) _ _ (le_trans inf_le_left inf_le_left) (le_inf (le_trans inf_le_left inf_le_left) inf_le_right) ((F i).res (S i ⊓ U) _ ((opens.covering_inf_left U (S i) OC).Uis k) inf_le_left (inf_le_inf (le_refl _) (subset_covering k)) (gluing.aux1 S F φ U OC s H i))) : by rw [← (φ i j).1.commutes, res_res_subset, res_res, res_res] ... = (F j).res ((opens.covering_inf_left U (S j) OC).Uis k) _ ((S i ⊓ S j) ⊓ OC.Uis k) _ (by rw inf_assoc; exact inf_le_right) ((F j).res (S j ⊓ U) _ ((opens.covering_inf_left U (S j) OC).Uis k) inf_le_left (inf_le_inf (le_refl _) (subset_covering k)) (gluing.aux1 S F φ U OC s H j)) : by erw [res_glue, res_glue]; exact (s k).2 i j ... = (F j).res (S i ⊓ S j ⊓ U) _ ((S i ⊓ S j) ⊓ OC.Uis k) _ _ ((F j).res (S j ⊓ U) _ (S i ⊓ S j ⊓ U) _ _ (gluing.aux1 S F φ U OC s H j)) : by rw [res_res, res_res]; refl theorem gluing.aux3 (U : opens X) (OC : covering U) (s : Π i : OC.γ, sheaf_glue.compat S F φ (OC.Uis i)) (H : ∀ i j : OC.γ, sheaf_glue.res S F φ _ _ inf_le_left (s i) = sheaf_glue.res S F φ _ _ inf_le_right (s j)) (i : OC.γ) : sheaf_glue.res S F φ U (OC.Uis i) (subset_covering i) ⟨λ i, gluing.aux1 S F φ U OC s H i, gluing.aux2 S F φ U OC s H⟩ = s i := subtype.eq $ funext $ λ j, by dsimp only [gluing.aux1, sheaf_glue.res]; change (F j).res _ _ ((opens.covering_inf_left U (S j) OC).Uis i) _ _ _ = _; erw res_glue theorem gluing (U : opens X) (OC : covering U) (s : Π i : OC.γ, sheaf_glue.compat S F φ (OC.Uis i)) (H : ∀ i j : OC.γ, sheaf_glue.res S F φ _ _ inf_le_left (s i) = sheaf_glue.res S F φ _ _ inf_le_right (s j)) : ∃ t : sheaf_glue.compat S F φ U, ∀ i : OC.γ, sheaf_glue.res S F φ U (OC.Uis i) (subset_covering i) t = s i := ⟨⟨λ i, gluing.aux1 S F φ U OC s H i, gluing.aux2 S F φ U OC s H⟩, λ i, gluing.aux3 S F φ U OC s H i⟩ end sheaf_glue def sheaf_glue {I : Type u} (S : I → opens X) (F : Π (i : I), sheaf_on_opens.{v} X (S i)) (φ : Π i j, equiv ((F i).res_subset ((S i) ⊓ (S j)) inf_le_left) ((F j).res_subset ((S i) ⊓ (S j)) inf_le_right)) : sheaf_on_opens.{max u v} X (⋃S) := { F := sheaf_glue.compat S F φ, res := sheaf_glue.res S F φ, Hid := λ U, funext $ λ f, subtype.eq $ funext $ λ i, by dsimp only [sheaf_glue.res, id]; rw res_self, Hcomp := λ U V W HWV HVU, funext $ λ f, subtype.eq $ funext $ λ i, by symmetry; apply res_res; exact inf_le_left, locality := sheaf_glue.locality S F φ, gluing := sheaf_glue.gluing S F φ } @[simp] lemma sheaf_glue_res_val {I : Type u} (S : I → opens X) (F : Π (i : I), sheaf_on_opens.{v} X (S i)) (φ : Π i j, equiv ((F i).res_subset ((S i) ⊓ (S j)) inf_le_left) ((F j).res_subset ((S i) ⊓ (S j)) inf_le_right)) (U HU V HV HVU s i) : ((sheaf_glue S F φ).res U HU V HV HVU s).1 i = (F i).res _ _ _ _ (inf_le_inf (le_refl _) HVU) (s.1 i) := rfl def universal_property (I : Type u) (S : I → opens X) (F : Π (i : I), sheaf_on_opens.{v} X (S i)) (φ : Π i j, equiv ((F i).res_subset ((S i) ⊓ (S j)) inf_le_left) ((F j).res_subset ((S i) ⊓ (S j)) inf_le_right)) (Hφ1 : ∀ i V HV s, (φ i i).1.1 V HV s = s) (Hφ2 : ∀ i j k V HV1 HV2 HV3 s, (φ j k).1.1 V HV1 ((φ i j).1.1 V HV2 s) = (φ i k).1.1 V HV3 s) (i : I) : equiv (res_subset (sheaf_glue S F φ) (S i) (le_supr S i)) (F i) := { to_fun := { map := λ U H s, (F i).res _ _ _ _ (le_inf H (le_refl _)) (s.1 i), commutes := λ U HU V HV HVU s, by rw [res_res, res_res_subset]; dsimp only [res, sheaf_glue, sheaf_glue.res]; rw ← presheaf.Hcomp'; refl }, inv_fun := { map := λ U H s, ⟨λ j, (φ i j).1.1 (S j ⊓ U) (le_inf (le_trans inf_le_right H) inf_le_left) ((F i).res _ _ _ (le_trans inf_le_right H) inf_le_right s), λ j k, begin have h1 : S j ⊓ S k ⊓ U ≤ S i ⊓ S j := le_inf (le_trans inf_le_right H) (le_trans inf_le_left inf_le_left), have h2 : S j ⊓ S k ⊓ U ≤ S i ⊓ S k := le_inf (le_trans inf_le_right H) (le_trans inf_le_left inf_le_right), rw [← res_res_subset (F j) _ _ _ _ _ h1, ← (φ i j).1.2, Hφ2 _ _ _ _ _ _ h2, res_res_subset, res_res], rw [← res_res_subset (F k) _ _ _ _ _ h2, ← (φ i k).1.2, res_res_subset, res_res], end⟩, commutes := λ U HU V HV HVU s, subtype.eq $ funext $ λ j, by dsimp only [res_res_subset, sheaf_glue_res_val]; rw [← res_res_subset (F j), ← (φ i j).1.2, res_res_subset, res_res, res_res] }, left_inv := λ V HV s, subtype.eq $ funext $ λ j, have _, from s.2 i j, calc _ = (φ i j).1.map (S j ⊓ V) (le_inf (le_trans inf_le_right HV) inf_le_left) ((F i).res V HV (S j ⊓ V) (le_trans inf_le_right HV) inf_le_right ((F i).res (S i ⊓ V) _ V HV (le_inf HV (le_refl _)) (s.1 i))) : rfl ... = (φ i j).1.map (S j ⊓ V) _ ((F i).res (S i ⊓ V) _ (S j ⊓ V) _ _ (s.1 i)) : by rw res_res ... = (φ i j).1.map (S j ⊓ V) _ (((F i).res_subset (S i ⊓ S j) _).res ((S i ⊓ S j) ⊓ V) inf_le_left _ _ (by rw [inf_assoc, inf_left_comm, inf_of_le_right HV]; exact le_refl _) ((F i).res (S i ⊓ V) _ ((S i ⊓ S j) ⊓ V) (le_trans inf_le_left inf_le_left) (le_inf (le_trans inf_le_left inf_le_left) inf_le_right) (s.1 i))) : by rw [res_res_subset, res_res] ... = s.1 j : by rw [(φ i j).1.2, s.2 i j, res_res_subset, res_res, res_self], right_inv := λ V HV s, by dsimp only; erw [Hφ1, res_res, res_self] } end sheaf_on_opens
example (p q r : Prop) (hp : p) : (p ∨ q ∨ r) ∧ (q ∨ p ∨ r) ∧ (q ∨ r ∨ p) := begin split, left, assumption, split, right, left, assumption, right, right, assumption end example (p q r : Prop) (hp : p) : (p ∨ q ∨ r) ∧ (q ∨ p ∨ r) ∧ (q ∨ r ∨ p) := by repeat { split <|> { try {left}, assumption } <|> right }
Formal statement is: lemmas reflect_poly_simps = reflect_poly_0 reflect_poly_1 reflect_poly_const reflect_poly_smult reflect_poly_mult reflect_poly_power reflect_poly_prod reflect_poly_prod_list Informal statement is: Simplification rules for polynomials.
using Discretizers using Distances using LinearAlgebra function distances!( r::AbstractArray{T,3} where T, t::Trajectory{TA,NonPeriodic} where {TA<:AbstractAtomNames}, ur1::AbstractUnitRange, ur2::AbstractUnitRange ) metric = Euclidean() for i in 1:length(t) pairwise!(view(r,:,:,i), metric, view(t,ur1,i), view(t,ur2,i),dims=2) end return r end function distances!( r::AbstractArray{T,3} where T, t::Trajectory{TA,TC} where {TA<:AbstractAtomNames, TC<:AbstractOrthorombicCell}, ur1::AbstractUnitRange, ur2::AbstractUnitRange ) metric = (PeriodicEuclidean ∘ celldiag)(t) for i in 1:length(t) pairwise!(view(r,:,:,i), metric, view(t,ur1,i), view(t,ur2,i),dims=2) end return r end function distances!( r::AbstractArray{T,3} where T, t::Trajectory{TA,VariableCell} where {TA<:AbstractAtomNames}, ur1::AbstractUnitRange, ur2::AbstractUnitRange ) get_metric(c::NonPeriodic) = Euclidean() get_metric(c::AbstractOrthorombicCell) = (PeriodicEuclidean ∘ celldiag)(c) for i in 1:length(t) pairwise!(view(r,:,:,i), get_metric(c.cell[i]), view(t,ur1,i), view(t,ur2,i),dims=2) end return r end function distances(t::AbstractTrajectory, i1::Integer, i2::Integer) out = Vector{Float64}(undef, length(t)) distances!(out, t, i1, i2) return out end function distances!( r::AbstractVector, t::Trajectory{TA,NonPeriodic} where {TA<:AbstractAtomNames}, i1::Integer, i2::Integer ) colwise!(r, Euclidean(), view(t,i1,:), view(t,i2,:)) return r end function distances!( r::AbstractVector, t::Trajectory{TA,TC} where {TA<:AbstractAtomNames, TC<:AbstractOrthorombicCell}, i1::Integer, i2::Integer ) metric = (PeriodicEuclidean ∘ celldiag)(t) colwise!(r, metric, view(t,i1,:), view(t,i2,:)) return r end cellvolume(t::AbstractTrajectory) = volume(t.cell) """ angle(t::AbstractTrajectory, i, j, k) -> Vector{Float64} Computes angle for atoms i, j, k in degrees """ function Base.angle(t::AbstractTrajectory, i, j, k) @warn "angle does not understand periodicity" r1 = view(t,i,:) .- view(t,j,:) r2 = view(t,k,:) .- view(t,j,:) acos.(1 .- colwise(CosineDist(),r1,r2)) .* 180 ./ π end """ dihedral(t::AbstractTrajectory, i,j,k,m) -> Vector{Float64} """ function dihedral(t::AbstractTrajectory, i,j,k,m) out = zeros(length(t)) @warn "dihedral does not understand periodicity" for n in 1:length(t) b1 = view(t,j,n) .- view(t,i,n) b2 = view(t,k,n) .- view(t,j,n) b3 = view(t,m,n) .- view(t,k,n) out[n]=atand((b1×b2)×(b2×b3)⋅b2 / norm(b2), (b1×b2)⋅(b2×b3)) end return out end """ angletoframe(t::AbstractTrajectory, i, j, k, m; frame=:) Computes angle betweem two vectors. First from atoms i to j second from k to m. Only given frame is calculated for first given vector. If frame=: (default) then calculate for whole trajectory. """ function angletoframe(t::AbstractTrajectory, i, j, k, m; frame=:) r1 = view(t,j,frame) .- view(t,i,frame) r2 = view(t,m,:) .- view(t,k,:) acosd.(1 .- colwise(CosineDist(),r1,r2)) end """ sphericalview(t::AbstractTrajectory, i, j) -> Dict Transfroms vector from atom i to j to spherical coordinates """ function sphericalview(t::AbstractTrajectory, i, j) function rdis(r) rr = sqrt.(sum(r.^2,dims=1)) #TODO fix for periodic reshape(rr, (length(rr),1)) end r = view(t,j,:) .- view(t,i,:) rr = rdis(r) ϕ = atan.(view(r,2,:), view(r,1,:)) θ = acos.( view(r,3,:) ./ rr ) return Dict("r"=>rr, "θ"=>θ.*180 ./ π, "ϕ"=>ϕ.*180 ./ π) end """ compute_rdf(t, ur1, ur2; mindis=undef, maxdis=9.0, nbins=100) -> Dict Calculates radial distribution function for trajectory or file `t` """ function compute_rdf( t::Trajectory{TA,TC} where {TA<:AbstractAtomNames, TC<:AbstractOrthorombicCell}, ur1::AbstractUnitRange, ur2::AbstractUnitRange; mindis=undef, maxdis=9.0, nbins=100 ) dis = distances(t, ur1, ur2) di = DiscretizeUniformWidth(nbins) # Collect data that are in defined range [mindis, maxdis] data = Dict{Int, Vector{Float64}}() for (i,j) in enumerate(ur1) tmp = @view dis[i,:,:] if mindis != undef q1 = tmp .< maxdis q2 = tmp .> mindis push!(data, j=> tmp[ q1 .& q2 ] ) else push!(data, j=> tmp[ tmp .< maxdis ] ) end end #Discretize data to form histograms ρ = length(ur2)*length(t) / cellvolume(t) # Average density for ur2 in trajectry edges = Dict() counts = Dict() radius = Dict() for (key,val) in data if mindis != undef e = Array(LinRange(mindis, maxdis, nbins+1)) else e = binedges(di, val) end r = 0.5 .* (e[1:end-1] .+ e[2:end]) dr = diff(e) disc = LinearDiscretizer(e) count = get_discretization_counts(disc, val) ./ (4*π*ρ .* r.^2 .* dr) push!(edges, key=> e) push!(counts, key=> count) push!(radius, key=>r) end return Dict("r"=>radius, "rdf"=>counts, "edges"=>edges) end function compute_rdf(fname::AbstractString, ur1::AbstractUnitRange, ur2::AbstractUnitRange; mindis=undef, maxdis=9.0, nbins=100) t = read_trajectory(fname) return compute_rdf(t, ur1, ur2, mindis=mindis, maxdis=maxdis, nbins=nbins) end """ compute_rdf(ur1, ur2, fnames...; mindis=0.0, maxdis=9.0, nbins=100) -> Dict() Calculates radial distribution function from given input and adds up results """ function compute_rdf(ur1::AbstractUnitRange, ur2::AbstractUnitRange, fnames...; mindis=0.0, maxdis=9.0, nbins=100) dtmp = pmap( x -> compute_rdf(x, ur1, ur2; mindis=mindis, maxdis=maxdis, nbins=nbins), fnames ) # Sum up results data = [] for x in dtmp if length(keys(x)) == 0 continue end push!(data,x) end rdf = Dict() if length(data) >0 for (k,v) in data[1]["rdf"] push!(rdf, k => deepcopy(v)) end end if length(data) > 1 for x in data[2:end] for (k,v) in x["rdf"] rdf[k] .+= v end end end for k in keys(rdf) rdf[k] ./= length(data) end rk = collect(keys(data[1]["r"]))[1] return Dict("r"=>data[1]["r"][rk] , "rdf" => rdf) end function get_close_atoms(traj::AbstractTrajectory, i; maxdis=5.0) t = subtrajectory(traj,1) d = distances(t,1:natoms(t),i)[:,:,1] m = minimum(d; dims=2) a = m .< maxdis return getatoms(traj, a[:,1]) end function get_close_atoms(traj::AbstractTrajectory, i::Integer; maxdis=5.0) return get_close_atoms(traj, i:i; maxdis=maxdis) end
[STATEMENT] lemma analz_insert_HPair [simp]: "analz (insert (Hash[X] Y) H) = insert (Hash[X] Y) (insert (Hash\<lbrace>X,Y\<rbrace>) (analz (insert Y H)))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. analz (insert Hash[X] Y H) = insert Hash[X] Y (insert (Hash \<lbrace>X, Y\<rbrace>) (analz (insert Y H))) [PROOF STEP] by (simp add: HPair_def)
Dublin @-@ Belfast corridor - 3 @.@ 3 m
/* NAME: read_data PURPOSE: read the data from the data input file CALLING SEQUENCE: read_data(inputfilename) INPUT: inputfilename - name of the data file OUPUT: reads everything into the right structures REVISION HISTORY: 2008-09-21 - Written Bovy */ #include <stdio.h> #include <stdbool.h> #include <math.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_matrix.h> #include <proj_gauss_main.h> #include <proj_gauss_mixtures.h> bool read_data(char inputfilename[]){ FILE *inputfile; if ( (inputfile= fopen(inputfilename,"r")) == NULL){ printf ("Opening the data file failed...\n"); return false; } //First count the number of datapoints N=0; while (feof(inputfile) ==0) if (getc(inputfile) == '\n') N++; printf("%i datapoints found in ",N); printf("%s", inputfilename); printf("\n"); //Then read the actual data fseek(inputfile,0,SEEK_SET); //allocate data data = (struct datapoint *) malloc(N*sizeof (struct datapoint)); if (data == NULL){ printf("Allocation of arrays failed, not enough free memory?\n"); exit(-1); } startdata = data; //current line holds a maximum of d+dV+d*d elements //First read the whole line double *curr_line = (double *) calloc(d+dV+d*d, sizeof (double) ); bool end_line; int ii=0,dd=0,di;//di is the dimension of the individual datapoints while (feof(inputfile) == 0){ char curr_value[20]=""; end_line = read_till_sep(curr_value,inputfile,'|'); *(curr_line++) = atof(curr_value); ++dd; if (end_line){ ++ii; curr_line -= dd; //Determine the dimension of the datapoint, di, from the equation di+di*(di+1)/2+d*di=dd, or, di = (int) ((-(3 + 2 * d) + sqrt((3 + 2 * d)*(3 + 2 * d)+8 * dd))/2); //then write data values to memory //first allocate the space for the data data->ww = gsl_vector_alloc(di); data->SS = gsl_matrix_alloc(di,di); data->RR = gsl_matrix_alloc(di,d); int dd1,dd2; for (dd1=0; dd1 != di; ++dd1) gsl_vector_set(data->ww,dd1,*(curr_line++)); for (dd1=0; dd1 != di; ++dd1) gsl_matrix_set(data->SS,dd1,dd1,*(curr_line++)); for (dd1=0; dd1 != di-1; ++dd1) for (dd2=dd1+1; dd2 != di; ++dd2){ gsl_matrix_set(data->SS,dd1,dd2,*curr_line); gsl_matrix_set(data->SS,dd2,dd1,*curr_line); curr_line++; } for (dd1=0; dd1 != di; ++dd1) for (dd2=0; dd2 != d; ++dd2) gsl_matrix_set(data->RR,dd1,dd2,*(curr_line++)); curr_line -= dd; dd = 0; data++; if (ii == N) break; } } data = startdata; fclose(inputfile); free(curr_line); return true; }
The Townhomes at Diamond Ridge invites you to embrace a life of comfort and convenience. Located in the Windsor Mill neighborhood of Baltimore, Maryland, our apartments and townhomes are your shortcut to better living. We are conveniently located near I-695 and I-70, just 10 miles from the museums, galleries, and parks in the city center. Here in our neighborhood, you will appreciate easy access to employers, eateries, and entertainment. Take advantage of the short commutes to Baltimore County Public Schools, Northwest Hospital, and University of Maryland – Baltimore County. For a night out, visit nearby Windsor Inn Crab House for a delicious seafood dinner. When you need to get outside, explore the miles of wooded hiking trails at Patapsco Valley State Park. There’s no better time to make your move. Call The Townhomes at Diamond Ridge in Baltimore, MD, today to schedule your personalized tour.
------------------------------------------------------------------------ -- The Agda standard library -- -- Results concerning uniqueness of identity proofs, with axiom K ------------------------------------------------------------------------ {-# OPTIONS --with-K --safe #-} module Axiom.UniquenessOfIdentityProofs.WithK where open import Axiom.UniquenessOfIdentityProofs open import Relation.Binary.PropositionalEquality.Core -- Axiom K implies UIP. uip : ∀ {a A} → UIP {a} A uip refl refl = refl
/- Copyright (c) 2018 Guy Leroy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes Hölzl Greatest common divisor (gcd) and least common multiple (lcm) for integers. This sets up ℤ to be a GCD domain, and introduces rules about `int.gcd`, as well as `int.lcm`. NOTE: If you add rules to this theory, check that the corresponding rules are available for `gcd_domain`. -/ import data.int.basic data.nat.prime /- Extended Euclidean algorithm -/ namespace nat def xgcd_aux : ℕ → ℤ → ℤ → ℕ → ℤ → ℤ → ℕ × ℤ × ℤ | 0 s t r' s' t' := (r', s', t') | r@(succ _) s t r' s' t' := have r' % r < r, from mod_lt _ $ succ_pos _, let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t @[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcd_aux 0 s t r' s' t' = (r', s', t') := by simp [xgcd_aux] @[simp] theorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) : xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t := by cases r; [exact absurd h (lt_irrefl _), {simp only [xgcd_aux], refl}] /-- Use the extended GCD algorithm to generate the `a` and `b` values satisfying `gcd x y = x * a + y * b`. -/ def xgcd (x y : ℕ) : ℤ × ℤ := (xgcd_aux x 1 0 y 0 1).2 /-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/ def gcd_a (x y : ℕ) : ℤ := (xgcd x y).1 /-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/ def gcd_b (x y : ℕ) : ℤ := (xgcd x y).2 @[simp] theorem xgcd_aux_fst (x y) : ∀ s t s' t', (xgcd_aux x s t y s' t').1 = gcd x y := gcd.induction x y (by simp) (λ x y h IH s t s' t', by simp [h, IH]; rw ← gcd_rec) theorem xgcd_aux_val (x y) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by rw [xgcd, ← xgcd_aux_fst x y 1 0 0 1]; cases xgcd_aux x 1 0 y 0 1; refl theorem xgcd_val (x y) : xgcd x y = (gcd_a x y, gcd_b x y) := by unfold gcd_a gcd_b; cases xgcd x y; refl section parameters (a b : ℕ) private def P : ℕ × ℤ × ℤ → Prop | (r, s, t) := (r : ℤ) = a * s + b * t theorem xgcd_aux_P {r r'} : ∀ {s t s' t'}, P (r, s, t) → P (r', s', t') → P (xgcd_aux r s t r' s' t') := gcd.induction r r' (by simp) $ λ x y h IH s t s' t' p p', begin rw [xgcd_aux_rec h], refine IH _ p, dsimp [P] at *, rw [int.mod_def], generalize : (y / x : ℤ) = k, rw [p, p'], simp [mul_add, mul_comm, mul_left_comm] end theorem gcd_eq_gcd_ab : (gcd a b : ℤ) = a * gcd_a a b + b * gcd_b a b := by have := @xgcd_aux_P a b a b 1 0 0 1 (by simp [P]) (by simp [P]); rwa [xgcd_aux_val, xgcd_val] at this end end nat namespace int theorem nat_abs_div (a b : ℤ) (H : b ∣ a) : nat_abs (a / b) = (nat_abs a) / (nat_abs b) := begin cases (nat.eq_zero_or_pos (nat_abs b)), rw eq_zero_of_nat_abs_eq_zero h, simp, calc nat_abs (a / b) = nat_abs (a / b) * 1 : by rw mul_one ... = nat_abs (a / b) * (nat_abs b / nat_abs b) : by rw nat.div_self h ... = nat_abs (a / b) * nat_abs b / nat_abs b : by rw (nat.mul_div_assoc _ (dvd_refl _)) ... = nat_abs (a / b * b) / nat_abs b : by rw (nat_abs_mul (a / b) b) ... = nat_abs a / nat_abs b : by rw int.div_mul_cancel H, end theorem nat_abs_dvd_abs_iff {i j : ℤ} : i.nat_abs ∣ j.nat_abs ↔ i ∣ j := ⟨assume (H : i.nat_abs ∣ j.nat_abs), dvd_nat_abs.mp (nat_abs_dvd.mp (coe_nat_dvd.mpr H)), assume H : (i ∣ j), coe_nat_dvd.mp (dvd_nat_abs.mpr (nat_abs_dvd.mpr H))⟩ lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : nat.prime p) {m n : ℤ} {k l : ℕ} (hpm : ↑(p ^ k) ∣ m) (hpn : ↑(p ^ l) ∣ n) (hpmn : ↑(p ^ (k+l+1)) ∣ m*n) : ↑(p ^ (k+1)) ∣ m ∨ ↑(p ^ (l+1)) ∣ n := have hpm' : p ^ k ∣ m.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpm, have hpn' : p ^ l ∣ n.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpn, have hpmn' : (p ^ (k+l+1)) ∣ m.nat_abs*n.nat_abs, by rw ←int.nat_abs_mul; apply (int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpmn), let hsd := nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul p_prime hpm' hpn' hpmn' in hsd.elim (λ hsd1, or.inl begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd1 end) (λ hsd2, or.inr begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd2 end) theorem dvd_of_mul_dvd_mul_left {i j k : ℤ} (k_non_zero : k ≠ 0) (H : k * i ∣ k * j) : i ∣ j := dvd.elim H (λl H1, by rw mul_assoc at H1; exact ⟨_, eq_of_mul_eq_mul_left k_non_zero H1⟩) theorem dvd_of_mul_dvd_mul_right {i j k : ℤ} (k_non_zero : k ≠ 0) (H : i * k ∣ j * k) : i ∣ j := by rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H end int
module Part2.Sec3_2_3_gen import Data.Vect {- implementation code generated 100% by idris steps (based on Atom key bindings): * Add def with cursor on mapV (Ctr-Alt-a) * Case split xs (Ctr-Alt-c) * Search (Crl-Alt-s) for both holes -} mapV : (a -> b) -> Vect n a -> Vect n b mapV f [] = [] mapV f (x :: xs) = f x :: mapV f xs mapV2 : (a -> b) -> Vect n a -> Vect n b mapV2 f [] = ?mapV2_rhs_1 mapV2 f (x :: xs) = ?mapV2_rhs_2
lemma cball_scale: assumes "a \<noteq> 0" shows "(\<lambda>x. a *\<^sub>R x) ` cball c r = cball (a *\<^sub>R c :: 'a :: real_normed_vector) (\<bar>a\<bar> * r)"
Require Import mathcomp.ssreflect.ssreflect. Require Import mathcomp.ssreflect.seq mathcomp.ssreflect.prime. (** Example of computation involving Peano nats *) Time Eval vm_compute in filter prime (iota 1 100). (** Example of theorem proved using Coq tactics *) Theorem thm : forall P, not (iff P (not P)). Proof. idtac "proof in progress...". now intros P [H1 H2]; apply H1; apply H2; intros HP; apply H1. Qed.
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison ! This file was ported from Lean 3 source module topology.category.TopCommRing ! leanprover-community/mathlib commit 9a59dcb7a2d06bf55da57b9030169219980660cd ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Algebra.Category.Ring.Basic import Mathbin.Topology.Category.Top.Basic import Mathbin.Topology.Algebra.Ring.Basic /-! # Category of topological commutative rings We introduce the category `TopCommRing` of topological commutative rings together with the relevant forgetful functors to topological spaces and commutative rings. -/ universe u open CategoryTheory /-- A bundled topological commutative ring. -/ structure TopCommRing where α : Type u [isCommRing : CommRing α] [isTopologicalSpace : TopologicalSpace α] [is_topologicalRing : TopologicalRing α] #align TopCommRing TopCommRing namespace TopCommRing instance : Inhabited TopCommRing := ⟨⟨PUnit⟩⟩ instance : CoeSort TopCommRing (Type u) := ⟨TopCommRing.α⟩ attribute [instance] is_comm_ring is_topological_space is_topological_ring instance : Category TopCommRing.{u} where Hom R S := { f : R →+* S // Continuous f } id R := ⟨RingHom.id R, by obviously⟩ -- TODO remove obviously? comp R S T f g := ⟨g.val.comp f.val, by -- TODO automate cases f; cases g dsimp; apply Continuous.comp <;> assumption⟩ instance : ConcreteCategory TopCommRing.{u} where forget := { obj := fun R => R map := fun R S f => f.val } forget_faithful := { } /-- Construct a bundled `TopCommRing` from the underlying type and the appropriate typeclasses. -/ def of (X : Type u) [CommRing X] [TopologicalSpace X] [TopologicalRing X] : TopCommRing := ⟨X⟩ #align TopCommRing.of TopCommRing.of @[simp] theorem coe_of (X : Type u) [CommRing X] [TopologicalSpace X] [TopologicalRing X] : (of X : Type u) = X := rfl #align TopCommRing.coe_of TopCommRing.coe_of instance forgetTopologicalSpace (R : TopCommRing) : TopologicalSpace ((forget TopCommRing).obj R) := R.isTopologicalSpace #align TopCommRing.forget_topological_space TopCommRing.forgetTopologicalSpace instance forgetCommRing (R : TopCommRing) : CommRing ((forget TopCommRing).obj R) := R.isCommRing #align TopCommRing.forget_comm_ring TopCommRing.forgetCommRing instance forget_topologicalRing (R : TopCommRing) : TopologicalRing ((forget TopCommRing).obj R) := R.is_topologicalRing #align TopCommRing.forget_topological_ring TopCommRing.forget_topologicalRing instance hasForgetToCommRing : HasForget₂ TopCommRing CommRingCat := HasForget₂.mk' (fun R => CommRingCat.of R) (fun x => rfl) (fun R S f => f.val) fun R S f => HEq.rfl #align TopCommRing.has_forget_to_CommRing TopCommRing.hasForgetToCommRing instance forgetToCommRingTopologicalSpace (R : TopCommRing) : TopologicalSpace ((forget₂ TopCommRing CommRingCat).obj R) := R.isTopologicalSpace #align TopCommRing.forget_to_CommRing_topological_space TopCommRing.forgetToCommRingTopologicalSpace /-- The forgetful functor to Top. -/ instance hasForgetToTop : HasForget₂ TopCommRing TopCat := HasForget₂.mk' (fun R => TopCat.of R) (fun x => rfl) (fun R S f => ⟨⇑f.1, f.2⟩) fun R S f => HEq.rfl #align TopCommRing.has_forget_to_Top TopCommRing.hasForgetToTop instance forgetToTopCommRing (R : TopCommRing) : CommRing ((forget₂ TopCommRing TopCat).obj R) := R.isCommRing #align TopCommRing.forget_to_Top_comm_ring TopCommRing.forgetToTopCommRing instance forget_to_topCat_topologicalRing (R : TopCommRing) : TopologicalRing ((forget₂ TopCommRing TopCat).obj R) := R.is_topologicalRing #align TopCommRing.forget_to_Top_topological_ring TopCommRing.forget_to_topCat_topologicalRing /-- The forgetful functors to `Type` do not reflect isomorphisms, but the forgetful functor from `TopCommRing` to `Top` does. -/ instance : ReflectsIsomorphisms (forget₂ TopCommRing.{u} TopCat.{u}) where reflects X Y f _ := by skip -- We have an isomorphism in `Top`, let i_Top := as_iso ((forget₂ TopCommRing TopCat).map f) -- and a `ring_equiv`. let e_Ring : X ≃+* Y := { f.1, ((forget TopCat).mapIso i_Top).toEquiv with } -- Putting these together we obtain the isomorphism we're after: exact ⟨⟨⟨e_Ring.symm, i_Top.inv.2⟩, ⟨by ext x exact e_Ring.left_inv x, by ext x exact e_Ring.right_inv x⟩⟩⟩ end TopCommRing
FUNCTION GMAX1 (ARG1,ARG2) C C MAXIMUM VALUE OF TWO ARGUMENTS C NOTE THAT THIS DOES NOT UTILIZE THE FULL CAPABILITY OF THE C LIBRARY FUNCTIONS IN THAT THE NUMBER OF ARGUMENTS IS NOT LIMITED C TO TWO. (AT LEAST ON THE VAX). C REAL*8 GMAX1,DMAX1,ARG1,ARG2 C GMAX1 = DMAX1 (ARG1,ARG2) RETURN END
/- Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu ! This file was ported from Lean 3 source module number_theory.modular ! leanprover-community/mathlib commit 2196ab363eb097c008d4497125e0dde23fb36db2 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Analysis.Complex.UpperHalfPlane.Basic import Mathbin.Analysis.NormedSpace.FiniteDimension import Mathbin.LinearAlgebra.GeneralLinearGroup import Mathbin.LinearAlgebra.Matrix.GeneralLinearGroup /-! # The action of the modular group SL(2, ℤ) on the upper half-plane We define the action of `SL(2,ℤ)` on `ℍ` (via restriction of the `SL(2,ℝ)` action in `analysis.complex.upper_half_plane`). We then define the standard fundamental domain (`modular_group.fd`, `𝒟`) for this action and show (`modular_group.exists_smul_mem_fd`) that any point in `ℍ` can be moved inside `𝒟`. ## Main definitions The standard (closed) fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟`: `fd := {z | 1 ≤ (z : ℂ).norm_sq ∧ |z.re| ≤ (1 : ℝ) / 2}` The standard open fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟ᵒ`: `fdo := {z | 1 < (z : ℂ).norm_sq ∧ |z.re| < (1 : ℝ) / 2}` These notations are localized in the `modular` locale and can be enabled via `open_locale modular`. ## Main results Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,ℤ)`: `exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2,ℤ), g • z ∈ 𝒟` If both `z` and `γ • z` are in the open domain `𝒟ᵒ` then `z = γ • z`: `eq_smul_self_of_mem_fdo_mem_fdo {z : ℍ} {g : SL(2,ℤ)} (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z` # Discussion Standard proofs make use of the identity `g • z = a / c - 1 / (c (cz + d))` for `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`. Instead, our proof makes use of the following perhaps novel identity (see `modular_group.smul_eq_lc_row0_add`): `g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))` where there is no issue of division by zero. Another feature is that we delay until the very end the consideration of special matrices `T=[[1,1],[0,1]]` (see `modular_group.T`) and `S=[[0,-1],[1,0]]` (see `modular_group.S`), by instead using abstract theory on the properness of certain maps (phrased in terms of the filters `filter.cocompact`, `filter.cofinite`, etc) to deduce existence theorems, first to prove the existence of `g` maximizing `(g•z).im` (see `modular_group.exists_max_im`), and then among those, to minimize `|(g•z).re|` (see `modular_group.exists_row_one_eq_and_min_re`). -/ /- Disable these instances as they are not the simp-normal form, and having them disabled ensures we state lemmas in this file without spurious `coe_fn` terms. -/ attribute [-instance] Matrix.SpecialLinearGroup.hasCoeToFun attribute [-instance] Matrix.GeneralLinearGroup.hasCoeToFun open Complex hiding abs_two open Matrix hiding mul_smul open Matrix.SpecialLinearGroup UpperHalfPlane noncomputable section -- mathport name: «exprSL( , )» local notation "SL(" n ", " R ")" => SpecialLinearGroup (Fin n) R -- mathport name: «expr↑ₘ » local prefix:1024 "↑ₘ" => @coe _ (Matrix (Fin 2) (Fin 2) ℤ) _ open UpperHalfPlane ComplexConjugate attribute [local instance] Fintype.card_fin_even namespace ModularGroup variable {g : SL(2, ℤ)} (z : ℍ) section BottomRow /-- The two numbers `c`, `d` in the "bottom_row" of `g=[[*,*],[c,d]]` in `SL(2, ℤ)` are coprime. -/ theorem bottom_row_coprime {R : Type _} [CommRing R] (g : SL(2, R)) : IsCoprime ((↑g : Matrix (Fin 2) (Fin 2) R) 1 0) ((↑g : Matrix (Fin 2) (Fin 2) R) 1 1) := by use -(↑g : Matrix (Fin 2) (Fin 2) R) 0 1, (↑g : Matrix (Fin 2) (Fin 2) R) 0 0 rw [add_comm, neg_mul, ← sub_eq_add_neg, ← det_fin_two] exact g.det_coe #align modular_group.bottom_row_coprime ModularGroup.bottom_row_coprime /-- Every pair `![c, d]` of coprime integers is the "bottom_row" of some element `g=[[*,*],[c,d]]` of `SL(2,ℤ)`. -/ theorem bottom_row_surj {R : Type _} [CommRing R] : Set.SurjOn (fun g : SL(2, R) => @coe _ (Matrix (Fin 2) (Fin 2) R) _ g 1) Set.univ { cd | IsCoprime (cd 0) (cd 1) } := by rintro cd ⟨b₀, a, gcd_eqn⟩ let A := of ![![a, -b₀], cd] have det_A_1 : det A = 1 := by convert gcd_eqn simp [A, det_fin_two, (by ring : a * cd 1 + b₀ * cd 0 = b₀ * cd 0 + a * cd 1)] refine' ⟨⟨A, det_A_1⟩, Set.mem_univ _, _⟩ ext <;> simp [A] #align modular_group.bottom_row_surj ModularGroup.bottom_row_surj end BottomRow section TendstoLemmas open Filter ContinuousLinearMap attribute [local simp] coe_smul /-- The function `(c,d) → |cz+d|^2` is proper, that is, preimages of bounded-above sets are finite. -/ theorem tendsto_normSq_coprime_pair : Filter.Tendsto (fun p : Fin 2 → ℤ => ((p 0 : ℂ) * z + p 1).normSq) cofinite atTop := by -- using this instance rather than the automatic `function.module` makes unification issues in -- `linear_equiv.closed_embedding_of_injective` less bad later in the proof. letI : Module ℝ (Fin 2 → ℝ) := NormedSpace.toModule let π₀ : (Fin 2 → ℝ) →ₗ[ℝ] ℝ := LinearMap.proj 0 let π₁ : (Fin 2 → ℝ) →ₗ[ℝ] ℝ := LinearMap.proj 1 let f : (Fin 2 → ℝ) →ₗ[ℝ] ℂ := π₀.smul_right (z : ℂ) + π₁.smul_right 1 have f_def : ⇑f = fun p : Fin 2 → ℝ => (p 0 : ℂ) * ↑z + p 1 := by ext1 dsimp only [LinearMap.coe_proj, real_smul, LinearMap.coe_smulRight, LinearMap.add_apply] rw [mul_one] have : (fun p : Fin 2 → ℤ => norm_sq ((p 0 : ℂ) * ↑z + ↑(p 1))) = norm_sq ∘ f ∘ fun p : Fin 2 → ℤ => (coe : ℤ → ℝ) ∘ p := by ext1 rw [f_def] dsimp only [Function.comp] rw [of_real_int_cast, of_real_int_cast] rw [this] have hf : f.ker = ⊥ := by let g : ℂ →ₗ[ℝ] Fin 2 → ℝ := LinearMap.pi ![im_lm, im_lm.comp ((z : ℂ) • ((conj_ae : ℂ →ₐ[ℝ] ℂ) : ℂ →ₗ[ℝ] ℂ))] suffices ((z : ℂ).im⁻¹ • g).comp f = LinearMap.id by exact LinearMap.ker_eq_bot_of_inverse this apply LinearMap.ext intro c have hz : (z : ℂ).im ≠ 0 := z.2.ne' rw [LinearMap.comp_apply, LinearMap.smul_apply, LinearMap.id_apply] ext i dsimp only [g, Pi.smul_apply, LinearMap.pi_apply, smul_eq_mul] fin_cases i · show (z : ℂ).im⁻¹ * (f c).im = c 0 rw [f_def, add_im, of_real_mul_im, of_real_im, add_zero, mul_left_comm, inv_mul_cancel hz, mul_one] · show (z : ℂ).im⁻¹ * ((z : ℂ) * conj (f c)).im = c 1 rw [f_def, RingHom.map_add, RingHom.map_mul, mul_add, mul_left_comm, mul_conj, conj_of_real, conj_of_real, ← of_real_mul, add_im, of_real_im, zero_add, inv_mul_eq_iff_eq_mul₀ hz] simp only [of_real_im, of_real_re, mul_im, zero_add, MulZeroClass.mul_zero] have hf' : ClosedEmbedding f := by -- for some reason we get a timeout if we try and apply this lemma in a more sensible way have := @LinearEquiv.closedEmbedding_of_injective ℝ _ (Fin 2 → ℝ) _ (id _) ℂ _ _ _ _ rotate_left 2 exact f exact this hf have h₂ : tendsto (fun p : Fin 2 → ℤ => (coe : ℤ → ℝ) ∘ p) cofinite (cocompact _) := by convert tendsto.pi_map_Coprod fun i => Int.tendsto_coe_cofinite · rw [Coprod_cofinite] · rw [Coprod_cocompact] exact tendsto_norm_sq_cocompact_at_top.comp (hf'.tendsto_cocompact.comp h₂) #align modular_group.tendsto_norm_sq_coprime_pair ModularGroup.tendsto_normSq_coprime_pair /-- Given `coprime_pair` `p=(c,d)`, the matrix `[[a,b],[*,*]]` is sent to `a*c+b*d`. This is the linear map version of this operation. -/ def lcRow0 (p : Fin 2 → ℤ) : Matrix (Fin 2) (Fin 2) ℝ →ₗ[ℝ] ℝ := ((p 0 : ℝ) • LinearMap.proj 0 + (p 1 : ℝ) • LinearMap.proj 1 : (Fin 2 → ℝ) →ₗ[ℝ] ℝ).comp (LinearMap.proj 0) #align modular_group.lc_row0 ModularGroup.lcRow0 @[simp] theorem lcRow0_apply (p : Fin 2 → ℤ) (g : Matrix (Fin 2) (Fin 2) ℝ) : lcRow0 p g = p 0 * g 0 0 + p 1 * g 0 1 := rfl #align modular_group.lc_row0_apply ModularGroup.lcRow0_apply /-- Linear map sending the matrix [a, b; c, d] to the matrix [ac₀ + bd₀, - ad₀ + bc₀; c, d], for some fixed `(c₀, d₀)`. -/ @[simps] def lcRow0Extend {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) : Matrix (Fin 2) (Fin 2) ℝ ≃ₗ[ℝ] Matrix (Fin 2) (Fin 2) ℝ := LinearEquiv.piCongrRight ![by refine' LinearMap.GeneralLinearGroup.generalLinearEquiv ℝ (Fin 2 → ℝ) (general_linear_group.to_linear (plane_conformal_matrix (cd 0 : ℝ) (-(cd 1 : ℝ)) _)) norm_cast rw [neg_sq] exact hcd.sq_add_sq_ne_zero, LinearEquiv.refl ℝ (Fin 2 → ℝ)] #align modular_group.lc_row0_extend ModularGroup.lcRow0Extend /-- The map `lc_row0` is proper, that is, preimages of cocompact sets are finite in `[[* , *], [c, d]]`.-/ theorem tendsto_lcRow0 {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) : Tendsto (fun g : { g : SL(2, ℤ) // ↑ₘg 1 = cd } => lcRow0 cd ↑(↑g : SL(2, ℝ))) cofinite (cocompact ℝ) := by let mB : ℝ → Matrix (Fin 2) (Fin 2) ℝ := fun t => of ![![t, (-(1 : ℤ) : ℝ)], coe ∘ cd] have hmB : Continuous mB := by refine' continuous_matrix _ simp only [Fin.forall_fin_two, mB, continuous_const, continuous_id', of_apply, cons_val_zero, cons_val_one, and_self_iff] refine' Filter.Tendsto.of_tendsto_comp _ (comap_cocompact_le hmB) let f₁ : SL(2, ℤ) → Matrix (Fin 2) (Fin 2) ℝ := fun g => Matrix.map (↑g : Matrix _ _ ℤ) (coe : ℤ → ℝ) have cocompact_ℝ_to_cofinite_ℤ_matrix : tendsto (fun m : Matrix (Fin 2) (Fin 2) ℤ => Matrix.map m (coe : ℤ → ℝ)) cofinite (cocompact _) := by simpa only [Coprod_cofinite, Coprod_cocompact] using tendsto.pi_map_Coprod fun i : Fin 2 => tendsto.pi_map_Coprod fun j : Fin 2 => Int.tendsto_coe_cofinite have hf₁ : tendsto f₁ cofinite (cocompact _) := cocompact_ℝ_to_cofinite_ℤ_matrix.comp subtype.coe_injective.tendsto_cofinite have hf₂ : ClosedEmbedding (lc_row0_extend hcd) := (lc_row0_extend hcd).toContinuousLinearEquiv.toHomeomorph.ClosedEmbedding convert hf₂.tendsto_cocompact.comp (hf₁.comp subtype.coe_injective.tendsto_cofinite) using 1 ext (⟨g, rfl⟩i j) : 3 fin_cases i <;> [fin_cases j, skip] -- the following are proved by `simp`, but it is replaced by `simp only` to avoid timeouts. · simp only [mB, mul_vec, dot_product, Fin.sum_univ_two, _root_.coe_coe, coe_matrix_coe, Int.coe_castRingHom, lc_row0_apply, Function.comp_apply, cons_val_zero, lc_row0_extend_apply, LinearMap.GeneralLinearGroup.coeFn_generalLinearEquiv, general_linear_group.to_linear_apply, coe_plane_conformal_matrix, neg_neg, mul_vec_lin_apply, cons_val_one, head_cons, of_apply] · convert congr_arg (fun n : ℤ => (-n : ℝ)) g.det_coe.symm using 1 simp only [f₁, mul_vec, dot_product, Fin.sum_univ_two, Matrix.det_fin_two, Function.comp_apply, Subtype.coe_mk, lc_row0_extend_apply, cons_val_zero, LinearMap.GeneralLinearGroup.coeFn_generalLinearEquiv, general_linear_group.to_linear_apply, coe_plane_conformal_matrix, mul_vec_lin_apply, cons_val_one, head_cons, map_apply, neg_mul, Int.cast_sub, Int.cast_mul, neg_sub, of_apply] ring · rfl #align modular_group.tendsto_lc_row0 ModularGroup.tendsto_lcRow0 /-- This replaces `(g•z).re = a/c + *` in the standard theory with the following novel identity: `g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))` which does not need to be decomposed depending on whether `c = 0`. -/ theorem smul_eq_lcRow0_add {p : Fin 2 → ℤ} (hp : IsCoprime (p 0) (p 1)) (hg : ↑ₘg 1 = p) : ↑(g • z) = (lcRow0 p ↑(g : SL(2, ℝ)) : ℂ) / (p 0 ^ 2 + p 1 ^ 2) + ((p 1 : ℂ) * z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1)) := by have nonZ1 : (p 0 : ℂ) ^ 2 + p 1 ^ 2 ≠ 0 := by exact_mod_cast hp.sq_add_sq_ne_zero have : (coe : ℤ → ℝ) ∘ p ≠ 0 := fun h => hp.ne_zero (by ext i <;> simpa using congr_fun h i) have nonZ2 : (p 0 : ℂ) * z + p 1 ≠ 0 := by simpa using linear_ne_zero _ z this field_simp [nonZ1, nonZ2, denom_ne_zero, -UpperHalfPlane.denom, -denom_apply] rw [(by simp : (p 1 : ℂ) * z - p 0 = (p 1 * z - p 0) * ↑(det (↑g : Matrix (Fin 2) (Fin 2) ℤ)))] rw [← hg, det_fin_two] simp only [Int.coe_castRingHom, coe_matrix_coe, Int.cast_mul, of_real_int_cast, map_apply, denom, Int.cast_sub, _root_.coe_coe, coe_GL_pos_coe_GL_coe_matrix] ring #align modular_group.smul_eq_lc_row0_add ModularGroup.smul_eq_lcRow0_add theorem tendsto_abs_re_smul {p : Fin 2 → ℤ} (hp : IsCoprime (p 0) (p 1)) : Tendsto (fun g : { g : SL(2, ℤ) // ↑ₘg 1 = p } => |((g : SL(2, ℤ)) • z).re|) cofinite atTop := by suffices tendsto (fun g : (fun g : SL(2, ℤ) => ↑ₘg 1) ⁻¹' {p} => ((g : SL(2, ℤ)) • z).re) cofinite (cocompact ℝ) by exact tendsto_norm_cocompact_at_top.comp this have : ((p 0 : ℝ) ^ 2 + p 1 ^ 2)⁻¹ ≠ 0 := by apply inv_ne_zero exact_mod_cast hp.sq_add_sq_ne_zero let f := Homeomorph.mulRight₀ _ this let ff := Homeomorph.addRight (((p 1 : ℂ) * z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re convert(f.trans ff).ClosedEmbedding.tendsto_cocompact.comp (tendsto_lc_row0 hp) ext g change ((g : SL(2, ℤ)) • z).re = lc_row0 p ↑(↑g : SL(2, ℝ)) / (p 0 ^ 2 + p 1 ^ 2) + (((p 1 : ℂ) * z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re exact_mod_cast congr_arg Complex.re (smul_eq_lc_row0_add z hp g.2) #align modular_group.tendsto_abs_re_smul ModularGroup.tendsto_abs_re_smul end TendstoLemmas section FundamentalDomain attribute [local simp] coe_smul re_smul /-- For `z : ℍ`, there is a `g : SL(2,ℤ)` maximizing `(g•z).im` -/ theorem exists_max_im : ∃ g : SL(2, ℤ), ∀ g' : SL(2, ℤ), (g' • z).im ≤ (g • z).im := by classical let s : Set (Fin 2 → ℤ) := { cd | IsCoprime (cd 0) (cd 1) } have hs : s.nonempty := ⟨![1, 1], isCoprime_one_left⟩ obtain ⟨p, hp_coprime, hp⟩ := Filter.Tendsto.exists_within_forall_le hs (tendsto_norm_sq_coprime_pair z) obtain ⟨g, -, hg⟩ := bottom_row_surj hp_coprime refine' ⟨g, fun g' => _⟩ rw [special_linear_group.im_smul_eq_div_norm_sq, special_linear_group.im_smul_eq_div_norm_sq, div_le_div_left] · simpa [← hg] using hp (↑ₘg' 1) (bottom_row_coprime g') · exact z.im_pos · exact norm_sq_denom_pos g' z · exact norm_sq_denom_pos g z #align modular_group.exists_max_im ModularGroup.exists_max_im /-- Given `z : ℍ` and a bottom row `(c,d)`, among the `g : SL(2,ℤ)` with this bottom row, minimize `|(g•z).re|`. -/ theorem exists_row_one_eq_and_min_re {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) : ∃ g : SL(2, ℤ), ↑ₘg 1 = cd ∧ ∀ g' : SL(2, ℤ), ↑ₘg 1 = ↑ₘg' 1 → |(g • z).re| ≤ |(g' • z).re| := by haveI : Nonempty { g : SL(2, ℤ) // ↑ₘg 1 = cd } := let ⟨x, hx⟩ := bottom_row_surj hcd ⟨⟨x, hx.2⟩⟩ obtain ⟨g, hg⟩ := Filter.Tendsto.exists_forall_le (tendsto_abs_re_smul z hcd) refine' ⟨g, g.2, _⟩ · intro g1 hg1 have : g1 ∈ (fun g : SL(2, ℤ) => ↑ₘg 1) ⁻¹' {cd} := by rw [Set.mem_preimage, Set.mem_singleton_iff] exact Eq.trans hg1.symm (set.mem_singleton_iff.mp (set.mem_preimage.mp g.2)) exact hg ⟨g1, this⟩ #align modular_group.exists_row_one_eq_and_min_re ModularGroup.exists_row_one_eq_and_min_re theorem coe_t_zpow_smul_eq {n : ℤ} : (↑(t ^ n • z) : ℂ) = z + n := by simp [coe_T_zpow] #align modular_group.coe_T_zpow_smul_eq ModularGroup.coe_t_zpow_smul_eq theorem re_t_zpow_smul (n : ℤ) : (t ^ n • z).re = z.re + n := by rw [← coe_re, coe_T_zpow_smul_eq, add_re, int_cast_re, coe_re] #align modular_group.re_T_zpow_smul ModularGroup.re_t_zpow_smul theorem im_t_zpow_smul (n : ℤ) : (t ^ n • z).im = z.im := by rw [← coe_im, coe_T_zpow_smul_eq, add_im, int_cast_im, add_zero, coe_im] #align modular_group.im_T_zpow_smul ModularGroup.im_t_zpow_smul theorem re_t_smul : (t • z).re = z.re + 1 := by simpa using re_T_zpow_smul z 1 #align modular_group.re_T_smul ModularGroup.re_t_smul theorem im_t_smul : (t • z).im = z.im := by simpa using im_T_zpow_smul z 1 #align modular_group.im_T_smul ModularGroup.im_t_smul theorem re_t_inv_smul : (t⁻¹ • z).re = z.re - 1 := by simpa using re_T_zpow_smul z (-1) #align modular_group.re_T_inv_smul ModularGroup.re_t_inv_smul theorem im_t_inv_smul : (t⁻¹ • z).im = z.im := by simpa using im_T_zpow_smul z (-1) #align modular_group.im_T_inv_smul ModularGroup.im_t_inv_smul variable {z} -- If instead we had `g` and `T` of type `PSL(2, ℤ)`, then we could simply state `g = T^n`. theorem exists_eq_t_zpow_of_c_eq_zero (hc : ↑ₘg 1 0 = 0) : ∃ n : ℤ, ∀ z : ℍ, g • z = t ^ n • z := by have had := g.det_coe replace had : ↑ₘg 0 0 * ↑ₘg 1 1 = 1; · rw [det_fin_two, hc] at had linarith rcases Int.eq_one_or_neg_one_of_mul_eq_one' had with (⟨ha, hd⟩ | ⟨ha, hd⟩) · use ↑ₘg 0 1 suffices g = T ^ ↑ₘg 0 1 by intro z conv_lhs => rw [this] ext (i j) fin_cases i <;> fin_cases j <;> simp [ha, hc, hd, coe_T_zpow] · use -↑ₘg 0 1 suffices g = -T ^ (-↑ₘg 0 1) by intro z conv_lhs => rw [this, SL_neg_smul] ext (i j) fin_cases i <;> fin_cases j <;> simp [ha, hc, hd, coe_T_zpow] #align modular_group.exists_eq_T_zpow_of_c_eq_zero ModularGroup.exists_eq_t_zpow_of_c_eq_zero /- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:73:14: unsupported tactic `congrm #[[expr «expr!![ »(matrix.notation [expr _, ",", expr _, ";", expr _, ",", expr _, "]"] [])]] -/ -- If `c = 1`, then `g` factorises into a product terms involving only `T` and `S`. theorem g_eq_of_c_eq_one (hc : ↑ₘg 1 0 = 1) : g = t ^ ↑ₘg 0 0 * s * t ^ ↑ₘg 1 1 := by have hg := g.det_coe.symm replace hg : ↑ₘg 0 1 = ↑ₘg 0 0 * ↑ₘg 1 1 - 1; · rw [det_fin_two, hc] at hg linarith refine' Subtype.ext _ conv_lhs => rw [Matrix.eta_fin_two ↑ₘg] rw [hc, hg] simp only [coe_mul, coe_T_zpow, coe_S, mul_fin_two] trace "./././Mathport/Syntax/Translate/Tactic/Builtin.lean:73:14: unsupported tactic `congrm #[[expr «expr!![ »(matrix.notation [expr _, \",\", expr _, \";\", expr _, \",\", expr _, \"]\"] [])]]" <;> ring #align modular_group.g_eq_of_c_eq_one ModularGroup.g_eq_of_c_eq_one /-- If `1 < |z|`, then `|S • z| < 1`. -/ theorem normSq_s_smul_lt_one (h : 1 < normSq z) : normSq ↑(s • z) < 1 := by simpa [coe_S] using (inv_lt_inv z.norm_sq_pos zero_lt_one).mpr h #align modular_group.norm_sq_S_smul_lt_one ModularGroup.normSq_s_smul_lt_one /-- If `|z| < 1`, then applying `S` strictly decreases `im`. -/ theorem im_lt_im_s_smul (h : normSq z < 1) : z.im < (s • z).im := by have : z.im < z.im / norm_sq (z : ℂ) := by have imz : 0 < z.im := im_pos z apply (lt_div_iff z.norm_sq_pos).mpr nlinarith convert this simp only [special_linear_group.im_smul_eq_div_norm_sq] field_simp [norm_sq_denom_ne_zero, norm_sq_ne_zero, S] #align modular_group.im_lt_im_S_smul ModularGroup.im_lt_im_s_smul /-- The standard (closed) fundamental domain of the action of `SL(2,ℤ)` on `ℍ`. -/ def fd : Set ℍ := { z | 1 ≤ (z : ℂ).normSq ∧ |z.re| ≤ (1 : ℝ) / 2 } #align modular_group.fd ModularGroup.fd /-- The standard open fundamental domain of the action of `SL(2,ℤ)` on `ℍ`. -/ def fdo : Set ℍ := { z | 1 < (z : ℂ).normSq ∧ |z.re| < (1 : ℝ) / 2 } #align modular_group.fdo ModularGroup.fdo -- mathport name: modular_group.fd scoped[Modular] notation "𝒟" => ModularGroup.fd -- mathport name: modular_group.fdo scoped[Modular] notation "𝒟ᵒ" => ModularGroup.fdo theorem abs_two_mul_re_lt_one_of_mem_fdo (h : z ∈ 𝒟ᵒ) : |2 * z.re| < 1 := by rw [abs_mul, abs_two, ← lt_div_iff' (zero_lt_two' ℝ)] exact h.2 #align modular_group.abs_two_mul_re_lt_one_of_mem_fdo ModularGroup.abs_two_mul_re_lt_one_of_mem_fdo theorem three_lt_four_mul_im_sq_of_mem_fdo (h : z ∈ 𝒟ᵒ) : 3 < 4 * z.im ^ 2 := by have : 1 < z.re * z.re + z.im * z.im := by simpa [Complex.normSq_apply] using h.1 have := h.2 cases abs_cases z.re <;> nlinarith #align modular_group.three_lt_four_mul_im_sq_of_mem_fdo ModularGroup.three_lt_four_mul_im_sq_of_mem_fdo /-- If `z ∈ 𝒟ᵒ`, and `n : ℤ`, then `|z + n| > 1`. -/ theorem one_lt_normSq_t_zpow_smul (hz : z ∈ 𝒟ᵒ) (n : ℤ) : 1 < normSq (t ^ n • z : ℍ) := by have hz₁ : 1 < z.re * z.re + z.im * z.im := hz.1 have hzn := Int.nneg_mul_add_sq_of_abs_le_one n (abs_two_mul_re_lt_one_of_mem_fdo hz).le have : 1 < (z.re + ↑n) * (z.re + ↑n) + z.im * z.im := by linarith simpa [coe_T_zpow, norm_sq] #align modular_group.one_lt_norm_sq_T_zpow_smul ModularGroup.one_lt_normSq_t_zpow_smul theorem eq_zero_of_mem_fdo_of_t_zpow_mem_fdo {n : ℤ} (hz : z ∈ 𝒟ᵒ) (hg : t ^ n • z ∈ 𝒟ᵒ) : n = 0 := by suffices |(n : ℝ)| < 1 by rwa [← Int.cast_abs, ← Int.cast_one, Int.cast_lt, Int.abs_lt_one_iff] at this have h₁ := hz.2 have h₂ := hg.2 rw [re_T_zpow_smul] at h₂ calc |(n : ℝ)| ≤ |z.re| + |z.re + (n : ℝ)| := abs_add' (n : ℝ) z.re _ < 1 / 2 + 1 / 2 := (add_lt_add h₁ h₂) _ = 1 := add_halves 1 #align modular_group.eq_zero_of_mem_fdo_of_T_zpow_mem_fdo ModularGroup.eq_zero_of_mem_fdo_of_t_zpow_mem_fdo /-- Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,ℤ)` -/ theorem exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2, ℤ), g • z ∈ 𝒟 := by -- obtain a g₀ which maximizes im (g • z), obtain ⟨g₀, hg₀⟩ := exists_max_im z -- then among those, minimize re obtain ⟨g, hg, hg'⟩ := exists_row_one_eq_and_min_re z (bottom_row_coprime g₀) refine' ⟨g, _⟩ -- `g` has same max im property as `g₀` have hg₀' : ∀ g' : SL(2, ℤ), (g' • z).im ≤ (g • z).im := by have hg'' : (g • z).im = (g₀ • z).im := by rw [special_linear_group.im_smul_eq_div_norm_sq, special_linear_group.im_smul_eq_div_norm_sq, denom_apply, denom_apply, hg] simpa only [hg''] using hg₀ constructor · -- Claim: `1 ≤ ⇑norm_sq ↑(g • z)`. If not, then `S•g•z` has larger imaginary part contrapose! hg₀' refine' ⟨S * g, _⟩ rw [mul_smul] exact im_lt_im_S_smul hg₀' · show |(g • z).re| ≤ 1 / 2 -- if not, then either `T` or `T'` decrease |Re|. rw [abs_le] constructor · contrapose! hg' refine' ⟨T * g, (T_mul_apply_one _).symm, _⟩ rw [mul_smul, re_T_smul] cases abs_cases ((g • z).re + 1) <;> cases abs_cases (g • z).re <;> linarith · contrapose! hg' refine' ⟨T⁻¹ * g, (T_inv_mul_apply_one _).symm, _⟩ rw [mul_smul, re_T_inv_smul] cases abs_cases ((g • z).re - 1) <;> cases abs_cases (g • z).re <;> linarith #align modular_group.exists_smul_mem_fd ModularGroup.exists_smul_mem_fd section UniqueRepresentative variable {z} /-- An auxiliary result en route to `modular_group.c_eq_zero`. -/ theorem abs_c_le_one (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : |↑ₘg 1 0| ≤ 1 := by let c' : ℤ := ↑ₘg 1 0 let c : ℝ := (c' : ℝ) suffices 3 * c ^ 2 < 4 by rw [← Int.cast_pow, ← Int.cast_three, ← Int.cast_four, ← Int.cast_mul, Int.cast_lt] at this replace this : c' ^ 2 ≤ 1 ^ 2 · linarith rwa [sq_le_sq, abs_one] at this suffices c ≠ 0 → 9 * c ^ 4 < 16 by rcases eq_or_ne c 0 with (hc | hc) · rw [hc] norm_num · refine' (abs_lt_of_sq_lt_sq' _ (by norm_num)).2 specialize this hc linarith intro hc replace hc : 0 < c ^ 4 · rw [pow_bit0_pos_iff] <;> trivial have h₁ := mul_lt_mul_of_pos_right (mul_lt_mul'' (three_lt_four_mul_im_sq_of_mem_fdo hg) (three_lt_four_mul_im_sq_of_mem_fdo hz) (by linarith) (by linarith)) hc have h₂ : (c * z.im) ^ 4 / norm_sq (denom (↑g) z) ^ 2 ≤ 1 := div_le_one_of_le (pow_four_le_pow_two_of_pow_two_le (UpperHalfPlane.c_mul_im_sq_le_normSq_denom z g)) (sq_nonneg _) let nsq := norm_sq (denom g z) calc 9 * c ^ 4 < c ^ 4 * z.im ^ 2 * (g • z).im ^ 2 * 16 := by linarith _ = c ^ 4 * z.im ^ 4 / nsq ^ 2 * 16 := by rw [special_linear_group.im_smul_eq_div_norm_sq, div_pow] ring _ ≤ 16 := by rw [← mul_pow] linarith #align modular_group.abs_c_le_one ModularGroup.abs_c_le_one /-- An auxiliary result en route to `modular_group.eq_smul_self_of_mem_fdo_mem_fdo`. -/ theorem c_eq_zero (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : ↑ₘg 1 0 = 0 := by have hp : ∀ {g' : SL(2, ℤ)} (hg' : g' • z ∈ 𝒟ᵒ), ↑ₘg' 1 0 ≠ 1 := by intros by_contra hc let a := ↑ₘg' 0 0 let d := ↑ₘg' 1 1 have had : T ^ (-a) * g' = S * T ^ d := by rw [g_eq_of_c_eq_one hc] group let w := T ^ (-a) • g' • z have h₁ : w = S • T ^ d • z := by simp only [w, ← mul_smul, had] replace h₁ : norm_sq w < 1 := h₁.symm ▸ norm_sq_S_smul_lt_one (one_lt_norm_sq_T_zpow_smul hz d) have h₂ : 1 < norm_sq w := one_lt_norm_sq_T_zpow_smul hg' (-a) linarith have hn : ↑ₘg 1 0 ≠ -1 := by intro hc replace hc : ↑ₘ(-g) 1 0 = 1 · simp [← neg_eq_iff_eq_neg.mpr hc] replace hg : -g • z ∈ 𝒟ᵒ := (SL_neg_smul g z).symm ▸ hg exact hp hg hc specialize hp hg rcases int.abs_le_one_iff.mp <| abs_c_le_one hz hg with ⟨⟩ <;> tauto #align modular_group.c_eq_zero ModularGroup.c_eq_zero /-- Second Main Fundamental Domain Lemma: if both `z` and `g • z` are in the open domain `𝒟ᵒ`, where `z : ℍ` and `g : SL(2,ℤ)`, then `z = g • z`. -/ theorem eq_smul_self_of_mem_fdo_mem_fdo (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z := by obtain ⟨n, hn⟩ := exists_eq_T_zpow_of_c_eq_zero (c_eq_zero hz hg) rw [hn] at hg⊢ simp [eq_zero_of_mem_fdo_of_T_zpow_mem_fdo hz hg, one_smul] #align modular_group.eq_smul_self_of_mem_fdo_mem_fdo ModularGroup.eq_smul_self_of_mem_fdo_mem_fdo end UniqueRepresentative end FundamentalDomain end ModularGroup
State Before: α : Type u_1 𝕜 : Type u_2 inst✝² : LinearOrderedField 𝕜 inst✝¹ : DecidableEq α A : Finset α P : Finpartition A G : SimpleGraph α inst✝ : DecidableRel G.Adj ε : 𝕜 hP : P.parts = ∅ ⊢ IsUniform P G ε State After: no goals Tactic: simp [IsUniform, hP, nonUniforms]
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura ! This file was ported from Lean 3 source module init.meta.smt.smt_tactic ! leanprover-community/mathlib commit 4a03bdeb31b3688c31d02d7ff8e0ff2e5d6174db ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ prelude import Leanbin.Init.Control.Default import Leanbin.Init.Meta.SimpTactic import Leanbin.Init.Meta.Smt.CongruenceClosure import Leanbin.Init.Meta.Smt.Ematch universe u run_cmd mk_simp_attr `pre_smt run_cmd mk_hinst_lemma_attr_set `ematch [] [`ematch_lhs] /-- Configuration for the smt tactic preprocessor. The preprocessor is applied whenever a new hypothesis is introduced. - simp_attr: is the attribute name for the simplification lemmas that are used during the preprocessing step. - max_steps: it is the maximum number of steps performed by the simplifier. - zeta: if tt, then zeta reduction (i.e., unfolding let-expressions) is used during preprocessing. -/ structure SmtPreConfig where simpAttr : Name := `pre_smt maxSteps : Nat := 1000000 zeta : Bool := false #align smt_pre_config SmtPreConfig /-- Configuration for the smt_state object. - em_attr: is the attribute name for the hinst_lemmas that are used for ematching -/ structure SmtConfig where ccCfg : CcConfig := { } emCfg : EmatchConfig := { } preCfg : SmtPreConfig := { } emAttr : Name := `ematch #align smt_config SmtConfig unsafe def smt_config.set_classical (c : SmtConfig) (b : Bool) : SmtConfig := { c with ccCfg := { c.ccCfg with em := b } } #align smt_config.set_classical smt_config.set_classical unsafe axiom smt_goal : Type #align smt_goal smt_goal unsafe def smt_state := List smt_goal #align smt_state smt_state unsafe axiom smt_state.mk : SmtConfig → tactic smt_state #align smt_state.mk smt_state.mk unsafe axiom smt_state.to_format : smt_state → tactic_state → format #align smt_state.to_format smt_state.to_format /-- Return tt iff classical excluded middle was enabled at smt_state.mk -/ unsafe axiom smt_state.classical : smt_state → Bool #align smt_state.classical smt_state.classical unsafe def smt_tactic := StateT smt_state tactic #align smt_tactic smt_tactic unsafe instance : Append smt_state := List.hasAppend section attribute [local reducible] smt_tactic unsafe instance : Monad smt_tactic := by infer_instance unsafe instance : Alternative smt_tactic := by infer_instance unsafe instance : MonadState smt_state smt_tactic := by infer_instance end /- We don't use the default state_t lift operation because only tactics that do not change hypotheses can be automatically lifted to smt_tactic. -/ unsafe axiom tactic_to_smt_tactic (α : Type) : tactic α → smt_tactic α #align tactic_to_smt_tactic tactic_to_smt_tactic unsafe instance : HasMonadLift tactic smt_tactic := ⟨tactic_to_smt_tactic⟩ unsafe instance (α : Type) : Coe (tactic α) (smt_tactic α) := ⟨monadLift⟩ unsafe instance : MonadFail smt_tactic := { smt_tactic.monad with fail := fun α s => (tactic.fail (to_fmt s) : smt_tactic α) } namespace SmtTactic open Tactic (Transparency) unsafe axiom intros : smt_tactic Unit #align smt_tactic.intros smt_tactic.intros unsafe axiom intron : Nat → smt_tactic Unit #align smt_tactic.intron smt_tactic.intron unsafe axiom intro_lst : List Name → smt_tactic Unit #align smt_tactic.intro_lst smt_tactic.intro_lst /-- Try to close main goal by using equalities implied by the congruence closure module. -/ unsafe axiom close : smt_tactic Unit #align smt_tactic.close smt_tactic.close /-- Produce new facts using heuristic lemma instantiation based on E-matching. This tactic tries to match patterns from lemmas in the main goal with terms in the main goal. The set of lemmas is populated with theorems tagged with the attribute specified at smt_config.em_attr, and lemmas added using tactics such as `smt_tactic.add_lemmas`. The current set of lemmas can be retrieved using the tactic `smt_tactic.get_lemmas`. Remark: the given predicate is applied to every new instance. The instance is only added to the state if the predicate returns tt. -/ unsafe axiom ematch_core : (expr → Bool) → smt_tactic Unit #align smt_tactic.ematch_core smt_tactic.ematch_core /-- Produce new facts using heuristic lemma instantiation based on E-matching. This tactic tries to match patterns from the given lemmas with terms in the main goal. -/ unsafe axiom ematch_using : hinst_lemmas → smt_tactic Unit #align smt_tactic.ematch_using smt_tactic.ematch_using unsafe axiom mk_ematch_eqn_lemmas_for_core : Transparency → Name → smt_tactic hinst_lemmas #align smt_tactic.mk_ematch_eqn_lemmas_for_core smt_tactic.mk_ematch_eqn_lemmas_for_core unsafe axiom to_cc_state : smt_tactic cc_state #align smt_tactic.to_cc_state smt_tactic.to_cc_state unsafe axiom to_em_state : smt_tactic ematch_state #align smt_tactic.to_em_state smt_tactic.to_em_state unsafe axiom get_config : smt_tactic SmtConfig #align smt_tactic.get_config smt_tactic.get_config /-- Preprocess the given term using the same simplifications rules used when we introduce a new hypothesis. The result is pair containing the resulting term and a proof that it is equal to the given one. -/ unsafe axiom preprocess : expr → smt_tactic (expr × expr) #align smt_tactic.preprocess smt_tactic.preprocess unsafe axiom get_lemmas : smt_tactic hinst_lemmas #align smt_tactic.get_lemmas smt_tactic.get_lemmas unsafe axiom set_lemmas : hinst_lemmas → smt_tactic Unit #align smt_tactic.set_lemmas smt_tactic.set_lemmas unsafe axiom add_lemmas : hinst_lemmas → smt_tactic Unit #align smt_tactic.add_lemmas smt_tactic.add_lemmas unsafe def add_ematch_lemma_core (md : Transparency) (as_simp : Bool) (e : expr) : smt_tactic Unit := do let h ← hinst_lemma.mk_core md e as_simp add_lemmas (mk_hinst_singleton h) #align smt_tactic.add_ematch_lemma_core smt_tactic.add_ematch_lemma_core unsafe def add_ematch_lemma_from_decl_core (md : Transparency) (as_simp : Bool) (n : Name) : smt_tactic Unit := do let h ← hinst_lemma.mk_from_decl_core md n as_simp add_lemmas (mk_hinst_singleton h) #align smt_tactic.add_ematch_lemma_from_decl_core smt_tactic.add_ematch_lemma_from_decl_core unsafe def add_ematch_eqn_lemmas_for_core (md : Transparency) (n : Name) : smt_tactic Unit := do let hs ← mk_ematch_eqn_lemmas_for_core md n add_lemmas hs #align smt_tactic.add_ematch_eqn_lemmas_for_core smt_tactic.add_ematch_eqn_lemmas_for_core unsafe def ematch : smt_tactic Unit := ematch_core fun _ => true #align smt_tactic.ematch smt_tactic.ematch unsafe def failed {α} : smt_tactic α := tactic.failed #align smt_tactic.failed smt_tactic.failed unsafe def fail {α : Type} {β : Type u} [has_to_format β] (msg : β) : smt_tactic α := tactic.fail msg #align smt_tactic.fail smt_tactic.fail unsafe def try {α : Type} (t : smt_tactic α) : smt_tactic Unit := ⟨fun ss ts => result.cases_on (t.run ss ts) (fun ⟨a, new_ss⟩ => result.success ((), new_ss)) fun e ref s' => result.success ((), ss) ts⟩ #align smt_tactic.try smt_tactic.try /-- `iterate_at_most n t`: repeat the given tactic at most n times or until t fails -/ unsafe def iterate_at_most : Nat → smt_tactic Unit → smt_tactic Unit | 0, t => return () | n + 1, t => (do t iterate_at_most n t) <|> return () #align smt_tactic.iterate_at_most smt_tactic.iterate_at_most /-- `iterate_exactly n t` : execute t n times -/ unsafe def iterate_exactly : Nat → smt_tactic Unit → smt_tactic Unit | 0, t => return () | n + 1, t => do t iterate_exactly n t #align smt_tactic.iterate_exactly smt_tactic.iterate_exactly unsafe def iterate : smt_tactic Unit → smt_tactic Unit := iterate_at_most 100000 #align smt_tactic.iterate smt_tactic.iterate unsafe def eblast : smt_tactic Unit := iterate (ematch >> try close) #align smt_tactic.eblast smt_tactic.eblast open Tactic protected unsafe def read : smt_tactic (smt_state × tactic_state) := do let s₁ ← get let s₂ ← tactic.read return (s₁, s₂) #align smt_tactic.read smt_tactic.read protected unsafe def write : smt_state × tactic_state → smt_tactic Unit := fun ⟨ss, ts⟩ => ⟨fun _ _ => result.success ((), ss) ts⟩ #align smt_tactic.write smt_tactic.write private unsafe def mk_smt_goals_for (cfg : SmtConfig) : List expr → List smt_goal → List expr → tactic (List smt_goal × List expr) | [], sr, tr => return (sr.reverse, tr.reverse) | tg :: tgs, sr, tr => do tactic.set_goals [tg] let [new_sg] ← smt_state.mk cfg | tactic.failed let [new_tg] ← get_goals | tactic.failed mk_smt_goals_for tgs (new_sg :: sr) (new_tg :: tr) #align smt_tactic.mk_smt_goals_for smt_tactic.mk_smt_goals_for /-- See slift -/ unsafe def slift_aux {α : Type} (t : tactic α) (cfg : SmtConfig) : smt_tactic α := ⟨fun ss => do let _ :: sgs ← return ss | tactic.fail "slift tactic failed, there no smt goals to be solved" let tg :: tgs ← tactic.get_goals | tactic.failed tactic.set_goals [tg] let a ← t let new_tgs ← tactic.get_goals let (new_sgs, new_tgs) ← mk_smt_goals_for cfg new_tgs [] [] tactic.set_goals (new_tgs ++ tgs) return (a, new_sgs ++ sgs)⟩ #align smt_tactic.slift_aux smt_tactic.slift_aux /-- This lift operation will restart the SMT state. It is useful for using tactics that change the set of hypotheses. -/ unsafe def slift {α : Type} (t : tactic α) : smt_tactic α := get_config >>= slift_aux t #align smt_tactic.slift smt_tactic.slift unsafe def trace_state : smt_tactic Unit := do let (s₁, s₂) ← smt_tactic.read trace (smt_state.to_format s₁ s₂) #align smt_tactic.trace_state smt_tactic.trace_state unsafe def trace {α : Type} [has_to_tactic_format α] (a : α) : smt_tactic Unit := tactic.trace a #align smt_tactic.trace smt_tactic.trace unsafe def to_expr (q : pexpr) (allow_mvars := true) : smt_tactic expr := tactic.to_expr q allow_mvars #align smt_tactic.to_expr smt_tactic.to_expr unsafe def classical : smt_tactic Bool := do let s ← get return s #align smt_tactic.classical smt_tactic.classical unsafe def num_goals : smt_tactic Nat := List.length <$> get #align smt_tactic.num_goals smt_tactic.num_goals -- Low level primitives for managing set of goals unsafe def get_goals : smt_tactic (List smt_goal × List expr) := do let (g₁, _) ← smt_tactic.read let g₂ ← tactic.get_goals return (g₁, g₂) #align smt_tactic.get_goals smt_tactic.get_goals unsafe def set_goals : List smt_goal → List expr → smt_tactic Unit := fun g₁ g₂ => ⟨fun ss => tactic.set_goals g₂ >> return ((), g₁)⟩ #align smt_tactic.set_goals smt_tactic.set_goals private unsafe def all_goals_core (tac : smt_tactic Unit) : List smt_goal → List expr → List smt_goal → List expr → smt_tactic Unit | [], ts, acs, act => set_goals acs (ts ++ act) | s :: ss, [], acs, act => fail "ill-formed smt_state" | s :: ss, t :: ts, acs, act => do set_goals [s] [t] tac let (new_ss, new_ts) ← get_goals all_goals_core ss ts (acs ++ new_ss) (act ++ new_ts) #align smt_tactic.all_goals_core smt_tactic.all_goals_core /-- Apply the given tactic to all goals. -/ unsafe def all_goals (tac : smt_tactic Unit) : smt_tactic Unit := do let (ss, ts) ← get_goals all_goals_core tac ss ts [] [] #align smt_tactic.all_goals smt_tactic.all_goals /-- LCF-style AND_THEN tactic. It applies tac1, and if succeed applies tac2 to each subgoal produced by tac1 -/ unsafe def seq (tac1 : smt_tactic Unit) (tac2 : smt_tactic Unit) : smt_tactic Unit := do let (s :: ss, t :: ts) ← get_goals set_goals [s] [t] tac1 all_goals tac2 let (new_ss, new_ts) ← get_goals set_goals (new_ss ++ ss) (new_ts ++ ts) #align smt_tactic.seq smt_tactic.seq unsafe instance : AndThen' (smt_tactic Unit) (smt_tactic Unit) (smt_tactic Unit) := ⟨seq⟩ unsafe def focus1 {α} (tac : smt_tactic α) : smt_tactic α := do let (s :: ss, t :: ts) ← get_goals match ss with | [] => tac | _ => do set_goals [s] [t] let a ← tac let (ss', ts') ← get_goals set_goals (ss' ++ ss) (ts' ++ ts) return a #align smt_tactic.focus1 smt_tactic.focus1 unsafe def solve1 (tac : smt_tactic Unit) : smt_tactic Unit := do let (ss, gs) ← get_goals match ss, gs with | [], _ => fail "solve1 tactic failed, there isn't any goal left to focus" | _, [] => fail "solve1 tactic failed, there isn't any smt goal left to focus" | s :: ss, g :: gs => do set_goals [s] [g] tac let (ss', gs') ← get_goals match ss', gs' with | [], [] => set_goals ss gs | _, _ => fail "solve1 tactic failed, focused goal has not been solved" #align smt_tactic.solve1 smt_tactic.solve1 unsafe def swap : smt_tactic Unit := do let (ss, ts) ← get_goals match ss, ts with | s₁ :: s₂ :: ss, t₁ :: t₂ :: ts => set_goals (s₂ :: s₁ :: ss) (t₂ :: t₁ :: ts) | _, _ => failed #align smt_tactic.swap smt_tactic.swap /-- Add a new goal for t, and the hypothesis (h : t) in the current goal. -/ unsafe def assert (h : Name) (t : expr) : smt_tactic Unit := (((tactic.assert_core h t >> swap) >> intros) >> swap) >> try close #align smt_tactic.assert smt_tactic.assert /-- Add the hypothesis (h : t) in the current goal if v has type t. -/ unsafe def assertv (h : Name) (t : expr) (v : expr) : smt_tactic Unit := (tactic.assertv_core h t v >> intros) >> return () #align smt_tactic.assertv smt_tactic.assertv /-- Add a new goal for t, and the hypothesis (h : t := ?M) in the current goal. -/ unsafe def define (h : Name) (t : expr) : smt_tactic Unit := (((tactic.define_core h t >> swap) >> intros) >> swap) >> try close #align smt_tactic.define smt_tactic.define /-- Add the hypothesis (h : t := v) in the current goal if v has type t. -/ unsafe def definev (h : Name) (t : expr) (v : expr) : smt_tactic Unit := (tactic.definev_core h t v >> intros) >> return () #align smt_tactic.definev smt_tactic.definev /-- Add (h : t := pr) to the current goal -/ unsafe def pose (h : Name) (t : Option expr := none) (pr : expr) : smt_tactic Unit := match t with | none => do let t ← infer_type pr definev h t pr | some t => definev h t pr #align smt_tactic.pose smt_tactic.pose /-- Add (h : t) to the current goal, given a proof (pr : t) -/ unsafe def note (h : Name) (t : Option expr := none) (pr : expr) : smt_tactic Unit := match t with | none => do let t ← infer_type pr assertv h t pr | some t => assertv h t pr #align smt_tactic.note smt_tactic.note unsafe def destruct (e : expr) : smt_tactic Unit := smt_tactic.seq (tactic.destruct e) smt_tactic.intros #align smt_tactic.destruct smt_tactic.destruct unsafe def by_cases (e : expr) : smt_tactic Unit := do let c ← classical if c then destruct (expr.app (expr.const `classical.em []) e) else do let dec_e ← mk_app `decidable [e] <|> fail "by_cases smt_tactic failed, type is not a proposition" let inst ← mk_instance dec_e <|> fail "by_cases smt_tactic failed, type of given expression is not decidable" let em ← mk_app `decidable.em [e, inst] destruct em #align smt_tactic.by_cases smt_tactic.by_cases unsafe def by_contradiction : smt_tactic Unit := do let t ← target let c ← classical if t then skip else if c then do apply (expr.app (expr.const `classical.by_contradiction []) t) intros else do let dec_t ← mk_app `decidable [t] <|> fail "by_contradiction smt_tactic failed, target is not a proposition" let inst ← mk_instance dec_t <|> fail "by_contradiction smt_tactic failed, target is not decidable" let a ← mk_mapp `decidable.by_contradiction [some t, some inst] apply a intros #align smt_tactic.by_contradiction smt_tactic.by_contradiction /-- Return a proof for e, if 'e' is a known fact in the main goal. -/ unsafe def proof_for (e : expr) : smt_tactic expr := do let cc ← to_cc_state cc e #align smt_tactic.proof_for smt_tactic.proof_for /-- Return a refutation for e (i.e., a proof for (not e)), if 'e' has been refuted in the main goal. -/ unsafe def refutation_for (e : expr) : smt_tactic expr := do let cc ← to_cc_state cc e #align smt_tactic.refutation_for smt_tactic.refutation_for unsafe def get_facts : smt_tactic (List expr) := do let cc ← to_cc_state return <| cc expr.mk_true #align smt_tactic.get_facts smt_tactic.get_facts unsafe def get_refuted_facts : smt_tactic (List expr) := do let cc ← to_cc_state return <| cc expr.mk_false #align smt_tactic.get_refuted_facts smt_tactic.get_refuted_facts unsafe def add_ematch_lemma : expr → smt_tactic Unit := add_ematch_lemma_core reducible false #align smt_tactic.add_ematch_lemma smt_tactic.add_ematch_lemma unsafe def add_ematch_lhs_lemma : expr → smt_tactic Unit := add_ematch_lemma_core reducible true #align smt_tactic.add_ematch_lhs_lemma smt_tactic.add_ematch_lhs_lemma unsafe def add_ematch_lemma_from_decl : Name → smt_tactic Unit := add_ematch_lemma_from_decl_core reducible false #align smt_tactic.add_ematch_lemma_from_decl smt_tactic.add_ematch_lemma_from_decl unsafe def add_ematch_lhs_lemma_from_decl : Name → smt_tactic Unit := add_ematch_lemma_from_decl_core reducible false #align smt_tactic.add_ematch_lhs_lemma_from_decl smt_tactic.add_ematch_lhs_lemma_from_decl unsafe def add_ematch_eqn_lemmas_for : Name → smt_tactic Unit := add_ematch_eqn_lemmas_for_core reducible #align smt_tactic.add_ematch_eqn_lemmas_for smt_tactic.add_ematch_eqn_lemmas_for /- ./././Mathport/Syntax/Translate/Expr.lean:207:4: warning: unsupported notation `f -/ unsafe def add_lemmas_from_facts_core : List expr → smt_tactic Unit | [] => return () | f :: fs => do try ((is_prop f >> guard (f && not (f f.is_arrow))) >> proof_for f >>= add_ematch_lemma_core reducible ff) add_lemmas_from_facts_core fs #align smt_tactic.add_lemmas_from_facts_core smt_tactic.add_lemmas_from_facts_core unsafe def add_lemmas_from_facts : smt_tactic Unit := get_facts >>= add_lemmas_from_facts_core #align smt_tactic.add_lemmas_from_facts smt_tactic.add_lemmas_from_facts unsafe def induction (e : expr) (ids : List Name := []) (rec : Option Name := none) : smt_tactic Unit := slift (tactic.induction e ids rec >> return ()) #align smt_tactic.induction smt_tactic.induction -- pass on the information? unsafe def when (c : Prop) [Decidable c] (tac : smt_tactic Unit) : smt_tactic Unit := if c then tac else skip #align smt_tactic.when smt_tactic.when unsafe def when_tracing (n : Name) (tac : smt_tactic Unit) : smt_tactic Unit := when (is_trace_enabled_for n = true) tac #align smt_tactic.when_tracing smt_tactic.when_tracing end SmtTactic open SmtTactic unsafe def using_smt {α} (t : smt_tactic α) (cfg : SmtConfig := { }) : tactic α := do let ss ← smt_state.mk cfg let (a, _) ← (do let a ← t iterate close return a).run ss return a #align using_smt using_smt unsafe def using_smt_with {α} (cfg : SmtConfig) (t : smt_tactic α) : tactic α := using_smt t cfg #align using_smt_with using_smt_with
lemma prime_nat_int_transfer [simp]: "prime (int n) \<longleftrightarrow> prime n" (is "?P \<longleftrightarrow> ?Q")
PJ Masks - what time is it on TV? Episode 26 Series 1 cast list and preview. Romeo plans to use his newest device to make everyone in the world so clumsy that they can't stop him.
= The First Tale > module WhoStoleTheTarts.TheFirstTale > > %access export > %default total > > %hide Prelude.Pairs.DPair.fst Someone stole the jam. Our job is to figure out who the thief was. == Suspects We know it was one of the - March Hare, > data MarchHare - Mad Hatter, or > data MadHatter - Dormouse > data Dormouse ... and that they worked alone. > SomeoneStoleTheJam : Type > SomeoneStoleTheJam = Either ( MarchHare, Not MadHatter, Not Dormouse) > $ Either (Not MarchHare, MadHatter, Not Dormouse) > (Not MarchHare, Not MadHatter, Dormouse) == Statements The March Hare claims, <blockquote> I never stole the jam! </blockquote> > MarchHareStatement : (truth : Bool) -> Type > MarchHareStatement False = MarchHare > MarchHareStatement True = Not MarchHare According to the Mad Hatter, <blockquote> One of us stole it, but it wasn't me! </blockquote> > MadHatterStatement : (truth : Bool) -> Type > MadHatterStatement False = ( MadHatter, Not MarchHare, Not Dormouse) > MadHatterStatement True = (Not MadHatter, Either MarchHare Dormouse) As per the Dormouse, <blockquote> At least one of them (spoke the truth). </blockquote> > DormouseStatement : (truth : Bool) -> Type > DormouseStatement False = (MarchHareStatement False, MadHatterStatement False) > DormouseStatement True = Not (MarchHareStatement False, MadHatterStatement False) == Revelation We're also given a revelation: > Revelation : Type The March Hare and the Dormouse were not both speaking the truth, i.e. either - ... the March Hare spoke the truth and the Dormouse did not > Revelation = Either (MarchHareStatement True, DormouseStatement False) - ... or the March Hare did not speak the truth and the Dormouse did. > (MarchHareStatement False, DormouseStatement True) == Conclusion Given the [statements](#statements) above and the [revelation](#revelation), > Thief : SomeoneStoleTheJam -> Revelation ... we can conclude the March Hare stole the jam. > -> (MarchHare, Not MadHatter, Not Dormouse) The first clause is a simple pattern match. > Thief (Left marchHare) _ = marchHare From the revelation it follows that if the March Hare spoke the truth, then the Dormouse lied. If the March Hare spoke the truth, then they didn't steal the jam. But if the Dormouse lied, then so did the March Hare and is guilty *BWOC*. > Thief _ (Left (itWas,(them,_))) = absurd (itWas them) If the March Hare lied, then they stole the jam. > Thief (Left (_,did,it)) (Right (marchHare,_)) = (marchHare,did,it) If we assume the Mad Hatter stole jam and the March Hare lied, then the March Hare did it *BWOC*. > Thief (Right (Left (itWas,_))) (Right (them,_)) = absurd (itWas them) Assume the Dormouse did it and lied. If the Dormouse lied, then the March Hare lied, and therefore stole the jam. > Thief (Right (Right (itWas,_))) (Left (_,(them,_))) = absurd (itWas them) Assume the Dormouse did it and the March Hare lied. If the March Hare lied then they are guilty. > Thief (Right (Right (itWas,_))) (Right (them,_)) = absurd (itWas them) ∎
[STATEMENT] lemma C_eq_RS1n: "C(list2FWpolicy (removeShadowRules1_alternative p)) = C(list2FWpolicy p)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] proof (cases "p") [PROOF STATE] proof (state) goal (2 subgoals): 1. p = [] \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) 2. \<And>a list. p = a # list \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] print_cases [PROOF STATE] proof (state) goal (2 subgoals): 1. p = [] \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) 2. \<And>a list. p = a # list \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] case Nil [PROOF STATE] proof (state) this: p = [] goal (2 subgoals): 1. p = [] \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) 2. \<And>a list. p = a # list \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] then [PROOF STATE] proof (chain) picking this: p = [] [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: p = [] goal (1 subgoal): 1. C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] apply(simp_all) [PROOF STATE] proof (prove) goal (1 subgoal): 1. p = [] \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative [])) = C undefined [PROOF STEP] by (metis list2FWpolicy.simps(1) rSR1_eq removeShadowRules1.simps(2)) [PROOF STATE] proof (state) this: C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) goal (1 subgoal): 1. \<And>a list. p = a # list \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>a list. p = a # list \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] case (Cons x list) [PROOF STATE] proof (state) this: p = x # list goal (1 subgoal): 1. \<And>a list. p = a # list \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) goal (1 subgoal): 1. C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) [PROOF STEP] apply (rule rev_induct) [PROOF STATE] proof (prove) goal (2 subgoals): 1. C (list2FWpolicy (removeShadowRules1_alternative [])) = C (list2FWpolicy []) 2. \<And>x xs. C (list2FWpolicy (removeShadowRules1_alternative xs)) = C (list2FWpolicy xs) \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative (xs @ [x]))) = C (list2FWpolicy (xs @ [x])) [PROOF STEP] apply (metis rSR1_eq removeShadowRules1.simps(2)) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>x xs. C (list2FWpolicy (removeShadowRules1_alternative xs)) = C (list2FWpolicy xs) \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative (xs @ [x]))) = C (list2FWpolicy (xs @ [x])) [PROOF STEP] subgoal for x xs [PROOF STATE] proof (prove) goal (1 subgoal): 1. C (list2FWpolicy (removeShadowRules1_alternative xs)) = C (list2FWpolicy xs) \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative (xs @ [x]))) = C (list2FWpolicy (xs @ [x])) [PROOF STEP] apply (case_tac "xs = []", simp_all) [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<lbrakk>C (list2FWpolicy (removeShadowRules1_alternative [])) = C undefined; xs = []\<rbrakk> \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative [x])) = C x 2. \<lbrakk>C (list2FWpolicy (removeShadowRules1_alternative xs)) = C (list2FWpolicy xs); xs \<noteq> []\<rbrakk> \<Longrightarrow> C (list2FWpolicy (removeShadowRules1_alternative (xs @ [x]))) = C (list2FWpolicy (xs @ [x])) [PROOF STEP] unfolding removeShadowRules1_alternative_def [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<lbrakk>C (list2FWpolicy (rev (removeShadowRules1_alternative_rev (rev [])))) = C undefined; xs = []\<rbrakk> \<Longrightarrow> C (list2FWpolicy (rev (removeShadowRules1_alternative_rev (rev [x])))) = C x 2. \<lbrakk>C (list2FWpolicy (rev (removeShadowRules1_alternative_rev (rev xs)))) = C (list2FWpolicy xs); xs \<noteq> []\<rbrakk> \<Longrightarrow> C (list2FWpolicy (rev (removeShadowRules1_alternative_rev (rev (xs @ [x]))))) = C (list2FWpolicy (xs @ [x])) [PROOF STEP] apply (case_tac x, simp_all) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>C (list2FWpolicy (rev (removeShadowRules1_alternative_rev (rev xs)))) = C (list2FWpolicy xs); xs \<noteq> []\<rbrakk> \<Longrightarrow> C (list2FWpolicy (rev (removeShadowRules1_alternative_rev (x # rev xs)))) = C (list2FWpolicy (xs @ [x])) [PROOF STEP] by (metis (no_types, opaque_lifting) CConcEnd2 CConcStart C_DenyAll RS1n_nMT aux114 domIff removeShadowRules1_alternative_def removeShadowRules1_alternative_rev.simps(2) rev.simps(2)) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done [PROOF STATE] proof (state) this: C (list2FWpolicy (removeShadowRules1_alternative p)) = C (list2FWpolicy p) goal: No subgoals! [PROOF STEP] qed
------------------------------------------------------------------------ -- The Agda standard library -- -- Data.Vec.Any.Membership instantiated with propositional equality, -- along with some additional definitions. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Vec.Membership.Propositional {a} {A : Set a} where open import Data.Vec using (Vec) open import Data.Vec.Relation.Unary.Any using (Any) open import Relation.Binary.PropositionalEquality using (setoid; subst) import Data.Vec.Membership.Setoid as SetoidMembership ------------------------------------------------------------------------ -- Re-export contents of setoid membership open SetoidMembership (setoid A) public hiding (lose) ------------------------------------------------------------------------ -- Other operations lose : ∀ {p} {P : A → Set p} {x n} {xs : Vec A n} → x ∈ xs → P x → Any P xs lose = SetoidMembership.lose (setoid A) (subst _)
\documentclass[conference]{IEEEtran} \usepackage{amsmath,amssymb} \usepackage[all]{xy} \newcommand{\op}[1]{{\textsc{#1}}} \newcommand{\DB}{\mathbf{DB}} \newcommand{\DOC}{\mathbf{DOC}} \newcommand{\attr}{\mathrm{attr}} \newcommand{\textattr}{\mathrm{attr}_\mathrm{text}} \newcommand{\Val}{\mathcal{V}} \newcommand{\dom}{\mathrm{dom}} \newcommand{\Tables}{\mathrm{tables}} \newcommand{\Words}{\textsc{Words}} \newcommand{\todo}[1]{{\em TODO: #1}} \begin{document} \title{Using Document Space For Relational Search} \author{ \IEEEauthorblockN{Richard Drake} \IEEEauthorblockA{ Faculty of Science\\ University of Ontario Inst of Technology } \and \IEEEauthorblockN{Ken Pu} \IEEEauthorblockA{ Faculty of Science\\ University of Ontario Inst of Technology } } \maketitle \begin{abstract} In this paper, we present a family of methods and algorithms to efficiently integrate text indexing and keyword search from information retrieval to support search in relational databases. We propose a bi-directional transformation that maps relational database instances to document collections. The transformation is shown to be a homomorphism of keyword search. Thus, any search of tuple networks by a keyword query can be efficiently executed as a search for documents, and vice versa. By this construction, we demonstrate that indexing and search technologies developed for documents can naturally be reduced and integrated into relational database systems. \end{abstract} \section{Motivation} Information retrieval has been an active and fruitful field of research since 1960's. With seminal work by \cite{jones72} and \cite{salton75}, the IR community has laid the foundation of automatic text indexing and keyword query processing of text documents. The technology for document indexing continues to gain momentum with the growing presence of text data found on the Web and in social media. For instance, new techniques by \cite{janu12} and \cite{goyal13} improve on the traditional similarity measures by incorporating further (NLP) on the context of phrases and words. In the last decade, there has been a tremendous interest from the database community to support keyword search queries for structured relational databases. Systems such as {\em Discover} \cite{hris02}, {\em DBxplorer} \cite{agrawal2002dbxplorer} and {\em BANKS} \cite{bhalotia2002keyword} and many others \cite{hristidis2003efficient,liu2006effective} model relational tuples as documents, and foreign key joins as links. Thus, it's possible to derive IR-style scoring function for document similarity. More recently, semantic information \cite{zeng2013semantic}, schema and meta data \cite{bergamaschi2011keyword} have been incorporated into the search algorithm. We are motivated to explore the possibility of a unified framework to integrate and reuse indexing and search algorithms from IR system and databases. In particular, our interest is to construct a pair of transformations: \begin{eqnarray*} h &:& \mathbf{DB} \to \mathbf{DOC} \\ g &:& \mathbf{DOC} \to \mathbf{DB} \end{eqnarray*} where $\mathbf{DB}$ is the domain of databases and $\mathbf{DOC}$ is the domain of collections of documents. We want to design $h$ and $g$ satisfying the following: \begin{displaymath} \xymatrix { \mathbf{DB} \ar[r]^h\ar[d]_{\op{search}_\mathbf{DB}} & \mathbf{DOC}\ar[d]^{\op{search}_\mathbf{DOC}} \\ \mathbf{DB} & \mathbf{DOC}\ar[l]^g } \end{displaymath} where $\op{search}_\DB$ and $\op{search}_\DOC$ are the search functions for relational databases and documents respectively. Practical experiences have demonstrated that the state-of-the-art $\op{search}_\DOC$ has more performant implementations (\cite{xapian,lucene}) compared to its relational database counter part. Our interest is to construct efficient transformations $h$ and $g$ such that relational search $\op{search}_\DB$ can be efficiently implemented as a composition of $g\circ \op{search}_\DOC\circ h$, effectively taking advantage of the document search technology. \section{Problem Definition} In this section, we present the formal definition of relational databases and collections of documents. We also formalize the notion of keyword search entity graphs and join networks of entity graphs in relational databases. \subsection{Relational entities} A relational database consists of a collection of tables which are interconnected via joinable linkages. A table, $T$, has a number of attributes: $$ \attr(T) $$ A tuple in a table $r\in T$ is defined as a mapping from attributes to values: $$ r:\attr(T)\to\Val\quad \mbox{such that } r(\alpha)\in\dom(\alpha) $$ Given two tables $T$ and $T'$, a joinable linkage $L=\left<A,B\right>$, is defined as two lists of attributes of equal length. $$A = \left<\alpha_1, \alpha_2, \dots, \alpha_n\right>$$ $$B = \left<\beta_1, \beta_2, \dots, \beta_n\right>$$ such that $\alpha_i\in\attr(T)$ and $\beta_j\in\attr(T')$. Furthermore, $$ \forall\ i\leq n,\quad \dom(\alpha_i) = \dom(\beta_i)$$ The set of all linkages are denoted as $\mathcal{L}$. Two tables $T$ and $T'$ are joinable by some link $L=\left<A,B\right>$, written $T\sim_L T'$ if $$A\subseteq\attr(T)\mbox{ and } B\subseteq\attr(T')$$ Two tuples $r\in T$ and $r'\in T'$ are joinable by some link $L=\left<A,B\right>$, written $r\sim_L r'$ if $$ T\sim_L T'\quad\mbox{and}\quad r[A] = r[B] $$ \textbf{Entity groups: schema and instances} An {entity group schema}, $G$, is characterized by a {\em forest} of tables connected by joinable links. $$G = (V_G, E_G)$$ where $V_G \subseteq \Tables(\DB)$, and $E_G\subseteq\mathcal{L}$. A $G$-entity instance, $g$, is a forest of tuples $$\{r_T : T\in V_G\} \mbox{ where } r_T\in T$$ connected by edges: $$\left<r_T, r_{T'}\right> \mbox{ where } T\sim T' \mbox{ wrt } E_G$$ {\bf Networks of entity group instances} Two entity group instances, $g$ and $g'$, are {\em connected} if $$\Tables(g)\cap\Tables(g')\not=\emptyset$$ and for some $T\in\Tables(g)\cap\Tables(g')$, we have: $$\exists\alpha\in\attr(T), g_T(\alpha) = g'_T(\alpha)$$ \subsection{Keyword search queries} A {\em keyword query} is a bag of words. $$ Q = \{w_1, w_2, \dots, w_n\} $$ A tuple $r\in T$ in some table $T$ satisfies the keyword query if $$\exists \alpha\in\textattr(T),\ \Words(r(\alpha))\cap Q\not=\empty$$ \bibliographystyle{IEEEtran} \bibliography{references} \end{document}
------------------------------------------------------------------------ -- Instantiation of Contractive for streams ------------------------------------------------------------------------ -- Taken from the paper. -- The definition of Eq has been changed slightly, as compared to the -- paper. The paper uses -- Eq = λ n xs ys → take n xs ≡ take n ys. -- The reason for the change is that with the definition above -- coherence does not say anything about the first element in limU s. -- With the definition in the paper head (s 0), which is the first -- element in limU s, does not have to be related to head (s n) for -- any other n, and this makes it impossible to prove isLimitU. -- (Unless I have missed something.) module Contractive.Stream {A : Set} where open import Codata.Musical.Notation open import Codata.Musical.Stream open import Contractive open import Data.Nat open import Data.Nat.Induction open import Data.Nat.Properties import Data.Vec as Vec open Vec using (_∷_; []) open import Function open import Relation.Unary open import Relation.Binary.PropositionalEquality <′-isWellFoundedOrder : IsWellFoundedOrder _<′_ <′-isWellFoundedOrder = record { trans = λ {i} {j} {k} i+1≤j j+1≤k → ≤⇒≤′ (begin suc i ≤⟨ ≤′⇒≤ (≤′-step i+1≤j) ⟩ suc j ≤⟨ ≤′⇒≤ j+1≤k ⟩ k ∎) ; isWellFounded = <′-wellFounded } where open ≤-Reasoning ofe : OFE ofe = record { Carrier = ℕ ; Domain = Stream A ; _<_ = _<′_ ; isWellFoundedOrder = <′-isWellFoundedOrder ; Eq = λ n xs ys → take (suc n) xs ≡ take (suc n) ys ; isEquivalence = λ _ → record { refl = refl ; sym = sym ; trans = trans } } open OFE ofe private limU : (ℕ → Stream A) → Stream A limU s = head (s 0) ∷ ♯ limU (tail ∘ s ∘ suc) η : ∀ {n} {xs : Stream A} → Eq n xs (head xs ∷ ♯ tail xs) η {xs = x ∷ xs} = refl step : ∀ s → IsCoherent {U} (lift s) → IsCoherent {U} (lift (tail ∘ s ∘ suc)) step s coh {m} {n} _ _ m<n = begin take (suc m) (tail (s (suc m))) ≡⟨ lem (s (suc m)) ⟩ Vec.tail (take (2 + m) (s (1 + m))) ≡⟨ cong Vec.tail $ coh {1 + m} {1 + n} _ _ (s≤′s m<n) ⟩ Vec.tail (take (2 + m) (s (1 + n))) ≡⟨ sym $ lem (s (suc n)) ⟩ take (suc m) (tail (s (suc n))) ∎ where open ≡-Reasoning lem : ∀ {n} (xs : Stream A) → take n (tail xs) ≡ Vec.tail (take (1 + n) xs) lem (x ∷ xs) = refl isLimitU : ∀ s → IsCoherent {U} (lift s) → IsLimit {U} (lift s) (limU s) isLimitU s coh {zero} _ = begin take 1 (s 0) ≡⟨ η ⟩ head (s 0) ∷ [] ∎ where open ≡-Reasoning isLimitU s coh {suc n} _ = begin take (2 + n) (s (1 + n)) ≡⟨ η ⟩ head (s (1 + n)) ∷ take (1 + n) ((tail ∘ s ∘ suc) n) ≡⟨ cong₂ _∷_ lem₁ (isLimitU (tail ∘ s ∘ suc) (step s coh) {n} _) ⟩ head (s 0) ∷ take (1 + n) (limU (tail ∘ s ∘ suc)) ∎ where open ≡-Reasoning lem₂ : ∀ {n} (xs ys : Stream A) → Eq n xs ys → head xs ≡ head ys lem₂ (x ∷ xs) (y ∷ ys) = cong Vec.head lem₁ : head (s (1 + n)) ≡ head (s 0) lem₁ = lem₂ _ _ $ sym $ coh {0} {suc n} _ _ (s≤′s z≤′n) lim↓ : A → ∀ n → (∀ n' → n' <′ n → Stream A) → Stream A lim↓ x zero s = repeat x lim↓ x (suc n) s = s n ≤′-refl isLimit↓ : ∀ x n (s : Family (↓ n)) → IsCoherent s → IsLimit s (lim↓ x n s) isLimit↓ x zero s coh () isLimit↓ x (suc n) s coh ≤′-refl = refl isLimit↓ x (suc n) s coh (≤′-step m<n) = coh (≤′-step m<n) ≤′-refl m<n -- The paper implicitly assumes that A is non-empty. cofe : A → COFE cofe x = record { ofe = ofe ; limU = limU ; isLimitU = isLimitU _ ; lim↓ = lim↓ x ; isLimit↓ = λ n {s} → isLimit↓ x n s }
A recurring theme in these myths is the effort of the gods to maintain maat against the forces of disorder . They fight vicious battles with the forces of chaos at the start of creation . Ra and Apep , battling each other each night , continue this struggle into the present . Another prominent theme is the gods ' death and revival . The clearest instance where a god dies is the myth of Osiris ' murder , in which that god is resurrected as ruler of the Duat . The sun god is also said to grow old during his daily journey across the sky , sink into the Duat at night , and emerge as a young child at dawn . In the process he comes into contact with the rejuvenating water of primordial chaos . Funerary texts that depict Ra 's journey through the Duat also show the corpses of gods who are enlivened along with him . Instead of being <unk> immortal , the gods periodically died and were reborn by repeating the events of creation , thus renewing the whole world . But it was always possible for this cycle to be disrupted and for chaos to return . Some poorly understood Egyptian texts even suggest that this calamity is destined to happen — that the creator god will one day dissolve the order of the world , leaving only himself and Osiris amid the primordial chaos .
(************************************************************************) (* * The Coq Proof Assistant / The Coq Development Team *) (* v * INRIA, CNRS and contributors - Copyright 1999-2018 *) (* <O___,, * (see CREDITS file for the list of authors) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************) (* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) Require Import ssreflect. Axiom daemon : False. Ltac myadmit := case: daemon. Ltac T1 x := match goal with |- _ => set t := (x in X in _ = X) end. Ltac T2 x := first [set t := (x in RHS)]. Ltac T3 x := first [set t := (x in Y in _ = Y)|idtac]. Ltac T4 x := set t := (x in RHS); idtac. Ltac T5 x := match goal with |- _ => set t := (x in RHS) | |- _ => idtac end. Require Import ssrbool TestSuite.ssr_mini_mathcomp. Open Scope nat_scope. Lemma foo x y : x.+1 = y + x.+1. set t := (_.+1 in RHS). match goal with |- x.+1 = y + t => rewrite /t {t} end. set t := (x in RHS). match goal with |- x.+1 = y + t.+1 => rewrite /t {t} end. set t := (x in _ = x). match goal with |- x.+1 = t => rewrite /t {t} end. set t := (x in X in _ = X). match goal with |- x.+1 = y + t.+1 => rewrite /t {t} end. set t := (x in RHS). match goal with |- x.+1 = y + t.+1 => rewrite /t {t} end. set t := (y + (1 + x) as X in _ = X). match goal with |- x.+1 = t => rewrite /t addSn add0n {t} end. set t := x.+1. match goal with |- t = y + t => rewrite /t {t} end. set t := (x).+1. match goal with |- t = y + t => rewrite /t {t} end. set t := ((x).+1 in X in _ = X). match goal with |- x.+1 = y + t => rewrite /t {t} end. set t := (x.+1 in RHS). match goal with |- x.+1 = y + t => rewrite /t {t} end. T1 (x.+1). match goal with |- x.+1 = y + t => rewrite /t {t} end. T2 (x.+1). match goal with |- x.+1 = y + t => rewrite /t {t} end. T3 (x.+1). match goal with |- x.+1 = y + t => rewrite /t {t} end. T4 (x.+1). match goal with |- x.+1 = y + t => rewrite /t {t} end. T5 (x.+1). match goal with |- x.+1 = y + t => rewrite /t {t} end. rewrite [RHS]addnC. match goal with |- x.+1 = x.+1 + y => rewrite -[RHS]addnC end. rewrite -[in RHS](@subnK 1 x.+1) //. match goal with |- x.+1 = y + (x.+1 - 1 + 1) => rewrite subnK // end. have H : x.+1 = y by myadmit. set t := _.+1 in H |- *. match goal with H : t = y |- t = y + t => rewrite /t {t} in H * end. set t := (_.+1 in X in _ + X) in H |- *. match goal with H : x.+1 = y |- x.+1 = y + t => rewrite /t {t} in H * end. set t := 0. match goal with t := 0 |- x.+1 = y + x.+1 => clear t end. set t := y + _. match goal with |- x.+1 = t => rewrite /t {t} end. set t : nat := 0. clear t. set t : nat := (x in RHS). match goal with |- x.+1 = y + t.+1 => rewrite /t {t} end. set t : nat := RHS. match goal with |- x.+1 = t => rewrite /t {t} end. (* set t := 0 + _. *) (* set t := (x).+1 in X in _ + X in H |-. *) (* set t := (x).+1 in X in _ = X.*) Admitted.
[STATEMENT] lemma compatible_Fst_Snd[simp]: \<open>compatible Fst Snd\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. compatible Fst Snd [PROOF STEP] apply (rule compatibleI, simp, simp) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>a b. Fst a *\<^sub>u Snd b = Snd b *\<^sub>u Fst a [PROOF STEP] by (simp add: Fst_def Snd_def comp_tensor_op)
(* Title: ZF/Induct/FoldSet.thy Author: Sidi O Ehmety, Cambridge University Computer Laboratory A "fold" functional for finite sets. For n non-negative we have fold f e {x1,...,xn} = f x1 (... (f xn e)) where f is at least left-commutative. *) theory FoldSet imports ZF begin consts fold_set :: "[i, i, [i,i]=>i, i] => i" inductive domains "fold_set(A, B, f,e)" \<subseteq> "Fin(A)*B" intros emptyI: "e\<in>B ==> <0, e>\<in>fold_set(A, B, f,e)" consI: "[| x\<in>A; x \<notin>C; <C,y> \<in> fold_set(A, B,f,e); f(x,y):B |] ==> <cons(x,C), f(x,y)>\<in>fold_set(A, B, f, e)" type_intros Fin.intros definition fold :: "[i, [i,i]=>i, i, i] => i" ("fold[_]'(_,_,_')") where "fold[B](f,e, A) == THE x. <A, x>\<in>fold_set(A, B, f,e)" definition setsum :: "[i=>i, i] => i" where "setsum(g, C) == if Finite(C) then fold[int](%x y. g(x) $+ y, #0, C) else #0" (** foldSet **) inductive_cases empty_fold_setE: "<0, x> \<in> fold_set(A, B, f,e)" inductive_cases cons_fold_setE: "<cons(x,C), y> \<in> fold_set(A, B, f,e)" (* add-hoc lemmas *) lemma cons_lemma1: "[| x\<notin>C; x\<notin>B |] ==> cons(x,B)=cons(x,C) \<longleftrightarrow> B = C" by (auto elim: equalityE) lemma cons_lemma2: "[| cons(x, B)=cons(y, C); x\<noteq>y; x\<notin>B; y\<notin>C |] ==> B - {y} = C-{x} & x\<in>C & y\<in>B" apply (auto elim: equalityE) done (* fold_set monotonicity *) lemma fold_set_mono_lemma: "<C, x> \<in> fold_set(A, B, f, e) ==> \<forall>D. A<=D \<longrightarrow> <C, x> \<in> fold_set(D, B, f, e)" apply (erule fold_set.induct) apply (auto intro: fold_set.intros) done lemma fold_set_mono: " C<=A ==> fold_set(C, B, f, e) \<subseteq> fold_set(A, B, f, e)" apply clarify apply (frule fold_set.dom_subset [THEN subsetD], clarify) apply (auto dest: fold_set_mono_lemma) done lemma fold_set_lemma: "<C, x>\<in>fold_set(A, B, f, e) ==> <C, x>\<in>fold_set(C, B, f, e) & C<=A" apply (erule fold_set.induct) apply (auto intro!: fold_set.intros intro: fold_set_mono [THEN subsetD]) done (* Proving that fold_set is deterministic *) lemma Diff1_fold_set: "[| <C-{x},y> \<in> fold_set(A, B, f,e); x\<in>C; x\<in>A; f(x, y):B |] ==> <C, f(x, y)> \<in> fold_set(A, B, f, e)" apply (frule fold_set.dom_subset [THEN subsetD]) apply (erule cons_Diff [THEN subst], rule fold_set.intros, auto) done locale fold_typing = fixes A and B and e and f assumes ftype [intro,simp]: "[|x \<in> A; y \<in> B|] ==> f(x,y) \<in> B" and etype [intro,simp]: "e \<in> B" and fcomm: "[|x \<in> A; y \<in> A; z \<in> B|] ==> f(x, f(y, z))=f(y, f(x, z))" lemma (in fold_typing) Fin_imp_fold_set: "C\<in>Fin(A) ==> (\<exists>x. <C, x> \<in> fold_set(A, B, f,e))" apply (erule Fin_induct) apply (auto dest: fold_set.dom_subset [THEN subsetD] intro: fold_set.intros etype ftype) done lemma Diff_sing_imp: "[|C - {b} = D - {a}; a \<noteq> b; b \<in> C|] ==> C = cons(b,D) - {a}" by (blast elim: equalityE) lemma (in fold_typing) fold_set_determ_lemma [rule_format]: "n\<in>nat ==> \<forall>C. |C|<n \<longrightarrow> (\<forall>x. <C, x> \<in> fold_set(A, B, f,e)\<longrightarrow> (\<forall>y. <C, y> \<in> fold_set(A, B, f,e) \<longrightarrow> y=x))" apply (erule nat_induct) apply (auto simp add: le_iff) apply (erule fold_set.cases) apply (force elim!: empty_fold_setE) apply (erule fold_set.cases) apply (force elim!: empty_fold_setE, clarify) (*force simplification of "|C| < |cons(...)|"*) apply (frule_tac a = Ca in fold_set.dom_subset [THEN subsetD, THEN SigmaD1]) apply (frule_tac a = Cb in fold_set.dom_subset [THEN subsetD, THEN SigmaD1]) apply (simp add: Fin_into_Finite [THEN Finite_imp_cardinal_cons]) apply (case_tac "x=xb", auto) apply (simp add: cons_lemma1, blast) txt\<open>case @{term "x\<noteq>xb"}\<close> apply (drule cons_lemma2, safe) apply (frule Diff_sing_imp, assumption+) txt\<open>* LEVEL 17\<close> apply (subgoal_tac "|Ca| \<le> |Cb|") prefer 2 apply (rule succ_le_imp_le) apply (simp add: Fin_into_Finite Finite_imp_succ_cardinal_Diff Fin_into_Finite [THEN Finite_imp_cardinal_cons]) apply (rule_tac C1 = "Ca-{xb}" in Fin_imp_fold_set [THEN exE]) apply (blast intro: Diff_subset [THEN Fin_subset]) txt\<open>* LEVEL 24 *\<close> apply (frule Diff1_fold_set, blast, blast) apply (blast dest!: ftype fold_set.dom_subset [THEN subsetD]) apply (subgoal_tac "ya = f(xb,xa) ") prefer 2 apply (blast del: equalityCE) apply (subgoal_tac "<Cb-{x}, xa> \<in> fold_set(A,B,f,e)") prefer 2 apply simp apply (subgoal_tac "yb = f (x, xa) ") apply (drule_tac [2] C = Cb in Diff1_fold_set, simp_all) apply (blast intro: fcomm dest!: fold_set.dom_subset [THEN subsetD]) apply (blast intro: ftype dest!: fold_set.dom_subset [THEN subsetD], blast) done lemma (in fold_typing) fold_set_determ: "[| <C, x>\<in>fold_set(A, B, f, e); <C, y>\<in>fold_set(A, B, f, e)|] ==> y=x" apply (frule fold_set.dom_subset [THEN subsetD], clarify) apply (drule Fin_into_Finite) apply (unfold Finite_def, clarify) apply (rule_tac n = "succ (n)" in fold_set_determ_lemma) apply (auto intro: eqpoll_imp_lepoll [THEN lepoll_cardinal_le]) done (** The fold function **) lemma (in fold_typing) fold_equality: "<C,y> \<in> fold_set(A,B,f,e) ==> fold[B](f,e,C) = y" apply (unfold fold_def) apply (frule fold_set.dom_subset [THEN subsetD], clarify) apply (rule the_equality) apply (rule_tac [2] A=C in fold_typing.fold_set_determ) apply (force dest: fold_set_lemma) apply (auto dest: fold_set_lemma) apply (simp add: fold_typing_def, auto) apply (auto dest: fold_set_lemma intro: ftype etype fcomm) done lemma fold_0 [simp]: "e \<in> B ==> fold[B](f,e,0) = e" apply (unfold fold_def) apply (blast elim!: empty_fold_setE intro: fold_set.intros) done text\<open>This result is the right-to-left direction of the subsequent result\<close> lemma (in fold_typing) fold_set_imp_cons: "[| <C, y> \<in> fold_set(C, B, f, e); C \<in> Fin(A); c \<in> A; c\<notin>C |] ==> <cons(c, C), f(c,y)> \<in> fold_set(cons(c, C), B, f, e)" apply (frule FinD [THEN fold_set_mono, THEN subsetD]) apply assumption apply (frule fold_set.dom_subset [of A, THEN subsetD]) apply (blast intro!: fold_set.consI intro: fold_set_mono [THEN subsetD]) done lemma (in fold_typing) fold_cons_lemma [rule_format]: "[| C \<in> Fin(A); c \<in> A; c\<notin>C |] ==> <cons(c, C), v> \<in> fold_set(cons(c, C), B, f, e) \<longleftrightarrow> (\<exists>y. <C, y> \<in> fold_set(C, B, f, e) & v = f(c, y))" apply auto prefer 2 apply (blast intro: fold_set_imp_cons) apply (frule_tac Fin.consI [of c, THEN FinD, THEN fold_set_mono, THEN subsetD], assumption+) apply (frule_tac fold_set.dom_subset [of A, THEN subsetD]) apply (drule FinD) apply (rule_tac A1 = "cons(c,C)" and f1=f and B1=B and C1=C and e1=e in fold_typing.Fin_imp_fold_set [THEN exE]) apply (blast intro: fold_typing.intro ftype etype fcomm) apply (blast intro: Fin_subset [of _ "cons(c,C)"] Finite_into_Fin dest: Fin_into_Finite) apply (rule_tac x = x in exI) apply (auto intro: fold_set.intros) apply (drule_tac fold_set_lemma [of C], blast) apply (blast intro!: fold_set.consI intro: fold_set_determ fold_set_mono [THEN subsetD] dest: fold_set.dom_subset [THEN subsetD]) done lemma (in fold_typing) fold_cons: "[| C\<in>Fin(A); c\<in>A; c\<notin>C|] ==> fold[B](f, e, cons(c, C)) = f(c, fold[B](f, e, C))" apply (unfold fold_def) apply (simp add: fold_cons_lemma) apply (rule the_equality, auto) apply (subgoal_tac [2] "\<langle>C, y\<rangle> \<in> fold_set(A, B, f, e)") apply (drule Fin_imp_fold_set) apply (auto dest: fold_set_lemma simp add: fold_def [symmetric] fold_equality) apply (blast intro: fold_set_mono [THEN subsetD] dest!: FinD) done lemma (in fold_typing) fold_type [simp,TC]: "C\<in>Fin(A) ==> fold[B](f,e,C):B" apply (erule Fin_induct) apply (simp_all add: fold_cons ftype etype) done lemma (in fold_typing) fold_commute [rule_format]: "[| C\<in>Fin(A); c\<in>A |] ==> (\<forall>y\<in>B. f(c, fold[B](f, y, C)) = fold[B](f, f(c, y), C))" apply (erule Fin_induct) apply (simp_all add: fold_typing.fold_cons [of A B _ f] fold_typing.fold_type [of A B _ f] fold_typing_def fcomm) done lemma (in fold_typing) fold_nest_Un_Int: "[| C\<in>Fin(A); D\<in>Fin(A) |] ==> fold[B](f, fold[B](f, e, D), C) = fold[B](f, fold[B](f, e, (C \<inter> D)), C \<union> D)" apply (erule Fin_induct, auto) apply (simp add: Un_cons Int_cons_left fold_type fold_commute fold_typing.fold_cons [of A _ _ f] fold_typing_def fcomm cons_absorb) done lemma (in fold_typing) fold_nest_Un_disjoint: "[| C\<in>Fin(A); D\<in>Fin(A); C \<inter> D = 0 |] ==> fold[B](f,e,C \<union> D) = fold[B](f, fold[B](f,e,D), C)" by (simp add: fold_nest_Un_Int) lemma Finite_cons_lemma: "Finite(C) ==> C\<in>Fin(cons(c, C))" apply (drule Finite_into_Fin) apply (blast intro: Fin_mono [THEN subsetD]) done subsection\<open>The Operator @{term setsum}\<close> lemma setsum_0 [simp]: "setsum(g, 0) = #0" by (simp add: setsum_def) lemma setsum_cons [simp]: "Finite(C) ==> setsum(g, cons(c,C)) = (if c \<in> C then setsum(g,C) else g(c) $+ setsum(g,C))" apply (auto simp add: setsum_def Finite_cons cons_absorb) apply (rule_tac A = "cons (c, C)" in fold_typing.fold_cons) apply (auto intro: fold_typing.intro Finite_cons_lemma) done lemma setsum_K0: "setsum((%i. #0), C) = #0" apply (case_tac "Finite (C) ") prefer 2 apply (simp add: setsum_def) apply (erule Finite_induct, auto) done (*The reversed orientation looks more natural, but LOOPS as a simprule!*) lemma setsum_Un_Int: "[| Finite(C); Finite(D) |] ==> setsum(g, C \<union> D) $+ setsum(g, C \<inter> D) = setsum(g, C) $+ setsum(g, D)" apply (erule Finite_induct) apply (simp_all add: Int_cons_right cons_absorb Un_cons Int_commute Finite_Un Int_lower1 [THEN subset_Finite]) done lemma setsum_type [simp,TC]: "setsum(g, C):int" apply (case_tac "Finite (C) ") prefer 2 apply (simp add: setsum_def) apply (erule Finite_induct, auto) done lemma setsum_Un_disjoint: "[| Finite(C); Finite(D); C \<inter> D = 0 |] ==> setsum(g, C \<union> D) = setsum(g, C) $+ setsum(g,D)" apply (subst setsum_Un_Int [symmetric]) apply (subgoal_tac [3] "Finite (C \<union> D) ") apply (auto intro: Finite_Un) done lemma Finite_RepFun [rule_format (no_asm)]: "Finite(I) ==> (\<forall>i\<in>I. Finite(C(i))) \<longrightarrow> Finite(RepFun(I, C))" apply (erule Finite_induct, auto) done lemma setsum_UN_disjoint [rule_format (no_asm)]: "Finite(I) ==> (\<forall>i\<in>I. Finite(C(i))) \<longrightarrow> (\<forall>i\<in>I. \<forall>j\<in>I. i\<noteq>j \<longrightarrow> C(i) \<inter> C(j) = 0) \<longrightarrow> setsum(f, \<Union>i\<in>I. C(i)) = setsum (%i. setsum(f, C(i)), I)" apply (erule Finite_induct, auto) apply (subgoal_tac "\<forall>i\<in>B. x \<noteq> i") prefer 2 apply blast apply (subgoal_tac "C (x) \<inter> (\<Union>i\<in>B. C (i)) = 0") prefer 2 apply blast apply (subgoal_tac "Finite (\<Union>i\<in>B. C (i)) & Finite (C (x)) & Finite (B) ") apply (simp (no_asm_simp) add: setsum_Un_disjoint) apply (auto intro: Finite_Union Finite_RepFun) done lemma setsum_addf: "setsum(%x. f(x) $+ g(x),C) = setsum(f, C) $+ setsum(g, C)" apply (case_tac "Finite (C) ") prefer 2 apply (simp add: setsum_def) apply (erule Finite_induct, auto) done lemma fold_set_cong: "[| A=A'; B=B'; e=e'; (\<forall>x\<in>A'. \<forall>y\<in>B'. f(x,y) = f'(x,y)) |] ==> fold_set(A,B,f,e) = fold_set(A',B',f',e')" apply (simp add: fold_set_def) apply (intro refl iff_refl lfp_cong Collect_cong disj_cong ex_cong, auto) done lemma fold_cong: "[| B=B'; A=A'; e=e'; !!x y. [|x\<in>A'; y\<in>B'|] ==> f(x,y) = f'(x,y) |] ==> fold[B](f,e,A) = fold[B'](f', e', A')" apply (simp add: fold_def) apply (subst fold_set_cong) apply (rule_tac [5] refl, simp_all) done lemma setsum_cong: "[| A=B; !!x. x\<in>B ==> f(x) = g(x) |] ==> setsum(f, A) = setsum(g, B)" by (simp add: setsum_def cong add: fold_cong) lemma setsum_Un: "[| Finite(A); Finite(B) |] ==> setsum(f, A \<union> B) = setsum(f, A) $+ setsum(f, B) $- setsum(f, A \<inter> B)" apply (subst setsum_Un_Int [symmetric], auto) done lemma setsum_zneg_or_0 [rule_format (no_asm)]: "Finite(A) ==> (\<forall>x\<in>A. g(x) $\<le> #0) \<longrightarrow> setsum(g, A) $\<le> #0" apply (erule Finite_induct) apply (auto intro: zneg_or_0_add_zneg_or_0_imp_zneg_or_0) done lemma setsum_succD_lemma [rule_format]: "Finite(A) ==> \<forall>n\<in>nat. setsum(f,A) = $# succ(n) \<longrightarrow> (\<exists>a\<in>A. #0 $< f(a))" apply (erule Finite_induct) apply (auto simp del: int_of_0 int_of_succ simp add: not_zless_iff_zle int_of_0 [symmetric]) apply (subgoal_tac "setsum (f, B) $\<le> #0") apply simp_all prefer 2 apply (blast intro: setsum_zneg_or_0) apply (subgoal_tac "$# 1 $\<le> f (x) $+ setsum (f, B) ") apply (drule zdiff_zle_iff [THEN iffD2]) apply (subgoal_tac "$# 1 $\<le> $# 1 $- setsum (f,B) ") apply (drule_tac x = "$# 1" in zle_trans) apply (rule_tac [2] j = "#1" in zless_zle_trans, auto) done lemma setsum_succD: "[| setsum(f, A) = $# succ(n); n\<in>nat |]==> \<exists>a\<in>A. #0 $< f(a)" apply (case_tac "Finite (A) ") apply (blast intro: setsum_succD_lemma) apply (unfold setsum_def) apply (auto simp del: int_of_0 int_of_succ simp add: int_succ_int_1 [symmetric] int_of_0 [symmetric]) done lemma g_zpos_imp_setsum_zpos [rule_format]: "Finite(A) ==> (\<forall>x\<in>A. #0 $\<le> g(x)) \<longrightarrow> #0 $\<le> setsum(g, A)" apply (erule Finite_induct) apply (simp (no_asm)) apply (auto intro: zpos_add_zpos_imp_zpos) done lemma g_zpos_imp_setsum_zpos2 [rule_format]: "[| Finite(A); \<forall>x. #0 $\<le> g(x) |] ==> #0 $\<le> setsum(g, A)" apply (erule Finite_induct) apply (auto intro: zpos_add_zpos_imp_zpos) done lemma g_zspos_imp_setsum_zspos [rule_format]: "Finite(A) ==> (\<forall>x\<in>A. #0 $< g(x)) \<longrightarrow> A \<noteq> 0 \<longrightarrow> (#0 $< setsum(g, A))" apply (erule Finite_induct) apply (auto intro: zspos_add_zspos_imp_zspos) done lemma setsum_Diff [rule_format]: "Finite(A) ==> \<forall>a. M(a) = #0 \<longrightarrow> setsum(M, A) = setsum(M, A-{a})" apply (erule Finite_induct) apply (simp_all add: Diff_cons_eq Finite_Diff) done end
def MT {p : Prop} {q : Prop}: (((p -> q) ∧ ¬q) -> ¬p) := fun h1 : ((p -> q) ∧ ¬q) => (fun (h2 : p) => h1.right (h1.left h2)) --∀x(F(x) → G(x)), ∃x(H(x) ∧ ¬G(x)) ⊢ ∃x(H(x) ∧ ¬F(x)) variable(F G H : ℕ → Prop ) variable(x y : ℕ ) variable(a b : Prop ) example (h1 : ∀ x : ℕ, F x → G x ) (h2 : ∃ x : ℕ, H x ∧ ¬G x ) : ∃ x : ℕ, (H x ∧ ¬ F x) := have ⟨a,(ha: H a ∧ ¬G a)⟩ := h2 have proofnotfa := MT $ And.intro (h1 a) ha.right ⟨a, And.intro ha.left proofnotfa⟩ -- ∃x(F(x) ∧ ¬G(x)), ∀x(F(x) → H(x)) ⊢ ∃x(H(x) ∧ ¬G(x)) example (h1 : ∃ x : ℕ, F x ∧ ¬ G x) (h2 : ∀ x : ℕ, F x → H x) : ∃ x : ℕ, H x ∧ ¬G x := have ⟨a, (ha: F a ∧ ¬G a )⟩ := h1 have proofha := (h2 a) ha.left ⟨a, And.intro proofha ha.right⟩ --∀x(F(x) → G(x)), ¬∃x(G(x) ∧ H(x)) ⊢ ¬∃x(H(x) ∧ F(x)) example (h1 : ∀x : ℕ, F x → G x) (h2 : ¬∃ x : ℕ, G x ∧ H x) : ¬∃x : ℕ, H x ∧ F x := fun (a1 : ∃x : ℕ, H x ∧ F x) => have ⟨a, (ha: H a ∧ F a)⟩ := a1 h2 ⟨a, And.intro ((h1 a) ha.right) ha.left ⟩ -- ¬∃x(F(x) ∧ G(x)), ∃x(H(x) ∧ F(x)) ⊢ ∃x(H(x) ∧ ¬G(x)) example (h1 : ¬∃ x : ℕ, F x ∧ G x) (h2 : ∃ x : ℕ, H x ∧ F x) : ∃ x : ℕ, H x ∧ ¬G x := have ⟨a, (ha: H a ∧ F a )⟩ := h2 have proofnga := λ(ga : G a) => h1 ⟨a, And.intro ha.right ga⟩ ⟨a, And.intro ha.left proofnga⟩ -- !(a v b) |- !a ^ !b example (h1 : ¬(a ∨ b)) : ¬a ∧ ¬b := have proofna := λ(a1 : a) => h1 $ Or.intro_left b a1 have proofnb := λ(a2 : b) => h1 $ Or.intro_right a a2 And.intro proofna proofnb axiom DNE {p : Prop} : ¬¬p -> p -- !(a ^ b) |- !a v !b example(h1 : ¬(a ∧ b)) : ¬a ∨ ¬b := DNE λ(a1 : ¬(¬a ∨ ¬b)) => have proofa := λ(a2 : ¬a) => a1 $ Or.intro_left (¬b) a2 have proofb := λ(a3 : ¬b) => a1 $ Or.intro_right (¬a) a3 h1 $ And.intro (DNE proofa) (DNE proofb)
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov ! This file was ported from Lean 3 source module dynamics.ergodic.conservative ! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.MeasureTheory.Constructions.BorelSpace import Mathbin.Dynamics.Ergodic.MeasurePreserving import Mathbin.Combinatorics.Pigeonhole /-! # Conservative systems In this file we define `f : α → α` to be a *conservative* system w.r.t a measure `μ` if `f` is non-singular (`measure_theory.quasi_measure_preserving`) and for every measurable set `s` of positive measure at least one point `x ∈ s` returns back to `s` after some number of iterations of `f`. There are several properties that look like they are stronger than this one but actually follow from it: * `measure_theory.conservative.frequently_measure_inter_ne_zero`, `measure_theory.conservative.exists_gt_measure_inter_ne_zero`: if `μ s ≠ 0`, then for infinitely many `n`, the measure of `s ∩ (f^[n]) ⁻¹' s` is positive. * `measure_theory.conservative.measure_mem_forall_ge_image_not_mem_eq_zero`, `measure_theory.conservative.ae_mem_imp_frequently_image_mem`: a.e. every point of `s` visits `s` infinitely many times (Poincaré recurrence theorem). We also prove the topological Poincaré recurrence theorem `measure_theory.conservative.ae_frequently_mem_of_mem_nhds`. Let `f : α → α` be a conservative dynamical system on a topological space with second countable topology and measurable open sets. Then almost every point `x : α` is recurrent: it visits every neighborhood `s ∈ 𝓝 x` infinitely many times. ## Tags conservative dynamical system, Poincare recurrence theorem -/ noncomputable section open Classical Set Filter MeasureTheory Finset Function TopologicalSpace open Classical Topology variable {ι : Type _} {α : Type _} [MeasurableSpace α] {f : α → α} {s : Set α} {μ : Measure α} namespace MeasureTheory open Measure /- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (m «expr ≠ » 0) -/ /-- We say that a non-singular (`measure_theory.quasi_measure_preserving`) self-map is *conservative* if for any measurable set `s` of positive measure there exists `x ∈ s` such that `x` returns back to `s` under some iteration of `f`. -/ structure Conservative (f : α → α) (μ : Measure α := by exact MeasureTheory.MeasureSpace.volume) extends QuasiMeasurePreserving f μ μ : Prop where exists_mem_image_mem : ∀ ⦃s⦄, MeasurableSet s → μ s ≠ 0 → ∃ x ∈ s, ∃ (m : _)(_ : m ≠ 0), (f^[m]) x ∈ s #align measure_theory.conservative MeasureTheory.Conservative /-- A self-map preserving a finite measure is conservative. -/ protected theorem MeasurePreserving.conservative [IsFiniteMeasure μ] (h : MeasurePreserving f μ μ) : Conservative f μ := ⟨h.QuasiMeasurePreserving, fun s hsm h0 => h.exists_mem_image_mem hsm h0⟩ #align measure_theory.measure_preserving.conservative MeasureTheory.MeasurePreserving.conservative namespace Conservative /-- The identity map is conservative w.r.t. any measure. -/ protected theorem id (μ : Measure α) : Conservative id μ := { toQuasiMeasurePreserving := QuasiMeasurePreserving.id μ exists_mem_image_mem := fun s hs h0 => let ⟨x, hx⟩ := nonempty_of_measure_ne_zero h0 ⟨x, hx, 1, one_ne_zero, hx⟩ } #align measure_theory.conservative.id MeasureTheory.Conservative.id /-- If `f` is a conservative map and `s` is a measurable set of nonzero measure, then for infinitely many values of `m` a positive measure of points `x ∈ s` returns back to `s` after `m` iterations of `f`. -/ theorem frequently_measure_inter_ne_zero (hf : Conservative f μ) (hs : MeasurableSet s) (h0 : μ s ≠ 0) : ∃ᶠ m in atTop, μ (s ∩ f^[m] ⁻¹' s) ≠ 0 := by by_contra H simp only [not_frequently, eventually_at_top, Ne.def, Classical.not_not] at H rcases H with ⟨N, hN⟩ induction' N with N ihN · apply h0 simpa using hN 0 le_rfl rw [imp_false] at ihN push_neg at ihN rcases ihN with ⟨n, hn, hμn⟩ set T := s ∩ ⋃ n ≥ N + 1, f^[n] ⁻¹' s have hT : MeasurableSet T := hs.inter (MeasurableSet.bunionᵢ (to_countable _) fun _ _ => hf.measurable.iterate _ hs) have hμT : μ T = 0 := by convert(measure_bUnion_null_iff <| to_countable _).2 hN rw [← inter_Union₂] rfl have : μ ((s ∩ f^[n] ⁻¹' s) \ T) ≠ 0 := by rwa [measure_diff_null hμT] rcases hf.exists_mem_image_mem ((hs.inter (hf.measurable.iterate n hs)).diffₓ hT) this with ⟨x, ⟨⟨hxs, hxn⟩, hxT⟩, m, hm0, ⟨hxms, hxm⟩, hxx⟩ refine' hxT ⟨hxs, mem_Union₂.2 ⟨n + m, _, _⟩⟩ · exact add_le_add hn (Nat.one_le_of_lt <| pos_iff_ne_zero.2 hm0) · rwa [Set.mem_preimage, ← iterate_add_apply] at hxm #align measure_theory.conservative.frequently_measure_inter_ne_zero MeasureTheory.Conservative.frequently_measure_inter_ne_zero /-- If `f` is a conservative map and `s` is a measurable set of nonzero measure, then for an arbitrarily large `m` a positive measure of points `x ∈ s` returns back to `s` after `m` iterations of `f`. -/ theorem exists_gt_measure_inter_ne_zero (hf : Conservative f μ) (hs : MeasurableSet s) (h0 : μ s ≠ 0) (N : ℕ) : ∃ m > N, μ (s ∩ f^[m] ⁻¹' s) ≠ 0 := let ⟨m, hm, hmN⟩ := ((hf.frequently_measure_inter_ne_zero hs h0).and_eventually (eventually_gt_atTop N)).exists ⟨m, hmN, hm⟩ #align measure_theory.conservative.exists_gt_measure_inter_ne_zero MeasureTheory.Conservative.exists_gt_measure_inter_ne_zero /-- Poincaré recurrence theorem: given a conservative map `f` and a measurable set `s`, the set of points `x ∈ s` such that `x` does not return to `s` after `≥ n` iterations has measure zero. -/ theorem measure_mem_forall_ge_image_not_mem_eq_zero (hf : Conservative f μ) (hs : MeasurableSet s) (n : ℕ) : μ ({ x ∈ s | ∀ m ≥ n, (f^[m]) x ∉ s }) = 0 := by by_contra H have : MeasurableSet (s ∩ { x | ∀ m ≥ n, (f^[m]) x ∉ s }) := by simp only [set_of_forall, ← compl_set_of] exact hs.inter (MeasurableSet.binterᵢ (to_countable _) fun m _ => hf.measurable.iterate m hs.compl) rcases(hf.exists_gt_measure_inter_ne_zero this H) n with ⟨m, hmn, hm⟩ rcases nonempty_of_measure_ne_zero hm with ⟨x, ⟨hxs, hxn⟩, hxm, -⟩ exact hxn m hmn.lt.le hxm #align measure_theory.conservative.measure_mem_forall_ge_image_not_mem_eq_zero MeasureTheory.Conservative.measure_mem_forall_ge_image_not_mem_eq_zero /-- Poincaré recurrence theorem: given a conservative map `f` and a measurable set `s`, almost every point `x ∈ s` returns back to `s` infinitely many times. -/ theorem ae_mem_imp_frequently_image_mem (hf : Conservative f μ) (hs : MeasurableSet s) : ∀ᵐ x ∂μ, x ∈ s → ∃ᶠ n in atTop, (f^[n]) x ∈ s := by simp only [frequently_at_top, @forall_swap (_ ∈ s), ae_all_iff] intro n filter_upwards [measure_zero_iff_ae_nmem.1 (hf.measure_mem_forall_ge_image_not_mem_eq_zero hs n)] simp #align measure_theory.conservative.ae_mem_imp_frequently_image_mem MeasureTheory.Conservative.ae_mem_imp_frequently_image_mem theorem inter_frequently_image_mem_ae_eq (hf : Conservative f μ) (hs : MeasurableSet s) : (s ∩ { x | ∃ᶠ n in atTop, (f^[n]) x ∈ s } : Set α) =ᵐ[μ] s := inter_eventuallyEq_left.2 <| hf.ae_mem_imp_frequently_image_mem hs #align measure_theory.conservative.inter_frequently_image_mem_ae_eq MeasureTheory.Conservative.inter_frequently_image_mem_ae_eq theorem measure_inter_frequently_image_mem_eq (hf : Conservative f μ) (hs : MeasurableSet s) : μ (s ∩ { x | ∃ᶠ n in atTop, (f^[n]) x ∈ s }) = μ s := measure_congr (hf.inter_frequently_image_mem_ae_eq hs) #align measure_theory.conservative.measure_inter_frequently_image_mem_eq MeasureTheory.Conservative.measure_inter_frequently_image_mem_eq /-- Poincaré recurrence theorem: if `f` is a conservative dynamical system and `s` is a measurable set, then for `μ`-a.e. `x`, if the orbit of `x` visits `s` at least once, then it visits `s` infinitely many times. -/ theorem ae_forall_image_mem_imp_frequently_image_mem (hf : Conservative f μ) (hs : MeasurableSet s) : ∀ᵐ x ∂μ, ∀ k, (f^[k]) x ∈ s → ∃ᶠ n in atTop, (f^[n]) x ∈ s := by refine' ae_all_iff.2 fun k => _ refine' (hf.ae_mem_imp_frequently_image_mem (hf.measurable.iterate k hs)).mono fun x hx hk => _ rw [← map_add_at_top_eq_nat k, frequently_map] refine' (hx hk).mono fun n hn => _ rwa [add_comm, iterate_add_apply] #align measure_theory.conservative.ae_forall_image_mem_imp_frequently_image_mem MeasureTheory.Conservative.ae_forall_image_mem_imp_frequently_image_mem /-- If `f` is a conservative self-map and `s` is a measurable set of positive measure, then `μ.ae`-frequently we have `x ∈ s` and `s` returns to `s` under infinitely many iterations of `f`. -/ theorem frequently_ae_mem_and_frequently_image_mem (hf : Conservative f μ) (hs : MeasurableSet s) (h0 : μ s ≠ 0) : ∃ᵐ x ∂μ, x ∈ s ∧ ∃ᶠ n in atTop, (f^[n]) x ∈ s := ((frequently_ae_mem_iff.2 h0).and_eventually (hf.ae_mem_imp_frequently_image_mem hs)).mono fun x hx => ⟨hx.1, hx.2 hx.1⟩ #align measure_theory.conservative.frequently_ae_mem_and_frequently_image_mem MeasureTheory.Conservative.frequently_ae_mem_and_frequently_image_mem /-- Poincaré recurrence theorem. Let `f : α → α` be a conservative dynamical system on a topological space with second countable topology and measurable open sets. Then almost every point `x : α` is recurrent: it visits every neighborhood `s ∈ 𝓝 x` infinitely many times. -/ theorem ae_frequently_mem_of_mem_nhds [TopologicalSpace α] [SecondCountableTopology α] [OpensMeasurableSpace α] {f : α → α} {μ : Measure α} (h : Conservative f μ) : ∀ᵐ x ∂μ, ∀ s ∈ 𝓝 x, ∃ᶠ n in atTop, (f^[n]) x ∈ s := by have : ∀ s ∈ countable_basis α, ∀ᵐ x ∂μ, x ∈ s → ∃ᶠ n in at_top, (f^[n]) x ∈ s := fun s hs => h.ae_mem_imp_frequently_image_mem (is_open_of_mem_countable_basis hs).MeasurableSet refine' ((ae_ball_iff <| countable_countable_basis α).2 this).mono fun x hx s hs => _ rcases(is_basis_countable_basis α).mem_nhds_iffₓ.1 hs with ⟨o, hoS, hxo, hos⟩ exact (hx o hoS hxo).mono fun n hn => hos hn #align measure_theory.conservative.ae_frequently_mem_of_mem_nhds MeasureTheory.Conservative.ae_frequently_mem_of_mem_nhds /-- Iteration of a conservative system is a conservative system. -/ protected theorem iterate (hf : Conservative f μ) (n : ℕ) : Conservative (f^[n]) μ := by cases n · exact conservative.id μ -- Discharge the trivial case `n = 0` refine' ⟨hf.1.iterate _, fun s hs hs0 => _⟩ rcases(hf.frequently_ae_mem_and_frequently_image_mem hs hs0).exists with ⟨x, hxs, hx⟩ /- We take a point `x ∈ s` such that `f^[k] x ∈ s` for infinitely many values of `k`, then we choose two of these values `k < l` such that `k ≡ l [MOD (n + 1)]`. Then `f^[k] x ∈ s` and `(f^[n + 1])^[(l - k) / (n + 1)] (f^[k] x) = f^[l] x ∈ s`. -/ rw [Nat.frequently_atTop_iff_infinite] at hx rcases Nat.exists_lt_modEq_of_infinite hx n.succ_pos with ⟨k, hk, l, hl, hkl, hn⟩ set m := (l - k) / (n + 1) have : (n + 1) * m = l - k := by apply Nat.mul_div_cancel' exact (Nat.modEq_iff_dvd' hkl.le).1 hn refine' ⟨(f^[k]) x, hk, m, _, _⟩ · intro hm rw [hm, MulZeroClass.mul_zero, eq_comm, tsub_eq_zero_iff_le] at this exact this.not_lt hkl · rwa [← iterate_mul, this, ← iterate_add_apply, tsub_add_cancel_of_le] exact hkl.le #align measure_theory.conservative.iterate MeasureTheory.Conservative.iterate end Conservative end MeasureTheory
Inductive t := | C0 : t | C1 : bool -> t | C2 : t -> nat -> t .
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Bags with negative multiplicities, for Nehemiah. -- -- Instead of implementing bags (with negative multiplicities, -- like in the paper) in Agda, we postulate that a group of such -- bags exist. Note that integer bags with integer multiplicities -- are actually the free group given a singleton operation -- `Integer -> Bag`, so this should be easy to formalize in -- principle. ------------------------------------------------------------------------ module Postulate.Bag-Nehemiah where -- Postulates about bags of integers, version Nehemiah -- -- This module postulates bags of integers with negative -- multiplicities as a group under additive union. open import Relation.Binary.PropositionalEquality open import Algebra.Structures open import Data.Integer -- postulate Bag as an abelion group postulate Bag : Set -- singleton postulate singletonBag : ℤ → Bag -- union postulate _++_ : Bag → Bag → Bag infixr 5 _++_ -- negate = mapMultiplicities (λ z → - z) postulate negateBag : Bag → Bag postulate emptyBag : Bag instance postulate abelian-bag : IsAbelianGroup _≡_ _++_ emptyBag negateBag -- Naming convention follows Algebra.Morphism -- Homomorphic₁ : morphism preserves negation Homomorphic₁ : {A B : Set} (f : A → B) (negA : A → A) (negB : B → B) → Set Homomorphic₁ {A} {B} f negA negB = ∀ {x} → f (negA x) ≡ negB (f x) -- Homomorphic₂ : morphism preserves binary operation. Homomorphic₂ : {A B : Set} (f : A → B) (_+_ : A → A → A) (_*_ : B → B → B) → Set Homomorphic₂ {A} {B} f _+_ _*_ = ∀ {x y} → f (x + y) ≡ f x * f y -- postulate map, flatmap and sum to be homomorphisms postulate mapBag : (f : ℤ → ℤ) (b : Bag) → Bag postulate flatmapBag : (f : ℤ → Bag) (b : Bag) → Bag postulate sumBag : Bag → ℤ postulate homo-map : ∀ {f} → Homomorphic₂ (mapBag f) _++_ _++_ postulate homo-flatmap : ∀ {f} → Homomorphic₂ (flatmapBag f) _++_ _++_ postulate homo-sum : Homomorphic₂ sumBag _++_ _+_ postulate neg-map : ∀ {f} → Homomorphic₁ (mapBag f) negateBag negateBag postulate neg-flatmap : ∀ {f} → Homomorphic₁ (flatmapBag f) negateBag negateBag
[STATEMENT] lemma twice_field_differentiable_at_cos [simp, intro]: "cos twice_field_differentiable_at x" [PROOF STATE] proof (prove) goal (1 subgoal): 1. cos twice_field_differentiable_at x [PROOF STEP] by (auto intro!: exI [of _ UNIV] simp add: field_differentiable_within_sin field_differentiable_minus field_differentiable_on_def twice_field_differentiable_at_def field_differentiable_at_cos)
[STATEMENT] lemma l1_learn_refines_a0_ia_skip_i: "{R01iai} Id, l1_learn m {>R01iai}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. {R01iai} Id, l1_learn m {> R01iai} [PROOF STEP] apply (auto simp add: PO_rhoare_defs R01iai_def) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>a b y. \<lbrakk>signals a = signalsInit y; (y, b) \<in> l1_learn m\<rbrakk> \<Longrightarrow> signalsInit y = signalsInit b [PROOF STEP] apply (simp add: l1_learn_def) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
#include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <gsl/gsl_math.h> #include <sys/stat.h> #include <sys/types.h> #include "allvars.h" #include "proto.h" #ifdef SUBFIND #include "fof.h" #include "subfind.h" /*! Structure for communication during the density computation. Holds data that is sent to other processors. */ static struct contamdata_in { MyDouble Pos[3]; MyFloat R200; int NodeList[NODELISTLENGTH]; } *ContamIn, *ContamGet; static struct contamdata_out { double ContaminationMass; int ContaminationLen; } *ContamResult, *ContamOut; void subfind_contamination(void) { int i, j, ndone, ndone_flag, dummy, count; int ngrp, sendTask, recvTask, place, nexport, nimport; struct unbind_data *d; d = (struct unbind_data *) mymalloc(NumPart * sizeof(struct unbind_data)); for(i = 0, count = 0; i < NumPart; i++) #ifdef DENSITY_SPLIT_BY_TYPE if(!((1 << P[i].Type) & (DENSITY_SPLIT_BY_TYPE))) #else if(!((1 << P[i].Type) & (FOF_PRIMARY_LINK_TYPES))) #endif d[count++].index = i; force_treebuild(count, d); /* construct tree only with boundary particles */ myfree(d); /* allocate buffers to arrange communication */ All.BunchSize = (int) ((All.BufferSize * 1024 * 1024) / (sizeof(struct data_index) + sizeof(struct data_nodelist) + sizeof(struct contamdata_in) + sizeof(struct contamdata_out) + sizemax(sizeof(struct contamdata_in), sizeof(struct contamdata_out)))); DataIndexTable = (struct data_index *) mymalloc(All.BunchSize * sizeof(struct data_index)); DataNodeList = (struct data_nodelist *) mymalloc(All.BunchSize * sizeof(struct data_nodelist)); /* we will repeat the whole thing for those groups where we didn't converge to a SO radius yet */ i = 0; /* begin with this index */ do { for(j = 0; j < NTask; j++) { Send_count[j] = 0; Exportflag[j] = -1; } /* do local particles and prepare export list */ for(nexport = 0; i < Ngroups; i++) { if(Group[i].R_Mean200 > 0) { if(subfind_contamination_evaluate(i, 0, &nexport, Send_count) < 0) break; } else { Group[i].ContaminationLen = 0; Group[i].ContaminationMass = 0; } } qsort(DataIndexTable, nexport, sizeof(struct data_index), data_index_compare); MPI_Allgather(Send_count, NTask, MPI_INT, Sendcount_matrix, NTask, MPI_INT, MPI_COMM_WORLD); for(j = 0, nimport = 0, Recv_offset[0] = 0, Send_offset[0] = 0; j < NTask; j++) { Recv_count[j] = Sendcount_matrix[j * NTask + ThisTask]; nimport += Recv_count[j]; if(j > 0) { Send_offset[j] = Send_offset[j - 1] + Send_count[j - 1]; Recv_offset[j] = Recv_offset[j - 1] + Recv_count[j - 1]; } } ContamGet = (struct contamdata_in *) mymalloc(nimport * sizeof(struct contamdata_in)); ContamIn = (struct contamdata_in *) mymalloc(nexport * sizeof(struct contamdata_in)); /* prepare particle data for export */ for(j = 0; j < nexport; j++) { place = DataIndexTable[j].Index; ContamIn[j].Pos[0] = Group[place].Pos[0]; ContamIn[j].Pos[1] = Group[place].Pos[1]; ContamIn[j].Pos[2] = Group[place].Pos[2]; ContamIn[j].R200 = Group[place].R_Mean200; memcpy(ContamIn[j].NodeList, DataNodeList[DataIndexTable[j].IndexGet].NodeList, NODELISTLENGTH * sizeof(int)); } /* exchange data */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) { sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the data */ MPI_Sendrecv(&ContamIn[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct contamdata_in), MPI_BYTE, recvTask, TAG_DENS_A, &ContamGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct contamdata_in), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } myfree(ContamIn); ContamResult = (struct contamdata_out *) mymalloc(nimport * sizeof(struct contamdata_out)); ContamOut = (struct contamdata_out *) mymalloc(nexport * sizeof(struct contamdata_out)); /* now do the locations that were sent to us */ for(j = 0; j < nimport; j++) subfind_contamination_evaluate(j, 1, &dummy, &dummy); if(i >= Ngroups) ndone_flag = 1; else ndone_flag = 0; MPI_Allreduce(&ndone_flag, &ndone, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); /* get the result */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) { sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* send the results */ MPI_Sendrecv(&ContamResult[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct contamdata_out), MPI_BYTE, recvTask, TAG_DENS_B, &ContamOut[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct contamdata_out), MPI_BYTE, recvTask, TAG_DENS_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } /* add the result to the local particles */ for(j = 0; j < nexport; j++) { place = DataIndexTable[j].Index; Group[place].ContaminationLen += ContamOut[j].ContaminationLen; Group[place].ContaminationMass += ContamOut[j].ContaminationMass; } myfree(ContamOut); myfree(ContamResult); myfree(ContamGet); } while(ndone < NTask); myfree(DataNodeList); myfree(DataIndexTable); } /*! This function represents the core of the SPH density computation. The * target particle may either be local, or reside in the communication * buffer. */ int subfind_contamination_evaluate(int target, int mode, int *nexport, int *nsend_local) { int startnode, listindex = 0; double h, mass, masssum; int count, countsum; MyDouble *pos; masssum = 0; countsum = 0; if(mode == 0) { pos = Group[target].Pos; h = Group[target].R_Mean200; } else { pos = ContamGet[target].Pos; h = ContamGet[target].R200; } if(mode == 0) { startnode = All.MaxPart; /* root node */ } else { startnode = ContamGet[target].NodeList[0]; startnode = Nodes[startnode].u.d.nextnode; /* open it */ } while(startnode >= 0) { while(startnode >= 0) { count = subfind_contamination_treefind(pos, h, target, &startnode, mode, nexport, nsend_local, &mass); if(count < 0) return -1; masssum += mass; countsum += count; } if(mode == 1) { listindex++; if(listindex < NODELISTLENGTH) { startnode = ContamGet[target].NodeList[listindex]; if(startnode >= 0) startnode = Nodes[startnode].u.d.nextnode; /* open it */ } } } if(mode == 0) { Group[target].ContaminationMass = masssum; Group[target].ContaminationLen = countsum; } else { ContamResult[target].ContaminationMass = masssum; ContamResult[target].ContaminationLen = countsum; } return 0; } int subfind_contamination_treefind(MyDouble searchcenter[3], MyFloat hsml, int target, int *startnode, int mode, int *nexport, int *nsend_local, double *Mass) { int no, p, task, nexport_save; struct NODE *current; double mass; int count; MyDouble dx, dy, dz, dist, r2; #ifdef PERIODIC MyDouble xtmp; #endif nexport_save = *nexport; mass = 0; count = 0; no = *startnode; while(no >= 0) { if(no < All.MaxPart) /* single particle */ { p = no; no = Nextnode[no]; dist = hsml; dx = NGB_PERIODIC_LONG_X(P[p].Pos[0] - searchcenter[0]); if(dx > dist) continue; dy = NGB_PERIODIC_LONG_Y(P[p].Pos[1] - searchcenter[1]); if(dy > dist) continue; dz = NGB_PERIODIC_LONG_Z(P[p].Pos[2] - searchcenter[2]); if(dz > dist) continue; if(dx * dx + dy * dy + dz * dz > dist * dist) continue; mass += P[p].Mass; count++; } else { if(no >= All.MaxPart + MaxNodes) /* pseudo particle */ { if(mode == 1) endrun(12312); if(mode == 0) { if(Exportflag[task = DomainTask[no - (All.MaxPart + MaxNodes)]] != target) { Exportflag[task] = target; Exportnodecount[task] = NODELISTLENGTH; } if(Exportnodecount[task] == NODELISTLENGTH) { if(*nexport >= All.BunchSize) { *nexport = nexport_save; if(nexport_save == 0) endrun(13005); /* in this case, the buffer is too small to process even a single particle */ for(task = 0; task < NTask; task++) nsend_local[task] = 0; for(no = 0; no < nexport_save; no++) nsend_local[DataIndexTable[no].Task]++; return -1; } Exportnodecount[task] = 0; Exportindex[task] = *nexport; DataIndexTable[*nexport].Task = task; DataIndexTable[*nexport].Index = target; DataIndexTable[*nexport].IndexGet = *nexport; *nexport = *nexport + 1; nsend_local[task]++; } DataNodeList[Exportindex[task]].NodeList[Exportnodecount[task]++] = DomainNodeIndex[no - (All.MaxPart + MaxNodes)]; if(Exportnodecount[task] < NODELISTLENGTH) DataNodeList[Exportindex[task]].NodeList[Exportnodecount[task]] = -1; } no = Nextnode[no - MaxNodes]; continue; } current = &Nodes[no]; if(mode == 1) { if(current->u.d.bitflags & (1 << BITFLAG_TOPLEVEL)) /* we reached a top-level node again, which means that we are done with the branch */ { *startnode = -1; *Mass = mass; return count; } } no = current->u.d.sibling; /* in case the node can be discarded */ dist = hsml + 0.5 * current->len;; dx = NGB_PERIODIC_LONG_X(current->center[0] - searchcenter[0]); if(dx > dist) continue; dy = NGB_PERIODIC_LONG_Y(current->center[1] - searchcenter[1]); if(dy > dist) continue; dz = NGB_PERIODIC_LONG_Z(current->center[2] - searchcenter[2]); if(dz > dist) continue; /* now test against the minimal sphere enclosing everything */ dist += FACT1 * current->len; if((r2 = (dx * dx + dy * dy + dz * dz)) > dist * dist) continue; no = current->u.d.nextnode; /* ok, we need to open the node */ } } *startnode = -1; *Mass = mass; return count; } #endif
Formal statement is: lemma imaginary_eq_real_iff [simp]: assumes "y \<in> Reals" "x \<in> Reals" shows "\<i> * y = x \<longleftrightarrow> x=0 \<and> y=0" Informal statement is: If $y$ and $x$ are real numbers, then $\i y = x$ if and only if $x=0$ and $y=0$.
(* Author: David Sanan Maintainer: David Sanan, sanan at ntu edu sg License: LGPL *) (* Title: ArincMultiCoreServices.thy Author: David Sanan, NTU Copyright (C) 2015-2016 David Sanan Some rights reserved, NTU This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) theory ArincSpec_com_queue_insert imports "ArincQueuing" begin section {* tests *} (*declare[[ML_print_depth = 50000]]*) (* setup{* Config.put_global Proof_Context.debug true *} ML\<open> local fun sleep b m t = Method.RUNTIME (fn ctxt_st => let val _ = writeln (m ^ (if b then " " ^ (@{make_string} ((#1 ctxt_st) |> Proof_Display.pp_context )) else "")) in (OS.Process.sleep t; Seq.single (Seq.Result ctxt_st)) end) in fun g b m = Method.NO_CONTEXT_TACTIC @{context} (sleep b m (Time.fromSeconds 0)) end \<close> ML{* val _ = CONTEXT_METHOD val _ = METHOD val _ = Seq.succeed val _ = Theory.setup ( Method.setup @{binding succeed2} (Scan.succeed (fn ctxt => K (CONTEXT_METHOD (fn using => fn ccc => Method.RUNTIME (fn (goal_ctxt, st) => let val _ = writeln ("qqqq" ^ @{make_string} (using, ccc)) in (goal_ctxt, st) |> Seq.Result |> Seq.succeed end) ccc)) ctxt)) "succeed")*} *) section {* Event Specification *} subsection {* send queuing message param *} definition send_q_message_i::"nat \<Rightarrow> (vars,(Evnt\<times>nat),Faults,Events) com" where "send_q_message_i i \<equiv> IF (\<not> (p_queuing conf \<acute>communication (pt (\<acute>locals!i)))) \<or> (\<not> (p_source conf \<acute>communication (pt (\<acute>locals!i)))) \<or> (\<not> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals!i))) (pt (\<acute>locals!i))) \<or> ( \<not> port_open \<acute>communication (pt (\<acute>locals!i))) \<or> ( \<not> (snd (msg (\<acute>locals!i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals!i)))) THEN \<acute>locals :==\<^sub>E\<^sub>V \<acute>locals[i:=((\<acute>locals!i)\<lparr>ret_n := 0\<rparr>)] ELSE (AWAIT\<^sub>\<down>\<^sub>E\<^sub>V (port_get_mutex conf \<acute>communication (pt ((\<acute>locals)!i)) = 0) (\<acute>communication :==\<^sub>s (port_set_mutex conf \<acute>communication (pt ((\<acute>locals)!i)) (i+1))));; AWAIT\<^sub>\<down>\<^sub>E\<^sub>V True (IF\<^sub>s port_full conf \<acute>communication (pt ((\<acute>locals)!i)) THEN (\<acute>locals :==\<^sub>s \<acute>locals[i:=((\<acute>locals!i)\<lparr>ret_n := 1\<rparr>)];;\<^sub>s \<acute>communication :==\<^sub>s (port_set_mutex conf \<acute>communication (pt ((\<acute>locals)!i)) 0)) ELSE (\<acute>communication :==\<^sub>s port_insert_message conf \<acute>communication (pt (\<acute>locals!i)) (msg (\<acute>locals!i)) 0 ;;\<^sub>s \<acute>locals :==\<^sub>s \<acute>locals[i:=((\<acute>locals!i) \<lparr>a_que_aux := set_que_aux conf \<acute>communication (pt ((\<acute>locals)!i)) (a_que_aux (\<acute>locals ! i)) (get_que_aux conf \<acute>communication (pt ((\<acute>locals)!i)) (a_que_aux (\<acute>locals ! i)) + {# (msg (\<acute>locals!i)) #}) \<rparr>)];;\<^sub>s \<acute>communication :==\<^sub>s (port_set_mutex conf \<acute>communication (pt ((\<acute>locals)!i)) 0);;\<^sub>s \<acute>locals :==\<^sub>s \<acute>locals[i:=((\<acute>locals!i)\<lparr>ret_n := 1\<rparr>)]) FI) FI " subsection {* receive queuing message param *} (* remove for Case-Study lemma body_receive: "i<n \<Longrightarrow> \<Gamma> (Receive_Message_Q,i) = Some (receive_q_message_i i)" unfolding \<Gamma>_def by auto lemma body_clear: "i<n \<Longrightarrow> \<Gamma> (Clear_Message_Q,i) = Some (clear_q_message_i i)" unfolding \<Gamma>_def by auto *) subsection {* instructions preserving locals *} lemma ret_chan_preserves_locals: "i< length (locals_' x) \<Longrightarrow> x' = x\<lparr>locals_' := (locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := m\<rparr>]\<rparr> \<Longrightarrow> (x,x',i) \<in> preserves_locals_constr \<and> a_que_aux ((locals_' x)!i) = a_que_aux ((locals_' x')!i) \<and> r_que_aux ((locals_' x)!i) = r_que_aux ((locals_' x')!i) \<and> chans (communication_' x) = chans(communication_' x') \<and> ports (communication_' x) = ports(communication_' x')" unfolding preserves_locals_constr_def by auto lemma modify_mutex_preserves_locals: "state_conf s \<Longrightarrow> port_open (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ch_id \<Longrightarrow> s' = s\<lparr>communication_' := port_set_mutex conf (communication_' s) (pt (locals_' s ! i)) m\<rparr> \<Longrightarrow> (s,s', i) \<in> preserves_locals_constr \<and> (s,s',ch_id) \<in> preserves_comm_constr \<and> channel_get_messages (the (chans (communication_' s) ch_id)) = channel_get_messages (the (chans (communication_' s') ch_id)) \<and> channel_get_mutex (the (chans (communication_' s') ch_id)) = m \<and> a_que_aux ((locals_' s)!i) = a_que_aux ((locals_' s')!i) \<and> r_que_aux ((locals_' s)!i) = r_que_aux ((locals_' s')!i)" apply (frule port_channel, assumption+) unfolding preserves_comm_constr_def port_set_mutex_def preserves_locals_constr_def channel_set_mutex_def channel_get_messages_def channel_get_mutex_def by auto lemma modify_mutex_ret_preserves_locals: " i<length (locals_' s) \<Longrightarrow> state_conf s \<Longrightarrow> port_open (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ch_id \<Longrightarrow> s' = s\<lparr>locals_' := (locals_' s)[i := (locals_' s ! i)\<lparr>ret_n := m\<rparr>], communication_' := port_set_mutex conf (communication_' s) (pt ((locals_' s)[i := (locals_' s ! i)\<lparr>ret_n := m\<rparr>] ! i)) v\<rparr> \<Longrightarrow> (s,s', i) \<in> preserves_locals_constr \<and> (s,s',ch_id) \<in> preserves_comm_constr \<and> channel_get_messages (the (chans (communication_' s) ch_id)) = channel_get_messages (the (chans (communication_' s') ch_id)) \<and> channel_get_mutex (the (chans (communication_' s') ch_id)) = v \<and> a_que_aux ((locals_' s)!i) = a_que_aux ((locals_' s')!i) \<and> r_que_aux ((locals_' s)!i) = r_que_aux ((locals_' s')!i)" apply (frule port_channel, assumption+) unfolding Invariant_def preserves_comm_constr_def port_set_mutex_def Let_def preserves_locals_constr_def port_in_channel_def port_channel_def channel_set_mutex_def channel_get_messages_def channel_get_mutex_def port_name_in_channel_def port_id_name_def by auto lemma transit_send_que_preserve_locals: "i< length (locals_' s) \<Longrightarrow> state_conf s \<Longrightarrow> port_open (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ch_id \<Longrightarrow> p_queuing conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = Suc i \<Longrightarrow> s' = s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) t) (pt (locals_' s !i)) 0, locals_' := (locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr> \<lparr>ret_n := Suc 0\<rparr>]\<rparr> \<Longrightarrow> (s,s',i) \<in> preserves_locals_constr \<and> (s,s', ch_id) \<in> preserves_comm_constr \<and> msg ((locals_' s)!i) = msg ((locals_' s')!i) \<and> a_que_aux ((locals_' s')!i) ch_id = a_que_aux ((locals_' s)!i) ch_id + ({# (msg (locals_' s ! i)) #}) \<and> (\<forall>j. j\<noteq>ch_id \<longrightarrow> a_que_aux ((locals_' s')!i) j = a_que_aux ((locals_' s)!i) j) \<and> r_que_aux ((locals_' s)!i) = r_que_aux ((locals_' s')!i) \<and> channel_get_mutex (the (chans (communication_' s) ch_id)) \<noteq> 0 \<and> channel_get_mutex (the (chans (communication_' s') ch_id)) = 0 \<and> channel_get_messages (the (chans (communication_' s) ch_id)) + {# msg ((locals_' s')!i) #} = channel_get_messages (the (chans (communication_' s') ch_id))" apply (frule port_channel, assumption+) apply (frule p_queuing_chan_queuing,assumption+) unfolding preserves_comm_constr_def port_set_mutex_def preserves_locals_constr_def port_get_mutex_def port_insert_message_def port_exists_def channel_get_mutex_def chan_queuing_def chan_sampling_def channel_insert_message_def channel_set_messages_def channel_get_messages_def port_set_mutex_def set_que_aux_def get_que_aux_def channel_set_mutex_def Let_def port_channel_def port_in_channel_def port_name_in_channel_def port_id_name_def by(cases "data (the (chans (communication_' s) ch_id))",auto) lemma transit_send_que_preserve_locals': "i< length (locals_' s) \<Longrightarrow> state_conf s \<Longrightarrow> port_open (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ch_id \<Longrightarrow> s' = s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) t) (pt (locals_' s !i)) 0, locals_' := (locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr> \<lparr>ret_n := Suc 0\<rparr>]\<rparr> \<Longrightarrow> (s,s',i) \<in> preserves_locals_constr \<and> (s,s', ch_id) \<in> preserves_comm_constr \<and> (\<forall>j. j\<noteq>ch_id \<longrightarrow> a_que_aux ((locals_' s')!i) j = a_que_aux ((locals_' s)!i) j) \<and> r_que_aux ((locals_' s)!i) = r_que_aux ((locals_' s')!i)" apply (frule port_channel, assumption+) unfolding preserves_comm_constr_def port_exists_def Let_def preserves_locals_constr_def port_insert_message_def port_set_mutex_def set_que_aux_def port_channel_def port_in_channel_def port_id_name_def by auto subsection {* instructions preserving Invariant *} lemma modify_mut_chan: "state_conf x \<Longrightarrow> i<length (locals_' x) \<Longrightarrow> port_open (communication_' x) (pt (locals_' x ! i)) \<Longrightarrow> channel_spec B adds rems ch_id x \<Longrightarrow> port_in_channel conf (communication_' x) (pt (locals_' x ! i)) ch_id \<Longrightarrow> x' = x\<lparr>communication_' := port_set_mutex conf (communication_' x) (pt (locals_' x ! i)) m\<rparr> \<Longrightarrow> channel_spec B adds rems ch_id x'" apply (frule modify_mutex_preserves_locals,auto) apply (rule local_constr_ch_spec_channel_spec) using p_chan by auto lemma modify_ret_inv:"i< procs conf \<Longrightarrow> x\<in> Invariant B adds rems i \<Longrightarrow> x\<lparr>locals_' := (locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := m\<rparr>]\<rparr> \<in> Invariant B adds rems i" proof- assume a0:"i< procs conf" and a1:"x\<in> Invariant B adds rems i" then have a0:"i<length (locals_' x)" unfolding Invariant_def state_conf_def by auto thus ?thesis using Invariant_eq ret_chan_preserves_locals a1 by blast qed lemma modify_mut_inv': "i< length (locals_' x) \<Longrightarrow> port_open (communication_' x) (pt (locals_' x ! i)) \<Longrightarrow> x\<in> Invariant B adds rems i \<Longrightarrow> x' = x\<lparr>communication_' := port_set_mutex conf (communication_' x) (pt (locals_' x ! i)) m\<rparr> \<Longrightarrow> channel_spec B adds rems (port_channel conf (communication_' x) (pt (locals_' x !i))) x'" unfolding Invariant_def apply auto using modify_mut_chan port_unique_channel by metis lemma modify_mut_inv'': "x\<in> Invariant B adds rems i\<Longrightarrow> x\<lparr>communication_' := port_set_mutex conf (communication_' x) (pt (locals_' x ! i)) m\<rparr> \<in> {s. state_conf s} " unfolding Invariant_def state_conf_def Let_def port_set_mutex_def chan_queuing_def chan_sampling_def channel_set_mutex_def port_exists_def by auto lemma modify_mut_inv: "i< procs conf \<Longrightarrow> port_open (communication_' x) (pt (locals_' x ! i)) \<Longrightarrow> x\<in> Invariant B adds rems i \<Longrightarrow> x' = x\<lparr>communication_' := port_set_mutex conf (communication_' x) (pt (locals_' x ! i)) m\<rparr> \<Longrightarrow> x' \<in> Invariant B adds rems i" apply (drule procs_len_locals,assumption) apply (frule modify_mut_inv'[of _ _ _ _ _ _ m], simp+) apply (frule modify_mut_inv''[of _ _ _ _ _ m], simp+) apply (subgoal_tac "ports (communication_' x) = ports (communication_' x')") apply (drule port_channl_eq_pid[of _ _ "(pt (locals_' x ! i))"], simp) unfolding Invariant_def apply auto by (auto simp add: port_set_mutex_def channel_set_mutex_def Let_def) (* by (cases "data (the (chans (communication_' s) ch_id))",auto) *) lemma modify_mut_zero_ret_chan: "state_conf s \<Longrightarrow> i<length (locals_' s) \<Longrightarrow> channel_spec B adds rems ch_id s \<Longrightarrow> port_open (communication_' s) (pt (locals_' s !i)) \<Longrightarrow> port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ch_id \<Longrightarrow> s' = s\<lparr>locals_' := (locals_' s)[i := (locals_' s ! i)\<lparr>ret_n := m\<rparr>], communication_' := port_set_mutex conf (communication_' s) (pt (locals_' s ! i)) v\<rparr> \<Longrightarrow> channel_spec B adds rems ch_id s'" apply (frule modify_mutex_ret_preserves_locals,auto) apply (rule local_constr_ch_spec_channel_spec) using p_chan by auto lemma modify_mut_zero_ret_inv': assumes a0:"i < length (locals_' x)" and a1:"x \<in> Invariant B adds rems i" and a2:"port_open (communication_' x) (pt (locals_' x !i))" and a3:"x' = x\<lparr>locals_' := (locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>], communication_' := port_set_mutex conf (communication_' x) (pt ((locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>] ! i)) 0\<rparr>" shows "channel_spec B adds rems (port_channel conf (communication_' x')(pt (locals_' x' !i))) x'" proof - have a1:"state_conf x" and a1':"channel_spec B adds rems (port_channel conf (communication_' x)(pt (locals_' x !i))) x" using a1 unfolding Invariant_def by auto have "channel_spec B adds rems (port_channel conf (communication_' x)(pt (locals_' x !i))) x'" using a3 a0 apply auto using port_exist_unique_channel[OF a1 a2] modify_mut_zero_ret_chan[OF a1 a0 a1' a2] port_channel[OF a1 a2] by blast moreover have "port_channel conf (communication_' x')(pt (locals_' x' !i)) = port_channel conf (communication_' x)(pt (locals_' x !i))" using modify_mutex_ret_preserves_locals[OF a0 a1 a2 _ a3] using a1 a2 preserves_locals_D3 exist_port_in_channel preserves_comm_D3 by (metis port_channl_eq_ports) ultimately show ?thesis by simp qed lemma modify_mut_ret_inv'': " i< length (locals_' x) \<Longrightarrow> port_open (communication_' x) (pt (locals_' x !i)) \<Longrightarrow> x\<in> Invariant B adds rems i \<Longrightarrow> x\<lparr>locals_' := (locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>], communication_' := port_set_mutex conf (communication_' x) (pt ((locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>] ! i)) 0\<rparr> \<in> {s. state_conf s} " using port_exist_unique_channel port_channel unfolding Invariant_def state_conf_def Let_def port_set_mutex_def chan_queuing_def chan_sampling_def channel_set_mutex_def port_exists_def by auto (* lemma modify_mut_ret_inv''': assumes a0: " i< length (locals_' x)" and a1:"port_open (communication_' x) (pt (locals_' x !i))" and a2:"x\<in> Invariant B adds rems i" shows "x\<lparr>locals_' := locals_' x[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>], communication_' := port_set_mutex conf (communication_' x) (pt (locals_' x[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>] ! i)) 0\<rparr> \<in> \<lbrace>channel_messages (port_channel conf \<acute>communication (pt (\<acute>locals ! i))) rems [0..<length \<acute>locals] \<subseteq># channel_messages (port_channel conf \<acute>communication (pt (\<acute>locals ! i))) r_que_aux \<acute>locals \<and> channel_messages (port_channel conf \<acute>communication (pt (\<acute>locals ! i))) adds [0..<length \<acute>locals] \<subseteq># channel_messages (port_channel conf \<acute>communication (pt (\<acute>locals ! i))) a_que_aux \<acute>locals\<rbrace> " proof- let ?x' = "x\<lparr>locals_' := locals_' x[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>], communication_' := port_set_mutex conf (communication_' x) (pt (locals_' x[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>] ! i)) 0\<rparr>" let ?p = "(port_channel conf (communication_' x) (pt (locals_' x ! i)))" have "port_in_channel conf (communication_' x) (pt (locals_' x ! i)) ?p" using port_exist_unique_channel port_channel a2 a1 unfolding Invariant_def by fastforce then have prev:"(x,?x', i) \<in> preserves_locals_constr \<and> (x,?x',?p) \<in> preserves_comm_constr \<and> channel_get_messages (the (chans (communication_' x) ?p)) = channel_get_messages (the (chans (communication_' ?x') ?p)) \<and> a_que_aux ((locals_' x)!i) = a_que_aux ((locals_' ?x')!i) \<and> r_que_aux ((locals_' x)!i) = r_que_aux ((locals_' ?x')!i)" using modify_mutex_ret_preserves_locals[OF a0 _ a1 ] a2[simplified Invariant_def] by auto then have "?x'\<in> \<lbrace>channel_messages ?p rems [0..<length (locals_' ?x')] \<subseteq># channel_messages ?p r_que_aux (locals_' ?x') \<and> channel_messages ?p adds [0..<length (locals_' ?x')] \<subseteq># channel_messages ?p a_que_aux (locals_' ?x')\<rbrace>" using local_constr_subset_aux IntE Invariant_def a2 mem_Collect_eq by (metis (no_types, lifting) IntE Invariant_def a2 mem_Collect_eq) moreover have "?p = port_channel conf (communication_' ?x') (pt (locals_' ?x' ! i))" using prev port_channl_eq_pid preserves_comm_D3 preserves_locals_D3 by (metis (no_types, lifting)) ultimately show ?thesis by force qed *) lemma modify_mut_zero_ret_inv: "i<procs conf \<Longrightarrow> x \<in> Invariant B adds rems i\<Longrightarrow> port_open (communication_' x) (pt (locals_' x !i)) \<Longrightarrow> x\<lparr>locals_' := (locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>], communication_' := port_set_mutex conf (communication_' x) (pt ((locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>] ! i)) 0\<rparr> \<in> Invariant B adds rems i" apply (drule procs_len_locals,assumption) using modify_mut_zero_ret_inv' modify_mut_ret_inv'' unfolding Invariant_def by fast lemma modify_ret_n_guarantee: "i < procs conf \<Longrightarrow> state_conf s \<Longrightarrow> (Normal s, Normal (s\<lparr>locals_' := (locals_' s)[i := (locals_' s ! i)\<lparr>ret_n := u\<rparr>]\<rparr>)) \<in> Guarantee_Send_Receive i " unfolding Guarantee_Send_Receive_def Guarantee_Send_Receive'_def state_conf_def Guarantee_mod_chan_def Let_def port_exists_def by auto lemma modify_mutex_send_guarantee: "i < procs conf \<Longrightarrow> state_conf s \<Longrightarrow> p_queuing conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = 0 \<Longrightarrow> (Normal s, Normal (s\<lparr>communication_' := port_set_mutex conf (communication_' s) (pt (locals_' s ! i)) (Suc i)\<rparr>)) \<in> Guarantee_Send_Receive i " unfolding state_conf_def Invariant_def Guarantee_Send_Receive'_def Guarantee_Send_Receive_def port_set_mutex_def port_get_mutex_def channel_get_mutex_def chan_queuing_def channel_get_messages_def channel_set_mutex_def ch_id_queuing_def Let_def p_queuing_def chan_sampling_def Guarantee_mod_chan_def Let_def port_exists_def by auto (* lemmas For the atomic version *) lemma modify_ret_mutex_zero_guarantee: " i < procs conf \<Longrightarrow> state_conf s \<Longrightarrow> port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = Suc i \<Longrightarrow> p_queuing conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> (Normal s, Normal (s\<lparr>locals_' := (locals_' s)[i := (locals_' s ! i)\<lparr>ret_n := Suc 0\<rparr>], communication_' := port_set_mutex conf (communication_' s) (pt ((locals_' s)[i := (locals_' s ! i)\<lparr>ret_n := Suc 0\<rparr>] ! i)) 0\<rparr>)) \<in> Guarantee_Send_Receive i" unfolding state_conf_def Guarantee_Send_Receive'_def Guarantee_Send_Receive_def port_set_mutex_def port_get_mutex_def channel_get_mutex_def chan_queuing_def channel_get_messages_def channel_set_mutex_def ch_id_queuing_def Let_def p_queuing_def chan_sampling_def Guarantee_mod_chan_def port_exists_def by auto lemma insert_queue_preserves_ch_spec: assumes a0:"i < length (locals_' s)" and a1:"s \<in> Invariant B adds rems i" and a3:"port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = Suc i" and a4:"evnt (locals_' s ! i) = ev" and a5:"p_source conf (communication_' s) (pt (locals_' s ! i))" and a6:"p_queuing conf (communication_' s) (pt (locals_' s ! i))" and a7:"port_open (communication_' s) (pt (locals_' s ! i))" and a9:"\<not> port_full conf (communication_' s) (pt (locals_' s ! i))" and a10:"t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) ti) (pt ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] !i)) 0, locals_' := (locals_' s) [i := ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" shows "channel_spec B adds rems (port_channel conf (communication_' t) (pt (locals_' t !i))) t" proof- have a10': "t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) ti) (pt (locals_' s !i)) 0, locals_' := (locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr> \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" using a10 a0 by auto then have pt:"pt (locals_' s ! i) = pt (locals_' t ! i)" using a0 by auto let ?ch = "port_channel conf (communication_' s) (pt (locals_' s!i))" have port_in_channel: "port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ?ch " using a0 a1 a7 port_exist_unique_channel port_channel unfolding Invariant_def by fast then obtain chan where chan:"chans (communication_' s) ?ch = Some chan" using a0 a1 unfolding Invariant_def state_conf_def port_in_channel_def port_name_in_channel_def by fastforce then obtain chan' where chan':"chans (communication_' t) ?ch = Some chan'" using a0 a1 a3 a4 a5 a6 a9 a10' a7 unfolding Invariant_def state_conf_def port_insert_message_def Let_def port_set_mutex_def by fastforce have state: "state_conf s" using a0 a1 unfolding Invariant_def by auto have channel_spec:"channel_spec B adds rems ?ch s" and a0':"(s,t,i) \<in> preserves_locals_constr" and a1:"(s,t, ?ch) \<in> preserves_comm_constr" and a3:"msg ((locals_' s)!i) = msg ((locals_' t)!i)" and a4:"a_que_aux ((locals_' t)!i) ?ch = a_que_aux ((locals_' s)!i) ?ch + ({# (msg (locals_' s ! i)) #}) \<and> (\<forall>j. j\<noteq>?ch \<longrightarrow> a_que_aux ((locals_' t)!i) j = a_que_aux ((locals_' s)!i) j) \<and> r_que_aux ((locals_' s)!i) = r_que_aux ((locals_' t)!i)" and qmut_not_zero: "channel_get_mutex (the (chans (communication_' s) ?ch)) \<noteq> 0" and eq_qmut : "channel_get_mutex (the (chans (communication_' t) ?ch)) = 0" and a6: "i< length (locals_' s)" and a7': "p_queuing conf (communication_' s) (pt (locals_' s !i))" and a8: "\<not> port_full conf (communication_' s) (pt(locals_' s!i))" and a9: "channel_get_messages chan + {# msg ((locals_' s)!i) #} = channel_get_messages chan'" and a10:"channel_get_messages (the (chans (communication_' s) ?ch)) + {# msg ((locals_' s)!i) #} = channel_get_messages (the (chans (communication_' t) ?ch))" using a0 a1 a3 a4 a5 a6 a9 a10' chan chan' transit_send_que_preserve_locals [OF a0 state a7 port_in_channel _ _ a10'] state unfolding Invariant_def by auto also have a5:"ch_spec B adds rems ?ch s" using channel_spec_dest2[OF channel_spec] a7'[simplified p_queuing_def] using chan by auto then have "ch_spec B adds rems ?ch t" using atomic_tran_channel_ch_spec[OF a0 state a0' a10 _ _ a1 port_in_channel a7 a7' a5 a8] a4 unfolding ch_spec_def channel_received_messages_def channel_sent_messages_def by fastforce moreover have "port_channel conf (communication_' t) (pt (locals_' s!i)) = ?ch" by (metis (no_types) a1 port_channl_eq_ports preserves_comm_D3) ultimately show ?thesis by (simp add: channel_spec_intro pt) qed (* lemma insert_queue_preserves_aux_subset1: assumes a0:"i < length (locals_' s)" and a1:"s \<in> Invariant B adds rems i" and a3:"port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = Suc i" and a6:"p_queuing conf (communication_' s) (pt (locals_' s ! i))" and a7:"port_open (communication_' s) (pt (locals_' s ! i))" and a10:"t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) ti) (pt (locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] !i)) 0, locals_' := locals_' s [i := (locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" shows "channel_messages (port_channel conf (communication_' s) (pt (locals_' s !i))) rems [0..<length (locals_' t)] \<subseteq># channel_messages (port_channel conf (communication_' s) (pt (locals_' s !i))) r_que_aux (locals_' t)" proof- have a10': "t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) ti) (pt (locals_' s !i)) 0, locals_' := locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr> \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" using a10 a0 by auto then have pt:"pt (locals_' s ! i) = pt (locals_' t ! i)" using a0 by automodify_mut_ret_inv''' let ?ch = "port_channel conf (communication_' s) (pt (locals_' s!i))" have port_in_channel: "port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ?ch " using a0 a1 a7 port_exist_unique_channel port_channel unfolding Invariant_def by fast have state: "state_conf s" using a0 a1 unfolding Invariant_def by auto have r_aux_sub:" channel_messages ?ch rems [0..<length (locals_' s)] \<subseteq># channel_messages ?ch r_que_aux (locals_' s)" using a1 unfolding Invariant_def channel_spec_def by auto have channel_spec:"channel_spec B adds rems ?ch s" and a0':"(s,t,i) \<in> preserves_locals_constr" and a4:"a_que_aux ((locals_' t)!i) ?ch = a_que_aux ((locals_' s)!i) ?ch + ({# (msg (locals_' s ! i)) #}) \<and> (\<forall>j. j\<noteq>?ch \<longrightarrow> a_que_aux ((locals_' t)!i) j = a_que_aux ((locals_' s)!i) j) \<and> r_que_aux ((locals_' s)!i) = r_que_aux ((locals_' t)!i)" using a1 a3 a6 transit_send_que_preserve_locals [OF a0 state a7 port_in_channel _ _ a10'] unfolding Invariant_def by auto show ?thesis using a0' a4 add_channel_message_not_evnt preserves_locals_D1 pt r_aux_sub by fastforce qed *) (* lemma insert_queue_preserves_aux_subset2: assumes a0:"i < length (locals_' s)" and a1:"s \<in> Invariant B adds rems i" and a3:"port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = Suc i" and a6:"p_queuing conf (communication_' s) (pt (locals_' s ! i))" and a7:"port_open (communication_' s) (pt (locals_' s ! i))" and a10:"t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt (locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] !i)) 0, locals_' := locals_' s [i := (locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" shows "channel_messages (port_channel conf (communication_' s) (pt (locals_' s !i))) adds [0..<length (locals_' t)] \<subseteq># channel_messages (port_channel conf (communication_' s) (pt (locals_' s !i))) a_que_aux (locals_' t)" proof- have a10': "t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt (locals_' s !i)) 0, locals_' := locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr> \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" using a10 a0 by auto then have pt:"pt (locals_' s ! i) = pt (locals_' t ! i)" using a0 by auto let ?ch = "port_channel conf (communication_' s) (pt (locals_' s!i))" have port_in_channel: "port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ?ch " using a0 a1 a7 port_exist_unique_channel port_channel unfolding Invariant_def by fast have state: "state_conf s" using a0 a1 unfolding Invariant_def by auto have r_aux_sub:" channel_messages ?ch rems [0..<length (locals_' s)] \<subseteq># channel_messages ?ch r_que_aux (locals_' s)" using a1 unfolding Invariant_def by auto have a_aux_sub:" channel_messages ?ch adds [0..<length (locals_' s)] \<subseteq># channel_messages ?ch a_que_aux (locals_' s)" using a1 unfolding Invariant_def by auto have channel_spec:"channel_spec B adds rems ?ch s" and a0':"(s,t,i) \<in> preserves_locals_constr" and a4:"a_que_aux ((locals_' t)!i) ?ch = a_que_aux ((locals_' s)!i) ?ch + ({# (msg (locals_' s ! i)) #})" and a5:"(\<forall>j. j\<noteq>?ch \<longrightarrow> a_que_aux ((locals_' t)!i) j = a_que_aux ((locals_' s)!i) j) \<and> r_que_aux ((locals_' s)!i) = r_que_aux ((locals_' t)!i)" using a1 a3 a6 transit_send_que_preserve_locals [OF a0 state a7 port_in_channel _ _ a10'] unfolding Invariant_def by auto show ?thesis using add_channel_message_evnt[OF a0 a0',of a_que_aux,OF a4] a0' preserves_locals_D1 pt a_aux_sub by (metis mset_subset_eq_add_left subset_mset.add_increasing2 subset_mset.le_add_same_cancel1) qed *) (* lemma insert_queue_preserves_aux_subset: assumes a0:"i < length (locals_' s)" and a1:"s \<in> Invariant B adds rems i" and a3:"port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = Suc i" and a6:"p_queuing conf (communication_' s) (pt (locals_' s ! i))" and a7:"port_open (communication_' s) (pt (locals_' s ! i))" and a10:"t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt (locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] !i)) 0, locals_' := locals_' s [i := (locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" shows "t\<in>\<lbrace>channel_messages (port_channel conf \<acute>communication (pt (\<acute>locals ! i))) rems [0..<length \<acute>locals] \<subseteq># channel_messages (port_channel conf \<acute>communication (pt (\<acute>locals ! i))) r_que_aux \<acute>locals \<and> channel_messages (port_channel conf \<acute>communication (pt (\<acute>locals ! i))) adds [0..<length \<acute>locals] \<subseteq># channel_messages (port_channel conf \<acute>communication (pt (\<acute>locals ! i))) a_que_aux \<acute>locals\<rbrace>" proof- have a10': "t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt (locals_' s !i)) 0, locals_' := locals_' s [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr> \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" using a10 a0 by auto then have pt:"pt (locals_' s ! i) = pt (locals_' t ! i)" and ports:"ports (communication_' s) = ports (communication_' t)" using a0 unfolding port_set_mutex_def port_insert_message_def Let_def by auto let ?ch = "port_channel conf (communication_' s) (pt (locals_' s!i))" have port_in_channel: "port_in_channel conf (communication_' s) (pt (locals_' s ! i)) ?ch " using a0 a1 a7 port_exist_unique_channel port_channel unfolding Invariant_def by fast have state: "state_conf s" using a0 a1 unfolding Invariant_def by auto have r_aux_sub:" channel_messages ?ch rems [0..<length (locals_' s)] \<subseteq># channel_messages ?ch r_que_aux (locals_' s)" using a1 unfolding Invariant_def by auto have a_aux_sub:"channel_messages ?ch adds [0..<length (locals_' s)] \<subseteq># channel_messages ?ch a_que_aux (locals_' s)" using a1 unfolding Invariant_def by auto have channel_spec:"channel_spec B adds rems ?ch s" and a0':"(s,t,i) \<in> preserves_locals_constr" and a4:"a_que_aux ((locals_' t)!i) ?ch = a_que_aux ((locals_' s)!i) ?ch + ({# (msg (locals_' s ! i)) #})" and a5:"(\<forall>j. j\<noteq>?ch \<longrightarrow> a_que_aux ((locals_' t)!i) j = a_que_aux ((locals_' s)!i) j) \<and> r_que_aux ((locals_' s)!i) = r_que_aux ((locals_' t)!i)" using a1 a3 a6 transit_send_que_preserve_locals [OF a0 state a7 port_in_channel _ _ a10'] unfolding Invariant_def by auto have "channel_messages ?ch adds [0..<length (locals_' t)] \<subseteq># channel_messages ?ch a_que_aux (locals_' t)" by (metis a0 a0' a4 a_aux_sub add_channel_message_evnt mset_subset_eq_add_left preserves_locals_D1 subset_mset.add_increasing2 subset_mset.le_add_same_cancel1) moreover have "channel_messages ?ch rems [0..<length (locals_' t)] \<subseteq># channel_messages ?ch r_que_aux (locals_' t)" using a0' a4 add_channel_message_not_evnt preserves_locals_D1 pt r_aux_sub using a5 by fastforce moreover have"port_channel conf (communication_' t) (pt (locals_' t ! i)) = port_channel conf (communication_' s) (pt (locals_' t ! i))" using port_channl_eq_ports[OF ports, THEN sym, of i, simplified pt] by auto ultimately show ?thesis using pt ports by auto qed *) lemma tran_insert_state_conf: "state_conf s \<Longrightarrow> t=s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt (locals_' s !i)) 0, locals_' := (locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr> \<lparr>ret_n := Suc 0\<rparr>]\<rparr> \<Longrightarrow> state_conf t" unfolding state_conf_def channel_set_mutex_def port_set_mutex_def port_insert_message_def Let_def port_exists_def channel_insert_message_def channel_set_messages_def chan_queuing_def chan_sampling_def apply (cases "data (the (chans (communication_' s) (port_channel conf (communication_' s) (pt (locals_' s ! i)))))") by auto lemma eq_insert: "s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i) ) (msg (locals_' s ! i)) x) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i)) 0, locals_' := (locals_' s) [i := ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr> = s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i)) 0, locals_' := (locals_' s) [i := ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" unfolding set_que_aux_def get_que_aux_def Let_def port_insert_message_def port_exists_def port_channel_def port_in_channel_def port_id_name_def by auto lemma insert_queue_preserves_inv: "i < procs conf \<Longrightarrow> s \<in> Invariant B adds rems i \<Longrightarrow> port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = Suc i \<Longrightarrow> evnt (locals_' s ! i) = Send_Message_Q \<Longrightarrow> p_source conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> p_queuing conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> port_open (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> \<not> port_full conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i)) 0, locals_' := (locals_' s) [i := ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr> \<in> Invariant B adds rems i" apply (frule procs_len_locals,assumption) unfolding Invariant_def apply rule using tran_insert_state_conf using insert_queue_preserves_ch_spec[of i s B adds rems Send_Message_Q "s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i)) 0, locals_' := (locals_' s) [i := ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr>"] apply auto unfolding Invariant_def by fastforce lemma send_message_clear_mutex_temp_msg_guar: "i < procs conf \<Longrightarrow> state_conf s \<Longrightarrow> port_get_mutex conf (communication_' s) (pt (locals_' s ! i)) = Suc i \<Longrightarrow> p_source conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> p_queuing conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> port_open (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> \<not> port_full conf (communication_' s) (pt (locals_' s ! i)) \<Longrightarrow> t= s\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' s) (pt (locals_' s ! i)) (msg (locals_' s ! i)) x) (pt ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i)) 0, locals_' := (locals_' s) [i := ((locals_' s) [i := (locals_' s ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i)) (add_mset (msg (locals_' s ! i)) (get_que_aux conf (communication_' s) (pt (locals_' s ! i)) (a_que_aux (locals_' s ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr> \<Longrightarrow> (Normal s, Normal t) \<in> Guarantee_Send_Receive i" unfolding Guarantee_Send_Receive_def Guarantee_Send_Receive'_def port_get_mutex_def channel_get_mutex_def set_que_aux_def get_que_aux_def channel_set_messages_def channel_insert_message_def Let_def port_insert_message_def channel_set_mutex_def port_set_mutex_def state_conf_def Invariant_def chan_queuing_def chan_sampling_def channel_get_messages_def port_full_def channel_full_def channel_get_bufsize_def Guarantee_mod_chan_def p_queuing_def ch_id_queuing_def port_exists_def apply (case_tac "data (the (chans (communication_' s) (port_channel conf (communication_' s) (pt (locals_' s ! i)))))") unfolding port_channel_def port_in_channel_def port_id_name_def port_exists_def apply auto using port_channel_get_channel unfolding state_conf_def chan_queuing_def port_open_def chan_sampling_def not_less_eq_eq port_channel_def port_in_channel_def port_name_in_channel_def port_id_name_def port_exists_def by blast lemma sta_cond: "LocalRG_HoareDef.Sta (\<lbrace>port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> port_open \<acute>communication (pt (\<acute>locals ! i))\<rbrace>) (Rely_Send_ReceiveQ i)" unfolding Rely_Send_ReceiveQ_def Rely_Send_Receive_def Sta_def port_id_in_part_def port_open_def Let_def port_channel_def port_in_channel_def port_id_name_def p_source_def p_queuing_def port_exists_def by fastforce lemma sta_cond_inv:"i < Sys_Config.procs conf \<Longrightarrow> LocalRG_HoareDef.Sta (Invariant B adds rems i \<inter> \<lbrace>evnt (\<acute>locals ! i) = Ev\<rbrace> \<inter> \<lbrace>port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> port_open \<acute>communication (pt (\<acute>locals ! i))\<rbrace>) (Rely_Send_ReceiveQ i)" using sta_cond sta_event_inv by (fastforce intro:Sta_intro) lemma sta_not_cond:"LocalRG_HoareDef.Sta (- \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace>) (Rely_Send_ReceiveQ i)" unfolding Sta_def apply clarify apply (frule rely_eq_ports1) unfolding p_queuing_def port_exists_def port_channel_def port_in_channel_def port_id_name_def port_open_def p_source_def port_id_in_part_def port_max_size_def port_id_in_part_def apply auto apply (metis (no_types) option.sel option.simps(3)) unfolding Rely_Send_ReceiveQ_def by fastforce+ lemma sta_not_cond_inv:"i < Sys_Config.procs conf \<Longrightarrow> LocalRG_HoareDef.Sta (Invariant B adds rems i \<inter> \<lbrace>evnt (\<acute>locals ! i) = Ev\<rbrace> \<inter> - \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace>) (Rely_Send_ReceiveQ i)" using sta_not_cond sta_event_inv by (fastforce intro:Sta_intro) lemma sta_not_cond_inv_mut: "LocalRG_HoareDef.Sta (\<lbrace>p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<and> port_open \<acute>communication (pt (\<acute>locals ! i)) \<rbrace> \<inter> \<lbrace>port_get_mutex conf \<acute>communication (pt (\<acute>locals ! i)) = Suc i\<rbrace>) (Rely_Send_ReceiveQ i)" unfolding Sta_def apply clarify apply simp apply (frule rely_eq_ports1) unfolding p_queuing_def port_exists_def port_channel_def port_in_channel_def port_id_name_def port_open_def p_source_def apply auto apply fastforce unfolding Rely_Send_ReceiveQ_def Rely_Send_Receive_def Let_def port_get_mutex_def channel_get_mutex_def port_exists_def port_channel_def port_in_channel_def port_id_name_def by fastforce lemma sta_not_cond_inv_mut1: "i < Sys_Config.procs conf \<Longrightarrow> LocalRG_HoareDef.Sta (Invariant B adds rems i \<inter> \<lbrace>evnt (\<acute>locals ! i) = Ev\<rbrace> \<inter> - \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace> \<inter> \<lbrace>port_get_mutex conf \<acute>communication (pt (\<acute>locals ! i)) = Suc i\<rbrace>) (Rely_Send_ReceiveQ i)" by (auto intro: subst[of "Invariant B adds rems i \<inter> \<lbrace>evnt (\<acute>locals ! i) = Ev\<rbrace> \<inter> - \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace> \<inter> (\<lbrace>p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<and> port_open \<acute>communication (pt (\<acute>locals ! i))\<rbrace> \<inter> \<lbrace>port_get_mutex conf \<acute>communication (pt (\<acute>locals ! i)) = Suc i\<rbrace>)"] dest: Sta_intro[OF sta_not_cond_inv sta_not_cond_inv_mut]) lemma send_correct: "i < procs conf \<Longrightarrow> \<Gamma>,{} \<turnstile>\<^bsub>/{}\<^esub> send_q_message_i i sat [Invariant B adds rems i \<inter> \<lbrace>evnt (\<acute>locals ! i) = Send_Message_Q\<rbrace>, Rely_Send_ReceiveQ i, Guarantee_Send_Receive i, Post_Arinc_i B adds rems i,UNIV]" apply (auto simp add: Norm_def send_q_message_i_def reflexive_Guarantee_Send Int_assoc Post_Arinc_i_def) apply (rule If,(auto simp add: reflexive_Guarantee_Send)) apply (rule sta_event_inv, simp+) apply (rule conseqPre[where p'="Invariant B adds rems i"]) apply (rule Basic) apply (rule sta_invariant_rely_send, assumption)+ apply(simp add: modify_ret_n_guarantee Invariant_def) apply (auto simp add: modify_ret_inv) apply (rule Seq[where q="Invariant B adds rems i \<inter> (\<lbrace>evnt (\<acute>locals ! i) = Send_Message_Q\<rbrace>) \<inter> - \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace> \<inter> \<lbrace>port_get_mutex conf \<acute>communication (pt (\<acute>locals ! i)) = (Suc i)\<rbrace>"], (auto simp add: reflexive_Guarantee_Send)) apply (rule sta_uni sta_not_cond_inv, assumption?)+ apply (rule Await) apply (rule sta_uni sta_not_cond_inv sta_not_cond_inv_mut1, assumption?)+ apply vcg apply (auto intro: port_get_set_mutex)[1] apply (simp add: modify_mutex_send_guarantee Invariant_def ) apply (rule modify_mut_inv, assumption+,simp) apply (auto simp add: port_id_in_part_def p_source_def channel_id_get_source_def port_name_in_channel_def port_channel_def port_in_channel_def port_id_name_def port_exists_def Let_def port_set_mutex_def p_queuing_def port_open_def port_max_size_def)[5] apply (rule Await) apply (rule sta_uni sta_invariant_rely_send sta_not_cond_inv_mut1, assumption?)+ apply vcg apply (auto simp add: eq_insert) apply (simp add: modify_ret_mutex_zero_guarantee Invariant_def) apply (auto simp add:modify_mut_zero_ret_inv) apply (simp add: send_message_clear_mutex_temp_msg_guar Invariant_def)[1] by (auto simp add: current_def insert_queue_preserves_inv) lemma modify_ret_QueCom:"i< procs conf \<Longrightarrow> x \<in> Pre_QueCom_ch B adds rems ch_id \<Longrightarrow> x\<lparr>locals_' := (locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := m\<rparr>]\<rparr> \<in> Pre_QueCom_ch B adds rems ch_id" proof- let ?x' = "x\<lparr>locals_' := (locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := m\<rparr>]\<rparr>" let ?ch_id = "port_channel conf (communication_' x) (pt(locals_' x!i))" assume a0:"i< procs conf" and a1:"x\<in>Pre_QueCom_ch B adds rems ch_id" then have a0':"i<length (locals_' x)" unfolding Pre_QueCom_ch_def state_conf_def by auto have b0:"(x, ?x', i) \<in> preserves_locals_constr" and b1:"a_que_aux (locals_' x ! i) = a_que_aux (locals_' ?x' ! i)" and b2:"r_que_aux (locals_' x ! i) = r_que_aux (locals_' ?x' ! i)" and b3:"chans (communication_' x) = chans (communication_' ?x')" and b4:"ports (communication_' x) = ports (communication_' ?x')" using ret_chan_preserves_locals[OF a0'] by auto have pts:"\<forall>i. pt (locals_' x ! i) = pt (locals_' ?x' ! i)" using b0 using preserves_locals_D2 preserves_locals_D3 by fastforce have auxs:"(\<forall>i.(a_que_aux (locals_' x !i) ch_id = a_que_aux (locals_' ?x' !i) ch_id) \<and> (r_que_aux (locals_' x !i) ch_id = r_que_aux (locals_' ?x' !i) ch_id) )" by (metis aux_eq b0 b1 b2) thus ?thesis using pre_quecom_ch[OF a0 _ _ _ b4 preserves_locals_D1[OF b0] pts auxs a1] by auto qed lemma modify_mut_QueCom: "i< procs conf \<Longrightarrow> state_conf x \<Longrightarrow> port_open (communication_' x)(pt (locals_' x ! i)) \<Longrightarrow> x \<in> Pre_QueCom_ch B adds rems ch_id \<Longrightarrow> x\<lparr>communication_' := port_set_mutex conf (communication_' x) (pt (locals_' x ! i)) (Suc i)\<rparr> \<in> Pre_QueCom_ch B adds rems ch_id" proof- let ?x' = "x\<lparr>communication_' := port_set_mutex conf (communication_' x) (pt (locals_' x ! i)) (Suc i)\<rparr>" let ?ch_id = "port_channel conf (communication_' x) (pt(locals_' x!i))" assume a0:"i< procs conf" and a0':"state_conf x" and a1':"port_open (communication_' x)(pt (locals_' x ! i))" and a1:"x\<in>Pre_QueCom_ch B adds rems ch_id" have p:"port_in_channel conf (communication_' x) (pt (locals_' x ! i)) ?ch_id" using a1 port_unique_channel[OF _ a1'] unfolding Pre_QueCom_ch_def by auto have b0:"(x, ?x', i) \<in> preserves_locals_constr" and b0':"(x, ?x', ?ch_id) \<in> preserves_comm_constr" and b1:"a_que_aux (locals_' x ! i) = a_que_aux (locals_' ?x' ! i)" and b2:"r_que_aux (locals_' x ! i) = r_que_aux (locals_' ?x' ! i)" using modify_mutex_preserves_locals[OF a0' a1' p] by auto have pts:"\<forall>i. pt (locals_' x ! i) = pt (locals_' ?x' ! i)" using b0 using preserves_locals_D2 preserves_locals_D3 by fastforce have auxs:"(\<forall>i.(a_que_aux (locals_' x !i) ch_id = a_que_aux (locals_' ?x' !i) ch_id) \<and> (r_que_aux (locals_' x !i) ch_id = r_que_aux (locals_' ?x' !i) ch_id) )" by (metis aux_eq b0 b1 b2) thus ?thesis using pre_quecom_ch[OF a0 _ _ _ _ preserves_locals_D1[OF b0] pts auxs a1] b0' unfolding port_set_mutex_def Let_def channel_set_mutex_def chan_queuing_def chan_sampling_def preserves_comm_constr_def by auto qed lemma modify_mut_zero_ret_QueCom: "i<procs conf \<Longrightarrow> x \<in> Pre_QueCom_ch B adds rems ch_id \<Longrightarrow> port_get_mutex conf (communication_' x) (pt (locals_' x ! i)) = Suc i \<Longrightarrow> port_open (communication_' x) (pt (locals_' x!i)) \<Longrightarrow> x\<lparr>locals_' := (locals_' x)[i := (locals_' x ! i)\<lparr>ret_n := Suc 0\<rparr>], communication_' := port_set_mutex conf (communication_' x) (pt ((locals_' x)[i := ((locals_' x) ! i)\<lparr>ret_n := Suc 0\<rparr>] ! i)) 0\<rparr> \<in> Pre_QueCom_ch B adds rems ch_id" proof- let ?x' = "x\<lparr>locals_' := (locals_' x)[i := ((locals_' x) ! i)\<lparr>ret_n := Suc 0\<rparr>], communication_' := port_set_mutex conf (communication_' x) (pt ((locals_' x)[i := ((locals_' x) ! i)\<lparr>ret_n := Suc 0\<rparr>] ! i)) 0\<rparr>" let ?ch_id = "port_channel conf (communication_' x) (pt(locals_' x!i))" assume a0:"i< procs conf" and a1':"port_open (communication_' x) (pt (locals_' x!i))" and a1:"x\<in>Pre_QueCom_ch B adds rems ch_id" then have a0':"i<length (locals_' x)" unfolding Pre_QueCom_ch_def state_conf_def by auto have p:"port_in_channel conf (communication_' x) (pt (locals_' x ! i)) ?ch_id" using a1 port_unique_channel[OF _ a1'] unfolding Pre_QueCom_ch_def by auto have b0:"(x, ?x', i) \<in> preserves_locals_constr" and b0':"(x, ?x', ?ch_id) \<in> preserves_comm_constr" and b1:"a_que_aux (locals_' x ! i) = a_que_aux (locals_' ?x' ! i)" and b2:"r_que_aux (locals_' x ! i) = r_que_aux (locals_' ?x' ! i)" using modify_mutex_ret_preserves_locals[OF a0' _ a1' p] a1[simplified Pre_QueCom_ch_def] by auto have pts:"\<forall>i. pt (locals_' x ! i) = pt (locals_' ?x' ! i)" using b0 using preserves_locals_D2 preserves_locals_D3 by fastforce have auxs:"(\<forall>i.(a_que_aux (locals_' x !i) ch_id = a_que_aux (locals_' ?x' !i) ch_id) \<and> (r_que_aux (locals_' x !i) ch_id = r_que_aux (locals_' ?x' !i) ch_id) )" by (metis aux_eq b0 b1 b2) thus ?thesis using pre_quecom_ch[OF a0 _ _ _ _ preserves_locals_D1[OF b0] pts auxs a1] b0' unfolding port_set_mutex_def Let_def channel_set_mutex_def chan_queuing_def chan_sampling_def preserves_comm_constr_def by auto qed lemma insert_queue_preserves_QueCom: assumes a0:"i < procs conf" and a1:"x \<in> Pre_QueCom_ch B adds rems ch_id" and a2:" port_open (communication_' x) (pt (locals_' x!i))" and a3:"x' = x\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' x) (pt (locals_' x ! i)) (msg (locals_' x ! i)) t) (pt ((locals_' x) [i := (locals_' x ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' x) (pt (locals_' x ! i)) (a_que_aux (locals_' x ! i)) (add_mset (msg (locals_' x ! i)) (get_que_aux conf (communication_' x) (pt (locals_' x ! i)) (a_que_aux (locals_' x ! i))))\<rparr>] ! i)) 0, locals_' := (locals_' x) [i := ((locals_' x) [i := (locals_' x ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' x) (pt (locals_' x ! i)) (a_que_aux (locals_' x ! i)) (add_mset (msg (locals_' x ! i)) (get_que_aux conf (communication_' x) (pt (locals_' x ! i)) (a_que_aux (locals_' x ! i))))\<rparr>] ! i) \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" shows "x' \<in> Pre_QueCom_ch B adds rems ch_id" proof- let ?ch_id = "port_channel conf (communication_' x) (pt(locals_' x!i))" have a0':"i<length (locals_' x)" using a0 a1 unfolding Pre_QueCom_ch_def state_conf_def by auto then have eq_s':"x' = x\<lparr>communication_' := port_set_mutex conf (port_insert_message conf (communication_' x) (pt (locals_' x ! i)) (msg (locals_' x ! i)) t) (pt (locals_' x !i)) 0, locals_' := (locals_' x) [i := (locals_' x ! i) \<lparr>a_que_aux := set_que_aux conf (communication_' x) (pt (locals_' x ! i)) (a_que_aux (locals_' x ! i)) (add_mset (msg (locals_' x ! i)) (get_que_aux conf (communication_' x) (pt (locals_' x ! i)) (a_que_aux (locals_' x ! i))))\<rparr> \<lparr>ret_n := Suc 0\<rparr>]\<rparr>" using a3 by auto have p:"port_in_channel conf (communication_' x) (pt (locals_' x ! i)) ?ch_id" using a1 port_unique_channel[OF _ a2] unfolding Pre_QueCom_ch_def by auto have b0:"(x, x', i) \<in> preserves_locals_constr" and b0':"(x, x', ?ch_id) \<in> preserves_comm_constr" and b1:"(\<forall>j. j\<noteq> ?ch_id \<longrightarrow> a_que_aux ((locals_' x')!i) j = a_que_aux ((locals_' x)!i) j)" and b2:"r_que_aux (locals_' x ! i) = r_que_aux (locals_' x' ! i)" using transit_send_que_preserve_locals'[OF a0' _ a2 p eq_s'] a1[simplified Pre_QueCom_ch_def]by auto have pts:"\<forall>i. pt (locals_' x ! i) = pt (locals_' x' ! i)" using b0 using preserves_locals_D2 preserves_locals_D3 by fastforce have chans:" chans (communication_' x) ?ch_id \<noteq> chans (communication_' x') ?ch_id \<longrightarrow> (\<forall>chs. chans (communication_' x) ?ch_id = Some chs \<longrightarrow> (\<exists>chs'. chans (communication_' x') ?ch_id = Some chs' \<and> chan_queuing chs = chan_queuing chs'))" using eq_s' unfolding port_set_mutex_def port_insert_message_def Let_def channel_insert_message_def channel_set_messages_def channel_set_mutex_def chan_queuing_def chan_sampling_def port_channel_def port_in_channel_def port_id_name_def port_exists_def apply auto apply (case_tac "data chs") apply auto apply (case_tac "data chs") by auto show ?thesis using pre_quecom_ch'[OF a0 _ _ chans _ preserves_locals_D1[OF b0] pts _] b0' unfolding port_set_mutex_def Let_def channel_set_mutex_def chan_queuing_def chan_sampling_def preserves_comm_constr_def port_insert_message_def channel_insert_message_def using a1 b0 b1 b2 preserves_locals_D2 by fastforce qed lemma sta_cond_spec:"LocalRG_HoareDef.Sta ( \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i))\<rbrace>) (Rely_Send_ReceiveQ i)" unfolding Sta_def apply clarify apply (frule rely_eq_ports1) unfolding p_queuing_def port_exists_def port_channel_def port_in_channel_def port_id_name_def port_open_def p_source_def port_id_in_part_def port_max_size_def port_id_in_part_def by fastforce lemma sta_cond_PreQue:"i < Sys_Config.procs conf \<Longrightarrow> LocalRG_HoareDef.Sta (Pre_QueCom_ch B adds rems ch_id \<inter> \<lbrace>evnt (\<acute>locals ! i) = x\<rbrace> \<inter> \<lbrace>port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> port_open \<acute>communication (pt (\<acute>locals ! i))\<rbrace>) (Rely_Send_ReceiveQ i)" using sta_cond sta_event_inv_PreQue by (fastforce intro:Sta_intro) lemma sta_not_cond_inv_PreQue:"i < Sys_Config.procs conf \<Longrightarrow> LocalRG_HoareDef.Sta (Pre_QueCom_ch B adds rems ch_id \<inter> \<lbrace>evnt (\<acute>locals ! i) = x\<rbrace> \<inter> - \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace>) (Rely_Send_ReceiveQ i)" using sta_not_cond sta_event_inv_PreQue by (fastforce intro:Sta_intro) lemma sta_not_cond_inv_mut1_PreQue: "i < Sys_Config.procs conf \<Longrightarrow> LocalRG_HoareDef.Sta (Pre_QueCom_ch B adds rems ch_id \<inter> \<lbrace>evnt (\<acute>locals ! i) = x\<rbrace> \<inter> - \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace> \<inter> \<lbrace>port_get_mutex conf \<acute>communication (pt (\<acute>locals ! i)) = Suc i\<rbrace>) (Rely_Send_ReceiveQ i)" by (auto intro: subst[of "(Pre_QueCom_ch B adds rems ch_id \<inter> \<lbrace>evnt (\<acute>locals ! i) = x\<rbrace> \<inter> - \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace> \<inter> (\<lbrace>p_source conf \<acute>communication (pt (\<acute>locals ! i))\<and> port_open \<acute>communication (pt (\<acute>locals ! i))\<rbrace> \<inter> \<lbrace>port_get_mutex conf \<acute>communication (pt (\<acute>locals ! i)) = Suc i\<rbrace>))"] dest: Sta_intro[OF sta_not_cond_inv_PreQue sta_not_cond_inv_mut]) lemma send_correct': " i < Sys_Config.procs conf \<Longrightarrow> \<Gamma>,{} \<turnstile>\<^bsub>/{}\<^esub> send_q_message_i i sat [Pre_QueCom_ch B adds rems ch_id \<inter> \<lbrace>evnt (\<acute>locals ! i) = Send_Message_Q\<rbrace>, Rely_Send_ReceiveQ i, Guarantee_Send_Receive i, Pre_QueCom_ch B adds rems ch_id,UNIV]" apply (auto simp add: Norm_def send_q_message_i_def reflexive_Guarantee_Send Int_assoc ) apply (rule If,(auto simp add: reflexive_Guarantee_Send)) apply (rule sta_event_inv_PreQue, assumption) apply (rule conseqPre[where p'="Pre_QueCom_ch B adds rems ch_id"]) apply (rule Basic) apply (rule sta_cond_PreQue sta_no_channel_rely_send, assumption)+ apply(simp add: modify_ret_n_guarantee Pre_QueCom_ch_def) apply (auto simp add: modify_ret_QueCom ) apply (rule Seq[where q="Pre_QueCom_ch B adds rems ch_id \<inter> (\<lbrace>evnt (\<acute>locals ! i) = Send_Message_Q\<rbrace>) \<inter> - \<lbrace>port_open \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> port_id_in_part conf \<acute>communication (current (schedule (\<acute>locals ! i))) (pt (\<acute>locals ! i)) \<longrightarrow> p_source conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> p_queuing conf \<acute>communication (pt (\<acute>locals ! i)) \<longrightarrow> \<not> snd (msg (\<acute>locals ! i)) \<le> port_max_size conf \<acute>communication (pt (\<acute>locals ! i))\<rbrace> \<inter> \<lbrace>port_get_mutex conf \<acute>communication (pt (\<acute>locals ! i)) = (Suc i)\<rbrace>"], (auto simp add: reflexive_Guarantee_Send)) apply (rule sta_uni sta_not_cond_inv_PreQue, assumption?)+ apply (rule Await) apply (rule sta_uni sta_not_cond_inv_PreQue sta_not_cond_inv_mut1_PreQue, assumption?)+ apply vcg apply (auto simp add: current_def port_get_set_mutex)[1] apply (simp add: modify_mutex_send_guarantee Pre_QueCom_ch_def) apply (rule modify_mut_QueCom, assumption+, simp add:Pre_QueCom_ch_def, assumption+) apply (auto simp add: port_id_in_part_def p_source_def channel_id_get_source_def port_name_in_channel_def port_channel_def port_in_channel_def port_id_name_def port_exists_def Let_def port_set_mutex_def p_queuing_def port_open_def port_max_size_def)[5] apply (rule Await) apply (rule sta_uni sta_no_channel_rely_send sta_not_cond_inv_mut1_PreQue, assumption?)+ apply vcg apply (auto simp add: eq_insert) apply (simp add: modify_ret_mutex_zero_guarantee Pre_QueCom_ch_def) apply (auto simp add: current_def modify_mut_zero_ret_QueCom) apply (simp add: send_message_clear_mutex_temp_msg_guar Pre_QueCom_ch_def) by (auto simp add: insert_queue_preserves_QueCom) end
lemma content_times_primitive_part [simp]: "smult (content p) (primitive_part p) = p" for p :: "'a :: semiring_gcd poly"
------------------------------------------------------------------------ -- Products (variants for Set₁) ------------------------------------------------------------------------ -- I want universe polymorphism. module Data.Product1 where open import Data.Function open import Relation.Nullary infixr 4 _,_ infixr 2 _×₀₁_ _×₁₀_ _×₁₁_ ------------------------------------------------------------------------ -- Definition data Σ₀₁ (a : Set) (b : a → Set₁) : Set₁ where _,_ : (x : a) (y : b x) → Σ₀₁ a b data Σ₁₀ (a : Set₁) (b : a → Set) : Set₁ where _,_ : (x : a) (y : b x) → Σ₁₀ a b data Σ₁₁ (a : Set₁) (b : a → Set₁) : Set₁ where _,_ : (x : a) (y : b x) → Σ₁₁ a b ∃₀₁ : {A : Set} → (A → Set₁) → Set₁ ∃₀₁ = Σ₀₁ _ ∃₁₀ : {A : Set₁} → (A → Set) → Set₁ ∃₁₀ = Σ₁₀ _ ∃₁₁ : {A : Set₁} → (A → Set₁) → Set₁ ∃₁₁ = Σ₁₁ _ _×₀₁_ : Set → Set₁ → Set₁ A ×₀₁ B = Σ₀₁ A (λ _ → B) _×₁₀_ : Set₁ → Set → Set₁ A ×₁₀ B = Σ₁₀ A (λ _ → B) _×₁₁_ : Set₁ → Set₁ → Set₁ A ×₁₁ B = Σ₁₁ A (λ _ → B) ------------------------------------------------------------------------ -- Functions proj₀₁₁ : ∀ {a b} → Σ₀₁ a b → a proj₀₁₁ (x , y) = x proj₀₁₂ : ∀ {a b} → (p : Σ₀₁ a b) → b (proj₀₁₁ p) proj₀₁₂ (x , y) = y proj₁₀₁ : ∀ {a b} → Σ₁₀ a b → a proj₁₀₁ (x , y) = x proj₁₀₂ : ∀ {a b} → (p : Σ₁₀ a b) → b (proj₁₀₁ p) proj₁₀₂ (x , y) = y proj₁₁₁ : ∀ {a b} → Σ₁₁ a b → a proj₁₁₁ (x , y) = x proj₁₁₂ : ∀ {a b} → (p : Σ₁₁ a b) → b (proj₁₁₁ p) proj₁₁₂ (x , y) = y map₀₁ : ∀ {A B P Q} → (f : A → B) → (∀ {x} → P x → Q (f x)) → Σ₀₁ A P → Σ₀₁ B Q map₀₁ f g p = (f (proj₀₁₁ p) , g (proj₀₁₂ p)) map₁₀ : ∀ {A B P Q} → (f : A → B) → (∀ {x} → P x → Q (f x)) → Σ₁₀ A P → Σ₁₀ B Q map₁₀ f g p = (f (proj₁₀₁ p) , g (proj₁₀₂ p)) map₁₁ : ∀ {A B P Q} → (f : A → B) → (∀ {x} → P x → Q (f x)) → Σ₁₁ A P → Σ₁₁ B Q map₁₁ f g p = (f (proj₁₁₁ p) , g (proj₁₁₂ p))
module Aexamples where open import Data.List hiding (reverse) open import Data.List.All open import Data.Nat open import Typing open import Syntax open import Async {- Lithmus test for asynchronous operations A thread send something to an asynchronous channel and receives it afterwards. -} aex1 : Expr [] TUnit aex1 = letbind [] (anew [] (delay send!)) (letpair (left []) (here []) (letbind (left (rght [])) (aclose (here [])) (await (there UUnit (here []))))) -- just replace synchronous operations by the asynchronous ones asyncex1 : Expr [] TUnit asyncex1 = letbind [] (anew [] (delay send!)) (letpair (left []) (here []) (letbind (rght (left [])) (fork (await (here []))) (aclose (there UUnit (here []))))) -- sending and receiving asyncex2 : Expr [] TUnit asyncex2 = letbind [] (anew [] (delay (send TInt (delay send!)))) (letpair (left []) (here []) (letbind (left (rght [])) (fork (letbind (rght []) (nat [] 42) (letbind (left (left [])) (asend (rght (left [])) (here []) (here [])) (letbind (left []) (aclose (here [])) (var (here [])))))) (letbind (rght (left [])) (arecv (here [])) (letpair (left (rght [])) (here []) (letbind (left (left (rght []))) (await (here (UInt ∷ []))) (var (here (UUnit ∷ []))))))))
[GOAL] x : ℤ ⊢ IsUnit x ↔ |x| = 1 [PROOFSTEP] rw [isUnit_iff_natAbs_eq, abs_eq_natAbs, ← Int.ofNat_one, coe_nat_inj'] [GOAL] a : ℤ ha : IsUnit a ⊢ a ^ 2 = 1 [PROOFSTEP] rw [sq, isUnit_mul_self ha] [GOAL] u : ℤˣ ⊢ u ^ 2 = 1 [PROOFSTEP] rw [Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one, isUnit_sq u.isUnit] [GOAL] u : ℤˣ ⊢ u * u = 1 [PROOFSTEP] rw [← sq, units_sq] [GOAL] u : ℤˣ ⊢ u⁻¹ = u [PROOFSTEP] rw [inv_eq_iff_mul_eq_one, units_mul_self] [GOAL] u : ℤˣ ⊢ ↑u * ↑u = 1 [PROOFSTEP] rw [← Units.val_mul, units_mul_self, Units.val_one] [GOAL] n : ℕ ⊢ 0 < |(-1)| [PROOFSTEP] simp [GOAL] u : ℤˣ n : ℕ ⊢ u ^ n = u ^ (n % 2) [PROOFSTEP] conv => lhs rw [← Nat.mod_add_div n 2]; rw [pow_add, pow_mul, units_sq, one_pow, mul_one] [GOAL] u : ℤˣ n : ℕ | u ^ n = u ^ (n % 2) [PROOFSTEP] lhs rw [← Nat.mod_add_div n 2]; rw [pow_add, pow_mul, units_sq, one_pow, mul_one] [GOAL] u : ℤˣ n : ℕ | u ^ n = u ^ (n % 2) [PROOFSTEP] lhs rw [← Nat.mod_add_div n 2]; rw [pow_add, pow_mul, units_sq, one_pow, mul_one] [GOAL] u : ℤˣ n : ℕ | u ^ n = u ^ (n % 2) [PROOFSTEP] lhs [GOAL] u : ℤˣ n : ℕ | u ^ n [PROOFSTEP] rw [← Nat.mod_add_div n 2] [GOAL] u : ℤˣ n : ℕ | u ^ (n % 2 + 2 * (n / 2)) [PROOFSTEP] rw [pow_add, pow_mul, units_sq, one_pow, mul_one]
(* Title: HOL/ex/While_Combinator_Example.thy Author: Tobias Nipkow Copyright 2000 TU Muenchen *) section {* An application of the While combinator *} theory While_Combinator_Example imports "~~/src/HOL/Library/While_Combinator" begin text {* Computation of the @{term lfp} on finite sets via iteration. *} theorem lfp_conv_while: "[| mono f; finite U; f U = U |] ==> lfp f = fst (while (\<lambda>(A, fA). A \<noteq> fA) (\<lambda>(A, fA). (fA, f fA)) ({}, f {}))" apply (rule_tac P = "\<lambda>(A, B). (A \<subseteq> U \<and> B = f A \<and> A \<subseteq> B \<and> B \<subseteq> lfp f)" and r = "((Pow U \<times> UNIV) \<times> (Pow U \<times> UNIV)) \<inter> inv_image finite_psubset (op - U o fst)" in while_rule) apply (subst lfp_unfold) apply assumption apply (simp add: monoD) apply (subst lfp_unfold) apply assumption apply clarsimp apply (blast dest: monoD) apply (fastforce intro!: lfp_lowerbound) apply (blast intro: wf_finite_psubset Int_lower2 [THEN [2] wf_subset]) apply (clarsimp simp add: finite_psubset_def order_less_le) apply (blast dest: monoD) done subsection {* Example *} text{* Cannot use @{thm[source]set_eq_subset} because it leads to looping because the antisymmetry simproc turns the subset relationship back into equality. *} theorem "P (lfp (\<lambda>N::int set. {0} \<union> {(n + 2) mod 6 | n. n \<in> N})) = P {0, 4, 2}" proof - have seteq: "!!A B. (A = B) = ((!a : A. a:B) & (!b:B. b:A))" by blast have aux: "!!f A B. {f n | n. A n \<or> B n} = {f n | n. A n} \<union> {f n | n. B n}" apply blast done show ?thesis apply (subst lfp_conv_while [where ?U = "{0, 1, 2, 3, 4, 5}"]) apply (rule monoI) apply blast apply simp apply (simp add: aux set_eq_subset) txt {* The fixpoint computation is performed purely by rewriting: *} apply (simp add: while_unfold aux seteq del: subset_empty) done qed end
lemma holomorphic_on_ident [simp, holomorphic_intros]: "(\<lambda>x. x) holomorphic_on s"
/- (1) Boo! Happy Halloween! (2) You gotta love the ℕs! (3) Notes from Tue in IN (4) Weather warning. (3) No exam on Tuesday. -/ /- Review: We define day to be a type. -/ inductive day : Type /- Type is the type of *computational* types. Constructors define the values of the type. -/ | mon | tue | wed | thu | fri | sat | sun /- Now we can define variables of this type. -/ open day def d : day := tue /- NEW IDEA: another syntax for defintions Definition now given by a "PROOF SCRIPT" -/ def d' : day := begin exact sat, end /- *************************************** Propositions as Types, Proofs as Values *************************************** -/ /- We define emily's_from_cville to be a new kind of type: a logical type as opposed to a computational type. We understand this *type* to represent a proposition. Now the question, is what does it mean to have a proof of such a proposition? Informally, we might say that we'll take a driver's license, passport, or utility bill as a proof. We can formalize this idea by defining drivers_license, passport, and proof to be *values* of this type! We have a proof of a proposition if we can produce a value of its type! -/ inductive emily's_from_cville : Prop /- Constructors define the values, which we now accept as "proofs" of the proposition Proofs in Lean are values of *logical* types. -/ | drivers_license | passport | utility_bill open emily's_from_cville -- Proofs represented formally as *values* def a_proof : emily's_from_cville := passport theorem a_proof' : emily's_from_cville := utility_bill theorem a_proof'' : emily's_from_cville := begin exact utility_bill, end /- Note the use of def in the first example and theorem in the second. There is no practical difference. We use "theorem" to inform the reader that we intend to produce a proof of a proposition. -/ /- **************************************** Predicates as parameterized propositions **************************************** -/ /- Here's aother data (computational) type. -/ inductive person : Type | mari | jose | jane | bill open person inductive mari_is_from_cville : Prop | yes_she_is #check mari_is_from_cville open mari_is_from_cville theorem mari_proof : mari_is_from_cville := yes_she_is /- We can generalize from a specific proposition, such as *emily* is from charlottesville to one that allows us to assert that any given person is from charlottesville. We do this by adding a parameter. The result is what we call a predicate. We can say that a predicate is a proposition with a parameter. When applied to an argument of the right type, the result is again a proposition. Ex: inductive is_from_cville : person → Prop The constructors of the parameterized type define the set of proofs that can be produced for each of the corresponding propositions. -/ inductive is_from_cville : person → Prop | proof_for : ∀ (p : person), p = mari → is_from_cville p #check is_from_cville #check is_from_cville mari #check is_from_cville jose #check is_from_cville jane #check is_from_cville bill open is_from_cville #check proof_for /- Think of a proof of a "∀" proposition as being like a function. A constructor is a proof. In particular, proof_for can be understood as a proof of the ∀ claim. So we can treat proof_for as a function that takes a person as an argument and that returns a proposition, obtained by applying the predicate on the right of the comma to the given argument. -/ #check proof_for mari #check proof_for jose #check proof_for bill theorem mifc : is_from_cville mari := begin apply proof_for _ _, apply eq.refl mari, end theorem bifc : is_from_cville bill := begin apply proof_for, _ end /- What we're seeing here is what we call the elimination principle for proofs of ∀ propositions. We can treat such a proof as a function and apply it to a particular object of the quantified type to get a proof for the stated proposition *about that particular object*. Here' we get back proofs of proposition such as mari = mari → is_from_cvill mari and bill = mari → is_from_cville bill. Each of these is a proof of an implication, of the form P → Q, which we can also treat as a kind of function: if we can produce a proof of a premise, then we can apply the proof-of-implication/function to it to get a proof of the conclusion. In this case, we will be able to construct and thereby obtain a proof of mari = mari, but there is no proof of bill = mari, so we will be able to construct a proof of the proposition, (is_from_cville mari) but not one of (is_from_cville bill). -/ /- Understand that the constructors of a type are to be understood as the "axioms," or fundamental rules of reasoning, for a given type. They tell us exactly how we can produce values (or proofs) of a given type (or proposition, understood as a type). -/ /- As an example, suppose we to prove the proposition that mari is from cville. Formally we'd state this as the proposition (is_from_cville mari). To prove it, we need to construct a proof. To do that, we have to use the only available "reasoning rule", which is given by the one constructor for this type, namely: proof_for : ∀ (p : person), p = mari → is_from_cville p What this says is that for any person, p, *if* you have a proof that (p = mari) then you can derive a proof of (is_from_cville mari). In plain English, the proof would thus go like this: "To produce a proof of (is_from_cville mari) we first apply the `proof_for' rule to mari to conclude that (mari = mari) → is_from_cville mari. To prove the conclusion, it will suffice to produce a proof of (mari = mari). But this follows from the reflexivity of the equality relation. QED." Now look at what happens if we try to prove jane is from cville. We apply proof_for to jane, yielding the proposition, (jane = mari) → is_from_cville jane. The conclusion is what we want, but to reach it, we have to produce a proof of (jane = mari), and there is no way to do that because jane and mari are different people. So we are stuck, with no way to build the proof we require. -/ /- ****************************************** Predicates define properties and relations ****************************************** -/ /- The is_from_cville predicate defines the "property" of being from Charlottesville. Only mari has this property according to our definitions, because only for mari is there a proof. A predicate of one argument defines proofs for none, some, or all values of its argument type and thereby identifies those with the given property. A predicate of two arguments similarly defines a *relation*: a set of pairs of values that have a given property. The equality relation is a very good example. We accept as an axiom that there is a proof for every proposition of the form, a = a, no matter what type of thing a is, and that there are no other proofs of equalities. (Slight footnote here.) This idea is formalized in Lean with a predicate called that takes two arguments (of any given type -- it's polymorphic), for which there's a proof only if both are the same. Convention infix notation uses the = operator. -/ #check eq 4 4 #check eq 4 5 #check 4 = 5 #check eq "Hi" "Hi" /- Each of these terms is a proposition/type. There are proofs for those that are true! The proofs are constructed by a constructor called refl defined for the eq type. We refer to it as eq.refl. It takes *one* argument, a, and yields a proof/value of type a = a. It's thus impossible to create a proof of a = b unless a and b are really equal to each other! -/ #check (eq.refl 3) #check (eq.refl "Hi") #check (eq.refl mari) /- The term, (proof_for mari (eq.refl mari)), is accepted as a value of type (is_from_cville mari), i.e., as a proof that mari is from charlottesville. Can we construct a proof -/ theorem mari_is_from_cville' : is_from_cville mari := begin apply proof_for mari _, exact (eq.refl mari), _ end -- YAY! theorem mari_is_from_cville'' : is_from_cville mari := begin apply proof_for _ _, -- lean infer first arg! --exact mari, exact (eq.refl mari), end theorem bill_is_from_cville : is_from_cville bill := begin apply proof_for _ _, -- lean infer first arg! --exact mari, exact (eq.refl mari), -- no way end /- End of lecture -/ /- Some comments about function definitions. Consider the following simple definition. -/ def evenb (n : ℕ) : bool := n % 2 = 0 #eval evenb 3 #eval evenb 4 #check evenb def evenb' : ℕ → bool := λ n, n % 2 = 0 def evenb'' : Π (n : ℕ), bool := λ n, n % 2 = 0 #eval evenb'' 5 def evenb''' : ∀ (n : ℕ), bool := λ n, n % 2 = 0 #eval evenb''' 6 /- Predicates are often used to represent properties of objects, here, a property of people, namely the property of a person being from Cville. -/ inductive is_zero : ℕ → Prop | zmk: ∀ (n : ℕ), n = 0 → is_zero n open is_zero theorem zero_is_zero_0 : is_zero 0 := zmk 0 (eq.refl 0) /- Even: inductively defined proofs -/ inductive is_even : ℕ → Prop | pf_zero_is_even : (is_even 0) | pf_even_plus_two_is_even : ∀ (n : ℕ), is_even n → is_even (nat.succ (nat.succ n)) open is_even theorem zero_is_even : is_even 0 := pf_zero_is_even theorem zero_is_even' : is_even 0 := begin exact pf_zero_is_even end /- Inductive -/ theorem two_is_even : is_even 2 := pf_even_plus_two_is_even 0 zero_is_even theorem four_is_even : is_even 4 := pf_even_plus_two_is_even 2 two_is_even theorem ten_is_even : is_even 1000 := begin repeat { apply pf_even_plus_two_is_even }, exact pf_zero_is_even, end #print ten_is_even theorem two_is_even' : is_even 2 := begin apply pf_even_plus_two_is_even 0 zero_is_even, end theorem two_is_even'' : is_even 2 := begin apply pf_even_plus_two_is_even 0 _, exact zero_is_even, end theorem two_is_even''' : is_even 2 := begin apply pf_even_plus_two_is_even _ _, exact zero_is_even, end theorem two_is_even'''' : is_even 2 := begin apply pf_even_plus_two_is_even, exact zero_is_even, end theorem four_is_even' : is_even 4 := pf_even_plus_two_is_even 2 two_is_even theorem four_is_even'' : is_even 4 := begin apply pf_even_plus_two_is_even 2 two_is_even, end theorem four_is_even''' : is_even 4 := begin apply pf_even_plus_two_is_even, apply two_is_even, end theorem four_is_even'''' : is_even 4 := begin apply pf_even_plus_two_is_even, apply pf_even_plus_two_is_even, apply zero_is_even, end theorem ten_is_even' : is_even 10 := begin apply pf_even_plus_two_is_even, apply pf_even_plus_two_is_even, apply pf_even_plus_two_is_even, apply pf_even_plus_two_is_even, apply pf_even_plus_two_is_even, exact zero_is_even, end #print ten_is_even' -- Here's some automation in Lean theorem ten_is_even'' : is_even 10 := begin repeat {apply pf_even_plus_two_is_even}, exact zero_is_even, end inductive successor_of : ℕ → ℕ → Prop | mk : ∀ (n : ℕ), successor_of (nat.succ n) n theorem five_succ_four : successor_of 5 4 := successor_of.mk 4 inductive equal_to_nat : ℕ → ℕ → Prop | refl : ∀ (n : ℕ), equal_to_nat n n theorem five_equals_five : equal_to_nat 5 5 := equal_to_nat.refl 5 theorem five_equals_five' : equal_to_nat 5 5 := begin apply equal_to_nat.refl _, end inductive equal_to_nat' (n : ℕ) : ℕ → Prop | refl : ∀ (n : ℕ), equal_to_nat' n #check equal_to_nat #check equal_to_nat' theorem five_eq_five'' : equal_to_nat' 5 5 := equal_to_nat'.refl 5 5 inductive equal_to {α : Type} : α → α → Prop | refl : ∀ (a : α), equal_to a a
# Find worst cases \begin{equation} \begin{array}{rl} \mathcal{F}_L =& \dfrac{4 K I H r}{Q_{in}(1+f)}\\ u_{c} =& \dfrac{-KI\mathcal{F}_L}{\theta \left(\mathcal{F}_L+1\right)}\\ \tau =& -\dfrac{r}{|u_{c}|}\\ C_{\tau,{\rm decay}}=& C_0 \exp{\left(-\lambda \tau \right)}\\ C_{\tau,{\rm filtr}}=& C_0 \exp{\left(-k_{\rm att} \tau \right)}\\ C_{\tau,{\rm dilut}} =& C_{in} \left( \dfrac{Q_{in}}{u_c \Delta y \Delta z} \right)\\ C_{\tau,{\rm both}} =& \dfrac{C_{\rm in}Q_{\rm in}}{u_c \Delta y H \theta} \exp{\left(-\lambda\dfrac{r}{|u_c|}\right)} \end{array} \end{equation} ```python %reset -f import numpy as np import matplotlib.pyplot as plt import matplotlib from os import system from matplotlib.gridspec import GridSpec from drawStuff import * ''' GLOBAL CONSTANTS ''' PI = 3.141592 THETA = 0.35 ``` ```python def flowNumber(): return (4.0*K*I*H*r) / (Qin*(1+f)) def uChar(): return -(K*I*flowNumber())/(THETA*(flowNumber() + 1)) def tChar(): return -r/uChar() def cDecay(): return C0 * np.exp(-decayRate * tChar()) def cDilut(): return (C0 * Qin) / (-uChar() * delY * delZ * THETA) def cBoth(): return (C0 * Qin) / (-uChar() * delY * delZ * THETA) * np.exp(-decayRate * tChar()) def findSweet(): deltaConc = np.abs(cBoth() - np.max(cBoth())) return np.argmin(deltaConc) ``` ```python K = 10**-2 Qin = 0.24/86400 f = 10 H = 20 r = 40 I = 0.001 C0 = 1.0 decayRate = 3.5353E-06 delY,delZ = 1.35,H ``` ```python print("Nondim Flow = {:.2E}".format(flowNumber())) print("Charac. Vel = {:.2E} m/s".format(uChar())) print("Charac. time = {:.2E} s".format(tChar())) ``` Nondim Flow = 1.05E+03 Charac. Vel = -2.85E-05 m/s Charac. time = 1.40E+06 s ```python print("Rel concenc. due decay = {:.2E}".format(cDecay())) print("Rel conc. due dilution = {:.2E}".format(cDilut())) print("Rel conc. due both eff = {:.2E}".format(cBoth())) ``` Rel concenc. due decay = 7.05E-03 Rel conc. due dilution = 1.03E-02 Rel conc. due both eff = 7.26E-05 ```python I = 10**np.linspace(-5,0,num=100) c1 = cDecay() c2 = cDilut() c3 = cBoth() i = findSweet() worstC = c3[i] worstI = I[i] ``` ```python fig, axs = plt.subplots(2,2,sharex=True, sharey=False,\ figsize=(12,8),gridspec_kw={"height_ratios":[1,3],"hspace":0.04,"wspace":0.35}) bbox = dict(boxstyle='round', facecolor='mintcream', alpha=0.90) arrowprops = dict( arrowstyle="->", connectionstyle="angle,angleA=90,angleB=10,rad=5") annotation = \ r"$\bf{-\log(C/C_0)} = $" + "{:.1f}".format(-np.log10(worstC)) + \ "\n@" + r" $\bf{I} = $" + "{:.1E}".format(worstI) information = \ r"$\bf{K}$" + " = {:.1E} m/s".format(K) + "\n"\ r"$\bf{H}$" + " = {:.1f} m".format(H) + "\n"\ r"$\bf{r}$" + " = {:.1f} m".format(r) + "\n"\ r"$\bf{Q_{in}}$" + " = {:.2f} m³/d".format(Qin*86400) + "\n"\ r"$\bf{f}$" + " = {:.1f}".format(f) + "\n"\ r"$\bf{\lambda}$" + " = {:.2E} 1/s".format(decayRate) # Ax1 - Relative concentration ax = axs[1,0] ax.plot(I,c1,label="Due decay",lw=3,ls="dashed",alpha=0.8) ax.plot(I,c2,label="Due dilution",lw=3,ls="dashed",alpha=0.8) #ax.plot(I,np.minimum(c1,c2),label="Overall effect",lw=3,c='k',alpha=0.9) ax.plot(I,c3,label="Overall effect",lw=3,c='k',alpha=0.9) ax.set_xscale("log") ax.set_yscale("log") ax.set_ylim(1.0E-10,1) ax.set_xlim(1.0E-4,1.0E-1) ax.set_xlabel("Water table gradient\n$I$ [m/m]") ax.set_ylabel("Relative Concentration\n$C/C_0$ [-]") ax.legend(loc="lower left",shadow=True) ax.annotate(annotation,(worstI,worstC), xytext=(0.05,0.85), textcoords='axes fraction', bbox=bbox, arrowprops=arrowprops) ax.text(0.65,0.05,information,bbox=bbox,transform=ax.transAxes) ax.axvline(x=I[i], lw = 1, ls = "dashed", c = "red") #################################### # Ax2 - log-removals ax = axs[1,1] ax.plot(I,-np.log10(c1),label="Due decay",lw=3,ls="dashed",alpha=0.8) ax.plot(I,-np.log10(c2),label="Due dilution",lw=3,ls="dashed",alpha=0.8) #ax.plot(I,-np.log10(np.minimum(c1,c2)),label="Overall effect",lw=3,c='k',alpha=0.9) ax.plot(I,-np.log10(c3),label="Overall effect",lw=3,c='k',alpha=0.9) ax.set_xscale("log") ax.set_ylim(0,10) ax.set_xlim(1.0E-4,1.0E-1) ax.set_xlabel("Water table gradient\n$I$ [m/m]") ax.set_ylabel("log-reductions\n$-\log(C/C_0)$ [-]") ax.legend(loc="lower right",shadow=True) ax.annotate(annotation,(worstI,-np.log10(worstC)), xytext=(0.05,0.10), textcoords='axes fraction', bbox=bbox, arrowprops=arrowprops) ax.text(0.65,0.70,information,bbox=bbox,transform=ax.transAxes) ax.axvline(x=I[i], lw = 1, ls = "dashed", c = "red") #################################### #Ax3 - Flow number ax = axs[0,1] ax.plot(I,flowNumber(),label="flowNumber",lw=3,c="gray") ax.axhline(y=1.0) ax.set_xscale("log") ax.set_yscale("log") ax.xaxis.set_tick_params(which="both",labeltop='on',top=True,bottom=False) ax.set_ylabel("Nondim. flow number\n$\mathcal{F}_L$ [-]") ax.axvline(x=I[i], lw = 1, ls = "dashed", c = "red") #Ax4 - Flow number ax = axs[0,0] ax.plot(I,flowNumber(),label="flowNumber",lw=3,c="gray") ax.axhline(y=1.0) ax.set_xscale("log") ax.set_yscale("log") ax.xaxis.set_tick_params(which="both",labeltop='on',top=True,bottom=False) ax.set_ylabel("Nondim. flow number\n$\mathcal{F}_L$ [-]") ax.axvline(x=I[i], lw = 1, ls = "dashed", c = "red") plt.show() ``` ____ # Find the worst case ## >> Geometric parameters $H$ and $r$ ```python K = 10**-2 Qin = 0.24/86400 f = 10 C0 = 1.0 decayRate = 3.5353E-06 Harray = np.array([2.,5.,10.,20.,50.]) rarray = np.array([5.,10.,40.,100.]) Iarray = 10**np.linspace(-5,0,num=100) Ci = np.zeros([len(rarray),len(Harray)]) Ii = np.zeros([len(rarray),len(Harray)]) FLi = np.zeros([len(rarray),len(Harray)]) for hi,H in enumerate(Harray): for ri,r in enumerate(rarray): i = findSweet() worstC = -np.log10(cBoth()[i]) worstGradient = Iarray[i] worstFlowNumber = flowNumber()[i] Ci[ri,hi] = worstC Ii[ri,hi] = worstGradient FLi[ri,hi] = worstFlowNumber ``` ```python myLabels={"Title": { 0: r"$\bf{-\log (C_{\tau}/C_0)}$", 1: r"$\bf{I}$ (%)", 2: r"$\log(\mathcal{F}_L)$"}, "Y": "Aquifer thickness\n$\\bf{H}$ (m)", "X": "Setback distance\n$\\bf{r}$ (m)"} threeHeatplots(data={"I":Ii.T,"C":Ci.T,"FL":FLi.T},\ xlabel=Harray,ylabel=rarray,myLabels=myLabels); ``` ## >>Well parameters ```python K = 10**-2 H = 20 r = 40 C0 = 1.0 decayRate = 3.5353E-06 Qin_array = np.array([0.24,1.0,10.0,100.])/86400. f_array = np.array([1,10.,100.,1000.,10000.]) Iarray = 10**np.linspace(-5,0,num=100) Ci = np.zeros([len(Qin_array),len(f_array)]) Ii = np.zeros([len(Qin_array),len(f_array)]) FLi = np.zeros([len(Qin_array),len(f_array)]) for fi,f in enumerate(f_array): for qi,Qin in enumerate(Qin_array): i = findSweet() worstC = -np.log10(cBoth()[i]) worstGradient = Iarray[i] worstFlowNumber = flowNumber()[i] Ci[qi,fi] = worstC Ii[qi,fi] = worstGradient FLi[qi,fi] = worstFlowNumber ### Plot heatmap myLabels={"Title": { 0: r"$\bf{-\log (C_{\tau}/C_0)}$", 1: r"$\bf{I}$ (%)", 2: r"$\log(\mathcal{F}_L)$"}, "Y": "Extraction to injection ratio\n$\\bf{f}$ (-)", "X": "Injection flow rate\n$\\bf{Q_{in}}$ (m³/d)"} threeHeatplots(data={"I":Ii.T,"C":Ci.T,"FL":FLi.T},\ xlabel=f_array,ylabel=np.round(Qin_array*86400,decimals=2),myLabels=myLabels); ``` ## Hydraulic conductivity ```python Qin = 0.24/86400 f = 10 C0 = 1.0 decayRate = 3.5353E-06 Karray = 10.**np.array([-1.,-2.,-3.,-4.,-5.]) rarray = np.array([5.,10.,40.,100.]) Iarray = 10**np.linspace(-5,0,num=100) Ci = np.zeros([len(rarray),len(Karray)]) Ii = np.zeros([len(rarray),len(Karray)]) FLi = np.zeros([len(rarray),len(Karray)]) for ki,K in enumerate(Karray): for ri,r in enumerate(rarray): i = findSweet() worstC = -np.log10(cBoth()[i]) worstGradient = Iarray[i] worstFlowNumber = flowNumber()[i] Ci[ri,ki] = worstC Ii[ri,ki] = worstGradient FLi[ri,ki] = worstFlowNumber ### Plot heatmap myLabels={"Title": { 0: r"$\bf{-\log (C_{\tau}/C_0)}$", 1: r"$\bf{I}$ (%)", 2: r"$\log(\mathcal{F}_L)$"}, "Y": "Hydraulic conductivity\n$\\bf{K}$ (m/s)", "X": "Setback distance\n$\\bf{r}$ (m)"} threeHeatplots(data={"I":Ii.T,"C":Ci.T,"FL":FLi.T},\ xlabel=Karray,ylabel=rarray,myLabels=myLabels); ``` ```python K = 10**-2 H = 20 f = 10 C0 = 1.0 decayRate = 3.5353E-06 Qin_array = np.array([0.24,1.0,10.0,100.])/86400. rarray = np.array([5.,10.,40.,100.]) Iarray = 10**np.linspace(-5,0,num=100) Ci = np.zeros([len(rarray),len(Qin_array)]) Ii = np.zeros([len(rarray),len(Qin_array)]) FLi = np.zeros([len(rarray),len(Qin_array)]) for qi,Qin in enumerate(Qin_array): for ri,r in enumerate(rarray): i = findSweet() worstC = -np.log10(cBoth()[i]) worstGradient = Iarray[i] worstFlowNumber = flowNumber()[i] Ci[ri,qi] = worstC Ii[ri,qi] = worstGradient FLi[ri,qi] = worstFlowNumber myLabels={"Title": { 0: r"$\bf{-\log (C_{\tau}/C_0)}$", 1: r"$\bf{I}$ (%)", 2: r"$\log(\mathcal{F}_L)$"}, "Y": "Injection flow rate\n$\\bf{Q_{in}}$ (m³/d)", "X": "Setback distance\n$\\bf{r}$ (m)"} threeHeatplots(data={"I":Ii.T,"C":Ci.T,"FL":FLi.T},\ ylabel=rarray,xlabel=np.round(Qin_array*86400,decimals=2),myLabels=myLabels); ``` ```python K = 10**-2 H = 20 f = 10 C0 = 1.0 decayRate = 1.119E-5 Qin_array = np.array([0.24,1.0,10.0,100.])/86400. rarray = np.array([5.,10.,40.,100.]) Iarray = 10**np.linspace(-5,0,num=100) Ci = np.zeros([len(rarray),len(Qin_array)]) Ii = np.zeros([len(rarray),len(Qin_array)]) FLi = np.zeros([len(rarray),len(Qin_array)]) for qi,Qin in enumerate(Qin_array): for ri,r in enumerate(rarray): i = findSweet() worstC = -np.log10(cBoth()[i]) worstGradient = Iarray[i] worstFlowNumber = flowNumber()[i] Ci[ri,qi] = worstC Ii[ri,qi] = worstGradient FLi[ri,qi] = worstFlowNumber myLabels={"Title": { 0: r"$\bf{-\log (C_{\tau}/C_0)}$", 1: r"$\bf{I}$ (%)", 2: r"$\log(\mathcal{F}_L)$"}, "Y": "Injection flow rate\n$\\bf{Q_{in}}$ (m³/d)", "X": "Setback distance\n$\\bf{r}$ (m)"} threeHeatplots(data={"I":Ii.T,"C":Ci.T,"FL":FLi.T},\ ylabel=rarray,xlabel=np.round(Qin_array*86400,decimals=2),myLabels=myLabels); ``` ## PLOTRAN SIMULATION RESULTS ```python minI = np.array([0.00046667, 0.0013 , 0.0048 , 0.012 , 0.00046667, 0.0013 , 0.0048 , 0.012 , 0.00053333, 0.0013 , 0.0048 , 0.012 , 0.00056667, 0.0021 , 0.0053 , 0.012 ]) minC = np.array([2.2514572 , 2.62298917, 3.14213329, 3.51421485, 1.64182175, 2.00913676, 2.52461269, 2.89537637, 0.74130696, 1.0754177 , 1.55071976, 1.90646243, 0.18705258, 0.39222131, 0.73428991, 1.00387133]) ``` ```python Qin_array = np.array([0.24,1.0,10.0,100.])/86400. rarray = np.array([5.,10.,40.,100.]) Iarray = 10**np.linspace(-5,0,num=100) Ci = np.zeros([len(rarray),len(Qin_array)]) Ii = np.zeros([len(rarray),len(Qin_array)]) FLi = np.zeros([len(rarray),len(Qin_array)]) i = 0 for qi,Qin in enumerate(Qin_array): for ri,r in enumerate(rarray): worstC = minC[i] worstGradient = minI[i] Ci[ri,qi] = worstC Ii[ri,qi] = worstGradient i += 1 myLabels={"Title": { 0: r"$\bf{-\log (C_{\tau}/C_0)}$", 1: r"$\bf{I}$ (%)", 2: r"$\log(\mathcal{F}_L)$"}, "Y": "Injection flow rate\n$\\bf{Q_{in}}$ (m³/d)", "X": "Setback distance\n$\\bf{r}$ (m)"} threeHeatplots(data={"I":Ii.T,"C":Ci.T,"FL":Ii.T},\ ylabel=rarray,xlabel=np.round(Qin_array*86400,decimals=2),myLabels=myLabels); ``` ```python ```
<a href="https://colab.research.google.com/github/lsantiago/PythonIntermedio/blob/master/Clases/Semana7_SYMPY/Clase7_SymPy_vacia.ipynb" target="_parent"></a> # CLASE 7: SymPy _ __SymPy es una biblioteca de Python para matemática simbólica__. Apunta a convertirse en un sistema de algebra computacional (__CAS__) con todas sus prestaciones manteniendo el código tan simple como sea posible para manterlo comprensible y fácilmente extensible. SymPy está __escrito totalmente en Python y no requiere bibliotecas adicionales__. _Este proyecto comenzó en 2005, fue lanzado al público en 2007 y a él han contribuido durante estos años cientos de personas._ _ Otros CAS conocidos son Mathematica y Maple, sin embargo ambos son software privativo y de pago. [Aquí](https://github.com/sympy/sympy/wiki/SymPy-vs.-Maple) puedes encontrar una comparativa de SymPy con Maple. _ Hoy veremos cómo: * Crear símbolos y expresiones. * Manipular expresiones (simplificación, expansión...) * Calcular derivadas e integrales. * Límites y desarrollos en serie. * Resolución de ecuaciones. * Resolción de EDOs. * Matrices Sin embargo, SymPy no acaba aquí ni mucho menos... ## Documentación & SymPy Live Shell [Documentacion](http://docs.sympy.org/latest/index.html) [SympyGamma](http://www.sympygamma.com/input/?i=integrate%281+%2F+%281+%2B+x^2%29%29) ## Creación de símbolos Lo primero, como siempre, es importar aquello que vayamos a necesitar: ```python !pip install sympy ``` ```python #import sympy as sp from sympy import * ``` ```python init_printing(use_latex=True) ``` * Gracias a `use_latex=True` obtenemos la salida en $\LaTeX$. * __Ha creado una serie de variables__ para que podamos ponernos a trabajar en el momento. <div class="alert warning-info"><strong>Nota:</strong> En Python, no se declaran las variables, sin embargo, no puedes usar una hasta que no le hayas asignado un valor. Si ahora intentamos crear una variable `a` que sea `a = 2 * b`, veamos qué ocurre: </div> ```python # Intentamos usar un símbolo que no hemos creado a = 2 * b ``` Como en `b` no había sido creada, Python no sabe qué es `b`. Esto mismo nos ocurre con los símbolos de SymPy. __Antes de usar una variable, debo decir que es un símbolo y asignárselo:__ ```python # Creamos el símbolo a a = symbols("a") a ``` ```python ``` ```python # Número pi (a + pi)**2 ``` ```python # Unidad imaginaria 1 + 2*I ``` ```python # Número e E ** 2 ``` ```python # Vemos qué tipo de variable es a type(a) ``` sympy.core.symbol.Symbol Ahora ya podría crear `b = 2 * a`: ```python b = 2 * a b ``` ```python ``` ¿Qué está ocurriendo? Python detecta que a es una variable de tipo `Symbol` y al multiplicarla por `2` devuelve una variable de Sympy. Como Python permite que el tipo de una variable cambie, __si ahora le asigno a `a` un valor float deja de ser un símbolo.__ ```python b = 2.0 ``` ```python type(b) ``` float --- __Las conclusiones son:__ * __Si quiero usar una variable como símbolo debo crearla previamente.__ * Las operaciones con símbolos devuelven símbolos. * Si una varibale que almacenaba un símbolo recibe otra asignación, cambia de tipo. --- __Las variables de tipo `Symbol` actúan como contenedores en los que no sabemos qué hay (un real, un complejo, una lista...)__. Hay que tener en cuenta que: __una cosa es el nombre de la variable y otra el símbolo con el que se representa__. ```python #creación de símbolos alpha, beta = symbols("alpha beta") alpha, beta ``` ```python c_T = symbols("c_T") c_T ``` Incluso puedo hacer cosas raras como: ```python # Diferencia entre variable y símbolo b = symbols("d") b ``` Además, se pueden crear varos símbolos a la vez: ```python x, y, z, t = symbols("x, y, z, t") x, y, z, t ``` y símbolos griegos: ```python ``` __Por defecto, SymPy entiende que los símbolos son números complejos__. Esto puede producir resultados inesperados ante determinadas operaciones como, por ejemplo, lo logaritmos. __Podemos indicar que la variable es real, entera... en el momento de la creación__: ```python # Creamos símbolos reales x, y, z, t = symbols("x, y, z, t") ``` ```python # restricciones sobre el simbolo x.assumptions0 ``` {'commutative': True} ```python # Podemos ver las asunciones de un símbolo x = symbols("x", real=True, positive=True) ``` ```python x.assumptions0 ``` {'real': True, 'commutative': True, 'imaginary': False, 'finite': True, 'hermitian': True, 'complex': True, 'extended_real': True, 'infinite': False, 'positive': True, 'nonpositive': False, 'negative': False, 'extended_positive': True, 'extended_nonnegative': True, 'nonnegative': True, 'extended_negative': False, 'extended_nonpositive': False, 'extended_nonzero': True, 'nonzero': True, 'zero': False} ## Expresiones Comencemos por crear una expresión como: $\cos(x)^2+\sin(x)^2$ ```python cos(z) ** 2 + sin(z) ** 2 ``` ### `simplify()` Podemos pedirle que simplifique la expresión anterior: ```python simplify(_25) ``` ```python sqrt(z**2) ``` ```python simplify(_27) ``` ```python y = symbols("y", real=True) ``` ```python simplify(sqrt(y**2)) ``` ```python simplify(sqrt(x**2)) ``` En este caso parece estar claro lo que quiere decir más simple, pero como en cualquier _CAS_ el comando `simplify` puede no devolvernos la expresión que nosotros queremos. Cuando esto ocurra necesitaremos usar otras instrucciones. ### `.subs()` En algunas ocasiones necesitaremos sustituir una variable por otra, por otra expresión o por un valor. ```python _25.subs(z, 1+x**2) ``` ```python (sin(x)**2 + cos(y)**2).subs({x: 1+ z, y: 1-z}) ``` ```python ``` ```python ``` Cambia el `sin(x)` por `exp(x)` ```python sin(x).replace(sin, exp) ``` Particulariza la expresión $sin(x) + 3 x $ en $x = \pi$ ```python (sin(x)+3*x).subs(x, pi) ``` __Aunque si lo que queremos es obtener el valor numérico lo mejor es `.evalf()`__ ```python _36.evalf() ``` ```python _36.evalf(n=27) ``` ```python #ver pi con 25 decimales ``` ```python #el mismo resultado se obtiene ocn la función N() N(_36) ``` # Simplificación SymPy ofrece numerosas funciones para __simplificar y manipular expresiones__. Entre otras, destacan: * `expand()` * `factor()` * `collect()` * `apart()` * `cancel()` Puedes consultar en la documentación de SymPy lo que hace cada una y algunos ejemplos. __Existen también funciones específicas de simplificación para funciones trigonométricas, potencias y logaritmos.__ Abre [esta documentación](http://docs.sympy.org/latest/tutorial/simplification.html) si lo necesitas. ##### ¡Te toca! Pasaremos rápidamente por esta parte, para hacer cosas "más interesantes". Te proponemos algunos ejemplos para que te familiarices con el manejor de expresiones: __Crea las expresiones de la izquierda y averigua qué función te hace obtener la de la derecha:__ expresión 1| expresión 2 :------:|:------: $\left(x^{3} + 3 y + 2\right)^{2}$ | $x^{6} + 6 x^{3} y + 4 x^{3} + 9 y^{2} + 12 y + 4$ $\frac{\left(3 x^{2} - 2 x + 1\right)}{\left(x - 1\right)^{2}} $ | $3 + \frac{4}{x - 1} + \frac{2}{\left(x - 1\right)^{2}}$ $x^{3} + 9 x^{2} + 27 x + 27$ | $\left(x + 3\right)^{3}$ $\sin(x+2y)$ | $\left(2 \cos^{2}{\left (y \right )} - 1\right) \sin{\left (x \right )} + 2 \sin{\left (y \right )} \cos{\left (x \right )} \cos{\left (y \right )}$ ```python x, y = symbols("x y") ``` ```python #1 (x**3 + 3*y+2)**2 ``` ```python expand(_43) ``` ```python ``` ```python #2 (3*x**2-2*x+1)/(x-1)**2 ``` ```python apart(_46) ``` ```python ``` ```python #3 ``` ```python (x**3 + 9*x**2 + 27*x + 27).factor() ``` ```python ``` ```python #4 sin(x+2*y) ``` ```python expand(_, trig=True) ``` ```python expand_trig(_50) ``` ```python ``` ```python ``` # Derivadas e integrales Puedes derivar una expresion usando el método `.diff()` y la función `diff()` ```python #creamos una expresión expresion = cos(x) #obtenemos la derivada primera con funcion expresion.diff(x) ``` ```python #utilizando método diff(expresion) ``` __¿derivada tercera?__ ```python expresion.diff(x, x, x) ``` ```python expresion.diff(x, 3) ``` __¿varias variables?__ ```python expr = y * exp(2*x) + x / (x**2 + y**3) expr ``` ```python expr.diff(x, 2, y, 3) ``` __Queremos que la deje indicada__, usamos `Derivative()` ```python Derivative(expr, y) ``` __¿Será capaz SymPy de aplicar la regla de la cadena?__ ```python # Creamos una función F F = Function("F") F(x) ``` ```python # Creamos una función G G = Function("G") G(x) ``` $$\frac{d}{d x} F{\left (G(x) \right )} $$ ```python # Derivamos la función compuesta F(G(x)) F(G(x)).diff(x) ``` En un caso en el que conocemos las funciones: ```python # definimos una f f = 3 * x + cos(y) ``` ```python # definimos una g(f) g = 1 / f g ``` ```python #la derivamos g.diff(x) ``` ##### Te toca integrar __Si te digo que se integra usando el método `.integrate()` o la función `integrate()`__. ¿Te atreves a integrar estas casi inmediatas...?: $$\int{\cos(x)^2}dx$$ $$\int{\frac{dx}{\sin(x)}}$$ $$\int{\frac{dx}{(x^2+a^2)^2}}$$ ```python #integrate? ``` ```python cos(x)**2 ``` ```python integrate(cos(x)**2) ``` ```python integrate(cos(x)**2, (x, 0, 1)) ``` ```python (1/sin(x)).integrate() ``` ```python integrate(1/(x**2+a**2)**2, x) ``` ```python ``` # Límites Calculemos este límite sacado del libro _Cálculo: definiciones, teoremas y resultados_, de Juan de Burgos: $$\lim_{x \to 0} \left(\frac{x}{\tan{\left (x \right )}}\right)^{\frac{1}{x^{2}}}$$ Primero creamos la expresión: ```python expr = (x/tan(x))**(1/x**2) expr ``` Obtenemos el límite con la función `limit()` y si queremos dejarlo indicado, podemos usar `Limit()`: ```python limit(expr, x, 0) ``` ```python oo ``` ```python limit(expr, x, oo) ``` ```python # para dejar indicado Limit(expr, x, 0) ``` # Series Los desarrollos en serie se pueden llevar a cabo con el método `.series()` o la función `series()` ```python #creamos la expresión expr = cos(x) ``` ```python #la desarrollamos en serie expr.series(x) ``` Se puede especificar el número de términos pasándole un argumento `n=...`. El número que le pasemos será el primer término que desprecie. ```python # Indicando el número de términos expr.series(x, n=10) ``` Si nos molesta el $\mathcal{O}(x^{10})$ lo podemos quitar con `removeO()`: ```python _.removeO() ``` ```python expr.series(x, n=10, x0=pi/2) ``` --- ## Resolución de ecuaciones Como se ha mencionado anteriormente las ecuaciones no se pueden crear con el `=` ```python #creamos la ecuación a + x = cos(x) ``` ```python Eq(1+x, x**2) ``` ```python Eq(1+x - x**2, 0) ``` ```python # También la podemos crear como ecuacion = Eq(1+x-sin(x), 0) ecuacion ``` ```python ecuacion2 = Eq(x**2+1, 0) ``` ```python #la resolvemos sol = solve(ecuacion2, x) sol ``` ```python ``` Pero la gracia es resolver con símbolos, ¿no? $$a e^{\frac{x}{t}} = C$$ ```python # Creamos los símbolos y la ecuación C = symbols("C") C ``` ```python # La resolvemos ecuacion = Eq(a*exp(x/t), C) ecuacion ``` ```python solve(ecuacion, x) ``` Si consultamos la ayuda, vemos que las posibilidades y el número de parámetros son muchos, no vamos a entrar ahora en ellos, pero ¿se ve la potencia? ## Ecuaciones diferenciales Tratemos de resolver, por ejemplo: $$y{\left (x \right )} + \frac{d}{d x} y{\left (x \right )} + \frac{d^{2}}{d x^{2}} y{\left (x \right )} = \cos{\left (x \right )}$$ ```python # solo sirve para ejemplos acádemicos sencillos y = Function('y') y ``` y ```python edo = Eq(y(x) + y(x).diff(x) + y(x).diff(x, 2), cos(x)) edo ``` ```python #resolvemos dsolve(edo,y(x)) ``` # Matrices ```python #creamos una matriz llena de símbolos a, b, c, d = symbols('a, b, c, d') a, b, c, d A = Matrix([ [a, b], [c, d] ]) A ``` ```python #sacamos autovalores A.eigenvals() ``` ```python A.eigenvects() ``` ```python #inversa A.inv() ``` ```python #elevamos al cuadrado la matriz A ** 2 ```
section {* Verification condition generator *} theory VCG imports While "$AFP/KAT_and_DRA/SingleSorted/KAT_Models" "$ISABELLE_HOME/src/HOL/Eisbach/Eisbach" begin no_notation comp_op ("n_" [90] 91) and test_operator ("t_" [100] 101) and floor ("\<lfloor>_\<rfloor>") and ceiling ("\<lceil>_\<rceil>") and Set.image (infixr "`" 90) notation inf (infixl "\<sqinter>" 60) (***********************************************************************************************) text {* \emph{hoare} tactic *} named_theorems hl_rules method hoare_init uses simp = ((subst simp | subst fst_conv | subst snd_conv)+)? method hoare_step uses simp hl = (hoare_init simp: simp, (assumption | rule subset_refl | rule mono_rules | rule hl hl_rules | rule allI | rule ballI)) method hoare_ind uses simp hl = (hoare_step simp: simp hl: hl; (hoare_ind simp: simp hl: hl)?)+ method hoare uses simp hl = (hoare_init simp: simp; (hoare_ind simp: simp hl: hl)?) method hl_aux uses rule = (rule allI, rule rule; ((erule_tac x=u in allE)+, assumption)) (***********************************************************************************************) text {* Classic Hoare logic *} definition ht :: "'a set \<Rightarrow> 'a rel \<Rightarrow> 'a set \<Rightarrow> bool" where "ht P x Q \<equiv> \<lfloor>P\<rfloor>;x \<subseteq> x;\<lfloor>Q\<rfloor>" lemma ht_true: "ht P x UNIV" by (auto simp: ht_def seq_def) lemma hl_false [intro]: "ht {} x Q" by (auto simp: ht_def seq_def test_def) lemma hl_abort [hl_rules]: "ht P abort Q" by (auto simp: ht_def abort_def seq_def) lemma hl_skip [hl_rules]: "P \<subseteq> Q \<Longrightarrow> ht P skip Q" by (auto simp: ht_def skip_def seq_def test_def) lemma hl_graph [hl_rules]: "P \<subseteq> {s. f s \<in> Q} \<Longrightarrow> ht P (graph f) Q" by (auto simp: ht_def graph_def seq_def test_def) lemma hl_assign [hl_rules]: "P \<subseteq> subst Q z_upd t \<Longrightarrow> ht P (assign z_upd t) Q" by (auto simp: assign_def subst_def intro!: hl_graph) lemma hl_assign_aux [hl_rules]: "\<forall>z. P z \<subseteq> subst (Q z) z_upd t \<Longrightarrow> \<forall>z. ht (P z) (assign z_upd t) (Q z)" by (auto simp: assign_def subst_def intro!: hl_graph) lemma hl_seq [hl_rules]: "ht R y Q \<Longrightarrow> ht P x R \<Longrightarrow> ht P (x; y) Q" by (force simp: ht_def seq_def) lemma hl_seq_aux [hl_rules]: "\<forall>u. ht (R u) (y u) (Q u) \<Longrightarrow> \<forall>u. ht (P u) (x u) (R u) \<Longrightarrow> \<forall>u. ht (P u) (x u; y u) (Q u)" by (hl_aux rule: hl_seq) lemma hl_split: "ht P x {t. Q t} \<Longrightarrow> ht P x {t. Q' t} \<Longrightarrow> ht P x {t. Q t \<and> Q' t}" by (force simp: ht_def seq_def test_def) lemma hl_split_aux: "\<forall>u. ht (P u) x {t. (Q u) t} \<Longrightarrow> \<forall>u. ht (P u) x {t. Q' u t} \<Longrightarrow> \<forall>u. ht (P u) x {t. Q u t \<and> Q' u t}" by (hl_aux rule: hl_split) lemma hl_cassic_cond : "ht (b \<sqinter> P) x Q \<Longrightarrow> ht (-b \<sqinter> P) y Q \<Longrightarrow> ht P (cond b x y) Q" by (fastforce simp: ht_def cond_def seq_def test_def) lemma hl_cond [hl_rules]: "P \<subseteq> (P' \<union> - b) \<inter> (P'' \<union> b) \<Longrightarrow> ht P' x Q \<Longrightarrow> ht P'' y Q \<Longrightarrow> ht P (cond b x y) Q" by (fastforce simp: ht_def cond_def seq_def) lemma hl_cond_aux [hl_rules]: "\<forall>u. P u \<subseteq> (P' u \<union> - b) \<inter> (P'' u \<union> b) \<Longrightarrow> \<forall>u. ht (P' u) x (Q u) \<Longrightarrow> \<forall>u. ht (P'' u) y (Q u) \<Longrightarrow> \<forall>u. ht (P u) (cond b x y) (Q u)" by (hl_aux rule: hl_cond) lemma hl_while: "ht (b \<sqinter> i) x i \<Longrightarrow> ht i (cwhile b x) (-b \<sqinter> i)" proof (simp add: ht_def cwhile_def seq_def) assume "\<lfloor>b \<sqinter> i\<rfloor> O x \<subseteq> x O \<lfloor>i\<rfloor>" hence "\<lfloor>i\<rfloor> O (\<lfloor>b\<rfloor> O x)\<^sup>* \<subseteq> (\<lfloor>b\<rfloor> O x)\<^sup>* O \<lfloor>i\<rfloor>" by (force intro!: rel_kat.star_sim2) thus "\<lfloor>i\<rfloor> O (\<lfloor>b\<rfloor> O x)\<^sup>* O \<lfloor>-b\<rfloor> \<subseteq> ((\<lfloor>b\<rfloor> O x)\<^sup>* O \<lfloor>-b\<rfloor>) O \<lfloor>-b \<sqinter> i\<rfloor>" by auto qed (***********************************************************************************************) text {* Weakening / Strengthening / Consequence Rules *} lemma hl_pre: "P \<le> P' \<Longrightarrow> ht P' x Q \<Longrightarrow> ht P x Q" by (fastforce simp: ht_def le_fun_def seq_def test_def) lemma hl_post: "Q' \<le> Q \<Longrightarrow> ht P x Q' \<Longrightarrow> ht P x Q" by (fastforce simp: ht_def le_fun_def seq_def test_def) lemma hl_post_aux: "\<forall>u. Q' u \<le> Q u \<Longrightarrow> \<forall>u. ht (P u) x (Q' u) \<Longrightarrow> \<forall>u. ht (P u) x (Q u)" by (fastforce simp: ht_def le_fun_def seq_def test_def) lemma hl_classic: "P \<le> P' \<Longrightarrow> Q' \<le> Q \<Longrightarrow> ht P' x Q' \<Longrightarrow> ht P x Q" by (fastforce simp: ht_def le_fun_def seq_def) lemma hl_conseq: "\<forall>z. ht (P' z) c (Q' z) \<Longrightarrow> \<forall>s. s \<in> P \<longrightarrow> (\<exists>z. s \<in> P' z \<and> (Q' z \<subseteq> Q)) \<Longrightarrow> ht P c Q" by (force simp: ht_def seq_def) lemma hl_kleymann: "\<forall>z. ht (P' z) x (Q' z) \<Longrightarrow> \<forall>s t. (\<forall>z. s \<in> P' z \<longrightarrow> t \<in> Q' z) \<longrightarrow> (\<forall>z. s \<in> P z \<longrightarrow> t \<in> Q z) \<Longrightarrow> ht (P z) x (Q z)" by (fastforce simp: apre_def seq_def ht_def) lemma hl_kleymann_aux: "\<forall>z. ht (P' z) x (Q' z) \<Longrightarrow> \<forall>s t. (\<forall>z. s \<in> P' z \<longrightarrow> t \<in> Q' z) \<longrightarrow> (\<forall>z. s \<in> P z \<longrightarrow> t \<in> Q z) \<Longrightarrow> \<forall>z. ht (P z) x (Q z)" by (hl_aux rule: hl_kleymann) lemma hl_for [hl_rules]: "\<forall>s. m_upd(\<lambda>_. m s) s = s \<Longrightarrow> ht P (assign j_upd n) (subst Q m_upd j \<inter> {s. j s \<le> m s}) \<Longrightarrow> ht ({s. j s < m s} \<inter> subst Q m_upd j) x (subst (subst Q m_upd j \<inter> {s. j s \<le> m s}) j_upd (\<lambda>s. j s + 1)) \<Longrightarrow> ht P (cfor (j_upd, j) n (m_upd, m) x) Q" apply (rule hl_post [where Q'="(-{s. j s < m s} \<inter> (subst Q m_upd j \<inter> {s. j s \<le> m s}))"]) apply (subgoal_tac "-{s. j s < m s} \<inter> (subst Q m_upd j \<inter> {s. j s \<le> m s}) = {s. j s = m s} \<inter> subst Q m_upd j") apply (force simp: subst_def) apply force apply (hoare simp: cfor_def hl: hl_while) apply (subgoal_tac "{s. j s < m s} \<inter> (subst Q m_upd j \<inter> {s. j s \<le> m s}) = {s. j s < m s} \<inter> subst Q m_upd j") apply force+ done (***********************************************************************************************) text {* Blocks / Procedures / Recursive Calls *} lemma hl_dyn [hl_rules]: "\<forall>s \<in> P. ht P (g s) Q \<Longrightarrow> ht P (\<lceil>g\<rceil>) Q" by (fastforce simp: ht_def seq_def dyn_def) lemma hl_local_inv: "\<forall>s s'. z (z_upd (\<lambda>_. z s) s') = z s \<Longrightarrow> P \<le> {s. z s = u} \<Longrightarrow> ht P (loc_block (z_upd, z) t x) {s. z s = u}" by (auto simp: block_def loc_block_def graph_def dyn_def seq_def ht_def) lemma hl_block: "\<forall>s. ht P x {t. f s t \<in> Q} \<Longrightarrow> ht P (block x f) Q" by (hoare simp: block_def hl: ballI) force lemma hl_loc_block: "\<forall>s. ht P (\<langle>\<lambda>s. z_upd (\<lambda>_. t s) s\<rangle>; x) {t. z_upd s t \<in> Q} \<Longrightarrow> ht P (loc_block (z_upd, z) t x) Q" by (auto simp: loc_block_def intro: hl_block) lemma hl_fun_block_inv: "\<forall>s s'. y (y_upd (\<lambda>_. y s) s') = y s \<Longrightarrow> P \<le> {s. y s = u} \<Longrightarrow> ht P (fun_call z_upd (R, (y_upd, y))) {s. y s = u }" by (auto simp: block_def loc_block_def graph_def dyn_def seq_def ht_def fun_call_def) lemma hl_fun_block: "\<forall>s. ht P R {t. y_upd (\<lambda>_. y s) (z_upd (\<lambda>_. y t) t) \<in> Q} \<Longrightarrow> ht P (fun_call z_upd (R, (y_upd, y))) Q" by (auto simp: fun_call_def intro: hl_block) lemma hl_Sup: "\<forall>x \<in> X. \<forall>z. ht (P z) (x z) (Q z) \<Longrightarrow> \<forall>z. ht (P z) (Sup X z) (Q z)" by (fastforce simp: ht_def seq_def) lemma hl_rec_dep: "mono f \<Longrightarrow> (\<And>x. \<forall>z. ht (P z) (x z) (Q z) \<Longrightarrow> \<forall>z. ht (P z) (f x z) (Q z)) \<Longrightarrow> \<forall>z. ht (P z) (lfp f z) (Q z)" apply (erule lfp_ordinal_induct [where f=f], assumption) by (force intro!: hl_Sup) lemma hl_rec_aux [hl_rules]: "mono f \<Longrightarrow> (\<And>x. \<forall>z. ht (P z) x (Q z) \<Longrightarrow> \<forall>z. ht (P z) (f x) (Q z)) \<Longrightarrow> \<forall>z. ht (P z) (lfp f) (Q z)" apply (erule lfp_ordinal_induct [where f=f], simp) by (fastforce simp: ht_def seq_def) lemma hl_rec [hl_rules]: "mono f \<Longrightarrow> (\<And>x. \<forall>z. ht (P z) x (Q z) \<Longrightarrow> \<forall>z. ht (P z) (f x) (Q z)) \<Longrightarrow> ht (P z) (lfp f) (Q z)" apply (drule hl_rec_aux) prefer 2 apply (erule_tac x=z in allE) apply assumption apply simp done (***********************************************************************************************) text {* Annotated programs *} lemma hl_awhile [hl_rules]: "P \<subseteq> i \<Longrightarrow> -b \<inter> i \<subseteq> Q \<Longrightarrow> ht (b \<sqinter> i) x i \<Longrightarrow> ht P (awhile i b x) Q" apply (rule hl_conseq) by (hoare simp: awhile_def hl: allI hl_while) force lemma hl_apre_classic: "P \<le> P' \<Longrightarrow> ht P' x Q \<Longrightarrow> ht P (apre P' x) Q" apply (rule hl_pre, assumption) by (hoare simp: apre_def) lemma hl_apre_kleymann [hl_rules]: "ht P' x Q' \<Longrightarrow> \<forall>s t. (s \<in> P' \<longrightarrow> t \<in> Q') \<longrightarrow> (s \<in> P \<longrightarrow> t \<in> Q) \<Longrightarrow> ht P (apre P x) Q" by (force simp add: apre_def seq_def ht_def) lemma hl_apre_kleymann_aux [hl_rules]: "\<forall>z. ht (P' z) x (Q' z) \<Longrightarrow> \<forall>s t. (\<forall>z. s \<in> P' z \<longrightarrow> t \<in> Q' z) \<longrightarrow> (\<forall>z. s \<in> P z \<longrightarrow> t \<in> Q z) \<Longrightarrow> \<forall>z. ht (P z) (apre_aux P x) (Q z)" by (force simp add: apre_aux_def seq_def ht_def) lemma hl_apost_classic [hl_rules]: "Q' \<le> Q \<Longrightarrow> ht P x Q' \<Longrightarrow> ht P (apost x Q') Q" by (hoare simp: apost_def hl: hl_apre_kleymann) force lemma hl_aprog_classic : "P \<le> P' \<Longrightarrow> Q' \<le> Q \<Longrightarrow> ht P' x Q' \<Longrightarrow> ht P (aprog P' x Q') Q" apply (rule hl_classic, assumption+) by (hoare simp: aprog_def) lemma hl_aprog_kleymann_aux [hl_rules]: "\<forall>z. ht (P' z) x (Q' z) \<Longrightarrow> \<forall>s t. (\<forall>z. s \<in> P' z \<longrightarrow> t \<in> Q' z) \<longrightarrow> (\<forall>z. s \<in> P z \<longrightarrow> t \<in> Q z) \<Longrightarrow> \<forall>z. Q z \<le> Q'' z \<Longrightarrow> \<forall>z. ht (P z) (aprog_aux P x Q) (Q'' z)" apply (simp add: aprog_aux_def) apply (rule hl_post_aux) apply assumption by (force simp add: aprog_aux_def seq_def ht_def) (***********************************************************************************************) text {* When using hoare, rules should be applied in the following order *} declare hl_local_inv [hl_rules] hl_loc_block [hl_rules] hl_fun_block_inv [hl_rules] hl_fun_block [hl_rules] hl_block [hl_rules] declare subst_def [simp] method hoare_split uses simp hl = (hoare_init simp: simp; (rule hl_split)+; (hoare_ind simp: simp hl: hl)?) end