Datasets:
AI4M
/

text
stringlengths
0
3.34M
lemma algebraic_int_cnj_iff [simp]: "algebraic_int (cnj x) \<longleftrightarrow> algebraic_int x"
\section{Mixture Models for Jet Tagging} \label{sec:tagging} \subsection{Gaussian Mixture Models} As a first step we pick the boosted top tagging problem. From Figure \ref{fig:efp-histogram}, it is apparent that the jets are points N-dimentional space (here 1000 dimentional, we have limited to EFPs of degree <= 7) which originate from several multivariate distributions. The obvious choice to model this data is to fit a Bayesian Gaussian Mixture Model, each distribution being a multivariate Gaussian: \begin{equation} f_{pdf}(X) = \frac{1}{\sqrt{(2\pi)^k \vert \Sigma \vert}} e^{-\frac{1}{2} (x - \mu)^T \Sigma^{-1} (x - \mu)} \end{equation} We train the model using Expectation Maximization algorithm. The performance of the algorithm is at par with that of LDA (89.2\% on the top tagging dataset). \subsection{Maxwellian Mixture Models} The performance of the GMM is marred by the fact that the distributions of EFPs are actually maxwellian. The skew of the distributions is high for the top quarks even at low degrees and increases as the degree of the EFP increases. Therefore it behooves us to model the data using the Maxwellian distribution, which follows. We model the multivariate form of the Maxwell-Boltzmann Distribution as follows ~\cite{maxwellian_multivariate}. \begin{equation} f_{pdf}(X) = \frac{b^{1 + \frac{n}{2}} \vert B \vert^\frac{n}{2} \Gamma(\frac{n}{2})}{\pi^{\frac{n}{2}} \Gamma(1 + \frac{n}{2})} [XBX^T] e^{-b(XBX^T)} \end{equation} The parameters being learnt will be the $n \times n$ sized matrix $B$. $X$ is the input vector to the model of shape $n \times 1$ and the the constant $b$ is the determinant of the matrix $B$, which together with the Gamma functions serves the task of normalization. \textcolor{red}{This distribution will be trained on using the Expectation Maximization algorithm, details of the E- step and M- step will be added here, together with any improvements in performance. ~\cite{maxwellian_plasma}} \subsection{Performance of the Models} Following is the performance of the algorithms on the Top Tagging dataset \cite{data_toptagging}. \begin{table} \caption{Performance on Top Tagging \cite{tagging_review}} \label{tab:1} \begin{tabular}{lll} \hline\noalign{\smallskip} Model Name & Accuracy & ROC AUC \\ \noalign{\smallskip}\hline\noalign{\smallskip} \textbf{Bayessian Maxwellian Mixture Model with EFP} & UNK & UNK \\ \textbf{Bayesian Gaussian Mixture Model with EFP} & 89.224\% & UNK \\ Latent Dirichlet Allocation & 89.2\% & 0.955 \\ \noalign{\smallskip}\hline Linear Discriminant Analysis with EFP & 93.2\% & 0.980 \\ ParticleNet (Graph Neural Net on Point Cloud) & 93.8\% & 0.985 \\ \noalign{\smallskip}\hline \end{tabular} \end{table} \textcolor{red}{Add accuracy figures on the QCD tagging dataset \cite{data_qcdtagging}} \subsection{Features of probabilistic tagging} While boosted top tagging is solved to a very high accuracy, the following attributes are still sought for: \begin{itemize} \item To know what confidence we have tagged a single jet with? - As seen from the histograms, some jets are very clearly in the Top or QCD domain, the overlap of the two is the set of jets where most algorithms fail. When tagging, a model should be able to output both the class label and the confidence figure. \item Resilliance to unseen input, and ability to fail gracefully if the input jet is not unlike what the model has seen before? This may be due to errors by the clustering algorithm which has clustered multiple jets together or because of an unknown decay type. \end{itemize} A probabilistic Bayesian generative model is the best attempt at modelling the probability with which we are tagging a jet. \textcolor{red}{Show experimental proof that we are indeed resilliant against mutliple-jet in one jet image and against unknown jet types}. \textcolor{yellow}{We need to explore what set of features help models like ParticleNet \cite{particle_net} perform better in the overlap zone, and it's performance relative to our confidence, as in the Orange comparative scatters.}
\section{Extra: FAIMS research-specific features} \begin{sectionframe} % Custom environment required for section slides \frametitle{Extra: FAIMS research-specific features} %\framesubtitle{Subtitle} % Some section slide content % This is on another line \end{sectionframe} %---------------------------------------------------------------------------------------- \begin{frame}[allowframebreaks]{Key research-specific features} \begin{itemize} \item Workflows and data schemata are deeply customisable. \item Customisation is achieved using relatively simple and human-readable XML documents separate from the ‘core’ software, supporting sharing, modification, and reuse via collaborative software development platforms like GitHub. \item Resulting mobile applications work offline. \item Automated bi-directional synchronisation using local or online server. \item A complete version history, with review and selective rollback, is provided for all data. \item Binds structured, geospatial, multimedia, and free text data in one record. \item A mobile GIS provides layer management and tools for the creation and editing of shapes. \item Connects to internal and external sensors (e.g., Bluetooth / USB devices). \item Externally captured multimedia (e.g., dSLR photos, audio recordings) can be connected to a record, then data contained in the associated record can be used to automatically rename connected multimedia files or write file metadata. \item Data validated on device and/or on server. \item Applications can be made multilingual using a standard and well-established localisation approach.. \item Granular and contextualised metadata and certainty. \item Granular and contextualised help, including images, can be provided for all data entry fields. \item All data entry fields can be mapped to shared vocabularies, thesauri, or ontologies via embedded URIs, supporting Linked Open Data approaches. \item Data can be exported from the server in a variety of formats, or can be customised to a specific data target (e.g., JSON, relational database). \end{itemize} \end{frame} % %----------------------------------------------------------------------------------------
If $\mu$ is a positive additive measure on a finite set $\Omega$, then $\mu$ is countably additive.
(* Pierre Casteran, LaBRI, Univ. Bordeaux *) Set Implicit Arguments. From Coq Require Import Relations Ensembles. (* begin snippet isLubDef *) Definition upper_bound (M:Type) (D: Ensemble M) (lt: relation M) (X:Ensemble M) (a:M) := forall x, In _ D x -> In _ X x -> x = a \/ lt x a. Definition is_lub (M:Type) (D : Ensemble M) (lt : relation M) (X:Ensemble M) (a:M) := In _ D a /\ upper_bound D lt X a /\ (forall y, In _ D y -> upper_bound D lt X y -> y = a \/ lt a y). (* end snippet isLubDef *)
[STATEMENT] lemma pre_post_compose_1: "-p\<stileturn>-r \<le> (-p\<stileturn>-q)*(-q\<stileturn>-r)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. - p \<stileturn> - r \<le> (- p \<stileturn> - q) * (- q \<stileturn> - r) [PROOF STEP] by (simp add: pre_post_compose)
""" Generates a `Float64` from a `MRG32k3a` instance. """ function rand(rng::MRG32k3a, ::Type{Float64}) rand(rng) end """ Generates a `Float32` from a `MRG32k3a` instance. """ function rand(rng::MRG32k3a, ::Type{Float32}) convert(Float32, rand(rng)) end """ Generates a `Float16` from a `MRG32k3a` instance. """ function rand(rng::MRG32k3a, ::Type{Float16}) convert(Float16, rand(rng)) end """ Generates a `Int64` in the given range from a `MRG32k3a` instance. """ function rand(rng::MRG32k3a, r::UnitRange{Int64}) r.start + convert(Int64, (r.stop - r.start) * rand(rng, Float64)) end
State Before: α β γ : Type u F G : Type u → Type u inst✝³ : Applicative F inst✝² : Applicative G inst✝¹ : CommApplicative F inst✝ : CommApplicative G g : α → G β h : β → γ s : Finset α ⊢ Functor.map h <$> traverse g s = traverse (Functor.map h ∘ g) s State After: α β γ : Type u F G : Type u → Type u inst✝³ : Applicative F inst✝² : Applicative G inst✝¹ : CommApplicative F inst✝ : CommApplicative G g : α → G β h : β → γ s : Finset α ⊢ Functor.map h <$> Multiset.toFinset <$> Multiset.traverse g s.val = Multiset.toFinset <$> Multiset.traverse (Functor.map h ∘ g) s.val Tactic: unfold traverse State Before: α β γ : Type u F G : Type u → Type u inst✝³ : Applicative F inst✝² : Applicative G inst✝¹ : CommApplicative F inst✝ : CommApplicative G g : α → G β h : β → γ s : Finset α ⊢ Functor.map h <$> Multiset.toFinset <$> Multiset.traverse g s.val = Multiset.toFinset <$> Multiset.traverse (Functor.map h ∘ g) s.val State After: α β γ : Type u F G : Type u → Type u inst✝³ : Applicative F inst✝² : Applicative G inst✝¹ : CommApplicative F inst✝ : CommApplicative G g : α → G β h : β → γ s : Finset α ⊢ (Multiset.toFinset ∘ Functor.map h) <$> Multiset.traverse g s.val = Multiset.toFinset <$> Multiset.traverse (Functor.map h ∘ g) s.val Tactic: simp only [map_comp_coe, functor_norm] State Before: α β γ : Type u F G : Type u → Type u inst✝³ : Applicative F inst✝² : Applicative G inst✝¹ : CommApplicative F inst✝ : CommApplicative G g : α → G β h : β → γ s : Finset α ⊢ (Multiset.toFinset ∘ Functor.map h) <$> Multiset.traverse g s.val = Multiset.toFinset <$> Multiset.traverse (Functor.map h ∘ g) s.val State After: no goals Tactic: rw [LawfulFunctor.comp_map, Multiset.map_traverse]
module Numeral.Sign.Oper.Proofs where
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Deedy - One Page Two Column Resume % LaTeX Template % Version 1.3 (22/9/2018) % % Original author: % Debarghya Das (http://debarghyadas.com) % % Original repository: % https://github.com/deedydas/Deedy-Resume % % v1.3 author: % Zachary Taylor % % v1.3 repository: % https://github.com/ZDTaylor/Deedy-Resume % % IMPORTANT: THIS TEMPLATE NEEDS TO BE COMPILED WITH XeLaTeX % % This template uses several fonts not included with Windows/Linux by % default. If you get compilation errors saying a font is missing, find the line % on which the font is used and either change it to a font included with your % operating system or comment the line out to use the default font. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TODO: % 1. Add various styling and section options and allow for multiple pages smoothly. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CHANGELOG: % v1.3: % 1. Removed MacFonts version as I have no desire to maintain it nor access to macOS % 2. Switched column ordering % 3. Changed font styles/colors for easier human readability % 4. Added, removed, and rearranged sections to reflect my own experience % 5. Hid last updated % % v1.2: % 1. Added publications in place of societies. % 2. Collapsed a portion of education. % 3. Fixed a bug with alignment of overflowing long last updated dates on the top right. % % v1.1: % 1. Fixed several compilation bugs with \renewcommand % 2. Got Open-source fonts (Windows/Linux support) % 3. Added Last Updated % 4. Move Title styling into .sty % 5. Commented .sty file. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Known Issues: % 1. Overflows onto second page if any column's contents are more than the vertical limit % 2. Hacky space on the first bullet point on the second column. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \documentclass[]{resume} \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \begin{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LAST UPDATED DATE % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \lastupdated %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TITLE NAME % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \namesection{Kartik Poojari}{ \href{mailto:[email protected]}{[email protected]} | \href{tel:+91 8551033429}{+91 8551033429} } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % COLUMN ONE % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{minipage}[t]{0.60\textwidth} \bigskip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % PROFILE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Profile} \location{Programmer and Internet Enthusiast. A creative thinker, adept in software development and working with various problem solving possibilities.} \bigskip \bigskip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % EDUCATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Education} \subsection{Savitribai Phule Pune University | Pune} \descript{Bachelor of Engineering in Computer Engineering} \location{2019 - Present} Second Year Engineering Student at Dr. D. Y. Patil School of Engineering \\ \smallskip \location{ Cum. GPA: 8.05 / 10.0} \sectionsep \bigskip \bigskip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % PROJECTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Projects} \runsubsection{Accident Location Broadcasting System} \\ \descript{Web, Arduino} \location{Dec 2019 - March 2020} \textbullet{} Lead the development of this project which was created as a class project. \textbullet{} This Project aimed at finding the solution for timely medical attention for the victims in event of an accident.\\ \textbullet{} The solution was designed using GSM and GPS modules which relayed location of the accident on detecting an accident. \sectionsep \bigskip \bigskip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % COURSES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Courses} \runsubsection{Beginner Full Stack Web Development: HTML, CSS, React and Node}\\ \descript{DevSlopes by Mark WehlBeck} \location{March 2019 - April 2020} \sectionsep \medskip \runsubsection{Network Security }\\ \descript{Ermin Kreponic} \location{September 2019 - January 2020} \sectionsep \bigskip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % COLUMN TWO % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \end{minipage} \hfill \begin{minipage}[t]{0.33\textwidth} \bigskip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % SKILLS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Skills} \subsection{Programming} \location{3+ years:} Python \textbullet{} JavaScript \textbullet{} HTML/CSS \\ \location{1+ years:} C/C++ \textbullet{} MongoDB \textbullet{} Express \textbullet{} React \textbullet{} Node \\ \location{0+ years:} Flask \textbullet{} Django \\ \sectionsep \medskip \subsection{Technology} Git/Github \textbullet{} Linux \\ UNIX \textbullet{} Arduino \\ \LaTeX \textbullet{} Microsoft Office\\ Adobe Illustrator \textbullet{} Figma \\ \sectionsep \subsection{Other Skills} Document Writing \\ UI/UX Design \\ \bigskip \bigskip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Hobbies %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{HOBBIES} Football\\ Cycling\\ Reading\\ \sectionsep \bigskip \bigskip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Languages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{LANGUAGES} English | \descript{Professional} Hindi | \descript{Native} Kannada | \descript{Native} Marathi | \descript{Limited} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % LINKS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \bigskip \bigskip \section{Links} Github:// \href{https://github.com/KRPoojari}{\bf KRPoojari} \\ LinkedIn:// \href{https://www.linkedin.com/in/kartik-poojari-74250b201/}{\bf Kartik Poojari} \\ \sectionsep \end{minipage} \end{document} \documentclass[]{article}
-- A module which re-exports Type.Category.ExtensionalFunctionsCategory as the default category for types, and defines some shorthand names for categorical stuff. module Type.Category where open import Functional open import Function.Equals open import Logic.Predicate open import Relator.Equals.Proofs.Equiv import Structure.Category.Functor as Category import Structure.Category.Monad.ExtensionSystem as Category import Structure.Category.NaturalTransformation as Category open import Syntax.Transitivity open import Type module _ {ℓ} where open import Type.Category.ExtensionalFunctionsCategory{ℓ} public -- Shorthand for the category-related types in the category of types. Functor = Category.Endofunctor(typeExtensionalFnCategory) -- TODO: Should not be an endofunctor. Let it be parameterized by different levels module Functor {F} ⦃ functor : Functor(F) ⦄ where open Category.Endofunctor(typeExtensionalFnCategory) functor public module HaskellNames where _<$_ : ∀{x y} → y → (F(x) → F(y)) _<$_ = map ∘ const _$>_ : ∀{x y} → F(x) → y → F(y) _$>_ = swap(_<$_) _<$>_ : ∀{x y} → (x → y) → (F(x) → F(y)) _<$>_ = map _<&>_ : ∀{x y} → F(x) → (x → y) → F(y) _<&>_ = swap(_<$>_) -- Applies an unlifted argument to a lifted function, returning a lifted value. -- TODO: When `f` is an instance of `Applicative`, it should be functionally equivalent -- to `f <*> pure x` because: -- f <*$> x -- = fmap ($ x) f //Definition: <*$> -- = pure ($ x) <*> f //Applicative: "As a consequence of these laws, the Functor instance for f will satisfy..." -- = f <*> pure x //Applicative: interchange _<*$>_ : ∀{x y : Type{ℓ}} → F(x → y) → (x → F(y)) f <*$> x = (_$ x) <$> f module _ {F₁} ⦃ functor₁ : Functor(F₁) ⦄ {F₂} ⦃ functor₂ : Functor(F₂) ⦄ where NaturalTransformation : (∀{T} → F₁(T) → F₂(T)) → Type NaturalTransformation η = Category.NaturalTransformation {Cₗ = typeExtensionalFnCategoryObject} {Cᵣ = typeExtensionalFnCategoryObject} ([∃]-intro F₁) ([∃]-intro F₂) (T ↦ η{T}) module NaturalTransformation {η : ∀{T} → F₁(T) → F₂(T)} ⦃ nt : NaturalTransformation(η) ⦄ where open Category.NaturalTransformation {Cₗ = typeExtensionalFnCategoryObject} {Cᵣ = typeExtensionalFnCategoryObject} {[∃]-intro F₁} {[∃]-intro F₂} nt public {- -- All mappings between functors are natural. -- Also called: Theorems for free. -- TODO: Is this correct? Is this provable? Maybe one needs to prove stuff about how types are formed? natural-functor-mapping : ∀{η : ∀{T} → F₁(T) → F₂(T)} → NaturalTransformation(η) Dependent._⊜_.proof (Category.NaturalTransformation.natural (natural-functor-mapping {η}) {X}{Y} {f}) {F₁X} = (η ∘ (Functor.map f)) F₁X 🝖[ _≡_ ]-[] η(Functor.map f(F₁X)) 🝖[ _≡_ ]-[ {!!} ] Functor.map f (η(F₁X)) 🝖[ _≡_ ]-[] ((Functor.map f) ∘ η) F₁X 🝖-end -} Monad = Category.ExtensionSystem{cat = typeExtensionalFnCategoryObject} module Monad {T} ⦃ monad : Monad(T) ⦄ where open Category.ExtensionSystem{cat = typeExtensionalFnCategoryObject} (monad) public -- Do notation for monads. open import Syntax.Do instance doNotation : DoNotation(T) return ⦃ doNotation ⦄ = HaskellNames.return _>>=_ ⦃ doNotation ⦄ = swap(HaskellNames.bind) open Monad using () renaming (doNotation to Monad-doNotation) public
State Before: C : Type u₁ inst✝ : Category C X : C F₁ : Discrete PEmpty ⥤ C F₂ : Discrete PEmpty ⥤ C h : HasLimit F₁ ⊢ (X : Discrete PEmpty) → ((Functor.const (Discrete PEmpty)).obj (limit F₁)).obj X ⟶ F₂.obj X State After: no goals Tactic: aesop_cat State Before: C : Type u₁ inst✝ : Category C X : C F₁ : Discrete PEmpty ⥤ C F₂ : Discrete PEmpty ⥤ C h : HasLimit F₁ ⊢ ∀ ⦃X Y : Discrete PEmpty⦄ (f : X ⟶ Y), ((Functor.const (Discrete PEmpty)).obj (limit F₁)).map f ≫ id (Discrete.casesOn Y fun as => False.elim (_ : False)) = id (Discrete.casesOn X fun as => False.elim (_ : False)) ≫ F₂.map f State After: no goals Tactic: aesop_cat
[STATEMENT] lemma proj2_Col_abs: assumes "p \<noteq> 0" and "q \<noteq> 0" and "r \<noteq> 0" and "i \<noteq> 0 \<or> j \<noteq> 0 \<or> k \<noteq> 0" and "i *\<^sub>R p + j *\<^sub>R q + k *\<^sub>R r = 0" shows "proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r)" (is "proj2_Col ?pp ?pq ?pr") [PROOF STATE] proof (prove) goal (1 subgoal): 1. proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) [PROOF STEP] from \<open>p \<noteq> 0\<close> and proj2_rep_abs2 [PROOF STATE] proof (chain) picking this: p \<noteq> 0 ?v \<noteq> 0 \<Longrightarrow> \<exists>k. k \<noteq> 0 \<and> proj2_rep (proj2_abs ?v) = k *\<^sub>R ?v [PROOF STEP] obtain i' where "i' \<noteq> 0" and "proj2_rep ?pp = i' *\<^sub>R p" (is "?rp = _") [PROOF STATE] proof (prove) using this: p \<noteq> 0 ?v \<noteq> 0 \<Longrightarrow> \<exists>k. k \<noteq> 0 \<and> proj2_rep (proj2_abs ?v) = k *\<^sub>R ?v goal (1 subgoal): 1. (\<And>i'. \<lbrakk>i' \<noteq> 0; proj2_rep (proj2_abs p) = i' *\<^sub>R p\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: i' \<noteq> 0 proj2_rep (proj2_abs p) = i' *\<^sub>R p goal (1 subgoal): 1. proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) [PROOF STEP] from \<open>q \<noteq> 0\<close> and proj2_rep_abs2 [PROOF STATE] proof (chain) picking this: q \<noteq> 0 ?v \<noteq> 0 \<Longrightarrow> \<exists>k. k \<noteq> 0 \<and> proj2_rep (proj2_abs ?v) = k *\<^sub>R ?v [PROOF STEP] obtain j' where "j' \<noteq> 0" and "proj2_rep ?pq = j' *\<^sub>R q" (is "?rq = _") [PROOF STATE] proof (prove) using this: q \<noteq> 0 ?v \<noteq> 0 \<Longrightarrow> \<exists>k. k \<noteq> 0 \<and> proj2_rep (proj2_abs ?v) = k *\<^sub>R ?v goal (1 subgoal): 1. (\<And>j'. \<lbrakk>j' \<noteq> 0; proj2_rep (proj2_abs q) = j' *\<^sub>R q\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: j' \<noteq> 0 proj2_rep (proj2_abs q) = j' *\<^sub>R q goal (1 subgoal): 1. proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) [PROOF STEP] from \<open>r \<noteq> 0\<close> and proj2_rep_abs2 [PROOF STATE] proof (chain) picking this: r \<noteq> 0 ?v \<noteq> 0 \<Longrightarrow> \<exists>k. k \<noteq> 0 \<and> proj2_rep (proj2_abs ?v) = k *\<^sub>R ?v [PROOF STEP] obtain k' where "k' \<noteq> 0" and "proj2_rep ?pr = k' *\<^sub>R r" (is "?rr = _") [PROOF STATE] proof (prove) using this: r \<noteq> 0 ?v \<noteq> 0 \<Longrightarrow> \<exists>k. k \<noteq> 0 \<and> proj2_rep (proj2_abs ?v) = k *\<^sub>R ?v goal (1 subgoal): 1. (\<And>k'. \<lbrakk>k' \<noteq> 0; proj2_rep (proj2_abs r) = k' *\<^sub>R r\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by auto [PROOF STATE] proof (state) this: k' \<noteq> 0 proj2_rep (proj2_abs r) = k' *\<^sub>R r goal (1 subgoal): 1. proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) [PROOF STEP] with \<open>i *\<^sub>R p + j *\<^sub>R q + k *\<^sub>R r = 0\<close> and \<open>i' \<noteq> 0\<close> and \<open>proj2_rep ?pp = i' *\<^sub>R p\<close> and \<open>j' \<noteq> 0\<close> and \<open>proj2_rep ?pq = j' *\<^sub>R q\<close> [PROOF STATE] proof (chain) picking this: i *\<^sub>R p + j *\<^sub>R q + k *\<^sub>R r = 0 i' \<noteq> 0 proj2_rep (proj2_abs p) = i' *\<^sub>R p j' \<noteq> 0 proj2_rep (proj2_abs q) = j' *\<^sub>R q k' \<noteq> 0 proj2_rep (proj2_abs r) = k' *\<^sub>R r [PROOF STEP] have "(i/i') *\<^sub>R ?rp + (j/j') *\<^sub>R ?rq + (k/k') *\<^sub>R ?rr = 0" [PROOF STATE] proof (prove) using this: i *\<^sub>R p + j *\<^sub>R q + k *\<^sub>R r = 0 i' \<noteq> 0 proj2_rep (proj2_abs p) = i' *\<^sub>R p j' \<noteq> 0 proj2_rep (proj2_abs q) = j' *\<^sub>R q k' \<noteq> 0 proj2_rep (proj2_abs r) = k' *\<^sub>R r goal (1 subgoal): 1. (i / i') *\<^sub>R proj2_rep (proj2_abs p) + (j / j') *\<^sub>R proj2_rep (proj2_abs q) + (k / k') *\<^sub>R proj2_rep (proj2_abs r) = 0 [PROOF STEP] by simp [PROOF STATE] proof (state) this: (i / i') *\<^sub>R proj2_rep (proj2_abs p) + (j / j') *\<^sub>R proj2_rep (proj2_abs q) + (k / k') *\<^sub>R proj2_rep (proj2_abs r) = 0 goal (1 subgoal): 1. proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) [PROOF STEP] from \<open>i' \<noteq> 0\<close> and \<open>j' \<noteq> 0\<close> and \<open>k' \<noteq> 0\<close> and \<open>i \<noteq> 0 \<or> j \<noteq> 0 \<or> k \<noteq> 0\<close> [PROOF STATE] proof (chain) picking this: i' \<noteq> 0 j' \<noteq> 0 k' \<noteq> 0 i \<noteq> 0 \<or> j \<noteq> 0 \<or> k \<noteq> 0 [PROOF STEP] have "i/i' \<noteq> 0 \<or> j/j' \<noteq> 0 \<or> k/k' \<noteq> 0" [PROOF STATE] proof (prove) using this: i' \<noteq> 0 j' \<noteq> 0 k' \<noteq> 0 i \<noteq> 0 \<or> j \<noteq> 0 \<or> k \<noteq> 0 goal (1 subgoal): 1. i / i' \<noteq> 0 \<or> j / j' \<noteq> 0 \<or> k / k' \<noteq> 0 [PROOF STEP] by simp [PROOF STATE] proof (state) this: i / i' \<noteq> 0 \<or> j / j' \<noteq> 0 \<or> k / k' \<noteq> 0 goal (1 subgoal): 1. proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) [PROOF STEP] with \<open>(i/i') *\<^sub>R ?rp + (j/j') *\<^sub>R ?rq + (k/k') *\<^sub>R ?rr = 0\<close> [PROOF STATE] proof (chain) picking this: (i / i') *\<^sub>R proj2_rep (proj2_abs p) + (j / j') *\<^sub>R proj2_rep (proj2_abs q) + (k / k') *\<^sub>R proj2_rep (proj2_abs r) = 0 i / i' \<noteq> 0 \<or> j / j' \<noteq> 0 \<or> k / k' \<noteq> 0 [PROOF STEP] show "proj2_Col ?pp ?pq ?pr" [PROOF STATE] proof (prove) using this: (i / i') *\<^sub>R proj2_rep (proj2_abs p) + (j / j') *\<^sub>R proj2_rep (proj2_abs q) + (k / k') *\<^sub>R proj2_rep (proj2_abs r) = 0 i / i' \<noteq> 0 \<or> j / j' \<noteq> 0 \<or> k / k' \<noteq> 0 goal (1 subgoal): 1. proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) [PROOF STEP] by (unfold proj2_Col_def, best) [PROOF STATE] proof (state) this: proj2_Col (proj2_abs p) (proj2_abs q) (proj2_abs r) goal: No subgoals! [PROOF STEP] qed
/- Copyright (c) 2021 Ashvni Narayanan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ashvni Narayanan -/ import sum_eval.second_sum import sum_eval.third_sum import p_adic_L_function_def /-! # p-adic L-function This file proves that the p-adic L-function takes special values at negative integers, in terms of generalized Bernoulli numbers. ## Main definitions * `p_adic_L_function_eval_neg_int` * `bernoulli_measure_eval_char_fn` ## Implementation notes * `pri_dir_char_extend'` replaced with `dir_char_extend` * Try to avoid `teichmuller_character_mod_p_change_level` * `neg_pow'_to_hom` replaced with `mul_inv_pow_hom` * `neg_pow'` replaced with `mul_inv_pow` * `clopen_from_units` replaced with `clopen_from.units` ## References Introduction to Cyclotomic Fields, Washington (Chapter 12, Section 2) ## Tags p-adic, L-function, Bernoulli measure, Dirichlet character -/ open_locale big_operators local attribute [instance] zmod.topological_space variables (p : ℕ) [fact (nat.prime p)] (d : ℕ) (R : Type*) [normed_comm_ring R] (m : ℕ) (hd : d.gcd p = 1) (χ : dirichlet_character R (d*(p^m))) {c : ℕ} (hc : c.gcd p = 1) (hc' : c.gcd d = 1) (na : ∀ (n : ℕ) (f : ℕ → R), ∥ ∑ (i : ℕ) in finset.range n, f i∥ ≤ ⨆ (i : zmod n), ∥f i.val∥) (w : continuous_monoid_hom (units (zmod d) × units ℤ_[p]) R) variables [fact (0 < d)] [complete_space R] [char_zero R] lemma trying [algebra ℚ R] [normed_algebra ℚ_[p] R] [norm_one_class R] (f : C((zmod d)ˣ × ℤ_[p]ˣ, R)) (i : ℕ → locally_constant ((zmod d)ˣ × ℤ_[p]ˣ) R) (hf : filter.tendsto (λ j : ℕ, (i j : C((zmod d)ˣ × ℤ_[p]ˣ, R))) (filter.at_top) (nhds f)) : filter.tendsto (λ j : ℕ, (bernoulli_measure R hc hc' hd na).1 (i j)) (filter.at_top) (nhds (measure.integral (bernoulli_measure R hc hc' hd na) f)) := begin convert filter.tendsto.comp (continuous.tendsto (continuous_linear_map.continuous (measure.integral (bernoulli_measure R hc hc' hd na) )) f) hf, ext, simp, rw integral_loc_const_eval, simp, end open ind_fn eventually_constant_seq zmod clopen_from lemma bernoulli_measure_eval_char_fn [normed_algebra ℚ_[p] R] [algebra ℚ R] [norm_one_class R] (n : ℕ) (hn : 1 < n) (a : (zmod d)ˣ × (zmod (p^n))ˣ) : (bernoulli_measure R hc hc' hd na).val (_root_.char_fn R (clopen_from.is_clopen_units a)) = (algebra_map ℚ_[p] R (bernoulli_distribution p d c n ((zmod.chinese_remainder (nat.coprime.pow_right n hd)).inv_fun ((a.1 : zmod d), (a.2 : zmod (p^n))))) ) := begin delta bernoulli_measure, simp only [linear_map.coe_mk, ring_equiv.inv_fun_eq_symm], --delta bernoulli_distribution, simp only [linear_map.coe_mk], rw sequence_limit_eq _ n _, { --delta g, simp only [algebra.id.smul_eq_mul], convert finset.sum_eq_single_of_mem _ _ (λ b memb hb, _), swap 2, { refine ((zmod.chinese_remainder (nat.coprime.pow_right n hd)).inv_fun ((a.1 : zmod d), (a.2 : zmod (p^n)))), }, { conv_lhs { rw ← one_mul ((algebra_map ℚ_[p] R) (bernoulli_distribution p d c n (((zmod.chinese_remainder _).symm) (↑(a.fst), ↑(a.snd))))), }, congr, rw loc_const_ind_fn, simp only [ring_equiv.inv_fun_eq_symm, locally_constant.coe_mk], --rw ind_fn_def, simp only, rw dif_pos _, rw map_ind_fn_eq_fn, { symmetry, rw ← char_fn_one, rw set.mem_prod, simp only [prod.fst_zmod_cast, prod.snd_zmod_cast, set.mem_singleton_iff, ring_hom.to_monoid_hom_eq_coe, set.mem_preimage], rw units.ext_iff, rw units.ext_iff, rw is_unit.unit_spec, rw units.coe_map, rw is_unit.unit_spec, rw ← ring_equiv.inv_fun_eq_symm, rw proj_fst'', rw ring_hom.coe_monoid_hom (@padic_int.to_zmod_pow p _ n), rw proj_snd'', simp only [eq_self_iff_true, and_self], }, { rw ← ring_equiv.inv_fun_eq_symm, simp only [prod.fst_zmod_cast, prod.snd_zmod_cast], split, { rw proj_fst'', apply units.is_unit, }, { apply padic_int.is_unit_to_zmod_pow_of_is_unit p hn, rw proj_snd'', apply units.is_unit, }, }, }, { delta zmod', apply finset.mem_univ, }, { --rw loc_const_ind_fn.loc_const_ind_fn_def, rw map_ind_fn_eq_zero, --rw smul_eq_zero, left, --rw mul_eq_zero_of_left _, rw helper_18 p d R hd hn a, rw (char_fn_zero R _ _).1 _, rw zero_smul, rw mem_clopen_from, intro h, apply hb, rw units.chinese_remainder_symm_apply_snd at h, rw units.chinese_remainder_symm_apply_fst at h, rw h.2, rw ← h.1, rw ring_equiv.eq_inv_fun_iff, rw ← ring_equiv.coe_to_equiv, change (zmod.chinese_remainder (nat.coprime.pow_right n hd)).to_equiv b = _, rw prod.ext_iff, rw inv_fst', rw inv_snd', simp only [prod.fst_zmod_cast, eq_self_iff_true, prod.snd_zmod_cast, true_and], conv_rhs { rw ← zmod.int_cast_cast, }, rw ring_hom.map_int_cast, rw zmod.int_cast_cast, }, }, { convert seq_lim_from_loc_const_char_fn R ((units.chinese_remainder (nat.coprime.pow_right n hd)).symm a : zmod (d * p^n)) hc hc' hd, apply helper_18 p d R hd hn a, }, end open continuous_map zmod dirichlet_character variables [normed_algebra ℚ_[p] R] [fact (0 < m)] variable [fact (0 < d)] variable (c) variables (hc) (hc') @[simp, to_additive] lemma locally_constant.coe_prod {α : Type*} {β : Type*} [comm_monoid β] [topological_space α] [topological_space β] [has_continuous_mul β] {ι : Type*} (s : finset ι) (f : ι → locally_constant α β) : ⇑(∏ i in s, f i) = (∏ i in s, (f i : α → β)) := map_prod (locally_constant.coe_fn_monoid_hom : locally_constant α β →* _) f s -- remove prod_apply @[to_additive] lemma locally_constant.prod_apply' {α : Type*} {β : Type*} [comm_monoid β] [topological_space α] [topological_space β] [has_continuous_mul β] {ι : Type*} (s : finset ι) (f : ι → locally_constant α β) (a : α) : (∏ i in s, f i) a = (∏ i in s, f i a) := by simp lemma monoid_hom.pow_apply {X Y : Type*} [monoid X] [comm_monoid Y] (f : X →* Y) (n : ℕ) (x : X) : (f^n) x = (f x)^n := rfl lemma ring_hom.comp_to_monoid_hom {α β γ : Type*} [non_assoc_semiring α] [non_assoc_semiring β] [non_assoc_semiring γ] (f : α →+* β) (g : β →+* γ) : (g.comp f).to_monoid_hom = g.to_monoid_hom.comp f.to_monoid_hom := by { ext, simp, } lemma monoid_hom.snd_apply {X Y : Type*} [mul_one_class X] [mul_one_class Y] (x : X) (y : Y) : monoid_hom.snd X Y (x, y) = y := rfl lemma helper_254 [algebra ℚ R] [norm_one_class R] (n : ℕ) (hn : n ≠ 0) : (algebra_map ℚ R) (1 / ↑n) * (1 - ↑(χ (zmod.unit_of_coprime c (nat.coprime_mul_iff_right.2 ⟨hc', nat.coprime.pow_right m hc⟩))) * (mul_inv_pow p d R n) (zmod.unit_of_coprime c hc', (is_unit.unit (padic_int.nat_is_unit_of_not_dvd ((fact.out (nat.prime p)).coprime_iff_not_dvd.mp (nat.coprime.symm hc))) --(is_unit_iff_not_dvd _ _ ((fact.out (nat.prime p)).coprime_iff_not_dvd.mp (nat.coprime.symm hc))) ))) * (1 - (asso_dirichlet_character (χ.mul (teichmuller_character_mod_p' p R ^ n))) ↑p * ↑p ^ (n - 1)) * general_bernoulli_number (χ.mul (teichmuller_character_mod_p' p R ^ n)) n = (1 - (asso_dirichlet_character (χ.mul (teichmuller_character_mod_p' p R ^ n))) ↑p * ↑p ^ (n - 1)) * general_bernoulli_number (χ.mul (teichmuller_character_mod_p' p R ^ n)) n - ((algebra_map ℚ R) ((↑n - 1) / ↑n) + (algebra_map ℚ R) (1 / ↑n) * (asso_dirichlet_character (χ.mul (teichmuller_character_mod_p' p R ^ n))) ↑c * ↑c ^ n) * ((1 - (asso_dirichlet_character (χ.mul (teichmuller_character_mod_p' p R ^ n))) ↑p * ↑p ^ (n - 1)) * general_bernoulli_number (χ.mul (teichmuller_character_mod_p' p R ^ n)) n) + 0 := begin have h2 : nat.coprime c (d * p^m) := nat.coprime_mul_iff_right.2 ⟨hc', nat.coprime.pow_right _ hc⟩, have h1 : is_unit (c : zmod (d * p^m)) := is_unit_of_is_coprime_dvd dvd_rfl h2, --((fact.out (nat.prime p)).coprime_iff_not_dvd.mp (nat.coprime.symm hc)), rw add_zero, rw ← one_sub_mul, rw mul_assoc, congr, rw ← sub_sub, rw sub_div, rw div_self _, --rw ← sub_mul, apply congr_arg2 _ _ rfl, rw sub_div, rw div_self _, --simp, rw ring_hom.map_sub, rw ring_hom.map_one, rw sub_sub_cancel (1 : R), rw mul_assoc, rw ← mul_one_sub, congr' 2, -- rw teichmuller_character_mod_p_change_level_def, rw mul_eval_of_coprime, rw mul_assoc, congr, { rw asso_dirichlet_character_eq_char' _ h1, congr, rw units.ext_iff, rw is_unit.unit_spec, rw zmod.coe_unit_of_coprime, }, { delta mul_inv_pow, change (mul_inv_pow_hom p d R n).to_fun _ = _, delta mul_inv_pow_hom, simp only, rw asso_dirichlet_character_eq_char' _ (is_unit_of_is_coprime_dvd dvd_rfl hc), rw mul_pow, rw monoid_hom.comp_mul, rw monoid_hom.comp_mul, rw monoid_hom.comp_mul, rw monoid_hom.to_fun_eq_coe, rw mul_comm, rw monoid_hom.mul_apply, delta teichmuller_character_mod_p', simp_rw monoid_hom.comp_apply, simp_rw monoid_hom.pow_apply, simp_rw units.coe_hom_apply, simp_rw units.coe_pow, simp_rw monoid_hom.map_pow, --rw ←monoid_hom.to_fun_eq_coe, simp_rw monoid_hom.comp_apply, rw ←monoid_hom.comp_inv, rw monoid_hom.comp_apply, rw units.coe_map, rw ring_hom.comp_to_monoid_hom, rw monoid_hom.comp_apply, rw monoid_hom.snd_apply, rw is_unit.unit_spec, congr, { rw units.ext_iff, rw units.coe_map, rw is_unit.unit_spec, rw is_unit.unit_spec, rw ring_hom.to_monoid_hom_eq_coe, rw ring_hom.coe_monoid_hom, rw map_nat_cast, }, { rw ring_hom.to_monoid_hom_eq_coe, rw ring_hom.coe_monoid_hom, rw ring_hom.to_monoid_hom_eq_coe, rw ring_hom.coe_monoid_hom, rw map_nat_cast, rw map_nat_cast, }, }, { apply nat.coprime.mul_right h2 hc, }, { norm_cast, apply hn, }, end lemma helpful_much {α β : Type*} [nonempty β] [semilattice_sup β] [topological_space α] [t2_space α] {a b : α} {f : filter β} [f.ne_bot] {g : β → α} (h1 : filter.tendsto g filter.at_top (nhds a)) (h2 : filter.tendsto g filter.at_top (nhds b)) : a = b := begin haveI : (@filter.at_top β _).ne_bot, { apply filter.at_top_ne_bot, }, have h3 := @filter.tendsto.lim_eq _ _ _ _ _ _ infer_instance _ h2, have h4 := @filter.tendsto.lim_eq _ _ _ _ _ _ infer_instance _ h1, rw ← h3, rw ← h4, end lemma helper_269 (n : ℕ) (y : (zmod (d * p^n))ˣ) : (zmod.chinese_remainder (nat.coprime.pow_right n hd)).inv_fun (↑(((units.chinese_remainder (nat.coprime.pow_right n hd)) y).fst), ↑(((units.chinese_remainder (nat.coprime.pow_right n hd)) y).snd)) = (y : zmod (d * p^n)) := begin delta units.chinese_remainder, delta mul_equiv.prod_units, delta units.map_equiv, simp, end lemma helper_idk' (n : ℕ) : (change_level (dvd_lcm_left (d * p^m) p) χ * change_level (dvd_lcm_right _ _) ((teichmuller_character_mod_p' p R) ^n)).conductor ∣ d * p^m := (dvd_trans (conductor.dvd_lev _) (by { rw helper_4 m, })) lemma exists_pow_of_dvd_mul_pow (hd : d.coprime p) (hχ : d ∣ χ.conductor) (n : ℕ) : ∃ k : ℕ, (change_level (dvd_lcm_left (d * p^m) p) χ * change_level (dvd_lcm_right _ _) (teichmuller_character_mod_p' p R ^ n)).conductor = d * p^k := begin obtain ⟨y, hy⟩ := dvd_mul_of_dvd_conductor p d R m χ n hd hχ, have := helper_idk' p d R m χ n, --dvd_trans (conductor_dvd (χ.mul (teichmuller_character_mod_p' p R ^ n))) (conductor_dvd _), rw (is_primitive_def _).1 (is_primitive.mul _ _) at hy, simp_rw [hy] at this, have dvd' := nat.dvd_of_mul_dvd_mul_left (fact.out _) this, obtain ⟨k, h1, h2⟩ := (nat.dvd_prime_pow (fact.out _)).1 dvd', use k, rw [hy, h2], end /-noncomputable abbreviation k (n : ℕ) (hχ : d ∣ χ.conductor) : ℕ := classical.some (exists_pow_of_dvd_mul_pow p d R m χ hd hχ n) abbreviation ψ (n : ℕ) (hχ : d ∣ χ.conductor) : dirichlet_character R (d * p^(k p d R m hd χ n hχ)) := -- gives a timeout-/ /-theorem cont_paLf'' [fact (0 < m)] : _root_.continuous ((units.coe_hom R).comp (dirichlet_char_extend p d R m hd ((χ --.mul --((teichmuller_character_mod_p' p R)^n)).change_level (helper_idk p d R m χ n ))) * w.to_monoid_hom) := continuous.mul (units.continuous_coe.comp (dirichlet_char_extend.continuous m hd _)) w.continuous_to_fun noncomputable def p_adic_L_function'' [normed_algebra ℚ_[p] R] [nontrivial R] [complete_space R] [norm_one_class R] [fact (0 < d)] [fact (0 < m)] (hχ : d ∣ χ.conductor) : R := (@measure.integral _ _ _ _ _ _ _ _ (bernoulli_measure' R hc hc' hd na) ⟨(units.coe_hom R).comp (dirichlet_char_extend p d R m hd ((χ.mul ((teichmuller_character_mod_p' p R))).change_level (helper_idk p d R m χ))) * w.to_monoid_hom, cont_paLf'' p d R m hd _ w⟩) -- cont_paLf' m hd χ w -/ open filter -- `pls_help` changed to `rev_prod_hom` noncomputable abbreviation rev_prod_hom (y : ℕ) : (zmod d)ˣ × ℤ_[p]ˣ →* (zmod (d * p^y))ˣ := monoid_hom.comp (units.map (zmod.chinese_remainder (nat.coprime.pow_right y hd)).symm.to_monoid_hom) (monoid_hom.comp (mul_equiv.to_monoid_hom mul_equiv.prod_units.symm) ((monoid_hom.prod_map (monoid_hom.id (zmod d)ˣ) (units.map (@padic_int.to_zmod_pow p _ y).to_monoid_hom)))) -- dot notation does not work for mul_equiv.to_monoid_hom? lemma is_loc_const_rev_prod_hom (y : ℕ) : is_locally_constant (rev_prod_hom p d hd y) := begin delta rev_prod_hom, apply is_locally_constant.comp_continuous, { convert is_locally_constant.of_discrete _, apply_instance, }, { simp only [ring_hom.to_monoid_hom_eq_coe, monoid_hom.coe_comp, mul_equiv.coe_to_monoid_hom, monoid_hom.coe_prod_map, function.comp_app, _root_.prod_map, monoid_hom.id_apply], refine continuous.comp continuous_of_discrete_topology (continuous_fst.prod_mk (continuous.comp (padic_int.continuous_units _) continuous_snd)), }, end lemma zmod.cast_cast {n : ℕ} [fact (0 < n)] (l m : ℕ) (a : zmod n) (h1 : l ∣ m) : ((a : zmod m) : zmod l) = (a : zmod l) := begin rw ← zmod.nat_cast_val a, rw zmod.cast_nat_cast h1, { rw zmod.nat_cast_val, }, { refine zmod.char_p _, }, end lemma ring_equiv.coe_to_monoid_hom {R S : Type*} [non_assoc_semiring R] [non_assoc_semiring S] (e : R ≃+* S) : ⇑e.to_monoid_hom = e := by { ext, change e.to_ring_hom.to_monoid_hom x = _, rw ring_hom.to_monoid_hom_eq_coe, rw ring_hom.coe_monoid_hom, rw ring_equiv.to_ring_hom_eq_coe, rw ring_equiv.coe_to_ring_hom, } lemma ring_equiv.eq_symm_apply {R S : Type*} [non_assoc_semiring R] [non_assoc_semiring S] (e : R ≃+* S) (x : S) (y : R) : y = e.symm x ↔ e y = x := by { refine ⟨λ h, _, λ h, _⟩, { rw h, simp, }, { rw ← h, simp, }, } lemma zmod.coe_proj {x : ℕ} (hx : m < x) (a : (zmod d)ˣ × ℤ_[p]ˣ) : ↑(((zmod.chinese_remainder (nat.coprime.pow_right x hd)).symm.to_monoid_hom) (↑(a.fst), (padic_int.to_zmod_pow x) ↑(a.snd))) = ((zmod.chinese_remainder (nat.coprime.pow_right m hd)).symm.to_monoid_hom) (↑(a.fst), (padic_int.to_zmod_pow m) ↑(a.snd)) := begin --haveI : fact (0 < d * p ^ x), { apply imp p d x, }, rw ring_equiv.coe_to_monoid_hom (zmod.chinese_remainder (nat.coprime.pow_right x hd)).symm, rw ring_equiv.coe_to_monoid_hom (zmod.chinese_remainder (nat.coprime.pow_right m hd)).symm, rw ring_equiv.eq_symm_apply, apply prod.ext, { rw ← ring_equiv.coe_to_equiv, rw ← ring_equiv.to_equiv_eq_coe, rw inv_fst' _ (nat.coprime.pow_right _ hd), rw zmod.cast_cast _ _ _ (dvd_mul_right d _), simp_rw proj_fst'', change (zmod.cast_hom (dvd_mul_right d (p^x)) (zmod d)) ((zmod.chinese_remainder (nat.coprime.pow_right _ hd)).symm (↑(a.fst), (padic_int.to_zmod_pow x) ↑(a.snd))) = _, rw proj_fst' (nat.coprime.pow_right x hd) (↑(a.fst)) _, apply_instance, }, { rw ← ring_equiv.coe_to_equiv, rw ← ring_equiv.to_equiv_eq_coe, rw inv_snd' _ (nat.coprime.pow_right _ hd), rw zmod.cast_cast _ _ _ (dvd_mul_left _ d), have h2 : p^m ∣ p^x, apply pow_dvd_pow p (le_of_lt hx), rw ← zmod.cast_cast _ _ _ h2, -- rw ← ring_equiv.inv_fun_eq_symm, change _ = (padic_int.to_zmod_pow m) ↑(a.snd), rw ← padic_int.cast_to_zmod_pow m x (le_of_lt hx) _, apply congr_arg, change (zmod.cast_hom (dvd_mul_left (p^x) d) (zmod (p^x))) ((zmod.chinese_remainder (nat.coprime.pow_right _ hd)).symm (↑(a.fst), (padic_int.to_zmod_pow x) ↑(a.snd))) = _, simp_rw proj_snd' (nat.coprime.pow_right x hd) (↑(a.fst)) _, apply_instance, apply_instance, }, end lemma helper_281 {x : ℕ} (hx : m < x) (a : (zmod d)ˣ × ℤ_[p]ˣ) : (((rev_prod_hom p d hd x) a) : zmod (d * p^m)) = ↑((rev_prod_hom p d hd m) a) := begin change ((units.map (zmod.cast_hom (mul_dvd_mul_left d (pow_dvd_pow p (le_of_lt hx))) (zmod (d * p^m))).to_monoid_hom) (rev_prod_hom p d hd x a) : zmod (d * p^m)) = _, rw units.coe_map, delta rev_prod_hom, simp_rw monoid_hom.comp_apply, rw units.coe_map, rw units.coe_map, simp only [ring_hom.to_monoid_hom_eq_coe, monoid_hom.coe_prod_map, _root_.prod_map, monoid_hom.id_apply, mul_equiv.coe_to_monoid_hom, ring_hom.coe_monoid_hom, zmod.cast_hom_apply], delta mul_equiv.prod_units, simp, rw zmod.coe_proj p d m hd hx a, end lemma units_chinese_remainder_comp_rev_prod_hom (x : ℕ) (a : (zmod d)ˣ × ℤ_[p]ˣ) : (units.chinese_remainder (nat.coprime.pow_right x hd)) ((rev_prod_hom p d hd x) a) = (a.fst, units.map (@padic_int.to_zmod_pow p _ x).to_monoid_hom a.snd) := begin delta rev_prod_hom, rw monoid_hom.comp_apply, convert mul_equiv.apply_symm_apply _ _, end . lemma units_chinese_remainder_comp_rev_prod_hom_fst (x : ℕ) (a : (zmod d)ˣ × ℤ_[p]ˣ) : ((units.chinese_remainder (nat.coprime.pow_right x hd)) ((rev_prod_hom p d hd x) a)).fst = a.fst := by { rw units_chinese_remainder_comp_rev_prod_hom p d hd x a, } lemma units_chinese_remainder_comp_rev_prod_hom_snd (x : ℕ) (a : (zmod d)ˣ × ℤ_[p]ˣ) : ((units.chinese_remainder (nat.coprime.pow_right x hd)) ((rev_prod_hom p d hd x) a)).snd = units.map (@padic_int.to_zmod_pow p _ x).to_monoid_hom a.snd := by { rw units_chinese_remainder_comp_rev_prod_hom p d hd x a, } lemma helper_256 (n : ℕ) (hn : 1 < n) : (λ y : ℕ, ((∑ (a : (zmod (d * p ^ y))ˣ), ((asso_dirichlet_character (χ.mul (teichmuller_character_mod_p' p R ^ n))) ↑a * ↑((a : zmod (d * p^y)).val) ^ (n - 1)) • _root_.char_fn R (clopen_from.is_clopen_units ((units.chinese_remainder (nat.coprime.pow_right y hd)) a)) : locally_constant ((zmod d)ˣ × ℤ_[p]ˣ) R) : C((zmod d)ˣ × ℤ_[p]ˣ, R))) =ᶠ[at_top] (λ y : ℕ, (⟨λ x, (change_level (helper_change_level_conductor m χ) (χ.mul (teichmuller_character_mod_p' p R)) ((rev_prod_hom p d hd m) x) : R), is_locally_constant.continuous begin apply is_locally_constant.comp _ _, apply is_locally_constant.comp _ _, apply is_loc_const_rev_prod_hom, end⟩) * (((⟨λ x, ↑(rev_prod_hom p d hd y x : zmod (d * p^y)) ^ (n - 1), is_locally_constant.continuous begin apply is_locally_constant.comp₂, { apply is_locally_constant.comp _ _, apply is_locally_constant.comp _ _, apply is_loc_const_rev_prod_hom, }, { apply is_locally_constant.const, }, end⟩ ) * ⟨λ x, (change_level (dvd_mul_of_dvd_right (dvd_pow dvd_rfl (nat.ne_zero_of_lt' 0)) d) ((teichmuller_character_mod_p' p R) ^ (n - 1)) ((rev_prod_hom p d hd m) x) : R), is_locally_constant.continuous begin apply is_locally_constant.comp _ _, apply is_locally_constant.comp _ _, apply is_loc_const_rev_prod_hom, end⟩ ))) := begin rw eventually_eq_iff_exists_mem, set s : set ℕ := {x : ℕ | m < x} with hs, refine ⟨s, _, _⟩, { rw mem_at_top_sets, refine ⟨m.succ, λ b hb, _⟩, change m < b, apply nat.succ_le_iff.1 hb, }, { rw set.eq_on, rintros x hx, ext, simp only, rw coe_mul, rw coe_mul, rw pi.mul_apply, rw pi.mul_apply, rw locally_constant.coe_continuous_map, --rw locally_constant.coe_sum, rw locally_constant.sum_apply', simp_rw locally_constant.smul_apply, have h1 : is_unit ((rev_prod_hom p d hd x a) : zmod (d * p^m)), { apply coe_map_of_dvd, apply mul_dvd_mul_left d (pow_dvd_pow p (le_of_lt hx)), }, rw finset.sum_eq_single_of_mem (rev_prod_hom p d hd x a), { rw (char_fn_one R _ _).1, rw smul_eq_mul, rw mul_one, conv_rhs { rw mul_comm, rw mul_assoc, rw mul_comm, }, rw zmod.nat_cast_val, congr, rw ← to_fun_eq_coe, rw ← to_fun_eq_coe, simp only, rw ← units.coe_mul, { rw asso_dirichlet_character_eq_char' _ _, swap 2, { -- change name of lemma apply coe_map_of_dvd (dvd_trans (helper_idk' p d R m χ n) (mul_dvd_mul_left d (pow_dvd_pow p (le_of_lt hx)))) _, }, apply congr_arg, rw ← monoid_hom.mul_apply, rw units.ext_iff, rw ←asso_dirichlet_character_eq_char', rw coe_coe, rw ←zmod.cast_cast _ _ (↑((rev_prod_hom p d hd x) a)) (helper_idk' p d R m χ n), rw ←coe_coe, rw helper_281 p d m hd hx, rw ←coe_coe, rw ←asso_dirichlet_character_eq_char, rw ←change_level.asso_dirichlet_character_eq (χ.mul (teichmuller_character_mod_p' p R ^ n)) (helper_idk' p d R m χ n) _, apply congr _ rfl, { -- rw ←asso_dirichlet_character_eq_iff, rw mul_def, rw mul_def, rw ←eq_asso_primitive_character_change_level, rw ←eq_asso_primitive_character_change_level, any_goals { rw helper_4, }, simp_rw [monoid_hom.map_mul, ←change_level.dvd], conv_rhs { rw mul_comm _ (change_level _ χ * _), rw mul_assoc, rw monoid_hom.map_pow, }, --_ (χ.mul teichmuller_character_mod_p' p R), }, rw ← pow_succ, rw nat.sub_add_cancel (le_of_lt hn), rw monoid_hom.map_pow, }, { apply_instance, }, }, { rw set.mem_prod, simp only [prod.fst_zmod_cast, prod.snd_zmod_cast, set.mem_singleton_iff, ring_hom.to_monoid_hom_eq_coe, set.mem_preimage], rw units.ext_iff, rw units.ext_iff, rw units_chinese_remainder_comp_rev_prod_hom, simp only [eq_self_iff_true, ring_hom.to_monoid_hom_eq_coe, and_self], }, }, { apply finset.mem_univ, }, { intros b h' hb, clear h', rw (char_fn_zero R _ _).1 _, { rw smul_zero, }, { intro h, rw set.mem_prod at h, rw set.mem_preimage at h, rw set.mem_singleton_iff at h, rw set.mem_singleton_iff at h, cases h with h2 h3, conv_lhs at h2 { rw ← units_chinese_remainder_comp_rev_prod_hom_fst p d hd x a, }, conv_lhs at h3 { rw ← units_chinese_remainder_comp_rev_prod_hom_snd p d hd x a, }, apply hb, apply mul_equiv.injective (units.chinese_remainder (nat.coprime.pow_right x hd)), symmetry, apply prod.ext h2 h3, }, }, }, end lemma helper_271 (n : ℕ) : continuous (λ x : (zmod d)ˣ × ℤ_[p]ˣ, ((algebra_map ℚ_[p] R) (padic_int.coe.ring_hom (x.snd : ℤ_[p])))) := begin continuity, { rw algebra.algebra_map_eq_smul_one', exact continuous_id'.smul continuous_const, }, { exact units.continuous_coe, }, end lemma helper_272 (a : (zmod d)ˣ × ℤ_[p]ˣ) : ↑(((zmod.chinese_remainder (nat.coprime.pow_right m hd)).symm.to_monoid_hom) (↑(a.fst), (padic_int.to_zmod_pow m) ↑(a.snd))) = (@padic_int.to_zmod_pow p _ m) ↑(a.snd) := begin have := proj_snd' (nat.coprime.pow_right _ hd) (a.fst : zmod d) ((padic_int.to_zmod_pow m) ↑(a.snd)), conv_rhs { rw ← this, }, simp only [ring_equiv.inv_fun_eq_symm, zmod.cast_hom_apply], congr, end --the underlying def for to_zmod and to_zmod_pow are different, this causes an issue, dont want to -- use equi between p and p^1 ; maybe ring_hom.ext_zmod can be extended to ring_hom.padic_ext? lemma padic_int.to_zmod_pow_cast_to_zmod (n : ℕ) (hn : n ≠ 0) (x : ℤ_[p]) : (padic_int.to_zmod_pow n x : zmod p) = padic_int.to_zmod x := begin apply padic_int.dense_range_int_cast.induction_on x, { refine is_closed_eq _ _, { continuity, apply padic_int.continuous_to_zmod_pow, }, { apply padic_int.continuous_to_zmod, }, }, { intro a, change (zmod.cast_hom (dvd_pow_self p hn) (zmod p)).comp (padic_int.to_zmod_pow n) (a : ℤ_[p]) = padic_int.to_zmod (a : ℤ_[p]), rw ring_hom.map_int_cast, rw ring_hom.map_int_cast, }, end lemma helper_258 (n : ℕ) : continuous_monoid_hom.to_continuous_map (mul_inv_pow p d R (n - 1)) = ((⟨λ x, ((algebra_map ℚ_[p] R) (padic_int.coe.ring_hom (x.snd : ℤ_[p]))), helper_271 p d R n⟩ : C((zmod d)ˣ × ℤ_[p]ˣ, R))^ (n - 1) * (⟨λ x, (change_level (dvd_mul_of_dvd_right (dvd_pow dvd_rfl (nat.ne_zero_of_lt' 0)) d) ((teichmuller_character_mod_p' p R)^(n - 1)) ((rev_prod_hom p d hd m) x) : R), begin apply is_locally_constant.comp _ _, apply is_locally_constant.comp _ _, apply is_loc_const_rev_prod_hom, end⟩ : locally_constant ((zmod d)ˣ × ℤ_[p]ˣ) R)) := begin ext, change mul_inv_pow_hom p d R (n - 1) a = _, delta mul_inv_pow_hom, rw mul_pow, simp_rw monoid_hom.comp_mul, rw coe_mul, rw pi.mul_apply, rw monoid_hom.mul_apply, apply congr_arg2 _ _ _, { change _ = ((algebra_map ℚ_[p] R) (padic_int.coe.ring_hom ↑(a.snd)))^(n - 1), rw ← ring_hom.map_pow, rw ← ring_hom.map_pow, rw ← units.coe_pow, refl, }, { change _ = ↑(change_level (dvd_mul_of_dvd_right (dvd_pow dvd_rfl (nat.ne_zero_of_lt' 0)) d) ((teichmuller_character_mod_p' p R) ^ (n - 1)) ((rev_prod_hom p d hd m) a)), delta teichmuller_character_mod_p', --rw dirichlet_character.pow_apply, simp_rw monoid_hom.comp_apply, change ((algebra_map ℚ_[p] R).to_monoid_hom) ((padic_int.coe.ring_hom.to_monoid_hom) ((units.coe_hom ℤ_[p]) (((monoid_hom.comp (teichmuller_character_mod_p p)⁻¹ (units.map padic_int.to_zmod.to_monoid_hom)) (a.snd)^(n - 1))))) = _, rw monoid_hom.map_pow, rw monoid_hom.map_pow, rw monoid_hom.map_pow, rw monoid_hom.map_pow, rw dirichlet_character.pow_apply, rw units.coe_pow, apply congr_arg2 _ _ rfl, --rw teichmuller_character_mod_p_change_level_def, rw units.coe_hom_apply, rw dirichlet_character.change_level_def, conv_rhs { rw monoid_hom.comp_apply, rw monoid_hom.inv_apply, rw monoid_hom.comp_apply, }, rw ← monoid_hom.map_inv, rw units.coe_map, rw ← monoid_hom.comp_apply, rw ← ring_hom.comp_to_monoid_hom, apply congr_arg, rw ← units.ext_iff, rw monoid_hom.comp_apply, rw monoid_hom.inv_apply, apply congr_arg, apply congr_arg, rw units.ext_iff, rw units.coe_map, rw units.coe_map, rw units.coe_map, delta mul_equiv.prod_units, simp, have mnz : m ≠ 0, { apply ne_of_gt (fact.out _), apply_instance, apply_instance, }, rw ← zmod.cast_cast _ _ _ (dvd_pow_self p mnz), rw helper_272 p d m hd a, rw padic_int.to_zmod_pow_cast_to_zmod p _ mnz _, { apply_instance, }, }, end -- make change_level a monoid_hom? lemma helper_259 (n : ℕ) : filter.tendsto (λ (x : ℕ), ((⟨λ (x : (zmod d)ˣ × ℤ_[p]ˣ), ↑(change_level (helper_change_level_conductor m χ) (χ.mul (teichmuller_character_mod_p' p R)) ((rev_prod_hom p d hd m) x)), begin apply is_locally_constant.comp _ _, apply is_locally_constant.comp _ _, apply is_loc_const_rev_prod_hom, end⟩ : locally_constant ((zmod d)ˣ × ℤ_[p]ˣ) R) : C((zmod d)ˣ × ℤ_[p]ˣ, R))) filter.at_top (nhds ⟨((units.coe_hom R).comp (dirichlet_char_extend p d R m hd (change_level (helper_change_level_conductor m χ) (χ.mul (teichmuller_character_mod_p' p R))))), units.continuous_coe.comp (dirichlet_char_extend.continuous p d R m hd _)⟩) := begin -- for later : try to use this instead : convert tendsto_const_nhds, rw metric.tendsto_at_top, intros ε hε, refine ⟨1, λ y hy, _⟩, rw dist_eq_norm, rw norm_eq_supr_norm, rw coe_sub, simp_rw pi.sub_apply, simp_rw ← to_fun_eq_coe, simp_rw monoid_hom.comp_apply, simp_rw units.coe_hom_apply, have calc1 : ε/2 < ε, by linarith, apply lt_of_le_of_lt _ calc1, apply cSup_le (set.range_nonempty _) (λ b hb, _), { apply_instance, }, cases hb with y hy, rw ← hy, simp only, clear hy, convert le_of_lt (half_pos hε), rw norm_eq_zero, rw ← locally_constant.to_continuous_map_eq_coe, delta locally_constant.to_continuous_map, simp_rw ← locally_constant.to_fun_eq_coe, rw sub_eq_zero, end lemma helper_263 : continuous (λ (x : (zmod d)ˣ × ℤ_[p]ˣ), (algebra_map ℚ_[p] R) (padic_int.coe.ring_hom ↑(x.snd))) := by { continuity, { rw algebra.algebra_map_eq_smul_one', exact continuous_id'.smul continuous_const, }, { exact units.continuous_coe, }, } open padic_int lemma helper_268 (x : ℤ_[p]) (n : ℕ) : (@padic_int.to_zmod_pow p _ n x : ℤ_[p]) = (padic_int.appr x n : ℤ_[p]) := begin haveI : fact (0 < p^n) := fact_iff.2 (pow_pos (nat.prime.pos (fact.out _)) _), rw ← zmod.nat_cast_val, congr, change (x.appr n : zmod (p^n)).val = _, rw zmod.val_cast_of_lt, apply padic_int.appr_lt, end lemma helper_267 (n x : ℕ) : @padic_int.to_zmod_pow p _ n (x : ℤ_[p]) = (x : zmod (p^n)) := by { simp, } lemma helper_261 [norm_one_class R] : filter.tendsto (λ (x : ℕ), (⟨λ (z : (zmod d)ˣ × ℤ_[p]ˣ), ↑((@padic_int.to_zmod_pow p _ x) ↑(z.snd)), continuous.comp continuous_bot (continuous.comp (padic_int.continuous_to_zmod_pow x) (continuous.comp units.continuous_coe continuous_snd))⟩ : C((zmod d)ˣ × ℤ_[p]ˣ, R))) filter.at_top (nhds ⟨λ (x : (zmod d)ˣ × ℤ_[p]ˣ), (algebra_map ℚ_[p] R) (padic_int.coe.ring_hom ↑(x.snd)), helper_263 p d R⟩) := begin rw metric.tendsto_at_top, intros ε hε, refine ⟨classical.some (padic_int.exists_pow_neg_lt p (half_pos hε)), λ n hn, _⟩, rw dist_eq_norm, rw norm_eq_supr_norm, simp only [continuous_map.coe_sub, coe_mk, pi.sub_apply], have calc1 : ε/2 < ε, by linarith, apply lt_of_le_of_lt _ calc1, apply cSup_le (set.range_nonempty _) (λ b hb, _), { apply_instance, }, cases hb with y hy, rw ← hy, simp only, clear hy, haveI : fact (0 < p^n) := fact_iff.2 (pow_pos (nat.prime.pos (fact.out _)) _), have : (algebra_map ℚ_[p] R) (padic_int.coe.ring_hom ↑((@padic_int.to_zmod_pow p _ n) ↑(y.snd))) = ((@padic_int.to_zmod_pow p _ n) (y.snd : ℤ_[p]) : R), { change ((algebra_map ℚ_[p] R).comp (@padic_int.coe.ring_hom p _)) (↑((padic_int.to_zmod_pow n) ↑(y.snd))) = _, rw ← zmod.nat_cast_val, rw map_nat_cast, rw zmod.nat_cast_val, }, rw ← this, simp_rw ← ring_hom.map_sub, rw norm_algebra_map', rw padic_int.coe.ring_hom, simp only [ring_hom.coe_mk], rw padic_int.padic_norm_e_of_padic_int, have finally := dist_appr_spec (y.snd : ℤ_[p]) n, rw dist_eq_norm at finally, rw norm_sub_rev, have final := classical.some_spec (padic_int.exists_pow_neg_lt p (half_pos hε)), apply le_of_lt, apply lt_of_le_of_lt _ final, rw helper_268 p _ n, apply le_trans finally _, apply zpow_le_of_le, { norm_cast, apply le_of_lt (nat.prime.one_lt (fact.out _)), apply_instance, }, { apply neg_le_neg, norm_cast, apply hn, }, end lemma helper_262 [norm_one_class R] : filter.tendsto (λ (x : ℕ), dist (⟨λ (z : (zmod d)ˣ × ℤ_[p]ˣ), ↑((@padic_int.to_zmod_pow p _ x) ↑(z.snd)), continuous.comp continuous_bot (continuous.comp (padic_int.continuous_to_zmod_pow x) (continuous.comp units.continuous_coe continuous_snd))⟩ : C((zmod d)ˣ × ℤ_[p]ˣ, R)) (⟨λ (y : (zmod d)ˣ × ℤ_[p]ˣ), ↑((rev_prod_hom p d hd x) y), continuous.comp continuous_of_discrete_topology (is_locally_constant.continuous (is_loc_const_rev_prod_hom p d hd _))⟩)) filter.at_top (nhds 0) := begin -- use norm_le! rw metric.tendsto_at_top, intros ε hε, refine ⟨classical.some (padic_int.exists_pow_neg_lt p (half_pos hε)), λ n hn, _⟩, rw dist_zero_right, rw dist_eq_norm, rw norm_norm, rw norm_eq_supr_norm, simp only [continuous_map.coe_sub, coe_mk, pi.sub_apply], have calc1 : ε/2 < ε, by linarith, apply lt_of_le_of_lt _ calc1, apply cSup_le (set.range_nonempty _) (λ b hb, _), { apply_instance, }, cases hb with y hy, rw ← hy, simp only, clear hy, rw norm_sub_rev, delta rev_prod_hom, change ∥(((units.map (zmod.chinese_remainder (nat.coprime.pow_right n hd)).symm.to_monoid_hom) ((mul_equiv.prod_units.symm) (((monoid_hom.id (zmod d)ˣ).prod_map (units.map (@padic_int.to_zmod_pow p _ n).to_monoid_hom)) y)) : zmod (d * p^n)) : R) - _∥ ≤ ε/2, rw units.coe_map, change ∥(↑(((zmod.chinese_remainder (nat.coprime.pow_right n hd)).symm) ↑((mul_equiv.prod_units.symm) (y.1, (units.map (@padic_int.to_zmod_pow p _ n).to_monoid_hom) y.2)))) - _∥ ≤ ε/2, simp_rw ← mul_equiv.inv_fun_eq_symm, delta mul_equiv.prod_units, simp only, simp_rw units.coe_mk, simp_rw units.coe_map, change ∥↑(((zmod.chinese_remainder (nat.coprime.pow_right n hd)).inv_fun) (↑(y.fst), ((padic_int.to_zmod_pow n)) ↑(y.snd))) - _∥ ≤ ε/2, have := proj_snd ((y.fst : zmod d), (y.snd : ℤ_[p])) (nat.coprime.pow_right n hd), change ↑((zmod.chinese_remainder _).inv_fun (↑(y.fst), (padic_int.to_zmod_pow n) (↑(y.snd)))) = (padic_int.to_zmod_pow n) (↑(y.snd)) at this, haveI : fact (0 < p^n) := fact_iff.2 (pow_pos (nat.prime.pos (fact.out _)) _), conv { congr, congr, congr, rw ← zmod.nat_cast_val, rw ← map_nat_cast ((algebra_map ℚ_[p] R).comp (padic_int.coe.ring_hom)), skip, rw ← this, rw ← zmod.nat_cast_val, rw ← zmod.nat_cast_val, rw ← map_nat_cast ((algebra_map ℚ_[p] R).comp (padic_int.coe.ring_hom)), rw zmod.nat_cast_val, }, -- this entire pricess should be a separate lemma rw ← ring_hom.map_sub, rw ring_hom.comp_apply, rw norm_algebra_map', rw padic_int.coe.ring_hom, simp only [ring_hom.coe_mk], rw padic_int.padic_norm_e_of_padic_int, rw ← helper_267, rw helper_268, rw ← dist_eq_norm, apply le_trans (dist_appr_spec _ _) _, have final := classical.some_spec (padic_int.exists_pow_neg_lt p (half_pos hε)), apply le_of_lt, apply lt_of_le_of_lt _ final, apply zpow_le_of_le, { norm_cast, apply le_of_lt (nat.prime.one_lt (fact.out _)), apply_instance, }, { apply neg_le_neg, norm_cast, apply hn, }, end lemma helper_260 [norm_one_class R] (n : ℕ) : filter.tendsto (λ (x : ℕ), ↑(⟨λ (y : (zmod d)ˣ × ℤ_[p]ˣ), ((rev_prod_hom p d hd x) y : R) ^ (n - 1), begin apply is_locally_constant.comp₂, { apply is_locally_constant.comp _ _, apply is_loc_const_rev_prod_hom, }, { apply is_locally_constant.const, }, end⟩ : locally_constant ((zmod d)ˣ × ℤ_[p]ˣ) R)) filter.at_top (nhds ((⟨λ (x : (zmod d)ˣ × ℤ_[p]ˣ), (algebra_map ℚ_[p] R) (padic_int.coe.ring_hom ↑(x.snd)), begin continuity, { rw algebra.algebra_map_eq_smul_one', exact continuous_id'.smul continuous_const, }, { exact units.continuous_coe, }, end⟩ : C((zmod d)ˣ × ℤ_[p]ˣ, R))^(n - 1))) := begin change filter.tendsto (λ x : ℕ, (⟨λ y, ((rev_prod_hom p d hd x) y : R), begin continuity, { simp only, apply continuous_of_discrete_topology, }, { apply is_locally_constant.continuous (is_loc_const_rev_prod_hom p d hd x), }, end⟩ : C((zmod d)ˣ × ℤ_[p]ˣ, R))^(n - 1)) filter.at_top _, apply filter.tendsto.pow _ (n - 1), { apply_instance, }, { apply filter.tendsto.congr_dist, swap 3, { refine λ x, ⟨λ z, padic_int.to_zmod_pow x (z.snd : ℤ_[p]), continuous.comp continuous_bot (continuous.comp (padic_int.continuous_to_zmod_pow x) (continuous.comp units.continuous_coe continuous_snd))⟩, }, apply helper_261, apply helper_262, }, end theorem p_adic_L_function_eval_neg_int [algebra ℚ R] [norm_one_class R] [no_zero_divisors R] [is_scalar_tower ℚ ℚ_[p] R] (n : ℕ) (hn : 1 < n) (hχ : χ.is_even) (hp : 2 < p) (na : ∀ (n : ℕ) (f : ℕ → R), ∥ ∑ (i : ℕ) in finset.range n, f i∥ ≤ ⨆ (i : zmod n), ∥f i.val∥) (hp : 2 < p) (hχ : χ.is_even) (hχ1 : d ∣ χ.conductor) --(hχ2 : p ∣ (χ.mul (((teichmuller_character_mod_p' p R)^n))).conductor) (na' : ∀ (n : ℕ) (f : (zmod n)ˣ → R), ∥∑ i : (zmod n)ˣ, f i∥ ≤ ⨆ (i : (zmod n)ˣ), ∥f i∥) (na : ∀ (n : ℕ) (f : ℕ → R), ∥∑ i in finset.range n, f i∥ ≤ ⨆ (i : zmod n), ∥f i.val∥) : (p_adic_L_function m hd χ c hc hc' na (mul_inv_pow p d R (n - 1))) = (algebra_map ℚ R) (1 / n : ℚ) * (1 - (χ (zmod.unit_of_coprime c (nat.coprime_mul_iff_right.2 ⟨hc', nat.coprime.pow_right m hc⟩)) * (mul_inv_pow p d R n (zmod.unit_of_coprime c hc', is_unit.unit (padic_int.nat_is_unit_of_not_dvd ((fact.out (nat.prime p)).coprime_iff_not_dvd.mp (nat.coprime.symm hc)) )) ))) * (1 - ((asso_dirichlet_character (dirichlet_character.mul χ ((teichmuller_character_mod_p' p R)^n))) p * p^(n - 1)) ) * (general_bernoulli_number (dirichlet_character.mul χ ((teichmuller_character_mod_p' p R)^n)) n) := begin delta p_adic_L_function, have h1 := filter.tendsto.add (filter.tendsto.sub (U p d R m χ hd n hn hχ hχ1 hp na) (V p d R m χ c hd hc' hc hp hχ hχ1 na' na n hn)) (W p d R m χ c hd hp na' na n hn hχ), conv at h1 { congr, skip, skip, rw ← helper_254 p d R m χ c hc hc' n (ne_zero_of_lt hn), }, symmetry, apply helpful_much h1, clear h1, swap 3, { apply filter.at_top_ne_bot, }, convert (tendsto_congr' _).2 (trying p d R hd hc hc' na _ (λ j : ℕ, ∑ (a : (zmod (d * p^j))ˣ), (((asso_dirichlet_character (χ.mul ((teichmuller_character_mod_p' p R)^n)) a : R) * ((((a : zmod (d * p^j))).val)^(n - 1) : R))) • (_root_.char_fn R (clopen_from.is_clopen_units ((units.chinese_remainder (nat.coprime.pow_right j hd)) a)))) _), { rw eventually_eq_iff_exists_mem, set s : set ℕ := {x : ℕ | 1 < x} with hs, refine ⟨s, _, _⟩, { rw mem_at_top_sets, refine ⟨nat.succ 1, λ b hb, _⟩, change 1 < b, apply nat.succ_le_iff.1 hb, }, rw set.eq_on, rintros x hx, simp only, delta U_def, delta V_def, rw linear_map.map_sum, simp_rw linear_map.map_smul, convert finset.sum_congr rfl _, swap 3, { intros z hz, rw bernoulli_measure_eval_char_fn, apply hx, }, rw bernoulli_distribution, simp only, simp_rw [helper_269, ring_hom.map_add, ring_hom.map_sub, zmod.nat_cast_val, smul_add, smul_sub], rw finset.sum_add_distrib, rw finset.sum_sub_distrib, simp_rw is_scalar_tower.algebra_map_apply ℚ ℚ_[p] R, congr, }, { rw tendsto_congr' (helper_256 p d R m hd χ n hn), change tendsto _ at_top (nhds ((⟨((units.coe_hom R).comp (dirichlet_char_extend p d R m hd (change_level (helper_change_level_conductor m χ) (χ.mul (teichmuller_character_mod_p' p R))))), units.continuous_coe.comp _⟩ : C((zmod d)ˣ × ℤ_[p]ˣ, R)) * ⟨((mul_inv_pow p d R (n - 1)).to_monoid_hom), ((mul_inv_pow p d R (n - 1))).continuous_to_fun⟩)), apply filter.tendsto.mul _ _, { exact semi_normed_ring_top_monoid, }, { apply helper_259 p d R m hd χ n, }, { change filter.tendsto _ filter.at_top (nhds (mul_inv_pow p d R (n - 1)).to_continuous_map), rw helper_258 p d R m hd n, apply filter.tendsto.mul, { apply helper_260, }, { apply tendsto_const_nhds, }, }, }, end
theory TopoS_Helper imports Main TopoS_Interface TopoS_ENF vertex_example_simps begin lemma (in SecurityInvariant_preliminaries) sinvar_valid_remove_flattened_offending_flows: assumes "wf_graph \<lparr>nodes = nodesG, edges = edgesG\<rparr>" (*TODO: we could get rid of this assumption*) shows "sinvar \<lparr>nodes = nodesG, edges = edgesG - \<Union> (set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP) \<rparr> nP" proof - { fix f assume *: "f\<in>set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP" from * have 1: "sinvar \<lparr>nodes = nodesG, edges = edgesG - f \<rparr> nP" by (metis (opaque_lifting, mono_tags) SecurityInvariant_withOffendingFlows.valid_without_offending_flows delete_edges_simp2 graph.select_convs(1) graph.select_convs(2)) from * have 2: "edgesG - \<Union> (set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP) \<subseteq> edgesG - f" by blast note 1 2 } with assms show ?thesis by (metis (opaque_lifting, no_types) Diff_empty Union_empty defined_offending equals0I mono_sinvar wf_graph_remove_edges) qed lemma (in SecurityInvariant_preliminaries) sinvar_valid_remove_SOME_offending_flows: assumes "set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP \<noteq> {}" shows "sinvar \<lparr>nodes = nodesG, edges = edgesG - (SOME F. F \<in> set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP) \<rparr> nP" proof - { fix f assume *: "f\<in>set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP" from * have 1: "sinvar \<lparr>nodes = nodesG, edges = edgesG - f \<rparr> nP" by (metis (opaque_lifting, mono_tags) SecurityInvariant_withOffendingFlows.valid_without_offending_flows delete_edges_simp2 graph.select_convs(1) graph.select_convs(2)) from * have 2: "edgesG - \<Union> (set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP) \<subseteq> edgesG - f" by blast note 1 2 } with assms show ?thesis by (simp add: some_in_eq) qed lemma (in SecurityInvariant_preliminaries) sinvar_valid_remove_minimalize_offending_overapprox: assumes "wf_graph \<lparr>nodes = nodesG, edges = edgesG\<rparr>" and "\<not> sinvar \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP" (*"set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP \<noteq> {}"*) and "set Es = edgesG" and "distinct Es" shows "sinvar \<lparr>nodes = nodesG, edges = edgesG - set (minimalize_offending_overapprox Es [] \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP) \<rparr> nP" proof - from assms have off_Es: "is_offending_flows (set Es) \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP" by (metis (no_types, lifting) Diff_cancel SecurityInvariant_withOffendingFlows.valid_empty_edges_iff_exists_offending_flows defined_offending delete_edges_simp2 graph.select_convs(2) is_offending_flows_def sinvar_monoI) from minimalize_offending_overapprox_gives_back_an_offending_flow[OF assms(1) off_Es _ assms(4)] have in_offending: "set (minimalize_offending_overapprox Es [] \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP) \<in> set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP" using assms(3) by simp { fix f assume *: "f\<in>set_offending_flows \<lparr>nodes = nodesG, edges = edgesG\<rparr> nP" from * have 1: "sinvar \<lparr>nodes = nodesG, edges = edgesG - f \<rparr> nP" by (metis (opaque_lifting, mono_tags) SecurityInvariant_withOffendingFlows.valid_without_offending_flows delete_edges_simp2 graph.select_convs(1) graph.select_convs(2)) note 1 } with in_offending show ?thesis by (simp add: some_in_eq) qed end
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import data.nat.interval import data.nat.prime import group_theory.perm.sign import tactic.fin_cases example (f : ℕ → Prop) (p : fin 3) (h0 : f 0) (h1 : f 1) (h2 : f 2) : f p.val := begin fin_cases *, simp, assumption, simp, assumption, simp, assumption, end example (f : ℕ → Prop) (p : fin 0) : f p.val := by fin_cases * example (f : ℕ → Prop) (p : fin 1) (h : f 0) : f p.val := begin fin_cases p, assumption end example (x2 : fin 2) (x3 : fin 3) (n : nat) (y : fin n) : x2.val * x3.val = x3.val * x2.val := begin fin_cases x2; fin_cases x3, success_if_fail { fin_cases * }, success_if_fail { fin_cases y }, all_goals { refl }, end open finset example (x : ℕ) (h : x ∈ Ico 2 5) : x = 2 ∨ x = 3 ∨ x = 4 := begin fin_cases h, all_goals { simp } end open nat example (x : ℕ) (h : x ∈ [2,3,5,7]) : x = 2 ∨ x = 3 ∨ x = 5 ∨ x = 7 := begin fin_cases h, all_goals { simp } end example (x : ℕ) (h : x ∈ [2,3,5,7]) : true := begin success_if_fail { fin_cases h with [3,3,5,7] }, trivial end example (x : list ℕ) (h : x ∈ [[1],[2]]) : x.length = 1 := begin fin_cases h with [[1],[1+1]], simp, guard_target (list.length [1 + 1] = 1), simp end -- testing that `with` arguments are elaborated with respect to the expected type: example (x : ℤ) (h : x ∈ ([2,3] : list ℤ)) : x = 2 ∨ x = 3 := begin fin_cases h with [2,3], all_goals { simp } end instance (n : ℕ) : decidable (nat.prime n) := decidable_prime_1 n example (x : ℕ) (h : x ∈ (range 10).filter nat.prime) : x = 2 ∨ x = 3 ∨ x = 5 ∨ x = 7 := begin fin_cases h; exact dec_trivial end open equiv.perm example (x : (Σ (a : fin 4), fin 4)) (h : x ∈ fin_pairs_lt 4) : x.1.val < 4 := begin fin_cases h; simp, any_goals { exact dec_trivial }, end example (x : fin 3) : x.val < 5 := begin fin_cases x; exact dec_trivial end example (f : ℕ → Prop) (p : fin 3) (h0 : f 0) (h1 : f 1) (h2 : f 2) : f p.val := begin fin_cases *, all_goals { assumption } end example (n : ℕ) (h : n % 3 ∈ [0,1]) : true := begin fin_cases h, guard_hyp h : n % 3 = 0, trivial, guard_hyp h : n % 3 = 1, trivial, end /- In some circumstances involving `let`, the temporary hypothesis that `fin_cases` creates does not get deleted. We test that this is correctly named and that the name can be changed. -/ example (f : ℕ → fin 3) : true := begin let a := f 3, fin_cases a, guard_hyp a := f 3, guard_hyp this : a = (0 : fin 3), trivial, trivial, let b := f 2, fin_cases b using what, guard_hyp what : b = (0 : fin 3), all_goals {trivial} end /- The behavior above can be worked around with `fin_cases with`. -/ example (f : ℕ → fin 3) : true := begin let a := f 3, fin_cases a with [0, 1, 2], guard_hyp a := f 3, guard_hyp this : a = 0, trivial, guard_hyp this : a = 1, trivial, guard_hyp this : a = 2, let b := f 2, fin_cases b with [0, 1, 2] using what, guard_hyp what : b = 0, all_goals {trivial} end
[STATEMENT] lemma reduce_below_not0: assumes A: "A \<in> carrier_mat m n" and a: "a<m" and j: "0<n" and Aaj: "A $$ (a,0) \<noteq> 0" and "distinct xs" and "\<forall>x \<in> set xs. x < m \<and> a < x" and "D\<noteq> 0" shows "reduce_below a xs D A $$ (a, 0) \<noteq> 0" (is "?R $$ (a,0) \<noteq> _") [PROOF STATE] proof (prove) goal (1 subgoal): 1. reduce_below a xs D A $$ (a, 0) \<noteq> 0 [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: A \<in> carrier_mat m n a < m 0 < n A $$ (a, 0) \<noteq> 0 distinct xs \<forall>x\<in>set xs. x < m \<and> a < x D \<noteq> 0 goal (1 subgoal): 1. reduce_below a xs D A $$ (a, 0) \<noteq> 0 [PROOF STEP] proof (induct a xs D A arbitrary: A rule: reduce_below.induct) [PROOF STATE] proof (state) goal (2 subgoals): 1. \<And>a D A Aa. \<lbrakk>Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct []; \<forall>x\<in>set []. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a [] D Aa $$ (a, 0) \<noteq> 0 2. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] case (1 a D A) [PROOF STATE] proof (state) this: A \<in> carrier_mat m n a < m 0 < n A $$ (a, 0) \<noteq> 0 distinct [] \<forall>x\<in>set []. x < m \<and> a < x D \<noteq> 0 goal (2 subgoals): 1. \<And>a D A Aa. \<lbrakk>Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct []; \<forall>x\<in>set []. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a [] D Aa $$ (a, 0) \<noteq> 0 2. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] then [PROOF STATE] proof (chain) picking this: A \<in> carrier_mat m n a < m 0 < n A $$ (a, 0) \<noteq> 0 distinct [] \<forall>x\<in>set []. x < m \<and> a < x D \<noteq> 0 [PROOF STEP] show ?case [PROOF STATE] proof (prove) using this: A \<in> carrier_mat m n a < m 0 < n A $$ (a, 0) \<noteq> 0 distinct [] \<forall>x\<in>set []. x < m \<and> a < x D \<noteq> 0 goal (1 subgoal): 1. reduce_below a [] D A $$ (a, 0) \<noteq> 0 [PROOF STEP] by auto [PROOF STATE] proof (state) this: reduce_below a [] D A $$ (a, 0) \<noteq> 0 goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] case (2 a x xs D A) [PROOF STATE] proof (state) this: \<lbrakk>?A \<in> carrier_mat m n; a < m; 0 < n; ?A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D ?A $$ (a, 0) \<noteq> 0 A \<in> carrier_mat m n a < m 0 < n A $$ (a, 0) \<noteq> 0 distinct (x # xs) \<forall>x\<in>set (x # xs). x < m \<and> a < x D \<noteq> 0 goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] note A = "2.prems"(1) [PROOF STATE] proof (state) this: A \<in> carrier_mat m n goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] note a = "2.prems"(2) [PROOF STATE] proof (state) this: a < m goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] note j = "2.prems"(3) [PROOF STATE] proof (state) this: 0 < n goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] note Aaj = "2.prems"(4) [PROOF STATE] proof (state) this: A $$ (a, 0) \<noteq> 0 goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] note d = "2.prems"(5) [PROOF STATE] proof (state) this: distinct (x # xs) goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] note D0 = "2.prems"(7) [PROOF STATE] proof (state) this: D \<noteq> 0 goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] note x_less_xxs = "2.prems"(6) [PROOF STATE] proof (state) this: \<forall>x\<in>set (x # xs). x < m \<and> a < x goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] have xm: "x < m" [PROOF STATE] proof (prove) goal (1 subgoal): 1. x < m [PROOF STEP] using "2.prems" [PROOF STATE] proof (prove) using this: A \<in> carrier_mat m n a < m 0 < n A $$ (a, 0) \<noteq> 0 distinct (x # xs) \<forall>x\<in>set (x # xs). x < m \<and> a < x D \<noteq> 0 goal (1 subgoal): 1. x < m [PROOF STEP] by auto [PROOF STATE] proof (state) this: x < m goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] have D1: "D \<cdot>\<^sub>m 1\<^sub>m n \<in> carrier_mat n n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. D \<cdot>\<^sub>m 1\<^sub>m n \<in> carrier_mat n n [PROOF STEP] by simp [PROOF STATE] proof (state) this: D \<cdot>\<^sub>m 1\<^sub>m n \<in> carrier_mat n n goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] obtain p q u v d where pquvd: "(p,q,u,v,d) = euclid_ext2 (A$$(a,0)) (A$$(x,0))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<And>p q u v d. (p, q, u, v, d) = euclid_ext2 (A $$ (a, 0)) (A $$ (x, 0)) \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by (metis prod_cases5) [PROOF STATE] proof (state) this: (p, q, u, v, d) = euclid_ext2 (A $$ (a, 0)) (A $$ (x, 0)) goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] let ?reduce_ax = "reduce a x D A" [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] have reduce_ax: "?reduce_ax \<in> carrier_mat m n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. reduce a x D A \<in> carrier_mat m n [PROOF STEP] by (metis (no_types, lifting) A carrier_matD carrier_mat_triv reduce_preserves_dimensions) [PROOF STATE] proof (state) this: reduce a x D A \<in> carrier_mat m n goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] have h: "reduce_below a xs D (reduce a x D A) $$ (a,0) \<noteq> 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. reduce_below a xs D (reduce a x D A) $$ (a, 0) \<noteq> 0 [PROOF STEP] proof (rule "2.hyps") [PROOF STATE] proof (state) goal (7 subgoals): 1. reduce a x D A \<in> carrier_mat m n 2. a < m 3. 0 < n 4. reduce a x D A $$ (a, 0) \<noteq> 0 5. distinct xs 6. \<forall>x\<in>set xs. x < m \<and> a < x 7. D \<noteq> 0 [PROOF STEP] show "reduce a x D A $$ (a, 0) \<noteq> 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. reduce a x D A $$ (a, 0) \<noteq> 0 [PROOF STEP] by (rule reduce_not0[OF A a _ j xm Aaj D0], insert x_less_xxs, simp) [PROOF STATE] proof (state) this: reduce a x D A $$ (a, 0) \<noteq> 0 goal (6 subgoals): 1. reduce a x D A \<in> carrier_mat m n 2. a < m 3. 0 < n 4. distinct xs 5. \<forall>x\<in>set xs. x < m \<and> a < x 6. D \<noteq> 0 [PROOF STEP] qed (insert A a j Aaj d x_less_xxs xm reduce_ax D0, auto) [PROOF STATE] proof (state) this: reduce_below a xs D (reduce a x D A) $$ (a, 0) \<noteq> 0 goal (1 subgoal): 1. \<And>a x xs D A Aa. \<lbrakk>\<And>A. \<lbrakk>A \<in> carrier_mat m n; a < m; 0 < n; A $$ (a, 0) \<noteq> 0; distinct xs; \<forall>x\<in>set xs. x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a xs D A $$ (a, 0) \<noteq> 0; Aa \<in> carrier_mat m n; a < m; 0 < n; Aa $$ (a, 0) \<noteq> 0; distinct (x # xs); \<forall>x\<in>set (x # xs). x < m \<and> a < x; D \<noteq> 0\<rbrakk> \<Longrightarrow> reduce_below a (x # xs) D Aa $$ (a, 0) \<noteq> 0 [PROOF STEP] thus ?case [PROOF STATE] proof (prove) using this: reduce_below a xs D (reduce a x D A) $$ (a, 0) \<noteq> 0 goal (1 subgoal): 1. reduce_below a (x # xs) D A $$ (a, 0) \<noteq> 0 [PROOF STEP] by auto [PROOF STATE] proof (state) this: reduce_below a (x # xs) D A $$ (a, 0) \<noteq> 0 goal: No subgoals! [PROOF STEP] qed
lemma homotopic_with_canon_on_empty [simp]: "homotopic_with_canon (\<lambda>x. True) {} t f g"
The Gangadhara image to the right of the Trimurti is an ensemble of divinities assembled around the central figures of Shiva and Parvati , the former bearing the River Ganges as she descends from heaven . The carving is 4 m ( 13 ft ) wide and 5 @.@ 207 m ( 17 @.@ 08 ft ) high . The image is highly damaged , particularly the lower half of Shiva seen seated with Parvati , who is shown with four arms , two of which are broken . From the crown , a cup with a triple @-@ headed female figure ( with broken arms ) , representing the three sacred rivers Ganges , Yamuna , and Sarasvati , is depicted . Shiva is sculpted and bedecked with ornaments . The arms hold a coiling serpent whose hood is seen above his left shoulder . Another hand ( partly broken ) gives the semblance of Shiva hugging Parvati , with a head of matted hair . There is a small snake on the right hand and a tortoise close to the neck , with a bundle tied to the back . An ornamented drapery covers his lower torso , below the waist . Parvati is carved to the left of Shiva with a coiffured hair dress , fully bedecked with ornaments and jewellery , also fully draped , with her right hand touching the head of a female attendant who carries Parvati 's dress case . The gods Brahma and Indra , with their mystic regalia and mounts , are shown to the right of Shiva ; Vishnu , riding his mount Garuda , is shown to the left of Parvati . Many other details are defaced but a kneeling figure in the front is inferred to be the king who ordered the image to be carved . There are many divinities and attendant females at the back . The whole setting is under the sky and cloud scenes , with men and women , all dressed , shown showering flowers on the deities .
function [H,Ip] = imagesAlign( I, Iref, varargin ) % Fast and robust estimation of homography relating two images. % % The algorithm for image alignment is a simple but effective variant of % the inverse compositional algorithm. For a thorough overview, see: % "Lucas-kanade 20 years on A unifying framework," % S. Baker and I. Matthews. IJCV 2004. % The implementation is optimized and can easily run at 20-30 fps. % % type may take on the following values: % 'translation' - translation only % 'rigid' - translation and rotation % 'similarity' - translation, rotation and scale % 'affine' - 6 parameter affine transform % 'rotation' - pure rotation (about x, y and z) % 'projective' - full 8 parameter homography % Alternatively, type may be a vector of ids between 1 and 8, specifying % exactly the types of transforms allowed. The ids correspond, to: 1: % translate-x, 2: translate-y, 3: uniform scale, 4: shear, 5: non-uniform % scale, 6: rotate-z, 7: rotate-x, 8: rotate-y. For example, to specify % translation use type=[1,2]. If the transforms don't form a group, the % returned homography may have more degrees of freedom than expected. % % Parameters (in rough order of importance): [resample] controls image % downsampling prior to computing H. Runtime is proportional to area, so % using resample<1 can dramatically speed up alignment, and in general not % degrade performance much. [sig] controls image smoothing, sig=2 gives % good performance, setting sig too low causes loss of information and too % high will violate the linearity assumption. [epsilon] defines the % stopping criteria, use to adjust performance versus speed tradeoff. % [lambda] is a regularization term that causes small transforms to be % favored, in general any small non-zero setting of lambda works well. % [outThr] is a threshold beyond which pixels are considered outliers, be % careful not to set too low. [minArea] determines coarsest scale beyond % which the image is not downsampled (should not be set too low). [H0] can % be used to specify an initial alignment. Use [show] to display results. % % USAGE % [H,Ip] = imagesAlign( I, Iref, varargin ) % % INPUTS % I - transformed version of I % Iref - reference grayscale double image % varargin - additional params (struct or name/value pairs) % .type - ['projective'] see above for options % .resample - [1] image resampling prior to homography estimation % .sig - [2] amount of Gaussian spatial smoothing to apply % .epsilon - [1e-3] stopping criteria (min change in error) % .lambda - [1e-6] regularization term favoring small transforms % .outThr - [inf] outlier threshold % .minArea - [4096] minimum image area in coarse to fine search % .H0 - [eye(3)] optional initial homography estimate % .show - [0] optionally display results in figure show % % OUTPUTS % H - estimated homography to transform I into Iref % Ip - tranformed version of I (slow to compute) % % EXAMPLE % Iref = double(imread('cameraman.tif'))/255; % H0 = [eye(2)+randn(2)*.1 randn(2,1)*10; randn(1,2)*1e-3 1]; % I = imtransform2(Iref,H0^-1,'pad','replicate'); % o=50; P=ones(o)*1; I(150:149+o,150:149+o)=P; % prmAlign={'outThr',.1,'resample',.5,'type',1:8,'show'}; % [H,Ip]=imagesAlign(I,Iref,prmAlign{:},1); % tic, for i=1:30, H=imagesAlign(I,Iref,prmAlign{:},0); end; % t=toc; fprintf('average fps: %f\n',30/t) % % See also imTransform2 % % Piotr's Computer Vision Matlab Toolbox Version 2.61 % Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com] % Licensed under the Simplified BSD License [see external/bsd.txt] % get parameters dfs={'type','projective','resample',1,'sig',2,'epsilon',1e-3,... 'lambda',1e-6,'outThr',inf,'minArea',4096,'H0',eye(3),'show',0}; [type,resample,sig,epsilon,lambda,outThr,minArea,H0,show] = ... getPrmDflt(varargin,dfs,1); filt = filterGauss(2*ceil(sig*2.5)+1,[],sig^2); % determine type of transformation to recover if(isnumeric(type)), assert(length(type)<=8); else id=find(strcmpi(type,{'translation','rigid','similarity','affine',... 'rotation','projective'})); msgId='piotr:imagesAlign'; if(isempty(id)), error(msgId,'unknown type: %s',type); end type={1:2,[1:2 6],[1:3 6],1:6,6:8,1:8}; type=type{id}; end; keep=zeros(1,8); keep(type)=1; keep=keep>0; % compute image alignment (optionally resample first) prm={keep,filt,epsilon,H0,minArea,outThr,lambda}; if( resample==1 ), H=imagesAlign1(I,Iref,prm); else S=eye(3); S([1 5])=resample; H0=S*H0*S^-1; prm{4}=H0; I1=imResample(I,resample); Iref1=imResample(Iref,resample); H=imagesAlign1(I1,Iref1,prm); H=S^-1*H*S; end % optionally rectify I and display results (can be expensive) if(nargout==1 && show==0), return; end Ip = imtransform2(I,H,'pad','replicate'); if(show), figure(show); clf; s=@(i) subplot(2,3,i); Is=[I Iref Ip]; ri=[min(Is(:)) max(Is(:))]; D0=abs(I-Iref); D1=abs(Ip-Iref); Ds=[D0 D1]; di=[min(Ds(:)) max(Ds(:))]; s(1); im(I,ri,0); s(2); im(Iref,ri,0); s(3); im(D0,di,0); s(4); im(Ip,ri,0); s(5); im(Iref,ri,0); s(6); im(D1,di,0); s(3); title('|I-Iref|'); s(6); title('|Ip-Iref|'); end end function H = imagesAlign1( I, Iref, prm ) % apply recursively if image large [keep,filt,epsilon,H0,minArea,outThr,lambda]=deal(prm{:}); [h,w]=size(I); hc=mod(h,2); wc=mod(w,2); if( w*h<minArea ), H=H0; else I1=imResample(I(1:(h-hc),1:(w-wc)),.5); Iref1=imResample(Iref(1:(h-hc),1:(w-wc)),.5); S=eye(3); S([1 5])=2; H0=S^-1*H0*S; prm{4}=H0; H=imagesAlign1(I1,Iref1,prm); H=S*H*S^-1; end % smooth images (pad first so dimensions unchanged) O=ones(1,(length(filt)-1)/2); hs=[O 1:h h*O]; ws=[O 1:w w*O]; Iref=conv2(conv2(Iref(hs,ws),filt','valid'),filt,'valid'); I=conv2(conv2(I(hs,ws),filt','valid'),filt,'valid'); % pad images with nan so later can determine valid regions hs=[1 1 1:h h h]; ws=[1 1 1:w w w]; I=I(hs,ws); Iref=Iref(hs,ws); hs=[1:2 h+3:h+4]; I(hs,:)=nan; Iref(hs,:)=nan; ws=[1:2 w+3:w+4]; I(:,ws)=nan; Iref(:,ws)=nan; % convert weights hardcoded for 128x128 image to given image dims wts=[1 1 1.0204 .03125 1.0313 0.0204 .00055516 .00055516]; s=sqrt(numel(Iref))/128; wts=[wts(1:2) wts(3)^(1/s) wts(4)/s wts(5)^(1/s) wts(6)/s wts(7:8)/(s*s)]; % prepare subspace around Iref [~,Hs]=ds2H(-ones(1,8),wts); Hs=Hs(:,:,keep); K=size(Hs,3); [h,w]=size(Iref); Ts=zeros(h,w,K); k=0; if(keep(1)), k=k+1; Ts(:,1:end-1,k)=Iref(:,2:end); end if(keep(2)), k=k+1; Ts(1:end-1,:,k)=Iref(2:end,:); end pTransf={'method','bilinear','pad','none','useCache'}; for i=k+1:K, Ts(:,:,i)=imtransform2(Iref,Hs(:,:,i),pTransf{:},1); end Ds=Ts-Iref(:,:,ones(1,K)); Mref = ~any(isnan(Ds),3); if(0), figure(10); montage2(Ds); end Ds = reshape(Ds,[],size(Ds,3)); % iteratively project Ip onto subspace, storing transformation lambda=lambda*w*h*eye(K); ds=zeros(1,8); err=inf; for i=1:100 s=svd(H); if(s(3)<=1e-4*s(1)), H=eye(3); return; end Ip=imtransform2(I,H,pTransf{:},0); dI=Ip-Iref; dI0=abs(dI); M=Mref & ~isnan(Ip); M0=M; if(outThr<inf), M=M & dI0<outThr; end M1=find(M); D=Ds(M1,:); ds1=(D'*D + lambda)^(-1)*(D'*dI(M1)); if(any(isnan(ds1))), ds1=zeros(K,1); end ds(keep)=ds1; H1=ds2H(ds,wts); H=H*H1; H=H/H(9); err0=err; err=dI0; err(~M0)=0; err=mean2(err); del=err0-err; if(0), fprintf('i=%03i err=%e del=%e\n',i,err,del); end if( del<epsilon ), break; end end end function [H,Hs] = ds2H( ds, wts ) % compute homography from offsets ds Hs=eye(3); Hs=Hs(:,:,ones(1,8)); Hs(2,3,1)=wts(1)*ds(1); % 1 x translation Hs(1,3,2)=wts(2)*ds(2); % 2 y translation Hs(1:2,1:2,3)=eye(2)*wts(3)^ds(3); % 3 scale Hs(2,1,4)=wts(4)*ds(4); % 4 shear Hs(1,1,5)=wts(5)^ds(5); % 5 scale non-uniform ct=cos(wts(6)*ds(6)); st=sin(wts(6)*ds(6)); Hs(1:2,1:2,6)=[ct -st; st ct]; % 6 rotation about z ct=cos(wts(7)*ds(7)); st=sin(wts(7)*ds(7)); Hs([1 3],[1 3],7)=[ct -st; st ct]; % 7 rotation about x ct=cos(wts(8)*ds(8)); st=sin(wts(8)*ds(8)); Hs(2:3,2:3,8)=[ct -st; st ct]; % 8 rotation about y H=eye(3); for i=1:8, H=Hs(:,:,i)*H; end end
[GOAL] a b c d : ℤ hb : b ≠ 0 hbc : b ∣ c h : b * a = c * d ⊢ a = c / b * d [PROOFSTEP] cases' hbc with k hk [GOAL] case intro a b c d : ℤ hb : b ≠ 0 h : b * a = c * d k : ℤ hk : c = b * k ⊢ a = c / b * d [PROOFSTEP] subst hk [GOAL] case intro a b d : ℤ hb : b ≠ 0 k : ℤ h : b * a = b * k * d ⊢ a = b * k / b * d [PROOFSTEP] rw [Int.mul_ediv_cancel_left _ hb] [GOAL] case intro a b d : ℤ hb : b ≠ 0 k : ℤ h : b * a = b * k * d ⊢ a = k * d [PROOFSTEP] rw [mul_assoc] at h [GOAL] case intro a b d : ℤ hb : b ≠ 0 k : ℤ h : b * a = b * (k * d) ⊢ a = k * d [PROOFSTEP] apply mul_left_cancel₀ hb h [GOAL] a b : ℤ w : a ∣ b h : natAbs b < natAbs a ⊢ b = 0 [PROOFSTEP] rw [← natAbs_dvd, ← dvd_natAbs, coe_nat_dvd] at w [GOAL] a b : ℤ w : natAbs a ∣ natAbs b h : natAbs b < natAbs a ⊢ b = 0 [PROOFSTEP] rw [← natAbs_eq_zero] [GOAL] a b : ℤ w : natAbs a ∣ natAbs b h : natAbs b < natAbs a ⊢ natAbs b = 0 [PROOFSTEP] exact eq_zero_of_dvd_of_lt w h [GOAL] m n : ℕ h : Nat.succ n ≤ m ⊢ ofNat m + -[n+1] = ofNat (m - Nat.succ n) [PROOFSTEP] rw [negSucc_eq, ofNat_eq_cast, ofNat_eq_cast, ← Nat.cast_one, ← Nat.cast_add, ← sub_eq_add_neg, ← Nat.cast_sub h]
module def_upper_lower_test use def_upper_lower use fruit implicit none contains subroutine test_lower call assert_equals("z", lower(26:26), "26 th is z") call assert_equals("c", lower( 3: 3), "3rd th is c") end !!! subroutine test_lower subroutine test_upper call assert_equals("Z", upper(26:26), "26 th is Z") call assert_equals("C", upper( 3: 3), "3rd th is C") end end module def_upper_lower_test
using Images, Luxor, BenchmarkTools function calc(dims) img = fill(RGB(0,0,0), (dims, dims)) a = 2.24; b = 0.43; c = -0.65; d = -2.43 x = y = z = .0 for _ in 1:dims^2 x, y, z = sin(a * y) - z * cos(b * x), z * sin(c * x) - cos(d * y), sin(x) xx = trunc(Int, rescale(x, -2., 2., 0, dims)) yy = trunc(Int, rescale(y, -2., 2., 0, dims)) zz = rescale(z, -1, 1, .3, .8) img[yy,xx] = RGB(.7xx / dims, .3yy / dims + .2, zz) end return img end @time save("strange.png",calc(1000))
%% Copyright (C) 2014, 2016, 2019 Colin B. Macdonald %% %% This file is part of OctSymPy. %% %% OctSymPy is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published %% by the Free Software Foundation; either version 3 of the License, %% or (at your option) any later version. %% %% This 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. %% %% You should have received a copy of the GNU General Public %% License along with this software; see the file COPYING. %% If not, see <http://www.gnu.org/licenses/>. %% -*- texinfo -*- %% @documentencoding UTF-8 %% @defmethod @@sym flipud (@var{A}) %% Flip a symbolic matrix vertically. %% %% Example: %% @example %% @group %% A = sym([1 2 pi; 4 5 6]); %% flipud (A) %% @result{} (sym 2×3 matrix) %% ⎡4 5 6⎤ %% ⎢ ⎥ %% ⎣1 2 π⎦ %% @end group %% @end example %% %% @seealso{@@sym/fliplr, @@sym/reshape} %% @end defmethod function B = flipud (A) cmd = { 'A, = _ins' 'if A is None or not A.is_Matrix:' ' A = sp.Matrix([A])' 'return A[::-1, :]' }; B = pycall_sympy__ (cmd, sym(A)); end %!test %! % simple %! syms x %! A = [x 2; sym(pi) x]; %! B = [sym(pi) x; x 2]; %! assert (isequal (flipud(A), B)) %!test %! % simple, odd # rows %! syms x %! A = [x 2; sym(pi) x; [1 2]]; %! B = [[1 2]; sym(pi) x; x 2]; %! assert (isequal (flipud(A), B)) %!test %! % scalar %! syms x %! assert (isequal (flipud(x), x))
------------------------------------------------------------------------------ -- Non-terminating GCD ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Program.GCD.GCD-NT where open import Data.Nat open import Relation.Nullary ------------------------------------------------------------------------------ {-# TERMINATING #-} gcd : ℕ → ℕ → ℕ gcd 0 0 = 0 gcd (suc m) 0 = suc m gcd 0 (suc n) = suc n gcd (suc m) (suc n) with suc m ≤? suc n gcd (suc m) (suc n) | yes p = gcd (suc m) (suc n ∸ suc m) gcd (suc m) (suc n) | no ¬p = gcd (suc m ∸ suc n) (suc n)
No warning letters were posted this week due to the partial government shutdown. However, there was one warning letter that posted elsewhere that focused on aseptic processing and data integrity. Poor aseptic behavior including failure to log interventions in the batch records; use of gloves from non-integral packaging where foreign particles were evident; inadequate cleanroom design. Personnel monitoring is inadequate because staff sanitized their hands prior to sampling, and failure to trigger an investigation when staff in the ISO 5 cabinet has one CFU/glove on a repeated basis. Cleaning program is inadequate because steps were skipped, not performed properly and some equipment was not sanitized. The firm did not perform impurity testing during stability on two products since 2016. At the time of the inspection, the firm did not have a validated method.
print("Hello World", quote = FALSE)
[GOAL] M : Type u m₁ m₂ : Monoid M h_mul : Mul.mul = Mul.mul ⊢ m₁ = m₂ [PROOFSTEP] have : m₁.toMulOneClass = m₂.toMulOneClass := MulOneClass.ext h_mul [GOAL] M : Type u m₁ m₂ : Monoid M h_mul : Mul.mul = Mul.mul this : toMulOneClass = toMulOneClass ⊢ m₁ = m₂ [PROOFSTEP] have h₁ : m₁.one = m₂.one := congr_arg (·.one) (this) [GOAL] M : Type u m₁ m₂ : Monoid M h_mul : Mul.mul = Mul.mul this : toMulOneClass = toMulOneClass h₁ : One.one = One.one ⊢ m₁ = m₂ [PROOFSTEP] let f : @MonoidHom M M m₁.toMulOneClass m₂.toMulOneClass := @MonoidHom.mk _ _ (_) _ (@OneHom.mk _ _ (_) _ id h₁) (fun x y => congr_fun (congr_fun h_mul x) y) [GOAL] M : Type u m₁ m₂ : Monoid M h_mul : Mul.mul = Mul.mul this : toMulOneClass = toMulOneClass h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } ⊢ m₁ = m₂ [PROOFSTEP] have : m₁.npow = m₂.npow := by ext n x exact @MonoidHom.map_pow M M m₁ m₂ f x n [GOAL] M : Type u m₁ m₂ : Monoid M h_mul : Mul.mul = Mul.mul this : toMulOneClass = toMulOneClass h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } ⊢ npow = npow [PROOFSTEP] ext n x [GOAL] case h.h M : Type u m₁ m₂ : Monoid M h_mul : Mul.mul = Mul.mul this : toMulOneClass = toMulOneClass h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } n : ℕ x : M ⊢ npow n x = npow n x [PROOFSTEP] exact @MonoidHom.map_pow M M m₁ m₂ f x n [GOAL] M : Type u m₁ m₂ : Monoid M h_mul : Mul.mul = Mul.mul this✝ : toMulOneClass = toMulOneClass h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this : npow = npow ⊢ m₁ = m₂ [PROOFSTEP] rcases m₁ with @⟨@⟨⟨_⟩⟩, ⟨_⟩⟩ [GOAL] case mk.mk.mk.mk M : Type u m₂ : Monoid M npow✝ : ℕ → M → M mul✝ : M → M → M mul_assoc✝ : ∀ (a b c : M), a * b * c = a * (b * c) npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x one✝ : M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a h_mul : Mul.mul = Mul.mul this✝ : toMulOneClass = toMulOneClass h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this : npow = npow ⊢ mk one_mul✝ mul_one✝ npow✝ = m₂ [PROOFSTEP] rcases m₂ with @⟨@⟨⟨_⟩⟩, ⟨_⟩⟩ [GOAL] case mk.mk.mk.mk.mk.mk.mk.mk M : Type u npow✝¹ : ℕ → M → M mul✝¹ : M → M → M mul_assoc✝¹ : ∀ (a b c : M), a * b * c = a * (b * c) npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x one✝¹ : M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow✝ : ℕ → M → M mul✝ : M → M → M mul_assoc✝ : ∀ (a b c : M), a * b * c = a * (b * c) npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x one✝ : M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a h_mul : Mul.mul = Mul.mul this✝ : toMulOneClass = toMulOneClass h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this : npow = npow ⊢ mk one_mul✝¹ mul_one✝¹ npow✝¹ = mk one_mul✝ mul_one✝ npow✝ [PROOFSTEP] congr [GOAL] M : Type u ⊢ Function.Injective (@toMonoid M) [PROOFSTEP] rintro ⟨⟩ ⟨⟩ h [GOAL] case mk.mk M : Type u toMonoid✝¹ : Monoid M mul_comm✝¹ : ∀ (a b : M), a * b = b * a toMonoid✝ : Monoid M mul_comm✝ : ∀ (a b : M), a * b = b * a h : toMonoid = toMonoid ⊢ mk mul_comm✝¹ = mk mul_comm✝ [PROOFSTEP] congr [GOAL] M : Type u ⊢ Function.Injective (@toMonoid M) [PROOFSTEP] rintro @⟨@⟨⟩⟩ @⟨@⟨⟩⟩ h [GOAL] case mk.mk.mk.mk M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x h : toMonoid = toMonoid ⊢ mk one_mul✝¹ mul_one✝¹ npow✝¹ = mk one_mul✝ mul_one✝ npow✝ [PROOFSTEP] congr [GOAL] case mk.mk.mk.mk.e_toLeftCancelSemigroup.e_toSemigroup M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x h : toMonoid = toMonoid ⊢ toSemigroup✝¹ = toSemigroup✝ [PROOFSTEP] injection h [GOAL] case mk.mk.mk.mk.e_toOne M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x h : toMonoid = toMonoid ⊢ toOne✝¹ = toOne✝ [PROOFSTEP] injection h [GOAL] case mk.mk.mk.mk.e_npow M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x h : toMonoid = toMonoid ⊢ npow✝¹ = npow✝ [PROOFSTEP] injection h [GOAL] M : Type u ⊢ Function.Injective (@toMonoid M) [PROOFSTEP] rintro @⟨@⟨⟩⟩ @⟨@⟨⟩⟩ h [GOAL] case mk.mk.mk.mk M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_right_cancel✝¹ : ∀ (a b c : M), a * b = c * b → a = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_right_cancel✝ : ∀ (a b c : M), a * b = c * b → a = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x h : toMonoid = toMonoid ⊢ mk one_mul✝¹ mul_one✝¹ npow✝¹ = mk one_mul✝ mul_one✝ npow✝ [PROOFSTEP] congr [GOAL] case mk.mk.mk.mk.e_toRightCancelSemigroup.e_toSemigroup M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_right_cancel✝¹ : ∀ (a b c : M), a * b = c * b → a = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_right_cancel✝ : ∀ (a b c : M), a * b = c * b → a = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x h : toMonoid = toMonoid ⊢ toSemigroup✝¹ = toSemigroup✝ [PROOFSTEP] injection h [GOAL] case mk.mk.mk.mk.e_toOne M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_right_cancel✝¹ : ∀ (a b c : M), a * b = c * b → a = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_right_cancel✝ : ∀ (a b c : M), a * b = c * b → a = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x h : toMonoid = toMonoid ⊢ toOne✝¹ = toOne✝ [PROOFSTEP] injection h [GOAL] case mk.mk.mk.mk.e_npow M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_right_cancel✝¹ : ∀ (a b c : M), a * b = c * b → a = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_right_cancel✝ : ∀ (a b c : M), a * b = c * b → a = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x h : toMonoid = toMonoid ⊢ npow✝¹ = npow✝ [PROOFSTEP] injection h [GOAL] M : Type u ⊢ Function.Injective (@toLeftCancelMonoid M) [PROOFSTEP] rintro ⟨⟩ ⟨⟩ h [GOAL] case mk.mk M : Type u toLeftCancelMonoid✝¹ : LeftCancelMonoid M mul_right_cancel✝¹ : ∀ (a b c : M), a * b = c * b → a = c toLeftCancelMonoid✝ : LeftCancelMonoid M mul_right_cancel✝ : ∀ (a b c : M), a * b = c * b → a = c h : toLeftCancelMonoid = toLeftCancelMonoid ⊢ mk mul_right_cancel✝¹ = mk mul_right_cancel✝ [PROOFSTEP] congr [GOAL] M : Type u ⊢ Function.Injective (@toCommMonoid M) [PROOFSTEP] rintro @⟨@⟨@⟨⟩⟩⟩ @⟨@⟨@⟨⟩⟩⟩ h [GOAL] case mk.mk.mk.mk.mk.mk M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h : toCommMonoid = toCommMonoid ⊢ mk mul_comm✝¹ = mk mul_comm✝ [PROOFSTEP] congr [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_toLeftCancelSemigroup.e_toSemigroup M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h : toCommMonoid = toCommMonoid ⊢ toSemigroup✝¹ = toSemigroup✝ [PROOFSTEP] { injection h with h' injection h' } [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_toLeftCancelSemigroup.e_toSemigroup M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h : toCommMonoid = toCommMonoid ⊢ toSemigroup✝¹ = toSemigroup✝ [PROOFSTEP] injection h with h' [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_toLeftCancelSemigroup.e_toSemigroup M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h' : Monoid.mk (_ : ∀ (a : M), 1 * a = a) (_ : ∀ (a : M), a * 1 = a) LeftCancelMonoid.npow = Monoid.mk (_ : ∀ (a : M), 1 * a = a) (_ : ∀ (a : M), a * 1 = a) LeftCancelMonoid.npow ⊢ toSemigroup✝¹ = toSemigroup✝ [PROOFSTEP] injection h' [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_toOne M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h : toCommMonoid = toCommMonoid ⊢ toOne✝¹ = toOne✝ [PROOFSTEP] { injection h with h' injection h' } [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_toOne M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h : toCommMonoid = toCommMonoid ⊢ toOne✝¹ = toOne✝ [PROOFSTEP] injection h with h' [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_toOne M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h' : Monoid.mk (_ : ∀ (a : M), 1 * a = a) (_ : ∀ (a : M), a * 1 = a) LeftCancelMonoid.npow = Monoid.mk (_ : ∀ (a : M), 1 * a = a) (_ : ∀ (a : M), a * 1 = a) LeftCancelMonoid.npow ⊢ toOne✝¹ = toOne✝ [PROOFSTEP] injection h' [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_npow M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h : toCommMonoid = toCommMonoid ⊢ npow✝¹ = npow✝ [PROOFSTEP] { injection h with h' injection h' } [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_npow M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h : toCommMonoid = toCommMonoid ⊢ npow✝¹ = npow✝ [PROOFSTEP] injection h with h' [GOAL] case mk.mk.mk.mk.mk.mk.e_toLeftCancelMonoid.e_npow M : Type u toOne✝¹ : One M npow✝¹ : ℕ → M → M npow_zero✝¹ : ∀ (x : M), npow✝¹ 0 x = 1 toSemigroup✝¹ : Semigroup M mul_left_cancel✝¹ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝¹ : ∀ (a : M), 1 * a = a mul_one✝¹ : ∀ (a : M), a * 1 = a npow_succ✝¹ : ∀ (n : ℕ) (x : M), npow✝¹ (n + 1) x = x * npow✝¹ n x mul_comm✝¹ : ∀ (a b : M), a * b = b * a toOne✝ : One M npow✝ : ℕ → M → M npow_zero✝ : ∀ (x : M), npow✝ 0 x = 1 toSemigroup✝ : Semigroup M mul_left_cancel✝ : ∀ (a b c : M), a * b = a * c → b = c one_mul✝ : ∀ (a : M), 1 * a = a mul_one✝ : ∀ (a : M), a * 1 = a npow_succ✝ : ∀ (n : ℕ) (x : M), npow✝ (n + 1) x = x * npow✝ n x mul_comm✝ : ∀ (a b : M), a * b = b * a h' : Monoid.mk (_ : ∀ (a : M), 1 * a = a) (_ : ∀ (a : M), a * 1 = a) LeftCancelMonoid.npow = Monoid.mk (_ : ∀ (a : M), 1 * a = a) (_ : ∀ (a : M), a * 1 = a) LeftCancelMonoid.npow ⊢ npow✝¹ = npow✝ [PROOFSTEP] injection h' [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv ⊢ m₁ = m₂ [PROOFSTEP] have h_mon := Monoid.ext h_mul [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid ⊢ m₁ = m₂ [PROOFSTEP] have h₁ : m₁.one = m₂.one := congr_arg (·.one) h_mon [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one ⊢ m₁ = m₂ [PROOFSTEP] let f : @MonoidHom M M m₁.toMulOneClass m₂.toMulOneClass := @MonoidHom.mk _ _ (_) _ (@OneHom.mk _ _ (_) _ id h₁) (fun x y => congr_fun (congr_fun h_mul x) y) [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } ⊢ m₁ = m₂ [PROOFSTEP] have : m₁.npow = m₂.npow := congr_arg (·.npow) h_mon [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this : Monoid.npow = Monoid.npow ⊢ m₁ = m₂ [PROOFSTEP] have : m₁.zpow = m₂.zpow := by ext m x exact @MonoidHom.map_zpow' M M m₁ m₂ f (congr_fun h_inv) x m [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this : Monoid.npow = Monoid.npow ⊢ zpow = zpow [PROOFSTEP] ext m x [GOAL] case h.h M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this : Monoid.npow = Monoid.npow m : ℤ x : M ⊢ zpow m x = zpow m x [PROOFSTEP] exact @MonoidHom.map_zpow' M M m₁ m₂ f (congr_fun h_inv) x m [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this✝ : Monoid.npow = Monoid.npow this : zpow = zpow ⊢ m₁ = m₂ [PROOFSTEP] have : m₁.div = m₂.div := by ext a b exact @map_div' _ _ (@MonoidHom _ _ (_) _) (id _) _ (@MonoidHom.monoidHomClass _ _ (_) _) f (congr_fun h_inv) a b [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this✝ : Monoid.npow = Monoid.npow this : zpow = zpow ⊢ Div.div = Div.div [PROOFSTEP] ext a b [GOAL] case h.h M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this✝ : Monoid.npow = Monoid.npow this : zpow = zpow a b : M ⊢ Div.div a b = Div.div a b [PROOFSTEP] exact @map_div' _ _ (@MonoidHom _ _ (_) _) (id _) _ (@MonoidHom.monoidHomClass _ _ (_) _) f (congr_fun h_inv) a b [GOAL] M : Type u_1 m₁ m₂ : DivInvMonoid M h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this✝¹ : Monoid.npow = Monoid.npow this✝ : zpow = zpow this : Div.div = Div.div ⊢ m₁ = m₂ [PROOFSTEP] rcases m₁ with @⟨_, ⟨_⟩, ⟨_⟩⟩ [GOAL] case mk.mk.mk M : Type u_1 m₂ : DivInvMonoid M toMonoid✝ : Monoid M zpow✝ : ℤ → M → M zpow_zero'✝ : ∀ (a : M), zpow✝ 0 a = 1 zpow_succ'✝ : ∀ (n : ℕ) (a : M), zpow✝ (Int.ofNat (Nat.succ n)) a = a * zpow✝ (Int.ofNat n) a inv✝ : M → M zpow_neg'✝ : ∀ (n : ℕ) (a : M), zpow✝ (Int.negSucc n) a = (zpow✝ (↑(Nat.succ n)) a)⁻¹ div✝ : M → M → M div_eq_mul_inv✝ : ∀ (a b : M), a / b = a * b⁻¹ h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this✝¹ : Monoid.npow = Monoid.npow this✝ : zpow = zpow this : Div.div = Div.div ⊢ mk zpow✝ = m₂ [PROOFSTEP] rcases m₂ with @⟨_, ⟨_⟩, ⟨_⟩⟩ [GOAL] case mk.mk.mk.mk.mk.mk M : Type u_1 toMonoid✝¹ : Monoid M zpow✝¹ : ℤ → M → M zpow_zero'✝¹ : ∀ (a : M), zpow✝¹ 0 a = 1 zpow_succ'✝¹ : ∀ (n : ℕ) (a : M), zpow✝¹ (Int.ofNat (Nat.succ n)) a = a * zpow✝¹ (Int.ofNat n) a inv✝¹ : M → M zpow_neg'✝¹ : ∀ (n : ℕ) (a : M), zpow✝¹ (Int.negSucc n) a = (zpow✝¹ (↑(Nat.succ n)) a)⁻¹ div✝¹ : M → M → M div_eq_mul_inv✝¹ : ∀ (a b : M), a / b = a * b⁻¹ toMonoid✝ : Monoid M zpow✝ : ℤ → M → M zpow_zero'✝ : ∀ (a : M), zpow✝ 0 a = 1 zpow_succ'✝ : ∀ (n : ℕ) (a : M), zpow✝ (Int.ofNat (Nat.succ n)) a = a * zpow✝ (Int.ofNat n) a inv✝ : M → M zpow_neg'✝ : ∀ (n : ℕ) (a : M), zpow✝ (Int.negSucc n) a = (zpow✝ (↑(Nat.succ n)) a)⁻¹ div✝ : M → M → M div_eq_mul_inv✝ : ∀ (a b : M), a / b = a * b⁻¹ h_mul : Mul.mul = Mul.mul h_inv : Inv.inv = Inv.inv h_mon : toMonoid = toMonoid h₁ : One.one = One.one f : M →* M := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : M), Mul.mul x y = Mul.mul x y) } this✝¹ : Monoid.npow = Monoid.npow this✝ : zpow = zpow this : Div.div = Div.div ⊢ mk zpow✝¹ = mk zpow✝ [PROOFSTEP] congr [GOAL] G : Type u_1 g₁ g₂ : Group G h_mul : Mul.mul = Mul.mul ⊢ g₁ = g₂ [PROOFSTEP] have h₁ : g₁.one = g₂.one := congr_arg (·.one) (Monoid.ext h_mul) [GOAL] G : Type u_1 g₁ g₂ : Group G h_mul : Mul.mul = Mul.mul h₁ : One.one = One.one ⊢ g₁ = g₂ [PROOFSTEP] let f : @MonoidHom G G g₁.toMulOneClass g₂.toMulOneClass := @MonoidHom.mk _ _ (_) _ (@OneHom.mk _ _ (_) _ id h₁) (fun x y => congr_fun (congr_fun h_mul x) y) [GOAL] G : Type u_1 g₁ g₂ : Group G h_mul : Mul.mul = Mul.mul h₁ : One.one = One.one f : G →* G := { toOneHom := { toFun := id, map_one' := h₁ }, map_mul' := (_ : ∀ (x y : G), Mul.mul x y = Mul.mul x y) } ⊢ g₁ = g₂ [PROOFSTEP] exact Group.toDivInvMonoid_injective (DivInvMonoid.ext h_mul (funext <| @MonoidHom.map_inv G G g₁ g₂.toDivisionMonoid f))
From iris.bi Require Export monpred. From iris.bi Require Import plainly. From iris.proofmode Require Import proofmode classes_make modality_instances. From iris.prelude Require Import options. Class MakeMonPredAt {I : biIndex} {PROP : bi} (i : I) (P : monPred I PROP) (𝓟 : PROP) := make_monPred_at : P i ⊣⊢ 𝓟. Global Arguments MakeMonPredAt {_ _} _ _%I _%I. (** Since [MakeMonPredAt] is used by [AsEmpValid] to import lemmas into the proof mode, the index [I] and BI [PROP] often contain evars. Hence, it is important to use the mode [!] also for the first two arguments. *) Global Hint Mode MakeMonPredAt ! ! - ! - : typeclass_instances. Class IsBiIndexRel {I : biIndex} (i j : I) := is_bi_index_rel : i ⊑ j. Global Hint Mode IsBiIndexRel + - - : typeclass_instances. Global Instance is_bi_index_rel_refl {I : biIndex} (i : I) : IsBiIndexRel i i | 0. Proof. by rewrite /IsBiIndexRel. Qed. Global Hint Extern 1 (IsBiIndexRel _ _) => unfold IsBiIndexRel; assumption : typeclass_instances. (** Frame [𝓡] into the goal [monPred_at P i] and determine the remainder [𝓠]. Used when framing encounters a monPred_at in the goal. *) Class FrameMonPredAt {I : biIndex} {PROP : bi} (p : bool) (i : I) (𝓡 : PROP) (P : monPred I PROP) (𝓠 : PROP) := frame_monPred_at : □?p 𝓡 ∗ 𝓠 -∗ P i. Global Arguments FrameMonPredAt {_ _} _ _ _%I _%I _%I. Global Hint Mode FrameMonPredAt + + + - ! ! - : typeclass_instances. Section modalities. Context {I : biIndex} {PROP : bi}. Lemma modality_objectively_mixin : modality_mixin (@monPred_objectively I PROP) (MIEnvFilter Objective) (MIEnvFilter Objective). Proof. split; simpl; split_and?; intros; try select (TCDiag _ _ _) (fun H => destruct H); eauto using bi.equiv_entails_1_2, objective_objectively, monPred_objectively_mono, monPred_objectively_and, monPred_objectively_sep_2 with typeclass_instances. Qed. Definition modality_objectively := Modality _ modality_objectively_mixin. End modalities. Section bi. Context {I : biIndex} {PROP : bi}. Local Notation monPredI := (monPredI I PROP). Local Notation monPred := (monPred I PROP). Local Notation MakeMonPredAt := (@MakeMonPredAt I PROP). Implicit Types P Q R : monPred. Implicit Types 𝓟 𝓠 𝓡 : PROP. Implicit Types φ : Prop. Implicit Types i j : I. Global Instance from_modal_objectively P : FromModal True modality_objectively (<obj> P) (<obj> P) P | 1. Proof. by rewrite /FromModal. Qed. Global Instance from_modal_subjectively P : FromModal True modality_id (<subj> P) (<subj> P) P | 1. Proof. by rewrite /FromModal /= -monPred_subjectively_intro. Qed. Global Instance from_modal_affinely_monPred_at φ `(sel : A) P Q 𝓠 i : FromModal φ modality_affinely sel P Q → MakeMonPredAt i Q 𝓠 → FromModal φ modality_affinely sel (P i) 𝓠 | 0. Proof. rewrite /FromModal /MakeMonPredAt /==> HPQ <- ?. by rewrite -HPQ // monPred_at_affinely. Qed. Global Instance from_modal_persistently_monPred_at φ `(sel : A) P Q 𝓠 i : FromModal φ modality_persistently sel P Q → MakeMonPredAt i Q 𝓠 → FromModal φ modality_persistently sel (P i) 𝓠 | 0. Proof. rewrite /FromModal /MakeMonPredAt /==> HPQ <- ?. by rewrite -HPQ // monPred_at_persistently. Qed. Global Instance from_modal_intuitionistically_monPred_at φ `(sel : A) P Q 𝓠 i : FromModal φ modality_intuitionistically sel P Q → MakeMonPredAt i Q 𝓠 → FromModal φ modality_intuitionistically sel (P i) 𝓠 | 0. Proof. rewrite /FromModal /MakeMonPredAt /==> HPQ <- ?. by rewrite -HPQ // monPred_at_affinely monPred_at_persistently. Qed. Global Instance from_modal_id_monPred_at φ `(sel : A) P Q 𝓠 i : FromModal φ modality_id sel P Q → MakeMonPredAt i Q 𝓠 → FromModal φ modality_id sel (P i) 𝓠. Proof. rewrite /FromModal /MakeMonPredAt=> HPQ <- ?. by rewrite -HPQ. Qed. Global Instance make_monPred_at_pure φ i : MakeMonPredAt i ⌜φ⌝ ⌜φ⌝. Proof. by rewrite /MakeMonPredAt monPred_at_pure. Qed. Global Instance make_monPred_at_emp i : MakeMonPredAt i emp emp. Proof. by rewrite /MakeMonPredAt monPred_at_emp. Qed. Global Instance make_monPred_at_sep i P 𝓟 Q 𝓠 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i Q 𝓠 → MakeMonPredAt i (P ∗ Q) (𝓟 ∗ 𝓠). Proof. by rewrite /MakeMonPredAt monPred_at_sep=><-<-. Qed. Global Instance make_monPred_at_and i P 𝓟 Q 𝓠 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i Q 𝓠 → MakeMonPredAt i (P ∧ Q) (𝓟 ∧ 𝓠). Proof. by rewrite /MakeMonPredAt monPred_at_and=><-<-. Qed. Global Instance make_monPred_at_or i P 𝓟 Q 𝓠 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i Q 𝓠 → MakeMonPredAt i (P ∨ Q) (𝓟 ∨ 𝓠). Proof. by rewrite /MakeMonPredAt monPred_at_or=><-<-. Qed. Global Instance make_monPred_at_forall {A} i (Φ : A → monPred) (Ψ : A → PROP) : (∀ a, MakeMonPredAt i (Φ a) (Ψ a)) → MakeMonPredAt i (∀ a, Φ a) (∀ a, Ψ a). Proof. rewrite /MakeMonPredAt monPred_at_forall=>H. by setoid_rewrite <- H. Qed. Global Instance make_monPred_at_exists {A} i (Φ : A → monPred) (Ψ : A → PROP) : (∀ a, MakeMonPredAt i (Φ a) (Ψ a)) → MakeMonPredAt i (∃ a, Φ a) (∃ a, Ψ a). Proof. rewrite /MakeMonPredAt monPred_at_exist=>H. by setoid_rewrite <- H. Qed. Global Instance make_monPred_at_persistently i P 𝓟 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (<pers> P) (<pers> 𝓟). Proof. by rewrite /MakeMonPredAt monPred_at_persistently=><-. Qed. Global Instance make_monPred_at_affinely i P 𝓟 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (<affine> P) (<affine> 𝓟). Proof. by rewrite /MakeMonPredAt monPred_at_affinely=><-. Qed. Global Instance make_monPred_at_intuitionistically i P 𝓟 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (□ P) (□ 𝓟). Proof. by rewrite /MakeMonPredAt monPred_at_intuitionistically=><-. Qed. Global Instance make_monPred_at_absorbingly i P 𝓟 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (<absorb> P) (<absorb> 𝓟). Proof. by rewrite /MakeMonPredAt monPred_at_absorbingly=><-. Qed. Global Instance make_monPred_at_persistently_if i P 𝓟 p : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (<pers>?p P) (<pers>?p 𝓟). Proof. destruct p; simpl; apply _. Qed. Global Instance make_monPred_at_affinely_if i P 𝓟 p : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (<affine>?p P) (<affine>?p 𝓟). Proof. destruct p; simpl; apply _. Qed. Global Instance make_monPred_at_absorbingly_if i P 𝓟 p : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (<absorb>?p P) (<absorb>?p 𝓟). Proof. destruct p; simpl; apply _. Qed. Global Instance make_monPred_at_intuitionistically_if i P 𝓟 p : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (□?p P) (□?p 𝓟). Proof. destruct p; simpl; apply _. Qed. Global Instance make_monPred_at_embed i 𝓟 : MakeMonPredAt i ⎡𝓟⎤ 𝓟. Proof. by rewrite /MakeMonPredAt monPred_at_embed. Qed. Global Instance make_monPred_at_in i j : MakeMonPredAt j (monPred_in i) ⌜i ⊑ j⌝. Proof. by rewrite /MakeMonPredAt monPred_at_in. Qed. Global Instance make_monPred_at_default i P : MakeMonPredAt i P (P i) | 100. Proof. by rewrite /MakeMonPredAt. Qed. Global Instance make_monPred_at_bupd `{!BiBUpd PROP} i P 𝓟 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (|==> P) (|==> 𝓟). Proof. by rewrite /MakeMonPredAt monPred_at_bupd=> <-. Qed. Global Instance from_assumption_make_monPred_at_l p i j P 𝓟 : MakeMonPredAt i P 𝓟 → IsBiIndexRel j i → KnownLFromAssumption p (P j) 𝓟. Proof. rewrite /MakeMonPredAt /KnownLFromAssumption /FromAssumption /IsBiIndexRel=><- ->. apply bi.intuitionistically_if_elim. Qed. Global Instance from_assumption_make_monPred_at_r p i j P 𝓟 : MakeMonPredAt i P 𝓟 → IsBiIndexRel i j → KnownRFromAssumption p 𝓟 (P j). Proof. rewrite /MakeMonPredAt /KnownRFromAssumption /FromAssumption /IsBiIndexRel=><- ->. apply bi.intuitionistically_if_elim. Qed. Global Instance from_assumption_make_monPred_objectively p P Q : FromAssumption p P Q → KnownLFromAssumption p (<obj> P) Q. Proof. by rewrite /KnownLFromAssumption /FromAssumption monPred_objectively_elim. Qed. Global Instance from_assumption_make_monPred_subjectively p P Q : FromAssumption p P Q → KnownRFromAssumption p P (<subj> Q). Proof. by rewrite /KnownRFromAssumption /FromAssumption -monPred_subjectively_intro. Qed. Global Instance as_emp_valid_monPred_at φ P (Φ : I → PROP) : AsEmpValid0 φ P → (∀ i, MakeMonPredAt i P (Φ i)) → AsEmpValid φ (∀ i, Φ i) | 100. Proof. rewrite /MakeMonPredAt /AsEmpValid0 /AsEmpValid /bi_emp_valid=> -> EQ. setoid_rewrite <-EQ. split. - move=>[H]. apply bi.forall_intro=>i. rewrite -H. by rewrite monPred_at_emp. - move=>HP. split=>i. rewrite monPred_at_emp HP bi.forall_elim //. Qed. Global Instance as_emp_valid_monPred_at_wand φ P Q (Φ Ψ : I → PROP) : AsEmpValid0 φ (P -∗ Q) → (∀ i, MakeMonPredAt i P (Φ i)) → (∀ i, MakeMonPredAt i Q (Ψ i)) → AsEmpValid φ (∀ i, Φ i -∗ Ψ i). Proof. rewrite /AsEmpValid0 /AsEmpValid /MakeMonPredAt. intros -> EQ1 EQ2. setoid_rewrite <-EQ1. setoid_rewrite <-EQ2. split. - move=>/bi.wand_entails HP. setoid_rewrite HP. by iIntros (i) "$". - move=>HP. apply bi.entails_wand. split=>i. iIntros "H". by iApply HP. Qed. Global Instance as_emp_valid_monPred_at_equiv φ P Q (Φ Ψ : I → PROP) : AsEmpValid0 φ (P ∗-∗ Q) → (∀ i, MakeMonPredAt i P (Φ i)) → (∀ i, MakeMonPredAt i Q (Ψ i)) → AsEmpValid φ (∀ i, Φ i ∗-∗ Ψ i). Proof. rewrite /AsEmpValid0 /AsEmpValid /MakeMonPredAt. intros -> EQ1 EQ2. setoid_rewrite <-EQ1. setoid_rewrite <-EQ2. split. - move=>/bi.wand_iff_equiv HP. setoid_rewrite HP. iIntros. iSplit; iIntros "$". - move=>HP. apply bi.equiv_wand_iff. split=>i. by iSplit; iIntros; iApply HP. Qed. Global Instance into_pure_monPred_at P φ i : IntoPure P φ → IntoPure (P i) φ. Proof. rewrite /IntoPure=>->. by rewrite monPred_at_pure. Qed. Global Instance from_pure_monPred_at a P φ i : FromPure a P φ → FromPure a (P i) φ. Proof. rewrite /FromPure=><-. by rewrite monPred_at_affinely_if monPred_at_pure. Qed. Global Instance into_pure_monPred_in i j : @IntoPure PROP (monPred_in i j) (i ⊑ j). Proof. by rewrite /IntoPure monPred_at_in. Qed. Global Instance from_pure_monPred_in i j : @FromPure PROP false (monPred_in i j) (i ⊑ j). Proof. by rewrite /FromPure monPred_at_in. Qed. Global Instance into_persistent_monPred_at p P Q 𝓠 i : IntoPersistent p P Q → MakeMonPredAt i Q 𝓠 → IntoPersistent p (P i) 𝓠 | 0. Proof. rewrite /IntoPersistent /MakeMonPredAt =>-[/(_ i) ?] <-. by rewrite -monPred_at_persistently -monPred_at_persistently_if. Qed. Lemma into_wand_monPred_at_unknown_unknown p q R P 𝓟 Q 𝓠 i : IntoWand p q R P Q → MakeMonPredAt i P 𝓟 → MakeMonPredAt i Q 𝓠 → IntoWand p q (R i) 𝓟 𝓠. Proof. rewrite /IntoWand /MakeMonPredAt /bi_affinely_if /bi_persistently_if. destruct p, q=> /bi.wand_elim_l' [/(_ i) H] <- <-; apply bi.wand_intro_r; revert H; by rewrite monPred_at_sep ?monPred_at_affinely ?monPred_at_persistently. Qed. Lemma into_wand_monPred_at_unknown_known p q R P 𝓟 Q i j : IsBiIndexRel i j → IntoWand p q R P Q → MakeMonPredAt j P 𝓟 → IntoWand p q (R i) 𝓟 (Q j). Proof. rewrite /IntoWand /IsBiIndexRel /MakeMonPredAt=>-> ? ?. eapply into_wand_monPred_at_unknown_unknown=>//. apply _. Qed. Lemma into_wand_monPred_at_known_unknown_le p q R P Q 𝓠 i j : IsBiIndexRel i j → IntoWand p q R P Q → MakeMonPredAt j Q 𝓠 → IntoWand p q (R i) (P j) 𝓠. Proof. rewrite /IntoWand /IsBiIndexRel /MakeMonPredAt=>-> ? ?. eapply into_wand_monPred_at_unknown_unknown=>//. apply _. Qed. Lemma into_wand_monPred_at_known_unknown_ge p q R P Q 𝓠 i j : IsBiIndexRel i j → IntoWand p q R P Q → MakeMonPredAt j Q 𝓠 → IntoWand p q (R j) (P i) 𝓠. Proof. rewrite /IntoWand /IsBiIndexRel /MakeMonPredAt=>-> ? ?. eapply into_wand_monPred_at_unknown_unknown=>//. apply _. Qed. Global Instance into_wand_wand'_monPred p q P Q 𝓟 𝓠 i : IntoWand' p q ((P -∗ Q) i) 𝓟 𝓠 → IntoWand p q ((P -∗ Q) i) 𝓟 𝓠 | 100. Proof. done. Qed. Global Instance into_wand_impl'_monPred p q P Q 𝓟 𝓠 i : IntoWand' p q ((P → Q) i) 𝓟 𝓠 → IntoWand p q ((P → Q) i) 𝓟 𝓠 | 100. Proof. done. Qed. Global Instance from_forall_monPred_at_wand P Q (Φ Ψ : I → PROP) i : (∀ j, MakeMonPredAt j P (Φ j)) → (∀ j, MakeMonPredAt j Q (Ψ j)) → FromForall ((P -∗ Q) i)%I (λ j, ⌜i ⊑ j⌝ → Φ j -∗ Ψ j)%I (to_ident_name idx). Proof. rewrite /FromForall /MakeMonPredAt monPred_at_wand=> H1 H2. do 2 f_equiv. by rewrite H1 H2. Qed. Global Instance from_forall_monPred_at_impl P Q (Φ Ψ : I → PROP) i : (∀ j, MakeMonPredAt j P (Φ j)) → (∀ j, MakeMonPredAt j Q (Ψ j)) → FromForall ((P → Q) i)%I (λ j, ⌜i ⊑ j⌝ → Φ j → Ψ j)%I (to_ident_name idx). Proof. rewrite /FromForall /MakeMonPredAt monPred_at_impl=> H1 H2. do 2 f_equiv. by rewrite H1 H2 bi.pure_impl_forall. Qed. Global Instance into_forall_monPred_at_index P i : IntoForall (P i) (λ j, ⌜i ⊑ j⌝ → P j)%I | 100. Proof. rewrite /IntoForall. setoid_rewrite bi.pure_impl_forall. do 2 apply bi.forall_intro=>?. by f_equiv. Qed. Global Instance from_and_monPred_at P Q1 𝓠1 Q2 𝓠2 i : FromAnd P Q1 Q2 → MakeMonPredAt i Q1 𝓠1 → MakeMonPredAt i Q2 𝓠2 → FromAnd (P i) 𝓠1 𝓠2. Proof. rewrite /FromAnd /MakeMonPredAt /MakeMonPredAt=> <- <- <-. by rewrite monPred_at_and. Qed. Global Instance into_and_monPred_at p P Q1 𝓠1 Q2 𝓠2 i : IntoAnd p P Q1 Q2 → MakeMonPredAt i Q1 𝓠1 → MakeMonPredAt i Q2 𝓠2 → IntoAnd p (P i) 𝓠1 𝓠2. Proof. rewrite /IntoAnd /MakeMonPredAt /bi_affinely_if /bi_persistently_if. destruct p=>-[/(_ i) H] <- <-; revert H; by rewrite ?monPred_at_affinely ?monPred_at_persistently monPred_at_and. Qed. Global Instance from_sep_monPred_at P Q1 𝓠1 Q2 𝓠2 i : FromSep P Q1 Q2 → MakeMonPredAt i Q1 𝓠1 → MakeMonPredAt i Q2 𝓠2 → FromSep (P i) 𝓠1 𝓠2. Proof. rewrite /FromSep /MakeMonPredAt=> <- <- <-. by rewrite monPred_at_sep. Qed. Global Instance into_sep_monPred_at P Q1 𝓠1 Q2 𝓠2 i : IntoSep P Q1 Q2 → MakeMonPredAt i Q1 𝓠1 → MakeMonPredAt i Q2 𝓠2 → IntoSep (P i) 𝓠1 𝓠2. Proof. rewrite /IntoSep /MakeMonPredAt=> -> <- <-. by rewrite monPred_at_sep. Qed. Global Instance from_or_monPred_at P Q1 𝓠1 Q2 𝓠2 i : FromOr P Q1 Q2 → MakeMonPredAt i Q1 𝓠1 → MakeMonPredAt i Q2 𝓠2 → FromOr (P i) 𝓠1 𝓠2. Proof. rewrite /FromOr /MakeMonPredAt=> <- <- <-. by rewrite monPred_at_or. Qed. Global Instance into_or_monPred_at P Q1 𝓠1 Q2 𝓠2 i : IntoOr P Q1 Q2 → MakeMonPredAt i Q1 𝓠1 → MakeMonPredAt i Q2 𝓠2 → IntoOr (P i) 𝓠1 𝓠2. Proof. rewrite /IntoOr /MakeMonPredAt=> -> <- <-. by rewrite monPred_at_or. Qed. Global Instance from_exist_monPred_at {A} P (Φ : A → monPred) (Ψ : A → PROP) i : FromExist P Φ → (∀ a, MakeMonPredAt i (Φ a) (Ψ a)) → FromExist (P i) Ψ. Proof. rewrite /FromExist /MakeMonPredAt=><- H. setoid_rewrite <- H. by rewrite monPred_at_exist. Qed. Global Instance into_exist_monPred_at {A} P (Φ : A → monPred) name (Ψ : A → PROP) i : IntoExist P Φ name → (∀ a, MakeMonPredAt i (Φ a) (Ψ a)) → IntoExist (P i) Ψ name. Proof. rewrite /IntoExist /MakeMonPredAt=>-> H. setoid_rewrite <- H. by rewrite monPred_at_exist. Qed. Global Instance from_forall_monPred_at_objectively P (Φ : I → PROP) i : (∀ i, MakeMonPredAt i P (Φ i)) → FromForall ((<obj> P) i)%I Φ (to_ident_name idx). Proof. rewrite /FromForall /MakeMonPredAt monPred_at_objectively=>H. by setoid_rewrite <- H. Qed. Global Instance into_forall_monPred_at_objectively P (Φ : I → PROP) i : (∀ i, MakeMonPredAt i P (Φ i)) → IntoForall ((<obj> P) i) Φ. Proof. rewrite /IntoForall /MakeMonPredAt monPred_at_objectively=>H. by setoid_rewrite <- H. Qed. Global Instance from_exist_monPred_at_ex P (Φ : I → PROP) i : (∀ i, MakeMonPredAt i P (Φ i)) → FromExist ((<subj> P) i) Φ. Proof. rewrite /FromExist /MakeMonPredAt monPred_at_subjectively=>H. by setoid_rewrite <- H. Qed. (* TODO: this implementation uses [idx] as the automatic name for the index. In theory a monPred could define an appropriate metavariable for indices with an [ident_name] argument to [MakeMonPredAt], but this is not implemented. *) Global Instance into_exist_monPred_at_ex P (Φ : I → PROP) i : (∀ i, MakeMonPredAt i P (Φ i)) → IntoExist ((<subj> P) i) Φ (to_ident_name idx). Proof. rewrite /IntoExist /MakeMonPredAt monPred_at_subjectively=>H. by setoid_rewrite <- H. Qed. Global Instance from_forall_monPred_at {A} P (Φ : A → monPred) name (Ψ : A → PROP) i : FromForall P Φ name → (∀ a, MakeMonPredAt i (Φ a) (Ψ a)) → FromForall (P i) Ψ name. Proof. rewrite /FromForall /MakeMonPredAt=><- H. setoid_rewrite <- H. by rewrite monPred_at_forall. Qed. Global Instance into_forall_monPred_at {A} P (Φ : A → monPred) (Ψ : A → PROP) i : IntoForall P Φ → (∀ a, MakeMonPredAt i (Φ a) (Ψ a)) → IntoForall (P i) Ψ. Proof. rewrite /IntoForall /MakeMonPredAt=>-> H. setoid_rewrite <- H. by rewrite monPred_at_forall. Qed. (* Framing. *) Global Instance frame_monPred_at_enter p i 𝓡 P 𝓠 : FrameMonPredAt p i 𝓡 P 𝓠 → Frame p 𝓡 (P i) 𝓠 | 2. Proof. intros. done. Qed. Global Instance frame_monPred_at_here p P i j : IsBiIndexRel i j → FrameMonPredAt p j (P i) P emp | 0. Proof. rewrite /FrameMonPredAt /IsBiIndexRel right_id bi.intuitionistically_if_elim=> -> //. Qed. Global Instance frame_monPred_at_embed p 𝓡 𝓠 𝓟 i : Frame p 𝓡 𝓟 𝓠 → FrameMonPredAt p i 𝓡 (embed (B:=monPredI) 𝓟) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_embed. Qed. Global Instance frame_monPred_at_sep p P Q 𝓡 𝓠 i : Frame p 𝓡 (P i ∗ Q i) 𝓠 → FrameMonPredAt p i 𝓡 (P ∗ Q) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_sep. Qed. Global Instance frame_monPred_at_and p P Q 𝓡 𝓠 i : Frame p 𝓡 (P i ∧ Q i) 𝓠 → FrameMonPredAt p i 𝓡 (P ∧ Q) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_and. Qed. Global Instance frame_monPred_at_or p P Q 𝓡 𝓠 i : Frame p 𝓡 (P i ∨ Q i) 𝓠 → FrameMonPredAt p i 𝓡 (P ∨ Q) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_or. Qed. Global Instance frame_monPred_at_wand p P R Q1 Q2 i j : IsBiIndexRel i j → Frame p R Q1 Q2 → FrameMonPredAt p j (R i) (P -∗ Q1) ((P -∗ Q2) i). Proof. rewrite /Frame /FrameMonPredAt=>-> Hframe. rewrite -monPred_at_intuitionistically_if -monPred_at_sep. apply monPred_in_entails. change ((□?p R ∗ (P -∗ Q2)) -∗ P -∗ Q1). apply bi.wand_intro_r. rewrite -assoc bi.wand_elim_l. done. Qed. Global Instance frame_monPred_at_impl P R Q1 Q2 i j : IsBiIndexRel i j → Frame true R Q1 Q2 → FrameMonPredAt true j (R i) (P → Q1) ((P → Q2) i). Proof. rewrite /Frame /FrameMonPredAt=>-> Hframe. rewrite -monPred_at_intuitionistically_if -monPred_at_sep. apply monPred_in_entails. change ((□ R ∗ (P → Q2)) -∗ P → Q1). rewrite -bi.persistently_and_intuitionistically_sep_l. apply bi.impl_intro_r. rewrite -assoc bi.impl_elim_l bi.persistently_and_intuitionistically_sep_l. done. Qed. Global Instance frame_monPred_at_forall {X : Type} p (Ψ : X → monPred) 𝓡 𝓠 i : Frame p 𝓡 (∀ x, Ψ x i) 𝓠 → FrameMonPredAt p i 𝓡 (∀ x, Ψ x) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_forall. Qed. Global Instance frame_monPred_at_exist {X : Type} p (Ψ : X → monPred) 𝓡 𝓠 i : Frame p 𝓡 (∃ x, Ψ x i) 𝓠 → FrameMonPredAt p i 𝓡 (∃ x, Ψ x) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_exist. Qed. Global Instance frame_monPred_at_absorbingly p P 𝓡 𝓠 i : Frame p 𝓡 (<absorb> P i) 𝓠 → FrameMonPredAt p i 𝓡 (<absorb> P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_absorbingly. Qed. Global Instance frame_monPred_at_affinely p P 𝓡 𝓠 i : Frame p 𝓡 (<affine> P i) 𝓠 → FrameMonPredAt p i 𝓡 (<affine> P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_affinely. Qed. Global Instance frame_monPred_at_persistently p P 𝓡 𝓠 i : Frame p 𝓡 (<pers> P i) 𝓠 → FrameMonPredAt p i 𝓡 (<pers> P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_persistently. Qed. Global Instance frame_monPred_at_intuitionistically p P 𝓡 𝓠 i : Frame p 𝓡 (□ P i) 𝓠 → FrameMonPredAt p i 𝓡 (□ P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_intuitionistically. Qed. Global Instance frame_monPred_at_objectively p P 𝓡 𝓠 i : Frame p 𝓡 (∀ i, P i) 𝓠 → FrameMonPredAt p i 𝓡 (<obj> P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_objectively. Qed. Global Instance frame_monPred_at_subjectively p P 𝓡 𝓠 i : Frame p 𝓡 (∃ i, P i) 𝓠 → FrameMonPredAt p i 𝓡 (<subj> P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_subjectively. Qed. Global Instance frame_monPred_at_bupd `{!BiBUpd PROP} p P 𝓡 𝓠 i : Frame p 𝓡 (|==> P i) 𝓠 → FrameMonPredAt p i 𝓡 (|==> P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_bupd. Qed. Global Instance into_embed_objective P : Objective P → IntoEmbed P (∀ i, P i). Proof. rewrite /IntoEmbed=> ?. by rewrite {1}(objective_objectively P) monPred_objectively_unfold. Qed. Global Instance elim_modal_at_bupd_goal `{!BiBUpd PROP} φ p p' 𝓟 𝓟' Q Q' i : ElimModal φ p p' 𝓟 𝓟' (|==> Q i) (|==> Q' i) → ElimModal φ p p' 𝓟 𝓟' ((|==> Q) i) ((|==> Q') i). Proof. by rewrite /ElimModal !monPred_at_bupd. Qed. Global Instance elim_modal_at_bupd_hyp `{!BiBUpd PROP} φ p p' P 𝓟 𝓟' 𝓠 𝓠' i: MakeMonPredAt i P 𝓟 → ElimModal φ p p' (|==> 𝓟) 𝓟' 𝓠 𝓠' → ElimModal φ p p' ((|==> P) i) 𝓟' 𝓠 𝓠'. Proof. by rewrite /MakeMonPredAt /ElimModal monPred_at_bupd=><-. Qed. Global Instance elim_modal_at φ p p' 𝓟 𝓟' P P' V: ElimModal φ p p' ⎡𝓟⎤ ⎡𝓟'⎤ P P' → ElimModal φ p p' 𝓟 𝓟' (P V) (P' V). Proof. rewrite /ElimModal -!embed_intuitionistically_if. iIntros (HH Hφ) "[? HP]". iApply HH; [done|]. iFrame. iIntros (? <-) "?". by iApply "HP". Qed. Global Instance add_modal_at_bupd_goal `{!BiBUpd PROP} φ 𝓟 𝓟' Q i : AddModal 𝓟 𝓟' (|==> Q i)%I → AddModal 𝓟 𝓟' ((|==> Q) i). Proof. by rewrite /AddModal !monPred_at_bupd. Qed. Global Instance from_forall_monPred_at_plainly `{!BiPlainly PROP} i P Φ : (∀ i, MakeMonPredAt i P (Φ i)) → FromForall ((■ P) i) (λ j, ■ (Φ j))%I (to_ident_name idx). Proof. rewrite /FromForall /MakeMonPredAt=>HPΦ. rewrite monPred_at_plainly. by setoid_rewrite HPΦ. Qed. Global Instance into_forall_monPred_at_plainly `{!BiPlainly PROP} i P Φ : (∀ i, MakeMonPredAt i P (Φ i)) → IntoForall ((■ P) i) (λ j, ■ (Φ j))%I. Proof. rewrite /IntoForall /MakeMonPredAt=>HPΦ. rewrite monPred_at_plainly. by setoid_rewrite HPΦ. Qed. Global Instance is_except_0_monPred_at i P : IsExcept0 P → IsExcept0 (P i). Proof. rewrite /IsExcept0=>- [/(_ i)]. by rewrite monPred_at_except_0. Qed. Global Instance make_monPred_at_internal_eq `{!BiInternalEq PROP} {A : ofe} (x y : A) i : MakeMonPredAt i (x ≡ y) (x ≡ y). Proof. by rewrite /MakeMonPredAt monPred_at_internal_eq. Qed. Global Instance make_monPred_at_except_0 i P 𝓠 : MakeMonPredAt i P 𝓠 → MakeMonPredAt i (◇ P) (◇ 𝓠). Proof. by rewrite /MakeMonPredAt monPred_at_except_0=><-. Qed. Global Instance make_monPred_at_later i P 𝓠 : MakeMonPredAt i P 𝓠 → MakeMonPredAt i (▷ P) (▷ 𝓠). Proof. by rewrite /MakeMonPredAt monPred_at_later=><-. Qed. Global Instance make_monPred_at_laterN i n P 𝓠 : MakeMonPredAt i P 𝓠 → MakeMonPredAt i (▷^n P) (▷^n 𝓠). Proof. rewrite /MakeMonPredAt=> <-. elim n=>//= ? <-. by rewrite monPred_at_later. Qed. Global Instance make_monPred_at_fupd `{!BiFUpd PROP} i E1 E2 P 𝓟 : MakeMonPredAt i P 𝓟 → MakeMonPredAt i (|={E1,E2}=> P) (|={E1,E2}=> 𝓟). Proof. by rewrite /MakeMonPredAt monPred_at_fupd=> <-. Qed. Global Instance into_internal_eq_monPred_at `{!BiInternalEq PROP} {A : ofe} (x y : A) P i : IntoInternalEq P x y → IntoInternalEq (P i) x y. Proof. rewrite /IntoInternalEq=> ->. by rewrite monPred_at_internal_eq. Qed. Global Instance into_except_0_monPred_at_fwd i P Q 𝓠 : IntoExcept0 P Q → MakeMonPredAt i Q 𝓠 → IntoExcept0 (P i) 𝓠. Proof. rewrite /IntoExcept0 /MakeMonPredAt=> -> <-. by rewrite monPred_at_except_0. Qed. Global Instance into_except_0_monPred_at_bwd i P 𝓟 Q : IntoExcept0 P Q → MakeMonPredAt i P 𝓟 → IntoExcept0 𝓟 (Q i). Proof. rewrite /IntoExcept0 /MakeMonPredAt=> H <-. by rewrite H monPred_at_except_0. Qed. Global Instance maybe_into_later_monPred_at i n P Q 𝓠 : IntoLaterN false n P Q → MakeMonPredAt i Q 𝓠 → IntoLaterN false n (P i) 𝓠. Proof. rewrite /IntoLaterN /MaybeIntoLaterN /MakeMonPredAt=> -> <-. elim n=>//= ? <-. by rewrite monPred_at_later. Qed. Global Instance from_later_monPred_at i φ `(sel : A) n P Q 𝓠 : FromModal φ (modality_laterN n) sel P Q → MakeMonPredAt i Q 𝓠 → FromModal φ (modality_laterN n) sel (P i) 𝓠. Proof. rewrite /FromModal /MakeMonPredAt=> HPQ <- ?. rewrite -HPQ //. elim n=>//= ? ->. by rewrite monPred_at_later. Qed. Global Instance frame_monPred_at_later p P 𝓡 𝓠 i : Frame p 𝓡 (▷ P i) 𝓠 → FrameMonPredAt p i 𝓡 (▷ P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_later. Qed. Global Instance frame_monPred_at_laterN p n P 𝓡 𝓠 i : Frame p 𝓡 (▷^n P i) 𝓠 → FrameMonPredAt p i 𝓡 (▷^n P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_laterN. Qed. Global Instance frame_monPred_at_fupd `{!BiFUpd PROP} E1 E2 p P 𝓡 𝓠 i : Frame p 𝓡 (|={E1,E2}=> P i) 𝓠 → FrameMonPredAt p i 𝓡 (|={E1,E2}=> P) 𝓠. Proof. rewrite /Frame /FrameMonPredAt=> ->. by rewrite monPred_at_fupd. Qed. End bi. (* When P and/or Q are evars when doing typeclass search on [IntoWand (R i) P Q], we use [MakeMonPredAt] in order to normalize the result of unification. However, when they are not evars, we want to propagate the known information through typeclass search. Hence, we do not want to use [MakeMonPredAt]. As a result, depending on P and Q being evars, we use a different version of [into_wand_monPred_at_xx_xx]. *) Global Hint Extern 3 (IntoWand _ _ (monPred_at _ _) ?P ?Q) => is_evar P; is_evar Q; eapply @into_wand_monPred_at_unknown_unknown : typeclass_instances. Global Hint Extern 2 (IntoWand _ _ (monPred_at _ _) ?P (monPred_at ?Q _)) => eapply @into_wand_monPred_at_unknown_known : typeclass_instances. Global Hint Extern 2 (IntoWand _ _ (monPred_at _ _) (monPred_at ?P _) ?Q) => eapply @into_wand_monPred_at_known_unknown_le : typeclass_instances. Global Hint Extern 2 (IntoWand _ _ (monPred_at _ _) (monPred_at ?P _) ?Q) => eapply @into_wand_monPred_at_known_unknown_ge : typeclass_instances. Section modal. Context {I : biIndex} {PROP : bi}. Local Notation monPred := (monPred I PROP). Implicit Types P Q R : monPred. Implicit Types 𝓟 𝓠 𝓡 : PROP. Implicit Types φ : Prop. Implicit Types i j : I. Global Instance elim_modal_at_fupd_goal `{!BiFUpd PROP} φ p p' E1 E2 E3 𝓟 𝓟' Q Q' i : ElimModal φ p p' 𝓟 𝓟' (|={E1,E3}=> Q i) (|={E2,E3}=> Q' i) → ElimModal φ p p' 𝓟 𝓟' ((|={E1,E3}=> Q) i) ((|={E2,E3}=> Q') i). Proof. by rewrite /ElimModal !monPred_at_fupd. Qed. Global Instance elim_modal_at_fupd_hyp `{!BiFUpd PROP} φ p p' E1 E2 P 𝓟 𝓟' 𝓠 𝓠' i : MakeMonPredAt i P 𝓟 → ElimModal φ p p' (|={E1,E2}=> 𝓟) 𝓟' 𝓠 𝓠' → ElimModal φ p p' ((|={E1,E2}=> P) i) 𝓟' 𝓠 𝓠'. Proof. by rewrite /MakeMonPredAt /ElimModal monPred_at_fupd=><-. Qed. Global Instance elim_acc_at_None `{!BiFUpd PROP} {X} φ E1 E2 E3 E4 α α' β β' P P'x i : (∀ x, MakeEmbed (α x) (α' x)) → (∀ x, MakeEmbed (β x) (β' x)) → ElimAcc (X:=X) φ (fupd E1 E2) (fupd E3 E4) α' β' (λ _, None) P P'x → ElimAcc (X:=X) φ (fupd E1 E2) (fupd E3 E4) α β (λ _, None) (P i) (λ x, P'x x i). Proof. rewrite /ElimAcc /MakeEmbed. iIntros (Hα Hβ HEA ?) "Hinner Hacc". iApply (HEA with "[Hinner]"); first done. - iIntros (x). iSpecialize ("Hinner" $! x). rewrite -Hα. by iIntros (? <-). - iMod "Hacc". iDestruct "Hacc" as (x) "[Hα Hclose]". iModIntro. iExists x. rewrite -Hα -Hβ. iFrame. iIntros (? _) "Hβ". by iApply "Hclose". Qed. Global Instance elim_acc_at_Some `{!BiFUpd PROP} {X} φ E1 E2 E3 E4 α α' β β' γ γ' P P'x i : (∀ x, MakeEmbed (α x) (α' x)) → (∀ x, MakeEmbed (β x) (β' x)) → (∀ x, MakeEmbed (γ x) (γ' x)) → ElimAcc (X:=X) φ (fupd E1 E2) (fupd E3 E4) α' β' (λ x, Some (γ' x)) P P'x → ElimAcc (X:=X) φ (fupd E1 E2) (fupd E3 E4) α β (λ x, Some (γ x)) (P i) (λ x, P'x x i). Proof. rewrite /ElimAcc /MakeEmbed. iIntros (Hα Hβ Hγ HEA ?) "Hinner Hacc". iApply (HEA with "[Hinner]"); first done. - iIntros (x). iSpecialize ("Hinner" $! x). rewrite -Hα. by iIntros (? <-). - iMod "Hacc". iDestruct "Hacc" as (x) "[Hα Hclose]". iModIntro. iExists x. rewrite -Hα -Hβ -Hγ. iFrame. iIntros (? _) "Hβ /=". by iApply "Hclose". Qed. Global Instance add_modal_at_fupd_goal `{!BiFUpd PROP} E1 E2 𝓟 𝓟' Q i : AddModal 𝓟 𝓟' (|={E1,E2}=> Q i) → AddModal 𝓟 𝓟' ((|={E1,E2}=> Q) i). Proof. by rewrite /AddModal !monPred_at_fupd. Qed. (* This hard-codes the fact that ElimInv with_close returns a [(λ _, ...)] as Q'. *) Global Instance elim_inv_embed_with_close {X : Type} φ 𝓟inv 𝓟in (𝓟out 𝓟close : X → PROP) Pin (Pout Pclose : X → monPred) Q Q' : (∀ i, ElimInv φ 𝓟inv 𝓟in 𝓟out (Some 𝓟close) (Q i) (λ _, Q' i)) → MakeEmbed 𝓟in Pin → (∀ x, MakeEmbed (𝓟out x) (Pout x)) → (∀ x, MakeEmbed (𝓟close x) (Pclose x)) → ElimInv (X:=X) φ ⎡𝓟inv⎤ Pin Pout (Some Pclose) Q (λ _, Q'). Proof. rewrite /MakeEmbed /ElimInv=>H <- Hout Hclose ?. iStartProof PROP. setoid_rewrite <-Hout. setoid_rewrite <-Hclose. iIntros (?) "(?&?&HQ')". iApply H; [done|]. iFrame. iIntros (x) "?". by iApply "HQ'". Qed. Global Instance elim_inv_embed_without_close {X : Type} φ 𝓟inv 𝓟in (𝓟out : X → PROP) Pin (Pout : X → monPred) Q (Q' : X → monPred) : (∀ i, ElimInv φ 𝓟inv 𝓟in 𝓟out None (Q i) (λ x, Q' x i)) → MakeEmbed 𝓟in Pin → (∀ x, MakeEmbed (𝓟out x) (Pout x)) → ElimInv (X:=X) φ ⎡𝓟inv⎤ Pin Pout None Q Q'. Proof. rewrite /MakeEmbed /ElimInv=>H <-Hout ?. iStartProof PROP. setoid_rewrite <-Hout. iIntros (?) "(?&?&HQ')". iApply H; [done|]. iFrame. iIntros (x) "?". by iApply "HQ'". Qed. End modal.
lemma collinear_alt: "collinear S \<longleftrightarrow> (\<exists>u v. \<forall>x \<in> S. \<exists>c. x = u + c *\<^sub>R v)" (is "?lhs = ?rhs")
(* Title: HMLSL.thy Author: Sven Linker Definition of HMLSL syntax over traffic snapshots and views for cars with any sensors. Each formula is a function with a traffic snapshot and view as parameters, and evaluates to True or False. *) section\<open>Basic HMLSL\<close> text\<open> In this section, we define the basic formulas of HMLSL. All of these basic formulas and theorems are independent of the choice of sensor function. However, they show how the general operators (chop, changes in perspective, atomic formulas) work. \<close> theory HMLSL imports "Restriction" "Move" Length begin subsection\<open>Syntax of Basic HMLSL\<close> text \<open> Formulas are functions associating a traffic snapshot and a view with a Boolean value. \<close> type_synonym \<sigma> = " traffic \<Rightarrow> view \<Rightarrow> bool" locale hmlsl = restriction+ fixes sensors::"cars \<Rightarrow> traffic \<Rightarrow> cars \<Rightarrow> real" assumes sensors_ge:"(sensors e ts c) > 0" begin end sublocale hmlsl<sensors by (simp add: sensors.intro sensors_ge) context hmlsl begin text\<open> All formulas are defined as abbreviations. As a consequence, proofs will directly refer to the semantics of HMLSL, i.e., traffic snapshots and views. \<close> text\<open> The first-order operators are direct translations into HOL operators. \<close> definition mtrue :: "\<sigma>" ("\<^bold>\<top>") where "\<^bold>\<top> \<equiv> \<lambda> ts w. True" definition mfalse :: "\<sigma>" ("\<^bold>\<bottom>") where "\<^bold>\<bottom> \<equiv> \<lambda> ts w. False" definition mnot :: "\<sigma>\<Rightarrow>\<sigma>" ("\<^bold>\<not>_"[52]53) where "\<^bold>\<not>\<phi> \<equiv> \<lambda> ts w. \<not>\<phi>(ts)(w)" definition mnegpred :: "(cars\<Rightarrow>\<sigma>)\<Rightarrow>(cars\<Rightarrow>\<sigma>)" ("\<^sup>\<not>_"[52]53) where "\<^sup>\<not>\<Phi> \<equiv> \<lambda>x.\<lambda> ts w. \<not>\<Phi>(x)(ts)(w)" definition mand :: "\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>\<sigma>" (infixr"\<^bold>\<and>"51) where "\<phi>\<^bold>\<and>\<psi> \<equiv> \<lambda> ts w. \<phi>(ts)(w)\<and>\<psi>(ts)(w)" definition mor :: "\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>\<sigma>" (infix "\<^bold>\<or>"50 ) where "\<phi>\<^bold>\<or>\<psi> \<equiv> \<lambda> ts w. \<phi>(ts)(w)\<or>\<psi>(ts)(w)" definition mimp :: "\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>\<sigma>" (infixr"\<^bold>\<rightarrow>"49) where "\<phi>\<^bold>\<rightarrow>\<psi> \<equiv> \<lambda> ts w. \<phi>(ts)(w)\<longrightarrow>\<psi>(ts)(w)" definition mequ :: "\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>\<sigma>" (infixr"\<^bold>\<leftrightarrow>"48) where "\<phi>\<^bold>\<leftrightarrow>\<psi> \<equiv> \<lambda> ts w. \<phi>(ts)(w)\<longleftrightarrow>\<psi>(ts)(w)" definition mforall :: "('a\<Rightarrow>\<sigma>)\<Rightarrow>\<sigma>" ("\<^bold>\<forall>") where "\<^bold>\<forall>\<Phi> \<equiv> \<lambda> ts w.\<forall>x. \<Phi>(x)(ts)(w)" definition mforallB :: "('a\<Rightarrow>\<sigma>)\<Rightarrow>\<sigma>" (binder"\<^bold>\<forall>"[8]9) where "\<^bold>\<forall>x. \<phi>(x) \<equiv> \<^bold>\<forall>\<phi>" definition mexists :: "('a\<Rightarrow>\<sigma>)\<Rightarrow>\<sigma>" ("\<^bold>\<exists>") where "\<^bold>\<exists>\<Phi> \<equiv> \<lambda> ts w.\<exists>x. \<Phi>(x)(ts)(w)" definition mexistsB :: "(('a)\<Rightarrow>\<sigma>)\<Rightarrow>\<sigma>" (binder"\<^bold>\<exists>"[8]9) where "\<^bold>\<exists>x. \<phi>(x) \<equiv> \<^bold>\<exists>\<phi>" definition meq :: "'a\<Rightarrow>'a\<Rightarrow>\<sigma>" (infixr"\<^bold>="60) \<comment> \<open>Equality\<close> where "x\<^bold>=y \<equiv> \<lambda> ts w. x = y" definition mgeq :: "('a::ord) \<Rightarrow> 'a \<Rightarrow> \<sigma>" (infix "\<^bold>\<ge>" 60) where "x \<^bold>\<ge> y \<equiv> \<lambda> ts w. x \<ge> y" definition mge ::"('a::ord) \<Rightarrow> 'a \<Rightarrow> \<sigma>" (infix "\<^bold>>" 60) where "x \<^bold>> y \<equiv> \<lambda> ts w. x > y" text\<open> For the spatial modalities, we use the chopping operations defined on views. Observe that our chop modalities are existential. \<close> definition hchop :: "\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>\<sigma>" (infixr "\<^bold>\<frown>" 53) where "\<phi> \<^bold>\<frown> \<psi> \<equiv> \<lambda> ts w.\<exists>v u. (w=v\<parallel>u) \<and> \<phi>(ts)(v)\<and>\<psi>(ts)(u)" definition vchop :: "\<sigma>\<Rightarrow>\<sigma>\<Rightarrow>\<sigma>" (infixr "\<^bold>\<smile>" 53) where "\<phi> \<^bold>\<smile> \<psi> \<equiv> \<lambda> ts w.\<exists>v u. (w=v--u) \<and> \<phi>(ts)(v) \<and> \<psi>(ts)(u)" definition somewhere ::"\<sigma>\<Rightarrow>\<sigma>" ( "\<^bold>\<langle>_\<^bold>\<rangle> " 55) where "\<^bold>\<langle>\<phi>\<^bold>\<rangle> \<equiv> \<^bold>\<top> \<^bold>\<frown> (\<^bold>\<top>\<^bold>\<smile>\<phi> \<^bold>\<smile>\<^bold>\<top>)\<^bold>\<frown>\<^bold>\<top>" definition everywhere::"\<sigma>\<Rightarrow>\<sigma>" ("\<^bold>[_\<^bold>]" 55) where "\<^bold>[\<phi>\<^bold>] \<equiv> \<^bold>\<not>\<^bold>\<langle>\<^bold>\<not>\<phi>\<^bold>\<rangle>" text\<open> To change the perspective of a view, we use an operator in the fashion of Hybrid Logic. \<close> definition at :: "cars \<Rightarrow> \<sigma> \<Rightarrow> \<sigma> " ("\<^bold>@ _ _" 56) where "\<^bold>@c \<phi> \<equiv> \<lambda>ts w . \<forall>v'. (w=c>v') \<longrightarrow> \<phi>(ts)(v')" text\<open> The behavioural modalities are defined as usual modal box-like modalities, where the accessibility relations are given by the different types of transitions between traffic snapshots. \<close> definition res_box::"cars \<Rightarrow> \<sigma> \<Rightarrow> \<sigma>" ("\<^bold>\<box>r'(_') _" 55) where "\<^bold>\<box>r(c) \<phi> \<equiv> \<lambda> ts w. \<forall>ts'. (ts\<^bold>\<midarrow>r(c)\<^bold>\<rightarrow>ts') \<longrightarrow> \<phi>(ts')(w)" definition clm_box::"cars \<Rightarrow> \<sigma> \<Rightarrow> \<sigma>" ("\<^bold>\<box>c'(_') _" 55) where "\<^bold>\<box>c(c) \<phi> \<equiv> \<lambda> ts w. \<forall>ts' n. (ts\<^bold>\<midarrow>c(c,n)\<^bold>\<rightarrow>ts') \<longrightarrow> \<phi>(ts')(w)" definition wdres_box::"cars \<Rightarrow> \<sigma> \<Rightarrow> \<sigma>" ("\<^bold>\<box>wdr'(_') _" 55) where "\<^bold>\<box>wdr(c) \<phi> \<equiv> \<lambda> ts w. \<forall>ts' n. (ts\<^bold>\<midarrow>wdr(c,n)\<^bold>\<rightarrow>ts') \<longrightarrow> \<phi>(ts')(w)" definition wdclm_box::"cars \<Rightarrow> \<sigma> \<Rightarrow> \<sigma>" ("\<^bold>\<box>wdc'(_') _" 55) where "\<^bold>\<box>wdc(c) \<phi> \<equiv> \<lambda> ts w. \<forall>ts'. (ts\<^bold>\<midarrow>wdc(c)\<^bold>\<rightarrow>ts') \<longrightarrow> \<phi>(ts')(w)" definition time_box::"\<sigma> \<Rightarrow> \<sigma>" ("\<^bold>\<box>\<^bold>\<tau> _" 55) where "\<^bold>\<box>\<^bold>\<tau> \<phi> \<equiv> \<lambda>ts w. \<forall>ts'. (ts\<^bold>\<leadsto>ts') \<longrightarrow> \<phi>(ts')(move ts ts' w)" definition globally::"\<sigma> \<Rightarrow> \<sigma>" ("\<^bold>G _" 55) where "\<^bold>G \<phi> \<equiv> \<lambda>ts w. \<forall>ts'. (ts \<^bold>\<Rightarrow> ts') \<longrightarrow> \<phi>(ts')(move ts ts' w)" text\<open> The spatial atoms to refer to reservations, claims and free space are direct translations of the original definitions of MLSL \cite{Hilscher2011} into the Isabelle implementation. \<close> definition re:: "cars \<Rightarrow> \<sigma>" ("re'(_')" 70) where "re(c) \<equiv> \<lambda> ts v. \<parallel>ext v\<parallel>> 0 \<and> len v ts c = ext v \<and> restrict v (res ts) c = lan v \<and> |lan v|=1" definition cl:: "cars \<Rightarrow> \<sigma>" ("cl'(_')" 70) where "cl(c) \<equiv> \<lambda> ts v. \<parallel>ext v\<parallel>> 0 \<and> len v ts c = ext v \<and> restrict v (clm ts) c = lan v \<and> |lan v| = 1" abbreviation free:: "\<sigma>" ("free") where "free \<equiv> \<lambda> ts v. \<parallel>ext v\<parallel> > 0 \<and> |lan v| = 1 \<and> (\<forall>c. \<parallel>len v ts c\<parallel> = 0 \<or> (restrict v (clm ts) c = \<emptyset> \<and> restrict v (res ts) c = \<emptyset>))" text\<open> Even though we do not need them for the subsequent proofs of safety, we define ways to measure the number of lanes (width) and the size of the extension (length) of a view. This allows us to connect the atomic formulas for reservations and claims with the atom denoting free space \cite{Linker2015a}. \<close> definition width_eq::"nat \<Rightarrow> \<sigma>" ("\<^bold>\<omega> = _ " 60) where "\<^bold>\<omega> = n \<equiv> \<lambda> ts v. |lan v| = n" definition width_geq::"nat \<Rightarrow> \<sigma>" ("\<^bold>\<omega> \<ge> _" 60) where "\<^bold>\<omega> \<ge> n \<equiv> \<lambda> ts v. |lan v| \<ge> n" definition width_ge::"nat \<Rightarrow> \<sigma>" ("\<^bold>\<omega> > _" 60) where "\<^bold>\<omega> > n \<equiv> (\<^bold>\<omega> = n+1) \<^bold>\<smile> \<^bold>\<top>" definition length_eq::"real \<Rightarrow> \<sigma>" ("\<^bold>\<l> = _ " 60) where "\<^bold>\<l> = r \<equiv> \<lambda> ts v. \<parallel>ext v\<parallel> = r" definition length_ge:: "real \<Rightarrow> \<sigma>" ("\<^bold>\<l> > _" 60) where "\<^bold>\<l> > r \<equiv> \<lambda> ts v. \<parallel>ext v\<parallel> > r" definition length_geq::"real \<Rightarrow> \<sigma>" ("\<^bold>\<l> \<ge> _" 60) where "\<^bold>\<l> \<ge> r \<equiv> (\<^bold>\<l> = r) \<^bold>\<or> (\<^bold>\<l> > r)" text\<open> For convenience, we use abbreviations for the validity and satisfiability of formulas. While the former gives a nice way to express theorems, the latter is useful within proofs. \<close> definition satisfies::" traffic \<Rightarrow> view \<Rightarrow> \<sigma> \<Rightarrow> bool" ("_ , _ \<Turnstile> _" 10) where "ts,v \<Turnstile> \<phi> \<equiv> \<phi>(ts)(v)" definition valid :: "\<sigma> \<Rightarrow> bool" ("\<Turnstile> _" 10 ) where "\<Turnstile> \<phi> \<equiv> \<forall>ts. \<forall>v. ( ts,v \<Turnstile> \<phi> )" subsection \<open>Theorems about Basic HMLSL\<close> subsubsection\<open>FOL Fragment\<close> text\<open>Disjunction\<close> lemma mdisE: assumes major: "ts,v \<Turnstile> P \<^bold>\<or> Q" and minorP: "ts,v \<Turnstile> P \<Longrightarrow> ts,v \<Turnstile>R" and minorQ: "ts,v \<Turnstile> Q \<Longrightarrow> ts,v \<Turnstile> R" shows "ts,v \<Turnstile>R" using major minorP minorQ mor_def satisfies_def by auto lemma mdisjI1: "ts,v \<Turnstile> P \<Longrightarrow> ts,v \<Turnstile>P \<^bold>\<or> Q" using mor_def satisfies_def by auto lemma mdisjI2: "ts,v \<Turnstile> Q \<Longrightarrow> ts,v \<Turnstile> P \<^bold>\<or> Q" using mor_def satisfies_def by auto text\<open>Conjunction\<close> lemma mconjI: "\<lbrakk>ts,v \<Turnstile>P; ts,v \<Turnstile> Q\<rbrakk> \<Longrightarrow> ts,v \<Turnstile> P \<^bold>\<and> Q" using mand_def satisfies_def by auto lemma mconjunct1: "\<lbrakk>ts,v \<Turnstile> P \<^bold>\<and> Q\<rbrakk> \<Longrightarrow> ts,v \<Turnstile>P" using mand_def satisfies_def by auto lemma mconjunct2: "\<lbrakk>ts,v \<Turnstile> P \<^bold>\<and> Q\<rbrakk> \<Longrightarrow> ts,v \<Turnstile>Q" using mand_def satisfies_def by auto lemma mconjE: assumes major: "ts,v \<Turnstile>P \<^bold>\<and> Q" and minor: "\<lbrakk>ts,v \<Turnstile>P; ts,v \<Turnstile> Q\<rbrakk> \<Longrightarrow> R" shows R using mand_def satisfies_def using major minor by auto lemma mcontext_conjI: assumes "ts,v \<Turnstile>P" "ts,v \<Turnstile> P \<Longrightarrow> ts,v \<Turnstile>Q" shows "ts,v \<Turnstile> P \<^bold>\<and> Q" using mand_def satisfies_def assms(1) assms(2) by auto lemma hchop_weaken1: "ts,v \<Turnstile> \<phi> \<^bold>\<rightarrow> (\<phi> \<^bold>\<frown> \<^bold>\<top>) " using valid_def hchop_def horizontal_chop_empty_right satisfies_def by (metis (no_types, lifting) hmlsl.intro hmlsl.mtrue_def mimp_def sensors_ge) lemma hchop_weaken2: " \<Turnstile> \<phi> \<^bold>\<rightarrow> (\<^bold>\<top> \<^bold>\<frown> \<phi>) " using valid_def hchop_def horizontal_chop_empty_left satisfies_def by fastforce lemma hchop_weaken: " \<Turnstile> \<phi> \<^bold>\<rightarrow> (\<^bold>\<top> \<^bold>\<frown> \<phi> \<^bold>\<frown> \<^bold>\<top>)" using valid_def hchop_weaken1 hchop_weaken2 using view.horizontal_chop_empty_left satisfies_def by fastforce lemma hchop_neg1:"\<Turnstile> \<^bold>\<not> (\<phi> \<^bold>\<frown> \<^bold>\<top>) \<^bold>\<rightarrow> ((\<^bold>\<not> \<phi>) \<^bold>\<frown> \<^bold>\<top>)" using horizontal_chop1 valid_def hchop_def satisfies_def using view.horizontal_chop_empty_right by fastforce lemma hchop_neg2:"\<Turnstile> \<^bold>\<not> (\<^bold>\<top>\<^bold>\<frown>\<phi> ) \<^bold>\<rightarrow> (\<^bold>\<top> \<^bold>\<frown> \<^bold>\<not> \<phi>)" using valid_def hchop_def horizontal_chop1 satisfies_def using view.horizontal_chop_empty_right by fastforce lemma hchop_disj_distr1:"\<Turnstile> ((\<phi> \<^bold>\<frown> (\<psi> \<^bold>\<or> \<chi>)) \<^bold>\<leftrightarrow> ((\<phi> \<^bold>\<frown> \<psi>)\<^bold>\<or>(\<phi> \<^bold>\<frown> \<chi>)))" using valid_def hchop_def satisfies_def by auto lemma hchop_disj_distr2:"\<Turnstile> (((\<psi> \<^bold>\<or> \<chi>)\<^bold>\<frown>\<phi>) \<^bold>\<leftrightarrow> ((\<psi> \<^bold>\<frown> \<phi>)\<^bold>\<or>(\<chi> \<^bold>\<frown> \<phi>)))" using valid_def hchop_def satisfies_def by auto lemma hchop_assoc:"\<Turnstile>\<phi> \<^bold>\<frown> (\<psi> \<^bold>\<frown> \<chi>) \<^bold>\<leftrightarrow> (\<phi> \<^bold>\<frown> \<psi>) \<^bold>\<frown> \<chi>" unfolding valid_def satisfies_def using hchop_def horizontal_chop_assoc1 horizontal_chop_assoc2 by fastforce lemma v_chop_weaken1:"\<Turnstile> (\<phi> \<^bold>\<rightarrow> (\<phi> \<^bold>\<smile> \<^bold>\<top>))" using valid_def satisfies_def vertical_chop_empty_down vchop_def by fastforce lemma v_chop_weaken2:"\<Turnstile> (\<phi> \<^bold>\<rightarrow> (\<^bold>\<top> \<^bold>\<smile> \<phi>))" using valid_def satisfies_def vertical_chop_empty_up vchop_def by fastforce lemma v_chop_assoc:"\<Turnstile>(\<phi> \<^bold>\<smile> (\<psi> \<^bold>\<smile> \<chi>)) \<^bold>\<leftrightarrow> ((\<phi> \<^bold>\<smile> \<psi>) \<^bold>\<smile> \<chi>)" unfolding valid_def satisfies_def using vertical_chop_assoc1 vertical_chop_assoc2 vchop_def by fastforce lemma vchop_disj_distr1:"\<Turnstile> ((\<phi> \<^bold>\<smile> (\<psi> \<^bold>\<or> \<chi>)) \<^bold>\<leftrightarrow> ((\<phi> \<^bold>\<smile> \<psi>)\<^bold>\<or>(\<phi> \<^bold>\<smile> \<chi>)))" using valid_def satisfies_def vchop_def by auto lemma vchop_disj_distr2:"\<Turnstile> (((\<psi> \<^bold>\<or> \<chi>) \<^bold>\<smile> \<phi> ) \<^bold>\<leftrightarrow> ((\<psi> \<^bold>\<smile> \<phi>)\<^bold>\<or>(\<chi> \<^bold>\<smile> \<phi>)))" using valid_def satisfies_def vchop_def by auto lemma somewhere_leq:" (ts,v \<Turnstile> \<^bold>\<langle> \<phi> \<^bold>\<rangle>) \<longleftrightarrow> (\<exists>v'. v' \<le> v \<and> (ts,v' \<Turnstile> \<phi>))" proof assume "ts,v \<Turnstile> \<^bold>\<langle> \<phi> \<^bold>\<rangle>" then obtain v1 v2 vl vr where 1: " (v=vl\<parallel>v1) \<and> (v1=v2\<parallel>vr) \<and> (ts,v2 \<Turnstile> \<^bold>\<top> \<^bold>\<smile> \<phi> \<^bold>\<smile> \<^bold>\<top>)" using hchop_def satisfies_def by auto then obtain v3 vu vd v' where 2:"(v=vl\<parallel>v1) \<and> (v1=v2\<parallel>vr) \<and> (v2=vd--v3) \<and> (v3=v'--vu) \<and> (ts,v' \<Turnstile> \<phi>)" using satisfies_def vchop_def by auto then have "v' \<le> v" using somewhere_leq 1 2 by blast then show "(\<exists>v'. v' \<le> v \<and> (ts,v' \<Turnstile> \<phi>))" using 2 by blast next assume "(\<exists>v'. v' \<le> v \<and> (ts,v' \<Turnstile> \<phi>))" then obtain v1 v2 vl vr v3 vu vd v' where 1:"(v=vl\<parallel>v1) \<and> (v1=v2\<parallel>vr) \<and> (v2=vd--v3) \<and> (v3=v'--vu) \<and> (ts,v' \<Turnstile> \<phi>)" using somewhere_leq by auto then have "ts, v2 \<Turnstile> \<^bold>\<top> \<^bold>\<smile> \<phi> \<^bold>\<smile> \<^bold>\<top>" using satisfies_def vchop_def by auto then show "ts,v \<Turnstile> \<^bold>\<langle> \<phi> \<^bold>\<rangle>" using hchop_def satisfies_def 1 by auto qed lemma at_exists :"ts,v \<Turnstile> \<phi> \<^bold>\<rightarrow> (\<^bold>\<exists> c. \<^bold>@c \<phi>)" unfolding valid_def satisfies_def unfolding at_def using view.switch_refl view.switch_unique by blast (*proof fix ts v assume assm:"ts,v \<Turnstile>\<phi>" obtain d where d_def:"d=own v" by blast then have "ts,v \<Turnstile> \<^bold>@d \<phi>" using assm switch_refl switch_unique unfolding satisfies_def by fastforce show "ts,v \<Turnstile> (\<^bold>\<exists> c. \<^bold>@c \<phi>)" qed *) lemma at_conj_distr:"\<Turnstile>(\<^bold>@c ( \<phi> \<^bold>\<and> \<psi>)) \<^bold>\<leftrightarrow> ((\<^bold>@c \<phi>) \<^bold>\<and> (\<^bold>@c \<psi>))" unfolding at_def satisfies_def using valid_def satisfies_def switch_unique by blast lemma at_disj_dist:"\<Turnstile>(\<^bold>@c (\<phi> \<^bold>\<or> \<psi>)) \<^bold>\<leftrightarrow> ((\<^bold>@c \<phi> ) \<^bold>\<or> ( \<^bold>@c \<psi> ))" unfolding at_def satisfies_def valid_def using valid_def switch_unique satisfies_def by blast lemma at_hchop_dist1:"ts,v \<Turnstile>(\<^bold>@c (\<phi> \<^bold>\<frown> \<psi>)) \<^bold>\<rightarrow> ((\<^bold>@c \<phi>) \<^bold>\<frown> (\<^bold>@c \<psi>))" proof - { assume assm:"ts, v \<Turnstile>(\<^bold>@c (\<phi> \<^bold>\<frown> \<psi>))" obtain v' where v':"v=c>v'" using switch_always_exists by fastforce with assm obtain v1' and v2' where chop:"(v'=v1'\<parallel>v2') \<and> (ts,v1' \<Turnstile> \<phi>) \<and> (ts,v2'\<Turnstile>\<psi>)" unfolding satisfies_def using hchop_def at_def by auto from chop and v' obtain v1 and v2 where origin:"(v1=c>v1') \<and> (v2=c>v2') \<and> (v=v1\<parallel>v2)" using switch_hchop2 by fastforce hence v1:"ts,v1 \<Turnstile> (\<^bold>@c \<phi>)" and v2:"ts,v2 \<Turnstile> (\<^bold>@c \<psi>)" unfolding satisfies_def using switch_unique chop at_def unfolding satisfies_def by fastforce+ from v1 and v2 and origin have "ts,v \<Turnstile>(\<^bold>@c \<phi>) \<^bold>\<frown> (\<^bold>@c \<psi>)" unfolding satisfies_def hchop_def by blast } from this show ?thesis unfolding satisfies_def by blast (* " ( ts,v \<Turnstile> (\<^bold>@ c \<phi>) \<^bold>\<frown>( \<^bold>@ c \<psi>)) " *) qed lemma at_hchop_dist2:"\<Turnstile>( (\<^bold>@c \<phi>) \<^bold>\<frown> (\<^bold>@c \<psi>)) \<^bold>\<rightarrow> (\<^bold>@c (\<phi> \<^bold>\<frown> \<psi>)) " unfolding valid_def at_def hchop_def using switch_unique switch_hchop1 switch_def unfolding satisfies_def at_def hchop_def by meson (*lemma at_hchop_dist:"\<Turnstile>( (\<^bold>@c \<phi>) \<^bold>\<frown> (\<^bold>@c \<psi>)) \<^bold>\<leftrightarrow> (\<^bold>@c (\<phi> \<^bold>\<frown> \<psi>)) " unfolding valid_def using at_hchop_dist1 at_hchop_dist2 *) lemma at_vchop_dist1:"\<Turnstile>(\<^bold>@c (\<phi> \<^bold>\<smile> \<psi>)) \<^bold>\<rightarrow> ( (\<^bold>@c \<phi>) \<^bold>\<smile> (\<^bold>@c \<psi>))" proof - { fix ts v assume assm:"ts, v \<Turnstile>(\<^bold>@c (\<phi> \<^bold>\<smile> \<psi>))" obtain v' where v':"v=c>v'" using switch_always_exists by fastforce with assm obtain v1' and v2' where chop:"(v'=v1'--v2') \<and> (ts,v1' \<Turnstile> \<phi>) \<and> (ts,v2'\<Turnstile>\<psi>)" using at_def satisfies_def vchop_def by auto from chop and v' obtain v1 and v2 where origin:"(v1=c>v1') \<and> (v2=c>v2') \<and> (v=v1--v2)" using switch_vchop2 by fastforce hence v1:"ts,v1 \<Turnstile> (\<^bold>@c \<phi>)" and v2:"ts,v2 \<Turnstile> (\<^bold>@c \<psi>)" using switch_unique chop at_def satisfies_def unfolding at_def unfolding satisfies_def by fastforce+ from v1 and v2 and origin have "ts,v \<Turnstile> (\<^bold>@c \<phi>) \<^bold>\<smile> (\<^bold>@c \<psi>)" unfolding satisfies_def using vchop_def by auto } from this show ?thesis unfolding satisfies_def valid_def by simp qed (*lemma at_vchop_dist2:"\<Turnstile>( (\<^bold>@c \<phi>) \<^bold>\<smile> (\<^bold>@c \<psi>)) \<^bold>\<rightarrow> (\<^bold>@c (\<phi> \<^bold>\<smile> \<psi>)) " using valid_def switch_unique switch_vchop1 switch_def lemma at_vchop_dist:"\<Turnstile>( (\<^bold>@c \<phi>) \<^bold>\<smile> (\<^bold>@c \<psi>)) \<^bold>\<leftrightarrow> (\<^bold>@c (\<phi> \<^bold>\<smile> \<psi>)) " using at_vchop_dist1 at_vchop_dist2 by blast *) lemma at_eq:"\<Turnstile>(\<^bold>@e c \<^bold>= d) \<^bold>\<leftrightarrow> (c \<^bold>= d)" unfolding valid_def satisfies_def using switch_always_exists unfolding at_def by blast lemma at_neg1:"\<Turnstile>(\<^bold>@c \<^bold>\<not> \<phi>) \<^bold>\<rightarrow> \<^bold>\<not> (\<^bold>@c \<phi>)" unfolding satisfies_def valid_def using switch_unique unfolding at_def by (simp add: view.switch_always_exists) lemma at_neg2:"\<Turnstile>\<^bold>\<not> (\<^bold>@c \<phi> ) \<^bold>\<rightarrow> ( (\<^bold>@c \<^bold>\<not> \<phi>))" unfolding valid_def satisfies_def at_def using switch_unique by fastforce lemma at_neg :"\<Turnstile>(\<^bold>@c( \<^bold>\<not> \<phi>)) \<^bold>\<leftrightarrow> \<^bold>\<not> (\<^bold>@c \<phi>)" unfolding at_def satisfies_def valid_def using valid_def view.switch_always_exists view.switch_unique by fastforce lemma at_neg':"ts,v \<Turnstile> \<^bold>\<not> (\<^bold>@c \<phi>) \<^bold>\<leftrightarrow> (\<^bold>@c( \<^bold>\<not> \<phi>))" unfolding valid_def at_def satisfies_def using at_neg valid_def satisfies_def by (metis view.switch_always_exists view.switch_unique) lemma at_neg_neg1:"\<Turnstile>(\<^bold>@c \<phi>) \<^bold>\<rightarrow> \<^bold>\<not>(\<^bold>@c \<^bold>\<not> \<phi>)" unfolding valid_def satisfies_def at_def using switch_unique switch_def switch_refl using view.switch_always_exists by blast lemma at_neg_neg2:"\<Turnstile>\<^bold>\<not>(\<^bold>@c \<^bold>\<not> \<phi>) \<^bold>\<rightarrow> (\<^bold>@c \<phi>)" unfolding valid_def at_def satisfies_def using switch_unique switch_def switch_refl by metis lemma at_neg_neg:"\<Turnstile> (\<^bold>@c \<phi>) \<^bold>\<leftrightarrow> \<^bold>\<not>(\<^bold>@c \<^bold>\<not> \<phi>)" unfolding valid_def at_def satisfies_def using at_neg_neg1 at_neg_neg2 valid_def at_def using at_neg' by (metis view.switch_always_exists view.switch_unique) lemma globally_all_iff:"\<Turnstile> (\<^bold>G(\<^bold>\<forall>c. \<phi>)) \<^bold>\<leftrightarrow> (\<^bold>\<forall>c.( \<^bold>G \<phi>))" unfolding valid_def satisfies_def by simp lemma globally_all_iff':"ts,v\<Turnstile> (\<^bold>G(\<^bold>\<forall>c. \<phi>)) \<^bold>\<leftrightarrow> (\<^bold>\<forall>c.( \<^bold>G \<phi>))" unfolding valid_def satisfies_def by simp lemma globally_refl:" \<Turnstile>(\<^bold>G \<phi>) \<^bold>\<rightarrow> \<phi>" unfolding valid_def satisfies_def using traffic.abstract.refl move_nothing by fastforce lemma globally_4: "\<Turnstile> (\<^bold>G \<phi>) \<^bold>\<rightarrow> \<^bold>G \<^bold>G \<phi>" using traffic.abs_trans traffic.move_trans valid_def satisfies_def by presburger (*proof - { fix ts v ts' ts'' assume 1:"ts \<^bold>\<Rightarrow> ts'" and 2:"ts' \<^bold>\<Rightarrow> ts''" and 3:"ts,v \<Turnstile> \<^bold>G \<phi>" from 2 and 1 have "ts \<^bold>\<Rightarrow> ts''" using traffic.abs_trans by blast moreover from 1 and 2 have "move ts' ts'' (move ts ts' v) = move ts ts'' v" using traffic.move_trans by blast with 3 have "ts'', move ts' ts'' (move ts ts' v) \<Turnstile>\<phi>" unfolding satisfies_def using calculation by simp } show ?thesis using traffic.abs_trans traffic.move_trans valid_def by presburger qed *) lemma spatial_weaken: "\<Turnstile> (\<phi> \<^bold>\<rightarrow> \<^bold>\<langle>\<phi>\<^bold>\<rangle>)" unfolding valid_def satisfies_def using horizontal_chop_empty_left horizontal_chop_empty_right vertical_chop_empty_down vertical_chop_empty_up hchop_def vchop_def by fastforce lemma spatial_weaken2:"\<Turnstile> (\<phi> \<^bold>\<rightarrow> \<psi>) \<^bold>\<rightarrow> (\<phi> \<^bold>\<rightarrow> \<^bold>\<langle>\<psi>\<^bold>\<rangle>)" unfolding valid_def satisfies_def using spatial_weaken horizontal_chop_empty_left horizontal_chop_empty_right vertical_chop_empty_down vertical_chop_empty_up unfolding valid_def satisfies_def by blast lemma somewhere_distr: "\<Turnstile> \<^bold>\<langle>\<phi>\<^bold>\<or>\<psi>\<^bold>\<rangle> \<^bold>\<leftrightarrow> \<^bold>\<langle>\<phi>\<^bold>\<rangle> \<^bold>\<or> \<^bold>\<langle>\<psi>\<^bold>\<rangle>" unfolding valid_def hchop_def vchop_def satisfies_def by blast lemma somewhere_and:"\<Turnstile> \<^bold>\<langle>\<phi> \<^bold>\<and> \<psi>\<^bold>\<rangle> \<^bold>\<rightarrow> \<^bold>\<langle>\<phi>\<^bold>\<rangle> \<^bold>\<and> \<^bold>\<langle>\<psi>\<^bold>\<rangle>" unfolding valid_def hchop_def vchop_def satisfies_def by blast lemma somewhere_and_or_distr :"\<Turnstile>(\<^bold>\<langle> \<chi> \<^bold>\<and> (\<phi> \<^bold>\<or> \<psi>) \<^bold>\<rangle> \<^bold>\<leftrightarrow> \<^bold>\<langle> \<chi> \<^bold>\<and> \<phi> \<^bold>\<rangle> \<^bold>\<or> \<^bold>\<langle> \<chi> \<^bold>\<and> \<psi> \<^bold>\<rangle>)" unfolding valid_def hchop_def vchop_def satisfies_def by blast lemma width_add1:"\<Turnstile>((\<^bold>\<omega> = x) \<^bold>\<smile> (\<^bold>\<omega> = y) \<^bold>\<rightarrow> \<^bold>\<omega> = x+y)" unfolding valid_def hchop_def vchop_def satisfies_def using vertical_chop_add1 by fastforce lemma width_add2:"\<Turnstile>((\<^bold>\<omega> = x+y) \<^bold>\<rightarrow> (\<^bold>\<omega> = x) \<^bold>\<smile> \<^bold>\<omega> = y)" unfolding valid_def satisfies_def vchop_def using vertical_chop_add2 by fastforce lemma width_hchop_stable: "\<Turnstile>((\<^bold>\<omega> = x) \<^bold>\<leftrightarrow> ((\<^bold>\<omega> = x) \<^bold>\<frown> (\<^bold>\<omega>=x)))" unfolding valid_def hchop_def satisfies_def using horizontal_chop1 by (metis view.horizontal_chop_width_stable) lemma length_geq_zero:"\<Turnstile> (\<^bold>\<l> \<ge> 0)" unfolding valid_def satisfies_def by (metis order.not_eq_order_implies_strict real_int.length_ge_zero) lemma length_split: "\<Turnstile>((\<^bold>\<l> > 0) \<^bold>\<rightarrow> (\<^bold>\<l> > 0) \<^bold>\<frown> (\<^bold>\<l> > 0))" unfolding valid_def hchop_def satisfies_def using horizontal_chop_non_empty by fastforce lemma length_meld: "\<Turnstile>((\<^bold>\<l> > 0) \<^bold>\<frown> (\<^bold>\<l> > 0) \<^bold>\<rightarrow> (\<^bold>\<l> > 0))" unfolding valid_def hchop_def satisfies_def using view.hchop_def real_int.chop_add_length_ge_0 by (metis (no_types, lifting)) lemma length_dense:"\<Turnstile>((\<^bold>\<l> > 0) \<^bold>\<leftrightarrow> (\<^bold>\<l> > 0) \<^bold>\<frown> (\<^bold>\<l> > 0))" unfolding valid_def satisfies_def using length_meld length_split unfolding valid_def satisfies_def by blast lemma length_add1:"\<Turnstile>((\<^bold>\<l>=x) \<^bold>\<frown> (\<^bold>\<l>= y)) \<^bold>\<rightarrow> (\<^bold>\<l>= x+y)" unfolding valid_def satisfies_def hchop_def using view.hchop_def real_int.rchop_def real_int.length_def by fastforce lemma length_add2:"\<Turnstile> (x \<^bold>\<ge> 0 \<^bold>\<and> y \<^bold>\<ge> 0) \<^bold>\<rightarrow> ( (\<^bold>\<l>=x+y) \<^bold>\<rightarrow> ((\<^bold>\<l>=x) \<^bold>\<frown> (\<^bold>\<l>=y)))" unfolding valid_def hchop_def satisfies_def using horizontal_chop_split_add by fastforce lemma length_add:"\<Turnstile> (x \<^bold>\<ge> 0 \<^bold>\<and> y \<^bold>\<ge> 0) \<^bold>\<rightarrow> ( (\<^bold>\<l>=x+y) \<^bold>\<leftrightarrow> ((\<^bold>\<l>=x) \<^bold>\<frown> (\<^bold>\<l>=y)))" unfolding valid_def satisfies_def using length_add1 length_add2 unfolding valid_def satisfies_def by blast lemma length_vchop_stable:"\<Turnstile>(\<^bold>\<l> = x) \<^bold>\<leftrightarrow> ((\<^bold>\<l> = x) \<^bold>\<smile> ( \<^bold>\<l> = x))" unfolding valid_def satisfies_def vchop_def using view.vchop_def vertical_chop1 by fastforce lemma res_ge_zero:"\<Turnstile>(re(c) \<^bold>\<rightarrow> \<^bold>\<l>>0)" unfolding valid_def satisfies_def re_def by blast lemma clm_ge_zero:"\<Turnstile>(cl(c) \<^bold>\<rightarrow> \<^bold>\<l>>0)" unfolding valid_def satisfies_def cl_def by blast lemma free_ge_zero:"\<Turnstile>free \<^bold>\<rightarrow> \<^bold>\<l>>0" unfolding valid_def satisfies_def by blast lemma width_res:"\<Turnstile>(re(c) \<^bold>\<rightarrow> \<^bold>\<omega> = 1)" unfolding valid_def satisfies_def re_def by auto lemma width_clm:"\<Turnstile>(cl(c) \<^bold>\<rightarrow> \<^bold>\<omega> = 1)" unfolding valid_def satisfies_def cl_def by simp lemma width_free:"\<Turnstile>(free \<^bold>\<rightarrow> \<^bold>\<omega> = 1)" unfolding valid_def satisfies_def by simp lemma width_somewhere_res:"\<Turnstile> \<^bold>\<langle>re(c)\<^bold>\<rangle> \<^bold>\<rightarrow> (\<^bold>\<omega> \<ge> 1)" proof - { fix ts v assume "ts,v \<Turnstile> \<^bold>\<langle>re(c)\<^bold>\<rangle>" then have "ts,v \<Turnstile> (\<^bold>\<omega> \<ge> 1)" unfolding vchop_def hchop_def using view.hchop_def view.vertical_chop_width_mon unfolding satisfies_def re_def by fastforce } from this show ?thesis unfolding valid_def by (simp add: satisfies_def) qed lemma clm_disj_res:"\<Turnstile> \<^bold>\<not> \<^bold>\<langle> cl(c) \<^bold>\<and> re(c) \<^bold>\<rangle>" proof - { fix ts v assume "ts,v \<Turnstile>\<^bold>\<langle>cl(c) \<^bold>\<and> re(c)\<^bold>\<rangle>" then obtain v' where "v' \<le> v \<and> (ts,v' \<Turnstile> cl(c) \<^bold>\<and> re(c))" unfolding satisfies_def hchop_def vchop_def by (meson view.somewhere_leq) then have False unfolding satisfies_def re_def cl_def using disjoint by (metis card_non_empty_geq_one inf.idem restriction.restriction_clm_leq_one restriction.restriction_clm_res_disjoint) } from this show ?thesis unfolding valid_def satisfies_def using satisfies_def by blast qed lemma width_ge:"\<Turnstile> (\<^bold>\<omega>> 0) \<^bold>\<rightarrow> (\<^bold>\<exists> x. (\<^bold>\<omega> = x) \<^bold>\<and> (x \<^bold>> 0))" unfolding valid_def satisfies_def using vertical_chop_add1 add_gr_0 zero_less_one using hmlsl.vchop_def hmlsl_axioms by auto lemma two_res_width: "\<Turnstile>((re(c) \<^bold>\<smile> re(c)) \<^bold>\<rightarrow> \<^bold>\<omega> = 2)" unfolding valid_def vchop_def satisfies_def re_def using view.vertical_chop_add1 by auto lemma res_at_most_two:"\<Turnstile>\<^bold>\<not> (re(c) \<^bold>\<smile> re(c) \<^bold>\<smile> re(c) )" proof - { fix ts v assume "ts, v \<Turnstile> (re(c) \<^bold>\<smile> re(c) \<^bold>\<smile> re(c) )" then obtain v' and v1 and v2 and v3 where "v = v1--v'" and "v'=v2--v3" and "ts,v1 \<Turnstile>re(c)" and "ts,v2 \<Turnstile>re(c)" and "ts,v3 \<Turnstile>re(c)" unfolding satisfies_def using vchop_def by auto then have False proof - have "|restrict v' (res ts) c| < |restrict v (res ts) c|" using \<open>ts,v1 \<Turnstile>re(c)\<close> \<open>v=v1--v'\<close> restriction.restriction_add_res unfolding satisfies_def re_def by auto then show ?thesis unfolding satisfies_def vchop_def using \<open>ts,v2 \<Turnstile> re(c)\<close> \<open>ts,v3 \<Turnstile>re(c)\<close> \<open>v'=v2--v3\<close> not_less one_add_one restriction_add_res restriction_res_leq_two unfolding satisfies_def re_def by metis qed } from this show ?thesis unfolding valid_def satisfies_def by blast qed lemma res_at_most_two2:"\<Turnstile>\<^bold>\<not> \<^bold>\<langle>re(c) \<^bold>\<smile> re(c) \<^bold>\<smile> re(c)\<^bold>\<rangle>" unfolding valid_def satisfies_def vchop_def hchop_def using res_at_most_two unfolding valid_def vchop_def satisfies_def by blast lemma res_at_most_somewhere:"\<Turnstile>\<^bold>\<not> \<^bold>\<langle>re(c)\<^bold>\<rangle> \<^bold>\<smile> \<^bold>\<langle>re(c)\<^bold>\<rangle> \<^bold>\<smile> \<^bold>\<langle>re(c)\<^bold>\<rangle> " proof - { fix ts v assume assm:"ts,v \<Turnstile> (\<^bold>\<langle>re(c)\<^bold>\<rangle> \<^bold>\<smile> \<^bold>\<langle>re(c)\<^bold>\<rangle> \<^bold>\<smile> \<^bold>\<langle>re(c)\<^bold>\<rangle> )" obtain vu and v1 and vm and vd where chops:"(v=vu--v1) \<and> (v1 = vm--vd)\<and> (ts,vu \<Turnstile>\<^bold>\<langle>re(c)\<^bold>\<rangle>) \<and> (ts,vm \<Turnstile> \<^bold>\<langle>re(c)\<^bold>\<rangle> ) \<and>( ts,vd \<Turnstile> \<^bold>\<langle> re(c)\<^bold>\<rangle>)" unfolding satisfies_def vchop_def hchop_def using assm unfolding hchop_def vchop_def satisfies_def by blast from chops have res_vu:"|restrict vu (res ts) c| \<ge> 1" unfolding satisfies_def vchop_def hchop_def re_def by (metis restriction_card_somewhere_mon) from chops have res_vm:"|restrict vm (res ts) c| \<ge> 1" unfolding satisfies_def vchop_def hchop_def re_def by (metis restriction_card_somewhere_mon) from chops have res_vd:"|restrict vd (res ts) c| \<ge> 1" unfolding satisfies_def vchop_def hchop_def re_def by (metis restriction_card_somewhere_mon) from chops have "|restrict v (res ts) c | = |restrict vu (res ts) c|+ |restrict vm (res ts) c| + |restrict vd (res ts) c| " using restriction_add_res by force with res_vu and res_vd res_vm have "|restrict v (res ts) c | \<ge> 3" by linarith with restriction_res_leq_two have False by (metis not_less_eq_eq numeral_2_eq_2 numeral_3_eq_3) } from this show ?thesis using hmlsl.valid_def hmlsl_axioms satisfies_def by auto qed (* lemma res_adj:"\<Turnstile>\<^bold>\<not> (re(c) \<^bold>\<smile> (\<^bold>\<omega> > 0) \<^bold>\<smile> re(c)) " unfolding valid_def proof (rule allI|rule notI)+ fix ts v assume "ts,v \<Turnstile> (re(c) \<^bold>\<smile> (\<^bold>\<omega> > 0) \<^bold>\<smile> re(c)) " then obtain v1 and v' and v2 and vn where chop:"(v=v1--v') \<and> (v'=vn--v2) \<and> (ts,v1\<Turnstile>re(c)) \<and> (ts,vn \<Turnstile> \<^bold>\<omega> > 0) \<and> (ts,v2\<Turnstile>re(c))" by blast hence res1:"|restrict v1 (res ts) c| \<ge> 1" by (simp add: le_numeral_extra(4)) from chop have res2: "|restrict v2 (res ts) c| \<ge> 1" by (simp add: le_numeral_extra(4)) from res1 and res2 have "|restrict v (res ts) c| \<ge> 2" using chop restriction.restriction_add_res by auto then have resv:"|restrict v (res ts) c| = 2" using dual_order.antisym restriction.restriction_res_leq_two by blast hence res_two_lanes:"|res ts c| =2" using atMostTwoRes restrict_res by (metis (no_types, lifting) nat_int.card_subset_le dual_order.antisym) from this obtain p where p_def:"Rep_nat_int (res ts c) = {p, p+1}" using consecutiveRes by force have "Abs_nat_int {p,p+1} \<sqsubseteq> lan v" by (metis Rep_nat_int_inverse atMostTwoRes card_seteq finite_atLeastAtMost insert_not_empty nat_int.card'.rep_eq nat_int.card_seq less_eq_nat_int.rep_eq p_def resv restrict_res restrict_view) have vn_not_e:"lan vn \<noteq> \<emptyset>" using chop unfolding valid_def by (metis nat_int.card_empty_zero less_irrefl width_ge) hence consec_vn_v2:"nat_int.consec (lan vn) (lan v2)" using nat_int.card_empty_zero chop nat_int.nchop_def one_neq_zero vchop_def by auto have v'_not_e:"lan v' \<noteq> \<emptyset>" using chop by (metis less_irrefl nat_int.card_empty_zero view.vertical_chop_assoc2 width_ge) hence consec_v1_v':"nat_int.consec (lan v1) (lan v')" by (metis (no_types, lifting) nat_int.card_empty_zero chop nat_int.nchop_def one_neq_zero vchop_def) hence consec_v1_vn:"nat_int.consec (lan v1) (lan vn)" by (metis (no_types, lifting) chop consec_vn_v2 nat_int.consec_def nat_int.chop_min vchop_def) hence lesser_con:"\<forall>n m. (n \<^bold>\<in> (lan v1) \<and> m \<^bold>\<in> (lan v2) \<longrightarrow> n < m)" using consec_v1_vn consec_vn_v2 nat_int.consec_trans_lesser by auto have p_in_v1:"p \<^bold>\<in> lan v1" proof (rule ccontr) assume "\<not> p \<^bold>\<in> lan v1" then have "p \<^bold>\<notin> lan v1" by (simp ) hence "p \<^bold>\<notin> restrict v1 (res ts) c" using chop by (simp add: chop ) then have "p+1 \<^bold>\<in> restrict v1 (res ts) c" proof - have "{p, p + 1} \<inter> (Rep_nat_int (res ts c) \<inter> Rep_nat_int (lan v1)) \<noteq> {}" by (metis chop Rep_nat_int_inject bot_nat_int.rep_eq consec_v1_v' inf_nat_int.rep_eq nat_int.consec_def p_def restriction.restrict_def) then have "p + 1 \<in> Rep_nat_int (lan v1)" using \<open>p \<^bold>\<notin> restrict v1 (res ts) c\<close> inf_nat_int.rep_eq not_in.rep_eq restriction.restrict_def by force then show ?thesis using chop el.rep_eq by presburger qed hence suc_p:"p+1 \<^bold>\<in> lan v1" using chop by (simp add: chop) hence "p+1 \<^bold>\<notin> lan v2" using p_def restrict_def using lesser_con nat_int.el.rep_eq nat_int.not_in.rep_eq by auto then have "p \<^bold>\<in> restrict v2 (res ts) c" proof - have f1: "minimum (lan v2) \<in> Rep_nat_int (lan v2)" using consec_vn_v2 el.rep_eq minimum_in nat_int.consec_def by simp have "lan v2 \<sqsubseteq> res ts c" by (metis (no_types) chop restriction.restrict_res) then have "minimum (lan v2) = p" using \<open>p + 1 \<^bold>\<notin> lan v2\<close> f1 less_eq_nat_int.rep_eq not_in.rep_eq p_def by auto then show ?thesis using f1 by (metis chop el.rep_eq) qed hence p:"p \<^bold>\<in> lan v2" using p_def restrict_def using chop by auto show False using lesser_con suc_p p by blast qed hence p_not_in_v2:"p \<^bold>\<notin> lan v2" using p_def restrict_def lesser_con nat_int.el.rep_eq nat_int.not_in.rep_eq by auto then have "p+1 \<^bold>\<in> restrict v2 (res ts) c" proof - have f1: "minimum (lan v2) \<^bold>\<in> lan v2" using consec_vn_v2 minimum_in nat_int.consec_def by simp obtain x where mini:"x = minimum (lan v2)" by blast have "x = p + 1" by (metis IntD1 p_not_in_v2 chop el.rep_eq f1 inf_nat_int.rep_eq insertE mini not_in.rep_eq p_def restriction.restrict_def singletonD) then show ?thesis using chop f1 mini by auto qed hence suc_p_in_v2:"p+1 \<^bold>\<in> lan v2" using p_def restrict_def using chop by auto have "\<forall>n m. (n \<^bold>\<in> (lan v1) \<and> m \<^bold>\<in> (lan vn) \<longrightarrow> n < m)" using consec_v1_vn nat_int.consec_lesser by auto with p_in_v1 have ge_p:"\<forall>m. (m \<^bold>\<in> lan vn \<longrightarrow> p < m)" by blast have "\<forall>n m. (n \<^bold>\<in> (lan vn) \<and> m \<^bold>\<in> (lan v2) \<longrightarrow> n < m)" using consec_vn_v2 nat_int.consec_lesser by auto with suc_p_in_v2 have less_suc_p:"\<forall>m. (m \<^bold>\<in> lan vn \<longrightarrow> m< p+1)" by blast have "\<forall>m. (m \<^bold>\<in> lan vn \<longrightarrow> (m< p+1 \<and> m > p) )" using ge_p less_suc_p by auto hence "\<not>(\<exists>m. (m \<^bold>\<in> lan vn))" by (metis One_nat_def Suc_leI add.right_neutral add_Suc_right linorder_not_less) hence "lan vn = \<emptyset>" using nat_int.non_empty_elem_in by auto with vn_not_e show False by blast qed *) lemma clm_sing:"\<Turnstile>\<^bold>\<not> (cl(c) \<^bold>\<smile> cl(c)) " unfolding valid_def vchop_def satisfies_def cl_def using atMostOneClm restriction_add_clm vchop_def restriction_clm_leq_one by (metis (no_types, hide_lams) add_eq_self_zero le_add1 le_antisym one_neq_zero) lemma clm_sing_somewhere:"\<Turnstile>\<^bold>\<not> \<^bold>\<langle>cl(c) \<^bold>\<smile> cl(c)\<^bold>\<rangle> " unfolding valid_def vchop_def hchop_def using clm_sing unfolding satisfies_def valid_def vchop_def hchop_def by blast lemma clm_sing_not_interrupted:"\<Turnstile> \<^bold>\<not>(cl(c) \<^bold>\<smile> \<^bold>\<top> \<^bold>\<smile> cl(c))" unfolding valid_def vchop_def satisfies_def cl_def using atMostOneClm restriction_add_clm vchop_def restriction_clm_leq_one clm_sing by (metis (no_types, hide_lams) add.commute add_eq_self_zero dual_order.antisym le_add1 one_neq_zero) lemma clm_sing_somewhere2:"\<Turnstile>\<^bold>\<not> (\<^bold>\<top> \<^bold>\<smile> cl(c) \<^bold>\<smile> \<^bold>\<top> \<^bold>\<smile> cl(c) \<^bold>\<smile> \<^bold>\<top>) " using view.vchop_def clm_sing_not_interrupted vertical_chop_assoc1 unfolding valid_def vchop_def satisfies_def by meson lemma clm_sing_somewhere3:"\<Turnstile>\<^bold>\<not> \<^bold>\<langle>(\<^bold>\<top> \<^bold>\<smile> cl(c) \<^bold>\<smile> \<^bold>\<top> \<^bold>\<smile> cl(c) \<^bold>\<smile> \<^bold>\<top>)\<^bold>\<rangle> " using clm_sing_somewhere2 unfolding valid_def satisfies_def vchop_def hchop_def by blast lemma clm_at_most_somewhere:"\<Turnstile>\<^bold>\<not> (\<^bold>\<langle>cl(c)\<^bold>\<rangle> \<^bold>\<smile> \<^bold>\<langle>cl(c)\<^bold>\<rangle>)" proof - { fix ts v assume assm:"ts,v \<Turnstile> (\<^bold>\<langle>cl(c)\<^bold>\<rangle> \<^bold>\<smile> \<^bold>\<langle>cl(c)\<^bold>\<rangle>)" obtain vu and vd where chops:"(v=vu--vd)\<and> (ts,vu \<Turnstile>\<^bold>\<langle>cl(c)\<^bold>\<rangle>) \<and> ( ts,vd \<Turnstile> \<^bold>\<langle> cl(c)\<^bold>\<rangle>)" unfolding vchop_def hchop_def satisfies_def using assm unfolding vchop_def hchop_def satisfies_def by blast from chops have clm_vu:"|restrict vu (clm ts) c| \<ge> 1" unfolding vchop_def hchop_def satisfies_def cl_def by (metis restriction_card_somewhere_mon) from chops have clm_vd:"|restrict vd (clm ts) c| \<ge> 1" unfolding vchop_def hchop_def satisfies_def cl_def by (metis restriction_card_somewhere_mon) from chops have clm_add: "|restrict v (clm ts) c | = |restrict vu (clm ts) c| + |restrict vd (clm ts) c|" using restriction_add_clm by auto with clm_vu and clm_vd have "|restrict v (clm ts) c | \<ge> 2" using add.commute add_eq_self_zero dual_order.antisym le_add1 less_one not_le restriction_res_leq_two by linarith with restriction_clm_leq_one have False by (metis One_nat_def not_less_eq_eq numeral_2_eq_2) } from this show ?thesis using hmlsl.valid_def hmlsl_axioms unfolding vchop_def hchop_def satisfies_def by fastforce qed lemma res_decompose: "\<Turnstile>(re(c) \<^bold>\<rightarrow> re(c) \<^bold>\<frown> re(c))" proof - { fix ts v assume assm:"ts,v \<Turnstile>re(c)" then obtain v1 and v2 where 1:"v=v1\<parallel>v2" and 2:"\<parallel>ext v1\<parallel> > 0" and 3:"\<parallel>ext v2\<parallel> > 0" unfolding satisfies_def re_def using view.horizontal_chop_non_empty by blast then have 4:"|lan v1| = 1" and 5:"|lan v2| = 1" using assm view.hchop_def unfolding satisfies_def re_def by auto then have 6:"ts,v1 \<Turnstile>re(c)" using assm unfolding satisfies_def hchop_def re_def by (metis 2 1 len_view_hchop_left restriction.restrict_eq_lan_subs restriction.restrict_view restriction.restriction_stable1) from 5 have 7:"ts,v2 \<Turnstile>re(c)" using assm "6" unfolding satisfies_def hchop_def re_def by (metis "1" "3" len_view_hchop_right restriction.restrict_eq_lan_subs restriction.restrict_view restriction.restriction_stable) from 1 and 6 and 7 have "ts,v \<Turnstile>re(c) \<^bold>\<frown> re(c)" unfolding satisfies_def hchop_def by blast } from this show ?thesis using hmlsl.satisfies_def hmlsl.valid_def hmlsl_axioms by auto qed lemma res_compose: "\<Turnstile>(re(c) \<^bold>\<frown> re(c) \<^bold>\<rightarrow> re(c))" unfolding valid_def hchop_def using real_int.chop_dense len_compose_hchop view.hchop_def length_dense restrict_def unfolding valid_def hchop_def satisfies_def re_def by (metis (no_types, lifting)) lemma res_dense:"\<Turnstile>re(c) \<^bold>\<leftrightarrow> re(c) \<^bold>\<frown> re(c)" using res_decompose res_compose unfolding valid_def satisfies_def by blast lemma res_continuous :"\<Turnstile>(re(c)) \<^bold>\<rightarrow> (\<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( \<^bold>\<not>re(c) \<^bold>\<and> \<^bold>\<l> > 0) \<^bold>\<frown> \<^bold>\<top>))" unfolding valid_def hchop_def satisfies_def re_def by (metis (no_types, lifting) view.hchop_def len_view_hchop_left len_view_hchop_right restrict_def) lemma no_clm_before_res:"\<Turnstile>\<^bold>\<not>(cl(c) \<^bold>\<frown> re(c))" unfolding valid_def hchop_def satisfies_def re_def cl_def by (metis (no_types, lifting) nat_int.card_empty_zero nat_int.card_subset_le disjoint view.hchop_def inf_assoc inf_le1 not_one_le_zero restrict_def) lemma no_clm_before_res2:"\<Turnstile>\<^bold>\<not> (cl(c) \<^bold>\<frown> \<^bold>\<top> \<^bold>\<frown> re(c))" unfolding valid_def hchop_def satisfies_def re_def cl_def by (metis (no_types, lifting) inf.idem nat_int.card_non_empty_geq_one restriction.restrict_def restriction.restriction_clm_leq_one restriction_clm_res_disjoint view.hchop_def) (*proof (rule allI| rule impI)+ fix ts v show "ts,v \<Turnstile> \<^bold>\<not> (cl(c) \<^bold>\<frown> \<^bold>\<top> \<^bold>\<frown> re(c))" proof (rule ccontr) assume "\<not> (ts,v \<Turnstile> \<^bold>\<not> (cl(c) \<^bold>\<frown> \<^bold>\<top> \<^bold>\<frown> re(c)))" then obtain ts and v where assm:"ts,v \<Turnstile> (cl(c) \<^bold>\<frown> \<^bold>\<top> \<^bold>\<frown> re(c))" unfolding valid_def by blast then have clm_subs:"restrict v (clm ts) c = restrict v (res ts) c" using restriction_stable by (metis (no_types, lifting) hchop_def restrict_def) have "restrict v (clm ts )c \<noteq> \<emptyset>" using assm nat_int.card_non_empty_geq_one restriction_stable1 by auto then have res_in_neq:"restrict v (clm ts) c \<sqinter> restrict v (res ts) c \<noteq>\<emptyset>" using clm_subs inf_absorb1 by (simp ) then show False using valid_def restriction_clm_res_disjoint by (metis inf_commute restriction.restriction_clm_res_disjoint) qed qed *) lemma clm_decompose: "\<Turnstile>(cl(c) \<^bold>\<rightarrow> cl(c) \<^bold>\<frown> cl(c))" proof - { fix ts v assume assm: "ts,v \<Turnstile> cl(c)" have restr:"restrict v (clm ts) c = lan v" using assm unfolding satisfies_def cl_def by simp have len_ge_zero:"\<parallel>len v ts c\<parallel> > 0" using assm unfolding satisfies_def cl_def by simp have len:"len v ts c = ext v" using assm unfolding satisfies_def cl_def by simp obtain v1 v2 where chop:"(v=v1\<parallel>v2) \<and> \<parallel>ext v1\<parallel> > 0 \<and> \<parallel>ext v2\<parallel> > 0 " using assm view.horizontal_chop_non_empty using length_split unfolding hchop_def satisfies_def cl_def by blast from chop and len have len_v1:"len v1 ts c = ext v1" using len_view_hchop_left by blast from chop and len have len_v2:"len v2 ts c = ext v2" using len_view_hchop_right by blast from chop and restr have restr_v1:"restrict v1 (clm ts) c = lan v1" by (metis (no_types, lifting) view.hchop_def restriction.restriction_stable1) from chop and restr have restr_v2:"restrict v2 (clm ts) c = lan v2" by (metis (no_types, lifting) view.hchop_def restriction.restriction_stable2) from chop and len_v1 len_v2 restr_v1 restr_v2 have "ts,v \<Turnstile>cl(c) \<^bold>\<frown> cl(c)" using view.hchop_def assm unfolding satisfies_def hchop_def cl_def by force } from this show ?thesis unfolding valid_def satisfies_def using hmlsl.satisfies_def hmlsl_axioms by blast qed lemma clm_compose: "\<Turnstile>(cl(c) \<^bold>\<frown> cl(c) \<^bold>\<rightarrow> cl(c))" using real_int.chop_dense len_compose_hchop view.hchop_def length_dense restrict_def unfolding valid_def hchop_def satisfies_def cl_def by (metis (no_types, lifting)) lemma clm_dense:"\<Turnstile>cl(c) \<^bold>\<leftrightarrow> cl(c) \<^bold>\<frown> cl(c)" using clm_decompose clm_compose unfolding valid_def satisfies_def by blast lemma clm_continuous :"\<Turnstile>(cl(c)) \<^bold>\<rightarrow> (\<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( \<^bold>\<not>cl(c) \<^bold>\<and> \<^bold>\<l> > 0) \<^bold>\<frown> \<^bold>\<top>))" unfolding valid_def hchop_def satisfies_def cl_def by (metis (no_types, lifting) view.hchop_def len_view_hchop_left len_view_hchop_right restrict_def) lemma res_not_free: "\<Turnstile>(\<^bold>\<exists> c. re(c) \<^bold>\<rightarrow> \<^bold>\<not>free)" unfolding valid_def satisfies_def using nat_int.card_empty_zero one_neq_zero re_def by auto lemma clm_not_free: "\<Turnstile>(\<^bold>\<exists> c. cl(c) \<^bold>\<rightarrow> \<^bold>\<not>free)" unfolding valid_def satisfies_def using nat_int.card_empty_zero cl_def by auto lemma free_no_res:"\<Turnstile>(free \<^bold>\<rightarrow> \<^bold>\<not>(\<^bold>\<exists> c. re(c)))" unfolding valid_def satisfies_def re_def using nat_int.card_empty_zero one_neq_zero by (metis less_irrefl) lemma free_no_clm:"\<Turnstile>(free \<^bold>\<rightarrow> \<^bold>\<not>(\<^bold>\<exists> c. cl(c)))" unfolding valid_def satisfies_def cl_def using nat_int.card_empty_zero one_neq_zero by (metis less_irrefl) lemma free_decompose:"\<Turnstile>free \<^bold>\<rightarrow> ( free \<^bold>\<frown> free)" proof - { fix ts v assume assm:"ts,v \<Turnstile>free" obtain v1 and v2 where non_empty_v1_v2:"(v=v1\<parallel>v2) \<and> \<parallel>ext v1\<parallel> > 0 \<and> \<parallel>ext v2\<parallel> > 0" unfolding valid_def using assm length_dense unfolding valid_def satisfies_def hchop_def by blast have one_lane:"|lan v1| = 1 \<and> |lan v2| = 1" using assm view.hchop_def non_empty_v1_v2 unfolding satisfies_def hchop_def by auto have nothing_on_v1: " (\<forall>c. \<parallel>len v1 ts c\<parallel> = 0 \<or> (restrict v1 (clm ts) c = \<emptyset> \<and> restrict v1 (res ts) c = \<emptyset>))" using assm unfolding satisfies_def by (metis (no_types, lifting) len_empty_on_subview1 non_empty_v1_v2 restriction_stable1) have nothing_on_v2: " (\<forall>c. \<parallel>len v2 ts c\<parallel> = 0 \<or> (restrict v2 (clm ts) c = \<emptyset> \<and> restrict v2 (res ts) c = \<emptyset>))" using assm unfolding satisfies_def by (metis (no_types, lifting) len_empty_on_subview2 non_empty_v1_v2 restriction_stable2) have "(v=v1\<parallel>v2) \<and> 0 < \<parallel>ext v1\<parallel> \<and> |lan v1| = 1 \<and> (\<forall>c. \<parallel>len v1 ts c\<parallel> = 0 \<or>( restrict v1 (clm ts) c = \<emptyset> \<and> restrict v1 (res ts) c = \<emptyset>)) \<and> 0 < \<parallel>ext v2\<parallel> \<and> |lan v2| = 1 \<and> (\<forall>c. \<parallel>len v2 ts c\<parallel> = 0 \<or>( restrict v2 (clm ts) c = \<emptyset> \<and> restrict v2 (res ts) c = \<emptyset>))" using non_empty_v1_v2 nothing_on_v1 nothing_on_v2 one_lane by blast then have "ts,v \<Turnstile>(free \<^bold>\<frown> free)" unfolding satisfies_def hchop_def by blast } from this show ?thesis unfolding valid_def by (simp add: satisfies_def) qed lemma free_compose:"\<Turnstile>(free \<^bold>\<frown> free) \<^bold>\<rightarrow> free" proof - { fix ts v assume assm:"ts,v \<Turnstile>free \<^bold>\<frown> free" have len_ge_0:"\<parallel>ext v\<parallel> > 0" unfolding valid_def using assm length_meld unfolding valid_def satisfies_def hchop_def by blast have widt_one:"|lan v| = 1" using assm unfolding satisfies_def hchop_def by (metis horizontal_chop_width_stable) have no_car: "(\<forall>c. \<parallel>len v ts c\<parallel> = 0 \<or> restrict v (clm ts) c = \<emptyset> \<and> restrict v (res ts) c = \<emptyset>)" proof (rule ccontr) assume "\<not>(\<forall>c. \<parallel>len v ts c\<parallel> = 0 \<or> (restrict v (clm ts) c = \<emptyset> \<and> restrict v (res ts) c = \<emptyset>))" then obtain c where ex: "\<parallel>len v ts c\<parallel> \<noteq> 0 \<and> (restrict v (clm ts) c \<noteq> \<emptyset> \<or> restrict v (res ts) c \<noteq> \<emptyset>)" by blast from ex have 1:"\<parallel>len v ts c\<parallel> > 0" using less_eq_real_def real_int.length_ge_zero by auto have "(restrict v (clm ts) c \<noteq> \<emptyset> \<or> restrict v (res ts) c \<noteq> \<emptyset>)" using ex .. then show False proof assume "restrict v (clm ts) c \<noteq> \<emptyset>" then show False using assm unfolding satisfies_def hchop_def by (metis (no_types, hide_lams) add.left_neutral ex len_hchop_add restriction.restrict_def view.hchop_def) next assume "restrict v (res ts) c \<noteq> \<emptyset>" then show False using assm unfolding satisfies_def hchop_def by (metis (no_types, hide_lams) add.left_neutral ex len_hchop_add restriction.restrict_def view.hchop_def) qed qed have "ts,v \<Turnstile>free" using len_ge_0 widt_one no_car unfolding satisfies_def by blast } from this show ?thesis unfolding valid_def satisfies_def by blast qed lemma free_dense:"\<Turnstile>free \<^bold>\<leftrightarrow> (free \<^bold>\<frown> free)" using free_decompose free_compose unfolding valid_def satisfies_def by blast lemma free_dense2:"\<Turnstile>free \<^bold>\<rightarrow> \<^bold>\<top> \<^bold>\<frown> free \<^bold>\<frown> \<^bold>\<top>" unfolding valid_def hchop_def satisfies_def using horizontal_chop_empty_left horizontal_chop_empty_right by fastforce text \<open> The next lemmas show the connection between the spatial. In particular, if the view consists of one lane and a non-zero extension, where neither a reservation nor a car resides, the view satisfies free (and vice versa). \<close> (* lemma no_cars_means_free: "\<Turnstile>((\<^bold>\<l>>0) \<^bold>\<and> (\<^bold>\<omega> = 1) \<^bold>\<and> (\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>))) \<^bold>\<rightarrow> free" proof - { fix ts v assume assm: "ts,v \<Turnstile> ((\<^bold>\<l>>0) \<^bold>\<and> (\<^bold>\<omega> = 1) \<^bold>\<and> (\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)))" have ge_0:"ts,v \<Turnstile> \<^bold>\<l> > 0" using assm unfolding satisfies_def by best have one_lane:"ts,v \<Turnstile>\<^bold>\<omega> = 1" using assm unfolding satisfies_def by best have "ts,v \<Turnstile> free" unfolding satisfies_def proof (rule ccontr) have no_car: "ts,v \<Turnstile>\<^bold>\<not>( \<^bold>\<exists> c. (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>))" using assm unfolding satisfies_def by best assume "ts,v \<Turnstile> \<^bold>\<not> free" hence contra: "\<not>(\<forall>c. \<parallel>len v ts c\<parallel> = 0 \<or> restrict v (clm ts) c = \<emptyset> \<and> restrict v (res ts) c = \<emptyset>)" using ge_0 one_lane unfolding satisfies_def by blast hence ex_car: "\<exists>c. \<parallel>len v ts c\<parallel> > 0 \<and> (restrict v (clm ts) c \<noteq> \<emptyset> \<or> restrict v (res ts) c \<noteq> \<emptyset>)" using real_int.length_ge_zero dual_order.antisym not_le by metis obtain c where c_def: "\<parallel>len v ts c\<parallel> > 0 \<and> (restrict v (clm ts) c \<noteq> \<emptyset> \<or> restrict v (res ts) c \<noteq> \<emptyset>)" using ex_car by blast hence "(restrict v (clm ts) c \<noteq> \<emptyset> \<or> restrict v (res ts) c \<noteq> \<emptyset>)" by best thus False proof assume "restrict v (clm ts) c \<noteq> \<emptyset>" with one_lane have clm_one:"|restrict v (clm ts) c| = 1" using el_in_restriction_clm_singleton by (metis card_non_empty_geq_one dual_order.antisym restriction.restriction_clm_leq_one) obtain v1 and v2 and v3 and v4 where "v=v1\<parallel>v2" and "v2=v3\<parallel>v4" and len_eq:"len v3 ts c = ext v3 \<and> \<parallel>len v3 ts c\<parallel> = \<parallel>len v ts c\<parallel> " using horizontal_chop_empty_left horizontal_chop_empty_right len_fills_subview c_def by blast then have res_non_empty:"restrict v3 (clm ts) c \<noteq> \<emptyset>" using \<open>restrict v (clm ts) c \<noteq> \<emptyset>\<close> restriction_stable restriction_stable1 by auto have len_non_empty:"\<parallel>len v3 ts c\<parallel> > 0" using len_eq c_def by auto have "|restrict v3 (clm ts) c| =1 " using \<open>v2=v3\<parallel>v4\<close> \<open>v=v1\<parallel>v2\<close> clm_one restriction_stable restriction_stable1 by auto have v3_one_lane:"|lan v3| = 1" using \<open>v2=v3\<parallel>v4\<close> \<open>v=v1\<parallel>v2\<close> hchop_def one_lane by auto have clm_fills_v3:"restrict v3 (clm ts) c = lan v3" proof (rule ccontr) assume aux:"restrict v3 (clm ts) c \<noteq> lan v3" have "restrict v3 (clm ts) c \<sqsubseteq> lan v3" by (simp add: restrict_view) hence "\<exists>n. n \<^bold>\<notin> restrict v3 (clm ts) c \<and> n \<^bold>\<in> lan v3" using aux \<open>|restrict v3 (clm ts) c| = 1\<close> restriction.restrict_eq_lan_subs v3_one_lane by auto hence "|lan v3| > 1" using \<open>| (restrict v3 (clm ts) c)| = 1\<close> \<open>restrict v3 (clm ts) c \<le> lan v3\<close> aux restriction.restrict_eq_lan_subs v3_one_lane by auto thus False using v3_one_lane by auto qed have "\<parallel>ext v3\<parallel> > 0" using c_def len_eq by auto have "ts, v3 \<Turnstile> cl(c)" using clm_one len_eq c_def clm_fills_v3 v3_one_lane by auto hence "ts,v \<Turnstile> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)" using \<open>v2=v3\<parallel>v4\<close> \<open>v=v1\<parallel>v2\<close> by blast hence "ts,v \<Turnstile>\<^bold>\<exists> c. (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)" by blast thus False using no_car by best next assume "restrict v (res ts) c \<noteq> \<emptyset>" with one_lane have clm_one:"|restrict v (res ts) c| = 1" using el_in_restriction_clm_singleton by (metis nat_int.card_non_empty_geq_one nat_int.card_subset_le dual_order.antisym restrict_view) obtain v1 and v2 and v3 and v4 where "v=v1\<parallel>v2" and "v2=v3\<parallel>v4" and len_eq:"len v3 ts c = ext v3 \<and> \<parallel>len v3 ts c\<parallel> = \<parallel>len v ts c\<parallel> " using horizontal_chop_empty_left horizontal_chop_empty_right len_fills_subview c_def by blast then have res_non_empty:"restrict v3 (res ts) c \<noteq> \<emptyset>" using \<open>restrict v (res ts) c \<noteq> \<emptyset>\<close> restriction_stable restriction_stable1 by auto have len_non_empty:"\<parallel>len v3 ts c\<parallel> > 0" using len_eq c_def by auto have "|restrict v3 (res ts) c| =1 " using \<open>v2=v3\<parallel>v4\<close> \<open>v=v1\<parallel>v2\<close> clm_one restriction_stable restriction_stable1 by auto have v3_one_lane:"|lan v3| = 1" using \<open>v2=v3\<parallel>v4\<close> \<open>v=v1\<parallel>v2\<close> hchop_def one_lane by auto have "restrict v3 (res ts) c = lan v3" proof (rule ccontr) assume aux:"restrict v3 (res ts) c \<noteq> lan v3" have "restrict v3 (res ts) c \<sqsubseteq> lan v3" by (simp add: restrict_view) hence "\<exists>n. n \<^bold>\<notin> restrict v3 (res ts) c \<and> n \<^bold>\<in> lan v3" using aux \<open>|restrict v3 (res ts) c| = 1\<close> restriction.restrict_eq_lan_subs v3_one_lane by auto hence "|lan v3| > 1" using \<open>| (restrict v3 (res ts) c)| = 1\<close> \<open>restrict v3 (res ts) c \<le> lan v3\<close> aux restriction.restrict_eq_lan_subs v3_one_lane by auto thus False using v3_one_lane by auto qed have "\<parallel>ext v3\<parallel> > 0" using c_def len_eq by auto have "ts, v3 \<Turnstile> re(c)" using clm_one len_eq c_def \<open>restrict v3 (res ts) c = lan v3\<close> v3_one_lane by auto hence "ts,v \<Turnstile> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)" using \<open>v2=v3\<parallel>v4\<close> \<open>v=v1\<parallel>v2\<close> by blast hence "ts,v \<Turnstile>\<^bold>\<exists> c. (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)" by blast thus False using no_car by best qed qed qed lemma free_means_no_cars: "\<Turnstile>free \<^bold>\<rightarrow> ((\<^bold>\<l>>0) \<^bold>\<and> (\<^bold>\<omega> = 1) \<^bold>\<and> (\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)))" unfolding valid_def proof (rule allI | rule impI)+ fix ts v assume assm:"ts,v \<Turnstile> free" have no_car:"ts,v \<Turnstile>(\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>))" proof (rule ccontr) assume "\<not> (ts,v \<Turnstile>(\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)))" hence contra:"ts,v \<Turnstile> \<^bold>\<exists> c. \<^bold>\<top> \<^bold>\<frown> (cl(c) \<^bold>\<or> re(c)) \<^bold>\<frown> \<^bold>\<top>" by blast from this obtain c and v1 and v' and v2 and vc where vc_def:"(v=v1\<parallel>v') \<and> (v'=vc\<parallel>v2) \<and> (ts,vc \<Turnstile> cl(c) \<^bold>\<or> re(c))" by blast hence len_ge_zero:"\<parallel>len v ts c\<parallel> > 0" by (metis len_empty_on_subview1 len_empty_on_subview2 less_eq_real_def real_int.length_ge_zero) from vc_def have vc_ex_car: "restrict vc (clm ts) c \<noteq> \<emptyset> \<or> restrict vc (res ts) c \<noteq>\<emptyset>" using nat_int.card_empty_zero one_neq_zero by auto have eq_lan:"lan v = lan vc" using vc_def hchop_def by auto hence v_ex_car:"restrict v (clm ts) c \<noteq> \<emptyset> \<or> restrict v (res ts) c \<noteq>\<emptyset>" using vc_ex_car by (simp add: restrict_def) from len_ge_zero and v_ex_car and assm show False by force qed with assm show "ts,v \<Turnstile>((\<^bold>\<l>>0) \<^bold>\<and> (\<^bold>\<omega> = 1) \<^bold>\<and> (\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)))" by blast qed lemma free_eq_no_cars: "\<Turnstile>free \<^bold>\<leftrightarrow> ((\<^bold>\<l>>0) \<^bold>\<and> (\<^bold>\<omega> = 1) \<^bold>\<and> (\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)))" unfolding valid_def using no_cars_means_free free_means_no_cars unfolding valid_def by blast lemma free_nowhere_res:"\<Turnstile>free \<^bold>\<rightarrow> \<^bold>\<not>(\<^bold>\<top> \<^bold>\<frown> (re(c)) \<^bold>\<frown> \<^bold>\<top>)" unfolding valid_def using free_eq_no_cars unfolding valid_def by blast lemma two_res_not_res: "\<Turnstile>((re(c) \<^bold>\<smile> re(c)) \<^bold>\<rightarrow> \<^bold>\<not>re(c))" unfolding valid_def using view.vertical_chop_singleton by fastforce lemma two_clm_width: "\<Turnstile>((cl(c) \<^bold>\<smile> cl(c)) \<^bold>\<rightarrow> \<^bold>\<omega> = 2)" unfolding valid_def using view.vertical_chop_add1 by auto lemma two_res_no_car: "\<Turnstile>(re(c) \<^bold>\<smile> re(c)) \<^bold>\<rightarrow> \<^bold>\<not>(\<^bold>\<exists> c. ( cl(c) \<^bold>\<or> re(c)) )" unfolding valid_def sledgehammer using view.vertical_chop_singleton by force lemma two_lanes_no_car:"\<Turnstile>(\<^bold>\<not> \<^bold>\<omega>= 1) \<^bold>\<rightarrow> \<^bold>\<not>(\<^bold>\<exists> c.(cl(c) \<^bold>\<or> re(c)))" unfolding valid_def by simp lemma empty_no_car:"\<Turnstile>( \<^bold>\<l> = 0) \<^bold>\<rightarrow> \<^bold>\<not>(\<^bold>\<exists> c.(cl(c) \<^bold>\<or> re(c)))" unfolding valid_def by simp lemma car_one_lane_non_empty: "\<Turnstile>(\<^bold>\<exists> c.(cl(c) \<^bold>\<or> re(c))) \<^bold>\<rightarrow> ((\<^bold>\<omega> =1) \<^bold>\<and> (\<^bold>\<l> > 0))" unfolding valid_def by blast lemma one_lane_notfree: "\<Turnstile>(\<^bold>\<omega> =1) \<^bold>\<and>(\<^bold>\<l>> 0) \<^bold>\<and> (\<^bold>\<not> free) \<^bold>\<rightarrow> ( (\<^bold>\<top> \<^bold>\<frown> (\<^bold>\<exists> c. (re(c) \<^bold>\<or> cl(c))) \<^bold>\<frown> \<^bold>\<top> ))" unfolding valid_def proof (rule allI|rule impI)+ fix ts v assume assm:"ts,v \<Turnstile>(\<^bold>\<omega> =1) \<^bold>\<and>(\<^bold>\<l>> 0) \<^bold>\<and> (\<^bold>\<not> free)" hence not_free:"ts,v \<Turnstile>\<^bold>\<not> free" by blast with free_eq_no_cars have "ts,v \<Turnstile>\<^bold>\<not> ((\<^bold>\<l>>0) \<^bold>\<and> (\<^bold>\<omega> = 1) \<^bold>\<and> (\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>)))" unfolding valid_def by blast hence "ts,v \<Turnstile> \<^bold>\<not> (\<^bold>\<forall>c. \<^bold>\<not> (\<^bold>\<top> \<^bold>\<frown> ( cl(c) \<^bold>\<or> re(c) ) \<^bold>\<frown> \<^bold>\<top>))" using assm by blast thus "ts,v \<Turnstile>(\<^bold>\<top> \<^bold>\<frown> (\<^bold>\<exists> c. (re(c) \<^bold>\<or> cl(c))) \<^bold>\<frown> \<^bold>\<top> )" by blast qed lemma one_lane_empty_or_car: "\<Turnstile>(\<^bold>\<omega> =1) \<^bold>\<and>(\<^bold>\<l>> 0) \<^bold>\<rightarrow> (free \<^bold>\<or> (\<^bold>\<top> \<^bold>\<frown> (\<^bold>\<exists> c. (re(c) \<^bold>\<or> cl(c))) \<^bold>\<frown> \<^bold>\<top> ))" unfolding valid_def using one_lane_notfree unfolding valid_def by blast end *) lemma valid_imp_sat: \<open>\<Turnstile> \<phi> \<Longrightarrow> ts,v \<Turnstile> \<phi>\<close> by (simp add: valid_def) end end
[STATEMENT] lemma subspace_image: assumes S: "m1.subspace S" shows "m2.subspace (f ` S)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. m2.subspace (f ` S) [PROOF STEP] unfolding m2.subspace_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. (0::'c) \<in> f ` S \<and> (\<forall>x\<in>f ` S. \<forall>y\<in>f ` S. x + y \<in> f ` S) \<and> (\<forall>c. \<forall>x\<in>f ` S. c *b x \<in> f ` S) [PROOF STEP] proof safe [PROOF STATE] proof (state) goal (3 subgoals): 1. (0::'c) \<in> f ` S 2. \<And>x xa y xb. \<lbrakk>xa \<in> S; xb \<in> S\<rbrakk> \<Longrightarrow> f xa + f xb \<in> f ` S 3. \<And>c x xa. xa \<in> S \<Longrightarrow> c *b f xa \<in> f ` S [PROOF STEP] show "0 \<in> f ` S" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (0::'c) \<in> f ` S [PROOF STEP] by (rule image_eqI[of _ _ 0]) (auto simp: S m1.subspace_0) [PROOF STATE] proof (state) this: (0::'c) \<in> f ` S goal (2 subgoals): 1. \<And>x xa y xb. \<lbrakk>xa \<in> S; xb \<in> S\<rbrakk> \<Longrightarrow> f xa + f xb \<in> f ` S 2. \<And>c x xa. xa \<in> S \<Longrightarrow> c *b f xa \<in> f ` S [PROOF STEP] show "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f x + f y \<in> f ` S" for x y [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>x \<in> S; y \<in> S\<rbrakk> \<Longrightarrow> f x + f y \<in> f ` S [PROOF STEP] by (rule image_eqI[of _ _ "x + y"]) (auto simp: S m1.subspace_add add) [PROOF STATE] proof (state) this: \<lbrakk>?x \<in> S; ?y \<in> S\<rbrakk> \<Longrightarrow> f ?x + f ?y \<in> f ` S goal (1 subgoal): 1. \<And>c x xa. xa \<in> S \<Longrightarrow> c *b f xa \<in> f ` S [PROOF STEP] show "x \<in> S \<Longrightarrow> r *b f x \<in> f ` S" for r x [PROOF STATE] proof (prove) goal (1 subgoal): 1. x \<in> S \<Longrightarrow> r *b f x \<in> f ` S [PROOF STEP] by (rule image_eqI[of _ _ "r *a x"]) (auto simp: S m1.subspace_scale scale) [PROOF STATE] proof (state) this: ?x \<in> S \<Longrightarrow> ?r *b f ?x \<in> f ` S goal: No subgoals! [PROOF STEP] qed
[STATEMENT] lemma orbit_step: assumes "y \<in> orbit f x" "f x \<noteq> y" shows "y \<in> orbit f (f x)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. y \<in> orbit f (f x) [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: y \<in> orbit f x f x \<noteq> y goal (1 subgoal): 1. y \<in> orbit f (f x) [PROOF STEP] proof induction [PROOF STATE] proof (state) goal (2 subgoals): 1. f x \<noteq> f x \<Longrightarrow> f x \<in> orbit f (f x) 2. \<And>y. \<lbrakk>y \<in> orbit f x; f x \<noteq> y \<Longrightarrow> y \<in> orbit f (f x); f x \<noteq> f y\<rbrakk> \<Longrightarrow> f y \<in> orbit f (f x) [PROOF STEP] case (step y) [PROOF STATE] proof (state) this: y \<in> orbit f x f x \<noteq> y \<Longrightarrow> y \<in> orbit f (f x) f x \<noteq> f y goal (2 subgoals): 1. f x \<noteq> f x \<Longrightarrow> f x \<in> orbit f (f x) 2. \<And>y. \<lbrakk>y \<in> orbit f x; f x \<noteq> y \<Longrightarrow> y \<in> orbit f (f x); f x \<noteq> f y\<rbrakk> \<Longrightarrow> f y \<in> orbit f (f x) [PROOF STEP] then [PROOF STATE] proof (chain) picking this: y \<in> orbit f x f x \<noteq> y \<Longrightarrow> y \<in> orbit f (f x) f x \<noteq> f y [PROOF STEP] show ?case [PROOF STATE] proof (prove) using this: y \<in> orbit f x f x \<noteq> y \<Longrightarrow> y \<in> orbit f (f x) f x \<noteq> f y goal (1 subgoal): 1. f y \<in> orbit f (f x) [PROOF STEP] by (cases "x = y") (auto intro: orbit.intros) [PROOF STATE] proof (state) this: f y \<in> orbit f (f x) goal (1 subgoal): 1. f x \<noteq> f x \<Longrightarrow> f x \<in> orbit f (f x) [PROOF STEP] qed simp
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.algebra.pointwise import Mathlib.order.filter.basic import Mathlib.PostPort universes u v namespace Mathlib /-! # Pointwise operations on filters. The pointwise operations on filters have nice properties, such as • `map m (f₁ * f₂) = map m f₁ * map m f₂` • `𝓝 x * 𝓝 y = 𝓝 (x * y)` -/ namespace filter protected instance has_one {α : Type u} [HasOne α] : HasOne (filter α) := { one := principal 1 } @[simp] theorem mem_zero {α : Type u} [HasZero α] (s : set α) : s ∈ 0 ↔ 0 ∈ s := sorry protected instance has_mul {α : Type u} [monoid α] : Mul (filter α) := { mul := fun (f g : filter α) => mk (set_of fun (s : set α) => ∃ (t₁ : set α), ∃ (t₂ : set α), t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ * t₂ ⊆ s) sorry sorry sorry } theorem mem_add {α : Type u} [add_monoid α] {f : filter α} {g : filter α} {s : set α} : s ∈ f + g ↔ ∃ (t₁ : set α), ∃ (t₂ : set α), t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ + t₂ ⊆ s := iff.rfl theorem mul_mem_mul {α : Type u} [monoid α] {f : filter α} {g : filter α} {s : set α} {t : set α} (hs : s ∈ f) (ht : t ∈ g) : s * t ∈ f * g := Exists.intro s (Exists.intro t { left := hs, right := { left := ht, right := set.subset.refl (s * t) } }) protected theorem mul_le_mul {α : Type u} [monoid α] {f₁ : filter α} {f₂ : filter α} {g₁ : filter α} {g₂ : filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁ * g₁ ≤ f₂ * g₂ := sorry theorem ne_bot.add {α : Type u} [add_monoid α] {f : filter α} {g : filter α} : ne_bot f → ne_bot g → ne_bot (f + g) := sorry protected theorem add_assoc {α : Type u} [add_monoid α] (f : filter α) (g : filter α) (h : filter α) : f + g + h = f + (g + h) := sorry protected theorem one_mul {α : Type u} [monoid α] (f : filter α) : 1 * f = f := sorry protected theorem add_zero {α : Type u} [add_monoid α] (f : filter α) : f + 0 = f := sorry protected instance monoid {α : Type u} [monoid α] : monoid (filter α) := monoid.mk Mul.mul filter.mul_assoc 1 filter.one_mul filter.mul_one protected theorem map_add {α : Type u} {β : Type v} [add_monoid α] [add_monoid β] (m : α → β) [is_add_hom m] {f₁ : filter α} {f₂ : filter α} : map m (f₁ + f₂) = map m f₁ + map m f₂ := sorry protected theorem map_one {α : Type u} {β : Type v} [monoid α] [monoid β] (m : α → β) [is_monoid_hom m] : map m 1 = 1 := sorry -- TODO: prove similar statements when `m` is group homomorphism etc. theorem Mathlib.map.is_add_monoid_hom {α : Type u} {β : Type v} [add_monoid α] [add_monoid β] (m : α → β) [is_add_monoid_hom m] : is_add_monoid_hom (map m) := is_add_monoid_hom.mk (filter.map_zero m) -- The other direction does not hold in general. theorem comap_mul_comap_le {α : Type u} {β : Type v} [monoid α] [monoid β] (m : α → β) [is_mul_hom m] {f₁ : filter β} {f₂ : filter β} : comap m f₁ * comap m f₂ ≤ comap m (f₁ * f₂) := sorry theorem tendsto.mul_mul {α : Type u} {β : Type v} [monoid α] [monoid β] {m : α → β} [is_mul_hom m] {f₁ : filter α} {g₁ : filter α} {f₂ : filter β} {g₂ : filter β} : tendsto m f₁ f₂ → tendsto m g₁ g₂ → tendsto m (f₁ * g₁) (f₂ * g₂) := fun (hf : tendsto m f₁ f₂) (hg : tendsto m g₁ g₂) => eq.mpr (id (Eq._oldrec (Eq.refl (tendsto m (f₁ * g₁) (f₂ * g₂))) (tendsto.equations._eqn_1 m (f₁ * g₁) (f₂ * g₂)))) (eq.mpr (id (Eq._oldrec (Eq.refl (map m (f₁ * g₁) ≤ f₂ * g₂)) (filter.map_mul m))) (filter.mul_le_mul hf hg))
func $cvtu64tof64 ( var %i u64 ) f64 { return ( cvt f64 u64(dread u64 %i))} # EXEC: %irbuild Main.mpl # EXEC: %irbuild Main.irb.mpl # EXEC: %cmp Main.irb.mpl Main.irb.irb.mpl
module Main import Effects import Effect.State import Effect.Exception import Effect.Random import Effect.StdIO data Expr = Var String | Val Integer | Add Expr Expr | Random Integer Env : Type Env = List (String, Integer) -- Evaluator : Type -> Type -- Evaluator t -- = Eff m [EXCEPTION String, RND, STATE Env] t eval : Expr -> Eff Integer [EXCEPTION String, STDIO, RND, STATE Env] eval (Var x) = do vs <- get case lookup x vs of Nothing => raise ("No such variable " ++ x) Just val => pure val eval (Val x) = pure x eval (Add l r) = [| eval l + eval r |] eval (Random upper) = do val <- rndInt 0 upper putStrLn (show val) pure val testExpr : Expr testExpr = Add (Add (Var "foo") (Val 42)) (Random 100) runEval : List (String, Integer) -> Expr -> IO Integer runEval args expr = runInit [(), (), 123456, args] (eval expr) main : IO () main = do let x = 42 val <- runEval [("foo", x)] testExpr putStrLn $ "Answer: " ++ show val
%default total data Format = Number Format | Str Format | FChar Format | FDouble Format | Lit String Format | End %name Format f PrintfType : Format -> Type PrintfType (Number f) = Int -> PrintfType f PrintfType (Str f) = String -> PrintfType f PrintfType (FChar f) = Char -> PrintfType f PrintfType (FDouble f) = Double -> PrintfType f PrintfType (Lit str f) = PrintfType f PrintfType End = String parseFormatString : List Char -> Format parseFormatString [] = End parseFormatString ('%' :: 'd' :: xs) = Number $ parseFormatString xs parseFormatString ('%' :: 's' :: xs) = Str $ parseFormatString xs parseFormatString ('%' :: 'c' :: xs) = FChar $ parseFormatString xs parseFormatString ('%' :: 'f' :: xs) = FDouble $ parseFormatString xs parseFormatString (x :: xs) = case parseFormatString xs of (Lit str f) => Lit (strCons x str) f format => Lit (cast x) format printFormat : (f : Format) -> (acc : String) -> PrintfType f printFormat (Number f) acc = \i => printFormat f (acc ++ show i ) printFormat (Str f) acc = \str => printFormat f (acc ++ str ) printFormat (FDouble f) acc = \double => printFormat f (acc ++ show double) printFormat (FChar f) acc = \c => printFormat f (acc ++ cast c ) printFormat (Lit str f) acc = printFormat f (acc ++ str ) printFormat End acc = acc printf : (s : String) -> PrintfType (parseFormatString $ unpack s) printf s with (parseFormatString $ unpack s) printf s | format = printFormat format "" TupleVect : Nat -> Type -> Type TupleVect Z x = () TupleVect (S k) x = (x, TupleVect k x) test : TupleVect 4 Nat test = (1,2,3,4,())
function this = plot(this, module, varargin) % Plots different aspects of MrSeries using MrImage-plot functions % % Y = MrSeries() % Y.plot(inputs) % % This is a method of class MrSeries. % % IN % % OUT % % EXAMPLE % plot % % See also MrSeries % Author: Saskia Klein & Lars Kasper % Created: 2014-07-08 % Copyright (C) 2014 Institute for Biomedical Engineering % University of Zurich and ETH Zurich % % This file is part of the TAPAS UniQC Toolbox, which is released % under the terms of the GNU General Public Licence (GPL), version 3. % You can redistribute it and/or modify it under the terms of the GPL % (either version 3 or, at your option, any later version). % For further details, see the file COPYING or % <http://www.gnu.org/licenses/>. if ~exist('module', 'var') module = 'data'; end switch module case {'data', 'mean', 'sd', 'snr', 'coeffVar', 'diffLastFirst'} this.(module).plot(varargin{:}); otherwise error('tapas:uniqc:MrSeries:InvalidPlotModule', ... 'plotting module %s not implemented for MrSeries', ... module); end
Formal statement is: lemma vimage_algebra_sigma: assumes X: "X \<subseteq> Pow \<Omega>'" and f: "f \<in> \<Omega> \<rightarrow> \<Omega>'" shows "vimage_algebra \<Omega> f (sigma \<Omega>' X) = sigma \<Omega> {f -` A \<inter> \<Omega> | A. A \<in> X }" (is "?V = ?S") Informal statement is: If $f$ is a function from $\Omega$ to $\Omega'$, then the preimage of a $\sigma$-algebra on $\Omega'$ is a $\sigma$-algebra on $\Omega$.
%access public export Int32 : Type Int32 = Bits32 Int64 : Type Int64 = Bits64 Bytes : Type Bytes = String
(* Title: HOL/Corec_Examples/LFilter.thy Author: Andreas Lochbihler, ETH Zuerich Author: Dmitriy Traytel, ETH Zuerich Author: Andrei Popescu, TU Muenchen Copyright 2014, 2016 The filter function on lazy lists. *) section \<open>The Filter Function on Lazy Lists\<close> theory LFilter imports "HOL-Library.BNF_Corec" begin codatatype (lset: 'a) llist = LNil | LCons (lhd: 'a) (ltl: "'a llist") corecursive lfilter where "lfilter P xs = (if \<forall>x \<in> lset xs. \<not> P x then LNil else if P (lhd xs) then LCons (lhd xs) (lfilter P (ltl xs)) else lfilter P (ltl xs))" proof (relation "measure (\<lambda>(P, xs). LEAST n. P (lhd ((ltl ^^ n) xs)))", rule wf_measure, clarsimp) fix P xs x assume "x \<in> lset xs" "P x" "\<not> P (lhd xs)" from this(1,2) obtain a where "P (lhd ((ltl ^^ a) xs))" by (atomize_elim, induct x xs rule: llist.set_induct) (auto simp: funpow_Suc_right simp del: funpow.simps(2) intro: exI[of _ 0] exI[of _ "Suc i" for i]) with \<open>\<not> P (lhd xs)\<close> have "(LEAST n. P (lhd ((ltl ^^ n) xs))) = Suc (LEAST n. P (lhd ((ltl ^^ Suc n) xs)))" by (intro Least_Suc) auto then show "(LEAST n. P (lhd ((ltl ^^ n) (ltl xs)))) < (LEAST n. P (lhd ((ltl ^^ n) xs)))" by (simp add: funpow_swap1[of ltl]) qed lemma lfilter_LNil [simp]: "lfilter P LNil = LNil" by(simp add: lfilter.code) lemma lnull_lfilter [simp]: "lfilter P xs = LNil \<longleftrightarrow> (\<forall>x \<in> lset xs. \<not> P x)" proof(rule iffI ballI)+ show "\<not> P x" if "x \<in> lset xs" "lfilter P xs = LNil" for x using that by(induction rule: llist.set_induct)(subst (asm) lfilter.code; auto split: if_split_asm; fail)+ qed(simp add: lfilter.code) lemma lfilter_LCons [simp]: "lfilter P (LCons x xs) = (if P x then LCons x (lfilter P xs) else lfilter P xs)" by(subst lfilter.code)(auto intro: sym) lemma llist_in_lfilter [simp]: "lset (lfilter P xs) = lset xs \<inter> {x. P x}" proof(intro set_eqI iffI) show "x \<in> lset xs \<inter> {x. P x}" if "x \<in> lset (lfilter P xs)" for x using that proof(induction ys\<equiv>"lfilter P xs" arbitrary: xs rule: llist.set_induct) case (LCons1 x xs ys) from this show ?case apply(induction arg\<equiv>"(P, ys)" arbitrary: ys rule: lfilter.inner_induct) subgoal by(subst (asm) (2) lfilter.code)(auto split: if_split_asm elim: llist.set_cases) done next case (LCons2 xs y x ys) from LCons2(3) LCons2(1) show ?case apply(induction arg\<equiv>"(P, ys)" arbitrary: ys rule: lfilter.inner_induct) subgoal using LCons2(2) by(subst (asm) (2) lfilter.code)(auto split: if_split_asm elim: llist.set_cases) done qed show "x \<in> lset (lfilter P xs)" if "x \<in> lset xs \<inter> {x. P x}" for x using that[THEN IntD1] that[THEN IntD2] by(induction) auto qed lemma lfilter_unique_weak: "(\<And>xs. f xs = (if \<forall>x \<in> lset xs. \<not> P x then LNil else if P (lhd xs) then LCons (lhd xs) (f (ltl xs)) else lfilter P (ltl xs))) \<Longrightarrow> f = lfilter P" by(corec_unique)(rule ext lfilter.code)+ lemma lfilter_unique: assumes "\<And>xs. f xs = (if \<forall>x\<in>lset xs. \<not> P x then LNil else if P (lhd xs) then LCons (lhd xs) (f (ltl xs)) else f (ltl xs))" shows "f = lfilter P" \<comment> \<open>It seems as if we cannot use @{thm lfilter_unique_weak} for showing this as the induction and the coinduction must be nested\<close> proof(rule ext) show "f xs = lfilter P xs" for xs proof(coinduction arbitrary: xs) case (Eq_llist xs) show ?case apply(induction arg\<equiv>"(P, xs)" arbitrary: xs rule: lfilter.inner_induct) apply(subst (1 2 3 4) assms) apply(subst (1 2 3 4) lfilter.code) apply auto done qed qed lemma lfilter_lfilter: "lfilter P \<circ> lfilter Q = lfilter (\<lambda>x. P x \<and> Q x)" by(rule lfilter_unique)(auto elim: llist.set_cases) end
[STATEMENT] lemma small_all_tm_ntsmcfs[simp]: "small {\<NN>. \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB>}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. small {\<NN>. \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB>} [PROOF STEP] proof(rule down) [PROOF STATE] proof (state) goal (1 subgoal): 1. {\<NN>. \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB>} \<subseteq> elts ?x [PROOF STEP] show "{\<NN>. \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB>} \<subseteq> elts (set {\<NN>. \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB>})" [PROOF STATE] proof (prove) goal (1 subgoal): 1. {\<NN>. \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB>} \<subseteq> elts (all_ntsmcfs \<alpha>) [PROOF STEP] proof ( simp only: elts_of_set small_all_ntsmcfs if_True, rule subsetI, unfold mem_Collect_eq ) [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x. \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> \<Longrightarrow> \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] fix \<NN> [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x. \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> \<Longrightarrow> \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] assume "\<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB>" [PROOF STATE] proof (state) this: \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> goal (1 subgoal): 1. \<And>x. \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> \<Longrightarrow> \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] then [PROOF STATE] proof (chain) picking this: \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] obtain \<FF> \<GG> \<AA> \<BB> where "\<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB>" [PROOF STATE] proof (prove) using this: \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> goal (1 subgoal): 1. (\<And>\<AA> \<BB> \<FF> \<GG>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by clarsimp [PROOF STATE] proof (state) this: \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> goal (1 subgoal): 1. \<And>x. \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> \<Longrightarrow> \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] then [PROOF STATE] proof (chain) picking this: \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] interpret is_tm_ntsmcf \<alpha> \<AA> \<BB> \<FF> \<GG> \<NN> [PROOF STATE] proof (prove) using this: \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> goal (1 subgoal): 1. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] . [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x. \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> \<Longrightarrow> \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] have "\<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] by (auto simp: smc_cs_intros) [PROOF STATE] proof (state) this: \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> goal (1 subgoal): 1. \<And>x. \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB> \<Longrightarrow> \<exists>\<FF> \<GG> \<AA> \<BB>. x : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] then [PROOF STATE] proof (chain) picking this: \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] show "\<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB>" [PROOF STATE] proof (prove) using this: \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> goal (1 subgoal): 1. \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> [PROOF STEP] by auto [PROOF STATE] proof (state) this: \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^bsub>\<alpha>\<^esub> \<BB> goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: {\<NN>. \<exists>\<FF> \<GG> \<AA> \<BB>. \<NN> : \<FF> \<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>F\<^sub>.\<^sub>t\<^sub>m \<GG> : \<AA> \<mapsto>\<mapsto>\<^sub>S\<^sub>M\<^sub>C\<^sub>.\<^sub>t\<^sub>m\<^bsub>\<alpha>\<^esub> \<BB>} \<subseteq> elts (all_ntsmcfs \<alpha>) goal: No subgoals! [PROOF STEP] qed
If $P(x, x^2)$ holds for all nonnegative $x$, then $P(\lvert x \rvert, x^2)$ holds for all $x$.
Formal statement is: lemma closed_UNIV [continuous_intros, intro, simp]: "closed UNIV" Informal statement is: The whole space is closed.
State Before: ι : Type ?u.2795604 α : Type ?u.2795607 β : Type u_1 inst✝¹ : DecidableEq α inst✝ : Finite β ⊢ closure {σ | IsCycle σ} = ⊤ State After: no goals Tactic: classical cases nonempty_fintype β exact top_le_iff.mp (le_trans (ge_of_eq closure_isSwap) (closure_mono fun _ => IsSwap.isCycle)) State Before: ι : Type ?u.2795604 α : Type ?u.2795607 β : Type u_1 inst✝¹ : DecidableEq α inst✝ : Finite β ⊢ closure {σ | IsCycle σ} = ⊤ State After: case intro ι : Type ?u.2795604 α : Type ?u.2795607 β : Type u_1 inst✝¹ : DecidableEq α inst✝ : Finite β val✝ : Fintype β ⊢ closure {σ | IsCycle σ} = ⊤ Tactic: cases nonempty_fintype β State Before: case intro ι : Type ?u.2795604 α : Type ?u.2795607 β : Type u_1 inst✝¹ : DecidableEq α inst✝ : Finite β val✝ : Fintype β ⊢ closure {σ | IsCycle σ} = ⊤ State After: no goals Tactic: exact top_le_iff.mp (le_trans (ge_of_eq closure_isSwap) (closure_mono fun _ => IsSwap.isCycle))
{- defining Nat as a kind of List -} -- the need for ‼ is unfortunate module Oscar.Data2 where record ⊤ : Set where constructor tt -- List data ⟦_⟧ {a} (A : Set a) : Set a where ∅ : ⟦ A ⟧ _∷_ : A → ⟦ A ⟧ → ⟦ A ⟧ -- Nat ⟦⟧ = ⟦ ⊤ ⟧ pattern ‼ ⟦A⟧ = tt ∷ ⟦A⟧ -- Fin data ⟦⟧[_] : ⟦⟧ → Set where ∅ : ∀ {n} → ⟦⟧[ ‼ n ] ! : ∀ {n} → ⟦⟧[ n ] → ⟦⟧[ ‼ n ] test : ⟦⟧[ ‼ (‼ ∅) ] test = ! ∅
lemma locallyI: assumes "\<And>w x. \<lbrakk>openin (top_of_set S) w; x \<in> w\<rbrakk> \<Longrightarrow> \<exists>u v. openin (top_of_set S) u \<and> P v \<and> x \<in> u \<and> u \<subseteq> v \<and> v \<subseteq> w" shows "locally P S"
_ : Set
/- Copyright (c) 2022 Mac Malone. All rights reserved. Released under the MIT license described in the file LICENSE. Authors: Mac Malone -/ import Folktale open Folktale /-! A crime is committed, and X and Y are accused. They could be both guilty, both innocent, or only one guilty. 8 witnesses are brought in, who make the following statements in order: * A: X is a knight * B: Y is a knave * C: A is a knave * D: B is a knave * E: C and D are knights * F: A and B are not both lying * G: E and F are the same type * H: I am the same type as G; also, X and Y are not both guilty Whodunit? That is, did X do it and/or did Y do it? **Clarifications:** * H's statement is a single proposition with an AND. **Source:** *The Riddle of Scheherazade* by Raymond Smullyan -/ -- # Setting axiom X : Folk axiom Y : Folk axiom A : Folk axiom B : Folk axiom C : Folk axiom D : Folk axiom E : Folk axiom F : Folk axiom G : Folk axiom H : Folk constant guilty : Folk → Prop -- # Statements axiom A_knight_X : A.say <| knight X axiom B_knave_Y : B.say <| knave Y axiom C_knave_A : C.say <| knave A axiom D_knave_B : D.say <| knave B axiom E_knight_C_D : E.say <| knight C ∧ knight D axiom F_not_knave_A_B : F.say <| ¬ (knave A ∧ knave B) axiom G_same_E_F : G.say <| same2 E F axiom H_G_X_Y : H.say <| same2 H G ∧ ¬ (guilty X ∧ guilty Y) -- # Deductions theorem not_same_E_F : ¬ (same2 E F) := by intro h; cases h with | inl knights => let ⟨knight_E, knight_F⟩ := knights let ⟨knight_C, knight_D⟩ := knight_truth knight_E E_knight_C_D cases Classical.dm_and (knight_truth knight_F F_not_knave_A_B) with | inl not_knave_A => let knave_A := knight_truth knight_C C_knave_A contradiction | inr not_knave_B => let knave_B := knight_truth knight_D D_knave_B contradiction | inr knaves => let ⟨knave_E, knave_F⟩ := knaves let ⟨knave_A, knave_B⟩ := Classical.dne <| knave_lie knave_F F_not_knave_A_B cases Classical.dm_and (knave_lie knave_E E_knight_C_D) with | inl not_knight_C => let not_knave_A := knave_lie (not_knight_knave (not_knight_C)) C_knave_A contradiction | inr not_knight_D => let not_knave_B := knave_lie (not_knight_knave (not_knight_D)) D_knave_B contradiction theorem knave_G : knave G := not_knight_knave fun knight_G => not_same_E_F (knight_truth knight_G G_same_E_F) theorem solution : guilty X ∧ guilty Y := by cases knight_or_knave H with | inl knight_H => apply False.elim let ⟨same_H_G, _⟩ := knight_truth knight_H H_G_X_Y cases same_H_G with | inl both_knights => let ⟨_, knight_G⟩ := both_knights exact knight_not_knave knight_G knave_G | inr both_knaves => let ⟨knave_H, _⟩ := both_knaves exact knight_not_knave knight_H knave_H | inr knave_H => cases Classical.dm_and <| knave_lie knave_H H_G_X_Y with | inl not_same_H_G => exact False.elim <| not_same_H_G <| Or.inr <| And.intro knave_H knave_G | inr not_not_guilty_X_Y => exact Classical.dne not_not_guilty_X_Y -- # Side Note /-- If one interprets H's line as two separate statements instead of a single one joined with an AND, the puzzle is contradictory (i.e., proves false). Essentially, since G is provably a knave, H's statement that they are both the same type reduces to "We are both knaves", which is always contradictory. -/ theorem bad_interpretation (H_same_G : H.say <| same2 H G) : False := by cases knight_or_knave H with | inl knight_H => cases knight_truth knight_H H_same_G with | inl both_knights => let ⟨_, knight_G⟩ := both_knights exact knight_not_knave knight_G knave_G | inr both_knaves => let ⟨knave_H, _⟩ := both_knaves exact knight_not_knave knight_H knave_H | inr knave_H => let ⟨_, not_both_knaves⟩ := Classical.dm_or <| knave_lie knave_H H_same_G cases Classical.dm_and not_both_knaves with | inl not_knave_H => exact not_knave_H knave_H | inr not_knave_G => exact not_knave_G knave_G
!! Copyright (C) Stichting Deltares, 2012-2016. !! !! This program is free software: you can redistribute it and/or modify !! it under the terms of the GNU General Public License version 3, !! as published by the Free Software Foundation. !! !! This program is distributed in the hope that it will be useful, !! but WITHOUT ANY WARRANTY; without even the implied warranty of !! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !! GNU General Public License for more details. !! !! You should have received a copy of the GNU General Public License !! along with this program. If not, see <http://www.gnu.org/licenses/>. !! !! contact: [email protected] !! Stichting Deltares !! P.O. Box 177 !! 2600 MH Delft, The Netherlands !! !! All indications and logos of, and references to registered trademarks !! of Stichting Deltares remain the property of Stichting Deltares. All !! rights reserved. subroutine rdbalg ( pmsa , fl , ipoint , increm , noseg , & noflux , iexpnt , iknmrk , noq1 , noq2 , & noq3 , noq4 ) !>\file !> Light efficiency function DYNAMO algae ! ! Description of the module : ! ! Name T L I/O Description Unit ! ---- --- - - ------------------- --- ! DEPTH R*4 1 I depth of the water column [ ! EFF R*4 1 L average light efficiency green-algea [ ! ACTRAD R*4 1 I radiation [W/m ! SATRAD R*4 1 I radiation growth saturation green-algea [W/m ! Logical Units : - ! Modules called : - ! Name Type Library ! ------ ----- ------------ IMPLICIT REAL (A-H,J-Z) REAL PMSA ( * ) , FL (*) INTEGER IPOINT( * ) , INCREM(*) , NOSEG , NOFLUX, + IEXPNT(4,*) , IKNMRK(*) , NOQ1, NOQ2, NOQ3, NOQ4 LOGICAL LGTOPT ! IN1 = INCREM( 1) IN2 = INCREM( 2) IN3 = INCREM( 3) IN4 = INCREM( 4) IN5 = INCREM( 5) IN6 = INCREM( 6) ! IP1 = IPOINT( 1) IP2 = IPOINT( 2) IP3 = IPOINT( 3) IP4 = IPOINT( 4) IP5 = IPOINT( 5) IP6 = IPOINT( 6) ! IF ( IN2 .EQ. 0 .AND. IN3 .EQ. 0 .AND. IN5 .EQ. 0 ) THEN ACTRAD = PMSA(IP2 ) SATRAD = PMSA(IP3 ) TFGRO = PMSA(IP5 ) ! ! Correct SATRAD for temperature using Temp function for growth ! ! SATRAD = TFGRO * SATRAD SATRAD = SATRAD ! actuele straling / straling voor groei verzadiging FRAD = ACTRAD / SATRAD LGTOPT = .FALSE. ELSE LGTOPT = .TRUE. ENDIF ! IFLUX = 0 DO 9000 ISEG = 1 , NOSEG !! CALL DHKMRK(1,IKNMRK(ISEG),IKMRK1) !! IF (IKMRK1.EQ.1) THEN IF (BTEST(IKNMRK(ISEG),0)) THEN ! IF ( LGTOPT ) THEN ACTRAD = PMSA(IP2 ) SATRAD = PMSA(IP3 ) TFGRO = PMSA(IP5 ) ! ! Correct SATRAD for temperature using Temp function for growth ! ! SATRAD = TFGRO * SATRAD SATRAD = SATRAD ! actuele straling / straling voor groei verzadiging FRAD = ACTRAD / SATRAD ENDIF ! PMSA(IP6) = MAX(MIN(FRAD,1.0),0.0) ! IF (SATRAD .LT. 1E-20 ) CALL ERRSYS ('SATRAD in RADALG zero', 1 ) 8900 CONTINUE ! ENDIF ! IFLUX = IFLUX + NOFLUX IP1 = IP1 + IN1 IP2 = IP2 + IN2 IP3 = IP3 + IN3 IP5 = IP5 + IN5 IP4 = IP4 + IN4 IP6 = IP6 + IN6 ! 9000 CONTINUE ! RETURN ! END
A : Set₁ A = Set {-# POLARITY A #-}
State Before: ι : Type u_2 α : ι → Type u_1 f f₁ f₂ : (i : ι) → Filter (α i) s : (i : ι) → Set (α i) ⊢ NeBot (Filter.coprodᵢ f) ↔ (∀ (i : ι), Nonempty (α i)) ∧ ∃ d, NeBot (f d) State After: no goals Tactic: simp only [Filter.coprodᵢ, iSup_neBot, ← exists_and_left, ← comap_eval_neBot_iff']
-- Andreas, 2019-11-12, issue #4168b -- -- Meta variable solver should not use uncurrying -- if the record type contains erased fields. open import Agda.Builtin.Equality open import Agda.Builtin.Sigma open import Common.IO P : (A B : Set) → (A → B) → Set P A B f = (y : B) → Σ A (λ x → f x ≡ y) record R (A B : Set) : Set where field to : A → B from : B → A from-to : (x : A) → from (to x) ≡ x p : (A B : Set) (r : R A B) → P A B (R.to r) p _ _ r y = R.from r y , to-from y where postulate to-from : ∀ x → R.to r (R.from r x) ≡ x record Box (A : Set) : Set where constructor box field @0 unbox : A test : (A : Set) → P (Box A) (Box (Box A)) (box {A = Box A}) test A = p _ _ (record { to = box {A = _} ; from = λ { (box (box x)) → box {A = A} x } -- at first, a postponed type checking problem ?from ; from-to = λ x → refl {A = Box A} {x = _} }) -- from-to creates constraint -- -- x : Box A |- ?from (box x) = x : Box A -- -- This was changed to -- -- y : Box (Box A) |- ?from y = unbox y : Box A -- -- which is an invalid transformation since x is not -- guaranteed to be in erased context. -- As a consequence, compilation (GHC backend) failed. -- A variant with a non-erased field. record ⊤ : Set where record Box' (A : Set) : Set where constructor box' field unit : ⊤ @0 unbox' : A test' : (A : Set) → P (Box' A) (Box' (Box' A)) (box' {A = Box' A} _) test' A = p _ _ (record { to = box' {A = _} _ ; from = λ { (box' _ (box' _ x)) → box' {A = A} _ x } ; from-to = λ x → refl {A = Box' A} {x = _} }) main : IO ⊤ main = return _
lemma Cauchy_theorem_quadrisection: assumes f: "continuous_on (convex hull {a,b,c}) f" and dist: "dist a b \<le> K" "dist b c \<le> K" "dist c a \<le> K" and e: "e * K^2 \<le> norm (contour_integral(linepath a b) f + contour_integral(linepath b c) f + contour_integral(linepath c a) f)" shows "\<exists>a' b' c'. a' \<in> convex hull {a,b,c} \<and> b' \<in> convex hull {a,b,c} \<and> c' \<in> convex hull {a,b,c} \<and> dist a' b' \<le> K/2 \<and> dist b' c' \<le> K/2 \<and> dist c' a' \<le> K/2 \<and> e * (K/2)^2 \<le> norm(contour_integral(linepath a' b') f + contour_integral(linepath b' c') f + contour_integral(linepath c' a') f)" (is "\<exists>x y z. ?\<Phi> x y z")
-- import group_theory.level1 --hide /- # Level 2: Union of two open sets -/ /- Lemma The union of two open sets is open. -/ -- lemma open_of_union {X : Type} [topological_space X] {U V : set X} -- (hU : is_open U) (hV : is_open V): is_open (U ∪ V) := -- begin -- let I : set (set X) := {U, V}, -- have H : ⋃₀ I = U ∪ V := sUnion_pair U V, -- rw ←H, -- apply union I, -- intros B hB, -- replace hB : B = U ∨ B = V, by tauto, -- cases hB; {rw hB, assumption}, -- end
function [data,compress,gridlocs,node_sizes,voxel_sizes] = fns_read_recipdata(infile) % % This function reads the reciprocity data and the related % information into the MATLAB workspace. % $Copyright (C) 2010 by Hung Dang$ % Read in the reciprocity data data = hdf5read(infile,'/recipdata/data'); % Read in other parameters compress = hdf5read(infile,'/recipdata/roicompress') + 1; gridlocs = hdf5read(infile,'/recipdata/gridlocs'); node_sizes = hdf5read(infile,'/model/node_sizes'); voxel_sizes = hdf5read(infile,'/model/voxel_sizes');
```python from sympy import init_session init_session() ``` IPython console for SymPy 1.0 (Python 3.6.3-64-bit) (ground types: python) These commands were executed: >>> from __future__ import division >>> from sympy import * >>> x, y, z, t = symbols('x y z t') >>> k, m, n = symbols('k m n', integer=True) >>> f, g, h = symbols('f g h', cls=Function) >>> init_printing() Documentation can be found at http://docs.sympy.org/1.0/ ```python r, u, v, w, E, e, p = symbols("rho u v w E e p") dedr, dedp = symbols(r"\left.\frac{\partial{}e}{\partial\rho}\right|_p \left.\frac{\partial{}e}{\partial{}p}\right|_\rho") Bx, By, Bz = symbols("B_x B_y B_z") ``` ```python A = Matrix( [[1, 0, 0, 0, 0, 0, 0, 0], [u, r, 0, 0, 0, 0, 0, 0], [v, 0, r, 0, 0, 0, 0, 0], [w, 0, 0, r, 0, 0, 0, 0], [e + r*dedr + (u**2 + v**2 + w**2)/2, r*u, r*v, r*w, r*dedp, Bx, By, Bz], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1]]) ``` ```python A ``` ```python A.inv() ``` ```python Fr, Fu, Fv, Fw, FE, FBx, FBy, FBz = symbols(r"F_{\rho} F_{\rho{}u} F_{\rho{}v} F_{\rho{}w} F_{\rho{}E} F_{B_x} F_{B_y} F_{B_z}") ``` ```python F = Matrix([[Fr], [Fu], [Fv], [Fw], [FE], [FBx], [FBy], [FBz]]) ``` ```python A.inv() * F ``` ```python ```
SUBROUTINE conab(sgm,sge) !------------------------------------------------------------- ! ! Construct the A and B matrices that make the gamma matrix ! A and B matrices specific for an ordinate (n) and cell (x,y) ! !------------------------------------------------------------- USE invar USE solvar IMPLICIT NONE INTEGER, INTENT(IN) :: sgm, sge INTEGER :: k, l, ieq, ll, col, mltx, mlty, mltxx, mltyy ! at end will have: ieq = ordsq + 2*order ! Initialize the amat and bmat values amat = 0.0 bmat = 0.0 ! Set ieq ieq = 0 ! Begin constructing the matrices by advancing through the equations ! From the AHOT-N equations DO k = 0, lambda mltx = sgm**k mltxx = ((-1)**k)*mltx DO l = 0, lambda mlty = sge**l mltyy = ((-1)**l)*mlty ! Start with the 00 equation, then 01, 02, ... ieq = ieq + 1 ! amat contribution from total interaction amat(ieq,ieq) = amat(ieq,ieq) + 1.0 ! contribution from x-dir summation DO ll = MOD((k+1),2), (k-1), 2 col = order*ll + l + 1 amat(ieq,col) = amat(ieq,col) - sgm*(2.0*ll+1.0)/ex END DO ! Contribution from y-dir summation DO ll = MOD((l+1),2), (l-1), 2 col = order*k + ll + 1 amat(ieq,col) = amat(ieq,col) - sge*(2.0*ll+1.0)/ey END DO ! Contribution from outgoing y flux (amat) and incoming y flux (bmat) col = ordsq + 1 + k amat(ieq,col) = amat(ieq,col) + mlty/(2.0*ey) bmat(ieq,col) = bmat(ieq,col) + mltyy/(2.0*ey) ! Contribution from outgoing x flux (amat) and incoming x flux (bmat) col = ordsq + order + 1 + l amat(ieq,col) = amat(ieq,col) + mltx/(2.0*ex) bmat(ieq,col) = bmat(ieq,col) + mltxx/(2.0*ex) ! bmat contribution from scattering and fixed source bmat(ieq,ieq) = bmat(ieq,ieq) + 1.0 ! Finished with the AHOT-N equations END DO END DO ! Contributions from the WDD equations ! y-direction DO k = 0, lambda ieq = ieq + 1 ! Contributions to amat from even summations DO ll = 0, lambda, 2 col = order*k + ll + 1 amat(ieq,col) = amat(ieq,col) + (2.0*ll + 1.0) END DO ! Contributions to amat from odd summations DO ll = 1, lambda, 2 col = order*k + ll + 1 amat(ieq,col) = amat(ieq,col) + sge*beta*(2.0*ll+1.0) END DO ! Contribution from outgoing flux col = ordsq + 1 + k amat(ieq,col) = amat(ieq,col) - (1.0+beta)/2.0 ! Contribution to bmat from incoming flux bmat(ieq,col) = bmat(ieq,col) + (1.0-beta)/2.0 ! Done with y-direction END DO ! x-direction DO l = 0, lambda ieq = ieq + 1 ! Contributions to amat from even summations DO ll = 0, lambda, 2 col = order*ll + l + 1 amat(ieq,col) = amat(ieq,col) + (2.0*ll + 1.0) END DO ! Contributions to amat from odd summations DO ll = 1, lambda, 2 col = order*ll + l + 1 amat(ieq,col) = amat(ieq,col) + sgm*alpha*(2.0*ll+1.0) END DO ! Contribution from outgoing flux col = ordsq + order + 1 + l amat(ieq,col) = amat(ieq,col) - (1.0+alpha)/2.0 ! Contribution to bmat from incoming flux bmat(ieq,col) = bmat(ieq,col) + (1.0-alpha)/2.0 ! Done with x-direction END DO RETURN END SUBROUTINE conab
module Test.Inigo.Archive.ArchiveTest import IdrTest.Test import IdrTest.Expectation import Inigo.Archive.Archive export suite : Test suite = describe "Encode" [ test "Simple Encode" (\_ => assertEq (encode [(["a","b"], "bbb"), (["a","c"], "ccc")]) "a.b=\"bbb\"\na.c=\"ccc\"" ), test "Simple Decode" (\_ => assertEq (decode "a.b=\"bbb\"\na.c=\"ccc\"") (Just [(["a","b"], "bbb"), (["a","c"], "ccc")]) ) ]
Formal statement is: lemma fixes c :: "'a::euclidean_space \<Rightarrow> real" and t assumes c: "\<And>j. j \<in> Basis \<Longrightarrow> c j \<noteq> 0" defines "T == (\<lambda>x. t + (\<Sum>j\<in>Basis. (c j * (x \<bullet> j)) *\<^sub>R j))" shows lebesgue_affine_euclidean: "lebesgue = density (distr lebesgue lebesgue T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))" (is "_ = ?D") and lebesgue_affine_measurable: "T \<in> lebesgue \<rightarrow>\<^sub>M lebesgue" Informal statement is: If $c$ is a vector of nonzero real numbers, then the Lebesgue measure of the set $T = \{t + \sum_{j \in \text{Basis}} c_j x_j \mid x \in \mathbb{R}^n\}$ is equal to the product of the absolute values of the $c_j$'s.
lemma bounded_bilinear_mult: "bounded_bilinear ((*) :: 'a \<Rightarrow> 'a \<Rightarrow> 'a::real_normed_algebra)"
# --- # title: 912. Sort an Array # id: problem912 # author: Tian Jun # date: 2020-10-31 # difficulty: Medium # categories: # link: <https://leetcode.com/problems/sort-an-array/description/> # hidden: true # --- # # Given an array of integers `nums`, sort the array in ascending order. # # # # **Example 1:** # # # # Input: nums = [5,2,3,1] # Output: [1,2,3,5] # # # **Example 2:** # # # # Input: nums = [5,1,1,2,0,0] # Output: [0,0,1,1,2,5] # # # # # **Constraints:** # # * `1 <= nums.length <= 50000` # * `-50000 <= nums[i] <= 50000` # # ## @lc code=start using LeetCode ## add your code here: ## @lc code=end
{-# LANGUAGE Rank2Types, BangPatterns, ScopedTypeVariables #-} ----------------------------------------------------------------------------- -- | -- Module : Numeric.AD.Newton -- Copyright : (c) Edward Kmett 2010 -- License : BSD3 -- Maintainer : [email protected] -- Stability : experimental -- Portability : GHC only -- ----------------------------------------------------------------------------- module Numeric.AD.Newton ( -- * Newton's Method (Forward AD) findZero , inverse , fixedPoint , extremum -- * Gradient Ascent/Descent (Reverse AD) , gradientDescent , gradientAscent , conjugateGradientDescent , conjugateGradientAscent ) where import Prelude hiding (all, mapM, sum) import Data.Functor import Data.Foldable (all, sum) import Data.Traversable import Numeric.AD.Types import Numeric.AD.Mode.Forward (diff, diff') import Numeric.AD.Mode.Reverse (grad, gradWith') import Numeric.AD.Internal.Combinators import Numeric.AD.Internal.Composition -- | The 'findZero' function finds a zero of a scalar function using -- Newton's method; its output is a stream of increasingly accurate -- results. (Modulo the usual caveats.) If the stream becomes constant -- ("it converges"), no further elements are returned. -- -- Examples: -- -- >>> take 10 $ findZero (\x->x^2-4) 1 -- [1.0,2.5,2.05,2.000609756097561,2.0000000929222947,2.000000000000002,2.0] -- -- >>> import Data.Complex -- >>> last $ take 10 $ findZero ((+1).(^2)) (1 :+ 1) -- 0.0 :+ 1.0 findZero :: (Fractional a, Eq a) => (forall s. Mode s => AD s a -> AD s a) -> a -> [a] findZero f = go where go x = x : if x == xn then [] else go xn where (y,y') = diff' f x xn = x - y/y' {-# INLINE findZero #-} -- | The 'inverse' function inverts a scalar function using -- Newton's method; its output is a stream of increasingly accurate -- results. (Modulo the usual caveats.) If the stream becomes -- constant ("it converges"), no further elements are returned. -- -- Example: -- -- >>> last $ take 10 $ inverse sqrt 1 (sqrt 10) -- 10.0 inverse :: (Fractional a, Eq a) => (forall s. Mode s => AD s a -> AD s a) -> a -> a -> [a] inverse f x0 y = findZero (\x -> f x - lift y) x0 {-# INLINE inverse #-} -- | The 'fixedPoint' function find a fixedpoint of a scalar -- function using Newton's method; its output is a stream of -- increasingly accurate results. (Modulo the usual caveats.) -- -- If the stream becomes constant ("it converges"), no further -- elements are returned. -- -- >>> last $ take 10 $ fixedPoint cos 1 -- 0.7390851332151607 fixedPoint :: (Fractional a, Eq a) => (forall s. Mode s => AD s a -> AD s a) -> a -> [a] fixedPoint f = findZero (\x -> f x - x) {-# INLINE fixedPoint #-} -- | The 'extremum' function finds an extremum of a scalar -- function using Newton's method; produces a stream of increasingly -- accurate results. (Modulo the usual caveats.) If the stream -- becomes constant ("it converges"), no further elements are returned. -- -- >>> last $ take 10 $ extremum cos 1 -- 0.0 extremum :: (Fractional a, Eq a) => (forall s. Mode s => AD s a -> AD s a) -> a -> [a] extremum f = findZero (diff (decomposeMode . f . composeMode)) {-# INLINE extremum #-} -- | The 'gradientDescent' function performs a multivariate -- optimization, based on the naive-gradient-descent in the file -- @stalingrad\/examples\/flow-tests\/pre-saddle-1a.vlad@ from the -- VLAD compiler Stalingrad sources. Its output is a stream of -- increasingly accurate results. (Modulo the usual caveats.) -- -- It uses reverse mode automatic differentiation to compute the gradient. gradientDescent :: (Traversable f, Fractional a, Ord a) => (forall s. Mode s => f (AD s a) -> AD s a) -> f a -> [f a] gradientDescent f x0 = go x0 fx0 xgx0 0.1 (0 :: Int) where (fx0, xgx0) = gradWith' (,) f x0 go x fx xgx !eta !i | eta == 0 = [] -- step size is 0 | fx1 > fx = go x fx xgx (eta/2) 0 -- we stepped too far | zeroGrad xgx = [] -- gradient is 0 | otherwise = x1 : if i == 10 then go x1 fx1 xgx1 (eta*2) 0 else go x1 fx1 xgx1 eta (i+1) where zeroGrad = all (\(_,g) -> g == 0) x1 = fmap (\(xi,gxi) -> xi - eta * gxi) xgx (fx1, xgx1) = gradWith' (,) f x1 {-# INLINE gradientDescent #-} -- | Perform a gradient descent using reverse mode automatic differentiation to compute the gradient. gradientAscent :: (Traversable f, Fractional a, Ord a) => (forall s. Mode s => f (AD s a) -> AD s a) -> f a -> [f a] gradientAscent f = gradientDescent (negate . f) {-# INLINE gradientAscent #-} -- | Perform a conjugate gradient descent using reverse mode automatic differentiation to compute the gradient. conjugateGradientDescent :: (Traversable f, Fractional a, Ord a) => (forall s. Mode s => f (AD s a) -> AD s a) -> f a -> [f a] conjugateGradientDescent f x0 = go x0 d0 d0 where dot x y = sum $ zipWithT (*) x y d0 = negate <$> grad f x0 go xi ri di = xi : go xi1 ri1 di1 where ai = last $ take 20 $ extremum (\a -> f $ zipWithT (\x d -> lift x + a * lift d) xi di) 0 xi1 = zipWithT (\x d -> x + ai*d) xi di ri1 = negate <$> grad f xi1 bi1 = max 0 $ dot ri1 (zipWithT (-) ri1 ri) / dot ri1 ri1 -- bi1 = max 0 $ sum (zipWithT (\a b -> a * (a - b)) ri1 ri) / dot ri1 ri1 di1 = zipWithT (\r d -> r * bi1*d) ri1 di {-# INLINE conjugateGradientDescent #-} -- | Perform a conjugate gradient ascent using reverse mode automatic differentiation to compute the gradient. conjugateGradientAscent :: (Traversable f, Fractional a, Ord a) => (forall s. Mode s => f (AD s a) -> AD s a) -> f a -> [f a] conjugateGradientAscent f = conjugateGradientDescent (negate . f) {-# INLINE conjugateGradientAscent #-}
State Before: x y : ℝ≥0∞ z : ℝ hz : 0 < z ⊢ x ≤ y ^ (1 / z) ↔ x ^ z ≤ y State After: x y : ℝ≥0∞ z : ℝ hz : 0 < z ⊢ x ^ 1 ≤ y ^ (1 / z) ↔ x ^ z ≤ y Tactic: nth_rw 1 [← rpow_one x] State Before: x y : ℝ≥0∞ z : ℝ hz : 0 < z ⊢ x ^ 1 ≤ y ^ (1 / z) ↔ x ^ z ≤ y State After: x y : ℝ≥0∞ z : ℝ hz : 0 < z ⊢ x ^ (z * z⁻¹) ≤ y ^ (1 / z) ↔ x ^ z ≤ y Tactic: nth_rw 1 [← @_root_.mul_inv_cancel _ _ z hz.ne'] State Before: x y : ℝ≥0∞ z : ℝ hz : 0 < z ⊢ x ^ (z * z⁻¹) ≤ y ^ (1 / z) ↔ x ^ z ≤ y State After: no goals Tactic: rw [rpow_mul, ← one_div, @rpow_le_rpow_iff _ _ (1 / z) (by simp [hz])] State Before: x y : ℝ≥0∞ z : ℝ hz : 0 < z ⊢ 0 < 1 / z State After: no goals Tactic: simp [hz]
[GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ ¬r ∈ (toΓSpecFun X x).asIdeal ↔ IsUnit (↑(ΓToStalk X x) r) [PROOFSTEP] erw [LocalRing.mem_maximalIdeal, Classical.not_not] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ toΓSpecFun X ⁻¹' (basicOpen r).carrier = (RingedSpace.basicOpen (toRingedSpace X) r).carrier [PROOFSTEP] ext [GOAL] case h X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x✝ : ↑(toTopCat X) ⊢ x✝ ∈ toΓSpecFun X ⁻¹' (basicOpen r).carrier ↔ x✝ ∈ (RingedSpace.basicOpen (toRingedSpace X) r).carrier [PROOFSTEP] erw [X.toRingedSpace.mem_top_basicOpen] [GOAL] case h X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x✝ : ↑(toTopCat X) ⊢ x✝ ∈ toΓSpecFun X ⁻¹' (basicOpen r).carrier ↔ IsUnit (↑(germ (toRingedSpace X).toPresheafedSpace.presheaf { val := x✝, property := (_ : x✝ ∈ ⊤) }) r) [PROOFSTEP] apply not_mem_prime_iff_unit_in_stalk [GOAL] X : LocallyRingedSpace ⊢ Continuous (toΓSpecFun X) [PROOFSTEP] apply isTopologicalBasis_basic_opens.continuous [GOAL] case hf X : LocallyRingedSpace ⊢ ∀ (s : Set (PrimeSpectrum ↑(Γ.obj (op X)))), (s ∈ Set.range fun r => ↑(basicOpen r)) → IsOpen (toΓSpecFun X ⁻¹' s) [PROOFSTEP] rintro _ ⟨r, rfl⟩ [GOAL] case hf.intro X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ IsOpen (toΓSpecFun X ⁻¹' (fun r => ↑(basicOpen r)) r) [PROOFSTEP] erw [X.toΓSpec_preim_basicOpen_eq r] [GOAL] case hf.intro X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ IsOpen (RingedSpace.basicOpen (toRingedSpace X) r).carrier [PROOFSTEP] exact (X.toRingedSpace.basicOpen r).2 [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ IsUnit (↑(toToΓSpecMapBasicOpen X r) r) [PROOFSTEP] convert (X.presheaf.map <| (eqToHom <| X.toΓSpecMapBasicOpen_eq r).op).isUnit_map (X.toRingedSpace.isUnit_res_basicOpen r) -- Porting note : `rw [comp_apply]` to `erw [comp_apply]` [GOAL] case h.e'_3 X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ ↑(toToΓSpecMapBasicOpen X r) r = ↑(X.presheaf.map (eqToHom (_ : toΓSpecMapBasicOpen X r = RingedSpace.basicOpen (toRingedSpace X) r)).op) (↑((toRingedSpace X).toPresheafedSpace.presheaf.map (homOfLE (_ : RingedSpace.basicOpen (toRingedSpace X) r ≤ ⊤)).op) r) [PROOFSTEP] erw [← comp_apply, ← Functor.map_comp] [GOAL] case h.e'_3 X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ ↑(toToΓSpecMapBasicOpen X r) r = ↑((toRingedSpace X).toPresheafedSpace.presheaf.map ((homOfLE (_ : RingedSpace.basicOpen (toRingedSpace X) r ≤ ⊤)).op ≫ (eqToHom (_ : toΓSpecMapBasicOpen X r = RingedSpace.basicOpen (toRingedSpace X) r)).op)) r [PROOFSTEP] congr [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) f : (structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X r)) ⊢ toOpen (↑(Γ.obj (op X))) (basicOpen r) ≫ f = toToΓSpecMapBasicOpen X r ↔ f = toΓSpecCApp X r [PROOFSTEP] have loc_inst := IsLocalization.to_basicOpen (Γ.obj (op X)) r [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) f : (structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X r)) loc_inst : IsLocalization.Away r ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r))) ⊢ toOpen (↑(Γ.obj (op X))) (basicOpen r) ≫ f = toToΓSpecMapBasicOpen X r ↔ f = toΓSpecCApp X r [PROOFSTEP] rw [← @IsLocalization.Away.AwayMap.lift_comp _ _ _ _ _ _ _ r loc_inst _ (X.isUnit_res_toΓSpecMapBasicOpen r)] --pick_goal 5; exact is_localization.to_basic_open _ r [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) f : (structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X r)) loc_inst : IsLocalization.Away r ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r))) ⊢ toOpen (↑(Γ.obj (op X))) (basicOpen r) ≫ f = RingHom.comp (IsLocalization.Away.lift r (_ : IsUnit (↑(toToΓSpecMapBasicOpen X r) r))) (algebraMap ↑(Γ.obj (op X)) ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)))) ↔ f = toΓSpecCApp X r [PROOFSTEP] constructor [GOAL] case mp X : LocallyRingedSpace r : ↑(Γ.obj (op X)) f : (structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X r)) loc_inst : IsLocalization.Away r ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r))) ⊢ toOpen (↑(Γ.obj (op X))) (basicOpen r) ≫ f = RingHom.comp (IsLocalization.Away.lift r (_ : IsUnit (↑(toToΓSpecMapBasicOpen X r) r))) (algebraMap ↑(Γ.obj (op X)) ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)))) → f = toΓSpecCApp X r [PROOFSTEP] intro h [GOAL] case mp X : LocallyRingedSpace r : ↑(Γ.obj (op X)) f : (structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X r)) loc_inst : IsLocalization.Away r ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r))) h : toOpen (↑(Γ.obj (op X))) (basicOpen r) ≫ f = RingHom.comp (IsLocalization.Away.lift r (_ : IsUnit (↑(toToΓSpecMapBasicOpen X r) r))) (algebraMap ↑(Γ.obj (op X)) ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)))) ⊢ f = toΓSpecCApp X r [PROOFSTEP] refine' @IsLocalization.ringHom_ext _ _ _ _ _ _ _ _ loc_inst _ _ _ [GOAL] case mp X : LocallyRingedSpace r : ↑(Γ.obj (op X)) f : (structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X r)) loc_inst : IsLocalization.Away r ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r))) h : toOpen (↑(Γ.obj (op X))) (basicOpen r) ≫ f = RingHom.comp (IsLocalization.Away.lift r (_ : IsUnit (↑(toToΓSpecMapBasicOpen X r) r))) (algebraMap ↑(Γ.obj (op X)) ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)))) ⊢ RingHom.comp f (algebraMap ↑(Γ.obj (op X)) ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)))) = RingHom.comp (toΓSpecCApp X r) (algebraMap ↑(Γ.obj (op X)) ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)))) [PROOFSTEP] exact h [GOAL] case mpr X : LocallyRingedSpace r : ↑(Γ.obj (op X)) f : (structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X r)) loc_inst : IsLocalization.Away r ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r))) ⊢ f = toΓSpecCApp X r → toOpen (↑(Γ.obj (op X))) (basicOpen r) ≫ f = RingHom.comp (IsLocalization.Away.lift r (_ : IsUnit (↑(toToΓSpecMapBasicOpen X r) r))) (algebraMap ↑(Γ.obj (op X)) ↑((structureSheaf ↑(Γ.obj (op X))).val.obj (op (basicOpen r)))) [PROOFSTEP] apply congr_arg [GOAL] X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) r s : (InducedCategory (Opens (PrimeSpectrum ↑(Γ.obj (op X)))) basicOpen)ᵒᵖ f : r ⟶ s ⊢ ((inducedFunctor basicOpen).op ⋙ (structureSheaf ↑(Γ.obj (op X))).val).map f ≫ (fun r => toΓSpecCApp X r.unop) s = (fun r => toΓSpecCApp X r.unop) r ≫ ((inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)).val).map f [PROOFSTEP] apply (StructureSheaf.to_basicOpen_epi (Γ.obj (op X)) r.unop).1 [GOAL] case a X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) r s : (InducedCategory (Opens (PrimeSpectrum ↑(Γ.obj (op X)))) basicOpen)ᵒᵖ f : r ⟶ s ⊢ toOpen (↑(Γ.obj (op X))) (basicOpen r.unop) ≫ ((inducedFunctor basicOpen).op ⋙ (structureSheaf ↑(Γ.obj (op X))).val).map f ≫ (fun r => toΓSpecCApp X r.unop) s = toOpen (↑(Γ.obj (op X))) (basicOpen r.unop) ≫ (fun r => toΓSpecCApp X r.unop) r ≫ ((inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)).val).map f [PROOFSTEP] simp only [← Category.assoc] [GOAL] case a X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) r s : (InducedCategory (Opens (PrimeSpectrum ↑(Γ.obj (op X)))) basicOpen)ᵒᵖ f : r ⟶ s ⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen r.unop) ≫ ((inducedFunctor basicOpen).op ⋙ (structureSheaf ↑(Γ.obj (op X))).val).map f) ≫ toΓSpecCApp X s.unop = (toOpen (↑(Γ.obj (op X))) (basicOpen r.unop) ≫ toΓSpecCApp X r.unop) ≫ ((inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)).val).map f [PROOFSTEP] erw [X.toΓSpecCApp_spec r.unop] [GOAL] case a X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) r s : (InducedCategory (Opens (PrimeSpectrum ↑(Γ.obj (op X)))) basicOpen)ᵒᵖ f : r ⟶ s ⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen r.unop) ≫ ((inducedFunctor basicOpen).op ⋙ (structureSheaf ↑(Γ.obj (op X))).val).map f) ≫ toΓSpecCApp X s.unop = toToΓSpecMapBasicOpen X r.unop ≫ ((inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)).val).map f [PROOFSTEP] convert X.toΓSpecCApp_spec s.unop [GOAL] case h.e'_3.h X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) r s : (InducedCategory (Opens (PrimeSpectrum ↑(Γ.obj (op X)))) basicOpen)ᵒᵖ f : r ⟶ s e_1✝ : (CommRingCat.of ↑(Γ.obj (op X)) ⟶ ((inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)).val).obj s) = (CommRingCat.of ↑(Γ.obj (op X)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X s.unop))) ⊢ toToΓSpecMapBasicOpen X r.unop ≫ ((inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)).val).map f = toToΓSpecMapBasicOpen X s.unop [PROOFSTEP] symm [GOAL] case h.e'_3.h X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) r s : (InducedCategory (Opens (PrimeSpectrum ↑(Γ.obj (op X)))) basicOpen)ᵒᵖ f : r ⟶ s e_1✝ : (CommRingCat.of ↑(Γ.obj (op X)) ⟶ ((inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)).val).obj s) = (CommRingCat.of ↑(Γ.obj (op X)) ⟶ X.presheaf.obj (op (toΓSpecMapBasicOpen X s.unop))) ⊢ toToΓSpecMapBasicOpen X s.unop = toToΓSpecMapBasicOpen X r.unop ≫ ((inducedFunctor basicOpen).op ⋙ ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)).val).map f [PROOFSTEP] apply X.presheaf.map_comp [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ NatTrans.app (toΓSpecSheafedSpace X).c (op (basicOpen r)) = toΓSpecCApp X r [PROOFSTEP] have := TopCat.Sheaf.extend_hom_app (Spec.toSheafedSpace.obj (op (Γ.obj (op X)))).presheaf ((TopCat.Sheaf.pushforward X.toΓSpecBase).obj X.𝒪) isBasis_basic_opens X.toΓSpecCBasicOpens r [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) this : NatTrans.app (↑(TopCat.Sheaf.restrictHomEquivHom (Spec.toSheafedSpace.obj (op (Γ.obj (op X)))).presheaf ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)) (_ : Opens.IsBasis (Set.range basicOpen))) (toΓSpecCBasicOpens X)) (op (basicOpen r)) = NatTrans.app (toΓSpecCBasicOpens X) (op r) ⊢ NatTrans.app (toΓSpecSheafedSpace X).c (op (basicOpen r)) = toΓSpecCApp X r [PROOFSTEP] dsimp at this [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) this : NatTrans.app (↑(TopCat.Sheaf.restrictHomEquivHom (structureSheaf ↑(X.presheaf.obj (op ⊤))).val ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)) (_ : Opens.IsBasis (Set.range basicOpen))) (toΓSpecCBasicOpens X)) (op (basicOpen r)) = toΓSpecCApp X r ⊢ NatTrans.app (toΓSpecSheafedSpace X).c (op (basicOpen r)) = toΓSpecCApp X r [PROOFSTEP] rw [← this] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) this : NatTrans.app (↑(TopCat.Sheaf.restrictHomEquivHom (structureSheaf ↑(X.presheaf.obj (op ⊤))).val ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)) (_ : Opens.IsBasis (Set.range basicOpen))) (toΓSpecCBasicOpens X)) (op (basicOpen r)) = toΓSpecCApp X r ⊢ NatTrans.app (toΓSpecSheafedSpace X).c (op (basicOpen r)) = NatTrans.app (↑(TopCat.Sheaf.restrictHomEquivHom (structureSheaf ↑(X.presheaf.obj (op ⊤))).val ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)) (_ : Opens.IsBasis (Set.range basicOpen))) (toΓSpecCBasicOpens X)) (op (basicOpen r)) [PROOFSTEP] dsimp [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) this : NatTrans.app (↑(TopCat.Sheaf.restrictHomEquivHom (structureSheaf ↑(X.presheaf.obj (op ⊤))).val ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)) (_ : Opens.IsBasis (Set.range basicOpen))) (toΓSpecCBasicOpens X)) (op (basicOpen r)) = toΓSpecCApp X r ⊢ NatTrans.app (↑(TopCat.Sheaf.restrictHomEquivHom (structureSheaf ↑(X.presheaf.obj (op ⊤))).val ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)) (_ : Opens.IsBasis (Set.range basicOpen))) (toΓSpecCBasicOpens X)) (op (basicOpen r)) = NatTrans.app (↑(TopCat.Sheaf.restrictHomEquivHom (structureSheaf ↑(X.presheaf.obj (op ⊤))).val ((TopCat.Sheaf.pushforward (toΓSpecBase X)).obj (𝒪 X)) (_ : Opens.IsBasis (Set.range basicOpen))) (toΓSpecCBasicOpens X)) (op (basicOpen r)) [PROOFSTEP] congr [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ toStalk (↑(op (Γ.obj (op X))).unop) (↑(toΓSpecSheafedSpace X).base x) ≫ PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x = ΓToStalk X x [PROOFSTEP] rw [PresheafedSpace.stalkMap] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ toStalk (↑(op (Γ.obj (op X))).unop) (↑(toΓSpecSheafedSpace X).base x) ≫ (stalkFunctor CommRingCat (↑(toΓSpecSheafedSpace X).base x)).map (toΓSpecSheafedSpace X).c ≫ stalkPushforward CommRingCat (toΓSpecSheafedSpace X).base X.presheaf x = ΓToStalk X x [PROOFSTEP] erw [← toOpen_germ _ (basicOpen (1 : Γ.obj (op X))) ⟨X.toΓSpecFun x, by rw [basicOpen_one]; trivial⟩] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ toΓSpecFun X x ∈ basicOpen 1 [PROOFSTEP] rw [basicOpen_one] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ toΓSpecFun X x ∈ ⊤ [PROOFSTEP] trivial [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫ germ (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) }) ≫ (stalkFunctor CommRingCat (↑(toΓSpecSheafedSpace X).base x)).map (toΓSpecSheafedSpace X).c ≫ stalkPushforward CommRingCat (toΓSpecSheafedSpace X).base X.presheaf x = ΓToStalk X x [PROOFSTEP] rw [← Category.assoc, Category.assoc (toOpen _ _)] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫ germ (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) } ≫ (stalkFunctor CommRingCat (↑(toΓSpecSheafedSpace X).base x)).map (toΓSpecSheafedSpace X).c) ≫ stalkPushforward CommRingCat (toΓSpecSheafedSpace X).base X.presheaf x = ΓToStalk X x [PROOFSTEP] erw [stalkFunctor_map_germ] -- Porting note : was `rw [←assoc, toΓSpecSheafedSpace_app_spec]`, but Lean did not like it. [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫ NatTrans.app (toΓSpecSheafedSpace X).c (op (basicOpen 1)) ≫ germ ((toΓSpecSheafedSpace X).base _* X.presheaf) { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) }) ≫ stalkPushforward CommRingCat (toΓSpecSheafedSpace X).base X.presheaf x = ΓToStalk X x [PROOFSTEP] rw [toΓSpecSheafedSpace_app_spec_assoc] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ (toToΓSpecMapBasicOpen X 1 ≫ germ ((toΓSpecSheafedSpace X).base _* X.presheaf) { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) }) ≫ stalkPushforward CommRingCat (toΓSpecSheafedSpace X).base X.presheaf x = ΓToStalk X x [PROOFSTEP] unfold ΓToStalk [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ (toToΓSpecMapBasicOpen X 1 ≫ germ ((toΓSpecSheafedSpace X).base _* X.presheaf) { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) }) ≫ stalkPushforward CommRingCat (toΓSpecSheafedSpace X).base X.presheaf x = germ X.presheaf { val := x, property := trivial } [PROOFSTEP] rw [← stalkPushforward_germ _ X.toΓSpecBase X.presheaf ⊤] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ (toToΓSpecMapBasicOpen X 1 ≫ germ ((toΓSpecSheafedSpace X).base _* X.presheaf) { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) }) ≫ stalkPushforward CommRingCat (toΓSpecSheafedSpace X).base X.presheaf x = germ (toΓSpecBase X _* X.presheaf) { val := ↑(toΓSpecBase X) ↑{ val := x, property := trivial }, property := (_ : ↑{ val := x, property := trivial } ∈ (Opens.map (toΓSpecBase X)).obj ⊤) } ≫ stalkPushforward CommRingCat (toΓSpecBase X) X.presheaf ↑{ val := x, property := trivial } [PROOFSTEP] congr 1 [GOAL] case e_a X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ toToΓSpecMapBasicOpen X 1 ≫ germ ((toΓSpecSheafedSpace X).base _* X.presheaf) { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) } = germ (toΓSpecBase X _* X.presheaf) { val := ↑(toΓSpecBase X) ↑{ val := x, property := trivial }, property := (_ : ↑{ val := x, property := trivial } ∈ (Opens.map (toΓSpecBase X)).obj ⊤) } [PROOFSTEP] change (X.toΓSpecBase _* X.presheaf).map le_top.hom.op ≫ _ = _ [GOAL] case e_a X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑(toTopCat X) ⊢ (toΓSpecBase X _* X.presheaf).map (LE.le.hom (_ : { carrier := {x | ¬1 ∈ x.asIdeal}, is_open' := (_ : ∃ y, zeroLocus y = {x | ¬1 ∈ x.asIdeal}ᶜ) } ≤ ⊤)).op ≫ germ ((toΓSpecSheafedSpace X).base _* X.presheaf) { val := toΓSpecFun X x, property := (_ : toΓSpecFun X x ∈ basicOpen 1) } = germ (toΓSpecBase X _* X.presheaf) { val := ↑(toΓSpecBase X) ↑{ val := x, property := trivial }, property := (_ : ↑{ val := x, property := trivial } ∈ (Opens.map (toΓSpecBase X)).obj ⊤) } [PROOFSTEP] apply germ_res [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ ∀ (x : ↑↑X.toPresheafedSpace), IsLocalRingHom (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) [PROOFSTEP] intro x [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace ⊢ IsLocalRingHom (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) [PROOFSTEP] let p : PrimeSpectrum (Γ.obj (op X)) := X.toΓSpecFun x [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x ⊢ IsLocalRingHom (PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) [PROOFSTEP] constructor -- show stalk map is local hom ↓ [GOAL] case map_nonunit X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x ⊢ ∀ (a : ↑(PresheafedSpace.stalk (Spec.locallyRingedSpaceObj (Γ.obj (op X))).toSheafedSpace.toPresheafedSpace (↑(toΓSpecSheafedSpace X).base x))), IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) a) → IsUnit a [PROOFSTEP] let S := (structureSheaf _).presheaf.stalk p [GOAL] case map_nonunit X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p ⊢ ∀ (a : ↑(PresheafedSpace.stalk (Spec.locallyRingedSpaceObj (Γ.obj (op X))).toSheafedSpace.toPresheafedSpace (↑(toΓSpecSheafedSpace X).base x))), IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) a) → IsUnit a [PROOFSTEP] rintro (t : S) ht [GOAL] case map_nonunit X : LocallyRingedSpace r : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) ⊢ IsUnit t [PROOFSTEP] obtain ⟨⟨r, s⟩, he⟩ := IsLocalization.surj p.asIdeal.primeCompl t [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } he : t * ↑(algebraMap ↑(Γ.obj (op X)) ↑S) ↑(r, s).snd = ↑(algebraMap ↑(Γ.obj (op X)) ↑S) (r, s).fst ⊢ IsUnit t [PROOFSTEP] dsimp at he [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } he : t * ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ IsUnit t [PROOFSTEP] set t' := _ [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } he : t * ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r t' : ?m.142259 := ?m.142260 ⊢ IsUnit t [PROOFSTEP] change t * t' = _ at he [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ IsUnit t [PROOFSTEP] apply isUnit_of_mul_isUnit_left (y := t') [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ IsUnit (t * t') [PROOFSTEP] rw [he] [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ IsUnit (↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r) [PROOFSTEP] refine' IsLocalization.map_units S (⟨r, _⟩ : p.asIdeal.primeCompl) [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ r ∈ Ideal.primeCompl p.asIdeal [PROOFSTEP] apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ IsUnit (↑(ΓToStalk X x) r) [PROOFSTEP] rw [← toStalk_stalkMap_toΓSpec] [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ IsUnit (↑(toStalk (↑(op (Γ.obj (op X))).unop) (↑(toΓSpecSheafedSpace X).base x) ≫ PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) r) [PROOFSTEP] erw [comp_apply, ← he] [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) (t * t')) [PROOFSTEP] rw [RingHom.map_mul] -- Porting note : `IsLocalization.map_units` and the goal needs to be simplified before Lean -- realize it is useful [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r ⊢ IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t * ↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t') [PROOFSTEP] have := IsLocalization.map_units (R := Γ.obj (op X)) S s [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r this : IsUnit (↑(algebraMap ↑(Γ.obj (op X)) ↑S) ↑s) ⊢ IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t * ↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t') [PROOFSTEP] dsimp at this ⊢ [GOAL] case map_nonunit.intro.mk X : LocallyRingedSpace r✝ : ↑(Γ.obj (op X)) x : ↑↑X.toPresheafedSpace p : PrimeSpectrum ↑(Γ.obj (op X)) := toΓSpecFun X x S : CommRingCat := TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑(Γ.obj (op X)))) p t : ↑S ht : IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t) r : ↑(Γ.obj (op X)) s : { x // x ∈ Ideal.primeCompl p.asIdeal } t' : ↑S := ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s he : t * t' = ↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) r this : IsUnit (↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s) ⊢ IsUnit (↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) t * ↑(PresheafedSpace.stalkMap (toΓSpecSheafedSpace X) x) (↑(toStalk (↑(X.presheaf.obj (op ⊤))) (toΓSpecFun X x)) ↑s)) [PROOFSTEP] refine ht.mul <| this.map _ [GOAL] X✝ : LocallyRingedSpace r : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R w : (toΓSpec X).val.base ≫ (Spec.locallyRingedSpaceMap f).val.base = β.val.base h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) ⊢ toΓSpec X ≫ Spec.locallyRingedSpaceMap f = β [PROOFSTEP] ext1 -- Porting note : need more hand holding here [GOAL] case h X✝ : LocallyRingedSpace r : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R w : (toΓSpec X).val.base ≫ (Spec.locallyRingedSpaceMap f).val.base = β.val.base h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) ⊢ (toΓSpec X ≫ Spec.locallyRingedSpaceMap f).val = β.val [PROOFSTEP] change (X.toΓSpec.1 ≫ _).base = _ at w [GOAL] case h X✝ : LocallyRingedSpace r : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base ⊢ (toΓSpec X ≫ Spec.locallyRingedSpaceMap f).val = β.val [PROOFSTEP] apply Spec.basicOpen_hom_ext w [GOAL] case h X✝ : LocallyRingedSpace r : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base ⊢ ∀ (r : ↑R), let U := basicOpen r; (toOpen (↑R) U ≫ NatTrans.app ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).c (op U)) ≫ X.presheaf.map (eqToHom (_ : (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) = (Opens.map β.val.base).op.obj (op U))) = toOpen (↑R) U ≫ NatTrans.app β.val.c (op U) [PROOFSTEP] intro r U [GOAL] case h X✝ : LocallyRingedSpace r✝ : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base r : ↑R U : Opens (PrimeSpectrum ↑R) := basicOpen r ⊢ (toOpen (↑R) U ≫ NatTrans.app ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).c (op U)) ≫ X.presheaf.map (eqToHom (_ : (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) = (Opens.map β.val.base).op.obj (op U))) = toOpen (↑R) U ≫ NatTrans.app β.val.c (op U) [PROOFSTEP] erw [LocallyRingedSpace.comp_val_c_app] [GOAL] case h X✝ : LocallyRingedSpace r✝ : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base r : ↑R U : Opens (PrimeSpectrum ↑R) := basicOpen r ⊢ (toOpen (↑R) U ≫ NatTrans.app (Spec.locallyRingedSpaceMap f).val.c (op U) ≫ NatTrans.app (toΓSpec X).val.c (op ((Opens.map (Spec.locallyRingedSpaceMap f).val.base).obj (op U).unop))) ≫ X.presheaf.map (eqToHom (_ : (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) = (Opens.map β.val.base).op.obj (op U))) = toOpen (↑R) U ≫ NatTrans.app β.val.c (op U) [PROOFSTEP] erw [toOpen_comp_comap_assoc] [GOAL] case h X✝ : LocallyRingedSpace r✝ : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base r : ↑R U : Opens (PrimeSpectrum ↑R) := basicOpen r ⊢ (CommRingCat.ofHom f ≫ toOpen (↑(Γ.obj (op X))) (↑(Opens.comap (PrimeSpectrum.comap f)) U) ≫ NatTrans.app (toΓSpec X).val.c (op ((Opens.map (Spec.locallyRingedSpaceMap f).val.base).obj (op U).unop))) ≫ X.presheaf.map (eqToHom (_ : (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) = (Opens.map β.val.base).op.obj (op U))) = toOpen (↑R) U ≫ NatTrans.app β.val.c (op U) [PROOFSTEP] rw [Category.assoc] [GOAL] case h X✝ : LocallyRingedSpace r✝ : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base r : ↑R U : Opens (PrimeSpectrum ↑R) := basicOpen r ⊢ CommRingCat.ofHom f ≫ (toOpen (↑(Γ.obj (op X))) (↑(Opens.comap (PrimeSpectrum.comap f)) U) ≫ NatTrans.app (toΓSpec X).val.c (op ((Opens.map (Spec.locallyRingedSpaceMap f).val.base).obj (op U).unop))) ≫ X.presheaf.map (eqToHom (_ : (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) = (Opens.map β.val.base).op.obj (op U))) = toOpen (↑R) U ≫ NatTrans.app β.val.c (op U) [PROOFSTEP] erw [toΓSpecSheafedSpace_app_spec, ← X.presheaf.map_comp] [GOAL] case h X✝ : LocallyRingedSpace r✝ : ↑(Γ.obj (op X✝)) X : LocallyRingedSpace R : CommRingCat f : R ⟶ Γ.obj (op X) β : X ⟶ Spec.locallyRingedSpaceObj R h : ∀ (r : ↑R), f ≫ X.presheaf.map (homOfLE (_ : (Opens.map β.val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑R) (basicOpen r) ≫ NatTrans.app β.val.c (op (basicOpen r)) w : ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base = β.val.base r : ↑R U : Opens (PrimeSpectrum ↑R) := basicOpen r ⊢ CommRingCat.ofHom f ≫ X.presheaf.map ((Opens.leTop (toΓSpecMapBasicOpen X (↑f r))).op ≫ eqToHom (_ : (Opens.map ((toΓSpec X).val ≫ (Spec.locallyRingedSpaceMap f).val).base).op.obj (op U) = (Opens.map β.val.base).op.obj (op U))) = toOpen (↑R) U ≫ NatTrans.app β.val.c (op U) [PROOFSTEP] convert h r using 1 [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ toSpecΓ (Γ.obj (op X)) ≫ NatTrans.app (toΓSpec X).val.c (op ⊤) = 𝟙 (Γ.obj (op X)) [PROOFSTEP] unfold toSpecΓ [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ toOpen ↑(Γ.obj (op X)) ⊤ ≫ NatTrans.app (toΓSpec X).val.c (op ⊤) = 𝟙 (Γ.obj (op X)) [PROOFSTEP] rw [← toOpen_res _ (basicOpen (1 : Γ.obj (op X))) ⊤ (eqToHom basicOpen_one.symm)] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫ (structureSheaf ↑(Γ.obj (op X))).val.map (eqToHom (_ : ⊤ = basicOpen 1)).op) ≫ NatTrans.app (toΓSpec X).val.c (op ⊤) = 𝟙 (Γ.obj (op X)) [PROOFSTEP] erw [Category.assoc] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫ (structureSheaf ↑(Γ.obj (op X))).val.map (eqToHom (_ : ⊤ = basicOpen 1)).op ≫ NatTrans.app (toΓSpec X).val.c (op ⊤) = 𝟙 (Γ.obj (op X)) [PROOFSTEP] rw [NatTrans.naturality, ← Category.assoc] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ (toOpen (↑(Γ.obj (op X))) (basicOpen 1) ≫ NatTrans.app (toΓSpec X).val.c (op (basicOpen 1))) ≫ ((toΓSpec X).val.base _* X.presheaf).map (eqToHom (_ : ⊤ = basicOpen 1)).op = 𝟙 (Γ.obj (op X)) [PROOFSTEP] erw [X.toΓSpecSheafedSpace_app_spec 1, ← Functor.map_comp] [GOAL] X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ X.presheaf.map ((Opens.leTop (toΓSpecMapBasicOpen X 1)).op ≫ (Opens.map (toΓSpec X).val.base).op.map (eqToHom (_ : ⊤ = basicOpen 1)).op) = 𝟙 (Γ.obj (op X)) [PROOFSTEP] convert eqToHom_map X.presheaf _ [GOAL] case convert_3 X : LocallyRingedSpace r : ↑(Γ.obj (op X)) ⊢ op ⊤ = (Opens.map (toΓSpec X).val.base).op.obj (op ⊤) [PROOFSTEP] rfl [GOAL] X Y : LocallyRingedSpace f : X ⟶ Y ⊢ (𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y = toΓSpec X ≫ (Γ.rightOp ⋙ Spec.toLocallyRingedSpace).map f [PROOFSTEP] symm [GOAL] X Y : LocallyRingedSpace f : X ⟶ Y ⊢ toΓSpec X ≫ (Γ.rightOp ⋙ Spec.toLocallyRingedSpace).map f = (𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y [PROOFSTEP] apply LocallyRingedSpace.comp_ring_hom_ext [GOAL] case w X Y : LocallyRingedSpace f : X ⟶ Y ⊢ (toΓSpec ((𝟭 LocallyRingedSpace).obj X)).val.base ≫ (Spec.locallyRingedSpaceMap (Γ.rightOp.map f).unop).val.base = ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.base [PROOFSTEP] ext1 x [GOAL] case w.w X Y : LocallyRingedSpace f : X ⟶ Y x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace ⊢ ↑((toΓSpec ((𝟭 LocallyRingedSpace).obj X)).val.base ≫ (Spec.locallyRingedSpaceMap (Γ.rightOp.map f).unop).val.base) x = ↑((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.base x [PROOFSTEP] dsimp [Spec.topMap, LocallyRingedSpace.toΓSpecFun] --Porting Note: Had to add the next four lines [GOAL] case w.w X Y : LocallyRingedSpace f : X ⟶ Y x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace ⊢ ↑(toΓSpecBase X ≫ PrimeSpectrum.comap (NatTrans.app f.val.c (op ⊤))) x = ↑(f.val.base ≫ toΓSpecBase Y) x [PROOFSTEP] rw [comp_apply, comp_apply] [GOAL] case w.w X Y : LocallyRingedSpace f : X ⟶ Y x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace ⊢ ↑(PrimeSpectrum.comap (NatTrans.app f.val.c (op ⊤))) (↑(toΓSpecBase X) x) = ↑(toΓSpecBase Y) (↑f.val.base x) [PROOFSTEP] dsimp [toΓSpecBase] [GOAL] case w.w X Y : LocallyRingedSpace f : X ⟶ Y x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace ⊢ ↑(PrimeSpectrum.comap (NatTrans.app f.val.c (op ⊤))) (↑(ContinuousMap.mk (toΓSpecFun X)) x) = ↑(ContinuousMap.mk (toΓSpecFun Y)) (↑f.val.base x) [PROOFSTEP] rw [ContinuousMap.coe_mk, ContinuousMap.coe_mk] [GOAL] case w.w X Y : LocallyRingedSpace f : X ⟶ Y x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace ⊢ ↑(PrimeSpectrum.comap (NatTrans.app f.val.c (op ⊤))) (toΓSpecFun X x) = toΓSpecFun Y (↑f.val.base x) [PROOFSTEP] dsimp [toΓSpecFun] [GOAL] case w.w X Y : LocallyRingedSpace f : X ⟶ Y x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace ⊢ ↑(PrimeSpectrum.comap (NatTrans.app f.val.c (op ⊤))) (↑(PrimeSpectrum.comap (ΓToStalk X x)) (LocalRing.closedPoint ↑(TopCat.Presheaf.stalk X.presheaf x))) = ↑(PrimeSpectrum.comap (ΓToStalk Y (↑f.val.base x))) (LocalRing.closedPoint ↑(TopCat.Presheaf.stalk Y.presheaf (↑f.val.base x))) [PROOFSTEP] rw [← LocalRing.comap_closedPoint (PresheafedSpace.stalkMap f.val x), ← PrimeSpectrum.comap_comp_apply, ← PrimeSpectrum.comap_comp_apply] [GOAL] case w.w X Y : LocallyRingedSpace f : X ⟶ Y x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace ⊢ ↑(PrimeSpectrum.comap (RingHom.comp (ΓToStalk X x) (NatTrans.app f.val.c (op ⊤)))) (LocalRing.closedPoint ↑(TopCat.Presheaf.stalk X.presheaf x)) = ↑(PrimeSpectrum.comap (RingHom.comp (PresheafedSpace.stalkMap f.val x) (ΓToStalk Y (↑f.val.base x)))) (LocalRing.closedPoint ↑(PresheafedSpace.stalk X.toPresheafedSpace x)) [PROOFSTEP] congr 2 [GOAL] case w.w.e_a.e_f X Y : LocallyRingedSpace f : X ⟶ Y x : (forget TopCat).obj ↑((𝟭 LocallyRingedSpace).obj X).toPresheafedSpace ⊢ RingHom.comp (ΓToStalk X x) (NatTrans.app f.val.c (op ⊤)) = RingHom.comp (PresheafedSpace.stalkMap f.val x) (ΓToStalk Y (↑f.val.base x)) [PROOFSTEP] exact (PresheafedSpace.stalkMap_germ f.1 ⊤ ⟨x, trivial⟩).symm [GOAL] case h X Y : LocallyRingedSpace f : X ⟶ Y ⊢ ∀ (r : ↑(Γ.rightOp.obj Y).unop), (Γ.rightOp.map f).unop ≫ ((𝟭 LocallyRingedSpace).obj X).presheaf.map (homOfLE (_ : (Opens.map ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑(Γ.rightOp.obj Y).unop) (basicOpen r) ≫ NatTrans.app ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.c (op (basicOpen r)) [PROOFSTEP] intro r [GOAL] case h X Y : LocallyRingedSpace f : X ⟶ Y r : ↑(Γ.rightOp.obj Y).unop ⊢ (Γ.rightOp.map f).unop ≫ ((𝟭 LocallyRingedSpace).obj X).presheaf.map (homOfLE (_ : (Opens.map ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑(Γ.rightOp.obj Y).unop) (basicOpen r) ≫ NatTrans.app ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.c (op (basicOpen r)) [PROOFSTEP] rw [LocallyRingedSpace.comp_val_c_app, ← Category.assoc] [GOAL] case h X Y : LocallyRingedSpace f : X ⟶ Y r : ↑(Γ.rightOp.obj Y).unop ⊢ (Γ.rightOp.map f).unop ≫ ((𝟭 LocallyRingedSpace).obj X).presheaf.map (homOfLE (_ : (Opens.map ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.base).obj (basicOpen r) ≤ ⊤)).op = (toOpen (↑(Γ.rightOp.obj Y).unop) (basicOpen r) ≫ NatTrans.app (toΓSpec Y).val.c (op (basicOpen r))) ≫ NatTrans.app ((𝟭 LocallyRingedSpace).map f).val.c (op ((Opens.map (toΓSpec Y).val.base).obj (op (basicOpen r)).unop)) [PROOFSTEP] erw [Y.toΓSpecSheafedSpace_app_spec, f.1.c.naturality] [GOAL] case h X Y : LocallyRingedSpace f : X ⟶ Y r : ↑(Γ.rightOp.obj Y).unop ⊢ (Γ.rightOp.map f).unop ≫ ((𝟭 LocallyRingedSpace).obj X).presheaf.map (homOfLE (_ : (Opens.map ((𝟭 LocallyRingedSpace).map f ≫ toΓSpec Y).val.base).obj (basicOpen r) ≤ ⊤)).op = NatTrans.app f.val.c (op ⊤) ≫ (f.val.base _* X.presheaf).map (Opens.leTop (toΓSpecMapBasicOpen Y r)).op [PROOFSTEP] rfl [GOAL] R : CommRingCat ⊢ NatTrans.app identityToΓSpec (Spec.toLocallyRingedSpace.obj (op R)) ≫ Spec.toLocallyRingedSpace.map (NatTrans.app SpecΓIdentity.inv R).op = 𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R))) [PROOFSTEP] apply LocallyRingedSpace.comp_ring_hom_ext [GOAL] case w R : CommRingCat ⊢ (toΓSpec ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base ≫ (Spec.locallyRingedSpaceMap (NatTrans.app SpecΓIdentity.inv R).op.unop).val.base = (𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base [PROOFSTEP] ext (p : PrimeSpectrum R) [GOAL] case w.w R : CommRingCat p : PrimeSpectrum ↑R ⊢ ↑((toΓSpec ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base ≫ (Spec.locallyRingedSpaceMap (NatTrans.app SpecΓIdentity.inv R).op.unop).val.base) p = ↑(𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base p [PROOFSTEP] change _ = p [GOAL] case w.w R : CommRingCat p : PrimeSpectrum ↑R ⊢ ↑((toΓSpec ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base ≫ (Spec.locallyRingedSpaceMap (NatTrans.app SpecΓIdentity.inv R).op.unop).val.base) p = p [PROOFSTEP] ext x [GOAL] case w.w.asIdeal.h R : CommRingCat p : PrimeSpectrum ↑R x : ↑(op ((𝟭 CommRingCat).obj R)).unop ⊢ x ∈ (↑((toΓSpec ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base ≫ (Spec.locallyRingedSpaceMap (NatTrans.app SpecΓIdentity.inv R).op.unop).val.base) p).asIdeal ↔ x ∈ p.asIdeal [PROOFSTEP] erw [← IsLocalization.AtPrime.to_map_mem_maximal_iff ((structureSheaf R).presheaf.stalk p) p.asIdeal x] [GOAL] case w.w.asIdeal.h R : CommRingCat p : PrimeSpectrum ↑R x : ↑(op ((𝟭 CommRingCat).obj R)).unop ⊢ x ∈ (↑((toΓSpec ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base ≫ (Spec.locallyRingedSpaceMap (NatTrans.app SpecΓIdentity.inv R).op.unop).val.base) p).asIdeal ↔ ↑(algebraMap ↑R ↑(TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑R)) p)) x ∈ LocalRing.maximalIdeal ↑(TopCat.Presheaf.stalk (TopCat.Sheaf.presheaf (structureSheaf ↑R)) p) [PROOFSTEP] rfl [GOAL] case h R : CommRingCat ⊢ ∀ (r : ↑(op ((𝟭 CommRingCat).obj R)).unop), (NatTrans.app SpecΓIdentity.inv R).op.unop ≫ ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R))).presheaf.map (homOfLE (_ : (Opens.map (𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑(op ((𝟭 CommRingCat).obj R)).unop) (basicOpen r) ≫ NatTrans.app (𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.c (op (basicOpen r)) [PROOFSTEP] intro r [GOAL] case h R : CommRingCat r : ↑(op ((𝟭 CommRingCat).obj R)).unop ⊢ (NatTrans.app SpecΓIdentity.inv R).op.unop ≫ ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R))).presheaf.map (homOfLE (_ : (Opens.map (𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.base).obj (basicOpen r) ≤ ⊤)).op = toOpen (↑(op ((𝟭 CommRingCat).obj R)).unop) (basicOpen r) ≫ NatTrans.app (𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.toLocallyRingedSpace.obj (op R)))).val.c (op (basicOpen r)) [PROOFSTEP] apply toOpen_res [GOAL] ⊢ whiskerRight identityToΓSpec Γ.rightOp ≫ (Functor.associator Γ.rightOp Spec.toLocallyRingedSpace Γ.rightOp).hom ≫ whiskerLeft Γ.rightOp (NatIso.op SpecΓIdentity).inv = NatTrans.id (𝟭 LocallyRingedSpace ⋙ Γ.rightOp) [PROOFSTEP] ext X [GOAL] case w.h X : LocallyRingedSpace ⊢ NatTrans.app (whiskerRight identityToΓSpec Γ.rightOp ≫ (Functor.associator Γ.rightOp Spec.toLocallyRingedSpace Γ.rightOp).hom ≫ whiskerLeft Γ.rightOp (NatIso.op SpecΓIdentity).inv) X = NatTrans.app (NatTrans.id (𝟭 LocallyRingedSpace ⋙ Γ.rightOp)) X [PROOFSTEP] erw [Category.id_comp] [GOAL] case w.h X : LocallyRingedSpace ⊢ NatTrans.app (whiskerRight identityToΓSpec Γ.rightOp ≫ whiskerLeft Γ.rightOp (NatIso.op SpecΓIdentity).inv) X = NatTrans.app (NatTrans.id (𝟭 LocallyRingedSpace ⋙ Γ.rightOp)) X [PROOFSTEP] exact congr_arg Quiver.Hom.op (left_triangle X) [GOAL] ⊢ whiskerLeft Spec.toLocallyRingedSpace identityToΓSpec ≫ (Functor.associator Spec.toLocallyRingedSpace Γ.rightOp Spec.toLocallyRingedSpace).inv ≫ whiskerRight (NatIso.op SpecΓIdentity).inv Spec.toLocallyRingedSpace = NatTrans.id (Spec.toLocallyRingedSpace ⋙ 𝟭 LocallyRingedSpace) [PROOFSTEP] ext R : 2 -- Porting note : a little bit hand holding [GOAL] case w.h R : CommRingCatᵒᵖ ⊢ NatTrans.app (whiskerLeft Spec.toLocallyRingedSpace identityToΓSpec ≫ (Functor.associator Spec.toLocallyRingedSpace Γ.rightOp Spec.toLocallyRingedSpace).inv ≫ whiskerRight (NatIso.op SpecΓIdentity).inv Spec.toLocallyRingedSpace) R = NatTrans.app (NatTrans.id (Spec.toLocallyRingedSpace ⋙ 𝟭 LocallyRingedSpace)) R [PROOFSTEP] change identityToΓSpec.app _ ≫ 𝟙 _ ≫ Spec.toLocallyRingedSpace.map _ = 𝟙 _ [GOAL] case w.h R : CommRingCatᵒᵖ ⊢ NatTrans.app identityToΓSpec (Spec.locallyRingedSpaceObj R.unop) ≫ 𝟙 ((Γ.rightOp ⋙ Spec.toLocallyRingedSpace).obj (Spec.locallyRingedSpaceObj R.unop)) ≫ Spec.toLocallyRingedSpace.map (NatTrans.app (NatIso.op SpecΓIdentity).inv R) = 𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.locallyRingedSpaceObj R.unop)) [PROOFSTEP] simp_rw [Category.id_comp, show (NatIso.op SpecΓIdentity).inv.app R = (SpecΓIdentity.inv.app R.unop).op from rfl] [GOAL] case w.h R : CommRingCatᵒᵖ ⊢ NatTrans.app identityToΓSpec (Spec.locallyRingedSpaceObj R.unop) ≫ Spec.toLocallyRingedSpace.map (NatTrans.app SpecΓIdentity.inv R.unop).op = 𝟙 ((𝟭 LocallyRingedSpace).obj (Spec.locallyRingedSpaceObj R.unop)) [PROOFSTEP] exact right_triangle R.unop [GOAL] X : Scheme R : CommRingCatᵒᵖ f : op (Scheme.Γ.obj (op X)) ⟶ R ⊢ ↑(Adjunction.homEquiv adjunction X R) f = ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace R) f [PROOFSTEP] dsimp [adjunction, Adjunction.restrictFullyFaithful] [GOAL] X : Scheme R : CommRingCatᵒᵖ f : op (Scheme.Γ.obj (op X)) ⟶ R ⊢ ↑(equivOfFullyFaithful Scheme.forgetToLocallyRingedSpace).symm (𝟙 X.toLocallyRingedSpace ≫ ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace R) (𝟙 (op (X.presheaf.obj (op ⊤))) ≫ ↑(equivOfFullyFaithful (𝟭 CommRingCatᵒᵖ)) f ≫ 𝟙 R) ≫ 𝟙 (Spec.locallyRingedSpaceObj R.unop)) = ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace R) f [PROOFSTEP] simp only [Category.comp_id, Category.id_comp] [GOAL] X : Scheme R : CommRingCatᵒᵖ f : op (Scheme.Γ.obj (op X)) ⟶ R ⊢ ↑(equivOfFullyFaithful Scheme.forgetToLocallyRingedSpace).symm (↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace R) (↑(equivOfFullyFaithful (𝟭 CommRingCatᵒᵖ)) f)) = ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace R) f [PROOFSTEP] rfl --Porting Note: Added [GOAL] X : Scheme R : CommRingCatᵒᵖ f : X ⟶ Scheme.Spec.obj R ⊢ ↑(Adjunction.homEquiv adjunction X R).symm f = ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace R).symm f [PROOFSTEP] rw [adjunction_homEquiv] [GOAL] X : Scheme R : CommRingCatᵒᵖ f : X ⟶ Scheme.Spec.obj R ⊢ ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace R).symm f = ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace R).symm f [PROOFSTEP] rfl [GOAL] R : CommRingCatᵒᵖ ⊢ NatTrans.app adjunction.counit R = NatTrans.app locallyRingedSpaceAdjunction.counit R [PROOFSTEP] rw [← Adjunction.homEquiv_symm_id, ← Adjunction.homEquiv_symm_id, adjunction_homEquiv_symm_apply] [GOAL] R : CommRingCatᵒᵖ ⊢ ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction (Scheme.Spec.obj R).toLocallyRingedSpace R).symm (𝟙 (Scheme.Spec.obj R)) = ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction (Spec.toLocallyRingedSpace.obj R) R).symm (𝟙 (Spec.toLocallyRingedSpace.obj R)) [PROOFSTEP] rfl [GOAL] X : Scheme ⊢ NatTrans.app adjunction.unit X = NatTrans.app locallyRingedSpaceAdjunction.unit X.toLocallyRingedSpace [PROOFSTEP] rw [← Adjunction.homEquiv_id, ← Adjunction.homEquiv_id, adjunction_homEquiv_apply] [GOAL] X : Scheme ⊢ ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace (Scheme.Γ.rightOp.obj X)) (𝟙 (Scheme.Γ.rightOp.obj X)) = ↑(Adjunction.homEquiv locallyRingedSpaceAdjunction X.toLocallyRingedSpace (Γ.rightOp.obj X.toLocallyRingedSpace)) (𝟙 (Γ.rightOp.obj X.toLocallyRingedSpace)) [PROOFSTEP] rfl [GOAL] ⊢ IsIso locallyRingedSpaceAdjunction.counit [PROOFSTEP] dsimp only [locallyRingedSpaceAdjunction, Adjunction.mkOfUnitCounit_counit] -- Porting Note: `dsimp` was unnecessary and had to make this explicit [GOAL] ⊢ IsIso (NatIso.op SpecΓIdentity).inv [PROOFSTEP] convert IsIso.of_iso_inv (NatIso.op SpecΓIdentity) using 1 [GOAL] ⊢ IsIso adjunction.counit [PROOFSTEP] apply (config := { allowSynthFailures := true }) NatIso.isIso_of_isIso_app [GOAL] case inst ⊢ ∀ (X : CommRingCatᵒᵖ), IsIso (NatTrans.app adjunction.counit X) [PROOFSTEP] intro R [GOAL] case inst R : CommRingCatᵒᵖ ⊢ IsIso (NatTrans.app adjunction.counit R) [PROOFSTEP] rw [adjunction_counit_app] [GOAL] case inst R : CommRingCatᵒᵖ ⊢ IsIso (NatTrans.app locallyRingedSpaceAdjunction.counit R) [PROOFSTEP] infer_instance [GOAL] X : Scheme ⊢ NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = NatTrans.app SpecΓIdentity.hom (X.presheaf.obj (op ⊤)) [PROOFSTEP] have := congr_app ΓSpec.adjunction.left_triangle X [GOAL] X : Scheme this : NatTrans.app (whiskerRight adjunction.unit Scheme.Γ.rightOp ≫ whiskerLeft Scheme.Γ.rightOp adjunction.counit) X = NatTrans.app (𝟙 (𝟭 Scheme ⋙ Scheme.Γ.rightOp)) X ⊢ NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = NatTrans.app SpecΓIdentity.hom (X.presheaf.obj (op ⊤)) [PROOFSTEP] dsimp at this [GOAL] X : Scheme this : (NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤)).op ≫ NatTrans.app adjunction.counit (op (X.presheaf.obj (op ⊤))) = 𝟙 (op (X.presheaf.obj (op ⊤))) ⊢ NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = NatTrans.app SpecΓIdentity.hom (X.presheaf.obj (op ⊤)) [PROOFSTEP] rw [← IsIso.eq_comp_inv] at this [GOAL] X : Scheme this : (NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤)).op = 𝟙 (op (X.presheaf.obj (op ⊤))) ≫ inv (NatTrans.app adjunction.counit (op (X.presheaf.obj (op ⊤)))) ⊢ NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = NatTrans.app SpecΓIdentity.hom (X.presheaf.obj (op ⊤)) [PROOFSTEP] simp only [adjunction_counit_app, locallyRingedSpaceAdjunction_counit, NatIso.op_inv, NatTrans.op_app, unop_op, Functor.id_obj, Functor.comp_obj, Functor.rightOp_obj, Spec.toLocallyRingedSpace_obj, Γ_obj, Spec.locallyRingedSpaceObj_toSheafedSpace, Spec.sheafedSpaceObj_carrier, Spec.sheafedSpaceObj_presheaf, SpecΓIdentity_inv_app, Category.id_comp] at this [GOAL] X : Scheme this : (NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤)).op = inv (toSpecΓ (X.presheaf.obj (op ⊤))).op ⊢ NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = NatTrans.app SpecΓIdentity.hom (X.presheaf.obj (op ⊤)) [PROOFSTEP] rw [← op_inv, Quiver.Hom.op_inj.eq_iff] at this [GOAL] X : Scheme this : NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = inv (toSpecΓ (X.presheaf.obj (op ⊤))) ⊢ NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = NatTrans.app SpecΓIdentity.hom (X.presheaf.obj (op ⊤)) [PROOFSTEP] rw [SpecΓIdentity_hom_app] [GOAL] X : Scheme this : NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = inv (toSpecΓ (X.presheaf.obj (op ⊤))) ⊢ NatTrans.app (NatTrans.app adjunction.unit X).val.c (op ⊤) = inv (toSpecΓ (X.presheaf.obj (op ⊤))) [PROOFSTEP] convert this using 1
#= Purpose: time utilities that depend on custom Types go here Difference from CoreUtils/time.jl functions here require SeisIO Types to work =# function mk_t!(C::GphysChannel, nx::Integer, ts_new::Int64) T = Array{Int64, 2}(undef, 2, 2) setindex!(T, one(Int64), 1) setindex!(T, nx, 2) setindex!(T, ts_new, 3) setindex!(T, zero(Int64), 4) setfield!(C, :t, T) return nothing end function check_for_gap!(S::GphysData, i::Integer, ts_new::Int64, nx::Integer, v::Integer) Δ = round(Int64, sμ / getindex(getfield(S, :fs), i)) T = getindex(getfield(S, :t), i) T1 = t_extend(T, ts_new, nx, Δ) if T1 != nothing if v > 1 te_old = endtime(T, Δ) δt = ts_new - te_old (v > 1) && println(stdout, lpad(S.id[i], 15), ": time difference = ", lpad(δt, 16), " μs (old end = ", lpad(te_old, 16), ", new start = ", lpad(ts_new, 16), ", gap = ", lpad(δt-Δ, 16), " μs)") end S.t[i] = T1 end return nothing end
||| A small library introducing string positions ||| This can be used as an alternative to unpacking a string into a list of ||| characters module Data.String.Position import Data.String %default total ||| @ValidPosition points to an existing character into ||| @str its parameter string ||| Do NOT publicly export so that users cannot manufacture arbitrary positions export record ValidPosition (str : String) where constructor MkValidPosition ||| @currentIndex is the valid position into str currentIndex : Int ||| @parameterLength is the length of the parameter str parameterLength : Int -- TODO: add invariants? -- 0 isLength : length str === parameterLength -- 0 isIndex : (0 `LTE` currentIndex, 0 `LT` parameterLength) ||| A position is either a ValidPosition or the end of the string public export Position : String -> Type Position str = Maybe (ValidPosition str) ||| Manufacture a position by checking it is strictly inside the string export mkPosition : (str : String) -> Int -> Position str mkPosition str idx = do let len : Int = cast (length str) guard (0 <= idx && idx < len) pure (MkValidPosition idx len) ||| Move a position (note that we do not need access to the string here) export mvPosition : ValidPosition str -> Int -> Position str mvPosition (MkValidPosition pos len) idx = do guard (0 <= idx && idx < len) pure (MkValidPosition idx len) ||| Find the initial position inside the input string export init : (str : String) -> Position str init str = mkPosition str 0 ||| Move from a valid position to the next position in the string export next : ValidPosition str -> Position str next (MkValidPosition pos len) = do let idx = pos + 1 guard (idx < len) pure (MkValidPosition idx len) ||| We can safely access the character at a valid position export index : {str : _} -> ValidPosition str -> Char index pos = assert_total (strIndex str pos.currentIndex) ||| We can successfully uncons the substring starting at a `ValidPosition`. ||| Note that we can use `map uncons pos` to uncons the substring starting ||| a `Position`. export uncons : {str : _} -> ValidPosition str -> (Char, Position str) uncons pos = (index pos, next pos) ||| @span keeps munching characters of the substring starting at a given ||| position as long as the predicate is true of them. It returns the position ||| after the last successful munch. ||| Using `subString` to recover the string selected by `span` should yield ||| the same result as Data.String's `span`. That is to say we should have: ||| ``` ||| subString pos (Position.span p pos) = String.span p (subString pos Nothing) ||| ``` export span : {str : _} -> (Char -> Bool) -> Position str -> Position str span p pos = do (c, str) <- map uncons pos if p c then assert_total (span p str) else pos ||| @count computes the length of the substring one would obtain if one were ||| to filter out characters based on the predicate passed as an argument. ||| It replaces the `length (filter p (fastUnpack str))` pattern. export count : {str : _} -> (Char -> Bool) -> Position str -> Nat count p Nothing = 0 count p (Just pos) = if p (index pos) then S (assert_total (count p (next pos))) else assert_total (count p (next pos)) ||| Distance between a starting position and an end one. ||| We assume that the end position is *after* the starting one, otherwise the ||| output may be negative. export distance : (start : Position str) -> (end : Position str) -> Int distance Nothing _ = 0 distance (Just pos) pos' = let start = pos.currentIndex end = maybe pos.parameterLength currentIndex pos' in end - start ||| the substring of length `distance start end` that is contained between ||| start (inclusive) and end (exclusive). export subString : {str : _} -> (start : Position str) -> (end : Position str) -> String subString Nothing pos' = "" subString (Just pos) pos' = let start = pos.currentIndex end = maybe pos.parameterLength currentIndex pos' in assert_total (strSubstr start (end - start) str)
lemma (in normalization_semidom) normalize_power_normalize: "normalize (normalize x ^ n) = normalize (x ^ n)"
[GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Subsingleton α x : α ⊢ x ∈ zpowers 1 [PROOFSTEP] rw [Subsingleton.elim x 1] [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Subsingleton α x : α ⊢ 1 ∈ zpowers 1 [PROOFSTEP] exact mem_zpowers 1 [GOAL] α : Type u a : α inst✝¹ : Group α G : Type u_1 inst✝ : Group G h : IsCyclic G σ : G →* G ⊢ ∃ m, ∀ (g : G), ↑σ g = g ^ m [PROOFSTEP] obtain ⟨h, hG⟩ := IsCyclic.exists_generator (α := G) [GOAL] case intro α : Type u a : α inst✝¹ : Group α G : Type u_1 inst✝ : Group G h✝ : IsCyclic G σ : G →* G h : G hG : ∀ (x : G), x ∈ zpowers h ⊢ ∃ m, ∀ (g : G), ↑σ g = g ^ m [PROOFSTEP] obtain ⟨m, hm⟩ := hG (σ h) [GOAL] case intro.intro α : Type u a : α inst✝¹ : Group α G : Type u_1 inst✝ : Group G h✝ : IsCyclic G σ : G →* G h : G hG : ∀ (x : G), x ∈ zpowers h m : ℤ hm : (fun x x_1 => x ^ x_1) h m = ↑σ h ⊢ ∃ m, ∀ (g : G), ↑σ g = g ^ m [PROOFSTEP] refine' ⟨m, fun g => _⟩ [GOAL] case intro.intro α : Type u a : α inst✝¹ : Group α G : Type u_1 inst✝ : Group G h✝ : IsCyclic G σ : G →* G h : G hG : ∀ (x : G), x ∈ zpowers h m : ℤ hm : (fun x x_1 => x ^ x_1) h m = ↑σ h g : G ⊢ ↑σ g = g ^ m [PROOFSTEP] obtain ⟨n, rfl⟩ := hG g [GOAL] case intro.intro.intro α : Type u a : α inst✝¹ : Group α G : Type u_1 inst✝ : Group G h✝ : IsCyclic G σ : G →* G h : G hG : ∀ (x : G), x ∈ zpowers h m : ℤ hm : (fun x x_1 => x ^ x_1) h m = ↑σ h n : ℤ ⊢ ↑σ ((fun x x_1 => x ^ x_1) h n) = (fun x x_1 => x ^ x_1) h n ^ m [PROOFSTEP] rw [MonoidHom.map_zpow, ← hm, ← zpow_mul, ← zpow_mul'] [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α x : α hx : orderOf x = Fintype.card α ⊢ IsCyclic α [PROOFSTEP] classical use x simp_rw [← SetLike.mem_coe, ← Set.eq_univ_iff_forall] rw [← Fintype.card_congr (Equiv.Set.univ α), orderOf_eq_card_zpowers] at hx exact Set.eq_of_subset_of_card_le (Set.subset_univ _) (ge_of_eq hx) [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α x : α hx : orderOf x = Fintype.card α ⊢ IsCyclic α [PROOFSTEP] use x [GOAL] case h α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α x : α hx : orderOf x = Fintype.card α ⊢ ∀ (x_1 : α), x_1 ∈ zpowers x [PROOFSTEP] simp_rw [← SetLike.mem_coe, ← Set.eq_univ_iff_forall] [GOAL] case h α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α x : α hx : orderOf x = Fintype.card α ⊢ ↑(zpowers x) = Set.univ [PROOFSTEP] rw [← Fintype.card_congr (Equiv.Set.univ α), orderOf_eq_card_zpowers] at hx [GOAL] case h α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α x : α hx✝ : orderOf x = Fintype.card ↑Set.univ hx : Fintype.card { x_1 // x_1 ∈ zpowers x } = Fintype.card ↑Set.univ ⊢ ↑(zpowers x) = Set.univ [PROOFSTEP] exact Set.eq_of_subset_of_card_le (Set.subset_univ _) (ge_of_eq hx) [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] obtain ⟨g, hg⟩ : ∃ g : α, g ≠ 1 := Fintype.exists_ne_of_one_lt_card (h.symm ▸ hp.1.one_lt) 1 [GOAL] case intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] classical -- for Fintype (Subgroup.zpowers g) have : Fintype.card (Subgroup.zpowers g) ∣ p := by rw [← h] apply card_subgroup_dvd_card rw [Nat.dvd_prime hp.1] at this cases' this with that that · rw [Fintype.card_eq_one_iff] at that cases' that with t ht suffices g = 1 by contradiction have hgt := ht ⟨g, by change g ∈ Subgroup.zpowers g exact Subgroup.mem_zpowers g⟩ rw [← ht 1] at hgt change (⟨_, _⟩ : Subgroup.zpowers g) = ⟨_, _⟩ at hgt simpa using hgt · use g intro x rw [← h] at that rw [Subgroup.eq_top_of_card_eq _ that] exact Subgroup.mem_top _ [GOAL] case intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] have : Fintype.card (Subgroup.zpowers g) ∣ p := by rw [← h] apply card_subgroup_dvd_card [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 ⊢ Fintype.card { x // x ∈ zpowers g } ∣ p [PROOFSTEP] rw [← h] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 ⊢ Fintype.card { x // x ∈ zpowers g } ∣ Fintype.card α [PROOFSTEP] apply card_subgroup_dvd_card [GOAL] case intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 this : Fintype.card { x // x ∈ zpowers g } ∣ p ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] rw [Nat.dvd_prime hp.1] at this [GOAL] case intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 this : Fintype.card { x // x ∈ zpowers g } = 1 ∨ Fintype.card { x // x ∈ zpowers g } = p ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] cases' this with that that [GOAL] case intro.inl α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 that : Fintype.card { x // x ∈ zpowers g } = 1 ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] rw [Fintype.card_eq_one_iff] at that [GOAL] case intro.inl α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 that : ∃ x, ∀ (y : { x // x ∈ zpowers g }), y = x ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] cases' that with t ht [GOAL] case intro.inl.intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 t : { x // x ∈ zpowers g } ht : ∀ (y : { x // x ∈ zpowers g }), y = t ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] suffices g = 1 by contradiction [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 t : { x // x ∈ zpowers g } ht : ∀ (y : { x // x ∈ zpowers g }), y = t this : g = 1 ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] contradiction [GOAL] case intro.inl.intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 t : { x // x ∈ zpowers g } ht : ∀ (y : { x // x ∈ zpowers g }), y = t ⊢ g = 1 [PROOFSTEP] have hgt := ht ⟨g, by change g ∈ Subgroup.zpowers g exact Subgroup.mem_zpowers g⟩ [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 t : { x // x ∈ zpowers g } ht : ∀ (y : { x // x ∈ zpowers g }), y = t ⊢ g ∈ zpowers g [PROOFSTEP] change g ∈ Subgroup.zpowers g [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 t : { x // x ∈ zpowers g } ht : ∀ (y : { x // x ∈ zpowers g }), y = t ⊢ g ∈ zpowers g [PROOFSTEP] exact Subgroup.mem_zpowers g [GOAL] case intro.inl.intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 t : { x // x ∈ zpowers g } ht : ∀ (y : { x // x ∈ zpowers g }), y = t hgt : { val := g, property := (_ : g ∈ zpowers g) } = t ⊢ g = 1 [PROOFSTEP] rw [← ht 1] at hgt [GOAL] case intro.inl.intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 t : { x // x ∈ zpowers g } ht : ∀ (y : { x // x ∈ zpowers g }), y = t hgt : { val := g, property := (_ : g ∈ zpowers g) } = 1 ⊢ g = 1 [PROOFSTEP] change (⟨_, _⟩ : Subgroup.zpowers g) = ⟨_, _⟩ at hgt [GOAL] case intro.inl.intro α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 t : { x // x ∈ zpowers g } ht : ∀ (y : { x // x ∈ zpowers g }), y = t hgt : { val := g, property := (_ : g ∈ zpowers g) } = { val := 1, property := (_ : 1 ∈ (zpowers g).toSubmonoid) } ⊢ g = 1 [PROOFSTEP] simpa using hgt [GOAL] case intro.inr α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 that : Fintype.card { x // x ∈ zpowers g } = p ⊢ ∃ g, ∀ (x : α), x ∈ zpowers g [PROOFSTEP] use g [GOAL] case h α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 that : Fintype.card { x // x ∈ zpowers g } = p ⊢ ∀ (x : α), x ∈ zpowers g [PROOFSTEP] intro x [GOAL] case h α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 that : Fintype.card { x // x ∈ zpowers g } = p x : α ⊢ x ∈ zpowers g [PROOFSTEP] rw [← h] at that [GOAL] case h α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 that : Fintype.card { x // x ∈ zpowers g } = Fintype.card α x : α ⊢ x ∈ zpowers g [PROOFSTEP] rw [Subgroup.eq_top_of_card_eq _ that] [GOAL] case h α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p g : α hg : g ≠ 1 that : Fintype.card { x // x ∈ zpowers g } = Fintype.card α x : α ⊢ x ∈ ⊤ [PROOFSTEP] exact Subgroup.mem_top _ [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α g : α hx : ∀ (x : α), x ∈ zpowers g ⊢ orderOf g = Fintype.card α [PROOFSTEP] classical rw [orderOf_eq_card_zpowers] apply Fintype.card_of_finset' simpa using hx [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α g : α hx : ∀ (x : α), x ∈ zpowers g ⊢ orderOf g = Fintype.card α [PROOFSTEP] rw [orderOf_eq_card_zpowers] [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α g : α hx : ∀ (x : α), x ∈ zpowers g ⊢ Fintype.card { x // x ∈ zpowers g } = Fintype.card α [PROOFSTEP] apply Fintype.card_of_finset' [GOAL] case H α : Type u a : α inst✝¹ : Group α inst✝ : Fintype α g : α hx : ∀ (x : α), x ∈ zpowers g ⊢ ∀ (x : α), x ∈ Finset.univ ↔ x ∈ ↑(zpowers g) [PROOFSTEP] simpa using hx [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g ⊢ orderOf g = 0 [PROOFSTEP] classical rw [orderOf_eq_zero_iff'] refine' fun n hn hgn => _ have ho := orderOf_pos' ((isOfFinOrder_iff_pow_eq_one g).mpr ⟨n, hn, hgn⟩) obtain ⟨x, hx⟩ := Infinite.exists_not_mem_finset (Finset.image (fun x => g ^ x) <| Finset.range <| orderOf g) apply hx rw [← mem_powers_iff_mem_range_order_of' (x := g) (y := x) ho, Submonoid.mem_powers_iff] obtain ⟨k, hk⟩ := h x dsimp at hk obtain ⟨k, rfl | rfl⟩ := k.eq_nat_or_neg · exact ⟨k, by exact_mod_cast hk⟩ rw [zpow_eq_mod_orderOf] at hk have : 0 ≤ (-k % orderOf g : ℤ) := Int.emod_nonneg (-k) (by exact_mod_cast ho.ne') refine' ⟨(-k % orderOf g : ℤ).toNat, _⟩ rwa [← zpow_ofNat, Int.toNat_of_nonneg this] [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g ⊢ orderOf g = 0 [PROOFSTEP] rw [orderOf_eq_zero_iff'] [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g ⊢ ∀ (n : ℕ), 0 < n → g ^ n ≠ 1 [PROOFSTEP] refine' fun n hn hgn => _ [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ⊢ False [PROOFSTEP] have ho := orderOf_pos' ((isOfFinOrder_iff_pow_eq_one g).mpr ⟨n, hn, hgn⟩) [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g ⊢ False [PROOFSTEP] obtain ⟨x, hx⟩ := Infinite.exists_not_mem_finset (Finset.image (fun x => g ^ x) <| Finset.range <| orderOf g) [GOAL] case intro α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) ⊢ False [PROOFSTEP] apply hx [GOAL] case intro α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) ⊢ x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) [PROOFSTEP] rw [← mem_powers_iff_mem_range_order_of' (x := g) (y := x) ho, Submonoid.mem_powers_iff] [GOAL] case intro α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) ⊢ ∃ n, g ^ n = x [PROOFSTEP] obtain ⟨k, hk⟩ := h x [GOAL] case intro.intro α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℤ hk : (fun x x_1 => x ^ x_1) g k = x ⊢ ∃ n, g ^ n = x [PROOFSTEP] dsimp at hk [GOAL] case intro.intro α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℤ hk : g ^ k = x ⊢ ∃ n, g ^ n = x [PROOFSTEP] obtain ⟨k, rfl | rfl⟩ := k.eq_nat_or_neg [GOAL] case intro.intro.intro.inl α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℕ hk : g ^ ↑k = x ⊢ ∃ n, g ^ n = x [PROOFSTEP] exact ⟨k, by exact_mod_cast hk⟩ [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℕ hk : g ^ ↑k = x ⊢ g ^ k = x [PROOFSTEP] exact_mod_cast hk [GOAL] case intro.intro.intro.inr α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℕ hk : g ^ (-↑k) = x ⊢ ∃ n, g ^ n = x [PROOFSTEP] rw [zpow_eq_mod_orderOf] at hk [GOAL] case intro.intro.intro.inr α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℕ hk : g ^ (-↑k % ↑(orderOf g)) = x ⊢ ∃ n, g ^ n = x [PROOFSTEP] have : 0 ≤ (-k % orderOf g : ℤ) := Int.emod_nonneg (-k) (by exact_mod_cast ho.ne') [GOAL] α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℕ hk : g ^ (-↑k % ↑(orderOf g)) = x ⊢ ↑(orderOf g) ≠ 0 [PROOFSTEP] exact_mod_cast ho.ne' [GOAL] case intro.intro.intro.inr α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℕ hk : g ^ (-↑k % ↑(orderOf g)) = x this : 0 ≤ -↑k % ↑(orderOf g) ⊢ ∃ n, g ^ n = x [PROOFSTEP] refine' ⟨(-k % orderOf g : ℤ).toNat, _⟩ [GOAL] case intro.intro.intro.inr α : Type u a : α inst✝¹ : Group α inst✝ : Infinite α g : α h : ∀ (x : α), x ∈ zpowers g n : ℕ hn : 0 < n hgn : g ^ n = 1 ho : 0 < orderOf g x : α hx : ¬x ∈ Finset.image (fun x => g ^ x) (Finset.range (orderOf g)) k : ℕ hk : g ^ (-↑k % ↑(orderOf g)) = x this : 0 ≤ -↑k % ↑(orderOf g) ⊢ g ^ Int.toNat (-↑k % ↑(orderOf g)) = x [PROOFSTEP] rwa [← zpow_ofNat, Int.toNat_of_nonneg this] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ∃ x, x ∈ H ∧ x ≠ 1 x : α hx₁ : x ∈ H hx₂ : x ≠ 1 k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x h : Int.natAbs k = 0 ⊢ x = 1 [PROOFSTEP] rw [← hk, Int.natAbs_eq_zero.mp h, zpow_zero] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ∃ x, x ∈ H ∧ x ≠ 1 x : α hx₁ : x ∈ H hx₂ : x ≠ 1 k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x ⊢ g ^ Int.natAbs k ∈ H [PROOFSTEP] cases' k with k k [GOAL] case ofNat α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ∃ x, x ∈ H ∧ x ≠ 1 x : α hx₁ : x ∈ H hx₂ : x ≠ 1 k : ℕ hk✝ : (fun x x_1 => x ^ x_1) g (Int.ofNat k) = x hk : g ^ Int.ofNat k = x ⊢ g ^ Int.natAbs (Int.ofNat k) ∈ H [PROOFSTEP] rw [Int.ofNat_eq_coe, Int.natAbs_cast k, ← zpow_ofNat, ← Int.ofNat_eq_coe, hk] [GOAL] case ofNat α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ∃ x, x ∈ H ∧ x ≠ 1 x : α hx₁ : x ∈ H hx₂ : x ≠ 1 k : ℕ hk✝ : (fun x x_1 => x ^ x_1) g (Int.ofNat k) = x hk : g ^ Int.ofNat k = x ⊢ x ∈ H [PROOFSTEP] exact hx₁ [GOAL] case negSucc α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ∃ x, x ∈ H ∧ x ≠ 1 x : α hx₁ : x ∈ H hx₂ : x ≠ 1 k : ℕ hk✝ : (fun x x_1 => x ^ x_1) g (Int.negSucc k) = x hk : g ^ Int.negSucc k = x ⊢ g ^ Int.natAbs (Int.negSucc k) ∈ H [PROOFSTEP] rw [Int.natAbs_negSucc, ← Subgroup.inv_mem_iff H] [GOAL] case negSucc α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ∃ x, x ∈ H ∧ x ≠ 1 x : α hx₁ : x ∈ H hx₂ : x ≠ 1 k : ℕ hk✝ : (fun x x_1 => x ^ x_1) g (Int.negSucc k) = x hk : g ^ Int.negSucc k = x ⊢ (g ^ Nat.succ k)⁻¹ ∈ H [PROOFSTEP] simp_all [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x ⊢ g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H [PROOFSTEP] rw [zpow_mul] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x ⊢ (g ^ ↑(Nat.find hex)) ^ (k / ↑(Nat.find hex)) ∈ H [PROOFSTEP] apply H.zpow_mem [GOAL] case hx α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x ⊢ g ^ ↑(Nat.find hex) ∈ H [PROOFSTEP] exact_mod_cast (Nat.find_spec hex).2 [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H ⊢ g ^ (k % ↑(Nat.find hex)) * g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H [PROOFSTEP] rw [← zpow_add, Int.emod_add_ediv, hk] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H ⊢ x ∈ H [PROOFSTEP] exact hx [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H hk₃ : g ^ (k % ↑(Nat.find hex)) ∈ H ⊢ k % ↑(Nat.find hex) = ↑(Int.natAbs (k % ↑(Nat.find hex))) [PROOFSTEP] rw [Int.natAbs_of_nonneg (Int.emod_nonneg _ (Int.coe_nat_ne_zero_iff_pos.2 (Nat.find_spec hex).1))] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H hk₃ : g ^ (k % ↑(Nat.find hex)) ∈ H hk₄ : k % ↑(Nat.find hex) = ↑(Int.natAbs (k % ↑(Nat.find hex))) ⊢ g ^ Int.natAbs (k % ↑(Nat.find hex)) ∈ H [PROOFSTEP] rwa [← zpow_ofNat, ← hk₄] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H hk₃ : g ^ (k % ↑(Nat.find hex)) ∈ H hk₄ : k % ↑(Nat.find hex) = ↑(Int.natAbs (k % ↑(Nat.find hex))) hk₅ : g ^ Int.natAbs (k % ↑(Nat.find hex)) ∈ H h : ¬Int.natAbs (k % ↑(Nat.find hex)) = 0 ⊢ ↑(Int.natAbs (k % ↑(Nat.find hex))) < ↑(Nat.find hex) [PROOFSTEP] rw [← hk₄] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H hk₃ : g ^ (k % ↑(Nat.find hex)) ∈ H hk₄ : k % ↑(Nat.find hex) = ↑(Int.natAbs (k % ↑(Nat.find hex))) hk₅ : g ^ Int.natAbs (k % ↑(Nat.find hex)) ∈ H h : ¬Int.natAbs (k % ↑(Nat.find hex)) = 0 ⊢ k % ↑(Nat.find hex) < ↑(Nat.find hex) [PROOFSTEP] exact Int.emod_lt_of_pos _ (Int.coe_nat_pos.2 (Nat.find_spec hex).1) [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H hk₃ : g ^ (k % ↑(Nat.find hex)) ∈ H hk₄ : k % ↑(Nat.find hex) = ↑(Int.natAbs (k % ↑(Nat.find hex))) hk₅ : g ^ Int.natAbs (k % ↑(Nat.find hex)) ∈ H hk₆ : Int.natAbs (k % ↑(Nat.find hex)) = 0 ⊢ ↑((fun x x_1 => x ^ x_1) { val := g ^ Nat.find hex, property := (_ : g ^ Nat.find hex ∈ H) } (k / ↑(Nat.find hex))) = ↑{ val := x, property := hx } [PROOFSTEP] suffices g ^ ((Nat.find hex : ℤ) * (k / Nat.find hex : ℤ)) = x by simpa [zpow_mul] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this✝ : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H hk₃ : g ^ (k % ↑(Nat.find hex)) ∈ H hk₄ : k % ↑(Nat.find hex) = ↑(Int.natAbs (k % ↑(Nat.find hex))) hk₅ : g ^ Int.natAbs (k % ↑(Nat.find hex)) ∈ H hk₆ : Int.natAbs (k % ↑(Nat.find hex)) = 0 this : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) = x ⊢ ↑((fun x x_1 => x ^ x_1) { val := g ^ Nat.find hex, property := (_ : g ^ Nat.find hex ∈ H) } (k / ↑(Nat.find hex))) = ↑{ val := x, property := hx } [PROOFSTEP] simpa [zpow_mul] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx✝ : ∃ x, x ∈ H ∧ x ≠ 1 x✝¹ : α hx₁ : x✝¹ ∈ H hx₂ : x✝¹ ≠ 1 k✝ : ℤ hk✝² : (fun x x_1 => x ^ x_1) g k✝ = x✝¹ hk✝¹ : g ^ k✝ = x✝¹ hex : ∃ n, 0 < n ∧ g ^ n ∈ H x✝ : { x // x ∈ H } x : α hx : x ∈ H k : ℤ hk✝ : (fun x x_1 => x ^ x_1) g k = x hk : g ^ k = x hk₂ : g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) ∈ H hk₃ : g ^ (k % ↑(Nat.find hex)) ∈ H hk₄ : k % ↑(Nat.find hex) = ↑(Int.natAbs (k % ↑(Nat.find hex))) hk₅ : g ^ Int.natAbs (k % ↑(Nat.find hex)) ∈ H hk₆ : Int.natAbs (k % ↑(Nat.find hex)) = 0 ⊢ g ^ (↑(Nat.find hex) * (k / ↑(Nat.find hex))) = x [PROOFSTEP] rw [Int.mul_ediv_cancel' (Int.dvd_of_emod_eq_zero (Int.natAbs_eq_zero.mp hk₆)), hk] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ¬∃ x, x ∈ H ∧ x ≠ 1 ⊢ IsCyclic { x // x ∈ H } [PROOFSTEP] have : H = (⊥ : Subgroup α) := Subgroup.ext fun x => ⟨fun h => by simp at *; tauto, fun h => by rw [Subgroup.mem_bot.1 h]; exact H.one_mem⟩ [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ¬∃ x, x ∈ H ∧ x ≠ 1 x : α h : x ∈ H ⊢ x ∈ ⊥ [PROOFSTEP] simp at * [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g x : α h : x ∈ H hx : ∀ (x : α), x ∈ H → x = 1 ⊢ x = 1 [PROOFSTEP] tauto [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ¬∃ x, x ∈ H ∧ x ≠ 1 x : α h : x ∈ ⊥ ⊢ x ∈ H [PROOFSTEP] rw [Subgroup.mem_bot.1 h] [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ¬∃ x, x ∈ H ∧ x ≠ 1 x : α h : x ∈ ⊥ ⊢ 1 ∈ H [PROOFSTEP] exact H.one_mem [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α H : Subgroup α this✝ : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ¬∃ x, x ∈ H ∧ x ≠ 1 this : H = ⊥ ⊢ IsCyclic { x // x ∈ H } [PROOFSTEP] subst this [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : IsCyclic α this : (a : Prop) → Decidable a g : α hg : ∀ (x : α), x ∈ zpowers g hx : ¬∃ x, x ∈ ⊥ ∧ x ≠ 1 ⊢ IsCyclic { x // x ∈ ⊥ } [PROOFSTEP] infer_instance [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : (fun x x_1 => x ^ x_1) g m = x ⊢ (fun x x_1 => x ^ x_1) (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x [PROOFSTEP] dsimp at hm [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x ⊢ (fun x x_1 => x ^ x_1) (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x [PROOFSTEP] have hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 := by rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff]; exact (mem_filter.1 hx).2 [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x ⊢ g ^ (m * Nat.gcd n (Fintype.card α)) = 1 [PROOFSTEP] rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x ⊢ x ^ n = 1 [PROOFSTEP] exact (mem_filter.1 hx).2 [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ (fun x x_1 => x ^ x_1) (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x [PROOFSTEP] dsimp only [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) ^ ↑(m / (Fintype.card α / Nat.gcd n (Fintype.card α))) = x [PROOFSTEP] rw [zpow_ofNat, ← pow_mul, Nat.mul_div_cancel_left', hm] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ Fintype.card α / Nat.gcd n (Fintype.card α) ∣ m [PROOFSTEP] refine' Nat.dvd_of_mul_dvd_mul_right (gcd_pos_of_pos_left (Fintype.card α) hn0) _ [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ Fintype.card α / Nat.gcd n (Fintype.card α) * Nat.gcd n (Fintype.card α) ∣ m * Nat.gcd n (Fintype.card α) [PROOFSTEP] conv_lhs => rw [Nat.div_mul_cancel (Nat.gcd_dvd_right _ _), ← orderOf_eq_card_of_forall_mem_zpowers hg] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 | Fintype.card α / Nat.gcd n (Fintype.card α) * Nat.gcd n (Fintype.card α) [PROOFSTEP] rw [Nat.div_mul_cancel (Nat.gcd_dvd_right _ _), ← orderOf_eq_card_of_forall_mem_zpowers hg] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 | Fintype.card α / Nat.gcd n (Fintype.card α) * Nat.gcd n (Fintype.card α) [PROOFSTEP] rw [Nat.div_mul_cancel (Nat.gcd_dvd_right _ _), ← orderOf_eq_card_of_forall_mem_zpowers hg] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 | Fintype.card α / Nat.gcd n (Fintype.card α) * Nat.gcd n (Fintype.card α) [PROOFSTEP] rw [Nat.div_mul_cancel (Nat.gcd_dvd_right _ _), ← orderOf_eq_card_of_forall_mem_zpowers hg] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g x : α hx : x ∈ filter (fun a => a ^ n = 1) univ m : ℕ hm : g ^ m = x hgmn : g ^ (m * Nat.gcd n (Fintype.card α)) = 1 ⊢ orderOf g ∣ m * Nat.gcd n (Fintype.card α) [PROOFSTEP] exact orderOf_dvd_of_pow_eq_one hgmn [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g ⊢ card (Set.toFinset ↑(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))))) ≤ n [PROOFSTEP] let ⟨m, hm⟩ := Nat.gcd_dvd_right n (Fintype.card α) [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m ⊢ card (Set.toFinset ↑(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))))) ≤ n [PROOFSTEP] have hm0 : 0 < m := Nat.pos_of_ne_zero fun hm0 => by rw [hm0, mul_zero, Fintype.card_eq_zero_iff] at hm exact hm.elim' 1 [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : m = 0 ⊢ False [PROOFSTEP] rw [hm0, mul_zero, Fintype.card_eq_zero_iff] at hm [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : IsEmpty α hm0 : m = 0 ⊢ False [PROOFSTEP] exact hm.elim' 1 [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ card (Set.toFinset ↑(zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))))) ≤ n [PROOFSTEP] simp only [Set.toFinset_card, SetLike.coe_sort_coe] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card { x // x ∈ zpowers (g ^ (Fintype.card α / Nat.gcd n (Fintype.card α))) } ≤ n [PROOFSTEP] rw [← orderOf_eq_card_zpowers, orderOf_pow g, orderOf_eq_card_of_forall_mem_zpowers hg] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Fintype.card α) (Fintype.card α / Nat.gcd n (Fintype.card α)) ≤ n [PROOFSTEP] nth_rw 2 [hm] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Nat.gcd n (Fintype.card α) * m) (Fintype.card α / Nat.gcd n (Fintype.card α)) ≤ n [PROOFSTEP] nth_rw 3 [hm] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Fintype.card α / Nat.gcd (Nat.gcd n (Fintype.card α) * m) (Nat.gcd n (Fintype.card α) * m / Nat.gcd n (Fintype.card α)) ≤ n [PROOFSTEP] rw [Nat.mul_div_cancel_left _ (gcd_pos_of_pos_left _ hn0), gcd_mul_left_left, hm, Nat.mul_div_cancel _ hm0] [GOAL] α : Type u a : α inst✝³ : Group α inst✝² : DecidableEq α inst✝¹ : Fintype α inst✝ : IsCyclic α n : ℕ hn0 : 0 < n g : α hg : ∀ (x : α), x ∈ zpowers g m : ℕ hm : Fintype.card α = Nat.gcd n (Fintype.card α) * m hm0 : 0 < m ⊢ Nat.gcd n (Fintype.card α) ≤ n [PROOFSTEP] exact le_of_dvd hn0 (Nat.gcd_dvd_left _ _) [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : Finite α inst✝ : IsCyclic α ⊢ ∃ x, ∀ (y : α), y ∈ Submonoid.powers x [PROOFSTEP] simp_rw [mem_powers_iff_mem_zpowers] [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : Finite α inst✝ : IsCyclic α ⊢ ∃ x, ∀ (y : α), y ∈ zpowers x [PROOFSTEP] exact IsCyclic.exists_generator [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α ha : ∀ (x : α), x ∈ zpowers a ⊢ image (fun i => a ^ i) (range (orderOf a)) = univ [PROOFSTEP] simp_rw [← SetLike.mem_coe] at ha [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α ha : ∀ (x : α), x ∈ ↑(zpowers a) ⊢ image (fun i => a ^ i) (range (orderOf a)) = univ [PROOFSTEP] simp only [_root_.image_range_orderOf, Set.eq_univ_iff_forall.mpr ha, Set.toFinset_univ] [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α ha : ∀ (x : α), x ∈ zpowers a ⊢ image (fun i => a ^ i) (range (Fintype.card α)) = univ [PROOFSTEP] rw [← orderOf_eq_card_of_forall_mem_zpowers ha, IsCyclic.image_range_orderOf ha] [GOAL] α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n a : α b : { x // x ∈ zpowers a } ⊢ ↑b ^ orderOf a = 1 [PROOFSTEP] let ⟨i, hi⟩ := b.2 [GOAL] α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n a : α b : { x // x ∈ zpowers a } i : ℤ hi : (fun x x_1 => x ^ x_1) a i = ↑b ⊢ ↑b ^ orderOf a = 1 [PROOFSTEP] rw [← hi, ← zpow_ofNat, ← zpow_mul, mul_comm, zpow_mul, zpow_ofNat, pow_orderOf_eq_one, one_zpow] [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n ⊢ ∀ {d : ℕ}, d ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = d) univ) → card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] intro d hd hpos [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] induction' d using Nat.strongRec' with d IH [GOAL] case H α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] rcases Decidable.eq_or_ne d 0 with (rfl | hd0) [GOAL] case H.inl α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd✝ : d ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d) univ) IH : ∀ (m : ℕ), m < 0 → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : 0 ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = 0) univ) ⊢ card (filter (fun a => orderOf a = 0) univ) = φ 0 [PROOFSTEP] cases Fintype.card_ne_zero (eq_zero_of_zero_dvd hd) [GOAL] case H.inr α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] rcases card_pos.1 hpos with ⟨a, ha'⟩ [GOAL] case H.inr.intro α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] have ha : orderOf a = d := (mem_filter.1 ha').2 [GOAL] case H.inr.intro α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ha : orderOf a = d ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] have h1 : (∑ m in d.properDivisors, (univ.filter fun a : α => orderOf a = m).card) = ∑ m in d.properDivisors, φ m := by refine' Finset.sum_congr rfl fun m hm => _ simp only [mem_filter, mem_range, mem_properDivisors] at hm refine' IH m hm.2 (hm.1.trans hd) (Finset.card_pos.2 ⟨a ^ (d / m), _⟩) simp only [mem_filter, mem_univ, orderOf_pow a, ha, true_and_iff, Nat.gcd_eq_right (div_dvd_of_dvd hm.1), Nat.div_div_self hm.1 hd0] [GOAL] α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ha : orderOf a = d ⊢ ∑ m in properDivisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in properDivisors d, φ m [PROOFSTEP] refine' Finset.sum_congr rfl fun m hm => _ [GOAL] α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ha : orderOf a = d m : ℕ hm : m ∈ properDivisors d ⊢ card (filter (fun a => orderOf a = m) univ) = φ m [PROOFSTEP] simp only [mem_filter, mem_range, mem_properDivisors] at hm [GOAL] α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ha : orderOf a = d m : ℕ hm : m ∣ d ∧ m < d ⊢ card (filter (fun a => orderOf a = m) univ) = φ m [PROOFSTEP] refine' IH m hm.2 (hm.1.trans hd) (Finset.card_pos.2 ⟨a ^ (d / m), _⟩) [GOAL] α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ha : orderOf a = d m : ℕ hm : m ∣ d ∧ m < d ⊢ a ^ (d / m) ∈ filter (fun a => orderOf a = m) univ [PROOFSTEP] simp only [mem_filter, mem_univ, orderOf_pow a, ha, true_and_iff, Nat.gcd_eq_right (div_dvd_of_dvd hm.1), Nat.div_div_self hm.1 hd0] [GOAL] case H.inr.intro α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ha : orderOf a = d h1 : ∑ m in properDivisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in properDivisors d, φ m ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] have h2 : (∑ m in d.divisors, (univ.filter fun a : α => orderOf a = m).card) = ∑ m in d.divisors, φ m := by rw [← filter_dvd_eq_divisors hd0, sum_card_orderOf_eq_card_pow_eq_one hd0, filter_dvd_eq_divisors hd0, sum_totient, ← ha, card_pow_eq_one_eq_orderOf_aux hn a] [GOAL] α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ha : orderOf a = d h1 : ∑ m in properDivisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in properDivisors d, φ m ⊢ ∑ m in divisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in divisors d, φ m [PROOFSTEP] rw [← filter_dvd_eq_divisors hd0, sum_card_orderOf_eq_card_pow_eq_one hd0, filter_dvd_eq_divisors hd0, sum_totient, ← ha, card_pow_eq_one_eq_orderOf_aux hn a] [GOAL] case H.inr.intro α : Type u a✝ : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d✝ : ℕ hd✝ : d✝ ∣ Fintype.card α hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ) d : ℕ IH : ∀ (m : ℕ), m < d → m ∣ Fintype.card α → 0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m hd : d ∣ Fintype.card α hpos : 0 < card (filter (fun a => orderOf a = d) univ) hd0 : d ≠ 0 a : α ha' : a ∈ filter (fun a => orderOf a = d) univ ha : orderOf a = d h1 : ∑ m in properDivisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in properDivisors d, φ m h2 : ∑ m in divisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in divisors d, φ m ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] simpa [← cons_self_properDivisors hd0, ← h1] using h2 [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] let c := Fintype.card α [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] have hc0 : 0 < c := Fintype.card_pos_iff.2 ⟨1⟩ [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] apply card_orderOf_eq_totient_aux₁ hn hd [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c ⊢ 0 < card (filter (fun a => orderOf a = d) univ) [PROOFSTEP] by_contra h0 [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : ¬0 < card (filter (fun a => orderOf a = d) univ) ⊢ False [PROOFSTEP] simp only [not_lt, _root_.le_zero_iff, card_eq_zero] at h0 [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ ⊢ False [PROOFSTEP] apply lt_irrefl c [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ ⊢ c < c [PROOFSTEP] calc c = ∑ m in c.divisors, (univ.filter fun a : α => orderOf a = m).card := by simp only [← filter_dvd_eq_divisors hc0.ne', sum_card_orderOf_eq_card_pow_eq_one hc0.ne'] apply congr_arg card simp _ = ∑ m in c.divisors.erase d, (univ.filter fun a : α => orderOf a = m).card := by rw [eq_comm] refine' sum_subset (erase_subset _ _) fun m hm₁ hm₂ => _ have : m = d := by contrapose! hm₂ exact mem_erase_of_ne_of_mem hm₂ hm₁ simp [this, h0] _ ≤ ∑ m in c.divisors.erase d, φ m := by refine' sum_le_sum fun m hm => _ have hmc : m ∣ c := by simp only [mem_erase, mem_divisors] at hm tauto rcases(filter (fun a : α => orderOf a = m) univ).card.eq_zero_or_pos with (h1 | h1) · simp [h1] · simp [card_orderOf_eq_totient_aux₁ hn hmc h1] _ < ∑ m in c.divisors, φ m := (sum_erase_lt_of_pos (mem_divisors.2 ⟨hd, hc0.ne'⟩) (totient_pos (pos_of_dvd_of_pos hd hc0))) _ = c := sum_totient _ [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ ⊢ c = ∑ m in divisors c, card (filter (fun a => orderOf a = m) univ) [PROOFSTEP] simp only [← filter_dvd_eq_divisors hc0.ne', sum_card_orderOf_eq_card_pow_eq_one hc0.ne'] [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ ⊢ Fintype.card α = card (filter (fun x => x ^ Fintype.card α = 1) univ) [PROOFSTEP] apply congr_arg card [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ ⊢ univ = filter (fun x => x ^ Fintype.card α = 1) univ [PROOFSTEP] simp [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ ⊢ ∑ m in divisors c, card (filter (fun a => orderOf a = m) univ) = ∑ m in erase (divisors c) d, card (filter (fun a => orderOf a = m) univ) [PROOFSTEP] rw [eq_comm] [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ ⊢ ∑ m in erase (divisors c) d, card (filter (fun a => orderOf a = m) univ) = ∑ m in divisors c, card (filter (fun a => orderOf a = m) univ) [PROOFSTEP] refine' sum_subset (erase_subset _ _) fun m hm₁ hm₂ => _ [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm₁ : m ∈ divisors c hm₂ : ¬m ∈ erase (divisors c) d ⊢ card (filter (fun a => orderOf a = m) univ) = 0 [PROOFSTEP] have : m = d := by contrapose! hm₂ exact mem_erase_of_ne_of_mem hm₂ hm₁ [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm₁ : m ∈ divisors c hm₂ : ¬m ∈ erase (divisors c) d ⊢ m = d [PROOFSTEP] contrapose! hm₂ [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm₁ : m ∈ divisors c hm₂ : m ≠ d ⊢ m ∈ erase (divisors (Fintype.card α)) d [PROOFSTEP] exact mem_erase_of_ne_of_mem hm₂ hm₁ [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm₁ : m ∈ divisors c hm₂ : ¬m ∈ erase (divisors c) d this : m = d ⊢ card (filter (fun a => orderOf a = m) univ) = 0 [PROOFSTEP] simp [this, h0] [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ ⊢ ∑ m in erase (divisors c) d, card (filter (fun a => orderOf a = m) univ) ≤ ∑ m in erase (divisors c) d, φ m [PROOFSTEP] refine' sum_le_sum fun m hm => _ [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm : m ∈ erase (divisors c) d ⊢ card (filter (fun a => orderOf a = m) univ) ≤ φ m [PROOFSTEP] have hmc : m ∣ c := by simp only [mem_erase, mem_divisors] at hm tauto [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm : m ∈ erase (divisors c) d ⊢ m ∣ c [PROOFSTEP] simp only [mem_erase, mem_divisors] at hm [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm : m ≠ d ∧ m ∣ Fintype.card α ∧ Fintype.card α ≠ 0 ⊢ m ∣ c [PROOFSTEP] tauto [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm : m ∈ erase (divisors c) d hmc : m ∣ c ⊢ card (filter (fun a => orderOf a = m) univ) ≤ φ m [PROOFSTEP] rcases(filter (fun a : α => orderOf a = m) univ).card.eq_zero_or_pos with (h1 | h1) [GOAL] case inl α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm : m ∈ erase (divisors c) d hmc : m ∣ c h1 : card (filter (fun a => orderOf a = m) univ) = 0 ⊢ card (filter (fun a => orderOf a = m) univ) ≤ φ m [PROOFSTEP] simp [h1] [GOAL] case inr α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n d : ℕ hd : d ∣ Fintype.card α c : ℕ := Fintype.card α hc0 : 0 < c h0 : filter (fun a => orderOf a = d) univ = ∅ m : ℕ hm : m ∈ erase (divisors c) d hmc : m ∣ c h1 : card (filter (fun a => orderOf a = m) univ) > 0 ⊢ card (filter (fun a => orderOf a = m) univ) ≤ φ m [PROOFSTEP] simp [card_orderOf_eq_totient_aux₁ hn hmc h1] [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n ⊢ 0 < card (filter (fun a => orderOf a = Fintype.card α) univ) [PROOFSTEP] rw [card_orderOf_eq_totient_aux₂ hn dvd_rfl] [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n ⊢ 0 < φ (Fintype.card α) [PROOFSTEP] exact totient_pos (Fintype.card_pos_iff.2 ⟨1⟩) [GOAL] α✝ : Type u a : α✝ inst✝⁵ : Group α✝ inst✝⁴ : DecidableEq α✝ inst✝³ : Fintype α✝ hn✝ : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n α : Type u_1 inst✝² : AddGroup α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => n • a = 0) univ) ≤ n ⊢ IsAddCyclic α [PROOFSTEP] obtain ⟨g, hg⟩ := (@isCyclic_of_card_pow_eq_one_le (Multiplicative α) _ _ (_) hn) [GOAL] case mk.intro α✝ : Type u a : α✝ inst✝⁵ : Group α✝ inst✝⁴ : DecidableEq α✝ inst✝³ : Fintype α✝ hn✝ : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n α : Type u_1 inst✝² : AddGroup α inst✝¹ : DecidableEq α inst✝ : Fintype α hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => n • a = 0) univ) ≤ n g : Multiplicative α hg : ∀ (x : Multiplicative α), x ∈ zpowers g ⊢ IsAddCyclic α [PROOFSTEP] exact ⟨⟨g, hg⟩⟩ [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : IsCyclic α inst✝ : Fintype α d : ℕ hd : d ∣ Fintype.card α ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] classical apply card_orderOf_eq_totient_aux₂ (fun n => IsCyclic.card_pow_eq_one_le) hd [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : IsCyclic α inst✝ : Fintype α d : ℕ hd : d ∣ Fintype.card α ⊢ card (filter (fun a => orderOf a = d) univ) = φ d [PROOFSTEP] apply card_orderOf_eq_totient_aux₂ (fun n => IsCyclic.card_pow_eq_one_le) hd [GOAL] α✝ : Type u a : α✝ inst✝³ : Group α✝ α : Type u_1 inst✝² : AddGroup α inst✝¹ : IsAddCyclic α inst✝ : Fintype α d : ℕ hd : d ∣ Fintype.card α ⊢ card (filter (fun a => addOrderOf a = d) univ) = φ d [PROOFSTEP] obtain ⟨g, hg⟩ := id ‹IsAddCyclic α› [GOAL] case mk.intro α✝ : Type u a : α✝ inst✝³ : Group α✝ α : Type u_1 inst✝² : AddGroup α inst✝¹ : IsAddCyclic α inst✝ : Fintype α d : ℕ hd : d ∣ Fintype.card α g : α hg : ∀ (x : α), x ∈ AddSubgroup.zmultiples g ⊢ card (filter (fun a => addOrderOf a = d) univ) = φ d [PROOFSTEP] apply @IsCyclic.card_orderOf_eq_totient (Multiplicative α) _ ⟨⟨g, hg⟩⟩ (_) _ hd [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p ⊢ Nontrivial α [PROOFSTEP] have h' := Nat.Prime.one_lt (Fact.out (p := p.Prime)) [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p h' : 1 < p ⊢ Nontrivial α [PROOFSTEP] rw [← h] at h' [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p h' : 1 < Fintype.card α ⊢ Nontrivial α [PROOFSTEP] exact Fintype.one_lt_card_iff_nontrivial.1 h' [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p this : Nontrivial α H : Subgroup α x✝ : Normal H ⊢ H = ⊥ ∨ H = ⊤ [PROOFSTEP] classical have hcard := card_subgroup_dvd_card H rw [h, dvd_prime (Fact.out (p := p.Prime))] at hcard refine' hcard.imp (fun h1 => _) fun hp => _ · haveI := Fintype.card_le_one_iff_subsingleton.1 (le_of_eq h1) apply eq_bot_of_subsingleton · exact eq_top_of_card_eq _ (hp.trans h.symm) [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p this : Nontrivial α H : Subgroup α x✝ : Normal H ⊢ H = ⊥ ∨ H = ⊤ [PROOFSTEP] have hcard := card_subgroup_dvd_card H [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p this : Nontrivial α H : Subgroup α x✝ : Normal H hcard : Fintype.card { x // x ∈ H } ∣ Fintype.card α ⊢ H = ⊥ ∨ H = ⊤ [PROOFSTEP] rw [h, dvd_prime (Fact.out (p := p.Prime))] at hcard [GOAL] α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p this : Nontrivial α H : Subgroup α x✝ : Normal H hcard : Fintype.card { x // x ∈ H } = 1 ∨ Fintype.card { x // x ∈ H } = p ⊢ H = ⊥ ∨ H = ⊤ [PROOFSTEP] refine' hcard.imp (fun h1 => _) fun hp => _ [GOAL] case refine'_1 α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p this : Nontrivial α H : Subgroup α x✝ : Normal H hcard : Fintype.card { x // x ∈ H } = 1 ∨ Fintype.card { x // x ∈ H } = p h1 : Fintype.card { x // x ∈ H } = 1 ⊢ H = ⊥ [PROOFSTEP] haveI := Fintype.card_le_one_iff_subsingleton.1 (le_of_eq h1) [GOAL] case refine'_1 α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp : Fact (Nat.Prime p) h : Fintype.card α = p this✝ : Nontrivial α H : Subgroup α x✝ : Normal H hcard : Fintype.card { x // x ∈ H } = 1 ∨ Fintype.card { x // x ∈ H } = p h1 : Fintype.card { x // x ∈ H } = 1 this : Subsingleton { x // x ∈ H } ⊢ H = ⊥ [PROOFSTEP] apply eq_bot_of_subsingleton [GOAL] case refine'_2 α✝ : Type u a : α✝ inst✝² : Group α✝ α : Type u inst✝¹ : Group α inst✝ : Fintype α p : ℕ hp✝ : Fact (Nat.Prime p) h : Fintype.card α = p this : Nontrivial α H : Subgroup α x✝ : Normal H hcard : Fintype.card { x // x ∈ H } = 1 ∨ Fintype.card { x // x ∈ H } = p hp : Fintype.card { x // x ∈ H } = p ⊢ H = ⊤ [PROOFSTEP] exact eq_top_of_card_eq _ (hp.trans h.symm) [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } ⊢ x ^ m = ↑f a [PROOFSTEP] simpa [Subtype.ext_iff] using hm [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } hm : x ^ m = ↑f a ⊢ x ^ n = ↑f b [PROOFSTEP] simpa [Subtype.ext_iff] using hn [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } hm : x ^ m = ↑f a hn : x ^ n = ↑f b ⊢ y ^ (-m) * a ∈ MonoidHom.ker f [PROOFSTEP] rw [f.mem_ker, f.map_mul, f.map_zpow, hxy, zpow_neg x m, hm, inv_mul_self] [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } hm : x ^ m = ↑f a hn : x ^ n = ↑f b ha : y ^ (-m) * a ∈ center G ⊢ y ^ (-n) * b ∈ MonoidHom.ker f [PROOFSTEP] rw [f.mem_ker, f.map_mul, f.map_zpow, hxy, zpow_neg x n, hn, inv_mul_self] [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } hm : x ^ m = ↑f a hn : x ^ n = ↑f b ha : y ^ (-m) * a ∈ center G hb : y ^ (-n) * b ∈ center G ⊢ a * b = y ^ m * (y ^ (-m) * a * y ^ n) * (y ^ (-n) * b) [PROOFSTEP] simp [mul_assoc] [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } hm : x ^ m = ↑f a hn : x ^ n = ↑f b ha : y ^ (-m) * a ∈ center G hb : y ^ (-n) * b ∈ center G ⊢ y ^ m * (y ^ (-m) * a * y ^ n) * (y ^ (-n) * b) = y ^ m * (y ^ n * (y ^ (-m) * a)) * (y ^ (-n) * b) [PROOFSTEP] rw [mem_center_iff.1 ha] [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } hm : x ^ m = ↑f a hn : x ^ n = ↑f b ha : y ^ (-m) * a ∈ center G hb : y ^ (-n) * b ∈ center G ⊢ y ^ m * (y ^ n * (y ^ (-m) * a)) * (y ^ (-n) * b) = y ^ m * y ^ n * y ^ (-m) * (a * (y ^ (-n) * b)) [PROOFSTEP] simp [mul_assoc] [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } hm : x ^ m = ↑f a hn : x ^ n = ↑f b ha : y ^ (-m) * a ∈ center G hb : y ^ (-n) * b ∈ center G ⊢ y ^ m * y ^ n * y ^ (-m) * (a * (y ^ (-n) * b)) = y ^ m * y ^ n * y ^ (-m) * (y ^ (-n) * b * a) [PROOFSTEP] rw [mem_center_iff.1 hb] [GOAL] α : Type u a✝ : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G a b : G x : H y : G hxy : ↑f y = x hx : ∀ (a : { x // x ∈ MonoidHom.range f }), a ∈ zpowers { val := x, property := (_ : ∃ y, ↑f y = x) } m : ℤ hm✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } m = { val := ↑f a, property := (_ : ∃ y, ↑f y = ↑f a) } n : ℤ hn✝ : (fun x x_1 => x ^ x_1) { val := x, property := (_ : ∃ y, ↑f y = x) } n = { val := ↑f b, property := (_ : ∃ y, ↑f y = ↑f b) } hm : x ^ m = ↑f a hn : x ^ n = ↑f b ha : y ^ (-m) * a ∈ center G hb : y ^ (-n) * b ∈ center G ⊢ y ^ m * y ^ n * y ^ (-m) * (y ^ (-n) * b * a) = b * a [PROOFSTEP] group [GOAL] α : Type u a : α G : Type u_1 H : Type u_2 inst✝² : Group G inst✝¹ : Group H inst✝ : IsCyclic H f : G →* H hf : MonoidHom.ker f ≤ center G ⊢ Group G [PROOFSTEP] infer_instance [GOAL] α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α ⊢ IsCyclic α [PROOFSTEP] cases' subsingleton_or_nontrivial α with hi hi [GOAL] case inl α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi : Subsingleton α ⊢ IsCyclic α [PROOFSTEP] haveI := hi [GOAL] case inr α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi : Nontrivial α ⊢ IsCyclic α [PROOFSTEP] haveI := hi [GOAL] case inl α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Subsingleton α ⊢ IsCyclic α [PROOFSTEP] apply isCyclic_of_subsingleton [GOAL] case inr α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α ⊢ IsCyclic α [PROOFSTEP] obtain ⟨g, hg⟩ := exists_ne (1 : α) [GOAL] case inr.intro α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α g : α hg : g ≠ 1 ⊢ IsCyclic α [PROOFSTEP] refine' ⟨⟨g, fun x => _⟩⟩ [GOAL] case inr.intro α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α g : α hg : g ≠ 1 x : α ⊢ x ∈ Subgroup.zpowers g [PROOFSTEP] cases' IsSimpleOrder.eq_bot_or_eq_top (Subgroup.zpowers g) with hb ht [GOAL] case inr.intro.inl α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α g : α hg : g ≠ 1 x : α hb : Subgroup.zpowers g = ⊥ ⊢ x ∈ Subgroup.zpowers g [PROOFSTEP] exfalso [GOAL] case inr.intro.inl.h α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α g : α hg : g ≠ 1 x : α hb : Subgroup.zpowers g = ⊥ ⊢ False [PROOFSTEP] apply hg [GOAL] case inr.intro.inl.h α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α g : α hg : g ≠ 1 x : α hb : Subgroup.zpowers g = ⊥ ⊢ g = 1 [PROOFSTEP] rw [← Subgroup.mem_bot, ← hb] [GOAL] case inr.intro.inl.h α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α g : α hg : g ≠ 1 x : α hb : Subgroup.zpowers g = ⊥ ⊢ g ∈ Subgroup.zpowers g [PROOFSTEP] apply Subgroup.mem_zpowers [GOAL] case inr.intro.inr α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α g : α hg : g ≠ 1 x : α ht : Subgroup.zpowers g = ⊤ ⊢ x ∈ Subgroup.zpowers g [PROOFSTEP] rw [ht] [GOAL] case inr.intro.inr α : Type u a : α inst✝¹ : CommGroup α inst✝ : IsSimpleGroup α hi this : Nontrivial α g : α hg : g ≠ 1 x : α ht : Subgroup.zpowers g = ⊤ ⊢ x ∈ ⊤ [PROOFSTEP] apply Subgroup.mem_top [GOAL] α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α ⊢ Nat.Prime (Fintype.card α) [PROOFSTEP] have h0 : 0 < Fintype.card α := Fintype.card_pos_iff.2 (by infer_instance) [GOAL] α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α ⊢ Nonempty α [PROOFSTEP] infer_instance [GOAL] α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α ⊢ Nat.Prime (Fintype.card α) [PROOFSTEP] obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := α) [GOAL] case intro α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g ⊢ Nat.Prime (Fintype.card α) [PROOFSTEP] rw [Nat.prime_def_lt''] [GOAL] case intro α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g ⊢ 2 ≤ Fintype.card α ∧ ∀ (m : ℕ), m ∣ Fintype.card α → m = 1 ∨ m = Fintype.card α [PROOFSTEP] refine' ⟨Fintype.one_lt_card_iff_nontrivial.2 inferInstance, fun n hn => _⟩ [GOAL] case intro α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α ⊢ n = 1 ∨ n = Fintype.card α [PROOFSTEP] refine' (IsSimpleOrder.eq_bot_or_eq_top (Subgroup.zpowers (g ^ n))).symm.imp _ _ [GOAL] case intro.refine'_1 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α ⊢ Subgroup.zpowers (g ^ n) = ⊤ → n = 1 [PROOFSTEP] intro h [GOAL] case intro.refine'_1 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊤ ⊢ n = 1 [PROOFSTEP] have hgo := orderOf_pow (n := n) g [GOAL] case intro.refine'_1 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊤ hgo : orderOf (g ^ n) = orderOf g / Nat.gcd (orderOf g) n ⊢ n = 1 [PROOFSTEP] rw [orderOf_eq_card_of_forall_mem_zpowers hg, Nat.gcd_eq_right_iff_dvd.1 hn, orderOf_eq_card_of_forall_mem_zpowers, eq_comm, Nat.div_eq_iff_eq_mul_left (Nat.pos_of_dvd_of_pos hn h0) hn] at hgo [GOAL] case intro.refine'_1 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊤ hgo✝ : orderOf (g ^ n) = Fintype.card α / n hgo : Fintype.card α = Fintype.card α * n ⊢ n = 1 [PROOFSTEP] exact (mul_left_cancel₀ (ne_of_gt h0) ((mul_one (Fintype.card α)).trans hgo)).symm [GOAL] case intro.refine'_1 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊤ hgo : orderOf (g ^ n) = Fintype.card α / n ⊢ ∀ (x : α), x ∈ Subgroup.zpowers (g ^ n) [PROOFSTEP] intro x [GOAL] case intro.refine'_1 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊤ hgo : orderOf (g ^ n) = Fintype.card α / n x : α ⊢ x ∈ Subgroup.zpowers (g ^ n) [PROOFSTEP] rw [h] [GOAL] case intro.refine'_1 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊤ hgo : orderOf (g ^ n) = Fintype.card α / n x : α ⊢ x ∈ ⊤ [PROOFSTEP] exact Subgroup.mem_top _ [GOAL] case intro.refine'_2 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α ⊢ Subgroup.zpowers (g ^ n) = ⊥ → n = Fintype.card α [PROOFSTEP] intro h [GOAL] case intro.refine'_2 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊥ ⊢ n = Fintype.card α [PROOFSTEP] apply le_antisymm (Nat.le_of_dvd h0 hn) [GOAL] case intro.refine'_2 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊥ ⊢ Fintype.card α ≤ n [PROOFSTEP] rw [← orderOf_eq_card_of_forall_mem_zpowers hg] [GOAL] case intro.refine'_2 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊥ ⊢ orderOf g ≤ n [PROOFSTEP] apply orderOf_le_of_pow_eq_one (Nat.pos_of_dvd_of_pos hn h0) [GOAL] case intro.refine'_2 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊥ ⊢ g ^ n = 1 [PROOFSTEP] rw [← Subgroup.mem_bot, ← h] [GOAL] case intro.refine'_2 α : Type u a : α inst✝² : CommGroup α inst✝¹ : IsSimpleGroup α inst✝ : Fintype α h0 : 0 < Fintype.card α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g n : ℕ hn : n ∣ Fintype.card α h : Subgroup.zpowers (g ^ n) = ⊥ ⊢ g ^ n ∈ Subgroup.zpowers (g ^ n) [PROOFSTEP] exact Subgroup.mem_zpowers _ [GOAL] α : Type u a : α inst✝¹ : Fintype α inst✝ : CommGroup α ⊢ IsSimpleGroup α ↔ IsCyclic α ∧ Nat.Prime (Fintype.card α) [PROOFSTEP] constructor [GOAL] case mp α : Type u a : α inst✝¹ : Fintype α inst✝ : CommGroup α ⊢ IsSimpleGroup α → IsCyclic α ∧ Nat.Prime (Fintype.card α) [PROOFSTEP] intro h [GOAL] case mp α : Type u a : α inst✝¹ : Fintype α inst✝ : CommGroup α h : IsSimpleGroup α ⊢ IsCyclic α ∧ Nat.Prime (Fintype.card α) [PROOFSTEP] exact ⟨IsSimpleGroup.isCyclic, IsSimpleGroup.prime_card⟩ [GOAL] case mpr α : Type u a : α inst✝¹ : Fintype α inst✝ : CommGroup α ⊢ IsCyclic α ∧ Nat.Prime (Fintype.card α) → IsSimpleGroup α [PROOFSTEP] rintro ⟨_, hp⟩ [GOAL] case mpr.intro α : Type u a : α inst✝¹ : Fintype α inst✝ : CommGroup α left✝ : IsCyclic α hp : Nat.Prime (Fintype.card α) ⊢ IsSimpleGroup α [PROOFSTEP] haveI : Fact (Fintype.card α).Prime := ⟨hp⟩ [GOAL] case mpr.intro α : Type u a : α inst✝¹ : Fintype α inst✝ : CommGroup α left✝ : IsCyclic α hp : Nat.Prime (Fintype.card α) this : Fact (Nat.Prime (Fintype.card α)) ⊢ IsSimpleGroup α [PROOFSTEP] exact isSimpleGroup_of_prime_card rfl [GOAL] α : Type u a : α inst✝² : Group α inst✝¹ : IsCyclic α inst✝ : Fintype α ⊢ exponent α = Fintype.card α [PROOFSTEP] obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := α) [GOAL] case intro α : Type u a : α inst✝² : Group α inst✝¹ : IsCyclic α inst✝ : Fintype α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g ⊢ exponent α = Fintype.card α [PROOFSTEP] apply Nat.dvd_antisymm [GOAL] case intro.a α : Type u a : α inst✝² : Group α inst✝¹ : IsCyclic α inst✝ : Fintype α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g ⊢ exponent α ∣ Fintype.card α [PROOFSTEP] rw [← lcm_order_eq_exponent, Finset.lcm_dvd_iff] [GOAL] case intro.a α : Type u a : α inst✝² : Group α inst✝¹ : IsCyclic α inst✝ : Fintype α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g ⊢ ∀ (b : α), b ∈ Finset.univ → orderOf b ∣ Fintype.card α [PROOFSTEP] exact fun b _ => orderOf_dvd_card_univ [GOAL] case intro.a α : Type u a : α inst✝² : Group α inst✝¹ : IsCyclic α inst✝ : Fintype α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g ⊢ Fintype.card α ∣ exponent α [PROOFSTEP] rw [← orderOf_eq_card_of_forall_mem_zpowers hg] [GOAL] case intro.a α : Type u a : α inst✝² : Group α inst✝¹ : IsCyclic α inst✝ : Fintype α g : α hg : ∀ (x : α), x ∈ Subgroup.zpowers g ⊢ orderOf g ∣ exponent α [PROOFSTEP] exact order_dvd_exponent _
module Package.IpkgParser import public Text.Lexer -- not used %default total public export {- <|> clause "main" (iName []) (\st v -> st { idris_main = Just v }) <|> clause "sourcedir" identifier (\st v -> st { sourcedir = v }) <|> clause "opts" pOptions (\st v -> st { idris_opts = v ++ idris_opts st }) <|> clause "pkgs" (commaSep (pPkgName <* someSpace)) (\st ps -> <|> clause "modules" (commaSep moduleName) (\st v -> st { modules = modules st ++ v }) <|> clause "libs" (commaSep identifier) (\st v -> st { libdeps = libdeps st ++ v }) <|> clause "objs" (commaSep identifier) (\st v -> st { objs = objs st ++ v }) <|> clause "makefile" (iName []) (\st v -> st { makefile = Just (show v) }) <|> clause "tests" (commaSep (iName [])) (\st v -> st { idris_tests = idris_tests st ++ v }) <|> clause "version" textUntilEol (\st v -> st { pkgversion = Just v }) <|> clause "readme" textUntilEol (\st v -> st { pkgreadme = Just v }) <|> clause "license" textUntilEol (\st v -> st { pkglicense = Just v }) <|> clause "homepage" textUntilEol (\st v -> st { pkghomepage = Just v }) <|> clause "sourceloc" textUntilEol (\st v -> st { pkgsourceloc = Just v }) <|> clause "bugtracker" textUntilEol (\st v -> st { pkgbugtracker = Just v }) <|> clause "brief" stringLiteral (\st v -> st { pkgbrief = Just v }) <|> clause "author" textUntilEol (\st v -> st { pkgauthor = Just v }) <|> clause "maintainer" textUntilEol (\st v -> st { pkgmaintainer = Just v })-} data Token = Iexecutable String | Imain String | Isourcedir String | Iopts String | Ipkgs (List String) | Symbol String | Keyword String | Unrecognised String | Comment String | EndInput comment : Lexer comment = exact "--" <+> many (isNot '\n') rawTokens : TokenMap Token rawTokens = [(comment, Comment)] doParse : String-> Either String $ List (TokenData Token) doParse str =case lex rawTokens str of (a, (_,_,""))=> Right a (_,(_,_,e)) => Left $ "error! " ++ e {- module Idris.Package.Parser where import Idris.CmdOptions import Idris.Imports import Idris.Options (Opt) import Idris.Package.Common import Idris.Parser (moduleName) import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier, isEol, lchar, packageName, parseErrorDoc, reserved, runparser, someSpace, stringLiteral) import Control.Applicative import Control.Monad.State.Strict import Data.List (union) import qualified Options.Applicative as Opts import System.Directory (doesFileExist) import System.Exit import System.FilePath (isValid, takeExtension, takeFileName) import Text.Megaparsec ((<?>)) import qualified Text.Megaparsec as P import qualified Text.Megaparsec.Char as P import qualified Text.PrettyPrint.ANSI.Leijen as PP type PParser = Parser PkgDesc parseDesc :: FilePath -> IO PkgDesc parseDesc fp = do when (not $ takeExtension fp == ".ipkg") $ do putStrLn $ unwords ["The presented iPKG file does not have a '.ipkg' extension:", show fp] exitWith (ExitFailure 1) res <- doesFileExist fp if res then do p <- readFile fp case runparser pPkg defaultPkg fp p of Left err -> fail (show $ PP.plain $ parseErrorDoc err) Right x -> return x else do putStrLn $ unwords [ "The presented iPKG file does not exist:", show fp] exitWith (ExitFailure 1) pPkg :: PParser PkgDesc pPkg = do reserved "package" p <- pPkgName someSpace modify $ \st -> st { pkgname = p } some pClause st <- get P.eof return st pPkgName :: PParser PkgName pPkgName = (either fail pure . pkgName =<< packageName) <?> "PkgName" -- | Parses a filename. -- | -- | Treated for now as an identifier or a double-quoted string. filename :: Parsing m => m String filename = (do -- Treat a double-quoted string as a filename to support spaces. -- This also moves away from tying filenames to identifiers, so -- it will also accept hyphens -- (https://github.com/idris-lang/Idris-dev/issues/2721) filename <- stringLiteral -- Through at least version 0.9.19.1, IPKG executable values were -- possibly namespaced identifiers, like foo.bar.baz. <|> show <$> iName [] case filenameErrorMessage filename of Just errorMessage -> fail errorMessage Nothing -> return filename) <?> "filename" where -- TODO: Report failing span better! We could lookAhead, -- or do something with DeltaParsing? filenameErrorMessage :: FilePath -> Maybe String filenameErrorMessage path = either Just (const Nothing) $ do checkEmpty path checkValid path checkNoDirectoryComponent path where checkThat ok message = if ok then Right () else Left message checkEmpty path = checkThat (path /= "") "filename must not be empty" checkValid path = checkThat (System.FilePath.isValid path) "filename must contain only valid characters" checkNoDirectoryComponent path = checkThat (path == takeFileName path) "filename must contain no directory component" textUntilEol :: Parsing m => m String textUntilEol = many (P.satisfy (not . isEol)) <* eol <* someSpace clause :: String -> PParser a -> (PkgDesc -> a -> PkgDesc) -> PParser () clause name p f = do value <- reserved name *> lchar '=' *> p <* someSpace modify $ \st -> f st value commaSep :: Parsing m => m a -> m [a] commaSep p = P.sepBy1 p (lchar ',') pOptions :: PParser [Opt] pOptions = do str <- stringLiteral case execArgParserPure (words str) of Opts.Success a -> return a Opts.Failure e -> fail $ fst $ Opts.renderFailure e "" _ -> fail "Unexpected error" pClause :: PParser () pClause = clause "executable" filename (\st v -> st { execout = Just v }) <|> clause "main" (iName []) (\st v -> st { idris_main = Just v }) <|> clause "sourcedir" identifier (\st v -> st { sourcedir = v }) <|> clause "opts" pOptions (\st v -> st { idris_opts = v ++ idris_opts st }) <|> clause "pkgs" (commaSep (pPkgName <* someSpace)) (\st ps -> let pkgs = pureArgParser $ concatMap (\x -> ["-p", show x]) ps in st { pkgdeps = ps `union` pkgdeps st , idris_opts = pkgs ++ idris_opts st }) <|> clause "modules" (commaSep moduleName) (\st v -> st { modules = modules st ++ v }) <|> clause "libs" (commaSep identifier) (\st v -> st { libdeps = libdeps st ++ v }) <|> clause "objs" (commaSep identifier) (\st v -> st { objs = objs st ++ v }) <|> clause "makefile" (iName []) (\st v -> st { makefile = Just (show v) }) <|> clause "tests" (commaSep (iName [])) (\st v -> st { idris_tests = idris_tests st ++ v }) <|> clause "version" textUntilEol (\st v -> st { pkgversion = Just v }) <|> clause "readme" textUntilEol (\st v -> st { pkgreadme = Just v }) <|> clause "license" textUntilEol (\st v -> st { pkglicense = Just v }) <|> clause "homepage" textUntilEol (\st v -> st { pkghomepage = Just v }) <|> clause "sourceloc" textUntilEol (\st v -> st { pkgsourceloc = Just v }) <|> clause "bugtracker" textUntilEol (\st v -> st { pkgbugtracker = Just v }) <|> clause "brief" stringLiteral (\st v -> st { pkgbrief = Just v }) <|> clause "author" textUntilEol (\st v -> st { pkgauthor = Just v }) <|> clause "maintainer" textUntilEol (\st v -> st { pkgmaintainer = Just v }) -}
Thou wast not born for death , immortal Bird !
% !TeX root = main.tex \chapter{Prefix Sum and Histogram} \glsresetall \label{chapter:prefixsum} \section{Prefix Sum} \label{sec:prefixSum} Prefix sum is a common kernel used in many applications, e.g., recurrence relations, compaction problems, string comparison, polynomial evaluation, histogram, radix sort, and quick sort \cite{blelloch1990prefix}. Prefix sum requires restructuring in order to create an efficient FPGA design. The prefix sum is the cumulative sum of a sequence of numbers. Given a sequence of inputs $in_n$, the prefix sum $out_n$ is the summation of the first $n$ inputs, namely $out_n = in_0 + in_1 + in_2 + \cdots + in_{n-1} + in_n$. The following shows the computation for the first four elements of the output sequence $out$. \begin{align*} out_0 & = in_0 &\\ out_1 & = in_0 + in_1 &\\ out_2 & = in_0 + in_1 + in_2 \\ out_3 & = in_0 + in_1 + in_2 + in_3 \\ \cdots \end{align*} Of course, in practice we don't want to store and recompute the sum of all of the previous inputs, so the prefix sum is often computed by the recurrence equation: \begin{equation} out_n = out_{n-1} + in_n \end{equation} The disadvantage of the recurrence equation is that we must compute $out_{n-1}$ before computing $out_n$, which fundamentally limits the parallelism and throughput that this computation can be performed. In contrast, the original equations have obvious parallelism where each output can be computed independently at the expense of a significant amount of redundant computation. C code implementing the recurrence equation is shown in Figure \ref{fig:prefixsumSW}. Ideally, we'd like to achieve $II=1$ for the loop in the code, but this can be challenging even for such simple code. Implementing this code with \VHLS results in behavior like that shown in Figure \ref{fig:prefixsumSW}. \begin{figure} \begin{minipage}{.5\textwidth} \lstinputlisting{examples/prefixsumBO.cpp} \end{minipage} \begin{minipage}{.5\textwidth} \centering \includesvg{prefixsumBO_behavior} \end{minipage} \caption{ Code for implementing prefix sum, and its accompanying behavior. } \label{fig:prefixsumSW} \end{figure} The way this code is written, each output is written into the output memory \lstinline|out[]| and then in the next iteration is read back out of the memory again. Since the memory read is has a latency of one, data read from memory cannot be processed until the following clock cycle. As a result, such a design can only achieve a loop II of 2. In this case there is a relatively easy way to rewrite the code: we can simply perform the accumulation on a separate local variable, rather than reading the previous value back from the array. Avoiding extra memory accesses in favor of register storage is often advantageous in processor code, but in HLS designs it is often more significant since other operations are rarely a performance bottleneck. Code that does this is shown in Figure \ref{fig:prefixsum_optimized}. \begin{figure} \begin{minipage}{.5\textwidth} \lstinputlisting{examples/prefixsum_optimized.cpp} \end{minipage} \begin{minipage}{.5\textwidth} \centering \includesvg{prefixsum_optimized_behavior} \end{minipage} \caption{ Code for implementing an optimized prefix sum, and its accompanying behavior. } \label{fig:prefixsum_optimized} \end{figure} You might ask why the compiler is not able to optimize the memory loads and stores automatically in order to improve the II of the design. It turns out that \VHLS is capable of optimizing loads and stores to array, but only for reads and writes within the scope of a single basic block. You can see this if we unroll the loop, as shown in Figure \ref{fig:prefixsum_unrolled}. Note that we also have to add appropriate \lstinline{array_partition} s in order to be able to read and write multiple values at the interfaces. In this case, \VHLS is able to eliminate most of the read operations of the \lstinline{out[]} array within the body of the loop, but we still only achieve a loop II of 2. In this case the first load in the body of the loop is still not able to be removed. We can, however, rewrite the code manually to use a local variable rather than read from the \lstinline{out[]} array. \begin{figure} \begin{minipage}{.5\textwidth} \lstinputlisting{examples/prefixsum_unrolled.cpp} \end{minipage} \begin{minipage}{.5\textwidth} \raggedleft \includesvg{prefixsum_unrolled_behavior} \end{minipage} \caption{ Optimizing the prefixsum code using \lstinline{unroll}, \lstinline{pipeline}, and \lstinline{array_partition} directives. } \label{fig:prefixsum_unrolled} \end{figure} %results in the following message: %\lstinputlisting[basicstyle=\ttfamily\footnotesize]{examples/prefixsumBO.message} %\begin{figure} %\lstinputlisting{examples/prefixsumBO.cpp} %\caption{ The initial code for implementing prefix sum. } %\label{fig:prefixsumSW} %\end{figure} Ideally, when we unroll the inner loop, we the perform more operations per clock and reduce the interval to compute the function. If we unroll by a factor of two, then the performance doubles. A factor of four would increase the performance by factor four, i.e., the performance scales in a linear manner as it is unrolled. While this is mostly the case, as we unroll the inner loop there are often some aspects of the design that don't change. Under most circumstances, such as when the iteration space of loops execute for a long time, these aspects represent a small fixed overhead which doesn't contribute significantly to the performance of the overall function. However, as the number of loop iterations decreases, these fixed portions of the design have more impact. The largest fixed component of a pipelined loop is the depth of the pipeline itself. The control logic generate by \VHLS for a pipelined loop requires the pipeline to completely flush before code after the loop can execute. \begin{exercise} Unroll the \lstinline{for} loop corresponding to the prefix sum code in Figure \ref{fig:prefixsum_optimized} by different factors in combination with array partitioning to achieve a loop II of 1. How does the \lstinline{prefixsum} function latency change? What are the trends in the resource usages? Why do you think you are seeing these trends? What happens when the loop becomes fully unrolled? \end{exercise} \begin{figure} \centering \includegraphics[width= .7\textwidth]{images/architectures_prefixsum} \caption{ Part a) displays an architecture corresponding to the code in Figure~\ref{fig:prefixsumSW}. The dependence on the \lstinline{out[]} array can prevent achieving a loop II of 1. Computing the recurrence with a local variable, as shown in the code in Figure~\ref{fig:prefixsum_optimized}, is able to reduce the latency in the recurrence and achieve a loop II of 1.} \label{fig:architecture_prefixsum} \end{figure} Figure~\ref{fig:architecture_prefixsum} shows the hardware architecture resulting from synthesizing the code from Figure \ref{fig:prefixsumSW} and Figure~\ref{fig:prefixsum_optimized}. In part a), we can see that the `loop' in the circuit includes the output memory that stores the \lstinline{out[]} array, whereas in part b), the loop in the circuit includes only a register that stores the accumulated value and the output memory is only written. Simplifying recurrences and eliminating unnecessary memory accesses is a common practice in optimizing HLS code. %This \lstinline{A} variable maps to a hardware register. A register is helpful because a it can be read to and written from on every cycle. Unlike a memory, which has limited number of read and write ports, the register value can be read from and subsequently sent to a large number of places that need that data on every cycle with very limited penalty. The only major issues is wire routing, which in the grand scheme of things is not much additional overhead in terms of resources. Nor does it typically incur a large penalty in terms of performance. \note{Could add a whole part about doing reduction. Probably not necessary.} \note{Should have something here about what to do with floating point accumulation. This is fundamentally more problematic than what's above (which is relatively easily handled by improving store->load optimization.} The goal of this section is to show that even a small changes in the code can sometimes have a significant effect on the hardware design. Some changes may not necessarily be intuitive, but can be identified with feedback from the tool. \section{Histogram} \label{sec:histogram} A Histogram models the probability distribution of a discrete signal. Given a sequence of discrete input values, the histogram counts the number of times each value appears in the sequence. When normalized by the total number of input values, the histogram becomes the probability distribution function of the sequence. Creating a histogram is a common function used in image processing, signal processing, database processing, and many other domains. In many cases, it is common to quantize high-precision input data into a smaller number of intervals or \term{bins} as part of the histogram computation. For the purpose of this section, we will skip the actual process by which this is done and focus on what happens with the binned data. \begin{figure} \centering \includegraphics[width= .7\textwidth]{images/histogram_introd} \caption{ An example of a histogram. } \label{fig:histogram_introd} \end{figure} Figure~\ref{fig:histogram_introd} provides a simple example of a histogram. The data set consists of a sequence of binned values, in this case represented by an integer in $[0,4]$. The corresponding histogram, consisting of a count for each bin, is shown below along with a graphical representation of the histogram, where the height of each bar corresponding to the count of each separate value. Figure~\ref{fig:histogramSW} shows baseline code for the \lstinline{histogram} function. \begin{figure} \lstinputlisting{examples/histogramSW.cpp} \caption{ Original code for calculating the histogram. The \lstinline{for} loop iterates across the input array and increments the corresponding element of the \lstinline{hist} array. } \label{fig:histogramSW} \end{figure} The code ends up looking very similar to the prefix sum in the previous section. The difference is that the prefix sum is essentially only performing one accumulation, while in the \lstinline|histogram| function we compute one accumulation for each bin. The other difference is that in the prefix sum we added the input value each time, in this case we only add 1. When pipelining the inner loops using the \lstinline|pipeline| directive, we return to the same problem as with the code in Figure \ref{fig:prefixsumSW}, where we can only achieve a loop II of 2 due to the recurrence through the memory. This is due to the fact that we are reading from the \lstinline{hist} array and writing to the same array in every iteration of the loop. Figure~\ref{fig:architecture_histogram} shows the hardware architecture for the code in Figure~\ref{fig:histogramSW}. You can see that the \lstinline{hist} array has a read and write operation. The \lstinline{val} variable is used as the index into the \lstinline{hist} array, and the variable at that index is read out, incremented, and written back into the same location. \begin{figure} \centering \includegraphics[width= .5\textwidth]{images/architectures_histogram} \caption{ An architecture resulting from the code in Figure \ref{fig:histogramSW}. The \lstinline{val} data from the \lstinline{in} array is used to index into the \lstinline{hist} array. This data is incremented and stored back into the same location.} \label{fig:architecture_histogram} \end{figure} \section{Histogram Optimization and False Dependencies} Let's look deeper at the recurrence here. In the first iteration of the loop, we read the \lstinline{hist} array at some location $x_0$ and write back to the same location $x_0$. The read operation has a latency of one clock cycle, so the write has to happen in the following clock. Then in the next iteration of the loop, we read at another location $x_1$. Both $x_0$ and $x_1$ are dependent on the input and could take any value, so we consider the worst case when generating the circuit. In this case, if $x_0 == x_1$, then the read at location $x_1$ cannot begin until the previous write has completed. As a result, we must alternate between reads and writes. It turns out that we must alternate between reads and writes as long as $x_0$ and $x_1$ are independent. What if they are {\em not} actually independent? For instance, we might know that the source of data never produces two consecutive pieces of data that actually have the same bin. What do we do now? If we could give this extra information to the HLS tool, then it would be able to read at location $x_1$ while writing at location $x_0$ because it could guarantee that they are different addresses. In \VHLS, this is done using the \lstinline|dependence| directive. The modified code is shown in Figure \ref{fig:histogram_dependence}. Here we've explicitly documented (informally) that the function has some preconditions. In the code, we've added an \lstinline|assert()| call which checks the second precondition. in \VHLS, this assertion is enabled during simulation to ensure that the simulation testvectors meet the required precondition. The \lstinline|dependence| directive captures the effect of this precondition on the circuit, generated by the tool. Namely, it indicates to \VHLS that reads and writes to the \lstinline|hist| array are dependent only in a particular way. In this case, \lstinline|inter|-iteration dependencies consisting of a read operation after a write operation (RAW) have a distance of 2. In this case a distance of $n$ would indicate that read operations in iteration $i+n$ only depend on write operations in iteration $i$. In this case, we assert that \lstinline|in[i+1] != in[i]|, but it could be the case that \lstinline|in[i+2] == in[i]| so the correct distance is 2. \begin{figure} \lstinputlisting{examples/histogram_dependence.cpp} \caption{ An alternative function for computing a histogram. By restricting the inputs and indicating this restriction to \VHLS via the \lstinline|dependence| directive, II=1 can be achieved without significantly altering the code. } \label{fig:histogram_dependence} \end{figure} \begin{exercise} In Figure \ref{fig:histogram_dependence}, we added a precondition to the code, checked it using an assertion, and indicated the effect of the precondition to the tool using the \lstinline|dependence| directive. What happens if your testbench violates this precondition? What happens if you remove the \lstinline|assert()| call? Does \VHLS still check the precondition? What happens if the precondition is not consistent with the \lstinline|dependence| directive? \end{exercise} Unfortunately, the \lstinline{dependence} directive doesn't really help us if we are unwilling to accept the additional precondition. It's also clear that we can't directly apply same optimization as with the \lstinline|prefixsum| function, since we might need to use all of the values stored in the \lstinline|hist| array. Another alternative is implement the \lstinline|hist| array with a different technology, for instance we could partition the \lstinline|hist| array completely resulting in the array being implemented with \gls{ff} resources. Since the data written into a \gls{ff} on one clock cycle is available immediately on the next clock cycle, this solves the recurrence problem and can be a good solution when a small number of bins are involved. The architecture resulting from such a design is shown in Figure \ref{fig:histogram_partitioned}. However, it tends to be a poor solution when a large number of bins are required. Commonly histograms are constructed with hundreds to thousands of bins and for large data sets can require many bits of precision to count all of the inputs. This results in a large number of FF resources and a large mux, which also requires logic resources. Storing large histograms in \gls{bram} is usually a much better solution. \begin{figure} \centering \note{fixme!} \includegraphics[width= .5\textwidth]{images/architectures_histogram} \caption{ An architecture resulting from the code in Figure \ref{fig:histogramSW} when the \lstinline|hist| array is completely partitioned.} \label{fig:histogram_partitioned} \end{figure} Returning to the code in Figure~\ref{fig:histogramSW}, we see that there are really two separate cases that the architecture must be able to handle. One case is when the input contains consecutive values in the same bin. In this case, we'd like to use a simple register to perform the accumulation with a minimal amount of delay. The second case is when the input does not contain consecutive values in the same bin, in which case we need to read, modify, and write back the result to the memory. In this case, we can guarantee that the read operation of the \lstinline|hist| array can not be affected by the previous write operation. We've seen that both of these cases can be implemented separately, perhaps we can combine them into a single design. The code to accomplish this is shown in Figure~\ref{fig:histogramOpt1}. This code uses a local variable \lstinline|old| to store the bin from the previous iteration and another local variable \lstinline{accu} to store the count for that bin. Each time through the loop we check to see if we are looking at the same bin as the previous iteration. If so, then we can simply increment \lstinline|accu|. If not, then we need to store the value in \lstinline|accu| in the \lstinline|hist| array and increment the correct value in the \lstinline|hist| array instead. In either case, we update \lstinline|old| and \lstinline|accu| to contain the current correct values. The architecture corresponding to this code is shown in Figure \ref{fig:architecture_histogram_restructured}. In this code, we still need a \lstinline|dependence| directive, just as in Figure \ref{fig:histogram_dependence}, however the form is slightly different. In this case the read and write accesses are to two different addresses in the same loop iteration. Both of these addresses are dependent on the input data and so could point to any individual element of the \lstinline|hist| array. Because of this, \VHLS assumes that both of these accesses could access the same location and as a result schedules the read and write operations to the array in alternating cycles, resulting in a loop II of 2. However, looking at the code we can readily see that \lstinline|hist[old]| and \lstinline|hist[val]| can never access the same location because they are in the \lstinline|else| branch of the conditional \lstinline|if(old == val)|. Within one iteration (an \lstinline|intra|-dependence) a read operation after a write operation (\lstinline|RAW|) can never occur and hence is a \lstinline|false| dependence. In this case we are not using the \lstinline|dependence| directive to inform the tool about a precondition of the function, but instead about a property of the code itself. \begin{figure} \lstinputlisting{examples/histogram_opt1.cpp} \caption{ Removing the read after write dependency from the \lstinline{for} loop. This requires an \lstinline{if/else} structure that may seem like it is adding unnecessary complexity to the design. However, it allows for more effective pipelining despite the fact that the datapath is more complicated. } \label{fig:histogramOpt1} \end{figure} \begin{exercise} Synthesize the code from Figure \ref{fig:histogramSW} and Figure \ref{fig:histogramOpt1}. What is the initiation interval (II) in each case? What happens when you remove the \lstinline{dependence} directive from the code in Figure \ref{fig:histogramOpt1}? How does the loop interval change in both cases? What about the resource usage? \end{exercise} \begin{aside} For the code in Figure \ref{fig:histogramOpt1}, you might question why a tool like \VHLS cannot determine this property. In fact, while in some simple cases like this one better code analysis could propagate the \lstinline|if| condition property into each branch, we must accept that there are some pieces of code where properties of memory accesses are actually undecidable. The highest performance in such cases will only be achieved in a static schedule with the addition of user information. Several recent research works have looked to improve this by introducing some dynamic control logic into the design\cite{winterstein13dynamic, liu17elasticflow, dai17dynamic}. \end{aside} A pictorial description of the restructured code from Figure \ref{fig:histogramOpt1} is shown in Figure \ref{fig:architecture_histogram_restructured}. Not all of the operations are shown here, but the major idea of the function is there. You can see the two separate \lstinline{if} and \lstinline{else} regions (denoted by dotted lines). The \lstinline{acc} variable is replicated twice in order to make the drawing more readable; the actual design will only have one register for that variable. The figure shows the two separate datapaths for the \lstinline{if} and the \lstinline{else} clause with the computation corresponding to the \lstinline{if} clause on the top and the \lstinline{else} clause datapath on the bottom. \begin{figure} \centering \includegraphics[width= .6\textwidth]{images/architectures_histogram_restructured} \caption{ A depiction of the datapath corresponding to the code in Figure \ref{fig:histogramOpt1}. There are two separate portions corresponding to the \lstinline{if} and \lstinline{else} clauses. The figure shows the important portions of the computation, and leaves out some minor details. } \label{fig:architecture_histogram_restructured} \end{figure} \section{Increasing Histogram Performance} With some effort, we've achieved a design with a loop II of 1. Previously we have seen how further reducing the execution time of a design can be achieved by partial unrolling of the inner loop. However, with the \lstinline|histogram| function this is somewhat difficult for several reasons. One reason is the challenging recurrence, unless we can break up the input data in some fashion, the computation of one iteration of the loop must be completed with the computation of the next iteration of the loop. A second reason is that with a loop II of 1, the circuit performs a read and a write of the \lstinline|hist| array each clock cycle, occupying both ports of a \gls{bram} resource in the FPGA. Previously we have considered \gls{arraypartitioning} to increase the number of memory ports for accessing an array, but there's not a particularly obvious way to partition the \lstinline|hist| array since the access order depends on the input data. All is not lost, however, as there is a way we can expose more parallelism by decomposing the histogram computation into two stages. In the first stage, we divide the input data into a number of separate partitions. The histogram for each partition can be computed independently using a separate instance, often called a \gls{pe}, of the histogram solution we've developed previously. In the second stage, the individual histograms are combined to generate the histogram of the complete data sets. This partitioning (or mapping) and merging (or reducing) process is very similar to that adopted by the MapReduce framework \cite{dean08mapreduce} and is a common pattern for parallel computation. The map-reduce pattern is applicable whenever there is recurrence which includes a commutative and associative operation, such as addition in this case. This idea is shown in Figure~\ref{fig:architecture_histogram_parallel}. \begin{figure} \centering \includegraphics[width= .9\textwidth]{images/architectures_histogram_parallel} \caption{The histogram computation implemented using a map-reduce pattern. The processing element (PE) in Part a) is the same architecture as shown in Figure \ref{fig:architecture_histogram_restructured}. The \lstinline|in| array is partitioned and each partition is processed by a separate \gls{pe}. The merge block combines the individual histograms to create the final histogram. } \label{fig:architecture_histogram_parallel} \end{figure} The code for implementing this architecture is shown in Figure \ref{fig:histogram_parallel}. The \lstinline{histogram_map} function implements the `map' portion of the map-reduce pattern and will be instantiated multiple times. The code is very similar to the code in Figure \ref{fig:histogramOpt1}. The main difference is that we have added the additional code to initialize the \lstinline|hist| array. The \lstinline{histogram_map} function takes an input array \lstinline{in} which will contain a partition of the data being processed and computes the histogram of that partition in the \lstinline|hist| array. The \lstinline{histogram_reduce} function implements the `reduce' portion of the pattern. It takes as input a number of partial histograms and combines them into complete histogram by adding together the count for each histogram bin. In our code example in Figure \ref{fig:histogram_parallel}, we have only two processing elements, thus the merge has two input arrays \lstinline{hist1} and \lstinline{hist2}. This can easily be extended to handle more processing elements. The new \lstinline{histogram} function takes as an input two partitions of the input data, stored in the \lstinline{inputA} and \lstinline{inputB} arrays. It computes the histogram of each partition using the \lstinline {histogram_map} function, which are then stored in the \lstinline{hist1} and \lstinline{hist2} arrays. These are feed into the \lstinline{histogram_reduce} function which combines them and stores the result in the \lstinline{hist} array, which is the final output of the top level function \lstinline{histogram}. \begin{figure} \lstinputlisting{examples/histogram_parallel.cpp} \caption{ Another implementation of histogram that uses task level parallelism and pipelining. The histogram operation is split into two sub tasks, which are executed in the two \lstinline{histogram_map} functions. These results are combined in the final histogram result using the \lstinline{histogram_reduce} function. The \lstinline{histogram} function is the top level function that connects these three functions together. } \label{fig:histogram_parallel} \end{figure} \begin{exercise} Modify the code in Figure \ref{fig:histogram_parallel} to support a parameterizable number \lstinline|NUM_PE| of \glspl{pe}? Hint: You'll need to combine some of the arrays into a single array that is correctly partitioned and add some loops that depend on \lstinline|NUM_PE|. What happens to the throughput and task interval as you vary the number of \glspl{pe}? \end{exercise} We use the \lstinline{dataflow} directive in the \lstinline{histogram} function in order to enable a design with \gls{taskpipelining}. In this case there are three processes: two instances of the \lstinline{histogram_map} function and one instance of the \lstinline{histogram_reduce} function. Within a single task, the two \lstinline{histogram_map} processes can execute concurrently since they work on independent data, while the \lstinline{histogram_reduce} function must execute after since it uses the results from the \lstinline{histogram_map} processes. Thus, the \lstinline{dataflow} directive essentially creates a two stage task pipeline with the \lstinline{histogram_map} functions in the first stage and the \lstinline{histogram_reduce} function in the second stage. As with any dataflow design, the interval of the entire \lstinline{histogram} function depends upon the maximum initiation interval of the two stages. The two \lstinline{histogram_map} functions in the first stage are the same and will have the same interval ($II_\mathrm{histogram\_map}$). The \lstinline{histogram_reduce} function will have another interval ($II_\mathrm{histogram\_reduce}$). The interval of the toplevel \lstinline{histogram} function $II_\mathrm{histogram}$ is then $\max (II_\mathrm{histogram\_map}, II_\mathrm{histogram\_reduce})$. \begin{exercise} What happens when you add or change the locations of the \lstinline{pipeline} directives? For example, is it beneficial to add a \lstinline{pipeline} directive to the \lstinline{for} loop in the \lstinline{histogram_reduce} function? What is the result of moving the \lstinline{pipeline} directive into the \lstinline{histogram_map} function, i.e., hoisting it outside of the \lstinline{for} loop where it currently resides? \end{exercise} The goal of this section was to walk through the optimization the histogram computation, another small but important kernel of many applications. The key takeaway is that there are often limits to what tools can understand about our programs. In some cases we must take care in how we write the code and in other cases we must actually give the tool more information about the code or the environment that the code is executing in. In particular, properties about memory access patterns often critically affect the ability of HLS to generate correct and efficient hardware. In \VHLS, these properties can be expressed using the \lstinline|dependence| directive. Sometimes these optimizations might even be counter-intuitive, such as the addition of the \lstinline{if/else} control structure in \ref{fig:histogramOpt1}. In other cases optimizations might require some creativity, as in applying the map-reduce pattern in Figures \ref{fig:architecture_histogram_parallel} and \ref{fig:histogram_parallel}. \section{Conclusion} In this section, we've looked at the prefix sum and histogram kernels. Although these functions seem different, they both contain recurrences through a memory access. These recurrences can limit throughput if the memory access is not pipelined. In both cases, by rewriting the code we can remove the recurrence. In the case of the prefix sum, this is much easier since the access patterns are deterministic. In the case of the histogram we must rewrite the code to address the recurrence or ensure that recurrence never happens in practice. In either case we needed a way to describe to \VHLS information about the environment or about the code itself that the tool was unable to determine for itself. This information is captured in the \lstinline{dependence} directive. Lastly, we looked at ways of parallelizing both algorithms yet further, so that they could process a number of data samples each clock cycle.
lemma bigo_const [simp]: "(\<lambda>_. c) \<in> O[F](\<lambda>_. 1)"
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash ! This file was ported from Lean 3 source module algebra.lie.nilpotent ! leanprover-community/mathlib commit 938fead7abdc0cbbca8eba7a1052865a169dc102 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Algebra.Lie.Solvable import Mathbin.Algebra.Lie.Quotient import Mathbin.Algebra.Lie.Normalizer import Mathbin.LinearAlgebra.Eigenspace import Mathbin.RingTheory.Nilpotent /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `lie_module.lower_central_series` * `lie_module.is_nilpotent` ## Tags lie algebra, lower central series, nilpotent -/ universe u v w w₁ w₂ section NilpotentModules variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] variable (k : ℕ) (N : LieSubmodule R L M) namespace LieSubmodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊤` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `lie_module.lower_central_series_eq_lcs_comap` and `lie_module.lower_central_series_map_eq_lcs` below, as well as `lie_submodule.ucs`. -/ def lcs : LieSubmodule R L M → LieSubmodule R L M := (fun N => ⁅(⊤ : LieIdeal R L), N⁆)^[k] #align lie_submodule.lcs LieSubmodule.lcs @[simp] theorem lcs_zero (N : LieSubmodule R L M) : N.lcs 0 = N := rfl #align lie_submodule.lcs_zero LieSubmodule.lcs_zero @[simp] theorem lcs_succ : N.lcs (k + 1) = ⁅(⊤ : LieIdeal R L), N.lcs k⁆ := Function.iterate_succ_apply' (fun N' => ⁅⊤, N'⁆) k N #align lie_submodule.lcs_succ LieSubmodule.lcs_succ end LieSubmodule namespace LieModule variable (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lowerCentralSeries : LieSubmodule R L M := (⊤ : LieSubmodule R L M).lcs k #align lie_module.lower_central_series LieModule.lowerCentralSeries @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries R L M 0 = ⊤ := rfl #align lie_module.lower_central_series_zero LieModule.lowerCentralSeries_zero @[simp] theorem lowerCentralSeries_succ : lowerCentralSeries R L M (k + 1) = ⁅(⊤ : LieIdeal R L), lowerCentralSeries R L M k⁆ := (⊤ : LieSubmodule R L M).lcs_succ k #align lie_module.lower_central_series_succ LieModule.lowerCentralSeries_succ end LieModule namespace LieSubmodule open LieModule variable {R L M} theorem lcs_le_self : N.lcs k ≤ N := by induction' k with k ih · simp · simp only [lcs_succ] exact (LieSubmodule.mono_lie_right _ _ ⊤ ih).trans (N.lie_le_right ⊤) #align lie_submodule.lcs_le_self LieSubmodule.lcs_le_self theorem lowerCentralSeries_eq_lcs_comap : lowerCentralSeries R L N k = (N.lcs k).comap N.incl := by induction' k with k ih · simp · simp only [lcs_succ, lower_central_series_succ] at ih⊢ have : N.lcs k ≤ N.incl.range := by rw [N.range_incl] apply lcs_le_self rw [ih, LieSubmodule.comap_bracket_eq _ _ N.incl N.ker_incl this] #align lie_submodule.lower_central_series_eq_lcs_comap LieSubmodule.lowerCentralSeries_eq_lcs_comap theorem lowerCentralSeries_map_eq_lcs : (lowerCentralSeries R L N k).map N.incl = N.lcs k := by rw [lower_central_series_eq_lcs_comap, LieSubmodule.map_comap_incl, inf_eq_right] apply lcs_le_self #align lie_submodule.lower_central_series_map_eq_lcs LieSubmodule.lowerCentralSeries_map_eq_lcs end LieSubmodule namespace LieModule variable (R L M) theorem antitone_lowerCentralSeries : Antitone <| lowerCentralSeries R L M := by intro l k induction' k with k ih generalizing l <;> intro h · exact (le_zero_iff.mp h).symm ▸ le_rfl · rcases Nat.of_le_succ h with (hk | hk) · rw [lower_central_series_succ] exact (LieSubmodule.mono_lie_right _ _ ⊤ (ih hk)).trans (LieSubmodule.lie_le_right _ _) · exact hk.symm ▸ le_rfl #align lie_module.antitone_lower_central_series LieModule.antitone_lowerCentralSeries theorem trivial_iff_lower_central_eq_bot : IsTrivial L M ↔ lowerCentralSeries R L M 1 = ⊥ := by constructor <;> intro h · erw [eq_bot_iff, LieSubmodule.lieSpan_le] rintro m ⟨x, n, hn⟩ rw [← hn, h.trivial] simp · rw [LieSubmodule.eq_bot_iff] at h apply is_trivial.mk intro x m apply h apply LieSubmodule.subset_lieSpan use x, m rfl #align lie_module.trivial_iff_lower_central_eq_bot LieModule.trivial_iff_lower_central_eq_bot theorem iterate_toEndomorphism_mem_lowerCentralSeries (x : L) (m : M) (k : ℕ) : (toEndomorphism R L M x^[k]) m ∈ lowerCentralSeries R L M k := by induction' k with k ih · simp only [Function.iterate_zero] · simp only [lower_central_series_succ, Function.comp_apply, Function.iterate_succ', to_endomorphism_apply_apply] exact LieSubmodule.lie_mem_lie _ _ (LieSubmodule.mem_top x) ih #align lie_module.iterate_to_endomorphism_mem_lower_central_series LieModule.iterate_toEndomorphism_mem_lowerCentralSeries variable {R L M} theorem map_lowerCentralSeries_le {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] (k : ℕ) (f : M →ₗ⁅R,L⁆ M₂) : LieSubmodule.map f (lowerCentralSeries R L M k) ≤ lowerCentralSeries R L M₂ k := by induction' k with k ih · simp only [LieModule.lowerCentralSeries_zero, le_top] · simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] exact LieSubmodule.mono_lie_right _ _ ⊤ ih #align lie_module.map_lower_central_series_le LieModule.map_lowerCentralSeries_le variable (R L M) open LieAlgebra theorem derivedSeries_le_lowerCentralSeries (k : ℕ) : derivedSeries R L k ≤ lowerCentralSeries R L L k := by induction' k with k h · rw [derived_series_def, derived_series_of_ideal_zero, lower_central_series_zero] exact le_rfl · have h' : derivedSeries R L k ≤ ⊤ := by simp only [le_top] rw [derived_series_def, derived_series_of_ideal_succ, lower_central_series_succ] exact LieSubmodule.mono_lie _ _ _ _ h' h #align lie_module.derived_series_le_lower_central_series LieModule.derivedSeries_le_lowerCentralSeries /-- A Lie module is nilpotent if its lower central series reaches 0 (in a finite number of steps). -/ class IsNilpotent : Prop where nilpotent : ∃ k, lowerCentralSeries R L M k = ⊥ #align lie_module.is_nilpotent LieModule.IsNilpotent /-- See also `lie_module.is_nilpotent_iff_exists_ucs_eq_top`. -/ theorem isNilpotent_iff : IsNilpotent R L M ↔ ∃ k, lowerCentralSeries R L M k = ⊥ := ⟨fun h => h.nilpotent, fun h => ⟨h⟩⟩ #align lie_module.is_nilpotent_iff LieModule.isNilpotent_iff variable {R L M} theorem LieSubmodule.isNilpotent_iff_exists_lcs_eq_bot (N : LieSubmodule R L M) : LieModule.IsNilpotent R L N ↔ ∃ k, N.lcs k = ⊥ := by rw [is_nilpotent_iff] refine' exists_congr fun k => _ rw [N.lower_central_series_eq_lcs_comap k, LieSubmodule.comap_incl_eq_bot, inf_eq_right.mpr (N.lcs_le_self k)] #align lie_submodule.is_nilpotent_iff_exists_lcs_eq_bot LieSubmodule.isNilpotent_iff_exists_lcs_eq_bot variable (R L M) instance (priority := 100) trivialIsNilpotent [IsTrivial L M] : IsNilpotent R L M := ⟨by use 1 change ⁅⊤, ⊤⁆ = ⊥ simp⟩ #align lie_module.trivial_is_nilpotent LieModule.trivialIsNilpotent theorem nilpotent_endo_of_nilpotent_module [hM : IsNilpotent R L M] : ∃ k : ℕ, ∀ x : L, toEndomorphism R L M x ^ k = 0 := by obtain ⟨k, hM⟩ := hM use k intro x; ext m rw [LinearMap.pow_apply, LinearMap.zero_apply, ← @LieSubmodule.mem_bot R L M, ← hM] exact iterate_to_endomorphism_mem_lower_central_series R L M x m k #align lie_module.nilpotent_endo_of_nilpotent_module LieModule.nilpotent_endo_of_nilpotent_module /-- For a nilpotent Lie module, the weight space of the 0 weight is the whole module. This result will be used downstream to show that weight spaces are Lie submodules, at which time it will be possible to state it in the language of weight spaces. -/ theorem infᵢ_max_gen_zero_eigenspace_eq_top_of_nilpotent [IsNilpotent R L M] : (⨅ x : L, (toEndomorphism R L M x).maximalGeneralizedEigenspace 0) = ⊤ := by ext m simp only [Module.End.mem_maximalGeneralizedEigenspace, Submodule.mem_top, sub_zero, iff_true_iff, zero_smul, Submodule.mem_infᵢ] intro x obtain ⟨k, hk⟩ := nilpotent_endo_of_nilpotent_module R L M use k; rw [hk] exact LinearMap.zero_apply m #align lie_module.infi_max_gen_zero_eigenspace_eq_top_of_nilpotent LieModule.infᵢ_max_gen_zero_eigenspace_eq_top_of_nilpotent /-- If the quotient of a Lie module `M` by a Lie submodule on which the Lie algebra acts trivially is nilpotent then `M` is nilpotent. This is essentially the Lie module equivalent of the fact that a central extension of nilpotent Lie algebras is nilpotent. See `lie_algebra.nilpotent_of_nilpotent_quotient` below for the corresponding result for Lie algebras. -/ theorem nilpotentOfNilpotentQuotient {N : LieSubmodule R L M} (h₁ : N ≤ maxTrivSubmodule R L M) (h₂ : IsNilpotent R L (M ⧸ N)) : IsNilpotent R L M := by obtain ⟨k, hk⟩ := h₂ use k + 1 simp only [lower_central_series_succ] suffices lower_central_series R L M k ≤ N by replace this := LieSubmodule.mono_lie_right _ _ ⊤ (le_trans this h₁) rwa [ideal_oper_max_triv_submodule_eq_bot, le_bot_iff] at this rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, ← le_bot_iff, ← hk] exact map_lower_central_series_le k (LieSubmodule.Quotient.mk' N) #align lie_module.nilpotent_of_nilpotent_quotient LieModule.nilpotentOfNilpotentQuotient /-- Given a nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the natural number `k` (the number of inclusions). For a non-nilpotent module, we use the junk value 0. -/ noncomputable def nilpotencyLength : ℕ := infₛ { k | lowerCentralSeries R L M k = ⊥ } #align lie_module.nilpotency_length LieModule.nilpotencyLength theorem nilpotencyLength_eq_zero_iff [IsNilpotent R L M] : nilpotencyLength R L M = 0 ↔ Subsingleton M := by let s := { k | lower_central_series R L M k = ⊥ } have hs : s.nonempty := by obtain ⟨k, hk⟩ := (by infer_instance : IsNilpotent R L M) exact ⟨k, hk⟩ change Inf s = 0 ↔ _ rw [← LieSubmodule.subsingleton_iff R L M, ← subsingleton_iff_bot_eq_top, ← lower_central_series_zero, @eq_comm (LieSubmodule R L M)] refine' ⟨fun h => h ▸ Nat.infₛ_mem hs, fun h => _⟩ rw [Nat.infₛ_eq_zero] exact Or.inl h #align lie_module.nilpotency_length_eq_zero_iff LieModule.nilpotencyLength_eq_zero_iff theorem nilpotencyLength_eq_succ_iff (k : ℕ) : nilpotencyLength R L M = k + 1 ↔ lowerCentralSeries R L M (k + 1) = ⊥ ∧ lowerCentralSeries R L M k ≠ ⊥ := by let s := { k | lower_central_series R L M k = ⊥ } change Inf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s have hs : ∀ k₁ k₂, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := by rintro k₁ k₂ h₁₂ (h₁ : lower_central_series R L M k₁ = ⊥) exact eq_bot_iff.mpr (h₁ ▸ antitone_lower_central_series R L M h₁₂) exact Nat.infₛ_upward_closed_eq_succ_iff hs k #align lie_module.nilpotency_length_eq_succ_iff LieModule.nilpotencyLength_eq_succ_iff /-- Given a non-trivial nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the `k-1`th term in the lower central series (the last non-trivial term). For a trivial or non-nilpotent module, this is the bottom submodule, `⊥`. -/ noncomputable def lowerCentralSeriesLast : LieSubmodule R L M := match nilpotencyLength R L M with | 0 => ⊥ | k + 1 => lowerCentralSeries R L M k #align lie_module.lower_central_series_last LieModule.lowerCentralSeriesLast theorem lowerCentralSeriesLast_le_max_triv : lowerCentralSeriesLast R L M ≤ maxTrivSubmodule R L M := by rw [lower_central_series_last] cases' h : nilpotency_length R L M with k · exact bot_le · rw [le_max_triv_iff_bracket_eq_bot] rw [nilpotency_length_eq_succ_iff, lower_central_series_succ] at h exact h.1 #align lie_module.lower_central_series_last_le_max_triv LieModule.lowerCentralSeriesLast_le_max_triv theorem nontrivial_lowerCentralSeriesLast [Nontrivial M] [IsNilpotent R L M] : Nontrivial (lowerCentralSeriesLast R L M) := by rw [LieSubmodule.nontrivial_iff_ne_bot, lower_central_series_last] cases h : nilpotency_length R L M · rw [nilpotency_length_eq_zero_iff, ← not_nontrivial_iff_subsingleton] at h contradiction · rw [nilpotency_length_eq_succ_iff] at h exact h.2 #align lie_module.nontrivial_lower_central_series_last LieModule.nontrivial_lowerCentralSeriesLast theorem nontrivial_max_triv_of_isNilpotent [Nontrivial M] [IsNilpotent R L M] : Nontrivial (maxTrivSubmodule R L M) := Set.nontrivial_mono (lowerCentralSeriesLast_le_max_triv R L M) (nontrivial_lowerCentralSeriesLast R L M) #align lie_module.nontrivial_max_triv_of_is_nilpotent LieModule.nontrivial_max_triv_of_isNilpotent @[simp] theorem coe_lcs_range_toEndomorphism_eq (k : ℕ) : (lowerCentralSeries R (toEndomorphism R L M).range M k : Submodule R M) = lowerCentralSeries R L M k := by induction' k with k ih · simp · simp only [lower_central_series_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', ← (lower_central_series R (to_endomorphism R L M).range M k).mem_coe_submodule, ih] congr ext m constructor · rintro ⟨⟨-, ⟨y, rfl⟩⟩, -, n, hn, rfl⟩ exact ⟨y, LieSubmodule.mem_top _, n, hn, rfl⟩ · rintro ⟨x, hx, n, hn, rfl⟩ exact ⟨⟨to_endomorphism R L M x, LieHom.mem_range_self _ x⟩, LieSubmodule.mem_top _, n, hn, rfl⟩ #align lie_module.coe_lcs_range_to_endomorphism_eq LieModule.coe_lcs_range_toEndomorphism_eq @[simp] theorem isNilpotent_range_toEndomorphism_iff : IsNilpotent R (toEndomorphism R L M).range M ↔ IsNilpotent R L M := by constructor <;> rintro ⟨k, hk⟩ <;> use k <;> rw [← LieSubmodule.coe_to_submodule_eq_iff] at hk⊢ <;> simpa using hk #align lie_module.is_nilpotent_range_to_endomorphism_iff LieModule.isNilpotent_range_toEndomorphism_iff end LieModule namespace LieSubmodule variable {N₁ N₂ : LieSubmodule R L M} /-- The upper (aka ascending) central series. See also `lie_submodule.lcs`. -/ def ucs (k : ℕ) : LieSubmodule R L M → LieSubmodule R L M := normalizer^[k] #align lie_submodule.ucs LieSubmodule.ucs @[simp] theorem ucs_zero : N.ucs 0 = N := rfl #align lie_submodule.ucs_zero LieSubmodule.ucs_zero @[simp] theorem ucs_succ (k : ℕ) : N.ucs (k + 1) = (N.ucs k).normalizer := Function.iterate_succ_apply' normalizer k N #align lie_submodule.ucs_succ LieSubmodule.ucs_succ theorem ucs_add (k l : ℕ) : N.ucs (k + l) = (N.ucs l).ucs k := Function.iterate_add_apply normalizer k l N #align lie_submodule.ucs_add LieSubmodule.ucs_add @[mono] theorem ucs_mono (k : ℕ) (h : N₁ ≤ N₂) : N₁.ucs k ≤ N₂.ucs k := by induction' k with k ih; · simpa simp only [ucs_succ] mono #align lie_submodule.ucs_mono LieSubmodule.ucs_mono theorem ucs_eq_self_of_normalizer_eq_self (h : N₁.normalizer = N₁) (k : ℕ) : N₁.ucs k = N₁ := by induction' k with k ih · simp · rwa [ucs_succ, ih] #align lie_submodule.ucs_eq_self_of_normalizer_eq_self LieSubmodule.ucs_eq_self_of_normalizer_eq_self /-- If a Lie module `M` contains a self-normalizing Lie submodule `N`, then all terms of the upper central series of `M` are contained in `N`. An important instance of this situation arises from a Cartan subalgebra `H ⊆ L` with the roles of `L`, `M`, `N` played by `H`, `L`, `H`, respectively. -/ theorem ucs_le_of_normalizer_eq_self (h : N₁.normalizer = N₁) (k : ℕ) : (⊥ : LieSubmodule R L M).ucs k ≤ N₁ := by rw [← ucs_eq_self_of_normalizer_eq_self h k] mono simp #align lie_submodule.ucs_le_of_normalizer_eq_self LieSubmodule.ucs_le_of_normalizer_eq_self theorem lcs_add_le_iff (l k : ℕ) : N₁.lcs (l + k) ≤ N₂ ↔ N₁.lcs l ≤ N₂.ucs k := by revert l induction' k with k ih; · simp intro l rw [(by abel : l + (k + 1) = l + 1 + k), ih, ucs_succ, lcs_succ, top_lie_le_iff_le_normalizer] #align lie_submodule.lcs_add_le_iff LieSubmodule.lcs_add_le_iff theorem lcs_le_iff (k : ℕ) : N₁.lcs k ≤ N₂ ↔ N₁ ≤ N₂.ucs k := by convert lcs_add_le_iff 0 k rw [zero_add] #align lie_submodule.lcs_le_iff LieSubmodule.lcs_le_iff theorem gc_lcs_ucs (k : ℕ) : GaloisConnection (fun N : LieSubmodule R L M => N.lcs k) fun N : LieSubmodule R L M => N.ucs k := fun N₁ N₂ => lcs_le_iff k #align lie_submodule.gc_lcs_ucs LieSubmodule.gc_lcs_ucs theorem ucs_eq_top_iff (k : ℕ) : N.ucs k = ⊤ ↔ LieModule.lowerCentralSeries R L M k ≤ N := by rw [eq_top_iff, ← lcs_le_iff] rfl #align lie_submodule.ucs_eq_top_iff LieSubmodule.ucs_eq_top_iff theorem LieModule.isNilpotent_iff_exists_ucs_eq_top : LieModule.IsNilpotent R L M ↔ ∃ k, (⊥ : LieSubmodule R L M).ucs k = ⊤ := by rw [LieModule.isNilpotent_iff] exact exists_congr fun k => by simp [ucs_eq_top_iff] #align lie_module.is_nilpotent_iff_exists_ucs_eq_top LieModule.isNilpotent_iff_exists_ucs_eq_top theorem ucs_comap_incl (k : ℕ) : ((⊥ : LieSubmodule R L M).ucs k).comap N.incl = (⊥ : LieSubmodule R L N).ucs k := by induction' k with k ih · exact N.ker_incl · simp [← ih] #align lie_submodule.ucs_comap_incl LieSubmodule.ucs_comap_incl theorem isNilpotent_iff_exists_self_le_ucs : LieModule.IsNilpotent R L N ↔ ∃ k, N ≤ (⊥ : LieSubmodule R L M).ucs k := by simp_rw [LieModule.isNilpotent_iff_exists_ucs_eq_top, ← ucs_comap_incl, comap_incl_eq_top] #align lie_submodule.is_nilpotent_iff_exists_self_le_ucs LieSubmodule.isNilpotent_iff_exists_self_le_ucs end LieSubmodule section Morphisms open LieModule Function variable {L₂ M₂ : Type _} [LieRing L₂] [LieAlgebra R L₂] variable [AddCommGroup M₂] [Module R M₂] [LieRingModule L₂ M₂] [LieModule R L₂ M₂] variable {f : L →ₗ⁅R⁆ L₂} {g : M →ₗ[R] M₂} variable (hf : Surjective f) (hg : Surjective g) (hfg : ∀ x m, ⁅f x, g m⁆ = g ⁅x, m⁆) include hf hg hfg theorem Function.Surjective.lieModule_lcs_map_eq (k : ℕ) : (lowerCentralSeries R L M k : Submodule R M).map g = lowerCentralSeries R L₂ M₂ k := by induction' k with k ih · simp [LinearMap.range_eq_top, hg] · suffices g '' { m | ∃ (x : L)(n : _), n ∈ lower_central_series R L M k ∧ ⁅x, n⁆ = m } = { m | ∃ (x : L₂)(n : _), n ∈ lower_central_series R L M k ∧ ⁅x, g n⁆ = m } by simp only [← LieSubmodule.mem_coeSubmodule] at this simp [← LieSubmodule.mem_coeSubmodule, ← ih, LieSubmodule.lieIdeal_oper_eq_linear_span', Submodule.map_span, -Submodule.span_image, this] ext m₂ constructor · rintro ⟨m, ⟨x, n, hn, rfl⟩, rfl⟩ exact ⟨f x, n, hn, hfg x n⟩ · rintro ⟨x, n, hn, rfl⟩ obtain ⟨y, rfl⟩ := hf x exact ⟨⁅y, n⁆, ⟨y, n, hn, rfl⟩, (hfg y n).symm⟩ #align function.surjective.lie_module_lcs_map_eq Function.Surjective.lieModule_lcs_map_eq theorem Function.Surjective.lieModuleIsNilpotent [IsNilpotent R L M] : IsNilpotent R L₂ M₂ := by obtain ⟨k, hk⟩ := id (by infer_instance : IsNilpotent R L M) use k rw [← LieSubmodule.coe_to_submodule_eq_iff] at hk⊢ simp [← hf.lie_module_lcs_map_eq hg hfg k, hk] #align function.surjective.lie_module_is_nilpotent Function.Surjective.lieModuleIsNilpotent omit hf hg hfg theorem Equiv.lieModule_isNilpotent_iff (f : L ≃ₗ⁅R⁆ L₂) (g : M ≃ₗ[R] M₂) (hfg : ∀ x m, ⁅f x, g m⁆ = g ⁅x, m⁆) : IsNilpotent R L M ↔ IsNilpotent R L₂ M₂ := by constructor <;> intro h · have hg : surjective (g : M →ₗ[R] M₂) := g.surjective exact f.surjective.lie_module_is_nilpotent hg hfg · have hg : surjective (g.symm : M₂ →ₗ[R] M) := g.symm.surjective refine' f.symm.surjective.lie_module_is_nilpotent hg fun x m => _ rw [LinearEquiv.coe_coe, LieEquiv.coe_to_lieHom, ← g.symm_apply_apply ⁅f.symm x, g.symm m⁆, ← hfg, f.apply_symm_apply, g.apply_symm_apply] #align equiv.lie_module_is_nilpotent_iff Equiv.lieModule_isNilpotent_iff @[simp] theorem LieModule.isNilpotent_of_top_iff : IsNilpotent R (⊤ : LieSubalgebra R L) M ↔ IsNilpotent R L M := Equiv.lieModule_isNilpotent_iff LieSubalgebra.topEquiv (1 : M ≃ₗ[R] M) fun x m => rfl #align lie_module.is_nilpotent_of_top_iff LieModule.isNilpotent_of_top_iff end Morphisms end NilpotentModules instance (priority := 100) LieAlgebra.isSolvableOfIsNilpotent (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] [hL : LieModule.IsNilpotent R L L] : LieAlgebra.IsSolvable R L := by obtain ⟨k, h⟩ : ∃ k, LieModule.lowerCentralSeries R L L k = ⊥ := hL.nilpotent use k; rw [← le_bot_iff] at h⊢ exact le_trans (LieModule.derivedSeries_le_lowerCentralSeries R L k) h #align lie_algebra.is_solvable_of_is_nilpotent LieAlgebra.isSolvableOfIsNilpotent section NilpotentAlgebras variable (R : Type u) (L : Type v) (L' : Type w) variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] /-- We say a Lie algebra is nilpotent when it is nilpotent as a Lie module over itself via the adjoint representation. -/ abbrev LieAlgebra.IsNilpotent (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] : Prop := LieModule.IsNilpotent R L L #align lie_algebra.is_nilpotent LieAlgebra.IsNilpotent open LieAlgebra theorem LieAlgebra.nilpotent_ad_of_nilpotent_algebra [IsNilpotent R L] : ∃ k : ℕ, ∀ x : L, ad R L x ^ k = 0 := LieModule.nilpotent_endo_of_nilpotent_module R L L #align lie_algebra.nilpotent_ad_of_nilpotent_algebra LieAlgebra.nilpotent_ad_of_nilpotent_algebra /-- See also `lie_algebra.zero_root_space_eq_top_of_nilpotent`. -/ theorem LieAlgebra.infᵢ_max_gen_zero_eigenspace_eq_top_of_nilpotent [IsNilpotent R L] : (⨅ x : L, (ad R L x).maximalGeneralizedEigenspace 0) = ⊤ := LieModule.infᵢ_max_gen_zero_eigenspace_eq_top_of_nilpotent R L L #align lie_algebra.infi_max_gen_zero_eigenspace_eq_top_of_nilpotent LieAlgebra.infᵢ_max_gen_zero_eigenspace_eq_top_of_nilpotent -- TODO Generalise the below to Lie modules if / when we define morphisms, equivs of Lie modules -- covering a Lie algebra morphism of (possibly different) Lie algebras. variable {R L L'} open LieModule (lowerCentralSeries) /-- Given an ideal `I` of a Lie algebra `L`, the lower central series of `L ⧸ I` is the same whether we regard `L ⧸ I` as an `L` module or an `L ⧸ I` module. TODO: This result obviously generalises but the generalisation requires the missing definition of morphisms between Lie modules over different Lie algebras. -/ theorem coe_lowerCentralSeries_ideal_quot_eq {I : LieIdeal R L} (k : ℕ) : (lowerCentralSeries R L (L ⧸ I) k : Submodule R (L ⧸ I)) = lowerCentralSeries R (L ⧸ I) (L ⧸ I) k := by induction' k with k ih · simp only [LieSubmodule.top_coeSubmodule, LieModule.lowerCentralSeries_zero] · simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span] congr ext x constructor · rintro ⟨⟨y, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩ erw [← LieSubmodule.mem_coeSubmodule, ih, LieSubmodule.mem_coeSubmodule] at hz exact ⟨⟨LieSubmodule.Quotient.mk y, LieSubmodule.mem_top _⟩, ⟨z, hz⟩, rfl⟩ · rintro ⟨⟨⟨y⟩, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩ erw [← LieSubmodule.mem_coeSubmodule, ← ih, LieSubmodule.mem_coeSubmodule] at hz exact ⟨⟨y, LieSubmodule.mem_top _⟩, ⟨z, hz⟩, rfl⟩ #align coe_lower_central_series_ideal_quot_eq coe_lowerCentralSeries_ideal_quot_eq /-- Note that the below inequality can be strict. For example the ideal of strictly-upper-triangular 2x2 matrices inside the Lie algebra of upper-triangular 2x2 matrices with `k = 1`. -/ theorem LieModule.coe_lowerCentralSeries_ideal_le {I : LieIdeal R L} (k : ℕ) : (lowerCentralSeries R I I k : Submodule R I) ≤ lowerCentralSeries R L I k := by induction' k with k ih · simp · simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span] apply Submodule.span_mono rintro x ⟨⟨y, -⟩, ⟨z, hz⟩, rfl : ⁅y, z⁆ = x⟩ exact ⟨⟨y.val, LieSubmodule.mem_top _⟩, ⟨z, ih hz⟩, rfl⟩ #align lie_module.coe_lower_central_series_ideal_le LieModule.coe_lowerCentralSeries_ideal_le /-- A central extension of nilpotent Lie algebras is nilpotent. -/ theorem LieAlgebra.nilpotent_of_nilpotent_quotient {I : LieIdeal R L} (h₁ : I ≤ center R L) (h₂ : IsNilpotent R (L ⧸ I)) : IsNilpotent R L := by suffices LieModule.IsNilpotent R L (L ⧸ I) by exact LieModule.nilpotentOfNilpotentQuotient R L L h₁ this obtain ⟨k, hk⟩ := h₂ use k simp [← LieSubmodule.coe_to_submodule_eq_iff, coe_lowerCentralSeries_ideal_quot_eq, hk] #align lie_algebra.nilpotent_of_nilpotent_quotient LieAlgebra.nilpotent_of_nilpotent_quotient theorem LieAlgebra.non_trivial_center_of_isNilpotent [Nontrivial L] [IsNilpotent R L] : Nontrivial <| center R L := LieModule.nontrivial_max_triv_of_isNilpotent R L L #align lie_algebra.non_trivial_center_of_is_nilpotent LieAlgebra.non_trivial_center_of_isNilpotent theorem LieIdeal.map_lowerCentralSeries_le (k : ℕ) {f : L →ₗ⁅R⁆ L'} : LieIdeal.map f (lowerCentralSeries R L L k) ≤ lowerCentralSeries R L' L' k := by induction' k with k ih · simp only [LieModule.lowerCentralSeries_zero, le_top] · simp only [LieModule.lowerCentralSeries_succ] exact le_trans (LieIdeal.map_bracket_le f) (LieSubmodule.mono_lie _ _ _ _ le_top ih) #align lie_ideal.map_lower_central_series_le LieIdeal.map_lowerCentralSeries_le theorem LieIdeal.lowerCentralSeries_map_eq (k : ℕ) {f : L →ₗ⁅R⁆ L'} (h : Function.Surjective f) : LieIdeal.map f (lowerCentralSeries R L L k) = lowerCentralSeries R L' L' k := by have h' : (⊤ : LieIdeal R L).map f = ⊤ := by rw [← f.ideal_range_eq_map] exact f.ideal_range_eq_top_of_surjective h induction' k with k ih · simp only [LieModule.lowerCentralSeries_zero] exact h' · simp only [LieModule.lowerCentralSeries_succ, LieIdeal.map_bracket_eq f h, ih, h'] #align lie_ideal.lower_central_series_map_eq LieIdeal.lowerCentralSeries_map_eq theorem Function.Injective.lieAlgebra_isNilpotent [h₁ : IsNilpotent R L'] {f : L →ₗ⁅R⁆ L'} (h₂ : Function.Injective f) : IsNilpotent R L := { nilpotent := by obtain ⟨k, hk⟩ := id h₁ use k apply LieIdeal.bot_of_map_eq_bot h₂; rw [eq_bot_iff, ← hk] apply LieIdeal.map_lowerCentralSeries_le } #align function.injective.lie_algebra_is_nilpotent Function.Injective.lieAlgebra_isNilpotent theorem Function.Surjective.lieAlgebra_isNilpotent [h₁ : IsNilpotent R L] {f : L →ₗ⁅R⁆ L'} (h₂ : Function.Surjective f) : IsNilpotent R L' := { nilpotent := by obtain ⟨k, hk⟩ := id h₁ use k rw [← LieIdeal.lowerCentralSeries_map_eq k h₂, hk] simp only [LieIdeal.map_eq_bot_iff, bot_le] } #align function.surjective.lie_algebra_is_nilpotent Function.Surjective.lieAlgebra_isNilpotent theorem LieEquiv.nilpotent_iff_equiv_nilpotent (e : L ≃ₗ⁅R⁆ L') : IsNilpotent R L ↔ IsNilpotent R L' := by constructor <;> intro h · exact e.symm.injective.lie_algebra_is_nilpotent · exact e.injective.lie_algebra_is_nilpotent #align lie_equiv.nilpotent_iff_equiv_nilpotent LieEquiv.nilpotent_iff_equiv_nilpotent theorem LieHom.isNilpotent_range [IsNilpotent R L] (f : L →ₗ⁅R⁆ L') : IsNilpotent R f.range := f.surjective_rangeRestrict.lieAlgebra_isNilpotent #align lie_hom.is_nilpotent_range LieHom.isNilpotent_range /-- Note that this result is not quite a special case of `lie_module.is_nilpotent_range_to_endomorphism_iff` which concerns nilpotency of the `(ad R L).range`-module `L`, whereas this result concerns nilpotency of the `(ad R L).range`-module `(ad R L).range`. -/ @[simp] theorem LieAlgebra.isNilpotent_range_ad_iff : IsNilpotent R (ad R L).range ↔ IsNilpotent R L := by refine' ⟨fun h => _, _⟩ · have : (ad R L).ker = center R L := by simp exact LieAlgebra.nilpotent_of_nilpotent_quotient (le_of_eq this) ((ad R L).quotKerEquivRange.nilpotent_iff_equiv_nilpotent.mpr h) · intro h exact (ad R L).isNilpotent_range #align lie_algebra.is_nilpotent_range_ad_iff LieAlgebra.isNilpotent_range_ad_iff instance [h : LieAlgebra.IsNilpotent R L] : LieAlgebra.IsNilpotent R (⊤ : LieSubalgebra R L) := LieSubalgebra.topEquiv.nilpotent_iff_equiv_nilpotent.mpr h end NilpotentAlgebras namespace LieIdeal open LieModule variable {R L : Type _} [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) variable (M : Type _) [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable (k : ℕ) /-- Given a Lie module `M` over a Lie algebra `L` together with an ideal `I` of `L`, this is the lower central series of `M` as an `I`-module. The advantage of using this definition instead of `lie_module.lower_central_series R I M` is that its terms are Lie submodules of `M` as an `L`-module, rather than just as an `I`-module. See also `lie_ideal.coe_lcs_eq`. -/ def lcs : LieSubmodule R L M := ((fun N => ⁅I, N⁆)^[k]) ⊤ #align lie_ideal.lcs LieIdeal.lcs @[simp] theorem lcs_zero : I.lcs M 0 = ⊤ := rfl #align lie_ideal.lcs_zero LieIdeal.lcs_zero @[simp] theorem lcs_succ : I.lcs M (k + 1) = ⁅I, I.lcs M k⁆ := Function.iterate_succ_apply' (fun N => ⁅I, N⁆) k ⊤ #align lie_ideal.lcs_succ LieIdeal.lcs_succ theorem lcs_top : (⊤ : LieIdeal R L).lcs M k = lowerCentralSeries R L M k := rfl #align lie_ideal.lcs_top LieIdeal.lcs_top theorem coe_lcs_eq : (I.lcs M k : Submodule R M) = lowerCentralSeries R I M k := by induction' k with k ih · simp · simp_rw [lower_central_series_succ, lcs_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', ← (I.lcs M k).mem_coe_submodule, ih, LieSubmodule.mem_coeSubmodule, LieSubmodule.mem_top, exists_true_left, (I : LieSubalgebra R L).coe_bracket_of_module] congr ext m constructor · rintro ⟨x, hx, m, hm, rfl⟩ exact ⟨⟨x, hx⟩, m, hm, rfl⟩ · rintro ⟨⟨x, hx⟩, m, hm, rfl⟩ exact ⟨x, hx, m, hm, rfl⟩ #align lie_ideal.coe_lcs_eq LieIdeal.coe_lcs_eq end LieIdeal section OfAssociative variable (R : Type u) {A : Type v} [CommRing R] [Ring A] [Algebra R A] theorem LieAlgebra.ad_nilpotent_of_nilpotent {a : A} (h : IsNilpotent a) : IsNilpotent (LieAlgebra.ad R A a) := by rw [LieAlgebra.ad_eq_lmul_left_sub_lmul_right] have hl : IsNilpotent (LinearMap.mulLeft R a) := by rwa [LinearMap.isNilpotent_mulLeft_iff] have hr : IsNilpotent (LinearMap.mulRight R a) := by rwa [LinearMap.isNilpotent_mulRight_iff] have := @LinearMap.commute_mulLeft_right R A _ _ _ _ _ a a exact this.is_nilpotent_sub hl hr #align lie_algebra.ad_nilpotent_of_nilpotent LieAlgebra.ad_nilpotent_of_nilpotent variable {R} theorem LieSubalgebra.isNilpotent_ad_of_isNilpotent_ad {L : Type v} [LieRing L] [LieAlgebra R L] (K : LieSubalgebra R L) {x : K} (h : IsNilpotent (LieAlgebra.ad R L ↑x)) : IsNilpotent (LieAlgebra.ad R K x) := by obtain ⟨n, hn⟩ := h use n exact LinearMap.submodule_pow_eq_zero_of_pow_eq_zero (K.ad_comp_incl_eq x) hn #align lie_subalgebra.is_nilpotent_ad_of_is_nilpotent_ad LieSubalgebra.isNilpotent_ad_of_isNilpotent_ad theorem LieAlgebra.isNilpotent_ad_of_isNilpotent {L : LieSubalgebra R A} {x : L} (h : IsNilpotent (x : A)) : IsNilpotent (LieAlgebra.ad R L x) := L.isNilpotent_ad_of_isNilpotent_ad <| LieAlgebra.ad_nilpotent_of_nilpotent R h #align lie_algebra.is_nilpotent_ad_of_is_nilpotent LieAlgebra.isNilpotent_ad_of_isNilpotent end OfAssociative
{-# OPTIONS --without-K #-} module PathStructure.Sigma {a b} {A : Set a} {B : A → Set b} where open import Equivalence open import PathOperations open import Transport open import Types ap₂-dep : ∀ {a b c} {A : Set a} {B : A → Set b} {C : Set c} {x x′ : A} {y : B x} {y′ : B x′} (f : (a : A) (b : B a) → C) (p : x ≡ x′) (q : tr B p y ≡ y′) → f x y ≡ f x′ y′ ap₂-dep {B = B} f p q = J (λ x x′ p → (y : B x) (y′ : B x′) (q : tr B p y ≡ y′) → f x y ≡ f x′ y′) (λ x _ _ q → ap (f x) q) _ _ p _ _ q ap₂-dep-eq : ∀ {a b c} {A : Set a} {B : A → Set b} {C : Set c} (f : (x : A) → B x → C) {x x′ : A} (p p′ : x ≡ x′) (pp : p ≡ p′) {y : B x} {y′ : B x′} (q : tr B p y ≡ y′) (q′ : tr B p′ y ≡ y′) (qq : tr (λ z → tr B z y ≡ y′) pp q ≡ q′) → ap₂-dep f p q ≡ ap₂-dep f p′ q′ ap₂-dep-eq {B = B} f {x = x} {x′ = x′} p p′ pp q q′ qq = J (λ p p′ pp → (y : B x) (y′ : B x′) (q : tr B p y ≡ y′) (q′ : tr B p′ y ≡ y′) (qq : tr (λ z → tr B z y ≡ y′) pp q ≡ q′) → ap₂-dep f p q ≡ ap₂-dep f p′ q′) (λ p _ _ q q′ qq → J (λ q q′ qq → ap₂-dep f p q ≡ ap₂-dep f p q′) (λ _ → refl) _ _ qq) _ _ pp _ _ _ _ qq split-path : {x y : Σ A B} → x ≡ y → Σ (π₁ x ≡ π₁ y) (λ p → tr B p (π₂ x) ≡ π₂ y) split-path {x = x} p = ap π₁ p , tr-∘ π₁ p (π₂ x) ⁻¹ · apd π₂ p merge-path : {x y : Σ A B} → Σ (π₁ x ≡ π₁ y) (λ p → tr B p (π₂ x) ≡ π₂ y) → x ≡ y merge-path pq = ap₂-dep _,_ (π₁ pq) (π₂ pq) split-merge-eq : {x y : Σ A B} → (x ≡ y) ≃ Σ (π₁ x ≡ π₁ y) (λ p → tr B p (π₂ x) ≡ π₂ y) split-merge-eq = split-path , (merge-path , λ pq → J (λ x x′ p → (y : B x) (y′ : B x′) (q : tr B p y ≡ y′) → split-path (merge-path (p , q)) ≡ p , q) (λ x y y′ q → J {A = B x} (λ _ _ q → split-path (merge-path (refl , q)) ≡ refl , q) (λ _ → refl) _ _ q) _ _ (π₁ pq) _ _ (π₂ pq)) , (merge-path , J (λ _ _ p → merge-path (split-path p) ≡ p) (λ _ → refl) _ _)
data Format = Number Format | NumDouble Format | Str Format | Ch Format | Lit String Format | End %name Format fmt ||| Takes a Format and converts it to a Type that ||| includes the variable length arguments to the format string ||| ex. ||| PrintfType (toFormat (unpack "this is a literal of %d words")) ||| will return Int -> String : Type PrintfType : Format -> Type PrintfType (Number fmt) = (i : Int) -> PrintfType fmt PrintfType (NumDouble fmt) =(d : Double) -> PrintfType fmt PrintfType (Str fmt) = (s : String) -> PrintfType fmt PrintfType (Ch fmt) = (c : Char) -> PrintfType fmt PrintfType (Lit s fmt) = PrintfType fmt PrintfType End = String ||| Builds String from a Format ||| Basically recursively parses the given Format into final PrintfType to return from printf printfFmt : (fmt : Format) -> (acc : String) -> PrintfType fmt printfFmt (Number fmt) acc = \i => printfFmt fmt (acc ++ show i) printfFmt (NumDouble fmt) acc = \d => printfFmt fmt (acc ++ show d) printfFmt (Str fmt) acc = \s => printfFmt fmt (acc ++ s) printfFmt (Ch fmt) acc = \c => printfFmt fmt (acc ++ cast c) printfFmt (Lit lit fmt) acc = printfFmt fmt (acc ++ lit) printfFmt End acc = acc ||| Converts format string (with %d or %s) to Format ||| ex. toFormat (unpack "this is a literal of %d words") ||| => Lit "this is a literal of " (Number (Lit " words" End)) : Format toFormat : (xs : List Char) -> Format toFormat [] = End toFormat ('%' :: 'd' :: chars) = Number (toFormat chars) toFormat ('%' :: 'f' :: chars) = NumDouble (toFormat chars) toFormat ('%' :: 's' :: chars) = Str (toFormat chars) toFormat ('%' :: 'c' :: chars) = Ch (toFormat chars) toFormat ('%' :: chars) = Lit "%" (toFormat chars) toFormat (c :: chars) = case toFormat chars of Lit lit chars' => Lit (strCons c lit) chars' fmt => Lit (strCons c "") fmt ||| PrintfType will generate a Type based on the input string `fmt` ||| which consists of all the arguments that need to be present ||| to interpolate the string. ||| > :t printf "the %s is %d years old" : String -> Int -> String ||| > printf "the %s is %d years old" "man" 55 : String ||| => "the man is 55 years old" : String printf : (fmtStr : String) -> PrintfType (toFormat (unpack fmtStr)) printf _ = printfFmt _ "" -- full Format type inferred from above definition
lemma infdist_Un_min: assumes "A \<noteq> {}" "B \<noteq> {}" shows "infdist x (A \<union> B) = min (infdist x A) (infdist x B)"
module wuming2d use json_module use jsonio use mpiio use field use particle use mom_calc use sort use mpi_set use fio ! ! select default I/O routines ! #ifdef USE_HDF5 use h5io, & & io__init => h5io__init, & & io__finalize => h5io__finalize, & & io__param => h5io__param, & & io__input => h5io__input, & & io__output => h5io__output, & & io__mom => h5io__mom, & & io__ptcl => h5io__ptcl, & & io__orb => h5io__orb use paraio #else use h5io use paraio, & & io__init => paraio__init, & & io__finalize => paraio__finalize, & & io__param => paraio__param, & & io__input => paraio__input, & & io__output => paraio__output, & & io__mom => paraio__mom, & & io__ptcl => paraio__ptcl, & & io__orb => paraio__orb #endif implicit none end module wuming2d
lemma map_poly_0 [simp]: "map_poly f 0 = 0"
module CoPatWith where data Maybe (A : Set) : Set where nothing : Maybe A just : A -> Maybe A data _×_ (A B : Set) : Set where _,_ : A -> B -> A × B record CoList (A : Set) : Set where constructor inn field out : Maybe (A × CoList A) open CoList module With where map : {A B : Set}(f : A -> B)(l : CoList A) -> CoList B out (map f l) with out l out (map f l) | nothing = nothing out (map f l) | just (a , as) = just (f a , map f as) module NoWith where map : {A B : Set}(f : A -> B)(l : CoList A) -> CoList B out (map {A = A}{B = B} f l) = map' f l (out l) where outmap : (f : A -> B)(l : CoList A)(outl : Maybe (A × CoList A)) -> Maybe (B × CoList B) outmap f l nothing = nothing outmap f l (just (a , as)) = just (f a , map f as) module With2 where map : {A B : Set}(f : A -> B)(l : CoList A) -> CoList B out (map f (inn l)) with l out (map f (inn .nothing)) | nothing = nothing out (map f (inn .(just (a , as)))) | just (a , as) = just (f a , map f as) module NoWith2 where map : {A B : Set}(f : A -> B)(l : CoList A) -> CoList B out (map {A = A}{B = B} f l) = map' f l (out l) where outmap : (f : A -> B)(l : CoList A)(outl : Maybe (A × CoList A)) -> Maybe (B × CoList B) outmap f (inn .nothing) nothing = nothing outmap f (inn .(just (a , as))) (just (a , as)) = just (f a , map f as)
#define BOOST_TEST_MODULE "Cuttle Generator Tests" #define BOOST_TEST_DYN_LINK #include <boost/test/unit_test.hpp>
function atlas = ft_read_atlas(filename, varargin) % FT_READ_ATLAS reads an template/individual segmentation or parcellation from disk. % The volumetric segmentation or the surface-based parcellation can either represent % a template atlas (e.g. AAL or the Talairach Daemon), it can represent an % individualized atlas (e.g. obtained from FreeSurfer) or it can represent an % unlabeled parcellation/segmentation obtained from an individual's DTi, anatomical, % or resting state fMRI scan. % % Use as % atlas = ft_read_atlas(filename, ...) % or % atlas = ft_read_atlas({filenamelabels, filenamemesh}, ...) % % Additional options should be specified in key-value pairs and can include % 'format' = string, see below % 'unit' = string, e.g. 'mm' (default is to keep it in the native units of the file) % 'map' = string, 'maxprob' (default), or 'prob', for FSL-based atlases, providing % either a probabilistic segmentation or a maximum a posterior probability map % 'labelfile' = string, point to a (generic) text or xml file for interpretation of the values in the atlas % % For individual surface-based atlases from FreeSurfer you should specify two % filenames as a cell-array: the first points to the file that contains information % with respect to the parcels' labels, the second points to the file that defines the % mesh on which the parcellation is defined. % % The 'format' variable, if not specified, will be determined automatically. In general % it will not be needed to specify it. The following formats are supported: % % Volumetric atlases based on a (gzipped) nifti-file with an companion txt-file for interpretation % 'aal' assumes filename starting with 'ROI_MNI' % 'brainnetome' assumes companion lookuptable txt-file starting with 'Brainnetome Atlas' % 'simnibs_v4' assumes filename starting with 'final_tissues', with companion freesurfer-style lookuptable txt-file % 'wfu' assumes specific formatting of companion lookuptable txt-file % % Volumetric atlases based on a (gzipped) nifti-file with hard coded assumption on the labels % 'yeo7' % 'yeo17' % % Volumetric atlases based on a folder with (gzipped) nifti-files with a companion xml-file for interpretation % 'fsl' assumes path to folder with data mentioned in the xml-file. Use xml-file as filename % % Volumetric atlases based on the freesurfer mgz format with standard lookuptable txt-file for interpretation % 'freesurfer_volume' assumes the freesurfer LUT file for interpretation, and assumes aparc or aseg in the % filename, used for subject-specific parcellations % % Volumetric atlases based on the afni software % 'afni' assumes filename containing BRIK or HEAD, assumes generic interpretation of the labels % for the TTatlas+tlrc, or otherwise the interpretation should be in the file % % Volumetric atlas based on the spm_anatomy toolbox % 'spm_anatomy' pair of .hdr/.img files, and an associated mat-file for the interpretation % Specify the associated mat-file with MPM in filename % % Surface based atlases, requiring a pair of files, containing the labels, and the associated geometry % 'caret_label' hcp-workbench/caret style .gii, with .label. in filename, requires additional file describing the geometry % 'freesurfer_surface' freesurfer style annotation file, requires additional file describing the geometry % % Miscellaneous formats % 'mat' mat-file, with FieldTrip style struct, other matlab data that FieldTrip knows to handle, can also be % Brainstorm derived surfaces % 'vtpm' % % For volume data for whicth the format cannot be automatically detected, or if the volume data does not have a companion file % for the interpretation of the labels, a list of 'fake' labels will be generated. % % The output atlas will be represented as structure according to FT_DATATYPE_SEGMENTATION or % FT_DATATYPE_PARCELLATION. % % The 'lines' and the 'colorcube' colormaps may be useful for plotting the different % patches, for example using FT_PLOT_MESH, or FT_SOURCEPLOT. % % See also FT_READ_MRI, FT_READ_HEADSHAPE, FT_PREPARE_SOURCEMODEL, FT_SOURCEPARCELLATE, FT_PLOT_MESH % Copyright (C) 2005-2019, Robert Oostenveld, Ingrid Nieuwenhuis, Jan-Mathijs Schoffelen, Arjen Stolk % Copyright (C) 2023, Jan-Mathijs Schoffelen % % This file is part of FieldTrip, see http://www.fieldtriptoolbox.org % for the documentation and details. % % FieldTrip is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % FieldTrip is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with FieldTrip. If not, see <http://www.gnu.org/licenses/>. % % $Id$ % deal with multiple filenames, if the geometry and labels are stored % in different files, as with freesurfer/caret if isa(filename, 'cell') if numel(filename)==2 filenamemesh = filename{2}; filename = filename{1}; else ft_error('with multiple filenames, only 2 files are allowed'); end % if precisely two input files end % iscell % optionally get the data from an URL and make a temporary local copy filename = fetch_url(filename); [p, f, x] = fileparts(filename); labelfile = ft_getopt(varargin, 'labelfile', []); ftype = ft_filetype(filename); % if the original file was a .gz if isequal(x,'.gz') [p, f, x] = fileparts(filename(1:end-3)); end % do an educated guess of the format based on the input, ensure that the % required additional functions are available, and specify the companion labelfile if contains(filename, 'BRIK') || contains(filename, 'HEAD') % the above is needed to correctly detect zipped files ft_hastoolbox('afni', 1); % this is robust for both compressed or uncompressed afni atlases. format = 'afni'; elseif startsWith(ftype, 'nifti') % first handle the ones for which the labels are implicit in the filename if contains(f, 'Yeo2011_7Networks') % assume to be conform the shared atlas, with hardcoded index-to-label mapping format = 'yeo7'; elseif contains(f, 'Yeo2011_17Networks') % assume to be conform the shared atlas, with hardcoded index-to-label mapping format = 'yeo17'; end % try for different conventions of the naming of a potential companion labelfile if isempty(labelfile) labelfile = fullfile(p, sprintf('%s.txt', f)); if ~exist(labelfile, 'file') % in case the volume was zipped, and the txt only replaced the gz labelfile = fullfile(p, sprintf('%s.nii.txt', f)); end if ~exist(labelfile, 'file') labelfile = ''; % revert back to empty end end if ~isempty(labelfile) % do a quick check on the companion labelfile to specify the format fid = fopen_or_error(labelfile, 'rt'); l1 = fgetl(fid); if strcmp(l1(1),'[') && strcmp(l1(end),']') % specific to this one is that some of the wakeforest atlases contain non-human data, so no fixed coordsys can be assumed format = 'wfu'; coordsys = 'unknown'; elseif strcmp(l1,'Brainnetome Atlas') % specific to this one is the coordinate system it seems format = 'brainnetome'; coordsys = 'mni'; % apparently the image is in radiological convention, % so the voxel-axes are left-handed. The even valued parcels should end % up in the right hemisphere elseif contains(filename, 'ROI_MNI') || contains(filename, 'AAL') % newer versions of AAL also exist with a companion .xml file, this is not yet supported format = 'aal'; coordsys = 'mni'; end fclose(fid); end if contains(filename, 'final_tissues') ft_hastoolbox('freesurfer', 1); % required to read lookuptable % assume to be from SimNIBS version 4 format = 'simnibs_v4'; labelfile = fullfile(p, sprintf('%s_LUT.txt', f)); end if isempty(labelfile) % just a nifti file without interpretation of labels format = 'nifti_no_label'; end elseif isequal(ftype, 'freesurfer_mgz') && contains(f, 'aparc') || contains(f, 'aseg') ft_hastoolbox('freesurfer', 1); % individual volume based segmentation from freesurfer format = 'freesurfer_volume'; if isempty(labelfile) % use the version for freesurfer that is in fieldtrip/external/freesurfer [ftver, ftpath] = ft_version; labelfile = fullfile(ftpath, 'external/freesurfer', 'FreeSurferColorLUT.txt'); end elseif isequal(ftype, 'freesurfer_annot') ft_hastoolbox('freesurfer', 1); % individual volume based segmentation from freesurfer format = 'freesurfer_surface'; elseif isequal(ftype, 'caret_label') ft_hastoolbox('gifti', 1); % this is a gifti file that contains both the values for a set of vertices as well as the labels. format = 'caret_label'; elseif contains(filename, 'MPM.mat') ft_hastoolbox('spm8up', 1); % assume to be from the spm_anatomy toolbox format = 'spm_anatomy'; elseif exist(fullfile(p, [f '_MPM.mat']), 'file') ft_warning('please specify the corresponding MPM.mat file as the filename'); filename = fullfile(p, [f '_MPM.mat']); % update the filename [p, f, x] = fileparts(filename); ft_hastoolbox('spm8up', 1); % assume to be from the spm_anatomy toolbox format = 'spm_anatomy'; elseif strcmp(x, '.xml') ft_hastoolbox('gifti', 1); % required to read the xml % fsl-style atlas, this is assumed to consist of an .xml file that specifies the labels, as well as a pointer % to the file/folder with the volume data. format = 'fsl'; labelfile = fullfile(p, sprintf('%s.xml',f)); elseif strcmp(x, '.mat') % mat-file to contain a well-defined structure format = 'mat'; else format = 'unknown'; end % get the optional input arguments fileformat = ft_getopt(varargin, 'format', format); unit = ft_getopt(varargin, 'unit'); switch fileformat case {'aal' 'brainnetome' 'freesurfer_volume' 'nifti_no_label' 'simnibs_v4' 'wfu'} atlas = ft_read_mri(filename, 'outputfield', 'tissue'); % interpret the format specific labelfile if isequal(fileformat, 'aal') % The labelfile is a combination of nii+txt file, where the txt file may contain three columns like this % FAG Precentral_L 2001 % FAD Precentral_R 2002 % ... fid = fopen_or_error(labelfile, 'rt'); C = textscan(fid, '%s%s%d'); lab = C{2}; idx = C{3}; fclose(fid); elseif isequal(fileformat, 'wfu') % the download from http://fmri.wfubmc.edu comes with pairs of nii and txt files % the text file looks like this, with tabs between the colums % the section at the end with three times 191 does not always exist % % [ TD Labels] % 53 Angular Gyrus 191 191 191 % 39 Anterior Cingulate 191 191 191 % ... fid = fopen_or_error(labelfile, 'rt'); C = textscan(fid, '%d%s%*[^\n]', 'HeaderLines', 1, 'Delimiter', '\t'); lab = C{2}; idx = C{1}; fclose(fid); elseif any(strcmp(fileformat, {'simnibs_v4' 'freesurfer_volume'})) [idx, lab, rgba] = read_fscolorlut(labelfile); lab = cellstr(lab); elseif isequal(fileformat, 'brainnetome') % Brainnetome Atlas: L. Fan, et al.The Human Brainnetome Atlas: A New Brain Atlas Based on % Connectional Architecture. Cereb Cortex 2016; 26 (8): 3508-3526. doi: 10.1093/cercor/bhw157 fid = fopen_or_error(labelfile, 'rt'); fgetl(fid); % this reads: 'Brainnetome Atlas' lab = cell(246,1); for i=1:246 lab{i,1}=fgetl(fid); end idx = (1:246)'; fclose(fid); elseif isequal(fileformat, 'nifti_no_label') % the file does not exist ft_warning('cannot locate a labelfile, making default tissue labels'); idx = (1:max(atlas.tissue(:)))'; lab = cell(size(idx)); for i = 1:numel(lab) % this is consistent with FIXSEGMENTATION lab{i} = sprintf('tissue %d', i); end end if ~isfield(atlas, 'coordsys') && exist('coordsys', 'var') atlas.coordsys = coordsys; end uval = unique(atlas.tissue(:)); sel = find(ismember(idx, uval)); fprintf('subselecting %d labels from the total list of %d\n', numel(sel), numel(lab)); idx = idx(sel); lab = lab(sel); if exist('rgba', 'var') tmprgba = rgba(sel,:); rgba = zeros(0,4); end % remap the values in the data, if needed if ~isequal(idx(:)', 1:numel(idx)) dat = zeros(atlas.dim); cnt = 0; for k = 1:numel(idx) sel = atlas.tissue==idx(k); if sum(sel(:)) cnt = cnt+1; fprintf('re-indexing label %s to a value of %d (was %d)\n', lab{k}, cnt, idx(k)); dat(sel) = cnt; tissuelabel{cnt,1} = lab{k}; if exist('rgba', 'var') rgba(cnt,:) = tmprgba(k,:); end end end atlas.tissue = dat; else tissuelabel = lab; end atlas.tissuelabel = tissuelabel; if exist('rgba', 'var'), atlas.rgba = rgba; end % reduce memory footprint if numel(tissuelabel)<=intmax('uint8') atlas.tissue = uint8(atlas.tissue); elseif numel(tissuelabel)<=intmax('uint16') atlas.tissue = uint16(atlas.tissue); elseif numel(tissuelabel)<=intmax('uint32') atlas.tissue = uint32(atlas.tissue); end case 'afni' tmp = ft_read_mri(filename); if isfield(tmp, 'coordsys') && ~strcmp(tmp.coordsys, 'unknown') coordsys = tmp.coordsys; elseif isfield(tmp.hdr, 'TEMPLATE_SPACE') && ~isempty(tmp.hdr.TEMPLATE_SPACE) coordsys = lower(tmp.hdr.TEMPLATE_SPACE); % FIXME this is based on AFNI conventions, not easily decodable by FT else coordsys = 'tal'; % FIXME could be different in other atlases end if isfield(tmp.hdr, 'ATLAS_LABEL_TABLE') && ~isempty(tmp.hdr.ATLAS_LABEL_TABLE) if isfield(tmp.hdr.ATLAS_LABEL_TABLE(1), 'sb_label') && ~all(tmp.anatomy(:)==round(tmp.anatomy(:))) % probabilistic atlas isprobabilistic = true; else % indexed atlas isprobabilistic = false; end labels = {tmp.hdr.ATLAS_LABEL_TABLE.struct}'; values = [tmp.hdr.ATLAS_LABEL_TABLE.val]'; elseif contains(filename, 'TTatlas+tlrc') isprobabilistic = false; [labels, values] = TTatlas_labels; else ft_error('no information about the atlas labels is available'); end atlas = []; atlas.dim = tmp.dim(1:3); atlas.transform = tmp.transform; atlas.hdr = tmp.hdr; atlas.coordsys = coordsys; nbrick = size(tmp.anatomy,4); for k = 1:nbrick if ~isprobabilistic brickname = sprintf('brick%d',k-1); brick = tmp.anatomy(:,:,:,k); ulabel = setdiff(unique(brick(:)), 0); label = cell(size(ulabel)); nlabel = numel(label); % renumber the brick from 1:N and keep track of the label newbrick = zeros(size(brick)); for i = 1:nlabel sel = find(values==ulabel(i)); if ~isempty(sel) label(i) = labels(sel); newbrick(brick==ulabel(i)) = i; else ft_warning('the value %d does not have a label according to the ATLAS_LABEL_TABLE and will be discarded', ulabel(i)); end end atlas.(brickname) = newbrick; atlas.([brickname 'label']) = label; else atlas.(labels{k}) = tmp.anatomy(:,:,:,values(k)+1); % indexing is 0-based in this case end end case {'freesurfer_surface'} if contains(filename, 'a2009s') parcelfield = 'a2009s'; elseif contains(filename, 'aparc') parcelfield = 'aparc'; elseif contains(filename, 'ba') parcelfield = 'BA'; else ft_error('unknown freesurfer parcellation type requested'); end % read the labels [v, p, c] = read_annotation(filename); label = c.struct_names; rgba = c.table(:,1:4); rgb = c.table(:,5); % compound value that is used for the indexing in vector p index = ((1:c.numEntries)-1)'; switch ft_filetype(filenamemesh) case 'freesurfer_triangle_binary' [pos, tri] = read_surf(filenamemesh); % ensure the triangles to be 1-indexed if min(tri(:))==0 && max(tri(:))==size(pos,1)-1 tri = tri+1; end bnd.pos = pos; bnd.tri = tri; reindex = true; otherwise ft_error('unsupported fileformat for surface mesh'); end % check the number of vertices if size(bnd.pos,1) ~= numel(p) ft_error('the number of vertices in the mesh does not match the number of elements in the parcellation'); end % reindex the parcels, if needed: I am not fully sure about this, but the caret % label files seem to have the stuff numbered with normal numbers, with unknown % being -1. assuming them to be in order; if reindex % this is then freesurfer convention, coding in rgb newp = zeros(size(p)); for k = 1:numel(label) newp(p==rgb(k)) = index(k)+1; end else uniquep = unique(p); if uniquep(1)<0 p(p<0) = 0; end newp = p; end atlas = []; atlas.pos = bnd.pos; atlas.tri = bnd.tri; atlas.(parcelfield) = newp; atlas.([parcelfield, 'label']) = label; atlas.rgba = rgba; atlas = ft_determine_units(atlas); case 'caret_label' g = gifti(filename); rgba = []; if isfield(g, 'labels') label = g.labels.name(:); key = g.labels.key(:); if isfield(g.labels, 'rgba') rgba = g.labels.rgba; % I'm not sure whether this always exists end else label = g.private.label.name(:); key = g.private.label.key(:); if isfield(g.private.label, 'rgba') rgba = g.private.label.rgba; % I'm not sure whether this always exists end end %label = g.private.label.name; % provides the name of the parcel %key = g.private.label.key; % maps value to name % Store each column in cdata as an independent parcellation, because % each vertex can have multiple values in principle atlas = []; for k = 1:size(g.cdata,2) tmporig = g.cdata(:,k); tmpnew = nan(size(tmporig)); tmplabel = cell(0,1); tmprgba = zeros(0,4); cnt = 0; for m = 1:numel(label) sel = find(tmporig==key(m)); if ~isempty(sel) cnt = cnt+1; if any(strcmp(tmplabel,deblank(label{m}))) % one feature of a gifti can be that the same labels can exist (and % are treated as a different parcel) while they should be the same % parcel, i.e. when there's an empty space at the end of the label val = find(strcmp(tmplabel, deblank(label{m}))); else % add as a new label tmplabel{end+1,1} = label{m}; if ~isempty(rgba), tmprgba(end+1,:) = rgba(m,:); end val = cnt; end tmpnew(tmporig==key(m)) = val; end end % there is some additional meta data that may be useful, but for now % stick to the rather uninformative parcellation1/2/3 etc. % % if strcmp(g.private.data{k}.metadata(1).name, 'Name') % parcelfield = fixname(g.private.data{k}.metadata(1).value); % else % ft_error('could not determine parcellation name'); % end if size(g.cdata,2)>1 parcelfield = ['parcellation' num2str(k)]; else parcelfield = 'parcellation'; end atlas.(parcelfield) = tmpnew; atlas.([parcelfield 'label']) = tmplabel; if ~isempty(tmprgba), atlas.rgba = tmprgba; end end if exist('filenamemesh', 'var') tmp = ft_read_headshape(filenamemesh); atlas.pos = tmp.pos; atlas.tri = tmp.tri; atlas = ft_determine_units(atlas); elseif ~isfield(atlas, 'coordsys') atlas.coordsys = 'unknown'; end case 'spm_anatomy' % load the map, this is assumed to be the struct-array MAP load(filename); [p,f,e] = fileparts(filename); mrifilename = fullfile(p,[strrep(f, '_MPM',''),'.img']); atlas = ft_read_mri(mrifilename, 'dataformat', 'analyze_img', 'outputfield', 'tissue'); tissue = round(atlas.tissue); % I don't know why the values are non-integer label = {MAP.name}'; idx = [MAP.GV]'; % check whether all labels are present if numel(intersect(idx,unique(tissue(:))))<numel(idx) fprintf('there are fewer labels in the volume than in the list\n'); end % remap the values of the labels to run from 1-numel(idx) newtissue = zeros(size(tissue)); for k = 1:numel(idx) newtissue(tissue==idx(k)) = k; end atlas.tissue = newtissue; atlas.tissuelabel = label; atlas.coordsys = 'spm'; % I think this is safe to assume clear tissue newtissue; case 'fsl' map = ft_getopt(varargin, 'map', 'maxprob'); switch map case 'prob' imagefile = 'imagefile'; case 'maxprob' imagefile = 'summaryimagefile'; otherwise error('unknown map requested'); end ft_hastoolbox('gifti', 1); hdr = xmltree(filename); hdr = convert(hdr); % get the full path [p, f , x] = fileparts(filename); mrifilename = sprintf('%s.nii.gz', hdr.header.images{1}.(imagefile)); if isequal(mrifilename(1), '/') mrifilename = mrifilename(2:end); % remove first backslash to avoid error if no full path was given end % this uses the thresholded image switch map case 'maxprob' atlas = ft_read_mri(fullfile(p, mrifilename), 'outputfield', 'tissue'); atlas.tissuelabel = hdr.data.label(:); atlas.coordsys = 'mni'; case 'prob' tmp = ft_read_mri(fullfile(p, mrifilename)); atlas = removefields(tmp, 'anatomy'); for m = 1:numel(hdr.data.label) fn = strrep(hdr.data.label{m}, ' ' , '_'); fn = strrep(fn, '-', '_'); fn = strrep(fn, '(', ''); fn = strrep(fn, ')', ''); atlas.(fn) = tmp.anatomy(:,:,:,m); if ~isa(atlas.(fn), 'double') && ~isa(atlas.(fn), 'single') % ensure that the probabilistic values are either double or % single precision, do single precision to save memory atlas.(fn) = single(atlas.(fn)); end if any(atlas.(fn)(:)>1) && all(atlas.(fn)(:)<=100) % convert to probability values, assuming 100 to be max atlas.(fn) = atlas.(fn)./100; end end atlas.coordsys = 'mni'; atlas.dim = atlas.dim(1:3); end case 'mat' tmp = load(filename); if isfield(tmp, 'Vertices') && isfield(tmp, 'Atlas') % this applies to BrainStorm *.mat files containing cortical meshes atlas.pos = tmp.Vertices; % copy some optional fields over with a new name atlas = copyfields(tmp, atlas, {'Faces', 'Curvature', 'SulciMap'}); atlas = renamefields(atlas, {'Faces', 'Curvature', 'SulciMap'}, {'tri', 'curv', 'sulc'}); for i=1:numel(tmp.Atlas) name = fixname(tmp.Atlas(i).Name); nlabel = numel(tmp.Atlas(i).Scouts); label = cell(1, nlabel); index = zeros(size(atlas.pos,1), 1); for j=1:nlabel index(tmp.Atlas(i).Scouts(j).Vertices) = j; label{j} = tmp.Atlas(i).Scouts(j).Label; end atlas.( name ) = index; atlas.([name 'label']) = label; end elseif isfield(tmp, 'atlas') % this applies to most FieldTrip *.mat files atlas = tmp.atlas; elseif numel(fieldnames(tmp))==1 % just take whatever variable is contained in the file fn = fieldnames(tmp); atlas = tmp.(fn{1}); if isstruct(atlas) ft_warning('assuming that the variable "%s" in "%s" represents the atlas', fn{1}, filename); else ft_error('cannot read atlas structure from "%s"', filename); end else ft_error('the mat-file %s does not contain a variable called ''atlas''',filename); end case 'yeo7' % this uses Yeo2011_7Networks_MNI152_FreeSurferConformed1mm_LiberalMask_colin27.nii, which is % the 7 network parcellation from https://surfer.nmr.mgh.harvard.edu/fswiki/CorticalParcellation_Yeo2011 % aligned to the colin27 template (skull-stripped version of single_subj_T1_1mm.nii) % using AFNI's 3dQwarp and 3dNwarpApply atlas = ft_read_mri(filename, 'outputfield', 'tissue'); atlas.coordsys = 'mni'; atlas.tissuelabel = { '7Networks_1' '7Networks_2' '7Networks_3' '7Networks_4' '7Networks_5' '7Networks_6' '7Networks_7' }; colors = [ 120 18 134; 70 130 180; 0 118 14; 196 58 250; 220 248 164; 230 148 34; 205 62 78 ]; % not used case 'yeo17' % this uses Yeo2011_17Networks_MNI152_FreeSurferConformed1mm_LiberalMask_colin27.nii, which is % the 17 network parcellation from https://surfer.nmr.mgh.harvard.edu/fswiki/CorticalParcellation_Yeo2011 % aligned to the colin27 template (skull-stripped version of single_subj_T1_1mm.nii) using AFNI's 3dQwarp and 3dNwarpApply atlas = ft_read_mri(filename, 'outputfield', 'tissue'); atlas.coordsys = 'mni'; atlas.tissuelabel = { '17Networks_1' '17Networks_2' '17Networks_3' '17Networks_4' '17Networks_5' '17Networks_6' '17Networks_7' '17Networks_8' '17Networks_9' '17Networks_10' '17Networks_11' '17Networks_12' '17Networks_13' '17Networks_14' '17Networks_15' '17Networks_16' '17Networks_17' }; colors = [ 120 18 134; 255 0 0; 70 130 180; 42 204 164; 74 155 60; 0 118 14; 196 58 250; 255 152 213; 220 248 164; 122 135 50; 119 140 176; 230 148 34; 135 50 74; 12 48 255; 0 0 130; 255 255 0; 205 62 78 ]; % not used otherwise ft_error('unsupported format "%s"', fileformat); end % switch fileformat if ~isempty(unit) % ensure the atlas is in the desired units atlas = ft_convert_units(atlas, unit); else % ensure the units of the atlas are specified try atlas = ft_determine_units(atlas); catch % ft_determine_units will fail for triangle-only gifties. end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % TTatlas labels moved to a subfunction for readability of the above code function [labels, values] = TTatlas_labels % the following information is from https://sscc.nimh.nih.gov/afni/doc/misc/afni_ttatlas/index_html values = [ 68 71 20 21 22 24 25 26 27 28 29 30 31 32 33 34 35 36 37 39 40 41 42 43 44 45 46 47 48 49 50 51 52 70 72 73 74 75 76 77 124 125 126 128 129 130 131 132 133 134 135 136 137 138 144 145 151 146 147 148 149 81 82 83 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 53 54 55 56 57 58 59 60 61 62 63 66 65 127 64 67 ]; labels = { 'Hippocampus' 'Amygdala' 'Posterior Cingulate' 'Anterior Cingulate' 'Subcallosal Gyrus' 'Transverse Temporal Gyrus' 'Uncus' 'Rectal Gyrus' 'Fusiform Gyrus' 'Inferior Occipital Gyrus' 'Inferior Temporal Gyrus' 'Insula' 'Parahippocampal Gyrus' 'Lingual Gyrus' 'Middle Occipital Gyrus' 'Orbital Gyrus' 'Middle Temporal Gyrus' 'Superior Temporal Gyrus' 'Superior Occipital Gyrus' 'Inferior Frontal Gyrus' 'Cuneus' 'Angular Gyrus' 'Supramarginal Gyrus' 'Cingulate Gyrus' 'Inferior Parietal Lobule' 'Precuneus' 'Superior Parietal Lobule' 'Middle Frontal Gyrus' 'Paracentral Lobule' 'Postcentral Gyrus' 'Precentral Gyrus' 'Superior Frontal Gyrus' 'Medial Frontal Gyrus' 'Lentiform Nucleus' 'Hypothalamus' 'Red Nucleus' 'Substantia Nigra' 'Claustrum' 'Thalamus' 'Caudate' 'Caudate Tail' 'Caudate Body' 'Caudate Head' 'Ventral Anterior Nucleus' 'Ventral Posterior Medial Nucleus' 'Ventral Posterior Lateral Nucleus' 'Medial Dorsal Nucleus' 'Lateral Dorsal Nucleus' 'Pulvinar' 'Lateral Posterior Nucleus' 'Ventral Lateral Nucleus' 'Midline Nucleus' 'Anterior Nucleus' 'Mammillary Body' 'Medial Globus Pallidus' 'Lateral Globus Pallidus' 'Putamen' 'Nucleus Accumbens' 'Medial Geniculum Body' 'Lateral Geniculum Body' 'Subthalamic Nucleus' 'Brodmann area 1' 'Brodmann area 2' 'Brodmann area 3' 'Brodmann area 4' 'Brodmann area 5' 'Brodmann area 6' 'Brodmann area 7' 'Brodmann area 8' 'Brodmann area 9' 'Brodmann area 10' 'Brodmann area 11' 'Brodmann area 13' 'Brodmann area 17' 'Brodmann area 18' 'Brodmann area 19' 'Brodmann area 20' 'Brodmann area 21' 'Brodmann area 22' 'Brodmann area 23' 'Brodmann area 24' 'Brodmann area 25' 'Brodmann area 27' 'Brodmann area 28' 'Brodmann area 29' 'Brodmann area 30' 'Brodmann area 31' 'Brodmann area 32' 'Brodmann area 33' 'Brodmann area 34' 'Brodmann area 35' 'Brodmann area 36' 'Brodmann area 37' 'Brodmann area 38' 'Brodmann area 39' 'Brodmann area 40' 'Brodmann area 41' 'Brodmann area 42' 'Brodmann area 43' 'Brodmann area 44' 'Brodmann area 45' 'Brodmann area 46' 'Brodmann area 47' 'Uvula of Vermis' 'Pyramis of Vermis' 'Tuber of Vermis' 'Declive of Vermis' 'Culmen of Vermis' 'Cerebellar Tonsil' 'Inferior Semi-Lunar Lobule' 'Fastigium' 'Nodule' 'Uvula' 'Pyramis' 'Culmen' 'Declive' 'Dentate' 'Tuber' 'Cerebellar Lingual' };
(** R-CoqLib: general-purpose Coq libraries and tactics. Version 1.0 (2015-12-04) Copyright (C) 2015 Reservoir Labs Inc. All rights reserved. This file, which is part of R-CoqLib, is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License (GNU GPL v3), or (at your option) any later version. This file 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 LICENSE for more details about the use and redistribution of this file and the whole R-CoqLib library. This work is sponsored in part by DARPA MTO as part of the Power Efficiency Revolution for Embedded Computing Technologies (PERFECT) program (issued by DARPA/CMO under Contract No: HR0011-12-C-0123). The views and conclusions contained in this work are those of the authors and should not be interpreted as representing the official policies, either expressly or implied, of the DARPA or the U.S. Government. Distribution Statement "A" (Approved for Public Release, Distribution Unlimited.) *) (** Author: Tahina Ramananandro <[email protected]> More properties about real numbers. *) Require Export Reals Psatz. Require Export Lia. From Coquelicot Require Import Coquelicot. Open Scope R_scope. Lemma increasing_weaken f x y: (x < y -> f x < f y) -> x <= y -> f x <= f y. Proof. intros. destruct (Req_dec x y); subst; lra. Qed. Lemma Rle_Rpower_strong: forall e n m : R, 1 < e -> n <= m -> Rpower e n <= Rpower e m. Proof. unfold Rpower. intros. apply (increasing_weaken (fun t => exp (t * ln e))); auto. intros. apply exp_increasing. apply Rmult_lt_compat_r; auto. rewrite <- ln_1. apply ln_increasing; auto; lra. Qed. Lemma Rle_powerRZ_2: forall a b : R, forall n: nat, 0 <= a -> a <= b -> powerRZ a (Z.of_nat n) <= powerRZ b (Z.of_nat n). Proof. intros. induction n. + simpl. nra. + replace (Z.of_nat (S n)) with ( (Z.of_nat n + 1%Z)%Z) by lia. destruct H. - rewrite ?powerRZ_add; try nra. eapply Rmult_le_compat; try simpl; try nra. apply powerRZ_le; auto. - subst; destruct H0; subst; try simpl; try nra. assert ((0 < n + 1)%nat) by lia. pose proof pow_i (n+1) H0. replace (powerRZ 0 (Z.of_nat n + 1)) with (0^( n + 1)). pose proof pow_i (n+1) H0. rewrite H1. apply powerRZ_le; nra. rewrite ?pow_powerRZ; apply f_equal; lia. Qed. Lemma power_RZ_inv: forall x y, x <> 0 -> Rinv (powerRZ x y) = powerRZ x (-y). Proof. intros. destruct y; simpl; auto. apply Rinv_1. apply Rinv_inv. Qed. Lemma lesseq_less_or_eq: forall x y : R, x <= y -> x < y \/ x = y. Proof. intros. lra. Qed. Lemma Int_part_unique x z: IZR z <= x -> IZR z - x > -1 -> z = Int_part x. Proof. intros. destruct (base_Int_part x). assert (K: -1 < IZR z - IZR (Int_part x) < 1) by lra. replace (-1) with (IZR (-1)) in K by reflexivity. replace (1) with (IZR (1)) in K by reflexivity. rewrite <- minus_IZR in K. destruct K as [KL KR]. apply lt_IZR in KL. apply lt_IZR in KR. lia. Qed. Lemma IZR_Int_part x y: IZR x <= y -> (x <= Int_part y)%Z. Proof. intros. destruct (base_Int_part y). assert (K: -1 < IZR (Int_part y) - IZR x) by lra. rewrite <- minus_IZR in K. replace (-1) with (IZR (-1)) in K by reflexivity. apply lt_IZR in K. lia. Qed. Lemma powerRZ_Rpower a b: 0 < a -> powerRZ a b = Rpower a (IZR b). Proof. intros. destruct b; simpl. { rewrite Rpower_O; auto. } { unfold IZR. rewrite <- INR_IPR. rewrite Rpower_pow; auto. } rewrite IZR_NEG. unfold IZR. rewrite <- INR_IPR. rewrite Rpower_Ropp. rewrite Rpower_pow; auto. Qed. Lemma frac_part_sterbenz w: 1 <= w -> IZR (Int_part w) / 2 <= w <= 2 * IZR (Int_part w). Proof. intro K. generalize K. intro L. replace 1 with (IZR 1) in L by reflexivity. apply IZR_Int_part in L. apply IZR_le in L. simpl in L. destruct (base_Int_part w). lra. Qed. Lemma Rdiv_le_left d a b: 0 < d -> a <= b * d -> a / d <= b. Proof. intros. apply (Rmult_le_compat_r ( / d)) in H0. * rewrite Rmult_assoc in H0. rewrite <- Rinv_r_sym in H0; [ | lra]. rewrite Rmult_1_r in H0. assumption. * cut (0 < / d); [ lra | ]. apply Rinv_0_lt_compat. assumption. Qed. Lemma Rdiv_le_right_elim d a b: 0 < d -> a <= b / d -> a * d <= b. Proof. intros. apply Rdiv_le_left in H0. { unfold Rdiv in H0. rewrite Rinv_inv in H0; lra. } apply Rinv_0_lt_compat. assumption. Qed. Lemma Rdiv_lt_right d a b: 0 < d -> a * d < b -> a < b / d. Proof. intros. apply (Rmult_lt_compat_r ( / d)) in H0. * rewrite Rmult_assoc in H0. rewrite <- Rinv_r_sym in H0; [ | lra]. rewrite Rmult_1_r in H0. assumption. * apply Rinv_0_lt_compat. assumption. Qed. Lemma Rdiv_lt_left d a b: 0 < d -> a < b * d -> a / d < b. Proof. intros. apply (Rmult_lt_compat_r ( / d)) in H0. * rewrite Rmult_assoc in H0. rewrite <- Rinv_r_sym in H0; [ | lra]. rewrite Rmult_1_r in H0. assumption. * apply Rinv_0_lt_compat. assumption. Qed. Lemma Rdiv_lt_left_elim d a b: 0 < d -> a / d < b -> a < b * d. Proof. intros. apply Rdiv_lt_right in H0. { unfold Rdiv in H0. rewrite Rinv_inv in H0; lra. } apply Rinv_0_lt_compat. assumption. Qed. Lemma Rminus_diag x: x - x = 0. Proof. ring. Qed. Lemma Rminus_le x y: x - y <= 0 -> x<=y. Proof. nra. Qed. Lemma Rminus_plus_le_minus x y z: x + y <= z -> x <= z - y. Proof. intros. nra. Qed. Lemma Rabs_le_minus x y z: Rabs (x-y) <= z -> Rabs x <= z + Rabs y. Proof. intros. pose proof Rle_trans (Rabs x - Rabs y) (Rabs (x - y)) z (Rabs_triang_inv x y) H. nra. Qed. Lemma Rabs_triang1 a b u v: Rabs a <= u -> Rabs b <= v -> Rabs (a + b) <= u + v. Proof. intros. eapply Rle_trans. { apply Rabs_triang. } lra. Qed. Lemma Rabs_triang2 a b c u v: Rabs (a - b) <= u -> Rabs (b - c) <= v -> Rabs (a - c) <= u + v. Proof. intros. replace (a - c) with (a - b + (b - c)) by ring. apply Rabs_triang1; auto. Qed. Lemma neg_powerRZ (x:R) (n:Z) : x <> R0 -> 1 / (powerRZ x%R n%Z) = (powerRZ x%R (-n)%Z) . Proof. intros; pose proof power_RZ_inv x n H; symmetry; rewrite <- H0; nra. Qed. Lemma mul_hlf_powerRZ (n:Z) : / 2 * / powerRZ 2 n = powerRZ 2 (-n-1). Proof. assert (2 <> R0) by nra. replace (/ 2) with (1/2) by nra. replace (1 / 2 * / powerRZ 2 n) with (1 / 2 * powerRZ 2 (- n)). match goal with |- ?s = powerRZ ?a ?b' => replace b' with (-1 + - n)%Z by ring end. pose proof powerRZ_add 2 (-1) (-n) H. rewrite H0. replace (1 / 2) with (powerRZ 2 (-1)). reflexivity. simpl; nra. replace (powerRZ 2 (- n)) with (1 / powerRZ 2 n). nra. (apply neg_powerRZ); nra. Qed. Require Import ZArith. Require Import Coq.Lists.List. Ltac R_to_pos p := match p with | 1%R => constr:(1%positive) | 2%R => constr:(2%positive) | 3%R => constr:(3%positive) | 1 + 2 * ?q => let r := R_to_pos q in constr:(xI r) | 2 * ?q => let r := R_to_pos q in constr:(xO r) end. Ltac R_to_Z p := match p with | - ?q => let r := R_to_pos q in constr:(Z.neg r) | 0%R => constr:(0%Z) | ?q => let r := R_to_pos q in constr:(Z.pos r) end. (* Limits of derivatives and variations. *) Theorem derivable_nonpos_decr : forall (f f':R -> R) (a b:R), a < b -> (forall c:R, a < c < b -> derivable_pt_lim f c (f' c)) -> (forall c:R, a < c < b -> f' c <= 0) -> forall x1 x2, a < x1 -> x1 <= x2 -> x2 < b -> f x2 <= f x1. Proof. intros. destruct (Req_dec x1 x2). { apply Req_le. congruence. } assert (K: x1 < x2) by lra. destruct (MVT_cor2 f f' _ _ K) as (c & ? & ?). { intros. apply H0. lra. } cut (f' c * (x2 - x1) <= 0); [ lra | ]. rewrite <- Ropp_0. rewrite <- (Ropp_involutive (f' c)). rewrite Ropp_mult_distr_l_reverse. apply Ropp_le_contravar. apply Rmult_le_pos. { assert (f' c <= 0) by (apply H1; lra). lra. } lra. Qed. Theorem derivable_nonneg_incr : forall (f f':R -> R) (a b:R), a < b -> (forall c:R, a < c < b -> derivable_pt_lim f c (f' c)) -> (forall c:R, a < c < b -> 0 <= f' c) -> forall x1 x2, a < x1 -> x1 <= x2 -> x2 < b -> f x1 <= f x2. Proof. intros. cut (opp_fct f x2 <= opp_fct f x1). { unfold opp_fct. lra. } eapply derivable_nonpos_decr with (a := a) (b := b) (f' := opp_fct f'); eauto. { intros. apply derivable_pt_lim_opp. auto. } unfold opp_fct. intros. replace 0 with (- 0) by ring. apply Ropp_le_contravar. auto. Qed. Theorem derivable_nonneg_incr' : forall (f f':R -> R) (a b:R), (forall c:R, a <= c <= b -> derivable_pt_lim f c (f' c)) -> (forall c:R, a <= c <= b -> 0 <= f' c) -> a <= b -> f a <= f b. Proof. intros. destruct (Req_dec a b). { subst. lra. } assert (K: a < b) by lra. destruct (MVT_cor2 f f' _ _ K H) as (c & ? & ?). cut (0 <= f' c * (b - a)); [ lra | ]. apply Rmult_le_pos. { apply H0. lra. } lra. Qed. Theorem derivable_nonpos_decr' : forall (f f':R -> R) (a b:R), (forall c:R, a <= c <= b -> derivable_pt_lim f c (f' c)) -> (forall c:R, a <= c <= b -> f' c <= 0) -> a <= b -> f b <= f a. Proof. intros. cut (opp_fct f a <= opp_fct f b). { unfold opp_fct. lra. } apply derivable_nonneg_incr' with (opp_fct f'). { intros. apply derivable_pt_lim_opp. auto. } { intros. generalize (H0 _ H2). unfold opp_fct. lra. } assumption. Qed. (* Absolute error for sine/cosine *) Lemma sin_ub x: 0 <= x -> sin x <= x. Proof. intros. pose (f t := sin t - t). cut (f x <= f 0). { unfold f. rewrite sin_0. lra. } apply derivable_nonpos_decr' with (f' := fun t => cos t - 1); auto; intros. { apply derivable_pt_lim_minus. { apply derivable_pt_lim_sin. } apply derivable_pt_lim_id. } generalize (COS_bound c). lra. Qed. Corollary sin_ub_abs_pos x: 0 <= x -> Rabs x <= PI / 2 -> Rabs (sin x) <= Rabs x. Proof. intro. rewrite (Rabs_right x) by lra. intro. rewrite Rabs_right. { apply sin_ub; auto. } apply Rle_ge. rewrite <- sin_0. generalize PI2_3_2; intro. apply sin_incr_1; try lra. Qed. Corollary sin_ub_abs x: Rabs x <= PI / 2 -> Rabs (sin x) <= Rabs x. Proof. intros. destruct (Rle_dec 0 x). { apply sin_ub_abs_pos; auto. } rewrite <- Rabs_Ropp. rewrite <- sin_neg. revert H. rewrite <- (Rabs_Ropp x). apply sin_ub_abs_pos. lra. Qed. Lemma sin_absolute_error_term x d: sin (x + d) - sin x = 2 * cos (x + d / 2) * sin (d / 2). Proof. replace (x + d) with (x + d / 2 + d / 2) by field. replace x with (x + d / 2 - d / 2) at 2 by field. rewrite sin_plus. rewrite sin_minus. ring. Qed. Lemma sin_absolute_error_bound' x d: Rabs d <= PI -> Rabs (sin (x + d) - sin x) <= Rabs d. Proof. intros. rewrite sin_absolute_error_term. rewrite Rabs_mult. rewrite Rabs_mult. rewrite Rabs_right by lra. replace (Rabs d) with (2 * 1 * Rabs (d / 2)) by (unfold Rdiv; rewrite Rabs_mult; rewrite (Rabs_right ( / 2)) by lra; field). repeat rewrite Rmult_assoc. apply Rmult_le_compat_l. { lra. } apply Rmult_le_compat; auto using Rabs_pos. { apply Rabs_le. apply COS_bound. } apply sin_ub_abs. unfold Rdiv. rewrite Rabs_mult. rewrite (Rabs_right (/ 2)) by lra. lra. Qed. Lemma sin_absolute_error_bound x d: Rabs (sin (x + d) - sin x) <= Rmin (Rabs d) 2. Proof. unfold Rmin. destruct (Rle_dec (Rabs d) 2). { apply sin_absolute_error_bound'. generalize (PI2_3_2). lra. } eapply Rle_trans. { apply Rabs_triang. } rewrite Rabs_Ropp. apply Rplus_le_compat; apply Rabs_le; apply SIN_bound. Qed. Lemma cos_absolute_error_bound x d: Rabs (cos (x + d) - cos x) <= Rmin (Rabs d) 2. Proof. repeat rewrite cos_sin. rewrite <- Rplus_assoc. apply sin_absolute_error_bound. Qed. Lemma sin_abs_error a b d: Rabs (a - b) <= d -> Rabs (sin a - sin b) <= d. Proof. intros. replace a with (b + (a - b)) by ring. eapply Rle_trans. { eapply sin_absolute_error_bound. } eapply Rle_trans. { apply Rmin_l. } assumption. Qed. Lemma cos_abs_error a b d: Rabs (a - b) <= d -> Rabs (cos a - cos b) <= d. Proof. intros. replace a with (b + (a - b)) by ring. eapply Rle_trans. { eapply cos_absolute_error_bound. } eapply Rle_trans. { apply Rmin_l. } assumption. Qed. Lemma sin_abs x: Rabs x <= PI -> sin (Rabs x) = Rabs (sin x). Proof. intros H. destruct (Rle_dec 0 x). { rewrite Rabs_right in * |- * by lra. rewrite Rabs_right; auto. generalize (sin_ge_0 x). lra. } destruct (Req_dec x (-PI)). { subst. rewrite sin_neg. repeat rewrite Rabs_Ropp. rewrite Rabs_right by lra. rewrite sin_PI. rewrite Rabs_R0. reflexivity. } rewrite Rabs_left in * |- * by lra. rewrite sin_neg. rewrite Rabs_left; auto. apply sin_lt_0_var; lra. Qed. Lemma cos_abs_eq u: cos (Rabs u) = cos u. Proof. destruct (Rle_dec 0 u). { rewrite Rabs_right by lra. reflexivity. } rewrite Rabs_left by lra. apply cos_neg. Qed. Lemma abs_sign (b: bool): Rabs (if b then -1 else 1) = 1. Proof. destruct b. { rewrite IZR_NEG. rewrite Rabs_Ropp. apply Rabs_R1. } apply Rabs_R1. Qed. (* Square root *) Lemma sqrt_pos_strict x: 0 < x -> 0 < sqrt x. Proof. intros. assert (sqrt x <> 0). { intro ABSURD. apply sqrt_eq_0 in ABSURD; lra. } generalize (sqrt_pos x). lra. Qed. Lemma cos_sin_plus_bound a: Rabs (cos a + sin a) <= sqrt 2. Proof. rewrite <- cos_shift. rewrite form1. match goal with |- Rabs (2 * cos ?u * cos ?v) <= _ => replace v with (PI / 4) by field; rewrite cos_PI4 end. assert (0 < sqrt 2) as HSQRT. { apply sqrt_pos_strict. lra. } rewrite Rabs_mult. eapply Rle_trans. { apply Rmult_le_compat; auto using Rabs_pos. { rewrite Rabs_mult. apply Rmult_le_compat; auto using Rabs_pos. { rewrite Rabs_right by lra. apply Rle_refl. } apply Rabs_le. apply COS_bound. } rewrite Rabs_right. { apply Rle_refl. } apply Rinv_0_lt_compat in HSQRT. lra. } eapply (eq_rect_r (fun t => t <= _)). { apply Rle_refl. } rewrite <- (sqrt_sqrt 2) at 1 by lra. unfold IPR. field. lra. Qed. Lemma cos_sin_minus_bound a: Rabs (cos a - sin a) <= sqrt 2. Proof. rewrite <- cos_neg. unfold Rminus. rewrite <- sin_neg. apply cos_sin_plus_bound. Qed. Lemma abs_cos_sin_plus_1 a: 0 <= a <= PI / 2 -> Rabs (cos a) + Rabs (sin a) = cos a + sin a. Proof. intros. generalize (cos_ge_0 a ltac:( lra ) ltac:( lra ) ). generalize (sin_ge_0 a ltac:( lra ) ltac:( lra ) ). intros. repeat rewrite Rabs_right by lra. reflexivity. Qed. Lemma abs_cos_sin_plus_aux_2 a: 0 <= a <= PI -> exists b, Rabs (cos a) + Rabs (sin a) = cos b + sin b. Proof. intros. destruct (Rle_dec a (PI / 2)). { exists a. apply abs_cos_sin_plus_1. lra. } exists (PI - a). replace a with ((- (PI - a)) + PI) at 1 by ring. rewrite neg_cos. rewrite cos_neg. rewrite Rabs_Ropp. replace a with (PI - (PI - a)) at 2 by ring. rewrite sin_PI_x. apply abs_cos_sin_plus_1. lra. Qed. Lemma abs_cos_sin_plus_aux_3 a: - PI <= a <= PI -> exists b, Rabs (cos a) + Rabs (sin a) = cos b + sin b. Proof. intros. destruct (Rle_dec 0 a). { apply abs_cos_sin_plus_aux_2. lra. } replace a with (- (- a)) by ring. rewrite cos_neg. rewrite sin_neg. rewrite Rabs_Ropp. apply abs_cos_sin_plus_aux_2. lra. Qed. Lemma cos_period_1 x k: (0 <= k)%Z -> cos (x + 2 * IZR k * PI) = cos x. Proof. intro LE. apply IZN in LE. destruct LE. subst. rewrite <- INR_IZR_INZ. apply cos_period. Qed. Lemma cos_period' k x: cos (x + 2 * IZR k * PI) = cos x. Proof. destruct (Z_le_dec 0 k) as [ LE | ]. { apply cos_period_1. lia. } match goal with |- cos ?a = _ => rewrite <- (Ropp_involutive a); rewrite cos_neg; replace (- a) with ((- x) + 2 * (- IZR k) * PI) by ring end. rewrite <- opp_IZR. rewrite cos_period_1 by lia. apply cos_neg. Qed. Lemma sin_period' k x: sin (x + 2 * IZR k * PI) = sin x. Proof. repeat rewrite <- cos_shift. match goal with |- cos ?a = _ => replace a with (PI / 2 - x + 2 * (- IZR k) * PI) by ring end. rewrite <- opp_IZR. apply cos_period'. Qed. Lemma frac_part_ex x: { i | IZR (Int_part x) = x - i /\ 0 <= i < 1 }. Proof. exists (x - IZR (Int_part x)). split. { ring. } generalize (base_Int_part x). lra. Qed. Lemma sin_period_minus x z: sin (x - IZR z * (2 * PI)) = sin x. Proof. unfold Rminus. rewrite <- Ropp_mult_distr_l_reverse. rewrite <- opp_IZR. generalize (- z)%Z. clear z. intro z. replace (IZR z * (2 * PI)) with (2 * IZR z * PI) by ring. destruct z; simpl. { f_equal. ring. } { unfold IZR. rewrite <- !INR_IPR. apply sin_period. } unfold IZR. rewrite <- !INR_IPR. generalize (Pos.to_nat p). clear p. simpl. intro n. rewrite <- (sin_period _ n). f_equal. ring. Qed. Lemma cos_period_minus x z: cos (x - IZR z * (2 * PI)) = cos x. Proof. repeat rewrite <- sin_shift. replace (PI / 2 - (x - IZR z * (2 * PI))) with (PI / 2 - x - IZR (- z) * (2 * PI)). { apply sin_period_minus. } rewrite opp_IZR. ring. Qed. Lemma cos_PI_x x: cos (PI - x) = - cos x. Proof. replace (PI - x) with ((-x) + PI) by ring. rewrite neg_cos. rewrite cos_neg. reflexivity. Qed. Lemma abs_cos_sin_plus a: exists b, Rabs (cos a) + Rabs (sin a) = cos b + sin b. Proof. remember (a / (2 * PI) + / 2) as u. remember (- Int_part u)%Z as k. rewrite <- (cos_period' k). rewrite <- (sin_period' k). apply abs_cos_sin_plus_aux_3. subst k. rewrite opp_IZR. destruct (base_Int_part u). remember (IZR (Int_part u)) as k. clear Heqk. subst. assert (k - / 2 <= a / (2 * PI)) as LE by lra. assert (a / (2 * PI) < k + 1 - / 2) as LT by lra. generalize (PI_RGT_0). intros. apply Rdiv_le_right_elim in LE; [ | lra ] . match type of LE with ?v <= _ => replace v with (- (2 * - k * PI) - PI) in LE by field end. apply Rdiv_lt_left_elim in LT; [ | lra ] . match type of LT with _ < ?v => replace v with (- (2 * - k * PI) + PI) in LT by field end. lra. Qed. Corollary abs_cos_sin_plus_le a: Rabs (cos a) + Rabs (sin a) <= sqrt 2. Proof. match goal with |- ?u <= _ => rewrite <- (Rabs_right u) end. { destruct (abs_cos_sin_plus a) as (? & K). rewrite K. apply cos_sin_plus_bound. } generalize (Rabs_pos (cos a)). generalize (Rabs_pos (sin a)). lra. Qed. Lemma sqrt_abs_error x d: 0 <= x -> 0 <= x + d -> sqrt (x + d) - sqrt x = d / (sqrt (x + d) + sqrt x). Proof. intros. destruct (Req_dec d 0). { subst. unfold Rdiv. rewrite Rplus_0_r. ring. } assert (0 < x \/ 0 < x + d) as OR by lra. assert (0 + 0 < sqrt (x + d) + sqrt x). { destruct OR. { apply Rplus_le_lt_compat. { apply sqrt_pos. } apply sqrt_pos_strict. assumption. } apply Rplus_lt_le_compat. { apply sqrt_pos_strict. assumption. } apply sqrt_pos. } replace d with (x + d - x) at 2 by ring. rewrite <- (sqrt_sqrt (x + d)) at 2 by assumption. rewrite <- (sqrt_sqrt x) at 5 by assumption. field. lra. Qed. Lemma sqrt_abs_error' x y: 0 <= x -> 0 <= y -> Rabs (sqrt y - sqrt x) = Rabs (y - x) / (sqrt y + sqrt x). Proof. intros. replace y with (x + (y - x)) at 1 by ring. rewrite sqrt_abs_error by lra. unfold Rdiv. rewrite Rabs_mult. replace (x + (y - x)) with y by ring. destruct (Req_dec y x). { subst. rewrite Rminus_diag. rewrite Rabs_R0. ring. } f_equal. assert (0 < x \/ 0 < y) as OR by lra. generalize match OR with | or_introl K => or_introl (sqrt_pos_strict _ K) | or_intror K => or_intror (sqrt_pos_strict _ K) end. intros. generalize (sqrt_pos x). generalize (sqrt_pos y). intros. rewrite Rabs_inv by lra. f_equal. rewrite Rabs_right by lra. reflexivity. Qed. Corollary sqrt_abs_error_bound x y d: Rabs (y - x) <= d -> 0 < x (* one of the two must be positive, we arbitrarily choose x *) -> 0 <= y -> Rabs (sqrt y - sqrt x) <= d / (sqrt y + sqrt x). Proof. intros Hxy Hx Hy. generalize (sqrt_pos y). intro. generalize (sqrt_pos_strict _ Hx). intro. rewrite sqrt_abs_error' by lra. apply Rmult_le_compat_r. { apply Rlt_le. apply Rinv_0_lt_compat. lra. } assumption. Qed. Lemma sqrt_succ_le : forall n: R, 0 <= n -> sqrt(n) < sqrt(n+1). Proof. intros. assert (0 <= n+1) by nra. assert (n < n+1) by nra. pose proof sqrt_lt_1 n (n+1) H H0 H1; apply H2. Qed. Lemma eq_le_le x y: x = y -> y <= x <= y. Proof. lra. Qed. Lemma Rdiv_le_0_compat_Raux : forall r1 r2 : R, 0 <= r1 -> 0 < r2 -> 0 <= r1 / r2. Proof. apply Rdiv_le_0_compat; auto. Qed. Lemma Rabs_div_Raux : forall a b : R, b <> 0 -> Rabs (a/b) = (Rabs a) / (Rabs b). Proof. apply Rabs_div; auto. Qed. Lemma Rabs_div_eq : forall a b , b <> 0 -> 0 <= b -> Rabs (a /b) = Rabs a / b. Proof. intros. rewrite Rabs_div; try nra; replace (Rabs b) with b; try nra; symmetry; apply Rabs_pos_eq; auto. Qed. Lemma Rminus_rel_error : forall u1 u2 v1 v2, ((u1 - v1) ) - (u2 - v2) = (u1 - u2) - (v1 - v2). Proof. intros. nra. Qed. Lemma Rplus_rel_error: forall u1 u2 v1 v2, (u1 + v1) - (u2 + v2) = (u1 - u2) + (v1 - v2). Proof. intros. nra. Qed. Lemma Rmult_rel_error: forall a b c d, (a * b) - (c * d) = (a - c)*d + (b - d)*c + (a-c) * (b-d). Proof. intros. nra. Qed. Lemma Rdiv_rel_error : forall u v u' v', v' <>0 -> v <> 0 -> u <> 0 -> u'/v' - u/v = ((u'-u)/u - (v'-v)/v ) * (1 / (1 + ((v'-v)/v))) * (u/v). Proof. intros. field_simplify; repeat try split; try nra; auto. Qed. Lemma Rdiv_rel_error_add : forall u v u' v', v' <>0 -> v <> 0 -> u <> 0 -> Rabs (u'/v' - u/v) <= (Rabs((u'-u) / u) + Rabs((v'-v) /v)) * Rabs (1 / (1 + ((v'-v)/v))) * Rabs (u/v). Proof. intros. rewrite Rdiv_rel_error; auto. rewrite Rabs_mult. rewrite Rabs_mult. eapply Rle_trans. rewrite Rmult_assoc. apply Rmult_le_compat. apply Rabs_pos. rewrite <- Rabs_mult. apply Rabs_pos. match goal with |- Rabs (?a/u - ?b /v) <= _=> replace (a/u - b /v) with (a/u + (v - v') /v) by nra end. eapply Rle_trans. apply Rabs_triang. apply Rplus_le_compat. apply Rle_refl. apply Rle_refl. apply Rle_refl. rewrite Rmult_assoc. replace ((v - v')/v) with (-((v' - v)/v)) by nra. rewrite Rabs_Ropp. apply Rle_refl. Qed. Lemma Rdiv_rel_error_add_reduced_r : forall u v u' v', v' <>0 -> v <> 0 -> u <> 0 -> Rabs (u'/v' - u/v) <= (Rabs((u'-u)/u) + Rabs (v'-v) * Rabs(1/v)) * Rabs (1 / (1 + ((v'-v)/v))) * Rabs (u/v). Proof. intros. rewrite Rdiv_rel_error; auto. eapply Rle_trans. rewrite Rmult_assoc. rewrite Rabs_mult. apply Rmult_le_compat. apply Rabs_pos. apply Rabs_pos. match goal with |- Rabs (?a/u - ?b /v) <= _=> replace (a/u - b /v) with (a/u + (v - v') /v) by nra end. match goal with |- Rabs (?a/u + ?b /v) <= _=> replace (a/u + b /v) with (a/u + b * (1 /v)) end. eapply Rle_trans. apply Rabs_triang. apply Rplus_le_compat. apply Rle_refl. rewrite Rabs_mult. rewrite Rabs_minus_sym. apply Rle_refl. field_simplify. f_equal. split; auto. split; auto. rewrite Rabs_mult; apply Rle_refl. rewrite Rmult_assoc. apply Rle_refl. Qed. Lemma Rdiv_rel_error_add_reduced_l : forall u v u' v', v' <>0 -> v <> 0 -> u <> 0 -> Rabs (u'/v' - u/v) <= (Rabs(u'-u) * Rabs(1/u) + Rabs((v'-v)/v)) * Rabs (1 / (1 + ((v'-v)/v))) * Rabs (u/v). Proof. intros. rewrite Rdiv_rel_error; auto. eapply Rle_trans. rewrite Rmult_assoc. rewrite Rabs_mult. apply Rmult_le_compat. apply Rabs_pos. apply Rabs_pos. match goal with |- Rabs (?a/u - ?b /v) <= _=> replace (a/u - b /v) with (a/u + (v - v') /v) by nra end. match goal with |- Rabs (?a/u + ?b /v) <= _=> replace (a/u + b /v) with (a * (1/u) + b /v) end. eapply Rle_trans. apply Rabs_triang. apply Rplus_le_compat. rewrite Rabs_mult. apply Rle_refl. rewrite <- Rabs_Ropp. apply Rle_refl. field_simplify. f_equal. split; auto. split; auto. rewrite Rabs_mult; apply Rle_refl. rewrite Rmult_assoc. apply Req_le. f_equal. f_equal. f_equal. nra. Qed. Lemma Rdiv_rel_error_add_reduced : forall u v u' v', v' <>0 -> v <> 0 -> u <> 0 -> Rabs (u'/v' - u/v) <= (Rabs(u'-u) * Rabs (1/u) + Rabs (v'-v) * Rabs(1/v)) * Rabs (1 / (1 + ((v'-v)/v))) * Rabs (u/v). Proof. intros. rewrite Rdiv_rel_error; auto. eapply Rle_trans. rewrite Rmult_assoc. rewrite Rabs_mult. apply Rmult_le_compat. apply Rabs_pos. apply Rabs_pos. match goal with |- Rabs (?a/u - ?b /v) <= _=> replace (a/u - b /v) with (a/u + (v - v') /v) by nra end. match goal with |- Rabs (?a/u + ?b /v) <= _=> replace (a/u + b /v) with (a * (1/u) + b * (1 /v)) end. eapply Rle_trans. apply Rabs_triang. apply Rplus_le_compat. rewrite Rabs_mult; apply Rle_refl. rewrite Rabs_mult. rewrite Rabs_minus_sym. apply Rle_refl. field_simplify. f_equal. split; auto. split; auto. rewrite Rabs_mult; apply Rle_refl. rewrite Rmult_assoc. apply Rle_refl. Qed. Lemma Rdiv_rel_error_no_u_div' : forall u v u' v', v' <>0 -> v <> 0 -> u'/v' - u/v = ((u'-u) - (v'-v) * 1/v * u) * (1 / (1 + ((v'-v)/v))) * (1/v). Proof. intros. field_simplify; repeat try split; try nra; auto. Qed. Lemma Rdiv_rel_error_no_u_div2 : forall u v u' v', v' <>0 -> v <> 0 -> u'/v' - u/v = ((u'-u) - (v'-v)/v * u) * (1 / (1 + ((v'-v)/v))) * (1/v). Proof. intros. field_simplify; repeat try split; try nra; auto. Qed. Lemma Rdiv_rel_error_no_u_div_reduced : forall u v u' v', v' <>0 -> v <> 0 -> Rabs (u'/v' - u/v) <= (Rabs (u'-u) + Rabs ((v'-v)) * Rabs (1/v) * Rabs u) * Rabs (1 / (1 + ((v'-v)/v))) * Rabs (1/v). Proof. intros. rewrite Rdiv_rel_error_no_u_div'; auto. eapply Rle_trans. rewrite Rmult_assoc. rewrite Rabs_mult. apply Rmult_le_compat. apply Rabs_pos. apply Rabs_pos. match goal with |- Rabs (?a - (v' - v) *1/v * u) <= _=> replace (a - (v' - v) * 1/v * u) with (a + (v - v') * (1/v) * u) by nra end. eapply Rle_trans. apply Rabs_triang. apply Rplus_le_compat. apply Rle_refl. rewrite Rabs_mult. apply Rmult_le_compat; try apply Rabs_pos. rewrite Rabs_mult. apply Rmult_le_compat; try apply Rabs_pos. rewrite <- Rabs_Ropp; apply Rle_refl. apply Rle_refl. apply Rle_refl. rewrite Rabs_mult. apply Rmult_le_compat; try apply Rabs_pos. apply Rle_refl. apply Rle_refl. repeat rewrite Rmult_assoc. apply Req_le. f_equal. f_equal. f_equal. f_equal. nra. Qed. Lemma Rdiv_rel_error_no_u_div_reduced2 : forall u v u' v', v' <>0 -> v <> 0 -> Rabs (u'/v' - u/v) <= (Rabs (u'-u) + Rabs ((v'-v)/v)* Rabs u) * Rabs (1 / (1 + ((v'-v)/v))) * Rabs (1/v). Proof. intros. rewrite Rdiv_rel_error_no_u_div2; auto. eapply Rle_trans. rewrite Rmult_assoc. rewrite Rabs_mult. apply Rmult_le_compat. apply Rabs_pos. apply Rabs_pos. match goal with |- Rabs (?a - (v' - v)/v * u) <= _=> replace (a - (v' - v)/v * u) with (a + (v - v')/v * u) by nra end. eapply Rle_trans. apply Rabs_triang. apply Rplus_le_compat. apply Rle_refl. rewrite Rabs_mult. apply Rmult_le_compat; try apply Rabs_pos. rewrite <- Rabs_Ropp; apply Rle_refl. apply Rle_refl. apply Rle_refl. repeat rewrite Rmult_assoc. apply Req_le. f_equal. f_equal. f_equal. f_equal. nra. rewrite Rabs_mult. nra. Qed. Lemma Rplus_opp : forall a b, a + - b = a - b. Proof. intros. nra. Qed. Lemma Rabs_Ropp2 : forall A D U, Rabs(-A * D - - U) = Rabs(A * D - U). Proof. intros. rewrite <- Rabs_Ropp. rewrite Ropp_minus_distr. f_equal. nra. Qed.
[STATEMENT] lemma semantics_fresh: \<open>i \<notin> nominals p \<Longrightarrow> (M, g, w \<Turnstile> p) = (M, g(i := v), w \<Turnstile> p)\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. i \<notin> nominals p \<Longrightarrow> (M, g, w \<Turnstile> p) = (M, g(i := v), w \<Turnstile> p) [PROOF STEP] by (induct p arbitrary: w) auto
lemma measurable_gfp_coinduct[consumes 1, case_names continuity step]: fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_lattice, countable})" assumes "P M" assumes F: "inf_continuous F" assumes *: "\<And>M A. P M \<Longrightarrow> (\<And>N. P N \<Longrightarrow> A \<in> measurable N (count_space UNIV)) \<Longrightarrow> F A \<in> measurable M (count_space UNIV)" shows "gfp F \<in> measurable M (count_space UNIV)"
C C************************** BOUNDIR ************************************ C C puntdir are the pointers to pass from a global dirichlet numbering C to a local dirichlet numbering C*********************************************************************** C subroutine BOUNDIR(nface,np,contp,puntdir) implicit none integer nface, np integer contp(*), puntdir(*) integer i,iface C puntdir is the inverse function of edgedir C do i=1,nface puntdir(i)=0 end do do i=1,np iface=contp(i) puntdir(iface)=i end do return end
install.packages("languageserver", dependencies = TRUE, repos="http://cran.rstudio.com/") install.packages("reticulate", dependencies=TRUE, repos="http://cran.rstudio.com/") library(reticulate) # Dynamically find system Python python_path <- system("which python", intern=TRUE) use_python(python_path) # Pre compile orchest deps orchest <- import("orchest") print(orchest)
open import bool module list-merge-sort (A : Set) (_<A_ : A → A → 𝔹) where open import braun-tree A _<A_ open import eq open import list open import nat open import nat-thms merge : (l1 l2 : 𝕃 A) → 𝕃 A merge [] ys = ys merge xs [] = xs merge (x :: xs) (y :: ys) with x <A y merge (x :: xs) (y :: ys) | tt = x :: (merge xs (y :: ys)) merge (x :: xs) (y :: ys) | ff = y :: (merge (x :: xs) ys) merge-sort-h : ∀{n : ℕ} → braun-tree' n → 𝕃 A merge-sort-h (bt'-leaf a) = [ a ] merge-sort-h (bt'-node l r p) = merge (merge-sort-h l) (merge-sort-h r) merge-sort : 𝕃 A → 𝕃 A merge-sort [] = [] merge-sort (a :: as) with 𝕃-to-braun-tree' a as merge-sort (a :: as) | t = merge-sort-h t
Highly coveted location! Amazing Beach Plantation masterpiece built by Zivec & Corbet Development. This model home offers the the finest details and interior finishes by Paul L'Esperance. This magnificent home is located on a prime "South Facing" 6250 sq. ft corner lot. Thoughtfully designed, this 5870 sq. ft custom property features 6 bedrooms, 8 baths and is perfect for entertaining. The open floor plan boasts 11 ft ceilings, a designer kitchen that opens to a spacious living area, outdoor yard and covered patio area with private retreat.. The kitchen features a 36 inch Subzero freezer and a 36 inch Sub Zero fridge, 48 inch Wolf range/double oven and microwave. There is also a Sub Zero fridge/ice maker in the bar. The spacious downstairs family area has a beautiful built-in bar, 1500 bottle walk in wine cellar and state of the art movie theater. The floor plan is open and bright and drenched with sunlight. Listing provided by : Brett Zebrowski, Palm Realty Boutique, Inc.
theory Chisholm imports SDL (* Christoph Benzmüller, 2018 *) begin (* Chisholm Example *) consts go::\<sigma> tell::\<sigma> kill::\<sigma> axiomatization where D1: "\<lfloor>\<^bold>O\<^bold>\<langle>go\<^bold>\<rangle>\<rfloor>" (*It ought to be that Jones goes to assist his neighbors.*) and D2: "\<lfloor>\<^bold>O\<^bold>\<langle>go \<^bold>\<rightarrow> tell\<^bold>\<rangle>\<rfloor>" (*It ought to be that if Jones goes, then he tells them he is coming.*) and D3: "\<lfloor>\<^bold>\<not>go \<^bold>\<rightarrow> \<^bold>O\<^bold>\<langle>\<^bold>\<not>tell\<^bold>\<rangle>\<rfloor>" (*If Jones doesn't go, then he ought not tell them he is coming.*) and D4: "\<lfloor>\<^bold>\<not>go\<rfloor>\<^sub>c\<^sub>w" (*Jones doesn't go. (This is encoded as a locally valid statement.)*) (*Some Experiments*) sledgehammer_params [max_facts=20] (*Sets default parameters for the theorem provers*) nitpick_params [user_axioms,expect=genuine,show_all,format=2] (*... and for the model finder.*) lemma True nitpick [satisfy] oops (*Consistency-check: Is there a model?*) lemma False sledgehammer oops (*Inconsistency-check: Can Falsum be derived?*) lemma "\<lfloor>\<^bold>O\<^bold>\<langle>\<^bold>\<not>tell\<^bold>\<rangle>\<rfloor>" sledgehammer nitpick oops (*Should James not tell?*) lemma "\<lfloor>\<^bold>O\<^bold>\<langle>tell\<^bold>\<rangle>\<rfloor>" sledgehammer nitpick oops (*Should James tell?*) lemma "\<lfloor>\<^bold>O\<^bold>\<langle>kill\<^bold>\<rangle>\<rfloor>" sledgehammer nitpick oops (*Should James kill?*) end
import Relation.Binary.Reasoning.Setoid as SetoidR open import SingleSorted.AlgebraicTheory import SingleSorted.Interpretation as Interpretation import SingleSorted.Model as Model import SingleSorted.UniversalInterpretation as UniversalInterpretation import SingleSorted.Substitution as Substitution import SingleSorted.SyntacticCategory as SyntacticCategory module SingleSorted.UniversalModel {ℓt} {Σ : Signature} (T : Theory ℓt Σ) where open Theory T open Substitution T open UniversalInterpretation T open Interpretation.Interpretation ℐ open SyntacticCategory T 𝒰 : Model.Model T cartesian-𝒮 ℐ 𝒰 = record { model-eq = λ ε var-var → let open SetoidR (eq-setoid (ax-ctx ε)) in begin interp-term (ax-lhs ε) var-var ≈⟨ interp-term-self (ax-lhs ε) var-var ⟩ ax-lhs ε ≈⟨ id-action ⟩ ax-lhs ε [ id-s ]s ≈⟨ eq-axiom ε id-s ⟩ ax-rhs ε [ id-s ]s ≈˘⟨ id-action ⟩ ax-rhs ε ≈˘⟨ interp-term-self (ax-rhs ε) var-var ⟩ interp-term (ax-rhs ε) var-var ∎ }
lemma lead_coeff_1 [simp]: "lead_coeff 1 = 1"
function a = elastix_affine_struct2matrix(tf) % ELASTIX_AFFINE_STRUCT2MATRIX Convert any type of affine transform from % elastix struct format to homogeneous coordinates matrix format. % % A = ELASTIX_AFFINE_STRUCT2MATRIX(TF) % % TF is a struct in elastix format of a 2D transform. The transform may % be of any affine type: % % 'AffineTransform' % 'SimilarityTransform' % 'EulerTransform' % 'TranslationTransform' % % It may also have an arbitrary TF.CenterOfRotationPoint, it doesn't need % to be 0. Subsequent transforms pointed at from % TF.InitialTransformParametersFileName are ignored. % % A is an affine transform matrix in homegeneous coordinates, referred to % the centre of coordinates = 0. The transform is computed as % % [y 1] = [x 1] * A % % where A = [a11 a12 0] % [a21 a22 0] % [t1 t2 1] % % [t1 t2] is the translation vector, whereas % % for a general affine transform: [a11 a12] % [a21 a22] % % for a similarity transform: [ cos(theta) sin(theta)] * s % [-sin(theta) cos(theta)] % % for a rigid transform: [ cos(theta) sin(theta)] % [-sin(theta) cos(theta)] % % for a translation transform: [1 0] % [0 1] % % If TF is a vector of structures, A is an array where each A(:, :, I) % corresponds to TP(I). % % See also: elastix_affine_matrix2struct. % Author: Ramon Casero <[email protected]> % Copyright © 2015 University of Oxford % Version: 0.2.0 % % University of Oxford means the Chancellor, Masters and Scholars of % the University of Oxford, having an administrative office at % Wellington Square, Oxford OX1 2JD, UK. % % This file is part of Gerardus. % % This program is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. The offer of this % program under the terms of the License is subject to the License % being interpreted in accordance with English Law and subject to any % action against the University of Oxford being under the jurisdiction % of the English Courts. % % You should have received a copy of the GNU General Public License % along with this program. If not, see <http://www.gnu.org/licenses/>. % check arguments narginchk(1, 1); nargoutchk(0, 1); % number of input transforms N = length(tf); % init output a = zeros(3, 3, N); % loop each transform for I = 1:N a(:, :, I) = one_struct2matrix(tf(I)); end end %% auxiliary function % one_struct2matrix: convert a single transform to matrix form function a = one_struct2matrix(tf) switch (tf.Transform) case 'AffineTransform' % transformation nomenclature a11 = tf.TransformParameters(1); a21 = tf.TransformParameters(2); a12 = tf.TransformParameters(3); a22 = tf.TransformParameters(4); t = tf.TransformParameters(5:6); % matrix block that doesn't contain the translation A = [a11 a12; a21 a22]; case 'SimilarityTransform' % transformation nomenclature s = tf.TransformParameters(1); theta = tf.TransformParameters(2); t = tf.TransformParameters(3:4); % matrix block that doesn't contain the translation A = [cos(theta) sin(theta);... -sin(theta) cos(theta)] * s; case 'EulerTransform' % transformation nomenclature theta = tf.TransformParameters(1); t = tf.TransformParameters(2:3); % matrix block that doesn't contain the translation A = [cos(theta) sin(theta);... -sin(theta) cos(theta)]; case 'TranslationTransform' % transformation nomenclature t = tf.TransformParameters(1:2); % matrix block that doesn't contain the translation A = [1 0;... 0 1]; otherwise error('Transform not implemented') end % centre of rotation c = tf.CenterOfRotationPoint; % center transform on origin t = t + c * (eye(2) - A); % create affine transform matrix a = [A [0;0]; t 1]; end
/** * @file SurfaceSample.hpp * @author Adam Wolniakowski */ #include "SurfaceSample.hpp" #include <iostream> #include <rw/rw.hpp> #include <rwsim/rwsim.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <boost/optional.hpp> #include <boost/lexical_cast.hpp> #include <boost/algorithm/string.hpp> #include "XMLHelpers.hpp" using namespace std; USE_ROBWORK_NAMESPACE; using namespace robwork; using namespace rwsim; using namespace rwsim::dynamics; using namespace boost::property_tree; using boost::algorithm::trim; using namespace rwlibs::xml; vector<SurfaceSample> SurfaceSample::loadFromXML(const std::string& filename) { vector<SurfaceSample> samples; try { PTree tree; read_xml(filename, tree); PTree root = tree.get_child("SurfaceSamples"); for (CI p = root.begin(); p != root.end(); ++p) { if (p->first == "Sample") { Q posq = XMLHelpers::readQ(p->second.get_child("Pos")); Q rpyq = XMLHelpers::readQ(p->second.get_child("RPY")); double graspW = XMLHelpers::readDouble(p->second.get_child("GraspW")); //cout << "pos=" << posq << " rot=" << rpyq << " graspW=" << graspW << endl; Vector3D<> pos(posq[0], posq[1], posq[2]); RPY<> rpy(rpyq[0], rpyq[1], rpyq[2]); samples.push_back(SurfaceSample(Transform3D<>(pos, rpy.toRotation3D()), graspW)); } } } catch (const ptree_error& e) { RW_THROW(e.what()); } return samples; } void SurfaceSample::saveToXML(const std::string& filename, const std::vector<SurfaceSample>& samples) { PTree tree; // save all the samples! for(const SurfaceSample& sample : samples) { PTree node; node.put("Pos", XMLHelpers::QToString(Q(3, sample.transform.P()[0], sample.transform.P()[1],sample.transform.P()[2]))); RPY<> rpy(sample.transform.R()); node.put("RPY", XMLHelpers::QToString(Q(3, rpy[0], rpy[1], rpy[2]))); node.put("GraspW", boost::lexical_cast<std::string>(sample.graspW)); tree.add_child("SurfaceSamples.Sample", node); } // save to XML try { boost::property_tree::xml_writer_settings<char> settings('\t', 1); write_xml(filename, tree, std::locale(), settings); } catch (const ptree_error& e) { // Convert from parse errors to RobWork errors. RW_THROW(e.what()); } }
module Issue734a where module M₁ (Z : Set₁) where postulate P : Set Q : Set → Set module M₂ (X Y : Set) where module M₁′ = M₁ Set open M₁′ p : P p = {!!} -- Previous and current agda2-goal-and-context: -- Y : Set -- X : Set -- --------- -- Goal: P q : Q X q = {!!} -- Previous and current agda2-goal-and-context: -- Y : Set -- X : Set -- ----------- -- Goal: Q X postulate X : Set pp : M₂.M₁′.P X X pp = {!!} -- Previous agda2-goal-and-context: -- ---------------- -- Goal: M₁.P Set -- Current agda2-goal-and-context: -- -------------------- -- Goal: M₂.M₁′.P X X
(** * PSet 1: Functional Programming in Coq This lab is designed as a file that you should download and complete in a Coq IDE. Before doing that, you need to install Coq. The installation instructions are on the course website. *) (* Exercise: mult2 [10 points]. Define a function that multiplies its input by 2. What is the function's type? What is the result of computing the function on 0? On 3110? *) (* Exercise: xor [10 points]. Define a function that computes the xor of two [bool] inputs. Do this by pattern matching on the inputs. What is the function's type? Compute all four possible combinations of inputs to test your function. *) (* Exercise: is_none [20 points]. Define a function that returns [true] if its input is [None], and [false] otherwise. Your function's type should be [forall A : Type, option A -> bool]. That means the function will actually need to take two inputs: the first has type [Type], and the second is an option. Hint: model your solution on [is_empty] in the notes for this lecture. *) Require Import List. Import ListNotations. (* Exercise: double_all [20 points]. There is a function [map] that was imported by the [Require Import List] command above. First, check its type with [Check map]. Explain that type in your own words. Second, print it with [Print map]. Note at the end of that which arguments are _implicit_. For a discussion of what implicit means, see the notes for this lecture. Third, use map to write your own function, which should double (i.e., multiply by 2) every value of a list. For example, [double_all [0;2;10]] should be [[0;4;20]]. *) (* Exercise: sum [20 points] Write a function that sums all the natural numbers in a list. Implement this two different ways: - as a recursive function, using the [Fixpoint] syntax. - as a nonrecursive function, using [Definition] and an application of [fold_left]. *) Inductive day : Type := | sun : day | mon : day | tue : day | wed : day | thu : day | fri : day | sat : day. Definition next_day d := match d with | sun => mon | mon => tue | tue => wed | wed => thu | thu => fri | fri => sat | sat => sun end. (* Exercise: thu after wed [20 points]. State a theorem that says [thu] is the [next_day] after [wed]. Write down in natural language how you would informally explain to a human why this theorem is true. ---> Don't skip this "natural language" part of the exercise; it's crucial to develop intuition before proceeding. Prove the theorem in Coq. *) (* Exercise: wed before thu [30 points]. Below is a theorem that says if the day after [d] is [thu], then [d] must be [wed]. Write down in natural language how you would informally explain to a human why this theorem is true. ---> Don't skip this "natural language" part of the exercise; it's crucial to develop intuition before proceeding. Prove the theorem in Coq. To do that, delete the [Abort] command, which tells Coq to discard the theorem, then fill in your own proof. *) Theorem wed_proceeds_thu : forall d : day, next_day d = thu -> d = wed. Abort. (* Exercise: tl_opt [20 points]. Define a function [tl_opt] such that [tl_opt lst] return [Some t] if [t] is the tail of [lst], or [None] if [lst] is empty. We have gotten you started by providing an obviously incorrect definition, below; you should replace the body of the function with a correct definition. *) Definition tl_opt {A : Type} (lst : list A) : option (list A) := None. (* Here is a new tactic: [rewrite x]. If [H: x = e] is an assumption in the proof state, then [rewrite H] replaces [x] with [e] in the subgoal being proved. For example, here is a proof that incrementing 1 produces 2: *) Theorem inc1_is_2 : forall n, n=1 -> (fun x => x+1) n = 2. Proof. intros n n_is_1. rewrite n_is_1. trivial. Qed. (* Exercise: tl_opt correct [20 points]. Using [rewrite], prove the following theorems. For both, first explain in natural language why the theorem should hold, before moving on to prove it with Coq. *) Theorem nil_implies_tlopt_none : forall A : Type, forall lst : list A, lst = nil -> tl_opt lst = None. Abort. Theorem cons_implies_tlopt_some : forall {A : Type} (h:A) (t : list A) (lst : list A), lst = h::t -> tl_opt lst = Some t. Abort.
Solon gets SO excited when this bed gets wheeled out of the basement backroom in its little suitcase, plugged in, turned on, air flowing into it and linens laid on top making it into a bed...this bed means Nana and Papa or Grandma and Grandpa are coming for a visit and Solon just LOVES that! He also loves to make sure it feels just right by jumping on it, laying in the pillows and leaving his lion flashlight for them just in case they need to look for the moon in the night (he believes you need a flashlight to find it :). Luckily for him, this bed is seeing lots of use lately!
||| CSS Rules for the Math Game Example module Examples.CSS.MathGame import Data.Vect import Examples.CSS.Colors import public Examples.CSS.Core import Rhone.JS import Text.CSS -------------------------------------------------------------------------------- -- IDs -------------------------------------------------------------------------------- ||| Where the message about the correct result ||| is printed to. public export out : ElemRef Div out = Id Div "mathgame_out" ||| Select box where users choose the language. public export langIn : ElemRef Select langIn = Id Select "mathgame_language" ||| Text field where users enter their result. public export resultIn : ElemRef Input resultIn = Id Input "mathgame_input" ||| Button to check the entered result public export checkBtn : ElemRef Button checkBtn = Id Button "mathgame_check_btn" ||| Button to start a new game public export newBtn : ElemRef Button newBtn = Id Button "mathgame_newbtn" ||| ID of the picture canvas public export pic : ElemRef Canvas pic = Id Canvas "mathgame_pic" ||| ID of the calculation label public export calc : ElemRef Div calc = Id Div "mathgame_calc" -------------------------------------------------------------------------------- -- CSS -------------------------------------------------------------------------------- ||| Message field class if answer is correct export correct : String correct = "correct" ||| Message field class if answer is wrong export wrong : String wrong = "wrong" export mathContent : String mathContent = "mathgame_content" export lblLang : String lblLang = "mathgame_lbllang" data Tag = LLan | ILan | OClc | IRes | BChk | ORep | BNew | OPic | Dot AreaTag Tag where showTag LLan = "LLan" showTag ILan = "ILan" showTag OClc = "OClc" showTag IRes = "IRes" showTag BChk = "BChk" showTag ORep = "ORep" showTag BNew = "BNew" showTag OPic = "OPic" showTag Dot = "." export css : List (Rule 1) css = [ Media "min-width: 300px" [ class mathContent !! [ Display .= Area (replicate 6 MinContent) [MaxContent, MaxContent] [ [LLan, ILan] , [OClc, IRes] , [Dot, BChk] , [Dot, BNew] , [ORep, ORep] , [OPic, OPic] ] , ColumnGap .= px 10 , RowGap .= px 10 , Padding .= VH (px 20) (px 10) ] ] , Media "min-width: 800px" [ class mathContent !! [ Display .= Area (replicate 6 MinContent) [MaxContent, MaxContent, fr 1] [ [LLan, ILan, OPic] , [OClc, IRes, OPic] , [Dot, BChk, OPic] , [Dot, BNew, OPic] , [ORep, ORep, OPic] , [Dot, Dot, OPic] ] , ColumnGap .= px 10 , RowGap .= px 10 , Padding .= VH (px 20) (px 10) ] ] , class lblLang !! [ GridArea .= LLan ] , idRef langIn !! [ GridArea .= ILan , FontSize .= Large , TextAlign .= End ] , idRef calc !! [ GridArea .= OClc , FontSize .= Large , TextAlign .= Start ] , idRef resultIn !! [ GridArea .= IRes , FontSize .= Large , TextAlign .= End ] , idRef checkBtn !! [ GridArea .= BChk ] , idRef newBtn !! [ GridArea .= BNew ] , idRef out !! [ GridArea .= ORep , FontSize .= Large , TextAlign .= Start ] , idRef pic !! [ BackgroundSize .= perc 100 , JustifySelf .= Center , GridArea .= OPic , MaxWidth .= px 500 , Width .= px 500 ] , class correct !! [ Color .= green ] , class wrong !! [ Color .= red ] ]
[STATEMENT] lemma bits_mod_0 [simp]: \<open>0 mod a = 0\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. (0::'a) mod a = (0::'a) [PROOF STEP] using div_mult_mod_eq [of 0 a] [PROOF STATE] proof (prove) using this: (0::'a) div a * a + (0::'a) mod a = (0::'a) goal (1 subgoal): 1. (0::'a) mod a = (0::'a) [PROOF STEP] by simp
classdef PTKAirways < PTKPlugin % PTKAirways. Plugin for segmenting the pulmonary airways from CT data % % This is a plugin for the Pulmonary Toolkit. Plugins can be run using % the gui, or through the interfaces provided by the Pulmonary Toolkit. % See PTKPlugin.m for more information on how to run plugins. % % Plugins should not be run directly from your code. % % PTKAirways calls the PTKTopOfTrachea plugin to find the trachea % location, and then runs the library routine % PTKAirwayRegionGrowingWithExplosionControl to obtain the % airway segmentation. The results are stored in a heirarchical tree % structure. % % The output image generated by GenerateImageFromResults creates a % colour-coded segmentation image with true airway points shown as blue % and explosion points shown in red. % % % Licence % ------- % Part of the TD Pulmonary Toolkit. https://github.com/tomdoel/pulmonarytoolkit % Author: Tom Doel, 2012. www.tomdoel.com % Distributed under the GNU GPL v3 licence. Please see website for details. % properties ButtonText = 'Airways' ToolTip = 'Shows a segmentation of the airways illustrating deleted points' Category = 'Airways' AllowResultsToBeCached = true AlwaysRunPlugin = false PluginType = 'ReplaceOverlay' HidePluginInDisplay = false FlattenPreviewImage = true PTKVersion = '1' ButtonWidth = 6 ButtonHeight = 2 GeneratePreview = true Version = 2 end methods (Static) function results = RunPlugin(dataset, reporting) trachea_results = dataset.GetResult('PTKTopOfTrachea'); if dataset.IsGasMRI threshold = dataset.GetResult('PTKThresholdGasMRIAirways'); coronal_mode = false; elseif strcmp(dataset.GetImageInfo.Modality, 'MR') lung_threshold = dataset.GetResult('PTKMRILungThreshold'); threshold = lung_threshold.LungMask; threshold_raw = threshold.RawImage; se = ones(1, 3, 10); threshold_raw_c = imopen(threshold_raw, se); threshold.ChangeRawImage(threshold_raw_c); coronal_mode = true; else threshold = dataset.GetResult('PTKThresholdLungInterior'); coronal_mode = false; end % We use results from the trachea finding to remove holes in the % trachea, which can otherwise cause early branching of the airway % algorithm threshold.SetIndexedVoxelsToThis(trachea_results.trachea_voxels, true); start_point = trachea_results.top_of_trachea; if PTKSoftwareInfo.FastMode maximum_number_of_generations = 10; else maximum_number_of_generations = 15; end explosion_multiplier = 4; debug_mode = PTKSoftwareInfo.GraphicalDebugMode; results = PTKAirwayRegionGrowingWithExplosionControl(threshold, start_point, maximum_number_of_generations, explosion_multiplier, coronal_mode, reporting, debug_mode); end function results = GenerateImageFromResults(airway_results, image_templates, reporting) template_image = image_templates.GetTemplateImage(PTKContext.LungROI); results = PTKGetImageFromAirwayResults(airway_results.AirwayTree, template_image, false, reporting); results_raw = results.RawImage; explosion_points = template_image.GlobalToLocalIndices(airway_results.ExplosionPoints); results_raw(explosion_points) = 3; results.ChangeRawImage(results_raw); end end end