Datasets:
AI4M
/

text
stringlengths
0
3.34M
# Homework 5 ## Due Date: Tuesday, October 3rd at 11:59 PM # Problem 1 We discussed documentation and testing in lecture and also briefly touched on code coverage. You must write tests for your code for your final project (and in life). There is a nice way to automate the testing process called continuous integration (CI). This problem will walk you through the basics of CI and show you how to get up and running with some CI software. ### Continuous Integration The idea behind continuous integration is to automate away the testing of your code. We will be using it for our projects. The basic workflow goes something like this: 1. You work on your part of the code in your own branch or fork 2. On every commit you make and push to GitHub, your code is automatically tested on a fresh machine on Travis CI. This ensures that there are no specific dependencies on the structure of your machine that your code needs to run and also ensures that your changes are sane 3. Now you submit a pull request to `master` in the main repo (the one you're hoping to contribute to). The repo manager creates a branch off `master`. 4. This branch is also set to run tests on Travis. If all tests pass, then the pull request is accepted and your code becomes part of master. We use GitHub to integrate our roots library with Travis CI and Coveralls. Note that this is not the only workflow people use. Google git..github..workflow and feel free to choose another one for your group. ### Part 1: Create a repo Create a public GitHub repo called `cs207test` and clone it to your local machine. **Note:** No need to do this in Jupyter. ### Part 2: Create a roots library Use the example from lecture 7 to create a file called `roots.py`, which contains the `quad_roots` and `linear_roots` functions (along with their documentation). Also create a file called `test_roots.py`, which contains the tests from lecture. All of these files should be in your newly created `cs207test` repo. **Don't push yet!!!** ```bash %%bash cd ../../../cs207test file roots.py def linear_roots(a=1.0, b=0.0): if a == 0: raise ValueError("The linear coefficient is zero. This is not a linear equation.") else: return ((-b / a)) def quad_roots(a=1.0, b=2.0, c=0.0): import cmath # Can return complex numbers from square roots if a == 0: raise ValueError("The quadratic coefficient is zero. This is not a quadratic equation.") else: sqrtdisc = cmath.sqrt(b * b - 4.0 * a * c) r1 = -b + sqrtdisc r2 = -b - sqrtdisc return (r1 / 2.0 / a, r2 / 2.0 / a) ``` roots.py: ASCII English text bash: line 4: syntax error near unexpected token `(' bash: line 4: `def linear_roots(a=1.0, b=0.0):' ```python ``` ### Part 3: Create an account on Travis CI and Start Building #### Part A: Create an account on Travis CI and set your `cs207test` repo up for continuous integration once this repo can be seen on Travis. #### Part B: Create an instruction to Travis to make sure that 1. python is installed 2. its python 3.5 3. pytest is installed The file should be called `.travis.yml` and should have the contents: ```yml language: python python: - "3.5" before_install: - pip install pytest pytest-cov script: - pytest ``` You should also create a configuration file called `setup.cfg`: ```cfg [tool:pytest] addopts = --doctest-modules --cov-report term-missing --cov roots ``` #### Part C: Push the new changes to your `cs207test` repo. At this point you should be able to see your build on Travis and if and how your tests pass. ### Part 4: Coveralls Integration In class, we also discussed code coverage. Just like Travis CI runs tests automatically for you, Coveralls automatically checks your code coverage. One minor drawback of Coveralls is that it can only work with public GitHub accounts. However, this isn't too big of a problem since your projects will be public. #### Part A: Create an account on [`Coveralls`](https://coveralls.zendesk.com/hc/en-us), connect your GitHub, and turn Coveralls integration on. #### Part B: Update your the `.travis.yml` file as follows: ```yml language: python python: - "3.5" before_install: - pip install pytest pytest-cov - pip install coveralls script: - py.test after_success: - coveralls ``` Be sure to push the latest changes to your new repo. ### Part 5: Update README.md in repo You can have your GitHub repo reflect the build status on Travis CI and the code coverage status from Coveralls. To do this, you should modify the `README.md` file in your repo to include some badges. Put the following at the top of your `README.md` file: ``` [](https://travis-ci.org/dsondak/cs207testing.svg?branch=master) [](https://coveralls.io/github/dsondak/cs207testing?branch=master) ``` Of course, you need to make sure that the links are to your repo and not mine. You can find embed code on the Coveralls and Travis CI sites. --- # Problem 2 Write a Python module for reaction rate coefficients. Your module should include functions for constant reaction rate coefficients, Arrhenius reaction rate coefficients, and modified Arrhenius reaction rate coefficients. Here are their mathematical forms: \begin{align} &k_{\textrm{const}} = k \tag{constant} \\ &k_{\textrm{arr}} = A \exp\left(-\frac{E}{RT}\right) \tag{Arrhenius} \\ &k_{\textrm{mod arr}} = A T^{b} \exp\left(-\frac{E}{RT}\right) \tag{Modified Arrhenius} \end{align} Test your functions with the following paramters: $A = 10^7$, $b=0.5$, $E=10^3$. Use $T=10^2$. A few additional comments / suggestions: * The Arrhenius prefactor $A$ is strictly positive * The modified Arrhenius parameter $b$ must be real * $R = 8.314$ is the ideal gas constant. It should never be changed (except to convert units) * The temperature $T$ must be positive (assuming a Kelvin scale) * You may assume that units are consistent * Document each function! * You might want to check for overflows and underflows **Recall:** A Python module is a `.py` file which is not part of the main execution script. The module contains several functions which may be related to each other (like in this problem). Your module will be importable via the execution script. For example, suppose you have called your module `reaction_coeffs.py` and your execution script `kinetics.py`. Inside of `kinetics.py` you will write something like: ```python import reaction_coeffs # Some code to do some things # : # : # : # Time to use a reaction rate coefficient: reaction_coeffs.const() # Need appropriate arguments, etc # Continue on... # : # : # : ``` Be sure to include your module in the same directory as your execution script. --- # Problem 3 Write a function that returns the **progress rate** for a reaction of the following form: \begin{align} \nu_{A} A + \nu_{B} B \longrightarrow \nu_{C} C. \end{align} Order your concentration vector so that \begin{align} \mathbf{x} = \begin{bmatrix} \left[A\right] \\ \left[B\right] \\ \left[C\right] \end{bmatrix} \end{align} Test your function with \begin{align} \nu_{i}^{\prime} = \begin{bmatrix} 2.0 \\ 1.0 \\ 0.0 \end{bmatrix} \qquad \mathbf{x} = \begin{bmatrix} 1.0 \\ 2.0 \\ 3.0 \end{bmatrix} \qquad k = 10. \end{align} You must document your function and write some tests in addition to the one suggested. You choose the additional tests, but you must have at least one doctest in addition to a suite of unit tests. --- # Problem 4 Write a function that returns the **progress rate** for a system of reactions of the following form: \begin{align} \nu_{11}^{\prime} A + \nu_{21}^{\prime} B \longrightarrow \nu_{31}^{\prime\prime} C \\ \nu_{12}^{\prime} A + \nu_{32}^{\prime} C \longrightarrow \nu_{22}^{\prime\prime} B + \nu_{32}^{\prime\prime} C \end{align} Note that $\nu_{ij}^{\prime}$ represents the stoichiometric coefficient of reactant $i$ in reaction $j$ and $\nu_{ij}^{\prime\prime}$ represents the stoichiometric coefficient of product $i$ in reaction $j$. Therefore, in this convention, I have ordered my vector of concentrations as \begin{align} \mathbf{x} = \begin{bmatrix} \left[A\right] \\ \left[B\right] \\ \left[C\right] \end{bmatrix}. \end{align} Test your function with \begin{align} \nu_{ij}^{\prime} = \begin{bmatrix} 1.0 & 2.0 \\ 2.0 & 0.0 \\ 0.0 & 2.0 \end{bmatrix} \qquad \nu_{ij}^{\prime\prime} = \begin{bmatrix} 0.0 & 0.0 \\ 0.0 & 1.0 \\ 2.0 & 1.0 \end{bmatrix} \qquad \mathbf{x} = \begin{bmatrix} 1.0 \\ 2.0 \\ 1.0 \end{bmatrix} \qquad k_{j} = 10, \quad j=1,2. \end{align} You must document your function and write some tests in addition to the one suggested. You choose the additional tests, but you must have at least one doctest in addition to a suite of unit tests. --- # Problem 5 Write a function that returns the **reaction rate** of a system of irreversible reactions of the form: \begin{align} \nu_{11}^{\prime} A + \nu_{21}^{\prime} B &\longrightarrow \nu_{31}^{\prime\prime} C \\ \nu_{32}^{\prime} C &\longrightarrow \nu_{12}^{\prime\prime} A + \nu_{22}^{\prime\prime} B \end{align} Once again $\nu_{ij}^{\prime}$ represents the stoichiometric coefficient of reactant $i$ in reaction $j$ and $\nu_{ij}^{\prime\prime}$ represents the stoichiometric coefficient of product $i$ in reaction $j$. In this convention, I have ordered my vector of concentrations as \begin{align} \mathbf{x} = \begin{bmatrix} \left[A\right] \\ \left[B\right] \\ \left[C\right] \end{bmatrix} \end{align} Test your function with \begin{align} \nu_{ij}^{\prime} = \begin{bmatrix} 1.0 & 0.0 \\ 2.0 & 0.0 \\ 0.0 & 2.0 \end{bmatrix} \qquad \nu_{ij}^{\prime\prime} = \begin{bmatrix} 0.0 & 1.0 \\ 0.0 & 2.0 \\ 1.0 & 0.0 \end{bmatrix} \qquad \mathbf{x} = \begin{bmatrix} 1.0 \\ 2.0 \\ 1.0 \end{bmatrix} \qquad k_{j} = 10, \quad j = 1,2. \end{align} You must document your function and write some tests in addition to the one suggested. You choose the additional tests, but you must have at least one doctest in addition to a suite of unit tests. ```python %%file reaction_coeffs.py from math import exp def k_constant(k): return k def k_arr(a,e,t): r=8.314 if a<= 0: raise ValueError("a<0!") if t<= 0: raise ValueError("t<0!") return (a*exp(-e/(r*t))) def k_mod_arr(a,e,t,b): r=8.314 if a<= 0: raise ValueError("a<0!") if t<= 0: raise ValueError("t<0!") return (a*(t**b)*exp(-e/(r*t))) ``` Writing reaction_coeffs.py ```python %%file reaction1_rate.py import numpy as np import copy def reaction_rate1(x,v,vv,k): """Returns reaction rate of chemical reactoins INPUTS ======= x: array of float concentration of molecule species v: array of integers Coefficient of molecule species on the left side of equation vv: array of integers Coefficient of melecule species on the right side of equation kk: array of float reaction rate coefficient RETURNS ======== roots: array of floats EXAMPLES ========= >>> reaction_rate1(np.array([[1.0],[2.0],[1]]),np.array([[1,0],[2,0],[0,2]]),np.array([[0,1],[0,2],[1,0]]),[10,10]) array([[-40.], [ 10.], [-80.], [ 20.], [ 40.], [-20.]]) """ if (any([kk<0 for kk in k])): raise ValueError("k<0") flag=True for j in range(v.shape[1]): if all([v[i][j]<=0 for i in range(v.shape[0])]): flag=False break if (flag==False): raise ValueError("no reactants") flag=True for j in range(vv.shape[1]): if all([vv[i][j]<=0 for i in range(vv.shape[0])]): flag=False break if (flag==False): raise ValueError("no products") if x.shape[0]!=v.shape[0] or v.shape!=vv.shape or v.shape[1]!=len(k): raise ValueError("dimensions not match") tmp=np.array([x[i][0]**v[i][j] for i in range(v.shape[0]) for j in range(v.shape[1])]).reshape(v.shape) w=copy.copy(k) for i in range(len(x)): for j in range(v.shape[1]): a=tmp[i][j] w[j]*=a return (np.transpose([np.array([w[j]*(vv[i][j]-v[i][j]) for i in range(len(x)) for j in range(v.shape[1])])])) ``` Writing reaction1_rate.py ```python %%file reaction1_test.py import reaction1_rate as rr1 import numpy as np def test_normal1(): x=np.array([[1.0],[2.0],[1]]) v_i_prime=np.array([[1,0],[2,0],[0,2]]) v_i_prime_prime=np.array([[0,1],[0,2],[1,0]]) k=[10,10] assert all(rr1.reaction_rate1(x,v_i_prime,v_i_prime_prime,k)==[[-40],[10],[-80],[20],[40],[-20]]) def test_nagative_k1(): try: x=np.array([[1.0],[2.0],[1]]) v_i_prime=np.array([[1,2],[2,0],[0,2]]) v_i_prime_prime=np.array([[0,0],[0,1],[2,1]]) k=[-10,10] rr1.reaction_rate1(x,v_i_prime,v_i_prime_prime,k) except ValueError as err: assert(True) def test_reactants1(): try: x=np.array([[1.0],[2.0],[1]]) v_i_prime=np.array([[0,2],[0,0],[0,2]]) v_i_prime_prime=np.array([[0,0],[0,1],[2,1]]) k=[10,10] rr1.reaction_rate1(x,v_i_prime,v_i_prime_prime,k) except ValueError as err: assert(True) def test_products1(): try: x=np.array([[1.0],[2.0],[1]]) v_i_prime=np.array([[1,2],[2,0],[0,2]]) v_i_prime_prime=np.array([[0,0],[0,0],[2,0]]) k=[10,10] rr1.reaction_rate1(x,v_i_prime,v_i_prime_prime,k) except ValueError as err: assert(True) def test_dimensions1(): try: x=np.array([[1.0],[2.0]]) v_i_prime=np.array([[1,2],[2,0],[0,2]]) v_i_prime_prime=np.array([[0,0],[0,0],[2,0]]) k=[10,10] rr1.reaction_rate1(x,v_i_prime,v_i_prime_prime,k) except ValueError as err: assert(True) ``` Writing reaction1_test.py ```python import doctest doctest.testmod(verbose=True) ``` 1 items had no tests: __main__ 0 tests in 1 items. 0 passed and 0 failed. Test passed. TestResults(failed=0, attempted=0) ```python !pytest ``` ============================= test session starts ============================== platform darwin -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 rootdir: /Users/zhaiyi/cs207_yi_zhai/homeworks/HW5, inifile: plugins: cov-2.5.1 collected 5 items   reaction1_test.py ..... =========================== 5 passed in 0.26 seconds =========================== ```bash %%bash pwd ``` /Users/zhaiyi/cs207_yi_zhai/homeworks/HW5 ```python !pytest --cov ``` ============================= test session starts ============================== platform darwin -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 rootdir: /Users/zhaiyi/cs207_yi_zhai/homeworks/HW5, inifile: plugins: cov-2.5.1 collected 5 items   reaction1_test.py ..... ---------- coverage: platform darwin, python 3.6.1-final-0 ----------- Name Stmts Miss Cover --------------------------------------- reaction1_rate.py 28 1 96% reaction1_test.py 44 0 100% --------------------------------------- TOTAL 72 1 99% =========================== 5 passed in 0.27 seconds =========================== --- # Problem 6 Put parts 3, 4, and 5 in a module called `chemkin`. Next, pretend you're a client who needs to compute the reaction rates at three different temperatures ($T = \left\{750, 1500, 2500\right\}$) of the following system of irreversible reactions: \begin{align} 2H_{2} + O_{2} \longrightarrow 2OH + H_{2} \\ OH + HO_{2} \longrightarrow H_{2}O + O_{2} \\ H_{2}O + O_{2} \longrightarrow HO_{2} + OH \end{align} The client also happens to know that reaction 1 is a modified Arrhenius reaction with $A_{1} = 10^{8}$, $b_{1} = 0.5$, $E_{1} = 5\times 10^{4}$, reaction 2 has a constant reaction rate parameter $k = 10^{4}$, and reaction 3 is an Arrhenius reaction with $A_{3} = 10^{7}$ and $E_{3} = 10^{4}$. You should write a script that imports your `chemkin` module and returns the reaction rates of the species at each temperature of interest given the following species concentrations: \begin{align} \mathbf{x} = \begin{bmatrix} H_{2} \\ O_{2} \\ OH \\ HO_{2} \\ H_{2}O \end{bmatrix} = \begin{bmatrix} 2.0 \\ 1.0 \\ 0.5 \\ 1.0 \\ 1.0 \end{bmatrix} \end{align} You may assume that these are elementary reactions. ```python ``` --- # Problem 7 Get together with your project team, form a GitHub organization (with a descriptive team name), and give the teaching staff access. You can have has many repositories as you like within your organization. However, we will grade the repository called **`cs207-FinalProject`**. Within the `cs207-FinalProject` repo, you must set up Travis CI and Coveralls. Make sure your `README.md` file includes badges indicating how many tests are passing and the coverage of your code.
import phase2.weak_approx open cardinal quiver set sum with_bot open_locale cardinal classical pointwise universe u namespace con_nf variables [params.{u}] /-! # Filling in ranges of weak near-litter approximations TODO: Rename the gadgetry created in this file. -/ namespace weak_near_litter_approx variables (w : weak_near_litter_approx) noncomputable def preimage_litter : litter := w.not_banned_litter_nonempty.some lemma preimage_litter_not_banned : ¬w.banned_litter w.preimage_litter := w.not_banned_litter_nonempty.some.prop /-- An atom is called *without preimage* if it is not in the range of the approximation, but it is in a litter near some near-litter in the range. Atoms without preimage need to have something map to it, so that the resulting map that we use in the freedom of action theorem actually maps to the correct near-litter. -/ @[mk_iff] structure without_preimage (a : atom) : Prop := (mem_map : ∃ (L : litter) (hL : (w.litter_map L).dom), a ∈ litter_set ((w.litter_map L).get hL).1) (not_mem_map : ∀ (L : litter) (hL : (w.litter_map L).dom), a ∉ (w.litter_map L).get hL) (not_mem_ran : a ∉ w.atom_map.ran) lemma without_preimage_small : small {a | w.without_preimage a} := begin simp only [without_preimage_iff, set_of_and], rw ← inter_assoc, refine small.mono (inter_subset_left _ _) _, suffices : small ⋃ (L : litter) (hL), litter_set ((w.litter_map L).get hL).1 \ (w.litter_map L).get hL, { refine small.mono _ this, rintro a ⟨⟨L, hL, ha₁⟩, ha₂⟩, simp only [mem_Union], exact ⟨L, hL, ha₁, ha₂ _ _⟩, }, refine small.bUnion _ _, { refine lt_of_le_of_lt _ w.litter_map_dom_small, refine ⟨⟨λ L, ⟨_, L.prop⟩, _⟩⟩, intros L₁ L₂ h, simp only [subtype.mk_eq_mk, prod.mk.inj_iff, eq_self_iff_true, and_true, litter.to_near_litter_injective.eq_iff, subtype.coe_inj] at h, exact h, }, { intros L hL, refine small.mono _ ((w.litter_map L).get hL).2.prop, exact λ x hx, or.inl hx, }, end /-- The subset of the preimage litter that is put in correspondence with the set of atoms without preimage. -/ def preimage_litter_subset : set atom := (le_mk_iff_exists_subset.mp (lt_of_lt_of_eq w.without_preimage_small (mk_litter_set w.preimage_litter).symm).le).some lemma preimage_litter_subset_spec : w.preimage_litter_subset ⊆ litter_set w.preimage_litter ∧ #w.preimage_litter_subset = #{a : atom | w.without_preimage a} := (le_mk_iff_exists_subset.mp (lt_of_lt_of_eq w.without_preimage_small (mk_litter_set w.preimage_litter).symm).le).some_spec lemma preimage_litter_subset_subset : w.preimage_litter_subset ⊆ litter_set w.preimage_litter := w.preimage_litter_subset_spec.1 lemma preimage_litter_subset_small : small (w.preimage_litter_subset) := lt_of_eq_of_lt w.preimage_litter_subset_spec.2 w.without_preimage_small @[irreducible] noncomputable def preimage_litter_equiv : w.preimage_litter_subset ≃ {a : atom | w.without_preimage a} := (cardinal.eq.mp w.preimage_litter_subset_spec.2).some /-- The images of atoms in a litter `L` that were mapped outside the target litter, but were not in the domain. -/ @[mk_iff] structure mapped_outside (L : litter) (hL : (w.litter_map L).dom) (a : atom) : Prop := (mem_map : a ∈ (w.litter_map L).get hL) (not_mem_map : a ∉ litter_set ((w.litter_map L).get hL).1) (not_mem_ran : a ∉ w.atom_map.ran) /-- There are only `< κ`-many atoms in a litter `L` that are mapped outside the image litter, and that are not already in the domain. -/ lemma mapped_outside_small (L : litter) (hL : (w.litter_map L).dom) : small {a | w.mapped_outside L hL a} := begin simp only [mapped_outside_iff, set_of_and], rw ← inter_assoc, refine small.mono (inter_subset_left _ _) _, refine small.mono _ ((w.litter_map L).get hL).2.prop, exact λ x hx, or.inr hx, end lemma without_preimage.not_mapped_outside {a : atom} (ha : w.without_preimage a) (L : litter) (hL : (w.litter_map L).dom) : ¬w.mapped_outside L hL a := λ ha', ha.not_mem_map L hL ha'.mem_map lemma mapped_outside.not_without_preimage {a : atom} {L : litter} {hL : (w.litter_map L).dom} (ha : w.mapped_outside L hL a) : ¬w.without_preimage a := λ ha', ha'.not_mem_map L hL ha.mem_map /-- The amount of atoms in a litter that are not in the domain already is `κ`. -/ lemma mk_mapped_outside_domain (L : litter) : #(litter_set L \ w.atom_map.dom : set atom) = #κ := begin refine le_antisymm _ _, { rw ← mk_litter_set, exact mk_subtype_mono (λ x hx, hx.1), }, by_contra' h, have := small.union h w.atom_map_dom_small, rw diff_union_self at this, exact (mk_litter_set L).not_lt (small.mono (subset_union_left _ _) this), end /-- To each litter we associate a subset which is to contain the atoms mapped outside it. -/ def mapped_outside_subset (L : litter) (hL : (w.litter_map L).dom) : set atom := (le_mk_iff_exists_subset.mp (lt_of_lt_of_eq (w.mapped_outside_small L hL) (w.mk_mapped_outside_domain L).symm).le).some lemma mapped_outside_subset_spec (L : litter) (hL : (w.litter_map L).dom) : w.mapped_outside_subset L hL ⊆ litter_set L \ w.atom_map.dom ∧ #(w.mapped_outside_subset L hL) = #{a : atom | w.mapped_outside L hL a} := (le_mk_iff_exists_subset.mp (lt_of_lt_of_eq (w.mapped_outside_small L hL) (w.mk_mapped_outside_domain L).symm).le).some_spec lemma mapped_outside_subset_subset (L : litter) (hL : (w.litter_map L).dom) : w.mapped_outside_subset L hL ⊆ litter_set L := λ x hx, ((w.mapped_outside_subset_spec L hL).1 hx).1 lemma mapped_outside_subset_closure (L : litter) (hL : (w.litter_map L).dom) : w.mapped_outside_subset L hL ⊆ w.atom_map.domᶜ := λ x hx, ((w.mapped_outside_subset_spec L hL).1 hx).2 lemma mapped_outside_subset_small (L : litter) (hL : (w.litter_map L).dom) : small (w.mapped_outside_subset L hL) := lt_of_eq_of_lt (w.mapped_outside_subset_spec L hL).2 (w.mapped_outside_small L hL) /-- A correspondence between the "mapped outside" subset of `L` and its atoms which were mapped outside the target litter. We will use this equivalence to construct an approximation to use in the freedom of action theorem. -/ @[irreducible] noncomputable def mapped_outside_equiv (L : litter) (hL : (w.litter_map L).dom) : w.mapped_outside_subset L hL ≃ {a : atom | w.mapped_outside L hL a} := (cardinal.eq.mp (w.mapped_outside_subset_spec L hL).2).some noncomputable def supported_action_atom_map_core : atom →. atom := λ a, { dom := (w.atom_map a).dom ∨ a ∈ w.preimage_litter_subset ∨ ∃ L hL, a ∈ w.mapped_outside_subset L hL, get := λ h, h.elim' (w.atom_map a).get (λ h, h.elim' (λ h, w.preimage_litter_equiv ⟨a, h⟩) (λ h, w.mapped_outside_equiv h.some h.some_spec.some ⟨a, h.some_spec.some_spec⟩)), } lemma mem_supported_action_atom_map_core_dom_iff (a : atom) : (w.supported_action_atom_map_core a).dom ↔ a ∈ w.atom_map.dom ∪ w.preimage_litter_subset ∪ ⋃ L hL, w.mapped_outside_subset L hL := begin rw supported_action_atom_map_core, simp only [pfun.dom_mk, mem_set_of_eq, mem_union, mem_Union], rw or_assoc, refl, end lemma supported_action_atom_map_core_dom_eq : w.supported_action_atom_map_core.dom = w.atom_map.dom ∪ w.preimage_litter_subset ∪ ⋃ L hL, w.mapped_outside_subset L hL := begin ext a : 1, exact w.mem_supported_action_atom_map_core_dom_iff a, end lemma supported_action_atom_map_core_dom_small : small w.supported_action_atom_map_core.dom := begin rw supported_action_atom_map_core_dom_eq, refine small.union (small.union w.atom_map_dom_small _) _, { exact w.preimage_litter_subset_small, }, { refine small.bUnion _ _, { refine lt_of_le_of_lt _ w.litter_map_dom_small, refine ⟨⟨λ L, ⟨_, L.prop⟩, λ L₁ L₂ h, _⟩⟩, simp only [subtype.mk_eq_mk, prod.mk.inj_iff, eq_self_iff_true, and_true, litter.to_near_litter_injective.eq_iff, subtype.coe_inj] at h, exact h, }, { intros L hL, exact w.mapped_outside_subset_small L hL, }, }, end lemma mk_supported_action_atom_map_dom : #(w.supported_action_atom_map_core.dom ∆ ((λ a, part.get_or_else (w.supported_action_atom_map_core a) (arbitrary atom)) '' w.supported_action_atom_map_core.dom) : set atom) ≤ #(litter_set $ w.preimage_litter) := begin rw mk_litter_set, refine le_trans (mk_subtype_mono symm_diff_subset_union) (le_trans (mk_union_le _ _) _), refine add_le_of_le κ_regular.aleph_0_le _ _, exact le_of_lt w.supported_action_atom_map_core_dom_small, exact le_trans mk_image_le (le_of_lt w.supported_action_atom_map_core_dom_small), end lemma supported_action_eq_of_dom {a : atom} (ha : (w.atom_map a).dom) : (w.supported_action_atom_map_core a).get (or.inl ha) = (w.atom_map a).get ha := begin simp only [supported_action_atom_map_core], rw or.elim'_left, end lemma supported_action_eq_of_mem_preimage_litter_subset {a : atom} (ha : a ∈ w.preimage_litter_subset) : (w.supported_action_atom_map_core a).get (or.inr (or.inl ha)) = w.preimage_litter_equiv ⟨a, ha⟩ := begin simp only [supported_action_atom_map_core], rw [or.elim'_right, or.elim'_left], intro h', have := w.preimage_litter_not_banned, rw banned_litter_iff at this, push_neg at this, exact this.1 a h' (w.preimage_litter_subset_subset ha).symm, end lemma supported_action_eq_of_mem_mapped_outside_subset {a : atom} {L hL} (ha : a ∈ w.mapped_outside_subset L hL) : (w.supported_action_atom_map_core a).get (or.inr (or.inr ⟨L, hL, ha⟩)) = w.mapped_outside_equiv L hL ⟨a, ha⟩ := begin have : ∃ L hL, a ∈ w.mapped_outside_subset L hL := ⟨L, hL, ha⟩, simp only [supported_action_atom_map_core], rw [or.elim'_right, or.elim'_right], { cases eq_of_mem_litter_set_of_mem_litter_set (w.mapped_outside_subset_subset _ hL ha) (w.mapped_outside_subset_subset _ this.some_spec.some this.some_spec.some_spec), refl, }, { intro h, have := eq_of_mem_litter_set_of_mem_litter_set (w.mapped_outside_subset_subset _ hL ha) (w.preimage_litter_subset_subset h), cases this, have := w.preimage_litter_not_banned, rw banned_litter_iff at this, push_neg at this, cases this.2.1 hL, }, { exact ((mapped_outside_subset_spec _ _ hL).1 ha).2, }, end lemma supported_action_atom_map_core_injective ⦃a b : atom⦄ (ha : (supported_action_atom_map_core w a).dom) (hb : (supported_action_atom_map_core w b).dom) (hab : (w.supported_action_atom_map_core a).get ha = (w.supported_action_atom_map_core b).get hb) : a = b := begin obtain (ha | ha | ⟨L, hL, ha⟩) := ha; obtain (hb | hb | ⟨L', hL', hb⟩) := hb, { have := (supported_action_eq_of_dom _ ha).symm.trans (hab.trans (supported_action_eq_of_dom _ hb)), exact w.atom_map_injective ha hb this, }, { have := (supported_action_eq_of_dom _ ha).symm.trans (hab.trans (supported_action_eq_of_mem_preimage_litter_subset _ hb)), obtain ⟨hab, -⟩ := subtype.coe_eq_iff.mp this.symm, cases hab.not_mem_ran ⟨a, ha, rfl⟩, }, { have := (supported_action_eq_of_dom _ ha).symm.trans (hab.trans (supported_action_eq_of_mem_mapped_outside_subset _ hb)), obtain ⟨hab, -⟩ := subtype.coe_eq_iff.mp this.symm, cases hab.not_mem_ran ⟨a, ha, rfl⟩, }, { have := (supported_action_eq_of_mem_preimage_litter_subset _ ha).symm.trans (hab.trans (supported_action_eq_of_dom _ hb)), obtain ⟨hab, -⟩ := subtype.coe_eq_iff.mp this, cases hab.not_mem_ran ⟨b, hb, rfl⟩, }, { have := (supported_action_eq_of_mem_preimage_litter_subset _ ha).symm.trans (hab.trans (supported_action_eq_of_mem_preimage_litter_subset _ hb)), rw [subtype.coe_inj, embedding_like.apply_eq_iff_eq] at this, exact subtype.coe_inj.mpr this, }, { have := (supported_action_eq_of_mem_preimage_litter_subset _ ha).symm.trans (hab.trans (supported_action_eq_of_mem_mapped_outside_subset _ hb)), obtain ⟨hab, -⟩ := subtype.coe_eq_iff.mp this, cases without_preimage.not_mapped_outside w hab _ hL' (w.mapped_outside_equiv L' hL' ⟨b, hb⟩).prop, }, { have := (supported_action_eq_of_mem_mapped_outside_subset _ ha).symm.trans (hab.trans (supported_action_eq_of_dom _ hb)), obtain ⟨hab, -⟩ := subtype.coe_eq_iff.mp this, cases hab.not_mem_ran ⟨b, hb, rfl⟩, }, { have := (supported_action_eq_of_mem_mapped_outside_subset _ ha).symm.trans (hab.trans (supported_action_eq_of_mem_preimage_litter_subset _ hb)), obtain ⟨hab, -⟩ := subtype.coe_eq_iff.mp this.symm, cases without_preimage.not_mapped_outside w hab _ hL (w.mapped_outside_equiv L hL ⟨a, ha⟩).prop, }, { have := (supported_action_eq_of_mem_mapped_outside_subset _ ha).symm.trans (hab.trans (supported_action_eq_of_mem_mapped_outside_subset _ hb)), cases w.litter_map_injective hL hL' _, { simp only [subtype.coe_inj, embedding_like.apply_eq_iff_eq] at this, exact this, }, obtain ⟨hab, -⟩ := subtype.coe_eq_iff.mp this, exact ⟨_, hab.1, (w.mapped_outside_equiv L' hL' ⟨b, hb⟩).prop.1⟩, }, end lemma supported_action_atom_map_core_mem (a : atom) (ha : (w.supported_action_atom_map_core a).dom) (L : litter) (hL : (w.litter_map L).dom) : a.fst = L ↔ (w.supported_action_atom_map_core a).get ha ∈ (w.litter_map L).get hL := begin obtain (ha | ha | ⟨L', hL', ha⟩) := ha, { rw [w.atom_mem a ha L hL, supported_action_eq_of_dom], }, { rw supported_action_eq_of_mem_preimage_litter_subset, split, { rintro rfl, have := w.preimage_litter_subset_subset ha, rw mem_litter_set at this, rw this at hL, have := banned_litter.litter_dom _ hL, cases w.preimage_litter_not_banned this, }, { intro h, cases (w.preimage_litter_equiv ⟨a, ha⟩).prop.not_mem_map L hL h, }, }, { cases w.mapped_outside_subset_subset L' hL' ha, rw supported_action_eq_of_mem_mapped_outside_subset, split, { rintro rfl, exact (w.mapped_outside_equiv _ _ _ ).prop.mem_map, }, { intro h, refine w.litter_map_injective hL' hL ⟨_, _, h⟩, exact (w.mapped_outside_equiv _ _ _ ).prop.mem_map, }, }, end noncomputable def fill_atom_range : weak_near_litter_approx := { atom_map := w.supported_action_atom_map_core, litter_map := w.litter_map, atom_map_dom_small := w.supported_action_atom_map_core_dom_small, litter_map_dom_small := w.litter_map_dom_small, atom_map_injective := w.supported_action_atom_map_core_injective, litter_map_injective := w.litter_map_injective, atom_mem := w.supported_action_atom_map_core_mem, } variable {w} @[simp] lemma fill_atom_range_atom_map : w.fill_atom_range.atom_map = w.supported_action_atom_map_core := rfl @[simp] lemma fill_atom_range_litter_map : w.fill_atom_range.litter_map = w.litter_map := rfl lemma subset_supported_action_atom_map_core_dom : w.atom_map.dom ⊆ w.supported_action_atom_map_core.dom := subset_union_left _ _ lemma subset_supported_action_atom_map_core_ran : w.atom_map.ran ⊆ w.supported_action_atom_map_core.ran := begin rintro _ ⟨a, ha, rfl⟩, exact ⟨a, subset_supported_action_atom_map_core_dom ha, w.supported_action_eq_of_dom _⟩, end lemma fill_atom_range_symm_diff_subset_ran (L : litter) (hL : (w.fill_atom_range.litter_map L).dom) : ((w.fill_atom_range.litter_map L).get hL : set atom) ∆ litter_set ((w.fill_atom_range.litter_map L).get hL).fst ⊆ w.fill_atom_range.atom_map.ran := begin rintro a, by_cases ha₁ : a ∈ w.atom_map.ran, { obtain ⟨b, hb, rfl⟩ := ha₁, exact λ _, ⟨b, or.inl hb, w.supported_action_eq_of_dom hb⟩, }, rintro (⟨ha₂, ha₃⟩ | ⟨ha₂, ha₃⟩), { refine ⟨(w.mapped_outside_equiv L hL).symm ⟨a, ha₂, ha₃, ha₁⟩, _, _⟩, { exact or.inr (or.inr ⟨L, hL, ((w.mapped_outside_equiv L hL).symm _).prop⟩), }, { simp only [fill_atom_range_atom_map], refine (w.supported_action_eq_of_mem_mapped_outside_subset ((w.mapped_outside_equiv L hL).symm _).prop).trans _, simp only [subtype.coe_eta, equiv.apply_symm_apply, subtype.coe_mk], }, }, { by_cases ha₄ : ∀ (L' : litter) (hL' : (w.litter_map L').dom), a ∉ (w.litter_map L').get hL', { refine ⟨w.preimage_litter_equiv.symm ⟨a, ⟨L, hL, ha₂⟩, ha₄, ha₁⟩, _, _⟩, { exact or.inr (or.inl (w.preimage_litter_equiv.symm _).prop), }, { simp only [fill_atom_range_atom_map], refine (w.supported_action_eq_of_mem_preimage_litter_subset (w.preimage_litter_equiv.symm _).prop).trans _, simp only [subtype.coe_eta, equiv.apply_symm_apply, subtype.coe_mk], }, }, { push_neg at ha₄, obtain ⟨L', hL', ha₄⟩ := ha₄, refine ⟨(w.mapped_outside_equiv L' hL').symm ⟨a, ha₄, _, ha₁⟩, _, _⟩, { intro ha, have := near_litter.inter_nonempty_of_fst_eq_fst (eq_of_mem_litter_set_of_mem_litter_set ha₂ ha), cases w.litter_map_injective hL hL' this, exact ha₃ ha₄, }, { exact or.inr (or.inr ⟨L', hL', ((w.mapped_outside_equiv L' hL').symm _).prop⟩), }, { simp only [fill_atom_range_atom_map], refine (w.supported_action_eq_of_mem_mapped_outside_subset ((w.mapped_outside_equiv L' hL').symm _).prop).trans _, simp only [subtype.coe_eta, equiv.apply_symm_apply, subtype.coe_mk], }, }, }, end end weak_near_litter_approx end con_nf
fecundity.allometric = function( cw, method="st.marie" ) { if (method == "st.marie") { # this is from Saint-Marie(1993, unpublished) ... look for a more recent summary # est = cw ^2.725 * 10^0.7311 } if (method == "moncton.primiparous" ) { est = cw^2.94 * 10^(-0.7229) # R^2 = 0.88 } if (method == "moncton.multiparous" ) { est = cw^2.5811 * 10^0.0158 ## R^2 = 0.607 } return( est ) }
\subsection{Doing things with strings}\label{refostrin} \index{Overview,strings} \index{Strings,overview} :p. A character string is the fundamental datatype of NetRexx, and so, as you might expect, NetRexx provides many useful routines for manipulating strings. These are based on the functions of Rexx, but use a syntax that is more like Java or other similar languages: \begin{verbatim} phrase='Now is the time for a party' say phrase.word(7).pos('r') \end{verbatim} :p. The second line here can be read from left to right as: :sl. :li. take the variable \textbf{phrase}, find the seventh word, and then find the position of the first "\textbf{r}" in that word. :esl. :pc.This would display "\textbf{3}" in this case, because "\textbf{r}" is the third character in "\textbf{party}". :p. (In Rexx, the second line above would have been written using nested function calls: \begin{verbatim} say pos('r', word(phrase, 7)) \end{verbatim} :p. which is not as easy to read; you have to follow the nesting and then backtrack from right to left to work out exactly what's going on.) :p. In the NetRexx syntax, at each point in the sequence of operations some routine is acting on the result of what has gone before. These routines are called \emph{methods}, to make the distinction from functions (which act in isolation). NetRexx provides (as methods) most of the functions that were evolved for Rexx, including: :ul. :li.:m. changestr:em. (change all occurrences of a substring to another) :li.:m. copies:em. (make multiple copies of a string) :li.:m. lastpos:em. (find rightmost occurrence) :li.:m. left:em. and :m.right:em. (return leftmost/rightmost character(s)) :li.:m. pos:em. and :m.wordpos:em. (find the position of string or a word in a string) :li.:m. reverse:em. (swap end-to-end) :li.:m. space:em. (pad between words with fixed spacing) :li.:m. strip:em. (remove leading and/or trailing white space) :li.:m. verify:em. (check the contents of a string for selected characters) :li.:m. word:em., :m.wordindex:em., :m.wordlength:em., and :m.words:em. (work with words). :eul. :p. These and the others like them, and the parsing described in the next section, make it especially easy to process text with NetRexx.
Monte Carlo integration is a technique for numerical integration using random numbers. It can be useful, for example, when evaluating integrals over domains of high dimension. Meshing in high dimensions suffers from the [curse of dimensionality](https://en.wikipedia.org/wiki/Curse_of_dimensionality): 100 evenly spaced sample points suffice to sample the unit interval $[0,1]$ with no more than 0.01 distance between points, whereas sampling of the 10-dimensional unit hypercube $[0,1]^{10}$ with a lattice that has a spacing of 0.01 between adjacent points would require $10^{20}$ sample points. Let $\Omega \subset \mathbb R^n$ and let $f : \Omega \to \mathbb R$ be piecewise continuous. Let $p$ be such a probability density function on $\Omega$ that $p(x) > 0$ for all $x \in \Omega$. The Monte Carlo approach to approximate the integral $\int_\Omega f(x) dx$ works as follows: 1. Generate a large number of independent samples $x_1,\dots,x_N \in \Omega$ from the probablity distribution with the density $p$ 2. Compute the quantity $$ I_N = \frac 1 N \sum_{i=1}^N \frac{f(x_i)}{p(x_i)}. $$ The [law of large numbers](https://en.wikipedia.org/wiki/Law_of_large_numbers) implies that $$ I_N \to \int_\Omega f(x) dx \quad \text{as $n \to \infty$}. $$ Choosing $p$ cleverly is the basic idea behind [importance sampling](https://en.wikipedia.org/wiki/Importance_sampling). [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem) experiment is a classical pedagogical example of Monte Carlo integration. Suppose we have a floor made of parallel strips of wood, each the same width $t$, and we drop a needle of length $l < t$ onto the floor. Buffon showed that the probability $P$ that the needle will lie across a line between two strips is \begin{equation}\tag{1} P=\frac{2}{\pi}\frac{l}{t}. \end{equation} Let $s$ be the distance from the center of the needle to the closest parallel line, and let $\theta$ be the acute angle between the needle and one of the parallel lines. Here $s$ and $\theta$ are random variables with uniform distributions over $[0, t/2]$ and $[0,\pi/2]$, respectively. We write $p(s,\theta)$ for their joint probability density function and $A$ for the event that the needle lies across a line between two strips. Then $$ P = \int_A p(s,\theta) ds d\theta. $$ Writing $\Omega = [0, t/2] \times [0,\pi/2]$ and $f(x) = 1_A(x) p(x)$ where $x = (s,\theta)$ and $$ 1_A(x) = \begin{cases} 1 & x \in A, \\ 0 & x \notin A, \end{cases} $$ we have, using the notation above, that $I_N \to P$ as $N \to \infty$. Observe that, in this case, $$ I_N = \frac 1 N \sum_{i=1}^N 1_A(x_i), $$ and evaluating $I_N$ boils down to counting the needles that lie across a line between two strips. Take $l = 5/6$ and $t = 1$. The goal of this homework is to approximate $\pi$ via the formula $$ \pi=\frac{2l}{t P} \approx \frac{2l}{t I_N}, $$ that follows from (1). Let us give some remarks on the history of Monte Carlo integration. Formula (1) was first derived in > Buffon, Georges L. L., comte de. _Histoire naturelle, générale et particulière, Supplément 4_. Imprimerie royale, Paris, 1777. (scan in [Google Books](https://books.google.fi/books?id=AjhYD1vsVAIC&hl=fi&pg=PA100#v=onepage&q&f=false)) Now my French is not very strong, but as claimed [here](https://en.wikipedia.org/wiki/Buffon's_needle_problem), it seems that approximating $\pi$ was not the original motivation for Buffon's question. You can have a look at his book, see pp. 100-104, and while you are at it, you can also try figure out if there is an error in his derivation, as claimed [here](https://mathworld.wolfram.com/Buffon-LaplaceNeedleProblem.html). The idea of using Buffon's formula to design a method for approximating the number $\pi$ goes back at least to Laplace. _"Si l'on projette un grand nombre de fois ce cylindre [...] ce qui fera connaître la valeur de la circonférence $2 \pi$"_, see p. 360 of > Laplace, Pierre S., marquis de. _Théorie analytique des probabilités_. Veuve Courcier, Paris, 1812. (scan in [Internet Archive](https://archive.org/details/thorieanalytiqu01laplgoog/page/n464/mode/2up)) The first computerized Monte Carlo simulations were run on [ENIAC](https://en.wikipedia.org/wiki/ENIAC) in 1948 by a team including John and Klara von Neumann and Nick Metropolis. It can be argued that the simulations were also the first code written in the modern paradigm, associated with the "stored program concept," ever to be executed, see > Haigh, Thomas, Priestley, Mark, and Rope, Crispin. _Los Alamos Bets on ENIAC: Nuclear Monte Carlo Simulations, 1947-1948_. IEEE Annals of the History of Computing 36, no. 3, 42-63, 2014. <https://doi.org/10.1109/MAHC.2014.40> (in [Helka](https://helka.helsinki.fi/permalink/358UOH_INST/qn0n39/cdi_ieee_primary_6880250)) ```python import numpy as np rng = np.random.default_rng() t = 1 l = 5/6 def sample(): '''Returns s and theta generated using the random number generator rng''' # Draw samples from uniform distributions using the function rng.uniform, see # https://numpy.org/doc/stable/reference/random/generated/numpy.random.Generator.uniform.html raise NotImplementedError() # a placeholder, your implementation goes here def intersects(s, theta): '''Returns True iff the needle lies across a line between two strips''' raise NotImplementedError() # a placeholder, your implementation goes here # We will plot I_N for several N so let's save every nth approximation def I(n, K): '''Return I_n, I_{2n}, ..., I_{Kn}''' out = np.zeros(K) raise NotImplementedError() # a placeholder, your implementation goes here return out ``` ```python import matplotlib.pyplot as plt ``` ```python # Plot one sample s, theta = sample() c = np.array([0, s]) # Center of needle d = np.array([np.cos(theta), np.sin(theta)]) # Direction of needle # End points of needle end1 = c - l/2*d end2 = c + l/2*d ends = np.stack((end1, end2)) xs = ends[:,0] ys = ends[:,1] plt.plot(xs, ys, 'r') # needle in red plt.plot([-1,1],[0, 0], 'b') # closest line in blue ax = plt.gca() ax.set_ylim(-0.5, 1) ax.set_aspect(1) print(f'Needle intersects the closest line: {intersects(s, theta)}') ``` ```python # Plot convergence to pi n = 100 K = 40 Is = I(n, K) Ns = n*np.arange(1,K+1) plt.plot(Ns, 2*l/(t*Is), 'b') # approximation in blue plt.plot([n,n*K],[np.pi, np.pi],'r') # pi in red ax = plt.gca() ax.set_ylim(2.4, 3.6); ``` **How to hand in your solution** 1. Run the whole notebook by choosing _Restart Kernel and Run All Cells_ in the _Run_ menu - Alternatively you can click the ⏩️ icon in the toolbar 2. Click the link below to check that the piece of code containing your solution was uploaded to pastebin - If you have changed the order of cells in the notebook, you may need to change the number in the below cell to the one in the left margin of the cell containing your solution 3. Copy the link and submit it in Moodle - You can copy the link easily by right-clicking it and choosing _Copy Output to Clipboard_ ```python # Upload the code in the first input cell to pastebin %pastebin 1 ```
lemma emeasure_compl: "s \<in> sets M \<Longrightarrow> emeasure M s \<noteq> \<infinity> \<Longrightarrow> emeasure M (space M - s) = emeasure M (space M) - emeasure M s"
#ifndef SEARCHPATTERNBASE_HHHHH #define SEARCHPATTERNBASE_HHHHH #include "../../SigScannerMemoryData.h" #include <vector> #include <string> #include <memory> #include <gsl/span> namespace MPSig { namespace detail { class SearchPatternBase { public: virtual ~SearchPatternBase() = default; using gsl_span_cit_t = typename gsl::span<const char>::const_iterator; using gsl_span_crit_t = typename gsl::span<const char>::const_reverse_iterator; template<typename It> struct ExecFirstResult { bool success; // If it was a success It rangeBegin; // The first valid iterator It rangeEnd; // The next depended iterator point (from which all other patterns depend on) }; // ExecFirst can look up begin to end fully, without restrictions virtual ExecFirstResult<gsl_span_cit_t> ExecFirst(const MPSig::SigScannerMemoryData& data, gsl_span_cit_t begin, gsl_span_cit_t end) const = 0; virtual ExecFirstResult<gsl_span_crit_t> ExecFirst(const MPSig::SigScannerMemoryData& data, gsl_span_crit_t begin, gsl_span_crit_t end) const = 0; // ExecDepend must only check the current location as it depends on a search success virtual ExecFirstResult<gsl_span_cit_t> ExecDepend(const MPSig::SigScannerMemoryData& data, gsl_span_cit_t begin, gsl_span_cit_t end) const = 0; virtual ExecFirstResult<gsl_span_crit_t> ExecDepend(const MPSig::SigScannerMemoryData& data, gsl_span_crit_t begin, gsl_span_crit_t end) const = 0; virtual std::unique_ptr<SearchPatternBase> Clone() const = 0; }; } } #endif
{-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeOperators #-} --------------------------------- -- | -- Module : HMM -- Copyright : (C) Kaushik Chakraborty, 2019 -- License : Apache v2 (see the file LICENSE) -- Maintainer : Kaushik Chakraborty <[email protected]> -- Stability : experimental -- --------------------------------- module HMM ( HMM(..), -- ** Smart Constructors mkHMM_, mkHMM, mkHMM1, sensorDiagonal, -- * Utility Functions normalise, inverse, reverseV, extract1, (!**!), unitColumn, -- ** Converting to/from HMatrix matrices toHM, fromHM, -- * Inference Algorithms -- ** Forward-Backward forward, backward, forwardBackward, -- ** Fixed Lag Smoothing fixedLagSmoothing, -- * Sample HMM Models umbrellaHMM, -- * Miscellaneous -- ** Type Synonyms R, TransitionModel, SensorDiagonal, SensorModel, Message, Distribution, -- ** Data Types Persistent(..), -- ** Test Functions runFLSAlgo, runFBAlgo, -- ** Lenses prior, tModel, sDist, sModel ) where import Text.Printf (printf) import Papa import GHC.TypeNats import Data.Proxy (Proxy(..)) import Control.Monad.State (State, runState) import Control.Monad.Trans.Maybe (MaybeT, runMaybeT) import qualified Data.Vector as Vec import Linear.V import Linear import qualified Numeric.LinearAlgebra.Static as HM import qualified Numeric.LinearAlgebra as HMat ----------------------------------------------------------------------------------- type R = Double type TransitionModel (s :: Nat) a = V s (V s a) type SensorDiagonal (s :: Nat) a = V s (V s a) type SensorModel (t :: Nat) (s :: Nat) a = V t (SensorDiagonal s a) type Message (s :: Nat) a = V s (V 1 a) type Distribution (s :: Nat) a = V s a -- | Hidden Markov Models data HMM (s :: Nat) (t :: Nat) a b = HMM { -- | prior distribution which is used as initial forward message _prior :: Message s a, -- | transition model with @s@ states as @sxs@ matrix _tModel :: TransitionModel s a, -- | evidence value vector, each index maps to the corresponding evidence values _sDist :: V t b, -- | sensor model with @t@ evidence values having @sxs@ diagonal matrix capturing their ditributions for each state @s@ _sModel :: SensorModel t s a } deriving (Show) makeLenses ''HMM mkHMM_ :: (KnownNat s, KnownNat t) => Maybe (Message s R) -- ^ Prior distribution on the initial state, @P(X0)@. If nothing then considered @(0.5,0.5)@ -> TransitionModel s R -- ^ Transition Model as @sxs@ matrix, @s@ being the number of states -> V t b -- ^ evidence values vector map -> V t (V s R) -- ^ a @txs@ matrix for each evidence value @t@, a vector capturing conditional probabilities for each state @s@ -> HMM s t R b mkHMM_ mp xs evs = let p = fromMaybe (V $ Vec.replicate (dim xs) 0.5) mp in HMM p xs evs . (scaled <$>) -- | A default HMM where both transition model states and evidence variables have boolean support mkHMM :: KnownNat s => TransitionModel s R -> V 2 (V s R) -> HMM s 2 R Bool mkHMM ts = mkHMM_ Nothing ts (V $ Vec.fromList [True, False]) -- | A default HMM with one state variable having boolean support mkHMM1 :: V2 (V2 R) -> V2 (V2 R) -> HMM 2 2 R Bool mkHMM1 ts ss = let f = (_V #) . over mapped toV in uncurry mkHMM $ over both f (ts , ss) -- | create a @sxs@ diagonal matrix with corresponding posterior probabilities from the sensor model of the @HMM@ for an input sensor value sensorDiagonal :: (KnownNat s, KnownNat t, Eq b) => HMM s t a b -> b -- ^ sensor value -> Maybe (SensorDiagonal s a) sensorDiagonal hmm e = findIndexOf (sDist.folded) (== e) hmm >>= (\i -> hmm ^? sModel . ix i) -- | Multiply each number by a constant such that the sum is 1.0 normalise :: (Fractional a, Foldable f, Functor f) => f a -> f a normalise xs | null xs = xs | otherwise = let s = sum xs in (/ s) <$> xs -- | inverse a square matrix inverse :: forall s. (KnownNat s) => V s (V s R) -> V s (V s R) inverse = fromHM . HM.inv . toHM -- | reverse contents of a 'Linear.V' vector reverseV :: forall s a. (KnownNat s) => V s a -> V s a reverseV = V . Vec.fromList . Papa.reverse . toList extract1 :: (KnownNat s) => V s (V 1 a) -> V s a extract1 = V . foldMap toVector -- | Pointwise product of 2 @mxn@ 'V' vectors infix 8 !**! (!**!) :: (KnownNat m, KnownNat n) => V m (V n R) -> V m (V n R) -> V m (V n R) as !**! bs = fromHM $ toHM as * toHM bs -- | an unit vector having @s@ columns unitColumn :: forall s. KnownNat s => Message s R unitColumn = V $ Vec.replicate (fromIntegral $ natVal (Proxy :: Proxy s)) (toV $ V1 1.0) -- | take a @sxt@ 'Linear.V.V' matrix and give corresponding 'Numeric.LinearAlgebra.Static.L' version toHM :: (KnownNat s, KnownNat t) => V s (V t R) -> HM.L s t toHM = HM.matrix . foldMap (Vec.toList . toVector) -- | take a @sxt@ 'Numeric.LinearAlgebra.Static.L' matrix and give corresponding 'Linear.V.V' version fromHM :: (KnownNat s, KnownNat t) => HM.L s t -> V s (V t R) fromHM m = V $ V <$> Vec.fromList (fmap Vec.fromList $ HMat.toLists $ HM.extract m) -- | Filtering message propagated forward forward :: (KnownNat s) => HMM s t R b -> SensorDiagonal s R -> Message s R -> Message s R forward hmm ot f = normalise (ot !*! Linear.transpose (hmm ^. tModel) !*! f) -- | Smoothing message propagated backward backward :: (KnownNat s) => HMM s t R b -> SensorDiagonal s R -> Message s R -> Message s R backward hmm ok1 bk2 = (hmm ^. tModel) !*! ok1 !*! bk2 -- | The forward–backward algorithm for smoothing: computing posterior prob- abilities of a sequence of states given a sequence of observations forwardBackward :: forall s t u b . (KnownNat t, KnownNat s, KnownNat u, Eq b) => HMM s u R b -- ^ HMM model as a way to implement -> V t b -- ^ list of evidences for each time step -> V t (Distribution s R) forwardBackward hmm evs = let -- reifying the number of evidences tNat = dim evs -- forward messages from time t .. 0 fv :: V (t + 1) (Message s R) fv = V $ Vec.fromList $ foldl' (\m@(x:_) e -> forward hmm (sensorDiagonal hmm e ^?! _Just) x : m) [hmm ^. prior] evs -- getting rid of the prior message from the end of the list -- so now forward messages vector is from time t .. 1 fv_0 :: V t (Message s R) fv_0 = V $ Vec.fromList $ fv ^.. taking tNat traversed -- backward messages from time 1 .. t bs :: V t (Message s R) bs = V $ Vec.fromList $ foldl' (\m@(x:_) e -> backward hmm (sensorDiagonal hmm e ^?! _Just) x : m) [unitColumn] $ reverseV evs -- reversing the backward messages -- so now the backward messages vector is from time t .. 1 revBs :: V t (Message s R) revBs = reverseV bs in -- smoothing probabilities in reverse order of the list of evidences -- i.e. starting from time t .. 1 liftA2 (\f b' -> extract1 $ normalise $ f !**! b') fv_0 revBs -- | Persistent State data Persistent (s :: Nat) a b d= Persistent { _t :: d, -- ^ current time _f_msg :: Message s a, -- ^ the forward message @P(Xt|e1:t)@ _b :: V s (V s a), -- ^ the @d@-step backward transformation matrix _e_td_t :: Vec.Vector b -- ^ double-ended list of evidence from @t − d@ to @t@ } deriving (Show) makeLenses ''Persistent -- | Initial persistent state where -- -- * t = 1 -- -- * f_msg = hmm.prior -- -- * b = identity matrix -- -- * e_td_t = empty vector persistentInit :: forall s b d. (KnownNat s, Integral d) => Message s R -> Persistent s R b d persistentInit p = Persistent { _t = 1, _f_msg = p, _b = identity, _e_td_t = Vec.empty} -- | Online Algorithm for smoothing with a fixed time lag of @d@ steps fixedLagSmoothing :: forall s u b d. (KnownNat s, KnownNat u, Eq b, Integral d) => HMM s u R b -- ^ HMM model -> d -- ^ length of lag -> b -- ^ evidence at time @t@ -> MaybeT (State (Persistent s R b d)) (Distribution s R) fixedLagSmoothing hmm d e = do e_td_t %= flip Vec.snoc e o_t <- uses e_td_t $ (^?! _Just) . sensorDiagonal hmm . Vec.last t' <- use t if t' > d then do e_td_t %= Vec.drop 1 o_tmd <- uses e_td_t $ (^?! _Just) . sensorDiagonal hmm . Vec.head f_msg %= forward hmm o_tmd b %= \b' -> inverse o_tmd !*! inverse (hmm ^. tModel) !*! b' !*! (hmm ^. tModel) !*! o_t t += 1 (f'', b'') <- liftA2 (,) (use f_msg) (use b) return $ extract1 $ normalise (f'' !**! (b'' !*! unitColumn)) else do b %= \b' -> b' !*! (hmm ^. tModel) !*! o_t t += 1 mzero umbrellaHMM :: HMM 2 2 R Bool umbrellaHMM = mkHMM1 (V2 (V2 0.7 0.3) (V2 0.3 0.7)) (V2 (V2 0.9 0.2) (V2 0.1 0.8)) runFLSAlgo :: [Bool] -> Integer -> [Maybe (Distribution 2 String)] runFLSAlgo bs d = let hmm = mkHMM1 (V2 (V2 0.7 0.3) (V2 0.3 0.7)) (V2 (V2 0.9 0.2) (V2 0.1 0.8)) initState = persistentInit (V $ Vec.fromList [V $ Vec.singleton 0.5, V $ Vec.singleton 0.5]) :: Persistent 2 R Bool Integer algo = fixedLagSmoothing hmm d a :: ([Maybe (Distribution 2 R)], Persistent 2 R Bool Integer) a = foldl' (\(rs, s) x -> runState (runMaybeT $ algo x) s & _1 #%~ ((rs ++) . pure)) ([], initState) bs in (a ^. _1) & traverse.traverse.traverse %~ \(x :: R) -> printf "%.3f" x :: String runFBAlgo :: [Bool] -> [Distribution 2 R] runFBAlgo bs = reifyVectorNat (Vec.fromList bs) (toList . forwardBackward umbrellaHMM)
SUBROUTINE D5SPLT (ALM,BLM,clm,MULT,UENORM,num,coord,jatom) ! ! DECOMPOSITION OF D CHARGE IN DZ2,DX2-Y2,DXY,DXZ,DYZ ! new (and reversed) definitions for dxz, dyz (6.2.89., Blaha) ! use param USE chard use lo IMPLICIT REAL*8 (A-H,O-Z) COMPLEX*16 ALM,BLM,clm,CSUMa,csumb,csumc DIMENSION ALM((lmax2+1)*(lmax2+1)),BLM((lmax2+1)*(lmax2+1)) DIMENSION cLM((lomax+1)*(lomax+1)) CHARACTER*5 COORD !--------------------------------------------------------------------- ! ipip=max(ilo(2),1) SQRT2=SQRT(2.D0) SQRT3=SQRT(3.D0) IF (COORD.EQ.'OCTAH') THEN ! ! non standard dsplit ! classical octahedral coordinates ! IF (JATOM.EQ.1) THEN ! =========================== ! 1. METALLATOM ! ! CSUMa=( SQRT3*(ALM(9)+ALM(5))/SQRT2 - ALM(7) )*0.5 CSUMb=( SQRT3*(bLM(9)+bLM(5))/SQRT2 - bLM(7) )*0.5 CSUMc=( SQRT3*(cLM(9)+cLM(5))/SQRT2 - cLM(7) )*0.5 ADz2(num)=ADz2(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDz2(num)=BDz2(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdz2(num)=cdz2(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadz2(num)=cadz2(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdz2(num)=acdz2(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdz2(num)=cbdz2(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdz2(num)=bcdz2(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(-1)*(ALM(8)+ALM(6))/SQRT2 CSUMb=(-1)*(BLM(8)+BLM(6))/SQRT2 CSUMc=(-1)*(cLM(8)+cLM(6))/SQRT2 ADX2Y2(num)=ADX2Y2(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDX2Y2(num)=BDX2Y2(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdx2y2(num)=cdx2y2(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadx2y2(num)=cadx2y2(num)+ & CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdx2y2(num)=acdx2y2(num)+ & CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdx2y2(num)=cbdx2y2(num)+ & CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdx2y2(num)=bcdx2y2(num)+ & CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=( (ALM(9)+ALM(5))/SQRT2 + SQRT3*ALM(7) )*0.5 CSUMb=( (BLM(9)+BLM(5))/SQRT2 + SQRT3*BLM(7) )*0.5 CSUMc=( (cLM(9)+cLM(5))/SQRT2 + SQRT3*cLM(7) )*0.5 ADXY(num)=ADXY(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDXY(num)=BDXY(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdxy(num)=cdxy(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadxy(num)=cadxy(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdxy(num)=acdxy(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdxy(num)=cbdxy(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdxy(num)=bcdxy(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=((ALM(9)-ALM(5))/SQRT2-(ALM(8)-ALM(6))/SQRT2)/SQRT2 CSUMb=((BLM(9)-BLM(5))/SQRT2-(BLM(8)-BLM(6))/SQRT2)/SQRT2 CSUMc=((cLM(9)-cLM(5))/SQRT2-(cLM(8)-cLM(6))/SQRT2)/SQRT2 ADXz(num)=ADXz(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDXz(num)=BDXz(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdxz(num)=cdxz(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadxz(num)=cadxz(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdxz(num)=acdxz(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdxz(num)=cbdxz(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdxz(num)=bcdxz(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=((-1.)*(ALM(9)-ALM(5))/SQRT2-(ALM(8)-ALM(6))/SQRT2)/SQRT2 CSUMb=((-1.)*(BLM(9)-BLM(5))/SQRT2-(BLM(8)-BLM(6))/SQRT2)/SQRT2 CSUMc=((-1.)*(cLM(9)-cLM(5))/SQRT2-(cLM(8)-cLM(6))/SQRT2)/SQRT2 ADYz(num)=ADYz(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDYz(num)=BDYz(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdyz(num)=cdyz(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadyz(num)=cadyz(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdyz(num)=acdyz(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdyz(num)=cbdyz(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdyz(num)=bcdyz(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! ELSE ! =========================== ! 2.METALLATOM ! CSUMa=(-SQRT3*(ALM(9)+ALM(5))/SQRT2-ALM(7) )*0.5 CSUMb=(-SQRT3*(BLM(9)+BLM(5))/SQRT2-BLM(7) )*0.5 CSUMc=(-SQRT3*(cLM(9)+cLM(5))/SQRT2-cLM(7) )*0.5 ADz2(num)=ADz2(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDz2(num)=BDz2(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdz2(num)=cdz2(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadz2(num)=cadz2(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdz2(num)=acdz2(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdz2(num)=cbdz2(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdz2(num)=bcdz2(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(-1.)*(ALM(8)-ALM(6))/SQRT2 CSUMb=(-1.)*(BLM(8)-BLM(6))/SQRT2 CSUMc=(-1.)*(cLM(8)-cLM(6))/SQRT2 ADX2Y2(num)=ADX2Y2(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDX2Y2(num)=BDX2Y2(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdx2y2(num)=cdx2y2(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadx2y2(num)=cadx2y2(num)+ & CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdx2y2(num)=acdx2y2(num)+ & CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdx2y2(num)=cbdx2y2(num)+ & CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdx2y2(num)=bcdx2y2(num)+ & CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=( (-1.)*(ALM(9)+ALM(5))/SQRT2 + SQRT3*ALM(7) )*0.5 CSUMb=( (-1.)*(BLM(9)+BLM(5))/SQRT2 + SQRT3*BLM(7) )*0.5 CSUMc=( (-1.)*(cLM(9)+cLM(5))/SQRT2 + SQRT3*cLM(7) )*0.5 ADXY(num)=ADXY(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDXY(num)=BDXY(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdxy(num)=cdxy(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadxy(num)=cadxy(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdxy(num)=acdxy(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdxy(num)=cbdxy(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdxy(num)=bcdxy(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=((ALM(9)-ALM(5))/SQRT2-(ALM(8)+ALM(6))/SQRT2 )/SQRT2 CSUMb=((BLM(9)-BLM(5))/SQRT2-(BLM(8)+BLM(6))/SQRT2 )/SQRT2 CSUMc=((cLM(9)-cLM(5))/SQRT2-(cLM(8)+cLM(6))/SQRT2 )/SQRT2 ADXz(num)=ADXz(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDXz(num)=BDXz(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdxz(num)=cdxz(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadxz(num)=cadxz(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdxz(num)=acdxz(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdxz(num)=cbdxz(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdxz(num)=bcdxz(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=((-1.)*(ALM(9)-ALM(5))/SQRT2-(ALM(8)+ALM(6))/SQRT2)/SQRT2 CSUMb=((-1.)*(BLM(9)-BLM(5))/SQRT2-(BLM(8)+BLM(6))/SQRT2)/SQRT2 CSUMc=((-1.)*(cLM(9)-cLM(5))/SQRT2-(cLM(8)+cLM(6))/SQRT2)/SQRT2 ADYz(num)=ADYz(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDYz(num)=BDYz(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdyz(num)=cdyz(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadyz(num)=cadyz(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdyz(num)=acdyz(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdyz(num)=cbdyz(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdyz(num)=bcdyz(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! END IF ! ELSE if (COORD.EQ.'TRIGO') THEN ! CSUMa=(1/SQRT3)*((ALM(8)-ALM(6))+(ALM(9)+ALM(5))/SQRT2) CSUMb=(1/SQRT3)*((bLM(8)-bLM(6))+(bLM(9)+bLM(5))/SQRT2) CSUMc=(1/SQRT3)*((cLM(8)-cLM(6))+(cLM(9)+cLM(5))/SQRT2) ADz2(num)=ADz2(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDz2(num)=BDz2(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdz2(num)=cdz2(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadz2(num)=cadz2(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdz2(num)=acdz2(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdz2(num)=cbdz2(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdz2(num)=bcdz2(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(1/SQRT3)*((aLM(8)+aLM(6))-(aLM(9)-aLM(5))/SQRT2) CSUMb=(1/SQRT3)*((bLM(8)+bLM(6))-(bLM(9)-bLM(5))/SQRT2) CSUMc=(1/SQRT3)*((cLM(8)+cLM(6))-(cLM(9)-cLM(5))/SQRT2) ADX2Y2(num)=ADX2Y2(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDX2Y2(num)=BDX2Y2(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdx2y2(num)=cdx2y2(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadx2y2(num)=cadx2y2(num)+ & CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdx2y2(num)=acdx2y2(num)+ & CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdx2y2(num)=cbdx2y2(num)+ & CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdx2y2(num)=bcdx2y2(num)+ & CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=ALM(7) CSUMb=BLM(7) CSUMc=cLM(7) ADXY(num)=ADXY(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDXY(num)=BDXY(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdxy(num)=cdxy(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadxy(num)=cadxy(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdxy(num)=acdxy(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdxy(num)=cbdxy(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdxy(num)=bcdxy(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(1/SQRT3)*((ALM(8)+ALM(6))/SQRT2+(ALM(9)-ALM(5))) CSUMb=(1/SQRT3)*((bLM(8)+bLM(6))/SQRT2+(bLM(9)-bLM(5))) CSUMc=(1/SQRT3)*((cLM(8)+cLM(6))/SQRT2+(cLM(9)-cLM(5))) ADXz(num)=ADXz(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDXz(num)=BDXz(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdxz(num)=cdxz(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadxz(num)=cadxz(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdxz(num)=acdxz(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdxz(num)=cbdxz(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdxz(num)=bcdxz(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(1/SQRT3)*((ALM(8)-ALM(6))/SQRT2-(ALM(9)+ALM(5))) CSUMb=(1/SQRT3)*((bLM(8)-bLM(6))/SQRT2-(bLM(9)+bLM(5))) CSUMc=(1/SQRT3)*((cLM(8)-cLM(6))/SQRT2-(cLM(9)+cLM(5))) ADYz(num)=ADYz(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDYz(num)=BDYz(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdyz(num)=cdyz(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadyz(num)=cadyz(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdyz(num)=acdyz(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdyz(num)=cbdyz(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdyz(num)=bcdyz(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ELSE ! ! standard-split ! ADZ2(num)=ADZ2(num)+ALM(7)*CONJG(ALM(7))*100.D0/MULT BDZ2(num)=BDZ2(num)+BLM(7)*CONJG(BLM(7))*UENORM*100.D0/MULT cdz2(num)=cdz2(num)+cLM(7)*CONJG(cLM(7))*100.D0/MULT cadz2(num)=cadz2(num)+Clm(7)*CONJG(alm(7))*pi12lo(ipip,2)*100.D0/MULT acdz2(num)=acdz2(num)+alm(7)*CONJG(Clm(7))*pi12lo(ipip,2)*100.D0/MULT cbdz2(num)=cbdz2(num)+Clm(7)*CONJG(blm(7))*pe12lo(ipip,2)*100.D0/MULT bcdz2(num)=bcdz2(num)+blm(7)*CONJG(Clm(7))*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(ALM(9)+ALM(5))/SQRT2 CSUMb=(BLM(9)+BLM(5))/SQRT2 CSUMc=(cLM(9)+cLM(5))/SQRT2 ADX2Y2(num)=ADX2Y2(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDX2Y2(num)=BDX2Y2(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdx2y2(num)=cdx2y2(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadx2y2(num)=cadx2y2(num)+ & CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdx2y2(num)=acdx2y2(num)+ & CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdx2y2(num)=cbdx2y2(num)+ & CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdx2y2(num)=bcdx2y2(num)+ & CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(ALM(9)-ALM(5))/SQRT2 CSUMb=(BLM(9)-BLM(5))/SQRT2 CSUMc=(cLM(9)-cLM(5))/SQRT2 ADXY(num)=ADXY(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDXY(num)=BDXY(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdxy(num)=cdxy(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadxy(num)=cadxy(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdxy(num)=acdxy(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdxy(num)=cbdxy(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdxy(num)=bcdxy(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(ALM(8)-ALM(6))/SQRT2 CSUMb=(BLM(8)-BLM(6))/SQRT2 CSUMc=(cLM(8)-cLM(6))/SQRT2 ADXz(num)=ADXz(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDXz(num)=BDXz(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdxz(num)=cdxz(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadxz(num)=cadxz(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdxz(num)=acdxz(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdxz(num)=cbdxz(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdxz(num)=bcdxz(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT ! CSUMa=(ALM(8)+ALM(6))/SQRT2 CSUMb=(BLM(8)+BLM(6))/SQRT2 CSUMc=(cLM(8)+cLM(6))/SQRT2 ADYz(num)=ADYz(num)+CSUMa*CONJG(CSUMa)*100.D0/MULT BDYz(num)=BDYz(num)+CSUMb*CONJG(CSUMb)*UENORM*100.D0/MULT cdyz(num)=cdyz(num)+CSUMc*CONJG(CSUMc)*100.D0/MULT cadyz(num)=cadyz(num)+CSUMc*CONJG(CSUMa)*pi12lo(ipip,2)*100.D0/MULT acdyz(num)=acdyz(num)+CSUMa*CONJG(CSUMc)*pi12lo(ipip,2)*100.D0/MULT cbdyz(num)=cbdyz(num)+CSUMc*CONJG(CSUMb)*pe12lo(ipip,2)*100.D0/MULT bcdyz(num)=bcdyz(num)+CSUMb*CONJG(CSUMc)*pe12lo(ipip,2)*100.D0/MULT endif RETURN END SUBROUTINE D5SPLT
module OddAndEvens %access export %default total public export data Even : Nat -> Type where -- | Zero is even. ZeroEven : Even Z -- | If n is even, then n+2 is even. NextEven : Even n -> Even (S (S n)) public export data Odd : Nat -> Type where -- | One is odd. OneOdd : Odd (S Z) -- | If n is odd, then n+2 is odd. NextOdd : Odd n -> Odd (S (S n)) -- | Proves that if n is even, n+1 is odd. -- Notice how I use the axioms here. evenPlusOne : Even n -> Odd (S n) evenPlusOne ZeroEven = OneOdd evenPlusOne (NextEven x) = NextOdd $ evenPlusOne x -- | Proves that if n is odd, n+1 is even. oddPlusOne : Odd n -> Even (S n) oddPlusOne OneOdd = NextEven $ ZeroEven oddPlusOne (NextOdd x) = NextEven $ oddPlusOne x -- | Proves even + even = even evenPlusEven : Even n -> Even m -> Even (n + m) evenPlusEven ZeroEven y = y evenPlusEven (NextEven x) y = NextEven $ evenPlusEven x y -- | Proves odd + odd = even oddPlusOdd : Odd n -> Odd m -> Even (n + m) oddPlusOdd OneOdd y = oddPlusOne y oddPlusOdd (NextOdd x) y = NextEven $ oddPlusOdd x y -- | Proves even + odd = odd evenPlusOdd : Even n -> Odd m -> Odd (n + m) evenPlusOdd ZeroEven y = y evenPlusOdd (NextEven x) y = NextOdd $ evenPlusOdd x y -- | Proves odd + even = odd oddPlusEven : Odd n -> Even m -> Odd (n + m) oddPlusEven OneOdd y = evenPlusOne y oddPlusEven (NextOdd x) y = NextOdd $ oddPlusEven x y -- | Proves even * even = even evenTimesEven : Even n -> Even m -> Even (n * m) evenTimesEven ZeroEven _ = ZeroEven evenTimesEven (NextEven x) y = evenPlusEven y $ evenPlusEven y $ evenTimesEven x y -- | Proves odd * odd = odd oddTimesOdd : Odd n -> Odd m -> Odd (n * m) oddTimesOdd OneOdd {m} y = rewrite plusZeroRightNeutral m in y oddTimesOdd (NextOdd x) y = oddPlusEven y $ oddPlusOdd y $ oddTimesOdd x y -- | Proves even * odd = even evenTimesOdd : Even n -> Odd m -> Even (n * m) evenTimesOdd ZeroEven y = ZeroEven evenTimesOdd (NextEven x) y = oddPlusOdd y $ oddPlusEven y $ evenTimesOdd x y -- | Proves odd * even = even oddTimesEven : Odd n -> Even m -> Even (n * m) oddTimesEven OneOdd {m} y = rewrite plusZeroRightNeutral m in y oddTimesEven (NextOdd x) y = evenPlusEven y $ evenPlusEven y $ oddTimesEven x y
lemma bdd_below_closure: fixes A :: "real set" assumes "bdd_below A" shows "bdd_below (closure A)"
! Copyright (C) 2011 ! Free Software Foundation, Inc. ! This file is part of the gtk-fortran gtk+ Fortran Interface library. ! This is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 3, or (at your option) ! any later version. ! This software is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! Under Section 7 of GPL version 3, you are granted additional ! permissions described in the GCC Runtime Library Exception, version ! 3.1, as published by the Free Software Foundation. ! You should have received a copy of the GNU General Public License along with ! this program; see the files COPYING3 and COPYING.RUNTIME respectively. ! If not, see <http://www.gnu.org/licenses/>. ! ! gfortran -g gtk.f90 gtk-sup.f90 gtk-hl.f90 hl_choosers.f90 `pkg-config --cflags --libs gtk+-2.0` ! Contributed by James Tappin. ! Demo of file choosers. module handlers use gtk_hl use gtk, only: gtk_button_new, gtk_container_add, gtk_main, gtk_main_quit, gtk_& &text_view_new, gtk_widget_set_sensitive, gtk_widget_show, gtk_widget_show_all,& & gtk_window_new, gtk_init, TRUE, FALSE use gtk_os_dependent, only: gtk_file_chooser_get_filename implicit none ! Those widgets that need to be addressed explicitly in the handlers type(c_ptr) :: window, sbut, sabut, tedit ! Other variables that need to be shared between handlers logical, private :: file_is_changed = .FALSE. character(len=120), private :: filename='' contains subroutine my_destroy(widget, gdata) bind(c) type(c_ptr), value :: widget, gdata integer(kind=c_int) :: ok character(len=60), dimension(4) :: msg msg(1) = "File is changed" msg(2) = "" msg(3) = "Quitting now will destroy your changes" msg(4) = "Do you really want to quit" if (file_is_changed) then ok = hl_gtk_message_dialog_show(msg, GTK_BUTTONS_YES_NO, & & "Really Quit"//c_null_char, parent=window) if (ok == GTK_RESPONSE_NO) return end if print *, "Exit called" call gtk_main_quit () end subroutine my_destroy subroutine open_file(widget, gdata) bind(c) type(c_ptr), value :: widget, gdata integer(kind=c_int) :: isel character(len=120), dimension(:), allocatable :: chfile character(len=30), dimension(2) :: filters character(len=30), dimension(2) :: filtnames character(len=200) :: inln integer :: ios integer :: idxs filters(1) = "*.txt,*.lis" filters(2) = "*.f90" filtnames(1) = "Text files" filtnames(2) = "Fortran code" print*, "WRONG1" isel = hl_gtk_file_chooser_show(chfile, create=FALSE,& & title="Select input file"//c_null_char, filter=filters, & & filter_name=filtnames, wsize=(/ 600_c_int, 400_c_int /), & & edit_filters=TRUE, & & parent=window, all=TRUE) print*, "WRONG2" if (isel == FALSE) return ! No selection made filename = chfile(1) deallocate(chfile) open(37, file=filename, action='read') call hl_gtk_text_view_delete(tedit) do read(37,"(A)",iostat=ios) inln if (ios /= 0) exit call hl_gtk_text_view_insert(tedit, (/ trim(inln)//c_new_line /)) end do close(37) idxs = index(filename, '/', .true.)+1 call gtk_window_set_title(window, trim(filename(idxs:))//c_null_char) ! We manually reset the changed flag as the text box signal handler sets it. file_is_changed = .FALSE. call gtk_widget_set_sensitive(sabut, TRUE) call gtk_widget_set_sensitive(sbut, FALSE) end subroutine open_file subroutine do_open(widget, gdata) bind(c) type(c_ptr), value :: widget, gdata type(c_ptr) :: c_string character(len=200) :: inln integer :: ios integer :: idxs c_string = gtk_file_chooser_get_filename(widget) call convert_c_string(c_string, filename) call g_free(c_string) open(37, file=filename, action='read') call hl_gtk_text_view_delete(tedit) do read(37,"(A)",iostat=ios) inln if (ios /= 0) exit call hl_gtk_text_view_insert(tedit, (/ trim(inln)//c_new_line /)) end do close(37) idxs = index(filename, '/', .true.)+1 call gtk_window_set_title(window, trim(filename(idxs:))//c_null_char) ! We manually reset the changed flag as the text box signal handler sets it. file_is_changed = .FALSE. call gtk_widget_set_sensitive(sabut, TRUE) call gtk_widget_set_sensitive(sbut, FALSE) end subroutine do_open subroutine save_file(widget, gdata) bind(c) type(c_ptr), value :: widget, gdata character(len=200), dimension(:), allocatable :: text integer :: i call hl_gtk_text_view_get_text(tedit, text) open(37, file=filename, action='write') do i = 1, size(text) write(37, '(A)') trim(text(i)) end do close(37) deallocate(text) file_is_changed = .FALSE. call gtk_widget_set_sensitive(widget, false) end subroutine save_file subroutine save_file_as(widget, gdata) bind(c) type(c_ptr), value :: widget, gdata integer(kind=c_int) :: isel character(len=120), dimension(:), allocatable :: chfile character(len=20), dimension(2) :: filters character(len=30), dimension(2) :: filtnames integer :: i character(len=200), dimension(:), allocatable :: text integer :: idxs filters(1) = "*.txt,*.lis" filters(2) = "*.f90" filtnames(1) = "Text files" filtnames(2) = "Fortran code" isel = hl_gtk_file_chooser_show(chfile, create=TRUE,& & title="Select input file"//c_null_char, filter=filters, & & filter_name=filtnames, initial_file=trim(filename)//c_null_char, & & confirm_overwrite=TRUE, all=TRUE, parent=window) if (isel == FALSE) return ! No selection made filename = chfile(1) deallocate(chfile) idxs = index(filename, '/', .true.)+1 call gtk_window_set_title(window, trim(filename(idxs:))//c_null_char) call hl_gtk_text_view_get_text(tedit, text) open(37, file=filename, action='write') do i = 1, size(text) write(37, '(A)') trim(text(i)) end do close(37) deallocate(text) file_is_changed = .FALSE. call gtk_widget_set_sensitive(sbut, false) end subroutine save_file_as subroutine file_edited(widget, gdata) bind(c) type(c_ptr), value :: widget, gdata file_is_changed = .true. if (filename == '') then call gtk_widget_set_sensitive(sabut, TRUE) else call gtk_widget_set_sensitive(sbut, TRUE) end if end subroutine file_edited end module handlers program choosers_demo use handlers implicit none ! Widgets that don't need to be global type(c_ptr) :: base, jb, junk ! Filters for the chooser button character(len=30), dimension(3) :: filters character(len=30), dimension(3) :: filtnames filters(1) = "text/plain" filters(2) = "*.f90" filters(3) = "*" filtnames(1) = "Text files" filtnames(2) = "Fortran code" filtnames(3) = "All files" ! Initialize GTK call gtk_init() ! Create a window and a column box window = hl_gtk_window_new("Choosers Demo"//c_null_char, & & destroy=c_funloc(my_destroy)) base = hl_gtk_box_new() call gtk_container_add(window, base) ! A row of buttons jb = hl_gtk_box_new(horizontal=TRUE, homogeneous=TRUE) call hl_gtk_box_pack(base, jb) junk = hl_gtk_button_new("Open"//c_null_char, clicked=c_funloc(open_file)) !call hl_gtk_box_pack(jb, junk) junk = hl_gtk_file_chooser_button_new(title="Alt-open"//c_null_char, & & filter=filters, filter_name=filtnames, file_set=c_funloc(do_open)) call hl_gtk_box_pack(jb, junk) sbut = hl_gtk_button_new("Save"//c_null_char, clicked=c_funloc(save_file),& & sensitive=FALSE) call hl_gtk_box_pack(jb, sbut) sabut = hl_gtk_button_new("Save as"//c_null_char, clicked=c_funloc(save_file_as), & & sensitive=FALSE) call hl_gtk_box_pack(jb, sabut) ! A multiline text editor in which to display the file. tedit = hl_gtk_text_view_new(jb, editable=TRUE, & & changed=c_funloc(file_edited), ssize = (/ 750_c_int, 400_c_int /) ) call hl_gtk_box_pack(base, jb) ! A quit button junk = hl_gtk_button_new("Quit"//c_null_char, clicked=c_funloc(my_destroy)) call hl_gtk_box_pack(base, junk) ! Realise & enter event loop call gtk_widget_show_all(window) call gtk_main() end program choosers_demo
import Data.Vect fourInts: Vect 4 Int fourInts = [1, 2, 2, 4] sixInts: Vect 6 Int sixInts = [1, 2, 3, 4, 5, 7] tenInts: Vect 10 Int tenInts = fourInts ++ sixInts
import numpy as np import matplotlib.pyplot as plt import h5py import matplotlib as mpl import os import sys import freqent.freqent as fe from datetime import datetime plt.close('all') mpl.rcParams['pdf.fonttype'] = 42 mpl.rcParams['font.size'] = 12 mpl.rcParams['axes.linewidth'] = 2 mpl.rcParams['xtick.major.width'] = 2 mpl.rcParams['ytick.major.width'] = 2 mpl.rcParams['ytick.minor.width'] = 2 if sys.platform == 'linux': dataPath = '/mnt/llmStorage203/Danny/freqent/spinOsc/190709/' savePath = '/media/daniel/storage11/Dropbox/LLM_Danny/freqent/figures/spinOsc/' elif sys.platform == 'darwin': dataPath = '/Volumes/Storage/Danny/freqent/spinOsc/190709/' savePath = '/Users/Danny/Dropbox/LLM_Danny/freqent/figures/spinOsc/' cmap = mpl.cm.get_cmap('tab10') normalize = mpl.colors.Normalize(vmin=-0.5, vmax=9.5) colors = [cmap(normalize(value)) for value in np.arange(11)] ndim = 2 alphas = [1, 3, 9] # alphas = [1, 2, 3, 4, 5, 6, 7, 8, 9] # alphas = [1, 5, 9] fig, ax = plt.subplots(figsize=(5.5, 5)) for file in os.listdir(dataPath): if file.endswith('.hdf5'): if int(file.split('dim')[1][0]) == ndim: with h5py.File(os.path.join(dataPath, file), 'r') as f: nt = len(f['data']['t'][:]) alpha = f['params']['alpha'][()] if alpha in alphas: print(file) s, rhos, w = fe.entropy(f['data']['trajs'][..., nt // 2:], f['params']['dt'][()], sigma=f['params']['sigma_array'][0], return_epf=True) ax.loglog(w[w > 0] / (1 + alpha**2)**0.5, rhos[w > 0].real / np.diff(w)[0], color=colors[int(alpha)], label=r'$\alpha$ = {a}'.format(a=alpha), alpha=0.5) sig = (8 * alpha**2 * w**2) / (2 * np.pi * ((1 + 1j * w)**2 + alpha**2) * ((1 - 1j * w)**2 + alpha**2)) ax.loglog(w[w > 0] / (1 + alpha**2)**0.5, sig[w > 0], '--', color=colors[int(alpha)], lw=2) ax.set(xlabel=r'$\omega / (r^2 + \alpha^2)^{1/2}$', ylabel=r'$\mathcal{E}$', ylim=[1e-5, 1e2], xlim=[1e-1, 1e2]) # xticks=[-20, -10, 0, 10, 20]) # ax.set_aspect(np.diff(ax.set_xlim())[0] / np.diff(ax.set_ylim())[0]) ax.tick_params(which='both', direction='in') ax.legend() # cax, _ = mpl.colorbar.make_axes(ax) # cbar = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=normalize, ticks=alphas) # cbar.ax.set_title(r'$\alpha$') # cbar.ax.tick_params(which='both', direction='in') # fig.savefig(os.path.join(savePath, datetime.now().strftime('%y%m%d') + '_epf_vs_alpha.pdf'), format='pdf') plt.show()
= = Production history = =
#include <nav_msgs/Odometry.h> #include <ros/ros.h> #include <tf2/LinearMath/Quaternion.h> #include <tf2_ros/static_transform_broadcaster.h> #include <Eigen/Core> #include <cmath> #include <iostream> using namespace Eigen; double deg2rad(const double degree) { return degree * M_PI / 180.0; } double rad2deg(const double radian) { return radian * 180.0 / M_PI; } double angle_limit_pi(double angle) { while (angle >= M_PI) { angle -= 2 * M_PI; } while (angle <= -M_PI) { angle += 2 * M_PI; } return angle; } double sdlab_uniform() { double ret = ((double)rand() + 1.0) / ((double)RAND_MAX + 2.0); return ret; } // gauss noise double gauss(double mu, double sigma) { double z = std::sqrt(-2.0 * std::log(sdlab_uniform())) * std::sin(2.0 * M_PI * sdlab_uniform()); return mu + sigma * z; } class FakeSensorPublisher { public: FakeSensorPublisher() : grund_truth(Matrix<double, 3, 1>::Zero()), odom(Matrix<double, 3, 1>::Zero()), gps(Matrix<double, 3, 1>::Zero()) { Q << 0.1, 0, 0, deg2rad(30); Q = Q * Q; R << 2.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, deg2rad(5); R = R * R; ground_truth_pub_ = pnh_.advertise<nav_msgs::Odometry>("grund_truth", 10); odom_pub_ = pnh_.advertise<nav_msgs::Odometry>("odom", 10); gps_pub_ = pnh_.advertise<nav_msgs::Odometry>("gps", 10); previous_stamp_ = ros::Time::now(); timer_ = nh_.createTimer(ros::Duration(0.01), &FakeSensorPublisher::timerCallback, this); } ~FakeSensorPublisher() {} nav_msgs::Odometry inputToNavMsgs(Matrix<double, 3, 1> pose_2d, Matrix<double, 2, 1> input) { nav_msgs::Odometry msg; msg.header.frame_id = "world"; msg.child_frame_id = "odom"; msg.pose.pose.position.x = pose_2d[0]; msg.pose.pose.position.y = pose_2d[1]; tf2::Quaternion quat; quat.setRPY(0.0, 0.0, angle_limit_pi(pose_2d[2])); msg.pose.pose.orientation.w = quat.w(); msg.pose.pose.orientation.x = quat.x(); msg.pose.pose.orientation.y = quat.y(); msg.pose.pose.orientation.z = quat.z(); msg.twist.twist.linear.x = input[0]; msg.twist.twist.angular.z = input[1]; return msg; } void timerCallback(const ros::TimerEvent & e) { ros::Time current_stamp = ros::Time::now(); nav_msgs::Odometry grund_truth_msg; nav_msgs::Odometry odom_msg; nav_msgs::Odometry gps_msgs; Matrix<double, 2, 1> u(1.0, deg2rad(5)); const double dt = current_stamp.toSec() - previous_stamp_.toSec(); // ground truth ROS_INFO("delta time: %f", dt); grund_truth = motionModel(grund_truth, u, dt); grund_truth_msg = inputToNavMsgs(grund_truth, u); // dead recogning Matrix<double, 2, 1> ud = motionNoise(u, Q); odom = motionModel(odom, ud, dt); odom_msg = inputToNavMsgs(odom, ud); // observation Matrix<double, 3, 1> gps = observationNoise(grund_truth, R); gps_msgs = inputToNavMsgs(gps, Matrix<double, 2, 1>::Zero()); ground_truth_pub_.publish(grund_truth_msg); odom_pub_.publish(odom_msg); gps_pub_.publish(gps_msgs); previous_stamp_ = current_stamp; } Matrix<double, 3, 1> motionModel(Matrix<double, 3, 1> x, Matrix<double, 2, 1> u, double dt) { Matrix<double, 3, 3> F = Matrix<double, 3, 3>::Identity(); Matrix<double, 3, 2> B; B << dt * std::cos(x[2]), 0, dt * std::sin(x[2]), 0, 0, dt; x = F * x + B * u; x[2] = angle_limit_pi(x[2]); return x; } Matrix<double, 2, 1> motionNoise(Matrix<double, 2, 1> u, Matrix<double, 2, 2> Q) { Matrix<double, 2, 1> uw(gauss(0.0, Q(0, 0)), gauss(0.0, Q(1, 1))); return u + uw; } Matrix<double, 3, 1> observationNoise(Matrix<double, 3, 1> x, Matrix<double, 3, 3> R) { Matrix<double, 3, 1> xw(gauss(0.0, R(0, 0)), gauss(0.0, R(1, 1)), gauss(0.0, R(2, 2))); return x + xw; } private: ros::NodeHandle nh_{}; ros::NodeHandle pnh_{"~"}; ros::Timer timer_; ros::Time previous_stamp_; ros::Publisher ground_truth_pub_; ros::Publisher odom_pub_; ros::Publisher gps_pub_; Matrix<double, 2, 2> Q; Matrix<double, 3, 3> R; Matrix<double, 3, 1> grund_truth; Matrix<double, 3, 1> odom; Matrix<double, 3, 1> gps; }; int main(int argc, char ** argv) { ros::init(argc, argv, "fake_sensor_publisher_node"); FakeSensorPublisher fake_sensor_publisher; ros::spin(); return 0; }
lemma lmeasurable_open: "bounded S \<Longrightarrow> open S \<Longrightarrow> S \<in> lmeasurable"
using Test using Comonicon.PATH using Comonicon.Configurations using Comonicon.Configurations: Install, Application, SysImg, Download, Precompile module XYZ end @test read_configs(XYZ) == Configurations.Comonicon( name="xyz", install = Install( path = "~/.julia", completion = true, quiet = false, compile = "yes", optimize = 2, ), sysimg = nothing, download = nothing, application = nothing, ) @test read_configs(XYZ; name="zzz") == Configurations.Comonicon( name="zzz", install = Install( path = "~/.julia", completion = true, quiet = false, compile = "yes", optimize = 2, ), sysimg = nothing, download = nothing, application = nothing, ) @test read_configs(XYZ; path="mypath") == Configurations.Comonicon( name="xyz", install = Install( path = "mypath", completion = true, quiet = false, compile = "yes", optimize = 2, ), sysimg = nothing, download = nothing, application = nothing, ) @test_throws ArgumentError read_configs(XYZ; filter_stdlibs=true) @test_throws ArgumentError Application(;path=pwd()) @test_throws ArgumentError SysImg(;path=pwd()) read_configs(XYZ; user="Roger-luo", repo="Foo") == Configurations.Comonicon( name="xyz", install = Install( path = "~/.julia", completion = true, quiet = false, compile = "yes", optimize = 2, ), sysimg = nothing, download = Download( user="Roger-luo", repo="Foo", ), application = nothing, ) @test_throws ArgumentError read_configs(XYZ; abc=2) @test read_configs(PATH.project("test", "Foo", "Comonicon.toml")) == Configurations.Comonicon( name = "foo", install = Install( path = "~/.julia", completion = true, quiet = false, compile = "min", optimize = 2, ), sysimg = SysImg( path = "deps", incremental = true, filter_stdlibs = false, cpu_target = "native", precompile = Precompile( execution_file = ["precopmile.jl"], statements_file = String[], ), ), download = Download( host = "github.com", user = "Roger-luo", repo = "Foo.jl", ), application = nothing, ) @test_throws ErrorException read_configs(PATH.project("test"))
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import topology.urysohns_lemma import topology.continuous_function.bounded /-! # Metrizability of a regular topological space with second countable topology In this file we define metrizable topological spaces, i.e., topological spaces for which there exists a metric space structure that generates the same topology. We also show that a regular topological space with second countable topology `X` is metrizable. First we prove that `X` can be embedded into `l^∞`, then use this embedding to pull back the metric space structure. -/ open set filter metric open_locale bounded_continuous_function filter topological_space namespace topological_space variables {ι X Y : Type*} {π : ι → Type*} [topological_space X] [topological_space Y] [fintype ι] [Π i, topological_space (π i)] /-- A topological space is *pseudo metrizable* if there exists a pseudo metric space structure compatible with the topology. To endow such a space with a compatible distance, use `letI : pseudo_metric_space X := topological_space.pseudo_metrizable_space_pseudo_metric X`. -/ class pseudo_metrizable_space (X : Type*) [t : topological_space X] : Prop := (exists_pseudo_metric : ∃ (m : pseudo_metric_space X), m.to_uniform_space.to_topological_space = t) @[priority 100] instance _root_.pseudo_metric_space.to_pseudo_metrizable_space {X : Type*} [m : pseudo_metric_space X] : pseudo_metrizable_space X := ⟨⟨m, rfl⟩⟩ /-- Construct on a metrizable space a metric compatible with the topology. -/ noncomputable def pseudo_metrizable_space_pseudo_metric (X : Type*) [topological_space X] [h : pseudo_metrizable_space X] : pseudo_metric_space X := h.exists_pseudo_metric.some.replace_topology h.exists_pseudo_metric.some_spec.symm instance pseudo_metrizable_space_prod [pseudo_metrizable_space X] [pseudo_metrizable_space Y] : pseudo_metrizable_space (X × Y) := begin letI : pseudo_metric_space X := pseudo_metrizable_space_pseudo_metric X, letI : pseudo_metric_space Y := pseudo_metrizable_space_pseudo_metric Y, apply_instance end /-- Given an inducing map of a topological space into a pseudo metrizable space, the source space is also pseudo metrizable. -/ lemma _root_.inducing.pseudo_metrizable_space [pseudo_metrizable_space Y] {f : X → Y} (hf : inducing f) : pseudo_metrizable_space X := begin letI : pseudo_metric_space Y := pseudo_metrizable_space_pseudo_metric Y, exact ⟨⟨hf.comap_pseudo_metric_space, rfl⟩⟩ end instance pseudo_metrizable_space.subtype [pseudo_metrizable_space X] (s : set X) : pseudo_metrizable_space s := inducing_coe.pseudo_metrizable_space instance pseudo_metrizable_space_pi [Π i, pseudo_metrizable_space (π i)] : pseudo_metrizable_space (Π i, π i) := by { letI := λ i, pseudo_metrizable_space_pseudo_metric (π i), apply_instance } /-- A topological space is metrizable if there exists a metric space structure compatible with the topology. To endow such a space with a compatible distance, use `letI : metric_space X := topological_space.metrizable_space_metric X` -/ class metrizable_space (X : Type*) [t : topological_space X] : Prop := (exists_metric : ∃ (m : metric_space X), m.to_uniform_space.to_topological_space = t) @[priority 100] instance _root_.metric_space.to_metrizable_space {X : Type*} [m : metric_space X] : metrizable_space X := ⟨⟨m, rfl⟩⟩ @[priority 100] instance metrizable_space.to_pseudo_metrizable_space [h : metrizable_space X] : pseudo_metrizable_space X := ⟨let ⟨m, hm⟩ := h.1 in ⟨m.to_pseudo_metric_space, hm⟩⟩ /-- Construct on a metrizable space a metric compatible with the topology. -/ noncomputable def metrizable_space_metric (X : Type*) [topological_space X] [h : metrizable_space X] : metric_space X := h.exists_metric.some.replace_topology h.exists_metric.some_spec.symm @[priority 100] instance t2_space_of_metrizable_space [metrizable_space X] : t2_space X := by { letI : metric_space X := metrizable_space_metric X, apply_instance } instance metrizable_space_prod [metrizable_space X] [metrizable_space Y] : metrizable_space (X × Y) := begin letI : metric_space X := metrizable_space_metric X, letI : metric_space Y := metrizable_space_metric Y, apply_instance end /-- Given an embedding of a topological space into a metrizable space, the source space is also metrizable. -/ lemma _root_.embedding.metrizable_space [metrizable_space Y] {f : X → Y} (hf : embedding f) : metrizable_space X := begin letI : metric_space Y := metrizable_space_metric Y, exact ⟨⟨hf.comap_metric_space f, rfl⟩⟩ end instance metrizable_space.subtype [metrizable_space X] (s : set X) : metrizable_space s := embedding_subtype_coe.metrizable_space instance metrizable_space_pi [Π i, metrizable_space (π i)] : metrizable_space (Π i, π i) := by { letI := λ i, metrizable_space_metric (π i), apply_instance } variables (X) [regular_space X] [second_countable_topology X] /-- A regular topological space with second countable topology can be embedded into `l^∞ = ℕ →ᵇ ℝ`. -/ lemma exists_embedding_l_infty : ∃ f : X → (ℕ →ᵇ ℝ), embedding f := begin haveI : normal_space X := normal_space_of_regular_second_countable X, -- Choose a countable basis, and consider the set `s` of pairs of set `(U, V)` such that `U ∈ B`, -- `V ∈ B`, and `closure U ⊆ V`. rcases exists_countable_basis X with ⟨B, hBc, -, hB⟩, set s : set (set X × set X) := {UV ∈ B ×ˢ B| closure UV.1 ⊆ UV.2}, -- `s` is a countable set. haveI : encodable s := ((hBc.prod hBc).mono (inter_subset_left _ _)).to_encodable, -- We don't have the space of bounded (possibly discontinuous) functions, so we equip `s` -- with the discrete topology and deal with `s →ᵇ ℝ` instead. letI : topological_space s := ⊥, haveI : discrete_topology s := ⟨rfl⟩, suffices : ∃ f : X → (s →ᵇ ℝ), embedding f, { rcases this with ⟨f, hf⟩, exact ⟨λ x, (f x).extend (encodable.encode' s) 0, (bounded_continuous_function.isometry_extend (encodable.encode' s) (0 : ℕ →ᵇ ℝ)).embedding.comp hf⟩ }, have hd : ∀ UV : s, disjoint (closure UV.1.1) (UV.1.2ᶜ) := λ UV, disjoint_compl_right.mono_right (compl_subset_compl.2 UV.2.2), -- Choose a sequence of `εₙ > 0`, `n : s`, that is bounded above by `1` and tends to zero -- along the `cofinite` filter. obtain ⟨ε, ε01, hε⟩ : ∃ ε : s → ℝ, (∀ UV, ε UV ∈ Ioc (0 : ℝ) 1) ∧ tendsto ε cofinite (𝓝 0), { rcases pos_sum_of_encodable zero_lt_one s with ⟨ε, ε0, c, hεc, hc1⟩, refine ⟨ε, λ UV, ⟨ε0 UV, _⟩, hεc.summable.tendsto_cofinite_zero⟩, exact (le_has_sum hεc UV $ λ _ _, (ε0 _).le).trans hc1 }, /- For each `UV = (U, V) ∈ s` we use Urysohn's lemma to choose a function `f UV` that is equal to zero on `U` and is equal to `ε UV` on the complement to `V`. -/ have : ∀ UV : s, ∃ f : C(X, ℝ), eq_on f 0 UV.1.1 ∧ eq_on f (λ _, ε UV) UV.1.2ᶜ ∧ ∀ x, f x ∈ Icc 0 (ε UV), { intro UV, rcases exists_continuous_zero_one_of_closed is_closed_closure (hB.is_open UV.2.1.2).is_closed_compl (hd UV) with ⟨f, hf₀, hf₁, hf01⟩, exact ⟨ε UV • f, λ x hx, by simp [hf₀ (subset_closure hx)], λ x hx, by simp [hf₁ hx], λ x, ⟨mul_nonneg (ε01 _).1.le (hf01 _).1, mul_le_of_le_one_right (ε01 _).1.le (hf01 _).2⟩⟩ }, choose f hf0 hfε hf0ε, have hf01 : ∀ UV x, f UV x ∈ Icc (0 : ℝ) 1, from λ UV x, Icc_subset_Icc_right (ε01 _).2 (hf0ε _ _), /- The embedding is given by `F x UV = f UV x`. -/ set F : X → s →ᵇ ℝ := λ x, ⟨⟨λ UV, f UV x, continuous_of_discrete_topology⟩, 1, λ UV₁ UV₂, real.dist_le_of_mem_Icc_01 (hf01 _ _) (hf01 _ _)⟩, have hF : ∀ x UV, F x UV = f UV x := λ _ _, rfl, refine ⟨F, embedding.mk' _ (λ x y hxy, _) (λ x, le_antisymm _ _)⟩, { /- First we prove that `F` is injective. Indeed, if `F x = F y` and `x ≠ y`, then we can find `(U, V) ∈ s` such that `x ∈ U` and `y ∉ V`, hence `F x UV = 0 ≠ ε UV = F y UV`. -/ refine not_not.1 (λ Hne, _), -- `by_contra Hne` timeouts rcases hB.mem_nhds_iff.1 (is_open_ne.mem_nhds Hne) with ⟨V, hVB, hxV, hVy⟩, rcases hB.exists_closure_subset (hB.mem_nhds hVB hxV) with ⟨U, hUB, hxU, hUV⟩, set UV : ↥s := ⟨(U, V), ⟨hUB, hVB⟩, hUV⟩, apply (ε01 UV).1.ne, calc (0 : ℝ) = F x UV : (hf0 UV hxU).symm ... = F y UV : by rw hxy ... = ε UV : hfε UV (λ h : y ∈ V, hVy h rfl) }, { /- Now we prove that each neighborhood `V` of `x : X` include a preimage of a neighborhood of `F x` under `F`. Without loss of generality, `V` belongs to `B`. Choose `U ∈ B` such that `x ∈ V` and `closure V ⊆ U`. Then the preimage of the `(ε (U, V))`-neighborhood of `F x` is included by `V`. -/ refine ((nhds_basis_ball.comap _).le_basis_iff hB.nhds_has_basis).2 _, rintro V ⟨hVB, hxV⟩, rcases hB.exists_closure_subset (hB.mem_nhds hVB hxV) with ⟨U, hUB, hxU, hUV⟩, set UV : ↥s := ⟨(U, V), ⟨hUB, hVB⟩, hUV⟩, refine ⟨ε UV, (ε01 UV).1, λ y (hy : dist (F y) (F x) < ε UV), _⟩, replace hy : dist (F y UV) (F x UV) < ε UV, from (bounded_continuous_function.dist_coe_le_dist _).trans_lt hy, contrapose! hy, rw [hF, hF, hfε UV hy, hf0 UV hxU, pi.zero_apply, dist_zero_right], exact le_abs_self _ }, { /- Finally, we prove that `F` is continuous. Given `δ > 0`, consider the set `T` of `(U, V) ∈ s` such that `ε (U, V) ≥ δ`. Since `ε` tends to zero, `T` is finite. Since each `f` is continuous, we can choose a neighborhood such that `dist (F y (U, V)) (F x (U, V)) ≤ δ` for any `(U, V) ∈ T`. For `(U, V) ∉ T`, the same inequality is true because both `F y (U, V)` and `F x (U, V)` belong to the interval `[0, ε (U, V)]`. -/ refine (nhds_basis_closed_ball.comap _).ge_iff.2 (λ δ δ0, _), have h_fin : {UV : s | δ ≤ ε UV}.finite, by simpa only [← not_lt] using hε (gt_mem_nhds δ0), have : ∀ᶠ y in 𝓝 x, ∀ UV, δ ≤ ε UV → dist (F y UV) (F x UV) ≤ δ, { refine (eventually_all_finite h_fin).2 (λ UV hUV, _), exact (f UV).continuous.tendsto x (closed_ball_mem_nhds _ δ0) }, refine this.mono (λ y hy, (bounded_continuous_function.dist_le δ0.le).2 $ λ UV, _), cases le_total δ (ε UV) with hle hle, exacts [hy _ hle, (real.dist_le_of_mem_Icc (hf0ε _ _) (hf0ε _ _)).trans (by rwa sub_zero)] } end /-- *Urysohn's metrization theorem* (Tychonoff's version): a regular topological space with second countable topology `X` is metrizable, i.e., there exists a metric space structure that generates the same topology. -/ lemma metrizable_space_of_regular_second_countable : metrizable_space X := let ⟨f, hf⟩ := exists_embedding_l_infty X in hf.metrizable_space instance : metrizable_space ennreal := metrizable_space_of_regular_second_countable ennreal end topological_space
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.ring.equiv import group_theory.group_action.group import ring_theory.subring.basic /-! # Group action on rings This file defines the typeclass of monoid acting on semirings `mul_semiring_action M R`, and the corresponding typeclass of invariant subrings. Note that `algebra` does not satisfy the axioms of `mul_semiring_action`. ## Implementation notes There is no separate typeclass for group acting on rings, group acting on fields, etc. They are all grouped under `mul_semiring_action`. ## Tags group action, invariant subring -/ universes u v open_locale big_operators /-- Typeclass for multiplicative actions by monoids on semirings. This combines `distrib_mul_action` with `mul_distrib_mul_action`. -/ class mul_semiring_action (M : Type u) (R : Type v) [monoid M] [semiring R] extends distrib_mul_action M R := (smul_one : ∀ (g : M), (g • 1 : R) = 1) (smul_mul : ∀ (g : M) (x y : R), g • (x * y) = (g • x) * (g • y)) section semiring variables (M G : Type u) [monoid M] [group G] variables (A R S F : Type v) [add_monoid A] [semiring R] [comm_semiring S] [division_ring F] -- note we could not use `extends` since these typeclasses are made with `old_structure_cmd` @[priority 100] instance mul_semiring_action.to_mul_distrib_mul_action [h : mul_semiring_action M R] : mul_distrib_mul_action M R := { ..h } /-- Each element of the monoid defines a semiring homomorphism. -/ @[simps] def mul_semiring_action.to_ring_hom [mul_semiring_action M R] (x : M) : R →+* R := { .. mul_distrib_mul_action.to_monoid_hom R x, .. distrib_mul_action.to_add_monoid_hom R x } theorem to_ring_hom_injective [mul_semiring_action M R] [has_faithful_scalar M R] : function.injective (mul_semiring_action.to_ring_hom M R) := λ m₁ m₂ h, eq_of_smul_eq_smul $ λ r, ring_hom.ext_iff.1 h r /-- Each element of the group defines a semiring isomorphism. -/ @[simps] def mul_semiring_action.to_ring_equiv [mul_semiring_action G R] (x : G) : R ≃+* R := { .. distrib_mul_action.to_add_equiv R x, .. mul_semiring_action.to_ring_hom G R x } section variables {M G R} /-- A stronger version of `submonoid.distrib_mul_action`. -/ instance submonoid.mul_semiring_action [mul_semiring_action M R] (H : submonoid M) : mul_semiring_action H R := { smul := (•), .. H.mul_distrib_mul_action, .. H.distrib_mul_action } /-- A stronger version of `subgroup.distrib_mul_action`. -/ instance subgroup.mul_semiring_action [mul_semiring_action G R] (H : subgroup G) : mul_semiring_action H R := H.to_submonoid.mul_semiring_action /-- A stronger version of `subsemiring.distrib_mul_action`. -/ instance subsemiring.mul_semiring_action {R'} [semiring R'] [mul_semiring_action R' R] (H : subsemiring R') : mul_semiring_action H R := H.to_submonoid.mul_semiring_action /-- A stronger version of `subring.distrib_mul_action`. -/ instance subring.mul_semiring_action {R'} [ring R'] [mul_semiring_action R' R] (H : subring R') : mul_semiring_action H R := H.to_subsemiring.mul_semiring_action end section simp_lemmas variables {M G A R F} attribute [simp] smul_one smul_mul' smul_zero smul_add /-- Note that `smul_inv'` refers to the group case, and `smul_inv` has an additional inverse on `x`. -/ @[simp] lemma smul_inv'' [mul_semiring_action M F] (x : M) (m : F) : x • m⁻¹ = (x • m)⁻¹ := (mul_semiring_action.to_ring_hom M F x).map_inv _ end simp_lemmas end semiring section ring variables (M : Type u) [monoid M] {R : Type v} [ring R] [mul_semiring_action M R] variables (S : subring R) open mul_action /-- A typeclass for subrings invariant under a `mul_semiring_action`. -/ class is_invariant_subring : Prop := (smul_mem : ∀ (m : M) {x : R}, x ∈ S → m • x ∈ S) instance is_invariant_subring.to_mul_semiring_action [is_invariant_subring M S] : mul_semiring_action M S := { smul := λ m x, ⟨m • x, is_invariant_subring.smul_mem m x.2⟩, one_smul := λ s, subtype.eq $ one_smul M s, mul_smul := λ m₁ m₂ s, subtype.eq $ mul_smul m₁ m₂ s, smul_add := λ m s₁ s₂, subtype.eq $ smul_add m s₁ s₂, smul_zero := λ m, subtype.eq $ smul_zero m, smul_one := λ m, subtype.eq $ smul_one m, smul_mul := λ m s₁ s₂, subtype.eq $ smul_mul' m s₁ s₂ } end ring
# Singular value decomposition ### Singular value decomposition The singular value decomposition is based on the following geometric observation: > The image of the unit $n$-sphere under a $m\times n$ matrix is a hyperellipse in $\mathbb{R}^m$. ### Singular value decomposition Recall an $m\times n$ matrix represents a linear tranformation: $$T:V\to W$$ We would like to make a choice of bases for both $V$ and $W$, such that the matrix representing $T$ is as simple as possible. When $m=n$ we could use the eigenvalue decomposition. We mimick this process. > **DEFINITION.** A _singular value decomposition_ of a matrix $A$ is a factorization: $$M=U\Sigma V^*$$ where $U$ is an $m\times m$ unitary matrix, $V$ is an $n\times n$ unitary matrix and $\Sigma$ is an $m\times n$ diagonal matrix. The columns of $U$ are called the _left singular vectors_ of $M$. The columns of $V$ are called the _right singular vectors_ of $M$. The entries of $\Sigma$ are called the _singular values_ of $M$. ```julia svd([1 2 3 4; 5 6 7 8]) ``` ( 2x2 Array{Float64,2}: -0.376168 -0.926551 -0.926551 0.376168, [14.227407412633742,1.2573298353791105], 4x2 Array{Float64,2}: -0.352062 0.758981 -0.443626 0.321242 -0.53519 -0.116498 -0.626754 -0.554238) ### ED vs SVD > __*Question.*__ If $M$ is normal (hence square), is its singular value decomposition equal to its eigenvalue decomposition? ```julia svd([2 1; 1 2]) ``` ( 2x2 Array{Float64,2}: -0.707107 -0.707107 -0.707107 0.707107, [2.9999999999999996,1.0000000000000002], 2x2 Array{Float64,2}: -0.707107 -0.707107 -0.707107 0.707107) ```julia eig([2 1; 1 2]) ``` ([1.0,3.0], 2x2 Array{Float64,2}: -0.707107 0.707107 0.707107 0.707107) ### Computing singular value decompositions If $M$ is $m\times n$, then $M^*M$ is $n\times n$ and $MM^*$ is $m\times m$. Both are normal, hence by the Spectral Theorem: \begin{align} MM^* &= VD_1 V^*\\ M^*M &= U D_2 U^*\end{align} Where $D_1$ and $D_2$ are diagonal matrices the same nonzero entries counted with multiplicity. > **THEOREM.** Every matrix has a singular value decomposition. Furthermore, the singular values are uniquely determined. This states that _every_ linear transformation is a rotation, followed by certain scalings, followed by a rotation. **Nota Bene:** The theorem does _not_ say that the singular value decomposition is unique, only that it exists _and_ that the singular values are unique. > **THEOREM.** The singular value decomposition of a normal matrix is equivalent to the eigenvalue decomposition if and only if the matrix is positive semi-definite. **Proof.** It is clear that the left and right singular vectors are equal to the eigenvectors (since $A$ is assumed normal). Further a matrix is positive semi-definite if and only if its eigenvalues are nonnegative. The singular values are precisely the positive square roots of the squares of the eigenvalues. ```julia M = [1 1 1; 1 0 1] svd(M) ``` ( 2x2 Array{Float64,2}: -0.788205 -0.615412 -0.615412 0.788205, [2.135779205069857,0.6621534468619564], 3x2 Array{Float64,2}: -0.657192 0.260956 -0.369048 -0.92941 -0.657192 0.260956) Observe that the singular vectors are orthonormal, and the $2$-norm of $M$ is always the largest singular value: ```julia norm(M) ``` 2.135779205069857 The proof of Existence of a singular value decomposition will proceed inductively on the number of columns of the matrix. **Proof of Existence of SVD** Let $\sigma_1=\|A\|_2$. By compactness, there are vectors $\mathbf{v}_1\in\mathbb{C}^n$ and $\mathbf{u}_1\in\mathbb{C}^m$ satsifying: $$\|\mathbf{v}_1\|_2 = \|\mathbf{u}\|_2=1,\quad A \mathbf{v}_1 = \sigma_1 \mathbf{u}_1.$$ Extend both of these sets to orthonormal bases of $\mathbb{C}^n$ and $\mathbb{C}^m$, and let $V_1$ and $U_1$ denote the corresponding unitary matrices with these vectors as columns. Then: $$U_1^*A V_1 = S = \begin{bmatrix} \sigma_1 & \mathbf{w}^* \\ \mathbf{0} & B\end{bmatrix}.$$ We check: $$\left\|\begin{bmatrix} \sigma_1 & \mathbf{w}^*\\ \mathbf{0} & B\end{bmatrix}\begin{bmatrix} \sigma_1\\ \mathbf{w}\end{bmatrix}\right\|_2 \geq \sigma_1^2 + \mathbf{w}^*\mathbf{w} = \left(\sigma_1^2+\mathbf{w}^*\mathbf{w}\right)^{1/2}\left\|\begin{bmatrix} \sigma_1\\ \mathbf{w}\end{bmatrix}\right\|_2,$$ Thus $\|S\|_2\geq \left(\sigma_1^2 + \mathbf{w}^*\mathbf{w}\right)^{1/2}$. Since $U_1$ and $V_1$ are unitary, we know $\|S\|_2=\|A\|_2=\sigma_1$, hence $\mathbf{w}=0$. If either $n$ or $m$ are equal to $1$, we are done. Otherwise, $B$ describes the action of the matrix $A$ on the subspace orthogonal to $\mathbf{v}_1$. By induction, $B=U_2 \sigma_2 V_2^*$, and: $$A=U_1 \begin{bmatrix} 1 & \mathbf{0} \\ \mathbf{0} & U_2\end{bmatrix} \begin{bmatrix} \sigma_1 & \mathbf{0}\\ \mathbf{0} & \Sigma_2\end{bmatrix}\begin{bmatrix} 1 & \mathbf{0}\\ \mathbf{0} & V_2\end{bmatrix}^* V_1^*.$$ **Proof of Uniqueness of SVD** The uniqueness of $\sigma_1$ is clear by maximality, i.e. $\sigma_1 = \|A\|_2$. Proceeding inductively, by noting that once $\sigma_1,\mathbf{u}_1$ and $\mathbf{v}_1$ are determined the remainder of the SVD is determined by the action of $A$ on the space orthogonal to $\mathbf{v}_1$ --- which is uniquely defined up to sign. Continuing, one can show that: $$\sigma_1\geq \sigma_2 \geq \cdots \geq \sigma_k,$$ where $k=\min(m,n)$. ### Image compression Singular value decompositions can be used to represent data efficiently. Suppose, for instance, that we wish to transmit the following image: which consists of an array of $25\times 15$ black or white pixels. ```julia M = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1; 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1; 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1; 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1; 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1; 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1; ] ``` 25x15 Array{Int64,2}: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ```julia U, s, V = svd(M) ``` ( 25x15 Array{Float64,2}: -0.254727 -0.183563 -0.0376665 … 6.66134e-17 -2.498e-17 -0.254727 -0.183563 -0.0376665 -9.07659e-18 3.01407e-17 -0.254727 -0.183563 -0.0376665 8.27064e-18 4.66705e-17 -0.254727 -0.183563 -0.0376665 8.27064e-18 -2.09394e-17 -0.254727 -0.183563 -0.0376665 -2.57652e-17 3.39131e-17 -0.0872463 0.192717 -0.349163 … -6.85833e-18 -4.0722e-17 -0.0872463 0.192717 -0.349163 -1.42425e-16 2.71824e-17 -0.0872463 0.192717 -0.349163 -1.55019e-16 1.47039e-17 -0.184232 0.22116 0.168101 0.00349757 -1.80873e-16 -0.184232 0.22116 0.168101 -0.161402 2.14801e-16 -0.184232 0.22116 0.168101 … 0.934561 -6.56966e-16 -0.184232 0.22116 0.168101 -0.129443 0.563142 -0.184232 0.22116 0.168101 -0.129443 0.591329 -0.184232 0.22116 0.168101 -0.129443 -0.288618 -0.184232 0.22116 0.168101 -0.129443 -0.288618 -0.184232 0.22116 0.168101 … -0.129443 -0.288618 -0.184232 0.22116 0.168101 -0.129443 -0.288618 -0.0872463 0.192717 -0.349163 1.01178e-16 8.44459e-18 -0.0872463 0.192717 -0.349163 1.01178e-16 8.44459e-18 -0.0872463 0.192717 -0.349163 1.01178e-16 8.44459e-18 -0.254727 -0.183563 -0.0376665 … -1.37533e-17 1.70323e-18 -0.254727 -0.183563 -0.0376665 -1.37533e-17 1.70323e-18 -0.254727 -0.183563 -0.0376665 -1.37533e-17 1.70323e-18 -0.254727 -0.183563 -0.0376665 -1.37533e-17 1.70323e-18 -0.254727 -0.183563 -0.0376665 -1.37533e-17 1.70323e-18, [14.724253056565878,5.21662293482156,3.314093704484553,5.7852058868648e-16,4.6490282558955e-16,5.732681207036566e-17,6.996891466623839e-32,1.6436603393843544e-32,1.1148911652143973e-47,1.1717746418956173e-48,3.8056938872156064e-49,1.7224044350991095e-64,6.3231106197103315e-65,7.772568552445547e-66,2.4881106284937148e-82], 15x15 Array{Float64,2}: -0.321159 0.251333 -0.28929 … 0.0 -0.0 -0.321159 0.251333 -0.28929 2.41611e-17 -7.6724e-17 -0.172998 -0.351882 -0.113656 2.75329e-17 2.81778e-17 -0.172998 -0.351882 -0.113656 0.0311947 1.67756e-17 -0.172998 -0.351882 -0.113656 -0.0403481 -1.32331e-16 -0.285607 0.0296757 0.342853 … -0.0400428 4.64596e-17 -0.285607 0.0296757 0.342853 -0.0268824 -6.83068e-17 -0.285607 0.0296757 0.342853 0.0360895 2.51e-17 -0.285607 0.0296757 0.342853 0.208092 5.4074e-17 -0.285607 0.0296757 0.342853 -0.177257 -6.40776e-17 -0.172998 -0.351882 -0.113656 … 0.714254 1.09588e-16 -0.172998 -0.351882 -0.113656 -0.635663 -6.27794e-17 -0.172998 -0.351882 -0.113656 -0.0694369 9.42999e-18 -0.321159 0.251333 -0.28929 4.8697e-18 0.707107 -0.321159 0.251333 -0.28929 4.8697e-18 -0.707107 ) ```julia u = [U[:,1] U[:,2] U[:,3]] ``` 25x3 Array{Float64,2}: -0.254727 -0.183563 -0.0376665 -0.254727 -0.183563 -0.0376665 -0.254727 -0.183563 -0.0376665 -0.254727 -0.183563 -0.0376665 -0.254727 -0.183563 -0.0376665 -0.0872463 0.192717 -0.349163 -0.0872463 0.192717 -0.349163 -0.0872463 0.192717 -0.349163 -0.184232 0.22116 0.168101 -0.184232 0.22116 0.168101 -0.184232 0.22116 0.168101 -0.184232 0.22116 0.168101 -0.184232 0.22116 0.168101 -0.184232 0.22116 0.168101 -0.184232 0.22116 0.168101 -0.184232 0.22116 0.168101 -0.184232 0.22116 0.168101 -0.0872463 0.192717 -0.349163 -0.0872463 0.192717 -0.349163 -0.0872463 0.192717 -0.349163 -0.254727 -0.183563 -0.0376665 -0.254727 -0.183563 -0.0376665 -0.254727 -0.183563 -0.0376665 -0.254727 -0.183563 -0.0376665 -0.254727 -0.183563 -0.0376665 ```julia v = [V[:,1] V[:,2] V[:,3]] ``` 15x3 Array{Float64,2}: -0.321159 0.251333 -0.28929 -0.321159 0.251333 -0.28929 -0.172998 -0.351882 -0.113656 -0.172998 -0.351882 -0.113656 -0.172998 -0.351882 -0.113656 -0.285607 0.0296757 0.342853 -0.285607 0.0296757 0.342853 -0.285607 0.0296757 0.342853 -0.285607 0.0296757 0.342853 -0.285607 0.0296757 0.342853 -0.172998 -0.351882 -0.113656 -0.172998 -0.351882 -0.113656 -0.172998 -0.351882 -0.113656 -0.321159 0.251333 -0.28929 -0.321159 0.251333 -0.28929 ```julia D = diagm(s) d = [D[:,1] D[:,2] D[:,3]] f = [d[1,:]; d[2,:]; d[3,:]] ``` 3x3 Array{Float64,2}: 14.7243 0.0 0.0 0.0 5.21662 0.0 0.0 0.0 3.31409 ```julia *(u,*(f,transpose(v))) ``` 25x15 Array{Float64,2}: 1.0 1.0 1.0 1.0 … 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 4.996e-16 2.77556e-16 … 3.88578e-16 3.88578e-16 1.0 1.0 1.0 1.0 4.996e-16 2.77556e-16 3.88578e-16 3.88578e-16 1.0 1.0 1.0 1.0 4.996e-16 2.77556e-16 3.88578e-16 3.88578e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 … 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 … 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 9.29812e-16 9.57567e-16 8.60423e-16 8.60423e-16 1.0 1.0 1.0 1.0 4.996e-16 2.77556e-16 3.88578e-16 3.88578e-16 1.0 1.0 1.0 1.0 4.996e-16 2.77556e-16 3.88578e-16 3.88578e-16 1.0 1.0 1.0 1.0 4.996e-16 2.77556e-16 3.88578e-16 3.88578e-16 1.0 1.0 1.0 1.0 1.0 1.0 … 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ### Collaborative filtering Amy, Bob, Charlie and David rate the following six movies from 1 to 5: $$\begin{array}{ccccl} \text{Amy} & \text{Bob} & \text{Charlie} & \text{David} & \\ 1 & 1 & 5 & 4 & \text{The Dark Knight}\\ 2 & 1 & 4 & 4 & \text{The Amazing Spiderman}\\ 4 & 5 & 2 & 1 & \text{Love Actually}\\ 5 & 4 & 2 & 1 & \text{Bridget Jones's Diary}\\ 4 & 5 & 1 & 2 & \text{Pretty Woman}\\ 1 & 2 & 5 & 4 & \text{Superman 2}\end{array}$$ ```julia A = [1 1 5 4; 2 1 4 5; 4 5 2 1; 5 4 2 1; 4 5 1 2; 1 2 5 5] ``` 6x4 Array{Int64,2}: 1 1 5 4 2 1 4 5 4 5 2 1 5 4 2 1 4 5 1 2 1 2 5 5 ```julia M = reshape(A, 1, 24) ``` 1x24 Array{Int64,2}: 1 2 4 5 4 1 1 1 5 4 5 2 5 4 2 2 1 5 4 5 1 1 2 5 ```julia m = mean(M) ``` 3.0 We compute the mean-centered ratings matrix: ```julia B = m*ones(6,4) C = A-B ``` 6x4 Array{Float64,2}: -2.0 -2.0 2.0 1.0 -1.0 -2.0 1.0 2.0 1.0 2.0 -1.0 -2.0 2.0 1.0 -1.0 -2.0 1.0 2.0 -2.0 -1.0 -2.0 -1.0 2.0 2.0 We compute the singular value decomposition of the mean-centered ratings matrix: ```julia p, q, r = svd(C) ``` ( 6x4 Array{Float64,2}: -0.446401 -0.371748 -0.420224 -0.601501 -0.390517 -4.68375e-15 0.562549 3.60822e-16 0.390517 4.68375e-15 -0.562549 -2.77556e-17 0.384996 -0.601501 0.0833694 0.371748 0.384996 0.601501 0.0833694 -0.371748 -0.446401 0.371748 -0.420224 0.601501 , [7.785085687110693,1.6180339887498958,1.5467517073998112,0.6180339887498946], 4x4 Array{Float64,2}: 0.478046 -0.371748 0.52103 0.601501 0.52103 0.601501 -0.478046 0.371748 -0.478046 -0.371748 -0.52103 0.601501 -0.52103 0.601501 0.478046 0.371748) We observe that the first singular value is significantly larger than the rest. This indicates that the mean centered ratings matrix is well-approximated by the following low rank matrix formed from the first singular vectors: ```julia B+q[1]*p[:,1]*transpose(r[:,1]) ``` 6x4 Array{Float64,2}: 1.33866 1.18928 4.66134 4.81072 1.54664 1.41596 4.45336 4.58404 4.45336 4.58404 1.54664 1.41596 4.43281 4.56164 1.56719 1.43836 4.43281 4.56164 1.56719 1.43836 1.33866 1.18928 4.66134 4.81072 The first left-singular vector is: ```julia p[:,1] ``` 6-element Array{Float64,1}: -0.446401 -0.390517 0.390517 0.384996 0.384996 -0.446401 Similar centered scores indicate similar genre. The first right-singular vector is: ```julia r[:,1] ``` 4-element Array{Float64,1}: 0.478046 0.52103 -0.478046 -0.52103 Similar centered scores indicate users with similar tastes, thus Amy and Bob are a cluster (both prefer romantic comedies over action). ### Principal components analysis Consider the following data: ```julia M = [-1.03 0.74 -0.02 0.51 -1.31 0.99 0.69 -0.12 -0.72 1.11; -2.23 1.61 -0.02 0.88 -2.39 2.02 1.62 -0.35 -1.67 2.46] L, Q, R = svd(M) ``` ( 2x2 Array{Float64,2}: -0.430715 -0.902488 -0.902488 0.430715, [6.0397087855043186,0.21867278363335854], 10x2 Array{Float64,2}: 0.406673 -0.141455 -0.293348 0.117118 0.00441479 0.0431487 -0.167865 -0.371511 0.450549 0.698989 -0.372441 -0.107093 -0.291276 0.34317 0.0608567 -0.194134 0.300887 -0.317841 -0.446746 0.264312 ) With one singular value so much larger than the other, it may be safe to assume that the small value of the second singular value is due to noise in the data. So we reconstitute the matrix using only the first singular value and its singular vectors. ```julia Q[1]*L[:,1]*transpose(R[:,1]) ``` 2x10 Array{Float64,2}: -1.05792 0.763113 -0.0114846 0.436682 … -0.158312 -0.782726 1.16216 -2.21668 1.59897 -0.024064 0.914991 -0.331715 -1.64006 2.43511
(* Title: HOL/Auth/n_germanSymIndex_lemma_on_inv__51.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSymIndex Protocol Case Study*} theory n_germanSymIndex_lemma_on_inv__51 imports n_germanSymIndex_base begin section{*All lemmas on causal relation between inv__51 and some rule r*} lemma n_RecvReqSVsinv__51: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvReqS N i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv0)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv0)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv0)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv0)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvReqEVsinv__51: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvReqE N i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv0)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv0)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv0)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const true)) (eqn (IVar (Ident ''ExGntd'')) (Const true))) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv0)) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendInv__part__0Vsinv__51: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInv__part__0 i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv0)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendInv__part__1Vsinv__51: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInv__part__1 i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv0)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvInvAckVsinv__51: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvInvAck i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" have "?P2 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(i=p__Inv0)" have "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" have "?P2 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv2)" have "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))" have "?P2 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendGntEVsinv__51: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntE N i" apply fastforce done from a2 obtain p__Inv0 p__Inv2 where a2:"p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i=p__Inv0)\<or>(i~=p__Inv0\<and>i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv2)) (Const true)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i=p__Inv0)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv2)) (Const true)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv0\<and>i~=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Ident ''InvSet'') p__Inv2)) (Const true)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendReqE__part__1Vsinv__51: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__51: assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvGntSVsinv__51: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvGntS i" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendGntSVsinv__51: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendGntS i" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvGntEVsinv__51: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvGntE i" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendInvAckVsinv__51: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendInvAck i" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqE__part__0Vsinv__51: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqSVsinv__51: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqS i" and a2: "(\<exists> p__Inv0 p__Inv2. p__Inv0\<le>N\<and>p__Inv2\<le>N\<and>p__Inv0~=p__Inv2\<and>f=inv__51 p__Inv0 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
""" load results files and classification results files into an array of dicts """ import glob import os import pickle as pickle import numpy as np import matplotlib.pyplot as plt plt.ion() paths = glob.glob("results/results-*.pkl") # paths = glob.glob("results/results-gen2-*.pkl") data = [] DEL_PARAMS = True # save space by not keeping all the parameters in memory for path in paths: dirname = os.path.dirname(path) basename = os.path.basename(path) with open(path, 'r') as f: d = pickle.load(f) d['path'] = path if DEL_PARAMS: del d['params'] data.append(d) def point_plot(result_sets, xt, yt, *args, **kwargs): """ make a point plot based on the result set, where xt is the value type used for the x axis (a result set dictionary key), and yt is the same thing for the y axis. """ xs = [r[xt] for r in result_sets] ys = [r[yt] for r in result_sets] plt.scatter(xs, ys, *args, **kwargs) def pp(result_sets, xt, yt, logx=False, logy=False): """ make a point plot based on the result set, where xt is the value type used for the x axis (a result set dictionary key), and yt is the same thing for the y axis. """ if logx: xs = [np.log(r[xt]) for r in result_sets] else: xs = [r[xt] for r in result_sets] if logy: ys = [np.log(r[yt]) for r in result_sets] else: ys = [r[yt] for r in result_sets] plt.scatter(xs, ys) def point_plot_lambda(result_sets, fx, fy, *args, **kwargs): """ like point_plot, but with lambdas that operate on the result_set to select the values to plot. """ xs = [fx(r) for r in result_sets] ys = [fy(r) for r in result_sets] plt.scatter(xs, ys, *args, **kwargs) def nbest(result_sets, n=10, key='valid'): rs = list(result_sets) # make a copy because we'll sort in place rs.sort(key=lambda d: d[key]) return rs[-n:] aucs = np.array([r['evaluation']['auc'] for r in data]) order = np.argsort(aucs) # filenames = [os.path.basename(data[k]['path']) for k in order[-30:]]
1 -- @@stderr -- dtrace: invalid probe specifier profile: probe description :::profile does not match any probes
The fractional content of a fractional polynomial is equal to the content of the polynomial.
# Finding constants using fsolve Problem: find $k$ and $c$ given $\begin{align} 1 + \sinh^{-1}1 &= k \sinh^{-1}(1/k) + c \;, \\ 1 + \sinh^{-1}5 &= k \sinh^{-1}(5/k) + c \;. \end{align}$ Plan: use `fsolve` from `scipy.optimize`. ```python import numpy as np from scipy.optimize import fsolve ``` ```python def func(x): """Function of x = (k, c) defined so that when each component is zero we have our solution. No extra arguments need to be passed, so func is simple.""" k, c = x return ( 1. + np.arcsinh(1.) - (k * np.arcsinh(1./k) + c), 1. + np.arcsinh(5.) - (k * np.arcsinh(5./k) + c) ) ``` ```python x0 = (0.1, 0.1) # guesses for k and c k, c = fsolve(func, x0) print(f'k = {k:0.2f}, c = {c:0.2f}') ``` k = 1.00, c = 1.00 ```python ```
MODULE totvar ! Module for the variables for the entire sub-domian IMPLICIT NONE SAVE ! Problem size REAL*8, DIMENSION(:), ALLOCATABLE :: dxt, dyt, dzt ! Cell materials INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: matt ! Boundary conditions !REAL*8, DIMENSION(:,:,:,:), ALLOCATABLE :: posinz, neginz, posiny, neginy, posinx, neginx ! Source data REAL*8, DIMENSION(:,:,:), ALLOCATABLE :: st END MODULE
/* pbrt source code is Copyright(c) 1998-2016 Matt Pharr, Greg Humphreys, and Wenzel Jakob. This file is part of pbrt. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(_MSC_VER) #define NOMINMAX #pragma once #endif #ifndef PBRT_CAMERAS_REALISTICEYE_H #define PBRT_CAMERAS_REALISTICEYE_H // cameras/realistic.h* #include "pbrt.h" #include "camera.h" #include "film.h" #include <gsl/gsl_randist.h> #include "spectrum.h" // This is necessary to declare Spectrum class in this header file. namespace pbrt { // This is slightly different than our normal lens class. We have more variables to be able to describe the elements of the eye including biconic surfaces and unique ocular mediums. struct LensElementEye{ float radiusX; float radiusY; float thickness; float mediumIndex; // Corresponds to the mediumElement. Describes media directly "behind" (-z direction, toward the retina) the surface. float semiDiameter; float conicConstantX; float conicConstantY; }; // RealisticCamera Declarations class RealisticEye : public Camera { public: // RealisticCamera Public Methods RealisticEye(const AnimatedTransform &CameraToWorld, Float shutterOpen, Float shutterClose, bool simpleWeighting, bool noWeighting, Film *film, const Medium *medium, std::string specfile, Float pupilDiameter, Float retinaDistance, Float retinaRadius, Float retinaSemiDiam, std::vector<Spectrum> iorSpectra, bool flipRad, bool mmUnits, bool diffractionEnabled); Float GenerateRay(const CameraSample &sample, Ray *) const; private: const bool simpleWeighting; const bool noWeighting; // Lens information std::vector<LensElementEye> lensEls; Float effectiveFocalLength; // Specific parameters for the human eye Float pupilDiameter; Float retinaDistance; Float retinaRadius; Float retinaSemiDiam; Float retinaDiag; // This will take the place of "film->diag" Float frontThickness; // The distance from the back of the lens to the front of the eye. std::vector<Spectrum> iorSpectra; // Flags for conventions bool diffractionEnabled; float lensScaling; // Private methods for tracing through lens bool IntersectLensElAspheric(const Ray &r, Float *tHit, LensElementEye currElement, Float zShift, Vector3f *n) const; void applySnellsLaw(Float n1, Float n2, Float lensRadius, Vector3f &normalVec, Ray * ray ) const; Float lookUpIOR(int mediumIndex, const Ray &ray) const; void diffractHURB(Point3f intersect, Float apertureRadius, const Float wavelength, const Vector3f oldDirection, Vector3f *newDirection) const; // Handy method to explicity solve for the z(x,y) at a given point (x,y), for the biconic SAG Float BiconicZ(Float x, Float y, LensElementEye currElement) const; // GSL seed(?) for random number generation gsl_rng * r; }; RealisticEye *CreateRealisticEye(const ParamSet &params, const AnimatedTransform &cam2world, Film *film, const Medium *medium); } // namespace pbrt #endif // PBRT_CAMERAS_REALISTICEYE_H
function mtrPlotCorr(ccFilenameBase,threshVec,paramNames,midP,whichParams,strLineProp) % % paramNames = {'kLength','kSmooth','kMidSD'}; % midP = [0 18 0.175]; for pp = 1:length(whichParams) strThreshVec = {}; parVecs = []; corrVecs = []; ovrVecs = []; for tt = 1:length(threshVec) cc = load([ccFilenameBase '_thresh_' num2str(threshVec(tt)) '.mat']); ccGrid = mtrCCMatrix2Grid(cc.ccMatrix,cc.paramData,paramNames); indGrid = ones(size(ccGrid,1),1); for ss = 1:length(paramNames) if ss ~= whichParams(pp) indGrid = indGrid & ccGrid(:,ss) == midP(ss); end end subGrid = ccGrid(indGrid,:); [foo, sortI] = sort(subGrid(:,whichParams(pp))); parVecs(:,tt) = subGrid(sortI(:),whichParams(pp)); corrVecs(:,tt) = subGrid(sortI(:),4); strThreshVec{tt} = ['Top ' num2str(threshVec(tt))]; end if( pp>1 ) figure; end if strcmp(paramNames{whichParams(pp)},'kSmooth') parVecs = asin(sqrt(1./parVecs)).*180./pi; plot(parVecs,corrVecs,strLineProp); else plot(parVecs,corrVecs,strLineProp); end %legend(strThreshVec); xlabel([paramNames{whichParams(pp)} ' parameter']); ylabel('Corr. Coef.'); end
{-# OPTIONS --cubical #-} open import Agda.Primitive.Cubical open import Agda.Builtin.Cubical.Path open import Agda.Builtin.Sigma data S1 : Set where base : S1 loop : base ≡ base data Torus : Set where point : Torus line1 : point ≡ point line2 : point ≡ point square : PathP (λ i → line1 i ≡ line1 i) line2 line2 t2c : Torus → Σ S1 \ _ → S1 t2c point = ( base , base ) t2c (line1 i) = ( loop i , base ) t2c (line2 i) = ( base , loop i ) t2c (square i1 i2) = ( loop i1 , loop i2 )
(* Title: HOL/Auth/n_flash_nodata_cub_lemma_on_inv__116.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_flash_nodata_cub Protocol Case Study*} theory n_flash_nodata_cub_lemma_on_inv__116 imports n_flash_nodata_cub_base begin section{*All lemmas on causal relation between inv__116 and some rule r*} lemma n_PI_Remote_GetVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Get src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Get src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Remote_GetXVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_GetX src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_GetX src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_NakVsinv__116: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Nak dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Nak dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__0Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__2Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Get__part__0Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Get__part__1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Put_HeadVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_PutVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Put_DirtyVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_NakVsinv__116: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_PutVsinv__116: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__0Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__2Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_GetX__part__0Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_GetX__part__1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_2Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_3Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_4Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_5Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_6Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7__part__0Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7__part__1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_HomeVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8Vsinv__116: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_NODE_GetVsinv__116: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_9__part__0Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_9__part__1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_10_HomeVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeShrSet'')) (Const true)))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_10Vsinv__116: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 b1 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4)))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadVld'')) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_11Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_NakVsinv__116: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_PutXVsinv__116: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (andForm (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''InvSet'') p__Inv4)) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_GetX))) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''HomeProc'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_PutVsinv__116: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Put dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Put dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_PutXVsinv__116: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_PutX dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_PutX dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_InvAck_exists_HomeVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_InvAck_exists_Home src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_InvAck_exists_Home src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_InvAck_existsVsinv__116: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_InvAck_1Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_InvAck_1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_InvAck_1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_InvAck_2Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_InvAck_2 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_InvAck_2 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_InvAck_3Vsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_InvAck_3 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_InvAck_3 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_ReplaceVsinv__116: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Replace src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Replace src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "((formEval (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) s))" have "?P2 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__116: assumes a1: "(r=n_PI_Local_GetX_PutX_HeadVld__part__0 N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__116: assumes a1: "(r=n_PI_Local_GetX_PutX_HeadVld__part__1 N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))\<or>((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false))) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''Dirty'')) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HeadPtr'')) (Const (index p__Inv4))))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''ShrVld'')) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true))) (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const false)))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_ShWbVsinv__116: assumes a1: "(r=n_NI_ShWb N )" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__116 p__Inv4" apply fastforce done have "((formEval (andForm (eqn (Const (index p__Inv4)) (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Proc''))) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''HomeProc'')) (Const false))) s))\<or>((formEval (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)) s))\<or>((formEval (andForm (neg (eqn (Const (index p__Inv4)) (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Proc'')))) (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)))) s))\<or>((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''HomeProc'')) (Const false))) (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)))) s))" by auto moreover { assume c1: "((formEval (andForm (eqn (Const (index p__Inv4)) (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Proc''))) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''HomeProc'')) (Const false))) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX)) (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Cmd'')) (Const SHWB_ShWb))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)) s))" have "?P3 s" apply (cut_tac a1 a2 c1, simp, rule_tac x="(neg (andForm (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_PutX))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (Const (index p__Inv4)) (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''Proc'')))) (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (andForm (neg (eqn (IVar (Field (Field (Ident ''Sta'') ''ShWbMsg'') ''HomeProc'')) (Const false))) (neg (eqn (IVar (Para (Field (Field (Ident ''Sta'') ''Dir'') ''ShrSet'') p__Inv4)) (Const true)))) s))" have "?P1 s" proof(cut_tac a1 a2 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_PutX_HomeVsinv__116: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__0Vsinv__116: assumes a1: "r=n_PI_Local_GetX_PutX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_WbVsinv__116: assumes a1: "r=n_NI_Wb " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__1Vsinv__116: assumes a1: "r=n_PI_Local_GetX_GetX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__0Vsinv__116: assumes a1: "r=n_PI_Local_GetX_GetX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_ReplaceVsinv__116: assumes a1: "\<exists> src. src\<le>N\<and>r=n_PI_Remote_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_ReplaceVsinv__116: assumes a1: "r=n_PI_Local_Replace " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Remote_PutXVsinv__116: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_PI_Remote_PutX dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Put_HomeVsinv__116: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvVsinv__116: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Inv dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_PutXVsinv__116: assumes a1: "r=n_PI_Local_PutX " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_PutVsinv__116: assumes a1: "r=n_PI_Local_Get_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_GetX_Nak_HomeVsinv__116: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutXAcksDoneVsinv__116: assumes a1: "r=n_NI_Local_PutXAcksDone " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__1Vsinv__116: assumes a1: "r=n_PI_Local_GetX_PutX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Nak_HomeVsinv__116: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Replace_HomeVsinv__116: assumes a1: "r=n_NI_Replace_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutVsinv__116: assumes a1: "r=n_NI_Local_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_ClearVsinv__116: assumes a1: "r=n_NI_Nak_Clear " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_GetVsinv__116: assumes a1: "r=n_PI_Local_Get_Get " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_HomeVsinv__116: assumes a1: "r=n_NI_Nak_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_FAckVsinv__116: assumes a1: "r=n_NI_FAck " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__116 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
If $x = 0$ and $a \neq 0$, then $y = 0$ if and only if $a y - b x = 0$.
{-# OPTIONS --without-K #-} module Fmmh where open import Data.List using (List) open import Pitch -- Reconstruction of "Functional Modelling of Musical Harmony" (ICFP 2011) -- using similar notation. Original code: -- https://github.com/chordify/HarmTrace-Base data Mode : Set where maj : Mode min : Mode data ChordQuality : Set where maj : ChordQuality min : ChordQuality dom7 : ChordQuality dim : ChordQuality data Chord : DiatonicDegree → ChordQuality → Set where chord : (d : DiatonicDegree) → (q : ChordQuality) → Chord d q data Ton : Mode → Set where maj : Chord d1 maj → Ton maj min : Chord d1 min → Ton min data SDom : Mode → Set where ii : Chord d2 min → SDom maj iv-maj : Chord d4 maj → SDom maj iii-iv : Chord d3 min → Chord d4 maj → SDom maj iv-min : Chord d4 min → SDom min data Dom (m : Mode) : Set where v7 : Chord d5 dom7 → Dom m v : Chord d5 maj → Dom m vii : Chord d7 dim → Dom m sdom : SDom m → Dom m → Dom m ii-v : Chord d2 dom7 → Chord d5 dom7 → Dom m data Phrase (m : Mode) : Set where i-v-i : Ton m → Dom m → Ton m → Phrase m v-i : Dom m → Ton m → Phrase m data Piece : Set where piece : {m : Mode} → List (Phrase m) → Piece
Davis water wells are the source of the tap water in Davis. These are scattered about town and generally the water from the faucet comes from the nearest well(s). Also note that the water towers are used in the distribution scheme to maintain pressure and distribution across the system. Currently, all the water supplied by the city comes from an aquifer. In general, the city sits over an aquifer system with two distinct layers. The upper layer, known as the intermediate depth aquifer, extends approximately 700 feet below the ground surface. A second layer is known as the deep depth aquifer, is separated from the intermediate depth aquifer by a less permeable clay layer. Originally, the city supplied all its water from the intermediate depth aquifer. In recent years however, in order to achieve greater water quality, the city has begun shifting its water supply over to the deep depth aquifer. Older wells in Davis typically extend 300 to 600 feet below the ground surface, while newer deep wells in Davis may extend 1500 to 1800 feet below the ground surface. A depth chart of all the well in davis can be seen http://cityofdavis.org/pw/water/pdfs/Well_Profiles_Color.pdf here. More information on the citys water system can be found in its http://cityofdavis.org/pw/water/pdfs/2005UrbanWaterManagementPlanUpdate.pdf urban water management plan. Currently Operational Wells Davis Well 1 Davis Well 7 Davis Well 11 Davis Well 12 Davis Well 13 Davis Well 14 Davis Well 15 May be abandoned Davis Well 18 Davis Well 19 Davis Well 20 Davis Well 21 Davis Well 22 Davis Well 23 Davis Well 24 Davis Well 25 Davis Well 26 Davis Well 27 Davis Deep Well 28 Davis Well EM2 Davis Well EM3 Davis Deep Well 29 Davis Deep Well 30 Davis Deep Well 31 Abandoned Wells Davis Well 16
#' Change naming style of the taxa in the phyloseq object. #' #' This function adapts the rows and the columns of the corresponding #' phyloseq object to improve the reading. It adds 0s based #' on the total amount of ASVs to enable correct sorting in R. If you imported #' your data from dada2 and your current taxa names are the sequences (ASVs), #' you can specify `use_sequences = TRUE` to move the sequences to the phyloseq #' refseq() slot before renaming takes place. Existing sequences in the refseq() #' slot will then be overwritten! #' #' @param phyloseq_object The phyloseq object with the taxa_names() to be modified #' @param taxa_prefix The leading name of your taxa, e.g. `ASV` or `OTU`, #' must not contain an underscore or white space #' @param use_sequences Logical indicating whether your current taxa_names() #' are sequences which you want to have moved to the refseq() slot of the #' returning phyloseq object #' #' @return The modified phyloseq object #' #' @export standardize_phyloseq_headers <- function(phyloseq_object, taxa_prefix, use_sequences) { if (!is.character(taxa_prefix) | !length(taxa_prefix) == 1) stop("Please provide a single character string as name") if(grepl("_", taxa_prefix, fixed = TRUE)) stop("taxa_prefix needs to be a string without underscores") if (!is.logical(use_sequences)) stop("Please enter TRUE or FALSE depending on whether your current taxa_prefixs are sequences (ASVs from dada2 import)") if (isTRUE(use_sequences)) { string_vector <- phyloseq::taxa_names(phyloseq_object) if(!all(grepl("A", string_vector) & grepl("T", string_vector) & grepl("G", string_vector) & grepl("C", string_vector))) { futile.logger::flog.warn( "Your taxa_names() do not seem to contain DNA sequences") } } number_seqs <- seq(phyloseq::ntaxa(phyloseq_object)) length_number_seqs <- nchar(max(number_seqs)) newNames <- paste0(taxa_prefix, formatC(number_seqs, width = length_number_seqs, flag = "0")) if (isTRUE(use_sequences)) { futile.logger::flog.warn("This will overwrite sequences currently existing in the refseq() slot") sequences <- phyloseq::taxa_names(phyloseq_object) names(sequences) <- newNames } phyloseq::taxa_names(phyloseq_object) <- newNames if (isTRUE(use_sequences)) { phyloseq::merge_phyloseq(phyloseq_object, Biostrings::DNAStringSet(sequences)) } else { phyloseq_object } } #' Add columns with unique lineages to phyloseq `tax_table()` #' #' This function modifies the phyloseq object in order to enable Machine learning #' analysis on specified taxonomy ranks. phyloseq provides the `tax_glom()` function #' which allows to combine an `otu_table` at e.g. the Genus or Family level. #' However, not annotated taxa (`NA` or `unclassified`) at a given level will #' either be dropped or combined to e.g. one large Genus called `unclassified. #' But an unannotated taxa might still be important for classification. This #' function keeps such information by incorporating the full unique lineage #' for each existing taxonomic rank by concatenating all higher level annotations. #' The function than interleaves those newly generated columns with the existing #' tax_table() so the positioning is what tax_glom() requires. #' #' @param phyloseq_object The phyloseq object with the `tax_table()` to be #' modified. This function assumes that ranks are hierarchically ordered, #' starting with the highest taxonomic rank (e.g. Kingdom) as first column. #' #' @return The phyloseq object with a modified `tax_table()` #' #' @export add_unique_lineages <- function(phyloseq_object) { if(class(phyloseq_object) != "phyloseq") { stop('Provided argument for "phyloseq_object" is not of class "phyloseq"') } if(any(grepl("To_", phyloseq::rank_names(phyloseq_object)))) { futile.logger::flog.warn('rank_names(phyloseq_object) already contain the pattern "To_", unique lineages already added?') } # get available taxa ranks and create a vector containing an # interleaved order of columns based on the number of taxa ranks tax_columns <- colnames(phyloseq::tax_table(phyloseq_object)) interleaved <- rep(1:length(tax_columns), each = 2) + (0:1) * length(tax_columns) # for each tax rank, create a new column consisting of the concatenated # lineage down to the specific tax rank # e.g. for tax rank Order: Kingdom_Phylum_Class_Order unique_lineages <- list() for (tax_rank in tax_columns){ unique_lineages[[paste("To", tax_rank, sep = "_")]] <- as.vector(apply(phyloseq::tax_table(phyloseq_object)[, c(1:which(tax_columns == tax_rank))], 1, paste, collapse = "_")) } # combine tax_table and the lineages in an alternating (interleaved) order unique_lineages_df <- as.data.frame(unique_lineages) phyloseq::tax_table(phyloseq_object) <- cbind(as.matrix(unique_lineages_df), phyloseq::tax_table(phyloseq_object))[,interleaved] phyloseq_object }
/- Author: Justin Mayer self study of abstract algebra. Chapter two of dummit and foote. -/ import tactic import algebra.group.basic import group_theory.subgroup.basic import data.set.basic --#print subgroup variables {G: Type} [group G] (H : subgroup G) instance : has_mem G (subgroup G) := {mem := λ m H, m ∈ H.carrier } --this allows for g ∈ H to be written. See formalising math by Kevin Buzzard. Groups, sheet 3 instance : has_coe (subgroup G) (set G) := {coe := λ H, H.carrier} --just removing the need to reference H.carrier since this doesn't feel very "mathy." Once again a trick demonstrated by Kevin Buzzard. Formalising mathematics, Groups, sheet 3. --notice that these are instances of general functions definied in lean. We then define the mem function using the lambda calculus formalism. @[simp] lemma mem_coe {g:G} : g ∈ (H : set G) ↔ g ∈ H := begin refl, end --always for a rewrite where if something has type g ∈ (H : set G), then it can just be written as g ∈ H. Another useful math tactic. @[ext] def ext' (H K : subgroup G) (h : ∀ g : G, g ∈ H ↔ g ∈ K) : H = K := begin ext x, exact h x, end --another extensionality theorem that asserts two subgroups are equal iff every element is contained in both subgroups. --finally, remove all refereneces to the carrier function: theorem one_mem : (1:G) ∈ H := begin apply H.one_mem', end theorem mul_mem {x y : G}: x ∈ H → y ∈ H → x*y ∈ H := begin apply H.mul_mem', end theorem inv_mem {x:G} : x ∈ H → x⁻¹ ∈ H := begin apply H.inv_mem', end --A subgroup has now been defined in a way that is natural to the notation in dummit foote. The three important theorems to use are: -- H.one_mem : (1:G) ∈ H -- H.mul_mem : x ∈ H → y ∈ H → x * y ∈ H -- H.inv_mem : x ∈ H → x⁻¹ ∈ H --the subgroup criterion mentioned on page 46 lemma subgroup_crit {G : Type} [group G] (H : subgroup G) : (∃ g : G, g ∈ H) ∧ ∀ x y : G, x ∈ H → y ∈ H → x*y⁻¹ ∈ H := begin split, have h: (1:G) ∈ H := H.one_mem, use (1:G), exact h, intros x y hx hy, have h2: y⁻¹ ∈ H := H.inv_mem hy, exact H.mul_mem hx h2, end --define a structure mysubgroup based on the fact that it is a nonempty subset of G with a particular multiplication relation on the subset. --does this structure end up being a subgroup? Let's find out! structure mysubgroup (G:Type) [group G] := (carrier : set G) (non_empty' : carrier.nonempty) (mul_con' : ∀ x y: G, x ∈ carrier → y ∈ carrier → x*y⁻¹ ∈ carrier) variables (P : mysubgroup G) instance : has_mem G (mysubgroup G) := {mem := λ m P, m ∈ P.carrier } --#print mysubgroup lemma mysubgroup_one_mem (P:mysubgroup G) : (1:G) ∈ P.carrier := begin have h: ∃ x:G, x ∈ P.carrier := P.non_empty', cases h with x hx, have h2: x*x⁻¹ ∈ P.carrier := P.mul_con' x x hx hx, simp at h2, exact h2, end lemma mysubgroup_inv_mem (P:mysubgroup G) : ∀ x:G, x∈P.carrier → x⁻¹∈P.carrier := begin intros x hx, have h1: (1:G) ∈ P.carrier := mysubgroup_one_mem P, have h2: 1*x⁻¹ ∈ P.carrier := P.mul_con' (1:G) x h1 hx, simp at h2, exact h2, end lemma mysubgroup_mul_mem (P:mysubgroup G) : ∀ x y : G, x∈P.carrier → y∈P.carrier → x*y ∈ P.carrier := begin intros x y hx hy, have h1: y⁻¹ ∈ P.carrier := mysubgroup_inv_mem P y hy, have h2: x*y⁻¹⁻¹ ∈ P.carrier := P.mul_con' x y⁻¹ hx h1, simp at h2, exact h2, end --based on these three lemmas the definition mysubgroup is clearly a group! I think to be completely precise --it may also make sense to show that mysubgroup is an instance of subgroup. Do this with Harlan perhaps?
State Before: C : Type u₁ inst✝⁵ : Category C D : Type u₂ inst✝⁴ : Category D G : C ⥤ D X Y Z : C f g : X ⟶ Y h : Y ⟶ Z w : f ≫ h = g ≫ h inst✝³ : HasCoequalizer f g inst✝² : HasCoequalizer (G.map f) (G.map g) inst✝¹ : PreservesColimit (parallelPair f g) G X' Y' : D f' g' : X' ⟶ Y' inst✝ : HasCoequalizer f' g' p : G.obj X ⟶ X' q : G.obj Y ⟶ Y' wf : G.map f ≫ q = p ≫ f' wg : G.map g ≫ q = p ≫ g' ⊢ G.map (coequalizer.π f g) ≫ (PreservesCoequalizer.iso G f g).inv ≫ colimMap (parallelPairHom (G.map f) (G.map g) f' g' p q wf wg) = q ≫ coequalizer.π f' g' State After: no goals Tactic: rw [← Category.assoc, map_π_preserves_coequalizer_inv, ι_colimMap, parallelPairHom_app_one]
function [avgArray] = calculateAvgArray(tau, sPeriod, readings) %This function uses raw readings and returns an array of readings for the %input Tau argument. readings can either be freq or time avgCount = tau / sPeriod; %gets count for averaging loopCount = numel(readings) / avgCount; %get number of loop iterations needed loopCount = floor(loopCount); %convert loopCount to integer in case it is a non int avgArray = zeros(1,loopCount); %allocate array iter = 0; iter = int32(iter); %loop to build array for i = 1:loopCount temp = mean(readings((iter+1):(iter+avgCount))); avgArray(i) = temp; iter = iter + avgCount; end
[STATEMENT] lemma "Inf_pres (\<lambda>x. \<bottom>::'a::complete_lattice)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. Inf_pres (\<lambda>x. \<bottom>) [PROOF STEP] (*nitpick[show_all]*) [PROOF STATE] proof (prove) goal (1 subgoal): 1. Inf_pres (\<lambda>x. \<bottom>) [PROOF STEP] oops
module Compiler.LambdaLift import Core.CompileExpr import Core.Context import Core.Core import Core.TT import Data.List import Data.Vect import Data.Maybe %default covering mutual public export -- lazy (lazy reason) represents if a function application is lazy (Just _) -- and if so why (eg. Just LInf, Just LLazy) data Lifted : List Name -> Type where LLocal : {idx : Nat} -> FC -> (0 p : IsVar x idx vars) -> Lifted vars -- A known function applied to exactly the right number of arguments, -- so the runtime can Just Go LAppName : FC -> (lazy : Maybe LazyReason) -> Name -> List (Lifted vars) -> Lifted vars -- A known function applied to too few arguments, so the runtime should -- make a closure and wait for the remaining arguments LUnderApp : FC -> Name -> (missing : Nat) -> (args : List (Lifted vars)) -> Lifted vars -- A closure applied to one more argument (so, for example a closure -- which is waiting for another argument before it can run). -- The runtime should add the argument to the closure and run the result -- if it is now fully applied. LApp : FC -> (lazy : Maybe LazyReason) -> (closure : Lifted vars) -> (arg : Lifted vars) -> Lifted vars LLet : FC -> (x : Name) -> Lifted vars -> Lifted (x :: vars) -> Lifted vars LCon : FC -> Name -> ConInfo -> (tag : Maybe Int) -> List (Lifted vars) -> Lifted vars LOp : {arity : _} -> FC -> (lazy : Maybe LazyReason) -> PrimFn arity -> Vect arity (Lifted vars) -> Lifted vars LExtPrim : FC -> (lazy : Maybe LazyReason) -> (p : Name) -> List (Lifted vars) -> Lifted vars LConCase : FC -> Lifted vars -> List (LiftedConAlt vars) -> Maybe (Lifted vars) -> Lifted vars LConstCase : FC -> Lifted vars -> List (LiftedConstAlt vars) -> Maybe (Lifted vars) -> Lifted vars LPrimVal : FC -> Constant -> Lifted vars LErased : FC -> Lifted vars LCrash : FC -> String -> Lifted vars public export data LiftedConAlt : List Name -> Type where MkLConAlt : Name -> ConInfo -> (tag : Maybe Int) -> (args : List Name) -> Lifted (args ++ vars) -> LiftedConAlt vars public export data LiftedConstAlt : List Name -> Type where MkLConstAlt : Constant -> Lifted vars -> LiftedConstAlt vars public export data LiftedDef : Type where -- We take the outer scope and the function arguments separately so that -- we don't have to reshuffle de Bruijn indices, which is expensive. -- This should be compiled as a function which takes 'args' first, -- then 'reverse scope'. -- (Sorry for the awkward API - it's to do with how the indices are -- arranged for the variables, and it oculd be expensive to reshuffle them! -- See Compiler.ANF for an example of how they get resolved to names) MkLFun : (args : List Name) -> -- function arguments (scope : List Name) -> -- outer scope Lifted (scope ++ args) -> LiftedDef MkLCon : (tag : Maybe Int) -> (arity : Nat) -> (nt : Maybe Nat) -> LiftedDef MkLForeign : (ccs : List String) -> (fargs : List CFType) -> CFType -> LiftedDef MkLError : Lifted [] -> LiftedDef showLazy : Maybe LazyReason -> String showLazy = maybe "" $ (" " ++) . show mutual export {vs : _} -> Show (Lifted vs) where show (LLocal {idx} _ p) = "!" ++ show (nameAt p) show (LAppName fc lazy n args) = show n ++ showLazy lazy ++ "(" ++ showSep ", " (map show args) ++ ")" show (LUnderApp fc n m args) = "<" ++ show n ++ " underapp " ++ show m ++ ">(" ++ showSep ", " (map show args) ++ ")" show (LApp fc lazy c arg) = show c ++ showLazy lazy ++ " @ (" ++ show arg ++ ")" show (LLet fc x val sc) = "%let " ++ show x ++ " = " ++ show val ++ " in " ++ show sc show (LCon fc n _ t args) = "%con " ++ show n ++ "(" ++ showSep ", " (map show args) ++ ")" show (LOp fc lazy op args) = "%op " ++ show op ++ showLazy lazy ++ "(" ++ showSep ", " (toList (map show args)) ++ ")" show (LExtPrim fc lazy p args) = "%extprim " ++ show p ++ showLazy lazy ++ "(" ++ showSep ", " (map show args) ++ ")" show (LConCase fc sc alts def) = "%case " ++ show sc ++ " of { " ++ showSep "| " (map show alts) ++ " " ++ show def show (LConstCase fc sc alts def) = "%case " ++ show sc ++ " of { " ++ showSep "| " (map show alts) ++ " " ++ show def show (LPrimVal _ x) = show x show (LErased _) = "___" show (LCrash _ x) = "%CRASH(" ++ show x ++ ")" export {vs : _} -> Show (LiftedConAlt vs) where show (MkLConAlt n _ t args sc) = "%conalt " ++ show n ++ "(" ++ showSep ", " (map show args) ++ ") => " ++ show sc export {vs : _} -> Show (LiftedConstAlt vs) where show (MkLConstAlt c sc) = "%constalt(" ++ show c ++ ") => " ++ show sc export Show LiftedDef where show (MkLFun args scope exp) = show args ++ show (reverse scope) ++ ": " ++ show exp show (MkLCon tag arity pos) = "Constructor tag " ++ show tag ++ " arity " ++ show arity ++ maybe "" (\n => " (newtype by " ++ show n ++ ")") pos show (MkLForeign ccs args ret) = "Foreign call " ++ show ccs ++ " " ++ show args ++ " -> " ++ show ret show (MkLError exp) = "Error: " ++ show exp data Lifts : Type where record LDefs where constructor MkLDefs basename : Name -- top level name we're lifting from defs : List (Name, LiftedDef) -- new definitions we made nextName : Int -- name of next definition to lift genName : {auto l : Ref Lifts LDefs} -> Core Name genName = do ldefs <- get Lifts let i = nextName ldefs put Lifts (record { nextName = i + 1 } ldefs) pure $ mkName (basename ldefs) i where mkName : Name -> Int -> Name mkName (NS ns b) i = NS ns (mkName b i) mkName (UN n) i = MN (displayUserName n) i mkName (DN _ n) i = mkName n i mkName (CaseBlock outer inner) i = MN ("case block in " ++ outer ++ " (" ++ show inner ++ ")") i mkName (WithBlock outer inner) i = MN ("with block in " ++ outer ++ " (" ++ show inner ++ ")") i mkName n i = MN (show n) i unload : FC -> (lazy : Maybe LazyReason) -> Lifted vars -> List (Lifted vars) -> Core (Lifted vars) unload fc _ f [] = pure f -- only outermost LApp must be lazy as rest will be closures unload fc lazy f (a :: as) = unload fc Nothing (LApp fc lazy f a) as record Used (vars : List Name) where constructor MkUsed used : Vect (length vars) Bool initUsed : {vars : _} -> Used vars initUsed {vars} = MkUsed (replicate (length vars) False) lengthDistributesOverAppend : (xs, ys : List a) -> length (xs ++ ys) = length xs + length ys lengthDistributesOverAppend [] ys = Refl lengthDistributesOverAppend (x :: xs) ys = cong S $ lengthDistributesOverAppend xs ys weakenUsed : {outer : _} -> Used vars -> Used (outer ++ vars) weakenUsed {outer} (MkUsed xs) = MkUsed (rewrite lengthDistributesOverAppend outer vars in (replicate (length outer) False ++ xs)) contractUsed : (Used (x::vars)) -> Used vars contractUsed (MkUsed xs) = MkUsed (tail xs) contractUsedMany : {remove : _} -> (Used (remove ++ vars)) -> Used vars contractUsedMany {remove=[]} x = x contractUsedMany {remove=(r::rs)} x = contractUsedMany {remove=rs} (contractUsed x) markUsed : {vars : _} -> (idx : Nat) -> {0 prf : IsVar x idx vars} -> Used vars -> Used vars markUsed {vars} {prf} idx (MkUsed us) = let newUsed = replaceAt (finIdx prf) True us in MkUsed newUsed where finIdx : {vars : _} -> {idx : _} -> (0 prf : IsVar x idx vars) -> Fin (length vars) finIdx {idx=Z} First = FZ finIdx {idx=S x} (Later l) = FS (finIdx l) getUnused : Used vars -> Vect (length vars) Bool getUnused (MkUsed uv) = map not uv total dropped : (vars : List Name) -> (drop : Vect (length vars) Bool) -> List Name dropped [] _ = [] dropped (x::xs) (False::us) = x::(dropped xs us) dropped (x::xs) (True::us) = dropped xs us mutual makeLam : {auto l : Ref Lifts LDefs} -> {vars : _} -> {doLazyAnnots : Bool} -> {default Nothing lazy : Maybe LazyReason} -> FC -> (bound : List Name) -> CExp (bound ++ vars) -> Core (Lifted vars) makeLam fc bound (CLam _ x sc') = makeLam fc {doLazyAnnots} {lazy} (x :: bound) sc' makeLam {vars} fc bound sc = do scl <- liftExp {doLazyAnnots} {lazy} sc -- Find out which variables aren't used in the new definition, and -- do not abstract over them in the new definition. let scUsedL = usedVars initUsed scl unusedContracted = contractUsedMany {remove=bound} scUsedL unused = getUnused unusedContracted scl' = dropUnused {outer=bound} unused scl n <- genName ldefs <- get Lifts put Lifts (record { defs $= ((n, MkLFun (dropped vars unused) bound scl') ::) } ldefs) pure $ LUnderApp fc n (length bound) (allVars fc vars unused) where allPrfs : (vs : List Name) -> (unused : Vect (length vs) Bool) -> List (Var vs) allPrfs [] _ = [] allPrfs (v :: vs) (False::uvs) = MkVar First :: map weaken (allPrfs vs uvs) allPrfs (v :: vs) (True::uvs) = map weaken (allPrfs vs uvs) -- apply to all the variables. 'First' will be first in the last, which -- is good, because the most recently bound name is the first argument to -- the resulting function allVars : FC -> (vs : List Name) -> (unused : Vect (length vs) Bool) -> List (Lifted vs) allVars fc vs unused = map (\ (MkVar p) => LLocal fc p) (allPrfs vs unused) -- if doLazyAnnots = True then annotate function application with laziness -- otherwise use old behaviour (thunk is a function) liftExp : {vars : _} -> {auto l : Ref Lifts LDefs} -> {doLazyAnnots : Bool} -> {default Nothing lazy : Maybe LazyReason} -> CExp vars -> Core (Lifted vars) liftExp (CLocal fc prf) = pure $ LLocal fc prf liftExp (CRef fc n) = pure $ LAppName fc lazy n [] -- probably shouldn't happen! liftExp (CLam fc x sc) = makeLam {doLazyAnnots} {lazy} fc [x] sc liftExp (CLet fc x _ val sc) = pure $ LLet fc x !(liftExp {doLazyAnnots} val) !(liftExp {doLazyAnnots} sc) liftExp (CApp fc (CRef _ n) args) -- names are applied exactly in compileExp = pure $ LAppName fc lazy n !(traverse (liftExp {doLazyAnnots}) args) liftExp (CApp fc f args) = unload fc lazy !(liftExp {doLazyAnnots} f) !(traverse (liftExp {doLazyAnnots}) args) liftExp (CCon fc n ci t args) = pure $ LCon fc n ci t !(traverse (liftExp {doLazyAnnots}) args) liftExp (COp fc op args) = pure $ LOp fc lazy op !(traverseArgs args) where traverseArgs : Vect n (CExp vars) -> Core (Vect n (Lifted vars)) traverseArgs [] = pure [] traverseArgs (a :: as) = pure $ !(liftExp {doLazyAnnots} a) :: !(traverseArgs as) liftExp (CExtPrim fc p args) = pure $ LExtPrim fc lazy p !(traverse (liftExp {doLazyAnnots}) args) liftExp (CForce fc lazy tm) = if doLazyAnnots then liftExp {doLazyAnnots} {lazy = Nothing} tm else liftExp {doLazyAnnots} (CApp fc tm [CErased fc]) liftExp (CDelay fc lazy tm) = if doLazyAnnots then liftExp {doLazyAnnots} {lazy = Just lazy} tm else liftExp {doLazyAnnots} (CLam fc (MN "act" 0) (weaken tm)) liftExp (CConCase fc sc alts def) = pure $ LConCase fc !(liftExp {doLazyAnnots} sc) !(traverse (liftConAlt {lazy}) alts) !(traverseOpt (liftExp {doLazyAnnots}) def) where liftConAlt : {default Nothing lazy : Maybe LazyReason} -> CConAlt vars -> Core (LiftedConAlt vars) liftConAlt (MkConAlt n ci t args sc) = pure $ MkLConAlt n ci t args !(liftExp {doLazyAnnots} {lazy} sc) liftExp (CConstCase fc sc alts def) = pure $ LConstCase fc !(liftExp {doLazyAnnots} sc) !(traverse liftConstAlt alts) !(traverseOpt (liftExp {doLazyAnnots}) def) where liftConstAlt : {default Nothing lazy : Maybe LazyReason} -> CConstAlt vars -> Core (LiftedConstAlt vars) liftConstAlt (MkConstAlt c sc) = pure $ MkLConstAlt c !(liftExp {doLazyAnnots} {lazy} sc) liftExp (CPrimVal fc c) = pure $ LPrimVal fc c liftExp (CErased fc) = pure $ LErased fc liftExp (CCrash fc str) = pure $ LCrash fc str usedVars : {vars : _} -> {auto l : Ref Lifts LDefs} -> Used vars -> Lifted vars -> Used vars usedVars used (LLocal {idx} fc prf) = markUsed {prf} idx used usedVars used (LAppName fc lazy n args) = foldl (usedVars {vars}) used args usedVars used (LUnderApp fc n miss args) = foldl (usedVars {vars}) used args usedVars used (LApp fc lazy c arg) = usedVars (usedVars used arg) c usedVars used (LLet fc x val sc) = let innerUsed = contractUsed $ usedVars (weakenUsed {outer=[x]} used) sc in usedVars innerUsed val usedVars used (LCon fc n ci tag args) = foldl (usedVars {vars}) used args usedVars used (LOp fc lazy fn args) = foldl (usedVars {vars}) used args usedVars used (LExtPrim fc lazy fn args) = foldl (usedVars {vars}) used args usedVars used (LConCase fc sc alts def) = let defUsed = maybe used (usedVars used {vars}) def scDefUsed = usedVars defUsed sc in foldl usedConAlt scDefUsed alts where usedConAlt : {default Nothing lazy : Maybe LazyReason} -> Used vars -> LiftedConAlt vars -> Used vars usedConAlt used (MkLConAlt n ci tag args sc) = contractUsedMany {remove=args} (usedVars (weakenUsed used) sc) usedVars used (LConstCase fc sc alts def) = let defUsed = maybe used (usedVars used {vars}) def scDefUsed = usedVars defUsed sc in foldl usedConstAlt scDefUsed alts where usedConstAlt : {default Nothing lazy : Maybe LazyReason} -> Used vars -> LiftedConstAlt vars -> Used vars usedConstAlt used (MkLConstAlt c sc) = usedVars used sc usedVars used (LPrimVal _ _) = used usedVars used (LErased _) = used usedVars used (LCrash _ _) = used dropIdx : {vars : _} -> {idx : _} -> (outer : List Name) -> (unused : Vect (length vars) Bool) -> (0 p : IsVar x idx (outer ++ vars)) -> Var (outer ++ (dropped vars unused)) dropIdx [] (False::_) First = MkVar First dropIdx [] (True::_) First = assert_total $ idris_crash "INTERNAL ERROR: Referenced variable marked as unused" dropIdx [] (False::rest) (Later p) = Var.later $ dropIdx [] rest p dropIdx [] (True::rest) (Later p) = dropIdx [] rest p dropIdx (_::xs) unused First = MkVar First dropIdx (_::xs) unused (Later p) = Var.later $ dropIdx xs unused p dropUnused : {vars : _} -> {auto l : Ref Lifts LDefs} -> {outer : List Name} -> (unused : Vect (length vars) Bool) -> (l : Lifted (outer ++ vars)) -> Lifted (outer ++ (dropped vars unused)) dropUnused _ (LPrimVal fc val) = LPrimVal fc val dropUnused _ (LErased fc) = LErased fc dropUnused _ (LCrash fc msg) = LCrash fc msg dropUnused {outer} unused (LLocal fc p) = let (MkVar p') = dropIdx outer unused p in LLocal fc p' dropUnused unused (LCon fc n ci tag args) = let args' = map (dropUnused unused) args in LCon fc n ci tag args' dropUnused {outer} unused (LLet fc n val sc) = let val' = dropUnused unused val sc' = dropUnused {outer=n::outer} (unused) sc in LLet fc n val' sc' dropUnused unused (LApp fc lazy c arg) = let c' = dropUnused unused c arg' = dropUnused unused arg in LApp fc lazy c' arg' dropUnused unused (LOp fc lazy fn args) = let args' = map (dropUnused unused) args in LOp fc lazy fn args' dropUnused unused (LExtPrim fc lazy n args) = let args' = map (dropUnused unused) args in LExtPrim fc lazy n args' dropUnused unused (LAppName fc lazy n args) = let args' = map (dropUnused unused) args in LAppName fc lazy n args' dropUnused unused (LUnderApp fc n miss args) = let args' = map (dropUnused unused) args in LUnderApp fc n miss args' dropUnused {vars} {outer} unused (LConCase fc sc alts def) = let alts' = map dropConCase alts in LConCase fc (dropUnused unused sc) alts' (map (dropUnused unused) def) where dropConCase : LiftedConAlt (outer ++ vars) -> LiftedConAlt (outer ++ (dropped vars unused)) dropConCase (MkLConAlt n ci t args sc) = let sc' = (rewrite sym $ appendAssociative args outer vars in sc) droppedSc = dropUnused {vars=vars} {outer=args++outer} unused sc' in MkLConAlt n ci t args (rewrite appendAssociative args outer (dropped vars unused) in droppedSc) dropUnused {vars} {outer} unused (LConstCase fc sc alts def) = let alts' = map dropConstCase alts in LConstCase fc (dropUnused unused sc) alts' (map (dropUnused unused) def) where dropConstCase : LiftedConstAlt (outer ++ vars) -> LiftedConstAlt (outer ++ (dropped vars unused)) dropConstCase (MkLConstAlt c val) = MkLConstAlt c (dropUnused unused val) export liftBody : {vars : _} -> {doLazyAnnots : Bool} -> Name -> CExp vars -> Core (Lifted vars, List (Name, LiftedDef)) liftBody n tm = do l <- newRef Lifts (MkLDefs n [] 0) tml <- liftExp {doLazyAnnots} {l} tm ldata <- get Lifts pure (tml, defs ldata) export lambdaLiftDef : (doLazyAnnots : Bool) -> Name -> CDef -> Core (List (Name, LiftedDef)) lambdaLiftDef doLazyAnnots n (MkFun args exp) = do (expl, defs) <- liftBody {doLazyAnnots} n exp pure ((n, MkLFun args [] expl) :: defs) lambdaLiftDef _ n (MkCon t a nt) = pure [(n, MkLCon t a nt)] lambdaLiftDef _ n (MkForeign ccs fargs ty) = pure [(n, MkLForeign ccs fargs ty)] lambdaLiftDef doLazyAnnots n (MkError exp) = do (expl, defs) <- liftBody {doLazyAnnots} n exp pure ((n, MkLError expl) :: defs) -- Return the lambda lifted definitions required for the given name. -- If the name hasn't been compiled yet (via CompileExpr.compileDef) then -- this will return an empty list -- An empty list an error, because on success you will always get at least -- one definition, the lifted definition for the given name. export lambdaLift : {auto c : Ref Ctxt Defs} -> (doLazyAnnots : Bool) -> (Name,FC,CDef) -> Core (List (Name, LiftedDef)) lambdaLift doLazyAnnots (n,_,def) = lambdaLiftDef doLazyAnnots n def
theory Formula imports BDT begin type_synonym atom = bool datatype binop = And | Or | Impl (* inductive definition of abstract syntax trees for formula *) datatype form = Var "var" | Atom "atom" | Neg "form" | Bin "binop" "form" "form" text \<open> Notations \<close> syntax "_top" :: "form" ("top\<^sub>F") translations "top\<^sub>F" == "(CONST Atom) (CONST True)" syntax "_bot" :: "form" ("bot\<^sub>F") translations "bot\<^sub>F" == "(CONST Atom) (CONST False)" syntax "_neg" :: "form \<Rightarrow> form" ("neg\<^sub>F _") translations "neg\<^sub>F F" == "(CONST Neg) F" syntax "_and" :: "form \<Rightarrow> form \<Rightarrow> form" ("and\<^sub>F _ _") translations "and\<^sub>F F1 F2" == "(CONST Bin) (CONST And) F1 F2" syntax "_or" :: "form \<Rightarrow> form \<Rightarrow> form" ("or\<^sub>F _ _") translations "or\<^sub>F F1 F2" == "(CONST Bin) (CONST Or) F1 F2" syntax "_impl" :: "form \<Rightarrow> form \<Rightarrow> form" ("impl\<^sub>F _ _") translations "impl\<^sub>F F1 F2" == "(CONST Bin) (CONST Impl) F1 F2" (** Test cases *) definition p0 where "p0 = Var 0" definition p1 where "p1 = Var 1" definition p2 where "p2 = Var 2" definition P0 where "P0 = impl\<^sub>F p0 p1" definition P1 where "P1 = impl\<^sub>F p1 P0" definition dnegp where "dnegp P Q = (impl\<^sub>F (impl\<^sub>F P Q) Q)" definition P2 where "P2 = dnegp P0 p0" (** ** Semantic *) (* Boolean interpretation of binary operators *) fun interp ("I\<^sub>f\<^sub>o\<^sub>r\<^sub>m") where "I\<^sub>f\<^sub>o\<^sub>r\<^sub>m _ _ = undefined" (* a completer *) value "I\<^sub>f\<^sub>o\<^sub>r\<^sub>m P2 Itrue " value "I\<^sub>f\<^sub>o\<^sub>r\<^sub>m P2 Ifalse " value "I\<^sub>f\<^sub>o\<^sub>r\<^sub>m P2 (list2interpretation [True,False] False) " value "I\<^sub>f\<^sub>o\<^sub>r\<^sub>m P2 (list2interpretation [False,True] False) " (** ** Equivalence *) definition equiv where "equiv P Q = (\<forall>I. I\<^sub>f\<^sub>o\<^sub>r\<^sub>m P I = I\<^sub>f\<^sub>o\<^sub>r\<^sub>m Q I)" lemma negimpl : "equiv (neg\<^sub>F (impl\<^sub>F P Q)) (and\<^sub>F P (neg\<^sub>F Q))" unfolding equiv_def by auto lemma implor : "equiv (impl\<^sub>F P Q) (or\<^sub>F (neg\<^sub>F P) Q)" unfolding equiv_def by auto (** ** Validity *) definition valid where "valid P = (\<forall> I. I\<^sub>f\<^sub>o\<^sub>r\<^sub>m P I = True)" lemma Pierce :" valid (impl\<^sub>F (impl\<^sub>F (impl\<^sub>F P Q) P) P)" unfolding valid_def by auto end
ifelse(sqrt(9)<2,sqrt(9),0) ifelse(sqrt(100)>9,sqrt(100),0) x=12 if(is.numeric(x)) y=x*2 y z=6 if(z<0) { y=z*3 }else { y=z*5 } y x=15 y=3 if(is.numeric(x)) if(is.numeric(y) & y!=0) z=x/y z x=letters[20] if(is.numeric(x)) print("Is numeric"); if(is.character(x)) print("Is character"); z=='i' if(z%in% letters) { if(z=='a') { n=1 }else if(z=='e') { n=2 }else if(z=='b') { n=3 }else if(z=='i') { n=4 }else { n=5 } } n
module Main import GLCore import JSArrays import Shaders -- Save time, just get the canvas directly by id getElemById : String -> IO Element getElemById s = do x <- mkForeign (FFun "document.getElementById(%0)" [FString] FPtr) s return (MkElem x) -- Shader Functions vShader : String vShader = "attribute vec2 pos;void main() { gl_Position = vec4(pos, 0, 1); }" fShader : String fShader = "precision mediump float;void main() { gl_FragColor = vec4(0,0.8,0,1); }" -- Create the 2D Vector -- Populate the 2D Vector -- var vertices = [-0.5, -0.5, 0.5, -0.5, 0, 0.5] triangleVertices : List Float triangleVertices = [-0.5, -0.5, 0.5, -0.5, 0, 0.5] -- Some basic settings for starting our GL env baseGLInit : GLCxt -> IO GLCxt baseGLInit c = do clearColor c enableGLSetting c depthFun c glClear c -- Create an array, populate it with vertices, and use it to create a proper Float32Array prepareTriangleArray : IO F32Array prepareTriangleArray = createJSArray >>= fromFloatList triangleVertices >>= createF32Array -- Wrapper for finding and init'ing our GL env and context locateInitCanvas : IO GLCxt locateInitCanvas = getElemById "canvas" >>= getGLCxt >>= baseGLInit -- Wrapper for the process of assigning a shader variable the correct location -- for our program to locate vertex information when the shader runs. assignVertexPositionAttribs : (GLProgram,GLCxt) -> IO (GLProgram,GLCxt) assignVertexPositionAttribs glProg = getAttribLocation "pos" glProg >>= setVertexPosAttrib glProg >>= enableVertexAttribArray >>= setVertexAttribPointer 2 main : IO () main = do f32Arr <- prepareTriangleArray -- prepare our vertices glCxt <- locateInitCanvas -- start our engines buffer <- createBuffer glCxt -- create a buffer to store our vertex information bindArrayBuffer glCxt buffer -- bind the buffer to the current gl context program <- bufferVertexData f32Arr glCxt >>= createProg -- fill the buffer with vertex info -- Pass our shader code to be built,compiled, and linked to the GL context compileAndLinkShaders [(Vertex vShader),(Fragment fShader)] program glCxt >>= useProg -- set the gl context to use this created program >>= assignVertexPositionAttribs -- assign our pointer information for the shaders >>= \glProg => drawTriangles glProg 0 3 -- draw our vertices to the screen putStrLn "We're finished?"
[STATEMENT] lemma iflt_inj_image_correct: assumes "set_inj_image_filter \<alpha>1 invar1 \<alpha>2 invar2 iflt" shows "set_inj_image \<alpha>1 invar1 \<alpha>2 invar2 (iflt_inj_image iflt)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. set_inj_image \<alpha>1 invar1 \<alpha>2 invar2 (iflt_inj_image iflt) [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. set_inj_image \<alpha>1 invar1 \<alpha>2 invar2 (iflt_inj_image iflt) [PROOF STEP] interpret set_inj_image_filter \<alpha>1 invar1 \<alpha>2 invar2 iflt [PROOF STATE] proof (prove) goal (1 subgoal): 1. set_inj_image_filter \<alpha>1 invar1 \<alpha>2 invar2 iflt [PROOF STEP] by fact [PROOF STATE] proof (state) goal (1 subgoal): 1. set_inj_image \<alpha>1 invar1 \<alpha>2 invar2 (iflt_inj_image iflt) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) goal (1 subgoal): 1. set_inj_image \<alpha>1 invar1 \<alpha>2 invar2 (iflt_inj_image iflt) [PROOF STEP] apply (unfold_locales) [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> \<alpha>2 (iflt_inj_image iflt f s) = f ` \<alpha>1 s 2. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> invar2 (iflt_inj_image iflt f s) [PROOF STEP] apply (unfold iflt_image_def iflt_inj_image_def) [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> \<alpha>2 (iflt (\<lambda>x. Some (f x)) s) = f ` \<alpha>1 s 2. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> invar2 (iflt (\<lambda>x. Some (f x)) s) [PROOF STEP] apply (subst inj_image_filter_correct) [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> invar1 s 2. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> inj_on (\<lambda>x. Some (f x)) (\<alpha>1 s \<inter> dom (\<lambda>x. Some (f x))) 3. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> {b. \<exists>a\<in>\<alpha>1 s. Some (f a) = Some b} = f ` \<alpha>1 s 4. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> invar2 (iflt (\<lambda>x. Some (f x)) s) [PROOF STEP] apply (auto simp add: dom_const intro: inj_onI dest: inj_onD) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> invar2 (iflt (\<lambda>x. Some (f x)) s) [PROOF STEP] apply (subst inj_image_filter_correct) [PROOF STATE] proof (prove) goal (3 subgoals): 1. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> invar1 s 2. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> inj_on (\<lambda>x. Some (f x)) (\<alpha>1 s \<inter> dom (\<lambda>x. Some (f x))) 3. \<And>s f. \<lbrakk>invar1 s; inj_on f (\<alpha>1 s)\<rbrakk> \<Longrightarrow> True [PROOF STEP] apply (auto simp add: dom_const intro: inj_onI dest: inj_onD) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done [PROOF STATE] proof (state) this: set_inj_image \<alpha>1 invar1 \<alpha>2 invar2 (iflt_inj_image iflt) goal: No subgoals! [PROOF STEP] qed
module Flexidisc.OrdList.Diff import public Flexidisc.OrdList.Disjoint import public Flexidisc.OrdList.Fresh import public Flexidisc.OrdList.Label import public Flexidisc.OrdList.Sub import public Flexidisc.OrdList.Type %default total %access public export ||| compute the difference between the first and the second list. diffKeys : DecEq k => (xs, ys : OrdList k v o) -> OrdList k v o diffKeys [] ys = [] diffKeys ((lx, vx) :: xs) ys with (decFresh lx ys) | Yes prf = (lx, vx) :: diffKeys xs ys | No contra = diffKeys xs ys ||| Apply a patch `xs` to an `OrdList` `ys`. ||| The label of `ys` that are in `xs` are updated, ||| and the fresh element of `xs` are added patch : DecEq k => (xs, ys : OrdList k v o) -> OrdList k v o patch xs ys = merge (diffKeys ys xs) xs diffIsSub : DecEq k => {xs : OrdList k v o} -> Sub (diffKeys xs ys) xs diffIsSub {xs = []} = Empty diffIsSub {xs = (lx, vx) :: xs} {ys} with (decFresh lx ys) | Yes prf = Keep diffIsSub | No contra = Skip diffIsSub diffIsDisjoint : DecEq k => {xs : OrdList k v o} -> Disjoint (diffKeys xs ys) ys diffIsDisjoint {xs = []} = [] diffIsDisjoint {xs = (kx, vx) :: xs} {ys} with (decFresh kx ys) | Yes prf = isFreshFromEvidence prf :: diffIsDisjoint | No contra = diffIsDisjoint
{-# OPTIONS --without-K --safe #-} open import Level using (Level) open import Data.List using (List; sum) renaming ([] to []ᴸ; _∷_ to _∷ᴸ_) open import Data.Nat using (ℕ; _+_; zero; suc) open import Data.Vec using (Vec; _++_; take; drop) renaming ([] to []ⱽ; _∷_ to _∷ⱽ_) open import Data.Product as Prod using (∃; ∃₂; _×_; _,_) module FLA.Data.VectorList where -- At the moment, `VectorList` is named `RList` in the Haskell code. data VectorList (A : Set) : List ℕ → Set where []ⱽᴸ : VectorList A []ᴸ _∷ⱽᴸ_ : {n : ℕ} {ns : List ℕ} → Vec A n → VectorList A ns → VectorList A (n ∷ᴸ ns) infixr 5 _∷ⱽᴸ_ concat : {A : Set} {ns : List ℕ} → VectorList A ns → Vec A (sum ns) concat []ⱽᴸ = []ⱽ concat (v ∷ⱽᴸ vs) = v ++ concat vs -- We will want to use split to split a VectorList split : {ℓ : Level} {A : Set ℓ} → {m n : ℕ} → Vec A (m + n) → Vec A m × Vec A n split {ℓ} {A} {zero} {n} v = []ⱽ , v split {ℓ} {A} {suc m} {n} (v ∷ⱽ vs) = let v₁ , v₂ = split vs in v ∷ⱽ v₁ , v₂ -- split' : {ℓ : Level} {A : Set ℓ} → {m n : ℕ} → Vec A (m + n) → Vec A m × Vec A n -- split' {ℓ} {A} {m} {n} v = (take v , drop v) -- Hmm, this will be hard to translate to Haskell, since we match on ns splitToVectorList : {A : Set} → (ns : List ℕ) → Vec A (sum ns) → VectorList A ns splitToVectorList []ᴸ v = []ⱽᴸ splitToVectorList (_ ∷ᴸ ns) v = let v₁ , v₂ = split v in v₁ ∷ⱽᴸ (splitToVectorList ns v₂)
module Rect public export record Rect where constructor CreateRect x : Double y : Double x2 : Double y2 : Double
// This file is part of SWGANH which is released under the MIT license. // See file LICENSE or go to http://swganh.com/LICENSE #include "smf_session_provider.h" #include <boost/date_time/posix_time/posix_time.hpp> #include <cppconn/exception.h> #include <cppconn/connection.h> #include <cppconn/resultset.h> #include <cppconn/statement.h> #include <cppconn/prepared_statement.h> #include <cppconn/sqlstring.h> #include "anh/logger.h" using namespace anh::database; using namespace plugins::smf_auth; using namespace std; using namespace swganh::connection; SmfSessionProvider::SmfSessionProvider( DatabaseManagerInterface* database_manager, string table_prefix) : database_manager_(database_manager) , table_prefix_(table_prefix) {} uint64_t SmfSessionProvider::GetPlayerId(uint32_t account_id) { uint64_t player_id = FindPlayerByReferenceId_(account_id); if (player_id == 0) { CreatePlayerAccount_(account_id); player_id = FindPlayerByReferenceId_(account_id); } return player_id; } bool SmfSessionProvider::CreatePlayerAccount_(uint64_t account_id) { bool success = false; try { string sql = "call sp_CreatePlayerAccount(?);"; auto conn = database_manager_->getConnection("galaxy"); auto statement = shared_ptr<sql::PreparedStatement>(conn->prepareStatement(sql)); statement->setUInt64(1, account_id); auto rows_updated = statement->executeUpdate(); if (rows_updated > 0) success = true; } catch(sql::SQLException &e) { LOG(error) << "SQLException at " << __FILE__ << " (" << __LINE__ << ": " << __FUNCTION__ << ")"; LOG(error) << "MySQL Error: (" << e.getErrorCode() << ": " << e.getSQLState() << ") " << e.what(); } return success; } uint64_t SmfSessionProvider::FindPlayerByReferenceId_(uint64_t account_id) { uint64_t player_id = 0; try { string sql = "select id from player_account where reference_id = ?"; auto conn = database_manager_->getConnection("galaxy"); auto statement = shared_ptr<sql::PreparedStatement>(conn->prepareStatement(sql)); statement->setUInt64(1, account_id); auto result_set = unique_ptr<sql::ResultSet>(statement->executeQuery()); if (result_set->next()) { player_id = result_set->getUInt64("id"); } else { LOG(warning) << "No Player Id found for account_id: " << account_id << endl; } } catch(sql::SQLException &e) { LOG(error) << "SQLException at " << __FILE__ << " (" << __LINE__ << ": " << __FUNCTION__ << ")"; LOG(error) << "MySQL Error: (" << e.getErrorCode() << ": " << e.getSQLState() << ") " << e.what(); } return player_id; } bool SmfSessionProvider::CreateGameSession(uint64_t player_id, uint32_t session_id) { bool updated = false; // create new game session std::string game_session = boost::posix_time::to_simple_string(boost::posix_time::microsec_clock::local_time()) + boost::lexical_cast<std::string>(session_id); try { string sql = "INSERT INTO player_session(player,session_key) VALUES (?,?)"; auto conn = database_manager_->getConnection("galaxy"); auto statement = shared_ptr<sql::PreparedStatement>(conn->prepareStatement(sql)); statement->setUInt64(1, player_id); statement->setString(2, game_session); auto rows_updated = statement->executeUpdate(); if (rows_updated > 0) { updated = true; } else { LOG(warning) << "Couldn't create session for player " << player_id << endl; } } catch(sql::SQLException &e) { LOG(error) << "SQLException at " << __FILE__ << " (" << __LINE__ << ": " << __FUNCTION__ << ")"; LOG(error) << "MySQL Error: (" << e.getErrorCode() << ": " << e.getSQLState() << ") " << e.what(); } return updated; } void SmfSessionProvider::EndGameSession(uint64_t player_id) { try { string sql = "DELETE FROM player_session where player = ?"; auto conn = database_manager_->getConnection("galaxy"); auto statement = shared_ptr<sql::PreparedStatement>(conn->prepareStatement(sql)); statement->setUInt64(1, player_id); auto rows_updated = statement->executeUpdate(); if (rows_updated <= 0) { LOG(warning) << "Couldn't delete session for player " << player_id << endl; } } catch(sql::SQLException &e) { LOG(error) << "SQLException at " << __FILE__ << " (" << __LINE__ << ": " << __FUNCTION__ << ")"; LOG(error) << "MySQL Error: (" << e.getErrorCode() << ": " << e.getSQLState() << ") " << e.what(); } } uint32_t SmfSessionProvider::GetAccountId(uint64_t player_id) { uint32_t account_id = 0; try { string sql = "select reference_id from player_account where id = ?"; auto conn = database_manager_->getConnection("galaxy"); auto statement = shared_ptr<sql::PreparedStatement>(conn->prepareStatement(sql)); statement->setUInt64(1, player_id); auto result_set = unique_ptr<sql::ResultSet>(statement->executeQuery()); if (result_set->next()) { account_id = result_set->getUInt("reference_id"); } else { LOG(warning) << "No account Id found for player id : " << player_id << endl; } } catch(sql::SQLException &e) { LOG(error) << "SQLException at " << __FILE__ << " (" << __LINE__ << ": " << __FUNCTION__ << ")"; LOG(error) << "MySQL Error: (" << e.getErrorCode() << ": " << e.getSQLState() << ") " << e.what(); } return account_id; }
REBOL [ Name: "Volker's script for resize testing" Author: "DocKimbel/Softinnov" Date: 08/08/2002 ] do %../auto-resize.r lay: layout [ across button "save&close" rot: rotary data ["first" "second"] rot2: rotary data ["a" "b"] rot3: rotary data ["a" "b"] return ta: area 400x300 mold system/script/header resize-all sl: scroller 16x300 resize-v user-data ta [ scroll-para face/user-data face ] return area 196x50 "empty" resize-all area 196x50 "empty too" resize-all sensor 20x50 resize-v ; invisible face added to "balance" the layout, so the do [ ; resize works exactly as expected. (you can test without it...) sl/data: 0 scroll-para ta sl ] ] view/options lay 'resize ; min-size 476x457
module Verilog #support for -v suffixed verilog-style ranges. #support for python-style range() indexing include("verilog_ranges.jl") include("Wire.jl") include("wire-display.jl") include("booleanops.jl") include("arithmeticops.jl") #the magical verilog macro include("verilog_macro.jl") #verigen - where verilog generation happens include("Verigen.jl") #verilog generation passes these objects around. include("WireObject.jl") #codegen contains resources to create .v files and verilate them. if is_linux() include("codegen.jl") include("verilator-adapter.c.jl") end end # module
% elementwise production of all previous layers, which are required to have the % same size. % classdef HadamardNode < GraphNode methods function obj = HadamardNode(dimOut) obj = obj@GraphNode('Hadamard',dimOut); end function obj = forward(obj,prev_layers) obj = obj.preprocessingForward(prev_layers); obj.a = prev_layers{1}.a; for i=2:length(prev_layers) obj.a = obj.a .* conj(prev_layers{i}.a); end obj = forward@GraphNode(obj, prev_layers); end function obj = backward(obj,prev_layers, future_layers) if obj.skipGrad || obj.skipBP return; end future_grad = obj.GetFutureGrad(future_layers); for i=1:length(prev_layers) [D(1) D(2) D(3) D(4)] = size(prev_layers{i}.a); if i==1 grad = future_grad .* prev_layers{2}.a; else grad = future_grad .* prev_layers{1}.a; end for j = 1:4 if D(j) == 1 grad = sum(grad,j); end end obj.grad{i} = conj(grad); end obj = backward@GraphNode(obj, prev_layers, future_layers); end end end
variables (α : Type*) (r : α → α → Prop) variable trans_r : ∀ {x y z}, r x y → r y z → r x z variables (a b c : α) variables (hab : r a b) (hbc : r b c) #check trans_r #check trans_r hab #check trans_r hab hbc variable refl_r : ∀ x, r x x variable symm_r : ∀ {x y}, r x y → r y x example (a b c d : α ) (hab : r a b) (hcb : r c b) (hcd : r c d) : r a d := trans_r (trans_r hab (symm_r hcb)) hcd
C ********************************************************* C * * C * TEST NUMBER: 03.01/01 * C * TEST TITLE : Effect of <open archive file> and * C * <close archive file> * C * * C * PHIGS Validation Tests, produced by NIST * C * * C ********************************************************* COMMON /GLOBNU/ CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR, 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN, 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN, 3 DUMINT, DUMRL INTEGER CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR, 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN, 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN, 3 DUMINT(20), ERRIND REAL DUMRL(20) COMMON /GLOBCH/ PIDENT, GLBERR, TSTMSG, FUNCID, 1 DUMCH CHARACTER PIDENT*40, GLBERR*60, TSTMSG*900, FUNCID*80, 1 DUMCH(20)*20 C archive state C closed open INTEGER PARCL, PAROP PARAMETER (PARCL=0, PAROP=1) INTEGER PGMAX PARAMETER (PGMAX = 200) INTEGER ARID, ARNM, ALISIZ, MXARNO, ARSTAT, CUSTID, 1 ACIDLS(PGMAX), ACNMLS(PGMAX), 2 EXIDLS(PGMAX), EXNMLS(PGMAX), 2 IDUM1, IDUM2, IDUM3, IDUM4, IDUM5, IDUM6, 3 STRUID, ARCNUM, CNT, NUMSTR, LOOPCT LOGICAL OPENOK, CLOSOK, STATOK, ARSET, ACCOK, SETEQ CHARACTER MSG*300 C Throughout, use variable names: C arid : archive file identifier C arnm : archive file name C mxarno : maximum number of simultaneously open archive files C arstat : archive file state C openok : <open archive file> ok flag C closok : <close archive file> ok flag C statok : archive state ok flag C arset : open archive file set ok flag C accok : access archive file ok flag C alisiz : actual size of open archive list C acidls : actual open archive file id. list C acnmls : actual open archive file name list C exidls : expected open archive file id. list C exnmls : expected open archive file name list C arcnum : opened archive file counter C struid : structure identifier C custid : structure identifier list in CSS CALL INITGL ('03.01/01') CALL SETMSG ('10', 'Before opening PHIGS, <inquire archive ' // 1 'state value> should return the archive state as ' // 2 'ARCL.') C <Inquire archive state value> to determine C arstat = archive file state ARSTAT = -66 CALL PQARS (ARSTAT) CALL IFPF (ARSTAT .EQ. PARCL) CALL XPOPPH (ERRFIL, MEMUN) CALL SETMSG ('3 10', 'Immediately after <open phigs>, the ' // 1 'archive state should be reported as ARCL.') ARSTAT = -66 CALL PQARS (ARSTAT) CALL IFPF (ARSTAT .EQ. PARCL) CALL SETMSG ('4 11', 'Immediately after <open phigs>, the set ' // 1 'of open archive files should be reported as empty.') C <Inquire archive files> to determine acidls ALISIZ = -66 CALL PQARF (0, ERRIND, ALISIZ, IDUM1, IDUM2) CALL IFPF (ERRIND .EQ. 0 .AND. ALISIZ .EQ. 0) CALL SETMSG ('1 2', '<Inquire phigs facilities> should report ' // 1 'the maximum number of simultaneously open ' // 2 'archive files to be greater than 0.') C <Inquire phigs facilities> to determine C mxarno = maximum number of simultaneously open archive files CALL PQPHF (0, ERRIND, IDUM1, MXARNO, IDUM2, IDUM3, IDUM4, IDUM5, 1 IDUM6) IF (ERRIND .EQ. 0 .AND. MXARNO .GT. 0) THEN CALL PASS ELSE CALL FAIL WRITE (MSG, '(A,I5,A,I5,A)') '<Inquire phigs facilities> ' // 1 'reported error indicator = ', ERRIND, 2 ' and maximum open archive files = ', MXARNO, 3 '. Skipping opening/closing tests.' CALL INMSG (MSG) GOTO 500 ENDIF OPENOK = .TRUE. STATOK = .TRUE. ARSET = .TRUE. ACCOK = .TRUE. C loop to open simultaneously the maximum number of archive files, C up to the program maximum LOOPCT = MIN(PGMAX, MXARNO) DO 100 ARCNUM = 1, LOOPCT ARID = ARCNUM + 10 CALL AVARNM (ARNM) CALL ERRCTL (.TRUE.) C open next archive file CALL POPARF (ARID, ARNM) CALL ERRCTL (.FALSE.) IF (ERRSIG .NE. 0) THEN WRITE (MSG, '(A,I5,A,I4,A)') 'Got error ', ERRSIG, 1 ' when attempting to open archive file named ', 2 ARNM, '.' CALL INMSG (MSG) OPENOK = .FALSE. GOTO 100 ENDIF C <Inquire archive state value> to determine C arstat = archive file state ARSTAT = -66 CALL PQARS (ARSTAT) IF (ARSTAT .NE. PAROP) THEN STATOK = .FALSE. ENDIF C expected list of open archive files EXIDLS (ARCNUM) = ARID EXNMLS (ARCNUM) = ARNM C get actual list of open archive files CALL PQARF (0, ERRIND, ALISIZ, IDUM1, IDUM2) IF (ERRIND .NE. 0) THEN ARSET = .FALSE. GOTO 210 ENDIF DO 200 CNT = 1, ALISIZ CALL PQARF (CNT, ERRIND, IDUM1, ACIDLS(CNT), ACNMLS(CNT)) IF (ERRIND .NE. 0) THEN ARSET = .FALSE. GOTO 210 ENDIF 200 CONTINUE C compare expected and actual list of open archive files IF (ALISIZ .EQ. ARCNUM .AND. 1 SETEQ (ALISIZ, EXIDLS, ACIDLS) .AND. 2 SETEQ (ALISIZ, EXNMLS, ACNMLS)) THEN C OK so far ELSE ARSET = .FALSE. ENDIF 210 CONTINUE C create structure and test access CALL PDAS CALL PDASAR (ARID) STRUID = ARCNUM+20 CALL POPST (STRUID) CALL PLB (ARCNUM+30) CALL PCLST C <archive all structures> with arid CALL PARAST (ARID) CALL PDAS C <retrieve all structures> with arid CALL PRAST (ARID) C <inquire structure identifiers> to determine: C custid = current structure identifier list in CSS CALL PQSID (1, ERRIND, NUMSTR, CUSTID) IF (ERRIND .EQ. 0 .AND. 1 NUMSTR .EQ. 1 .AND. 2 CUSTID .EQ. STRUID) THEN C OK so far ELSE ACCOK = .FALSE. ENDIF C end_open_loop 100 CONTINUE C CALL SETMSG ('1 2', 'Opening the maximum number of ' // 1 'simultaneously open archive files should be ' // 2 'allowed.') CALL IFPF (OPENOK) CALL SETMSG ('5 10', 'A successful <open archive file> should ' // 1 'set the archive state to AROP.') CALL IFPF (STATOK) CALL SETMSG ('6 11', 'A successful <open archive file> should ' // 1 'add the specified file to the set of open ' // 2 'archive files.') CALL IFPF (ARSET) CALL SETMSG ('7', 'A successful <open archive file> should ' // 1 'provide access to the archive file of the ' // 2 'specified name through the specified identifier.') CALL IFPF (ACCOK) CLOSOK = .TRUE. STATOK = .TRUE. ARSET = .TRUE. C loop to close the archive files DO 300 ARCNUM = LOOPCT, 1, -1 ARID = ARCNUM + 10 CALL ERRCTL (.TRUE.) CALL PCLARF (ARID) CALL ERRCTL (.FALSE.) IF (ERRSIG .NE. 0) THEN WRITE (MSG, '(A,I5,A,I4,A)') 'Got error ', ERRSIG, 1 ' when attempting to close archive file with ' // 2 'identifier #', ARID, '.' CALL INMSG (MSG) CLOSOK = .FALSE. ENDIF C check archive state value ARSTAT = -66 CALL PQARS (ARSTAT) IF (ARCNUM .EQ. 1) THEN IF (ARSTAT .NE. PARCL) THEN STATOK = .FALSE. ENDIF ELSE IF (ARSTAT .NE. PAROP) THEN STATOK = .FALSE. ENDIF ENDIF C get actual list of open archive files CALL PQARF (0, ERRIND, ALISIZ, IDUM1, IDUM2) IF (ERRIND .NE. 0) THEN ARSET = .FALSE. GOTO 410 ENDIF DO 400, CNT = 1, ALISIZ CALL PQARF (CNT, ERRIND, IDUM1, ACIDLS(CNT), ACNMLS(CNT)) IF (ERRIND .NE. 0) THEN ARSET = .FALSE. GOTO 410 ENDIF 400 CONTINUE C compare expected and actual list of open archive files IF (ALISIZ .EQ. ARCNUM - 1 .AND. 1 SETEQ (ALISIZ, EXIDLS, ACIDLS) .AND. 2 SETEQ (ALISIZ, EXNMLS, ACNMLS)) THEN C OK so far ELSE ARSET = .FALSE. ENDIF 410 CONTINUE 300 CONTINUE C CALL SETMSG ('8 10', 'A successful <close archive file> on ' // 1 'the last open archive file should set the ' // 2 'archive state to ARCL, but otherwise leave the ' // 3 'state as AROP.') CALL IFPF (STATOK) CALL SETMSG ('9', 'Closing an archive file in the set of open ' // 1 'archive files should succeed.') CALL IFPF (CLOSOK) CALL SETMSG ('9 11', 'A successful <close archive file> ' // 1 'should remove the specified file from the set ' // 2 'of open archive files.') CALL IFPF (ARSET) C check_close: 500 CONTINUE CALL PCLPH CALL SETMSG ('10', 'After closing PHIGS, <inquire archive ' // 1 'state value> should return the archive state as ' // 2 'ARCL.') ARSTAT = -66 CALL PQARS (ARSTAT) CALL IFPF (ARSTAT .EQ. PARCL) CALL XPOPPH (ERRFIL, MEMUN) CALL SETMSG ('3 10', 'After closing and re-opening PHIGS, the ' // 1 'archive state should be reported as ARCL.') ARSTAT = -66 CALL PQARS (ARSTAT) CALL IFPF (ARSTAT .EQ. PARCL) CALL SETMSG ('4 11', 'After closing and re-opening PHIGS, the ' // 1 'set of open archive files should be reported as ' // 2 'empty.') CALL PQARF (0, ERRIND, ALISIZ, IDUM1, IDUM2) CALL IFPF (ERRIND .EQ. 0 .AND. ALISIZ .EQ. 0) 666 CONTINUE CALL ENDIT END
Doha – 26 June 2016 (WQ): In light of the holy month of Ramadan, Oryx Rotana distributed Iftar packages to motorists who were stuck in traffic and couldn’t make it home on time for Iftar. This initiative was inspired by the hotel’s endless CSR efforts to give back to the community. All packages were prepared and distributed in accordance to high food and traffic safety standards. Oryx Rotana simultaneously celebrated the Garangao night in the lobby, Choices restaurant and colleagues’ Dine-Inn. Garangao is an age-old annual Qatari tradition that falls on the 14th night of Ramadan. Numerous candy boxes were distributed to kids in order to celebrate this important part of the Qatari heritage during the Holy Month of Ramadan.
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Chris Hughes -/ import data.int.modeq data.int.gcd data.fintype data.pnat open nat nat.modeq int def zmod (n : ℕ+) := fin n namespace zmod instance (n : ℕ+) : has_neg (zmod n) := ⟨λ a, ⟨nat_mod (-(a.1 : ℤ)) n, have h : (n : ℤ) ≠ 0 := int.coe_nat_ne_zero_iff_pos.2 n.pos, have h₁ : ((n : ℕ) : ℤ) = abs n := (abs_of_nonneg (int.coe_nat_nonneg n)).symm, by rw [← int.coe_nat_lt, nat_mod, to_nat_of_nonneg (int.mod_nonneg _ h), h₁]; exact int.mod_lt _ h⟩⟩ instance (n : ℕ+) : add_comm_semigroup (zmod n) := { add_assoc := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq (show ((a + b) % n + c) ≡ (a + (b + c) % n) [MOD n], from calc ((a + b) % n + c) ≡ a + b + c [MOD n] : modeq_add (nat.mod_mod _ _) rfl ... ≡ a + (b + c) [MOD n] : by rw add_assoc ... ≡ (a + (b + c) % n) [MOD n] : modeq_add rfl (nat.mod_mod _ _).symm), add_comm := λ ⟨a, _⟩ ⟨b, _⟩, fin.eq_of_veq (show (a + b) % n = (b + a) % n, by rw add_comm), ..fin.has_add } instance (n : ℕ+) : comm_semigroup (zmod n) := { mul_assoc := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq (calc ((a * b) % n * c) ≡ a * b * c [MOD n] : modeq_mul (nat.mod_mod _ _) rfl ... ≡ a * (b * c) [MOD n] : by rw mul_assoc ... ≡ a * (b * c % n) [MOD n] : modeq_mul rfl (nat.mod_mod _ _).symm), mul_comm := λ ⟨a, _⟩ ⟨b, _⟩, fin.eq_of_veq (show (a * b) % n = (b * a) % n, by rw mul_comm), ..fin.has_mul } instance (n : ℕ+) : has_one (zmod n) := ⟨⟨(1 % n), nat.mod_lt _ n.pos⟩⟩ instance (n : ℕ+) : has_zero (zmod n) := ⟨⟨0, n.pos⟩⟩ instance zmod_one.subsingleton : subsingleton (zmod 1) := ⟨λ a b, fin.eq_of_veq (by rw [eq_zero_of_le_zero (le_of_lt_succ a.2), eq_zero_of_le_zero (le_of_lt_succ b.2)])⟩ lemma add_val {n : ℕ+} : ∀ a b : zmod n, (a + b).val = (a.val + b.val) % n | ⟨_, _⟩ ⟨_, _⟩ := rfl lemma mul_val {n : ℕ+} : ∀ a b : zmod n, (a * b).val = (a.val * b.val) % n | ⟨_, _⟩ ⟨_, _⟩ := rfl lemma one_val {n : ℕ+} : (1 : zmod n).val = 1 % n := rfl @[simp] lemma zero_val (n : ℕ+) : (0 : zmod n).val = 0 := rfl private lemma one_mul_aux (n : ℕ+) (a : zmod n) : (1 : zmod n) * a = a := begin cases n with n hn, cases n with n, { exact (lt_irrefl _ hn).elim }, { cases n with n, { exact @subsingleton.elim (zmod 1) _ _ _ }, { have h₁ : a.1 % n.succ.succ = a.1 := nat.mod_eq_of_lt a.2, have h₂ : 1 % n.succ.succ = 1 := nat.mod_eq_of_lt dec_trivial, refine fin.eq_of_veq _, simp [mul_val, one_val, h₁, h₂] } } end private lemma left_distrib_aux (n : ℕ+) : ∀ a b c : zmod n, a * (b + c) = a * b + a * c := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq (calc a * ((b + c) % n) ≡ a * (b + c) [MOD n] : modeq_mul rfl (nat.mod_mod _ _) ... ≡ a * b + a * c [MOD n] : by rw mul_add ... ≡ (a * b) % n + (a * c) % n [MOD n] : modeq_add (nat.mod_mod _ _).symm (nat.mod_mod _ _).symm) instance (n : ℕ+) : comm_ring (zmod n) := { zero_add := λ ⟨a, ha⟩, fin.eq_of_veq (show (0 + a) % n = a, by rw zero_add; exact nat.mod_eq_of_lt ha), add_zero := λ ⟨a, ha⟩, fin.eq_of_veq (nat.mod_eq_of_lt ha), add_left_neg := λ ⟨a, ha⟩, fin.eq_of_veq (show (((-a : ℤ) % n).to_nat + a) % n = 0, from int.coe_nat_inj begin have hn : (n : ℤ) ≠ 0 := (ne_of_lt (int.coe_nat_lt.2 n.pos)).symm, rw [int.coe_nat_mod, int.coe_nat_add, to_nat_of_nonneg (int.mod_nonneg _ hn), add_comm], simp, end), one_mul := one_mul_aux n, mul_one := λ a, by rw mul_comm; exact one_mul_aux n a, left_distrib := left_distrib_aux n, right_distrib := λ a b c, by rw [mul_comm, left_distrib_aux, mul_comm _ b, mul_comm]; refl, ..zmod.has_zero n, ..zmod.has_one n, ..zmod.has_neg n, ..zmod.add_comm_semigroup n, ..zmod.comm_semigroup n } lemma val_cast_nat {n : ℕ+} (a : ℕ) : (a : zmod n).val = a % n := begin induction a with a ih, { rw [nat.zero_mod]; refl }, { rw [succ_eq_add_one, nat.cast_add, add_val, ih], show (a % n + ((0 + (1 % n)) % n)) % n = (a + 1) % n, rw [zero_add, nat.mod_mod], exact nat.modeq.modeq_add (nat.mod_mod a n) (nat.mod_mod 1 n) } end lemma mk_eq_cast {n : ℕ+} {a : ℕ} (h : a < n) : (⟨a, h⟩ : zmod n) = (a : zmod n) := fin.eq_of_veq (by rw [val_cast_nat, nat.mod_eq_of_lt h]) @[simp] lemma cast_self_eq_zero {n : ℕ+} : ((n : ℕ) : zmod n) = 0 := fin.eq_of_veq (show (n : zmod n).val = 0, by simp [val_cast_nat]) lemma val_cast_of_lt {n : ℕ+} {a : ℕ} (h : a < n) : (a : zmod n).val = a := by rw [val_cast_nat, nat.mod_eq_of_lt h] @[simp] lemma cast_mod_nat (n : ℕ+) (a : ℕ) : ((a % n : ℕ) : zmod n) = a := by conv {to_rhs, rw ← nat.mod_add_div a n}; simp @[simp] lemma cast_val {n : ℕ+} (a : zmod n) : (a.val : zmod n) = a := by cases a; simp [mk_eq_cast] @[simp] lemma cast_mod_int (n : ℕ+) (a : ℤ) : ((a % (n : ℕ) : ℤ) : zmod n) = a := by conv {to_rhs, rw ← int.mod_add_div a n}; simp lemma val_cast_int {n : ℕ+} (a : ℤ) : (a : zmod n).val = (a % (n : ℕ)).nat_abs := have h : nat_abs (a % (n : ℕ)) < n := int.coe_nat_lt.1 begin rw [nat_abs_of_nonneg (mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos))], conv {to_rhs, rw ← abs_of_nonneg (int.coe_nat_nonneg n)}, exact int.mod_lt _ (int.coe_nat_ne_zero_iff_pos.2 n.pos) end, int.coe_nat_inj $ by conv {to_lhs, rw [← cast_mod_int n a, ← nat_abs_of_nonneg (mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos)), int.cast_coe_nat, val_cast_of_lt h] } lemma eq_iff_modeq_nat {n : ℕ+} {a b : ℕ} : (a : zmod n) = b ↔ a ≡ b [MOD n] := ⟨λ h, by have := fin.veq_of_eq h; rwa [val_cast_nat, val_cast_nat] at this, λ h, fin.eq_of_veq $ by rwa [val_cast_nat, val_cast_nat]⟩ lemma eq_iff_modeq_int {n : ℕ+} {a b : ℤ} : (a : zmod n) = b ↔ a ≡ b [ZMOD (n : ℕ)] := ⟨λ h, by have := fin.veq_of_eq h; rwa [val_cast_int, val_cast_int, ← int.coe_nat_eq_coe_nat_iff, nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos)), nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2 n.pos))] at this, λ h : a % (n : ℕ) = b % (n : ℕ), by rw [← cast_mod_int n a, ← cast_mod_int n b, h]⟩ instance (n : ℕ+) : fintype (zmod n) := fin.fintype _ lemma card_zmod (n : ℕ+) : fintype.card (zmod n) = n := fintype.card_fin n end zmod def zmodp (p : ℕ) (hp : prime p) : Type := zmod ⟨p, hp.pos⟩ namespace zmodp variables {p : ℕ} (hp : prime p) instance : comm_ring (zmodp p hp) := zmod.comm_ring ⟨p, hp.pos⟩ instance {p : ℕ} (hp : prime p) : has_inv (zmodp p hp) := ⟨λ a, gcd_a a.1 p⟩ lemma add_val : ∀ a b : zmodp p hp, (a + b).val = (a.val + b.val) % p | ⟨_, _⟩ ⟨_, _⟩ := rfl lemma mul_val : ∀ a b : zmodp p hp, (a * b).val = (a.val * b.val) % p | ⟨_, _⟩ ⟨_, _⟩ := rfl @[simp] lemma one_val : (1 : zmodp p hp).val = 1 := nat.mod_eq_of_lt hp.gt_one @[simp] lemma zero_val : (0 : zmodp p hp).val = 0 := rfl lemma val_cast_nat (a : ℕ) : (a : zmodp p hp).val = a % p := @zmod.val_cast_nat ⟨p, hp.pos⟩ _ lemma mk_eq_cast {a : ℕ} (h : a < p) : (⟨a, h⟩ : zmodp p hp) = (a : zmodp p hp) := @zmod.mk_eq_cast ⟨p, hp.pos⟩ _ _ @[simp] lemma cast_self_eq_zero: (p : zmodp p hp) = 0 := fin.eq_of_veq $ by simp [val_cast_nat] lemma val_cast_of_lt {a : ℕ} (h : a < p) : (a : zmodp p hp).val = a := @zmod.val_cast_of_lt ⟨p, hp.pos⟩ _ h @[simp] lemma cast_mod_nat (a : ℕ) : ((a % p : ℕ) : zmodp p hp) = a := @zmod.cast_mod_nat ⟨p, hp.pos⟩ _ @[simp] lemma cast_val (a : zmodp p hp) : (a.val : zmodp p hp) = a := @zmod.cast_val ⟨p, hp.pos⟩ _ @[simp] lemma cast_mod_int (a : ℤ) : ((a % p : ℤ) : zmodp p hp) = a := @zmod.cast_mod_int ⟨p, hp.pos⟩ _ lemma val_cast_int (a : ℤ) : (a : zmodp p hp).val = (a % p).nat_abs := @zmod.val_cast_int ⟨p, hp.pos⟩ _ lemma eq_iff_modeq_nat {a b : ℕ} : (a : zmodp p hp) = b ↔ a ≡ b [MOD p] := @zmod.eq_iff_modeq_nat ⟨p, hp.pos⟩ _ _ lemma eq_iff_modeq_int {a b : ℤ} : (a : zmodp p hp) = b ↔ a ≡ b [ZMOD p] := @zmod.eq_iff_modeq_int ⟨p, hp.pos⟩ _ _ lemma gcd_a_modeq (a b : ℕ) : (a : ℤ) * gcd_a a b ≡ nat.gcd a b [ZMOD b] := by rw [← add_zero ((a : ℤ) * _), gcd_eq_gcd_ab]; exact int.modeq.modeq_add rfl (int.modeq.modeq_zero_iff.2 (dvd_mul_right _ _)).symm lemma mul_inv_eq_gcd (a : ℕ) : (a : zmodp p hp) * a⁻¹ = nat.gcd a p := by rw [← int.cast_coe_nat (nat.gcd _ _), nat.gcd_comm, nat.gcd_rec, ← (eq_iff_modeq_int _).2 (gcd_a_modeq _ _)]; simp [has_inv.inv, val_cast_nat] private lemma mul_inv_cancel_aux : ∀ a : zmodp p hp, a ≠ 0 → a * a⁻¹ = 1 := λ ⟨a, hap⟩ ha0, begin rw [mk_eq_cast, ne.def, ← @nat.cast_zero (zmodp p hp), eq_iff_modeq_nat, modeq_zero_iff] at ha0, have : nat.gcd p a = 1 := (prime.coprime_iff_not_dvd hp).2 ha0, rw [mk_eq_cast _ hap, mul_inv_eq_gcd, nat.gcd_comm], simpa [nat.gcd_comm, this] end instance : discrete_field (zmodp p hp) := { zero_ne_one := fin.ne_of_vne $ show 0 ≠ 1 % p, by rw nat.mod_eq_of_lt hp.gt_one; exact zero_ne_one, mul_inv_cancel := mul_inv_cancel_aux hp, inv_mul_cancel := λ a, by rw mul_comm; exact mul_inv_cancel_aux hp _, has_decidable_eq := by apply_instance, inv_zero := show (gcd_a 0 p : zmodp p hp) = 0, by unfold gcd_a xgcd xgcd_aux; refl, ..zmodp.comm_ring hp, ..zmodp.has_inv hp } end zmodp
function [ns] = min2ns(min) % Convert time from minutes to nanoseconds. % Chad Greene 2012 ns = min*60000000000;
Homosexuals are , according to the Church , " called to chastity " . They are instructed to practice the virtues of " self @-@ mastery " that teaches " inner freedom " using the support of friends , prayer and grace found in the sacraments of the Church . These tools are meant to help homosexuals " gradually and resolutely approach Christian perfection " , which is a state to which all Christians are called .
import matplotlib as mpl mpl.use('Qt5Agg') import matplotlib.pyplot as plt import numpy as np from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas # from skimage import exposure from skimage.external import tifffile as tiff class mpl3DFigure: def __init__(self,view): # Set up empty plot variables. self.volume = None # self.adjusted = None self.dims = None self.x = [] self.y = [] self.i = 0 self.max_markers = 0 self.marker_scat = () # Create a figure to plot on. self.fig = plt.figure() # Set face color. self.fig.patch.set_facecolor('#FFFFFF') # Create an axis in the figure. self.ax = self.fig.add_subplot(111, axisbg='#FFFFFF') # Set tight fitting. self.fig.tight_layout() # Set the tick colors. self.ax.tick_params(colors='#000000') if view == 'Coronal': self.ax.set_title('0 Degree View') self.ax.set_xlabel('X-axis (LR)') self.ax.set_ylabel('Z-axis (HF)') elif view == 'Sagittal': self.ax.set_title('90 Degree View') self.ax.set_xlabel('Y-axis (PA)') self.ax.set_ylabel('Z-axis (HF)') else: # Deal with something that shouldn't occur. self.ax.set_title('Unknown') self.ax.set_xlabel('Unknown') self.ax.set_ylabel('Unknown') # Set Label Colors. self.ax.title.set_color('#000000') self.ax.xaxis.label.set_color('#000000') self.ax.yaxis.label.set_color('#000000') # Create a canvas widget for Qt to use. self.canvas = FigureCanvas(self.fig) # Refresh the canvas. self.canvas.draw() def loadImage(self,fn,pix,orientation='HFS',img=1,format='npy'): # Try to read in numpy array. if format == 'npy': self.data = np.load(fn) else: # For everything else assume it's an image readable by tifffile. self.data = tiff.imread(fn) # Patient imaging orientation. Calculate the extent (left, right, bottom, top). if orientation == 'HFS': if img == 1: self.dims = np.array([0,np.shape(self.data)[1]*pix[0],np.shape(self.data)[0]*pix[2],0]) if img == 2: self.dims = np.array([0,np.shape(self.data)[1]*pix[1],np.shape(self.data)[0]*pix[2],0]) elif orientation == 'FHS': if img == 1: self.dims = np.array([0,np.shape(self.data)[1]*pix[0],np.shape(self.data)[0]*pix[2],0]) if img == 2: self.dims = np.array([0,np.shape(self.data)[1]*pix[1],np.shape(self.data)[0]*pix[2],0]) # Display the image. self.image = self.ax.imshow(self.data, cmap='bone', extent=self.dims) self.ax.set_autoscale_on(False) # Refresh the canvas. self.canvas.draw() # Start Callback ID self.cid = self.canvas.mpl_connect('button_press_event', self.onClick) def onClick(self,event): # If mouse button 1 is clicked (left click). if event.button == 1: # Create scatter point and numbered text for each marker up to max markers. if self.i < self.max_markers: self.x.append(event.xdata) self.y.append(event.ydata) self.i = self.i+1 # Create tuple list of scatter and text plots. a = self.ax.scatter(event.xdata,event.ydata,c='r',marker='+',s=50) b = self.ax.text(event.xdata+1,event.ydata-3,self.i,color='r') tmp = a,b self.marker_scat = self.marker_scat + tmp # Refresh canvas. self.canvas.draw() else: pass def resetMarkers(self,args=None): # Reset all parameters back to their initial states. if args == 'all': self.x = [] self.y = [] self.i = 0 # Remove each scatter point from the canvas. for i in range(len(self.marker_scat)): self.marker_scat[i].remove() # Reset the tuple list. self.marker_scat = () # Redraw the canvas. self.canvas.draw() def updateImage(self,data): # Set image data. self.image.set_data(data) # Refresh the canvas. self.canvas.draw() def markerUpdate(self): # Reset the markers. self.resetMarkers() # Re-plot markers with pts. for i in range(self.max_markers): # Create tuple list of scatter and text plots. a = self.ax.scatter(self.x[i],self.y[i],c='b',marker='+',s=50) b = self.ax.text(self.x[i]+1,self.y[i]-3,i+1,color='b') tmp = a,b self.marker_scat = self.marker_scat + tmp # Refresh the canvas. self.canvas.draw()
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Abhimanyu Pallavi Sudhir -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.order.filter.basic import Mathlib.algebra.module.pi import Mathlib.PostPort universes u_1 u_2 u_3 u_4 u_5 u_6 u_7 namespace Mathlib /-! # Germ of a function at a filter The germ of a function `f : α → β` at a filter `l : filter α` is the equivalence class of `f` with respect to the equivalence relation `eventually_eq l`: `f ≈ g` means `∀ᶠ x in l, f x = g x`. ## Main definitions We define * `germ l β` to be the space of germs of functions `α → β` at a filter `l : filter α`; * coercion from `α → β` to `germ l β`: `(f : germ l β)` is the germ of `f : α → β` at `l : filter α`; this coercion is declared as `has_coe_t`, so it does not require an explicit up arrow `↑`; * coercion from `β` to `germ l β`: `(↑c : germ l β)` is the germ of the constant function `λ x:α, c` at a filter `l`; this coercion is declared as `has_lift_t`, so it requires an explicit up arrow `↑`, see [TPiL][TPiL_coe] for details. * `map (F : β → γ) (f : germ l β)` to be the composition of a function `F` and a germ `f`; * `map₂ (F : β → γ → δ) (f : germ l β) (g : germ l γ)` to be the germ of `λ x, F (f x) (g x)` at `l`; * `f.tendsto lb`: we say that a germ `f : germ l β` tends to a filter `lb` if its representatives tend to `lb` along `l`; * `f.comp_tendsto g hg` and `f.comp_tendsto' g hg`: given `f : germ l β` and a function `g : γ → α` (resp., a germ `g : germ lc α`), if `g` tends to `l` along `lc`, then the composition `f ∘ g` is a well-defined germ at `lc`; * `germ.lift_pred`, `germ.lift_rel`: lift a predicate or a relation to the space of germs: `(f : germ l β).lift_pred p` means `∀ᶠ x in l, p (f x)`, and similarly for a relation. [TPiL_coe]: https://leanprover.github.io/theorem_proving_in_lean/type_classes.html#coercions-using-type-classes We also define `map (F : β → γ) : germ l β → germ l γ` sending each germ `f` to `F ∘ f`. For each of the following structures we prove that if `β` has this structure, then so does `germ l β`: * one-operation algebraic structures up to `comm_group`; * `mul_zero_class`, `distrib`, `semiring`, `comm_semiring`, `ring`, `comm_ring`; * `mul_action`, `distrib_mul_action`, `semimodule`; * `preorder`, `partial_order`, and `lattice` structures up to `bounded_lattice`; * `ordered_cancel_comm_monoid` and `ordered_cancel_add_comm_monoid`. ## Tags filter, germ -/ namespace filter theorem const_eventually_eq' {α : Type u_1} {β : Type u_2} {l : filter α} [ne_bot l] {a : β} {b : β} : filter.eventually (fun (x : α) => a = b) l ↔ a = b := eventually_const theorem const_eventually_eq {α : Type u_1} {β : Type u_2} {l : filter α} [ne_bot l] {a : β} {b : β} : (eventually_eq l (fun (_x : α) => a) fun (_x : α) => b) ↔ a = b := const_eventually_eq' theorem eventually_eq.comp_tendsto {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} {f : α → β} {f' : α → β} (H : eventually_eq l f f') {g : γ → α} {lc : filter γ} (hg : tendsto g lc l) : eventually_eq lc (f ∘ g) (f' ∘ g) := tendsto.eventually hg H /-- Setoid used to define the space of germs. -/ def germ_setoid {α : Type u_1} (l : filter α) (β : Type u_2) : setoid (α → β) := setoid.mk (eventually_eq l) sorry /-- The space of germs of functions `α → β` at a filter `l`. -/ def germ {α : Type u_1} (l : filter α) (β : Type u_2) := quotient (germ_setoid l β) namespace germ protected instance has_coe_t {α : Type u_1} {β : Type u_2} {l : filter α} : has_coe_t (α → β) (germ l β) := has_coe_t.mk quotient.mk' protected instance has_lift_t {α : Type u_1} {β : Type u_2} {l : filter α} : has_lift_t β (germ l β) := has_lift_t.mk fun (c : β) => ↑fun (x : α) => c @[simp] theorem quot_mk_eq_coe {α : Type u_1} {β : Type u_2} (l : filter α) (f : α → β) : Quot.mk setoid.r f = ↑f := rfl @[simp] theorem mk'_eq_coe {α : Type u_1} {β : Type u_2} (l : filter α) (f : α → β) : quotient.mk' f = ↑f := rfl theorem induction_on {α : Type u_1} {β : Type u_2} {l : filter α} (f : germ l β) {p : germ l β → Prop} (h : ∀ (f : α → β), p ↑f) : p f := quotient.induction_on' f h theorem induction_on₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : germ l β) (g : germ l γ) {p : germ l β → germ l γ → Prop} (h : ∀ (f : α → β) (g : α → γ), p ↑f ↑g) : p f g := quotient.induction_on₂' f g h theorem induction_on₃ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} (f : germ l β) (g : germ l γ) (h : germ l δ) {p : germ l β → germ l γ → germ l δ → Prop} (H : ∀ (f : α → β) (g : α → γ) (h : α → δ), p ↑f ↑g ↑h) : p f g h := quotient.induction_on₃' f g h H /-- Given a map `F : (α → β) → (γ → δ)` that sends functions eventually equal at `l` to functions eventually equal at `lc`, returns a map from `germ l β` to `germ lc δ`. -/ def map' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} {lc : filter γ} (F : (α → β) → γ → δ) (hF : relator.lift_fun (eventually_eq l) (eventually_eq lc) F F) : germ l β → germ lc δ := quotient.map' F hF /-- Given a germ `f : germ l β` and a function `F : (α → β) → γ` sending eventually equal functions to the same value, returns the value `F` takes on functions having germ `f` at `l`. -/ def lift_on {α : Type u_1} {β : Type u_2} {l : filter α} {γ : Sort u_3} (f : germ l β) (F : (α → β) → γ) (hF : relator.lift_fun (eventually_eq l) Eq F F) : γ := quotient.lift_on' f F hF @[simp] theorem map'_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} {lc : filter γ} (F : (α → β) → γ → δ) (hF : relator.lift_fun (eventually_eq l) (eventually_eq lc) F F) (f : α → β) : map' F hF ↑f = ↑(F f) := rfl @[simp] theorem coe_eq {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {g : α → β} : ↑f = ↑g ↔ eventually_eq l f g := quotient.eq' theorem Mathlib.filter.eventually_eq.germ_eq {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {g : α → β} : eventually_eq l f g → ↑f = ↑g := iff.mpr coe_eq /-- Lift a function `β → γ` to a function `germ l β → germ l γ`. -/ def map {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (op : β → γ) : germ l β → germ l γ := map' (function.comp op) sorry @[simp] theorem map_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (op : β → γ) (f : α → β) : map op ↑f = ↑(op ∘ f) := rfl @[simp] theorem map_id {α : Type u_1} {β : Type u_2} {l : filter α} : map id = id := funext fun (x : germ l β) => quot.induction_on x fun (f : α → β) => Eq.refl (map id (Quot.mk setoid.r f)) theorem map_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} (op₁ : γ → δ) (op₂ : β → γ) (f : germ l β) : map op₁ (map op₂ f) = map (op₁ ∘ op₂) f := induction_on f fun (f : α → β) => rfl /-- Lift a binary function `β → γ → δ` to a function `germ l β → germ l γ → germ l δ`. -/ def map₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} (op : β → γ → δ) : germ l β → germ l γ → germ l δ := quotient.map₂' (fun (f : α → β) (g : α → γ) (x : α) => op (f x) (g x)) sorry @[simp] theorem map₂_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} (op : β → γ → δ) (f : α → β) (g : α → γ) : map₂ op ↑f ↑g = ↑fun (x : α) => op (f x) (g x) := rfl /-- A germ at `l` of maps from `α` to `β` tends to `lb : filter β` if it is represented by a map which tends to `lb` along `l`. -/ protected def tendsto {α : Type u_1} {β : Type u_2} {l : filter α} (f : germ l β) (lb : filter β) := lift_on f (fun (f : α → β) => tendsto f l lb) sorry @[simp] theorem coe_tendsto {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {lb : filter β} : germ.tendsto (↑f) lb ↔ tendsto f l lb := iff.rfl theorem Mathlib.filter.tendsto.germ_tendsto {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {lb : filter β} : tendsto f l lb → germ.tendsto (↑f) lb := iff.mpr coe_tendsto /-- Given two germs `f : germ l β`, and `g : germ lc α`, where `l : filter α`, if `g` tends to `l`, then the composition `f ∘ g` is well-defined as a germ at `lc`. -/ def comp_tendsto' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : germ l β) {lc : filter γ} (g : germ lc α) (hg : germ.tendsto g l) : germ lc β := lift_on f (fun (f : α → β) => map f g) sorry @[simp] theorem coe_comp_tendsto' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : α → β) {lc : filter γ} {g : germ lc α} (hg : germ.tendsto g l) : comp_tendsto' (↑f) g hg = map f g := rfl /-- Given a germ `f : germ l β` and a function `g : γ → α`, where `l : filter α`, if `g` tends to `l` along `lc : filter γ`, then the composition `f ∘ g` is well-defined as a germ at `lc`. -/ def comp_tendsto {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : germ l β) {lc : filter γ} (g : γ → α) (hg : tendsto g lc l) : germ lc β := comp_tendsto' f (↑g) (tendsto.germ_tendsto hg) @[simp] theorem coe_comp_tendsto {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : α → β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : comp_tendsto (↑f) g hg = ↑(f ∘ g) := rfl @[simp] theorem comp_tendsto'_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : germ l β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : comp_tendsto' f (↑g) (tendsto.germ_tendsto hg) = comp_tendsto f g hg := rfl @[simp] theorem const_inj {α : Type u_1} {β : Type u_2} {l : filter α} [ne_bot l] {a : β} {b : β} : ↑a = ↑b ↔ a = b := iff.trans coe_eq const_eventually_eq @[simp] theorem map_const {α : Type u_1} {β : Type u_2} {γ : Type u_3} (l : filter α) (a : β) (f : β → γ) : map f ↑a = ↑(f a) := rfl @[simp] theorem map₂_const {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} (l : filter α) (b : β) (c : γ) (f : β → γ → δ) : map₂ f ↑b ↑c = ↑(f b c) := rfl @[simp] theorem const_comp_tendsto {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (b : β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : comp_tendsto (↑b) g hg = ↑b := rfl @[simp] theorem const_comp_tendsto' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (b : β) {lc : filter γ} {g : germ lc α} (hg : germ.tendsto g l) : comp_tendsto' (↑b) g hg = ↑b := induction_on g (fun (_x : γ → α) (_x_1 : germ.tendsto (↑_x) l) => rfl) hg /-- Lift a predicate on `β` to `germ l β`. -/ def lift_pred {α : Type u_1} {β : Type u_2} {l : filter α} (p : β → Prop) (f : germ l β) := lift_on f (fun (f : α → β) => filter.eventually (fun (x : α) => p (f x)) l) sorry @[simp] theorem lift_pred_coe {α : Type u_1} {β : Type u_2} {l : filter α} {p : β → Prop} {f : α → β} : lift_pred p ↑f ↔ filter.eventually (fun (x : α) => p (f x)) l := iff.rfl theorem lift_pred_const {α : Type u_1} {β : Type u_2} {l : filter α} {p : β → Prop} {x : β} (hx : p x) : lift_pred p ↑x := eventually_of_forall fun (y : α) => hx @[simp] theorem lift_pred_const_iff {α : Type u_1} {β : Type u_2} {l : filter α} [ne_bot l] {p : β → Prop} {x : β} : lift_pred p ↑x ↔ p x := eventually_const /-- Lift a relation `r : β → γ → Prop` to `germ l β → germ l γ → Prop`. -/ def lift_rel {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (r : β → γ → Prop) (f : germ l β) (g : germ l γ) := quotient.lift_on₂' f g (fun (f : α → β) (g : α → γ) => filter.eventually (fun (x : α) => r (f x) (g x)) l) sorry @[simp] theorem lift_rel_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} {r : β → γ → Prop} {f : α → β} {g : α → γ} : lift_rel r ↑f ↑g ↔ filter.eventually (fun (x : α) => r (f x) (g x)) l := iff.rfl theorem lift_rel_const {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} {r : β → γ → Prop} {x : β} {y : γ} (h : r x y) : lift_rel r ↑x ↑y := eventually_of_forall fun (_x : α) => h @[simp] theorem lift_rel_const_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} [ne_bot l] {r : β → γ → Prop} {x : β} {y : γ} : lift_rel r ↑x ↑y ↔ r x y := eventually_const protected instance inhabited {α : Type u_1} {β : Type u_2} {l : filter α} [Inhabited β] : Inhabited (germ l β) := { default := ↑Inhabited.default } protected instance has_add {α : Type u_1} {l : filter α} {M : Type u_5} [Add M] : Add (germ l M) := { add := map₂ Add.add } @[simp] theorem coe_add {α : Type u_1} {l : filter α} {M : Type u_5} [Add M] (f : α → M) (g : α → M) : ↑(f + g) = ↑f + ↑g := rfl protected instance has_one {α : Type u_1} {l : filter α} {M : Type u_5} [HasOne M] : HasOne (germ l M) := { one := ↑1 } @[simp] theorem coe_zero {α : Type u_1} {l : filter α} {M : Type u_5} [HasZero M] : ↑0 = 0 := rfl protected instance add_semigroup {α : Type u_1} {l : filter α} {M : Type u_5} [add_semigroup M] : add_semigroup (germ l M) := add_semigroup.mk Add.add sorry protected instance add_comm_semigroup {α : Type u_1} {l : filter α} {M : Type u_5} [add_comm_semigroup M] : add_comm_semigroup (germ l M) := add_comm_semigroup.mk Add.add sorry sorry protected instance left_cancel_semigroup {α : Type u_1} {l : filter α} {M : Type u_5} [left_cancel_semigroup M] : left_cancel_semigroup (germ l M) := left_cancel_semigroup.mk Mul.mul sorry sorry protected instance right_cancel_semigroup {α : Type u_1} {l : filter α} {M : Type u_5} [right_cancel_semigroup M] : right_cancel_semigroup (germ l M) := right_cancel_semigroup.mk Mul.mul sorry sorry protected instance monoid {α : Type u_1} {l : filter α} {M : Type u_5} [monoid M] : monoid (germ l M) := monoid.mk Mul.mul sorry 1 sorry sorry /-- coercion from functions to germs as a monoid homomorphism. -/ def coe_mul_hom {α : Type u_1} {M : Type u_5} [monoid M] (l : filter α) : (α → M) →* germ l M := monoid_hom.mk coe sorry sorry /-- coercion from functions to germs as an additive monoid homomorphism. -/ @[simp] theorem coe_coe_mul_hom {α : Type u_1} {l : filter α} {M : Type u_5} [monoid M] : ⇑(coe_mul_hom l) = coe := rfl protected instance add_comm_monoid {α : Type u_1} {l : filter α} {M : Type u_5} [add_comm_monoid M] : add_comm_monoid (germ l M) := add_comm_monoid.mk Add.add sorry 0 sorry sorry sorry protected instance has_neg {α : Type u_1} {l : filter α} {G : Type u_6} [Neg G] : Neg (germ l G) := { neg := map Neg.neg } @[simp] theorem coe_neg {α : Type u_1} {l : filter α} {G : Type u_6} [Neg G] (f : α → G) : ↑(-f) = -↑f := rfl protected instance has_div {α : Type u_1} {l : filter α} {M : Type u_5} [Div M] : Div (germ l M) := { div := map₂ Div.div } @[simp] theorem coe_div {α : Type u_1} {l : filter α} {M : Type u_5} [Div M] (f : α → M) (g : α → M) : ↑(f / g) = ↑f / ↑g := rfl protected instance sub_neg_add_monoid {α : Type u_1} {l : filter α} {G : Type u_6} [sub_neg_monoid G] : sub_neg_monoid (germ l G) := sub_neg_monoid.mk add_monoid.add sorry add_monoid.zero sorry sorry Neg.neg Sub.sub protected instance group {α : Type u_1} {l : filter α} {G : Type u_6} [group G] : group (germ l G) := group.mk Mul.mul sorry 1 sorry sorry div_inv_monoid.inv div_inv_monoid.div sorry protected instance comm_group {α : Type u_1} {l : filter α} {G : Type u_6} [comm_group G] : comm_group (germ l G) := comm_group.mk Mul.mul sorry 1 sorry sorry has_inv.inv group.div sorry sorry protected instance nontrivial {α : Type u_1} {l : filter α} {R : Type u_5} [nontrivial R] [ne_bot l] : nontrivial (germ l R) := sorry protected instance mul_zero_class {α : Type u_1} {l : filter α} {R : Type u_5} [mul_zero_class R] : mul_zero_class (germ l R) := mul_zero_class.mk Mul.mul 0 sorry sorry protected instance distrib {α : Type u_1} {l : filter α} {R : Type u_5} [distrib R] : distrib (germ l R) := distrib.mk Mul.mul Add.add sorry sorry protected instance semiring {α : Type u_1} {l : filter α} {R : Type u_5} [semiring R] : semiring (germ l R) := semiring.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry sorry sorry /-- Coercion `(α → R) → germ l R` as a `ring_hom`. -/ def coe_ring_hom {α : Type u_1} {R : Type u_5} [semiring R] (l : filter α) : (α → R) →+* germ l R := ring_hom.mk coe sorry sorry sorry sorry @[simp] theorem coe_coe_ring_hom {α : Type u_1} {l : filter α} {R : Type u_5} [semiring R] : ⇑(coe_ring_hom l) = coe := rfl protected instance ring {α : Type u_1} {l : filter α} {R : Type u_5} [ring R] : ring (germ l R) := ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry protected instance comm_semiring {α : Type u_1} {l : filter α} {R : Type u_5} [comm_semiring R] : comm_semiring (germ l R) := comm_semiring.mk semiring.add sorry semiring.zero sorry sorry sorry semiring.mul sorry semiring.one sorry sorry sorry sorry sorry sorry sorry protected instance comm_ring {α : Type u_1} {l : filter α} {R : Type u_5} [comm_ring R] : comm_ring (germ l R) := comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry ring.one sorry sorry sorry sorry sorry protected instance has_scalar {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [has_scalar M β] : has_scalar M (germ l β) := has_scalar.mk fun (c : M) => map (has_scalar.smul c) protected instance has_scalar' {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [has_scalar M β] : has_scalar (germ l M) (germ l β) := has_scalar.mk (map₂ has_scalar.smul) @[simp] theorem coe_smul {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [has_scalar M β] (c : M) (f : α → β) : ↑(c • f) = c • ↑f := rfl @[simp] theorem coe_smul' {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [has_scalar M β] (c : α → M) (f : α → β) : ↑(c • f) = ↑c • ↑f := rfl protected instance mul_action {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [monoid M] [mul_action M β] : mul_action M (germ l β) := mul_action.mk sorry sorry protected instance mul_action' {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [monoid M] [mul_action M β] : mul_action (germ l M) (germ l β) := mul_action.mk sorry sorry protected instance distrib_mul_action {α : Type u_1} {l : filter α} {M : Type u_5} {N : Type u_6} [monoid M] [add_monoid N] [distrib_mul_action M N] : distrib_mul_action M (germ l N) := distrib_mul_action.mk sorry sorry protected instance distrib_mul_action' {α : Type u_1} {l : filter α} {M : Type u_5} {N : Type u_6} [monoid M] [add_monoid N] [distrib_mul_action M N] : distrib_mul_action (germ l M) (germ l N) := distrib_mul_action.mk sorry sorry protected instance semimodule {α : Type u_1} {l : filter α} {M : Type u_5} {R : Type u_7} [semiring R] [add_comm_monoid M] [semimodule R M] : semimodule R (germ l M) := semimodule.mk sorry sorry protected instance semimodule' {α : Type u_1} {l : filter α} {M : Type u_5} {R : Type u_7} [semiring R] [add_comm_monoid M] [semimodule R M] : semimodule (germ l R) (germ l M) := semimodule.mk sorry sorry protected instance has_le {α : Type u_1} {β : Type u_2} {l : filter α} [HasLessEq β] : HasLessEq (germ l β) := { LessEq := lift_rel LessEq } @[simp] theorem coe_le {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {g : α → β} [HasLessEq β] : ↑f ≤ ↑g ↔ eventually_le l f g := iff.rfl theorem le_def {α : Type u_1} {β : Type u_2} {l : filter α} [HasLessEq β] : LessEq = lift_rel LessEq := rfl theorem const_le {α : Type u_1} {β : Type u_2} {l : filter α} [HasLessEq β] {x : β} {y : β} (h : x ≤ y) : ↑x ≤ ↑y := lift_rel_const h @[simp] theorem const_le_iff {α : Type u_1} {β : Type u_2} {l : filter α} [HasLessEq β] [ne_bot l] {x : β} {y : β} : ↑x ≤ ↑y ↔ x ≤ y := lift_rel_const_iff protected instance preorder {α : Type u_1} {β : Type u_2} {l : filter α} [preorder β] : preorder (germ l β) := preorder.mk LessEq (fun (a b : germ l β) => a ≤ b ∧ ¬b ≤ a) sorry sorry protected instance partial_order {α : Type u_1} {β : Type u_2} {l : filter α} [partial_order β] : partial_order (germ l β) := partial_order.mk LessEq preorder.lt sorry sorry sorry protected instance has_bot {α : Type u_1} {β : Type u_2} {l : filter α} [has_bot β] : has_bot (germ l β) := has_bot.mk ↑⊥ @[simp] theorem const_bot {α : Type u_1} {β : Type u_2} {l : filter α} [has_bot β] : ↑⊥ = ⊥ := rfl protected instance order_bot {α : Type u_1} {β : Type u_2} {l : filter α} [order_bot β] : order_bot (germ l β) := order_bot.mk ⊥ LessEq partial_order.lt sorry sorry sorry sorry protected instance has_top {α : Type u_1} {β : Type u_2} {l : filter α} [has_top β] : has_top (germ l β) := has_top.mk ↑⊤ @[simp] theorem const_top {α : Type u_1} {β : Type u_2} {l : filter α} [has_top β] : ↑⊤ = ⊤ := rfl protected instance order_top {α : Type u_1} {β : Type u_2} {l : filter α} [order_top β] : order_top (germ l β) := order_top.mk ⊤ LessEq partial_order.lt sorry sorry sorry sorry protected instance has_sup {α : Type u_1} {β : Type u_2} {l : filter α} [has_sup β] : has_sup (germ l β) := has_sup.mk (map₂ has_sup.sup) @[simp] theorem const_sup {α : Type u_1} {β : Type u_2} {l : filter α} [has_sup β] (a : β) (b : β) : ↑(a ⊔ b) = ↑a ⊔ ↑b := rfl protected instance has_inf {α : Type u_1} {β : Type u_2} {l : filter α} [has_inf β] : has_inf (germ l β) := has_inf.mk (map₂ has_inf.inf) @[simp] theorem const_inf {α : Type u_1} {β : Type u_2} {l : filter α} [has_inf β] (a : β) (b : β) : ↑(a ⊓ b) = ↑a ⊓ ↑b := rfl protected instance semilattice_sup {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_sup β] : semilattice_sup (germ l β) := semilattice_sup.mk has_sup.sup partial_order.le partial_order.lt sorry sorry sorry sorry sorry sorry protected instance semilattice_inf {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_inf β] : semilattice_inf (germ l β) := semilattice_inf.mk has_inf.inf partial_order.le partial_order.lt sorry sorry sorry sorry sorry sorry protected instance semilattice_inf_bot {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_inf_bot β] : semilattice_inf_bot (germ l β) := semilattice_inf_bot.mk order_bot.bot semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry semilattice_inf.inf sorry sorry sorry protected instance semilattice_sup_bot {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_sup_bot β] : semilattice_sup_bot (germ l β) := semilattice_sup_bot.mk order_bot.bot semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry semilattice_sup.sup sorry sorry sorry protected instance semilattice_inf_top {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_inf_top β] : semilattice_inf_top (germ l β) := semilattice_inf_top.mk order_top.top semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry semilattice_inf.inf sorry sorry sorry protected instance semilattice_sup_top {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_sup_top β] : semilattice_sup_top (germ l β) := semilattice_sup_top.mk order_top.top semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry semilattice_sup.sup sorry sorry sorry protected instance lattice {α : Type u_1} {β : Type u_2} {l : filter α} [lattice β] : lattice (germ l β) := lattice.mk semilattice_sup.sup semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry sorry sorry semilattice_inf.inf sorry sorry sorry protected instance bounded_lattice {α : Type u_1} {β : Type u_2} {l : filter α} [bounded_lattice β] : bounded_lattice (germ l β) := bounded_lattice.mk lattice.sup lattice.le lattice.lt sorry sorry sorry sorry sorry sorry lattice.inf sorry sorry sorry order_top.top sorry order_bot.bot sorry protected instance ordered_cancel_add_comm_monoid {α : Type u_1} {β : Type u_2} {l : filter α} [ordered_cancel_add_comm_monoid β] : ordered_cancel_add_comm_monoid (germ l β) := ordered_cancel_add_comm_monoid.mk add_comm_monoid.add sorry sorry add_comm_monoid.zero sorry sorry sorry sorry partial_order.le partial_order.lt sorry sorry sorry sorry sorry protected instance ordered_add_comm_group {α : Type u_1} {β : Type u_2} {l : filter α} [ordered_add_comm_group β] : ordered_add_comm_group (germ l β) := ordered_add_comm_group.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg add_comm_group.sub sorry sorry partial_order.le partial_order.lt sorry sorry sorry sorry
State Before: α : Type u_1 M : Type u N : Type v G : Type w H : Type x A : Type y B : Type z R : Type u₁ S : Type u₂ inst✝ : DivisionMonoid α a : α n : ℕ ⊢ a ^ bit0 ↑n = a ^ ↑n * a ^ ↑n State After: no goals Tactic: simp only [zpow_ofNat, ← Int.ofNat_bit0, pow_bit0] State Before: α : Type u_1 M : Type u N : Type v G : Type w H : Type x A : Type y B : Type z R : Type u₁ S : Type u₂ inst✝ : DivisionMonoid α a : α n : ℕ ⊢ a ^ bit0 -[n+1] = a ^ -[n+1] * a ^ -[n+1] State After: α : Type u_1 M : Type u N : Type v G : Type w H : Type x A : Type y B : Type z R : Type u₁ S : Type u₂ inst✝ : DivisionMonoid α a : α n : ℕ ⊢ a ^ bit0 -[n+1] = (a ^ bit0 (n + 1))⁻¹ Tactic: simp [← mul_inv_rev, ← pow_bit0] State Before: α : Type u_1 M : Type u N : Type v G : Type w H : Type x A : Type y B : Type z R : Type u₁ S : Type u₂ inst✝ : DivisionMonoid α a : α n : ℕ ⊢ a ^ bit0 -[n+1] = (a ^ bit0 (n + 1))⁻¹ State After: α : Type u_1 M : Type u N : Type v G : Type w H : Type x A : Type y B : Type z R : Type u₁ S : Type u₂ inst✝ : DivisionMonoid α a : α n : ℕ ⊢ (a ^ bit0 (↑n + 1))⁻¹ = (a ^ bit0 (n + 1))⁻¹ Tactic: rw [negSucc_eq, bit0_neg, zpow_neg] State Before: α : Type u_1 M : Type u N : Type v G : Type w H : Type x A : Type y B : Type z R : Type u₁ S : Type u₂ inst✝ : DivisionMonoid α a : α n : ℕ ⊢ (a ^ bit0 (↑n + 1))⁻¹ = (a ^ bit0 (n + 1))⁻¹ State After: no goals Tactic: norm_cast
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison, Apurva Nakade -/ import set_theory.game.pgame import tactic.abel /-! # Combinatorial games. In this file we define the quotient of pre-games by the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p` (its `antisymmetrization`), and construct an instance `add_comm_group game`, as well as an instance `partial_order game`. ## Multiplication on pre-games We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x ≈ y` does not imply `x * z ≈ y * z`. Hence, multiplication is not a well-defined operation on games. Nevertheless, the abelian group structure on games allows us to simplify many proofs for pre-games. -/ open function pgame open_locale pgame universes u instance pgame.setoid : setoid pgame := ⟨(≈), equiv_refl, @pgame.equiv.symm, @pgame.equiv.trans⟩ /-- The type of combinatorial games. In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a combinatorial pre-game is built inductively from two families of combinatorial games indexed over any type in Type u. The resulting type `pgame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. A combinatorial game is then constructed by quotienting by the equivalence `x ≈ y ↔ x ≤ y ∧ y ≤ x`. -/ abbreviation game := quotient pgame.setoid namespace game instance : add_comm_group_with_one game := { zero := ⟦0⟧, one := ⟦1⟧, neg := quot.lift (λ x, ⟦-x⟧) (λ x y h, quot.sound ((@neg_equiv_neg_iff x y).2 h)), add := quotient.lift₂ (λ x y : pgame, ⟦x + y⟧) (λ x₁ y₁ x₂ y₂ hx hy, quot.sound (pgame.add_congr hx hy)), add_zero := by { rintro ⟨x⟩, exact quot.sound (add_zero_equiv x) }, zero_add := by { rintro ⟨x⟩, exact quot.sound (zero_add_equiv x) }, add_assoc := by { rintros ⟨x⟩ ⟨y⟩ ⟨z⟩, exact quot.sound add_assoc_equiv }, add_left_neg := by { rintro ⟨x⟩, exact quot.sound (add_left_neg_equiv x) }, add_comm := by { rintros ⟨x⟩ ⟨y⟩, exact quot.sound add_comm_equiv } } instance : inhabited game := ⟨0⟩ instance : partial_order game := { le := quotient.lift₂ (≤) (λ x₁ y₁ x₂ y₂ hx hy, propext (le_congr hx hy)), le_refl := by { rintro ⟨x⟩, exact le_refl x }, le_trans := by { rintro ⟨x⟩ ⟨y⟩ ⟨z⟩, exact @le_trans _ _ x y z }, le_antisymm := by { rintro ⟨x⟩ ⟨y⟩ h₁ h₂, apply quot.sound, exact ⟨h₁, h₂⟩ }, lt := quotient.lift₂ (<) (λ x₁ y₁ x₂ y₂ hx hy, propext (lt_congr hx hy)), lt_iff_le_not_le := by { rintro ⟨x⟩ ⟨y⟩, exact @lt_iff_le_not_le _ _ x y }, } /-- The less or fuzzy relation on games. If `0 ⧏ x` (less or fuzzy with), then Left can win `x` as the first player. -/ def lf : game → game → Prop := quotient.lift₂ lf (λ x₁ y₁ x₂ y₂ hx hy, propext (lf_congr hx hy)) local infix ` ⧏ `:50 := lf /-- On `game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_le : ∀ {x y : game}, ¬ x ≤ y ↔ y ⧏ x := by { rintro ⟨x⟩ ⟨y⟩, exact pgame.not_le } /-- On `game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_lf : ∀ {x y : game}, ¬ x ⧏ y ↔ y ≤ x := by { rintro ⟨x⟩ ⟨y⟩, exact not_lf } instance : is_trichotomous game (⧏) := ⟨by { rintro ⟨x⟩ ⟨y⟩, change _ ∨ ⟦x⟧ = ⟦y⟧ ∨ _, rw quotient.eq, apply lf_or_equiv_or_gf }⟩ /-! It can be useful to use these lemmas to turn `pgame` inequalities into `game` inequalities, as the `add_comm_group` structure on `game` often simplifies many proofs. -/ theorem _root_.pgame.le_iff_game_le {x y : pgame} : x ≤ y ↔ ⟦x⟧ ≤ ⟦y⟧ := iff.rfl theorem _root_.pgame.lf_iff_game_lf {x y : pgame} : pgame.lf x y ↔ ⟦x⟧ ⧏ ⟦y⟧ := iff.rfl theorem _root_.pgame.lt_iff_game_lt {x y : pgame} : x < y ↔ ⟦x⟧ < ⟦y⟧ := iff.rfl theorem _root_.pgame.equiv_iff_game_eq {x y : pgame} : x ≈ y ↔ ⟦x⟧ = ⟦y⟧ := (@quotient.eq _ _ x y).symm /-- The fuzzy, confused, or incomparable relation on games. If `x ‖ 0`, then the first player can always win `x`. -/ def fuzzy : game → game → Prop := quotient.lift₂ fuzzy (λ x₁ y₁ x₂ y₂ hx hy, propext (fuzzy_congr hx hy)) local infix ` ‖ `:50 := fuzzy theorem _root_.pgame.fuzzy_iff_game_fuzzy {x y : pgame} : pgame.fuzzy x y ↔ ⟦x⟧ ‖ ⟦y⟧ := iff.rfl instance covariant_class_add_le : covariant_class game game (+) (≤) := ⟨by { rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h, exact @add_le_add_left _ _ _ _ b c h a }⟩ instance covariant_class_swap_add_le : covariant_class game game (swap (+)) (≤) := ⟨by { rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h, exact @add_le_add_right _ _ _ _ b c h a }⟩ instance covariant_class_add_lt : covariant_class game game (+) (<) := ⟨by { rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h, exact @add_lt_add_left _ _ _ _ b c h a }⟩ instance covariant_class_swap_add_lt : covariant_class game game (swap (+)) (<) := ⟨by { rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h, exact @add_lt_add_right _ _ _ _ b c h a }⟩ theorem add_lf_add_right : ∀ {b c : game} (h : b ⧏ c) (a), b + a ⧏ c + a := by { rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩, apply add_lf_add_right h } theorem add_lf_add_left : ∀ {b c : game} (h : b ⧏ c) (a), a + b ⧏ a + c := by { rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩, apply add_lf_add_left h } instance ordered_add_comm_group : ordered_add_comm_group game := { add_le_add_left := @add_le_add_left _ _ _ game.covariant_class_add_le, ..game.add_comm_group_with_one, ..game.partial_order } end game namespace pgame @[simp] lemma quot_neg (a : pgame) : ⟦-a⟧ = -⟦a⟧ := rfl @[simp] lemma quot_add (a b : pgame) : ⟦a + b⟧ = ⟦a⟧ + ⟦b⟧ := rfl @[simp] lemma quot_sub (a b : pgame) : ⟦a - b⟧ = ⟦a⟧ - ⟦b⟧ := rfl theorem quot_eq_of_mk_quot_eq {x y : pgame} (L : x.left_moves ≃ y.left_moves) (R : x.right_moves ≃ y.right_moves) (hl : ∀ i, ⟦x.move_left i⟧ = ⟦y.move_left (L i)⟧) (hr : ∀ j, ⟦x.move_right j⟧ = ⟦y.move_right (R j)⟧) : ⟦x⟧ = ⟦y⟧ := by { simp_rw [quotient.eq] at hl hr, exact quot.sound (equiv_of_mk_equiv L R hl hr) } /-! Multiplicative operations can be defined at the level of pre-games, but to prove their properties we need to use the abelian group structure of games. Hence we define them here. -/ /-- The product of `x = {xL | xR}` and `y = {yL | yR}` is `{xL*y + x*yL - xL*yL, xR*y + x*yR - xR*yR | xL*y + x*yR - xL*yR, x*yL + xR*y - xR*yL }`. -/ instance : has_mul pgame.{u} := ⟨λ x y, 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⟩ theorem left_moves_mul : ∀ (x y : pgame.{u}), (x * y).left_moves = (x.left_moves × y.left_moves ⊕ x.right_moves × y.right_moves) | ⟨_, _, _, _⟩ ⟨_, _, _, _⟩ := rfl theorem right_moves_mul : ∀ (x y : pgame.{u}), (x * y).right_moves = (x.left_moves × y.right_moves ⊕ x.right_moves × y.left_moves) | ⟨_, _, _, _⟩ ⟨_, _, _, _⟩ := rfl /-- Turns two left or right moves for `x` and `y` into a left move for `x * y` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def to_left_moves_mul {x y : pgame} : x.left_moves × y.left_moves ⊕ x.right_moves × y.right_moves ≃ (x * y).left_moves := equiv.cast (left_moves_mul x y).symm /-- Turns a left and a right move for `x` and `y` into a right move for `x * y` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def to_right_moves_mul {x y : pgame} : x.left_moves × y.right_moves ⊕ x.right_moves × y.left_moves ≃ (x * y).right_moves := equiv.cast (right_moves_mul x y).symm @[simp] lemma mk_mul_move_left_inl {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).move_left (sum.inl (i, j)) = xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j := rfl @[simp] lemma mul_move_left_inl {x y : pgame} {i j} : (x * y).move_left (to_left_moves_mul (sum.inl (i, j))) = x.move_left i * y + x * y.move_left j - x.move_left i * y.move_left j := by { cases x, cases y, refl } @[simp] lemma mk_mul_move_left_inr {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).move_left (sum.inr (i, j)) = xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j := rfl @[simp] lemma mul_move_left_inr {x y : pgame} {i j} : (x * y).move_left (to_left_moves_mul (sum.inr (i, j))) = x.move_right i * y + x * y.move_right j - x.move_right i * y.move_right j := by { cases x, cases y, refl } @[simp] lemma mk_mul_move_right_inl {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).move_right (sum.inl (i, j)) = xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j := rfl @[simp] lemma mul_move_right_inl {x y : pgame} {i j} : (x * y).move_right (to_right_moves_mul (sum.inl (i, j))) = x.move_left i * y + x * y.move_right j - x.move_left i * y.move_right j := by { cases x, cases y, refl } @[simp] lemma mk_mul_move_right_inr {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).move_right (sum.inr (i, j)) = xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j := rfl @[simp] lemma mul_move_right_inr {x y : pgame} {i j} : (x * y).move_right (to_right_moves_mul (sum.inr (i, j))) = x.move_right i * y + x * y.move_left j - x.move_right i * y.move_left j := by { cases x, cases y, refl } @[simp] lemma neg_mk_mul_move_left_inl {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).move_left (sum.inl (i, j)) = -(xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j) := rfl @[simp] lemma neg_mk_mul_move_left_inr {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).move_left (sum.inr (i, j)) = -(xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j) := rfl @[simp] lemma neg_mk_mul_move_right_inl {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).move_right (sum.inl (i, j)) = -(xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j) := rfl @[simp] lemma neg_mk_mul_move_right_inr {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).move_right (sum.inr (i, j)) = -(xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j) := rfl lemma left_moves_mul_cases {x y : pgame} (k) {P : (x * y).left_moves → Prop} (hl : ∀ ix iy, P $ to_left_moves_mul (sum.inl ⟨ix, iy⟩)) (hr : ∀ jx jy, P $ to_left_moves_mul (sum.inr ⟨jx, jy⟩)) : P k := begin rw ←to_left_moves_mul.apply_symm_apply k, rcases to_left_moves_mul.symm k with ⟨ix, iy⟩ | ⟨jx, jy⟩, { apply hl }, { apply hr } end lemma right_moves_mul_cases {x y : pgame} (k) {P : (x * y).right_moves → Prop} (hl : ∀ ix jy, P $ to_right_moves_mul (sum.inl ⟨ix, jy⟩)) (hr : ∀ jx iy, P $ to_right_moves_mul (sum.inr ⟨jx, iy⟩)) : P k := begin rw ←to_right_moves_mul.apply_symm_apply k, rcases to_right_moves_mul.symm k with ⟨ix, iy⟩ | ⟨jx, jy⟩, { apply hl }, { apply hr } end /-- `x * y` and `y * x` have the same moves. -/ def mul_comm_relabelling : Π (x y : pgame.{u}), x * y ≡r y * x | ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ := begin refine ⟨equiv.sum_congr (equiv.prod_comm _ _) (equiv.prod_comm _ _), (equiv.sum_comm _ _).trans (equiv.sum_congr (equiv.prod_comm _ _) (equiv.prod_comm _ _)), _, _⟩; rintro (⟨i, j⟩ | ⟨i, j⟩); dsimp; exact ((add_comm_relabelling _ _).trans $ (mul_comm_relabelling _ _).add_congr (mul_comm_relabelling _ _)).sub_congr (mul_comm_relabelling _ _) end using_well_founded { dec_tac := pgame_wf_tac } theorem quot_mul_comm (x y : pgame.{u}) : ⟦x * y⟧ = ⟦y * x⟧ := quot.sound (mul_comm_relabelling x y).equiv /-- `x * y` is equivalent to `y * x`. -/ theorem mul_comm_equiv (x y : pgame) : x * y ≈ y * x := quotient.exact $ quot_mul_comm _ _ instance is_empty_mul_zero_left_moves (x : pgame.{u}) : is_empty (x * 0).left_moves := by { cases x, apply sum.is_empty } instance is_empty_mul_zero_right_moves (x : pgame.{u}) : is_empty (x * 0).right_moves := by { cases x, apply sum.is_empty } instance is_empty_zero_mul_left_moves (x : pgame.{u}) : is_empty (0 * x).left_moves := by { cases x, apply sum.is_empty } instance is_empty_zero_mul_right_moves (x : pgame.{u}) : is_empty (0 * x).right_moves := by { cases x, apply sum.is_empty } /-- `x * 0` has exactly the same moves as `0`. -/ def mul_zero_relabelling (x : pgame) : x * 0 ≡r 0 := relabelling.is_empty _ /-- `x * 0` is equivalent to `0`. -/ theorem mul_zero_equiv (x : pgame) : x * 0 ≈ 0 := (mul_zero_relabelling x).equiv @[simp] theorem quot_mul_zero (x : pgame) : ⟦x * 0⟧ = ⟦0⟧ := @quotient.sound _ _ (x * 0) _ x.mul_zero_equiv /-- `0 * x` has exactly the same moves as `0`. -/ def zero_mul_relabelling (x : pgame) : 0 * x ≡r 0 := relabelling.is_empty _ /-- `0 * x` is equivalent to `0`. -/ theorem zero_mul_equiv (x : pgame) : 0 * x ≈ 0 := (zero_mul_relabelling x).equiv @[simp] theorem quot_zero_mul (x : pgame) : ⟦0 * x⟧ = ⟦0⟧ := @quotient.sound _ _ (0 * x) _ x.zero_mul_equiv /-- `-x * y` and `-(x * y)` have the same moves. -/ def neg_mul_relabelling : Π (x y : pgame.{u}), -x * y ≡r -(x * y) | ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ := begin refine ⟨equiv.sum_comm _ _, equiv.sum_comm _ _, _, _⟩; rintro (⟨i, j⟩ | ⟨i, j⟩); dsimp; apply ((neg_add_relabelling _ _).trans _).symm; apply ((neg_add_relabelling _ _).trans (relabelling.add_congr _ _)).sub_congr; exact (neg_mul_relabelling _ _).symm end using_well_founded { dec_tac := pgame_wf_tac } @[simp] theorem quot_neg_mul (x y : pgame) : ⟦-x * y⟧ = -⟦x * y⟧ := quot.sound (neg_mul_relabelling x y).equiv /-- `x * -y` and `-(x * y)` have the same moves. -/ def mul_neg_relabelling (x y : pgame) : x * -y ≡r -(x * y) := (mul_comm_relabelling x _).trans $ (neg_mul_relabelling _ x).trans (mul_comm_relabelling y x).neg_congr @[simp] theorem quot_mul_neg (x y : pgame) : ⟦x * -y⟧ = -⟦x * y⟧ := quot.sound (mul_neg_relabelling x y).equiv @[simp] theorem quot_left_distrib : Π (x y z : pgame), ⟦x * (y + z)⟧ = ⟦x * y⟧ + ⟦x * z⟧ | (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR) := begin let x := mk xl xr xL xR, let y := mk yl yr yL yR, let z := mk zl zr zL zR, refine quot_eq_of_mk_quot_eq _ _ _ _, { fsplit, { rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩); solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 5 } }, { rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩); solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 5 } }, { rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩); refl }, { rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩); refl } }, { fsplit, { rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩); solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 5 } }, { rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩); solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 5 } }, { rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩); refl }, { rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩); refl } }, { rintro (⟨i, j | k⟩ | ⟨i, j | k⟩), { change ⟦xL i * (y + z) + x * (yL j + z) - xL i * (yL j + z)⟧ = ⟦xL i * y + x * yL j - xL i * yL j + x * z⟧, simp [quot_left_distrib], abel }, { change ⟦xL i * (y + z) + x * (y + zL k) - xL i * (y + zL k)⟧ = ⟦x * y + (xL i * z + x * zL k - xL i * zL k)⟧, simp [quot_left_distrib], abel }, { change ⟦xR i * (y + z) + x * (yR j + z) - xR i * (yR j + z)⟧ = ⟦xR i * y + x * yR j - xR i * yR j + x * z⟧, simp [quot_left_distrib], abel }, { change ⟦xR i * (y + z) + x * (y + zR k) - xR i * (y + zR k)⟧ = ⟦x * y + (xR i * z + x * zR k - xR i * zR k)⟧, simp [quot_left_distrib], abel } }, { rintro (⟨i, j | k⟩ | ⟨i, j | k⟩), { change ⟦xL i * (y + z) + x * (yR j + z) - xL i * (yR j + z)⟧ = ⟦xL i * y + x * yR j - xL i * yR j + x * z⟧, simp [quot_left_distrib], abel }, { change ⟦xL i * (y + z) + x * (y + zR k) - xL i * (y + zR k)⟧ = ⟦x * y + (xL i * z + x * zR k - xL i * zR k)⟧, simp [quot_left_distrib], abel }, { change ⟦xR i * (y + z) + x * (yL j + z) - xR i * (yL j + z)⟧ = ⟦xR i * y + x * yL j - xR i * yL j + x * z⟧, simp [quot_left_distrib], abel }, { change ⟦xR i * (y + z) + x * (y + zL k) - xR i * (y + zL k)⟧ = ⟦x * y + (xR i * z + x * zL k - xR i * zL k)⟧, simp [quot_left_distrib], abel } } end using_well_founded { dec_tac := pgame_wf_tac } /-- `x * (y + z)` is equivalent to `x * y + x * z.`-/ theorem left_distrib_equiv (x y z : pgame) : x * (y + z) ≈ x * y + x * z := quotient.exact $ quot_left_distrib _ _ _ @[simp] theorem quot_left_distrib_sub (x y z : pgame) : ⟦x * (y - z)⟧ = ⟦x * y⟧ - ⟦x * z⟧ := by { change ⟦x * (y + -z)⟧ = ⟦x * y⟧ + -⟦x * z⟧, rw [quot_left_distrib, quot_mul_neg] } @[simp] theorem quot_right_distrib (x y z : pgame) : ⟦(x + y) * z⟧ = ⟦x * z⟧ + ⟦y * z⟧ := by simp only [quot_mul_comm, quot_left_distrib] /-- `(x + y) * z` is equivalent to `x * z + y * z.`-/ theorem right_distrib_equiv (x y z : pgame) : (x + y) * z ≈ x * z + y * z := quotient.exact $ quot_right_distrib _ _ _ @[simp] theorem quot_right_distrib_sub (x y z : pgame) : ⟦(y - z) * x⟧ = ⟦y * x⟧ - ⟦z * x⟧ := by { change ⟦(y + -z) * x⟧ = ⟦y * x⟧ + -⟦z * x⟧, rw [quot_right_distrib, quot_neg_mul] } /-- `x * 1` has the same moves as `x`. -/ def mul_one_relabelling : Π (x : pgame.{u}), x * 1 ≡r x | ⟨xl, xr, xL, xR⟩ := begin unfold has_one.one, refine ⟨(equiv.sum_empty _ _).trans (equiv.prod_punit _), (equiv.empty_sum _ _).trans (equiv.prod_punit _), _, _⟩; try { rintro (⟨i, ⟨ ⟩⟩ | ⟨i, ⟨ ⟩⟩) }; try { intro i }; dsimp; apply (relabelling.sub_congr (relabelling.refl _) (mul_zero_relabelling _)).trans; rw sub_zero; exact (add_zero_relabelling _).trans (((mul_one_relabelling _).add_congr (mul_zero_relabelling _)).trans $ add_zero_relabelling _) end @[simp] theorem quot_mul_one (x : pgame) : ⟦x * 1⟧ = ⟦x⟧ := quot.sound $ mul_one_relabelling x /-- `x * 1` is equivalent to `x`. -/ theorem mul_one_equiv (x : pgame) : x * 1 ≈ x := quotient.exact $ quot_mul_one x /-- `1 * x` has the same moves as `x`. -/ def one_mul_relabelling (x : pgame) : 1 * x ≡r x := (mul_comm_relabelling 1 x).trans $ mul_one_relabelling x @[simp] theorem quot_one_mul (x : pgame) : ⟦1 * x⟧ = ⟦x⟧ := quot.sound $ one_mul_relabelling x /-- `1 * x` is equivalent to `x`. -/ theorem one_mul_equiv (x : pgame) : 1 * x ≈ x := quotient.exact $ quot_one_mul x theorem quot_mul_assoc : Π (x y z : pgame), ⟦x * y * z⟧ = ⟦x * (y * z)⟧ | (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR) := begin let x := mk xl xr xL xR, let y := mk yl yr yL yR, let z := mk zl zr zL zR, refine quot_eq_of_mk_quot_eq _ _ _ _, { fsplit, { rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩); solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 7 } }, { rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_,⟨_, _⟩ | ⟨_, _⟩⟩); solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 7 } }, { rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_,_⟩ | ⟨_, _⟩,_⟩); refl }, { rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_,⟨_, _⟩ | ⟨_, _⟩⟩); refl } }, { fsplit, { rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩,_⟩); solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 7 } }, { rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩); solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 7 } }, { rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩,_⟩); refl }, { rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩); refl } }, { rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩), { change ⟦(xL i * y + x * yL j - xL i * yL j) * z + (x * y) * zL k - (xL i * y + x * yL j - xL i * yL j) * zL k⟧ = ⟦xL i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) - xL i * (yL j * z + y * zL k - yL j * zL k)⟧, simp [quot_mul_assoc], abel }, { change ⟦(xR i * y + x * yR j - xR i * yR j) * z + (x * y) * zL k - (xR i * y + x * yR j - xR i * yR j) * zL k⟧ = ⟦xR i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) - xR i * (yR j * z + y * zL k - yR j * zL k)⟧, simp [quot_mul_assoc], abel }, { change ⟦(xL i * y + x * yR j - xL i * yR j) * z + (x * y) * zR k - (xL i * y + x * yR j - xL i * yR j) * zR k⟧ = ⟦xL i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) - xL i * (yR j * z + y * zR k - yR j * zR k)⟧, simp [quot_mul_assoc], abel }, { change ⟦(xR i * y + x * yL j - xR i * yL j) * z + (x * y) * zR k - (xR i * y + x * yL j - xR i * yL j) * zR k⟧ = ⟦xR i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) - xR i * (yL j * z + y * zR k - yL j * zR k)⟧, simp [quot_mul_assoc], abel } }, { rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩), { change ⟦(xL i * y + x * yL j - xL i * yL j) * z + (x * y) * zR k - (xL i * y + x * yL j - xL i * yL j) * zR k⟧ = ⟦xL i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) - xL i * (yL j * z + y * zR k - yL j * zR k)⟧, simp [quot_mul_assoc], abel }, { change ⟦(xR i * y + x * yR j - xR i * yR j) * z + (x * y) * zR k - (xR i * y + x * yR j - xR i * yR j) * zR k⟧ = ⟦xR i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) - xR i * (yR j * z + y * zR k - yR j * zR k)⟧, simp [quot_mul_assoc], abel }, { change ⟦(xL i * y + x * yR j - xL i * yR j) * z + (x * y) * zL k - (xL i * y + x * yR j - xL i * yR j) * zL k⟧ = ⟦xL i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) - xL i * (yR j * z + y * zL k - yR j * zL k)⟧, simp [quot_mul_assoc], abel }, { change ⟦(xR i * y + x * yL j - xR i * yL j) * z + (x * y) * zL k - (xR i * y + x * yL j - xR i * yL j) * zL k⟧ = ⟦xR i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) - xR i * (yL j * z + y * zL k - yL j * zL k)⟧, simp [quot_mul_assoc], abel } } end using_well_founded { dec_tac := pgame_wf_tac } /-- `x * y * z` is equivalent to `x * (y * z).`-/ theorem mul_assoc_equiv (x y z : pgame) : x * y * z ≈ x * (y * z) := quotient.exact $ quot_mul_assoc _ _ _ /-- Because the two halves of the definition of `inv` produce more elements on each side, we have to define the two families inductively. This is the indexing set for the function, and `inv_val` is the function part. -/ inductive inv_ty (l r : Type u) : bool → Type u | zero : inv_ty ff | left₁ : r → inv_ty ff → inv_ty ff | left₂ : l → inv_ty tt → inv_ty ff | right₁ : l → inv_ty ff → inv_ty tt | right₂ : r → inv_ty tt → inv_ty tt instance (l r : Type u) [is_empty l] [is_empty r] : is_empty (inv_ty l r tt) := ⟨by rintro (_|_|_|a|a); exact is_empty_elim a⟩ instance (l r : Type u) : inhabited (inv_ty l r ff) := ⟨inv_ty.zero⟩ instance unique_inv_ty (l r : Type u) [is_empty l] [is_empty r] : unique (inv_ty l r ff) := { uniq := by { rintro (a|a|a), refl, all_goals { exact is_empty_elim a } }, ..inv_ty.inhabited l r } /-- Because the two halves of the definition of `inv` produce more elements of each side, we have to define the two families inductively. This is the function part, defined by recursion on `inv_ty`. -/ def inv_val {l r} (L : l → pgame) (R : r → pgame) (IHl : l → pgame) (IHr : r → pgame) : ∀ {b}, inv_ty l r b → pgame | _ inv_ty.zero := 0 | _ (inv_ty.left₁ i j) := (1 + (R i - mk l r L R) * inv_val j) * IHr i | _ (inv_ty.left₂ i j) := (1 + (L i - mk l r L R) * inv_val j) * IHl i | _ (inv_ty.right₁ i j) := (1 + (L i - mk l r L R) * inv_val j) * IHl i | _ (inv_ty.right₂ i j) := (1 + (R i - mk l r L R) * inv_val j) * IHr i @[simp] theorem inv_val_is_empty {l r : Type u} {b} (L R IHl IHr) (i : inv_ty l r b) [is_empty l] [is_empty r] : inv_val L R IHl IHr i = 0 := begin cases i with a _ a _ a _ a, { refl }, all_goals { exact is_empty_elim a } end /-- The inverse of a positive surreal number `x = {L | R}` is given by `x⁻¹ = {0, (1 + (R - x) * x⁻¹L) * R, (1 + (L - x) * x⁻¹R) * L | (1 + (L - x) * x⁻¹L) * L, (1 + (R - x) * x⁻¹R) * R}`. Because the two halves `x⁻¹L, x⁻¹R` of `x⁻¹` are used in their own definition, the sets and elements are inductively generated. -/ def inv' : pgame → pgame | ⟨l, r, L, R⟩ := let l' := {i // 0 < L i}, L' : l' → pgame := λ i, L i.1, IHl' : l' → pgame := λ i, inv' (L i.1), IHr := λ i, inv' (R i) in ⟨inv_ty l' r ff, inv_ty l' r tt, inv_val L' R IHl' IHr, inv_val L' R IHl' IHr⟩ theorem zero_lf_inv' : ∀ (x : pgame), 0 ⧏ inv' x | ⟨xl, xr, xL, xR⟩ := by { convert lf_mk _ _ inv_ty.zero, refl } /-- `inv' 0` has exactly the same moves as `1`. -/ def inv'_zero : inv' 0 ≡r 1 := begin change mk _ _ _ _ ≡r 1, refine ⟨_, _, λ i, _, is_empty.elim _⟩, { apply equiv.equiv_punit (inv_ty _ _ _), apply_instance }, { apply equiv.equiv_pempty (inv_ty _ _ _), apply_instance }, { simp }, { dsimp, apply_instance } end theorem inv'_zero_equiv : inv' 0 ≈ 1 := inv'_zero.equiv /-- `inv' 1` has exactly the same moves as `1`. -/ def inv'_one : inv' 1 ≡r (1 : pgame.{u}) := begin change relabelling (mk _ _ _ _) 1, haveI : is_empty {i : punit.{u+1} // (0 : pgame.{u}) < 0}, { rw lt_self_iff_false, apply_instance }, refine ⟨_, _, λ i, _, is_empty.elim _⟩; dsimp, { apply equiv.equiv_punit }, { apply equiv.equiv_of_is_empty }, { simp }, { apply_instance } end theorem inv'_one_equiv : inv' 1 ≈ 1 := inv'_one.equiv /-- The inverse of a pre-game in terms of the inverse on positive pre-games. -/ noncomputable instance : has_inv pgame := ⟨by { classical, exact λ x, if x ≈ 0 then 0 else if 0 < x then inv' x else -inv' (-x) }⟩ noncomputable instance : has_div pgame := ⟨λ x y, x * y⁻¹⟩ theorem inv_eq_of_equiv_zero {x : pgame} (h : x ≈ 0) : x⁻¹ = 0 := by { classical, exact if_pos h } @[simp] theorem inv_zero : (0 : pgame)⁻¹ = 0 := inv_eq_of_equiv_zero (equiv_refl _) theorem inv_eq_of_pos {x : pgame} (h : 0 < x) : x⁻¹ = inv' x := by { classical, exact (if_neg h.lf.not_equiv').trans (if_pos h) } theorem inv_eq_of_lf_zero {x : pgame} (h : x ⧏ 0) : x⁻¹ = -inv' (-x) := by { classical, exact (if_neg h.not_equiv).trans (if_neg h.not_gt) } /-- `1⁻¹` has exactly the same moves as `1`. -/ def inv_one : 1⁻¹ ≡r 1 := by { rw inv_eq_of_pos pgame.zero_lt_one, exact inv'_one } theorem inv_one_equiv : 1⁻¹ ≈ 1 := inv_one.equiv end pgame
* Please select color and size in the drop down menu to check availability. KEEN Kids Targhee hiking shoes in big kids' sizes offer cushioned support, weatherproof performance, and all-terrain traction. They’ll attack every trail with confidence in our toughest hiking shoe style.
# -*- coding: utf-8 -*- """ Created on Tue Jan 22 16:40:48 2019 @author: amaity """ import numpy as np import pandas as pd df = pd.read_csv("profile-lacedfs-sniper_000.csv") PH1 = df['alloc'].values PH2 = df['alloc'].values muet = df['mu-time'].values ppgp = df['ppg-power'].values Z = open("et-power2.csv","w") for x in PH1: for y in PH2: # z = (muet[x-1]*ppgp[x-1] + 33*muet[y-1]*ppgp[y-1])/(muet[x-1]+muet[y-1]) z = np.max([ppgp[x-1],ppgp[y-1]]) Z.write(f'{z},') Z.write("\n") Z.close()
module Text.CSS.Dir import Data.List import Text.CSS.Length import Text.CSS.Percentage import Text.CSS.Render %default total public export data Dir : Type -> Type where All : a -> Dir a Left : a -> Dir a Right : a -> Dir a Top : a -> Dir a Bottom : a -> Dir a ||| Vertical and horizontal width VH : (v, h : a) -> Dir a ||| Top, horizontal, bottom width THB : (t, h, b : a) -> Dir a ||| Top, right, bottom, left TRBL : (t, r, b, l : a) -> Dir a -- prefix prfx : Dir a -> String prfx (Left _) = "-left" prfx (Right _) = "-right" prfx (Top _) = "-top" prfx (Bottom _) = "-bottom" prfx _ = "" export vals : Dir a -> List a vals (All x) = [x] vals (Left x) = [x] vals (Right x) = [x] vals (Top x) = [x] vals (Bottom x) = [x] vals (VH v h) = [v,h] vals (THB t h b) = [t,h,b] vals (TRBL t r b l) = [t,r,b,l] export render : (prop : String) -> (a -> String) -> Dir a -> String render prop f d = let vs = fastConcat . intersperse " " . map f $ vals d pre = prfx d in "\{prop}\{pre}: \{vs}" export render2 : (prop,suffix : String) -> (a -> String) -> Dir a -> String render2 prop suffix f d = let vs = fastConcat . intersperse " " . map f $ vals d pre = prfx d in "\{prop}\{pre}-\{suffix}: \{vs}" export %inline Cast Length a => Cast Length (Dir a) where cast = All . cast export %inline Cast Percentage a => Cast Percentage (Dir a) where cast = All . cast
function E = keplerEq(M,e,eps) % Function solves Kepler's equation M = E-e*sin(E) % Input - Mean anomaly M [rad] , Eccentricity e and Epsilon % Output eccentric anomaly E [rad]. En = M; Ens = En - (En-e*sin(En)- M)/(1 - e*cos(En)); while ( abs(Ens-En) > eps ) En = Ens; Ens = En - (En - e*sin(En) - M)/(1 - e*cos(En)); end; E = Ens;
lemma holomorphic_on_compose: "f holomorphic_on s \<Longrightarrow> g holomorphic_on (f ` s) \<Longrightarrow> (g o f) holomorphic_on s"
import tactic inductive Form : Type | atom : ℕ → Form | tensor : Form → Form → Form | par : Form → Form → Form | neg : Form → Form infix ` ⊗ `:70 := Form.tensor infix ` ⅋ `:65 := Form.par prefix `~` := Form.neg theorem not_self_dual {A} : A ≠ ~A := begin intro e, apply_fun Form.sizeof at e, refine ne_of_lt _ e, rw [Form.sizeof, nat.add_comm], exact nat.lt_succ_self _ , end theorem not_self_sub_left_tensor {A B} : A ≠ A ⊗ B := begin intro e, apply_fun Form.sizeof at e, refine ne_of_lt _ e, rw [Form.sizeof, nat.add_comm], apply nat.lt_of_succ_le, rw nat.add_comm, rw nat.add_comm 1, apply nat.le_add_right, end theorem not_self_sub_right_tensor {A B} : B ≠ A ⊗ B := begin intro e, apply_fun Form.sizeof at e, refine ne_of_lt _ e, rw [Form.sizeof, nat.add_comm], apply nat.lt_of_succ_le, rw [←nat.add_assoc], apply nat.le_add_right, end theorem not_self_sub_left_par {A B} : A ≠ A ⅋ B := begin intro e, apply_fun Form.sizeof at e, refine ne_of_lt _ e, rw [Form.sizeof, nat.add_comm], apply nat.lt_of_succ_le, rw nat.add_comm, rw nat.add_comm 1, apply nat.le_add_right, end theorem not_self_sub_right_par {A B} : B ≠ A ⅋ B := begin intro e, apply_fun Form.sizeof at e, refine ne_of_lt _ e, rw [Form.sizeof, nat.add_comm], apply nat.lt_of_succ_le, rw [←nat.add_assoc], apply nat.le_add_right, end inductive Link : Type | ax : ℕ → ℕ → Form → Link | cut : ℕ → ℕ → Form → Link | tensor : ℕ → ℕ → ℕ → Form → Form → Link | par : ℕ → ℕ → ℕ → Form → Form → Link | con : ℕ → Form → Link def Form_occ := Form × ℕ def is_premise (Ai : Form_occ) : Link → Prop | (Link.ax n m B) := false | (Link.cut n m B) := (Ai = ⟨B,n⟩) ∨ (Ai = ⟨~B,m⟩) | (Link.tensor n m k A B) := (Ai = ⟨A,n⟩) ∨ (Ai = ⟨B,m⟩) | (Link.par n m k A B) := (Ai = ⟨A,n⟩) ∨ (Ai = ⟨B,m⟩) | (Link.con n A) := Ai = ⟨A,n⟩ def is_conclusion (Ai : Form_occ) : Link → Prop | (Link.ax n m B) := (Ai = ⟨B,n⟩) ∨ (Ai = ⟨~B,m⟩) | (Link.cut n m B) := false | (Link.tensor n m k A B) := Ai = ⟨A ⊗ B,k⟩ | (Link.par n m k A B) := Ai = ⟨A ⅋ B,k⟩ | (Link.con n A) := false inductive valid_link : Link → Prop | ax (i j A) : valid_link (Link.ax i j A) | cut (i j A) : valid_link (Link.cut i j A) | tensor (i j k A B) : (A,i) ≠ (B,j) → valid_link (Link.tensor i j k A B) | par (i j k A B) : (A,i) ≠ (B,j) → valid_link (Link.par i j k A B) | con (i A) : valid_link (Link.con i A) structure proof_structure : Type := (links : set Link) (valid : ∀ l ∈ links, valid_link l) (form_occs : set Form_occ) (link_prem : ∀ l ∈ links, ∀ Ai : Form_occ, is_premise Ai l → Ai ∈ form_occs) (link_con : ∀ l ∈ links, ∀ Ai : Form_occ, is_conclusion Ai l → Ai ∈ form_occs) (premise : Form_occ → Link) (prem_unique : ∀ Ai ∈ form_occs, ∀ l ∈ links, is_premise Ai l → premise Ai = l) (prem_range : ∀ Ai ∈ form_occs, premise Ai ∈ links ∧ is_premise Ai (premise Ai)) (conclusion : Form_occ → Link) (con_unique : ∀ Ai ∈ form_occs, ∀ l ∈ links, is_conclusion Ai l → conclusion Ai = l) (con_range : ∀ Ai ∈ form_occs, conclusion Ai ∈ links ∧ is_conclusion Ai (conclusion Ai)) @[reducible] def dir := bool @[pattern] def down := ff @[pattern] def up := tt @[pattern] def with_down (Ai : Form_occ) := (Ai,down) @[pattern] def with_up (Ai : Form_occ) := (Ai,up) postfix `↓`:max_plus := with_down postfix `↑`:max_plus := with_up @[reducible] def switch := bool @[reducible, pattern] def L := ff @[reducible, pattern] def R := tt def switching := Link → switch @[simp] def switch.flip {α β} (f : α → α → β) : switch → α → α → β | L a b := f a b | R a b := f b a @[simp] lemma flip_L {α β} {f : α → α → β} {a b} : switch.flip f L a b = f a b := rfl @[simp] lemma flip_R {α β} {f : α → α → β} {a b} : switch.flip f R a b = f b a := rfl inductive steps_tensor (Ai Bi Ci : Form_occ) : Form_occ × dir → Form_occ × dir → Prop | down : steps_tensor Ai↓ Ci↓ | turn : steps_tensor Bi↓ Ai↑ | up : steps_tensor Ci↑ Bi↑ inductive steps_par (Ai Bi Ci : Form_occ) : Form_occ × dir → Form_occ × dir → Prop | down : steps_par Ai↓ Ci↓ | turn : steps_par Bi↓ Bi↑ | up : steps_par Ci↑ Ai↑ inductive dual (A : Form) (ai ni : ℕ) : Form_occ → Form_occ → Prop | posneg : dual (A,ai) (~A,ni) | negpos : dual (~A,ni) (A,ai) inductive steps (T : switch) : Link → Form_occ × dir → Form_occ × dir → Prop | ax (A : Form) (ai ni : ℕ) (Bi Ci) : dual A ai ni Bi Ci → steps (Link.ax ai ni A) Bi↑ Ci↓ | cut (A : Form) (ai ni : ℕ) (Bi Ci) : dual A ai ni Bi Ci → steps (Link.cut ai ni A) Bi↓ Ci↑ | con (A : Form) (ai : ℕ) : steps (Link.con ai A) (A, ai)↓ (A,ai)↑ | tensor (A B : Form) (ai bi ci : ℕ) (x y) : T.flip steps_tensor (A, ai) (B, bi) (A ⊗ B, ci) x y → steps (Link.tensor ai bi ci A B) x y | par (A B : Form) (ai bi ci : ℕ) (x y) : T.flip steps_par (A, ai) (B, bi) (A ⅋ B, ci) x y → steps (Link.par ai bi ci A B) x y theorem dual_unique_prev {A ai ni Bi Ci Di} (d₁ : dual A ai ni Bi Ci) (d₂ : dual A ai ni Di Ci) : Bi = Di := begin generalize_hyp e : Ci = Ci' at d₂, have : A ≠ ~A, { intro e, apply_fun Form.sizeof at e, refine ne_of_lt _ e, rw [Form.sizeof, nat.add_comm], exact nat.lt_succ_self _ }, cases d₁; cases d₂; injection e with e1 e2; cases e2; try { cases e1 }; [refl, cases this e1.symm, cases this e1, refl] end theorem steps_tensor_unique_prev (Ai Bi Ci : Form_occ) (X Y Z) : Ai ≠ Bi → Bi ≠ Ci → Ai ≠ Ci → steps_tensor Ai Bi Ci X Z → steps_tensor Ai Bi Ci Y Z → X = Y := begin intros _ _ _ s₁ s₂, cases s₁; cases s₂; try {refl}; try {contradiction}, end theorem steps_tensor_unique_next (Ai Bi Ci : Form_occ) (X Y Z) : Ai ≠ Bi → Bi ≠ Ci → Ai ≠ Ci → steps_tensor Ai Bi Ci X Y → steps_tensor Ai Bi Ci X Z → Y = Z := begin intros _ _ _ s₁ s₂, cases s₁; cases s₂; try {refl}; try {contradiction}, end theorem steps_par_unique_prev (Ai Bi Ci : Form_occ) (X Y Z) : Ai ≠ Bi → Bi ≠ Ci → Ai ≠ Ci → steps_par Ai Bi Ci X Z → steps_par Ai Bi Ci Y Z → X = Y := begin intros _ _ _ s₁ s₂, cases s₁; cases s₂; try {refl}; try {contradiction}, end theorem steps_par_unique_next (Ai Bi Ci : Form_occ) (X Y Z) : Ai ≠ Bi → Bi ≠ Ci → Ai ≠ Ci → steps_par Ai Bi Ci X Y → steps_par Ai Bi Ci X Z → Y = Z := begin intros _ _ _ s₁ s₂, cases s₁; cases s₂; try {refl}; try {contradiction}, end theorem steps_unique_prev {T : switch} {Δ : Link} {X Y Z} : valid_link Δ → steps T Δ X Z → steps T Δ Y Z → X = Y := begin intros hΔ s₁ s₂, cases s₁, case steps.ax : A ai ni Bi Ci d₁ { cases s₂ with _ _ _ Di _ d₂, rw dual_unique_prev d₁ d₂ }, case steps.cut : A ai ni Bi Ci d₁ { rcases s₂ with _ | ⟨_,_,_,Di,_,d₂⟩, rw dual_unique_prev d₂ d₁ }, case steps.con : A ai { cases s₂, refl }, case steps.tensor : A B ai bi ci X y t₁ { rcases s₂ with _ | _ | _ | ⟨_,_,_,_,_,_,_,t₂⟩, cases T; simp at t₁ t₂; apply steps_tensor_unique_prev _ _ _ _ _ _ _ _ _ t₁ t₂; cases hΔ, finish, intro e, injection e with e1, exact not_self_sub_right_tensor e1, intro e, injection e with e1, exact not_self_sub_left_tensor e1, finish, intro e, injection e with e1, exact not_self_sub_left_tensor e1, intro e, injection e with e1, exact not_self_sub_right_tensor e1, }, case steps.par : A B ai bi ci X y p₁ { rcases s₂ with _ | _ | _ | _ | ⟨_,_,_,_,_,_,_,p₂⟩, cases T; simp at p₁ p₂; apply steps_par_unique_prev _ _ _ _ _ _ _ _ _ p₁ p₂; cases hΔ, finish, intro e, injection e with e1, exact not_self_sub_right_par e1, intro e, injection e with e1, exact not_self_sub_left_par e1, finish, intro e, injection e with e1, exact not_self_sub_left_par e1, intro e, injection e with e1, exact not_self_sub_right_par e1, }, end inductive trip (ps : proof_structure) (S : switching) : list (Form_occ × dir) → Prop | emp : trip [] | single (Ai : Form_occ) (d : dir) : Ai ∈ ps.form_occs → trip [(Ai,d)] | consup (Ai Bi : Form_occ) (d : dir) (Γ : list (Form_occ × dir)) : Ai ∈ ps.form_occs → (steps (S (ps.premise Bi)) (ps.premise Bi) (Ai,d) Bi↑) → trip (Bi↑ :: Γ) → trip ((Ai,d) :: Bi↑ :: Γ) | consdown (Ai Bi : Form_occ) (d : dir) (Γ : list (Form_occ × dir)) : Ai ∈ ps.form_occs → (steps (S (ps.conclusion Bi)) (ps.conclusion Bi) (Ai,d) Bi↓) → trip (Bi↓ :: Γ) → trip ((Ai,d) :: Bi↓ :: Γ) theorem trip_in_form_occs {ps : proof_structure} (S : switching) (Γ : list (Form_occ × dir)): trip ps S Γ → ∀ Ai d, (Ai,d) ∈ Γ → Ai ∈ ps.form_occs := begin induction Γ, intros _ _ _ h, cases h, intros t Ai d h, case list.cons : Ai Γ ih { cases t with Bi d₁ hB Ci Di d₂ Γ hC s₁ t₁ Ci Di d₂ Γ hC s₁ t₁, { cases h; cases h, assumption, }, repeat { cases h; cases h, assumption, apply ih t₁, constructor, exact h, apply ih t₁, right, exact h, }, } end theorem premise_valid_link {ps : proof_structure} : ∀ {Ai ∈ ps.form_occs}, valid_link (ps.premise Ai) := λ A hA, ps.valid _ (ps.prem_range _ hA).1 theorem conclusion_valid_link {ps : proof_structure} : ∀ {Ai ∈ ps.form_occs}, valid_link (ps.conclusion Ai) := λ A hA, ps.valid _ (ps.con_range _ hA).1 theorem trip_unique_cons (ps : proof_structure) (S : switching) (t : list (Form_occ × dir)) (nnil : t ≠ []) (Ai Bi : Form_occ) (d₁ d₂ : dir) : trip ps S ((Ai,d₁)::t) → trip ps S ((Bi,d₂)::t) → (Ai,d₁) = (Bi,d₂) := begin intros tA tB, cases t with Cid t, contradiction, cases d₁, cases d₂, repeat { rcases tA with _ | _ | ⟨_,Ci,_,_,hA,sAC,t₁⟩ | ⟨_,Ci,_,_,hA,sAC,t₁⟩, rcases tB with _ | _ | ⟨_,_,_,_,hB,sBC,t₂⟩, apply steps_unique_prev _ sAC sBC, apply premise_valid_link, apply trip_in_form_occs _ _ t₂, left, refl, rcases tB with _ | _ | _ | ⟨_,Ci,_,_,hB,sBC,t₂⟩, apply steps_unique_prev _ sAC sBC, apply conclusion_valid_link, apply trip_in_form_occs _ _ t₂, left, refl }, end theorem trip_unique (ps : proof_structure) (S : switching) (t : list (Form_occ × dir)) (nnil : t ≠ []) (Ai Bi : Form_occ) (d₁ d₂ : dir) : trip ps S ((Ai,d₁)::t) → trip ps S ((Bi,d₂)::t) → def length_non_nil {α} (p : list α) : length p > 1 → p ≠ [] := begin intros ip, intro h, rw h at ip, have : nil.length = 0, trivial, rw this at ip, cases ip, end def cycle_trip (ps : proof_structure) (S : switching) (Ai : Form_occ) (d : dir) (p : list (Form_occ × dir)) (ip : p ≠ []) : Prop := trip ps S (⟨Ai,d⟩::p) ∧ steps (S )(last p ip) def rotate {α} (l : list α) (n : ℕ) := drop n l ++ take n l def cycle_equiv {α} (l1 l2 : list α) := ∃ n : ℕ, rotate l1 n = l2 def longtrip (ps : proof_structure) (S1 S2 : switching) (p1 p2 : list (Form_occ × dir)) (ip1 : length p1 > 1) (ip2 : length p2 > 1) : Prop := cycle_trip ps S1 p1 ip1 → cycle_trip ps S2 p2 ip2 → cycle_equiv p1 p2 -- theorem tensor_rotate def ax_cut (A : Form) : proof_structure := {links := {Link.ax 0 1 A, Link.cut 0 1 A}, form_occs := {⟨A,0⟩, ⟨~A,1⟩}, link_prem := begin intros l hl Ai hp, cases hl, rw hl at hp, cases hp, cases hl, cases hp; finish, end, link_con := begin intros l hl Ai hc, cases hl, rw hl at hc, cases hc; finish, cases hl, cases hc; finish, end, premise := (λ Ai, Link.cut 0 1 A), prem_unique := begin intros Ai hA l hl pl, cases hl, rw hl at pl, cases pl; finish, cases hl, cases pl; finish, end, prem_range := begin intros Ai hA, split, finish, cases hA, left, exact hA, right, cases hA, refl, end, conclusion := λ Ai, Link.ax 0 1 A, con_unique := begin intros Ai hA l hl cl, cases hA, cases hl, finish, cases hl, cases cl, cases hA, cases hl, finish, cases hl, cases cl end, con_range := by intros; finish}
Formal statement is: lemma holomorphic_transform: "\<lbrakk>f holomorphic_on s; \<And>x. x \<in> s \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> g holomorphic_on s" Informal statement is: If $f$ is holomorphic on $s$ and $f(x) = g(x)$ for all $x \in s$, then $g$ is holomorphic on $s$.
import Data.Vect myReverse : Vect n elem -> Vect n elem myReverse [] = [] myReverse (x :: xs) = reverseProof (myReverse xs ++ [x]) where reverseProof : Vect (len + 1) elem -> Vect (S len) elem reverseProof result = rewrite plusCommutative 1 len in result
If $f$ and $g$ are continuous real-valued functions on a topological space $X$, then the function $x \mapsto \min(f(x), g(x))$ is continuous.
(* * Copyright 2014, General Dynamics C4 Systems * * SPDX-License-Identifier: GPL-2.0-only *) (* Proofs about untyped invocations. *) theory Untyped_AI imports "./$L4V_ARCH/ArchDetype_AI" "Lib.MonadicRewrite" begin context begin interpretation Arch . requalify_consts region_in_kernel_window arch_default_cap second_level_tables safe_ioport_insert requalify_facts set_cap_valid_arch_caps_simple set_cap_kernel_window_simple set_cap_ioports' safe_ioport_insert_triv end primrec valid_untyped_inv_wcap :: "Invocations_A.untyped_invocation \<Rightarrow> cap option \<Rightarrow> 'z::state_ext state \<Rightarrow> bool" where "valid_untyped_inv_wcap (Retype slot reset ptr_base ptr ty us slots dev) = (\<lambda>co s. \<exists>sz idx. (cte_wp_at (\<lambda>c. c = (cap.UntypedCap dev ptr_base sz idx) \<and> (co = None \<or> co = Some c)) slot s \<and> range_cover ptr sz (obj_bits_api ty us) (length slots) \<and> (idx \<le> unat (ptr - ptr_base) \<or> (reset \<and> ptr = ptr_base)) \<and> (ptr && ~~ mask sz) = ptr_base) \<and> (reset \<longrightarrow> descendants_of slot (cdt s) = {}) \<and> (ty = CapTableObject \<longrightarrow> us > 0) \<and> (ty = Untyped \<longrightarrow> us \<ge> untyped_min_bits) \<and> distinct (slot#slots) \<and> (\<forall>slot\<in>set slots. cte_wp_at ((=) cap.NullCap) slot s \<and> ex_cte_cap_wp_to is_cnode_cap slot s \<and> real_cte_at slot s) \<and> ty \<noteq> ArchObject ASIDPoolObj \<and> 0 < length slots \<and> (dev \<longrightarrow> ((ty = Untyped) \<or> is_frame_type ty)))" abbreviation "valid_untyped_inv ui \<equiv> valid_untyped_inv_wcap ui None" lemma valid_untyped_inv_wcap: "valid_untyped_inv ui = (\<lambda>s. \<exists>sz idx. valid_untyped_inv_wcap ui (Some (case ui of Retype slot reset ptr_base ptr ty us slots dev \<Rightarrow> UntypedCap dev (ptr && ~~ mask sz) sz idx)) s)" apply (cases ui) apply (clarsimp simp: fun_eq_iff cte_wp_at_caps_of_state intro!: arg_cong[where f=Ex] conj_cong[OF refl]) apply auto done locale Untyped_AI_of_bl_nat_to_cref = assumes of_bl_nat_to_cref: "\<lbrakk> x < 2 ^ bits; bits < word_bits \<rbrakk> \<Longrightarrow> (of_bl (nat_to_cref bits x) :: machine_word) = of_nat x" lemma cnode_cap_bits_range: "\<lbrakk> cte_wp_at P p s; invs s \<rbrakk> \<Longrightarrow> (\<exists>c. P c \<and> (is_cnode_cap c \<longrightarrow> (\<lambda>n. n > 0 \<and> n < (word_bits - cte_level_bits) \<and> is_aligned (obj_ref_of c) (n + cte_level_bits)) (bits_of c)))" apply (frule invs_valid_objs) apply (drule(1) cte_wp_at_valid_objs_valid_cap) apply clarsimp apply (rule exI, erule conjI) apply (clarsimp simp: is_cap_simps valid_cap_def bits_of_def) apply (erule (1) obj_at_valid_objsE) apply (case_tac ko, simp_all add: is_cap_table_def)[1] apply (clarsimp simp: valid_obj_def valid_cs_def well_formed_cnode_n_def valid_cs_size_def length_set_helper word_bits_def) apply (drule invs_psp_aligned) apply (unfold pspace_aligned_def) apply (frule domI, drule (1) bspec) apply (clarsimp simp: ex_with_length add.commute split: if_split_asm) done (* FIXME: move *) lemma cte_wp_at_wellformed_strengthen: "cte_at p s \<and> valid_objs s \<longrightarrow> cte_wp_at wellformed_cap p s" apply (clarsimp simp: cte_wp_at_caps_of_state) apply (frule (1) caps_of_state_valid_cap) apply (simp add: valid_cap_def2) done (* FIXME: move *) lemma get_cap_cte_wp_at_P: "\<lbrace>cte_wp_at P p\<rbrace> get_cap p \<lbrace>\<lambda>rv s. cte_wp_at (%c. c = rv) p s \<and> P rv\<rbrace>" apply (rule hoare_weaken_pre) apply (rule get_cap_wp) apply (clarsimp simp: cte_wp_at_caps_of_state) done lemma lookup_cap_ex: "\<lbrace>valid_objs\<rbrace> lookup_cap t x \<lbrace>\<lambda>rv s. valid_objs s \<and> (\<exists>p1 p2 m c'. rv = mask_cap m c' \<and> cte_wp_at (\<lambda>c. c = c') (p1, p2) s)\<rbrace>,-" apply (simp add: lookup_cap_def split_def) apply wp apply (rule_tac P1=wellformed_cap in hoare_strengthen_post[OF get_cap_cte_wp_at_P]) apply clarsimp apply (rule exI)+ apply (subst cap_mask_UNIV, simp) apply fastforce apply (wpsimp|strengthen cte_wp_at_wellformed_strengthen)+ done lemma is_cnode_mask: "is_cnode_cap (mask_cap m c) = is_cnode_cap c" by (case_tac c, simp_all add: mask_cap_def cap_rights_update_def is_cap_simps split:bool.splits) lemma Suc_length_not_empty: "length xs = length xs' \<Longrightarrow> Suc 0 \<le> length xs' = (xs \<noteq> [])" by (fastforce simp: le_simps) lemmas Suc_length_not_empty' = Suc_length_not_empty [OF refl] (* FIXME: hides Invariants_AI.caps_of_state_valid, FIXME: duplicate of Invariants_AI.caps_of_state_valid_cap *) lemma caps_of_state_valid: "\<lbrakk>invs s; caps_of_state s p = Some cap \<rbrakk> \<Longrightarrow> s \<turnstile> cap" apply (rule cte_wp_valid_cap) apply (simp add: cte_wp_at_caps_of_state) apply clarsimp done lemma mask_CNodeD: "mask_cap M' cap = cap.CNodeCap r bits g \<Longrightarrow> cap = cap.CNodeCap r bits g" by (cases cap, auto simp: mask_cap_def cap_rights_update_def split:bool.splits) (* FIXME: move *) lemma unat_2p_sub_1: "k < len_of TYPE('a) \<Longrightarrow> unat (2 ^ k - 1 :: 'a :: len word) = unat (2 ^ k :: 'a word) - 1" by (simp add: unat_minus_one) lemma compute_free_index_wp: "\<lbrace>\<top>\<rbrace> const_on_failure idx (doE y \<leftarrow> ensure_no_children slot; returnOk (0::nat) odE) \<lbrace>\<lambda>rv s. rv \<le> idx\<rbrace>" apply (rule hoare_pre) apply (wp const_on_failure_wp) apply clarsimp done lemma dui_inv[wp]: "\<lbrace>P\<rbrace> decode_untyped_invocation label args slot (cap.UntypedCap dev w n idx) cs \<lbrace>\<lambda>rv. P\<rbrace>" apply (simp add: decode_untyped_invocation_def whenE_def split_def data_to_obj_type_def unlessE_def split del: if_split cong: if_cong) apply (rule hoare_pre) apply (simp split del: if_split | wp (once) mapME_x_inv_wp hoare_drop_imps const_on_failure_wp | assumption | simp add: lookup_target_slot_def | wpcw | wp)+ done lemma map_ensure_empty_cte_wp_at: "\<lbrace>cte_wp_at P p\<rbrace> mapME_x ensure_empty xs \<lbrace>\<lambda>rv. cte_wp_at P p\<rbrace>,-" unfolding mapME_x_def sequenceE_x_def by (induct xs; wpsimp) lemma map_ensure_empty: "\<lbrace>P\<rbrace> mapME_x ensure_empty xs \<lbrace>\<lambda>rv s. (\<forall>x \<in> set xs. cte_wp_at ((=) cap.NullCap) x s) \<and> P s\<rbrace>,-" apply (induct xs) apply (simp add: mapME_x_def sequenceE_x_def) apply wp apply (simp add: mapME_x_def sequenceE_x_def) apply (unfold validE_R_def) apply (rule seqE[rotated]) apply (rule hoare_vcg_conj_liftE1) apply (fold sequenceE_x_def mapME_x_def)[1] apply (rule map_ensure_empty_cte_wp_at) apply assumption apply (simp add: ensure_empty_def whenE_def) apply (rule hoare_pre, wp get_cap_wp) apply clarsimp done lemma ensure_no_children_sp: "\<lbrace>P\<rbrace> ensure_no_children slot \<lbrace>\<lambda>rv s. descendants_of slot (cdt s) = {} \<and> P s\<rbrace>,-" apply (simp add: ensure_no_children_descendants) apply (clarsimp simp: valid_def validE_def validE_R_def split_def in_monad | rule conjI)+ done lemma data_to_obj_type_inv: "\<lbrace>P\<rbrace> data_to_obj_type v \<lbrace>\<lambda>rv. P\<rbrace>" apply (simp add: data_to_obj_type_def) apply (intro conjI impI; wpsimp) done lemma data_to_obj_type_inv2 [wp]: "\<lbrace>P\<rbrace> data_to_obj_type v \<lbrace>\<lambda>rv. P\<rbrace>,-" by (wp data_to_obj_type_inv) lemma get_cap_gets: "\<lbrace>valid_objs\<rbrace> get_cap ptr \<lbrace>\<lambda>rv s. \<exists>cref msk. cte_wp_at (\<lambda>cap. rv = mask_cap msk cap) cref s\<rbrace>" apply (wp get_cap_wp) apply (intro allI impI) apply (rule_tac x=ptr in exI) apply (rule_tac x=UNIV in exI) apply (simp add: cte_wp_at_caps_of_state) apply (frule (1) caps_of_state_valid_cap) apply (clarsimp simp add: valid_cap_def2) done lemma lookup_cap_gets: "\<lbrace>valid_objs\<rbrace> lookup_cap t c \<lbrace>\<lambda>rv s. \<exists>cref msk. cte_wp_at (\<lambda>cap. rv = mask_cap msk cap) cref s\<rbrace>,-" unfolding lookup_cap_def fun_app_def split_def apply (rule hoare_pre, wp get_cap_gets) apply simp done lemma dui_sp_helper: "(\<And>s. P s \<Longrightarrow> valid_objs s) \<Longrightarrow> \<lbrace>P\<rbrace> if val = 0 then returnOk root_cap else doE node_slot \<leftarrow> lookup_target_slot root_cap (to_bl (args ! 2)) (unat (args ! 3)); liftE $ get_cap node_slot odE \<lbrace>\<lambda>rv s. (rv = root_cap \<or> (\<exists>slot. cte_wp_at ((=) rv) slot s)) \<and> P s\<rbrace>, -" apply (simp add: split_def lookup_target_slot_def) apply (intro impI conjI) apply wpsimp apply (wp get_cap_wp) apply (rule hoare_post_imp_R [where Q'="\<lambda>rv. valid_objs and P"] ; wpsimp simp: cte_wp_at_caps_of_state) apply simp done locale Untyped_AI_arch = fixes state_ext_t :: "('state_ext::state_ext) itself" assumes data_to_obj_type_sp: "\<And>P x. \<lbrace>P\<rbrace> data_to_obj_type x \<lbrace>\<lambda>ts (s::'state_ext state). ts \<noteq> ArchObject ASIDPoolObj \<and> P s\<rbrace>, -" assumes dui_inv_wf[wp]: "\<And>w sz idx slot cs label args dev.\<lbrace>invs and cte_wp_at ((=) (cap.UntypedCap dev w sz idx)) slot and (\<lambda>(s::'state_ext state). \<forall>cap \<in> set cs. is_cnode_cap cap \<longrightarrow> (\<forall>r\<in>cte_refs cap (interrupt_irq_node s). ex_cte_cap_wp_to is_cnode_cap r s)) and (\<lambda>s. \<forall>x \<in> set cs. s \<turnstile> x)\<rbrace> decode_untyped_invocation label args slot (cap.UntypedCap dev w sz idx) cs \<lbrace>valid_untyped_inv\<rbrace>,-" assumes retype_ret_valid_caps_captable: "\<And>ptr sz dev us n s.\<lbrakk>pspace_no_overlap_range_cover ptr sz (s::'state_ext state) \<and> 0 < us \<and> range_cover ptr sz (obj_bits_api CapTableObject us) n \<and> ptr \<noteq> 0 \<rbrakk> \<Longrightarrow> \<forall>y\<in>{0..<n}. s \<lparr>kheap := foldr (\<lambda>p kh. kh(p \<mapsto> default_object CapTableObject dev us)) (map (\<lambda>p. ptr_add ptr (p * 2 ^ obj_bits_api CapTableObject us)) [0..<n]) (kheap s)\<rparr> \<turnstile> CNodeCap (ptr_add ptr (y * 2 ^ obj_bits_api CapTableObject us)) us []" assumes retype_ret_valid_caps_aobj: "\<And>ptr sz s x6 us n dev. \<lbrakk>pspace_no_overlap_range_cover ptr sz (s::'state_ext state) \<and> x6 \<noteq> ASIDPoolObj \<and> range_cover ptr sz (obj_bits_api (ArchObject x6) us) n \<and> ptr \<noteq> 0 \<comment> \<open>; tp = ArchObject x6\<close>\<rbrakk> \<Longrightarrow> \<forall>y\<in>{0..<n}. s \<lparr>kheap := foldr (\<lambda>p kh. kh(p \<mapsto> default_object (ArchObject x6) dev us)) (map (\<lambda>p. ptr_add ptr (p * 2 ^ obj_bits_api (ArchObject x6) us)) [0..<n]) (kheap s)\<rparr> \<turnstile> ArchObjectCap (arch_default_cap x6 (ptr_add ptr (y * 2 ^ obj_bits_api (ArchObject x6) us)) us dev)" assumes init_arch_objects_descendants_range[wp]: "\<And>x cref ty ptr n us y. \<lbrace>\<lambda>(s::'state_ext state). descendants_range x cref s \<rbrace> init_arch_objects ty ptr n us y \<lbrace>\<lambda>rv s. descendants_range x cref s\<rbrace>" assumes init_arch_objects_caps_overlap_reserved[wp]: "\<And>S ty ptr n us y. \<lbrace>\<lambda>(s::'state_ext state). caps_overlap_reserved S s\<rbrace> init_arch_objects ty ptr n us y \<lbrace>\<lambda>rv s. caps_overlap_reserved S s\<rbrace>" assumes delete_objects_rewrite: "\<And>sz ptr. \<lbrakk> word_size_bits \<le> sz; sz\<le> word_bits; ptr && ~~ mask sz = ptr \<rbrakk> \<Longrightarrow> delete_objects ptr sz = do y \<leftarrow> modify (clear_um {ptr + of_nat k |k. k < 2 ^ sz}); modify (detype {ptr && ~~ mask sz..ptr + 2 ^ sz - 1} :: 'state_ext state \<Rightarrow> 'state_ext state) od" assumes obj_is_device_vui_eq: "valid_untyped_inv ui (s :: 'state_ext state) \<Longrightarrow> case ui of Retype slot reset ptr_base ptr tp us slots dev \<Rightarrow> obj_is_device tp dev = dev" lemmas is_aligned_triv2 = Aligned.is_aligned_triv lemma strengthen_imp_ex2: "(P \<longrightarrow> Q x y) \<Longrightarrow> (P \<longrightarrow> (\<exists>x y. Q x y))" by auto lemma p2_minus: "sz < len_of TYPE('a) \<Longrightarrow> of_nat (2 ^ len_of TYPE('a) - 2 ^ sz) = ((mask (len_of TYPE('a)) && ~~ mask sz):: 'a :: len word)" apply (rule word_unat.Rep_inverse') apply (simp add: mask_out_sub_mask) apply (simp add: unat_sub word_and_le2 mask_and_mask) apply (simp add: min_def mask_def word_size unat_minus) done lemma range_cover_bound': fixes ptr :: "'a :: len word" assumes cover: "range_cover ptr sz sbit n" assumes le : "x < n" shows "unat (ptr + of_nat x * 2 ^ sbit) + 2 ^ sbit \<le> 2 ^ len_of TYPE('a)" proof - have l: "unat (ptr && ~~ mask sz) + 2^ sz \<le> 2^ len_of TYPE('a)" using cover apply - apply (rule le_diff_conv2[THEN iffD1]) apply (simp add: range_cover_def) apply (rule unat_le_helper) apply (subst p2_minus) apply (erule range_cover.sz) apply (rule neg_mask_mono_le) apply (simp add: mask_def) done have n: "unat ((ptr && mask sz) + of_nat x * 2 ^ sbit) + 2^sbit \<le> 2 ^ sz" apply (rule le_trans[OF _ range_cover.range_cover_compare_bound[OF cover]]) apply (rule le_trans[where j = "(x+1) * 2^sbit + unat (ptr && mask sz)"]) apply clarsimp apply (rule le_trans[OF unat_plus_gt]) using le apply (simp add: range_cover.unat_of_nat_shift[OF cover]) apply simp using le apply (case_tac n,simp+) done show ?thesis using cover le apply - apply (frule iffD1[OF meta_eq_to_obj_eq[OF range_cover_def]]) apply (clarsimp) apply (frule range_cover_le[where n=x]) apply simp apply (subst word_plus_and_or_coroll2[symmetric,where w = "mask sz"]) apply (subst add.commute) apply (subst add.assoc) apply (subst unat_plus_simple[THEN iffD1]) apply (rule is_aligned_no_wrap') apply (rule is_aligned_neg_mask[OF le_refl]) apply (simp add: range_cover_def) apply (simp add: word_less_nat_alt) apply (rule le_less_trans[OF unat_plus_gt]) apply (erule range_cover.range_cover_compare[OF cover]) apply (subst add.assoc) apply (rule le_trans[OF _ l]) apply simp apply (simp add: n) done qed lemma range_cover_stuff: notes unat_power_lower_machine = unat_power_lower[where 'a=machine_word_len] notes unat_of_nat_machine = unat_of_nat_eq[where 'a=machine_word_len] notes is_aligned_neg_mask_eq[simp del] notes is_aligned_neg_mask_weaken[simp del] shows "\<lbrakk>0 < n;n \<le> unat ((2::machine_word) ^ sz - of_nat rv >> bits); rv \<le> 2^ sz; sz < word_bits; is_aligned w sz\<rbrakk> \<Longrightarrow> rv \<le> unat (alignUp (w + of_nat rv) bits - w) \<and> (alignUp (w + of_nat rv) bits) && ~~ mask sz = w \<and> range_cover (alignUp (w + ((of_nat rv)::machine_word)) bits) sz bits n" apply (clarsimp simp: range_cover_def) proof (intro conjI) assume not_0 : "0<n" assume bound : "n \<le> unat ((2::machine_word) ^ sz - of_nat rv >> bits)" "rv\<le> 2^sz" "sz < word_bits" assume al: "is_aligned w sz" have space: "(2::machine_word) ^ sz - of_nat rv \<le> 2^ sz" apply (rule word_sub_le[OF word_of_nat_le]) apply (clarsimp simp: bound unat_power_lower_machine) done show cmp: "bits \<le> sz" using not_0 bound apply - apply (rule ccontr) apply (clarsimp simp: not_le) apply (drule le_trans) apply (rule word_le_nat_alt[THEN iffD1]) apply (rule le_shiftr[OF space]) apply (subgoal_tac "(2::machine_word)^sz >> bits = 0") apply simp apply (rule and_mask_eq_iff_shiftr_0[THEN iffD1]) apply (simp add: and_mask_eq_iff_le_mask) apply (case_tac "word_bits \<le> bits") apply (simp add: word_bits_def mask_def power_overflow) apply (subst le_mask_iff_lt_2n[THEN iffD1]) apply (simp add: word_bits_def) apply (simp add: word_less_nat_alt[THEN iffD2] unat_power_lower_machine) done have shiftr_t2n[simp]:"(2::machine_word)^sz >> bits = 2^ (sz - bits)" using bound cmp apply (case_tac "sz = 0",simp) apply (subgoal_tac "(1::machine_word) << sz >> bits = 2^ (sz -bits)") apply simp apply (subst shiftl_shiftr1) apply (simp add: word_size word_bits_def shiftl_t2n word_1_and_bl)+ done have cmp2[simp]: "alignUp (of_nat rv) bits < (2 :: machine_word) ^ sz" using bound cmp not_0 apply - apply (case_tac "rv = 0") apply simp apply (clarsimp simp: alignUp_def2) apply (subst mask_eq_x_eq_0[THEN iffD1]) apply (simp add: and_mask_eq_iff_le_mask mask_def) apply (simp add: p2_gt_0[where 'a=machine_word_len, folded word_bits_def]) apply (simp add: alignUp_def3) apply (subgoal_tac "1 \<le> unat (2 ^ sz - of_nat rv >> bits)") prefer 2 apply (erule le_trans[rotated]) apply clarsimp apply (thin_tac "n \<le> M" for M) apply (simp add: shiftr_div_2n') apply (simp add: td_gal[symmetric]) apply (subst (asm) unat_sub) apply (simp add: word_of_nat_le unat_power_lower_machine) apply (simp add: le_diff_conv2 word_of_nat_le unat_le_helper word_less_nat_alt) apply (rule le_less_trans[OF unat_plus_gt]) apply (rule less_le_trans[where y = "2^bits + unat (of_nat rv)"]) apply simp apply (rule le_less_trans[OF _ measure_unat]) apply (rule word_le_nat_alt[THEN iffD1]) apply (rule word_and_le2) apply (erule of_nat_neq_0) apply (subst word_bits_def[symmetric]) apply (erule le_less_trans) apply simp apply simp done show "n + unat (alignUp (w + ((of_nat rv)::machine_word)) bits && mask sz >> bits) \<le> 2 ^ (sz - bits)" using not_0 bound cmp apply - apply (erule le_trans[OF add_le_mono]) apply (rule le_refl) apply (clarsimp simp: power_sub field_simps td_gal[symmetric]) apply (subst (2) mult.commute) apply (subst unat_shiftl_absorb) apply (rule order_trans[OF le_shiftr]) apply (rule word_and_le1) apply (simp add: shiftr_mask2 word_bits_def) apply (simp add: mask_def) apply (rule word_sub_1_le) apply (simp add: word_bits_def)+ apply (simp add: shiftl_t2n[symmetric] field_simps shiftr_shiftl1) apply (subst is_aligned_neg_mask_eq) apply (rule is_aligned_andI1,simp) apply (subst mult.commute) apply (subst unat_shiftl_absorb[where p = "sz - bits"]) apply (rule order_trans[OF le_shiftr]) apply (rule space) apply (simp add: shiftr_div_2n_w word_bits_def)+ apply (simp add: shiftl_t2n[symmetric] field_simps shiftr_shiftl1) apply (subst is_aligned_diff_neg_mask[OF is_aligned_weaken]) apply (rule is_aligned_triv) apply (simp add: word_bits_def)+ apply (subst unat_sub) apply (rule order_trans[OF word_and_le2]) apply (simp add: less_imp_le) apply (subst diff_add_assoc[symmetric]) apply (rule unat_le_helper) apply (rule order_trans[OF word_and_le2]) apply (simp add: less_imp_le[OF cmp2]) apply (clarsimp simp: field_simps word_bits_def is_aligned_neg_mask_eq) apply (simp add: le_diff_conv word_le_nat_alt[symmetric] word_and_le2) apply (simp add: alignUp_plus[OF is_aligned_weaken[OF al]] is_aligned_add_helper[THEN conjunct1, OF al cmp2]) done show "rv \<le> unat (alignUp (w + of_nat rv) bits - w)" using bound not_0 cmp al apply - apply (clarsimp simp: alignUp_plus[OF is_aligned_weaken]) apply (case_tac "rv = 0") apply simp apply (rule le_trans[OF _ word_le_nat_alt[THEN iffD1,OF alignUp_ge]]) apply (subst unat_of_nat_machine) apply (erule le_less_trans) apply (rule power_strict_increasing) apply (simp_all add: word_bits_def)[4] apply (rule alignUp_is_aligned_nz[where x = "2^sz"]) apply (rule is_aligned_weaken[OF is_aligned_triv2]) apply (simp_all add: word_bits_def)[2] apply (subst word_of_nat_le) apply (subst unat_power_lower_machine) apply (simp add: word_bits_def)+ apply (erule of_nat_neq_0) apply (erule le_less_trans) apply (rule power_strict_increasing) apply (simp add: word_bits_def)+ done show "alignUp (w + of_nat rv) bits && ~~ mask sz = w" using bound not_0 cmp al apply (clarsimp simp: alignUp_plus[OF is_aligned_weaken] mask_out_add_aligned[symmetric]) apply (clarsimp simp: and_not_mask) apply (subgoal_tac "alignUp ((of_nat rv)::machine_word) bits >> sz = 0") apply simp apply (simp add: le_mask_iff[symmetric] mask_def) done qed (simp add: word_bits_def) context Arch begin (*FIXME: generify proof that uses this *) lemmas range_cover_stuff_arch = range_cover_stuff[unfolded word_bits_def, simplified] end lemma cte_wp_at_range_cover: "\<lbrakk>bits < word_bits; rv\<le> 2^ sz; invs s; cte_wp_at ((=) (cap.UntypedCap dev w sz idx)) p s; 0 < n; n \<le> unat ((2::machine_word) ^ sz - of_nat rv >> bits)\<rbrakk> \<Longrightarrow> range_cover (alignUp (w + of_nat rv) bits) sz bits n" apply (clarsimp simp: cte_wp_at_caps_of_state) apply (frule(1) caps_of_state_valid) apply (clarsimp simp: valid_cap_def valid_untyped_def cap_aligned_def) apply (drule range_cover_stuff) apply simp_all apply clarsimp done lemma le_mask_le_2p: "\<lbrakk>idx \<le> unat ((ptr::machine_word) && mask sz);sz < word_bits\<rbrakk> \<Longrightarrow> idx < 2^ sz" apply (erule le_less_trans) apply (rule unat_less_helper) apply simp apply (rule le_less_trans) apply (rule word_and_le1) apply (simp add: mask_def) done lemma diff_neg_mask[simp]: "ptr - (ptr && ~~ mask sz) = (ptr && mask sz)" apply (subst word_plus_and_or_coroll2[symmetric,where w = "mask sz" and t = ptr]) apply simp done lemma cte_wp_at_caps_descendants_range_inI: "\<lbrakk> invs s;cte_wp_at (\<lambda>c. c = cap.UntypedCap dev (ptr && ~~ mask sz) sz idx) cref s; idx \<le> unat (ptr && mask sz);sz < word_bits \<rbrakk> \<Longrightarrow> descendants_range_in {ptr .. (ptr && ~~mask sz) + 2^sz - 1} cref s" apply (frule invs_mdb) apply (frule(1) le_mask_le_2p) apply (clarsimp simp: descendants_range_in_def cte_wp_at_caps_of_state ) apply (frule(1) descendants_of_cte_at) apply (clarsimp simp: cte_wp_at_caps_of_state) apply (drule untyped_cap_descendants_range[rotated]) apply simp+ apply (simp add: invs_valid_pspace) apply (clarsimp simp: cte_wp_at_caps_of_state usable_untyped_range.simps) apply (erule disjoint_subset2[rotated]) apply clarsimp apply (rule le_plus'[OF word_and_le2]) apply simp apply (erule word_of_nat_le) done lemma nasty_range: fixes word :: "'a :: len word" assumes szb: "bz < len_of TYPE('a)" and al: "is_aligned word bz" and br: "ptr \<in> {word.. word+2^bz - 1}" and sr: "sz \<le> bz" shows "\<exists>idx::'a :: len word. idx < (2::'a :: len word)^(bz - sz) \<and> ptr \<in> {word + idx * 2^ sz .. word + (idx * 2^ sz) + (2^ sz - 1)}" proof - have offset: "ptr - word < 2^ bz" using br szb apply (subst word_less_sub_le[symmetric],simp) apply (rule word_diff_ls') apply (clarsimp simp: field_simps)+ done have t2n_sym: "\<And>z. (2::'a :: len word)^z = (1:: 'a :: len word)<<z" by (simp add: shiftl_t2n) have le_helper: "\<And>b c. \<lbrakk>\<And>a. (a::'a :: len word)< b \<Longrightarrow> a< c\<rbrakk> \<Longrightarrow> b\<le>c" apply (rule ccontr) apply (clarsimp simp: not_le dest!: meta_spec) by auto have ptr_word: "(ptr - word >> sz) * 2 ^ sz = (ptr &&~~ mask sz) - word" apply (subst mult.commute) apply (clarsimp simp: shiftl_t2n[symmetric] shiftr_shiftl1 word_and_le2) apply (simp only: diff_conv_add_uminus) apply (subst add.commute[where a = "ptr && ~~ mask sz"]) apply (subst mask_out_add_aligned) defer apply (simp add: field_simps) apply (rule is_aligned_minus) apply (rule is_aligned_weaken[OF al sr]) done show ?thesis using szb sr br apply clarsimp apply (rule_tac x = "(ptr - word) >> sz" in exI) apply (intro conjI) apply (rule less_le_trans) apply (rule shiftr_less_t2n[where m = "bz - sz"]) apply (simp add: offset) apply simp apply (rule le_plus) apply (subst mult.commute) apply (simp add: shiftl_t2n[symmetric] shiftr_shiftl1 word_and_le2) apply clarsimp apply (simp add: ptr_word p_assoc_help) apply (rule order_trans[OF _ word_plus_mono_right]) apply (rule order_eq_refl) apply (subst word_plus_and_or_coroll2[where x = "ptr",symmetric]) apply (subst add.commute) apply simp apply (rule order_trans[OF word_and_le1]) apply (clarsimp simp: mask_def) apply (rule is_aligned_no_overflow'[OF is_aligned_neg_mask]) apply simp+ done qed lemma check_children_wp: "\<lbrace>\<lambda>s. if descendants_of slot (cdt s) = {} then Q True s else Q False s \<rbrace> const_on_failure False (doE y \<leftarrow> ensure_no_children slot; returnOk True odE) \<lbrace>Q\<rbrace>" including no_pre apply (clarsimp simp: const_on_failure_def ensure_no_children_descendants bindE_assoc) apply wp apply (clarsimp simp: valid_def validE_def if_splits) apply (intro conjI impI) apply (clarsimp simp: in_monad free_index_of_def)+ done lemma alignUp_eq: "\<lbrakk>is_aligned (w :: 'a :: len word) sz; a \<le> 2^ sz; us \<le> sz; sz < len_of TYPE('a); alignUp (w + a) us = w\<rbrakk> \<Longrightarrow> a = 0" apply (clarsimp simp: alignUp_plus[OF is_aligned_weaken]) apply (rule ccontr) apply (drule alignUp_is_aligned_nz[rotated -1,where x = "2^ sz"]) apply (rule is_aligned_weaken[OF is_aligned_triv2]) apply simp+ done lemma map_ensure_empty_wp: "\<lbrace> \<lambda>s. (\<forall>x\<in>set xs. cte_wp_at ((=) NullCap) x s) \<longrightarrow> P () s \<rbrace> mapME_x ensure_empty xs \<lbrace>P\<rbrace>, -" by (rule hoare_post_imp_R, rule map_ensure_empty, simp) lemma cases_imp_eq: "((P \<longrightarrow> Q \<longrightarrow> R) \<and> (\<not> P \<longrightarrow> Q \<longrightarrow> S)) = (Q \<longrightarrow> (P \<longrightarrow> R) \<and> (\<not> P \<longrightarrow> S))" by blast lemma inj_bits: "\<lbrakk> of_nat x * 2^bits = of_nat y * (2^bits :: machine_word); x < bnd; y < bnd; bits \<le> word_bits; bnd \<le> 2 ^ (word_bits - bits) \<rbrakk> \<Longrightarrow> of_nat x = (of_nat y :: machine_word)" apply (cases "bits = 0", simp) apply (fold shiftl_t2n [where n=bits, simplified, simplified mult.commute]) apply (simp only: word_bl.Rep_inject[symmetric] bl_shiftl) apply (drule(1) order_less_le_trans)+ apply (drule of_nat_mono_maybe[rotated, where 'a=machine_word_len]) apply (rule power_strict_increasing) apply (simp add: word_bits_def) apply simp apply (drule of_nat_mono_maybe[rotated, where 'a=machine_word_len]) apply (rule power_strict_increasing) apply (simp add: word_bits_def) apply simp apply (simp only: word_unat_power[symmetric]) apply (erule ssubst [OF less_is_drop_replicate])+ apply (simp add: word_bits_def word_size) done lemma of_nat_shiftR: "a < 2 ^ word_bits \<Longrightarrow> unat (of_nat (shiftR a b)::machine_word) = unat ((of_nat a :: machine_word) >> b)" apply (subst shiftr_div_2n') apply (clarsimp simp: shiftR_nat) apply (subst unat_of_nat_eq[where 'a=machine_word_len]) apply (simp only: word_bits_def) apply (erule le_less_trans[OF div_le_dividend]) apply (subst unat_of_nat_eq[where 'a=machine_word_len]) apply (simp only: word_bits_def) apply simp done lemma valid_untypedD: "\<lbrakk> s \<turnstile> cap.UntypedCap dev ptr bits idx; kheap s p = Some ko; pspace_aligned s\<rbrakk> \<Longrightarrow> obj_range p ko \<inter> cap_range (cap.UntypedCap dev ptr bits idx) \<noteq> {} \<longrightarrow> (obj_range p ko \<subseteq> cap_range (cap.UntypedCap dev ptr bits idx) \<and> obj_range p ko \<inter> usable_untyped_range (cap.UntypedCap dev ptr bits idx) = {})" by (clarsimp simp: valid_untyped_def valid_cap_def cap_range_def obj_range_def) lemma pspace_no_overlap_detype': "\<lbrakk> s \<turnstile> cap.UntypedCap dev ptr bits idx; pspace_aligned s; valid_objs s \<rbrakk> \<Longrightarrow> pspace_no_overlap {ptr .. ptr + 2 ^ bits - 1} (detype {ptr .. ptr + 2 ^ bits - 1} s)" apply (clarsimp simp del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff simp: obj_range_def add_diff_eq[symmetric] pspace_no_overlap_def) apply (frule(2) valid_untypedD) apply (rule ccontr) apply (clarsimp simp del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff is_aligned_neg_mask_eq simp: valid_cap_def cap_aligned_def obj_range_def cap_range_def is_aligned_neg_mask_eq p_assoc_help) apply (drule_tac c= x in set_mp) apply simp+ done lemma pspace_no_overlap_detype: "\<lbrakk> s \<turnstile> cap.UntypedCap dev ptr bits idx; pspace_aligned s; valid_objs s \<rbrakk> \<Longrightarrow> pspace_no_overlap_range_cover ptr bits (detype {ptr .. ptr + 2 ^ bits - 1} s)" apply (drule(2) pspace_no_overlap_detype'[rotated]) apply (drule valid_cap_aligned) apply (clarsimp simp: cap_aligned_def is_aligned_neg_mask_eq field_simps) done lemma zip_take_length[simp]: "zip (take (length ys) xs) ys = zip xs ys" apply (induct xs arbitrary: ys) apply simp apply (case_tac ys) apply simp apply simp done (* FIXME: move *) lemma int_not_empty_subsetD: "\<lbrakk> A\<inter> B = {}; A\<noteq> {};B\<noteq> {}\<rbrakk> \<Longrightarrow> \<not> A \<subset> B \<and> \<not> B\<subset> A \<and> \<not> A = B" by auto (* FIXME: move *) lemma subset_not_psubset: " A \<subseteq> B \<Longrightarrow> \<not> B \<subset> A" by clarsimp lemma mdb_Null_descendants: "\<lbrakk> cte_wp_at ((=) cap.NullCap) p s; valid_mdb s \<rbrakk> \<Longrightarrow> descendants_of p (cdt s) = {}" apply (clarsimp simp add: valid_mdb_def cte_wp_at_caps_of_state swp_def) apply (erule(1) mdb_cte_at_Null_descendants) done lemma mdb_Null_None: "\<lbrakk> cte_wp_at ((=) cap.NullCap) p s; valid_mdb s \<rbrakk> \<Longrightarrow> cdt s p = None" apply (clarsimp simp add: valid_mdb_def cte_wp_at_caps_of_state swp_def) apply (erule(1) mdb_cte_at_Null_None) done lemma not_waiting_reply_slot_no_descendants: "\<lbrakk> st_tcb_at (Not \<circ> awaiting_reply) t s; valid_reply_caps s; valid_objs s; valid_mdb s \<rbrakk> \<Longrightarrow> descendants_of (t, tcb_cnode_index 2) (cdt s) = {}" apply (rule ccontr, erule nonemptyE) apply (clarsimp simp: valid_mdb_def reply_mdb_def reply_masters_mdb_def) apply (frule_tac ref="tcb_cnode_index 2" in tcb_at_cte_at[OF st_tcb_at_tcb_at]) apply (simp add: domI) apply (clarsimp simp: cte_wp_at_caps_of_state) apply (frule(1) tcb_cap_valid_caps_of_stateD) apply (clarsimp simp: tcb_cap_valid_def st_tcb_at_tcb_at) apply (clarsimp simp: st_tcb_def2) apply (erule disjE) apply (clarsimp simp: cte_wp_at_caps_of_state is_cap_simps) apply (elim allE impE) apply fastforce apply (clarsimp) apply (drule(1) bspec) apply (subgoal_tac "has_reply_cap t s") apply (erule notE[rotated], strengthen reply_cap_doesnt_exist_strg) apply (simp add: st_tcb_def2) apply (erule exE) apply (drule caps_of_state_cteD)+ apply (fastforce simp add:has_reply_cap_def is_reply_cap_to_def elim:cte_wp_at_lift intro: caps_of_state_cteD) apply clarsimp apply (frule mdb_Null_descendants[OF caps_of_state_cteD]) apply (simp add: valid_mdb_def reply_mdb_def reply_masters_mdb_def) apply simp done crunch irq_node[wp]: set_thread_state "\<lambda>s. P (interrupt_irq_node s)" crunch irq_states[wp]: update_cdt "\<lambda>s. P (interrupt_states s)" crunch ups[wp]: set_cdt "\<lambda>s. P (ups_of_heap (kheap s))" crunch cns[wp]: set_cdt "\<lambda>s. P (cns_of_heap (kheap s))" (* FIXME: move *) lemma list_all2_zip_split: "\<lbrakk> list_all2 P as cs; list_all2 Q bs ds \<rbrakk> \<Longrightarrow> list_all2 (\<lambda>x y. P (fst x) (fst y) \<and> Q (snd x) (snd y)) (zip as bs) (zip cs ds)" apply (induct as arbitrary: bs cs ds) apply simp apply (case_tac cs; simp) apply (case_tac bs; simp) apply (case_tac ds; simp) done crunch irq_states[wp]: update_cdt "\<lambda>s. P (interrupt_states s)" crunch ups[wp]: set_cdt "\<lambda>s. P (ups_of_heap (kheap s))" crunch cns[wp]: set_cdt "\<lambda>s. P (cns_of_heap (kheap s))" lemma set_cdt_tcb_valid[wp]: "\<lbrace>tcb_cap_valid cap ptr\<rbrace> set_cdt m \<lbrace>\<lambda>rv. tcb_cap_valid cap ptr\<rbrace>" by (simp add: set_cdt_def, wp, simp add: tcb_cap_valid_def) lemma tcb_cap_valid_rvk[simp]: "tcb_cap_valid cap ptr (is_original_cap_update f s) = tcb_cap_valid cap ptr s" by (simp add: tcb_cap_valid_def) lemma tcb_cap_valid_more_update[simp]: "tcb_cap_valid cap ptr (trans_state f s) = tcb_cap_valid cap ptr s" by (simp add: tcb_cap_valid_def) lemma create_cap_wps[wp]: "\<lbrace>pspace_aligned\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. pspace_aligned\<rbrace>" "\<lbrace>pspace_distinct\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. pspace_distinct\<rbrace>" "\<lbrace>cte_wp_at P p' and K (p' \<noteq> cref)\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. cte_wp_at P p'\<rbrace>" "\<lbrace>valid_objs and valid_cap (default_cap tp oref sz dev) and real_cte_at cref\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_objs\<rbrace>" "\<lbrace>valid_cap cap\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_cap cap\<rbrace>" apply (safe intro!: hoare_gen_asm) apply (simp_all add: create_cap_def) apply (wp set_cap_cte_wp_at' set_cdt_cte_wp_at set_cap_valid_objs set_cdt_valid_objs set_cdt_valid_cap set_cap_valid_cap | simp split del: if_split add: real_cte_tcb_valid)+ done lemma default_non_Null[simp]: "cap.NullCap \<noteq> default_cap tp oref sz dev" by (cases tp, simp_all) locale vo_abs = vmdb_abs + assumes valid_objs: "valid_objs s" begin lemma cs_valid_cap: "cs p = Some c \<Longrightarrow> s \<turnstile> c" using valid_objs apply (simp add: cs_def) apply (drule cte_wp_at_valid_objs_valid_cap [rotated, where P="(=) c"]) apply (simp add: cte_wp_at_caps_of_state) apply clarsimp done lemma cs_cap_aligned: "cs p = Some c \<Longrightarrow> cap_aligned c" apply (drule cs_valid_cap) apply (simp add: valid_cap_def) done end lemma untyped_ranges_aligned_disjoing_or_subset: "\<lbrakk>cap_aligned c1;cap_aligned c2\<rbrakk> \<Longrightarrow> untyped_range c1 \<subseteq> untyped_range c2 \<or> untyped_range c2 \<subseteq> untyped_range c1 \<or> untyped_range c1 \<inter> untyped_range c2 = {}" apply (simp add: cap_aligned_def) apply (elim conjE) apply (drule(1) aligned_ranges_subset_or_disjoint) apply (case_tac c1) apply simp_all apply (case_tac c2) apply simp_all done locale mdb_create_cap = vo_abs + mdb_insert_abs + fixes cap assumes c_dest: "cs dest = Some cap.NullCap" assumes c_src: "cs src = Some cap" assumes ut: "is_untyped_cap cap" begin lemmas no_dest_mdb [simp] = null_no_mdb [OF c_dest] lemma d_rangeD: "\<lbrakk>descendants_range ac p s; m \<Turnstile> p \<rightarrow> p'\<rbrakk> \<Longrightarrow> \<exists>c. cs p' = Some c \<and> untyped_range c \<inter> untyped_range ac = {}" apply (drule(1) descendants_rangeD[where s= s,folded m_def cs_def]) apply clarsimp apply (drule disjoint_subset2[OF untyped_range_in_cap_range]) apply (drule disjoint_subset[OF untyped_range_in_cap_range]) apply simp done lemma subseteq_imp_not_subset: "A \<subseteq> B \<Longrightarrow> \<not> B \<subset> A" by fastforce lemma cap_bits_default_untyped_cap: "is_untyped_cap (default_cap tp oref sz dev) \<Longrightarrow> cap_bits (default_cap tp oref sz dev) = sz" by (case_tac tp,simp_all) lemma untyped_inc': assumes inc: "untyped_inc m cs" assumes d: "descendants_range (default_cap tp oref sz dev) src s" assumes r: "untyped_range (default_cap tp oref sz dev) \<subseteq> untyped_range cap" assumes al: "cap_aligned (default_cap tp oref sz dev)" assumes noint: "untyped_range (default_cap tp oref sz dev) \<inter> usable_untyped_range cap = {}" shows "untyped_inc (m(dest \<mapsto> src)) (cs(dest \<mapsto> default_cap tp oref sz dev))" using inc r c_src al ut noint unfolding untyped_inc_def descendants_of_def apply (intro allI impI) apply (rule conjI) apply (simp add: parency del: split_paired_All split: if_split_asm) apply (rule untyped_ranges_aligned_disjoing_or_subset[OF _ cs_cap_aligned]) apply simp apply simp apply (rule untyped_ranges_aligned_disjoing_or_subset[OF cs_cap_aligned _ ]) apply simp apply simp apply (case_tac "p' = src") apply (simp add: parency del: split_paired_All split: if_split_asm) apply (erule_tac x=src in allE) apply (erule_tac x=p in allE) apply (simp add: c_dest) apply (simp add: subseteq_imp_not_subset) apply (intro impI) apply (drule(1) usable_range_subseteq[OF cs_cap_aligned]) apply simp apply (drule Int_absorb1) apply simp apply (simp add: c_dest) apply (erule_tac x = src in allE) apply (erule_tac x = p in allE) apply simp apply (elim conjE) apply (rule conjI) apply (intro impI) apply (elim disjE) apply (clarsimp+)[3] apply (erule subset_splitE) apply clarsimp apply (intro conjI impI) apply simp+ apply (intro conjI impI,clarsimp+)[1] apply (intro conjI impI,clarsimp+)[1] apply (simp add: parency del: split_paired_All split: if_split_asm) apply (erule_tac x=src in allE) apply (erule_tac x=p' in allE) apply simp apply (elim conjE) apply (erule subset_splitE) apply (intro conjI) apply (intro impI) apply blast apply blast apply (intro conjI) apply (intro impI) apply (drule trancl_trans) apply fastforce apply simp apply (intro impI) apply (cut_tac p' = p' in d_rangeD[OF d]) apply simp+ apply (drule(1) untyped_range_non_empty[OF _ cs_cap_aligned]) apply (drule(1) untyped_range_non_empty) apply (rule int_not_empty_subsetD) apply (simp add:Int_ac) apply simp apply simp apply simp apply (intro conjI) apply (intro impI) apply (erule disjE) apply (drule trancl_trans) apply fastforce apply simp apply (simp add: subseteq_imp_not_subset) apply (drule(1) untyped_range_non_empty[OF _ cs_cap_aligned]) apply (drule(1) untyped_range_non_empty) apply (elim disjE) apply (cut_tac p' = p' in d_rangeD[OF d]) apply clarsimp apply simp apply fastforce apply clarsimp apply (drule(1) untyped_range_non_empty[OF _ cs_cap_aligned]) apply (drule(1) untyped_range_non_empty) apply (thin_tac "P \<longrightarrow> Q" for P Q)+ apply blast apply (erule_tac x = src in allE) apply (erule_tac x = p in allE) apply simp apply (elim conjE) apply (erule subset_splitE) apply simp apply (thin_tac "P \<longrightarrow> Q" for P Q)+ apply blast apply (intro conjI) apply (intro impI) apply (drule trancl_trans) apply fastforce apply simp apply clarsimp apply simp apply (elim conjE) apply (thin_tac "P \<longrightarrow> Q" for P Q)+ apply (thin_tac "P \<inter> Q = {}" for P Q)+ apply (intro impI) apply (drule d_rangeD[OF d]) apply simp apply (drule(1) untyped_range_non_empty[OF _ cs_cap_aligned])+ apply (drule(1) untyped_range_non_empty)+ apply (intro conjI) apply (rule notI) apply (drule(1) disjoint_subset2[OF psubset_imp_subset,rotated]) apply simp apply (rule notI) apply (drule(1) disjoint_subset[OF psubset_imp_subset,rotated]) apply simp apply blast apply simp apply (intro conjI) apply (intro impI) apply (erule disjE) apply (drule trancl_trans) apply fastforce apply simp apply fastforce apply (clarsimp simp: subseteq_imp_not_subset) apply (drule(1) usable_range_subseteq[OF cs_cap_aligned] ) apply blast apply (rule impI) apply simp apply (drule(1) untyped_range_non_empty[OF _ cs_cap_aligned])+ apply (drule(1) untyped_range_non_empty)+ apply (elim conjE | simp)+ apply (drule d_rangeD[OF d]) apply simp apply (intro conjI) apply (rule notI) apply (drule(1) disjoint_subset2[OF psubset_imp_subset,rotated]) apply simp apply (rule notI) apply (drule(1) disjoint_subset[OF psubset_imp_subset,rotated]) apply simp apply blast apply (thin_tac "P \<longrightarrow> Q" for P Q)+ apply (drule disjoint_subset2) apply (simp (no_asm) add:Int_ac) apply (drule(1) untyped_range_non_empty[OF _ cs_cap_aligned])+ apply (drule(1) untyped_range_non_empty)+ apply blast apply (erule_tac x= src in allE) apply (erule_tac x = p' in allE) apply simp apply (intro impI conjI) apply simp+ done end lemma default_cap_replies[simp]: "\<not> is_reply_cap (default_cap otype oref sz dev)" "\<not> is_master_reply_cap (default_cap otype oref sz dev)" by (cases otype, simp_all add: is_cap_simps)+ lemma inter_non_emptyD: "\<lbrakk>A \<subseteq> B; A \<inter> C \<noteq> {}\<rbrakk> \<Longrightarrow> B \<inter> C \<noteq> {}" by blast lemma cap_class_default_cap: "cap_class (default_cap tp oref sz dev) = PhysicalClass" apply (case_tac tp) apply (simp_all add: default_cap_def physical_arch_cap_has_ref aobj_ref_default) done lemma untyped_incD2: "\<lbrakk>cs p = Some c; is_untyped_cap c; cs p' = Some c'; is_untyped_cap c'; untyped_inc m cs\<rbrakk> \<Longrightarrow> untyped_range c \<inter> untyped_range c' \<noteq> {} \<longrightarrow> p \<in> descendants_of p' m \<and> untyped_range c \<subseteq> untyped_range c' \<or> p' \<in> descendants_of p m \<and> untyped_range c'\<subseteq> untyped_range c \<or> p = p'" apply (drule(4) untyped_incD) apply (rule ccontr) apply (elim conjE subset_splitE) apply clarsimp+ done lemma create_cap_mdb[wp]: "\<lbrace>valid_mdb and valid_objs and cte_wp_at (\<lambda>c. is_untyped_cap c \<and> obj_refs (default_cap tp oref sz dev) \<subseteq> untyped_range c \<and> untyped_range (default_cap tp oref sz dev) \<subseteq> untyped_range c \<and> untyped_range (default_cap tp oref sz dev) \<inter> usable_untyped_range c = {}) p and descendants_range (default_cap tp oref sz dev) p and cte_wp_at ((=) cap.NullCap) cref and K (cap_aligned (default_cap tp oref sz dev))\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_mdb\<rbrace>" apply (simp add: valid_mdb_def2 create_cap_def set_cdt_def) apply (wp set_cap_caps_of_state2 | simp)+ apply clarsimp apply (subgoal_tac "mdb_insert_abs (cdt s) p cref") prefer 2 apply (rule mdb_insert_abs.intro) apply (clarsimp simp: cte_wp_at_def) apply (clarsimp simp: valid_mdb_def2 elim!: mdb_Null_None mdb_Null_descendants)+ apply (clarsimp simp: cte_wp_at_caps_of_state) apply (fold fun_upd_def) apply (intro conjI) apply (rule mdb_cte_atI) apply (simp add: is_cap_simps split: if_split_asm) apply (drule(1) mdb_cte_atD,clarsimp)+ apply (simp add: untyped_mdb_def descendants_of_def mdb_insert_abs.parency del: split_paired_All) apply (intro allI conjI impI) apply (clarsimp simp: is_cap_simps) apply (clarsimp simp: is_cap_simps) apply (erule_tac x=p in allE) apply (erule_tac x=ptr' in allE) apply (simp del: split_paired_All) apply (erule impE, blast) apply (erule (1) trancl_trans) apply (simp del: split_paired_All) apply (erule_tac x=p in allE) apply (erule_tac x=ptr' in allE) apply (simp del: split_paired_All) apply (erule impE, blast) apply (drule(1) descendants_rangeD) apply (simp del: split_paired_All add: cap_range_def) apply blast apply (drule_tac x=ptr in spec) apply (drule_tac x=cref in spec) apply (simp del: split_paired_All) apply (frule(1) inter_non_emptyD[rotated]) apply (drule_tac c = cap and c' = capa in untyped_incD2) apply simp+ apply (clarsimp simp add: descendants_of_def simp del: split_paired_All) apply (drule(1) descendants_rangeD) apply (clarsimp simp del: split_paired_All simp: cap_range_def) apply blast apply (erule(1) mdb_insert_abs.descendants_inc) apply simp apply (clarsimp simp: is_cap_simps cap_range_def cap_class_default_cap) apply (clarsimp simp: no_mloop_def) apply (frule_tac p = "(a,b)" and p'="(a,b)" in mdb_insert_abs.parency) apply (simp split: if_split_asm) apply (erule disjE) apply (drule_tac m = "cdt s" in mdb_cte_at_Null_descendants) apply (clarsimp simp: untyped_mdb_def) apply (clarsimp simp: descendants_of_def simp del: split_paired_All) apply clarsimp apply (rule mdb_create_cap.untyped_inc') apply (rule mdb_create_cap.intro) apply (rule vo_abs.intro) apply (rule vmdb_abs.intro) apply (simp add: valid_mdb_def swp_def cte_wp_at_caps_of_state) apply (erule vo_abs_axioms.intro) apply assumption apply (erule (2) mdb_create_cap_axioms.intro) apply assumption+ apply (simp add: ut_revocable_def del: split_paired_All) apply (simp add: irq_revocable_def del: split_paired_All) apply (simp add: reply_master_revocable_def del: split_paired_All) apply (simp add: reply_mdb_def) apply (subgoal_tac "\<And>t m R. default_cap tp oref sz dev \<noteq> cap.ReplyCap t m R") apply (rule conjI) apply (fastforce simp: reply_caps_mdb_def descendants_of_def mdb_insert_abs.parency simp del: split_paired_All split_paired_Ex elim!: allEI exEI) apply (fastforce simp: reply_masters_mdb_def descendants_of_def mdb_insert_abs.parency simp del: split_paired_All split_paired_Ex elim!: allEI) apply (cases tp, simp_all)[1] apply (erule valid_arch_mdb_untypeds) done lemma create_cap_descendants_range[wp]: "\<lbrace>descendants_range c p and K (cap_range c \<inter> cap_range (default_cap tp oref sz dev) = {}) and cte_wp_at ((\<noteq>) cap.NullCap) p and cte_wp_at ((=) cap.NullCap) cref and valid_mdb\<rbrace> create_cap tp sz p dev (cref,oref) \<lbrace>\<lambda>rv. descendants_range c p\<rbrace>" apply (simp add: create_cap_def descendants_range_def cte_wp_at_caps_of_state set_cdt_def) apply (wp set_cap_caps_of_state2 | simp del: fun_upd_apply)+ apply (clarsimp simp: cte_wp_at_caps_of_state swp_def valid_mdb_def simp del: fun_upd_apply) apply (subst (asm) mdb_insert_abs.descendants_child) apply (rule mdb_insert_abs.intro) apply clarsimp apply (erule (1) mdb_cte_at_Null_None) apply (erule (1) mdb_cte_at_Null_descendants) apply clarsimp apply (rule conjI, clarsimp) apply blast apply clarsimp done (* FIXME: Move to top *) lemma caps_overlap_reservedD: "\<lbrakk>caps_overlap_reserved S s; caps_of_state s slot = Some cap; is_untyped_cap cap\<rbrakk> \<Longrightarrow> usable_untyped_range cap \<inter> S = {}" apply (simp add: caps_overlap_reserved_def) apply (erule ballE) apply (erule(1) impE) apply simp apply fastforce done lemma cap_range_inter_emptyD: "cap_range a \<inter> cap_range b = {} \<Longrightarrow> untyped_range a \<inter> untyped_range b = {}" apply (drule disjoint_subset2[OF untyped_range_in_cap_range]) apply (drule disjoint_subset[OF untyped_range_in_cap_range]) apply simp done lemma create_cap_overlap_reserved [wp]: "\<lbrace>caps_overlap_reserved (untyped_range c) and K (cap_range c \<inter> cap_range (default_cap tp oref sz dev) = {}) and cte_wp_at ((\<noteq>) cap.NullCap) p and cte_wp_at ((=) cap.NullCap) cref and valid_mdb and K (cap_aligned (default_cap tp oref sz dev))\<rbrace> create_cap tp sz p dev (cref,oref) \<lbrace>\<lambda>rv s. caps_overlap_reserved (untyped_range c) s\<rbrace>" apply (simp add: create_cap_def caps_overlap_reserved_def cte_wp_at_caps_of_state set_cdt_def) apply (wp set_cap_caps_of_state2 | simp del: fun_upd_apply)+ apply (clarsimp simp: ran_def split: if_splits) apply (case_tac "cref = (a,b)") apply simp apply (erule(1) disjoint_subset[OF usable_range_subseteq]) apply (simp add:Int_ac cap_range_inter_emptyD) apply simp apply (erule(2) caps_overlap_reservedD) done crunch typ_at[wp]: create_cap "\<lambda>s. P (typ_at T p s)" (simp: crunch_simps) lemmas create_cap_cap_table_at[wp] = cap_table_at_lift_valid [OF create_cap_typ_at] lemma retype_region_invs_extras: "\<lbrace>invs and pspace_no_overlap_range_cover ptr sz and caps_no_overlap ptr sz and caps_overlap_reserved {ptr..ptr + of_nat n * 2 ^ obj_bits_api ty us - 1} and region_in_kernel_window {ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1} and (\<lambda>s. \<exists>slot. cte_wp_at (\<lambda>c. {ptr..(ptr && ~~ mask sz) + (2 ^ sz - 1)} \<subseteq> cap_range c \<and> cap_is_device c = dev) slot s) and K (ty = CapTableObject \<longrightarrow> 0 < us) and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev\<lbrace>\<lambda>rv. pspace_aligned\<rbrace>" "\<lbrace>invs and pspace_no_overlap_range_cover ptr sz and caps_no_overlap ptr sz and caps_overlap_reserved {ptr..ptr + of_nat n * 2 ^ obj_bits_api ty us - 1} and region_in_kernel_window {ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1} and (\<lambda>s. \<exists>slot. cte_wp_at (\<lambda>c. {ptr..(ptr && ~~ mask sz) + (2 ^ sz - 1)} \<subseteq> cap_range c \<and> cap_is_device c = dev) slot s) and K (ty = CapTableObject \<longrightarrow> 0 < us) and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev\<lbrace>\<lambda>rv. valid_objs\<rbrace>" "\<lbrace>invs and pspace_no_overlap_range_cover ptr sz and caps_no_overlap ptr sz and caps_overlap_reserved {ptr..ptr + of_nat n * 2 ^ obj_bits_api ty us - 1} and region_in_kernel_window {ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1} and (\<lambda>s. \<exists>slot. cte_wp_at (\<lambda>c. {ptr..(ptr && ~~ mask sz) + (2 ^ sz - 1)} \<subseteq> cap_range c \<and> cap_is_device c = dev) slot s) and K (ty = CapTableObject \<longrightarrow> 0 < us) and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev \<lbrace>\<lambda>rv. pspace_distinct\<rbrace>" "\<lbrace>invs and pspace_no_overlap_range_cover ptr sz and caps_no_overlap ptr sz and caps_overlap_reserved {ptr..ptr + of_nat n * 2 ^ obj_bits_api ty us - 1} and region_in_kernel_window {ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1} and (\<lambda>s. \<exists>slot. cte_wp_at (\<lambda>c. {ptr..(ptr && ~~ mask sz) + (2 ^ sz - 1)} \<subseteq> cap_range c \<and> cap_is_device c = dev) slot s) and K (ty = CapTableObject \<longrightarrow> 0 < us) and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev \<lbrace>\<lambda>rv. valid_mdb\<rbrace>" "\<lbrace>invs and pspace_no_overlap_range_cover ptr sz and caps_no_overlap ptr sz and caps_overlap_reserved {ptr..ptr + of_nat n * 2 ^ obj_bits_api ty us - 1} and region_in_kernel_window {ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1} and (\<lambda>s. \<exists>slot. cte_wp_at (\<lambda>c. {ptr..(ptr && ~~ mask sz) + (2 ^ sz - 1)} \<subseteq> cap_range c \<and> cap_is_device c = dev) slot s) and K (ty = CapTableObject \<longrightarrow> 0 < us) and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev\<lbrace>\<lambda>rv. valid_global_objs\<rbrace>" "\<lbrace>invs and pspace_no_overlap_range_cover ptr sz and caps_no_overlap ptr sz and caps_overlap_reserved {ptr..ptr + of_nat n * 2 ^ obj_bits_api ty us - 1} and region_in_kernel_window {ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1} and (\<lambda>s. \<exists>slot. cte_wp_at (\<lambda>c. {ptr..(ptr && ~~ mask sz) + (2 ^ sz - 1)} \<subseteq> cap_range c \<and> cap_is_device c = dev) slot s) and K (ty = CapTableObject \<longrightarrow> 0 < us) and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev \<lbrace>\<lambda>rv. valid_arch_state\<rbrace>" apply (wp hoare_strengthen_post [OF retype_region_post_retype_invs], auto simp: post_retype_invs_def split: if_split_asm)+ done lemma set_tuple_pick: "\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>x \<in> set (xs rv s). Q x rv s\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>tup \<in> set (zip (xs rv s) (ys rv s)). Q (fst tup) rv s\<rbrace>" "\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>y \<in> set (ys rv s). R y rv s\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. \<forall>tup \<in> set (zip (xs rv s) (ys rv s)). R (snd tup) rv s\<rbrace>" apply (safe elim!: hoare_strengthen_post) apply (clarsimp simp: set_zip)+ done lemma obj_at_foldr_intro: "P obj \<and> p \<in> set xs \<Longrightarrow> obj_at P p (s \<lparr> kheap := foldr (\<lambda>p ps. ps (p \<mapsto> obj)) xs (kheap s) \<rparr>)" by (clarsimp simp: obj_at_def foldr_upd_app_if) context Untyped_AI_arch begin lemma retype_ret_valid_caps: "\<lbrace>pspace_no_overlap_range_cover ptr sz and K (tp = Structures_A.CapTableObject \<longrightarrow> us > 0) and K (tp = Untyped \<longrightarrow> untyped_min_bits \<le> us) and K (tp \<noteq> ArchObject ASIDPoolObj) and K (range_cover ptr sz (obj_bits_api tp us) n \<and> ptr \<noteq> 0)\<rbrace> retype_region ptr n us tp dev\<lbrace>\<lambda>rv (s::'state_ext state). \<forall>y\<in>set rv. s \<turnstile> default_cap tp y us dev\<rbrace>" apply (simp add: retype_region_def split del: if_split cong: if_cong) apply wp apply (simp only: trans_state_update[symmetric] more_update.valid_cap_update) apply wp apply (case_tac tp,simp_all) defer apply ((clarsimp simp:valid_cap_def default_object_def cap_aligned_def is_obj_defs well_formed_cnode_n_def empty_cnode_def dom_def ptr_add_def | rule conjI | intro conjI obj_at_foldr_intro imageI | rule is_aligned_add_multI[OF _ le_refl], (simp add:range_cover_def word_bits_def obj_bits_api_def)+)+)[3] apply (rule_tac ptr=ptr and sz=sz in retype_ret_valid_caps_captable; simp) apply (rule_tac ptr=ptr and sz=sz in retype_ret_valid_caps_aobj; simp) apply (clarsimp simp:valid_cap_def default_object_def cap_aligned_def is_obj_defs well_formed_cnode_n_def empty_cnode_def dom_def ptr_add_def | intro conjI obj_at_foldr_intro imageI | rule is_aligned_add_multI[OF _ le_refl] | fastforce simp:range_cover_def obj_bits_api_def word_bits_def a_type_def)+ apply (clarsimp simp:valid_cap_def valid_untyped_def) apply (drule(1) pspace_no_overlap_obj_range) apply (frule range_cover_cell_subset) apply (erule of_nat_mono_maybe[rotated]) apply (drule range_cover.range_cover_n_less) apply (simp add:word_bits_def) apply (simp add:obj_bits_api_def field_simps del:atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff) apply blast apply (erule(2) range_cover_no_0) done end (* FIXME: move to Lib *) lemma set_zip_helper: "t \<in> set (zip xs ys) \<Longrightarrow> fst t \<in> set xs \<and> snd t \<in> set ys" by (clarsimp simp add: set_zip) lemma ex_cte_cap_protects: "\<lbrakk> ex_cte_cap_wp_to P p s; cte_wp_at ((=) (cap.UntypedCap dev ptr bits idx)) p' s; descendants_range_in S p' s; untyped_children_in_mdb s; S\<subseteq> untyped_range (cap.UntypedCap dev ptr bits idx); valid_global_refs s \<rbrakk> \<Longrightarrow> fst p \<notin> S" apply (drule ex_cte_cap_to_obj_ref_disj, erule disjE) apply clarsimp apply (erule(1) untyped_children_in_mdbEE[where P="\<lambda>c. fst p \<in> obj_refs c" for c]) apply simp apply assumption apply (rule notemptyI[where x="fst p"]) apply (clarsimp simp del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff split_paired_Ex) apply blast apply (clarsimp simp:cte_wp_at_caps_of_state) apply (drule(2) descendants_range_inD) apply (clarsimp simp:cap_range_def) apply blast apply clarsimp apply (drule_tac irq=irq in valid_globals_irq_node, assumption) apply (clarsimp simp del:atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff split_paired_Ex) apply blast done lemma untyped_range_default_empty: "tp \<noteq> Untyped \<Longrightarrow> untyped_range (default_cap tp sz us dev) = {}" by (cases tp, auto) lemma obj_refs_default_cap: "obj_refs (default_cap tp oref sz dev) \<subseteq> {oref}" apply (cases tp, simp_all add: aobj_ref_default) done lemma obj_refs_default_nut: "tp \<noteq> Untyped \<Longrightarrow> obj_refs (default_cap tp oref sz dev) = {oref}" apply (cases tp, simp_all add: aobj_ref_default) done lemma range_cover_subset': "\<lbrakk>range_cover ptr sz sbit n; n \<noteq> 0\<rbrakk> \<Longrightarrow> {ptr ..ptr + of_nat n * 2 ^ sbit - 1} \<subseteq> {ptr..(ptr && ~~ mask sz) + 2^ sz - 1}" apply clarsimp apply (frule range_cover_cell_subset[OF _ of_nat_mono_maybe,where y1 = "(n - 1)"]) apply (drule range_cover.range_cover_n_less) apply (simp add:word_bits_def) apply simp apply (clarsimp simp:range_cover_def) apply (erule impE) apply (clarsimp simp:p_assoc_help) apply (rule is_aligned_no_wrap'[OF is_aligned_add_multI[OF _ le_refl refl ]]) apply (fastforce simp:range_cover_def)+ apply (clarsimp) apply (subst (asm) add.assoc) apply (subst (asm) distrib_right[where b = "1::'a::len word",simplified,symmetric]) apply simp done context Untyped_AI_arch begin lemma retype_region_ranges': "\<lbrace>K (range_cover ptr sz (obj_bits_api tp us) n)\<rbrace> retype_region ptr n us tp dev \<lbrace>\<lambda>rv s. \<forall>y\<in>set rv. cap_range (default_cap tp y us dev) \<subseteq> {ptr..ptr + of_nat (n * 2 ^ (obj_bits_api tp us)) - 1}\<rbrace>" apply (simp add:valid_def) apply clarify apply (drule use_valid[OF _ retype_region_ret]) apply simp apply (clarsimp simp del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff) apply (rule subsetD[OF subset_trans]) apply (rule range_cover_subset,assumption) apply clarsimp apply assumption apply fastforce apply simp apply (case_tac tp) apply (simp_all add: cap_range_def obj_bits_api_def ptr_add_def) apply (subst add.commute, rule is_aligned_no_wrap'[OF aligned_add_aligned[OF _ _ le_refl]]) apply (fastforce simp: range_cover_def) apply (simp_all add: word_bits_def is_aligned_mult_triv2[where n=tcb_bits, simplified])[2] apply (subst add.commute, rule is_aligned_no_wrap'[OF aligned_add_aligned[OF _ _ le_refl]]) apply (fastforce simp: range_cover_def) apply (simp add: word_bits_def is_aligned_mult_triv2[where n=endpoint_bits, simplified])+ apply (subst add.commute, rule is_aligned_no_wrap'[OF aligned_add_aligned[OF _ _ le_refl]]) apply (fastforce simp: range_cover_def) apply (simp add: word_bits_def is_aligned_mult_triv2[where n=ntfn_bits, simplified])+ apply (clarsimp simp: is_aligned_def) apply (simp add: p_assoc_help) apply (rule is_aligned_no_wrap'[OF aligned_add_aligned[OF _ _ le_refl]]) apply (fastforce simp: range_cover_def) apply (rule is_aligned_mult_triv2) apply (simp add: range_cover_def) apply (simp add: p_assoc_help) apply (rule is_aligned_no_wrap'[OF is_aligned_add_multI[OF _ le_refl refl]]) apply (simp add: range_cover_def)+ done lemma retype_region_ranges: "\<lbrace>cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_bits c = sz \<and> obj_ref_of c = ptr && ~~ mask sz) p and pspace_no_overlap_range_cover ptr sz and valid_pspace and K (range_cover ptr sz (obj_bits_api tp us) n) \<rbrace> retype_region ptr n us tp dev \<lbrace>\<lambda>rv s. \<forall>y\<in>set rv. cte_wp_at (\<lambda>c. cap_range (default_cap tp y us dev) \<subseteq> untyped_range c ) p s\<rbrace>" apply (clarsimp simp: cte_wp_at_caps_of_state valid_def) apply (frule_tac P1 = "(=) cap" in use_valid[OF _ retype_region_cte_at_other]) apply simp apply (fastforce simp: cte_wp_at_caps_of_state) apply (clarsimp simp: cte_wp_at_caps_of_state) apply (frule use_valid[OF _ retype_region_ranges']) apply (fastforce simp: cte_wp_at_caps_of_state) apply (drule(1) bspec) apply (drule(1) subsetD) apply (rule_tac A = "{x..y}" for x y in subsetD[rotated]) apply assumption apply simp apply (erule subset_trans[OF range_cover_subset']) apply (frule use_valid[OF _ retype_region_ret]) apply simp apply fastforce apply (clarsimp simp: is_cap_simps) apply (erule order_trans[OF word_and_le2]) done end lemma map_snd_zip_prefix_help: "map (\<lambda>tup. cap_range (default_cap tp (snd tup) us dev)) (zip xs ys) \<le> map (\<lambda>x. cap_range (default_cap tp x us dev)) ys" apply (induct xs arbitrary: ys) apply simp apply (case_tac ys) apply auto done context Untyped_AI_arch begin lemma retype_region_distinct_sets: "\<lbrace>K (range_cover ptr sz (obj_bits_api tp us) n)\<rbrace> retype_region ptr n us tp dev \<lbrace>\<lambda>rv s. distinct_sets (map (\<lambda>tup. cap_range (default_cap tp (snd tup) us dev)) (zip xs rv))\<rbrace>" apply (simp add: distinct_sets_prop) apply (rule hoare_gen_asm[where P'="\<top>", simplified]) apply (rule hoare_strengthen_post [OF retype_region_ret]) apply (rule distinct_prop_prefixE [rotated]) apply (rule map_snd_zip_prefix_help [unfolded less_eq_list_def]) apply (clarsimp simp: retype_addrs_def distinct_prop_map) apply (rule distinct_prop_distinct) apply simp apply (subgoal_tac "of_nat y * (2::machine_word) ^ obj_bits_api tp us \<noteq> of_nat x * 2 ^ obj_bits_api tp us") apply (case_tac tp) defer apply (simp add:cap_range_def ptr_add_def)+ apply (clarsimp simp: ptr_add_def word_unat_power[symmetric] shiftl_t2n[simplified mult.commute, symmetric]) apply (erule(2) of_nat_shift_distinct_helper[where 'a=machine_word_len and n = "obj_bits_api tp us"]) apply simp apply (simp add:range_cover_def) apply (erule range_cover.range_cover_n_le) apply (clarsimp simp: add_diff_eq[symmetric] simp del: Int_atLeastAtMost dest!: less_two_pow_divD) apply (simp add: obj_bits_api_def ptr_add_def shiftl_t2n[simplified mult.commute, symmetric] del: Int_atLeastAtMost) apply (rule aligned_neq_into_no_overlap) apply simp apply (simp_all add:range_cover_def shiftl_t2n mult.commute) apply (rule is_aligned_add_multI[OF _ le_refl refl]) apply (simp add:range_cover_def)+ apply (rule is_aligned_add_multI[OF _ le_refl refl]) apply (simp add:range_cover_def) done end declare dmo_aligned [wp] crunch pdistinct[wp]: do_machine_op "pspace_distinct" crunch vmdb[wp]: do_machine_op "valid_mdb" crunch mdb[wp]: do_machine_op "\<lambda>s. P (cdt s)" crunch cte_wp_at[wp]: do_machine_op "\<lambda>s. P (cte_wp_at P' p s)" lemmas dmo_valid_cap[wp] = valid_cap_typ [OF do_machine_op_obj_at] lemma delete_objects_pspace_no_overlap[wp]: "\<lbrace>\<lambda>s. (\<exists>dev idx. s \<turnstile> (cap.UntypedCap dev ptr bits idx)) \<and> pspace_aligned s \<and> valid_objs s \<and> (S = {ptr .. ptr + 2 ^ bits - 1})\<rbrace> delete_objects ptr bits \<lbrace>\<lambda>_. pspace_no_overlap S\<rbrace>" apply (unfold delete_objects_def) apply wp apply (simp add: do_machine_op_def split_def) apply wp apply (clarsimp simp: pspace_no_overlap_detype') done lemma retype_region_descendants_range: "\<lbrace>\<lambda>s. descendants_range x cref s \<and> pspace_no_overlap_range_cover ptr sz s \<and> valid_pspace s \<and> range_cover ptr sz (obj_bits_api ty us) n\<rbrace> retype_region ptr n us ty dev \<lbrace>\<lambda>rv s. descendants_range x cref s\<rbrace>" apply (simp add:descendants_range_def) apply (rule hoare_pre) apply (wps retype_region_mdb) apply (wp hoare_vcg_ball_lift retype_cte_wp_at) apply fastforce done lemma cap_range_def2: "cap_range (default_cap ty ptr us dev) = (if ty = Untyped then {ptr..ptr + 2 ^ us - 1} else {ptr})" apply (case_tac ty) by (simp_all add: cap_range_def) find_theorems preemption_point context Untyped_AI_arch begin lemma retype_region_descendants_range_ret: "\<lbrace>\<lambda>s. (range_cover ptr sz (obj_bits_api ty us) n) \<and> pspace_no_overlap_range_cover ptr sz s \<and> valid_pspace s \<and> range_cover ptr sz (obj_bits_api ty us) n \<and> descendants_range_in {ptr..ptr + of_nat n * 2^(obj_bits_api ty us) - 1} cref s \<rbrace> retype_region ptr n us ty dev \<lbrace>\<lambda>rv (s::'state_ext state). \<forall>y\<in>set rv. descendants_range (default_cap ty y us dev) cref s\<rbrace>" apply (rule hoare_name_pre_state) apply (clarsimp simp: valid_def) apply (frule retype_region_ret[unfolded valid_def,simplified,THEN spec,THEN bspec]) apply (clarsimp) apply (rename_tac x) apply (erule use_valid[OF _ retype_region_descendants_range]) apply (intro conjI,simp_all) apply (clarsimp simp: descendants_range_def descendants_range_in_def) apply (drule(1) bspec) apply (clarsimp simp: cte_wp_at_caps_of_state) apply (erule disjoint_subset2[rotated]) apply (frule(1) range_cover_subset) apply simp apply (erule subset_trans[rotated]) apply (subgoal_tac "ptr + of_nat x * 2 ^ obj_bits_api ty us \<le> ptr + of_nat x * 2 ^ obj_bits_api ty us + 2 ^ obj_bits_api ty us - 1") prefer 2 apply (rule is_aligned_no_overflow) apply (rule is_aligned_add_multI) apply (fastforce simp: range_cover_def)+ apply (auto simp add: cap_range_def2 ptr_add_def obj_bits_api_def) done end lemma caps_overlap_reserved_def2: "caps_overlap_reserved S = (\<lambda>s. (\<forall>cap \<in> ran (null_filter (caps_of_state s)). is_untyped_cap cap \<longrightarrow> usable_untyped_range cap \<inter> S = {}))" apply (rule ext) apply (clarsimp simp: caps_overlap_reserved_def) apply (intro iffI ballI impI) apply (elim ballE impE) apply simp apply simp apply (simp add: ran_def null_filter_def split: if_split_asm option.splits) apply (elim ballE impE) apply simp apply simp apply (clarsimp simp: ran_def null_filter_def is_cap_simps simp del: split_paired_All split_paired_Ex split: if_splits) apply (drule_tac x = "(a,b)" in spec) apply simp done lemma set_cap_valid_mdb_simple: "\<lbrace>\<lambda>s. valid_objs s \<and> valid_mdb s \<and> descendants_range_in {ptr .. ptr+2^sz - 1} cref s \<and> cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_bits c = sz \<and> obj_ref_of c = ptr \<and> cap_is_device c = dev) cref s\<rbrace> set_cap (cap.UntypedCap dev ptr sz idx) cref \<lbrace>\<lambda>rv s'. valid_mdb s'\<rbrace>" apply (simp add: valid_mdb_def) apply (rule hoare_pre) apply (wp set_cap_mdb_cte_at) apply (wps set_cap_rvk_cdt_ct_ms) apply wp apply (clarsimp simp: cte_wp_at_caps_of_state is_cap_simps reply_master_revocable_def irq_revocable_def reply_mdb_def) unfolding fun_upd_def[symmetric] apply clarsimp proof(intro conjI impI) fix s f r bits dev assume obj:"valid_objs s" assume mdb:"untyped_mdb (cdt s) (caps_of_state s)" assume cstate:"caps_of_state s cref = Some (cap.UntypedCap dev r bits f)" (is "?m cref = Some ?srccap") show "untyped_mdb (cdt s) (caps_of_state s(cref \<mapsto> cap.UntypedCap dev r bits idx))" apply (rule untyped_mdb_update_free_index [where capa = ?srccap and m = "caps_of_state s" and src = cref, unfolded free_index_update_def,simplified,THEN iffD2]) apply (simp add: cstate mdb)+ done assume inc: "untyped_inc (cdt s) (caps_of_state s)" assume drange: "descendants_range_in {r..r + 2 ^ bits - 1} cref s" have untyped_range_simp: "untyped_range (cap.UntypedCap dev r bits f) = untyped_range (cap.UntypedCap dev r bits idx)" by simp note blah[simp del] = untyped_range.simps usable_untyped_range.simps atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff split_paired_Ex show "untyped_inc (cdt s) (caps_of_state s(cref \<mapsto> cap.UntypedCap dev r bits idx))" using inc cstate drange apply (unfold untyped_inc_def) apply (intro allI impI) apply (drule_tac x = p in spec) apply (drule_tac x = p' in spec) apply (case_tac "p = cref") apply (simp) apply (case_tac "p' = cref") apply simp apply (simp add: untyped_range_simp) apply (intro conjI impI) apply (simp) apply (elim conjE) apply (thin_tac "Q \<longrightarrow> P" for P Q)+ apply (frule(2) descendants_range_inD[rotated]) apply (drule caps_of_state_valid_cap[OF _ obj]) apply (drule sym) apply (rule disjoint_subset2[OF usable_range_subseteq]) apply (simp add: valid_cap_def cap_aligned_def untyped_range.simps)+ apply (elim disjE conjE) apply (frule(2) descendants_range_inD[rotated]) apply (drule caps_of_state_valid_cap[OF _ obj])+ apply (drule sym) apply (simp add: untyped_range.simps) apply (drule(1) untyped_range_non_empty[OF _ valid_cap_aligned]) apply simp+ apply (case_tac "p' = cref") apply simp apply (intro conjI) apply (elim conjE) apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (simp add: untyped_range_simp)+ apply (intro impI) apply (elim conjE | simp)+ apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (frule(2) descendants_range_inD[rotated]) apply (drule caps_of_state_valid_cap[OF _ obj]) apply (drule sym) apply (rule disjoint_subset2[OF usable_range_subseteq]) apply ((clarsimp simp: valid_cap_def cap_aligned_def untyped_range.simps)+)[3] apply (intro impI) apply (elim conjE subset_splitE | simp)+ apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (clarsimp simp: untyped_range.simps) apply simp apply (elim conjE) apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (clarsimp simp: untyped_range.simps) apply simp apply (erule disjE) apply (clarsimp simp: blah) apply (clarsimp simp: blah) apply (drule_tac t = c' in sym) apply (simp add: untyped_range.simps) apply (drule_tac t= c' in sym) apply (intro impI) apply (simp add: untyped_range.simps) apply (elim disjE conjE) apply simp apply (frule(2) descendants_range_inD[rotated]) apply (drule caps_of_state_valid_cap[OF _ obj])+ apply simp apply (drule(1) untyped_range_non_empty[OF _ valid_cap_aligned]) apply simp+ done assume "ut_revocable (is_original_cap s) (caps_of_state s)" thus "ut_revocable (is_original_cap s) (caps_of_state s(cref \<mapsto> cap.UntypedCap dev r bits idx))" using cstate by (fastforce simp: ut_revocable_def) assume "valid_arch_mdb (is_original_cap s) (caps_of_state s)" thus "valid_arch_mdb (is_original_cap s) (caps_of_state s(cref \<mapsto> cap.UntypedCap dev r bits idx))" using cstate by (fastforce elim!: valid_arch_mdb_untypeds) assume "reply_caps_mdb (cdt s) (caps_of_state s)" thus "reply_caps_mdb (cdt s) (caps_of_state s(cref \<mapsto> cap.UntypedCap dev r bits idx))" using cstate apply (simp add: reply_caps_mdb_def del: split_paired_All split_paired_Ex) apply (intro allI impI conjI) apply (drule spec)+ apply (erule(1) impE) apply (erule exE)+ apply (rule_tac x = ptr' in exI) apply clarsimp done assume "reply_masters_mdb (cdt s) (caps_of_state s)" thus "reply_masters_mdb (cdt s) (caps_of_state s(cref \<mapsto> cap.UntypedCap dev r bits idx))" apply (simp add: reply_masters_mdb_def del: split_paired_All split_paired_Ex) apply (intro allI impI ballI) apply (erule exE) apply (elim allE impE) apply simp using cstate apply fastforce done assume misc: "mdb_cte_at (swp (cte_wp_at ((\<noteq>) cap.NullCap)) s) (cdt s)" "descendants_inc (cdt s) (caps_of_state s)" "caps_of_state s cref = Some (cap.UntypedCap dev r bits f)" thus "descendants_inc (cdt s) (caps_of_state s(cref \<mapsto> cap.UntypedCap dev r bits idx))" apply - apply (erule descendants_inc_minor) apply (clarsimp simp: swp_def cte_wp_at_caps_of_state) apply (clarsimp simp: untyped_range.simps) done qed lemma set_free_index_valid_pspace_simple: "\<lbrace>\<lambda>s. valid_mdb s \<and> valid_pspace s \<and> pspace_no_overlap_range_cover ptr sz s \<and> descendants_range_in {ptr .. ptr+2^sz - 1} cref s \<and> cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_bits c = sz \<and> obj_ref_of c = ptr) cref s \<and> idx \<le> 2^ sz\<rbrace> set_cap (cap.UntypedCap dev ptr sz idx) cref \<lbrace>\<lambda>rv s'. valid_pspace s'\<rbrace>" apply (clarsimp simp: valid_pspace_def) apply (wp set_cap_valid_objs update_cap_iflive set_cap_zombies') apply (clarsimp simp: cte_wp_at_caps_of_state is_cap_simps)+ apply (frule(1) caps_of_state_valid_cap) apply (clarsimp simp: valid_cap_def cap_aligned_def ) apply (intro conjI) apply (simp add: valid_untyped_def) apply (intro impI allI) apply (elim allE allE impE) apply simp+ apply (drule(1) pspace_no_overlap_obj_range) apply (simp add: is_aligned_neg_mask_eq field_simps) apply (clarsimp simp add: pred_tcb_at_def tcb_cap_valid_def obj_at_def is_tcb valid_ipc_buffer_cap_def split: option.split) apply (drule(2) tcb_cap_slot_regular) apply (clarsimp simp: tcb_cap_cases_def is_cap_simps split: if_splits) apply (fastforce simp: is_nondevice_page_cap_simps) apply (clarsimp split: thread_state.splits simp: is_reply_cap_def) done lemma set_untyped_cap_refs_respects_device_simple: "\<lbrace>K (is_untyped_cap cap) and cte_wp_at ((=) cap) cref and cap_refs_respects_device_region \<rbrace> set_cap (UntypedCap (cap_is_device cap) (obj_ref_of cap) (cap_bits cap) idx) cref \<lbrace>\<lambda>rv s. cap_refs_respects_device_region s\<rbrace>" apply (wp set_cap_cap_refs_respects_device_region) apply (clarsimp simp del: split_paired_Ex) apply (rule_tac x = cref in exI) apply (erule cte_wp_at_weakenE) apply (case_tac cap,auto) done lemma set_untyped_cap_caps_overlap_reserved: "\<lbrace>\<lambda>s. invs s \<and> S \<subseteq> {ptr..ptr + 2 ^ sz - 1} \<and> usable_untyped_range (cap.UntypedCap dev ptr sz idx') \<inter> S = {} \<and> descendants_range_in S cref s \<and> cte_wp_at ((=) (cap.UntypedCap dev ptr sz idx)) cref s\<rbrace> set_cap (cap.UntypedCap dev ptr sz idx') cref \<lbrace>\<lambda>rv s. caps_overlap_reserved S s\<rbrace>" apply (unfold caps_overlap_reserved_def) apply wp apply (clarsimp simp: cte_wp_at_caps_of_state caps_overlap_reserved_def simp del: usable_untyped_range.simps split: if_split_asm) apply (frule invs_mdb) apply (erule ranE) apply (simp split: if_split_asm del: usable_untyped_range.simps add: valid_mdb_def) apply (drule untyped_incD) apply ((simp add: is_cap_simps)+)[4] apply clarify apply (erule subset_splitE) apply (simp del: usable_untyped_range.simps) apply (thin_tac "P \<longrightarrow> Q" for P Q)+ apply (elim conjE) apply blast apply (simp del: usable_untyped_range.simps) apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (elim conjE) apply (drule(2) descendants_range_inD) apply simp apply (drule_tac B = S in disjoint_subset[rotated,OF _ usable_range_subseteq]) apply (rule valid_cap_aligned) apply (erule(1) caps_of_state_valid) apply simp+ apply (elim disjE) apply clarsimp apply (drule(2) descendants_range_inD) apply simp apply (drule_tac B=S in disjoint_subset[rotated,OF _ usable_range_subseteq]) apply (rule valid_cap_aligned) apply (erule(1) caps_of_state_valid) apply simp+ apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (rule disjoint_subset[OF usable_range_subseteq]) apply (rule valid_cap_aligned) apply (erule(1) caps_of_state_valid) apply simp+ apply blast done lemma set_cap_caps_no_overlap: "\<lbrace>cte_wp_at (\<lambda>c. untyped_range c = untyped_range cap) cref and caps_no_overlap ptr sz\<rbrace> set_cap cap cref \<lbrace>\<lambda>r s. caps_no_overlap ptr sz s\<rbrace>" apply (simp add: caps_no_overlap_def) apply wp apply (clarsimp simp: cte_wp_at_caps_of_state caps_no_overlap_def simp del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff ) apply (erule ranE) apply (simp split: if_splits del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff ) apply (drule bspec) apply fastforce apply (clarsimp simp del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff ) apply (erule(1) set_mp) apply (drule_tac x = capa in bspec) apply fastforce apply (clarsimp simp del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff ) apply (erule(1) set_mp) done lemma caps_overlap_reserved_detype: "caps_overlap_reserved S s \<Longrightarrow> caps_overlap_reserved S (detype H s)" apply (clarsimp simp: caps_of_state_detype caps_overlap_reserved_def ) apply (erule ranE) apply (clarsimp split: if_splits) apply (drule bspec) apply fastforce apply simp done lemma caps_no_overlap_detype: "caps_no_overlap ptr sz s \<Longrightarrow> caps_no_overlap ptr sz (detype H s)" apply (clarsimp simp: caps_of_state_detype caps_no_overlap_def) apply (erule ranE) apply (clarsimp split: if_splits) apply (drule bspec,fastforce) apply clarsimp apply (erule subsetD) apply simp done lemma not_inD:"\<lbrakk>x \<notin> A; y \<in> A\<rbrakk> \<Longrightarrow>x \<noteq> y" by clarsimp lemma caps_of_state_no_overlapD: "\<lbrakk>caps_of_state s slot = Some cap; valid_objs s; pspace_aligned s; pspace_no_overlap S s\<rbrakk> \<Longrightarrow> (fst slot) \<notin> S" apply (drule caps_of_state_cteD) apply (clarsimp simp: cte_wp_at_cases obj_at_def simp del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost) apply (elim disjE) apply clarify apply (frule(2) p_in_obj_range) apply (erule(1) pspace_no_overlapE) apply (drule(1) IntI) unfolding obj_range_def apply (drule notemptyI)+ apply (simp add: Int_ac p_assoc_help del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost) apply clarify apply (frule(2) p_in_obj_range) apply (erule(1) pspace_no_overlapE) apply (drule(1) IntI) unfolding obj_range_def apply (drule notemptyI)+ apply (simp add: Int_ac p_assoc_help add.commute del: atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost) done lemma op_equal: "(\<lambda>x. x = c) = ((=) c)" by (rule ext) auto lemma descendants_range_in_subseteq: "\<lbrakk>descendants_range_in A p ms ;B\<subseteq> A\<rbrakk> \<Longrightarrow> descendants_range_in B p ms" by (auto simp: descendants_range_in_def cte_wp_at_caps_of_state dest!: bspec) lemma cte_wp_at_pspace_no_overlapI: "\<lbrakk>invs s; cte_wp_at (\<lambda>c. c = cap.UntypedCap dev (ptr && ~~ mask sz) sz idx) cref s; idx \<le> unat (ptr && mask sz); sz < word_bits\<rbrakk> \<Longrightarrow> pspace_no_overlap_range_cover ptr sz s" apply (clarsimp simp: cte_wp_at_caps_of_state) apply (frule caps_of_state_valid_cap) apply (simp add: invs_valid_objs) apply (clarsimp simp: valid_cap_def valid_untyped_def) apply (unfold pspace_no_overlap_def) apply (intro allI impI) apply (drule spec)+ apply (erule(1) impE) apply (simp only: obj_range_def[symmetric] p_assoc_help[symmetric]) apply (frule(1) le_mask_le_2p) apply (rule ccontr) apply (erule impE) apply (rule ccontr) apply simp apply (drule disjoint_subset2[rotated, where B'="{ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1}"]) apply clarsimp apply (rule word_and_le2) apply simp apply clarsimp apply (drule_tac A'="{ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1}" in disjoint_subset[rotated]) apply clarsimp apply (rule le_plus'[OF word_and_le2]) apply simp apply (erule word_of_nat_le) apply blast done lemma descendants_range_caps_no_overlapI: "\<lbrakk>invs s; cte_wp_at ((=) (cap.UntypedCap dev (ptr && ~~ mask sz) sz idx)) cref s; descendants_range_in {ptr .. (ptr && ~~ mask sz) +2^sz - 1} cref s\<rbrakk> \<Longrightarrow> caps_no_overlap ptr sz s" apply (frule invs_mdb) apply (clarsimp simp: valid_mdb_def cte_wp_at_caps_of_state) apply (unfold caps_no_overlap_def) apply (intro ballI impI) apply (erule ranE) apply (subgoal_tac "is_untyped_cap cap") prefer 2 apply (rule untyped_range_is_untyped_cap) apply blast apply (drule untyped_incD) apply simp+ apply (elim conjE) apply (erule subset_splitE) apply (erule subset_trans[OF _ psubset_imp_subset,rotated]) apply (clarsimp simp: word_and_le2) apply simp apply (elim conjE) apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (drule(2) descendants_range_inD) apply simp apply simp apply (erule subset_trans[OF _ equalityD1,rotated]) apply (clarsimp simp: word_and_le2) apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (drule disjoint_subset[rotated, where A' = "{ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1}"]) apply (clarsimp simp: word_and_le2 Int_ac)+ done lemma shiftr_then_mask_commute: "(x >> n) && mask m = (x && mask (m + n)) >> n" using test_bit_size[where w=x] by (auto intro: word_eqI simp add: word_size nth_shiftr) lemma cte_wp_at_caps_no_overlapI: "\<lbrakk> invs s;cte_wp_at (\<lambda>c. c = cap.UntypedCap dev (ptr && ~~ mask sz) sz idx) cref s; idx \<le> unat (ptr && mask sz);sz < word_bits \<rbrakk> \<Longrightarrow> caps_no_overlap ptr sz s" apply (frule invs_mdb) apply (frule(1) le_mask_le_2p) apply (clarsimp simp: valid_mdb_def cte_wp_at_caps_of_state) apply (frule caps_of_state_valid_cap) apply (simp add: invs_valid_objs) apply (unfold caps_no_overlap_def) apply (intro ballI impI) apply (erule ranE) apply (subgoal_tac "is_untyped_cap cap") prefer 2 apply (rule untyped_range_is_untyped_cap) apply blast apply (drule untyped_incD) apply simp+ apply (elim conjE) apply (erule subset_splitE) apply (erule subset_trans[OF _ psubset_imp_subset,rotated]) apply (clarsimp simp: word_and_le2) apply simp apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (elim conjE) apply (drule disjoint_subset2[rotated, where B' = "{ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1}"]) apply clarsimp apply (rule le_plus'[OF word_and_le2]) apply simp apply (erule word_of_nat_le) apply simp apply simp apply (erule subset_trans[OF _ equalityD1,rotated]) apply (clarsimp simp: word_and_le2) apply (thin_tac "P\<longrightarrow>Q" for P Q)+ apply (drule disjoint_subset[rotated, where A' = "{ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1}"]) apply (clarsimp simp: word_and_le2 Int_ac)+ done lemma add_minus_neg_mask: "ptr + a - (ptr && ~~ mask sz) = (ptr && mask sz) + a" apply (subst word_plus_and_or_coroll2[symmetric,where w = "mask sz" and t = ptr]) apply simp done lemma range_cover_idx_compare: "\<lbrakk>range_cover ptr sz sbit n; unat ((ptr && mask sz) + of_nat n * 2 ^ sbit) < 2 ^ sz; ptr \<noteq> ptr && ~~ mask sz; idx \<le> 2 ^ sz; idx \<le> unat (ptr && mask sz)\<rbrakk> \<Longrightarrow> (ptr && ~~ mask sz) + of_nat idx \<le> ptr + (of_nat n << sbit)" apply (subst not_less[symmetric]) apply (subst word_plus_and_or_coroll2[symmetric,where w = "mask sz" and t = ptr]) apply (subst add.commute) apply (simp add: not_less) apply (subst add.assoc) apply (rule word_add_le_mono2) apply (rule order_trans[OF word_of_nat_le]) apply simp apply (erule range_cover.range_cover_base_le) apply (subst unat_plus_simple[THEN iffD1]) apply (erule range_cover.range_cover_base_le) apply (subst unat_add_lem[THEN iffD1,symmetric]) apply (frule range_cover.unat_of_nat_shift[OF _ le_refl le_refl]) apply (simp add: shiftl_t2n field_simps del: add.commute add.assoc) apply (rule le_less_trans) apply (subst add.commute) apply (erule range_cover.range_cover_compare_bound) apply (simp add: range_cover_def) apply (rule less_diff_conv[THEN iffD1]) apply (rule less_le_trans) apply (simp add: shiftl_t2n field_simps) apply (subst le_diff_conv2) apply (rule less_imp_le[OF unat_lt2p]) apply (subst add.commute) apply (subst unat_power_lower[where 'a='a, symmetric]) apply (simp add: range_cover_def) apply (rule is_aligned_no_wrap_le[OF is_aligned_neg_mask[OF le_refl]]) apply (simp add: range_cover_def)+ done locale invoke_untyped_proofs = fixes s cref reset ptr_base ptr tp us slots ptr' sz idx dev assumes vui: "valid_untyped_inv_wcap (Retype cref reset ptr_base ptr tp us slots dev) (Some (UntypedCap dev (ptr && ~~ mask sz) sz idx)) s" and misc: "ct_active s" "invs s" notes blah[simp del] = untyped_range.simps usable_untyped_range.simps atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff split_paired_Ex begin abbreviation(input) "retype_range == {ptr..ptr + of_nat (length slots) * 2 ^ (obj_bits_api tp us) - 1}" abbreviation(input) "usable_range == {ptr..(ptr && ~~ mask sz) + 2 ^ sz - 1}" lemma not_0_ptr[simp]: "ptr\<noteq> 0" using misc vui apply (clarsimp simp: cte_wp_at_caps_of_state) apply (drule(1) caps_of_state_valid) apply (clarsimp simp: valid_cap_def) done lemma cover: "range_cover ptr sz (obj_bits_api tp us) (length slots)" using vui by (clarsimp simp:cte_wp_at_caps_of_state) lemma misc2: "distinct slots" "slots \<noteq> []" using vui by (auto simp:cte_wp_at_caps_of_state) lemma subset_stuff[simp]: "retype_range \<subseteq> usable_range" apply (rule range_cover_subset'[OF cover]) apply (simp add:misc2) done lemma cte_wp_at: "cte_wp_at ((=) (cap.UntypedCap dev (ptr && ~~ mask sz) sz idx)) cref s" using vui by (clarsimp simp: cte_wp_at_caps_of_state) lemma idx_cases: "(idx \<le> unat (ptr - (ptr && ~~ mask sz)) \<or> reset \<and> ptr = ptr && ~~ mask sz)" using vui by (clarsimp simp: cte_wp_at_caps_of_state) lemma desc_range: "reset \<longrightarrow> descendants_range_in S cref s" using vui by (clarsimp simp: empty_descendants_range_in) lemma descendants_range[simp]: "descendants_range_in usable_range cref s" "descendants_range_in retype_range cref s" proof - have "descendants_range_in usable_range cref s" using misc idx_cases cte_wp_at cover apply - apply (erule disjE) apply (erule cte_wp_at_caps_descendants_range_inI[OF _ _ _ range_cover.sz(1) [where 'a=machine_word_len, folded word_bits_def]]) apply (simp add:cte_wp_at_caps_of_state desc_range)+ done thus "descendants_range_in usable_range cref s" by simp thus "descendants_range_in retype_range cref s" by (rule descendants_range_in_subseteq[OF _ subset_stuff]) qed lemma vc[simp] : "s \<turnstile>cap.UntypedCap dev (ptr && ~~ mask sz) sz idx" using misc cte_wp_at apply (clarsimp simp: cte_wp_at_caps_of_state) apply (erule caps_of_state_valid) apply simp done lemma ps_no_overlap[simp]: "\<not> reset \<longrightarrow> pspace_no_overlap_range_cover ptr sz s" using misc cte_wp_at cover idx_cases apply clarsimp apply (erule cte_wp_at_pspace_no_overlapI[OF _ _ _ range_cover.sz(1)[where 'a=machine_word_len, folded word_bits_def]]) apply (simp add: cte_wp_at_caps_of_state) apply simp+ done lemma caps_no_overlap[simp]: "caps_no_overlap ptr sz s" using cte_wp_at misc cover idx_cases apply - apply (erule disjE) apply (erule cte_wp_at_caps_no_overlapI[OF _ _ _ range_cover.sz(1) [where 'a=machine_word_len, folded word_bits_def]]) apply (simp add:cte_wp_at_caps_of_state)+ apply (erule descendants_range_caps_no_overlapI) apply (simp add:cte_wp_at_caps_of_state desc_range)+ done lemma idx_compare'[simp]:"unat ((ptr && mask sz) + (of_nat (length slots)<< (obj_bits_api tp us))) \<le> 2 ^ sz" apply (rule le_trans[OF unat_plus_gt]) apply (simp add:range_cover.unat_of_nat_n_shift[OF cover] range_cover_unat) apply (insert range_cover.range_cover_compare_bound[OF cover]) apply simp done lemma ex_cte_no_overlap: "\<And>P slot. ex_cte_cap_wp_to P slot s \<Longrightarrow> fst slot \<notin> usable_range" using cte_wp_at apply clarsimp apply (drule ex_cte_cap_to_obj_ref_disj,erule disjE) using misc apply clarsimp apply (rule_tac ptr' = "(aa,b)" in untyped_children_in_mdbEE[OF invs_untyped_children]) apply simp+ apply (clarsimp simp:untyped_range.simps) apply (drule_tac B'="usable_range" in disjoint_subset2[rotated]) apply (clarsimp simp:blah word_and_le2) apply blast apply (drule descendants_range_inD[OF descendants_range(1)]) apply (simp add:cte_wp_at_caps_of_state)+ apply (clarsimp simp:cap_range_def) apply blast apply clarsimp apply (drule_tac irq = irq in valid_globals_irq_node[rotated]) using misc apply (clarsimp simp: invs_def valid_state_def ) apply (clarsimp simp:untyped_range.simps) apply (drule_tac B = "{ptr && ~~ mask sz..(ptr && ~~ mask sz) + 2 ^ sz - 1}" in subsetD[rotated]) apply (clarsimp simp:blah word_and_le2) apply simp done lemma cref_inv: "fst cref \<notin> usable_range" apply (insert misc cte_wp_at) apply (drule if_unsafe_then_capD) apply (simp add:invs_def valid_state_def) apply clarsimp apply (drule ex_cte_no_overlap) apply simp done lemma slots_invD: "\<And>x. x \<in> set slots \<Longrightarrow> x \<noteq> cref \<and> fst x \<notin> usable_range \<and> ex_cte_cap_wp_to (\<lambda>_. True) x s" using misc cte_wp_at vui apply (clarsimp simp: cte_wp_at_caps_of_state) apply (drule(1) bspec)+ apply clarsimp apply (frule ex_cte_no_overlap) apply (auto elim: ex_cte_cap_wp_to_weakenE) done lemma usable_range_disjoint: "usable_untyped_range (cap.UntypedCap dev (ptr && ~~ mask sz) sz (unat ((ptr && mask sz) + of_nat (length slots) * 2 ^ obj_bits_api tp us))) \<inter> {ptr..ptr + of_nat (length slots) * 2 ^ obj_bits_api tp us - 1} = {}" proof - have idx_compare''[simp]: "unat ((ptr && mask sz) + (of_nat (length slots) * (2::machine_word) ^ obj_bits_api tp us)) < 2 ^ sz \<Longrightarrow> ptr + of_nat (length slots) * 2 ^ obj_bits_api tp us - 1 < ptr + of_nat (length slots) * 2 ^ obj_bits_api tp us" apply (rule word_leq_le_minus_one,simp) apply (rule neq_0_no_wrap) apply (rule machine_word_plus_mono_right_split) apply (simp add:shiftl_t2n range_cover_unat[OF cover] field_simps) apply (simp add:range_cover.sz[where 'a=machine_word_len, folded word_bits_def, OF cover])+ done show ?thesis apply (clarsimp simp:mask_out_sub_mask blah) apply (drule idx_compare'') apply (simp add:not_le[symmetric]) done qed lemma detype_locale:"ptr && ~~ mask sz = ptr \<Longrightarrow> detype_locale (cap.UntypedCap dev (ptr && ~~ mask sz) sz idx) cref s" using cte_wp_at descendants_range misc by (simp add:detype_locale_def descendants_range_def2 blah invs_untyped_children) lemma detype_descendants_range_in: "ptr && ~~ mask sz = ptr \<Longrightarrow> descendants_range_in usable_range cref (detype usable_range s)" using misc cte_wp_at apply - apply (frule detype_invariants) apply (simp) using descendants_range apply (clarsimp simp: blah descendants_range_def2) apply (simp add: invs_untyped_children blah invs_valid_reply_caps invs_valid_reply_masters)+ apply (subst valid_mdb_descendants_range_in) apply (clarsimp dest!:invs_mdb simp:detype_clear_um_independent) apply (frule detype_locale) apply (drule detype_locale.non_filter_detype[symmetric]) apply (simp add:blah) using descendants_range(1) apply - apply (subst (asm)valid_mdb_descendants_range_in) apply (simp add:invs_mdb) apply simp done lemma detype_invs: "ptr && ~~ mask sz = ptr \<Longrightarrow> invs (detype usable_range (clear_um usable_range s))" apply (insert misc cte_wp_at descendants_range) apply clarsimp apply (frule detype_invariants, simp_all) apply (clarsimp simp:blah descendants_range_def2) apply ((simp add: invs_untyped_children blah invs_valid_reply_caps invs_valid_reply_masters)+) done lemmas simps = caps_no_overlap descendants_range slots_invD cref_inv ps_no_overlap subset_stuff lemma szw: "sz < word_bits" using cte_wp_at_valid_objs_valid_cap[OF cte_wp_at] misc by (clarsimp simp: valid_cap_def cap_aligned_def invs_valid_objs) lemma idx_le_new_offs: "\<not> reset \<Longrightarrow> idx \<le> unat ((ptr && mask sz) + (of_nat (length slots) << obj_bits_api tp us))" using misc idx_cases range_cover.range_cover_base_le[OF cover] apply (simp only: simp_thms) apply (erule order_trans) apply (simp add: word_le_nat_alt[symmetric]) done end lemmas aligned_after_mask = is_aligned_andI1[where x=ptr and n=a and y="mask sz" for ptr sz a] lemma detype_clear_um_simps[simp]: "caps_no_overlap ptr sz (clear_um H s) = caps_no_overlap ptr sz s" "pspace_no_overlap S (clear_um H s) = pspace_no_overlap S s" "descendants_range_in S p (clear_um H s) = descendants_range_in S p s" apply (clarsimp simp: caps_no_overlap_def pspace_no_overlap_def clear_um.pspace descendants_range_in_def cong: if_cong)+ apply (simp add: clear_um_def) done crunch pred_tcb_at[wp]: create_cap "pred_tcb_at proj P t" (simp: crunch_simps) crunch tcb[wp]: create_cap "tcb_at t" (simp: crunch_simps) lemma valid_untyped_cap_inc: "\<lbrakk>s \<turnstile> cap.UntypedCap dev (ptr&&~~ mask sz) sz idx; idx \<le> unat (ptr && mask sz); range_cover ptr sz sb n\<rbrakk> \<Longrightarrow> s \<turnstile> cap.UntypedCap dev (ptr && ~~ mask sz) sz (unat ((ptr && mask sz) + of_nat n * 2 ^ sb))" apply (clarsimp simp: valid_cap_def cap_aligned_def valid_untyped_def simp del: usable_untyped_range.simps) apply (intro conjI allI impI) apply (elim allE conjE impE) apply simp apply simp apply (erule disjoint_subset[rotated]) apply (frule(1) le_mask_le_2p[OF _ range_cover.sz(1)[where 'a=machine_word_len, folded word_bits_def]]) apply clarsimp apply (rule word_plus_mono_right) apply (rule word_of_nat_le) apply (simp add: unat_of_nat_eq[where 'a=machine_word_len] range_cover_unat field_simps) apply (rule is_aligned_no_wrap'[OF is_aligned_neg_mask[OF le_refl]]) apply (simp add: word_less_nat_alt unat_power_lower[where 'a=machine_word_len, folded word_bits_def]) apply (simp add: range_cover_unat range_cover.unat_of_nat_shift shiftl_t2n field_simps) apply (subst add.commute) apply (simp add: range_cover.range_cover_compare_bound) done (* FIXME: move maybe *) lemma tcb_cap_valid_untyped_cong: "tcb_cap_valid (cap.UntypedCap dev1 a1 b1 c) = tcb_cap_valid (cap.UntypedCap dev2 a2 b2 c2)" apply (rule ext)+ apply (clarsimp simp:tcb_cap_valid_def valid_ipc_buffer_cap_def split:option.splits) apply (simp add: tcb_cap_cases_def is_arch_cap_def is_nondevice_page_cap_simps is_cap_simps split: thread_state.split) done lemma tcb_cap_valid_untyped_to_thread: "tcb_cap_valid (cap.UntypedCap dev a1 b1 c) = tcb_cap_valid (cap.ThreadCap 0)" apply (rule ext)+ apply (clarsimp simp:tcb_cap_valid_def valid_ipc_buffer_cap_def split:option.splits) apply (simp add: tcb_cap_cases_def is_cap_simps is_arch_cap_def is_nondevice_page_cap_simps split: thread_state.split) done (* FIXME: move *) lemma ex_nonz_cap_to_overlap: "\<lbrakk>ex_nonz_cap_to t s; cte_wp_at ((=) cap) p s; is_untyped_cap cap; invs s; descendants_range cap p s \<rbrakk> \<Longrightarrow> \<not> t \<in> untyped_range cap" apply (rule ccontr) apply (clarsimp simp: ex_nonz_cap_to_def descendants_range_def2 cte_wp_at_caps_of_state caps_no_overlap_def zobj_refs_to_obj_refs) apply (frule invs_mdb) apply (clarsimp simp: valid_mdb_def) apply (frule_tac cap' = capa in untyped_mdbD) apply simp+ apply blast apply simp apply (drule(2) descendants_range_inD) apply (simp add: cap_range_def) apply blast done lemma detype_valid_untyped: "\<lbrakk>invs s; detype S s \<turnstile> cap.UntypedCap dev ptr sz idx1; {ptr .. ptr + 2 ^ sz - 1} \<subseteq> S; idx2 \<le> 2 ^ sz\<rbrakk> \<Longrightarrow> detype S s \<turnstile> cap.UntypedCap dev ptr sz idx2" apply (clarsimp simp: detype_def valid_cap_def valid_untyped_def cap_aligned_def) apply (drule_tac x = p in spec) apply clarsimp apply (drule p_in_obj_range) apply (simp add: invs_psp_aligned invs_valid_objs)+ apply (drule(1) subset_trans[rotated]) apply blast done lemma do_machine_op_pspace_no_overlap[wp]: "\<lbrace>pspace_no_overlap S\<rbrace> do_machine_op f \<lbrace>\<lambda>r. pspace_no_overlap S\<rbrace>" apply (clarsimp simp: pspace_no_overlap_def do_machine_op_def) apply (wp hoare_vcg_all_lift) apply (simp add: split_def) apply wp+ apply clarsimp done lemma mapME_append: "mapME f (xs @ ys) = doE xs_r \<leftarrow> mapME f xs; ys_r \<leftarrow> mapME f ys; returnOk (xs_r @ ys_r) odE" by (induct xs, simp_all add: mapME_Nil mapME_Cons bindE_assoc) lemma mapME_validE_nth_induct: "\<lbrakk> \<And>i ys. i < length xs \<Longrightarrow> \<lbrace>P i ys\<rbrace> f (zs ! i) \<lbrace>\<lambda>y. P (Suc i) (y # ys)\<rbrace>, \<lbrace>E\<rbrace>; \<And>i. i < length xs \<Longrightarrow> zs ! i = xs ! i \<rbrakk> \<Longrightarrow> \<lbrace>P 0 []\<rbrace> mapME f xs \<lbrace>\<lambda>ys. P (length xs) (rev ys)\<rbrace>, \<lbrace>E\<rbrace>" proof (induct xs rule: rev_induct) case Nil show ?case by (wp | simp add: mapME_Nil)+ next case (snoc x xs) from snoc.prems have x: "x = zs ! length xs" by simp from snoc.prems have zs: "\<And>i. i < length xs \<Longrightarrow> xs ! i = zs ! i" by (metis length_append_singleton less_SucI nth_append) show ?case apply (simp add: mapME_append mapME_Cons mapME_Nil bindE_assoc x) apply (wp snoc.hyps snoc.prems | simp add: zs)+ done qed lemma mapME_x_mapME: "mapME_x m l = (mapME m l >>=E (%_. returnOk ()))" apply (simp add: mapME_x_def sequenceE_x_def mapME_def sequenceE_def) apply (induct l, simp_all add: Let_def bindE_assoc) done lemmas mapME_validE_nth = mapME_validE_nth_induct[OF _ refl] lemma mapME_x_validE_nth: "\<lbrakk> \<And>i. i < length xs \<Longrightarrow> \<lbrace>P i\<rbrace> f (xs ! i) \<lbrace>\<lambda>y. P (Suc i)\<rbrace>, \<lbrace>E\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>P 0\<rbrace> mapME_x f xs \<lbrace>\<lambda>_. P (length xs)\<rbrace>, \<lbrace>E\<rbrace>" by (wp mapME_validE_nth | simp add: mapME_x_mapME)+ lemma alignUp_ge_nat: "0 < m \<Longrightarrow> (n :: nat) \<le> ((n + m - 1) div m) * m" apply (cases n, simp_all add: Suc_le_eq) apply (subgoal_tac "\<exists>q r. nat = q * m + r \<and> r < m") apply clarsimp apply (metis div_mult_mod_eq mod_less_divisor) done lemma alignUp_le_nat: "0 < m \<Longrightarrow> n \<le> (b :: nat) \<Longrightarrow> m dvd b \<Longrightarrow> ((n + m - 1) div m) * m \<le> b" apply (clarsimp simp: dvd_def) apply (rule less_Suc_eq_le[THEN iffD1]) apply (simp add: td_gal_lt[symmetric]) apply (subst less_eq_Suc_le, simp add: mult.commute) done lemma filter_upt_eq: assumes mono: "\<forall>a b. a \<le> b \<longrightarrow> f b \<longrightarrow> f a" and preds: "\<not> f k" "k \<noteq> 0 \<longrightarrow> f (k - 1)" "k \<le> j" shows "filter f (upt i j) = upt i k" proof - have mono': "\<And>a b. a \<le> b \<longrightarrow> f b \<longrightarrow> f a" by (metis mono) have f: "f = (\<lambda>x. x < k)" apply (rule ext) apply (cut_tac a=k and b=x in mono') apply (cut_tac a=x and b="k - 1" in mono') apply (cut_tac preds(1)) apply (cases "k = 0") apply (simp add: preds) apply (simp add: preds[simplified]) apply (cases k, auto) done show ?thesis apply (rule sorted_distinct_set_unique, simp_all add: sorted_filter[where f=id, simplified]) apply (cut_tac preds) apply (auto simp add: f) done qed lemma nat_diff_less2: fixes x :: nat shows "\<lbrakk> x < y + z; 0 < y\<rbrakk> \<Longrightarrow> x - z < y" apply (cases "z \<le> x") apply (metis nat_diff_less) apply simp done lemma upt_mult_lt_prop: assumes n: "n \<le> 2 ^ a" assumes b: "b \<le> a" shows "\<exists>bd. [i\<leftarrow>[0..<2 ^ (a - b)]. i * 2 ^ b < n] = [0 ..< bd] \<and> n \<le> bd * 2 ^ b \<and> bd * 2 ^ b \<le> 2 ^ a \<and> (bd - 1) * 2 ^ b \<le> n" proof - let ?al = "(n + (2 ^ b - 1)) div 2 ^ b" have sub1: "0 < n \<Longrightarrow> (?al - 1) * 2 ^ b < n" apply (cases "?al = 0") apply simp apply (simp add: diff_mult_distrib) apply (rule nat_diff_less2, simp_all) apply (rule order_le_less_trans, rule div_mult_le) apply simp done have le1: "(n + 2 ^ b - Suc 0) div 2 ^ b * 2 ^ b \<le> 2 ^ a" apply (rule alignUp_le_nat[simplified], simp_all add: n) apply (simp add: b le_imp_power_dvd) done note le2 = div_le_mono[OF le1, where k="2 ^ b", simplified] show ?thesis apply (cases "n = 0") apply (simp add: exI[where x=0]) apply (rule exI[where x="?al"]) apply (strengthen filter_upt_eq) apply (simp add: linorder_not_less conj_ac) apply (simp add: alignUp_ge_nat[simplified] sub1[simplified] sub1[THEN order_less_imp_le, simplified] power_minus_is_div[OF b] le1 le2) apply (auto elim: order_le_less_trans[rotated]) done qed lemma delete_objects_ex_cte_cap_wp_to: notes untyped_range.simps[simp del] shows "\<lbrace>ex_cte_cap_wp_to P slot and invs and cte_wp_at (\<lambda>cp. is_untyped_cap cp \<and> {ptr_base .. ptr_base + 2 ^ sz - 1} \<subseteq> untyped_range cp) src_slot and (\<lambda>s. descendants_of src_slot (cdt s) = {})\<rbrace> delete_objects ptr_base sz \<lbrace>\<lambda>rv s. ex_cte_cap_wp_to P slot s\<rbrace>" apply (simp add: delete_objects_def ex_cte_cap_wp_to_def) apply (rule hoare_pre) apply (rule hoare_lift_Pf2 [where f="interrupt_irq_node"]) apply (wp hoare_vcg_ex_lift | simp)+ apply (clarsimp simp: cte_wp_at_caps_of_state) apply (intro exI conjI, assumption+) apply (frule if_unsafe_then_capD[OF caps_of_state_cteD], clarsimp+) apply (case_tac "the (caps_of_state s src_slot)", simp_all) apply (frule ex_cte_cap_protects, simp add: cte_wp_at_caps_of_state, rule empty_descendants_range_in, (assumption | clarsimp)+) done lemma do_machine_op_ex_cte_cap_wp_to[wp]: "\<lbrace>ex_cte_cap_wp_to P slot\<rbrace> do_machine_op oper \<lbrace>\<lambda>rv s. ex_cte_cap_wp_to P slot s\<rbrace>" apply (simp add: do_machine_op_def split_def) apply wp apply (clarsimp simp: ex_cte_cap_wp_to_def) done lemma delete_objects_real_cte_at[wp]: "\<lbrace>\<lambda>s. real_cte_at p s \<and> fst p \<notin> {ptr_base .. ptr_base + 2 ^ sz - 1}\<rbrace> delete_objects ptr_base sz \<lbrace>\<lambda>rv. real_cte_at p\<rbrace>" by (wp | simp add: delete_objects_def)+ lemma delete_objects_ct_in_state[wp]: "\<lbrace>\<lambda>s. ct_in_state P s \<and> cur_thread s \<notin> {ptr_base .. ptr_base + 2 ^ sz - 1}\<rbrace> delete_objects ptr_base sz \<lbrace>\<lambda>rv. ct_in_state P\<rbrace>" apply (rule hoare_pre) apply (wp | simp add: delete_objects_def ct_in_state_def st_tcb_at_def | simp add: detype_def)+ apply (rule hoare_lift_Pf2[where f=cur_thread]) apply wp+ apply (clarsimp simp: ct_in_state_def st_tcb_at_def) done (* FIXME: move? *) lemma pspace_no_overlap_subset: "pspace_no_overlap S s \<Longrightarrow> T \<subseteq> S \<Longrightarrow> pspace_no_overlap T s" by (clarsimp simp: pspace_no_overlap_def disjoint_subset2) crunch cur_thread[wp]: delete_objects "\<lambda>s. P (cur_thread s)" (simp: detype_def) lemma ct_in_state_trans_state[simp]: "ct_in_state P (trans_state a s) = ct_in_state P s" by (simp add: ct_in_state_def) lemmas unat_of_nat_word_bits = unat_of_nat_eq[where 'a = machine_word_len, unfolded word_bits_len_of, simplified] lemma caps_of_state_pspace_no_overlapD: "\<lbrakk> caps_of_state s cref = Some (cap.UntypedCap dev ptr sz idx); invs s; idx < 2 ^ sz \<rbrakk> \<Longrightarrow> pspace_no_overlap_range_cover (ptr + of_nat idx) sz s" apply (frule(1) caps_of_state_valid) apply (clarsimp simp: valid_cap_simps cap_aligned_def) apply (cut_tac neg_mask_add_aligned[where p=ptr and q="of_nat idx" and n=sz]) apply (rule cte_wp_at_pspace_no_overlapI[where idx=idx and cref=cref], simp_all) apply (simp add: cte_wp_at_caps_of_state) apply (simp add: mask_out_sub_mask) apply (subst unat_of_nat_word_bits, erule order_less_le_trans, simp_all) apply (rule word_of_nat_less) apply (erule order_less_le_trans) apply simp done lemma set_untyped_cap_invs_simple: "\<lbrace>\<lambda>s. descendants_range_in {ptr .. ptr+2^sz - 1} cref s \<and> pspace_no_overlap_range_cover ptr sz s \<and> invs s \<and> cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_bits c = sz \<and> cap_is_device c = dev\<and> obj_ref_of c = ptr) cref s \<and> idx \<le> 2^ sz\<rbrace> set_cap (cap.UntypedCap dev ptr sz idx) cref \<lbrace>\<lambda>rv s. invs s\<rbrace>" apply (rule hoare_name_pre_state) apply (clarsimp simp:cte_wp_at_caps_of_state invs_def valid_state_def) apply (rule hoare_pre) apply (wp set_free_index_valid_pspace_simple set_cap_valid_mdb_simple set_cap_idle update_cap_ifunsafe set_cap_valid_arch_caps_simple) apply (simp add:valid_irq_node_def) apply wps apply (wp hoare_vcg_all_lift set_cap_irq_handlers set_cap_irq_handlers cap_table_at_lift_valid set_cap_ioports' set_cap_typ_at set_cap_valid_arch_caps_simple set_cap_kernel_window_simple set_cap_cap_refs_respects_device_region) apply (clarsimp simp del: split_paired_Ex) apply (strengthen exI[where x=cref]) apply (clarsimp simp:cte_wp_at_caps_of_state is_cap_simps valid_pspace_def) apply (intro conjI; clarsimp?) apply (clarsimp simp: fun_eq_iff) apply (clarsimp split:cap.splits simp:is_cap_simps appropriate_cte_cap_def) apply (drule(1) if_unsafe_then_capD[OF caps_of_state_cteD]) apply clarsimp apply (clarsimp simp: is_cap_simps ex_cte_cap_wp_to_def appropriate_cte_cap_def cte_wp_at_caps_of_state) apply (clarsimp dest!:valid_global_refsD2 simp:cap_range_def) apply (simp add:valid_irq_node_def) apply (clarsimp simp:valid_irq_node_def) apply (clarsimp intro!: safe_ioport_insert_triv simp: is_cap_simps) done lemma reset_untyped_cap_invs_etc: "\<lbrace>invs and valid_untyped_inv_wcap ui (Some (UntypedCap dev ptr sz idx)) and ct_active and K (\<exists>ptr_base ptr' ty us slots. ui = Retype slot True ptr_base ptr' ty us slots dev)\<rbrace> reset_untyped_cap slot \<lbrace>\<lambda>_. invs and valid_untyped_inv_wcap ui (Some (UntypedCap dev ptr sz 0)) and ct_active and pspace_no_overlap {ptr .. ptr + 2 ^ sz - 1}\<rbrace>, \<lbrace>\<lambda>_. invs\<rbrace>" (is "\<lbrace>invs and valid_untyped_inv_wcap ?ui (Some ?cap) and ct_active and _\<rbrace> ?f \<lbrace>\<lambda>_. invs and ?vu2 and ct_active and ?psp\<rbrace>, \<lbrace>\<lambda>_. invs\<rbrace>") apply (simp add: reset_untyped_cap_def) apply (rule hoare_vcg_seqE[rotated]) apply ((wp (once) get_cap_sp)+)[1] apply (rule hoare_name_pre_stateE) apply (clarsimp simp: cte_wp_at_caps_of_state bits_of_def split del: if_split) apply (subgoal_tac "is_aligned ptr sz") prefer 2 apply (frule caps_of_state_valid_cap, clarsimp) apply auto[1] apply (cases "idx = 0") apply (clarsimp simp: free_index_of_def) apply wp apply clarsimp apply (frule(1) caps_of_state_pspace_no_overlapD, simp+) apply (simp add: word_bw_assocs field_simps) apply (clarsimp simp: free_index_of_def split del: if_split) apply (rule_tac B="\<lambda>_. invs and valid_untyped_inv_wcap ?ui (Some ?cap) and ct_active and ?psp" in hoare_vcg_seqE[rotated]) apply clarsimp apply (rule hoare_pre) apply (wp hoare_vcg_ex_lift hoare_vcg_const_Ball_lift delete_objects_ex_cte_cap_wp_to[where src_slot=slot] ) apply (clarsimp simp: cte_wp_at_caps_of_state ct_in_state_def) apply (frule if_unsafe_then_capD[OF caps_of_state_cteD], clarsimp+) apply (drule(1) ex_cte_cap_protects[OF _ caps_of_state_cteD _ _ order_refl]) apply (simp add: empty_descendants_range_in) apply clarsimp+ apply (strengthen ballEI[mk_strg I E] refl) apply (strengthen exI[where x="fst slot"], strengthen exI[where x="snd slot"]) apply (strengthen ex_cte_cap_protects[OF _ caps_of_state_cteD _ _ order_refl, mk_strg D E]) apply (simp add: empty_descendants_range_in invs_untyped_children invs_valid_global_refs descendants_range_def bits_of_def) apply (strengthen refl) apply (drule st_tcb_ex_cap, clarsimp, fastforce) apply (drule ex_nonz_cap_to_overlap[where p=slot], (simp add: cte_wp_at_caps_of_state descendants_range_def)+) apply (drule caps_of_state_valid_cap | clarify)+ apply (intro conjI; clarify?; blast)[1] apply (cases "dev \<or> sz < reset_chunk_bits") apply (simp add: bits_of_def) apply (simp add: unless_def) apply (rule hoare_pre) apply (wp set_untyped_cap_invs_simple set_cap_cte_wp_at set_cap_no_overlap hoare_vcg_const_Ball_lift set_cap_cte_cap_wp_to ct_in_state_thread_state_lift) apply (strengthen empty_descendants_range_in) apply (rule hoare_lift_Pf2 [where f="interrupt_irq_node"]) apply (wp hoare_vcg_const_Ball_lift hoare_vcg_const_imp_lift hoare_vcg_ex_lift ct_in_state_thread_state_lift)+ apply (clarsimp simp add: bits_of_def field_simps cte_wp_at_caps_of_state empty_descendants_range_in) apply (cut_tac a=sz and b=reset_chunk_bits and n=idx in upt_mult_lt_prop) apply (frule caps_of_state_valid_cap, clarsimp+) apply (simp add: valid_cap_def) apply simp apply (clarsimp simp: bits_of_def free_index_of_def) apply (rule hoare_pre, rule hoare_post_impErr, rule_tac P="\<lambda>i. invs and ?psp and ct_active and valid_untyped_inv_wcap ?ui (Some (UntypedCap dev ptr sz (if i = 0 then idx else (bd - i) * 2 ^ reset_chunk_bits)))" and E="\<lambda>_. invs" in mapME_x_validE_nth) apply (rule hoare_pre) apply (wp set_untyped_cap_invs_simple set_cap_no_overlap set_cap_cte_wp_at preemption_point_inv hoare_vcg_ex_lift hoare_vcg_const_imp_lift hoare_vcg_const_Ball_lift set_cap_cte_cap_wp_to | strengthen empty_descendants_range_in | simp | rule irq_state_independent_A_conjI | simp add: cte_wp_at_caps_of_state | wp (once) ct_in_state_thread_state_lift | (rule irq_state_independent_A_def[THEN meta_eq_to_obj_eq, THEN iffD2], simp add: ex_cte_cap_wp_to_def ct_in_state_def))+ apply (clarsimp simp: is_aligned_neg_mask_eq bits_of_def field_simps cte_wp_at_caps_of_state nth_rev) apply (strengthen order_trans[where z="2 ^ sz", rotated, mk_strg I E]) apply (clarsimp split: if_split_asm) apply auto[1] apply (auto elim: order_trans[rotated])[1] apply (clarsimp simp: cte_wp_at_caps_of_state split: if_split_asm) apply simp apply (clarsimp simp: cte_wp_at_caps_of_state) done lemma get_cap_prop_known: "\<lbrace>cte_wp_at (\<lambda>cp. f cp = v) slot and Q v\<rbrace> get_cap slot \<lbrace>\<lambda>rv. Q (f rv)\<rbrace>" apply (wp get_cap_wp) apply (clarsimp simp: cte_wp_at_caps_of_state) done lemma reset_untyped_cap_st_tcb_at: "\<lbrace>invs and st_tcb_at P t and cte_wp_at (\<lambda>cp. t \<notin> cap_range cp \<and> is_untyped_cap cp) slot\<rbrace> reset_untyped_cap slot \<lbrace>\<lambda>_. st_tcb_at P t\<rbrace>, \<lbrace>\<lambda>_. st_tcb_at P t\<rbrace>" apply (simp add: reset_untyped_cap_def) apply (rule hoare_pre) apply (wp mapME_x_inv_wp preemption_point_inv | simp add: unless_def)+ apply (simp add: delete_objects_def) apply (wp get_cap_wp hoare_vcg_const_imp_lift | simp)+ apply (auto simp: cte_wp_at_caps_of_state cap_range_def bits_of_def is_cap_simps) done lemma create_cap_iflive[wp]: "\<lbrace>if_live_then_nonz_cap and cte_wp_at ((=) cap.NullCap) cref\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. if_live_then_nonz_cap\<rbrace>" apply (simp add: create_cap_def) apply (wp new_cap_iflive set_cdt_cte_wp_at | simp)+ done crunch cap_to_again[wp]: set_cdt "ex_cte_cap_wp_to P p" (simp: ex_cte_cap_wp_to_def) lemma create_cap_ifunsafe[wp]: "\<lbrace>if_unsafe_then_cap and ex_cte_cap_wp_to (appropriate_cte_cap (default_cap tp oref sz dev)) cref and cte_wp_at ((=) cap.NullCap) cref\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. if_unsafe_then_cap\<rbrace>" apply (simp add: create_cap_def) apply (wp new_cap_ifunsafe set_cdt_cte_wp_at | simp)+ done lemma set_cdt_state_refs_of[wp]: "\<lbrace>\<lambda>s. P (state_refs_of s)\<rbrace> set_cdt m \<lbrace>\<lambda>rv s. P (state_refs_of s)\<rbrace>" apply (simp add: set_cdt_def) apply wp apply (clarsimp elim!: state_refs_of_pspaceI) done lemma set_cdt_state_hyp_refs_of[wp]: "\<lbrace>\<lambda>s. P (state_hyp_refs_of s)\<rbrace> set_cdt m \<lbrace>\<lambda>rv s. P (state_hyp_refs_of s)\<rbrace>" apply (simp add: set_cdt_def) apply wp apply (clarsimp elim!: state_hyp_refs_of_pspaceI) done lemma state_refs_of_rvk[simp]: "state_refs_of (is_original_cap_update f s) = state_refs_of s" by (simp add: state_refs_of_def) lemma create_cap_state_refs_of[wp]: "\<lbrace>\<lambda>s. P (state_refs_of s)\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv s. P (state_refs_of s)\<rbrace>" unfolding create_cap_def by wpsimp lemma create_cap_state_hyp_refs_of[wp]: "\<lbrace>\<lambda>s. P (state_hyp_refs_of s)\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv s. P (state_hyp_refs_of s)\<rbrace>" apply (simp add: create_cap_def) apply (wp | simp)+ done lemma create_cap_zombies[wp]: "\<lbrace>zombies_final and cte_wp_at ((=) cap.NullCap) cref and (\<lambda>s. \<forall>r\<in>obj_refs (default_cap tp oref sz dev). \<forall>p'. \<not> cte_wp_at (\<lambda>cap. r \<in> obj_refs cap) p' s)\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. zombies_final\<rbrace>" unfolding create_cap_def set_cdt_def by (wpsimp wp: new_cap_zombies) lemma create_cap_cur_tcb[wp]: "\<lbrace>cur_tcb\<rbrace> create_cap tp sz p dev tup \<lbrace>\<lambda>rv. cur_tcb\<rbrace>" unfolding create_cap_def split_def set_cdt_def by wpsimp lemma create_cap_valid_idle[wp]: "\<lbrace>valid_idle\<rbrace> create_cap tp sz p dev tup \<lbrace>\<lambda>rv. valid_idle\<rbrace>" unfolding create_cap_def split_def set_cdt_def by (wpsimp wp: set_cap_idle) crunch it[wp]: create_cap "\<lambda>s. P (idle_thread s)" (simp: crunch_simps) lemma default_cap_reply: "default_cap tp ptr sz dev \<noteq> cap.ReplyCap ptr' bool R" by (cases tp; simp) lemma create_cap_valid_reply_caps[wp]: "\<lbrace>valid_reply_caps\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_reply_caps\<rbrace>" apply (simp add: valid_reply_caps_def has_reply_cap_def cte_wp_at_caps_of_state create_cap_def is_reply_cap_to_def set_cdt_def) apply (simp only: imp_conv_disj) apply (rule hoare_pre) apply (wp hoare_vcg_all_lift hoare_vcg_disj_lift | simp)+ apply (clarsimp simp: default_cap_reply) apply (erule conjI [OF allEI], fastforce) apply (simp add: unique_reply_caps_def default_cap_reply) done lemma create_cap_valid_reply_masters[wp]: "\<lbrace>valid_reply_masters\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_reply_masters\<rbrace>" apply (simp add: valid_reply_masters_def cte_wp_at_caps_of_state create_cap_def is_master_reply_cap_to_def) apply (wp | simp add: default_cap_reply)+ done lemma create_cap_valid_global_refs[wp]: "\<lbrace>valid_global_refs and cte_wp_at (\<lambda>c. cap_range (default_cap tp oref sz dev) \<subseteq> cap_range c) p\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_global_refs\<rbrace>" apply (simp add: valid_global_refs_def valid_refs_def cte_wp_at_caps_of_state create_cap_def pred_conj_def) apply (simp only: imp_conv_disj) apply (wpsimp wp: hoare_vcg_all_lift hoare_vcg_disj_lift) apply (subgoal_tac "global_refs s \<inter> cap_range (default_cap tp oref sz dev) = {}") apply auto[1] apply (erule disjoint_subset2) apply (cases p, simp) done crunch arch_state[wp]: create_cap "\<lambda>s. P (arch_state s)" (simp: crunch_simps) lemma create_cap_aobj_at: "arch_obj_pred P' \<Longrightarrow> \<lbrace>\<lambda>s. P (obj_at P' pd s)\<rbrace> create_cap type bits ut is_dev cref \<lbrace>\<lambda>r s. P (obj_at P' pd s)\<rbrace>" unfolding create_cap_def split_def set_cdt_def by (wpsimp wp: set_cap.aobj_at) lemma create_cap_valid_arch_state[wp]: "\<lbrace>valid_arch_state\<rbrace> create_cap type bits ut is_dev cref \<lbrace>\<lambda>_. valid_arch_state\<rbrace>" by (wp valid_arch_state_lift_aobj_at create_cap_aobj_at) crunch irq_node[wp]: create_cap "\<lambda>s. P (interrupt_irq_node s)" (simp: crunch_simps) lemmas create_cap_valid_irq_node[wp] = valid_irq_node_typ [OF create_cap_typ_at create_cap_irq_node] lemma default_cap_irqs[simp]: "cap_irqs (default_cap tp oref sz dev) = {}" by (cases tp, simp_all) lemma create_cap_irq_handlers[wp]: "\<lbrace>valid_irq_handlers\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_irq_handlers\<rbrace>" apply (simp add: valid_irq_handlers_def irq_issued_def) apply (simp add: create_cap_def Ball_def) apply (simp only: imp_conv_disj) apply (wpsimp wp: hoare_vcg_all_lift hoare_vcg_disj_lift) apply (auto simp: ran_def split: if_split_asm) done crunch valid_vspace_objs[wp]: create_cap "valid_vspace_objs" (simp: crunch_simps) locale Untyped_AI_nonempty_table = fixes state_ext_t :: "('state_ext::state_ext) itself" fixes nonempty_table :: "machine_word set \<Rightarrow> Structures_A.kernel_object \<Rightarrow> bool" assumes create_cap_valid_arch_caps[wp]: "\<And>tp oref sz dev cref p.\<lbrace>valid_arch_caps and valid_cap (default_cap tp oref sz dev) and (\<lambda>(s::'state_ext state). \<forall>r\<in>obj_refs (default_cap tp oref sz dev). (\<forall>p'. \<not> cte_wp_at (\<lambda>cap. r \<in> obj_refs cap) p' s) \<and> \<not> obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s) and cte_wp_at ((=) cap.NullCap) cref and K (tp \<noteq> ArchObject ASIDPoolObj)\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_arch_caps\<rbrace>" assumes create_cap_cap_refs_in_kernel_window[wp]: "\<And>tp oref sz p dev cref.\<lbrace>cap_refs_in_kernel_window and cte_wp_at (\<lambda>c. cap_range (default_cap tp oref sz dev) \<subseteq> cap_range c) p\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. (cap_refs_in_kernel_window::'state_ext state \<Rightarrow> bool)\<rbrace>" assumes nonempty_default[simp]: "\<And>tp S us dev. tp \<noteq> Untyped \<Longrightarrow> \<not> nonempty_table S (default_object tp dev us)" assumes nonempty_table_caps_of: "\<And>S ko. nonempty_table S ko \<Longrightarrow> caps_of ko = {}" assumes init_arch_objects_nonempty_table: "\<lbrace>(\<lambda>s. \<not> (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s) \<and> valid_global_objs s \<and> valid_arch_state s \<and> pspace_aligned s) and K (\<forall>ref\<in>set refs. is_aligned ref (obj_bits_api tp us))\<rbrace> init_arch_objects tp ptr bits us refs \<lbrace>\<lambda>rv. \<lambda>s :: 'state_ext state. \<not> (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s)\<rbrace>" assumes create_cap_ioports[wp]: "\<And>tp oref sz dev cref p. \<lbrace>valid_ioports and cte_wp_at (\<lambda>_. True) cref\<rbrace> create_cap tp sz p dev (cref,oref) \<lbrace>\<lambda>rv (s::'state_ext state). valid_ioports s\<rbrace>" crunch v_ker_map[wp]: create_cap "valid_kernel_mappings" (simp: crunch_simps) crunch eq_ker_map[wp]: create_cap "equal_kernel_mappings" (simp: crunch_simps) lemma create_cap_asid_map[wp]: "\<lbrace>valid_asid_map\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_asid_map\<rbrace>" unfolding create_cap_def set_cdt_def by wpsimp crunch only_idle[wp]: create_cap only_idle (simp: crunch_simps) crunch pspace_in_kernel_window[wp]: create_cap "pspace_in_kernel_window" (simp: crunch_simps) lemma set_original_valid_ioc[wp]: "\<lbrace>valid_ioc\<rbrace> create_cap tp sz p dev slot \<lbrace>\<lambda>_. valid_ioc\<rbrace>" apply (cases slot) apply (wpsimp wp: set_cdt_cos_ioc set_cap_caps_of_state simp: create_cap_def set_original_set_cap_comm cte_wp_at_caps_of_state) apply (cases tp; simp) done interpretation create_cap: non_vspace_non_mem_op "create_cap tp sz p slot dev" apply (cases slot) apply (simp add: create_cap_def set_cdt_def) apply unfold_locales apply (rule hoare_pre, (wp set_cap.vsobj_at | wpc |simp add: create_cap_def set_cdt_def bind_assoc)+)+ done (* by (wp set_cap.vsobj_at | simp)+ *) (* ARMHYP might need this *) crunch valid_irq_states[wp]: create_cap "valid_irq_states" crunch pspace_respects_device_region[wp]: create_cap pspace_respects_device_region lemma cap_range_subseteq_weaken: "\<lbrakk>obj_refs c \<subseteq> untyped_range cap; untyped_range c \<subseteq> untyped_range cap\<rbrakk> \<Longrightarrow> cap_range c \<subseteq> cap_range cap" by (fastforce simp add: cap_range_def) lemma create_cap_refs_respects_device: "\<lbrace>cap_refs_respects_device_region and cte_wp_at (\<lambda>c. cap_is_device (default_cap tp oref sz dev) = cap_is_device c \<and>is_untyped_cap c \<and> cap_range (default_cap tp oref sz dev) \<subseteq> cap_range c) p\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv s. cap_refs_respects_device_region s\<rbrace>" apply (simp add: create_cap_def) apply (rule hoare_pre) apply (wp set_cap_cap_refs_respects_device_region hoare_vcg_ex_lift set_cdt_cte_wp_at | simp del: split_paired_Ex)+ apply (rule_tac x = p in exI) apply clarsimp apply (erule cte_wp_at_weakenE) apply (fastforce simp: is_cap_simps) done lemma (in Untyped_AI_nonempty_table) create_cap_invs[wp]: "\<lbrace>invs and cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_is_device (default_cap tp oref sz dev) = cap_is_device c \<and> obj_refs (default_cap tp oref sz dev) \<subseteq> untyped_range c \<and> untyped_range (default_cap tp oref sz dev) \<subseteq> untyped_range c \<and> untyped_range (default_cap tp oref sz dev) \<inter> usable_untyped_range c = {}) p and descendants_range (default_cap tp oref sz dev) p and cte_wp_at ((=) cap.NullCap) cref and valid_cap (default_cap tp oref sz dev) and ex_cte_cap_wp_to (appropriate_cte_cap (default_cap tp oref sz dev)) cref and real_cte_at cref and (\<lambda>(s::'state_ext state). \<forall>r\<in>obj_refs (default_cap tp oref sz dev). (\<forall>p'. \<not> cte_wp_at (\<lambda>cap. r \<in> obj_refs cap) p' s) \<and> \<not> obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s) and K (p \<noteq> cref \<and> tp \<noteq> ArchObject ASIDPoolObj)\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. invs\<rbrace>" apply (rule hoare_pre) apply (simp add: invs_def valid_state_def valid_pspace_def) apply (wp create_cap_refs_respects_device | simp add: valid_cap_def)+ apply clarsimp apply (clarsimp simp: cte_wp_at_caps_of_state valid_pspace_def) apply (frule_tac p1 = p in valid_cap_aligned[OF caps_of_state_valid]) apply simp apply (simp add: invs_def valid_state_def valid_pspace_def ) apply (simp add: cap_range_def) done lemma create_cap_ex_cap_to[wp]: "\<lbrace>ex_cte_cap_wp_to P p' and cte_wp_at ((=) cap.NullCap) cref\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. ex_cte_cap_wp_to P p'\<rbrace>" apply (simp add: create_cap_def) apply (wp set_cap_cte_cap_wp_to set_cdt_cte_wp_at | simp | wps set_cdt_irq_node)+ apply (clarsimp elim!: cte_wp_at_weakenE) done (* FIXME: move *) lemma hoare_vcg_split_lift[wp]: "\<lbrace>P\<rbrace> f x y \<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> case (x, y) of (a, b) \<Rightarrow> f a b \<lbrace>Q\<rbrace>" by simp lemma create_cap_no_cap[wp]: "\<lbrace>\<lambda>s. (\<forall>p'. \<not> cte_wp_at P p' s) \<and> \<not> P (default_cap tp oref sz dev)\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv s. \<forall>oref' cref'. \<not> cte_wp_at P (oref', cref') s\<rbrace>" unfolding create_cap_def cte_wp_at_caps_of_state by wpsimp lemma (in Untyped_AI_nonempty_table) create_cap_nonempty_tables[wp]: "\<lbrace>\<lambda>s. P (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) p s)\<rbrace> create_cap tp sz p' dev (cref, oref) \<lbrace>\<lambda>rv s. P (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) p s)\<rbrace>" apply (rule hoare_pre) apply (rule hoare_use_eq [where f=arch_state, OF create_cap_arch_state]) apply (simp add: create_cap_def set_cdt_def) apply (wp set_cap_obj_at_impossible|simp)+ apply (clarsimp simp: nonempty_table_caps_of) done lemma cap_range_not_untyped: "\<not> is_untyped_cap c \<Longrightarrow> cap_range c = obj_refs c" apply (case_tac c) apply (simp_all add: is_cap_simps cap_range_def) done lemma cap_range_inter_emptyI: "\<lbrakk>is_untyped_cap a = is_untyped_cap b; untyped_range a \<inter> untyped_range b ={}; obj_refs a \<inter> obj_refs b = {}\<rbrakk> \<Longrightarrow> cap_range a \<inter> cap_range b = {}" apply (case_tac "is_untyped_cap a") apply (simp_all add: cap_range_not_untyped) done lemma (in Untyped_AI_nonempty_table) create_caps_invs_inv: assumes create_cap_Q[wp]: "\<lbrace>invs and Q and cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_range (default_cap tp oref sz dev) \<subseteq> untyped_range c \<and> {oref .. oref + 2 ^ (obj_bits_api tp us) - 1} \<subseteq> untyped_range c) p and cte_wp_at ((=) NullCap) cref and valid_cap (default_cap tp oref sz dev)\<rbrace> create_cap tp sz p dev (cref,oref) \<lbrace>\<lambda>_. Q \<rbrace>" shows "\<lbrace>(\<lambda>s. invs (s::('state_ext::state_ext) state) \<and> Q s \<and> cte_wp_at (\<lambda>c. is_untyped_cap c \<and> obj_is_device tp dev = cap_is_device c) p s \<and> (\<forall>tup \<in> set ((cref,oref)#list). cte_wp_at (\<lambda>c. cap_range (default_cap tp (snd tup) sz dev) \<subseteq> untyped_range c \<and> {snd tup .. snd tup + 2 ^ (obj_bits_api tp us) - 1} \<subseteq> untyped_range c \<and> (untyped_range (default_cap tp (snd tup) sz dev) \<inter> usable_untyped_range c = {})) p s) \<and> (\<forall>tup \<in> set ((cref,oref)#list). descendants_range (default_cap tp (snd tup) sz dev) p s) \<and> distinct_sets (map (\<lambda>tup. cap_range (default_cap tp (snd tup) sz dev)) ((cref,oref)#list)) \<and> (\<forall>tup \<in> set ((cref,oref)#list). cte_wp_at ((=) cap.NullCap) (fst tup) s) \<and> (\<forall>tup \<in> set ((cref,oref)#list). valid_cap (default_cap tp (snd tup) sz dev) s) \<and> (\<forall>tup \<in> set ((cref,oref)#list). ex_cte_cap_wp_to is_cnode_cap (fst tup) s) \<and> (\<forall>tup \<in> set ((cref,oref)#list). real_cte_at (fst tup) s) \<and> (\<forall>tup \<in> set ((cref,oref)#list). \<forall>r \<in> obj_refs (default_cap tp (snd tup) sz dev). (\<forall>p'. \<not> cte_wp_at (\<lambda>cap. r \<in> Structures_A.obj_refs cap) p' s) \<and> \<not> obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s) \<and> distinct (p # (map fst ((cref,oref)#list))) \<and> tp \<noteq> ArchObject ASIDPoolObj) \<rbrace> create_cap tp sz p dev (cref,oref) \<lbrace>(\<lambda>r s. invs s \<and> Q s \<and> cte_wp_at (\<lambda>c. is_untyped_cap c \<and> obj_is_device tp dev = cap_is_device c) p s \<and> (\<forall>tup \<in> set list. cte_wp_at (\<lambda>c. cap_range (default_cap tp (snd tup) sz dev) \<subseteq> untyped_range c \<and> {snd tup .. snd tup + 2 ^ (obj_bits_api tp us) - 1} \<subseteq> untyped_range c \<and> (untyped_range (default_cap tp (snd tup) sz dev) \<inter> usable_untyped_range c = {})) p s) \<and> (\<forall>tup \<in> set list. descendants_range (default_cap tp (snd tup) sz dev) p s) \<and> distinct_sets (map (\<lambda>tup. cap_range (default_cap tp (snd tup) sz dev)) list) \<and> (\<forall>tup \<in> set list. cte_wp_at ((=) cap.NullCap) (fst tup) s) \<and> (\<forall>tup \<in> set list. valid_cap (default_cap tp (snd tup) sz dev) s) \<and> (\<forall>tup \<in> set list. ex_cte_cap_wp_to is_cnode_cap (fst tup) s) \<and> (\<forall>tup \<in> set list. real_cte_at (fst tup) s) \<and> (\<forall>tup \<in> set list. \<forall>r \<in> obj_refs (default_cap tp (snd tup) sz dev). (\<forall>p'. \<not> cte_wp_at (\<lambda>cap. r \<in> Structures_A.obj_refs cap) p' s) \<and> \<not> obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s) \<and> distinct (p # (map fst list)) \<and> tp \<noteq> ArchObject ASIDPoolObj) \<rbrace>" apply (rule hoare_pre) apply (wp hoare_vcg_const_Ball_lift | clarsimp)+ apply (clarsimp simp: conj_comms invs_mdb distinct_sets_prop distinct_prop_map ex_cte_cap_to_cnode_always_appropriate_strg) apply (simp add: cte_wp_at_caps_of_state[where p=p] | erule exE conjE)+ apply (intro conjI) apply (clarsimp simp:image_def) apply (drule(1) bspec)+ apply simp apply (fastforce simp:cap_range_def) apply (clarsimp simp:is_cap_simps) apply (simp only: UN_extend_simps UNION_empty_conv) apply (drule(1) bspec)+ apply clarsimp apply blast apply (clarsimp simp: cap_range_def) apply (clarsimp simp: cap_range_def) done lemma (in Untyped_AI_nonempty_table) create_caps_invs: assumes create_cap_Q[wp]: "\<And>cref oref. \<lbrace>invs and Q and cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_range (default_cap tp oref sz dev) \<subseteq> untyped_range c \<and> {oref .. oref + 2 ^ (obj_bits_api tp us) - 1} \<subseteq> untyped_range c) p and cte_wp_at ((=) NullCap) cref and valid_cap (default_cap tp oref sz dev) and K (cref \<in> set crefs \<and> oref \<in> set (retype_addrs ptr tp (length slots) us))\<rbrace> create_cap tp sz p dev (cref,oref) \<lbrace>\<lambda>_. Q \<rbrace>" shows "\<lbrace>(\<lambda>s. invs (s::('state_ext::state_ext) state) \<and> (Q::('state_ext::state_ext) state \<Rightarrow> bool) s \<and> cte_wp_at (\<lambda>c. is_untyped_cap c \<and> obj_is_device tp dev = cap_is_device c) p s \<and> (\<forall>tup \<in> set (zip crefs orefs). cte_wp_at (\<lambda>c. cap_range (default_cap tp (snd tup) sz dev) \<subseteq> untyped_range c \<and> {snd tup .. snd tup + 2 ^ (obj_bits_api tp us) - 1} \<subseteq> untyped_range c \<and> (untyped_range (default_cap tp (snd tup) sz dev) \<inter> usable_untyped_range c = {})) p s) \<and> (\<forall>tup \<in> set (zip crefs orefs). descendants_range (default_cap tp (snd tup) sz dev) p s) \<and> distinct_sets (map (\<lambda>tup. cap_range (default_cap tp (snd tup) sz dev)) (zip crefs orefs)) \<and> (\<forall>tup \<in> set (zip crefs orefs). cte_wp_at ((=) cap.NullCap) (fst tup) s) \<and> (\<forall>tup \<in> set (zip crefs orefs). valid_cap (default_cap tp (snd tup) sz dev) s) \<and> (\<forall>tup \<in> set (zip crefs orefs). ex_cte_cap_wp_to is_cnode_cap (fst tup) s) \<and> (\<forall>tup \<in> set (zip crefs orefs). real_cte_at (fst tup) s) \<and> (\<forall>tup \<in> set (zip crefs orefs). \<forall>r \<in> obj_refs (default_cap tp (snd tup) sz dev). (\<forall>p'. \<not> cte_wp_at (\<lambda>cap. r \<in> Structures_A.obj_refs cap) p' s) \<and> \<not> obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s) \<and> distinct (p # (map fst (zip crefs orefs))) \<and> tp \<noteq> ArchObject ASIDPoolObj) and K (set orefs \<subseteq> set (retype_addrs ptr tp (length slots) us))\<rbrace> mapM_x (create_cap tp sz p dev) (zip crefs orefs) \<lbrace>\<lambda>rv s. invs s \<and> Q s\<rbrace>" apply (rule hoare_gen_asm) apply (subgoal_tac "set (zip crefs orefs) \<subseteq> set crefs \<times> set (retype_addrs ptr tp (length slots) us)") prefer 2 apply (auto dest!: set_zip_helper)[1] apply (induct ("zip crefs orefs")) apply (simp add: mapM_x_def sequence_x_def) apply wpsimp apply (clarsimp simp add: mapM_x_def sequence_x_def) apply (rule hoare_seq_ext) apply assumption apply (thin_tac "valid a b c" for a b c) apply (rule hoare_pre) apply (rule hoare_strengthen_post) apply (rule_tac list=list and us=us in create_caps_invs_inv) apply (rule hoare_pre, rule create_cap_Q) apply (clarsimp | drule(1) bspec)+ done lemma retype_region_cte_at_other': "\<lbrace>pspace_no_overlap_range_cover ptr sz and cte_wp_at P p and valid_pspace and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev \<lbrace>\<lambda>rv. cte_wp_at P p\<rbrace>" apply (rule hoare_gen_asm) apply (wpsimp wp: retype_region_cte_at_other) done lemma retype_region_ex_cte_cap_to: "\<lbrace>pspace_no_overlap_range_cover ptr sz and ex_cte_cap_wp_to P p and valid_pspace and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev \<lbrace>\<lambda>rv. ex_cte_cap_wp_to P p\<rbrace>" apply (simp add: ex_cte_cap_wp_to_def) apply (wp hoare_vcg_ex_lift retype_region_cte_at_other' | wps retype_region_irq_node)+ apply auto done lemma retype_region_obj_ref_range: "\<lbrakk> \<And>r. \<lbrace>P r\<rbrace> retype_region ptr n us ty dev\<lbrace>\<lambda>rv. Q r\<rbrace> \<rbrakk> \<Longrightarrow> \<lbrace>(\<lambda>s. \<forall>r \<in> {ptr .. (ptr && ~~ mask sz) + 2 ^ sz - 1}. P r s) and K (range_cover ptr sz (obj_bits_api ty us) n)\<rbrace> retype_region ptr n us ty dev \<lbrace>\<lambda>rv s. \<forall>x \<in> set rv. \<forall>r \<in> obj_refs (default_cap tp x us dev). Q r s\<rbrace>" apply (rule hoare_gen_asm) apply (rule hoare_strengthen_post) apply (rule hoare_vcg_conj_lift [OF retype_region_ret, simplified]) apply (rule hoare_vcg_const_Ball_lift) apply assumption apply (clarsimp) apply (drule subsetD[OF obj_refs_default_cap]) apply (drule_tac x = ra in bspec) apply (simp add: ptr_add_def) apply (drule(1) range_cover_mem) apply simp apply simp done lemma retype_region_not_cte_wp_at: "\<lbrace>(\<lambda>s. \<not> cte_wp_at P p s) and valid_pspace and caps_overlap_reserved {ptr..ptr + of_nat n * 2 ^ obj_bits_api tp us - 1} and valid_mdb and pspace_no_overlap_range_cover ptr sz and caps_no_overlap ptr sz and (\<lambda>s. \<exists>cref. cte_wp_at (\<lambda>c. up_aligned_area ptr sz \<subseteq> cap_range c \<and> cap_is_device c = dev) cref s) and K (\<not> P cap.NullCap \<and> (tp = CapTableObject \<longrightarrow> 0 < us) \<and> range_cover ptr sz (obj_bits_api tp us) n)\<rbrace> retype_region ptr n us tp dev \<lbrace>\<lambda>rv s. \<not> cte_wp_at P p s\<rbrace>" apply (rule hoare_gen_asm) apply (clarsimp simp: P_null_filter_caps_of_cte_wp_at[symmetric]) apply (wpsimp wp: retype_region_caps_of) apply auto done lemma retype_region_refs_distinct[wp]: "\<lbrace>K (range_cover ptr sz (obj_bits_api tp us) n)\<rbrace> retype_region ptr n us tp dev \<lbrace>\<lambda>rv s. distinct_prop (\<lambda>x y. obj_refs (default_cap tp (snd x) us dev) \<inter> obj_refs (default_cap tp (snd y) us dev) = {}) (zip xs rv)\<rbrace>" apply simp apply (rule hoare_gen_asm[where P'="\<top>", simplified]) apply (rule hoare_strengthen_post [OF retype_region_ret]) apply (subst distinct_prop_map[symmetric, where f=snd]) apply (rule distinct_prop_prefixE [OF _ map_snd_zip_prefix [unfolded less_eq_list_def]]) apply (clarsimp simp: retype_addrs_def distinct_prop_map word_unat_power[symmetric] power_sub[symmetric] power_add[symmetric] mult.commute | rule conjI distinct_prop_distinct [where xs="upt a b" for a b] set_eqI diff_le_mono | erule(3) ptr_add_distinct_helper ptr_add_distinct_helper [OF _ not_sym] | drule subsetD [OF obj_refs_default_cap] less_two_pow_divD)+ apply (simp add: range_cover_def word_bits_def) apply (erule range_cover.range_cover_n_le[where 'a=machine_word_len]) done lemma unsafe_protected: "\<lbrakk> cte_wp_at P p s; cte_wp_at ((=) (cap.UntypedCap dev ptr bits idx)) p' s; descendants_range_in S p' s; invs s; S \<subseteq> untyped_range (cap.UntypedCap dev ptr bits idx); \<And>cap. P cap \<Longrightarrow> cap \<noteq> cap.NullCap \<rbrakk> \<Longrightarrow> fst p \<notin> S" apply (rule ex_cte_cap_protects) apply (erule if_unsafe_then_capD) apply (clarsimp simp: invs_def valid_state_def) apply simp apply assumption+ apply clarsimp+ done lemma cap_to_protected: "\<lbrakk> ex_cte_cap_wp_to P p s; cte_wp_at ((=) (cap.UntypedCap dev ptr bits idx)) p' s; descendants_range (cap.UntypedCap dev ptr bits idx) p' s; invs s \<rbrakk> \<Longrightarrow> ex_cte_cap_wp_to P p (detype {ptr .. ptr + 2 ^ bits - 1} s)" apply (clarsimp simp: ex_cte_cap_wp_to_def, simp add: detype_def descendants_range_def2) apply (intro exI conjI, assumption) apply (case_tac "a = fst p") apply (frule(1) ex_cte_cap_protects [rotated,where P=P]) apply clarsimp+ apply (simp add: ex_cte_cap_wp_to_def) apply fastforce+ apply (drule(2) unsafe_protected[rotated]) apply simp+ apply (clarsimp simp: cte_wp_at_caps_of_state) apply auto done lemma valid_cap_aligned: "valid_cap cap s \<Longrightarrow> cap_aligned cap" by (simp add: valid_cap_def) crunch irq_node[wp]: do_machine_op "\<lambda>s. P (interrupt_irq_node s)" (* FIXME: move *) lemma ge_mask_eq: "len_of TYPE('a) \<le> n \<Longrightarrow> (x::'a::len word) && mask n = x" by (simp add: mask_def p2_eq_0[THEN iffD2]) (* FIXME: replace do_machine_op_obj_at in KHeap_R by the lemma below *) lemma do_machine_op_obj_at_arch_state[wp]: "\<lbrace>\<lambda>s. P (obj_at (Q (arch_state s)) p s)\<rbrace> do_machine_op f \<lbrace>\<lambda>_ s. P (obj_at (Q (arch_state s)) p s)\<rbrace>" by (clarsimp simp: do_machine_op_def split_def | wp)+ lemma (in Untyped_AI_nonempty_table) retype_nonempty_table[wp]: "\<lbrace>\<lambda>(s::('state_ext::state_ext) state). \<not> (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s)\<rbrace> retype_region ptr sz us tp dev \<lbrace>\<lambda>rv s. \<not> (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s)\<rbrace>" apply (simp add: retype_region_def split del: if_split) apply (rule hoare_pre) apply (wp|simp del: fun_upd_apply)+ apply (clarsimp simp del: fun_upd_apply) apply (simp add: foldr_upd_app_if) apply (clarsimp simp: obj_at_def split: if_split_asm) done lemma invs_arch_state_strg: "invs s \<longrightarrow> valid_arch_state s" by (clarsimp simp: invs_def valid_state_def) lemma invs_psp_aligned_strg: "invs s \<longrightarrow> pspace_aligned s" by (clarsimp simp: invs_def valid_state_def) (* FIXME: move *) lemma invs_cap_refs_in_kernel_window[elim!]: "invs s \<Longrightarrow> cap_refs_in_kernel_window s" by (simp add: invs_def valid_state_def) lemma (in Untyped_AI_nonempty_table) set_cap_nonempty_tables[wp]: "\<lbrace>\<lambda>s. P (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) p s)\<rbrace> set_cap cap cref \<lbrace>\<lambda>rv s. P (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) p s)\<rbrace>" apply (rule hoare_pre) apply (rule hoare_use_eq [where f=arch_state, OF set_cap_arch]) apply (wp set_cap_obj_at_impossible) apply (clarsimp simp: nonempty_table_caps_of) done lemma ex_cte_cap_wp_to_def_msu[simp]: "ex_cte_cap_wp_to P x (machine_state_update f s) = ex_cte_cap_wp_to P x s" by (simp add: ex_cte_cap_wp_to_def) lemma (in Untyped_AI_arch) retype_region_caps_reserved: "\<lbrace>cte_wp_at (is_untyped_cap) p and caps_overlap_reserved {ptr..ptr + of_nat (n * 2 ^ obj_bits_api tp us) - 1} and K (range_cover ptr sz (obj_bits_api tp us) n) and pspace_no_overlap_range_cover ptr sz and valid_pspace \<rbrace> retype_region ptr n us tp dev \<lbrace>\<lambda>rv (s::('state_ext::state_ext) state). \<forall>y\<in>set rv. cte_wp_at (\<lambda>a. untyped_range (default_cap tp y us dev) \<inter> usable_untyped_range a = {}) p s\<rbrace>" apply (clarsimp simp: valid_def cte_wp_at_caps_of_state) apply (frule use_valid[OF _ retype_region_ranges']) apply fastforce apply (drule(1) bspec) apply (frule_tac P1 = "(=) cap" in use_valid[OF _ retype_region_cte_at_other]) apply simp+ apply (fastforce simp: cte_wp_at_caps_of_state) apply (clarsimp simp: cte_wp_at_caps_of_state caps_overlap_reserved_def) apply (drule bspec) apply fastforce apply (clarsimp simp: cap_range_def) apply blast done lemma untyped_mdb_descendants_range: "\<lbrakk>caps_of_state s p = Some ucap; is_untyped_cap ucap; valid_mdb s; descendants_range_in S p s; S \<subseteq> untyped_range ucap; caps_of_state s slot = Some cap; x\<in> obj_refs cap \<rbrakk>\<Longrightarrow> x\<notin> S" apply (clarsimp simp: valid_mdb_def) apply (drule untyped_mdbD) apply simp+ apply (rule ccontr) apply (clarsimp) apply blast apply simp apply (drule(2) descendants_range_inD) apply (simp add: cap_range_def,blast) done lemma global_refs_detype[simp]: "global_refs (detype S s) = global_refs s" by (simp add: detype_def) lemma ex_cte_cap_wp_to_clear_um[simp]: "ex_cte_cap_wp_to P p (clear_um T s) = ex_cte_cap_wp_to P p s" by (clarsimp simp: ex_cte_cap_wp_to_def clear_um_def) locale Untyped_AI = Untyped_AI_of_bl_nat_to_cref + Untyped_AI_arch state_ext_t + Untyped_AI_nonempty_table state_ext_t nonempty_table for state_ext_t :: "'state_ext :: state_ext itself" and nonempty_table lemma set_cap_device_and_range: "\<lbrace>\<top>\<rbrace> set_cap (UntypedCap dev (ptr && ~~ mask sz) sz idx) aref \<lbrace>\<lambda>rv s. (\<exists>slot. cte_wp_at (\<lambda>c. cap_is_device c = dev \<and> up_aligned_area ptr sz \<subseteq> cap_range c) slot s)\<rbrace>" apply (rule hoare_pre) apply (clarsimp simp: cte_wp_at_caps_of_state simp del: split_paired_All split_paired_Ex) apply (wp set_cap_cte_wp_at' hoare_vcg_ex_lift) apply (rule_tac x="aref" in exI) apply (auto intro: word_and_le2 simp: p_assoc_help) done lemma set_free_index_invs_UntypedCap: "\<lbrace>\<lambda>s. invs s \<and> (\<exists>cap. free_index_of cap \<le> idx \<and> is_untyped_cap cap \<and> idx \<le> 2^cap_bits cap \<and> free_index_update (\<lambda>_. idx) cap = UntypedCap dev ptr sz idx \<and> cte_wp_at ((=) cap) cref s)\<rbrace> set_cap (UntypedCap dev ptr sz idx) cref \<lbrace>\<lambda>rv s'. invs s'\<rbrace>" apply (rule hoare_name_pre_state) apply clarsimp apply (cut_tac cap=cap and idx=idx in set_free_index_invs) apply clarsimp apply (erule hoare_pre) apply (clarsimp simp: cte_wp_at_caps_of_state) apply (case_tac cap, simp_all add: free_index_of_def) done lemma monadic_rewrite_state_assert_true: "monadic_rewrite F E P (state_assert P) (return ())" by (simp add: state_assert_def monadic_rewrite_def exec_get) lemma retype_region_aligned_for_init_sz: "\<lbrace>\<lambda>s. range_cover ptr sz (obj_bits_api new_type obj_sz) n \<and> obj_bits_api new_type obj_sz = some_us_sz\<rbrace> retype_region ptr n obj_sz new_type is_dev \<lbrace>\<lambda>rv s. \<forall>ref \<in> set rv. is_aligned ref some_us_sz\<rbrace>" apply (rule hoare_name_pre_state) apply (rule hoare_pre, rule hoare_strengthen_post, rule retype_region_aligned_for_init, auto) done lemma (in strengthen_implementation) strengthen_Not[strg]: "\<lbrakk> st (\<not> F) (\<longrightarrow>) P P' \<rbrakk> \<Longrightarrow> st F (\<longrightarrow>) (\<not> P) (\<not> P')" by (cases F, auto) lemma retype_region_ret_folded_general: "\<lbrace>\<lambda>s. P (retype_addrs y ty n bits)\<rbrace> retype_region y n bits ty dev \<lbrace>\<lambda>r s. P r\<rbrace>" apply (rule hoare_name_pre_state) apply (rule hoare_pre, rule hoare_strengthen_post, rule retype_region_ret_folded, auto) done lemma retype_region_post_retype_invs_folded: "\<lbrace>P\<rbrace> retype_region y n bits ty dev \<lbrace>\<lambda>r. post_retype_invs ty r\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> retype_region y n bits ty dev \<lbrace>\<lambda>r. post_retype_invs ty (retype_addrs y ty n bits)\<rbrace>" apply (rule hoare_strengthen_post, rule hoare_vcg_conj_lift[OF retype_region_ret_folded, simplified], assumption) apply clarsimp done lemma tup_in_fst_image_set_zipD: "x \<in> fst ` set (zip xs ys) \<Longrightarrow> x \<in> set xs" by (auto dest!: set_zip_helper) lemma distinct_map_fst_zip: "distinct xs \<Longrightarrow> distinct (map fst (zip xs ys))" apply (induct xs arbitrary: ys, simp_all) apply (case_tac ys, simp_all) apply (metis tup_in_fst_image_set_zipD) done lemma retype_region_ranges_obj_bits_api: "\<lbrace>cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_bits c = sz \<and> obj_ref_of c = ptr && ~~ mask sz) p and pspace_no_overlap_range_cover ptr sz and valid_pspace and K (range_cover ptr sz (obj_bits_api tp us) n) \<rbrace> retype_region ptr n us tp dev \<lbrace>\<lambda>rv s. \<forall>y\<in>set rv. cte_wp_at (\<lambda>c. {y .. y + 2 ^ (obj_bits_api tp us) - 1} \<subseteq> untyped_range c ) p s\<rbrace>" apply (clarsimp simp:cte_wp_at_caps_of_state valid_def) apply (frule_tac P1 = "(=) cap" in use_valid[OF _ retype_region_cte_at_other]) apply simp apply (fastforce simp:cte_wp_at_caps_of_state) apply (clarsimp simp:cte_wp_at_caps_of_state del: subsetI) apply (frule use_valid[OF _ retype_region_ret_folded], simp+) apply (rule order_trans, erule(1) retype_addrs_range_subset) apply (clarsimp simp: is_cap_simps word_and_le2 del: subsetI) done context Untyped_AI begin lemma invoke_untyp_invs': assumes create_cap_Q: "\<And>tp sz cref slot oref reset ptr us slots dev. ui = Invocations_A.Retype slot reset (ptr && ~~ mask sz) ptr tp us slots dev \<Longrightarrow> \<lbrace>invs and Q and cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_range (default_cap tp oref us dev) \<subseteq> untyped_range c \<and> {oref .. oref + 2 ^ (obj_bits_api tp us) - 1} \<subseteq> untyped_range c) slot and cte_wp_at ((=) NullCap) cref and K (cref \<in> set slots \<and> oref \<in> set (retype_addrs ptr tp (length slots) us)) and K (range_cover ptr sz (obj_bits_api tp us) (length slots))\<rbrace> create_cap tp us slot dev (cref,oref) \<lbrace>\<lambda>_. Q\<rbrace>" assumes init_arch_Q: "\<And>tp slot reset sz slots ptr n us refs dev. ui = Invocations_A.Retype slot reset (ptr && ~~ mask sz) ptr tp us slots dev \<Longrightarrow> \<lbrace>Q and post_retype_invs tp refs and cte_wp_at (\<lambda>c. \<exists>idx. c = cap.UntypedCap dev (ptr && ~~ mask sz) sz idx) slot and K (refs = retype_addrs ptr tp n us \<and> range_cover ptr sz (obj_bits_api tp us) n)\<rbrace> init_arch_objects tp ptr n us refs \<lbrace>\<lambda>_. Q\<rbrace>" assumes retype_region_Q: "\<And>ptr us tp slot reset sz slots dev. ui = Invocations_A.Retype slot reset (ptr && ~~ mask sz) ptr tp us slots dev \<Longrightarrow> \<lbrace>\<lambda>s. invs s \<and> Q s \<and> cte_wp_at (\<lambda>c. \<exists>idx. c = cap.UntypedCap dev (ptr && ~~ mask sz) sz idx) slot s \<and> pspace_no_overlap {ptr..(ptr && ~~ mask sz) + (2 ^ sz - 1)} s \<and> range_cover ptr sz (obj_bits_api tp us) (length slots) \<and> (tp = CapTableObject \<longrightarrow> 0 < us) \<and> caps_overlap_reserved {ptr..ptr + of_nat ((length slots) * 2 ^ obj_bits_api tp us) - 1} s \<and> caps_no_overlap ptr sz s \<rbrace> retype_region ptr (length slots) us tp dev \<lbrace>\<lambda>_.Q\<rbrace>" assumes set_cap_Q[wp]: "\<And>ptr sz idx cref dev. \<lbrace>\<lambda>s. Q s \<and> invs s \<and> cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_bits c = sz \<and> obj_ref_of c = ptr) cref s \<and> (case ui of Invocations_A.Retype slot reset ptr' ptr tp us slots dev' \<Rightarrow> cref = slot \<and> dev' = dev) \<and> idx \<le> 2^ sz\<rbrace> set_cap (cap.UntypedCap dev ptr sz idx) cref \<lbrace>\<lambda>rv. Q\<rbrace>" assumes reset_Q: "\<lbrace>Q'\<rbrace> reset_untyped_cap (case ui of Retype src_slot _ _ _ _ _ _ _ \<Rightarrow> src_slot) \<lbrace>\<lambda>_. Q\<rbrace>" shows "\<lbrace>(invs ::'state_ext state \<Rightarrow> bool) and (\<lambda>s. (case ui of Retype _ reset _ _ _ _ _ _ \<Rightarrow> reset) \<longrightarrow> Q' s) and Q and valid_untyped_inv ui and ct_active\<rbrace> invoke_untyped ui \<lbrace>\<lambda>rv s. invs s \<and> Q s\<rbrace>, \<lbrace>\<lambda>_ s. invs s \<and> Q s\<rbrace>" apply (cases ui) apply (rule hoare_name_pre_stateE) apply (clarsimp simp only: valid_untyped_inv_wcap untyped_invocation.simps) proof - fix cref oref reset ptr_base ptr tp us slots s sz idx dev assume ui: "ui = Retype (cref, oref) reset ptr_base ptr tp us slots dev" assume Q: "Q s" and Q': "reset \<longrightarrow> Q' s" assume invs: "invs s" "ct_active s" assume vui: "valid_untyped_inv_wcap (Retype (cref, oref) reset ptr_base ptr tp us slots dev) (Some (UntypedCap dev (ptr && ~~ mask sz) sz idx)) s" (is "valid_untyped_inv_wcap _ (Some ?orig_cap) s") have cte_at: "cte_wp_at ((=) ?orig_cap) (cref,oref) s" (is "?cte_cond s") using vui by (clarsimp simp add:cte_wp_at_caps_of_state) note blah[simp del] = untyped_range.simps usable_untyped_range.simps atLeastAtMost_iff atLeastatMost_subset_iff atLeastLessThan_iff Int_atLeastAtMost atLeastatMost_empty_iff split_paired_Ex note neg_mask_add_mask = word_plus_and_or_coroll2[symmetric,where w = "mask sz" and t = ptr,symmetric] have p_neq_0:"ptr \<noteq> 0" using cte_at invs apply (clarsimp simp:cte_wp_at_caps_of_state) apply (drule(1) caps_of_state_valid)+ apply (simp add:valid_cap_def) done have cover: "range_cover ptr sz (obj_bits_api tp us) (length slots)" using vui by (clarsimp simp:cte_wp_at_caps_of_state) note neg_mask_add_mask = word_plus_and_or_coroll2[symmetric,where w = "mask sz" and t = ptr,symmetric] note set_cap_free_index_invs_spec = set_free_index_invs[where cap = "cap.UntypedCap dev (ptr && ~~ mask sz) sz (if reset then 0 else idx)", unfolded free_index_update_def free_index_of_def,simplified] have slot_not_in: "(cref, oref) \<notin> set slots" using vui cte_at by (auto simp: cte_wp_at_caps_of_state) note reset_Q' = reset_Q[simplified ui, simplified] have ptr_base: "ptr_base = ptr && ~~ mask sz" using vui by (clarsimp simp: cte_wp_at_caps_of_state) note ui' = ui[unfolded ptr_base] note msimp[simp] = neg_mask_add_mask let ?ui = "Retype (cref, oref) reset ptr_base ptr tp us slots dev" show "\<lbrace>(=) s\<rbrace> invoke_untyped ?ui \<lbrace>\<lambda>rv s. invs s \<and> Q s\<rbrace>, \<lbrace>\<lambda>_ s. invs s \<and> Q s\<rbrace>" using cover apply (simp add:mapM_x_def[symmetric] invoke_untyped_def) apply (rule_tac B="\<lambda>_ s. invs s \<and> Q s \<and> ct_active s \<and> valid_untyped_inv_wcap ?ui (Some (UntypedCap dev (ptr && ~~ mask sz) sz (if reset then 0 else idx))) s \<and> (reset \<longrightarrow> pspace_no_overlap {ptr && ~~ mask sz..(ptr && ~~ mask sz) + 2 ^ sz - 1} s) " in hoare_vcg_seqE[rotated]) apply (simp only: whenE_def) apply (rule hoare_pre, wp) apply (rule hoare_post_impErr, rule combine_validE, rule reset_untyped_cap_invs_etc, rule valid_validE, rule reset_Q') apply (clarsimp simp only: pred_conj_def if_True, blast) apply (wp | simp)+ apply (cut_tac vui Q Q' invs) apply (clarsimp simp: cte_wp_at_caps_of_state slot_not_in) apply blast apply (simp add: cte_wp_at_conj ball_conj_distrib split del: if_split | wp hoare_vcg_const_Ball_lift set_tuple_pick retype_region_ex_cte_cap_to [where sz = sz] retype_region_obj_ref_range [where sz = sz] hoare_vcg_all_lift [of _ _ "%a _ p. \<forall>b. ~ cte_wp_at P (a,b) p" for P] hoare_vcg_all_lift [of _ _ "%b _ p. ~ cte_wp_at P (a,b) p" for P a] retype_region_not_cte_wp_at [where sz = sz] init_arch_objects_invs_from_restricted retype_ret_valid_caps [where sz = sz] retype_region_global_refs_disjoint [where sz = sz] retype_region_post_retype_invs [where sz = sz] retype_region_cte_at_other[where sz = sz] retype_region_invs_extras[where sz = sz] retype_region_ranges [where sz = sz] retype_region_ranges_obj_bits_api[where sz=sz] retype_region_caps_reserved [where sz = sz] retype_region_distinct_sets [where sz = sz] create_caps_invs[where ptr=ptr and slots=slots and us=us] create_cap_Q[OF ui'] init_arch_Q[OF ui'] retype_region_Q[OF ui'] retype_region_descendants_range_ret[where sz = sz] retype_region_obj_at_other2 [where P="is_cap_table n" for n] distinct_tuple_helper init_arch_objects_wps init_arch_objects_nonempty_table | wp (once) retype_region_ret_folded_general)+ apply ((wp hoare_vcg_const_imp_lift hoare_drop_imp retype_region_invs_extras[where sz = sz] retype_region_aligned_for_init[where sz = sz] set_free_index_invs_UntypedCap set_cap_caps_no_overlap set_cap_no_overlap set_untyped_cap_caps_overlap_reserved | strengthen tup_in_fst_image_set_zipD[mk_strg D] distinct_map_fst_zip | simp add: ptr_base | wp (once) retype_region_ret_folded_general)+)[1] apply (clarsimp simp:conj_comms,simp cong:conj_cong) apply (simp add:ball_conj_distrib conj_comms) apply (strengthen invs_mdb invs_valid_pspace caps_region_kernel_window_imp[where p="(cref, oref)"] invs_cap_refs_in_kernel_window exI[where x="(cref, oref)"] | clarsimp simp: conj_comms | simp cong: conj_cong)+ apply (rule_tac P = "bits_of cap = sz" in hoare_gen_asm) apply (simp add:bits_of_def) apply (wp set_cap_no_overlap hoare_vcg_ball_lift set_free_index_invs_UntypedCap set_cap_cte_wp_at set_cap_descendants_range_in set_cap_caps_no_overlap set_untyped_cap_caps_overlap_reserved[where idx="if reset then 0 else idx"] set_cap_cte_cap_wp_to hoare_vcg_ex_lift | wp (once) hoare_drop_imps)+ apply (wp set_cap_cte_wp_at_neg hoare_vcg_all_lift get_cap_wp)+ apply (clarsimp simp: slot_not_in field_simps ui free_index_of_def split del: if_split) apply ((strengthen cover refl)+)? apply (simp only: cte_wp_at_caps_of_state, clarify, simp only: option.simps, simp(no_asm_use) split del: if_split, clarify) apply (clarsimp simp: bits_of_def untyped_range.simps if_split[where P="\<lambda>v. v \<le> unat x" for x]) apply (frule(1) valid_global_refsD2[OF _ invs_valid_global_refs]) apply (clarsimp simp:cte_wp_at_caps_of_state untyped_range.simps conj_comms split del: if_split) apply (frule invoke_untyped_proofs.intro[where cref="(cref, oref)" and reset=reset, rotated 1], simp_all add: cte_wp_at_caps_of_state split del: if_split) apply (rule conjI, (rule refl | assumption))+ apply clarsimp apply (simp add: invoke_untyped_proofs.simps p_neq_0) apply (simp add: arg_cong[OF mask_out_sub_mask, where f="\<lambda>y. x - y" for x] field_simps invoke_untyped_proofs.idx_le_new_offs invoke_untyped_proofs.idx_compare' exI invoke_untyped_proofs.simps word_bw_assocs) apply (frule cte_wp_at_pspace_no_overlapI, simp add: cte_wp_at_caps_of_state, simp+, simp add: invoke_untyped_proofs.szw) apply (cut_tac s=s in obj_is_device_vui_eq[where ui=ui]) apply (clarsimp simp: ui cte_wp_at_caps_of_state) apply (simp_all add: field_simps ui) apply (intro conjI) (* slots not in retype_addrs *) apply (clarsimp dest!:retype_addrs_subset_ptr_bits) apply (drule(1) invoke_untyped_proofs.slots_invD) apply (drule(1) subsetD) apply (simp add:p_assoc_help) (* not global refs*) apply (simp add: Int_commute, erule disjoint_subset2[rotated]) apply (simp add: atLeastatMost_subset_iff word_and_le2) (* idx less_eq new offs *) apply (auto dest: invoke_untyped_proofs.idx_le_new_offs)[1] (* not empty tables *) apply clarsimp apply (drule(1) pspace_no_overlap_obj_not_in_range, clarsimp+)[1] (* set ineqs *) apply (simp add: atLeastatMost_subset_iff word_and_le2) apply (erule order_trans[OF invoke_untyped_proofs.subset_stuff]) apply (simp add: atLeastatMost_subset_iff word_and_le2) (* new untyped range disjoint *) apply (drule invoke_untyped_proofs.usable_range_disjoint) apply (clarsimp simp: field_simps mask_out_sub_mask shiftl_t2n) (* something about caps *) apply clarsimp apply (frule untyped_mdb_descendants_range, clarsimp+, erule invoke_untyped_proofs.descendants_range, simp_all+)[1] apply (simp add: untyped_range_def atLeastatMost_subset_iff word_and_le2) done qed lemmas invoke_untyp_invs[wp] = invoke_untyp_invs'[where Q=\<top> and Q'=\<top>, simplified, simplified hoare_post_taut, simplified] lemmas invoke_untyped_Q = invoke_untyp_invs'[THEN validE_valid, THEN hoare_conjD2[unfolded pred_conj_def]] lemma invoke_untyped_st_tcb_at[wp]: "\<lbrace>invs and st_tcb_at (P and (Not \<circ> inactive) and (Not \<circ> idle)) t and ct_active and valid_untyped_inv ui\<rbrace> invoke_untyped ui \<lbrace>\<lambda>rv. \<lambda>s :: 'state_ext state. st_tcb_at P t s\<rbrace>" apply (rule hoare_pre, rule invoke_untyped_Q, (wp init_arch_objects_wps | simp)+) apply (rule hoare_name_pre_state, clarsimp) apply (wp retype_region_st_tcb_at, auto)[1] apply (wp reset_untyped_cap_st_tcb_at | simp)+ apply (cases ui, clarsimp) apply (strengthen st_tcb_weakenE[mk_strg I E], clarsimp) apply (frule(1) st_tcb_ex_cap[OF _ invs_iflive]) apply (clarsimp split: Structures_A.thread_state.splits) apply (drule ex_nonz_cap_to_overlap, ((simp add:cte_wp_at_caps_of_state is_cap_simps descendants_range_def2 empty_descendants_range_in)+)) done lemma invoked_untyp_tcb[wp]: "\<lbrace>invs and st_tcb_at active tptr and valid_untyped_inv ui and ct_active\<rbrace> invoke_untyped ui \<lbrace>\<lambda>rv. \<lambda>s :: 'state_ext state. tcb_at tptr s\<rbrace>" apply (simp add: tcb_at_st_tcb_at) apply (rule hoare_pre, wp invoke_untyped_st_tcb_at) apply (clarsimp elim!: pred_tcb_weakenE) apply fastforce done end lemma sts_mdb[wp]: "\<lbrace>\<lambda>s. P (cdt s)\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv s. P (cdt s)\<rbrace>" by (simp add: set_thread_state_def | wp)+ lemma sts_ex_cap[wp]: "\<lbrace>ex_cte_cap_wp_to P p\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv. ex_cte_cap_wp_to P p\<rbrace>" by (wp ex_cte_cap_to_pres) lemmas sts_real_cte_at[wp] = cap_table_at_lift_valid [OF set_thread_state_typ_at] lemma sts_valid_untyped_inv: "\<lbrace>valid_untyped_inv ui\<rbrace> set_thread_state t st \<lbrace>\<lambda>rv. valid_untyped_inv ui\<rbrace>" apply (cases ui, simp add: descendants_range_in_def) apply (wp hoare_vcg_const_Ball_lift hoare_vcg_ex_lift hoare_vcg_imp_lift | wps)+ apply clarsimp done lemma update_untyped_cap_valid_objs: "\<lbrace> valid_objs and valid_cap cap and cte_wp_at (is_untyped_cap) p and K (is_untyped_cap cap)\<rbrace> set_cap cap p \<lbrace> \<lambda>rv. valid_objs \<rbrace>" apply (wp set_cap_valid_objs) apply (clarsimp simp: is_cap_simps cte_wp_at_caps_of_state) apply (drule tcb_cap_valid_caps_of_stateD, simp+) apply (simp add: tcb_cap_valid_untyped_to_thread) done lemma valid_untyped_pspace_no_overlap: "pspace_no_overlap {ptr .. ptr + 2 ^ sz - 1} s \<Longrightarrow> valid_untyped (cap.UntypedCap dev ptr sz idx) s" apply (clarsimp simp: valid_untyped_def split del: if_split) apply (drule(1) pspace_no_overlap_obj_range) apply simp done (* FIXME: move *) lemma snd_set_zip_in_set: "x\<in> snd ` set (zip a b) \<Longrightarrow> x\<in> set b" apply (clarsimp) apply (erule in_set_zipE) apply simp done end
## -------->> [[file:../../nstandr.src.org::*Complex conditions][Complex conditions:2]] expect_equal(data.table(org = c(" EVIL FOUND OF BIG CORP " , " EVIL FOUND OF BIG CORP " , " INT INST OF MAGIC" , " COUNCIL OF PARANORMAL RES & DEV " , " COUNCIL OF GROWN UP KIDS ") , org_entity_type = list(c("univ", "gov"), NA, "univ", NA, "gov")) |> cockburn_detect_inst_conds_2() , structure(list(org = c(" EVIL FOUND OF BIG CORP ", " EVIL FOUND OF BIG CORP ", " INT INST OF MAGIC", " COUNCIL OF PARANORMAL RES & DEV ", " COUNCIL OF GROWN UP KIDS " ), org_entity_type = list(c("univ", "gov"), "inst", "univ", NA_character_, "gov")), row.names = c(NA, -5L), class = c("data.table", "data.frame"))) expect_equal(data.table(name = c("MÄKARÖNI ETÖ FKÜSNÖ Ltd" , "MSLab CÖ. <a href=lsdldf> <br> <\\a>" , "MSLab Co." , "MSLaeb Comp." , " INST OF PARANORMAL RES & DEV " , "MSLab Comp. Ltd." , "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŸ") , foo = "I love coffee") |> cockburn_detect_inst_conds(merge_existing_codes = "append_to_existing") , structure(list(name = c("MÄKARÖNI ETÖ FKÜSNÖ Ltd", "MSLab CÖ. <a href=lsdldf> <br> <\\a>", "MSLab Co.", "MSLaeb Comp.", " INST OF PARANORMAL RES & DEV ", "MSLab Comp. Ltd.", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŸ" ), foo = c("I love coffee", "I love coffee", "I love coffee", "I love coffee", "I love coffee", "I love coffee", "I love coffee" ), name_entity_type = c(NA, NA, NA, NA, "inst", NA, NA)), row.names = c(NA, -7L), class = c("data.table", "data.frame"))) expect_equal(data.table(org = c(" DR VLASOV " , " S.VLASOV PHD " , " STANICA LEGALY REPRESENTED BY STAS INST " , " INST DR VLASOV & BROTHER " , "MSlab & C" , "LEGALY REPRESENTED BY STAS" , " REPUBLIC LEGALY REPRESENTED BY STAS" , " TILBURG UNIVERSTIY " , " VU UNIVERSTITAET " , " FUNDATION LEGALY REPRESENTED BY STAS") , org_entity_type = list(c("univ", "gov"), NA, "univ", NA, "gov")) |> cockburn_detect_inst_conds() , structure(list(org = c(" DR VLASOV ", " S.VLASOV PHD ", " STANICA LEGALY REPRESENTED BY STAS INST ", " INST DR VLASOV & BROTHER ", "MSlab & C", "LEGALY REPRESENTED BY STAS", " REPUBLIC LEGALY REPRESENTED BY STAS", " TILBURG UNIVERSTIY ", " VU UNIVERSTITAET ", " FUNDATION LEGALY REPRESENTED BY STAS" ), org_entity_type = list(c("univ", "gov"), NA_character_, "univ", "inst", "gov", c("univ", "gov"), NA_character_, "univ", NA_character_, "gov")), row.names = c(NA, -10L), class = c("data.table", "data.frame"))) ## --------<< Complex conditions:2 ends here
import copy import numpy as np class Oracle(): """ Base class for all objectives. Can provide objective values, gradients and its Hessians as functions that take parameters as input. Takes as input the values of l1 and l2 regularization. """ def __init__(self, l1=0, l2=0): if l1 < 0.0: raise ValueError("Invalid value for l1 regularization: {}".format(l1)) if l2 < 0.0: raise ValueError("Invalid value for l2 regularization: {}".format(l2)) self.l1 = l1 self.l2 = l2 self.x_opt = None self.f_opt = np.inf def value(self, x): value = self.value_(x) if value < self.f_opt: self.x_opt = copy.deepcopy(x) self.f_opt = value return value def gradient(self, x): pass def hessian(self, x): pass def norm(self, x): pass def inner_prod(self, x, y): pass def hess_vec_prod(self, x, v, grad_dif=False, eps=None): pass def smoothness(self): pass def max_smoothness(self): pass def average_smoothness(self): pass def batch_smoothness(self, batch_size): pass
= = = San Leonardo = = =
State Before: α : Type u β : Type v γ : Type ?u.534439 δ : Type ?u.534442 ε : Type ?u.534445 ζ : Type ?u.534448 ι : Type u_1 κ : Type u_2 σ : ι → Type u_3 τ : κ → Type u_4 inst✝² : (i : ι) → TopologicalSpace (σ i) inst✝¹ : (k : κ) → TopologicalSpace (τ k) inst✝ : TopologicalSpace α f₁ : ι → κ f₂ : (i : ι) → σ i → τ (f₁ i) h : Injective f₁ ⊢ _root_.Embedding (Sigma.map f₁ f₂) ↔ ∀ (i : ι), _root_.Embedding (f₂ i) State After: no goals Tactic: simp only [embedding_iff, Injective.sigma_map, inducing_sigma_map h, forall_and, h.sigma_map_iff]
{- This second-order term syntax was created from the following second-order syntax description: syntax TLC | Λ type N : 0-ary _↣_ : 2-ary | r30 𝟙 : 0-ary _⊗_ : 2-ary | l40 𝟘 : 0-ary _⊕_ : 2-ary | l30 term app : α ↣ β α -> β | _$_ l20 lam : α.β -> α ↣ β | ƛ_ r10 unit : 𝟙 pair : α β -> α ⊗ β | ⟨_,_⟩ fst : α ⊗ β -> α snd : α ⊗ β -> β abort : 𝟘 -> α inl : α -> α ⊕ β inr : β -> α ⊕ β case : α ⊕ β α.γ β.γ -> γ ze : N su : N -> N nrec : N α (α,N).α -> α theory (ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a] (ƛη) f : α ↣ β |> lam (x. app(f, x)) = f (𝟙η) u : 𝟙 |> u = unit (fβ) a : α b : β |> fst (pair(a, b)) = a (sβ) a : α b : β |> snd (pair(a, b)) = b (pη) p : α ⊗ β |> pair (fst(p), snd(p)) = p (𝟘η) e : 𝟘 c : α |> abort(e) = c (lβ) a : α f : α.γ g : β.γ |> case (inl(a), x.f[x], y.g[y]) = f[a] (rβ) b : β f : α.γ g : β.γ |> case (inr(b), x.f[x], y.g[y]) = g[b] (cη) s : α ⊕ β c : (α ⊕ β).γ |> case (s, x.c[inl(x)], y.c[inr(y)]) = c[s] (zeβ) z : α s : (α,N).α |> nrec (ze, z, r m. s[r,m]) = z (suβ) z : α s : (α,N).α n : N |> nrec (su (n), z, r m. s[r,m]) = s[nrec (n, z, r m. s[r,m]), n] (ift) t f : α |> if (true, t, f) = t (iff) t f : α |> if (false, t, f) = f -} module TLC.Syntax where open import SOAS.Common open import SOAS.Context open import SOAS.Variable open import SOAS.Families.Core open import SOAS.Construction.Structure open import SOAS.ContextMaps.Inductive open import SOAS.Metatheory.Syntax open import TLC.Signature private variable Γ Δ Π : Ctx α β γ : ΛT 𝔛 : Familyₛ -- Inductive term declaration module Λ:Terms (𝔛 : Familyₛ) where data Λ : Familyₛ where var : ℐ ⇾̣ Λ mvar : 𝔛 α Π → Sub Λ Π Γ → Λ α Γ _$_ : Λ (α ↣ β) Γ → Λ α Γ → Λ β Γ ƛ_ : Λ β (α ∙ Γ) → Λ (α ↣ β) Γ unit : Λ 𝟙 Γ ⟨_,_⟩ : Λ α Γ → Λ β Γ → Λ (α ⊗ β) Γ fst : Λ (α ⊗ β) Γ → Λ α Γ snd : Λ (α ⊗ β) Γ → Λ β Γ abort : Λ 𝟘 Γ → Λ α Γ inl : Λ α Γ → Λ (α ⊕ β) Γ inr : Λ β Γ → Λ (α ⊕ β) Γ case : Λ (α ⊕ β) Γ → Λ γ (α ∙ Γ) → Λ γ (β ∙ Γ) → Λ γ Γ ze : Λ N Γ su : Λ N Γ → Λ N Γ nrec : Λ N Γ → Λ α Γ → Λ α (α ∙ N ∙ Γ) → Λ α Γ infixl 20 _$_ infixr 10 ƛ_ open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛 Λᵃ : MetaAlg Λ Λᵃ = record { 𝑎𝑙𝑔 = λ where (appₒ ⋮ a , b) → _$_ a b (lamₒ ⋮ a) → ƛ_ a (unitₒ ⋮ _) → unit (pairₒ ⋮ a , b) → ⟨_,_⟩ a b (fstₒ ⋮ a) → fst a (sndₒ ⋮ a) → snd a (abortₒ ⋮ a) → abort a (inlₒ ⋮ a) → inl a (inrₒ ⋮ a) → inr a (caseₒ ⋮ a , b , c) → case a b c (zeₒ ⋮ _) → ze (suₒ ⋮ a) → su a (nrecₒ ⋮ a , b , c) → nrec a b c ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) } module Λᵃ = MetaAlg Λᵃ module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where open MetaAlg 𝒜ᵃ 𝕤𝕖𝕞 : Λ ⇾̣ 𝒜 𝕊 : Sub Λ Π Γ → Π ~[ 𝒜 ]↝ Γ 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t 𝕊 (t ◂ σ) (old v) = 𝕊 σ v 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε) 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v 𝕤𝕖𝕞 (_$_ a b) = 𝑎𝑙𝑔 (appₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b) 𝕤𝕖𝕞 (ƛ_ a) = 𝑎𝑙𝑔 (lamₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 unit = 𝑎𝑙𝑔 (unitₒ ⋮ tt) 𝕤𝕖𝕞 (⟨_,_⟩ a b) = 𝑎𝑙𝑔 (pairₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b) 𝕤𝕖𝕞 (fst a) = 𝑎𝑙𝑔 (fstₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 (snd a) = 𝑎𝑙𝑔 (sndₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 (abort a) = 𝑎𝑙𝑔 (abortₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 (inl a) = 𝑎𝑙𝑔 (inlₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 (inr a) = 𝑎𝑙𝑔 (inrₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 (case a b c) = 𝑎𝑙𝑔 (caseₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c) 𝕤𝕖𝕞 ze = 𝑎𝑙𝑔 (zeₒ ⋮ tt) 𝕤𝕖𝕞 (su a) = 𝑎𝑙𝑔 (suₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 (nrec a b c) = 𝑎𝑙𝑔 (nrecₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c) 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Λᵃ 𝒜ᵃ 𝕤𝕖𝕞 𝕤𝕖𝕞ᵃ⇒ = record { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t } ; ⟨𝑣𝑎𝑟⟩ = refl ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } } where open ≡-Reasoning ⟨𝑎𝑙𝑔⟩ : (t : ⅀ Λ α Γ) → 𝕤𝕖𝕞 (Λᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t) ⟨𝑎𝑙𝑔⟩ (appₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (lamₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (unitₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (pairₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (fstₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (sndₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (abortₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (inlₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (inrₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (caseₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (zeₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (suₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (nrecₒ ⋮ _) = refl 𝕊-tab : (mε : Π ~[ Λ ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v) 𝕊-tab mε new = refl 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v module _ (g : Λ ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Λᵃ 𝒜ᵃ g) where open MetaAlg⇒ gᵃ⇒ 𝕤𝕖𝕞! : (t : Λ α Γ) → 𝕤𝕖𝕞 t ≡ g t 𝕊-ix : (mε : Sub Λ Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v) 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε)) = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε)) 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩ 𝕤𝕖𝕞! (_$_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (ƛ_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! unit = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (⟨_,_⟩ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (fst a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (snd a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (abort a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (inl a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (inr a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (case a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! ze = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (su a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (nrec a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩ -- Syntax instance for the signature Λ:Syn : Syntax Λ:Syn = record { ⅀F = ⅀F ; ⅀:CS = ⅀:CompatStr ; mvarᵢ = Λ:Terms.mvar ; 𝕋:Init = λ 𝔛 → let open Λ:Terms 𝔛 in record { ⊥ = Λ ⋉ Λᵃ ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ } ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } } -- Instantiation of the syntax and metatheory open Syntax Λ:Syn public open Λ:Terms public open import SOAS.Families.Build public open import SOAS.Syntax.Shorthands Λᵃ public open import SOAS.Metatheory Λ:Syn public -- Derived operations true : Λ 𝔛 B Γ true = inl unit false : Λ 𝔛 B Γ false = inr unit if : Λ 𝔛 B Γ → Λ 𝔛 α Γ → Λ 𝔛 α Γ → Λ 𝔛 α Γ if b t e = case b (Theory.𝕨𝕜 _ t) (Theory.𝕨𝕜 _ e) plus : Λ 𝔛 (N ↣ N ↣ N) Γ plus = ƛ (ƛ (nrec x₁ x₀ (su x₀))) uncurry : Λ 𝔛 ((α ↣ β ↣ γ) ↣ (α ⊗ β) ↣ γ) Γ uncurry = ƛ ƛ x₁ $ fst x₀ $ snd x₀
proposition (in metric_space) completeE: assumes "complete s" and "\<forall>n. f n \<in> s" and "Cauchy f" obtains l where "l \<in> s" and "f \<longlonglongrightarrow> l"
Formal statement is: lemma bezout_gcd_nat: fixes a::nat shows "\<exists>x y. a * x - b * y = gcd a b \<or> b * x - a * y = gcd a b" Informal statement is: For any two natural numbers $a$ and $b$, there exist two natural numbers $x$ and $y$ such that $a x - b y = \gcd(a, b)$ or $b x - a y = \gcd(a, b)$.
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import topology.uniform_space.completion import topology.metric_space.isometry import topology.instances.real /-! # The completion of a metric space Completion of uniform spaces are already defined in `topology.uniform_space.completion`. We show here that the uniform space completion of a metric space inherits a metric space structure, by extending the distance to the completion and checking that it is indeed a distance, and that it defines the same uniformity as the already defined uniform structure on the completion -/ open set filter uniform_space metric open_locale filter topological_space uniformity noncomputable theory universes u v variables {α : Type u} {β : Type v} [pseudo_metric_space α] namespace uniform_space.completion /-- The distance on the completion is obtained by extending the distance on the original space, by uniform continuity. -/ instance : has_dist (completion α) := ⟨completion.extension₂ dist⟩ /-- The new distance is uniformly continuous. -/ protected lemma uniform_continuous_dist : uniform_continuous (λp:completion α × completion α, dist p.1 p.2) := uniform_continuous_extension₂ dist /-- The new distance is continuous. -/ protected lemma continuous_dist [topological_space β] {f g : β → completion α} (hf : continuous f) (hg : continuous g) : continuous (λ x, dist (f x) (g x)) := completion.uniform_continuous_dist.continuous.comp (hf.prod_mk hg : _) /-- The new distance is an extension of the original distance. -/ @[simp] protected lemma dist_eq (x y : α) : dist (x : completion α) y = dist x y := completion.extension₂_coe_coe uniform_continuous_dist _ _ /- Let us check that the new distance satisfies the axioms of a distance, by starting from the properties on α and extending them to `completion α` by continuity. -/ protected lemma dist_self (x : completion α) : dist x x = 0 := begin apply induction_on x, { refine is_closed_eq _ continuous_const, exact completion.continuous_dist continuous_id continuous_id }, { assume a, rw [completion.dist_eq, dist_self] } end protected lemma dist_comm (x y : completion α) : dist x y = dist y x := begin apply induction_on₂ x y, { exact is_closed_eq (completion.continuous_dist continuous_fst continuous_snd) (completion.continuous_dist continuous_snd continuous_fst) }, { assume a b, rw [completion.dist_eq, completion.dist_eq, dist_comm] } end protected lemma dist_triangle (x y z : completion α) : dist x z ≤ dist x y + dist y z := begin apply induction_on₃ x y z, { refine is_closed_le _ (continuous.add _ _); apply_rules [completion.continuous_dist, continuous.fst, continuous.snd, continuous_id] }, { assume a b c, rw [completion.dist_eq, completion.dist_eq, completion.dist_eq], exact dist_triangle a b c } end /-- Elements of the uniformity (defined generally for completions) can be characterized in terms of the distance. -/ protected lemma mem_uniformity_dist (s : set (completion α × completion α)) : s ∈ 𝓤 (completion α) ↔ (∃ε>0, ∀{a b}, dist a b < ε → (a, b) ∈ s) := begin split, { /- Start from an entourage `s`. It contains a closed entourage `t`. Its pullback in `α` is an entourage, so it contains an `ε`-neighborhood of the diagonal by definition of the entourages in metric spaces. Then `t` contains an `ε`-neighborhood of the diagonal in `completion α`, as closed properties pass to the completion. -/ assume hs, rcases mem_uniformity_is_closed hs with ⟨t, ht, ⟨tclosed, ts⟩⟩, have A : {x : α × α | (coe (x.1), coe (x.2)) ∈ t} ∈ uniformity α := uniform_continuous_def.1 (uniform_continuous_coe α) t ht, rcases mem_uniformity_dist.1 A with ⟨ε, εpos, hε⟩, refine ⟨ε, εpos, λx y hxy, _⟩, have : ε ≤ dist x y ∨ (x, y) ∈ t, { apply induction_on₂ x y, { have : {x : completion α × completion α | ε ≤ dist (x.fst) (x.snd) ∨ (x.fst, x.snd) ∈ t} = {p : completion α × completion α | ε ≤ dist p.1 p.2} ∪ t, by ext; simp, rw this, apply is_closed.union _ tclosed, exact is_closed_le continuous_const completion.uniform_continuous_dist.continuous }, { assume x y, rw completion.dist_eq, by_cases h : ε ≤ dist x y, { exact or.inl h }, { have Z := hε (not_le.1 h), simp only [set.mem_set_of_eq] at Z, exact or.inr Z }}}, simp only [not_le.mpr hxy, false_or, not_le] at this, exact ts this }, { /- Start from a set `s` containing an ε-neighborhood of the diagonal in `completion α`. To show that it is an entourage, we use the fact that `dist` is uniformly continuous on `completion α × completion α` (this is a general property of the extension of uniformly continuous functions). Therefore, the preimage of the ε-neighborhood of the diagonal in ℝ is an entourage in `completion α × completion α`. Massaging this property, it follows that the ε-neighborhood of the diagonal is an entourage in `completion α`, and therefore this is also the case of `s`. -/ rintros ⟨ε, εpos, hε⟩, let r : set (ℝ × ℝ) := {p | dist p.1 p.2 < ε}, have : r ∈ uniformity ℝ := metric.dist_mem_uniformity εpos, have T := uniform_continuous_def.1 (@completion.uniform_continuous_dist α _) r this, simp only [uniformity_prod_eq_prod, mem_prod_iff, exists_prop, filter.mem_map, set.mem_set_of_eq] at T, rcases T with ⟨t1, ht1, t2, ht2, ht⟩, refine mem_of_superset ht1 _, have A : ∀a b : completion α, (a, b) ∈ t1 → dist a b < ε, { assume a b hab, have : ((a, b), (a, a)) ∈ t1 ×ˢ t2 := ⟨hab, refl_mem_uniformity ht2⟩, have I := ht this, simp [completion.dist_self, real.dist_eq, completion.dist_comm] at I, exact lt_of_le_of_lt (le_abs_self _) I }, show t1 ⊆ s, { rintros ⟨a, b⟩ hp, have : dist a b < ε := A a b hp, exact hε this }} end /-- If two points are at distance 0, then they coincide. -/ protected lemma eq_of_dist_eq_zero (x y : completion α) (h : dist x y = 0) : x = y := begin /- This follows from the separation of `completion α` and from the description of entourages in terms of the distance. -/ have : separated_space (completion α) := by apply_instance, refine separated_def.1 this x y (λs hs, _), rcases (completion.mem_uniformity_dist s).1 hs with ⟨ε, εpos, hε⟩, rw ← h at εpos, exact hε εpos end /-- Reformulate `completion.mem_uniformity_dist` in terms that are suitable for the definition of the metric space structure. -/ protected lemma uniformity_dist' : 𝓤 (completion α) = (⨅ε:{ε : ℝ // 0 < ε}, 𝓟 {p | dist p.1 p.2 < ε.val}) := begin ext s, rw mem_infi_of_directed, { simp [completion.mem_uniformity_dist, subset_def] }, { rintro ⟨r, hr⟩ ⟨p, hp⟩, use ⟨min r p, lt_min hr hp⟩, simp [lt_min_iff, (≥)] {contextual := tt} } end protected lemma uniformity_dist : 𝓤 (completion α) = (⨅ ε>0, 𝓟 {p | dist p.1 p.2 < ε}) := by simpa [infi_subtype] using @completion.uniformity_dist' α _ /-- Metric space structure on the completion of a pseudo_metric space. -/ instance : metric_space (completion α) := { dist_self := completion.dist_self, eq_of_dist_eq_zero := completion.eq_of_dist_eq_zero, dist_comm := completion.dist_comm, dist_triangle := completion.dist_triangle, to_uniform_space := by apply_instance, uniformity_dist := completion.uniformity_dist } /-- The embedding of a metric space in its completion is an isometry. -/ lemma coe_isometry : isometry (coe : α → completion α) := isometry_emetric_iff_metric.2 completion.dist_eq @[simp] protected lemma edist_eq (x y : α) : edist (x : completion α) y = edist x y := coe_isometry x y end uniform_space.completion
[STATEMENT] lemma g_step_lm_0: "c_fst (c_fst key) mod 7 = 0 \<Longrightarrow> g_step ls key = c_cons (c_pair key 0) ls" [PROOF STATE] proof (prove) goal (1 subgoal): 1. c_fst (c_fst key) mod 7 = 0 \<Longrightarrow> g_step ls key = c_cons (c_pair key 0) ls [PROOF STEP] by (simp add: g_step_def)
function cc_grids_constrained_display ( ) %*****************************************************************************80 % %% CC_GRIDS_CONSTRAINED_DISPLAY displays grids generated by CC_GRIDS_CONSTRAINED. % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 08 November 2006 % % Author: % % John Burkardt % fprintf ( 1, '\n' ); timestamp ( ); fprintf ( 1, '\n' ); fprintf ( 1, 'CC_GRIDS_CONSTRAINED_DISPLAY:\n' ); fprintf ( 1, ' MATLAB version\n' ); fprintf ( 1, ' Display the 2D Clenshaw-Curtis grids\n' ); fprintf ( 1, ' generated by CC_GRIDS_CONSTRAINED.\n' ); dim_num = 2; while ( 1 ) % % Get user input. % q_max = input ( 'Enter Q_MAX or RETURN to exit;' ); if ( isempty ( q_max ) ) break end if ( q_max < dim_num ) fprintf ( 1, '\n' ); fprintf ( 1, ' We require DIM_NUM <= Q_MAX!\n' ); continue end alpha = input ( 'Enter [ ALPHA1, ALPHA2 ] or RETURN to exit;' ); if ( isempty ( alpha ) ) break end order_min = input ( 'Enter [ ORDER_MIN1, ORDER_MIN2 ] or RETURN to exit;' ); if ( isempty ( order_min ) ) break end order_max = input ( 'Enter [ ORDER_MAX1, ORDER_MAX2 ] or RETURN to exit;' ); if ( isempty ( order_max ) ) break end % % Compute data. % [ grid_num, point_num ] = cc_grids_constrained_size ( dim_num, ... q_max, alpha, order_min, order_max ); fprintf ( 1, '\n' ); fprintf ( 1, ' Number of grids is %d\n', grid_num ); fprintf ( 1, ' Number of points is %d\n', point_num ); [ grid_order, grid_point ] = cc_grids_constrained ( dim_num, ... q_max, alpha, order_min, order_max, grid_num, point_num ); clf % % We have to name the axes in order to control the grid. % axes_handle = axes; % % Plot the points. % handle = scatter ( grid_point(1,:), grid_point(2,:), 'filled' ); % % Force the plotting region to be square, not rectangular. % axis square % % Request grid lines. % grid on % % Specify the location of the grid lines, and suppress labeling. % set ( axes_handle, 'xtick', [ -1, -.75, -.5, -.25, 0, .25, .50, .75, 1] ); set ( axes_handle, 'xticklabel', [] ); set ( axes_handle, 'ytick', [ -1, -.75, -.5, -.25, 0, .25, .50, .75, 1] ); set ( axes_handle, 'yticklabel', [] ); % % Make the plotting region slightly bigger than the data. % axis ( [ -1.1, 1.1, -1.1, 1.1 ] ) % % Title % s = sprintf ( '%d <= Q <= %d', q_min, q_max ); title ( s ); end fprintf ( 1, '\n' ); fprintf ( 1, 'CC_GRIDS_CONSTRAINED_DISPLAY:\n' ); fprintf ( 1, ' Normal end of execution.\n' ); fprintf ( 1, '\n' ); timestamp ( ); return end
/* Copyright [2017-2021] [IBM Corporation] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef MCAS_HSTORE_HEAP_MM_EPHEMERAL_H #define MCAS_HSTORE_HEAP_MM_EPHEMERAL_H #include "heap_ephemeral.h" #include "hstore_config.h" #include "histogram_log2.h" #include "hop_hash_log.h" #include <mm_plugin_itf.h> #include "persistent.h" #include <ccpm/interfaces.h> /* ownership_callback, (IHeap_expandable, region_vector_t) */ #include <common/byte_span.h> #include <common/string_view.h> #include <nupm/region_descriptor.h> #include <gsl/span> #include <algorithm> /* min, swap */ #include <cstddef> /* size_t */ #include <vector> struct heap_mm_ephemeral : private heap_ephemeral { private: using byte_span = common::byte_span; /* Although the mm heap tracks managed regions, its definition of a managed * region probably differs from what hstore needs: * * The hstore managed region must include the hstore metadata area, as that * must be include in the "maanged regions" returned through the kvstore * interface. * * The mm heap managed region cannot include the hstore metadata area, as * that would allow the allocator to use the area for memory allocation. * * Therefore, heap_mr_ephemeral keeps its own copy of the managed regions. */ nupm::region_descriptor _managed_regions; protected: using heap_ephemeral::_alloc_mutex; protected: using hist_type = util::histogram_log2<std::size_t>; hist_type _hist_alloc; hist_type _hist_inject; hist_type _hist_free; private: /* Rca_LB seems not to allocate at or above about 2GiB. Limit reporting to 16 GiB. */ static constexpr unsigned hist_report_upper_bound = 24U; static constexpr unsigned log_min_alignment = 3U; /* log (sizeof(void *)) */ static_assert(sizeof(void *) == 1U << log_min_alignment, "log_min_alignment does not match sizeof(void *)"); protected: virtual void add_managed_region_to_heap(byte_span r_heap) = 0; public: template <bool B> void write_hist(const byte_span pool_) const { static bool suppress = false; if ( ! suppress ) { hop_hash_log<B>::write(LOG_LOCATION, "pool ", ::base(pool_)); std::size_t lower_bound = 0; auto limit = std::min(std::size_t(hist_report_upper_bound), _hist_alloc.data().size()); for ( unsigned i = log_min_alignment; i != limit; ++i ) { const std::size_t upper_bound = 1ULL << i; hop_hash_log<B>::write(LOG_LOCATION , "[", lower_bound, "..", upper_bound, "): " , _hist_alloc.data()[i], " ", _hist_inject.data()[i], " ", _hist_free.data()[i] , " " ); lower_bound = upper_bound; } suppress = true; } } using common::log_source::debug_level; explicit heap_mm_ephemeral( unsigned debug_level , nupm::region_descriptor managed_regions ); virtual ~heap_mm_ephemeral() {} virtual std::size_t allocated() const = 0; virtual std::size_t capacity() const = 0; virtual void allocate(persistent_t<void *> &p, std::size_t sz, std::size_t alignment) = 0; virtual std::size_t free(persistent_t<void *> &p_, std::size_t sz_) = 0; virtual void free_tracked(const void *p, std::size_t sz) = 0; nupm::region_descriptor get_managed_regions() const { return _managed_regions; } nupm::region_descriptor set_managed_regions(nupm::region_descriptor n) { using std::swap; swap(n, _managed_regions); return n; } void add_managed_region(byte_span r_full, byte_span r_heap); void reconstitute_managed_region( const byte_span r_full , const byte_span r_heap , ccpm::ownership_callback_t f ); virtual void reconstitute_managed_region_to_heap(byte_span r_heap, ccpm::ownership_callback_t f) = 0; virtual bool is_crash_consistent() const = 0; virtual bool can_reconstitute() const = 0; }; #endif
[STATEMENT] lemma p_min_le_neut[simp]: "p_min Infty a = a" [PROOF STATE] proof (prove) goal (1 subgoal): 1. p_min Infty a = a [PROOF STEP] by (induct a) auto
[STATEMENT] lemma map_indets_id: "(\<And>x. x \<in> indets p \<Longrightarrow> f x = x) \<Longrightarrow> map_indets f p = p" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<And>x. x \<in> indets p \<Longrightarrow> f x = x) \<Longrightarrow> map_indets f p = p [PROOF STEP] by (simp add: map_indets_def poly_subst_id)
module Toolkit.Data.List.Interleaving %default total infixr 6 <:: infixr 6 ::> public export data Interleaving : (xs, ys, zs : List type) -> Type where Empty : Interleaving Nil Nil Nil Left : {xs,ys,zs : List type} -> (x : type) -> (rest : Interleaving xs ys zs) -> Interleaving (x::xs) ys (x::zs) Right : {xs,ys,zs : List type} -> (y : type) -> (rest : Interleaving xs ys zs) -> Interleaving xs (y::ys) (y::zs) public export (<::) : {xs,ys,zs : List type} -> (x : type) -> (rest : Interleaving xs ys zs) -> Interleaving (x::xs) ys (x::zs) (<::) = Left public export (::>) : {xs,ys,zs : List type} -> (y : type) -> (rest : Interleaving xs ys zs) -> Interleaving xs (y::ys) (y::zs) (::>) = Right
<!-- dom:TITLE: FFM232, Klassisk fysik och vektorfält - Föreläsningsanteckningar --> # FFM232, Klassisk fysik och vektorfält - Föreläsningsanteckningar <!-- dom:AUTHOR: [Christian Forssén](http://fy.chalmers.se/subatom/tsp/), Institutionen för fysik, Chalmers, Göteborg, Sverige --> <!-- Author: --> **[Christian Forssén](http://fy.chalmers.se/subatom/tsp/), Institutionen för fysik, Chalmers, Göteborg, Sverige** Date: **Sep 9, 2016** # 2. Kroklinjiga koordinater Allmänt behöver vi tre parametrar $u_1, u_2, u_3$ för att beskriva en godtycklig punkt i rummet. Jämför med *generaliserade koordinater* i analytisk mekanik. Vi kan då skriva ortsvektorn som $\vec{r}(u_1, u_2, u_3)$. ### Koordinatyta för koordinat $i$: alla lösningar till $u_i = \mathrm{konstant}$. ### Koordinatkurva den kurva som fås om en koordinat tillåts variera och de andra hålls konstanta. Om vi då håller en av parametrarna, säg $u_1$, fix och låter $u_2$ och $u_3$ variera, så får vi en två-dimensionell yta, vilken vi kallar $u_1$-ytan. På samma sätt kan vi då definiera ytor för de andra koordinaterna. Två koordinatytor, till exempel de för koordinaterna $u_2$ och $u_3$, skär varandra längs en en-dimensionell kurva. Längs denna kurva kommer då bara koordinaten $u_1$ att variera, så denna kurva är en koordinatkurva för $u_1$. ### Exempel: I de cylindriska koordinaterna $\rho, \phi, z$ kan vi skriva ortsvektorn som $\vec{r} = \rho\cos \phi \hat{x} + \rho\sin \phi \hat{y} + z \hat{z}$. <!-- dom:FIGURE:[fig/620px-Coord_system_CY.png, width=600 frac=0.8] --> <!-- begin figure --> <p></p> <!-- end figure --> Koordinatytorna för $\rho, \phi, z$ är då en cylinder med $z$-axeln som symmetriaxel och med radien $\rho$, ett plan som utgår från $z$-axeln och bildar en vinkel $\phi$ med $x$-axeln, samt ett plan parallellt med $xy$-planet och med $z$-koordinaten $z$. <!-- dom:FIGURE:[fig/Cylindrical_coordinate_surfaces.png, width=600 frac=0.8] --> <!-- begin figure --> <p></p> <!-- end figure --> Koordinatlinjerna för $\rho, \phi, z$ blir då en stråle som utgår från $z$-axeln och bildar vinkeln $\phi$ med $x$-axeln, en cirkel med radien $\rho$ och en linje parallell med $z$-axeln. ## Enhetsvektorer Om vi nu studerar en liten förskjutning av ortsvektorn, $\mbox{d}\vec{r}$, så kan vi i och med att ortsvektorn är en funktion av $u_1, u_2, u_3$ skriva denna som $$ \begin{equation} \mbox{d}\vec{r} = \frac{\partial \vec{r}}{\partial u_1} \mbox{d}u_1 + \frac{\partial \vec{r}}{\partial u_2} \mbox{d}u_2 + \frac{\partial \vec{r}}{\partial u_3} \mbox{d}u_3. \end{equation} $$ Tänk nu på att den partiella derivatan $\partial \vec{r}/\partial u_1$ är definierad som derivatan då vi håller $u_2$ och $u_3$ fixa. Därför måste $\partial \vec{r}/\partial u_1$ vara en tangentvektor till koordinatkurvan för $u_1$. Vi kan då definiera en enhetsvektor för $u_1$ som $$ \begin{equation} \hat{e}_1 = \frac{1}{h_1} \frac{\partial \vec{r}}{\partial u_1}, \end{equation} $$ där $$ \begin{equation} h_1 = \left|\frac{\partial \vec{r}}{\partial u_1}\right| \end{equation} $$ kallas för skalfaktorn. På samma sätt kan vi bestämma skalfaktorer och enhetsvektorer till $u_2$ och $u_3$. Förskjutningsvektorn $\mbox{d}\vec{r}$ kan vi nu skriva som $$ \begin{equation} \mbox{d}\vec{r} = h_1\hat{e}_1 \mbox{d}u_1 + h_2\hat{e}_2\mbox{d}u_2 + h_3\hat{e}_3\mbox{d}u_3. \end{equation} $$ ### Alternativ definition Ett alternativ till att använda de normerade tangentvektorerna som enhetsvektorer är att använda normalvektorerna till koordinatytorna. Betrakta t.ex. $$ \begin{equation} u_1 = u_1(x,y,z) = \mathrm{konstant}. \end{equation} $$ Detta motsvarar en nivåyta till ett skalärfält. Normalvektorn ges alltså av $\nabla u_1$. Det gäller alltid att $$ \begin{equation} \nabla u_i \cdot \frac{\partial \vec{r}}{\partial u_j} = \delta_{ij}. \end{equation} $$ När vi inskränker oss till ortogonala system gäller dessutom att $\nabla u_i \parallel \frac{\partial \vec{r}}{\partial u_i}$. Notera dock att dessa vektorer i allmänhet kan ha *olika* längd. Faktum är att följande samband gäller för ortogonala system $$ \begin{equation} \hat{e}_i = \frac{1}{h_i} \frac{\partial \vec{r}}{\partial u_i} = h_i \nabla u_i. \end{equation} $$ ### Exempel: I cylindriska koordinater är $\vec{r} = (\rho\cos \phi, \rho\sin \phi, z)$. Vi kan då beräkna $$ \begin{equation} \frac{\partial \vec{r}}{\partial \rho} = \left(\cos \phi, \sin \phi, 0\right), \end{equation} $$ $$ \begin{equation} \frac{\partial \vec{r}}{\partial \phi} = \left(-\rho \sin\phi, \rho \cos \phi, 0\right), \end{equation} $$ $$ \begin{equation} \frac{\partial \vec{r}}{\partial z} = \left(0,0,1\right). \end{equation} $$ Skalfaktorerna blir då $$ \begin{equation} h_\rho = \left(\cos^2\phi + \sin^2\phi\right)^{1/2} = 1, \end{equation} $$ $$ \begin{equation} h_\phi = \left(\rho^2 \cos^2\phi + \rho^2 \sin^2\phi\right)^{1/2} = \rho, \end{equation} $$ $$ \begin{equation} h_z = 1. \end{equation} $$ Enhetsvektorerna blir $$ \begin{equation} \hat{\rho} = \left(\cos\phi, \sin\phi,0\right), \end{equation} $$ $$ \begin{equation} \hat{\phi} = \left(-\sin\phi, \cos\phi,0\right), \end{equation} $$ $$ \begin{equation} \hat{z} = \left(0,0,1\right). \end{equation} $$ Förskjutningsvektorn kan då skrivas som $$ \begin{equation} \mbox{d}\vec{r} = \hat{\rho} \mbox{d}\rho + \rho \hat{\phi} \mbox{d} \phi + \hat{z} \mbox{d}z. \end{equation} $$ I fortsättningen skall vi begränsa oss till koordinatsystem med ortogonala enhetsvektorer, dvs $$ \begin{equation} \hat{e}_i \cdot \hat{e}_j = \delta_{ij} = \left\{ \begin{array}{ll} 1 & \,\mbox{om}\,\, i = j \\ 0 & \,\mbox{annars}\\ \end{array}\right. \end{equation} $$ där vi passat på att introducera Kroneckers delta, $\delta_{ij}$. Vi skall också anta att enhetsvektorerna bildar ett högersystem $$ \begin{equation} \hat{e}_1 \times \hat{e}_2 = \hat{e}_3 \end{equation} $$ *Visa att enhetsvektorerna i de cylindriska koordinaterna uppfyller dessa villkor.* Vi kan nu härleda några användbara samband som båglängden längs en kurva $$ \begin{equation} \mbox{d}s^2 = \mbox{d}\vec{r}\cdot \mbox{d}\vec{r} = h_1^2\mbox{d}u_1^2 + h_2^2 \mbox{d}u_2^2 + h_3^2 \mbox{d}u_3^2. \end{equation} $$ Betrakta ovanstående båglängd för fallet då $du_2=du_3=0$. Det står då klart att vi kan tolka $h_1 du_1$ som båglängden $ds_1$, dvs som en infinitesimal förflyttning i $u_1$-riktningen. Notera därför att $h_i du_i$ alltid måste ha enheten längd. Ett ytelement $\mbox{d}\vec{S}_1$ på koordinatytan $u_1$ är en rektangel som genereras av $\mbox{d}u_2$ och $\mbox{d}u_3$. Rektangelns sidor har då längderna $h_2\mbox{d}u_2$ och $h_3\mbox{d}u_3$. Ytelementet blir $$ \begin{equation} \mbox{d}\vec{S}_1 = \hat{e}_1 h_2 h_3 \mbox{d}u_2 \mbox{d}u_3, \end{equation} $$ och på samma sätt kan vi beräkna ytelementen på koordinatytorna för $u_2$ och $u_3$. Analogt kan vi beräkna volymelementet som genereras av $\mbox{d}u_1$, $\mbox{d}u_2$ och $\mbox{d}u_3$, vilket blir $$ \begin{equation} \mbox{d}V = h_1 h_2 h_3 \mbox{d}u_1 \mbox{d}u_2 \mbox{d}u_3. \end{equation} $$ ### Exempel: Bågelementet i cylindriska koordinater blir $$ \begin{equation} \mbox{d}s^2 = \mbox{d}\rho^2 + \rho^2\mbox{d}\theta^2 + \mbox{d}z^2. \end{equation} $$ Ett ytelement på $\rho$-ytan skrives $$ \begin{equation} \mbox{d}\vec{S}_\rho = \hat{e}_\rho \rho \mbox{d}\phi\mbox{d}z, \end{equation} $$ på $\phi$-ytan $$ \begin{equation} \mbox{d}\vec{S}_\phi = \hat{e}_\phi \mbox{d}\rho\mbox{z} \end{equation} $$ och på $z$-ytan $$ \begin{equation} \mbox{d}\vec{S}_z = \hat{e}_z \rho\mbox{d}\rho \mbox{d}\phi. \end{equation} $$ Volymelementet kan vi skriva som $$ \begin{equation} \mbox{d}V = \rho\mbox{d}\rho \mbox{d}\phi\mbox{d}z. \end{equation} $$ ## Vektoroperatorer i kroklinjiga koordinater ### Gradient Betrakta ett skalärt fält $\phi$. Om vi förflyttar oss en sträcka $\mbox{d}\vec{r}$ så förändras $\phi$ $$ \begin{equation} \mbox{d}\phi = \nabla \phi \cdot \mbox{d}\vec{r}. \end{equation} $$ Förflyttningen kan vi i de nya koordinaterna skriva som $$ \begin{equation} \mbox{d}\vec{r} = h_1 \hat{e}_1 \mbox{d}u_1 + h_2 \hat{e}_2 \mbox{d}u_2 + h_3 \hat{e}_3 \mbox{d}u_3. \end{equation} $$ Om vi skriver $\phi$ som en funktion av $u_1, u_2$ och $u_3$ får vi $$ \begin{equation} \mbox{d}\phi = \frac{\partial \phi}{\partial u_1}\mbox{d}u_1 + \frac{\partial \phi}{\partial u_2}\mbox{d}u_2 + \frac{\partial \phi}{\partial u_3}\mbox{d}u_3 = \frac{1}{h_1} \frac{\partial \phi}{\partial u_1} h_1 \mbox{d}u_1 + \frac{1}{h_2} \frac{\partial \phi}{\partial u_2} h_2 \mbox{d}u_2 + \frac{1}{h_3} \frac{\partial \phi}{\partial u_3} h_3 \mbox{d}u_3 \nonumber \end{equation} $$ $$ \begin{equation} = \left(\frac{1}{h_1} \frac{\partial \phi}{\partial u_1} \hat{e}_1 + \frac{1}{h_2} \frac{\partial \phi}{\partial u_2} \hat{e}_2 + \frac{1}{h_3} \frac{\partial \phi}{\partial u_3} \hat{e}_3\right) \cdot \mbox{d}\vec{r} \end{equation} $$ Då kan vi identifiera uttrycket inom parentesen som gradienten i de nya koordinaterna $u_1, u_2, u_3$ $$ \begin{equation} \nabla \phi = \frac{1}{h_1} \frac{\partial \phi}{\partial u_1} \hat{e}_1 + \frac{1}{h_2} \frac{\partial \phi}{\partial u_2} \hat{e}_2 + \frac{1}{h_3} \frac{\partial \phi}{\partial u_3} \hat{e}_3. \end{equation} $$ ### Gradient i cylindriska koordinater: I cylindriska koordinater blir gradienten $$ \begin{equation} \nabla f = \frac{\partial f}{\partial \rho} + \frac{1}{\rho} \frac{\partial f}{\partial \phi} + \frac{\partial f}{\partial z}. \end{equation} $$ ### Exempel Ett skalärfält är givet i Cartesiska koordinater $$ \begin{equation} \beta = x^2 + y^2. \end{equation} $$ Motsvarande skalärfält i plana polärkoordinater blir $$ \begin{equation} \beta = r^2\cos^2\theta + r^2 \sin^2\theta = r^2. \end{equation} $$ Gradienten i Cartesiska koordinater blir $$ \begin{equation} \nabla \beta = \hat{x} \partial_x \beta + \hat{y} \partial_y \beta = 2 (x \hat{x} + y \hat{y}). \end{equation} $$ Medan i plana polärkoordinater blir den $$ \begin{equation} \nabla \beta = \hat{e}_r \partial_r + \hat{e}_\theta \frac{1}{r} \partial_\theta \beta = 2 r \hat{e}_r. \end{equation} $$ Eftersom $x \hat{x} + y \hat{y} = r \hat{e}_r$ är det uppenbart att detta är samma vektor! ## Tentauppgift 2010-08-26: 1b För vilka värden på $\alpha,\beta,\gamma$ har det tvådimensionella koordinatsystemet med koordinater $\xi$ och $\eta$, givna av $$ \begin{equation} \xi = x^2 - y^2 \end{equation} $$ $$ \begin{equation} \eta = \alpha x^2 + \beta x y + \gamma y^2 \end{equation} $$ ortogonala basvektorer? ### Lösning Vi kan konstruera basvektorer på två sätt: * $\hat{e}_i \propto \frac{\partial \vec{r}}{\partial u_i}$ * $\hat{e}_i \propto \nabla u_i$ Det första sättet innebär att vi behöver räkna ut storheterna $\frac{\partial x}{\partial u_i}$ och $\frac{\partial y}{\partial u_i}$, dvs vi behöver veta $x=x(\xi,\eta),\; y=y(\xi,\eta)$. Vi skulle behöva invertera det givna koordinatsambandet. Det andra sättet kräver istället $\frac{\partial \xi}{\partial x}$ och $\frac{\partial \xi}{\partial y}$ (samt motsvarande för $\eta$) och detta blir enkelt med de givna koordinattransformationerna. Vi får $$ \begin{equation} \nabla \xi = 2x \hat{x} - 2y \hat{y} \end{equation} $$ $$ \begin{equation} \nabla \eta = (2 \alpha x + \beta y)\hat{x} + (\beta x + 2 \gamma y) \hat{y} \end{equation} $$ vilket ger $$ \begin{equation} \nabla \xi \cdot \nabla \eta = 2x (2 \alpha x + \beta y) - 2 y (\beta x + 2 \gamma y) = 4 \alpha x^2 - 4 \gamma y^2 = 0. \end{equation} $$ Detta innebär att vi måste ha $\alpha = \gamma = 0$, medan $\beta$ är godtyckligt. 0 < < < ! ! C O D E _ B L O C K p y c o d ``` p.figure(figsize=(6,6)) CS = p.contour(x,y,xi,5,colors='k') p.clabel(CS, inline=1, fontsize=10) p.text(0.5,1.3,r'$\xi$-yta',color='k',rotation=45) CS = p.contour(x,y,eta,5,colors='r') p.clabel(CS, inline=1, fontsize=10) p.text(1,0.05,r'$\eta$-yta',color='r') p.xlabel(r'$x$') p.ylabel(r'$y$') ``` <!-- dom:FIGURE:[fig/koordinatytor.png, width=600 frac=0.8] --> <!-- begin figure --> <p></p> <!-- end figure -->
function r=rot4z(theta,xscale,yscale,zscale) % r = rot4z(theta) % % rotz produces a 4x4 rotation matrix representing % a rotation by theta radians about the z axis. % % Argument definitions: % % theta = rotation angle in radians if nargin == 1 c = cos(theta); s = sin(theta); r = [c -s 0 0; s c 0 0; 0 0 1 0; 0 0 0 1]; else c = cos(theta); s = sin(theta); r = [c -s 0 xscale; s c 0 yscale; 0 0 1 zscale; 0 0 0 1]; end
module Tactic.Deriving.Quotable where open import Prelude open import Container.Traversable open import Tactic.Reflection open import Tactic.Reflection.Quote.Class open import Tactic.Deriving private -- Bootstrapping qVis : Visibility → Term qVis visible = con (quote visible) [] qVis hidden = con (quote hidden) [] qVis instance′ = con (quote instance′) [] qRel : Relevance → Term qRel relevant = con (quote relevant) [] qRel irrelevant = con (quote irrelevant) [] qArgInfo : ArgInfo → Term qArgInfo (arg-info v r) = con₂ (quote arg-info) (qVis v) (qRel r) qArg : Arg Term → Term qArg (arg i x) = con₂ (quote arg) (qArgInfo i) x qList : List Term → Term qList = foldr (λ x xs → con₂ (quote List._∷_) x xs) (con₀ (quote List.[])) -- Could compute this from the type of the dictionary constructor quoteType : Name → TC Type quoteType d = caseM instanceTelescope d (quote Quotable) of λ { (tel , vs) → pure $ telPi tel $ def d vs `→ def (quote Term) [] } dictConstructor : TC Name dictConstructor = caseM getConstructors (quote Quotable) of λ { (c ∷ []) → pure c ; _ → typeErrorS "impossible" } patArgs : Telescope → List (Arg Pattern) patArgs tel = map (var "x" <$_) tel quoteArgs′ : Nat → Telescope → List Term quoteArgs′ 0 _ = [] quoteArgs′ _ [] = [] quoteArgs′ (suc n) (a ∷ tel) = qArg (def₁ (quote `) (var n []) <$ a) ∷ quoteArgs′ n tel quoteArgs : Nat → Telescope → Term quoteArgs pars tel = qList $ replicate pars (qArg $ hArg (con₀ (quote Term.unknown))) ++ quoteArgs′ (length tel) tel constructorClause : Nat → Name → TC Clause constructorClause pars c = do tel ← drop pars ∘ fst ∘ telView <$> getType c pure (clause (vArg (con c (patArgs tel)) ∷ []) (con₂ (quote Term.con) (lit (name c)) (quoteArgs pars tel))) quoteClauses : Name → TC (List Clause) quoteClauses d = do n ← getParameters d caseM getConstructors d of λ where [] → pure [ absurd-clause (vArg absurd ∷ []) ] cs → mapM (constructorClause n) cs declareQuotableInstance : Name → Name → TC ⊤ declareQuotableInstance iname d = declareDef (iArg iname) =<< instanceType d (quote Quotable) defineQuotableInstance : Name → Name → TC ⊤ defineQuotableInstance iname d = do fname ← freshName ("quote[" & show d & "]") declareDef (vArg fname) =<< quoteType d dictCon ← dictConstructor defineFun iname (clause [] (con₁ dictCon (def₀ fname)) ∷ []) defineFun fname =<< quoteClauses d return _ deriveQuotable : Name → Name → TC ⊤ deriveQuotable iname d = declareQuotableInstance iname d >> defineQuotableInstance iname d
(* Title: The pi-calculus Author/Maintainer: Jesper Bengtson (jebe.dk), 2012 *) theory Weak_Late_Bisim_Pres imports Weak_Late_Bisim_SC Weak_Late_Sim_Pres Strong_Late_Bisim_SC begin lemma tauPres: fixes P :: pi and Q :: pi assumes "P \<approx> Q" shows "\<tau>.(P) \<approx> \<tau>.(Q)" proof - let ?X = "{(\<tau>.(P), \<tau>.(Q)) | P Q. P \<approx> Q}" from assms have "(\<tau>.(P), \<tau>.(Q)) \<in> ?X" by auto thus ?thesis by(coinduct rule: weakBisimCoinduct) (auto simp add: pi.inject intro: Weak_Late_Sim_Pres.tauPres symmetric) qed lemma inputPres: fixes P :: pi and Q :: pi and a :: name and x :: name assumes PSimQ: "\<forall>y. P[x::=y] \<approx> Q[x::=y]" shows "a<x>.P \<approx> a<x>.Q" proof - let ?X = "{(a<x>.P, a<x>.Q) | a x P Q. \<forall>y. P[x::=y] \<approx> Q[x::=y]}" { fix axP axQ p assume "(axP, axQ) \<in> ?X" then obtain a x P Q where A: "\<forall>y. P[x::=y] \<approx> Q[x::=y]" and B: "axP = a<x>.P" and C: "axQ = a<x>.Q" by auto have "\<And>y. ((p::name prm) \<bullet> P)[(p \<bullet> x)::=y] \<approx> (p \<bullet> Q)[(p \<bullet> x)::=y]" proof - fix y from A have "P[x::=(rev p \<bullet> y)] \<approx> Q[x::=(rev p \<bullet> y)]" by blast hence "(p \<bullet> (P[x::=(rev p \<bullet> y)])) \<approx> p \<bullet> (Q[x::=(rev p \<bullet> y)])" by(rule eqvtI) thus "(p \<bullet> P)[(p \<bullet> x)::=y] \<approx> (p \<bullet> Q)[(p \<bullet> x)::=y]" by(simp add: eqvts pt_pi_rev[OF pt_name_inst, OF at_name_inst]) qed hence "((p::name prm) \<bullet> axP, p \<bullet> axQ) \<in> ?X" using B C by auto } hence "eqvt ?X" by(simp add: eqvt_def) from PSimQ have "(a<x>.P, a<x>.Q) \<in> ?X" by auto thus ?thesis proof(coinduct rule: weakBisimCoinduct) case(cSim P Q) thus ?case using \<open>eqvt ?X\<close> by(force intro: inputPres) next case(cSym P Q) thus ?case by(blast dest: symmetric) qed qed lemma outputPres: fixes P :: pi and Q :: pi and a :: name and b :: name assumes "P \<approx> Q" shows "a{b}.(P) \<approx> a{b}.(Q)" proof - let ?X = "{(a{b}.(P), a{b}.(Q)) | a b P Q. P \<approx> Q}" from assms have "(a{b}.(P), a{b}.(Q)) \<in> ?X" by auto thus ?thesis by(coinduct rule: weakBisimCoinduct) (auto simp add: pi.inject intro: Weak_Late_Sim_Pres.outputPres symmetric) qed shows "<\<nu>x>P \<approx> <\<nu>x>Q" proof - let ?X = "{x. \<exists>P Q. P \<approx> Q \<and> (\<exists>a. x = (<\<nu>a>P, <\<nu>a>Q))}" from PBiSimQ have "(<\<nu>x>P, <\<nu>x>Q) \<in> ?X" by blast moreover have "\<And>P Q a. P \<leadsto>\<^sup>^<weakBisim> Q \<Longrightarrow> <\<nu>a>P \<leadsto>\<^sup>^<(?X \<union> weakBisim)> <\<nu>a>Q" proof - fix P Q a assume PSimQ: "P \<leadsto>\<^sup>^<weakBisim> Q" moreover have "\<And>P Q a. P \<approx> Q \<Longrightarrow> (<\<nu>a>P, <\<nu>a>Q) \<in> ?X \<union> weakBisim" by blast moreover have "weakBisim \<subseteq> ?X \<union> weakBisim" by blast moreover have "eqvt weakBisim" by(rule eqvt) moreover have "eqvt (?X \<union> weakBisim)" by(auto simp add: eqvt_def dest: eqvtI)+ ultimately show "<\<nu>a>P \<leadsto>\<^sup>^<(?X \<union> weakBisim)> <\<nu>a>Q" by(rule Weak_Late_Sim_Pres.resPres) qed ultimately show ?thesis using PBiSimQ by(coinduct rule: weakBisimCoinductAux, blast dest: unfoldE) qed assumes "P \<approx> Q" shows "[a\<frown>b]P \<approx> [a\<frown>b]Q" proof - let ?X = "{([a\<frown>b]P, [a\<frown>b]Q) | a b P Q. P \<approx> Q}" from assms have "([a\<frown>b]P, [a\<frown>b]Q) \<in> ?X" by auto thus ?thesis proof(coinduct rule: weakBisimCoinduct) case(cSim P Q) { fix P Q a b assume "P \<approx> Q" hence "P \<leadsto>\<^sup>^<weakBisim> Q" by(rule unfoldE) moreover { fix P Q a assume "P \<approx> Q" moreover have "[a\<frown>a]P \<approx> P" by(rule matchId) ultimately have "[a\<frown>a]P \<approx> Q" by(blast intro: transitive) } moreover have "weakBisim \<subseteq> ?X \<union> weakBisim" by blast ultimately have "[a\<frown>b]P \<leadsto>\<^sup>^<(?X \<union> weakBisim)> [a\<frown>b]Q" by(rule matchPres) } with \<open>(P, Q) \<in> ?X\<close> show ?case by auto next case(cSym P Q) thus ?case by(auto simp add: pi.inject dest: symmetric) qed qed lemma mismatchPres: fixes P :: pi and Q :: pi and a :: name and b :: name assumes "P \<approx> Q" shows "[a\<noteq>b]P \<approx> [a\<noteq>b]Q" proof - let ?X = "{([a\<noteq>b]P, [a\<noteq>b]Q) | a b P Q. P \<approx> Q}" from assms have "([a\<noteq>b]P, [a\<noteq>b]Q) \<in> ?X" by auto thus ?thesis proof(coinduct rule: weakBisimCoinduct) case(cSim P Q) { fix P Q a b assume "P \<approx> Q" hence "P \<leadsto>\<^sup>^<weakBisim> Q" by(rule unfoldE) moreover { fix P Q a b assume "P \<approx> Q" and "(a::name) \<noteq> b" note \<open>P \<approx> Q\<close> moreover from \<open>a \<noteq> b\<close> have "[a\<noteq>b]P \<approx> P" by(rule mismatchId) ultimately have "[a\<noteq>b]P \<approx> Q" by(blast intro: transitive) } moreover have "weakBisim \<subseteq> ?X \<union> weakBisim" by blast ultimately have "[a\<noteq>b]P \<leadsto>\<^sup>^<(?X \<union> weakBisim)> [a\<noteq>b]Q" by(rule mismatchPres) } with \<open>(P, Q) \<in> ?X\<close> show ?case by auto next case(cSym P Q) thus ?case by(auto simp add: pi.inject dest: symmetric) qed qed lemma parPres: fixes P :: pi and Q :: pi and R :: pi assumes "P \<approx> Q" shows "P \<parallel> R \<approx> Q \<parallel> R" proof - let ?ParSet = "{(resChain lst (P \<parallel> R), resChain lst (Q \<parallel> R)) | lst P Q R. P \<approx> Q}" have BC: "\<And>P Q. P \<parallel> Q = resChain [] (P \<parallel> Q)" by auto from assms have "(P \<parallel> R, Q \<parallel> R) \<in> ?ParSet" by(blast intro: BC) thus ?thesis proof(coinduct rule: weakBisimCoinduct) case(cSim PR QR) { fix P Q R lst assume "P \<approx> Q" from eqvtI have "eqvt (?ParSet \<union> weakBisim)" by(auto simp add: eqvt_def, blast) moreover have "\<And>P Q a. (P, Q) \<in> ?ParSet \<union> weakBisim \<Longrightarrow> (<\<nu>a>P, <\<nu>a>Q) \<in> ?ParSet \<union> weakBisim" by(blast intro: resChain.step[THEN sym] resPres) moreover { from \<open>P \<approx> Q\<close> have "P \<leadsto>\<^sup>^<weakBisim> Q" by(rule unfoldE) moreover note \<open>P \<approx> Q\<close> moreover { fix P Q R assume "P \<approx> Q" moreover have "P \<parallel> R = resChain [] (P \<parallel> R)" by simp moreover have "Q \<parallel> R = resChain [] (Q \<parallel> R)" by simp ultimately have "(P \<parallel> R, Q \<parallel> R) \<in> ?ParSet \<union> weakBisim" by blast } moreover { fix P Q a assume A: "(P, Q) \<in> ?ParSet \<union> weakBisim" hence "(<\<nu>a>P, <\<nu>a>Q) \<in> ?ParSet \<union> weakBisim" (is "?goal") apply(auto intro: resPres) by(rule_tac x="a#lst" in exI) auto } ultimately have "(P \<parallel> R) \<leadsto>\<^sup>^<(?ParSet \<union> weakBisim)> (Q \<parallel> R)" using eqvt \<open>eqvt(?ParSet \<union> weakBisim)\<close> by(rule Weak_Late_Sim_Pres.parPres) } ultimately have "resChain lst (P \<parallel> R) \<leadsto>\<^sup>^<(?ParSet \<union> weakBisim)> resChain lst (Q \<parallel> R)" by(rule resChainI) } with \<open>(PR, QR) \<in> ?ParSet\<close> show ?case by blast next case(cSym PR QR) thus ?case by(auto dest: symmetric) qed qed assumes PBisimQ: "P \<approx> Q" shows "!P \<approx> !Q" proof - let ?X = "(bangRel weakBisim)" let ?Y = "Strong_Late_Bisim.bisim O (bangRel weakBisim) O Strong_Late_Bisim.bisim" from eqvt Strong_Late_Bisim.bisimEqvt have eqvtY: "eqvt ?Y" by(blast intro: eqvtBangRel) have XsubY: "?X \<subseteq> ?Y" by(auto intro: Strong_Late_Bisim.reflexive) have RelStay: "\<And>P Q. (P \<parallel> !P, Q) \<in> ?Y \<Longrightarrow> (!P, Q) \<in> ?Y" proof(auto) fix P Q R T assume PBisimQ: "P \<parallel> !P \<sim> Q" and QBRR: "(Q, R) \<in> bangRel weakBisim" and RBisimT: "R \<sim> T" have "!P \<sim> Q" proof - have "!P \<sim> P \<parallel> !P" by(rule Strong_Late_Bisim_SC.bangSC) thus ?thesis using PBisimQ by(rule Strong_Late_Bisim.transitive) qed with QBRR RBisimT show "(!P, T) \<in> ?Y" by blast qed have ParCompose: "\<And>P Q R T. \<lbrakk>P \<approx> Q; (R, T) \<in> ?Y\<rbrakk> \<Longrightarrow> (P \<parallel> R, Q \<parallel> T) \<in> ?Y" proof - fix P Q R T assume PBisimQ: "P \<approx> Q" and RYT: "(R, T) \<in> ?Y" thus "(P \<parallel> R, Q \<parallel> T) \<in> ?Y" proof(auto) fix T' R' assume T'BisimT: "T' \<sim> T" and RBisimR': "R \<sim> R'" and R'BRT': "(R', T') \<in> bangRel weakBisim" have "P \<parallel> R \<sim> P \<parallel> R'" proof - from RBisimR' have "R \<parallel> P \<sim> R' \<parallel> P" by(rule Strong_Late_Bisim_Pres.parPres) moreover have "P \<parallel> R \<sim> R \<parallel> P" and "R' \<parallel> P \<sim> P \<parallel> R'" by(rule Strong_Late_Bisim_SC.parSym)+ ultimately show ?thesis by(blast intro: Strong_Late_Bisim.transitive) qed moreover from PBisimQ R'BRT' have "(P \<parallel> R', Q \<parallel> T') \<in> bangRel weakBisim" by(rule BRPar) moreover have "Q \<parallel> T' \<sim> Q \<parallel> T" proof - from T'BisimT have "T' \<parallel> Q \<sim> T \<parallel> Q" by(rule Strong_Late_Bisim_Pres.parPres) moreover have "Q \<parallel> T' \<sim> T' \<parallel> Q" and "T \<parallel> Q \<sim> Q \<parallel> T" by(rule Strong_Late_Bisim_SC.parSym)+ ultimately show ?thesis by(blast intro: Strong_Late_Bisim.transitive) qed ultimately show ?thesis by blast qed qed have ResCong: "\<And>P Q x. (P, Q) \<in> ?Y \<Longrightarrow> (<\<nu>x>P, <\<nu>x>Q) \<in> ?Y" by(auto intro: BRRes Strong_Late_Bisim_Pres.resPres transitive) from PBisimQ have "(!P, !Q) \<in> ?X" by(rule BRBang) moreover from eqvt have "eqvt (bangRel weakBisim)" by(rule eqvtBangRel) ultimately show ?thesis proof(coinduct rule: weakBisimTransitiveCoinduct) case(cSim P Q) from \<open>(P, Q) \<in> ?X\<close> show "P \<leadsto>\<^sup>^<?Y> Q" proof(induct) case(BRBang P Q) have "P \<approx> Q" by fact moreover hence "P \<leadsto>\<^sup>^<weakBisim> Q" by(blast dest: unfoldE) moreover have "\<And>P Q. P \<approx> Q \<Longrightarrow> P \<leadsto>\<^sup>^<weakBisim> Q" by(blast dest: unfoldE) moreover from Strong_Late_Bisim.bisimEqvt eqvt have "eqvt ?Y" by(blast intro: eqvtBangRel) ultimately show "!P \<leadsto>\<^sup>^<?Y> !Q" using ParCompose ResCong RelStay XsubY by(rule_tac Weak_Late_Sim_Pres.bangPres, simp_all) next case(BRPar P Q R T) have PBiSimQ: "P \<approx> Q" by fact have RBangRelT: "(R, T) \<in> ?X" by fact have RSimT: "R \<leadsto>\<^sup>^<?Y> T" by fact moreover from PBiSimQ have "P \<leadsto>\<^sup>^<weakBisim> Q" by(blast dest: unfoldE) moreover from RBangRelT have "(R, T) \<in> ?Y" by(blast intro: Strong_Late_Bisim.reflexive) ultimately show "P \<parallel> R \<leadsto>\<^sup>^<?Y> Q \<parallel> T" using ParCompose ResCong eqvt eqvtY \<open>P \<approx> Q\<close> by(rule_tac Weak_Late_Sim_Pres.parCompose) next case(BRRes P Q x) have "P \<leadsto>\<^sup>^<?Y> Q" by fact thus "<\<nu>x>P \<leadsto>\<^sup>^<?Y> <\<nu>x>Q" using ResCong eqvtY XsubY by(rule_tac Weak_Late_Sim_Pres.resPres, simp_all) qed next case(cSym P Q) thus ?case by(metis symmetric bangRelSymetric) qed qed end
#ifndef BOOST_NETWORK_URL_HTTP_URL_HPP_ #define BOOST_NETWORK_URL_HTTP_URL_HPP_ // Copyright 2009 Dean Michael Berris, Jeroen Habraken. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include <boost/cstdint.hpp> #include <boost/algorithm/string/predicate.hpp> #include <boost/network/tags.hpp> #include <boost/network/traits/string.hpp> #include <boost/network/uri/basic_uri_fwd.hpp> #include <boost/network/uri/http/detail/parse_specific.hpp> namespace boost { namespace network { namespace uri { template <> struct basic_uri<tags::http_default_8bit_tcp_resolve> : uri_base<tags::http_default_8bit_tcp_resolve> { typedef uri_base<tags::http_default_8bit_tcp_resolve>::string_type string_type; using uri_base<tags::http_default_8bit_tcp_resolve>::operator=; using uri_base<tags::http_default_8bit_tcp_resolve>::swap; basic_uri() : uri_base<tags::http_default_8bit_tcp_resolve>() {} basic_uri(uri_base<tags::http_default_8bit_tcp_resolve>::string_type const & uri) : uri_base<tags::http_default_8bit_tcp_resolve>(uri) {} boost::uint16_t port() const { return parts_.port ? *(parts_.port) : (boost::iequals(parts_.scheme, string_type("https")) ? 443u : 80u); } string_type path() const { return (parts_.path == "") ? string_type("/") : parts_.path; } }; inline boost::uint16_t port(basic_uri<tags::http_default_8bit_tcp_resolve> const & uri) { return uri.port(); } } // namespace uri } // namespace network } // namespace boost #endif
We at Biofeedback Therapy understand that privacy of your personal information is extremely important. This policy describes the types of information we receive and collect when you access and use our website. All webservers tend to track basic information about their visitors. As most other websites do we use some of the data contained in log files for SEO purposes (search engine optimisation) and to improve visitor experience, the information contained in the log files includes your IP (internet protocol) address, your internet service provider, the browser that you used to access our site, the time you visited our site, the length of your stay, and the pages you accessed. None of this information is used to personally identify specific visitors to our web site. We at 'Biofeedback Therapy' have third party advertisements placed on our website, they include ads and affiliate links that when clicked on place a cookie onto your computer. A cookie is a text file that is downloaded to your computer, and is used to store information such as your preferences when visiting various websites, which links you clicked on etc (no personally identifiable information). Some third parties may use web beacons also. Web beacons used in combination with cookies allow a better understanding of browsing behaviour, they gather very simple statistics, none of which can identify any individual. You can choose to disable or turn off cookies in your browser settings, so that no other information except your IP address is available, although disabling cookies may cause problems when browsing certain websites. We suggest consulting the Help section of your browser or taking a look at the About Cookies website which offers guidance for all modern browsers. The 'DoubleClick DART cookie' refers to a cookie used by Google in the ads served on its partners websites (Google Adsense ads for example). Whenever you visit a website such as ours, that uses DoubleClick advertising, a cookie is placed on your computer. Third party vendors, including Google, use these cookies to serve specific ads based on your individual interests / browsing history (for example based on your prior visits to this website and other websites throughout the internet). DART cookies do not track any kind of personal information. DART is an acronym for 'Dynamic Advertising Reporting and Targeting'. If you want to opt-out of the use of the DART cookie please visit Google's advertising opt-out page.
State Before: R✝ : Type u S : Type ?u.71352 inst✝¹ : Ring R✝ R : Type u inst✝ : CommRing R p : R[X] n : ℕ ⊢ coeff (map (algebraMap { x // x ∈ Subring.closure ↑(frange p) } R) (restriction p)) n = coeff p n State After: no goals Tactic: rw [coeff_map, Algebra.algebraMap_ofSubring_apply, coeff_restriction]
lemma prime_odd_nat: "prime p \<Longrightarrow> p > (2::nat) \<Longrightarrow> odd p"
C ********************************************************* C * * C * TEST NUMBER: 04.02.01.02/10 * C * TEST TITLE : Polyline bundle index * C * * C * PHIGS Validation Tests, produced by NIST * C * * C ********************************************************* COMMON /GLOBNU/ CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR, 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN, 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN, 3 DUMINT, DUMRL INTEGER CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR, 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN, 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN, 3 DUMINT(20), ERRIND REAL DUMRL(20) COMMON /GLOBCH/ PIDENT, GLBERR, TSTMSG, FUNCID, 1 DUMCH CHARACTER PIDENT*40, GLBERR*60, TSTMSG*900, FUNCID*80, 1 DUMCH(20)*20 COMMON /DIALOG/ DOUTYP, DINTYP, DSTDNR, DSTRID, PSTRID, DTCLIM, 1 SCRMOD, DTXCI, SPECWT, 2 DSIZE, EFRAC, DYXRAT, SYXRAT, MTRPDC, WCPDC, QVIS INTEGER DOUTYP, DINTYP, DSTDNR, DSTRID, PSTRID, DTCLIM, 1 SCRMOD, DTXCI, SPECWT REAL DSIZE, EFRAC, DYXRAT, SYXRAT, MTRPDC, WCPDC, QVIS C aspect source C bundled individual INTEGER PBUNDL, PINDIV PARAMETER (PBUNDL = 0, PINDIV = 1) C linetype INTEGER PLSOLI, PLDASH, PLDOT, PLDASD PARAMETER (PLSOLI = 1, PLDASH = 2, PLDOT = 3, PLDASD = 4) C colour model INTEGER PRGB, PCIE, PHSV, PHLS PARAMETER (PRGB = 1, PCIE = 2, PHSV = 3, PHLS = 4) C colour available INTEGER PMONOC, PCOLOR PARAMETER (PMONOC=0, PCOLOR=1) C type of returned value INTEGER PSET, PREALI PARAMETER (PSET = 0, PREALI = 1) INTEGER PICSTR, TXCI, BUNEL, UNDF(3), EXPLCT INTEGER SZBT, BUNDIS, BUNDIF, IX, PERM(10), RNDINT REAL YLOC, YINCR, RAD,CENTX,CENTY,PI,XA(9),YA(9) INTEGER IDUM1, IDUM2, IDUM3, IDUM4, IDUM5, IDUM6, IDUM7 CALL INITGL ('04.02.01.02/10') C open PHIGS CALL XPOPPH (ERRFIL, MEMUN) C set-up of workstation and dialogue area PICSTR = 101 TXCI = 1 CALL SETDLG (PICSTR, 801,TXCI) CALL PSCMD (WKID, PRGB) CALL POPST (PICSTR) C by convention, view #1 is for picture CALL PSVWI (1) C use bundled attributes CALL SETASF (PBUNDL) C szbt = maximum size of bundle table CALL PQWKSL (SPECWT, ERRIND, SZBT, IDUM1, IDUM2, IDUM3, 1 IDUM4, IDUM5, IDUM6, IDUM7) CALL CHKINQ ('pqwksl', ERRIND) C *** *** *** *** polyline index C mark start of polyline bundles CALL PLB (1) CALL SETMSG ('3 4 5 6', 'A defined polyline index should ' // 1 'cause the addressed entry in the bundle table ' // 2 'to be used when rendering a polyline.') C bundis = # of bundles to be displayed BUNDIS = MIN(8, SZBT) C initialize bundis to linetype=1, linewidth=1.0, color index=1 DO 60 IX = 1,BUNDIS CALL PSPLR (WKID, IX, 1, 1.0, 1) 60 CONTINUE C bundif = randomly selected bundle, set to C linetype=2, linewidth=2.0, color index = 2 BUNDIF = RNDINT(1, BUNDIS) CALL PSPLR (WKID, BUNDIF, 2, 2.0, 2) C draw and label actual XA(1) = 0.3 XA(2) = 0.55 YINCR = 0.8/BUNDIS YLOC = 0.9 CALL NUMLAB (BUNDIS, 0.2, YLOC, YINCR) DO 100 IX = 1,BUNDIS YA(1) = YLOC YA(2) = YLOC CALL PSPLI (IX) CALL PPL (2, XA,YA) YLOC = YLOC-YINCR 100 CONTINUE C mark end of linetypes CALL PLB (2) CALL DCHPFV ('DEFINED POLYLINE INDICES: Which line is ' // 1 'different?', BUNDIS, BUNDIF) C clear out last display from structure CALL PSEP (1) CALL PDELLB (1,2) CALL SETMSG ('3 4 5 7', 'An undefined polyline index ' // 1 'should cause bundle number 1 in the polyline ' // 2 'bundle table to be used when rendering a ' // 3 'polyline.') C set index #1 in bundle table to linetype=2, width=2.0, color index=2 CALL PSPLR (WKID, 1, 2, 2.0, 2) C undf1,undf2,undf3 = 3 undefined polyline indices UNDF(1) = SZBT + 1 UNDF(2) = SZBT + 10 UNDF(3) = SZBT + 90 C explct = number of explicit lines of bundle #1 = random integer C from 0 to 4 EXPLCT = RNDINT(0,4) BUNDIS = EXPLCT+3 CALL RNPERM (BUNDIS, PERM) C draw star with color #1 RAD = .15 CENTX = .5 CENTY = .75 PI = 3.14159265 DO 400 IX = 1,6 YA(IX) = CENTY + RAD*COS((4*PI*IX)/5) XA(IX) = CENTX + RAD*SIN((4*PI*IX)/5) 400 CONTINUE CALL PSPLI (1) CALL PPL (6,XA,YA) C display interleaved: three lines with bundles u1,u2,u3, C and explct lines with bundle #1 YLOC = 0.5 YINCR = 0.5 / 8 XA(1) = .1 XA(2) = .9 DO 500 IX = 1,BUNDIS BUNEL = PERM(IX) IF (BUNEL .LE. 3) THEN CALL PSPLI (UNDF(BUNEL)) ELSE CALL PSPLI (1) ENDIF YA(1) = YLOC YA(2) = YLOC CALL PPL (2, XA,YA) YLOC = YLOC-YINCR 500 CONTINUE CALL DCHPFV ('UNDEFINED POLYLINE INDICES: How many ' // 1 'of the horizontal lines have the same ' // 2 'attributes as the star?', 12, BUNDIS) 666 CONTINUE C wrap it up CALL ENDIT END
In the aftermath of the earthquake , the government of Canada announced that it would match the donations of Canadians up to a total of C $ 50 million . Canadians were able to donate through the Humanitarian Coalition which distributed funds to partner organizations working in the field . During this time the Humanitarian Coalition raised over C $ 15 Million . After a United Nations call for help for the people affected by the earthquake , Canada pledged an additional C $ 60 million in aid on 19 January 2010 , bringing Canada 's total contribution to C $ 135 million . By 8 February 2010 , the federal International Co @-@ operation Department , through the Canadian International Development Agency ( <unk> ) , had already provided about C $ 85 million in humanitarian aid through UN agencies , the International Federation of Red Cross and Red Crescent Societies and to organizations such as CARE , Médecins du Monde , Save the Children , Oxfam Quebec , the Centre for International Studies and co @-@ operation , and World Vision . On 23 January 2010 , Canadian Prime Minister Stephen Harper announced that the federal government had lifted the limit on the amount of money allocated for matching individual donations to relief efforts , and that the federal government would continue to match individual donations until 12 February 2010 ; by the deadline , Canadians had privately raised C $ 220 million . On top of matching donations , International Co @-@ operation Minister Bev Oda pledged an additional C $ 290 million in long @-@ term relief to be spent between 2010 and 2012 , including C $ 8 million in debt relief to Haiti , part of a broader cancellation of the country 's overall World Bank debt . The government 's commitment to provide C $ 550 million in aid and debt relief and Canadians ' individual donations amount to a total of C $ 770 million .
Load LFindLoad. From lfind Require Import LFind. From QuickChick Require Import QuickChick. From adtind Require Import goal33. Derive Show for natural. Derive Arbitrary for natural. Instance Dec_Eq_natural : Dec_Eq natural. Proof. dec_eq. Qed. Lemma conj6synthconj1 : forall (lv0 : natural) (lv1 : natural), (@eq natural (plus Zero lv0) (plus lv1 Zero)). Admitted. QuickChick conj6synthconj1.
(* * Copyright 2021, Florian Haftmann * * SPDX-License-Identifier: BSD-2-Clause *) theory Singleton_Bit_Shifts imports "HOL-Library.Word" Bit_Shifts_Infix_Syntax begin definition shiftl1 :: \<open>'a::len word \<Rightarrow> 'a word\<close> where \<open>shiftl1 = push_bit 1\<close> lemma bit_shiftl1_iff [bit_simps]: \<open>bit (shiftl1 w) n \<longleftrightarrow> 0 < n \<and> n < LENGTH('a) \<and> bit w (n - 1)\<close> for w :: \<open>'a::len word\<close> by (simp only: shiftl1_def bit_push_bit_iff) auto definition shiftr1 :: \<open>'a::len word \<Rightarrow> 'a word\<close> where \<open>shiftr1 = drop_bit 1\<close> lemma bit_shiftr1_iff [bit_simps]: \<open>bit (shiftr1 w) n \<longleftrightarrow> bit w (Suc n)\<close> for w :: \<open>'a::len word\<close> by (simp add: shiftr1_def bit_drop_bit_eq) definition sshiftr1 :: \<open>'a::len word \<Rightarrow> 'a word\<close> where \<open>sshiftr1 \<equiv> signed_drop_bit 1\<close> lemma bit_sshiftr1_iff [bit_simps]: \<open>bit (sshiftr1 w) n \<longleftrightarrow> bit w (if n = LENGTH('a) - 1 then LENGTH('a) - 1 else Suc n)\<close> for w :: \<open>'a::len word\<close> by (auto simp add: sshiftr1_def bit_signed_drop_bit_iff) lemma shiftr1_1: "shiftr1 (1::'a::len word) = 0" by (simp add: shiftr1_def) lemma sshiftr1_eq: \<open>sshiftr1 w = word_of_int (sint w div 2)\<close> by (rule bit_word_eqI) (auto simp add: bit_simps min_def simp flip: bit_Suc elim: le_SucE) lemma shiftl1_eq: \<open>shiftl1 w = word_of_int (2 * uint w)\<close> by (rule bit_word_eqI) (auto simp add: bit_simps) lemma shiftr1_eq: \<open>shiftr1 w = word_of_int (uint w div 2)\<close> by (rule bit_word_eqI) (simp add: bit_simps flip: bit_Suc) lemma shiftl1_rev: "shiftl1 w = word_reverse (shiftr1 (word_reverse w))" by (rule bit_word_eqI) (auto simp add: bit_simps Suc_diff_Suc simp flip: bit_Suc) lemma shiftl1_p: "shiftl1 w = w + w" for w :: "'a::len word" by (simp add: shiftl1_def) lemma shiftr1_bintr: "(shiftr1 (numeral w) :: 'a::len word) = word_of_int (take_bit LENGTH('a) (numeral w) div 2)" by (rule bit_word_eqI) (simp add: bit_simps bit_numeral_iff [where ?'a = int] flip: bit_Suc) lemma sshiftr1_sbintr: "(sshiftr1 (numeral w) :: 'a::len word) = word_of_int (signed_take_bit (LENGTH('a) - 1) (numeral w) div 2)" apply (cases \<open>LENGTH('a)\<close>) apply simp_all apply (rule bit_word_eqI) apply (auto simp add: bit_simps min_def simp flip: bit_Suc elim: le_SucE) done lemma shiftl1_wi: "shiftl1 (word_of_int w) = word_of_int (2 * w)" by (rule bit_word_eqI) (auto simp add: bit_simps) lemma shiftl1_numeral: "shiftl1 (numeral w) = numeral (Num.Bit0 w)" unfolding word_numeral_alt shiftl1_wi by simp lemma shiftl1_neg_numeral: "shiftl1 (- numeral w) = - numeral (Num.Bit0 w)" unfolding word_neg_numeral_alt shiftl1_wi by simp lemma shiftl1_0: "shiftl1 0 = 0" by (simp add: shiftl1_def) lemma shiftl1_def_u: "shiftl1 w = word_of_int (2 * uint w)" by (fact shiftl1_eq) lemma shiftl1_def_s: "shiftl1 w = word_of_int (2 * sint w)" by (simp add: shiftl1_def) lemma shiftr1_0: "shiftr1 0 = 0" by (simp add: shiftr1_def) lemma sshiftr1_0: "sshiftr1 0 = 0" by (simp add: sshiftr1_def) lemma sshiftr1_n1: "sshiftr1 (- 1) = - 1" by (simp add: sshiftr1_def) lemma uint_shiftr1: "uint (shiftr1 w) = uint w div 2" by (rule bit_eqI) (simp add: bit_simps flip: bit_Suc) lemma shiftr1_div_2: "uint (shiftr1 w) = uint w div 2" by (fact uint_shiftr1) lemma sshiftr1_div_2: "sint (sshiftr1 w) = sint w div 2" by (rule bit_eqI) (auto simp add: bit_simps ac_simps min_def simp flip: bit_Suc elim: le_SucE) lemma nth_shiftl1: "bit (shiftl1 w) n \<longleftrightarrow> n < size w \<and> n > 0 \<and> bit w (n - 1)" by (auto simp add: word_size bit_simps) lemma nth_shiftr1: "bit (shiftr1 w) n = bit w (Suc n)" by (fact bit_shiftr1_iff) lemma nth_sshiftr1: "bit (sshiftr1 w) n = (if n = size w - 1 then bit w n else bit w (Suc n))" by (auto simp add: word_size bit_simps) lemma shiftl_power: "(shiftl1 ^^ x) (y::'a::len word) = 2 ^ x * y" by (induction x) (simp_all add: shiftl1_def) lemma le_shiftr1: \<open>shiftr1 u \<le> shiftr1 v\<close> if \<open>u \<le> v\<close> using that by (simp add: word_le_nat_alt unat_div div_le_mono shiftr1_def drop_bit_Suc) lemma le_shiftr1': "\<lbrakk> shiftr1 u \<le> shiftr1 v ; shiftr1 u \<noteq> shiftr1 v \<rbrakk> \<Longrightarrow> u \<le> v" by (meson dual_order.antisym le_cases le_shiftr1) lemma sshiftr_eq_funpow_sshiftr1: \<open>w >>> n = (sshiftr1 ^^ n) w\<close> apply (rule sym) apply (simp add: sshiftr1_def sshiftr_def) apply (induction n) apply simp_all done end
""" ``` t = find_threshold(Balanced(), histogram, edges) ``` Balanced histogram thresholding weighs a histogram and compares the overall weight of each side of the histogram. Each iteration weight is removed from the heavier side and the start/middle/end points are recalculated. The agorithm continues untill the start and end points have converged to meet the middle point. # Output Returns a real number `t` that specifies the threshold. # Details If after the start and end points have converged the final position is at the initial start or end point then the histogram must have a single peak and has failed to find a threshold. In this case the algorithm will fall back to using the `UnimodalRosin` method to select a threshold. # Arguments The function arguments are described in more detail below. ## `histogram` An `AbstractArray` storing the frequency distribution. ## `edges` An `AbstractRange` specifying how the intervals for the frequency distribution are divided. # Example Compute the threshold for the "cameraman" image in the `TestImages` package. ```julia using TestImages, ImageContrastAdjustment, HistogramThresholding img = testimage("cameraman") edges, counts = build_histogram(img, 256) #= The `counts` array stores at index 0 the frequencies that were below the first bin edge. Since we are seeking a threshold over the interval partitioned by `edges` we need to discard the first bin in `counts` so that the dimensions of `edges` and `counts` match. =# t = find_threshold(Balanced(), counts[1:end], edges) ``` # Reference 1. "BI-LEVEL IMAGE THRESHOLDING - A Fast Method", Proceedings of the First International Conference on Bio-inspired Systems and Signal Processing, 2008. Available: [10.5220/0001064300700076](https://doi.org/10.5220/0001064300700076) """ function find_threshold(algorithm::Balanced, histogram::AbstractArray, edges::AbstractRange) # set initial start/middle/end points and weigths Iₛ = 1 Iₑ = length(histogram) Iₘ = round(Int, (Iₛ + Iₑ) / 2) Wₗ = 0 Wᵣ = 0 for i = 1:Iₘ Wₗ += histogram[i] end for i = Iₘ:Iₑ Wᵣ += histogram[i] end while Iₛ < Iₑ if Wₗ < Wᵣ Wᵣ -= histogram[Iₑ] Iₑ -= 1 if (Iₛ + Iₑ) / 2 < Iₘ Wₗ -= histogram[Iₘ] Wᵣ += histogram[Iₘ] Iₘ -= 1 end else Wₗ -= histogram[Iₛ] Iₛ += 1 if (Iₛ + Iₑ) / 2 > Iₘ Wₗ += histogram[Iₘ + 1] Wᵣ -= histogram[Iₘ + 1] Iₘ += 1 end end end if Iₘ == 1 || Iₘ == length(histogram) @warn "Failed to threshold. Falling back to `UnimodalRosin` method." return find_threshold(UnimodalRosin(), histogram, edges) else return edges[Iₘ] end end
(* Title: Kleene algebra with tests Author: Alasdair Armstrong, Victor B. F. Gomes, Georg Struth Maintainer: Georg Struth <g.struth at sheffield.ac.uk> *) header {* Kleene Algebra with Tests *} theory KAT imports "../DRA_Base" Test_Dioids begin text {* First, we study left Kleene algebras with tests which also have only a left zero. These structures can be expanded to demonic refinement algebras. *} class left_kat_zerol = left_kleene_algebra_zerol + dioid_tests_zerol begin lemma star_test_export1: "test p \<Longrightarrow> (p\<cdot>x)\<^sup>\<star>\<cdot>p \<le> p\<cdot>x\<^sup>\<star>" by (metis mult_isol mult_oner star_iso star_slide test_eq3 test_one_var) lemma star_test_export2: "test p \<Longrightarrow> (p\<cdot>x)\<^sup>\<star>\<cdot>p \<le> x\<^sup>\<star>\<cdot>p" by (metis mult_isor star2 star_denest star_invol star_iso star_slide star_subdist_var_2 star_subid test_ub_var) lemma star_test_export_left: "\<lbrakk>test p; x\<cdot>p \<le> p\<cdot>x\<rbrakk> \<Longrightarrow> x\<^sup>\<star>\<cdot>p = p\<cdot>(x\<cdot>p)\<^sup>\<star>" apply (rule antisym) apply (metis mult.assoc mult_isol_var star_sim1 test_double_comp_var test_mult_idem_var test_mult_lb1) by (metis star_slide star_test_export2) lemma star_test_export_right: "\<lbrakk>test p; x\<cdot>p \<le> p\<cdot>x\<rbrakk> \<Longrightarrow> x\<^sup>\<star>\<cdot>p = (p\<cdot>x)\<^sup>\<star>\<cdot>p" by (metis star_slide star_test_export_left) lemma star_test_export2_left: "\<lbrakk>test p; p\<cdot>x = x\<cdot>p\<rbrakk> \<Longrightarrow> x\<^sup>\<star>\<cdot>p = p\<cdot>(p\<cdot>x)\<^sup>\<star>" by (metis order_refl star_test_export_left) lemma star_test_export2_right: "\<lbrakk>test p; p\<cdot>x = x\<cdot>p\<rbrakk> \<Longrightarrow> x\<^sup>\<star>\<cdot>p = (x\<cdot>p)\<^sup>\<star>\<cdot>p" by (metis star_slide star_test_export2_left) lemma star_test_folk: "\<lbrakk>test p; p\<cdot>x = x\<cdot>p; p\<cdot>y = y\<cdot>p\<rbrakk> \<Longrightarrow> (p\<cdot>x + !p\<cdot>y)\<^sup>\<star>\<cdot>p = p\<cdot>(p\<cdot>x)\<^sup>\<star>" proof - assume assms: "test p" "p\<cdot>x = x\<cdot>p" "p\<cdot>y = y\<cdot>p" hence "(p\<cdot>x + !p\<cdot>y)\<^sup>\<star>\<cdot>p = p\<cdot>(p\<cdot>p\<cdot>x + p\<cdot>!p\<cdot>y)\<^sup>\<star>" by (metis comm_add_var test_comp_closed_var star_test_export2_left distrib_left mult.assoc) thus ?thesis by (metis assms(1) test_double_comp_var test_mult_comp test_mult_idem_var add_zeror annil) qed end class kat_zerol = kleene_algebra_zerol + dioid_tests_zerol begin subclass left_kat_zerol by (unfold_locales) lemma star_sim_right: "\<lbrakk>test p; p\<cdot>x = x\<cdot>p\<rbrakk> \<Longrightarrow> p\<cdot>x\<^sup>\<star> = (p\<cdot>x)\<^sup>\<star>\<cdot>p" by (metis mult.assoc star_sim3 test_mult_idem_var) lemma star_sim_left: "\<lbrakk>test p; p\<cdot>x = x\<cdot>p\<rbrakk> \<Longrightarrow> p\<cdot>x\<^sup>\<star> = p\<cdot>(x\<cdot>p)\<^sup>\<star>" by (metis star_sim_right star_slide) lemma comm_star: "\<lbrakk>test p; p\<cdot>x = x\<cdot>p; p\<cdot>y = y\<cdot>p\<rbrakk> \<Longrightarrow> p\<cdot>x\<cdot>(p\<cdot>y)\<^sup>\<star> = p\<cdot>x\<cdot>y\<^sup>\<star>" by (metis star_sim_right mult.assoc star_slide) lemma star_sim_right_var: "\<lbrakk>test p; p\<cdot>x = x\<cdot>p\<rbrakk> \<Longrightarrow> x\<^sup>\<star>\<cdot>p = p\<cdot>(x\<cdot>p)\<^sup>\<star>" by (metis mult.assoc star_sim3 test_mult_idem_var) lemma star_folk_var[simp]: "\<lbrakk>test p; p\<cdot>x = x\<cdot>p; p\<cdot>y = y\<cdot>p\<rbrakk> \<Longrightarrow> (p\<cdot>x + !p\<cdot>y)\<^sup>\<star>\<cdot>p = p\<cdot>x\<^sup>\<star>" by (metis star_test_folk comm_star mult_onel mult_oner) lemma star_folk_var2[simp]: "\<lbrakk>test p; !p\<cdot>x = x\<cdot>!p; !p\<cdot>y = y\<cdot>!p\<rbrakk> \<Longrightarrow> (p\<cdot>x + !p\<cdot>y)\<^sup>\<star>\<cdot>!p = !p\<cdot>y\<^sup>\<star>" by (metis star_folk_var add.commute test_def) end text {* Finally, we define Kleene algebra with tests. *} class kat = kleene_algebra + dioid_tests begin subclass kat_zerol apply (unfold_locales) by (metis star_inductr) end end
(* * Copyright 2022, Proofcraft Pty Ltd * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) * * SPDX-License-Identifier: GPL-2.0-only *) theory ArchUntyped_AI imports Untyped_AI begin context Arch begin global_naming AARCH64 named_theorems Untyped_AI_assms lemma of_bl_nat_to_cref[Untyped_AI_assms]: "\<lbrakk> x < 2 ^ bits; bits < word_bits \<rbrakk> \<Longrightarrow> (of_bl (nat_to_cref bits x) :: word64) = of_nat x" apply (clarsimp intro!: less_mask_eq simp: nat_to_cref_def of_drop_to_bl word_size word_less_nat_alt word_bits_def) by (metis add_lessD1 le_unat_uoi nat_le_iff_add nat_le_linear) lemma cnode_cap_ex_cte[Untyped_AI_assms]: "\<lbrakk> is_cnode_cap cap; cte_wp_at (\<lambda>c. \<exists>m. cap = mask_cap m c) p s; (s::'state_ext::state_ext state) \<turnstile> cap; valid_objs s; pspace_aligned s \<rbrakk> \<Longrightarrow> ex_cte_cap_wp_to is_cnode_cap (obj_ref_of cap, nat_to_cref (bits_of cap) x) s" apply (simp only: ex_cte_cap_wp_to_def) apply (rule exI, erule cte_wp_at_weakenE) apply (clarsimp simp: is_cap_simps bits_of_def) apply (case_tac c, simp_all add: mask_cap_def cap_rights_update_def split:bool.splits) apply (clarsimp simp: nat_to_cref_def word_bits_def) apply (erule(2) valid_CNodeCapE) apply (simp add: word_bits_def cte_level_bits_def) done lemma inj_on_nat_to_cref[Untyped_AI_assms]: "bits < word_bits \<Longrightarrow> inj_on (nat_to_cref bits) {..< 2 ^ bits}" apply (rule inj_onI) apply (drule arg_cong[where f="\<lambda>x. replicate (64 - bits) False @ x"]) apply (subst(asm) word_bl.Abs_inject[where 'a=64, symmetric]) apply (simp add: nat_to_cref_def word_bits_def) apply (simp add: nat_to_cref_def word_bits_def) apply (simp add: of_bl_rep_False of_bl_nat_to_cref) apply (erule word_unat.Abs_eqD) apply (simp only: unats_def mem_simps) apply (erule order_less_le_trans) apply (rule power_increasing, (simp add: word_bits_def) +) apply (simp only: unats_def mem_simps) apply (erule order_less_le_trans) apply (rule power_increasing, simp+) done lemma data_to_obj_type_sp[Untyped_AI_assms]: "\<lbrace>P\<rbrace> data_to_obj_type x \<lbrace>\<lambda>ts (s::'state_ext::state_ext state). ts \<noteq> ArchObject ASIDPoolObj \<and> P s\<rbrace>, -" unfolding data_to_obj_type_def apply (rule hoare_pre) apply (wp|wpc)+ apply clarsimp apply (simp add: arch_data_to_obj_type_def split: if_split_asm) done lemma dui_inv_wf[wp, Untyped_AI_assms]: "\<lbrace>invs and cte_wp_at ((=) (cap.UntypedCap dev w sz idx)) slot and (\<lambda>s. \<forall>cap \<in> set cs. is_cnode_cap cap \<longrightarrow> (\<forall>r\<in>cte_refs cap (interrupt_irq_node s). ex_cte_cap_wp_to is_cnode_cap r s)) and (\<lambda>s. \<forall>x \<in> set cs. s \<turnstile> x)\<rbrace> decode_untyped_invocation label args slot (cap.UntypedCap dev w sz idx) cs \<lbrace>valid_untyped_inv\<rbrace>,-" proof - have inj: "\<And>node_cap s. \<lbrakk>is_cnode_cap node_cap; unat (args ! 5) \<le> 2 ^ bits_of node_cap - unat (args ! 4);valid_cap node_cap s\<rbrakk> \<Longrightarrow> inj_on (Pair (obj_ref_of node_cap) \<circ> nat_to_cref (bits_of node_cap)) {unat (args ! 4)..<unat (args ! 4) + unat (args ! 5)}" apply (simp add: comp_def) apply (rule inj_on_split) apply (rule subset_inj_on [OF inj_on_nat_to_cref]) apply (clarsimp simp: is_cap_simps bits_of_def valid_cap_def word_bits_def cap_aligned_def) apply clarsimp apply (rule less_le_trans) apply assumption apply (simp add:le_diff_conv2) done have nasty_strengthen: "\<And>S a f s. (\<forall>x\<in>S. cte_wp_at ((=) cap.NullCap) (a, f x) s) \<Longrightarrow> cte_wp_at (\<lambda>c. c \<noteq> cap.NullCap) slot s \<longrightarrow> slot \<notin> (Pair a \<circ> f) ` S" by (auto simp:cte_wp_at_caps_of_state) show ?thesis apply (simp add: decode_untyped_invocation_def unlessE_def[symmetric] unlessE_whenE split del: if_split) apply (rule validE_R_sp[OF whenE_throwError_sp] validE_R_sp[OF data_to_obj_type_sp] validE_R_sp[OF dui_sp_helper] validE_R_sp[OF map_ensure_empty])+ apply clarsimp apply (rule hoare_pre) apply (wp whenE_throwError_wp[THEN validE_validE_R] check_children_wp map_ensure_empty_wp) apply (clarsimp simp: distinct_map cases_imp_eq) apply (subgoal_tac "s \<turnstile> node_cap") prefer 2 apply (erule disjE) apply (drule bspec [where x = "cs ! 0"],clarsimp)+ apply fastforce apply clarsimp apply (clarsimp simp: cte_wp_at_caps_of_state) apply (drule(1) caps_of_state_valid[rotated])+ apply assumption apply (subgoal_tac "\<forall>r\<in>cte_refs node_cap (interrupt_irq_node s). ex_cte_cap_wp_to is_cnode_cap r s") apply (clarsimp simp: cte_wp_at_caps_of_state) apply (frule(1) caps_of_state_valid[rotated]) apply (clarsimp simp: not_less) apply (frule(2) inj) apply (clarsimp simp: comp_def) apply (frule(1) caps_of_state_valid) apply (simp add: nasty_strengthen[unfolded o_def] cte_wp_at_caps_of_state) apply (intro conjI) apply (intro impI) apply (frule range_cover_stuff[where w=w and rv = 0 and sz = sz], simp_all)[1] apply (clarsimp simp: valid_cap_simps cap_aligned_def)+ apply (frule alignUp_idem[OF is_aligned_weaken,where a = w]) apply (erule range_cover.sz) apply (simp add: range_cover_def) apply (clarsimp simp: get_free_ref_def empty_descendants_range_in) apply (rule conjI[rotated], blast, clarsimp) apply (drule_tac x = "(obj_ref_of node_cap, nat_to_cref (bits_of node_cap) slota)" in bspec) apply (clarsimp simp: is_cap_simps nat_to_cref_def word_bits_def bits_of_def valid_cap_simps cap_aligned_def)+ apply (simp add: free_index_of_def) apply (frule(1) range_cover_stuff[where sz = sz]) apply (clarsimp dest!: valid_cap_aligned simp: cap_aligned_def word_bits_def)+ apply simp+ apply (clarsimp simp: get_free_ref_def) apply (erule disjE) apply (drule_tac x= "cs!0" in bspec, clarsimp) apply simp apply (clarsimp simp: cte_wp_at_caps_of_state ex_cte_cap_wp_to_def) apply (rule_tac x=aa in exI, rule exI, rule exI) apply simp done qed lemma asid_bits_ge_0: "(0::word32) < 2 ^ asid_bits" by (simp add: asid_bits_def) lemma retype_ret_valid_caps_captable[Untyped_AI_assms]: "\<lbrakk>pspace_no_overlap_range_cover ptr sz (s::'state_ext::state_ext state) \<and> 0 < us \<and> range_cover ptr sz (obj_bits_api CapTableObject us) n \<and> ptr \<noteq> 0 \<rbrakk> \<Longrightarrow> \<forall>y\<in>{0..<n}. s \<lparr>kheap := foldr (\<lambda>p kh. kh(p \<mapsto> default_object CapTableObject dev us)) (map (\<lambda>p. ptr_add ptr (p * 2 ^ obj_bits_api CapTableObject us)) [0..<n]) (kheap s)\<rparr> \<turnstile> CNodeCap (ptr_add ptr (y * 2 ^ obj_bits_api CapTableObject us)) us []" by ((clarsimp simp:valid_cap_def default_object_def cap_aligned_def cte_level_bits_def is_obj_defs well_formed_cnode_n_def empty_cnode_def dom_def arch_default_cap_def ptr_add_def | rule conjI | intro conjI obj_at_foldr_intro imageI | rule is_aligned_add_multI[OF _ le_refl], (simp add:range_cover_def word_bits_def obj_bits_api_def slot_bits_def)+)+)[1] lemma retype_ret_valid_caps_aobj[Untyped_AI_assms]: "\<And>ptr sz (s::'state_ext::state_ext state) x6 us n. \<lbrakk>pspace_no_overlap_range_cover ptr sz s \<and> x6 \<noteq> ASIDPoolObj \<and> range_cover ptr sz (obj_bits_api (ArchObject x6) us) n \<and> ptr \<noteq> 0\<rbrakk> \<Longrightarrow> \<forall>y\<in>{0..<n}. s \<lparr>kheap := foldr (\<lambda>p kh. kh(p \<mapsto> default_object (ArchObject x6) dev us)) (map (\<lambda>p. ptr_add ptr (p * 2 ^ obj_bits_api (ArchObject x6) us)) [0..<n]) (kheap s)\<rparr> \<turnstile> ArchObjectCap (arch_default_cap x6 (ptr_add ptr (y * 2 ^ obj_bits_api (ArchObject x6) us)) us dev)" apply (rename_tac aobject_type us n) apply (case_tac aobject_type) by (clarsimp simp: valid_cap_def default_object_def cap_aligned_def cte_level_bits_def is_obj_defs well_formed_cnode_n_def empty_cnode_def dom_def arch_default_cap_def ptr_add_def | intro conjI obj_at_foldr_intro imageI valid_vm_rights_def | rule is_aligned_add_multI[OF _ le_refl] | fastforce simp:range_cover_def obj_bits_api_def default_arch_object_def valid_vm_rights_def word_bits_def a_type_def)+ lemma cap_refs_in_kernel_windowD2: "\<lbrakk> cte_wp_at P p (s::'state_ext::state_ext state); cap_refs_in_kernel_window s \<rbrakk> \<Longrightarrow> \<exists>cap. P cap \<and> region_in_kernel_window (cap_range cap) s" apply (clarsimp simp: cte_wp_at_caps_of_state region_in_kernel_window_def) apply (drule(1) cap_refs_in_kernel_windowD) apply fastforce done lemma init_arch_objects_descendants_range[wp,Untyped_AI_assms]: "\<lbrace>\<lambda>(s::'state_ext::state_ext state). descendants_range x cref s \<rbrace> init_arch_objects ty ptr n us y \<lbrace>\<lambda>rv s. descendants_range x cref s\<rbrace>" unfolding init_arch_objects_def by wp lemma init_arch_objects_caps_overlap_reserved[wp,Untyped_AI_assms]: "\<lbrace>\<lambda>(s::'state_ext::state_ext state). caps_overlap_reserved S s\<rbrace> init_arch_objects ty ptr n us y \<lbrace>\<lambda>rv s. caps_overlap_reserved S s\<rbrace>" unfolding init_arch_objects_def by wp lemma set_untyped_cap_invs_simple[Untyped_AI_assms]: "\<lbrace>\<lambda>s. descendants_range_in {ptr .. ptr+2^sz - 1} cref s \<and> pspace_no_overlap_range_cover ptr sz s \<and> invs s \<and> cte_wp_at (\<lambda>c. is_untyped_cap c \<and> cap_bits c = sz \<and> obj_ref_of c = ptr \<and> cap_is_device c = dev) cref s \<and> idx \<le> 2^ sz\<rbrace> set_cap (cap.UntypedCap dev ptr sz idx) cref \<lbrace>\<lambda>rv s. invs s\<rbrace>" apply (rule hoare_name_pre_state) apply (clarsimp simp: cte_wp_at_caps_of_state invs_def valid_state_def) apply (rule hoare_pre) apply (wp set_free_index_valid_pspace_simple set_cap_valid_mdb_simple set_cap_idle update_cap_ifunsafe) apply (simp add:valid_irq_node_def) apply wps apply (wp hoare_vcg_all_lift set_cap_irq_handlers set_cap_valid_arch_caps set_cap_irq_handlers cap_table_at_lift_valid set_cap_typ_at set_untyped_cap_refs_respects_device_simple) apply (clarsimp simp:cte_wp_at_caps_of_state is_cap_simps) apply (intro conjI,clarsimp) apply (rule ext,clarsimp simp:is_cap_simps) apply (clarsimp split:cap.splits simp:is_cap_simps appropriate_cte_cap_def) apply (drule(1) if_unsafe_then_capD[OF caps_of_state_cteD]) apply clarsimp apply (clarsimp simp:is_cap_simps ex_cte_cap_wp_to_def appropriate_cte_cap_def cte_wp_at_caps_of_state) apply (clarsimp dest!:valid_global_refsD2 simp:cap_range_def) apply (simp add:valid_irq_node_def) apply (clarsimp simp:valid_irq_node_def) apply (clarsimp simp:no_cap_to_obj_with_diff_ref_def cte_wp_at_caps_of_state vs_cap_ref_def) apply (case_tac cap) apply (simp_all add:vs_cap_ref_def table_cap_ref_def) apply (rename_tac arch_cap) apply (case_tac arch_cap) apply simp_all apply (clarsimp simp:cap_refs_in_kernel_window_def valid_refs_def simp del:split_paired_All) apply (drule_tac x = cref in spec) apply (clarsimp simp:cte_wp_at_caps_of_state) apply (fastforce simp: not_kernel_window_def) done lemmas pbfs_less_wb' = pageBitsForSize_bounded lemma delete_objects_rewrite[Untyped_AI_assms]: "\<lbrakk> word_size_bits \<le> sz; sz\<le> word_bits;ptr && ~~ mask sz = ptr\<rbrakk> \<Longrightarrow> delete_objects ptr sz = do y \<leftarrow> modify (clear_um {ptr + of_nat k |k. k < 2 ^ sz}); modify (detype {ptr && ~~ mask sz..ptr + 2 ^ sz - 1}) od" apply (clarsimp simp:delete_objects_def freeMemory_def word_size_def word_size_bits_def) apply (subgoal_tac "is_aligned (ptr &&~~ mask sz) sz") apply (subst mapM_storeWord_clear_um[simplified word_size_def word_size_bits_def]) apply (simp) apply simp apply (simp add:range_cover_def) apply clarsimp apply (rule is_aligned_neg_mask) apply simp done declare store_pte_pred_tcb_at [wp] definition nonempty_table :: "obj_ref set \<Rightarrow> kernel_object \<Rightarrow> bool" where "nonempty_table S ko \<equiv> \<exists>pt_t. a_type ko = AArch (APageTable pt_t) \<and> ko \<noteq> ArchObj (PageTable (empty_pt pt_t))" lemma reachable_target_trans[simp]: "reachable_target ref p (trans_state f s) = reachable_target ref p s" by (simp add: reachable_target_def split: prod.split) lemma reachable_pg_cap_exst_update[simp]: "reachable_frame_cap x (trans_state f (s::'state_ext::state_ext state)) = reachable_frame_cap x s" by (simp add: reachable_frame_cap_def obj_at_def) lemma create_cap_valid_arch_caps[wp, Untyped_AI_assms]: "\<lbrace>valid_arch_caps and valid_cap (default_cap tp oref sz dev) and (\<lambda>(s::'state_ext::state_ext state). \<forall>r\<in>obj_refs (default_cap tp oref sz dev). (\<forall>p'. \<not> cte_wp_at (\<lambda>cap. r \<in> obj_refs cap) p' s) \<and> \<not> obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s) and cte_wp_at ((=) cap.NullCap) cref and K (tp \<noteq> ArchObject ASIDPoolObj)\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. valid_arch_caps\<rbrace>" apply (simp add: create_cap_def set_cdt_def) apply (wp set_cap_valid_arch_caps) apply (simp add: trans_state_update[symmetric] del: trans_state_update) apply (wp hoare_vcg_disj_lift hoare_vcg_conj_lift hoare_vcg_all_lift hoare_vcg_imp_lift | simp)+ apply (clarsimp simp del: split_paired_All split_paired_Ex imp_disjL simp: cte_wp_at_caps_of_state) apply (rule conjI) apply (clarsimp simp: no_cap_to_obj_with_diff_ref_def cte_wp_at_caps_of_state) apply (case_tac "\<exists>x. x \<in> obj_refs cap") apply (clarsimp dest!: obj_ref_elemD) apply (case_tac cref, fastforce) apply (simp add: obj_ref_none_no_asid) apply (rule conjI) apply (auto simp: is_cap_simps valid_cap_def second_level_tables_def obj_at_def nonempty_table_def a_type_simps in_omonad)[1] apply (clarsimp simp del: imp_disjL) apply (case_tac "\<exists>x. x \<in> obj_refs cap") apply (clarsimp dest!: obj_ref_elemD) apply fastforce apply (auto simp: is_cap_simps)[1] done lemma create_cap_cap_refs_in_kernel_window[wp, Untyped_AI_assms]: "\<lbrace>cap_refs_in_kernel_window and cte_wp_at (\<lambda>c. cap_range (default_cap tp oref sz dev) \<subseteq> cap_range c) p\<rbrace> create_cap tp sz p dev (cref, oref) \<lbrace>\<lambda>rv. cap_refs_in_kernel_window\<rbrace>" apply (simp add: create_cap_def) apply (wp | simp)+ apply (clarsimp simp: cte_wp_at_caps_of_state) apply (drule(1) cap_refs_in_kernel_windowD) apply blast done lemma create_cap_ioports[wp, Untyped_AI_assms]: "\<lbrace>valid_ioports and cte_wp_at (\<lambda>_. True) cref\<rbrace> create_cap tp sz p dev (cref,oref) \<lbrace>\<lambda>rv. valid_ioports\<rbrace>" by wpsimp lemma init_arch_objects_nonempty_table[Untyped_AI_assms, wp]: "\<lbrace>(\<lambda>s. \<not> (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s) \<and> valid_global_objs s \<and> valid_arch_state s \<and> pspace_aligned s) and K (\<forall>ref\<in>set refs. is_aligned ref (obj_bits_api tp us))\<rbrace> init_arch_objects tp ptr bits us refs \<lbrace>\<lambda>rv s. \<not> (obj_at (nonempty_table (set (second_level_tables (arch_state s)))) r s)\<rbrace>" unfolding init_arch_objects_def by wpsimp lemma nonempty_table_caps_of[Untyped_AI_assms]: "nonempty_table S ko \<Longrightarrow> caps_of ko = {}" by (auto simp: caps_of_def cap_of_def nonempty_table_def a_type_def split: Structures_A.kernel_object.split if_split_asm) lemma nonempty_default[simp, Untyped_AI_assms]: "tp \<noteq> Untyped \<Longrightarrow> \<not> nonempty_table S (default_object tp dev us)" apply (case_tac tp, simp_all add: default_object_def nonempty_table_def a_type_def) apply (rename_tac aobject_type) apply (case_tac aobject_type; simp add: default_arch_object_def empty_pt_def) done crunch cte_wp_at_iin[wp]: init_arch_objects "\<lambda>s. P (cte_wp_at (P' (interrupt_irq_node s)) p s)" lemmas init_arch_objects_ex_cte_cap_wp_to = init_arch_objects_excap lemma obj_is_device_vui_eq[Untyped_AI_assms]: "valid_untyped_inv ui s \<Longrightarrow> case ui of Retype slot reset ptr_base ptr tp us slots dev \<Rightarrow> obj_is_device tp dev = dev" apply (cases ui, clarsimp) apply (clarsimp simp: obj_is_device_def split: apiobject_type.split) apply (intro impI conjI allI, simp_all add: is_frame_type_def default_object_def) apply (simp add: default_arch_object_def split: aobject_type.split) apply (auto simp: arch_is_frame_type_def) done end global_interpretation Untyped_AI? : Untyped_AI where nonempty_table = AARCH64.nonempty_table proof goal_cases interpret Arch . case 1 show ?case by (unfold_locales; (fact Untyped_AI_assms)?) qed end