Datasets:
AI4M
/

text
stringlengths
0
3.34M
[STATEMENT] lemma ordered_insert_binary [rewrite]: "strict_sorted (xs @ a # ys) \<Longrightarrow> ordered_insert x (xs @ a # ys) = (if x < a then ordered_insert x xs @ a # ys else if x > a then xs @ a # ordered_insert x ys else xs @ a # ys)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. strict_sorted (xs @ a # ys) \<Longrightarrow> ordered_insert x (xs @ a # ys) = (if x < a then ordered_insert x xs @ a # ys else if a < x then xs @ a # ordered_insert x ys else xs @ a # ys) [PROOF STEP] @proof [PROOF STATE] proof (prove) goal (1 subgoal): 1. strict_sorted (xs @ a # ys) \<Longrightarrow> ordered_insert x (xs @ a # ys) = (if x < a then ordered_insert x xs @ a # ys else if a < x then xs @ a # ordered_insert x ys else xs @ a # ys) [PROOF STEP] @induct xs [PROOF STATE] proof (prove) goal (1 subgoal): 1. strict_sorted (xs @ a # ys) \<Longrightarrow> ordered_insert x (xs @ a # ys) = (if x < a then ordered_insert x xs @ a # ys else if a < x then xs @ a # ordered_insert x ys else xs @ a # ys) [PROOF STEP] @qed
lemma isCont_fst [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. fst (f x)) a"
lemmas isCont_Im [simp] = bounded_linear.isCont [OF bounded_linear_Im]
{-# OPTIONS_GHC -Wall #-} {-# LANGUAGE Trustworthy #-} {- | Module : Physics.Learn.Schrodinger1D Copyright : (c) Scott N. Walck 2015-2018 License : BSD3 (see LICENSE) Maintainer : Scott N. Walck <[email protected]> Stability : experimental This module contains functions to solve the (time dependent) Schrodinger equation in one spatial dimension for a given potential function. -} module Physics.Learn.Schrodinger1D ( -- * Potentials freeV , harmonicV , squareWell , doubleWell , stepV , wall -- * Initial wavefunctions -- , harm , coherent , gaussian , movingGaussian -- * Utilities , stateVectorFromWavefunction , hamiltonianMatrix , expectX , picture , xRange , listForm ) where import Data.Complex ( Complex(..) , magnitude ) import Graphics.Gloss ( Picture(..) , yellow , black , Display(..) , display ) -- import Math.Polynomial.Hermite -- ( evalPhysHermite -- ) import Numeric.LinearAlgebra ( R , C , Vector , Matrix , (|>) , (<.>) , fromLists , toList , size ) import Physics.Learn.QuantumMat ( probVector , timeEv ) --i :: Complex Double --i = 0 :+ 1 ---------------- -- Potentials -- ---------------- -- | Free potential. -- The potential energy is zero everywhere. freeV :: Double -- ^ position -> Double -- ^ potential energy freeV _x = 0 -- | Harmonic potential. -- This is the potential energy of a linear spring. harmonicV :: Double -- ^ spring constant -> Double -- ^ position -> Double -- ^ potential energy harmonicV k x = k * x**2 / 2 -- | A double well potential. -- Potential energy is a quartic function of position -- that gives two wells, each approximately harmonic -- at the bottom of the well. doubleWell :: Double -- ^ width (for both wells and well separation) -> Double -- ^ energy height of barrier between wells -> Double -- ^ position -> Double -- ^ potential energy doubleWell a v0 x = v0 * ((x**2 - a**2)/a**2)**2 -- | Finite square well potential. -- Potential is zero inside the well, -- and constant outside the well. -- Well is centered at the origin. squareWell :: Double -- ^ well width -> Double -- ^ energy height of well -> Double -- ^ position -> Double -- ^ potential energy squareWell l v0 x | abs x < l/2 = 0 | otherwise = v0 -- | A step barrier potential. -- Potential is zero to left of origin. stepV :: Double -- ^ energy height of barrier (to the right of origin) -> Double -- ^ position -> Double -- ^ potential energy stepV v0 x | x < 0 = 0 | otherwise = v0 -- | A potential barrier with thickness and height. wall :: Double -- ^ thickness of wall -> Double -- ^ energy height of barrier -> Double -- ^ position of center of barrier -> Double -- ^ position -> Double -- ^ potential energy wall w v0 x0 x | abs (x-x0) < w/2 = v0 | otherwise = 0 --------------------------- -- Initial wavefunctions -- --------------------------- -- -- | Harmonic oscillator stationary state -- harm :: Int -- ^ nonnegative integer n identifying stationary state -- -> Double -- ^ x / sqrt(hbar/(m * omega)), i.e. position -- -- in units of sqrt(hbar/(m * omega)) -- -> C -- ^ complex amplitude -- harm n u -- = exp (-u**2/2) * evalPhysHermite n u / sqrt (2^n * fact n * sqrt pi) :+ 0 coherent :: R -- ^ length scale = sqrt(hbar / m omega) -> C -- ^ parameter z -> R -> C -- ^ wavefunction coherent l z x = ((1/(pi*l**2))**0.25 * exp(-x**2/(2*l**2)) :+ 0) * exp(-z**2/2 + (sqrt(2/l**2) * x :+ 0) * z) gaussian :: R -- ^ width parameter -> R -- ^ center of wave packet -> R -> C -- ^ wavefunction gaussian a x0 x = exp(-(x-x0)**2/(2*a**2)) / sqrt(a * sqrt pi) :+ 0 movingGaussian :: R -- ^ width parameter -> R -- ^ center of wave packet -> R -- ^ l0 = hbar / p0 -> R -> C -- ^ wavefunction movingGaussian a x0 l0 x = exp((0 :+ x/l0) - ((x-x0)**2/(2*a**2) :+ 0)) / (sqrt(a * sqrt pi) :+ 0) --------------- -- Utilities -- --------------- fact :: Int -> Double fact 0 = 1 fact n = fromIntegral n * fact (n-1) linspace :: Double -> Double -> Int -> [Double] linspace left right num = let dx = (right - left) / fromIntegral (num - 1) in [ left + dx * fromIntegral n | n <- [0..num-1]] -- | Transform a wavefunction into a state vector. stateVectorFromWavefunction :: R -- ^ lowest x -> R -- ^ highest x -> Int -- ^ dimension of state vector -> (R -> C) -- ^ wavefunction -> Vector C -- ^ state vector stateVectorFromWavefunction left right num psi = (num |>) [psi x | x <- linspace left right num] hamiltonianMatrix :: R -- ^ lowest x -> R -- ^ highest x -> Int -- ^ dimension of state vector -> R -- ^ hbar -> R -- ^ mass -> (R -> R) -- ^ potential energy function -> Matrix C -- ^ Hamiltonian Matrix hamiltonianMatrix xmin xmax num hbar m pe = let coeff = -hbar**2/(2*m) dx = (xmax - xmin) / fromIntegral (num - 1) diagKEterm = -2 * coeff / dx**2 offdiagKEterm = coeff / dx**2 xs = linspace xmin xmax num in fromLists [[case abs(i-j) of 0 -> (diagKEterm + pe x) :+ 0 1 -> offdiagKEterm :+ 0 _ -> 0 | j <- [1..num] ] | (i,x) <- zip [1..num] xs] expectX :: Vector C -- ^ state vector -> Vector R -- ^ vector of x values -> R -- ^ <X>, expectation value of X expectX psi xs = probVector psi <.> xs glossScaleX :: Int -> (Double,Double) -> Double -> Float glossScaleX screenWidth (xmin,xmax) x = let w = fromIntegral screenWidth :: Double in realToFrac $ (x - xmin) / (xmax - xmin) * w - w / 2 glossScaleY :: Int -> (Double,Double) -> Double -> Float glossScaleY screenHeight (ymin,ymax) y = let h = fromIntegral screenHeight :: Double in realToFrac $ (y - ymin) / (ymax - ymin) * h - h / 2 glossScalePoint :: (Int,Int) -- ^ (screenWidth,screenHeight) -> (Double,Double) -- ^ (xmin,xmax) -> (Double,Double) -- ^ (ymin,ymax) -> (Double,Double) -- ^ (x,y) -> (Float,Float) glossScalePoint (screenWidth,screenHeight) xMinMax yMinMax (x,y) = (glossScaleX screenWidth xMinMax x ,glossScaleY screenHeight yMinMax y) -- | Produce a gloss 'Picture' of state vector -- for 1D wavefunction. picture :: (Double, Double) -- ^ y range -> [Double] -- ^ xs -> Vector C -- ^ state vector -> Picture picture (ymin,ymax) xs psi = Color yellow (Line [glossScalePoint (screenWidth,screenHeight) (head xs, last xs) (ymin,ymax) p | p <- zip xs (map magSq $ toList psi)]) where magSq = \z -> magnitude z ** 2 screenWidth = 1000 screenHeight = 750 -- options for representing wave functions -- 1. A function R -> C -- 2. ([R],Vector C), where lengths match -- 3. [(R,C)] -- 4. (R,R,Vector C) -- xmin, xmax, state vector (assumes even spacing) -- 2,4 are best for evolution listForm :: (R,R,Vector C) -> ([R],Vector C) listForm (xmin,xmax,v) = let dt = (xmax - xmin) / fromIntegral (size v - 1) in ([xmin, xmin + dt .. xmax],v) {- -- | Given an initial state vector and -- state propagation function, produce a simulation. -- The 'Float' in the state propagation function is the time -- interval for one timestep. simulate1D :: [Double] -> Vector C -> (Float -> (Float,[Double],Vector C) -> (Float,[Double],Vector C)) -> IO () simulate1D xs initial statePropFunc = simulate display black 10 (0,initial) displayFunc (const statePropFunc) where display = InWindow "Animation" (screenWidth,screenHeight) (10,10) displayFunc (_t,v) = Color yellow (Line [( white (\tFloat -> Pictures [Color blue (Line (points (realToFrac tFloat))) ,axes (screenWidth,screenHeight) (xmin,xmax) (ymin,ymax)]) -- | Produce a state propagation function from a time-dependent Hamiltonian. -- The float is dt. statePropGloss :: (Double -> Matrix C) -> Float -> (Float,Vector C) -> (Float,Vector C) statePropGloss ham dt (tOld,v) = (tNew, timeEv (realToFrac dt) (ham tMid) v) where tNew = tOld + dt tMid = realToFrac $ (tNew + tOld) / 2 -- | Given an initial state vector and a time-dependent Hamiltonian, -- produce a visualization of a 1D wavefunction. evolutionBlochSphere :: Vector C -> (Double -> Matrix C) -> IO () evolutionBlochSphere psi0 ham = simulateBlochSphere 0.01 psi0 (stateProp ham) -} {- def triDiagMatrixMult(square_arr,arr): num = len(arr) result = array([0 for n in range(num)],dtype=complex128) result[0] = square_arr[0][0] * arr[0] + square_arr[0][1] * arr[1] for n in range(1,num-1): result[n] = square_arr[n][n-1] * arr[n-1] + square_arr[n][n] * arr[n] \ + square_arr[n][n+1] * arr[n+1] result[num-1] = square_arr[num-1][num-2] * arr[num-2] \ + square_arr[num-1][num-1] * arr[num-1] return result -} ------------------ -- Main program -- ------------------ -- n is number of points -- n-1 is number of intervals xRange :: R -> R -> Int -> [R] xRange xmin xmax n = let dt = (xmax - xmin) / fromIntegral (n - 1) in [xmin, xmin + dt .. xmax] {- if __name__ == '__main__': m = 1 omega = 10 xmin = -2.0 xmax = 2.0 num = 256 num = 128 dt = 0.0002 dt = 0.01 xs = linspace(xmin,xmax,num) dx = xs[1] - xs[0] super = lambda x: (harm0(m,omega)(x) + harm1(m,omega)(x))/sqrt(2) shiftedHarm = lambda x: harm0(m,omega)(x-1) coh = coherent(m,omega,1) print sum(conj(psi)*psi)*dx harmV = harmonicV(m * omega**2) V = doubleWell(1,0.1*hbar*omega) V = squareWell(1.0,hbar*omega) V = harmonicV(m*omega**2) V = stepV(10*hbar*omega) V = wall(0.1,14.0*hbar*omega,0) V = freeV H = matrixH(m,xmin,xmax,num,V) I = matrixI(num) (vals,vecs) = eigh(H) E0 = vals[0] E1 = vals[1] psi0 = normalize(transpose(vecs)[0],dx) psi1 = normalize(transpose(vecs)[1],dx) psi = func2psi(gaussian(0.3,1),xmin,xmax,num) psi = func2psi(coh,xmin,xmax,num) psi = func2psi(movingGaussian(0.3,10,-1),xmin,xmax,num) psi = psi0 psi = psi1 psi = (psi0 + psi1)/sqrt(2) E = sum(conj(psi)*triDiagMatrixMult(H,psi)).real*dx Escale = hbar*omega print E print Escale leftM = I + 0.5 * i * H / hbar * dt rightM = I - 0.5 * i * H / hbar * dt box = display(title='Schrodinger Equation',width=1000,height=1000) c = curve(pos = psi2rho(psi,xs)) c.color = color.blue c.radius = 0.02 ball = sphere(radius=0.05,color=color.red,pos=(expectX(psi,xs),0,0)) pot_curve = [(x,V(x)/Escale,0) for x in xs if V(x)/Escale < xmax] pot = curve(color=color.green,pos=pot_curve,radius=0.01) Eline = curve(color=(1,1,0),pos=[(x,E/Escale) for x in xs]) axis = curve(color=color.white,pos=[(x,0) for x in xs]) while 1: psi = solve(leftM,triDiagMatrixMult(rightM,psi)) c.pos = psi2rho(psi,xs) ball.x = expectX(psi,xs) To Do: add combinators for potentials to shift horizontally and vertically, and to add potentials -} -- Are we committed to SI units for hbar? No. -- harmonic oscillator functions depend only on sqrt(hbar/m omega) -- which is a length parameter -- for moving gaussian, could give hbar/p0 instead of p0 -- (is that debrogie wavelength? I think it's h/p0)
Formal statement is: lemma continuous_on_closed_Union: assumes "finite I" "\<And>i. i \<in> I \<Longrightarrow> closed (U i)" "\<And>i. i \<in> I \<Longrightarrow> continuous_on (U i) f" shows "continuous_on (\<Union> i \<in> I. U i) f" Informal statement is: If $f$ is continuous on each closed set $U_i$ in a finite collection of closed sets, then $f$ is continuous on the union of the $U_i$.
*----------------------------------------------------------------------* subroutine get_spprjmap_blk(strmap, & nblk,iocc,lstr,igrph,idxms,igam, & strmap_info,nsym,ngraph) *----------------------------------------------------------------------* * obtain spin-projection string-map from buffer * call strmap_man_spprj before to make sure that it exists *----------------------------------------------------------------------* implicit none include 'opdim.h' include 'stdunit.h' include 'hpvxseq.h' include 'def_filinf.h' include 'def_strmapinf.h' integer, intent(out), target :: & strmap(*) integer, intent(in) :: & nblk, & iocc(nblk), lstr(nblk), igrph(nblk), idxms(nblk), & igam(nblk), nsym, ngraph type(strmapinf), intent(in), target :: & strmap_info type(flpmap_offsets), pointer :: & offsets(:) integer, pointer :: & curmap(:) integer :: & ioffmap, hpvx_idx, hpvx, idx, idxmap, idx_minf, idxbuf, & idxgraph, ioff, ilen, iblk if (strmap_info%mxgraph.lt.ngraph) & call quit(1,'get_spprjmap_blk', & 'you forgot to update the maps after adding a graph') offsets => strmap_info%offsets_spprj ioffmap = 0 do iblk = 1, nblk if (iocc(iblk).gt.1) then c dbg c print *,'iblk = ',iblk c print *,'fetching G,MS/G: ',igrph(iblk),idxms(iblk),igam(iblk) c dbg idxgraph = igrph(iblk) idxmap = igam(iblk) ! offset of string map (actually stored for ms, just in ! case we need more maps, not only those starting from the ! canonical sceleton part of the ME list) ioff = offsets(idxgraph)%ms(idxms(iblk)) c dbg c print *,'idxgraph = ',idxgraph c print *,'ioff0: ',ioff c dbg ! plus offset of current gm block ioff = ioff + offsets(idxgraph)%msgm(idxmap) c dbg c print *,'idxgraph,idxmap: ',idxgraph,idxmap c print *,'idxmap,ioff1: ',idxmap,offsets(idxgraph)%msgm(idxmap) c dbg ilen = lstr(iblk)*(2**iocc(iblk)-1) c dbg c print *,'ilen = ',ilen c print *,'fetching from: ',ioff+1, c & ioff+ilen c print *,'fetching map: ',ioffmap+1,ioffmap+ilen c dbg c dbg c print *,'call to mem_iget in get_flipmap_blk ',ioff,ilen c dbg call mem_iget(strmap_info%ffstrmap, & strmap(ioffmap+1),ioff+1,ioff+ilen) c dbg c print '(x,5i6,2x,5i6)',strmap(ioffmap+1:ioffmap+ilen) c dbg ioffmap = ioffmap+ilen else ! set trivial map ilen = lstr(iblk) c dbg c print *,'setting trivial map of length : ',ilen c print *,'settig map: ',ioffmap+1,ioffmap+ilen c dbg curmap => strmap(ioffmap+1:ioffmap+ilen) do idx = 1, ilen curmap(idx) = idx end do ioffmap = ioffmap+ilen end if end do c dbg c print *,'total len of map: ',ioffmap c dbg return end
= = Geology = =
lemmas tendsto_Re [tendsto_intros] = bounded_linear.tendsto [OF bounded_linear_Re]
In 2007 , as the second @-@ string quarterback , he saw his first action against Villanova when he was substituted for injured starter Jordan Steffy . Turner executed a scoring drive and completed four of six passes , but also threw two interceptions . He sat out the next two games and then took one snap against Wake Forest . When the unranked Terps faced 10th @-@ ranked Rutgers , Steffy suffered a concussion and Turner again filled in . He led drives for two touchdowns and two field goals in an upset of the Scarlet Knights , 34 – 24 . About the then relatively unknown Turner , Rutgers head coach Greg <unk> said , " I wish I would have seen this guy before . " Turner started for the remaining eight games of the season . In his career @-@ first start , he passed for 255 yards in a win against Georgia Tech , 28 – 26 . In the game , he threw a 78 @-@ yard touchdown pass , which was caught by tight end Jason Goode rather than his intended receiver , Darrius Heyward @-@ Bey . After a three @-@ game losing streak , Turner led another upset win over a top @-@ ten team , this time against eighth @-@ ranked Boston College , 42 – 35 . In the 24 – 16 loss to Florida State , Turner had his worst performance of the season . Late in the second quarter , he was benched and replaced by Steffy for two possessions . Turner said , " I didn 't know that my leash was that short in the first place , to be honest . I didn 't think it would come to this . I guess I should have . " After an uneven performance by Steffy , Turner played the entire second half and showed improvement . The following week Maryland played their regular season finale against NC State and both teams needed an additional win to attain bowl eligibility . Maryland led in the second quarter , 3 – 0 , but was struggling offensively . Turner , a generally immobile pocket quarterback , invigorated the offense when he executed a 41 @-@ yard option run for a first down . He completed 19 of 24 passes for 206 yards and led a shutout of NC State , 37 – 0 . With the sixth win , Maryland was invited to the Emerald Bowl , where they were beaten by Oregon State , 21 – 14 . Turner finished the season as the third @-@ most efficient passer in the Atlantic Coast Conference ( ACC ) .
[STATEMENT] lemma ii_nz [simp]: "quat_ii \<noteq> 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<i> \<noteq> 0 [PROOF STEP] using quat_ii.simps(2) [PROOF STATE] proof (prove) using this: Im1 \<i> = 1 goal (1 subgoal): 1. \<i> \<noteq> 0 [PROOF STEP] by fastforce
(* Title: HOL/Auth/n_mutualEx.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) theory n_mutualEx imports n_mutualEx_lemma_invs_on_rules n_mutualEx_on_inis begin lemma main: assumes a1: "s \<in> reachableSet {andList (allInitSpecs N)} (rules N)" and a2: "0 < N" shows "\<forall> f. f \<in> (invariants N) --> formEval f s" proof (rule consistentLemma) show "consistent (invariants N) {andList (allInitSpecs N)} (rules N)" proof (cut_tac a1, unfold consistent_def, rule conjI) show "\<forall> f ini s. f \<in> (invariants N) --> ini \<in> {andList (allInitSpecs N)} --> formEval ini s --> formEval f s" proof ((rule allI)+, (rule impI)+) fix f ini s assume b1: "f \<in> (invariants N)" and b2: "ini \<in> {andList (allInitSpecs N)}" and b3: "formEval ini s" have b4: "formEval (andList (allInitSpecs N)) s" apply (cut_tac b2 b3, simp) done show "formEval f s" apply (rule on_inis, cut_tac b1, assumption, cut_tac b2, assumption, cut_tac b3, assumption) done qed next show "\<forall> f r s. f \<in> invariants N --> r \<in> rules N --> invHoldForRule s f r (invariants N)" proof ((rule allI)+, (rule impI)+) fix f r s assume b1: "f \<in> invariants N" and b2: "r \<in> rules N" show "invHoldForRule s f r (invariants N)" apply (rule invs_on_rules, cut_tac b1, assumption, cut_tac b2, assumption) done qed qed next show "s \<in> reachableSet {andList (allInitSpecs N)} (rules N)" apply (metis a1) done qed end
State Before: a : ℕ a1 : 1 < a ⊢ az a * az a - ↑(Pell.d a1) * 1 * 1 = 1 State After: no goals Tactic: simp [dz_val]
## Numeric vs symbolic computing ```python 1.01 - 1 ``` 0.010000000000000009 Floating point numbers have limited accuracy (53 bits for double precision IEEE 754) ```python import math math.log10(2**53) ``` 15.954589770191003 That is, about 15 decimal places. Additionally, decimal numbers don't have exact representation in binary in general. In some cases, it may lead to accumulation of errors (numerically unstable algorithms) ```python x = 1 for i in range(10): x = (1.01-x)*100 print(x) ``` 1.0000000000000009 0.9999999999999121 1.0000000000087939 0.9999999991206154 1.0000000879384574 0.9999912061542604 1.0008793845739605 0.912061542603948 9.7938457396052 -878.38457396052 ## SymPy as a calculator Symbolic computing uses exact mathematical rules. Numbers in sympy are represented by objects of type Integer, Rational, and Float and they have overloaded mathematical operators ```python from sympy import * ``` ```python Rational(101, 100)-Integer(1) ``` 1/100 ```python sympify("101/100-1") ``` 1/100 ```python nsimplify("1.01") - 1 ``` 1/100 ```python x = Integer(1) for i in range(10): x = (Rational(101, 100)-x)*100 print(x) ``` 1 1 1 1 1 1 1 1 1 1 Sympy has some predefined mathematical constants ```python E*I - pi ``` -pi + E*I and many functions... ```python cos(0) ``` 1 ```python sin(pi/3) ``` sqrt(3)/2 and you can evaluate the expressions numerically with function N() or method .evalf() with arbirtary precision (based on mpmath) ```python N(pi+E*I, 30) ``` 3.14159265358979323846264338328 + 2.71828182845904523536028747135*I ```python sqrt(2).evalf(1000) ``` 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572735013846230912297024924836055850737212644121497099935831413222665927505592755799950501152782060571470109559971605970274534596862014728517418640889198609552329230484308714321450839762603627995251407989687253396546331808829640620615258352395054745750287759961729835575220337531857011354374603408498847160386899970699004815030544027790316454247823068492936918621580578463111596668713013015618568987237235288509264861249497715421833420428568606014682472077143585487415565706967765372022648544701585880162075847492265722600208558446652145839889394437092659180031138824646815708263010059485870400318648034219489727829064104507263688131373985525611732204024509122770022694112757362728049573810896750401836986836845072579936472906076299694138047565482372899718032680247442062926912485905218100445984215059112024944134172853147810580360337107730918286931471017111168391658172688941975871658215212822951848847 ## Symbolic computing Symbols are python objects ```python x, y, z = symbols("x, y, z") alpha, beta, delta = symbols('alpha, beta, delta') ``` symbolic expressions are created using standard python syntax ```python expr = x**y + sqrt(alpha)/2 expr ``` sqrt(alpha)/2 + x**y SymPy can print expressions in various forms, including $\LaTeX$, unicode pretty printing, and others. The pretty printing is enabled with `init_printing()` ```python init_printing() ``` ```python expr ``` Lists of symbols can be created with the following notation ```python symbols("x0:10") ``` ### Basic manipulation with the expressions #### Polynomials and rational functions ```python (x+y)**10 ``` Polynomials can be expanded ```python expand(_) ``` and, more importantly, factorized ```python factor(_) ``` ```python _.subs(x+y, z) ``` We can collect the terms with the same power of a given variable ```python collect(y*x**2 + 3*x**2 - x*y + x - 1, x) ``` Cancel rational functions ```python cancel((x**2 + 2*x + 1)/(x**2 - 1)) ``` or decompose them into partial fractions ```python apart((x**3 + 4*x - 1)/(x**2 - 1)) ``` #### Trigonometric functions ```python sin(x+y) ``` ```python expand(_, trig=True) ``` ```python trigsimp(_) ``` ```python trigsimp(sin(x)**2 + cos(x)**2) ``` #### Exponentiation ```python x**alpha * y**alpha ``` ```python powsimp(_) ``` Note that symbols in SymPy are complex by default. However, $x^\alpha y^\alpha$ does not equal $(xy)^\alpha$ in general. For example $\sqrt{-1}\sqrt{-1} \neq \sqrt{-1\cdot-1}$. It is valid for $x, y \ge 0$ and $\alpha\in\mathbb R$ and we have to define the symbols as such. Similarly $(x^a)^b = x^{ab}$ holds only for $b\in\mathbb Z$ ```python x_pos, y_pos = symbols("x_pos, y_pos", positive=True) alpha_R = symbols("alpha_R", real=True) beta_Z = symbols("beta_Z", integer=True) ``` ```python powsimp(x_pos**alpha_R * y_pos**alpha_R) ``` ```python (expand_power_base(_)) ``` ```python (z**delta)**beta_Z ``` ```python log(x_pos**alpha_R * y_pos) ``` ```python expand_log(_) ``` ```python logcombine(_) ``` The need for assumptions can be avoided using `force=True` (not recommended :) ```python expand_log(log(x**alpha * y)) ``` ```python expand_log(log(x**alpha * y), force=True) ``` #### Rewriting functions ```python tan(x).rewrite(sin) ``` Note that there are many special functions defined in SymPy... ```python factorial(x).rewrite(gamma) ``` ```python k, m, n = symbols('k, m, n') binomial(k, n).rewrite(factorial) ``` ```python binomial(k, k-2) ``` ```python combsimp(_) ``` #### Equation solving Equations are defined using `Eq`. Note that `=` is assignment and `==` tests for exact identity of two expressions ```python Eq(x**2, 1) ``` `solveset` attempts to find all solutions of the given equation. If it fails, you may try to use `solve`... ```python solveset(_, x) ``` ```python solveset(sin(x), x) ``` ```python solveset(x**2+1, x) ``` ```python solveset(x**2+1, x, domain=S.Reals) ``` ```python solveset(exp(x)-1, x) ``` ```python solveset(exp(x) > 1, x, domain=S.Reals) ``` ```python linsolve([x + y + z - 1, x + y + 2*z - 3 ], (x, y, z)) ``` ```python nonlinsolve([x**2 + 1, y**2 + 1], [x, y]) ``` ## Sympy internals Expressions are represented as trees. This can be seen by printing with srepr ```python x*y ``` ```python srepr(x*y) ``` "Mul(Symbol('x'), Symbol('y'))" ```python from IPython.display import Image def show_tree(expr): with open("xy.dot", "w") as f: f.write(dotprint(expr)) !dot xy.dot -Tpng > xy.png return Image(filename='xy.png') ``` ```python show_tree(x*y) ``` ```python expr = sin(x)/y+1-x show_tree(expr) ``` ```python expr.func ``` sympy.core.add.Add ```python expr.args ``` ```python expr.args[1].func ``` sympy.core.mul.Mul ```python expr.args[1].args ```
theory simple_stuffs imports Main "/Volumes/Setup/Isabelle/Isabelle-Code/Jan21-Isab/trinhlibs" begin (*BIP*) value "\<exists>bet \<in> set t_betaSet_1.((\<forall>j \<in> set t_SyncInstance_1. \<forall>u \<in> set j. \<exists>t \<in> set u.\<forall>l \<in> set (snd t).(\<not>P (fst t) l)) \<and> ((\<forall>elm \<in> set bet.\<forall>el1 \<in> set elm.\<forall>h \<in> set (lookup_3 (fst el1) t_TrigInstance_1) - {snd el1}. \<not>Q (fst el1) h)))" lemma test_eq: "\<exists>bet \<in> set t_betaSet_1.((\<forall>j \<in> set t_SyncInstance_1. \<forall>u \<in> set j. \<exists>t \<in> set u.\<forall>l \<in> set (snd t).(\<not>P (fst t) l)) \<and> ((\<forall>elm \<in> set bet.\<forall>el1 \<in> set elm.\<forall>h \<in> set (lookup_3 (fst el1) t_TrigInstance_1) - {snd el1}. \<not>Q (fst el1) h))) \<Longrightarrow> ((\<forall>j \<in> set t_SyncInstance_1. \<forall>u \<in> set j. \<exists>t \<in> set u.\<forall>l \<in> set (snd t).(\<not>P (fst t) l)) \<and> (\<exists>bet \<in> set t_betaSet_1.(\<forall>elm \<in> set bet.\<forall>el1 \<in> set elm.\<forall>h \<in> set (lookup_3 (fst el1) t_TrigInstance_1) - {snd el1}. \<not>Q (fst el1) h)))" by simp value t_betaSet_1 value "(\<exists>bet \<in> set t_betaSet_1. \<forall>elm \<in> set bet. \<forall>el1 \<in> set elm. \<forall>h \<in> set (lookup_3 (fst el1) t_TrigInstance_1) - {snd el1}. \<not>Q (fst el1) h)" (*JavaBIP*) value "(\<forall>i \<in> set t_TrigInstance_1. \<forall>v \<in> set i. \<forall>k \<in> set v. \<exists>h \<in> set (snd k). \<forall>h1 \<in> set (snd k) - {h}. \<not> Q (fst k) h1)" lemma test_eq_2: "(\<exists>bet \<in> set t_betaSet_1.\<forall>elm \<in> set bet.\<forall>el1 \<in> set elm.\<forall>h \<in> set (lookup_3 (fst el1) t_TrigInstance_1) - {snd el1}. \<not>Q (fst el1) h) \<Longrightarrow>(\<forall>i \<in> set t_TrigInstance_1. \<forall>v \<in> set i. \<forall>k \<in> set v. \<exists>h \<in> set (snd k).\<forall>h1 \<in> set (snd k) - {h}. \<not> Q (fst k) h1) " unfolding t_betaSet_1_def t_SyncInstance_1_def t_TrigInstance_1_def sledgehammer end
Wigwam's Trail Trax Pro is our choice for trail running or “fast and light” summer mountain trips. These socks give your feet insulated, moisture-wicking protection when you want to take your runs off-road. A little bit of care can keep your Wigwam socks performing well for years. For best results turn socks inside out before washing. Wash in warm water and tumble dry on low heat. Wigwam Trail Trax Pro Sock has a rating of stars based on reviews.
Welcome to Coq 8.4pl4 (November 2015) Coq < Definition andb (b1:bool) (b2:bool) : bool := match b1 with | true => b2 | false => false end. andb is defined Coq < Theorem andb_commutative : forall b c, andb b c = andb c b. 1 subgoal ============================ forall b c : bool, andb b c = andb c b andb_commutative < Proof. 1 subgoal ============================ forall b c : bool, andb b c = andb c b andb_commutative < info_auto. (* info auto : *) idtac. 1 subgoal ============================ forall b c : bool, andb b c = andb c b andb_commutative < intros b c. 1 subgoal b : bool c : bool ============================ andb b c = andb c b andb_commutative < destruct b. 2 subgoals c : bool ============================ andb true c = andb c true subgoal 2 is: andb false c = andb c false andb_commutative < destruct c. 3 subgoals ============================ andb true true = andb true true subgoal 2 is: andb true false = andb false true subgoal 3 is: andb false c = andb c false andb_commutative < info_auto. (* info auto : *) apply @eq_refl. 2 subgoals ============================ andb true false = andb false true subgoal 2 is: andb false c = andb c false andb_commutative < reflexivity. 1 subgoal c : bool ============================ andb false c = andb c false andb_commutative < destruct c. 2 subgoals ============================ andb false true = andb true false subgoal 2 is: andb false false = andb false false andb_commutative < reflexivity. 1 subgoal ============================ andb false false = andb false false andb_commutative < reflexivity. No more subgoals. andb_commutative < Qed. info_auto. intros b c. destruct b. destruct c. info_auto. reflexivity. destruct c. reflexivity. reflexivity. andb_commutative is defined Coq <
[STATEMENT] lemma wcode_goon_right_moving_2_Oc_move[simp]: "wcode_on_right_moving_2 ires rs (b, Oc # list) \<Longrightarrow> wcode_goon_right_moving_2 ires rs (Oc # b, list)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. wcode_on_right_moving_2 ires rs (b, Oc # list) \<Longrightarrow> wcode_goon_right_moving_2 ires rs (Oc # b, list) [PROOF STEP] apply(auto simp: wcode_fourtimes_invs) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>ml rn. \<lbrakk>b = Bk \<up> ml @ Oc # ires; Suc 0 < ml; list = Oc \<up> rs @ Bk \<up> rn\<rbrakk> \<Longrightarrow> \<exists>mla. (\<exists>ln. Oc # Bk \<up> ml = Oc \<up> mla @ Bk # Bk # Bk \<up> ln) \<and> (\<exists>mr. (\<exists>rna. Oc \<up> rs @ Bk \<up> rn = Oc \<up> mr @ Bk \<up> rna) \<and> mla + mr = Suc rs) [PROOF STEP] apply(rule_tac x = "Suc 0" in exI, auto) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>ml rn. \<lbrakk>b = Bk \<up> ml @ Oc # ires; Suc 0 < ml; list = Oc \<up> rs @ Bk \<up> rn\<rbrakk> \<Longrightarrow> \<exists>ln. Bk \<up> ml = Bk # Bk # Bk \<up> ln [PROOF STEP] apply(rule_tac x = "ml - 2" in exI) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>ml rn. \<lbrakk>b = Bk \<up> ml @ Oc # ires; Suc 0 < ml; list = Oc \<up> rs @ Bk \<up> rn\<rbrakk> \<Longrightarrow> Bk \<up> ml = Bk # Bk # Bk \<up> (ml - 2) [PROOF STEP] apply(case_tac ml, simp, case_tac "ml - 1", simp_all) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
[STATEMENT] lemma af_G_letter_sat_core: "Only_G \<G> \<Longrightarrow> \<G> \<Turnstile>\<^sub>P \<phi> \<Longrightarrow> \<G> \<Turnstile>\<^sub>P af_G_letter \<phi> \<nu>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>Only_G \<G>; \<G> \<Turnstile>\<^sub>P \<phi>\<rbrakk> \<Longrightarrow> \<G> \<Turnstile>\<^sub>P af_G_letter \<phi> \<nu> [PROOF STEP] by (induction \<phi>) (simp_all, blast+)
mutable struct WeightMatrix seed::Int64 log_prices::Array{Float64,1} block_size::Int64 num_bootstap::Int64 end function block_bootstrap_index(block_ind, n, b) rand_blocks = sample(block_ind, floor(Int,n/b)) sample_ind = transpose(repeat(rand_blocks, 1, b)) sample_ind = sample_ind[:] addition_vec = repeat(0:b-1,floor(Int,n/b)) sample_ind = sample_ind + addition_vec return sample_ind end function block_bootstrap_estimator(wm::WeightMatrix) # Step 1: Apply a Moving Block Bootstrap to the Measured Series Random.seed!(wm.seed) n = size(wm.log_prices, 1) block_ind = 1:n-wm.block_size+1 # b_samples = [log_prices[block_bootstrap_index(block_ind, n, b)] for i in 1:num_bootstap] b_samples = Array{Float64,2}(undef, n, wm.num_bootstap) for i in 1:wm.num_bootstap b_samples[:,i] = wm.log_prices[block_bootstrap_index(block_ind, n, wm.block_size)] end # Step 2: Calculate Distributions for Each Moment and Test Statistic dist = get_summary_stats(b_samples, wm.log_prices) W = inv(cov(dist)) return W end function(wm::WeightMatrix)(algo) return algo(wm) end function select_moments(log_prices) mean_log = mean(log_prices) std_log = std(log_prices) kurt_log = normal_kurtosis(log_prices) ks_stat = 0.0 hurst_log = generalized_hurts_exp(log_prices) return [mean_log, std_log, kurt_log, ks_stat, hurst_log] end # function identity_estimator(moments, simulated_moments) # return Matrix{Float64}(I, size(moments,1), size(moments,1)) # end # # function two_step_cov_estimator(moments, simulated_moments) # weight_matrix_1 = identity_estimator(moments, simulated_moments) # smm_estimated_parameters = # moment_error = # Ω = 1/N * (moment_error * moment_error') # weight_matrix_2 = inv(Ω) # return weight_matrix_2 # end # # function iterated_var_cov_estimator(moments, simulated_moments) # # end # # function newey_west_consistent_estimator(moments, simulated_moments) # # end
lemma subsequence_diagonalization_lemma: fixes P :: "nat \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> bool" assumes sub: "\<And>i r. \<exists>k. strict_mono (k :: nat \<Rightarrow> nat) \<and> P i (r \<circ> k)" and P_P: "\<And>i r::nat \<Rightarrow> 'a. \<And>k1 k2 N. \<lbrakk>P i (r \<circ> k1); \<And>j. N \<le> j \<Longrightarrow> \<exists>j'. j \<le> j' \<and> k2 j = k1 j'\<rbrakk> \<Longrightarrow> P i (r \<circ> k2)" obtains k where "strict_mono (k :: nat \<Rightarrow> nat)" "\<And>i. P i (r \<circ> k)"
!* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. !* See https://llvm.org/LICENSE.txt for license information. !* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception subroutine slave_bar_checkin(pbar, nthreads) INTEGER, INTENT(INOUT) :: pbar INTEGER, INTENT(IN) :: nthreads INTEGER :: bar !$omp atomic pbar = pbar + 1 !$omp end atomic DO !$omp atomic read bar = pbar !$omp end atomic IF (bar .ge. nthreads) then EXIT end if ENDDO end subroutine integer pbar pbar=0 !$omp parallel call slave_bar_checkin(pbar,4) !$omp end parallel print *, "PASS" end
/- Copyright (c) 2021 Henry Swanson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Henry Swanson, Patrick Massot -/ import analysis.special_functions.exponential import combinatorics.derangements.finite import order.filter.basic /-! # Derangement exponential series This file proves that the probability of a permutation on n elements being a derangement is 1/e. The specific lemma is `num_derangements_tendsto_inv_e`. -/ open filter open_locale big_operators open_locale topological_space theorem num_derangements_tendsto_inv_e : tendsto (λ n, (num_derangements n : ℝ) / n.factorial) at_top (𝓝 (real.exp (-1))) := begin -- we show that d(n)/n! is the partial sum of exp(-1), but offset by 1. -- this isn't entirely obvious, since we have to ensure that asc_factorial and -- factorial interact in the right way, e.g., that k ≤ n always let s : ℕ → ℝ := λ n, ∑ k in finset.range n, (-1 : ℝ)^k / k.factorial, suffices : ∀ n : ℕ, (num_derangements n : ℝ) / n.factorial = s(n+1), { simp_rw this, -- shift the function by 1, and then use the fact that the partial sums -- converge to the infinite sum rw tendsto_add_at_top_iff_nat 1, apply has_sum.tendsto_sum_nat, -- there's no specific lemma for ℝ that ∑ x^k/k! sums to exp(x), but it's -- true in more general fields, so use that lemma rw real.exp_eq_exp_ℝ, exact exp_series_div_has_sum_exp ℝ (-1 : ℝ) }, intro n, rw [← int.cast_coe_nat, num_derangements_sum], push_cast, rw finset.sum_div, -- get down to individual terms refine finset.sum_congr (refl _) _, intros k hk, have h_le : k ≤ n := finset.mem_range_succ_iff.mp hk, rw [nat.asc_factorial_eq_div, add_tsub_cancel_of_le h_le], push_cast [nat.factorial_dvd_factorial h_le], field_simp [nat.factorial_ne_zero], ring, end
variable x : int example : x=x := begin trivial end #check 2 #check x #check (2:int) #check int #check Type #check Type 1 #check 2 #check ℕ #check Type #check Type 1 #check Type 2 #check Type 3
[STATEMENT] lemma improve_lottery: assumes "\<not>SD_efficient R q" defines "r \<equiv> improve_lottery q" shows "r \<in> lotteries_on alts" "r \<succ>[Pareto(SD\<circ>R)] q" "\<And>r'. r' \<in> lotteries_on alts \<Longrightarrow> r' \<succ>[Pareto(SD\<circ>R)] q \<Longrightarrow> \<not>(set_pmf r' \<subset> set_pmf r)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. r \<in> lotteries_on alts &&& q \<prec>[Pareto (SD \<circ> R)] r &&& (\<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r) [PROOF STEP] proof - [PROOF STATE] proof (state) goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] define A where "A = {r\<in>lotteries_on alts. r \<succ>[Pareto(SD\<circ>R)] q}" [PROOF STATE] proof (state) this: A = {r \<in> lotteries_on alts. q \<prec>[Pareto (SD \<circ> R)] r} goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] have subset_alts: "X \<subseteq> alts" if "X \<in> set_pmf`A" for X [PROOF STATE] proof (prove) goal (1 subgoal): 1. X \<subseteq> alts [PROOF STEP] using that [PROOF STATE] proof (prove) using this: X \<in> set_pmf ` A goal (1 subgoal): 1. X \<subseteq> alts [PROOF STEP] by (auto simp: A_def lotteries_on_def) [PROOF STATE] proof (state) this: ?X \<in> set_pmf ` A \<Longrightarrow> ?X \<subseteq> alts goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] have r_altdef: "r = (SOME r. r \<in> A \<and> \<not>(\<exists>r'\<in>A. set_pmf r' \<subset> set_pmf r))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. r = (SOME r. r \<in> A \<and> \<not> (\<exists>r'\<in>A. set_pmf r' \<subset> set_pmf r)) [PROOF STEP] unfolding r_def improve_lottery_def Let_def A_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. (SOME r. r \<in> {r \<in> lotteries_on alts. q \<prec>[Pareto (SD \<circ> R)] r} \<and> \<not> (\<exists>r'\<in>{r \<in> lotteries_on alts. q \<prec>[Pareto (SD \<circ> R)] r}. set_pmf r' \<subset> set_pmf r)) = (SOME r. r \<in> {r \<in> lotteries_on alts. q \<prec>[Pareto (SD \<circ> R)] r} \<and> \<not> (\<exists>r'\<in>{r \<in> lotteries_on alts. q \<prec>[Pareto (SD \<circ> R)] r}. set_pmf r' \<subset> set_pmf r)) [PROOF STEP] by simp [PROOF STATE] proof (state) this: r = (SOME r. r \<in> A \<and> \<not> (\<exists>r'\<in>A. set_pmf r' \<subset> set_pmf r)) goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] from assms [PROOF STATE] proof (chain) picking this: \<not> SD_efficient R q r \<equiv> improve_lottery q [PROOF STEP] have nonempty: "A \<noteq> {}" [PROOF STATE] proof (prove) using this: \<not> SD_efficient R q r \<equiv> improve_lottery q goal (1 subgoal): 1. A \<noteq> {} [PROOF STEP] by (auto simp: A_def SD_efficient_def) [PROOF STATE] proof (state) this: A \<noteq> {} goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] hence nonempty': "set_pmf`A \<noteq> {}" [PROOF STATE] proof (prove) using this: A \<noteq> {} goal (1 subgoal): 1. set_pmf ` A \<noteq> {} [PROOF STEP] by simp [PROOF STATE] proof (state) this: set_pmf ` A \<noteq> {} goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] have "set_pmf ` A \<subseteq> Pow alts" [PROOF STATE] proof (prove) goal (1 subgoal): 1. set_pmf ` A \<subseteq> Pow alts [PROOF STEP] by (auto simp: A_def lotteries_on_def) [PROOF STATE] proof (state) this: set_pmf ` A \<subseteq> Pow alts goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] from finite_alts [PROOF STATE] proof (chain) picking this: finite alts [PROOF STEP] have wf: "wf {(X,Y). X \<subset> Y \<and> Y \<subseteq> alts}" [PROOF STATE] proof (prove) using this: finite alts goal (1 subgoal): 1. wf {(X, Y). X \<subset> Y \<and> Y \<subseteq> alts} [PROOF STEP] by (rule finite_subset_wf) [PROOF STATE] proof (state) this: wf {(X, Y). X \<subset> Y \<and> Y \<subseteq> alts} goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] obtain X where "X \<in> set_pmf`A" "\<And>Y. Y \<subset> X \<and> X \<subseteq> alts \<Longrightarrow> Y \<notin> set_pmf ` A" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<And>X. \<lbrakk>X \<in> set_pmf ` A; \<And>Y. Y \<subset> X \<and> X \<subseteq> alts \<Longrightarrow> Y \<notin> set_pmf ` A\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis [PROOF STEP] by (rule wfE_min'[OF wf nonempty']) simp_all [PROOF STATE] proof (state) this: X \<in> set_pmf ` A ?Y \<subset> X \<and> X \<subseteq> alts \<Longrightarrow> ?Y \<notin> set_pmf ` A goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] hence "\<exists>r. r \<in> A \<and> \<not>(\<exists>r'\<in>A. set_pmf r' \<subset> set_pmf r)" [PROOF STATE] proof (prove) using this: X \<in> set_pmf ` A ?Y \<subset> X \<and> X \<subseteq> alts \<Longrightarrow> ?Y \<notin> set_pmf ` A goal (1 subgoal): 1. \<exists>r. r \<in> A \<and> \<not> (\<exists>r'\<in>A. set_pmf r' \<subset> set_pmf r) [PROOF STEP] by (auto simp: subset_alts[of X]) [PROOF STATE] proof (state) this: \<exists>r. r \<in> A \<and> \<not> (\<exists>r'\<in>A. set_pmf r' \<subset> set_pmf r) goal (3 subgoals): 1. r \<in> lotteries_on alts 2. q \<prec>[Pareto (SD \<circ> R)] r 3. \<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r [PROOF STEP] from someI_ex[OF this, folded r_altdef] [PROOF STATE] proof (chain) picking this: r \<in> A \<and> \<not> (\<exists>r'\<in>A. set_pmf r' \<subset> set_pmf r) [PROOF STEP] show "r \<in> lotteries_on alts" "r \<succ>[Pareto(SD\<circ>R)] q" "\<And>r'. r' \<in> lotteries_on alts \<Longrightarrow> r' \<succ>[Pareto(SD\<circ>R)] q \<Longrightarrow> \<not>(set_pmf r' \<subset> set_pmf r)" [PROOF STATE] proof (prove) using this: r \<in> A \<and> \<not> (\<exists>r'\<in>A. set_pmf r' \<subset> set_pmf r) goal (1 subgoal): 1. r \<in> lotteries_on alts &&& q \<prec>[Pareto (SD \<circ> R)] r &&& (\<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r) [PROOF STEP] unfolding A_def [PROOF STATE] proof (prove) using this: r \<in> {r \<in> lotteries_on alts. q \<prec>[Pareto (SD \<circ> R)] r} \<and> \<not> (\<exists>r'\<in>{r \<in> lotteries_on alts. q \<prec>[Pareto (SD \<circ> R)] r}. set_pmf r' \<subset> set_pmf r) goal (1 subgoal): 1. r \<in> lotteries_on alts &&& q \<prec>[Pareto (SD \<circ> R)] r &&& (\<And>r'. \<lbrakk>r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] r'\<rbrakk> \<Longrightarrow> \<not> set_pmf r' \<subset> set_pmf r) [PROOF STEP] by blast+ [PROOF STATE] proof (state) this: r \<in> lotteries_on alts q \<prec>[Pareto (SD \<circ> R)] r \<lbrakk>?r' \<in> lotteries_on alts; q \<prec>[Pareto (SD \<circ> R)] ?r'\<rbrakk> \<Longrightarrow> \<not> set_pmf ?r' \<subset> set_pmf r goal: No subgoals! [PROOF STEP] qed
% SYNTAX: % intensity = hmrR_PreprocessIntensity_MedianFilter( intensity ) % % UI NAME: % hmrR_PreprocessIntensity_MedianFilter % % DESCRIPTION: % Applies a median filter to data to remove huge spikes. % % INPUT: % intensity - SNIRF data type where the d matrix is intensity % % OUTPUT: % intensity - SNIRF data type where the d matrix is intensity % % USAGE OPTIONS: % Intensity_to_Intensity: d = hmrR_PreprocessIntensity_MedianFilter(data) function d = hmrR_PreprocessIntensity_MedianFilter( intensity) for ii=1:length(intensity) d = intensity(ii).GetDataTimeSeries(); for j = 1:size(d,2) foo = d(:,j); xdata = (1:length( foo))'; d(:,j) = interp1(xdata(~isnan( foo)), foo(~isnan( foo)),xdata,'spline'); new_signal = zeros(size(foo)); new_signal(1) = foo(1); new_signal(end) = foo(end); for tp = 2:length(foo)-1 values = foo([tp-1,tp,tp+1]); median_value = median(values); new_signal(tp) = median_value; end d(:,j) = new_signal; end intensity(ii).SetDataTimeSeries(d); end
[STATEMENT] lemma first_iff_u_greater_strict_preff: assumes "p \<in> \<P>" and "q \<in> \<P>" assumes "some_best \<succ>[\<R>] some_worst" shows "my_U p > my_U q \<longleftrightarrow> mix_pmf (my_U p) some_best some_worst \<succ>[\<R>] mix_pmf (my_U q) some_best some_worst" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (my_U q < my_U p) = (mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R>) [PROOF STEP] proof [PROOF STATE] proof (state) goal (2 subgoals): 1. my_U q < my_U p \<Longrightarrow> mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> 2. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> \<Longrightarrow> my_U q < my_U p [PROOF STEP] assume a: "my_U p > my_U q" [PROOF STATE] proof (state) this: my_U q < my_U p goal (2 subgoals): 1. my_U q < my_U p \<Longrightarrow> mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> 2. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> \<Longrightarrow> my_U q < my_U p [PROOF STEP] have "my_U p \<in> {0..1}" "my_U q \<in> {0..1}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. my_U p \<in> {0..1} &&& my_U q \<in> {0..1} [PROOF STEP] using assms my_U_is_defined(1) [PROOF STATE] proof (prove) using this: p \<in> local.\<P> q \<in> local.\<P> some_best \<succeq>[\<R>] some_worst \<and> (some_worst, some_best) \<notin> \<R> ?p \<in> local.\<P> \<Longrightarrow> my_U ?p \<in> {0..1} goal (1 subgoal): 1. my_U p \<in> {0..1} &&& my_U q \<in> {0..1} [PROOF STEP] by blast+ [PROOF STATE] proof (state) this: my_U p \<in> {0..1} my_U q \<in> {0..1} goal (2 subgoals): 1. my_U q < my_U p \<Longrightarrow> mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> 2. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> \<Longrightarrow> my_U q < my_U p [PROOF STEP] then [PROOF STATE] proof (chain) picking this: my_U p \<in> {0..1} my_U q \<in> {0..1} [PROOF STEP] show "mix_pmf (my_U p) some_best some_worst \<succ>[\<R>] mix_pmf (my_U q) some_best some_worst" [PROOF STATE] proof (prove) using this: my_U p \<in> {0..1} my_U q \<in> {0..1} goal (1 subgoal): 1. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> [PROOF STEP] using a assms(3) [PROOF STATE] proof (prove) using this: my_U p \<in> {0..1} my_U q \<in> {0..1} my_U q < my_U p some_best \<succeq>[\<R>] some_worst \<and> (some_worst, some_best) \<notin> \<R> goal (1 subgoal): 1. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> [PROOF STEP] by blast [PROOF STATE] proof (state) this: mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> goal (1 subgoal): 1. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> \<Longrightarrow> my_U q < my_U p [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> \<Longrightarrow> my_U q < my_U p [PROOF STEP] assume a: "mix_pmf (my_U p) some_best some_worst \<succ>[\<R>] mix_pmf (my_U q) some_best some_worst" [PROOF STATE] proof (state) this: mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> goal (1 subgoal): 1. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> \<Longrightarrow> my_U q < my_U p [PROOF STEP] have "my_U p \<in> {0..1}" "my_U q \<in> {0..1}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. my_U p \<in> {0..1} &&& my_U q \<in> {0..1} [PROOF STEP] using assms my_U_is_defined(1) [PROOF STATE] proof (prove) using this: p \<in> local.\<P> q \<in> local.\<P> some_best \<succeq>[\<R>] some_worst \<and> (some_worst, some_best) \<notin> \<R> ?p \<in> local.\<P> \<Longrightarrow> my_U ?p \<in> {0..1} goal (1 subgoal): 1. my_U p \<in> {0..1} &&& my_U q \<in> {0..1} [PROOF STEP] by blast+ [PROOF STATE] proof (state) this: my_U p \<in> {0..1} my_U q \<in> {0..1} goal (1 subgoal): 1. mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> \<Longrightarrow> my_U q < my_U p [PROOF STEP] then [PROOF STATE] proof (chain) picking this: my_U p \<in> {0..1} my_U q \<in> {0..1} [PROOF STEP] show "my_U p > my_U q " [PROOF STATE] proof (prove) using this: my_U p \<in> {0..1} my_U q \<in> {0..1} goal (1 subgoal): 1. my_U q < my_U p [PROOF STEP] using preferred_greater_my_U[of p q] assms a [PROOF STATE] proof (prove) using this: my_U p \<in> {0..1} my_U q \<in> {0..1} \<lbrakk>p \<in> local.\<P>; q \<in> local.\<P>; mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R>\<rbrakk> \<Longrightarrow> my_U q < my_U p p \<in> local.\<P> q \<in> local.\<P> some_best \<succeq>[\<R>] some_worst \<and> (some_worst, some_best) \<notin> \<R> mix_pmf (my_U p) some_best some_worst \<succeq>[\<R>] mix_pmf (my_U q) some_best some_worst \<and> (mix_pmf (my_U q) some_best some_worst, mix_pmf (my_U p) some_best some_worst) \<notin> \<R> goal (1 subgoal): 1. my_U q < my_U p [PROOF STEP] by blast [PROOF STATE] proof (state) this: my_U q < my_U p goal: No subgoals! [PROOF STEP] qed
[STATEMENT] lemma iam_fmempty_empty: \<open>(uncurry0 (RETURN op_map_empty), uncurry0 (RETURN op_iam_fmap_empty)) \<in> unit_rel \<rightarrow>\<^sub>f \<langle>map_fmap_rel\<rangle>nres_rel\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. (uncurry0 (RETURN op_map_empty), uncurry0 (RETURN op_iam_fmap_empty)) \<in> unit_rel \<rightarrow>\<^sub>f \<langle>map_fmap_rel\<rangle>nres_rel [PROOF STEP] by (auto simp: map_fmap_rel_def br_def fmempty_def frefI nres_relI op_iam_fmap_empty_def)
lemma measurable_SUP2: "I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> f \<in> measurable N (M i)) \<Longrightarrow> (\<And>i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> space (M i) = space (M j)) \<Longrightarrow> f \<in> measurable N (SUP i\<in>I. M i)"
#source: tlssunnopic64.s #source: tlsnopic.s #as: --64 -Av9 #ld: -shared -melf64_sparc #readelf: -WSsrl #target: sparc-*-* # FIXME #pass
In such an ecstasy !
Formal statement is: lemmas continuous_on_mult [continuous_intros] = bounded_bilinear.continuous_on [OF bounded_bilinear_mult] Informal statement is: If $f$ and $g$ are continuous functions, then so is $f \cdot g$.
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.set.lattice import Mathlib.PostPort universes u_3 l u_1 u_2 namespace Mathlib /-! # Submonoids: definition and `complete_lattice` structure This file defines bundled multiplicative and additive submonoids. We also define a `complete_lattice` structure on `submonoid`s, define the closure of a set as the minimal submonoid that includes this set, and prove a few results about extending properties from a dense set (i.e. a set with `closure s = ⊤`) to the whole monoid, see `submonoid.dense_induction` and `monoid_hom.of_mdense`. ## Main definitions * `submonoid M`: the type of bundled submonoids of a monoid `M`; the underlying set is given in the `carrier` field of the structure, and should be accessed through coercion as in `(S : set M)`. * `add_submonoid M` : the type of bundled submonoids of an additive monoid `M`. For each of the following definitions in the `submonoid` namespace, there is a corresponding definition in the `add_submonoid` namespace. * `submonoid.copy` : copy of a submonoid with `carrier` replaced by a set that is equal but possibly not definitionally equal to the carrier of the original `submonoid`. * `submonoid.closure` : monoid closure of a set, i.e., the least submonoid that includes the set. * `submonoid.gi` : `closure : set M → submonoid M` and coercion `coe : submonoid M → set M` form a `galois_insertion`; * `monoid_hom.eq_mlocus`: the submonoid of elements `x : M` such that `f x = g x`; * `monoid_hom.of_mdense`: if a map `f : M → N` between two monoids satisfies `f 1 = 1` and `f (x * y) = f x * f y` for `y` from some dense set `s`, then `f` is a monoid homomorphism. E.g., if `f : ℕ → M` satisfies `f 0 = 0` and `f (x + 1) = f x + f 1`, then `f` is an additive monoid homomorphism. ## Implementation notes Submonoid inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a submonoid's underlying set. This file is designed to have very few dependencies. In particular, it should not use natural numbers. ## Tags submonoid, submonoids -/ /-- A submonoid of a monoid `M` is a subset containing 1 and closed under multiplication. -/ structure submonoid (M : Type u_3) [monoid M] where carrier : set M one_mem' : 1 ∈ carrier mul_mem' : ∀ {a b : M}, a ∈ carrier → b ∈ carrier → a * b ∈ carrier /-- An additive submonoid of an additive monoid `M` is a subset containing 0 and closed under addition. -/ structure add_submonoid (M : Type u_3) [add_monoid M] where carrier : set M zero_mem' : 0 ∈ carrier add_mem' : ∀ {a b : M}, a ∈ carrier → b ∈ carrier → a + b ∈ carrier namespace submonoid protected instance Mathlib.add_submonoid.set.has_coe {M : Type u_1} [add_monoid M] : has_coe (add_submonoid M) (set M) := has_coe.mk add_submonoid.carrier protected instance has_mem {M : Type u_1} [monoid M] : has_mem M (submonoid M) := has_mem.mk fun (m : M) (S : submonoid M) => m ∈ ↑S protected instance has_coe_to_sort {M : Type u_1} [monoid M] : has_coe_to_sort (submonoid M) := has_coe_to_sort.mk (Type u_1) fun (S : submonoid M) => Subtype fun (x : M) => x ∈ S @[simp] theorem mem_carrier {M : Type u_1} [monoid M] {s : submonoid M} {x : M} : x ∈ carrier s ↔ x ∈ s := iff.rfl @[simp] theorem mem_coe {M : Type u_1} [monoid M] {S : submonoid M} {m : M} : m ∈ ↑S ↔ m ∈ S := iff.rfl @[simp] theorem coe_coe {M : Type u_1} [monoid M] (s : submonoid M) : ↥↑s = ↥s := rfl protected theorem Mathlib.add_submonoid.exists {M : Type u_1} [add_monoid M] {s : add_submonoid M} {p : ↥s → Prop} : (∃ (x : ↥s), p x) ↔ ∃ (x : M), ∃ (H : x ∈ s), p { val := x, property := H } := set_coe.exists protected theorem forall {M : Type u_1} [monoid M] {s : submonoid M} {p : ↥s → Prop} : (∀ (x : ↥s), p x) ↔ ∀ (x : M) (H : x ∈ s), p { val := x, property := H } := set_coe.forall /-- Two submonoids are equal if the underlying subsets are equal. -/ theorem ext' {M : Type u_1} [monoid M] {S : submonoid M} {T : submonoid M} (h : ↑S = ↑T) : S = T := sorry /-- Two submonoids are equal if and only if the underlying subsets are equal. -/ protected theorem ext'_iff {M : Type u_1} [monoid M] {S : submonoid M} {T : submonoid M} : S = T ↔ ↑S = ↑T := { mp := fun (h : S = T) => h ▸ rfl, mpr := fun (h : ↑S = ↑T) => ext' h } /-- Two submonoids are equal if they have the same elements. -/ theorem Mathlib.add_submonoid.ext {M : Type u_1} [add_monoid M] {S : add_submonoid M} {T : add_submonoid M} (h : ∀ (x : M), x ∈ S ↔ x ∈ T) : S = T := add_submonoid.ext' (set.ext h) /-- Copy a submonoid replacing `carrier` with a set that is equal to it. -/ def copy {M : Type u_1} [monoid M] (S : submonoid M) (s : set M) (hs : s = ↑S) : submonoid M := mk s sorry sorry @[simp] theorem coe_copy {M : Type u_1} [monoid M] {S : submonoid M} {s : set M} (hs : s = ↑S) : ↑(copy S s hs) = s := rfl theorem copy_eq {M : Type u_1} [monoid M] {S : submonoid M} {s : set M} (hs : s = ↑S) : copy S s hs = S := ext' hs /-- A submonoid contains the monoid's 1. -/ theorem Mathlib.add_submonoid.zero_mem {M : Type u_1} [add_monoid M] (S : add_submonoid M) : 0 ∈ S := add_submonoid.zero_mem' S /-- A submonoid is closed under multiplication. -/ theorem mul_mem {M : Type u_1} [monoid M] (S : submonoid M) {x : M} {y : M} : x ∈ S → y ∈ S → x * y ∈ S := mul_mem' S theorem coe_injective {M : Type u_1} [monoid M] (S : submonoid M) : function.injective coe := subtype.val_injective @[simp] theorem coe_eq_coe {M : Type u_1} [monoid M] (S : submonoid M) (x : ↥S) (y : ↥S) : ↑x = ↑y ↔ x = y := set_coe.ext_iff protected instance has_le {M : Type u_1} [monoid M] : HasLessEq (submonoid M) := { LessEq := fun (S T : submonoid M) => ∀ {x : M}, x ∈ S → x ∈ T } theorem le_def {M : Type u_1} [monoid M] {S : submonoid M} {T : submonoid M} : S ≤ T ↔ ∀ {x : M}, x ∈ S → x ∈ T := iff.rfl @[simp] theorem Mathlib.add_submonoid.coe_subset_coe {M : Type u_1} [add_monoid M] {S : add_submonoid M} {T : add_submonoid M} : ↑S ⊆ ↑T ↔ S ≤ T := iff.rfl protected instance Mathlib.add_submonoid.partial_order {M : Type u_1} [add_monoid M] : partial_order (add_submonoid M) := partial_order.mk (fun (S T : add_submonoid M) => ∀ {x : M}, x ∈ S → x ∈ T) partial_order.lt sorry sorry sorry @[simp] theorem coe_ssubset_coe {M : Type u_1} [monoid M] {S : submonoid M} {T : submonoid M} : ↑S ⊂ ↑T ↔ S < T := iff.rfl /-- The submonoid `M` of the monoid `M`. -/ protected instance has_top {M : Type u_1} [monoid M] : has_top (submonoid M) := has_top.mk (mk set.univ sorry sorry) /-- The trivial submonoid `{1}` of an monoid `M`. -/ protected instance Mathlib.add_submonoid.has_bot {M : Type u_1} [add_monoid M] : has_bot (add_submonoid M) := has_bot.mk (add_submonoid.mk (singleton 0) sorry sorry) protected instance Mathlib.add_submonoid.inhabited {M : Type u_1} [add_monoid M] : Inhabited (add_submonoid M) := { default := ⊥ } @[simp] theorem mem_bot {M : Type u_1} [monoid M] {x : M} : x ∈ ⊥ ↔ x = 1 := set.mem_singleton_iff @[simp] theorem mem_top {M : Type u_1} [monoid M] (x : M) : x ∈ ⊤ := set.mem_univ x @[simp] theorem Mathlib.add_submonoid.coe_top {M : Type u_1} [add_monoid M] : ↑⊤ = set.univ := rfl @[simp] theorem coe_bot {M : Type u_1} [monoid M] : ↑⊥ = singleton 1 := rfl /-- The inf of two submonoids is their intersection. -/ protected instance has_inf {M : Type u_1} [monoid M] : has_inf (submonoid M) := has_inf.mk fun (S₁ S₂ : submonoid M) => mk (↑S₁ ∩ ↑S₂) sorry sorry @[simp] theorem coe_inf {M : Type u_1} [monoid M] (p : submonoid M) (p' : submonoid M) : ↑(p ⊓ p') = ↑p ∩ ↑p' := rfl @[simp] theorem mem_inf {M : Type u_1} [monoid M] {p : submonoid M} {p' : submonoid M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl protected instance has_Inf {M : Type u_1} [monoid M] : has_Inf (submonoid M) := has_Inf.mk fun (s : set (submonoid M)) => mk (set.Inter fun (t : submonoid M) => set.Inter fun (H : t ∈ s) => ↑t) sorry sorry @[simp] theorem coe_Inf {M : Type u_1} [monoid M] (S : set (submonoid M)) : ↑(Inf S) = set.Inter fun (s : submonoid M) => set.Inter fun (H : s ∈ S) => ↑s := rfl theorem Mathlib.add_submonoid.mem_Inf {M : Type u_1} [add_monoid M] {S : set (add_submonoid M)} {x : M} : x ∈ Inf S ↔ ∀ (p : add_submonoid M), p ∈ S → x ∈ p := set.mem_bInter_iff theorem mem_infi {M : Type u_1} [monoid M] {ι : Sort u_2} {S : ι → submonoid M} {x : M} : (x ∈ infi fun (i : ι) => S i) ↔ ∀ (i : ι), x ∈ S i := sorry @[simp] theorem Mathlib.add_submonoid.coe_infi {M : Type u_1} [add_monoid M] {ι : Sort u_2} {S : ι → add_submonoid M} : ↑(infi fun (i : ι) => S i) = set.Inter fun (i : ι) => ↑(S i) := sorry /-- Submonoids of a monoid form a complete lattice. -/ protected instance complete_lattice {M : Type u_1} [monoid M] : complete_lattice (submonoid M) := complete_lattice.mk complete_lattice.sup LessEq Less sorry sorry sorry sorry sorry sorry has_inf.inf sorry sorry sorry ⊤ sorry ⊥ sorry complete_lattice.Sup Inf sorry sorry sorry sorry theorem subsingleton_iff {M : Type u_1} [monoid M] : subsingleton M ↔ subsingleton (submonoid M) := sorry theorem nontrivial_iff {M : Type u_1} [monoid M] : nontrivial M ↔ nontrivial (submonoid M) := iff.mp not_iff_not (iff.trans (iff.trans not_nontrivial_iff_subsingleton subsingleton_iff) (iff.symm not_nontrivial_iff_subsingleton)) protected instance subsingleton {M : Type u_1} [monoid M] [subsingleton M] : subsingleton (submonoid M) := iff.mp subsingleton_iff _inst_3 protected instance nontrivial {M : Type u_1} [monoid M] [nontrivial M] : nontrivial (submonoid M) := iff.mp nontrivial_iff _inst_3 /-- The `submonoid` generated by a set. -/ def Mathlib.add_submonoid.closure {M : Type u_1} [add_monoid M] (s : set M) : add_submonoid M := Inf (set_of fun (S : add_submonoid M) => s ⊆ ↑S) theorem mem_closure {M : Type u_1} [monoid M] {s : set M} {x : M} : x ∈ closure s ↔ ∀ (S : submonoid M), s ⊆ ↑S → x ∈ S := mem_Inf /-- The submonoid generated by a set includes the set. -/ @[simp] theorem subset_closure {M : Type u_1} [monoid M] {s : set M} : s ⊆ ↑(closure s) := fun (x : M) (hx : x ∈ s) => iff.mpr mem_closure fun (S : submonoid M) (hS : s ⊆ ↑S) => hS hx /-- A submonoid `S` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {M : Type u_1} [monoid M] {s : set M} {S : submonoid M} : closure s ≤ S ↔ s ⊆ ↑S := { mp := set.subset.trans subset_closure, mpr := fun (h : s ⊆ ↑S) => Inf_le h } /-- Submonoid closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ theorem Mathlib.add_submonoid.closure_mono {M : Type u_1} [add_monoid M] {s : set M} {t : set M} (h : s ⊆ t) : add_submonoid.closure s ≤ add_submonoid.closure t := iff.mpr add_submonoid.closure_le (set.subset.trans h add_submonoid.subset_closure) theorem Mathlib.add_submonoid.closure_eq_of_le {M : Type u_1} [add_monoid M] {s : set M} {S : add_submonoid M} (h₁ : s ⊆ ↑S) (h₂ : S ≤ add_submonoid.closure s) : add_submonoid.closure s = S := le_antisymm (iff.mpr add_submonoid.closure_le h₁) h₂ /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `s`, and is preserved under multiplication, then `p` holds for all elements of the closure of `s`. -/ theorem closure_induction {M : Type u_1} [monoid M] {s : set M} {p : M → Prop} {x : M} (h : x ∈ closure s) (Hs : ∀ (x : M), x ∈ s → p x) (H1 : p 1) (Hmul : ∀ (x y : M), p x → p y → p (x * y)) : p x := iff.mpr closure_le Hs x h /-- If `s` is a dense set in a monoid `M`, `submonoid.closure s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, verify `p 1`, and verify that `p x` and `p y` imply `p (x * y)`. -/ theorem dense_induction {M : Type u_1} [monoid M] {p : M → Prop} (x : M) {s : set M} (hs : closure s = ⊤) (Hs : ∀ (x : M), x ∈ s → p x) (H1 : p 1) (Hmul : ∀ (x y : M), p x → p y → p (x * y)) : p x := sorry /-- If `s` is a dense set in an additive monoid `M`, `add_submonoid.closure s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, verify `p 0`, and verify that `p x` and `p y` imply `p (x + y)`. -/ /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi (M : Type u_1) [monoid M] : galois_insertion closure coe := galois_insertion.mk (fun (s : set M) (_x : ↑(closure s) ≤ s) => closure s) sorry sorry sorry /-- Closure of a submonoid `S` equals `S`. -/ @[simp] theorem closure_eq {M : Type u_1} [monoid M] (S : submonoid M) : closure ↑S = S := galois_insertion.l_u_eq (submonoid.gi M) S @[simp] theorem closure_empty {M : Type u_1} [monoid M] : closure ∅ = ⊥ := galois_connection.l_bot (galois_insertion.gc (submonoid.gi M)) @[simp] theorem closure_univ {M : Type u_1} [monoid M] : closure set.univ = ⊤ := coe_top ▸ closure_eq ⊤ theorem Mathlib.add_submonoid.closure_union {M : Type u_1} [add_monoid M] (s : set M) (t : set M) : add_submonoid.closure (s ∪ t) = add_submonoid.closure s ⊔ add_submonoid.closure t := galois_connection.l_sup (galois_insertion.gc (add_submonoid.gi M)) theorem closure_Union {M : Type u_1} [monoid M] {ι : Sort u_2} (s : ι → set M) : closure (set.Union fun (i : ι) => s i) = supr fun (i : ι) => closure (s i) := galois_connection.l_supr (galois_insertion.gc (submonoid.gi M)) end submonoid /-- The submonoid consisting of the units of a monoid -/ def is_unit.submonoid (M : Type u_1) [monoid M] : submonoid M := submonoid.mk (set_of is_unit) sorry sorry theorem is_unit.mem_submonoid_iff {M : Type u_1} [monoid M] (a : M) : a ∈ is_unit.submonoid M ↔ is_unit a := id (eq.mpr (id (Eq._oldrec (Eq.refl (a ∈ set_of is_unit ↔ is_unit a)) set.mem_set_of_eq)) (iff.refl (is_unit a))) namespace monoid_hom /-- The submonoid of elements `x : M` such that `f x = g x` -/ def eq_mlocus {M : Type u_1} [monoid M] {N : Type u_3} [monoid N] (f : M →* N) (g : M →* N) : submonoid M := submonoid.mk (set_of fun (x : M) => coe_fn f x = coe_fn g x) sorry sorry /-- If two monoid homomorphisms are equal on a set, then they are equal on its submonoid closure. -/ theorem Mathlib.add_monoid_hom.eq_on_mclosure {M : Type u_1} [add_monoid M] {N : Type u_3} [add_monoid N] {f : M →+ N} {g : M →+ N} {s : set M} (h : set.eq_on (⇑f) (⇑g) s) : set.eq_on ⇑f ⇑g ↑(add_submonoid.closure s) := (fun (this : add_submonoid.closure s ≤ add_monoid_hom.eq_mlocus f g) => this) (iff.mpr add_submonoid.closure_le h) theorem Mathlib.add_monoid_hom.eq_of_eq_on_mtop {M : Type u_1} [add_monoid M] {N : Type u_3} [add_monoid N] {f : M →+ N} {g : M →+ N} (h : set.eq_on ⇑f ⇑g ↑⊤) : f = g := add_monoid_hom.ext fun (x : M) => h trivial theorem eq_of_eq_on_mdense {M : Type u_1} [monoid M] {N : Type u_3} [monoid N] {s : set M} (hs : submonoid.closure s = ⊤) {f : M →* N} {g : M →* N} (h : set.eq_on (⇑f) (⇑g) s) : f = g := eq_of_eq_on_mtop (hs ▸ eq_on_mclosure h) /-- Let `s` be a subset of a monoid `M` such that the closure of `s` is the whole monoid. Then `monoid_hom.of_mdense` defines a monoid homomorphism from `M` asking for a proof of `f (x * y) = f x * f y` only for `y ∈ s`. -/ def of_mdense {M : Type u_1} [monoid M] {s : set M} {N : Type u_3} [monoid N] (f : M → N) (hs : submonoid.closure s = ⊤) (h1 : f 1 = 1) (hmul : ∀ (x y : M), y ∈ s → f (x * y) = f x * f y) : M →* N := mk f h1 sorry /-- Let `s` be a subset of an additive monoid `M` such that the closure of `s` is the whole monoid. Then `add_monoid_hom.of_mdense` defines an additive monoid homomorphism from `M` asking for a proof of `f (x + y) = f x + f y` only for `y ∈ s`. -/ @[simp] theorem coe_of_mdense {M : Type u_1} [monoid M] {s : set M} {N : Type u_3} [monoid N] (f : M → N) (hs : submonoid.closure s = ⊤) (h1 : f 1 = 1) (hmul : ∀ (x y : M), y ∈ s → f (x * y) = f x * f y) : ⇑(of_mdense f hs h1 hmul) = f := rfl end Mathlib
############################################################################ ## ## recognizeprim.gi IRREDSOL Burkhard Höfling ## ## Copyright © 2003–2016 Burkhard Höfling ## ########################################################################### ## #F IdPrimitiveSolubleGroup(<grp>) ## ## see IRREDSOL documentation ## InstallMethod(IdPrimitiveSolubleGroup, "for soluble group", true, [IsSolvableGroup and IsFinite], 0, G -> IdIrreducibleSolubleMatrixGroup(IrreducibleMatrixGroupPrimitiveSolubleGroup(G))); RedispatchOnCondition(IdPrimitiveSolubleGroup, true, [IsGroup], [IsFinite and IsSolvableGroup], 0); ########################################################################### ## #F IdPrimitiveSolubleGroupNC(<grp>) ## ## see IRREDSOL documentation ## InstallGlobalFunction(IdPrimitiveSolubleGroupNC, function(G) local id; id := IdIrreducibleSolubleMatrixGroup(IrreducibleMatrixGroupPrimitiveSolubleGroupNC(G)); SetIdPrimitiveSolubleGroup(G, id); return id; end); ############################################################################ ## #F RecognitionPrimitiveSolubleGroup(<G>) ## ## see IRREDSOL documentation ## InstallGlobalFunction(RecognitionPrimitiveSolubleGroup, function(G, wantiso) local N, F, p, pcgsN, C, pcgsC, one, i, mat, mats, CC, H, hom, infomat, info, rep, ext, imgs, g, r; N := FittingSubgroup(G); pcgsN := Pcgs(N); p := Set(RelativeOrders(pcgsN)); if Length(p) <> 1 then Error("G must be primitive"); fi; p := p[1]; if not IsAbelian(N) or ForAny(pcgsN, g -> g^p <> One(G)) then Error("G must be primitive"); fi; # now we know that N is elementary abelian of exponent p F := GF(p); one := One(F); mats := []; C := ComplementClassesRepresentatives(G, N); if Length(C) <> 1 then Error("G must be primitive"); fi; C := C[1]; # N is complemented pcgsC := Pcgs(C); for g in pcgsC do mat := []; for i in [1..Length(pcgsN)] do mat[i] := ExponentsOfPcElement(pcgsN, pcgsN[i]^g)*one; od; Add(mats, ImmutableMatrix(F, mat)); od; if not MTX.IsIrreducible(GModuleByMats(mats, F)) then Error("G must be primitive"); fi; H := Group(mats); # the recognition part works best if the source of the representation isomorphism is a pc group if IsPcGroup(C) then CC := C; else CC := PcGroupWithPcgs(Pcgs(C)); fi; SetSize(H, Size(C)); hom := GroupGeneralMappingByImagesNC(CC, H, Pcgs(CC), mats); SetIsGroupHomomorphism(hom, true); SetIsBijective(hom, true); SetRepresentationIsomorphism(H, hom); infomat := RecognitionIrreducibleSolubleMatrixGroup(H, wantiso, wantiso, wantiso); info := rec(id := infomat.id); if not wantiso then return info; fi; rep := RepresentationIsomorphism(infomat.group); ext := PcGroupExtensionByMatrixAction(Pcgs(Source(rep)), rep); imgs := []; for g in Pcgs(CC) do Add(imgs, ImageElm(ext.embed, ImageElm(infomat.iso, g))); od; for r in infomat.mat do g := PcElementByExponents(ext.pcgsV, List(r, IntFFE)); Add(imgs, g); od; info.group := ext.E; info.iso := GroupHomomorphismByImages(G, ext.E, Concatenation(pcgsC, pcgsN), imgs); if info.iso = fail or not IsBijective(info.iso) then Error("wrong group homomorphism"); fi; return info; end); ############################################################################ ## #E ##
""" Deterministic(value) Create a deterministic distribution over only one value. This is intended to be used when a distribution is required, but the outcome is deterministic. It is equivalent to a Kronecker Delta distribution. """ struct Deterministic{T} val::T end rand(rng::AbstractRNG, d::Deterministic) = d.val rand(d::Deterministic) = d.val support(d::Deterministic) = (d.val,) sampletype(::Type{Deterministic{T}}) where T = T Random.gentype(::Type{Deterministic{T}}) where T = T pdf(d::Deterministic, x) = convert(Float64, x == d.val) mode(d::Deterministic) = d.val mean(d::Deterministic{N}) where N<:Number = d.val / 1 # / 1 is to make this return a similar type to Statistics.mean mean(d::Deterministic) = d.val # so that division need not be implemented for the value type
using SymPy function Base.show(io::IO, ::MIME"text/latex", x::SymPy.SymbolicObject) print(io, SymPy.as_markdown(sympy.latex(x))) end # Show SymPy ## Type piracy function Base.show(io::IO, ::MIME"text/html", x::T) where {T <: SymPy.SymbolicObject} #write(io, "<div class=\"well well-sm\">") write(io, "<div class=\"output\">") show(io, "text/latex", x) write(io, "</div>") end function Base.show(io::IO, ::MIME"text/html", x::Array{T}) where {T <: SymPy.SymbolicObject} #write(io, "<div class=\"well well-sm\">") write(io, "<div class=\"output\">") show(io, "text/latex", x) write(io, "</div>") end ## -------- gradient(ex::SymPy.Sym, vars::AbstractArray=free_symbols(ex)) = diff.(ex, [vars...]) divergence(F::Vector{Sym}, vars=free_symbols(F)) = sum(diff.(F, vars)) curl(F::Vector{Sym}, vars=free_symbols(F)) = curl(F.jacobian(vars))
[STATEMENT] lemma of_char_mod_256 [simp]: \<open>of_char c mod 256 = of_char c\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. of_char c mod (256::'a) = of_char c [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. of_char c mod (256::'a) = of_char c [PROOF STEP] have \<open>of_char (char_of (of_char c)) mod 256 = of_char (char_of (of_char c))\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. of_char (char_of (of_char c)) mod (256::'a) = of_char (char_of (of_char c)) [PROOF STEP] by (simp only: of_char_of) simp [PROOF STATE] proof (state) this: of_char (char_of (of_char c)) mod (256::'a) = of_char (char_of (of_char c)) goal (1 subgoal): 1. of_char c mod (256::'a) = of_char c [PROOF STEP] then [PROOF STATE] proof (chain) picking this: of_char (char_of (of_char c)) mod (256::'a) = of_char (char_of (of_char c)) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: of_char (char_of (of_char c)) mod (256::'a) = of_char (char_of (of_char c)) goal (1 subgoal): 1. of_char c mod (256::'a) = of_char c [PROOF STEP] by simp [PROOF STATE] proof (state) this: of_char c mod (256::'a) = of_char c goal: No subgoals! [PROOF STEP] qed
Formal statement is: lemma bounded_linear_zero[simp]: "bounded_linear (\<lambda>x. 0)" Informal statement is: The function $f(x) = 0$ is bounded linear.
// Copyright (C) 2006-2009, 2012 Alexander Nasonov // Copyright (C) 2012 Lorenzo Caminiti // Distributed under the Boost Software License, Version 1.0 // (see accompanying file LICENSE_1_0.txt or a copy at // http://www.boost.org/LICENSE_1_0.txt) // Home at http://www.boost.org/libs/scope_exit #include <boost/scope_exit.hpp> #include <boost/rational.hpp> #include <boost/typeof/typeof.hpp> #include <boost/typeof/std/vector.hpp> #include <boost/detail/lightweight_test.hpp> #include <vector> template<class type> void tpl_long( type tval , type & t , type const& tc , type volatile& tv , type const volatile& tcv ) { int i = 0; // non-dependent name type const remember(tval); { BOOST_SCOPE_EXIT_TPL( (&tval) (&t) (&tc) (&tv) (&tcv) (&i) ) { tval = 1; ++t; ++tv; } BOOST_SCOPE_EXIT_END BOOST_TEST(t == remember); BOOST_TEST(tval == remember); } BOOST_TEST(tval == 1); BOOST_TEST(t == remember + 2); } template<class Vector, int Value> void tpl_vector( Vector vval , Vector & v , Vector const& vc ) { Vector const remember(vval); { BOOST_SCOPE_EXIT_TPL( (&vval) (&v) (&vc) ) { v.push_back(-Value); vval.push_back(Value); } BOOST_SCOPE_EXIT_END BOOST_TEST(v.size() == remember.size()); BOOST_TEST(vval.size() == remember.size()); } BOOST_TEST(v.size() == 1 + remember.size()); BOOST_TEST(vval.size() == 1 + remember.size()); } int main(void) { long l = 137; tpl_long(l, l, l, l, l); std::vector<int> v(10, 137); tpl_vector<std::vector<int>, 13>(v, v, v); return boost::report_errors(); }
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Yury Kudryashov -/ import data.real.sqrt import tactic.interval_cases import ring_theory.algebraic import data.rat.sqrt import data.polynomial.eval import ring_theory.int.basic /-! # Irrational real numbers In this file we define a predicate `irrational` on `ℝ`, prove that the `n`-th root of an integer number is irrational if it is not integer, and that `sqrt q` is irrational if and only if `rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q`. We also provide dot-style constructors like `irrational.add_rat`, `irrational.rat_sub` etc. -/ open rat real multiplicity /-- A real number is irrational if it is not equal to any rational number. -/ def irrational (x : ℝ) := x ∉ set.range (coe : ℚ → ℝ) lemma irrational_iff_ne_rational (x : ℝ) : irrational x ↔ ∀ a b : ℤ, x ≠ a / b := by simp only [irrational, rat.forall, cast_mk, not_exists, set.mem_range, cast_coe_int, cast_div, eq_comm] /-- A transcendental real number is irrational. -/ lemma transcendental.irrational {r : ℝ} (tr : transcendental ℚ r) : irrational r := by { rintro ⟨a, rfl⟩, exact tr (is_algebraic_algebra_map a) } /-! ### Irrationality of roots of integer and rational numbers -/ /-- If `x^n`, `n > 0`, is integer and is not the `n`-th power of an integer, then `x` is irrational. -/ theorem irrational_nrt_of_notint_nrt {x : ℝ} (n : ℕ) (m : ℤ) (hxr : x ^ n = m) (hv : ¬ ∃ y : ℤ, x = y) (hnpos : 0 < n) : irrational x := begin rintros ⟨⟨N, D, P, C⟩, rfl⟩, rw [← cast_pow] at hxr, have c1 : ((D : ℤ) : ℝ) ≠ 0, { rw [int.cast_ne_zero, int.coe_nat_ne_zero], exact ne_of_gt P }, have c2 : ((D : ℤ) : ℝ) ^ n ≠ 0 := pow_ne_zero _ c1, rw [num_denom', cast_pow, cast_mk, div_pow, div_eq_iff_mul_eq c2, ← int.cast_pow, ← int.cast_pow, ← int.cast_mul, int.cast_inj] at hxr, have hdivn : ↑D ^ n ∣ N ^ n := dvd.intro_left m hxr, rw [← int.dvd_nat_abs, ← int.coe_nat_pow, int.coe_nat_dvd, int.nat_abs_pow, nat.pow_dvd_pow_iff hnpos] at hdivn, have hD : D = 1 := by rw [← nat.gcd_eq_right hdivn, C.gcd_eq_one], subst D, refine hv ⟨N, _⟩, rw [num_denom', int.coe_nat_one, mk_eq_div, int.cast_one, div_one, cast_coe_int] end /-- If `x^n = m` is an integer and `n` does not divide the `multiplicity p m`, then `x` is irrational. -/ theorem irrational_nrt_of_n_not_dvd_multiplicity {x : ℝ} (n : ℕ) {m : ℤ} (hm : m ≠ 0) (p : ℕ) [hp : fact p.prime] (hxr : x ^ n = m) (hv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.1.ne_one, hm⟩) % n ≠ 0) : irrational x := begin rcases nat.eq_zero_or_pos n with rfl | hnpos, { rw [eq_comm, pow_zero, ← int.cast_one, int.cast_inj] at hxr, simpa [hxr, multiplicity.one_right (mt is_unit_iff_dvd_one.1 (mt int.coe_nat_dvd.1 hp.1.not_dvd_one)), nat.zero_mod] using hv }, refine irrational_nrt_of_notint_nrt _ _ hxr _ hnpos, rintro ⟨y, rfl⟩, rw [← int.cast_pow, int.cast_inj] at hxr, subst m, have : y ≠ 0, { rintro rfl, rw zero_pow hnpos at hm, exact hm rfl }, erw [multiplicity.pow' (nat.prime_iff_prime_int.1 hp.1) (finite_int_iff.2 ⟨hp.1.ne_one, this⟩), nat.mul_mod_right] at hv, exact hv rfl end theorem irrational_sqrt_of_multiplicity_odd (m : ℤ) (hm : 0 < m) (p : ℕ) [hp : fact p.prime] (Hpv : (multiplicity (p : ℤ) m).get (finite_int_iff.2 ⟨hp.1.ne_one, (ne_of_lt hm).symm⟩) % 2 = 1) : irrational (sqrt m) := @irrational_nrt_of_n_not_dvd_multiplicity _ 2 _ (ne.symm (ne_of_lt hm)) p hp (sq_sqrt (int.cast_nonneg.2 $ le_of_lt hm)) (by rw Hpv; exact one_ne_zero) theorem nat.prime.irrational_sqrt {p : ℕ} (hp : nat.prime p) : irrational (sqrt p) := @irrational_sqrt_of_multiplicity_odd p (int.coe_nat_pos.2 hp.pos) p ⟨hp⟩ $ by simp [multiplicity_self (mt is_unit_iff_dvd_one.1 (mt int.coe_nat_dvd.1 hp.not_dvd_one) : _)]; refl /-- **Irrationality of the Square Root of 2** -/ theorem irrational_sqrt_two : irrational (sqrt 2) := by simpa using nat.prime_two.irrational_sqrt theorem irrational_sqrt_rat_iff (q : ℚ) : irrational (sqrt q) ↔ rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q := if H1 : rat.sqrt q * rat.sqrt q = q then iff_of_false (not_not_intro ⟨rat.sqrt q, by rw [← H1, cast_mul, sqrt_mul_self (cast_nonneg.2 $ rat.sqrt_nonneg q), sqrt_eq, abs_of_nonneg (rat.sqrt_nonneg q)]⟩) (λ h, h.1 H1) else if H2 : 0 ≤ q then iff_of_true (λ ⟨r, hr⟩, H1 $ (exists_mul_self _).1 ⟨r, by rwa [eq_comm, sqrt_eq_iff_mul_self_eq (cast_nonneg.2 H2), ← cast_mul, rat.cast_inj] at hr; rw [← hr]; exact real.sqrt_nonneg _⟩) ⟨H1, H2⟩ else iff_of_false (not_not_intro ⟨0, by rw cast_zero; exact (sqrt_eq_zero_of_nonpos (rat.cast_nonpos.2 $ le_of_not_le H2)).symm⟩) (λ h, H2 h.2) instance (q : ℚ) : decidable (irrational (sqrt q)) := decidable_of_iff' _ (irrational_sqrt_rat_iff q) /-! ### Dot-style operations on `irrational` #### Coercion of a rational/integer/natural number is not irrational -/ namespace irrational variable {x : ℝ} /-! #### Irrational number is not equal to a rational/integer/natural number -/ theorem ne_rat (h : irrational x) (q : ℚ) : x ≠ q := λ hq, h ⟨q, hq.symm⟩ theorem ne_int (h : irrational x) (m : ℤ) : x ≠ m := by { rw ← rat.cast_coe_int, exact h.ne_rat _ } theorem ne_nat (h : irrational x) (m : ℕ) : x ≠ m := h.ne_int m theorem ne_zero (h : irrational x) : x ≠ 0 := h.ne_nat 0 theorem ne_one (h : irrational x) : x ≠ 1 := by simpa only [nat.cast_one] using h.ne_nat 1 end irrational @[simp] lemma rat.not_irrational (q : ℚ) : ¬irrational q := λ h, h ⟨q, rfl⟩ @[simp] lemma int.not_irrational (m : ℤ) : ¬irrational m := λ h, h.ne_int m rfl @[simp] lemma nat.not_irrational (m : ℕ) : ¬irrational m := λ h, h.ne_nat m rfl namespace irrational variables (q : ℚ) {x y : ℝ} /-! #### Addition of rational/integer/natural numbers -/ /-- If `x + y` is irrational, then at least one of `x` and `y` is irrational. -/ theorem add_cases : irrational (x + y) → irrational x ∨ irrational y := begin delta irrational, contrapose!, rintros ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩, exact ⟨rx + ry, cast_add rx ry⟩ end theorem of_rat_add (h : irrational (q + x)) : irrational x := h.add_cases.resolve_left q.not_irrational theorem rat_add (h : irrational x) : irrational (q + x) := of_rat_add (-q) $ by rwa [cast_neg, neg_add_cancel_left] theorem of_add_rat : irrational (x + q) → irrational x := add_comm ↑q x ▸ of_rat_add q theorem add_rat (h : irrational x) : irrational (x + q) := add_comm ↑q x ▸ h.rat_add q theorem of_int_add (m : ℤ) (h : irrational (m + x)) : irrational x := by { rw ← cast_coe_int at h, exact h.of_rat_add m } theorem of_add_int (m : ℤ) (h : irrational (x + m)) : irrational x := of_int_add m $ add_comm x m ▸ h theorem int_add (h : irrational x) (m : ℤ) : irrational (m + x) := by { rw ← cast_coe_int, exact h.rat_add m } theorem add_int (h : irrational x) (m : ℤ) : irrational (x + m) := add_comm ↑m x ▸ h.int_add m theorem of_nat_add (m : ℕ) (h : irrational (m + x)) : irrational x := h.of_int_add m theorem of_add_nat (m : ℕ) (h : irrational (x + m)) : irrational x := h.of_add_int m theorem nat_add (h : irrational x) (m : ℕ) : irrational (m + x) := h.int_add m theorem add_nat (h : irrational x) (m : ℕ) : irrational (x + m) := h.add_int m /-! #### Negation -/ theorem of_neg (h : irrational (-x)) : irrational x := λ ⟨q, hx⟩, h ⟨-q, by rw [cast_neg, hx]⟩ protected theorem neg (h : irrational x) : irrational (-x) := of_neg $ by rwa neg_neg /-! #### Subtraction of rational/integer/natural numbers -/ theorem sub_rat (h : irrational x) : irrational (x - q) := by simpa only [sub_eq_add_neg, cast_neg] using h.add_rat (-q) theorem rat_sub (h : irrational x) : irrational (q - x) := by simpa only [sub_eq_add_neg] using h.neg.rat_add q theorem of_sub_rat (h : irrational (x - q)) : irrational x := (of_add_rat (-q) $ by simpa only [cast_neg, sub_eq_add_neg] using h) theorem of_rat_sub (h : irrational (q - x)) : irrational x := of_neg (of_rat_add q (by simpa only [sub_eq_add_neg] using h)) theorem sub_int (h : irrational x) (m : ℤ) : irrational (x - m) := by simpa only [rat.cast_coe_int] using h.sub_rat m theorem int_sub (h : irrational x) (m : ℤ) : irrational (m - x) := by simpa only [rat.cast_coe_int] using h.rat_sub m theorem of_sub_int (m : ℤ) (h : irrational (x - m)) : irrational x := of_sub_rat m $ by rwa rat.cast_coe_int theorem of_int_sub (m : ℤ) (h : irrational (m - x)) : irrational x := of_rat_sub m $ by rwa rat.cast_coe_int theorem sub_nat (h : irrational x) (m : ℕ) : irrational (x - m) := h.sub_int m theorem nat_sub (h : irrational x) (m : ℕ) : irrational (m - x) := h.int_sub m theorem of_sub_nat (m : ℕ) (h : irrational (x - m)) : irrational x := h.of_sub_int m theorem of_nat_sub (m : ℕ) (h : irrational (m - x)) : irrational x := h.of_int_sub m /-! #### Multiplication by rational numbers -/ theorem mul_cases : irrational (x * y) → irrational x ∨ irrational y := begin delta irrational, contrapose!, rintros ⟨⟨rx, rfl⟩, ⟨ry, rfl⟩⟩, exact ⟨rx * ry, cast_mul rx ry⟩ end theorem of_mul_rat (h : irrational (x * q)) : irrational x := h.mul_cases.resolve_right q.not_irrational theorem mul_rat (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (x * q) := of_mul_rat q⁻¹ $ by rwa [mul_assoc, ← cast_mul, mul_inv_cancel hq, cast_one, mul_one] theorem of_rat_mul : irrational (q * x) → irrational x := mul_comm x q ▸ of_mul_rat q theorem rat_mul (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (q * x) := mul_comm x q ▸ h.mul_rat hq theorem of_mul_int (m : ℤ) (h : irrational (x * m)) : irrational x := of_mul_rat m $ by rwa cast_coe_int theorem of_int_mul (m : ℤ) (h : irrational (m * x)) : irrational x := of_rat_mul m $ by rwa cast_coe_int theorem mul_int (h : irrational x) {m : ℤ} (hm : m ≠ 0) : irrational (x * m) := by { rw ← cast_coe_int, refine h.mul_rat _, rwa int.cast_ne_zero } theorem int_mul (h : irrational x) {m : ℤ} (hm : m ≠ 0) : irrational (m * x) := mul_comm x m ▸ h.mul_int hm theorem of_mul_nat (m : ℕ) (h : irrational (x * m)) : irrational x := h.of_mul_int m theorem of_nat_mul (m : ℕ) (h : irrational (m * x)) : irrational x := h.of_int_mul m theorem mul_nat (h : irrational x) {m : ℕ} (hm : m ≠ 0) : irrational (x * m) := h.mul_int $ int.coe_nat_ne_zero.2 hm theorem nat_mul (h : irrational x) {m : ℕ} (hm : m ≠ 0) : irrational (m * x) := h.int_mul $ int.coe_nat_ne_zero.2 hm /-! #### Inverse -/ theorem of_inv (h : irrational x⁻¹) : irrational x := λ ⟨q, hq⟩, h $ hq ▸ ⟨q⁻¹, q.cast_inv⟩ protected theorem inv (h : irrational x) : irrational x⁻¹ := of_inv $ by rwa inv_inv₀ /-! #### Division -/ theorem div_cases (h : irrational (x / y)) : irrational x ∨ irrational y := h.mul_cases.imp id of_inv theorem of_rat_div (h : irrational (q / x)) : irrational x := (h.of_rat_mul q).of_inv theorem of_div_rat (h : irrational (x / q)) : irrational x := h.div_cases.resolve_right q.not_irrational theorem rat_div (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (q / x) := h.inv.rat_mul hq theorem div_rat (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (x / q) := by { rw [div_eq_mul_inv, ← cast_inv], exact h.mul_rat (inv_ne_zero hq) } theorem of_int_div (m : ℤ) (h : irrational (m / x)) : irrational x := h.div_cases.resolve_left m.not_irrational theorem of_div_int (m : ℤ) (h : irrational (x / m)) : irrational x := h.div_cases.resolve_right m.not_irrational theorem int_div (h : irrational x) {m : ℤ} (hm : m ≠ 0) : irrational (m / x) := h.inv.int_mul hm theorem div_int (h : irrational x) {m : ℤ} (hm : m ≠ 0) : irrational (x / m) := by { rw ← cast_coe_int, refine h.div_rat _, rwa int.cast_ne_zero } theorem of_nat_div (m : ℕ) (h : irrational (m / x)) : irrational x := h.of_int_div m theorem of_div_nat (m : ℕ) (h : irrational (x / m)) : irrational x := h.of_div_int m theorem nat_div (h : irrational x) {m : ℕ} (hm : m ≠ 0) : irrational (m / x) := h.inv.nat_mul hm theorem div_nat (h : irrational x) {m : ℕ} (hm : m ≠ 0) : irrational (x / m) := h.div_int $ by rwa int.coe_nat_ne_zero theorem of_one_div (h : irrational (1 / x)) : irrational x := of_rat_div 1 $ by rwa [cast_one] /-! #### Natural and integerl power -/ theorem of_mul_self (h : irrational (x * x)) : irrational x := h.mul_cases.elim id id theorem of_pow : ∀ n : ℕ, irrational (x^n) → irrational x | 0 := λ h, by { rw pow_zero at h, exact (h ⟨1, cast_one⟩).elim } | (n+1) := λ h, by { rw pow_succ at h, exact h.mul_cases.elim id (of_pow n) } theorem of_zpow : ∀ m : ℤ, irrational (x^m) → irrational x | (n:ℕ) := of_pow n | -[1+n] := λ h, by { rw zpow_neg_succ_of_nat at h, exact h.of_inv.of_pow _ } end irrational section polynomial open polynomial variables (x : ℝ) (p : polynomial ℤ) lemma one_lt_nat_degree_of_irrational_root (hx : irrational x) (p_nonzero : p ≠ 0) (x_is_root : aeval x p = 0) : 1 < p.nat_degree := begin by_contra rid, rcases exists_eq_X_add_C_of_nat_degree_le_one (not_lt.1 rid) with ⟨a, b, rfl⟩, clear rid, have : (a : ℝ) * x = -b, by simpa [eq_neg_iff_add_eq_zero] using x_is_root, rcases em (a = 0) with (rfl|ha), { obtain rfl : b = 0, by simpa, simpa using p_nonzero }, { rw [mul_comm, ← eq_div_iff_mul_eq, eq_comm] at this, refine hx ⟨-b / a, _⟩, assumption_mod_cast, assumption_mod_cast } end end polynomial section variables {q : ℚ} {m : ℤ} {n : ℕ} {x : ℝ} open irrational /-! ### Simplification lemmas about operations -/ @[simp] theorem irrational_rat_add_iff : irrational (q + x) ↔ irrational x := ⟨of_rat_add q, rat_add q⟩ @[simp] theorem irrational_int_add_iff : irrational (m + x) ↔ irrational x := ⟨of_int_add m, λ h, h.int_add m⟩ @[simp] theorem irrational_nat_add_iff : irrational (n + x) ↔ irrational x := ⟨of_nat_add n, λ h, h.nat_add n⟩ @[simp] theorem irrational_add_rat_iff : irrational (x + q) ↔ irrational x := ⟨of_add_rat q, add_rat q⟩ @[simp] theorem irrational_add_int_iff : irrational (x + m) ↔ irrational x := ⟨of_add_int m, λ h, h.add_int m⟩ @[simp] theorem irrational_add_nat_iff : irrational (x + n) ↔ irrational x := ⟨of_add_nat n, λ h, h.add_nat n⟩ @[simp] theorem irrational_rat_sub_iff : irrational (q - x) ↔ irrational x := ⟨of_rat_sub q, rat_sub q⟩ @[simp] theorem irrational_int_sub_iff : irrational (m - x) ↔ irrational x := ⟨of_int_sub m, λ h, h.int_sub m⟩ @[simp] theorem irrational_nat_sub_iff : irrational (n - x) ↔ irrational x := ⟨of_nat_sub n, λ h, h.nat_sub n⟩ @[simp] theorem irrational_sub_rat_iff : irrational (x - q) ↔ irrational x := ⟨of_sub_rat q, sub_rat q⟩ @[simp] theorem irrational_sub_int_iff : irrational (x - m) ↔ irrational x := ⟨of_sub_int m, λ h, h.sub_int m⟩ @[simp] theorem irrational_sub_nat_iff : irrational (x - n) ↔ irrational x := ⟨of_sub_nat n, λ h, h.sub_nat n⟩ @[simp] theorem irrational_neg_iff : irrational (-x) ↔ irrational x := ⟨of_neg, irrational.neg⟩ @[simp] theorem irrational_inv_iff : irrational x⁻¹ ↔ irrational x := ⟨of_inv, irrational.inv⟩ @[simp] theorem irrational_rat_mul_iff : irrational (q * x) ↔ q ≠ 0 ∧ irrational x := ⟨λ h, ⟨rat.cast_ne_zero.1 $ left_ne_zero_of_mul h.ne_zero, h.of_rat_mul q⟩, λ h, h.2.rat_mul h.1⟩ @[simp] theorem irrational_mul_rat_iff : irrational (x * q) ↔ q ≠ 0 ∧ irrational x := by rw [mul_comm, irrational_rat_mul_iff] @[simp] theorem irrational_int_mul_iff : irrational (m * x) ↔ m ≠ 0 ∧ irrational x := by rw [← cast_coe_int, irrational_rat_mul_iff, int.cast_ne_zero] @[simp] theorem irrational_mul_int_iff : irrational (x * m) ↔ m ≠ 0 ∧ irrational x := by rw [← cast_coe_int, irrational_mul_rat_iff, int.cast_ne_zero] @[simp] theorem irrational_nat_mul_iff : irrational (n * x) ↔ n ≠ 0 ∧ irrational x := by rw [← cast_coe_nat, irrational_rat_mul_iff, nat.cast_ne_zero] @[simp] theorem irrational_mul_nat_iff : irrational (x * n) ↔ n ≠ 0 ∧ irrational x := by rw [← cast_coe_nat, irrational_mul_rat_iff, nat.cast_ne_zero] @[simp] theorem irrational_rat_div_iff : irrational (q / x) ↔ q ≠ 0 ∧ irrational x := by simp [div_eq_mul_inv] @[simp] theorem irrational_div_rat_iff : irrational (x / q) ↔ q ≠ 0 ∧ irrational x := by rw [div_eq_mul_inv, ← cast_inv, irrational_mul_rat_iff, ne.def, inv_eq_zero] @[simp] theorem irrational_int_div_iff : irrational (m / x) ↔ m ≠ 0 ∧ irrational x := by simp [div_eq_mul_inv] @[simp] theorem irrational_div_int_iff : irrational (x / m) ↔ m ≠ 0 ∧ irrational x := by rw [← cast_coe_int, irrational_div_rat_iff, int.cast_ne_zero] @[simp] theorem irrational_nat_div_iff : irrational (n / x) ↔ n ≠ 0 ∧ irrational x := by simp [div_eq_mul_inv] @[simp] theorem irrational_div_nat_iff : irrational (x / n) ↔ n ≠ 0 ∧ irrational x := by rw [← cast_coe_nat, irrational_div_rat_iff, nat.cast_ne_zero] /-- There is an irrational number `r` between any two reals `x < r < y`. -/ theorem exists_irrational_btwn {x y : ℝ} (h : x < y) : ∃ r, irrational r ∧ x < r ∧ r < y := let ⟨q, ⟨hq1, hq2⟩⟩ := (exists_rat_btwn ((sub_lt_sub_iff_right (real.sqrt 2)).mpr h)) in ⟨q + real.sqrt 2, irrational_sqrt_two.rat_add _, sub_lt_iff_lt_add.mp hq1, lt_sub_iff_add_lt.mp hq2⟩ end
module TypeSig where f : {A : Set} → A → A f x = x g : {A : Set} → A → A g x = x h : {A : Set} → A → A h x = f x _ : {A : Set} → A → A _ = λ x → x
(*** Boolean Unification Type Declarations. Authors: Joseph St. Pierre Spyridon Antonatos ***) (*** Required Libraries ***) Require Import Bool. Require Import Omega. Require Import EqNat. Require Import List. Require Import Setoid. Import ListNotations. (** * Introduction **) (** In order for any proofs to be constructed in Coq, we need to formally define the logic and data across which said proofs will operate. Since the heart of our analysis is concerned with the unification of Boolean equations, it stands to reason that we should articulate precisely how algebra functions with respect to Boolean rings. To attain this, we shall formalize what an equation looks like, how it can be composed inductively, and also how substitutions behave when applied to equations. *) (** * Terms **) (** ** Definitions **) (** We shall now begin describing the rules of Boolean arithmetic as well as the nature of Boolean equations. *) (** Define a variable to be a natural number *) Definition var := nat. (** A _term_, as has already been previously described, is now inductively declared to hold either a constant value, a single variable, a sum of terms, or a product of terms. *) Inductive term: Type := | T0 : term | T1 : term | VAR : var -> term | SUM : term -> term -> term | PRODUCT : term -> term -> term. (** For convenience's sake, we define some shorthanded notation for readability. *) Implicit Types x y z : term. Implicit Types n m : var. Notation "x + y" := (SUM x y) (at level 50, left associativity). Notation "x * y" := (PRODUCT x y) (at level 40, left associativity). (** ** Axioms *) (** Now that we have informed Coq on the nature of what a term is, it is now time to propose a set of axioms that will articulate exactly how algebra behaves across Boolean rings. This is a requirement since the very act of unifying an equation is intimately related to solving it algebraically. Each of the axioms proposed below describe the rules of Boolean algebra precisely and in an unambiguous manner. None of these should come as a surprise to the reader; however, if one is not familiar with this form of logic, the rules regarding the summation and multiplication of identical terms might pose as a source of confusion. For reasons of keeping Coq's internal logic consistent, we roll our own custom equivalence relation as opposed to simply using "=". This will provide a surefire way to avoid any odd errors from later cropping up in our proofs. Of course, by doing this we introduce some implications that we will need to address later. *) Parameter eqv : term -> term -> Prop. (** Here we introduce some special notation for term equivalence *) Infix " == " := eqv (at level 70). (** Below is the set of fundamental axioms concerning the equivalence "==" relation. They form the boolean ring (or system) on which Lowenheim's formula and proof are developed. Most of these axioms will appear familiar to anyone; however, certain ones such as the summation of two identical terms are true only across Boolean rings and as such might appear strange at first glance. *) Axiom sum_comm : forall x y, x + y == y + x. Axiom sum_assoc : forall x y z, (x + y) + z == x + (y + z). Axiom sum_id : forall x, T0 + x == x. (** Across boolean rings, the summation of two terms will always be 0 because there are only two elements in the ring: 0 and 1. For this reason, the mapping of [1 + 1] has nowhere else to go besides 0. *) Axiom sum_x_x : forall x, x + x == T0. Axiom mul_comm : forall x y, x * y == y * x. Axiom mul_assoc : forall x y z, (x * y) * z == x * (y * z). (** Across boolean rings, the multiplication of two identical terms will always be the same as just having one instance of said term. This is because $0 \ast 0 = 0$ and $1 \ast 1 = 1$ as one would expect normally. *) Axiom mul_x_x : forall x, x * x == x. Axiom mul_T0_x : forall x, T0 * x == T0. Axiom mul_id : forall x, T1 * x == x. Axiom distr : forall x y z, x * (y + z) == (x * y) + (x * z). (** Any axioms beyond this point of the development are not considered part of the "fundamental axiom system", but they still need to exist for the development and proofs to hold. *) (** Across all equations, adding an expression to both sides does not break the equivalence of the relation. *) Axiom term_sum_symmetric : forall x y z, x == y <-> x + z == y + z. Axiom refl_comm : forall t1 t2, t1 == t2 -> t2 == t1. Axiom T1_not_equiv_T0 : ~(T1 == T0). Hint Resolve sum_comm sum_assoc sum_x_x sum_id distr mul_comm mul_assoc mul_x_x mul_T0_x mul_id. (** Now that the core axioms have been taken care of, we need to handle the implications posed by our custom equivalence relation. Below we inform Coq of the behavior of our equivalence relation with respect to reflexivity, symmetry, and transitivity in order to allow for rewrites during the construction of proofs operating across our new equivalence relation. *) (* Mundane coq magic for custom equivalence relation *) Axiom eqv_ref : Reflexive eqv. Axiom eqv_sym : Symmetric eqv. Axiom eqv_trans : Transitive eqv. Add Parametric Relation : term eqv reflexivity proved by @eqv_ref symmetry proved by @eqv_sym transitivity proved by @eqv_trans as eq_set_rel. Axiom SUM_compat : forall x x', x == x' -> forall y y', y == y' -> (x + y) == (x' + y'). Axiom PRODUCT_compat : forall x x', x == x' -> forall y y', y == y' -> (x * y) == (x' * y'). Add Parametric Morphism : SUM with signature eqv ==> eqv ==> eqv as SUM_mor. Proof. exact SUM_compat. Qed. Add Parametric Morphism : PRODUCT with signature eqv ==> eqv ==> eqv as PRODUCT_mor. Proof. exact PRODUCT_compat. Qed. Hint Resolve eqv_ref eqv_sym eqv_trans SUM_compat PRODUCT_compat. (** ** Lemmas **) (** Since Coq now understands the basics of Boolean algebra, it serves as a good exercise for us to generate some further rules using Coq's proving systems. By doing this, not only do we gain some additional tools that will become handy later down the road, but we also test whether our axioms are behaving as we would like them to. *) (** This is a lemma for a sub-case of term multiplication. *) Lemma mul_x_x_plus_T1 : forall x, x * (x + T1) == T0. Proof. intros. rewrite distr. rewrite mul_x_x. rewrite mul_comm. rewrite mul_id. apply sum_x_x. Qed. (** This is a lemma to convert term equivalence to equivalence between their addition and ground term [T0], and vice-versa. *) Lemma x_equal_y_x_plus_y : forall x y, x == y <-> x + y == T0. Proof. intros. split. - intros. rewrite H. rewrite sum_x_x. reflexivity. - intros. rewrite term_sum_symmetric with (y := y) (z := y). rewrite sum_x_x. apply H. Qed. Hint Resolve mul_x_x_plus_T1 x_equal_y_x_plus_y. (** These lemmas just serve to make certain rewrites regarding the core axioms less tedious to write. While one could certainly argue that they should be formulated as axioms and not lemmas due to their triviality, being pedantic is a good exercise. *) (** This is a lemma for identity addition between term and ground term [T0]. *) Lemma sum_id_sym : forall x, x + T0 == x. Proof. intros. rewrite sum_comm. apply sum_id. Qed. (** Here is a lemma for identity multiplication between term and ground term [T1]. *) Lemma mul_id_sym : forall x, x * T1 == x. Proof. intros. rewrite mul_comm. apply mul_id. Qed. (** This is a lemma for multiplication between term and ground term [T0]. *) Lemma mul_T0_x_sym : forall x, x * T0 == T0. Proof. intros. rewrite mul_comm. apply mul_T0_x. Qed. Lemma sum_assoc_opp : forall x y z, x + (y + z) == (x + y) + z. Proof. intros. rewrite sum_assoc. reflexivity. Qed. Lemma mul_assoc_opp : forall x y z, x * (y * z) == (x * y) * z. Proof. intros. rewrite mul_assoc. reflexivity. Qed. Lemma distr_opp : forall x y z, x * y + x * z == x * ( y + z). Proof. intros. rewrite distr. reflexivity. Qed. (** * Variable Sets **) (** Now that the underlying behavior concerning Boolean algebra has been properly articulated to Coq, it is now time to begin formalizing the logic surrounding our meta reasoning of Boolean equations and systems. While there are certainly several approaches to begin this process, we thought it best to ease into things through formalizing the notion of a set of variables present in an equation. *) (** ** Definitions **) (** We now define a _variable set_ to be precisely a list of variables; additionally, we include several functions for including and excluding variables from these variable sets. Furthermore, since uniqueness is not a property guaranteed by Coq lists and it has the potential to be desirable, we define a function that consumes a variable set and removes duplicate entries from it. For convenience, we also provide several examples to demonstrate the functionalities of these new definitions. *) (** Here is a definition of the new type to represent a list (set) of variables (natural numbers). *) Definition var_set := list var. Implicit Type vars: var_set. (** Here is a simple function to check to see if a variable is in a variable set. *) Fixpoint var_set_includes_var (v : var) (vars : var_set) : bool := match vars with | nil => false | n :: n' => if (beq_nat v n) then true else var_set_includes_var v n' end. (** Here is a function to remove all instances of var [v] from a list of vars. *) Fixpoint var_set_remove_var (v : var) (vars : var_set) : var_set := match vars with | nil => nil | n :: n' => if (beq_nat v n) then (var_set_remove_var v n') else n :: (var_set_remove_var v n') end. (** Next is a function to return a unique [var_set] without duplicates. Found vars should be empty for correctness guarantee. *) Fixpoint var_set_create_unique (vars : var_set): var_set := match vars with | nil => nil | n :: n' => if (var_set_includes_var n n') then var_set_create_unique n' else n :: var_set_create_unique n' end. (** This is a function to check if a given var_set is unique. *) Fixpoint var_set_is_unique (vars : var_set): bool := match vars with | nil => true | n :: n' => if (var_set_includes_var n n') then false else var_set_is_unique n' end. (** This is a function to get the variables of a term as a var_set. *) Fixpoint term_vars (t : term) : var_set := match t with | T0 => nil | T1 => nil | VAR x => x :: nil | PRODUCT x y => (term_vars x) ++ (term_vars y) | SUM x y => (term_vars x) ++ (term_vars y) end. (** This is a function to generate a list of unique variables that make up a given term. *) Definition term_unique_vars (t : term) : var_set := var_set_create_unique (term_vars t). (** ** Helper Lemmas for variable sets and lists *) (** Now that we have established the functionality for variable sets, let us prove some properties about them. *) Lemma vs_includes_true : forall (x : var) (lvar : list var), var_set_includes_var x lvar = true -> In x lvar. Proof. intros. induction lvar. - simpl; intros. discriminate. - simpl in H. remember (beq_nat x a) as H2. destruct H2. + simpl. left. symmetry in HeqH2. pose proof beq_nat_true as H7. specialize (H7 x a HeqH2). symmetry in H7. apply H7. + specialize (IHlvar H). simpl. right. apply IHlvar. Qed. Lemma vs_includes_false : forall (x : var) (lvar : list var), var_set_includes_var x lvar = false -> ~ In x lvar. Proof. intros. induction lvar. - simpl; intros. unfold not. intros. destruct H0. - simpl in H. remember (beq_nat x a) as H2. destruct H2. inversion H. specialize (IHlvar H). firstorder. intuition. apply IHlvar. simpl in H0. destruct H0. + inversion HeqH2. symmetry in H2. pose proof beq_nat_false as H7. specialize (H7 x a H2). rewrite H0 in H7. destruct H7. intuition. + apply H0. Qed. Lemma in_dup_and_non_dup : forall (x: var) (lvar : list var), In x lvar <-> In x (var_set_create_unique lvar). Proof. intros. split. - induction lvar. + intros. simpl in H. destruct H. + intros. simpl. remember (var_set_includes_var a lvar) as C. destruct C. * symmetry in HeqC. pose proof vs_includes_true as H7. specialize (H7 a lvar HeqC). simpl in H. destruct H. -- rewrite H in H7. specialize (IHlvar H7). apply IHlvar. -- specialize (IHlvar H). apply IHlvar. * symmetry in HeqC. pose proof vs_includes_false as H7. specialize (H7 a lvar HeqC). simpl in H. destruct H. -- simpl. left. apply H. -- specialize (IHlvar H). simpl. right. apply IHlvar. - induction lvar. + intros. simpl in H. destruct H. + intros. simpl in H. remember (var_set_includes_var a lvar) as C. destruct C. * symmetry in HeqC. pose proof vs_includes_true as H7. specialize (H7 a lvar HeqC). specialize (IHlvar H). simpl. right. apply IHlvar. * symmetry in HeqC. pose proof vs_includes_false as H7. specialize (H7 a lvar HeqC). simpl in H. destruct H. -- simpl. left. apply H. -- specialize (IHlvar H). simpl. right. apply IHlvar. Qed. (** ** Examples **) (** Below are some examples of the behaviors of variable sets. *) Example var_set_create_unique_ex1 : var_set_create_unique [0;5;2;1;1;2;2;9;5;3] = [0;1;2;9;5;3]. Proof. simpl. reflexivity. Qed. Example var_set_is_unique_ex1 : var_set_is_unique [0;2;2;2] = false. Proof. simpl. reflexivity. Qed. (** Here are examples to demonstrate the correctness of the function [term_vars] on specific cases. *) Example term_vars_ex1 : term_vars (VAR 0 + VAR 0 + VAR 1) = [0;0;1]. Proof. simpl. reflexivity. Qed. Example term_vars_ex2 : In 0 (term_vars (VAR 0 + VAR 0 + VAR 1)). Proof. simpl. left. reflexivity. Qed. (** * Ground Terms **) (** Seeing as we just outlined the definition of a variable set, it seems fair to now formalize the definition of a ground term, or in other words, a term that has no variables and whose variable set is the empty set. *) (** ** Definitions **) (** A _ground term_ is a recursively defined proposition that is only true if and only if no variable appears in it; otherwise it will be a false proposition and no longer a ground term. *) (** In this subsection we declare definitions related to ground terms, inluding functions and lemmas. *) (** This is a function to check if a given term is a ground term (i.e. has no vars). *) Fixpoint ground_term (t : term) : Prop := match t with | VAR x => False | SUM x y => ground_term x /\ ground_term y | PRODUCT x y => ground_term x /\ ground_term y | _ => True end. (** ** Lemmas **) (** Our first real lemma (shown below), articulates an important property of ground terms: all ground terms are equvialent to either 0 or 1. This curious property is a direct result of the fact that these terms possess no variables and additioanlly because of the axioms of Boolean algebra. *) (** This is a lemma (trivial, intuitively true) that proves that if the function [ground_term] returns true then it is either [T0] or [T1]. *) Lemma ground_term_equiv_T0_T1 : forall x, ground_term x -> x == T0 \/ x == T1. Proof. intros. induction x. - left. reflexivity. - right. reflexivity. - contradiction. - inversion H. destruct IHx1; destruct IHx2; auto. rewrite H2. left. rewrite sum_id. apply H3. rewrite H2. rewrite H3. rewrite sum_id. right. reflexivity. rewrite H2. rewrite H3. right. rewrite sum_comm. rewrite sum_id. reflexivity. rewrite H2. rewrite H3. rewrite sum_x_x. left. reflexivity. - inversion H. destruct IHx1; destruct IHx2; auto. rewrite H2. left. rewrite mul_T0_x. reflexivity. rewrite H2. left. rewrite mul_T0_x. reflexivity. rewrite H3. left. rewrite mul_comm. rewrite mul_T0_x. reflexivity. rewrite H2. rewrite H3. right. rewrite mul_id. reflexivity. Qed. (** This lemma, while intuitively obvious by definition, nonetheless provides a formal bridge between the world of ground terms and the world of variable sets. *) Lemma ground_term_has_empty_var_set : forall x, ground_term x -> term_vars x = []. Proof. intros. induction x. - simpl. reflexivity. - simpl. reflexivity. - contradiction. - firstorder. unfold term_vars. unfold term_vars in H2. rewrite H2. unfold term_vars in H1. rewrite H1. simpl. reflexivity. - firstorder. unfold term_vars. unfold term_vars in H2. rewrite H2. unfold term_vars in H1. rewrite H1. simpl. reflexivity. Qed. (** ** Examples **) (** Here are some examples to show that our ground term definition is working appropriately. *) Example ex_gt1 : ground_term (T0 + T1). Proof. simpl. split. - reflexivity. - reflexivity. Qed. Example ex_gt2 : ground_term (VAR 0 * T1) -> False. Proof. simpl. intros. destruct H. apply H. Qed. (** * Substitutions **) (** It is at this point in our Coq development that we begin to officially define the principal action around which the entirety of our efforts are centered: the act of substituting variables with other terms. While substitutions alone are not of great interest, their emergent properties as in the case of whether or not a given substitution unifies an equation are of substantial importance to our later research. *) (** ** Definitions **) (** In this subsection we make the fundamental definitions of substitutions, basic functions for them, accompanying lemmas and some propsitions. *) (** Here we define a _substitution_ to be a list of ordered pairs where each pair represents a variable being mapped to a term. For sake of clarity these ordered pairs shall be referred to as _replacements_ from now on and as a result, substitutions should really be considered to be lists of replacements. *) Definition replacement := prod var term. (** We define a new type [susbt] to represent a substitution as a list of replacements. *) Definition subst := list replacement. Implicit Type s : subst. (** Our first function, [find_replacement], is an auxilliary to [apply_subst]. This function will search through a substitution for a specific variable, and if found, returns the variable's associated term. *) Fixpoint find_replacement (x : var) (s : subst) : term := match s with | nil => VAR x | r :: r' => if beq_nat (fst r) x then snd r else find_replacement x r' end. (** The [apply_subst] function will take a term and a substitution and will produce a new term reflecting the changes made to the original one. *) Fixpoint apply_subst (t : term) (s : subst) : term := match t with | T0 => T0 | T1 => T1 | VAR x => find_replacement x s | PRODUCT x y => PRODUCT (apply_subst x s) (apply_subst y s) | SUM x y => SUM (apply_subst x s) (apply_subst y s) end. (** For reasons of completeness, it is useful to be able to generate _identity substitutions_; namely, substitutions that map the variables of a term to themselves. *) (** This is a function when given a list of variables builds a list of identity substitutions - one for each variable. *) Fixpoint build_id_subst (lvar : var_set) : subst := match lvar with | nil => nil | v :: v' => (v , (VAR v)) :: build_id_subst v' end. (** Since we now have the ability to generate identity substitutions, we should now formalize a general proposition for testing whether or not a given substitution is an identity substitution of a given term. *) Definition subst_equiv (s1 s2: subst) : Prop := forall t, apply_subst t s1 == apply_subst t s2. Definition subst_is_id_subst (t : term) (s : subst) : Prop := apply_subst t s == t. (** Given we now have definitions for substitutions, we should now introduce the idea of a substitution composing another one. *) Fixpoint subst_compose (s s' : subst) : subst := match s' with | [] => s | (x, t) :: s'' => (x, apply_subst t s) :: (subst_compose s s'') end. (** Here we define the domain of a substituion, namely the list of variables for which the substitution has a mapping (replacement). Essentially this acts as a list of all the first parts of the replacement. *) Definition subst_domain (sig : subst) : list var := map (fun r => (fst r)) sig. (** We define the concept of a sub list. If an element is a member of a list, it is then a member of the other list as well. *) Definition sub_dmn_list (l1 : list var) (l2 : list var) : Prop := forall (x : var), In x l1 -> In x l2. (** ** Helper Lemmas for the [apply_subst] function **) (** Having now outlined the functionality of a subsitution, let us now begin to analyze some implications of its form and composition by proving some lemmas. *) (** Given that we have a definition for identity substitutions, we should prove that identity substitutions do not modify a term. *) Lemma id_subst: forall (t : term) (l : var_set), apply_subst t (build_id_subst l) == t. Proof. intros. induction t. - simpl. reflexivity. - simpl. reflexivity. - simpl. induction l. + simpl. reflexivity. + simpl. destruct (beq_nat a v) eqn: e. * apply beq_nat_true in e. rewrite e. reflexivity. * apply IHl. - simpl. rewrite IHt1. rewrite IHt2. reflexivity. - simpl. rewrite IHt1. rewrite IHt2. reflexivity. Qed. (** These are helper lemmes for the [apply_subst] properties. *) Lemma sum_comm_compat t1 t2: forall (sigma: subst), apply_subst (t1 + t2) sigma == apply_subst (t2 + t1) sigma. Proof. intros. simpl. auto. Qed. Hint Resolve sum_comm_compat. Lemma sum_assoc_compat t1 t2 t3: forall (sigma: subst), apply_subst ((t1 + t2) + t3) sigma == apply_subst (t1 + (t2 + t3)) sigma. Proof. intros. simpl. auto. Qed. Hint Resolve sum_assoc_compat. Lemma sum_id_compat t: forall (sigma: subst), apply_subst (T0 + t) sigma == apply_subst t sigma. Proof. intros. simpl. auto. Qed. Hint Resolve sum_id_compat. Lemma sum_x_x_compat t: forall (sigma: subst), apply_subst (t + t) sigma == apply_subst T0 sigma. Proof. intros. simpl. auto. Qed. Hint Resolve sum_x_x_compat. Lemma mul_comm_compat t1 t2: forall (sigma: subst), apply_subst (t1 * t2) sigma == apply_subst (t2 * t1) sigma. Proof. intros. simpl. auto. Qed. Hint Resolve mul_comm_compat. Lemma mul_assoc_compat t1 t2 t3: forall (sigma: subst), apply_subst ((t1 * t2) * t3) sigma == apply_subst (t1 * (t2 * t3)) sigma. Proof. intros. simpl. auto. Qed. Hint Resolve mul_assoc_compat. Lemma mul_x_x_compat t: forall (sigma: subst), apply_subst (t * t) sigma == apply_subst t sigma. Proof. intros. simpl. auto. Qed. Hint Resolve mul_x_x_compat. Lemma mul_T0_x_compat t: forall (sigma: subst), apply_subst (T0 * t) sigma == apply_subst T0 sigma. Proof. intros. simpl. auto. Qed. Hint Resolve mul_T0_x_compat. Lemma mul_id_compat t: forall (sigma: subst), apply_subst (T1 * t) sigma == apply_subst t sigma. Proof. intros. simpl. auto. Qed. Hint Resolve mul_id_compat. Lemma distr_compat t1 t2 t3: forall (sigma: subst), apply_subst (t1 * (t2 + t3)) sigma == apply_subst ((t1 * t2) + (t1 * t3)) sigma. Proof. intros. simpl. auto. Qed. Hint Resolve distr_compat. Lemma refl_comm_compat t1 t2: forall (sigma: subst), apply_subst t1 sigma == apply_subst t2 sigma -> apply_subst t2 sigma == apply_subst t1 sigma. Proof. intros. simpl. auto. Qed. Hint Resolve refl_comm_compat. Lemma trans_compat t1 t2 t3 : forall (sigma: subst), apply_subst t1 sigma == apply_subst t2 sigma -> apply_subst t2 sigma == apply_subst t3 sigma -> apply_subst t1 sigma == apply_subst t3 sigma. Proof. intros. eauto. Qed. Hint Resolve trans_compat. Lemma trans_compat2 c1 c2 c3 : c1 == c2 -> c2 == c3 -> c1 == c3. Proof. intros. eauto. Qed. (** This is an axiom that states that if two terms are equivalent then applying any substitution on them will also produce equivalent terms. The reason we axiomatized this and we did not prove it as a lemma is because the set of our fundamental axioms is not an inductive relation, so it would be impossible to prove the lemma below with our fundamental axioms in the currrent format. *) Axiom apply_subst_compat : forall (t t' : term), t == t' -> forall (sigma: subst), apply_subst t sigma == apply_subst t' sigma. Add Parametric Morphism : apply_subst with signature eqv ==> eq ==> eqv as apply_subst_mor. Proof. exact apply_subst_compat. Qed. (** This is a simple lemma that states that an empty substitution cannot modify a term. *) Lemma subst_empty_no_change : forall (t : term), (apply_subst t []) == t. Proof. intros. induction t. - simpl. reflexivity. - simpl. reflexivity. - simpl. reflexivity. - simpl. rewrite IHt1. rewrite IHt2. reflexivity. - simpl. rewrite IHt1. rewrite IHt2. reflexivity. Qed. (** An intuitive thing to prove for ground terms is that they cannot be modified by applying substitutions to them. This will later prove to be very relevant when we begin to talk about unification. *) (** This is a helpful lemma for showing substitutions do not affect ground terms. *) Lemma ground_term_cannot_subst : forall x, ground_term x -> forall s, apply_subst x s == x. Proof. intros. induction s. - apply ground_term_equiv_T0_T1 in H. destruct H. + rewrite H. simpl. reflexivity. + rewrite H. simpl. reflexivity. - apply ground_term_equiv_T0_T1 in H. destruct H. rewrite H. + simpl. reflexivity. + rewrite H. simpl. reflexivity. Qed. (** A fundamental property of substitutions is their distributivity across the summation and multiplication of terms. Again the importance of these proofs will not become apparent until we talk about unification. *) (** This is a useful lemma for showing the distributivity of substitutions across term summation. *) Lemma subst_sum_distribution : forall s x y, apply_subst x s + apply_subst y s == apply_subst (x + y) s. Proof. intro. induction s. - simpl. intros. reflexivity. - intros. simpl. reflexivity. Qed. (** This is a lemma to prove the distributivity of the [apply_subst] function across term multiplication. *) Lemma subst_mul_distribution : forall s x y, apply_subst x s * apply_subst y s == apply_subst (x * y) s. Proof. intro. induction s. - intros. reflexivity. - intros. simpl. reflexivity. Qed. (** Here is a lemma to prove the opposite of summation distributivity of the [apply_subst] function across term summation. *) Lemma subst_sum_distr_opp : forall s x y, apply_subst (x + y) s == apply_subst x s + apply_subst y s. Proof. intros. apply refl_comm. apply subst_sum_distribution. Qed. (** This is a lemma to prove the opposite of multiplication distributivity of the [apply_subst] function across term summation. *) Lemma subst_mul_distr_opp : forall s x y, apply_subst (x * y) s == apply_subst x s * apply_subst y s. Proof. intros. apply refl_comm. apply subst_mul_distribution. Qed. (** This is an intutitive lemmas to apply a single replacement substitution on a VAR term. *) Lemma var_subst: forall (v : var) (ts : term), apply_subst (VAR v) [(v , ts)] == ts. Proof. intros. simpl. destruct (beq_nat v v) eqn: e. - apply beq_nat_true in e. reflexivity. - apply beq_nat_false in e. firstorder. Qed. (** ** Examples **) (** Here are some examples showcasing the nature of applying substitutions to terms. *) Example subst_ex1 : apply_subst (T0 + T1) [] == T0 + T1. Proof. intros. reflexivity. Qed. Example subst_ex2 : apply_subst (VAR 0 * VAR 1) [(0, T0)] == T0. Proof. intros. simpl. apply mul_T0_x. Qed. (** ** Auxillary Definitions for Substitutions and Terms *) (** In this section we define more helper functions and lemmas related to substitutions and ground terms. Specifically we are defining a ground term, a ground substitution, a "01" term, a "01" substitution, and a substitution composition. A [ground_term] is a term with no variables in it. The terms that are used more in the future proofs are the "01" term and "01" substitution. A "01" term is a term that is either exaclty equal to [T0] or [T1]. A "01" substitution is a substitution in which each variable (or the first part of each replacement) is mapped to a "01" term. A "01" term is not necessarily a ground term (but it might be) and a "01" substitution is not necessarily a ground substitution (but it might be). In the proof file, we are mostly using the "01" term and substitution terminology. *) (** We define a proposition for a [ground_subst]. A substitution is ground when in all of its replacements, the second part is a [ground_term]. *) Fixpoint ground_subst (sig : subst) : Prop := match sig with | [] => True | r :: r' => ground_term (snd r) /\ ground_subst r' end. (** This is a function to determine whether a term is a ground term, by returning a boolean. *) Fixpoint is_ground_term (t : term) : bool := match t with | T0 => true | T1 => true | VAR x => false | SUM a b => (is_ground_term a) && (is_ground_term b) | PRODUCT a b => (is_ground_term a) && (is_ground_term b) end. (** This is a function to determine whether a subsitution is a ground substitution, by returning a boolean. *) Fixpoint is_ground_subst (sig : subst) : bool := existsb is_ground_term (map snd sig). (** This is a function to determine whether a term is a [T0] or [T1] term by returning a boolean. *) Definition is_01_term (t : term) : bool := match t with | T0 => true | T1 => true | _ => false end. (** This is a function to determine whether a substitution is a "01" substitution by returning a boolean, meaning that each second part of every replacement is either a [T0] or a [T1] term. *) Fixpoint is_01_subst (sig : subst) : bool := existsb is_01_term (map snd sig). (** This is a function to determine whether a term is a [T0] or [T1] term by returning a proposition. *) Fixpoint _01_term (t : term) : Prop := match t with | T0 => True | T1 => True | _ => False end. (** This is a function to determine whether a substitution is a "01" substitution by returning a proposition, meaning that each second part of every replacement is either a [T0] or a [T1] term. *) Fixpoint _01_subst (sig : subst) : Prop := match sig with | [] => True | r :: r' => _01_term (snd r) /\ _01_subst r' end. (** * Unification **) (** Now that we have established the concept of term substitutions in Coq, it is time for us to formally define the concept of Boolean unification. _Unification_, in its most literal sense, refers to the act of applying a substitution to terms in order to make them equivalent to each other. In other words, to say that two terms are _unifiable_ is to really say that there exists a substitution such that the two terms are equal. Interestingly enough, we can abstract this concept further to simply saying that a single term is unifiable if there exists a substitution such that the term will be equivalent to [0]. By doing this abstraction, we can prove that equation solving and unification are essentially the same fundamental problem. *) (** Below is the initial definition for unification, namely that two terms can be unified to be equivalent to one another. By starting here we will show each step towards abstracting unification to refer to a single term. *) (** Proposition that a given substitution unifies (namely, makes equivalent), two given terms *) Definition unifies (a b : term) (s : subst) : Prop := apply_subst a s == apply_subst b s. (** Here is a simple example demonstrating the concept of testing whether two terms are unified by a substitution. *) Example ex_unif1 : unifies (VAR 0) (VAR 1) [(0, T1); (1, T1)]. Proof. unfold unifies. simpl. reflexivity. Qed. (** Now we are going to show that moving both terms to one side of the equivalence relation through addition does not change the concept of unification. *) (** This is a proposition that a given substitution makes equivalent the sum of two terms when the substitution is applied to each of them, and ground term [T0]. *) Definition unifies_T0 (a b : term) (s : subst) : Prop := apply_subst a s + apply_subst b s == T0. (** This is a lemma that proves that finding a unifier for [x = y] is the same as finding a unifier for [x + y = 0]. *) Lemma unifies_T0_equiv : forall x y s, unifies x y s <-> unifies_T0 x y s. Proof. intros. split. - intros. unfold unifies_T0. unfold unifies in H. rewrite H. rewrite sum_x_x. reflexivity. - intros. unfold unifies_T0 in H. unfold unifies. rewrite term_sum_symmetric with (x := apply_subst x s + apply_subst y s) (z := apply_subst y s) in H. rewrite sum_id in H. rewrite sum_comm in H. rewrite sum_comm with (y := apply_subst y s) in H. rewrite <- sum_assoc in H. rewrite sum_x_x in H. rewrite sum_id in H. apply H. Qed. (** Now we can define what it means for a substitution to be a unifier for a given term. *) (** Here is a proposition that a given substitution unifies a given term, namely it makes it equivalent with [T0]. *) Definition unifier (t : term) (s : subst) : Prop := apply_subst t s == T0. Example unifier_ex1 : unifier (VAR 0) [(0, T0)]. Proof. unfold unifier. simpl. reflexivity. Qed. (** To ensure our efforts were not in vain, let us now prove that this last abstraction of the unification problem is still equivalent to the original. *) (** This is a lemma that proves that the unifier proposition can distributes over addition of terms. *) Lemma unifier_distribution : forall x y s, unifies_T0 x y s <-> unifier (x + y) s. Proof. intros. split. - intros. unfold unifies_T0 in H. unfold unifier. rewrite <- H. symmetry. apply subst_sum_distribution. - intros. unfold unifies_T0. unfold unifier in H. rewrite <- H. apply subst_sum_distribution. Qed. (** Lastly let us define a term to be unifiable if there exists a substitution that unifies it. *) (** This is a proposition that states when a term is unifiable. *) Definition unifiable (t : term) : Prop := exists s, unifier t s. Example unifiable_ex1 : exists x, unifiable (x + T1). Proof. exists T1. unfold unifiable. unfold unifier. exists []. simpl. rewrite sum_x_x. reflexivity. Qed. (** * Most General Unifier **) (** In this subsection we define propositions, lemmas and examples related to the most general unifier. *) (** While the property of a term being unifiable is certainly important, it should come as no surprise that not all unifiers are created equal; in fact, certain unifiers possess the desirable property of being _more general_ than others. For this reason, let us now formally define the concept of a _most general unifier_ (mgu): a unifier such that with respect to a given term, all other unifiers are instances of it, or in other words, less general than it. *) (** The first step towards establishing the concept of a mgu requires us to formalize the notion of a unifier being more general than another. To accomplish this goal, let us formulate the definition of a substitution composing another one; or in other words, to say that a substitution is more general than another one. *) (** This is a proposition of sequential substition application. *) Definition substitution_factor_through (s s' delta : subst) : Prop := forall (x : var), apply_subst (apply_subst (VAR x) s) delta == apply_subst (VAR x) s' . (** This is the definition of a more general substition. *) Definition more_general_substitution (s s': subst) : Prop := exists delta, substitution_factor_through s s' delta . (** Now that we have articulated the concept of composing substitutions, let us now formulate the definition for a most general unifier. *) (** This is the definition of a Most General Unifier (mgu): A Most General Unifier (MGU) takes in a term and a substitution and tells whether or not said substitution is an mgu for the given term. *) Definition most_general_unifier (t : term) (s : subst) : Prop := unifier t s /\ forall (s' : subst), unifier t s' -> more_general_substitution s s'. (** While this definition of a most general unifier is certainly valid, we can also characterize a unifier by other similar properties. For this reason, let us now define an alternative definition called a _reproductive unifier_, and then prove it to be equivalent to our definition of a most general unifier. This will make our proofs easier to formulate down the road as the task of proving a unifier to be reproductive is substantially easier than proving it to be most general directly. *) Definition reproductive_unifier (t : term) (sig : subst) : Prop := unifier t sig /\ forall (tau : subst) (x : var), unifier t tau -> apply_subst (apply_subst (VAR x) sig ) tau == apply_subst (VAR x) tau. (** This is a lemma to show that a reproductive unifier is a most general unifier. Since the ultimate goal is to prove that a specific algorithm produces an mgu then if we could prove it is a reproductive unifier then we could use this lemma to arrive at the desired conclusion. *) Lemma reproductive_is_mgu : forall (t : term) (u : subst), reproductive_unifier t u -> most_general_unifier t u. Proof. intros. unfold most_general_unifier. unfold reproductive_unifier in H. unfold more_general_substitution . destruct H. split. - apply H. - intros. specialize (H0 s'). exists s'. unfold substitution_factor_through. intros. specialize (H0 x). specialize (H0 H1). apply H0. Qed. (** This is a lemma to show that if two terms are equivalent then for any subsitution that is an mgu of one of the terms, then it is an mgu of the other term as well. *) Lemma most_general_unifier_compat : forall (t t' : term), t == t' -> forall (sigma: subst), most_general_unifier t sigma <-> most_general_unifier t' sigma. Proof. intros. split. - intros. unfold most_general_unifier. unfold unifier in H0. unfold unifier in *. split. + unfold most_general_unifier in H0. destruct H0. unfold unifier in H0. rewrite H in H0. apply H0. + intros. unfold most_general_unifier in H0. destruct H0. specialize (H2 s'). unfold unifier in H0. symmetry in H. rewrite H in H1. unfold unifier in H2. specialize (H2 H1). apply H2. - unfold most_general_unifier. intros. destruct H0 . split. + symmetry in H. unfold unifier in H0. rewrite H in H0. unfold unifier. apply H0. + intros. specialize (H1 s'). unfold unifier in H2. rewrite H in H2. unfold unifier in H1. specialize (H1 H2). apply H1. Qed. (** * Auxilliary Computational Operations and Simplifications *) (** These functions below will come in handy later during the Lowenheim formula proof. They mainly lay the groundwork for providing the computational nuts and bolts for Lowenheim's algorithm for finding most general unifiers and initial ground unifiers. *) (* alternate defintion of functions related to term operations and evaluations that take into consideration more sub-cases *) (** This is a function to check if two terms are exaclty identical. *) Fixpoint identical (a b: term) : bool := match a , b with | T0, T0 => true | T0, _ => false | T1 , T1 => true | T1 , _ => false | VAR x , VAR y => if beq_nat x y then true else false | VAR x, _ => false | PRODUCT x y, PRODUCT x1 y1 => identical x x1 && identical y y1 | PRODUCT x y, _ => false | SUM x y, SUM x1 y1 => identical x x1 && identical y y1 | SUM x y, _ => false end. (** This is basic addition for terms. *) Definition plus_one_step (a b : term) : term := match a, b with | T0, T0 => T0 | T0, T1 => T1 | T1, T0 => T1 | T1 , T1 => T0 | _ , _ => SUM a b end. (** This is basic multiplication for terms. *) Definition mult_one_step (a b : term) : term := match a, b with | T0, T0 => T0 | T0, T1 => T0 | T1, T0 => T0 | T1 , T1 => T1 | _ , _ => PRODUCT a b end. (** This is a function to simplify a term in very apparent and basic ways. They are only simplified if they are ground terms. *) Fixpoint simplify (t : term) : term := match t with | T0 => T0 | T1 => T1 | VAR x => VAR x | PRODUCT x y => mult_one_step (simplify x) (simplify y) | SUM x y => plus_one_step (simplify x) (simplify y) end. (** Some lemmas follow to prove intuitive facts for the basic multiplication and addition of terms, leading up to proving the [simplify_eqv] lemma. *) Lemma pos_left_sum_compat : forall (t t1 t2 : term), t == t1 -> plus_one_step t1 t2 == plus_one_step t t2. Proof. intros. induction t1. - induction t. + reflexivity. + apply T1_not_equiv_T0 in H. inversion H. + induction t2. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. - induction t. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. - induction t. + induction t2. * simpl. rewrite H. rewrite sum_x_x. rewrite H. reflexivity. * simpl. rewrite <- H. rewrite sum_id. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite <- H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. - induction t. + induction t2. * simpl. rewrite <- H. rewrite sum_x_x. reflexivity. * simpl. rewrite <- H. rewrite sum_id. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite <- H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. - induction t. + induction t2. * simpl. rewrite <- H. rewrite sum_x_x. reflexivity. * simpl. rewrite <- H. rewrite sum_id. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite <- H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. Qed. Lemma pos_right_sum_compat : forall (t t1 t2 : term), t == t2 -> plus_one_step t1 t2 == plus_one_step t1 t. Proof. intros. induction t1. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. rewrite sum_x_x. apply H. * simpl. rewrite <- H. rewrite sum_x_x. reflexivity. * simpl. rewrite <- H. rewrite sum_x_x. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite <- H. rewrite sum_id. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite <- H. rewrite sum_id. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite <- H. rewrite sum_id. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_id. reflexivity. * simpl. rewrite <- H. rewrite sum_id. reflexivity. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite <- H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite <- H. rewrite sum_comm. rewrite sum_id. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite <- H. rewrite sum_x_x. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. rewrite sum_comm. rewrite sum_id. reflexivity. * simpl. rewrite H. rewrite sum_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. Qed. Lemma pos_left_mul_compat : forall (t t1 t2 : term), t == t1 -> mult_one_step t1 t2 == mult_one_step t t2. Proof. intros. induction t1. - induction t. + reflexivity. + apply T1_not_equiv_T0 in H. inversion H. + induction t2. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. - induction t. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. + induction t2. * simpl. rewrite H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. - induction t. + induction t2. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite <- H. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite <- H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. - induction t. + induction t2. * simpl. rewrite <- H. rewrite mul_x_x. reflexivity. * simpl. rewrite <- H. rewrite mul_T0_x. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite <- H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. - induction t. + induction t2. * simpl. rewrite <- H. rewrite mul_x_x. reflexivity. * simpl. rewrite <- H. rewrite mul_T0_x. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite <- H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. Qed. Lemma pos_right_mul_compat : forall (t t1 t2 : term), t == t2 -> mult_one_step t1 t2 == mult_one_step t1 t. Proof. intros. induction t1. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite <- H. rewrite mul_x_x. reflexivity. * simpl. rewrite <- H. rewrite mul_x_x. reflexivity. + induction t2. * simpl. reflexivity. * simpl. reflexivity. * simpl. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. reflexivity. + induction t2. * simpl. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. + induction t2. * simpl. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. + induction t2. * simpl. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. * simpl. rewrite mul_T0_x. rewrite mul_T0_x. reflexivity. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite <- H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite <- H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite <- H. rewrite mul_x_x. reflexivity. + induction t2. * simpl. rewrite H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. rewrite mul_comm. rewrite mul_T0_x. reflexivity. * simpl. rewrite H. rewrite mul_x_x. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. - induction t. + induction t2. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. + induction t2. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite H. reflexivity. * simpl. rewrite <- H. reflexivity. Qed. (** Being able to simplify a term can be a useful tool. Being able to use the simplified version of the term as the equivalent version of the original term can also be useful since many of our functions simplify the term first. *) Lemma simplify_eqv : forall (t : term), simplify t == t. Proof. intros. induction t. - simpl. reflexivity. - simpl. reflexivity. - simpl. reflexivity. - simpl. pose proof pos_left_sum_compat. specialize (H t1 (simplify t1) (simplify t2)). symmetry in IHt1. specialize (H IHt1). rewrite H. pose proof pos_right_sum_compat. specialize (H0 (simplify t2) t1 t2). specialize (H0 IHt2). symmetry in H0. rewrite H0. induction t1. + induction t2. * simpl. rewrite sum_x_x. reflexivity. * simpl. rewrite sum_id. reflexivity. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. + induction t2. * simpl. rewrite sum_id_sym. reflexivity. * simpl. rewrite sum_x_x. reflexivity. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. + simpl. reflexivity. + simpl. reflexivity. + simpl. reflexivity. - simpl. pose proof pos_left_mul_compat. specialize (H t1 (simplify t1) (simplify t2)). symmetry in IHt1. specialize (H IHt1). rewrite H. pose proof pos_right_mul_compat. specialize (H0 (simplify t2) t1 t2). specialize (H0 IHt2). symmetry in H0. rewrite H0. induction t1. + induction t2. * simpl. rewrite mul_x_x. reflexivity. * simpl. rewrite mul_T0_x. reflexivity. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. + induction t2. * simpl. rewrite mul_T0_x_sym. reflexivity. * simpl. rewrite mul_x_x. reflexivity. * simpl. reflexivity. * simpl. reflexivity. * simpl. reflexivity. + simpl. reflexivity. + simpl. reflexivity. + simpl. reflexivity. Qed.
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison Ported by: E.W.Ayers -/ import Lean import Lean.Data open Lean open Lean.Elab open Lean.Elab.Command /-- __DEPRECATED__: `restate_axiom` was necessary in Lean 3 but is no longer needed for Lean 4. It is still present for backwards compatibility but will probably be removed in the future. # Original Docstring `restate_axiom` makes a new copy of a structure field, first definitionally simplifying the type. This is useful to remove `auto_param` or `opt_param` from the statement. As an example, we have: ```lean structure A := (x : ℕ) (a' : x = 1 . skip) example (z : A) : z.x = 1 := by rw A.a' -- rewrite tactic failed, lemma is not an equality nor a iff restate_axiom A.a' example (z : A) : z.x = 1 := by rw A.a ``` By default, `restate_axiom` names the new lemma by removing a trailing `'`, or otherwise appending `_lemma` if there is no trailing `'`. You can also give `restate_axiom` a second argument to specify the new name, as in ```lean restate_axiom A.a f example (z : A) : z.x = 1 := by rw A.f ``` -/ elab "restate_axiom " oldName:ident newName:optional(ident) : command => do let oldName ← resolveGlobalConstNoOverloadWithInfo oldName let newName : Name := match newName with | none => match oldName with | Name.str n s => if s.back = '\'' then Name.mkStr n $ s.extract 0 (s.endPos - ⟨1⟩) else Name.mkStr n $ s ++ "_lemma" | x => x | some n => Name.getPrefix oldName ++ n.getId liftCoreM do match ← getConstInfo oldName with | ConstantInfo.defnInfo info => addAndCompile <| .defnDecl { info with name := newName } | ConstantInfo.thmInfo info => addAndCompile <| .thmDecl { info with name := newName } | _ => throwError "Constant {oldName} is not a definition or theorem."
theorem test (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p := by apply And.intro . exact hp . apply And.intro . exact hq . exact hp
[GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ 1 ∈ { carrier := {x | ‖x‖ ≤ 1}, mul_mem' := (_ : ∀ {a b : ℚ_[p]}, a ∈ {x | ‖x‖ ≤ 1} → b ∈ {x | ‖x‖ ≤ 1} → ‖a * b‖ ≤ 1) }.carrier [PROOFSTEP] norm_num [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ 0 ∈ { toSubsemigroup := { carrier := {x | ‖x‖ ≤ 1}, mul_mem' := (_ : ∀ {a b : ℚ_[p]}, a ∈ {x | ‖x‖ ≤ 1} → b ∈ {x | ‖x‖ ≤ 1} → ‖a * b‖ ≤ 1) }, one_mem' := (_ : ‖1‖ ≤ 1) }.toSubsemigroup.carrier [PROOFSTEP] norm_num [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ Add { x // x ∈ subring p } [PROOFSTEP] infer_instance [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ Mul { x // x ∈ subring p } [PROOFSTEP] infer_instance [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ Neg { x // x ∈ subring p } [PROOFSTEP] infer_instance [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ Sub { x // x ∈ subring p } [PROOFSTEP] infer_instance [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ Zero { x // x ∈ subring p } [PROOFSTEP] infer_instance [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ ‖1‖ ≤ 1 [PROOFSTEP] norm_num [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z : ℤ_[p] ⊢ ↑z = 0 ↔ z = 0 [PROOFSTEP] rw [← coe_zero, Subtype.coe_inj] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ AddCommGroup { x // x ∈ subring p } [PROOFSTEP] infer_instance [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ CommRing { x // x ∈ subring p } [PROOFSTEP] infer_instance [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖k‖ = 1 ⊢ ‖k⁻¹‖ ≤ 1 [PROOFSTEP] simp [h] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) m n : ℕ h : ↑m = ↑n ⊢ ↑m = ↑n [PROOFSTEP] rw [Subtype.ext_iff] at h [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) m n : ℕ h✝ : ↑m = ↑n h : ↑↑m = ↑↑n ⊢ ↑m = ↑n [PROOFSTEP] norm_cast at h [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z1 z2 : ℤ ⊢ ↑z1 = ↑z2 ↔ z1 = z2 [PROOFSTEP] suffices (z1 : ℚ_[p]) = z2 ↔ z1 = z2 from Iff.trans (by norm_cast) this [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z1 z2 : ℤ this : ↑z1 = ↑z2 ↔ z1 = z2 ⊢ ↑z1 = ↑z2 ↔ ↑z1 = ↑z2 [PROOFSTEP] norm_cast [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z1 z2 : ℤ ⊢ ↑z1 = ↑z2 ↔ z1 = z2 [PROOFSTEP] norm_cast [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) seq : ℕ → ℤ h : IsCauSeq (padicNorm p) fun n => ↑(seq n) ⊢ ↑(PadicSeq.norm { val := fun n => ↑(seq n), property := h }) ≤ 1 [PROOFSTEP] rw [PadicSeq.norm] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) seq : ℕ → ℤ h : IsCauSeq (padicNorm p) fun n => ↑(seq n) ⊢ ↑(if hf : { val := fun n => ↑(seq n), property := h } ≈ 0 then 0 else padicNorm p (↑{ val := fun n => ↑(seq n), property := h } (PadicSeq.stationaryPoint hf))) ≤ 1 [PROOFSTEP] split_ifs with hne [GOAL] case pos p : ℕ inst✝ : Fact (Nat.Prime p) seq : ℕ → ℤ h : IsCauSeq (padicNorm p) fun n => ↑(seq n) hne : { val := fun n => ↑(seq n), property := h } ≈ 0 ⊢ ↑0 ≤ 1 [PROOFSTEP] norm_cast [GOAL] case neg p : ℕ inst✝ : Fact (Nat.Prime p) seq : ℕ → ℤ h : IsCauSeq (padicNorm p) fun n => ↑(seq n) hne : ¬{ val := fun n => ↑(seq n), property := h } ≈ 0 ⊢ ↑(padicNorm p (↑{ val := fun n => ↑(seq n), property := h } (PadicSeq.stationaryPoint hne))) ≤ 1 [PROOFSTEP] norm_cast [GOAL] case neg p : ℕ inst✝ : Fact (Nat.Prime p) seq : ℕ → ℤ h : IsCauSeq (padicNorm p) fun n => ↑(seq n) hne : ¬{ val := fun n => ↑(seq n), property := h } ≈ 0 ⊢ padicNorm p (↑{ val := fun n => ↑(seq n), property := h } (PadicSeq.stationaryPoint hne)) ≤ 1 [PROOFSTEP] apply padicNorm.of_int [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) src✝ : CommRing ℤ_[p] := instCommRing ⊢ ∀ (a b : ℤ_[p]), ‖a * b‖ ≤ ‖a‖ * ‖b‖ [PROOFSTEP] simp [norm_def] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) ⊢ ∀ {x : ℤ_[p]}, ‖x‖ = 0 ↔ x = 0 [PROOFSTEP] simp [norm_eq_zero] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) x✝¹ x✝ : ℤ_[p] ⊢ ‖x✝¹ * x✝‖ = ‖x✝¹‖ * ‖x✝‖ [PROOFSTEP] simp only [norm_def, padicNormE.mul, PadicInt.coe_mul] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z1 z2 : ℤ_[p] ⊢ ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ [PROOFSTEP] simp [norm_def] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z : ℤ_[p] ⊢ ‖z ^ 0‖ = ‖z‖ ^ 0 [PROOFSTEP] simp [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z : ℤ_[p] k : ℕ ⊢ ‖z ^ (k + 1)‖ = ‖z‖ ^ (k + 1) [PROOFSTEP] rw [pow_succ, pow_succ, norm_mul] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z : ℤ_[p] k : ℕ ⊢ ‖z‖ * ‖z ^ k‖ = ‖z‖ * ‖z‖ ^ k [PROOFSTEP] congr [GOAL] case e_a p : ℕ inst✝ : Fact (Nat.Prime p) z : ℤ_[p] k : ℕ ⊢ ‖z ^ k‖ = ‖z‖ ^ k [PROOFSTEP] apply norm_pow [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z1 z2 : ℤ_[p] h : ‖z1 + z2‖ < ‖z2‖ hne : ¬‖z1‖ = ‖z2‖ ⊢ ‖z1 + z2‖ ≥ ‖z2‖ [PROOFSTEP] rw [norm_add_eq_max_of_ne hne] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z1 z2 : ℤ_[p] h : ‖z1 + z2‖ < ‖z2‖ hne : ¬‖z1‖ = ‖z2‖ ⊢ max ‖z1‖ ‖z2‖ ≥ ‖z2‖ [PROOFSTEP] apply le_max_right [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z1 z2 : ℤ_[p] h : ‖z1 + z2‖ < ‖z1‖ hne : ¬‖z1‖ = ‖z2‖ ⊢ ‖z1 + z2‖ ≥ ‖z1‖ [PROOFSTEP] rw [norm_add_eq_max_of_ne hne] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z1 z2 : ℤ_[p] h : ‖z1 + z2‖ < ‖z1‖ hne : ¬‖z1‖ = ‖z2‖ ⊢ max ‖z1‖ ‖z2‖ ≥ ‖z1‖ [PROOFSTEP] apply le_max_left [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z : ℤ_[p] ⊢ ‖↑z‖ = ‖z‖ [PROOFSTEP] simp [norm_def] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) z : ℤ ⊢ ‖↑z‖ = ‖↑z‖ [PROOFSTEP] simp [norm_def] [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) f : CauSeq ℤ_[p] norm x✝ : ℝ hε : x✝ > 0 ⊢ ∃ i, ∀ (j : ℕ), j ≥ i → (fun a => ‖a‖) ((fun n => ↑(↑f n)) j - (fun n => ↑(↑f n)) i) < x✝ [PROOFSTEP] simpa [norm, norm_def] using f.cauchy hε [GOAL] p : ℕ inst✝ : Fact (Nat.Prime p) f : CauSeq ℤ_[p] norm hqn : ‖CauSeq.lim (PadicInt.cauSeq_to_rat_cauSeq f)‖ ≤ 1 ε : ℝ ⊢ ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖↑(f - CauSeq.const norm { val := CauSeq.lim (PadicInt.cauSeq_to_rat_cauSeq f), property := hqn }) j‖ < ε [PROOFSTEP] simpa [norm, norm_def] using CauSeq.equiv_lim (cauSeq_to_rat_cauSeq f) ε [GOAL] p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε ⊢ ∃ k, ↑p ^ (-↑k) < ε [PROOFSTEP] obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹ [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ ∃ k, ↑p ^ (-↑k) < ε [PROOFSTEP] use k [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ ↑p ^ (-↑k) < ε [PROOFSTEP] rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)] [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ ε⁻¹ < (↑p ^ (-↑k))⁻¹ [PROOFSTEP] rw [zpow_neg, inv_inv, zpow_ofNat] [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ ε⁻¹ < ↑p ^ k [PROOFSTEP] apply lt_of_lt_of_le hk [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ ↑k ≤ ↑p ^ k [PROOFSTEP] norm_cast [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ k ≤ p ^ k [PROOFSTEP] apply le_of_lt [GOAL] case h.a p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ k < p ^ k [PROOFSTEP] convert Nat.lt_pow_self _ _ using 1 [GOAL] case h.a.convert_2 p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ 1 < p [PROOFSTEP] exact hp.1.one_lt [GOAL] p : ℕ hp : Fact (Nat.Prime p) ε : ℝ hε : 0 < ε k : ℕ hk : ε⁻¹ < ↑k ⊢ 0 < ↑p [PROOFSTEP] exact_mod_cast hp.1.pos [GOAL] p : ℕ hp : Fact (Nat.Prime p) ε : ℚ hε : 0 < ε ⊢ ∃ k, ↑p ^ (-↑k) < ε [PROOFSTEP] obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (by exact_mod_cast hε) [GOAL] p : ℕ hp : Fact (Nat.Prime p) ε : ℚ hε : 0 < ε ⊢ 0 < ↑ε [PROOFSTEP] exact_mod_cast hε [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) ε : ℚ hε : 0 < ε k : ℕ hk : ↑p ^ (-↑k) < ↑ε ⊢ ∃ k, ↑p ^ (-↑k) < ε [PROOFSTEP] use k [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) ε : ℚ hε : 0 < ε k : ℕ hk : ↑p ^ (-↑k) < ↑ε ⊢ ↑p ^ (-↑k) < ε [PROOFSTEP] rw [show (p : ℝ) = (p : ℚ) by simp] at hk [GOAL] p : ℕ hp : Fact (Nat.Prime p) ε : ℚ hε : 0 < ε k : ℕ hk : ↑p ^ (-↑k) < ↑ε ⊢ ↑p = ↑↑p [PROOFSTEP] simp [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) ε : ℚ hε : 0 < ε k : ℕ hk : ↑↑p ^ (-↑k) < ↑ε ⊢ ↑p ^ (-↑k) < ε [PROOFSTEP] exact_mod_cast hk [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℤ this : ‖↑k‖ < 1 ↔ ↑p ∣ k ⊢ ‖↑k‖ < 1 ↔ ↑p ∣ k [PROOFSTEP] rwa [norm_int_cast_eq_padic_norm] [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℤ n : ℕ this : ‖↑k‖ ≤ ↑p ^ (-↑n) ↔ ↑(p ^ n) ∣ k ⊢ ‖↑k‖ ≤ ↑p ^ (-↑n) ↔ ↑(p ^ n) ∣ k [PROOFSTEP] simpa [norm_int_cast_eq_padic_norm] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ ‖x‖ = ↑p ^ (-valuation x) [PROOFSTEP] refine @Padic.norm_eq_pow_val p hp x ?_ [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ ↑x ≠ 0 [PROOFSTEP] contrapose! hx [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : ↑x = 0 ⊢ x = 0 [PROOFSTEP] exact Subtype.val_injective hx [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ valuation ↑p = 1 [PROOFSTEP] simp [valuation] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] ⊢ 0 ≤ valuation x [PROOFSTEP] by_cases hx : x = 0 [GOAL] case pos p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x = 0 ⊢ 0 ≤ valuation x [PROOFSTEP] simp [hx] [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : ¬x = 0 ⊢ 0 ≤ valuation x [PROOFSTEP] have h : (1 : ℝ) < p := by exact_mod_cast hp.1.one_lt [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : ¬x = 0 ⊢ 1 < ↑p [PROOFSTEP] exact_mod_cast hp.1.one_lt [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : ¬x = 0 h : 1 < ↑p ⊢ 0 ≤ valuation x [PROOFSTEP] rw [← neg_nonpos, ← (zpow_strictMono h).le_iff_le] [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : ¬x = 0 h : 1 < ↑p ⊢ (fun x x_1 => x ^ x_1) (↑p) (-valuation x) ≤ (fun x x_1 => x ^ x_1) (↑p) 0 [PROOFSTEP] show (p : ℝ) ^ (-valuation x) ≤ (p : ℝ) ^ (0 : ℤ) [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : ¬x = 0 h : 1 < ↑p ⊢ ↑p ^ (-valuation x) ≤ ↑p ^ 0 [PROOFSTEP] rw [← norm_eq_pow_val hx] [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : ¬x = 0 h : 1 < ↑p ⊢ ‖x‖ ≤ ↑p ^ 0 [PROOFSTEP] simpa using x.property [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hc : c ≠ 0 ⊢ valuation (↑p ^ n * c) = ↑n + valuation c [PROOFSTEP] have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _ [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hc : c ≠ 0 this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖ ⊢ valuation (↑p ^ n * c) = ↑n + valuation c [PROOFSTEP] have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by contrapose! hc rw [mul_eq_zero] at hc cases' hc with hc hc · refine (hp.1.ne_zero ?_).elim exact_mod_cast pow_eq_zero hc · exact hc [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hc : c ≠ 0 this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖ ⊢ ↑p ^ n * c ≠ 0 [PROOFSTEP] contrapose! hc [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖ hc : ↑p ^ n * c = 0 ⊢ c = 0 [PROOFSTEP] rw [mul_eq_zero] at hc [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖ hc : ↑p ^ n = 0 ∨ c = 0 ⊢ c = 0 [PROOFSTEP] cases' hc with hc hc [GOAL] case inl p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖ hc : ↑p ^ n = 0 ⊢ c = 0 [PROOFSTEP] refine (hp.1.ne_zero ?_).elim [GOAL] case inl p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖ hc : ↑p ^ n = 0 ⊢ p = 0 [PROOFSTEP] exact_mod_cast pow_eq_zero hc [GOAL] case inr p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖ hc : c = 0 ⊢ c = 0 [PROOFSTEP] exact hc [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hc : c ≠ 0 this : ‖↑p ^ n * c‖ = ‖↑p ^ n‖ * ‖c‖ aux : ↑p ^ n * c ≠ 0 ⊢ valuation (↑p ^ n * c) = ↑n + valuation c [PROOFSTEP] rwa [norm_eq_pow_val aux, norm_p_pow, norm_eq_pow_val hc, ← zpow_add₀, ← neg_add, zpow_inj, neg_inj] at this [GOAL] case h₀ p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hc : c ≠ 0 this : ↑p ^ (-valuation (↑p ^ n * c)) = ↑p ^ (-(↑n + valuation c)) aux : ↑p ^ n * c ≠ 0 ⊢ 0 < ↑p [PROOFSTEP] exact_mod_cast hp.1.pos [GOAL] case h₁ p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hc : c ≠ 0 this : ↑p ^ (-valuation (↑p ^ n * c)) = ↑p ^ (-(↑n + valuation c)) aux : ↑p ^ n * c ≠ 0 ⊢ ↑p ≠ 1 [PROOFSTEP] exact_mod_cast hp.1.ne_one [GOAL] case ha p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hc : c ≠ 0 this : ↑p ^ (-valuation (↑p ^ n * c)) = ↑p ^ (-↑n) * ↑p ^ (-valuation c) aux : ↑p ^ n * c ≠ 0 ⊢ ↑p ≠ 0 [PROOFSTEP] exact_mod_cast hp.1.ne_zero [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖{ val := k, property := property✝ }‖ = 1 ⊢ { val := k, property := property✝ } * inv { val := k, property := property✝ } = 1 [PROOFSTEP] have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h ) [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖{ val := k, property := property✝ }‖ = 1 h' : k = 0 ⊢ 0 = 1 [PROOFSTEP] simp [h'] at h [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖{ val := k, property := property✝ }‖ = 1 hk : k ≠ 0 ⊢ { val := k, property := property✝ } * inv { val := k, property := property✝ } = 1 [PROOFSTEP] unfold PadicInt.inv [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖{ val := k, property := property✝ }‖ = 1 hk : k ≠ 0 ⊢ ({ val := k, property := property✝ } * match { val := k, property := property✝ } with | { val := k, property := property } => if h : ‖k‖ = 1 then { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) } else 0) = 1 [PROOFSTEP] rw [norm_eq_padic_norm] at h [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖k‖ = 1 hk : k ≠ 0 ⊢ ({ val := k, property := property✝ } * match { val := k, property := property✝ } with | { val := k, property := property } => if h : ‖k‖ = 1 then { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) } else 0) = 1 [PROOFSTEP] dsimp only [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖k‖ = 1 hk : k ≠ 0 ⊢ ({ val := k, property := property✝ } * if h : ‖k‖ = 1 then { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) } else 0) = 1 [PROOFSTEP] rw [dif_pos h] [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖k‖ = 1 hk : k ≠ 0 ⊢ { val := k, property := property✝ } * { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) } = 1 [PROOFSTEP] apply Subtype.ext_iff_val.2 [GOAL] p : ℕ hp : Fact (Nat.Prime p) k : ℚ_[p] property✝ : ‖k‖ ≤ 1 h : ‖k‖ = 1 hk : k ≠ 0 ⊢ ↑({ val := k, property := property✝ } * { val := k⁻¹, property := (_ : ‖k⁻¹‖ ≤ 1) }) = ↑1 [PROOFSTEP] simp [mul_inv_cancel hk] [GOAL] p : ℕ hp : Fact (Nat.Prime p) z : ℤ_[p] hz : ‖z‖ = 1 ⊢ inv z * z = 1 [PROOFSTEP] rw [mul_comm, mul_inv hz] [GOAL] p : ℕ hp : Fact (Nat.Prime p) z : ℤ_[p] h : IsUnit z ⊢ ‖z‖ = 1 [PROOFSTEP] rcases isUnit_iff_dvd_one.1 h with ⟨w, eq⟩ [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) z : ℤ_[p] h : IsUnit z w : ℤ_[p] eq : 1 = z * w ⊢ ‖z‖ = 1 [PROOFSTEP] refine' le_antisymm (norm_le_one _) _ [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) z : ℤ_[p] h : IsUnit z w : ℤ_[p] eq : 1 = z * w ⊢ 1 ≤ ‖z‖ [PROOFSTEP] have := mul_le_mul_of_nonneg_left (norm_le_one w) (norm_nonneg z) [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) z : ℤ_[p] h : IsUnit z w : ℤ_[p] eq : 1 = z * w this : ‖z‖ * ‖w‖ ≤ ‖z‖ * 1 ⊢ 1 ≤ ‖z‖ [PROOFSTEP] rwa [mul_one, ← norm_mul, ← eq, norm_one] at this [GOAL] p : ℕ hp : Fact (Nat.Prime p) z1 z2 : ℤ_[p] hz2 : ‖z2‖ < 1 ⊢ ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ [PROOFSTEP] simp [GOAL] p : ℕ hp : Fact (Nat.Prime p) z : ℤ_[p] ⊢ z ∈ nonunits ℤ_[p] ↔ ‖z‖ < 1 [PROOFSTEP] rw [lt_iff_le_and_ne] [GOAL] p : ℕ hp : Fact (Nat.Prime p) z : ℤ_[p] ⊢ z ∈ nonunits ℤ_[p] ↔ ‖z‖ ≤ 1 ∧ ‖z‖ ≠ 1 [PROOFSTEP] simp [norm_le_one z, nonunits, isUnit_iff] [GOAL] p : ℕ hp : Fact (Nat.Prime p) u : ℤ_[p]ˣ ⊢ IsUnit ↑u [PROOFSTEP] simp [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 u : ℚ_[p] := ↑x * ↑p ^ (-valuation x) ⊢ ‖u‖ = 1 [PROOFSTEP] simp [hx, Nat.zpow_ne_zero_of_pos (by exact_mod_cast hp.1.pos) x.valuation, norm_eq_pow_val, zpow_neg, inv_mul_cancel] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 u : ℚ_[p] := ↑x * ↑p ^ (-valuation x) ⊢ 0 < ?m.493673 [PROOFSTEP] exact_mod_cast hp.1.pos [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ x = ↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x) [PROOFSTEP] apply Subtype.coe_injective [GOAL] case a p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ (fun a => ↑a) x = (fun a => ↑a) (↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x)) [PROOFSTEP] push_cast [GOAL] case a p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ ↑x = ↑↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x) [PROOFSTEP] have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by rw [unitCoeff_coe, mul_assoc, ← zpow_add₀] · simp · exact_mod_cast hp.1.ne_zero [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ ↑x = ↑↑(unitCoeff hx) * ↑p ^ valuation x [PROOFSTEP] rw [unitCoeff_coe, mul_assoc, ← zpow_add₀] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ ↑x = ↑x * ↑p ^ (-valuation x + valuation x) [PROOFSTEP] simp [GOAL] case ha p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ ↑p ≠ 0 [PROOFSTEP] exact_mod_cast hp.1.ne_zero [GOAL] case a p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 repr : ↑x = ↑↑(unitCoeff hx) * ↑p ^ valuation x ⊢ ↑x = ↑↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x) [PROOFSTEP] convert repr using 2 [GOAL] case h.e'_3.h.e'_6 p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 repr : ↑x = ↑↑(unitCoeff hx) * ↑p ^ valuation x ⊢ ↑p ^ Int.natAbs (valuation x) = ↑p ^ valuation x [PROOFSTEP] rw [← zpow_ofNat, Int.natAbs_of_nonneg (valuation_nonneg x)] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n : ℕ ⊢ ‖x‖ ≤ ↑p ^ (-↑n) ↔ ↑n ≤ valuation x [PROOFSTEP] rw [norm_eq_pow_val hx] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n : ℕ ⊢ ↑p ^ (-valuation x) ≤ ↑p ^ (-↑n) ↔ ↑n ≤ valuation x [PROOFSTEP] lift x.valuation to ℕ using x.valuation_nonneg with k [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ ⊢ ↑p ^ (-↑k) ≤ ↑p ^ (-↑n) ↔ ↑n ≤ ↑k [PROOFSTEP] simp only [Int.ofNat_le, zpow_neg, zpow_ofNat] [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ ⊢ (↑p ^ k)⁻¹ ≤ (↑p ^ n)⁻¹ ↔ n ≤ k [PROOFSTEP] have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by intro m refine pow_pos ?_ m exact_mod_cast hp.1.pos [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ ⊢ ∀ (m : ℕ), 0 < ↑p ^ m [PROOFSTEP] intro m [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k m : ℕ ⊢ 0 < ↑p ^ m [PROOFSTEP] refine pow_pos ?_ m [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k m : ℕ ⊢ 0 < ↑p [PROOFSTEP] exact_mod_cast hp.1.pos [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ aux : ∀ (m : ℕ), 0 < ↑p ^ m ⊢ (↑p ^ k)⁻¹ ≤ (↑p ^ n)⁻¹ ↔ n ≤ k [PROOFSTEP] rw [inv_le_inv (aux _) (aux _)] [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ aux : ∀ (m : ℕ), 0 < ↑p ^ m ⊢ ↑p ^ n ≤ ↑p ^ k ↔ n ≤ k [PROOFSTEP] have : p ^ n ≤ p ^ k ↔ n ≤ k := (pow_strictMono_right hp.1.one_lt).le_iff_le [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ aux : ∀ (m : ℕ), 0 < ↑p ^ m this : p ^ n ≤ p ^ k ↔ n ≤ k ⊢ ↑p ^ n ≤ ↑p ^ k ↔ n ≤ k [PROOFSTEP] rw [← this] [GOAL] case intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ aux : ∀ (m : ℕ), 0 < ↑p ^ m this : p ^ n ≤ p ^ k ↔ n ≤ k ⊢ ↑p ^ n ≤ ↑p ^ k ↔ p ^ n ≤ p ^ k [PROOFSTEP] norm_cast [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n : ℕ ⊢ x ∈ Ideal.span {↑p ^ n} ↔ ↑n ≤ valuation x [PROOFSTEP] rw [Ideal.mem_span_singleton] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n : ℕ ⊢ ↑p ^ n ∣ x ↔ ↑n ≤ valuation x [PROOFSTEP] constructor [GOAL] case mp p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n : ℕ ⊢ ↑p ^ n ∣ x → ↑n ≤ valuation x [PROOFSTEP] rintro ⟨c, rfl⟩ [GOAL] case mp.intro p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hx : ↑p ^ n * c ≠ 0 ⊢ ↑n ≤ valuation (↑p ^ n * c) [PROOFSTEP] suffices c ≠ 0 by rw [valuation_p_pow_mul _ _ this, le_add_iff_nonneg_right] apply valuation_nonneg [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hx : ↑p ^ n * c ≠ 0 this : c ≠ 0 ⊢ ↑n ≤ valuation (↑p ^ n * c) [PROOFSTEP] rw [valuation_p_pow_mul _ _ this, le_add_iff_nonneg_right] [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hx : ↑p ^ n * c ≠ 0 this : c ≠ 0 ⊢ 0 ≤ valuation c [PROOFSTEP] apply valuation_nonneg [GOAL] case mp.intro p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hx : ↑p ^ n * c ≠ 0 ⊢ c ≠ 0 [PROOFSTEP] contrapose! hx [GOAL] case mp.intro p : ℕ hp : Fact (Nat.Prime p) n : ℕ c : ℤ_[p] hx : c = 0 ⊢ ↑p ^ n * c = 0 [PROOFSTEP] rw [hx, mul_zero] [GOAL] case mpr p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n : ℕ ⊢ ↑n ≤ valuation x → ↑p ^ n ∣ x [PROOFSTEP] nth_rewrite 2 [unitCoeff_spec hx] [GOAL] case mpr p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n : ℕ ⊢ ↑n ≤ valuation x → ↑p ^ n ∣ ↑(unitCoeff hx) * ↑p ^ Int.natAbs (valuation x) [PROOFSTEP] lift x.valuation to ℕ using x.valuation_nonneg with k [GOAL] case mpr.intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ ⊢ ↑n ≤ ↑k → ↑p ^ n ∣ ↑(unitCoeff hx) * ↑p ^ Int.natAbs ↑k [PROOFSTEP] simp only [Int.natAbs_ofNat, Units.isUnit, IsUnit.dvd_mul_left, Int.ofNat_le] [GOAL] case mpr.intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ ⊢ n ≤ k → ↑p ^ n ∣ ↑p ^ k [PROOFSTEP] intro H [GOAL] case mpr.intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ H : n ≤ k ⊢ ↑p ^ n ∣ ↑p ^ k [PROOFSTEP] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le H [GOAL] case mpr.intro.intro p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 n k : ℕ H : n ≤ n + k ⊢ ↑p ^ n ∣ ↑p ^ (n + k) [PROOFSTEP] simp only [pow_add, dvd_mul_right] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] n : ℕ ⊢ ‖x‖ ≤ ↑p ^ (-↑n) ↔ x ∈ Ideal.span {↑p ^ n} [PROOFSTEP] by_cases hx : x = 0 [GOAL] case pos p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] n : ℕ hx : x = 0 ⊢ ‖x‖ ≤ ↑p ^ (-↑n) ↔ x ∈ Ideal.span {↑p ^ n} [PROOFSTEP] subst hx [GOAL] case pos p : ℕ hp : Fact (Nat.Prime p) n : ℕ ⊢ ‖0‖ ≤ ↑p ^ (-↑n) ↔ 0 ∈ Ideal.span {↑p ^ n} [PROOFSTEP] simp only [norm_zero, zpow_neg, zpow_ofNat, inv_nonneg, iff_true_iff, Submodule.zero_mem] [GOAL] case pos p : ℕ hp : Fact (Nat.Prime p) n : ℕ ⊢ 0 ≤ ↑p ^ n [PROOFSTEP] exact_mod_cast Nat.zero_le _ [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] n : ℕ hx : ¬x = 0 ⊢ ‖x‖ ≤ ↑p ^ (-↑n) ↔ x ∈ Ideal.span {↑p ^ n} [PROOFSTEP] rw [norm_le_pow_iff_le_valuation x hx, mem_span_pow_iff_le_valuation x hx] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] n : ℤ ⊢ ‖x‖ ≤ ↑p ^ n ↔ ‖x‖ < ↑p ^ (n + 1) [PROOFSTEP] rw [norm_def] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] n : ℤ ⊢ ‖↑x‖ ≤ ↑p ^ n ↔ ‖↑x‖ < ↑p ^ (n + 1) [PROOFSTEP] exact Padic.norm_le_pow_iff_norm_lt_pow_add_one _ _ [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] n : ℤ ⊢ ‖x‖ < ↑p ^ n ↔ ‖x‖ ≤ ↑p ^ (n - 1) [PROOFSTEP] rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] ⊢ ‖x‖ < 1 ↔ ↑p ∣ x [PROOFSTEP] have := norm_le_pow_iff_mem_span_pow x 1 [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] this : ‖x‖ ≤ ↑p ^ (-↑1) ↔ x ∈ Ideal.span {↑p ^ 1} ⊢ ‖x‖ < 1 ↔ ↑p ∣ x [PROOFSTEP] rw [Ideal.mem_span_singleton, pow_one] at this [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] this : ‖x‖ ≤ ↑p ^ (-↑1) ↔ ↑p ∣ x ⊢ ‖x‖ < 1 ↔ ↑p ∣ x [PROOFSTEP] rw [← this, norm_le_pow_iff_norm_lt_pow_add_one] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] this : ‖x‖ ≤ ↑p ^ (-↑1) ↔ ↑p ∣ x ⊢ ‖x‖ < 1 ↔ ‖x‖ < ↑p ^ (-↑1 + 1) [PROOFSTEP] simp only [zpow_zero, Int.ofNat_zero, Int.ofNat_succ, add_left_neg, zero_add] [GOAL] p : ℕ hp : Fact (Nat.Prime p) n : ℕ a : ℤ ⊢ ↑p ^ n ∣ ↑a ↔ ↑(p ^ n) ∣ a [PROOFSTEP] rw [← Nat.cast_pow, ← norm_int_le_pow_iff_dvd, norm_le_pow_iff_mem_span_pow, Ideal.mem_span_singleton, Nat.cast_pow] [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ ∀ (a b : ℤ_[p]), a ∈ nonunits ℤ_[p] → b ∈ nonunits ℤ_[p] → a + b ∈ nonunits ℤ_[p] [PROOFSTEP] simp only [mem_nonunits] [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ ∀ (a b : ℤ_[p]), ‖a‖ < 1 → ‖b‖ < 1 → ‖a + b‖ < 1 [PROOFSTEP] exact fun x y => norm_lt_one_add [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ ↑p ∈ nonunits ℤ_[p] [PROOFSTEP] have : (p : ℝ)⁻¹ < 1 := inv_lt_one <| by exact_mod_cast hp.1.one_lt [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ 1 < ↑p [PROOFSTEP] exact_mod_cast hp.1.one_lt [GOAL] p : ℕ hp : Fact (Nat.Prime p) this : (↑p)⁻¹ < 1 ⊢ ↑p ∈ nonunits ℤ_[p] [PROOFSTEP] rwa [← norm_p, ← mem_nonunits] at this [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ maximalIdeal ℤ_[p] = Ideal.span {↑p} [PROOFSTEP] apply le_antisymm [GOAL] case a p : ℕ hp : Fact (Nat.Prime p) ⊢ maximalIdeal ℤ_[p] ≤ Ideal.span {↑p} [PROOFSTEP] intro x hx [GOAL] case a p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ∈ maximalIdeal ℤ_[p] ⊢ x ∈ Ideal.span {↑p} [PROOFSTEP] simp only [LocalRing.mem_maximalIdeal, mem_nonunits] at hx [GOAL] case a p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : ‖x‖ < 1 ⊢ x ∈ Ideal.span {↑p} [PROOFSTEP] rwa [Ideal.mem_span_singleton, ← norm_lt_one_iff_dvd] [GOAL] case a p : ℕ hp : Fact (Nat.Prime p) ⊢ Ideal.span {↑p} ≤ maximalIdeal ℤ_[p] [PROOFSTEP] rw [Ideal.span_le, Set.singleton_subset_iff] [GOAL] case a p : ℕ hp : Fact (Nat.Prime p) ⊢ ↑p ∈ ↑(maximalIdeal ℤ_[p]) [PROOFSTEP] exact p_nonnunit [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ Prime ↑p [PROOFSTEP] rw [← Ideal.span_singleton_prime, ← maximalIdeal_eq_span_p] [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ Ideal.IsPrime (maximalIdeal ℤ_[p]) [PROOFSTEP] infer_instance [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ ↑p ≠ 0 [PROOFSTEP] exact_mod_cast hp.1.ne_zero [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℤ_[p] hx : x ≠ 0 ⊢ ↑p ^ Int.natAbs (valuation x) * ↑(unitCoeff hx) = x [PROOFSTEP] rw [mul_comm, ← unitCoeff_spec hx] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → x m ≡ x n [SMOD maximalIdeal ℤ_[p] ^ m • ⊤] ⊢ ∃ L, ∀ (n : ℕ), x n ≡ L [SMOD maximalIdeal ℤ_[p] ^ n • ⊤] [PROOFSTEP] simp only [← Ideal.one_eq_top, smul_eq_mul, mul_one, SModEq.sub_mem, maximalIdeal_eq_span_p, Ideal.span_singleton_pow, ← norm_le_pow_iff_mem_span_pow] at hx ⊢ [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) ⊢ ∃ L, ∀ (n : ℕ), ‖x n - L‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] let x' : CauSeq ℤ_[p] norm := ⟨x, ?_⟩ [GOAL] case refine_2 p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := ?refine_1 } ⊢ ∃ L, ∀ (n : ℕ), ‖x n - L‖ ≤ ↑p ^ (-↑n) case refine_1 p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) ⊢ IsCauSeq norm x [PROOFSTEP] swap [GOAL] case refine_1 p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) ⊢ IsCauSeq norm x [PROOFSTEP] intro ε hε [GOAL] case refine_1 p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) ε : ℝ hε : ε > 0 ⊢ ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε [PROOFSTEP] obtain ⟨m, hm⟩ := exists_pow_neg_lt p hε [GOAL] case refine_1.intro p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) ε : ℝ hε : ε > 0 m : ℕ hm : ↑p ^ (-↑m) < ε ⊢ ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε [PROOFSTEP] refine ⟨m, fun n hn => lt_of_le_of_lt ?_ hm⟩ [GOAL] case refine_1.intro p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) ε : ℝ hε : ε > 0 m : ℕ hm : ↑p ^ (-↑m) < ε n : ℕ hn : n ≥ m ⊢ ‖x n - x m‖ ≤ ↑p ^ (-↑m) [PROOFSTEP] rw [← neg_sub, norm_neg] [GOAL] case refine_1.intro p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) ε : ℝ hε : ε > 0 m : ℕ hm : ↑p ^ (-↑m) < ε n : ℕ hn : n ≥ m ⊢ ‖x m - x n‖ ≤ ↑p ^ (-↑m) [PROOFSTEP] exact hx hn [GOAL] case refine_2 p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } ⊢ ∃ L, ∀ (n : ℕ), ‖x n - L‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] refine ⟨x'.lim, fun n => ?_⟩ [GOAL] case refine_2 p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] have : (0 : ℝ) < (p : ℝ) ^ (-n : ℤ) := by apply zpow_pos_of_pos exact_mod_cast hp.1.pos [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ ⊢ 0 < ↑p ^ (-↑n) [PROOFSTEP] apply zpow_pos_of_pos [GOAL] case ha p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ ⊢ 0 < ↑p [PROOFSTEP] exact_mod_cast hp.1.pos [GOAL] case refine_2 p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this : 0 < ↑p ^ (-↑n) ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] obtain ⟨i, hi⟩ := equiv_def₃ (equiv_lim x') this [GOAL] case refine_2.intro p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this : 0 < ↑p ^ (-↑n) i : ℕ hi : ∀ (j : ℕ), j ≥ i → ∀ (k : ℕ), k ≥ j → ‖↑x' k - ↑(const norm (CauSeq.lim x')) j‖ < ↑p ^ (-↑n) ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] by_cases hin : i ≤ n [GOAL] case pos p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this : 0 < ↑p ^ (-↑n) i : ℕ hi : ∀ (j : ℕ), j ≥ i → ∀ (k : ℕ), k ≥ j → ‖↑x' k - ↑(const norm (CauSeq.lim x')) j‖ < ↑p ^ (-↑n) hin : i ≤ n ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] exact (hi i le_rfl n hin).le [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this : 0 < ↑p ^ (-↑n) i : ℕ hi : ∀ (j : ℕ), j ≥ i → ∀ (k : ℕ), k ≥ j → ‖↑x' k - ↑(const norm (CauSeq.lim x')) j‖ < ↑p ^ (-↑n) hin : ¬i ≤ n ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] push_neg at hin [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this : 0 < ↑p ^ (-↑n) i : ℕ hi : ∀ (j : ℕ), j ≥ i → ∀ (k : ℕ), k ≥ j → ‖↑x' k - ↑(const norm (CauSeq.lim x')) j‖ < ↑p ^ (-↑n) hin : n < i ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] specialize hi i le_rfl i le_rfl [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this : 0 < ↑p ^ (-↑n) i : ℕ hin : n < i hi : ‖↑x' i - ↑(const norm (CauSeq.lim x')) i‖ < ↑p ^ (-↑n) ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] specialize hx hin.le [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx✝ : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this : 0 < ↑p ^ (-↑n) i : ℕ hin : n < i hi : ‖↑x' i - ↑(const norm (CauSeq.lim x')) i‖ < ↑p ^ (-↑n) hx : ‖x n - x i‖ ≤ ↑p ^ (-↑n) ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] have := nonarchimedean (x n - x i : ℤ_[p]) (x i - x'.lim) [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx✝ : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this✝ : 0 < ↑p ^ (-↑n) i : ℕ hin : n < i hi : ‖↑x' i - ↑(const norm (CauSeq.lim x')) i‖ < ↑p ^ (-↑n) hx : ‖x n - x i‖ ≤ ↑p ^ (-↑n) this : ‖x n - x i + (x i - CauSeq.lim x')‖ ≤ max ‖x n - x i‖ ‖x i - CauSeq.lim x'‖ ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] rw [sub_add_sub_cancel] at this [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℕ → ℤ_[p] hx✝ : ∀ {m n : ℕ}, m ≤ n → ‖x m - x n‖ ≤ ↑p ^ (-↑m) x' : CauSeq ℤ_[p] norm := { val := x, property := (_ : ∀ (ε : ℝ), ε > 0 → ∃ i, ∀ (j : ℕ), j ≥ i → ‖x j - x i‖ < ε) } n : ℕ this✝ : 0 < ↑p ^ (-↑n) i : ℕ hin : n < i hi : ‖↑x' i - ↑(const norm (CauSeq.lim x')) i‖ < ↑p ^ (-↑n) hx : ‖x n - x i‖ ≤ ↑p ^ (-↑n) this : ‖x n - CauSeq.lim x'‖ ≤ max ‖x n - x i‖ ‖x i - CauSeq.lim x'‖ ⊢ ‖x n - CauSeq.lim x'‖ ≤ ↑p ^ (-↑n) [PROOFSTEP] refine' this.trans (max_le_iff.mpr ⟨hx, hi.le⟩) [GOAL] p : ℕ hp : Fact (Nat.Prime p) x✝ : { x // x ∈ nonZeroDivisors ℤ_[p] } x : ℤ_[p] hx : x ∈ nonZeroDivisors ℤ_[p] ⊢ IsUnit (↑(algebraMap ℤ_[p] ℚ_[p]) ↑{ val := x, property := hx }) [PROOFSTEP] rwa [algebraMap_apply, isUnit_iff_ne_zero, PadicInt.coe_ne_zero, ← mem_nonZeroDivisors_iff_ne_zero] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] ⊢ ∃ x_1, x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑x_1.snd = ↑(algebraMap ℤ_[p] ℚ_[p]) x_1.fst [PROOFSTEP] by_cases hx : ‖x‖ ≤ 1 [GOAL] case pos p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ‖x‖ ≤ 1 ⊢ ∃ x_1, x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑x_1.snd = ↑(algebraMap ℤ_[p] ℚ_[p]) x_1.fst [PROOFSTEP] use(⟨x, hx⟩, 1) [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ‖x‖ ≤ 1 ⊢ x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑({ val := x, property := hx }, 1).snd = ↑(algebraMap ℤ_[p] ℚ_[p]) ({ val := x, property := hx }, 1).fst [PROOFSTEP] rw [Submonoid.coe_one, map_one, mul_one, PadicInt.algebraMap_apply, Subtype.coe_mk] [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 ⊢ ∃ x_1, x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑x_1.snd = ↑(algebraMap ℤ_[p] ℚ_[p]) x_1.fst [PROOFSTEP] set n := Int.toNat (-x.valuation) with hn [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) ⊢ ∃ x_1, x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑x_1.snd = ↑(algebraMap ℤ_[p] ℚ_[p]) x_1.fst [PROOFSTEP] have hn_coe : (n : ℤ) = -x.valuation := by rw [hn, Int.toNat_of_nonneg] rw [Right.nonneg_neg_iff] rw [Padic.norm_le_one_iff_val_nonneg, not_le] at hx exact hx.le [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) ⊢ ↑n = -Padic.valuation x [PROOFSTEP] rw [hn, Int.toNat_of_nonneg] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) ⊢ 0 ≤ -Padic.valuation x [PROOFSTEP] rw [Right.nonneg_neg_iff] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) ⊢ Padic.valuation x ≤ 0 [PROOFSTEP] rw [Padic.norm_le_one_iff_val_nonneg, not_le] at hx [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : Padic.valuation x < 0 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) ⊢ Padic.valuation x ≤ 0 [PROOFSTEP] exact hx.le [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x ⊢ ∃ x_1, x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑x_1.snd = ↑(algebraMap ℤ_[p] ℚ_[p]) x_1.fst [PROOFSTEP] set a := x * (p : ℚ_[p]) ^ n with ha [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n ⊢ ∃ x_1, x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑x_1.snd = ↑(algebraMap ℤ_[p] ℚ_[p]) x_1.fst [PROOFSTEP] have ha_norm : ‖a‖ = 1 := by have hx : x ≠ 0 := by intro h0 rw [h0, norm_zero] at hx exact hx zero_le_one rw [ha, padicNormE.mul, padicNormE.norm_p_pow, Padic.norm_eq_pow_val hx, ← zpow_add', hn_coe, neg_neg, add_left_neg, zpow_zero] exact Or.inl (Nat.cast_ne_zero.mpr (NeZero.ne p)) [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n ⊢ ‖a‖ = 1 [PROOFSTEP] have hx : x ≠ 0 := by intro h0 rw [h0, norm_zero] at hx exact hx zero_le_one [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n ⊢ x ≠ 0 [PROOFSTEP] intro h0 [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n h0 : x = 0 ⊢ False [PROOFSTEP] rw [h0, norm_zero] at hx [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬0 ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n h0 : x = 0 ⊢ False [PROOFSTEP] exact hx zero_le_one [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx✝ : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n hx : x ≠ 0 ⊢ ‖a‖ = 1 [PROOFSTEP] rw [ha, padicNormE.mul, padicNormE.norm_p_pow, Padic.norm_eq_pow_val hx, ← zpow_add', hn_coe, neg_neg, add_left_neg, zpow_zero] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx✝ : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n hx : x ≠ 0 ⊢ ↑p ≠ 0 ∨ -Padic.valuation x + -↑n ≠ 0 ∨ -Padic.valuation x = 0 ∧ -↑n = 0 [PROOFSTEP] exact Or.inl (Nat.cast_ne_zero.mpr (NeZero.ne p)) [GOAL] case neg p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n ha_norm : ‖a‖ = 1 ⊢ ∃ x_1, x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑x_1.snd = ↑(algebraMap ℤ_[p] ℚ_[p]) x_1.fst [PROOFSTEP] use(⟨a, le_of_eq ha_norm⟩, ⟨(p ^ n : ℤ_[p]), mem_nonZeroDivisors_iff_ne_zero.mpr (NeZero.ne _)⟩) [GOAL] case h p : ℕ hp : Fact (Nat.Prime p) x : ℚ_[p] hx : ¬‖x‖ ≤ 1 n : ℕ := Int.toNat (-Padic.valuation x) hn : n = Int.toNat (-Padic.valuation x) hn_coe : ↑n = -Padic.valuation x a : ℚ_[p] := x * ↑p ^ n ha : a = x * ↑p ^ n ha_norm : ‖a‖ = 1 ⊢ x * ↑(algebraMap ℤ_[p] ℚ_[p]) ↑({ val := a, property := (_ : ‖a‖ ≤ 1) }, { val := ↑(p ^ n), property := (_ : ↑(p ^ n) ∈ nonZeroDivisors ℤ_[p]) }).snd = ↑(algebraMap ℤ_[p] ℚ_[p]) ({ val := a, property := (_ : ‖a‖ ≤ 1) }, { val := ↑(p ^ n), property := (_ : ↑(p ^ n) ∈ nonZeroDivisors ℤ_[p]) }).fst [PROOFSTEP] simp only [map_pow, map_natCast, algebraMap_apply, PadicInt.coe_pow, PadicInt.coe_nat_cast, Subtype.coe_mk, Nat.cast_pow] [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ ∀ {x y : ℤ_[p]}, ↑(algebraMap ℤ_[p] ℚ_[p]) x = ↑(algebraMap ℤ_[p] ℚ_[p]) y ↔ ∃ c, ↑c * x = ↑c * y [PROOFSTEP] simp_rw [algebraMap_apply, Subtype.coe_inj] [GOAL] p : ℕ hp : Fact (Nat.Prime p) ⊢ ∀ {x y : ℤ_[p]}, x = y ↔ ∃ c, ↑c * x = ↑c * y [PROOFSTEP] refine ⟨fun h => ⟨1, by rw [h]⟩, ?_⟩ [GOAL] p : ℕ hp : Fact (Nat.Prime p) x✝ y✝ : ℤ_[p] h : x✝ = y✝ ⊢ ↑1 * x✝ = ↑1 * y✝ [PROOFSTEP] rw [h] [GOAL] p : ℕ hp : Fact (Nat.Prime p) x✝ y✝ : ℤ_[p] ⊢ (∃ c, ↑c * x✝ = ↑c * y✝) → x✝ = y✝ [PROOFSTEP] rintro ⟨⟨c, hc⟩, h⟩ [GOAL] case intro.mk p : ℕ hp : Fact (Nat.Prime p) x✝ y✝ c : ℤ_[p] hc : c ∈ nonZeroDivisors ℤ_[p] h : ↑{ val := c, property := hc } * x✝ = ↑{ val := c, property := hc } * y✝ ⊢ x✝ = y✝ [PROOFSTEP] exact (mul_eq_mul_left_iff.mp h).resolve_right (mem_nonZeroDivisors_iff_ne_zero.mp hc)
% TTEST_CELL - compute paired t-test. Allow fast computation of % multiple t-test using matrix manipulation. % % Usage: % >> [F df] = ttest_cell( { a b } ); % >> [F df] = ttest_cell(a, b); % % Inputs: % a,b = data consisting of PAIRED arrays to be compared. The last % dimension of the data array is used to compute the t-test. % Outputs: % T - T-value % df - degree of freedom (array) % % Example: % a = { rand(1,10) rand(1,10)+0.5 } % [T df] = ttest_cell(a) % signif = 1-tcdf(T, df(1)) % % % for comparison, the same using the Matlab t-test function % [h p ci stats] = ttest(a{1}', b{1}'); % [ stats.tstat' p] % % % fast computation (fMRI scanner volume 100x100x100 and 10 subjects in % % two conditions). The computation itself takes 0.5 seconds instead of % % half an hour using the standard approach (1000000 loops and Matlab % % t-test function) % a = rand(100,100,100,10); b = rand(100,100,100,10); % [F df] = ttest_cell({ a b }); % % Author: Arnaud Delorme, SCCN/INC/UCSD, La Jolla, 2005 % % Reference: % Schaum's outlines in statistics (3rd edition). 1999. Mc Graw-Hill. % Copyright (C) Arnaud Delorme % % This file is part of EEGLAB, see http://www.eeglab.org % for the documentation and details. % % Redistribution and use in source and binary forms, with or without % modification, are permitted provided that the following conditions are met: % % 1. Redistributions of source code must retain the above copyright notice, % this list of conditions and the following disclaimer. % % 2. Redistributions in binary form must reproduce the above copyright notice, % this list of conditions and the following disclaimer in the documentation % and/or other materials provided with the distribution. % % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF % THE POSSIBILITY OF SUCH DAMAGE. function [tval, df] = ttest_cell(a,b) if nargin < 1 help ttest_cell; return; end if iscell(a), b = a{2}; a = a{1}; end tmpdiff = a-b; diff = mymean(tmpdiff, myndims(a)); sd = mystd( tmpdiff,[], myndims(a)); tval = diff./sd*sqrt(size(a, myndims(a))); df = size(a, myndims(a))-1; % check values againg Matlab statistics toolbox %[h p ci stats] = ttest(a', b'); % [ tval stats.tstat' ] function val = myndims(a) if ndims(a) > 2 val = ndims(a); else if size(a,1) == 1, val = 2; elseif size(a,2) == 1, val = 1; else val = 2; end end; function res = mymean( data, varargin) % deal with complex numbers res = mean( data, varargin{:}); if ~isreal(data) res = abs( res ); end function res = mystd( data, varargin) % deal with complex numbers if ~isreal(data) res = std( abs(data), varargin{:}); else res = sqrt(sum( bsxfun(@minus, data, mean( data, varargin{2})).^2, varargin{2})/(size(data,varargin{2})-1)); % 8 percent speedup %res = std( data, varargin{:}); end
(* Title: HOL/Isar_Examples/Group.thy Author: Makarius *) section \<open>Basic group theory\<close> theory Group imports Main begin subsection \<open>Groups and calculational reasoning\<close> text \<open> Groups over signature \<open>(* :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> \<alpha>, 1 :: \<alpha>, inverse :: \<alpha> \<Rightarrow> \<alpha>)\<close> are defined as an axiomatic type class as follows. Note that the parent class \<open>times\<close> is provided by the basic HOL theory. \<close> class group = times + one + inverse + assumes group_assoc: "(x * y) * z = x * (y * z)" and group_left_one: "1 * x = x" and group_left_inverse: "inverse x * x = 1" text \<open> The group axioms only state the properties of left one and inverse, the right versions may be derived as follows. \<close> theorem (in group) group_right_inverse: "x * inverse x = 1" proof - have "x * inverse x = 1 * (x * inverse x)" by (simp only: group_left_one) also have "\<dots> = 1 * x * inverse x" by (simp only: group_assoc) also have "\<dots> = inverse (inverse x) * inverse x * x * inverse x" by (simp only: group_left_inverse) also have "\<dots> = inverse (inverse x) * (inverse x * x) * inverse x" by (simp only: group_assoc) also have "\<dots> = inverse (inverse x) * 1 * inverse x" by (simp only: group_left_inverse) also have "\<dots> = inverse (inverse x) * (1 * inverse x)" by (simp only: group_assoc) also have "\<dots> = inverse (inverse x) * inverse x" by (simp only: group_left_one) also have "\<dots> = 1" by (simp only: group_left_inverse) finally show ?thesis . qed text \<open> With \<open>group_right_inverse\<close> already available, \<open>group_right_one\<close> is now established much easier. \<close> theorem (in group) group_right_one: "x * 1 = x" proof - have "x * 1 = x * (inverse x * x)" by (simp only: group_left_inverse) also have "\<dots> = x * inverse x * x" by (simp only: group_assoc) also have "\<dots> = 1 * x" by (simp only: group_right_inverse) also have "\<dots> = x" by (simp only: group_left_one) finally show ?thesis . qed text \<open> \<^medskip> The calculational proof style above follows typical presentations given in any introductory course on algebra. The basic technique is to form a transitive chain of equations, which in turn are established by simplifying with appropriate rules. The low-level logical details of equational reasoning are left implicit. Note that ``\<open>\<dots>\<close>'' is just a special term variable that is bound automatically to the argument\<^footnote>\<open>The argument of a curried infix expression happens to be its right-hand side.\<close> of the last fact achieved by any local assumption or proven statement. In contrast to \<open>?thesis\<close>, the ``\<open>\<dots>\<close>'' variable is bound \<^emph>\<open>after\<close> the proof is finished. There are only two separate Isar language elements for calculational proofs: ``\<^theory_text>\<open>also\<close>'' for initial or intermediate calculational steps, and ``\<^theory_text>\<open>finally\<close>'' for exhibiting the result of a calculation. These constructs are not hardwired into Isabelle/Isar, but defined on top of the basic Isar/VM interpreter. Expanding the \<^theory_text>\<open>also\<close> and \<^theory_text>\<open>finally\<close> derived language elements, calculations may be simulated by hand as demonstrated below. \<close> theorem (in group) "x * 1 = x" proof - have "x * 1 = x * (inverse x * x)" by (simp only: group_left_inverse) note calculation = this \<comment> \<open>first calculational step: init calculation register\<close> have "\<dots> = x * inverse x * x" by (simp only: group_assoc) note calculation = trans [OF calculation this] \<comment> \<open>general calculational step: compose with transitivity rule\<close> have "\<dots> = 1 * x" by (simp only: group_right_inverse) note calculation = trans [OF calculation this] \<comment> \<open>general calculational step: compose with transitivity rule\<close> have "\<dots> = x" by (simp only: group_left_one) note calculation = trans [OF calculation this] \<comment> \<open>final calculational step: compose with transitivity rule \dots\<close> from calculation \<comment> \<open>\dots\ and pick up the final result\<close> show ?thesis . qed text \<open> Note that this scheme of calculations is not restricted to plain transitivity. Rules like anti-symmetry, or even forward and backward substitution work as well. For the actual implementation of \<^theory_text>\<open>also\<close> and \<^theory_text>\<open>finally\<close>, Isabelle/Isar maintains separate context information of ``transitivity'' rules. Rule selection takes place automatically by higher-order unification. \<close> subsection \<open>Groups as monoids\<close> text \<open> Monoids over signature \<open>(* :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> \<alpha>, 1 :: \<alpha>)\<close> are defined like this. \<close> class monoid = times + one + assumes monoid_assoc: "(x * y) * z = x * (y * z)" and monoid_left_one: "1 * x = x" and monoid_right_one: "x * 1 = x" text \<open> Groups are \<^emph>\<open>not\<close> yet monoids directly from the definition. For monoids, \<open>right_one\<close> had to be included as an axiom, but for groups both \<open>right_one\<close> and \<open>right_inverse\<close> are derivable from the other axioms. With \<open>group_right_one\<close> derived as a theorem of group theory (see @{thm group_right_one}), we may still instantiate \<open>group \<subseteq> monoid\<close> properly as follows. \<close> instance group \<subseteq> monoid by intro_classes (rule group_assoc, rule group_left_one, rule group_right_one) text \<open> The \<^theory_text>\<open>instance\<close> command actually is a version of \<^theory_text>\<open>theorem\<close>, setting up a goal that reflects the intended class relation (or type constructor arity). Thus any Isar proof language element may be involved to establish this statement. When concluding the proof, the result is transformed into the intended type signature extension behind the scenes. \<close> subsection \<open>More theorems of group theory\<close> text \<open> The one element is already uniquely determined by preserving an \<^emph>\<open>arbitrary\<close> group element. \<close> theorem (in group) group_one_equality: assumes eq: "e * x = x" shows "1 = e" proof - have "1 = x * inverse x" by (simp only: group_right_inverse) also have "\<dots> = (e * x) * inverse x" by (simp only: eq) also have "\<dots> = e * (x * inverse x)" by (simp only: group_assoc) also have "\<dots> = e * 1" by (simp only: group_right_inverse) also have "\<dots> = e" by (simp only: group_right_one) finally show ?thesis . qed text \<open> Likewise, the inverse is already determined by the cancel property. \<close> theorem (in group) group_inverse_equality: assumes eq: "x' * x = 1" shows "inverse x = x'" proof - have "inverse x = 1 * inverse x" by (simp only: group_left_one) also have "\<dots> = (x' * x) * inverse x" by (simp only: eq) also have "\<dots> = x' * (x * inverse x)" by (simp only: group_assoc) also have "\<dots> = x' * 1" by (simp only: group_right_inverse) also have "\<dots> = x'" by (simp only: group_right_one) finally show ?thesis . qed text \<open> The inverse operation has some further characteristic properties. \<close> theorem (in group) group_inverse_times: "inverse (x * y) = inverse y * inverse x" proof (rule group_inverse_equality) show "(inverse y * inverse x) * (x * y) = 1" proof - have "(inverse y * inverse x) * (x * y) = (inverse y * (inverse x * x)) * y" by (simp only: group_assoc) also have "\<dots> = (inverse y * 1) * y" by (simp only: group_left_inverse) also have "\<dots> = inverse y * y" by (simp only: group_right_one) also have "\<dots> = 1" by (simp only: group_left_inverse) finally show ?thesis . qed qed theorem (in group) inverse_inverse: "inverse (inverse x) = x" proof (rule group_inverse_equality) show "x * inverse x = one" by (simp only: group_right_inverse) qed theorem (in group) inverse_inject: assumes eq: "inverse x = inverse y" shows "x = y" proof - have "x = x * 1" by (simp only: group_right_one) also have "\<dots> = x * (inverse y * y)" by (simp only: group_left_inverse) also have "\<dots> = x * (inverse x * y)" by (simp only: eq) also have "\<dots> = (x * inverse x) * y" by (simp only: group_assoc) also have "\<dots> = 1 * y" by (simp only: group_right_inverse) also have "\<dots> = y" by (simp only: group_left_one) finally show ?thesis . qed end
[STATEMENT] lemma bt_dfs_comp_distinct: "distinct (bt_dfs (f \<circ> g) t) \<Longrightarrow> distinct (bt_dfs g t)" "distinct (bts_dfs (f \<circ> g) ts) \<Longrightarrow> distinct (bts_dfs g ts)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (distinct (bt_dfs (f \<circ> g) t) \<Longrightarrow> distinct (bt_dfs g t)) &&& (distinct (bts_dfs (f \<circ> g) ts) \<Longrightarrow> distinct (bts_dfs g ts)) [PROOF STEP] by (simp_all add: bt_dfs_comp distinct_map [of f])
lemma space_interval_measure [simp]: "space (interval_measure F) = UNIV"
Infant and junior choirs meet at lunchtime on Wednesday in the ICT Suite. We also have an afterschool choir on Wednesday from 3.30 - 4.30pm. All ages welcome.
lemma in_enum_image: "A \<subseteq> {.. n} \<Longrightarrow> i \<le> n \<Longrightarrow> enum i \<in> enum ` A \<longleftrightarrow> i \<in> A"
(* Title: HOL/Finite_Set.thy Author: Tobias Nipkow Author: Lawrence C Paulson Author: Markus Wenzel Author: Jeremy Avigad Author: Andrei Popescu *) section \<open>Finite sets\<close> theory Finite_Set imports Product_Type Sum_Type Fields Relation begin subsection \<open>Predicate for finite sets\<close> context notes [[inductive_internals]] begin inductive finite :: "'a set \<Rightarrow> bool" where emptyI [simp, intro!]: "finite {}" | insertI [simp, intro!]: "finite A \<Longrightarrow> finite (insert a A)" end simproc_setup finite_Collect ("finite (Collect P)") = \<open>K Set_Comprehension_Pointfree.simproc\<close> declare [[simproc del: finite_Collect]] lemma finite_induct [case_names empty insert, induct set: finite]: \<comment> \<open>Discharging \<open>x \<notin> F\<close> entails extra work.\<close> assumes "finite F" assumes "P {}" and insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" shows "P F" using \<open>finite F\<close> proof induct show "P {}" by fact next fix x F assume F: "finite F" and P: "P F" show "P (insert x F)" proof cases assume "x \<in> F" then have "insert x F = F" by (rule insert_absorb) with P show ?thesis by (simp only:) next assume "x \<notin> F" from F this P show ?thesis by (rule insert) qed qed lemma infinite_finite_induct [case_names infinite empty insert]: assumes infinite: "\<And>A. \<not> finite A \<Longrightarrow> P A" and empty: "P {}" and insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" shows "P A" proof (cases "finite A") case False with infinite show ?thesis . next case True then show ?thesis by (induct A) (fact empty insert)+ qed subsubsection \<open>Choice principles\<close> lemma ex_new_if_finite: \<comment> \<open>does not depend on def of finite at all\<close> assumes "\<not> finite (UNIV :: 'a set)" and "finite A" shows "\<exists>a::'a. a \<notin> A" proof - from assms have "A \<noteq> UNIV" by blast then show ?thesis by blast qed text \<open>A finite choice principle. Does not need the SOME choice operator.\<close> lemma finite_set_choice: "finite A \<Longrightarrow> \<forall>x\<in>A. \<exists>y. P x y \<Longrightarrow> \<exists>f. \<forall>x\<in>A. P x (f x)" proof (induct rule: finite_induct) case empty then show ?case by simp next case (insert a A) then obtain f b where f: "\<forall>x\<in>A. P x (f x)" and ab: "P a b" by auto show ?case (is "\<exists>f. ?P f") proof show "?P (\<lambda>x. if x = a then b else f x)" using f ab by auto qed qed subsubsection \<open>Finite sets are the images of initial segments of natural numbers\<close> lemma finite_imp_nat_seg_image_inj_on: assumes "finite A" shows "\<exists>(n::nat) f. A = f ` {i. i < n} \<and> inj_on f {i. i < n}" using assms proof induct case empty show ?case proof show "\<exists>f. {} = f ` {i::nat. i < 0} \<and> inj_on f {i. i < 0}" by simp qed next case (insert a A) have notinA: "a \<notin> A" by fact from insert.hyps obtain n f where "A = f ` {i::nat. i < n}" "inj_on f {i. i < n}" by blast then have "insert a A = f(n:=a) ` {i. i < Suc n}" and "inj_on (f(n:=a)) {i. i < Suc n}" using notinA by (auto simp add: image_def Ball_def inj_on_def less_Suc_eq) then show ?case by blast qed lemma nat_seg_image_imp_finite: "A = f ` {i::nat. i < n} \<Longrightarrow> finite A" proof (induct n arbitrary: A) case 0 then show ?case by simp next case (Suc n) let ?B = "f ` {i. i < n}" have finB: "finite ?B" by (rule Suc.hyps[OF refl]) show ?case proof (cases "\<exists>k<n. f n = f k") case True then have "A = ?B" using Suc.prems by (auto simp:less_Suc_eq) then show ?thesis using finB by simp next case False then have "A = insert (f n) ?B" using Suc.prems by (auto simp:less_Suc_eq) then show ?thesis using finB by simp qed qed lemma finite_conv_nat_seg_image: "finite A \<longleftrightarrow> (\<exists>n f. A = f ` {i::nat. i < n})" by (blast intro: nat_seg_image_imp_finite dest: finite_imp_nat_seg_image_inj_on) lemma finite_imp_inj_to_nat_seg: assumes "finite A" shows "\<exists>f n. f ` A = {i::nat. i < n} \<and> inj_on f A" proof - from finite_imp_nat_seg_image_inj_on [OF \<open>finite A\<close>] obtain f and n :: nat where bij: "bij_betw f {i. i<n} A" by (auto simp: bij_betw_def) let ?f = "the_inv_into {i. i<n} f" have "inj_on ?f A \<and> ?f ` A = {i. i<n}" by (fold bij_betw_def) (rule bij_betw_the_inv_into[OF bij]) then show ?thesis by blast qed lemma finite_Collect_less_nat [iff]: "finite {n::nat. n < k}" by (fastforce simp: finite_conv_nat_seg_image) lemma finite_Collect_le_nat [iff]: "finite {n::nat. n \<le> k}" by (simp add: le_eq_less_or_eq Collect_disj_eq) subsection \<open>Finiteness and common set operations\<close> lemma rev_finite_subset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> finite A" proof (induct arbitrary: A rule: finite_induct) case empty then show ?case by simp next case (insert x F A) have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F \<Longrightarrow> finite (A - {x})" by fact+ show "finite A" proof cases assume x: "x \<in> A" with A have "A - {x} \<subseteq> F" by (simp add: subset_insert_iff) with r have "finite (A - {x})" . then have "finite (insert x (A - {x}))" .. also have "insert x (A - {x}) = A" using x by (rule insert_Diff) finally show ?thesis . next show ?thesis when "A \<subseteq> F" using that by fact assume "x \<notin> A" with A show "A \<subseteq> F" by (simp add: subset_insert_iff) qed qed lemma finite_subset: "A \<subseteq> B \<Longrightarrow> finite B \<Longrightarrow> finite A" by (rule rev_finite_subset) simproc_setup finite ("finite A") = \<open>fn _ => let val finite_subset = @{thm finite_subset} val Eq_TrueI = @{thm Eq_TrueI} fun is_subset A th = case Thm.prop_of th of (_ $ (Const (\<^const_name>\<open>less_eq\<close>, Type (\<^type_name>\<open>fun\<close>, [Type (\<^type_name>\<open>set\<close>, _), _])) $ A' $ B)) => if A aconv A' then SOME(B,th) else NONE | _ => NONE; fun is_finite th = case Thm.prop_of th of (_ $ (Const (\<^const_name>\<open>finite\<close>, _) $ A)) => SOME(A,th) | _ => NONE; fun comb (A,sub_th) (A',fin_th) ths = if A aconv A' then (sub_th,fin_th) :: ths else ths fun proc ss ct = (let val _ $ A = Thm.term_of ct val prems = Simplifier.prems_of ss val fins = map_filter is_finite prems val subsets = map_filter (is_subset A) prems in case fold_product comb subsets fins [] of (sub_th,fin_th) :: _ => SOME((fin_th RS (sub_th RS finite_subset)) RS Eq_TrueI) | _ => NONE end) in proc end \<close> (* Needs to be used with care *) declare [[simproc del: finite]] lemma finite_UnI: assumes "finite F" and "finite G" shows "finite (F \<union> G)" using assms by induct simp_all lemma finite_Un [iff]: "finite (F \<union> G) \<longleftrightarrow> finite F \<and> finite G" by (blast intro: finite_UnI finite_subset [of _ "F \<union> G"]) lemma finite_insert [simp]: "finite (insert a A) \<longleftrightarrow> finite A" proof - have "finite {a} \<and> finite A \<longleftrightarrow> finite A" by simp then have "finite ({a} \<union> A) \<longleftrightarrow> finite A" by (simp only: finite_Un) then show ?thesis by simp qed lemma finite_Int [simp, intro]: "finite F \<or> finite G \<Longrightarrow> finite (F \<inter> G)" by (blast intro: finite_subset) lemma finite_Collect_conjI [simp, intro]: "finite {x. P x} \<or> finite {x. Q x} \<Longrightarrow> finite {x. P x \<and> Q x}" by (simp add: Collect_conj_eq) lemma finite_Collect_disjI [simp]: "finite {x. P x \<or> Q x} \<longleftrightarrow> finite {x. P x} \<and> finite {x. Q x}" by (simp add: Collect_disj_eq) lemma finite_Diff [simp, intro]: "finite A \<Longrightarrow> finite (A - B)" by (rule finite_subset, rule Diff_subset) lemma finite_Diff2 [simp]: assumes "finite B" shows "finite (A - B) \<longleftrightarrow> finite A" proof - have "finite A \<longleftrightarrow> finite ((A - B) \<union> (A \<inter> B))" by (simp add: Un_Diff_Int) also have "\<dots> \<longleftrightarrow> finite (A - B)" using \<open>finite B\<close> by simp finally show ?thesis .. qed lemma finite_Diff_insert [iff]: "finite (A - insert a B) \<longleftrightarrow> finite (A - B)" proof - have "finite (A - B) \<longleftrightarrow> finite (A - B - {a})" by simp moreover have "A - insert a B = A - B - {a}" by auto ultimately show ?thesis by simp qed lemma finite_compl [simp]: "finite (A :: 'a set) \<Longrightarrow> finite (- A) \<longleftrightarrow> finite (UNIV :: 'a set)" by (simp add: Compl_eq_Diff_UNIV) lemma finite_Collect_not [simp]: "finite {x :: 'a. P x} \<Longrightarrow> finite {x. \<not> P x} \<longleftrightarrow> finite (UNIV :: 'a set)" by (simp add: Collect_neg_eq) lemma finite_Union [simp, intro]: "finite A \<Longrightarrow> (\<And>M. M \<in> A \<Longrightarrow> finite M) \<Longrightarrow> finite (\<Union>A)" by (induct rule: finite_induct) simp_all lemma finite_UN_I [intro]: "finite A \<Longrightarrow> (\<And>a. a \<in> A \<Longrightarrow> finite (B a)) \<Longrightarrow> finite (\<Union>a\<in>A. B a)" by (induct rule: finite_induct) simp_all lemma finite_UN [simp]: "finite A \<Longrightarrow> finite (\<Union>(B ` A)) \<longleftrightarrow> (\<forall>x\<in>A. finite (B x))" by (blast intro: finite_subset) lemma finite_Inter [intro]: "\<exists>A\<in>M. finite A \<Longrightarrow> finite (\<Inter>M)" by (blast intro: Inter_lower finite_subset) lemma finite_INT [intro]: "\<exists>x\<in>I. finite (A x) \<Longrightarrow> finite (\<Inter>x\<in>I. A x)" by (blast intro: INT_lower finite_subset) lemma finite_imageI [simp, intro]: "finite F \<Longrightarrow> finite (h ` F)" by (induct rule: finite_induct) simp_all lemma finite_image_set [simp]: "finite {x. P x} \<Longrightarrow> finite {f x |x. P x}" by (simp add: image_Collect [symmetric]) lemma finite_image_set2: "finite {x. P x} \<Longrightarrow> finite {y. Q y} \<Longrightarrow> finite {f x y |x y. P x \<and> Q y}" by (rule finite_subset [where B = "\<Union>x \<in> {x. P x}. \<Union>y \<in> {y. Q y}. {f x y}"]) auto lemma finite_imageD: assumes "finite (f ` A)" and "inj_on f A" shows "finite A" using assms proof (induct "f ` A" arbitrary: A) case empty then show ?case by simp next case (insert x B) then have B_A: "insert x B = f ` A" by simp then obtain y where "x = f y" and "y \<in> A" by blast from B_A \<open>x \<notin> B\<close> have "B = f ` A - {x}" by blast with B_A \<open>x \<notin> B\<close> \<open>x = f y\<close> \<open>inj_on f A\<close> \<open>y \<in> A\<close> have "B = f ` (A - {y})" by (simp add: inj_on_image_set_diff) moreover from \<open>inj_on f A\<close> have "inj_on f (A - {y})" by (rule inj_on_diff) ultimately have "finite (A - {y})" by (rule insert.hyps) then show "finite A" by simp qed lemma finite_image_iff: "inj_on f A \<Longrightarrow> finite (f ` A) \<longleftrightarrow> finite A" using finite_imageD by blast lemma finite_surj: "finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> finite B" by (erule finite_subset) (rule finite_imageI) lemma finite_range_imageI: "finite (range g) \<Longrightarrow> finite (range (\<lambda>x. f (g x)))" by (drule finite_imageI) (simp add: range_composition) lemma finite_subset_image: assumes "finite B" shows "B \<subseteq> f ` A \<Longrightarrow> \<exists>C\<subseteq>A. finite C \<and> B = f ` C" using assms proof induct case empty then show ?case by simp next case insert then show ?case by (clarsimp simp del: image_insert simp add: image_insert [symmetric]) blast qed lemma all_subset_image: "(\<forall>B. B \<subseteq> f ` A \<longrightarrow> P B) \<longleftrightarrow> (\<forall>B. B \<subseteq> A \<longrightarrow> P(f ` B))" by (safe elim!: subset_imageE) (use image_mono in \<open>blast+\<close>) (* slow *) lemma all_finite_subset_image: "(\<forall>B. finite B \<and> B \<subseteq> f ` A \<longrightarrow> P B) \<longleftrightarrow> (\<forall>B. finite B \<and> B \<subseteq> A \<longrightarrow> P (f ` B))" proof safe fix B :: "'a set" assume B: "finite B" "B \<subseteq> f ` A" and P: "\<forall>B. finite B \<and> B \<subseteq> A \<longrightarrow> P (f ` B)" show "P B" using finite_subset_image [OF B] P by blast qed blast lemma ex_finite_subset_image: "(\<exists>B. finite B \<and> B \<subseteq> f ` A \<and> P B) \<longleftrightarrow> (\<exists>B. finite B \<and> B \<subseteq> A \<and> P (f ` B))" proof safe fix B :: "'a set" assume B: "finite B" "B \<subseteq> f ` A" and "P B" show "\<exists>B. finite B \<and> B \<subseteq> A \<and> P (f ` B)" using finite_subset_image [OF B] \<open>P B\<close> by blast qed blast lemma finite_vimage_IntI: "finite F \<Longrightarrow> inj_on h A \<Longrightarrow> finite (h -` F \<inter> A)" proof (induct rule: finite_induct) case (insert x F) then show ?case by (simp add: vimage_insert [of h x F] finite_subset [OF inj_on_vimage_singleton] Int_Un_distrib2) qed simp lemma finite_finite_vimage_IntI: assumes "finite F" and "\<And>y. y \<in> F \<Longrightarrow> finite ((h -` {y}) \<inter> A)" shows "finite (h -` F \<inter> A)" proof - have *: "h -` F \<inter> A = (\<Union> y\<in>F. (h -` {y}) \<inter> A)" by blast show ?thesis by (simp only: * assms finite_UN_I) qed lemma finite_vimageI: "finite F \<Longrightarrow> inj h \<Longrightarrow> finite (h -` F)" using finite_vimage_IntI[of F h UNIV] by auto lemma finite_vimageD': "finite (f -` A) \<Longrightarrow> A \<subseteq> range f \<Longrightarrow> finite A" by (auto simp add: subset_image_iff intro: finite_subset[rotated]) lemma finite_vimageD: "finite (h -` F) \<Longrightarrow> surj h \<Longrightarrow> finite F" by (auto dest: finite_vimageD') lemma finite_vimage_iff: "bij h \<Longrightarrow> finite (h -` F) \<longleftrightarrow> finite F" unfolding bij_def by (auto elim: finite_vimageD finite_vimageI) lemma finite_inverse_image_gen: assumes "finite A" "inj_on f D" shows "finite {j\<in>D. f j \<in> A}" using finite_vimage_IntI [OF assms] by (simp add: Collect_conj_eq inf_commute vimage_def) lemma finite_inverse_image: assumes "finite A" "inj f" shows "finite {j. f j \<in> A}" using finite_inverse_image_gen [OF assms] by simp lemma finite_Collect_bex [simp]: assumes "finite A" shows "finite {x. \<exists>y\<in>A. Q x y} \<longleftrightarrow> (\<forall>y\<in>A. finite {x. Q x y})" proof - have "{x. \<exists>y\<in>A. Q x y} = (\<Union>y\<in>A. {x. Q x y})" by auto with assms show ?thesis by simp qed lemma finite_Collect_bounded_ex [simp]: assumes "finite {y. P y}" shows "finite {x. \<exists>y. P y \<and> Q x y} \<longleftrightarrow> (\<forall>y. P y \<longrightarrow> finite {x. Q x y})" proof - have "{x. \<exists>y. P y \<and> Q x y} = (\<Union>y\<in>{y. P y}. {x. Q x y})" by auto with assms show ?thesis by simp qed lemma finite_Plus: "finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A <+> B)" by (simp add: Plus_def) lemma finite_PlusD: fixes A :: "'a set" and B :: "'b set" assumes fin: "finite (A <+> B)" shows "finite A" "finite B" proof - have "Inl ` A \<subseteq> A <+> B" by auto then have "finite (Inl ` A :: ('a + 'b) set)" using fin by (rule finite_subset) then show "finite A" by (rule finite_imageD) (auto intro: inj_onI) next have "Inr ` B \<subseteq> A <+> B" by auto then have "finite (Inr ` B :: ('a + 'b) set)" using fin by (rule finite_subset) then show "finite B" by (rule finite_imageD) (auto intro: inj_onI) qed lemma finite_Plus_iff [simp]: "finite (A <+> B) \<longleftrightarrow> finite A \<and> finite B" by (auto intro: finite_PlusD finite_Plus) lemma finite_Plus_UNIV_iff [simp]: "finite (UNIV :: ('a + 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)" by (subst UNIV_Plus_UNIV [symmetric]) (rule finite_Plus_iff) lemma finite_SigmaI [simp, intro]: "finite A \<Longrightarrow> (\<And>a. a\<in>A \<Longrightarrow> finite (B a)) \<Longrightarrow> finite (SIGMA a:A. B a)" unfolding Sigma_def by blast lemma finite_SigmaI2: assumes "finite {x\<in>A. B x \<noteq> {}}" and "\<And>a. a \<in> A \<Longrightarrow> finite (B a)" shows "finite (Sigma A B)" proof - from assms have "finite (Sigma {x\<in>A. B x \<noteq> {}} B)" by auto also have "Sigma {x:A. B x \<noteq> {}} B = Sigma A B" by auto finally show ?thesis . qed lemma finite_cartesian_product: "finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A \<times> B)" by (rule finite_SigmaI) lemma finite_Prod_UNIV: "finite (UNIV :: 'a set) \<Longrightarrow> finite (UNIV :: 'b set) \<Longrightarrow> finite (UNIV :: ('a \<times> 'b) set)" by (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product) lemma finite_cartesian_productD1: assumes "finite (A \<times> B)" and "B \<noteq> {}" shows "finite A" proof - from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}" by (auto simp add: finite_conv_nat_seg_image) then have "fst ` (A \<times> B) = fst ` f ` {i::nat. i < n}" by simp with \<open>B \<noteq> {}\<close> have "A = (fst \<circ> f) ` {i::nat. i < n}" by (simp add: image_comp) then have "\<exists>n f. A = f ` {i::nat. i < n}" by blast then show ?thesis by (auto simp add: finite_conv_nat_seg_image) qed lemma finite_cartesian_productD2: assumes "finite (A \<times> B)" and "A \<noteq> {}" shows "finite B" proof - from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}" by (auto simp add: finite_conv_nat_seg_image) then have "snd ` (A \<times> B) = snd ` f ` {i::nat. i < n}" by simp with \<open>A \<noteq> {}\<close> have "B = (snd \<circ> f) ` {i::nat. i < n}" by (simp add: image_comp) then have "\<exists>n f. B = f ` {i::nat. i < n}" by blast then show ?thesis by (auto simp add: finite_conv_nat_seg_image) qed lemma finite_cartesian_product_iff: "finite (A \<times> B) \<longleftrightarrow> (A = {} \<or> B = {} \<or> (finite A \<and> finite B))" by (auto dest: finite_cartesian_productD1 finite_cartesian_productD2 finite_cartesian_product) lemma finite_prod: "finite (UNIV :: ('a \<times> 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)" using finite_cartesian_product_iff[of UNIV UNIV] by simp lemma finite_Pow_iff [iff]: "finite (Pow A) \<longleftrightarrow> finite A" proof assume "finite (Pow A)" then have "finite ((\<lambda>x. {x}) ` A)" by (blast intro: finite_subset) (* somewhat slow *) then show "finite A" by (rule finite_imageD [unfolded inj_on_def]) simp next assume "finite A" then show "finite (Pow A)" by induct (simp_all add: Pow_insert) qed corollary finite_Collect_subsets [simp, intro]: "finite A \<Longrightarrow> finite {B. B \<subseteq> A}" by (simp add: Pow_def [symmetric]) lemma finite_set: "finite (UNIV :: 'a set set) \<longleftrightarrow> finite (UNIV :: 'a set)" by (simp only: finite_Pow_iff Pow_UNIV[symmetric]) lemma finite_UnionD: "finite (\<Union>A) \<Longrightarrow> finite A" by (blast intro: finite_subset [OF subset_Pow_Union]) lemma finite_bind: assumes "finite S" assumes "\<forall>x \<in> S. finite (f x)" shows "finite (Set.bind S f)" using assms by (simp add: bind_UNION) lemma finite_filter [simp]: "finite S \<Longrightarrow> finite (Set.filter P S)" unfolding Set.filter_def by simp lemma finite_set_of_finite_funs: assumes "finite A" "finite B" shows "finite {f. \<forall>x. (x \<in> A \<longrightarrow> f x \<in> B) \<and> (x \<notin> A \<longrightarrow> f x = d)}" (is "finite ?S") proof - let ?F = "\<lambda>f. {(a,b). a \<in> A \<and> b = f a}" have "?F ` ?S \<subseteq> Pow(A \<times> B)" by auto from finite_subset[OF this] assms have 1: "finite (?F ` ?S)" by simp have 2: "inj_on ?F ?S" by (fastforce simp add: inj_on_def set_eq_iff fun_eq_iff) (* somewhat slow *) show ?thesis by (rule finite_imageD [OF 1 2]) qed lemma not_finite_existsD: assumes "\<not> finite {a. P a}" shows "\<exists>a. P a" proof (rule classical) assume "\<not> ?thesis" with assms show ?thesis by auto qed lemma finite_converse [iff]: "finite (r\<inverse>) \<longleftrightarrow> finite r" unfolding converse_def conversep_iff using [[simproc add: finite_Collect]] by (auto elim: finite_imageD simp: inj_on_def) lemma finite_Domain: "finite r \<Longrightarrow> finite (Domain r)" by (induct set: finite) auto lemma finite_Range: "finite r \<Longrightarrow> finite (Range r)" by (induct set: finite) auto lemma finite_Field: "finite r \<Longrightarrow> finite (Field r)" by (simp add: Field_def finite_Domain finite_Range) lemma finite_Image[simp]: "finite R \<Longrightarrow> finite (R `` A)" by(rule finite_subset[OF _ finite_Range]) auto subsection \<open>Further induction rules on finite sets\<close> lemma finite_ne_induct [case_names singleton insert, consumes 2]: assumes "finite F" and "F \<noteq> {}" assumes "\<And>x. P {x}" and "\<And>x F. finite F \<Longrightarrow> F \<noteq> {} \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" shows "P F" using assms proof induct case empty then show ?case by simp next case (insert x F) then show ?case by cases auto qed lemma finite_subset_induct [consumes 2, case_names empty insert]: assumes "finite F" and "F \<subseteq> A" and empty: "P {}" and insert: "\<And>a F. finite F \<Longrightarrow> a \<in> A \<Longrightarrow> a \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert a F)" shows "P F" using \<open>finite F\<close> \<open>F \<subseteq> A\<close> proof induct show "P {}" by fact next fix x F assume "finite F" and "x \<notin> F" and P: "F \<subseteq> A \<Longrightarrow> P F" and i: "insert x F \<subseteq> A" show "P (insert x F)" proof (rule insert) from i show "x \<in> A" by blast from i have "F \<subseteq> A" by blast with P show "P F" . show "finite F" by fact show "x \<notin> F" by fact qed qed lemma finite_empty_induct: assumes "finite A" and "P A" and remove: "\<And>a A. finite A \<Longrightarrow> a \<in> A \<Longrightarrow> P A \<Longrightarrow> P (A - {a})" shows "P {}" proof - have "P (A - B)" if "B \<subseteq> A" for B :: "'a set" proof - from \<open>finite A\<close> that have "finite B" by (rule rev_finite_subset) from this \<open>B \<subseteq> A\<close> show "P (A - B)" proof induct case empty from \<open>P A\<close> show ?case by simp next case (insert b B) have "P (A - B - {b})" proof (rule remove) from \<open>finite A\<close> show "finite (A - B)" by induct auto from insert show "b \<in> A - B" by simp from insert show "P (A - B)" by simp qed also have "A - B - {b} = A - insert b B" by (rule Diff_insert [symmetric]) finally show ?case . qed qed then have "P (A - A)" by blast then show ?thesis by simp qed lemma finite_update_induct [consumes 1, case_names const update]: assumes finite: "finite {a. f a \<noteq> c}" and const: "P (\<lambda>a. c)" and update: "\<And>a b f. finite {a. f a \<noteq> c} \<Longrightarrow> f a = c \<Longrightarrow> b \<noteq> c \<Longrightarrow> P f \<Longrightarrow> P (f(a := b))" shows "P f" using finite proof (induct "{a. f a \<noteq> c}" arbitrary: f) case empty with const show ?case by simp next case (insert a A) then have "A = {a'. (f(a := c)) a' \<noteq> c}" and "f a \<noteq> c" by auto with \<open>finite A\<close> have "finite {a'. (f(a := c)) a' \<noteq> c}" by simp have "(f(a := c)) a = c" by simp from insert \<open>A = {a'. (f(a := c)) a' \<noteq> c}\<close> have "P (f(a := c))" by simp with \<open>finite {a'. (f(a := c)) a' \<noteq> c}\<close> \<open>(f(a := c)) a = c\<close> \<open>f a \<noteq> c\<close> have "P ((f(a := c))(a := f a))" by (rule update) then show ?case by simp qed subsection \<open>Class \<open>finite\<close>\<close> class finite = assumes finite_UNIV: "finite (UNIV :: 'a set)" begin lemma finite [simp]: "finite (A :: 'a set)" by (rule subset_UNIV finite_UNIV finite_subset)+ lemma finite_code [code]: "finite (A :: 'a set) \<longleftrightarrow> True" by simp end instance prod :: (finite, finite) finite by standard (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product finite) lemma inj_graph: "inj (\<lambda>f. {(x, y). y = f x})" by (rule inj_onI) (auto simp add: set_eq_iff fun_eq_iff) instance "fun" :: (finite, finite) finite proof show "finite (UNIV :: ('a \<Rightarrow> 'b) set)" proof (rule finite_imageD) let ?graph = "\<lambda>f::'a \<Rightarrow> 'b. {(x, y). y = f x}" have "range ?graph \<subseteq> Pow UNIV" by simp moreover have "finite (Pow (UNIV :: ('a * 'b) set))" by (simp only: finite_Pow_iff finite) ultimately show "finite (range ?graph)" by (rule finite_subset) show "inj ?graph" by (rule inj_graph) qed qed instance bool :: finite by standard (simp add: UNIV_bool) instance set :: (finite) finite by standard (simp only: Pow_UNIV [symmetric] finite_Pow_iff finite) instance unit :: finite by standard (simp add: UNIV_unit) instance sum :: (finite, finite) finite by standard (simp only: UNIV_Plus_UNIV [symmetric] finite_Plus finite) subsection \<open>A basic fold functional for finite sets\<close> text \<open> The intended behaviour is \<open>fold f z {x\<^sub>1, \<dots>, x\<^sub>n} = f x\<^sub>1 (\<dots> (f x\<^sub>n z)\<dots>)\<close> if \<open>f\<close> is ``left-commutative''. The commutativity requirement is relativised to the carrier set \<open>S\<close>: \<close> locale comp_fun_commute_on = fixes S :: "'a set" fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" assumes comp_fun_commute_on: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f y \<circ> f x = f x \<circ> f y" begin lemma fun_left_comm: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f y (f x z) = f x (f y z)" using comp_fun_commute_on by (simp add: fun_eq_iff) lemma commute_left_comp: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f y \<circ> (f x \<circ> g) = f x \<circ> (f y \<circ> g)" by (simp add: o_assoc comp_fun_commute_on) end inductive fold_graph :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> bool" for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: 'b where emptyI [intro]: "fold_graph f z {} z" | insertI [intro]: "x \<notin> A \<Longrightarrow> fold_graph f z A y \<Longrightarrow> fold_graph f z (insert x A) (f x y)" inductive_cases empty_fold_graphE [elim!]: "fold_graph f z {} x" lemma fold_graph_closed_lemma: "fold_graph f z A x \<and> x \<in> B" if "fold_graph g z A x" "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> f a b = g a b" "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> g a b \<in> B" "z \<in> B" using that(1-3) proof (induction rule: fold_graph.induct) case (insertI x A y) have "fold_graph f z A y" "y \<in> B" unfolding atomize_conj by (rule insertI.IH) (auto intro: insertI.prems) then have "g x y \<in> B" and f_eq: "f x y = g x y" by (auto simp: insertI.prems) moreover have "fold_graph f z (insert x A) (f x y)" by (rule fold_graph.insertI; fact) ultimately show ?case by (simp add: f_eq) qed (auto intro!: that) lemma fold_graph_closed_eq: "fold_graph f z A = fold_graph g z A" if "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> f a b = g a b" "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> g a b \<in> B" "z \<in> B" using fold_graph_closed_lemma[of f z A _ B g] fold_graph_closed_lemma[of g z A _ B f] that by auto definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" where "fold f z A = (if finite A then (THE y. fold_graph f z A y) else z)" lemma fold_closed_eq: "fold f z A = fold g z A" if "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> f a b = g a b" "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> g a b \<in> B" "z \<in> B" unfolding Finite_Set.fold_def by (subst fold_graph_closed_eq[where B=B and g=g]) (auto simp: that) text \<open> A tempting alternative for the definition is \<^term>\<open>if finite A then THE y. fold_graph f z A y else e\<close>. It allows the removal of finiteness assumptions from the theorems \<open>fold_comm\<close>, \<open>fold_reindex\<close> and \<open>fold_distrib\<close>. The proofs become ugly. It is not worth the effort. (???) \<close> lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x" by (induct rule: finite_induct) auto subsubsection \<open>From \<^const>\<open>fold_graph\<close> to \<^term>\<open>fold\<close>\<close> context comp_fun_commute_on begin lemma fold_graph_insertE_aux: assumes "A \<subseteq> S" assumes "fold_graph f z A y" "a \<in> A" shows "\<exists>y'. y = f a y' \<and> fold_graph f z (A - {a}) y'" using assms(2-,1) proof (induct set: fold_graph) case emptyI then show ?case by simp next case (insertI x A y) show ?case proof (cases "x = a") case True with insertI show ?thesis by auto next case False then obtain y' where y: "y = f a y'" and y': "fold_graph f z (A - {a}) y'" using insertI by auto from insertI have "x \<in> S" "a \<in> S" by auto then have "f x y = f a (f x y')" unfolding y by (intro fun_left_comm; simp) moreover have "fold_graph f z (insert x A - {a}) (f x y')" using y' and \<open>x \<noteq> a\<close> and \<open>x \<notin> A\<close> by (simp add: insert_Diff_if fold_graph.insertI) ultimately show ?thesis by fast qed qed lemma fold_graph_insertE: assumes "insert x A \<subseteq> S" assumes "fold_graph f z (insert x A) v" and "x \<notin> A" obtains y where "v = f x y" and "fold_graph f z A y" using assms by (auto dest: fold_graph_insertE_aux[OF \<open>insert x A \<subseteq> S\<close> _ insertI1]) lemma fold_graph_determ: assumes "A \<subseteq> S" assumes "fold_graph f z A x" "fold_graph f z A y" shows "y = x" using assms(2-,1) proof (induct arbitrary: y set: fold_graph) case emptyI then show ?case by fast next case (insertI x A y v) from \<open>insert x A \<subseteq> S\<close> and \<open>fold_graph f z (insert x A) v\<close> and \<open>x \<notin> A\<close> obtain y' where "v = f x y'" and "fold_graph f z A y'" by (rule fold_graph_insertE) from \<open>fold_graph f z A y'\<close> insertI have "y' = y" by simp with \<open>v = f x y'\<close> show "v = f x y" by simp qed lemma fold_equality: "A \<subseteq> S \<Longrightarrow> fold_graph f z A y \<Longrightarrow> fold f z A = y" by (cases "finite A") (auto simp add: fold_def intro: fold_graph_determ dest: fold_graph_finite) lemma fold_graph_fold: assumes "A \<subseteq> S" assumes "finite A" shows "fold_graph f z A (fold f z A)" proof - from \<open>finite A\<close> have "\<exists>x. fold_graph f z A x" by (rule finite_imp_fold_graph) moreover note fold_graph_determ[OF \<open>A \<subseteq> S\<close>] ultimately have "\<exists>!x. fold_graph f z A x" by (rule ex_ex1I) then have "fold_graph f z A (The (fold_graph f z A))" by (rule theI') with assms show ?thesis by (simp add: fold_def) qed text \<open>The base case for \<open>fold\<close>:\<close> lemma (in -) fold_infinite [simp]: "\<not> finite A \<Longrightarrow> fold f z A = z" by (auto simp: fold_def) lemma (in -) fold_empty [simp]: "fold f z {} = z" by (auto simp: fold_def) text \<open>The various recursion equations for \<^const>\<open>fold\<close>:\<close> lemma fold_insert [simp]: assumes "insert x A \<subseteq> S" assumes "finite A" and "x \<notin> A" shows "fold f z (insert x A) = f x (fold f z A)" proof (rule fold_equality[OF \<open>insert x A \<subseteq> S\<close>]) fix z from \<open>insert x A \<subseteq> S\<close> \<open>finite A\<close> have "fold_graph f z A (fold f z A)" by (blast intro: fold_graph_fold) with \<open>x \<notin> A\<close> have "fold_graph f z (insert x A) (f x (fold f z A))" by (rule fold_graph.insertI) then show "fold_graph f z (insert x A) (f x (fold f z A))" by simp qed declare (in -) empty_fold_graphE [rule del] fold_graph.intros [rule del] \<comment> \<open>No more proofs involve these.\<close> lemma fold_fun_left_comm: assumes "insert x A \<subseteq> S" "finite A" shows "f x (fold f z A) = fold f (f x z) A" using assms(2,1) proof (induct rule: finite_induct) case empty then show ?case by simp next case (insert y F) then have "fold f (f x z) (insert y F) = f y (fold f (f x z) F)" by simp also have "\<dots> = f x (f y (fold f z F))" using insert by (simp add: fun_left_comm[where ?y=x]) also have "\<dots> = f x (fold f z (insert y F))" proof - from insert have "insert y F \<subseteq> S" by simp from fold_insert[OF this] insert show ?thesis by simp qed finally show ?case .. qed lemma fold_insert2: "insert x A \<subseteq> S \<Longrightarrow> finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" by (simp add: fold_fun_left_comm) lemma fold_rec: assumes "A \<subseteq> S" assumes "finite A" and "x \<in> A" shows "fold f z A = f x (fold f z (A - {x}))" proof - have A: "A = insert x (A - {x})" using \<open>x \<in> A\<close> by blast then have "fold f z A = fold f z (insert x (A - {x}))" by simp also have "\<dots> = f x (fold f z (A - {x}))" by (rule fold_insert) (use assms in \<open>auto\<close>) finally show ?thesis . qed lemma fold_insert_remove: assumes "insert x A \<subseteq> S" assumes "finite A" shows "fold f z (insert x A) = f x (fold f z (A - {x}))" proof - from \<open>finite A\<close> have "finite (insert x A)" by auto moreover have "x \<in> insert x A" by auto ultimately have "fold f z (insert x A) = f x (fold f z (insert x A - {x}))" using \<open>insert x A \<subseteq> S\<close> by (blast intro: fold_rec) then show ?thesis by simp qed lemma fold_set_union_disj: assumes "A \<subseteq> S" "B \<subseteq> S" assumes "finite A" "finite B" "A \<inter> B = {}" shows "Finite_Set.fold f z (A \<union> B) = Finite_Set.fold f (Finite_Set.fold f z A) B" using \<open>finite B\<close> assms(1,2,3,5) proof induct case (insert x F) have "fold f z (A \<union> insert x F) = f x (fold f (fold f z A) F)" using insert by auto also have "\<dots> = fold f (fold f z A) (insert x F)" using insert by (blast intro: fold_insert[symmetric]) finally show ?case . qed simp end text \<open>Other properties of \<^const>\<open>fold\<close>:\<close> lemma fold_graph_image: assumes "inj_on g A" shows "fold_graph f z (g ` A) = fold_graph (f \<circ> g) z A" proof fix w show "fold_graph f z (g ` A) w = fold_graph (f o g) z A w" proof assume "fold_graph f z (g ` A) w" then show "fold_graph (f \<circ> g) z A w" using assms proof (induct "g ` A" w arbitrary: A) case emptyI then show ?case by (auto intro: fold_graph.emptyI) next case (insertI x A r B) from \<open>inj_on g B\<close> \<open>x \<notin> A\<close> \<open>insert x A = image g B\<close> obtain x' A' where "x' \<notin> A'" and [simp]: "B = insert x' A'" "x = g x'" "A = g ` A'" by (rule inj_img_insertE) from insertI.prems have "fold_graph (f \<circ> g) z A' r" by (auto intro: insertI.hyps) with \<open>x' \<notin> A'\<close> have "fold_graph (f \<circ> g) z (insert x' A') ((f \<circ> g) x' r)" by (rule fold_graph.insertI) then show ?case by simp qed next assume "fold_graph (f \<circ> g) z A w" then show "fold_graph f z (g ` A) w" using assms proof induct case emptyI then show ?case by (auto intro: fold_graph.emptyI) next case (insertI x A r) from \<open>x \<notin> A\<close> insertI.prems have "g x \<notin> g ` A" by auto moreover from insertI have "fold_graph f z (g ` A) r" by simp ultimately have "fold_graph f z (insert (g x) (g ` A)) (f (g x) r)" by (rule fold_graph.insertI) then show ?case by simp qed qed qed lemma fold_image: assumes "inj_on g A" shows "fold f z (g ` A) = fold (f \<circ> g) z A" proof (cases "finite A") case False with assms show ?thesis by (auto dest: finite_imageD simp add: fold_def) next case True then show ?thesis by (auto simp add: fold_def fold_graph_image[OF assms]) qed lemma fold_cong: assumes "comp_fun_commute_on S f" "comp_fun_commute_on S g" and "A \<subseteq> S" "finite A" and cong: "\<And>x. x \<in> A \<Longrightarrow> f x = g x" and "s = t" and "A = B" shows "fold f s A = fold g t B" proof - have "fold f s A = fold g s A" using \<open>finite A\<close> \<open>A \<subseteq> S\<close> cong proof (induct A) case empty then show ?case by simp next case insert interpret f: comp_fun_commute_on S f by (fact \<open>comp_fun_commute_on S f\<close>) interpret g: comp_fun_commute_on S g by (fact \<open>comp_fun_commute_on S g\<close>) from insert show ?case by simp qed with assms show ?thesis by simp qed text \<open>A simplified version for idempotent functions:\<close> locale comp_fun_idem_on = comp_fun_commute_on + assumes comp_fun_idem_on: "x \<in> S \<Longrightarrow> f x \<circ> f x = f x" begin lemma fun_left_idem: "x \<in> S \<Longrightarrow> f x (f x z) = f x z" using comp_fun_idem_on by (simp add: fun_eq_iff) lemma fold_insert_idem: assumes "insert x A \<subseteq> S" assumes fin: "finite A" shows "fold f z (insert x A) = f x (fold f z A)" proof cases assume "x \<in> A" then obtain B where "A = insert x B" and "x \<notin> B" by (rule set_insert) then show ?thesis using assms by (simp add: comp_fun_idem_on fun_left_idem) next assume "x \<notin> A" then show ?thesis using assms by auto qed declare fold_insert [simp del] fold_insert_idem [simp] lemma fold_insert_idem2: "insert x A \<subseteq> S \<Longrightarrow> finite A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" by (simp add: fold_fun_left_comm) end subsubsection \<open>Liftings to \<open>comp_fun_commute_on\<close> etc.\<close> lemma (in comp_fun_commute_on) comp_comp_fun_commute_on: "range g \<subseteq> S \<Longrightarrow> comp_fun_commute_on R (f \<circ> g)" by standard (force intro: comp_fun_commute_on) lemma (in comp_fun_idem_on) comp_comp_fun_idem_on: assumes "range g \<subseteq> S" shows "comp_fun_idem_on R (f \<circ> g)" proof interpret f_g: comp_fun_commute_on R "f o g" by (fact comp_comp_fun_commute_on[OF \<open>range g \<subseteq> S\<close>]) show "x \<in> R \<Longrightarrow> y \<in> R \<Longrightarrow> (f \<circ> g) y \<circ> (f \<circ> g) x = (f \<circ> g) x \<circ> (f \<circ> g) y" for x y by (fact f_g.comp_fun_commute_on) qed (use \<open>range g \<subseteq> S\<close> in \<open>force intro: comp_fun_idem_on\<close>) lemma (in comp_fun_commute_on) comp_fun_commute_on_funpow: "comp_fun_commute_on S (\<lambda>x. f x ^^ g x)" proof fix x y assume "x \<in> S" "y \<in> S" show "f y ^^ g y \<circ> f x ^^ g x = f x ^^ g x \<circ> f y ^^ g y" proof (cases "x = y") case True then show ?thesis by simp next case False show ?thesis proof (induct "g x" arbitrary: g) case 0 then show ?case by simp next case (Suc n g) have hyp1: "f y ^^ g y \<circ> f x = f x \<circ> f y ^^ g y" proof (induct "g y" arbitrary: g) case 0 then show ?case by simp next case (Suc n g) define h where "h z = g z - 1" for z with Suc have "n = h y" by simp with Suc have hyp: "f y ^^ h y \<circ> f x = f x \<circ> f y ^^ h y" by auto from Suc h_def have "g y = Suc (h y)" by simp with \<open>x \<in> S\<close> \<open>y \<in> S\<close> show ?case by (simp add: comp_assoc hyp) (simp add: o_assoc comp_fun_commute_on) qed define h where "h z = (if z = x then g x - 1 else g z)" for z with Suc have "n = h x" by simp with Suc have "f y ^^ h y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ h y" by auto with False h_def have hyp2: "f y ^^ g y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ g y" by simp from Suc h_def have "g x = Suc (h x)" by simp then show ?case by (simp del: funpow.simps add: funpow_Suc_right o_assoc hyp2) (simp add: comp_assoc hyp1) qed qed qed subsubsection \<open>\<^term>\<open>UNIV\<close> as carrier set\<close> locale comp_fun_commute = fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" assumes comp_fun_commute: "f y \<circ> f x = f x \<circ> f y" begin lemma (in -) comp_fun_commute_def': "comp_fun_commute f = comp_fun_commute_on UNIV f" unfolding comp_fun_commute_def comp_fun_commute_on_def by blast text \<open> We abuse the \<open>rewrites\<close> functionality of locales to remove trivial assumptions that result from instantiating the carrier set to \<^term>\<open>UNIV\<close>. \<close> sublocale comp_fun_commute_on UNIV f rewrites "\<And>X. (X \<subseteq> UNIV) \<equiv> True" and "\<And>x. x \<in> UNIV \<equiv> True" and "\<And>P. (True \<Longrightarrow> P) \<equiv> Trueprop P" and "\<And>P Q. (True \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> True \<Longrightarrow> PROP Q)" proof - show "comp_fun_commute_on UNIV f" by standard (simp add: comp_fun_commute) qed simp_all end lemma (in comp_fun_commute) comp_comp_fun_commute: "comp_fun_commute (f o g)" unfolding comp_fun_commute_def' by (fact comp_comp_fun_commute_on) lemma (in comp_fun_commute) comp_fun_commute_funpow: "comp_fun_commute (\<lambda>x. f x ^^ g x)" unfolding comp_fun_commute_def' by (fact comp_fun_commute_on_funpow) locale comp_fun_idem = comp_fun_commute + assumes comp_fun_idem: "f x o f x = f x" begin lemma (in -) comp_fun_idem_def': "comp_fun_idem f = comp_fun_idem_on UNIV f" unfolding comp_fun_idem_on_def comp_fun_idem_def comp_fun_commute_def' unfolding comp_fun_idem_axioms_def comp_fun_idem_on_axioms_def by blast text \<open> Again, we abuse the \<open>rewrites\<close> functionality of locales to remove trivial assumptions that result from instantiating the carrier set to \<^term>\<open>UNIV\<close>. \<close> sublocale comp_fun_idem_on UNIV f rewrites "\<And>X. (X \<subseteq> UNIV) \<equiv> True" and "\<And>x. x \<in> UNIV \<equiv> True" and "\<And>P. (True \<Longrightarrow> P) \<equiv> Trueprop P" and "\<And>P Q. (True \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> True \<Longrightarrow> PROP Q)" proof - show "comp_fun_idem_on UNIV f" by standard (simp_all add: comp_fun_idem comp_fun_commute) qed simp_all end lemma (in comp_fun_idem) comp_comp_fun_idem: "comp_fun_idem (f o g)" unfolding comp_fun_idem_def' by (fact comp_comp_fun_idem_on) subsubsection \<open>Expressing set operations via \<^const>\<open>fold\<close>\<close> lemma comp_fun_commute_const: "comp_fun_commute (\<lambda>_. f)" by standard (rule refl) lemma comp_fun_idem_insert: "comp_fun_idem insert" by standard auto lemma comp_fun_idem_remove: "comp_fun_idem Set.remove" by standard auto lemma (in semilattice_inf) comp_fun_idem_inf: "comp_fun_idem inf" by standard (auto simp add: inf_left_commute) lemma (in semilattice_sup) comp_fun_idem_sup: "comp_fun_idem sup" by standard (auto simp add: sup_left_commute) lemma union_fold_insert: assumes "finite A" shows "A \<union> B = fold insert B A" proof - interpret comp_fun_idem insert by (fact comp_fun_idem_insert) from \<open>finite A\<close> show ?thesis by (induct A arbitrary: B) simp_all qed lemma minus_fold_remove: assumes "finite A" shows "B - A = fold Set.remove B A" proof - interpret comp_fun_idem Set.remove by (fact comp_fun_idem_remove) from \<open>finite A\<close> have "fold Set.remove B A = B - A" by (induct A arbitrary: B) auto (* slow *) then show ?thesis .. qed lemma comp_fun_commute_filter_fold: "comp_fun_commute (\<lambda>x A'. if P x then Set.insert x A' else A')" proof - interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert) show ?thesis by standard (auto simp: fun_eq_iff) qed lemma Set_filter_fold: assumes "finite A" shows "Set.filter P A = fold (\<lambda>x A'. if P x then Set.insert x A' else A') {} A" using assms proof - interpret commute_insert: comp_fun_commute "(\<lambda>x A'. if P x then Set.insert x A' else A')" by (fact comp_fun_commute_filter_fold) from \<open>finite A\<close> show ?thesis by induct (auto simp add: Set.filter_def) qed lemma inter_Set_filter: assumes "finite B" shows "A \<inter> B = Set.filter (\<lambda>x. x \<in> A) B" using assms by induct (auto simp: Set.filter_def) lemma image_fold_insert: assumes "finite A" shows "image f A = fold (\<lambda>k A. Set.insert (f k) A) {} A" proof - interpret comp_fun_commute "\<lambda>k A. Set.insert (f k) A" by standard auto show ?thesis using assms by (induct A) auto qed lemma Ball_fold: assumes "finite A" shows "Ball A P = fold (\<lambda>k s. s \<and> P k) True A" proof - interpret comp_fun_commute "\<lambda>k s. s \<and> P k" by standard auto show ?thesis using assms by (induct A) auto qed lemma Bex_fold: assumes "finite A" shows "Bex A P = fold (\<lambda>k s. s \<or> P k) False A" proof - interpret comp_fun_commute "\<lambda>k s. s \<or> P k" by standard auto show ?thesis using assms by (induct A) auto qed lemma comp_fun_commute_Pow_fold: "comp_fun_commute (\<lambda>x A. A \<union> Set.insert x ` A)" by (clarsimp simp: fun_eq_iff comp_fun_commute_def) blast lemma Pow_fold: assumes "finite A" shows "Pow A = fold (\<lambda>x A. A \<union> Set.insert x ` A) {{}} A" proof - interpret comp_fun_commute "\<lambda>x A. A \<union> Set.insert x ` A" by (rule comp_fun_commute_Pow_fold) show ?thesis using assms by (induct A) (auto simp: Pow_insert) qed lemma fold_union_pair: assumes "finite B" shows "(\<Union>y\<in>B. {(x, y)}) \<union> A = fold (\<lambda>y. Set.insert (x, y)) A B" proof - interpret comp_fun_commute "\<lambda>y. Set.insert (x, y)" by standard auto show ?thesis using assms by (induct arbitrary: A) simp_all qed lemma comp_fun_commute_product_fold: "finite B \<Longrightarrow> comp_fun_commute (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B)" by standard (auto simp: fold_union_pair [symmetric]) lemma product_fold: assumes "finite A" "finite B" shows "A \<times> B = fold (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B) {} A" proof - interpret commute_product: comp_fun_commute "(\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B)" by (fact comp_fun_commute_product_fold[OF \<open>finite B\<close>]) from assms show ?thesis unfolding Sigma_def by (induct A) (simp_all add: fold_union_pair) qed context complete_lattice begin lemma inf_Inf_fold_inf: assumes "finite A" shows "inf (Inf A) B = fold inf B A" proof - interpret comp_fun_idem inf by (fact comp_fun_idem_inf) from \<open>finite A\<close> fold_fun_left_comm show ?thesis by (induct A arbitrary: B) (simp_all add: inf_commute fun_eq_iff) qed lemma sup_Sup_fold_sup: assumes "finite A" shows "sup (Sup A) B = fold sup B A" proof - interpret comp_fun_idem sup by (fact comp_fun_idem_sup) from \<open>finite A\<close> fold_fun_left_comm show ?thesis by (induct A arbitrary: B) (simp_all add: sup_commute fun_eq_iff) qed lemma Inf_fold_inf: "finite A \<Longrightarrow> Inf A = fold inf top A" using inf_Inf_fold_inf [of A top] by (simp add: inf_absorb2) lemma Sup_fold_sup: "finite A \<Longrightarrow> Sup A = fold sup bot A" using sup_Sup_fold_sup [of A bot] by (simp add: sup_absorb2) lemma inf_INF_fold_inf: assumes "finite A" shows "inf B (\<Sqinter>(f ` A)) = fold (inf \<circ> f) B A" (is "?inf = ?fold") proof - interpret comp_fun_idem inf by (fact comp_fun_idem_inf) interpret comp_fun_idem "inf \<circ> f" by (fact comp_comp_fun_idem) from \<open>finite A\<close> have "?fold = ?inf" by (induct A arbitrary: B) (simp_all add: inf_left_commute) then show ?thesis .. qed lemma sup_SUP_fold_sup: assumes "finite A" shows "sup B (\<Squnion>(f ` A)) = fold (sup \<circ> f) B A" (is "?sup = ?fold") proof - interpret comp_fun_idem sup by (fact comp_fun_idem_sup) interpret comp_fun_idem "sup \<circ> f" by (fact comp_comp_fun_idem) from \<open>finite A\<close> have "?fold = ?sup" by (induct A arbitrary: B) (simp_all add: sup_left_commute) then show ?thesis .. qed lemma INF_fold_inf: "finite A \<Longrightarrow> \<Sqinter>(f ` A) = fold (inf \<circ> f) top A" using inf_INF_fold_inf [of A top] by simp lemma SUP_fold_sup: "finite A \<Longrightarrow> \<Squnion>(f ` A) = fold (sup \<circ> f) bot A" using sup_SUP_fold_sup [of A bot] by simp lemma finite_Inf_in: assumes "finite A" "A\<noteq>{}" and inf: "\<And>x y. \<lbrakk>x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> inf x y \<in> A" shows "Inf A \<in> A" proof - have "Inf B \<in> A" if "B \<le> A" "B\<noteq>{}" for B using finite_subset [OF \<open>B \<subseteq> A\<close> \<open>finite A\<close>] that by (induction B) (use inf in \<open>force+\<close>) then show ?thesis by (simp add: assms) qed lemma finite_Sup_in: assumes "finite A" "A\<noteq>{}" and sup: "\<And>x y. \<lbrakk>x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> sup x y \<in> A" shows "Sup A \<in> A" proof - have "Sup B \<in> A" if "B \<le> A" "B\<noteq>{}" for B using finite_subset [OF \<open>B \<subseteq> A\<close> \<open>finite A\<close>] that by (induction B) (use sup in \<open>force+\<close>) then show ?thesis by (simp add: assms) qed end subsubsection \<open>Expressing relation operations via \<^const>\<open>fold\<close>\<close> lemma Id_on_fold: assumes "finite A" shows "Id_on A = Finite_Set.fold (\<lambda>x. Set.insert (Pair x x)) {} A" proof - interpret comp_fun_commute "\<lambda>x. Set.insert (Pair x x)" by standard auto from assms show ?thesis unfolding Id_on_def by (induct A) simp_all qed lemma comp_fun_commute_Image_fold: "comp_fun_commute (\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A)" proof - interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert) show ?thesis by standard (auto simp: fun_eq_iff comp_fun_commute split: prod.split) qed lemma Image_fold: assumes "finite R" shows "R `` S = Finite_Set.fold (\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A) {} R" proof - interpret comp_fun_commute "(\<lambda>(x,y) A. if x \<in> S then Set.insert y A else A)" by (rule comp_fun_commute_Image_fold) have *: "\<And>x F. Set.insert x F `` S = (if fst x \<in> S then Set.insert (snd x) (F `` S) else (F `` S))" by (force intro: rev_ImageI) show ?thesis using assms by (induct R) (auto simp: * ) qed lemma insert_relcomp_union_fold: assumes "finite S" shows "{x} O S \<union> X = Finite_Set.fold (\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A') X S" proof - interpret comp_fun_commute "\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A'" proof - interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert) show "comp_fun_commute (\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A')" by standard (auto simp add: fun_eq_iff split: prod.split) qed have *: "{x} O S = {(x', z). x' = fst x \<and> (snd x, z) \<in> S}" by (auto simp: relcomp_unfold intro!: exI) show ?thesis unfolding * using \<open>finite S\<close> by (induct S) (auto split: prod.split) qed lemma insert_relcomp_fold: assumes "finite S" shows "Set.insert x R O S = Finite_Set.fold (\<lambda>(w,z) A'. if snd x = w then Set.insert (fst x,z) A' else A') (R O S) S" proof - have "Set.insert x R O S = ({x} O S) \<union> (R O S)" by auto then show ?thesis by (auto simp: insert_relcomp_union_fold [OF assms]) qed lemma comp_fun_commute_relcomp_fold: assumes "finite S" shows "comp_fun_commute (\<lambda>(x,y) A. Finite_Set.fold (\<lambda>(w,z) A'. if y = w then Set.insert (x,z) A' else A') A S)" proof - have *: "\<And>a b A. Finite_Set.fold (\<lambda>(w, z) A'. if b = w then Set.insert (a, z) A' else A') A S = {(a,b)} O S \<union> A" by (auto simp: insert_relcomp_union_fold[OF assms] cong: if_cong) show ?thesis by standard (auto simp: * ) qed lemma relcomp_fold: assumes "finite R" "finite S" shows "R O S = Finite_Set.fold (\<lambda>(x,y) A. Finite_Set.fold (\<lambda>(w,z) A'. if y = w then Set.insert (x,z) A' else A') A S) {} R" proof - interpret commute_relcomp_fold: comp_fun_commute "(\<lambda>(x, y) A. Finite_Set.fold (\<lambda>(w, z) A'. if y = w then insert (x, z) A' else A') A S)" by (fact comp_fun_commute_relcomp_fold[OF \<open>finite S\<close>]) from assms show ?thesis by (induct R) (auto simp: comp_fun_commute_relcomp_fold insert_relcomp_fold cong: if_cong) qed subsection \<open>Locales as mini-packages for fold operations\<close> subsubsection \<open>The natural case\<close> locale folding_on = fixes S :: "'a set" fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: "'b" assumes comp_fun_commute_on: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f y o f x = f x o f y" begin interpretation fold?: comp_fun_commute_on S f by standard (simp add: comp_fun_commute_on) definition F :: "'a set \<Rightarrow> 'b" where eq_fold: "F A = Finite_Set.fold f z A" lemma empty [simp]: "F {} = z" by (simp add: eq_fold) lemma infinite [simp]: "\<not> finite A \<Longrightarrow> F A = z" by (simp add: eq_fold) lemma insert [simp]: assumes "insert x A \<subseteq> S" and "finite A" and "x \<notin> A" shows "F (insert x A) = f x (F A)" proof - from fold_insert assms have "Finite_Set.fold f z (insert x A) = f x (Finite_Set.fold f z A)" by simp with \<open>finite A\<close> show ?thesis by (simp add: eq_fold fun_eq_iff) qed lemma remove: assumes "A \<subseteq> S" and "finite A" and "x \<in> A" shows "F A = f x (F (A - {x}))" proof - from \<open>x \<in> A\<close> obtain B where A: "A = insert x B" and "x \<notin> B" by (auto dest: mk_disjoint_insert) moreover from \<open>finite A\<close> A have "finite B" by simp ultimately show ?thesis using \<open>A \<subseteq> S\<close> by auto qed lemma insert_remove: assumes "insert x A \<subseteq> S" and "finite A" shows "F (insert x A) = f x (F (A - {x}))" using assms by (cases "x \<in> A") (simp_all add: remove insert_absorb) end subsubsection \<open>With idempotency\<close> locale folding_idem_on = folding_on + assumes comp_fun_idem_on: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f x \<circ> f x = f x" begin declare insert [simp del] interpretation fold?: comp_fun_idem_on S f by standard (simp_all add: comp_fun_commute_on comp_fun_idem_on) lemma insert_idem [simp]: assumes "insert x A \<subseteq> S" and "finite A" shows "F (insert x A) = f x (F A)" proof - from fold_insert_idem assms have "fold f z (insert x A) = f x (fold f z A)" by simp with \<open>finite A\<close> show ?thesis by (simp add: eq_fold fun_eq_iff) qed end subsubsection \<open>\<^term>\<open>UNIV\<close> as the carrier set\<close> locale folding = fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: "'b" assumes comp_fun_commute: "f y \<circ> f x = f x \<circ> f y" begin lemma (in -) folding_def': "folding f = folding_on UNIV f" unfolding folding_def folding_on_def by blast text \<open> Again, we abuse the \<open>rewrites\<close> functionality of locales to remove trivial assumptions that result from instantiating the carrier set to \<^term>\<open>UNIV\<close>. \<close> sublocale folding_on UNIV f rewrites "\<And>X. (X \<subseteq> UNIV) \<equiv> True" and "\<And>x. x \<in> UNIV \<equiv> True" and "\<And>P. (True \<Longrightarrow> P) \<equiv> Trueprop P" and "\<And>P Q. (True \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> True \<Longrightarrow> PROP Q)" proof - show "folding_on UNIV f" by standard (simp add: comp_fun_commute) qed simp_all end locale folding_idem = folding + assumes comp_fun_idem: "f x \<circ> f x = f x" begin lemma (in -) folding_idem_def': "folding_idem f = folding_idem_on UNIV f" unfolding folding_idem_def folding_def' folding_idem_on_def unfolding folding_idem_axioms_def folding_idem_on_axioms_def by blast text \<open> Again, we abuse the \<open>rewrites\<close> functionality of locales to remove trivial assumptions that result from instantiating the carrier set to \<^term>\<open>UNIV\<close>. \<close> sublocale folding_idem_on UNIV f rewrites "\<And>X. (X \<subseteq> UNIV) \<equiv> True" and "\<And>x. x \<in> UNIV \<equiv> True" and "\<And>P. (True \<Longrightarrow> P) \<equiv> Trueprop P" and "\<And>P Q. (True \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> True \<Longrightarrow> PROP Q)" proof - show "folding_idem_on UNIV f" by standard (simp add: comp_fun_idem) qed simp_all end subsection \<open>Finite cardinality\<close> text \<open> The traditional definition \<^prop>\<open>card A \<equiv> LEAST n. \<exists>f. A = {f i |i. i < n}\<close> is ugly to work with. But now that we have \<^const>\<open>fold\<close> things are easy: \<close> global_interpretation card: folding "\<lambda>_. Suc" 0 defines card = "folding_on.F (\<lambda>_. Suc) 0" by standard (rule refl) lemma card_insert_disjoint: "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> card (insert x A) = Suc (card A)" by (fact card.insert) lemma card_insert_if: "finite A \<Longrightarrow> card (insert x A) = (if x \<in> A then card A else Suc (card A))" by auto (simp add: card.insert_remove card.remove) lemma card_ge_0_finite: "card A > 0 \<Longrightarrow> finite A" by (rule ccontr) simp lemma card_0_eq [simp]: "finite A \<Longrightarrow> card A = 0 \<longleftrightarrow> A = {}" by (auto dest: mk_disjoint_insert) lemma finite_UNIV_card_ge_0: "finite (UNIV :: 'a set) \<Longrightarrow> card (UNIV :: 'a set) > 0" by (rule ccontr) simp lemma card_eq_0_iff: "card A = 0 \<longleftrightarrow> A = {} \<or> \<not> finite A" by auto lemma card_range_greater_zero: "finite (range f) \<Longrightarrow> card (range f) > 0" by (rule ccontr) (simp add: card_eq_0_iff) lemma card_gt_0_iff: "0 < card A \<longleftrightarrow> A \<noteq> {} \<and> finite A" by (simp add: neq0_conv [symmetric] card_eq_0_iff) lemma card_Suc_Diff1: assumes "finite A" "x \<in> A" shows "Suc (card (A - {x})) = card A" proof - have "Suc (card (A - {x})) = card (insert x (A - {x}))" using assms by (simp add: card.insert_remove) also have "... = card A" using assms by (simp add: card_insert_if) finally show ?thesis . qed lemma card_insert_le_m1: assumes "n > 0" "card y \<le> n - 1" shows "card (insert x y) \<le> n" using assms by (cases "finite y") (auto simp: card_insert_if) lemma card_Diff_singleton: assumes "x \<in> A" shows "card (A - {x}) = card A - 1" proof (cases "finite A") case True with assms show ?thesis by (simp add: card_Suc_Diff1 [symmetric]) qed auto lemma card_Diff_singleton_if: "card (A - {x}) = (if x \<in> A then card A - 1 else card A)" by (simp add: card_Diff_singleton) lemma card_Diff_insert[simp]: assumes "a \<in> A" and "a \<notin> B" shows "card (A - insert a B) = card (A - B) - 1" proof - have "A - insert a B = (A - B) - {a}" using assms by blast then show ?thesis using assms by (simp add: card_Diff_singleton) qed lemma card_insert_le: "card A \<le> card (insert x A)" proof (cases "finite A") case True then show ?thesis by (simp add: card_insert_if) qed auto lemma card_Collect_less_nat[simp]: "card {i::nat. i < n} = n" by (induct n) (simp_all add:less_Suc_eq Collect_disj_eq) lemma card_Collect_le_nat[simp]: "card {i::nat. i \<le> n} = Suc n" using card_Collect_less_nat[of "Suc n"] by (simp add: less_Suc_eq_le) lemma card_mono: assumes "finite B" and "A \<subseteq> B" shows "card A \<le> card B" proof - from assms have "finite A" by (auto intro: finite_subset) then show ?thesis using assms proof (induct A arbitrary: B) case empty then show ?case by simp next case (insert x A) then have "x \<in> B" by simp from insert have "A \<subseteq> B - {x}" and "finite (B - {x})" by auto with insert.hyps have "card A \<le> card (B - {x})" by auto with \<open>finite A\<close> \<open>x \<notin> A\<close> \<open>finite B\<close> \<open>x \<in> B\<close> show ?case by simp (simp only: card.remove) qed qed lemma card_seteq: assumes "finite B" and A: "A \<subseteq> B" "card B \<le> card A" shows "A = B" using assms proof (induction arbitrary: A rule: finite_induct) case (insert b B) then have A: "finite A" "A - {b} \<subseteq> B" by force+ then have "card B \<le> card (A - {b})" using insert by (auto simp add: card_Diff_singleton_if) then have "A - {b} = B" using A insert.IH by auto then show ?case using insert.hyps insert.prems by auto qed auto lemma psubset_card_mono: "finite B \<Longrightarrow> A < B \<Longrightarrow> card A < card B" using card_seteq [of B A] by (auto simp add: psubset_eq) lemma card_Un_Int: assumes "finite A" "finite B" shows "card A + card B = card (A \<union> B) + card (A \<inter> B)" using assms proof (induct A) case empty then show ?case by simp next case insert then show ?case by (auto simp add: insert_absorb Int_insert_left) qed lemma card_Un_disjoint: "finite A \<Longrightarrow> finite B \<Longrightarrow> A \<inter> B = {} \<Longrightarrow> card (A \<union> B) = card A + card B" using card_Un_Int [of A B] by simp lemma card_Un_disjnt: "\<lbrakk>finite A; finite B; disjnt A B\<rbrakk> \<Longrightarrow> card (A \<union> B) = card A + card B" by (simp add: card_Un_disjoint disjnt_def) lemma card_Un_le: "card (A \<union> B) \<le> card A + card B" proof (cases "finite A \<and> finite B") case True then show ?thesis using le_iff_add card_Un_Int [of A B] by auto qed auto lemma card_Diff_subset: assumes "finite B" and "B \<subseteq> A" shows "card (A - B) = card A - card B" using assms proof (cases "finite A") case False with assms show ?thesis by simp next case True with assms show ?thesis by (induct B arbitrary: A) simp_all qed lemma card_Diff_subset_Int: assumes "finite (A \<inter> B)" shows "card (A - B) = card A - card (A \<inter> B)" proof - have "A - B = A - A \<inter> B" by auto with assms show ?thesis by (simp add: card_Diff_subset) qed lemma diff_card_le_card_Diff: assumes "finite B" shows "card A - card B \<le> card (A - B)" proof - have "card A - card B \<le> card A - card (A \<inter> B)" using card_mono[OF assms Int_lower2, of A] by arith also have "\<dots> = card (A - B)" using assms by (simp add: card_Diff_subset_Int) finally show ?thesis . qed lemma card_le_sym_Diff: assumes "finite A" "finite B" "card A \<le> card B" shows "card(A - B) \<le> card(B - A)" proof - have "card(A - B) = card A - card (A \<inter> B)" using assms(1,2) by(simp add: card_Diff_subset_Int) also have "\<dots> \<le> card B - card (A \<inter> B)" using assms(3) by linarith also have "\<dots> = card(B - A)" using assms(1,2) by(simp add: card_Diff_subset_Int Int_commute) finally show ?thesis . qed lemma card_less_sym_Diff: assumes "finite A" "finite B" "card A < card B" shows "card(A - B) < card(B - A)" proof - have "card(A - B) = card A - card (A \<inter> B)" using assms(1,2) by(simp add: card_Diff_subset_Int) also have "\<dots> < card B - card (A \<inter> B)" using assms(1,3) by (simp add: card_mono diff_less_mono) also have "\<dots> = card(B - A)" using assms(1,2) by(simp add: card_Diff_subset_Int Int_commute) finally show ?thesis . qed lemma card_Diff1_less_iff: "card (A - {x}) < card A \<longleftrightarrow> finite A \<and> x \<in> A" proof (cases "finite A \<and> x \<in> A") case True then show ?thesis by (auto simp: card_gt_0_iff intro: diff_less) qed auto lemma card_Diff1_less: "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> card (A - {x}) < card A" unfolding card_Diff1_less_iff by auto lemma card_Diff2_less: assumes "finite A" "x \<in> A" "y \<in> A" shows "card (A - {x} - {y}) < card A" proof (cases "x = y") case True with assms show ?thesis by (simp add: card_Diff1_less del: card_Diff_insert) next case False then have "card (A - {x} - {y}) < card (A - {x})" "card (A - {x}) < card A" using assms by (intro card_Diff1_less; simp)+ then show ?thesis by (blast intro: less_trans) qed lemma card_Diff1_le: "card (A - {x}) \<le> card A" proof (cases "finite A") case True then show ?thesis by (cases "x \<in> A") (simp_all add: card_Diff1_less less_imp_le) qed auto lemma card_psubset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> card A < card B \<Longrightarrow> A < B" by (erule psubsetI) blast lemma card_le_inj: assumes fA: "finite A" and fB: "finite B" and c: "card A \<le> card B" shows "\<exists>f. f ` A \<subseteq> B \<and> inj_on f A" using fA fB c proof (induct arbitrary: B rule: finite_induct) case empty then show ?case by simp next case (insert x s t) then show ?case proof (induct rule: finite_induct [OF insert.prems(1)]) case 1 then show ?case by simp next case (2 y t) from "2.prems"(1,2,5) "2.hyps"(1,2) have cst: "card s \<le> card t" by simp from "2.prems"(3) [OF "2.hyps"(1) cst] obtain f where *: "f ` s \<subseteq> t" "inj_on f s" by blast let ?g = "(\<lambda>a. if a = x then y else f a)" have "?g ` insert x s \<subseteq> insert y t \<and> inj_on ?g (insert x s)" using * "2.prems"(2) "2.hyps"(2) unfolding inj_on_def by auto then show ?case by (rule exI[where ?x="?g"]) qed qed lemma card_subset_eq: assumes fB: "finite B" and AB: "A \<subseteq> B" and c: "card A = card B" shows "A = B" proof - from fB AB have fA: "finite A" by (auto intro: finite_subset) from fA fB have fBA: "finite (B - A)" by auto have e: "A \<inter> (B - A) = {}" by blast have eq: "A \<union> (B - A) = B" using AB by blast from card_Un_disjoint[OF fA fBA e, unfolded eq c] have "card (B - A) = 0" by arith then have "B - A = {}" unfolding card_eq_0_iff using fA fB by simp with AB show "A = B" by blast qed lemma insert_partition: "x \<notin> F \<Longrightarrow> \<forall>c1 \<in> insert x F. \<forall>c2 \<in> insert x F. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {} \<Longrightarrow> x \<inter> \<Union>F = {}" by auto lemma finite_psubset_induct [consumes 1, case_names psubset]: assumes finite: "finite A" and major: "\<And>A. finite A \<Longrightarrow> (\<And>B. B \<subset> A \<Longrightarrow> P B) \<Longrightarrow> P A" shows "P A" using finite proof (induct A taking: card rule: measure_induct_rule) case (less A) have fin: "finite A" by fact have ih: "card B < card A \<Longrightarrow> finite B \<Longrightarrow> P B" for B by fact have "P B" if "B \<subset> A" for B proof - from that have "card B < card A" using psubset_card_mono fin by blast moreover from that have "B \<subseteq> A" by auto then have "finite B" using fin finite_subset by blast ultimately show ?thesis using ih by simp qed with fin show "P A" using major by blast qed lemma finite_induct_select [consumes 1, case_names empty select]: assumes "finite S" and "P {}" and select: "\<And>T. T \<subset> S \<Longrightarrow> P T \<Longrightarrow> \<exists>s\<in>S - T. P (insert s T)" shows "P S" proof - have "0 \<le> card S" by simp then have "\<exists>T \<subseteq> S. card T = card S \<and> P T" proof (induct rule: dec_induct) case base with \<open>P {}\<close> show ?case by (intro exI[of _ "{}"]) auto next case (step n) then obtain T where T: "T \<subseteq> S" "card T = n" "P T" by auto with \<open>n < card S\<close> have "T \<subset> S" "P T" by auto with select[of T] obtain s where "s \<in> S" "s \<notin> T" "P (insert s T)" by auto with step(2) T \<open>finite S\<close> show ?case by (intro exI[of _ "insert s T"]) (auto dest: finite_subset) qed with \<open>finite S\<close> show "P S" by (auto dest: card_subset_eq) qed lemma remove_induct [case_names empty infinite remove]: assumes empty: "P ({} :: 'a set)" and infinite: "\<not> finite B \<Longrightarrow> P B" and remove: "\<And>A. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P (A - {x})) \<Longrightarrow> P A" shows "P B" proof (cases "finite B") case False then show ?thesis by (rule infinite) next case True define A where "A = B" with True have "finite A" "A \<subseteq> B" by simp_all then show "P A" proof (induct "card A" arbitrary: A) case 0 then have "A = {}" by auto with empty show ?case by simp next case (Suc n A) from \<open>A \<subseteq> B\<close> and \<open>finite B\<close> have "finite A" by (rule finite_subset) moreover from Suc.hyps have "A \<noteq> {}" by auto moreover note \<open>A \<subseteq> B\<close> moreover have "P (A - {x})" if x: "x \<in> A" for x using x Suc.prems \<open>Suc n = card A\<close> by (intro Suc) auto ultimately show ?case by (rule remove) qed qed lemma finite_remove_induct [consumes 1, case_names empty remove]: fixes P :: "'a set \<Rightarrow> bool" assumes "finite B" and "P {}" and "\<And>A. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P (A - {x})) \<Longrightarrow> P A" defines "B' \<equiv> B" shows "P B'" by (induct B' rule: remove_induct) (simp_all add: assms) text \<open>Main cardinality theorem.\<close> lemma card_partition [rule_format]: "finite C \<Longrightarrow> finite (\<Union>C) \<Longrightarrow> (\<forall>c\<in>C. card c = k) \<Longrightarrow> (\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}) \<Longrightarrow> k * card C = card (\<Union>C)" proof (induct rule: finite_induct) case empty then show ?case by simp next case (insert x F) then show ?case by (simp add: card_Un_disjoint insert_partition finite_subset [of _ "\<Union>(insert _ _)"]) qed lemma card_eq_UNIV_imp_eq_UNIV: assumes fin: "finite (UNIV :: 'a set)" and card: "card A = card (UNIV :: 'a set)" shows "A = (UNIV :: 'a set)" proof show "A \<subseteq> UNIV" by simp show "UNIV \<subseteq> A" proof show "x \<in> A" for x proof (rule ccontr) assume "x \<notin> A" then have "A \<subset> UNIV" by auto with fin have "card A < card (UNIV :: 'a set)" by (fact psubset_card_mono) with card show False by simp qed qed qed text \<open>The form of a finite set of given cardinality\<close> lemma card_eq_SucD: assumes "card A = Suc k" shows "\<exists>b B. A = insert b B \<and> b \<notin> B \<and> card B = k \<and> (k = 0 \<longrightarrow> B = {})" proof - have fin: "finite A" using assms by (auto intro: ccontr) moreover have "card A \<noteq> 0" using assms by auto ultimately obtain b where b: "b \<in> A" by auto show ?thesis proof (intro exI conjI) show "A = insert b (A - {b})" using b by blast show "b \<notin> A - {b}" by blast show "card (A - {b}) = k" and "k = 0 \<longrightarrow> A - {b} = {}" using assms b fin by (fastforce dest: mk_disjoint_insert)+ qed qed lemma card_Suc_eq: "card A = Suc k \<longleftrightarrow> (\<exists>b B. A = insert b B \<and> b \<notin> B \<and> card B = k \<and> (k = 0 \<longrightarrow> B = {}))" by (auto simp: card_insert_if card_gt_0_iff elim!: card_eq_SucD) lemma card_Suc_eq_finite: "card A = Suc k \<longleftrightarrow> (\<exists>b B. A = insert b B \<and> b \<notin> B \<and> card B = k \<and> finite B)" unfolding card_Suc_eq using card_gt_0_iff by fastforce lemma card_1_singletonE: assumes "card A = 1" obtains x where "A = {x}" using assms by (auto simp: card_Suc_eq) lemma is_singleton_altdef: "is_singleton A \<longleftrightarrow> card A = 1" unfolding is_singleton_def by (auto elim!: card_1_singletonE is_singletonE simp del: One_nat_def) lemma card_1_singleton_iff: "card A = Suc 0 \<longleftrightarrow> (\<exists>x. A = {x})" by (simp add: card_Suc_eq) lemma card_le_Suc0_iff_eq: assumes "finite A" shows "card A \<le> Suc 0 \<longleftrightarrow> (\<forall>a1 \<in> A. \<forall>a2 \<in> A. a1 = a2)" (is "?C = ?A") proof assume ?C thus ?A using assms by (auto simp: le_Suc_eq dest: card_eq_SucD) next assume ?A show ?C proof cases assume "A = {}" thus ?C using \<open>?A\<close> by simp next assume "A \<noteq> {}" then obtain a where "A = {a}" using \<open>?A\<close> by blast thus ?C by simp qed qed lemma card_le_Suc_iff: "Suc n \<le> card A = (\<exists>a B. A = insert a B \<and> a \<notin> B \<and> n \<le> card B \<and> finite B)" proof (cases "finite A") case True then show ?thesis by (fastforce simp: card_Suc_eq less_eq_nat.simps split: nat.splits) qed auto lemma finite_fun_UNIVD2: assumes fin: "finite (UNIV :: ('a \<Rightarrow> 'b) set)" shows "finite (UNIV :: 'b set)" proof - from fin have "finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary))" for arbitrary by (rule finite_imageI) moreover have "UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary)" for arbitrary by (rule UNIV_eq_I) auto ultimately show "finite (UNIV :: 'b set)" by simp qed lemma card_UNIV_unit [simp]: "card (UNIV :: unit set) = 1" unfolding UNIV_unit by simp lemma infinite_arbitrarily_large: assumes "\<not> finite A" shows "\<exists>B. finite B \<and> card B = n \<and> B \<subseteq> A" proof (induction n) case 0 show ?case by (intro exI[of _ "{}"]) auto next case (Suc n) then obtain B where B: "finite B \<and> card B = n \<and> B \<subseteq> A" .. with \<open>\<not> finite A\<close> have "A \<noteq> B" by auto with B have "B \<subset> A" by auto then have "\<exists>x. x \<in> A - B" by (elim psubset_imp_ex_mem) then obtain x where x: "x \<in> A - B" .. with B have "finite (insert x B) \<and> card (insert x B) = Suc n \<and> insert x B \<subseteq> A" by auto then show "\<exists>B. finite B \<and> card B = Suc n \<and> B \<subseteq> A" .. qed text \<open>Sometimes, to prove that a set is finite, it is convenient to work with finite subsets and to show that their cardinalities are uniformly bounded. This possibility is formalized in the next criterion.\<close> lemma finite_if_finite_subsets_card_bdd: assumes "\<And>G. G \<subseteq> F \<Longrightarrow> finite G \<Longrightarrow> card G \<le> C" shows "finite F \<and> card F \<le> C" proof (cases "finite F") case False obtain n::nat where n: "n > max C 0" by auto obtain G where G: "G \<subseteq> F" "card G = n" using infinite_arbitrarily_large[OF False] by auto hence "finite G" using \<open>n > max C 0\<close> using card.infinite gr_implies_not0 by blast hence False using assms G n not_less by auto thus ?thesis .. next case True thus ?thesis using assms[of F] by auto qed lemma obtain_subset_with_card_n: assumes "n \<le> card S" obtains T where "T \<subseteq> S" "card T = n" "finite T" proof - obtain n' where "card S = n + n'" using le_Suc_ex[OF assms] by blast with that show thesis proof (induct n' arbitrary: S) case 0 thus ?case by (cases "finite S") auto next case Suc thus ?case by (auto simp add: card_Suc_eq) qed qed lemma exists_subset_between: assumes "card A \<le> n" "n \<le> card C" "A \<subseteq> C" "finite C" shows "\<exists>B. A \<subseteq> B \<and> B \<subseteq> C \<and> card B = n" using assms proof (induct n arbitrary: A C) case 0 thus ?case using finite_subset[of A C] by (intro exI[of _ "{}"], auto) next case (Suc n A C) show ?case proof (cases "A = {}") case True from obtain_subset_with_card_n[OF Suc(3)] obtain B where "B \<subseteq> C" "card B = Suc n" by blast thus ?thesis unfolding True by blast next case False then obtain a where a: "a \<in> A" by auto let ?A = "A - {a}" let ?C = "C - {a}" have 1: "card ?A \<le> n" using Suc(2-) a using finite_subset by fastforce have 2: "card ?C \<ge> n" using Suc(2-) a by auto from Suc(1)[OF 1 2 _ finite_subset[OF _ Suc(5)]] Suc(2-) obtain B where "?A \<subseteq> B" "B \<subseteq> ?C" "card B = n" by blast thus ?thesis using a Suc(2-) by (intro exI[of _ "insert a B"], auto intro!: card_insert_disjoint finite_subset[of B C]) qed qed subsubsection \<open>Cardinality of image\<close> lemma card_image_le: "finite A \<Longrightarrow> card (f ` A) \<le> card A" by (induct rule: finite_induct) (simp_all add: le_SucI card_insert_if) lemma card_image: "inj_on f A \<Longrightarrow> card (f ` A) = card A" proof (induct A rule: infinite_finite_induct) case (infinite A) then have "\<not> finite (f ` A)" by (auto dest: finite_imageD) with infinite show ?case by simp qed simp_all lemma bij_betw_same_card: "bij_betw f A B \<Longrightarrow> card A = card B" by (auto simp: card_image bij_betw_def) lemma endo_inj_surj: "finite A \<Longrightarrow> f ` A \<subseteq> A \<Longrightarrow> inj_on f A \<Longrightarrow> f ` A = A" by (simp add: card_seteq card_image) lemma eq_card_imp_inj_on: assumes "finite A" "card(f ` A) = card A" shows "inj_on f A" using assms proof (induct rule:finite_induct) case empty show ?case by simp next case (insert x A) then show ?case using card_image_le [of A f] by (simp add: card_insert_if split: if_splits) qed lemma inj_on_iff_eq_card: "finite A \<Longrightarrow> inj_on f A \<longleftrightarrow> card (f ` A) = card A" by (blast intro: card_image eq_card_imp_inj_on) lemma card_inj_on_le: assumes "inj_on f A" "f ` A \<subseteq> B" "finite B" shows "card A \<le> card B" proof - have "finite A" using assms by (blast intro: finite_imageD dest: finite_subset) then show ?thesis using assms by (force intro: card_mono simp: card_image [symmetric]) qed lemma inj_on_iff_card_le: "\<lbrakk> finite A; finite B \<rbrakk> \<Longrightarrow> (\<exists>f. inj_on f A \<and> f ` A \<le> B) = (card A \<le> card B)" using card_inj_on_le[of _ A B] card_le_inj[of A B] by blast lemma surj_card_le: "finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> card B \<le> card A" by (blast intro: card_image_le card_mono le_trans) lemma card_bij_eq: "inj_on f A \<Longrightarrow> f ` A \<subseteq> B \<Longrightarrow> inj_on g B \<Longrightarrow> g ` B \<subseteq> A \<Longrightarrow> finite A \<Longrightarrow> finite B \<Longrightarrow> card A = card B" by (auto intro: le_antisym card_inj_on_le) lemma bij_betw_finite: "bij_betw f A B \<Longrightarrow> finite A \<longleftrightarrow> finite B" unfolding bij_betw_def using finite_imageD [of f A] by auto lemma inj_on_finite: "inj_on f A \<Longrightarrow> f ` A \<le> B \<Longrightarrow> finite B \<Longrightarrow> finite A" using finite_imageD finite_subset by blast lemma card_vimage_inj_on_le: assumes "inj_on f D" "finite A" shows "card (f-`A \<inter> D) \<le> card A" proof (rule card_inj_on_le) show "inj_on f (f -` A \<inter> D)" by (blast intro: assms inj_on_subset) qed (use assms in auto) lemma card_vimage_inj: "inj f \<Longrightarrow> A \<subseteq> range f \<Longrightarrow> card (f -` A) = card A" by (auto 4 3 simp: subset_image_iff inj_vimage_image_eq intro: card_image[symmetric, OF subset_inj_on]) lemma card_inverse[simp]: "card (R\<inverse>) = card R" proof - have *: "\<And>R. prod.swap ` R = R\<inverse>" by auto { assume "\<not>finite R" hence ?thesis by auto } moreover { assume "finite R" with card_image_le[of R prod.swap] card_image_le[of "R\<inverse>" prod.swap] have ?thesis by (auto simp: * ) } ultimately show ?thesis by blast qed subsubsection \<open>Pigeonhole Principles\<close> lemma pigeonhole: "card A > card (f ` A) \<Longrightarrow> \<not> inj_on f A " by (auto dest: card_image less_irrefl_nat) lemma pigeonhole_infinite: assumes "\<not> finite A" and "finite (f`A)" shows "\<exists>a0\<in>A. \<not> finite {a\<in>A. f a = f a0}" using assms(2,1) proof (induct "f`A" arbitrary: A rule: finite_induct) case empty then show ?case by simp next case (insert b F) show ?case proof (cases "finite {a\<in>A. f a = b}") case True with \<open>\<not> finite A\<close> have "\<not> finite (A - {a\<in>A. f a = b})" by simp also have "A - {a\<in>A. f a = b} = {a\<in>A. f a \<noteq> b}" by blast finally have "\<not> finite {a\<in>A. f a \<noteq> b}" . from insert(3)[OF _ this] insert(2,4) show ?thesis by simp (blast intro: rev_finite_subset) next case False then have "{a \<in> A. f a = b} \<noteq> {}" by force with False show ?thesis by blast qed qed lemma pigeonhole_infinite_rel: assumes "\<not> finite A" and "finite B" and "\<forall>a\<in>A. \<exists>b\<in>B. R a b" shows "\<exists>b\<in>B. \<not> finite {a:A. R a b}" proof - let ?F = "\<lambda>a. {b\<in>B. R a b}" from finite_Pow_iff[THEN iffD2, OF \<open>finite B\<close>] have "finite (?F ` A)" by (blast intro: rev_finite_subset) from pigeonhole_infinite [where f = ?F, OF assms(1) this] obtain a0 where "a0 \<in> A" and infinite: "\<not> finite {a\<in>A. ?F a = ?F a0}" .. obtain b0 where "b0 \<in> B" and "R a0 b0" using \<open>a0 \<in> A\<close> assms(3) by blast have "finite {a\<in>A. ?F a = ?F a0}" if "finite {a\<in>A. R a b0}" using \<open>b0 \<in> B\<close> \<open>R a0 b0\<close> that by (blast intro: rev_finite_subset) with infinite \<open>b0 \<in> B\<close> show ?thesis by blast qed subsubsection \<open>Cardinality of sums\<close> lemma card_Plus: assumes "finite A" "finite B" shows "card (A <+> B) = card A + card B" proof - have "Inl`A \<inter> Inr`B = {}" by fast with assms show ?thesis by (simp add: Plus_def card_Un_disjoint card_image) qed lemma card_Plus_conv_if: "card (A <+> B) = (if finite A \<and> finite B then card A + card B else 0)" by (auto simp add: card_Plus) text \<open>Relates to equivalence classes. Based on a theorem of F. Kammüller.\<close> lemma dvd_partition: assumes f: "finite (\<Union>C)" and "\<forall>c\<in>C. k dvd card c" "\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}" shows "k dvd card (\<Union>C)" proof - have "finite C" by (rule finite_UnionD [OF f]) then show ?thesis using assms proof (induct rule: finite_induct) case empty show ?case by simp next case (insert c C) then have "c \<inter> \<Union>C = {}" by auto with insert show ?case by (simp add: card_Un_disjoint) qed qed subsection \<open>Minimal and maximal elements of finite sets\<close> context begin qualified lemma assumes "finite A" and "A \<noteq> {}" and "transp_on A R" and "asymp_on A R" shows bex_min_element: "\<exists>m \<in> A. \<forall>x \<in> A. x \<noteq> m \<longrightarrow> \<not> R x m" and bex_max_element: "\<exists>m \<in> A. \<forall>x \<in> A. x \<noteq> m \<longrightarrow> \<not> R m x" unfolding atomize_conj using assms proof (induction A rule: finite_induct) case empty hence False by simp thus ?case .. next case (insert a A') show ?case proof (cases "A' = {}") case True show ?thesis proof (intro conjI bexI) show "\<forall>x\<in>insert a A'. x \<noteq> a \<longrightarrow> \<not> R x a" and "\<forall>x\<in>insert a A'. x \<noteq> a \<longrightarrow> \<not> R a x" using True by blast+ qed simp_all next case False moreover have "transp_on A' R" using insert.prems transp_on_subset by blast moreover have "asymp_on A' R" using insert.prems asymp_on_subset by blast ultimately obtain min max where "min \<in> A'" and "max \<in> A'" and min_is_min: "\<forall>x\<in>A'. x \<noteq> min \<longrightarrow> \<not> R x min" and max_is_max: "\<forall>x\<in>A'. x \<noteq> max \<longrightarrow> \<not> R max x" using insert.IH by auto show ?thesis proof (rule conjI) show "\<exists>min\<in>insert a A'. \<forall>x\<in>insert a A'. x \<noteq> min \<longrightarrow> \<not> R x min" proof (cases "R a min") case True show ?thesis proof (intro bexI ballI impI) show "a \<in> insert a A'" by simp next fix x show "x \<in> insert a A' \<Longrightarrow> x \<noteq> a \<Longrightarrow> \<not> R x a" using True \<open>min \<in> A'\<close> min_is_min[rule_format, of x] insert.prems(2,3) by (auto dest: asymp_onD transp_onD) qed next case False show ?thesis proof (rule bexI) show "min \<in> insert a A'" using \<open>min \<in> A'\<close> by auto next show "\<forall>x\<in>insert a A'. x \<noteq> min \<longrightarrow> \<not> R x min" using False min_is_min by blast qed qed next show "\<exists>max\<in>insert a A'. \<forall>x\<in>insert a A'. x \<noteq> max \<longrightarrow> \<not> R max x" proof (cases "R max a") case True show ?thesis proof (intro bexI ballI impI) show "a \<in> insert a A'" by simp next fix x show "x \<in> insert a A' \<Longrightarrow> x \<noteq> a \<Longrightarrow> \<not> R a x" using True \<open>max \<in> A'\<close> max_is_max[rule_format, of x] insert.prems(2,3) by (auto dest: asymp_onD transp_onD) qed next case False show ?thesis proof (rule bexI) show "max \<in> insert a A'" using \<open>max \<in> A'\<close> by auto next show "\<forall>x\<in>insert a A'. x \<noteq> max \<longrightarrow> \<not> R max x" using False max_is_max by blast qed qed qed qed qed end text \<open>The following alternative form might sometimes be easier to work with.\<close> lemma is_min_element_in_set_iff: "asymp_on A R \<Longrightarrow> (\<forall>y \<in> A. y \<noteq> x \<longrightarrow> \<not> R y x) \<longleftrightarrow> (\<forall>y. R y x \<longrightarrow> y \<notin> A)" by (auto dest: asymp_onD) lemma is_max_element_in_set_iff: "asymp_on A R \<Longrightarrow> (\<forall>y \<in> A. y \<noteq> x \<longrightarrow> \<not> R x y) \<longleftrightarrow> (\<forall>y. R x y \<longrightarrow> y \<notin> A)" by (auto dest: asymp_onD) context begin qualified lemma assumes "finite A" and "A \<noteq> {}" and "transp_on A R" and "totalp_on A R" shows bex_least_element: "\<exists>l \<in> A. \<forall>x \<in> A. x \<noteq> l \<longrightarrow> R l x" and bex_greatest_element: "\<exists>g \<in> A. \<forall>x \<in> A. x \<noteq> g \<longrightarrow> R x g" unfolding atomize_conj using assms proof (induction A rule: finite_induct) case empty hence False by simp thus ?case .. next case (insert a A') from insert.prems(2) have transp_on_A': "transp_on A' R" by (auto intro: transp_onI dest: transp_onD) from insert.prems(3) have totalp_on_a_A'_raw: "\<forall>y \<in> A'. a \<noteq> y \<longrightarrow> R a y \<or> R y a" and totalp_on_A': "totalp_on A' R" by (simp_all add: totalp_on_def) show ?case proof (cases "A' = {}") case True thus ?thesis by simp next case False then obtain least greatest where "least \<in> A'" and least_of_A': "\<forall>x\<in>A'. x \<noteq> least \<longrightarrow> R least x" and "greatest \<in> A'" and greatest_of_A': "\<forall>x\<in>A'. x \<noteq> greatest \<longrightarrow> R x greatest" using insert.IH[OF _ transp_on_A' totalp_on_A'] by auto show ?thesis proof (rule conjI) show "\<exists>l\<in>insert a A'. \<forall>x\<in>insert a A'. x \<noteq> l \<longrightarrow> R l x" proof (cases "R a least") case True show ?thesis proof (intro bexI ballI impI) show "a \<in> insert a A'" by simp next fix x show "\<And>x. x \<in> insert a A' \<Longrightarrow> x \<noteq> a \<Longrightarrow> R a x" using True \<open>least \<in> A'\<close> least_of_A' using insert.prems(2)[THEN transp_onD, of a least] by auto qed next case False show ?thesis proof (intro bexI ballI impI) show "least \<in> insert a A'" using \<open>least \<in> A'\<close> by simp next fix x show "x \<in> insert a A' \<Longrightarrow> x \<noteq> least \<Longrightarrow> R least x" using False \<open>least \<in> A'\<close> least_of_A' totalp_on_a_A'_raw by (cases "x = a") auto qed qed next show "\<exists>g \<in> insert a A'. \<forall>x \<in> insert a A'. x \<noteq> g \<longrightarrow> R x g" proof (cases "R greatest a") case True show ?thesis proof (intro bexI ballI impI) show "a \<in> insert a A'" by simp next fix x show "\<And>x. x \<in> insert a A' \<Longrightarrow> x \<noteq> a \<Longrightarrow> R x a" using True \<open>greatest \<in> A'\<close> greatest_of_A' using insert.prems(2)[THEN transp_onD, of _ greatest a] by auto qed next case False show ?thesis proof (intro bexI ballI impI) show "greatest \<in> insert a A'" using \<open>greatest \<in> A'\<close> by simp next fix x show "x \<in> insert a A' \<Longrightarrow> x \<noteq> greatest \<Longrightarrow> R x greatest" using False \<open>greatest \<in> A'\<close> greatest_of_A' totalp_on_a_A'_raw by (cases "x = a") auto qed qed qed qed qed end subsubsection \<open>Finite orders\<close> context order begin lemma finite_has_maximal: assumes "finite A" and "A \<noteq> {}" shows "\<exists> m \<in> A. \<forall> b \<in> A. m \<le> b \<longrightarrow> m = b" proof - obtain m where "m \<in> A" and m_is_max: "\<forall>x\<in>A. x \<noteq> m \<longrightarrow> \<not> m < x" using Finite_Set.bex_max_element[OF \<open>finite A\<close> \<open>A \<noteq> {}\<close>, of "(<)"] by auto moreover have "\<forall>b \<in> A. m \<le> b \<longrightarrow> m = b" using m_is_max by (auto simp: le_less) ultimately show ?thesis by auto qed lemma finite_has_maximal2: "\<lbrakk> finite A; a \<in> A \<rbrakk> \<Longrightarrow> \<exists> m \<in> A. a \<le> m \<and> (\<forall> b \<in> A. m \<le> b \<longrightarrow> m = b)" using finite_has_maximal[of "{b \<in> A. a \<le> b}"] by fastforce lemma finite_has_minimal: assumes "finite A" and "A \<noteq> {}" shows "\<exists> m \<in> A. \<forall> b \<in> A. b \<le> m \<longrightarrow> m = b" proof - obtain m where "m \<in> A" and m_is_min: "\<forall>x\<in>A. x \<noteq> m \<longrightarrow> \<not> x < m" using Finite_Set.bex_min_element[OF \<open>finite A\<close> \<open>A \<noteq> {}\<close>, of "(<)"] by auto moreover have "\<forall>b \<in> A. b \<le> m \<longrightarrow> m = b" using m_is_min by (auto simp: le_less) ultimately show ?thesis by auto qed lemma finite_has_minimal2: "\<lbrakk> finite A; a \<in> A \<rbrakk> \<Longrightarrow> \<exists> m \<in> A. m \<le> a \<and> (\<forall> b \<in> A. b \<le> m \<longrightarrow> m = b)" using finite_has_minimal[of "{b \<in> A. b \<le> a}"] by fastforce end subsubsection \<open>Relating injectivity and surjectivity\<close> lemma finite_surj_inj: assumes "finite A" "A \<subseteq> f ` A" shows "inj_on f A" proof - have "f ` A = A" by (rule card_seteq [THEN sym]) (auto simp add: assms card_image_le) then show ?thesis using assms by (simp add: eq_card_imp_inj_on) qed lemma finite_UNIV_surj_inj: "finite(UNIV:: 'a set) \<Longrightarrow> surj f \<Longrightarrow> inj f" for f :: "'a \<Rightarrow> 'a" by (blast intro: finite_surj_inj subset_UNIV) lemma finite_UNIV_inj_surj: "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f" for f :: "'a \<Rightarrow> 'a" by (fastforce simp:surj_def dest!: endo_inj_surj) lemma surjective_iff_injective_gen: assumes fS: "finite S" and fT: "finite T" and c: "card S = card T" and ST: "f ` S \<subseteq> T" shows "(\<forall>y \<in> T. \<exists>x \<in> S. f x = y) \<longleftrightarrow> inj_on f S" (is "?lhs \<longleftrightarrow> ?rhs") proof assume h: "?lhs" { fix x y assume x: "x \<in> S" assume y: "y \<in> S" assume f: "f x = f y" from x fS have S0: "card S \<noteq> 0" by auto have "x = y" proof (rule ccontr) assume xy: "\<not> ?thesis" have th: "card S \<le> card (f ` (S - {y}))" unfolding c proof (rule card_mono) show "finite (f ` (S - {y}))" by (simp add: fS) have "\<lbrakk>x \<noteq> y; x \<in> S; z \<in> S; f x = f y\<rbrakk> \<Longrightarrow> \<exists>x \<in> S. x \<noteq> y \<and> f z = f x" for z by (cases "z = y \<longrightarrow> z = x") auto then show "T \<subseteq> f ` (S - {y})" using h xy x y f by fastforce qed also have " \<dots> \<le> card (S - {y})" by (simp add: card_image_le fS) also have "\<dots> \<le> card S - 1" using y fS by simp finally show False using S0 by arith qed } then show ?rhs unfolding inj_on_def by blast next assume h: ?rhs have "f ` S = T" by (simp add: ST c card_image card_subset_eq fT h) then show ?lhs by blast qed hide_const (open) Finite_Set.fold subsection \<open>Infinite Sets\<close> text \<open> Some elementary facts about infinite sets, mostly by Stephan Merz. Beware! Because "infinite" merely abbreviates a negation, these lemmas may not work well with \<open>blast\<close>. \<close> abbreviation infinite :: "'a set \<Rightarrow> bool" where "infinite S \<equiv> \<not> finite S" text \<open> Infinite sets are non-empty, and if we remove some elements from an infinite set, the result is still infinite. \<close> lemma infinite_UNIV_nat [iff]: "infinite (UNIV :: nat set)" proof assume "finite (UNIV :: nat set)" with finite_UNIV_inj_surj [of Suc] show False by simp (blast dest: Suc_neq_Zero surjD) qed lemma infinite_UNIV_char_0: "infinite (UNIV :: 'a::semiring_char_0 set)" proof assume "finite (UNIV :: 'a set)" with subset_UNIV have "finite (range of_nat :: 'a set)" by (rule finite_subset) moreover have "inj (of_nat :: nat \<Rightarrow> 'a)" by (simp add: inj_on_def) ultimately have "finite (UNIV :: nat set)" by (rule finite_imageD) then show False by simp qed lemma infinite_imp_nonempty: "infinite S \<Longrightarrow> S \<noteq> {}" by auto lemma infinite_remove: "infinite S \<Longrightarrow> infinite (S - {a})" by simp lemma Diff_infinite_finite: assumes "finite T" "infinite S" shows "infinite (S - T)" using \<open>finite T\<close> proof induct from \<open>infinite S\<close> show "infinite (S - {})" by auto next fix T x assume ih: "infinite (S - T)" have "S - (insert x T) = (S - T) - {x}" by (rule Diff_insert) with ih show "infinite (S - (insert x T))" by (simp add: infinite_remove) qed lemma Un_infinite: "infinite S \<Longrightarrow> infinite (S \<union> T)" by simp lemma infinite_Un: "infinite (S \<union> T) \<longleftrightarrow> infinite S \<or> infinite T" by simp lemma infinite_super: assumes "S \<subseteq> T" and "infinite S" shows "infinite T" proof assume "finite T" with \<open>S \<subseteq> T\<close> have "finite S" by (simp add: finite_subset) with \<open>infinite S\<close> show False by simp qed proposition infinite_coinduct [consumes 1, case_names infinite]: assumes "X A" and step: "\<And>A. X A \<Longrightarrow> \<exists>x\<in>A. X (A - {x}) \<or> infinite (A - {x})" shows "infinite A" proof assume "finite A" then show False using \<open>X A\<close> proof (induction rule: finite_psubset_induct) case (psubset A) then obtain x where "x \<in> A" "X (A - {x}) \<or> infinite (A - {x})" using local.step psubset.prems by blast then have "X (A - {x})" using psubset.hyps by blast show False proof (rule psubset.IH [where B = "A - {x}"]) show "A - {x} \<subset> A" using \<open>x \<in> A\<close> by blast qed fact qed qed text \<open> For any function with infinite domain and finite range there is some element that is the image of infinitely many domain elements. In particular, any infinite sequence of elements from a finite set contains some element that occurs infinitely often. \<close> lemma inf_img_fin_dom': assumes img: "finite (f ` A)" and dom: "infinite A" shows "\<exists>y \<in> f ` A. infinite (f -` {y} \<inter> A)" proof (rule ccontr) have "A \<subseteq> (\<Union>y\<in>f ` A. f -` {y} \<inter> A)" by auto moreover assume "\<not> ?thesis" with img have "finite (\<Union>y\<in>f ` A. f -` {y} \<inter> A)" by blast ultimately have "finite A" by (rule finite_subset) with dom show False by contradiction qed lemma inf_img_fin_domE': assumes "finite (f ` A)" and "infinite A" obtains y where "y \<in> f`A" and "infinite (f -` {y} \<inter> A)" using assms by (blast dest: inf_img_fin_dom') lemma inf_img_fin_dom: assumes img: "finite (f`A)" and dom: "infinite A" shows "\<exists>y \<in> f`A. infinite (f -` {y})" using inf_img_fin_dom'[OF assms] by auto lemma inf_img_fin_domE: assumes "finite (f`A)" and "infinite A" obtains y where "y \<in> f`A" and "infinite (f -` {y})" using assms by (blast dest: inf_img_fin_dom) proposition finite_image_absD: "finite (abs ` S) \<Longrightarrow> finite S" for S :: "'a::linordered_ring set" by (rule ccontr) (auto simp: abs_eq_iff vimage_def dest: inf_img_fin_dom) subsection \<open>The finite powerset operator\<close> definition Fpow :: "'a set \<Rightarrow> 'a set set" where "Fpow A \<equiv> {X. X \<subseteq> A \<and> finite X}" lemma Fpow_mono: "A \<subseteq> B \<Longrightarrow> Fpow A \<subseteq> Fpow B" unfolding Fpow_def by auto lemma empty_in_Fpow: "{} \<in> Fpow A" unfolding Fpow_def by auto lemma Fpow_not_empty: "Fpow A \<noteq> {}" using empty_in_Fpow by blast lemma Fpow_subset_Pow: "Fpow A \<subseteq> Pow A" unfolding Fpow_def by auto lemma Fpow_Pow_finite: "Fpow A = Pow A Int {A. finite A}" unfolding Fpow_def Pow_def by blast lemma inj_on_image_Fpow: assumes "inj_on f A" shows "inj_on (image f) (Fpow A)" using assms Fpow_subset_Pow[of A] subset_inj_on[of "image f" "Pow A"] inj_on_image_Pow by blast lemma image_Fpow_mono: assumes "f ` A \<subseteq> B" shows "(image f) ` (Fpow A) \<subseteq> Fpow B" using assms by(unfold Fpow_def, auto) end
lemma AE_ball_countable': "(\<And>N. N \<in> I \<Longrightarrow> AE x in M. P N x) \<Longrightarrow> countable I \<Longrightarrow> AE x in M. \<forall>N \<in> I. P N x"
import Hw5 import Lean.Elab.Print import Lean.Elab.Command theorem desiredType (A B C : Prop) (h : B ↔ C) : (A ∨ B) ↔ (A ∨ C) := sorry open Lean open Lean.Meta open Lean.Elab.Command def collectAxiomsOf (constName : Name) : MetaM (List String) := do let env ← getEnv let (_, s) := ((CollectAxioms.collect constName).run env).run {} let a := s.axioms.toList.map toString return a #eval isDefEq (Expr.const ``desiredType []) (Expr.const ``problem3 []) #eval collectAxiomsOf ``problem3
(* * Copyright 2014, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) *) theory retprefix imports "CParser.CTranslation" begin external_file "retprefix.c" install_C_file "retprefix.c" context retprefix begin thm f_body_def thm g_body_def thm h_body_def thm i_body_def lemma "\<Gamma> \<turnstile> \<lbrace> True \<rbrace> \<acute>x :== CALL h() \<lbrace> \<acute>x = 6 \<rbrace>" by vcg simp lemma "\<Gamma> \<turnstile> \<lbrace> True \<rbrace> \<acute>x :== CALL i() \<lbrace> \<acute>x = 6 \<rbrace>" by vcg simp end (* context *) end (* theory *)
[GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' ⊢ affineSpan k (range id) = ⊤ [PROOFSTEP] simp [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' f g : AffineBasis ι k P h : f.toFun = g.toFun ⊢ f = g [PROOFSTEP] cases f [GOAL] case mk ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' g : AffineBasis ι k P toFun✝ : ι → P ind'✝ : AffineIndependent k toFun✝ tot'✝ : affineSpan k (range toFun✝) = ⊤ h : { toFun := toFun✝, ind' := ind'✝, tot' := tot'✝ }.toFun = g.toFun ⊢ { toFun := toFun✝, ind' := ind'✝, tot' := tot'✝ } = g [PROOFSTEP] cases g [GOAL] case mk.mk ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' toFun✝¹ : ι → P ind'✝¹ : AffineIndependent k toFun✝¹ tot'✝¹ : affineSpan k (range toFun✝¹) = ⊤ toFun✝ : ι → P ind'✝ : AffineIndependent k toFun✝ tot'✝ : affineSpan k (range toFun✝) = ⊤ h : { toFun := toFun✝¹, ind' := ind'✝¹, tot' := tot'✝¹ }.toFun = { toFun := toFun✝, ind' := ind'✝, tot' := tot'✝ }.toFun ⊢ { toFun := toFun✝¹, ind' := ind'✝¹, tot' := tot'✝¹ } = { toFun := toFun✝, ind' := ind'✝, tot' := tot'✝ } [PROOFSTEP] congr [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' hι : IsEmpty ι ⊢ False [PROOFSTEP] simpa only [@range_eq_empty _ _ hι, AffineSubspace.span_empty, bot_ne_top] using b.tot [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e✝ e : ι ≃ ι' ⊢ affineSpan k (range (↑b ∘ ↑e.symm)) = ⊤ [PROOFSTEP] rw [e.symm.surjective.range_comp] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e✝ e : ι ≃ ι' ⊢ affineSpan k (range ↑b) = ⊤ [PROOFSTEP] exact b.3 [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι ⊢ ⊤ ≤ Submodule.span k (range fun i_1 => ↑b ↑i_1 -ᵥ ↑b i) [PROOFSTEP] suffices Submodule.span k (range fun j : { x // x ≠ i } => b ↑j -ᵥ b i) = vectorSpan k (range b) by rw [this, ← direction_affineSpan, b.tot, AffineSubspace.direction_top] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι this : Submodule.span k (range fun j => ↑b ↑j -ᵥ ↑b i) = vectorSpan k (range ↑b) ⊢ ⊤ ≤ Submodule.span k (range fun i_1 => ↑b ↑i_1 -ᵥ ↑b i) [PROOFSTEP] rw [this, ← direction_affineSpan, b.tot, AffineSubspace.direction_top] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι ⊢ Submodule.span k (range fun j => ↑b ↑j -ᵥ ↑b i) = vectorSpan k (range ↑b) [PROOFSTEP] conv_rhs => rw [← image_univ] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι | vectorSpan k (range ↑b) [PROOFSTEP] rw [← image_univ] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι | vectorSpan k (range ↑b) [PROOFSTEP] rw [← image_univ] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι | vectorSpan k (range ↑b) [PROOFSTEP] rw [← image_univ] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι ⊢ Submodule.span k (range fun j => ↑b ↑j -ᵥ ↑b i) = vectorSpan k (↑b '' univ) [PROOFSTEP] rw [vectorSpan_image_eq_span_vsub_set_right_ne k b (mem_univ i)] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι ⊢ Submodule.span k (range fun j => ↑b ↑j -ᵥ ↑b i) = Submodule.span k ((fun x => x -ᵥ ↑b i) '' (↑b '' (univ \ {i}))) [PROOFSTEP] congr [GOAL] case e_s ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι ⊢ (range fun j => ↑b ↑j -ᵥ ↑b i) = (fun x => x -ᵥ ↑b i) '' (↑b '' (univ \ {i})) [PROOFSTEP] ext v [GOAL] case e_s.h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι v : V ⊢ (v ∈ range fun j => ↑b ↑j -ᵥ ↑b i) ↔ v ∈ (fun x => x -ᵥ ↑b i) '' (↑b '' (univ \ {i})) [PROOFSTEP] simp [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j✝ : ι e : ι ≃ ι' i : ι j : { j // j ≠ i } ⊢ ↑(basisOf b i) j = ↑b ↑j -ᵥ ↑b i [PROOFSTEP] simp [basisOf] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι' ⊢ basisOf (reindex b e) i = Basis.reindex (basisOf b (↑e.symm i)) (Equiv.subtypeEquiv e (_ : ∀ (x : ι), ¬x = ↑e.symm i ↔ ¬↑e x = i)) [PROOFSTEP] ext j [GOAL] case a ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j✝ : ι e : ι ≃ ι' i : ι' j : { j // j ≠ i } ⊢ ↑(basisOf (reindex b e) i) j = ↑(Basis.reindex (basisOf b (↑e.symm i)) (Equiv.subtypeEquiv e (_ : ∀ (x : ι), ¬x = ↑e.symm i ↔ ¬↑e x = i))) j [PROOFSTEP] simp [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι q : P v : V ⊢ (fun q => 1 - ↑(Basis.sumCoords (basisOf b i)) (q -ᵥ ↑b i)) (v +ᵥ q) = ↑(-Basis.sumCoords (basisOf b i)) v +ᵥ (fun q => 1 - ↑(Basis.sumCoords (basisOf b i)) (q -ᵥ ↑b i)) q [PROOFSTEP] dsimp only [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι q : P v : V ⊢ 1 - ↑(Basis.sumCoords (basisOf b i)) (v +ᵥ q -ᵥ ↑b i) = ↑(-Basis.sumCoords (basisOf b i)) v +ᵥ (1 - ↑(Basis.sumCoords (basisOf b i)) (q -ᵥ ↑b i)) [PROOFSTEP] rw [vadd_vsub_assoc, LinearMap.map_add, vadd_eq_add, LinearMap.neg_apply, sub_add_eq_sub_sub_swap, add_comm, sub_eq_add_neg] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι' ⊢ coord (reindex b e) i = coord b (↑e.symm i) [PROOFSTEP] ext [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι' p✝ : P ⊢ ↑(coord (reindex b e) i) p✝ = ↑(coord b (↑e.symm i)) p✝ [PROOFSTEP] classical simp [AffineBasis.coord] [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι' p✝ : P ⊢ ↑(coord (reindex b e) i) p✝ = ↑(coord b (↑e.symm i)) p✝ [PROOFSTEP] simp [AffineBasis.coord] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' i : ι ⊢ ↑(coord b i) (↑b i) = 1 [PROOFSTEP] simp only [coord, Basis.coe_sumCoords, LinearEquiv.map_zero, LinearEquiv.coe_coe, sub_zero, AffineMap.coe_mk, Finsupp.sum_zero_index, vsub_self] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' h : i ≠ j ⊢ ↑(coord b i) (↑b j) = 0 [PROOFSTEP] rw [coord, AffineMap.coe_mk, ← @Subtype.coe_mk _ (fun j => j ≠ i) j h.symm, ← b.basisOf_apply, Basis.sumCoords_self_apply, sub_self] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : DecidableEq ι i j : ι ⊢ ↑(coord b i) (↑b j) = if i = j then 1 else 0 [PROOFSTEP] cases' eq_or_ne i j with h h [GOAL] case inl ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : DecidableEq ι i j : ι h : i = j ⊢ ↑(coord b i) (↑b j) = if i = j then 1 else 0 [PROOFSTEP] simp [h] [GOAL] case inr ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : DecidableEq ι i j : ι h : i ≠ j ⊢ ↑(coord b i) (↑b j) = if i = j then 1 else 0 [PROOFSTEP] simp [h] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' hi : i ∈ s w : ι → k hw : Finset.sum s w = 1 ⊢ ↑(coord b i) (↑(Finset.affineCombination k s ↑b) w) = w i [PROOFSTEP] classical simp only [coord_apply, hi, Finset.affineCombination_eq_linear_combination, if_true, mul_boole, hw, Function.comp_apply, smul_eq_mul, s.sum_ite_eq, s.map_affineCombination b w hw] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' hi : i ∈ s w : ι → k hw : Finset.sum s w = 1 ⊢ ↑(coord b i) (↑(Finset.affineCombination k s ↑b) w) = w i [PROOFSTEP] simp only [coord_apply, hi, Finset.affineCombination_eq_linear_combination, if_true, mul_boole, hw, Function.comp_apply, smul_eq_mul, s.sum_ite_eq, s.map_affineCombination b w hw] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' hi : ¬i ∈ s w : ι → k hw : Finset.sum s w = 1 ⊢ ↑(coord b i) (↑(Finset.affineCombination k s ↑b) w) = 0 [PROOFSTEP] classical simp only [coord_apply, hi, Finset.affineCombination_eq_linear_combination, if_false, mul_boole, hw, Function.comp_apply, smul_eq_mul, s.sum_ite_eq, s.map_affineCombination b w hw] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' hi : ¬i ∈ s w : ι → k hw : Finset.sum s w = 1 ⊢ ↑(coord b i) (↑(Finset.affineCombination k s ↑b) w) = 0 [PROOFSTEP] simp only [coord_apply, hi, Finset.affineCombination_eq_linear_combination, if_false, mul_boole, hw, Function.comp_apply, smul_eq_mul, s.sum_ite_eq, s.map_affineCombination b w hw] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι q : P ⊢ ∑ i : ι, ↑(coord b i) q = 1 [PROOFSTEP] have hq : q ∈ affineSpan k (range b) := by rw [b.tot] exact AffineSubspace.mem_top k V q [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι q : P ⊢ q ∈ affineSpan k (range ↑b) [PROOFSTEP] rw [b.tot] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι q : P ⊢ q ∈ ⊤ [PROOFSTEP] exact AffineSubspace.mem_top k V q [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι q : P hq : q ∈ affineSpan k (range ↑b) ⊢ ∑ i : ι, ↑(coord b i) q = 1 [PROOFSTEP] obtain ⟨w, hw, rfl⟩ := eq_affineCombination_of_mem_affineSpan_of_fintype hq [GOAL] case intro.intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι w : ι → k hw : ∑ i : ι, w i = 1 hq : ↑(Finset.affineCombination k Finset.univ ↑b) w ∈ affineSpan k (range ↑b) ⊢ ∑ i : ι, ↑(coord b i) (↑(Finset.affineCombination k Finset.univ ↑b) w) = 1 [PROOFSTEP] convert hw [GOAL] case h.e'_2.a ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι w : ι → k hw : ∑ i : ι, w i = 1 hq : ↑(Finset.affineCombination k Finset.univ ↑b) w ∈ affineSpan k (range ↑b) x✝ : ι a✝ : x✝ ∈ Finset.univ ⊢ ↑(coord b x✝) (↑(Finset.affineCombination k Finset.univ ↑b) w) = w x✝ [PROOFSTEP] exact b.coord_apply_combination_of_mem (Finset.mem_univ _) hw [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι q : P ⊢ (↑(Finset.affineCombination k Finset.univ ↑b) fun i => ↑(coord b i) q) = q [PROOFSTEP] have hq : q ∈ affineSpan k (range b) := by rw [b.tot] exact AffineSubspace.mem_top k V q [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι q : P ⊢ q ∈ affineSpan k (range ↑b) [PROOFSTEP] rw [b.tot] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι q : P ⊢ q ∈ ⊤ [PROOFSTEP] exact AffineSubspace.mem_top k V q [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι q : P hq : q ∈ affineSpan k (range ↑b) ⊢ (↑(Finset.affineCombination k Finset.univ ↑b) fun i => ↑(coord b i) q) = q [PROOFSTEP] obtain ⟨w, hw, rfl⟩ := eq_affineCombination_of_mem_affineSpan_of_fintype hq [GOAL] case intro.intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι w : ι → k hw : ∑ i : ι, w i = 1 hq : ↑(Finset.affineCombination k Finset.univ ↑b) w ∈ affineSpan k (range ↑b) ⊢ (↑(Finset.affineCombination k Finset.univ ↑b) fun i => ↑(coord b i) (↑(Finset.affineCombination k Finset.univ ↑b) w)) = ↑(Finset.affineCombination k Finset.univ ↑b) w [PROOFSTEP] congr [GOAL] case intro.intro.h.e_6.h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι w : ι → k hw : ∑ i : ι, w i = 1 hq : ↑(Finset.affineCombination k Finset.univ ↑b) w ∈ affineSpan k (range ↑b) ⊢ (fun i => ↑(coord b i) (↑(Finset.affineCombination k Finset.univ ↑b) w)) = w [PROOFSTEP] ext i [GOAL] case intro.intro.h.e_6.h.h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Fintype ι w : ι → k hw : ∑ i : ι, w i = 1 hq : ↑(Finset.affineCombination k Finset.univ ↑b) w ∈ affineSpan k (range ↑b) i : ι ⊢ ↑(coord b i) (↑(Finset.affineCombination k Finset.univ ↑b) w) = w i [PROOFSTEP] exact b.coord_apply_combination_of_mem (Finset.mem_univ i) hw [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b✝ : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι b : AffineBasis ι k V v : V ⊢ ∑ i : ι, ↑(coord b i) v • ↑b i = v [PROOFSTEP] have hb := b.affineCombination_coord_eq_self v [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b✝ : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Fintype ι b : AffineBasis ι k V v : V hb : (↑(Finset.affineCombination k Finset.univ ↑b) fun i => ↑(coord b i) v) = v ⊢ ∑ i : ι, ↑(coord b i) v • ↑b i = v [PROOFSTEP] rwa [Finset.univ.affineCombination_eq_linear_combination _ _ (b.sum_coord_apply_eq_one v)] at hb [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Finite ι q₁ q₂ : P h : ∀ (i : ι), ↑(coord b i) q₁ = ↑(coord b i) q₂ ⊢ q₁ = q₂ [PROOFSTEP] cases nonempty_fintype ι [GOAL] case intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Finite ι q₁ q₂ : P h : ∀ (i : ι), ↑(coord b i) q₁ = ↑(coord b i) q₂ val✝ : Fintype ι ⊢ q₁ = q₂ [PROOFSTEP] rw [← b.affineCombination_coord_eq_self q₁, ← b.affineCombination_coord_eq_self q₂] [GOAL] case intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' inst✝ : Finite ι q₁ q₂ : P h : ∀ (i : ι), ↑(coord b i) q₁ = ↑(coord b i) q₂ val✝ : Fintype ι ⊢ (↑(Finset.affineCombination k Finset.univ ↑b) fun i => ↑(coord b i) q₁) = ↑(Finset.affineCombination k Finset.univ ↑b) fun i => ↑(coord b i) q₂ [PROOFSTEP] simp only [h] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι ⊢ ↑(coord b i) = 1 [PROOFSTEP] ext q [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P ⊢ ↑(coord b i) q = OfNat.ofNat 1 q [PROOFSTEP] have hp : (range b).Subsingleton := by rw [← image_univ] apply Subsingleton.image apply subsingleton_of_subsingleton [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P ⊢ Set.Subsingleton (range ↑b) [PROOFSTEP] rw [← image_univ] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P ⊢ Set.Subsingleton (↑b '' univ) [PROOFSTEP] apply Subsingleton.image [GOAL] case hs ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P ⊢ Set.Subsingleton univ [PROOFSTEP] apply subsingleton_of_subsingleton [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) ⊢ ↑(coord b i) q = OfNat.ofNat 1 q [PROOFSTEP] haveI := AffineSubspace.subsingleton_of_subsingleton_span_eq_top hp b.tot [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) this : Subsingleton P ⊢ ↑(coord b i) q = OfNat.ofNat 1 q [PROOFSTEP] let s : Finset ι := { i } [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) this : Subsingleton P s : Finset ι := {i} ⊢ ↑(coord b i) q = OfNat.ofNat 1 q [PROOFSTEP] have hi : i ∈ s := by simp [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) this : Subsingleton P s : Finset ι := {i} ⊢ i ∈ s [PROOFSTEP] simp [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) this : Subsingleton P s : Finset ι := {i} hi : i ∈ s ⊢ ↑(coord b i) q = OfNat.ofNat 1 q [PROOFSTEP] have hw : s.sum (Function.const ι (1 : k)) = 1 := by simp [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) this : Subsingleton P s : Finset ι := {i} hi : i ∈ s ⊢ Finset.sum s (Function.const ι 1) = 1 [PROOFSTEP] simp [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) this : Subsingleton P s : Finset ι := {i} hi : i ∈ s hw : Finset.sum s (Function.const ι 1) = 1 ⊢ ↑(coord b i) q = OfNat.ofNat 1 q [PROOFSTEP] have hq : q = s.affineCombination k b (Function.const ι (1 : k)) := by simp [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) this : Subsingleton P s : Finset ι := {i} hi : i ∈ s hw : Finset.sum s (Function.const ι 1) = 1 ⊢ q = ↑(Finset.affineCombination k s ↑b) (Function.const ι 1) [PROOFSTEP] simp [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Subsingleton ι i : ι q : P hp : Set.Subsingleton (range ↑b) this : Subsingleton P s : Finset ι := {i} hi : i ∈ s hw : Finset.sum s (Function.const ι 1) = 1 hq : q = ↑(Finset.affineCombination k s ↑b) (Function.const ι 1) ⊢ ↑(coord b i) q = OfNat.ofNat 1 q [PROOFSTEP] rw [Pi.one_apply, hq, b.coord_apply_combination_of_mem hi hw, Function.const_apply] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι ⊢ Function.Surjective ↑(coord b i) [PROOFSTEP] classical intro x obtain ⟨j, hij⟩ := exists_ne i let s : Finset ι := { i, j } have hi : i ∈ s := by simp have _ : j ∈ s := by simp let w : ι → k := fun j' => if j' = i then x else 1 - x have hw : s.sum w = 1 := by -- Porting note: previously this subgoal worked just by: -- simp [hij, Finset.sum_ite, Finset.filter_insert, Finset.filter_eq'] -- I'm not sure why `simp` can not successfully use `Finset.filter_eq'`. simp [Finset.sum_ite, Finset.filter_insert, hij] erw [Finset.filter_eq'] simp [hij.symm] use s.affineCombination k b w simp [b.coord_apply_combination_of_mem hi hw] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι ⊢ Function.Surjective ↑(coord b i) [PROOFSTEP] intro x [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k ⊢ ∃ a, ↑(coord b i) a = x [PROOFSTEP] obtain ⟨j, hij⟩ := exists_ne i [GOAL] case intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i ⊢ ∃ a, ↑(coord b i) a = x [PROOFSTEP] let s : Finset ι := { i, j } [GOAL] case intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} ⊢ ∃ a, ↑(coord b i) a = x [PROOFSTEP] have hi : i ∈ s := by simp [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} ⊢ i ∈ s [PROOFSTEP] simp [GOAL] case intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s ⊢ ∃ a, ↑(coord b i) a = x [PROOFSTEP] have _ : j ∈ s := by simp [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s ⊢ j ∈ s [PROOFSTEP] simp [GOAL] case intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s x✝ : j ∈ s ⊢ ∃ a, ↑(coord b i) a = x [PROOFSTEP] let w : ι → k := fun j' => if j' = i then x else 1 - x [GOAL] case intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s x✝ : j ∈ s w : ι → k := fun j' => if j' = i then x else 1 - x ⊢ ∃ a, ↑(coord b i) a = x [PROOFSTEP] have hw : s.sum w = 1 := by -- Porting note: previously this subgoal worked just by: -- simp [hij, Finset.sum_ite, Finset.filter_insert, Finset.filter_eq'] -- I'm not sure why `simp` can not successfully use `Finset.filter_eq'`. simp [Finset.sum_ite, Finset.filter_insert, hij] erw [Finset.filter_eq'] simp [hij.symm] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s x✝ : j ∈ s w : ι → k := fun j' => if j' = i then x else 1 - x ⊢ Finset.sum s w = 1 [PROOFSTEP] simp [Finset.sum_ite, Finset.filter_insert, hij] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s x✝ : j ∈ s w : ι → k := fun j' => if j' = i then x else 1 - x ⊢ ↑(Finset.card (insert i (Finset.filter (fun x => x = i) {j}))) * x + (1 - x) = 1 [PROOFSTEP] erw [Finset.filter_eq'] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s x✝ : j ∈ s w : ι → k := fun j' => if j' = i then x else 1 - x ⊢ ↑(Finset.card (insert i (if i ∈ {j} then {i} else ∅))) * x + (1 - x) = 1 [PROOFSTEP] simp [hij.symm] [GOAL] case intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s x✝ : j ∈ s w : ι → k := fun j' => if j' = i then x else 1 - x hw : Finset.sum s w = 1 ⊢ ∃ a, ↑(coord b i) a = x [PROOFSTEP] use s.affineCombination k b w [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : Ring k inst✝¹ : Module k V b : AffineBasis ι k P s✝ : Finset ι i✝ j✝ : ι e : ι ≃ ι' inst✝ : Nontrivial ι i : ι x : k j : ι hij : j ≠ i s : Finset ι := {i, j} hi : i ∈ s x✝ : j ∈ s w : ι → k := fun j' => if j' = i then x else 1 - x hw : Finset.sum s w = 1 ⊢ ↑(coord b i) (↑(Finset.affineCombination k s ↑b) w) = x [PROOFSTEP] simp [b.coord_apply_combination_of_mem hi hw] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' v w : V ⊢ (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w [PROOFSTEP] ext i [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' v w : V i : ι ⊢ (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) i = ((fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) i [PROOFSTEP] simp only [LinearMap.map_add, Pi.add_apply, neg_add] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' t : k v : V ⊢ AddHom.toFun { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } (t • v) = ↑(RingHom.id k) t • AddHom.toFun { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } v [PROOFSTEP] ext i [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' t : k v : V i : ι ⊢ AddHom.toFun { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } (t • v) i = (↑(RingHom.id k) t • AddHom.toFun { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } v) i [PROOFSTEP] simp only [LinearMap.map_smul, Pi.smul_apply, smul_neg, RingHom.id_apply, mul_neg] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i j : ι e : ι ≃ ι' p : P v : V ⊢ (fun q i => ↑(coord b i) q) (v +ᵥ p) = ↑{ toAddHom := { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) }, map_smul' := (_ : ∀ (t : k) (v : V), AddHom.toFun { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } (t • v) = ↑(RingHom.id k) t • AddHom.toFun { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } v) } v +ᵥ (fun q i => ↑(coord b i) q) p [PROOFSTEP] ext i [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' p : P v : V i : ι ⊢ (fun q i => ↑(coord b i) q) (v +ᵥ p) i = (↑{ toAddHom := { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) }, map_smul' := (_ : ∀ (t : k) (v : V), AddHom.toFun { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } (t • v) = ↑(RingHom.id k) t • AddHom.toFun { toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } v) } v +ᵥ (fun q i => ↑(coord b i) q) p) i [PROOFSTEP] rw [LinearMap.coe_mk, Pi.vadd_apply'] [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' p : P v : V i : ι ⊢ (fun q i => ↑(coord b i) q) (v +ᵥ p) i = ↑{ toFun := fun v i => -↑(Basis.sumCoords (basisOf b i)) v, map_add' := (_ : ∀ (v w : V), (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) (v + w) = (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) v + (fun v i => -↑(Basis.sumCoords (basisOf b i)) v) w) } v i +ᵥ (fun q i => ↑(coord b i) q) p i [PROOFSTEP] dsimp [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' p : P v : V i : ι ⊢ ↑(coord b i) (v +ᵥ p) = (-Finsupp.sum (↑(basisOf b i).repr v) fun x => id) + ↑(coord b i) p [PROOFSTEP] rw [AffineMap.map_vadd, linear_eq_sumCoords, LinearMap.neg_apply] [GOAL] case h ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : Ring k inst✝ : Module k V b : AffineBasis ι k P s : Finset ι i✝ j : ι e : ι ≃ ι' p : P v : V i : ι ⊢ -↑(Basis.sumCoords (basisOf b i)) v +ᵥ ↑(coord b i) p = (-Finsupp.sum (↑(basisOf b i).repr v) fun x => id) + ↑(coord b i) p [PROOFSTEP] simp only [ne_eq, Basis.coe_sumCoords, vadd_eq_add] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝⁴ : AddCommGroup V inst✝³ : AffineSpace V P inst✝² : DivisionRing k inst✝¹ : Module k V inst✝ : CharZero k b : AffineBasis ι k P s : Finset ι i : ι hi : i ∈ s ⊢ ↑(coord b i) (Finset.centroid k s ↑b) = (↑(Finset.card s))⁻¹ [PROOFSTEP] rw [Finset.centroid, b.coord_apply_combination_of_mem hi (s.sum_centroidWeights_eq_one_of_nonempty _ ⟨i, hi⟩), Finset.centroidWeights, Function.const_apply] [GOAL] ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : DivisionRing k inst✝ : Module k V t : Set P ht : affineSpan k t = ⊤ ⊢ ∃ s x b, ↑b = Subtype.val [PROOFSTEP] obtain ⟨s, hst, h_tot, h_ind⟩ := exists_affineIndependent k V t [GOAL] case intro.intro.intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : DivisionRing k inst✝ : Module k V t : Set P ht : affineSpan k t = ⊤ s : Set P hst : s ⊆ t h_tot : affineSpan k s = affineSpan k t h_ind : AffineIndependent k Subtype.val ⊢ ∃ s x b, ↑b = Subtype.val [PROOFSTEP] refine' ⟨s, hst, ⟨(↑), h_ind, _⟩, rfl⟩ [GOAL] case intro.intro.intro ι : Type u_1 ι' : Type u_2 k : Type u_3 V : Type u_4 P : Type u_5 inst✝³ : AddCommGroup V inst✝² : AffineSpace V P inst✝¹ : DivisionRing k inst✝ : Module k V t : Set P ht : affineSpan k t = ⊤ s : Set P hst : s ⊆ t h_tot : affineSpan k s = affineSpan k t h_ind : AffineIndependent k Subtype.val ⊢ affineSpan k (range Subtype.val) = ⊤ [PROOFSTEP] rw [Subtype.range_coe, h_tot, ht]
/- Copyright (c) 2020 Ruben Van de Velde. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ruben Van de Velde ! This file was ported from Lean 3 source module analysis.normed_space.extend ! leanprover-community/mathlib commit 468b141b14016d54b479eb7a0fff1e360b7e3cf6 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Analysis.NormedSpace.OperatorNorm import Mathbin.Algebra.Algebra.RestrictScalars import Mathbin.Data.IsROrC.Basic /-! # Extending a continuous `ℝ`-linear map to a continuous `𝕜`-linear map In this file we provide a way to extend a continuous `ℝ`-linear map to a continuous `𝕜`-linear map in a way that bounds the norm by the norm of the original map, when `𝕜` is either `ℝ` (the extension is trivial) or `ℂ`. We formulate the extension uniformly, by assuming `is_R_or_C 𝕜`. We motivate the form of the extension as follows. Note that `fc : F →ₗ[𝕜] 𝕜` is determined fully by `Re fc`: for all `x : F`, `fc (I • x) = I * fc x`, so `Im (fc x) = -Re (fc (I • x))`. Therefore, given an `fr : F →ₗ[ℝ] ℝ`, we define `fc x = fr x - fr (I • x) * I`. ## Main definitions * `linear_map.extend_to_𝕜` * `continuous_linear_map.extend_to_𝕜` ## Implementation details For convenience, the main definitions above operate in terms of `restrict_scalars ℝ 𝕜 F`. Alternate forms which operate on `[is_scalar_tower ℝ 𝕜 F]` instead are provided with a primed name. -/ open IsROrC variable {𝕜 : Type _} [IsROrC 𝕜] {F : Type _} [SeminormedAddCommGroup F] [NormedSpace 𝕜 F] -- mathport name: exprabs𝕜 local notation "abs𝕜" => @IsROrC.abs 𝕜 _ /-- Extend `fr : F →ₗ[ℝ] ℝ` to `F →ₗ[𝕜] 𝕜` in a way that will also be continuous and have its norm bounded by `‖fr‖` if `fr` is continuous. -/ noncomputable def LinearMap.extendTo𝕜' [Module ℝ F] [IsScalarTower ℝ 𝕜 F] (fr : F →ₗ[ℝ] ℝ) : F →ₗ[𝕜] 𝕜 := by let fc : F → 𝕜 := fun x => (fr x : 𝕜) - (I : 𝕜) * fr ((I : 𝕜) • x) have add : ∀ x y : F, fc (x + y) = fc x + fc y := by intro x y simp only [fc] simp only [smul_add, LinearMap.map_add, of_real_add] rw [mul_add] abel have A : ∀ (c : ℝ) (x : F), (fr ((c : 𝕜) • x) : 𝕜) = (c : 𝕜) * (fr x : 𝕜) := by intro c x rw [← of_real_mul] congr 1 rw [IsROrC.of_real_alg, smul_assoc, fr.map_smul, Algebra.id.smul_eq_mul, one_smul] have smul_ℝ : ∀ (c : ℝ) (x : F), fc ((c : 𝕜) • x) = (c : 𝕜) * fc x := by intro c x simp only [fc, A] rw [A c x] rw [smul_smul, mul_comm I (c : 𝕜), ← smul_smul, A, mul_sub] ring have smul_I : ∀ x : F, fc ((I : 𝕜) • x) = (I : 𝕜) * fc x := by intro x simp only [fc] cases' @I_mul_I_ax 𝕜 _ with h h · simp [h] rw [mul_sub, ← mul_assoc, smul_smul, h] simp only [neg_mul, LinearMap.map_neg, one_mul, one_smul, mul_neg, of_real_neg, neg_smul, sub_neg_eq_add, add_comm] have smul_𝕜 : ∀ (c : 𝕜) (x : F), fc (c • x) = c • fc x := by intro c x rw [← re_add_im c, add_smul, add_smul, add, smul_ℝ, ← smul_smul, smul_ℝ, smul_I, ← mul_assoc] rfl exact { toFun := fc map_add' := add map_smul' := smul_𝕜 } #align linear_map.extend_to_𝕜' LinearMap.extendTo𝕜' theorem LinearMap.extendTo𝕜'_apply [Module ℝ F] [IsScalarTower ℝ 𝕜 F] (fr : F →ₗ[ℝ] ℝ) (x : F) : fr.extendTo𝕜' x = (fr x : 𝕜) - (i : 𝕜) * fr ((i : 𝕜) • x) := rfl #align linear_map.extend_to_𝕜'_apply LinearMap.extendTo𝕜'_apply /-- The norm of the extension is bounded by `‖fr‖`. -/ theorem norm_bound [NormedSpace ℝ F] [IsScalarTower ℝ 𝕜 F] (fr : F →L[ℝ] ℝ) (x : F) : ‖(fr.toLinearMap.extendTo𝕜' x : 𝕜)‖ ≤ ‖fr‖ * ‖x‖ := by let lm : F →ₗ[𝕜] 𝕜 := fr.to_linear_map.extend_to_𝕜' classical -- We aim to find a `t : 𝕜` such that -- * `lm (t • x) = fr (t • x)` (so `lm (t • x) = t * lm x ∈ ℝ`) -- * `‖lm x‖ = ‖lm (t • x)‖` (so `t.abs` must be 1) -- If `lm x ≠ 0`, `(lm x)⁻¹` satisfies the first requirement, and after normalizing, it -- satisfies the second. -- (If `lm x = 0`, the goal is trivial.) by_cases h : lm x = 0 · rw [h, norm_zero] apply mul_nonneg <;> exact norm_nonneg _ let fx := (lm x)⁻¹ let t := fx / (abs𝕜 fx : 𝕜) have ht : abs𝕜 t = 1 := by field_simp [abs_of_real, of_real_inv, IsROrC.abs_inv, IsROrC.abs_div, IsROrC.abs_abs, h] have h1 : (fr (t • x) : 𝕜) = lm (t • x) := by apply ext · simp only [lm, of_real_re, LinearMap.extendTo𝕜'_apply, mul_re, I_re, of_real_im, MulZeroClass.zero_mul, AddMonoidHom.map_sub, sub_zero, MulZeroClass.mul_zero] rfl · symm calc im (lm (t • x)) = im (t * lm x) := by rw [lm.map_smul, smul_eq_mul] _ = im ((lm x)⁻¹ / abs𝕜 (lm x)⁻¹ * lm x) := rfl _ = im (1 / (abs𝕜 (lm x)⁻¹ : 𝕜)) := by rw [div_mul_eq_mul_div, inv_mul_cancel h] _ = 0 := by rw [← of_real_one, ← of_real_div, of_real_im] _ = im (fr (t • x) : 𝕜) := by rw [of_real_im] calc ‖lm x‖ = abs𝕜 t * ‖lm x‖ := by rw [ht, one_mul] _ = ‖t * lm x‖ := by rw [← norm_eq_abs, norm_mul] _ = ‖lm (t • x)‖ := by rw [← smul_eq_mul, lm.map_smul] _ = ‖(fr (t • x) : 𝕜)‖ := by rw [h1] _ = ‖fr (t • x)‖ := by rw [norm_eq_abs, abs_of_real, norm_eq_abs, abs_to_real] _ ≤ ‖fr‖ * ‖t • x‖ := (ContinuousLinearMap.le_op_norm _ _) _ = ‖fr‖ * (‖t‖ * ‖x‖) := by rw [norm_smul] _ ≤ ‖fr‖ * ‖x‖ := by rw [norm_eq_abs, ht, one_mul] #align norm_bound norm_bound /-- Extend `fr : F →L[ℝ] ℝ` to `F →L[𝕜] 𝕜`. -/ noncomputable def ContinuousLinearMap.extendTo𝕜' [NormedSpace ℝ F] [IsScalarTower ℝ 𝕜 F] (fr : F →L[ℝ] ℝ) : F →L[𝕜] 𝕜 := LinearMap.mkContinuous _ ‖fr‖ (norm_bound _) #align continuous_linear_map.extend_to_𝕜' ContinuousLinearMap.extendTo𝕜' theorem ContinuousLinearMap.extendTo𝕜'_apply [NormedSpace ℝ F] [IsScalarTower ℝ 𝕜 F] (fr : F →L[ℝ] ℝ) (x : F) : fr.extendTo𝕜' x = (fr x : 𝕜) - (i : 𝕜) * fr ((i : 𝕜) • x) := rfl #align continuous_linear_map.extend_to_𝕜'_apply ContinuousLinearMap.extendTo𝕜'_apply /-- Extend `fr : restrict_scalars ℝ 𝕜 F →ₗ[ℝ] ℝ` to `F →ₗ[𝕜] 𝕜`. -/ noncomputable def LinearMap.extendTo𝕜 (fr : RestrictScalars ℝ 𝕜 F →ₗ[ℝ] ℝ) : F →ₗ[𝕜] 𝕜 := fr.extendTo𝕜' #align linear_map.extend_to_𝕜 LinearMap.extendTo𝕜 theorem LinearMap.extendTo𝕜_apply (fr : RestrictScalars ℝ 𝕜 F →ₗ[ℝ] ℝ) (x : F) : fr.extendTo𝕜 x = (fr x : 𝕜) - (i : 𝕜) * fr ((i : 𝕜) • x : _) := rfl #align linear_map.extend_to_𝕜_apply LinearMap.extendTo𝕜_apply /-- Extend `fr : restrict_scalars ℝ 𝕜 F →L[ℝ] ℝ` to `F →L[𝕜] 𝕜`. -/ noncomputable def ContinuousLinearMap.extendTo𝕜 (fr : RestrictScalars ℝ 𝕜 F →L[ℝ] ℝ) : F →L[𝕜] 𝕜 := fr.extendTo𝕜' #align continuous_linear_map.extend_to_𝕜 ContinuousLinearMap.extendTo𝕜 theorem ContinuousLinearMap.extendTo𝕜_apply (fr : RestrictScalars ℝ 𝕜 F →L[ℝ] ℝ) (x : F) : fr.extendTo𝕜 x = (fr x : 𝕜) - (i : 𝕜) * fr ((i : 𝕜) • x : _) := rfl #align continuous_linear_map.extend_to_𝕜_apply ContinuousLinearMap.extendTo𝕜_apply
State Before: α : Type u β : Type v γ : Type w ι : Sort x a b : α s s₁ s₂ t t₁ t₂ u : Set α inst✝¹ : LinearOrder α inst✝ : LinearOrder β f : α → β ⊢ ¬MonotoneOn f s ∧ ¬AntitoneOn f s ↔ ∃ a x b x c x, a < b ∧ b < c ∧ (f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) State After: no goals Tactic: simp [monotoneOn_iff_monotone, antitoneOn_iff_antitone, and_assoc, exists_and_left, not_monotone_not_antitone_iff_exists_lt_lt, @and_left_comm (_ ∈ s)]
[GOAL] N✝ N : ℕ γ : SL(2, ℤ) ⊢ γ ∈ Gamma N ↔ ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 [PROOFSTEP] rw [Gamma_mem'] [GOAL] N✝ N : ℕ γ : SL(2, ℤ) ⊢ ↑(SpecialLinearGroup.map (Int.castRingHom (ZMod N))) γ = 1 ↔ ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 [PROOFSTEP] constructor [GOAL] case mp N✝ N : ℕ γ : SL(2, ℤ) ⊢ ↑(SpecialLinearGroup.map (Int.castRingHom (ZMod N))) γ = 1 → ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 [PROOFSTEP] intro h [GOAL] case mp N✝ N : ℕ γ : SL(2, ℤ) h : ↑(SpecialLinearGroup.map (Int.castRingHom (ZMod N))) γ = 1 ⊢ ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 [PROOFSTEP] simp [← SL_reduction_mod_hom_val N γ, h] [GOAL] case mpr N✝ N : ℕ γ : SL(2, ℤ) ⊢ ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 → ↑(SpecialLinearGroup.map (Int.castRingHom (ZMod N))) γ = 1 [PROOFSTEP] intro h [GOAL] case mpr N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(SpecialLinearGroup.map (Int.castRingHom (ZMod N))) γ = 1 [PROOFSTEP] ext i j [GOAL] case mpr.a N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 i j : Fin 2 ⊢ ↑(↑(SpecialLinearGroup.map (Int.castRingHom (ZMod N))) γ) i j = ↑1 i j [PROOFSTEP] rw [SL_reduction_mod_hom_val N γ] [GOAL] case mpr.a N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 i j : Fin 2 ⊢ ↑(↑γ i j) = ↑1 i j [PROOFSTEP] fin_cases i [GOAL] case mpr.a.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 j : Fin 2 ⊢ ↑(↑γ { val := 0, isLt := (_ : 0 < 2) } j) = ↑1 { val := 0, isLt := (_ : 0 < 2) } j [PROOFSTEP] fin_cases j [GOAL] case mpr.a.tail.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 j : Fin 2 ⊢ ↑(↑γ { val := 1, isLt := (_ : (fun a => a < 2) 1) } j) = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } j [PROOFSTEP] fin_cases j [GOAL] case mpr.a.head.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(↑γ { val := 0, isLt := (_ : 0 < 2) } { val := 0, isLt := (_ : 0 < 2) }) = ↑1 { val := 0, isLt := (_ : 0 < 2) } { val := 0, isLt := (_ : 0 < 2) } [PROOFSTEP] simp only [h] [GOAL] case mpr.a.head.tail.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(↑γ { val := 0, isLt := (_ : 0 < 2) } { val := 1, isLt := (_ : (fun a => a < 2) 1) }) = ↑1 { val := 0, isLt := (_ : 0 < 2) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } [PROOFSTEP] simp only [h] [GOAL] case mpr.a.tail.head.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(↑γ { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 0, isLt := (_ : 0 < 2) }) = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 0, isLt := (_ : 0 < 2) } [PROOFSTEP] simp only [h] [GOAL] case mpr.a.tail.head.tail.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(↑γ { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 1, isLt := (_ : (fun a => a < 2) 1) }) = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } [PROOFSTEP] simp only [h] [GOAL] case mpr.a.head.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(↑γ { val := 0, isLt := (_ : 0 < 2) } { val := 0, isLt := (_ : 0 < 2) }) = ↑1 { val := 0, isLt := (_ : 0 < 2) } { val := 0, isLt := (_ : 0 < 2) } case mpr.a.head.tail.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(↑γ { val := 0, isLt := (_ : 0 < 2) } { val := 1, isLt := (_ : (fun a => a < 2) 1) }) = ↑1 { val := 0, isLt := (_ : 0 < 2) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } case mpr.a.tail.head.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(↑γ { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 0, isLt := (_ : 0 < 2) }) = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 0, isLt := (_ : 0 < 2) } case mpr.a.tail.head.tail.head N✝ N : ℕ γ : SL(2, ℤ) h : ↑(↑γ 0 0) = 1 ∧ ↑(↑γ 0 1) = 0 ∧ ↑(↑γ 1 0) = 0 ∧ ↑(↑γ 1 1) = 1 ⊢ ↑(↑γ { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 1, isLt := (_ : (fun a => a < 2) 1) }) = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } [PROOFSTEP] exacts [h.1, h.2.1, h.2.2.1, h.2.2.2] [GOAL] N : ℕ ⊢ Gamma 1 = ⊤ [PROOFSTEP] ext [GOAL] case h N : ℕ x✝ : SL(2, ℤ) ⊢ x✝ ∈ Gamma 1 ↔ x✝ ∈ ⊤ [PROOFSTEP] simp [GOAL] N : ℕ ⊢ Gamma 0 = ⊥ [PROOFSTEP] ext [GOAL] case h N : ℕ x✝ : SL(2, ℤ) ⊢ x✝ ∈ Gamma 0 ↔ x✝ ∈ ⊥ [PROOFSTEP] simp only [Gamma_mem, coe_matrix_coe, Int.coe_castRingHom, map_apply, Int.cast_id, Subgroup.mem_bot] [GOAL] case h N : ℕ x✝ : SL(2, ℤ) ⊢ ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ↔ x✝ = 1 [PROOFSTEP] constructor [GOAL] case h.mp N : ℕ x✝ : SL(2, ℤ) ⊢ ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 → x✝ = 1 [PROOFSTEP] intro h [GOAL] case h.mp N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ x✝ = 1 [PROOFSTEP] ext i j [GOAL] case h.mp.a N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 i j : Fin 2 ⊢ ↑x✝ i j = ↑1 i j [PROOFSTEP] fin_cases i [GOAL] case h.mp.a.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 j : Fin 2 ⊢ ↑x✝ { val := 0, isLt := (_ : 0 < 2) } j = ↑1 { val := 0, isLt := (_ : 0 < 2) } j [PROOFSTEP] fin_cases j [GOAL] case h.mp.a.tail.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 j : Fin 2 ⊢ ↑x✝ { val := 1, isLt := (_ : (fun a => a < 2) 1) } j = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } j [PROOFSTEP] fin_cases j [GOAL] case h.mp.a.head.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ ↑x✝ { val := 0, isLt := (_ : 0 < 2) } { val := 0, isLt := (_ : 0 < 2) } = ↑1 { val := 0, isLt := (_ : 0 < 2) } { val := 0, isLt := (_ : 0 < 2) } [PROOFSTEP] simp only [h] [GOAL] case h.mp.a.head.tail.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ ↑x✝ { val := 0, isLt := (_ : 0 < 2) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } = ↑1 { val := 0, isLt := (_ : 0 < 2) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } [PROOFSTEP] simp only [h] [GOAL] case h.mp.a.tail.head.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ ↑x✝ { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 0, isLt := (_ : 0 < 2) } = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 0, isLt := (_ : 0 < 2) } [PROOFSTEP] simp only [h] [GOAL] case h.mp.a.tail.head.tail.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ ↑x✝ { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } [PROOFSTEP] simp only [h] [GOAL] case h.mp.a.head.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ ↑x✝ { val := 0, isLt := (_ : 0 < 2) } { val := 0, isLt := (_ : 0 < 2) } = ↑1 { val := 0, isLt := (_ : 0 < 2) } { val := 0, isLt := (_ : 0 < 2) } case h.mp.a.head.tail.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ ↑x✝ { val := 0, isLt := (_ : 0 < 2) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } = ↑1 { val := 0, isLt := (_ : 0 < 2) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } case h.mp.a.tail.head.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ ↑x✝ { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 0, isLt := (_ : 0 < 2) } = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 0, isLt := (_ : 0 < 2) } case h.mp.a.tail.head.tail.head N : ℕ x✝ : SL(2, ℤ) h : ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 ⊢ ↑x✝ { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } = ↑1 { val := 1, isLt := (_ : (fun a => a < 2) 1) } { val := 1, isLt := (_ : (fun a => a < 2) 1) } [PROOFSTEP] exacts [h.1, h.2.1, h.2.2.1, h.2.2.2] [GOAL] case h.mpr N : ℕ x✝ : SL(2, ℤ) ⊢ x✝ = 1 → ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 [PROOFSTEP] intro h [GOAL] case h.mpr N : ℕ x✝ : SL(2, ℤ) h : x✝ = 1 ⊢ ↑(↑x✝ 0 0) = 1 ∧ ↑(↑x✝ 0 1) = 0 ∧ ↑(↑x✝ 1 0) = 0 ∧ ↑(↑x✝ 1 1) = 1 [PROOFSTEP] simp [h] [GOAL] N✝ N : ℕ ⊢ ∀ {a b : SL(2, ℤ)}, a ∈ {g | ↑(↑g 1 0) = 0} → b ∈ {g | ↑(↑g 1 0) = 0} → a * b ∈ {g | ↑(↑g 1 0) = 0} [PROOFSTEP] intro a b ha hb [GOAL] N✝ N : ℕ a b : SL(2, ℤ) ha : a ∈ {g | ↑(↑g 1 0) = 0} hb : b ∈ {g | ↑(↑g 1 0) = 0} ⊢ a * b ∈ {g | ↑(↑g 1 0) = 0} [PROOFSTEP] simp only [Set.mem_setOf_eq] [GOAL] N✝ N : ℕ a b : SL(2, ℤ) ha : a ∈ {g | ↑(↑g 1 0) = 0} hb : b ∈ {g | ↑(↑g 1 0) = 0} ⊢ ↑(↑(a * b) 1 0) = 0 [PROOFSTEP] have h := (Matrix.two_mul_expl a.1 b.1).2.2.1 [GOAL] N✝ N : ℕ a b : SL(2, ℤ) ha : a ∈ {g | ↑(↑g 1 0) = 0} hb : b ∈ {g | ↑(↑g 1 0) = 0} h : (↑a * ↑b) 1 0 = ↑a 1 0 * ↑b 0 0 + ↑a 1 1 * ↑b 1 0 ⊢ ↑(↑(a * b) 1 0) = 0 [PROOFSTEP] simp only [coe_matrix_coe, coe_mul, Int.coe_castRingHom, map_apply, Set.mem_setOf_eq] at * [GOAL] N✝ N : ℕ a b : SL(2, ℤ) ha : ↑(↑a 1 0) = 0 hb : ↑(↑b 1 0) = 0 h : (↑a * ↑b) 1 0 = ↑a 1 0 * ↑b 0 0 + ↑a 1 1 * ↑b 1 0 ⊢ ↑((↑a * ↑b) 1 0) = 0 [PROOFSTEP] rw [h] [GOAL] N✝ N : ℕ a b : SL(2, ℤ) ha : ↑(↑a 1 0) = 0 hb : ↑(↑b 1 0) = 0 h : (↑a * ↑b) 1 0 = ↑a 1 0 * ↑b 0 0 + ↑a 1 1 * ↑b 1 0 ⊢ ↑(↑a 1 0 * ↑b 0 0 + ↑a 1 1 * ↑b 1 0) = 0 [PROOFSTEP] simp [ha, hb] [GOAL] N✝ N : ℕ ⊢ 1 ∈ { carrier := {g | ↑(↑g 1 0) = 0}, mul_mem' := (_ : ∀ {a b : SL(2, ℤ)}, a ∈ {g | ↑(↑g 1 0) = 0} → b ∈ {g | ↑(↑g 1 0) = 0} → a * b ∈ {g | ↑(↑g 1 0) = 0}) }.carrier [PROOFSTEP] simp [GOAL] N✝ N : ℕ ⊢ ∀ {x : SL(2, ℤ)}, x ∈ { toSubsemigroup := { carrier := {g | ↑(↑g 1 0) = 0}, mul_mem' := (_ : ∀ {a b : SL(2, ℤ)}, a ∈ {g | ↑(↑g 1 0) = 0} → b ∈ {g | ↑(↑g 1 0) = 0} → a * b ∈ {g | ↑(↑g 1 0) = 0}) }, one_mem' := (_ : ↑(OfNat.ofNat 1 1 0) = 0) }.toSubsemigroup.carrier → x⁻¹ ∈ { toSubsemigroup := { carrier := {g | ↑(↑g 1 0) = 0}, mul_mem' := (_ : ∀ {a b : SL(2, ℤ)}, a ∈ {g | ↑(↑g 1 0) = 0} → b ∈ {g | ↑(↑g 1 0) = 0} → a * b ∈ {g | ↑(↑g 1 0) = 0}) }, one_mem' := (_ : ↑(OfNat.ofNat 1 1 0) = 0) }.toSubsemigroup.carrier [PROOFSTEP] intro a ha [GOAL] N✝ N : ℕ a : SL(2, ℤ) ha : a ∈ { toSubsemigroup := { carrier := {g | ↑(↑g 1 0) = 0}, mul_mem' := (_ : ∀ {a b : SL(2, ℤ)}, a ∈ {g | ↑(↑g 1 0) = 0} → b ∈ {g | ↑(↑g 1 0) = 0} → a * b ∈ {g | ↑(↑g 1 0) = 0}) }, one_mem' := (_ : ↑(OfNat.ofNat 1 1 0) = 0) }.toSubsemigroup.carrier ⊢ a⁻¹ ∈ { toSubsemigroup := { carrier := {g | ↑(↑g 1 0) = 0}, mul_mem' := (_ : ∀ {a b : SL(2, ℤ)}, a ∈ {g | ↑(↑g 1 0) = 0} → b ∈ {g | ↑(↑g 1 0) = 0} → a * b ∈ {g | ↑(↑g 1 0) = 0}) }, one_mem' := (_ : ↑(OfNat.ofNat 1 1 0) = 0) }.toSubsemigroup.carrier [PROOFSTEP] simp only [Set.mem_setOf_eq] [GOAL] N✝ N : ℕ a : SL(2, ℤ) ha : a ∈ { toSubsemigroup := { carrier := {g | ↑(↑g 1 0) = 0}, mul_mem' := (_ : ∀ {a b : SL(2, ℤ)}, a ∈ {g | ↑(↑g 1 0) = 0} → b ∈ {g | ↑(↑g 1 0) = 0} → a * b ∈ {g | ↑(↑g 1 0) = 0}) }, one_mem' := (_ : ↑(OfNat.ofNat 1 1 0) = 0) }.toSubsemigroup.carrier ⊢ ↑(↑a⁻¹ 1 0) = 0 [PROOFSTEP] rw [SL2_inv_expl a] [GOAL] N✝ N : ℕ a : SL(2, ℤ) ha : a ∈ { toSubsemigroup := { carrier := {g | ↑(↑g 1 0) = 0}, mul_mem' := (_ : ∀ {a b : SL(2, ℤ)}, a ∈ {g | ↑(↑g 1 0) = 0} → b ∈ {g | ↑(↑g 1 0) = 0} → a * b ∈ {g | ↑(↑g 1 0) = 0}) }, one_mem' := (_ : ↑(OfNat.ofNat 1 1 0) = 0) }.toSubsemigroup.carrier ⊢ ↑(↑{ val := ![![↑a 1 1, -↑a 0 1], ![-↑a 1 0, ↑a 0 0]], property := (_ : det ![![↑a 1 1, -↑a 0 1], ![-↑a 1 0, ↑a 0 0]] = 1) } 1 0) = 0 [PROOFSTEP] simp only [cons_val_zero, cons_val_one, head_cons, coe_matrix_coe, coe_mk, Int.coe_castRingHom, map_apply, Int.cast_neg, neg_eq_zero, Set.mem_setOf_eq] at * [GOAL] N✝ N : ℕ a : SL(2, ℤ) ha : ↑(↑a 1 0) = 0 ⊢ ↑(↑a 1 0) = 0 [PROOFSTEP] exact ha [GOAL] N✝ N : ℕ A : { x // x ∈ Gamma0 N } ⊢ ↑(det ↑↑A) = 1 [PROOFSTEP] simp [A.1.property] [GOAL] N✝ N : ℕ ⊢ (fun g => ↑(↑↑g 1 1)) 1 = 1 [PROOFSTEP] simp [GOAL] N✝ N : ℕ ⊢ ∀ (x y : { x // x ∈ Gamma0 N }), OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } (x * y) = OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } x * OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } y [PROOFSTEP] intro A B [GOAL] N✝ N : ℕ A B : { x // x ∈ Gamma0 N } ⊢ OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } (A * B) = OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } A * OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } B [PROOFSTEP] have := (two_mul_expl A.1.1 B.1.1).2.2.2 [GOAL] N✝ N : ℕ A B : { x // x ∈ Gamma0 N } this : (↑↑A * ↑↑B) 1 1 = ↑↑A 1 0 * ↑↑B 0 1 + ↑↑A 1 1 * ↑↑B 1 1 ⊢ OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } (A * B) = OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } A * OneHom.toFun { toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } B [PROOFSTEP] simp only [Subgroup.coe_mul, coe_matrix_coe, coe_mul, Int.coe_castRingHom, map_apply] at * [GOAL] N✝ N : ℕ A B : { x // x ∈ Gamma0 N } this : (↑↑A * ↑↑B) 1 1 = ↑↑A 1 0 * ↑↑B 0 1 + ↑↑A 1 1 * ↑↑B 1 1 ⊢ ↑((↑↑A * ↑↑B) 1 1) = ↑(↑↑A 1 1) * ↑(↑↑B 1 1) [PROOFSTEP] rw [this] [GOAL] N✝ N : ℕ A B : { x // x ∈ Gamma0 N } this : (↑↑A * ↑↑B) 1 1 = ↑↑A 1 0 * ↑↑B 0 1 + ↑↑A 1 1 * ↑↑B 1 1 ⊢ ↑(↑↑A 1 0 * ↑↑B 0 1 + ↑↑A 1 1 * ↑↑B 1 1) = ↑(↑↑A 1 1) * ↑(↑↑B 1 1) [PROOFSTEP] have ha := A.property [GOAL] N✝ N : ℕ A B : { x // x ∈ Gamma0 N } this : (↑↑A * ↑↑B) 1 1 = ↑↑A 1 0 * ↑↑B 0 1 + ↑↑A 1 1 * ↑↑B 1 1 ha : ↑A ∈ Gamma0 N ⊢ ↑(↑↑A 1 0 * ↑↑B 0 1 + ↑↑A 1 1 * ↑↑B 1 1) = ↑(↑↑A 1 1) * ↑(↑↑B 1 1) [PROOFSTEP] simp only [Int.cast_add, Int.cast_mul, add_left_eq_self, Gamma0_mem, coe_matrix_coe, Int.coe_castRingHom, map_apply] at * [GOAL] N✝ N : ℕ A B : { x // x ∈ Gamma0 N } this : (↑↑A * ↑↑B) 1 1 = ↑↑A 1 0 * ↑↑B 0 1 + ↑↑A 1 1 * ↑↑B 1 1 ha : ↑(↑↑A 1 0) = 0 ⊢ ↑(↑↑A 1 0) * ↑(↑↑B 0 1) = 0 [PROOFSTEP] rw [ha] [GOAL] N✝ N : ℕ A B : { x // x ∈ Gamma0 N } this : (↑↑A * ↑↑B) 1 1 = ↑↑A 1 0 * ↑↑B 0 1 + ↑↑A 1 1 * ↑↑B 1 1 ha : ↑(↑↑A 1 0) = 0 ⊢ 0 * ↑(↑↑B 0 1) = 0 [PROOFSTEP] simp [GOAL] N✝ N : ℕ A : { x // x ∈ Gamma0 N } ⊢ A ∈ Gamma1' N ↔ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] constructor [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } ⊢ A ∈ Gamma1' N → ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] intro ha [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } ha : A ∈ Gamma1' N ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] have hA := A.property [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } ha : A ∈ Gamma1' N hA : ↑A ∈ Gamma0 N ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] rw [Gamma0_mem] at hA [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } ha : A ∈ Gamma1' N hA : ↑(↑↑A 1 0) = 0 ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] have adet := Gamma0_det N A [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } ha : A ∈ Gamma1' N hA : ↑(↑↑A 1 0) = 0 adet : ↑(det ↑↑A) = 1 ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] rw [Matrix.det_fin_two] at adet [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } ha : A ∈ Gamma1' N hA : ↑(↑↑A 1 0) = 0 adet : ↑(↑↑A 0 0 * ↑↑A 1 1 - ↑↑A 0 1 * ↑↑A 1 0) = 1 ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] simp only [Gamma0Map, coe_matrix_coe, Int.coe_castRingHom, map_apply, Gamma1_mem', MonoidHom.coe_mk, OneHom.coe_mk, Int.cast_sub, Int.cast_mul] at * [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } hA : ↑(↑↑A 1 0) = 0 ha : ↑(↑↑A 1 1) = 1 adet : ↑(↑↑A 0 0) * ↑(↑↑A 1 1) - ↑(↑↑A 0 1) * ↑(↑↑A 1 0) = 1 ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] rw [hA, ha] at adet [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } hA : ↑(↑↑A 1 0) = 0 ha : ↑(↑↑A 1 1) = 1 adet : ↑(↑↑A 0 0) * 1 - ↑(↑↑A 0 1) * 0 = 1 ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] simp only [mul_one, mul_zero, sub_zero] at adet [GOAL] case mp N✝ N : ℕ A : { x // x ∈ Gamma0 N } hA : ↑(↑↑A 1 0) = 0 ha : ↑(↑↑A 1 1) = 1 adet : ↑(↑↑A 0 0) = 1 ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 [PROOFSTEP] simp only [adet, hA, ha, eq_self_iff_true, and_self_iff] [GOAL] case mpr N✝ N : ℕ A : { x // x ∈ Gamma0 N } ⊢ ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 → A ∈ Gamma1' N [PROOFSTEP] intro ha [GOAL] case mpr N✝ N : ℕ A : { x // x ∈ Gamma0 N } ha : ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 ⊢ A ∈ Gamma1' N [PROOFSTEP] simp only [Gamma1_mem', Gamma0Map, MonoidHom.coe_mk, coe_matrix_coe, Int.coe_castRingHom, map_apply] [GOAL] case mpr N✝ N : ℕ A : { x // x ∈ Gamma0 N } ha : ↑(↑↑A 0 0) = 1 ∧ ↑(↑↑A 1 1) = 1 ∧ ↑(↑↑A 1 0) = 0 ⊢ ↑{ toFun := fun g => ↑(↑↑g 1 1), map_one' := (_ : ↑(OfNat.ofNat 1 1 1) = 1) } A = 1 [PROOFSTEP] exact ha.2.1 [GOAL] N✝ N : ℕ A : SL(2, ℤ) ⊢ A ∈ Gamma1 N ↔ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] constructor [GOAL] case mp N✝ N : ℕ A : SL(2, ℤ) ⊢ A ∈ Gamma1 N → ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] intro ha [GOAL] case mp N✝ N : ℕ A : SL(2, ℤ) ha : A ∈ Gamma1 N ⊢ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] simp_rw [Gamma1, Subgroup.mem_map] at ha [GOAL] case mp N✝ N : ℕ A : SL(2, ℤ) ha : ∃ x, x ∈ ⊤ ∧ ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) x = A ⊢ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] obtain ⟨⟨x, hx⟩, hxx⟩ := ha [GOAL] case mp.intro.mk N✝ N : ℕ A : SL(2, ℤ) x : { x // x ∈ Gamma0 N } hx : x ∈ Gamma1' N hxx : { val := x, property := hx } ∈ ⊤ ∧ ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) { val := x, property := hx } = A ⊢ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] rw [Gamma1_to_Gamma0_mem] at hx [GOAL] case mp.intro.mk N✝ N : ℕ A : SL(2, ℤ) x : { x // x ∈ Gamma0 N } hx✝ : x ∈ Gamma1' N hx : ↑(↑↑x 0 0) = 1 ∧ ↑(↑↑x 1 1) = 1 ∧ ↑(↑↑x 1 0) = 0 hxx : { val := x, property := hx✝ } ∈ ⊤ ∧ ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) { val := x, property := hx✝ } = A ⊢ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] simp only [Subgroup.mem_top, true_and] at hxx [GOAL] case mp.intro.mk N✝ N : ℕ A : SL(2, ℤ) x : { x // x ∈ Gamma0 N } hx✝ : x ∈ Gamma1' N hx : ↑(↑↑x 0 0) = 1 ∧ ↑(↑↑x 1 1) = 1 ∧ ↑(↑↑x 1 0) = 0 hxx : ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) { val := x, property := hx✝ } = A ⊢ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] rw [← hxx] [GOAL] case mp.intro.mk N✝ N : ℕ A : SL(2, ℤ) x : { x // x ∈ Gamma0 N } hx✝ : x ∈ Gamma1' N hx : ↑(↑↑x 0 0) = 1 ∧ ↑(↑↑x 1 1) = 1 ∧ ↑(↑↑x 1 0) = 0 hxx : ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) { val := x, property := hx✝ } = A ⊢ ↑(↑(↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) { val := x, property := hx✝ }) 0 0) = 1 ∧ ↑(↑(↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) { val := x, property := hx✝ }) 1 1) = 1 ∧ ↑(↑(↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) { val := x, property := hx✝ }) 1 0) = 0 [PROOFSTEP] convert hx [GOAL] case mpr N✝ N : ℕ A : SL(2, ℤ) ⊢ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 → A ∈ Gamma1 N [PROOFSTEP] intro ha [GOAL] case mpr N✝ N : ℕ A : SL(2, ℤ) ha : ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 ⊢ A ∈ Gamma1 N [PROOFSTEP] simp_rw [Gamma1, Subgroup.mem_map] [GOAL] case mpr N✝ N : ℕ A : SL(2, ℤ) ha : ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 ⊢ ∃ x, x ∈ ⊤ ∧ ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) x = A [PROOFSTEP] have hA : A ∈ Gamma0 N := by simp [ha.right.right, Gamma0_mem] [GOAL] N✝ N : ℕ A : SL(2, ℤ) ha : ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 ⊢ A ∈ Gamma0 N [PROOFSTEP] simp [ha.right.right, Gamma0_mem] [GOAL] case mpr N✝ N : ℕ A : SL(2, ℤ) ha : ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 hA : A ∈ Gamma0 N ⊢ ∃ x, x ∈ ⊤ ∧ ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) x = A [PROOFSTEP] have HA : (⟨A, hA⟩ : Gamma0 N) ∈ Gamma1' N := by simp only [Gamma1_to_Gamma0_mem, Subgroup.coe_mk, coe_matrix_coe, Int.coe_castRingHom, map_apply] exact ha [GOAL] N✝ N : ℕ A : SL(2, ℤ) ha : ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 hA : A ∈ Gamma0 N ⊢ { val := A, property := hA } ∈ Gamma1' N [PROOFSTEP] simp only [Gamma1_to_Gamma0_mem, Subgroup.coe_mk, coe_matrix_coe, Int.coe_castRingHom, map_apply] [GOAL] N✝ N : ℕ A : SL(2, ℤ) ha : ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 hA : A ∈ Gamma0 N ⊢ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] exact ha [GOAL] case mpr N✝ N : ℕ A : SL(2, ℤ) ha : ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 hA : A ∈ Gamma0 N HA : { val := A, property := hA } ∈ Gamma1' N ⊢ ∃ x, x ∈ ⊤ ∧ ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) x = A [PROOFSTEP] refine' ⟨(⟨(⟨A, hA⟩ : Gamma0 N), HA⟩ : (Gamma1' N : Subgroup (Gamma0 N))), _⟩ [GOAL] case mpr N✝ N : ℕ A : SL(2, ℤ) ha : ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 hA : A ∈ Gamma0 N HA : { val := A, property := hA } ∈ Gamma1' N ⊢ { val := { val := A, property := hA }, property := HA } ∈ ⊤ ∧ ↑(MonoidHom.comp (Subgroup.subtype (Gamma0 N)) (Subgroup.subtype (Gamma1' N))) { val := { val := A, property := hA }, property := HA } = A [PROOFSTEP] simp [GOAL] N✝ N : ℕ ⊢ Gamma1 N ≤ Gamma0 N [PROOFSTEP] intro x HA [GOAL] N✝ N : ℕ x : SL(2, ℤ) HA : x ∈ Gamma1 N ⊢ x ∈ Gamma0 N [PROOFSTEP] simp only [Gamma0_mem, Gamma1_mem, coe_matrix_coe, Int.coe_castRingHom, map_apply] at * [GOAL] N✝ N : ℕ x : SL(2, ℤ) HA : ↑(↑x 0 0) = 1 ∧ ↑(↑x 1 1) = 1 ∧ ↑(↑x 1 0) = 0 ⊢ ↑(↑x 1 0) = 0 [PROOFSTEP] exact HA.2.2 [GOAL] N : ℕ H K : Subgroup SL(2, ℤ) h : H ≤ K h2 : IsCongruenceSubgroup H ⊢ IsCongruenceSubgroup K [PROOFSTEP] obtain ⟨N, hN⟩ := h2 [GOAL] case intro N✝ : ℕ H K : Subgroup SL(2, ℤ) h : H ≤ K N : ℕ+ hN : Gamma ↑N ≤ H ⊢ IsCongruenceSubgroup K [PROOFSTEP] refine' ⟨N, le_trans hN h⟩ [GOAL] N✝ : ℕ N : ℕ+ ⊢ Gamma ↑N ≤ Gamma ↑N [PROOFSTEP] simp only [le_refl] [GOAL] N✝ : ℕ N : ℕ+ ⊢ IsCongruenceSubgroup (Gamma1 ↑N) [PROOFSTEP] refine' ⟨N, _⟩ [GOAL] N✝ : ℕ N : ℕ+ ⊢ Gamma ↑N ≤ Gamma1 ↑N [PROOFSTEP] intro A hA [GOAL] N✝ : ℕ N : ℕ+ A : SL(2, ℤ) hA : A ∈ Gamma ↑N ⊢ A ∈ Gamma1 ↑N [PROOFSTEP] simp only [Gamma1_mem, Gamma_mem] at * [GOAL] N✝ : ℕ N : ℕ+ A : SL(2, ℤ) hA : ↑(↑A 0 0) = 1 ∧ ↑(↑A 0 1) = 0 ∧ ↑(↑A 1 0) = 0 ∧ ↑(↑A 1 1) = 1 ⊢ ↑(↑A 0 0) = 1 ∧ ↑(↑A 1 1) = 1 ∧ ↑(↑A 1 0) = 0 [PROOFSTEP] simp only [hA, eq_self_iff_true, and_self_iff] [GOAL] N✝ N : ℕ g : ConjAct SL(2, ℤ) ⊢ g • Gamma N = Gamma N [PROOFSTEP] apply Subgroup.Normal.conjAct (Gamma_normal N) [GOAL] N : ℕ g : ConjAct SL(2, ℤ) Γ : Subgroup SL(2, ℤ) h : IsCongruenceSubgroup Γ ⊢ IsCongruenceSubgroup (g • Γ) [PROOFSTEP] obtain ⟨N, HN⟩ := h [GOAL] case intro N✝ : ℕ g : ConjAct SL(2, ℤ) Γ : Subgroup SL(2, ℤ) N : ℕ+ HN : Gamma ↑N ≤ Γ ⊢ IsCongruenceSubgroup (g • Γ) [PROOFSTEP] refine' ⟨N, _⟩ [GOAL] case intro N✝ : ℕ g : ConjAct SL(2, ℤ) Γ : Subgroup SL(2, ℤ) N : ℕ+ HN : Gamma ↑N ≤ Γ ⊢ Gamma ↑N ≤ g • Γ [PROOFSTEP] rw [← Gamma_cong_eq_self N g, Subgroup.pointwise_smul_le_pointwise_smul_iff] [GOAL] case intro N✝ : ℕ g : ConjAct SL(2, ℤ) Γ : Subgroup SL(2, ℤ) N : ℕ+ HN : Gamma ↑N ≤ Γ ⊢ Gamma ↑N ≤ Γ [PROOFSTEP] exact HN
module Ch03.Activation where import Prelude hiding (and, or) import Numeric.LinearAlgebra hiding (step) import Graphics.Gnuplot.Simple -- Activation functions step :: [R] -> [R] step = map (\x -> if x > 0.0 then 1.0 else 0.0) sigmoid :: [R] -> [R] sigmoid = map (\x -> 1 / (1 + exp (-x))) relu :: [R] -> [R] relu = map $ max 0 -- Graphs step_graph :: IO () step_graph = plotPath [Title "step", YRange (-0.2, 1.2)] $ zip xs ys where xs = linearScale 1000 (-5.0, 5.0) ys = step xs sigmoid_graph :: IO () sigmoid_graph = plotPath [Title "sigmoid", YRange (-0.2, 1.2)] $ zip xs ys where xs = linearScale 1000 (-5.0, 5.0) ys = sigmoid xs sigmoid_step_graph :: IO () sigmoid_step_graph = plotPathsStyle [Title "sigmoid and step", YRange (-0.2, 1.2)] [(style1, zip xs ys1), (style2, zip xs ys2)] where xs = linearScale 1000 (-5.0, 5.0) ys1 = sigmoid xs ys2 = step xs style1 = PlotStyle Lines $ CustomStyle [(LineTitle "sigmoid")] style2 = PlotStyle Lines $ CustomStyle [(LineTitle "step")] relu_graph :: IO () relu_graph = plotPath [Title "ReLU", YRange (-1.0, 5.5)] $ zip xs ys where xs = linearScale 1000 (-5.0, 5.0) ys = relu xs
lemma real_eq_imaginary_iff [simp]: assumes "y \<in> Reals" "x \<in> Reals" shows "x = \<i> * y \<longleftrightarrow> x=0 \<and> y=0"
theory Extended_Real_Lemma_Bucket imports Complex_Main "~~/src/HOL/Library/Extended_Real" "~~/src/HOL/Multivariate_Analysis/Extended_Real_Limits" begin lemma ereal_inverse_real: "\<bar>z\<bar> \<noteq> \<infinity> \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> ereal (inverse (real_of_ereal z)) = inverse z" by (cases z) simp_all lemma ereal_inverse_mult: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse (a * (b::ereal)) = inverse a * inverse b" by (cases a; cases b) auto lemma tendsto_PInfty': "(f ---> \<infinity>) F = (\<forall>r>c. eventually (\<lambda>x. ereal r < f x) F)" proof (subst tendsto_PInfty, intro iffI allI impI) assume A: "\<forall>r>c. eventually (\<lambda>x. ereal r < f x) F" fix r :: real from A have A: "eventually (\<lambda>x. ereal r < f x) F" if "r > c" for r using that by blast show "eventually (\<lambda>x. ereal r < f x) F" proof (cases "r > c") case False hence B: "ereal r \<le> ereal (c + 1)" by simp have "c < c + 1" by simp from A[OF this] show "eventually (\<lambda>x. ereal r < f x) F" by eventually_elim (rule le_less_trans[OF B]) qed (simp add: A) qed simp lemma tendsto_zero_erealI: assumes "\<And>e. e > 0 \<Longrightarrow> eventually (\<lambda>x. \<bar>f x\<bar> < ereal e) F" shows "(f ---> 0) F" proof (subst filterlim_cong[OF refl refl]) from assms[OF zero_less_one] show "eventually (\<lambda>x. f x = ereal (real_of_ereal (f x))) F" by eventually_elim (auto simp: ereal_real) hence "eventually (\<lambda>x. abs (real_of_ereal (f x)) < e) F" if "e > 0" for e using assms[OF that] by eventually_elim (simp add: real_less_ereal_iff that) hence "((\<lambda>x. real_of_ereal (f x)) ---> 0) F" unfolding tendsto_iff by (auto simp: tendsto_iff dist_real_def) thus "((\<lambda>x. ereal (real_of_ereal (f x))) ---> 0) F" by (simp add: zero_ereal_def) qed lemma tendsto_inverse_ereal: assumes lim: "(f ---> (c :: ereal)) F" assumes nonneg: "eventually (\<lambda>x. f x \<ge> 0) F" shows "((\<lambda>x. inverse (f x)) ---> inverse c) F" proof (cases "F = bot") assume F: "F \<noteq> bot" from F assms have c: "c \<ge> 0" by (rule tendsto_le_const) then consider "c = 0" | "c = \<infinity>" | c' where "c = ereal c'" "c' > 0" by (cases c) (auto simp: le_less) thus ?thesis proof cases fix c' assume c': "c = ereal c'" "c' > 0" with c' have f: "eventually (\<lambda>x. f x > 0) F" "eventually (\<lambda>x. f x < \<infinity>) F" by (intro order_tendstoD[OF lim]; simp)+ hence "((ereal \<circ> (real_of_ereal \<circ> f)) ---> c) F" by (intro Lim_transform_eventually[OF _ lim], eventually_elim) (simp add: ereal_real) hence "((\<lambda>x. real_of_ereal (f x)) ---> c') F" by (simp add: c' o_def) with c' have "((inverse \<circ> real_of_ereal \<circ> f) ---> inverse c') F" unfolding o_def by (intro tendsto_inverse) simp_all with c' have "((ereal \<circ> inverse \<circ> real_of_ereal \<circ> f) ---> inverse c) F" by (simp add: o_def) moreover from f have "eventually (\<lambda>x. (ereal \<circ> inverse \<circ> real_of_ereal \<circ> f) x = inverse (f x)) F" by eventually_elim (simp add: ereal_inverse_real) ultimately show "((\<lambda>x. inverse (f x)) ---> inverse c) F" by (rule Lim_transform_eventually[rotated]) next assume "c = 0" hence "c < \<infinity>" and c: "c = ereal 0" by simp_all note f = order_tendstoD(2)[OF lim this(1)] from lim c have lim': "((\<lambda>x. real_of_ereal (f x)) ---> 0) F" using lim_real_of_ereal[of f 0 F] by simp have "eventually (\<lambda>x. ereal r < inverse (f x)) F" if "r > 0" for r proof - from that have "inverse r > 0" by simp from nonneg f order_tendstoD(2)[OF lim' this] show ?thesis proof eventually_elim fix x assume "f x \<ge> 0" "f x < \<infinity>" "real_of_ereal (f x) < inverse r" with that show "inverse (f x) > ereal r" by (cases "f x") (simp_all add: field_simps) qed qed thus ?thesis by (simp add: c tendsto_PInfty'[of _ _ 0]) next assume c: "c = \<infinity>" hence f: "eventually (\<lambda>x. f x > 0) F" by (intro order_tendstoD[OF lim]) simp_all { fix r :: real assume r: "r > 0" from tendsto_PInfty lim have "eventually (\<lambda>x. f x > ereal (inverse r)) F" by (simp add: tendsto_PInfty c) with f have "eventually (\<lambda>x. abs (inverse (f x)) < ereal r) F" proof eventually_elim fix x assume "f x > 0" "ereal (inverse r) < f x" with r show "abs (inverse (f x)) < ereal r" by (cases "f x") (simp_all add: field_simps) qed } with c show "((\<lambda>x. inverse (f x)) ---> inverse c) F" by (force intro: tendsto_zero_erealI) qed qed simp lemma continuous_inverse_ereal_nonneg [continuous_intros]: "continuous_on ({0..} :: ereal set) inverse" unfolding continuous_on_def proof clarify fix x :: ereal assume "x \<ge> 0" thus "(inverse ---> inverse x) (at x within {0..})" by (intro tendsto_inverse_ereal) (auto simp: eventually_at_topological) qed lemma continuous_uminus_ereal [continuous_intros]: "continuous_on (A :: ereal set) uminus" unfolding continuous_on_def by (intro ballI tendsto_uminus_ereal[of "\<lambda>x. x::ereal"]) simp lemma ereal_uminus_atMost [simp]: "uminus ` {..(a::ereal)} = {-a..}" proof (intro equalityI subsetI) fix x :: ereal assume "x \<in> {-a..}" hence "-(-x) \<in> uminus ` {..a}" by (intro imageI) (simp add: ereal_uminus_le_reorder) thus "x \<in> uminus ` {..a}" by simp qed auto lemma continuous_inverse_ereal_nonpos: "continuous_on ({..<0} :: ereal set) inverse" proof (subst continuous_on_cong[OF refl]) have "continuous_on {(0::ereal)<..} inverse" by (rule continuous_on_subset[OF continuous_inverse_ereal_nonneg]) auto thus "continuous_on {..<(0::ereal)} (uminus \<circ> inverse \<circ> uminus)" by (intro continuous_intros) simp_all qed simp end
Program check Implicit None Print *, 'Put some tests in here!' End Program check
module Test import Test.Golden tests : TestPool tests = MkTestPool "Hello World" [] Nothing [ "000-hello"] export main : IO () main = runner [ tests ] -- [ EOF ]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include "tz_error.h" #if HAVE_LIBGSL == 1 #include <gsl/gsl_vector.h> #include <gsl/gsl_statistics_double.h> #endif #include "tz_constant.h" #include "tz_iarray.h" #include "tz_darray.h" #include "tz_voxel_linked_list.h" #include "tz_stack_sampling.h" #include "tz_voxel_graphics.h" #include "tz_neurotrace.h" #include "tz_stack_math.h" #include "tz_stack_utils.h" #include "tz_objdetect.h" #include "tz_voxeltrans.h" #include "tz_stack_stat.h" #include "tz_stack_draw.h" #include "tz_geo3d_vector.h" #include "tz_stack_bwmorph.h" #include "tz_vrml_io.h" #include "tz_locseg_chain.h" #include "tz_trace_utils.h" #include "tz_fmatrix.h" #include "tz_fimage_lib.h" #include "tz_arraytrans.h" #include "tz_neuron_structure.h" #include "tz_utilities.h" #include "tz_workspace.h" #include "tz_stack_graph.h" #include "tz_stack_attribute.h" #include "tz_math.h" #include "tz_stack_threshold.h" INIT_EXCEPTION_MAIN(e) int main(int argc, char* argv[]) { #if 0 Stack *stack = Read_Stack("/tmp/binimg.tif"); Stack *dist = Stack_Bwdist(stack); Stack *seeds = Stack_Local_Max(dist, NULL, STACK_LOCMAX_ALTER1); Write_Stack("/tmp/seedimg.tif", seeds); #endif #if 0 Stack *stack = Read_Stack("/tmp/seedimg.tif"); Voxel_List *list = Stack_To_Voxel_List(stack); Print_Voxel_List(list); Kill_Stack(stack); stack = Read_Stack("/tmp/binimg.tif"); Stack *dist = Stack_Bwdist(stack); Pixel_Array *pa = Voxel_List_Sampling(dist, list); Print_Pixel_Array(pa); Pixel_Array_Write("/tmp/seeds.pa", pa); #endif #if 0 Stack *stack = Read_Stack("/tmp/seedimg.tif"); Voxel_List *list = Stack_To_Voxel_List(stack); //Print_Voxel_List(list); Pixel_Array *pa = Pixel_Array_Read("/tmp/seeds.pa"); //Print_Pixel_Array(pa); Voxel *seed; int i; double *pa_array = (double *) pa->array; gsl_vector_view gv = gsl_vector_view_array(pa_array, pa->size); printf("mean: %g, std: %g\n", gsl_stats_mean(pa_array, 1, pa->size), sqrt(gsl_stats_variance(pa_array, 1, pa->size))); double threshold = gsl_stats_mean(pa_array, 1, pa->size) + 3.0 * sqrt(gsl_stats_variance(pa_array, 1, pa->size)); dim_type dim[3]; dim[0] = stack->width; dim[1] = stack->height; dim[2] = stack->depth; IMatrix *chord = Make_IMatrix(dim, 3); Stack *code = Make_Stack(GREY16, stack->width, stack->height, stack->depth); Kill_Stack(stack); stack = Read_Stack("/tmp/binimg.tif"); Stack_Not(stack, stack); Rgb_Color color; Set_Color(&color, 255, 0, 0); Stack *signal = Read_Stack("../data/testneurotrace.tif"); Stack *canvas = Translate_Stack(signal, COLOR, 0); /************** soma detection *************/ #if 0 Struct_Element *se = Make_Ball_Se(((int) threshold)); Stack *stack1 = Stack_Erode_Fast(stack, NULL, se); Stack *soma = Stack_Dilate(stack1, NULL, se); Kill_Stack(stack1); Stack_And(stack, soma, soma); Stack_Label_Bwc(canvas, soma, color); Kill_Stack(soma); Write_Stack("../data/test.tif", canvas); return 0; #endif /*******************************************/ Object_3d *obj = NULL; int seed_offset = -1; Neurochain *chain = NULL; double z_scale = 0.8; Stack *traced = Make_Stack(GREY, signal->width, signal->height, signal->depth); One_Stack(traced); for (i = 0; i < pa->size; i++) { seed = Voxel_Queue_De(&list); printf("%d, color: %u, %u, %u\n", i, *STACK_PIXEL_8(canvas, seed->x, seed->y, seed->z, 0), *STACK_PIXEL_8(canvas, seed->x, seed->y, seed->z, 1), *STACK_PIXEL_8(canvas, seed->x, seed->y, seed->z, 2)); if (*STACK_PIXEL_8(canvas, seed->x, seed->y, seed->z, 2) == 0) { continue; } double width = pa_array[i]; if (width > threshold) { continue; } chain = New_Neurochain(); Print_Voxel(seed); printf("%g\n", width); int max_level = (int) (width + 0.5); if (max_level < 6) { max_level = 6; } seed_offset = Stack_Util_Offset(seed->x, seed->y, seed->z, stack->width, stack->height, stack->depth); Stack_Level_Code_Constraint(stack, code, chord->array, &seed_offset, 1, max_level + 1); Voxel_t v; Voxel_To_Tvoxel(seed, v); Print_Tvoxel(v); Stack *tmp_stack = Copy_Stack(stack); obj = Stack_Grow_Object_Constraint(tmp_stack, 1, v, chord, code, max_level); Free_Stack(tmp_stack); Print_Object_3d_Info(obj); double vec[3]; Object_3d_Orientation_Zscale(obj, vec, MAJOR_AXIS, z_scale); double theta, psi; Geo3d_Vector obj_vec; Set_Geo3d_Vector(&obj_vec, vec[0], vec[1], vec[2]); darray_print2(vec, 3, 1); Geo3d_Vector_Orientation(&obj_vec, &theta, &psi); Set_Neuroseg(&(chain->locseg.seg), width, width, 10.0, theta, psi); double cpos[3]; cpos[0] = seed->x; cpos[1] = seed->y; cpos[2] = seed->z; cpos[2] *= 0.8; Set_Neuroseg_Position(&(chain->locseg), cpos, NEUROSEG_CENTER); if (Initialize_Tracing(signal, chain, NULL, z_scale) >= MIN_SCORE) { chain = Trace_Neuron(signal, chain, BOTH, traced, z_scale); Print_Neurochain(chain); //Stack_Draw_Object_Bwc(canvas, obj, color); Neurochain_Erase(traced, Neurochain_Head(chain), z_scale); Neurochain_Label(canvas, Neurochain_Head(chain), z_scale); } Free_Neurochain(chain); free(seed); Kill_Object_3d(obj); } Write_Stack("../data/test2.tif", traced); Write_Stack("../data/test.tif", canvas); #endif #if 0 Stack *stack = Read_Stack("/tmp/seedimg.tif"); Voxel_List *list = Stack_To_Voxel_List(stack); Kill_Stack(stack); stack = Read_Stack("../data/testneurotrace.tif"); Pixel_Array *pa = Voxel_List_Sampling(stack, list); Print_Pixel_Array(pa); Pixel_Array_Write("/tmp/test.pa", pa); Pixel_Array *pa2 = Pixel_Array_Read("/tmp/test.pa"); Print_Pixel_Array(pa2); #endif #if 0 Stack *stack = Read_Stack("../data/fly_neuron.tif"); double z_scale = 1.0; Neurochain *chain = New_Neurochain(); #if 0 Set_Neuroseg(&(chain->locseg.seg), 2.78302, 3.60932, 12.0, 3.58051, 4.6416); Set_Neuropos(chain->locseg.pos, 308.154, 49.7471, 134.73); #endif #if 0 Set_Neuroseg(&(chain->locseg.seg), 2.7830153868018668, 3.6093167912750355, 12.0, 3.5805148810681988, 4.641602279067599); Set_Neuropos(chain->locseg.pos, 308.15367011522028, 49.747085927056794, 134.73010125059292); #endif #if 0 Set_Neuroseg(&(chain->locseg.seg), 2.7165, 3.49483, 12.0, 3.39146, 4.70638); Set_Neuropos(chain->locseg.pos, 306.119, 49.8914, 139.075); #endif #if 0 Set_Neuroseg(&(chain->locseg.seg), 3.17991, 4.56142, 12.0, 2.10521, 2.34306, 0); Set_Neuropos(chain->locseg.pos, 344.281, 258.937, 138.332); #endif Set_Neuroseg(&(chain->locseg.seg), 2.12805, 3.37411, 12.0, 2.94503, 2.25645, 0); Set_Neuropos(chain->locseg.pos, 343.556, 258.344, 143.04); //refit_local_neuroseg(&(chain->locseg), stack, z_scale, NULL); Neuroseg_Fit_Score fs; fs.n = 1; fs.options[0] = 1; printf("%g\n", Local_Neuroseg_Score(&(chain->locseg), stack, z_scale, &fs)); //Trace_Neuron2(stack, chain, BACKWARD, NULL, z_scale, 10); //Print_Neurochain(chain); stack = Translate_Stack(stack, COLOR, 1); Neurochain_Label(stack, Neurochain_Head(chain), z_scale); Write_Stack("../data/test.tif", stack); #endif #if 0 Stack *stack = Read_Stack("../data/testneurotrace.tif"); double z_scale = 0.488/0.585; Neurochain *chain = New_Neurochain(); Set_Neuroseg(&(chain->locseg.seg), 2.0, 2.0, 12.0, -TZ_PI_2, 0.0); //Set_Neuropos(chain->locseg.pos, 95, 96, 162*0.8); //Set_Neuropos(chain->locseg.pos, 39, 192, 283 * z_scale); Set_Neuropos(chain->locseg.pos, 129, 170, 239 * z_scale); //Trace_Neuron(stack, chain, BOTH, NULL, z_scale, 100); //Set_Neuropos(chain->locseg.pos, 143, 99, 107*0.8); //Set_Position(chain->position, 127, 68, 34*0.8); //Set_Position(chain->position, 60, 136, 91*0.8); //Set_Position(chain->position, 176, 221, 184*0.8); //Fit_Local_Neuroseg(stack, &(chain->seg), chain->position, TRUE); /* Set_Neuroseg(&(chain->locseg.seg), 1.8295717513170491, 1.2647574210394514, 12, -1.2864278377709504, 0.51799979287881037); Set_Neuropos(chain->locseg.pos, 91.370009398825573, 98.614687377839488, 131.9121806489851); */ /* Set_Neuroseg(&(chain->locseg.seg), 5, 5, 11.1336, -TZ_PI_2, 0.0); Set_Neuropos(chain->locseg.pos, 90.1456, 99.1741, 132.564); */ int i; for (i = 0; i < 1; i++) { Initialize_Tracing(stack, chain, NULL, z_scale); } /* int var_index[LOCAL_NEUROSEG_NPARAM]; int nvar = Local_Neuroseg_Var_Mask_To_Index(NEUROSEG_VAR_MASK_ORIENTATION, NEUROPOS_VAR_MASK_NONE, var_index); Fit_Local_Neuroseg(&(chain->locseg), stack, var_index, nvar, z_scale, NULL); nvar = Local_Neuroseg_Var_Mask_To_Index(NEUROSEG_VAR_MASK_R, NEUROPOS_VAR_MASK_NONE, var_index); Fit_Local_Neuroseg(&(chain->locseg), stack, var_index, nvar, z_scale, NULL); printf("score: %g\n", Local_Neuroseg_Score(&(chain->locseg), stack, z_scale, NULL)); */ Trace_Neuron2(stack, chain, BOTH, NULL, z_scale, 10); //Print_Neurochain(chain); stack = Translate_Stack(stack, COLOR, 1); Neurochain_Label(stack, Neurochain_Head(chain), z_scale); //Flip_Local_Neuroseg(&(chain->locseg)); //Local_Neuroseg_Label(&(chain->locseg), stack, 1, z_scale); Write_Stack("../data/test.tif", stack); Kill_Stack(stack); #endif #if 0 /* fly neuron tracing */ //Stack *stack = Read_Stack("../data/fly_neuron.tif"); //Stack *stack = Read_Stack("../data/resimg.tif"); Stack *stack = Read_Stack("../data/fly_neuron2.tif"); double z_scale = 1.0; Neurochain *chain = New_Neurochain(); //Set_Neuroseg(&(chain->locseg.seg), 2.19832, 2.18053, 12, -3.54093, 0.779524); Set_Neuropos(chain->locseg.pos, 166, 325, 43); /* fly_neuron2 */ Set_Neuroseg(&(chain->locseg.seg), 2.0, 2.0, 12.0, -TZ_PI_2, 0.0); //Set_Neuroseg(&(chain->locseg.seg), 2.0, 2.0, 12.0, TZ_PI_2, TZ_PI_2); //Set_Neuroseg(&(chain->locseg.seg), 1.70074, 1.09443, 12, 2.12734, 1.77422); //Set_Neuroseg(&(chain->locseg.seg), 4.51936, 4.19414, 12, 3.56059, 3.13054); //Set_Neuropos(chain->locseg.pos, 294, 178, 172); //Set_Neuropos(chain->locseg.pos, 280.328, 60.8357, 198.226); //Set_Neuropos(chain->locseg.pos, 281, 64, 202); //Set_Neuropos(chain->locseg.pos, 207, 227, 168); //Set_Neuropos(chain->locseg.pos, 166, 238, 141); //Set_Neuropos(chain->locseg.pos, 294, 178, 175); //Set_Neuropos(chain->locseg.pos, 296, 217, 160); //Set_Neuropos(chain->locseg.pos, 296, 217, 160); //Set_Neuropos(chain->locseg.pos, 282, 64, 204); //Set_Neuropos(chain->locseg.pos, 294, 255, 158); //Set_Neuropos(chain->locseg.pos, 220, 342, 68); //Set_Neuropos(chain->locseg.pos, 227, 283, 139); //Set_Neuropos(chain->locseg.pos, 231, 327, 67); //Set_Neuropos(chain->locseg.pos, 179, 266, 142); //Set_Neuropos(chain->locseg.pos, 246.546, 296.202, 106.407); //Set_Neuropos(chain->locseg.pos, 307.867, 62.5301, 274.218); //Trace_Neuron(stack, chain, BOTH, NULL, z_scale, 100); //Set_Neuropos(chain->locseg.pos, 143, 99, 107*0.8); //Set_Position(chain->position, 127, 68, 34*0.8); //Set_Position(chain->position, 60, 136, 91*0.8); //Set_Position(chain->position, 176, 221, 184*0.8); //Fit_Local_Neuroseg(stack, &(chain->seg), chain->position, TRUE); /* Set_Neuroseg(&(chain->locseg.seg), 1.8295717513170491, 1.2647574210394514, 12, -1.2864278377709504, 0.51799979287881037); Set_Neuropos(chain->locseg.pos, 91.370009398825573, 98.614687377839488, 131.9121806489851); */ /* Set_Neuroseg(&(chain->locseg.seg), 5, 5, 11.1336, -TZ_PI_2, 0.0); Set_Neuropos(chain->locseg.pos, 90.1456, 99.1741, 132.564); */ int i; for (i = 0; i < 1; i++) { Initialize_Tracing(stack, chain, NULL, z_scale); } #if 0 /* int var_index[LOCAL_NEUROSEG_NPARAM]; int nvar = Local_Neuroseg_Var_Mask_To_Index(NEUROSEG_VAR_MASK_ORIENTATION, NEUROPOS_VAR_MASK_NONE, var_index); Fit_Local_Neuroseg(&(chain->locseg), stack, var_index, nvar, z_scale, NULL); nvar = Local_Neuroseg_Var_Mask_To_Index(NEUROSEG_VAR_MASK_R, NEUROPOS_VAR_MASK_NONE, var_index); Fit_Local_Neuroseg(&(chain->locseg), stack, var_index, nvar, z_scale, NULL); printf("score: %g\n", Local_Neuroseg_Score(&(chain->locseg), stack, z_scale, NULL)); */ Trace_Neuron2(stack, chain, FORWARD, NULL, z_scale, 30); #endif Print_Neurochain(chain); printf("%g\n", Local_Neuroseg_Score(&(chain->locseg), stack, z_scale, NULL)); stack = Translate_Stack(stack, COLOR, 1); Neurochain_Label(stack, Neurochain_Head(chain), z_scale); //Flip_Local_Neuroseg(&(chain->locseg)); //Local_Neuroseg_Label(&(chain->locseg), stack, 1, z_scale); Write_Stack("../data/test.tif", stack); Kill_Stack(stack); #endif #if 0 /* check segments */ Neurochain *chain = New_Neurochain(); FILE *fp = fopen("../data/fly_neuron/chain103.bn", "r"); Neurochain_Fread(chain, fp); fclose(fp); int length = Neurochain_Length(chain, FORWARD); printf("%d\n", length); //Print_Neurochain(chain); Stack *stack = Read_Stack("../data/fly_neuron.tif"); double z_scale = 1.0; Neuroseg_Fit_Score fs; fs.n = 1; fs.options[0] = 1; double score = Neurochain_Score(chain, stack, z_scale, &fs); printf("%g\n", score / length); #endif #if 0 /* check chain features */ char cmd[100]; sprintf(cmd, "ls ../data/%s/*.wrl > ../data/%s/wrllist.txt") system(cmd); #endif #if 0 /* read stack */ Stack *stack = Read_Stack("../data/run_w1_t1.tif"); double z_scale = 1.0; /* Initialize neurochain */ Neurochain *chain = New_Neurochain(); Set_Neuroseg(&(chain->locseg.seg), 3.0, 3.0, 12.0, 0.0, 0.0, 0.0); Set_Neuropos(chain->locseg.pos, 72, 35, 0); //Initialize_Tracing(stack, chain, NULL, z_scale); Trace_Neuron2(stack, chain, FORWARD, NULL, z_scale, 30); Translate_Stack(stack, COLOR, 1); Neurochain_Label(stack, Neurochain_Head(chain), z_scale); Write_Stack("../data/test.tif", stack); #endif #if 0 double pos[] = {268, 265, 56}; double r = 3.0; Local_Neuroseg_Ellipse *locne = New_Local_Neuroseg_Ellipse(); Set_Local_Neuroseg_Ellipse(locne, r, r, TZ_PI_2, 0, 0, 0, pos[0], pos[1], pos[2]); char *imgfile = "../data/mouse_neuron.tif"; Stack *stack = Read_Stack(imgfile); Locne_Chain *chain = Trace_Soma(stack, 1.0, locne, NULL); double point[] = {277.5, 255.5, 56.5}; BOOL hit = Locne_Chain_Hittest(chain, point); if (hit == TRUE) { printf("The point hits the object\n"); } else { printf("The point misses the object\n"); } #endif #if 0 Geo3d_Scalar_Field *seed = Read_Geo3d_Scalar_Field("../data/mouse_neuron_org/seeds"); int *indices = iarray_malloc(seed->size); double *values = darray_malloc(seed->size); int i; for (i = 0; i < seed->size; i++) { indices[i] = i; } darraycpy(values, seed->values, 0, seed->size); darray_qsort(values, indices, seed->size); int index = indices[seed->size-1]; printf("%d\n", seed->size); printf("%g\n", seed->values[index]); printf("%g, %g, %g\n", seed->points[index][0], seed->points[index][1], seed->points[index][2]); double r = seed->values[index]; Local_Neuroseg_Ellipse *segs[10]; segs[0] = New_Local_Neuroseg_Ellipse(); Set_Local_Neuroseg_Ellipse(segs[0], r, r, TZ_PI_2, 0, 0, 0, 0, seed->points[index][0], seed->points[index][1], seed->points[index][2]); char *imgfile = "../data/mouse_neuron_org.tif"; Stack *stack = Read_Stack(imgfile); Locne_Chain *somas[10]; int nsoma = 0; Soma_Trace_Workspace *stw = New_Soma_Trace_Workspace(); stw->tw.dyvar[0] = r * 3.0; stw->tw.dyvar[1] = 5.0; stw->tw.test_func = Locne_Chain_Trace_Test; somas[nsoma++] = Trace_Soma(stack, 1.0, segs[0], stw); int j; for (i = seed->size - 1; i >= 0; i--) { BOOL traced = FALSE; for (j = 0; j < nsoma; j++) { if (Locne_Chain_Hittest(somas[j], seed->points[indices[i]]) == TRUE) { traced = TRUE; Print_Coordinate_3d(seed->points[indices[i]]); break; } } if (traced == FALSE) { index = indices[i]; r = seed->values[index]; segs[nsoma] = New_Local_Neuroseg_Ellipse(); Set_Local_Neuroseg_Ellipse(segs[nsoma], r, r, TZ_PI_2, 0, 0, 0, 0, seed->points[index][0], seed->points[index][1], seed->points[index][2]); somas[nsoma] = Trace_Soma(stack, 1.0, segs[nsoma], stw); nsoma++; } if (nsoma >= 10) { break; } } for (i = 0; i < nsoma; i++) { Print_Local_Neuroseg_Ellipse(segs[i]); printf("soma score: %g\n", Soma_Score(somas[i])); if (Soma_Score(somas[i]) > 1.0) { char file_path[100]; sprintf(file_path, "../data/mouse_neuron/soma%d.bn", i); Write_Locne_Chain(file_path, somas[i]); //Soma_Stack_Mask(somas[i], stack, 1.0, 0.0); } } darray_write("../data/test.bn", values, seed->size); //Write_Stack("../data/test.tif", stack); # if 1 Stack *label = Make_Stack(FLOAT32, stack->width, stack->height, stack->depth); Zero_Stack(label); double coef[] = {0.1, 255.0}; double range[] = {0.0, 10000.0}; FILE *fp = fopen("../data/test.wrl", "w"); Vrml_Head_Fprint(fp, "V2.0", "utf8"); Geo3d_Scalar_Field* field = NULL; Local_Neuroseg_Ellipse *locne; for (i = 0; i < nsoma; i++) { if ((Soma_Score(somas[i]) > 1.0) && Locne_Chain_Length(somas[i]) >= 10) { Locne_Chain *chain = somas[i]; Locne_Chain_Vrml_Fprint(fp, chain, 0); Locne_Chain_Iterator_Start(chain); int offset = 0; while ((locne = Locne_Chain_Next(chain)) != NULL) { field = Local_Neuroseg_Ellipse_Field(locne, 0.5, NULL); Geo3d_Scalar_Field_Draw_Stack(field, label, coef, range); Kill_Geo3d_Scalar_Field(field); offset++; } //printf("%d\n", Locne_Chain_Length(chain)); } } fclose(fp); /* Turn the stack to GREY type */ label = Scale_Float_Stack((float *) label->array, label->width, label->height, label->depth, GREY); /* Make canvas */ Translate_Stack(stack, COLOR, 1); /* Label the canvas */ Stack_Label_Color(stack, label, 5.0, 1.0, label); /* Save the stack */ Write_Stack("../data/test.tif", stack); # endif #endif #if 0 Trace_Workspace *tw = New_Trace_Workspace(); tw->trace_direction = DL_FORWARD; Stack *stack = Read_Stack("../data/fly_neuron2.tif"); double z_scale = 1.0; Local_Neuroseg *locseg = New_Local_Neuroseg(); Set_Neuropos(locseg->pos, 166, 325, 43); /* fly_neuron2 */ Set_Neuroseg(&(locseg->seg), 2.0, 2.0, 12.0, -TZ_PI_2, 0.0, 0.0); tw->test_func = Locseg_Chain_Trace_Test; tw->dyvar[0] = 10.0; Stack_Fit_Score fs; fs.n = 2; fs.options[0] = 0; fs.options[1] = tw->tscore_option; Locseg_Chain* chain = Locseg_Chain_Trace_Init(stack, z_scale, locseg, &fs); Trace_Locseg(stack, z_scale, chain, tw); Print_Locseg_Chain(chain); Translate_Stack(stack, COLOR, 1); Locseg_Chain_Label(chain, stack, z_scale); Write_Stack("../data/test.tif", stack); #endif #if 0 Trace_Workspace *tw = New_Trace_Workspace(); tw->trace_direction = DL_BOTHDIR; Stack *stack = Read_Stack("../data/fly_neuron2.tif"); double z_scale = 1.0; Local_Neuroseg *locseg = New_Local_Neuroseg(); Set_Neuropos(locseg->pos, 164, 322, 43); Set_Neuroseg(&(locseg->seg), 2.0, 0.0, 12.0, -TZ_PI_2, 0.0, 0.0, 0.0, 1.0); //Local_Neuroseg_Height_Search_P(locseg, stack, 1.0); Print_Local_Neuroseg(locseg); tw->test_func = Locseg_Chain_Trace_Test; tw->dyvar[0] = 10.0; Locseg_Fit_Workspace *fw = New_Locseg_Fit_Workspace(); Locseg_Chain* chain = Locseg_Chain_Trace_Init(stack, z_scale, locseg, fw); // Local_Neuroseg_Height_Search_P(locseg, stack, 1.0); Print_Locseg_Chain(chain); Trace_Locseg(stack, z_scale, chain, tw); //Locseg_Chain_Remove_Overlap_Ends(chain); //Locseg_Chain_Remove_Turn_Ends(chain, 1.0); /* Local_Neuroseg_Plane *locnp = Local_Neuroseg_To_Plane(locseg, 12.0, NULL); Locnp_Chain *locnp_chain = Locnp_Chain_Trace_Init(stack, z_scale, locnp); tw->length = locseg->seg.h * 10; tw->fit_first = FALSE; tw->tscore_option = 1; tw->min_score = 0.5; tw->trace_direction = DL_FORWARD; tw->trace_mask = NULL; tw->dyvar[0] = 100.0; tw->test_func = Locnp_Chain_Trace_Test; Trace_Locnp(stack, 1.0, locnp_chain, tw); Locseg_Chain_Append_Locnp(chain, locnp_chain); Kill_Locnp_Chain(locnp_chain); */ Translate_Stack(stack, COLOR, 1); Locseg_Chain_Label(chain, stack, z_scale); Write_Stack("../data/test.tif", stack); Kill_Stack(stack); Kill_Locseg_Chain(chain); #endif #if 0 Neurochain *chain = Read_Neurochain("../data/mouse_neuron3_org/chain9810.bn"); Stack *stack = Read_Stack("../data/mouse_neuron3_org.tif"); double z_scale = 1.0; Locseg_Chain *locseg_chain = Neurochain_To_Locseg_Chain(chain); Locseg_Chain_Remove_End(locseg_chain, DL_HEAD); Locseg_Chain_Remove_End(locseg_chain, DL_TAIL); Print_Locseg_Chain(locseg_chain); Trace_Workspace tw; tw.length = 100; tw.fit_first = FALSE; tw.tscore_option = 1; tw.min_score = 0.3; tw.trace_direction = DL_FORWARD; tw.trace_mask = NULL;//Read_Stack("../data/mouse_neuron3_org/trace_mask.tif"); tw.dyvar[0] = 10.0; tw.test_func = Locnp_Chain_Trace_Test; Locseg_Chain_Trace_Np(stack, z_scale, locseg_chain, &tw); Stretch_Stack_Value_Q(stack, 0.999); Stack *canvas = Translate_Stack(stack, COLOR, 1); Locseg_Chain_Label(locseg_chain, canvas, 1.0); Write_Stack("../data/test.tif", canvas); #endif #if 0 Stack *stack1 = Read_Stack("../data/fly_neuron/trace_mask.tif"); Stack *stack2 = Read_Stack("../data/fly_neuron/mask.tif"); Stack_And(stack1, stack2, stack2); Write_Stack("../data/test.tif", stack2); #endif #if 0 static char *Spec[] = { "-p <int> <int> <int>", NULL}; Process_Arguments(argc, argv, Spec, 1); double pos[3]; pos[0] = Get_Int_Arg("-p", 1); pos[1] = Get_Int_Arg("-p", 2); pos[2] = Get_Int_Arg("-p", 3); Geo3d_Scalar_Field *seed = Read_Geo3d_Scalar_Field("../data/mouse_neuron3_org/seeds"); int i; for (i = 0; i < seed->size; i++) { if ((fabs(pos[0] - seed->points[i][0]) < 1.0) && (fabs(pos[1] - seed->points[i][1]) < 1.0) && (fabs(pos[2] - seed->points[i][2]) < 1.0)) { printf("%d, %g\n", i, seed->values[i]); break; } } char chain_file_path[100]; sprintf(chain_file_path, "../data/mouse_neuron3_org/chain%d.bn", i); Neurochain *chain = Read_Neurochain(chain_file_path); Print_Neurochain(chain); #endif #if 0 Trace_Record *tr = NULL; fp = fopen("../data/test", "w"); Trace_Record_Fwrite(tr, fp); fclose(fp); #endif #if 0 Geo3d_Scalar_Field *seed = Read_Geo3d_Scalar_Field("../data/adult_fly_neuron/seeds"); Stack *stack = Read_Stack("../data/adult_fly_neuron.tif"); double z_scale = 1.0; int index = 1213; double r0 = seed->values[index]; if (r0 < 3.0) { r0 = 3.0; } printf("(%g %g %g) %g\n", seed->points[index][0], seed->points[index][1], seed->points[index][2], seed->values[index]); Local_Neuroseg *locseg = New_Local_Neuroseg(); Set_Neuroseg_Position(locseg, seed->points[index], NEUROSEG_CENTER); Set_Neuroseg(&(locseg->seg), r0, r0, 12.0, 0.0, 0.0, 0.0); Stack_Fit_Score ortfs; ortfs.n = 1; ortfs.options[0] = STACK_FIT_CORRCOEF; Local_Neuroseg_Orientation_Search_C(locseg, stack, z_scale, &ortfs); Trace_Workspace *tw = New_Trace_Workspace(); tw->length = 200; tw->fit_first = FALSE; tw->tscore_option = STACK_FIT_CORRCOEF; tw->min_score = 0.3; tw->trace_direction = DL_BOTHDIR; tw->trace_status[0] = TRACE_NORMAL; tw->trace_status[1] = TRACE_NORMAL; tw->trace_range[0] = 0; tw->trace_range[1] = 0; tw->trace_range[2] = 0; tw->trace_range[3] = stack->width - 1; tw->trace_range[4] = stack->height - 1; tw->trace_range[5] = stack->depth - 1; tw->trace_mask = NULL; tw->dyvar[0] = 10.0; tw->test_func = Locseg_Chain_Trace_Test; Stack_Fit_Score fs; fs.n = 1; fs.options[0] = tw->tscore_option; Locseg_Chain *chain = Locseg_Chain_Trace_Init(stack, z_scale, locseg, &fs); tic(); if (fs.scores[0] >= tw->min_score) { Trace_Locseg(stack, z_scale, chain, tw); } printf("time passed: %lld\n", toc()); Print_Locseg_Chain(chain); Translate_Stack(stack, GREY, 1); Stretch_Stack_Value_Q(stack, 0.999); Stack *canvas = Translate_Stack(stack, COLOR, 0); Neurochain *chain_head = Neurochain_From_Locseg_Chain(chain); Neurochain_Label(canvas, chain_head, z_scale); Write_Stack("../data/test.tif", canvas); Kill_Stack(canvas); Kill_Stack(stack); #endif #if 0 Locseg_Chain *chain1 = Read_Locseg_Chain("../data/fly_neuron/chain26.bn"); Locseg_Chain *chain2 = Read_Locseg_Chain("../data/fly_neuron/chain90.bn"); Stack *stack = Read_Stack("../data/fly_neuron.tif"); neurocomp_conn_t conn; conn[0] = NEUROCOMP_CONN_HL; Locseg_Chain_Connection_Test(chain1, chain2, stack, 1.0, conn, NULL); Print_Neurocomp_Conn(conn); /* Int_Arraylist *path = Locseg_Chain_Path2(chain1, chain2, stack, 1.0); //Print_Int_Arraylist(path, "%d"); Pixel_Array *pa = Stack_Index_Sampling(stack, path->array, path->length); Print_Pixel_Array(pa); Pixel_Array_Export("../data/test.bn", pa); */ /* Image_Array ima; Translate_Stack(stack, COLOR, 1); ima.array = stack->array; int i; for (i = 0; i < path->length; i++) { ima.arrayc[path->array[i]][0] = 255; ima.arrayc[path->array[i]][1] = 0; ima.arrayc[path->array[i]][1] = 0; } Locseg_Chain_Label(chain1, stack, 1.0); //Locseg_Chain_Label(chain2, stack, 1.0); Write_Stack("../data/test.tif",stack); */ #endif #if 0 Stack *stack = Read_Stack("../data/mouse_single_org.tif"); Stack *mask = Read_Stack("../data/mouse_single_org/mask2.tif"); /* Stack *stack = Read_Stack("../data/rn003/cross_45_0.tif"); Stack *mask = Read_Stack("../data/rn003/cross_45_0/mask2.tif"); */ Stack_Seed_Workspace *ssw = New_Stack_Seed_Workspace(); Geo3d_Scalar_Field *seed = Stack_Seed(mask, ssw); Trace_Evaluate_Seed_Workspace *ws = New_Trace_Evaluate_Seed_Workspace(); Trace_Evaluate_Seed(seed, stack, 1.0, ws); Trace_Workspace *tw = New_Trace_Workspace(); Locseg_Chain_Default_Trace_Workspace(tw, stack); double sigma[3] = {1.0, 1.0, 0.5}; FMatrix *filter = Gaussian_3D_Filter_F(sigma, NULL); FMatrix *result = Filter_Stack_Fast_F(stack, filter, NULL, 0); Array_Link *a = FMatrix_To_Stack(result); tw->sup_stack = Get_Stack_At(a); int nchain1; Locseg_Chain **chain = Trace_Locseg_S(stack, 1.0, ws->locseg, ws->score, ws->nseed, tw, &nchain1); Stack_Binarize(tw->trace_mask); Stack *trace_mask = Translate_Stack(tw->trace_mask, GREY, 0); Stack_Or(trace_mask, ws->base_mask, trace_mask); Struct_Element *se = Make_Zline_Se(5); Stack *submask = Stack_Dilate(trace_mask, NULL, se); Stack_Bsub(mask, submask, mask); // Stack_Brighten_Bw(mask); Stack *mask2 = Stack_Remove_Small_Object(mask, NULL, 27, 26); /* Stack_Brighten_Bw(mask2); Write_Stack("../data/test.tif", mask2); return 1; */ Geo3d_Scalar_Field *seed2 = Stack_Seed(mask2, ssw); Trace_Evaluate_Seed(seed2, stack, 1.0, ws); tw->min_chain_length = NEUROSEG_DEFAULT_H * 1.5; int nchain2; Locseg_Chain **chain2 = Trace_Locseg_S(stack, 1.0, ws->locseg, ws->score, ws->nseed, tw, &nchain2); Print_Geo3d_Scalar_Field(seed2); Write_Stack("../data/test.tif", tw->canvas); Kill_FMatrix(result); int nchain = nchain1 + nchain2; Locseg_Chain **allchain = (Locseg_Chain**) Guarded_Malloc(sizeof(Locseg_Chain*) * nchain, "main"); memcpy(allchain, chain, sizeof(Locseg_Chain*) * nchain1); memcpy(allchain + nchain1, chain2, sizeof(Locseg_Chain*) * nchain2); # if 1 /* Array to store corrected chains */ Neuron_Component *chain_array = Make_Neuron_Component_Array(nchain); int chain_number = 0; int i; /* build chain map */ for (i = 0; i < nchain; i++) { if (allchain[i] != NULL) { if (Locseg_Chain_Geolen(allchain[i]) >= tw->min_chain_length) { Set_Neuron_Component(chain_array + chain_number, NEUROCOMP_TYPE_LOCSEG_CHAIN, allchain[i]); chain_number++; } } } Neuron_Structure *ns = Locseg_Chain_Comp_Neurostruct(chain_array, chain_number, stack, 1.0, NULL); Process_Neuron_Structure(ns); Neuron_Structure* ns2= Neuron_Structure_Locseg_Chain_To_Circle(ns); Neuron_Structure_Main_Graph(ns2); Neuron_Structure_To_Tree(ns2); Neuron_Structure_To_Swc_File_Circle(ns2, fullpath("../data", "test.swc", NULL)); # endif #endif #if 0 Stack *signal = Read_Stack("../data/diadem_e1.tif"); Locseg_Chain *chain1 = Read_Locseg_Chain("../data/diadem_e1/chain0.tb"); Local_Neuroseg locseg[2]; Local_Neuroseg_Copy(locseg, Locseg_Chain_Head_Seg(chain1)); Local_Neuroseg_Copy(locseg + 1, Locseg_Chain_Tail_Seg(chain1)); while (1) { Trace_Workspace *tw = New_Trace_Workspace(); Locseg_Chain_Default_Trace_Workspace(tw, signal); tw->break_refit = TRUE; strcpy(tw->save_path, "../data/test/chain"); int nchain; Locseg_Chain **chain = Trace_Locseg_S(signal, 1.0, locseg, NULL, 2, tw, &nchain); printf("%d\n", nchain); Kill_Trace_Workspace(tw); int i; for (i = 0; i < nchain; i++) { Kill_Locseg_Chain(chain[i]); } free(chain); } #endif #if 0 Stack *signal = Read_Stack("../data/fly_neuron_n1.tif"); Stack *mask = Read_Stack("../data/fly_neuron_n1/trace_mask.tif"); Locseg_Chain *chain = Read_Locseg_Chain("../data/fly_neuron_n1/chain0.tb"); Local_Neuroseg *locseg = Locseg_Chain_Head_Seg(chain); Local_Neuroseg_Push(locseg, signal, 1.0, mask, STACK_FIT_VALID_SIGNAL_RATIO, NULL, NULL); #endif #if 0 Trace_Workspace *tw = New_Trace_Workspace(); Locseg_Chain_Default_Trace_Workspace(tw, NULL); Print_Trace_Workspace(tw); Print_Locseg_Fit_Workspace((Locseg_Fit_Workspace*) tw->fit_workspace); #endif #if 0 Trace_Record *tr = New_Trace_Record(); tr->mask = ALL_ON_BIT_MASK; tr->fs.n = 1; tr->fs.options[0] = 1; tr->fs.scores[0] = 0.3; tr->hit_region = 1; tr->index = 2; tr->refit = 1; Print_Trace_Record(tr); /* FILE *fp = fopen("../data/test.bn", "w"); Trace_Record_Fwrite(tr, fp); fclose(fp); */ Trace_Record *tr2 = New_Trace_Record(); FILE *fp2 = fopen("../data/test.bn", "r"); Trace_Record_Fread(tr2, fp2); fclose(fp2); Print_Trace_Record(tr2); char *ct1 = (char*) tr; char *ct2 = (char*) tr2; int i; for (i = 0; i < sizeof(Trace_Record); i++) { if (ct1[i] != ct2[i]) { printf("Possible bug.\n"); break; } } #endif #if 0 Trace_Record *tr = New_Trace_Record(); tr->mask = ALL_ON_BIT_MASK; tr->fs.n = 1; tr->fs.options[0] = 1; tr->fs.scores[0] = 0.3; tr->hit_region = 1; tr->index = 2; tr->refit = 1; Local_Neuroseg *locseg = Local_Neuroseg_Import_Xml("../data/locseg.xml", NULL); Locseg_Node *node = Make_Locseg_Node(locseg, tr); Print_Locseg_Node(node); FILE *fp = fopen("../data/test.bn", "w"); Locseg_Node_Fwrite(node, fp); fclose(fp); Locseg_Node *node2 = New_Locseg_Node(); FILE *fp2 = fopen("../data/test.bn", "r"); Locseg_Node_Fread(node2, fp2); fclose(fp2); Print_Locseg_Node(node2); #endif #if 0 /* Test what's going on during end tuning */ Locseg_Chain *chain = Read_Locseg_Chain("../data/diadem_e3/chain7.tb"); Stack *signal = Read_Stack("../data/diadem_e3.tif"); double z_scale = 1.0; Trace_Workspace *tw = New_Trace_Workspace(); Locseg_Chain_Default_Trace_Workspace(tw, signal); tw->refit = FALSE; tw->tune_end = TRUE; tw->fit_workspace = New_Locseg_Fit_Workspace(); tw->trace_step = 0.1; //fw->sws->field_func = Neurofield_S1; Locseg_Label_Workspace *ws = New_Locseg_Label_Workspace(); ws->signal = signal; ws->sratio = 1.0; ws->sdiff = 0.0; ws->option = 6; //ws->flag = 0; tw->trace_mask = Make_Stack(GREY, signal->width, signal->height, signal->depth); Zero_Stack(tw->trace_mask); tw->chain_id = 28; int i; char file_path[100]; for (i = 0; i < tw->chain_id; i++) { sprintf(file_path, "../data/diadem_e3/chain%d.tb", i); if (fexist(file_path)) { printf("id: %d\n", i); Locseg_Chain *chain = Read_Locseg_Chain(file_path); //ws->value = i + 1; Locseg_Chain_Label_W(chain, tw->trace_mask, 1.0, 0, Locseg_Chain_Length(chain) - 1, ws); } } ws->option = 7; Locseg_Chain_Label_W(chain, tw->trace_mask, 1.0, 0, Locseg_Chain_Length(chain) - 1, ws); # if 1 tw->trace_status[0] = TRACE_NORMAL; tw->trace_status[1] = TRACE_NORMAL; Trace_Locseg(signal, 1.0, chain, tw); # endif Locseg_Chain_Down_Sample(chain); Locseg_Chain_Tune_End(chain, signal, z_scale, tw->trace_mask, DL_HEAD); Locseg_Chain_Tune_End(chain, signal, z_scale, tw->trace_mask, DL_TAIL); if (Locseg_Chain_Length(chain) > 0) { Write_Locseg_Chain("../data/test.tb", chain); } #endif #if 0 Stack *stack = Read_Stack("../data/benchmark/stack_graph/neuroseg/cross_60_8.tif"); Locseg_Chain *chain = Read_Locseg_Chain("../data/benchmark/stack_graph/neuroseg/seg0.tb"); Print_Locseg_Chain(chain); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_R; sgw->group_mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(sgw->group_mask); Locseg_Chain_Label_G(chain, sgw->group_mask, 1.0, 0, -1, 1.0, 0.0, 0, 1); //sgw->group_mask = NULL; int start[3] = {66, 21, 58}; int end[3] = {49, 48, 49}; //int end[3] = {13, 49, 50}; //int start[3] = {66, 21, 58}; //int end[3] = {63, 26, 58}; Stack_Graph_Workspace_Set_Range(sgw, start[0], end[0], start[1], end[1], start[2], end[2]); sgw->sp_option = 1; Int_Arraylist *offset_path = Stack_Route(stack, start, end, sgw); Stack *canvas = Translate_Stack(stack, COLOR, 0); if (sgw->group_mask != NULL) { Stack_Blend_Mc(canvas, sgw->group_mask, 4.0); } Image_Array ima; ima.array = canvas->array; int i; int nvoxel = Stack_Voxel_Number(stack); for (i = 0; i < offset_path->length; i++) { int index = offset_path->array[i]; if ((index < nvoxel) && (index >= 0)) { ima.arrayc[index][0] = 255; ima.arrayc[index][1] = 0; ima.arrayc[index][2] = 0; } } Kill_Stack_Graph_Workspace(sgw); Kill_Int_Arraylist(offset_path); //Write_Stack("../data/presentation9/cross_path.tif", canvas); Write_Stack("../data/test.tif", canvas); #endif #if 1 Locseg_Chain *source = Read_Locseg_Chain("../data/benchmark/stack_graph/fork/chain1.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/benchmark/stack_graph/fork/chain0.tb"); double pos[3]; Locseg_Chain_End_Pos(source, DL_TAIL, pos); int seg_index; double dist = Locseg_Chain_Point_Dist(target, pos, &seg_index, NULL); printf("dist: %g\n", dist); Locseg_Label_Workspace *ws = New_Locseg_Label_Workspace(); Stack *stack = Read_Stack("../data/benchmark/stack_graph/fork/fork.tif"); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_R; sgw->group_mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(sgw->group_mask); int start, end; start = seg_index - 1; end = seg_index + 2; if (start < 0) { start = 0; } int length = Locseg_Chain_Length(target); if (end >= length) { end = length - 1; } printf("seg index: %d--%d\n", start, end); ws->flag = 0; ws->value = 1; Locseg_Chain_Label_W(target, sgw->group_mask, 1.0, start, end, ws); Stack_Graph_Workspace_Set_Range(sgw, (int) pos[0], ws->range[0], (int) pos[1], ws->range[1], (int) pos[2], ws->range[2]); Stack_Graph_Workspace_Update_Range(sgw, ws->range[3], ws->range[4], ws->range[5]); int start_pos[3]; int end_pos[3]; start_pos[0] = (int) pos[0]; start_pos[1] = (int) pos[1]; start_pos[2] = (int) pos[2]; Local_Neuroseg *locseg = Locseg_Chain_Peek_Seg_At(target, seg_index); Print_Local_Neuroseg(locseg); Local_Neuroseg_Center(locseg, pos); end_pos[0] = iround(pos[0]); end_pos[1] = iround(pos[1]); end_pos[2] = iround(pos[2]); sgw->sp_option = 1; Int_Arraylist *offset_path = Stack_Route(stack, start_pos, end_pos, sgw); Stack *canvas = Translate_Stack(stack, COLOR, 0); if (sgw->group_mask != NULL) { Stack_Blend_Mc(canvas, sgw->group_mask, 4.0); } Image_Array ima; ima.array = canvas->array; int i; int nvoxel = Stack_Voxel_Number(stack); for (i = 0; i < offset_path->length; i++) { int index = offset_path->array[i]; if ((index < nvoxel) && (index >= 0)) { ima.arrayc[index][0] = 255; ima.arrayc[index][1] = 0; ima.arrayc[index][2] = 0; } } Kill_Stack_Graph_Workspace(sgw); Kill_Int_Arraylist(offset_path); //Write_Stack("../data/presentation9/fork_path.tif", canvas); Write_Stack("../data/test.tif", canvas); #endif #if 0 Locseg_Chain *source = Read_Locseg_Chain("../data/diadem_e1/chain7.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/diadem_e1/chain0.tb"); double pos[3]; Locseg_Chain_End_Pos(source, DL_TAIL, pos); int seg_index; double dist = Locseg_Chain_Point_Dist(target, pos, &seg_index); printf("dist: %g\n", dist); Locseg_Label_Workspace *ws = New_Locseg_Label_Workspace(); Stack *stack = Read_Stack("../data/diadem_e1.tif"); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_S; sgw->group_mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(sgw->group_mask); int start, end; start = seg_index - 2; end = seg_index + 2; if (start < 0) { start = 0; } int length = Locseg_Chain_Length(target); if (end >= length) { end = length - 1; } printf("seg index: %d--%d\n", start, end); ws->flag = 0; ws->value = 1; Locseg_Chain_Label_W(target, sgw->group_mask, 1.0, start, end, ws); Stack_Graph_Workspace_Set_Range(sgw, (int) pos[0], ws->range[0], (int) pos[1], ws->range[1], (int) pos[2], ws->range[2]); Stack_Graph_Workspace_Update_Range(sgw, ws->range[3], ws->range[4], ws->range[5]); int start_pos[3]; int end_pos[3]; start_pos[0] = (int) pos[0]; start_pos[1] = (int) pos[1]; start_pos[2] = (int) pos[2]; Local_Neuroseg *locseg = Locseg_Chain_Peek_Seg_At(target, seg_index); Print_Local_Neuroseg(locseg); Local_Neuroseg_Center(locseg, pos); end_pos[0] = iround(pos[0]); end_pos[1] = iround(pos[1]); end_pos[2] = iround(pos[2]); Int_Arraylist *offset_path = Stack_Route(stack, start_pos, end_pos, sgw); printf("dist: %g\n", sgw->value); Stack *canvas = Translate_Stack(stack, COLOR, 0); if (sgw->group_mask != NULL) { Stack_Blend_Mc(canvas, sgw->group_mask, 4.0); } Image_Array ima; ima.array = canvas->array; int i; int nvoxel = Stack_Voxel_Number(stack); Int_Arraylist *path_value = Make_Int_Arraylist(0, 1); for (i = 0; i < offset_path->length; i++) { int index = offset_path->array[i]; if ((index < nvoxel) && (index >= 0)) { printf("%d-(%d)->", index, stack->array[index]); Int_Arraylist_Add(path_value, stack->array[index]); ima.arrayc[index][0] = 255; ima.arrayc[index][1] = 0; ima.arrayc[index][2] = 0; } } printf("\n"); iarray_write("../data/presentation9/diadem_e1/path_value_ws.bn", path_value->array, path_value->length - 1); Kill_Stack_Graph_Workspace(sgw); Kill_Int_Arraylist(offset_path); Write_Stack("../data/presentation9/diadem_e1_path_ws.tif", canvas); #endif #if 0 Locseg_Chain *source = Read_Locseg_Chain("../data/diadem_e1/chain22.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/diadem_e1/chain0.tb"); //double pos[3] = {378, 183, 38}; //Locseg_Chain_End_Pos(source, DL_TAIL, pos); Stack *stack = Read_Stack("../data/diadem_e1.tif"); double pos[3]; Locseg_Chain_Bright_End(source, DL_HEAD, stack, 1.0, pos); int seg_index; double dist = Locseg_Chain_Point_Dist(target, pos, &seg_index); printf("dist: %g\n", dist); Locseg_Label_Workspace *ws = New_Locseg_Label_Workspace(); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_S; sgw->group_mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(sgw->group_mask); int start, end; start = seg_index - 1; end = seg_index + 2; if (start < 0) { start = 0; } int length = Locseg_Chain_Length(target); if (end >= length) { end = length - 1; } printf("seg index: %d--%d\n", start, end); ws->flag = 0; ws->value = 1; Locseg_Chain_Label_W(target, sgw->group_mask, 1.0, start, end, ws); Stack_Graph_Workspace_Set_Range(sgw, (int) pos[0], ws->range[0], (int) pos[1], ws->range[1], (int) pos[2], ws->range[2]); Stack_Graph_Workspace_Update_Range(sgw, ws->range[3], ws->range[4], ws->range[5]); int start_pos[3]; int end_pos[3]; start_pos[0] = (int) pos[0]; start_pos[1] = (int) pos[1]; start_pos[2] = (int) pos[2]; Local_Neuroseg *locseg = Locseg_Chain_Peek_Seg_At(target, seg_index); Print_Local_Neuroseg(locseg); Local_Neuroseg_Center(locseg, pos); end_pos[0] = iround(pos[0]); end_pos[1] = iround(pos[1]); end_pos[2] = iround(pos[2]); Int_Arraylist *offset_path = Stack_Route(stack, start_pos, end_pos, sgw); printf("dist: %g\n", sgw->value); Stack *canvas = Translate_Stack(stack, COLOR, 0); if (sgw->group_mask != NULL) { Stack_Blend_Mc(canvas, sgw->group_mask, 4.0); } Image_Array ima; ima.array = canvas->array; int i; int nvoxel = Stack_Voxel_Number(stack); Int_Arraylist *path_value = Make_Int_Arraylist(0, 1); for (i = 0; i < offset_path->length; i++) { int index = offset_path->array[i]; if ((index < nvoxel) && (index >= 0)) { printf("%d-(%d)->", index, stack->array[index]); Int_Arraylist_Add(path_value, stack->array[index]); ima.arrayc[index][0] = 255; ima.arrayc[index][1] = 0; ima.arrayc[index][2] = 0; } } printf("\n"); iarray_write("../data/presentation9/diadem_e1/path_value_gap_ws.bn", path_value->array, path_value->length - 1); Kill_Stack_Graph_Workspace(sgw); Kill_Int_Arraylist(offset_path); Write_Stack("../data/presentation9/diadem_e1_path_gap_ws.tif", canvas); #endif #if 0 Locseg_Chain *source = Read_Locseg_Chain("../data/diadem_e1/chain22.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/diadem_e1/chain0.tb"); Stack *stack = Read_Stack("../data/diadem_e1.tif"); double pos[3]; Locseg_Chain_Bright_End(source, DL_HEAD, stack, 1.0, pos); int seg_index; double dist = Locseg_Chain_Point_Dist(target, pos, &seg_index); printf("dist: %g\n", dist); Locseg_Label_Workspace *ws = New_Locseg_Label_Workspace(); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_S; sgw->group_mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); Zero_Stack(sgw->group_mask); int start, end; start = seg_index - 2; end = seg_index + 2; if (start < 0) { start = 0; } int length = Locseg_Chain_Length(target); if (end >= length) { end = length - 1; } printf("seg index: %d--%d\n", start, end); ws->flag = 0; ws->value = 1; Locseg_Chain_Label_W(target, sgw->group_mask, 1.0, start, end, ws); Stack_Graph_Workspace_Set_Range(sgw, (int) pos[0], ws->range[0], (int) pos[1], ws->range[1], (int) pos[2], ws->range[2]); Stack_Graph_Workspace_Update_Range(sgw, ws->range[3], ws->range[4], ws->range[5]); int start_pos[3]; int end_pos[3]; start_pos[0] = (int) pos[0]; start_pos[1] = (int) pos[1]; start_pos[2] = (int) pos[2]; Local_Neuroseg *locseg = Locseg_Chain_Peek_Seg_At(target, seg_index); Print_Local_Neuroseg(locseg); Local_Neuroseg_Center(locseg, pos); end_pos[0] = iround(pos[0]); end_pos[1] = iround(pos[1]); end_pos[2] = iround(pos[2]); Int_Arraylist *offset_path = Stack_Route(stack, start_pos, end_pos, sgw); printf("dist: %g\n", sgw->value); Stack *canvas = Translate_Stack(stack, COLOR, 0); if (sgw->group_mask != NULL) { Stack_Blend_Mc(canvas, sgw->group_mask, 4.0); } Image_Array ima; ima.array = canvas->array; int i; int nvoxel = Stack_Voxel_Number(stack); Int_Arraylist *path_value = Make_Int_Arraylist(0, 1); for (i = 0; i < offset_path->length; i++) { int index = offset_path->array[i]; if ((index < nvoxel) && (index >= 0)) { printf("%d-(%d)->", index, stack->array[index]); Int_Arraylist_Add(path_value, stack->array[index]); ima.arrayc[index][0] = 255; ima.arrayc[index][1] = 0; ima.arrayc[index][2] = 0; } } printf("\n"); /* iarray_write("../data/presentation9/diadem_e1/path_value_ws.bn", path_value->array, path_value->length - 1); */ Kill_Stack_Graph_Workspace(sgw); Kill_Int_Arraylist(offset_path); Write_Stack("../data/test.tif", canvas); #endif #if 0 Locseg_Chain *source = Read_Locseg_Chain("../data/diadem_e3/chain14.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/diadem_e3/chain0.tb"); Stack *stack = Read_Stack("../data/diadem_e3.tif"); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_S; sgw->resolution[2] = 3.03; sgw->signal_mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); One_Stack(sgw->signal_mask); Locseg_Chain_Erase(source, sgw->signal_mask, 1.0); Locseg_Chain_Erase(target, sgw->signal_mask, 1.0); Local_Neuroseg *source_seg = Locseg_Chain_Tail_Seg(source); Locseg_Chain_Update_Stack_Graph_Workspace(source_seg, target, stack, 1.0, sgw); /* Stack *substack = Crop_Stack(new_stack, sgw->range[0], sgw->range[2], sgw->range[4], sgw->range[1] - sgw->range[0] + 1, sgw->range[3] - sgw->range[2] + 1, sgw->range[5] - sgw->range[4] + 1, NULL); Kill_Stack(new_stack); double c1, c2; int thre = Stack_Threshold_RC_R(substack, 0, 255, &c1, &c2); sgw->argv[3] = thre; sgw->argv[4] = c2 - c1; if (sgw->argv[4] < 1.0) { sgw->argv[4] = 1.0; } sgw->argv[4] /= 9.2; */ Int_Arraylist *path = Locseg_Chain_Shortest_Path(source, target, stack, 1.0, sgw); Stack *canvas = Translate_Stack(stack, COLOR, 0); if (sgw->group_mask != NULL) { Stack_Blend_Mc(canvas, sgw->group_mask, 4.0); } Kill_Stack_Graph_Workspace(sgw); Image_Array ima; ima.array = canvas->array; int i; for (i = 0; i < path->length; i++) { int index = path->array[i]; ima.arrayc[index][0] = stack->array[i]; ima.arrayc[index][1] = 128; ima.arrayc[index][2] = 128; } Write_Stack("../data/test.tif", canvas); #endif #if 0 Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); Kill_Stack_Graph_Workspace(sgw); #endif #if 0 Locseg_Chain *source = Read_Locseg_Chain("../data/diadem_e3/chain13.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/diadem_e3/chain8.tb"); Stack *stack = Read_Stack("../data/diadem_e3.tif"); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_S; sgw->resolution[0] = 0.33; sgw->resolution[1] = 0.33; sgw->resolution[2] = 1.00; /* Int_Arraylist *path = Locseg_Chain_Shortest_Path(source, target, stack, 1.0, sgw); */ Connection_Test_Workspace *ctw = New_Connection_Test_Workspace(); ctw->dist_thre = NEUROSEG_DEFAULT_H * 1.5; ctw->mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); One_Stack(ctw->mask); Locseg_Chain_Erase(source, ctw->mask, 1.0); Locseg_Chain_Erase(target, ctw->mask, 1.0); Neurocomp_Conn conn; conn.mode = NEUROCOMP_CONN_HL; Locseg_Chain_Connection_Test(source, target, stack, 1.0, &conn, ctw); Print_Neurocomp_Conn(&conn); Kill_Locseg_Chain(source); Kill_Locseg_Chain(target); Kill_Stack(stack); Kill_Connection_Test_Workspace(ctw); Kill_Stack_Graph_Workspace(sgw); #endif #if 0 Locseg_Chain *source = Read_Locseg_Chain("../data/diadem_e1/chain7.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/diadem_e1/chain0.tb"); Stack *stack = Read_Stack("../data/diadem_e1.tif"); Local_Neuroseg *source_seg = Locseg_Chain_Tail_Seg(source); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); Locseg_Chain_Update_Stack_Graph_Workspace(source_seg, target, stack, 1.0, sgw); Int_Arraylist *path = Locseg_Chain_Shortest_Path(source, target, stack, 1.0, sgw); Locseg_Chain *chain2 = Locseg_Chain_Bridge_Sp(source_seg, target, stack, 1.0, sgw, NULL); Print_Locseg_Chain(chain2); #endif #if 0 Locseg_Chain *source = Read_Locseg_Chain("../data/diadem_e3/chain1.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/diadem_e3/chain0.tb"); Stack *stack = Read_Stack("../data/diadem_e3.tif"); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_S; sgw->resolution[2] = 3.03; sgw->signal_mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); One_Stack(sgw->signal_mask); Locseg_Chain_Erase(source, sgw->signal_mask, 1.0); Locseg_Chain_Erase(target, sgw->signal_mask, 1.0); Local_Neuroseg *source_seg = Locseg_Chain_Tail_Seg(source); Locseg_Chain_Update_Stack_Graph_Workspace(source_seg, target, stack, 1.0, sgw); printf("%g, %g\n", sgw->argv[3], sgw->argv[4]); Int_Arraylist *path = Locseg_Chain_Shortest_Path(source, target, stack, 1.0, sgw); Stack *canvas = Translate_Stack(stack, COLOR, 0); if (sgw->group_mask != NULL) { Stack_Blend_Mc(canvas, sgw->group_mask, 4.0); } Kill_Stack_Graph_Workspace(sgw); Image_Array ima; ima.array = canvas->array; int i; for (i = 0; i < path->length; i++) { int index = path->array[i]; ima.arrayc[index][0] = stack->array[index]; ima.arrayc[index][1] = 128; ima.arrayc[index][2] = 128; } Write_Stack("../data/test.tif", canvas); #endif #if 0 Locseg_Chain *source = Read_Locseg_Chain("../data/diadem_e3/chain3.tb"); Locseg_Chain *target = Read_Locseg_Chain("../data/diadem_e3/chain1.tb"); Stack *stack = Read_Stack("../data/diadem_e3.tif"); Stack_Graph_Workspace *sgw = New_Stack_Graph_Workspace(); sgw->conn = 26; sgw->wf = Stack_Voxel_Weight_S; sgw->resolution[2] = 3.03; sgw->signal_mask = Make_Stack(GREY, stack->width, stack->height, stack->depth); One_Stack(sgw->signal_mask); Locseg_Chain_Erase(source, sgw->signal_mask, 1.0); Locseg_Chain_Erase(target, sgw->signal_mask, 1.0); Local_Neuroseg *source_seg = Locseg_Chain_Tail_Seg(source); Locseg_Chain_Update_Stack_Graph_Workspace(source_seg, target, stack, 1.0, sgw); printf("%g, %g\n", sgw->argv[3], sgw->argv[4]); Int_Arraylist *path = Locseg_Chain_Shortest_Path(source, target, stack, 1.0, sgw); Stack *canvas = Translate_Stack(stack, COLOR, 0); if (sgw->group_mask != NULL) { Stack_Blend_Mc(canvas, sgw->group_mask, 3.0); } Kill_Stack_Graph_Workspace(sgw); Image_Array ima; ima.array = canvas->array; int i; for (i = 0; i < path->length; i++) { int index = path->array[i]; ima.arrayc[index][0] = stack->array[index]; ima.arrayc[index][1] = 255; ima.arrayc[index][2] = 128; } Write_Stack("../data/test.tif", canvas); #endif #if 0 Stack *stack = Read_Stack("../data/benchmark/fork2/fork2.tif"); int z = 34; stack_adjust_zpos(stack, 50, 44, &z); printf("%d\n", z); #endif return 0; }
import new.unordered.d import algebra.homology.homological_complex import algebra.category.Group.abelian import algebra.homology.homology import new.unordered.refinement noncomputable theory section open topological_space Top Top.sheaf open category_theory open opposite open nat open_locale big_operators universe u variables {X : Top.{u}} (𝓕 : sheaf Ab X) (U V : X.oc) def d_from_to (i j : ℕ) : C 𝓕 U i ⟶ C 𝓕 U j := dite (j = i + 1) (λ h, d 𝓕 U i ≫ eq_to_hom (by rw h)) (λ h, 0) lemma d_to_succ {i : ℕ} (f α) : d_from_to 𝓕 U i (i + 1) f α = d 𝓕 U i f α := begin rw [d_from_to], rw dif_pos rfl, rw comp_apply, refl, end lemma d_to_succ' (i : ℕ) : d_from_to 𝓕 U i (i + 1) = d 𝓕 U i := begin ext f α, rw d_to_succ, end lemma d_not_to_succ {i j : ℕ} (h : j ≠ i + 1) (f α) : d_from_to 𝓕 U i j f α = 0 := begin rw [d_from_to, dif_neg h], refl, end def Cech_complex_wrt_cover_unordered : cochain_complex Ab.{u} ℕ := { X := λ n, C 𝓕 U (n + 1), d := λ i j, d_from_to 𝓕 U (i + 1) (j + 1), shape' := λ i j h, begin ext f α, rw d_not_to_succ, rw [add_monoid_hom.zero_apply, pi.zero_apply], simp only [complex_shape.up_rel] at h, contrapose! h, simp only [add_left_inj] at h, exact h.symm, end, d_comp_d' := λ i j k h1 h2, begin simp only [complex_shape.up_rel] at h1 h2, subst' h2, subst' h1, ext f α, rw comp_apply, rw d_to_succ, rw d_to_succ', simp only [AddCommGroup.zero_apply, C_pre.zero_apply], rw dd_eq_zero, end } lemma Cech_complex_wrt_cover_unordered.d_to_rel (n : ℕ) (m) (h : (complex_shape.up ℕ).prev n = some m) : (Cech_complex_wrt_cover_unordered 𝓕 U).d m.1 n = d 𝓕 U (m.1 + 1) ≫ eq_to_hom begin have := m.2, simp only [complex_shape.up_rel] at this, rw this, refl, end := begin change d_from_to 𝓕 U _ _ = _, rw [d_from_to, dif_pos], refl, have h2 := m.2.symm, rw ← h2, end def Cech_Cohomology_Group_wrt_cover_unordered_nth (n : ℕ) : Ab.{u} := @homological_complex.homology ℕ Ab _ _ (complex_shape.up ℕ) (abelian.has_zero_object) _ _ _ (Cech_complex_wrt_cover_unordered 𝓕 U) n section variables {U V} (r : U ⟶ V) include r def Cech_complex_wrt_cover_unordered.prev (n : ℕ) : @homological_complex.X_prev _ _ _ _ (complex_shape.up ℕ) (Cech_complex_wrt_cover_unordered 𝓕 V) (abelian.has_zero_object) n ⟶ @homological_complex.X_prev _ _ _ _ (complex_shape.up ℕ) (Cech_complex_wrt_cover_unordered 𝓕 U) (abelian.has_zero_object) n := match (complex_shape.up ℕ).prev n with | none := 0 | some m := begin refine _ ≫ @C.refine X 𝓕 _ _ (m.1 + 1) r ≫ _, refine (@@homological_complex.X_prev_iso _ _ _ (abelian.has_zero_object) m.2).hom, exact (@@homological_complex.X_prev_iso _ _ (Cech_complex_wrt_cover_unordered 𝓕 U) (abelian.has_zero_object) m.2).inv, end end lemma Cech_complex_wrt_cover_unordered.prev_none (n : ℕ) (h : (complex_shape.up ℕ).prev n = none) : Cech_complex_wrt_cover_unordered.prev 𝓕 r n = 0 := begin rw Cech_complex_wrt_cover_unordered.prev, rw h, refl, end lemma Cech_Group_wrt_cover_unordered_nth.prev_some (n : ℕ) (m) (h : (complex_shape.up ℕ).prev n = some m) : Cech_complex_wrt_cover_unordered.prev 𝓕 r n = (@@homological_complex.X_prev_iso _ _ _ (abelian.has_zero_object) m.2).hom ≫ @C.refine X 𝓕 _ _ (m.1 + 1) r ≫ (@@homological_complex.X_prev_iso _ _ (Cech_complex_wrt_cover_unordered 𝓕 U) (abelian.has_zero_object) m.2).inv := begin rw Cech_complex_wrt_cover_unordered.prev, rw h, refl, end example (n : ℕ) : (complex_shape.up ℕ).next n = some ⟨n+1, rfl⟩ := begin rw [complex_shape.next_eq_some], end def Cech_Cohomology_Group_wrt_cover_unordered_nth.refinement (n : ℕ) : Cech_Cohomology_Group_wrt_cover_unordered_nth 𝓕 V n ⟶ Cech_Cohomology_Group_wrt_cover_unordered_nth 𝓕 U n := homology.map _ _ { left := Cech_complex_wrt_cover_unordered.prev 𝓕 r n, right := C.refine r, w' := begin simp only [category_theory.functor.id_map, arrow.mk_hom], ext f α, rw [comp_apply, comp_apply], by_cases h : (complex_shape.up ℕ).prev n = none, { rw Cech_complex_wrt_cover_unordered.prev_none, rw homological_complex.d_to_eq_zero, rw homological_complex.d_to_eq_zero, swap, exact h, swap, exact h, swap, exact h, simp only [AddCommGroup.zero_apply, C_pre.zero_apply, map_zero], }, { change _ ≠ _ at h, rw option.ne_none_iff_exists at h, rcases h with ⟨m, hm⟩, rw Cech_Group_wrt_cover_unordered_nth.prev_some, swap, exact hm.symm, rw homological_complex.d_to_eq, swap, exact m.2, rw homological_complex.d_to_eq, swap, exact m.2, simp only [comp_apply, coe_inv_hom_id], rw Cech_complex_wrt_cover_unordered.d_to_rel, swap, exact hm.symm, rw Cech_complex_wrt_cover_unordered.d_to_rel, swap, exact hm.symm, rw comp_apply, rw comp_apply, rw ← C.refine_d_eq_d_refine', simp only [← comp_apply], congr' 1, simp only [category.assoc], apply whisker_eq, apply whisker_eq, rw C.refine_eq_to_hom, have : _ + 1 = _ := m.2, rw this, }, end } { left := C.refine r, right := (@@homological_complex.X_next_iso _ _ (Cech_complex_wrt_cover_unordered 𝓕 V) (abelian.has_zero_object) (rfl : n + 1 = n + 1)).hom ≫ C.refine r ≫ (@@homological_complex.X_next_iso _ _ (Cech_complex_wrt_cover_unordered 𝓕 U) (abelian.has_zero_object) (rfl : n + 1 = n + 1)).inv, w' := begin simp only [category_theory.functor.id_map, arrow.mk_hom], ext f α, simp only [comp_apply, homological_complex.d_from_comp_X_next_iso_assoc], rw homological_complex.d_from_eq, swap 2, exact (rfl : n + 1 = n + 1), simp only [← comp_apply], congr' 1, simp only [← category.assoc], apply eq_whisker, change C.refine r ≫ d_from_to 𝓕 U _ _ = _, rw d_to_succ', change _ = d_from_to _ _ _ _ ≫ C.refine r, rw d_to_succ', rw C.refine_d_eq_d_refine, end } rfl def Cech_Cohomology_Group_wrt_cover_unordered_nth.refinement_functor (n : ℕ) : X.ocᵒᵖ ⥤ Ab.{u} := { obj := λ U, Cech_Cohomology_Group_wrt_cover_unordered_nth 𝓕 U.unop n, map := λ U V r, Cech_Cohomology_Group_wrt_cover_unordered_nth.refinement 𝓕 r.unop n, map_id' := λ U, begin rw [Cech_Cohomology_Group_wrt_cover_unordered_nth.refinement], ext f, simp only [unop_id, homology.π_map, comp_apply, id_apply], congr', sorry end, map_comp' := sorry } include 𝓕 def Cech_Cohomology_Group_nth (n : ℕ) : Ab := limits.colim.obj $ (Cech_Cohomology_Group_wrt_cover_unordered_nth.refinement_functor 𝓕 r n) ⋙ AddCommGroup.ulift_functor.{u u+1} end end
Welcome to Coq 8.4pl6 (January 2017) Coq < Inductive boollist : Type := | bool_nil : boollist | bool_cons : bool -> boollist -> boollist. boollist is defined boollist_rect is defined boollist_ind is defined boollist_rec is defined Coq < Inductive list (X:Type) : Type := | nil : list X | cons : X -> list X -> list X. list is defined list_rect is defined list_ind is defined list_rec is defined Coq < Check nil. nil : forall X : Type, list X Coq < Check cons. cons : forall X : Type, X -> list X -> list X Coq < Check (cons nat 2 (cons nat 1 (nil nat))). cons nat 2 (cons nat 1 (nil nat)) : list nat Coq < Fixpoint repeat (X : Type) (x : X) (count : nat) : list X := match count with | O => nil X | S count' => cons X x (repeat X x count') end. repeat is recursively defined (decreasing on 3rd argument) Coq < Example test_repeat1 : repeat nat 4 2 = cons nat 4 (cons nat 4 (nil nat)). 1 subgoal ============================ repeat nat 4 2 = cons nat 4 (cons nat 4 (nil nat)) test_repeat1 < Proof. 1 subgoal ============================ repeat nat 4 2 = cons nat 4 (cons nat 4 (nil nat)) test_repeat1 < info_auto. (* info auto : *) apply @eq_refl. No more subgoals. test_repeat1 < Qed. info_auto. test_repeat1 is defined Coq < Example test_repeat2 : repeat bool false 1 = cons bool false (nil bool). 1 subgoal ============================ repeat bool false 1 = cons bool false (nil bool) test_repeat2 < Proof. 1 subgoal ============================ repeat bool false 1 = cons bool false (nil bool) test_repeat2 < info_auto. (* info auto : *) apply @eq_refl. No more subgoals. test_repeat2 < Qed. info_auto. test_repeat2 is defined
import tactic init.meta.interactive_base open tactic interactive interactive.types #check tactic.induction #check interactive.induction #check mk_const #check ``(1) #check intro #check exact #check applyc #check prod.fst #check first #check focus #check try meta def tactic.my_tac (e : expr) : tactic unit := do cases ← induction e, focus (list.map (λx, try $ applyc (prod.fst x)) cases) meta def my_tac (q : parse texpr) : tactic unit := i_to_expr ``(%%q) >>= tactic.my_tac inductive test | a : test | b : test example : ∀ t : test, ∃ x, x = t := begin intro t, have h := true.intro, -- my_tac h, admit end
State Before: α : Type u β : Type v γ : Type w inst✝² : TopologicalSpace α inst✝¹ : LinearOrder α inst✝ : OrderTopology α a u' : α s : Set α hu' : a < u' ⊢ List.get? [s ∈ 𝓝[Ici a] a, s ∈ 𝓝[Icc a u'] a, s ∈ 𝓝[Ico a u'] a, ∃ u, u ∈ Ioc a u' ∧ Ico a u ⊆ s, ∃ u, u ∈ Ioi a ∧ Ico a u ⊆ s] 0 = some (s ∈ 𝓝[Ici a] a) State After: no goals Tactic: norm_num State Before: α : Type u β : Type v γ : Type w inst✝² : TopologicalSpace α inst✝¹ : LinearOrder α inst✝ : OrderTopology α a u' : α s : Set α hu' : a < u' ⊢ List.get? [s ∈ 𝓝[Ici a] a, s ∈ 𝓝[Icc a u'] a, s ∈ 𝓝[Ico a u'] a, ∃ u, u ∈ Ioc a u' ∧ Ico a u ⊆ s, ∃ u, u ∈ Ioi a ∧ Ico a u ⊆ s] 4 = some (∃ u, u ∈ Ioi a ∧ Ico a u ⊆ s) State After: no goals Tactic: norm_num
theory prop_70 imports Main "$HIPSTER_HOME/IsaHipster" begin datatype Nat = Z | S "Nat" fun le :: "Nat => Nat => bool" where "le (Z) y = True" | "le (S z) (Z) = False" | "le (S z) (S x2) = le z x2" (*hipster le *) theorem x0 : "(le m n) ==> (le m (S n))" by (tactic \<open>Subgoal.FOCUS_PARAMS (K (Tactic_Data.hard_tac @{context})) @{context} 1\<close>) end
lemma closed_Nats [simp]: "closed (\<nat> :: 'a :: real_normed_algebra_1 set)"
variable {p q r s: Prop} #check And p q #check Or (And p q) r #check p → r theorem t1' : p → q → p := fun hp : p => fun hq : q => show p from hp #print t1' theorem t1 (p q : Prop)(hp: p) (hq : q) : p := hp axiom hp : p axiom unsound : False -- Everything follows from false (principle of explosion) theorem ex : 1 = 0 := False.elim unsound #check t1 p q #check t1 (r → p) (p → q) variable (h : r → s) #check t1 (r → s) (s → r) h theorem t2 (h₁ : q → r) (h₂ : p → q) : p → r := fun h₃ : p => show r from h₁ (h₂ h₃)
import Mathlib def sumTo (n: ℕ) := match n with | 0 => 0 | n + 1 => (n + 1) + sumTo n theorem sum_formula (n: ℕ) : 2 * sumTo n = n * (n + 1):= by -- 2 * sumTo n = n * (n + 1) induction n with | zero => -- 2 * sumTo Nat.zero = Nat.zero * (Nat.zero + 1) rfl | succ n ih => simp [sumTo] -- 2 * (n + 1 + sumTo n) = Nat.succ n * (Nat.succ n + 1) simp [left_distrib, ih] -- 2 * n + 2 + (n * n + n) = Nat.succ n * Nat.succ n + Nat.succ n linarith
Explaining Church teaching of this commandment , Kreeft cites Saint Thomas Aquinas , who wrote , " An evil desire can only be overcome by a stronger good desire . " The US Bishops suggest that this can be achieved through cultivation of goodwill , humility and gratitude for one 's own and others ' blessings , while trusting in God 's grace . Kreeft explains that Saint Paul the Apostle illustrated the concept in his letter to the Philippians when he listed his worldly credentials as a respected Jew and stated , " I count everything as loss because of the surpassing worth of knowing Christ Jesus my Lord . " As Jesus stated , " What shall it profit a man if he shall gain the whole world , and lose his own soul ? " Church teaching on the tenth commandment is directed toward this same attitude toward worldly goods , termed " poverty of spirit " .
------------------------------------------------------------------------------ -- Distributive laws on a binary operation: Task B ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module DistributiveLaws.TaskB.UnprovedATP where open import DistributiveLaws.Base ------------------------------------------------------------------------------ -- 2018-06-28: The ATPs could not prove the theorem (300 sec). postulate prop₂ : ∀ u x y z → (x · y · (z · u)) · ((x · y · (z · u)) · (x · z · (y · u))) ≡ x · z · (y · u) {-# ATP prove prop₂ #-}
# Create example data data = randn(100) # Draw a polar histogram with 19 bins polarhistogram(data, nbins = 19, fullcircle=true)
(* Title: Containers/Containers_Auxiliary.thy Author: Andreas Lochbihler, KIT *) theory Containers_Auxiliary imports "~~/src/HOL/Library/Monad_Syntax" begin chapter {* An executable linear order on sets *} text_raw {* \label{chapter:linear:order:set} *} section {* Auxiliary definitions *} lemma insert_bind_set: "insert a A \<guillemotright>= f = f a \<union> (A \<guillemotright>= f)" by(auto simp add: Set.bind_def) lemma set_bind_iff: "set (List.bind xs f) = Set.bind (set xs) (set \<circ> f)" by(induct xs)(simp_all add: insert_bind_set) lemma set_bind_conv_fold: "set xs \<guillemotright>= f = fold (op \<union> \<circ> f) xs {}" by(induct xs rule: rev_induct)(simp_all add: insert_bind_set) lemma card_gt_1D: assumes "card A > 1" shows "\<exists>x y. x \<in> A \<and> y \<in> A \<and> x \<noteq> y" proof(rule ccontr) from assms have "A \<noteq> {}" by auto then obtain x where "x \<in> A" by auto moreover assume "\<not> ?thesis" ultimately have "A = {x}" by auto with assms show False by simp qed lemma card_eq_1_iff: "card A = 1 \<longleftrightarrow> (\<exists>x. A = {x})" proof assume card: "card A = 1" hence [simp]: "finite A" using card_gt_0_iff[of A] by simp have "A = {THE x. x \<in> A}" proof(intro equalityI subsetI) fix x assume x: "x \<in> A" hence "(THE x. x \<in> A) = x" proof(rule the_equality) fix x' assume x': "x' \<in> A" show "x' = x" proof(rule ccontr) assume neq: "x' \<noteq> x" from x x' have eq: "A = insert x (insert x' (A - {x, x'}))" by auto have "card A = 2 + card (A - {x, x'})" using neq by(subst eq)(simp) with card show False by simp qed qed thus "x \<in> {THE x. x \<in> A}" by simp next fix x assume "x \<in> {THE x. x \<in> A}" hence x: "x = (THE x. x \<in> A)" by simp from card have "A \<noteq> {}" by auto then obtain x' where x': "x' \<in> A" by blast thus "x \<in> A" unfolding x proof(rule theI) fix x assume x: "x \<in> A" show "x = x'" proof(rule ccontr) assume neq: "x \<noteq> x'" from x x' have eq: "A = insert x (insert x' (A - {x, x'}))" by auto have "card A = 2 + card (A - {x, x'})" using neq by(subst eq)(simp) with card show False by simp qed qed qed thus "\<exists>x. A = {x}" .. qed auto lemma card_eq_Suc_0_ex1: "card A = Suc 0 \<longleftrightarrow> (\<exists>!x. x \<in> A)" by(auto simp only: One_nat_def[symmetric] card_eq_1_iff) context linorder begin lemma sorted_last: "\<lbrakk> sorted xs; x \<in> set xs \<rbrakk> \<Longrightarrow> x \<le> last xs" by(cases xs rule: rev_cases)(auto simp add: sorted_append) end lemma empty_filter_conv: "[] = filter P xs \<longleftrightarrow> (\<forall>x\<in>set xs. \<not> P x)" by(auto dest: sym simp add: filter_empty_conv) definition ID :: "'a \<Rightarrow> 'a" where "ID = id" lemma ID_code [code, code_unfold]: "ID = (\<lambda>x. x)" by(simp add: ID_def id_def) lemma ID_Some: "ID (Some x) = Some x" by(simp add: ID_def) lemma ID_None: "ID None = None" by(simp add: ID_def) text {* lexicographic order on pairs *} context fixes leq_a :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<sqsubseteq>\<^sub>a" 50) and less_a :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<sqsubset>\<^sub>a" 50) and leq_b :: "'b \<Rightarrow> 'b \<Rightarrow> bool" (infix "\<sqsubseteq>\<^sub>b" 50) and less_b :: "'b \<Rightarrow> 'b \<Rightarrow> bool" (infix "\<sqsubset>\<^sub>b" 50) begin definition less_eq_prod :: "('a \<times> 'b) \<Rightarrow> ('a \<times> 'b) \<Rightarrow> bool" (infix "\<sqsubseteq>" 50) where "less_eq_prod = (\<lambda>(x1, x2) (y1, y2). x1 \<sqsubset>\<^sub>a y1 \<or> x1 \<sqsubseteq>\<^sub>a y1 \<and> x2 \<sqsubseteq>\<^sub>b y2)" definition less_prod :: "('a \<times> 'b) \<Rightarrow> ('a \<times> 'b) \<Rightarrow> bool" (infix "\<sqsubset>" 50) where "less_prod = (\<lambda>(x1, x2) (y1, y2). x1 \<sqsubset>\<^sub>a y1 \<or> x1 \<sqsubseteq>\<^sub>a y1 \<and> x2 \<sqsubset>\<^sub>b y2)" lemma less_eq_prod_simps [simp]: "(x1, x2) \<sqsubseteq> (y1, y2) \<longleftrightarrow> x1 \<sqsubset>\<^sub>a y1 \<or> x1 \<sqsubseteq>\<^sub>a y1 \<and> x2 \<sqsubseteq>\<^sub>b y2" by(simp add: less_eq_prod_def) lemma less_prod_simps [simp]: "(x1, x2) \<sqsubset> (y1, y2) \<longleftrightarrow> x1 \<sqsubset>\<^sub>a y1 \<or> x1 \<sqsubseteq>\<^sub>a y1 \<and> x2 \<sqsubset>\<^sub>b y2" by(simp add: less_prod_def) end context fixes leq_a :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<sqsubseteq>\<^sub>a" 50) and less_a :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<sqsubset>\<^sub>a" 50) and leq_b :: "'b \<Rightarrow> 'b \<Rightarrow> bool" (infix "\<sqsubseteq>\<^sub>b" 50) and less_b :: "'b \<Rightarrow> 'b \<Rightarrow> bool" (infix "\<sqsubset>\<^sub>b" 50) assumes lin_a: "class.linorder leq_a less_a" and lin_b: "class.linorder leq_b less_b" begin abbreviation (input) less_eq_prod' :: "('a \<times> 'b) \<Rightarrow> ('a \<times> 'b) \<Rightarrow> bool" (infix "\<sqsubseteq>" 50) where "less_eq_prod' \<equiv> less_eq_prod leq_a less_a leq_b" abbreviation (input) less_prod' :: "('a \<times> 'b) \<Rightarrow> ('a \<times> 'b) \<Rightarrow> bool" (infix "\<sqsubset>" 50) where "less_prod' \<equiv> less_prod leq_a less_a less_b" lemma linorder_prod: "class.linorder op \<sqsubseteq> op \<sqsubset>" proof - interpret a!: linorder "op \<sqsubseteq>\<^sub>a" "op \<sqsubset>\<^sub>a" by(fact lin_a) interpret b!: linorder "op \<sqsubseteq>\<^sub>b" "op \<sqsubset>\<^sub>b" by(fact lin_b) show ?thesis by unfold_locales auto qed end hide_const less_eq_prod' less_prod' end
(* This Isabelle theory is produced using the TIP tool offered at the following website: https://github.com/tip-org/tools This file was originally provided as part of TIP benchmark at the following website: https://github.com/tip-org/benchmarks Yutaka Nagashima at CIIRC, CTU changed the TIP output theory file slightly to make it compatible with Isabelle2017. \:w Some proofs were added by Yutaka Nagashima.*) theory TIP_propositional_AndCommutative imports "../../Test_Base" begin datatype ('a, 'b) pair = pair2 "'a" "'b" datatype 'a list = nil2 | cons2 "'a" "'a list" datatype Form = x "Form" "Form" | Not "Form" | Var "int" fun y :: "'a list => 'a list => 'a list" where "y (nil2) y2 = y2" | "y (cons2 z2 xs) y2 = cons2 z2 (y xs y2)" fun or2 :: "bool list => bool" where "or2 (nil2) = False" | "or2 (cons2 y2 xs) = (y2 | (or2 xs))" fun models7 :: "int => ((int, bool) pair) list => ((int, bool) pair) list" where "models7 z (nil2) = nil2" | "models7 z (cons2 z2 xs) = (if (z ~= (case z2 of pair2 x2 y22 => x2)) then cons2 z2 (models7 z xs) else models7 z xs)" fun models6 :: "int => ((int, bool) pair) list => bool list" where "models6 z (nil2) = nil2" | "models6 z (cons2 (pair2 y22 True) x2) = models6 z x2" | "models6 z (cons2 (pair2 y22 False) x2) = cons2 (z = y22) (models6 z x2)" fun models5 :: "int => ((int, bool) pair) list => ((int, bool) pair) list" where "models5 z (nil2) = nil2" | "models5 z (cons2 z2 xs) = (if (z ~= (case z2 of pair2 x2 y22 => x2)) then cons2 z2 (models5 z xs) else models5 z xs)" fun models4 :: "int => ((int, bool) pair) list => bool list" where "models4 z (nil2) = nil2" | "models4 z (cons2 (pair2 y22 True) x2) = cons2 (z = y22) (models4 z x2)" | "models4 z (cons2 (pair2 y22 False) x2) = models4 z x2" function models :: "(((int, bool) pair) list) list => Form => (((int, bool) pair) list) list => (((int, bool) pair) list) list" and models2 :: "Form => (((int, bool) pair) list) list => (((int, bool) pair) list) list" and models3 :: "Form => ((int, bool) pair) list => (((int, bool) pair) list) list" where "models z q (nil2) = models2 q z" | "models z q (cons2 z2 x2) = cons2 z2 (models z q x2)" | "models2 q (nil2) = nil2" | "models2 q (cons2 y2 z2) = models z2 q (models3 q y2)" | "models3 (x p q) y2 = models2 q (models3 p y2)" | "models3 (Not (x r q2)) y2 = y (models3 (Not r) y2) (models3 (x r (Not q2)) y2)" | "models3 (Not (Not p2)) y2 = models3 p2 y2" | "models3 (Not (Var x2)) y2 = (if (~ (or2 (models4 x2 y2))) then cons2 (cons2 (pair2 x2 False) (models5 x2 y2)) (nil2) else nil2)" | "models3 (Var x3) y2 = (if (~ (or2 (models6 x3 y2))) then cons2 (cons2 (pair2 x3 True) (models7 x3 y2)) (nil2) else nil2)" by pat_completeness auto fun valid :: "Form => bool" where "valid z = (case models3 (Not z) (nil2) of nil2 => True | cons2 y2 z2 => False)" theorem property0 : "((valid (x p q)) = (valid (x q p)))" oops end
header {* Bit Block Transfer and Other Array Optimizations *} theory Array_Blit imports "../Sep_Main" "~~/src/HOL/Library/Code_Target_Numeral" begin subsection "Definition" primrec blit :: "_ array \<Rightarrow> nat \<Rightarrow> _ array \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> unit Heap" where "blit _ _ _ _ 0 = return ()" | "blit src si dst di (Suc l) = do { x \<leftarrow> Array.nth src si; Array.upd di x dst; blit src (si+1) dst (di+1) l }" lemma blit_rule[sep_heap_rules]: assumes LEN: "si+len \<le> length lsrc" "di+len \<le> length ldst" shows "< src \<mapsto>\<^sub>a lsrc * dst \<mapsto>\<^sub>a ldst > blit src si dst di len <\<lambda>_. src \<mapsto>\<^sub>a lsrc * dst \<mapsto>\<^sub>a (take di ldst @ take len (drop si lsrc) @ drop (di+len) ldst) >" using LEN proof (induction len arbitrary: si di ldst) case 0 thus ?case by sep_auto next case (Suc len) note [sep_heap_rules] = Suc.IH have [simp]: "\<And>x. lsrc ! si # take len (drop (Suc si) lsrc) @ x = take (Suc len) (drop si lsrc) @ x" apply simp by (metis Suc.prems(1) add_Suc_right Cons_nth_drop_Suc less_Suc_eq_le add.commute not_less_eq take_Suc_Cons Nat.trans_le_add2) from Suc.prems show ?case by (sep_auto simp: take_update_last drop_upd_irrelevant) qed definition nth_oo where "nth_oo v a i \<equiv> do { l\<leftarrow>Array.len a; if i<l then Array.nth a i else return v }" definition upd_oo where "upd_oo f i x a \<equiv> do { l\<leftarrow>Array.len a; if i<l then Array.upd i x a else f }" ML_val Array.update subsection "Code Generator Setup" code_printing code_module "array_blit" \<rightharpoonup> (SML) {* fun array_blit src si dst di len = ArraySlice.copy { di=di, src = ArraySlice.slice (src,si,SOME len), dst=dst} fun array_nth_oo v a i () = Array.sub(a,i) handle Subscript => v fun array_upd_oo f i x a () = (Array.update(a,i,x); a) handle Subscript => f () *} definition blit' where [code del]: "blit' src si dst di len = blit src (nat_of_integer si) dst (nat_of_integer di) (nat_of_integer len)" (* TODO: Export to other languages: OCaml, Haskell, Scala *) code_printing constant blit' \<rightharpoonup> (SML) "(fn/ ()/ => /array'_blit _ _ _ _ _)" and (Scala) "('_: Unit)/=>/ System.arraycopy((_).array,(_).as'_Int,(_).array,(_).as'_Int,(_).as'_Int)" definition [code del]: "nth_oo' v a == nth_oo v a o nat_of_integer" definition [code del]: "upd_oo' f == upd_oo f o nat_of_integer" lemma [code]: "nth_oo v a == nth_oo' v a o integer_of_nat" "upd_oo f == upd_oo' f o integer_of_nat" by (simp_all add: nth_oo'_def upd_oo'_def o_def) text {* Fallbacks *} lemmas [code] = nth_oo'_def[unfolded nth_oo_def[abs_def]] lemmas [code] = upd_oo'_def[unfolded upd_oo_def[abs_def]] code_printing constant nth_oo' \<rightharpoonup> (SML) "array'_nth'_oo _ _ _" | constant upd_oo' \<rightharpoonup> (SML) "array'_upd'_oo _ _ _ _" subsection {* Derived Functions *} definition "array_shrink a s \<equiv> do { (* Avoiding the need for default value *) l\<leftarrow>Array.len a; if l=s then return a else if l=0 then Array.of_list [] else do { x\<leftarrow>Array.nth a 0; a'\<leftarrow>Array.new s x; blit a 0 a' 0 s; return a' } }" lemma array_shrink_rule[sep_heap_rules]: assumes "s\<le>length la" shows "< a\<mapsto>\<^sub>ala > array_shrink a s <\<lambda>a'. a'\<mapsto>\<^sub>atake s la >\<^sub>t" using assms unfolding array_shrink_def by sep_auto definition "array_grow a s x \<equiv> do { l\<leftarrow>Array.len a; if l=s then return a else do { a'\<leftarrow>Array.new s x; blit a 0 a' 0 l; return a' } }" lemma array_grow_rule[sep_heap_rules]: assumes "s\<ge>length la" shows " < a\<mapsto>\<^sub>ala > array_grow a s x <\<lambda>a'. a'\<mapsto>\<^sub>a (la @ replicate (s-length la) x)>\<^sub>t" using assms unfolding array_grow_def by sep_auto end
(* File: Indexed_PQueue.thy Author: Bohua Zhan *) section \<open>Indexed priority queues\<close> theory Indexed_PQueue imports Arrays_Ex Mapping_Str begin text \<open> Verification of indexed priority queue: functional part. The data structure is also verified by Lammich in \cite{Refine_Imperative_HOL-AFP}. \<close> subsection \<open>Successor functions, eq-pred predicate\<close> fun s1 :: "nat \<Rightarrow> nat" where "s1 m = 2 * m + 1" fun s2 :: "nat \<Rightarrow> nat" where "s2 m = 2 * m + 2" lemma s_inj [forward]: "s1 m = s1 m' \<Longrightarrow> m = m'" "s2 m = s2 m' \<Longrightarrow> m = m'" by auto lemma s_neq [resolve]: "s1 m \<noteq> s2 m'" "s1 m > m" "s2 m > m" "s2 m > s1 m" using s1.simps s2.simps by presburger+ setup \<open>add_forward_prfstep_cond @{thm s_neq(2)} [with_term "s1 ?m"]\<close> setup \<open>add_forward_prfstep_cond @{thm s_neq(3)} [with_term "s2 ?m"]\<close> setup \<open>add_forward_prfstep_cond @{thm s_neq(4)} [with_term "s2 ?m", with_term "s1 ?m"]\<close> inductive eq_pred :: "nat \<Rightarrow> nat \<Rightarrow> bool" where "eq_pred n n" | "eq_pred n m \<Longrightarrow> eq_pred n (s1 m)" | "eq_pred n m \<Longrightarrow> eq_pred n (s2 m)" setup \<open>add_case_induct_rule @{thm eq_pred.cases}\<close> setup \<open>add_prop_induct_rule @{thm eq_pred.induct}\<close> setup \<open>add_resolve_prfstep @{thm eq_pred.intros(1)}\<close> setup \<open>fold add_backward_prfstep @{thms eq_pred.intros(2,3)}\<close> lemma eq_pred_parent1 [forward]: "eq_pred i (s1 k) \<Longrightarrow> i \<noteq> s1 k \<Longrightarrow> eq_pred i k" @proof @let "v = s1 k" @prop_induct "eq_pred i v" @qed lemma eq_pred_parent2 [forward]: "eq_pred i (s2 k) \<Longrightarrow> i \<noteq> s2 k \<Longrightarrow> eq_pred i k" @proof @let "v = s2 k" @prop_induct "eq_pred i v" @qed lemma eq_pred_cases: "eq_pred i j \<Longrightarrow> eq_pred (s1 i) j \<or> eq_pred (s2 i) j \<or> j = i \<or> j = s1 i \<or> j = s2 i" @proof @prop_induct "eq_pred i j" @qed setup \<open>add_forward_prfstep_cond @{thm eq_pred_cases} [with_cond "?i \<noteq> s1 ?k", with_cond "?i \<noteq> s2 ?k"]\<close> lemma eq_pred_le [forward]: "eq_pred i j \<Longrightarrow> i \<le> j" @proof @prop_induct "eq_pred i j" @qed subsection \<open>Heap property\<close> text \<open>The corresponding tree is a heap\<close> definition is_heap :: "('a \<times> 'b::linorder) list \<Rightarrow> bool" where [rewrite]: "is_heap xs = (\<forall>i j. eq_pred i j \<longrightarrow> j < length xs \<longrightarrow> snd (xs ! i) \<le> snd (xs ! j))" lemma is_heapD: "is_heap xs \<Longrightarrow> j < length xs \<Longrightarrow> eq_pred i j \<Longrightarrow> snd (xs ! i) \<le> snd (xs ! j)" by auto2 setup \<open>add_forward_prfstep_cond @{thm is_heapD} [with_term "?xs ! ?j"]\<close> setup \<open>del_prfstep_thm_eqforward @{thm is_heap_def}\<close> subsection \<open>Bubble-down\<close> text \<open>The corresponding tree is a heap, except k is not necessarily smaller than its descendents.\<close> definition is_heap_partial1 :: "('a \<times> 'b::linorder) list \<Rightarrow> nat \<Rightarrow> bool" where [rewrite]: "is_heap_partial1 xs k = (\<forall>i j. eq_pred i j \<longrightarrow> i \<noteq> k \<longrightarrow> j < length xs \<longrightarrow> snd (xs ! i) \<le> snd (xs ! j))" text \<open>Two cases of switching with s1 k.\<close> lemma bubble_down1: "s1 k < length xs \<Longrightarrow> is_heap_partial1 xs k \<Longrightarrow> snd (xs ! k) > snd (xs ! s1 k) \<Longrightarrow> snd (xs ! s1 k) \<le> snd (xs ! s2 k) \<Longrightarrow> is_heap_partial1 (list_swap xs k (s1 k)) (s1 k)" by auto2 setup \<open>add_forward_prfstep_cond @{thm bubble_down1} [with_term "list_swap ?xs ?k (s1 ?k)"]\<close> lemma bubble_down2: "s1 k < length xs \<Longrightarrow> is_heap_partial1 xs k \<Longrightarrow> snd (xs ! k) > snd (xs ! s1 k) \<Longrightarrow> s2 k \<ge> length xs \<Longrightarrow> is_heap_partial1 (list_swap xs k (s1 k)) (s1 k)" by auto2 setup \<open>add_forward_prfstep_cond @{thm bubble_down2} [with_term "list_swap ?xs ?k (s1 ?k)"]\<close> text \<open>One case of switching with s2 k.\<close> lemma bubble_down3: "s2 k < length xs \<Longrightarrow> is_heap_partial1 xs k \<Longrightarrow> snd (xs ! s1 k) > snd (xs ! s2 k) \<Longrightarrow> snd (xs ! k) > snd (xs ! s2 k) \<Longrightarrow> xs' = list_swap xs k (s2 k) \<Longrightarrow> is_heap_partial1 xs' (s2 k)" by auto2 setup \<open>add_forward_prfstep_cond @{thm bubble_down3} [with_term "?xs'"]\<close> subsection \<open>Bubble-up\<close> fun par :: "nat \<Rightarrow> nat" where "par m = (m - 1) div 2" setup \<open>register_wellform_data ("par m", ["m \<noteq> 0"])\<close> lemma ps_inverse [rewrite]: "par (s1 k) = k" "par (s2 k) = k" by simp+ lemma p_basic: "m \<noteq> 0 \<Longrightarrow> par m < m" by auto setup \<open>add_forward_prfstep_cond @{thm p_basic} [with_term "par ?m"]\<close> lemma p_cases: "m \<noteq> 0 \<Longrightarrow> m = s1 (par m) \<or> m = s2 (par m)" by auto setup \<open>add_forward_prfstep_cond @{thm p_cases} [with_term "par ?m"]\<close> lemma eq_pred_p_next: "i \<noteq> 0 \<Longrightarrow> eq_pred i j \<Longrightarrow> eq_pred (par i) j" @proof @prop_induct "eq_pred i j" @qed setup \<open>add_forward_prfstep_cond @{thm eq_pred_p_next} [with_term "par ?i"]\<close> lemma heap_implies_hd_min [resolve]: "is_heap xs \<Longrightarrow> i < length xs \<Longrightarrow> xs \<noteq> [] \<Longrightarrow> snd (hd xs) \<le> snd (xs ! i)" @proof @strong_induct i @case "i = 0" @apply_induct_hyp "par i" @have "eq_pred (par i) i" @qed text \<open>The corresponding tree is a heap, except k is not necessarily greater than its ancestors.\<close> definition is_heap_partial2 :: "('a \<times> 'b::linorder) list \<Rightarrow> nat \<Rightarrow> bool" where [rewrite]: "is_heap_partial2 xs k = (\<forall>i j. eq_pred i j \<longrightarrow> j < length xs \<longrightarrow> j \<noteq> k \<longrightarrow> snd (xs ! i) \<le> snd (xs ! j))" lemma bubble_up1 [forward]: "k < length xs \<Longrightarrow> is_heap_partial2 xs k \<Longrightarrow> snd (xs ! k) < snd (xs ! par k) \<Longrightarrow> k \<noteq> 0 \<Longrightarrow> is_heap_partial2 (list_swap xs k (par k)) (par k)" by auto2 lemma bubble_up2 [forward]: "k < length xs \<Longrightarrow> is_heap_partial2 xs k \<Longrightarrow> snd (xs ! k) \<ge> snd (xs ! par k) \<Longrightarrow> k \<noteq> 0 \<Longrightarrow> is_heap xs" by auto2 setup \<open>del_prfstep_thm @{thm p_cases}\<close> subsection \<open>Indexed priority queue\<close> type_synonym 'a idx_pqueue = "(nat \<times> 'a) list \<times> nat option list" fun index_of_pqueue :: "'a idx_pqueue \<Rightarrow> bool" where "index_of_pqueue (xs, m) = ( (\<forall>i<length xs. fst (xs ! i) < length m \<and> m ! (fst (xs ! i)) = Some i) \<and> (\<forall>i. \<forall>k<length m. m ! k = Some i \<longrightarrow> i < length xs \<and> fst (xs ! i) = k))" setup \<open>add_rewrite_rule @{thm index_of_pqueue.simps}\<close> lemma index_of_pqueueD1: "i < length xs \<Longrightarrow> index_of_pqueue (xs, m) \<Longrightarrow> fst (xs ! i) < length m \<and> m ! (fst (xs ! i)) = Some i" by auto2 setup \<open>add_forward_prfstep_cond @{thm index_of_pqueueD1} [with_term "?xs ! ?i"]\<close> lemma index_of_pqueueD2 [forward]: "k < length m \<Longrightarrow> index_of_pqueue (xs, m) \<Longrightarrow> m ! k = Some i \<Longrightarrow> i < length xs \<and> fst (xs ! i) = k" by auto2 lemma index_of_pqueueD3 [forward]: "index_of_pqueue (xs, m) \<Longrightarrow> p \<in> set xs \<Longrightarrow> fst p < length m" @proof @obtain i where "i < length xs" "xs ! i = p" @qed setup \<open>del_prfstep_thm_eqforward @{thm index_of_pqueue.simps}\<close> lemma has_index_unique_key [forward]: "index_of_pqueue (xs, m) \<Longrightarrow> unique_keys_set (set xs)" @proof @have "\<forall>a x y. (a, x) \<in> set xs \<longrightarrow> (a, y) \<in> set xs \<longrightarrow> x = y" @with @obtain i where "i < length xs" "xs ! i = (a, x)" @obtain j where "j < length xs" "xs ! j = (a, y)" @end @qed lemma has_index_keys_of [rewrite]: "index_of_pqueue (xs, m) \<Longrightarrow> has_key_alist xs k \<longleftrightarrow> (k < length m \<and> m ! k \<noteq> None)" @proof @case "has_key_alist xs k" @with @obtain v' where "(k, v') \<in> set xs" @obtain i where "i < length xs \<and> xs ! i = (k, v')" @end @qed lemma has_index_distinct [forward]: "index_of_pqueue (xs, m) \<Longrightarrow> distinct xs" @proof @have "\<forall>i<length xs. \<forall>j<length xs. i \<noteq> j \<longrightarrow> xs ! i \<noteq> xs ! j" @qed subsection \<open>Basic operations on indexed\_queue\<close> fun idx_pqueue_swap_fun :: "(nat \<times> 'a) list \<times> nat option list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> (nat \<times> 'a) list \<times> nat option list" where "idx_pqueue_swap_fun (xs, m) i j = ( list_swap xs i j, ((m [fst (xs ! i) := Some j]) [fst (xs ! j) := Some i]))" lemma index_of_pqueue_swap [forward_arg]: "i < length xs \<Longrightarrow> j < length xs \<Longrightarrow> index_of_pqueue (xs, m) \<Longrightarrow> index_of_pqueue (idx_pqueue_swap_fun (xs, m) i j)" @proof @unfold "idx_pqueue_swap_fun (xs, m) i j" @qed lemma fst_idx_pqueue_swap [rewrite]: "fst (idx_pqueue_swap_fun (xs, m) i j) = list_swap xs i j" @proof @unfold "idx_pqueue_swap_fun (xs, m) i j" @qed lemma snd_idx_pqueue_swap [rewrite]: "length (snd (idx_pqueue_swap_fun (xs, m) i j)) = length m" @proof @unfold "idx_pqueue_swap_fun (xs, m) i j" @qed fun idx_pqueue_push_fun :: "nat \<Rightarrow> 'a \<Rightarrow> 'a idx_pqueue \<Rightarrow> 'a idx_pqueue" where "idx_pqueue_push_fun k v (xs, m) = (xs @ [(k, v)], list_update m k (Some (length xs)))" lemma idx_pqueue_push_correct [forward_arg]: "index_of_pqueue (xs, m) \<Longrightarrow> k < length m \<Longrightarrow> \<not>has_key_alist xs k \<Longrightarrow> r = idx_pqueue_push_fun k v (xs, m) \<Longrightarrow> index_of_pqueue r \<and> fst r = xs @ [(k, v)] \<and> length (snd r) = length m" @proof @unfold "idx_pqueue_push_fun k v (xs, m)" @qed fun idx_pqueue_pop_fun :: "'a idx_pqueue \<Rightarrow> 'a idx_pqueue" where "idx_pqueue_pop_fun (xs, m) = (butlast xs, list_update m (fst (last xs)) None)" lemma idx_pqueue_pop_correct [forward_arg]: "index_of_pqueue (xs, m) \<Longrightarrow> xs \<noteq> [] \<Longrightarrow> r = idx_pqueue_pop_fun (xs, m) \<Longrightarrow> index_of_pqueue r \<and> fst r = butlast xs \<and> length (snd r) = length m" @proof @unfold "idx_pqueue_pop_fun (xs, m)" @have "length xs = length (butlast xs) + 1" @have "fst (xs ! length (butlast xs)) < length m" (* TODO: remove? *) @qed subsection \<open>Bubble up and down\<close> function idx_bubble_down_fun :: "'a::linorder idx_pqueue \<Rightarrow> nat \<Rightarrow> 'a idx_pqueue" where "idx_bubble_down_fun (xs, m) k = ( if s2 k < length xs then if snd (xs ! s1 k) \<le> snd (xs ! s2 k) then if snd (xs ! k) > snd (xs ! s1 k) then idx_bubble_down_fun (idx_pqueue_swap_fun (xs, m) k (s1 k)) (s1 k) else (xs, m) else if snd (xs ! k) > snd (xs ! s2 k) then idx_bubble_down_fun (idx_pqueue_swap_fun (xs, m) k (s2 k)) (s2 k) else (xs, m) else if s1 k < length xs then if snd (xs ! k) > snd (xs ! s1 k) then idx_bubble_down_fun (idx_pqueue_swap_fun (xs, m) k (s1 k)) (s1 k) else (xs, m) else (xs, m))" by pat_completeness auto termination by (relation "measure (\<lambda>((xs,_),k). (length xs - k))") (simp_all, auto2+) lemma idx_bubble_down_fun_correct: "r = idx_bubble_down_fun x k \<Longrightarrow> is_heap_partial1 (fst x) k \<Longrightarrow> is_heap (fst r) \<and> mset (fst r) = mset (fst x) \<and> length (snd r) = length (snd x)" @proof @fun_induct "idx_bubble_down_fun x k" @with @subgoal "(x = (xs, m), k = k)" @unfold "idx_bubble_down_fun (xs, m) k" @case "s2 k < length xs" @with @case "snd (xs ! s1 k) \<le> snd (xs ! s2 k)" @end @case "s1 k < length xs" @end @qed setup \<open>add_forward_prfstep_cond @{thm idx_bubble_down_fun_correct} [with_term "?r"]\<close> lemma idx_bubble_down_fun_correct2 [forward]: "index_of_pqueue x \<Longrightarrow> index_of_pqueue (idx_bubble_down_fun x k)" @proof @fun_induct "idx_bubble_down_fun x k" @with @subgoal "(x = (xs, m), k = k)" @unfold "idx_bubble_down_fun (xs, m) k" @case "s2 k < length xs" @with @case "snd (xs ! s1 k) \<le> snd (xs ! s2 k)" @end @case "s1 k < length xs" @end @qed fun idx_bubble_up_fun :: "'a::linorder idx_pqueue \<Rightarrow> nat \<Rightarrow> 'a idx_pqueue" where "idx_bubble_up_fun (xs, m) k = ( if k = 0 then (xs, m) else if k < length xs then if snd (xs ! k) < snd (xs ! par k) then idx_bubble_up_fun (idx_pqueue_swap_fun (xs, m) k (par k)) (par k) else (xs, m) else (xs, m))" lemma idx_bubble_up_fun_correct: "r = idx_bubble_up_fun x k \<Longrightarrow> is_heap_partial2 (fst x) k \<Longrightarrow> is_heap (fst r) \<and> mset (fst r) = mset (fst x) \<and> length (snd r) = length (snd x)" @proof @fun_induct "idx_bubble_up_fun x k" @with @subgoal "(x = (xs, m), k = k)" @unfold "idx_bubble_up_fun (xs, m) k" @end @qed setup \<open>add_forward_prfstep_cond @{thm idx_bubble_up_fun_correct} [with_term "?r"]\<close> lemma idx_bubble_up_fun_correct2 [forward]: "index_of_pqueue x \<Longrightarrow> index_of_pqueue (idx_bubble_up_fun x k)" @proof @fun_induct "idx_bubble_up_fun x k" @with @subgoal "(x = (xs, m), k = k)" @unfold "idx_bubble_up_fun (xs, m) k" @end @qed subsection \<open>Main operations\<close> fun delete_min_idx_pqueue_fun :: "'a::linorder idx_pqueue \<Rightarrow> (nat \<times> 'a) \<times> 'a idx_pqueue" where "delete_min_idx_pqueue_fun (xs, m) = ( let (xs', m') = idx_pqueue_swap_fun (xs, m) 0 (length xs - 1); a'' = idx_pqueue_pop_fun (xs', m') in (last xs', idx_bubble_down_fun a'' 0))" lemma delete_min_idx_pqueue_correct: "index_of_pqueue (xs, m) \<Longrightarrow> xs \<noteq> [] \<Longrightarrow> res = delete_min_idx_pqueue_fun (xs, m) \<Longrightarrow> index_of_pqueue (snd res)" @proof @unfold "delete_min_idx_pqueue_fun (xs, m)" @qed setup \<open>add_forward_prfstep_cond @{thm delete_min_idx_pqueue_correct} [with_term "?res"]\<close> lemma hd_last_swap_eval_last [rewrite]: "xs \<noteq> [] \<Longrightarrow> last (list_swap xs 0 (length xs - 1)) = hd xs" @proof @let "xs' = list_swap xs 0 (length xs - 1)" @have "last xs' = xs' ! (length xs - 1)" @qed text \<open>Correctness of delete-min.\<close> theorem delete_min_idx_pqueue_correct2: "is_heap xs \<Longrightarrow> xs \<noteq> [] \<Longrightarrow> res = delete_min_idx_pqueue_fun (xs, m) \<Longrightarrow> index_of_pqueue (xs, m) \<Longrightarrow> is_heap (fst (snd res)) \<and> fst res = hd xs \<and> length (snd (snd res)) = length m \<and> map_of_alist (fst (snd res)) = delete_map (fst (fst res)) (map_of_alist xs)" @proof @unfold "delete_min_idx_pqueue_fun (xs, m)" @let "xs' = list_swap xs 0 (length xs - 1)" @have "is_heap_partial1 (butlast xs') 0" @qed setup \<open>add_forward_prfstep_cond @{thm delete_min_idx_pqueue_correct2} [with_term "?res"]\<close> fun insert_idx_pqueue_fun :: "nat \<Rightarrow> 'a::linorder \<Rightarrow> 'a idx_pqueue \<Rightarrow> 'a idx_pqueue" where "insert_idx_pqueue_fun k v x = ( let x' = idx_pqueue_push_fun k v x in idx_bubble_up_fun x' (length (fst x') - 1))" lemma insert_idx_pqueue_correct [forward_arg]: "index_of_pqueue (xs, m) \<Longrightarrow> k < length m \<Longrightarrow> \<not>has_key_alist xs k \<Longrightarrow> index_of_pqueue (insert_idx_pqueue_fun k v (xs, m))" @proof @unfold "insert_idx_pqueue_fun k v (xs, m)" @qed text \<open>Correctness of insertion.\<close> theorem insert_idx_pqueue_correct2: "index_of_pqueue (xs, m) \<Longrightarrow> is_heap xs \<Longrightarrow> k < length m \<Longrightarrow> \<not>has_key_alist xs k \<Longrightarrow> r = insert_idx_pqueue_fun k v (xs, m) \<Longrightarrow> is_heap (fst r) \<and> length (snd r) = length m \<and> map_of_alist (fst r) = map_of_alist xs { k \<rightarrow> v }" @proof @unfold "insert_idx_pqueue_fun k v (xs, m)" @have "is_heap_partial2 (xs @ [(k, v)]) (length xs)" @qed setup \<open>add_forward_prfstep_cond @{thm insert_idx_pqueue_correct2} [with_term "?r"]\<close> fun update_idx_pqueue_fun :: "nat \<Rightarrow> 'a::linorder \<Rightarrow> 'a idx_pqueue \<Rightarrow> 'a idx_pqueue" where "update_idx_pqueue_fun k v (xs, m) = ( if m ! k = None then insert_idx_pqueue_fun k v (xs, m) else let i = the (m ! k); xs' = list_update xs i (k, v) in if snd (xs ! i) \<le> v then idx_bubble_down_fun (xs', m) i else idx_bubble_up_fun (xs', m) i)" lemma update_idx_pqueue_correct [forward_arg]: "index_of_pqueue (xs, m) \<Longrightarrow> k < length m \<Longrightarrow> index_of_pqueue (update_idx_pqueue_fun k v (xs, m))" @proof @unfold "update_idx_pqueue_fun k v (xs, m)" @let "i = the (m ! k)" @let "xs' = list_update xs i (k, v)" @case "m ! k = None" @have "index_of_pqueue (xs', m)" @qed text \<open>Correctness of update.\<close> theorem update_idx_pqueue_correct2: "index_of_pqueue (xs, m) \<Longrightarrow> is_heap xs \<Longrightarrow> k < length m \<Longrightarrow> r = update_idx_pqueue_fun k v (xs, m) \<Longrightarrow> is_heap (fst r) \<and> length (snd r) = length m \<and> map_of_alist (fst r) = map_of_alist xs { k \<rightarrow> v }" @proof @unfold "update_idx_pqueue_fun k v (xs, m)" @let "i = the (m ! k)" @let "xs' = list_update xs i (k, v)" @have "xs' = fst (xs', m)" (* TODO: remove *) @case "m ! k = None" @case "snd (xs ! the (m ! k)) \<le> v" @with @have "is_heap_partial1 xs' i" @end @have "is_heap_partial2 xs' i" @qed setup \<open>add_forward_prfstep_cond @{thm update_idx_pqueue_correct2} [with_term "?r"]\<close> end
[STATEMENT] lemma mrbst_join_Leaf_left [simp]: "mrbst_join \<langle>\<rangle> = return_pmf" [PROOF STATE] proof (prove) goal (1 subgoal): 1. mrbst_join \<langle>\<rangle> = return_pmf [PROOF STEP] by (simp add: fun_eq_iff)
import Mathlib.Tactic.Basic import Mathlib.Tactic.LeftRight lemma v1 (P Q R : Prop) : P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) := by (constructor; (intro h; cases h with | intro hP hQR => cases hQR with | inl hQ => left; constructor; assumption; assumption | inr hR => right; constructor; assumption; assumption ); (intro h; cases h with | inl hPQ => cases hPQ with | intro hP hQ => constructor; assumption; left; assumption | inr hPR => cases hPR with | intro hP hR => constructor; assumption; right; assumption ) ) lemma v2 (P Q R : Prop) : P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) := ((Iff.intro ((λ h : P ∧ (Q ∨ R) => (match h with | And.intro hP hQR => (match hQR with | Or.inl hQ => Or.inl (And.intro hP hQ : P ∧ Q) | Or.inr hR => Or.inr (And.intro hP hR : P ∧ R) ) ) ) : P ∧ (Q ∨ R) -> (P ∧ Q) ∨ (P ∧ R)) ((λ h : P ∧ Q ∨ P ∧ R => (And.intro ((match h with | Or.inl (And.intro hP hQ) => hP | Or.inr (And.intro hP hR) => hP ) : P) ((match h with | Or.inl (And.intro hP hQ) => Or.inl hQ | Or.inr (And.intro hP hR) => Or.inr hR ) : Q ∨ R) ) ) : (P ∧ Q) ∨ (P ∧ R) -> P ∧ (Q ∨ R)) ) : P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R)) class MyAdd (a : Type) where add : a -> a -> a #check @MyAdd.add instance : MyAdd Nat where add := Nat.add instance : MyAdd Int where add := Int.add instance : MyAdd Float where add := Float.add def double [inst : Add a] (x : a) : a := inst.add x x #check @double -- @double : {a : Type} → [inst : Add a] → a → a -- #eval double 10 -- 20 #check Nat.ne_of_lt example : ¬ 0 < 0 := ((fun h => let x := (Nat.ne_of_lt h) let y := (absurd rfl x) y ) : ¬ 0 < 0) #check @absurd example (n : Nat) (h : n ≠ 0) : .succ (.pred n) = n := ((match n with | Nat.zero => absurd rfl h | Nat.succ m => rfl ) : .succ (.pred n) = n) example (n : Nat) (h : n ≠ 0) : .succ (.pred n) = n := by cases n with | zero => -- goal: h : 0 ≠ 0 ⊢ succ (pred 0) = 0 apply absurd rfl h | succ m => -- second goal: h : succ m ≠ 0 ⊢ succ (pred (succ m)) = succ m rfl -- induction with term and tactics def add : Nat → Nat → Nat | m, .zero => m | m, .succ n => .succ (add m n) theorem add_zero (m : Nat) : add m .zero = m := rfl theorem add_succ (m n : Nat) : add m (.succ n) = .succ (add m n) := rfl theorem zero_add : ∀ n, add .zero n = n | .zero => rfl | .succ n => congrArg Nat.succ (zero_add n) #check @congrArg example : ∀ n, add .zero n = n := by (intro n; (induction n with | zero => apply rfl | succ n IH => apply congrArg Nat.succ IH ) ) theorem not_lt_zero (n : Nat) : ¬ n < 0 := (fun h => let h : n + 1 ≤ 0 := h match n with | 0 => let z := Nat.ne_of_lt h absurd rfl z | n' + 1 => let IH := not_lt_zero n' let z : n' + 1 ≤ 0 := Nat.lt_of_succ_lt h (IH z) )
[GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R ⊢ ∀ {a b : S}, a ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → a + b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} [PROOFSTEP] rintro a b ⟨a', ha⟩ ⟨b', hb⟩ [GOAL] case intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R a b : S a' : { x // x ∈ I } × { x // x ∈ M } ha : a * ↑(algebraMap R S) ↑a'.snd = ↑(algebraMap R S) ↑a'.fst b' : { x // x ∈ I } × { x // x ∈ M } hb : b * ↑(algebraMap R S) ↑b'.snd = ↑(algebraMap R S) ↑b'.fst ⊢ a + b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} [PROOFSTEP] let Z : { x // x ∈ I } := ⟨(a'.2 : R) * (b'.1 : R) + (b'.2 : R) * (a'.1 : R), I.add_mem (I.mul_mem_left _ b'.1.2) (I.mul_mem_left _ a'.1.2)⟩ [GOAL] case intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R a b : S a' : { x // x ∈ I } × { x // x ∈ M } ha : a * ↑(algebraMap R S) ↑a'.snd = ↑(algebraMap R S) ↑a'.fst b' : { x // x ∈ I } × { x // x ∈ M } hb : b * ↑(algebraMap R S) ↑b'.snd = ↑(algebraMap R S) ↑b'.fst Z : { x // x ∈ I } := { val := ↑a'.snd * ↑b'.fst + ↑b'.snd * ↑a'.fst, property := (_ : ↑a'.snd * ↑b'.fst + ↑b'.snd * ↑a'.fst ∈ I) } ⊢ a + b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} [PROOFSTEP] use⟨Z, a'.2 * b'.2⟩ [GOAL] case h R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R a b : S a' : { x // x ∈ I } × { x // x ∈ M } ha : a * ↑(algebraMap R S) ↑a'.snd = ↑(algebraMap R S) ↑a'.fst b' : { x // x ∈ I } × { x // x ∈ M } hb : b * ↑(algebraMap R S) ↑b'.snd = ↑(algebraMap R S) ↑b'.fst Z : { x // x ∈ I } := { val := ↑a'.snd * ↑b'.fst + ↑b'.snd * ↑a'.fst, property := (_ : ↑a'.snd * ↑b'.fst + ↑b'.snd * ↑a'.fst ∈ I) } ⊢ (a + b) * ↑(algebraMap R S) ↑(Z, a'.snd * b'.snd).snd = ↑(algebraMap R S) ↑(Z, a'.snd * b'.snd).fst [PROOFSTEP] simp only [RingHom.map_add, Submodule.coe_mk, Submonoid.coe_mul, RingHom.map_mul] [GOAL] case h R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R a b : S a' : { x // x ∈ I } × { x // x ∈ M } ha : a * ↑(algebraMap R S) ↑a'.snd = ↑(algebraMap R S) ↑a'.fst b' : { x // x ∈ I } × { x // x ∈ M } hb : b * ↑(algebraMap R S) ↑b'.snd = ↑(algebraMap R S) ↑b'.fst Z : { x // x ∈ I } := { val := ↑a'.snd * ↑b'.fst + ↑b'.snd * ↑a'.fst, property := (_ : ↑a'.snd * ↑b'.fst + ↑b'.snd * ↑a'.fst ∈ I) } ⊢ (a + b) * (↑(algebraMap R S) ↑a'.snd * ↑(algebraMap R S) ↑b'.snd) = ↑(algebraMap R S) ↑a'.snd * ↑(algebraMap R S) ↑b'.fst + ↑(algebraMap R S) ↑b'.snd * ↑(algebraMap R S) ↑a'.fst [PROOFSTEP] rw [add_mul, ← mul_assoc a, ha, mul_comm (algebraMap R S a'.2) (algebraMap R S b'.2), ← mul_assoc b, hb] [GOAL] case h R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R a b : S a' : { x // x ∈ I } × { x // x ∈ M } ha : a * ↑(algebraMap R S) ↑a'.snd = ↑(algebraMap R S) ↑a'.fst b' : { x // x ∈ I } × { x // x ∈ M } hb : b * ↑(algebraMap R S) ↑b'.snd = ↑(algebraMap R S) ↑b'.fst Z : { x // x ∈ I } := { val := ↑a'.snd * ↑b'.fst + ↑b'.snd * ↑a'.fst, property := (_ : ↑a'.snd * ↑b'.fst + ↑b'.snd * ↑a'.fst ∈ I) } ⊢ ↑(algebraMap R S) ↑a'.fst * ↑(algebraMap R S) ↑b'.snd + ↑(algebraMap R S) ↑b'.fst * ↑(algebraMap R S) ↑a'.snd = ↑(algebraMap R S) ↑a'.snd * ↑(algebraMap R S) ↑b'.fst + ↑(algebraMap R S) ↑b'.snd * ↑(algebraMap R S) ↑a'.fst [PROOFSTEP] ring [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R ⊢ 0 * ↑(algebraMap R S) ↑(0, 1).snd = ↑(algebraMap R S) ↑(0, 1).fst [PROOFSTEP] simp [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R ⊢ ∀ (c : S) {x : S}, x ∈ { toAddSubsemigroup := { carrier := {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}, add_mem' := (_ : ∀ {a b : S}, a ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → a + b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}) }, zero_mem' := (_ : ∃ x, 0 * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst) }.toAddSubsemigroup.carrier → c • x ∈ { toAddSubsemigroup := { carrier := {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}, add_mem' := (_ : ∀ {a b : S}, a ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → a + b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}) }, zero_mem' := (_ : ∃ x, 0 * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst) }.toAddSubsemigroup.carrier [PROOFSTEP] rintro c x ⟨x', hx⟩ [GOAL] case intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R c x : S x' : { x // x ∈ I } × { x // x ∈ M } hx : x * ↑(algebraMap R S) ↑x'.snd = ↑(algebraMap R S) ↑x'.fst ⊢ c • x ∈ { toAddSubsemigroup := { carrier := {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}, add_mem' := (_ : ∀ {a b : S}, a ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → a + b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}) }, zero_mem' := (_ : ∃ x, 0 * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst) }.toAddSubsemigroup.carrier [PROOFSTEP] obtain ⟨c', hc⟩ := IsLocalization.surj M c [GOAL] case intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R c x : S x' : { x // x ∈ I } × { x // x ∈ M } hx : x * ↑(algebraMap R S) ↑x'.snd = ↑(algebraMap R S) ↑x'.fst c' : R × { x // x ∈ M } hc : c * ↑(algebraMap R S) ↑c'.snd = ↑(algebraMap R S) c'.fst ⊢ c • x ∈ { toAddSubsemigroup := { carrier := {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}, add_mem' := (_ : ∀ {a b : S}, a ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → a + b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}) }, zero_mem' := (_ : ∃ x, 0 * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst) }.toAddSubsemigroup.carrier [PROOFSTEP] let Z : { x // x ∈ I } := ⟨c'.1 * x'.1, I.mul_mem_left c'.1 x'.1.2⟩ [GOAL] case intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R c x : S x' : { x // x ∈ I } × { x // x ∈ M } hx : x * ↑(algebraMap R S) ↑x'.snd = ↑(algebraMap R S) ↑x'.fst c' : R × { x // x ∈ M } hc : c * ↑(algebraMap R S) ↑c'.snd = ↑(algebraMap R S) c'.fst Z : { x // x ∈ I } := { val := c'.fst * ↑x'.fst, property := (_ : c'.fst * ↑x'.fst ∈ I) } ⊢ c • x ∈ { toAddSubsemigroup := { carrier := {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}, add_mem' := (_ : ∀ {a b : S}, a ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst} → a + b ∈ {z | ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst}) }, zero_mem' := (_ : ∃ x, 0 * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst) }.toAddSubsemigroup.carrier [PROOFSTEP] use⟨Z, c'.2 * x'.2⟩ [GOAL] case h R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R c x : S x' : { x // x ∈ I } × { x // x ∈ M } hx : x * ↑(algebraMap R S) ↑x'.snd = ↑(algebraMap R S) ↑x'.fst c' : R × { x // x ∈ M } hc : c * ↑(algebraMap R S) ↑c'.snd = ↑(algebraMap R S) c'.fst Z : { x // x ∈ I } := { val := c'.fst * ↑x'.fst, property := (_ : c'.fst * ↑x'.fst ∈ I) } ⊢ c • x * ↑(algebraMap R S) ↑(Z, c'.snd * x'.snd).snd = ↑(algebraMap R S) ↑(Z, c'.snd * x'.snd).fst [PROOFSTEP] simp only [← hx, ← hc, smul_eq_mul, Submodule.coe_mk, Submonoid.coe_mul, RingHom.map_mul] [GOAL] case h R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R c x : S x' : { x // x ∈ I } × { x // x ∈ M } hx : x * ↑(algebraMap R S) ↑x'.snd = ↑(algebraMap R S) ↑x'.fst c' : R × { x // x ∈ M } hc : c * ↑(algebraMap R S) ↑c'.snd = ↑(algebraMap R S) c'.fst Z : { x // x ∈ I } := { val := c'.fst * ↑x'.fst, property := (_ : c'.fst * ↑x'.fst ∈ I) } ⊢ c * x * (↑(algebraMap R S) ↑c'.snd * ↑(algebraMap R S) ↑x'.snd) = c * ↑(algebraMap R S) ↑c'.snd * (x * ↑(algebraMap R S) ↑x'.snd) [PROOFSTEP] ring -- Porting note: removed #align declaration since it is a private def [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z : S ⊢ z ∈ Ideal.map (algebraMap R S) I ↔ ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst [PROOFSTEP] constructor [GOAL] case mp R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z : S ⊢ z ∈ Ideal.map (algebraMap R S) I → ∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst [PROOFSTEP] change _ → z ∈ map_ideal M S I [GOAL] case mp R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z : S ⊢ z ∈ Ideal.map (algebraMap R S) I → z ∈ IsLocalization.map_ideal M S I [PROOFSTEP] refine' fun h => Ideal.mem_sInf.1 h fun z hz => _ [GOAL] case mp R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z✝ : S h : z✝ ∈ Ideal.map (algebraMap R S) I z : S hz : z ∈ ↑(algebraMap R S) '' ↑I ⊢ z ∈ ↑(IsLocalization.map_ideal M S I) [PROOFSTEP] obtain ⟨y, hy⟩ := hz [GOAL] case mp.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z✝ : S h : z✝ ∈ Ideal.map (algebraMap R S) I z : S y : R hy : y ∈ ↑I ∧ ↑(algebraMap R S) y = z ⊢ z ∈ ↑(IsLocalization.map_ideal M S I) [PROOFSTEP] let Z : { x // x ∈ I } := ⟨y, hy.left⟩ [GOAL] case mp.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z✝ : S h : z✝ ∈ Ideal.map (algebraMap R S) I z : S y : R hy : y ∈ ↑I ∧ ↑(algebraMap R S) y = z Z : { x // x ∈ I } := { val := y, property := (_ : y ∈ ↑I) } ⊢ z ∈ ↑(IsLocalization.map_ideal M S I) [PROOFSTEP] use⟨Z, 1⟩ [GOAL] case h R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z✝ : S h : z✝ ∈ Ideal.map (algebraMap R S) I z : S y : R hy : y ∈ ↑I ∧ ↑(algebraMap R S) y = z Z : { x // x ∈ I } := { val := y, property := (_ : y ∈ ↑I) } ⊢ z * ↑(algebraMap R S) ↑(Z, 1).snd = ↑(algebraMap R S) ↑(Z, 1).fst [PROOFSTEP] simp [hy.right] [GOAL] case mpr R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z : S ⊢ (∃ x, z * ↑(algebraMap R S) ↑x.snd = ↑(algebraMap R S) ↑x.fst) → z ∈ Ideal.map (algebraMap R S) I [PROOFSTEP] rintro ⟨⟨a, s⟩, h⟩ [GOAL] case mpr.intro.mk R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z : S a : { x // x ∈ I } s : { x // x ∈ M } h : z * ↑(algebraMap R S) ↑(a, s).snd = ↑(algebraMap R S) ↑(a, s).fst ⊢ z ∈ Ideal.map (algebraMap R S) I [PROOFSTEP] rw [← Ideal.unit_mul_mem_iff_mem _ (map_units S s), mul_comm] [GOAL] case mpr.intro.mk R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R z : S a : { x // x ∈ I } s : { x // x ∈ M } h : z * ↑(algebraMap R S) ↑(a, s).snd = ↑(algebraMap R S) ↑(a, s).fst ⊢ z * ↑(algebraMap R S) ↑s ∈ Ideal.map (algebraMap R S) I [PROOFSTEP] exact h.symm ▸ Ideal.mem_map_of_mem _ a.2 [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S x : S hJ : x ∈ J ⊢ x ∈ Ideal.map (algebraMap R S) (Ideal.comap (algebraMap R S) J) [PROOFSTEP] obtain ⟨r, s, hx⟩ := mk'_surjective M x [GOAL] case intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S x : S hJ : x ∈ J r : R s : { x // x ∈ M } hx : mk' S r s = x ⊢ x ∈ Ideal.map (algebraMap R S) (Ideal.comap (algebraMap R S) J) [PROOFSTEP] rw [← hx] at hJ ⊢ [GOAL] case intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S x : S r : R s : { x // x ∈ M } hJ : mk' S r s ∈ J hx : mk' S r s = x ⊢ mk' S r s ∈ Ideal.map (algebraMap R S) (Ideal.comap (algebraMap R S) J) [PROOFSTEP] exact Ideal.mul_mem_right _ _ (Ideal.mem_map_of_mem _ (show (algebraMap R S) r ∈ J from mk'_spec S r s ▸ J.mul_mem_right ((algebraMap R S) s) hJ)) [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I ⊢ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) = I [PROOFSTEP] refine' le_antisymm _ Ideal.le_comap_map [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I ⊢ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) ≤ I [PROOFSTEP] refine' (fun a ha => _) [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I a : R ha : a ∈ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) ⊢ a ∈ I [PROOFSTEP] obtain ⟨⟨b, s⟩, h⟩ := (mem_map_algebraMap_iff M S).1 (Ideal.mem_comap.1 ha) [GOAL] case intro.mk R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I a : R ha : a ∈ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) b : { x // x ∈ I } s : { x // x ∈ M } h : ↑(algebraMap R S) a * ↑(algebraMap R S) ↑(b, s).snd = ↑(algebraMap R S) ↑(b, s).fst ⊢ a ∈ I [PROOFSTEP] replace h : algebraMap R S (s * a) = algebraMap R S b := by simpa only [← map_mul, mul_comm] using h [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I a : R ha : a ∈ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) b : { x // x ∈ I } s : { x // x ∈ M } h : ↑(algebraMap R S) a * ↑(algebraMap R S) ↑(b, s).snd = ↑(algebraMap R S) ↑(b, s).fst ⊢ ↑(algebraMap R S) (↑s * a) = ↑(algebraMap R S) ↑b [PROOFSTEP] simpa only [← map_mul, mul_comm] using h [GOAL] case intro.mk R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I a : R ha : a ∈ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) b : { x // x ∈ I } s : { x // x ∈ M } h : ↑(algebraMap R S) (↑s * a) = ↑(algebraMap R S) ↑b ⊢ a ∈ I [PROOFSTEP] obtain ⟨c, hc⟩ := (eq_iff_exists M S).1 h [GOAL] case intro.mk.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I a : R ha : a ∈ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) b : { x // x ∈ I } s : { x // x ∈ M } h : ↑(algebraMap R S) (↑s * a) = ↑(algebraMap R S) ↑b c : { x // x ∈ M } hc : ↑c * (↑s * a) = ↑c * ↑b ⊢ a ∈ I [PROOFSTEP] have : ↑c * ↑s * a ∈ I := by rw [mul_assoc, hc] exact I.mul_mem_left c b.2 [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I a : R ha : a ∈ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) b : { x // x ∈ I } s : { x // x ∈ M } h : ↑(algebraMap R S) (↑s * a) = ↑(algebraMap R S) ↑b c : { x // x ∈ M } hc : ↑c * (↑s * a) = ↑c * ↑b ⊢ ↑c * ↑s * a ∈ I [PROOFSTEP] rw [mul_assoc, hc] [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I a : R ha : a ∈ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) b : { x // x ∈ I } s : { x // x ∈ M } h : ↑(algebraMap R S) (↑s * a) = ↑(algebraMap R S) ↑b c : { x // x ∈ M } hc : ↑c * (↑s * a) = ↑c * ↑b ⊢ ↑c * ↑b ∈ I [PROOFSTEP] exact I.mul_mem_left c b.2 [GOAL] case intro.mk.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hI : Ideal.IsPrime I hM : Disjoint ↑M ↑I a : R ha : a ∈ Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) b : { x // x ∈ I } s : { x // x ∈ M } h : ↑(algebraMap R S) (↑s * a) = ↑(algebraMap R S) ↑b c : { x // x ∈ M } hc : ↑c * (↑s * a) = ↑c * ↑b this : ↑c * ↑s * a ∈ I ⊢ a ∈ I [PROOFSTEP] exact (hI.mem_or_mem this).resolve_left fun hsc => hM.le_bot ⟨(c * s).2, hsc⟩ [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S ⊢ ∀ {a b : Ideal S}, ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } a ≤ ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } b ↔ a ≤ b [PROOFSTEP] rintro J₁ J₂ [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J₁ J₂ : Ideal S ⊢ ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } J₁ ≤ ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } J₂ ↔ J₁ ≤ J₂ [PROOFSTEP] constructor [GOAL] case mp R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J₁ J₂ : Ideal S ⊢ ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } J₁ ≤ ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } J₂ → J₁ ≤ J₂ case mpr R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J₁ J₂ : Ideal S ⊢ J₁ ≤ J₂ → ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } J₁ ≤ ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } J₂ [PROOFSTEP] exact (fun hJ => (map_comap M S) J₁ ▸ (map_comap M S) J₂ ▸ Ideal.map_mono hJ) [GOAL] case mpr R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J₁ J₂ : Ideal S ⊢ J₁ ≤ J₂ → ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } J₁ ≤ ↑{ toFun := fun J => Ideal.comap (algebraMap R S) J, inj' := (_ : Function.Injective fun J => Ideal.comap (algebraMap R S) J) } J₂ [PROOFSTEP] exact (fun hJ => Ideal.comap_mono hJ) [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S ⊢ Ideal.IsPrime J ↔ Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) [PROOFSTEP] constructor [GOAL] case mp R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S ⊢ Ideal.IsPrime J → Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) [PROOFSTEP] refine' fun h => ⟨⟨_, _⟩, Set.disjoint_left.mpr fun m hm1 hm2 => h.ne_top (Ideal.eq_top_of_isUnit_mem _ hm2 (map_units S ⟨m, hm1⟩))⟩ [GOAL] case mp.refine'_1 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime J ⊢ Ideal.comap (algebraMap R S) J ≠ ⊤ [PROOFSTEP] refine' fun hJ => h.ne_top _ [GOAL] case mp.refine'_1 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime J hJ : Ideal.comap (algebraMap R S) J = ⊤ ⊢ J = ⊤ [PROOFSTEP] rw [eq_top_iff, ← (orderEmbedding M S).le_iff_le] [GOAL] case mp.refine'_1 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime J hJ : Ideal.comap (algebraMap R S) J = ⊤ ⊢ ↑(orderEmbedding M S) ⊤ ≤ ↑(orderEmbedding M S) J [PROOFSTEP] exact le_of_eq hJ.symm [GOAL] case mp.refine'_2 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime J ⊢ ∀ {x y : R}, x * y ∈ Ideal.comap (algebraMap R S) J → x ∈ Ideal.comap (algebraMap R S) J ∨ y ∈ Ideal.comap (algebraMap R S) J [PROOFSTEP] intro x y hxy [GOAL] case mp.refine'_2 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime J x y : R hxy : x * y ∈ Ideal.comap (algebraMap R S) J ⊢ x ∈ Ideal.comap (algebraMap R S) J ∨ y ∈ Ideal.comap (algebraMap R S) J [PROOFSTEP] rw [Ideal.mem_comap, RingHom.map_mul] at hxy [GOAL] case mp.refine'_2 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime J x y : R hxy : ↑(algebraMap R S) x * ↑(algebraMap R S) y ∈ J ⊢ x ∈ Ideal.comap (algebraMap R S) J ∨ y ∈ Ideal.comap (algebraMap R S) J [PROOFSTEP] exact h.mem_or_mem hxy [GOAL] case mpr R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S ⊢ Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) → Ideal.IsPrime J [PROOFSTEP] refine' fun h => ⟨fun hJ => h.left.ne_top (eq_top_iff.2 _), _⟩ [GOAL] case mpr.refine'_1 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) hJ : J = ⊤ ⊢ ⊤ ≤ Ideal.comap (algebraMap R S) J [PROOFSTEP] rwa [eq_top_iff, ← (orderEmbedding M S).le_iff_le] at hJ [GOAL] case mpr.refine'_2 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) ⊢ ∀ {x y : S}, x * y ∈ J → x ∈ J ∨ y ∈ J [PROOFSTEP] intro x y hxy [GOAL] case mpr.refine'_2 R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) x y : S hxy : x * y ∈ J ⊢ x ∈ J ∨ y ∈ J [PROOFSTEP] obtain ⟨a, s, ha⟩ := mk'_surjective M x [GOAL] case mpr.refine'_2.intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) x y : S hxy : x * y ∈ J a : R s : { x // x ∈ M } ha : mk' S a s = x ⊢ x ∈ J ∨ y ∈ J [PROOFSTEP] obtain ⟨b, t, hb⟩ := mk'_surjective M y [GOAL] case mpr.refine'_2.intro.intro.intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) x y : S hxy : x * y ∈ J a : R s : { x // x ∈ M } ha : mk' S a s = x b : R t : { x // x ∈ M } hb : mk' S b t = y ⊢ x ∈ J ∨ y ∈ J [PROOFSTEP] have : mk' S (a * b) (s * t) ∈ J := by rwa [mk'_mul, ha, hb] [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) x y : S hxy : x * y ∈ J a : R s : { x // x ∈ M } ha : mk' S a s = x b : R t : { x // x ∈ M } hb : mk' S b t = y ⊢ mk' S (a * b) (s * t) ∈ J [PROOFSTEP] rwa [mk'_mul, ha, hb] [GOAL] case mpr.refine'_2.intro.intro.intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) x y : S hxy : x * y ∈ J a : R s : { x // x ∈ M } ha : mk' S a s = x b : R t : { x // x ∈ M } hb : mk' S b t = y this : mk' S (a * b) (s * t) ∈ J ⊢ x ∈ J ∨ y ∈ J [PROOFSTEP] rw [mk'_mem_iff, ← Ideal.mem_comap] at this [GOAL] case mpr.refine'_2.intro.intro.intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) x y : S hxy : x * y ∈ J a : R s : { x // x ∈ M } ha : mk' S a s = x b : R t : { x // x ∈ M } hb : mk' S b t = y this : a * b ∈ Ideal.comap (algebraMap R S) J ⊢ x ∈ J ∨ y ∈ J [PROOFSTEP] have this₂ := (h.1).mul_mem_iff_mem_or_mem.1 this [GOAL] case mpr.refine'_2.intro.intro.intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) x y : S hxy : x * y ∈ J a : R s : { x // x ∈ M } ha : mk' S a s = x b : R t : { x // x ∈ M } hb : mk' S b t = y this : a * b ∈ Ideal.comap (algebraMap R S) J this₂ : a ∈ Ideal.comap (algebraMap R S) J ∨ b ∈ Ideal.comap (algebraMap R S) J ⊢ x ∈ J ∨ y ∈ J [PROOFSTEP] rw [Ideal.mem_comap, Ideal.mem_comap] at this₂ [GOAL] case mpr.refine'_2.intro.intro.intro.intro R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S J : Ideal S h : Ideal.IsPrime (Ideal.comap (algebraMap R S) J) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) J) x y : S hxy : x * y ∈ J a : R s : { x // x ∈ M } ha : mk' S a s = x b : R t : { x // x ∈ M } hb : mk' S b t = y this : a * b ∈ Ideal.comap (algebraMap R S) J this₂ : ↑(algebraMap R S) a ∈ J ∨ ↑(algebraMap R S) b ∈ J ⊢ x ∈ J ∨ y ∈ J [PROOFSTEP] rwa [← ha, ← hb, mk'_mem_iff, mk'_mem_iff] [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hp : Ideal.IsPrime I hd : Disjoint ↑M ↑I ⊢ Ideal.IsPrime (Ideal.map (algebraMap R S) I) [PROOFSTEP] rw [isPrime_iff_isPrime_disjoint M S, comap_map_of_isPrime_disjoint M S I hp hd] [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I : Ideal R hp : Ideal.IsPrime I hd : Disjoint ↑M ↑I ⊢ Ideal.IsPrime I ∧ Disjoint ↑M ↑I [PROOFSTEP] exact ⟨hp, hd⟩ [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S ⊢ ∀ {a b : { p // Ideal.IsPrime p }}, ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } a ≤ ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } b ↔ a ≤ b [PROOFSTEP] rintro I I' [GOAL] R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I I' : { p // Ideal.IsPrime p } ⊢ ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } I ≤ ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } I' ↔ I ≤ I' [PROOFSTEP] constructor [GOAL] case mp R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I I' : { p // Ideal.IsPrime p } ⊢ ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } I ≤ ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } I' → I ≤ I' case mpr R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I I' : { p // Ideal.IsPrime p } ⊢ I ≤ I' → ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } I ≤ ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } I' [PROOFSTEP] exact (fun h => show I.val ≤ I'.val from map_comap M S I.val ▸ map_comap M S I'.val ▸ Ideal.map_mono h) [GOAL] case mpr R : Type u_1 inst✝³ : CommSemiring R M : Submonoid R S : Type u_2 inst✝² : CommSemiring S inst✝¹ : Algebra R S inst✝ : IsLocalization M S I I' : { p // Ideal.IsPrime p } ⊢ I ≤ I' → ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } I ≤ ↑{ toFun := fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }, invFun := fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }, left_inv := (_ : ∀ (J : { p // Ideal.IsPrime p }), (fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) J) = J), right_inv := (_ : ∀ (I : { p // Ideal.IsPrime p ∧ Disjoint ↑M ↑p }), (fun p => { val := Ideal.comap (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.comap (algebraMap R S) ↑p) ∧ Disjoint ↑M ↑(Ideal.comap (algebraMap R S) ↑p)) }) ((fun p => { val := Ideal.map (algebraMap R S) ↑p, property := (_ : Ideal.IsPrime (Ideal.map (algebraMap R S) ↑p)) }) I) = I) } I' [PROOFSTEP] exact (fun h x hx => h hx) [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) ⊢ Function.Surjective ↑(Ideal.quotientMap I (algebraMap R S) H) [PROOFSTEP] intro s [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) s : S ⧸ I ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = s [PROOFSTEP] obtain ⟨s, rfl⟩ := Ideal.Quotient.mk_surjective s [GOAL] case intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) s : S ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = ↑(Ideal.Quotient.mk I) s [PROOFSTEP] obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M s [GOAL] case intro.intro.intro.mk R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] by_cases hM : (Ideal.Quotient.mk (I.comap (algebraMap R S))) m = 0 [GOAL] case pos R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] have : I = ⊤ := by rw [Ideal.eq_top_iff_one] rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_comap] at hM convert I.mul_mem_right (mk' S (1 : R) ⟨m, hm⟩) hM rw [← mk'_eq_mul_mk'_one, mk'_self] [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 ⊢ I = ⊤ [PROOFSTEP] rw [Ideal.eq_top_iff_one] [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 ⊢ 1 ∈ I [PROOFSTEP] rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_comap] at hM [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ↑(algebraMap R S) m ∈ I ⊢ 1 ∈ I [PROOFSTEP] convert I.mul_mem_right (mk' S (1 : R) ⟨m, hm⟩) hM [GOAL] case h.e'_4 R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ↑(algebraMap R S) m ∈ I ⊢ 1 = ↑(algebraMap R S) m * mk' S 1 { val := m, property := hm } [PROOFSTEP] rw [← mk'_eq_mul_mk'_one, mk'_self] [GOAL] case pos R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 this : I = ⊤ ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] exact ⟨0, eq_comm.1 (by simp [Ideal.Quotient.eq_zero_iff_mem, this])⟩ [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 this : I = ⊤ ⊢ ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) = ↑(Ideal.quotientMap I (algebraMap R S) H) 0 [PROOFSTEP] simp [Ideal.Quotient.eq_zero_iff_mem, this] [GOAL] case neg R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : Ideal.IsMaximal (Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] rw [Ideal.Quotient.maximal_ideal_iff_isField_quotient] at hI [GOAL] case neg R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] obtain ⟨n, hn⟩ := hI.3 hM [GOAL] case neg.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 n : R ⧸ Ideal.comap (algebraMap R S) I hn : ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m * n = 1 ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] obtain ⟨rn, rfl⟩ := Ideal.Quotient.mk_surjective n [GOAL] case neg.intro.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 rn : R hn : ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m * ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) rn = 1 ⊢ ∃ a, ↑(Ideal.quotientMap I (algebraMap R S) H) a = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] refine' ⟨(Ideal.Quotient.mk J) (r * rn), _⟩ -- The rest of the proof is essentially just algebraic manipulations to prove the equality [GOAL] case neg.intro.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 rn : R hn : ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m * ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) rn = 1 ⊢ ↑(Ideal.quotientMap I (algebraMap R S) H) (↑(Ideal.Quotient.mk J) (r * rn)) = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] replace hn := congr_arg (Ideal.quotientMap I (algebraMap R S) le_rfl) hn [GOAL] case neg.intro.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 rn : R hn : ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m * ↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) rn) = ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) 1 ⊢ ↑(Ideal.quotientMap I (algebraMap R S) H) (↑(Ideal.Quotient.mk J) (r * rn)) = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] rw [RingHom.map_one, RingHom.map_mul] at hn [GOAL] case neg.intro.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 rn : R hn : ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m) * ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) rn) = 1 ⊢ ↑(Ideal.quotientMap I (algebraMap R S) H) (↑(Ideal.Quotient.mk J) (r * rn)) = ↑(Ideal.Quotient.mk I) (mk' S r { val := m, property := hm }) [PROOFSTEP] rw [Ideal.quotientMap_mk, ← sub_eq_zero, ← RingHom.map_sub, Ideal.Quotient.eq_zero_iff_mem, ← Ideal.Quotient.eq_zero_iff_mem, RingHom.map_sub, sub_eq_zero, mk'_eq_mul_mk'_one] [GOAL] case neg.intro.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 rn : R hn : ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m) * ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) rn) = 1 ⊢ ↑(Ideal.Quotient.mk I) (↑(algebraMap R S) (r * rn)) = ↑(Ideal.Quotient.mk I) (↑(algebraMap R S) r * mk' S 1 { val := m, property := hm }) [PROOFSTEP] simp only [mul_eq_mul_left_iff, RingHom.map_mul] [GOAL] case neg.intro.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 rn : R hn : ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m) * ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) rn) = 1 ⊢ ↑(Ideal.Quotient.mk I) (↑(algebraMap R S) rn) = ↑(Ideal.Quotient.mk I) (mk' S 1 { val := m, property := hm }) ∨ ↑(Ideal.Quotient.mk I) (↑(algebraMap R S) r) = 0 [PROOFSTEP] refine Or.inl (mul_left_cancel₀ (M₀ := S ⧸ I) (fun hn => hM (Ideal.Quotient.eq_zero_iff_mem.2 (Ideal.mem_comap.2 (Ideal.Quotient.eq_zero_iff_mem.1 hn)))) (_root_.trans hn ?_)) -- Porting note: was `rw`, but this took extremely long. [GOAL] case neg.intro.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 rn : R hn : ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m) * ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) rn) = 1 ⊢ 1 = ↑(Ideal.Quotient.mk I) (↑(algebraMap R S) m) * ↑(Ideal.Quotient.mk I) (mk' S 1 { val := m, property := hm }) [PROOFSTEP] refine Eq.trans ?_ (RingHom.map_mul (Ideal.Quotient.mk I) (algebraMap R S m) (mk' S 1 ⟨m, hm⟩)) [GOAL] case neg.intro.intro R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S I : Ideal S inst✝ : Ideal.IsPrime I J : Ideal R H : J ≤ Ideal.comap (algebraMap R S) I hI : IsField (R ⧸ Ideal.comap (algebraMap R S) I) r m : R hm : m ∈ M hM : ¬↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m = 0 rn : R hn : ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) m) * ↑(Ideal.quotientMap I (algebraMap R S) (_ : Ideal.comap (algebraMap R S) I ≤ Ideal.comap (algebraMap R S) I)) (↑(Ideal.Quotient.mk (Ideal.comap (algebraMap R S) I)) rn) = 1 ⊢ 1 = ↑(Ideal.Quotient.mk I) (↑(algebraMap R S) m * mk' S 1 { val := m, property := hm }) [PROOFSTEP] rw [← mk'_eq_mul_mk'_one, mk'_self, RingHom.map_one] [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S inst✝ : IsDomain R hM : M ≤ R⁰ p : Ideal S hpp : Ideal.IsPrime p hp0 : p ≠ ⊥ ⊢ ⊥ < Ideal.comap (algebraMap R S) p [PROOFSTEP] haveI : IsDomain S := isDomain_of_le_nonZeroDivisors _ hM [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S inst✝ : IsDomain R hM : M ≤ R⁰ p : Ideal S hpp : Ideal.IsPrime p hp0 : p ≠ ⊥ this : IsDomain S ⊢ ⊥ < Ideal.comap (algebraMap R S) p [PROOFSTEP] rw [← Ideal.comap_bot_of_injective (algebraMap R S) (IsLocalization.injective _ hM)] [GOAL] R : Type u_1 inst✝⁴ : CommRing R M : Submonoid R S : Type u_2 inst✝³ : CommRing S inst✝² : Algebra R S inst✝¹ : IsLocalization M S inst✝ : IsDomain R hM : M ≤ R⁰ p : Ideal S hpp : Ideal.IsPrime p hp0 : p ≠ ⊥ this : IsDomain S ⊢ Ideal.comap (algebraMap R S) ⊥ < Ideal.comap (algebraMap R S) p [PROOFSTEP] convert (orderIsoOfPrime M S).lt_iff_lt.mpr (show (⟨⊥, Ideal.bot_prime⟩ : { p : Ideal S // p.IsPrime }) < ⟨p, hpp⟩ from hp0.bot_lt)
Require Import ssreflect. Set Implicit Arguments. Unset Strict Implicit. Import Prenex Implicits. Lemma plusn0 n : n + 0 = n. Proof. case: n. - done. (* forall n : nat, S n + 0 = S n *) Restart. move: n. (**) Check nat_ind : forall P : nat -> Prop, P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n. (**) apply: nat_ind. (* elim の意味*) - done. (* forall n : nat, n + 0 = n -> S n + 0 = S n *) (* - move=> n. rewrite /=. move=> ->. rewrite //. *) - move=> n /= -> //. Qed. (* 偶数の定義*) Inductive even : nat -> Prop := | even_O : even O | even_SS : forall n, even n -> even (S (S n)). (* 帰納的述語を証明する定理*) Theorem even_double n : even (n + n). Proof. elim: n => /= [|n IH]. - apply: even_O. - rewrite -plus_n_Sm. by apply: even_SS. Qed. (* 帰納的述語に対する帰納法もできる*) Theorem even_plus m n : even m -> even n -> even (m + n). Proof. elim: m => //=. Restart. move=> Hm Hn. elim: Hm => //= m' m'' IH. by apply: even_SS. Qed. (* 矛盾を導き出す*) Theorem one_not_even : ~ even 1. Proof. case. Restart. move H: 1 => one He. (* move H: exp => pat はH: exp = pat を作る*) case: He H => //. Restart. move=> He. inversion He. Show Proof. (* 証明が複雑で、SSReflect では様々な理由で避ける*) Qed. (* 等式を導き出す*) Theorem eq_pred m n : S m = S n -> m = n. Proof. case. (* 等式を分解する*) done. Qed. Theorem contradict (P Q : Prop) : P -> ~P -> Q. Proof. move=> p. elim. exact: p. Qed. Module Odd. Inductive odd : nat -> Prop := | odd_1 : odd 1 | odd_SS : forall n, odd n -> odd (S (S n)). Theorem even_odd n : even n -> odd (S n). Proof. Check even_ind : forall P : nat -> Prop, P 0 -> (forall n : nat, even n -> P n -> P (S (S n))) -> forall n : nat, even n -> P n. Check (fun n => odd (S n)) : nat -> Prop. Check (@even_ind (fun n => odd (S n))) : odd 1 (* ★1 *) -> (forall n : nat, even n -> odd (S n) -> odd (S (S (S n)))) (* ★2 *) -> forall n : nat, even n -> odd (S n) (* ★3 *). apply: (@even_ind (fun n => odd (S n))). - (* 結果的に★1の命題を証明することになる模様。 *) by apply: odd_1. - (* 結果的に★2の命題を証明することになるらしい。 *) move=> n' Hevnn' HoddSn'. by apply: odd_SS. Restart. elim. (* 焦点の命題 even n (帰納的述語というらしい)についての帰納法 こうすることにより、apply: (@even_ind (fun n => odd (S n))). を行っている模様。 これにより、初期のゴールが証明され、代わりに2つの前提条件を証明することになる模様。 (ここで、elim: n. とするとハマるので注意!) *) - (* 結果的に★1の命題を証明することになる模様。 *) by apply: odd_1. - (* 結果的に★2の命題を証明することになるらしい。 *) move=> n' Hevnn' HoddSn'. by apply: odd_SS. Qed. Theorem odd_even n : odd n -> even (S n). Proof. Check (@odd_ind (fun n => even (S n))) : even 2 (* ★1 *) -> (forall n : nat, odd n -> even (S n) -> even (S (S (S n)))) (* ★2 *) -> forall n : nat, odd n -> even (S n) (* ★3 *). elim. - (* ★1 *) by apply: (even_SS even_O). - (* ★2 *) move=> n' Hoddn' HevnSn'. by apply: even_SS. Qed. Theorem even_not_odd n : even n -> ~odd n. Proof. Check (@nat_ind (fun n => even n -> ~odd n)) : (even 0 -> ~ odd 0) (* ★1 *) -> (forall n : nat, (even n -> ~ odd n) -> even (S n) -> ~ odd (S n)) (* ★2 *) -> forall n : nat, even n -> ~ odd n (* ★3 *). elim: n. - (* ★1 *) move=> HevnO. by move/odd_even/one_not_even. - (* ★2 *) move=> n IHn HevnSn HoddSn. inversion HoddSn. (* SSReflectでは使用を避けないといけないタクティクを使ってしまった... *) + (* n = 0 *) rewrite -H0 in HevnSn. by move: one_not_even. + (* n > 0 *) apply odd_even in H0. rewrite H in H0. apply IHn in H0. (* inversion タクティクを使っても手詰まりになってきた... *) Restart. Check (@even_ind (fun n => ~odd n)) : ~ odd 0 (* ★1 *) -> (forall n : nat, even n -> ~ odd n -> ~ odd (S (S n))) (* ★2 *) -> forall n : nat, even n -> ~ odd n (* ★3 *). elim. - (* ★1 *) move/odd_even. by move: one_not_even. - (* ★2 *) move=> n' Hevnn' Hnoddn' HoddSSn'. inversion HoddSSn'. (* SSReflectでは使用を避けないといけないタクティクを使ってしまった... *) easy. (* 結果的に、この定理も elim: n. とするとハマるパターンの模様。 *) Qed. End Odd. Section SystemF. Definition Fand P Q := forall X : Prop, (P -> Q -> X) -> X. Definition For P Q := forall X : Prop, (P -> X) -> (Q -> X) -> X. (* andに見えるけどandではない。 *) Definition Ffalse := forall X : Prop, X. (* 何も証明を返さない *) Definition Ftrue := forall X : Prop, (X -> X). (* トートロジー、証明できるなら証明を返す *) Definition Feq T (x y : T) := forall P, P x <-> P y. (* ライプニッツの等式 *) Definition Fex T (P : T -> Prop) := forall X : Prop, (forall x, P x -> X) -> X. Theorem Fand_ok (P Q : Prop) : Fand P Q <-> P /\ Q. Proof. split => [pq | [p q] X]. - split; by apply: pq. - by apply. Qed. (* 練習問題 *) Theorem For_ok (P Q : Prop) : For P Q <-> P \/ Q. Proof. split. - (* For P Q -> P \/ Q の証明 *) apply => [Hp | Hq]. + (* Pが成り立つ場合 *) by left. + (* Qが成り立つ場合 *) by right. - (* For P Q <- P \/ Q の証明 *) case => [Hp | Hq] X Hpx Hqx. + (* Pが成り立つ場合 *) by apply: Hpx. + (* Qが成り立つ場合 *) by apply: Hqx. Qed. (* 練習問題 *) Theorem Ffalse_ok : Ffalse <-> False. Proof. split. - apply. (* これで1個目のゴールは消える。 *) - done. (* 2個目のゴールは自明。 *) (* split; last done. rewrite /Ffalse. by apply. *) Qed. (* 練習問題 *) Theorem Ftrue_ok : Ftrue <-> True. Proof. split. - by apply. - move=> _ X. by apply. (* split; first done. (* apply. move=> _. rewrite /Ftrue. move=> X. apply. *) by move=> _. *) Qed. (* SystemF は、古典論理ではなく、直観論理である点に注意 *) (* 練習問題 *) Theorem Feq_ok T (x y : T) : Feq x y <-> x = y. Proof. split. - (* Feq x y -> x = y の証明 *) (* rewrite /Feq. 1 subgoal T : Type x, y : T ______________________________________(1/1) (forall P : T -> Prop, P x <-> P y) -> x = y 1 subgoal T : Type x, y : T ______________________________________(1/1) forall _ : forall P : forall _ : T, Prop, iff (P x) (P y), eq x y Print eq. (* Inductive eq (A : Type) (x : A) : A -> Prop := eq_refl : x = x *) Print iff. (* iff = fun A B : Prop => (A -> B) /\ (B -> A) : Prop -> Prop -> Prop *) *) move=> H. Check eq. Check eq x : T -> Prop. Check eq y : T -> Prop. Check H (eq x) : x = x <-> x = y. Check H (eq y) : y = x <-> y = y. move: (H (eq x)) => H_. (* ゴールが同値の場合はsplit、前提が同値の場合はcaseもしくはapply/ *) (* 場合1 *) case: H_ => H1 H2. by apply: H1. (* 場合2 apply/H_. done. *) (* more: (H (eq x)) => [H' H'']. by apply: H'. *) - (* Feq x y <- x = y の証明 *) (* move=> ->. rewrite /Feq. done. *) by move=> ->. Qed. (* 練習問題 *) Theorem Fex_ok T (P : T -> Prop) : Fex P <-> exists x, P x. Proof. split. rewrite /Fex. - (* Fex P -> exists x, P x の証明 *) apply. move=> x Hpx. by exists x. - (* Fex P <- exists x, P x の証明 *) case. move=> x Hpx X H. by apply: (H x). Qed. Definition Nat := forall X : Prop, (X -> X) -> X -> X. Definition Zero : Nat := fun X f x => x. Definition Succ (N : Nat) : Nat := fun X f x => f (N X f x). Definition Plus (M N : Nat) : Nat := fun X f x => M X f (N X f x). Definition Mult (M N : Nat) : Nat := fun X f x => M X (N X f) x. (* 自己確認 ここから *) Check Succ : Nat -> Nat. Eval compute in (Succ Zero). (* = fun (X : Prop) (f : X -> X) (x : X) => f x : Nat *) Eval compute in (Succ (Succ Zero)). (* = fun (X : Prop) (f : X -> X) (x : X) => f (f x) : Nat *) (* 自己確認 ここまで *) (* こちらの定義はより直感的*) Definition Plus' (M N : Nat) : Nat := M Nat Succ N. (* 1 をM 回足す*) Definition Mult' (M N : Nat) : Nat := M Nat (Plus' N) Zero. (* N をM 回足す*) (* 自己確認 ここから *) Check Nat : Prop. Check (forall X : Prop, (X -> X) -> X -> X). (* これを M とすると... *) Check (forall Nat : Prop, (Nat -> Nat) -> Nat -> Nat). (* これが (M Nat) になると思われる。 *) Check Succ : Nat -> Nat. (* Plus' の場合、これが (M Nat) の第1引数になると思われる。 *) (* 自己確認 ここまで *) Fixpoint Nat_of_nat n : Nat := (* 自然数をNat に変換*) match n with 0 => Zero | S m => Succ (Nat_of_nat m) end. (* 自己確認 ここから *) Eval compute in Nat_of_nat 0. (* = fun (X : Prop) (_ : X -> X) (x : X) => x : Nat *) Eval compute in Nat_of_nat 1. (* = fun (X : Prop) (f : X -> X) (x : X) => f x : Nat *) Eval compute in Nat_of_nat 2. (* = fun (X : Prop) (f : X -> X) (x : X) => f (f x) : Nat *) (* 自己確認 ここまで *) (* Nat の元の等価性は適用された物を比較するべき*) Definition eq_Nat (M N : Nat) := forall X f x, M X f x = N X f x. Definition eq_Nat_fun F f := forall n, eq_Nat (F (Nat_of_nat n)) (Nat_of_nat (f n)). Definition eq_Nat_op Op op := forall m n, eq_Nat (Op (Nat_of_nat m) (Nat_of_nat n)) (Nat_of_nat (op m n)). Theorem Succ_ok : eq_Nat_fun Succ S. Proof. rewrite /eq_Nat_fun. (* 自己確認 ここから 1 subgoal ______________________________________(1/1) forall n : nat, eq_Nat (Succ (Nat_of_nat n)) (Nat_of_nat (S n)) elim. (* n に関する帰納法となる模様。 *) 2 subgoals ______________________________________(1/2) eq_Nat (Succ (Nat_of_nat 0)) (Nat_of_nat 1) ______________________________________(2/2) forall n : nat, eq_Nat (Succ (Nat_of_nat n)) (Nat_of_nat (S n)) -> eq_Nat (Succ (Nat_of_nat (S n))) (Nat_of_nat (S (S n))) Check nat_ind : forall P : nat -> Prop, P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n. Check (fun n => eq_Nat (Succ (Nat_of_nat n)) (Nat_of_nat (S n))) : nat -> Prop. Check (nat_ind (fun n => eq_Nat (Succ (Nat_of_nat n)) (Nat_of_nat (S n)))) : eq_Nat (Succ (Nat_of_nat 0)) (Nat_of_nat 1) (* ★1 *) -> (forall n : nat, eq_Nat (Succ (Nat_of_nat n)) (Nat_of_nat (S n)) -> eq_Nat (Succ (Nat_of_nat (S n))) (Nat_of_nat (S (S n)))) (* ★2 *) -> forall n : nat, eq_Nat (Succ (Nat_of_nat n)) (Nat_of_nat (S n)) (* ★3 *). 自己確認 ここまで *) elim. - (* n = 0 *) rewrite /Succ. rewrite /=. rewrite /Succ /Zero. done. - (* n > 0 *) move=> n IHn. rewrite /=. done. (* IHnを使わなくても証明できる模様。 *) Restart. by elim. Qed. (* 実は自明*) Theorem Plus_ok : eq_Nat_op Plus plus. Proof. rewrite /eq_Nat_op /Plus /eq_Nat. move=> m n X f x. elim: m x. - (* m = 0 *) move=> x. rewrite /=. rewrite /Zero. by []. - (* m > 0 *) move=> m IH x. rewrite /=. (* 自己確認 ここから by rewrite /Succ -IH. (* これだけで証明完了する模様。 *) 自己確認 ここまで *) (* 自己確認 ここから 1 subgoal n : nat X : Prop f : X -> X m : nat IH : forall x : X, Nat_of_nat m f (Nat_of_nat n f x) = Nat_of_nat (m + n) f x x : X ______________________________________(1/1) Succ (Nat_of_nat m) f (Nat_of_nat n f x) = Succ (Nat_of_nat (m + n)) f x Check Succ_ok : eq_Nat_fun Succ S. (* Succ_ok の中身。 *) eq_Nat_fun = (* 関数を2つもらって、命題を返す関数らしい。 *) fun (F : Nat -> Nat) (f : nat -> nat) => forall n : nat, eq_Nat (F (Nat_of_nat n)) (Nat_of_nat (f n)) : (Nat -> Nat) -> (nat -> nat) -> Prop eq_Nat_fun Succ S = (* 関数 Succ と、関数 S を渡すと、命題が返る模様。 *) forall n : nat, eq_Nat (Succ (Nat_of_nat n)) (Nat_of_nat (S n)) : Prop 自己確認 ここまで *) rewrite Succ_ok. (* 左辺の Succ (Nat_of_nat m) ... を、Nat_of_nat (S m) ... に書き換える模様。 *) rewrite /=. (* これを行うと、直前で行った rewrite が元に戻ってしまう模様。 *) rewrite [in RHS]/Succ. rewrite -IH. (* 自己確認 ここから rewrite /Succ. (* こうしてみると、左辺と右辺が等しいことが自分にもわかる。 *) 自己確認 ここまで *) by []. Restart. move=> m n X f x. elim: m x => //= m IH x. by rewrite Succ_ok /= [in RHS]/Succ -IH. Qed. Theorem Mult_ok : eq_Nat_op Mult mult. Proof. rewrite /eq_Nat_op /Mult /eq_Nat. (* これは蛇足だが、自分にとっては必要。 *) move=> m n X f x. elim: m x => //= m IH x. rewrite Succ_ok. Check Plus_ok : eq_Nat_op Plus Nat.add. rewrite -[in RHS]Plus_ok. rewrite /Plus. rewrite -IH. rewrite /=. Check Succ. rewrite /Succ. done. Restart. move=> m n X f x. elim: m x => //= m IH x. by rewrite -[in RHS]Plus_ok /Plus -IH. Qed. Definition Pow (M N : Nat) := fun X => N _ (M X). (* M のN 乗*) Fixpoint pow m n := match n with 0 => 1 | S n => m * pow m n end. (* 自己確認 ここから Eval compute in (Pow (Succ (Succ Zero)) (Succ (Succ (Succ Zero)))). (* = fun (X : Prop) (x : X -> X) (x0 : X) => x (x (x (x (x (x (x (x x0))))))) : forall X : Prop, (X -> X) -> X -> X Pow (Succ (Succ Zero)) (Succ (Succ (Succ Zero))) = fun X => (Succ (Succ (Succ Zero))) _ ((Succ (Succ Zero)) X) = fun X => (fun (X' : Prop) (x : X' -> X') (x0 : X') => x (x (x x0))) _ ((fun (X'' : Prop) (x : X'' -> X'') (x0 : X'') => x (x x0)) X) = fun X => (fun (X' : Prop) (x : X' -> X') (x0 : X') => x (x (x x0))) _ (fun (x : X -> X) (x0 : X) => x (x x0)) ここで、 fun (x : X -> X) (x0 : X) => x (x x0) を func2 とでもおいてみると... = fun X => (fun (x : _ -> _) (x0 : _) => x (x (x x0))) func2 = fun X => (fun (x0 : X) => func2 (func2 (func2 x0))) のようになって、x : X -> X を2回適用する関数を3回適用することになり、 2の3乗が求められるのだろうか? *) 自己確認 ここまで *) Lemma Nat_of_nat_eq : forall n X f1 f2 x, (forall y, f1 y = f2 y) -> @Nat_of_nat n X f1 x = @Nat_of_nat n X f2 x. Proof. move=> n X f1 f2 x H. elim: n. - (* n = 0 *) rewrite /=. rewrite /Zero. by []. - (* n > 0 *) move=> n IHn. rewrite /=. rewrite /Succ. rewrite IHn. by apply: H. Restart. move=> n X f1 f2 x H. elim: n => //= n IHn. by rewrite /Succ IHn H. Qed. Theorem Pow_ok : eq_Nat_op Pow pow. Proof. rewrite /eq_Nat_op => m n. rewrite /eq_Nat => X f x. elim: n x. - (* n = 0 *) rewrite /=. rewrite /Pow. rewrite /Succ. rewrite /Zero. done. - (* n > 0 *) move=> n IHn x. rewrite /=. rewrite -Mult_ok. rewrite /Mult. rewrite /Pow. rewrite /Succ. rewrite /Pow in IHn. apply: Nat_of_nat_eq => y. rewrite (IHn y). done. Restart. rewrite /eq_Nat_op => m n. rewrite /eq_Nat => X f x. elim: n x => //= n IHn x. rewrite /Pow in IHn. rewrite -Mult_ok /Mult /Pow /Succ. apply: Nat_of_nat_eq => y. by rewrite (IHn y). Qed. Section ProdSum. (* 値の対と直和も定義できます*) Variables X Y : Prop. Definition Prod := forall Z : Prop, (X -> Y -> Z) -> Z. Definition Pair (x : X) (y : Y) : Prod := fun Z f => f x y. Definition Fst (p : Prod) := p _ (fun x y => x). Definition Snd (p : Prod) := p _ (fun x y => y). Definition Sum := forall Z : Prop, (X -> Z) -> (Y -> Z) -> Z. Definition InL x : Sum := fun Z f g => f x. Definition InR x : Sum := fun Z f g => g x. End ProdSum. (* 自己確認 ここから *) Check Prod : (Prop -> Prop -> Prop). (* Variables X Y : Prop. Check Prod X Y : Prop. *) Check Pair : forall X Y : Prop, X -> Y -> Prod X Y. Check Fst : forall X Y : Prop, Prod X Y -> X. Check Snd : forall X Y : Prop, Prod X Y -> Y. Check Sum : (Prop -> Prop -> Prop). (* Variables X Y : Prop. Check Sum X Y : Prop. *) Check InL : forall X Y : Prop, X -> Sum X Y. Check InR : forall X Y : Prop, Y -> Sum X Y. (* 自己確認 ここまで *) Arguments Pair [X Y]. Arguments Fst [X Y]. Arguments Snd [X Y]. Arguments InL [X] Y. Arguments InR X [Y]. (* 型引数を省略できるようにする*) Definition Pred (N : Nat) := (* 前者関数の定義は工夫が必要*) Fst (N _ (fun p : Prod Nat Nat => Pair (Snd p) (Succ (Snd p))) (Pair Zero Zero)). (* 自己確認 ここから *) Check Pred : Nat -> Nat. Check (Pair Zero Zero) : Prod Nat Nat. Check (Snd (Pair Zero Zero)) : Nat. Check (Succ (Snd (Pair Zero Zero))) : Nat. Print Nat. (* Nat = forall X : Prop, (X -> X) -> X -> X : Prop *) Eval compute in Succ Zero. (* = fun (X : Prop) (f : X -> X) (x : X) => f x : Nat *) Eval compute in Succ (Succ Zero). (* = fun (X : Prop) (f : X -> X) (x : X) => f (f x) : Nat *) Eval compute in (Pred Zero). (* = fun (X : Prop) (_ : X -> X) (x : X) => x : Nat *) Eval compute in (pred 0). (* = 0 : nat *) Eval compute in (Pred (Succ Zero)). (* = fun (X : Prop) (_ : X -> X) (x : X) => x : Nat *) Eval compute in (pred (S 0)). (* = 0 : nat *) Eval compute in (Pred (Succ (Succ Zero))). (* = fun (X : Prop) (f : X -> X) (x : X) => f x : Nat *) Eval compute in (pred (S (S 0))). (* = 1 : nat *) (* 自己確認 ここまで *) Theorem Pred_ok : eq_Nat_fun Pred pred. Proof. rewrite /eq_Nat_fun => n. elim: n. - (* n = 0 *) rewrite /Pred. rewrite /=. rewrite {1}/Zero. rewrite /Fst /Pair. done. - (* n > 0 *) move=> n IHn. rewrite /=. Restart. (* ここから、須原さんの証明を真似してみたら、証明が完了した! 凄い! いきなり帰納法を適用するのではなく、下ごしらえしなければいけないのがわからなかった! しかも、Succの定義を展開して、相当複雑な形になったのに、IHnでrewriteできるなんて、 とても気づかない! *) case => //= n X f x. rewrite /Pred. elim: n => //= n IHn. rewrite /Succ. rewrite -IHn. done. Restart. case. (* nについての場合分けらしい。 *) - (* n = 0 *) rewrite /=. rewrite /Pred /Zero /=. rewrite /Pair /=. rewrite /Fst /=. (* ここまでくると、左辺と右辺が等しいことが自明になる。 *) done. - (* n > 0 *) rewrite /=. move=> n X f x. rewrite /Pred /=. elim: n. + (* n = 0 *) rewrite /=. rewrite /Fst /Succ /Zero /Prod /Pair /=. rewrite /Snd /=. (* ここまでくると、左辺と右辺が等しいことが自明になる。 *) done. + (* n > 0 *) rewrite /=. move=> n IHn. rewrite [RHS]/Succ. rewrite -IHn. (* 左辺と右辺が、かなりよく似た形になってきた模様。 *) rewrite /Fst /Succ /Prod /Snd /Pair /Zero /=. (* とても複雑な式だが、同じように見える。 *) done. Qed. (* NatをSetで定義し直したNat'を作る。 *) Definition Nat' := forall X : Set, (X -> X) -> X -> X. Check Nat' : Set. (* ZeroをNat'で定義し直したZero'を作る。 *) Definition Zero' : Nat' := fun X f x => x. Check Zero' : Nat'. (* SuccをNat'で定義し直したSucc'を作る。 *) Definition Succ' (N : Nat') : Nat' := fun X f x => f (N X f x). Check Succ' : Nat' -> Nat'. (* Nat_of_natをNat'で定義し直したNat_of_nat'を作る。 *) Fixpoint Nat_of_nat' n : Nat' := (* 自然数をNat に変換*) match n with 0 => Zero' | S m => Succ' (Nat_of_nat' m) end. (* Nat がSet で定義されているときだけ証明可能*) Lemma Nat_of_nat_ok : forall n, @Nat_of_nat' n _ S O = n. Proof. elim. - (* n = 0 *) rewrite /=. rewrite /Zero'. done. - (* n > 0 *) move=> n IHn. rewrite /=. rewrite /Succ'. rewrite IHn. done. Restart. elim => //= n IHn. by rewrite /Succ' IHn. Qed. End SystemF.
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ As an example, suppose that we want to add jumps to the noisy Lorenz oscillator from `example`. These shall have exponentially distributed waiting times (i.e. they are a Poisson process) with a scale parameter :math:`β=1.0`. A function sampling such waiting times (inter-jump intervals) is: .. literalinclude:: ../examples/noisy_and_jumpy_lorenz.py :dedent: 1 :lines: 49-50 Note that since our waiting times are neither state- nor time-dependent, we do not use the `time` and `state` argument. Next, we want the jumps to only apply to the last component, being normally distributed with zero mean and the current amplitude of this component as a standard deviation. A function producing such a jump is: .. literalinclude:: ../examples/noisy_and_jumpy_lorenz.py :dedent: 1 :lines: 52-57 Finally, we initialise the integrator using `jitcsde_jump` instead of `jitcsde` with the previously defined functions as additional arguments: .. literalinclude:: ../examples/noisy_and_jumpy_lorenz.py :dedent: 1 :lines: 59 Everything else remains unchanged. See `the sources <https://raw.githubusercontent.com/neurophysik/jitcsde/master/examples/noisy_and_jumpy_lorenz.py>`_ for the full example. """ if __name__ == "__main__": from jitcsde import y, jitcsde_jump import numpy import symengine ρ = 28 σ = 10 β = symengine.Rational(8,3) p = 0.1 f = [ σ * (y(1)-y(0)), y(0)*(ρ-y(2)) - y(1), y(0)*y(1) - β*y(2) ] g = [ p*y(i) for i in range(3) ] def IJI(time,state): return numpy.random.exponential(1.0) def jump(time,state): return numpy.array([ 0.0, 0.0, numpy.random.normal(0.0,abs(state[2])) ]) SDE = jitcsde_jump(IJI,jump,f,g) initial_state = numpy.random.random(3) SDE.set_initial_value(initial_state,0.0) data = [] for time in numpy.arange(0.0, 100.0, 0.01): data.append( SDE.integrate(time) ) numpy.savetxt("timeseries.dat", data)
import Data.List import Data.List1 import Data.String import System.File cost : Nat -> Nat cost 0 = 0 cost n@(S k) = n + cost k fuel : List Nat -> Nat -> Nat fuel [] y = 0 fuel (x :: xs) y = (cost (if x > y then minus x y else minus y x)) + fuel xs y upTo : Nat -> List Nat upTo 0 = 0 :: [] upTo (S k) = S k :: upTo k run : String -> IO () run s = do let l = catMaybes $ parsePositive {a=Nat} <$> (forget $ split (== ',') s) Just u <- pure $ head' $ reverse $ (\(c ::: _) => c) <$> (group $ sort $ l) | Nothing => putStrLn "no upper bound" let fs = head' $ sort $ fuel l <$> (upTo u) putStrLn $ show fs main : IO () main = do Right s <- readFile "input.txt" | Left err => putStrLn $ show err run s
import tactic import ssyt /- Defining "inverse_row_bump_step": one step of inverse row insertion Given an ssyt T and natural numbers i, k, we "inverse bump" k into row i while preserving semistandardness. In particular k goes before any existing k's and replaces the rightmost smaller entry. (It is necessary that there exist an entry smaller than k in row i.) An assumption is necessary (to preserve column strictness) for this to be legal. [ssyt.irbs_cert] [ssyt.irbs_cert.legal_of_cert] The bump position is defined using finset.max'. [ssyt.irbc] The bump itself uses ssyt.legal.replace. [ssyt.irbs] -/ section inverse_row_bump_column def ssyt.irbc_strip {μ : young_diagram} (T : ssyt μ) (i val : ℕ) : finset ℕ := ((finset.range $ μ.row_len i).filter (λ j, T i j < val)) lemma ssyt.irbc_strip_mem {μ : young_diagram} (T : ssyt μ) {i val j : ℕ} : j ∈ T.irbc_strip i val ↔ (i, j) ∈ μ ∧ T i j < val := by rw [ssyt.irbc_strip, finset.mem_filter, finset.mem_range, μ.mem_row_iff'] lemma ssyt.irbc_aux {μ : young_diagram} (T : ssyt μ) {i val : ℕ} : (T.irbc_strip i val).nonempty ↔ ∃ j, (i, j) ∈ μ ∧ T i j < val := begin simp_rw ← T.irbc_strip_mem, refl, end def ssyt.irbc {μ : young_diagram} (T : ssyt μ) {i val : ℕ} (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) : ℕ := finset.max' _ $ T.irbc_aux.mpr exists_lt lemma ssyt.irbc_cell_and_lt_val {μ : young_diagram} (T : ssyt μ) {i val : ℕ} (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) : (i, T.irbc exists_lt) ∈ μ ∧ T i (T.irbc exists_lt) < val := begin rw ← T.irbc_strip_mem, apply finset.max'_mem, end lemma ssyt.irbc_lt_iff {μ : young_diagram} (T : ssyt μ) {i val : ℕ} (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) (j : ℕ) : T.irbc exists_lt < j ↔ (i, j) ∈ μ → val ≤ T i j := begin simp_rw [ssyt.irbc, finset.max'_lt_iff, ssyt.irbc_strip_mem], rw ← not_iff_not, push_neg, split, rintro ⟨j', ⟨cell', hj'⟩, hj''⟩, exact ⟨μ.nw_of (by refl) hj'' cell', lt_of_le_of_lt (T.row_weak' hj'' cell') hj'⟩, intro hj, exact ⟨j, hj, by refl⟩, end lemma ssyt.le_irbc_iff {μ : young_diagram} (T : ssyt μ) {i val : ℕ} (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) (j : ℕ) : j ≤ T.irbc exists_lt ↔ (i, j) ∈ μ ∧ T i j < val := begin rw [← not_iff_not], push_neg, rw ssyt.irbc_lt_iff, end lemma ssyt.irbc_le_iff {μ : young_diagram} (T : ssyt μ) {i val : ℕ} (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) (j : ℕ) : T.irbc exists_lt ≤ j ↔ ∀ j' > j, (i, j') ∈ μ → val ≤ T i j' := begin rw [ssyt.irbc, finset.max'_le_iff], apply forall_congr, intro a, rw [ssyt.irbc_strip_mem, ← not_imp_not], push_neg, refl, end lemma ssyt.lt_irbc_iff {μ : young_diagram} (T : ssyt μ) {i val : ℕ} (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) (j : ℕ) : j < T.irbc exists_lt ↔ ∃ j' > j, (i, j') ∈ μ ∧ T i j' < val := begin rw ← not_iff_not, push_neg, rw ssyt.irbc_le_iff, end lemma ssyt.irbc_eq_iff {μ : young_diagram} (T : ssyt μ) {i val : ℕ} (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) (j : ℕ) : T.irbc exists_lt = j ↔ (i, j) ∈ μ ∧ T i j < val ∧ (∀ j' > j, (i, j') ∈ μ → val ≤ T i j') := begin rw [eq_comm, eq_iff_le_not_lt], push_neg, rw [ssyt.le_irbc_iff, ssyt.irbc_le_iff, and_assoc], end lemma ssyt.irbc_eq_of_eq_row {μ ν : young_diagram} (T : ssyt μ) (T' : ssyt ν) {i val : ℕ} (eq_cell : ∀ {j}, (i, j) ∈ μ ↔ (i, j) ∈ ν) (eq_row : ∀ {j}, T i j = T' i j) (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) (exists_lt' : ∃ j, (i, j) ∈ ν ∧ T' i j < val := by { obtain ⟨j, hj⟩ := exists_lt, rw [eq_cell, eq_row] at hj, exact ⟨j, hj⟩ }) : T.irbc exists_lt = T'.irbc exists_lt' := begin rw T.irbc_eq_iff, -- change first statement rw [eq_cell, eq_row], -- change second statement simp_rw [eq_cell, eq_row], rw ← T'.irbc_eq_iff, end lemma ssyt.irbc_eq_of_eq_row' {μ ν : young_diagram} (T : ssyt μ) (T' : ssyt ν) {i val i' val' : ℕ} (eq_cell : ∀ {j}, (i, j) ∈ μ ↔ (i, j) ∈ ν) (eq_row : ∀ {j}, T i j = T' i j) (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) (exists_lt' : ∃ j, (i', j) ∈ ν ∧ T' i' j < val') (hi : i' = i) (hval : val' = val) : T.irbc exists_lt = T'.irbc exists_lt' := begin rw T.irbc_eq_iff, simp_rw [eq_cell, eq_row, ← hi, ← hval], rw ← T'.irbc_eq_iff, end end inverse_row_bump_column section inverse_row_bump_step section irbs_cert structure ssyt.irbs_cert {μ : young_diagram} (T : ssyt μ) := (i val : ℕ) (exists_lt : ∃ j, (i, j) ∈ μ ∧ T i j < val) -- can just use 0! (down : ∀ i', i < i' → (i', T.irbc exists_lt) ∈ μ → val < T i' (T.irbc exists_lt)) @[reducible] def ssyt.irbs_cert.j {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) : ℕ := T.irbc h.exists_lt @[reducible] def ssyt.irbs_cert.out {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) : ℕ := T h.i h.j lemma ssyt.irbs_cert.cell {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) : (h.i, h.j) ∈ μ := (T.irbc_cell_and_lt_val h.exists_lt).1 lemma ssyt.irbs_cert.out_lt_val {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) : h.out < h.val := (T.irbc_cell_and_lt_val h.exists_lt).2 def ssyt.irbs_cert.to_legal {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) : T.legal := { i := h.i, j := h.j, val := h.val, cell_left := λ j hj, μ.nw_of (by refl) (le_of_lt hj) h.cell, cell_up := λ i hi, μ.nw_of (le_of_lt hi) (by refl) h.cell, left := λ j hj, (T.row_weak hj h.cell).trans (le_of_lt h.out_lt_val), right := λ j hj cell, (T.irbc_lt_iff h.exists_lt _).mp hj cell, up := λ i hi, (T.col_strict hi h.cell).trans h.out_lt_val, down := h.down } lemma ssyt.exists_lt_of_del_inner {μ : young_diagram} (T : ssyt μ) (c : μ.inner_corner) (hc : c.i ≠ 0) : ∃ j, (c.i.pred, j) ∈ c.del ∧ (T.del c) c.i.pred j < T c.i c.j := begin use c.j, have not_cell : (c.i.pred, c.j) ≠ (c.i, c.j) := λ h, (ne_of_lt (nat.pred_lt hc)) (prod.mk.inj_right c.j h), rw [c.mem_del, T.del_entry, if_neg not_cell], exact ⟨⟨not_cell, μ.nw_of (nat.pred_le _) (by refl) c.cell⟩, T.col_strict (nat.pred_lt hc) c.cell⟩, end def ssyt.irbs_cert_of_inner_corner {μ : young_diagram} (T : ssyt μ) (c : μ.inner_corner) (hc : c.i ≠ 0) : (T.del c).irbs_cert := { i := c.i.pred, val := T c.i c.j, exists_lt := T.exists_lt_of_del_inner c hc, down := λ i' hi' cell', begin suffices : c.j ≤ (T.del c).irbc (T.exists_lt_of_del_inner c hc), have cell := c.del.nw_of (nat.le_of_pred_lt hi') this cell', rw c.mem_del at cell, exfalso, exact cell.1 rfl, have hi_ne : c.i.pred ≠ c.i := ne_of_lt (nat.pred_lt hc), rw [ssyt.le_irbc_iff, c.mem_del, T.del_entry_eq_of_ne_row hi_ne], split, split, exact λ h, hi_ne (prod.mk.inj_right c.j h), exact μ.nw_of (nat.pred_le _) (by refl) c.cell, exact T.col_strict (nat.pred_lt hc) c.cell, end, } def ssyt.irbs_cert.copy {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) {ν : young_diagram} (T' : ssyt ν) (eq_cell : ∀ i j (hi : h.i ≤ i), (i, j) ∈ μ ↔ (i, j) ∈ ν) (eq_ge_row : ∀ i j (hi : h.i ≤ i), T i j = T' i j) : T'.irbs_cert := { i := h.i, val := h.val, exists_lt := begin simp_rw [← eq_cell _ _ (le_refl _), ← eq_ge_row _ _ (le_refl _)], exact h.exists_lt, end, down := λ i' hi', begin rw [← eq_cell _ _ (le_of_lt hi'), ← eq_ge_row _ _ (le_of_lt hi')], rw ← T.irbc_eq_of_eq_row T', exact h.down i' hi', exact λ j, eq_cell _ _ (by refl), exact λ j, eq_ge_row _ _ (by refl), end } end irbs_cert section irbs def ssyt.irbs_cert.irbs {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) : ssyt μ := h.to_legal.replace h.cell lemma ssyt.irbs_cert.irbs_entry {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) (i j : ℕ) : h.irbs i j = ite ((i, j) = (h.i, h.j)) h.val (T i j) := rfl lemma ssyt.irbs_cert.irbs_wt {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) (val : ℕ) : h.irbs.wt val + ite (val = T h.i h.j) 1 0 = T.wt val + ite (val = h.val) 1 0 := by apply ssyt.wt_replace lemma ssyt.irbs_cert.irbs_entry_eq_of_ne_row {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) {i j : ℕ} (hi : i ≠ h.i) : h.irbs i j = T i j := begin rw [h.irbs_entry, if_neg], rintro ⟨⟩, exact hi rfl end lemma ssyt.irbs_cert.next_exists_lt {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) (hi_pos : h.i ≠ 0) : ∃ (j : ℕ), (h.i.pred, j) ∈ μ ∧ (h.irbs) h.i.pred j < h.out := begin use h.j, split, apply μ.nw_of (nat.pred_le _) (le_refl _) h.cell, rw h.irbs_entry_eq_of_ne_row (ne_of_lt (nat.pred_lt hi_pos)), exact T.col_strict (nat.pred_lt hi_pos) h.cell, end lemma ssyt.irbs_cert.le_next_irbc {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) (hi_pos : h.i ≠ 0) : h.j ≤ h.irbs.irbc (h.next_exists_lt hi_pos) := begin rw ssyt.le_irbc_iff, split, exact μ.nw_of (nat.pred_le _) (by refl) h.cell, rw h.irbs_entry_eq_of_ne_row (ne_of_lt _), apply T.col_strict _ h.cell, all_goals {exact nat.pred_lt hi_pos}, end @[simps] def ssyt.irbs_cert.next_cert {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) (hi_pos : h.i ≠ 0) : h.irbs.irbs_cert := { i := h.i.pred, val := h.out, exists_lt := begin use h.j, split, apply μ.nw_of (nat.pred_le _) (le_refl _) h.cell, rw h.irbs_entry_eq_of_ne_row (ne_of_lt (nat.pred_lt hi_pos)), exact T.col_strict (nat.pred_lt hi_pos) h.cell, end, down := λ i' hi' cell', begin replace hi' := nat.le_of_pred_lt hi', apply le_trans _ (h.irbs.col_weak hi' cell'), apply lt_of_lt_of_le h.out_lt_val, apply le_trans _ (h.irbs.row_weak' (h.le_next_irbc hi_pos) _), rw h.irbs_entry, split_ifs; refl, exact μ.nw_of hi' (by refl) cell', end } -- what is the correct "lexicographic" fact here? -- (the inverse fact to [row_insertion.lean/ssyt.rbs_cert.rbc_lt_rbc] ?) -- if we inverse-bump a second corner west of the first one, the resulting out-value -- is ≤ the first one -- intermediate stage: if we inverse-bump in the same row with a value k' s.t. -- k' ≤ k, then j' < j and out' ≤ out lemma ssyt.irbs_cert.irbc_lt_irbc {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) (h' : h.irbs.irbs_cert) (hi : h'.i = h.i) (hval : h'.val ≤ h.val) : h'.j < h.j := begin rw ssyt.irbc_lt_iff, intro _, rwa [hi, h.irbs_entry, if_pos rfl], end lemma ssyt.irbs_cert.irbc_out_le_irbc_out {μ : young_diagram} {T : ssyt μ} (h : T.irbs_cert) (h' : h.irbs.irbs_cert) (hi : h'.i = h.i) (hval : h'.val ≤ h.val) : h'.out ≤ h.out := begin have hj : h'.j < h.j := h.irbc_lt_irbc h' hi hval, rw [ssyt.irbs_cert.out, h.irbs_entry, hi, if_neg], exact T.row_weak hj h.cell, exact λ h, (ne_of_lt hj) (prod.mk.inj_left _ h), end end irbs end inverse_row_bump_step
module IPL where data _∧_ (P : Set) (Q : Set) : Set where ∧-intro : P → Q → (P ∧ Q) _⇔_ : (P : Set) → (Q : Set) → Set a ⇔ b = (a → b) ∧ (b → a) proof₁ : {P Q : Set} → (P ∧ Q) → P proof₁ (∧-intro p q) = p proof₂ : {P Q : Set} → (P ∧ Q) → Q proof₂ (∧-intro p q) = q ∧-assoc₁ : { P Q R : Set } → ((P ∧ Q) ∧ R) → (P ∧ (Q ∧ R)) ∧-assoc₁ (∧-intro (∧-intro p q) r) = ∧-intro p (∧-intro q r) ∧-assoc₂ : { P Q R : Set } → (P ∧ (Q ∧ R)) → ((P ∧ Q) ∧ R) ∧-assoc₂ (∧-intro p (∧-intro q r)) = ∧-intro (∧-intro p q) r ∧-assoc : { P Q R : Set } → ((P ∧ Q) ∧ R) ⇔ (P ∧ (Q ∧ R)) ∧-assoc = ∧-intro ∧-assoc₁ ∧-assoc₂ data _∨_ (P Q : Set) : Set where ∨-intro₁ : P → P ∨ Q ∨-intro₂ : Q → P ∨ Q ∨-elim : {A B C : Set} → (A → C) → (B → C) → (A ∨ B) → C ∨-elim ac bc (∨-intro₁ a) = ac a ∨-elim ac bc (∨-intro₂ b) = bc b ∨-comm′ : {P Q : Set} → (P ∨ Q) → (Q ∨ P) ∨-comm′ (∨-intro₁ p) = ∨-intro₂ p ∨-comm′ (∨-intro₂ q) = ∨-intro₁ q ∨-comm : {P Q : Set} → (P ∨ Q) ⇔ (Q ∨ P) ∨-comm = ∧-intro ∨-comm′ ∨-comm′ ∨-assoc : { P Q R : Set } → ((P ∨ Q) ∨ R) → (P ∨ (Q ∨ R)) ∨-assoc (∨-intro₁ (∨-intro₁ p)) = ∨-intro₁ p ∨-assoc (∨-intro₁ (∨-intro₂ q)) = ∨-intro₂ (∨-intro₁ q) ∨-assoc (∨-intro₂ r) = ∨-intro₂ (∨-intro₂ r) data ⊥ : Set where ¬ : Set → Set ¬ A = A → ⊥
import numpy as np def radian(angle): return angle*np.pi/180.0 def PolarRandom1(m,n,angle0,angle1,radius0, radius1): if radius0 < np.amin([m,n])/2.0 and radius1 < np.amin([m,n])/2.0: radius = np.random.randint(low = radius0, high = radius1, size = 1) angle = np.random.randint(low = angle0, high = angle1, size = 1) x = int(n/2.0+radius*np.cos(radian(angle))) y = int(m/2.0+radius*np.sin(radian(angle))) if x < 0 or x > n or y < 0 or y > m: print("Ошибка") return x,y
variable (xs : List Nat) theorem foo1 : xs = xs := by induction xs <;> rfl theorem foo2 : xs = xs := by cases xs with | nil => rfl | cons x xs => rfl
(* Title: Dual_Order.thy Author: Jose Divasón <jose.divasonm at unirioja.es> Author: Jesús Aransay <jesus-maria.aransay at unirioja.es> *) section "Dual Order" theory Dual_Order imports Main begin subsection\<open>Interpretation of dual wellorder based on wellorder\<close> lemma wf_wellorderI2: assumes wf: "wf {(x::'a::ord, y). y < x}" assumes lin: "class.linorder (\<lambda>(x::'a) y::'a. y \<le> x) (\<lambda>(x::'a) y::'a. y < x)" shows "class.wellorder (\<lambda>(x::'a) y::'a. y \<le> x) (\<lambda>(x::'a) y::'a. y < x)" using lin unfolding class.wellorder_def apply (rule conjI) apply (rule class.wellorder_axioms.intro) by (blast intro: wf_induct_rule [OF wf]) lemma (in preorder) tranclp_less': "(>)\<^sup>+\<^sup>+ = (>)" by(auto simp add: fun_eq_iff intro: less_trans elim: tranclp.induct) interpretation dual_wellorder: wellorder "(\<ge>)::('a::{linorder, finite}=>'a=>bool)" "(>)" proof (rule wf_wellorderI2) show "wf {(x :: 'a, y). y < x}" by(auto simp add: trancl_def tranclp_less' intro!: finite_acyclic_wf acyclicI) show "class.linorder (\<lambda>(x::'a) y::'a. y \<le> x) (\<lambda>(x::'a) y::'a. y < x)" unfolding class.linorder_def unfolding class.linorder_axioms_def unfolding class.order_def unfolding class.preorder_def unfolding class.order_axioms_def by auto qed subsection\<open>Properties of the Greatest operator\<close> lemma dual_wellorder_Least_eq_Greatest[simp]: "dual_wellorder.Least = Greatest" by (auto simp add: Greatest_def dual_wellorder.Least_def) lemmas GreatestI = dual_wellorder.LeastI[unfolded dual_wellorder_Least_eq_Greatest] lemmas GreatestI2_ex = dual_wellorder.LeastI2_ex[unfolded dual_wellorder_Least_eq_Greatest] lemmas GreatestI2_wellorder = dual_wellorder.LeastI2_wellorder[unfolded dual_wellorder_Least_eq_Greatest] lemmas GreatestI_ex = dual_wellorder.LeastI_ex[unfolded dual_wellorder_Least_eq_Greatest] lemmas not_greater_Greatest = dual_wellorder.not_less_Least[unfolded dual_wellorder_Least_eq_Greatest] lemmas GreatestI2 = dual_wellorder.LeastI2[unfolded dual_wellorder_Least_eq_Greatest] lemmas Greatest_ge = dual_wellorder.Least_le[unfolded dual_wellorder_Least_eq_Greatest] end
import data.real.irrational import topology.basic import algebra.order.floor --OUTPUT 1 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=density_of_irrational_orbit {α : Type*} [linear_ordered_field α] [decidable_linear_ordered_comm_ring α] (α : α) [ha : ¬ is_rat α] : ∃ (B : ℤ → set α), ∀ i, ∀ j, i ≠ j → B i ≠ B j ∧ ∀ x ∈ B i, ∀ y ∈ B j, x - y ∈ B (i - j) := begin -- consider $S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\}$ let S := λ (i : ℤ), {x : α | ∃ y : ℤ, x = i * α - y}, let B := S, -- Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. -- If this were not true, then -- $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j}$ have h1 : ∀ i j : ℤ, i ≠ j → B i ≠ B j, from begin assume i j : ℤ, assume h1 : i ≠ j, have h2 : ¬ ∃ x : α, ∃ y : α, i * α - y = j * α - x, from begin assume h3, cases h3 with x h4, cases h4 with y h5, rw h5, have h6 : i - j ≠ 0, from by {contradict h1, linarith,}, have h7 : i * α - y = (i - j) * α + j * α - x, by {rw mul_sub_right_distrib, rw sub_add_eq_add_sub, ring}, have h8 : i - j ≠ 0, from by {rw [← @add_mul α 0 (-j) i] at h7, have h9 : i * 0 - y + j * α - x = 0, from zero_add y, rw [h7,h9,mul_zero], simp,}, have h9 : i * α - y -(j * α - x) = (i - j) * α - 0, from sub_add_eq_add_sub h7, have h10 : (i - j)⁻¹ ≠ 0, from inv_ne_zero h8, have h11 : (i - j)⁻¹ * ((i - j) * α - 0) = (i - j)⁻¹ * ((i - j) * α - (j * α - x) - y), by {rw h9, rw sub_zero,}, rw h11, rw mul_comm, rw mul_assoc, have h12 : (i - j)⁻¹ * ((i - j) * α) = (i - j)⁻¹ * (i - j) * α, from mul_comm _ ((i - j) * α), have h13 : (i - j)⁻¹ * ((i - j) * α) - ((i - j)⁻¹ * y) - (i - j)⁻¹ * (j * α - x) = (i - j)⁻¹ * (i - j) * α - (i - j)⁻¹ * y - (i - j)⁻¹ * (j * α - x), from by {rw [← sub_sub,zero_sub]}, rw h13 at h11, rw h12 at h11, have h14 : (i - j)⁻¹ * (i - j) = 1, from mul_inv_cancel h8, rw h14 at h11, have h15 : 1 * α - (i - j)⁻¹ * y - (i - j)⁻¹ * (j * α - x) = α - (i - j)⁻¹ * y - (i - j)⁻¹ * (j * α - x), from rfl, rw h15 at h11, have h16 : α - (i - j)⁻¹ * y - (i - j)⁻¹ * (j * α - x) = α - (i - j)⁻¹ * (y + (j * α - x)), from by {rw [← mul_one ((i - j)⁻¹), ← mul_add], ring}, rw h16 at h11, have h17 : (i - j)⁻¹ * (y + (j * α - x)) = (i - j)⁻¹ * y + (i - j)⁻¹ * (j * α - x), from mul_add _ _ _, rw h17 at h11, have h18 : α - (i - j)⁻¹ * y - (i - j)⁻¹ * (j * α - x) = α - (i - j)⁻¹ * (y + (j * α - x)), from rfl, rw h18 at h11, rw h17 at h11, rw h11, rw sub_self, linarith, end, exact and.intro, { assume h3 : x ∈ B i, cases h3 with y h4, have h5 : x ∈ B j, from by {existsi y, rw h4,}, have h6 : y ∈ B j, from by {existsi y, rw h4,}, exact absurd h2 (h1 (B i) (B j) h5 h6), }, { assume h3 : y ∈ B i, cases h3 with y h4, have h5 : x ∈ B j, from by {existsi y, rw h4,}, have h6 : y ∈ B j, from by {existsi y, rw h4,}, exact absurd h2 (h1 (B i) (B j) h5 h6), } end, -- $S$ is an infinite subset of $\left[0,1\right]$. have h2 : ∀ i : ℤ, S i ≠ ∅, from assume i : ℤ, by {existsi 0, rw sub_zero}, --By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. have h3 : ∀ (x : α), x ∈ [0, 1] → ∀ (ε : α), ε > 0 → ∃ y : ℤ, ∃ z : ℤ, ((i ≠ j) → (y ∈ S i ∧ z ∈ S j)) ∧ |x - (i * α - y) - (j * α - z)| < ε, from by { assume x : α, assume h3 : x ∈ [0, 1], assume ε : α, assume h4 : ε > 0, let y : ℤ := 0, let z : ℤ := 0, let h5 : ∀ i j : ℤ, i ≠ j → y ∈ S i ∧ z ∈ S j, from by { assume i j : ℤ, assume h5 : i ≠ j, split, { have h6 : y ∈ S i, from by {existsi y, rw sub_zero,}, exact h6, }, { have h7 : z ∈ S j, from by {existsi z, rw sub_zero,}, exact h7, } }, have h6 : |x - (i * α - y) - (j * α - z)| = |x - i * α + y - j * α + z| end --Needs more than 2000 tokens! --OUTPUT 2 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=density_of_irrational_orbit (α : ℝ) [irrational α] : ∀ ε : ℝ, ε > 0 → ∃ x y ∈ set.range (λ n : ℕ, n * α), abs (x - y) < ε := begin assume (ε : ℝ) hε, have h : ∀ i j : ℕ, ¬ (set.fintype.card (set.range ((λ (n : ℕ), n * α))) ≤ ((j : ℕ) - (i : ℕ))) ∨ (i * α - j * α) = 0 , from (assume i j : ℕ, by { rw [set.card_range,set.card_le_iff_finite,set.fintype.finite_subset], show (λ (n : ℕ), n * α) '' (((i : ℕ) : finset ℕ) ⊆ (j : finset ℕ)), from by { use ((i : ℕ) : finset ℕ), rintro x ⟨h1, h2⟩, existsi (x - i), split; try { exact add_sub_cancel' h2 }, simp [h1,h2], }, }), have h0 : ∀ i j : ℕ, (set.fintype.card (set.range ((λ (n : ℕ), n * α))) ≤ ((j : ℕ) - (i : ℕ))) → (i * α - j * α) ≠ 0 , from (assume i j : ℕ, by { rw [set.card_range,set.card_le_iff_finite,set.fintype.finite_subset], intro h1, exact not_of_imp_not (h i j) h1, }), have h1 : ∀ i j : ℕ, (set.fintype.card (set.range ((λ (n : ℕ), n * α))) ≤ ((j : ℕ) - (i : ℕ))) → (j * α - i * α) ≠ 0 , from (assume i j : ℕ, by { rw [← neg_eq_zero, ← sub_eq_add_neg], apply h0, }), let seq_limit : (ℕ → ℝ) → ℝ → Prop := λ (u : ℕ → ℝ) (l : ℝ), ∀ ε > 0, ∃ N, ∀ n > N, |u n - l| < ε in have h2 : seq_limit (λ n : ℕ, n * α) 0, from (assume (b : ℝ) h, show ∃ (N : ℕ), ∀ (n : ℕ), N < n → |(n : ℕ) * α - b| < b, from by { cases classical.em (b = 0) with h3 h3, use (0 : ℕ), assume n h4, use (abs (n * α)), rw [h3, abs_zero], linarith, use (⌊abs b⌋ : ℕ), rintro n h5, rw [← sub_eq_add_neg, ← abs_of_nonneg], apply lt_of_le_of_lt, rw [← abs_of_nonneg], apply lt_of_le_of_lt, apply abs_nonneg (n * α), calc abs (n * α) ≤ (n : ℕ) * (abs b) : abs_mul_le_mul_abs ... ≤ (⌊abs b⌋ : ℕ) * (abs b) : mul_le_mul_right _ h5 ... < abs b + 1 : mul_lt_mul_of_pos_left _ (lt_add_one _) ... = abs b : by simp, }), have h3 : ∀ x y : ℝ, x ∈ set.range (λ n : ℕ, n * α) → y ∈ set.range (λ n : ℕ, n * α) → x ≠ y → x - y ≠ 0 ∧ y - x ≠ 0, from (assume (x y : ℝ) h4 h5 h6, by { cases h4 with i h4, cases h5 with j h5, split, apply h0 i j, exact h4, apply h1 j i, exact h5, }), have h4 : ∀ x y : ℝ, x ∈ set.range (λ n : ℕ, n * α) → y ∈ set.range (λ n : ℕ, n * α) → x ≠ y → abs (x - y) ≠ 0, from (assume (x y : ℝ) h5 h6 h7, by { cases h5 with i h5, cases h6 with j h6, have h8 : ∀ x y : ℝ, x ≠ y ∧ y ≠ x → abs x ≠ 0 ∧ abs y ≠ 0, from (assume (x y : ℝ) h9, by { split, intro h10, cases h9.1, symmetry at h10, exact h10 h10, intro h11, cases h9.2, symmetry at h11, exact h11 h11, }), apply h8, split, apply h0 i j, exact h5, apply h1 j i, exact h6, }), have h5 : ∀ x y : ℝ, x ∈ set.range (λ n : ℕ, n * α) → y ∈ set.range (λ n : ℕ, n * α) → x ≠ y → abs (x - y) ≠ 0 ∧ abs (y - x) ≠ 0, from (assume (x y : ℝ) h7 h8 h9, by { cases h7 with i h7, cases h8 with j h8, split, apply h0 i j, exact h7, apply h1 j i, exact h8, }), have h6 : ∀ x y : ℝ, x ∈ set.range (λ n : ℕ, n * α) → y ∈ set.range (λ n : ℕ, n * α) → x ≠ y → abs (x - y) ≈ abs (y - x), from (assume (x y : ℝ) h7 h8 h9, by { cases h7 with i h7, cases h8 with j h8, show abs (x - y) ≈ abs (y - x), from by { have h10 : x - y ≠ 0 ∧ y - x ≠ 0, from by { apply h5, apply h7, apply h8, exact h9, }, apply abs_abs_sub, split; exact h10.1, } }), have h7 : ∀ (x y : ℝ) (ε : ℝ), x ∈ set.range (λ n : ℕ, n * α) → y ∈ set.range (λ n : ℕ, n * α) → x ≠ y → ε > 0 → abs (x - y) < ε → abs (y - x) < ε, from (assume (x y : ℝ) (ε : ℝ) h7 h8 h9 h10 h11, by { cases h7 with i h7, cases h8 with j h8, cases h6 x y _ _ h9 with h12 h13, have h14 : abs (x - y) ≈ abs (y - x), from h12, have h15 : abs (y - x) ≈ abs (x - y), from h13, have h16 : abs ((x - y) + (y - x)) = abs (x - y end --Needs more than 2000 tokens! --OUTPUT 3 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=irrational_orbit_dense (α : ℝ) (hα : ¬(is_irrat α)) : ∀ (ε : ℝ) (hε : ε > 0), ∃ N : ℤ, ∀ (x : ℤ), (N*x)%Z ∈ ℤ → x ∈ ℤ → ε > (abs (α*x%Z - IZR (N*x)%Z)) ∧ ε ≥ (abs (α*x%Z - IZR (N*x)%Z)) := begin intros ε hε, have h1 : (∃ (l : ℤ), ε > IZR l), from exists_rat_btwn ε (by norm_num : (0:ℝ) < ε), cases h1 with l hl, let N := l+1, use N, intros x x_int hx_int, have h1 := abs_lt_of_lt_sub_left hl, have h2 : abs (α * x - IZR (N * x)) = abs (α * x - IZR (N * x - 1)), from begin rw sub_succ, rw sub_self, have h2 : (0:ℝ) < abs (α * x), { rw [mul_comm α x, ← abs_mul], exact abs_pos_iff.mpr (mul_self_pos α⁻¹) }, have h3 : (0:ℝ) < ε + 1, simpa [add_comm, hε], have h4 := by linarith, have h5 := abs_mul_le_iff α x ε h2, have h6 := abs_mul_le_iff α x (ε + 1) h3, have h7 : abs (α * x) ≤ (ε + 1) * abs x, from by linarith, show abs ((α * x - IZR (N * x)) - (-1)) ≤ abs (α * x - IZR (N * x - 1)), from by linarith, end, have h3 : IZR (N*x)%Z ∈ {a | ∃ (b : ℤ), a = IZR b}, from begin refine (exists_int_of_int_pos _).mpr _, exact (mul_self_pos N).mpr (pos_of_ne_zero (by linarith)), end, have h4 : IZR (N*x)%Z <= α * x ∧ (α * x) < IZR (N*x)%Z + 1, from by { rw mul_comm α x,have h4 := rat_btwn_of_abs_lt (by linarith) h3 (by linarith), refine ⟨le_of_lt h4.left, h4.right⟩, }, let y := α * x - IZR (N*x)%Z, have h5 : IZR (N*x)%Z ≤ α * x ∧ y < 1, from by linarith, have h6 : abs y < IZR (N*x)%Z, from abs_lt_of_lt_sub_left h5, have h7 : abs y < N*x, from by linarith, have h8 := by linarith, have h9 := by linarith, split; linarith, end --OUTPUT 4 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=density_of_irrational_orbit {α : Type*} (α : ℝ) (h : ¬ (α ∈ ℚ)) : ∀ x ∈ set.range (λ n : ℤ, (n : ℝ) * α), x ∈ Ioo 0 1 := begin -- Let $\alpha$ be an irrational number. assume A : set α, assume h2 : ¬ ∀ (x : ℝ), ∃ (n : ℤ), x = n * α, assume (x : α) (hx : x ∈ set.range (λ (n : ℤ), (n : ℝ) * α)), -- Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. have h3 : ∀ (i j : ℤ), ¬ (i ≠ j ∧ ((λ (n : ℤ), fractional_part (n * α)) i = (λ (n : ℤ), fractional_part (n * α)) j)), from assume (i j : ℤ) (h3 : i ≠ j ∧ ((λ (n : ℤ), fractional_part (n * α)) i = (λ (n : ℤ), fractional_part (n * α)) j)), --If this were not true, then $$ i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor, $$Using floor of real number begin have h4 : ∀ (n : ℤ), fractional_part (n * α) = (n * α) - (floor (n * α)), from begin assume n, have nat_lt_add_of_pos_left : ∀ a b : ℝ, 0 < a → a < b + a, from assume (a b : ℝ) (h_pos : 0 < a), by linarith, have nat_lt_add_of_pos_right : ∀ a b : ℝ, 0 < b → a < b + a, from assume (a b : ℝ) (h_pos : 0 < b), by linarith, have nat_le_add_of_le_left : ∀ a b : ℝ, a ≤ b → a ≤ b + a, from assume (a b : ℝ) (h_le : a ≤ b), by linarith, have nat_le_add_of_le_right : ∀ a b : ℝ, b ≤ a → b ≤ a + b, from assume (a b : ℝ) (h_le : b ≤ a), by linarith, have nat_add_le_of_le_add : ∀ a b c : ℝ, a ≤ b → a + c ≤ b + c, from assume (a b c : ℝ) (h_le : a ≤ b), by linarith, calc (fractional_part (n * α)) = (n * α) - (n * α) ∩ (nat) : (fractional_part_nat_eq_sub _ _) ... = (n * α) - (n * α) ∩ (Ioc 0 1) : by {congr, rw @interval_nat, } ... = (n * α) - (n * α) ∩ (Icc 0 1) : le_antisymm (by {apply nat_le_add_of_le_left, rw mul_pos (nat_le_add_of_le_right _ _ (by linarith)), exact h_pos *α, }) (le_floor (n * α)) : by {rw (floor_eq_of_nat_le _ _ h_le), rw (floor_eq_of_nat_le _ _ (by {apply nat_le_add_of_le_left, rw mul_pos (nat_le_add_of_le_right _ _ (by linarith)), exact h_pos *α, })), reflexivity} ... = (n * α) - floor (n * α) : (set.inter_eq_self_of_subset (set.inter_subset_inter (set.preimage_subset_preimage_iff.mp $ (show (λ (x : ℝ), _) ⁻¹' _ ⊆ (λ (x : ℝ), _) ⁻¹' _, from dec_trivial)) show (λ (x : ℝ), _) ⁻¹' _ ⊆ (λ (x : ℝ), _) ⁻¹' _, from dec_trivial) rfl) ... = (n * α) - floor ((n * α) + (1 : ℝ)) : by {rw (add_sub_cancel'.mp ((nat_add_le_of_le_add _ _ _ (by {apply nat_le_add_of_le_left, rw mul_pos (nat_le_add_of_le_right _ _ (by linarith)), exact h_pos *α, }))).symm), reflexivity} ... = (n * α) - floor ((n * α) + (1 : ℝ)) : by {rw (add_sub_cancel'.mp ((nat_add_le_of_le_add _ _ _ (by {apply nat_le_add_of_le_left, rw mul_pos (nat_le_add_of_le_right _ _ (by linarith)), exact h_pos *α, }))).symm), reflexivity} ... = (n * α) - ((n * α) + ((n * α) + (1 : ℝ) - (n * α))) : by {rw (sub_add_cancel' (n * α)), reflexivity} ... = (n * α) - ((n * α) + ((n * α) + (1 : ℝ) - (n * α))) : by {rw (sub_add_cancel' (n * α)), reflexivity} ... = (n * α) - ((n * α) + 1) : by {rw add_sub_cancel', reflexivity} ... = (n * α) - 1 - (n * α) : by {rw nat_sub_sub_cancel', reflexivity} ... = -1 : by {rw ← nat_sub_sub_eq_sub_sub_sub}, end, --which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. by_contradiction h3c, have h4 : rational_distinct.to_real α = (real.floor (i * α) - real.floor (j * α)) / (i - j) := (fractional_part_eq_sub.mp h3.left).right, have h5 : rational_distinct.to_real α = (real.floor (i * α) - real.floor (j * α)) / (i - j) := by rw ← h4, have h6 : (α : ℝ) = (real.floor (i * α) - real.floor (j * α)) / (i - j) := by rw ← h5, have h7 : (α : ℝ) = (real.floor (i * α) - real.floor (j * α)) / (i - j) := by rw ← h6, have h8 : (α : ℝ) = ((i : ℝ) * α - real.floor (j * α)) / (i - j) := by {rw [←mul_assoc, ←mul_sub_right_distrib], apply nat_sub_sub_eq_sub_sub_sub }, have h9 : (α : ℝ) = (i * α - real.floor (j * α)) / (i - j) := by rw ← h8, have h10 : (α : ℝ) = ((i : ℝ) * α - real.floor ( end --Needs more than 2000 tokens! --OUTPUT 5 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=density_of_irrational_orbit : ∀ {α : Type u} [inhabited α] [linear_order α] [total_order α] [preorder α] [linear_ordered_ring α] (irra : α) (below : α) (above : α), irra ≠ 0 → ∃ i : ℤ, ∃ j : ℤ, i ≠ j ∧ irra * i ≠ irra * j := begin assume (α : Type u) [inhabited α] [linear_order α] [total_order α] [preorder α] [linear_ordered_ring α] (irra : α) (below : α) (above : α) (h_irra_not_zero : irra ≠ 0), cases exists_ne_zero_and_ne_zero_of_mul_eq_zero (irra * irra) with i h_irra_and_i, cases h_irra_and_i with h_irra_not_zero h_irra_not_zero_and_i, cases h_irra_not_zero_and_i with h_i_not_zero h_irra_neq_i, use irra * i + 1, use irra * i, split, show irra * (irra * i + 1) ≠ irra * irra * i, from by { rw ← mul_assoc, rw ← mul_assoc irra irra i, ring, simp [h_irra_not_zero, h_i_not_zero, h_irra_neq_i], }, show irra * i ≠ irra * irra * i, from by { rw ← mul_assoc irra irra i, ring, simp [h_irra_not_zero, h_i_not_zero, h_irra_neq_i], }, end --OUTPUT 6 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=density_irrational_orbit (x : ℝ) (h1 : irrational x) : ∀ a b ∈ ℕ, a ≠ b → (int.fract a * x) ≠ (int.fract b * x) := begin assume b c hb hc, assume h2 : (int.fract b * x) = (int.fract c * x), --By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. have h3 : ∃ x, ∀ ε > 0, ∃ c, ∃ c', c ≠ c' ∧ |x - c| < ε ∧ |x - c'| < ε, from classical.by_contradiction $ assume H : ∀ x : ℝ, ¬ (∀ (ε : ℝ) (hp : 0 < ε), ∃ (c c' : ℝ), c ≠ c' ∧ |x - c| < ε ∧ |x - c'| < ε), have H₂ : ∀ x : ℝ, ∀ (ε : ℝ) (hp : 0 < ε), ∃ (c : ℝ), ∀ (c' : ℝ), |c - c'| ≥ ε ∨ c' = c, from begin assume x ε hp, obtain ⟨ε₁, h_ε₁⟩ : (0 < ε / 2), from rat.exists_pos_half ε hp, cases H x ⟨ε₁, h_ε₁⟩ with c Hc, use c, intros c' hc', cases (Hc c' (hc'.elim not_le_of_gt h_ε₁)), exact (show ε / 2 < ε, by exact lt_of_lt_of_le h_ε₁ (le_of_lt hp)), exact ‹c ≠ c'›, end, have H₃ : ∀ x : ℝ, ∀ (ε : ℝ) (hp : 0 < ε), ∃ (c : ℝ), ∀ (c' : ℝ), |c' - c| ≥ ε ∨ c' = c, from begin assume x ε hp, obtain ⟨c, hc⟩ : ∃ (c : ℝ), ∀ (c' : ℝ), |c - c'| ≥ ε ∨ c' = c, from H₂ x ε hp, use c, intro c', cases hc c' with h h, use h, exact h, end, have H₄ : ∀ x : ℝ, ∀ (ε : ℝ) (hp : 0 < ε), ∃ (c : ℝ), ∃ (c' : ℝ), c ≠ c' ∧ |x - c| < ε ∧ |x - c'| < ε, from begin assume x ε hp, obtain ⟨c, hc⟩ : ∃ (c : ℝ), ∀ (c' : ℝ), |c' - c| ≥ ε ∨ c' = c, from H₃ x ε hp, obtain ⟨c'₁, hc'₁⟩ : c' ≠ c, from not_iff_not_of_iff hc, obtain ⟨c'₂, hc'₂⟩ : c' ≠ c, from not_iff_not_of_iff hc, have h_c'₁_c'₂ : c'₁ ≠ c'₂ := not_iff_not_of_iff (hc c'₁) c'₂ hc'₁, have h_c_c'₁ : c'₁ ≠ c := not_iff_not_of_iff (hc c'₂) c'₁ hc'₂, use c'₁, use c'₂, split, exact h_c'₁_c'₂, split, exact lt_of_not_ge h_c_c'₁, exact lt_of_not_ge h_c'₁_c'₂, end, obtain ⟨c, hc⟩ : ∃ (c : ℝ), ∃ (c' : ℝ), c ≠ c' ∧ 0 < c ∧ 0 < c', from H₄ 0 1 (by norm_num), obtain ⟨c', hc'⟩ : ∃ (c' : ℝ), c ≠ c' ∧ 0 < c' ∧ 0 < c', from H₄ 0 c.val (show 0 < c.val, from hc.right.left), obtain ⟨h₁, h₂⟩ : c ≠ c' ∧ 0 < c' ∧ 0 < c, from hc', obtain ⟨h₃, h₄⟩ : c ≠ c' ∧ 0 < c ∧ 0 < c', from hc, have hc_hc' : c < c' ∨ c' < c, from or_iff_not_imp_left.mp h₁, obtain ⟨ε, h_ε⟩ : 0 < c - c' ∨ 0 < c' - c, from (by linarith) hc_hc', obtain ⟨ε₁, h_ε₁⟩ : 0 < ε ∨ 0 < ε, from lt_or_lt_of_le_or_le h_ε, cases ε with ε, cases ε_property with ne ne, exact absurd ne dec_trivial, cases ε_property with ne ne, exact absurd ne dec_trivial, have h₅ : ε = ε₁, from sub_eq_zero.mp (ε_property (lt_of_le_of_lt h_ε₁ h_ε₂)), have H₆ : ∀ (x : ℝ) (h₁ : x ≠ 0), ¬ (∃ (c c' : ℝ), c ≠ c' ∧ 0 < c ∧ 0 < c'), from by { assume x h₁ h₂, obtain ⟨c, hc⟩ : ∃ (c : ℝ), c ≠ 0 ∧ 0 < c, from (exists_ne_zero_and_lt 0).mp h₂, obtain ⟨c', hc'⟩ : ∃ (c' : ℝ), c ≠ c' ∧ 0 < c, from hc, obtain ⟨h_hc', h_hc⟩ : c ≠ c' ∧ 0 < c, from hc', have h' : c ≠ c', from (eq_of_mul_eq_mul_right h₁).mp h_hc.right, exact absurd h_hc'.left h', }, obtain ⟨c, hc⟩ : ∃ (c : ℝ), c ≠ 0 ∧ 0 < c, from H₆ ε h_ε₁, obtain ⟨h_hc, hc'⟩ : c ≠ 0 ∧ 0 < c, from hc, have hc₁ : 0 < ε, from ‹0 < c›, have H₇ : ∃ (c c' : ℝ), c ≠ c' ∧ 0 < c ∧ 0 < c', from H₆ ε h_hc, have h₈ : ∃ (c c' : ℝ), c ≠ c' ∧ 0 < c ∧ 0 < c end --Needs more than 2000 tokens! --OUTPUT 7 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=irrational_orbit (α : ℝ) (hαirr : irrational α) : ∃ N : ℤ, ∀ (n : ℕ), ∃ i ∈ {i : ℤ | ∃ N : ℕ, i = N * N} , |i*α - (n : ℕ)| < 1/2^(n+1) := sorry /--`theorem` A Closure Property Let $\struct {G, \circ}$ be a group. Let $A$ be a subset of $G$. Suppose that $\forall a, b \in A: a \circ b \in A$. Then $A$ is a subgroup of $G$. `proof` From $a \circ b^{-1} \in A$ for all $a, b \in A$ we have: :$\forall a : A: a^{-1} \in A$ Hence $A$ is a submonoid. From $a, a^{-1} \in A$ for all $a \in A$ we have: :$\forall a: A: a = a^{-1}^{-1}$ Hence $A$ is a group. {{qed}} -/ theorem closure_property_group {G : Type*} [group G] (A : set G) (h1 : ∀ a b ∈ A, a * b ∈ A) : is_subgroup A := begin -- Group has Latin Square Property have h2 : ∀ a b : G, ∃! x : G, a * x = b, from by { assume a b : G, use a⁻¹ * b, obviously, }, have h3 : ∀ a b : G, ∃! y : G, y * a = b, from by { assume a b : G, use b * a⁻¹, obviously, }, -- From $a \circ b^{-1} \in A$ for all $a, b \in A$ we have $\forall a : A: a^{-1} \in A$ have h4 : ∀ a ∈ A, a⁻¹ ∈ A, from assume (a : G) (h0 : a ∈ A), have h5 : (a⁻¹*a) ∈ A, from h1 a⁻¹ a h0, have h6 : ∃! x : G, a * x = a⁻¹ * a, from h2 a (a⁻¹ * a), have h7 : a⁻¹ = classical.some (h6).exists, from exists_unique.unique (h6) (classical.some_spec (exists_unique.exists (h6))) (classical.some_spec (exists_unique.exists (h6))), show a⁻¹ ∈ A, from h4 a h5, -- Hence $A$ is a submonoid. have h8 : is_submonoid A, from {one_mem := by rw [← one_inv, h4 (1 : G) (set.one_mem A)], mul_mem := assume a b h9 h10, show a * b ∈ A, from h1 a b (h9) (h10)}, -- From $a, a^{-1} \in A$ for all $a \in A$ we have $\forall a: A: a = a^{-1}^{-1}$ have h9 : ∀ a : G, a⁻¹⁻¹ = a, from assume (a : G) (h10 : a ∈ A), by { have h11 : a⁻¹ ∈ A, from h4 a h10, have h12 : ∃! x : G, x * a⁻¹ = a⁻¹, from h3 a⁻¹ (a⁻¹), have h13 : a⁻¹⁻¹ = classical.some (h12).exists, from exists_unique.unique (h12) (classical.some_spec (exists_unique.exists (h12))) (classical.some_spec (exists_unique.exists (h12))), rw h13}, -- Hence $A$ is a group. exact is_subgroup.mk h8 h9 end --OUTPUT 8 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=irrational_orbit_density (α : ℝ) (hα : irrational α) : ∀ y : ℝ, ∃ (x : ℝ) (N : ℤ), 0 ≤ x ∧ x ≤ 1 ∧ N*x ≤ y ∧ y < (N+1)*x := begin assume (y : ℝ), -- there are infinitely many distinct multiples of $\alpha$ have h : ∀ n : ℤ, n ≠ 0 → ∃ m : ℤ, m ≠ n, from by { assume n, assume hn : n ≠ 0, by_contra h, have h' : n = 0, from ne_of_gt (abs_pos_of_ne_zero) h, contradiction, }, have h2 : ∀ m n : ℤ, m ≠ n → m*α ≠ n*α, from by { assume m n, assume hmn : m ≠ n, assume hmn2 : m*α = n*α, have h1 : (m-n)*α = 0, from calc (m-n)*α = m*α - n*α : by ring ... = 0 : by exact hmn2, -- we cannot have that $(m-n)*\alpha$ = 0, because $\alpha$ is irrational have h2 : (m-n) = 0, from mul_eq_zero.mp h1, have h3 : m = n, from eq_of_sub_eq_zero h2, contradiction, }, have h3 : ∀ m n : ℤ, m ≠ n → ¬(⟨m*α,1⟩ = ⟨n*α,1⟩), from by { assume m n, assume hmn : m ≠ n, assume hmn2 : ⟨m*α,1⟩ = ⟨n*α,1⟩, have h2 : m*α = n*α, from (rat.num_denom m*α).symm.trans hmn2, contradiction, }, have h4 : ∀ m n : ℤ, m ≠ n → ∀ N : ℕ, ¬(⟨m*α,1⟩ = ⟨n*α,1⟩ + ⟨(m-n)*α,1⟩/2^N), from by { assume m n, assume hmn : m ≠ n, assume N, assume hmn2 : ⟨m*α,1⟩ = ⟨n*α,1⟩ + ⟨(m-n)*α,1⟩/2^N, have h1 : ⟨m*α,1⟩ = ⟨n*α,1⟩ + 0, from rat.add_eq_of_eq_of_eq_of_eq_zero_of_le (rat.add_le_add_iff_right.mp (rat.num_denom _).mp) (by ring) (by refl), have h2 : ⟨m*α,1⟩ = ⟨n*α,1⟩, from eq_of_sub_eq_zero (by linarith), have h3 : m*α = n*α, from (rat.num_denom _).symm.trans h2, exact hmn h3, }, -- there are infinitely many distinct pairs of multiples of $\alpha$ have h5 : ∀ n : ℤ, n ≠ 0 → ∃ m k : ℤ, m ≠ n ∧ k ≠ n, from by { assume n, assume hn : n ≠ 0, cases h n hn with m hm, cases h m (ne.symm hm) with k hk, use [m,k], rw ← hk, repeat {split}; show m ≠ n, from hm, show k ≠ n, from hn, }, -- 0 is a limit point of the orbit have h6 : (∀ ε > 0, ∃ n : ℤ, n ≠ 0 ∧ ((nat.floor(n*ε))/n) ≤ 0 ∧ (0 ≤ ((nat.floor(n*α*n))/n))), from by { assume ε, assume hε : ε > 0, cases h5 1 (by linarith) with m hm, cases h5 1 (by linarith) with k hk, use [m,k], split, exact hm.left, rw ← div_mul_cancel, swap, { by_contra h, rw [← hm.right, ← hk.right] at h, cases h, }, rw [← add_le_add, ← add_le_add], have h2 : ∀ n : ℤ, n ≠ 0 → 0 ≤ nat.floor(n*α*n), from by { assume n, assume hn : n ≠ 0, by_contra h, have h3 : n*α*n = 0, from mul_eq_zero.mp (by linarith), have h4 : n = 0, from eq_zero_of_mul_self_right (rat.num_denom n*α*n) (by linarith), contradiction, }, split, { exact h2 m hm.left, }, { exact h2 k hk.left, } }, -- let's find $N$ such that $N*x ≤ y$ and such that $y < (N+1)*x$ have h7 : ∃ N : ℤ, N*(⟨1,1⟩/2^(nat.floor(2^1*ε) + 1)) ≤ ⟨y,1⟩ ∧ ⟨y,1⟩ < (N+1)*(⟨1,1⟩/2^(nat.floor(2^1*ε) + 1)) ∧ ∀ (p q : ℤ), q ≠ 0 → p ≠ N → p ≠ N+1 → ¬((⟨p*α,1⟩ ≤ ⟨y,1⟩ + ⟨1/2^(nat.floor(2^1*ε) + 1),1⟩) ∧ (⟨y,1⟩ + ⟨1/2^(nat.floor(2^1*ε) + 1),1⟩ < ⟨q*α,1⟩)) := begin have h8 : ∃ m n : ℤ, m ≠ n, from h5 1 (by linarith), cases h8 with m h8, cases h8 with n hn, use [m,n], split, { cases lt_or_le.mp (lt_add_one m) with hm hm, { have h9 := h6 (1/2^(nat.floor(2^1*ε) + 1)), cases h9 (by linarith) with k hk, cases hk with hk hk, cases hk with hk₁ hk₂, cases hk₂ with hk₂ hk₄, cases hk₄ with hk₄ hk₅, have h20 : n*α ≠ k*α, from h2 n k hn.left, have h21 : m*α ≠ k*α, from h2 m k hn.right, have h22 : m*α ≠ n*α, from hn.left, have h23 : k*α ≠ n*α, from h2 k n hk₁, have h24 : k* end --Needs more than 2000 tokens! --OUTPUT 9 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=density_of_irrational_orbit {α : Type*} [linear_ordered_field α] : ∀ (α : α), α ≠ 0 → ∀ s : set α, s ⊆ (λ i : ℤ, i * α) '' range ℤ → ∃ i : ℤ, i * α ∈ s := begin assume (α : α) H s h1, cases (exists_nat_gt (0 : α)) with N hN, have h2 : ∀ m n : ℤ, m ≠ n → (m : α) * α - ⌊(m : α) * α⌋ ≠ (n : α) * α - ⌊(n : α) * α⌋, { assume m n hmneq, have h3 : m * α - ⌊m * α⌋ = n * α - ⌊n * α⌋ → m * α - ⌊m * α⌋ = 0, { assume h mneq, rw [← sub_eq_zero, ← sub_eq_zero, ← sub_eq_zero, ← h, int.cast_sub, int.cast_sub, int.cast_sub, sub_eq_zero], }, have h4 : (m : α) - (n : α) = 0 → ((m : α) * α - ⌊(m : α) * α⌋) - ((n : α) * α - ⌊(n : α) * α⌋) = 0, { assume h, have h5 : (m : α) * α - ⌊(m : α) * α⌋ = (n : α) * α - ⌊(n : α) * α⌋ ↔ (m : α) = (n : α), { rw [eq_comm, ← eq_comm (⌊(m : α) * α⌋), ← eq_comm (⌊(n : α) * α⌋), ← sub_eq_zero, ← sub_eq_zero, ← sub_eq_zero, ← h, int.cast_sub, int.cast_sub, int.cast_sub, sub_eq_zero], split, assume h6, linarith, assume h7, linarith, }, rw [← h5], have h8 : m - n = 0, from int.cast_inj h7, have h9 : m * α - ⌊m * α⌋ = n * α - ⌊n * α⌋, from h5.mp h7, simp [h8, h9], }, have h6 : (m : α) - (n : α) = 0 ↔ m = n, from eq_comm (m - n) 0, have h7 : m ≠ n ↔ (m : α) - (n : α) ≠ 0, from eq_comm (m : α) (n : α), exact h7.mp (mt h4.mpr (h6.mp h7.mpr mneq)), }, have h3 : ∀ m n : ℤ, m ≠ n → (λ (i : ℤ), i * α - ⌊i * α⌋) m ≠ (λ (i : ℤ), i * α - ⌊i * α⌋) n, { assume m n hmneq, have h4 : (λ i : ℤ, i * α) m ≠ (λ i : ℤ, i * α) n, { rw [← eq_comm (m * α) (n * α), ← eq_comm (m : α) (n : α), ← int.cast_inj hmneq, int.cast_mul, int.cast_mul], exact hmneq, }, have h5 : (λ i : ℤ, (i - ⌊i * α⌋) * α) m ≠ (λ i : ℤ, (i - ⌊i * α⌋) * α) n, { rw [← int.cast_add, int.cast_mul, int.cast_mul, int.cast_add, int.cast_comm m, int.cast_comm n], exact h4, }, exact h5, }, have h4 : (λ (i : ℤ), i * α - ⌊i * α⌋) '' range ℤ = (λ (i : ℤ), i * α) '' range ℤ, { simp, }, have h5 : (λ i : ℤ, i * α - ⌊i * α⌋) '' range ℤ = (λ i : ℤ, i * α) '' range ℤ, { rw ← h4, }, have h6 : (λ i : ℤ, i * α - ⌊i * α⌋) '' range ℤ ⊆ s, { rw h5, from set.image_subset h1, }, have h7 : ∃ i : ℤ, (λ i : ℤ, i * α - ⌊i * α⌋) i ∈ s, { rw [h5], from set.exists_mem_image s, }, cases h7 with i hi, use i, show (λ i : ℤ, i * α) i ∈ s, { simp, exact hi, }, end --OUTPUT 10 theorem irrational_orbit_dense {α : ℝ} (hα_irrat : irrational α) : closure ((λ m : ℤ, int.fract (α * ↑m)) '' (@set.univ ℤ)) = set.Icc 0 1 :=density_of_irrational_orbit {α : Type*} [decidable_eq α] [linear_order α] [decidable_linear_order α] [add_comm_group α] [order_bot α] [densely_ordered α] [∀ a b c : α, (a ≤ b) ∧ (b ≤ c) → (a ≤ c)] [∀ a b : α, a ≤ b ∨ b ≤ a] {β : Type*} [comm_ring β] [decidable_eq β] [inhabited β] [∀ a b c : β, (a ≤ b) ∧ (b ≤ c) → (a ≤ c)] [∀ a b : β, a ≤ b ∨ b ≤ a] {γ : Type*} [no_zero_divisors β] [inhabited γ] [add_comm_group γ] [decidable_eq γ] [order_bot γ] [∀ a b c : γ, (a ≤ b) ∧ (b ≤ c) → (a ≤ c)] [∀ a b : γ, a ≤ b ∨ b ≤ a] {δ : Type*} [add_comm_group δ] [decidable_eq δ] [has_zero δ] {δ₀ : Type*} [add_comm_group δ₀] [decidable_eq δ₀] [has_zero δ₀] [has_one δ₀] [is_submonoid δ₀] {δ₁ : Type*} [add_comm_group δ₁] [decidable_eq δ₁] [has_one δ₁] [is_submonoid δ₁] [∀ a b : δ₁, a ≤ b ∨ b ≤ a] {δ₂ : Type*} [add_comm_group δ₂] [decidable_eq δ₂] [add_comm_monoid δ₂] [has_one δ₂] {δ₃ : Type*} [add_comm_group δ₃] [decidable_eq δ₃] [add_comm_monoid δ₃] [has_one δ₃] [has_inv δ₃] [is_submonoid δ₃] {δ₄ : Type*} [add_comm_group δ₄] [decidable_eq δ₄] [add_comm_monoid δ₄] [has_one δ₄] [has_inv δ₄] [is_submonoid δ₄] {δ₅ : Type*} [add_comm_group δ₅] [decidable_eq δ₅] [add_comm_monoid δ₅] [has_one δ₅] [has_inv δ₅] {δ₆ : Type*} [add_comm_group δ₆] [decidable_eq δ₆] [add_comm_monoid δ₆] [has_one δ₆] [has_inv δ₆] {δ₇ : Type*} [add_comm_group δ₇] [decidable_eq δ₇] [add_comm_monoid δ₇] [has_one δ₇] [has_inv δ₇] {δ₈ : Type*} [add_comm_group δ₈] [decidable_eq δ₈] [add_comm_monoid δ₈] [has_one δ₈] [has_inv δ₈] {δ₉ : Type*} [add_comm_group δ₉] [decidable_eq δ₉] [add_comm_monoid δ₉] [has_one δ₉] [has_inv δ₉] {η : Type*} [decidable_eq η] [linear_order η] [dedekind_order η] {η₀ : Type*} [add_comm_group η₀] [decidable_eq η₀] {η₁ : Type*} [add_comm_group η₁] [decidable_eq η₁] {η₂ : Type*} [add_comm_group η₂] [decidable_eq η₂] {η₃ : Type*} [add_comm_group η₃] [decidable_eq η₃] {η₄ : Type*} [add_comm_group η₄] [decidable_eq η₄] {η₅ : Type*} [add_comm_group η₅] [decidable_eq η₅] {η₆ : Type*} [add_comm_group η₆] [decidable_eq η₆] {η₇ : Type*} [add_comm_group η₇] [decidable_eq η₇] {η₈ : Type*} [add_comm_group η₈] [decidable_eq η₈] {η₉ : Type*} [add_comm_group η₉] [decidable_eq η₉] {θ : Type*} [add_comm_group θ] [order_bot θ] [decidable_eq θ] [∀ a b : θ, a ≤ b ∨ b ≤ a] {θ₀ : Type*} [add_comm_group θ₀] [order_bot θ₀] [decidable_eq θ₀] [∀ a b : θ₀, a ≤ b ∨ b ≤ a] {θ₁ : Type*} [add_comm_group θ₁] [order_bot θ₁] [decidable_eq θ₁] [∀ a b : θ₁, a ≤ b ∨ b ≤ a] {θ₂ : Type*} [add_comm_group θ₂] [order_bot θ₂] [decidable_eq θ₂] [∀ a b : θ₂, a ≤ b ∨ b ≤ a] {θ₃ : Type*} [add_comm_group θ₃] [order_bot θ₃] [decidable_eq θ₃] [∀ a b : θ₃, a ≤ b ∨ b ≤ a] {θ₄ : Type*} [add_comm_group θ₄] [order_bot θ₄] [decidable_eq θ₄] [∀ a b : θ₄, a ≤ b ∨ b ≤ a] {θ₅ : Type*} [add_comm_group θ₅] [order_bot θ₅] [decidable_eq θ₅] [∀ a b : θ₅, a ≤ b ∨ b ≤ a] {θ₆ : Type*} [add_comm_group θ₆] [order_bot θ₆] [decidable_eq θ₆] [∀ a b : θ₆, a ≤ b ∨ b ≤ a] {θ₇ : Type*} [add_comm_group θ₇] [order_bot θ₇] [decidable_eq θ₇] [∀ a b : θ₇, a ≤ b ∨ b ≤ a] {θ₈ : Type*} [add_comm_group θ₈] [order_bot θ₈] [decidable_eq θ₈] [∀ a b : θ₈, a ≤ b ∨ b ≤ a] {θ₉ : Type*} [add_comm_group θ₉] [order_bot θ₉] [decidable_ end --Needs more than 2000 tokens! /- FEW SHOT PROMPTS TO CODEX(START) /--`theorem` Power Set is Closed under Intersection Let $S$ be a set. Let $\powerset S$ be the power set of $S$. Then: :$\forall A, B \in \powerset S: A \cap B \in \powerset S$ `proof` Let $A, B \in \powerset S$. Then by the definition of power set, $A \subseteq S$ and $B \subseteq S$. From Intersection is Subset we have that $A \cap B \subseteq A$. It follows from Subset Relation is Transitive that $A \cap B \subseteq S$. Thus $A \cap B \in \powerset S$ and closure is proved. {{qed}} -/ theorem power_set_intersection_closed {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S := begin -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$ assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S), -- Then $A ⊆ S$ and $B ⊆ S$, by power set definition have h1 : (A ⊆ S) ∧ (B ⊆ S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB}, -- Then $(A ∩ B) ⊆ A$, by intersection of set is a subset have h2 : (A ∩ B) ⊆ A, from by apply set.inter_subset_left, -- Then $(A ∩ B) ⊆ S$, by subset relation is transitive have h3 : (A ∩ B) ⊆ S, from by {apply set.subset.trans h2 h1.left}, -- Hence $(A ∩ B) ∈ 𝒫 S$, by power set definition show (A ∩ B) ∈ 𝒫 S, from by {apply set.mem_powerset h3}, end /--`theorem` Square of Sum :$\forall x, y \in \R: \paren {x + y}^2 = x^2 + 2 x y + y^2$ `proof` Follows from the distribution of multiplication over addition: {{begin-eqn}} {{eqn | l = \left({x + y}\right)^2 | r = \left({x + y}\right) \cdot \left({x + y}\right) }} {{eqn | r = x \cdot \left({x + y}\right) + y \cdot \left({x + y}\right) | c = Real Multiplication Distributes over Addition }} {{eqn | r = x \cdot x + x \cdot y + y \cdot x + y \cdot y | c = Real Multiplication Distributes over Addition }} {{eqn | r = x^2 + 2xy + y^2 | c = }} {{end-eqn}} {{qed}} -/ theorem square_of_sum (x y : ℝ) : (x + y)^2 = (x^2 + 2*x*y + y^2) := begin -- expand the power calc (x + y)^2 = (x+y)*(x+y) : by rw sq -- distributive property of multiplication over addition gives: ... = x*(x+y) + y*(x+y) : by rw add_mul -- applying the above property further gives: ... = x*x + x*y + y*x + y*y : by {rw [mul_comm x (x+y),mul_comm y (x+y)], rw [add_mul,add_mul], ring} -- rearranging the terms using commutativity and adding gives: ... = x^2 + 2*x*y + y^2 : by {repeat {rw ← sq}, rw mul_comm y x, ring} end /--`theorem` Identity of Group is Unique Let $\struct {G, \circ}$ be a group. Then there is a unique identity element $e \in G$. `proof` From Group has Latin Square Property, there exists a unique $x \in G$ such that: :$a x = b$ and there exists a unique $y \in G$ such that: :$y a = b$ Setting $b = a$, this becomes: There exists a unique $x \in G$ such that: :$a x = a$ and there exists a unique $y \in G$ such that: :$y a = a$ These $x$ and $y$ are both $e$, by definition of identity element. {{qed}} -/ theorem group_identity_unique {G : Type*} [group G] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a := begin -- Group has Latin Square Property have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by { assume a b : G, use a⁻¹ * b, obviously, }, have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by { assume a b : G, use b * a⁻¹, obviously, }, -- Setting $b = a$, this becomes: have h3 : ∀ a : G, ∃! x : G, a * x = a, from assume a : G, h1 a a, have h4 : ∀ a : G, ∃! y : G, y * a = a, from assume a : G, h2 a a, -- These $x$ and $y$ are both $(1 : G)$, by definition of identity element have h5 : ∀ a : G, classical.some (h3 a).exists = (1 : G), from assume a :G, exists_unique.unique (h3 a) (classical.some_spec (exists_unique.exists (h3 a))) (mul_one a), have h6 : ∀ a : G, classical.some (h4 a).exists = (1 : G), from assume a : G, exists_unique.unique (h4 a) (classical.some_spec (exists_unique.exists (h4 a))) (one_mul a), show ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by { use (1 : G), have h7 : ∀ e : G, (∀ a : G, e * a = a ∧ a * e = a) → e = 1, from by { assume (e : G) (hident : ∀ a : G, e * a = a ∧ a * e = a), have h8 : ∀ a : G, e = classical.some (h3 a).exists, from assume (a : G), exists_unique.unique (h3 a) (hident a).right (classical.some_spec (exists_unique.exists (h3 a))), have h9 : ∀ a : G, e = classical.some (h4 a).exists, from assume (a : G), exists_unique.unique (h4 a) (hident a).left (classical.some_spec (exists_unique.exists (h4 a))), show e = (1 : G), from eq.trans (h9 e) (h6 _), }, exact ⟨by obviously, h7⟩, } end /--`theorem` Squeeze Theorem for Real Numbers Let $\sequence {x_n}$, $\sequence {y_n}$ and $\sequence {z_n}$ be sequences in $\R$. Let $\sequence {y_n}$ and $\sequence {z_n}$ both be convergent to the following limit: :$\ds \lim_{n \mathop \to \infty} y_n = l, \lim_{n \mathop \to \infty} z_n = l$ Suppose that: :$\forall n \in \N: y_n \le x_n \le z_n$ Then: :$x_n \to l$ as $n \to \infty$ that is: :$\ds \lim_{n \mathop \to \infty} x_n = l$ `proof` From Negative of Absolute Value: :$\size {x - l} < \epsilon \iff l - \epsilon < x < l + \epsilon$ Let $\epsilon > 0$. We need to prove that: :$\exists N: \forall n > N: \size {x_n - l} < \epsilon$ As $\ds \lim_{n \mathop \to \infty} y_n = l$ we know that: :$\exists N_1: \forall n > N_1: \size {y_n - l} < \epsilon$ As $\ds \lim_{n \mathop \to \infty} z_n = l$ we know that: :$\exists N_2: \forall n > N_2: \size {z_n - l} < \epsilon$ Let $N = \max \set {N_1, N_2}$. Then if $n > N$, it follows that $n > N_1$ and $n > N_2$. So: :$\forall n > N: l - \epsilon < y_n < l + \epsilon$ :$\forall n > N: l - \epsilon < z_n < l + \epsilon$ But: :$\forall n \in \N: y_n \le x_n \le z_n$ So: :$\forall n > N: l - \epsilon < y_n \le x_n \le z_n < l + \epsilon$ and so: :$\forall n > N: l - \epsilon < x_n < l + \epsilon$ So: :$\forall n > N: \size {x_n - l} < \epsilon$ Hence the result. {{qed}} -/ theorem squeeze_theorem_real_numbers (x y z : ℕ → ℝ) (l : ℝ) : let seq_limit : (ℕ → ℝ) → ℝ → Prop := λ (u : ℕ → ℝ) (l : ℝ), ∀ ε > 0, ∃ N, ∀ n > N, |u n - l| < ε in seq_limit y l → seq_limit z l → (∀ n : ℕ, (y n) ≤ (x n) ∧ (x n) ≤ (z n)) → seq_limit x l := begin assume seq_limit (h2 : seq_limit y l) (h3 : seq_limit z l) (h4 : ∀ (n : ℕ), y n ≤ x n ∧ x n ≤ z n) (ε), --From Negative of Absolute Value: $\size {x - l} < \epsilon \iff l - \epsilon < x < l + \epsilon$ have h5 : ∀ x, |x - l| < ε ↔ (((l - ε) < x) ∧ (x < (l + ε))), from by { intro x0, have h6 : |x0 - l| < ε ↔ ((x0 - l) < ε) ∧ ((l - x0) < ε), from abs_sub_lt_iff, rw h6, split, rintro ⟨ S_1, S_2 ⟩, split; linarith, rintro ⟨ S_3, S_4 ⟩, split; linarith, }, --Let $\epsilon > 0$. assume (h7 : ε > 0), --As $\ds \lim_{n \mathop \to \infty} y_n = l$ we know that $\exists N_1: \forall n > N_1: \size {y_n - l} < \epsilon$ cases h2 ε h7 with N1 h8, --As $\ds \lim_{n \mathop \to \infty} z_n = l$ we know that $\exists N_2: \forall n > N_2: \size {z_n - l} < \epsilon$ cases h3 ε h7 with N2 h9, --Let $N = \max \set {N_1, N_2}$. let N := max N1 N2, use N, --Then if $n > N$, it follows that $n > N_1$ and $n > N_2$. have h10 : ∀ n > N, n > N1 ∧ n > N2 := by { assume n h, split, exact lt_of_le_of_lt (le_max_left N1 N2) h, exact lt_of_le_of_lt (le_max_right N1 N2) h, }, --$\forall n > N: l - \epsilon < y_n < l + \epsilon$ --$\forall n > N: l - \epsilon < z_n < l + \epsilon$ --$\forall n \in \N: y_n \le x_n \le z_n$ --So $\forall n > N: l - \epsilon < y_n \le x_n \le z_n < l + \epsilon$ have h11 : ∀ n > N, (((l - ε) < (y n)) ∧ ((y n) ≤ (x n))) ∧ (((x n) ≤ (z n)) ∧ ((z n) < l+ε)), from by { intros n h12, split, { have h13 := (h8 n (h10 n h12).left), rw h5 (y n) at h13, split, exact h13.left, exact (h4 n).left, }, { have h14 := (h9 n (h10 n h12).right),rw h5 (z n) at h14, split, exact (h4 n).right, exact h14.right, }, }, --$\forall n > N: l - \epsilon < x_n < l + \epsilon$ have h15 : ∀ n > N, ((l - ε) < (x n)) ∧ ((x n) < (l+ε)), from by { intros n1 h16, cases (h11 n1 h16); split; linarith, }, --So $\forall n > N: \size {x_n - l} < \epsilon$ --Hence the result show ∀ (n : ℕ), n > N → |x n - l| < ε, from by { intros n h17, cases h5 (x n) with h18 h19, apply h19, exact h15 n h17, }, end /--`theorem` Density of irrational orbit The fractional parts of the integer multiples of an irrational number form a dense subset of the unit interval `proof` Let $\alpha$ be an irrational number. Then for distinct $i, j \in \mathbb{Z}$, we must have $\{i \alpha\} \neq\{j \alpha\}$. If this were not true, then $$ i \alpha-\lfloor i \alpha\rfloor=\{i \alpha\}=\{j \alpha\}=j \alpha-\lfloor j \alpha\rfloor, $$ which yields the false statement $\alpha=\frac{\lfloor i \alpha\rfloor-\lfloor j \alpha\rfloor}{i-j} \in \mathbb{Q}$. Hence, $$ S:=\{\{i \alpha\} \mid i \in \mathbb{Z}\} $$ is an infinite subset of $\left[0,1\right]$. By the Bolzano-Weierstrass theorem, $S$ has a limit point in $[0, 1]$. One can thus find pairs of elements of $S$ that are arbitrarily close. Since (the absolute value of) the difference of any two elements of $S$ is also an element of $S$, it follows that $0$ is a limit point of $S$. To show that $S$ is dense in $[0, 1]$, consider $y \in[0,1]$, and $\epsilon>0$. Then by selecting $x \in S$ such that $\{x\}<\epsilon$ (which exists as $0$ is a limit point), and $N$ such that $N \cdot\{x\} \leq y<(N+1) \cdot\{x\}$, we get: $|y-\{N x\}|<\epsilon$. QED -/ theorem FEW SHOT PROMPTS TO CODEX(END)-/
postulate A B : Set C : .{{_ : B}} → Set instance f : {{_ : A}} → B test : {{x : A}} → C
In the Aurora or Naperville area and looking for a life-changing personal training service? Contact us today to start training! Whatever you need, we're here for you. Here's how to get in touch with us! If you would like to set up a complimentary Success Session, please fill out the form below. In your message, please include some times you're available to meet, so we can get you scheduled most efficiently! Thank you! You'll hear back within 12 hours, but most likely much sooner!
F04BAJ Example Program Results Solution 1 2 1 1.0000 3.0000 2 -1.0000 2.0000 3 3.0000 4.0000 4 -5.0000 1.0000 Estimate of condition number 1.5e+02 Esttimate of error bound for computed solutions 1.7e-14
import numpy as np # We generate random points num_points = 1000 vectors_set = [] for i in xrange(num_points): x1 = np.random.normal(0.0, 0.55) y1 = x1 * 0.1 + 0.3 + np.random.normal(0.0, 0.03) vectors_set.append([x1, y1]) x_data = [v[0] for v in vectors_set] y_data = [v[1] for v in vectors_set] # The 2 lines below are useful on OS X to prevent the following error: # RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ import matplotlib as mpl mpl.use('TkAgg') # Display Random points import matplotlib.pyplot as plt plt.plot(x_data, y_data, 'ro', label='Original data') plt.legend() plt.show() import tensorflow as tf W = tf.Variable(tf.random_uniform([1], -1.0, 1.0)) b = tf.Variable(tf.zeros([1])) y = W * x_data + b # Cost function calculation loss = tf.reduce_mean(tf.square(y - y_data)) # We want to minimize the cost function # We train the Optimizer which is the gradient descent algo to the cost function defined optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss) init = tf.initialize_all_variables() sess = tf.Session() sess.run(init) for step in xrange(8): sess.run(train) print(step, sess.run(W), sess.run(b)) print(step, sess.run(loss)) # Display Graphic plt.plot(x_data, y_data, 'ro') plt.plot(x_data, sess.run(W) * x_data + sess.run(b)) plt.xlabel('x') plt.xlim(-2, 2) plt.ylabel('y') plt.ylim(0.1, 0.6) plt.legend() plt.show()
[STATEMENT] lemma fps_one_to_fls [simp]: "fps_to_fls 1 = 1" [PROOF STATE] proof (prove) goal (1 subgoal): 1. fps_to_fls 1 = 1 [PROOF STEP] by (intro fls_eqI) simp
Require Export Arith. Require Export XR_S_INR. Require Export XR_Rlt_trans. Require Export XR_Rlt_plus_1. Local Open Scope R_scope. Lemma lt_0_INR : forall n:nat, (0 < n)%nat -> R0 < INR n. Proof. intros n hn. induction n as [ | n hin ]. { inversion hn. } { unfold lt in hn. inversion hn as [ eq | n' hn' ]. { subst n. simpl. exact Rlt_0_1. } { subst n'. rewrite S_INR. apply Rlt_trans with (INR n). { apply hin. apply lt_le_trans with 1%nat. { unfold lt. apply le_n. } { exact hn'. } } { apply Rlt_plus_1. } } } Qed.
[GOAL] ⊢ Tendsto (fun k => ∑ i in Finset.range k, (-1) ^ i / (2 * ↑i + 1)) atTop (𝓝 (π / 4)) [PROOFSTEP] rw [tendsto_iff_norm_tendsto_zero, ← tendsto_zero_iff_norm_tendsto_zero] -- (1) We introduce a useful sequence `u` of values in [0,1], then prove that another sequence -- constructed from `u` tends to `0` at `+∞` [GOAL] ⊢ Tendsto (fun e => ∑ i in Finset.range e, (-1) ^ i / (2 * ↑i + 1) - π / 4) atTop (𝓝 0) [PROOFSTEP] let u := fun k : ℕ => (k : NNReal) ^ (-1 / (2 * (k : ℝ) + 1)) [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) ⊢ Tendsto (fun e => ∑ i in Finset.range e, (-1) ^ i / (2 * ↑i + 1) - π / 4) atTop (𝓝 0) [PROOFSTEP] have H : Tendsto (fun k : ℕ => (1 : ℝ) - u k + u k ^ (2 * (k : ℝ) + 1)) atTop (𝓝 0) := by convert (((tendsto_rpow_div_mul_add (-1) 2 1 two_ne_zero.symm).neg.const_add 1).add tendsto_inv_atTop_zero).comp tendsto_nat_cast_atTop_atTop using 1 · ext k simp only [NNReal.coe_nat_cast, Function.comp_apply, NNReal.coe_rpow] rw [← rpow_mul (Nat.cast_nonneg k) (-1 / (2 * (k : ℝ) + 1)) (2 * (k : ℝ) + 1), @div_mul_cancel _ _ (2 * (k : ℝ) + 1) _ (by norm_cast; simp only [Nat.succ_ne_zero, not_false_iff]), rpow_neg_one k, sub_eq_add_neg] · simp only [add_zero, add_right_neg] -- (2) We convert the limit in our goal to an inequality [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) ⊢ Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) [PROOFSTEP] convert (((tendsto_rpow_div_mul_add (-1) 2 1 two_ne_zero.symm).neg.const_add 1).add tendsto_inv_atTop_zero).comp tendsto_nat_cast_atTop_atTop using 1 [GOAL] case h.e'_3 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) ⊢ (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) = (fun x => 1 + -x ^ (-1 / (2 * x + 1)) + x⁻¹) ∘ Nat.cast [PROOFSTEP] ext k [GOAL] case h.e'_3.h u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) k : ℕ ⊢ 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) = ((fun x => 1 + -x ^ (-1 / (2 * x + 1)) + x⁻¹) ∘ Nat.cast) k [PROOFSTEP] simp only [NNReal.coe_nat_cast, Function.comp_apply, NNReal.coe_rpow] [GOAL] case h.e'_3.h u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) k : ℕ ⊢ 1 - ↑k ^ (-1 / (2 * ↑k + 1)) + (↑k ^ (-1 / (2 * ↑k + 1))) ^ (2 * ↑k + 1) = 1 + -↑k ^ (-1 / (2 * ↑k + 1)) + (↑k)⁻¹ [PROOFSTEP] rw [← rpow_mul (Nat.cast_nonneg k) (-1 / (2 * (k : ℝ) + 1)) (2 * (k : ℝ) + 1), @div_mul_cancel _ _ (2 * (k : ℝ) + 1) _ (by norm_cast; simp only [Nat.succ_ne_zero, not_false_iff]), rpow_neg_one k, sub_eq_add_neg] [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) k : ℕ ⊢ 2 * ↑k + 1 ≠ 0 [PROOFSTEP] norm_cast [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) k : ℕ ⊢ ¬2 * k + 1 = 0 [PROOFSTEP] simp only [Nat.succ_ne_zero, not_false_iff] [GOAL] case h.e'_5 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) ⊢ 𝓝 0 = 𝓝 (1 + -1 + 0) [PROOFSTEP] simp only [add_zero, add_right_neg] -- (2) We convert the limit in our goal to an inequality [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) ⊢ Tendsto (fun e => ∑ i in Finset.range e, (-1) ^ i / (2 * ↑i + 1) - π / 4) atTop (𝓝 0) [PROOFSTEP] refine' squeeze_zero_norm _ H [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) ⊢ ∀ (n : ℕ), ‖∑ i in Finset.range n, (-1) ^ i / (2 * ↑i + 1) - π / 4‖ ≤ 1 - ↑(u n) + ↑(u n ^ (2 * ↑n + 1)) [PROOFSTEP] intro k [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ ⊢ ‖∑ i in Finset.range k, (-1) ^ i / (2 * ↑i + 1) - π / 4‖ ≤ 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) [PROOFSTEP] let U := u k [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k ⊢ ‖∑ i in Finset.range k, (-1) ^ i / (2 * ↑i + 1) - π / 4‖ ≤ 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) [PROOFSTEP] let b (i : ℕ) x := (-(1 : ℝ)) ^ i * x ^ (2 * i + 1) / (2 * i + 1) [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) ⊢ ‖∑ i in Finset.range k, (-1) ^ i / (2 * ↑i + 1) - π / 4‖ ≤ 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) [PROOFSTEP] let f x := arctan x - ∑ i in Finset.range k, b i x [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x ⊢ ‖∑ i in Finset.range k, (-1) ^ i / (2 * ↑i + 1) - π / 4‖ ≤ 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) [PROOFSTEP] suffices f_bound : |f 1 - f 0| ≤ (1 : ℝ) - U + U ^ (2 * (k : ℝ) + 1) [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x f_bound : |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) ⊢ ‖∑ i in Finset.range k, (-1) ^ i / (2 * ↑i + 1) - π / 4‖ ≤ 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) [PROOFSTEP] rw [← norm_neg] [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x f_bound : |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) ⊢ ‖-(∑ i in Finset.range k, (-1) ^ i / (2 * ↑i + 1) - π / 4)‖ ≤ 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) [PROOFSTEP] convert f_bound using 1 [GOAL] case h.e'_3 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x f_bound : |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) ⊢ ‖-(∑ i in Finset.range k, (-1) ^ i / (2 * ↑i + 1) - π / 4)‖ = |f 1 - f 0| [PROOFSTEP] simp -- We show that `U` is indeed in [0,1] [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have hU1 : (U : ℝ) ≤ 1 := by by_cases hk : k = 0 · simp [hk] · exact rpow_le_one_of_one_le_of_nonpos (by norm_cast; exact Nat.succ_le_iff.mpr (Nat.pos_of_ne_zero hk)) (le_of_lt (@div_neg_of_neg_of_pos _ _ (-(1 : ℝ)) (2 * k + 1) (neg_neg_iff_pos.mpr zero_lt_one) (by norm_cast; exact Nat.succ_pos'))) [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x ⊢ ↑U ≤ 1 [PROOFSTEP] by_cases hk : k = 0 [GOAL] case pos u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hk : k = 0 ⊢ ↑U ≤ 1 [PROOFSTEP] simp [hk] [GOAL] case neg u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hk : ¬k = 0 ⊢ ↑U ≤ 1 [PROOFSTEP] exact rpow_le_one_of_one_le_of_nonpos (by norm_cast; exact Nat.succ_le_iff.mpr (Nat.pos_of_ne_zero hk)) (le_of_lt (@div_neg_of_neg_of_pos _ _ (-(1 : ℝ)) (2 * k + 1) (neg_neg_iff_pos.mpr zero_lt_one) (by norm_cast; exact Nat.succ_pos'))) [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hk : ¬k = 0 ⊢ 1 ≤ ↑↑k [PROOFSTEP] norm_cast [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hk : ¬k = 0 ⊢ 1 ≤ k [PROOFSTEP] exact Nat.succ_le_iff.mpr (Nat.pos_of_ne_zero hk) [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hk : ¬k = 0 ⊢ 0 < 2 * ↑k + 1 [PROOFSTEP] norm_cast [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hk : ¬k = 0 ⊢ 0 < 2 * k + 1 [PROOFSTEP] exact Nat.succ_pos' [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have hU2 := NNReal.coe_nonneg U [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] let f' := fun x : ℝ => (-x ^ 2) ^ k / (1 + x ^ 2) [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have has_deriv_at_f : ∀ x, HasDerivAt f (f' x) x := by intro x have has_deriv_at_b : ∀ i ∈ Finset.range k, HasDerivAt (b i) ((-x ^ 2) ^ i) x := by intro i _ convert HasDerivAt.const_mul ((-1 : ℝ) ^ i / (2 * i + 1)) (HasDerivAt.pow (2 * i + 1) (hasDerivAt_id x)) using 1 · ext y simp only [id.def] ring · simp rw [← mul_assoc, @div_mul_cancel _ _ (2 * (i : ℝ) + 1) _ (by norm_cast; linarith), pow_mul x 2 i, ← mul_pow (-1 : ℝ) (x ^ 2) i] ring_nf convert (hasDerivAt_arctan x).sub (HasDerivAt.sum has_deriv_at_b) using 1 have g_sum := @geom_sum_eq _ _ (-x ^ 2) ((neg_nonpos.mpr (sq_nonneg x)).trans_lt zero_lt_one).ne k simp only at g_sum ⊢ rw [g_sum, ← neg_add' (x ^ 2) 1, add_comm (x ^ 2) 1, sub_eq_add_neg, neg_div', neg_div_neg_eq] ring [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) ⊢ ∀ (x : ℝ), HasDerivAt f (f' x) x [PROOFSTEP] intro x [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ ⊢ HasDerivAt f (f' x) x [PROOFSTEP] have has_deriv_at_b : ∀ i ∈ Finset.range k, HasDerivAt (b i) ((-x ^ 2) ^ i) x := by intro i _ convert HasDerivAt.const_mul ((-1 : ℝ) ^ i / (2 * i + 1)) (HasDerivAt.pow (2 * i + 1) (hasDerivAt_id x)) using 1 · ext y simp only [id.def] ring · simp rw [← mul_assoc, @div_mul_cancel _ _ (2 * (i : ℝ) + 1) _ (by norm_cast; linarith), pow_mul x 2 i, ← mul_pow (-1 : ℝ) (x ^ 2) i] ring_nf [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ ⊢ ∀ (i : ℕ), i ∈ Finset.range k → HasDerivAt (b i) ((-x ^ 2) ^ i) x [PROOFSTEP] intro i _ [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k ⊢ HasDerivAt (b i) ((-x ^ 2) ^ i) x [PROOFSTEP] convert HasDerivAt.const_mul ((-1 : ℝ) ^ i / (2 * i + 1)) (HasDerivAt.pow (2 * i + 1) (hasDerivAt_id x)) using 1 [GOAL] case h.e'_6 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k ⊢ b i = fun y => (-1) ^ i / (2 * ↑i + 1) * id y ^ (2 * i + 1) [PROOFSTEP] ext y [GOAL] case h.e'_6.h u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k y : ℝ ⊢ b i y = (-1) ^ i / (2 * ↑i + 1) * id y ^ (2 * i + 1) [PROOFSTEP] simp only [id.def] [GOAL] case h.e'_6.h u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k y : ℝ ⊢ (-1) ^ i * y ^ (2 * i + 1) / (2 * ↑i + 1) = (-1) ^ i / (2 * ↑i + 1) * y ^ (2 * i + 1) [PROOFSTEP] ring [GOAL] case h.e'_7 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k ⊢ (-x ^ 2) ^ i = (-1) ^ i / (2 * ↑i + 1) * (↑(2 * i + 1) * id x ^ (2 * i + 1 - 1) * 1) [PROOFSTEP] simp [GOAL] case h.e'_7 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k ⊢ (-x ^ 2) ^ i = (-1) ^ i / (2 * ↑i + 1) * ((2 * ↑i + 1) * x ^ (2 * i)) [PROOFSTEP] rw [← mul_assoc, @div_mul_cancel _ _ (2 * (i : ℝ) + 1) _ (by norm_cast; linarith), pow_mul x 2 i, ← mul_pow (-1 : ℝ) (x ^ 2) i] [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k ⊢ 2 * ↑i + 1 ≠ 0 [PROOFSTEP] norm_cast [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k ⊢ ¬2 * i + 1 = 0 [PROOFSTEP] linarith [GOAL] case h.e'_7 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ i : ℕ a✝ : i ∈ Finset.range k ⊢ (-x ^ 2) ^ i = (-1 * x ^ 2) ^ i [PROOFSTEP] ring_nf [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ has_deriv_at_b : ∀ (i : ℕ), i ∈ Finset.range k → HasDerivAt (b i) ((-x ^ 2) ^ i) x ⊢ HasDerivAt f (f' x) x [PROOFSTEP] convert (hasDerivAt_arctan x).sub (HasDerivAt.sum has_deriv_at_b) using 1 [GOAL] case h.e'_7 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ has_deriv_at_b : ∀ (i : ℕ), i ∈ Finset.range k → HasDerivAt (b i) ((-x ^ 2) ^ i) x ⊢ f' x = ↑1 / (↑1 + x ^ 2) - ∑ i in Finset.range k, (-x ^ 2) ^ i [PROOFSTEP] have g_sum := @geom_sum_eq _ _ (-x ^ 2) ((neg_nonpos.mpr (sq_nonneg x)).trans_lt zero_lt_one).ne k [GOAL] case h.e'_7 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ has_deriv_at_b : ∀ (i : ℕ), i ∈ Finset.range k → HasDerivAt (b i) ((-x ^ 2) ^ i) x g_sum : ∑ i in Finset.range k, (-x ^ 2) ^ i = ((-x ^ 2) ^ k - 1) / (-x ^ 2 - 1) ⊢ f' x = ↑1 / (↑1 + x ^ 2) - ∑ i in Finset.range k, (-x ^ 2) ^ i [PROOFSTEP] simp only at g_sum ⊢ [GOAL] case h.e'_7 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ has_deriv_at_b : ∀ (i : ℕ), i ∈ Finset.range k → HasDerivAt (b i) ((-x ^ 2) ^ i) x g_sum : ∑ i in Finset.range k, (-x ^ 2) ^ i = ((-x ^ 2) ^ k - 1) / (-x ^ 2 - 1) ⊢ (-x ^ 2) ^ k / (↑1 + x ^ 2) = ↑1 / (↑1 + x ^ 2) - ∑ i in Finset.range k, (-x ^ 2) ^ i [PROOFSTEP] rw [g_sum, ← neg_add' (x ^ 2) 1, add_comm (x ^ 2) 1, sub_eq_add_neg, neg_div', neg_div_neg_eq] [GOAL] case h.e'_7 u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) x : ℝ has_deriv_at_b : ∀ (i : ℕ), i ∈ Finset.range k → HasDerivAt (b i) ((-x ^ 2) ^ i) x g_sum : ∑ i in Finset.range k, (-x ^ 2) ^ i = ((-x ^ 2) ^ k - 1) / (-x ^ 2 - 1) ⊢ (-x ^ 2) ^ k / (↑1 + x ^ 2) = ↑1 / (↑1 + x ^ 2) + ((-x ^ 2) ^ k - 1) / (1 + x ^ 2) [PROOFSTEP] ring [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have hderiv1 : ∀ x ∈ Icc (U : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (U : ℝ) 1) x := fun x _ => (has_deriv_at_f x).hasDerivWithinAt [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have hderiv2 : ∀ x ∈ Icc 0 (U : ℝ), HasDerivWithinAt f (f' x) (Icc 0 (U : ℝ)) x := fun x _ => (has_deriv_at_f x).hasDerivWithinAt [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have f'_bound : ∀ x ∈ Icc (-1 : ℝ) 1, |f' x| ≤ |x| ^ (2 * k) := by intro x _ rw [abs_div, IsAbsoluteValue.abv_pow abs (-x ^ 2) k, abs_neg, IsAbsoluteValue.abv_pow abs x 2, ← pow_mul] refine' div_le_of_nonneg_of_le_mul (abs_nonneg _) (pow_nonneg (abs_nonneg _) _) _ refine' le_mul_of_one_le_right (pow_nonneg (abs_nonneg _) _) _ rw_mod_cast [abs_of_nonneg (add_nonneg zero_le_one (sq_nonneg x) : (0 : ℝ) ≤ _)] exact (le_add_of_nonneg_right (sq_nonneg x) : (1 : ℝ) ≤ _) [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x ⊢ ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) [PROOFSTEP] intro x _ [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x x : ℝ a✝ : x ∈ Icc (-1) 1 ⊢ |f' x| ≤ |x| ^ (2 * k) [PROOFSTEP] rw [abs_div, IsAbsoluteValue.abv_pow abs (-x ^ 2) k, abs_neg, IsAbsoluteValue.abv_pow abs x 2, ← pow_mul] [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x x : ℝ a✝ : x ∈ Icc (-1) 1 ⊢ |x| ^ (2 * k) / |↑1 + x ^ 2| ≤ |x| ^ (2 * k) [PROOFSTEP] refine' div_le_of_nonneg_of_le_mul (abs_nonneg _) (pow_nonneg (abs_nonneg _) _) _ [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x x : ℝ a✝ : x ∈ Icc (-1) 1 ⊢ |x| ^ (2 * k) ≤ |x| ^ (2 * k) * |↑1 + x ^ 2| [PROOFSTEP] refine' le_mul_of_one_le_right (pow_nonneg (abs_nonneg _) _) _ [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x x : ℝ a✝ : x ∈ Icc (-1) 1 ⊢ 1 ≤ |↑1 + x ^ 2| [PROOFSTEP] rw_mod_cast [abs_of_nonneg (add_nonneg zero_le_one (sq_nonneg x) : (0 : ℝ) ≤ _)] [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x x : ℝ H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * k + 1))) atTop (𝓝 0) hU1 : U ≤ 1 hU2 : 0 ≤ U a✝ : x ∈ Icc (↑(Int.negSucc 0)) 1 ⊢ 1 ≤ 1 + x ^ 2 [PROOFSTEP] exact (le_add_of_nonneg_right (sq_nonneg x) : (1 : ℝ) ≤ _) [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have hbound1 : ∀ x ∈ Ico (U : ℝ) 1, |f' x| ≤ 1 := by rintro x ⟨hx_left, hx_right⟩ have hincr := pow_le_pow_of_le_left (le_trans hU2 hx_left) (le_of_lt hx_right) (2 * k) rw [one_pow (2 * k), ← abs_of_nonneg (le_trans hU2 hx_left)] at hincr rw [← abs_of_nonneg (le_trans hU2 hx_left)] at hx_right linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_of_lt hx_right)))] [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) ⊢ ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 [PROOFSTEP] rintro x ⟨hx_left, hx_right⟩ [GOAL] case intro u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) x : ℝ hx_left : ↑U ≤ x hx_right : x < 1 ⊢ |f' x| ≤ 1 [PROOFSTEP] have hincr := pow_le_pow_of_le_left (le_trans hU2 hx_left) (le_of_lt hx_right) (2 * k) [GOAL] case intro u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) x : ℝ hx_left : ↑U ≤ x hx_right : x < 1 hincr : x ^ (2 * k) ≤ 1 ^ (2 * k) ⊢ |f' x| ≤ 1 [PROOFSTEP] rw [one_pow (2 * k), ← abs_of_nonneg (le_trans hU2 hx_left)] at hincr [GOAL] case intro u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) x : ℝ hx_left : ↑U ≤ x hx_right : x < 1 hincr : |x| ^ (2 * k) ≤ 1 ⊢ |f' x| ≤ 1 [PROOFSTEP] rw [← abs_of_nonneg (le_trans hU2 hx_left)] at hx_right [GOAL] case intro u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) x : ℝ hx_left : ↑U ≤ x hx_right : |x| < 1 hincr : |x| ^ (2 * k) ≤ 1 ⊢ |f' x| ≤ 1 [PROOFSTEP] linarith [f'_bound x (mem_Icc.mpr (abs_le.mp (le_of_lt hx_right)))] [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have hbound2 : ∀ x ∈ Ico 0 (U : ℝ), |f' x| ≤ U ^ (2 * k) := by rintro x ⟨hx_left, hx_right⟩ have hincr := pow_le_pow_of_le_left hx_left (le_of_lt hx_right) (2 * k) rw [← abs_of_nonneg hx_left] at hincr hx_right rw [← abs_of_nonneg hU2] at hU1 hx_right exact (f'_bound x (mem_Icc.mpr (abs_le.mp (le_trans (le_of_lt hx_right) hU1)))).trans hincr [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 ⊢ ∀ (x : ℝ), x ∈ Ico 0 ↑U → |f' x| ≤ ↑(U ^ (2 * k)) [PROOFSTEP] rintro x ⟨hx_left, hx_right⟩ [GOAL] case intro u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 x : ℝ hx_left : 0 ≤ x hx_right : x < ↑U ⊢ |f' x| ≤ ↑(U ^ (2 * k)) [PROOFSTEP] have hincr := pow_le_pow_of_le_left hx_left (le_of_lt hx_right) (2 * k) [GOAL] case intro u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 x : ℝ hx_left : 0 ≤ x hx_right : x < ↑U hincr : x ^ (2 * k) ≤ ↑U ^ (2 * k) ⊢ |f' x| ≤ ↑(U ^ (2 * k)) [PROOFSTEP] rw [← abs_of_nonneg hx_left] at hincr hx_right [GOAL] case intro u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 x : ℝ hx_left : 0 ≤ x hx_right : |x| < ↑U hincr : |x| ^ (2 * k) ≤ ↑U ^ (2 * k) ⊢ |f' x| ≤ ↑(U ^ (2 * k)) [PROOFSTEP] rw [← abs_of_nonneg hU2] at hU1 hx_right [GOAL] case intro u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : |↑U| ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 x : ℝ hx_left : 0 ≤ x hx_right : |x| < |↑U| hincr : |x| ^ (2 * k) ≤ ↑U ^ (2 * k) ⊢ |f' x| ≤ ↑(U ^ (2 * k)) [PROOFSTEP] exact (f'_bound x (mem_Icc.mpr (abs_le.mp (le_trans (le_of_lt hx_right) hU1)))).trans hincr [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 hbound2 : ∀ (x : ℝ), x ∈ Ico 0 ↑U → |f' x| ≤ ↑(U ^ (2 * k)) ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have mvt1 := norm_image_sub_le_of_norm_deriv_le_segment' hderiv1 hbound1 _ (right_mem_Icc.mpr hU1) [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 hbound2 : ∀ (x : ℝ), x ∈ Ico 0 ↑U → |f' x| ≤ ↑(U ^ (2 * k)) mvt1 : ‖f 1 - f ↑U‖ ≤ 1 * (1 - ↑U) ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] have mvt2 := norm_image_sub_le_of_norm_deriv_le_segment' hderiv2 hbound2 _ (right_mem_Icc.mpr hU2) -- The following algebra is enough to complete the proof [GOAL] case f_bound u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 hbound2 : ∀ (x : ℝ), x ∈ Ico 0 ↑U → |f' x| ≤ ↑(U ^ (2 * k)) mvt1 : ‖f 1 - f ↑U‖ ≤ 1 * (1 - ↑U) mvt2 : ‖f ↑U - f 0‖ ≤ ↑(U ^ (2 * k)) * (↑U - 0) ⊢ |f 1 - f 0| ≤ 1 - ↑U + ↑(U ^ (2 * ↑k + 1)) [PROOFSTEP] calc |f 1 - f 0| = |f 1 - f U + (f U - f 0)| := by simp _ ≤ 1 * (1 - U) + U ^ (2 * k) * (U - 0) := (le_trans (abs_add (f 1 - f U) (f U - f 0)) (add_le_add mvt1 mvt2)) _ = 1 - U + (U : ℝ) ^ (2 * k) * U := by simp _ = 1 - u k + u k ^ (2 * (k : ℝ) + 1) := by rw [← pow_succ' (U : ℝ) (2 * k)]; norm_cast [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 hbound2 : ∀ (x : ℝ), x ∈ Ico 0 ↑U → |f' x| ≤ ↑(U ^ (2 * k)) mvt1 : ‖f 1 - f ↑U‖ ≤ 1 * (1 - ↑U) mvt2 : ‖f ↑U - f 0‖ ≤ ↑(U ^ (2 * k)) * (↑U - 0) ⊢ |f 1 - f 0| = |f 1 - f ↑U + (f ↑U - f 0)| [PROOFSTEP] simp [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 hbound2 : ∀ (x : ℝ), x ∈ Ico 0 ↑U → |f' x| ≤ ↑(U ^ (2 * k)) mvt1 : ‖f 1 - f ↑U‖ ≤ 1 * (1 - ↑U) mvt2 : ‖f ↑U - f 0‖ ≤ ↑(U ^ (2 * k)) * (↑U - 0) ⊢ 1 * (1 - ↑U) + ↑(U ^ (2 * k)) * (↑U - 0) = 1 - ↑U + ↑U ^ (2 * k) * ↑U [PROOFSTEP] simp [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 hbound2 : ∀ (x : ℝ), x ∈ Ico 0 ↑U → |f' x| ≤ ↑(U ^ (2 * k)) mvt1 : ‖f 1 - f ↑U‖ ≤ 1 * (1 - ↑U) mvt2 : ‖f ↑U - f 0‖ ≤ ↑(U ^ (2 * k)) * (↑U - 0) ⊢ 1 - ↑U + ↑U ^ (2 * k) * ↑U = 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) [PROOFSTEP] rw [← pow_succ' (U : ℝ) (2 * k)] [GOAL] u : ℕ → NNReal := fun k => ↑k ^ (-1 / (2 * ↑k + 1)) H : Tendsto (fun k => 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1))) atTop (𝓝 0) k : ℕ U : NNReal := u k b : ℕ → ℝ → ℝ := fun i x => (-1) ^ i * x ^ (2 * i + 1) / (2 * ↑i + 1) f : ℝ → ℝ := fun x => arctan x - ∑ i in Finset.range k, b i x hU1 : ↑U ≤ 1 hU2 : 0 ≤ ↑U f' : ℝ → ℝ := fun x => (-x ^ 2) ^ k / (↑1 + x ^ 2) has_deriv_at_f : ∀ (x : ℝ), HasDerivAt f (f' x) x hderiv1 : ∀ (x : ℝ), x ∈ Icc (↑U) 1 → HasDerivWithinAt f (f' x) (Icc (↑U) 1) x hderiv2 : ∀ (x : ℝ), x ∈ Icc 0 ↑U → HasDerivWithinAt f (f' x) (Icc 0 ↑U) x f'_bound : ∀ (x : ℝ), x ∈ Icc (-1) 1 → |f' x| ≤ |x| ^ (2 * k) hbound1 : ∀ (x : ℝ), x ∈ Ico (↑U) 1 → |f' x| ≤ 1 hbound2 : ∀ (x : ℝ), x ∈ Ico 0 ↑U → |f' x| ≤ ↑(U ^ (2 * k)) mvt1 : ‖f 1 - f ↑U‖ ≤ 1 * (1 - ↑U) mvt2 : ‖f ↑U - f 0‖ ≤ ↑(U ^ (2 * k)) * (↑U - 0) ⊢ 1 - ↑U + ↑U ^ (2 * k + 1) = 1 - ↑(u k) + ↑(u k ^ (2 * ↑k + 1)) [PROOFSTEP] norm_cast
Join the Food Shuttle & our Gardeners for a Spring Kickoff with CompostNow! The day kicks off at 11 a.m. with food, hands-on compositing demonstrations, cooking demonstrations, garden tours, volunteer opportunities and fun activities for kids. Stay after for a fermented foods workshop at 1 pm with our friends Piedmont Picnic. RSVP for the workshop by emailing [email protected].
[STATEMENT] theorem (in finite) update_balanced: assumes "\<rho> 0 = 0" and "\<forall>n. \<rho> n < 1" and "0 \<le> i" shows "balanced \<L> c = balanced (update_ledger \<rho> i \<L>) ((1 + i) * c)" (is "_ = balanced ?\<L>' ((1 + i) * c)") [PROOF STATE] proof (prove) goal (1 subgoal): 1. balanced \<L> c = balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) [PROOF STEP] proof [PROOF STATE] proof (state) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] assume "balanced \<L> c" [PROOF STATE] proof (state) this: balanced \<L> c goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "\<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (?\<L>' a) n) = 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] proof (rule allI, rule impI) [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] fix n :: nat [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] assume "n > 0" [PROOF STATE] proof (state) this: 0 < n goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] { [PROOF STATE] proof (state) this: 0 < n goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] fix a [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] let ?\<alpha>' = "\<lambda>n. (1 - \<rho> n) * \<pi> (\<L> a) n" [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] have "\<pi> (?\<L>' a) n = ?\<alpha>' n" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<pi> (update_ledger \<rho> i \<L> a) n = (1 - \<rho> n) * \<pi> (\<L> a) n [PROOF STEP] unfolding update_ledger_def update_account_def Rep_account_plus Rep_account_just_cash Rep_account_return_loans [PROOF STATE] proof (prove) goal (1 subgoal): 1. (if n = 0 then i * net_asset_value (\<L> a) else 0) + (1 - \<rho> n) * \<pi> (\<L> a) n = (1 - \<rho> n) * \<pi> (\<L> a) n [PROOF STEP] using plus_account_def \<open>n > 0\<close> [PROOF STATE] proof (prove) using this: ?\<alpha>\<^sub>1 + ?\<alpha>\<^sub>2 = \<iota> (\<lambda>n. \<pi> ?\<alpha>\<^sub>1 n + \<pi> ?\<alpha>\<^sub>2 n) 0 < n goal (1 subgoal): 1. (if n = 0 then i * net_asset_value (\<L> a) else 0) + (1 - \<rho> n) * \<pi> (\<L> a) n = (1 - \<rho> n) * \<pi> (\<L> a) n [PROOF STEP] by simp [PROOF STATE] proof (state) this: \<pi> (update_ledger \<rho> i \<L> a) n = (1 - \<rho> n) * \<pi> (\<L> a) n goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] } [PROOF STATE] proof (state) this: \<pi> (update_ledger \<rho> i \<L> ?a2) n = (1 - \<rho> n) * \<pi> (\<L> ?a2) n goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] hence "(\<Sum>a\<in>UNIV. \<pi> (?\<L>' a) n) = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n)" [PROOF STATE] proof (prove) using this: \<pi> (update_ledger \<rho> i \<L> ?a2) n = (1 - \<rho> n) * \<pi> (\<L> ?a2) n goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) [PROOF STEP] using finite_UNIV [PROOF STATE] proof (prove) using this: \<pi> (update_ledger \<rho> i \<L> ?a2) n = (1 - \<rho> n) * \<pi> (\<L> ?a2) n finite UNIV goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) [PROOF STEP] by (metis (mono_tags, lifting) sum.cong sum_distrib_left) [PROOF STATE] proof (state) this: (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] thus "(\<Sum>a\<in>UNIV. \<pi> (?\<L>' a) n) = 0" [PROOF STATE] proof (prove) using this: (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] using \<open>0 < n\<close> \<open>balanced \<L> c\<close> local.balanced_alt_def [PROOF STATE] proof (prove) using this: (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) 0 < n balanced \<L> c balanced ?\<L> ?c = ((\<Sum>a\<in>UNIV. cash_reserve (?\<L> a)) = ?c \<and> (\<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (?\<L> a) n) = 0)) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 [PROOF STEP] by force [PROOF STATE] proof (state) this: (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] moreover [PROOF STATE] proof (state) this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] { [PROOF STATE] proof (state) this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] fix S :: "'a set" [PROOF STATE] proof (state) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] let ?\<omega> = "shortest_ledger_period \<L>" [PROOF STATE] proof (state) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] assume "(\<Sum>a\<in>S. cash_reserve (\<L> a)) = c" and "\<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0" [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. cash_reserve (\<L> a)) = c \<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0 goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "(\<Sum>a\<in>S. cash_reserve (?\<L>' a)) = (\<Sum>a\<in>S. i * (\<Sum> n \<le> ?\<omega>. \<pi> (\<L> a) n) + cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] using finite [PROOF STATE] proof (prove) using this: finite ?A goal (1 subgoal): 1. (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] proof (induct S arbitrary: c rule: finite_induct) [PROOF STATE] proof (state) goal (2 subgoals): 1. (\<Sum>a\<in>{}. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>{}. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) 2. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] case empty [PROOF STATE] proof (state) this: goal (2 subgoals): 1. (\<Sum>a\<in>{}. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>{}. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) 2. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] then [PROOF STATE] proof (chain) picking this: [PROOF STEP] show ?case [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>{}. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>{}. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] by auto [PROOF STATE] proof (state) this: (\<Sum>a\<in>{}. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>{}. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] case (insert x S) [PROOF STATE] proof (state) this: finite S x \<notin> S (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] have "(\<Sum>a\<in>insert x S. cash_reserve (?\<L>' a)) = (\<Sum>a\<in>insert x S. i * (\<Sum> n \<le> ?\<omega>. \<pi> (\<L> a) n) + cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] unfolding update_ledger_def update_account_def cash_reserve_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>insert x S. \<pi> (just_cash (i * net_asset_value (\<L> a)) + return_loans \<rho> (\<L> a)) 0) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + \<pi> (\<L> a) 0) [PROOF STEP] by (simp add: \<open>\<rho> 0 = 0\<close>, metis (no_types) shortest_ledger_period_bound net_asset_value_shortest_period_ge) [PROOF STATE] proof (state) this: (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] thus ?case [PROOF STATE] proof (prove) using this: (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] . [PROOF STATE] proof (state) this: (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "... = (\<Sum>a\<in>S. i * (\<Sum> n = 1 .. ?\<omega>. \<pi> (\<L> a) n) + i * cash_reserve (\<L> a) + cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) [PROOF STEP] unfolding cash_reserve_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + \<pi> (\<L> a) 0) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * \<pi> (\<L> a) 0 + \<pi> (\<L> a) 0) [PROOF STEP] by (simp add: add.commute distrib_left sum.atMost_shift sum_bounds_lt_plus1) [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "... = (\<Sum>a\<in>S. i * (\<Sum> n = 1 .. ?\<omega>. \<pi> (\<L> a) n) + (1 + i) * cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) [PROOF STEP] using finite [PROOF STATE] proof (prove) using this: finite ?A goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) [PROOF STEP] by (induct S rule: finite_induct, auto, simp add: distrib_right) [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "... = i * (\<Sum>a\<in>S. (\<Sum> n = 1 .. ?\<omega>. \<pi> (\<L> a) n)) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) = i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] by (simp add: sum.distrib sum_distrib_left) [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) = i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) = i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "... = i * (\<Sum> n = 1 .. ?\<omega>. (\<Sum>a\<in>S. \<pi> (\<L> a) n)) + (1 + i) * c" [PROOF STATE] proof (prove) goal (1 subgoal): 1. i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * c [PROOF STEP] using \<open>(\<Sum>a\<in>S. cash_reserve (\<L> a)) = c\<close> sum.swap [PROOF STATE] proof (prove) using this: (\<Sum>a\<in>S. cash_reserve (\<L> a)) = c (\<Sum>i\<in>?A. sum (?g i) ?B) = (\<Sum>j\<in>?B. \<Sum>i\<in>?A. ?g i j) goal (1 subgoal): 1. i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * c [PROOF STEP] by force [PROOF STATE] proof (state) this: i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * c goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * c [PROOF STEP] have "(\<Sum>a\<in>S. cash_reserve (?\<L>' a)) = c * (1 + i)" [PROOF STATE] proof (prove) using this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * c goal (1 subgoal): 1. (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) [PROOF STEP] using \<open>\<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0\<close> [PROOF STATE] proof (prove) using this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * c \<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0 goal (1 subgoal): 1. (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) [PROOF STEP] by simp [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] } [PROOF STATE] proof (state) this: \<lbrakk>(\<Sum>a\<in>?S2. cash_reserve (\<L> a)) = c; \<forall>n>0. (\<Sum>a\<in>?S2. \<pi> (\<L> a) n) = 0\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>?S2. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] hence "(\<Sum>a\<in>UNIV. cash_reserve (?\<L>' a)) = c * (1 + i)" [PROOF STATE] proof (prove) using this: \<lbrakk>(\<Sum>a\<in>?S2. cash_reserve (\<L> a)) = c; \<forall>n>0. (\<Sum>a\<in>?S2. \<pi> (\<L> a) n) = 0\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>?S2. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) [PROOF STEP] using \<open>balanced \<L> c\<close> [PROOF STATE] proof (prove) using this: \<lbrakk>(\<Sum>a\<in>?S2. cash_reserve (\<L> a)) = c; \<forall>n>0. (\<Sum>a\<in>?S2. \<pi> (\<L> a) n) = 0\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>?S2. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) balanced \<L> c goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) [PROOF STEP] unfolding balanced_alt_def [PROOF STATE] proof (prove) using this: \<lbrakk>(\<Sum>a\<in>?S2. cash_reserve (\<L> a)) = c; \<forall>n>0. (\<Sum>a\<in>?S2. \<pi> (\<L> a) n) = 0\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>?S2. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) (\<Sum>a\<in>UNIV. cash_reserve (\<L> a)) = c \<and> (\<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) [PROOF STEP] by fastforce [PROOF STATE] proof (state) this: (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) goal (2 subgoals): 1. balanced \<L> c \<Longrightarrow> balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) 2. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) [PROOF STEP] show "balanced ?\<L>' ((1 + i) * c)" [PROOF STATE] proof (prove) using this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) [PROOF STEP] unfolding balanced_alt_def [PROOF STATE] proof (prove) using this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0 (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = c * (1 + i) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = (1 + i) * c \<and> (\<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0) [PROOF STEP] by auto [PROOF STATE] proof (state) this: balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] assume "balanced ?\<L>' ((1 + i) * c)" [PROOF STATE] proof (state) this: balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have \<star>: "\<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] proof (rule allI, rule impI) [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] fix n :: nat [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] assume "n > 0" [PROOF STATE] proof (state) this: 0 < n goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] hence "0 = (\<Sum>a\<in>UNIV. \<pi> (?\<L>' a) n)" [PROOF STATE] proof (prove) using this: 0 < n goal (1 subgoal): 1. 0 = (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) [PROOF STEP] using \<open>balanced ?\<L>' ((1 + i) * c)\<close> [PROOF STATE] proof (prove) using this: 0 < n balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) goal (1 subgoal): 1. 0 = (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) [PROOF STEP] unfolding balanced_alt_def [PROOF STATE] proof (prove) using this: 0 < n (\<Sum>a\<in>UNIV. cash_reserve (update_ledger \<rho> i \<L> a)) = (1 + i) * c \<and> (\<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = 0) goal (1 subgoal): 1. 0 = (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) [PROOF STEP] by auto [PROOF STATE] proof (state) this: 0 = (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] also [PROOF STATE] proof (state) this: 0 = (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] have "\<dots> = (\<Sum>a\<in>UNIV. (1 - \<rho> n) * \<pi> (\<L> a) n)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = (\<Sum>a\<in>UNIV. (1 - \<rho> n) * \<pi> (\<L> a) n) [PROOF STEP] unfolding update_ledger_def update_account_def Rep_account_return_loans Rep_account_just_cash [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (just_cash (i * net_asset_value (\<L> a)) + return_loans \<rho> (\<L> a)) n) = (\<Sum>a\<in>UNIV. (1 - \<rho> n) * \<pi> (\<L> a) n) [PROOF STEP] using \<open>n > 0\<close> [PROOF STATE] proof (prove) using this: 0 < n goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (just_cash (i * net_asset_value (\<L> a)) + return_loans \<rho> (\<L> a)) n) = (\<Sum>a\<in>UNIV. (1 - \<rho> n) * \<pi> (\<L> a) n) [PROOF STEP] by auto [PROOF STATE] proof (state) this: (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = (\<Sum>a\<in>UNIV. (1 - \<rho> n) * \<pi> (\<L> a) n) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>UNIV. \<pi> (update_ledger \<rho> i \<L> a) n) = (\<Sum>a\<in>UNIV. (1 - \<rho> n) * \<pi> (\<L> a) n) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] have "\<dots> = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. (1 - \<rho> n) * \<pi> (\<L> a) n) = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) [PROOF STEP] by (simp add: sum_distrib_left) [PROOF STATE] proof (state) this: (\<Sum>a\<in>UNIV. (1 - \<rho> n) * \<pi> (\<L> a) n) = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) goal (1 subgoal): 1. \<And>n. 0 < n \<Longrightarrow> (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: 0 = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) [PROOF STEP] show "(\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0" [PROOF STATE] proof (prove) using this: 0 = (1 - \<rho> n) * (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 [PROOF STEP] by (metis \<open>\<forall> r . \<rho> r < 1\<close> diff_gt_0_iff_gt less_numeral_extra(3) mult_eq_0_iff) [PROOF STATE] proof (state) this: (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] moreover [PROOF STATE] proof (state) this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] { [PROOF STATE] proof (state) this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] fix S :: "'a set" [PROOF STATE] proof (state) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] let ?\<omega> = "shortest_ledger_period \<L>" [PROOF STATE] proof (state) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] assume "(\<Sum>a\<in>S. cash_reserve (?\<L>' a)) = (1 + i) * c" and "\<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0" [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (1 + i) * c \<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0 goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] hence "(1 + i) * c = (\<Sum>a\<in>S. cash_reserve (?\<L>' a))" [PROOF STATE] proof (prove) using this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (1 + i) * c \<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0 goal (1 subgoal): 1. (1 + i) * c = (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) [PROOF STEP] by auto [PROOF STATE] proof (state) this: (1 + i) * c = (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (1 + i) * c = (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "\<dots> = (\<Sum>a\<in>S. i * (\<Sum> n \<le> ?\<omega>. \<pi> (\<L> a) n) + cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] using finite [PROOF STATE] proof (prove) using this: finite ?A goal (1 subgoal): 1. (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] proof (induct S rule: finite_induct) [PROOF STATE] proof (state) goal (2 subgoals): 1. (\<Sum>a\<in>{}. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>{}. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) 2. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] case empty [PROOF STATE] proof (state) this: goal (2 subgoals): 1. (\<Sum>a\<in>{}. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>{}. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) 2. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] then [PROOF STATE] proof (chain) picking this: [PROOF STEP] show ?case [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>{}. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>{}. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] by auto [PROOF STATE] proof (state) this: (\<Sum>a\<in>{}. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>{}. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] next [PROOF STATE] proof (state) goal (1 subgoal): 1. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] case (insert x S) [PROOF STATE] proof (state) this: finite S x \<notin> S (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] have "(\<Sum>a\<in>insert x S. cash_reserve (?\<L>' a)) = (\<Sum>a\<in>insert x S. i * (\<Sum> n \<le> ?\<omega>. \<pi> (\<L> a) n) + cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] unfolding update_ledger_def update_account_def cash_reserve_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>insert x S. \<pi> (just_cash (i * net_asset_value (\<L> a)) + return_loans \<rho> (\<L> a)) 0) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + \<pi> (\<L> a) 0) [PROOF STEP] by (simp add: \<open>\<rho> 0 = 0\<close>, metis (no_types) shortest_ledger_period_bound net_asset_value_shortest_period_ge) [PROOF STATE] proof (state) this: (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. \<And>x F. \<lbrakk>finite F; x \<notin> F; (\<Sum>a\<in>F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a))\<rbrakk> \<Longrightarrow> (\<Sum>a\<in>insert x F. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x F. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] thus ?case [PROOF STATE] proof (prove) using this: (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) [PROOF STEP] . [PROOF STATE] proof (state) this: (\<Sum>a\<in>insert x S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>insert x S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal: No subgoals! [PROOF STEP] qed [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. cash_reserve (update_ledger \<rho> i \<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "\<dots> = (\<Sum>a\<in>S. i * (\<Sum> n = 1 .. ?\<omega>. \<pi> (\<L> a) n) + i * cash_reserve (\<L> a) + cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) [PROOF STEP] unfolding cash_reserve_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + \<pi> (\<L> a) 0) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * \<pi> (\<L> a) 0 + \<pi> (\<L> a) 0) [PROOF STEP] by (simp add: add.commute distrib_left sum.atMost_shift sum_bounds_lt_plus1) [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {..shortest_ledger_period \<L>} + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "\<dots> = (\<Sum>a\<in>S. i * (\<Sum> n = 1 .. ?\<omega>. \<pi> (\<L> a) n) + (1 + i) * cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) [PROOF STEP] using finite [PROOF STATE] proof (prove) using this: finite ?A goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) [PROOF STEP] by (induct S rule: finite_induct, auto, simp add: distrib_right) [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + i * cash_reserve (\<L> a) + cash_reserve (\<L> a)) = (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "\<dots> = i * (\<Sum>a\<in>S. (\<Sum> n = 1 .. ?\<omega>. \<pi> (\<L> a) n)) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) = i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] by (simp add: sum.distrib sum_distrib_left) [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) = i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>a\<in>S. i * sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>} + (1 + i) * cash_reserve (\<L> a)) = i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "\<dots> = i * (\<Sum> n = 1 .. ?\<omega>. (\<Sum>a\<in>S. \<pi> (\<L> a) n)) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] using sum.swap [PROOF STATE] proof (prove) using this: (\<Sum>i\<in>?A. sum (?g i) ?B) = (\<Sum>j\<in>?B. \<Sum>i\<in>?A. ?g i j) goal (1 subgoal): 1. i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] by force [PROOF STATE] proof (state) this: i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] also [PROOF STATE] proof (state) this: i * (\<Sum>a\<in>S. sum (\<pi> (\<L> a)) {1..shortest_ledger_period \<L>}) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] have "\<dots> = (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] using \<open>\<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0\<close> [PROOF STATE] proof (prove) using this: \<forall>n>0. (\<Sum>a\<in>S. \<pi> (\<L> a) n) = 0 goal (1 subgoal): 1. i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] by simp [PROOF STATE] proof (state) this: i * (\<Sum>n = 1..shortest_ledger_period \<L>. \<Sum>a\<in>S. \<pi> (\<L> a) n) + (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) = (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: (1 + i) * c = (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] have "c = (\<Sum>a\<in>S. cash_reserve (\<L> a))" [PROOF STATE] proof (prove) using this: (1 + i) * c = (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (1 subgoal): 1. c = (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] using \<open>0 \<le> i\<close> [PROOF STATE] proof (prove) using this: (1 + i) * c = (1 + i) * (\<Sum>a\<in>S. cash_reserve (\<L> a)) 0 \<le> i goal (1 subgoal): 1. c = (\<Sum>a\<in>S. cash_reserve (\<L> a)) [PROOF STEP] by force [PROOF STATE] proof (state) this: c = (\<Sum>a\<in>S. cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] } [PROOF STATE] proof (state) this: \<lbrakk>(\<Sum>a\<in>?S2. cash_reserve (update_ledger \<rho> i \<L> a)) = (1 + i) * c; \<forall>n>0. (\<Sum>a\<in>?S2. \<pi> (\<L> a) n) = 0\<rbrakk> \<Longrightarrow> c = (\<Sum>a\<in>?S2. cash_reserve (\<L> a)) goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] hence "(\<Sum>a\<in>UNIV. cash_reserve (\<L> a)) = c" [PROOF STATE] proof (prove) using this: \<lbrakk>(\<Sum>a\<in>?S2. cash_reserve (update_ledger \<rho> i \<L> a)) = (1 + i) * c; \<forall>n>0. (\<Sum>a\<in>?S2. \<pi> (\<L> a) n) = 0\<rbrakk> \<Longrightarrow> c = (\<Sum>a\<in>?S2. cash_reserve (\<L> a)) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. cash_reserve (\<L> a)) = c [PROOF STEP] unfolding cash_reserve_def [PROOF STATE] proof (prove) using this: \<lbrakk>(\<Sum>a\<in>?S2. \<pi> (update_ledger \<rho> i \<L> a) 0) = (1 + i) * c; \<forall>n>0. (\<Sum>a\<in>?S2. \<pi> (\<L> a) n) = 0\<rbrakk> \<Longrightarrow> c = (\<Sum>a\<in>?S2. \<pi> (\<L> a) 0) goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) 0) = c [PROOF STEP] by (metis Rep_account_just_cash \<open>balanced ?\<L>' ((1 + i) * c)\<close> \<star> balanced_def finite_Rep_account_ledger) [PROOF STATE] proof (state) this: (\<Sum>a\<in>UNIV. cash_reserve (\<L> a)) = c goal (1 subgoal): 1. balanced (update_ledger \<rho> i \<L>) ((1 + i) * c) \<Longrightarrow> balanced \<L> c [PROOF STEP] ultimately [PROOF STATE] proof (chain) picking this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 (\<Sum>a\<in>UNIV. cash_reserve (\<L> a)) = c [PROOF STEP] show "balanced \<L> c" [PROOF STATE] proof (prove) using this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 (\<Sum>a\<in>UNIV. cash_reserve (\<L> a)) = c goal (1 subgoal): 1. balanced \<L> c [PROOF STEP] unfolding balanced_alt_def [PROOF STATE] proof (prove) using this: \<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0 (\<Sum>a\<in>UNIV. cash_reserve (\<L> a)) = c goal (1 subgoal): 1. (\<Sum>a\<in>UNIV. cash_reserve (\<L> a)) = c \<and> (\<forall>n>0. (\<Sum>a\<in>UNIV. \<pi> (\<L> a) n) = 0) [PROOF STEP] by auto [PROOF STATE] proof (state) this: balanced \<L> c goal: No subgoals! [PROOF STEP] qed